@algochad/archcoder 2.0.3 → 2.0.5

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.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-HTKwyaEM.js","assets/vendor--DbVqbJpV.css","assets/ToolOutputDialog-CzWxL8w8.js","assets/index-DKc7ZmSW.js","assets/index-CtCEGYrr.css","assets/TimelineDialog-C7rryZWn.js","assets/TerminalView-BYycNet-.js","assets/SettingsWindow-SRJdxJbx.js","assets/MultiRunWindow-DWSqqb1U.js"])))=>i.map(i=>d[i]);
2
- import{e as Fe,u as s,v as pg,w as gg,P as xg,C as bg,x as vg,y as yg,L as wg,z as jg,S as kg,B as Ng,D as Sg,G as Cg,I as Ag,J as Mg,O as Fg,Q as Bg,U as _g,V as Eg,W as Dg,Y as js,Z as On,R as d,$ as N1,a0 as xl,a1 as E2,a2 as D2,a3 as S1,a4 as Ps,a5 as X0,a6 as Ig,a7 as Q0,a8 as C1,a9 as A1,a as Dr,d as wa,p as Pl,b as Ii,aa as To,ab as Sh,ac as Tg,ad as he,ae as Pg,af as Ch,ag as Qn,ah as Rg,ai as zg,aj as Lg,ak as Ah,al as Hg,am as $g,an as Og,ao as Vg,ap as Ug,aq as Wg,ar as Mh,as as qg,at as Gg,au as Zg,av as $i,k as Cl,aw as xa,ax as Qr,ay as Fh,az as Pn,aA as ts,aB as xu,aC as Yo,aD as bl,aE as I0,aF as Qs,aG as Bh,aH as Kg,aI as Yg,aJ as Ds,aK as nr,aL as Va,aM as Xg,aN as hi,K as Po,aO as V1,aP as Qg,N as Jg,M as e9,aQ as Al,aR as on,aS as xr,aT as oa,aU as ya,aV as zo,aW as Rl,aX as M1,aY as Xo,_ as Kn,aZ as I2,a_ as Pa,a$ as wd,b0 as vl,b1 as yl,b2 as ji,b3 as J0,b4 as t9,b5 as F1,b6 as e2,b7 as T2,b8 as ba,b9 as Er,ba as bu,bb as vu,bc as _h,bd as Eh,be as s9,bf as n9,bg as c1,bh as Qo,bi as Bo,bj as t2,bk as Ml,bl as Fl,bm as r9,bn as $r,bo as o9,bp as a9,bq as bo,br as l9,bs as P2,bt as fa,bu as i9,bv as _o,bw as B1,bx as Bl,by as c9,bz as d9,bA as Dh,bB as qa,bC as R2,bD as u9,bE as f9,bF as ml,bG as Ih,bH as Th,bI as T0,bJ as jd,bK as m9,bL as ki,bM as Ni,bN as wo,bO as h9,bP as p9,bQ as g9,bR as x9,bS as b9,bT as v9,bU as y9,bV as w9,bW as j9,bX as k9,bY as N9,bZ as S9,b_ as C9,b$ as wr,c0 as Jo,c1 as ea,c2 as jr,c3 as A9,c4 as M9,c5 as kd,c6 as Ph,c7 as yu,c8 as wu,c9 as Rh,ca as ju,cb as U1,cc as zh,cd as z2,ce as Ga,cf as Za,cg as Go,ch as Lh,ci as F9,cj as B9,ck as _9,cl as Hh,cm as $h,cn as Oh,co as Vh,cp as Uh,cq as E9,cr as D9,cs as I9,ct as T9,cu as P9,cv as Wh,cw as oo,cx as v3,cy as R9,cz as z9,cA as ku,cB as ta,cC as L9,cD as H9,cE as y3,cF as w3,cG as $9,cH as O9,cI as V9,cJ as U9,cK as W9,cL as q9,cM as Co,cN as G9,cO as Lo,cP as Z9,cQ as K9,cR as qh,cS as Y9,cT as X9,cU as Ka,cV as Q9,cW as J9,cX as Gh,cY as ex,cZ as tx,i as s2,c_ as Zh,c$ as sx,d0 as Kh,d1 as nx,d2 as rx,d3 as ox,d4 as ax,d5 as Yh,d6 as wl,d7 as Nu,d8 as lx,d9 as ix,da as cx,db as dx,dc as j3,dd as k3,de as N3,df as Xh,dg as ux,dh as fx,di as mx,dj as hx,dk as px,dl as gx,dm as S3,dn as Su,dp as xx,dq as bx,dr as go,ds as vx,dt as Ti,du as C3,dv as yx,dw as wx,dx as ac,dy as jx,dz as kx,dA as Nx,dB as A3,dC as M3,dD as Sx,dE as Qh,dF as Jh,dG as Cx,dH as F3,dI as Ax,dJ as Mx,dK as Fx,dL as Bx,dM as Cu,dN as Au,dO as _x,dP as Nd,dQ as dt,dR as n1,dS as Ex,dT as Dx,dU as zl,dV as Ix,dW as Tx,dX as Px,dY as Rx,dZ as zx,d_ as Lx,d$ as Hx,e0 as $x,e1 as n2,e2 as e6,e3 as t6,e4 as s6,e5 as n6,e6 as r6,e7 as o6,e8 as a6,e9 as Ox,ea as l6,eb as i6,ec as ai,ed as c6,ee as d6,ef as W1,eg as u6,eh as Ll,ei as f6,ej as Sd,ek as Vx,q as m6,el as Mu,g as Fu,A as Bu,em as Ux,en as Wx,eo as d1,ep as L2,eq as qx,er as jl,es as Gx,et as Fn,eu as Zx,ev as Kx,ew as Yx,ex as Xx,ey as Qx,ez as h6,eA as Jx,eB as eb,eC as tb,eD as H2,eE as Pi,eF as sb,eG as nb,eH as rb,eI as p6,eJ as g6,eK as x6,eL as b6,eM as ob,eN as ab,eO as r2,eP as v6,o as _u,eQ as Cd,eR as lb,eS as ib,eT as P0,eU as B3,eV as cb,eW as db,eX as ub,eY as fb,eZ as mb,e_ as R0,e$ as y6,f0 as w6,f1 as Ad,f2 as hb,f3 as pb,f4 as gb,f5 as j6,f6 as xb,f7 as bb,f8 as vb,f9 as yb,fa as wb,j as k6,fb as jb,fc as kb,fd as Nb,fe as Sb,ff as Cb,fg as Ab,fh as Mb,fi as Fb,fj as Md,fk as Bb,fl as _3,fm as E3,fn as _b,fo as Eb,fp as Db,fq as Ib,fr as Tb,fs as Pb,ft as z0,E as D3,fu as Rb,fv as lc,fw as I3,fx as zb,fy as Lb,m as Hb,fz as $b,fA as Ob,fB as Vb}from"./vendor-.bun-HTKwyaEM.js";import{c as Q,u as Ee,a as ln,i as xn,g as Ho,b as Ko,d as _n,e as Eu,f as dn,h as Yr,j as Ub,k as _1,l as Rn,m as $o,n as T3,o as N6,p as L0,q as Wb,r as qb,s as S6,t as rs,v as Ze,w as vs,x as Du,y as Eo,z as u1,A as Iu,B as q1,C as $2,D as P3,E as O2,F as ma,G as hl,H as sr,I as R3,P as ja,J as ka,K as C6,L as A6,M as Or,N as Tu,O as Hl,Q as $l,R as Gb,S as Zb,T as M6,U as Ri,V as Kb,W as Yb,X as zi,Y as Xb,Z as Qb,_ as F6,$ as _l,a0 as En,a1 as o2,a2 as Fd,a3 as Jb,a4 as G1,a5 as ev,a6 as Bd,a7 as tv,a8 as sv,a9 as nv,aa as rv,ab as ov,ac as z3,ad as B6,ae as av,af as lv,ag as iv,ah as cv,ai as dv,aj as uv,ak as Nn,al as fv,am as mv,an as hv,ao as pv,ap as a2,aq as ic,ar as cc,as as dc,at as V2,au as gv,av as li,aw as pi,ax as U2,ay as E1,az as _6,aA as va,aB as xv,aC as f1,aD as uc,aE as Na,aF as H0,aG as bv,aH as fc,aI as vv,aJ as Pu,aK as E6,aL as yv,aM as wv,aN as t0,aO as L3,aP as uo,aQ as jv,aR as kv,aS as Nv,aT as D6,aU as Sv,aV as H3,aW as Cv,aX as Av,aY as Mv,aZ as $3,a_ as Fv,a$ as Bv,b0 as I6,b1 as T6,b2 as _v,b3 as P6}from"./index-DKc7ZmSW.js";function ii(t){const e=Fe.c(6);let n,r;e[0]!==t?({delayDuration:r,...n}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);const o=r===void 0?0:r;let a;return e[3]!==o||e[4]!==n?(a=s.jsx(vg,{"data-slot":"tooltip-provider",delayDuration:o,...n}),e[3]=o,e[4]=n,e[5]=a):a=e[5],a}function Dt(t){const e=Fe.c(6);let n,r;e[0]!==t?({delayDuration:r,...n}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);const o=r===void 0?0:r;let a;return e[3]!==o||e[4]!==n?(a=s.jsx(pg,{"data-slot":"tooltip",delayDuration:o,...n}),e[3]=o,e[4]=n,e[5]=a):a=e[5],a}function It(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(gg,{"data-slot":"tooltip-trigger",...n}),e[2]=n,e[3]=r):r=e[3],r}function _t(t){const e=Fe.c(17);let n,r,o,a,l;e[0]!==t?({className:r,sideOffset:l,children:n,style:a,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a,e[5]=l):(n=e[1],r=e[2],o=e[3],a=e[4],l=e[5]);const i=l===void 0?0:l;let c;e[6]!==r?(c=Q("bg-muted text-muted-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-xl px-3 py-1.5 typography-meta text-balance overflow-hidden transform-gpu will-change-transform",r),e[6]=r,e[7]=c):c=e[7];let u;e[8]!==a?(u={backdropFilter:"blur(28px)",WebkitBackdropFilter:"blur(28px)",...a},e[8]=a,e[9]=u):u=e[9];let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(yg,{className:"fill-muted z-50 size-2"}),e[10]=m):m=e[10];let f;return e[11]!==n||e[12]!==o||e[13]!==i||e[14]!==c||e[15]!==u?(f=s.jsx(xg,{children:s.jsxs(bg,{"data-slot":"tooltip-content",sideOffset:i,className:c,style:u,...o,children:[n,m]})}),e[11]=n,e[12]=o,e[13]=i,e[14]=c,e[15]=u,e[16]=f):f=e[16],f}function qs(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Sg,{"data-slot":"dropdown-menu",...n}),e[2]=n,e[3]=r):r=e[3],r}function Gs(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Cg,{"data-slot":"dropdown-menu-trigger",...n}),e[2]=n,e[3]=r):r=e[3],r}function Ys(t){const e=Fe.c(14);let n,r,o,a;e[0]!==t?({className:n,sideOffset:a,style:o,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a):(n=e[1],r=e[2],o=e[3],a=e[4]);const l=a===void 0?4:a;let i;e[5]!==o?(i={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)",backdropFilter:"blur(28px)",WebkitBackdropFilter:"blur(28px)",...o},e[5]=o,e[6]=i):i=e[6];let c;e[7]!==n?(c=Q("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-visible rounded-xl border-2 border-border/60 p-1 shadow-none",n),e[7]=n,e[8]=c):c=e[8];let u;return e[9]!==r||e[10]!==l||e[11]!==i||e[12]!==c?(u=s.jsx(Ag,{children:s.jsx(Mg,{"data-slot":"dropdown-menu-content",sideOffset:l,style:i,className:c,...r})}),e[9]=r,e[10]=l,e[11]=i,e[12]=c,e[13]=u):u=e[13],u}function Jt(t){const e=Fe.c(12);let n,r,o,a;e[0]!==t?({className:n,inset:r,variant:a,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a):(n=e[1],r=e[2],o=e[3],a=e[4]);const l=a===void 0?"default":a;let i;e[5]!==n?(i=Q("data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover data-[variant=destructive]:text-destructive data-[variant=destructive]:hover:bg-destructive/10 dark:data-[variant=destructive]:hover:bg-destructive/20 data-[variant=destructive]:hover:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 typography-ui-label outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",n),e[5]=n,e[6]=i):i=e[6];let c;return e[7]!==r||e[8]!==o||e[9]!==i||e[10]!==l?(c=s.jsx(Fg,{"data-slot":"dropdown-menu-item","data-inset":r,"data-variant":l,className:i,...o}),e[7]=r,e[8]=o,e[9]=i,e[10]=l,e[11]=c):c=e[11],c}function l2(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(jg,{"data-slot":"dropdown-menu-radio-group",...n}),e[2]=n,e[3]=r):r=e[3],r}function W2(t){const e=Fe.c(11);let n,r,o;e[0]!==t?({className:r,children:n,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o):(n=e[1],r=e[2],o=e[3]);let a;e[4]!==r?(a=Q("data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover data-[state=checked]:bg-interactive-selection data-[state=checked]:text-interactive-selection-foreground relative flex cursor-pointer items-start gap-2 rounded-lg py-1 pl-2 pr-8 typography-ui-label outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",r),e[4]=r,e[5]=a):a=e[5];let l;e[6]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"pointer-events-none absolute right-2 flex size-3.5 items-center justify-center text-primary",children:s.jsx(Dg,{children:s.jsx(js,{className:"size-3"})})}),e[6]=l):l=e[6];let i;return e[7]!==n||e[8]!==o||e[9]!==a?(i=s.jsxs(Ng,{"data-slot":"dropdown-menu-radio-item",className:a,...o,children:[l,n]}),e[7]=n,e[8]=o,e[9]=a,e[10]=i):i=e[10],i}function sa(t){const e=Fe.c(10);let n,r,o;e[0]!==t?({className:n,inset:r,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o):(n=e[1],r=e[2],o=e[3]);let a;e[4]!==n?(a=Q("px-2 py-1 typography-ui-label font-medium data-[inset]:pl-8",n),e[4]=n,e[5]=a):a=e[5];let l;return e[6]!==r||e[7]!==o||e[8]!==a?(l=s.jsx(wg,{"data-slot":"dropdown-menu-label","data-inset":r,className:a,...o}),e[6]=r,e[7]=o,e[8]=a,e[9]=l):l=e[9],l}function Zn(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("bg-border -mx-1 my-0.5 h-px",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(kg,{"data-slot":"dropdown-menu-separator",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function Ev(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Bg,{"data-slot":"dropdown-menu-sub",...n}),e[2]=n,e[3]=r):r=e[3],r}function Dv(t){const e=Fe.c(13);let n,r,o,a;e[0]!==t?({className:r,inset:o,children:n,...a}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a):(n=e[1],r=e[2],o=e[3],a=e[4]);let l;e[5]!==r?(l=Q("data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 typography-ui-label outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",r),e[5]=r,e[6]=l):l=e[6];let i;e[7]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(On,{className:"ml-auto size-3.5"}),e[7]=i):i=e[7];let c;return e[8]!==n||e[9]!==o||e[10]!==a||e[11]!==l?(c=s.jsxs(_g,{"data-slot":"dropdown-menu-sub-trigger","data-inset":o,className:l,...a,children:[n,i]}),e[8]=n,e[9]=o,e[10]=a,e[11]=l,e[12]=c):c=e[12],c}function Iv(t){const e=Fe.c(9);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]===Symbol.for("react.memo_cache_sentinel")?(o={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)",backdropFilter:"blur(28px)",WebkitBackdropFilter:"blur(28px)"},e[3]=o):o=e[3];let a;e[4]!==n?(a=Q("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-visible rounded-xl border-2 border-border/60 p-1 shadow-none",n),e[4]=n,e[5]=a):a=e[5];let l;return e[6]!==r||e[7]!==a?(l=s.jsx(Eg,{"data-slot":"dropdown-menu-sub-content",style:o,className:a,...r}),e[6]=r,e[7]=a,e[8]=l):l=e[8],l}const Tv=({transform:t})=>({...t,y:0}),Pv=t=>{const e=Fe.c(18),{id:n,children:r,className:o}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:l,listeners:i,setNodeRef:c,transform:u,transition:m,isDragging:f}=E2(a);let h;e[2]!==u?(h=D2.Transform.toString(u),e[2]=u,e[3]=h):h=e[3];let p;e[4]!==h||e[5]!==m?(p={transform:h,transition:m},e[4]=h,e[5]=m,e[6]=p):p=e[6];const g=f&&"opacity-50";let x;e[7]!==o||e[8]!==g?(x=Q("h-full rounded-md",o,g),e[7]=o,e[8]=g,e[9]=x):x=e[9];let b;return e[10]!==l||e[11]!==r||e[12]!==n||e[13]!==i||e[14]!==c||e[15]!==p||e[16]!==x?(b=s.jsx("div",{ref:c,"data-sortable-tab-id":n,style:p,className:x,...l,...i,children:r}),e[10]=l,e[11]=r,e[12]=n,e[13]=i,e[14]=c,e[15]=p,e[16]=x,e[17]=b):b=e[17],b},Rv=t=>{const e=Fe.c(6),{id:n,children:r,className:o}=t;let a;e[0]!==o?(a=Q("h-full",o),e[0]=o,e[1]=a):a=e[1];let l;return e[2]!==r||e[3]!==n||e[4]!==a?(l=s.jsx("div",{className:a,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=a,e[5]=l):l=e[5],l},Ro=t=>{const e=Fe.c(109),{items:n,activeId:r,onSelect:o,onClose:a,onReorder:l,layoutMode:i,variant:c,activePillInsetClassName:u,activePillButtonClassName:m,inactiveTabsIconOnly:f,animateActivePill:h,activePillLowercase:p,className:g}=t,x=i===void 0?"scrollable":i,b=c===void 0?"default":c,v=f===void 0?!1:f,y=p===void 0?!0:p,w=Ee(zv),C=d.useRef(null);let N;e[0]===Symbol.for("react.memo_cache_sentinel")?(N={left:!1,right:!1},e[0]=N):N=e[0];const[S,k]=d.useState(N);let j;e[1]!==n?(j=n.map(Lv),e[1]=n,e[2]=j):j=e[2];const F=j,A=x==="scrollable",M=b==="active-pill",B=b==="animated",E=M||B,I=M&&A,P=B,D=h??B,L=typeof l=="function",T=L?Pv:Rv;let _;e[3]===Symbol.for("react.memo_cache_sentinel")?(_=new Map,e[3]=_):_=e[3];const z=d.useRef(_),[R,W]=d.useState(null);let G;e[4]===Symbol.for("react.memo_cache_sentinel")?(G={activationConstraint:{distance:8}},e[4]=G):G=e[4];const Y=N1(xl(S1,G)),J=Hv;let V;e[5]===Symbol.for("react.memo_cache_sentinel")?(V=(Ge,Le)=>{if(Le){z.current.set(Ge,Le);return}z.current.delete(Ge)},e[5]=V):V=e[5];const te=V;let U;e[6]!==r||e[7]!==E?(U=()=>{if(!E||!r){W($v);return}const Ge=C.current,Le=z.current.get(r);if(!Ge||!Le){W(Ov);return}let qe=0,rt=0,st=Le;for(;st&&st!==Ge;)qe=qe+st.offsetLeft,rt=rt+st.offsetTop,st=st.offsetParent;const it={left:qe,top:rt,width:Le.offsetWidth,height:Le.offsetHeight};W(lt=>J(lt,it)?lt:it)},e[6]=r,e[7]=E,e[8]=U):U=e[8];const X=U;let $;e[9]!==A?($=()=>{if(!A){k({left:!1,right:!1});return}const Ge=C.current;if(!Ge){k({left:!1,right:!1});return}k({left:Ge.scrollLeft>2,right:Ge.scrollLeft+Ge.clientWidth<Ge.scrollWidth-2})},e[9]=A,e[10]=$):$=e[10];const q=$;let ee;e[11]!==A||e[12]!==q?(ee=()=>{if(!A){k({left:!1,right:!1});return}const Ge=C.current;if(!Ge)return;q(),Ge.addEventListener("scroll",q,{passive:!0});const Le=new ResizeObserver(q);return Le.observe(Ge),()=>{Ge.removeEventListener("scroll",q),Le.disconnect()}},e[11]=A,e[12]=q,e[13]=ee):ee=e[13];let ce;e[14]!==A||e[15]!==n.length||e[16]!==q?(ce=[A,n.length,q],e[14]=A,e[15]=n.length,e[16]=q,e[17]=ce):ce=e[17],d.useEffect(ee,ce);let ve;e[18]!==r||e[19]!==X||e[20]!==E?(ve=()=>{if(!E){W(null);return}X();const Ge=C.current;if(!Ge)return;const Le=new ResizeObserver(X);if(Le.observe(Ge),r){const qe=z.current.get(r);qe&&Le.observe(qe)}return()=>{Le.disconnect()}},e[18]=r,e[19]=X,e[20]=E,e[21]=ve):ve=e[21];let ge;e[22]!==r||e[23]!==n.length||e[24]!==X||e[25]!==E?(ge=[r,n.length,X,E],e[22]=r,e[23]=n.length,e[24]=X,e[25]=E,e[26]=ge):ge=e[26],d.useEffect(ve,ge);let xe;e[27]!==X?(xe=()=>{X()},e[27]=X,e[28]=xe):xe=e[28],d.useLayoutEffect(xe);let ne;e[29]!==r||e[30]!==A||e[31]!==q?(ne=()=>{if(!A||!r)return;const Ge=C.current;if(!Ge)return;const Le=window.requestAnimationFrame(()=>{const qe=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),rt=Ge.querySelector(`[data-sortable-tab-id="${qe}"]`);rt&&(rt.scrollIntoView({block:"nearest",inline:"nearest"}),q())});return()=>{window.cancelAnimationFrame(Le)}},e[29]=r,e[30]=A,e[31]=q,e[32]=ne):ne=e[32];let O;e[33]!==r||e[34]!==A||e[35]!==n.length||e[36]!==q?(O=[r,A,n.length,q],e[33]=r,e[34]=A,e[35]=n.length,e[36]=q,e[37]=O):O=e[37],d.useEffect(ne,O);let H;e[38]!==l?(H=Ge=>{if(!l)return;const{active:Le,over:qe}=Ge;!qe||Le.id===qe.id||l(String(Le.id),String(qe.id))},e[38]=l,e[39]=H):H=e[39];const K=H;let re;e[40]!==g?(re=Q("relative flex h-full min-w-0 flex-1",g),e[40]=g,e[41]=re):re=e[41];let le;e[42]!==A||e[43]!==S||e[44]!==E?(le=A&&S.left?s.jsx("div",{className:Q("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",E?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=A,e[43]=S,e[44]=E,e[45]=le):le=e[45];let ae;e[46]!==A||e[47]!==S||e[48]!==E?(ae=A&&S.right?s.jsx("div",{className:Q("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",E?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=A,e[47]=S,e[48]=E,e[49]=ae):ae=e[49];const ue=E?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",be=E&&"@container/pill-tabs",oe=E&&"pill-tabs__track",Z=E&&(u??"gap-0.5 py-0.5"),ie=P&&"rounded-lg bg-[var(--surface-muted)]/50",pe=A?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let me;e[50]!==ue||e[51]!==be||e[52]!==oe||e[53]!==Z||e[54]!==ie||e[55]!==pe?(me=Q("relative flex h-full min-w-0 flex-1",ue,be,oe,Z,ie,pe),e[50]=ue,e[51]=be,e[52]=oe,e[53]=Z,e[54]=ie,e[55]=pe,e[56]=me):me=e[56];let Se;e[57]!==A?(Se=A?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[57]=A,e[58]=Se):Se=e[58];let ke;e[59]!==R||e[60]!==D||e[61]!==E?(ke=E&&R?s.jsx("div",{className:Q("pointer-events-none absolute left-0 top-0 z-0 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",D&&"transition-[transform,width,height] duration-200 ease-out"),style:{transform:`translate(${R.left}px, ${R.top}px)`,width:`${R.width}px`,height:`${R.height}px`}}):null,e[59]=R,e[60]=D,e[61]=E,e[62]=ke):ke=e[62];let ye;if(e[63]!==T||e[64]!==r||e[65]!==m||e[66]!==y||e[67]!==v||e[68]!==M||e[69]!==w||e[70]!==A||e[71]!==n||e[72]!==a||e[73]!==o||e[74]!==I||e[75]!==E){let Ge;e[77]!==T||e[78]!==r||e[79]!==m||e[80]!==y||e[81]!==v||e[82]!==M||e[83]!==w||e[84]!==A||e[85]!==a||e[86]!==o||e[87]!==I||e[88]!==E?(Ge=Le=>{const qe=Le.id===r,rt=v&&E&&!qe&&!!Le.icon,st=!rt,it=v&&E&&qe&&!A&&!I,lt=Le.closable!==!1&&!!a,He=A||I?void 0:E?it?"flex-none basis-auto":w?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0";return s.jsx(T,{id:Le.id,className:He,children:s.jsxs("div",{ref:Oe=>te(Le.id,Oe),className:Q("group flex h-full items-center",A||I?"shrink-0":E?"w-full":"w-full min-w-0",E?"relative z-10 bg-transparent":qe?"border-r border-border/40 bg-[var(--surface-elevated)] text-foreground":"border-r border-border/40 bg-[var(--surface-elevated)]/25 text-muted-foreground hover:bg-[var(--surface-elevated)]/65 hover:text-foreground"),children:[s.jsx("button",{type:"button",role:"tab","aria-selected":qe,"aria-label":rt?Le.title??Le.label:void 0,onClick:()=>o(Le.id),className:Q(E?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 items-center justify-center rounded-lg text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 items-center typography-micro",E&&lt&&"!flex-none",E&&y?"lowercase":null,E&&(rt?"gap-0":"gap-1.5"),E?I?"shrink-0 whitespace-nowrap px-3 text-center":A?"max-w-56 shrink-0 px-3 text-center":rt?"px-2 !min-w-0 text-center":it?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":A?"max-w-56 justify-start truncate pl-3 pr-2 text-left":"w-full justify-center truncate px-2.5 text-center",E?m??(M?w?"h-[34px]":"h-[27px]":"h-7"):null,E?qe?"text-foreground":"text-muted-foreground hover:text-foreground":null,E?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:Le.title??Le.label,children:E?s.jsxs(s.Fragment,{children:[Le.icon?s.jsx("span",{className:"flex shrink-0 items-center justify-center",children:Le.icon}):null,st?s.jsx("span",{className:"animated-tabs__label truncate",children:Le.label}):null]}):s.jsxs("span",{className:Q("flex min-w-0 items-center gap-1.5",!A&&"justify-center"),children:[Le.icon?s.jsx("span",{className:"flex shrink-0 items-center justify-center",children:Le.icon}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:Le.label})]})}),lt?s.jsx("button",{type:"button",onPointerDown:Vv,onClick:Oe=>{Oe.stopPropagation(),a?.(Le.id)},className:Q("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",E?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",E?qe?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":qe?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":Le.closeLabel??`Close ${Le.label} tab`,title:Le.closeLabel??`Close ${Le.label} tab`,children:s.jsx(Ps,{className:"h-3 w-3"})}):null]})},Le.id)},e[77]=T,e[78]=r,e[79]=m,e[80]=y,e[81]=v,e[82]=M,e[83]=w,e[84]=A,e[85]=a,e[86]=o,e[87]=I,e[88]=E,e[89]=Ge):Ge=e[89],ye=n.map(Ge),e[63]=T,e[64]=r,e[65]=m,e[66]=y,e[67]=v,e[68]=M,e[69]=w,e[70]=A,e[71]=n,e[72]=a,e[73]=o,e[74]=I,e[75]=E,e[76]=ye}else ye=e[76];let Ne;e[90]!==me||e[91]!==Se||e[92]!==ke||e[93]!==ye?(Ne=s.jsxs("div",{ref:C,className:me,style:Se,role:"tablist","aria-label":"Tabs",children:[ke,ye]}),e[90]=me,e[91]=Se,e[92]=ke,e[93]=ye,e[94]=Ne):Ne=e[94];let _e;e[95]!==re||e[96]!==le||e[97]!==ae||e[98]!==Ne?(_e=s.jsxs("div",{className:re,children:[le,ae,Ne]}),e[95]=re,e[96]=le,e[97]=ae,e[98]=Ne,e[99]=_e):_e=e[99];const de=_e;if(!L)return de;let we;e[100]===Symbol.for("react.memo_cache_sentinel")?(we=[Tv],e[100]=we):we=e[100];let je;e[101]!==F||e[102]!==de?(je=s.jsx(X0,{items:F,strategy:Ig,children:de}),e[101]=F,e[102]=de,e[103]=je):je=e[103];let Ce;e[104]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(Q0,{dropAnimation:null}),e[104]=Ce):Ce=e[104];let ze;return e[105]!==K||e[106]!==Y||e[107]!==je?(ze=s.jsxs(C1,{sensors:Y,collisionDetection:A1,onDragEnd:K,modifiers:we,children:[je,Ce]}),e[105]=K,e[106]=Y,e[107]=je,e[108]=ze):ze=e[108],ze};function zv(t){return t.isMobile}function Lv(t){return t.id}function Hv(t,e){return!t||!e?t===e:Math.abs(t.left-e.left)<.5&&Math.abs(t.top-e.top)<.5&&Math.abs(t.width-e.width)<.5&&Math.abs(t.height-e.height)<.5}function $v(t){return t===null?t:null}function Ov(t){return t===null?t:null}function Vv(t){t.stopPropagation()}function O3(t){const e=Fe.c(14);let n,r,o,a;e[0]!==t?({size:o,className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a):(n=e[1],r=e[2],o=e[3],a=e[4]);const l=typeof o=="number"?`${o}px`:o,i=typeof o=="number"?`${o}px`:o;let c;e[5]!==a||e[6]!==l||e[7]!==i?(c={width:l,height:i,...a},e[5]=a,e[6]=l,e[7]=i,e[8]=c):c=e[8];let u;e[9]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=u):u=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==c?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:c,...r,children:u}),e[10]=n,e[11]=r,e[12]=c,e[13]=m):m=e[13],m}const Oo=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"}];Oo.reduce((t,e)=>(t[e.id]=e,t),{});const R6=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),Ao=t=>{const e=R6(t);return e===null?"-":`${e}%`},z6=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",i2=t=>t==="5h"?"5-Hour":t==="7d"?"7-Day Limit":t==="7d-sonnet"?"7-Day Sonnet Limit":t==="7d-opus"?"7-Day Opus Limit":t==="weekly"?"Weekly Limit":t==="daily"?"Daily":t==="monthly"?"Monthly Limit":t==="credits"?"Credits":t==="session"?"Session":t==="premium"?"Premium Interactions":t==="chat"?"Chat Requests":t==="completions"?"Completions":t==="premium_interactions"?"Premium interactions":t,Uv=t=>{const e=t.toLowerCase().trim();if(e==="5h")return 5*3600;if(e==="7d"||e==="weekly"||e==="7d-sonnet"||e==="7d-opus")return 7*86400;if(e==="monthly")return 30*86400;if(e==="24h"||e==="daily")return 86400;if(e==="1h")return 3600;const n=e.match(/^(\d+)h$/);if(n)return parseInt(n[1],10)*3600;const r=e.match(/^(\d+)d$/);return r?parseInt(r[1],10)*86400:null},ci=(t,e,n,r)=>{let o=n;if(o===null&&r&&(o=Uv(r)),t===null||e===null||o===null||o<=0)return null;const a=Date.now(),l=Math.max(0,(e-a)/1e3),i=Math.max(0,Math.min(o,o-l)),c=Math.max(0,Math.min(1,i/o)),u=t/100,m=t>=100&&l>0;let f;c>.01?f=Math.min(999,u/c*100):f=t;let h;m?h="exhausted":u<=c?h="on-track":f<=130?h="slightly-fast":h="too-fast";const p=o>=120*3600,g=p?86400:3600,x=p?"d":"h",b=o/g,v=Math.max(i/g,b*.01),y=t/v,w=Number.isFinite(y)?`${Math.min(999.9,Math.max(0,y)).toFixed(1)}%/${x}`:"-",C=f>100?`+${Math.round(f)}%`:`${Math.round(f)}%`;let N=null;const S=o/86400;return S>=7&&(N=100/S),{elapsedRatio:c,usageRatio:u,predictedFinalPercent:f,remainingSeconds:l,isExhausted:m,elapsedSeconds:i,totalSeconds:o,status:h,paceRateText:w,predictText:C,dailyAllocationPercent:N}},Wv=t=>{switch(t){case"exhausted":case"too-fast":return"var(--status-error)";case"slightly-fast":return"var(--status-warning)";case"on-track":return"var(--status-success)"}},V3=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),o=Math.floor(r/24),a=r%24,l=n%60;return o>0?`${o}d ${a}h`:r>0?`${r}h`:n===0?"<1m":`${l}m`},Mo=t=>Math.min(100,Math.max(0,t*100));function c2(t){const e=t.indexOf("/");if(e!==-1){const n=t.substring(0,e);if(n==="gemini"||n==="antigravity")return t.substring(e+1)}return t}const qv=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],L6={google:qv};function H6(t,e){const n=L6[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function $6(t){return L6[t]??[]}function O6(t){return[...t].sort((e,n)=>e.order-n.order)}function Gv(t,e){const n=new Map;for(const r of Object.keys(t)){const a=H6(r,e)?.id??null;n.has(a)||n.set(a,[]),n.get(a).push(r)}return n}function Zv(t,e,n){const r=new Map;for(const o of t){const a=e(o),i=H6(a,n)?.id??null;r.has(i)||r.set(i,[]),r.get(i).push(o)}return r}function Kv(t,e){return e.filter(n=>{const r=n.toLowerCase(),o=r.includes("/")?r.split("/")[1]:r;return!!(o.startsWith("gemini-3-")||o.startsWith("claude-"))})}const Ru=6e4,U3=t=>{const e=Oo.map(f=>f.id),n=typeof t?.usageAutoRefresh=="boolean"?t.usageAutoRefresh:!1,r=typeof t?.usageRefreshIntervalMs=="number"&&Number.isFinite(t.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(t.usageRefreshIntervalMs))):Ru,o=t?.usageDisplayMode==="remaining"?"remaining":"usage",a=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,l=a?a.filter(f=>typeof f=="string"&&e.includes(f)):e,i={},c=t?.usageSelectedModels;if(c&&typeof c=="object")for(const[f,h]of Object.entries(c))Array.isArray(h)&&(i[f]=h.filter(p=>typeof p=="string"));const u={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[f,h]of Object.entries(m))Array.isArray(h)&&(u[f]=h.filter(p=>typeof p=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:o,dropdownProviderIds:l,selectedModels:i,expandedFamilies:u}},Yv=async()=>{const t=Ho()?.settings;if(t)try{const n=(await t.load())?.settings;return U3(n??null)}catch{}if(!xn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return U3(n)}}return{autoRefresh:!1,refreshIntervalMs:Ru,displayMode:"usage",dropdownProviderIds:Oo.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ws=Dr()(wa((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Ru,displayMode:"usage",dropdownProviderIds:Oo.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Yv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Oo.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const o=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:o})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),o=await r.json().catch(()=>null);if(!r.ok)throw new Error(o?.error||"Failed to fetch quota");const a=o;t(l=>{const i=l.results.filter(c=>c.providerId!==n);return i.push(a),{results:i,error:null}})}catch(r){const o=r instanceof Error?r.message:"Failed to fetch quota",a={providerId:n,providerName:n,ok:!1,configured:!1,error:o,usage:null,fetchedAt:Date.now()};t(l=>{const i=l.results.filter(c=>c.providerId!==n);return i.push(a),{results:i,error:o}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(o=>({selectedModels:{...o.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(o=>{const a=o.selectedModels[n]??[],i=a.includes(r)?a.filter(c=>c!==r):[...a,r];return{selectedModels:{...o.selectedModels,[n]:i}}})},setExpandedFamilies:(n,r)=>{t(o=>({expandedFamilies:{...o.expandedFamilies,[n]:r}})),ln({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{t(o=>{const a=o.expandedFamilies[n]??[],i=a.includes(r)?a.filter(c=>c!==r):[...a,r];return{expandedFamilies:{...o.expandedFamilies,[n]:i}}}),ln({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const a=Kv(n,r);a.length!==0&&(t(l=>({selectedModels:{...l.selectedModels,[n]:a}})),ln({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),zu=()=>{const t=Fe.c(5),e=Ws(Xv),n=Ws(Qv),r=Ws(Jv);let o,a;t[0]!==e||t[1]!==r||t[2]!==n?(o=()=>{if(!e)return;const l=window.setInterval(()=>{r()},n);return()=>window.clearInterval(l)},a=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=o,t[4]=a):(o=t[3],a=t[4]),d.useEffect(o,a)};function Xv(t){return t.autoRefresh}function Qv(t){return t.refreshIntervalMs}function Jv(t){return t.fetchAllQuotas}const lr=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==="/",a=/^[A-Za-z]:\/$/.test(r);return!o&&!a&&(r=r.replace(/\/+$/,"")),r},W3=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,mc=(t,e)=>{const n=lr(e),r=lr(t);if(!n||!r)return!1;const o=W3(n),a=W3(r);return a===o||a.startsWith(`${o}/`)},ey=t=>{if(!t||typeof t!="object")return{};const e=t,n={};for(const[r,o]of Object.entries(e)){const a=lr(r);if(!a||!o||typeof o!="object")continue;const l=o,i=Array.isArray(l.openPaths)?Array.from(new Set(l.openPaths.filter(p=>typeof p=="string").map(p=>lr(p)).filter(p=>mc(p,a)))):[],c=Array.isArray(l.expandedPaths)?Array.from(new Set(l.expandedPaths.filter(p=>typeof p=="string").map(p=>lr(p)).filter(p=>mc(p,a)))):[],u=typeof l.selectedPath=="string"?lr(l.selectedPath):null,m=u&&mc(u,a)?u:i[0]??null,f=typeof l.touchedAt=="number"&&Number.isFinite(l.touchedAt)?l.touchedAt:Date.now(),h=n[a];if(h){const p=Array.from(new Set([...h.openPaths,...i])),g=Array.from(new Set([...h.expandedPaths,...c])),x=h.selectedPath??m??p[0]??null;n[a]={openPaths:p,selectedPath:x,expandedPaths:g,touchedAt:Math.max(h.touchedAt,f)};continue}n[a]={openPaths:i,selectedPath:m,expandedPaths:c,touchedAt:f}}return n},nl=(t,e)=>{const n=Object.entries(t);if(n.length<=e)return t;n.sort((o,a)=>(a[1]?.touchedAt??0)-(o[1]?.touchedAt??0));const r={};for(const[o,a]of n.slice(0,e))r[o]=a;return r},Oi=t=>t?{...t,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},vr=Dr()(wa(Pl((t,e)=>({byRoot:{},addOpenPath:(n,r)=>{const o=lr((n||"").trim()),a=lr((r||"").trim());!o||!a||t(l=>{const i=l.byRoot[o],c=Oi(i),u=c.openPaths.includes(a),m=u?c.openPaths:[...c.openPaths,a],f=c.selectedPath??a;if(i&&u&&i.selectedPath===f)return l;const h={...l.byRoot,[o]:{...c,openPaths:m,selectedPath:f}};return{byRoot:nl(h,20)}})},removeOpenPath:(n,r)=>{const o=lr((n||"").trim()),a=lr((r||"").trim());!o||!a||t(l=>{const i=l.byRoot[o];if(!i||!i.openPaths.includes(a)&&i.selectedPath!==a)return l;const c=i.openPaths.filter(f=>f!==a),u=i.selectedPath===a?c[0]??null:i.selectedPath,m={...l.byRoot,[o]:{...i,openPaths:c,selectedPath:u,touchedAt:Date.now()}};return{byRoot:nl(m,20)}})},removeOpenPathsByPrefix:(n,r)=>{const o=lr((n||"").trim()),a=lr((r||"").trim());!o||!a||t(l=>{const i=l.byRoot[o];if(!i)return l;const c=a.endsWith("/")?a:`${a}/`,u=i.openPaths.filter(h=>h!==a&&!h.startsWith(c));if(u.length===i.openPaths.length)return l;const m=i.selectedPath&&(i.selectedPath===a||i.selectedPath.startsWith(c))?u[0]??null:i.selectedPath,f={...l.byRoot,[o]:{...i,openPaths:u,selectedPath:m,touchedAt:Date.now()}};return{byRoot:nl(f,20)}})},setSelectedPath:(n,r)=>{const o=lr((n||"").trim()),a=r?lr(r.trim()):null;o&&t(l=>{const i=l.byRoot[o],c=Oi(i),u=a&&!c.openPaths.includes(a)?[...c.openPaths,a]:c.openPaths;if(i&&i.selectedPath===a&&u===i.openPaths)return l;const m={...l.byRoot,[o]:{...c,openPaths:u,selectedPath:a}};return{byRoot:nl(m,20)}})},ensureSelectedPath:n=>{const r=lr((n||"").trim());if(!r)return;const o=e().byRoot[r];if(!o||o.selectedPath)return;const a=o.openPaths[0]??null;a&&e().setSelectedPath(r,a)},toggleExpandedPath:(n,r)=>{const o=lr((n||"").trim()),a=lr((r||"").trim());!o||!a||t(l=>{const i=l.byRoot[o],c=Oi(i),m=c.expandedPaths.includes(a)?c.expandedPaths.filter(h=>h!==a):[...c.expandedPaths,a];if(i&&i.expandedPaths===m&&i.selectedPath===c.selectedPath&&i.openPaths===c.openPaths)return l;const f={...l.byRoot,[o]:{...c,expandedPaths:m}};return{byRoot:nl(f,20)}})},expandPath:(n,r)=>{const o=lr((n||"").trim()),a=lr((r||"").trim());!o||!a||t(l=>{const i=l.byRoot[o],c=Oi(i);if(c.expandedPaths.includes(a)&&i)return l;const m={...l.byRoot,[o]:{...c,expandedPaths:[...c.expandedPaths,a]}};return{byRoot:nl(m,20)}})},expandPaths:(n,r)=>{const o=lr((n||"").trim());if(!o||!r||r.length===0)return;const a=r.map(l=>lr((l||"").trim())).filter(Boolean);t(l=>{const i=l.byRoot[o],c=Oi(i),u=new Set(c.expandedPaths),m=a.filter(h=>!u.has(h));if(m.length===0)return l;const f={...l.byRoot,[o]:{...c,expandedPaths:[...c.expandedPaths,...m]}};return{byRoot:nl(f,20)}})}}),{name:"files-view-tabs-store",version:2,storage:Ii(()=>Ko()),migrate:t=>{if(!t||typeof t!="object")return{byRoot:{}};const e=t.byRoot;return{byRoot:ey(e)}},partialize:t=>({byRoot:t.byRoot})}),{name:"files-view-tabs-store"})),_d=1e4,ty=3e4,sy=15e3,ny=4e4,ry=5e3,oy=1e4,ay=6e4,q3=25,ly=40,iy=4,G3=15e3,Z3=3,cy=30,dy=20*1024*1024,K3=new Map,V6=new Map,s0=new Map,$0=t=>V6.get(t)??0,n0=t=>{const e=$0(t)+1;return V6.set(t,e),e},uy=t=>{const e=K3.get(t);if(e)return e;const n=new Set;return K3.set(t,n),n},qo=()=>({isGitRepo:null,status:null,branches:null,log:null,identity:null,diffCache:new Map,lastRepoCheckAt:0,lastStatusFetch:0,lastStatusChange:0,lastLogFetch:0,logMaxCount:25}),Y3=(t,e=cy,n=dy)=>{let r=0;for(const i of t.values())r+=(i.original?.length??0)+(i.modified?.length??0);if(t.size<=e&&r<=n)return t;const o=Array.from(t.entries()).sort((i,c)=>i[1].fetchedAt-c[1].fetchedAt),a=new Map;let l=0;for(let i=o.length-1;i>=0;i--){const[c,u]=o[i],m=(u.original?.length??0)+(u.modified?.length??0);if(a.size>=e)break;l+m>n&&a.size>0||(a.set(c,u),l+=m)}return a},fy=(t,e)=>{if(!t&&!e)return!1;if(!t||!e)return!0;const n=new Set([...Object.keys(t),...Object.keys(e)]);for(const r of n){const o=t[r],a=e[r];if(!(!o&&!a)&&(!o||!a||o.insertions!==a.insertions||o.deletions!==a.deletions))return!0}return!1},my=(t,e)=>{if(!t&&!e)return!1;if(!t||!e)return!0;const n=t.files??[],r=e.files??[];if(n.length!==r.length||t.ahead!==e.ahead||t.behind!==e.behind||t.current!==e.current||t.tracking!==e.tracking||t.isClean!==e.isClean)return!0;const o=new Set(n.map(a=>`${a.path}:${a.index}:${a.working_dir}`));for(const a of r)if(!o.has(`${a.path}:${a.index}:${a.working_dir}`))return!0;return!!fy(t.diffStats,e.diffStats)},hy=(t,e)=>{const n=new Set;if(!e)return n;const r=t?.files??[],o=e.files??[],a=new Map(r.map(f=>[f.path,f])),l=new Map(o.map(f=>[f.path,f])),i=new Set([...a.keys(),...l.keys()]);for(const f of i){const h=a.get(f),p=l.get(f);if(!h||!p){n.add(f);continue}if(h.index!==p.index||h.working_dir!==p.working_dir){n.add(f);continue}}const c=t?.diffStats??{},u=e.diffStats??{},m=new Set([...Object.keys(c),...Object.keys(u)]);for(const f of m){const h=c[f],p=u[f];if(!h||!p){n.add(f);continue}(h.insertions!==p.insertions||h.deletions!==p.deletions)&&n.add(f)}return n},hc=t=>t==="busy"?{base:sy,max:ny}:{base:_d,max:ty},Wn=Dr()(wa((t,e)=>({directories:new Map,activeDirectory:null,recentDirectories:[],isLoadingStatus:!1,isLoadingLog:!1,isLoadingBranches:!1,isLoadingIdentity:!1,pollIntervalId:null,currentPollInterval:_d,pollingMode:"normal",setActiveDirectory:n=>{const{activeDirectory:r,directories:o,recentDirectories:a}=e();if(r===n)return;r&&n0(r),n&&n0(n);const l=n?[n,...a.filter(i=>i!==n)].slice(0,Z3):a;if(n&&!o.has(n)){const i=new Map(o);i.set(n,qo()),t({activeDirectory:n,recentDirectories:l,directories:i})}else t({activeDirectory:n,recentDirectories:l})},getDirectoryState:n=>e().directories.get(n)??null,fetchStatus:async(n,r,o={})=>{const a=s0.get(n);if(a)return a;const l=(async()=>{const{silent:i=!1}=o,{directories:c}=e();let u=c.get(n);u||(u=qo()),i||t({isLoadingStatus:!0});let m=!1;try{const f=Date.now(),h=u.isGitRepo!==!0||f-(u.lastRepoCheckAt||0)>ay;let p=u.isGitRepo===!0;if(h&&(p=await r.checkIsGitRepository(n)),!p){const x=new Map(c);return x.set(n,{...u,isGitRepo:!1,status:null,lastRepoCheckAt:f,lastStatusFetch:f}),t({directories:x,isLoadingStatus:!1}),!1}const g=await r.getGitStatus(n);if(my(u.status,g)){m=!0;const x=new Map(e().directories),b=x.get(n)??qo(),v=hy(b.status,g),y=new Set((b.status?.files??[]).map(S=>S.path)),w=new Set((g.files??[]).map(S=>S.path)),C=new Map(b.diffCache);for(const S of y)w.has(S)||C.delete(S);for(const S of v)C.delete(S);const N=v.size>0;N&&n0(n),x.set(n,{...b,isGitRepo:!0,status:g,diffCache:C,lastRepoCheckAt:h?f:b.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:N?Date.now():b.lastStatusChange}),t({directories:x})}else{const x=new Map(e().directories),b=x.get(n)??qo();x.set(n,{...b,isGitRepo:!0,lastRepoCheckAt:h?f:b.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:b.lastStatusChange}),t({directories:x})}}catch(f){console.error("Failed to fetch git status:",f)}finally{i||t({isLoadingStatus:!1})}return m})();s0.set(n,l);try{return await l}finally{s0.get(n)===l&&s0.delete(n)}},fetchBranches:async(n,r)=>{t({isLoadingBranches:!0});try{const o=await r.getGitBranches(n),a=new Map(e().directories),l=a.get(n)??qo();a.set(n,{...l,branches:o}),t({directories:a})}catch(o){console.error("Failed to fetch git branches:",o)}finally{t({isLoadingBranches:!1})}},fetchLog:async(n,r,o)=>{const{directories:a}=e(),l=a.get(n),i=o??l?.logMaxCount??25;t({isLoadingLog:!0});try{const c=await r.getGitLog(n,{maxCount:i}),u=new Map(e().directories),m=u.get(n)??qo();u.set(n,{...m,log:c,lastLogFetch:Date.now(),logMaxCount:i}),t({directories:u})}catch(c){console.error("Failed to fetch git log:",c)}finally{t({isLoadingLog:!1})}},fetchIdentity:async(n,r)=>{t({isLoadingIdentity:!0});try{const o=await r.getCurrentGitIdentity(n),a=new Map(e().directories),l=a.get(n)??qo();a.set(n,{...l,identity:o}),t({directories:a})}catch(o){console.error("Failed to fetch git identity:",o)}finally{t({isLoadingIdentity:!1})}},fetchAll:async(n,r,o={})=>{const{directories:a}=e();let l=a.get(n);if(!l){l=qo();const h=new Map(a);h.set(n,l),t({directories:h})}const{force:i=!1,silentIfCached:c=!1}=o,u=Date.now();await e().fetchStatus(n,r,{silent:c&&!!l?.status});const m=e().directories.get(n);if(!m?.isGitRepo)return;await e().fetchBranches(n,r);const f=u-(m.lastLogFetch||0);(i||f>oy||!m.log)&&await e().fetchLog(n,r),await e().fetchIdentity(n,r),e().fetchAllDiffs(n,r)},getDiff:(n,r)=>e().directories.get(n)?.diffCache.get(r)??null,setDiff:(n,r,o)=>{const a=new Map(e().directories),l=a.get(n)??qo(),i=new Map(l.diffCache);i.set(r,{...o,fetchedAt:Date.now()});const c=Y3(i);a.set(n,{...l,diffCache:c}),t({directories:a})},clearDiffCache:n=>{n0(n);const r=new Map(e().directories),o=r.get(n);o&&(r.set(n,{...o,diffCache:new Map}),t({directories:r}))},fetchAllDiffs:async(n,r)=>{const o=e().directories.get(n);if(!o?.status?.files||o.status.files.length===0)return;const a=o.status.files.map(l=>l.path).slice(0,q3);await e().prefetchDiffs(n,r,a,{maxFiles:q3})},prefetchDiffs:async(n,r,o,a={})=>{const l=e().directories.get(n);if(!l?.status?.files||l.status.files.length===0||o.length===0)return;const{maxFiles:i=ly}=a,c=new Set(l.status.files.map(F=>F.path)),u=uy(n),m=[],f=new Set;for(const F of o)!F||f.has(F)||(f.add(F),c.has(F)&&(l.diffCache.has(F)||u.has(F)||m.push(F)));const h=m.slice(0,Math.max(1,i));if(h.length===0)return;const p=$0(n);if(typeof document<"u"&&document.hidden)return;h.forEach(F=>u.add(F));let g=0;const x=[],b=()=>{const F=g;return g+=1,F<h.length?h[F]:null},v=async F=>{const A=r.getGitFileDiff(n,{path:F}),M=new Promise((E,I)=>{setTimeout(()=>I(new Error(`Timed out after ${G3}ms`)),G3)}),B=await Promise.race([A,M]);return{path:F,diff:{original:B.original??"",modified:B.modified??"",isBinary:B.isBinary}}},y=async()=>{for(;;){if(p!==$0(n))return;const F=b();if(!F)return;try{x.push(await v(F))}catch{}finally{u.delete(F)}}},w=Math.min(iy,h.length);if(await Promise.allSettled(Array.from({length:w},()=>y())),h.forEach(F=>u.delete(F)),p!==$0(n))return;const C=new Map(e().directories),N=C.get(n);if(!N)return;const S=new Map(N.diffCache),k=Date.now();x.forEach(F=>{S.set(F.path,{...F.diff,fetchedAt:k})});const j=Y3(S);C.set(n,{...N,diffCache:j}),t({directories:C})},setLogMaxCount:(n,r)=>{const o=new Map(e().directories),a=o.get(n)??qo();o.set(n,{...a,logMaxCount:r}),t({directories:o})},setPollingMode:n=>{const{pollingMode:r,currentPollInterval:o}=e();if(r===n)return;const a=hc(n),l=Math.min(Math.max(o,a.base),a.max);t({pollingMode:n,currentPollInterval:l})},startPolling:n=>{const{pollIntervalId:r}=e();if(r)return;const o=()=>{const{currentPollInterval:l}=e();return setTimeout(async()=>{if(typeof document<"u"&&document.hidden){t({pollIntervalId:o()});return}const{activeDirectory:c,recentDirectories:u}=e();if(!c){t({pollIntervalId:o()});return}const m=[c,...u.filter(g=>g!==c).slice(0,Math.max(0,Z3-1))];let f=!1;for(const g of m)await e().fetchStatus(g,n,{silent:!0})&&(f=!0,g===c&&(await e().fetchLog(c,n),e().fetchAllDiffs(c,n)));const h=hc(e().pollingMode);if(f)t({currentPollInterval:h.base});else{const g=Math.min(l+ry,h.max);t({currentPollInterval:g})}const{pollIntervalId:p}=e();p!==null&&t({pollIntervalId:o()})},l)},a=hc(e().pollingMode);t({pollIntervalId:o(),currentPollInterval:a.base})},stopPolling:()=>{const{pollIntervalId:n}=e();n&&(clearTimeout(n),t({pollIntervalId:null,currentPollInterval:_d,pollingMode:"normal"}))},refresh:async(n,r={})=>{const{activeDirectory:o}=e();o&&await e().fetchAll(o,n,r)}}),{name:"git-store"})),q2=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.status??null:null,e[0]=t,e[1]=n):n=e[1],Wn(n)},G2=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.branches??null:null,e[0]=t,e[1]=n):n=e[1],Wn(n)},py=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.log??null:null,e[0]=t,e[1]=n):n=e[1],Wn(n)},gy=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.identity??null:null,e[0]=t,e[1]=n):n=e[1],Wn(n)},U6=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.isGitRepo??null:null,e[0]=t,e[1]=n):n=e[1],Wn(n)},xy=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.status?.files?.length??0:0,e[0]=t,e[1]=n):n=e[1],Wn(n)},by=9e4,vy=15e3,yy=5*6e4,wy=[2e3,5e3],jy=6e4,ky=2*6e4,Ny=5*6e4,Sy=720*6e4,Cy="openchamber.github-pr-status",Ay=t=>t==="closed"||t==="merged",My=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Ed=(t,e,n)=>`${t}::${e}`,r0=new Map,o0=new Map,Vi=new Set,X3=new Map,ql=new Set,r1=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),d2=t=>t?.params?.directory&&t.params.branch?{directory:t.params.directory,branch:t.params.branch,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null}:!t?.identity?.directory||!t.identity.branch?null:t.identity,Lu=t=>{const e=d2(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},W6=(t,e)=>Object.entries(t).filter(([,n])=>Lu(n)===e).map(([n])=>n),Fy=(t,e)=>{const n=e.remoteName??t.params?.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null;return{...t,params:t.params?{...t.params,...e,remoteName:n}:{...e,remoteName:n},identity:{directory:e.directory,branch:e.branch,remoteName:n}}},a0=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},By=(t,e,n)=>{const r=W6(t,e),o=r.map(c=>a0(t[c])).filter(c=>!!c);if(o.length===0)return null;const a=a0(t[n]);if(a&&Lu(t[n])===e)return a;const l=r.map(c=>t[c]).find(c=>!!(c?.resolvedRemoteName&&a0(c)));if(l)return a0(l);const i=o.find(c=>!!c.remoteName);return i||(o[0]??null)},_y=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:d2(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),Ey=t=>({...r1(),status:t?.status??null,isInitialStatusResolved:t?.isInitialStatusResolved??!1,lastRefreshAt:t?.lastRefreshAt??0,lastDiscoveryPollAt:t?.lastDiscoveryPollAt??0,identity:t?.identity??null,resolvedRemoteName:t?.resolvedRemoteName??t?.status?.resolvedRemoteName??null}),mo=Dr()(Pl((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:r1()}})},setParams:(n,r)=>{t(o=>{const a=o.entries[n]??r1();return{entries:{...o.entries,[n]:Fy(a,r)}}})},startWatching:n=>{if(t(a=>{const l=a.entries[n]??r1();return{entries:{...a.entries,[n]:{...l,watchers:l.watchers+1}}}}),r0.has(n))return;const r=a=>{const l=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const c=e().entries[n];!c||c.watchers<=0||c.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},a),i=o0.get(n)??[];i.push(l),o0.set(n,i)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),wy.forEach(a=>r(a));const o=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const a=e().entries[n];if(!a||a.watchers<=0)return;if(!!!a.status?.pr){const u=Date.now();if(u-a.lastDiscoveryPollAt<yy)return;t(m=>{const f=m.entries[n];return f?{entries:{...m.entries,[n]:{...f,lastDiscoveryPollAt:u}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(Ay(a.status?.pr?.state))return;const i=Date.now()-a.lastRefreshAt,c=My(a.status)?jy:a.status?.checks&&a.status.checks.state!=="pending"?Ny:ky;i<c||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},vy);r0.set(n,o)},stopWatching:n=>{t(l=>{const i=l.entries[n];if(!i)return l;const c=Math.max(0,i.watchers-1);return{entries:{...l.entries,[n]:{...i,watchers:c}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const o=r0.get(n);typeof o=="number"&&window.clearInterval(o),r0.delete(n);const a=o0.get(n);a&&a.length>0&&a.forEach(l=>{window.clearTimeout(l)}),o0.delete(n)},refresh:async(n,r)=>{const o=e(),a=o.entries[n],l=Lu(a);if(!a||!l)return;const i=W6(o.entries,l),c=i.some(f=>!!o.entries[f]?.status?.pr);if(r?.onlyExistingPr&&!c)return;const u=X3.get(l)??0;if(!r?.force&&Date.now()-u<by||Vi.has(l))return;const m=By(o.entries,l,n);if(m){if(Vi.add(l),X3.set(l,Date.now()),t(f=>{const h={...f.entries};return i.forEach(p=>{const g=h[p];g&&(h[p]={...g,lastRefreshAt:Date.now(),isLoading:r?.silent?g.isLoading:!0,error:null})}),{entries:h}}),m.githubAuthChecked&&m.githubConnected===!1){t(f=>{const h={...f.entries};return i.forEach(p=>{const g=h[p];g&&(h[p]={...g,status:{connected:!1},error:null,isLoading:r?.silent?g.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?g.isInitialStatusResolved:!0})}),{entries:h}}),Vi.delete(l);return}if(!m.github?.prStatus){t(f=>{const h={...f.entries};return i.forEach(p=>{const g=h[p];g&&(h[p]={...g,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?g.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?g.isInitialStatusResolved:!0})}),{entries:h}}),Vi.delete(l);return}try{t(h=>({...h,activeRequestCount:h.activeRequestCount+1,totalRequestCount:h.totalRequestCount+1}));const f=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0);t(h=>{const p={...h.entries};return i.forEach(g=>{const x=p[g];if(!x)return;const b=x.status?.pr,v=f.pr,w=!!(v&&b&&v.number===b.number&&(!v.body||!v.body.trim())&&typeof b.body=="string"&&b.body.trim().length>0)&&v&&b?.body?{...f,pr:{...v,body:b.body}}:f,C=w.resolvedRemoteName??x.resolvedRemoteName??m.remoteName??null,N=d2(x)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};p[g]={...x,status:w,error:null,isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0,resolvedRemoteName:C,identity:{...N,remoteName:C??N.remoteName??null}}}),{entries:p}})}catch(f){const h=f instanceof Error?f.message:String(f);t(p=>{const g={...p.entries};return i.forEach(x=>{const b=g[x];b&&(g[x]={...b,error:h||"Failed to load PR status",isLoading:r?.silent?b.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?b.isInitialStatusResolved:!0})}),{entries:g}})}finally{Vi.delete(l),t(f=>({...f,activeRequestCount:Math.max(0,f.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const o=Array.from(new Set(n.map(a=>{const l=a.directory.trim(),i=a.branch.trim();return!l||!i?null:Ed(l,i,a.remoteName??null)}).filter(a=>!!a)));await Promise.all(o.map(a=>e().refresh(a,r)))},updateStatus:(n,r)=>{t(o=>{const a=o.entries[n]??r1();return{entries:{...o.entries,[n]:{...a,status:r(a.status)}}}})},syncBackgroundTargets:({targets:n,github:r,githubAuthChecked:o,githubConnected:a})=>{if(!r||n.length===0){Array.from(ql).forEach(c=>{e().stopWatching(c),ql.delete(c)});return}const l=new Map;n.forEach(c=>{const u=c.directory.trim(),m=c.branch.trim();if(!u||!m)return;const f=Ed(u,m,c.remoteName??null);l.has(f)||l.set(f,{directory:u,branch:m,remoteName:c.remoteName??null})});const i=new Set(l.keys());Array.from(ql).forEach(c=>{i.has(c)||(e().stopWatching(c),ql.delete(c))}),l.forEach((c,u)=>{e().ensureEntry(u),e().setParams(u,{directory:c.directory,branch:c.branch,remoteName:c.remoteName??null,canShow:!0,github:r,githubAuthChecked:o,githubConnected:a}),ql.has(u)||(e().startWatching(u),ql.add(u))})}}),{name:Cy,storage:Ii(()=>Ko()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=d2(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<Sy}).map(([e,n])=>[e,_y(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([o,a])=>[o,Ey(a)]))}}})),Dy=async t=>{if(t)return await t.authStatus();const e=await fetch("/api/github/auth/status",{method:"GET",headers:{Accept:"application/json"}}),n=await e.json().catch(()=>null);if(!e.ok||!n)throw new Error(n?.error||e.statusText||"Failed to load GitHub status");return n},ir=Dr((t,e)=>({status:null,isLoading:!1,hasChecked:!1,setStatus:n=>t({status:n,hasChecked:!0}),refreshStatus:async(n,r)=>{const{hasChecked:o,status:a}=e();if(o&&!r?.force)return a;t({isLoading:!0});try{const l=await Dy(n);return t({status:l,isLoading:!1,hasChecked:!0}),l}catch(l){const i=l instanceof Error?l.message:String(l);return t({status:{connected:!1,error:i},isLoading:!1,hasChecked:!0}),null}}})),Z2=d.createContext(null),ur=()=>{const t=d.useContext(Z2);if(!t)throw new Error("Runtime APIs are not available. Did you forget to wrap the app in <RuntimeAPIProvider>?");return t},Iy=t=>{const e=Fe.c(3),n=ur();let r;return e[0]!==n||e[1]!==t?(r=t(n),e[0]=n,e[1]=t,e[2]=r):r=e[2],r},q6=()=>Iy(Ty);function Ty(t){return t.runtime.isVSCode}const Py=1e3,K2=t=>{const e=Fe.c(59),{containerRef:n,minThumbSize:r,hideDelayMs:o,className:a,disableHorizontal:l,observeMutations:i,suppressVisibility:c,userIntentOnly:u}=t,m=r===void 0?32:r,f=o===void 0?1e3:o,h=l===void 0?!1:l,p=i===void 0?!0:i,g=c===void 0?!1:c,x=u===void 0?!1:u,[b,v]=d.useState(!1);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y={length:0,offset:0},e[0]=y):y=e[0];const[w,C]=d.useState(y);let N;e[1]===Symbol.for("react.memo_cache_sentinel")?(N={length:0,offset:0},e[1]=N):N=e[1];const[S,k]=d.useState(N),j=d.useRef(null),F=d.useRef(null),A=d.useRef(null),M=d.useRef(!1),B=d.useRef(0);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E={pointerX:0,pointerY:0,scrollTop:0,scrollLeft:0},e[2]=E):E=e[2];const I=d.useRef(E),P=d.useRef(null);let D;e[3]!==n||e[4]!==h||e[5]!==m?(D=()=>{const ue=n.current;if(!ue)return;const{scrollHeight:be,clientHeight:oe,scrollTop:Z,scrollWidth:ie,clientWidth:pe,scrollLeft:me}=ue;if(be>oe){const Se=Math.max(oe-16,0),ke=oe/be*Se,ye=Math.max(m,Math.min(Se,ke)),Ne=Math.max(Se-ye,0),_e=Math.max(be-oe,1),de=Z/_e*Ne;C({length:ye,offset:de})}else C({length:0,offset:0});if(!h&&ie>pe){const Se=Math.max(pe-16,0),ke=pe/ie*Se,ye=Math.max(m,Math.min(Se,ke)),Ne=Math.max(Se-ye,0),_e=Math.max(ie-pe,1),de=me/_e*Ne;k({length:ye,offset:de})}else k({length:0,offset:0})},e[3]=n,e[4]=h,e[5]=m,e[6]=D):D=e[6];const L=D;let T;e[7]!==L?(T=()=>{A.current===null&&(A.current=requestAnimationFrame(()=>{A.current=null,L()}))},e[7]=L,e[8]=T):T=e[8];const _=T;let z;e[9]!==f?(z=()=>{j.current&&clearTimeout(j.current),j.current=setTimeout(()=>v(!1),f)},e[9]=f,e[10]=z):z=e[10];const R=z;let W;e[11]===Symbol.for("react.memo_cache_sentinel")?(W=()=>{B.current=Date.now()},e[11]=W):W=e[11];const G=W;let Y;e[12]!==R||e[13]!==g||e[14]!==L||e[15]!==x?(Y=()=>{F.current&&cancelAnimationFrame(F.current),F.current=requestAnimationFrame(()=>{if(L(),g&&!M.current){v(!1);return}if(x&&!M.current&&!(Date.now()-B.current<=Py)){v(!1);return}v(!0),R()})},e[12]=R,e[13]=g,e[14]=L,e[15]=x,e[16]=Y):Y=e[16];const J=Y;let V,te;e[17]!==n||e[18]!==J||e[19]!==p||e[20]!==_||e[21]!==L||e[22]!==x?(V=()=>{const ue=n.current;if(!ue)return;L(),v(!1);const be=()=>J(),oe=pe=>{(pe.key==="ArrowUp"||pe.key==="ArrowDown"||pe.key==="PageUp"||pe.key==="PageDown"||pe.key==="Home"||pe.key==="End"||pe.key===" ")&&G()};ue.addEventListener("scroll",be,{passive:!0}),x&&(ue.addEventListener("wheel",G,{passive:!0}),ue.addEventListener("touchstart",G,{passive:!0}),ue.addEventListener("touchmove",G,{passive:!0}),ue.addEventListener("keydown",oe));const Z=typeof ResizeObserver<"u"?new ResizeObserver(()=>{_()}):null;Z?.observe(ue);const ie=p&&typeof MutationObserver<"u"?new MutationObserver(()=>_()):null;return ie?.observe(ue,{childList:!0,subtree:!0,characterData:!0}),()=>{ue.removeEventListener("scroll",be),x&&(ue.removeEventListener("wheel",G),ue.removeEventListener("touchstart",G),ue.removeEventListener("touchmove",G),ue.removeEventListener("keydown",oe)),Z?.disconnect(),ie?.disconnect(),j.current&&clearTimeout(j.current),F.current&&cancelAnimationFrame(F.current),A.current&&cancelAnimationFrame(A.current)}},te=[n,J,G,p,_,L,x],e[17]=n,e[18]=J,e[19]=p,e[20]=_,e[21]=L,e[22]=x,e[23]=V,e[24]=te):(V=e[23],te=e[24]),d.useEffect(V,te);let U,X;e[25]!==g?(U=()=>{g&&(M.current||(v(!1),j.current&&(clearTimeout(j.current),j.current=null)))},X=[g],e[25]=g,e[26]=U,e[27]=X):(U=e[26],X=e[27]),d.useEffect(U,X);let $;e[28]!==n?($=(ue,be)=>{const oe=n.current;oe&&(M.current=!0,I.current={pointerX:ue.clientX,pointerY:ue.clientY,scrollTop:oe.scrollTop,scrollLeft:oe.scrollLeft},P.current=be,G(),v(!0),j.current&&clearTimeout(j.current),ue.currentTarget.setPointerCapture(ue.pointerId))},e[28]=n,e[29]=$):$=e[29];const q=$;let ee;e[30]!==n||e[31]!==S.length||e[32]!==w.length?(ee=ue=>{if(!M.current)return;const be=n.current;if(!be)return;const oe=P.current;if(oe==="vertical"){const{pointerY:Z,scrollTop:ie}=I.current,pe=ue.clientY-Z,me=be.clientHeight,Se=Math.max(me-w.length,1),ke=Math.max(be.scrollHeight-be.clientHeight,1),ye=pe/Se*ke;be.scrollTop=ie+ye}else if(oe==="horizontal"){const{pointerX:Z,scrollLeft:ie}=I.current,pe=ue.clientX-Z,me=be.clientWidth,Se=Math.max(me-S.length,1),ke=Math.max(be.scrollWidth-be.clientWidth,1),ye=pe/Se*ke;be.scrollLeft=ie+ye}},e[30]=n,e[31]=S.length,e[32]=w.length,e[33]=ee):ee=e[33];const ce=ee;let ve;e[34]!==R?(ve=ue=>{M.current&&(M.current=!1,ue.currentTarget.releasePointerCapture(ue.pointerId),R())},e[34]=R,e[35]=ve):ve=e[35];const ge=ve,xe=w.length>0,ne=S.length>0;if(!xe&&!ne)return null;let O;e[36]!==a?(O=Q("overlay-scrollbar",a),e[36]=a,e[37]=O):O=e[37];const H=b?1:0;let K;e[38]!==H?(K={opacity:H},e[38]=H,e[39]=K):K=e[39];let re;e[40]!==q||e[41]!==ce||e[42]!==ge||e[43]!==xe||e[44]!==w.length||e[45]!==w.offset?(re=xe&&s.jsx("div",{className:"overlay-scrollbar__thumb overlay-scrollbar__thumb--vertical",style:{height:`${w.length}px`,top:`${8+w.offset}px`,right:"4px"},onPointerDown:ue=>q(ue,"vertical"),onPointerMove:ce,onPointerUp:ge,onPointerCancel:ge}),e[40]=q,e[41]=ce,e[42]=ge,e[43]=xe,e[44]=w.length,e[45]=w.offset,e[46]=re):re=e[46];let le;e[47]!==q||e[48]!==ce||e[49]!==ge||e[50]!==S.length||e[51]!==S.offset||e[52]!==ne?(le=ne&&s.jsx("div",{className:"overlay-scrollbar__thumb overlay-scrollbar__thumb--horizontal",style:{width:`${S.length}px`,left:`${8+S.offset}px`,bottom:"4px"},onPointerDown:ue=>q(ue,"horizontal"),onPointerMove:ce,onPointerUp:ge,onPointerCancel:ge}),e[47]=q,e[48]=ce,e[49]=ge,e[50]=S.length,e[51]=S.offset,e[52]=ne,e[53]=le):le=e[53];let ae;return e[54]!==O||e[55]!==K||e[56]!==re||e[57]!==le?(ae=s.jsxs("div",{className:O,"aria-hidden":"true",style:K,children:[re,le]}),e[54]=O,e[55]=K,e[56]=re,e[57]=le,e[58]=ae):ae=e[58],ae};function Ry(...t){return e=>{t.forEach(n=>{typeof n=="function"?n(e):n&&typeof n=="object"&&(n.current=e)})}}const Qa=d.forwardRef((t,e)=>{const n=Fe.c(25),{as:r,orientation:o,offset:a,size:l,isEnabled:i,hideTopShadow:c,hideBottomShadow:u,observeMutations:m,onVisibilityChange:f,style:h,className:p,children:g,...x}=t,b=r===void 0?"div":r,v=o===void 0?"vertical":o,y=a===void 0?0:a,w=l===void 0?48:l,C=i===void 0?!0:i,N=c===void 0?!1:c,S=u===void 0?!1:u,k=m===void 0?!0:m,j=d.useRef(null),F=d.useRef("none"),A=x["data-scroll-shadow"];delete x["data-scroll-shadow"];const M=h;let B;n[0]!==w||n[1]!==M?(B={...M},B["--scroll-shadow-size"]=`${w}px`,n[0]=w,n[1]=M,n[2]=B):B=n[2];const E=B,I=zy,P=Ly;let D;n[3]!==S||n[4]!==N||n[5]!==C||n[6]!==y||n[7]!==f||n[8]!==v?(D=()=>{const Y=j.current;if(!Y)return;if(!C){P(Y);return}const J=v==="vertical"?Y.scrollTop>y:Y.scrollLeft>y;let V=v==="vertical"?Y.scrollTop+Y.clientHeight+y<Y.scrollHeight:Y.scrollLeft+Y.clientWidth+y<Y.scrollWidth;const te=N&&v==="vertical"?!1:J;S&&v==="vertical"&&(V=!1),I(Y,te,V,v==="vertical"?"top":"left",v==="vertical"?"bottom":"right");const U=te&&V?"both":te?v==="vertical"?"top":"left":V?v==="vertical"?"bottom":"right":"none";U!==F.current&&(F.current=U,f?.(U))},n[3]=S,n[4]=N,n[5]=C,n[6]=y,n[7]=f,n[8]=v,n[9]=D):D=n[9];const L=D;let T,_;n[10]!==L||n[11]!==k?(T=()=>{const Y=j.current;if(!Y)return;let J=null;const V=()=>{J===null&&(J=requestAnimationFrame(()=>{J=null,L()}))},te=()=>L(),U=typeof ResizeObserver<"u"?new ResizeObserver(V):null,X=k&&typeof MutationObserver<"u"?new MutationObserver(V):null;return L(),Y.addEventListener("scroll",te,{passive:!0}),U?.observe(Y),X?.observe(Y,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),()=>{J!==null&&cancelAnimationFrame(J),Y.removeEventListener("scroll",te),U?.disconnect(),X?.disconnect()}},_=[L,k],n[10]=L,n[11]=k,n[12]=T,n[13]=_):(T=n[12],_=n[13]),d.useEffect(T,_);const z=x;let R;n[14]!==e?(R=Ry(j,e),n[14]=e,n[15]=R):R=n[15];const W=A??!0;let G;return n[16]!==b||n[17]!==g||n[18]!==p||n[19]!==E||n[20]!==v||n[21]!==z||n[22]!==R||n[23]!==W?(G=s.jsx(b,{...z,ref:R,className:p,"data-orientation":v,"data-scroll-shadow":W,style:E,children:g}),n[16]=b,n[17]=g,n[18]=p,n[19]=E,n[20]=v,n[21]=z,n[22]=R,n[23]=W,n[24]=G):G=n[24],G});Qa.displayName="ScrollShadow";function zy(t,e,n,r,o){const a=`${r}${o.charAt(0).toUpperCase()}${o.slice(1)}Scroll`;e&&n?(t.dataset[a]="true",t.removeAttribute(`data-${r}-scroll`),t.removeAttribute(`data-${o}-scroll`)):(t.dataset[`${r}Scroll`]=String(e),t.dataset[`${o}Scroll`]=String(n),t.removeAttribute(`data-${r}-${o}-scroll`))}function Ly(t){["top","bottom","top-bottom","left","right","left-right"].forEach(e=>{t.removeAttribute(`data-${e}-scroll`)})}const ks=d.forwardRef((t,e)=>{const n=Fe.c(45);let r,o,a,l,i,c,u,m,f,h,p,g,x,b,v,y;n[0]!==t?({className:o,outerClassName:i,children:r,style:f,minThumbSize:l,hideDelayMs:a,as:h,scrollbarClassName:m,disableHorizontal:p,observeMutations:g,fillContainer:x,keyboardAvoid:b,preventOverscroll:v,useScrollShadow:y,scrollShadowSize:u,...c}=t,n[0]=t,n[1]=r,n[2]=o,n[3]=a,n[4]=l,n[5]=i,n[6]=c,n[7]=u,n[8]=m,n[9]=f,n[10]=h,n[11]=p,n[12]=g,n[13]=x,n[14]=b,n[15]=v,n[16]=y):(r=n[1],o=n[2],a=n[3],l=n[4],i=n[5],c=n[6],u=n[7],m=n[8],f=n[9],h=n[10],p=n[11],g=n[12],x=n[13],b=n[14],v=n[15],y=n[16]);const w=h===void 0?"div":h,C=p===void 0?!1:p,N=g===void 0?!0:g,S=x===void 0?!0:x,k=b===void 0?!1:b,j=v===void 0?!1:v,F=y===void 0?!1:y,A=d.useRef(null);let M,B;n[17]===Symbol.for("react.memo_cache_sentinel")?(M=()=>A.current,B=[],n[17]=M,n[18]=B):(M=n[17],B=n[18]),d.useImperativeHandle(e,M,B);const E=j&&"overscroll-none";let I;n[19]!==i||n[20]!==E?(I=Q("relative flex flex-col min-h-0 w-full overflow-hidden",E,i),n[19]=i,n[20]=E,n[21]=I):I=n[21];const P=k?"true":void 0;let D;n[22]!==w||n[23]!==r||n[24]!==o||n[25]!==C||n[26]!==S||n[27]!==N||n[28]!==j||n[29]!==c||n[30]!==u||n[31]!==f||n[32]!==F?(D=F?s.jsx(Qa,{as:w,ref:A,size:u,className:Q("overlay-scrollbar-target overlay-scrollbar-container",j&&"overscroll-none",S?"flex-1 min-h-0 w-full":"flex-none w-full h-auto",C?"overflow-y-auto overflow-x-hidden":"overflow-auto",o),style:f,observeMutations:N,...c,children:r}):s.jsx(w,{ref:A,className:Q("overlay-scrollbar-target overlay-scrollbar-container",j&&"overscroll-none",S?"flex-1 min-h-0 w-full":"flex-none w-full h-auto",C?"overflow-y-auto overflow-x-hidden":"overflow-auto",o),style:f,...c,children:r}),n[22]=w,n[23]=r,n[24]=o,n[25]=C,n[26]=S,n[27]=N,n[28]=j,n[29]=c,n[30]=u,n[31]=f,n[32]=F,n[33]=D):D=n[33];let L;n[34]!==C||n[35]!==a||n[36]!==l||n[37]!==N||n[38]!==m?(L=s.jsx(K2,{containerRef:A,minThumbSize:l,hideDelayMs:a,className:m,disableHorizontal:C,observeMutations:N}),n[34]=C,n[35]=a,n[36]=l,n[37]=N,n[38]=m,n[39]=L):L=n[39];let T;return n[40]!==I||n[41]!==P||n[42]!==D||n[43]!==L?(T=s.jsxs("div",{className:I,"data-keyboard-avoid":P,children:[D,L]}),n[40]=I,n[41]=P,n[42]=D,n[43]=L,n[44]=T):T=n[44],T});ks.displayName="ScrollableOverlay";const Q3="mobile-overlay-root",Hy=()=>{if(typeof document>"u")return null;let t=document.getElementById(Q3);return t||(t=document.createElement("div"),t.id=Q3,document.body.appendChild(t)),t},cr=({open:t,title:e,onClose:n,children:r,footer:o,className:a,contentMaxHeightClassName:l,renderHeader:i})=>{const c=d.useRef(null);if(typeof document<"u"&&!c.current&&(c.current=Hy()),d.useEffect(()=>{if(!t)return;const f=document.body.style.overflow;document.body.style.overflow="hidden";const h=p=>{p.key==="Escape"&&n()};return document.addEventListener("keydown",h),()=>{document.body.style.overflow=f,document.removeEventListener("keydown",h)}},[t,n]),!t||!c.current)return null;const u=l??"max-h-[min(70vh,520px)]",m=s.jsx("div",{"data-blur-bg":!0,className:"fixed inset-0 z-50 flex flex-col bg-background/40 backdrop-blur-sm",role:"dialog","aria-modal":"true",onClick:n,children:s.jsxs("div",{className:Q("mt-auto w-full rounded-t-xl border border-border/50 bg-background shadow-none pwa-overlay-panel","mx-auto max-w-lg",a),"data-keyboard-avoid":"true",onClick:f=>f.stopPropagation(),children:[(()=>{const f=s.jsx("button",{type:"button",onClick:n,className:"flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover",children:s.jsx(Ps,{className:"h-4 w-4"})});return i?i(f):s.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/40",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:e}),f]})})(),s.jsx(ks,{outerClassName:u,className:"px-2 py-2 pwa-overlay-scroll",children:r}),o?s.jsx("div",{className:"border-t border-border/40 px-3 py-2",children:o}):null]})});return To.createPortal(m,c.current)},G6=t=>{const e=Fe.c(79),{totalTokens:n,percentage:r,colorPercentage:o,contextLimit:a,outputLimit:l,size:i,isMobile:c,hideIcon:u,showPercentIcon:m,className:f,valueClassName:h,percentIconClassName:p,onClick:g,pressed:x}=t,b=i===void 0?"default":i,v=c===void 0?!1:c,y=u===void 0?!1:u,w=m===void 0?!1:m,C=x===void 0?!1:x,[N,S]=d.useState(!1),k=typeof o=="number"?o:r,j=$y,F=Oy,A=typeof l=="number"?Math.max(l,0):0;let M;e[0]!==n?(M=j(n),e[0]=n,e[1]=M):M=e[1];const B=`Used tokens: ${M}`;let E;e[2]!==a?(E=j(a),e[2]=a,e[3]=E):E=e[3];const I=`Context limit: ${E}`;let P;e[4]!==A?(P=j(A),e[4]=A,e[5]=P):P=e[5];const D=`Output limit: ${P}`;let L;e[6]!==D||e[7]!==B||e[8]!==I?(L=[B,I,D],e[6]=D,e[7]=B,e[8]=I,e[9]=L):L=e[9];const T=L,_=!v&&typeof g=="function";let z;e[10]!==y||e[11]!==v?(z=!v&&!y&&s.jsx(Tg,{className:"h-4 w-4 flex-shrink-0"}),e[10]=y,e[11]=v,e[12]=z):z=e[12];let R;e[13]!==h?(R=Q("font-medium inline-flex items-center gap-1.5",h),e[13]=h,e[14]=R):R=e[14];let W;e[15]!==k||e[16]!==p||e[17]!==r||e[18]!==w?(W=w?s.jsxs(s.Fragment,{children:[s.jsx(Sh,{className:Q("h-3.5 w-3.5",p,F(k)),"aria-hidden":"true"}),s.jsxs("span",{className:"text-foreground",children:[Math.min(r,999).toFixed(1),"%"]})]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:F(k),children:Math.min(r,999).toFixed(1)}),"%"]}),e[15]=k,e[16]=p,e[17]=r,e[18]=w,e[19]=W):W=e[19];let G;e[20]!==R||e[21]!==W?(G=s.jsx("span",{className:R,children:W}),e[20]=R,e[21]=W,e[22]=G):G=e[22];let Y;e[23]!==z||e[24]!==G?(Y=s.jsxs(s.Fragment,{children:[z,G]}),e[23]=z,e[24]=G,e[25]=Y):Y=e[25];const J=Y,V=b==="compact"?"typography-micro":"typography-meta";let te;e[26]!==f||e[27]!==_||e[28]!==V?(te=Q("app-region-no-drag flex items-center gap-1.5 select-none",V,_?Q("rounded-md px-2 py-1.5 text-foreground transition-colors","hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"):"text-muted-foreground/60",f),e[26]=f,e[27]=_,e[28]=V,e[29]=te):te=e[29];const U=te;let X;e[30]!==J||e[31]!==_||e[32]!==v||e[33]!==g||e[34]!==C||e[35]!==U?(X=_?s.jsx("button",{type:"button",className:U,"aria-label":"Context usage","aria-pressed":C,onClick:g,children:J}):s.jsx("div",{className:U,"aria-label":"Context usage",onClick:v?()=>S(!0):void 0,children:J}),e[30]=J,e[31]=_,e[32]=v,e[33]=g,e[34]=C,e[35]=U,e[36]=X):X=e[36];const $=X;if(v){let ve;e[37]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>S(!1),e[37]=ve):ve=e[37];let ge;e[38]===Symbol.for("react.memo_cache_sentinel")?(ge=s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Used tokens"}),e[38]=ge):ge=e[38];let xe;e[39]!==n?(xe=j(n),e[39]=n,e[40]=xe):xe=e[40];let ne;e[41]!==xe?(ne=s.jsxs("div",{className:"flex justify-between items-center",children:[ge,s.jsx("span",{className:"typography-meta text-foreground font-medium",children:xe})]}),e[41]=xe,e[42]=ne):ne=e[42];let O;e[43]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Context limit"}),e[43]=O):O=e[43];let H;e[44]!==a?(H=j(a),e[44]=a,e[45]=H):H=e[45];let K;e[46]!==H?(K=s.jsxs("div",{className:"flex justify-between items-center",children:[O,s.jsx("span",{className:"typography-meta text-foreground font-medium",children:H})]}),e[46]=H,e[47]=K):K=e[47];let re;e[48]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Output limit"}),e[48]=re):re=e[48];let le;e[49]!==A?(le=j(A),e[49]=A,e[50]=le):le=e[50];let ae;e[51]!==le?(ae=s.jsxs("div",{className:"flex justify-between items-center",children:[re,s.jsx("span",{className:"typography-meta text-foreground font-medium",children:le})]}),e[51]=le,e[52]=ae):ae=e[52];let ue;e[53]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Usage"}),e[53]=ue):ue=e[53];let be;e[54]!==k?(be=Q("typography-meta font-semibold",F(k)),e[54]=k,e[55]=be):be=e[55];const oe=Math.min(r,999);let Z;e[56]!==oe?(Z=oe.toFixed(1),e[56]=oe,e[57]=Z):Z=e[57];let ie;e[58]!==be||e[59]!==Z?(ie=s.jsxs("div",{className:"flex justify-between items-center pt-1 border-t border-border/40",children:[ue,s.jsxs("span",{className:be,children:[Z,"%"]})]}),e[58]=be,e[59]=Z,e[60]=ie):ie=e[60];let pe;e[61]!==ne||e[62]!==K||e[63]!==ae||e[64]!==ie?(pe=s.jsx("div",{className:"flex flex-col gap-1.5",children:s.jsxs("div",{className:"rounded-xl border border-border/40 bg-sidebar/30 px-3 py-2 space-y-1",children:[ne,K,ae,ie]})}),e[61]=ne,e[62]=K,e[63]=ae,e[64]=ie,e[65]=pe):pe=e[65];let me;e[66]!==N||e[67]!==pe?(me=s.jsx(cr,{open:N,onClose:ve,title:"Context Usage",children:pe}),e[66]=N,e[67]=pe,e[68]=me):me=e[68];let Se;return e[69]!==$||e[70]!==me?(Se=s.jsxs(s.Fragment,{children:[$,me]}),e[69]=$,e[70]=me,e[71]=Se):Se=e[71],Se}let q;e[72]!==$?(q=s.jsx(It,{asChild:!0,children:$}),e[72]=$,e[73]=q):q=e[73];let ee;e[74]!==T?(ee=s.jsx(_t,{children:s.jsx("div",{className:"space-y-0.5",children:T.map(Vy)})}),e[74]=T,e[75]=ee):ee=e[75];let ce;return e[76]!==q||e[77]!==ee?(ce=s.jsxs(Dt,{delayDuration:1e3,children:[q,ee]}),e[76]=q,e[77]=ee,e[78]=ce):ce=e[78],ce};function $y(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toFixed(1).replace(/\.0$/,"")}function Oy(t){return t>=90?"text-status-error":t>=75?"text-status-warning":"text-status-success"}function Vy(t){return s.jsx("p",{className:"typography-micro leading-tight",children:t},t)}const Ui={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536},Z6=(t,e,n)=>{if(typeof window>"u")return;const r=document.documentElement,o=e==="mobile",a=e==="tablet",l=Eu();r.classList.remove("device-mobile","device-tablet","device-desktop"),r.classList.add(e==="mobile"?"device-mobile":e==="tablet"?"device-tablet":"device-desktop"),t?(r.classList.add("desktop-runtime"),r.style.setProperty("--is-mobile","0"),r.style.setProperty("--device-type","desktop"),r.style.setProperty("--font-scale","1"),r.style.setProperty("--has-coarse-pointer","0"),r.style.setProperty("--has-touch-input","0"),r.classList.remove("mobile-pointer")):l?(r.classList.add("electron-runtime"),r.style.setProperty("--is-mobile","0"),r.style.setProperty("--device-type","desktop"),r.style.setProperty("--font-scale","1"),r.style.setProperty("--has-coarse-pointer","0"),r.style.setProperty("--has-touch-input","0"),r.classList.remove("mobile-pointer")):(r.classList.remove("desktop-runtime","electron-runtime"),r.style.setProperty("--is-mobile",o?"1":"0"),r.style.setProperty("--device-type",e),r.style.setProperty("--font-scale",o?"0.9":a?"0.95":"1"),r.style.setProperty("--has-coarse-pointer",n?"1":"0"),r.style.setProperty("--has-touch-input",n?"1":"0"),n?r.classList.add("mobile-pointer"):r.classList.remove("mobile-pointer"))};function u2(){const t=window.innerWidth,e=typeof window.matchMedia=="function",n=e?window.matchMedia("(pointer: coarse)"):null,r=e?window.matchMedia("(hover: none)"):null,o=n?.matches??!1,a=r?.matches??!1,l=typeof navigator<"u"?navigator.maxTouchPoints??0:0,i=_n(),c=o||a||l>0,u=t>Ui.md&&t<=Ui.lg,m=t<=Ui.md;let f=c&&m,h=c&&!f&&u,p=!c||t>Ui.lg,g="desktop";i?(f=!1,h=!1,p=!0,g="desktop"):f?g="mobile":h?g="tablet":(p=!0,g="desktop"),Z6(i,g,c);let x="xs";for(const[b,v]of Object.entries(Ui))t>=v&&(x=b);return{isMobile:f,isTablet:h,isDesktop:p,deviceType:g,screenWidth:t,breakpoint:x,hasTouchInput:c}}function Si(){if(typeof window>"u"||typeof window<"u"&&_n())return!1;const t=document.documentElement,e=t.style.getPropertyValue("--is-mobile")||getComputedStyle(t).getPropertyValue("--is-mobile");return e==="1"||e==="true"}function wn(){const t=Fe.c(9),[e,n]=d.useState(Wy);let r,o;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{if(typeof window>"u")return;let u;const m=()=>{clearTimeout(u),u=setTimeout(()=>{n(u2())},150)};return window.addEventListener("resize",m),()=>{clearTimeout(u),window.removeEventListener("resize",m)}},o=[],t[0]=r,t[1]=o):(r=t[0],o=t[1]),d.useEffect(r,o);let a,l;t[2]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const u=window.matchMedia("(pointer: coarse)"),m=window.matchMedia("(hover: none)"),f=()=>{n(u2())},h=[],p=g=>{g&&(typeof g.addEventListener=="function"?(g.addEventListener("change",f),h.push(()=>g.removeEventListener("change",f))):typeof g.addListener=="function"&&(g.addListener(f),h.push(()=>g.removeListener(f))))};return p(u),p(m),()=>{h.forEach(Uy)}},l=[],t[2]=a,t[3]=l):(a=t[2],l=t[3]),d.useEffect(a,l);let i;t[4]!==e.deviceType?(i=()=>{if(typeof window>"u")return;const u=_n(),m=typeof window.matchMedia=="function",f=m?window.matchMedia("(pointer: coarse)"):null,h=m?window.matchMedia("(hover: none)"):null,p=f?.matches??!1,g=h?.matches??!1,x=typeof navigator<"u"?navigator.maxTouchPoints??0:0,b=p||g||x>0;Z6(u,e.deviceType,b)},t[4]=e.deviceType,t[5]=i):i=t[5];let c;return t[6]!==e.deviceType||t[7]!==e.hasTouchInput?(c=[e.deviceType,e.hasTouchInput],t[6]=e.deviceType,t[7]=e.hasTouchInput,t[8]=c):c=t[8],d.useEffect(i,c),e}function Uy(t){return t()}function Wy(){return typeof window>"u"?{isMobile:!1,isTablet:!1,isDesktop:!0,deviceType:"desktop",screenWidth:1024,breakpoint:"lg",hasTouchInput:!1}:u2()}const D1=he.forwardRef((t,e)=>{const n=Fe.c(11);let r,o;n[0]!==t?({className:r,...o}=t,n[0]=t,n[1]=r,n[2]=o):(r=n[1],o=n[2]);let a;n[3]!==r?(a=Q("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=a):a=n[4];let l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let i;n[6]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Pg,{className:Q("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=i):i=n[6];let c;return n[7]!==o||n[8]!==e||n[9]!==a?(c=s.jsx(Ch,{className:a,style:l,...o,ref:e,children:i}),n[7]=o,n[8]=e,n[9]=a,n[10]=c):c=n[10],c});D1.displayName=Ch.displayName;function Hu(t){const e=Fe.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let o;return e[2]!==t?(o=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=o):o=e[3],o}const K6=t=>{if(!t)return"Unknown";switch(t.status){case"connected":return"Connected";case"failed":return`Failed: ${t.error||"Unknown error"}`;case"needs_auth":return"Needs authentication";case"needs_client_registration":return`Needs registration: ${t.error||""}`;default:return t.status}},Y6=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Dd=({active:t,className:e})=>{const r=dn(g=>g.currentDirectory)??null,o=Yr(g=>g.getStatusForDirectory(r)),a=Yr(g=>g.refresh),l=Yr(g=>g.connect),i=Yr(g=>g.disconnect),[c,u]=d.useState(!1),[m,f]=d.useState(null);d.useEffect(()=>{a({directory:r,silent:!0})},[a,r]),d.useEffect(()=>{t&&a({directory:r,silent:!0})},[t,a,r]);const h=d.useMemo(()=>Object.keys(o).sort((g,x)=>g.localeCompare(x)),[o]),p=d.useCallback(g=>{if(g?.preventDefault(),c)return;u(!0);const x=new Promise(b=>setTimeout(b,500));Promise.all([a({directory:r}),x]).finally(()=>{u(!1)})},[c,a,r]);return s.jsxs("div",{className:Q("w-full",e),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-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:"MCP Servers"}),r&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:r.split("/").pop()||r})]}),s.jsx("button",{type:"button",className:"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",disabled:c,onClick:p,"aria-label":"Refresh",children:s.jsx(Qn,{className:Q("h-4 w-4",c&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[h.map(g=>{const x=o[g],b=Y6(x),v=x?.status==="connected",y=m===g,w=K6(x);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(Dt,{delayDuration:300,children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:Q("h-2 w-2 rounded-full flex-shrink-0",b==="success"&&"bg-status-success",b==="error"&&"bg-status-error",b==="warning"&&"bg-status-warning",b==="default"&&"bg-muted-foreground/40"),"aria-label":w})}),s.jsx(_t,{side:"left",children:s.jsx("p",{children:w})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(D1,{checked:v,disabled:y,className:"data-[state=checked]:bg-status-info",onCheckedChange:async C=>{f(g);try{C?await l(g,r):await i(g,r)}finally{f(null)}}})]},g)}),h.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:"Configure MCP servers in Opencode config."})]})]})},qy=({headerIconButtonClass:t})=>{const[e,n]=d.useState(!1),[r,o]=d.useState(!1),a=d.useRef(!1),{isMobile:l}=wn(),c=dn(j=>j.currentDirectory)??null,u=Yr(j=>j.getStatusForDirectory(c)),m=Yr(j=>j.refresh),f=Yr(j=>j.connect),h=Yr(j=>j.disconnect),p=d.useCallback(j=>{j||(a.current=!0,o(!1),setTimeout(()=>{a.current=!1},200)),n(j)},[]),g=d.useCallback(j=>{a.current||o(j)},[]),[x,b]=d.useState(!1),[v,y]=d.useState(null);d.useEffect(()=>{m({directory:c,silent:!0})},[m,c]),d.useEffect(()=>{e&&m({directory:c,silent:!0})},[e,m,c]);const w=d.useMemo(()=>Ub(u),[u]),C=d.useMemo(()=>Object.keys(u).sort((j,F)=>j.localeCompare(F)),[u]),N=d.useCallback(j=>{if(j?.preventDefault(),x)return;b(!0);const F=new Promise(A=>setTimeout(A,500));Promise.all([m({directory:c}),F]).finally(()=>{b(!1)})},[x,m,c]),S=()=>s.jsxs(s.Fragment,{children:[C.map(j=>{const F=u[j],A=Y6(F),M=F?.status==="connected",B=v===j,E=K6(F);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[l?s.jsx("span",{className:Q("h-2 w-2 rounded-full flex-shrink-0",A==="success"&&"bg-status-success",A==="error"&&"bg-status-error",A==="warning"&&"bg-status-warning",A==="default"&&"bg-muted-foreground/40"),"aria-label":E}):s.jsxs(Dt,{delayDuration:300,children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:Q("h-2 w-2 rounded-full flex-shrink-0",A==="success"&&"bg-status-success",A==="error"&&"bg-status-error",A==="warning"&&"bg-status-warning",A==="default"&&"bg-muted-foreground/40"),"aria-label":E})}),s.jsx(_t,{side:"left",children:s.jsx("p",{children:E})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:j})]})}),s.jsx(D1,{checked:M,disabled:B,className:"data-[state=checked]:bg-status-info",onCheckedChange:async I=>{y(j);try{I?await f(j,c):await h(j,c)}finally{y(null)}}})]},j)}),C.length===0&&s.jsx("div",{className:"px-2 py-3 typography-ui-label text-muted-foreground text-center",children:"Configure MCP servers in Opencode config."})]}),k=s.jsxs("button",{type:"button","aria-label":"MCP servers",className:Q(t,"relative"),onClick:l?()=>n(!0):void 0,children:[s.jsx(Hu,{className:"h-[1.0625rem] w-[1.0625rem]"}),w.total>0&&s.jsx("span",{className:Q("absolute top-1.5 right-1.5 h-1.5 w-1.5 rounded-full",w.hasFailed?"bg-status-error":w.hasAuthRequired?"bg-status-warning":w.connected>0?"bg-status-success":"bg-muted-foreground/40"),"aria-label":"MCP status"})]});return l?s.jsxs(s.Fragment,{children:[k,s.jsxs(cr,{open:e,title:"MCP Servers",onClose:()=>n(!1),renderHeader:j=>s.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/40",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:"MCP Servers"}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{type:"button",className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover transition-colors",disabled:x,onClick:N,"aria-label":"Refresh",children:s.jsx(Qn,{className:Q("h-4 w-4",x&&"animate-spin")})}),j]})]}),children:[s.jsx("div",{className:"py-1",children:S()}),c&&s.jsx("div",{className:"px-2 py-1 border-t border-border/40 mt-1",children:s.jsx("span",{className:"typography-meta text-muted-foreground truncate block",children:c.split("/").pop()||c})})]})]}):s.jsxs(qs,{open:e,onOpenChange:p,children:[s.jsxs(Dt,{delayDuration:1e3,open:e?!1:r,onOpenChange:g,children:[s.jsx(It,{asChild:!0,children:s.jsx(Gs,{asChild:!0,children:k})}),s.jsx(_t,{children:s.jsx("p",{children:"MCP Servers"})})]}),s.jsx(Ys,{align:"end",className:"w-72",children:s.jsx(Dd,{active:e})})]})},Gy="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M37.9998%2023.021C33.7998%2025.2889%2029.5698%2027.3649%2024.8614%2028.3069C23.8114%2028.5154%2022.6474%2028.5154%2021.5809%2028.3714C20.5639%2028.2439%2020.0554%2027.3484%2020.4169%2026.4064C20.7619%2025.5289%2021.2209%2024.635%2021.8119%2023.9C23.0899%2022.3025%2024.5329%2020.849%2025.8289%2019.268C26.6203%2018.2991%2027.3335%2017.2689%2027.9618%2016.187C28.4208%2015.4205%2028.2078%2014.4935%2027.4038%2014.111C26.0584%2013.4556%2024.6154%2012.9936%2023.1889%2012.4986C23.0239%2012.4341%2022.7779%2012.6096%2022.4509%2012.7221C22.8604%2013.0881%2023.1559%2013.3596%2023.5654%2013.727C19.3339%2014.447%2015.3305%2015.467%2011.4455%2016.874C11.4275%2016.9535%2011.396%2017.0165%2011.411%2017.0495C11.9855%2017.927%2011.723%2018.5975%2010.886%2019.1405C10.5611%2019.3531%2010.2732%2019.6176%2010.034%2019.9235C12.593%2020.6735%2014.873%2020.243%2017.0539%2018.821C16.9234%2018.6305%2016.7914%2018.455%2016.6609%2018.263C17.4799%2018.407%2017.9719%2018.854%2018.0379%2019.556C18.0544%2019.7165%2017.9569%2019.8755%2017.9074%2020.036C17.7919%2019.907%2017.6449%2019.781%2017.5474%2019.6355C17.4799%2019.5395%2017.4634%2019.4285%2017.4154%2019.268C14.8235%2020.993%2012.035%2021.425%208.96751%2020.531C8.96751%2021.137%208.93451%2021.6485%208.98401%2022.1435C9.01701%2022.574%208.83701%2022.766%208.44401%2022.9895C7.55752%2023.5325%206.63803%2024.092%205.90003%2024.8105C5.01504%2025.6879%205.34354%2026.7589%206.54053%2027.2059C7.90102%2027.7159%209.329%2027.7309%2010.7555%2027.5569C12.4445%2027.3484%2014.1005%2027.0769%2015.9394%2026.8219C13.79%2027.8269%2011.6735%2028.5319%209.4445%2028.8169C7.88452%2029.0269%206.32753%2029.1379%204.78554%2028.6909C2.57156%2028.0684%201.58607%2026.4394%202.16057%2024.251C2.70206%2022.2065%204.01455%2020.5775%205.42454%2019.076C10.133%2014.078%2016.0864%2011.5401%2022.9744%2011.0286C24.5824%2010.9176%2026.2069%2011.1246%2027.7143%2011.7951C29.8308%2012.7536%2030.7173%2014.78%2029.6838%2016.826C29.0118%2018.1835%2028.0758%2019.4285%2027.1413%2020.6585C26.2234%2021.872%2025.1899%2022.9895%2024.2224%2024.155C23.9434%2024.506%2023.6809%2024.875%2023.4679%2025.2724C23.0569%2026.0224%2023.3359%2026.5174%2024.2059%2026.4394C26.0254%2026.2624%2027.8808%2026.1199%2029.6358%2025.6729C32.2098%2025.0174%2034.7193%2024.092%2037.2618%2023.2775C37.5243%2023.213%2037.7703%2023.117%2037.9998%2023.0225V23.021Z'%20fill='currentColor'/%3e%3c/svg%3e",Zy="data:image/svg+xml,%3csvg%20fill='currentColor'%20fill-rule='evenodd'%20height='1em'%20style='flex:none;line-height:1'%20viewBox='0%200%2024%2024'%20width='1em'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eCursor%3c/title%3e%3cg%20transform='translate(12%2012)%20scale(0.88)%20translate(-12%20-12)'%3e%3cpath%20d='M22.106%205.68L12.5.135a.998.998%200%2000-.998%200L1.893%205.68a.84.84%200%2000-.419.726v11.186c0%20.3.16.577.42.727l9.607%205.547a.999.999%200%2000.998%200l9.608-5.547a.84.84%200%2000.42-.727V6.407a.84.84%200%2000-.42-.726zm-.603%201.176L12.228%2022.92c-.063.108-.228.064-.228-.061V12.34a.59.59%200%2000-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264%200%20.428.286.296.514z'%3e%3c/path%3e%3c/g%3e%3c/svg%3e",Ky="data:image/svg+xml,%3csvg%20fill='%23000000'%20viewBox='0%200%2033%2025'%20role='img'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M79.01%205.863c-4.066%200-6.511%202.92-6.511%206.535%200%203.635%202.445%206.555%206.511%206.555%204.046%200%206.512-2.92%206.512-6.555s-2.466-6.535-6.512-6.535Zm0%2010.968c-2.633%200-4.172-1.933-4.172-4.433s1.539-4.455%204.172-4.455c2.635%200%204.151%201.933%204.151%204.434%200%202.521-1.516%204.454-4.15%204.454Zm14.393%202.096c3.393%200%205.542-1.808%205.837-4.539h-2.36c-.316%201.555-1.517%202.437-3.477%202.437-2.423%200-3.878-1.68-3.878-4.433%200-2.774%201.476-4.434%203.878-4.434%201.96%200%203.14.862%203.477%202.5h2.36c-.295-2.773-2.444-4.622-5.837-4.622-3.856%200-6.217%202.669-6.217%206.535%200%203.887%202.36%206.556%206.217%206.556Zm-29.543-.311h2.36v-6.01c0-2.752%201.348-4.244%203.772-4.244h2.276V6.177h-2.255c-2.128%200-3.288.735-3.898%202.605l-.443-.063.527-2.542h-2.36v12.439h.02Zm-24.445-7.332c.106-2.101%201.517-3.53%203.793-3.53%202.276%200%203.646%201.345%203.646%203.53h-7.439Zm9.778.4c0-3.426-2.381-5.821-5.943-5.821-3.73%200-6.174%202.563-6.174%206.535%200%204.013%202.423%206.555%206.28%206.555%202.929%200%205.247-1.597%205.669-3.887h-2.36c-.507%201.156-1.666%201.828-3.31%201.828-2.38%200-3.877-1.408-3.94-3.803h9.694c.042-.588.084-.861.084-1.408Zm5.69%206.932h1.939l5.5-12.44h-2.529L56%2015.99l-.316.021-3.793-9.833h-2.508l5.5%2012.439ZM32.23%2012.35c0-.882-.359-1.701-.99-2.437a8.594%208.594%200%200%201-1.497%201.093c.337.42.527.861.527%201.345%200%202.731-5.837%204.811-14.14%204.811-8.281.021-14.118-2.059-14.118-4.811%200-.463.168-.925.505-1.345a8.13%208.13%200%200%201-1.475-1.093c-.632.736-.99%201.555-.99%202.438%200%204.034%207.207%206.534%2016.1%206.534%208.87.021%2016.078-2.5%2016.078-6.535Zm-3.351%201.534c-.906-.462-1.96-.861-3.16-1.197-1.37.378-2.909.672-4.553.861%202.318.294%204.341.778%205.9%201.408.76-.336%201.37-.693%201.813-1.072Zm-17.849-.357a31.902%2031.902%200%200%201-4.467-.84c-1.18.336-2.255.735-3.16%201.197.42.379%201.01.715%201.748%201.05%201.539-.63%203.52-1.113%205.88-1.407Zm21.2-6.808c0-4.013-7.207-6.534-16.079-6.534C7.26.185.051%202.706.051%206.719c0%204.035%207.208%206.535%2016.1%206.535%208.872.021%2016.079-2.5%2016.079-6.535Zm-1.94%200c0%202.732-5.836%204.812-14.139%204.812-8.302.021-14.14-2.06-14.14-4.812%200-2.731%205.838-4.811%2014.14-4.811%207.86%200%2014.14%202.08%2014.14%204.811Zm-3.223%202.564c.758-.336%201.37-.694%201.812-1.072-2.95-1.513-7.544-2.353-12.728-2.353s-9.799.84-12.728%202.353c.422.378%201.012.715%201.75%201.05%202.507-1.05%206.363-1.68%2010.978-1.68%204.404%200%208.324.651%2010.916%201.702ZM1.042%2015.628c-.632.736-.99%201.534-.99%202.438%200%204.034%207.207%206.534%2016.1%206.534%208.892%200%2016.099-2.521%2016.099-6.534%200-.883-.359-1.702-.99-2.438-.422.4-.907.757-1.497%201.093.337.42.527.861.527%201.345%200%202.731-5.837%204.811-14.14%204.811-8.302%200-14.14-2.08-14.14-4.811%200-.463.17-.925.506-1.345a10.73%2010.73%200%200%201-1.475-1.093Z'/%3e%3c/svg%3e",Yy="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='utf-8'?%3e%3c!--%20Uploaded%20to:%20SVG%20Repo,%20www.svgrepo.com,%20Generator:%20SVG%20Repo%20Mixer%20Tools%20--%3e%3csvg%20fill='%23000000'%20width='800px'%20height='800px'%20viewBox='0%200%2024%2024'%20role='img'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M20.702%202.29c-2.494-1.554-5.778-1.187-8.706.654C9.076%201.104%205.79.736%203.3%202.29c-3.941%202.463-4.42%208.806-1.07%2014.167%202.47%203.954%206.333%206.269%209.77%206.226%203.439.043%207.301-2.273%209.771-6.226%203.347-5.361%202.872-11.704-1.069-14.167zM4.042%2015.328a12.838%2012.838%200%200%201-1.546-3.541%2010.12%2010.12%200%200%201-.336-3.338c.15-1.98.956-3.524%202.27-4.345%201.315-.822%203.052-.87%204.903-.137.281.113.556.24.825.382A15.11%2015.11%200%200%200%207.5%207.54c-2.035%203.255-2.655%206.878-1.945%209.765a13.247%2013.247%200%200%201-1.514-1.98zm17.465-3.541a12.866%2012.866%200%200%201-1.547%203.54%2013.25%2013.25%200%200%201-1.513%201.984c.635-2.589.203-5.76-1.353-8.734a.39.39%200%200%200-.563-.153l-4.852%203.032a.397.397%200%200%200-.126.546l.712%201.139a.395.395%200%200%200%20.547.126l3.145-1.965c.101.306.203.606.28.916.296%201.086.41%202.214.335%203.337-.15%201.982-.956%203.525-2.27%204.347a4.437%204.437%200%200%201-2.25.65h-.101a4.432%204.432%200%200%201-2.25-.65c-1.314-.822-2.121-2.365-2.27-4.347a10.153%2010.153%200%200%201%20.335-3.337%2013.212%2013.212%200%200%201%204.05-6.482%2010.148%2010.148%200%200%201%202.849-1.765c1.845-.733%203.586-.685%204.9.137%201.316.822%202.122%202.365%202.271%204.345a10.146%2010.146%200%200%201-.33%203.334z'/%3e%3c/svg%3e",Xy="data:image/svg+xml,%3csvg%20fill='currentColor'%20fill-rule='evenodd'%20height='1em'%20style='flex:none;line-height:1'%20viewBox='0%200%2024%2024'%20width='1em'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eLM%20Studio%3c/title%3e%3cpath%20d='M2.84%202a1.273%201.273%200%20100%202.547h14.107a1.273%201.273%200%20100-2.547H2.84zM7.935%205.33a1.273%201.273%200%20000%202.548H22.04a1.274%201.274%200%20000-2.547H7.935zM3.624%209.935c0-.704.57-1.274%201.274-1.274h14.106a1.274%201.274%200%20010%202.547H4.898c-.703%200-1.274-.57-1.274-1.273zM1.273%2012.188a1.273%201.273%200%20100%202.547H15.38a1.274%201.274%200%20000-2.547H1.273zM3.624%2016.792c0-.704.57-1.274%201.274-1.274h14.106a1.273%201.273%200%20110%202.547H4.898c-.703%200-1.274-.57-1.274-1.273zM13.029%2018.849a1.273%201.273%200%20100%202.547h9.698a1.273%201.273%200%20100-2.547h-9.698z'%20fill-opacity='.3'%3e%3c/path%3e%3cpath%20d='M2.84%202a1.273%201.273%200%20100%202.547h10.287a1.274%201.274%200%20000-2.547H2.84zM7.935%205.33a1.273%201.273%200%20000%202.548H18.22a1.274%201.274%200%20000-2.547H7.935zM3.624%209.935c0-.704.57-1.274%201.274-1.274h10.286a1.273%201.273%200%20010%202.547H4.898c-.703%200-1.274-.57-1.274-1.273zM1.273%2012.188a1.273%201.273%200%20100%202.547H11.56a1.274%201.274%200%20000-2.547H1.273zM3.624%2016.792c0-.704.57-1.274%201.274-1.274h10.286a1.273%201.273%200%20110%202.547H4.898c-.703%200-1.274-.57-1.274-1.273zM13.029%2018.849a1.273%201.273%200%20100%202.547h5.78a1.273%201.273%200%20100-2.547h-5.78z'%3e%3c/path%3e%3c/svg%3e",Qy="data:image/svg+xml,%3csvg%20fill='currentColor'%20fill-rule='evenodd'%20height='1em'%20style='flex:none;line-height:1'%20viewBox='0%200%2024%2024'%20width='1em'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eOllama%3c/title%3e%3cpath%20d='M7.905%201.09c.216.085.411.225.588.41.295.306.544.744.734%201.263.191.522.315%201.1.362%201.68a5.054%205.054%200%20012.049-.636l.051-.004c.87-.07%201.73.087%202.48.474.101.053.2.11.297.17.05-.569.172-1.134.36-1.644.19-.52.439-.957.733-1.264a1.67%201.67%200%2001.589-.41c.257-.1.53-.118.796-.042.401.114.745.368%201.016.737.248.337.434.769.561%201.287.23.934.27%202.163.115%203.645l.053.04.026.019c.757.576%201.284%201.397%201.563%202.35.435%201.487.216%203.155-.534%204.088l-.018.021.002.003c.417.762.67%201.567.724%202.4l.002.03c.064%201.065-.2%202.137-.814%203.19l-.007.01.01.024c.472%201.157.62%202.322.438%203.486l-.006.039a.651.651%200%2001-.747.536.648.648%200%2001-.54-.742c.167-1.033.01-2.069-.48-3.123a.643.643%200%2001.04-.617l.004-.006c.604-.924.854-1.83.8-2.72-.046-.779-.325-1.544-.8-2.273a.644.644%200%2001.18-.886l.009-.006c.243-.159.467-.565.58-1.12a4.229%204.229%200%2000-.095-1.974c-.205-.7-.58-1.284-1.105-1.683-.595-.454-1.383-.673-2.38-.61a.653.653%200%2001-.632-.371c-.314-.665-.772-1.141-1.343-1.436a3.288%203.288%200%2000-1.772-.332c-1.245.099-2.343.801-2.67%201.686a.652.652%200%2001-.61.425c-1.067.002-1.893.252-2.497.703-.522.39-.878.935-1.066%201.588a4.07%204.07%200%2000-.068%201.886c.112.558.331%201.02.582%201.269l.008.007c.212.207.257.53.109.785-.36.622-.629%201.549-.673%202.44-.05%201.018.186%201.902.719%202.536l.016.019a.643.643%200%2001.095.69c-.576%201.236-.753%202.252-.562%203.052a.652.652%200%2001-1.269.298c-.243-1.018-.078-2.184.473-3.498l.014-.035-.008-.012a4.339%204.339%200%2001-.598-1.309l-.005-.019a5.764%205.764%200%2001-.177-1.785c.044-.91.278-1.842.622-2.59l.012-.026-.002-.002c-.293-.418-.51-.953-.63-1.545l-.005-.024a5.352%205.352%200%2001.093-2.49c.262-.915.777-1.701%201.536-2.269.06-.045.123-.09.186-.132-.159-1.493-.119-2.73.112-3.67.127-.518.314-.95.562-1.287.27-.368.614-.622%201.015-.737.266-.076.54-.059.797.042zm4.116%209.09c.936%200%201.8.313%202.446.855.63.527%201.005%201.235%201.005%201.94%200%20.888-.406%201.58-1.133%202.022-.62.375-1.451.557-2.403.557-1.009%200-1.871-.259-2.493-.734-.617-.47-.963-1.13-.963-1.845%200-.707.398-1.417%201.056-1.946.668-.537%201.55-.849%202.485-.849zm0%20.896a3.07%203.07%200%2000-1.916.65c-.461.37-.722.835-.722%201.25%200%20.428.21.829.61%201.134.455.347%201.124.548%201.943.548.799%200%201.473-.147%201.932-.426.463-.28.7-.686.7-1.257%200-.423-.246-.89-.683-1.256-.484-.405-1.14-.643-1.864-.643zm.662%201.21l.004.004c.12.151.095.37-.056.49l-.292.23v.446a.375.375%200%2001-.376.373.375.375%200%2001-.376-.373v-.46l-.271-.218a.347.347%200%2001-.052-.49.353.353%200%2001.494-.051l.215.172.22-.174a.353.353%200%2001.49.051zm-5.04-1.919c.478%200%20.867.39.867.871a.87.87%200%2001-.868.871.87.87%200%2001-.867-.87.87.87%200%2001.867-.872zm8.706%200c.48%200%20.868.39.868.871a.87.87%200%2001-.868.871.87.87%200%2001-.867-.87.87.87%200%2001.867-.872zM7.44%202.3l-.003.002a.659.659%200%2000-.285.238l-.005.006c-.138.189-.258.467-.348.832-.17.692-.216%201.631-.124%202.782.43-.128.899-.208%201.404-.237l.01-.001.019-.034c.046-.082.095-.161.148-.239.123-.771.022-1.692-.253-2.444-.134-.364-.297-.65-.453-.813a.628.628%200%2000-.107-.09L7.44%202.3zm9.174.04l-.002.001a.628.628%200%2000-.107.09c-.156.163-.32.45-.453.814-.29.794-.387%201.776-.23%202.572l.058.097.008.014h.03a5.184%205.184%200%20011.466.212c.086-1.124.038-2.043-.128-2.722-.09-.365-.21-.643-.349-.832l-.004-.006a.659.659%200%2000-.285-.239h-.004z'%3e%3c/path%3e%3c/svg%3e",Jy=Object.assign({"../assets/provider-logos/bailian-coding-plan.svg":Gy,"../assets/provider-logos/cursor.svg":Zy,"../assets/provider-logos/evroc.svg":Ky,"../assets/provider-logos/gocode.svg":Yy,"../assets/provider-logos/lmstudio.svg":Xy,"../assets/provider-logos/ollama.svg":Qy}),$u=new Map,J3=new Map([["codex","openai"],["chatgpt","openai"],["claude","anthropic"],["gemini","google"],["evroc-ai","evroc"],["evrocai","evroc"],["ollama-cloud","ollama"]]),ew=t=>(t??"").toLowerCase().trim().replace(/^models\./,"").replace(/^provider\./,"").replace(/\s+/g,"-"),tw=t=>{const e=ew(t);if(!e)return[];const n=e.replace(/[^a-z0-9_\-./:]/g,""),r=n.split(/[/:]/)[0]||n,o=[J3.get(n),J3.get(r),n,r].filter(a=>!!(a&&a.length>0));return[...new Set(o)]};for(const[t,e]of Object.entries(Jy)){const n=t.match(/provider-logos\/([^/]+)\.svg$/i);n?.[1]&&e&&$u.set(n[1].toLowerCase(),e)}function X6(t){const e=Fe.c(23);let n,r,o,a;if(e[0]!==t){const g=tw(t);r=g.find(sw)??null,o=g[0]??null,n=!!r,a=r?$u.get(r)??null:null,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a}else n=e[1],r=e[2],o=e[3],a=e[4];const l=a,[i,c]=he.useState(n?"local":"remote");let u;e[5]!==n?(u=()=>{c(n?"local":"remote")},e[5]=n,e[6]=u):u=e[6];let m;e[7]!==n||e[8]!==r||e[9]!==o?(m=[n,r,o],e[7]=n,e[8]=r,e[9]=o,e[10]=m):m=e[10],he.useEffect(u,m);let f;e[11]!==n?(f=()=>{c(g=>g==="local"&&n?"remote":"none")},e[11]=n,e[12]=f):f=e[12];const h=f;if(!r&&!o){let g;return e[13]!==h?(g={src:null,onError:h,hasLogo:!1},e[13]=h,e[14]=g):g=e[14],g}if(i==="local"&&l){let g;return e[15]!==h||e[16]!==l?(g={src:l,onError:h,hasLogo:!0},e[15]=h,e[16]=l,e[17]=g):g=e[17],g}if(i==="remote"&&o){const g=`https://models.dev/logos/${o}.svg`;let x;return e[18]!==h||e[19]!==g?(x={src:g,onError:h,hasLogo:!0},e[18]=h,e[19]=g,e[20]=x):x=e[20],x}let p;return e[21]!==h?(p={src:null,onError:h,hasLogo:!1},e[21]=h,e[22]=p):p=e[22],p}function sw(t){return $u.has(t)}const Mn=t=>{const e=Fe.c(10),{providerId:n,alt:r,className:o,onError:a}=t,{src:l,onError:i,hasLogo:c}=X6(n);let u;e[0]!==a||e[1]!==i?(u=()=>{i(),a?.()},e[0]=a,e[1]=i,e[2]=u):u=e[2];const m=u;if(!c||!l)return null;const f=r||`${n} logo`;let h;e[3]!==o?(h=Q("dark:invert object-contain",o),e[3]=o,e[4]=h):h=e[4];let p;return e[5]!==m||e[6]!==l||e[7]!==f||e[8]!==h?(p=s.jsx("img",{src:l,alt:f,className:h,onError:m}),e[5]=m,e[6]=l,e[7]=f,e[8]=h,e[9]=p):p=e[9],p},di=t=>{const e=Fe.c(20),{percent:n,tonePercent:r,className:o,expectedMarkerPercent:a}=t;let l;e[0]!==n?(l=R6(n)??0,e[0]=n,e[1]=l):l=e[1];const i=l,c=r??n;let u;e[2]!==c?(u=z6(c),e[2]=c,e[3]=u):u=e[3];const m=u,f=a!=null?Math.max(0,Math.min(100,a)):null;let h;e[4]!==m?(h=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=h):h=e[5];const p=h;let g;e[6]!==o?(g=Q("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",o),e[6]=o,e[7]=g):g=e[7];const x=`${i}%`;let b;e[8]!==p||e[9]!==x?(b={...p,width:x},e[8]=p,e[9]=x,e[10]=b):b=e[10];let v;e[11]!==i||e[12]!==b?(v=s.jsx("div",{className:"h-full transition-all duration-300",style:b,role:"progressbar","aria-valuenow":i,"aria-valuemin":0,"aria-valuemax":100}),e[11]=i,e[12]=b,e[13]=v):v=e[13];let y;e[14]!==f?(y=f!=null&&f>0&&f<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${f}%`},title:`Expected usage if spread evenly: ${Math.round(f)}% of quota`,"aria-hidden":"true"}),e[14]=f,e[15]=y):y=e[15];let w;return e[16]!==g||e[17]!==v||e[18]!==y?(w=s.jsxs("div",{className:g,children:[v,y]}),e[16]=g,e[17]=v,e[18]=y,e[19]=w):w=e[19],w},ui=t=>{const e=Fe.c(53),{paceInfo:n,className:r,compact:o}=t,a=o===void 0?!1:o;let l;e[0]!==n.status?(l=Wv(n.status),e[0]=n.status,e[1]=l):l=e[1];const i=l;let c;e:{switch(n.status){case"on-track":{c="On track";break e}case"slightly-fast":{c="Slightly fast";break e}case"too-fast":{c="Too fast";break e}case"exhausted":{c="Used up";break e}}c=void 0}const u=c,m=`Predicted usage at window end based on current pace: ${n.predictText}`;if(a){let N;e[2]!==r?(N=Q("flex items-center gap-1.5",r),e[2]=r,e[3]=N):N=e[3];let S;e[4]!==i?(S={backgroundColor:i},e[4]=i,e[5]=S):S=e[5];let k;e[6]!==u||e[7]!==S?(k=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:S,title:u}),e[6]=u,e[7]=S,e[8]=k):k=e[8];let j;e[9]!==i?(j={color:i},e[9]=i,e[10]=j):j=e[10];const F=n.isExhausted?void 0:m;let A;e[11]!==n.isExhausted||e[12]!==n.predictText||e[13]!==n.remainingSeconds?(A=n.isExhausted?s.jsxs(s.Fragment,{children:["Wait ",V3(n.remainingSeconds)]}):s.jsxs(s.Fragment,{children:["Pred: ",n.predictText]}),e[11]=n.isExhausted,e[12]=n.predictText,e[13]=n.remainingSeconds,e[14]=A):A=e[14];let M;e[15]!==j||e[16]!==F||e[17]!==A?(M=s.jsx("span",{className:"typography-micro tabular-nums",style:j,title:F,children:A}),e[15]=j,e[16]=F,e[17]=A,e[18]=M):M=e[18];let B;return e[19]!==M||e[20]!==N||e[21]!==k?(B=s.jsxs("div",{className:N,children:[k,M]}),e[19]=M,e[20]=N,e[21]=k,e[22]=B):B=e[22],B}let f;e[23]!==r?(f=Q("flex items-center justify-between gap-2",r),e[23]=r,e[24]=f):f=e[24];let h;e[25]!==n.isExhausted||e[26]!==n.paceRateText?(h=!n.isExhausted&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["Pace: ",n.paceRateText]}),e[25]=n.isExhausted,e[26]=n.paceRateText,e[27]=h):h=e[27];let p;e[28]!==h?(p=s.jsx("div",{className:"flex items-center gap-1.5",children:h}),e[28]=h,e[29]=p):p=e[29];let g;e[30]!==i?(g={color:i},e[30]=i,e[31]=g):g=e[31];let x;e[32]!==n.isExhausted||e[33]!==n.predictText||e[34]!==n.remainingSeconds||e[35]!==m||e[36]!==u?(x=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:u}),s.jsx("span",{className:"text-muted-foreground",children:" · Wait "}),s.jsx("span",{className:"font-medium",children:V3(n.remainingSeconds)})]}):s.jsxs("span",{title:m,children:[s.jsx("span",{className:"text-muted-foreground",children:"Pred: "}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[32]=n.isExhausted,e[33]=n.predictText,e[34]=n.remainingSeconds,e[35]=m,e[36]=u,e[37]=x):x=e[37];let b;e[38]!==g||e[39]!==x?(b=s.jsx("span",{className:"typography-micro tabular-nums",style:g,children:x}),e[38]=g,e[39]=x,e[40]=b):b=e[40];let v;e[41]!==i?(v={backgroundColor:i},e[41]=i,e[42]=v):v=e[42];let y;e[43]!==u||e[44]!==v?(y=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:v,title:u}),e[43]=u,e[44]=v,e[45]=y):y=e[45];let w;e[46]!==y||e[47]!==b?(w=s.jsxs("div",{className:"flex items-center gap-1.5",children:[b,y]}),e[46]=y,e[47]=b,e[48]=w):w=e[48];let C;return e[49]!==w||e[50]!==f||e[51]!==p?(C=s.jsxs("div",{className:f,children:[p,w]}),e[49]=w,e[50]=f,e[51]=p,e[52]=C):C=e[52],C},kl="__unassigned__",Q6={mod:"mod",shift:"shift",alt:"alt",option:"alt",ctrl:"ctrl",meta:"mod",cmd:"mod",command:"mod"},nw={mod:_1()&&_n()?"⌘":"Ctrl",shift:"⇧",alt:"⌥",option:"⌥",ctrl:"⌃"},rw={comma:",",period:".",enter:"Enter",escape:"Esc",tab:"Tab",space:"Space",backspace:"⌫",delete:"⌦",arrowup:"↑",arrowdown:"↓",arrowleft:"←",arrowright:"→",home:"Home",end:"End",pageup:"Page Up",pagedown:"Page Down"},J6=["mod","ctrl","shift","alt"],ow={"{":"[","}":"]",":":";",'"':"'","<":",",">":".","?":"/","|":"\\","~":"`","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0"};function Li(t){return t.trim().toLowerCase()===kl}function Id(t){const e=t.toLowerCase();return e===","?"comma":e==="."?"period":e===" "?"space":e==="esc"?"escape":e==="+"?"plus":e==="-"||e==="_"?"minus":e==="arrowup"?"arrowup":e==="arrowdown"?"arrowdown":e==="arrowleft"?"arrowleft":e==="arrowright"?"arrowright":ow[e]??e}const e8=[{id:"open_command_palette",defaultCombo:"mod+k",label:"Open command palette",description:"Open the command palette",customizable:!0},{id:"focus_input",defaultCombo:"mod+i",label:"Focus input",description:"Focus the chat input field",customizable:!0},{id:"open_status",defaultCombo:"mod+shift+o",label:"Open OpenCode status",description:"Open the OpenCode status dialog"},{id:"open_settings",defaultCombo:"mod+comma",label:"Open settings",description:"Open the settings panel",customizable:!0},{id:"toggle_terminal",defaultCombo:"mod+j",label:"Toggle terminal dock",description:"Toggle the bottom terminal dock",customizable:!0},{id:"toggle_terminal_expanded",defaultCombo:"mod+shift+j",label:"Toggle terminal expanded",description:"Toggle terminal expanded or collapsed",customizable:!0},{id:"toggle_files",defaultCombo:"mod+shift+f",label:"Toggle files",description:"Toggle the files panel"},{id:"toggle_sidebar",defaultCombo:"mod+l",label:"Toggle sidebar",description:"Toggle the session sidebar",customizable:!0},{id:"toggle_right_sidebar",defaultCombo:"mod+b",label:"Toggle right sidebar",description:"Toggle the right sidebar",customizable:!0},{id:"open_right_sidebar_git",defaultCombo:"mod+shift+g",label:"Open right sidebar Git tab",description:"Open right sidebar and select Git",customizable:!0},{id:"open_right_sidebar_files",defaultCombo:"mod+shift+f",label:"Open right sidebar Files tab",description:"Open right sidebar and select Files",customizable:!0},{id:"cycle_right_sidebar_tab",defaultCombo:"mod+shift+]",label:"Cycle right sidebar tab",description:"Cycle through right sidebar tabs",customizable:!0},{id:"new_chat",defaultCombo:"mod+n",label:"New session",description:"Start a new session",customizable:!0},{id:"new_chat_worktree",defaultCombo:"mod+shift+n",label:"New worktree draft",description:"Create a new worktree and open a draft in it",customizable:!0},{id:"submit_message",defaultCombo:"mod+enter",label:"Submit message",description:"Submit the current message"},{id:"clear_input",defaultCombo:"escape",label:"Clear input",description:"Clear the input field"},{id:"open_diff_panel",defaultCombo:"mod+2",label:"Open diff panel",description:"Switch to the diff panel"},{id:"open_terminal_panel",defaultCombo:"mod+3",label:"Open terminal panel",description:"Switch to the terminal panel"},{id:"open_git_panel",defaultCombo:"mod+4",label:"Open git panel",description:"Switch to the git panel"},{id:"open_timeline",defaultCombo:"mod+t",label:"Open timeline",description:"Open the timeline dialog",customizable:!0},{id:"open_help",defaultCombo:"mod+.",label:"Open keyboard shortcuts",description:"Show the keyboard shortcuts help",customizable:!0},{id:"toggle_context_plan",defaultCombo:"mod+shift+p",label:"Toggle plan context panel",description:"Open or close plan in the context panel",customizable:!0},{id:"toggle_services_menu",defaultCombo:"mod+shift+s",label:"Toggle services menu",description:"Open or close the services menu",customizable:!0},{id:"cycle_services_tab",defaultCombo:"mod+shift+[",label:"Cycle services tab",description:"Cycle through tabs in the services menu",customizable:!0},{id:"cycle_theme",defaultCombo:"mod+/",label:"Cycle theme",description:"Cycle between light, dark, and system theme",customizable:!0},{id:"open_model_selector",defaultCombo:"mod+shift+m",label:"Open model selector",description:"Open model selector while in chat"},{id:"cycle_thinking_variant",defaultCombo:"mod+shift+t",label:"Cycle thinking variant",description:"Cycle thinking variant while in chat"},{id:"cycle_favorite_model_forward",defaultCombo:"ctrl+]",label:"Cycle favorite model forward",description:"Cycle forward through starred models without opening the picker",customizable:!0},{id:"cycle_favorite_model_backward",defaultCombo:"ctrl+[",label:"Cycle favorite model backward",description:"Cycle backward through starred models without opening the picker",customizable:!0},{id:"expand_input",defaultCombo:"mod+shift+e",label:"Expand input",description:"Toggle focus mode for the chat input",customizable:!0},{id:"abort_run",defaultCombo:"escape",label:"Abort active run",description:"Abort the currently running task (double press)"},{id:"switch_tab_1",defaultCombo:"mod+1",label:"Switch to tab 1",description:"Switch to the first tab or project"},{id:"switch_tab_2",defaultCombo:"mod+2",label:"Switch to tab 2",description:"Switch to the second tab or project"},{id:"switch_tab_3",defaultCombo:"mod+3",label:"Switch to tab 3",description:"Switch to the third tab or project"},{id:"switch_tab_4",defaultCombo:"mod+4",label:"Switch to tab 4",description:"Switch to the fourth tab or project"},{id:"switch_tab_5",defaultCombo:"mod+5",label:"Switch to tab 5",description:"Switch to the fifth tab or project"},{id:"switch_tab_6",defaultCombo:"mod+6",label:"Switch to tab 6",description:"Switch to the sixth tab or project"},{id:"switch_tab_7",defaultCombo:"mod+7",label:"Switch to tab 7",description:"Switch to the seventh tab or project"},{id:"switch_tab_8",defaultCombo:"mod+8",label:"Switch to tab 8",description:"Switch to the eighth tab or project"},{id:"switch_tab_9",defaultCombo:"mod+9",label:"Switch to tab 9",description:"Switch to the ninth tab or project"}];function Ra(t){if(Li(t))return kl;const e=t.toLowerCase().trim().split("+").map(a=>a.trim()).filter(Boolean),n=new Set;let r="";for(const a of e){const l=a===","?"comma":a==="."?"period":a,i=Q6[l];if(i){n.add(i);continue}r=l}return[...J6.filter(a=>n.has(a)),r].filter(Boolean).join("+")}function aw(t){return Li(t)?!0:Y2(t).key.trim().length>0}function Y2(t){if(Li(t))return{modifiers:new Set,key:kl};const n=Ra(t).split("+"),r=new Set;let o="";for(const a of n){const l=Q6[a];l?r.add(l):o=a}return{modifiers:r,key:o}}function X2(t){if(Li(t))return"Unassigned";const e=Y2(t);if(!e.key&&e.modifiers.size===0)return"Unassigned";const n=[];for(const r of J6)e.modifiers.has(r)&&n.push(nw[r]);if(e.key){const r=rw[e.key.toLowerCase()]||e.key.toUpperCase();n.push(r)}return n.join(" + ")}function t8(t){return e8.find(e=>e.id===t)}function lw(){return e8.filter(t=>t.customizable===!0)}function ha(t,e){const n=t8(t);if(!n)return"";const r=e?.[t];if(typeof r=="string"){if(r.trim().toLowerCase()===kl)return"";const o=Ra(r);if(o===kl)return kl;if(aw(o))return o}return n.defaultCombo}function e4(t){if(Li(t))return!1;const e=Y2(t);if(!e.modifiers.has("mod"))return!1;const n=e.key.toLowerCase();return new Set(["w","t","r","p","s","f","l","n"]).has(n)&&!e.modifiers.has("shift")&&!e.modifiers.has("alt")}function Gn(t,e){const n=typeof e=="string"?e:e.defaultCombo;if(Li(n))return!1;const r=Y2(n),o=r.modifiers.has("mod"),a=r.modifiers.has("shift"),l=r.modifiers.has("alt"),i=r.modifiers.has("ctrl"),c=_1()&&_n(),u=_1(),m=c?t.metaKey:u&&t.metaKey||t.ctrlKey;if(o&&!m||!o&&t.metaKey||a!==t.shiftKey||l!==t.altKey)return!1;if(i){if(!t.ctrlKey)return!1}else{const p=o&&!c&&t.ctrlKey;if(t.ctrlKey&&!p)return!1}const f=Id(t.key),h=Id(r.key);return f===h}function iw(){return _1()&&_n()?"⌘":"Ctrl"}const Jr=Rg,vo=t=>{const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(Lg,{className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a},eo=t=>{const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("overflow-hidden data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(zg,{className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a};let m1=0;function Os(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Hg,{"data-slot":"dialog",...n}),e[2]=n,e[3]=r):r=e[3],r}function cw(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Ug,{"data-slot":"dialog-portal",...n}),e[2]=n,e[3]=r):r=e[3],r}const s8=he.forwardRef((t,e)=>{const n=Fe.c(10);let r,o;n[0]!==t?({className:r,...o}=t,n[0]=t,n[1]=r,n[2]=o):(r=n[1],o=n[2]);let a;n[3]===Symbol.for("react.memo_cache_sentinel")?(a=[],n[3]=a):a=n[3],he.useEffect(uw,a);let l;n[4]!==r?(l=Q("fixed inset-0 z-50 bg-black/50 backdrop-blur-md",r),n[4]=r,n[5]=l):l=n[5];let i;return n[6]!==o||n[7]!==e||n[8]!==l?(i=s.jsx(Ah,{ref:e,"data-slot":"dialog-overlay","data-blur-bg":!0,className:l,...o}),n[6]=o,n[7]=e,n[8]=l,n[9]=i):i=n[9],i});s8.displayName=Ah.displayName;function Vs(t){const e=Fe.c(17);let n,r,o,a,l;e[0]!==t?({className:r,children:n,showCloseButton:a,keyboardAvoid:l,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a,e[5]=l):(n=e[1],r=e[2],o=e[3],a=e[4],l=e[5]);const i=a===void 0?!0:a,c=l===void 0?!1:l;let u;e[6]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(s8,{className:"rounded-none"}),e[6]=u):u=e[6];const m=c?"true":void 0;let f;e[7]!==r?(f=Q("bg-background text-foreground fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 rounded-xl border p-6 shadow-none overflow-hidden pwa-dialog-content",r),e[7]=r,e[8]=f):f=e[8];let h;e[9]!==i?(h=i&&s.jsxs(Wg,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-interactive-active data-[state=open]:text-foreground absolute top-2 right-2 rounded-lg opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none text-muted-foreground hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[s.jsx(Ps,{}),s.jsx("span",{className:"sr-only",children:"Close"})]}),e[9]=i,e[10]=h):h=e[10];let p;return e[11]!==n||e[12]!==o||e[13]!==m||e[14]!==f||e[15]!==h?(p=s.jsxs(cw,{"data-slot":"dialog-portal",children:[u,s.jsxs($g,{"data-slot":"dialog-content","data-keyboard-avoid":m,className:f,...o,children:[n,h]})]}),e[11]=n,e[12]=o,e[13]=m,e[14]=f,e[15]=h,e[16]=p):p=e[16],p}function Zs(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("flex flex-col gap-2 text-center sm:text-left",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx("div",{"data-slot":"dialog-header",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function yn(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("flex flex-col-reverse gap-2 bottom-safe-area sm:flex-row sm:justify-end",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx("div",{"data-slot":"dialog-footer",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function Us(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("typography-markdown leading-none font-semibold text-foreground",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(Og,{"data-slot":"dialog-title",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function sn(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("text-muted-foreground typography-ui-label",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(Vg,{"data-slot":"dialog-description",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function dw(){m1=Math.max(0,m1-1),m1===0&&document.documentElement.classList.remove("oc-dialog-open")}function uw(){return m1=m1+1,document.documentElement.classList.add("oc-dialog-open"),dw}function Xt(t){const e=Fe.c(10);let n,r,o;e[0]!==t?({className:n,type:o,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o):(n=e[1],r=e[2],o=e[3]);let a;e[4]!==n?(a=Q("text-foreground border border-border/80 file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 appearance-none flex h-9 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 typography-markdown outline-none focus-visible:outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:typography-ui-label file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:typography-ui-label","hover:border-input","focus:ring-1 focus:ring-primary/50 focus:border-primary/70","aria-invalid:border-destructive aria-invalid:ring-destructive",n),e[4]=n,e[5]=a):a=e[5];let l;return e[6]!==r||e[7]!==a||e[8]!==o?(l=s.jsx("input",{type:o,"data-slot":"input",className:a,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",...r}),e[6]=r,e[7]=a,e[8]=o,e[9]=l):l=e[9],l}const fw=qg("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg typography-ui-label font-medium lowercase transition-[background-color,border-color,color,box-shadow,opacity] duration-150 ease-in-out disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"border bg-[var(--primary-base)]/10 text-[var(--primary-base)] shadow-none hover:bg-[var(--primary-base)]/15 hover:text-[var(--primary-base)]",destructive:"bg-[var(--status-error)]/8 text-[var(--status-error)] shadow-none hover:bg-[var(--status-error)]/12 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40",outline:"border bg-[var(--surface-elevated)] shadow-none hover:bg-interactive-hover hover:text-foreground",secondary:"bg-interactive-hover text-foreground shadow-none hover:bg-interactive-active",ghost:"text-foreground hover:bg-interactive-hover hover:text-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-lg gap-1.5 px-3 has-[>svg]:px-2.5",xs:"h-6 rounded-lg gap-1 px-1.5 typography-micro has-[>svg]:px-1.5",lg:"h-10 rounded-lg px-6 has-[>svg]:px-4",icon:"size-9"}},defaultVariants:{variant:"default",size:"default"}});function Be(t){const e=Fe.c(14);let n,r,o,a,l;e[0]!==t?({className:n,variant:l,size:o,asChild:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a,e[5]=l):(n=e[1],r=e[2],o=e[3],a=e[4],l=e[5]);const c=(a===void 0?!1:a)?Mh:"button";let u;e[6]!==n||e[7]!==o||e[8]!==l?(u=Q(fw({variant:l,size:o,className:n})),e[6]=n,e[7]=o,e[8]=l,e[9]=u):u=e[9];let m;return e[10]!==c||e[11]!==r||e[12]!==u?(m=s.jsx(c,{"data-slot":"button",className:u,...r}),e[10]=c,e[11]=r,e[12]=u,e[13]=m):m=e[13],m}const l0=t=>{const e=Fe.c(7);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];const{theme:r}=Gg(),a=r===void 0?"system":r;let l,i;e[2]===Symbol.for("react.memo_cache_sentinel")?(l={style:{borderRadius:"var(--radius-lg)",backdropFilter:"blur(28px)",WebkitBackdropFilter:"blur(28px)"},classNames:{toast:"rounded-[var(--radius-lg)]",actionButton:"rounded-[var(--radius-md)]",cancelButton:"rounded-[var(--radius-md)]",closeButton:"rounded-[var(--radius-md)]"}},i={"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)","--error-bg":"var(--popover)","--error-text":"var(--popover-foreground)","--error-border":"var(--border)","--success-bg":"var(--popover)","--success-text":"var(--popover-foreground)","--success-border":"var(--border)","--warning-bg":"var(--popover)","--warning-text":"var(--popover-foreground)","--warning-border":"var(--border)","--info-bg":"var(--popover)","--info-text":"var(--popover-foreground)","--info-border":"var(--border)"},e[2]=l,e[3]=i):(l=e[2],i=e[3]);let c;return e[4]!==n||e[5]!==a?(c=s.jsx(Zg,{theme:a,className:"toaster group",closeButton:!1,toastOptions:l,style:i,...n}),e[4]=n,e[5]=a,e[6]=c):c=e[6],c};async function Dn(t){let e=null;if(typeof navigator<"u"&&navigator.clipboard?.writeText)try{return await navigator.clipboard.writeText(t),{ok:!0,method:"clipboard"}}catch(n){e=n instanceof Error?n.message:String(n)}if(typeof document<"u"&&document.body){const n=document.createElement("textarea");n.value=t,n.setAttribute("readonly",""),n.style.position="fixed",n.style.top="-1000px",n.style.left="-1000px",document.body.appendChild(n),n.select(),n.setSelectionRange(0,n.value.length);const r=document.execCommand("copy");if(document.body.removeChild(n),r)return{ok:!0,method:"execCommand"}}return{ok:!1,error:e??"Clipboard access denied in current context"}}const t4=async t=>{const e=await Dn(t);e.ok||console.error("Failed to copy to clipboard:",e.error)},f2=t=>t==null||typeof t=="boolean"?"":typeof t=="string"||typeof t=="number"?String(t):Array.isArray(t)?t.map(f2).join(" ").trim():he.isValidElement(t)?f2(t.props?.children):"",mw=t=>typeof t=="function"?t():t,s4=(t,e)=>{const n=f2(mw(e?.description));return n.length>0?n:f2(t)},fe={...$i,success:(t,e)=>$i.success(t,{...e,action:e?.action||{label:"OK",onClick:()=>{}}}),info:(t,e)=>$i.info(t,{...e,action:e?.action||{label:"OK",onClick:()=>{}}}),error:(t,e)=>$i.error(t,{...e,action:e?.action||{label:"Copy",onClick:()=>t4(s4(t,e))}}),warning:(t,e)=>$i.warning(t,{...e,action:e?.action||{label:"Copy",onClick:()=>t4(s4(t,e))}})},hw=/token|auth|secret|api/i,_r=t=>{const e=t.trim();if(!e)return null;try{const n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?null:e.split("#")[0]||null}catch{return null}},Br=t=>{const e=_r(t);if(!e)return t;try{const n=new URL(e),r=Array.from(new Set(Array.from(n.searchParams.keys())));for(const o of r)hw.test(o)&&n.searchParams.set(o,"[REDACTED]");return n.toString()}catch{return e}},Ci=(t,e)=>{const n=_r(t),r=_r(e);if(!n||!r)return!1;try{const o=new URL(n),a=new URL(r);if(o.origin!==a.origin||a.search&&o.search!==a.search)return!1;const l=a.pathname.length>1?a.pathname.replace(/\/+$/,""):a.pathname,i=o.pathname.length>1?o.pathname.replace(/\/+$/,""):o.pathname;return l==="/"?!0:i===l||i.startsWith(`${l}/`)}catch{return!1}},Ou=t=>typeof t=="object"&&t!==null,gi=(t,e)=>{const n=t[e];return typeof n=="string"?n:null},n4=(t,e)=>{const n=t[e];return typeof n=="number"&&Number.isFinite(n)?n:null},pw=t=>{if(!Ou(t))return null;const e=gi(t,"id"),n=gi(t,"label"),r=gi(t,"url");return!e||!n||!r?null:{id:e,label:n,url:r}},Q2=()=>{if(!_n())return null;const t=window.__TAURI__;return typeof t?.core?.invoke=="function"?t.core.invoke:null},Vu=async()=>{const t=Q2();if(!t)return{hosts:[],defaultHostId:"local"};const e=await t("desktop_hosts_get");if(!Ou(e))return{hosts:[],defaultHostId:null};const n=e.hosts,r=Array.isArray(n)?n.map(pw).filter(a=>!!a):[],o=gi(e,"defaultHostId")||gi(e,"default_host_id")||gi(e,"defaultHostID");return{hosts:r,defaultHostId:o}},gw=async t=>{const e=Q2();e&&await e("desktop_hosts_set",{config:{hosts:t.hosts,defaultHostId:t.defaultHostId}})},r4=async t=>{const e=Q2();if(!e)return{status:"unreachable",latencyMs:0};const n=await e("desktop_host_probe",{url:t});if(!Ou(n))return{status:"unreachable",latencyMs:0};const r=n.status,o=r==="ok"||r==="auth"||r==="unreachable"?r:"unreachable",a=n4(n,"latencyMs")??n4(n,"latency_ms")??0;return{status:o,latencyMs:a}},xw=async t=>{const e=Q2();e&&await e("desktop_new_window_at_url",{url:t})},ho=t=>typeof t=="object"&&t!==null,Cn=(t,e)=>{const n=t[e];return typeof n=="string"?n:null},tr=(t,e)=>{const n=t[e];return typeof n=="number"&&Number.isFinite(n)?n:null},Do=(t,e)=>{const n=t[e];return typeof n=="boolean"?n:null},bw=t=>Array.isArray(t)?t.filter(e=>typeof e=="string"):[],Ja=()=>{if(!_n())return null;const t=window.__TAURI__;return typeof t?.core?.invoke=="function"?t.core.invoke:null},o4=t=>{if(!ho(t))return;const e=Do(t,"enabled")??!1,r=Cn(t,"store")?.toLowerCase()==="settings"?"settings":"never",o=Cn(t,"value");return{enabled:e,store:r,...o?{value:o}:{}}},vw=t=>t==="remote"||t==="dynamic"?t:"local",yw=t=>{if(!ho(t))return null;const e=Cn(t,"id");if(!e)return null;const n=Do(t,"enabled")??!0,r=vw(Cn(t,"type")),o=Cn(t,"localHost")||Cn(t,"local_host")||void 0,a=tr(t,"localPort")??tr(t,"local_port")??void 0,l=Cn(t,"remoteHost")||Cn(t,"remote_host")||void 0,i=tr(t,"remotePort")??tr(t,"remote_port")??void 0;return{id:e,enabled:n,type:r,...o?{localHost:o}:{},...typeof a=="number"?{localPort:a}:{},...l?{remoteHost:l}:{},...typeof i=="number"?{remotePort:i}:{}}},ww=t=>{if(!ho(t))return null;const e=Cn(t,"id"),n=Cn(t,"sshCommand")||Cn(t,"ssh_command");if(!e||!n)return null;const r=Cn(t,"nickname"),o=t.sshParsed,a=ho(o)?{destination:Cn(o,"destination")||"",args:bw(o.args)}:void 0,l=ho(t.remoteOpenchamber)?t.remoteOpenchamber:ho(t.remote_openchamber)?t.remote_openchamber:{},i=ho(t.localForward)?t.localForward:ho(t.local_forward)?t.local_forward:{},c=ho(t.auth)?t.auth:{},m=Cn(l,"mode")?.toLowerCase()==="external"?"external":"managed",f=Cn(l,"installMethod")||Cn(l,"install_method"),h=f==="npm"||f==="download_release"||f==="upload_bundle"?f:"bun",p=Cn(i,"bindHost")||Cn(i,"bind_host")||"127.0.0.1",g=p==="localhost"||p==="0.0.0.0"?p:"127.0.0.1",b=(Array.isArray(t.portForwards)?t.portForwards:Array.isArray(t.port_forwards)?t.port_forwards:[]).map(N=>yw(N)).filter(N=>!!N),v=tr(l,"preferredPort")??tr(l,"preferred_port"),y=tr(i,"preferredLocalPort")??tr(i,"preferred_local_port"),w=o4(c.sshPassword||c.ssh_password),C=o4(c.openchamberPassword||c.openchamber_password);return{id:e,...r?{nickname:r}:{},sshCommand:n,...a&&a.destination?{sshParsed:a}:{},connectionTimeoutSec:tr(t,"connectionTimeoutSec")??tr(t,"connection_timeout_sec")??60,remoteOpenchamber:{mode:m,keepRunning:Do(l,"keepRunning")??Do(l,"keep_running")??!0,...v?{preferredPort:v}:{},installMethod:h,uploadBundleOverSsh:Do(l,"uploadBundleOverSsh")??Do(l,"upload_bundle_over_ssh")??!1},localForward:{...y?{preferredLocalPort:y}:{},bindHost:g},auth:{...w?{sshPassword:w}:{},...C?{openchamberPassword:C}:{}},portForwards:b}},jw=t=>{switch(t){case"config_resolved":case"auth_check":case"master_connecting":case"remote_probe":case"installing":case"updating":case"server_detecting":case"server_starting":case"forwarding":case"ready":case"degraded":case"error":return t;default:return"idle"}},n8=t=>{if(!ho(t))return null;const e=Cn(t,"id");return e?{id:e,phase:jw(Cn(t,"phase")),...Cn(t,"detail")?{detail:Cn(t,"detail")||void 0}:{},...Cn(t,"localUrl")||Cn(t,"local_url")?{localUrl:Cn(t,"localUrl")||Cn(t,"local_url")||void 0}:{},...typeof(tr(t,"localPort")??tr(t,"local_port"))=="number"?{localPort:tr(t,"localPort")??tr(t,"local_port")??void 0}:{},...typeof(tr(t,"remotePort")??tr(t,"remote_port"))=="number"?{remotePort:tr(t,"remotePort")??tr(t,"remote_port")??void 0}:{},startedByUs:Do(t,"startedByUs")??Do(t,"started_by_us")??!1,retryAttempt:tr(t,"retryAttempt")??tr(t,"retry_attempt")??0,requiresUserAction:Do(t,"requiresUserAction")??Do(t,"requires_user_action")??!1,updatedAtMs:tr(t,"updatedAtMs")??tr(t,"updated_at_ms")??Date.now()}:null},kw=t=>{if(!ho(t))return null;const e=Cn(t,"host"),n=Cn(t,"source"),r=Cn(t,"sshCommand")||Cn(t,"ssh_command");return!e||!n||!r?null:{host:e,source:n,sshCommand:r,pattern:Do(t,"pattern")??!1}},Nw=(t,e)=>({id:t,sshCommand:e,connectionTimeoutSec:60,remoteOpenchamber:{mode:"managed",keepRunning:!0,installMethod:"bun",uploadBundleOverSsh:!1},localForward:{bindHost:"127.0.0.1"},auth:{},portForwards:[]}),r8=async()=>{const t=Ja();if(!t)return{instances:[]};const e=await t("desktop_ssh_instances_get");return ho(e)?{instances:(Array.isArray(e.instances)?e.instances:Array.isArray(e.desktopSshInstances)?e.desktopSshInstances:[]).map(o=>ww(o)).filter(o=>!!o)}:{instances:[]}},Sw=async t=>{const e=Ja();e&&await e("desktop_ssh_instances_set",{config:{instances:t.instances}})},Cw=async()=>{const t=Ja();if(!t)return[];const e=await t("desktop_ssh_import_hosts");return Array.isArray(e)?e.map(n=>kw(n)).filter(n=>!!n):[]},Td=async t=>{const e=Ja();e&&await e("desktop_ssh_connect",{id:t})},Pd=async t=>{const e=Ja();e&&await e("desktop_ssh_disconnect",{id:t})},I1=async t=>{const e=Ja();if(!e)return[];const n=await e("desktop_ssh_status",{...t?{id:t}:{}});return Array.isArray(n)?n.map(r=>n8(r)).filter(r=>!!r):[]},Aw=async(t,e)=>{const n=Ja();if(!n)return[];const r=await n("desktop_ssh_logs",{id:t,limit:e});return Array.isArray(r)?r.filter(o=>typeof o=="string"):[]},Mw=async t=>{const e=Ja();e&&await e("desktop_ssh_logs_clear",{id:t})},Fw=async t=>{if(!_n())return async()=>{};const n=window.__TAURI__?.event?.listen;if(typeof n!="function")return async()=>{};const r=await n("archcoder:ssh-instance-status",o=>{const a=n8(o?.payload);a&&t(a)});return async()=>{await r()}},kr="local",a4=9e4,m2="SSH connection cancelled",Wi=t=>{const e=_r(t);if(!e)return t.trim();try{const n=new URL(e);return n.pathname.endsWith("/")||(n.pathname=`${n.pathname}/`),n.toString()}catch{return e}},fi=()=>typeof window>"u"?"":window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,Bw=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,_w=t=>t==="ok"?"bg-status-success":t==="auth"?"bg-status-warning":t==="unreachable"?"bg-status-error":"bg-muted-foreground/40",Ew=t=>t==="ok"?"Connected":t==="auth"?"Auth required":t==="unreachable"?"Unreachable":"Unknown",Dw=t=>t==="ok"?s.jsx(js,{className:"h-4 w-4"}):t==="auth"?s.jsx(Bh,{className:"h-4 w-4"}):t==="unreachable"?s.jsx(Kg,{className:"h-4 w-4"}):s.jsx(Yg,{className:"h-4 w-4"}),Iw=t=>new Promise(e=>window.setTimeout(e,t)),l4=t=>{switch(t){case"ready":return"Ready";case"error":return"Error";case"degraded":return"Reconnecting";case"config_resolved":return"Resolving config";case"auth_check":return"Checking auth";case"master_connecting":return"Connecting SSH";case"remote_probe":return"Probing remote";case"installing":return"Installing";case"updating":return"Updating";case"server_detecting":return"Detecting server";case"server_starting":return"Starting server";case"forwarding":return"Forwarding ports";default:return"Idle"}},Tw=t=>!t||t==="idle"?null:t==="ready"?"ok":t==="error"?"unreachable":"auth",i4=async()=>{const t=await I1().catch(()=>[]),e={};for(const n of t)e[n.id]=n;return e},c4=async(t,e,n,r)=>{const o=Date.now()+e;for(;Date.now()<o;){if(r?.())throw new Error(m2);const l=(await I1(t).catch(()=>[])).find(i=>i.id===t);if(l){if(n(l),l.phase==="ready")return l;if(l.phase==="error")throw new Error(l.detail||"SSH connection failed")}await Iw(700)}throw r?.()?new Error(m2):new Error("Timed out waiting for SSH connection")},Pw=()=>({id:kr,label:"Local",url:fi()}),Rw=t=>{const e=typeof window>"u"?"":window.location.href,n=fi(),r=_r(n)||n,o=_r(e)||e;if(e&&Ci(e,n))return{id:kr,label:"Local",url:r};const a=t.find(l=>e?Ci(e,l.url):!1);return a?{id:a.id,label:a.label,url:_r(a.url)||a.url}:{id:"custom",label:Br(o||"Instance"),url:o}};function o8({open:t,onOpenChange:e,embedded:n=!1,onHostSwitched:r}){const o=Ee(Z=>Z.setSettingsDialogOpen),a=Ee(Z=>Z.setSettingsPage),[l,i]=he.useState([]),[c,u]=he.useState(null),[m,f]=he.useState({}),[h,p]=he.useState(!1),[g,x]=he.useState(!1),[b,v]=he.useState(!1),[y,w]=he.useState(null),[C,N]=he.useState({}),[S,k]=he.useState({}),[j,F]=he.useState({open:!1,hostId:null,hostLabel:"",phase:"idle",detail:null,error:null}),[A,M]=he.useState(""),[B,E]=he.useState(null),[I,P]=he.useState(""),[D,L]=he.useState(""),[T,_]=he.useState(""),[z,R]=he.useState(""),[W,G]=he.useState(!n),Y=he.useRef(0),J=he.useMemo(()=>{const Z=Pw(),ie=l.map(pe=>({...pe,url:_r(pe.url)||pe.url}));return[Z,...ie]},[l]),V=he.useMemo(()=>Rw(J),[J]),te=he.useMemo(()=>{const Z=c||kr;return J.find(ie=>ie.id===Z)?.label||"Local"},[J,c]),U=he.useCallback(async(Z,ie)=>{if(_n()){v(!0),M("");try{const pe=Z.filter(me=>me.id!==kr);await gw({hosts:pe,defaultHostId:ie}),i(pe),u(ie)}catch(pe){M(pe instanceof Error?pe.message:"Failed to save")}finally{v(!1)}}},[]),X=he.useCallback(()=>{a("remote-instances"),o(!0),e(!1)},[e,o,a]),$=he.useCallback(async()=>{if(_n()){p(!0),M("");try{const[Z,ie,pe]=await Promise.all([Vu(),r8().catch(()=>({instances:[]})),i4()]),me={};for(const Se of ie.instances)me[Se.id]=!0;i(Z.hosts||[]),u(Z.defaultHostId??null),N(me),k(pe)}catch(Z){M(Z instanceof Error?Z.message:"Failed to load"),i([]),u(null),N({}),k({})}finally{p(!1)}}},[]),q=he.useCallback(async Z=>{if(_n()){x(!0);try{const ie=await Promise.all(Z.map(async me=>{const Se=_r(me.url);if(!Se)return[me.id,{status:"unreachable",latencyMs:0}];const ke=await r4(Se).catch(()=>({status:"unreachable",latencyMs:0}));return[me.id,{status:ke.status,latencyMs:ke.latencyMs}]})),pe={};for(const[me,Se]of ie)pe[me]=Se;f(pe)}finally{x(!1)}}},[]);he.useEffect(()=>{if(!t){E(null),P(""),L(""),_(""),R(""),G(!n),w(null),F({open:!1,hostId:null,hostLabel:"",phase:"idle",detail:null,error:null}),M("");return}$()},[n,t,$]),he.useEffect(()=>{t&&q(J)},[t,J,q]),he.useEffect(()=>{if(!t||!_n())return;let Z=!1;const ie=async()=>{const me=await i4();Z||k(me)};ie();const pe=window.setInterval(()=>{ie()},1500);return()=>{Z=!0,window.clearInterval(pe)}},[t]);const ee=he.useCallback(async Z=>{const ie=Z.id===kr?fi():_r(Z.url)||"";if(!ie)return;const pe=!!C[Z.id];if(Z.id!==kr&&pe&&_n()){let Se=S[Z.id];const ke=await I1(Z.id).then(_e=>_e.find(de=>de.id===Z.id)||null).catch(()=>null);ke&&(Se=ke,k(_e=>({..._e,[Z.id]:ke})));const ye=_r(Se?.localUrl||Z.url||"");if(Se?.phase==="ready"&&ye){const _e=Wi(ye);r?.(),window.location.assign(_e);return}w(Z.id);const Ne=Y.current+1;Y.current=Ne,F({open:!0,hostId:Z.id,hostLabel:Br(Z.label),phase:"master_connecting",detail:null,error:null});try{if(await Td(Z.id),Ne!==Y.current)return;const _e=await c4(Z.id,a4,je=>{k(Ce=>({...Ce,[je.id]:je})),F(Ce=>({...Ce,phase:je.phase,detail:je.detail||null}))},()=>Ne!==Y.current);if(Ne!==Y.current)return;const de=_r(_e.localUrl||"")||ie,we=Wi(de);r?.(),window.location.assign(we);return}catch(_e){if(Ne!==Y.current)return;const de=_e instanceof Error?_e.message:String(_e);if(de===m2)return;F(we=>({...we,error:de})),fe.error(`SSH instance "${Br(Z.label)}" failed to connect`,{description:de});return}finally{Ne===Y.current&&w(null)}}if(Z.id!==kr&&_n()){w(Z.id);const Se=await r4(ie).catch(()=>({status:"unreachable",latencyMs:0}));if(f(ke=>({...ke,[Z.id]:{status:Se.status,latencyMs:Se.latencyMs}})),Se.status==="unreachable"){fe.error(`Instance "${Br(Z.label)}" is unreachable`),w(null);return}}const me=Wi(ie);r?.();try{window.location.assign(me)}catch{window.location.href=me}},[r,C,S]),ce=he.useCallback(Z=>{E(Z.id),P(Z.label),L(Z.url),M("")},[]),ve=he.useCallback(()=>{E(null),P(""),L("")},[]),ge=he.useCallback(async()=>{if(!B)return;if(B===kr){ve();return}const Z=_r(D);if(!Z){M("Invalid URL (must be http/https)");return}const ie=(I||Br(Z)).trim(),pe=l.map(me=>me.id===B?{...me,label:ie,url:Z}:me);await U(pe,c),ve()},[ve,l,c,I,D,B,U]),xe=he.useCallback(async()=>{const Z=_r(z);if(!Z){M("Invalid URL (must be http/https)");return}const ie=(T||Br(Z)).trim(),me=[{id:Bw(),label:ie,url:Z},...l];await U(me,c),_(""),R(""),n&&G(!1)},[l,c,n,T,z,U]),ne=he.useCallback(async Z=>{if(Z===kr)return;const ie=l.filter(me=>me.id!==Z);await U(ie,c===Z?kr:c)},[l,c,U]),O=he.useCallback(async Z=>{await U(l,Z===kr?kr:Z)},[l,U]),H=he.useCallback(Z=>{const ie=Z.id===kr?fi():_r(Z.url)||"";if(!ie)return;const pe=Wi(ie);xw(pe).catch(me=>{fe.error("Failed to open new window",{description:me instanceof Error?me.message:String(me)})})},[]),K=he.useCallback(()=>{Y.current+=1,w(null),F(ie=>({...ie,open:!1,hostId:null,error:null,detail:null,phase:"idle"}));const Z=Wi(fi());r?.(),window.location.assign(Z)},[r]),re=he.useCallback(async()=>{const Z=j.hostId||y;Y.current+=1,w(null),F({open:!1,hostId:null,hostLabel:"",phase:"idle",detail:null,error:null}),!(!Z||Z===kr||!_n())&&await Pd(Z).catch(()=>{})},[j.hostId,y]),le=he.useCallback(()=>{const Z=j.hostId;if(!Z)return;const ie=J.find(pe=>pe.id===Z);ie&&ee(ie)},[J,ee,j.hostId]),ae=he.useCallback(async Z=>{if(_n()){w(Z.id);try{await Td(Z.id),(await c4(Z.id,a4,pe=>{k(me=>({...me,[pe.id]:pe}))})).phase==="ready"&&fe.success(`SSH instance "${Br(Z.label)}" connected`)}catch(ie){const pe=ie instanceof Error?ie.message:String(ie);pe!==m2&&fe.error(`SSH instance "${Br(Z.label)}" failed to connect`,{description:pe})}finally{w(null)}}},[]);if(!Rn())return null;const ue=_n(),be=s.jsxs(s.Fragment,{children:[n?s.jsx("div",{className:"flex-shrink-0 border-b border-[var(--interactive-border)] px-3 py-2",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-1.5 typography-ui-label",children:[s.jsx("span",{className:"font-medium text-foreground",children:"Current"}),s.jsx("span",{className:"max-w-[9rem] truncate text-muted-foreground",children:Br(V.label)}),s.jsx("span",{className:"text-muted-foreground/50",children:"•"}),s.jsx("span",{className:"font-medium text-foreground",children:"Default"}),s.jsx("span",{className:"max-w-[9rem] truncate text-muted-foreground",children:Br(te)})]}),s.jsx("button",{type:"button",className:Q("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:()=>{q(J)},disabled:!ue||h||g,"aria-label":"Refresh instances",children:s.jsx(Qn,{className:Q("h-4 w-4",g&&"animate-spin")})})]})}):s.jsxs(Zs,{className:"flex-shrink-0",children:[s.jsxs(Us,{className:"flex items-center gap-2",children:[s.jsx(Cl,{className:"h-5 w-5"}),"Instance"]}),s.jsx(sn,{children:"Switch between Local and remote ArchCoder servers"})]}),!n&&s.jsxs("div",{className:"flex items-center justify-between gap-2 flex-shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Current:"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Br(V.label)}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Current default:"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Br(te)})]}),s.jsx("div",{className:"flex items-center gap-1",children:s.jsxs(Be,{type:"button",size:"sm",variant:"ghost",onClick:()=>{q(J)},disabled:!ue||h||g,children:[s.jsx(Qn,{className:Q("h-4 w-4",g&&"animate-spin")}),"Refresh"]})})]}),ue&&s.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between gap-2 px-2.5 py-1.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["Need SSH instances?",s.jsx("br",{}),"Manage them in Settings."]}),s.jsxs(Be,{type:"button",variant:"ghost",size:"sm",onClick:X,children:[s.jsx(xa,{className:"h-4 w-4"}),"Remote SSH"]})]}),!ue&&s.jsx("div",{className:"flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:"Instance switcher is limited on this page. Use Local to recover."})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:s.jsx("div",{className:"space-y-1",children:h?s.jsx("div",{className:"px-2 py-2 text-muted-foreground text-sm",children:"Loading…"}):J.map(Z=>{const ie=Z.id===kr,pe=!!C[Z.id],me=Z.id===V.id,Se=(c||kr)===Z.id,ke=m[Z.id]||null,ye=S[Z.id]||null,Ne=pe?Tw(ye?.phase):ke?.status??null,_e=B===Z.id,de=ie?fi():_r(Z.url)||Z.url,we=Br(Z.label),je=Br(de);return s.jsxs("div",{className:Q("group flex items-center gap-2 px-2.5 py-2 rounded-md overflow-hidden",_e?"bg-interactive-hover/20":"hover:bg-interactive-hover/30"),children:[s.jsxs("button",{type:"button",className:Q("flex items-center gap-2 flex-1 min-w-0 text-left",_e&&"pointer-events-none opacity-70"),onClick:()=>{ee(Z)},disabled:y===Z.id,"aria-label":`Switch to ${we}`,children:[s.jsx("span",{className:Q("h-2 w-2 rounded-full flex-shrink-0",_w(Ne))}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:Q("typography-ui-label truncate","text-foreground"),children:we}),pe&&s.jsx("span",{className:"typography-micro px-1 rounded leading-none pb-px text-[var(--status-info)] bg-[var(--status-info)]/10",children:"SSH"}),me&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:"Current"}),s.jsxs("span",{className:"inline-flex items-center gap-1 typography-micro text-muted-foreground",children:[Dw(Ne),s.jsxs("span",{children:[pe?l4(ye?.phase):Ew(ke?.status??null),!pe&&ke?.status==="ok"&&typeof ke.latencyMs=="number"?` · ${Math.max(0,Math.round(ke.latencyMs))}ms ping`:""]})]})]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate font-mono",children:je})]})]}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[!ie&&!pe&&s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:"h-8 w-8 rounded-md inline-flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-interactive-hover transition-colors","aria-label":"Instance actions",disabled:b,onClick:Ce=>Ce.stopPropagation(),children:s.jsx(Qr,{className:"h-4 w-4"})})}),s.jsxs(Ys,{align:"end",className:"w-fit min-w-28",children:[s.jsxs(Jt,{onClick:Ce=>{Ce.stopPropagation(),ce(Z)},disabled:b,children:[s.jsx(Fh,{className:"h-4 w-4 mr-1"}),"Edit"]}),s.jsxs(Jt,{onClick:Ce=>{Ce.stopPropagation(),ne(Z.id)},className:"text-destructive focus:text-destructive",disabled:b,children:[s.jsx(Pn,{className:"h-4 w-4 mr-1"}),"Delete"]})]})]}),ie&&s.jsx("div",{className:"h-8 w-8 opacity-0 pointer-events-none","aria-hidden":"true"}),pe&&!ie&&(ye?.phase==="idle"||!ye?.phase?s.jsxs(Be,{type:"button",variant:"outline",size:"sm",className:"h-8 px-2.5",disabled:y===Z.id,onClick:Ce=>{Ce.stopPropagation(),ae(Z)},children:[y===Z.id?s.jsx(ts,{className:"h-3.5 w-3.5 animate-spin"}):s.jsx(xu,{className:"h-3.5 w-3.5"}),"Connect"]}):s.jsx("div",{className:"h-8 w-8 opacity-0 pointer-events-none","aria-hidden":"true"})),s.jsxs(Dt,{delayDuration:700,children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:Q("h-8 w-8 rounded-md inline-flex items-center justify-center hover:bg-interactive-hover transition-colors",Se?"text-primary hover:text-primary/80":"text-muted-foreground/60 hover:text-primary/80"),onClick:()=>{O(Z.id)},"aria-label":Se?"Default instance":"Set as default",disabled:b,children:Se?s.jsx(Yo,{className:"h-4 w-4"}):s.jsx(bl,{className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:Se?"Default":"Set as default"})]}),s.jsxs(Dt,{delayDuration:700,children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:Q("h-8 w-8 rounded-md inline-flex items-center justify-center hover:bg-interactive-hover transition-colors",Ne==="unreachable"?"text-muted-foreground/30 cursor-not-allowed":"text-muted-foreground/60 hover:text-foreground"),onClick:Ce=>{Ce.stopPropagation(),H(Z)},disabled:Ne==="unreachable","aria-label":"Open in new window",children:s.jsx(I0,{className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:Ne==="unreachable"?"Instance unreachable":"Open in new window"})]})]})]},Z.id)})})}),ue&&B&&B!==kr&&s.jsxs("div",{className:"flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:"Edit instance"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{type:"button",variant:"outline",size:"sm",onClick:ve,disabled:b,children:"Cancel"}),s.jsxs(Be,{type:"button",size:"sm",onClick:()=>{ge()},disabled:b,children:[b?s.jsx(ts,{className:"h-4 w-4 animate-spin"}):null,"Save"]})]})]}),s.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[s.jsx(Xt,{value:I,onChange:Z=>P(Z.target.value),placeholder:"Label",disabled:b}),s.jsx(Xt,{value:D,onChange:Z=>L(Z.target.value),placeholder:"https://host:port",disabled:b})]})]}),n&&!W?s.jsx("div",{className:"flex-shrink-0 border-t border-[var(--interactive-border)]",children:s.jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-2 py-2 text-left text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors",onClick:()=>G(!0),disabled:!ue||b,children:[s.jsx(Qs,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label",children:"Add instance"})]})}):s.jsxs("div",{className:Q("flex-shrink-0",n?"border-t border-[var(--interactive-border)] px-2 py-2":"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-2.5"),children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:"Add instance"}),s.jsxs("div",{className:"flex items-center gap-2",children:[n&&s.jsx(Be,{type:"button",variant:"ghost",size:"sm",onClick:()=>G(!1),disabled:b,children:"Cancel"}),s.jsxs(Be,{type:"button",size:"sm",onClick:()=>{xe()},disabled:!ue||b||!z.trim(),children:[b?s.jsx(ts,{className:"h-4 w-4 animate-spin"}):null,"Add"]})]})]}),s.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[s.jsx(Xt,{value:T,onChange:Z=>_(Z.target.value),placeholder:"Label (optional)",disabled:!ue||b}),s.jsx(Xt,{value:z,onChange:Z=>R(Z.target.value),placeholder:"https://host:port",disabled:!ue||b})]})]}),A&&s.jsx("div",{className:"flex-shrink-0 typography-meta text-status-error",children:A})]}),oe=s.jsx(Os,{open:j.open,onOpenChange:Z=>{if(!Z&&y){re();return}F(ie=>({...ie,open:Z,...Z?{}:{hostId:null,error:null,detail:null,phase:"idle"}}))},children:s.jsxs(Vs,{className:"w-[min(28rem,calc(100vw-2rem))] max-w-none",children:[s.jsxs(Zs,{children:[s.jsxs(Us,{className:"flex items-center gap-2",children:[s.jsx(ts,{className:Q("h-4 w-4",!j.error&&"animate-spin")}),"Connecting to ",j.hostLabel||"SSH instance"]}),s.jsx(sn,{children:j.error?j.error:j.detail||l4(j.phase)})]}),j.error?s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(Be,{type:"button",size:"sm",variant:"outline",onClick:K,children:"Switch to Local"}),s.jsx(Be,{type:"button",size:"sm",onClick:le,disabled:!j.hostId,children:"Retry"})]}):null]})});return n?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"w-full max-h-[70vh] flex flex-col overflow-hidden gap-2",children:be}),oe]}):s.jsxs(s.Fragment,{children:[s.jsx(Os,{open:t,onOpenChange:e,children:s.jsx(Vs,{className:"w-[min(42rem,calc(100vw-2rem))] max-w-none max-h-[70vh] flex flex-col overflow-hidden gap-3",children:be})}),oe]})}function zw(){const t=Fe.c(3),[e,n]=he.useState(!1);if(!Rn())return null;let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs(Be,{type:"button",variant:"ghost",size:"sm","data-oc-host-switcher":!0,className:"w-full justify-center",onClick:()=>n(!0),children:[s.jsx(Cl,{className:"h-4 w-4"}),"Switch instance"]}),t[0]=r):r=t[0];let o;return t[1]!==e?(o=s.jsxs(s.Fragment,{children:[r,s.jsx(o8,{open:e,onOpenChange:n})]}),t[1]=e,t[2]=o):o=t[2],o}const Ha=[{id:"vscode",label:"VS Code",appName:"Visual Studio Code"},{id:"vscodium",label:"VSCodium",appName:"VSCodium"},{id:"cursor",label:"Cursor",appName:"Cursor"},{id:"windsurf",label:"Windsurf",appName:"Windsurf"},{id:"zed",label:"Zed",appName:"Zed",platforms:["macos","linux"]},{id:"intellij",label:"IntelliJ",appName:"IntelliJ IDEA"},{id:"pycharm",label:"PyCharm",appName:"PyCharm"},{id:"webstorm",label:"WebStorm",appName:"WebStorm"},{id:"rider",label:"Rider",appName:"Rider"},{id:"phpstorm",label:"PhpStorm",appName:"PhpStorm"},{id:"rustrover",label:"RustRover",appName:"RustRover"},{id:"android-studio",label:"Android Studio",appName:"Android Studio"},{id:"terminal",label:"Terminal",appName:"Terminal"},{id:"iterm2",label:"iTerm2",appName:"iTerm",platforms:["macos"]},{id:"ghostty",label:"Ghostty",appName:"Ghostty"},{id:"finder",label:"Finder",appName:"Finder",platforms:["macos"]},{id:"explorer",label:"Explorer",appName:"File Explorer",platforms:["windows"]},{id:"files",label:"Files",appName:"File Manager",platforms:["linux"]},{id:"visual-studio",label:"Visual Studio",appName:"Visual Studio",platforms:["windows"]},{id:"xcode",label:"Xcode",appName:"Xcode",platforms:["macos"]},{id:"sublime-text",label:"Sublime",appName:"Sublime Text"},{id:"eclipse",label:"Eclipse",appName:"Eclipse"},{id:"antigravity",label:"Antigravity",appName:"Antigravity"},{id:"trae",label:"Trae",appName:"Trae"}],Rd="vscode",zd=new Set(["terminal"]),Lw=new Set(["finder","terminal","iterm2","ghostty","explorer","files","wt"]),Ld=t=>t?Ha.find(e=>e.id===t)??null:null,pc=()=>Ha.filter(t=>zd.has(t.id)).map(t=>({...t})),Hw=()=>{if(typeof window>"u")return Rd;const t=window.localStorage.getItem("openInAppId");return t&&Ld(t)?t:Rd};let gc=!1,Gl=!1,Ba=!1,_a=0,h1=null;const d4=()=>{h1&&(clearTimeout(h1),h1=null)},Fo=Dr()((t,e)=>({selectedAppId:Hw(),availableApps:pc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(gc||typeof window>"u")return;gc=!0;const n=c=>{if(!Array.isArray(c)||c.length===0){t({availableApps:pc(),hasLoadedApps:!1});return}const u=new Set(c.map(p=>p.name)),m=new Map(c.map(p=>[p.name,p.iconDataUrl??void 0])),h=Ha.filter(p=>u.has(p.appName)||zd.has(p.id)).map(p=>({...p,iconDataUrl:m.get(p.appName)}));t({availableApps:h,hasLoadedApps:!0})},r=async c=>{if(!_n()||!$o()||Gl||e().hasLoadedApps&&!c)return;const m=Ha.map(f=>f.appName);d4(),Gl=!0,Ba=!1,t({isScanning:!0});try{const{apps:f,success:h,hasCache:p,isCacheStale:g}=await T3(m,c);if(t({isCacheStale:p?g:!1}),n(f),h){if(!p&&f.length===0&&_a<3){const b=[800,1600,3200][_a]??3200;_a+=1,Ba=!0,h1=setTimeout(()=>{r()},b);return}_a=0,Ba=!1;return}if(_a<3){const b=[1e3,3e3,7e3][_a]??7e3;_a+=1,Ba=!0,h1=setTimeout(()=>{r()},b)}}finally{Gl=!1,Ba||t({isScanning:!1})}};r();const o=c=>{const u=c.detail,m=u&&typeof u.openInAppId=="string"&&u.openInAppId.length>0&&Ld(u.openInAppId)?u.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},a=()=>{r()},l=c=>{const u=c.detail;Array.isArray(u)&&(_a=3,Ba=!1,t({isScanning:!1,isCacheStale:!1}),n(u))};window.addEventListener("archcoder:settings-synced",o),window.addEventListener("archcoder:app-ready",a),window.addEventListener("archcoder:installed-apps-updated",l),(window.__archcoderAppReady||window.__openchamberAppReady)&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(gc||e().initialize(),!_n()||!$o()||Gl||e().hasLoadedApps&&!n)return;const o=Ha.map(a=>a.appName);d4(),n&&t({hasLoadedApps:!1}),Gl=!0,Ba=!1,t({isScanning:!0});try{const{apps:a,hasCache:l,isCacheStale:i}=await T3(o,n),c=new Set(a.map(h=>h.name)),u=new Map(a.map(h=>[h.name,h.iconDataUrl??void 0])),f=Ha.filter(h=>c.has(h.appName)||zd.has(h.id)).map(h=>({...h,iconDataUrl:u.get(h.appName)}));t({availableApps:f.length>0?f:pc(),hasLoadedApps:f.length>0,isCacheStale:l?i:!1})}finally{Gl=!1,Ba||t({isScanning:!1})}},selectApp:async n=>{Ld(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ln({openInAppId:n}))}})),$w="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",Ow="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",xc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?$w:t.id==="terminal"?Ow:void 0}),u4=t=>{const e=Fe.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:o}=t,[a,l]=d.useState(!1);let i;e[0]!==n?(i=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=i):i=e[1];const c=i,u=r||o;if(u&&!a){let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>l(!0),e[2]=h):h=e[2];let p;return e[3]!==u?(p=s.jsx("img",{src:u,alt:"",className:"h-4 w-4 rounded-sm",onError:h}),e[3]=u,e[4]=p):p=e[4],p}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=Q("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let f;return e[6]!==c?(f=s.jsx("span",{className:m,children:c}),e[6]=c,e[7]=f):f=e[7],f},Vw=t=>{const e=Fe.c(64),{directory:n,activeFilePath:r,className:o}=t,a=Fo(Uw),l=Fo(Ww),i=Fo(qw),c=Fo(Gw),u=Fo(Zw),m=Fo(Kw),f=Fo(Yw);let h,p;e[0]!==u?(h=()=>{u()},p=[u],e[0]=u,e[1]=h,e[2]=p):(h=e[1],p=e[2]),d.useEffect(h,p);const g=_n()&&$o();let x;e:{let U;e[3]!==l||e[4]!==a?(U=l.find(q=>q.id===a)??l.find(Xw)??l[0]??Ha[0],e[3]=l,e[4]=a,e[5]=U):U=e[5];const X=U;if(X){let q;e[6]!==X?(q=xc(X),e[6]=X,e[7]=q):q=e[7],x=q;break e}let $;e[8]===Symbol.for("react.memo_cache_sentinel")?($=xc(Ha[0]),e[8]=$):$=e[8],x=$}const b=x;if(!g||!n||l.length===0)return null;let v;e[9]!==r||e[10]!==n?(v=async U=>{await N6(n,U.id,U.appName,r)||await L0(n,U.appName)},e[9]=r,e[10]=n,e[11]=v):v=e[11];const y=v;let w;e[12]!==y||e[13]!==f?(w=async U=>{await f(U.id),await y(U)},e[12]=y,e[13]=f,e[14]=w):w=e[14];const C=w;let N;e[15]!==n?(N=async()=>{(await Dn(n)).ok&&fe.success("Path copied to clipboard")},e[15]=n,e[16]=N):N=e[16];const S=N;let k;e[17]!==o?(k=Q("app-region-no-drag inline-flex h-7 items-center self-center rounded-md border border-[var(--interactive-border)]","bg-[var(--surface-elevated)] shadow-none overflow-hidden",o),e[17]=o,e[18]=k):k=e[18];let j;e[19]!==y||e[20]!==b?(j=()=>{y(b)},e[19]=y,e[20]=b,e[21]=j):j=e[21];let F;e[22]===Symbol.for("react.memo_cache_sentinel")?(F=Q("inline-flex h-full items-center gap-2 px-3 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors"),e[22]=F):F=e[22];const A=`Open in ${b.label}`;let M;e[23]!==b.fallbackIconDataUrl||e[24]!==b.iconDataUrl||e[25]!==b.label?(M=s.jsx(u4,{label:b.label,iconDataUrl:b.iconDataUrl,fallbackIconDataUrl:b.fallbackIconDataUrl}),e[23]=b.fallbackIconDataUrl,e[24]=b.iconDataUrl,e[25]=b.label,e[26]=M):M=e[26];const B=c?"animate-pulse text-muted-foreground":void 0;let E;e[27]!==B?(E=Q("header-open-label",B),e[27]=B,e[28]=E):E=e[28];let I;e[29]!==E?(I=s.jsx("span",{className:E,children:"Open"}),e[29]=E,e[30]=I):I=e[30];let P;e[31]!==A||e[32]!==M||e[33]!==I||e[34]!==j?(P=s.jsxs("button",{type:"button",onClick:j,className:F,"aria-label":A,children:[M,I]}),e[31]=A,e[32]=M,e[33]=I,e[34]=j,e[35]=P):P=e[35];let D;e[36]===Symbol.for("react.memo_cache_sentinel")?(D=Q("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]=D):D=e[36];let L;e[37]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:D,"aria-label":"Choose app to open",children:s.jsx(Ds,{className:"h-4 w-4"})})}),e[37]=L):L=e[37];let T;e[38]===Symbol.for("react.memo_cache_sentinel")?(T={translate:"-30px 0"},e[38]=T):T=e[38];let _;e[39]!==S?(_=()=>{S()},e[39]=S,e[40]=_):_=e[40];let z,R;e[41]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(nr,{className:"h-4 w-4"}),R=s.jsx("span",{className:"typography-ui-label text-foreground",children:"Copy Path"}),e[41]=z,e[42]=R):(z=e[41],R=e[42]);let W;e[43]!==_?(W=s.jsxs(Jt,{className:"flex items-center gap-2",onClick:_,children:[z,R]}),e[43]=_,e[44]=W):W=e[44];let G;e[45]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(Zn,{}),e[45]=G):G=e[45];let Y;if(e[46]!==l||e[47]!==C||e[48]!==b.id){let U;e[50]!==C||e[51]!==b.id?(U=X=>{const $=xc(X);return s.jsxs(Jt,{className:"flex items-center gap-2",onClick:()=>{C(X)},children:[s.jsx(u4,{label:X.label,iconDataUrl:X.iconDataUrl,fallbackIconDataUrl:$.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:X.label}),b.id===X.id?s.jsx(js,{className:"ml-auto h-4 w-4 text-primary"}):null]},X.id)},e[50]=C,e[51]=b.id,e[52]=U):U=e[52],Y=l.map(U),e[46]=l,e[47]=C,e[48]=b.id,e[49]=Y}else Y=e[49];let J;e[53]!==i||e[54]!==m?(J=i?s.jsxs(Jt,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(Qn,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:"Refresh Apps"})]}):null,e[53]=i,e[54]=m,e[55]=J):J=e[55];let V;e[56]!==W||e[57]!==Y||e[58]!==J?(V=s.jsxs(qs,{children:[L,s.jsxs(Ys,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:T,children:[W,G,Y,J]})]}),e[56]=W,e[57]=Y,e[58]=J,e[59]=V):V=e[59];let te;return e[60]!==P||e[61]!==V||e[62]!==k?(te=s.jsxs("div",{className:k,children:[P,V]}),e[60]=P,e[61]=V,e[62]=k,e[63]=te):te=e[63],te};function Uw(t){return t.selectedAppId}function Ww(t){return t.availableApps}function qw(t){return t.isCacheStale}function Gw(t){return t.isScanning}function Zw(t){return t.initialize}function Kw(t){return t.loadInstalledApps}function Yw(t){return t.selectApp}function Xw(t){return t.id===Rd}const Qw=1e6,Jw="terminal-store";let f4=!1;const bc=t=>typeof t=="object"&&t!==null,ej=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function ao(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const vc=(t,e)=>({id:t,terminalSessionId:null,label:e,bufferChunks:[],bufferLength:0,isConnecting:!1,createdAt:Date.now()}),yc=t=>({tabs:[t],activeTabId:t.id}),rl=(t,e)=>t.tabs.findIndex(n=>n.id===e),fo=Dr()(wa(Pl((t,e)=>({sessions:new Map,nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=ao(n);r&&t(o=>{if(o.sessions.has(r))return o;const a=new Map(o.sessions),l=`tab-${o.nextTabId}`,i=vc(l,"Terminal");return a.set(r,yc(i)),{sessions:a,nextTabId:o.nextTabId+1}})},getDirectoryState:n=>{const r=ao(n);return e().sessions.get(r)},getActiveTab:n=>{const r=ao(n),o=e().sessions.get(r);if(!o)return;const a=o.activeTabId;return a?o.tabs.find(l=>l.id===a)??o.tabs[0]:o.tabs[0]},createTab:n=>{const r=ao(n);if(!r)return"tab-invalid";const o=`tab-${e().nextTabId}`;return t(a=>{const l=new Map(a.sessions),i=l.get(r),c=a.nextTabId+1,m=`Terminal ${(i?.tabs.length??0)+1}`,f=vc(o,m);return i?l.set(r,{...i,tabs:[...i.tabs,f]}):l.set(r,yc(f)),{sessions:l,nextTabId:c}}),o},setActiveTab:(n,r)=>{const o=ao(n);t(a=>{const l=new Map(a.sessions),i=l.get(o);return!i||i.activeTabId===r||rl(i,r)<0?a:(l.set(o,{...i,activeTabId:r}),{sessions:l})})},setTabLabel:(n,r,o)=>{const a=ao(n),l=o.trim();l&&t(i=>{const c=new Map(i.sessions),u=c.get(a);if(!u)return i;const m=rl(u,r);if(m<0||u.tabs[m]?.label===l)return i;const f=[...u.tabs];return f[m]={...f[m],label:l},c.set(a,{...u,tabs:f}),{sessions:c}})},closeTab:async(n,r)=>{const o=ao(n),i=e().sessions.get(o)?.tabs.find(c=>c.id===r)?.terminalSessionId??null;if(i)try{await qb(i)}catch{}t(c=>{const u=new Map(c.sessions),m=u.get(o);if(!m)return c;const f=rl(m,r);if(f<0)return c;const h=m.tabs.filter(g=>g.id!==r);if(h.length===0){const g=`tab-${c.nextTabId}`,x=vc(g,"Terminal");return u.set(o,yc(x)),{sessions:u,nextTabId:c.nextTabId+1}}let p=m.activeTabId;return m.activeTabId===r&&(p=h[Math.min(f,h.length-1)]?.id??h[0]?.id??null),u.set(o,{...m,tabs:h,activeTabId:p}),{sessions:u}})},setTabSessionId:(n,r,o)=>{const a=ao(n);t(l=>{const i=new Map(l.sessions),c=i.get(a);if(!c)return l;const u=rl(c,r);if(u<0)return l;const m=c.tabs[u],f=o!==null&&m.terminalSessionId!==o,h={...m,terminalSessionId:o,isConnecting:!1,...f?{bufferChunks:[],bufferLength:0}:{}},p=[...c.tabs];return p[u]=h,i.set(a,{...c,tabs:p}),{sessions:i}})},setConnecting:(n,r,o)=>{const a=ao(n);t(l=>{const i=new Map(l.sessions),c=i.get(a);if(!c)return l;const u=rl(c,r);if(u<0)return l;const m=[...c.tabs];return m[u]={...m[u],isConnecting:o},i.set(a,{...c,tabs:m}),{sessions:i}})},appendToBuffer:(n,r,o)=>{if(!o)return;const a=ao(n);t(l=>{const i=new Map(l.sessions),c=i.get(a);if(!c)return l;const u=rl(c,r);if(u<0)return l;const m=c.tabs[u],f=l.nextChunkId,h={id:f,data:o},p=[...m.bufferChunks,h];let g=m.bufferLength+o.length;for(;g>Qw&&p.length>1;){const b=p.shift();if(!b)break;g-=b.data.length}const x=[...c.tabs];return x[u]={...m,bufferChunks:p,bufferLength:g},i.set(a,{...c,tabs:x}),{sessions:i,nextChunkId:f+1}})},clearBuffer:(n,r)=>{const o=ao(n);t(a=>{const l=new Map(a.sessions),i=l.get(o);if(!i)return a;const c=rl(i,r);if(c<0)return a;const u=[...i.tabs];return u[c]={...u[c],bufferChunks:[],bufferLength:0},l.set(o,{...i,tabs:u}),{sessions:l}})},removeDirectory:n=>{const r=ao(n);t(o=>{const a=new Map(o.sessions);return a.delete(r),{sessions:a}})},clearAll:()=>{t({sessions:new Map,nextChunkId:1,nextTabId:1})}}),{name:Jw,storage:Ii(()=>Wb()),partialize:t=>({sessions:Array.from(t.sessions.entries()).map(([e,n])=>[e,{activeTabId:n.activeTabId,tabs:n.tabs.map(r=>({id:r.id,label:r.label,terminalSessionId:r.terminalSessionId,createdAt:r.createdAt}))}]),nextTabId:t.nextTabId}),merge:(t,e)=>{if(!bc(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let o=0;for(const i of n){if(!Array.isArray(i)||i.length!==2)continue;const[c,u]=i;if(typeof c!="string"||!bc(u))continue;const m=Array.isArray(u.tabs)?u.tabs:[],f=[];for(const g of m){if(!bc(g))continue;const x=typeof g.id=="string"?g.id:null;if(!x)continue;const b=ej(x);b!==null&&(o=Math.max(o,b)),f.push({id:x,label:typeof g.label=="string"?g.label:"Terminal",terminalSessionId:typeof g.terminalSessionId=="string"||g.terminalSessionId===null?g.terminalSessionId:null,createdAt:typeof g.createdAt=="number"?g.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1})}if(f.length===0)continue;const h=typeof u.activeTabId=="string"?u.activeTabId:null,p=h?f.some(g=>g.id===h):!1;r.set(c,{tabs:f,activeTabId:p?h:f[0].id})}const a=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,l=Math.max(e.nextTabId,a,o+1);return{...e,sessions:r,nextChunkId:1,nextTabId:l,hasHydrated:!0}}})));if(typeof window<"u"&&!f4){f4=!0;const t=fo.persist,e=()=>{fo.getState().hasHydrated||fo.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const m4=(t,e)=>e.updatedAtMs-t.updatedAtMs,Sn=Dr((t,e)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!e().isLoading){t({isLoading:!0,error:null});try{const[n,r]=await Promise.all([r8(),I1()]),o={};for(const a of r.sort(m4))o[a.id]=a;e().listenerReady||await Fw(a=>{t(l=>({statusesById:{...l.statusesById,[a.id]:a}}))}),t({instances:n.instances,statusesById:o,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await Cw();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await I1(),r={};for(const o of n.sort(m4))r[o.id]=o;t({statusesById:r})}catch(n){t({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{t({isSaving:!0,error:null});try{await Sw({instances:n}),t({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(r){throw t({isSaving:!1,error:r instanceof Error?r.message:String(r)}),r}},upsertInstance:async n=>{const r=e().instances,o=r.some(a=>a.id===n.id)?r.map(a=>a.id===n.id?n:a):[n,...r];await e().setInstances(o)},createFromCommand:async(n,r,o)=>{const a=Nw(n,r);o&&o.trim()&&(a.nickname=o.trim()),await e().upsertInstance(a)},removeInstance:async n=>{await Pd(n).catch(()=>{});const r=e().instances.filter(o=>o.id!==n);await e().setInstances(r),t(o=>{const a={...o.statusesById};return delete a[n],{statusesById:a}})},connect:async n=>{t({error:null});try{await Td(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},disconnect:async n=>{t({error:null});try{await Pd(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>t({error:null})})),a8=t=>{try{return new URL(t)}catch{return null}},tj=t=>{const e=a8(t.trim());return e?e.protocol==="http:"||e.protocol==="https:":!1},Xr=async t=>{if(typeof window>"u")return!1;const e=t.trim();if(!e)return!1;const n=a8(e);if(!n||n.protocol!=="http:"&&n.protocol!=="https:")return!1;const r=n.toString(),o=Ho();if(o?.runtime?.isVSCode&&o.vscode?.openExternalUrl)try{return await o.vscode.openExternalUrl(r),!0}catch{return!1}const a=window.__TAURI__;if(a?.shell?.open)try{return await a.shell.open(r),!0}catch{}try{return window.open(r,"_blank","noopener,noreferrer"),!0}catch{return!1}},l8=[{key:"play",label:"Play",Icon:Va},{key:"build",label:"Build",Icon:Xg},{key:"lint",label:"Lint",Icon:hi},{key:"terminal",label:"Terminal",Icon:Po},{key:"tools",label:"Tools",Icon:V1},{key:"bug",label:"Bug",Icon:Qg},{key:"flask",label:"Flask",Icon:Jg},{key:"rocket",label:"Rocket",Icon:e9},{key:"code",label:"Code",Icon:Al},{key:"server",label:"Server",Icon:Cl},{key:"branch",label:"Branch",Icon:on},{key:"search",label:"Search",Icon:xr},{key:"settings",label:"Settings",Icon:xa},{key:"brain",label:"Brain",Icon:oa},{key:"stack",label:"Stack",Icon:ya},{key:"robot",label:"Robot",Icon:zo},{key:"command",label:"Command",Icon:Rl},{key:"file",label:"File",Icon:M1}],O0=Object.fromEntries(l8.map(t=>[t.key,t.Icon])),Hd="openchamber:project-actions-updated",i8=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},Ea=(t,e)=>`${i8(t)}::${e}`,sj=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},h4=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},nj=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=h4(e.localPort),r=h4(e.remotePort);if(!n||!r)return null;const o=sj(e.localHost||t.localForward.bindHost||"127.0.0.1"),a=(e.remoteHost||"127.0.0.1").trim(),l=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${l} - ${o}:${n} -> ${a}:${r}`,url:`http://${o}:${n}`}},c8=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const o=nj(n,r);o&&e.push(o)}return e},rj=(t,e)=>{const n=(t||"").trim();return n&&c8(e).find(a=>a.id===n)?.url||null},oj=t=>new Promise(e=>{window.setTimeout(e,t)}),aj="\x1B",lj=new RegExp(`${aj}\\[[0-9;?]*[ -/]*[@-~]`,"g"),ij=/https?:\/\/[^\s<>'"`]+/gi,cj=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},dj=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}},uj=t=>{const n=t.replace(lj,"").match(ij);if(!n||n.length===0)return null;const r=n.map(a=>a.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const o=[];for(const a of r)try{const l=new URL(a);l.port&&l.port.length>0&&o.push({raw:a,parsed:l})}catch{}if(o.length>0){const a=l=>{const{parsed:i}=l,c=i.hostname.toLowerCase(),u=c==="localhost"||c==="127.0.0.1"||c==="0.0.0.0"||c==="::1",m=i.pathname||"/",f=m.split("/").filter(Boolean).length,h=m==="/"||m==="",p=!!(i.search||i.hash);let g=0;return u&&(g+=50),h&&(g+=30),g-=Math.min(f*5,20),p&&(g-=10),g};return o.sort((l,i)=>a(i)-a(l)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},fj=t=>{const e=t.trim();if(!e)return"Action";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],o=n[1].slice(0,3),a=`${r} ${o}`.trim();return n.length>2||a.length<e.length?`${a}...`:a}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},p4=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{terminal:a,runtime:l}=ur(),{isMobile:i}=wn(),c=d.useMemo(()=>Rn(),[]),u=Sn(ne=>ne.instances),m=Sn(ne=>ne.load),f=Ee(ne=>ne.setBottomTerminalOpen),h=Ee(ne=>ne.setActiveMainTab),p=Ee(ne=>ne.setSettingsPage),g=Ee(ne=>ne.setSettingsDialogOpen),x=Ee(ne=>ne.setSettingsProjectsSelectedId),b=fo(ne=>ne.sessions),v=fo(ne=>ne.ensureDirectory),y=fo(ne=>ne.setTabLabel),w=fo(ne=>ne.setActiveTab),C=fo(ne=>ne.setConnecting),N=fo(ne=>ne.setTabSessionId),[S,k]=d.useState([]),[j,F]=d.useState(null),[A,M]=d.useState(!1),[B,E]=d.useState({}),I=d.useRef({}),P=d.useRef({}),D=d.useRef(0),L=t?.id??null,T=t?.path??"",_=d.useMemo(()=>L?{id:L,path:T}:null,[L,T]);d.useEffect(()=>{c&&m().catch(()=>{})},[c,m]);const z=d.useCallback(async ne=>{await Xr(ne)},[]),R=d.useCallback(async()=>{if(!_)return;const ne=D.current+1;D.current=ne,M(!0);try{const O=await S6(_);if(D.current!==ne)return;const H=O.actions;k(H),F(K=>H.length===0?null:K&&H.some(re=>re.id===K)?K:H[0]?.id??null)}catch{if(D.current!==ne)return}finally{D.current===ne&&M(!1)}},[_]);d.useEffect(()=>{R()},[R]),d.useEffect(()=>{if(typeof window>"u")return;const ne=O=>{const H=O.detail;L&&(H?.projectId&&H.projectId!==L||R())};return window.addEventListener(Hd,ne),()=>{window.removeEventListener(Hd,ne)}},[R,L]),d.useEffect(()=>{j&&(S.some(ne=>ne.id===j)||F(S[0]?.id??null))},[S,j]),d.useEffect(()=>{E(ne=>{let O=!1;const H={};for(const[K,re]of Object.entries(ne)){const ae=b.get(re.directory)?.tabs.find(ue=>ue.id===re.tabId);if(!ae||ae.terminalSessionId!==re.sessionId){O=!0;continue}H[K]=re}return O?H:ne})},[b]),d.useEffect(()=>{for(const[ne,O]of Object.entries(B)){const H=P.current[ne]??{lastSeenChunkId:null,openedUrl:!1,tail:""};P.current[ne]=H;const K=S.find(ie=>ie.id===O.actionId);if(!K)continue;const le=b.get(O.directory)?.tabs.find(ie=>ie.id===O.tabId);if(!le||!Array.isArray(le.bufferChunks)||le.bufferChunks.length===0)continue;const ae=le.bufferChunks.filter(ie=>H.lastSeenChunkId===null?!0:ie.id>H.lastSeenChunkId);if(ae.length===0)continue;const ue=ae.map(ie=>ie.data).join(""),be=`${H.tail}${ue}`,oe=!H.openedUrl&&K.autoOpenUrl===!0?uj(be):null,Z=ae[ae.length-1]?.id??H.lastSeenChunkId;H.lastSeenChunkId=Z,H.tail=be.slice(-512),oe&&(H.openedUrl=!0,z(oe),fe.success("Opened URL from action output")),P.current[ne]=H}for(const ne of Object.keys(P.current))B[ne]||delete P.current[ne]},[S,z,B,b]);const W=d.useMemo(()=>i8(e||_?.path||""),[e,_?.path]),G=d.useMemo(()=>j?S.find(ne=>ne.id===j)??S[0]??null:S[0]??null,[S,j]),Y=d.useCallback(async ne=>{if(!W)throw new Error("No active directory");const O=Ea(W,ne.id);v(W);const H=fo.getState(),K=H.getDirectoryState(W);let re=I.current[O]||null;const le=re?!!K?.tabs.some(be=>be.id===re):!1;(!re||!le)&&(re=H.createTab(W),I.current[O]=re),y(W,re,`Action: ${ne.name}`),w(W,re),f(!0),h("terminal");const ue=fo.getState().getDirectoryState(W)?.tabs.find(be=>be.id===re);return{key:O,tabId:re,sessionId:ue?.terminalSessionId??null}},[v,W,h,w,f,y]),J=d.useCallback(async ne=>{if(l.isVSCode||!o&&i)return;if(!W){fe.error("No active directory for action");return}const O=Ea(W,ne.id),H=B[O];if(!(H&&H.status==="running"))try{const{key:K,tabId:re,sessionId:le}=await Y(ne);let ae=le,ue=!1;if(!ae){C(W,re,!0);try{ae=(await a.createSession({cwd:W})).sessionId,ue=!0,N(W,re,ae)}finally{C(W,re,!1)}}if(!ae)throw new Error("Failed to create terminal session");ue&&await oj(350),E(me=>({...me,[K]:{key:K,directory:W,actionId:ne.id,tabId:re,sessionId:ae,status:"running"}}));const be=ne.autoOpenUrl===!0&&(ne.openUrl||"").trim().length>0,oe=ne.autoOpenUrl===!0&&c&&(ne.desktopOpenSshForward||"").trim().length>0,Z=ne.autoOpenUrl?dj(ne.openUrl):null,ie=ne.autoOpenUrl&&c?rj(ne.desktopOpenSshForward,u):null;ie?(z(ie),fe.success("Opened forwarded URL")):Z?(z(Z),fe.success("Opened action URL")):be?fe.error("Invalid custom URL format"):oe&&fe.error("Selected desktop SSH forward is unavailable"),P.current[K]={lastSeenChunkId:null,openedUrl:!!ie||!!Z||be,tail:""};const pe=cj(ne.command.trim().replace(/\r\n|\r/g,`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-HTKwyaEM.js","assets/vendor--DbVqbJpV.css","assets/ToolOutputDialog-vSVMQalx.js","assets/index-Bdws7PjD.js","assets/index-CtCEGYrr.css","assets/TimelineDialog-DCaQs6K1.js","assets/TerminalView-DYFvA1o0.js","assets/SettingsWindow-DCnW8z6c.js","assets/MultiRunWindow-t-TdKGA_.js"])))=>i.map(i=>d[i]);
2
+ import{e as Fe,u as s,v as pg,w as gg,P as xg,C as bg,x as vg,y as yg,L as wg,z as jg,S as kg,B as Ng,D as Sg,G as Cg,I as Ag,J as Mg,O as Fg,Q as Bg,U as _g,V as Eg,W as Dg,Y as js,Z as On,R as d,$ as N1,a0 as xl,a1 as E2,a2 as D2,a3 as S1,a4 as Ps,a5 as X0,a6 as Ig,a7 as Q0,a8 as C1,a9 as A1,a as Dr,d as wa,p as Pl,b as Ii,aa as To,ab as Sh,ac as Tg,ad as he,ae as Pg,af as Ch,ag as Qn,ah as Rg,ai as zg,aj as Lg,ak as Ah,al as Hg,am as $g,an as Og,ao as Vg,ap as Ug,aq as Wg,ar as Mh,as as qg,at as Gg,au as Zg,av as $i,k as Cl,aw as xa,ax as Qr,ay as Fh,az as Pn,aA as ts,aB as xu,aC as Yo,aD as bl,aE as I0,aF as Qs,aG as Bh,aH as Kg,aI as Yg,aJ as Ds,aK as nr,aL as Va,aM as Xg,aN as hi,K as Po,aO as V1,aP as Qg,N as Jg,M as e9,aQ as Al,aR as on,aS as xr,aT as oa,aU as ya,aV as zo,aW as Rl,aX as M1,aY as Xo,_ as Kn,aZ as I2,a_ as Pa,a$ as wd,b0 as vl,b1 as yl,b2 as ji,b3 as J0,b4 as t9,b5 as F1,b6 as e2,b7 as T2,b8 as ba,b9 as Er,ba as bu,bb as vu,bc as _h,bd as Eh,be as s9,bf as n9,bg as c1,bh as Qo,bi as Bo,bj as t2,bk as Ml,bl as Fl,bm as r9,bn as $r,bo as o9,bp as a9,bq as bo,br as l9,bs as P2,bt as fa,bu as i9,bv as _o,bw as B1,bx as Bl,by as c9,bz as d9,bA as Dh,bB as qa,bC as R2,bD as u9,bE as f9,bF as ml,bG as Ih,bH as Th,bI as T0,bJ as jd,bK as m9,bL as ki,bM as Ni,bN as wo,bO as h9,bP as p9,bQ as g9,bR as x9,bS as b9,bT as v9,bU as y9,bV as w9,bW as j9,bX as k9,bY as N9,bZ as S9,b_ as C9,b$ as wr,c0 as Jo,c1 as ea,c2 as jr,c3 as A9,c4 as M9,c5 as kd,c6 as Ph,c7 as yu,c8 as wu,c9 as Rh,ca as ju,cb as U1,cc as zh,cd as z2,ce as Ga,cf as Za,cg as Go,ch as Lh,ci as F9,cj as B9,ck as _9,cl as Hh,cm as $h,cn as Oh,co as Vh,cp as Uh,cq as E9,cr as D9,cs as I9,ct as T9,cu as P9,cv as Wh,cw as oo,cx as v3,cy as R9,cz as z9,cA as ku,cB as ta,cC as L9,cD as H9,cE as y3,cF as w3,cG as $9,cH as O9,cI as V9,cJ as U9,cK as W9,cL as q9,cM as Co,cN as G9,cO as Lo,cP as Z9,cQ as K9,cR as qh,cS as Y9,cT as X9,cU as Ka,cV as Q9,cW as J9,cX as Gh,cY as ex,cZ as tx,i as s2,c_ as Zh,c$ as sx,d0 as Kh,d1 as nx,d2 as rx,d3 as ox,d4 as ax,d5 as Yh,d6 as wl,d7 as Nu,d8 as lx,d9 as ix,da as cx,db as dx,dc as j3,dd as k3,de as N3,df as Xh,dg as ux,dh as fx,di as mx,dj as hx,dk as px,dl as gx,dm as S3,dn as Su,dp as xx,dq as bx,dr as go,ds as vx,dt as Ti,du as C3,dv as yx,dw as wx,dx as ac,dy as jx,dz as kx,dA as Nx,dB as A3,dC as M3,dD as Sx,dE as Qh,dF as Jh,dG as Cx,dH as F3,dI as Ax,dJ as Mx,dK as Fx,dL as Bx,dM as Cu,dN as Au,dO as _x,dP as Nd,dQ as dt,dR as n1,dS as Ex,dT as Dx,dU as zl,dV as Ix,dW as Tx,dX as Px,dY as Rx,dZ as zx,d_ as Lx,d$ as Hx,e0 as $x,e1 as n2,e2 as e6,e3 as t6,e4 as s6,e5 as n6,e6 as r6,e7 as o6,e8 as a6,e9 as Ox,ea as l6,eb as i6,ec as ai,ed as c6,ee as d6,ef as W1,eg as u6,eh as Ll,ei as f6,ej as Sd,ek as Vx,q as m6,el as Mu,g as Fu,A as Bu,em as Ux,en as Wx,eo as d1,ep as L2,eq as qx,er as jl,es as Gx,et as Fn,eu as Zx,ev as Kx,ew as Yx,ex as Xx,ey as Qx,ez as h6,eA as Jx,eB as eb,eC as tb,eD as H2,eE as Pi,eF as sb,eG as nb,eH as rb,eI as p6,eJ as g6,eK as x6,eL as b6,eM as ob,eN as ab,eO as r2,eP as v6,o as _u,eQ as Cd,eR as lb,eS as ib,eT as P0,eU as B3,eV as cb,eW as db,eX as ub,eY as fb,eZ as mb,e_ as R0,e$ as y6,f0 as w6,f1 as Ad,f2 as hb,f3 as pb,f4 as gb,f5 as j6,f6 as xb,f7 as bb,f8 as vb,f9 as yb,fa as wb,j as k6,fb as jb,fc as kb,fd as Nb,fe as Sb,ff as Cb,fg as Ab,fh as Mb,fi as Fb,fj as Md,fk as Bb,fl as _3,fm as E3,fn as _b,fo as Eb,fp as Db,fq as Ib,fr as Tb,fs as Pb,ft as z0,E as D3,fu as Rb,fv as lc,fw as I3,fx as zb,fy as Lb,m as Hb,fz as $b,fA as Ob,fB as Vb}from"./vendor-.bun-HTKwyaEM.js";import{c as Q,u as Ee,a as ln,i as xn,g as Ho,b as Ko,d as _n,e as Eu,f as dn,h as Yr,j as Ub,k as _1,l as Rn,m as $o,n as T3,o as N6,p as L0,q as Wb,r as qb,s as S6,t as rs,v as Ze,w as vs,x as Du,y as Eo,z as u1,A as Iu,B as q1,C as $2,D as P3,E as O2,F as ma,G as hl,H as sr,I as R3,P as ja,J as ka,K as C6,L as A6,M as Or,N as Tu,O as Hl,Q as $l,R as Gb,S as Zb,T as M6,U as Ri,V as Kb,W as Yb,X as zi,Y as Xb,Z as Qb,_ as F6,$ as _l,a0 as En,a1 as o2,a2 as Fd,a3 as Jb,a4 as G1,a5 as ev,a6 as Bd,a7 as tv,a8 as sv,a9 as nv,aa as rv,ab as ov,ac as z3,ad as B6,ae as av,af as lv,ag as iv,ah as cv,ai as dv,aj as uv,ak as Nn,al as fv,am as mv,an as hv,ao as pv,ap as a2,aq as ic,ar as cc,as as dc,at as V2,au as gv,av as li,aw as pi,ax as U2,ay as E1,az as _6,aA as va,aB as xv,aC as f1,aD as uc,aE as Na,aF as H0,aG as bv,aH as fc,aI as vv,aJ as Pu,aK as E6,aL as yv,aM as wv,aN as t0,aO as L3,aP as uo,aQ as jv,aR as kv,aS as Nv,aT as D6,aU as Sv,aV as H3,aW as Cv,aX as Av,aY as Mv,aZ as $3,a_ as Fv,a$ as Bv,b0 as I6,b1 as T6,b2 as _v,b3 as P6}from"./index-Bdws7PjD.js";function ii(t){const e=Fe.c(6);let n,r;e[0]!==t?({delayDuration:r,...n}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);const o=r===void 0?0:r;let a;return e[3]!==o||e[4]!==n?(a=s.jsx(vg,{"data-slot":"tooltip-provider",delayDuration:o,...n}),e[3]=o,e[4]=n,e[5]=a):a=e[5],a}function Dt(t){const e=Fe.c(6);let n,r;e[0]!==t?({delayDuration:r,...n}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);const o=r===void 0?0:r;let a;return e[3]!==o||e[4]!==n?(a=s.jsx(pg,{"data-slot":"tooltip",delayDuration:o,...n}),e[3]=o,e[4]=n,e[5]=a):a=e[5],a}function It(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(gg,{"data-slot":"tooltip-trigger",...n}),e[2]=n,e[3]=r):r=e[3],r}function _t(t){const e=Fe.c(17);let n,r,o,a,l;e[0]!==t?({className:r,sideOffset:l,children:n,style:a,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a,e[5]=l):(n=e[1],r=e[2],o=e[3],a=e[4],l=e[5]);const i=l===void 0?0:l;let c;e[6]!==r?(c=Q("bg-muted text-muted-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-xl px-3 py-1.5 typography-meta text-balance overflow-hidden transform-gpu will-change-transform",r),e[6]=r,e[7]=c):c=e[7];let u;e[8]!==a?(u={backdropFilter:"blur(28px)",WebkitBackdropFilter:"blur(28px)",...a},e[8]=a,e[9]=u):u=e[9];let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(yg,{className:"fill-muted z-50 size-2"}),e[10]=m):m=e[10];let f;return e[11]!==n||e[12]!==o||e[13]!==i||e[14]!==c||e[15]!==u?(f=s.jsx(xg,{children:s.jsxs(bg,{"data-slot":"tooltip-content",sideOffset:i,className:c,style:u,...o,children:[n,m]})}),e[11]=n,e[12]=o,e[13]=i,e[14]=c,e[15]=u,e[16]=f):f=e[16],f}function qs(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Sg,{"data-slot":"dropdown-menu",...n}),e[2]=n,e[3]=r):r=e[3],r}function Gs(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Cg,{"data-slot":"dropdown-menu-trigger",...n}),e[2]=n,e[3]=r):r=e[3],r}function Ys(t){const e=Fe.c(14);let n,r,o,a;e[0]!==t?({className:n,sideOffset:a,style:o,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a):(n=e[1],r=e[2],o=e[3],a=e[4]);const l=a===void 0?4:a;let i;e[5]!==o?(i={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)",backdropFilter:"blur(28px)",WebkitBackdropFilter:"blur(28px)",...o},e[5]=o,e[6]=i):i=e[6];let c;e[7]!==n?(c=Q("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-visible rounded-xl border-2 border-border/60 p-1 shadow-none",n),e[7]=n,e[8]=c):c=e[8];let u;return e[9]!==r||e[10]!==l||e[11]!==i||e[12]!==c?(u=s.jsx(Ag,{children:s.jsx(Mg,{"data-slot":"dropdown-menu-content",sideOffset:l,style:i,className:c,...r})}),e[9]=r,e[10]=l,e[11]=i,e[12]=c,e[13]=u):u=e[13],u}function Jt(t){const e=Fe.c(12);let n,r,o,a;e[0]!==t?({className:n,inset:r,variant:a,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a):(n=e[1],r=e[2],o=e[3],a=e[4]);const l=a===void 0?"default":a;let i;e[5]!==n?(i=Q("data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover data-[variant=destructive]:text-destructive data-[variant=destructive]:hover:bg-destructive/10 dark:data-[variant=destructive]:hover:bg-destructive/20 data-[variant=destructive]:hover:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 typography-ui-label outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",n),e[5]=n,e[6]=i):i=e[6];let c;return e[7]!==r||e[8]!==o||e[9]!==i||e[10]!==l?(c=s.jsx(Fg,{"data-slot":"dropdown-menu-item","data-inset":r,"data-variant":l,className:i,...o}),e[7]=r,e[8]=o,e[9]=i,e[10]=l,e[11]=c):c=e[11],c}function l2(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(jg,{"data-slot":"dropdown-menu-radio-group",...n}),e[2]=n,e[3]=r):r=e[3],r}function W2(t){const e=Fe.c(11);let n,r,o;e[0]!==t?({className:r,children:n,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o):(n=e[1],r=e[2],o=e[3]);let a;e[4]!==r?(a=Q("data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover data-[state=checked]:bg-interactive-selection data-[state=checked]:text-interactive-selection-foreground relative flex cursor-pointer items-start gap-2 rounded-lg py-1 pl-2 pr-8 typography-ui-label outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",r),e[4]=r,e[5]=a):a=e[5];let l;e[6]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"pointer-events-none absolute right-2 flex size-3.5 items-center justify-center text-primary",children:s.jsx(Dg,{children:s.jsx(js,{className:"size-3"})})}),e[6]=l):l=e[6];let i;return e[7]!==n||e[8]!==o||e[9]!==a?(i=s.jsxs(Ng,{"data-slot":"dropdown-menu-radio-item",className:a,...o,children:[l,n]}),e[7]=n,e[8]=o,e[9]=a,e[10]=i):i=e[10],i}function sa(t){const e=Fe.c(10);let n,r,o;e[0]!==t?({className:n,inset:r,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o):(n=e[1],r=e[2],o=e[3]);let a;e[4]!==n?(a=Q("px-2 py-1 typography-ui-label font-medium data-[inset]:pl-8",n),e[4]=n,e[5]=a):a=e[5];let l;return e[6]!==r||e[7]!==o||e[8]!==a?(l=s.jsx(wg,{"data-slot":"dropdown-menu-label","data-inset":r,className:a,...o}),e[6]=r,e[7]=o,e[8]=a,e[9]=l):l=e[9],l}function Zn(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("bg-border -mx-1 my-0.5 h-px",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(kg,{"data-slot":"dropdown-menu-separator",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function Ev(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Bg,{"data-slot":"dropdown-menu-sub",...n}),e[2]=n,e[3]=r):r=e[3],r}function Dv(t){const e=Fe.c(13);let n,r,o,a;e[0]!==t?({className:r,inset:o,children:n,...a}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a):(n=e[1],r=e[2],o=e[3],a=e[4]);let l;e[5]!==r?(l=Q("data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 typography-ui-label outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",r),e[5]=r,e[6]=l):l=e[6];let i;e[7]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(On,{className:"ml-auto size-3.5"}),e[7]=i):i=e[7];let c;return e[8]!==n||e[9]!==o||e[10]!==a||e[11]!==l?(c=s.jsxs(_g,{"data-slot":"dropdown-menu-sub-trigger","data-inset":o,className:l,...a,children:[n,i]}),e[8]=n,e[9]=o,e[10]=a,e[11]=l,e[12]=c):c=e[12],c}function Iv(t){const e=Fe.c(9);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]===Symbol.for("react.memo_cache_sentinel")?(o={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)",backdropFilter:"blur(28px)",WebkitBackdropFilter:"blur(28px)"},e[3]=o):o=e[3];let a;e[4]!==n?(a=Q("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-visible rounded-xl border-2 border-border/60 p-1 shadow-none",n),e[4]=n,e[5]=a):a=e[5];let l;return e[6]!==r||e[7]!==a?(l=s.jsx(Eg,{"data-slot":"dropdown-menu-sub-content",style:o,className:a,...r}),e[6]=r,e[7]=a,e[8]=l):l=e[8],l}const Tv=({transform:t})=>({...t,y:0}),Pv=t=>{const e=Fe.c(18),{id:n,children:r,className:o}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:l,listeners:i,setNodeRef:c,transform:u,transition:m,isDragging:f}=E2(a);let h;e[2]!==u?(h=D2.Transform.toString(u),e[2]=u,e[3]=h):h=e[3];let p;e[4]!==h||e[5]!==m?(p={transform:h,transition:m},e[4]=h,e[5]=m,e[6]=p):p=e[6];const g=f&&"opacity-50";let x;e[7]!==o||e[8]!==g?(x=Q("h-full rounded-md",o,g),e[7]=o,e[8]=g,e[9]=x):x=e[9];let b;return e[10]!==l||e[11]!==r||e[12]!==n||e[13]!==i||e[14]!==c||e[15]!==p||e[16]!==x?(b=s.jsx("div",{ref:c,"data-sortable-tab-id":n,style:p,className:x,...l,...i,children:r}),e[10]=l,e[11]=r,e[12]=n,e[13]=i,e[14]=c,e[15]=p,e[16]=x,e[17]=b):b=e[17],b},Rv=t=>{const e=Fe.c(6),{id:n,children:r,className:o}=t;let a;e[0]!==o?(a=Q("h-full",o),e[0]=o,e[1]=a):a=e[1];let l;return e[2]!==r||e[3]!==n||e[4]!==a?(l=s.jsx("div",{className:a,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=a,e[5]=l):l=e[5],l},Ro=t=>{const e=Fe.c(109),{items:n,activeId:r,onSelect:o,onClose:a,onReorder:l,layoutMode:i,variant:c,activePillInsetClassName:u,activePillButtonClassName:m,inactiveTabsIconOnly:f,animateActivePill:h,activePillLowercase:p,className:g}=t,x=i===void 0?"scrollable":i,b=c===void 0?"default":c,v=f===void 0?!1:f,y=p===void 0?!0:p,w=Ee(zv),C=d.useRef(null);let N;e[0]===Symbol.for("react.memo_cache_sentinel")?(N={left:!1,right:!1},e[0]=N):N=e[0];const[S,k]=d.useState(N);let j;e[1]!==n?(j=n.map(Lv),e[1]=n,e[2]=j):j=e[2];const F=j,A=x==="scrollable",M=b==="active-pill",B=b==="animated",E=M||B,I=M&&A,P=B,D=h??B,L=typeof l=="function",T=L?Pv:Rv;let _;e[3]===Symbol.for("react.memo_cache_sentinel")?(_=new Map,e[3]=_):_=e[3];const z=d.useRef(_),[R,W]=d.useState(null);let G;e[4]===Symbol.for("react.memo_cache_sentinel")?(G={activationConstraint:{distance:8}},e[4]=G):G=e[4];const Y=N1(xl(S1,G)),J=Hv;let V;e[5]===Symbol.for("react.memo_cache_sentinel")?(V=(Ge,Le)=>{if(Le){z.current.set(Ge,Le);return}z.current.delete(Ge)},e[5]=V):V=e[5];const te=V;let U;e[6]!==r||e[7]!==E?(U=()=>{if(!E||!r){W($v);return}const Ge=C.current,Le=z.current.get(r);if(!Ge||!Le){W(Ov);return}let qe=0,rt=0,st=Le;for(;st&&st!==Ge;)qe=qe+st.offsetLeft,rt=rt+st.offsetTop,st=st.offsetParent;const it={left:qe,top:rt,width:Le.offsetWidth,height:Le.offsetHeight};W(lt=>J(lt,it)?lt:it)},e[6]=r,e[7]=E,e[8]=U):U=e[8];const X=U;let $;e[9]!==A?($=()=>{if(!A){k({left:!1,right:!1});return}const Ge=C.current;if(!Ge){k({left:!1,right:!1});return}k({left:Ge.scrollLeft>2,right:Ge.scrollLeft+Ge.clientWidth<Ge.scrollWidth-2})},e[9]=A,e[10]=$):$=e[10];const q=$;let ee;e[11]!==A||e[12]!==q?(ee=()=>{if(!A){k({left:!1,right:!1});return}const Ge=C.current;if(!Ge)return;q(),Ge.addEventListener("scroll",q,{passive:!0});const Le=new ResizeObserver(q);return Le.observe(Ge),()=>{Ge.removeEventListener("scroll",q),Le.disconnect()}},e[11]=A,e[12]=q,e[13]=ee):ee=e[13];let ce;e[14]!==A||e[15]!==n.length||e[16]!==q?(ce=[A,n.length,q],e[14]=A,e[15]=n.length,e[16]=q,e[17]=ce):ce=e[17],d.useEffect(ee,ce);let ve;e[18]!==r||e[19]!==X||e[20]!==E?(ve=()=>{if(!E){W(null);return}X();const Ge=C.current;if(!Ge)return;const Le=new ResizeObserver(X);if(Le.observe(Ge),r){const qe=z.current.get(r);qe&&Le.observe(qe)}return()=>{Le.disconnect()}},e[18]=r,e[19]=X,e[20]=E,e[21]=ve):ve=e[21];let ge;e[22]!==r||e[23]!==n.length||e[24]!==X||e[25]!==E?(ge=[r,n.length,X,E],e[22]=r,e[23]=n.length,e[24]=X,e[25]=E,e[26]=ge):ge=e[26],d.useEffect(ve,ge);let xe;e[27]!==X?(xe=()=>{X()},e[27]=X,e[28]=xe):xe=e[28],d.useLayoutEffect(xe);let ne;e[29]!==r||e[30]!==A||e[31]!==q?(ne=()=>{if(!A||!r)return;const Ge=C.current;if(!Ge)return;const Le=window.requestAnimationFrame(()=>{const qe=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),rt=Ge.querySelector(`[data-sortable-tab-id="${qe}"]`);rt&&(rt.scrollIntoView({block:"nearest",inline:"nearest"}),q())});return()=>{window.cancelAnimationFrame(Le)}},e[29]=r,e[30]=A,e[31]=q,e[32]=ne):ne=e[32];let O;e[33]!==r||e[34]!==A||e[35]!==n.length||e[36]!==q?(O=[r,A,n.length,q],e[33]=r,e[34]=A,e[35]=n.length,e[36]=q,e[37]=O):O=e[37],d.useEffect(ne,O);let H;e[38]!==l?(H=Ge=>{if(!l)return;const{active:Le,over:qe}=Ge;!qe||Le.id===qe.id||l(String(Le.id),String(qe.id))},e[38]=l,e[39]=H):H=e[39];const K=H;let re;e[40]!==g?(re=Q("relative flex h-full min-w-0 flex-1",g),e[40]=g,e[41]=re):re=e[41];let le;e[42]!==A||e[43]!==S||e[44]!==E?(le=A&&S.left?s.jsx("div",{className:Q("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",E?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=A,e[43]=S,e[44]=E,e[45]=le):le=e[45];let ae;e[46]!==A||e[47]!==S||e[48]!==E?(ae=A&&S.right?s.jsx("div",{className:Q("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",E?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=A,e[47]=S,e[48]=E,e[49]=ae):ae=e[49];const ue=E?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",be=E&&"@container/pill-tabs",oe=E&&"pill-tabs__track",Z=E&&(u??"gap-0.5 py-0.5"),ie=P&&"rounded-lg bg-[var(--surface-muted)]/50",pe=A?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let me;e[50]!==ue||e[51]!==be||e[52]!==oe||e[53]!==Z||e[54]!==ie||e[55]!==pe?(me=Q("relative flex h-full min-w-0 flex-1",ue,be,oe,Z,ie,pe),e[50]=ue,e[51]=be,e[52]=oe,e[53]=Z,e[54]=ie,e[55]=pe,e[56]=me):me=e[56];let Se;e[57]!==A?(Se=A?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[57]=A,e[58]=Se):Se=e[58];let ke;e[59]!==R||e[60]!==D||e[61]!==E?(ke=E&&R?s.jsx("div",{className:Q("pointer-events-none absolute left-0 top-0 z-0 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",D&&"transition-[transform,width,height] duration-200 ease-out"),style:{transform:`translate(${R.left}px, ${R.top}px)`,width:`${R.width}px`,height:`${R.height}px`}}):null,e[59]=R,e[60]=D,e[61]=E,e[62]=ke):ke=e[62];let ye;if(e[63]!==T||e[64]!==r||e[65]!==m||e[66]!==y||e[67]!==v||e[68]!==M||e[69]!==w||e[70]!==A||e[71]!==n||e[72]!==a||e[73]!==o||e[74]!==I||e[75]!==E){let Ge;e[77]!==T||e[78]!==r||e[79]!==m||e[80]!==y||e[81]!==v||e[82]!==M||e[83]!==w||e[84]!==A||e[85]!==a||e[86]!==o||e[87]!==I||e[88]!==E?(Ge=Le=>{const qe=Le.id===r,rt=v&&E&&!qe&&!!Le.icon,st=!rt,it=v&&E&&qe&&!A&&!I,lt=Le.closable!==!1&&!!a,He=A||I?void 0:E?it?"flex-none basis-auto":w?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0";return s.jsx(T,{id:Le.id,className:He,children:s.jsxs("div",{ref:Oe=>te(Le.id,Oe),className:Q("group flex h-full items-center",A||I?"shrink-0":E?"w-full":"w-full min-w-0",E?"relative z-10 bg-transparent":qe?"border-r border-border/40 bg-[var(--surface-elevated)] text-foreground":"border-r border-border/40 bg-[var(--surface-elevated)]/25 text-muted-foreground hover:bg-[var(--surface-elevated)]/65 hover:text-foreground"),children:[s.jsx("button",{type:"button",role:"tab","aria-selected":qe,"aria-label":rt?Le.title??Le.label:void 0,onClick:()=>o(Le.id),className:Q(E?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 items-center justify-center rounded-lg text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 items-center typography-micro",E&&lt&&"!flex-none",E&&y?"lowercase":null,E&&(rt?"gap-0":"gap-1.5"),E?I?"shrink-0 whitespace-nowrap px-3 text-center":A?"max-w-56 shrink-0 px-3 text-center":rt?"px-2 !min-w-0 text-center":it?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":A?"max-w-56 justify-start truncate pl-3 pr-2 text-left":"w-full justify-center truncate px-2.5 text-center",E?m??(M?w?"h-[34px]":"h-[27px]":"h-7"):null,E?qe?"text-foreground":"text-muted-foreground hover:text-foreground":null,E?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:Le.title??Le.label,children:E?s.jsxs(s.Fragment,{children:[Le.icon?s.jsx("span",{className:"flex shrink-0 items-center justify-center",children:Le.icon}):null,st?s.jsx("span",{className:"animated-tabs__label truncate",children:Le.label}):null]}):s.jsxs("span",{className:Q("flex min-w-0 items-center gap-1.5",!A&&"justify-center"),children:[Le.icon?s.jsx("span",{className:"flex shrink-0 items-center justify-center",children:Le.icon}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:Le.label})]})}),lt?s.jsx("button",{type:"button",onPointerDown:Vv,onClick:Oe=>{Oe.stopPropagation(),a?.(Le.id)},className:Q("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",E?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",E?qe?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":qe?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":Le.closeLabel??`Close ${Le.label} tab`,title:Le.closeLabel??`Close ${Le.label} tab`,children:s.jsx(Ps,{className:"h-3 w-3"})}):null]})},Le.id)},e[77]=T,e[78]=r,e[79]=m,e[80]=y,e[81]=v,e[82]=M,e[83]=w,e[84]=A,e[85]=a,e[86]=o,e[87]=I,e[88]=E,e[89]=Ge):Ge=e[89],ye=n.map(Ge),e[63]=T,e[64]=r,e[65]=m,e[66]=y,e[67]=v,e[68]=M,e[69]=w,e[70]=A,e[71]=n,e[72]=a,e[73]=o,e[74]=I,e[75]=E,e[76]=ye}else ye=e[76];let Ne;e[90]!==me||e[91]!==Se||e[92]!==ke||e[93]!==ye?(Ne=s.jsxs("div",{ref:C,className:me,style:Se,role:"tablist","aria-label":"Tabs",children:[ke,ye]}),e[90]=me,e[91]=Se,e[92]=ke,e[93]=ye,e[94]=Ne):Ne=e[94];let _e;e[95]!==re||e[96]!==le||e[97]!==ae||e[98]!==Ne?(_e=s.jsxs("div",{className:re,children:[le,ae,Ne]}),e[95]=re,e[96]=le,e[97]=ae,e[98]=Ne,e[99]=_e):_e=e[99];const de=_e;if(!L)return de;let we;e[100]===Symbol.for("react.memo_cache_sentinel")?(we=[Tv],e[100]=we):we=e[100];let je;e[101]!==F||e[102]!==de?(je=s.jsx(X0,{items:F,strategy:Ig,children:de}),e[101]=F,e[102]=de,e[103]=je):je=e[103];let Ce;e[104]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(Q0,{dropAnimation:null}),e[104]=Ce):Ce=e[104];let ze;return e[105]!==K||e[106]!==Y||e[107]!==je?(ze=s.jsxs(C1,{sensors:Y,collisionDetection:A1,onDragEnd:K,modifiers:we,children:[je,Ce]}),e[105]=K,e[106]=Y,e[107]=je,e[108]=ze):ze=e[108],ze};function zv(t){return t.isMobile}function Lv(t){return t.id}function Hv(t,e){return!t||!e?t===e:Math.abs(t.left-e.left)<.5&&Math.abs(t.top-e.top)<.5&&Math.abs(t.width-e.width)<.5&&Math.abs(t.height-e.height)<.5}function $v(t){return t===null?t:null}function Ov(t){return t===null?t:null}function Vv(t){t.stopPropagation()}function O3(t){const e=Fe.c(14);let n,r,o,a;e[0]!==t?({size:o,className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a):(n=e[1],r=e[2],o=e[3],a=e[4]);const l=typeof o=="number"?`${o}px`:o,i=typeof o=="number"?`${o}px`:o;let c;e[5]!==a||e[6]!==l||e[7]!==i?(c={width:l,height:i,...a},e[5]=a,e[6]=l,e[7]=i,e[8]=c):c=e[8];let u;e[9]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=u):u=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==c?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:c,...r,children:u}),e[10]=n,e[11]=r,e[12]=c,e[13]=m):m=e[13],m}const Oo=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"}];Oo.reduce((t,e)=>(t[e.id]=e,t),{});const R6=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),Ao=t=>{const e=R6(t);return e===null?"-":`${e}%`},z6=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",i2=t=>t==="5h"?"5-Hour":t==="7d"?"7-Day Limit":t==="7d-sonnet"?"7-Day Sonnet Limit":t==="7d-opus"?"7-Day Opus Limit":t==="weekly"?"Weekly Limit":t==="daily"?"Daily":t==="monthly"?"Monthly Limit":t==="credits"?"Credits":t==="session"?"Session":t==="premium"?"Premium Interactions":t==="chat"?"Chat Requests":t==="completions"?"Completions":t==="premium_interactions"?"Premium interactions":t,Uv=t=>{const e=t.toLowerCase().trim();if(e==="5h")return 5*3600;if(e==="7d"||e==="weekly"||e==="7d-sonnet"||e==="7d-opus")return 7*86400;if(e==="monthly")return 30*86400;if(e==="24h"||e==="daily")return 86400;if(e==="1h")return 3600;const n=e.match(/^(\d+)h$/);if(n)return parseInt(n[1],10)*3600;const r=e.match(/^(\d+)d$/);return r?parseInt(r[1],10)*86400:null},ci=(t,e,n,r)=>{let o=n;if(o===null&&r&&(o=Uv(r)),t===null||e===null||o===null||o<=0)return null;const a=Date.now(),l=Math.max(0,(e-a)/1e3),i=Math.max(0,Math.min(o,o-l)),c=Math.max(0,Math.min(1,i/o)),u=t/100,m=t>=100&&l>0;let f;c>.01?f=Math.min(999,u/c*100):f=t;let h;m?h="exhausted":u<=c?h="on-track":f<=130?h="slightly-fast":h="too-fast";const p=o>=120*3600,g=p?86400:3600,x=p?"d":"h",b=o/g,v=Math.max(i/g,b*.01),y=t/v,w=Number.isFinite(y)?`${Math.min(999.9,Math.max(0,y)).toFixed(1)}%/${x}`:"-",C=f>100?`+${Math.round(f)}%`:`${Math.round(f)}%`;let N=null;const S=o/86400;return S>=7&&(N=100/S),{elapsedRatio:c,usageRatio:u,predictedFinalPercent:f,remainingSeconds:l,isExhausted:m,elapsedSeconds:i,totalSeconds:o,status:h,paceRateText:w,predictText:C,dailyAllocationPercent:N}},Wv=t=>{switch(t){case"exhausted":case"too-fast":return"var(--status-error)";case"slightly-fast":return"var(--status-warning)";case"on-track":return"var(--status-success)"}},V3=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),o=Math.floor(r/24),a=r%24,l=n%60;return o>0?`${o}d ${a}h`:r>0?`${r}h`:n===0?"<1m":`${l}m`},Mo=t=>Math.min(100,Math.max(0,t*100));function c2(t){const e=t.indexOf("/");if(e!==-1){const n=t.substring(0,e);if(n==="gemini"||n==="antigravity")return t.substring(e+1)}return t}const qv=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],L6={google:qv};function H6(t,e){const n=L6[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function $6(t){return L6[t]??[]}function O6(t){return[...t].sort((e,n)=>e.order-n.order)}function Gv(t,e){const n=new Map;for(const r of Object.keys(t)){const a=H6(r,e)?.id??null;n.has(a)||n.set(a,[]),n.get(a).push(r)}return n}function Zv(t,e,n){const r=new Map;for(const o of t){const a=e(o),i=H6(a,n)?.id??null;r.has(i)||r.set(i,[]),r.get(i).push(o)}return r}function Kv(t,e){return e.filter(n=>{const r=n.toLowerCase(),o=r.includes("/")?r.split("/")[1]:r;return!!(o.startsWith("gemini-3-")||o.startsWith("claude-"))})}const Ru=6e4,U3=t=>{const e=Oo.map(f=>f.id),n=typeof t?.usageAutoRefresh=="boolean"?t.usageAutoRefresh:!1,r=typeof t?.usageRefreshIntervalMs=="number"&&Number.isFinite(t.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(t.usageRefreshIntervalMs))):Ru,o=t?.usageDisplayMode==="remaining"?"remaining":"usage",a=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,l=a?a.filter(f=>typeof f=="string"&&e.includes(f)):e,i={},c=t?.usageSelectedModels;if(c&&typeof c=="object")for(const[f,h]of Object.entries(c))Array.isArray(h)&&(i[f]=h.filter(p=>typeof p=="string"));const u={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[f,h]of Object.entries(m))Array.isArray(h)&&(u[f]=h.filter(p=>typeof p=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:o,dropdownProviderIds:l,selectedModels:i,expandedFamilies:u}},Yv=async()=>{const t=Ho()?.settings;if(t)try{const n=(await t.load())?.settings;return U3(n??null)}catch{}if(!xn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return U3(n)}}return{autoRefresh:!1,refreshIntervalMs:Ru,displayMode:"usage",dropdownProviderIds:Oo.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ws=Dr()(wa((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Ru,displayMode:"usage",dropdownProviderIds:Oo.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Yv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Oo.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const o=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:o})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),o=await r.json().catch(()=>null);if(!r.ok)throw new Error(o?.error||"Failed to fetch quota");const a=o;t(l=>{const i=l.results.filter(c=>c.providerId!==n);return i.push(a),{results:i,error:null}})}catch(r){const o=r instanceof Error?r.message:"Failed to fetch quota",a={providerId:n,providerName:n,ok:!1,configured:!1,error:o,usage:null,fetchedAt:Date.now()};t(l=>{const i=l.results.filter(c=>c.providerId!==n);return i.push(a),{results:i,error:o}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(o=>({selectedModels:{...o.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(o=>{const a=o.selectedModels[n]??[],i=a.includes(r)?a.filter(c=>c!==r):[...a,r];return{selectedModels:{...o.selectedModels,[n]:i}}})},setExpandedFamilies:(n,r)=>{t(o=>({expandedFamilies:{...o.expandedFamilies,[n]:r}})),ln({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{t(o=>{const a=o.expandedFamilies[n]??[],i=a.includes(r)?a.filter(c=>c!==r):[...a,r];return{expandedFamilies:{...o.expandedFamilies,[n]:i}}}),ln({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const a=Kv(n,r);a.length!==0&&(t(l=>({selectedModels:{...l.selectedModels,[n]:a}})),ln({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),zu=()=>{const t=Fe.c(5),e=Ws(Xv),n=Ws(Qv),r=Ws(Jv);let o,a;t[0]!==e||t[1]!==r||t[2]!==n?(o=()=>{if(!e)return;const l=window.setInterval(()=>{r()},n);return()=>window.clearInterval(l)},a=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=o,t[4]=a):(o=t[3],a=t[4]),d.useEffect(o,a)};function Xv(t){return t.autoRefresh}function Qv(t){return t.refreshIntervalMs}function Jv(t){return t.fetchAllQuotas}const lr=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==="/",a=/^[A-Za-z]:\/$/.test(r);return!o&&!a&&(r=r.replace(/\/+$/,"")),r},W3=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,mc=(t,e)=>{const n=lr(e),r=lr(t);if(!n||!r)return!1;const o=W3(n),a=W3(r);return a===o||a.startsWith(`${o}/`)},ey=t=>{if(!t||typeof t!="object")return{};const e=t,n={};for(const[r,o]of Object.entries(e)){const a=lr(r);if(!a||!o||typeof o!="object")continue;const l=o,i=Array.isArray(l.openPaths)?Array.from(new Set(l.openPaths.filter(p=>typeof p=="string").map(p=>lr(p)).filter(p=>mc(p,a)))):[],c=Array.isArray(l.expandedPaths)?Array.from(new Set(l.expandedPaths.filter(p=>typeof p=="string").map(p=>lr(p)).filter(p=>mc(p,a)))):[],u=typeof l.selectedPath=="string"?lr(l.selectedPath):null,m=u&&mc(u,a)?u:i[0]??null,f=typeof l.touchedAt=="number"&&Number.isFinite(l.touchedAt)?l.touchedAt:Date.now(),h=n[a];if(h){const p=Array.from(new Set([...h.openPaths,...i])),g=Array.from(new Set([...h.expandedPaths,...c])),x=h.selectedPath??m??p[0]??null;n[a]={openPaths:p,selectedPath:x,expandedPaths:g,touchedAt:Math.max(h.touchedAt,f)};continue}n[a]={openPaths:i,selectedPath:m,expandedPaths:c,touchedAt:f}}return n},nl=(t,e)=>{const n=Object.entries(t);if(n.length<=e)return t;n.sort((o,a)=>(a[1]?.touchedAt??0)-(o[1]?.touchedAt??0));const r={};for(const[o,a]of n.slice(0,e))r[o]=a;return r},Oi=t=>t?{...t,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},vr=Dr()(wa(Pl((t,e)=>({byRoot:{},addOpenPath:(n,r)=>{const o=lr((n||"").trim()),a=lr((r||"").trim());!o||!a||t(l=>{const i=l.byRoot[o],c=Oi(i),u=c.openPaths.includes(a),m=u?c.openPaths:[...c.openPaths,a],f=c.selectedPath??a;if(i&&u&&i.selectedPath===f)return l;const h={...l.byRoot,[o]:{...c,openPaths:m,selectedPath:f}};return{byRoot:nl(h,20)}})},removeOpenPath:(n,r)=>{const o=lr((n||"").trim()),a=lr((r||"").trim());!o||!a||t(l=>{const i=l.byRoot[o];if(!i||!i.openPaths.includes(a)&&i.selectedPath!==a)return l;const c=i.openPaths.filter(f=>f!==a),u=i.selectedPath===a?c[0]??null:i.selectedPath,m={...l.byRoot,[o]:{...i,openPaths:c,selectedPath:u,touchedAt:Date.now()}};return{byRoot:nl(m,20)}})},removeOpenPathsByPrefix:(n,r)=>{const o=lr((n||"").trim()),a=lr((r||"").trim());!o||!a||t(l=>{const i=l.byRoot[o];if(!i)return l;const c=a.endsWith("/")?a:`${a}/`,u=i.openPaths.filter(h=>h!==a&&!h.startsWith(c));if(u.length===i.openPaths.length)return l;const m=i.selectedPath&&(i.selectedPath===a||i.selectedPath.startsWith(c))?u[0]??null:i.selectedPath,f={...l.byRoot,[o]:{...i,openPaths:u,selectedPath:m,touchedAt:Date.now()}};return{byRoot:nl(f,20)}})},setSelectedPath:(n,r)=>{const o=lr((n||"").trim()),a=r?lr(r.trim()):null;o&&t(l=>{const i=l.byRoot[o],c=Oi(i),u=a&&!c.openPaths.includes(a)?[...c.openPaths,a]:c.openPaths;if(i&&i.selectedPath===a&&u===i.openPaths)return l;const m={...l.byRoot,[o]:{...c,openPaths:u,selectedPath:a}};return{byRoot:nl(m,20)}})},ensureSelectedPath:n=>{const r=lr((n||"").trim());if(!r)return;const o=e().byRoot[r];if(!o||o.selectedPath)return;const a=o.openPaths[0]??null;a&&e().setSelectedPath(r,a)},toggleExpandedPath:(n,r)=>{const o=lr((n||"").trim()),a=lr((r||"").trim());!o||!a||t(l=>{const i=l.byRoot[o],c=Oi(i),m=c.expandedPaths.includes(a)?c.expandedPaths.filter(h=>h!==a):[...c.expandedPaths,a];if(i&&i.expandedPaths===m&&i.selectedPath===c.selectedPath&&i.openPaths===c.openPaths)return l;const f={...l.byRoot,[o]:{...c,expandedPaths:m}};return{byRoot:nl(f,20)}})},expandPath:(n,r)=>{const o=lr((n||"").trim()),a=lr((r||"").trim());!o||!a||t(l=>{const i=l.byRoot[o],c=Oi(i);if(c.expandedPaths.includes(a)&&i)return l;const m={...l.byRoot,[o]:{...c,expandedPaths:[...c.expandedPaths,a]}};return{byRoot:nl(m,20)}})},expandPaths:(n,r)=>{const o=lr((n||"").trim());if(!o||!r||r.length===0)return;const a=r.map(l=>lr((l||"").trim())).filter(Boolean);t(l=>{const i=l.byRoot[o],c=Oi(i),u=new Set(c.expandedPaths),m=a.filter(h=>!u.has(h));if(m.length===0)return l;const f={...l.byRoot,[o]:{...c,expandedPaths:[...c.expandedPaths,...m]}};return{byRoot:nl(f,20)}})}}),{name:"files-view-tabs-store",version:2,storage:Ii(()=>Ko()),migrate:t=>{if(!t||typeof t!="object")return{byRoot:{}};const e=t.byRoot;return{byRoot:ey(e)}},partialize:t=>({byRoot:t.byRoot})}),{name:"files-view-tabs-store"})),_d=1e4,ty=3e4,sy=15e3,ny=4e4,ry=5e3,oy=1e4,ay=6e4,q3=25,ly=40,iy=4,G3=15e3,Z3=3,cy=30,dy=20*1024*1024,K3=new Map,V6=new Map,s0=new Map,$0=t=>V6.get(t)??0,n0=t=>{const e=$0(t)+1;return V6.set(t,e),e},uy=t=>{const e=K3.get(t);if(e)return e;const n=new Set;return K3.set(t,n),n},qo=()=>({isGitRepo:null,status:null,branches:null,log:null,identity:null,diffCache:new Map,lastRepoCheckAt:0,lastStatusFetch:0,lastStatusChange:0,lastLogFetch:0,logMaxCount:25}),Y3=(t,e=cy,n=dy)=>{let r=0;for(const i of t.values())r+=(i.original?.length??0)+(i.modified?.length??0);if(t.size<=e&&r<=n)return t;const o=Array.from(t.entries()).sort((i,c)=>i[1].fetchedAt-c[1].fetchedAt),a=new Map;let l=0;for(let i=o.length-1;i>=0;i--){const[c,u]=o[i],m=(u.original?.length??0)+(u.modified?.length??0);if(a.size>=e)break;l+m>n&&a.size>0||(a.set(c,u),l+=m)}return a},fy=(t,e)=>{if(!t&&!e)return!1;if(!t||!e)return!0;const n=new Set([...Object.keys(t),...Object.keys(e)]);for(const r of n){const o=t[r],a=e[r];if(!(!o&&!a)&&(!o||!a||o.insertions!==a.insertions||o.deletions!==a.deletions))return!0}return!1},my=(t,e)=>{if(!t&&!e)return!1;if(!t||!e)return!0;const n=t.files??[],r=e.files??[];if(n.length!==r.length||t.ahead!==e.ahead||t.behind!==e.behind||t.current!==e.current||t.tracking!==e.tracking||t.isClean!==e.isClean)return!0;const o=new Set(n.map(a=>`${a.path}:${a.index}:${a.working_dir}`));for(const a of r)if(!o.has(`${a.path}:${a.index}:${a.working_dir}`))return!0;return!!fy(t.diffStats,e.diffStats)},hy=(t,e)=>{const n=new Set;if(!e)return n;const r=t?.files??[],o=e.files??[],a=new Map(r.map(f=>[f.path,f])),l=new Map(o.map(f=>[f.path,f])),i=new Set([...a.keys(),...l.keys()]);for(const f of i){const h=a.get(f),p=l.get(f);if(!h||!p){n.add(f);continue}if(h.index!==p.index||h.working_dir!==p.working_dir){n.add(f);continue}}const c=t?.diffStats??{},u=e.diffStats??{},m=new Set([...Object.keys(c),...Object.keys(u)]);for(const f of m){const h=c[f],p=u[f];if(!h||!p){n.add(f);continue}(h.insertions!==p.insertions||h.deletions!==p.deletions)&&n.add(f)}return n},hc=t=>t==="busy"?{base:sy,max:ny}:{base:_d,max:ty},Wn=Dr()(wa((t,e)=>({directories:new Map,activeDirectory:null,recentDirectories:[],isLoadingStatus:!1,isLoadingLog:!1,isLoadingBranches:!1,isLoadingIdentity:!1,pollIntervalId:null,currentPollInterval:_d,pollingMode:"normal",setActiveDirectory:n=>{const{activeDirectory:r,directories:o,recentDirectories:a}=e();if(r===n)return;r&&n0(r),n&&n0(n);const l=n?[n,...a.filter(i=>i!==n)].slice(0,Z3):a;if(n&&!o.has(n)){const i=new Map(o);i.set(n,qo()),t({activeDirectory:n,recentDirectories:l,directories:i})}else t({activeDirectory:n,recentDirectories:l})},getDirectoryState:n=>e().directories.get(n)??null,fetchStatus:async(n,r,o={})=>{const a=s0.get(n);if(a)return a;const l=(async()=>{const{silent:i=!1}=o,{directories:c}=e();let u=c.get(n);u||(u=qo()),i||t({isLoadingStatus:!0});let m=!1;try{const f=Date.now(),h=u.isGitRepo!==!0||f-(u.lastRepoCheckAt||0)>ay;let p=u.isGitRepo===!0;if(h&&(p=await r.checkIsGitRepository(n)),!p){const x=new Map(c);return x.set(n,{...u,isGitRepo:!1,status:null,lastRepoCheckAt:f,lastStatusFetch:f}),t({directories:x,isLoadingStatus:!1}),!1}const g=await r.getGitStatus(n);if(my(u.status,g)){m=!0;const x=new Map(e().directories),b=x.get(n)??qo(),v=hy(b.status,g),y=new Set((b.status?.files??[]).map(S=>S.path)),w=new Set((g.files??[]).map(S=>S.path)),C=new Map(b.diffCache);for(const S of y)w.has(S)||C.delete(S);for(const S of v)C.delete(S);const N=v.size>0;N&&n0(n),x.set(n,{...b,isGitRepo:!0,status:g,diffCache:C,lastRepoCheckAt:h?f:b.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:N?Date.now():b.lastStatusChange}),t({directories:x})}else{const x=new Map(e().directories),b=x.get(n)??qo();x.set(n,{...b,isGitRepo:!0,lastRepoCheckAt:h?f:b.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:b.lastStatusChange}),t({directories:x})}}catch(f){console.error("Failed to fetch git status:",f)}finally{i||t({isLoadingStatus:!1})}return m})();s0.set(n,l);try{return await l}finally{s0.get(n)===l&&s0.delete(n)}},fetchBranches:async(n,r)=>{t({isLoadingBranches:!0});try{const o=await r.getGitBranches(n),a=new Map(e().directories),l=a.get(n)??qo();a.set(n,{...l,branches:o}),t({directories:a})}catch(o){console.error("Failed to fetch git branches:",o)}finally{t({isLoadingBranches:!1})}},fetchLog:async(n,r,o)=>{const{directories:a}=e(),l=a.get(n),i=o??l?.logMaxCount??25;t({isLoadingLog:!0});try{const c=await r.getGitLog(n,{maxCount:i}),u=new Map(e().directories),m=u.get(n)??qo();u.set(n,{...m,log:c,lastLogFetch:Date.now(),logMaxCount:i}),t({directories:u})}catch(c){console.error("Failed to fetch git log:",c)}finally{t({isLoadingLog:!1})}},fetchIdentity:async(n,r)=>{t({isLoadingIdentity:!0});try{const o=await r.getCurrentGitIdentity(n),a=new Map(e().directories),l=a.get(n)??qo();a.set(n,{...l,identity:o}),t({directories:a})}catch(o){console.error("Failed to fetch git identity:",o)}finally{t({isLoadingIdentity:!1})}},fetchAll:async(n,r,o={})=>{const{directories:a}=e();let l=a.get(n);if(!l){l=qo();const h=new Map(a);h.set(n,l),t({directories:h})}const{force:i=!1,silentIfCached:c=!1}=o,u=Date.now();await e().fetchStatus(n,r,{silent:c&&!!l?.status});const m=e().directories.get(n);if(!m?.isGitRepo)return;await e().fetchBranches(n,r);const f=u-(m.lastLogFetch||0);(i||f>oy||!m.log)&&await e().fetchLog(n,r),await e().fetchIdentity(n,r),e().fetchAllDiffs(n,r)},getDiff:(n,r)=>e().directories.get(n)?.diffCache.get(r)??null,setDiff:(n,r,o)=>{const a=new Map(e().directories),l=a.get(n)??qo(),i=new Map(l.diffCache);i.set(r,{...o,fetchedAt:Date.now()});const c=Y3(i);a.set(n,{...l,diffCache:c}),t({directories:a})},clearDiffCache:n=>{n0(n);const r=new Map(e().directories),o=r.get(n);o&&(r.set(n,{...o,diffCache:new Map}),t({directories:r}))},fetchAllDiffs:async(n,r)=>{const o=e().directories.get(n);if(!o?.status?.files||o.status.files.length===0)return;const a=o.status.files.map(l=>l.path).slice(0,q3);await e().prefetchDiffs(n,r,a,{maxFiles:q3})},prefetchDiffs:async(n,r,o,a={})=>{const l=e().directories.get(n);if(!l?.status?.files||l.status.files.length===0||o.length===0)return;const{maxFiles:i=ly}=a,c=new Set(l.status.files.map(F=>F.path)),u=uy(n),m=[],f=new Set;for(const F of o)!F||f.has(F)||(f.add(F),c.has(F)&&(l.diffCache.has(F)||u.has(F)||m.push(F)));const h=m.slice(0,Math.max(1,i));if(h.length===0)return;const p=$0(n);if(typeof document<"u"&&document.hidden)return;h.forEach(F=>u.add(F));let g=0;const x=[],b=()=>{const F=g;return g+=1,F<h.length?h[F]:null},v=async F=>{const A=r.getGitFileDiff(n,{path:F}),M=new Promise((E,I)=>{setTimeout(()=>I(new Error(`Timed out after ${G3}ms`)),G3)}),B=await Promise.race([A,M]);return{path:F,diff:{original:B.original??"",modified:B.modified??"",isBinary:B.isBinary}}},y=async()=>{for(;;){if(p!==$0(n))return;const F=b();if(!F)return;try{x.push(await v(F))}catch{}finally{u.delete(F)}}},w=Math.min(iy,h.length);if(await Promise.allSettled(Array.from({length:w},()=>y())),h.forEach(F=>u.delete(F)),p!==$0(n))return;const C=new Map(e().directories),N=C.get(n);if(!N)return;const S=new Map(N.diffCache),k=Date.now();x.forEach(F=>{S.set(F.path,{...F.diff,fetchedAt:k})});const j=Y3(S);C.set(n,{...N,diffCache:j}),t({directories:C})},setLogMaxCount:(n,r)=>{const o=new Map(e().directories),a=o.get(n)??qo();o.set(n,{...a,logMaxCount:r}),t({directories:o})},setPollingMode:n=>{const{pollingMode:r,currentPollInterval:o}=e();if(r===n)return;const a=hc(n),l=Math.min(Math.max(o,a.base),a.max);t({pollingMode:n,currentPollInterval:l})},startPolling:n=>{const{pollIntervalId:r}=e();if(r)return;const o=()=>{const{currentPollInterval:l}=e();return setTimeout(async()=>{if(typeof document<"u"&&document.hidden){t({pollIntervalId:o()});return}const{activeDirectory:c,recentDirectories:u}=e();if(!c){t({pollIntervalId:o()});return}const m=[c,...u.filter(g=>g!==c).slice(0,Math.max(0,Z3-1))];let f=!1;for(const g of m)await e().fetchStatus(g,n,{silent:!0})&&(f=!0,g===c&&(await e().fetchLog(c,n),e().fetchAllDiffs(c,n)));const h=hc(e().pollingMode);if(f)t({currentPollInterval:h.base});else{const g=Math.min(l+ry,h.max);t({currentPollInterval:g})}const{pollIntervalId:p}=e();p!==null&&t({pollIntervalId:o()})},l)},a=hc(e().pollingMode);t({pollIntervalId:o(),currentPollInterval:a.base})},stopPolling:()=>{const{pollIntervalId:n}=e();n&&(clearTimeout(n),t({pollIntervalId:null,currentPollInterval:_d,pollingMode:"normal"}))},refresh:async(n,r={})=>{const{activeDirectory:o}=e();o&&await e().fetchAll(o,n,r)}}),{name:"git-store"})),q2=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.status??null:null,e[0]=t,e[1]=n):n=e[1],Wn(n)},G2=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.branches??null:null,e[0]=t,e[1]=n):n=e[1],Wn(n)},py=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.log??null:null,e[0]=t,e[1]=n):n=e[1],Wn(n)},gy=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.identity??null:null,e[0]=t,e[1]=n):n=e[1],Wn(n)},U6=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.isGitRepo??null:null,e[0]=t,e[1]=n):n=e[1],Wn(n)},xy=t=>{const e=Fe.c(2);let n;return e[0]!==t?(n=r=>t?r.directories.get(t)?.status?.files?.length??0:0,e[0]=t,e[1]=n):n=e[1],Wn(n)},by=9e4,vy=15e3,yy=5*6e4,wy=[2e3,5e3],jy=6e4,ky=2*6e4,Ny=5*6e4,Sy=720*6e4,Cy="openchamber.github-pr-status",Ay=t=>t==="closed"||t==="merged",My=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Ed=(t,e,n)=>`${t}::${e}`,r0=new Map,o0=new Map,Vi=new Set,X3=new Map,ql=new Set,r1=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),d2=t=>t?.params?.directory&&t.params.branch?{directory:t.params.directory,branch:t.params.branch,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null}:!t?.identity?.directory||!t.identity.branch?null:t.identity,Lu=t=>{const e=d2(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},W6=(t,e)=>Object.entries(t).filter(([,n])=>Lu(n)===e).map(([n])=>n),Fy=(t,e)=>{const n=e.remoteName??t.params?.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null;return{...t,params:t.params?{...t.params,...e,remoteName:n}:{...e,remoteName:n},identity:{directory:e.directory,branch:e.branch,remoteName:n}}},a0=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},By=(t,e,n)=>{const r=W6(t,e),o=r.map(c=>a0(t[c])).filter(c=>!!c);if(o.length===0)return null;const a=a0(t[n]);if(a&&Lu(t[n])===e)return a;const l=r.map(c=>t[c]).find(c=>!!(c?.resolvedRemoteName&&a0(c)));if(l)return a0(l);const i=o.find(c=>!!c.remoteName);return i||(o[0]??null)},_y=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:d2(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),Ey=t=>({...r1(),status:t?.status??null,isInitialStatusResolved:t?.isInitialStatusResolved??!1,lastRefreshAt:t?.lastRefreshAt??0,lastDiscoveryPollAt:t?.lastDiscoveryPollAt??0,identity:t?.identity??null,resolvedRemoteName:t?.resolvedRemoteName??t?.status?.resolvedRemoteName??null}),mo=Dr()(Pl((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:r1()}})},setParams:(n,r)=>{t(o=>{const a=o.entries[n]??r1();return{entries:{...o.entries,[n]:Fy(a,r)}}})},startWatching:n=>{if(t(a=>{const l=a.entries[n]??r1();return{entries:{...a.entries,[n]:{...l,watchers:l.watchers+1}}}}),r0.has(n))return;const r=a=>{const l=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const c=e().entries[n];!c||c.watchers<=0||c.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},a),i=o0.get(n)??[];i.push(l),o0.set(n,i)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),wy.forEach(a=>r(a));const o=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const a=e().entries[n];if(!a||a.watchers<=0)return;if(!!!a.status?.pr){const u=Date.now();if(u-a.lastDiscoveryPollAt<yy)return;t(m=>{const f=m.entries[n];return f?{entries:{...m.entries,[n]:{...f,lastDiscoveryPollAt:u}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(Ay(a.status?.pr?.state))return;const i=Date.now()-a.lastRefreshAt,c=My(a.status)?jy:a.status?.checks&&a.status.checks.state!=="pending"?Ny:ky;i<c||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},vy);r0.set(n,o)},stopWatching:n=>{t(l=>{const i=l.entries[n];if(!i)return l;const c=Math.max(0,i.watchers-1);return{entries:{...l.entries,[n]:{...i,watchers:c}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const o=r0.get(n);typeof o=="number"&&window.clearInterval(o),r0.delete(n);const a=o0.get(n);a&&a.length>0&&a.forEach(l=>{window.clearTimeout(l)}),o0.delete(n)},refresh:async(n,r)=>{const o=e(),a=o.entries[n],l=Lu(a);if(!a||!l)return;const i=W6(o.entries,l),c=i.some(f=>!!o.entries[f]?.status?.pr);if(r?.onlyExistingPr&&!c)return;const u=X3.get(l)??0;if(!r?.force&&Date.now()-u<by||Vi.has(l))return;const m=By(o.entries,l,n);if(m){if(Vi.add(l),X3.set(l,Date.now()),t(f=>{const h={...f.entries};return i.forEach(p=>{const g=h[p];g&&(h[p]={...g,lastRefreshAt:Date.now(),isLoading:r?.silent?g.isLoading:!0,error:null})}),{entries:h}}),m.githubAuthChecked&&m.githubConnected===!1){t(f=>{const h={...f.entries};return i.forEach(p=>{const g=h[p];g&&(h[p]={...g,status:{connected:!1},error:null,isLoading:r?.silent?g.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?g.isInitialStatusResolved:!0})}),{entries:h}}),Vi.delete(l);return}if(!m.github?.prStatus){t(f=>{const h={...f.entries};return i.forEach(p=>{const g=h[p];g&&(h[p]={...g,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?g.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?g.isInitialStatusResolved:!0})}),{entries:h}}),Vi.delete(l);return}try{t(h=>({...h,activeRequestCount:h.activeRequestCount+1,totalRequestCount:h.totalRequestCount+1}));const f=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0);t(h=>{const p={...h.entries};return i.forEach(g=>{const x=p[g];if(!x)return;const b=x.status?.pr,v=f.pr,w=!!(v&&b&&v.number===b.number&&(!v.body||!v.body.trim())&&typeof b.body=="string"&&b.body.trim().length>0)&&v&&b?.body?{...f,pr:{...v,body:b.body}}:f,C=w.resolvedRemoteName??x.resolvedRemoteName??m.remoteName??null,N=d2(x)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};p[g]={...x,status:w,error:null,isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0,resolvedRemoteName:C,identity:{...N,remoteName:C??N.remoteName??null}}}),{entries:p}})}catch(f){const h=f instanceof Error?f.message:String(f);t(p=>{const g={...p.entries};return i.forEach(x=>{const b=g[x];b&&(g[x]={...b,error:h||"Failed to load PR status",isLoading:r?.silent?b.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?b.isInitialStatusResolved:!0})}),{entries:g}})}finally{Vi.delete(l),t(f=>({...f,activeRequestCount:Math.max(0,f.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const o=Array.from(new Set(n.map(a=>{const l=a.directory.trim(),i=a.branch.trim();return!l||!i?null:Ed(l,i,a.remoteName??null)}).filter(a=>!!a)));await Promise.all(o.map(a=>e().refresh(a,r)))},updateStatus:(n,r)=>{t(o=>{const a=o.entries[n]??r1();return{entries:{...o.entries,[n]:{...a,status:r(a.status)}}}})},syncBackgroundTargets:({targets:n,github:r,githubAuthChecked:o,githubConnected:a})=>{if(!r||n.length===0){Array.from(ql).forEach(c=>{e().stopWatching(c),ql.delete(c)});return}const l=new Map;n.forEach(c=>{const u=c.directory.trim(),m=c.branch.trim();if(!u||!m)return;const f=Ed(u,m,c.remoteName??null);l.has(f)||l.set(f,{directory:u,branch:m,remoteName:c.remoteName??null})});const i=new Set(l.keys());Array.from(ql).forEach(c=>{i.has(c)||(e().stopWatching(c),ql.delete(c))}),l.forEach((c,u)=>{e().ensureEntry(u),e().setParams(u,{directory:c.directory,branch:c.branch,remoteName:c.remoteName??null,canShow:!0,github:r,githubAuthChecked:o,githubConnected:a}),ql.has(u)||(e().startWatching(u),ql.add(u))})}}),{name:Cy,storage:Ii(()=>Ko()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=d2(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<Sy}).map(([e,n])=>[e,_y(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([o,a])=>[o,Ey(a)]))}}})),Dy=async t=>{if(t)return await t.authStatus();const e=await fetch("/api/github/auth/status",{method:"GET",headers:{Accept:"application/json"}}),n=await e.json().catch(()=>null);if(!e.ok||!n)throw new Error(n?.error||e.statusText||"Failed to load GitHub status");return n},ir=Dr((t,e)=>({status:null,isLoading:!1,hasChecked:!1,setStatus:n=>t({status:n,hasChecked:!0}),refreshStatus:async(n,r)=>{const{hasChecked:o,status:a}=e();if(o&&!r?.force)return a;t({isLoading:!0});try{const l=await Dy(n);return t({status:l,isLoading:!1,hasChecked:!0}),l}catch(l){const i=l instanceof Error?l.message:String(l);return t({status:{connected:!1,error:i},isLoading:!1,hasChecked:!0}),null}}})),Z2=d.createContext(null),ur=()=>{const t=d.useContext(Z2);if(!t)throw new Error("Runtime APIs are not available. Did you forget to wrap the app in <RuntimeAPIProvider>?");return t},Iy=t=>{const e=Fe.c(3),n=ur();let r;return e[0]!==n||e[1]!==t?(r=t(n),e[0]=n,e[1]=t,e[2]=r):r=e[2],r},q6=()=>Iy(Ty);function Ty(t){return t.runtime.isVSCode}const Py=1e3,K2=t=>{const e=Fe.c(59),{containerRef:n,minThumbSize:r,hideDelayMs:o,className:a,disableHorizontal:l,observeMutations:i,suppressVisibility:c,userIntentOnly:u}=t,m=r===void 0?32:r,f=o===void 0?1e3:o,h=l===void 0?!1:l,p=i===void 0?!0:i,g=c===void 0?!1:c,x=u===void 0?!1:u,[b,v]=d.useState(!1);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y={length:0,offset:0},e[0]=y):y=e[0];const[w,C]=d.useState(y);let N;e[1]===Symbol.for("react.memo_cache_sentinel")?(N={length:0,offset:0},e[1]=N):N=e[1];const[S,k]=d.useState(N),j=d.useRef(null),F=d.useRef(null),A=d.useRef(null),M=d.useRef(!1),B=d.useRef(0);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E={pointerX:0,pointerY:0,scrollTop:0,scrollLeft:0},e[2]=E):E=e[2];const I=d.useRef(E),P=d.useRef(null);let D;e[3]!==n||e[4]!==h||e[5]!==m?(D=()=>{const ue=n.current;if(!ue)return;const{scrollHeight:be,clientHeight:oe,scrollTop:Z,scrollWidth:ie,clientWidth:pe,scrollLeft:me}=ue;if(be>oe){const Se=Math.max(oe-16,0),ke=oe/be*Se,ye=Math.max(m,Math.min(Se,ke)),Ne=Math.max(Se-ye,0),_e=Math.max(be-oe,1),de=Z/_e*Ne;C({length:ye,offset:de})}else C({length:0,offset:0});if(!h&&ie>pe){const Se=Math.max(pe-16,0),ke=pe/ie*Se,ye=Math.max(m,Math.min(Se,ke)),Ne=Math.max(Se-ye,0),_e=Math.max(ie-pe,1),de=me/_e*Ne;k({length:ye,offset:de})}else k({length:0,offset:0})},e[3]=n,e[4]=h,e[5]=m,e[6]=D):D=e[6];const L=D;let T;e[7]!==L?(T=()=>{A.current===null&&(A.current=requestAnimationFrame(()=>{A.current=null,L()}))},e[7]=L,e[8]=T):T=e[8];const _=T;let z;e[9]!==f?(z=()=>{j.current&&clearTimeout(j.current),j.current=setTimeout(()=>v(!1),f)},e[9]=f,e[10]=z):z=e[10];const R=z;let W;e[11]===Symbol.for("react.memo_cache_sentinel")?(W=()=>{B.current=Date.now()},e[11]=W):W=e[11];const G=W;let Y;e[12]!==R||e[13]!==g||e[14]!==L||e[15]!==x?(Y=()=>{F.current&&cancelAnimationFrame(F.current),F.current=requestAnimationFrame(()=>{if(L(),g&&!M.current){v(!1);return}if(x&&!M.current&&!(Date.now()-B.current<=Py)){v(!1);return}v(!0),R()})},e[12]=R,e[13]=g,e[14]=L,e[15]=x,e[16]=Y):Y=e[16];const J=Y;let V,te;e[17]!==n||e[18]!==J||e[19]!==p||e[20]!==_||e[21]!==L||e[22]!==x?(V=()=>{const ue=n.current;if(!ue)return;L(),v(!1);const be=()=>J(),oe=pe=>{(pe.key==="ArrowUp"||pe.key==="ArrowDown"||pe.key==="PageUp"||pe.key==="PageDown"||pe.key==="Home"||pe.key==="End"||pe.key===" ")&&G()};ue.addEventListener("scroll",be,{passive:!0}),x&&(ue.addEventListener("wheel",G,{passive:!0}),ue.addEventListener("touchstart",G,{passive:!0}),ue.addEventListener("touchmove",G,{passive:!0}),ue.addEventListener("keydown",oe));const Z=typeof ResizeObserver<"u"?new ResizeObserver(()=>{_()}):null;Z?.observe(ue);const ie=p&&typeof MutationObserver<"u"?new MutationObserver(()=>_()):null;return ie?.observe(ue,{childList:!0,subtree:!0,characterData:!0}),()=>{ue.removeEventListener("scroll",be),x&&(ue.removeEventListener("wheel",G),ue.removeEventListener("touchstart",G),ue.removeEventListener("touchmove",G),ue.removeEventListener("keydown",oe)),Z?.disconnect(),ie?.disconnect(),j.current&&clearTimeout(j.current),F.current&&cancelAnimationFrame(F.current),A.current&&cancelAnimationFrame(A.current)}},te=[n,J,G,p,_,L,x],e[17]=n,e[18]=J,e[19]=p,e[20]=_,e[21]=L,e[22]=x,e[23]=V,e[24]=te):(V=e[23],te=e[24]),d.useEffect(V,te);let U,X;e[25]!==g?(U=()=>{g&&(M.current||(v(!1),j.current&&(clearTimeout(j.current),j.current=null)))},X=[g],e[25]=g,e[26]=U,e[27]=X):(U=e[26],X=e[27]),d.useEffect(U,X);let $;e[28]!==n?($=(ue,be)=>{const oe=n.current;oe&&(M.current=!0,I.current={pointerX:ue.clientX,pointerY:ue.clientY,scrollTop:oe.scrollTop,scrollLeft:oe.scrollLeft},P.current=be,G(),v(!0),j.current&&clearTimeout(j.current),ue.currentTarget.setPointerCapture(ue.pointerId))},e[28]=n,e[29]=$):$=e[29];const q=$;let ee;e[30]!==n||e[31]!==S.length||e[32]!==w.length?(ee=ue=>{if(!M.current)return;const be=n.current;if(!be)return;const oe=P.current;if(oe==="vertical"){const{pointerY:Z,scrollTop:ie}=I.current,pe=ue.clientY-Z,me=be.clientHeight,Se=Math.max(me-w.length,1),ke=Math.max(be.scrollHeight-be.clientHeight,1),ye=pe/Se*ke;be.scrollTop=ie+ye}else if(oe==="horizontal"){const{pointerX:Z,scrollLeft:ie}=I.current,pe=ue.clientX-Z,me=be.clientWidth,Se=Math.max(me-S.length,1),ke=Math.max(be.scrollWidth-be.clientWidth,1),ye=pe/Se*ke;be.scrollLeft=ie+ye}},e[30]=n,e[31]=S.length,e[32]=w.length,e[33]=ee):ee=e[33];const ce=ee;let ve;e[34]!==R?(ve=ue=>{M.current&&(M.current=!1,ue.currentTarget.releasePointerCapture(ue.pointerId),R())},e[34]=R,e[35]=ve):ve=e[35];const ge=ve,xe=w.length>0,ne=S.length>0;if(!xe&&!ne)return null;let O;e[36]!==a?(O=Q("overlay-scrollbar",a),e[36]=a,e[37]=O):O=e[37];const H=b?1:0;let K;e[38]!==H?(K={opacity:H},e[38]=H,e[39]=K):K=e[39];let re;e[40]!==q||e[41]!==ce||e[42]!==ge||e[43]!==xe||e[44]!==w.length||e[45]!==w.offset?(re=xe&&s.jsx("div",{className:"overlay-scrollbar__thumb overlay-scrollbar__thumb--vertical",style:{height:`${w.length}px`,top:`${8+w.offset}px`,right:"4px"},onPointerDown:ue=>q(ue,"vertical"),onPointerMove:ce,onPointerUp:ge,onPointerCancel:ge}),e[40]=q,e[41]=ce,e[42]=ge,e[43]=xe,e[44]=w.length,e[45]=w.offset,e[46]=re):re=e[46];let le;e[47]!==q||e[48]!==ce||e[49]!==ge||e[50]!==S.length||e[51]!==S.offset||e[52]!==ne?(le=ne&&s.jsx("div",{className:"overlay-scrollbar__thumb overlay-scrollbar__thumb--horizontal",style:{width:`${S.length}px`,left:`${8+S.offset}px`,bottom:"4px"},onPointerDown:ue=>q(ue,"horizontal"),onPointerMove:ce,onPointerUp:ge,onPointerCancel:ge}),e[47]=q,e[48]=ce,e[49]=ge,e[50]=S.length,e[51]=S.offset,e[52]=ne,e[53]=le):le=e[53];let ae;return e[54]!==O||e[55]!==K||e[56]!==re||e[57]!==le?(ae=s.jsxs("div",{className:O,"aria-hidden":"true",style:K,children:[re,le]}),e[54]=O,e[55]=K,e[56]=re,e[57]=le,e[58]=ae):ae=e[58],ae};function Ry(...t){return e=>{t.forEach(n=>{typeof n=="function"?n(e):n&&typeof n=="object"&&(n.current=e)})}}const Qa=d.forwardRef((t,e)=>{const n=Fe.c(25),{as:r,orientation:o,offset:a,size:l,isEnabled:i,hideTopShadow:c,hideBottomShadow:u,observeMutations:m,onVisibilityChange:f,style:h,className:p,children:g,...x}=t,b=r===void 0?"div":r,v=o===void 0?"vertical":o,y=a===void 0?0:a,w=l===void 0?48:l,C=i===void 0?!0:i,N=c===void 0?!1:c,S=u===void 0?!1:u,k=m===void 0?!0:m,j=d.useRef(null),F=d.useRef("none"),A=x["data-scroll-shadow"];delete x["data-scroll-shadow"];const M=h;let B;n[0]!==w||n[1]!==M?(B={...M},B["--scroll-shadow-size"]=`${w}px`,n[0]=w,n[1]=M,n[2]=B):B=n[2];const E=B,I=zy,P=Ly;let D;n[3]!==S||n[4]!==N||n[5]!==C||n[6]!==y||n[7]!==f||n[8]!==v?(D=()=>{const Y=j.current;if(!Y)return;if(!C){P(Y);return}const J=v==="vertical"?Y.scrollTop>y:Y.scrollLeft>y;let V=v==="vertical"?Y.scrollTop+Y.clientHeight+y<Y.scrollHeight:Y.scrollLeft+Y.clientWidth+y<Y.scrollWidth;const te=N&&v==="vertical"?!1:J;S&&v==="vertical"&&(V=!1),I(Y,te,V,v==="vertical"?"top":"left",v==="vertical"?"bottom":"right");const U=te&&V?"both":te?v==="vertical"?"top":"left":V?v==="vertical"?"bottom":"right":"none";U!==F.current&&(F.current=U,f?.(U))},n[3]=S,n[4]=N,n[5]=C,n[6]=y,n[7]=f,n[8]=v,n[9]=D):D=n[9];const L=D;let T,_;n[10]!==L||n[11]!==k?(T=()=>{const Y=j.current;if(!Y)return;let J=null;const V=()=>{J===null&&(J=requestAnimationFrame(()=>{J=null,L()}))},te=()=>L(),U=typeof ResizeObserver<"u"?new ResizeObserver(V):null,X=k&&typeof MutationObserver<"u"?new MutationObserver(V):null;return L(),Y.addEventListener("scroll",te,{passive:!0}),U?.observe(Y),X?.observe(Y,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),()=>{J!==null&&cancelAnimationFrame(J),Y.removeEventListener("scroll",te),U?.disconnect(),X?.disconnect()}},_=[L,k],n[10]=L,n[11]=k,n[12]=T,n[13]=_):(T=n[12],_=n[13]),d.useEffect(T,_);const z=x;let R;n[14]!==e?(R=Ry(j,e),n[14]=e,n[15]=R):R=n[15];const W=A??!0;let G;return n[16]!==b||n[17]!==g||n[18]!==p||n[19]!==E||n[20]!==v||n[21]!==z||n[22]!==R||n[23]!==W?(G=s.jsx(b,{...z,ref:R,className:p,"data-orientation":v,"data-scroll-shadow":W,style:E,children:g}),n[16]=b,n[17]=g,n[18]=p,n[19]=E,n[20]=v,n[21]=z,n[22]=R,n[23]=W,n[24]=G):G=n[24],G});Qa.displayName="ScrollShadow";function zy(t,e,n,r,o){const a=`${r}${o.charAt(0).toUpperCase()}${o.slice(1)}Scroll`;e&&n?(t.dataset[a]="true",t.removeAttribute(`data-${r}-scroll`),t.removeAttribute(`data-${o}-scroll`)):(t.dataset[`${r}Scroll`]=String(e),t.dataset[`${o}Scroll`]=String(n),t.removeAttribute(`data-${r}-${o}-scroll`))}function Ly(t){["top","bottom","top-bottom","left","right","left-right"].forEach(e=>{t.removeAttribute(`data-${e}-scroll`)})}const ks=d.forwardRef((t,e)=>{const n=Fe.c(45);let r,o,a,l,i,c,u,m,f,h,p,g,x,b,v,y;n[0]!==t?({className:o,outerClassName:i,children:r,style:f,minThumbSize:l,hideDelayMs:a,as:h,scrollbarClassName:m,disableHorizontal:p,observeMutations:g,fillContainer:x,keyboardAvoid:b,preventOverscroll:v,useScrollShadow:y,scrollShadowSize:u,...c}=t,n[0]=t,n[1]=r,n[2]=o,n[3]=a,n[4]=l,n[5]=i,n[6]=c,n[7]=u,n[8]=m,n[9]=f,n[10]=h,n[11]=p,n[12]=g,n[13]=x,n[14]=b,n[15]=v,n[16]=y):(r=n[1],o=n[2],a=n[3],l=n[4],i=n[5],c=n[6],u=n[7],m=n[8],f=n[9],h=n[10],p=n[11],g=n[12],x=n[13],b=n[14],v=n[15],y=n[16]);const w=h===void 0?"div":h,C=p===void 0?!1:p,N=g===void 0?!0:g,S=x===void 0?!0:x,k=b===void 0?!1:b,j=v===void 0?!1:v,F=y===void 0?!1:y,A=d.useRef(null);let M,B;n[17]===Symbol.for("react.memo_cache_sentinel")?(M=()=>A.current,B=[],n[17]=M,n[18]=B):(M=n[17],B=n[18]),d.useImperativeHandle(e,M,B);const E=j&&"overscroll-none";let I;n[19]!==i||n[20]!==E?(I=Q("relative flex flex-col min-h-0 w-full overflow-hidden",E,i),n[19]=i,n[20]=E,n[21]=I):I=n[21];const P=k?"true":void 0;let D;n[22]!==w||n[23]!==r||n[24]!==o||n[25]!==C||n[26]!==S||n[27]!==N||n[28]!==j||n[29]!==c||n[30]!==u||n[31]!==f||n[32]!==F?(D=F?s.jsx(Qa,{as:w,ref:A,size:u,className:Q("overlay-scrollbar-target overlay-scrollbar-container",j&&"overscroll-none",S?"flex-1 min-h-0 w-full":"flex-none w-full h-auto",C?"overflow-y-auto overflow-x-hidden":"overflow-auto",o),style:f,observeMutations:N,...c,children:r}):s.jsx(w,{ref:A,className:Q("overlay-scrollbar-target overlay-scrollbar-container",j&&"overscroll-none",S?"flex-1 min-h-0 w-full":"flex-none w-full h-auto",C?"overflow-y-auto overflow-x-hidden":"overflow-auto",o),style:f,...c,children:r}),n[22]=w,n[23]=r,n[24]=o,n[25]=C,n[26]=S,n[27]=N,n[28]=j,n[29]=c,n[30]=u,n[31]=f,n[32]=F,n[33]=D):D=n[33];let L;n[34]!==C||n[35]!==a||n[36]!==l||n[37]!==N||n[38]!==m?(L=s.jsx(K2,{containerRef:A,minThumbSize:l,hideDelayMs:a,className:m,disableHorizontal:C,observeMutations:N}),n[34]=C,n[35]=a,n[36]=l,n[37]=N,n[38]=m,n[39]=L):L=n[39];let T;return n[40]!==I||n[41]!==P||n[42]!==D||n[43]!==L?(T=s.jsxs("div",{className:I,"data-keyboard-avoid":P,children:[D,L]}),n[40]=I,n[41]=P,n[42]=D,n[43]=L,n[44]=T):T=n[44],T});ks.displayName="ScrollableOverlay";const Q3="mobile-overlay-root",Hy=()=>{if(typeof document>"u")return null;let t=document.getElementById(Q3);return t||(t=document.createElement("div"),t.id=Q3,document.body.appendChild(t)),t},cr=({open:t,title:e,onClose:n,children:r,footer:o,className:a,contentMaxHeightClassName:l,renderHeader:i})=>{const c=d.useRef(null);if(typeof document<"u"&&!c.current&&(c.current=Hy()),d.useEffect(()=>{if(!t)return;const f=document.body.style.overflow;document.body.style.overflow="hidden";const h=p=>{p.key==="Escape"&&n()};return document.addEventListener("keydown",h),()=>{document.body.style.overflow=f,document.removeEventListener("keydown",h)}},[t,n]),!t||!c.current)return null;const u=l??"max-h-[min(70vh,520px)]",m=s.jsx("div",{"data-blur-bg":!0,className:"fixed inset-0 z-50 flex flex-col bg-background/40 backdrop-blur-sm",role:"dialog","aria-modal":"true",onClick:n,children:s.jsxs("div",{className:Q("mt-auto w-full rounded-t-xl border border-border/50 bg-background shadow-none pwa-overlay-panel","mx-auto max-w-lg",a),"data-keyboard-avoid":"true",onClick:f=>f.stopPropagation(),children:[(()=>{const f=s.jsx("button",{type:"button",onClick:n,className:"flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover",children:s.jsx(Ps,{className:"h-4 w-4"})});return i?i(f):s.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/40",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:e}),f]})})(),s.jsx(ks,{outerClassName:u,className:"px-2 py-2 pwa-overlay-scroll",children:r}),o?s.jsx("div",{className:"border-t border-border/40 px-3 py-2",children:o}):null]})});return To.createPortal(m,c.current)},G6=t=>{const e=Fe.c(79),{totalTokens:n,percentage:r,colorPercentage:o,contextLimit:a,outputLimit:l,size:i,isMobile:c,hideIcon:u,showPercentIcon:m,className:f,valueClassName:h,percentIconClassName:p,onClick:g,pressed:x}=t,b=i===void 0?"default":i,v=c===void 0?!1:c,y=u===void 0?!1:u,w=m===void 0?!1:m,C=x===void 0?!1:x,[N,S]=d.useState(!1),k=typeof o=="number"?o:r,j=$y,F=Oy,A=typeof l=="number"?Math.max(l,0):0;let M;e[0]!==n?(M=j(n),e[0]=n,e[1]=M):M=e[1];const B=`Used tokens: ${M}`;let E;e[2]!==a?(E=j(a),e[2]=a,e[3]=E):E=e[3];const I=`Context limit: ${E}`;let P;e[4]!==A?(P=j(A),e[4]=A,e[5]=P):P=e[5];const D=`Output limit: ${P}`;let L;e[6]!==D||e[7]!==B||e[8]!==I?(L=[B,I,D],e[6]=D,e[7]=B,e[8]=I,e[9]=L):L=e[9];const T=L,_=!v&&typeof g=="function";let z;e[10]!==y||e[11]!==v?(z=!v&&!y&&s.jsx(Tg,{className:"h-4 w-4 flex-shrink-0"}),e[10]=y,e[11]=v,e[12]=z):z=e[12];let R;e[13]!==h?(R=Q("font-medium inline-flex items-center gap-1.5",h),e[13]=h,e[14]=R):R=e[14];let W;e[15]!==k||e[16]!==p||e[17]!==r||e[18]!==w?(W=w?s.jsxs(s.Fragment,{children:[s.jsx(Sh,{className:Q("h-3.5 w-3.5",p,F(k)),"aria-hidden":"true"}),s.jsxs("span",{className:"text-foreground",children:[Math.min(r,999).toFixed(1),"%"]})]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:F(k),children:Math.min(r,999).toFixed(1)}),"%"]}),e[15]=k,e[16]=p,e[17]=r,e[18]=w,e[19]=W):W=e[19];let G;e[20]!==R||e[21]!==W?(G=s.jsx("span",{className:R,children:W}),e[20]=R,e[21]=W,e[22]=G):G=e[22];let Y;e[23]!==z||e[24]!==G?(Y=s.jsxs(s.Fragment,{children:[z,G]}),e[23]=z,e[24]=G,e[25]=Y):Y=e[25];const J=Y,V=b==="compact"?"typography-micro":"typography-meta";let te;e[26]!==f||e[27]!==_||e[28]!==V?(te=Q("app-region-no-drag flex items-center gap-1.5 select-none",V,_?Q("rounded-md px-2 py-1.5 text-foreground transition-colors","hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"):"text-muted-foreground/60",f),e[26]=f,e[27]=_,e[28]=V,e[29]=te):te=e[29];const U=te;let X;e[30]!==J||e[31]!==_||e[32]!==v||e[33]!==g||e[34]!==C||e[35]!==U?(X=_?s.jsx("button",{type:"button",className:U,"aria-label":"Context usage","aria-pressed":C,onClick:g,children:J}):s.jsx("div",{className:U,"aria-label":"Context usage",onClick:v?()=>S(!0):void 0,children:J}),e[30]=J,e[31]=_,e[32]=v,e[33]=g,e[34]=C,e[35]=U,e[36]=X):X=e[36];const $=X;if(v){let ve;e[37]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>S(!1),e[37]=ve):ve=e[37];let ge;e[38]===Symbol.for("react.memo_cache_sentinel")?(ge=s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Used tokens"}),e[38]=ge):ge=e[38];let xe;e[39]!==n?(xe=j(n),e[39]=n,e[40]=xe):xe=e[40];let ne;e[41]!==xe?(ne=s.jsxs("div",{className:"flex justify-between items-center",children:[ge,s.jsx("span",{className:"typography-meta text-foreground font-medium",children:xe})]}),e[41]=xe,e[42]=ne):ne=e[42];let O;e[43]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Context limit"}),e[43]=O):O=e[43];let H;e[44]!==a?(H=j(a),e[44]=a,e[45]=H):H=e[45];let K;e[46]!==H?(K=s.jsxs("div",{className:"flex justify-between items-center",children:[O,s.jsx("span",{className:"typography-meta text-foreground font-medium",children:H})]}),e[46]=H,e[47]=K):K=e[47];let re;e[48]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Output limit"}),e[48]=re):re=e[48];let le;e[49]!==A?(le=j(A),e[49]=A,e[50]=le):le=e[50];let ae;e[51]!==le?(ae=s.jsxs("div",{className:"flex justify-between items-center",children:[re,s.jsx("span",{className:"typography-meta text-foreground font-medium",children:le})]}),e[51]=le,e[52]=ae):ae=e[52];let ue;e[53]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Usage"}),e[53]=ue):ue=e[53];let be;e[54]!==k?(be=Q("typography-meta font-semibold",F(k)),e[54]=k,e[55]=be):be=e[55];const oe=Math.min(r,999);let Z;e[56]!==oe?(Z=oe.toFixed(1),e[56]=oe,e[57]=Z):Z=e[57];let ie;e[58]!==be||e[59]!==Z?(ie=s.jsxs("div",{className:"flex justify-between items-center pt-1 border-t border-border/40",children:[ue,s.jsxs("span",{className:be,children:[Z,"%"]})]}),e[58]=be,e[59]=Z,e[60]=ie):ie=e[60];let pe;e[61]!==ne||e[62]!==K||e[63]!==ae||e[64]!==ie?(pe=s.jsx("div",{className:"flex flex-col gap-1.5",children:s.jsxs("div",{className:"rounded-xl border border-border/40 bg-sidebar/30 px-3 py-2 space-y-1",children:[ne,K,ae,ie]})}),e[61]=ne,e[62]=K,e[63]=ae,e[64]=ie,e[65]=pe):pe=e[65];let me;e[66]!==N||e[67]!==pe?(me=s.jsx(cr,{open:N,onClose:ve,title:"Context Usage",children:pe}),e[66]=N,e[67]=pe,e[68]=me):me=e[68];let Se;return e[69]!==$||e[70]!==me?(Se=s.jsxs(s.Fragment,{children:[$,me]}),e[69]=$,e[70]=me,e[71]=Se):Se=e[71],Se}let q;e[72]!==$?(q=s.jsx(It,{asChild:!0,children:$}),e[72]=$,e[73]=q):q=e[73];let ee;e[74]!==T?(ee=s.jsx(_t,{children:s.jsx("div",{className:"space-y-0.5",children:T.map(Vy)})}),e[74]=T,e[75]=ee):ee=e[75];let ce;return e[76]!==q||e[77]!==ee?(ce=s.jsxs(Dt,{delayDuration:1e3,children:[q,ee]}),e[76]=q,e[77]=ee,e[78]=ce):ce=e[78],ce};function $y(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toFixed(1).replace(/\.0$/,"")}function Oy(t){return t>=90?"text-status-error":t>=75?"text-status-warning":"text-status-success"}function Vy(t){return s.jsx("p",{className:"typography-micro leading-tight",children:t},t)}const Ui={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536},Z6=(t,e,n)=>{if(typeof window>"u")return;const r=document.documentElement,o=e==="mobile",a=e==="tablet",l=Eu();r.classList.remove("device-mobile","device-tablet","device-desktop"),r.classList.add(e==="mobile"?"device-mobile":e==="tablet"?"device-tablet":"device-desktop"),t?(r.classList.add("desktop-runtime"),r.style.setProperty("--is-mobile","0"),r.style.setProperty("--device-type","desktop"),r.style.setProperty("--font-scale","1"),r.style.setProperty("--has-coarse-pointer","0"),r.style.setProperty("--has-touch-input","0"),r.classList.remove("mobile-pointer")):l?(r.classList.add("electron-runtime"),r.style.setProperty("--is-mobile","0"),r.style.setProperty("--device-type","desktop"),r.style.setProperty("--font-scale","1"),r.style.setProperty("--has-coarse-pointer","0"),r.style.setProperty("--has-touch-input","0"),r.classList.remove("mobile-pointer")):(r.classList.remove("desktop-runtime","electron-runtime"),r.style.setProperty("--is-mobile",o?"1":"0"),r.style.setProperty("--device-type",e),r.style.setProperty("--font-scale",o?"0.9":a?"0.95":"1"),r.style.setProperty("--has-coarse-pointer",n?"1":"0"),r.style.setProperty("--has-touch-input",n?"1":"0"),n?r.classList.add("mobile-pointer"):r.classList.remove("mobile-pointer"))};function u2(){const t=window.innerWidth,e=typeof window.matchMedia=="function",n=e?window.matchMedia("(pointer: coarse)"):null,r=e?window.matchMedia("(hover: none)"):null,o=n?.matches??!1,a=r?.matches??!1,l=typeof navigator<"u"?navigator.maxTouchPoints??0:0,i=_n(),c=o||a||l>0,u=t>Ui.md&&t<=Ui.lg,m=t<=Ui.md;let f=c&&m,h=c&&!f&&u,p=!c||t>Ui.lg,g="desktop";i?(f=!1,h=!1,p=!0,g="desktop"):f?g="mobile":h?g="tablet":(p=!0,g="desktop"),Z6(i,g,c);let x="xs";for(const[b,v]of Object.entries(Ui))t>=v&&(x=b);return{isMobile:f,isTablet:h,isDesktop:p,deviceType:g,screenWidth:t,breakpoint:x,hasTouchInput:c}}function Si(){if(typeof window>"u"||typeof window<"u"&&_n())return!1;const t=document.documentElement,e=t.style.getPropertyValue("--is-mobile")||getComputedStyle(t).getPropertyValue("--is-mobile");return e==="1"||e==="true"}function wn(){const t=Fe.c(9),[e,n]=d.useState(Wy);let r,o;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{if(typeof window>"u")return;let u;const m=()=>{clearTimeout(u),u=setTimeout(()=>{n(u2())},150)};return window.addEventListener("resize",m),()=>{clearTimeout(u),window.removeEventListener("resize",m)}},o=[],t[0]=r,t[1]=o):(r=t[0],o=t[1]),d.useEffect(r,o);let a,l;t[2]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const u=window.matchMedia("(pointer: coarse)"),m=window.matchMedia("(hover: none)"),f=()=>{n(u2())},h=[],p=g=>{g&&(typeof g.addEventListener=="function"?(g.addEventListener("change",f),h.push(()=>g.removeEventListener("change",f))):typeof g.addListener=="function"&&(g.addListener(f),h.push(()=>g.removeListener(f))))};return p(u),p(m),()=>{h.forEach(Uy)}},l=[],t[2]=a,t[3]=l):(a=t[2],l=t[3]),d.useEffect(a,l);let i;t[4]!==e.deviceType?(i=()=>{if(typeof window>"u")return;const u=_n(),m=typeof window.matchMedia=="function",f=m?window.matchMedia("(pointer: coarse)"):null,h=m?window.matchMedia("(hover: none)"):null,p=f?.matches??!1,g=h?.matches??!1,x=typeof navigator<"u"?navigator.maxTouchPoints??0:0,b=p||g||x>0;Z6(u,e.deviceType,b)},t[4]=e.deviceType,t[5]=i):i=t[5];let c;return t[6]!==e.deviceType||t[7]!==e.hasTouchInput?(c=[e.deviceType,e.hasTouchInput],t[6]=e.deviceType,t[7]=e.hasTouchInput,t[8]=c):c=t[8],d.useEffect(i,c),e}function Uy(t){return t()}function Wy(){return typeof window>"u"?{isMobile:!1,isTablet:!1,isDesktop:!0,deviceType:"desktop",screenWidth:1024,breakpoint:"lg",hasTouchInput:!1}:u2()}const D1=he.forwardRef((t,e)=>{const n=Fe.c(11);let r,o;n[0]!==t?({className:r,...o}=t,n[0]=t,n[1]=r,n[2]=o):(r=n[1],o=n[2]);let a;n[3]!==r?(a=Q("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=a):a=n[4];let l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let i;n[6]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Pg,{className:Q("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=i):i=n[6];let c;return n[7]!==o||n[8]!==e||n[9]!==a?(c=s.jsx(Ch,{className:a,style:l,...o,ref:e,children:i}),n[7]=o,n[8]=e,n[9]=a,n[10]=c):c=n[10],c});D1.displayName=Ch.displayName;function Hu(t){const e=Fe.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let o;return e[2]!==t?(o=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=o):o=e[3],o}const K6=t=>{if(!t)return"Unknown";switch(t.status){case"connected":return"Connected";case"failed":return`Failed: ${t.error||"Unknown error"}`;case"needs_auth":return"Needs authentication";case"needs_client_registration":return`Needs registration: ${t.error||""}`;default:return t.status}},Y6=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Dd=({active:t,className:e})=>{const r=dn(g=>g.currentDirectory)??null,o=Yr(g=>g.getStatusForDirectory(r)),a=Yr(g=>g.refresh),l=Yr(g=>g.connect),i=Yr(g=>g.disconnect),[c,u]=d.useState(!1),[m,f]=d.useState(null);d.useEffect(()=>{a({directory:r,silent:!0})},[a,r]),d.useEffect(()=>{t&&a({directory:r,silent:!0})},[t,a,r]);const h=d.useMemo(()=>Object.keys(o).sort((g,x)=>g.localeCompare(x)),[o]),p=d.useCallback(g=>{if(g?.preventDefault(),c)return;u(!0);const x=new Promise(b=>setTimeout(b,500));Promise.all([a({directory:r}),x]).finally(()=>{u(!1)})},[c,a,r]);return s.jsxs("div",{className:Q("w-full",e),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-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:"MCP Servers"}),r&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:r.split("/").pop()||r})]}),s.jsx("button",{type:"button",className:"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",disabled:c,onClick:p,"aria-label":"Refresh",children:s.jsx(Qn,{className:Q("h-4 w-4",c&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[h.map(g=>{const x=o[g],b=Y6(x),v=x?.status==="connected",y=m===g,w=K6(x);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(Dt,{delayDuration:300,children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:Q("h-2 w-2 rounded-full flex-shrink-0",b==="success"&&"bg-status-success",b==="error"&&"bg-status-error",b==="warning"&&"bg-status-warning",b==="default"&&"bg-muted-foreground/40"),"aria-label":w})}),s.jsx(_t,{side:"left",children:s.jsx("p",{children:w})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(D1,{checked:v,disabled:y,className:"data-[state=checked]:bg-status-info",onCheckedChange:async C=>{f(g);try{C?await l(g,r):await i(g,r)}finally{f(null)}}})]},g)}),h.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:"Configure MCP servers in Opencode config."})]})]})},qy=({headerIconButtonClass:t})=>{const[e,n]=d.useState(!1),[r,o]=d.useState(!1),a=d.useRef(!1),{isMobile:l}=wn(),c=dn(j=>j.currentDirectory)??null,u=Yr(j=>j.getStatusForDirectory(c)),m=Yr(j=>j.refresh),f=Yr(j=>j.connect),h=Yr(j=>j.disconnect),p=d.useCallback(j=>{j||(a.current=!0,o(!1),setTimeout(()=>{a.current=!1},200)),n(j)},[]),g=d.useCallback(j=>{a.current||o(j)},[]),[x,b]=d.useState(!1),[v,y]=d.useState(null);d.useEffect(()=>{m({directory:c,silent:!0})},[m,c]),d.useEffect(()=>{e&&m({directory:c,silent:!0})},[e,m,c]);const w=d.useMemo(()=>Ub(u),[u]),C=d.useMemo(()=>Object.keys(u).sort((j,F)=>j.localeCompare(F)),[u]),N=d.useCallback(j=>{if(j?.preventDefault(),x)return;b(!0);const F=new Promise(A=>setTimeout(A,500));Promise.all([m({directory:c}),F]).finally(()=>{b(!1)})},[x,m,c]),S=()=>s.jsxs(s.Fragment,{children:[C.map(j=>{const F=u[j],A=Y6(F),M=F?.status==="connected",B=v===j,E=K6(F);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[l?s.jsx("span",{className:Q("h-2 w-2 rounded-full flex-shrink-0",A==="success"&&"bg-status-success",A==="error"&&"bg-status-error",A==="warning"&&"bg-status-warning",A==="default"&&"bg-muted-foreground/40"),"aria-label":E}):s.jsxs(Dt,{delayDuration:300,children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:Q("h-2 w-2 rounded-full flex-shrink-0",A==="success"&&"bg-status-success",A==="error"&&"bg-status-error",A==="warning"&&"bg-status-warning",A==="default"&&"bg-muted-foreground/40"),"aria-label":E})}),s.jsx(_t,{side:"left",children:s.jsx("p",{children:E})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:j})]})}),s.jsx(D1,{checked:M,disabled:B,className:"data-[state=checked]:bg-status-info",onCheckedChange:async I=>{y(j);try{I?await f(j,c):await h(j,c)}finally{y(null)}}})]},j)}),C.length===0&&s.jsx("div",{className:"px-2 py-3 typography-ui-label text-muted-foreground text-center",children:"Configure MCP servers in Opencode config."})]}),k=s.jsxs("button",{type:"button","aria-label":"MCP servers",className:Q(t,"relative"),onClick:l?()=>n(!0):void 0,children:[s.jsx(Hu,{className:"h-[1.0625rem] w-[1.0625rem]"}),w.total>0&&s.jsx("span",{className:Q("absolute top-1.5 right-1.5 h-1.5 w-1.5 rounded-full",w.hasFailed?"bg-status-error":w.hasAuthRequired?"bg-status-warning":w.connected>0?"bg-status-success":"bg-muted-foreground/40"),"aria-label":"MCP status"})]});return l?s.jsxs(s.Fragment,{children:[k,s.jsxs(cr,{open:e,title:"MCP Servers",onClose:()=>n(!1),renderHeader:j=>s.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/40",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:"MCP Servers"}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{type:"button",className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover transition-colors",disabled:x,onClick:N,"aria-label":"Refresh",children:s.jsx(Qn,{className:Q("h-4 w-4",x&&"animate-spin")})}),j]})]}),children:[s.jsx("div",{className:"py-1",children:S()}),c&&s.jsx("div",{className:"px-2 py-1 border-t border-border/40 mt-1",children:s.jsx("span",{className:"typography-meta text-muted-foreground truncate block",children:c.split("/").pop()||c})})]})]}):s.jsxs(qs,{open:e,onOpenChange:p,children:[s.jsxs(Dt,{delayDuration:1e3,open:e?!1:r,onOpenChange:g,children:[s.jsx(It,{asChild:!0,children:s.jsx(Gs,{asChild:!0,children:k})}),s.jsx(_t,{children:s.jsx("p",{children:"MCP Servers"})})]}),s.jsx(Ys,{align:"end",className:"w-72",children:s.jsx(Dd,{active:e})})]})},Gy="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M37.9998%2023.021C33.7998%2025.2889%2029.5698%2027.3649%2024.8614%2028.3069C23.8114%2028.5154%2022.6474%2028.5154%2021.5809%2028.3714C20.5639%2028.2439%2020.0554%2027.3484%2020.4169%2026.4064C20.7619%2025.5289%2021.2209%2024.635%2021.8119%2023.9C23.0899%2022.3025%2024.5329%2020.849%2025.8289%2019.268C26.6203%2018.2991%2027.3335%2017.2689%2027.9618%2016.187C28.4208%2015.4205%2028.2078%2014.4935%2027.4038%2014.111C26.0584%2013.4556%2024.6154%2012.9936%2023.1889%2012.4986C23.0239%2012.4341%2022.7779%2012.6096%2022.4509%2012.7221C22.8604%2013.0881%2023.1559%2013.3596%2023.5654%2013.727C19.3339%2014.447%2015.3305%2015.467%2011.4455%2016.874C11.4275%2016.9535%2011.396%2017.0165%2011.411%2017.0495C11.9855%2017.927%2011.723%2018.5975%2010.886%2019.1405C10.5611%2019.3531%2010.2732%2019.6176%2010.034%2019.9235C12.593%2020.6735%2014.873%2020.243%2017.0539%2018.821C16.9234%2018.6305%2016.7914%2018.455%2016.6609%2018.263C17.4799%2018.407%2017.9719%2018.854%2018.0379%2019.556C18.0544%2019.7165%2017.9569%2019.8755%2017.9074%2020.036C17.7919%2019.907%2017.6449%2019.781%2017.5474%2019.6355C17.4799%2019.5395%2017.4634%2019.4285%2017.4154%2019.268C14.8235%2020.993%2012.035%2021.425%208.96751%2020.531C8.96751%2021.137%208.93451%2021.6485%208.98401%2022.1435C9.01701%2022.574%208.83701%2022.766%208.44401%2022.9895C7.55752%2023.5325%206.63803%2024.092%205.90003%2024.8105C5.01504%2025.6879%205.34354%2026.7589%206.54053%2027.2059C7.90102%2027.7159%209.329%2027.7309%2010.7555%2027.5569C12.4445%2027.3484%2014.1005%2027.0769%2015.9394%2026.8219C13.79%2027.8269%2011.6735%2028.5319%209.4445%2028.8169C7.88452%2029.0269%206.32753%2029.1379%204.78554%2028.6909C2.57156%2028.0684%201.58607%2026.4394%202.16057%2024.251C2.70206%2022.2065%204.01455%2020.5775%205.42454%2019.076C10.133%2014.078%2016.0864%2011.5401%2022.9744%2011.0286C24.5824%2010.9176%2026.2069%2011.1246%2027.7143%2011.7951C29.8308%2012.7536%2030.7173%2014.78%2029.6838%2016.826C29.0118%2018.1835%2028.0758%2019.4285%2027.1413%2020.6585C26.2234%2021.872%2025.1899%2022.9895%2024.2224%2024.155C23.9434%2024.506%2023.6809%2024.875%2023.4679%2025.2724C23.0569%2026.0224%2023.3359%2026.5174%2024.2059%2026.4394C26.0254%2026.2624%2027.8808%2026.1199%2029.6358%2025.6729C32.2098%2025.0174%2034.7193%2024.092%2037.2618%2023.2775C37.5243%2023.213%2037.7703%2023.117%2037.9998%2023.0225V23.021Z'%20fill='currentColor'/%3e%3c/svg%3e",Zy="data:image/svg+xml,%3csvg%20fill='currentColor'%20fill-rule='evenodd'%20height='1em'%20style='flex:none;line-height:1'%20viewBox='0%200%2024%2024'%20width='1em'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eCursor%3c/title%3e%3cg%20transform='translate(12%2012)%20scale(0.88)%20translate(-12%20-12)'%3e%3cpath%20d='M22.106%205.68L12.5.135a.998.998%200%2000-.998%200L1.893%205.68a.84.84%200%2000-.419.726v11.186c0%20.3.16.577.42.727l9.607%205.547a.999.999%200%2000.998%200l9.608-5.547a.84.84%200%2000.42-.727V6.407a.84.84%200%2000-.42-.726zm-.603%201.176L12.228%2022.92c-.063.108-.228.064-.228-.061V12.34a.59.59%200%2000-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264%200%20.428.286.296.514z'%3e%3c/path%3e%3c/g%3e%3c/svg%3e",Ky="data:image/svg+xml,%3csvg%20fill='%23000000'%20viewBox='0%200%2033%2025'%20role='img'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M79.01%205.863c-4.066%200-6.511%202.92-6.511%206.535%200%203.635%202.445%206.555%206.511%206.555%204.046%200%206.512-2.92%206.512-6.555s-2.466-6.535-6.512-6.535Zm0%2010.968c-2.633%200-4.172-1.933-4.172-4.433s1.539-4.455%204.172-4.455c2.635%200%204.151%201.933%204.151%204.434%200%202.521-1.516%204.454-4.15%204.454Zm14.393%202.096c3.393%200%205.542-1.808%205.837-4.539h-2.36c-.316%201.555-1.517%202.437-3.477%202.437-2.423%200-3.878-1.68-3.878-4.433%200-2.774%201.476-4.434%203.878-4.434%201.96%200%203.14.862%203.477%202.5h2.36c-.295-2.773-2.444-4.622-5.837-4.622-3.856%200-6.217%202.669-6.217%206.535%200%203.887%202.36%206.556%206.217%206.556Zm-29.543-.311h2.36v-6.01c0-2.752%201.348-4.244%203.772-4.244h2.276V6.177h-2.255c-2.128%200-3.288.735-3.898%202.605l-.443-.063.527-2.542h-2.36v12.439h.02Zm-24.445-7.332c.106-2.101%201.517-3.53%203.793-3.53%202.276%200%203.646%201.345%203.646%203.53h-7.439Zm9.778.4c0-3.426-2.381-5.821-5.943-5.821-3.73%200-6.174%202.563-6.174%206.535%200%204.013%202.423%206.555%206.28%206.555%202.929%200%205.247-1.597%205.669-3.887h-2.36c-.507%201.156-1.666%201.828-3.31%201.828-2.38%200-3.877-1.408-3.94-3.803h9.694c.042-.588.084-.861.084-1.408Zm5.69%206.932h1.939l5.5-12.44h-2.529L56%2015.99l-.316.021-3.793-9.833h-2.508l5.5%2012.439ZM32.23%2012.35c0-.882-.359-1.701-.99-2.437a8.594%208.594%200%200%201-1.497%201.093c.337.42.527.861.527%201.345%200%202.731-5.837%204.811-14.14%204.811-8.281.021-14.118-2.059-14.118-4.811%200-.463.168-.925.505-1.345a8.13%208.13%200%200%201-1.475-1.093c-.632.736-.99%201.555-.99%202.438%200%204.034%207.207%206.534%2016.1%206.534%208.87.021%2016.078-2.5%2016.078-6.535Zm-3.351%201.534c-.906-.462-1.96-.861-3.16-1.197-1.37.378-2.909.672-4.553.861%202.318.294%204.341.778%205.9%201.408.76-.336%201.37-.693%201.813-1.072Zm-17.849-.357a31.902%2031.902%200%200%201-4.467-.84c-1.18.336-2.255.735-3.16%201.197.42.379%201.01.715%201.748%201.05%201.539-.63%203.52-1.113%205.88-1.407Zm21.2-6.808c0-4.013-7.207-6.534-16.079-6.534C7.26.185.051%202.706.051%206.719c0%204.035%207.208%206.535%2016.1%206.535%208.872.021%2016.079-2.5%2016.079-6.535Zm-1.94%200c0%202.732-5.836%204.812-14.139%204.812-8.302.021-14.14-2.06-14.14-4.812%200-2.731%205.838-4.811%2014.14-4.811%207.86%200%2014.14%202.08%2014.14%204.811Zm-3.223%202.564c.758-.336%201.37-.694%201.812-1.072-2.95-1.513-7.544-2.353-12.728-2.353s-9.799.84-12.728%202.353c.422.378%201.012.715%201.75%201.05%202.507-1.05%206.363-1.68%2010.978-1.68%204.404%200%208.324.651%2010.916%201.702ZM1.042%2015.628c-.632.736-.99%201.534-.99%202.438%200%204.034%207.207%206.534%2016.1%206.534%208.892%200%2016.099-2.521%2016.099-6.534%200-.883-.359-1.702-.99-2.438-.422.4-.907.757-1.497%201.093.337.42.527.861.527%201.345%200%202.731-5.837%204.811-14.14%204.811-8.302%200-14.14-2.08-14.14-4.811%200-.463.17-.925.506-1.345a10.73%2010.73%200%200%201-1.475-1.093Z'/%3e%3c/svg%3e",Yy="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='utf-8'?%3e%3c!--%20Uploaded%20to:%20SVG%20Repo,%20www.svgrepo.com,%20Generator:%20SVG%20Repo%20Mixer%20Tools%20--%3e%3csvg%20fill='%23000000'%20width='800px'%20height='800px'%20viewBox='0%200%2024%2024'%20role='img'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M20.702%202.29c-2.494-1.554-5.778-1.187-8.706.654C9.076%201.104%205.79.736%203.3%202.29c-3.941%202.463-4.42%208.806-1.07%2014.167%202.47%203.954%206.333%206.269%209.77%206.226%203.439.043%207.301-2.273%209.771-6.226%203.347-5.361%202.872-11.704-1.069-14.167zM4.042%2015.328a12.838%2012.838%200%200%201-1.546-3.541%2010.12%2010.12%200%200%201-.336-3.338c.15-1.98.956-3.524%202.27-4.345%201.315-.822%203.052-.87%204.903-.137.281.113.556.24.825.382A15.11%2015.11%200%200%200%207.5%207.54c-2.035%203.255-2.655%206.878-1.945%209.765a13.247%2013.247%200%200%201-1.514-1.98zm17.465-3.541a12.866%2012.866%200%200%201-1.547%203.54%2013.25%2013.25%200%200%201-1.513%201.984c.635-2.589.203-5.76-1.353-8.734a.39.39%200%200%200-.563-.153l-4.852%203.032a.397.397%200%200%200-.126.546l.712%201.139a.395.395%200%200%200%20.547.126l3.145-1.965c.101.306.203.606.28.916.296%201.086.41%202.214.335%203.337-.15%201.982-.956%203.525-2.27%204.347a4.437%204.437%200%200%201-2.25.65h-.101a4.432%204.432%200%200%201-2.25-.65c-1.314-.822-2.121-2.365-2.27-4.347a10.153%2010.153%200%200%201%20.335-3.337%2013.212%2013.212%200%200%201%204.05-6.482%2010.148%2010.148%200%200%201%202.849-1.765c1.845-.733%203.586-.685%204.9.137%201.316.822%202.122%202.365%202.271%204.345a10.146%2010.146%200%200%201-.33%203.334z'/%3e%3c/svg%3e",Xy="data:image/svg+xml,%3csvg%20fill='currentColor'%20fill-rule='evenodd'%20height='1em'%20style='flex:none;line-height:1'%20viewBox='0%200%2024%2024'%20width='1em'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eLM%20Studio%3c/title%3e%3cpath%20d='M2.84%202a1.273%201.273%200%20100%202.547h14.107a1.273%201.273%200%20100-2.547H2.84zM7.935%205.33a1.273%201.273%200%20000%202.548H22.04a1.274%201.274%200%20000-2.547H7.935zM3.624%209.935c0-.704.57-1.274%201.274-1.274h14.106a1.274%201.274%200%20010%202.547H4.898c-.703%200-1.274-.57-1.274-1.273zM1.273%2012.188a1.273%201.273%200%20100%202.547H15.38a1.274%201.274%200%20000-2.547H1.273zM3.624%2016.792c0-.704.57-1.274%201.274-1.274h14.106a1.273%201.273%200%20110%202.547H4.898c-.703%200-1.274-.57-1.274-1.273zM13.029%2018.849a1.273%201.273%200%20100%202.547h9.698a1.273%201.273%200%20100-2.547h-9.698z'%20fill-opacity='.3'%3e%3c/path%3e%3cpath%20d='M2.84%202a1.273%201.273%200%20100%202.547h10.287a1.274%201.274%200%20000-2.547H2.84zM7.935%205.33a1.273%201.273%200%20000%202.548H18.22a1.274%201.274%200%20000-2.547H7.935zM3.624%209.935c0-.704.57-1.274%201.274-1.274h10.286a1.273%201.273%200%20010%202.547H4.898c-.703%200-1.274-.57-1.274-1.273zM1.273%2012.188a1.273%201.273%200%20100%202.547H11.56a1.274%201.274%200%20000-2.547H1.273zM3.624%2016.792c0-.704.57-1.274%201.274-1.274h10.286a1.273%201.273%200%20110%202.547H4.898c-.703%200-1.274-.57-1.274-1.273zM13.029%2018.849a1.273%201.273%200%20100%202.547h5.78a1.273%201.273%200%20100-2.547h-5.78z'%3e%3c/path%3e%3c/svg%3e",Qy="data:image/svg+xml,%3csvg%20fill='currentColor'%20fill-rule='evenodd'%20height='1em'%20style='flex:none;line-height:1'%20viewBox='0%200%2024%2024'%20width='1em'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eOllama%3c/title%3e%3cpath%20d='M7.905%201.09c.216.085.411.225.588.41.295.306.544.744.734%201.263.191.522.315%201.1.362%201.68a5.054%205.054%200%20012.049-.636l.051-.004c.87-.07%201.73.087%202.48.474.101.053.2.11.297.17.05-.569.172-1.134.36-1.644.19-.52.439-.957.733-1.264a1.67%201.67%200%2001.589-.41c.257-.1.53-.118.796-.042.401.114.745.368%201.016.737.248.337.434.769.561%201.287.23.934.27%202.163.115%203.645l.053.04.026.019c.757.576%201.284%201.397%201.563%202.35.435%201.487.216%203.155-.534%204.088l-.018.021.002.003c.417.762.67%201.567.724%202.4l.002.03c.064%201.065-.2%202.137-.814%203.19l-.007.01.01.024c.472%201.157.62%202.322.438%203.486l-.006.039a.651.651%200%2001-.747.536.648.648%200%2001-.54-.742c.167-1.033.01-2.069-.48-3.123a.643.643%200%2001.04-.617l.004-.006c.604-.924.854-1.83.8-2.72-.046-.779-.325-1.544-.8-2.273a.644.644%200%2001.18-.886l.009-.006c.243-.159.467-.565.58-1.12a4.229%204.229%200%2000-.095-1.974c-.205-.7-.58-1.284-1.105-1.683-.595-.454-1.383-.673-2.38-.61a.653.653%200%2001-.632-.371c-.314-.665-.772-1.141-1.343-1.436a3.288%203.288%200%2000-1.772-.332c-1.245.099-2.343.801-2.67%201.686a.652.652%200%2001-.61.425c-1.067.002-1.893.252-2.497.703-.522.39-.878.935-1.066%201.588a4.07%204.07%200%2000-.068%201.886c.112.558.331%201.02.582%201.269l.008.007c.212.207.257.53.109.785-.36.622-.629%201.549-.673%202.44-.05%201.018.186%201.902.719%202.536l.016.019a.643.643%200%2001.095.69c-.576%201.236-.753%202.252-.562%203.052a.652.652%200%2001-1.269.298c-.243-1.018-.078-2.184.473-3.498l.014-.035-.008-.012a4.339%204.339%200%2001-.598-1.309l-.005-.019a5.764%205.764%200%2001-.177-1.785c.044-.91.278-1.842.622-2.59l.012-.026-.002-.002c-.293-.418-.51-.953-.63-1.545l-.005-.024a5.352%205.352%200%2001.093-2.49c.262-.915.777-1.701%201.536-2.269.06-.045.123-.09.186-.132-.159-1.493-.119-2.73.112-3.67.127-.518.314-.95.562-1.287.27-.368.614-.622%201.015-.737.266-.076.54-.059.797.042zm4.116%209.09c.936%200%201.8.313%202.446.855.63.527%201.005%201.235%201.005%201.94%200%20.888-.406%201.58-1.133%202.022-.62.375-1.451.557-2.403.557-1.009%200-1.871-.259-2.493-.734-.617-.47-.963-1.13-.963-1.845%200-.707.398-1.417%201.056-1.946.668-.537%201.55-.849%202.485-.849zm0%20.896a3.07%203.07%200%2000-1.916.65c-.461.37-.722.835-.722%201.25%200%20.428.21.829.61%201.134.455.347%201.124.548%201.943.548.799%200%201.473-.147%201.932-.426.463-.28.7-.686.7-1.257%200-.423-.246-.89-.683-1.256-.484-.405-1.14-.643-1.864-.643zm.662%201.21l.004.004c.12.151.095.37-.056.49l-.292.23v.446a.375.375%200%2001-.376.373.375.375%200%2001-.376-.373v-.46l-.271-.218a.347.347%200%2001-.052-.49.353.353%200%2001.494-.051l.215.172.22-.174a.353.353%200%2001.49.051zm-5.04-1.919c.478%200%20.867.39.867.871a.87.87%200%2001-.868.871.87.87%200%2001-.867-.87.87.87%200%2001.867-.872zm8.706%200c.48%200%20.868.39.868.871a.87.87%200%2001-.868.871.87.87%200%2001-.867-.87.87.87%200%2001.867-.872zM7.44%202.3l-.003.002a.659.659%200%2000-.285.238l-.005.006c-.138.189-.258.467-.348.832-.17.692-.216%201.631-.124%202.782.43-.128.899-.208%201.404-.237l.01-.001.019-.034c.046-.082.095-.161.148-.239.123-.771.022-1.692-.253-2.444-.134-.364-.297-.65-.453-.813a.628.628%200%2000-.107-.09L7.44%202.3zm9.174.04l-.002.001a.628.628%200%2000-.107.09c-.156.163-.32.45-.453.814-.29.794-.387%201.776-.23%202.572l.058.097.008.014h.03a5.184%205.184%200%20011.466.212c.086-1.124.038-2.043-.128-2.722-.09-.365-.21-.643-.349-.832l-.004-.006a.659.659%200%2000-.285-.239h-.004z'%3e%3c/path%3e%3c/svg%3e",Jy=Object.assign({"../assets/provider-logos/bailian-coding-plan.svg":Gy,"../assets/provider-logos/cursor.svg":Zy,"../assets/provider-logos/evroc.svg":Ky,"../assets/provider-logos/gocode.svg":Yy,"../assets/provider-logos/lmstudio.svg":Xy,"../assets/provider-logos/ollama.svg":Qy}),$u=new Map,J3=new Map([["codex","openai"],["chatgpt","openai"],["claude","anthropic"],["gemini","google"],["evroc-ai","evroc"],["evrocai","evroc"],["ollama-cloud","ollama"]]),ew=t=>(t??"").toLowerCase().trim().replace(/^models\./,"").replace(/^provider\./,"").replace(/\s+/g,"-"),tw=t=>{const e=ew(t);if(!e)return[];const n=e.replace(/[^a-z0-9_\-./:]/g,""),r=n.split(/[/:]/)[0]||n,o=[J3.get(n),J3.get(r),n,r].filter(a=>!!(a&&a.length>0));return[...new Set(o)]};for(const[t,e]of Object.entries(Jy)){const n=t.match(/provider-logos\/([^/]+)\.svg$/i);n?.[1]&&e&&$u.set(n[1].toLowerCase(),e)}function X6(t){const e=Fe.c(23);let n,r,o,a;if(e[0]!==t){const g=tw(t);r=g.find(sw)??null,o=g[0]??null,n=!!r,a=r?$u.get(r)??null:null,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a}else n=e[1],r=e[2],o=e[3],a=e[4];const l=a,[i,c]=he.useState(n?"local":"remote");let u;e[5]!==n?(u=()=>{c(n?"local":"remote")},e[5]=n,e[6]=u):u=e[6];let m;e[7]!==n||e[8]!==r||e[9]!==o?(m=[n,r,o],e[7]=n,e[8]=r,e[9]=o,e[10]=m):m=e[10],he.useEffect(u,m);let f;e[11]!==n?(f=()=>{c(g=>g==="local"&&n?"remote":"none")},e[11]=n,e[12]=f):f=e[12];const h=f;if(!r&&!o){let g;return e[13]!==h?(g={src:null,onError:h,hasLogo:!1},e[13]=h,e[14]=g):g=e[14],g}if(i==="local"&&l){let g;return e[15]!==h||e[16]!==l?(g={src:l,onError:h,hasLogo:!0},e[15]=h,e[16]=l,e[17]=g):g=e[17],g}if(i==="remote"&&o){const g=`https://models.dev/logos/${o}.svg`;let x;return e[18]!==h||e[19]!==g?(x={src:g,onError:h,hasLogo:!0},e[18]=h,e[19]=g,e[20]=x):x=e[20],x}let p;return e[21]!==h?(p={src:null,onError:h,hasLogo:!1},e[21]=h,e[22]=p):p=e[22],p}function sw(t){return $u.has(t)}const Mn=t=>{const e=Fe.c(10),{providerId:n,alt:r,className:o,onError:a}=t,{src:l,onError:i,hasLogo:c}=X6(n);let u;e[0]!==a||e[1]!==i?(u=()=>{i(),a?.()},e[0]=a,e[1]=i,e[2]=u):u=e[2];const m=u;if(!c||!l)return null;const f=r||`${n} logo`;let h;e[3]!==o?(h=Q("dark:invert object-contain",o),e[3]=o,e[4]=h):h=e[4];let p;return e[5]!==m||e[6]!==l||e[7]!==f||e[8]!==h?(p=s.jsx("img",{src:l,alt:f,className:h,onError:m}),e[5]=m,e[6]=l,e[7]=f,e[8]=h,e[9]=p):p=e[9],p},di=t=>{const e=Fe.c(20),{percent:n,tonePercent:r,className:o,expectedMarkerPercent:a}=t;let l;e[0]!==n?(l=R6(n)??0,e[0]=n,e[1]=l):l=e[1];const i=l,c=r??n;let u;e[2]!==c?(u=z6(c),e[2]=c,e[3]=u):u=e[3];const m=u,f=a!=null?Math.max(0,Math.min(100,a)):null;let h;e[4]!==m?(h=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=h):h=e[5];const p=h;let g;e[6]!==o?(g=Q("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",o),e[6]=o,e[7]=g):g=e[7];const x=`${i}%`;let b;e[8]!==p||e[9]!==x?(b={...p,width:x},e[8]=p,e[9]=x,e[10]=b):b=e[10];let v;e[11]!==i||e[12]!==b?(v=s.jsx("div",{className:"h-full transition-all duration-300",style:b,role:"progressbar","aria-valuenow":i,"aria-valuemin":0,"aria-valuemax":100}),e[11]=i,e[12]=b,e[13]=v):v=e[13];let y;e[14]!==f?(y=f!=null&&f>0&&f<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${f}%`},title:`Expected usage if spread evenly: ${Math.round(f)}% of quota`,"aria-hidden":"true"}),e[14]=f,e[15]=y):y=e[15];let w;return e[16]!==g||e[17]!==v||e[18]!==y?(w=s.jsxs("div",{className:g,children:[v,y]}),e[16]=g,e[17]=v,e[18]=y,e[19]=w):w=e[19],w},ui=t=>{const e=Fe.c(53),{paceInfo:n,className:r,compact:o}=t,a=o===void 0?!1:o;let l;e[0]!==n.status?(l=Wv(n.status),e[0]=n.status,e[1]=l):l=e[1];const i=l;let c;e:{switch(n.status){case"on-track":{c="On track";break e}case"slightly-fast":{c="Slightly fast";break e}case"too-fast":{c="Too fast";break e}case"exhausted":{c="Used up";break e}}c=void 0}const u=c,m=`Predicted usage at window end based on current pace: ${n.predictText}`;if(a){let N;e[2]!==r?(N=Q("flex items-center gap-1.5",r),e[2]=r,e[3]=N):N=e[3];let S;e[4]!==i?(S={backgroundColor:i},e[4]=i,e[5]=S):S=e[5];let k;e[6]!==u||e[7]!==S?(k=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:S,title:u}),e[6]=u,e[7]=S,e[8]=k):k=e[8];let j;e[9]!==i?(j={color:i},e[9]=i,e[10]=j):j=e[10];const F=n.isExhausted?void 0:m;let A;e[11]!==n.isExhausted||e[12]!==n.predictText||e[13]!==n.remainingSeconds?(A=n.isExhausted?s.jsxs(s.Fragment,{children:["Wait ",V3(n.remainingSeconds)]}):s.jsxs(s.Fragment,{children:["Pred: ",n.predictText]}),e[11]=n.isExhausted,e[12]=n.predictText,e[13]=n.remainingSeconds,e[14]=A):A=e[14];let M;e[15]!==j||e[16]!==F||e[17]!==A?(M=s.jsx("span",{className:"typography-micro tabular-nums",style:j,title:F,children:A}),e[15]=j,e[16]=F,e[17]=A,e[18]=M):M=e[18];let B;return e[19]!==M||e[20]!==N||e[21]!==k?(B=s.jsxs("div",{className:N,children:[k,M]}),e[19]=M,e[20]=N,e[21]=k,e[22]=B):B=e[22],B}let f;e[23]!==r?(f=Q("flex items-center justify-between gap-2",r),e[23]=r,e[24]=f):f=e[24];let h;e[25]!==n.isExhausted||e[26]!==n.paceRateText?(h=!n.isExhausted&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["Pace: ",n.paceRateText]}),e[25]=n.isExhausted,e[26]=n.paceRateText,e[27]=h):h=e[27];let p;e[28]!==h?(p=s.jsx("div",{className:"flex items-center gap-1.5",children:h}),e[28]=h,e[29]=p):p=e[29];let g;e[30]!==i?(g={color:i},e[30]=i,e[31]=g):g=e[31];let x;e[32]!==n.isExhausted||e[33]!==n.predictText||e[34]!==n.remainingSeconds||e[35]!==m||e[36]!==u?(x=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:u}),s.jsx("span",{className:"text-muted-foreground",children:" · Wait "}),s.jsx("span",{className:"font-medium",children:V3(n.remainingSeconds)})]}):s.jsxs("span",{title:m,children:[s.jsx("span",{className:"text-muted-foreground",children:"Pred: "}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[32]=n.isExhausted,e[33]=n.predictText,e[34]=n.remainingSeconds,e[35]=m,e[36]=u,e[37]=x):x=e[37];let b;e[38]!==g||e[39]!==x?(b=s.jsx("span",{className:"typography-micro tabular-nums",style:g,children:x}),e[38]=g,e[39]=x,e[40]=b):b=e[40];let v;e[41]!==i?(v={backgroundColor:i},e[41]=i,e[42]=v):v=e[42];let y;e[43]!==u||e[44]!==v?(y=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:v,title:u}),e[43]=u,e[44]=v,e[45]=y):y=e[45];let w;e[46]!==y||e[47]!==b?(w=s.jsxs("div",{className:"flex items-center gap-1.5",children:[b,y]}),e[46]=y,e[47]=b,e[48]=w):w=e[48];let C;return e[49]!==w||e[50]!==f||e[51]!==p?(C=s.jsxs("div",{className:f,children:[p,w]}),e[49]=w,e[50]=f,e[51]=p,e[52]=C):C=e[52],C},kl="__unassigned__",Q6={mod:"mod",shift:"shift",alt:"alt",option:"alt",ctrl:"ctrl",meta:"mod",cmd:"mod",command:"mod"},nw={mod:_1()&&_n()?"⌘":"Ctrl",shift:"⇧",alt:"⌥",option:"⌥",ctrl:"⌃"},rw={comma:",",period:".",enter:"Enter",escape:"Esc",tab:"Tab",space:"Space",backspace:"⌫",delete:"⌦",arrowup:"↑",arrowdown:"↓",arrowleft:"←",arrowright:"→",home:"Home",end:"End",pageup:"Page Up",pagedown:"Page Down"},J6=["mod","ctrl","shift","alt"],ow={"{":"[","}":"]",":":";",'"':"'","<":",",">":".","?":"/","|":"\\","~":"`","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0"};function Li(t){return t.trim().toLowerCase()===kl}function Id(t){const e=t.toLowerCase();return e===","?"comma":e==="."?"period":e===" "?"space":e==="esc"?"escape":e==="+"?"plus":e==="-"||e==="_"?"minus":e==="arrowup"?"arrowup":e==="arrowdown"?"arrowdown":e==="arrowleft"?"arrowleft":e==="arrowright"?"arrowright":ow[e]??e}const e8=[{id:"open_command_palette",defaultCombo:"mod+k",label:"Open command palette",description:"Open the command palette",customizable:!0},{id:"focus_input",defaultCombo:"mod+i",label:"Focus input",description:"Focus the chat input field",customizable:!0},{id:"open_status",defaultCombo:"mod+shift+o",label:"Open OpenCode status",description:"Open the OpenCode status dialog"},{id:"open_settings",defaultCombo:"mod+comma",label:"Open settings",description:"Open the settings panel",customizable:!0},{id:"toggle_terminal",defaultCombo:"mod+j",label:"Toggle terminal dock",description:"Toggle the bottom terminal dock",customizable:!0},{id:"toggle_terminal_expanded",defaultCombo:"mod+shift+j",label:"Toggle terminal expanded",description:"Toggle terminal expanded or collapsed",customizable:!0},{id:"toggle_files",defaultCombo:"mod+shift+f",label:"Toggle files",description:"Toggle the files panel"},{id:"toggle_sidebar",defaultCombo:"mod+l",label:"Toggle sidebar",description:"Toggle the session sidebar",customizable:!0},{id:"toggle_right_sidebar",defaultCombo:"mod+b",label:"Toggle right sidebar",description:"Toggle the right sidebar",customizable:!0},{id:"open_right_sidebar_git",defaultCombo:"mod+shift+g",label:"Open right sidebar Git tab",description:"Open right sidebar and select Git",customizable:!0},{id:"open_right_sidebar_files",defaultCombo:"mod+shift+f",label:"Open right sidebar Files tab",description:"Open right sidebar and select Files",customizable:!0},{id:"cycle_right_sidebar_tab",defaultCombo:"mod+shift+]",label:"Cycle right sidebar tab",description:"Cycle through right sidebar tabs",customizable:!0},{id:"new_chat",defaultCombo:"mod+n",label:"New session",description:"Start a new session",customizable:!0},{id:"new_chat_worktree",defaultCombo:"mod+shift+n",label:"New worktree draft",description:"Create a new worktree and open a draft in it",customizable:!0},{id:"submit_message",defaultCombo:"mod+enter",label:"Submit message",description:"Submit the current message"},{id:"clear_input",defaultCombo:"escape",label:"Clear input",description:"Clear the input field"},{id:"open_diff_panel",defaultCombo:"mod+2",label:"Open diff panel",description:"Switch to the diff panel"},{id:"open_terminal_panel",defaultCombo:"mod+3",label:"Open terminal panel",description:"Switch to the terminal panel"},{id:"open_git_panel",defaultCombo:"mod+4",label:"Open git panel",description:"Switch to the git panel"},{id:"open_timeline",defaultCombo:"mod+t",label:"Open timeline",description:"Open the timeline dialog",customizable:!0},{id:"open_help",defaultCombo:"mod+.",label:"Open keyboard shortcuts",description:"Show the keyboard shortcuts help",customizable:!0},{id:"toggle_context_plan",defaultCombo:"mod+shift+p",label:"Toggle plan context panel",description:"Open or close plan in the context panel",customizable:!0},{id:"toggle_services_menu",defaultCombo:"mod+shift+s",label:"Toggle services menu",description:"Open or close the services menu",customizable:!0},{id:"cycle_services_tab",defaultCombo:"mod+shift+[",label:"Cycle services tab",description:"Cycle through tabs in the services menu",customizable:!0},{id:"cycle_theme",defaultCombo:"mod+/",label:"Cycle theme",description:"Cycle between light, dark, and system theme",customizable:!0},{id:"open_model_selector",defaultCombo:"mod+shift+m",label:"Open model selector",description:"Open model selector while in chat"},{id:"cycle_thinking_variant",defaultCombo:"mod+shift+t",label:"Cycle thinking variant",description:"Cycle thinking variant while in chat"},{id:"cycle_favorite_model_forward",defaultCombo:"ctrl+]",label:"Cycle favorite model forward",description:"Cycle forward through starred models without opening the picker",customizable:!0},{id:"cycle_favorite_model_backward",defaultCombo:"ctrl+[",label:"Cycle favorite model backward",description:"Cycle backward through starred models without opening the picker",customizable:!0},{id:"expand_input",defaultCombo:"mod+shift+e",label:"Expand input",description:"Toggle focus mode for the chat input",customizable:!0},{id:"abort_run",defaultCombo:"escape",label:"Abort active run",description:"Abort the currently running task (double press)"},{id:"switch_tab_1",defaultCombo:"mod+1",label:"Switch to tab 1",description:"Switch to the first tab or project"},{id:"switch_tab_2",defaultCombo:"mod+2",label:"Switch to tab 2",description:"Switch to the second tab or project"},{id:"switch_tab_3",defaultCombo:"mod+3",label:"Switch to tab 3",description:"Switch to the third tab or project"},{id:"switch_tab_4",defaultCombo:"mod+4",label:"Switch to tab 4",description:"Switch to the fourth tab or project"},{id:"switch_tab_5",defaultCombo:"mod+5",label:"Switch to tab 5",description:"Switch to the fifth tab or project"},{id:"switch_tab_6",defaultCombo:"mod+6",label:"Switch to tab 6",description:"Switch to the sixth tab or project"},{id:"switch_tab_7",defaultCombo:"mod+7",label:"Switch to tab 7",description:"Switch to the seventh tab or project"},{id:"switch_tab_8",defaultCombo:"mod+8",label:"Switch to tab 8",description:"Switch to the eighth tab or project"},{id:"switch_tab_9",defaultCombo:"mod+9",label:"Switch to tab 9",description:"Switch to the ninth tab or project"}];function Ra(t){if(Li(t))return kl;const e=t.toLowerCase().trim().split("+").map(a=>a.trim()).filter(Boolean),n=new Set;let r="";for(const a of e){const l=a===","?"comma":a==="."?"period":a,i=Q6[l];if(i){n.add(i);continue}r=l}return[...J6.filter(a=>n.has(a)),r].filter(Boolean).join("+")}function aw(t){return Li(t)?!0:Y2(t).key.trim().length>0}function Y2(t){if(Li(t))return{modifiers:new Set,key:kl};const n=Ra(t).split("+"),r=new Set;let o="";for(const a of n){const l=Q6[a];l?r.add(l):o=a}return{modifiers:r,key:o}}function X2(t){if(Li(t))return"Unassigned";const e=Y2(t);if(!e.key&&e.modifiers.size===0)return"Unassigned";const n=[];for(const r of J6)e.modifiers.has(r)&&n.push(nw[r]);if(e.key){const r=rw[e.key.toLowerCase()]||e.key.toUpperCase();n.push(r)}return n.join(" + ")}function t8(t){return e8.find(e=>e.id===t)}function lw(){return e8.filter(t=>t.customizable===!0)}function ha(t,e){const n=t8(t);if(!n)return"";const r=e?.[t];if(typeof r=="string"){if(r.trim().toLowerCase()===kl)return"";const o=Ra(r);if(o===kl)return kl;if(aw(o))return o}return n.defaultCombo}function e4(t){if(Li(t))return!1;const e=Y2(t);if(!e.modifiers.has("mod"))return!1;const n=e.key.toLowerCase();return new Set(["w","t","r","p","s","f","l","n"]).has(n)&&!e.modifiers.has("shift")&&!e.modifiers.has("alt")}function Gn(t,e){const n=typeof e=="string"?e:e.defaultCombo;if(Li(n))return!1;const r=Y2(n),o=r.modifiers.has("mod"),a=r.modifiers.has("shift"),l=r.modifiers.has("alt"),i=r.modifiers.has("ctrl"),c=_1()&&_n(),u=_1(),m=c?t.metaKey:u&&t.metaKey||t.ctrlKey;if(o&&!m||!o&&t.metaKey||a!==t.shiftKey||l!==t.altKey)return!1;if(i){if(!t.ctrlKey)return!1}else{const p=o&&!c&&t.ctrlKey;if(t.ctrlKey&&!p)return!1}const f=Id(t.key),h=Id(r.key);return f===h}function iw(){return _1()&&_n()?"⌘":"Ctrl"}const Jr=Rg,vo=t=>{const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(Lg,{className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a},eo=t=>{const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("overflow-hidden data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(zg,{className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a};let m1=0;function Os(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Hg,{"data-slot":"dialog",...n}),e[2]=n,e[3]=r):r=e[3],r}function cw(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Ug,{"data-slot":"dialog-portal",...n}),e[2]=n,e[3]=r):r=e[3],r}const s8=he.forwardRef((t,e)=>{const n=Fe.c(10);let r,o;n[0]!==t?({className:r,...o}=t,n[0]=t,n[1]=r,n[2]=o):(r=n[1],o=n[2]);let a;n[3]===Symbol.for("react.memo_cache_sentinel")?(a=[],n[3]=a):a=n[3],he.useEffect(uw,a);let l;n[4]!==r?(l=Q("fixed inset-0 z-50 bg-black/50 backdrop-blur-md",r),n[4]=r,n[5]=l):l=n[5];let i;return n[6]!==o||n[7]!==e||n[8]!==l?(i=s.jsx(Ah,{ref:e,"data-slot":"dialog-overlay","data-blur-bg":!0,className:l,...o}),n[6]=o,n[7]=e,n[8]=l,n[9]=i):i=n[9],i});s8.displayName=Ah.displayName;function Vs(t){const e=Fe.c(17);let n,r,o,a,l;e[0]!==t?({className:r,children:n,showCloseButton:a,keyboardAvoid:l,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a,e[5]=l):(n=e[1],r=e[2],o=e[3],a=e[4],l=e[5]);const i=a===void 0?!0:a,c=l===void 0?!1:l;let u;e[6]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(s8,{className:"rounded-none"}),e[6]=u):u=e[6];const m=c?"true":void 0;let f;e[7]!==r?(f=Q("bg-background text-foreground fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 rounded-xl border p-6 shadow-none overflow-hidden pwa-dialog-content",r),e[7]=r,e[8]=f):f=e[8];let h;e[9]!==i?(h=i&&s.jsxs(Wg,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-interactive-active data-[state=open]:text-foreground absolute top-2 right-2 rounded-lg opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none text-muted-foreground hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[s.jsx(Ps,{}),s.jsx("span",{className:"sr-only",children:"Close"})]}),e[9]=i,e[10]=h):h=e[10];let p;return e[11]!==n||e[12]!==o||e[13]!==m||e[14]!==f||e[15]!==h?(p=s.jsxs(cw,{"data-slot":"dialog-portal",children:[u,s.jsxs($g,{"data-slot":"dialog-content","data-keyboard-avoid":m,className:f,...o,children:[n,h]})]}),e[11]=n,e[12]=o,e[13]=m,e[14]=f,e[15]=h,e[16]=p):p=e[16],p}function Zs(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("flex flex-col gap-2 text-center sm:text-left",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx("div",{"data-slot":"dialog-header",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function yn(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("flex flex-col-reverse gap-2 bottom-safe-area sm:flex-row sm:justify-end",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx("div",{"data-slot":"dialog-footer",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function Us(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("typography-markdown leading-none font-semibold text-foreground",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(Og,{"data-slot":"dialog-title",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function sn(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("text-muted-foreground typography-ui-label",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(Vg,{"data-slot":"dialog-description",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function dw(){m1=Math.max(0,m1-1),m1===0&&document.documentElement.classList.remove("oc-dialog-open")}function uw(){return m1=m1+1,document.documentElement.classList.add("oc-dialog-open"),dw}function Xt(t){const e=Fe.c(10);let n,r,o;e[0]!==t?({className:n,type:o,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o):(n=e[1],r=e[2],o=e[3]);let a;e[4]!==n?(a=Q("text-foreground border border-border/80 file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 appearance-none flex h-9 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 typography-markdown outline-none focus-visible:outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:typography-ui-label file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:typography-ui-label","hover:border-input","focus:ring-1 focus:ring-primary/50 focus:border-primary/70","aria-invalid:border-destructive aria-invalid:ring-destructive",n),e[4]=n,e[5]=a):a=e[5];let l;return e[6]!==r||e[7]!==a||e[8]!==o?(l=s.jsx("input",{type:o,"data-slot":"input",className:a,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",...r}),e[6]=r,e[7]=a,e[8]=o,e[9]=l):l=e[9],l}const fw=qg("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg typography-ui-label font-medium lowercase transition-[background-color,border-color,color,box-shadow,opacity] duration-150 ease-in-out disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"border bg-[var(--primary-base)]/10 text-[var(--primary-base)] shadow-none hover:bg-[var(--primary-base)]/15 hover:text-[var(--primary-base)]",destructive:"bg-[var(--status-error)]/8 text-[var(--status-error)] shadow-none hover:bg-[var(--status-error)]/12 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40",outline:"border bg-[var(--surface-elevated)] shadow-none hover:bg-interactive-hover hover:text-foreground",secondary:"bg-interactive-hover text-foreground shadow-none hover:bg-interactive-active",ghost:"text-foreground hover:bg-interactive-hover hover:text-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-lg gap-1.5 px-3 has-[>svg]:px-2.5",xs:"h-6 rounded-lg gap-1 px-1.5 typography-micro has-[>svg]:px-1.5",lg:"h-10 rounded-lg px-6 has-[>svg]:px-4",icon:"size-9"}},defaultVariants:{variant:"default",size:"default"}});function Be(t){const e=Fe.c(14);let n,r,o,a,l;e[0]!==t?({className:n,variant:l,size:o,asChild:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a,e[5]=l):(n=e[1],r=e[2],o=e[3],a=e[4],l=e[5]);const c=(a===void 0?!1:a)?Mh:"button";let u;e[6]!==n||e[7]!==o||e[8]!==l?(u=Q(fw({variant:l,size:o,className:n})),e[6]=n,e[7]=o,e[8]=l,e[9]=u):u=e[9];let m;return e[10]!==c||e[11]!==r||e[12]!==u?(m=s.jsx(c,{"data-slot":"button",className:u,...r}),e[10]=c,e[11]=r,e[12]=u,e[13]=m):m=e[13],m}const l0=t=>{const e=Fe.c(7);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];const{theme:r}=Gg(),a=r===void 0?"system":r;let l,i;e[2]===Symbol.for("react.memo_cache_sentinel")?(l={style:{borderRadius:"var(--radius-lg)",backdropFilter:"blur(28px)",WebkitBackdropFilter:"blur(28px)"},classNames:{toast:"rounded-[var(--radius-lg)]",actionButton:"rounded-[var(--radius-md)]",cancelButton:"rounded-[var(--radius-md)]",closeButton:"rounded-[var(--radius-md)]"}},i={"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)","--error-bg":"var(--popover)","--error-text":"var(--popover-foreground)","--error-border":"var(--border)","--success-bg":"var(--popover)","--success-text":"var(--popover-foreground)","--success-border":"var(--border)","--warning-bg":"var(--popover)","--warning-text":"var(--popover-foreground)","--warning-border":"var(--border)","--info-bg":"var(--popover)","--info-text":"var(--popover-foreground)","--info-border":"var(--border)"},e[2]=l,e[3]=i):(l=e[2],i=e[3]);let c;return e[4]!==n||e[5]!==a?(c=s.jsx(Zg,{theme:a,className:"toaster group",closeButton:!1,toastOptions:l,style:i,...n}),e[4]=n,e[5]=a,e[6]=c):c=e[6],c};async function Dn(t){let e=null;if(typeof navigator<"u"&&navigator.clipboard?.writeText)try{return await navigator.clipboard.writeText(t),{ok:!0,method:"clipboard"}}catch(n){e=n instanceof Error?n.message:String(n)}if(typeof document<"u"&&document.body){const n=document.createElement("textarea");n.value=t,n.setAttribute("readonly",""),n.style.position="fixed",n.style.top="-1000px",n.style.left="-1000px",document.body.appendChild(n),n.select(),n.setSelectionRange(0,n.value.length);const r=document.execCommand("copy");if(document.body.removeChild(n),r)return{ok:!0,method:"execCommand"}}return{ok:!1,error:e??"Clipboard access denied in current context"}}const t4=async t=>{const e=await Dn(t);e.ok||console.error("Failed to copy to clipboard:",e.error)},f2=t=>t==null||typeof t=="boolean"?"":typeof t=="string"||typeof t=="number"?String(t):Array.isArray(t)?t.map(f2).join(" ").trim():he.isValidElement(t)?f2(t.props?.children):"",mw=t=>typeof t=="function"?t():t,s4=(t,e)=>{const n=f2(mw(e?.description));return n.length>0?n:f2(t)},fe={...$i,success:(t,e)=>$i.success(t,{...e,action:e?.action||{label:"OK",onClick:()=>{}}}),info:(t,e)=>$i.info(t,{...e,action:e?.action||{label:"OK",onClick:()=>{}}}),error:(t,e)=>$i.error(t,{...e,action:e?.action||{label:"Copy",onClick:()=>t4(s4(t,e))}}),warning:(t,e)=>$i.warning(t,{...e,action:e?.action||{label:"Copy",onClick:()=>t4(s4(t,e))}})},hw=/token|auth|secret|api/i,_r=t=>{const e=t.trim();if(!e)return null;try{const n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?null:e.split("#")[0]||null}catch{return null}},Br=t=>{const e=_r(t);if(!e)return t;try{const n=new URL(e),r=Array.from(new Set(Array.from(n.searchParams.keys())));for(const o of r)hw.test(o)&&n.searchParams.set(o,"[REDACTED]");return n.toString()}catch{return e}},Ci=(t,e)=>{const n=_r(t),r=_r(e);if(!n||!r)return!1;try{const o=new URL(n),a=new URL(r);if(o.origin!==a.origin||a.search&&o.search!==a.search)return!1;const l=a.pathname.length>1?a.pathname.replace(/\/+$/,""):a.pathname,i=o.pathname.length>1?o.pathname.replace(/\/+$/,""):o.pathname;return l==="/"?!0:i===l||i.startsWith(`${l}/`)}catch{return!1}},Ou=t=>typeof t=="object"&&t!==null,gi=(t,e)=>{const n=t[e];return typeof n=="string"?n:null},n4=(t,e)=>{const n=t[e];return typeof n=="number"&&Number.isFinite(n)?n:null},pw=t=>{if(!Ou(t))return null;const e=gi(t,"id"),n=gi(t,"label"),r=gi(t,"url");return!e||!n||!r?null:{id:e,label:n,url:r}},Q2=()=>{if(!_n())return null;const t=window.__TAURI__;return typeof t?.core?.invoke=="function"?t.core.invoke:null},Vu=async()=>{const t=Q2();if(!t)return{hosts:[],defaultHostId:"local"};const e=await t("desktop_hosts_get");if(!Ou(e))return{hosts:[],defaultHostId:null};const n=e.hosts,r=Array.isArray(n)?n.map(pw).filter(a=>!!a):[],o=gi(e,"defaultHostId")||gi(e,"default_host_id")||gi(e,"defaultHostID");return{hosts:r,defaultHostId:o}},gw=async t=>{const e=Q2();e&&await e("desktop_hosts_set",{config:{hosts:t.hosts,defaultHostId:t.defaultHostId}})},r4=async t=>{const e=Q2();if(!e)return{status:"unreachable",latencyMs:0};const n=await e("desktop_host_probe",{url:t});if(!Ou(n))return{status:"unreachable",latencyMs:0};const r=n.status,o=r==="ok"||r==="auth"||r==="unreachable"?r:"unreachable",a=n4(n,"latencyMs")??n4(n,"latency_ms")??0;return{status:o,latencyMs:a}},xw=async t=>{const e=Q2();e&&await e("desktop_new_window_at_url",{url:t})},ho=t=>typeof t=="object"&&t!==null,Cn=(t,e)=>{const n=t[e];return typeof n=="string"?n:null},tr=(t,e)=>{const n=t[e];return typeof n=="number"&&Number.isFinite(n)?n:null},Do=(t,e)=>{const n=t[e];return typeof n=="boolean"?n:null},bw=t=>Array.isArray(t)?t.filter(e=>typeof e=="string"):[],Ja=()=>{if(!_n())return null;const t=window.__TAURI__;return typeof t?.core?.invoke=="function"?t.core.invoke:null},o4=t=>{if(!ho(t))return;const e=Do(t,"enabled")??!1,r=Cn(t,"store")?.toLowerCase()==="settings"?"settings":"never",o=Cn(t,"value");return{enabled:e,store:r,...o?{value:o}:{}}},vw=t=>t==="remote"||t==="dynamic"?t:"local",yw=t=>{if(!ho(t))return null;const e=Cn(t,"id");if(!e)return null;const n=Do(t,"enabled")??!0,r=vw(Cn(t,"type")),o=Cn(t,"localHost")||Cn(t,"local_host")||void 0,a=tr(t,"localPort")??tr(t,"local_port")??void 0,l=Cn(t,"remoteHost")||Cn(t,"remote_host")||void 0,i=tr(t,"remotePort")??tr(t,"remote_port")??void 0;return{id:e,enabled:n,type:r,...o?{localHost:o}:{},...typeof a=="number"?{localPort:a}:{},...l?{remoteHost:l}:{},...typeof i=="number"?{remotePort:i}:{}}},ww=t=>{if(!ho(t))return null;const e=Cn(t,"id"),n=Cn(t,"sshCommand")||Cn(t,"ssh_command");if(!e||!n)return null;const r=Cn(t,"nickname"),o=t.sshParsed,a=ho(o)?{destination:Cn(o,"destination")||"",args:bw(o.args)}:void 0,l=ho(t.remoteOpenchamber)?t.remoteOpenchamber:ho(t.remote_openchamber)?t.remote_openchamber:{},i=ho(t.localForward)?t.localForward:ho(t.local_forward)?t.local_forward:{},c=ho(t.auth)?t.auth:{},m=Cn(l,"mode")?.toLowerCase()==="external"?"external":"managed",f=Cn(l,"installMethod")||Cn(l,"install_method"),h=f==="npm"||f==="download_release"||f==="upload_bundle"?f:"bun",p=Cn(i,"bindHost")||Cn(i,"bind_host")||"127.0.0.1",g=p==="localhost"||p==="0.0.0.0"?p:"127.0.0.1",b=(Array.isArray(t.portForwards)?t.portForwards:Array.isArray(t.port_forwards)?t.port_forwards:[]).map(N=>yw(N)).filter(N=>!!N),v=tr(l,"preferredPort")??tr(l,"preferred_port"),y=tr(i,"preferredLocalPort")??tr(i,"preferred_local_port"),w=o4(c.sshPassword||c.ssh_password),C=o4(c.openchamberPassword||c.openchamber_password);return{id:e,...r?{nickname:r}:{},sshCommand:n,...a&&a.destination?{sshParsed:a}:{},connectionTimeoutSec:tr(t,"connectionTimeoutSec")??tr(t,"connection_timeout_sec")??60,remoteOpenchamber:{mode:m,keepRunning:Do(l,"keepRunning")??Do(l,"keep_running")??!0,...v?{preferredPort:v}:{},installMethod:h,uploadBundleOverSsh:Do(l,"uploadBundleOverSsh")??Do(l,"upload_bundle_over_ssh")??!1},localForward:{...y?{preferredLocalPort:y}:{},bindHost:g},auth:{...w?{sshPassword:w}:{},...C?{openchamberPassword:C}:{}},portForwards:b}},jw=t=>{switch(t){case"config_resolved":case"auth_check":case"master_connecting":case"remote_probe":case"installing":case"updating":case"server_detecting":case"server_starting":case"forwarding":case"ready":case"degraded":case"error":return t;default:return"idle"}},n8=t=>{if(!ho(t))return null;const e=Cn(t,"id");return e?{id:e,phase:jw(Cn(t,"phase")),...Cn(t,"detail")?{detail:Cn(t,"detail")||void 0}:{},...Cn(t,"localUrl")||Cn(t,"local_url")?{localUrl:Cn(t,"localUrl")||Cn(t,"local_url")||void 0}:{},...typeof(tr(t,"localPort")??tr(t,"local_port"))=="number"?{localPort:tr(t,"localPort")??tr(t,"local_port")??void 0}:{},...typeof(tr(t,"remotePort")??tr(t,"remote_port"))=="number"?{remotePort:tr(t,"remotePort")??tr(t,"remote_port")??void 0}:{},startedByUs:Do(t,"startedByUs")??Do(t,"started_by_us")??!1,retryAttempt:tr(t,"retryAttempt")??tr(t,"retry_attempt")??0,requiresUserAction:Do(t,"requiresUserAction")??Do(t,"requires_user_action")??!1,updatedAtMs:tr(t,"updatedAtMs")??tr(t,"updated_at_ms")??Date.now()}:null},kw=t=>{if(!ho(t))return null;const e=Cn(t,"host"),n=Cn(t,"source"),r=Cn(t,"sshCommand")||Cn(t,"ssh_command");return!e||!n||!r?null:{host:e,source:n,sshCommand:r,pattern:Do(t,"pattern")??!1}},Nw=(t,e)=>({id:t,sshCommand:e,connectionTimeoutSec:60,remoteOpenchamber:{mode:"managed",keepRunning:!0,installMethod:"bun",uploadBundleOverSsh:!1},localForward:{bindHost:"127.0.0.1"},auth:{},portForwards:[]}),r8=async()=>{const t=Ja();if(!t)return{instances:[]};const e=await t("desktop_ssh_instances_get");return ho(e)?{instances:(Array.isArray(e.instances)?e.instances:Array.isArray(e.desktopSshInstances)?e.desktopSshInstances:[]).map(o=>ww(o)).filter(o=>!!o)}:{instances:[]}},Sw=async t=>{const e=Ja();e&&await e("desktop_ssh_instances_set",{config:{instances:t.instances}})},Cw=async()=>{const t=Ja();if(!t)return[];const e=await t("desktop_ssh_import_hosts");return Array.isArray(e)?e.map(n=>kw(n)).filter(n=>!!n):[]},Td=async t=>{const e=Ja();e&&await e("desktop_ssh_connect",{id:t})},Pd=async t=>{const e=Ja();e&&await e("desktop_ssh_disconnect",{id:t})},I1=async t=>{const e=Ja();if(!e)return[];const n=await e("desktop_ssh_status",{...t?{id:t}:{}});return Array.isArray(n)?n.map(r=>n8(r)).filter(r=>!!r):[]},Aw=async(t,e)=>{const n=Ja();if(!n)return[];const r=await n("desktop_ssh_logs",{id:t,limit:e});return Array.isArray(r)?r.filter(o=>typeof o=="string"):[]},Mw=async t=>{const e=Ja();e&&await e("desktop_ssh_logs_clear",{id:t})},Fw=async t=>{if(!_n())return async()=>{};const n=window.__TAURI__?.event?.listen;if(typeof n!="function")return async()=>{};const r=await n("archcoder:ssh-instance-status",o=>{const a=n8(o?.payload);a&&t(a)});return async()=>{await r()}},kr="local",a4=9e4,m2="SSH connection cancelled",Wi=t=>{const e=_r(t);if(!e)return t.trim();try{const n=new URL(e);return n.pathname.endsWith("/")||(n.pathname=`${n.pathname}/`),n.toString()}catch{return e}},fi=()=>typeof window>"u"?"":window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,Bw=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,_w=t=>t==="ok"?"bg-status-success":t==="auth"?"bg-status-warning":t==="unreachable"?"bg-status-error":"bg-muted-foreground/40",Ew=t=>t==="ok"?"Connected":t==="auth"?"Auth required":t==="unreachable"?"Unreachable":"Unknown",Dw=t=>t==="ok"?s.jsx(js,{className:"h-4 w-4"}):t==="auth"?s.jsx(Bh,{className:"h-4 w-4"}):t==="unreachable"?s.jsx(Kg,{className:"h-4 w-4"}):s.jsx(Yg,{className:"h-4 w-4"}),Iw=t=>new Promise(e=>window.setTimeout(e,t)),l4=t=>{switch(t){case"ready":return"Ready";case"error":return"Error";case"degraded":return"Reconnecting";case"config_resolved":return"Resolving config";case"auth_check":return"Checking auth";case"master_connecting":return"Connecting SSH";case"remote_probe":return"Probing remote";case"installing":return"Installing";case"updating":return"Updating";case"server_detecting":return"Detecting server";case"server_starting":return"Starting server";case"forwarding":return"Forwarding ports";default:return"Idle"}},Tw=t=>!t||t==="idle"?null:t==="ready"?"ok":t==="error"?"unreachable":"auth",i4=async()=>{const t=await I1().catch(()=>[]),e={};for(const n of t)e[n.id]=n;return e},c4=async(t,e,n,r)=>{const o=Date.now()+e;for(;Date.now()<o;){if(r?.())throw new Error(m2);const l=(await I1(t).catch(()=>[])).find(i=>i.id===t);if(l){if(n(l),l.phase==="ready")return l;if(l.phase==="error")throw new Error(l.detail||"SSH connection failed")}await Iw(700)}throw r?.()?new Error(m2):new Error("Timed out waiting for SSH connection")},Pw=()=>({id:kr,label:"Local",url:fi()}),Rw=t=>{const e=typeof window>"u"?"":window.location.href,n=fi(),r=_r(n)||n,o=_r(e)||e;if(e&&Ci(e,n))return{id:kr,label:"Local",url:r};const a=t.find(l=>e?Ci(e,l.url):!1);return a?{id:a.id,label:a.label,url:_r(a.url)||a.url}:{id:"custom",label:Br(o||"Instance"),url:o}};function o8({open:t,onOpenChange:e,embedded:n=!1,onHostSwitched:r}){const o=Ee(Z=>Z.setSettingsDialogOpen),a=Ee(Z=>Z.setSettingsPage),[l,i]=he.useState([]),[c,u]=he.useState(null),[m,f]=he.useState({}),[h,p]=he.useState(!1),[g,x]=he.useState(!1),[b,v]=he.useState(!1),[y,w]=he.useState(null),[C,N]=he.useState({}),[S,k]=he.useState({}),[j,F]=he.useState({open:!1,hostId:null,hostLabel:"",phase:"idle",detail:null,error:null}),[A,M]=he.useState(""),[B,E]=he.useState(null),[I,P]=he.useState(""),[D,L]=he.useState(""),[T,_]=he.useState(""),[z,R]=he.useState(""),[W,G]=he.useState(!n),Y=he.useRef(0),J=he.useMemo(()=>{const Z=Pw(),ie=l.map(pe=>({...pe,url:_r(pe.url)||pe.url}));return[Z,...ie]},[l]),V=he.useMemo(()=>Rw(J),[J]),te=he.useMemo(()=>{const Z=c||kr;return J.find(ie=>ie.id===Z)?.label||"Local"},[J,c]),U=he.useCallback(async(Z,ie)=>{if(_n()){v(!0),M("");try{const pe=Z.filter(me=>me.id!==kr);await gw({hosts:pe,defaultHostId:ie}),i(pe),u(ie)}catch(pe){M(pe instanceof Error?pe.message:"Failed to save")}finally{v(!1)}}},[]),X=he.useCallback(()=>{a("remote-instances"),o(!0),e(!1)},[e,o,a]),$=he.useCallback(async()=>{if(_n()){p(!0),M("");try{const[Z,ie,pe]=await Promise.all([Vu(),r8().catch(()=>({instances:[]})),i4()]),me={};for(const Se of ie.instances)me[Se.id]=!0;i(Z.hosts||[]),u(Z.defaultHostId??null),N(me),k(pe)}catch(Z){M(Z instanceof Error?Z.message:"Failed to load"),i([]),u(null),N({}),k({})}finally{p(!1)}}},[]),q=he.useCallback(async Z=>{if(_n()){x(!0);try{const ie=await Promise.all(Z.map(async me=>{const Se=_r(me.url);if(!Se)return[me.id,{status:"unreachable",latencyMs:0}];const ke=await r4(Se).catch(()=>({status:"unreachable",latencyMs:0}));return[me.id,{status:ke.status,latencyMs:ke.latencyMs}]})),pe={};for(const[me,Se]of ie)pe[me]=Se;f(pe)}finally{x(!1)}}},[]);he.useEffect(()=>{if(!t){E(null),P(""),L(""),_(""),R(""),G(!n),w(null),F({open:!1,hostId:null,hostLabel:"",phase:"idle",detail:null,error:null}),M("");return}$()},[n,t,$]),he.useEffect(()=>{t&&q(J)},[t,J,q]),he.useEffect(()=>{if(!t||!_n())return;let Z=!1;const ie=async()=>{const me=await i4();Z||k(me)};ie();const pe=window.setInterval(()=>{ie()},1500);return()=>{Z=!0,window.clearInterval(pe)}},[t]);const ee=he.useCallback(async Z=>{const ie=Z.id===kr?fi():_r(Z.url)||"";if(!ie)return;const pe=!!C[Z.id];if(Z.id!==kr&&pe&&_n()){let Se=S[Z.id];const ke=await I1(Z.id).then(_e=>_e.find(de=>de.id===Z.id)||null).catch(()=>null);ke&&(Se=ke,k(_e=>({..._e,[Z.id]:ke})));const ye=_r(Se?.localUrl||Z.url||"");if(Se?.phase==="ready"&&ye){const _e=Wi(ye);r?.(),window.location.assign(_e);return}w(Z.id);const Ne=Y.current+1;Y.current=Ne,F({open:!0,hostId:Z.id,hostLabel:Br(Z.label),phase:"master_connecting",detail:null,error:null});try{if(await Td(Z.id),Ne!==Y.current)return;const _e=await c4(Z.id,a4,je=>{k(Ce=>({...Ce,[je.id]:je})),F(Ce=>({...Ce,phase:je.phase,detail:je.detail||null}))},()=>Ne!==Y.current);if(Ne!==Y.current)return;const de=_r(_e.localUrl||"")||ie,we=Wi(de);r?.(),window.location.assign(we);return}catch(_e){if(Ne!==Y.current)return;const de=_e instanceof Error?_e.message:String(_e);if(de===m2)return;F(we=>({...we,error:de})),fe.error(`SSH instance "${Br(Z.label)}" failed to connect`,{description:de});return}finally{Ne===Y.current&&w(null)}}if(Z.id!==kr&&_n()){w(Z.id);const Se=await r4(ie).catch(()=>({status:"unreachable",latencyMs:0}));if(f(ke=>({...ke,[Z.id]:{status:Se.status,latencyMs:Se.latencyMs}})),Se.status==="unreachable"){fe.error(`Instance "${Br(Z.label)}" is unreachable`),w(null);return}}const me=Wi(ie);r?.();try{window.location.assign(me)}catch{window.location.href=me}},[r,C,S]),ce=he.useCallback(Z=>{E(Z.id),P(Z.label),L(Z.url),M("")},[]),ve=he.useCallback(()=>{E(null),P(""),L("")},[]),ge=he.useCallback(async()=>{if(!B)return;if(B===kr){ve();return}const Z=_r(D);if(!Z){M("Invalid URL (must be http/https)");return}const ie=(I||Br(Z)).trim(),pe=l.map(me=>me.id===B?{...me,label:ie,url:Z}:me);await U(pe,c),ve()},[ve,l,c,I,D,B,U]),xe=he.useCallback(async()=>{const Z=_r(z);if(!Z){M("Invalid URL (must be http/https)");return}const ie=(T||Br(Z)).trim(),me=[{id:Bw(),label:ie,url:Z},...l];await U(me,c),_(""),R(""),n&&G(!1)},[l,c,n,T,z,U]),ne=he.useCallback(async Z=>{if(Z===kr)return;const ie=l.filter(me=>me.id!==Z);await U(ie,c===Z?kr:c)},[l,c,U]),O=he.useCallback(async Z=>{await U(l,Z===kr?kr:Z)},[l,U]),H=he.useCallback(Z=>{const ie=Z.id===kr?fi():_r(Z.url)||"";if(!ie)return;const pe=Wi(ie);xw(pe).catch(me=>{fe.error("Failed to open new window",{description:me instanceof Error?me.message:String(me)})})},[]),K=he.useCallback(()=>{Y.current+=1,w(null),F(ie=>({...ie,open:!1,hostId:null,error:null,detail:null,phase:"idle"}));const Z=Wi(fi());r?.(),window.location.assign(Z)},[r]),re=he.useCallback(async()=>{const Z=j.hostId||y;Y.current+=1,w(null),F({open:!1,hostId:null,hostLabel:"",phase:"idle",detail:null,error:null}),!(!Z||Z===kr||!_n())&&await Pd(Z).catch(()=>{})},[j.hostId,y]),le=he.useCallback(()=>{const Z=j.hostId;if(!Z)return;const ie=J.find(pe=>pe.id===Z);ie&&ee(ie)},[J,ee,j.hostId]),ae=he.useCallback(async Z=>{if(_n()){w(Z.id);try{await Td(Z.id),(await c4(Z.id,a4,pe=>{k(me=>({...me,[pe.id]:pe}))})).phase==="ready"&&fe.success(`SSH instance "${Br(Z.label)}" connected`)}catch(ie){const pe=ie instanceof Error?ie.message:String(ie);pe!==m2&&fe.error(`SSH instance "${Br(Z.label)}" failed to connect`,{description:pe})}finally{w(null)}}},[]);if(!Rn())return null;const ue=_n(),be=s.jsxs(s.Fragment,{children:[n?s.jsx("div",{className:"flex-shrink-0 border-b border-[var(--interactive-border)] px-3 py-2",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-1.5 typography-ui-label",children:[s.jsx("span",{className:"font-medium text-foreground",children:"Current"}),s.jsx("span",{className:"max-w-[9rem] truncate text-muted-foreground",children:Br(V.label)}),s.jsx("span",{className:"text-muted-foreground/50",children:"•"}),s.jsx("span",{className:"font-medium text-foreground",children:"Default"}),s.jsx("span",{className:"max-w-[9rem] truncate text-muted-foreground",children:Br(te)})]}),s.jsx("button",{type:"button",className:Q("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:()=>{q(J)},disabled:!ue||h||g,"aria-label":"Refresh instances",children:s.jsx(Qn,{className:Q("h-4 w-4",g&&"animate-spin")})})]})}):s.jsxs(Zs,{className:"flex-shrink-0",children:[s.jsxs(Us,{className:"flex items-center gap-2",children:[s.jsx(Cl,{className:"h-5 w-5"}),"Instance"]}),s.jsx(sn,{children:"Switch between Local and remote ArchCoder servers"})]}),!n&&s.jsxs("div",{className:"flex items-center justify-between gap-2 flex-shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Current:"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Br(V.label)}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:"Current default:"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Br(te)})]}),s.jsx("div",{className:"flex items-center gap-1",children:s.jsxs(Be,{type:"button",size:"sm",variant:"ghost",onClick:()=>{q(J)},disabled:!ue||h||g,children:[s.jsx(Qn,{className:Q("h-4 w-4",g&&"animate-spin")}),"Refresh"]})})]}),ue&&s.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between gap-2 px-2.5 py-1.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["Need SSH instances?",s.jsx("br",{}),"Manage them in Settings."]}),s.jsxs(Be,{type:"button",variant:"ghost",size:"sm",onClick:X,children:[s.jsx(xa,{className:"h-4 w-4"}),"Remote SSH"]})]}),!ue&&s.jsx("div",{className:"flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:"Instance switcher is limited on this page. Use Local to recover."})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:s.jsx("div",{className:"space-y-1",children:h?s.jsx("div",{className:"px-2 py-2 text-muted-foreground text-sm",children:"Loading…"}):J.map(Z=>{const ie=Z.id===kr,pe=!!C[Z.id],me=Z.id===V.id,Se=(c||kr)===Z.id,ke=m[Z.id]||null,ye=S[Z.id]||null,Ne=pe?Tw(ye?.phase):ke?.status??null,_e=B===Z.id,de=ie?fi():_r(Z.url)||Z.url,we=Br(Z.label),je=Br(de);return s.jsxs("div",{className:Q("group flex items-center gap-2 px-2.5 py-2 rounded-md overflow-hidden",_e?"bg-interactive-hover/20":"hover:bg-interactive-hover/30"),children:[s.jsxs("button",{type:"button",className:Q("flex items-center gap-2 flex-1 min-w-0 text-left",_e&&"pointer-events-none opacity-70"),onClick:()=>{ee(Z)},disabled:y===Z.id,"aria-label":`Switch to ${we}`,children:[s.jsx("span",{className:Q("h-2 w-2 rounded-full flex-shrink-0",_w(Ne))}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:Q("typography-ui-label truncate","text-foreground"),children:we}),pe&&s.jsx("span",{className:"typography-micro px-1 rounded leading-none pb-px text-[var(--status-info)] bg-[var(--status-info)]/10",children:"SSH"}),me&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:"Current"}),s.jsxs("span",{className:"inline-flex items-center gap-1 typography-micro text-muted-foreground",children:[Dw(Ne),s.jsxs("span",{children:[pe?l4(ye?.phase):Ew(ke?.status??null),!pe&&ke?.status==="ok"&&typeof ke.latencyMs=="number"?` · ${Math.max(0,Math.round(ke.latencyMs))}ms ping`:""]})]})]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate font-mono",children:je})]})]}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[!ie&&!pe&&s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:"h-8 w-8 rounded-md inline-flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-interactive-hover transition-colors","aria-label":"Instance actions",disabled:b,onClick:Ce=>Ce.stopPropagation(),children:s.jsx(Qr,{className:"h-4 w-4"})})}),s.jsxs(Ys,{align:"end",className:"w-fit min-w-28",children:[s.jsxs(Jt,{onClick:Ce=>{Ce.stopPropagation(),ce(Z)},disabled:b,children:[s.jsx(Fh,{className:"h-4 w-4 mr-1"}),"Edit"]}),s.jsxs(Jt,{onClick:Ce=>{Ce.stopPropagation(),ne(Z.id)},className:"text-destructive focus:text-destructive",disabled:b,children:[s.jsx(Pn,{className:"h-4 w-4 mr-1"}),"Delete"]})]})]}),ie&&s.jsx("div",{className:"h-8 w-8 opacity-0 pointer-events-none","aria-hidden":"true"}),pe&&!ie&&(ye?.phase==="idle"||!ye?.phase?s.jsxs(Be,{type:"button",variant:"outline",size:"sm",className:"h-8 px-2.5",disabled:y===Z.id,onClick:Ce=>{Ce.stopPropagation(),ae(Z)},children:[y===Z.id?s.jsx(ts,{className:"h-3.5 w-3.5 animate-spin"}):s.jsx(xu,{className:"h-3.5 w-3.5"}),"Connect"]}):s.jsx("div",{className:"h-8 w-8 opacity-0 pointer-events-none","aria-hidden":"true"})),s.jsxs(Dt,{delayDuration:700,children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:Q("h-8 w-8 rounded-md inline-flex items-center justify-center hover:bg-interactive-hover transition-colors",Se?"text-primary hover:text-primary/80":"text-muted-foreground/60 hover:text-primary/80"),onClick:()=>{O(Z.id)},"aria-label":Se?"Default instance":"Set as default",disabled:b,children:Se?s.jsx(Yo,{className:"h-4 w-4"}):s.jsx(bl,{className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:Se?"Default":"Set as default"})]}),s.jsxs(Dt,{delayDuration:700,children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:Q("h-8 w-8 rounded-md inline-flex items-center justify-center hover:bg-interactive-hover transition-colors",Ne==="unreachable"?"text-muted-foreground/30 cursor-not-allowed":"text-muted-foreground/60 hover:text-foreground"),onClick:Ce=>{Ce.stopPropagation(),H(Z)},disabled:Ne==="unreachable","aria-label":"Open in new window",children:s.jsx(I0,{className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:Ne==="unreachable"?"Instance unreachable":"Open in new window"})]})]})]},Z.id)})})}),ue&&B&&B!==kr&&s.jsxs("div",{className:"flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:"Edit instance"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{type:"button",variant:"outline",size:"sm",onClick:ve,disabled:b,children:"Cancel"}),s.jsxs(Be,{type:"button",size:"sm",onClick:()=>{ge()},disabled:b,children:[b?s.jsx(ts,{className:"h-4 w-4 animate-spin"}):null,"Save"]})]})]}),s.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[s.jsx(Xt,{value:I,onChange:Z=>P(Z.target.value),placeholder:"Label",disabled:b}),s.jsx(Xt,{value:D,onChange:Z=>L(Z.target.value),placeholder:"https://host:port",disabled:b})]})]}),n&&!W?s.jsx("div",{className:"flex-shrink-0 border-t border-[var(--interactive-border)]",children:s.jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-2 py-2 text-left text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors",onClick:()=>G(!0),disabled:!ue||b,children:[s.jsx(Qs,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label",children:"Add instance"})]})}):s.jsxs("div",{className:Q("flex-shrink-0",n?"border-t border-[var(--interactive-border)] px-2 py-2":"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-2.5"),children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:"Add instance"}),s.jsxs("div",{className:"flex items-center gap-2",children:[n&&s.jsx(Be,{type:"button",variant:"ghost",size:"sm",onClick:()=>G(!1),disabled:b,children:"Cancel"}),s.jsxs(Be,{type:"button",size:"sm",onClick:()=>{xe()},disabled:!ue||b||!z.trim(),children:[b?s.jsx(ts,{className:"h-4 w-4 animate-spin"}):null,"Add"]})]})]}),s.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[s.jsx(Xt,{value:T,onChange:Z=>_(Z.target.value),placeholder:"Label (optional)",disabled:!ue||b}),s.jsx(Xt,{value:z,onChange:Z=>R(Z.target.value),placeholder:"https://host:port",disabled:!ue||b})]})]}),A&&s.jsx("div",{className:"flex-shrink-0 typography-meta text-status-error",children:A})]}),oe=s.jsx(Os,{open:j.open,onOpenChange:Z=>{if(!Z&&y){re();return}F(ie=>({...ie,open:Z,...Z?{}:{hostId:null,error:null,detail:null,phase:"idle"}}))},children:s.jsxs(Vs,{className:"w-[min(28rem,calc(100vw-2rem))] max-w-none",children:[s.jsxs(Zs,{children:[s.jsxs(Us,{className:"flex items-center gap-2",children:[s.jsx(ts,{className:Q("h-4 w-4",!j.error&&"animate-spin")}),"Connecting to ",j.hostLabel||"SSH instance"]}),s.jsx(sn,{children:j.error?j.error:j.detail||l4(j.phase)})]}),j.error?s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(Be,{type:"button",size:"sm",variant:"outline",onClick:K,children:"Switch to Local"}),s.jsx(Be,{type:"button",size:"sm",onClick:le,disabled:!j.hostId,children:"Retry"})]}):null]})});return n?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"w-full max-h-[70vh] flex flex-col overflow-hidden gap-2",children:be}),oe]}):s.jsxs(s.Fragment,{children:[s.jsx(Os,{open:t,onOpenChange:e,children:s.jsx(Vs,{className:"w-[min(42rem,calc(100vw-2rem))] max-w-none max-h-[70vh] flex flex-col overflow-hidden gap-3",children:be})}),oe]})}function zw(){const t=Fe.c(3),[e,n]=he.useState(!1);if(!Rn())return null;let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs(Be,{type:"button",variant:"ghost",size:"sm","data-oc-host-switcher":!0,className:"w-full justify-center",onClick:()=>n(!0),children:[s.jsx(Cl,{className:"h-4 w-4"}),"Switch instance"]}),t[0]=r):r=t[0];let o;return t[1]!==e?(o=s.jsxs(s.Fragment,{children:[r,s.jsx(o8,{open:e,onOpenChange:n})]}),t[1]=e,t[2]=o):o=t[2],o}const Ha=[{id:"vscode",label:"VS Code",appName:"Visual Studio Code"},{id:"vscodium",label:"VSCodium",appName:"VSCodium"},{id:"cursor",label:"Cursor",appName:"Cursor"},{id:"windsurf",label:"Windsurf",appName:"Windsurf"},{id:"zed",label:"Zed",appName:"Zed",platforms:["macos","linux"]},{id:"intellij",label:"IntelliJ",appName:"IntelliJ IDEA"},{id:"pycharm",label:"PyCharm",appName:"PyCharm"},{id:"webstorm",label:"WebStorm",appName:"WebStorm"},{id:"rider",label:"Rider",appName:"Rider"},{id:"phpstorm",label:"PhpStorm",appName:"PhpStorm"},{id:"rustrover",label:"RustRover",appName:"RustRover"},{id:"android-studio",label:"Android Studio",appName:"Android Studio"},{id:"terminal",label:"Terminal",appName:"Terminal"},{id:"iterm2",label:"iTerm2",appName:"iTerm",platforms:["macos"]},{id:"ghostty",label:"Ghostty",appName:"Ghostty"},{id:"finder",label:"Finder",appName:"Finder",platforms:["macos"]},{id:"explorer",label:"Explorer",appName:"File Explorer",platforms:["windows"]},{id:"files",label:"Files",appName:"File Manager",platforms:["linux"]},{id:"visual-studio",label:"Visual Studio",appName:"Visual Studio",platforms:["windows"]},{id:"xcode",label:"Xcode",appName:"Xcode",platforms:["macos"]},{id:"sublime-text",label:"Sublime",appName:"Sublime Text"},{id:"eclipse",label:"Eclipse",appName:"Eclipse"},{id:"antigravity",label:"Antigravity",appName:"Antigravity"},{id:"trae",label:"Trae",appName:"Trae"}],Rd="vscode",zd=new Set(["terminal"]),Lw=new Set(["finder","terminal","iterm2","ghostty","explorer","files","wt"]),Ld=t=>t?Ha.find(e=>e.id===t)??null:null,pc=()=>Ha.filter(t=>zd.has(t.id)).map(t=>({...t})),Hw=()=>{if(typeof window>"u")return Rd;const t=window.localStorage.getItem("openInAppId");return t&&Ld(t)?t:Rd};let gc=!1,Gl=!1,Ba=!1,_a=0,h1=null;const d4=()=>{h1&&(clearTimeout(h1),h1=null)},Fo=Dr()((t,e)=>({selectedAppId:Hw(),availableApps:pc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(gc||typeof window>"u")return;gc=!0;const n=c=>{if(!Array.isArray(c)||c.length===0){t({availableApps:pc(),hasLoadedApps:!1});return}const u=new Set(c.map(p=>p.name)),m=new Map(c.map(p=>[p.name,p.iconDataUrl??void 0])),h=Ha.filter(p=>u.has(p.appName)||zd.has(p.id)).map(p=>({...p,iconDataUrl:m.get(p.appName)}));t({availableApps:h,hasLoadedApps:!0})},r=async c=>{if(!_n()||!$o()||Gl||e().hasLoadedApps&&!c)return;const m=Ha.map(f=>f.appName);d4(),Gl=!0,Ba=!1,t({isScanning:!0});try{const{apps:f,success:h,hasCache:p,isCacheStale:g}=await T3(m,c);if(t({isCacheStale:p?g:!1}),n(f),h){if(!p&&f.length===0&&_a<3){const b=[800,1600,3200][_a]??3200;_a+=1,Ba=!0,h1=setTimeout(()=>{r()},b);return}_a=0,Ba=!1;return}if(_a<3){const b=[1e3,3e3,7e3][_a]??7e3;_a+=1,Ba=!0,h1=setTimeout(()=>{r()},b)}}finally{Gl=!1,Ba||t({isScanning:!1})}};r();const o=c=>{const u=c.detail,m=u&&typeof u.openInAppId=="string"&&u.openInAppId.length>0&&Ld(u.openInAppId)?u.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},a=()=>{r()},l=c=>{const u=c.detail;Array.isArray(u)&&(_a=3,Ba=!1,t({isScanning:!1,isCacheStale:!1}),n(u))};window.addEventListener("archcoder:settings-synced",o),window.addEventListener("archcoder:app-ready",a),window.addEventListener("archcoder:installed-apps-updated",l),(window.__archcoderAppReady||window.__openchamberAppReady)&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(gc||e().initialize(),!_n()||!$o()||Gl||e().hasLoadedApps&&!n)return;const o=Ha.map(a=>a.appName);d4(),n&&t({hasLoadedApps:!1}),Gl=!0,Ba=!1,t({isScanning:!0});try{const{apps:a,hasCache:l,isCacheStale:i}=await T3(o,n),c=new Set(a.map(h=>h.name)),u=new Map(a.map(h=>[h.name,h.iconDataUrl??void 0])),f=Ha.filter(h=>c.has(h.appName)||zd.has(h.id)).map(h=>({...h,iconDataUrl:u.get(h.appName)}));t({availableApps:f.length>0?f:pc(),hasLoadedApps:f.length>0,isCacheStale:l?i:!1})}finally{Gl=!1,Ba||t({isScanning:!1})}},selectApp:async n=>{Ld(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ln({openInAppId:n}))}})),$w="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",Ow="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",xc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?$w:t.id==="terminal"?Ow:void 0}),u4=t=>{const e=Fe.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:o}=t,[a,l]=d.useState(!1);let i;e[0]!==n?(i=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=i):i=e[1];const c=i,u=r||o;if(u&&!a){let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>l(!0),e[2]=h):h=e[2];let p;return e[3]!==u?(p=s.jsx("img",{src:u,alt:"",className:"h-4 w-4 rounded-sm",onError:h}),e[3]=u,e[4]=p):p=e[4],p}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=Q("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let f;return e[6]!==c?(f=s.jsx("span",{className:m,children:c}),e[6]=c,e[7]=f):f=e[7],f},Vw=t=>{const e=Fe.c(64),{directory:n,activeFilePath:r,className:o}=t,a=Fo(Uw),l=Fo(Ww),i=Fo(qw),c=Fo(Gw),u=Fo(Zw),m=Fo(Kw),f=Fo(Yw);let h,p;e[0]!==u?(h=()=>{u()},p=[u],e[0]=u,e[1]=h,e[2]=p):(h=e[1],p=e[2]),d.useEffect(h,p);const g=_n()&&$o();let x;e:{let U;e[3]!==l||e[4]!==a?(U=l.find(q=>q.id===a)??l.find(Xw)??l[0]??Ha[0],e[3]=l,e[4]=a,e[5]=U):U=e[5];const X=U;if(X){let q;e[6]!==X?(q=xc(X),e[6]=X,e[7]=q):q=e[7],x=q;break e}let $;e[8]===Symbol.for("react.memo_cache_sentinel")?($=xc(Ha[0]),e[8]=$):$=e[8],x=$}const b=x;if(!g||!n||l.length===0)return null;let v;e[9]!==r||e[10]!==n?(v=async U=>{await N6(n,U.id,U.appName,r)||await L0(n,U.appName)},e[9]=r,e[10]=n,e[11]=v):v=e[11];const y=v;let w;e[12]!==y||e[13]!==f?(w=async U=>{await f(U.id),await y(U)},e[12]=y,e[13]=f,e[14]=w):w=e[14];const C=w;let N;e[15]!==n?(N=async()=>{(await Dn(n)).ok&&fe.success("Path copied to clipboard")},e[15]=n,e[16]=N):N=e[16];const S=N;let k;e[17]!==o?(k=Q("app-region-no-drag inline-flex h-7 items-center self-center rounded-md border border-[var(--interactive-border)]","bg-[var(--surface-elevated)] shadow-none overflow-hidden",o),e[17]=o,e[18]=k):k=e[18];let j;e[19]!==y||e[20]!==b?(j=()=>{y(b)},e[19]=y,e[20]=b,e[21]=j):j=e[21];let F;e[22]===Symbol.for("react.memo_cache_sentinel")?(F=Q("inline-flex h-full items-center gap-2 px-3 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors"),e[22]=F):F=e[22];const A=`Open in ${b.label}`;let M;e[23]!==b.fallbackIconDataUrl||e[24]!==b.iconDataUrl||e[25]!==b.label?(M=s.jsx(u4,{label:b.label,iconDataUrl:b.iconDataUrl,fallbackIconDataUrl:b.fallbackIconDataUrl}),e[23]=b.fallbackIconDataUrl,e[24]=b.iconDataUrl,e[25]=b.label,e[26]=M):M=e[26];const B=c?"animate-pulse text-muted-foreground":void 0;let E;e[27]!==B?(E=Q("header-open-label",B),e[27]=B,e[28]=E):E=e[28];let I;e[29]!==E?(I=s.jsx("span",{className:E,children:"Open"}),e[29]=E,e[30]=I):I=e[30];let P;e[31]!==A||e[32]!==M||e[33]!==I||e[34]!==j?(P=s.jsxs("button",{type:"button",onClick:j,className:F,"aria-label":A,children:[M,I]}),e[31]=A,e[32]=M,e[33]=I,e[34]=j,e[35]=P):P=e[35];let D;e[36]===Symbol.for("react.memo_cache_sentinel")?(D=Q("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]=D):D=e[36];let L;e[37]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:D,"aria-label":"Choose app to open",children:s.jsx(Ds,{className:"h-4 w-4"})})}),e[37]=L):L=e[37];let T;e[38]===Symbol.for("react.memo_cache_sentinel")?(T={translate:"-30px 0"},e[38]=T):T=e[38];let _;e[39]!==S?(_=()=>{S()},e[39]=S,e[40]=_):_=e[40];let z,R;e[41]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(nr,{className:"h-4 w-4"}),R=s.jsx("span",{className:"typography-ui-label text-foreground",children:"Copy Path"}),e[41]=z,e[42]=R):(z=e[41],R=e[42]);let W;e[43]!==_?(W=s.jsxs(Jt,{className:"flex items-center gap-2",onClick:_,children:[z,R]}),e[43]=_,e[44]=W):W=e[44];let G;e[45]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(Zn,{}),e[45]=G):G=e[45];let Y;if(e[46]!==l||e[47]!==C||e[48]!==b.id){let U;e[50]!==C||e[51]!==b.id?(U=X=>{const $=xc(X);return s.jsxs(Jt,{className:"flex items-center gap-2",onClick:()=>{C(X)},children:[s.jsx(u4,{label:X.label,iconDataUrl:X.iconDataUrl,fallbackIconDataUrl:$.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:X.label}),b.id===X.id?s.jsx(js,{className:"ml-auto h-4 w-4 text-primary"}):null]},X.id)},e[50]=C,e[51]=b.id,e[52]=U):U=e[52],Y=l.map(U),e[46]=l,e[47]=C,e[48]=b.id,e[49]=Y}else Y=e[49];let J;e[53]!==i||e[54]!==m?(J=i?s.jsxs(Jt,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(Qn,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:"Refresh Apps"})]}):null,e[53]=i,e[54]=m,e[55]=J):J=e[55];let V;e[56]!==W||e[57]!==Y||e[58]!==J?(V=s.jsxs(qs,{children:[L,s.jsxs(Ys,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:T,children:[W,G,Y,J]})]}),e[56]=W,e[57]=Y,e[58]=J,e[59]=V):V=e[59];let te;return e[60]!==P||e[61]!==V||e[62]!==k?(te=s.jsxs("div",{className:k,children:[P,V]}),e[60]=P,e[61]=V,e[62]=k,e[63]=te):te=e[63],te};function Uw(t){return t.selectedAppId}function Ww(t){return t.availableApps}function qw(t){return t.isCacheStale}function Gw(t){return t.isScanning}function Zw(t){return t.initialize}function Kw(t){return t.loadInstalledApps}function Yw(t){return t.selectApp}function Xw(t){return t.id===Rd}const Qw=1e6,Jw="terminal-store";let f4=!1;const bc=t=>typeof t=="object"&&t!==null,ej=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function ao(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const vc=(t,e)=>({id:t,terminalSessionId:null,label:e,bufferChunks:[],bufferLength:0,isConnecting:!1,createdAt:Date.now()}),yc=t=>({tabs:[t],activeTabId:t.id}),rl=(t,e)=>t.tabs.findIndex(n=>n.id===e),fo=Dr()(wa(Pl((t,e)=>({sessions:new Map,nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=ao(n);r&&t(o=>{if(o.sessions.has(r))return o;const a=new Map(o.sessions),l=`tab-${o.nextTabId}`,i=vc(l,"Terminal");return a.set(r,yc(i)),{sessions:a,nextTabId:o.nextTabId+1}})},getDirectoryState:n=>{const r=ao(n);return e().sessions.get(r)},getActiveTab:n=>{const r=ao(n),o=e().sessions.get(r);if(!o)return;const a=o.activeTabId;return a?o.tabs.find(l=>l.id===a)??o.tabs[0]:o.tabs[0]},createTab:n=>{const r=ao(n);if(!r)return"tab-invalid";const o=`tab-${e().nextTabId}`;return t(a=>{const l=new Map(a.sessions),i=l.get(r),c=a.nextTabId+1,m=`Terminal ${(i?.tabs.length??0)+1}`,f=vc(o,m);return i?l.set(r,{...i,tabs:[...i.tabs,f]}):l.set(r,yc(f)),{sessions:l,nextTabId:c}}),o},setActiveTab:(n,r)=>{const o=ao(n);t(a=>{const l=new Map(a.sessions),i=l.get(o);return!i||i.activeTabId===r||rl(i,r)<0?a:(l.set(o,{...i,activeTabId:r}),{sessions:l})})},setTabLabel:(n,r,o)=>{const a=ao(n),l=o.trim();l&&t(i=>{const c=new Map(i.sessions),u=c.get(a);if(!u)return i;const m=rl(u,r);if(m<0||u.tabs[m]?.label===l)return i;const f=[...u.tabs];return f[m]={...f[m],label:l},c.set(a,{...u,tabs:f}),{sessions:c}})},closeTab:async(n,r)=>{const o=ao(n),i=e().sessions.get(o)?.tabs.find(c=>c.id===r)?.terminalSessionId??null;if(i)try{await qb(i)}catch{}t(c=>{const u=new Map(c.sessions),m=u.get(o);if(!m)return c;const f=rl(m,r);if(f<0)return c;const h=m.tabs.filter(g=>g.id!==r);if(h.length===0){const g=`tab-${c.nextTabId}`,x=vc(g,"Terminal");return u.set(o,yc(x)),{sessions:u,nextTabId:c.nextTabId+1}}let p=m.activeTabId;return m.activeTabId===r&&(p=h[Math.min(f,h.length-1)]?.id??h[0]?.id??null),u.set(o,{...m,tabs:h,activeTabId:p}),{sessions:u}})},setTabSessionId:(n,r,o)=>{const a=ao(n);t(l=>{const i=new Map(l.sessions),c=i.get(a);if(!c)return l;const u=rl(c,r);if(u<0)return l;const m=c.tabs[u],f=o!==null&&m.terminalSessionId!==o,h={...m,terminalSessionId:o,isConnecting:!1,...f?{bufferChunks:[],bufferLength:0}:{}},p=[...c.tabs];return p[u]=h,i.set(a,{...c,tabs:p}),{sessions:i}})},setConnecting:(n,r,o)=>{const a=ao(n);t(l=>{const i=new Map(l.sessions),c=i.get(a);if(!c)return l;const u=rl(c,r);if(u<0)return l;const m=[...c.tabs];return m[u]={...m[u],isConnecting:o},i.set(a,{...c,tabs:m}),{sessions:i}})},appendToBuffer:(n,r,o)=>{if(!o)return;const a=ao(n);t(l=>{const i=new Map(l.sessions),c=i.get(a);if(!c)return l;const u=rl(c,r);if(u<0)return l;const m=c.tabs[u],f=l.nextChunkId,h={id:f,data:o},p=[...m.bufferChunks,h];let g=m.bufferLength+o.length;for(;g>Qw&&p.length>1;){const b=p.shift();if(!b)break;g-=b.data.length}const x=[...c.tabs];return x[u]={...m,bufferChunks:p,bufferLength:g},i.set(a,{...c,tabs:x}),{sessions:i,nextChunkId:f+1}})},clearBuffer:(n,r)=>{const o=ao(n);t(a=>{const l=new Map(a.sessions),i=l.get(o);if(!i)return a;const c=rl(i,r);if(c<0)return a;const u=[...i.tabs];return u[c]={...u[c],bufferChunks:[],bufferLength:0},l.set(o,{...i,tabs:u}),{sessions:l}})},removeDirectory:n=>{const r=ao(n);t(o=>{const a=new Map(o.sessions);return a.delete(r),{sessions:a}})},clearAll:()=>{t({sessions:new Map,nextChunkId:1,nextTabId:1})}}),{name:Jw,storage:Ii(()=>Wb()),partialize:t=>({sessions:Array.from(t.sessions.entries()).map(([e,n])=>[e,{activeTabId:n.activeTabId,tabs:n.tabs.map(r=>({id:r.id,label:r.label,terminalSessionId:r.terminalSessionId,createdAt:r.createdAt}))}]),nextTabId:t.nextTabId}),merge:(t,e)=>{if(!bc(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let o=0;for(const i of n){if(!Array.isArray(i)||i.length!==2)continue;const[c,u]=i;if(typeof c!="string"||!bc(u))continue;const m=Array.isArray(u.tabs)?u.tabs:[],f=[];for(const g of m){if(!bc(g))continue;const x=typeof g.id=="string"?g.id:null;if(!x)continue;const b=ej(x);b!==null&&(o=Math.max(o,b)),f.push({id:x,label:typeof g.label=="string"?g.label:"Terminal",terminalSessionId:typeof g.terminalSessionId=="string"||g.terminalSessionId===null?g.terminalSessionId:null,createdAt:typeof g.createdAt=="number"?g.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1})}if(f.length===0)continue;const h=typeof u.activeTabId=="string"?u.activeTabId:null,p=h?f.some(g=>g.id===h):!1;r.set(c,{tabs:f,activeTabId:p?h:f[0].id})}const a=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,l=Math.max(e.nextTabId,a,o+1);return{...e,sessions:r,nextChunkId:1,nextTabId:l,hasHydrated:!0}}})));if(typeof window<"u"&&!f4){f4=!0;const t=fo.persist,e=()=>{fo.getState().hasHydrated||fo.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const m4=(t,e)=>e.updatedAtMs-t.updatedAtMs,Sn=Dr((t,e)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!e().isLoading){t({isLoading:!0,error:null});try{const[n,r]=await Promise.all([r8(),I1()]),o={};for(const a of r.sort(m4))o[a.id]=a;e().listenerReady||await Fw(a=>{t(l=>({statusesById:{...l.statusesById,[a.id]:a}}))}),t({instances:n.instances,statusesById:o,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await Cw();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await I1(),r={};for(const o of n.sort(m4))r[o.id]=o;t({statusesById:r})}catch(n){t({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{t({isSaving:!0,error:null});try{await Sw({instances:n}),t({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(r){throw t({isSaving:!1,error:r instanceof Error?r.message:String(r)}),r}},upsertInstance:async n=>{const r=e().instances,o=r.some(a=>a.id===n.id)?r.map(a=>a.id===n.id?n:a):[n,...r];await e().setInstances(o)},createFromCommand:async(n,r,o)=>{const a=Nw(n,r);o&&o.trim()&&(a.nickname=o.trim()),await e().upsertInstance(a)},removeInstance:async n=>{await Pd(n).catch(()=>{});const r=e().instances.filter(o=>o.id!==n);await e().setInstances(r),t(o=>{const a={...o.statusesById};return delete a[n],{statusesById:a}})},connect:async n=>{t({error:null});try{await Td(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},disconnect:async n=>{t({error:null});try{await Pd(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>t({error:null})})),a8=t=>{try{return new URL(t)}catch{return null}},tj=t=>{const e=a8(t.trim());return e?e.protocol==="http:"||e.protocol==="https:":!1},Xr=async t=>{if(typeof window>"u")return!1;const e=t.trim();if(!e)return!1;const n=a8(e);if(!n||n.protocol!=="http:"&&n.protocol!=="https:")return!1;const r=n.toString(),o=Ho();if(o?.runtime?.isVSCode&&o.vscode?.openExternalUrl)try{return await o.vscode.openExternalUrl(r),!0}catch{return!1}const a=window.__TAURI__;if(a?.shell?.open)try{return await a.shell.open(r),!0}catch{}try{return window.open(r,"_blank","noopener,noreferrer"),!0}catch{return!1}},l8=[{key:"play",label:"Play",Icon:Va},{key:"build",label:"Build",Icon:Xg},{key:"lint",label:"Lint",Icon:hi},{key:"terminal",label:"Terminal",Icon:Po},{key:"tools",label:"Tools",Icon:V1},{key:"bug",label:"Bug",Icon:Qg},{key:"flask",label:"Flask",Icon:Jg},{key:"rocket",label:"Rocket",Icon:e9},{key:"code",label:"Code",Icon:Al},{key:"server",label:"Server",Icon:Cl},{key:"branch",label:"Branch",Icon:on},{key:"search",label:"Search",Icon:xr},{key:"settings",label:"Settings",Icon:xa},{key:"brain",label:"Brain",Icon:oa},{key:"stack",label:"Stack",Icon:ya},{key:"robot",label:"Robot",Icon:zo},{key:"command",label:"Command",Icon:Rl},{key:"file",label:"File",Icon:M1}],O0=Object.fromEntries(l8.map(t=>[t.key,t.Icon])),Hd="openchamber:project-actions-updated",i8=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},Ea=(t,e)=>`${i8(t)}::${e}`,sj=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},h4=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},nj=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=h4(e.localPort),r=h4(e.remotePort);if(!n||!r)return null;const o=sj(e.localHost||t.localForward.bindHost||"127.0.0.1"),a=(e.remoteHost||"127.0.0.1").trim(),l=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${l} - ${o}:${n} -> ${a}:${r}`,url:`http://${o}:${n}`}},c8=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const o=nj(n,r);o&&e.push(o)}return e},rj=(t,e)=>{const n=(t||"").trim();return n&&c8(e).find(a=>a.id===n)?.url||null},oj=t=>new Promise(e=>{window.setTimeout(e,t)}),aj="\x1B",lj=new RegExp(`${aj}\\[[0-9;?]*[ -/]*[@-~]`,"g"),ij=/https?:\/\/[^\s<>'"`]+/gi,cj=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},dj=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}},uj=t=>{const n=t.replace(lj,"").match(ij);if(!n||n.length===0)return null;const r=n.map(a=>a.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const o=[];for(const a of r)try{const l=new URL(a);l.port&&l.port.length>0&&o.push({raw:a,parsed:l})}catch{}if(o.length>0){const a=l=>{const{parsed:i}=l,c=i.hostname.toLowerCase(),u=c==="localhost"||c==="127.0.0.1"||c==="0.0.0.0"||c==="::1",m=i.pathname||"/",f=m.split("/").filter(Boolean).length,h=m==="/"||m==="",p=!!(i.search||i.hash);let g=0;return u&&(g+=50),h&&(g+=30),g-=Math.min(f*5,20),p&&(g-=10),g};return o.sort((l,i)=>a(i)-a(l)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},fj=t=>{const e=t.trim();if(!e)return"Action";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],o=n[1].slice(0,3),a=`${r} ${o}`.trim();return n.length>2||a.length<e.length?`${a}...`:a}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},p4=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{terminal:a,runtime:l}=ur(),{isMobile:i}=wn(),c=d.useMemo(()=>Rn(),[]),u=Sn(ne=>ne.instances),m=Sn(ne=>ne.load),f=Ee(ne=>ne.setBottomTerminalOpen),h=Ee(ne=>ne.setActiveMainTab),p=Ee(ne=>ne.setSettingsPage),g=Ee(ne=>ne.setSettingsDialogOpen),x=Ee(ne=>ne.setSettingsProjectsSelectedId),b=fo(ne=>ne.sessions),v=fo(ne=>ne.ensureDirectory),y=fo(ne=>ne.setTabLabel),w=fo(ne=>ne.setActiveTab),C=fo(ne=>ne.setConnecting),N=fo(ne=>ne.setTabSessionId),[S,k]=d.useState([]),[j,F]=d.useState(null),[A,M]=d.useState(!1),[B,E]=d.useState({}),I=d.useRef({}),P=d.useRef({}),D=d.useRef(0),L=t?.id??null,T=t?.path??"",_=d.useMemo(()=>L?{id:L,path:T}:null,[L,T]);d.useEffect(()=>{c&&m().catch(()=>{})},[c,m]);const z=d.useCallback(async ne=>{await Xr(ne)},[]),R=d.useCallback(async()=>{if(!_)return;const ne=D.current+1;D.current=ne,M(!0);try{const O=await S6(_);if(D.current!==ne)return;const H=O.actions;k(H),F(K=>H.length===0?null:K&&H.some(re=>re.id===K)?K:H[0]?.id??null)}catch{if(D.current!==ne)return}finally{D.current===ne&&M(!1)}},[_]);d.useEffect(()=>{R()},[R]),d.useEffect(()=>{if(typeof window>"u")return;const ne=O=>{const H=O.detail;L&&(H?.projectId&&H.projectId!==L||R())};return window.addEventListener(Hd,ne),()=>{window.removeEventListener(Hd,ne)}},[R,L]),d.useEffect(()=>{j&&(S.some(ne=>ne.id===j)||F(S[0]?.id??null))},[S,j]),d.useEffect(()=>{E(ne=>{let O=!1;const H={};for(const[K,re]of Object.entries(ne)){const ae=b.get(re.directory)?.tabs.find(ue=>ue.id===re.tabId);if(!ae||ae.terminalSessionId!==re.sessionId){O=!0;continue}H[K]=re}return O?H:ne})},[b]),d.useEffect(()=>{for(const[ne,O]of Object.entries(B)){const H=P.current[ne]??{lastSeenChunkId:null,openedUrl:!1,tail:""};P.current[ne]=H;const K=S.find(ie=>ie.id===O.actionId);if(!K)continue;const le=b.get(O.directory)?.tabs.find(ie=>ie.id===O.tabId);if(!le||!Array.isArray(le.bufferChunks)||le.bufferChunks.length===0)continue;const ae=le.bufferChunks.filter(ie=>H.lastSeenChunkId===null?!0:ie.id>H.lastSeenChunkId);if(ae.length===0)continue;const ue=ae.map(ie=>ie.data).join(""),be=`${H.tail}${ue}`,oe=!H.openedUrl&&K.autoOpenUrl===!0?uj(be):null,Z=ae[ae.length-1]?.id??H.lastSeenChunkId;H.lastSeenChunkId=Z,H.tail=be.slice(-512),oe&&(H.openedUrl=!0,z(oe),fe.success("Opened URL from action output")),P.current[ne]=H}for(const ne of Object.keys(P.current))B[ne]||delete P.current[ne]},[S,z,B,b]);const W=d.useMemo(()=>i8(e||_?.path||""),[e,_?.path]),G=d.useMemo(()=>j?S.find(ne=>ne.id===j)??S[0]??null:S[0]??null,[S,j]),Y=d.useCallback(async ne=>{if(!W)throw new Error("No active directory");const O=Ea(W,ne.id);v(W);const H=fo.getState(),K=H.getDirectoryState(W);let re=I.current[O]||null;const le=re?!!K?.tabs.some(be=>be.id===re):!1;(!re||!le)&&(re=H.createTab(W),I.current[O]=re),y(W,re,`Action: ${ne.name}`),w(W,re),f(!0),h("terminal");const ue=fo.getState().getDirectoryState(W)?.tabs.find(be=>be.id===re);return{key:O,tabId:re,sessionId:ue?.terminalSessionId??null}},[v,W,h,w,f,y]),J=d.useCallback(async ne=>{if(l.isVSCode||!o&&i)return;if(!W){fe.error("No active directory for action");return}const O=Ea(W,ne.id),H=B[O];if(!(H&&H.status==="running"))try{const{key:K,tabId:re,sessionId:le}=await Y(ne);let ae=le,ue=!1;if(!ae){C(W,re,!0);try{ae=(await a.createSession({cwd:W})).sessionId,ue=!0,N(W,re,ae)}finally{C(W,re,!1)}}if(!ae)throw new Error("Failed to create terminal session");ue&&await oj(350),E(me=>({...me,[K]:{key:K,directory:W,actionId:ne.id,tabId:re,sessionId:ae,status:"running"}}));const be=ne.autoOpenUrl===!0&&(ne.openUrl||"").trim().length>0,oe=ne.autoOpenUrl===!0&&c&&(ne.desktopOpenSshForward||"").trim().length>0,Z=ne.autoOpenUrl?dj(ne.openUrl):null,ie=ne.autoOpenUrl&&c?rj(ne.desktopOpenSshForward,u):null;ie?(z(ie),fe.success("Opened forwarded URL")):Z?(z(Z),fe.success("Opened action URL")):be?fe.error("Invalid custom URL format"):oe&&fe.error("Selected desktop SSH forward is unavailable"),P.current[K]={lastSeenChunkId:null,openedUrl:!!ie||!!Z||be,tail:""};const pe=cj(ne.command.trim().replace(/\r\n|\r/g,`
3
3
  `));await a.sendInput(ae,`${pe}\r`)}catch(K){E(re=>{const le={...re};return delete le[O],le}),delete P.current[O],fe.error(K instanceof Error?K.message:"Failed to run action")}},[u,Y,o,i,c,W,z,B,l.isVSCode,C,N,a]),V=d.useCallback(async ne=>{const O=Ea(W,ne.id),H=B[O];if(!H)return;E(le=>({...le,[O]:{...H,status:"stopping"}}));try{await a.sendInput(H.sessionId,"")}catch{}if(await new Promise(le=>{window.setTimeout(le,1e3)}),fo.getState().getDirectoryState(H.directory)?.tabs.find(le=>le.id===H.tabId)?.terminalSessionId===H.sessionId){if(typeof a.forceKill=="function")try{await a.forceKill({sessionId:H.sessionId})}catch{}else try{await a.close(H.sessionId)}catch{}N(H.directory,H.tabId,null)}E(le=>{const ae={...le};return delete ae[O],ae}),delete P.current[O]},[W,B,N,a]),te=d.useCallback(()=>{if(!G)return;const ne=Ea(W,G.id),O=B[ne];if(O?.status!=="stopping"){if(O){V(G);return}J(G)}},[W,J,B,G,V]),U=d.useCallback((ne,O=!1)=>{if(F(ne.id),!O){J(ne);return}const H=Ea(W,ne.id),K=B[H];if(K?.status!=="stopping"){if(K){V(ne);return}J(ne)}},[W,J,B,V]),X=d.useCallback(()=>{_?.id&&(x(_.id),p("projects"),g(!0))},[g,p,x,_?.id]);if(l.isVSCode||!o&&i||!_||!W)return null;if(S.length===0)return r?s.jsx("button",{type:"button",className:Q("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-md 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",n),"aria-label":"Add action",onClick:X,children:s.jsx(Qs,{className:"h-5 w-5"})}):s.jsxs("button",{type:"button",className:Q("app-region-no-drag inline-flex h-7 shrink-0 items-center gap-2 self-center rounded-md border border-[var(--interactive-border)]","bg-[var(--surface-elevated)] px-3 typography-ui-label font-medium text-foreground hover:bg-interactive-hover transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",n),onClick:X,children:[s.jsx(Qs,{className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"header-open-label whitespace-nowrap",children:"Add action"})]});const $=G??S[0]??null;if(!$)return null;const q=$.icon||"play",ee=O0[q]||Va,ce=fj($.name),ve=Ea(W,$.id),ge=B[ve],xe=ge?.status==="stopping";return r?s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",disabled:A||xe,className:Q("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-md 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),"aria-label":ge?`Stop ${$.name}`:`Run ${$.name}`,children:xe?s.jsx(ts,{className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):ge?s.jsx(Xo,{className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(ee,{className:"h-5 w-5"})})}),s.jsxs(Ys,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Jt,{className:"flex items-center gap-2",onClick:X,children:[s.jsx(Qs,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),s.jsx(Zn,{}),S.map(ne=>{const O=ne.icon||"play",H=O0[O]||Va,K=Ea(W,ne.id),re=B[K],le=!!re,ae=re?.status==="stopping";return s.jsxs(Jt,{className:"flex items-center gap-2",onClick:()=>{U(ne,!0)},children:[s.jsx(H,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ne.name}),ae?s.jsx(ts,{className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):le?s.jsx(Xo,{className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ne.id)})]})]}):s.jsxs("div",{className:Q("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-md border border-[var(--interactive-border)]","bg-[var(--surface-elevated)] shadow-none overflow-hidden",r?"h-9":"h-7",n),children:[s.jsxs("button",{type:"button",onClick:te,disabled:A||xe,className:Q("inline-flex h-full items-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 justify-center px-0":"gap-2 px-3","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":ge?`Stop ${$.name}`:`Run ${$.name}`,children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:xe?s.jsx(ts,{className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):ge?s.jsx(Xo,{className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(ee,{className:"h-4 w-4"})}),r?null:s.jsx("span",{className:"header-open-label whitespace-nowrap",children:ce})]}),s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:Q(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":"Choose project action",children:s.jsx(Ds,{className:"h-4 w-4"})})}),s.jsxs(Ys,{align:"center",className:"w-52 max-h-[70vh] overflow-y-auto",style:{translate:"-30px 0"},children:[s.jsxs(Jt,{className:"flex items-center gap-2",onClick:X,children:[s.jsx(Qs,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),s.jsx(Zn,{}),S.map(ne=>{const O=ne.icon||"play",H=O0[O]||Va,K=Ea(W,ne.id),re=B[K],le=!!re,ae=re?.status==="stopping";return s.jsxs(Jt,{className:"flex items-center gap-2",onClick:()=>{U(ne)},children:[s.jsx(H,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ne.name}),ae?s.jsx(ts,{className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):le?s.jsx(Xo,{className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ne.id)})]})]})]})},mj=t=>{const e=new Date(t),n=new Date,r=(l,i)=>l.getFullYear()===i.getFullYear()&&l.getMonth()===i.getMonth()&&l.getDate()===i.getDate(),o=new Date(n);return o.setDate(n.getDate()-1),r(e,n)?"Today":r(e,o)?"Yesterday":e.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}).replace(",","")},hj=t=>{const e=new Date,n=new Date(t);if(((o,a)=>o.getFullYear()===a.getFullYear()&&o.getMonth()===a.getMonth()&&o.getDate()===a.getDate())(n,e)){const o=Date.now()-t;return o<6e4?"Just now":o<36e5?`${Math.floor(o/6e4)}min ago`:`${Math.floor(o/36e5)}h ago`}return mj(t)},pj=t=>{const e=Math.max(0,Date.now()-t),n=6e4,r=60*n,o=24*r,a=7*o,l=30*o,i=365*o;return e<r?`${Math.max(1,Math.floor(e/n))}m`:e<o?`${Math.floor(e/r)}h`:e<a?`${Math.floor(e/o)}d`:e<5*a?`${Math.floor(e/a)}w`:e<i?`${Math.floor(e/l)}mo`:`${Math.floor(e/i)}y`},nn=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").replace(/\/+$/,"");return e.length===0?"/":e},h2=t=>t.toLowerCase().replace(/^opencode[/-]?/i,"").replace(/[-_]/g,"").trim(),gj=(t,e)=>t?h2(t)!==h2(e):!1,$d=t=>{if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"&&t.trim().length>0){const e=Number(t);if(Number.isFinite(e))return e}},g4=t=>$d(t.time?.created)??0,x4=t=>$d(t.time?.updated)??$d(t.time?.created)??0,T1=(t,e,n)=>{const r=n.has(t.id),o=n.has(e.id);return r!==o?r?-1:1:r&&o?g4(e)-g4(t):x4(e)-x4(t)},Ai=t=>{const e=new Map;return t.forEach(n=>{e.set(n.id,n)}),Array.from(e.values())},Uu=t=>`__archived__:${t}`,xj=(t,e)=>{const n=nn(t.directory??null),r=nn(t.project?.worktree??null),o=n??r;if(!o)return"unassigned";if(e&&o===e)return"project root";const l=(e&&o.startsWith(`${e}/`)?o.slice(e.length+1):o).split("/").filter(Boolean);return l[l.length-1]??"unassigned"},P1=(t,e,n)=>{const r=nn(t.directory??null),o=nn(t.project?.worktree??null);return o&&(o===e||o.startsWith(`${e}/`))?!0:r?n&&n.has(r)?!0:r===e||r.startsWith(`${e}/`):!1},i0=t=>{if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const e=Number(t);if(Number.isFinite(e))return e}return null},d8=t=>{if(!t)return null;const e=i0(t.additions),n=i0(t.deletions);if(e!==null||n!==null){const l={additions:Math.max(0,e??0),deletions:Math.max(0,n??0)};return l.additions===0&&l.deletions===0?null:l}const r=Array.isArray(t.diffs)?t.diffs:[];if(r.length===0)return null;let o=0,a=0;return r.forEach(l=>{o+=Math.max(0,i0(l.additions)??0),a+=Math.max(0,i0(l.deletions)??0)}),o===0&&a===0?null:{additions:o,deletions:a}},u8=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),p1=(t,e)=>{if(!e)return t;const n=t.toLowerCase(),r=e.toLowerCase(),o=r.length;if(o===0)return t;const a=[];let l=0,i=n.indexOf(r,l);for(;i!==-1;){i>l&&a.push(t.slice(l,i));const c=t.slice(i,i+o);a.push(s.jsx("mark",{className:"bg-primary text-primary-foreground ring-1 ring-primary/90",children:c},`${i}-${c}`)),l=i+o,i=n.indexOf(r,l)}return l<t.length&&a.push(t.slice(l)),a.length>0?a:t},bj=(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??""),vj=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"},b4=t=>{switch(t){case"open":return 5;case"blocked":return 4;case"draft":return 3;case"merged":return 2;case"closed":return 1;default:return 0}},yj=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),a=`${r} ${o}`.trim();return n.length>2||a.length<e.length?`${a}...`:a}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},v4=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},Zr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},y4=(t,e)=>{const n=Zr(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},wj=t=>y4(y4(t,".opencode"),"plans"),jj=()=>"~/.opencode/plans",kj=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},c0=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,w4=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r,desktopRightSidebarActionsHost:o=null})=>{const a=Ee(Te=>Te.setSessionSwitcherOpen),l=Ee(Te=>Te.toggleSidebar),i=Ee(Te=>Te.isSidebarOpen),c=Ee(Te=>Te.isRightSidebarOpen),u=Ee(Te=>Te.toggleBottomTerminal),m=Ee(Te=>Te.toggleRightSidebar),f=Ee(Te=>Te.openContextOverview),h=Ee(Te=>Te.openContextPlan),p=Ee(Te=>Te.closeContextPanel),g=Ee(Te=>Te.contextPanelByDirectory),x=Ee(Te=>Te.activeMainTab),b=Ee(Te=>Te.setActiveMainTab),v=Ee(Te=>Te.shortcutOverrides),{getCurrentModel:y}=rs(),w=ur(),C=Ze(Te=>Te.getContextUsage),N=Ze(Te=>Te.openNewSessionDraft),S=Ze(Te=>!!Te.newSessionDraft?.open),k=Ze(Te=>Te.currentSessionId),j=Ze(Te=>{if(k)return Te.messages.get(k)}),F=Ze(Te=>Te.sessions),A=vs(Te=>Te.activeProjectId?Te.projects.find(Ie=>Ie.id===Te.activeProjectId)??null:null),M=d.useMemo(()=>{if(!A)return null;const Te=A.label?.trim();if(Te)return Te;const Ie=A.path.split(/[\\/]/).filter(Boolean);return Ie[Ie.length-1]??null},[A]),B=Ws(Te=>Te.results),E=Ws(Te=>Te.fetchAllQuotas),I=Ws(Te=>Te.isLoading),P=Ws(Te=>Te.lastUpdated),D=Ws(Te=>Te.displayMode),L=Ws(Te=>Te.dropdownProviderIds),T=Ws(Te=>Te.loadSettings),_=Ws(Te=>Te.setDisplayMode),z=dn(Te=>Te.homeDirectory),{isMobile:R}=wn(),W=ir(Te=>Te.status),G=ir(Te=>Te.setStatus),Y=d.useRef(null),[J,V]=d.useState(()=>typeof window>"u"?!1:Rn()),[te,U]=d.useState(!1),X=d.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),$=d.useMemo(()=>{if(typeof window>"u")return null;const Te=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Te=="number"&&Number.isFinite(Te)&&Te>0)return Te;if(typeof navigator>"u")return null;const Ie=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Ie)return null;const Ke=Number.parseInt(Ie[1],10),Ve=Number.parseInt(Ie[2],10);return Number.isNaN(Ke)?null:Ke===10?Ve:Ke},[]);he.useEffect(()=>{typeof window>"u"||V(Rn())},[]);const q=y(),ee=q&&typeof q.limit=="object"&&q.limit!==null?q.limit:null,ce=ee&&typeof ee.context=="number"?ee.context:0,ve=ee&&typeof ee.output=="number"?ee.output:0,ge=C(ce,ve),[xe,ne]=d.useState(null),O=!k||j!==void 0;he.useEffect(()=>{if(!k){ne(Te=>Te===null?Te:null);return}if(ge&&ge.totalTokens>0){ne(Te=>bj(Te,ge)?Te:ge);return}O&&ne(Te=>Te===null?Te:null)},[ge,k,O]);const H=Ee(Te=>Te.isSessionSwitcherOpen),K=W?.connected?W.user?.avatarUrl:null,re=W?.connected?W.user?.login:null,le=W?.accounts??[],[ae,ue]=d.useState(!1),[be,oe]=d.useState(!1),[Z,ie]=d.useState(!1),[pe,me]=d.useState(!1),[Se,ke]=d.useState("Local"),ye=d.useMemo(()=>yj(Se),[Se]),[Ne,_e]=d.useState(J?"instance":"usage"),[de,we]=d.useState("usage");he.useEffect(()=>{!J&&Ne==="instance"&&_e("usage")},[Ne,J]);const je=d.useMemo(()=>xn(),[]),Ce=d.useMemo(()=>R?typeof t=="function"?!!n:H:i,[R,H,i,n,t]),ze=!je&&x==="chat"&&!!xe&&xe.totalTokens>0,Ge=xe&&xe.contextLimit>0?Math.min(999,xe.totalTokens/xe.contextLimit*100):0,Le=d.useCallback(async()=>{if(!(typeof window>"u"||!J))try{const Te=await Vu(),Ie=window.location.href,Ke=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(Ci(Ie,Ke)){ke("Local");return}const Ve=Te.hosts.find(ft=>Ci(Ie,ft.url));if(Ve?.label?.trim()){ke(Br(Ve.label.trim()));return}ke("Instance")}catch{ke("Local")}},[J]);he.useEffect(()=>{Le()},[Le]),zu();const qe=Ws(Te=>Te.selectedModels),rt=Ws(Te=>Te.expandedFamilies),st=Ws(Te=>Te.toggleFamilyExpanded),it=d.useMemo(()=>{const Te=[];for(const Ie of Oo){if(!L.includes(Ie.id))continue;const Ke=B.find(mt=>mt.providerId===Ie.id),Ve=Ke?.usage?.windows??{},ft=Ke?.usage?.models,Bt=Object.entries(Ve),At={providerId:Ie.id,providerName:Ie.name,entries:Bt,error:Ke&&!Ke.ok&&Ke.configured?Ke.error:void 0};if(ft&&Object.keys(ft).length>0){const mt=qe[Ie.id]??[],Lt=mt.length>0,$t=Gv(ft,Ie.id),Xs=$6(Ie.id),As=O6(Xs);At.modelFamilies=[];for(const ms of As){const Hs=$t.get(ms.id)??[];if(Hs.length===0)continue;const rn=Lt?Hs.filter(Vn=>mt.includes(Vn)):Hs;if(rn.length===0)continue;const zs=[];for(const Vn of rn){const Ln=ft[Vn];if(Ln?.windows){const Jn=Object.entries(Ln.windows);Jn.length>0&&zs.push([Vn,Jn[0][1]])}}zs.length>0&&At.modelFamilies.push({familyId:ms.id,familyLabel:ms.label,models:zs})}const Ot=$t.get(null)??[],fs=Lt?Ot.filter(ms=>mt.includes(ms)):Ot;if(fs.length>0){const ms=[];for(const Hs of fs){const rn=ft[Hs];if(rn?.windows){const zs=Object.entries(rn.windows);zs.length>0&&ms.push([Hs,zs[0][1]])}}ms.length>0&&At.modelFamilies.push({familyId:null,familyLabel:"Other",models:ms})}}(Bt.length>0||At.modelFamilies&&At.modelFamilies.length>0||At.error)&&Te.push(At)}return Te},[L,B,qe]),lt=it.length>0;d.useEffect(()=>{T()},[T]);const He=d.useCallback(async Te=>{_(Te);try{await ln({usageDisplayMode:Te})}catch(Ie){console.warn("Failed to update usage display mode:",Ie)}},[_]),Oe=d.useCallback(()=>{if(pe)return;me(!0);const Te=new Promise(Ie=>setTimeout(Ie,500));Promise.all([E(),Te]).finally(()=>{me(!1)})},[E,pe]),se=d.useMemo(()=>k?F.find(Te=>Te.id===k)??null:null,[k,F]),Pe=Ze(Te=>k?Te.worktreeMetadata.get(k)?.path??"":""),Ye=Ze(Te=>k?Te.worktreeMetadata.get(k)?.branch?.trim()??null:null),We=Wn(Te=>Te.directories),xt=mo(Te=>Te.entries),et=d.useMemo(()=>Zr(Pe||""),[Pe]),tt=d.useMemo(()=>{const Te=typeof se?.directory=="string"?se.directory:"";return Zr(Te||"")},[se?.directory]),ht=Ze(Te=>Te.newSessionDraft?.open?Zr(Te.newSessionDraft.bootstrapPendingDirectory??Te.newSessionDraft.directoryOverride??""):""),St=d.useMemo(()=>et||tt||ht,[ht,tt,et]),Ue=d.useMemo(()=>{if(!k)return M??"ArchCoder";const Te=se?.title?.trim();return Te&&Te.length>0?Te:"Untitled Session"},[M,se?.title,k]),ct=d.useMemo(()=>d8(se?.summary),[se?.summary]),Qe=d.useMemo(()=>{const Te=Zr(St||"");if(Te){const Ie=We.get(Te)?.status?.current?.trim();if(Ie)return Ie}return Ye},[Ye,We,St]),at=d.useMemo(()=>{const Te=Zr(St||""),Ie=Qe?.trim();if(!Te||!Ie)return null;let Ke=null;const Ve=Object.values(xt);for(const ft of Ve){const Bt=Zr(ft.params?.directory??ft.identity?.directory??""),At=ft.params?.branch?.trim()??ft.identity?.branch?.trim()??"";if(!Bt||!At||Bt!==Te||At!==Ie)continue;const mt=vj(ft.status??null),Lt=ft.status?.pr?.number;if(!mt||!Lt)continue;const $t={visualState:mt,number:Lt,canMerge:typeof ft.status?.canMerge=="boolean"?ft.status.canMerge:null,checksState:ft.status?.checks?.state??null};(!Ke||b4($t.visualState)>b4(Ke.visualState))&&(Ke=$t)}return Ke},[Qe,St,xt]),Nt=d.useMemo(()=>{if(!at)return null;switch(at.visualState){case"merged":return`PR #${at.number} merged`;case"closed":return`PR #${at.number} closed`;case"draft":return`PR #${at.number} draft`;case"blocked":return`PR #${at.number} blocked`;case"open":return at.canMerge===!0||at.checksState==="success"?`PR #${at.number} ready`:`PR #${at.number} open`;default:return null}},[at]),jt=d.useMemo(()=>ct||{additions:0,deletions:0},[ct]),qt=jt.additions>0||jt.deletions>0,Zt=vr(Te=>{const Ie=Zr(St||"");return Ie?Te.byRoot[Ie]?.selectedPath??null:null}),Pt=d.useMemo(()=>Zr(St||A?.path||""),[A?.path,St]),cs=d.useMemo(()=>A?{id:A.id,path:A.path}:null,[A]),ss=d.useRef(null);d.useEffect(()=>{!cs||!Pt||(ss.current={projectRef:cs,directory:Pt})},[Pt,cs]);const Wt=d.useMemo(()=>cs&&Pt?{projectRef:cs,directory:Pt}:ss.current,[Pt,cs]),[ls,us]=d.useState(!1),ys=ls,ws=d.useRef(""),Is=d.useCallback(async Te=>{if(!(!Te||ae)){ue(!0);try{const Ie=w.github?await w.github.authActivate(Te):await(async()=>{const Ke=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Te})}),Ve=await Ke.json().catch(()=>null);if(!Ke.ok||!Ve)throw new Error(Ve?.error||Ke.statusText);return Ve})();G(Ie)}catch(Ie){console.error("Failed to switch GitHub account:",Ie)}finally{ue(!1)}}},[ae,w.github,G]);d.useEffect(()=>{let Te=!1;const Ie=async(Bt,At)=>{if(!Bt||!At||!w.files?.listDirectory)return!1;try{const mt=await w.files.listDirectory(Bt);return(Array.isArray(mt?.entries)?mt.entries:[]).some($t=>$t?.name===At&&!$t?.isDirectory)}catch{return!1}},Ke=async()=>{if(Te)return;if(!se?.slug||!se?.time?.created||!tt){us(!1),Ee.getState().activeMainTab==="plan"&&Ee.getState().setActiveMainTab("chat");return}const Bt=`${se.time.created}-${se.slug}.md`,At=wj(tt),mt=kj(jj(),z||null),[Lt,$t]=await Promise.all([Ie(At,Bt),Ie(mt,Bt)]);if(Te)return;const Xs=Lt||$t;us(Xs),!Xs&&Ee.getState().activeMainTab==="plan"&&Ee.getState().setActiveMainTab("chat")},Ve=`${k||"none"}:${tt||"none"}:${se?.time?.created||0}:${se?.slug||"none"}`;ws.current!==Ve&&(ws.current=Ve,us(!1)),Ke();const ft=window.setInterval(()=>{Ke()},3e3);return()=>{Te=!0,window.clearInterval(ft)}},[tt,se?.slug,se?.time?.created,k,z,w.files]);const bs=d.useCallback(()=>{if(typeof document>"u")return;const Te=document.activeElement;if(!Te)return;const Ie=Te.tagName;(Ie==="INPUT"||Ie==="TEXTAREA"||Ie==="SELECT"||Te.isContentEditable)&&Te.blur()},[]),Ss=d.useCallback(()=>{if(R){bs(),a(!H);return}l()},[bs,R,H,a,l]),Cs=d.useCallback(()=>{b("chat"),a(!1),N()},[N,b,a]),ut=d.useCallback(()=>{const Te=Zr(St||"");if(!Te)return;const Ie=g[Te];if(c0(Ie)==="context"){p(Te);return}f(Te)},[p,g,f,St]),Mt=d.useMemo(()=>{const Te=Zr(St||"");if(!Te)return!1;const Ie=g[Te];return c0(Ie)==="context"},[g,St]),Kt=d.useCallback(()=>{const Te=Zr(St||"");if(!Te)return;const Ie=g[Te];if(c0(Ie)==="plan"){p(Te);return}h(Te)},[p,g,h,St]),Ft=d.useMemo(()=>{const Te=Zr(St||"");if(!Te)return!1;const Ie=g[Te];return c0(Ie)==="plan"},[g,St]),Et="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",bt="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",kt=d.useMemo(()=>!i&&J&&X&&!te?"pl-[5.5rem]":"pl-3",[J,te,X,i]);he.useEffect(()=>{if(!J||!X){U(!1);return}let Te=!1,Ie=null;const Ke=async()=>{try{const{getCurrentWindow:ft}=await Kn(async()=>{const{getCurrentWindow:mt}=await import("./vendor-.bun-HTKwyaEM.js").then(Lt=>Lt.fG);return{getCurrentWindow:mt}},__vite__mapDeps([0,1])),At=await ft().isFullscreen();Te||U(At)}catch{Te||U(!1)}},Ve=async()=>{try{const{getCurrentWindow:ft}=await Kn(async()=>{const{getCurrentWindow:At}=await import("./vendor-.bun-HTKwyaEM.js").then(mt=>mt.fG);return{getCurrentWindow:At}},__vite__mapDeps([0,1]));Ie=await ft().onResized(()=>{Ke()})}catch{}};return Ke(),Ve(),()=>{Te=!0,Ie&&Ie()}},[J,X]);const as=d.useMemo(()=>!J||!X||$===null?"":$>=26?"h-12":$<=15?"h-14":"",[J,X,$]),Gt=d.useCallback(()=>{if(typeof document>"u")return;const Te=Y.current?.getBoundingClientRect().height;Te&&document.documentElement.style.setProperty("--oc-header-height",`${Te}px`)},[]);he.useEffect(()=>{if(typeof window>"u")return;Gt();const Te=Y.current;if(!Te||typeof ResizeObserver>"u")return()=>{};let Ie=0;const Ke=()=>{Ie||(Ie=requestAnimationFrame(()=>{Ie=0,Gt()}))},Ve=new ResizeObserver(Ke);return Ve.observe(Te),window.addEventListener("resize",Ke),window.addEventListener("orientationchange",Ke),()=>{Ie&&cancelAnimationFrame(Ie),Ve.disconnect(),window.removeEventListener("resize",Ke),window.removeEventListener("orientationchange",Ke)}},[Gt]),he.useEffect(()=>{Gt()},[Gt,R,as]);const Ae=d.useCallback(async Te=>{const Ie=Te.target;if(!Ie.closest(".app-region-no-drag")&&!Ie.closest("button, a, input, select, textarea")&&Te.button===0&&J)try{const{getCurrentWindow:Ke}=await Kn(async()=>{const{getCurrentWindow:ft}=await import("./vendor-.bun-HTKwyaEM.js").then(Bt=>Bt.fG);return{getCurrentWindow:ft}},__vite__mapDeps([0,1]));await Ke().startDragging()}catch(Ke){console.error("Failed to start window dragging:",Ke)}},[J]),Xe=d.useMemo(()=>{if(R){const Te=[{id:"chat",label:"Chat",icon:I2}];return ys&&Te.push({id:"plan",label:"Plan",icon:M1}),Te.push({id:"diff",label:"Diff",icon:"diff"},{id:"files",label:"Files",icon:Pa},{id:"terminal",label:"Terminal",icon:Po}),Te}return[]},[R,ys]),yt=d.useCallback(Te=>X2(ha(Te,v)),[v]);he.useEffect(()=>{!R&&(x==="git"||x==="terminal"||x==="diff"||x==="files")&&b("chat")},[x,R,b]);const Tt=d.useMemo(()=>{const Te=[];return J&&Te.push({value:"instance",label:"Instance",icon:Cl}),Te.push({value:"usage",label:"Usage",icon:wd},{value:"mcp",label:"MCP",icon:Hu}),Te},[J]),Yt=d.useMemo(()=>Tt.map(Te=>({id:Te.value,label:Te.label,icon:s.jsx(Te.icon,{className:"h-3.5 w-3.5"})})),[Tt]),Ut=d.useMemo(()=>[{value:"usage",label:"Used"},{value:"remaining",label:"Remaining"}],[]),Es=d.useMemo(()=>Ut.map(Te=>({id:Te.value,label:Te.label})),[Ut]),Fs=d.useMemo(()=>[{id:"usage",label:"Usage",icon:s.jsx(wd,{className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(Rl,{className:"h-3.5 w-3.5"})}],[]);he.useEffect(()=>{const Te=Ie=>{if(Du(Ie)&&!Ie.shiftKey&&!Ie.altKey){const Ke=parseInt(Ie.key,10);Ke>=1&&Ke<=Xe.length&&(Ie.preventDefault(),b(Xe[Ke-1].id))}};return window.addEventListener("keydown",Te),()=>window.removeEventListener("keydown",Te)},[Xe,b]),he.useEffect(()=>{const Te=Ie=>{const Ke=ha("toggle_services_menu",v);if(Gn(Ie,Ke)){Ie.preventDefault(),Z?ie(!1):(ie(!0),Le(),Ne==="usage"&&B.length===0&&E());return}const Ve=ha("cycle_services_tab",v);if(Gn(Ie,Ve)){Ie.preventDefault();const Bt=Tt.map($t=>$t.value);if(Bt.length===0)return;const At=Bt.indexOf(Ne),mt=At===-1?0:(At+1)%Bt.length,Lt=Bt[mt];_e(Lt),ie(!0),Le(),Lt==="usage"&&B.length===0&&E();return}const ft=ha("toggle_context_plan",v);Gn(Ie,ft)&&(Ie.preventDefault(),Kt())};return window.addEventListener("keydown",Te),()=>window.removeEventListener("keydown",Te)},[v,Z,Ne,Tt,B.length,E,Le,Kt]);const ds=Te=>{const Ie=x===Te.id,Ke=Te.icon==="diff",Ve=Ke?null:Te.icon,ft=Te.id==="chat",Bt=mt=>Ke?s.jsx(O3,{size:mt}):Ve?s.jsx(Ve,{size:mt}):null,At=s.jsxs("button",{type:"button",onClick:()=>b(Te.id),className:Q("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Ie?"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",ft&&!R&&"min-w-[100px] justify-center"),"aria-label":Te.label,"aria-selected":Ie,role:"tab",children:[R?Bt(20):s.jsxs(s.Fragment,{children:[Bt(16),s.jsx("span",{className:"header-tab-label",children:Te.label})]}),Te.badge!==void 0&&Te.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:Te.badge})]});return s.jsx(d.Fragment,{children:At},Te.id)},es=()=>!W?.connected||R?null:le.length>1?s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:Q(Et,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),title:re?`GitHub: ${re}`:"GitHub connected",disabled:ae,children:K?s.jsx("img",{src:K,alt:re?`${re} avatar`:"GitHub avatar",className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(yl,{className:"h-3.5 w-3.5 text-foreground"})})}),s.jsxs(Ys,{align:"end",className:"w-64",children:[s.jsx(sa,{className:"typography-ui-header font-semibold text-foreground",children:"GitHub Accounts"}),s.jsx(Zn,{}),le.map(Te=>{const Ie=Te.user,Ke=!!Te.current;return s.jsxs(Jt,{className:"gap-2",disabled:Ke||ae,onSelect:()=>{Ke||Is(Te.id)},children:[Ie?.avatarUrl?s.jsx("img",{src:Ie.avatarUrl,alt:Ie.login?`${Ie.login} avatar`:"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(yl,{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:Ie?.name?.trim()||Ie?.login||"GitHub"}),Ie?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:Ie.login}):null]}),Ke?s.jsx(js,{className:"h-4 w-4 text-primary"}):null]},Te.id)})]})]}):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:re?`GitHub: ${re}`:"GitHub connected",children:K?s.jsx("img",{src:K,alt:re?`${re} avatar`:"GitHub avatar",className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(yl,{className:"h-3.5 w-3.5 text-foreground"})}),gs=s.jsxs(s.Fragment,{children:[ys&&s.jsxs(Dt,{delayDuration:500,children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":"Open plan",onClick:Kt,className:Q(Et,Ft&&"bg-[var(--interactive-hover)]"),children:s.jsx(M1,{className:"h-[18px] w-[18px]"})})}),s.jsx(_t,{children:s.jsxs("p",{children:["Plan (",yt("toggle_context_plan"),")"]})})]}),s.jsx(Vw,{directory:St,activeFilePath:Zt,className:"mr-1"}),s.jsxs(qs,{open:Z,onOpenChange:Te=>{ie(Te),Te&&(Le(),Ne==="usage"&&B.length===0&&E())},children:[s.jsxs(Dt,{delayDuration:500,children:[s.jsx(It,{asChild:!0,children:s.jsx(Gs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":J?`Open instance, usage and MCP (current: ${Se})`:"Open services, usage and MCP",className:Q(Et,J?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8"),children:[s.jsx(ya,{className:"h-[18px] w-[18px]"}),J?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:ye}):null]})})}),s.jsx(_t,{children:s.jsxs("p",{children:[J?`Current instance: ${Se}`:"Services"," (",yt("toggle_services_menu"),"; next tab ",yt("cycle_services_tab"),")"]})})]}),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:[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(Ro,{items:Yt,activeId:Ne,onSelect:Te=>{const Ie=Te;_e(Ie),Ie==="usage"&&B.length===0&&E()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),J&&Ne==="instance"?s.jsx(o8,{embedded:!0,open:Z&&Ne==="instance",onOpenChange:()=>{},onHostSwitched:()=>ie(!1)}):null,Ne==="mcp"?s.jsx(Dd,{active:Z&&Ne==="mcp"}):null,Ne==="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:"Rate limits"}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:v4(P)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Ro,{items:Es,activeId:D,onSelect:Te=>He(Te),layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:Q("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:Oe,disabled:I||pe,"aria-label":"Refresh rate limits",children:s.jsx(Qn,{className:Q("h-4 w-4",pe&&"animate-spin")})})]})]}),lt?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:"No rate limits available."})}),s.jsx("div",{className:"py-2",children:it.map((Te,Ie)=>{const Ke=rt[Te.providerId]??[];return s.jsxs(d.Fragment,{children:[Ie>0?s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(Mn,{providerId:Te.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Te.providerName})]}),Te.entries.length===0&&(!Te.modelFamilies||Te.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Te.error??"No rate limits reported."})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Te.entries.map(([Ve,ft])=>{const Bt=D==="remaining"?ft.remainingPercent:ft.usedPercent,At=ci(ft.usedPercent,ft.resetAt,ft.windowSeconds,Ve),mt=At?.dailyAllocationPercent!=null?D==="remaining"?100-Mo(At.elapsedRatio):Mo(At.elapsedRatio):null;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:i2(Ve)}),ft.resetAfterFormatted??ft.resetAtFormatted?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:ft.resetAfterFormatted??ft.resetAtFormatted}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Ao(Bt)==="-"?"":Ao(Bt)})]}),s.jsx(di,{percent:Bt,tonePercent:ft.usedPercent,className:"h-1.5",expectedMarkerPercent:mt}),At?s.jsx(ui,{paceInfo:At,compact:!0}):null]},`${Te.providerId}-${Ve}`)}),Te.modelFamilies&&Te.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:Te.modelFamilies.map(Ve=>{const ft=Ke.includes(Ve.familyId??"other");return s.jsxs(Jr,{open:ft,onOpenChange:()=>st(Te.providerId,Ve.familyId??"other"),children:[s.jsxs(vo,{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:Ve.familyLabel}),ft?s.jsx(Ds,{className:"h-4 w-4 text-muted-foreground"}):s.jsx(On,{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:Ve.models.map(([Bt,At])=>{const mt=D==="remaining"?At.remainingPercent:At.usedPercent,Lt=ci(At.usedPercent,At.resetAt,At.windowSeconds),$t=Lt?.dailyAllocationPercent!=null?D==="remaining"?100-Mo(Lt.elapsedRatio):Mo(Lt.elapsedRatio):null;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:c2(Bt)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Ao(mt)==="-"?"":Ao(mt)})]}),s.jsx(di,{percent:mt,tonePercent:At.usedPercent,className:"h-1.5",expectedMarkerPercent:$t}),Lt?s.jsx(ui,{paceInfo:Lt,compact:!0}):null]},`${Te.providerId}-${Bt}`)})})})]},Ve.familyId??"other")})}):null]})]},Te.providerId)})})]}):null]})]}),s.jsxs(Dt,{delayDuration:500,children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,"aria-label":"Toggle terminal panel",className:Et,children:s.jsx(Po,{className:"h-[18px] w-[18px]"})})}),s.jsx(_t,{children:s.jsxs("p",{children:["Terminal panel (",yt("toggle_terminal"),")"]})})]}),s.jsxs(Dt,{delayDuration:500,children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,"aria-label":"Toggle right sidebar",className:Et,children:s.jsx(vl,{className:"h-[18px] w-[18px]"})})}),s.jsx(_t,{children:s.jsxs("p",{children:["Right sidebar (",yt("toggle_right_sidebar"),")"]})})]}),es()]}),Ks=!c||!o,Rs=()=>s.jsxs("div",{onMouseDown:Ae,className:Q("app-region-drag relative flex h-12 select-none items-center pr-3",kt,as),role:"tablist","aria-label":"Main navigation",children:[i?null:s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ss,"aria-label":"Open sessions",className:`${Et} shrink-0`,children:s.jsx(ji,{className:"h-[18px] w-[18px]"})})}),s.jsx(_t,{children:s.jsxs("p",{children:["Open sessions (",yt("toggle_sidebar"),")"]})})]}),s.jsxs("div",{className:Q("flex min-w-0 flex-1 items-center",!i&&"pl-3"),children:[Ce?null:s.jsxs(Dt,{delayDuration:500,children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":"New session",onClick:Cs,className:Q(Et,"mr-6 shrink-0"),children:s.jsx(F1,{className:"h-[18px] w-[18px]"})})}),s.jsx(_t,{children:s.jsxs("p",{children:["New session (",yt("new_chat"),")"]})})]}),Wt&&s.jsx(p4,{projectRef:Wt.projectRef,directory:Wt.directory,className:"mr-2"}),S?null:s.jsxs("div",{className:"mr-3 min-w-0",children:[s.jsx("div",{className:"truncate pl-1 typography-ui-label text-[14px] font-normal leading-tight text-foreground",children:Ue}),M||Qe||Nt||qt?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 truncate pl-1 typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[M?s.jsx("span",{className:"truncate",children:M}):null,Qe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(on,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:Qe})]}):null,Nt?s.jsx("span",{className:"truncate",children:Nt}):null,qt?s.jsxs("span",{className:"inline-flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",jt.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",jt.deletions]})]}):null]}):null]}),Xe.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Xe.map(Te=>ds(Te))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[ze&&xe?s.jsx(G6,{totalTokens:xe.totalTokens,percentage:Ge,colorPercentage:xe.percentage,contextLimit:xe.contextLimit,outputLimit:xe.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:ut,pressed:Mt,className:Ks?"mr-3.5":"",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,Ks?gs:null,!Ks&&o?To.createPortal(gs,o):null]})]})]}),un=()=>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:t,className:Q(bt,n&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":n?"Close sessions":"Open sessions",children:s.jsx(ji,{className:"h-5 w-5"})}):H?s.jsx("button",{type:"button",onClick:()=>a(!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":"Back",children:s.jsx(J0,{className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:Ss,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":"Open sessions",children:s.jsx(t9,{className:"h-5 w-5"})}),H&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:"Sessions"})]}),!H&&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":"Main navigation",children:Xe.map(Te=>{const Ie=x===Te.id,Ke=Te.icon==="diff",Ve=Ke?null:Te.icon;return s.jsxs(Dt,{delayDuration:500,children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{R&&bs(),b(Te.id)},"aria-label":Te.label,"aria-selected":Ie,role:"tab",className:Q(bt,"relative rounded-lg",Ie&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Ke?s.jsx(O3,{className:"h-5 w-5"}):Ve?s.jsx(Ve,{className:"h-5 w-5"}):null,Te.badge!==void 0&&Te.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:Te.badge}),Te.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":"Changes available"})]})}),s.jsx(_t,{children:s.jsx("p",{children:Te.label})})]},Te.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[Wt&&s.jsx(p4,{projectRef:Wt.projectRef,directory:Wt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(qs,{open:be,onOpenChange:Te=>{oe(Te),Te&&B.length===0&&E()},children:[s.jsxs(Dt,{delayDuration:500,children:[s.jsx(It,{asChild:!0,children:s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":"View services",className:bt,children:s.jsx(ya,{className:"h-5 w-5"})})})}),s.jsx(_t,{children:s.jsx("p",{children:"Services"})})]}),s.jsx(Ys,{align:"end",sideOffset:0,className:"h-dvh w-[100vw] max-h-none rounded-none border-0 p-0 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(Ro,{items:Fs,activeId:de,onSelect:Te=>{const Ie=Te;we(Ie),Ie==="usage"&&B.length===0&&E()},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:()=>oe(!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":"Close services",children:s.jsx(Ps,{className:"h-5 w-5"})})]})}),de==="mcp"&&s.jsx(Dd,{active:be&&de==="mcp"}),de==="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:"Rate limits"}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:v4(P)})]}),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:()=>He("usage"),className:Q("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:"Used"}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>He("remaining"),className:Q("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:"Remaining"})]}),s.jsx("button",{type:"button",className:Q("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:Oe,disabled:I||pe,"aria-label":"Refresh rate limits",children:s.jsx(Qn,{className:Q("h-4 w-4",pe&&"animate-spin")})})]})]})}),!lt&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:"No rate limits available."})}),s.jsx("div",{className:"py-1",children:it.map((Te,Ie)=>s.jsxs(d.Fragment,{children:[Ie>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(Mn,{providerId:Te.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Te.providerName})]}),Te.entries.length===0&&(!Te.modelFamilies||Te.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Te.error??"No rate limits reported."})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Te.entries.map(([Ke,Ve])=>{const ft=D==="remaining"?Ve.remainingPercent:Ve.usedPercent,Bt=ci(Ve.usedPercent,Ve.resetAt,Ve.windowSeconds,Ke),At=Bt?.dailyAllocationPercent!=null?D==="remaining"?100-Mo(Bt.elapsedRatio):Mo(Bt.elapsedRatio):null;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:i2(Ke)}),Ve.resetAfterFormatted??Ve.resetAtFormatted?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Ve.resetAfterFormatted??Ve.resetAtFormatted}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Ao(ft)==="-"?"":Ao(ft)})]}),s.jsx(di,{percent:ft,tonePercent:Ve.usedPercent,className:"h-1.5",expectedMarkerPercent:At}),Bt?s.jsx(ui,{paceInfo:Bt,compact:!0}):null]},`${Te.providerId}-${Ke}`)}),Te.modelFamilies&&Te.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Te.modelFamilies.map(Ke=>{const ft=(rt[Te.providerId]??[]).includes(Ke.familyId??"other");return s.jsxs(Jr,{open:ft,onOpenChange:()=>st(Te.providerId,Ke.familyId??"other"),children:[s.jsxs(vo,{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:Ke.familyLabel}),ft?s.jsx(Ds,{className:"h-4 w-4 text-muted-foreground"}):s.jsx(On,{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:Ke.models.map(([Bt,At])=>{const mt=D==="remaining"?At.remainingPercent:At.usedPercent,Lt=ci(At.usedPercent,At.resetAt,At.windowSeconds),$t=Lt?.dailyAllocationPercent!=null?D==="remaining"?100-Mo(Lt.elapsedRatio):Mo(Lt.elapsedRatio):null;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:c2(Bt)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Ao(mt)==="-"?"":Ao(mt)})]}),s.jsx(di,{percent:mt,tonePercent:At.usedPercent,className:"h-1.5",expectedMarkerPercent:$t}),Lt?s.jsx(ui,{paceInfo:Lt,compact:!0}):null]},`${Te.providerId}-${Bt}`)})})})]},Ke.familyId??"other")})})]})]},Te.providerId))})]})]})})]}),e?s.jsxs(Dt,{delayDuration:500,children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:Q(bt,"relative",r&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(vl,{className:"h-5 w-5"})})}),s.jsx(_t,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),zn=Q("header-safe-area relative z-10",R&&"border-b border-border/50",R||J?"bg-background":"bg-background/95 supports-[backdrop-filter]:bg-background/80");return s.jsx("header",{ref:Y,className:zn,style:{"--padding-scale":"1"},children:R?un():Rs()})},wc=180,jc=640,Nj=110,Sj=t=>{const e=Fe.c(55),{isOpen:n,isMobile:r,children:o}=t,a=Ee(Cj),l=Ee(Aj),i=Ee(Mj),c=Ee(Fj),u=Ee(Bj),[m,f]=d.useState(null),[h,p]=d.useState(!1),g=d.useRef(null),x=d.useRef(0),b=d.useRef(a||300),v=d.useRef(a||300),y=Math.min(jc,Math.max(wc,a||300));let w,C;e[0]!==n?(w=()=>{n||(f(null),p(!1))},C=[n],e[0]=n,e[1]=w,e[2]=C):(w=e[1],C=e[2]),d.useEffect(w,C);let N,S;e[3]!==l||e[4]!==r||e[5]!==n?(N=()=>{if(r||!n||!l)return;const X=()=>{const ee=g.current?.parentElement?.getBoundingClientRect().height;if(!ee||ee<=0)return;const ce=Math.max(0,Math.round(ee));f(ve=>ve===ce?ve:ce)};X();const $=g.current?.parentElement;if(!$)return;const q=new ResizeObserver(X);return q.observe($),()=>{q.disconnect()}},S=[l,r,n],e[3]=l,e[4]=r,e[5]=n,e[6]=N,e[7]=S):(N=e[6],S=e[7]),d.useEffect(N,S);let k,j;if(e[8]!==l||e[9]!==r||e[10]!==h||e[11]!==i||e[12]!==c?(k=()=>{if(r||!h||l)return;const X=q=>{const ee=x.current-q.clientY,ce=Math.min(jc,Math.max(wc,b.current+ee));i(ce)},$=()=>{p(!1),Ee.getState().bottomTerminalHeight<=Nj&&c(!1)};return window.addEventListener("pointermove",X),window.addEventListener("pointerup",$,{once:!0}),()=>{window.removeEventListener("pointermove",X),window.removeEventListener("pointerup",$)}},j=[l,r,h,i,c],e[8]=l,e[9]=r,e[10]=h,e[11]=i,e[12]=c,e[13]=k,e[14]=j):(k=e[13],j=e[14]),d.useEffect(k,j),r)return null;const F=n?l?Math.max(0,m??y):y:0;let A;e[15]!==F||e[16]!==l||e[17]!==n?(A=X=>{!n||l||(p(!0),x.current=X.clientY,b.current=F,X.preventDefault())},e[15]=F,e[16]=l,e[17]=n,e[18]=A):A=e[18];const M=A;let B;e[19]!==l||e[20]!==n||e[21]!==u||e[22]!==i||e[23]!==y?(B=()=>{if(n){if(l){u(!1);const X=Math.min(jc,Math.max(wc,v.current));i(X);return}v.current=y,u(!0)}},e[19]=l,e[20]=n,e[21]=u,e[22]=i,e[23]=y,e[24]=B):B=e[24];const E=B,I=h?"transition-none":"transition-[height] duration-300 ease-in-out",P=!n&&"border-t-0";let D;e[25]!==P||e[26]!==I?(D=Q("relative flex overflow-hidden border-t border-border bg-sidebar",I,P),e[25]=P,e[26]=I,e[27]=D):D=e[27];const L=`${F}px`,T=`${F}px`,_=`${F}px`;let z;e[28]!==L||e[29]!==T||e[30]!==_?(z={height:L,minHeight:T,maxHeight:_},e[28]=L,e[29]=T,e[30]=_,e[31]=z):z=e[31];const R=!n||F===0;let W;e[32]!==M||e[33]!==l||e[34]!==n||e[35]!==h?(W=n&&!l&&s.jsx("div",{className:Q("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",h&&"bg-[var(--interactive-border)]"),onPointerDown:M,role:"separator","aria-orientation":"horizontal","aria-label":"Resize terminal panel"}),e[32]=M,e[33]=l,e[34]=n,e[35]=h,e[36]=W):W=e[36];let G;e[37]!==l||e[38]!==n||e[39]!==c||e[40]!==E?(G=n&&s.jsxs("div",{className:"absolute right-2 top-2 z-30 inline-flex items-center gap-1",children:[s.jsx("button",{type:"button",onClick:E,className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",title:l?"Restore terminal panel height":"Expand terminal panel","aria-label":l?"Restore terminal panel height":"Expand terminal panel",children:l?s.jsx(e2,{className:"h-5 w-5"}):s.jsx(T2,{className:"h-5 w-5"})}),s.jsx("button",{type:"button",onClick:()=>c(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",title:"Close terminal panel","aria-label":"Close terminal panel",children:s.jsx(Ps,{className:"h-6 w-6"})})]}),e[37]=l,e[38]=n,e[39]=c,e[40]=E,e[41]=G):G=e[41];const Y=!n&&"pointer-events-none select-none opacity-0";let J;e[42]!==Y?(J=Q("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",Y),e[42]=Y,e[43]=J):J=e[43];const V=!n;let te;e[44]!==o||e[45]!==J||e[46]!==V?(te=s.jsx("div",{className:J,"aria-hidden":V,children:o}),e[44]=o,e[45]=J,e[46]=V,e[47]=te):te=e[47];let U;return e[48]!==D||e[49]!==z||e[50]!==R||e[51]!==W||e[52]!==G||e[53]!==te?(U=s.jsxs("section",{ref:g,className:D,style:z,"aria-hidden":R,children:[W,G,te]}),e[48]=D,e[49]=z,e[50]=R,e[51]=W,e[52]=G,e[53]=te,e[54]=U):U=e[54],U};function Cj(t){return t.bottomTerminalHeight}function Aj(t){return t.isBottomTerminalExpanded}function Mj(t){return t.setBottomTerminalHeight}function Fj(t){return t.setBottomTerminalOpen}function Bj(t){return t.setBottomTerminalExpanded}function Wu(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-none",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx("div",{"data-slot":"card",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function f8(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx("div",{"data-slot":"card-header",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function m8(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("leading-none font-semibold",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx("div",{"data-slot":"card-title",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function h8(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("px-6",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx("div",{"data-slot":"card-content",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}class An extends d.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n,copied:!1}),console.error("Error caught by boundary:",e,n)}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};handleCopy=async()=>{const e=this.state.error?String(this.state.error):"Unknown error",n=this.state.error?.stack?`
4
4
 
5
5
  Stack:
@@ -7550,7 +7550,7 @@ ${ct}`;U(Qe)},[V,U]),qe=d.useCallback(Ue=>{if(Ue.stopPropagation(),Ue.preventDef
7550
7550
  ${at.cssText}
7551
7551
  transform: none;
7552
7552
  contain: none;
7553
- `;const Pt=Zt.querySelectorAll('[aria-label^="Message time:"]'),cs=new Set;Pt.forEach(ls=>{const ys=ls.getAttribute("aria-label")?.replace("Message time:","").trim();if(!ys||ls.textContent?.includes(ys))return;const ws=document.createElement("span");ws.style.marginLeft="4px",ws.textContent=ys,ls.appendChild(ws);const Is=ls.parentElement,bs=Is?.parentElement,Ss=bs?.firstElementChild;!bs||!Ss||Ss===Is||cs.has(bs)||(Ss.style.display="none",bs.style.justifyContent="flex-start",cs.add(bs))}),ct.appendChild(Zt),document.body.appendChild(ct);const ss=await lx(ct,{quality:1,pixelRatio:2,backgroundColor:jt}),Wt=`message-${t}.png`;if(xn()){const ls=await fetch("/api/vscode/save-image",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileName:Wt,dataUrl:ss})});if(!ls.ok)throw new Error("Failed to save image in VS Code");const us=await ls.json();if(us.saved!==!0){if(us.canceled)return;throw new Error(us.error||"Failed to save image in VS Code")}}else{const ls=document.createElement("a");ls.download=Wt,ls.href=ss,document.body.appendChild(ls),ls.click(),document.body.removeChild(ls)}fe.success("Image saved")}catch(Qe){console.error("Failed to generate image:",Qe),fe.error("Failed to generate image")}finally{ct&&ct.parentNode&&ct.parentNode.removeChild(ct),st(!1)}},[t,rt]);d.useEffect(()=>()=>{je()},[je]);const lt=d.useMemo(()=>{const Ue=C?.activityParts;return!$||!Ue?[]:Ue},[$,C?.activityParts]),He=d.useMemo(()=>{const Ue=C?.activityGroupSegments;return!$||!Ue?[]:Ue.filter(ct=>ct.anchorMessageId===t)},[$,t,C?.activityGroupSegments]),Oe=d.useMemo(()=>{const Ue=new Map,ct=new Map;return lt.forEach(Qe=>{Ue.set(Qe.part,Qe);const at=Qe.part.id;typeof at=="string"&&at.length>0&&ct.set(at,Qe)}),{get:Qe=>{const at=Ue.get(Qe);if(at)return at;const Nt=Qe.id;if(typeof Nt=="string"&&Nt.length>0)return ct.get(Nt)}}},[lt]),se=C?.toggleGroup,Pe=$&&He.length>0&&!!se,Ye=d.useMemo(()=>{const Ue=[];Pe&&se&&He.forEach(Qe=>{const at=w?Qe.parts:Qe.parts.filter(Nt=>Nt.kind!=="reasoning");at.length!==0&&Ue.push(s.jsx("div",{className:"mb-3",children:s.jsx(ME,{parts:at,isExpanded:C.isGroupExpanded===!0,collapsedPreviewCount:q,onToggle:se,syntaxTheme:l,isMobile:i,expandedTools:u,onToggleTool:m,onShowPopup:f,onContentChange:g,streamPhase:S,showHeader:!0,animateRows:D,animatedToolIds:J,diffStats:C.diffStats})},`progressive-group-${Qe.id}`))});let ct=0;for(;ct<L.length;){const Qe=L[ct];if(Qe.type==="text"){const at=Oe.get(Qe);if($&&!ce){ct+=1;continue}if(at?.kind==="justification"){ct+=1;continue}Ue.push(s.jsx(F_,{part:Qe,messageId:t,streamPhase:S,chatRenderMode:X,onContentChange:g},`assistant-text-${t}-${ct}`)),ct++;continue}if(Qe.type==="reasoning"){const at=Oe.get(Qe);if($&&!ce){ct+=1;continue}if(at?.kind==="reasoning"){ct+=1;continue}if(w)if($)Ue.push(s.jsx(Sp,{part:Qe,messageId:t,onContentChange:g},`reasoning-${t}-${ct}`));else{const Nt=Qe.text;Nt&&Nt.trim().length>0&&Ue.push(s.jsx(ga,{children:s.jsx("div",{className:"my-0.5 text-sm text-muted-foreground/60 italic leading-relaxed whitespace-pre-wrap",children:Nt})},`reasoning-${t}-${ct}`))}ct++;continue}if(Qe.type==="tool"){const at=Qe,Nt=at.tool?.toLowerCase()??"";if(Oe.get(Qe)?.kind==="tool"&&!l3(Nt)){ct+=1;continue}if(!ue(at)){ct++;continue}if(a3(Nt)){Ue.push(s.jsx(ga,{children:s.jsx(v2,{animate:J.has(at.id),wipe:!0,children:s.jsx(Xd,{part:at,isExpanded:u.has(at.id),onToggle:m,syntaxTheme:l,isMobile:i,onContentChange:g,onShowPopup:f,animateTailText:J.has(at.id)})})},`tool-${at.id}`)),ct++;continue}Ue.push(s.jsx(ga,{children:s.jsx(v2,{animate:J.has(at.id),wipe:!0,children:s.jsx(Bp,{toolName:Nt,activities:[{id:at.id,turnId:"",messageId:t,partIndex:0,part:at,kind:"tool"}],animateTailText:J.has(at.id)})})},`static-tools-${at.id}`)),ct++;continue}ct++}return Ue},[Oe,He,J,D,X,q,u,ce,i,$,t,g,f,m,Pe,ue,S,w,l,se,C,L]),We=!!N,xt=ee&&x&&(ce||!!N),et=d.useMemo(()=>{if(!ee||!ce)return;const Ue=C?.userMessageCreatedAt;if(!(typeof Ue!="number"||typeof o!="number")&&!(o<=Ue))return EE(o-Ue)},[ee,ce,C?.userMessageCreatedAt,o]),tt=d.useMemo(()=>{const Ue=typeof o=="number"&&o>0?o:typeof a=="number"&&a>0?a:null;if(Ue===null)return null;const ct=Q_(Ue);return ct.length>0?ct:null},[o,a]),ht="text-sm text-muted-foreground/60 tabular-nums flex items-center gap-1",St=s.jsxs(s.Fragment,{children:[b&&s.jsxs(Dt,{delayDuration:1e3,children:[s.jsx(It,{asChild:!0,children:s.jsx(Be,{type:"button",variant:"ghost",size:"icon","data-visible":k||E?"true":void 0,className:Q("h-8 w-8 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50",!we&&"opacity-50"),disabled:!we,"aria-label":"Copy message text","aria-hidden":!we,onPointerDown:Ue=>Ue.stopPropagation(),onClick:ze,onFocus:()=>{we&&j(!0)},onBlur:()=>{E||j(!1)},children:E?s.jsx(js,{className:"h-3.5 w-3.5 text-[color:var(--status-success)]"}):s.jsx(nr,{className:"h-3.5 w-3.5"})})}),s.jsx(_t,{sideOffset:6,children:"Copy answer"})]}),s.jsxs(Dt,{delayDuration:1e3,children:[s.jsx(It,{asChild:!0,children:s.jsx(Be,{type:"button",size:"icon",variant:"ghost",disabled:rt||!we,className:Q("h-8 w-8 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50",(!we||rt)&&"opacity-50"),onPointerDown:Ue=>Ue.stopPropagation(),onClick:it,children:rt?s.jsx(ts,{className:"h-4 w-4 animate-spin"}):s.jsx(ix,{className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:rt?"Saving image...":"Save as image"})]}),s.jsxs(Dt,{delayDuration:1e3,children:[s.jsx(It,{asChild:!0,children:s.jsx(Be,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50",onPointerDown:Ue=>Ue.stopPropagation(),onClick:Ge,children:s.jsx(F1,{className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:"Start new session from this answer"})]}),s.jsxs(Dt,{delayDuration:1e3,children:[s.jsx(It,{asChild:!0,children:s.jsx(Be,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50",onPointerDown:Ue=>Ue.stopPropagation(),onClick:Le,children:s.jsx(Ap,{className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:"Start new multi-run from this answer"})]}),ne&&we&&s.jsxs(Dt,{delayDuration:1e3,children:[s.jsx(It,{asChild:!0,children:s.jsx(Be,{type:"button",variant:"ghost",size:"icon",className:Q("h-8 w-8 bg-transparent hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50",ve?"text-green-500":"text-muted-foreground hover:text-foreground"),"aria-label":ve?"Stop speaking":"Read aloud",onPointerDown:Ue=>Ue.stopPropagation(),onClick:qe,children:ve?s.jsx(Xo,{className:"h-3.5 w-3.5"}):s.jsx(vu,{className:"h-3.5 w-3.5"})})}),s.jsx(_t,{sideOffset:6,children:H})]})]});return s.jsxs("div",{ref:A,className:Q("relative w-full group/message"),style:{contain:"layout",transform:"translateZ(0)"},onTouchStart:I&&B&&we?Ce:void 0,children:[s.jsx(W_,{containerRef:A}),s.jsxs("div",{children:[s.jsxs("div",{className:"message-content-text leading-relaxed overflow-hidden text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0",children:[Ye,We&&s.jsx(ga,{children:s.jsx("div",{className:"group/assistant-text relative break-words",children:s.jsx(yo,{content:N??"",onShowPopup:f})})},"assistant-error")]}),s.jsx(Zu,{files:e,onShowPopup:f}),xt&&s.jsxs("div",{className:"mt-2 mb-1 flex items-center justify-start gap-1.5",children:[s.jsx("div",{className:"flex items-center gap-1.5",children:St}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[et?s.jsxs("span",{className:"text-sm text-muted-foreground/60 tabular-nums flex items-center gap-1",children:[s.jsx(cx,{className:"h-3.5 w-3.5"}),et]}):null,tt?s.jsxs("span",{className:ht,"aria-label":`Message time: ${tt}`,children:[s.jsx(bo,{className:"h-3.5 w-3.5"}),tt]}):null]})]})]})]})},RE=t=>{const e=Fe.c(19);let n,r;if(e[0]!==t?({isUser:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),n){let a;return e[3]!==r.agentMention||e[4]!==r.copiedMessage||e[5]!==r.hasTextContent||e[6]!==r.hasTouchInput||e[7]!==r.isMobile||e[8]!==r.messageId||e[9]!==r.onCopyMessage||e[10]!==r.onFork||e[11]!==r.onRevert||e[12]!==r.onShowPopup||e[13]!==r.parts||e[14]!==r.stickyUserHeaderEnabled||e[15]!==r.userActionsMode?(a=s.jsx(TE,{messageId:r.messageId,parts:r.parts,isMobile:r.isMobile,hasTouchInput:r.hasTouchInput,hasTextContent:r.hasTextContent,onCopyMessage:r.onCopyMessage,copiedMessage:r.copiedMessage,onShowPopup:r.onShowPopup,agentMention:r.agentMention,onRevert:r.onRevert,onFork:r.onFork,userActionsMode:r.userActionsMode,stickyUserHeaderEnabled:r.stickyUserHeaderEnabled}),e[3]=r.agentMention,e[4]=r.copiedMessage,e[5]=r.hasTextContent,e[6]=r.hasTouchInput,e[7]=r.isMobile,e[8]=r.messageId,e[9]=r.onCopyMessage,e[10]=r.onFork,e[11]=r.onRevert,e[12]=r.onShowPopup,e[13]=r.parts,e[14]=r.stickyUserHeaderEnabled,e[15]=r.userActionsMode,e[16]=a):a=e[16],a}let o;return e[17]!==r?(o=s.jsx(PE,{...r}),e[17]=r,e[18]=o):o=e[18],o},Hc=d.memo(RE);function zE(t){return t.setCurrentSession}function LE(t){return!t}function HE(t){return!t}const Dl=t=>{const e=t,n=e?.clientRole,r=e?.role;return e?.userMessageMarker===!0||n==="user"||r==="user"||e?.origin==="user"||e?.source==="user"?{role:"user",isUser:!0}:{role:n||r||"assistant",isUser:!1}},_p="GitHub issue context (JSON)",Ep="GitHub pull request context (JSON)",Of=t=>typeof t=="number"&&Number.isFinite(t)&&t>0,Vf=(t,e)=>{const n=t.trimStart();if(!n.startsWith(e))return null;const r=n.indexOf("{");if(r<0)return null;try{return JSON.parse(n.slice(r))}catch{return null}},$E=t=>{const e=Vf(t,_p);if(e){const r=e.issue,o=r?.number,a=r?.title,l=r?.url;return!Of(o)||typeof a!="string"||typeof l!="string"?null:{type:"file",mime:"application/vnd.github.issue-link",filename:`Issue #${o}: ${a}`,url:l}}const n=Vf(t,Ep);if(n){const r=n.pr,o=r?.number,a=r?.title,l=r?.url;return!Of(o)||typeof a!="string"||typeof l!="string"?null:{type:"file",mime:"application/vnd.github.pull-request-link",filename:`PR #${o}: ${a}`,url:l}}return null},OE=t=>{const e=t.trim();return!!(e.startsWith("User has requested to enter plan mode")||e.startsWith("The plan at ")||e.startsWith("The following tool was executed by the user"))},VE=t=>t.filter(e=>{if(!(e.synthetic===!0))return!0;if(e.type!=="text")return!1;const r=e.text;if(typeof r!="string")return!1;const o=r.trimStart();return OE(r)||o.startsWith(_p)||o.startsWith(Ep)}).map(e=>{const n=e;if(n.type==="compaction")return{type:"text",text:"/compact"};if(n.type==="text"){const r=typeof n.text=="string"?n.text.trim():"";if(n.synthetic===!0){const a=$E(r);if(a)return a}if(r.startsWith("The following tool was executed by the user"))return{type:"text",text:"/shell"}}return e}),UE=d.lazy(()=>Kn(()=>import("./ToolOutputDialog-CzWxL8w8.js"),__vite__mapDeps([2,0,1,3,4]))),Dp=4e3,si=new Map,ni=new Map,WE=new Set(["bash","shell","cmd","terminal"]),qE=new Set(["apply_patch","edit","write","multiedit","str_replace","str_replace_based_edit_tool","create","file_write"]),GE=t=>{if(typeof t!="string")return"";const e=t.trim().toLowerCase();if(!e)return"";const n=e.replace(/:\d+$/,"");if(!n.includes("."))return n;const r=n.split(".").filter(Boolean);return r[r.length-1]??n},Uf=t=>{const e=si.get(t);return e?new Set(e):new Set},Wf=(t,e)=>{if(si.size>=Dp&&!si.has(t)){const n=si.keys().next().value;typeof n=="string"&&si.delete(n)}si.set(t,new Set(e))},qf=t=>{const e=ni.get(t);return e?new Set(e):new Set},Gf=(t,e)=>{if(ni.size>=Dp&&!ni.has(t)){const n=ni.keys().next().value;typeof n=="string"&&ni.delete(n)}ni.set(t,new Set(e))};function $c(t){const e=Fe.c(3),[n,r]=d.useState(t);let o,a;return e[0]!==t?(o=()=>{t!=null&&r(t)},a=[t],e[0]=t,e[1]=o,e[2]=a):(o=e[1],a=e[2]),d.useEffect(o,a),t??n}const lo=(t,e)=>{if(typeof t=="object"&&t!==null)return t[e]},ZE=({message:t,previousMessage:e,nextMessage:n,onContentChange:r,animationHandlers:o,turnGroupingContext:a,animateUserOnMount:l=!1,onUserAnimationConsumed:i})=>{const{isMobile:c,hasTouchInput:u}=wn(),{currentTheme:m}=qn(),f=d.useRef(null),h=Ze($r(ut=>({lifecyclePhase:ut.messageStreamStates.get(t.info.id)?.phase??null,isStreamingMessage:(()=>{const Mt=t.info.sessionID??ut.currentSessionId??null;return Mt?(ut.streamingMessageIds.get(Mt)??null)===t.info.id:!1})(),currentSessionId:ut.currentSessionId,getAgentModelForSession:ut.getAgentModelForSession,getSessionModelSelection:ut.getSessionModelSelection,revertToMessage:ut.revertToMessage,forkFromMessage:ut.forkFromMessage}))),{lifecyclePhase:p,isStreamingMessage:g,currentSessionId:x,getAgentModelForSession:b,getSessionModelSelection:v,revertToMessage:y,forkFromMessage:w}=h,C=rs(ut=>ut.providers),{showReasoningTraces:N,stickyUserHeader:S,chatRenderMode:k,showExpandedBashTools:j,showExpandedEditTools:F}=Ee($r(ut=>({showReasoningTraces:ut.showReasoningTraces,stickyUserHeader:ut.stickyUserHeader,chatRenderMode:ut.chatRenderMode,showExpandedBashTools:ut.showExpandedBashTools,showExpandedEditTools:ut.showExpandedEditTools})));d.useEffect(()=>{x&&Oa.getInstance().recordSessionStart(x)},[x]);const[A,M]=d.useState(null),[B,E]=d.useState(!1),[I,P]=d.useState(()=>Uf(t.info.id)),[D,L]=d.useState(()=>qf(t.info.id)),[T,_]=d.useState({open:!1,title:"",content:""});d.useEffect(()=>{P(Uf(t.info.id)),L(qf(t.info.id))},[t.info.id]);const R=d.useMemo(()=>Dl(t.info),[t.info]).isUser,W=R&&(c||!S),G=R&&!c&&S&&!W,Y=t.info.sessionID,{currentContextAgent:J,savedSessionAgentSelection:V}=sr($r(ut=>({currentContextAgent:Y?ut.currentAgentContext.get(Y):void 0,savedSessionAgentSelection:Y?ut.sessionAgentSelections.get(Y):void 0}))),te=d.useMemo(()=>R?VE(t.parts):t.parts,[R,t.parts]),U=d.useMemo(()=>{if(R||!e)return null;const ut=lo(e.info,"clientRole"),Mt=lo(e.info,"role");if((typeof ut=="string"?ut:typeof Mt=="string"?Mt:void 0)!=="user")return null;const Ft=lo(e.info,"mode"),Et=lo(e.info,"agent"),bt=lo(e.info,"providerID"),kt=lo(e.info,"modelID"),as=lo(e.info,"variant"),Gt=typeof Ft=="string"&&Ft.trim().length>0?Ft:typeof Et=="string"&&Et.trim().length>0?Et:void 0,Ae=typeof bt=="string"&&bt.trim().length>0?bt:void 0,Xe=typeof kt=="string"&&kt.trim().length>0?kt:void 0,yt=typeof as=="string"&&as.trim().length>0?as:void 0;return!Gt&&!Ae&&!Xe&&!yt?null:{agentName:Gt,providerId:Ae,modelId:Xe,variant:yt}},[R,e]),X=d.useMemo(()=>{if(R||!e)return!1;const ut=Array.isArray(e.parts)?e.parts:[];for(let Mt=0;Mt<ut.length;Mt++){const Kt=ut[Mt];if(Kt?.type!=="text"||Kt?.synthetic!==!0)continue;const Ft=typeof Kt.text=="string"?Kt.text.trim():"";if(Ft.startsWith("User has requested to enter plan mode")||Ft.startsWith("The plan at "))return!0}return!1},[R,e]),$=d.useMemo(()=>{if(R)return;const ut=t.info.time;if(!(typeof ut?.completed=="number"&&ut.completed>0)&&X&&U?.agentName)return U.agentName;const Kt=lo(t.info,"mode");if(typeof Kt=="string"&&Kt.trim().length>0)return Kt;const Ft=lo(t.info,"agent");if(typeof Ft=="string"&&Ft.trim().length>0)return Ft;if(U?.agentName)return U.agentName;if(Y)return J||(V??void 0)},[R,t.info,X,U,Y,J,V]),q=R?null:lo(t.info,"providerID"),ee=R?null:lo(t.info,"modelID"),ce=d.useMemo(()=>{if(R||!Y)return null;if(U?.providerId&&U?.modelId)return{providerId:U.providerId,modelId:U.modelId};if($){const Mt=b(Y,$);if(Mt?.providerId&&Mt?.modelId)return Mt}const ut=v(Y);return ut?.providerId&&ut?.modelId?ut:null},[R,Y,$,U,b,v]),ve=d.useMemo(()=>R?null:typeof q=="string"&&q.trim().length>0?q:ce?.providerId??null,[R,q,ce]),ge=d.useMemo(()=>R?null:typeof ee=="string"&&ee.trim().length>0?ee:ce?.modelId??null,[R,ee,ce]),xe=d.useMemo(()=>{if(!R&&ve&&ge&&C.length>0){const ut=C.find(Mt=>Mt.id===ve);if(ut?.models&&Array.isArray(ut.models)){const Ft=ut.models.find(Et=>Et.id===ge)?.name;return typeof Ft=="string"?Ft:void 0}}},[R,ve,ge,C]),ne=d.useMemo(()=>{if(R||!ve||!ge)return!1;const ut=C.find(Ft=>Ft.id===ve);if(!ut?.models||!Array.isArray(ut.models))return!1;const Kt=ut.models.find(Ft=>Ft.id===ge)?.variants;return!!(Kt&&Object.keys(Kt).length>0)},[R,ge,ve,C]),O=$c($),H=$c(ve??void 0),K=$c(xe),re=O??void 0,le=H??null,ae=K??void 0,ue=d.useMemo(()=>{const ut=t.info.time;return typeof ut?.completed=="number"?ut.completed:null},[t.info.time]),be=d.useMemo(()=>{const ut=t.info.time;return typeof ut?.created=="number"?ut.created:null},[t.info.time]),oe=d.useMemo(()=>R?!0:!!(ue&&ue>0),[R,ue]),Z=d.useMemo(()=>{const ut=t.info.finish;return typeof ut=="string"?ut:void 0},[t.info]),ie=d.useMemo(()=>z_(te,{includeReasoning:N}),[te,N]),pe=d.useMemo(()=>R?ie:!oe&&k==="sorted"?[]:ie,[k,oe,R,ie]),me=d.useMemo(()=>R?[]:ie.filter(ut=>ut.type==="text"),[R,ie]),Se=d.useMemo(()=>R?[]:ie.filter(Mt=>Mt.type==="tool"),[R,ie]),ke=d.useMemo(()=>R?[]:(a?.activityParts??[]).filter(Mt=>Mt.kind==="tool").map(Mt=>Mt.part).filter(Mt=>Mt.type==="tool"),[R,a?.activityParts]),ye=d.useMemo(()=>{if(!j&&!F)return new Set;const ut=new Set;for(const Mt of[...Se,...ke]){const Kt=typeof Mt?.id=="string"?Mt.id:"";if(!Kt)continue;const Ft=GE(Mt.tool);if(Ft){if(j&&WE.has(Ft)){ut.add(Kt);continue}F&&qE.has(Ft)&&ut.add(Kt)}}return ut},[j,F,Se,ke]),Ne=d.useMemo(()=>{if(ye.size===0&&D.size===0)return I;const ut=new Set(I);return ye.forEach(Mt=>{D.has(Mt)||ut.add(Mt)}),D.forEach(Mt=>{ut.delete(Mt)}),ut},[D,ye,I]),_e=d.useMemo(()=>{if(!R)return;const ut=t.parts.find(Et=>Et.type==="agent");if(!ut)return;const Mt=ut,Kt=typeof Mt.name=="string"?Mt.name:void 0;if(!Kt)return;const Ft=Mt.source&&typeof Mt.source.value=="string"&&Mt.source.value.trim().length>0?Mt.source.value:`@${Kt}`;return{name:Kt,token:Ft}},[R,t.parts]),de=R&&pe.length===0,we=typeof Z!="string",je=d.useMemo(()=>R?!1:me.length===0||Se.length===0?we:!0,[me.length,Se.length,we,R]),Ce=m?.metadata.variant,ze=d.useMemo(()=>Ce?Ce==="dark":typeof document<"u"?document.documentElement.classList.contains("dark"):!1,[Ce]),Ge=d.useMemo(()=>m?sc(m):ze?GC:ZC,[m,ze]),Le=d.useMemo(()=>R?!1:Oa.getInstance().shouldAnimateMessage(t.info,x||t.info.sessionID),[t.info,x,R]),[qe,rt]=d.useState(!1),st=d.useMemo(()=>n?Dl(n.info):null,[n]),it=!!a,lt=a?.isLastAssistantInTurn??!1,He=d.useMemo(()=>R?!1:it?!lt:st?!st.isUser&&st.role==="assistant":!1,[it,lt,R,st]),Oe=d.useMemo(()=>oe?"completed":p||(g?"streaming":"completed"),[oe,p,g]);d.useEffect(()=>{!R||!l||i?.(t.info.id)},[l,R,t.info.id,i]),d.useEffect(()=>{rt(!1)},[t.info.id]),d.useEffect(()=>{const ut=a?.headerMessageId;if(R||!ut||ut!==t.info.id)return;(Oe==="streaming"||Oe==="cooldown")&&rt(!0)},[R,t.info.id,Oe,a?.headerMessageId]);const se=d.useMemo(()=>{if(R)return!0;const ut=a?.headerMessageId;return ut?t.info.id===ut?Oe==="completed"?!0:qe||(Oe==="streaming"||Oe==="cooldown"):!1:!0},[qe,R,a,Oe,t.info.id]),Pe=d.useCallback(ut=>{Dn(ut).then(Mt=>{Mt.ok&&(M(ut),setTimeout(()=>M(null),2e3))})},[]),Ye=R?void 0:a?.userMessageVariant??U?.variant,We=!R&&ne?Ye??"Default":void 0,xt=d.useMemo(()=>{if(R)return;const ut=t.info?.error;if(!ut)return;const Mt=typeof ut.data?.message=="string"?ut.data.message:void 0,Kt=typeof ut.message=="string"?ut.message:void 0,Ft=typeof ut.name=="string"?ut.name:void 0,Et=Mt||Kt||Ft;if(Et)return Ft==="SessionRetry"?`Opencode failed to send a message. Retry attempt info:
7553
+ `;const Pt=Zt.querySelectorAll('[aria-label^="Message time:"]'),cs=new Set;Pt.forEach(ls=>{const ys=ls.getAttribute("aria-label")?.replace("Message time:","").trim();if(!ys||ls.textContent?.includes(ys))return;const ws=document.createElement("span");ws.style.marginLeft="4px",ws.textContent=ys,ls.appendChild(ws);const Is=ls.parentElement,bs=Is?.parentElement,Ss=bs?.firstElementChild;!bs||!Ss||Ss===Is||cs.has(bs)||(Ss.style.display="none",bs.style.justifyContent="flex-start",cs.add(bs))}),ct.appendChild(Zt),document.body.appendChild(ct);const ss=await lx(ct,{quality:1,pixelRatio:2,backgroundColor:jt}),Wt=`message-${t}.png`;if(xn()){const ls=await fetch("/api/vscode/save-image",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileName:Wt,dataUrl:ss})});if(!ls.ok)throw new Error("Failed to save image in VS Code");const us=await ls.json();if(us.saved!==!0){if(us.canceled)return;throw new Error(us.error||"Failed to save image in VS Code")}}else{const ls=document.createElement("a");ls.download=Wt,ls.href=ss,document.body.appendChild(ls),ls.click(),document.body.removeChild(ls)}fe.success("Image saved")}catch(Qe){console.error("Failed to generate image:",Qe),fe.error("Failed to generate image")}finally{ct&&ct.parentNode&&ct.parentNode.removeChild(ct),st(!1)}},[t,rt]);d.useEffect(()=>()=>{je()},[je]);const lt=d.useMemo(()=>{const Ue=C?.activityParts;return!$||!Ue?[]:Ue},[$,C?.activityParts]),He=d.useMemo(()=>{const Ue=C?.activityGroupSegments;return!$||!Ue?[]:Ue.filter(ct=>ct.anchorMessageId===t)},[$,t,C?.activityGroupSegments]),Oe=d.useMemo(()=>{const Ue=new Map,ct=new Map;return lt.forEach(Qe=>{Ue.set(Qe.part,Qe);const at=Qe.part.id;typeof at=="string"&&at.length>0&&ct.set(at,Qe)}),{get:Qe=>{const at=Ue.get(Qe);if(at)return at;const Nt=Qe.id;if(typeof Nt=="string"&&Nt.length>0)return ct.get(Nt)}}},[lt]),se=C?.toggleGroup,Pe=$&&He.length>0&&!!se,Ye=d.useMemo(()=>{const Ue=[];Pe&&se&&He.forEach(Qe=>{const at=w?Qe.parts:Qe.parts.filter(Nt=>Nt.kind!=="reasoning");at.length!==0&&Ue.push(s.jsx("div",{className:"mb-3",children:s.jsx(ME,{parts:at,isExpanded:C.isGroupExpanded===!0,collapsedPreviewCount:q,onToggle:se,syntaxTheme:l,isMobile:i,expandedTools:u,onToggleTool:m,onShowPopup:f,onContentChange:g,streamPhase:S,showHeader:!0,animateRows:D,animatedToolIds:J,diffStats:C.diffStats})},`progressive-group-${Qe.id}`))});let ct=0;for(;ct<L.length;){const Qe=L[ct];if(Qe.type==="text"){const at=Oe.get(Qe);if($&&!ce){ct+=1;continue}if(at?.kind==="justification"){ct+=1;continue}Ue.push(s.jsx(F_,{part:Qe,messageId:t,streamPhase:S,chatRenderMode:X,onContentChange:g},`assistant-text-${t}-${ct}`)),ct++;continue}if(Qe.type==="reasoning"){const at=Oe.get(Qe);if($&&!ce){ct+=1;continue}if(at?.kind==="reasoning"){ct+=1;continue}if(w)if($)Ue.push(s.jsx(Sp,{part:Qe,messageId:t,onContentChange:g},`reasoning-${t}-${ct}`));else{const Nt=Qe.text;Nt&&Nt.trim().length>0&&Ue.push(s.jsx(ga,{children:s.jsx("div",{className:"my-0.5 text-sm text-muted-foreground/60 italic leading-relaxed whitespace-pre-wrap",children:Nt})},`reasoning-${t}-${ct}`))}ct++;continue}if(Qe.type==="tool"){const at=Qe,Nt=at.tool?.toLowerCase()??"";if(Oe.get(Qe)?.kind==="tool"&&!l3(Nt)){ct+=1;continue}if(!ue(at)){ct++;continue}if(a3(Nt)){Ue.push(s.jsx(ga,{children:s.jsx(v2,{animate:J.has(at.id),wipe:!0,children:s.jsx(Xd,{part:at,isExpanded:u.has(at.id),onToggle:m,syntaxTheme:l,isMobile:i,onContentChange:g,onShowPopup:f,animateTailText:J.has(at.id)})})},`tool-${at.id}`)),ct++;continue}Ue.push(s.jsx(ga,{children:s.jsx(v2,{animate:J.has(at.id),wipe:!0,children:s.jsx(Bp,{toolName:Nt,activities:[{id:at.id,turnId:"",messageId:t,partIndex:0,part:at,kind:"tool"}],animateTailText:J.has(at.id)})})},`static-tools-${at.id}`)),ct++;continue}ct++}return Ue},[Oe,He,J,D,X,q,u,ce,i,$,t,g,f,m,Pe,ue,S,w,l,se,C,L]),We=!!N,xt=ee&&x&&(ce||!!N),et=d.useMemo(()=>{if(!ee||!ce)return;const Ue=C?.userMessageCreatedAt;if(!(typeof Ue!="number"||typeof o!="number")&&!(o<=Ue))return EE(o-Ue)},[ee,ce,C?.userMessageCreatedAt,o]),tt=d.useMemo(()=>{const Ue=typeof o=="number"&&o>0?o:typeof a=="number"&&a>0?a:null;if(Ue===null)return null;const ct=Q_(Ue);return ct.length>0?ct:null},[o,a]),ht="text-sm text-muted-foreground/60 tabular-nums flex items-center gap-1",St=s.jsxs(s.Fragment,{children:[b&&s.jsxs(Dt,{delayDuration:1e3,children:[s.jsx(It,{asChild:!0,children:s.jsx(Be,{type:"button",variant:"ghost",size:"icon","data-visible":k||E?"true":void 0,className:Q("h-8 w-8 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50",!we&&"opacity-50"),disabled:!we,"aria-label":"Copy message text","aria-hidden":!we,onPointerDown:Ue=>Ue.stopPropagation(),onClick:ze,onFocus:()=>{we&&j(!0)},onBlur:()=>{E||j(!1)},children:E?s.jsx(js,{className:"h-3.5 w-3.5 text-[color:var(--status-success)]"}):s.jsx(nr,{className:"h-3.5 w-3.5"})})}),s.jsx(_t,{sideOffset:6,children:"Copy answer"})]}),s.jsxs(Dt,{delayDuration:1e3,children:[s.jsx(It,{asChild:!0,children:s.jsx(Be,{type:"button",size:"icon",variant:"ghost",disabled:rt||!we,className:Q("h-8 w-8 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50",(!we||rt)&&"opacity-50"),onPointerDown:Ue=>Ue.stopPropagation(),onClick:it,children:rt?s.jsx(ts,{className:"h-4 w-4 animate-spin"}):s.jsx(ix,{className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:rt?"Saving image...":"Save as image"})]}),s.jsxs(Dt,{delayDuration:1e3,children:[s.jsx(It,{asChild:!0,children:s.jsx(Be,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50",onPointerDown:Ue=>Ue.stopPropagation(),onClick:Ge,children:s.jsx(F1,{className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:"Start new session from this answer"})]}),s.jsxs(Dt,{delayDuration:1e3,children:[s.jsx(It,{asChild:!0,children:s.jsx(Be,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50",onPointerDown:Ue=>Ue.stopPropagation(),onClick:Le,children:s.jsx(Ap,{className:"h-4 w-4"})})}),s.jsx(_t,{sideOffset:6,children:"Start new multi-run from this answer"})]}),ne&&we&&s.jsxs(Dt,{delayDuration:1e3,children:[s.jsx(It,{asChild:!0,children:s.jsx(Be,{type:"button",variant:"ghost",size:"icon",className:Q("h-8 w-8 bg-transparent hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50",ve?"text-green-500":"text-muted-foreground hover:text-foreground"),"aria-label":ve?"Stop speaking":"Read aloud",onPointerDown:Ue=>Ue.stopPropagation(),onClick:qe,children:ve?s.jsx(Xo,{className:"h-3.5 w-3.5"}):s.jsx(vu,{className:"h-3.5 w-3.5"})})}),s.jsx(_t,{sideOffset:6,children:H})]})]});return s.jsxs("div",{ref:A,className:Q("relative w-full group/message"),style:{contain:"layout",transform:"translateZ(0)"},onTouchStart:I&&B&&we?Ce:void 0,children:[s.jsx(W_,{containerRef:A}),s.jsxs("div",{children:[s.jsxs("div",{className:"message-content-text leading-relaxed overflow-hidden text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0",children:[Ye,We&&s.jsx(ga,{children:s.jsx("div",{className:"group/assistant-text relative break-words",children:s.jsx(yo,{content:N??"",onShowPopup:f})})},"assistant-error")]}),s.jsx(Zu,{files:e,onShowPopup:f}),xt&&s.jsxs("div",{className:"mt-2 mb-1 flex items-center justify-start gap-1.5",children:[s.jsx("div",{className:"flex items-center gap-1.5",children:St}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[et?s.jsxs("span",{className:"text-sm text-muted-foreground/60 tabular-nums flex items-center gap-1",children:[s.jsx(cx,{className:"h-3.5 w-3.5"}),et]}):null,tt?s.jsxs("span",{className:ht,"aria-label":`Message time: ${tt}`,children:[s.jsx(bo,{className:"h-3.5 w-3.5"}),tt]}):null]})]})]})]})},RE=t=>{const e=Fe.c(19);let n,r;if(e[0]!==t?({isUser:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),n){let a;return e[3]!==r.agentMention||e[4]!==r.copiedMessage||e[5]!==r.hasTextContent||e[6]!==r.hasTouchInput||e[7]!==r.isMobile||e[8]!==r.messageId||e[9]!==r.onCopyMessage||e[10]!==r.onFork||e[11]!==r.onRevert||e[12]!==r.onShowPopup||e[13]!==r.parts||e[14]!==r.stickyUserHeaderEnabled||e[15]!==r.userActionsMode?(a=s.jsx(TE,{messageId:r.messageId,parts:r.parts,isMobile:r.isMobile,hasTouchInput:r.hasTouchInput,hasTextContent:r.hasTextContent,onCopyMessage:r.onCopyMessage,copiedMessage:r.copiedMessage,onShowPopup:r.onShowPopup,agentMention:r.agentMention,onRevert:r.onRevert,onFork:r.onFork,userActionsMode:r.userActionsMode,stickyUserHeaderEnabled:r.stickyUserHeaderEnabled}),e[3]=r.agentMention,e[4]=r.copiedMessage,e[5]=r.hasTextContent,e[6]=r.hasTouchInput,e[7]=r.isMobile,e[8]=r.messageId,e[9]=r.onCopyMessage,e[10]=r.onFork,e[11]=r.onRevert,e[12]=r.onShowPopup,e[13]=r.parts,e[14]=r.stickyUserHeaderEnabled,e[15]=r.userActionsMode,e[16]=a):a=e[16],a}let o;return e[17]!==r?(o=s.jsx(PE,{...r}),e[17]=r,e[18]=o):o=e[18],o},Hc=d.memo(RE);function zE(t){return t.setCurrentSession}function LE(t){return!t}function HE(t){return!t}const Dl=t=>{const e=t,n=e?.clientRole,r=e?.role;return e?.userMessageMarker===!0||n==="user"||r==="user"||e?.origin==="user"||e?.source==="user"?{role:"user",isUser:!0}:{role:n||r||"assistant",isUser:!1}},_p="GitHub issue context (JSON)",Ep="GitHub pull request context (JSON)",Of=t=>typeof t=="number"&&Number.isFinite(t)&&t>0,Vf=(t,e)=>{const n=t.trimStart();if(!n.startsWith(e))return null;const r=n.indexOf("{");if(r<0)return null;try{return JSON.parse(n.slice(r))}catch{return null}},$E=t=>{const e=Vf(t,_p);if(e){const r=e.issue,o=r?.number,a=r?.title,l=r?.url;return!Of(o)||typeof a!="string"||typeof l!="string"?null:{type:"file",mime:"application/vnd.github.issue-link",filename:`Issue #${o}: ${a}`,url:l}}const n=Vf(t,Ep);if(n){const r=n.pr,o=r?.number,a=r?.title,l=r?.url;return!Of(o)||typeof a!="string"||typeof l!="string"?null:{type:"file",mime:"application/vnd.github.pull-request-link",filename:`PR #${o}: ${a}`,url:l}}return null},OE=t=>{const e=t.trim();return!!(e.startsWith("User has requested to enter plan mode")||e.startsWith("The plan at ")||e.startsWith("The following tool was executed by the user"))},VE=t=>t.filter(e=>{if(!(e.synthetic===!0))return!0;if(e.type!=="text")return!1;const r=e.text;if(typeof r!="string")return!1;const o=r.trimStart();return OE(r)||o.startsWith(_p)||o.startsWith(Ep)}).map(e=>{const n=e;if(n.type==="compaction")return{type:"text",text:"/compact"};if(n.type==="text"){const r=typeof n.text=="string"?n.text.trim():"";if(n.synthetic===!0){const a=$E(r);if(a)return a}if(r.startsWith("The following tool was executed by the user"))return{type:"text",text:"/shell"}}return e}),UE=d.lazy(()=>Kn(()=>import("./ToolOutputDialog-vSVMQalx.js"),__vite__mapDeps([2,0,1,3,4]))),Dp=4e3,si=new Map,ni=new Map,WE=new Set(["bash","shell","cmd","terminal"]),qE=new Set(["apply_patch","edit","write","multiedit","str_replace","str_replace_based_edit_tool","create","file_write"]),GE=t=>{if(typeof t!="string")return"";const e=t.trim().toLowerCase();if(!e)return"";const n=e.replace(/:\d+$/,"");if(!n.includes("."))return n;const r=n.split(".").filter(Boolean);return r[r.length-1]??n},Uf=t=>{const e=si.get(t);return e?new Set(e):new Set},Wf=(t,e)=>{if(si.size>=Dp&&!si.has(t)){const n=si.keys().next().value;typeof n=="string"&&si.delete(n)}si.set(t,new Set(e))},qf=t=>{const e=ni.get(t);return e?new Set(e):new Set},Gf=(t,e)=>{if(ni.size>=Dp&&!ni.has(t)){const n=ni.keys().next().value;typeof n=="string"&&ni.delete(n)}ni.set(t,new Set(e))};function $c(t){const e=Fe.c(3),[n,r]=d.useState(t);let o,a;return e[0]!==t?(o=()=>{t!=null&&r(t)},a=[t],e[0]=t,e[1]=o,e[2]=a):(o=e[1],a=e[2]),d.useEffect(o,a),t??n}const lo=(t,e)=>{if(typeof t=="object"&&t!==null)return t[e]},ZE=({message:t,previousMessage:e,nextMessage:n,onContentChange:r,animationHandlers:o,turnGroupingContext:a,animateUserOnMount:l=!1,onUserAnimationConsumed:i})=>{const{isMobile:c,hasTouchInput:u}=wn(),{currentTheme:m}=qn(),f=d.useRef(null),h=Ze($r(ut=>({lifecyclePhase:ut.messageStreamStates.get(t.info.id)?.phase??null,isStreamingMessage:(()=>{const Mt=t.info.sessionID??ut.currentSessionId??null;return Mt?(ut.streamingMessageIds.get(Mt)??null)===t.info.id:!1})(),currentSessionId:ut.currentSessionId,getAgentModelForSession:ut.getAgentModelForSession,getSessionModelSelection:ut.getSessionModelSelection,revertToMessage:ut.revertToMessage,forkFromMessage:ut.forkFromMessage}))),{lifecyclePhase:p,isStreamingMessage:g,currentSessionId:x,getAgentModelForSession:b,getSessionModelSelection:v,revertToMessage:y,forkFromMessage:w}=h,C=rs(ut=>ut.providers),{showReasoningTraces:N,stickyUserHeader:S,chatRenderMode:k,showExpandedBashTools:j,showExpandedEditTools:F}=Ee($r(ut=>({showReasoningTraces:ut.showReasoningTraces,stickyUserHeader:ut.stickyUserHeader,chatRenderMode:ut.chatRenderMode,showExpandedBashTools:ut.showExpandedBashTools,showExpandedEditTools:ut.showExpandedEditTools})));d.useEffect(()=>{x&&Oa.getInstance().recordSessionStart(x)},[x]);const[A,M]=d.useState(null),[B,E]=d.useState(!1),[I,P]=d.useState(()=>Uf(t.info.id)),[D,L]=d.useState(()=>qf(t.info.id)),[T,_]=d.useState({open:!1,title:"",content:""});d.useEffect(()=>{P(Uf(t.info.id)),L(qf(t.info.id))},[t.info.id]);const R=d.useMemo(()=>Dl(t.info),[t.info]).isUser,W=R&&(c||!S),G=R&&!c&&S&&!W,Y=t.info.sessionID,{currentContextAgent:J,savedSessionAgentSelection:V}=sr($r(ut=>({currentContextAgent:Y?ut.currentAgentContext.get(Y):void 0,savedSessionAgentSelection:Y?ut.sessionAgentSelections.get(Y):void 0}))),te=d.useMemo(()=>R?VE(t.parts):t.parts,[R,t.parts]),U=d.useMemo(()=>{if(R||!e)return null;const ut=lo(e.info,"clientRole"),Mt=lo(e.info,"role");if((typeof ut=="string"?ut:typeof Mt=="string"?Mt:void 0)!=="user")return null;const Ft=lo(e.info,"mode"),Et=lo(e.info,"agent"),bt=lo(e.info,"providerID"),kt=lo(e.info,"modelID"),as=lo(e.info,"variant"),Gt=typeof Ft=="string"&&Ft.trim().length>0?Ft:typeof Et=="string"&&Et.trim().length>0?Et:void 0,Ae=typeof bt=="string"&&bt.trim().length>0?bt:void 0,Xe=typeof kt=="string"&&kt.trim().length>0?kt:void 0,yt=typeof as=="string"&&as.trim().length>0?as:void 0;return!Gt&&!Ae&&!Xe&&!yt?null:{agentName:Gt,providerId:Ae,modelId:Xe,variant:yt}},[R,e]),X=d.useMemo(()=>{if(R||!e)return!1;const ut=Array.isArray(e.parts)?e.parts:[];for(let Mt=0;Mt<ut.length;Mt++){const Kt=ut[Mt];if(Kt?.type!=="text"||Kt?.synthetic!==!0)continue;const Ft=typeof Kt.text=="string"?Kt.text.trim():"";if(Ft.startsWith("User has requested to enter plan mode")||Ft.startsWith("The plan at "))return!0}return!1},[R,e]),$=d.useMemo(()=>{if(R)return;const ut=t.info.time;if(!(typeof ut?.completed=="number"&&ut.completed>0)&&X&&U?.agentName)return U.agentName;const Kt=lo(t.info,"mode");if(typeof Kt=="string"&&Kt.trim().length>0)return Kt;const Ft=lo(t.info,"agent");if(typeof Ft=="string"&&Ft.trim().length>0)return Ft;if(U?.agentName)return U.agentName;if(Y)return J||(V??void 0)},[R,t.info,X,U,Y,J,V]),q=R?null:lo(t.info,"providerID"),ee=R?null:lo(t.info,"modelID"),ce=d.useMemo(()=>{if(R||!Y)return null;if(U?.providerId&&U?.modelId)return{providerId:U.providerId,modelId:U.modelId};if($){const Mt=b(Y,$);if(Mt?.providerId&&Mt?.modelId)return Mt}const ut=v(Y);return ut?.providerId&&ut?.modelId?ut:null},[R,Y,$,U,b,v]),ve=d.useMemo(()=>R?null:typeof q=="string"&&q.trim().length>0?q:ce?.providerId??null,[R,q,ce]),ge=d.useMemo(()=>R?null:typeof ee=="string"&&ee.trim().length>0?ee:ce?.modelId??null,[R,ee,ce]),xe=d.useMemo(()=>{if(!R&&ve&&ge&&C.length>0){const ut=C.find(Mt=>Mt.id===ve);if(ut?.models&&Array.isArray(ut.models)){const Ft=ut.models.find(Et=>Et.id===ge)?.name;return typeof Ft=="string"?Ft:void 0}}},[R,ve,ge,C]),ne=d.useMemo(()=>{if(R||!ve||!ge)return!1;const ut=C.find(Ft=>Ft.id===ve);if(!ut?.models||!Array.isArray(ut.models))return!1;const Kt=ut.models.find(Ft=>Ft.id===ge)?.variants;return!!(Kt&&Object.keys(Kt).length>0)},[R,ge,ve,C]),O=$c($),H=$c(ve??void 0),K=$c(xe),re=O??void 0,le=H??null,ae=K??void 0,ue=d.useMemo(()=>{const ut=t.info.time;return typeof ut?.completed=="number"?ut.completed:null},[t.info.time]),be=d.useMemo(()=>{const ut=t.info.time;return typeof ut?.created=="number"?ut.created:null},[t.info.time]),oe=d.useMemo(()=>R?!0:!!(ue&&ue>0),[R,ue]),Z=d.useMemo(()=>{const ut=t.info.finish;return typeof ut=="string"?ut:void 0},[t.info]),ie=d.useMemo(()=>z_(te,{includeReasoning:N}),[te,N]),pe=d.useMemo(()=>R?ie:!oe&&k==="sorted"?[]:ie,[k,oe,R,ie]),me=d.useMemo(()=>R?[]:ie.filter(ut=>ut.type==="text"),[R,ie]),Se=d.useMemo(()=>R?[]:ie.filter(Mt=>Mt.type==="tool"),[R,ie]),ke=d.useMemo(()=>R?[]:(a?.activityParts??[]).filter(Mt=>Mt.kind==="tool").map(Mt=>Mt.part).filter(Mt=>Mt.type==="tool"),[R,a?.activityParts]),ye=d.useMemo(()=>{if(!j&&!F)return new Set;const ut=new Set;for(const Mt of[...Se,...ke]){const Kt=typeof Mt?.id=="string"?Mt.id:"";if(!Kt)continue;const Ft=GE(Mt.tool);if(Ft){if(j&&WE.has(Ft)){ut.add(Kt);continue}F&&qE.has(Ft)&&ut.add(Kt)}}return ut},[j,F,Se,ke]),Ne=d.useMemo(()=>{if(ye.size===0&&D.size===0)return I;const ut=new Set(I);return ye.forEach(Mt=>{D.has(Mt)||ut.add(Mt)}),D.forEach(Mt=>{ut.delete(Mt)}),ut},[D,ye,I]),_e=d.useMemo(()=>{if(!R)return;const ut=t.parts.find(Et=>Et.type==="agent");if(!ut)return;const Mt=ut,Kt=typeof Mt.name=="string"?Mt.name:void 0;if(!Kt)return;const Ft=Mt.source&&typeof Mt.source.value=="string"&&Mt.source.value.trim().length>0?Mt.source.value:`@${Kt}`;return{name:Kt,token:Ft}},[R,t.parts]),de=R&&pe.length===0,we=typeof Z!="string",je=d.useMemo(()=>R?!1:me.length===0||Se.length===0?we:!0,[me.length,Se.length,we,R]),Ce=m?.metadata.variant,ze=d.useMemo(()=>Ce?Ce==="dark":typeof document<"u"?document.documentElement.classList.contains("dark"):!1,[Ce]),Ge=d.useMemo(()=>m?sc(m):ze?GC:ZC,[m,ze]),Le=d.useMemo(()=>R?!1:Oa.getInstance().shouldAnimateMessage(t.info,x||t.info.sessionID),[t.info,x,R]),[qe,rt]=d.useState(!1),st=d.useMemo(()=>n?Dl(n.info):null,[n]),it=!!a,lt=a?.isLastAssistantInTurn??!1,He=d.useMemo(()=>R?!1:it?!lt:st?!st.isUser&&st.role==="assistant":!1,[it,lt,R,st]),Oe=d.useMemo(()=>oe?"completed":p||(g?"streaming":"completed"),[oe,p,g]);d.useEffect(()=>{!R||!l||i?.(t.info.id)},[l,R,t.info.id,i]),d.useEffect(()=>{rt(!1)},[t.info.id]),d.useEffect(()=>{const ut=a?.headerMessageId;if(R||!ut||ut!==t.info.id)return;(Oe==="streaming"||Oe==="cooldown")&&rt(!0)},[R,t.info.id,Oe,a?.headerMessageId]);const se=d.useMemo(()=>{if(R)return!0;const ut=a?.headerMessageId;return ut?t.info.id===ut?Oe==="completed"?!0:qe||(Oe==="streaming"||Oe==="cooldown"):!1:!0},[qe,R,a,Oe,t.info.id]),Pe=d.useCallback(ut=>{Dn(ut).then(Mt=>{Mt.ok&&(M(ut),setTimeout(()=>M(null),2e3))})},[]),Ye=R?void 0:a?.userMessageVariant??U?.variant,We=!R&&ne?Ye??"Default":void 0,xt=d.useMemo(()=>{if(R)return;const ut=t.info?.error;if(!ut)return;const Mt=typeof ut.data?.message=="string"?ut.data.message:void 0,Kt=typeof ut.message=="string"?ut.message:void 0,Ft=typeof ut.name=="string"?ut.name:void 0,Et=Mt||Kt||Ft;if(Et)return Ft==="SessionRetry"?`Opencode failed to send a message. Retry attempt info:
7554
7554
  \`${Et}\``:sv(Et)?nv:`Opencode failed to send message with error:
7555
7555
  \`${Et}\``},[R,t.info]),et=d.useMemo(()=>{if(R){const ut=pe.filter(Et=>Et.type==="text").map(Et=>{const bt=Et.shellAction?.output;return typeof bt=="string"?bt.trim():""}).filter(Et=>Et.length>0);if(ut.length>0)return ut.join(`
7556
7556
 
@@ -7807,7 +7807,7 @@ void main() {
7807
7807
  vec4 texColor = texture2D(uTexture, vUv);
7808
7808
  gl_FragColor = vec4(texColor.rgb, texColor.a * uOpacity);
7809
7809
  }
7810
- `;function _m(t){return new z2(t,{position:{size:2,data:new Float32Array([-.5,-.5,.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,.5])},uv:{size:2,data:new Float32Array([0,0,1,0,1,1,0,0,1,1,0,1])}})}function Gp(t,e,n,r){const o=document.createElement("canvas"),a=o.getContext("2d");if(!a)return new S3(t);o.width=128,o.height=32,a.fillStyle="transparent",a.fillRect(0,0,o.width,o.height),a.fillStyle="#ffffff",a.font=`${r} ${n}px system-ui, sans-serif`,a.textAlign="left",a.textBaseline="middle";const l=120;let i=e;if(a.measureText(e).width>l){for(;a.measureText(i+"...").width>l&&i.length>0;)i=i.slice(0,-1);i+="..."}return a.fillText(i,4,o.height/2),new S3(t,{image:o,minFilter:t.LINEAR,magFilter:t.LINEAR})}function WP(t,e){const n=_m(t),r=_m(t),o=new Ga(t,{vertex:$P,fragment:OP,transparent:!0,depthTest:!1,depthWrite:!1}),a=new Ga(t,{vertex:VP,fragment:UP,transparent:!0,depthTest:!1}),l=new Za(t,{geometry:n,program:o}),i=new Za(t,{geometry:r,program:a});i.position.z=.01;const c=Gp(t,e.toolName,11,"bold");return{cardMesh:l,labelMesh:i,cardProgram:o,labelProgram:a,cardGeometry:n,labelGeometry:r,labelTexture:c,labelDirty:!1,cachedToolName:e.toolName,cachedArgs:e.args}}function qP(t,e,n,r,o){const a=n.id===o,l=Bm[n.state]||Bm.pending,i=HP[n.state]||0;t.cardProgram.uniforms.uTime.value=r,t.cardProgram.uniforms.uCardSize.value=new ta(L1,H1,1),t.cardProgram.uniforms.uScale.value=1,t.cardProgram.uniforms.uPosition.value=new ta(n.x,n.y,0),t.cardProgram.uniforms.uStateColor.value=new ta(...l),t.cardProgram.uniforms.uOpacity.value=n.opacity,t.cardProgram.uniforms.uState.value=i,t.cardProgram.uniforms.uHovered.value=a,t.labelProgram&&t.labelMesh&&t.labelTexture&&((n.toolName!==t.cachedToolName||n.args!==t.cachedArgs||t.labelDirty)&&(t.labelTexture=Gp(e,n.toolName+" "+n.args,9,"normal"),t.cachedToolName=n.toolName,t.cachedArgs=n.args,t.labelDirty=!1),t.labelProgram.uniforms.uTexture.value=t.labelTexture,t.labelProgram.uniforms.uOpacity.value=n.opacity,t.labelMesh.position.x=n.x-L1/2+64,t.labelMesh.position.y=n.y-H1/2+16)}function Em(t){t.cardGeometry.remove(),t.cardProgram.remove(),t.labelGeometry&&t.labelGeometry.remove(),t.labelProgram&&t.labelProgram.remove()}const GP=t=>{const e=Fe.c(27),{width:n,height:r,transformRef:o,agents:a,toolCalls:l,selectedAgentId:i,hoveredAgentId:c}=t,u=he.useRef(null),m=he.useRef(null),f=he.useRef(null),h=he.useRef(null);let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=new Map,e[0]=p):p=e[0];const g=he.useRef(p);let x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=new Map,e[1]=x):x=e[1];const b=he.useRef(x);let v;e[2]===Symbol.for("react.memo_cache_sentinel")?(v={agents:[],tools:[]},e[2]=v):v=e[2];const y=he.useRef(v),w=he.useRef(0);let C;e[3]!==r||e[4]!==n?(C=()=>{if(n===0||r===0)return!1;const P=window.devicePixelRatio||1,D=FP(n,r,P);return h.current=D.renderer,f.current||(f.current=new zh(D.renderer.gl,{fov:45}),f.current.position.set(0,0,100),f.current.lookAt([0,0,0])),m.current!==D.canvas&&(m.current=D.canvas,u.current&&D.canvas.parentElement!==u.current&&u.current.appendChild(D.canvas)),D.renderer.gl.clearColor(0,0,0,0),!0},e[3]=r,e[4]=n,e[5]=C):C=e[5];const N=C;let S,k;e[6]!==N?(S=()=>{if(N())return ZP},k=[N],e[6]=N,e[7]=S,e[8]=k):(S=e[7],k=e[8]),he.useEffect(S,k);let j,F;e[9]!==a||e[10]!==l?(j=()=>{if(!h.current)return;const P=h.current.gl,D=a,L=l,T=new Set(g.current.keys()),_=new Set(D.keys());for(const W of T)if(!_.has(W)){const G=g.current.get(W);G&&(Fm(G),g.current.delete(W))}for(const[W,G]of D)if(!g.current.has(W)){const Y=zP(P,G);g.current.set(W,Y)}const z=new Set(b.current.keys()),R=new Set(L.keys());for(const W of z)if(!R.has(W)){const G=b.current.get(W);G&&(Em(G),b.current.delete(W))}for(const[W,G]of L)if(!b.current.has(W)){const Y=WP(P,G);b.current.set(W,Y)}y.current={agents:Array.from(g.current.values()),tools:Array.from(b.current.values())}},F=[a,l],e[9]=a,e[10]=l,e[11]=j,e[12]=F):(j=e[11],F=e[12]),he.useEffect(j,F);let A,M;e[13]!==a||e[14]!==r||e[15]!==c||e[16]!==i||e[17]!==l||e[18]!==o||e[19]!==n?(M=()=>{if(!f.current||!m.current||!h.current)return;let P=!0;const D=h.current,L=T=>{if(!P)return;w.current=requestAnimationFrame(L);const _=f.current;if(!_)return;const z=T*.001,R=o.current,W=D.gl;W.viewport(0,0,W.canvas.width,W.canvas.height),W.clear(W.COLOR_BUFFER_BIT|W.DEPTH_BUFFER_BIT);const G=n/r;_.perspective({aspect:G}),_.position.x=-R.x/R.scale,_.position.y=R.y/R.scale,_.position.z=100/R.scale,_.lookAt([0,0,0]);for(const[J,V]of g.current){const te=a.get(J);te&&(V.agentMesh.position.x=te.x,V.agentMesh.position.y=te.y,V.agentMesh.position.z=0,LP(V,W,te,z,c,i))}for(const[J,V]of b.current){const te=l.get(J);te&&qP(V,W,te,z,null)}const Y=y.current;for(const J of Y.agents)D.render({scene:J.agentMesh,camera:_}),J.particleMesh&&D.render({scene:J.particleMesh,camera:_});for(const J of Y.tools)D.render({scene:J.cardMesh,camera:_}),J.labelMesh&&D.render({scene:J.labelMesh,camera:_})};return w.current=requestAnimationFrame(L),()=>{P=!1,w.current&&cancelAnimationFrame(w.current)}},A=[n,r,o,a,l,i,c],e[13]=a,e[14]=r,e[15]=c,e[16]=i,e[17]=l,e[18]=o,e[19]=n,e[20]=A,e[21]=M):(A=e[20],M=e[21]),he.useEffect(M,A);let B,E;e[22]===Symbol.for("react.memo_cache_sentinel")?(B=()=>{const P=g.current,D=b.current;return()=>{for(const L of P.values())Fm(L);P.clear();for(const L of D.values())Em(L);D.clear()}},E=[],e[22]=B,e[23]=E):(B=e[22],E=e[23]),he.useEffect(B,E);let I;return e[24]!==r||e[25]!==n?(I=s.jsx("div",{ref:u,style:{position:"absolute",top:0,left:0,width:n,height:r,pointerEvents:"none",zIndex:10}}),e[24]=r,e[25]=n,e[26]=I):I=e[26],I};function ZP(){BP()}function KP(){try{return!!document.createElement("canvas").getContext("webgl2")}catch{return!1}}const YP=({selectedAgentId:t,hoveredAgentId:e,selectedToolCallId:n,selectedDiscoveryId:r,showCostOverlay:o,zoomToFitTrigger:a,pauseAutoFit:l,useParticleBackground:i,particleBackgroundColor:c,onAgentClick:u,onAgentHover:m,onAgentDrag:f,onContextMenu:h,onToolCallClick:p,onDiscoveryClick:g})=>{const x=he.useRef(null),b=he.useRef(null),[v,y]=he.useState({width:800,height:600}),w=he.useRef(0),C=he.useRef(0),N=he.useRef(null),S=he.useRef([]),k=he.useRef([]),j=he.useRef(0),F=he.useRef(1),A=he.useRef(()=>{}),M=he.useRef(()=>{}),B=he.useRef(new Map),E=he.useRef(new Map),I=he.useRef(0),P=he.useRef([]),D=he.useRef({x:-1e3,y:-1e3}),[L,T]=he.useState(!1),{currentTheme:_}=qn(),z=Nr(ge=>ge.updateAnimation),R=he.useMemo(()=>({background:_.colors.surface.background,foreground:_.colors.surface.foreground,mutedForeground:_.colors.surface.mutedForeground,elevated:_.colors.surface.elevated,primary:_.colors.primary.base,primaryForeground:_.colors.primary.foreground??"#ffffff",error:_.colors.status.error,success:_.colors.status.success,warning:_.colors.status.warning,info:_.colors.status.info,border:_.colors.interactive.border,hover:_.colors.interactive.hover,selection:_.colors.interactive.selection}),[_.colors]),W=he.useMemo(()=>{const ge=Nr.getState().agents;for(const xe of ge.values())if(xe.isMain)return xe},[]),G=()=>({agents:Nr.getState().agents,toolCalls:Nr.getState().toolCalls,discoveries:Nr.getState().discoveries,dimensions:v,selectedAgentId:t,selectedToolCallId:n??null,selectedDiscoveryId:r??null,pauseAutoFit:l??!1,showCostOverlay:o??!1,isDragging:!1,onAgentClick:u,onAgentHover:m,onAgentDrag:f,onContextMenu:h,onToolCallClick:p??(()=>{}),onDiscoveryClick:g??(()=>{})}),Y=he.useRef(G());Y.current={...Y.current,...G()};const{transformRef:J,userHasNavigatedRef:V,panVelocityRef:te,screenToCanvas:U,doZoomToFit:X,updateCamera:$}=NT({mainCanvasRef:b,drawPropsRef:Y,simTimeRef:C,dimensions:v,agentCount:Nr.getState().agents.size,zoomToFitTrigger:a,selectedAgentId:t}),{isDragging:q,handlers:ee,updateDragLerp:ce}=BT({drawPropsRef:Y,transformRef:J,userHasNavigatedRef:V,panVelocityRef:te,simTimeRef:C,screenToCanvas:U,doZoomToFit:X,mainCanvasRef:b});Y.current.isDragging=q,he.useEffect(()=>(N.current=new dP(.5),S.current=fP(v.width,v.height,yi.particleCount),P.current=hP(v.width,v.height,yi.particleCount,[R.primary,R.success,R.warning,R.info,R.foreground,R.mutedForeground]),()=>{N.current=null}),[]),he.useEffect(()=>{const ge=KP();T(ge)},[]),he.useEffect(()=>{const ge=x.current;if(!ge)return;const xe=window.devicePixelRatio||1;F.current=xe;const ne=new ResizeObserver(O=>{for(const H of O){const K=H.contentRect.width,re=H.contentRect.height;y({width:K,height:re}),N.current?.resize(K*xe,re*xe)}});return ne.observe(ge),()=>ne.disconnect()},[]);const ve=he.useCallback(ge=>{w.current=requestAnimationFrame(O=>A.current(O));const xe=b.current;if(!xe)return;const ne=xe.getContext("2d");if(ne)try{const O=F.current,H=v.width,K=v.height;(xe.width!==Math.round(H*O)||xe.height!==Math.round(K*O))&&(xe.width=Math.round(H*O),xe.height=Math.round(K*O),ne.scale(O,O)),ne.clearRect(0,0,H,K);const re=j.current?Math.min((ge-j.current)/1e3,.1):.016;j.current=ge;const le=Nr.getState(),{agents:ae,toolCalls:ue,particles:be,edges:oe,discoveries:Z,isPlaying:ie,camera:pe}=le;C.current=le.currentTime,ie&&z(re),$(q,l),ce(ae,f);{const Ne=CP(ae,ue,B.current,E.current,R.primary,R.success);Ne.effects.length>0&&k.current.push(...Ne.effects),B.current=Ne.newAgentStates,E.current=Ne.newToolStates}{const Ne=k.current;let _e=0;for(let de=0;de<Ne.length;de++)Ne[de].age+=re,Ne[de].age<Ne[de].duration&&(_e!==de&&(Ne[_e]=Ne[de]),_e++);Ne.length=_e}mP(S.current,re,H,K),P.current.length>0&&gP(P.current,re,H,K,D.current.x,D.current.y,[R.primary,R.success,R.warning,R.info,R.foreground,R.mutedForeground]);const me=J.current,Se=t?ae.get(t):void 0,ke=Se?{x:Se.x,y:Se.y,color:R.primary}:void 0;i||bP(ne,H,K,S.current,P.current,{x:me.x,y:me.y,scale:me.scale},{showHexGrid:!1,showDepthParticles:!0,showAnimParticles:!0,particleCount:yi.particleCount},ge*.001,R,ke),ne.save(),ne.translate(me.x,me.y),ne.scale(me.scale,me.scale);const ye=XT(be);if(QT(ne,oe,R,ae,ue,ye,ge*.001),eP(ne,be,R,ae,oe,ue,ge*.001),sP(ne,Array.from(ue.values()),R,le.currentTime),rP(ne,Z,R,ae),oP(ne,Z,R,r??null),cP(ne,ae,R,le.currentTime),KT(ne,ae,R,le.currentTime,t??null,e??null),t){const Ne=ae.get(t);Ne&&_T(ne,Ne,me,K,R)}o&&jP(ne,ae,ue,R),NP(ne,k.current),ne.restore(),N.current&&N.current.apply(xe,ne),(le.camera.x!==pe.x||le.camera.zoom!==pe.zoom)&&Nr.getState().setCamera({x:me.x,y:me.y,zoom:me.scale})}catch(O){const H=Date.now();H-I.current>5e3&&(I.current=H,console.warn("[AgentCanvas] draw error:",O))}},[v,z,$,ce,q,l,t,e,r,o,R,f,J]);return A.current=ve,M.current=he.useCallback(ge=>{A.current(ge)},[]),he.useEffect(()=>{const ge=xe=>A.current(xe);return w.current=requestAnimationFrame(ge),()=>{w.current&&cancelAnimationFrame(w.current)}},[]),s.jsxs("div",{ref:x,className:"relative w-full h-full overflow-hidden",style:{cursor:q?"grabbing":"grab"},onMouseMove:ge=>{const xe=b.current?.getBoundingClientRect();if(xe){const ne=J.current;D.current={x:(ge.clientX-xe.left-ne.x)/ne.scale,y:(ge.clientY-xe.top-ne.y)/ne.scale}}},onTouchMove:ge=>{const xe=b.current?.getBoundingClientRect();if(xe){const ne=J.current,O=ge.touches[0];D.current={x:(O.clientX-xe.left-ne.x)/ne.scale,y:(O.clientY-xe.top-ne.y)/ne.scale}}},onMouseLeave:()=>{D.current={x:-1e3,y:-1e3}},children:[i&&W&&s.jsx(MP,{color:c??R.primary,autoAnimate:!1,magnetRadius:10,ringRadius:8,waveSpeed:.4,waveAmplitude:1,particleSize:1.5,lerpSpeed:.05,particleVariance:1,rotationSpeed:.5,depthFactor:1,pulseSpeed:3,particleShape:"capsule",fieldStrength:10,agentX:W.x,agentY:W.y,transformRef:J}),i&&!W&&s.jsx(qd,{color:c??R.primary,autoAnimate:!0,magnetRadius:10,ringRadius:8,waveSpeed:.4,waveAmplitude:1,particleSize:1.5,lerpSpeed:.05,particleVariance:1,rotationSpeed:0,depthFactor:1,pulseSpeed:3,particleShape:"capsule",fieldStrength:10}),s.jsx("canvas",{ref:b,style:{width:v.width,height:v.height,backgroundColor:i?"transparent":R.background},...ee,className:"w-full h-full"}),L&&s.jsx(GP,{width:v.width,height:v.height,transformRef:J,agents:Nr.getState().agents,toolCalls:Nr.getState().toolCalls,selectedAgentId:t??null,hoveredAgentId:e??null}),!L&&s.jsx("div",{className:"absolute top-2 right-2 text-xs px-2 py-1 rounded bg-yellow-500/20 text-yellow-600",title:"WebGL 2.0 not supported - using Canvas 2D fallback",children:"WebGL unavailable"})]})},Kc=200;function XP(t){const e=Fe.c(14),{children:n,className:r,style:o,visible:a}=t,l=r===void 0?"":r,{currentTheme:i}=qn(),[c,u]=he.useState(!1),[m,f]=he.useState(!1);let h,p;if(e[0]!==a?(h=()=>{if(a)u(!0),requestAnimationFrame(()=>f(!0));else{f(!1);const S=setTimeout(()=>u(!1),Kc);return()=>clearTimeout(S)}},p=[a],e[0]=a,e[1]=h,e[2]=p):(h=e[1],p=e[2]),he.useEffect(h,p),!c)return null;const g=`glass-card ${l}`,x=i.colors.surface.elevated+"E6",b=`1px solid ${i.colors.interactive.border}40`,v=`0 8px 32px ${i.colors.surface.overlay}40`,y=m?1:0,w=m?"scale(1)":"scale(0.95)";let C;e[3]!==o||e[4]!==x||e[5]!==b||e[6]!==v||e[7]!==y||e[8]!==w?(C={...o,backgroundColor:x,backdropFilter:"blur(12px)",border:b,boxShadow:v,opacity:y,transform:w,transition:`opacity ${Kc}ms ease-out, transform ${Kc}ms ease-out`},e[3]=o,e[4]=x,e[5]=b,e[6]=v,e[7]=y,e[8]=w,e[9]=C):C=e[9];let N;return e[10]!==n||e[11]!==C||e[12]!==g?(N=s.jsx("div",{className:g,style:C,children:n}),e[10]=n,e[11]=C,e[12]=g,e[13]=N):N=e[13],N}function QP(t,e,n){const r=Fe.c(5),o=n;let a,l;r[0]!==o||r[1]!==e||r[2]!==t?(a=()=>{const i=u=>{t.current&&!t.current.contains(u.target)&&e()},c=setTimeout(()=>{document.addEventListener("mousedown",i)},o);return()=>{clearTimeout(c),document.removeEventListener("mousedown",i)}},l=[t,e,o],r[0]=o,r[1]=e,r[2]=t,r[3]=a,r[4]=l):(a=r[3],l=r[4]),he.useEffect(a,l)}const JP=150;function eR(t){const e=Fe.c(16),{position:n,items:r,onClose:o}=t,a=he.useRef(null),{currentTheme:l}=qn();QP(a,o,JP);let i;e[0]!==n.x||e[1]!==n.y?(i={position:"fixed",left:n.x,top:n.y,zIndex:1e3},e[0]=n.x,e[1]=n.y,e[2]=i):i=e[2];let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c={minWidth:160},e[3]=c):c=e[3];let u;if(e[4]!==l||e[5]!==r||e[6]!==o){let h;e[8]!==l||e[9]!==o?(h=(p,g)=>p.separator?s.jsx("div",{className:"my-1 h-px",style:{background:l.colors.interactive.border+"40"}},g):s.jsxs("button",{onClick:()=>{p.disabled||(p.onClick(),o())},disabled:p.disabled,className:"w-full px-3 py-1.5 text-left text-xs font-mono transition-colors flex items-center gap-2",style:{color:p.danger?l.colors.status.error:p.disabled?l.colors.surface.mutedForeground+"60":l.colors.surface.foreground,opacity:p.disabled?.5:1,cursor:p.disabled?"not-allowed":"pointer"},onMouseEnter:x=>{p.disabled||(x.currentTarget.style.backgroundColor=l.colors.interactive.hover)},onMouseLeave:tR,children:[p.icon&&s.jsx("span",{className:"w-4 h-4 flex items-center justify-center",children:p.icon}),p.label]},g),e[8]=l,e[9]=o,e[10]=h):h=e[10],u=r.map(h),e[4]=l,e[5]=r,e[6]=o,e[7]=u}else u=e[7];let m;e[11]!==u?(m=s.jsx(XP,{visible:!0,style:c,children:s.jsx("div",{className:"py-1",children:u})}),e[11]=u,e[12]=m):m=e[12];let f;return e[13]!==i||e[14]!==m?(f=s.jsx("div",{ref:a,style:i,onMouseDown:nR,onClick:sR,children:m}),e[13]=i,e[14]=m,e[15]=f):f=e[15],f}function tR(t){t.currentTarget.style.backgroundColor="transparent"}function sR(t){return t.stopPropagation()}function nR(t){return t.stopPropagation()}const rR=()=>{const t=Fe.c(37),{currentTheme:e}=qn(),n=Ee(oR),r=Ee(aR),o=Nr(ym.agents),a=Nr(ym.discoveries),l=Nr(lR),i=Nr(iR),c=Nr(cR);pT(!0),vT();const[u,m]=he.useState(0);let f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=new Map,t[0]=f):f=t[0];let h;t[1]!==o||t[2]!==a?(h={agents:o,toolCalls:f,discoveries:a},t[1]=o,t[2]=a,t[3]=h):h=t[3];const p=jT(h);let g,x;t[4]!==n||t[5]!==r?(g=()=>{const F=A=>{A.key==="Escape"&&n&&r(!1)};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},x=[n,r],t[4]=n,t[5]=r,t[6]=g,t[7]=x):(g=t[6],x=t[7]),he.useEffect(g,x);let b,v;if(t[8]!==n||t[9]!==i||t[10]!==l?(b=()=>(n&&l(),()=>{i()}),v=[n,l,i],t[8]=n,t[9]=i,t[10]=l,t[11]=b,t[12]=v):(b=t[11],v=t[12]),he.useEffect(b,v),!n)return null;let y;t[13]!==e.colors.surface.background?(y={backgroundColor:e.colors.surface.background},t[13]=e.colors.surface.background,t[14]=y):y=t[14];let w;t[15]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(U0,{}),t[15]=w):w=t[15];let C;t[16]!==c?(C=(F,A,M)=>c(F,A,M),t[16]=c,t[17]=C):C=t[17];let N;t[18]!==e.colors.primary.base||t[19]!==p.handleAgentClick||t[20]!==p.handleContextMenu||t[21]!==p.handleDiscoveryClick||t[22]!==p.hoveredAgentId||t[23]!==p.selectedAgentId||t[24]!==p.selectedDiscoveryId||t[25]!==p.setHoveredAgentId||t[26]!==C||t[27]!==u?(N=s.jsx(YP,{selectedAgentId:p.selectedAgentId,hoveredAgentId:p.hoveredAgentId,selectedToolCallId:null,selectedDiscoveryId:p.selectedDiscoveryId,showCostOverlay:!1,zoomToFitTrigger:u,pauseAutoFit:!1,useParticleBackground:!0,particleBackgroundColor:e.colors.primary.base,onAgentClick:p.handleAgentClick,onAgentHover:p.setHoveredAgentId,onAgentDrag:C,onContextMenu:p.handleContextMenu,onToolCallClick:dR,onDiscoveryClick:p.handleDiscoveryClick}),t[18]=e.colors.primary.base,t[19]=p.handleAgentClick,t[20]=p.handleContextMenu,t[21]=p.handleDiscoveryClick,t[22]=p.hoveredAgentId,t[23]=p.selectedAgentId,t[24]=p.selectedDiscoveryId,t[25]=p.setHoveredAgentId,t[26]=C,t[27]=u,t[28]=N):N=t[28];let S;t[29]!==p?(S=p.contextMenu&&s.jsx(eR,{position:p.contextMenu,items:[{label:"🔍 Zoom to Fit",onClick:()=>m(uR)}],onClose:()=>p.setContextMenu(null)}),t[29]=p,t[30]=S):S=t[30];let k;t[31]!==S||t[32]!==N?(k=s.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[w,N,S]}),t[31]=S,t[32]=N,t[33]=k):k=t[33];let j;return t[34]!==k||t[35]!==y?(j=s.jsx("div",{className:"fixed inset-0 z-50 flex flex-col",style:y,children:k}),t[34]=k,t[35]=y,t[36]=j):j=t[36],j};function oR(t){return t.isAgentFlowOpen}function aR(t){return t.setAgentFlowOpen}function lR(t){return t.play}function iR(t){return t.pause}function cR(t){return t.updateAgentPosition}function dR(){}function uR(t){return t+1}const fR=d.lazy(()=>Kn(()=>import("./TimelineDialog-C7rryZWn.js"),__vite__mapDeps([5,0,1,3,4])).then(t=>({default:t.TimelineDialog}))),Dm=[],mR=[],hR=[],Im={type:"idle"},Tm="archcoder:session-reselected",pR=()=>Ze($r(yR)),gR=()=>Ze($r(wR)),xR=()=>Ee($r(jR)),bR=()=>Ze($r(kR)),vR=[{id:1,toolRows:[{id:"search",titleWidth:"w-24",detailWidth:"w-52"},{id:"read",titleWidth:"w-20",detailWidth:"w-36"},{id:"edit",titleWidth:"w-24",detailWidth:"w-64"}],textWidths:["w-24","w-[92%]","w-[78%]"]},{id:2,toolRows:[{id:"read",titleWidth:"w-20",detailWidth:"w-40"},{id:"search",titleWidth:"w-24",detailWidth:"w-48"}],textWidths:["w-20","w-[88%]","w-[70%]"]},{id:3,toolRows:[{id:"shell",titleWidth:"w-28",detailWidth:"w-44"},{id:"edit",titleWidth:"w-24",detailWidth:"w-56"}],textWidths:["w-24","w-[84%]","w-[64%]"]}],Zp=()=>{const t=Fe.c(211),{currentSessionId:e,loadMessages:n,loadMoreMessages:r,updateViewportAnchor:o,openNewSessionDraft:a,setCurrentSession:l,newSessionDraft:i}=pR(),{isSyncing:c,messageStreamStates:u,sessionMemoryStateMap:m}=gR(),{isTimelineDialogOpen:f,setTimelineDialogOpen:h,isExpandedInput:p,stickyUserHeader:g,chatRenderMode:x}=xR();let b;t[0]!==e?(b=Ue=>e?Ue.messages.get(e)??Dm:Dm,t[0]=e,t[1]=b):b=t[1];const v=Ze(b),y=Ze(NR),w=bR();let C;t[2]!==w.sessions||t[3]!==e?(C=AI(w.sessions.map(SR),e),t[2]=w.sessions,t[3]=e,t[4]=C):C=t[4];const N=C;let S;e:{if(N.length===0){S=mR;break e}let Ue;t[5]!==w.permissions||t[6]!==N?(Ue=hm(w.permissions,N),t[5]=w.permissions,t[6]=N,t[7]=Ue):Ue=t[7],S=Ue}const k=S;let j;e:{if(N.length===0){j=hR;break e}let Ue;t[8]!==w.questions||t[9]!==N?(Ue=hm(w.questions,N),t[8]=w.questions,t[9]=N,t[10]=Ue):Ue=t[10],j=Ue}const F=j;let A;t[11]!==e?(A=Ue=>e?Ue.sessionHistoryMeta.get(e)??null:null,t[11]=e,t[12]=A):A=t[12];const M=Ze(A);let B;t[13]!==e?(B=Ue=>e?Ue.streamingMessageIds.get(e)??null:null,t[13]=e,t[14]=B):B=t[14];const E=Ze(B);let I;t[15]!==e?(I=Ue=>e?Ue.sessionStatus?.get(e)??Im:Im,t[15]=e,t[16]=I):I=t[16];const P=Ze(I);let D;t[17]!==e?(D=Ue=>e?Ue.messages.has(e):!1,t[17]=e,t[18]=D):D=t[18];const L=Ze(D),{isMobile:T}=wn(),_=!!i?.open,z=p&&!T,R=d.useRef(null);let W;e:{if(!e){W=null;break e}let Ue;if(t[19]!==e||t[20]!==y){let Nt;t[22]!==e?(Nt=jt=>jt.id===e,t[22]=e,t[23]=Nt):Nt=t[23],Ue=y.find(Nt),t[19]=e,t[20]=y,t[21]=Ue}else Ue=t[21];const Qe=Ue?.parentID;if(!Qe){W=null;break e}let at;t[24]!==Qe||t[25]!==y?(at=y.find(Nt=>Nt.id===Qe)??null,t[24]=Qe,t[25]=y,t[26]=at):at=t[26],W=at}const G=W;let Y;t[27]!==G||t[28]!==l?(Y=()=>{G&&l(G.id)},t[27]=G,t[28]=l,t[29]=Y):Y=t[29];const J=Y;let V;t[30]!==J||t[31]!==G?(V=G?s.jsxs(Be,{type:"button",variant:"outline",size:"xs",onClick:J,className:"absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95","aria-label":"Return to parent session",title:G.title?.trim()?`Return to: ${G.title}`:"Return to parent session",children:[s.jsx(Su,{className:"h-4 w-4"}),"Parent"]}):null,t[30]=J,t[31]=G,t[32]=V):V=t[32];const te=V;let U,X;t[33]!==e||t[34]!==_||t[35]!==a?(U=()=>{!e&&!_&&a()},X=[e,_,a],t[33]=e,t[34]=_,t[35]=a,t[36]=U,t[37]=X):(U=t[36],X=t[37]),d.useEffect(U,X);let $;t[38]!==k||t[39]!==F?($=[...k,...F],t[38]=k,t[39]=F,t[40]=$):$=t[40];const q=$,ee=d.useRef(CR);let ce;t[41]===Symbol.for("react.memo_cache_sentinel")?(ce=Ue=>{ee.current(Ue)},t[41]=ce):ce=t[41];let ve;t[42]!==x||t[43]!==e||t[44]!==T||t[45]!==c||t[46]!==u||t[47]!==q||t[48]!==m||t[49]!==v||t[50]!==E||t[51]!==o?(ve={currentSessionId:e,sessionMessages:v,streamingMessageId:E,sessionMemoryState:m,updateViewportAnchor:o,isSyncing:c,isMobile:T,chatRenderMode:x,messageStreamStates:u,sessionPermissions:q,onActiveTurnChange:ce},t[42]=x,t[43]=e,t[44]=T,t[45]=c,t[46]=u,t[47]=q,t[48]=m,t[49]=v,t[50]=E,t[51]=o,t[52]=ve):ve=t[52];const{scrollRef:ge,handleMessageContentChange:xe,getAnimationHandlers:ne,scrollToBottom:O,releasePinnedScroll:H,isPinned:K,isOverflowing:re,isProgrammaticFollowActive:le}=fI(ve);let ae;t[53]!==e||t[54]!==M||t[55]!==re||t[56]!==K||t[57]!==r||t[58]!==ge||t[59]!==O||t[60]!==v?(ae={sessionId:e,messages:v,historyMeta:M,scrollRef:ge,messageListRef:R,loadMoreMessages:r,scrollToBottom:O,isPinned:K,isOverflowing:re},t[53]=e,t[54]=M,t[55]=re,t[56]=K,t[57]=r,t[58]=ge,t[59]=O,t[60]=v,t[61]=ae):ae=t[61];const ue=kI(ae),{resumeToBottomInstant:be}=ue;let oe,Z;t[62]!==ue.handleActiveTurnChange?(oe=()=>{ee.current=ue.handleActiveTurnChange},Z=[ue.handleActiveTurnChange],t[62]=ue.handleActiveTurnChange,t[63]=oe,t[64]=Z):(oe=t[63],Z=t[64]),d.useEffect(oe,Z);let ie;t[65]!==e||t[66]!==ue.activeTurnId||t[67]!==ue.resumeToBottom||t[68]!==ue.scrollToMessage||t[69]!==ue.scrollToTurn||t[70]!==ue.turnIds?(ie={sessionId:e,turnIds:ue.turnIds,activeTurnId:ue.activeTurnId,scrollToTurn:ue.scrollToTurn,scrollToMessage:ue.scrollToMessage,resumeToBottom:ue.resumeToBottom},t[65]=e,t[66]=ue.activeTurnId,t[67]=ue.resumeToBottom,t[68]=ue.scrollToMessage,t[69]=ue.scrollToTurn,t[70]=ue.turnIds,t[71]=ie):ie=t[71];const pe=CI(ie);let me,Se;t[72]!==e||t[73]!==be?(me=()=>{if(typeof window>"u"||!e)return;const Ue=ct=>{ct.detail===e&&be()};return window.addEventListener(Tm,Ue),()=>{window.removeEventListener(Tm,Ue)}},Se=[e,be],t[72]=e,t[73]=be,t[74]=me,t[75]=Se):(me=t[74],Se=t[75]),d.useEffect(me,Se);let ke;t[76]!==ge?(ke=()=>{const Ue=ge.current;if(!Ue)return;const ct=()=>{Ue.style.setProperty("--chat-scroll-height",`${Ue.clientHeight}px`)};ct();let Qe=0;const at=()=>{Qe||(Qe=requestAnimationFrame(()=>{Qe=0,ct()}))};if(typeof ResizeObserver>"u")return window.addEventListener("resize",at),()=>{Qe&&cancelAnimationFrame(Qe),window.removeEventListener("resize",at)};const Nt=new ResizeObserver(at);return Nt.observe(Ue),()=>{Qe&&cancelAnimationFrame(Qe),Nt.disconnect()}},t[76]=ge,t[77]=ke):ke=t[77];let ye;t[78]!==e||t[79]!==z||t[80]!==ge?(ye=[e,z,ge],t[78]=e,t[79]=z,t[80]=ge,t[81]=ye):ye=t[81],d.useLayoutEffect(ke,ye);const Ne=!!M,_e=!!e&&(!L||!Ne||M?.loading===!0);let de;t[82]!==e||t[83]!==Ne||t[84]!==L||t[85]!==K||t[86]!==n||t[87]!==O||t[88]!==P.type?(de=()=>{if(!e||L&&Ne)return;(async()=>await n(e).finally(()=>{const Qe=P.type??"idle",at=Qe==="busy"||Qe==="retry",Nt=typeof window<"u"&&window.location.hash.length>0;at&&K||Nt||(typeof window>"u"?O({instant:!0}):window.requestAnimationFrame(()=>{O({instant:!0})}))}))()},t[82]=e,t[83]=Ne,t[84]=L,t[85]=K,t[86]=n,t[87]=O,t[88]=P.type,t[89]=de):de=t[89];let we;if(t[90]!==e||t[91]!==Ne||t[92]!==L||t[93]!==K||t[94]!==n||t[95]!==O||t[96]!==v.length||t[97]!==P.type?(we=[e,Ne,L,K,n,O,v.length,P.type],t[90]=e,t[91]=Ne,t[92]=L,t[93]=K,t[94]=n,t[95]=O,t[96]=v.length,t[97]=P.type,t[98]=we):we=t[98],d.useEffect(de,we),!e&&!_){let Ue;t[99]!==T?(Ue=T?{paddingBottom:"var(--oc-keyboard-inset, 0px)"}:void 0,t[99]=T,t[100]=Ue):Ue=t[100];let ct;t[101]===Symbol.for("react.memo_cache_sentinel")?(ct=s.jsx(Rc,{}),t[101]=ct):ct=t[101];let Qe;return t[102]!==Ue?(Qe=s.jsx("div",{className:"flex flex-col h-full bg-background",style:Ue,children:ct}),t[102]=Ue,t[103]=Qe):Qe=t[103],Qe}if(!e&&_){let Ue;t[104]!==T?(Ue=T?{paddingBottom:"var(--oc-keyboard-inset, 0px)"}:void 0,t[104]=T,t[105]=Ue):Ue=t[105];let ct;t[106]!==z?(ct=z?null:s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsx(Rc,{})}),t[106]=z,t[107]=ct):ct=t[107];const Qe=z?"flex-1 min-h-0 bg-background":"bg-background/95 supports-[backdrop-filter]:bg-background/80";let at;t[108]!==Qe?(at=Q("relative z-10",Qe),t[108]=Qe,t[109]=at):at=t[109];let Nt;t[110]!==O?(Nt=s.jsx(m0,{scrollToBottom:O}),t[110]=O,t[111]=Nt):Nt=t[111];let jt;t[112]!==at||t[113]!==Nt?(jt=s.jsx("div",{className:at,children:Nt}),t[112]=at,t[113]=Nt,t[114]=jt):jt=t[114];let qt;return t[115]!==Ue||t[116]!==ct||t[117]!==jt?(qt=s.jsxs("div",{className:"relative flex flex-col h-full bg-background transform-gpu",style:Ue,children:[ct,jt]}),t[115]=Ue,t[116]=ct,t[117]=jt,t[118]=qt):qt=t[118],qt}if(!e)return null;if(_e&&v.length===0&&!E){let Ue;t[119]!==T?(Ue=T?{paddingBottom:"var(--oc-keyboard-inset, 0px)"}:void 0,t[119]=T,t[120]=Ue):Ue=t[120];let ct;t[121]===Symbol.for("react.memo_cache_sentinel")?(ct=s.jsx(U0,{}),t[121]=ct):ct=t[121];let Qe;t[122]===Symbol.for("react.memo_cache_sentinel")?(Qe=s.jsx("div",{className:"flex-1 overflow-y-auto bg-background pt-6",children:s.jsx("div",{className:"space-y-4",children:vR.map(AR)})}),t[122]=Qe):Qe=t[122];let at;t[123]!==O?(at=s.jsx(m0,{scrollToBottom:O}),t[123]=O,t[124]=at):at=t[124];let Nt;return t[125]!==te||t[126]!==Ue||t[127]!==at?(Nt=s.jsxs("div",{className:"relative flex flex-col h-full bg-background gap-0",style:Ue,children:[te,ct,Qe,at]}),t[125]=te,t[126]=Ue,t[127]=at,t[128]=Nt):Nt=t[128],Nt}if(v.length===0&&!E){let Ue;t[129]!==T?(Ue=T?{paddingBottom:"var(--oc-keyboard-inset, 0px)"}:void 0,t[129]=T,t[130]=Ue):Ue=t[130];let ct;t[131]===Symbol.for("react.memo_cache_sentinel")?(ct=s.jsx(U0,{}),t[131]=ct):ct=t[131];let Qe;t[132]!==z?(Qe=z?null:s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsx(Rc,{})}),t[132]=z,t[133]=Qe):Qe=t[133];const at=z?"flex-1 min-h-0 bg-background":"bg-background/95 supports-[backdrop-filter]:bg-background/80";let Nt;t[134]!==at?(Nt=Q("relative z-10",at),t[134]=at,t[135]=Nt):Nt=t[135];let jt;t[136]!==O?(jt=s.jsx(m0,{scrollToBottom:O}),t[136]=O,t[137]=jt):jt=t[137];let qt;t[138]!==Nt||t[139]!==jt?(qt=s.jsx("div",{className:Nt,children:jt}),t[138]=Nt,t[139]=jt,t[140]=qt):qt=t[140];let Zt;return t[141]!==te||t[142]!==Ue||t[143]!==Qe||t[144]!==qt?(Zt=s.jsxs("div",{className:"relative flex flex-col h-full bg-background transform-gpu",style:Ue,children:[te,ct,Qe,qt]}),t[141]=te,t[142]=Ue,t[143]=Qe,t[144]=qt,t[145]=Zt):Zt=t[145],Zt}let je;t[146]!==T?(je=T?{paddingBottom:"var(--oc-keyboard-inset, 0px)"}:void 0,t[146]=T,t[147]=je):je=t[147];let Ce;t[148]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(U0,{}),t[148]=Ce):Ce=t[148];const ze=z?"absolute inset-0 opacity-0 pointer-events-none":"flex-1";let Ge;t[149]!==ze?(Ge=Q("relative min-h-0",ze),t[149]=ze,t[150]=Ge):Ge=t[150];const Le=T&&g;let qe;t[151]!==ue?(qe=()=>{ue.loadEarlier()},t[151]=ue,t[152]=qe):qe=t[152];let rt;t[153]!==e||t[154]!==ne||t[155]!==xe||t[156]!==ge||t[157]!==O||t[158]!==k||t[159]!==F||t[160]!==qe||t[161]!==ue.historySignals.hasMoreAboveTurns||t[162]!==ue.isLoadingOlder||t[163]!==ue.pendingRevealWork||t[164]!==ue.renderedMessages||t[165]!==ue.turnStart?(rt=s.jsx("div",{className:"relative z-0 min-h-full",children:s.jsx(qD,{ref:R,sessionKey:e,turnStart:ue.turnStart,disableStaging:ue.pendingRevealWork,messages:ue.renderedMessages,permissions:k,questions:F,onMessageContentChange:xe,getAnimationHandlers:ne,hasMoreAbove:ue.historySignals.hasMoreAboveTurns,isLoadingOlder:ue.isLoadingOlder,onLoadOlder:qe,scrollToBottom:O,scrollRef:ge})}),t[153]=e,t[154]=ne,t[155]=xe,t[156]=ge,t[157]=O,t[158]=k,t[159]=F,t[160]=qe,t[161]=ue.historySignals.hasMoreAboveTurns,t[162]=ue.isLoadingOlder,t[163]=ue.pendingRevealWork,t[164]=ue.renderedMessages,t[165]=ue.turnStart,t[166]=rt):rt=t[166];let st;t[167]!==ge||t[168]!==Le||t[169]!==rt?(st=s.jsx(Qa,{className:"absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target",ref:ge,observeMutations:!1,hideTopShadow:Le,"data-scroll-shadow":"true","data-scrollbar":"chat",children:rt}),t[167]=ge,t[168]=Le,t[169]=rt,t[170]=st):st=t[170];let it;t[171]!==le||t[172]!==ge?(it=s.jsx(K2,{containerRef:ge,suppressVisibility:le,userIntentOnly:!0}),t[171]=le,t[172]=ge,t[173]=it):it=t[173];let lt;t[174]!==st||t[175]!==it?(lt=s.jsxs("div",{className:"absolute inset-0",children:[st,it]}),t[174]=st,t[175]=it,t[176]=lt):lt=t[176];let He;t[177]!==z||t[178]!==Ge||t[179]!==lt?(He=s.jsx("div",{className:Ge,"aria-hidden":z,children:lt}),t[177]=z,t[178]=Ge,t[179]=lt,t[180]=He):He=t[180];const Oe=z?"flex-1 min-h-0 bg-background":"bg-background/95 supports-[backdrop-filter]:bg-background/80";let se;t[181]!==Oe?(se=Q("relative z-10",Oe),t[181]=Oe,t[182]=se):se=t[182];let Pe;t[183]!==z||t[184]!==pe.resumeToLatest||t[185]!==v.length||t[186]!==ue.showScrollToBottom?(Pe=!z&&v.length>0&&s.jsx(YD,{visible:ue.showScrollToBottom,onClick:pe.resumeToLatest}),t[183]=z,t[184]=pe.resumeToLatest,t[185]=v.length,t[186]=ue.showScrollToBottom,t[187]=Pe):Pe=t[187];let Ye;t[188]!==O?(Ye=s.jsx(m0,{scrollToBottom:O}),t[188]=O,t[189]=Ye):Ye=t[189];let We;t[190]!==se||t[191]!==Pe||t[192]!==Ye?(We=s.jsxs("div",{className:se,children:[Pe,Ye]}),t[190]=se,t[191]=Pe,t[192]=Ye,t[193]=We):We=t[193];let xt,et;t[194]!==pe||t[195]!==H?(xt=Ue=>(H(),pe.scrollToMessageId(Ue,{behavior:"smooth",updateHash:!1})),et=Ue=>{H(),pe.scrollByTurnOffset(Ue)},t[194]=pe,t[195]=H,t[196]=xt,t[197]=et):(xt=t[196],et=t[197]);let tt;t[198]!==f||t[199]!==pe.resumeToLatest||t[200]!==h||t[201]!==xt||t[202]!==et?(tt=s.jsx(d.Suspense,{fallback:null,children:s.jsx(fR,{open:f,onOpenChange:h,onScrollToMessage:xt,onScrollByTurnOffset:et,onResumeToLatest:pe.resumeToLatest})}),t[198]=f,t[199]=pe.resumeToLatest,t[200]=h,t[201]=xt,t[202]=et,t[203]=tt):tt=t[203];let ht;t[204]===Symbol.for("react.memo_cache_sentinel")?(ht=s.jsx(rR,{}),t[204]=ht):ht=t[204];let St;return t[205]!==te||t[206]!==je||t[207]!==He||t[208]!==We||t[209]!==tt?(St=s.jsxs("div",{className:"relative flex flex-col h-full bg-background",style:je,children:[te,Ce,He,We,tt,ht]}),t[205]=te,t[206]=je,t[207]=He,t[208]=We,t[209]=tt,t[210]=St):St=t[210],St};function yR(t){return{currentSessionId:t.currentSessionId,loadMessages:t.loadMessages,loadMoreMessages:t.loadMoreMessages,updateViewportAnchor:t.updateViewportAnchor,openNewSessionDraft:t.openNewSessionDraft,setCurrentSession:t.setCurrentSession,newSessionDraft:t.newSessionDraft}}function wR(t){return{isSyncing:t.isSyncing,messageStreamStates:t.messageStreamStates,sessionMemoryStateMap:t.sessionMemoryState}}function jR(t){return{isTimelineDialogOpen:t.isTimelineDialogOpen,setTimelineDialogOpen:t.setTimelineDialogOpen,isExpandedInput:t.isExpandedInput,stickyUserHeader:t.stickyUserHeader,chatRenderMode:t.chatRenderMode}}function kR(t){return{sessions:t.sessions,permissions:t.permissions,questions:t.questions}}function NR(t){return t.sessions}function SR(t){return{id:t.id,parentID:t.parentID}}function CR(){}function AR(t){return s.jsx("div",{className:"group w-full",children:s.jsx("div",{className:"chat-message-column",children:s.jsxs("div",{className:"space-y-2.5 px-4 py-3",children:[s.jsx("div",{className:"space-y-1.5",children:t.toolRows.map(e=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Zl,{className:"h-3.5 w-3.5 rounded-full flex-shrink-0"}),s.jsx(Zl,{className:Q("h-4 rounded-md",e.titleWidth)}),s.jsx(Zl,{className:Q("h-4 rounded-md",e.detailWidth)})]},`${t.id}-${e.id}`))}),s.jsxs("div",{className:"space-y-1.5 pt-1",children:[s.jsx(Zl,{className:Q("h-4 rounded-md",t.textWidths[0])}),s.jsx(Zl,{className:Q("h-4 rounded-md",t.textWidths[1])}),s.jsx(Zl,{className:Q("h-4 rounded-md",t.textWidths[2])})]})]})})},t.id)}class Kp extends d.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(Wu,{className:"w-full max-w-md",children:[s.jsx(f8,{className:"text-center",children:s.jsxs(m8,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(xx,{className:"h-5 w-5"}),"Chat Error"]})}),s.jsxs(h8,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"The chat interface encountered an error. This might be due to a temporary network issue or corrupted message data."}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["Session: ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:"Error details"}),s.jsx("pre",{className:"mt-2 overflow-x-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(Be,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(Er,{className:"h-4 w-4 mr-2"}),"Reset Chat"]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:"If the problem persists, try refreshing the page."})]})]})}):this.props.children}}const wi=()=>{const t=Fe.c(3),n=Ze(MR)||void 0;let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Zp,{}),t[0]=r):r=t[0];let o;return t[1]!==n?(o=s.jsx(Kp,{sessionId:n,children:r}),t[1]=n,t[2]=o):o=t[2],o};function MR(t){return t.currentSessionId}const FR={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},BR={case:"Match case",re:"Regular expression",word:"Match whole word"};function _R(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(FR)){const o=e.querySelector(`button[name="${n}"]`);o&&!o.title&&(o.title=r)}for(const[n,r]of Object.entries(BR)){const a=e.querySelector(`input[name="${n}"]`)?.parentElement;a&&!a.title&&(a.title=r)}}}const Pm=new Ti,Rm=new Ti,zm=new Ti,Lm=new Ti,Hm=new Ti,$m=new Ti,Om=t=>t,Yc=Ax,ER=Mx,DR=Fx;class IR extends Bx{constructor(e,n){super(),this.id=e,this.containerMap=n}toDOM(){let e=this.containerMap.get(this.id);return e||(e=document.createElement("div"),e.className="oc-block-widget",e.dataset.widgetId=this.id,this.containerMap.set(this.id,e)),e}eq(e){return e.id===this.id}destroy(){}}const Vm=(t,e)=>!t||t.length===0?[]:Cx.define({create(n){const r=new Qh,o=[...t].sort((a,l)=>a.afterLine-l.afterLine);for(const a of o){const l=n.doc.lines;if(a.afterLine>l)continue;const i=n.doc.line(a.afterLine);r.add(i.to,i.to,Jh.widget({widget:new IR(a.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>go.decorations.from(n)}),Um=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return Sx.fromClass(class{decorations;constructor(r){this.decorations=this.build(r)}update(r){(r.docChanged||r.viewportChanged)&&(this.decorations=this.build(r.view))}build(r){const o=new Qh;for(let a=e;a<=n&&a<=r.state.doc.lines;a+=1){const l=r.state.doc.line(a);o.add(l.from,l.from,Jh.line({class:"oc-cm-selected-line"}))}return o.finish()}},{decorations:r=>r.decorations})};function su({value:t,onChange:e,extensions:n,className:r,readOnly:o,lineNumbersConfig:a,highlightLines:l,onViewReady:i,onViewDestroy:c,blockWidgets:u,enableSearch:m,searchOpen:f,onSearchOpenChange:h}){const p=d.useRef(null),g=d.useRef(null),x=d.useRef(t),b=d.useRef(e),v=d.useRef(i),y=d.useRef(c),w=d.useRef(h),C=d.useRef(u),N=d.useRef(new Map),[S,k]=d.useState([]),j=d.useCallback(A=>{const M=(A??[]).map(B=>{const E=N.current.get(B.id);return E?{id:B.id,content:B.content,container:E}:null}).filter(B=>B!==null);k(B=>B.length===M.length&&B.every((E,I)=>{const P=M[I];return E.id===P.id&&E.content===P.content&&E.container===P.container})?B:M)},[]),F=d.useCallback(A=>{const M=p.current,B=A??g.current;if(!M||!B)return;const E=B.dom.querySelector(".cm-gutters"),I=E instanceof HTMLElement?E.getBoundingClientRect().width:0;M.style.setProperty("--oc-editor-gutter-width",`${I}px`)},[]);return d.useEffect(()=>{x.current=t},[t]),d.useEffect(()=>{b.current=e},[e]),d.useEffect(()=>{v.current=i,y.current=c},[i,c]),d.useEffect(()=>{w.current=h},[h]),d.useEffect(()=>{C.current=u,j(u)},[u,j]),d.useEffect(()=>{if(!p.current)return;const A=(()=>{if(typeof document>"u")return null;const B=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(B)return B;const E=window.__OPENCHAMBER_CSP_NONCE__;return typeof E=="string"&&E.length>0?E:null})(),M=bx.create({doc:x.current,extensions:[...A?[go.cspNonce.of(A)]:[],vx({fixed:!0}),Pm.of(C3(a)),yx(),wx.of(" "),ac.of([jx,...kx,...Nx]),go.updateListener.of(B=>{F(B.view),(B.viewportChanged||B.geometryChanged)&&j(C.current);const E=A3(B.startState),I=A3(B.state);if(E!==I&&w.current?.(I),!B.docChanged)return;const P=B.state.doc.toString();x.current=P,b.current(P),j(C.current)}),Rm.of(go.editable.of(!o)),zm.of(n??[]),Lm.of(Um(l)),Hm.of(Vm(u,N.current)),$m.of(m?[M3({top:!0}),ac.of(Om(F3))]:[])]});return g.current=new go({state:M,parent:p.current}),Yc(g.current,g.current.state.doc.length,200),g.current.requestMeasure(),requestAnimationFrame(()=>{F(g.current),j(C.current)}),g.current&&v.current?.(g.current),()=>{y.current?.(),g.current?.destroy(),g.current=null,k([])}},[C,F,j]),d.useEffect(()=>{const A=g.current;A&&(A.dispatch({effects:[Pm.reconfigure(C3(a)),Rm.reconfigure(go.editable.of(!o)),zm.reconfigure(n??[]),Lm.reconfigure(Um(l)),Hm.reconfigure(Vm(u,N.current)),$m.reconfigure(m?[M3({top:!0}),ac.of(Om(F3))]:[])]}),Yc(A,A.state.doc.length,200),A.requestMeasure(),requestAnimationFrame(()=>{F(A),j(C.current)}))},[n,l,a,o,u,m,F,j]),d.useEffect(()=>{const A=g.current;!A||m===!1||(f?(ER(A),requestAnimationFrame(()=>{_R(A.dom)})):DR(A))},[f,m]),d.useEffect(()=>{const A=g.current;if(!A)return;const M=A.state.doc.toString();M!==t&&(A.dispatch({changes:{from:0,to:M.length,insert:t}}),Yc(A,A.state.doc.length,300),A.requestMeasure(),requestAnimationFrame(()=>F(A)))},[t,F]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:p,className:Q("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",r)}),S.map(A=>To.createPortal(A.content,A.container,A.id))]})}const Yp=t=>{const e=Fe.c(11),{currentMode:n,onToggle:r}=t,o=n==="preview",a=o?"Switch to edit mode":"Switch to preview mode",l=o?"Edit":"Preview";let i;e[0]!==o?(i=o?s.jsx(Cu,{className:"size-4","aria-hidden":"true"}):s.jsx(Au,{className:"size-4","aria-hidden":"true"}),e[0]=o,e[1]=i):i=e[1];let c;e[2]!==a||e[3]!==r||e[4]!==i?(c=s.jsx(It,{asChild:!0,children:s.jsx(Be,{variant:"ghost",size:"sm",onClick:r,"aria-label":a,className:"h-5 w-5 p-0",children:i})}),e[2]=a,e[3]=r,e[4]=i,e[5]=c):c=e[5];let u;e[6]!==l?(u=s.jsx(_t,{sideOffset:8,children:l}),e[6]=l,e[7]=u):u=e[7];let m;return e[8]!==c||e[9]!==u?(m=s.jsxs(Dt,{delayDuration:500,children:[c,u]}),e[8]=c,e[9]=u,e[10]=m):m=e[10],m};function Xp(t){const e=Fe.c(53),{draft:n,onEdit:r,onDelete:o,className:a,maxWidth:l}=t,c=Sa()?.currentTheme,[u,m]=he.useState(!1),f=typeof n.text=="string"?n.text:"";let h;e[0]!==f?(h=f.length>150||f.split(`
7810
+ `;function _m(t){return new z2(t,{position:{size:2,data:new Float32Array([-.5,-.5,.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,.5])},uv:{size:2,data:new Float32Array([0,0,1,0,1,1,0,0,1,1,0,1])}})}function Gp(t,e,n,r){const o=document.createElement("canvas"),a=o.getContext("2d");if(!a)return new S3(t);o.width=128,o.height=32,a.fillStyle="transparent",a.fillRect(0,0,o.width,o.height),a.fillStyle="#ffffff",a.font=`${r} ${n}px system-ui, sans-serif`,a.textAlign="left",a.textBaseline="middle";const l=120;let i=e;if(a.measureText(e).width>l){for(;a.measureText(i+"...").width>l&&i.length>0;)i=i.slice(0,-1);i+="..."}return a.fillText(i,4,o.height/2),new S3(t,{image:o,minFilter:t.LINEAR,magFilter:t.LINEAR})}function WP(t,e){const n=_m(t),r=_m(t),o=new Ga(t,{vertex:$P,fragment:OP,transparent:!0,depthTest:!1,depthWrite:!1}),a=new Ga(t,{vertex:VP,fragment:UP,transparent:!0,depthTest:!1}),l=new Za(t,{geometry:n,program:o}),i=new Za(t,{geometry:r,program:a});i.position.z=.01;const c=Gp(t,e.toolName,11,"bold");return{cardMesh:l,labelMesh:i,cardProgram:o,labelProgram:a,cardGeometry:n,labelGeometry:r,labelTexture:c,labelDirty:!1,cachedToolName:e.toolName,cachedArgs:e.args}}function qP(t,e,n,r,o){const a=n.id===o,l=Bm[n.state]||Bm.pending,i=HP[n.state]||0;t.cardProgram.uniforms.uTime.value=r,t.cardProgram.uniforms.uCardSize.value=new ta(L1,H1,1),t.cardProgram.uniforms.uScale.value=1,t.cardProgram.uniforms.uPosition.value=new ta(n.x,n.y,0),t.cardProgram.uniforms.uStateColor.value=new ta(...l),t.cardProgram.uniforms.uOpacity.value=n.opacity,t.cardProgram.uniforms.uState.value=i,t.cardProgram.uniforms.uHovered.value=a,t.labelProgram&&t.labelMesh&&t.labelTexture&&((n.toolName!==t.cachedToolName||n.args!==t.cachedArgs||t.labelDirty)&&(t.labelTexture=Gp(e,n.toolName+" "+n.args,9,"normal"),t.cachedToolName=n.toolName,t.cachedArgs=n.args,t.labelDirty=!1),t.labelProgram.uniforms.uTexture.value=t.labelTexture,t.labelProgram.uniforms.uOpacity.value=n.opacity,t.labelMesh.position.x=n.x-L1/2+64,t.labelMesh.position.y=n.y-H1/2+16)}function Em(t){t.cardGeometry.remove(),t.cardProgram.remove(),t.labelGeometry&&t.labelGeometry.remove(),t.labelProgram&&t.labelProgram.remove()}const GP=t=>{const e=Fe.c(27),{width:n,height:r,transformRef:o,agents:a,toolCalls:l,selectedAgentId:i,hoveredAgentId:c}=t,u=he.useRef(null),m=he.useRef(null),f=he.useRef(null),h=he.useRef(null);let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=new Map,e[0]=p):p=e[0];const g=he.useRef(p);let x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=new Map,e[1]=x):x=e[1];const b=he.useRef(x);let v;e[2]===Symbol.for("react.memo_cache_sentinel")?(v={agents:[],tools:[]},e[2]=v):v=e[2];const y=he.useRef(v),w=he.useRef(0);let C;e[3]!==r||e[4]!==n?(C=()=>{if(n===0||r===0)return!1;const P=window.devicePixelRatio||1,D=FP(n,r,P);return h.current=D.renderer,f.current||(f.current=new zh(D.renderer.gl,{fov:45}),f.current.position.set(0,0,100),f.current.lookAt([0,0,0])),m.current!==D.canvas&&(m.current=D.canvas,u.current&&D.canvas.parentElement!==u.current&&u.current.appendChild(D.canvas)),D.renderer.gl.clearColor(0,0,0,0),!0},e[3]=r,e[4]=n,e[5]=C):C=e[5];const N=C;let S,k;e[6]!==N?(S=()=>{if(N())return ZP},k=[N],e[6]=N,e[7]=S,e[8]=k):(S=e[7],k=e[8]),he.useEffect(S,k);let j,F;e[9]!==a||e[10]!==l?(j=()=>{if(!h.current)return;const P=h.current.gl,D=a,L=l,T=new Set(g.current.keys()),_=new Set(D.keys());for(const W of T)if(!_.has(W)){const G=g.current.get(W);G&&(Fm(G),g.current.delete(W))}for(const[W,G]of D)if(!g.current.has(W)){const Y=zP(P,G);g.current.set(W,Y)}const z=new Set(b.current.keys()),R=new Set(L.keys());for(const W of z)if(!R.has(W)){const G=b.current.get(W);G&&(Em(G),b.current.delete(W))}for(const[W,G]of L)if(!b.current.has(W)){const Y=WP(P,G);b.current.set(W,Y)}y.current={agents:Array.from(g.current.values()),tools:Array.from(b.current.values())}},F=[a,l],e[9]=a,e[10]=l,e[11]=j,e[12]=F):(j=e[11],F=e[12]),he.useEffect(j,F);let A,M;e[13]!==a||e[14]!==r||e[15]!==c||e[16]!==i||e[17]!==l||e[18]!==o||e[19]!==n?(M=()=>{if(!f.current||!m.current||!h.current)return;let P=!0;const D=h.current,L=T=>{if(!P)return;w.current=requestAnimationFrame(L);const _=f.current;if(!_)return;const z=T*.001,R=o.current,W=D.gl;W.viewport(0,0,W.canvas.width,W.canvas.height),W.clear(W.COLOR_BUFFER_BIT|W.DEPTH_BUFFER_BIT);const G=n/r;_.perspective({aspect:G}),_.position.x=-R.x/R.scale,_.position.y=R.y/R.scale,_.position.z=100/R.scale,_.lookAt([0,0,0]);for(const[J,V]of g.current){const te=a.get(J);te&&(V.agentMesh.position.x=te.x,V.agentMesh.position.y=te.y,V.agentMesh.position.z=0,LP(V,W,te,z,c,i))}for(const[J,V]of b.current){const te=l.get(J);te&&qP(V,W,te,z,null)}const Y=y.current;for(const J of Y.agents)D.render({scene:J.agentMesh,camera:_}),J.particleMesh&&D.render({scene:J.particleMesh,camera:_});for(const J of Y.tools)D.render({scene:J.cardMesh,camera:_}),J.labelMesh&&D.render({scene:J.labelMesh,camera:_})};return w.current=requestAnimationFrame(L),()=>{P=!1,w.current&&cancelAnimationFrame(w.current)}},A=[n,r,o,a,l,i,c],e[13]=a,e[14]=r,e[15]=c,e[16]=i,e[17]=l,e[18]=o,e[19]=n,e[20]=A,e[21]=M):(A=e[20],M=e[21]),he.useEffect(M,A);let B,E;e[22]===Symbol.for("react.memo_cache_sentinel")?(B=()=>{const P=g.current,D=b.current;return()=>{for(const L of P.values())Fm(L);P.clear();for(const L of D.values())Em(L);D.clear()}},E=[],e[22]=B,e[23]=E):(B=e[22],E=e[23]),he.useEffect(B,E);let I;return e[24]!==r||e[25]!==n?(I=s.jsx("div",{ref:u,style:{position:"absolute",top:0,left:0,width:n,height:r,pointerEvents:"none",zIndex:10}}),e[24]=r,e[25]=n,e[26]=I):I=e[26],I};function ZP(){BP()}function KP(){try{return!!document.createElement("canvas").getContext("webgl2")}catch{return!1}}const YP=({selectedAgentId:t,hoveredAgentId:e,selectedToolCallId:n,selectedDiscoveryId:r,showCostOverlay:o,zoomToFitTrigger:a,pauseAutoFit:l,useParticleBackground:i,particleBackgroundColor:c,onAgentClick:u,onAgentHover:m,onAgentDrag:f,onContextMenu:h,onToolCallClick:p,onDiscoveryClick:g})=>{const x=he.useRef(null),b=he.useRef(null),[v,y]=he.useState({width:800,height:600}),w=he.useRef(0),C=he.useRef(0),N=he.useRef(null),S=he.useRef([]),k=he.useRef([]),j=he.useRef(0),F=he.useRef(1),A=he.useRef(()=>{}),M=he.useRef(()=>{}),B=he.useRef(new Map),E=he.useRef(new Map),I=he.useRef(0),P=he.useRef([]),D=he.useRef({x:-1e3,y:-1e3}),[L,T]=he.useState(!1),{currentTheme:_}=qn(),z=Nr(ge=>ge.updateAnimation),R=he.useMemo(()=>({background:_.colors.surface.background,foreground:_.colors.surface.foreground,mutedForeground:_.colors.surface.mutedForeground,elevated:_.colors.surface.elevated,primary:_.colors.primary.base,primaryForeground:_.colors.primary.foreground??"#ffffff",error:_.colors.status.error,success:_.colors.status.success,warning:_.colors.status.warning,info:_.colors.status.info,border:_.colors.interactive.border,hover:_.colors.interactive.hover,selection:_.colors.interactive.selection}),[_.colors]),W=he.useMemo(()=>{const ge=Nr.getState().agents;for(const xe of ge.values())if(xe.isMain)return xe},[]),G=()=>({agents:Nr.getState().agents,toolCalls:Nr.getState().toolCalls,discoveries:Nr.getState().discoveries,dimensions:v,selectedAgentId:t,selectedToolCallId:n??null,selectedDiscoveryId:r??null,pauseAutoFit:l??!1,showCostOverlay:o??!1,isDragging:!1,onAgentClick:u,onAgentHover:m,onAgentDrag:f,onContextMenu:h,onToolCallClick:p??(()=>{}),onDiscoveryClick:g??(()=>{})}),Y=he.useRef(G());Y.current={...Y.current,...G()};const{transformRef:J,userHasNavigatedRef:V,panVelocityRef:te,screenToCanvas:U,doZoomToFit:X,updateCamera:$}=NT({mainCanvasRef:b,drawPropsRef:Y,simTimeRef:C,dimensions:v,agentCount:Nr.getState().agents.size,zoomToFitTrigger:a,selectedAgentId:t}),{isDragging:q,handlers:ee,updateDragLerp:ce}=BT({drawPropsRef:Y,transformRef:J,userHasNavigatedRef:V,panVelocityRef:te,simTimeRef:C,screenToCanvas:U,doZoomToFit:X,mainCanvasRef:b});Y.current.isDragging=q,he.useEffect(()=>(N.current=new dP(.5),S.current=fP(v.width,v.height,yi.particleCount),P.current=hP(v.width,v.height,yi.particleCount,[R.primary,R.success,R.warning,R.info,R.foreground,R.mutedForeground]),()=>{N.current=null}),[]),he.useEffect(()=>{const ge=KP();T(ge)},[]),he.useEffect(()=>{const ge=x.current;if(!ge)return;const xe=window.devicePixelRatio||1;F.current=xe;const ne=new ResizeObserver(O=>{for(const H of O){const K=H.contentRect.width,re=H.contentRect.height;y({width:K,height:re}),N.current?.resize(K*xe,re*xe)}});return ne.observe(ge),()=>ne.disconnect()},[]);const ve=he.useCallback(ge=>{w.current=requestAnimationFrame(O=>A.current(O));const xe=b.current;if(!xe)return;const ne=xe.getContext("2d");if(ne)try{const O=F.current,H=v.width,K=v.height;(xe.width!==Math.round(H*O)||xe.height!==Math.round(K*O))&&(xe.width=Math.round(H*O),xe.height=Math.round(K*O),ne.scale(O,O)),ne.clearRect(0,0,H,K);const re=j.current?Math.min((ge-j.current)/1e3,.1):.016;j.current=ge;const le=Nr.getState(),{agents:ae,toolCalls:ue,particles:be,edges:oe,discoveries:Z,isPlaying:ie,camera:pe}=le;C.current=le.currentTime,ie&&z(re),$(q,l),ce(ae,f);{const Ne=CP(ae,ue,B.current,E.current,R.primary,R.success);Ne.effects.length>0&&k.current.push(...Ne.effects),B.current=Ne.newAgentStates,E.current=Ne.newToolStates}{const Ne=k.current;let _e=0;for(let de=0;de<Ne.length;de++)Ne[de].age+=re,Ne[de].age<Ne[de].duration&&(_e!==de&&(Ne[_e]=Ne[de]),_e++);Ne.length=_e}mP(S.current,re,H,K),P.current.length>0&&gP(P.current,re,H,K,D.current.x,D.current.y,[R.primary,R.success,R.warning,R.info,R.foreground,R.mutedForeground]);const me=J.current,Se=t?ae.get(t):void 0,ke=Se?{x:Se.x,y:Se.y,color:R.primary}:void 0;i||bP(ne,H,K,S.current,P.current,{x:me.x,y:me.y,scale:me.scale},{showHexGrid:!1,showDepthParticles:!0,showAnimParticles:!0,particleCount:yi.particleCount},ge*.001,R,ke),ne.save(),ne.translate(me.x,me.y),ne.scale(me.scale,me.scale);const ye=XT(be);if(QT(ne,oe,R,ae,ue,ye,ge*.001),eP(ne,be,R,ae,oe,ue,ge*.001),sP(ne,Array.from(ue.values()),R,le.currentTime),rP(ne,Z,R,ae),oP(ne,Z,R,r??null),cP(ne,ae,R,le.currentTime),KT(ne,ae,R,le.currentTime,t??null,e??null),t){const Ne=ae.get(t);Ne&&_T(ne,Ne,me,K,R)}o&&jP(ne,ae,ue,R),NP(ne,k.current),ne.restore(),N.current&&N.current.apply(xe,ne),(le.camera.x!==pe.x||le.camera.zoom!==pe.zoom)&&Nr.getState().setCamera({x:me.x,y:me.y,zoom:me.scale})}catch(O){const H=Date.now();H-I.current>5e3&&(I.current=H,console.warn("[AgentCanvas] draw error:",O))}},[v,z,$,ce,q,l,t,e,r,o,R,f,J]);return A.current=ve,M.current=he.useCallback(ge=>{A.current(ge)},[]),he.useEffect(()=>{const ge=xe=>A.current(xe);return w.current=requestAnimationFrame(ge),()=>{w.current&&cancelAnimationFrame(w.current)}},[]),s.jsxs("div",{ref:x,className:"relative w-full h-full overflow-hidden",style:{cursor:q?"grabbing":"grab"},onMouseMove:ge=>{const xe=b.current?.getBoundingClientRect();if(xe){const ne=J.current;D.current={x:(ge.clientX-xe.left-ne.x)/ne.scale,y:(ge.clientY-xe.top-ne.y)/ne.scale}}},onTouchMove:ge=>{const xe=b.current?.getBoundingClientRect();if(xe){const ne=J.current,O=ge.touches[0];D.current={x:(O.clientX-xe.left-ne.x)/ne.scale,y:(O.clientY-xe.top-ne.y)/ne.scale}}},onMouseLeave:()=>{D.current={x:-1e3,y:-1e3}},children:[i&&W&&s.jsx(MP,{color:c??R.primary,autoAnimate:!1,magnetRadius:10,ringRadius:8,waveSpeed:.4,waveAmplitude:1,particleSize:1.5,lerpSpeed:.05,particleVariance:1,rotationSpeed:.5,depthFactor:1,pulseSpeed:3,particleShape:"capsule",fieldStrength:10,agentX:W.x,agentY:W.y,transformRef:J}),i&&!W&&s.jsx(qd,{color:c??R.primary,autoAnimate:!0,magnetRadius:10,ringRadius:8,waveSpeed:.4,waveAmplitude:1,particleSize:1.5,lerpSpeed:.05,particleVariance:1,rotationSpeed:0,depthFactor:1,pulseSpeed:3,particleShape:"capsule",fieldStrength:10}),s.jsx("canvas",{ref:b,style:{width:v.width,height:v.height,backgroundColor:i?"transparent":R.background},...ee,className:"w-full h-full"}),L&&s.jsx(GP,{width:v.width,height:v.height,transformRef:J,agents:Nr.getState().agents,toolCalls:Nr.getState().toolCalls,selectedAgentId:t??null,hoveredAgentId:e??null}),!L&&s.jsx("div",{className:"absolute top-2 right-2 text-xs px-2 py-1 rounded bg-yellow-500/20 text-yellow-600",title:"WebGL 2.0 not supported - using Canvas 2D fallback",children:"WebGL unavailable"})]})},Kc=200;function XP(t){const e=Fe.c(14),{children:n,className:r,style:o,visible:a}=t,l=r===void 0?"":r,{currentTheme:i}=qn(),[c,u]=he.useState(!1),[m,f]=he.useState(!1);let h,p;if(e[0]!==a?(h=()=>{if(a)u(!0),requestAnimationFrame(()=>f(!0));else{f(!1);const S=setTimeout(()=>u(!1),Kc);return()=>clearTimeout(S)}},p=[a],e[0]=a,e[1]=h,e[2]=p):(h=e[1],p=e[2]),he.useEffect(h,p),!c)return null;const g=`glass-card ${l}`,x=i.colors.surface.elevated+"E6",b=`1px solid ${i.colors.interactive.border}40`,v=`0 8px 32px ${i.colors.surface.overlay}40`,y=m?1:0,w=m?"scale(1)":"scale(0.95)";let C;e[3]!==o||e[4]!==x||e[5]!==b||e[6]!==v||e[7]!==y||e[8]!==w?(C={...o,backgroundColor:x,backdropFilter:"blur(12px)",border:b,boxShadow:v,opacity:y,transform:w,transition:`opacity ${Kc}ms ease-out, transform ${Kc}ms ease-out`},e[3]=o,e[4]=x,e[5]=b,e[6]=v,e[7]=y,e[8]=w,e[9]=C):C=e[9];let N;return e[10]!==n||e[11]!==C||e[12]!==g?(N=s.jsx("div",{className:g,style:C,children:n}),e[10]=n,e[11]=C,e[12]=g,e[13]=N):N=e[13],N}function QP(t,e,n){const r=Fe.c(5),o=n;let a,l;r[0]!==o||r[1]!==e||r[2]!==t?(a=()=>{const i=u=>{t.current&&!t.current.contains(u.target)&&e()},c=setTimeout(()=>{document.addEventListener("mousedown",i)},o);return()=>{clearTimeout(c),document.removeEventListener("mousedown",i)}},l=[t,e,o],r[0]=o,r[1]=e,r[2]=t,r[3]=a,r[4]=l):(a=r[3],l=r[4]),he.useEffect(a,l)}const JP=150;function eR(t){const e=Fe.c(16),{position:n,items:r,onClose:o}=t,a=he.useRef(null),{currentTheme:l}=qn();QP(a,o,JP);let i;e[0]!==n.x||e[1]!==n.y?(i={position:"fixed",left:n.x,top:n.y,zIndex:1e3},e[0]=n.x,e[1]=n.y,e[2]=i):i=e[2];let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c={minWidth:160},e[3]=c):c=e[3];let u;if(e[4]!==l||e[5]!==r||e[6]!==o){let h;e[8]!==l||e[9]!==o?(h=(p,g)=>p.separator?s.jsx("div",{className:"my-1 h-px",style:{background:l.colors.interactive.border+"40"}},g):s.jsxs("button",{onClick:()=>{p.disabled||(p.onClick(),o())},disabled:p.disabled,className:"w-full px-3 py-1.5 text-left text-xs font-mono transition-colors flex items-center gap-2",style:{color:p.danger?l.colors.status.error:p.disabled?l.colors.surface.mutedForeground+"60":l.colors.surface.foreground,opacity:p.disabled?.5:1,cursor:p.disabled?"not-allowed":"pointer"},onMouseEnter:x=>{p.disabled||(x.currentTarget.style.backgroundColor=l.colors.interactive.hover)},onMouseLeave:tR,children:[p.icon&&s.jsx("span",{className:"w-4 h-4 flex items-center justify-center",children:p.icon}),p.label]},g),e[8]=l,e[9]=o,e[10]=h):h=e[10],u=r.map(h),e[4]=l,e[5]=r,e[6]=o,e[7]=u}else u=e[7];let m;e[11]!==u?(m=s.jsx(XP,{visible:!0,style:c,children:s.jsx("div",{className:"py-1",children:u})}),e[11]=u,e[12]=m):m=e[12];let f;return e[13]!==i||e[14]!==m?(f=s.jsx("div",{ref:a,style:i,onMouseDown:nR,onClick:sR,children:m}),e[13]=i,e[14]=m,e[15]=f):f=e[15],f}function tR(t){t.currentTarget.style.backgroundColor="transparent"}function sR(t){return t.stopPropagation()}function nR(t){return t.stopPropagation()}const rR=()=>{const t=Fe.c(37),{currentTheme:e}=qn(),n=Ee(oR),r=Ee(aR),o=Nr(ym.agents),a=Nr(ym.discoveries),l=Nr(lR),i=Nr(iR),c=Nr(cR);pT(!0),vT();const[u,m]=he.useState(0);let f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=new Map,t[0]=f):f=t[0];let h;t[1]!==o||t[2]!==a?(h={agents:o,toolCalls:f,discoveries:a},t[1]=o,t[2]=a,t[3]=h):h=t[3];const p=jT(h);let g,x;t[4]!==n||t[5]!==r?(g=()=>{const F=A=>{A.key==="Escape"&&n&&r(!1)};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},x=[n,r],t[4]=n,t[5]=r,t[6]=g,t[7]=x):(g=t[6],x=t[7]),he.useEffect(g,x);let b,v;if(t[8]!==n||t[9]!==i||t[10]!==l?(b=()=>(n&&l(),()=>{i()}),v=[n,l,i],t[8]=n,t[9]=i,t[10]=l,t[11]=b,t[12]=v):(b=t[11],v=t[12]),he.useEffect(b,v),!n)return null;let y;t[13]!==e.colors.surface.background?(y={backgroundColor:e.colors.surface.background},t[13]=e.colors.surface.background,t[14]=y):y=t[14];let w;t[15]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(U0,{}),t[15]=w):w=t[15];let C;t[16]!==c?(C=(F,A,M)=>c(F,A,M),t[16]=c,t[17]=C):C=t[17];let N;t[18]!==e.colors.primary.base||t[19]!==p.handleAgentClick||t[20]!==p.handleContextMenu||t[21]!==p.handleDiscoveryClick||t[22]!==p.hoveredAgentId||t[23]!==p.selectedAgentId||t[24]!==p.selectedDiscoveryId||t[25]!==p.setHoveredAgentId||t[26]!==C||t[27]!==u?(N=s.jsx(YP,{selectedAgentId:p.selectedAgentId,hoveredAgentId:p.hoveredAgentId,selectedToolCallId:null,selectedDiscoveryId:p.selectedDiscoveryId,showCostOverlay:!1,zoomToFitTrigger:u,pauseAutoFit:!1,useParticleBackground:!0,particleBackgroundColor:e.colors.primary.base,onAgentClick:p.handleAgentClick,onAgentHover:p.setHoveredAgentId,onAgentDrag:C,onContextMenu:p.handleContextMenu,onToolCallClick:dR,onDiscoveryClick:p.handleDiscoveryClick}),t[18]=e.colors.primary.base,t[19]=p.handleAgentClick,t[20]=p.handleContextMenu,t[21]=p.handleDiscoveryClick,t[22]=p.hoveredAgentId,t[23]=p.selectedAgentId,t[24]=p.selectedDiscoveryId,t[25]=p.setHoveredAgentId,t[26]=C,t[27]=u,t[28]=N):N=t[28];let S;t[29]!==p?(S=p.contextMenu&&s.jsx(eR,{position:p.contextMenu,items:[{label:"🔍 Zoom to Fit",onClick:()=>m(uR)}],onClose:()=>p.setContextMenu(null)}),t[29]=p,t[30]=S):S=t[30];let k;t[31]!==S||t[32]!==N?(k=s.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[w,N,S]}),t[31]=S,t[32]=N,t[33]=k):k=t[33];let j;return t[34]!==k||t[35]!==y?(j=s.jsx("div",{className:"fixed inset-0 z-50 flex flex-col",style:y,children:k}),t[34]=k,t[35]=y,t[36]=j):j=t[36],j};function oR(t){return t.isAgentFlowOpen}function aR(t){return t.setAgentFlowOpen}function lR(t){return t.play}function iR(t){return t.pause}function cR(t){return t.updateAgentPosition}function dR(){}function uR(t){return t+1}const fR=d.lazy(()=>Kn(()=>import("./TimelineDialog-DCaQs6K1.js"),__vite__mapDeps([5,0,1,3,4])).then(t=>({default:t.TimelineDialog}))),Dm=[],mR=[],hR=[],Im={type:"idle"},Tm="archcoder:session-reselected",pR=()=>Ze($r(yR)),gR=()=>Ze($r(wR)),xR=()=>Ee($r(jR)),bR=()=>Ze($r(kR)),vR=[{id:1,toolRows:[{id:"search",titleWidth:"w-24",detailWidth:"w-52"},{id:"read",titleWidth:"w-20",detailWidth:"w-36"},{id:"edit",titleWidth:"w-24",detailWidth:"w-64"}],textWidths:["w-24","w-[92%]","w-[78%]"]},{id:2,toolRows:[{id:"read",titleWidth:"w-20",detailWidth:"w-40"},{id:"search",titleWidth:"w-24",detailWidth:"w-48"}],textWidths:["w-20","w-[88%]","w-[70%]"]},{id:3,toolRows:[{id:"shell",titleWidth:"w-28",detailWidth:"w-44"},{id:"edit",titleWidth:"w-24",detailWidth:"w-56"}],textWidths:["w-24","w-[84%]","w-[64%]"]}],Zp=()=>{const t=Fe.c(211),{currentSessionId:e,loadMessages:n,loadMoreMessages:r,updateViewportAnchor:o,openNewSessionDraft:a,setCurrentSession:l,newSessionDraft:i}=pR(),{isSyncing:c,messageStreamStates:u,sessionMemoryStateMap:m}=gR(),{isTimelineDialogOpen:f,setTimelineDialogOpen:h,isExpandedInput:p,stickyUserHeader:g,chatRenderMode:x}=xR();let b;t[0]!==e?(b=Ue=>e?Ue.messages.get(e)??Dm:Dm,t[0]=e,t[1]=b):b=t[1];const v=Ze(b),y=Ze(NR),w=bR();let C;t[2]!==w.sessions||t[3]!==e?(C=AI(w.sessions.map(SR),e),t[2]=w.sessions,t[3]=e,t[4]=C):C=t[4];const N=C;let S;e:{if(N.length===0){S=mR;break e}let Ue;t[5]!==w.permissions||t[6]!==N?(Ue=hm(w.permissions,N),t[5]=w.permissions,t[6]=N,t[7]=Ue):Ue=t[7],S=Ue}const k=S;let j;e:{if(N.length===0){j=hR;break e}let Ue;t[8]!==w.questions||t[9]!==N?(Ue=hm(w.questions,N),t[8]=w.questions,t[9]=N,t[10]=Ue):Ue=t[10],j=Ue}const F=j;let A;t[11]!==e?(A=Ue=>e?Ue.sessionHistoryMeta.get(e)??null:null,t[11]=e,t[12]=A):A=t[12];const M=Ze(A);let B;t[13]!==e?(B=Ue=>e?Ue.streamingMessageIds.get(e)??null:null,t[13]=e,t[14]=B):B=t[14];const E=Ze(B);let I;t[15]!==e?(I=Ue=>e?Ue.sessionStatus?.get(e)??Im:Im,t[15]=e,t[16]=I):I=t[16];const P=Ze(I);let D;t[17]!==e?(D=Ue=>e?Ue.messages.has(e):!1,t[17]=e,t[18]=D):D=t[18];const L=Ze(D),{isMobile:T}=wn(),_=!!i?.open,z=p&&!T,R=d.useRef(null);let W;e:{if(!e){W=null;break e}let Ue;if(t[19]!==e||t[20]!==y){let Nt;t[22]!==e?(Nt=jt=>jt.id===e,t[22]=e,t[23]=Nt):Nt=t[23],Ue=y.find(Nt),t[19]=e,t[20]=y,t[21]=Ue}else Ue=t[21];const Qe=Ue?.parentID;if(!Qe){W=null;break e}let at;t[24]!==Qe||t[25]!==y?(at=y.find(Nt=>Nt.id===Qe)??null,t[24]=Qe,t[25]=y,t[26]=at):at=t[26],W=at}const G=W;let Y;t[27]!==G||t[28]!==l?(Y=()=>{G&&l(G.id)},t[27]=G,t[28]=l,t[29]=Y):Y=t[29];const J=Y;let V;t[30]!==J||t[31]!==G?(V=G?s.jsxs(Be,{type:"button",variant:"outline",size:"xs",onClick:J,className:"absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95","aria-label":"Return to parent session",title:G.title?.trim()?`Return to: ${G.title}`:"Return to parent session",children:[s.jsx(Su,{className:"h-4 w-4"}),"Parent"]}):null,t[30]=J,t[31]=G,t[32]=V):V=t[32];const te=V;let U,X;t[33]!==e||t[34]!==_||t[35]!==a?(U=()=>{!e&&!_&&a()},X=[e,_,a],t[33]=e,t[34]=_,t[35]=a,t[36]=U,t[37]=X):(U=t[36],X=t[37]),d.useEffect(U,X);let $;t[38]!==k||t[39]!==F?($=[...k,...F],t[38]=k,t[39]=F,t[40]=$):$=t[40];const q=$,ee=d.useRef(CR);let ce;t[41]===Symbol.for("react.memo_cache_sentinel")?(ce=Ue=>{ee.current(Ue)},t[41]=ce):ce=t[41];let ve;t[42]!==x||t[43]!==e||t[44]!==T||t[45]!==c||t[46]!==u||t[47]!==q||t[48]!==m||t[49]!==v||t[50]!==E||t[51]!==o?(ve={currentSessionId:e,sessionMessages:v,streamingMessageId:E,sessionMemoryState:m,updateViewportAnchor:o,isSyncing:c,isMobile:T,chatRenderMode:x,messageStreamStates:u,sessionPermissions:q,onActiveTurnChange:ce},t[42]=x,t[43]=e,t[44]=T,t[45]=c,t[46]=u,t[47]=q,t[48]=m,t[49]=v,t[50]=E,t[51]=o,t[52]=ve):ve=t[52];const{scrollRef:ge,handleMessageContentChange:xe,getAnimationHandlers:ne,scrollToBottom:O,releasePinnedScroll:H,isPinned:K,isOverflowing:re,isProgrammaticFollowActive:le}=fI(ve);let ae;t[53]!==e||t[54]!==M||t[55]!==re||t[56]!==K||t[57]!==r||t[58]!==ge||t[59]!==O||t[60]!==v?(ae={sessionId:e,messages:v,historyMeta:M,scrollRef:ge,messageListRef:R,loadMoreMessages:r,scrollToBottom:O,isPinned:K,isOverflowing:re},t[53]=e,t[54]=M,t[55]=re,t[56]=K,t[57]=r,t[58]=ge,t[59]=O,t[60]=v,t[61]=ae):ae=t[61];const ue=kI(ae),{resumeToBottomInstant:be}=ue;let oe,Z;t[62]!==ue.handleActiveTurnChange?(oe=()=>{ee.current=ue.handleActiveTurnChange},Z=[ue.handleActiveTurnChange],t[62]=ue.handleActiveTurnChange,t[63]=oe,t[64]=Z):(oe=t[63],Z=t[64]),d.useEffect(oe,Z);let ie;t[65]!==e||t[66]!==ue.activeTurnId||t[67]!==ue.resumeToBottom||t[68]!==ue.scrollToMessage||t[69]!==ue.scrollToTurn||t[70]!==ue.turnIds?(ie={sessionId:e,turnIds:ue.turnIds,activeTurnId:ue.activeTurnId,scrollToTurn:ue.scrollToTurn,scrollToMessage:ue.scrollToMessage,resumeToBottom:ue.resumeToBottom},t[65]=e,t[66]=ue.activeTurnId,t[67]=ue.resumeToBottom,t[68]=ue.scrollToMessage,t[69]=ue.scrollToTurn,t[70]=ue.turnIds,t[71]=ie):ie=t[71];const pe=CI(ie);let me,Se;t[72]!==e||t[73]!==be?(me=()=>{if(typeof window>"u"||!e)return;const Ue=ct=>{ct.detail===e&&be()};return window.addEventListener(Tm,Ue),()=>{window.removeEventListener(Tm,Ue)}},Se=[e,be],t[72]=e,t[73]=be,t[74]=me,t[75]=Se):(me=t[74],Se=t[75]),d.useEffect(me,Se);let ke;t[76]!==ge?(ke=()=>{const Ue=ge.current;if(!Ue)return;const ct=()=>{Ue.style.setProperty("--chat-scroll-height",`${Ue.clientHeight}px`)};ct();let Qe=0;const at=()=>{Qe||(Qe=requestAnimationFrame(()=>{Qe=0,ct()}))};if(typeof ResizeObserver>"u")return window.addEventListener("resize",at),()=>{Qe&&cancelAnimationFrame(Qe),window.removeEventListener("resize",at)};const Nt=new ResizeObserver(at);return Nt.observe(Ue),()=>{Qe&&cancelAnimationFrame(Qe),Nt.disconnect()}},t[76]=ge,t[77]=ke):ke=t[77];let ye;t[78]!==e||t[79]!==z||t[80]!==ge?(ye=[e,z,ge],t[78]=e,t[79]=z,t[80]=ge,t[81]=ye):ye=t[81],d.useLayoutEffect(ke,ye);const Ne=!!M,_e=!!e&&(!L||!Ne||M?.loading===!0);let de;t[82]!==e||t[83]!==Ne||t[84]!==L||t[85]!==K||t[86]!==n||t[87]!==O||t[88]!==P.type?(de=()=>{if(!e||L&&Ne)return;(async()=>await n(e).finally(()=>{const Qe=P.type??"idle",at=Qe==="busy"||Qe==="retry",Nt=typeof window<"u"&&window.location.hash.length>0;at&&K||Nt||(typeof window>"u"?O({instant:!0}):window.requestAnimationFrame(()=>{O({instant:!0})}))}))()},t[82]=e,t[83]=Ne,t[84]=L,t[85]=K,t[86]=n,t[87]=O,t[88]=P.type,t[89]=de):de=t[89];let we;if(t[90]!==e||t[91]!==Ne||t[92]!==L||t[93]!==K||t[94]!==n||t[95]!==O||t[96]!==v.length||t[97]!==P.type?(we=[e,Ne,L,K,n,O,v.length,P.type],t[90]=e,t[91]=Ne,t[92]=L,t[93]=K,t[94]=n,t[95]=O,t[96]=v.length,t[97]=P.type,t[98]=we):we=t[98],d.useEffect(de,we),!e&&!_){let Ue;t[99]!==T?(Ue=T?{paddingBottom:"var(--oc-keyboard-inset, 0px)"}:void 0,t[99]=T,t[100]=Ue):Ue=t[100];let ct;t[101]===Symbol.for("react.memo_cache_sentinel")?(ct=s.jsx(Rc,{}),t[101]=ct):ct=t[101];let Qe;return t[102]!==Ue?(Qe=s.jsx("div",{className:"flex flex-col h-full bg-background",style:Ue,children:ct}),t[102]=Ue,t[103]=Qe):Qe=t[103],Qe}if(!e&&_){let Ue;t[104]!==T?(Ue=T?{paddingBottom:"var(--oc-keyboard-inset, 0px)"}:void 0,t[104]=T,t[105]=Ue):Ue=t[105];let ct;t[106]!==z?(ct=z?null:s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsx(Rc,{})}),t[106]=z,t[107]=ct):ct=t[107];const Qe=z?"flex-1 min-h-0 bg-background":"bg-background/95 supports-[backdrop-filter]:bg-background/80";let at;t[108]!==Qe?(at=Q("relative z-10",Qe),t[108]=Qe,t[109]=at):at=t[109];let Nt;t[110]!==O?(Nt=s.jsx(m0,{scrollToBottom:O}),t[110]=O,t[111]=Nt):Nt=t[111];let jt;t[112]!==at||t[113]!==Nt?(jt=s.jsx("div",{className:at,children:Nt}),t[112]=at,t[113]=Nt,t[114]=jt):jt=t[114];let qt;return t[115]!==Ue||t[116]!==ct||t[117]!==jt?(qt=s.jsxs("div",{className:"relative flex flex-col h-full bg-background transform-gpu",style:Ue,children:[ct,jt]}),t[115]=Ue,t[116]=ct,t[117]=jt,t[118]=qt):qt=t[118],qt}if(!e)return null;if(_e&&v.length===0&&!E){let Ue;t[119]!==T?(Ue=T?{paddingBottom:"var(--oc-keyboard-inset, 0px)"}:void 0,t[119]=T,t[120]=Ue):Ue=t[120];let ct;t[121]===Symbol.for("react.memo_cache_sentinel")?(ct=s.jsx(U0,{}),t[121]=ct):ct=t[121];let Qe;t[122]===Symbol.for("react.memo_cache_sentinel")?(Qe=s.jsx("div",{className:"flex-1 overflow-y-auto bg-background pt-6",children:s.jsx("div",{className:"space-y-4",children:vR.map(AR)})}),t[122]=Qe):Qe=t[122];let at;t[123]!==O?(at=s.jsx(m0,{scrollToBottom:O}),t[123]=O,t[124]=at):at=t[124];let Nt;return t[125]!==te||t[126]!==Ue||t[127]!==at?(Nt=s.jsxs("div",{className:"relative flex flex-col h-full bg-background gap-0",style:Ue,children:[te,ct,Qe,at]}),t[125]=te,t[126]=Ue,t[127]=at,t[128]=Nt):Nt=t[128],Nt}if(v.length===0&&!E){let Ue;t[129]!==T?(Ue=T?{paddingBottom:"var(--oc-keyboard-inset, 0px)"}:void 0,t[129]=T,t[130]=Ue):Ue=t[130];let ct;t[131]===Symbol.for("react.memo_cache_sentinel")?(ct=s.jsx(U0,{}),t[131]=ct):ct=t[131];let Qe;t[132]!==z?(Qe=z?null:s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsx(Rc,{})}),t[132]=z,t[133]=Qe):Qe=t[133];const at=z?"flex-1 min-h-0 bg-background":"bg-background/95 supports-[backdrop-filter]:bg-background/80";let Nt;t[134]!==at?(Nt=Q("relative z-10",at),t[134]=at,t[135]=Nt):Nt=t[135];let jt;t[136]!==O?(jt=s.jsx(m0,{scrollToBottom:O}),t[136]=O,t[137]=jt):jt=t[137];let qt;t[138]!==Nt||t[139]!==jt?(qt=s.jsx("div",{className:Nt,children:jt}),t[138]=Nt,t[139]=jt,t[140]=qt):qt=t[140];let Zt;return t[141]!==te||t[142]!==Ue||t[143]!==Qe||t[144]!==qt?(Zt=s.jsxs("div",{className:"relative flex flex-col h-full bg-background transform-gpu",style:Ue,children:[te,ct,Qe,qt]}),t[141]=te,t[142]=Ue,t[143]=Qe,t[144]=qt,t[145]=Zt):Zt=t[145],Zt}let je;t[146]!==T?(je=T?{paddingBottom:"var(--oc-keyboard-inset, 0px)"}:void 0,t[146]=T,t[147]=je):je=t[147];let Ce;t[148]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(U0,{}),t[148]=Ce):Ce=t[148];const ze=z?"absolute inset-0 opacity-0 pointer-events-none":"flex-1";let Ge;t[149]!==ze?(Ge=Q("relative min-h-0",ze),t[149]=ze,t[150]=Ge):Ge=t[150];const Le=T&&g;let qe;t[151]!==ue?(qe=()=>{ue.loadEarlier()},t[151]=ue,t[152]=qe):qe=t[152];let rt;t[153]!==e||t[154]!==ne||t[155]!==xe||t[156]!==ge||t[157]!==O||t[158]!==k||t[159]!==F||t[160]!==qe||t[161]!==ue.historySignals.hasMoreAboveTurns||t[162]!==ue.isLoadingOlder||t[163]!==ue.pendingRevealWork||t[164]!==ue.renderedMessages||t[165]!==ue.turnStart?(rt=s.jsx("div",{className:"relative z-0 min-h-full",children:s.jsx(qD,{ref:R,sessionKey:e,turnStart:ue.turnStart,disableStaging:ue.pendingRevealWork,messages:ue.renderedMessages,permissions:k,questions:F,onMessageContentChange:xe,getAnimationHandlers:ne,hasMoreAbove:ue.historySignals.hasMoreAboveTurns,isLoadingOlder:ue.isLoadingOlder,onLoadOlder:qe,scrollToBottom:O,scrollRef:ge})}),t[153]=e,t[154]=ne,t[155]=xe,t[156]=ge,t[157]=O,t[158]=k,t[159]=F,t[160]=qe,t[161]=ue.historySignals.hasMoreAboveTurns,t[162]=ue.isLoadingOlder,t[163]=ue.pendingRevealWork,t[164]=ue.renderedMessages,t[165]=ue.turnStart,t[166]=rt):rt=t[166];let st;t[167]!==ge||t[168]!==Le||t[169]!==rt?(st=s.jsx(Qa,{className:"absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target",ref:ge,observeMutations:!1,hideTopShadow:Le,"data-scroll-shadow":"true","data-scrollbar":"chat",children:rt}),t[167]=ge,t[168]=Le,t[169]=rt,t[170]=st):st=t[170];let it;t[171]!==le||t[172]!==ge?(it=s.jsx(K2,{containerRef:ge,suppressVisibility:le,userIntentOnly:!0}),t[171]=le,t[172]=ge,t[173]=it):it=t[173];let lt;t[174]!==st||t[175]!==it?(lt=s.jsxs("div",{className:"absolute inset-0",children:[st,it]}),t[174]=st,t[175]=it,t[176]=lt):lt=t[176];let He;t[177]!==z||t[178]!==Ge||t[179]!==lt?(He=s.jsx("div",{className:Ge,"aria-hidden":z,children:lt}),t[177]=z,t[178]=Ge,t[179]=lt,t[180]=He):He=t[180];const Oe=z?"flex-1 min-h-0 bg-background":"bg-background/95 supports-[backdrop-filter]:bg-background/80";let se;t[181]!==Oe?(se=Q("relative z-10",Oe),t[181]=Oe,t[182]=se):se=t[182];let Pe;t[183]!==z||t[184]!==pe.resumeToLatest||t[185]!==v.length||t[186]!==ue.showScrollToBottom?(Pe=!z&&v.length>0&&s.jsx(YD,{visible:ue.showScrollToBottom,onClick:pe.resumeToLatest}),t[183]=z,t[184]=pe.resumeToLatest,t[185]=v.length,t[186]=ue.showScrollToBottom,t[187]=Pe):Pe=t[187];let Ye;t[188]!==O?(Ye=s.jsx(m0,{scrollToBottom:O}),t[188]=O,t[189]=Ye):Ye=t[189];let We;t[190]!==se||t[191]!==Pe||t[192]!==Ye?(We=s.jsxs("div",{className:se,children:[Pe,Ye]}),t[190]=se,t[191]=Pe,t[192]=Ye,t[193]=We):We=t[193];let xt,et;t[194]!==pe||t[195]!==H?(xt=Ue=>(H(),pe.scrollToMessageId(Ue,{behavior:"smooth",updateHash:!1})),et=Ue=>{H(),pe.scrollByTurnOffset(Ue)},t[194]=pe,t[195]=H,t[196]=xt,t[197]=et):(xt=t[196],et=t[197]);let tt;t[198]!==f||t[199]!==pe.resumeToLatest||t[200]!==h||t[201]!==xt||t[202]!==et?(tt=s.jsx(d.Suspense,{fallback:null,children:s.jsx(fR,{open:f,onOpenChange:h,onScrollToMessage:xt,onScrollByTurnOffset:et,onResumeToLatest:pe.resumeToLatest})}),t[198]=f,t[199]=pe.resumeToLatest,t[200]=h,t[201]=xt,t[202]=et,t[203]=tt):tt=t[203];let ht;t[204]===Symbol.for("react.memo_cache_sentinel")?(ht=s.jsx(rR,{}),t[204]=ht):ht=t[204];let St;return t[205]!==te||t[206]!==je||t[207]!==He||t[208]!==We||t[209]!==tt?(St=s.jsxs("div",{className:"relative flex flex-col h-full bg-background",style:je,children:[te,Ce,He,We,tt,ht]}),t[205]=te,t[206]=je,t[207]=He,t[208]=We,t[209]=tt,t[210]=St):St=t[210],St};function yR(t){return{currentSessionId:t.currentSessionId,loadMessages:t.loadMessages,loadMoreMessages:t.loadMoreMessages,updateViewportAnchor:t.updateViewportAnchor,openNewSessionDraft:t.openNewSessionDraft,setCurrentSession:t.setCurrentSession,newSessionDraft:t.newSessionDraft}}function wR(t){return{isSyncing:t.isSyncing,messageStreamStates:t.messageStreamStates,sessionMemoryStateMap:t.sessionMemoryState}}function jR(t){return{isTimelineDialogOpen:t.isTimelineDialogOpen,setTimelineDialogOpen:t.setTimelineDialogOpen,isExpandedInput:t.isExpandedInput,stickyUserHeader:t.stickyUserHeader,chatRenderMode:t.chatRenderMode}}function kR(t){return{sessions:t.sessions,permissions:t.permissions,questions:t.questions}}function NR(t){return t.sessions}function SR(t){return{id:t.id,parentID:t.parentID}}function CR(){}function AR(t){return s.jsx("div",{className:"group w-full",children:s.jsx("div",{className:"chat-message-column",children:s.jsxs("div",{className:"space-y-2.5 px-4 py-3",children:[s.jsx("div",{className:"space-y-1.5",children:t.toolRows.map(e=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Zl,{className:"h-3.5 w-3.5 rounded-full flex-shrink-0"}),s.jsx(Zl,{className:Q("h-4 rounded-md",e.titleWidth)}),s.jsx(Zl,{className:Q("h-4 rounded-md",e.detailWidth)})]},`${t.id}-${e.id}`))}),s.jsxs("div",{className:"space-y-1.5 pt-1",children:[s.jsx(Zl,{className:Q("h-4 rounded-md",t.textWidths[0])}),s.jsx(Zl,{className:Q("h-4 rounded-md",t.textWidths[1])}),s.jsx(Zl,{className:Q("h-4 rounded-md",t.textWidths[2])})]})]})})},t.id)}class Kp extends d.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(Wu,{className:"w-full max-w-md",children:[s.jsx(f8,{className:"text-center",children:s.jsxs(m8,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(xx,{className:"h-5 w-5"}),"Chat Error"]})}),s.jsxs(h8,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"The chat interface encountered an error. This might be due to a temporary network issue or corrupted message data."}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["Session: ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:"Error details"}),s.jsx("pre",{className:"mt-2 overflow-x-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(Be,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(Er,{className:"h-4 w-4 mr-2"}),"Reset Chat"]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:"If the problem persists, try refreshing the page."})]})]})}):this.props.children}}const wi=()=>{const t=Fe.c(3),n=Ze(MR)||void 0;let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Zp,{}),t[0]=r):r=t[0];let o;return t[1]!==n?(o=s.jsx(Kp,{sessionId:n,children:r}),t[1]=n,t[2]=o):o=t[2],o};function MR(t){return t.currentSessionId}const FR={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},BR={case:"Match case",re:"Regular expression",word:"Match whole word"};function _R(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(FR)){const o=e.querySelector(`button[name="${n}"]`);o&&!o.title&&(o.title=r)}for(const[n,r]of Object.entries(BR)){const a=e.querySelector(`input[name="${n}"]`)?.parentElement;a&&!a.title&&(a.title=r)}}}const Pm=new Ti,Rm=new Ti,zm=new Ti,Lm=new Ti,Hm=new Ti,$m=new Ti,Om=t=>t,Yc=Ax,ER=Mx,DR=Fx;class IR extends Bx{constructor(e,n){super(),this.id=e,this.containerMap=n}toDOM(){let e=this.containerMap.get(this.id);return e||(e=document.createElement("div"),e.className="oc-block-widget",e.dataset.widgetId=this.id,this.containerMap.set(this.id,e)),e}eq(e){return e.id===this.id}destroy(){}}const Vm=(t,e)=>!t||t.length===0?[]:Cx.define({create(n){const r=new Qh,o=[...t].sort((a,l)=>a.afterLine-l.afterLine);for(const a of o){const l=n.doc.lines;if(a.afterLine>l)continue;const i=n.doc.line(a.afterLine);r.add(i.to,i.to,Jh.widget({widget:new IR(a.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>go.decorations.from(n)}),Um=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return Sx.fromClass(class{decorations;constructor(r){this.decorations=this.build(r)}update(r){(r.docChanged||r.viewportChanged)&&(this.decorations=this.build(r.view))}build(r){const o=new Qh;for(let a=e;a<=n&&a<=r.state.doc.lines;a+=1){const l=r.state.doc.line(a);o.add(l.from,l.from,Jh.line({class:"oc-cm-selected-line"}))}return o.finish()}},{decorations:r=>r.decorations})};function su({value:t,onChange:e,extensions:n,className:r,readOnly:o,lineNumbersConfig:a,highlightLines:l,onViewReady:i,onViewDestroy:c,blockWidgets:u,enableSearch:m,searchOpen:f,onSearchOpenChange:h}){const p=d.useRef(null),g=d.useRef(null),x=d.useRef(t),b=d.useRef(e),v=d.useRef(i),y=d.useRef(c),w=d.useRef(h),C=d.useRef(u),N=d.useRef(new Map),[S,k]=d.useState([]),j=d.useCallback(A=>{const M=(A??[]).map(B=>{const E=N.current.get(B.id);return E?{id:B.id,content:B.content,container:E}:null}).filter(B=>B!==null);k(B=>B.length===M.length&&B.every((E,I)=>{const P=M[I];return E.id===P.id&&E.content===P.content&&E.container===P.container})?B:M)},[]),F=d.useCallback(A=>{const M=p.current,B=A??g.current;if(!M||!B)return;const E=B.dom.querySelector(".cm-gutters"),I=E instanceof HTMLElement?E.getBoundingClientRect().width:0;M.style.setProperty("--oc-editor-gutter-width",`${I}px`)},[]);return d.useEffect(()=>{x.current=t},[t]),d.useEffect(()=>{b.current=e},[e]),d.useEffect(()=>{v.current=i,y.current=c},[i,c]),d.useEffect(()=>{w.current=h},[h]),d.useEffect(()=>{C.current=u,j(u)},[u,j]),d.useEffect(()=>{if(!p.current)return;const A=(()=>{if(typeof document>"u")return null;const B=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(B)return B;const E=window.__OPENCHAMBER_CSP_NONCE__;return typeof E=="string"&&E.length>0?E:null})(),M=bx.create({doc:x.current,extensions:[...A?[go.cspNonce.of(A)]:[],vx({fixed:!0}),Pm.of(C3(a)),yx(),wx.of(" "),ac.of([jx,...kx,...Nx]),go.updateListener.of(B=>{F(B.view),(B.viewportChanged||B.geometryChanged)&&j(C.current);const E=A3(B.startState),I=A3(B.state);if(E!==I&&w.current?.(I),!B.docChanged)return;const P=B.state.doc.toString();x.current=P,b.current(P),j(C.current)}),Rm.of(go.editable.of(!o)),zm.of(n??[]),Lm.of(Um(l)),Hm.of(Vm(u,N.current)),$m.of(m?[M3({top:!0}),ac.of(Om(F3))]:[])]});return g.current=new go({state:M,parent:p.current}),Yc(g.current,g.current.state.doc.length,200),g.current.requestMeasure(),requestAnimationFrame(()=>{F(g.current),j(C.current)}),g.current&&v.current?.(g.current),()=>{y.current?.(),g.current?.destroy(),g.current=null,k([])}},[C,F,j]),d.useEffect(()=>{const A=g.current;A&&(A.dispatch({effects:[Pm.reconfigure(C3(a)),Rm.reconfigure(go.editable.of(!o)),zm.reconfigure(n??[]),Lm.reconfigure(Um(l)),Hm.reconfigure(Vm(u,N.current)),$m.reconfigure(m?[M3({top:!0}),ac.of(Om(F3))]:[])]}),Yc(A,A.state.doc.length,200),A.requestMeasure(),requestAnimationFrame(()=>{F(A),j(C.current)}))},[n,l,a,o,u,m,F,j]),d.useEffect(()=>{const A=g.current;!A||m===!1||(f?(ER(A),requestAnimationFrame(()=>{_R(A.dom)})):DR(A))},[f,m]),d.useEffect(()=>{const A=g.current;if(!A)return;const M=A.state.doc.toString();M!==t&&(A.dispatch({changes:{from:0,to:M.length,insert:t}}),Yc(A,A.state.doc.length,300),A.requestMeasure(),requestAnimationFrame(()=>F(A)))},[t,F]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:p,className:Q("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",r)}),S.map(A=>To.createPortal(A.content,A.container,A.id))]})}const Yp=t=>{const e=Fe.c(11),{currentMode:n,onToggle:r}=t,o=n==="preview",a=o?"Switch to edit mode":"Switch to preview mode",l=o?"Edit":"Preview";let i;e[0]!==o?(i=o?s.jsx(Cu,{className:"size-4","aria-hidden":"true"}):s.jsx(Au,{className:"size-4","aria-hidden":"true"}),e[0]=o,e[1]=i):i=e[1];let c;e[2]!==a||e[3]!==r||e[4]!==i?(c=s.jsx(It,{asChild:!0,children:s.jsx(Be,{variant:"ghost",size:"sm",onClick:r,"aria-label":a,className:"h-5 w-5 p-0",children:i})}),e[2]=a,e[3]=r,e[4]=i,e[5]=c):c=e[5];let u;e[6]!==l?(u=s.jsx(_t,{sideOffset:8,children:l}),e[6]=l,e[7]=u):u=e[7];let m;return e[8]!==c||e[9]!==u?(m=s.jsxs(Dt,{delayDuration:500,children:[c,u]}),e[8]=c,e[9]=u,e[10]=m):m=e[10],m};function Xp(t){const e=Fe.c(53),{draft:n,onEdit:r,onDelete:o,className:a,maxWidth:l}=t,c=Sa()?.currentTheme,[u,m]=he.useState(!1),f=typeof n.text=="string"?n.text:"";let h;e[0]!==f?(h=f.length>150||f.split(`
7811
7811
  `).length>3,e[0]=f,e[1]=h):h=e[1];const p=h;let g;e[2]!==a?(g=Q("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",a),e[2]=a,e[3]=g):g=e[3];const x=c?.colors?.surface?.elevated,b=c?.colors?.interactive?.border,v=l?`${Math.max(200,Math.floor(l))}px`:void 0;let y;e[4]!==x||e[5]!==b||e[6]!==v?(y={backgroundColor:x,borderColor:b,maxWidth:v},e[4]=x,e[5]=b,e[6]=v,e[7]=y):y=e[7];let w;e[8]!==n.fileLabel?(w=s.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[8]=n.fileLabel,e[9]=w):w=e[9];let C;e[10]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx("span",{children:"•"}),e[10]=C):C=e[10];let N;e[11]!==n.endLine||e[12]!==n.startLine?(N=s.jsxs("span",{children:["Lines ",n.startLine,"-",n.endLine]}),e[11]=n.endLine,e[12]=n.startLine,e[13]=N):N=e[13];let S;e[14]!==n.side?(S=n.side&&s.jsxs("span",{children:["(",n.side,")"]}),e[14]=n.side,e[15]=S):S=e[15];let k;e[16]!==S||e[17]!==w||e[18]!==N?(k=s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[w,C,N,S]}),e[16]=S,e[17]=w,e[18]=N,e[19]=k):k=e[19];const j=u||!p,F=!u&&p&&"line-clamp-3";let A;e[20]!==F?(A=Q("text-sm whitespace-pre-wrap break-words leading-relaxed",F),e[20]=F,e[21]=A):A=e[21];let M;e[22]!==f||e[23]!==A?(M=s.jsx("div",{className:A,children:f}),e[22]=f,e[23]=A,e[24]=M):M=e[24];let B;e[25]!==p||e[26]!==u?(B=p&&s.jsx(vo,{asChild:!0,children:s.jsx(Be,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:u?s.jsxs(s.Fragment,{children:[s.jsx(R2,{className:"size-3 mr-1"}),"Show less"]}):s.jsxs(s.Fragment,{children:[s.jsx(Ds,{className:"size-3 mr-1"}),"Show more"]})})}),e[25]=p,e[26]=u,e[27]=B):B=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(eo,{}),e[28]=E):E=e[28];let I;e[29]!==j||e[30]!==M||e[31]!==B?(I=s.jsxs(Jr,{open:j,onOpenChange:m,children:[M,B,E]}),e[29]=j,e[30]=M,e[31]=B,e[32]=I):I=e[32];let P;e[33]!==k||e[34]!==I?(P=s.jsxs("div",{className:"flex-1 min-w-0",children:[k,I]}),e[33]=k,e[34]=I,e[35]=P):P=e[35];let D;e[36]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(Gs,{asChild:!0,children:s.jsx(Be,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(_x,{className:"size-4"})})}),e[36]=D):D=e[36];let L;e[37]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(wo,{className:"size-4 mr-2"}),e[37]=L):L=e[37];let T;e[38]!==r?(T=s.jsxs(Jt,{onClick:r,children:[L,"Edit comment"]}),e[38]=r,e[39]=T):T=e[39];let _;e[40]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Pn,{className:"size-4 mr-2"}),e[40]=_):_=e[40];let z;e[41]!==o?(z=s.jsxs(Jt,{onClick:o,className:"text-destructive",children:[_,"Delete comment"]}),e[41]=o,e[42]=z):z=e[42];let R;e[43]!==T||e[44]!==z?(R=s.jsxs(qs,{children:[D,s.jsxs(Ys,{align:"end",children:[T,z]})]}),e[43]=T,e[44]=z,e[45]=R):R=e[45];let W;e[46]!==P||e[47]!==R?(W=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[P,R]}),e[46]=P,e[47]=R,e[48]=W):W=e[48];let G;return e[49]!==g||e[50]!==W||e[51]!==y?(G=s.jsx("div",{className:g,style:y,"data-comment-card":"true",children:W}),e[49]=g,e[50]=W,e[51]=y,e[52]=G):G=e[52],G}function N2(t){const e=Fe.c(55),{initialText:n,onSave:r,onCancel:o,fileLabel:a,lineRange:l,isEditing:i,className:c,maxWidth:u}=t,m=n===void 0?"":n,f=i===void 0?!1:i,p=Sa()?.currentTheme,{isMobile:g}=wn(),[x,b]=d.useState(m),v=he.useRef(null),y=he.useRef(l);let w,C;e[0]!==l?(w=()=>{l&&(y.current=l)},C=[l],e[0]=l,e[1]=w,e[2]=C):(w=e[1],C=e[2]),he.useEffect(w,C);const N=$R;let S;e[3]!==l?(S=N(l),e[3]=l,e[4]=S):S=e[4];const k=S;let j,F;e[5]!==g?(j=()=>{const ge=v.current;if(!ge)return;const xe=ge.closest(".overlay-scrollbar-container"),ne=xe?.scrollTop??window.scrollY,O=xe?.scrollLeft??window.scrollX;if(g){ge.scrollIntoView({behavior:"auto",block:"nearest"});try{ge.focus({preventScroll:!0})}catch{ge.focus()}return}try{ge.focus({preventScroll:!0})}catch{ge.focus()}const H=ge.value.length;try{ge.setSelectionRange(H,H)}catch{}requestAnimationFrame(()=>{xe?(xe.scrollTop=ne,xe.scrollLeft=O):window.scrollTo({top:ne,left:O})})},F=[g],e[5]=g,e[6]=j,e[7]=F):(j=e[6],F=e[7]),he.useEffect(j,F);let A;e[8]!==o||e[9]!==r||e[10]!==x?(A=ge=>{(ge.metaKey||ge.ctrlKey)&&ge.key==="Enter"?(ge.preventDefault(),x.trim()&&r(x,N(y.current))):ge.key==="Escape"&&(ge.preventDefault(),o())},e[8]=o,e[9]=r,e[10]=x,e[11]=A):A=e[11];const M=A;let B;e[12]!==r||e[13]!==x?(B=ge=>{ge.stopPropagation(),x.trim()&&r(x,N(y.current))},e[12]=r,e[13]=x,e[14]=B):B=e[14];const E=B;let I;e[15]!==c?(I=Q("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",c),e[15]=c,e[16]=I):I=e[16];const P=p?.colors?.surface?.elevated,D=p?.colors?.interactive?.border,L=u?`${Math.max(200,Math.floor(u))}px`:void 0;let T;e[17]!==P||e[18]!==D||e[19]!==L?(T={backgroundColor:P,borderColor:D,maxWidth:L},e[17]=P,e[18]=D,e[19]=L,e[20]=T):T=e[20];let _;e[21]!==k||e[22]!==a||e[23]!==l?(_=(a||l)&&s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[a&&s.jsx("span",{className:"truncate max-w-[200px]",children:a}),a&&l&&s.jsx("span",{children:"•"}),k&&s.jsxs("span",{children:["Lines ",k.start,"-",k.end]})]}),e[21]=k,e[22]=a,e[23]=l,e[24]=_):_=e[24];let z;e[25]===Symbol.for("react.memo_cache_sentinel")?(z=ge=>b(ge.target.value),e[25]=z):z=e[25];const R=p?.colors?.surface?.subtle;let W;e[26]!==R?(W={backgroundColor:R},e[26]=R,e[27]=W):W=e[27];let G;e[28]!==M||e[29]!==W||e[30]!==x?(G=s.jsx(hr,{ref:v,value:x,onChange:z,onKeyDown:M,placeholder:"Add a comment... (Cmd+Enter to save)",className:"min-h-[80px] text-sm resize-y",style:W}),e[28]=M,e[29]=W,e[30]=x,e[31]=G):G=e[31];let Y;e[32]!==o?(Y=s.jsx(Be,{variant:"ghost",size:"sm",onClick:o,onPointerDown:zR,onTouchStart:RR,className:"h-8 text-muted-foreground hover:text-foreground",children:"Cancel"}),e[32]=o,e[33]=Y):Y=e[33];let J;e[34]!==x?(J=x.trim(),e[34]=x,e[35]=J):J=e[35];const V=!J,te=p?.colors?.status?.success,U=p?.colors?.status?.successForeground;let X;e[36]!==te||e[37]!==U?(X={backgroundColor:te,color:U},e[36]=te,e[37]=U,e[38]=X):X=e[38];const $=f?"Save":"Comment";let q;e[39]!==E||e[40]!==V||e[41]!==X||e[42]!==$?(q=s.jsx(Be,{size:"sm",onClick:E,onPointerDown:PR,onTouchStart:TR,disabled:V,className:"h-8 min-w-[80px]",style:X,children:$}),e[39]=E,e[40]=V,e[41]=X,e[42]=$,e[43]=q):q=e[43];let ee;e[44]!==Y||e[45]!==q?(ee=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[Y,q]}),e[44]=Y,e[45]=q,e[46]=ee):ee=e[46];let ce;e[47]!==_||e[48]!==G||e[49]!==ee?(ce=s.jsxs("div",{className:"p-3",children:[_,G,ee]}),e[47]=_,e[48]=G,e[49]=ee,e[50]=ce):ce=e[50];let ve;return e[51]!==I||e[52]!==T||e[53]!==ce?(ve=s.jsx("div",{className:I,style:T,"data-comment-input":"true",onPointerDown:HR,onTouchStart:LR,children:ce}),e[51]=I,e[52]=T,e[53]=ce,e[54]=ve):ve=e[54],ve}function TR(t){return t.stopPropagation()}function PR(t){return t.stopPropagation()}function RR(t){return t.stopPropagation()}function zR(t){return t.stopPropagation()}function LR(t){return t.stopPropagation()}function HR(t){return t.stopPropagation()}function $R(t){if(!t)return;const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}}const OR=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},S2=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function d3(t){const e=Fe.c(39),{source:n,fileLabel:r,language:o,getCodeForRange:a,toStoreRange:l,fromDraftRange:i}=t,c=Ze(ZR),u=Ze(GR),m=mi(qR),f=mi(WR),h=mi(UR),p=mi(VR),[g,x]=d.useState(null),[b,v]=d.useState(""),[y,w]=d.useState(null),C=c??(u?"draft":null);let N;e:{if(!C||!r){let R;e[0]===Symbol.for("react.memo_cache_sentinel")?(R=[],e[0]=R):R=e[0],N=R;break e}let T;e[1]!==p||e[2]!==C?(T=p[C]??[],e[1]=p,e[2]=C,e[3]=T):T=e[3];const _=T;let z;if(e[4]!==r||e[5]!==_||e[6]!==n){let R;e[8]!==r||e[9]!==n?(R=W=>W.source===n&&W.fileLabel===r,e[8]=r,e[9]=n,e[10]=R):R=e[10],z=_.filter(R),e[4]=r,e[5]=_,e[6]=n,e[7]=z}else z=e[7];N=z}const S=N;let k;e[11]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{x(null),v(""),w(null)},e[11]=k):k=e[11];const j=k;let F;e[12]===Symbol.for("react.memo_cache_sentinel")?(F=()=>{j()},e[12]=F):F=e[12];const A=F;let M;e[13]!==i?(M=T=>{const _=S2(i(T));x(_),v(T.text),w(T.id)},e[13]=i,e[14]=M):M=e[14];const B=M;let E;e[15]!==y||e[16]!==h?(E=T=>{h(T.sessionKey,T.id),y===T.id&&j()},e[15]=y,e[16]=h,e[17]=E):E=e[17];const I=E;let P;e[18]!==m||e[19]!==y||e[20]!==r||e[21]!==a||e[22]!==o||e[23]!==g||e[24]!==C||e[25]!==n||e[26]!==l||e[27]!==f?(P=(T,_)=>{const z=_??g,R=T.trim();if(!z||!R||!r)return;if(!C){fe.error("Select a session to save comment");return}const W=S2(z),G=OR(l(W)),Y=a(W);y?f(C,y,{fileLabel:r,startLine:G.startLine,endLine:G.endLine,side:G.side,code:Y,language:o,text:R}):m({sessionKey:C,source:n,fileLabel:r,startLine:G.startLine,endLine:G.endLine,side:G.side,code:Y,language:o,text:R}),j()},e[18]=m,e[19]=y,e[20]=r,e[21]=a,e[22]=o,e[23]=g,e[24]=C,e[25]=n,e[26]=l,e[27]=f,e[28]=P):P=e[28];const D=P;let L;return e[29]!==b||e[30]!==I||e[31]!==S||e[32]!==y||e[33]!==i||e[34]!==D||e[35]!==g||e[36]!==C||e[37]!==B?(L={sessionKey:C,drafts:S,selection:g,setSelection:x,commentText:b,setCommentText:v,editingDraftId:y,setEditingDraftId:w,reset:j,cancel:A,startEdit:B,deleteDraft:I,saveComment:D,fromDraftRange:i},e[29]=b,e[30]=I,e[31]=S,e[32]=y,e[33]=i,e[34]=D,e[35]=g,e[36]=C,e[37]=B,e[38]=L):L=e[38],L}function VR(t){return t.drafts}function UR(t){return t.removeDraft}function WR(t){return t.updateDraft}function qR(t){return t.addDraft}function GR(t){return t.newSessionDraft?.open}function ZR(t){return t.currentSessionId}function Qp(t){const{drafts:e,editingDraftId:n,commentText:r,selection:o,isDragging:a,fileLabel:l,newWidgetId:i,mapDraftToRange:c,onSave:u,onCancel:m,onEdit:f,onDelete:h}=t,p=[];for(const g of e){const x=c(g);if(g.id===n){p.push({afterLine:x.end,id:`edit-${g.id}`,content:s.jsx(N2,{initialText:r,fileLabel:l,lineRange:x,isEditing:!0,onSave:u,onCancel:m},`edit-${g.id}`)});continue}p.push({afterLine:x.end,id:`card-${g.id}`,content:s.jsx(Xp,{draft:g,onEdit:()=>f(g),onDelete:()=>h(g)},`card-${g.id}`)})}if(o&&!n&&!a){const g={...o,start:Math.min(o.start,o.end),end:Math.max(o.start,o.end)};p.push({afterLine:g.end,id:i,content:s.jsx(N2,{initialText:r,fileLabel:l,lineRange:g,isEditing:!1,onSave:u,onCancel:m},i)})}return p}const q0=t=>{if(t.type==="new"){const e=Math.min(t.selection.start,t.selection.end),n=Math.max(t.selection.start,t.selection.end);return`new-comment-${t.selection.side??"additions"}-${e}-${n}`}return`draft-${t.draft.id}`},KR=t=>{const{drafts:e,editingDraftId:n,selection:r}=t,o=[];for(const a of e){if(!Number.isFinite(a.endLine))continue;const l=Math.max(1,Math.floor(a.endLine)),i=a.side==="original"?"deletions":"additions";o.push({lineNumber:l,side:i,metadata:{type:a.id===n?"edit":"saved",draft:a}})}return r&&!n&&o.push({lineNumber:Math.max(r.start,r.end),side:r.side??"additions",metadata:{type:"new",selection:r}}),o};function YR(t){const e=t.trim();if(!e)return null;if(/^-?\d+(\.\d+)?$/.test(e)){const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}if(e.endsWith("px")){const n=Number.parseFloat(e.slice(0,-2));return Number.isFinite(n)?n:null}return null}function Wm(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function XR(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:o,commentText:a,fileLabel:l,onSave:i,onCancel:c,onEdit:u,onDelete:m}=t,[f,h]=d.useState(0),[p,g]=d.useState(null),x=d.useMemo(()=>!r||o?null:q0({type:"new",selection:r}),[o,r]),b=d.useMemo(()=>{const w=n.map(C=>q0({type:C.id===o?"edit":"saved",draft:C}));return x&&w.push(x),w},[n,o,x]),v=d.useCallback(w=>{const C=e.current;if(!C)return null;const N=C.querySelector("diffs-container");if(!(N instanceof HTMLElement))return null;const S=N.querySelector(`[data-annotation-id="${w}"]`);if(S instanceof HTMLElement)return S;const k=N.shadowRoot;return k?k.querySelector(`[data-annotation-id="${w}"]`):null},[e]);d.useEffect(()=>{if(b.length===0)return;let w=!1,C=0;const N=12,S=()=>{w||b.every(j=>!!v(j))||C>=N||(C+=1,requestAnimationFrame(()=>{w||(h(j=>j+1),S())}))};return S(),()=>{w=!0}},[b,v]),d.useEffect(()=>{const w=e.current;if(!w)return;const C=()=>{const S=getComputedStyle(w),k=YR(S.getPropertyValue("--oc-context-panel-width")),j=w.getBoundingClientRect(),F=k??j.width;g(F>0?F:null)};C();const N=new ResizeObserver(()=>{C()});return N.observe(w),window.addEventListener("resize",C),()=>{N.disconnect(),window.removeEventListener("resize",C)}},[e]);const y=d.useCallback(w=>{const N=e.current?.getBoundingClientRect(),S=w.closest("[data-annotation-content]"),k=S instanceof HTMLElement?S.getBoundingClientRect():w.getBoundingClientRect(),j=[k.width];N&&j.push(N.right-k.left);const F=j.filter(A=>Number.isFinite(A)&&A>0);return F.length>0?Wm(Math.min(...F)):Wm(p)},[e,p]);return s.jsxs(s.Fragment,{children:[n.map(w=>{const C=q0({type:w.id===o?"edit":"saved",draft:w}),N=v(C);if(!N)return null;const S=y(N);return w.id===o?To.createPortal(s.jsx(N2,{initialText:a,fileLabel:l,lineRange:{start:w.startLine,end:w.endLine,side:w.side==="original"?"deletions":"additions"},isEditing:!0,onSave:i,onCancel:c,maxWidth:S}),N,`draft-edit-${w.id}`):To.createPortal(s.jsx(Xp,{draft:w,onEdit:()=>u(w),onDelete:()=>m(w),maxWidth:S}),N,`draft-card-${w.id}`)}),r&&!o&&x&&(()=>{const w=v(x);if(!w)return null;const C=y(w);return To.createPortal(s.jsx(N2,{initialText:a,fileLabel:l,lineRange:r,isEditing:!1,onSave:i,onCancel:c,maxWidth:C}),w,x)})()]})}function nu(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},o=t.colors.syntax.tokens||{},a=go.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:o.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:o.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:o.boolean||t.colors.syntax.base.number},".cm-builtin":{color:o.functionCall||t.colors.syntax.base.function},".cm-def":{color:o.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:o.variableOther||o.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:o.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:o.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:o.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:o.tag||t.colors.syntax.base.keyword},".cm-link":{color:o.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:e}),l=Nd.define([{tag:[dt.comment,dt.docComment,dt.meta,dt.documentMeta],class:"cm-comment"},{tag:[dt.keyword,dt.controlKeyword,dt.moduleKeyword,dt.definitionKeyword,dt.modifier],class:"cm-keyword"},{tag:[dt.operatorKeyword,dt.operator,dt.derefOperator,dt.updateOperator,dt.definitionOperator,dt.typeOperator,dt.controlOperator,dt.logicOperator,dt.bitwiseOperator,dt.arithmeticOperator,dt.compareOperator],class:"cm-operator"},{tag:[dt.punctuation,dt.separator,dt.bracket,dt.paren,dt.brace,dt.squareBracket,dt.angleBracket],class:"cm-punctuation"},{tag:[dt.string,dt.regexp,dt.attributeValue,dt.special(dt.string),dt.monospace],class:"cm-string"},{tag:dt.escape,class:"cm-string-2"},{tag:[dt.number,dt.bool,dt.atom,dt.null,dt.self],class:"cm-number"},{tag:[dt.function(dt.variableName),dt.function(dt.definition(dt.variableName)),dt.function(dt.propertyName),dt.standard(dt.variableName),dt.special(dt.variableName)],class:"cm-builtin"},{tag:dt.definition(dt.variableName),class:"cm-def"},{tag:[dt.variableName,dt.local(dt.variableName),dt.constant(dt.variableName),dt.literal],class:"cm-variable"},{tag:dt.propertyName,class:"cm-property"},{tag:dt.attributeName,class:"cm-attribute"},{tag:[dt.className,dt.typeName,dt.namespace],class:"cm-variable-3"},{tag:[dt.tagName,dt.labelName,dt.annotation,dt.macroName],class:"cm-tag"},{tag:dt.link,class:"cm-link"},{tag:[dt.heading,dt.heading1,dt.heading2,dt.heading3,dt.heading4,dt.heading5,dt.heading6],class:"cm-keyword"}]),i=Nd.define([{tag:[dt.comment,dt.docComment,dt.meta,dt.documentMeta],color:t.colors.syntax.base.comment},{tag:[dt.keyword,dt.controlKeyword,dt.moduleKeyword,dt.definitionKeyword,dt.modifier],color:t.colors.syntax.base.keyword},{tag:[dt.operatorKeyword,dt.operator,dt.derefOperator,dt.updateOperator,dt.definitionOperator,dt.typeOperator,dt.controlOperator,dt.logicOperator,dt.bitwiseOperator,dt.arithmeticOperator,dt.compareOperator],color:t.colors.syntax.base.operator},{tag:[dt.string,dt.regexp,dt.attributeValue,dt.special(dt.string),dt.monospace],color:t.colors.syntax.base.string},{tag:dt.escape,color:o.stringEscape||t.colors.syntax.base.string},{tag:[dt.number,dt.bool,dt.atom,dt.null,dt.self],color:t.colors.syntax.base.number},{tag:[dt.function(dt.variableName),dt.function(dt.definition(dt.variableName)),dt.function(dt.propertyName),dt.standard(dt.variableName),dt.special(dt.variableName)],color:t.colors.syntax.base.function},{tag:dt.definition(dt.variableName),color:o.variableGlobal||t.colors.syntax.base.variable},{tag:[dt.variableName,dt.local(dt.variableName),dt.constant(dt.variableName),dt.literal],color:t.colors.syntax.base.variable},{tag:dt.propertyName,color:o.variableProperty||t.colors.syntax.base.variable},{tag:dt.attributeName,color:o.variableOther||t.colors.syntax.base.variable},{tag:[dt.className,dt.typeName,dt.namespace],color:t.colors.syntax.base.type},{tag:[dt.tagName,dt.labelName,dt.annotation,dt.macroName],color:o.tag||t.colors.syntax.base.keyword},{tag:dt.link,color:o.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[dt.punctuation,dt.separator,dt.bracket,dt.paren,dt.brace,dt.squareBracket,dt.angleBracket],color:o.punctuation||t.colors.syntax.base.comment}]);return[a,n1(Ex,{fallback:!0}),n1(Dx),n1(l),n1(i)]}const ru=zl.define(Ix),Jp=zl.define(Tx),QR=zl.define(Px),JR=zl.define(Rx),ez=zl.define(zx),tz=zl.define(Lx),e7=Hx(),sz=e7.language,t7=zl.define($x);function nz(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return ru;case"toml":return Jp;case"diff":case"patch":return QR;case"json":case"jsonc":case"json5":return i6().language;case"js":case"javascript":return ai().language;case"jsx":return ai({jsx:!0}).language;case"ts":case"typescript":return ai({typescript:!0}).language;case"tsx":return ai({typescript:!0,jsx:!0}).language;case"yaml":case"yml":return a6().language;case"html":return n2().language;case"css":return l6().language;case"xml":case"svg":return n6().language;case"py":case"python":return o6().language;case"sql":return r6().language;case"rs":case"rust":return s6().language;case"c":case"cpp":case"h":case"hpp":return t6().language;case"go":return e6().language;case"ex":case"exs":case"elixir":return sz;case"erl":case"hrl":case"erlang":return t7;case"heex":case"eex":case"leex":return n2().language;default:return c6.matchLanguageName(d6,e,!0)}}const s7=t=>t.split("/").pop()?.toLowerCase()??"",rz=t=>{const e=s7(t);return e?c6.matchFilename(d6,e):null},oz=()=>n1(Nd.define([{tag:[dt.heading1,dt.heading2,dt.heading3,dt.heading4,dt.heading5,dt.heading6],fontWeight:"600"},{tag:dt.strong,fontWeight:"600"},{tag:dt.emphasis,fontStyle:"italic"},{tag:dt.strikethrough,textDecoration:"line-through"},{tag:[dt.link,dt.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:dt.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:dt.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:dt.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:dt.heading,color:"var(--markdown-heading1, currentColor)"}]));function n7(t){const e=t.toLowerCase();switch(s7(e)){case"dockerfile":return JR;case"makefile":case"gnumakefile":return ru}const r=e.lastIndexOf("."),o=r>=0?e.slice(r+1):"";switch(o){case"ts":case"tsx":case"mts":case"cts":return ai({typescript:!0,jsx:o==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return ai({typescript:!1,jsx:o==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return i6();case"css":case"scss":case"sass":case"less":return l6();case"html":case"htm":return n2();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[Ox({codeLanguages:nz}),oz()];case"yml":case"yaml":return a6();case"toml":return Jp;case"ini":case"cfg":case"conf":case"config":case"properties":return tz;case"sh":case"bash":case"zsh":case"fish":case"env":return ru;case"py":case"pyw":case"pyi":return o6();case"sql":case"psql":case"plsql":return r6();case"xml":case"xsl":case"xslt":case"xsd":case"dtd":case"plist":case"svg":return n6();case"rs":return s6();case"c":case"cpp":case"h":case"hpp":return t6();case"go":return e6();case"rb":case"erb":case"rake":case"gemspec":return ez;case"ex":case"exs":return e7;case"erl":case"hrl":return t7;case"eex":case"leex":case"heex":return n2();default:return null}}async function az(t){const e=rz(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}const j1=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Xc=(t,e)=>{const n=j1(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},lz=(t,e,n)=>Xc(Xc(Xc(t,".opencode"),"plans"),`${e}-${n}.md`),iz=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,cz=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},dz=(t,e)=>{const n=j1(e.currentDirectory),r=j1(e.homeDirectory),o=j1(t);return n&&o.startsWith(n+"/")?o.slice(n.length+1):r&&o===r?"~":r&&o.startsWith(r+"/")?`~${o.slice(r.length)}`:o},r7=()=>{const t=Ze(ce=>ce.currentSessionId),e=Ze(ce=>ce.sessions),n=dn(ce=>ce.homeDirectory),r=ur();Ee();const{isMobile:o}=wn(),{currentTheme:a}=qn();d.useMemo(()=>sc(a),[a]);const l=d.useMemo(()=>t?e.find(ce=>ce.id===t)??null:null,[t,e]),i=d.useMemo(()=>{const ce=typeof l?.directory=="string"?l.directory:"";return j1(ce||"")},[l?.directory]),[c,u]=d.useState(null),m=d.useMemo(()=>!c||!i||!n?c:dz(c,{currentDirectory:i,homeDirectory:n}),[c,i,n]),[f,h]=d.useState(""),p=d.useMemo(()=>m&&m.split("/").pop()||"plan",[m]),[g,x]=d.useState(!1),[b,v]=d.useState(!1),[y,w]=d.useState(!1),[C,N]=d.useState("edit"),S=d.useRef(null),k=d.useRef(null),[j,F]=d.useState(null),A=d.useRef(null),M=d.useRef(null),B="archcoder:plan:md-viewer-mode";d.useEffect(()=>{try{const ce=localStorage.getItem(B);if(!ce)return;const ve=JSON.parse(ce);(ve==="preview"||ve==="edit")&&N(ve)}catch{}},[]);const E=d.useCallback(ce=>{N(ce);try{localStorage.setItem(B,JSON.stringify(ce))}catch{}},[]),I=d.useRef(!1),P=d.useRef(null),[D,L]=d.useState(!1);d.useEffect(()=>{const ce=()=>{I.current=!1,P.current=null,L(!1)};return document.addEventListener("mouseup",ce),()=>document.removeEventListener("mouseup",ce)},[]);const T=d.useCallback((ce,ve)=>{const ge=ce.split(`
7812
7812
  `),xe=Math.max(1,ve.start),ne=Math.min(ge.length,ve.end);return xe>ne?"":ge.slice(xe-1,ne).join(`
7813
7813
  `)},[]),_=d3({source:"plan",fileLabel:p,language:c&&aa(c)||"markdown",getCodeForRange:ce=>T(f,S2(ce)),toStoreRange:ce=>({startLine:ce.start,endLine:ce.end}),fromDraftRange:ce=>({start:ce.startLine,end:ce.endLine})}),{drafts:z,commentText:R,editingDraftId:W,setSelection:G,saveComment:Y,cancel:J,reset:V,startEdit:te,deleteDraft:U}=_;d.useEffect(()=>{F(null),V()},[f,V]),d.useEffect(()=>{G(j)},[j,G]);const X=d.useCallback(()=>{F(null),J()},[J]),$=d.useCallback((ce,ve)=>{ve&&F(ve),Y(ce,ve??j??void 0),F(null)},[j,Y]);d.useEffect(()=>{if(!j)return;const ce=ge=>{const xe=ge.target;xe.closest('[data-comment-card="true"]')||xe.closest('[data-comment-input="true"]')||xe.closest(".oc-block-widget")||xe.closest(".cm-gutterElement")||xe.closest("[data-sonner-toast]")||xe.closest("[data-sonner-toaster]")||(F(null),J())},ve=window.setTimeout(()=>{document.addEventListener("click",ce)},100);return()=>{window.clearTimeout(ve),document.removeEventListener("click",ce)}},[J,W,o,j]);const q=d.useMemo(()=>{const ce=[nu(a)],ve=n7(c||"plan.md");return ve&&ce.push(ve),ce.push(go.lineWrapping),ce},[a,c]);d.useEffect(()=>{let ce=!1;const ve=async ne=>{if(r.files?.readFile)return(await r.files.readFile(ne))?.content??"";const O=await fetch(`/api/fs/read?path=${encodeURIComponent(ne)}`);if(!O.ok)throw new Error(`Failed to read plan file (${O.status})`);return O.text()},ge=async ne=>{if(ne&&(u(null),h("")),!l?.slug||!l?.time?.created||!i){u(null),h("");return}ne&&x(!0);try{const O=lz(i,l.time.created,l.slug),H=cz(iz(l.time.created,l.slug),n||null);let K=null,re=null;try{re=await ve(O),K=O}catch{}if(!K)try{re=await ve(H),K=H}catch{}if(ce)return;if(!K||re===null){u(null),h("");return}u(K),h(re)}catch{if(ce)return;u(null),h("")}finally{!ce&&ne&&x(!1)}};ge(!0);const xe=window.setInterval(()=>{ge(!1)},3e3);return()=>{ce=!0,window.clearInterval(xe)}},[i,l?.slug,l?.time?.created,n,r.files]),d.useEffect(()=>()=>{S.current!==null&&window.clearTimeout(S.current),k.current!==null&&window.clearTimeout(k.current)},[]);const ee=d.useMemo(()=>Qp({drafts:z,editingDraftId:W,commentText:R,selection:j,isDragging:D,fileLabel:p,newWidgetId:"plan-new-comment-input",mapDraftToRange:ce=>({start:ce.startLine,end:ce.endLine}),onSave:$,onCancel:X,onEdit:ce=>{te(ce),F({start:ce.startLine,end:ce.endLine})},onDelete:U}),[R,U,W,X,$,D,j,z,p,te]);return s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label font-medium truncate",children:"Plan"}),c?s.jsx("div",{className:"typography-meta text-muted-foreground truncate",title:m??c,children:m??c}):null]}),c?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(Yp,{currentMode:C,onToggle:()=>E(C==="preview"?"edit":"preview")}),s.jsx(Be,{variant:"ghost",size:"sm",onClick:async()=>{(await Dn(f)).ok&&(w(!0),k.current!==null&&window.clearTimeout(k.current),k.current=window.setTimeout(()=>{w(!1)},1200))},className:"h-5 w-5 p-0",title:"Copy plan contents","aria-label":"Copy plan contents",children:y?s.jsx(js,{className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(W1,{className:"h-4 w-4"})}),s.jsx(Be,{variant:"ghost",size:"sm",onClick:async()=>{(await Dn(m??c)).ok&&(v(!0),S.current!==null&&window.clearTimeout(S.current),S.current=window.setTimeout(()=>{v(!1)},1200))},className:"h-5 w-5 p-0",title:`Copy plan path (${m??c})`,"aria-label":`Copy plan path (${m??c})`,children:b?s.jsx(js,{className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(u6,{className:"h-4 w-4"})})]}):null]}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(ks,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:g?s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:"Loading…"}):s.jsx("div",{className:"relative h-full",children:s.jsx("div",{className:"h-full oc-plan-editor",children:C==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(An,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:"Preview unavailable"}),s.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to edit mode to fix the issue."})]}),children:s.jsx(yo,{content:f,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:M,children:s.jsx(su,{value:f,onChange:()=>{},readOnly:!0,className:"h-full",extensions:q,onViewReady:ce=>{A.current=ce},onViewDestroy:()=>{A.current=null},blockWidgets:ee,highlightLines:j?{start:Math.min(j.start,j.end),end:Math.max(j.start,j.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(ce,ve,ge)=>{if(!(ge instanceof MouseEvent)||ge.button!==0)return!1;ge.preventDefault();const xe=ce.state.doc.lineAt(ve.from).number;if(o&&j&&!ge.shiftKey){const ne=Math.min(j.start,j.end,xe),O=Math.max(j.start,j.end,xe);return F({start:ne,end:O}),I.current=!1,P.current=null,L(!1),!0}if(I.current=!0,P.current=xe,L(!0),j&&ge.shiftKey){const ne=Math.min(j.start,xe),O=Math.max(j.end,xe);F({start:ne,end:O})}else F({start:xe,end:xe});return!0},mouseover:(ce,ve,ge)=>{if(!(ge instanceof MouseEvent)||ge.buttons!==1||!I.current||P.current===null)return!1;const xe=ce.state.doc.lineAt(ve.from).number,ne=Math.min(P.current,xe),O=Math.max(P.current,xe);return F({start:ne,end:O}),L(!0),!1},mouseup:()=>(I.current=!1,P.current=null,L(!1),!1)}}})})})})})})]})},uz=Object.freeze(Object.defineProperty({__proto__:null,PlanView:r7},Symbol.toStringTag,{value:"Module"})),o7=12,fz=[{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"}],mz=t=>{const e=Fe.c(18),{isActive:n,burstKey:r,className:o,durationMs:a,bursts:l,onComplete:i}=t,c=r===void 0?0:r,u=a===void 0?900:a,m=l===void 0?fz:l,f=he.useRef(!1);let h,p;e[0]!==n||e[1]!==i?(h=()=>{!n&&f.current&&i?.(),n&&(f.current=!0)},p=[n,i],e[0]=n,e[1]=i,e[2]=h,e[3]=p):(h=e[2],p=e[3]),he.useEffect(h,p);let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=Array.from({length:o7},hz),e[4]=g):g=e[4];const x=g;if(!n)return null;let b;e[5]!==o?(b=Q("fireworks-overlay pointer-events-none",o),e[5]=o,e[6]=b):b=e[6];let v;if(e[7]!==c||e[8]!==m||e[9]!==u){let w;e[11]!==c||e[12]!==u?(w=C=>{const N={"--burst-delay":`${C.delay}ms`,"--burst-x":`${C.x}%`,"--burst-y":`${C.y}%`,"--firework-color":`var(${C.colorVar})`,"--firework-duration":`${u}ms`};return s.jsx("div",{className:"firework-burst",style:N,children:x.map((S,k)=>{const j=S.x*C.radius,F=S.y*C.radius,A={"--translate-x":`${j}px`,"--translate-y":`${F}px`,"--particle-delay":`${S.delay}ms`,color:`var(${C.colorVar})`};return s.jsx("span",{className:"firework-particle",style:A},`${C.id}-${k}-${c}`)})},`${C.id}-${c}`)},e[11]=c,e[12]=u,e[13]=w):w=e[13],v=m.map(w),e[7]=c,e[8]=m,e[9]=u,e[10]=v}else v=e[10];let y;return e[14]!==c||e[15]!==b||e[16]!==v?(y=s.jsx("div",{className:b,"aria-hidden":"true","data-burst-key":c,children:v}),e[14]=c,e[15]=b,e[16]=v,e[17]=y):y=e[17],y};function hz(t,e){const n=Math.PI*2*e/o7;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const pz=t=>{const e=Fe.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 a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={isActive:!1,cycle:0},e[2]=a):a=e[2];const[l,i]=he.useState(a),c=he.useRef(null);let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{c.current&&(window.clearTimeout(c.current),c.current=null)},e[3]=u):u=e[3];const m=u;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{m(),i(gz)},e[4]=f):f=e[4];const h=f;let p;e[5]!==o?(p=()=>{m(),i(xz),c.current=window.setTimeout(()=>{i(bz),c.current=null},o)},e[5]=o,e[6]=p):p=e[6];const g=p;let x,b;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=()=>()=>m(),b=[m],e[7]=x,e[8]=b):(x=e[7],b=e[8]),he.useEffect(x,b);let v;return e[9]!==l.cycle||e[10]!==l.isActive||e[11]!==g?(v={isActive:l.isActive,burstKey:l.cycle,triggerFireworks:g,dismissFireworks:h},e[9]=l.cycle,e[10]=l.isActive,e[11]=g,e[12]=v):v=e[12],v};function gz(t){return t.isActive?{...t,isActive:!1}:t}function xz(t){return{isActive:!0,cycle:t.cycle+1}}function bz(t){return t.isActive?{...t,isActive:!1}:t}const a7=d.createContext(void 0),qm=t=>{const e=Fe.c(10),{children:n}=t,{isActive:r,burstKey:o,triggerFireworks:a,dismissFireworks:l}=pz();let i;e[0]!==l||e[1]!==a?(i={triggerFireworks:a,dismissFireworks:l},e[0]=l,e[1]=a,e[2]=i):i=e[2];const c=i;let u;e[3]!==o||e[4]!==r?(u=s.jsx(mz,{isActive:r,burstKey:o}),e[3]=o,e[4]=r,e[5]=u):u=e[5];let m;return e[6]!==n||e[7]!==u||e[8]!==c?(m=s.jsxs(a7.Provider,{value:c,children:[n,u]}),e[6]=n,e[7]=u,e[8]=c,e[9]=m):m=e[9],m},vz=()=>{const t=d.useContext(a7);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Bi=Dr()(wa(Pl((t,e)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{t({selectedProfileId:n})},loadProfiles:async()=>{t({isLoading:!0});const n=e().profiles;try{const r=await uv();return t({profiles:r,isLoading:!1}),!0}catch(r){return console.error("Failed to load git identity profiles:",r),t({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{const n=await dv();if(n&&n.userName&&n.userEmail){const r={id:"global",name:"Global Identity",userName:n.userName,userEmail:n.userEmail,authType:n.sshCommand?"ssh":void 0,sshKey:n.sshCommand?n.sshCommand.replace("ssh -i ",""):null,color:"info",icon:"house"};t({globalIdentity:r})}else t({globalIdentity:null});return!0}catch(n){return console.error("Failed to load global git identity:",n),t({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{const n=await cv();return t({discoveredCredentials:n}),!0}catch(n){return console.error("Failed to discover git credentials:",n),t({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=r=>{if(typeof r!="string")return null;const o=r.trim();return o.length>0?o:null};try{let r=null;if(r===null){const o=Ho()?.settings;if(o)try{const l=(await o.load())?.settings||{};r=n(l.defaultGitIdentityId)}catch{}}if(r===null)try{const o=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(o.ok){const a=await o.json().catch(()=>null);r=n(a?.defaultGitIdentityId)}}catch{}return t({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",o=r.length>0?r:"";return await ln({defaultGitIdentityId:o}),t({defaultGitIdentityId:o.length>0?o:null}),!0}catch(r){return console.error("Failed to save default git identity setting:",r),!1}},createProfile:async n=>{try{const r={...n,id:n.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:n.color||"keyword",icon:n.icon||"branch"};return await iv(r),await e().loadProfiles(),!0}catch(r){return console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const o=e().profiles.find(l=>l.id===n);if(!o)throw new Error("Profile not found");const a={...o,...r};return await lv(n,a),await e().loadProfiles(),!0}catch(o){return console.error("Failed to update git identity profile:",o),!1}},deleteProfile:async n=>{try{return await av(n),e().selectedProfileId===n&&t({selectedProfileId:null}),await e().loadProfiles(),!0}catch(r){return console.error("Failed to delete git identity profile:",r),!1}},getProfileById:n=>{const{profiles:r,globalIdentity:o}=e();return n==="global"?o||void 0:r.find(a=>a.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:r}=e();return r.filter(o=>!n.some(a=>a.authType==="token"&&a.host===o.host))}}),{name:"git-identities-store",storage:Ii(()=>Ko()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Bi);function Y1(t){const e=Fe.c(9);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]===Symbol.for("react.memo_cache_sentinel")?(o={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},e[3]=o):o=e[3];let a;e[4]!==n?(a=Q("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[4]=n,e[5]=a):a=e[5];let l;return e[6]!==r||e[7]!==a?(l=s.jsx(Ll,{"data-slot":"command",style:o,className:a,...r}),e[6]=r,e[7]=a,e[8]=l):l=e[8],l}function yz(t){const e=Fe.c(26);let n,r,o,a,l,i;e[0]!==t?({title:a,description:l,children:n,className:r,showCloseButton:i,...o}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a,e[5]=l,e[6]=i):(n=e[1],r=e[2],o=e[3],a=e[4],l=e[5],i=e[6]);const c=a===void 0?"Command Palette":a,u=l===void 0?"Search for a command to run...":l,m=i===void 0?!0:i;let f;e[7]!==c?(f=s.jsx(Us,{children:c}),e[7]=c,e[8]=f):f=e[8];let h;e[9]!==u?(h=s.jsx(sn,{children:u}),e[9]=u,e[10]=h):h=e[10];let p;e[11]!==f||e[12]!==h?(p=s.jsxs(Zs,{className:"sr-only",children:[f,h]}),e[11]=f,e[12]=h,e[13]=p):p=e[13];let g;e[14]!==r?(g=Q("overflow-hidden p-0 transform-gpu will-change-transform",r),e[14]=r,e[15]=g):g=e[15];let x;e[16]!==n?(x=s.jsx(Y1,{className:"[&_[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",children:n}),e[16]=n,e[17]=x):x=e[17];let b;e[18]!==m||e[19]!==g||e[20]!==x?(b=s.jsx(Vs,{className:g,showCloseButton:m,children:x}),e[18]=m,e[19]=g,e[20]=x,e[21]=b):b=e[21];let v;return e[22]!==o||e[23]!==p||e[24]!==b?(v=s.jsxs(Os,{...o,children:[p,b]}),e[22]=o,e[23]=p,e[24]=b,e[25]=v):v=e[25],v}const Hi=he.forwardRef((t,e)=>{const n=Fe.c(10);let r,o;n[0]!==t?({className:r,...o}=t,n[0]=t,n[1]=r,n[2]=o):(r=n[1],o=n[2]);let a;n[3]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(xr,{className:"size-4 shrink-0 opacity-50"}),n[3]=a):a=n[3];let l;n[4]!==r?(l=Q("placeholder:text-muted-foreground flex h-8 w-full rounded-lg bg-transparent py-2 typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r),n[4]=r,n[5]=l):l=n[5];let i;return n[6]!==o||n[7]!==e||n[8]!==l?(i=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[a,s.jsx(Ll.Input,{ref:e,"data-slot":"command-input",className:l,...o})]}),n[6]=o,n[7]=e,n[8]=l,n[9]=i):i=n[9],i});Hi.displayName="CommandInput";function X1(t){const e=Fe.c(14);let n,r,o,a,l;e[0]!==t?({className:r,children:n,scrollbarClassName:l,disableHorizontal:o,...a}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a,e[5]=l):(n=e[1],r=e[2],o=e[3],a=e[4],l=e[5]);let i;e[6]!==r?(i=Q("scroll-py-1 overflow-x-hidden h-full min-h-0",r),e[6]=r,e[7]=i):i=e[7];const c=l??"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",u=o??!0;let m;return e[8]!==n||e[9]!==a||e[10]!==i||e[11]!==c||e[12]!==u?(m=s.jsx(ks,{as:Ll.List,"data-slot":"command-list",outerClassName:"max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0",className:i,scrollbarClassName:c,disableHorizontal:u,...a,children:n}),e[8]=n,e[9]=a,e[10]=i,e[11]=c,e[12]=u,e[13]=m):m=e[13],m}function Q1(t){const e=Fe.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Ll.Empty,{"data-slot":"command-empty",className:"py-6 text-center typography-ui-label",...n}),e[2]=n,e[3]=r):r=e[3],r}function Io(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(Ll.Group,{"data-slot":"command-group",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function $1(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("bg-border -mx-1 h-px",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(Ll.Separator,{"data-slot":"command-separator",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function Bn(t){const e=Fe.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=Q("data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=s.jsx(Ll.Item,{"data-slot":"command-item",className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function Wr(t){const e=Fe.c(12);let n,r,o,a;if(e[0]!==t){const{className:i,...c}=t,u=jz,m=typeof c.children=="string"?c.children:"",f=m?m.split("+").map(wz).filter(Boolean):[];n="command-shortcut",e[5]!==i?(r=Q("text-muted-foreground ml-auto flex items-center gap-1 typography-meta",i),e[5]=i,e[6]=r):r=e[6],o=c,a=f.length>0?f.map((h,p)=>s.jsxs(he.Fragment,{children:[p>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),u(h)]},`${h}-${p}`)):c.children,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=a}else n=e[1],r=e[2],o=e[3],a=e[4];let l;return e[7]!==n||e[8]!==r||e[9]!==o||e[10]!==a?(l=s.jsx("span",{"data-slot":n,className:r,...o,children:a}),e[7]=n,e[8]=r,e[9]=o,e[10]=a,e[11]=l):l=e[11],l}function wz(t){return t.trim()}function jz(t){const e=t.trim().toLowerCase();return e==="ctrl"||e==="control"?s.jsx("span",{className:"text-xs font-medium",children:"ctrl"}):e==="cmd"||e==="⌘"||e==="command"||e==="meta"?s.jsx(Rl,{className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(ki,{className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const Lr=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},_i=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),O1=t=>!!t.success,Il=t=>(t.stdout||"").trim(),Ei=t=>(t.stderr||"").trim();async function kz(t){const n=((await Nn("git worktree list --porcelain",t)).stdout||"").split(/\r?\n/),r=[];let o=null;for(const a of n){if(a.startsWith("worktree ")){o&&r.push(o),o={path:a.slice(9).trim(),branchRef:null};continue}o&&a.startsWith("branch ")&&(o.branchRef=a.slice(7).trim())}return o&&r.push(o),r.filter(a=>!!a.path)}async function Nz(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),o=(await kz(t.repoRoot)).filter(l=>l.branchRef===e).map(l=>l.path).filter(l=>l&&!n.has(l)),a=[];for(const l of o){const i=await Nn("git status --porcelain",l);Il(i)||a.push(l)}return a}async function l7(t,e){for(const n of e)await Nn("git reset --hard",n).catch(()=>{})}async function Sz(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await Nn(`git show-ref --verify --quiet ${Lr(`refs/heads/${n}`)} && echo ok || echo missing`,t);if(Il(r)==="ok")return n;if(n.startsWith("remotes/")){const l=n.slice(8).split("/"),i=l[0]||"origin",c=l.slice(1).join("/");if(c)return await Nn(`git branch --track ${Lr(c)} ${Lr(`${i}/${c}`)}`,t),c}const o=await Nn(`git show-ref --verify --quiet ${Lr(`refs/remotes/origin/${n}`)} && echo ok || echo missing`,t);return Il(o)==="ok"&&await Nn(`git branch --track ${Lr(n)} ${Lr(`origin/${n}`)}`,t),n}async function Xi(t){const e=t.repoRoot,n=t.sourceBranch.trim(),r=t.targetBranch.trim();if(!n||!r)return{repoRoot:e,sourceBranch:n,targetBranch:r,commits:[]};const o=await Sz(e,r),a=await Nn(`git cherry ${Lr(o)} ${Lr(n)}`,e),l=_i(a.stdout),i=new Set;for(const f of l){const h=f.match(/^\+\s+([0-9a-f]{7,40})\b/i);h&&i.add(h[1])}const c=await Nn(`git rev-list --reverse ${Lr(`${o}..${n}`)}`,e),m=_i(c.stdout).filter(f=>i.has(f));return{repoRoot:e,sourceBranch:n,targetBranch:o,commits:m}}async function Cz(t,e){const n=await Nn('mkdir -p "$HOME/.config/openchamber/tmp" && mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),r=Il(n);if(!r)throw new Error(Ei(n)||"Failed to create temp directory");const o=await Nn(`git worktree add --force ${Lr(r)} ${Lr(e)}`,t);if(!O1(o))throw new Error(Ei(o)||"Failed to create temp worktree");return r}async function C2(t,e){await Nn(`git worktree remove --force ${Lr(e)}`,t).catch(()=>{}),await Nn("git worktree prune",t).catch(()=>{})}async function Az(t){const e=await Nn("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Il(e);if(!n)return;await Nn("git fetch",t);const r=await Nn(`git merge --ff-only ${Lr(n)}`,t);if(!O1(r))throw new Error(Ei(r)||"Fast-forward failed")}async function A2(t){const e=await Nn("git status --porcelain",t),n=await Nn("git diff --name-only --diff-filter=U",t),r=await Nn("git diff",t),o=await Nn("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),a=await Nn("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:_i(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:o.stdout||o.stderr||"",currentPatch:a.stdout||a.stderr||""}}async function Mz(t){return A2(t)}async function Fz(t){const e=await Nn("git rev-parse --verify --quiet CHERRY_PICK_HEAD && echo yes || echo no",t);return Il(e)==="yes"}async function Bz(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await Cz(t.repoRoot,t.targetBranch);let n=[];try{await Az(e);const r=await Nn("git status --porcelain",e);if(Il(r))throw new Error("Target branch has local changes; abort integration and retry");const o=await Nz({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const a=n[0],l=await Nn(`git cherry-pick ${Lr(a)}`,e);if(O1(l)){n.shift();continue}const i=await Nn("git diff --name-only --diff-filter=U",e);if(_i(i.stdout).length>0){const u=await A2(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:o,remainingCommits:n,currentCommit:a},details:u}}throw new Error(Ei(l)||"Cherry-pick failed")}return await C2(t.repoRoot,e),await l7(t.repoRoot,o).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await C2(t.repoRoot,e).catch(()=>{}),r}}async function _z(t){await Nn("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await C2(t.repoRoot,t.tempWorktreePath)}async function Ez(t){const e=await Nn("git cherry-pick --continue",t.tempWorktreePath);if(!O1(e)){const a=await Nn("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(_i(a.stdout).length>0){const i=await A2(t.tempWorktreePath);return{kind:"conflict",state:t,details:i}}throw new Error(Ei(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const o=[...r];for(;o.length>0;){const a=o[0],l=await Nn(`git cherry-pick ${Lr(a)}`,n);if(O1(l)){o.shift();continue}const i=await Nn("git diff --name-only --diff-filter=U",n);if(_i(i.stdout).length>0){const u=await A2(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:o,currentCommit:a},details:u}}throw new Error(Ei(l)||"Cherry-pick failed")}return await C2(t.repoRoot,t.tempWorktreePath),await l7(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:r.length}}const Dz=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:o,refreshKey:a,onRefresh:l})=>{const i=Ze(T=>T.currentSessionId),c=Ee(T=>T.setActiveMainTab),[u,m]=he.useState(!1),f=he.useRef(null),[h,p]=he.useState(o);he.useEffect(()=>{p(o)},[o]),he.useEffect(()=>{if(u){const T=setTimeout(()=>{f.current?.focus()},0);return()=>clearTimeout(T)}},[u]);const g=!!(t&&e&&h&&h!=="HEAD"&&e!==h),[x,b]=he.useState({kind:"idle"}),[v,y]=he.useState(!1),[w,C]=he.useState([]),N=he.useMemo(()=>i?`openchamber.integrate.conflict:${i}`:null,[i]);he.useEffect(()=>{if(!N||typeof window>"u")return;const T=window.localStorage.getItem(N);if(T)try{const _=JSON.parse(T);if(!_?.tempWorktreePath||_.repoRoot!==t){window.localStorage.removeItem(N);return}(async()=>{if(!await Fz(_.tempWorktreePath).catch(()=>!1)){window.localStorage.removeItem(N);return}const R=await Mz(_.tempWorktreePath).catch(()=>null);R&&b({kind:"conflict",state:_,details:R})})()}catch{window.localStorage.removeItem(N)}},[N,t]),he.useEffect(()=>{if(!g){b({kind:"idle"});return}let T=!1;return b({kind:"loading"}),(async()=>{try{const _=await Xi({repoRoot:t,sourceBranch:e,targetBranch:h});if(T)return;if(b({kind:"ready",plan:_}),_.commits.length>0){const W=_.commits.slice(-50).reverse().map(V=>JSON.stringify(V)).join(" "),Y=((await Nn(`git show -s --format=%H%x09%h%x09%s ${W}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),J=[];for(const V of Y){const[te,U,X]=V.split(" ");!te||!U||J.push({sha:te,short:U,subject:X||""})}T||(C(J),y(!1))}else T||(C([]),y(!1))}catch{T||b({kind:"idle"})}})(),()=>{T=!0}},[g,t,e,h,a]);const S=he.useCallback(T=>{i&&Ze.getState().setWorktreeMetadata(i,{...n,createdFromBranch:T})},[i,n]),k=Ze(T=>T.openNewSessionDraft),j=he.useCallback(T=>{const _=`Resolve cherry-pick conflicts, stage the resolved files, and continue the cherry-pick. Keep intent of commit ${T.state.currentCommit} onto branch ${T.state.targetBranch}.`,z=`Worktree commit integration (cherry-pick) is in progress with conflicts.
@@ -8008,12 +8008,12 @@ Must-fix:
8008
8008
  Nice-to-have:
8009
8009
  - None`,pe=Rq(oe);await En.sendMessage({id:O.sessionId,providerID:le,modelID:ae,agent:ue,variant:be,text:Z,additionalParts:[{text:ie,synthetic:!0},{text:pe,synthetic:!0}]}),fe.success("Session created from PR")}},[J,r,u,W,G,Y]),te=f==="new-branch"?p:x;he.useEffect(()=>{if(!v?.all||!u||p.sourceBranch)return;(async()=>{try{const H=await $l(u).catch(()=>null),K=localStorage.getItem(th),re=K&&v.all?.includes(K)?K:H&&v.all?.includes(H)?H:v.all?.includes("main")?"main":v.all?.includes("master")?"master":v.all?.[0]||"";re&&g(le=>({...le,sourceBranch:re}))}catch{}})()},[v,u,p.sourceBranch]),he.useEffect(()=>{if(!t){h("new-branch"),g({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),b({selectedBranch:"",worktreeName:""}),L({isValidating:!1,branchError:null,worktreeError:null,touched:!1});return}const O=F();g(H=>({...H,branchName:O,worktreeName:O,isSyncingWorktreeName:!0}))},[t,F]),he.useEffect(()=>{if(f!=="new-branch"||!p.isSyncingWorktreeName)return;const O=i1(p.branchName),H=qr(O);g(K=>({...K,worktreeName:H}))},[f,p.branchName,p.isSyncingWorktreeName]);const U=he.useCallback(async()=>{if(!m||!D.touched||T)return;z&&z.abort();const O=new AbortController;R(O),L(H=>({...H,isValidating:!0}));try{const H=f==="new-branch"?p.branchName:x.selectedBranch,K=te.worktreeName,re=i1(H),le=qr(K);let ae=null,ue=null;if(re||(ae="Branch name is required"),le||(ue="Worktree directory is required"),re&&le){const be=await E6(m,{mode:f==="existing-branch"?"existing":"new",branchName:re,worktreeName:le,existingBranch:f==="existing-branch"?re:void 0});if(O.signal.aborted)return;be.ok||be.errors.forEach(oe=>{if(oe.code==="worktree_exists"){ue=ue??oe.message;return}oe.code.startsWith("branch_")&&(ae=ae??oe.message)})}O.signal.aborted||L(be=>({...be,isValidating:!1,branchError:ae,worktreeError:ue}))}catch{O.signal.aborted||L(H=>({...H,isValidating:!1}))}},[m,f,p.branchName,x.selectedBranch,te.worktreeName,D.touched,z,T]),X=f==="new-branch"?p.branchName:x.selectedBranch;he.useEffect(()=>{if(!t||!m||!D.touched||T)return;const O=setTimeout(()=>{U()},300);return()=>clearTimeout(O)},[te.worktreeName,X,t,m,U,D.touched,T]);const $=async()=>{if(!m||!u){fe.error("No active project");return}L(le=>({...le,touched:!0}));const O=f==="new-branch"?p.branchName:x.selectedBranch,H=te.worktreeName,K=i1(O),re=qr(H);if(!K){fe.error("Branch name is required");return}if(!re){fe.error("Worktree directory is required");return}z&&(z.abort(),R(null)),L(le=>({...le,isValidating:!1,branchError:null,worktreeError:null})),_(!0);try{const le=await zi(m),ae=f==="new-branch"?p.linkedPr:null,ue=p.sourceBranch;let be="";const oe=(()=>{if(ae){const ye=Tq(ae,N);return be=ye.sourceLabel,{preferredName:K||re,mode:"existing",branchName:K,worktreeName:re,existingBranch:ye.existingBranch,setupCommands:le,setUpstream:ye.setUpstream,upstreamRemote:ye.upstreamRemote,upstreamBranch:ye.upstreamBranch,...ye.ensureRemoteName?{ensureRemoteName:ye.ensureRemoteName}:{},...ye.ensureRemoteUrl?{ensureRemoteUrl:ye.ensureRemoteUrl}:{}}}return be=f==="new-branch"?ue:"",{preferredName:K||re,mode:f==="existing-branch"?"existing":"new",branchName:f==="existing-branch"?void 0:K,worktreeName:re,existingBranch:f==="existing-branch"?K:void 0,setupCommands:le,...ue&&f==="new-branch"?{startRef:ue}:{}}})(),Z=await O8(u,oe),ie=await M6(m,Z),pe=f==="new-branch"?p.linkedIssue:null,me=f==="new-branch"?p.linkedPr:null,Se=f==="new-branch"?p.includePrDiff:!1;let ke=null;if(pe||me){const ye=pe?`#${pe.number} ${pe.title}`.trim():me?`#${me.number} ${me.title}`.trim():"New session",Ne=await Ze.getState().createSession(ye,ie.path,null);if(!Ne?.id)throw new Error("Failed to create session");ke=Ne.id,Ze.getState().updateSessionTitle(Ne.id,ye).catch(()=>{});try{Ze.getState().initializeNewOpenChamberSession(Ne.id,rs.getState().agents)}catch{}}p.sourceBranch&&f==="new-branch"&&!p.linkedPr&&localStorage.setItem(th,p.sourceBranch),fe.success("Worktree created",{description:`${ie.branch||ie.name}${be?` from ${be}`:""} - bootstrapping in background`}),k().catch(()=>{}),e(!1),ke?(n?.(ie.path,{sessionId:ke}),V({sessionId:ke,issue:pe,pr:me,includeDiff:Se}).catch(ye=>{const Ne=ye instanceof Error?ye.message:"Failed to send GitHub context";fe.error("Failed to send GitHub context",{description:Ne})})):n?.(ie.path)}catch(le){const ae=le instanceof Error?le.message:"Failed to create worktree";fe.error("Failed to create worktree",{description:ae})}finally{_(!1)}},q=O=>{h(O),L(H=>({...H,touched:!1,branchError:null,worktreeError:null}))},ee=O=>{if(!O){g(H=>({...H,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(O.type==="issue"){const H=O.item,K=`issue-${H.number}-${x1()}`;g(re=>({...re,linkedIssue:H,linkedPr:null,includePrDiff:!1,branchName:K,worktreeName:qr(K),isSyncingWorktreeName:!0}))}else if(O.type==="pr"){const H=O.item;g(K=>({...K,linkedPr:H,linkedIssue:null,includePrDiff:O.includeDiff??!1,branchName:H.head,worktreeName:qr(H.head),isSyncingWorktreeName:!0}))}},ce=i&&l?.connected===!0,ge=(f==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!D.branchError&&!D.worktreeError:!!i1(p.branchName)&&!!p.worktreeName&&!D.branchError&&!D.worktreeError)&&!T,xe=()=>{g(O=>({...O,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},ne=s.jsxs("div",{className:Q("flex gap-2",a?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:Q("flex items-center gap-1.5 text-destructive",a?"w-full justify-center order-first":"mr-auto"),children:D.touched&&(D.branchError||D.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(ba,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:D.branchError||D.worktreeError})]})}),s.jsxs("div",{className:Q("flex gap-2",a&&"w-full"),children:[s.jsx(Be,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:T,className:Q(a&&"flex-1"),children:"Cancel"}),s.jsxs(Be,{size:"sm",onClick:$,disabled:!ge||T,className:Q("gap-1.5",a&&"flex-1"),children:[T&&s.jsx(ts,{className:"h-3.5 w-3.5 animate-spin"}),T?"Creating...":"Create Worktree"]})]})]});return s.jsxs(s.Fragment,{children:[a?s.jsxs(cr,{open:t,title:"New Worktree",onClose:()=>e(!1),footer:ne,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(Ro,{items:[{id:"new-branch",label:"New Branch",icon:s.jsx(on,{className:"h-3.5 w-3.5"})},{id:"existing-branch",label:"Existing Branch",icon:s.jsx(Cd,{className:"h-3.5 w-3.5"})}],activeId:f,onSelect:O=>q(O),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:"Select Branch"}),s.jsxs(Be,{variant:"outline",size:"sm",onClick:()=>E(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:x.selectedBranch?"text-foreground":"text-muted-foreground",children:x.selectedBranch||"Choose a branch..."}),s.jsx(on,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(cr,{open:B,title:"Select Branch",onClose:()=>E(!1),children:s.jsx("div",{className:"space-y-4",children:y?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:"Loading branches..."}):C.length===0&&N.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:"No branches found"}):s.jsxs(s.Fragment,{children:[C.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:"Local branches"}),s.jsx("div",{className:"space-y-1",children:C.map(O=>s.jsx("button",{onClick:()=>{b(H=>({...H,selectedBranch:O,worktreeName:qr(O)})),L(H=>({...H,touched:!0})),E(!1)},className:Q("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===O?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:O})},O))})]}),N.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:"Remote branches"}),s.jsx("div",{className:"space-y-1",children:N.map(O=>s.jsx("button",{onClick:()=>{b(H=>({...H,selectedBranch:`remotes/${O}`,worktreeName:qr(O)})),L(H=>({...H,touched:!0})),E(!1)},className:Q("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${O}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:O})},`remotes/${O}`))})]})]})})})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:"Branch Name"}),f==="new-branch"&&ce&&s.jsxs(Be,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"gap-1.5 h-7",children:[s.jsx(Bo,{className:"size-4 text-status-success"}),p.linkedIssue||p.linkedPr?"Change":"Start from GitHub Issue/PR"]})]}),s.jsx(Xt,{value:p.branchName,onChange:O=>{g(H=>({...H,branchName:O.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>L(O=>({...O,touched:!0})),placeholder:"feature/my-awesome-feature",disabled:!!p.linkedPr,className:Q("h-8",D.touched&&D.branchError&&"border-destructive",p.linkedPr&&"bg-muted text-muted-foreground")}),p.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(js,{className:"h-3.5 w-3.5 text-status-success"}),s.jsxs("span",{className:"typography-micro",children:["Using PR branch: ",p.linkedPr.head]})]}),p.linkedIssue&&!p.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(js,{className:"h-3.5 w-3.5 text-status-success"}),s.jsxs("span",{className:"typography-micro",children:["From issue #",p.linkedIssue.number,": ",p.linkedIssue.title]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:"Worktree Directory"}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const O=qr(f==="new-branch"?p.branchName:"");g(H=>({...H,worktreeName:O,isSyncingWorktreeName:!0}))},disabled:!p.branchName||p.worktreeName===qr(p.branchName),className:Q("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",p.worktreeName===qr(p.branchName)||!p.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:"Reset to match branch name",children:[s.jsx(Qn,{className:"h-3 w-3"}),s.jsx("span",{children:"Reset"})]})]}),s.jsx(Xt,{value:te.worktreeName,onChange:O=>{f==="new-branch"?g(H=>({...H,worktreeName:O.target.value,isSyncingWorktreeName:!1})):b(H=>({...H,worktreeName:O.target.value}))},onBlur:()=>L(O=>({...O,touched:!0})),placeholder:"my-worktree-directory",className:Q("h-8",D.touched&&D.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!p.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:"Source Branch"}),s.jsxs(Be,{variant:"outline",size:"sm",onClick:()=>P(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:p.sourceBranch?"text-foreground":"text-muted-foreground",children:p.sourceBranch||"Select source branch..."}),s.jsx(on,{className:"h-4 w-4 text-muted-foreground"})]}),p.sourceBranch&&s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["New branch will be created from ",p.sourceBranch]}),s.jsx(cr,{open:I,title:"Select Source Branch",onClose:()=>P(!1),children:s.jsx("div",{className:"space-y-4",children:y?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:"Loading branches..."}):C.length===0&&N.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:"No branches found"}):s.jsxs(s.Fragment,{children:[C.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:"Local branches"}),s.jsx("div",{className:"space-y-1",children:C.map(O=>s.jsx("button",{onClick:()=>{g(H=>({...H,sourceBranch:O})),P(!1)},className:Q("w-full text-left px-3 py-2.5 rounded-md transition-colors",p.sourceBranch===O?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:O})},O))})]}),N.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:"Remote branches"}),s.jsx("div",{className:"space-y-1",children:N.map(O=>s.jsx("button",{onClick:()=>{g(H=>({...H,sourceBranch:`remotes/${O}`})),P(!1)},className:Q("w-full text-left px-3 py-2.5 rounded-md transition-colors",p.sourceBranch===`remotes/${O}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:O})},`remotes/${O}`))})]})]})})})]}),(p.linkedIssue||p.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bo,{className:"h-3.5 w-3.5 text-status-success shrink-0"}),p.linkedIssue&&s.jsxs("span",{className:"typography-micro text-muted-foreground shrink-0",children:["Issue #",p.linkedIssue.number]}),p.linkedPr&&s.jsxs("span",{className:"typography-micro text-muted-foreground shrink-0",children:["PR #",p.linkedPr.number]}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:p.linkedIssue?.title||p.linkedPr?.title}),s.jsx("a",{href:p.linkedIssue?.url||p.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:O=>O.stopPropagation(),children:s.jsx(wr,{className:"h-3 w-3"})}),s.jsx("button",{onClick:xe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(Ps,{className:"h-3.5 w-3.5"})})]}),p.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[p.linkedPr.head," → ",p.linkedPr.base]}),p.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:"+diff"})]})]})]})]}):s.jsx(Os,{open:t,onOpenChange:e,children:s.jsxs(Vs,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(Zs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(Us,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(on,{className:"h-5 w-5"}),"New Worktree"]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(Ro,{items:[{id:"new-branch",label:"New Branch",icon:s.jsx(on,{className:"h-3.5 w-3.5"})},{id:"existing-branch",label:"Existing Branch",icon:s.jsx(Cd,{className:"h-3.5 w-3.5"})}],activeId:f,onSelect:O=>q(O),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:"Select Branch"}),s.jsxs(Js,{value:x.selectedBranch,onValueChange:O=>{b(H=>({...H,selectedBranch:O,worktreeName:qr(O)})),L(H=>({...H,touched:!0}))},children:[s.jsx(en,{size:"lg",className:"w-fit",children:s.jsx(mn,{placeholder:"Choose a branch..."})}),s.jsx(tn,{className:"max-h-[280px] max-w-[320px]",children:y?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:"Loading branches..."}):C.length===0&&N.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:"No branches found"}):s.jsxs(s.Fragment,{children:[C.length>0&&s.jsxs(pa,{children:[s.jsx(pl,{className:"typography-small font-semibold text-foreground",children:"Local branches"}),C.map(O=>s.jsx(is,{value:O,className:"whitespace-normal break-all",children:O},O))]}),C.length>0&&N.length>0&&s.jsx(g2,{}),N.length>0&&s.jsxs(pa,{children:[s.jsx(pl,{className:"typography-small font-semibold text-foreground",children:"Remote branches"}),N.map(O=>s.jsx(is,{value:`remotes/${O}`,className:"whitespace-normal break-all",children:O},`remotes/${O}`))]})]})})]})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:"Branch Name"}),f==="new-branch"&&ce&&s.jsxs(Be,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"gap-1.5 h-7",children:[s.jsx(Bo,{className:"size-4 text-status-success"}),p.linkedIssue||p.linkedPr?"Change":"Start from GitHub Issue/PR"]})]}),s.jsx(Xt,{value:p.branchName,onChange:O=>{g(H=>({...H,branchName:O.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>L(O=>({...O,touched:!0})),placeholder:"feature/my-awesome-feature",disabled:!!p.linkedPr,className:Q("h-8",D.touched&&D.branchError&&"border-destructive",p.linkedPr&&"bg-muted text-muted-foreground")}),p.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(js,{className:"h-3.5 w-3.5 text-status-success"}),s.jsxs("span",{className:"typography-micro",children:["Using PR branch: ",p.linkedPr.head]})]}),p.linkedIssue&&!p.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(js,{className:"h-3.5 w-3.5 text-status-success"}),s.jsxs("span",{className:"typography-micro",children:["From issue #",p.linkedIssue.number,": ",p.linkedIssue.title]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:"Worktree Directory"}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const O=qr(f==="new-branch"?p.branchName:"");g(H=>({...H,worktreeName:O,isSyncingWorktreeName:!0}))},disabled:!p.branchName||p.worktreeName===qr(p.branchName),className:Q("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",p.worktreeName===qr(p.branchName)||!p.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:"Reset to match branch name",children:[s.jsx(Qn,{className:"h-3 w-3"}),s.jsx("span",{children:"Reset"})]})]}),s.jsx(Xt,{value:te.worktreeName,onChange:O=>{f==="new-branch"?g(H=>({...H,worktreeName:O.target.value,isSyncingWorktreeName:!1})):b(H=>({...H,worktreeName:O.target.value}))},onBlur:()=>L(O=>({...O,touched:!0})),placeholder:"my-worktree-directory",className:Q("h-8",D.touched&&D.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!p.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:"Source Branch"}),s.jsxs(Js,{value:p.sourceBranch,onValueChange:O=>g(H=>({...H,sourceBranch:O})),children:[s.jsx(en,{size:"lg",className:"w-fit",children:s.jsx(mn,{placeholder:"Select source branch..."})}),s.jsx(tn,{className:"max-h-[280px] max-w-[320px]",children:y?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:"Loading branches..."}):C.length===0&&N.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:"No branches found"}):s.jsxs(s.Fragment,{children:[C.length>0&&s.jsxs(pa,{children:[s.jsx(pl,{className:"typography-small font-semibold text-foreground",children:"Local branches"}),C.map(O=>s.jsx(is,{value:O,className:"whitespace-normal break-all",children:O},O))]}),C.length>0&&N.length>0&&s.jsx(g2,{}),N.length>0&&s.jsxs(pa,{children:[s.jsx(pl,{className:"typography-small font-semibold text-foreground",children:"Remote branches"}),N.map(O=>s.jsx(is,{value:`remotes/${O}`,className:"whitespace-normal break-all",children:O},`remotes/${O}`))]})]})})]}),p.sourceBranch&&s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["New branch will be created from ",p.sourceBranch]})]}),(p.linkedIssue||p.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bo,{className:"h-3.5 w-3.5 text-status-success shrink-0"}),p.linkedIssue&&s.jsxs("span",{className:"typography-micro text-muted-foreground shrink-0",children:["Issue #",p.linkedIssue.number]}),p.linkedPr&&s.jsxs("span",{className:"typography-micro text-muted-foreground shrink-0",children:["PR #",p.linkedPr.number]}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:p.linkedIssue?.title||p.linkedPr?.title}),s.jsx("a",{href:p.linkedIssue?.url||p.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:O=>O.stopPropagation(),children:s.jsx(wr,{className:"h-3 w-3"})}),s.jsx("button",{onClick:xe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(Ps,{className:"h-3.5 w-3.5"})})]}),p.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[p.linkedPr.head," → ",p.linkedPr.base]}),p.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:"+diff"})]})]})]}),s.jsxs(yn,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:D.touched&&(D.branchError||D.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(ba,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:D.branchError||D.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:T,children:"Cancel"}),s.jsxs(Be,{size:"sm",onClick:$,disabled:!ge||T,className:"gap-1.5",children:[T&&s.jsx(ts,{className:"h-3.5 w-3.5 animate-spin"}),T?"Creating...":"Create Worktree"]})]})]})]})}),s.jsx(Dq,{open:A,onOpenChange:M,onSelect:ee})]})}const Lq=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,X7=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:o})=>{const[a,l]=d.useState(!1),[i,c]=d.useState(""),[u,m]=d.useState([]),[f,h]=d.useState(""),[p,g]=d.useState(null),[x,b]=d.useState(()=>new Set),v=Ze(_=>_.currentSessionId),y=Ze(_=>_.openNewSessionDraft),w=Ze(_=>_.setPendingInputText),C=Ee(_=>_.setActiveMainTab),N=Ee(_=>_.setSessionSwitcherOpen),S=d.useCallback(async(_,z)=>{if(!t)return!1;const R=await yv(t,{notes:_,todos:z});return R||fe.error("Failed to save project notes"),R},[t]);d.useEffect(()=>{if(!t){c(""),m([]),h(""),b(new Set);return}let _=!1;return l(!0),(async()=>{try{const z=await wv(t);if(_)return;c(z.notes),m(z.todos),h(""),b(new Set)}catch{_||(fe.error("Failed to load project notes"),c(""),m([]))}finally{_||l(!1)}})(),()=>{_=!0}},[t]);const k=d.useCallback(()=>{S(i,u)},[i,S,u]),j=d.useCallback(()=>{const _=f.trim();if(!_)return;const z=[...u,{id:Lq(),text:_.slice(0,t0),completed:!1,createdAt:Date.now()}];m(z),h(""),S(i,z)},[f,i,S,u]),F=d.useCallback(_=>{b(z=>{const R=new Set(z);return R.has(_)?R.delete(_):R.add(_),R})},[]),A=d.useCallback((_,z)=>{const R=u.map(W=>W.id===_?{...W,completed:z}:W);m(R),S(i,R)},[i,S,u]),M=d.useCallback(_=>{const z=u.filter(R=>R.id!==_);m(z),S(i,z)},[i,S,u]),B=d.useCallback(()=>{const _=u.filter(z=>!z.completed);_.length!==u.length&&(m(_),S(i,_))},[i,S,u]),E=f.slice(0,t0),I=u.reduce((_,z)=>_+(z.completed?1:0),0),P=d.useCallback(()=>{C("chat"),N(!1)},[C,N]),D=d.useCallback(_=>{t&&(P(),y({directoryOverride:t.path,initialPrompt:_}),fe.success("Todo sent to new session"),r?.())},[r,y,t,P]),L=d.useCallback(_=>{if(!v){fe.error("No active session selected");return}P();const z=`\`\`\`md
8010
8010
  ${_}
8011
- \`\`\``;w(z,"append"),fe.success("Todo sent to current session"),r?.()},[v,r,P,w]),T=d.useCallback(async(_,z)=>{if(t){if(!n){fe.error("Worktree actions are only available for Git repositories");return}g(_);try{if(P(),!await U8({initialPrompt:z}))return;fe.success("Todo sent to new worktree session"),r?.()}finally{g(null)}}},[n,r,t,P]);return t?s.jsxs("div",{className:Q("w-full min-w-0 space-y-3 p-3",o),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:["Quick notes - ",e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[i.length,"/",L3]})]}),s.jsx(hr,{value:i,onChange:_=>c(_.target.value.slice(0,L3)),onBlur:k,placeholder:"Capture context, reminders, or links",className:"min-h-28 max-h-80 resize-none",useScrollShadow:!0,scrollShadowSize:56,disabled:a})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:"Todo"}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[u.length," item",u.length===1?"":"s"]}),s.jsx("button",{type:"button",onClick:B,disabled:a||I===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:"Clear completed"})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[E.length,"/",t0]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Xt,{value:E,onChange:_=>h(_.target.value.slice(0,t0)),onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),j())},placeholder:"Add a todo",disabled:a,className:"h-8"}),s.jsx("button",{type:"button",onClick:j,disabled:a||E.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 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 disabled:opacity-50","aria-label":"Add todo",children:s.jsx(Qs,{className:"h-4 w-4"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:u.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:"No todos yet. Add a small checklist for this project."}):s.jsx("ul",{className:"divide-y divide-border/50",children:u.map(_=>{const z=x.has(_.id);return s.jsxs("li",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx(fn,{checked:_.completed,onChange:R=>A(_.id,R),ariaLabel:`Mark "${_.text}" complete`,className:"mt-[3px] self-start"}),s.jsx("button",{type:"button",onClick:()=>F(_.id),className:Q("mt-[3px] min-w-0 flex-1 self-start bg-transparent p-0 text-left typography-ui-label text-foreground",z?"whitespace-normal break-words":"truncate","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",_.completed&&"text-muted-foreground line-through"),title:z?void 0:_.text,"aria-label":z?`Collapse todo "${_.text}"`:`Expand todo "${_.text}"`,children:_.text}),s.jsxs("div",{className:"mt-0.5 flex self-start items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>M(_.id),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":`Delete "${_.text}"`,children:s.jsx(Pn,{className:"h-3.5 w-3.5"})}),s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",disabled:p===_.id,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 disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Send "${_.text}"`,children:s.jsx(Ab,{className:"h-3.5 w-3.5"})})}),s.jsxs(Ys,{align:"end",className:"w-56",children:[s.jsx(Jt,{onClick:()=>L(_.text),children:"Send to current session"}),s.jsx(Jt,{onClick:()=>D(_.text),children:"Send to new session"}),s.jsx(Jt,{onClick:()=>{T(_.id,_.text)},disabled:!n,children:"Send to new worktree session"})]})]})]})]},_.id)})})})]})]}):s.jsx("div",{className:Q("w-full min-w-0 p-3",o),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:"Select a project to add notes and todos."})})},Hq=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(i=>nn(i.path)??i.path).filter(i=>!!i)]),a=(i=>i.filter(c=>P1(c,t.normalizedPath,r)))(e.archivedSessions),l=e.sessions.filter(i=>i.time?.archived||nn(i.directory??null)?!1:P1(i,t.normalizedPath,r));return Ai([...a,...l])},$q=t=>{const e=Fe.c(12),{normalizedProjects:n,sessions:r,archivedSessions:o,availableWorktreesByProject:a,isVSCode:l,isSessionsLoading:i,foldersMap:c,createFolder:u,addSessionToFolder:m,cleanupSessions:f}=t;let h,p;e[0]!==m||e[1]!==o||e[2]!==a||e[3]!==f||e[4]!==u||e[5]!==c||e[6]!==i||e[7]!==l||e[8]!==n||e[9]!==r?(h=()=>{i||n.forEach(g=>{const x=Uu(g.normalizedPath),b=Hq(g,{sessions:r,archivedSessions:o,availableWorktreesByProject:a,isVSCode:l}),v=new Set(b.map(Oq)),y=c[x]??[],w=new Map(y.map(Vq));b.forEach(C=>{const N=xj(C,g.normalizedPath),S=N.toLowerCase();let k=w.get(S);k||(k=u(x,N),w.set(S,k)),k.sessionIds.includes(C.id)||m(x,k.id,C.id)}),f(x,v)})},p=[n,r,o,a,l,i,c,u,m,f],e[0]=m,e[1]=o,e[2]=a,e[3]=f,e[4]=u,e[5]=c,e[6]=i,e[7]=l,e[8]=n,e[9]=r,e[10]=h,e[11]=p):(h=e[10],p=e[11]),d.useEffect(h,p)};function Oq(t){return t.id}function Vq(t){return[t.name.toLowerCase(),t]}const Uq=t=>{const e=Fe.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:o,availableWorktreesByProject:a,projectRepoStatus:l,projectRootBranches:i,lastRepoStatus:c,buildGroupedSessions:u,hasSessionSearchQuery:m,normalizedSessionSearchQuery:f,filterSessionNodesForSearch:h,buildGroupSearchText:p,getFoldersForScope:g}=t;let x;if(e[0]!==a||e[1]!==u||e[2]!==o||e[3]!==r||e[4]!==c||e[5]!==n||e[6]!==l||e[7]!==i){let A;e[9]!==a||e[10]!==u||e[11]!==o||e[12]!==r||e[13]!==c||e[14]!==l||e[15]!==i?(A=M=>{const B=Ai([...r(M),...o(M)]),E=a.get(M.normalizedPath)??[],I=l.has(M.id)?!!l.get(M.id):c,P=u(B,M.normalizedPath,E,i.get(M.id)??null,I);return{project:M,groups:P}},e[9]=a,e[10]=u,e[11]=o,e[12]=r,e[13]=c,e[14]=l,e[15]=i,e[16]=A):A=e[16],x=n.map(A),e[0]=a,e[1]=u,e[2]=o,e[3]=r,e[4]=c,e[5]=n,e[6]=l,e[7]=i,e[8]=x}else x=e[8];const b=x,v=b;let y;if(e[17]!==p||e[18]!==h||e[19]!==g||e[20]!==m||e[21]!==f||e[22]!==v){e:{const A=new WeakMap;if(!m){y=A;break e}const M=B=>B.reduce((E,I)=>E+1+M(I.children),0);v.forEach(B=>{B.groups.forEach(E=>{const I=h(E.sessions,f),P=M(I),D=p(E).includes(f),L=nn(E.directory??null),T=L?g(L).filter(_=>_.name.toLowerCase().includes(f)).length:0;A.set(E,{filteredNodes:I,matchedSessionCount:P,folderNameMatchCount:T,groupMatches:D,hasMatch:D||P>0||T>0})})}),y=A}e[17]=p,e[18]=h,e[19]=g,e[20]=m,e[21]=f,e[22]=v,e[23]=y}else y=e[23];const w=y;let C;e:{if(!m){C=v;break e}let A;if(e[24]!==w||e[25]!==v){let M;e[27]!==w?(M=B=>({...B,groups:B.groups.filter(E=>w.get(E)?.hasMatch===!0)}),e[27]=w,e[28]=M):M=e[28],A=v.map(M).filter(Wq),e[24]=w,e[25]=v,e[26]=A}else A=e[26];C=A}const N=C,S=m?N:v;let k;e:{if(!m){k=0;break e}let A;if(e[29]!==w||e[30]!==S){let M;e[32]!==w?(M=(B,E)=>B+E.groups.reduce((I,P)=>{const D=w.get(P);if(!D)return I;const L=D.folderNameMatchCount+(D.groupMatches?1:0);return I+D.matchedSessionCount+L},0),e[32]=w,e[33]=M):M=e[33],A=S.reduce(M,0),e[29]=w,e[30]=S,e[31]=A}else A=e[31];k=A}const j=k;let F;return e[34]!==w||e[35]!==b||e[36]!==j||e[37]!==N||e[38]!==S||e[39]!==v?(F={projectSections:b,visibleProjectSections:v,groupSearchDataByGroup:w,searchableProjectSections:N,sectionsForRender:S,searchMatchCount:j},e[34]=w,e[35]=b,e[36]=j,e[37]=N,e[38]=S,e[39]=v,e[40]=F):F=e[40],F};function Wq(t){return t.groups.length>0}const qq=t=>{const e=Fe.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:o,setActiveSessionByProject:a,currentSessionId:l,handleSessionSelect:i,newSessionDraftOpen:c,mobileVariant:u,openNewSessionDraft:m,setActiveMainTab:f,setSessionSwitcherOpen:h,sessions:p,worktreeMetadata:g}=t;let x,b;if(e[0]!==n){b=new Map,x=new Map;const M=(B,E,I,P)=>{b.has(B)||b.set(B,new Map);const D=b.get(B);P.forEach(L=>{const T=nn(L.worktree?.path??L.session.directory??I??E);D.set(L.session.id,{directory:T}),x.has(B)||x.set(B,{id:L.session.id,directory:T}),L.children.length>0&&M(B,E,T,L.children)})};n.forEach(B=>{B.groups.forEach(E=>{M(B.project.id,B.project.normalizedPath,E.directory,E.sessions)})}),e[0]=n,e[1]=x,e[2]=b}else x=e[1],b=e[2];let v;e[3]!==x||e[4]!==b?(v={metaByProject:b,firstSessionByProject:x},e[3]=x,e[4]=b,e[5]=v):v=e[5];const y=v,w=d.useRef(null);let C,N;e[6]!==r||e[7]!==o||e[8]!==l||e[9]!==i||e[10]!==u||e[11]!==c||e[12]!==m||e[13]!==n||e[14]!==y||e[15]!==f||e[16]!==a||e[17]!==h?(C=()=>{if(!r||c||w.current===r)return;const M=n.find(T=>T.project.id===r);if(!M)return;w.current=r;const B=y.metaByProject.get(r);if(l&&B&&B.has(l)){a(T=>{if(T.get(r)===l)return T;const _=new Map(T);return _.set(r,l),_});return}if(!B||B.size===0){f("chat"),u&&h(!1),m({directoryOverride:M.project.normalizedPath});return}const E=o.get(r),I=E&&B.has(E)?E:null,P=y.firstSessionByProject.get(r)?.id??null,D=I??P;if(!D||D===l)return;const L=B.get(D)?.directory??null;i(D,L,!1,r)},N=[r,o,l,i,c,u,m,n,y,f,h,a],e[6]=r,e[7]=o,e[8]=l,e[9]=i,e[10]=u,e[11]=c,e[12]=m,e[13]=n,e[14]=y,e[15]=f,e[16]=a,e[17]=h,e[18]=C,e[19]=N):(C=e[18],N=e[19]),d.useLayoutEffect(C,N);let S,k;e[20]!==r||e[21]!==l||e[22]!==y||e[23]!==a?(S=()=>{if(!r||!l)return;const M=y.metaByProject.get(r);!M||!M.has(l)||a(B=>{if(B.get(r)===l)return B;const E=new Map(B);return E.set(r,l),E})},k=[r,l,y,a],e[20]=r,e[21]=l,e[22]=y,e[23]=a,e[24]=S,e[25]=k):(S=e[24],k=e[25]),d.useEffect(S,k);let j;if(e[26]!==l||e[27]!==p||e[28]!==g){e:{if(!l){j=null;break e}const M=g.get(l)?.path;if(M){j=nn(M)??M;break e}let B;e[30]!==l?(B=I=>I.id===l,e[30]=l,e[31]=B):B=e[31];const E=p.find(B);if(!E){j=null;break e}j=nn(E.directory??null)}e[26]=l,e[27]=p,e[28]=g,e[29]=j}else j=e[29];const F=j;let A;return e[32]!==F?(A={currentSessionDirectory:F},e[32]=F,e[33]=A):A=e[33],A},Gq=t=>{const e=Fe.c(4);let n;e[0]!==t?(n=(a,l)=>{const i=t.get(a);if(!i||i.length===0)return l;const c=new Map(l.map(Zq)),u=[];return i.forEach(m=>{const f=c.get(m);f&&(u.push(f),c.delete(m))}),l.forEach(m=>{c.has(m.id)&&u.push(m)}),u},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 Zq(t){return[t.id,t]}const A0=t=>!!t.time?.archived,Kq=t=>{const e=d.useCallback(a=>[a.label,a.branch??"",a.description??"",a.directory??""].join(" ").toLowerCase(),[]),n=d.useCallback(a=>{const l=nn(a.directory??null)??"";return`${(a.title||"Untitled Session").trim()} ${l}`.toLowerCase()},[]),r=d.useCallback((a,l)=>l?a.flatMap(i=>{if(n(i.session).includes(l))return[i];const u=r(i.children,l);return u.length===0?[]:[{...i,children:u}]}):a,[n]),o=d.useCallback((a,l,i,c,u)=>{const m=nn(l??null),f=Ai(a).sort((F,A)=>T1(F,A,t.pinnedSessionIds)),h=new Map(f.map(F=>[F.id,F])),p=new Map;f.forEach(F=>{const A=F.parentID;if(!A)return;const M=h.get(A);if(!M||A0(M)!==A0(F))return;const B=p.get(A)??[];B.push(F),p.set(A,B)}),p.forEach(F=>F.sort((A,M)=>T1(A,M,t.pinnedSessionIds)));const g=new Map;i.forEach(F=>{if(F.path){const A=nn(F.path)??F.path;g.set(A,F)}});const x=F=>{const A=nn(F.directory??null),M=t.worktreeMetadata.get(F.id)??null;if(M)return M;if(A){const B=g.get(A)??null;if(B&&A!==m)return B}return null},b=F=>{const A=p.get(F.id)??[];return{session:F,children:A.map(M=>b(M)),worktree:x(F)}},v=f.filter(F=>{const A=F.parentID;if(!A)return!0;const M=h.get(A);return M?A0(M)!==A0(F):!0}),y=new Map,w="__archived__",C=F=>{if(F.time?.archived)return w;const A=nn(t.worktreeMetadata.get(F.id)?.path??null),M=nn(F.directory??null);if(!A&&!M)return w;const B=nn(F.project?.worktree??null),E=A??M??B;return E?E!==m&&g.has(E)?E:E===m?m??"__project_root__":w:w};v.forEach(F=>{const A=b(F),M=C(F);y.has(M)||y.set(M,[]),y.get(M)?.push(A)});const N=m??"__project_root__",S=[{id:"root",label:u&&c&&c!=="HEAD"?`project root: ${c}`:"project root",branch:c??null,description:m?va(m,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:m,folderScopeKey:m,sessions:y.get(N)??[]}],k=new Map;return i.forEach(F=>{const A=nn(F.path)??F.path,M=y.get(A)??[],B=M.length>0,E=M.reduce((I,P)=>{const D=Number(P.session.time?.updated??P.session.time?.created??0);return Number.isFinite(D)?Math.max(I,D):I},0);k.set(A,{hasActiveSession:B,lastUpdatedAt:E})}),[...i].sort((F,A)=>{const M=nn(F.path)??F.path,B=nn(A.path)??A.path,E=k.get(M)??{hasActiveSession:!1,lastUpdatedAt:0},I=k.get(B)??{hasActiveSession:!1,lastUpdatedAt:0};if(E.hasActiveSession!==I.hasActiveSession)return E.hasActiveSession?-1:1;if(E.hasActiveSession&&I.hasActiveSession)return I.lastUpdatedAt-E.lastUpdatedAt;const P=(F.label||F.branch||F.name||F.path||"").toLowerCase(),D=(A.label||A.branch||A.name||A.path||"").toLowerCase();return P.localeCompare(D)}).forEach(F=>{const A=nn(F.path)??F.path,M=t.gitDirectories.get(A)?.status?.current?.trim()||null,B=F.branch?.trim()||null,I=!!(M&&B&&F.label&&h2(F.label)===h2(B))?M:F.label||F.name||Or(A,t.homeDirectory)||A;S.push({id:`worktree:${A}`,label:I,branch:M||B,description:va(A,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:F,directory:A,folderScopeKey:A,sessions:y.get(A)??[]})}),S.push({id:"archived",label:"archived",branch:null,description:"Archived and unassigned sessions",isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&m?Uu(m):null,sessions:y.get(w)??[]}),S},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitDirectories,t.isVSCode]);return{buildGroupSearchText:e,buildSessionSearchText:n,filterSessionNodesForSearch:r,buildGroupedSessions:o}},Yq=t=>{const e=Fe.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:o,sessionSearchContainerRef:a}=t;let l,i;e[0]!==n||e[1]!==o?(l=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.select()});return()=>window.cancelAnimationFrame(m)},i=[n,o],e[0]=n,e[1]=o,e[2]=l,e[3]=i):(l=e[2],i=e[3]),d.useEffect(l,i);let c,u;e[4]!==n||e[5]!==a||e[6]!==r?(c=()=>{if(!n||typeof document>"u")return;const m=f=>{a.current&&(a.current.contains(f.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},u=[n,r,a],e[4]=n,e[5]=a,e[6]=r,e[7]=c,e[8]=u):(c=e[7],u=e[8]),d.useEffect(c,u)},Xq=180,Qq=1,Jq=6,eG=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],loadMessages:r})=>{const o=d.useRef(new Map),a=d.useRef([]),l=d.useRef(new Set),i=d.useCallback(()=>{if(!(typeof window>"u"))for(;l.current.size<Qq&&a.current.length>0;){const u=a.current.shift();if(!u)break;const m=Ze.getState();if(m.currentSessionId===u)continue;const f=m.messages.has(u),h=m.sessionHistoryMeta.get(u);f&&typeof h?.complete=="boolean"||(l.current.add(u),r(u).catch(()=>{}).finally(()=>{l.current.delete(u),i()}))}},[r]),c=d.useCallback(u=>{if(!u||u===t||typeof window>"u")return;const m=Ze.getState(),f=m.messages.has(u),h=m.sessionHistoryMeta.get(u);if(f&&typeof h?.complete=="boolean"||l.current.has(u)||a.current.includes(u))return;a.current.length>=Jq&&a.current.shift();const g=o.current.get(u);g!==void 0&&window.clearTimeout(g);const x=window.setTimeout(()=>{o.current.delete(u),a.current.push(u),i()},Xq);o.current.set(u,x)},[t,i]);d.useEffect(()=>{if(!t||e.length===0)return;const u=e.findIndex(m=>m.id===t);u<0||(c(e[u-1]?.id),c(e[u+1]?.id))},[t,c,e]),d.useEffect(()=>{if(!t||n.length===0)return;const u=n.indexOf(t);u<0||(c(n[u-1]),c(n[u+1]))},[t,n,c]),d.useEffect(()=>{const u=o.current;return()=>{u.forEach(m=>{clearTimeout(m)}),u.clear(),a.current=[]}},[])},tG=t=>{const e=Fe.c(10),{sortedSessions:n,projects:r,directoryStatus:o,setDirectoryStatus:a}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=new Map,e[0]=l):l=e[0];const i=d.useRef(l);let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c=new Set,e[1]=c):c=e[1];const u=d.useRef(c);let m,f;e[2]!==o?(m=()=>{i.current=o},f=[o],e[2]=o,e[3]=m,e[4]=f):(m=e[3],f=e[4]),d.useEffect(m,f);let h,p;e[5]!==r||e[6]!==a||e[7]!==n?(h=()=>{const g=new Set;n.forEach(x=>{const b=nn(x.directory??null);b&&g.add(b)}),r.forEach(x=>{const b=nn(x.path);b&&g.add(b)}),g.forEach(x=>{const b=i.current.get(x);b&&b!=="unknown"||u.current.has(x)||(u.current.add(x),En.listLocalDirectory(x).then(()=>{a(v=>{const y=new Map(v);return y.get(x)==="exists"?v:(y.set(x,"exists"),y)})}).catch(async()=>{if((x.includes("/opencode/worktree/")||x.includes("/.opencode/data/worktree/")||x.includes("/.local/share/opencode/worktree/"))&&await En.probeDirectory(x).catch(sG)){a(w=>{const C=new Map(w);return C.get(x)==="exists"?w:(C.set(x,"exists"),C)});return}a(y=>{const w=new Map(y);return w.get(x)==="missing"?y:(w.set(x,"missing"),w)})}).finally(()=>{u.current.delete(x)}))})},p=[n,r,a],e[5]=r,e[6]=a,e[7]=n,e[8]=h,e[9]=p):(h=e[8],p=e[9]),d.useEffect(h,p)};function sG(){return!1}const nG=t=>{const e=Fe.c(37),[n,r]=d.useState(null),o=d.useRef(null);let a,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>()=>{o.current&&clearTimeout(o.current)},l=[],e[0]=a,e[1]=l):(a=e[0],l=e[1]),d.useEffect(a,l);let i;e[2]!==t?(i=(I,P,D,L)=>{if(D)return;const T=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(L&&L!==t.activeProjectId&&t.setActiveProjectIdOnly(L),P&&P!==t.currentDirectory&&t.setDirectory(P,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),I===t.currentSessionId){t.allowReselect&&(typeof window<"u"&&window.dispatchEvent(new CustomEvent("archcoder:session-reselected",{detail:I})),t.onSessionSelected?.(I)),T();return}t.setCurrentSession(I),t.onSessionSelected?.(I),T()},e[2]=t,e[3]=i):i=e[3];const c=i;let u;e[4]!==t?(u=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=u):u=e[5];const m=u;let f;e[6]!==t?(f=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=f):f=e[7];const h=f;let p;e[8]!==t?(p=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=p):p=e[9];const g=p;let x;e[10]!==t?(x=async I=>{const P=await t.shareSession(I.id);P&&P.share?.url?fe.success("Session shared",{description:"You can copy the link from the menu."}):fe.error("Unable to share session")},e[10]=t,e[11]=x):x=e[11];const b=x;let v;e[12]===Symbol.for("react.memo_cache_sentinel")?(v=(I,P)=>{Dn(I).then(D=>{if(!D.ok){fe.error("Failed to copy URL");return}r(P),o.current&&clearTimeout(o.current),o.current=window.setTimeout(()=>{r(null),o.current=null},2e3)}).catch(rG)},e[12]=v):v=e[12];const y=v;let w;e[13]!==t?(w=async I=>{await t.unshareSession(I)?fe.success("Session unshared"):fe.error("Unable to unshare session")},e[13]=t,e[14]=w):w=e[14];const C=w;let N;e[15]!==t.childrenMap?(N=I=>{const P=[],D=L=>{(t.childrenMap.get(L)??[]).forEach(_=>{P.push(_),D(_.id)})};return D(I),P},e[15]=t.childrenMap,e[16]=N):N=e[16];const S=N;let k;e[17]!==t||e[18]!==S?(k=async(I,P)=>{const D=S(I.id),L=P?.archivedBucket===!0;if(D.length===0){(L?await t.deleteSession(I.id):await t.archiveSession(I.id))?fe.success(L?"Session deleted":"Session archived"):fe.error(L?"Failed to delete session":"Failed to archive session");return}const T=[I.id,...D.map(oG)];if(L){const{deletedIds:R,failedIds:W}=await t.deleteSessions(T);R.length>0&&fe.success(`Deleted ${R.length} session${R.length===1?"":"s"}`),W.length>0&&fe.error(`Failed to delete ${W.length} session${W.length===1?"":"s"}`);return}const{archivedIds:_,failedIds:z}=await t.archiveSessions(T);_.length>0&&fe.success(`Archived ${_.length} session${_.length===1?"":"s"}`),z.length>0&&fe.error(`Failed to archive ${z.length} session${z.length===1?"":"s"}`)},e[17]=t,e[18]=S,e[19]=k):k=e[19];const j=k;let F;e[20]!==t||e[21]!==S||e[22]!==j?(F=(I,P)=>{const D=S(I.id);if(!t.showDeletionDialog){j(I,P);return}t.setDeleteSessionConfirm({session:I,descendantCount:D.length,archivedBucket:P?.archivedBucket===!0})},e[20]=t,e[21]=S,e[22]=j,e[23]=F):F=e[23];const A=F;let M;e[24]!==t||e[25]!==j?(M=async()=>{if(!t.deleteSessionConfirm)return;const{session:I,archivedBucket:P}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await j(I,{archivedBucket:P})},e[24]=t,e[25]=j,e[26]=M):M=e[26];const B=M;let E;return e[27]!==B||e[28]!==n||e[29]!==g||e[30]!==A||e[31]!==h||e[32]!==m||e[33]!==c||e[34]!==b||e[35]!==C?(E={copiedSessionId:n,handleSessionSelect:c,handleSessionDoubleClick:m,handleSaveEdit:h,handleCancelEdit:g,handleShareSession:b,handleCopyShareUrl:y,handleUnshareSession:C,handleDeleteSession:A,confirmDeleteSession:B},e[27]=B,e[28]=n,e[29]=g,e[30]=A,e[31]=h,e[32]=m,e[33]=c,e[34]=b,e[35]=C,e[36]=E):E=e[36],E};function rG(){fe.error("Failed to copy URL")}function oG(t){return t.id}const aG=t=>{const e=Fe.c(40),{isVSCode:n,safeStorage:r,keys:o,sessions:a,pinnedSessionIds:l,setPinnedSessionIds:i,groupOrderByProject:c,activeSessionByProject:u,collapsedGroups:m,setExpandedParents:f,setCollapsedProjects:h}=t,p=d.useRef(null),g=d.useRef(null);let x;e[0]!==n?(x=()=>{if(n)return;const T=g.current;if(g.current=null,p.current=null,!T)return;const{projects:_}=vs.getState(),z=_.map(R=>({...R,sidebarCollapsed:T.has(R.id)}));ln({projects:z}).catch(lG)},e[0]=n,e[1]=x):x=e[1];const b=x;let v;e[2]!==b||e[3]!==n?(v=T=>{typeof window>"u"||n||(g.current=T,p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{b()},700))},e[2]=b,e[3]=n,e[4]=v):v=e[4];const y=v;let w,C;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=()=>()=>{typeof window<"u"&&p.current!==null&&window.clearTimeout(p.current),p.current=null,g.current=null},C=[],e[5]=w,e[6]=C):(w=e[5],C=e[6]),d.useEffect(w,C);let N,S;e[7]!==o.projectCollapse||e[8]!==o.sessionExpanded||e[9]!==r||e[10]!==h||e[11]!==f?(N=()=>{try{const T=r.getItem(o.sessionExpanded);if(T){const z=JSON.parse(T);Array.isArray(z)&&f(new Set(z.filter(iG)))}const _=r.getItem(o.projectCollapse);if(_){const z=JSON.parse(_);Array.isArray(z)&&h(new Set(z.filter(cG)))}}catch{}},S=[o.projectCollapse,o.sessionExpanded,r,h,f],e[7]=o.projectCollapse,e[8]=o.sessionExpanded,e[9]=r,e[10]=h,e[11]=f,e[12]=N,e[13]=S):(N=e[12],S=e[13]),d.useEffect(N,S);let k,j;e[14]!==a||e[15]!==i?(k=()=>{const T=new Set(a.map(dG));i(_=>{let z=!1;const R=new Set;return _.forEach(W=>{T.has(W)?R.add(W):z=!0}),z?R:_})},j=[a,i],e[14]=a,e[15]=i,e[16]=k,e[17]=j):(k=e[16],j=e[17]),d.useEffect(k,j);let F,A;e[18]!==o.sessionPinned||e[19]!==l||e[20]!==r?(F=()=>{try{r.setItem(o.sessionPinned,JSON.stringify(Array.from(l)))}catch{}},A=[o.sessionPinned,l,r],e[18]=o.sessionPinned,e[19]=l,e[20]=r,e[21]=F,e[22]=A):(F=e[21],A=e[22]),d.useEffect(F,A);let M,B;e[23]!==c||e[24]!==o.groupOrder||e[25]!==r?(M=()=>{try{const T=Object.fromEntries(c.entries());r.setItem(o.groupOrder,JSON.stringify(T))}catch{}},B=[c,o.groupOrder,r],e[23]=c,e[24]=o.groupOrder,e[25]=r,e[26]=M,e[27]=B):(M=e[26],B=e[27]),d.useEffect(M,B);let E,I;e[28]!==u||e[29]!==o.projectActiveSession||e[30]!==r?(E=()=>{try{const T=Object.fromEntries(u.entries());r.setItem(o.projectActiveSession,JSON.stringify(T))}catch{}},I=[u,o.projectActiveSession,r],e[28]=u,e[29]=o.projectActiveSession,e[30]=r,e[31]=E,e[32]=I):(E=e[31],I=e[32]),d.useEffect(E,I);let P,D;e[33]!==m||e[34]!==o.groupCollapse||e[35]!==r?(P=()=>{try{r.setItem(o.groupCollapse,JSON.stringify(Array.from(m)))}catch{}},D=[m,o.groupCollapse,r],e[33]=m,e[34]=o.groupCollapse,e[35]=r,e[36]=P,e[37]=D):(P=e[36],D=e[37]),d.useEffect(P,D);let L;return e[38]!==y?(L={scheduleCollapsedProjectsPersist:y},e[38]=y,e[39]=L):L=e[39],L};function lG(){}function iG(t){return typeof t=="string"}function cG(t){return typeof t=="string"}function dG(t){return t.id}const uG=t=>{const e=Fe.c(17),{projects:n,normalizedProjects:r,normalizePath:o,gitDirectories:a,setProjectRepoStatus:l,setProjectRootBranches:i}=t;let c,u;e[0]!==o||e[1]!==n||e[2]!==l?(c=()=>{let g=!1;const x=n.map(b=>({id:b.id,path:o(b.path)})).filter(fG);return l(new Map),x.length===0?()=>{g=!0}:(x.forEach(b=>{Ri(b.path).then(v=>{g||l(y=>{const w=new Map(y);return w.set(b.id,v),w})}).catch(()=>{g||l(v=>{const y=new Map(v);return y.set(b.id,null),y})})}),()=>{g=!0})},u=[o,n,l],e[0]=o,e[1]=n,e[2]=l,e[3]=c,e[4]=u):(c=e[3],u=e[4]),d.useEffect(c,u);let m;if(e[5]!==a||e[6]!==r){let g;e[8]!==a?(g=x=>{const b=a.get(x.normalizedPath);return`${x.id}:${b?.status?.current??""}`},e[8]=a,e[9]=g):g=e[9],m=r.map(g).join("|"),e[5]=a,e[6]=r,e[7]=m}else m=e[7];const f=m;let h;e[10]!==r||e[11]!==i?(h=()=>{let g=!1;return(async()=>{const b=await Promise.all(r.map(hG));g||i(v=>{const y=new Map(v);return b.forEach(w=>{const{id:C,branch:N}=w;N&&y.set(C,N)}),y})})(),()=>{g=!0}},e[10]=r,e[11]=i,e[12]=h):h=e[12];let p;e[13]!==r||e[14]!==f||e[15]!==i?(p=[r,f,i],e[13]=r,e[14]=f,e[15]=i,e[16]=p):p=e[16],d.useEffect(h,p)};function fG(t){return!!t.path}function mG(){return null}async function hG(t){const e=await $l(t.normalizedPath).catch(mG);return{id:t.id,branch:e}}const pG=t=>{const e=Fe.c(13),{isVSCode:n,sessions:r,archivedSessions:o,sessionsByDirectory:a,getSessionsByDirectory:l,availableWorktreesByProject:i}=t;let c;e[0]!==i||e[1]!==l||e[2]!==n||e[3]!==a?(c=p=>{const g=n?[]:i.get(p.normalizedPath)??[],x=[p.normalizedPath,...g.map(gG).filter(xG)],b=new Set,v=[];return x.forEach(y=>{(a.get(y)??l(y)).forEach(C=>{b.has(C.id)||(b.add(C.id),v.push(C))})}),v},e[0]=i,e[1]=l,e[2]=n,e[3]=a,e[4]=c):c=e[4];const u=c;let m;e[5]!==o||e[6]!==i||e[7]!==n||e[8]!==r?(m=p=>{if(n){const w=o.filter(N=>{const S=nn(N.directory??null),k=nn(N.project?.worktree??null);return S?S===p.normalizedPath:k===p.normalizedPath}),C=r.filter(N=>N.time?.archived||nn(N.directory??null)?!1:nn(N.project?.worktree??null)===p.normalizedPath);return Ai([...w,...C])}const g=n?[]:i.get(p.normalizedPath)??[],x=new Set([p.normalizedPath,...g.map(bG).filter(vG)]),v=(w=>w.filter(C=>P1(C,p.normalizedPath,x)))(o),y=r.filter(w=>{if(w.time?.archived||nn(w.directory??null))return!1;const N=nn(w.project?.worktree??null);return N?N===p.normalizedPath||N.startsWith(`${p.normalizedPath}/`):!1});return Ai([...v,...y])},e[5]=o,e[6]=i,e[7]=n,e[8]=r,e[9]=m):m=e[9];const f=m;let h;return e[10]!==f||e[11]!==u?(h={getSessionsForProject:u,getArchivedSessionsForProject:f},e[10]=f,e[11]=u,e[12]=h):h=e[12],h};function gG(t){return nn(t.path)??t.path}function xG(t){return!!t}function bG(t){return nn(t.path)??t.path}function vG(t){return!!t}const yG=t=>{const e=Fe.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:o,normalizedProjects:a,isVSCode:l,availableWorktreesByProject:i,cleanupSessions:c}=t;let u,m;e[0]!==o||e[1]!==i||e[2]!==c||e[3]!==n||e[4]!==l||e[5]!==a||e[6]!==r?(u=()=>{if(n)return;const f=new Map;r.forEach(g=>{const x=nn(g.directory??null);if(!x)return;const b=f.get(x);if(b){b.add(g.id);return}f.set(x,new Set([g.id]))}),a.forEach(g=>{const x=Uu(g.normalizedPath),b=l?[]:i.get(g.normalizedPath)??[],v=new Set([g.normalizedPath,...b.map(wG).filter(jG)]),y=Ai([...o,...r.filter(w=>w.time?.archived||nn(w.directory??null)?!1:P1(w,g.normalizedPath,v))]).filter(w=>P1(w,g.normalizedPath,v));f.set(x,new Set(y.map(kG)))});const h=uo.getState().foldersMap;new Set([...Object.keys(h),...f.keys()]).forEach(g=>{c(g,f.get(g)??new Set)})},m=[o,i,c,n,l,a,r],e[0]=o,e[1]=i,e[2]=c,e[3]=n,e[4]=l,e[5]=a,e[6]=r,e[7]=u,e[8]=m):(u=e[7],m=e[8]),d.useEffect(u,m)};function wG(t){return nn(t.path)??t.path}function jG(t){return!!t}function kG(t){return t.id}const NG=t=>{const e=Fe.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:o}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[l,i]=d.useState(a);let c;e[1]!==n||e[2]!==o?(c=()=>{if(!n)return;const m=new IntersectionObserver(f=>{f.forEach(h=>{const p=h.target.dataset.projectId;p&&i(g=>{const x=new Set(g);return h.isIntersecting?x.delete(p):x.add(p),x})})},{threshold:0});return o.current.forEach(f=>{f&&m.observe(f)}),()=>m.disconnect()},e[1]=n,e[2]=o,e[3]=c):c=e[3];let u;return e[4]!==n||e[5]!==o||e[6]!==r?(u=[n,o,r],e[4]=n,e[5]=o,e[6]=r,e[7]=u):u=e[7],d.useEffect(c,u),l},SG=t=>{const e=Fe.c(78),{folder:n,sessions:r,subFolderItems:o,isCollapsed:a,onToggle:l,onRename:i,onDelete:c,renderSessionNode:u,groupDirectory:m,projectId:f,mobileVariant:h,isRenaming:p,renameDraft:g,onRenameDraftChange:x,onRenameSave:b,onRenameCancel:v,droppableRef:y,isDropTarget:w,onNewSession:C,onNewSubFolder:N,depth:S,hideActions:k,archivedBucket:j}=t,F=h===void 0?!1:h,A=p===void 0?!1:p,M=g===void 0?"":g,B=w===void 0?!1:w,E=S===void 0?0:S,I=k===void 0?!1:k,P=j===void 0?!1:j,[D,L]=d.useState(!1),[T,_]=d.useState(""),z=d.useRef(null),R=A||D,W=A?M:T;let G;e[0]!==n.name?(G=()=>{_(n.name),L(!0)},e[0]=n.name,e[1]=G):G=e[1];const Y=G;let J;e[2]!==W||e[3]!==n.name||e[4]!==A||e[5]!==i||e[6]!==b?(J=()=>{const _e=W.trim();_e&&_e!==n.name&&i(_e),A&&b&&b(),L(!1),_("")},e[2]=W,e[3]=n.name,e[4]=A,e[5]=i,e[6]=b,e[7]=J):J=e[7];const V=J;let te;e[8]!==A||e[9]!==v?(te=()=>{A&&v&&v(),L(!1),_("")},e[8]=A,e[9]=v,e[10]=te):te=e[10];const U=te;let X;e[11]!==A||e[12]!==x?(X=_e=>{A&&x?x(_e):_(_e)},e[11]=A,e[12]=x,e[13]=X):X=e[13];const $=X;let q,ee;e[14]!==A?(q=()=>{if(!A)return;const _e=()=>{const je=z.current;je&&(je.focus(),je.select())},de=requestAnimationFrame(_e),we=window.setTimeout(_e,0);return()=>{cancelAnimationFrame(de),window.clearTimeout(we)}},ee=[A],e[14]=A,e[15]=q,e[16]=ee):(q=e[15],ee=e[16]),d.useEffect(q,ee);const ce=a?jr:Mb,ge=E>0&&"ml-3";let xe;e[17]!==ge?(xe=Q("oc-folder",ge),e[17]=ge,e[18]=xe):xe=e[18];const ne=B&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let O;e[19]!==ne?(O=Q("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",ne),e[19]=ne,e[20]=O):O=e[20];const H=R?void 0:l,K=R?void 0:"button",re=R?void 0:0;let le;e[21]!==l||e[22]!==R?(le=R?void 0:_e=>{(_e.key==="Enter"||_e.key===" ")&&(_e.preventDefault(),l())},e[21]=l,e[22]=R,e[23]=le):le=e[23];const ae=a?`Expand folder ${n.name}`:`Collapse folder ${n.name}`,ue=P?F?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let be;e[24]!==ue?(be=Q("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",ue),e[24]=ue,e[25]=be):be=e[25];const oe=B?"text-primary":"text-muted-foreground";let Z;e[26]!==oe?(Z=Q("h-3.5 w-3.5 flex-shrink-0",oe),e[26]=oe,e[27]=Z):Z=e[27];let ie;e[28]!==ce||e[29]!==Z?(ie=s.jsx(ce,{className:Z}),e[28]=ce,e[29]=Z,e[30]=ie):ie=e[30];let pe;e[31]!==W||e[32]!==n.name||e[33]!==U||e[34]!==$||e[35]!==V||e[36]!==a||e[37]!==B||e[38]!==R||e[39]!==r?(pe=R?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1","data-keyboard-avoid":"true",onPointerDown:AG,onMouseDown:MG,onSubmit:_e=>{_e.preventDefault(),V()},children:[s.jsx("input",{ref:z,value:W,onChange:_e=>$(_e.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:"Folder name",onClick:FG,onPointerDown:BG,onMouseDown:_G,onKeyDown:_e=>{if(_e.key==="Escape"){_e.stopPropagation(),U();return}(_e.key===" "||_e.key==="Enter")&&_e.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:EG,onPointerDown:DG,onMouseDown:IG,children:s.jsx(js,{className:"size-4"})}),s.jsx("button",{type:"button",onClick:_e=>{_e.stopPropagation(),U()},onPointerDown:TG,onMouseDown:PG,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(Ps,{className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:Q("typography-ui-label font-semibold truncate",B?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),a?s.jsx(On,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(Ds,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[31]=W,e[32]=n.name,e[33]=U,e[34]=$,e[35]=V,e[36]=a,e[37]=B,e[38]=R,e[39]=r,e[40]=pe):pe=e[40];let me;e[41]!==be||e[42]!==ie||e[43]!==pe?(me=s.jsxs("div",{className:be,children:[ie,pe]}),e[41]=be,e[42]=ie,e[43]=pe,e[44]=me):me=e[44];let Se;e[45]!==P||e[46]!==E||e[47]!==n.name||e[48]!==Y||e[49]!==I||e[50]!==F||e[51]!==c||e[52]!==C||e[53]!==N||e[54]!==R?(Se=!R&&(!I||P)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:Q("flex items-center gap-0.5 transition-opacity",F?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",P&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!P&&C?s.jsx("button",{type:"button",onClick:_e=>{_e.stopPropagation(),C()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`New session in ${n.name}`,title:"New session",children:s.jsx(Qs,{className:"h-3.5 w-3.5"})}):null,!P&&N&&E===0?s.jsx("button",{type:"button",onClick:_e=>{_e.stopPropagation(),N()},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":`New sub-folder in ${n.name}`,title:"New sub-folder",children:s.jsx(Pi,{className:"h-3.5 w-3.5"})}):null,P?null:s.jsx("button",{type:"button",onClick:_e=>{_e.stopPropagation(),Y()},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":`Rename folder ${n.name}`,children:s.jsx(_o,{className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:_e=>{_e.stopPropagation(),c()},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":P?`Delete archived sessions in folder ${n.name}`:`Delete folder ${n.name}`,children:s.jsx(Pn,{className:"h-3.5 w-3.5"})})]})}):null,e[45]=P,e[46]=E,e[47]=n.name,e[48]=Y,e[49]=I,e[50]=F,e[51]=c,e[52]=C,e[53]=N,e[54]=R,e[55]=Se):Se=e[55];let ke;e[56]!==y||e[57]!==O||e[58]!==H||e[59]!==K||e[60]!==re||e[61]!==le||e[62]!==ae||e[63]!==me||e[64]!==Se?(ke=s.jsxs("div",{ref:y,className:O,onClick:H,role:K,tabIndex:re,onKeyDown:le,"aria-label":ae,children:[me,Se]}),e[56]=y,e[57]=O,e[58]=H,e[59]=K,e[60]=re,e[61]=le,e[62]=ae,e[63]=me,e[64]=Se,e[65]=ke):ke=e[65];let ye;e[66]!==P||e[67]!==m||e[68]!==a||e[69]!==f||e[70]!==u||e[71]!==r||e[72]!==o?(ye=a?null:s.jsxs("div",{className:"pb-1 pl-2",children:[o,r.length>0?r.map(_e=>u(_e,0,m??null,f??null,P)):o?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:"Empty folder"})]}),e[66]=P,e[67]=m,e[68]=a,e[69]=f,e[70]=u,e[71]=r,e[72]=o,e[73]=ye):ye=e[73];let Ne;return e[74]!==xe||e[75]!==ke||e[76]!==ye?(Ne=s.jsxs("div",{className:xe,children:[ke,ye]}),e[74]=xe,e[75]=ke,e[76]=ye,e[77]=Ne):Ne=e[77],Ne},CG=d.memo(SG);function AG(t){return t.stopPropagation()}function MG(t){return t.stopPropagation()}function FG(t){return t.stopPropagation()}function BG(t){return t.stopPropagation()}function _G(t){return t.stopPropagation()}function EG(t){return t.stopPropagation()}function DG(t){return t.stopPropagation()}function IG(t){return t.stopPropagation()}function TG(t){return t.stopPropagation()}function PG(t){return t.stopPropagation()}const RG=t=>{const e=Fe.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:o,children:a}=t,l=`session-drag:${n}`;let i;e[0]!==r||e[1]!==n||e[2]!==o?(i={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:o},e[0]=r,e[1]=n,e[2]=o,e[3]=i):i=e[3];let c;e[4]!==l||e[5]!==i?(c={id:l,data:i},e[4]=l,e[5]=i,e[6]=c):c=e[6];const{attributes:u,listeners:m,setNodeRef:f,isDragging:h}=Bb(c);let p;e[7]!==m?(p=v=>{v.stopPropagation(),m?.onPointerDown&&m.onPointerDown(v)},e[7]=m,e[8]=p):p=e[8];const g=p,x=h?"opacity-30":void 0;let b;return e[9]!==u||e[10]!==a||e[11]!==g||e[12]!==f||e[13]!==x?(b=s.jsx("div",{ref:f,...u,onPointerDown:g,className:x,children:a}),e[9]=u,e[10]=a,e[11]=g,e[12]=f,e[13]=x,e[14]=b):b=e[14],b},zG=t=>{const e=Fe.c(11),{folderId:n,children:r}=t,o=`folder-drop:${n}`;let a;e[0]!==n?(a={type:"folder",folderId:n},e[0]=n,e[1]=a):a=e[1];let l;e[2]!==o||e[3]!==a?(l={id:o,data:a},e[2]=o,e[3]=a,e[4]=l):l=e[4];const{setNodeRef:i,isOver:c}=Fb(l);let u;e[5]!==r||e[6]!==c||e[7]!==i?(u=r(i,c),e[5]=r,e[6]=c,e[7]=i,e[8]=u):u=e[8];let m;return e[9]!==u?(m=s.jsx(s.Fragment,{children:u}),e[9]=u,e[10]=m):m=e[10],m},LG=t=>{const e=Fe.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:o,children:a}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[0]=l):l=e[0];const i=N1(xl(S1,l)),[c,u]=d.useState(null),[m,f]=d.useState("Session"),[h,p]=d.useState(null),[g,x]=d.useState(null);if(!n){let k;return e[1]!==a?(k=s.jsx(s.Fragment,{children:a}),e[1]=a,e[2]=k):k=e[2],k}let b;e[3]!==o?(b=k=>{u(null),p(null),x(null);const{active:j,over:F}=k;if(!F)return;const A=j.data.current,M=F.data.current;A?.type==="session"&&A.sessionId&&M?.type==="folder"&&M.folderId&&o(A.sessionId,M.folderId)},e[3]=o,e[4]=b):b=e[4];const v=b;let y,w;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=k=>{const j=k.active.data.current;if(j?.type==="session"&&j.sessionId){u(j.sessionId),f(j.sessionTitle??"Session");const F=k.active.rect.current.initial?.width,A=k.active.rect.current.initial?.height;p(typeof F=="number"?F:null),x(typeof A=="number"?A:null)}},w=()=>{u(null),p(null),x(null)},e[5]=y,e[6]=w):(y=e[5],w=e[6]);let C;e[7]!==g||e[8]!==c||e[9]!==m||e[10]!==h||e[11]!==r?(C=c&&r?s.jsxs("div",{style:{width:h?`${h}px`:"auto",height:g?`${g}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(Md,{className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=g,e[8]=c,e[9]=m,e[10]=h,e[11]=r,e[12]=C):C=e[12];let N;e[13]!==C?(N=s.jsx(Q0,{children:C}),e[13]=C,e[14]=N):N=e[14];let S;return e[15]!==a||e[16]!==v||e[17]!==i||e[18]!==N?(S=s.jsxs(C1,{sensors:i,collisionDetection:A1,onDragStart:y,onDragCancel:w,onDragEnd:v,children:[a,N]}),e[15]=a,e[16]=v,e[17]=i,e[18]=N,e[19]=S):S=e[19],S},B2=Dr()(Pl(t=>({displayMode:"default",setDisplayMode:e=>t({displayMode:e})}),{name:"session-display-mode"}));function HG(t){const e=Fe.c(158),{group:n,groupKey:r,projectId:o,hideGroupLabel:a,hasSessionSearchQuery:l,normalizedSessionSearchQuery:i,groupSearchDataByGroup:c,expandedSessionGroups:u,collapsedGroups:m,hideDirectoryControls:f,getFoldersForScope:h,collapsedFolderIds:p,toggleFolderCollapse:g,renameFolder:x,deleteFolder:b,showDeletionDialog:v,setDeleteFolderConfirm:y,renderSessionNode:w,projectRepoStatus:C,lastRepoStatus:N,toggleGroupSessionLimit:S,mobileVariant:k,activeProjectId:j,setActiveProjectIdOnly:F,setActiveMainTab:A,setSessionSwitcherOpen:M,openNewSessionDraft:B,addSessionToFolder:E,createFolderAndStartRename:I,renamingFolderId:P,renameFolderDraft:D,setRenameFolderDraft:L,setRenamingFolderId:T,pinnedSessionIds:_,prVisualStateByDirectoryBranch:z,onToggleCollapsedGroup:R,dragHandleProps:W}=t,G=l?c.get(n):null,J=B2(ZG)==="minimal";let V;e[0]!==u||e[1]!==r?(V=u.has(r),e[0]=u,e[1]=r,e[2]=V):V=e[2];const te=V;let U;e[3]!==m||e[4]!==r||e[5]!==l?(U=l?!1:m.has(r),e[3]=m,e[4]=r,e[5]=l,e[6]=U):U=e[6];const X=U,$=f?10:5,q=l?G?.groupMatches===!0:!1,ce=l?G?.filteredNodes??[]:n.sessions,ve=n.folderScopeKey??nn(n.directory??null),ge=ve?h(ve):[],xe=new Map,ne=Ae=>{Ae.forEach(Xe=>{xe.set(Xe.session.id,Xe),Xe.children.length>0&&ne(Xe.children)})};ne(ce);const O=ge.map(Ae=>{const Xe=Ae.sessionIds.map(yt=>xe.get(yt)).filter(GG).sort((yt,Tt)=>T1(yt.session,Tt.session,_));return{folder:Ae,nodes:Xe}}),H=new Map(O.map(qG)),K=Ae=>{const Xe=H.get(Ae);return Xe?!l||Xe.folder.name.toLowerCase().includes(i)||Xe.nodes.length>0?!0:O.filter(Tt=>{const{folder:Yt}=Tt;return Yt.parentId===Ae}).some(Tt=>{const{folder:Yt}=Tt;return K(Yt.id)}):!1},re=l?O.filter(Ae=>{const{folder:Xe}=Ae;return K(Xe.id)}):O,le=new Set(re.flatMap(WG)),ae=ce.filter(Ae=>!le.has(Ae.session.id)),ue=re.filter(UG);if(l&&!q&&ue.length===0&&ae.length===0)return null;const be=ae.length,oe=n.isArchivedBucket||l||te?ae:ae.slice(0,$),Z=be-oe.length,ie=VG,pe=ie(ce);let me;e[7]!==N||e[8]!==o||e[9]!==C?(me=o&&C.has(o)?!!C.get(o):N,e[7]=N,e[8]=o,e[9]=C,e[10]=me):me=e[10];const Se=me,ke=n.directory??null;let ye;e[11]!==ke?(ye=nn(ke),e[11]=ke,e[12]=ye):ye=e[12];const Ne=ye;let _e;e[13]!==n.branch?(_e=n.branch?.trim()??null,e[13]=n.branch,e[14]=_e):_e=e[14];const de=_e;let we;e[15]!==de||e[16]!==Ne||e[17]!==z?(we=Ne&&de?z.get(`${Ne}::${de}`)??null:null,e[15]=de,e[16]=Ne,e[17]=z,e[18]=we):we=e[18];const je=we,Ce=!!(je&&n.branch),ze=!je&&!n.isMain&&!!n.branch,Ge=je?.visualState??null,Le=je&&je.state==="open"&&je.checks?`${je.checks.success}/${je.checks.total} checks passed`:null;let qe;e[19]!==je?(qe=je&&je.state==="open"&&je.checks?[je.checks.failure>0?`${je.checks.failure} failing`:null,je.checks.pending>0?`${je.checks.pending} pending`:null].filter(OG).join(", "):null,e[19]=je,e[20]=qe):qe=e[20];const rt=qe,st=je&&je.state==="open"?je.mergeableState==="blocked"||je.mergeableState==="dirty"?"Conflicts or blocked":je.mergeableState==="clean"||je.canMerge===!0?"Mergeable":null:null,it=je&&je.state==="open"&&je.mergeableState?`Merge state: ${je.mergeableState}`:null,lt=je?.base??null,He=je?.head??null;let Oe;e:{if(!je){let Ae;e[21]!==n.branch||e[22]!==n.label?(Ae=n.branch&&gj(n.branch,n.label)?{label:n.branch,color:null}:null,e[21]=n.branch,e[22]=n.label,e[23]=Ae):Ae=e[23],Oe=Ae;break e}switch(je.visualState){case"merged":{let Ae;e[24]===Symbol.for("react.memo_cache_sentinel")?(Ae={label:"Merged",color:"var(--pr-merged)"},e[24]=Ae):Ae=e[24],Oe=Ae;break e}case"open":{let Ae;e[25]!==je.canMerge||e[26]!==je.checks?.state||e[27]!==je.mergeableState?(Ae=je.canMerge===!0||je.mergeableState==="clean"||je.checks?.state==="success"?{label:"Ready to merge",color:"var(--pr-open)"}:{label:"PR open",color:"var(--pr-open)"},e[25]=je.canMerge,e[26]=je.checks?.state,e[27]=je.mergeableState,e[28]=Ae):Ae=e[28],Oe=Ae;break e}case"blocked":{const Ae=je.mergeableState==="dirty"?"Merge conflicts":"Merge blocked";let Xe;e[29]!==Ae?(Xe={label:Ae,color:"var(--pr-blocked)"},e[29]=Ae,e[30]=Xe):Xe=e[30],Oe=Xe;break e}case"draft":{let Ae;e[31]===Symbol.for("react.memo_cache_sentinel")?(Ae={label:"Draft PR",color:"var(--pr-draft)"},e[31]=Ae):Ae=e[31],Oe=Ae;break e}case"closed":{let Ae;e[32]===Symbol.for("react.memo_cache_sentinel")?(Ae={label:"Closed",color:"var(--pr-closed)"},e[32]=Ae):Ae=e[32],Oe=Ae;break e}default:Oe=null}}const se=Oe,Pe=se?.color??(Ge?`var(--pr-${Ge})`:void 0);let Ye;e[33]!==je?.url?(Ye=Ae=>{Ae.preventDefault(),Ae.stopPropagation();const Xe=je?.url;Xe&&Xr(Xe)},e[33]=je?.url,e[34]=Ye):Ye=e[34];const We=Ye,xt=(Ae,Xe,yt)=>{const Tt=re.filter(Fs=>{const{folder:ds}=Fs;return ds.parentId===Ae.id}),Yt=Tt.length>0?s.jsx(s.Fragment,{children:Tt.map(Fs=>{const{folder:ds,nodes:es}=Fs;return s.jsx(d.Fragment,{children:xt(ds,es,yt+1)},ds.id)})}):void 0,Ut=Fs=>{const ds=re.find(gs=>{const{folder:Ks}=gs;return Ks.id===Fs})?.nodes??[],es=re.filter(gs=>{const{folder:Ks}=gs;return Ks.parentId===Fs});return[...ie(ds),...es.flatMap(gs=>{const{folder:Ks}=gs;return Ut(Ks.id)})]},Es=n.isArchivedBucket?Ut(Ae.id):[];return s.jsx(zG,{folderId:Ae.id,children:(Fs,ds)=>s.jsx(CG,{folder:Ae,sessions:Xe,subFolderItems:Yt,isCollapsed:l?!1:p.has(Ae.id),onToggle:()=>g(Ae.id),onRename:es=>{ve&&x(ve,Ae.id,es)},onDelete:()=>{if(n.isArchivedBucket){na.requestDelete({sessions:Es,mode:"session"});return}if(!ve)return;if(!v){b(ve,Ae.id);return}const es=re.filter(Ks=>{const{folder:Rs}=Ks;return Rs.parentId===Ae.id}).length,gs=Xe.length;y({scopeKey:ve,folderId:Ae.id,folderName:Ae.name,subFolderCount:es,sessionCount:gs})},renderSessionNode:w,groupDirectory:n.directory,projectId:o,mobileVariant:k,isRenaming:P===Ae.id,renameDraft:P===Ae.id?D:void 0,onRenameDraftChange:es=>L(es),onRenameSave:()=>{const es=D.trim();es&&ve&&x(ve,Ae.id,es),T(null),L("")},onRenameCancel:()=>{T(null),L("")},droppableRef:Fs,isDropTarget:ds,depth:yt,onNewSession:()=>{o&&o!==j&&F(o),A("chat"),k&&M(!1),B({directoryOverride:n.directory,targetFolderId:Ae.id})},onNewSubFolder:yt===0?()=>{ve&&I(ve,Ae.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Ae.id)},et=()=>ue.map(Ae=>{const{folder:Xe,nodes:yt}=Ae;return xt(Xe,yt,0)}),tt=!!(!n.isMain&&n.worktree),ht=k?tt?"pr-14":"pr-7":J?tt?"pr-10 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-10":tt?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",St=LG,Ue=re.length>0,ct=(Ae,Xe)=>{ve&&E(ve,Xe,Ae)},Qe=et();let at;e[35]!==n.directory||e[36]!==n.isArchivedBucket||e[37]!==o||e[38]!==w?(at=Ae=>s.jsx(d.Fragment,{children:w(Ae,0,n.directory,o,n.isArchivedBucket===!0)},Ae.session.id),e[35]=n.directory,e[36]=n.isArchivedBucket,e[37]=o,e[38]=w,e[39]=at):at=e[39];const Nt=oe.map(at);let jt;e[40]!==re||e[41]!==n.isArchivedBucket||e[42]!==be?(jt=be===0&&re.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?"No archived sessions yet.":"No sessions in this workspace yet."}):null,e[40]=re,e[41]=n.isArchivedBucket,e[42]=be,e[43]=jt):jt=e[43];let qt;e[44]!==r||e[45]!==te||e[46]!==Z||e[47]!==S?(qt=Z>0&&!te?s.jsxs("button",{type:"button",onClick:()=>S(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:["Show ",Z," more ",Z===1?"session":"sessions"]}):null,e[44]=r,e[45]=te,e[46]=Z,e[47]=S,e[48]=qt):qt=e[48];let Zt;e[49]!==r||e[50]!==te||e[51]!==$||e[52]!==S||e[53]!==be?(Zt=te&&be>$?s.jsx("button",{type:"button",onClick:()=>S(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:"Show fewer sessions"}):null,e[49]=r,e[50]=te,e[51]=$,e[52]=S,e[53]=be,e[54]=Zt):Zt=e[54];let Pt;e[55]!==St||e[56]!==ve||e[57]!==Ue||e[58]!==ct||e[59]!==Qe||e[60]!==Nt||e[61]!==jt||e[62]!==qt||e[63]!==Zt?(Pt=s.jsxs(St,{scopeKey:ve,hasFolders:Ue,onSessionDroppedOnFolder:ct,children:[Qe,Nt,jt,qt,Zt]}),e[55]=St,e[56]=ve,e[57]=Ue,e[58]=ct,e[59]=Qe,e[60]=Nt,e[61]=jt,e[62]=qt,e[63]=Zt,e[64]=Pt):Pt=e[64];const cs=Pt;if(a){let Ae;return e[65]!==cs?(Ae=s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:"oc-group-body pb-3 pl-4",children:cs})}),e[65]=cs,e[66]=Ae):Ae=e[66],Ae}let ss;e[67]===Symbol.for("react.memo_cache_sentinel")?(ss=Q("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),e[67]=ss):ss=e[67];let Wt;e[68]!==r||e[69]!==R?(Wt=()=>R(r),e[68]=r,e[69]=R,e[70]=Wt):Wt=e[70];let ls;e[71]!==r||e[72]!==R?(ls=Ae=>{(Ae.key==="Enter"||Ae.key===" ")&&(Ae.preventDefault(),R(r))},e[71]=r,e[72]=R,e[73]=ls):ls=e[73];const us=X?`Expand ${n.label}`:`Collapse ${n.label}`,ys=!X,ws=W?.setActivatorNodeRef;let Is;e[74]!==ht?(Is=Q("min-w-0 flex items-start gap-1 pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",ht),e[74]=ht,e[75]=Is):Is=e[75];let bs;e[76]!==W?.listeners?(bs=W?.listeners??{},e[76]=W?.listeners,e[77]=bs):bs=e[77];let Ss;e[78]!==lt||e[79]!==Pe||e[80]!==Le||e[81]!==rt||e[82]!==n.branch||e[83]!==n.isArchivedBucket||e[84]!==n.isMain||e[85]!==n.label||e[86]!==n.worktree||e[87]!==We||e[88]!==He||e[89]!==X||e[90]!==it||e[91]!==st||e[92]!==i||e[93]!==je||e[94]!==Ce?(Ss=Ce&&je?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(on,{className:"h-3.5 w-3.5 shrink-0 group-hover/gh:hidden",style:Pe?{color:Pe}:void 0}),s.jsx("span",{className:"hidden text-muted-foreground group-hover/gh:inline-flex h-3.5 w-3.5 items-center justify-center",children:X?s.jsx(On,{className:"h-3.5 w-3.5"}):s.jsx(Ds,{className:"h-3.5 w-3.5"})})]}),je.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:$G,onClick:We,children:["#",je.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",je.number]})]})}),s.jsx(_t,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[lt||He?s.jsx("div",{className:"text-muted-foreground truncate",children:lt&&He?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:lt}),s.jsx(_3,{className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:He})]}):s.jsx("span",{children:lt??He??""})}):null,it?s.jsx("div",{className:"text-muted-foreground truncate",children:it}):null,st||Le?s.jsxs("div",{className:"text-muted-foreground truncate",children:[st??"",st&&Le?" • ":"",Le??"",rt?` (${rt})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:n.branch})]}):n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 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(E3,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground group-hover/gh:hidden"}),s.jsx("span",{className:"hidden text-muted-foreground group-hover/gh:inline-flex h-3.5 w-3.5 items-center justify-center",children:X?s.jsx(On,{className:"h-3.5 w-3.5"}):s.jsx(Ds,{className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"truncate",children:p1(n.label,i)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 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(on,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground group-hover/gh:hidden",style:Pe?{color:Pe}:void 0}),s.jsx("span",{className:"hidden text-muted-foreground group-hover/gh:inline-flex h-3.5 w-3.5 items-center justify-center",children:X?s.jsx(On,{className:"h-3.5 w-3.5"}):s.jsx(Ds,{className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"truncate",children:p1(n.label,i)})]}):p1(n.label,i),e[78]=lt,e[79]=Pe,e[80]=Le,e[81]=rt,e[82]=n.branch,e[83]=n.isArchivedBucket,e[84]=n.isMain,e[85]=n.label,e[86]=n.worktree,e[87]=We,e[88]=He,e[89]=X,e[90]=it,e[91]=st,e[92]=i,e[93]=je,e[94]=Ce,e[95]=Ss):Ss=e[95];let Cs;e[96]!==Ss?(Cs=s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:Ss}),e[96]=Ss,e[97]=Cs):Cs=e[97];let ut;e[98]!==lt||e[99]!==Pe||e[100]!==Le||e[101]!==rt||e[102]!==n.isArchivedBucket||e[103]!==n.isMain||e[104]!==He||e[105]!==Se||e[106]!==it||e[107]!==st||e[108]!==je||e[109]!==ze||e[110]!==Ce||e[111]!==se?(ut=ze&&se?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(E3,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||Se?Ce&&je?s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(on,{className:"h-3.5 w-3.5 text-muted-foreground",style:Pe?{color:Pe}:void 0})})}),s.jsx(_t,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[lt||He?s.jsx("div",{className:"text-muted-foreground truncate",children:lt&&He?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:lt}),s.jsx(_3,{className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:He})]}):s.jsx("span",{children:lt??He??""})}):null,it?s.jsx("div",{className:"text-muted-foreground truncate",children:it}):null,st||Le?s.jsxs("div",{className:"text-muted-foreground truncate",children:[st??"",st&&Le?" • ":"",Le??"",rt?` (${rt})`:""]}):null]})})]}):s.jsx(on,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Pe?{color:Pe}:void 0}):null,s.jsx("span",{className:Q("min-w-0 truncate text-[11px] font-medium",!se.color&&"text-muted-foreground/80"),style:se.color?{color:se.color}:void 0,children:se.label})]}):null,e[98]=lt,e[99]=Pe,e[100]=Le,e[101]=rt,e[102]=n.isArchivedBucket,e[103]=n.isMain,e[104]=He,e[105]=Se,e[106]=it,e[107]=st,e[108]=je,e[109]=ze,e[110]=Ce,e[111]=se,e[112]=ut):ut=e[112];let Mt;e[113]!==Cs||e[114]!==ut?(Mt=s.jsxs("div",{className:"min-w-0 flex flex-col justify-center gap-0.5",children:[Cs,ut]}),e[113]=Cs,e[114]=ut,e[115]=Mt):Mt=e[115];let Kt;e[116]!==ws||e[117]!==Is||e[118]!==bs||e[119]!==Mt?(Kt=s.jsx("div",{ref:ws,className:Is,...bs,children:Mt}),e[116]=ws,e[117]=Is,e[118]=bs,e[119]=Mt,e[120]=Kt):Kt=e[120];let Ft;e[121]!==pe||e[122]!==n.isArchivedBucket||e[123]!==n.label||e[124]!==k?(Ft=n.isArchivedBucket&&pe.length>0?s.jsx("div",{className:Q("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",k?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ae=>{Ae.stopPropagation(),na.requestDelete({sessions:pe,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":`Delete archived sessions in ${n.label}`,children:s.jsx(Pn,{className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Delete archived sessions"})})]})}):null,e[121]=pe,e[122]=n.isArchivedBucket,e[123]=n.label,e[124]=k,e[125]=Ft):Ft=e[125];let Et;e[126]!==pe||e[127]!==n.directory||e[128]!==n.isMain||e[129]!==n.label||e[130]!==n.worktree||e[131]!==k?(Et=n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:Q("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",k?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ae=>{Ae.stopPropagation(),na.requestDelete({sessions:pe,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":`Delete ${n.label}`,children:s.jsx(Pn,{className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Delete worktree"})})]})}):null,e[126]=pe,e[127]=n.directory,e[128]=n.isMain,e[129]=n.label,e[130]=n.worktree,e[131]=k,e[132]=Et):Et=e[132];let bt;e[133]!==j||e[134]!==n.directory||e[135]!==n.label||e[136]!==k||e[137]!==B||e[138]!==o||e[139]!==A||e[140]!==F||e[141]!==M?(bt=n.directory?s.jsx("div",{className:Q("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",k?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ae=>{Ae.stopPropagation(),o&&o!==j&&F(o),A("chat"),k&&M(!1),B({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":`New draft session in ${n.label}`,children:s.jsx(Qs,{className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"New draft session"})})]})}):null,e[133]=j,e[134]=n.directory,e[135]=n.label,e[136]=k,e[137]=B,e[138]=o,e[139]=A,e[140]=F,e[141]=M,e[142]=bt):bt=e[142];let kt;e[143]!==Wt||e[144]!==ls||e[145]!==us||e[146]!==ys||e[147]!==Kt||e[148]!==Ft||e[149]!==Et||e[150]!==bt?(kt=s.jsxs("div",{className:ss,onClick:Wt,role:"button",tabIndex:0,onKeyDown:ls,"aria-label":us,"aria-expanded":ys,children:[Kt,Ft,Et,bt]}),e[143]=Wt,e[144]=ls,e[145]=us,e[146]=ys,e[147]=Kt,e[148]=Ft,e[149]=Et,e[150]=bt,e[151]=kt):kt=e[151];let as;e[152]!==cs||e[153]!==X?(as=X?null:s.jsx("div",{className:"oc-group-body pb-3 pl-4",children:cs}),e[152]=cs,e[153]=X,e[154]=as):as=e[154];let Gt;return e[155]!==kt||e[156]!==as?(Gt=s.jsxs("div",{className:"oc-group",children:[kt,as]}),e[155]=kt,e[156]=as,e[157]=Gt):Gt=e[157],Gt}function $G(t){return t.stopPropagation()}function OG(t){return!!t}function VG(t){const e=[],n=r=>{r.forEach(o=>{e.push(o.session),o.children.length>0&&n(o.children)})};return n(t),e}function UG(t){const{folder:e}=t;return!e.parentId}function WG(t){return t.folder.sessionIds}function qG(t){return[t.folder.id,t]}function GG(t){return!!t}function ZG(t){return t.displayMode}function KG(t){const e=Fe.c(27),{hideDirectoryControls:n,handleOpenDirectoryDialog:r,handleNewSession:o,useMobileNotesPanel:a,projectNotesPanelOpen:l,setProjectNotesPanelOpen:i,activeProjectRefForHeader:c,activeProjectLabelForHeader:u,canOpenMultiRun:m,openMultiRunLauncher:f,stableActiveProjectIsRepo:h,headerActionIconClass:p,reserveHeaderActionsSpace:g,headerActionButtonClass:x,isSessionSearchOpen:b,setIsSessionSearchOpen:v,sessionSearchInputRef:y,sessionSearchQuery:w,setSessionSearchQuery:C,hasSessionSearchQuery:N,searchMatchCount:S,collapseAllProjects:k,expandAllProjects:j}=t,F=B2(QG),A=B2(XG);if(n)return null;let M;e[0]!==u||e[1]!==c||e[2]!==m||e[3]!==k||e[4]!==F||e[5]!==j||e[6]!==o||e[7]!==r||e[8]!==N||e[9]!==x||e[10]!==p||e[11]!==b||e[12]!==f||e[13]!==l||e[14]!==g||e[15]!==S||e[16]!==y||e[17]!==w||e[18]!==A||e[19]!==v||e[20]!==i||e[21]!==C||e[22]!==h||e[23]!==a?(M=g?s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:x,"aria-label":"Add project",children:s.jsx(Pi,{className:p})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Add project"})})]}),s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:x,"aria-label":"New session",children:s.jsx(F1,{className:p})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"New session"})})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:x,"aria-label":"New multi-run",disabled:!m,children:s.jsx(Ap,{className:p})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"New multi-run"})})]}),a?s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>i(!0),className:x,"aria-label":"Project notes",disabled:!c,children:s.jsx(Md,{className:p})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Project notes"})})]}):s.jsxs(qs,{open:l,onOpenChange:i,modal:!1,children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:x,"aria-label":"Project notes",disabled:!c,children:s.jsx(Md,{className:p})})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Project notes"})})]}),s.jsx(Ys,{align:"start",className:"w-[420px] max-w-[min(92vw,420px)] p-0",children:s.jsx(X7,{projectRef:c,projectLabel:u,canCreateWorktree:h,onActionComplete:()=>i(!1)})})]}),s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>v(YG),className:x,"aria-label":"Search sessions","aria-expanded":b,children:s.jsx(xr,{className:p})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Search sessions"})})]}),s.jsxs(qs,{children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:x,"aria-label":"Session display mode",children:s.jsx(_b,{className:p})})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Display mode"})})]}),s.jsxs(Ys,{align:"end",className:"min-w-[160px]",children:[s.jsxs(Jt,{onClick:()=>A("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:"Default"}),F==="default"?s.jsx(js,{className:"h-4 w-4 text-primary"}):null]}),s.jsxs(Jt,{onClick:()=>A("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:"Minimal"}),F==="minimal"?s.jsx(js,{className:"h-4 w-4 text-primary"}):null]}),s.jsx(Zn,{}),s.jsxs(Jt,{onClick:k,className:"flex items-center gap-2",children:[s.jsx(Eb,{className:"h-4 w-4"}),s.jsx("span",{children:"Collapse all"})]}),s.jsxs(Jt,{onClick:j,className:"flex items-center gap-2",children:[s.jsx(Db,{className:"h-4 w-4"}),s.jsx("span",{children:"Expand all"})]})]})]})]})]}),b?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[N?s.jsxs("span",{children:[S," ",S===1?"match":"matches"]}):s.jsx("span",{}),s.jsx("span",{children:"Esc to clear"})]}),s.jsxs("div",{className:"relative",children:[s.jsx(xr,{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:y,value:w,onChange:E=>C(E.target.value),placeholder:"Search sessions...",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:E=>{E.key==="Escape"&&(E.stopPropagation(),N?C(""):v(!1))}}),w.length>0?s.jsx("button",{type:"button",onClick:()=>C(""),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":"Clear search",children:s.jsx(Ps,{className:"h-3.5 w-3.5"})}):null]})]}):null]}):null,e[0]=u,e[1]=c,e[2]=m,e[3]=k,e[4]=F,e[5]=j,e[6]=o,e[7]=r,e[8]=N,e[9]=x,e[10]=p,e[11]=b,e[12]=f,e[13]=l,e[14]=g,e[15]=S,e[16]=y,e[17]=w,e[18]=A,e[19]=v,e[20]=i,e[21]=C,e[22]=h,e[23]=a,e[24]=M):M=e[24];let B;return e[25]!==M?(B=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:M}),e[25]=M,e[26]=B):B=e[26],B}function YG(t){return!t}function XG(t){return t.setDisplayMode}function QG(t){return t.displayMode}const sh=7;function JG(t){const e=Fe.c(18),{sections:n,renderSessionNode:r}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=new Set,e[0]=o):o=e[0];const[a,l]=d.useState(o);let i;e[1]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[1]=i):i=e[1];const[c,u]=d.useState(i);let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=y=>{l(w=>{const C=new Set(w);return C.has(y)?C.delete(y):C.add(y),C})},e[2]=m):m=e[2];const f=m;let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h=y=>{u(w=>{const C=new Set(w);return C.has(y)?C.delete(y):C.add(y),C})},e[3]=h):h=e[3];const p=h;let g,x,b;if(e[4]!==a||e[5]!==c||e[6]!==r||e[7]!==n){b=Symbol.for("react.early_return_sentinel");e:{const y=n.filter(eZ);if(y.length===0){b=null;break e}g="space-y-2 pb-2 pt-1";let w;e[11]!==a||e[12]!==c||e[13]!==r?(w=C=>{const N=a.has(C.key),S=c.has(C.key),k=S?C.items:C.items.slice(0,sh),j=C.items.length-k.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>f(C.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!N,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:N?s.jsx(On,{className:"h-3.5 w-3.5"}):s.jsx(Ds,{className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:C.title})]}),N?null:s.jsxs("div",{className:Q("space-y-0.5 pl-7"),children:[k.map(F=>r(F.node,0,F.groupDirectory,F.projectId,!1,F.secondaryMeta,"recent")),j>0&&!S?s.jsxs("button",{type:"button",onClick:()=>p(C.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:["Show ",j," more ",j===1?"session":"sessions"]}):null,S&&C.items.length>sh?s.jsx("button",{type:"button",onClick:()=>p(C.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:"Show fewer sessions"}):null]})]},C.key)},e[11]=a,e[12]=c,e[13]=r,e[14]=w):w=e[14],x=y.map(w)}e[4]=a,e[5]=c,e[6]=r,e[7]=n,e[8]=g,e[9]=x,e[10]=b}else g=e[8],x=e[9],b=e[10];if(b!==Symbol.for("react.early_return_sentinel"))return b;let v;return e[15]!==g||e[16]!==x?(v=s.jsx("div",{className:g,children:x}),e[15]=g,e[16]=x,e[17]=v):v=e[17],v}function eZ(t){return t.items.length>0}const pd="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 tZ(t){const e=Fe.c(11),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:o,onOpenUpdate:a,showRuntimeButtons:l,showUpdateButton:i}=t,c=l===void 0?!0:l,u=i===void 0?!0:i;let m;e[0]!==o||e[1]!==n||e[2]!==r||e[3]!==c?(m=c?s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:pd,"aria-label":"Settings",children:s.jsx(xa,{className:"h-4.5 w-4.5"})})}),s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:"Settings"})})]}),s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:pd,"aria-label":"Shortcuts",children:s.jsx(Bl,{className:"h-4.5 w-4.5"})})}),s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:"Shortcuts"})})]}),s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:pd,"aria-label":"About ArchCoder",children:s.jsx(Fn,{className:"h-4.5 w-4.5"})})}),s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:"About ArchCoder"})})]})]}):null,e[0]=o,e[1]=n,e[2]=r,e[3]=c,e[4]=m):m=e[4];let f;e[5]!==a||e[6]!==u?(f=u?s.jsx(Be,{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)]",onClick:a,children:"Update"}):null,e[5]=a,e[6]=u,e[7]=f):f=e[7];let h;return e[8]!==m||e[9]!==f?(h=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[m,f]}),e[8]=m,e[9]=f,e[10]=h):h=e[10],h}const sZ=t=>{const e=Fe.c(59),{id:n,projectLabel:r,projectDescription:o,projectIcon:a,projectColor:l,projectIconImage:i,projectIconBackground:c,isCollapsed:u,isActiveProject:m,isHovered:f,isRepo:h,isDesktopShell:p,isStuck:g,hideDirectoryControls:x,mobileVariant:b,onToggle:v,onHoverChange:y,onNewSession:w,onNewWorktreeSession:C,onRenameStart:N,onClose:S,sentinelRef:k,children:j,showCreateButtons:F,hideHeader:A,openSidebarMenuKey:M,setOpenSidebarMenuKey:B}=t,E=F===void 0?!0:F,I=A===void 0?!1:A,{currentTheme:P}=qn();let D;e[0]!==n?(D={id:n},e[0]=n,e[1]=D):D=e[1];const{attributes:L,listeners:T,setNodeRef:_,transform:z,transition:R,isDragging:W}=E2(D),[G,Y]=d.useState(!1),J=d.useRef(!1),V=`project:${n}`,te=M===V;let U;e[2]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{Y(!1)},e[2]=U):U=e[2];const X=i?.updatedAt;let $;e[3]!==n||e[4]!==X?($=[n,X],e[3]=n,e[4]=X,e[5]=$):$=e[5],d.useEffect(U,$);const q=a?Hl[a]:null,ee=l?ja[l]??null:null;let ce;e[6]!==P||e[7]!==n||e[8]!==G||e[9]!==i?(ce=G?null:ka({id:n,iconImage:i},{themeVariant:P.metadata.variant,iconColor:P.colors.surface.foreground}),e[6]=P,e[7]=n,e[8]=G,e[9]=i,e[10]=ce):ce=e[10];const ve=ce;let ge;e[11]!==V||e[12]!==B?(ge=ie=>{B(ie?V:null)},e[11]=V,e[12]=B,e[13]=ge):ge=e[13];const xe=ge,ne=oZ;let O;e[14]===Symbol.for("react.memo_cache_sentinel")?(O=ie=>{(ie.button===2||ie.button===0&&ie.ctrlKey)&&(J.current=!0)},e[14]=O):O=e[14];const H=O;let K;e[15]!==v?(K=()=>{if(J.current){J.current=!1;return}v()},e[15]=v,e[16]=K):K=e[16];const re=K;let le;e[17]!==z?(le=D2.Transform.toString(z),e[17]=z,e[18]=le):le=e[18];let ae;e[19]!==le||e[20]!==R?(ae={transform:le,transition:R},e[19]=le,e[20]=R,e[21]=ae):ae=e[21];const ue=W&&"opacity-30";let be;e[22]!==ue?(be=Q("relative",ue),e[22]=ue,e[23]=be):be=e[23];let oe;e[24]!==q||e[25]!==L||e[26]!==xe||e[27]!==re||e[28]!==x||e[29]!==I||e[30]!==ee||e[31]!==n||e[32]!==ve||e[33]!==m||e[34]!==u||e[35]!==p||e[36]!==f||e[37]!==te||e[38]!==h||e[39]!==g||e[40]!==T||e[41]!==b||e[42]!==S||e[43]!==y||e[44]!==w||e[45]!==C||e[46]!==N||e[47]!==o||e[48]!==c||e[49]!==r||e[50]!==k||e[51]!==E?(oe=I?null:s.jsxs(s.Fragment,{children:[p&&s.jsx("div",{ref:k,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:Q("w-full text-left group/project select-none"),style:{backgroundColor:p&&g?"transparent":void 0},onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",...L,children:[s.jsxs(Dt,{delayDuration:1500,children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:H,onClick:re,...T,className:Q("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]",h&&!x?b||f?"pr-20":"pr-7":b||f?"pr-14":"pr-7"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:Q("hidden text-muted-foreground h-3.5 w-3.5 items-center justify-center",f&&"inline-flex"),children:u?s.jsx(On,{className:"h-3.5 w-3.5"}):s.jsx(Ds,{className:"h-3.5 w-3.5"})}),ve?s.jsx("span",{className:Q("inline-flex h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",f&&"hidden"),style:c?{backgroundColor:c}:void 0,children:s.jsx("img",{src:ve,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>Y(!0)})}):q?s.jsx(q,{className:Q("h-3.5 w-3.5",f&&"hidden"),style:ee?{color:ee}:void 0}):s.jsx(jr,{className:Q("h-3.5 w-3.5 text-muted-foreground/80",f&&"hidden"),style:ee?{color:ee}:void 0})]}),s.jsx("span",{className:Q("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(_t,{side:"right",sideOffset:8,children:o})]}),s.jsxs("div",{className:Q("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",E?"right-7":"right-0.5"),children:[E&&h&&!x&&C?s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),C()},className:Q("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||f?"opacity-100":"opacity-0 pointer-events-none"),"aria-label":"New worktree",children:s.jsx(Ib,{className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"New worktree..."})})]}):null,s.jsxs(qs,{open:te,onOpenChange:xe,children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:Q("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",te?"opacity-100 pointer-events-auto":b||f?"opacity-100":"opacity-0 pointer-events-none"),"aria-label":"Project menu",onClick:ne,children:s.jsx(Qr,{className:"h-3.5 w-3.5"})})}),s.jsxs(Ys,{align:"end",className:"min-w-[180px]",children:[E&&!h&&!x&&w&&s.jsxs(Jt,{onClick:w,children:[s.jsx(Qs,{className:"mr-1.5 h-4 w-4"}),"New Session"]}),s.jsxs(Jt,{onClick:N,children:[s.jsx(_o,{className:"mr-1.5 h-4 w-4"}),"Rename"]}),s.jsxs(Jt,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(Ps,{className:"mr-1.5 h-4 w-4"}),"Close Project"]})]})]})]}),E&&w?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),w()},className:Q("h-6 w-6 rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",b||f?"inline-flex items-center justify-center":"hidden"),"aria-label":h?"New draft session":"New session",children:s.jsx(Qs,{className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:h?"New draft session":"New session"})})]})}):null]})})]}),e[24]=q,e[25]=L,e[26]=xe,e[27]=re,e[28]=x,e[29]=I,e[30]=ee,e[31]=n,e[32]=ve,e[33]=m,e[34]=u,e[35]=p,e[36]=f,e[37]=te,e[38]=h,e[39]=g,e[40]=T,e[41]=b,e[42]=S,e[43]=y,e[44]=w,e[45]=C,e[46]=N,e[47]=o,e[48]=c,e[49]=r,e[50]=k,e[51]=E,e[52]=oe):oe=e[52];let Z;return e[53]!==j||e[54]!==_||e[55]!==ae||e[56]!==be||e[57]!==oe?(Z=s.jsxs("div",{ref:_,style:ae,className:be,children:[oe,j]}),e[53]=j,e[54]=_,e[55]=ae,e[56]=be,e[57]=oe,e[58]=Z):Z=e[58],Z},nZ=t=>{const e=Fe.c(21),{id:n,disabled:r,children:o}=t,a=r===void 0?!1:r;let l;e[0]!==a||e[1]!==n?(l={id:n,disabled:a},e[0]=a,e[1]=n,e[2]=l):l=e[2];const{listeners:i,setNodeRef:c,setActivatorNodeRef:u,transform:m,transition:f,isDragging:h}=E2(l);let p;e[3]!==i||e[4]!==u?(p={listeners:i,setActivatorNodeRef:u},e[3]=i,e[4]=u,e[5]=p):p=e[5];const g=p;let x;e[6]!==m?(x=D2.Transform.toString(m),e[6]=m,e[7]=x):x=e[7];let b;e[8]!==x||e[9]!==f?(b={transform:x,transition:f},e[8]=x,e[9]=f,e[10]=b):b=e[10];const v=h&&"opacity-50";let y;e[11]!==v?(y=Q("space-y-0.5 rounded-md",v),e[11]=v,e[12]=y):y=e[12];let w;e[13]!==o||e[14]!==g?(w=typeof o=="function"?o(g):o,e[13]=o,e[14]=g,e[15]=w):w=e[15];let C;return e[16]!==c||e[17]!==b||e[18]!==y||e[19]!==w?(C=s.jsx("div",{ref:c,style:b,className:y,children:w}),e[16]=c,e[17]=b,e[18]=y,e[19]=w,e[20]=C):C=e[20],C},rZ=d.memo(nZ);function oZ(t){t.stopPropagation()}function aZ(t){const e=Fe.c(24);let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={activationConstraint:{distance:8}},e[0]=n):n=e[0];let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r={coordinateGetter:Th},e[1]=r):r=e[1];const o=N1(xl(S1,n),xl(Ih,r));let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={activationConstraint:{distance:8}},e[2]=a):a=e[2];const l=N1(xl(S1,a));if(t.projectSections.length===0){const f=(t.mobileVariant,"");let h;e[3]!==f?(h=Q("space-y-1 pb-1 pl-2.5 pr-2",f),e[3]=f,e[4]=h):h=e[4];let p;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==h?(p=s.jsxs(ks,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:h,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=h,e[8]=p):p=e[8],p}if(t.sectionsForRender.length===0){const f=(t.mobileVariant,"");let h;e[9]!==f?(h=Q("space-y-1 pb-1 pl-2.5 pr-2",f),e[9]=f,e[10]=h):h=e[10];let p;return e[11]!==t.searchEmptyState||e[12]!==h?(p=s.jsx(ks,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:h,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=h,e[13]=p):p=e[13],p}const i=(t.mobileVariant,"");let c;e[14]!==i?(c=Q("space-y-1 pb-1 pl-2.5 pr-2",i),e[14]=i,e[15]=c):c=e[15];let u;e[16]!==l||e[17]!==o||e[18]!==t?(u=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const f=t.sectionsForRender.find(x=>x.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!f)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const h=f.groups.find(hZ)??f.groups.find(mZ)??f.groups.find(fZ)??f.groups[0];if(!h)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:"No sessions yet."});const p=f.groups.find(uZ);return[h,...p&&p.id!==h.id?[p]:[]].map(x=>{const b=`${f.project.id}:${x.id}`,v=x.id===h.id;return s.jsx(d.Fragment,{children:t.renderGroupSessions(x,b,f.project.id,v)},b)})})()}):s.jsx(s.Fragment,{children:s.jsxs(C1,{sensors:o,collisionDetection:A1,onDragEnd:f=>{if(t.isInlineEditing)return;const{active:h,over:p}=f;if(!p||h.id===p.id)return;const g=t.sectionsForRender.findIndex(b=>b.project.id===h.id),x=t.sectionsForRender.findIndex(b=>b.project.id===p.id);g===-1||x===-1||g===x||t.reorderProjects(g,x)},children:[s.jsx(X0,{items:t.sectionsForRender.map(dZ),strategy:jd,children:t.sectionsForRender.map(f=>{const h=f.project,p=h.id,g=u8(h.label?.trim()||Or(h.normalizedPath,t.homeDirectory)||h.normalizedPath),x=va(h.normalizedPath,t.homeDirectory),b=t.collapsedProjects.has(p),v=p===t.activeProjectId,y=t.hoveredProjectId===p,w=t.projectRepoStatus.get(p),C=t.getOrderedGroups(p,f.groups),N=C.find(cZ)??null,S=N?C.filter(k=>k.id!==N.id):C;return s.jsx(sZ,{id:p,projectLabel:g,projectDescription:x,projectIcon:h.icon,projectColor:h.color,projectIconImage:h.iconImage,projectIconBackground:h.iconBackground,isCollapsed:b,isActiveProject:v,isHovered:y,isRepo:!!w,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(p),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,onToggle:()=>t.toggleProject(p),onHoverChange:k=>t.setHoveredProjectId(k?p:null),onNewSession:()=>{p!==t.activeProjectId&&t.setActiveProjectIdOnly(p),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:h.normalizedPath})},onNewWorktreeSession:()=>{p!==t.activeProjectId&&t.setActiveProjectIdOnly(p),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(p),onClose:()=>t.removeProject(p),sentinelRef:k=>{t.projectHeaderSentinelRefs.current.set(p,k)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:b?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:f.groups.length>0?s.jsxs(C1,{sensors:l,collisionDetection:A1,onDragEnd:k=>{if(t.isInlineEditing)return;const{active:j,over:F}=k;if(!F||j.id===F.id)return;const A=S.findIndex(I=>I.id===j.id),M=S.findIndex(I=>I.id===F.id);if(A===-1||M===-1||A===M)return;const B=T0(S,A,M).map(iZ),E=N?[N.id,...B]:B;t.setGroupOrderByProject(I=>{const P=new Map(I);return P.set(p,E),P})},children:[N?t.renderGroupSessions(N,`${p}:${N.id}`,p,!0):null,s.jsx(X0,{items:S.map(lZ),strategy:jd,children:S.map(k=>{const j=`${p}:${k.id}`;return s.jsx(rZ,{id:k.id,disabled:t.isInlineEditing,children:F=>t.renderGroupSessions(k,j,p,!1,F)},k.id)})}),s.jsx(Q0,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:"No sessions yet."})})},p)})}),s.jsx(Q0,{dropAnimation:null})]})}),e[16]=l,e[17]=o,e[18]=t,e[19]=u):u=e[19];let m;return e[20]!==t.topContent||e[21]!==c||e[22]!==u?(m=s.jsxs(ks,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:c,children:[t.topContent,u]}),e[20]=t.topContent,e[21]=c,e[22]=u,e[23]=m):m=e[23],m}function lZ(t){return t.id}function iZ(t){return t.id}function cZ(t){return t.isMain}function dZ(t){return t.project.id}function uZ(t){return t.isArchivedBucket}function fZ(t){return t.isMain}function mZ(t){return t.sessions.length>0}function hZ(t){return t.isMain&&t.sessions.length>0}const pZ=new Set([1,3,4,5,7]),gZ=t=>t===4?"0ms":"130ms";function xZ(t){const e=Fe.c(276),{node:n,depth:r,groupDirectory:o,projectId:a,archivedBucket:l,directoryStatus:i,sessionMemoryState:c,currentSessionId:u,pinnedSessionIds:m,expandedParents:f,hasSessionSearchQuery:h,normalizedSessionSearchQuery:p,sessionAttentionStates:g,notifyOnSubtasks:x,sessionStatus:b,permissions:v,editingId:y,setEditingId:w,editTitle:C,setEditTitle:N,handleSaveEdit:S,handleCancelEdit:k,toggleParent:j,handleSessionSelect:F,handleSessionDoubleClick:A,togglePinnedSession:M,handleShareSession:B,copiedSessionId:E,handleCopyShareUrl:I,handleUnshareSession:P,openSidebarMenuKey:D,setOpenSidebarMenuKey:L,renamingFolderId:T,getFoldersForScope:_,getSessionFolderId:z,removeSessionFromFolder:R,addSessionToFolder:W,createFolderAndStartRename:G,openContextPanelTab:Y,handleDeleteSession:J,mobileVariant:V,renderSessionNode:te,secondaryMeta:U,renderContext:X}=t,$=r===void 0?0:r,q=l===void 0?!1:l,ee=X===void 0?"project":X,ce=!!U?.projectLabel,ve=!!U?.branchLabel,xe=B2(jZ)==="minimal";let ne;e[0]===Symbol.for("react.memo_cache_sentinel")?(ne=xn(),e[0]=ne):ne=e[0];const O=ne,H=d.useRef(!1),K=n.session,re=`${ee}:${q?"archived":"active"}:${K.id}`;let le,ae,ue,be,oe,Z,ie,pe,me,Se,ke,ye,Ne,_e,de,we,je,Ce,ze,Ge,Le,qe,rt,st,it,lt,He,Oe,se;if(e[1]!==W||e[2]!==q||e[3]!==E||e[4]!==G||e[5]!==u||e[6]!==$||e[7]!==i||e[8]!==C||e[9]!==y||e[10]!==f||e[11]!==_||e[12]!==z||e[13]!==o||e[14]!==k||e[15]!==I||e[16]!==S||e[17]!==F||e[18]!==B||e[19]!==P||e[20]!==ve||e[21]!==ce||e[22]!==h||e[23]!==xe||e[24]!==re||e[25]!==n.children.length||e[26]!==x||e[27]!==D||e[28]!==v||e[29]!==m||e[30]!==a||e[31]!==R||e[32]!==T||e[33]!==U?.branchLabel||e[34]!==U?.projectLabel||e[35]!==K||e[36]!==g||e[37]!==c||e[38]!==b||e[39]!==N||e[40]!==w||e[41]!==L||e[42]!==j||e[43]!==M){rt=Symbol.for("react.early_return_sentinel");e:{je=nn(K.directory??null)??nn(o??null),ke=(je?i.get(je):null)==="missing";let ys;e[73]!==K.id||e[74]!==c?(ys=c.get(K.id),e[73]=K.id,e[74]=c,e[75]=ys):ys=e[75];const ws=ys;pe=u===K.id,Ce=K.title||"Untitled Session",Z=n.children.length>0;let Is;e[76]!==m||e[77]!==K.id?(Is=m.has(K.id),e[76]=m,e[77]=K.id,e[78]=Is):Is=e[78],ye=Is;let bs;e[79]!==f||e[80]!==h||e[81]!==K.id?(bs=h?!0:f.has(K.id),e[79]=f,e[80]=h,e[81]=K.id,e[82]=bs):bs=e[82],me=bs;const Ss=!!K.parentID;let Cs;e[83]!==K.id||e[84]!==g?(Cs=g.get(K.id)?.needsAttention,e[83]=K.id,e[84]=g,e[85]=Cs):Cs=e[85];const Mt=Cs===!0&&(!Ss||x),Kt=K.summary;let Ft;e[86]!==Kt?(Ft=d8(Kt),e[86]=Kt,e[87]=Ft):Ft=e[87],we=Ft;let Et;e[88]!==K.time?.created||e[89]!==K.time?.updated?(Et=K.time?.updated||K.time?.created||Date.now(),e[88]=K.time?.created,e[89]=K.time?.updated,e[90]=Et):Et=e[90];const bt=Et;let kt;e[91]!==bt?(kt=hj(bt),e[91]=bt,e[92]=kt):kt=e[92],ze=kt;let as;if(e[93]!==bt?(as=pj(bt),e[93]=bt,e[94]=as):as=e[94],de=as,Se=D===re,y===K.id){const Ve=K.id,ft=$>0&&"pl-[20px]";let Bt;e[95]!==ft?(Bt=Q("group relative flex items-center rounded-sm px-1.5 py-1",ft),e[95]=ft,e[96]=Bt):Bt=e[96];let At;e[97]!==S?(At=zs=>{zs.preventDefault(),S()},e[97]=S,e[98]=At):At=e[98];let mt;e[99]!==N?(mt=zs=>N(zs.target.value),e[99]=N,e[100]=mt):mt=e[100];let Lt;e[101]!==k?(Lt=zs=>{if(zs.key==="Escape"){zs.stopPropagation(),k();return}(zs.key===" "||zs.key==="Enter")&&zs.stopPropagation()},e[101]=k,e[102]=Lt):Lt=e[102];let $t;e[103]!==C||e[104]!==mt||e[105]!==Lt?($t=s.jsx("input",{value:C,onChange:mt,className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:"Rename session",onKeyDown:Lt}),e[103]=C,e[104]=mt,e[105]=Lt,e[106]=$t):$t=e[106];let Xs;e[107]===Symbol.for("react.memo_cache_sentinel")?(Xs=s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(js,{className:"size-4"})}),e[107]=Xs):Xs=e[107];let As;e[108]===Symbol.for("react.memo_cache_sentinel")?(As=s.jsx(Ps,{className:"size-4"}),e[108]=As):As=e[108];let Ot;e[109]!==k?(Ot=s.jsx("button",{type:"button",onClick:k,className:"shrink-0 text-muted-foreground hover:text-foreground",children:As}),e[109]=k,e[110]=Ot):Ot=e[110];let fs;e[111]!==At||e[112]!==$t||e[113]!==Ot?(fs=s.jsxs("form",{className:"flex w-full items-center gap-2","data-keyboard-avoid":"true",onSubmit:At,children:[$t,Xs,Ot]}),e[111]=At,e[112]=$t,e[113]=Ot,e[114]=fs):fs=e[114];let ms;e[115]!==Z||e[116]!==ve||e[117]!==ce||e[118]!==me||e[119]!==xe||e[120]!==U?.branchLabel||e[121]!==U?.projectLabel||e[122]!==we||e[123]!==ze?(ms=xe?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[Z?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:me?s.jsx(Ds,{className:"h-3 w-3"}):s.jsx(On,{className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:ze}),we?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",we.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",we.deletions]})]}):null,ce?s.jsx("span",{className:"truncate",children:U?.projectLabel}):null,ve?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(on,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:U?.branchLabel})]}):null]})}),e[115]=Z,e[116]=ve,e[117]=ce,e[118]=me,e[119]=xe,e[120]=U?.branchLabel,e[121]=U?.projectLabel,e[122]=we,e[123]=ze,e[124]=ms):ms=e[124];let Hs;e[125]!==fs||e[126]!==ms?(Hs=s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[fs,ms]}),e[125]=fs,e[126]=ms,e[127]=Hs):Hs=e[127];let rn;e[128]!==K.id||e[129]!==Bt||e[130]!==Hs?(rn=s.jsx("div",{className:Bt,children:Hs},Ve),e[128]=K.id,e[129]=Bt,e[130]=Hs,e[131]=rn):rn=e[131],rt=rn;break e}let Gt;e[132]!==K.id||e[133]!==b?(Gt=b?.get(K.id)?.type??"idle",e[132]=K.id,e[133]=b,e[134]=Gt):Gt=e[134];const Ae=Gt,Xe=Ae==="busy"||Ae==="retry";let yt;e[135]!==v||e[136]!==K.id?(yt=v.get(K.id)?.length??0,e[135]=v,e[136]=K.id,e[137]=yt):yt=e[137],_e=yt;const Yt=Xe||!Xe&&Mt&&!pe;let Ut;e[138]!==Xe?(Ut=Xe?s.jsx(h3,{size:"xs",className:"text-primary"}):s.jsx("span",{className:"grid grid-cols-3 gap-[1px] text-[var(--status-info)]","aria-label":"Unread updates",title:"Unread updates",children:Array.from({length:9},wZ)}),e[138]=Xe,e[139]=Ut):Ut=e[139];const Es=Ut;let Fs;e[140]!==xe||e[141]!==Yt||e[142]!==Es?(Fs=!xe&&Yt?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:Es}):null,e[140]=xe,e[141]=Yt,e[142]=Es,e[143]=Fs):Fs=e[143],ie=Fs;let ds;e[144]!==Z||e[145]!==xe||e[146]!==Yt||e[147]!==Es?(ds=xe&&Yt?s.jsx("span",{className:Q("pointer-events-none absolute left-[-10px] top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center transition-opacity",Z?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:Es}):null,e[144]=Z,e[145]=xe,e[146]=Yt,e[147]=Es,e[148]=ds):ds=e[148],Ne=ds;let es;e[149]!==Z||e[150]!==me||e[151]!==xe||e[152]!==K.id||e[153]!==Yt||e[154]!==j?(es=Z?s.jsx("span",{role:"button",tabIndex:0,onClick:Ve=>{Ve.stopPropagation(),j(K.id)},onKeyDown:Ve=>{(Ve.key==="Enter"||Ve.key===" ")&&(Ve.preventDefault(),Ve.stopPropagation(),j(K.id))},className:Q("absolute left-[-10px] 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",xe&&Yt?"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":me?"Collapse subsessions":"Expand subsessions",children:me?s.jsx(Ds,{className:"h-3 w-3"}):s.jsx(On,{className:"h-3 w-3"})}):null,e[149]=Z,e[150]=me,e[151]=xe,e[152]=K.id,e[153]=Yt,e[154]=j,e[155]=es):es=e[155],Le=es;let gs;e[156]!==ws?.isZombie?(gs=ws?.isZombie?s.jsx(ba,{className:"h-4 w-4 text-status-warning"}):null,e[156]=ws?.isZombie,e[157]=gs):gs=e[157],Ge=gs;let Ks;e[158]!==re||e[159]!==L?(Ks=Ve=>{L(Ve?re:null)},e[158]=re,e[159]=L,e[160]=Ks):Ks=e[160],ae=Ks,ue=yZ,oe=()=>{if(H.current){H.current=!1;return}F(K.id,je,ke,a)};let Rs;e[161]===Symbol.for("react.memo_cache_sentinel")?(Rs=Ve=>{(Ve.button===2||Ve.button===0&&Ve.ctrlKey)&&(H.current=!0)},e[161]=Rs):Rs=e[161],be=Rs,le=Ys,st="end",it="min-w-[180px]",e[162]!==T?(lt=Ve=>{T&&Ve.preventDefault()},e[162]=T,e[163]=lt):lt=e[163];let un;e[164]!==K.id||e[165]!==Ce||e[166]!==N||e[167]!==w?(un=()=>{w(K.id),N(Ce)},e[164]=K.id,e[165]=Ce,e[166]=N,e[167]=w,e[168]=un):un=e[168];let zn;e[169]===Symbol.for("react.memo_cache_sentinel")?(zn=s.jsx(_o,{className:"mr-1 h-4 w-4"}),e[169]=zn):zn=e[169],e[170]!==un?(He=s.jsxs(Jt,{onClick:un,className:"[&>svg]:mr-1",children:[zn,"Rename"]}),e[170]=un,e[171]=He):He=e[171];let Te;e[172]!==K.id||e[173]!==M?(Te=()=>M(K.id),e[172]=K.id,e[173]=M,e[174]=Te):Te=e[174];let Ie;e[175]!==ye?(Ie=ye?s.jsx(Rb,{className:"mr-1 h-4 w-4"}):s.jsx(z0,{className:"mr-1 h-4 w-4"}),e[175]=ye,e[176]=Ie):Ie=e[176];const Ke=ye?"Unpin session":"Pin session";e[177]!==Te||e[178]!==Ie||e[179]!==Ke?(Oe=s.jsxs(Jt,{onClick:Te,className:"[&>svg]:mr-1",children:[Ie,Ke]}),e[177]=Te,e[178]=Ie,e[179]=Ke,e[180]=Oe):Oe=e[180],e[181]!==E||e[182]!==I||e[183]!==B||e[184]!==P||e[185]!==K?(se=K.share?s.jsxs(s.Fragment,{children:[s.jsx(Jt,{onClick:()=>{K.share?.url&&I(K.share.url,K.id)},className:"[&>svg]:mr-1",children:E===K.id?s.jsxs(s.Fragment,{children:[s.jsx(js,{className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),"Copied"]}):s.jsxs(s.Fragment,{children:[s.jsx(nr,{className:"mr-1 h-4 w-4"}),"Copy link"]})}),s.jsxs(Jt,{onClick:()=>P(K.id),className:"[&>svg]:mr-1",children:[s.jsx(Pb,{className:"mr-1 h-4 w-4"}),"Unshare"]})]}):s.jsxs(Jt,{onClick:()=>B(K),className:"[&>svg]:mr-1",children:[s.jsx(Tb,{className:"mr-1 h-4 w-4"}),"Share"]}),e[181]=E,e[182]=I,e[183]=B,e[184]=P,e[185]=K,e[186]=se):se=e[186],qe=je&&!q?(()=>{const Ve=_(je),ft=z(je,K.id);return s.jsxs(s.Fragment,{children:[s.jsx(Zn,{}),s.jsxs(Ev,{children:[s.jsxs(Dv,{className:"[&>svg]:mr-1",children:[s.jsx(jr,{className:"h-4 w-4"}),"Move to folder"]}),s.jsxs(Iv,{className:"min-w-[180px]",children:[Ve.length===0?s.jsx(Jt,{disabled:!0,className:"text-muted-foreground",children:"No folders yet"}):Ve.map(Bt=>s.jsxs(Jt,{onClick:()=>{ft===Bt.id?R(je,K.id):W(je,Bt.id,K.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:Bt.name}),ft===Bt.id?s.jsx(js,{className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},Bt.id)),s.jsx(Zn,{}),s.jsxs(Jt,{onClick:()=>{const Bt=G(je);Bt&&W(je,Bt.id,K.id)},children:[s.jsx(Qs,{className:"mr-1 h-4 w-4"}),"New folder..."]}),ft?s.jsxs(Jt,{onClick:()=>{R(je,K.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(Ps,{className:"mr-1 h-4 w-4"}),"Remove from folder"]}):null]})]})]})})():null}e[1]=W,e[2]=q,e[3]=E,e[4]=G,e[5]=u,e[6]=$,e[7]=i,e[8]=C,e[9]=y,e[10]=f,e[11]=_,e[12]=z,e[13]=o,e[14]=k,e[15]=I,e[16]=S,e[17]=F,e[18]=B,e[19]=P,e[20]=ve,e[21]=ce,e[22]=h,e[23]=xe,e[24]=re,e[25]=n.children.length,e[26]=x,e[27]=D,e[28]=v,e[29]=m,e[30]=a,e[31]=R,e[32]=T,e[33]=U?.branchLabel,e[34]=U?.projectLabel,e[35]=K,e[36]=g,e[37]=c,e[38]=b,e[39]=N,e[40]=w,e[41]=L,e[42]=j,e[43]=M,e[44]=le,e[45]=ae,e[46]=ue,e[47]=be,e[48]=oe,e[49]=Z,e[50]=ie,e[51]=pe,e[52]=me,e[53]=Se,e[54]=ke,e[55]=ye,e[56]=Ne,e[57]=_e,e[58]=de,e[59]=we,e[60]=je,e[61]=Ce,e[62]=ze,e[63]=Ge,e[64]=Le,e[65]=qe,e[66]=rt,e[67]=st,e[68]=it,e[69]=lt,e[70]=He,e[71]=Oe,e[72]=se}else le=e[44],ae=e[45],ue=e[46],be=e[47],oe=e[48],Z=e[49],ie=e[50],pe=e[51],me=e[52],Se=e[53],ke=e[54],ye=e[55],Ne=e[56],_e=e[57],de=e[58],we=e[59],je=e[60],Ce=e[61],ze=e[62],Ge=e[63],Le=e[64],qe=e[65],rt=e[66],st=e[67],it=e[68],lt=e[69],He=e[70],Oe=e[71],se=e[72];if(rt!==Symbol.for("react.early_return_sentinel"))return rt;let Pe;e[187]!==Y||e[188]!==K.id||e[189]!==je||e[190]!==Ce?(Pe=O?null:s.jsxs(Jt,{disabled:!je,onClick:()=>{je&&Y(je,{mode:"chat",dedupeKey:`session:${K.id}`,label:Ce})},className:"[&>svg]:mr-1",children:[s.jsx(I2,{className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:"Open in Side Panel"}),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:"beta"})]}),e[187]=Y,e[188]=K.id,e[189]=je,e[190]=Ce,e[191]=Pe):Pe=e[191];let Ye;e[192]===Symbol.for("react.memo_cache_sentinel")?(Ye=s.jsx(Zn,{}),e[192]=Ye):Ye=e[192];let We;e[193]!==q||e[194]!==J||e[195]!==K?(We=()=>J(K,{archivedBucket:q}),e[193]=q,e[194]=J,e[195]=K,e[196]=We):We=e[196];let xt;e[197]===Symbol.for("react.memo_cache_sentinel")?(xt=s.jsx(Pn,{className:"mr-1 h-4 w-4"}),e[197]=xt):xt=e[197];const et=q?"Delete":"Archive";let tt;e[198]!==We||e[199]!==et?(tt=s.jsxs(Jt,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:We,children:[xt,et]}),e[198]=We,e[199]=et,e[200]=tt):tt=e[200];let ht;e[201]!==le||e[202]!==qe||e[203]!==Pe||e[204]!==tt||e[205]!==st||e[206]!==it||e[207]!==lt||e[208]!==He||e[209]!==Oe||e[210]!==se?(ht=s.jsxs(le,{align:st,className:it,onCloseAutoFocus:lt,children:[He,Oe,se,qe,Pe,Ye,tt]}),e[201]=le,e[202]=qe,e[203]=Pe,e[204]=tt,e[205]=st,e[206]=it,e[207]=lt,e[208]=He,e[209]=Oe,e[210]=se,e[211]=ht):ht=e[211];const St=ht,Ue=K.id,ct=K.id,Qe=je??null,at=ke?"opacity-75":"",Nt=$>0&&"pl-[20px]";let jt;e[212]!==at||e[213]!==Nt?(jt=Q("group relative flex items-center rounded-sm px-1.5 py-1",at,Nt),e[212]=at,e[213]=Nt,e[214]=jt):jt=e[214];let qt;e[215]!==ae||e[216]!==ue||e[217]!==be||e[218]!==oe||e[219]!==A||e[220]!==ve||e[221]!==ce||e[222]!==ie||e[223]!==pe||e[224]!==Se||e[225]!==xe||e[226]!==ke||e[227]!==ye||e[228]!==V||e[229]!==p||e[230]!==_e||e[231]!==U||e[232]!==de||e[233]!==we||e[234]!==St||e[235]!==Ce||e[236]!==ze?(qt=s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:xe?s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",disabled:ke,onMouseDown:be,onClick:oe,onDoubleClick:us=>{us.stopPropagation(),A()},className:Q("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",V?"pr-7":""),children:s.jsxs("div",{className:Q("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[ye?s.jsx(z0,{className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":"Pinned session"}):null,s.jsx("div",{className:Q("block min-w-0 flex-1 truncate typography-ui-label font-normal",pe?"text-primary":"text-foreground"),children:p1(Ce,p)}),V?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:de}):null,V?null:s.jsxs("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:[s.jsx("span",{className:Q("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",Se?"opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0"),children:de}),s.jsxs(qs,{open:Se,onOpenChange:ae,children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:Q("absolute inset-y-0 right-0 inline-flex h-4 w-4 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",Se?"opacity-100 pointer-events-auto":"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":"Session menu",onClick:ue,onKeyDown:vZ,children:s.jsx(Qr,{className:"h-2.5 w-2.5"})})}),St]})]}),_e>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:"Permission required","aria-label":"Permission required",children:[s.jsx(D3,{className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:_e})]}):null]})})}),s.jsx(_t,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:Q("flex items-center gap-3 text-left text-muted-foreground",U?.projectLabel?"justify-between":"justify-start"),children:[U?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:U.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:ze})]}),U?.branchLabel||we?s.jsxs("div",{className:Q("flex items-center gap-3 text-left text-muted-foreground",U?.branchLabel?"justify-between":"justify-start"),children:[U?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(on,{className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:U.branchLabel})]})}):null,we?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",we.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",we.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:ke,onMouseDown:be,onClick:oe,onDoubleClick:us=>{us.stopPropagation(),A()},className:Q("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",V?"pr-7":"group-hover:pr-5 group-focus-within:pr-5"),children:[s.jsxs("div",{className:Q("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[ie,ye?s.jsx(z0,{className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":"Pinned session"}):null,s.jsx("div",{className:Q("block min-w-0 flex-1 truncate typography-ui-label font-normal",pe?"text-primary":"text-foreground"),children:p1(Ce,p)}),_e>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:"Permission required","aria-label":"Permission required",children:[s.jsx(D3,{className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:_e})]}):null]}),xe?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[s.jsx("span",{className:"flex-shrink-0",children:ze}),we?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",we.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",we.deletions]})]}):null,ce?s.jsx("span",{className:"truncate",children:U?.projectLabel}):null,ve?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(on,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:U?.branchLabel})]}):null]})})]})}),e[215]=ae,e[216]=ue,e[217]=be,e[218]=oe,e[219]=A,e[220]=ve,e[221]=ce,e[222]=ie,e[223]=pe,e[224]=Se,e[225]=xe,e[226]=ke,e[227]=ye,e[228]=V,e[229]=p,e[230]=_e,e[231]=U,e[232]=de,e[233]=we,e[234]=St,e[235]=Ce,e[236]=ze,e[237]=qt):qt=e[237];let Zt;e[238]!==xe||e[239]!==V||e[240]!==Ge?(Zt=Ge&&!V?s.jsx("div",{className:Q("absolute top-1/2 -translate-y-1/2 z-10",xe?"right-0":"right-[30px]"),children:Ge}):null,e[238]=xe,e[239]=V,e[240]=Ge,e[241]=Zt):Zt=e[241];let Pt;e[242]!==ae||e[243]!==ue||e[244]!==Se||e[245]!==xe||e[246]!==V||e[247]!==St?(Pt=!xe||V?s.jsx("div",{className:Q("absolute right-0 top-1/2 z-10 -translate-y-1/2",Q("transition-opacity",Se||V?"opacity-100 pointer-events-auto":"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")),children:s.jsxs(qs,{open:Se,onOpenChange:ae,children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:Q("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",xe&&!V?Se?"h-4 w-4 opacity-100 pointer-events-auto":"h-4 w-4 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":"h-6 w-6 opacity-100"),"aria-label":"Session menu",onClick:ue,onKeyDown:bZ,children:s.jsx(Qr,{className:Q(xe&&!V?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),St]})}):null,e[242]=ae,e[243]=ue,e[244]=Se,e[245]=xe,e[246]=V,e[247]=St,e[248]=Pt):Pt=e[248];let cs;e[249]!==Ne||e[250]!==Le||e[251]!==jt||e[252]!==qt||e[253]!==Zt||e[254]!==Pt?(cs=s.jsxs("div",{className:jt,children:[Ne,Le,qt,Zt,Pt]}),e[249]=Ne,e[250]=Le,e[251]=jt,e[252]=qt,e[253]=Zt,e[254]=Pt,e[255]=cs):cs=e[255];let ss;e[256]!==K.id||e[257]!==Ce||e[258]!==Qe||e[259]!==cs?(ss=s.jsx(RG,{sessionId:ct,sessionDirectory:Qe,sessionTitle:Ce,children:cs}),e[256]=K.id,e[257]=Ce,e[258]=Qe,e[259]=cs,e[260]=ss):ss=e[260];let Wt;e[261]!==q||e[262]!==$||e[263]!==o||e[264]!==Z||e[265]!==me||e[266]!==n.children||e[267]!==a||e[268]!==ee||e[269]!==te||e[270]!==je?(Wt=Z&&me?n.children.map(us=>te(us,$+1,je??o,a,q,void 0,ee)):null,e[261]=q,e[262]=$,e[263]=o,e[264]=Z,e[265]=me,e[266]=n.children,e[267]=a,e[268]=ee,e[269]=te,e[270]=je,e[271]=Wt):Wt=e[271];let ls;return e[272]!==K.id||e[273]!==ss||e[274]!==Wt?(ls=s.jsxs(d.Fragment,{children:[ss,Wt]},Ue),e[272]=K.id,e[273]=ss,e[274]=Wt,e[275]=ls):ls=e[275],ls}function bZ(t){return t.stopPropagation()}function vZ(t){return t.stopPropagation()}function yZ(t){t.stopPropagation()}function wZ(t,e){return pZ.has(e)?s.jsx("span",{className:"h-[3px] w-[3px] rounded-full bg-current animate-attention-diamond-pulse",style:{animationDelay:gZ(e)}},e):s.jsx("span",{className:"h-[3px] w-[3px]"},e)}function jZ(t){return t.displayMode}function kZ(t){const e=Fe.c(38),{value:n,setValue:r,showDeletionDialog:o,setShowDeletionDialog:a,onConfirm:l}=t,i=!!n;let c;e[0]!==r?(c=A=>{A||r(null)},e[0]=r,e[1]=c):c=e[1];const u=n?.archivedBucket?"Delete session?":"Archive session?";let m;e[2]!==u?(m=s.jsx(Us,{children:u}),e[2]=u,e[3]=m):m=e[3];const f=n&&n.descendantCount>0?n.archivedBucket?`"${n.session.title||"Untitled Session"}" and its ${n.descendantCount} sub-task${n.descendantCount===1?"":"s"} will be permanently deleted.`:`"${n.session.title||"Untitled Session"}" and its ${n.descendantCount} sub-task${n.descendantCount===1?"":"s"} will be archived.`:n?.archivedBucket?`"${n?.session.title||"Untitled Session"}" will be permanently deleted.`:`"${n?.session.title||"Untitled Session"}" will be archived.`;let h;e[4]!==f?(h=s.jsx(sn,{children:f}),e[4]=f,e[5]=h):h=e[5];let p;e[6]!==m||e[7]!==h?(p=s.jsxs(Zs,{children:[m,h]}),e[6]=m,e[7]=h,e[8]=p):p=e[8];let g;e[9]!==a||e[10]!==o?(g=()=>a(!o),e[9]=a,e[10]=o,e[11]=g):g=e[11];const x=!o;let b;e[12]!==o?(b=o?s.jsx(ea,{className:"h-4 w-4"}):s.jsx(Jo,{className:"h-4 w-4 text-primary"}),e[12]=o,e[13]=b):b=e[13];let v;e[14]!==g||e[15]!==x||e[16]!==b?(v=s.jsxs("button",{type:"button",onClick:g,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":x,children:[b,"Never ask"]}),e[14]=g,e[15]=x,e[16]=b,e[17]=v):v=e[17];let y;e[18]!==r?(y=s.jsx("button",{type:"button",onClick:()=>r(null),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:"Cancel"}),e[18]=r,e[19]=y):y=e[19];let w;e[20]!==l?(w=()=>{l()},e[20]=l,e[21]=w):w=e[21];const C=n?.archivedBucket?"Delete":"Archive";let N;e[22]!==w||e[23]!==C?(N=s.jsx("button",{type:"button",onClick:w,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:C}),e[22]=w,e[23]=C,e[24]=N):N=e[24];let S;e[25]!==y||e[26]!==N?(S=s.jsxs("div",{className:"flex items-center gap-2",children:[y,N]}),e[25]=y,e[26]=N,e[27]=S):S=e[27];let k;e[28]!==v||e[29]!==S?(k=s.jsxs(yn,{className:"w-full sm:items-center sm:justify-between",children:[v,S]}),e[28]=v,e[29]=S,e[30]=k):k=e[30];let j;e[31]!==k||e[32]!==p?(j=s.jsxs(Vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,k]}),e[31]=k,e[32]=p,e[33]=j):j=e[33];let F;return e[34]!==i||e[35]!==c||e[36]!==j?(F=s.jsx(Os,{open:i,onOpenChange:c,children:j}),e[34]=i,e[35]=c,e[36]=j,e[37]=F):F=e[37],F}function NZ(t){const e=Fe.c(19),{value:n,setValue:r,onConfirm:o}=t,a=!!n;let l;e[0]!==r?(l=x=>{x||r(null)},e[0]=r,e[1]=l):l=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Us,{children:"Delete folder?"}),e[2]=i):i=e[2];const c=n&&(n.subFolderCount>0||n.sessionCount>0)?`"${n.folderName}" will be deleted${n.subFolderCount>0?` along with ${n.subFolderCount} sub-folder${n.subFolderCount===1?"":"s"}`:""}. Sessions inside will not be deleted.`:`"${n?.folderName}" will be permanently deleted.`;let u;e[3]!==c?(u=s.jsxs(Zs,{children:[i,s.jsx(sn,{children:c})]}),e[3]=c,e[4]=u):u=e[4];let m;e[5]!==r?(m=s.jsx("button",{type:"button",onClick:()=>r(null),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:"Cancel"}),e[5]=r,e[6]=m):m=e[6];let f;e[7]!==o?(f=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:"Delete"}),e[7]=o,e[8]=f):f=e[8];let h;e[9]!==m||e[10]!==f?(h=s.jsxs(yn,{children:[m,f]}),e[9]=m,e[10]=f,e[11]=h):h=e[11];let p;e[12]!==u||e[13]!==h?(p=s.jsxs(Vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[u,h]}),e[12]=u,e[13]=h,e[14]=p):p=e[14];let g;return e[15]!==a||e[16]!==l||e[17]!==p?(g=s.jsx(Os,{open:a,onOpenChange:l,children:p}),e[15]=a,e[16]=l,e[17]=p,e[18]=g):g=e[18],g}const Q7="oc.sessions.activeNow",SZ=2160*60*1e3,CZ=t=>!!t.parentID,J7=t=>!!t.time?.archived,pu=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},AZ=t=>{try{const e=t.getItem(Q7);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,o=[];return n.forEach(a=>{const l=typeof a=="string"?a:a&&typeof a=="object"&&"sessionId"in a&&typeof a.sessionId=="string"?a.sessionId:null;!l||r.has(l)||(r.add(l),o.push({sessionId:l}))}),o}catch{return[]}},gd=(t,e)=>{try{t.setItem(Q7,JSON.stringify(e))}catch{}},MZ=(t,e,n=Date.now())=>{const r=n-SZ;return t.filter(o=>{const a=e.get(o.sessionId);return a?J7(a)?!1:pu(a)>=r:!0})},nh=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],FZ=t=>[...t].sort((e,n)=>pu(n)-pu(e)),BZ=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!J7(r)).filter(r=>!CZ(r));return FZ(n)},M0="oc.sessions.projectCollapse",rh="oc.sessions.groupOrder",oh="oc.sessions.groupCollapse",ah="oc.sessions.activeSessionByProject",lh="oc.sessions.expandedParents",ih="oc.sessions.pinned",_Z=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"},ch=t=>{switch(t){case"open":return 5;case"blocked":return 4;case"draft":return 3;case"merged":return 2;case"closed":return 1;default:return 0}},_2=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:o=!1})=>{const[a,l]=d.useState(!1),[i,c]=d.useState(""),u=d.useRef(null),m=d.useRef(null),[f,h]=d.useState(null),[p,g]=d.useState(""),[x,b]=d.useState(null),[v,y]=d.useState(new Set),[w,C]=d.useState(()=>new Map),N=d.useMemo(()=>Ko(),[]),[S,k]=d.useState(()=>AZ(N)),[j,F]=d.useState(new Set),[A,M]=d.useState(new Map),[B,E]=d.useState(new Set),[I,P]=d.useState(null),[D,L]=d.useState(!1),[T,_]=d.useState(!1),[z,R]=d.useState(!1),[W,G]=d.useState(null),[Y,J]=d.useState(null),[V,te]=d.useState(""),[U,X]=d.useState(null),[$,q]=d.useState(null),[ee,ce]=d.useState(()=>{try{const De=Ko().getItem(ih);if(!De)return new Set;const wt=JSON.parse(De);return new Set(Array.isArray(wt)?wt.filter(Ht=>typeof Ht=="string"):[])}catch{return new Set}}),[ve,ge]=d.useState(()=>{try{const De=Ko().getItem(oh);if(!De)return new Set;const wt=JSON.parse(De);return new Set(Array.isArray(wt)?wt.filter(Ht=>typeof Ht=="string"):[])}catch{return new Set}}),[xe,ne]=d.useState(()=>{try{const De=Ko().getItem(rh);if(!De)return new Map;const wt=JSON.parse(De),Ht=new Map;return Object.entries(wt).forEach(([Ts,gn])=>{Array.isArray(gn)&&Ht.set(Ts,gn.filter($s=>typeof $s=="string"))}),Ht}catch{return new Map}}),[O,H]=d.useState(()=>{try{const De=Ko().getItem(ah);if(!De)return new Map;const wt=JSON.parse(De),Ht=new Map;return Object.entries(wt).forEach(([Ts,gn])=>{typeof gn=="string"&&gn.length>0&&Ht.set(Ts,gn)}),Ht}catch{return new Map}}),[K,re]=d.useState(new Map),le=d.useRef(new Map),ae=d.useRef(0),ue=dn(De=>De.homeDirectory),be=dn(De=>De.currentDirectory),oe=dn(De=>De.setDirectory),Z=vs(De=>De.projects),ie=vs(De=>De.activeProjectId),pe=vs(De=>De.addProject),me=vs(De=>De.removeProject),Se=vs(De=>De.setActiveProjectIdOnly),ke=vs(De=>De.updateProjectMeta),ye=vs(De=>De.reorderProjects),Ne=Ee(De=>De.setActiveMainTab),_e=Ee(De=>De.openContextPanelTab),de=Ee(De=>De.setSettingsDialogOpen),we=Ee(De=>De.toggleHelpDialog),je=Ee(De=>De.setAboutDialogOpen),Ce=wn(),ze=Ee(De=>De.setSessionSwitcherOpen),Ge=Ee(De=>De.toggleSidebar),Le=Ee(De=>De.openMultiRunLauncher),qe=Ee(De=>De.notifyOnSubtasks),rt=Ee(De=>De.showDeletionDialog),st=Ee(De=>De.setShowDeletionDialog),it=Z1(i,120),lt=d.useMemo(()=>it.trim().toLowerCase(),[it]),He=lt.length>0,Oe=uo(De=>De.collapsedFolderIds),se=uo(De=>De.foldersMap),Pe=uo(De=>De.getFoldersForScope),Ye=uo(De=>De.createFolder),We=uo(De=>De.renameFolder),xt=uo(De=>De.deleteFolder),et=uo(De=>De.addSessionToFolder),tt=uo(De=>De.removeSessionFromFolder),ht=uo(De=>De.toggleFolderCollapse),St=uo(De=>De.cleanupSessions),Ue=uo(De=>De.getSessionFolderId);Yq({isSessionSearchOpen:a,setIsSessionSearchOpen:l,sessionSearchInputRef:m,sessionSearchContainerRef:u});const ct=Wn(De=>De.directories),Qe=Ze(De=>De.sessions),at=Ze(De=>De.archivedSessions),Nt=Ze(De=>De.sessionsByDirectory),jt=Ze(De=>De.currentSessionId),qt=Ze(De=>!!De.newSessionDraft?.open),Zt=Ze(De=>De.setCurrentSession),Pt=Ze(De=>De.loadMessages),cs=Ze(De=>De.updateSessionTitle),ss=Ze(De=>De.shareSession),Wt=Ze(De=>De.unshareSession),ls=Ze(De=>De.sessionMemoryState),us=Ze(De=>De.sessionStatus),ys=Ze(De=>De.sessionAttentionStates),ws=Ze(De=>De.permissions),Is=Ze(De=>De.worktreeMetadata),bs=Ze(De=>De.availableWorktreesByProject),Ss=Ze(De=>De.getSessionsByDirectory),Cs=Ze(De=>De.openNewSessionDraft),ut=mo(De=>De.entries),Mt=Sl(),Kt=d.useMemo(()=>Rn(),[]),[Ft,Et]=d.useState(!1),bt=d.useMemo(()=>xn(),[]),kt=d.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),as=!t&&!bt,Gt=Kt&&kt&&!Ft?"pl-[5.5rem]":"pl-3",Ae="app-region-no-drag inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";d.useEffect(()=>{if(!Kt||!kt){Et(!1);return}let De=!1,wt=null;const Ht=async()=>{try{const{getCurrentWindow:gn}=await Kn(async()=>{const{getCurrentWindow:Tr}=await import("./vendor-.bun-HTKwyaEM.js").then(Fr=>Fr.fG);return{getCurrentWindow:Tr}},__vite__mapDeps([0,1])),gr=await gn().isFullscreen();De||Et(gr)}catch{De||Et(!1)}},Ts=async()=>{try{const{getCurrentWindow:gn}=await Kn(async()=>{const{getCurrentWindow:gr}=await import("./vendor-.bun-HTKwyaEM.js").then(Tr=>Tr.fG);return{getCurrentWindow:gr}},__vite__mapDeps([0,1]));wt=await gn().onResized(()=>{Ht()})}catch{}};return Ht(),Ts(),()=>{De=!0,wt&&wt()}},[Kt,kt]);const Xe=d.useCallback(async De=>{const wt=De.target;if(!wt.closest(".app-region-no-drag")&&!wt.closest("button, a, input, select, textarea")&&De.button===0&&Kt)try{const{getCurrentWindow:Ht}=await Kn(async()=>{const{getCurrentWindow:gn}=await import("./vendor-.bun-HTKwyaEM.js").then($s=>$s.fG);return{getCurrentWindow:gn}},__vite__mapDeps([0,1]));await Ht().startDragging()}catch(Ht){console.error("Failed to start window dragging:",Ht)}},[Kt]),{buildGroupSearchText:yt,filterSessionNodesForSearch:Tt,buildGroupedSessions:Yt}=Kq({homeDirectory:ue,worktreeMetadata:Is,pinnedSessionIds:ee,gitDirectories:ct,isVSCode:bt}),{scheduleCollapsedProjectsPersist:Ut}=aG({isVSCode:bt,safeStorage:N,keys:{sessionExpanded:lh,projectCollapse:M0,sessionPinned:ih,groupOrder:rh,projectActiveSession:ah,groupCollapse:oh},sessions:Qe,pinnedSessionIds:ee,setPinnedSessionIds:ce,groupOrderByProject:xe,activeSessionByProject:O,collapsedGroups:ve,setExpandedParents:y,setCollapsedProjects:F}),Es=d.useCallback(De=>{ce(wt=>{const Ht=new Set(wt);return Ht.has(De)?Ht.delete(De):Ht.add(De),Ht})},[]),Fs=d.useMemo(()=>[...Qe].sort((De,wt)=>T1(De,wt,ee)),[Qe,ee]),ds=d.useMemo(()=>{const De=new Map;return[...Qe,...at].forEach(wt=>{De.set(wt.id,wt)}),De},[Qe,at]);d.useEffect(()=>{const De=MZ(S,ds);De.length===S.length&&De.every((wt,Ht)=>wt.sessionId===S[Ht]?.sessionId)||(k(De),gd(N,De))},[S,ds,N]);const es=d.useRef(new Set);d.useEffect(()=>{const De=new Set;us?.forEach((Ts,gn)=>{(Ts?.type==="busy"||Ts?.type==="retry")&&De.add(gn)});const wt=es.current,Ht=Array.from(De).filter(Ts=>!wt.has(Ts));Ht.length>0&&k(Ts=>{const gn=Ht.reduce(($s,gr)=>nh($s,gr),Ts);return gn===Ts?Ts:(gd(N,gn),gn)}),es.current=De},[us,N]),d.useEffect(()=>{const De=[];us?.forEach((wt,Ht)=>{(wt?.type==="busy"||wt?.type==="retry")&&De.push(Ht)}),De.length!==0&&k(wt=>{const Ht=new Set(wt.map($s=>$s.sessionId));let Ts=wt,gn=!1;return De.forEach($s=>{if(Ht.has($s))return;const gr=ds.get($s);!gr||gr.time?.archived||gr.parentID||(Ts=nh(Ts,$s),Ht.add($s),gn=!0)}),gn?(gd(N,Ts),Ts):wt})},[us,ds,N]);const gs=d.useMemo(()=>{const De=new Map;return Fs.forEach(wt=>{const Ht=wt.parentID;if(!Ht)return;const Ts=De.get(Ht)??[];Ts.push(wt),De.set(Ht,Ts)}),De.forEach(wt=>wt.sort((Ht,Ts)=>T1(Ht,Ts,ee))),De},[Fs,ee]);tG({sortedSessions:Fs,projects:Z,directoryStatus:w,setDirectoryStatus:C});const Ks=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:"No sessions yet"}),s.jsx("p",{className:"typography-meta mt-1",children:"Create your first session to start coding."})]}),Rs=d.useMemo(()=>Z.find(De=>De.id===x)??null,[Z,x]),un=d.useCallback(De=>{x&&(ke(x,De),b(null))},[x,ke]),zn=d.useCallback(()=>{L(!0)},[]),Te=d.useCallback(()=>{const De=Sl.getState();if(De.available&&De.info){_(!0);return}Mt.checkForUpdates().then(()=>{const{available:wt,error:Ht}=Sl.getState();if(Ht){fe.error("Failed to check for updates",{description:Ht});return}if(!wt){fe.success("You are on the latest version");return}_(!0)})},[Mt]),Ie=Mt.available&&(Mt.runtimeType==="desktop"||Mt.runtimeType==="web"),Ke=Ze(De=>De.deleteSession),Ve=Ze(De=>De.deleteSessions),ft=Ze(De=>De.archiveSession),Bt=Ze(De=>De.archiveSessions),{copiedSessionId:At,handleSessionSelect:mt,handleSessionDoubleClick:Lt,handleSaveEdit:$t,handleCancelEdit:Xs,handleShareSession:As,handleCopyShareUrl:Ot,handleUnshareSession:fs,handleDeleteSession:ms,confirmDeleteSession:Hs}=nG({activeProjectId:ie,currentDirectory:be,currentSessionId:jt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:a,sessionSearchQuery:i,setSessionSearchQuery:c,setIsSessionSearchOpen:l,setActiveProjectIdOnly:Se,setDirectory:oe,setActiveMainTab:Ne,setSessionSwitcherOpen:ze,setCurrentSession:Zt,updateSessionTitle:cs,shareSession:ss,unshareSession:Wt,deleteSession:Ke,deleteSessions:Ve,archiveSession:ft,archiveSessions:Bt,childrenMap:gs,showDeletionDialog:rt,setDeleteSessionConfirm:X,deleteSessionConfirm:U,setEditingId:h,setEditTitle:g,editingId:f,editTitle:p}),rn=d.useCallback(()=>{if(!$)return;const{scopeKey:De,folderId:wt}=$;q(null),xt(De,wt)},[$,xt]),zs=d.useCallback(()=>{if(!Kt||!$o()){na.requestDirectoryDialog();return}Kn(async()=>{const{requestDirectoryAccess:De}=await import("./index-DKc7ZmSW.js").then(wt=>wt.b5);return{requestDirectoryAccess:De}},__vite__mapDeps([3,0,1,4])).then(({requestDirectoryAccess:De})=>De("")).then(De=>{De.success&&De.path?pe(De.path,{id:De.projectId})||fe.error("Failed to add project",{description:"Please select a valid directory."}):De.error&&De.error!=="Directory selection cancelled"&&fe.error("Failed to select directory",{description:De.error})}).catch(De=>{console.error("Desktop: Error selecting directory:",De),fe.error("Failed to select directory")})},[pe,Kt]),Vn=d.useCallback(De=>{y(wt=>{const Ht=new Set(wt);Ht.has(De)?Ht.delete(De):Ht.add(De);try{N.setItem(lh,JSON.stringify(Array.from(Ht)))}catch{}return Ht})},[N]),Ln=d.useCallback((De,wt)=>{if(!De)return null;wt&&Oe.has(wt)&&ht(wt);const Ht=Ye(De,"New folder",wt);return J(Ht.id),te(Ht.name),Ht},[Oe,ht,Ye]),Jn=d.useCallback(De=>{E(wt=>{const Ht=new Set(wt);return Ht.has(De)?Ht.delete(De):Ht.add(De),Ht})},[]),br=d.useCallback(()=>{ae.current=Date.now()+150,F(()=>{const De=new Set(Z.map(wt=>wt.id));try{N.setItem(M0,JSON.stringify(Array.from(De)))}catch{}return bt||Ut(De),De})},[Z,bt,N,Ut]),Ar=d.useCallback(()=>{ae.current=Date.now()+150,F(()=>{const De=new Set;try{N.setItem(M0,JSON.stringify([]))}catch{}return bt||Ut(De),De})},[bt,N,Ut]),Vr=d.useCallback(De=>{ae.current=Date.now()+150,F(wt=>{const Ht=new Set(wt);Ht.has(De)?Ht.delete(De):Ht.add(De);try{N.setItem(M0,JSON.stringify(Array.from(Ht)))}catch{}return bt||Ut(Ht),Ht})},[bt,N,Ut]),hn=d.useMemo(()=>Z.map(De=>({...De,normalizedPath:nn(De.path)})).filter(De=>!!De.normalizedPath),[Z]);uG({projects:Z,normalizedProjects:hn,normalizePath:nn,gitDirectories:ct,setProjectRepoStatus:M,setProjectRootBranches:re});const kn=Ze(De=>De.isLoading);yG({isSessionsLoading:kn,sessions:Qe,archivedSessions:at,normalizedProjects:hn,isVSCode:bt,availableWorktreesByProject:bs,cleanupSessions:St});const{getSessionsForProject:rr,getArchivedSessionsForProject:or}=pG({isVSCode:bt,sessions:Qe,archivedSessions:at,sessionsByDirectory:Nt,getSessionsByDirectory:Ss,availableWorktreesByProject:bs});$q({normalizedProjects:hn,sessions:Qe,archivedSessions:at,availableWorktreesByProject:bs,isVSCode:bt,isSessionsLoading:kn,foldersMap:se,createFolder:Ye,addSessionToFolder:et,cleanupSessions:St});const fr=d.useRef(!1);ie&&A.has(ie)&&(fr.current=!!A.get(ie));const{projectSections:bn,groupSearchDataByGroup:jn,sectionsForRender:pr,searchMatchCount:Ur}=Uq({normalizedProjects:hn,getSessionsForProject:rr,getArchivedSessionsForProject:or,availableWorktreesByProject:bs,projectRepoStatus:A,projectRootBranches:K,lastRepoStatus:fr.current,buildGroupedSessions:Yt,hasSessionSearchQuery:He,normalizedSessionSearchQuery:lt,filterSessionNodesForSearch:Tt,buildGroupSearchText:yt,getFoldersForScope:Pe}),Xn=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:"No matching sessions"}),s.jsx("p",{className:"typography-meta mt-1",children:"Try a different title, branch, folder, or path."})]}),an=d.useMemo(()=>hn.find(De=>De.id===ie)??hn[0]??null,[hn,ie]),Mr=d.useMemo(()=>an?{id:an.id,path:an.normalizedPath}:null,[an]),Ms=d.useMemo(()=>an?an.label?.trim()||Or(an.normalizedPath,ue)||an.normalizedPath:null,[an,ue]),ar=d.useMemo(()=>an?!!A.get(an.id):!1,[an,A]),Ir=an&&A.has(an.id)?ar:fr.current,Vo=!0,Uo=t||Ce.isMobile;d.useEffect(()=>{an||R(!1)},[an]);const{currentSessionDirectory:$e}=qq({projectSections:bn,activeProjectId:ie,activeSessionByProject:O,setActiveSessionByProject:H,currentSessionId:jt,handleSessionSelect:mt,newSessionDraftOpen:qt,mobileVariant:t,openNewSessionDraft:Cs,setActiveMainTab:Ne,setSessionSwitcherOpen:ze,sessions:Qe,worktreeMetadata:Is}),{getOrderedGroups:Je}=Gq(xe),ot=d.useRef(!1);d.useEffect(()=>{if(ot.current||bn.length===0)return;const De=bn.flatMap(wt=>wt.groups.filter(Ht=>Ht.isArchivedBucket).map(Ht=>`${wt.project.id}:${Ht.id}`));De.length>0&&ge(wt=>new Set([...wt,...De])),ot.current=!0},[bn]);const gt=d.useMemo(()=>{const De=new Map;return bn.forEach(wt=>{const Ht=u8(wt.project.label?.trim()||Or(wt.project.normalizedPath,ue)||wt.project.normalizedPath);wt.groups.forEach(Ts=>{const gn=Ts.branch&&Ts.branch!==Ht?{projectLabel:Ht,branchLabel:Ts.branch}:{projectLabel:Ht,branchLabel:null},$s=gr=>{gr.forEach(Tr=>{De.set(Tr.session.id,{node:Tr,projectId:wt.project.id,groupDirectory:Ts.directory,secondaryMeta:gn}),Tr.children.length>0&&$s(Tr.children)})};$s(Ts.sessions)})}),De},[bn,ue]),hs=d.useMemo(()=>BZ(S,new Map(Qe.map(De=>[De.id,De]))),[S,Qe]);eG({currentSessionId:jt,sortedSessions:Fs,recentSessionIds:hs.map(De=>De.id),loadMessages:Pt});const xs=d.useMemo(()=>{const De=wt=>{const Ht=gt.get(wt.id),Ts=nn(wt.directory??null);return{node:Ht?.node??{session:wt,children:[],worktree:null},projectId:Ht?.projectId??null,groupDirectory:Ht?.groupDirectory??Ts,secondaryMeta:Ht?.secondaryMeta??null}};return[{key:"active-now",title:"recent",items:hs.map(De)}]},[hs,gt]),la=t?"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",Ol="h-4.5 w-4.5",el=NG({isDesktopShellRuntime:Kt,projectSections:bn,projectHeaderSentinelRefs:le}),ia=d.useCallback((De,wt=0,Ht,Ts,gn=!1,$s,gr="project")=>s.jsx(xZ,{node:De,depth:wt,groupDirectory:Ht,projectId:Ts,archivedBucket:gn,directoryStatus:w,sessionMemoryState:ls,currentSessionId:jt,pinnedSessionIds:ee,expandedParents:v,hasSessionSearchQuery:He,normalizedSessionSearchQuery:lt,sessionAttentionStates:ys,notifyOnSubtasks:qe,sessionStatus:us,permissions:ws,editingId:f,setEditingId:h,editTitle:p,setEditTitle:g,handleSaveEdit:$t,handleCancelEdit:Xs,toggleParent:Vn,handleSessionSelect:mt,handleSessionDoubleClick:Lt,togglePinnedSession:Es,handleShareSession:As,copiedSessionId:At,handleCopyShareUrl:Ot,handleUnshareSession:fs,openSidebarMenuKey:W,setOpenSidebarMenuKey:G,renamingFolderId:Y,getFoldersForScope:Pe,getSessionFolderId:Ue,removeSessionFromFolder:tt,addSessionToFolder:et,createFolderAndStartRename:Ln,openContextPanelTab:_e,handleDeleteSession:ms,mobileVariant:t,renderSessionNode:ia,secondaryMeta:$s,renderContext:gr}),[w,ls,jt,ee,v,He,lt,ys,qe,us,ws,f,h,p,g,$t,Xs,Vn,mt,Lt,Es,As,At,Ot,fs,W,G,Y,Pe,Ue,tt,et,Ln,_e,ms,t]),tl=d.useCallback(De=>{ge(wt=>{const Ht=new Set(wt);return Ht.has(De)?Ht.delete(De):Ht.add(De),Ht})},[]),Vl=d.useMemo(()=>{const De=new Map;return Object.values(ut).forEach(wt=>{const Ht=nn(wt.params?.directory??wt.identity?.directory??null),Ts=wt.params?.branch?.trim()??wt.identity?.branch?.trim();if(!Ht||!Ts)return;const gn=_Z(wt.status??null),$s=wt.status?.pr;if(!gn||!$s?.number)return;const gr=`${Ht}::${Ts}`,Tr={visualState:gn,number:$s.number,url:typeof $s.url=="string"&&$s.url.trim().length>0?$s.url:null,state:$s.state,draft:!!$s.draft,title:typeof $s.title=="string"&&$s.title.trim().length>0?$s.title:null,base:typeof $s.base=="string"&&$s.base.trim().length>0?$s.base:null,head:typeof $s.head=="string"&&$s.head.trim().length>0?$s.head:null,checks:wt.status?.checks?{state:wt.status.checks.state,total:wt.status.checks.total,success:wt.status.checks.success,failure:wt.status.checks.failure,pending:wt.status.checks.pending}:null,canMerge:typeof wt.status?.canMerge=="boolean"?wt.status.canMerge:null,mergeableState:typeof $s.mergeableState=="string"?$s.mergeableState:null,repo:wt.status?.repo?{owner:wt.status.repo.owner,repo:wt.status.repo.repo}:null},Fr=De.get(gr);(!Fr||ch(Tr.visualState)>ch(Fr.visualState))&&De.set(gr,Tr)}),De},[ut]),Re=d.useCallback((De,wt,Ht,Ts,gn)=>s.jsx(HG,{group:De,groupKey:wt,projectId:Ht,hideGroupLabel:Ts,hasSessionSearchQuery:He,normalizedSessionSearchQuery:lt,groupSearchDataByGroup:jn,expandedSessionGroups:B,collapsedGroups:ve,hideDirectoryControls:r,getFoldersForScope:Pe,collapsedFolderIds:Oe,toggleFolderCollapse:ht,renameFolder:We,deleteFolder:xt,showDeletionDialog:rt,setDeleteFolderConfirm:q,renderSessionNode:ia,currentSessionDirectory:$e,projectRepoStatus:A,lastRepoStatus:fr.current,toggleGroupSessionLimit:Jn,mobileVariant:t,activeProjectId:ie,setActiveProjectIdOnly:Se,setActiveMainTab:Ne,setSessionSwitcherOpen:ze,openNewSessionDraft:Cs,addSessionToFolder:et,createFolderAndStartRename:Ln,renamingFolderId:Y,renameFolderDraft:V,setRenameFolderDraft:te,setRenamingFolderId:J,pinnedSessionIds:ee,prVisualStateByDirectoryBranch:Vl,onToggleCollapsedGroup:tl,dragHandleProps:gn}),[He,lt,jn,B,ve,r,Pe,Oe,ht,We,xt,rt,ia,$e,A,Jn,t,ie,Se,Ne,ze,Cs,et,Ln,Y,V,ee,Vl,tl]),pt=He?null:s.jsx(JG,{sections:xs,renderSessionNode:ia}),Ct=!!(Y||f||x),Vt=d.useCallback(()=>{Ne("chat"),t&&ze(!1),Cs()},[t,Cs,Ne,ze]),os=d.useCallback(()=>{Ne("chat"),t&&ze(!1),Le()},[t,Le,Ne,ze]);return s.jsxs("div",{ref:u,className:Q("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[as?s.jsxs("div",{onMouseDown:Xe,className:Q("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",Gt),children:[Eu()&&s.jsx(Bq,{className:"mr-3"}),s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ge,className:Ae,"aria-label":"Close sessions",children:s.jsx(ji,{className:"h-[18px] w-[18px]"})})}),s.jsx(_t,{children:s.jsx("p",{children:"Close sessions"})})]})]}):null,s.jsx(KG,{hideDirectoryControls:r,handleOpenDirectoryDialog:zs,handleNewSession:Vt,useMobileNotesPanel:Uo,projectNotesPanelOpen:z,setProjectNotesPanelOpen:R,activeProjectRefForHeader:Mr,activeProjectLabelForHeader:Ms,canOpenMultiRun:Z.length>0,openMultiRunLauncher:os,stableActiveProjectIsRepo:Ir,headerActionIconClass:Ol,reserveHeaderActionsSpace:Vo,headerActionButtonClass:la,isSessionSearchOpen:a,setIsSessionSearchOpen:l,sessionSearchInputRef:m,sessionSearchQuery:i,setSessionSearchQuery:c,hasSessionSearchQuery:He,searchMatchCount:Ur,collapseAllProjects:br,expandAllProjects:Ar}),s.jsx(aZ,{topContent:pt,sectionsForRender:pr,projectSections:bn,activeProjectId:ie,showOnlyMainWorkspace:o,hasSessionSearchQuery:He,emptyState:Ks,searchEmptyState:Xn,renderGroupSessions:Re,homeDirectory:ue,collapsedProjects:j,hideDirectoryControls:r,projectRepoStatus:A,hoveredProjectId:I,setHoveredProjectId:P,isDesktopShellRuntime:Kt,stuckProjectHeaders:el,mobileVariant:t,toggleProject:Vr,setActiveProjectIdOnly:Se,setActiveMainTab:Ne,setSessionSwitcherOpen:ze,openNewSessionDraft:Cs,openNewWorktreeDialog:zn,openProjectEditDialog:b,removeProject:me,projectHeaderSentinelRefs:le,reorderProjects:ye,getOrderedGroups:Je,setGroupOrderByProject:ne,openSidebarMenuKey:W,setOpenSidebarMenuKey:G,isInlineEditing:Ct}),s.jsx(tZ,{onOpenSettings:()=>de(!0),onOpenShortcuts:we,onOpenAbout:()=>je(!0),onOpenUpdate:Te,showRuntimeButtons:!bt,showUpdateButton:Ie}),s.jsx(fu,{open:T,onOpenChange:_,info:Mt.info,downloading:Mt.downloading,downloaded:Mt.downloaded,progress:Mt.progress,error:Mt.error,onDownload:Mt.downloadUpdate,onRestart:Mt.restartToUpdate,runtimeType:Mt.runtimeType}),Rs?s.jsx(E8,{open:!!Rs,onOpenChange:De=>{De||b(null)},projectId:Rs.id,projectName:Rs.label||Or(Rs.path,ue),projectPath:Rs.path,initialIcon:Rs.icon,initialColor:Rs.color,initialIconBackground:Rs.iconBackground,onSave:un}):null,s.jsx(zq,{open:D,onOpenChange:L,onWorktreeCreated:(De,wt)=>{if(Ne("chat"),t&&ze(!1),wt?.sessionId){Zt(wt.sessionId);return}Cs({directoryOverride:De})}}),Uo?s.jsx(cr,{open:z,onClose:()=>R(!1),title:Ms?`Project notes - ${Ms}`:"Project notes",children:s.jsx(X7,{projectRef:Mr,projectLabel:Ms,canCreateWorktree:Ir,onActionComplete:()=>R(!1),className:"p-0"})}):null,s.jsx(kZ,{value:U,setValue:X,showDeletionDialog:rt,setShowDeletionDialog:st,onConfirm:Hs}),s.jsx(NZ,{value:$,setValue:q,onConfirm:rn})]})},rc=()=>{const t=Fe.c(13),[e,n]=he.useState(!1);let r,o;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(_n()||Eu())},o=[],t[0]=r,t[1]=o):(r=t[0],o=t[1]),he.useEffect(r,o);let a;t[2]!==e?(a=async h=>e?await Tu(h):{success:!0,path:h},t[2]=e,t[3]=a):a=t[3];const l=a;let i;t[4]!==e?(i=async h=>e?await jv():{success:!0},t[4]=e,t[5]=i):i=t[5];const c=i;let u;t[6]!==e?(u=async h=>e?await kv():{success:!0},t[6]=e,t[7]=u):u=t[7];const m=u;let f;return t[8]!==e||t[9]!==l||t[10]!==c||t[11]!==m?(f={isDesktop:e,requestAccess:l,startAccessing:c,stopAccessing:m},t[8]=e,t[9]=l,t[10]=c,t[11]=m,t[12]=f):f=t[12],f},dh=({currentPath:t,onSelectPath:e,triggerClassName:n,variant:r="dropdown",className:o,selectionBehavior:a="immediate",onDoubleClickPath:l,showHidden:i=!1,rootDirectory:c=null,isRootReady:u,alwaysShowActions:m=!1})=>{const{isMobile:f}=wn(),[h,p]=d.useState([]),[g,x]=d.useState(new Set),[b,v]=d.useState(!0),[y,w]=d.useState(!1),[C,N]=d.useState(""),[S,k]=d.useState(new Set),[j,F]=d.useState(null),[A,M]=d.useState(""),[B,E]=d.useState(!0),I=d.useRef(null),{requestAccess:P,startAccessing:D,isDesktop:L}=rc(),T=d.useRef(i),_=d.useCallback(H=>{if(!H)return H;if(H==="/"||H.length===0)return"/";let K=H;for(;K.length>1&&K.endsWith("/");)K=K.slice(0,-1);return K.length===0?"/":K},[]),z=d.useMemo(()=>{if(!C)return null;const H=C.replace(/\\/g,"/");return _(H)},[C,_]),R=d.useMemo(()=>{if(typeof c=="string"&&c.length>0){const H=c.replace(/\\/g,"/"),K=_(H);if(K&&K!=="/")return K}return z&&z!=="/"?z:null},[c,z,_]),W=d.useMemo(()=>typeof u=="boolean"?!!(u&&R):!!R,[u,R]);d.useEffect(()=>{W||(v(!0),p([]))},[W]);const G=d.useCallback(H=>{if(!H||!W||!R)return!1;const K=H.replace(/\\/g,"/"),re=_(K)??K;if(re===R)return!0;const le=`${R}/`;return re.startsWith(le)},[W,R,_]),Y=async H=>{if(W){if(a==="deferred"){e(H);return}if(L){const K=await P(H);K.success&&K.path?(await D(K.path),e(K.path)):(console.error("Failed to get directory access:",K.error),e(H))}else e(H)}};d.useEffect(()=>{let H=!1;const K=ae=>{if(!ae)return!1;const ue=_(ae.replace(/\\/g,"/"));return!ue||ue==="/"?!1:(N(typeof ue=="string"?ue:ae.replace(/\\/g,"/")),!0)};return c&&K(c)||(async()=>{try{const ae=await En.getFilesystemHome();if(!H&&K(ae))return}catch(ae){console.warn("Failed to resolve filesystem home directory:",ae)}try{const ae=await En.getSystemInfo();if(!H&&K(ae?.homeDirectory))return}catch(ae){console.warn("Failed to resolve home directory from system info:",ae)}})(),()=>{H=!0}},[c,_]),d.useEffect(()=>{let H=!1;const K=ue=>{if(H)return;const be=ue.filter(oe=>typeof oe=="string"&&oe.length>0).map(oe=>{const Z=oe.replace(/\\/g,"/");return _(Z)??Z});k(new Set(be))},re=()=>{try{const ue=localStorage.getItem("pinnedDirectories");if(!ue)return;const be=JSON.parse(ue);Array.isArray(be)&&K(be)}catch(ue){console.warn("Failed to load pinned directories from local storage:",ue)}},le=async()=>{try{let ue=[];const be=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(be.ok){const oe=await be.json();ue=Array.isArray(oe?.pinnedDirectories)?oe.pinnedDirectories:[]}if(H)return;K(ue)}catch(ue){console.warn("Failed to load pinned directories:",ue)}};re();const ae=ue=>{const be=ue.detail;be&&Array.isArray(be.pinnedDirectories)&&K(be.pinnedDirectories)};return window.addEventListener("archcoder:settings-synced",ae),le(),()=>{H=!0,window.removeEventListener("archcoder:settings-synced",ae)}},[_]);const J=d.useRef(!0);d.useEffect(()=>{if(J.current){J.current=!1;return}const H={pinnedDirectories:Array.from(S)};ln(H)},[S]),d.useEffect(()=>{R&&k(H=>{const K=Array.from(H).map(re=>_(re.replace(/\\/g,"/"))??re).filter(re=>G(re));return new Set(K)})},[R,G,_]),d.useEffect(()=>{T.current!==i&&(T.current=i)},[i]);const V=H=>{k(K=>{if(!G(H))return K;const re=_(H.replace(/\\/g,"/"))??H.replace(/\\/g,"/"),le=new Set(K);return le.has(re)?le.delete(re):le.add(re),le})},te=d.useMemo(()=>Array.from(S).map(H=>_(H.replace(/\\/g,"/"))??H).filter(H=>G(H)).map(H=>({path:H,name:H.split("/").pop()||H})).sort((H,K)=>H.name.localeCompare(K.name)),[S,G,_]),U=d.useCallback(async H=>{const K=be=>i||!be.startsWith("."),re=R;if(!W||!re)return[];const le=H&&H.length>0?H:re,ae=le?le.replace(/\\/g,"/"):null,ue=ae?_(ae)??ae:null;if(ue){const be=`${re}/`;if(!(ue===re||ue.startsWith(be)))return[]}try{return(await En.listLocalDirectory(H)).filter(oe=>{if(!oe.isDirectory||!K(oe.name))return!1;const Z=oe.path.replace(/\\/g,"/"),ie=_(Z)??Z,pe=ie===re?re:`${re}/`;return ie===re||ie.startsWith(pe)}).map(oe=>({name:oe.name,path:oe.path.replace(/\\/g,"/"),isDirectory:!0})).sort((oe,Z)=>oe.name.localeCompare(Z.name))}catch{try{const oe=await En.getApiClient().file.list({path:".",directory:H});return oe.data?oe.data.filter(Z=>{if(Z.type!=="directory"||!Z.name||!K(Z.name))return!1;const ie=String(Z.absolute||Z.path||Z.name).replace(/\\/g,"/"),pe=_(ie)??ie,me=pe===re?re:`${re}/`;return pe===re||pe.startsWith(me)}).map(Z=>({name:Z.name||"",path:String(Z.absolute||Z.path||Z.name).replace(/\\/g,"/"),isDirectory:!0})).filter(Z=>Z.name!=="").sort((Z,ie)=>Z.name.localeCompare(ie.name)):[]}catch{return[]}}},[i,R,_,W]),X=d.useRef(!1),$=d.useCallback(async()=>{if(!W||!R){v(!0),p([]);return}X.current||v(!0);try{const H=await U(R);p(H),X.current=!0}catch{}finally{v(!1)}},[W,R,U]);d.useEffect(()=>{W&&(r==="inline"||y)&&$()},[r,y,W,$]);const q=async H=>{if(!W)return;const K=g.has(H.path),re=new Set(g);if(K){re.delete(H.path),x(re);return}re.add(H.path),x(re);const le=await U(H.path),ae=ue=>ue.map(be=>be.path===H.path?{...be,children:le}:be.children?{...be,children:ae(be.children)}:be);p(ue=>ae(ue))};d.useEffect(()=>{j&&I.current&&(I.current.focus(),I.current.select())},[j]);const ee=(H,K=[])=>{const re="new_directory",le=K.map(oe=>oe.name);if(!le.includes(re))return re;let ae=1;const ue=new RegExp(`^${re}(\\d+)$`);for(const oe of le){const Z=oe.match(ue);if(Z){const ie=parseInt(Z[1],10);ie>ae&&(ae=ie)}}let be=2;for(;le.includes(`${re}${be}`);)be++;return`${re}${Math.max(be,ae+1)}`},ce=async H=>{if(W){if(g.has(H.path)){const K=ee(H.path,H.children);M(K)}else{const K=new Set(g);if(K.add(H.path),x(K),H.children){const re=ee(H.path,H.children);M(re)}else{const re=await U(H.path),le=ue=>ue.map(be=>be.path===H.path?{...be,children:re}:be.children?{...be,children:le(be.children)}:be);p(ue=>le(ue));const ae=ee(H.path,re);M(ae)}}F(H.path)}},ve=async()=>{if(!j||!W)return;const H=A.trim()||"new_directory",K=`${j}/${H}`;try{await En.createDirectory(K,{allowOutsideWorkspace:!0});const re=await U(j),le=ae=>ae.map(ue=>ue.path===j?{...ue,children:re}:ue.children?{...ue,children:le(ue.children)}:ue);p(ae=>le(ae)),F(null),M("")}catch(re){console.error("Failed to create directory:",re)}},ge=()=>{F(null),M("")},xe=(H,K=0)=>{const re=g.has(H.path),le=H.isDirectory,ae=S.has(H.path),ue=t===H.path,be=r==="inline",oe=s.jsxs(s.Fragment,{children:[le&&s.jsx("button",{onClick:Z=>{Z.stopPropagation(),q(H)},className:Q("hover:bg-interactive-hover rounded","p-0.5"),children:re?s.jsx(Ds,{className:f?"h-3.5 w-3.5":"h-3 w-3"}):s.jsx(On,{className:f?"h-3.5 w-3.5":"h-3 w-3"})}),!le&&s.jsx("div",{className:f?"w-4.5":"w-4"}),s.jsxs("button",{onClick:Z=>{Z.stopPropagation(),Y(H.path),r==="dropdown"&&a==="immediate"&&w(!1)},onDoubleClick:Z=>{Z.stopPropagation(),l&&l(H.path)},className:Q("flex items-center flex-1 text-left focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/60 rounded","gap-1.5",be&&ue?"text-primary":"text-foreground"),children:[s.jsx(Pa,{className:Q("text-muted-foreground flex-shrink-0",f?"h-4 w-4":"h-3.5 w-3.5",be&&ue&&"text-primary")}),s.jsx("span",{className:Q("font-medium truncate","typography-ui-label",be&&ue?"text-primary":"text-foreground"),children:H.name})]}),s.jsx("button",{onClick:Z=>{Z.stopPropagation(),ce(H)},className:Q("hover:bg-interactive-hover rounded transition-opacity",f?"p-1.5":"p-1",m?"opacity-60":"opacity-0 group-hover:opacity-100"),title:"Create new directory",children:s.jsx(Qs,{className:Q("text-muted-foreground",f?"h-3.5 w-3.5":"h-3 w-3")})}),s.jsx("button",{onClick:Z=>{Z.stopPropagation(),V(H.path)},className:Q("hover:bg-interactive-hover rounded transition-opacity",f?"p-1.5":"p-1",m?"opacity-60":"opacity-0 group-hover:opacity-100"),title:ae?"Unpin directory":"Pin directory",children:ae?s.jsx(lc,{className:Q("text-primary",f?"h-3.5 w-3.5":"h-3 w-3")}):s.jsx(z0,{className:Q("text-muted-foreground",f?"h-3.5 w-3.5":"h-3 w-3")})})]});return r==="inline"?s.jsxs("div",{children:[s.jsx("div",{className:Q("group flex items-center gap-1 rounded-lg mx-1 text-left transition-colors",f?"px-1.5 py-1":"px-2 py-1.5",ue?"bg-primary/10 text-primary":"hover:bg-interactive-hover/50 text-foreground"),style:{paddingLeft:`${K*(f?12:14)+(f?4:6)}px`},children:oe}),re&&s.jsxs(s.Fragment,{children:[j===H.path&&s.jsxs("div",{className:"flex items-center gap-1 mx-1 px-2 py-1.5",style:{paddingLeft:`${(K+1)*14+6}px`},children:[s.jsx("div",{className:"w-4"}),s.jsx(Pa,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Xt,{ref:I,value:A,onChange:Z=>M(Z.target.value),onKeyDown:Z=>{Z.key==="Enter"?(Z.preventDefault(),Z.stopPropagation(),ve()):Z.key==="Escape"&&(Z.preventDefault(),Z.stopPropagation(),ge())},onBlur:ve,className:"h-6 typography-meta flex-1 selection:bg-interactive-selection selection:text-interactive-selection-foreground",placeholder:"new_directory"}),s.jsx("button",{onClick:Z=>{Z.preventDefault(),Z.stopPropagation(),ve()},className:"p-1 hover:bg-interactive-hover rounded",title:"Create directory",children:s.jsx(js,{className:"h-3 w-3 text-green-600"})}),s.jsx("button",{onClick:Z=>{Z.preventDefault(),Z.stopPropagation(),ge()},className:"p-1 hover:bg-interactive-hover rounded",title:"Cancel",children:s.jsx(Ps,{className:"h-3 w-3 text-muted-foreground"})})]}),H.children&&H.children.map(Z=>xe(Z,K+1))]})]},H.path):s.jsxs("div",{children:[s.jsxs(Jt,{className:Q("flex items-center gap-1 cursor-pointer group",t===H.path&&"bg-interactive-selection"),style:{paddingLeft:`${K*12+8}px`},onSelect:Z=>{Z.preventDefault()},children:[le&&s.jsx("button",{onClick:Z=>{Z.stopPropagation(),q(H)},className:"p-0.5 hover:bg-interactive-hover rounded",children:re?s.jsx(Ds,{className:"h-3 w-3"}):s.jsx(On,{className:"h-3 w-3"})}),!le&&s.jsx("div",{className:"w-4"}),oe]}),re&&s.jsxs("div",{children:[j===H.path&&s.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5",style:{paddingLeft:`${(K+1)*12+8}px`},children:[s.jsx("div",{className:"w-4"}),s.jsx(Pa,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Xt,{ref:I,value:A,onChange:Z=>M(Z.target.value),onKeyDown:Z=>{Z.key==="Enter"?(Z.preventDefault(),Z.stopPropagation(),ve()):Z.key==="Escape"&&(Z.preventDefault(),Z.stopPropagation(),ge())},onBlur:ve,className:"h-6 typography-meta flex-1 selection:bg-interactive-selection selection:text-interactive-selection-foreground",placeholder:"new_directory"}),s.jsx("button",{onClick:Z=>{Z.preventDefault(),Z.stopPropagation(),ve()},className:"p-1 hover:bg-interactive-hover rounded",title:"Create directory",children:s.jsx(js,{className:"h-3 w-3 text-green-600"})}),s.jsx("button",{onClick:Z=>{Z.preventDefault(),Z.stopPropagation(),ge()},className:"p-1 hover:bg-interactive-hover rounded",title:"Cancel",children:s.jsx(Ps,{className:"h-3 w-3 text-muted-foreground"})})]}),H.children&&H.children.map(Z=>xe(Z,K+1))]})]},H.path)},ne=(H,K)=>{if(r==="inline"){const re=t===K;return s.jsxs("div",{className:Q("group flex items-center gap-2 mx-1 rounded-lg transition-colors",f?"px-1.5 py-1":"px-2 py-1.5",re?"bg-primary/10":"hover:bg-interactive-hover/50"),children:[s.jsxs("button",{onClick:()=>Y(K),onDoubleClick:le=>{le.stopPropagation(),l&&l(K)},className:Q("flex flex-1 items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/60 rounded min-w-0",re?"text-primary":"text-foreground"),children:[s.jsx(Pa,{className:Q("flex-shrink-0",f?"h-4 w-4":"h-3.5 w-3.5",re?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:Q("typography-ui-label font-medium truncate flex-shrink-0",re?"text-primary":"text-foreground"),children:H}),s.jsx("span",{className:"typography-meta text-muted-foreground/60 truncate",children:va(K,C)})]}),s.jsx("button",{onClick:()=>V(K),className:Q("hover:bg-interactive-hover rounded-md transition-opacity",f?"p-1.5 opacity-60":"p-1 opacity-0 group-hover:opacity-100"),title:"Unpin directory",children:s.jsx(lc,{className:Q("text-primary","h-3.5 w-3.5")})})]},K)}return s.jsxs(Jt,{onSelect:re=>{re.preventDefault(),Y(K),a==="immediate"&&w(!1)},className:Q("flex items-start gap-2 cursor-pointer group py-2",t===K&&"bg-interactive-selection"),children:[s.jsx(Pa,{className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("div",{className:"typography-ui-label font-medium",children:H}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:va(K,C)})]}),s.jsx("button",{onClick:re=>{re.stopPropagation(),re.preventDefault(),V(K)},className:"p-1 opacity-0 group-hover:opacity-100 hover:bg-interactive-hover rounded transition-opacity",title:"Unpin directory",children:s.jsx(lc,{className:"h-3 w-3 text-primary"})})]},K)},O=s.jsx(s.Fragment,{children:W?s.jsxs(s.Fragment,{children:[te.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",onClick:()=>E(H=>!H),className:Q("flex w-full items-center gap-1.5 typography-meta font-medium text-muted-foreground/80 hover:bg-interactive-hover/30 rounded transition-colors uppercase tracking-wide",f?"px-1.5 py-1":"px-2 py-1.5"),children:[B?s.jsx(Ds,{className:f?"h-3.5 w-3.5":"h-3 w-3"}):s.jsx(On,{className:f?"h-3.5 w-3.5":"h-3 w-3"}),s.jsx("span",{children:"Pinned"}),s.jsx("span",{className:"ml-auto typography-micro text-muted-foreground/60 normal-case tracking-normal",children:te.length})]}),B&&te.map(({name:H,path:K})=>ne(H,K)),r==="dropdown"&&s.jsx(Zn,{}),r==="inline"&&B&&s.jsx("div",{className:"mx-3 my-2 border-t border-border/40"})]}),s.jsx("div",{className:Q("typography-meta font-medium text-muted-foreground/80 flex items-center gap-1.5 uppercase tracking-wide",f?"px-1.5 py-1":"px-2 py-1.5"),children:"Browse"}),b?s.jsx("div",{className:"px-3 py-2 typography-ui-label text-muted-foreground",children:"Loading..."}):h.map(H=>xe(H)),!b&&h.length===0&&s.jsx("div",{className:"px-3 py-2 typography-ui-label text-muted-foreground",children:"No directories found"})]}):s.jsx("div",{className:"px-3 py-2 typography-ui-label text-muted-foreground",children:"Locating home directory..."})});return r==="inline"?s.jsx("div",{className:Q("overflow-hidden flex flex-col",o),children:s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"w-full py-1",children:O})}):s.jsxs(qs,{open:y,onOpenChange:w,children:[s.jsx(Gs,{asChild:!0,children:s.jsxs(Be,{variant:"ghost",className:Q("w-full h-8 px-2.5 justify-between items-center rounded-lg border border-transparent bg-sidebar-accent/40 text-foreground/90 hover:bg-sidebar-accent/60 typography-meta",n),"aria-label":"Select working directory",children:[s.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:[s.jsx(Pa,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"truncate",title:t,children:va(t,C)})]}),s.jsx(Ds,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Ys,{align:"start",className:"w-[350px]",children:s.jsx(ks,{outerClassName:"h-full",className:"w-full",children:O})})]})},eg=d.forwardRef((t,e)=>{const n=Fe.c(40),{inputValue:r,homeDirectory:o,onSelectSuggestion:a,visible:l,onClose:i,showHidden:c}=t;let u;n[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],n[0]=u):u=n[0];const[m,f]=d.useState(u),[h,p]=d.useState(!1),[g,x]=d.useState(0),b=d.useRef(null);let v;n[1]===Symbol.for("react.memo_cache_sentinel")?(v=[],n[1]=v):v=n[1];const y=d.useRef(v),w=EZ;let C;n[2]!==o?(C=Y=>Y.startsWith("~")&&o?Y.replace(/^~/,o):Y,n[2]=o,n[3]=C):C=n[3];const N=C;let S;n[4]!==N?(S=Y=>{const J=N(Y);if(J.endsWith("/"))return J;const V=J.lastIndexOf("/");return V===-1?"":V===0?"/":J.substring(0,V+1)},n[4]=N,n[5]=S):S=n[5];const k=S;let j;n[6]!==N?(j=Y=>{const J=N(Y);if(J.endsWith("/"))return"";const V=J.lastIndexOf("/");return V===-1?J:J.substring(V+1)},n[6]=N,n[7]=j):j=n[7];const F=j,A=Z1(r,150);let M,B;n[8]!==A||n[9]!==k||n[10]!==F||n[11]!==c||n[12]!==l?(M=()=>{if(!l||!A){f([]);return}const Y=k(A),J=F(A).toLowerCase();if(!Y){f([]);return}let V=!1;return p(!0),En.listLocalDirectory(Y).then(te=>{if(V)return;const U=te.filter($=>!(!$.isDirectory||!c&&$.name.startsWith("."))),X=J?U.map($=>{const q=w(J,$.name);return q!==null?{entry:$,score:q}:null}).filter(DZ).sort(IZ).map(TZ):U.sort(PZ);f(X.slice(0,10)),x(0)}).catch(()=>{V||f([])}).finally(()=>{V||p(!1)}),()=>{V=!0}},B=[l,A,k,F,c,w],n[8]=A,n[9]=k,n[10]=F,n[11]=c,n[12]=l,n[13]=M,n[14]=B):(M=n[13],B=n[14]),d.useEffect(M,B);let E,I;n[15]!==g?(E=()=>{y.current[g]?.scrollIntoView({behavior:"smooth",block:"nearest"})},I=[g],n[15]=g,n[16]=E,n[17]=I):(E=n[16],I=n[17]),d.useEffect(E,I);let P,D;n[18]!==i||n[19]!==l?(P=()=>{if(!l)return;const Y=J=>{const V=J.target;!V||!b.current||b.current.contains(V)||i()};return document.addEventListener("pointerdown",Y,!0),()=>{document.removeEventListener("pointerdown",Y,!0)}},D=[l,i],n[18]=i,n[19]=l,n[20]=P,n[21]=D):(P=n[20],D=n[21]),d.useEffect(P,D);let L;n[22]!==a?(L=Y=>{const J=Y.path.endsWith("/")?Y.path:Y.path+"/";a(J)},n[22]=a,n[23]=L):L=n[23];const T=L;let _,z;if(n[24]!==T||n[25]!==i||n[26]!==g||n[27]!==m||n[28]!==l?(_=()=>({handleKeyDown:Y=>{if(!l||m.length===0)return!1;const J=m.length;if(Y.key==="Tab"){if(Y.preventDefault(),Y.shiftKey)x(V=>(V-1+J)%J);else if(J===1){const V=m[0];V&&T(V)}else x(V=>(V+1)%J);return!0}if(Y.key==="ArrowDown")return Y.preventDefault(),x(V=>(V+1)%J),!0;if(Y.key==="ArrowUp")return Y.preventDefault(),x(V=>(V-1+J)%J),!0;if(Y.key==="Enter"){Y.preventDefault();const V=(g%J+J)%J,te=m[V];return te&&T(te),i(),!0}return Y.key==="Escape"?(Y.preventDefault(),i(),!0):!1}}),z=[l,m,g,T,i],n[24]=T,n[25]=i,n[26]=g,n[27]=m,n[28]=l,n[29]=_,n[30]=z):(_=n[29],z=n[30]),d.useImperativeHandle(e,_,z),!l||m.length===0&&!h)return null;let R;n[31]!==T||n[32]!==h||n[33]!==i||n[34]!==g||n[35]!==m?(R=h?s.jsx("div",{className:"flex items-center justify-center py-3",children:s.jsx(Qn,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):s.jsx("div",{className:"overflow-y-auto py-1",children:m.map((Y,J)=>{const V=g===J;return s.jsxs("div",{ref:te=>{y.current[J]=te},className:Q("flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label",V&&"bg-interactive-selection"),onClick:()=>{T(Y),i()},onMouseEnter:()=>x(J),children:[s.jsx(jr,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Y.name})]},Y.path)})}),n[31]=T,n[32]=h,n[33]=i,n[34]=g,n[35]=m,n[36]=R):R=n[36];let W;n[37]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx("div",{className:"px-3 py-1.5 border-t typography-meta text-muted-foreground bg-sidebar/50",children:"Tab cycle • ↑↓ navigate • Enter select"}),n[37]=W):W=n[37];let G;return n[38]!==R?(G=s.jsxs("div",{ref:b,className:"absolute z-[100] w-full max-h-48 bg-background border border-border rounded-lg shadow-none top-full mt-1 left-0 flex flex-col overflow-hidden",children:[R,W]}),n[38]=R,n[39]=G):G=n[39],G});eg.displayName="DirectoryAutocomplete";function EZ(t,e){const n=t.trim().toLowerCase();if(!n)return 0;const r=e.toLowerCase();let o=0,a=-1,l=0;for(let i=0;i<n.length;i=i+1,i){const c=n[i];if(!c||c===" ")continue;const u=r.indexOf(c,a+1);if(u===-1)return null;const m=u-a-1;if(m===0?l=l+1:l=0,o=o+10,o=o+Math.max(0,18-u),o=o-Math.max(0,m),u===0)o=o+12;else{const f=r[u-1];(f==="/"||f==="_"||f==="-"||f==="."||f===" ")&&(o=o+10)}o=o+(l>0?12:0),a=u}return o=o+Math.max(0,24-Math.round(r.length/3)),o}function DZ(t){return t!==null}function IZ(t,e){return e.score-t.score||t.entry.name.localeCompare(e.entry.name)}function TZ(t){return t.entry}function PZ(t,e){return t.name.localeCompare(e.name)}const RZ=({open:t,onOpenChange:e})=>{const{currentDirectory:n,homeDirectory:r,isHomeReady:o}=dn(),{addProject:a,getActiveProject:l}=vs(),[i,c]=d.useState(null),[u,m]=d.useState(""),[f,h]=d.useState(!1),[p,g]=d.useState(!1),x=q1(),{isDesktop:b,requestAccess:v,startAccessing:y}=rc(),{isMobile:w}=wn(),[C,N]=d.useState(!1),S=d.useRef(null),k=d.useCallback(J=>J?va(J,r):"",[r]);d.useEffect(()=>{if(t){h(!1),g(!1),N(!1);const V=l()?.path||n||r||"";c(V),m(k(V))}},[t,n,r,k,l]),d.useEffect(()=>{!t||f||i||r&&o&&(c(r),h(!0),m("~"))},[t,f,i,r,o]);const j=d.useCallback(()=>{e(!1)},[e]),F=d.useCallback(async J=>{if(!(!J||p)){g(!0);try{let V=J,te;if(b){const X=await v(J);if(!X.success){fe.error("Unable to access directory",{description:X.error||"Desktop denied directory access."});return}V=X.path??J,te=X.projectId;const $=await y(V);if(!$.success){fe.error("Failed to open directory",{description:$.error||"Desktop could not grant file access."});return}}if(!a(V,{id:te})){fe.error("Failed to add project",{description:"Please select a valid directory path."});return}j()}catch(V){fe.error("Failed to select directory",{description:V instanceof Error?V.message:"Unknown error occurred."})}finally{g(!1)}}},[a,j,b,v,y,p]),A=d.useCallback(async()=>{const J=u.trim()||i;J&&await F(J)},[F,u,i]),M=d.useCallback(J=>{c(J),h(!0),m(k(J))},[k]),B=d.useCallback(async J=>{c(J),h(!0),m(k(J)),await F(J)},[F,k]),E=d.useCallback(J=>{const V=J.target.value;if(m(V),h(!0),N(V.startsWith("/")||V.startsWith("~")),V.startsWith("/")||V.startsWith("~")){const te=V.startsWith("~")&&r?V.replace(/^~/,r):V;c(te)}},[r]),I=d.useCallback(J=>{S.current?.handleKeyDown(J)||J.key==="Enter"&&(J.preventDefault(),A())},[A]),P=d.useCallback(J=>{c(J),h(!0),m(k(J))},[k]),D=d.useCallback(()=>{N(!1)},[]),L=d.useCallback(()=>{H0(!x)},[x]),T=s.jsxs("button",{type:"button",onClick:L,className:"flex items-center gap-2 px-2 py-1 rounded-lg hover:bg-interactive-hover/40 transition-colors typography-meta text-muted-foreground flex-shrink-0",children:[x?s.jsx(Jo,{className:"h-4 w-4 text-primary"}):s.jsx(ea,{className:"h-4 w-4"}),"Show hidden"]}),_=s.jsxs(Zs,{className:"flex-shrink-0 px-4 pb-2 pt-[calc(var(--oc-safe-area-top,0px)+0.5rem)] sm:px-0 sm:pb-3 sm:pt-0",children:[s.jsx(Us,{children:"Add project directory"}),s.jsxs("div",{className:"hidden sm:flex sm:items-center sm:justify-between sm:gap-4",children:[s.jsx(sn,{className:"flex-1",children:"Choose a folder to add as a project."}),T]})]}),z=s.jsxs("div",{className:"relative",children:[s.jsx(Xt,{value:u,onChange:E,onKeyDown:I,placeholder:"Enter path or select from tree...",className:"font-mono typography-meta",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),s.jsx(eg,{ref:S,inputValue:u,homeDirectory:r,onSelectSuggestion:P,visible:C,onClose:D,showHidden:x})]}),R=s.jsx("div",{className:"flex-1 min-h-0 rounded-xl border border-border/40 bg-sidebar/70 overflow-hidden flex flex-col",children:s.jsx(dh,{variant:"inline",currentPath:i??n,onSelectPath:M,onDoubleClickPath:B,className:"flex-1 min-h-0 sm:min-h-[280px] sm:max-h-[380px]",selectionBehavior:"deferred",showHidden:x,rootDirectory:o?r:null,isRootReady:o})}),W=s.jsxs("div",{className:"flex flex-col gap-3 h-full",children:[s.jsx("div",{className:"flex-shrink-0",children:z}),s.jsx("div",{className:"flex-shrink-0 flex items-center justify-end",children:T}),s.jsx("div",{className:"flex-1 min-h-0 rounded-xl border border-border/40 bg-sidebar/70 overflow-hidden flex flex-col",children:s.jsx(dh,{variant:"inline",currentPath:i??n,onSelectPath:M,onDoubleClickPath:B,className:"flex-1 min-h-0",selectionBehavior:"deferred",showHidden:x,rootDirectory:o?r:null,isRootReady:o,alwaysShowActions:!0})})]}),G=s.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col gap-3",children:[z,R]}),Y=()=>s.jsxs(s.Fragment,{children:[s.jsx(Be,{variant:"ghost",onClick:j,disabled:p,className:"flex-1 sm:flex-none sm:w-auto",children:"Cancel"}),s.jsx(Be,{onClick:A,disabled:p||!f||!i&&!u.trim(),className:"flex-1 sm:flex-none sm:w-auto sm:min-w-[140px]",children:p?"Adding...":"Add Project"})]});return w?s.jsx(cr,{open:t,onClose:()=>e(!1),title:"Add project directory",className:"max-w-full",contentMaxHeightClassName:"max-h-[min(70vh,520px)] h-[min(70vh,520px)]",footer:s.jsx("div",{className:"flex flex-row gap-2",children:Y()}),children:W}):s.jsx(Os,{open:t,onOpenChange:e,children:s.jsxs(Vs,{className:Q("flex w-full max-w-[min(560px,100vw)] max-h-[calc(100vh-32px)] flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh] sm:max-w-xl sm:p-6"),onOpenAutoFocus:J=>{J.preventDefault()},children:[_,G,s.jsx(yn,{className:"sticky bottom-0 flex w-full flex-shrink-0 flex-row gap-2 border-t border-border/40 bg-sidebar px-4 py-3 sm:static sm:justify-end sm:border-0 sm:bg-transparent sm:px-0 sm:pt-4 sm:pb-0",children:Y()})]})})},dl=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,So=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},zZ=()=>{const[t,e]=d.useState(!1),[n,r]=d.useState(!1),[o,a]=d.useState(null),[l,i]=d.useState([]),[c,u]=d.useState(!1),[m,f]=d.useState(!1),[h,p]=d.useState(!1),[g,x]=d.useState(!1),[b,v]=d.useState(new Set),{deleteSession:y,deleteSessions:w,archiveSession:C,archiveSessions:N,loadSessions:S,getWorktreeMetadata:k,newSessionDraft:j,setNewSessionDraftTarget:F,setDraftBootstrapPendingDirectory:A}=Ze(),M=Ee(Z=>Z.showDeletionDialog),B=Ee(Z=>Z.setShowDeletionDialog),{currentDirectory:E,homeDirectory:I,isHomeReady:P}=dn(),{projects:D,addProject:L,activeProjectId:T}=vs(),{requestAccess:_,startAccessing:z}=rc(),{isMobile:R,isTablet:W,hasTouchInput:G}=wn(),Y=R||W||G,J=d.useMemo(()=>{const ie=(T?D.find(pe=>pe.id===T)??null:null)?.path??E;return So(ie)},[T,E,D]),V=d.useCallback(Z=>{const pe=So(Z.projectDirectory)||J;return{id:(D.find(Se=>So(Se.path)===pe)??null)?.id??`path:${pe}`,path:pe}},[J,D]),te=g&&b.size>0,U=d.useMemo(()=>{const Z=o?.worktree;return Z&&typeof Z.branch=="string"&&Z.branch.trim().length>0?!0:l.length>0&&l.every(({metadata:ie})=>typeof ie.branch=="string"&&ie.branch.trim().length>0)},[o?.worktree,l]),X=o?.mode==="worktree",$=X,q=h||!X||!U,ee=h||!X;d.useEffect(()=>{S()},[S,E]);const ce=d.useMemo(()=>D.map(Z=>`${Z.id}:${Z.path}`).join("|"),[D]),ve=d.useRef(ce);d.useEffect(()=>{ce!==ve.current&&(ve.current=ce,S())},[S,ce]),d.useEffect(()=>{if(!(n||!P||D.length>0)){if(r(!0),Rn()&&$o()){_("").then(async Z=>{if(!Z.success||!Z.path){Z.error&&Z.error!=="Directory selection cancelled"&&fe.error("Failed to select directory",{description:Z.error});return}const ie=await z(Z.path);if(!ie.success){fe.error("Failed to open directory",{description:ie.error||"Desktop could not grant file access."});return}L(Z.path,{id:Z.projectId})||fe.error("Failed to add project",{description:"Please select a valid directory path."})}).catch(Z=>{console.error("Desktop: Error selecting directory:",Z),fe.error("Failed to select directory")});return}e(!0)}},[L,n,P,D.length,_,z]);const ge=d.useCallback(Z=>{a({sessions:Z.sessions,dateLabel:Z.dateLabel,mode:Z.mode??"session",worktree:Z.worktree??null})},[]),xe=d.useCallback(()=>{a(null),i([]),u(!1),f(!1),p(!1),x(!1),v(new Set)},[]),ne=d.useCallback(async Z=>{if(Z.sessions.length===0)return;if(Z.sessions.length===1){const Se=Z.sessions[0];await y(Se.id)?fe.success("Session deleted"):fe.error("Failed to delete session");return}const ie=Z.sessions.map(Se=>Se.id),{deletedIds:pe,failedIds:me}=await w(ie);if(pe.length>0){const Se=me.length>0?`${me.length} session${me.length===1?"":"s"} could not be deleted.`:Z.dateLabel?`Removed all sessions from ${Z.dateLabel}.`:void 0;fe.success(`Deleted ${pe.length} session${pe.length===1?"":"s"}`,{description:dl(Se)})}me.length>0&&fe.error(`Failed to delete ${me.length} session${me.length===1?"":"s"}`,{description:dl("Please try again in a moment.")})},[y,w]);d.useEffect(()=>na.onDeleteRequest(Z=>{if(!M&&(Z.mode??"session")==="session"){ne(Z);return}ge(Z)}),[ge,M,ne]),d.useEffect(()=>na.onDirectoryRequest(()=>{e(!0)}),[]),d.useEffect(()=>{if(!o){i([]),u(!1),f(!1),x(!1),v(new Set);return}const Z=o.sessions.map(me=>{const Se=k(me.id);return Se?{session:me,metadata:Se}:null}).filter(me=>!!me);i(Z),u(!1),x(!1),v(new Set);const ie=new Map;if(o.worktree?.path&&ie.set(So(o.worktree.path),o.worktree),Z.forEach(({metadata:me})=>{me.path&&ie.set(So(me.path),me)}),ie.size===0){x(!0);return}let pe=!1;return(async()=>{const me=new Map,Se=new Set;await Promise.all(Array.from(ie.entries()).map(async([ke,ye])=>{try{const Ne=await Nv(ye.path);me.set(ke,Ne),Ne?.isDirty&&Se.add(ke)}catch{ye.status&&(me.set(ke,ye.status),ye.status.isDirty&&Se.add(ke))}})).catch(ke=>{console.warn("Failed to inspect worktree status before deletion:",ke)}),!pe&&(v(Se),x(!0),a(ke=>{if(!ke?.worktree?.path)return ke;const ye=So(ke.worktree.path),Ne=me.get(ye);if(!Ne)return ke;const _e=ke.worktree.status;return _e?.isDirty===Ne.isDirty&&_e?.ahead===Ne.ahead&&_e?.behind===Ne.behind&&_e?.upstream===Ne.upstream?ke:{...ke,worktree:{...ke.worktree,status:Ne}}}),i(ke=>ke.map(ye=>{const Ne=So(ye.metadata.path),_e=me.get(Ne);return _e?{session:ye.session,metadata:{...ye.metadata,status:_e}}:ye})))})(),()=>{pe=!0}},[o,k]),d.useEffect(()=>{U||u(!1)},[U]);const O=d.useCallback(async(Z,ie)=>{const pe=c&&U,me=V(Z),Se=So(Z.path),ke=So(me.path);try{await F6(me,Z,{deleteRemoteBranch:pe,deleteLocalBranch:ie});const ye=So(j?.directoryOverride);return j?.open&&Se&&ye===Se&&ke&&(A(null),F({projectId:me.id,directoryOverride:ke},{force:!0})),So(E)===Se&&ke&&dn.getState().setDirectory(ke,{showOverlay:!1}),!0}catch(ye){return fe.error("Failed to remove worktree",{description:dl(ye instanceof Error?ye.message:"Please try again.")}),!1}},[U,E,c,V,j?.directoryOverride,j?.open,A,F]),H=d.useCallback(async()=>{if(o){p(!0);try{const Z=$,ie=Z&&c,pe=Z&&m;if(o.sessions.length===0&&X&&o.worktree){if(!await O(o.worktree,pe)){xe();return}const ke=c&&U?"Worktree and remote branch removed.":"Worktree removed.";fe.success("Worktree removed",{description:dl(ke)}),xe(),S();return}if(o.sessions.length===1){const me=o.sessions[0];if(!(X?await C(me.id):await y(me.id,{archiveWorktree:!1,deleteRemoteBranch:ie,deleteLocalBranch:pe}))){fe.error(X?"Failed to archive session":"Failed to delete session"),p(!1);return}const ke=!X&&Z?ie?"Worktree and remote branch removed.":"Attached worktree archived.":void 0;fe.success(X?"Session archived":"Session deleted",{description:dl(ke),action:{label:"OK",onClick:()=>{}}})}else{const me=o.sessions.map(ye=>ye.id);let Se=[],ke=[];if(X){const ye=await N(me);Se=ye.archivedIds,ke=ye.failedIds}else{const ye=await w(me,{archiveWorktree:!1,deleteRemoteBranch:ie,deleteLocalBranch:pe});Se=ye.deletedIds,ke=ye.failedIds}if(X&&o.worktree&&ke.length===0&&await O(o.worktree,pe)&&await S(),Se.length>0){const ye=!X&&Z?ie?"Archived worktrees and removed remote branches.":"Attached worktrees archived.":void 0,_e=[ke.length>0?`${ke.length} session${ke.length===1?"":"s"} could not be ${X?"archived":"deleted"}.`:o.dateLabel?`Removed all sessions from ${o.dateLabel}.`:void 0,ye].filter(Boolean).join(" ");fe.success(`${X?"Archived":"Deleted"} ${Se.length} session${Se.length===1?"":"s"}`,{description:dl(_e||void 0),action:{label:"OK",onClick:()=>{}}})}if(ke.length>0&&(fe.error(`Failed to ${X?"archive":"delete"} ${ke.length} session${ke.length===1?"":"s"}`,{description:dl("Please try again in a moment.")}),Se.length===0)){p(!1);return}}X&&o.sessions.length===1&&o.worktree&&await O(o.worktree,pe)&&await S(),xe()}finally{p(!1)}}},[o,c,m,y,w,C,N,xe,$,X,U,O,S]),K=o?.worktree??l[0]?.metadata??null,re=o?o.mode==="worktree"?o.sessions.length===0?"This removes the selected worktree.":`This removes the selected worktree and archives ${o.sessions.length===1?"1 linked session":`${o.sessions.length} linked sessions`}.`:`This action permanently removes ${o.sessions.length===1?"1 session":`${o.sessions.length} sessions`}${o.dateLabel?` from ${o.dateLabel}`:""}.`:"",le=o?s.jsxs("div",{className:Q(X?"space-y-3":"space-y-2"),children:[o.sessions.length>0&&s.jsxs("div",{className:Q(X?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[X&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:o.sessions.length===1?"Linked session":"Linked sessions"}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:o.sessions.length})]}),s.jsxs("ul",{className:Q(X?"mt-2 space-y-1":"space-y-0.5"),children:[o.sessions.slice(0,5).map(Z=>s.jsxs("li",{className:Q(X?"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:Q(!X&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:Z.title||"Untitled Session"})]},Z.id)),o.sessions.length>5&&s.jsxs("li",{className:Q(X?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:["+",o.sessions.length-5," more"]})]})]}),X?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(on,{className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:"Worktree"}),K?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:K.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:K?va(K.path,I):"Worktree path unavailable."}),te&&s.jsx("p",{className:"typography-micro text-status-warning",children:"Uncommitted changes will be discarded."})]}):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:"Worktree directories stay intact. Subsessions linked to the selected sessions will also be removed."})})]}):null,ae=X?U?s.jsxs("button",{type:"button",onClick:()=>{q||u(Z=>!Z)},disabled:q,className:Q("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",q?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[c?s.jsx(Jo,{className:"size-4 text-primary"}):s.jsx(ea,{className:"size-4"}),"Delete remote branch"]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:"Remote branch info unavailable"}):null,ue=X?s.jsxs("button",{type:"button",onClick:()=>{ee||f(Z=>!Z)},disabled:ee,className:Q("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",ee?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[m?s.jsx(Jo,{className:"size-4 text-primary"}):s.jsx(ea,{className:"size-4"}),"Delete local branch"]}):null,be=X?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:[ue,ae]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{variant:"ghost",onClick:xe,disabled:h,children:"Cancel"}),s.jsx(Be,{variant:"destructive",onClick:H,disabled:h,children:h?"Deleting…":"Delete worktree"})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>B(!M),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":!M,children:[M?s.jsx(ea,{className:"size-4"}):s.jsx(Jo,{className:"size-4 text-primary"}),"Never ask"]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{variant:"ghost",onClick:xe,disabled:h,children:"Cancel"}),s.jsx(Be,{variant:"destructive",onClick:H,disabled:h,children:h?"Deleting…":o?.sessions.length===1?"Delete session":"Delete sessions"})]})]}),oe=X?"Delete worktree":o?.sessions.length===1?"Delete session":"Delete sessions";return s.jsxs(s.Fragment,{children:[Y?s.jsx(cr,{open:!!o,onClose:()=>{h||xe()},title:oe,footer:s.jsx("div",{className:"flex justify-end gap-2",children:be}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[re&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:re}),le]})}):s.jsx(Os,{open:!!o,onOpenChange:Z=>{if(!Z){if(h)return;xe()}},children:s.jsxs(Vs,{className:Q(X?"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(Zs,{children:[s.jsxs(Us,{className:Q(X&&"flex items-center gap-2"),children:[X&&s.jsx(Pn,{className:"h-5 w-5"}),oe]}),re&&s.jsx(sn,{children:re})]}),s.jsx("div",{className:Q(X&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:le}),s.jsx(yn,{className:"mt-2 gap-2 pt-1 pb-1",children:be})]})}),s.jsx(RZ,{open:t,onOpenChange:e})]})},LZ=d.lazy(()=>Kn(()=>Promise.resolve().then(()=>uz),void 0).then(t=>({default:t.PlanView}))),uh=d.lazy(()=>Kn(()=>Promise.resolve().then(()=>HL),void 0).then(t=>({default:t.GitView}))),HZ=d.lazy(()=>Kn(()=>Promise.resolve().then(()=>CH),void 0).then(t=>({default:t.DiffView}))),fh=d.lazy(()=>Kn(()=>import("./TerminalView-BYycNet-.js"),__vite__mapDeps([6,0,1,3,4])).then(t=>({default:t.TerminalView}))),$Z=d.lazy(()=>Kn(()=>Promise.resolve().then(()=>ZH),void 0).then(t=>({default:t.FilesView}))),OZ=d.lazy(()=>Kn(()=>Promise.resolve().then(()=>WU),void 0).then(t=>({default:t.SettingsView}))),VZ=d.lazy(()=>Kn(()=>import("./SettingsWindow-SRJdxJbx.js"),__vite__mapDeps([7,0,1,3,4])).then(t=>({default:t.SettingsWindow}))),UZ=d.lazy(()=>Kn(()=>import("./MultiRunWindow-DWSqqb1U.js"),__vite__mapDeps([8,0,1,3,4])).then(t=>({default:t.MultiRunWindow}))),F0=85,WZ=250,qZ=500,GZ=400,ZZ=860,KZ=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},YZ=()=>{const{isSidebarOpen:o,isRightSidebarOpen:a,isBottomTerminalOpen:l,setRightSidebarOpen:i,setBottomTerminalOpen:c,activeMainTab:u,setIsMobile:m,isSessionSwitcherOpen:f,isSettingsDialogOpen:h,setSettingsDialogOpen:p,isMultiRunLauncherOpen:g,setMultiRunLauncherOpen:x,multiRunLauncherPrefillPrompt:b}=Ee(),{isMobile:v}=wn(),y=d.useMemo(()=>Rn(),[]),w=Ee(V=>V.sidebarWidth),C=Ee(V=>V.rightSidebarWidth),[N,S]=d.useState(null),k=Ca()??"",j=d.useMemo(()=>KZ(k),[k]),F=Ee(V=>{if(!j)return!1;const te=V.contextPanelByDirectory[j],U=te?.tabs??[],X=U.find($=>$.id===te?.activeTabId)??U[U.length-1];return!!(te?.isOpen&&X)}),A=Ee(V=>V.setSidebarOpen),M=d.useRef(!1),B=d.useRef(!1),E=d.useRef(!1),[I,P]=d.useState(!1),D=d.useRef(!1),L=I3(0),T=he.useRef(0),_=I3(0),z=he.useRef(0);he.useEffect(()=>{v&&(T.current=window.innerWidth*(F0/100),z.current=window.innerWidth*(F0/100))},[v]),he.useEffect(()=>{if(!v)return;const V=I?0:-T.current;ml(L,V,{type:"spring",stiffness:400,damping:35,mass:.8})},[I,v,L]),he.useEffect(()=>{if(!v)return;D.current=a;const V=a?0:z.current;ml(_,V,{type:"spring",stiffness:400,damping:35,mass:.8})},[v,a,_]),he.useEffect(()=>{v&&P(f)},[f,v]),he.useEffect(()=>{v&&(D.current=a)},[a,v]);const R=Sl(V=>V.checkForUpdates);d.useEffect(()=>{let $=!1,q=null;const ee=ve=>{const ge=Math.round(ve*1e3);return Math.max(3e5,Math.min(864e5,ge))},ce=ve=>{$||(q=window.setTimeout(async()=>{const ge=await R(),xe=typeof ge=="number"&&Number.isFinite(ge)?ee(ge):36e5;ce(xe)},ve))};return ce(3e3),()=>{$=!0,q!==null&&window.clearTimeout(q)}},[R]),d.useEffect(()=>{Ee.getState().isMobile!==v&&m(v)},[v,m]),d.useEffect(()=>{if(typeof window>"u")return;let V;const te=()=>{V!==void 0&&window.clearTimeout(V),V=window.setTimeout(()=>{Ee.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",te),()=>{window.removeEventListener("resize",te),V!==void 0&&window.clearTimeout(V)}},[]),d.useEffect(()=>{if(F){Ee.getState().isSidebarOpen&&(A(!1),E.current=!0);return}E.current&&(A(!0),E.current=!1)},[F,A]),d.useEffect(()=>{if(typeof window>"u")return;let V;const te=()=>{const X=Ee.getState(),$=window.innerWidth,q=window.innerHeight,ee=$<1140,ce=$>=1220;ee?X.isRightSidebarOpen&&(i(!1),M.current=!0):ce&&M.current&&(i(!0),M.current=!1);const ve=q<640,ge=q>=700;ve?X.isBottomTerminalOpen&&(c(!1),B.current=!0):ge&&B.current&&(c(!0),B.current=!1)},U=()=>{V!==void 0&&window.clearTimeout(V),V=window.setTimeout(()=>{te()},100)};return te(),window.addEventListener("resize",U),()=>{window.removeEventListener("resize",U),V!==void 0&&window.clearTimeout(V)}},[c,i]),d.useEffect(()=>{if(typeof window>"u")return;const V=Ee.subscribe((te,U)=>{const X=window.innerWidth,$=window.innerHeight,q=X>=1220,ee=$>=700;te.isRightSidebarOpen!==U.isRightSidebarOpen&&q&&(M.current=!1),te.isBottomTerminalOpen!==U.isBottomTerminalOpen&&ee&&(B.current=!1)});return()=>{V()}},[]),d.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const V=document.documentElement;let te=0,U=!1,X=0,$=null;const q=Ee.getState().setKeyboardOpen,ee=()=>{$&&($.style.setProperty("--oc-keyboard-avoid-offset","0px"),$.removeAttribute("data-keyboard-avoid-active"),$=null)},ce=le=>{if(!le)return null;const ae=le.getAttribute("data-keyboard-avoid-target-id");if(ae){const be=document.getElementById(ae);if(be instanceof HTMLElement)return be}const ue=le.closest("[data-keyboard-avoid]");if(ue)return ue.getAttribute("data-keyboard-avoid")==="none"?null:ue;if(le.classList.contains("overlay-scrollbar-container")){const be=le.parentElement;if(be instanceof HTMLElement)return be}return le},ve=()=>{te=0,U=!0,V.style.setProperty("--oc-keyboard-inset","0px"),q(!1)};let ge=0;const xe=()=>{const le=window.visualViewport,ae=le?Math.round(le.height):window.innerHeight,ue=le?Math.max(0,Math.round(le.offsetTop)):0;V.style.setProperty("--oc-visual-viewport-offset-top",`${ue}px`);const be=document.activeElement,oe=be?.tagName,ie=oe==="INPUT"||oe==="TEXTAREA"||oe==="SELECT"||!!be?.isContentEditable,pe=Math.round(V.clientHeight||window.innerHeight),me=ae+ue,Se=Math.max(0,pe-me),ye=Se>=(ie?120:180)?Se:0;if(U)ye===0&&(U=!1),te=0;else if(te===0)ye>0&&ie&&(te=ye);else{const we=!ie&&ae>X+6;ye===0?(te=0,q(!1)):we?ve():(ye>0&&ie||ye>te)&&(te=ye,q(!0))}V.style.setProperty("--oc-keyboard-inset",`${te}px`),X=ae;const _e=/iPad|iPhone|iPod/.test(navigator.userAgent)&&te>0?34:0;V.style.setProperty("--oc-keyboard-home-indicator",`${_e}px`);const de=ie?ce(be):null;if(!v||!de||!be)ee();else{de!==$&&(ee(),$=de);const we=ue+ae,Ce=be.getBoundingClientRect().bottom-we,ze=8,Ge=Math.max(te,ye),Le=Ce>ze&&Ge>0?Math.min(Ce,Ge):0,qe=$;qe&&(qe.style.setProperty("--oc-keyboard-avoid-offset",`${Le}px`),qe.setAttribute("data-keyboard-avoid-active","true"))}if(v&&ie){const we=document.scrollingElement;we&&we.scrollTop!==0&&(we.scrollTop=0),window.scrollY!==0&&window.scrollTo(0,0)}},ne=()=>{ge||(ge=requestAnimationFrame(()=>{ge=0,xe()}))};xe();const O=window.visualViewport;O?.addEventListener("resize",ne),O?.addEventListener("scroll",ne),window.addEventListener("resize",ne),window.addEventListener("orientationchange",ne);const H=le=>{if(!le)return!1;const ae=le.tagName;return ae==="INPUT"||ae==="TEXTAREA"||ae==="SELECT"||le.isContentEditable},K=le=>{const ae=le.target;H(ae)&&(U=!1),ne()};document.addEventListener("focusin",K,!0);const re=le=>{const ae=le.target;if(!H(ae))return;const ue=le.relatedTarget;H(ue)||window.requestAnimationFrame(()=>{if(H(document.activeElement))return;const be=window.visualViewport,oe=be?Math.round(be.height):window.innerHeight,Z=be?Math.max(0,Math.round(be.offsetTop)):0,ie=Math.round(V.clientHeight||window.innerHeight),pe=oe+Z;if(Math.max(0,ie-pe)>0){xe();return}ve(),xe()})};return document.addEventListener("focusout",re,!0),()=>{ge&&cancelAnimationFrame(ge),O?.removeEventListener("resize",ne),O?.removeEventListener("scroll",ne),window.removeEventListener("resize",ne),window.removeEventListener("orientationchange",ne),document.removeEventListener("focusin",K,!0),document.removeEventListener("focusout",re,!0),ee()}},[v]);const W=d.useMemo(()=>{const V=(()=>{switch(u){case"plan":return s.jsx(LZ,{});case"git":return s.jsx(uh,{});case"diff":return s.jsx(HZ,{});case"terminal":return s.jsx(fh,{});case"files":return s.jsx($Z,{});default:return null}})();return u!=="chat"?s.jsx(d.Suspense,{fallback:s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsx("div",{className:"animate-pulse",children:"Loading..."})}),children:V}):null},[u]),G=u==="chat",Y=d.useMemo(()=>Math.min(qZ,Math.max(WZ,w||Od)),[w]),J=d.useMemo(()=>Math.min(ZZ,Math.max(GZ,C||p8)),[C]);return s.jsx(WL,{children:s.jsxs("div",{className:Q("main-content-safe-area h-[100dvh]",v?"flex flex-col":"flex",y?"bg-transparent":"bg-background"),children:[s.jsx(Nq,{}),s.jsx(Aq,{}),s.jsx(Fq,{}),s.jsx(zZ,{}),v?s.jsxs($N,{value:{leftDrawerOpen:I,rightDrawerOpen:a,toggleLeftDrawer:()=>{a&&i(!1),P(!I)},toggleRightDrawer:()=>{I&&P(!1),i(!a)},leftDrawerX:L,rightDrawerX:_,leftDrawerWidth:T,rightDrawerWidth:z,setMobileLeftDrawerOpen:P,setRightSidebarOpen:i},children:[!h&&s.jsx(w4,{onToggleLeftDrawer:()=>{a&&i(!1),P(!I)},onToggleRightDrawer:()=>{I&&P(!1),i(!a)},leftDrawerOpen:I,rightDrawerOpen:a}),s.jsx(fa.button,{type:"button",initial:!1,animate:{opacity:I||a?1:0,pointerEvents:I||a?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{P(!1),i(!1)},"aria-label":"Close drawer"}),s.jsx(fa.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(T.current||window.innerWidth*.85),right:0},style:{width:`${F0}%`,x:L},onDragEnd:(V,te)=>{const U=T.current||window.innerWidth*.85,X=U*.3,$=500,q=L.get(),ee=te.offset.x<-X||te.velocity.x<-$,ce=te.offset.x>X||te.velocity.x>$;ee?(L.set(-U),P(!1)):ce?(L.set(0),P(!0)):q>-U/2?L.set(0):L.set(-U)},className:Q("fixed left-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-transparent","cursor-grab active:cursor-grabbing"),"aria-hidden":!I,children:s.jsx("div",{className:"h-full overflow-hidden flex bg-[var(--surface-background)] shadow-none drawer-safe-area",style:{backgroundImage:"linear-gradient(var(--surface-muted), var(--surface-muted))"},children:s.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col",children:s.jsx(An,{children:s.jsx(_2,{mobileVariant:!0})})})})}),s.jsx(fa.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:z.current||window.innerWidth*.85},style:{width:`${F0}%`,x:_},onDragEnd:(V,te)=>{const U=z.current||window.innerWidth*.85,X=U*.3,$=500,q=_.get(),ee=te.offset.x>X||te.velocity.x>$,ce=te.offset.x<-X||te.velocity.x<-$;ee?(_.set(U),i(!1)):ce?(_.set(0),i(!0)):q<U/2?_.set(0):_.set(U)},className:Q("fixed right-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-transparent","cursor-grab active:cursor-grabbing"),"aria-hidden":!a,children:s.jsx("div",{className:"h-full overflow-hidden flex flex-col bg-background shadow-none drawer-safe-area",children:s.jsx(An,{children:s.jsx(uh,{})})})}),s.jsx("div",{className:Q("flex flex-1 overflow-hidden relative",h&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative",children:[s.jsx("div",{className:Q("absolute inset-0",!G&&"invisible"),children:s.jsx(An,{children:s.jsx(wi,{})})}),W&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(An,{children:W})}),g&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(An,{children:s.jsx(cW,{initialPrompt:b,onCreated:()=>x(!1),onCancel:()=>x(!1)})})})]})}),h&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(An,{children:s.jsx(d.Suspense,{fallback:null,children:s.jsx(OZ,{onClose:()=>p(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:Q("absolute inset-0 flex overflow-hidden",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar"),children:[o?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:Q("pointer-events-none absolute top-0 z-0",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar"),style:{left:`${Y}px`,width:"var(--radius-md)",height:"var(--radius-md)",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))"}}),s.jsx("div",{"aria-hidden":!0,className:Q("pointer-events-none absolute bottom-0 z-0",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar"),style:{left:`${Y}px`,width:"var(--radius-md)",height:"var(--radius-md)",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))"}})]}):null,a?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:Q("pointer-events-none absolute top-0 z-0",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar"),style:{right:`${J}px`,width:"var(--radius-md)",height:"var(--radius-md)",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))",maskImage:"radial-gradient(circle at 0 100%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))"}}),s.jsx("div",{"aria-hidden":!0,className:Q("pointer-events-none absolute bottom-0 z-0",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar"),style:{right:`${J}px`,width:"var(--radius-md)",height:"var(--radius-md)",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(var(--radius-md) - 1px), black var(--radius-md))",maskImage:"radial-gradient(circle at 0 0, transparent calc(var(--radius-md) - 1px), black var(--radius-md))"}})]}):null,s.jsx(_j,{isOpen:o,isMobile:v,className:"border-0",children:s.jsx(_2,{})}),s.jsxs("div",{className:Q("relative flex flex-1 min-w-0 flex-col overflow-hidden",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar",o&&"border-l border-border/50 rounded-tl-md rounded-bl-md",a&&"border-r border-border/50 rounded-tr-md rounded-br-md"),"data-blur-bg":!0,style:y?{WebkitBackdropFilter:"blur(20px)",backdropFilter:"blur(20px)"}:void 0,children:[s.jsx(w4,{desktopRightSidebarActionsHost:N}),s.jsx("div",{className:Q("flex flex-1 min-h-0 overflow-hidden",o||G?"":"border-l border-border/50",a?"":"border-r border-border/50"),children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative",children:[s.jsx("div",{className:Q("absolute inset-0",!G&&"invisible"),children:s.jsx(An,{children:s.jsx(wi,{})})}),W&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(An,{children:W})})]}),s.jsx(kq,{})]})}),s.jsx(Sj,{isOpen:l,isMobile:v,children:s.jsx(An,{children:s.jsx(fh,{})})})]}),s.jsx(Ej,{isOpen:a,className:"border-0",onTopActionsHostChange:S,children:s.jsx(An,{children:s.jsx($W,{})})})]})}),s.jsx(d.Suspense,{fallback:null,children:s.jsx(VZ,{open:h,onOpenChange:p})}),s.jsx(d.Suspense,{fallback:null,children:s.jsx(UZ,{open:g,onOpenChange:x,initialPrompt:b})})]})]})})},XZ=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},QZ=550,JZ=1400,eK=280,tK=()=>{const t=ur(),e=d.useMemo(()=>(typeof window<"u"?window.__VSCODE_CONFIG__?.viewMode:null)==="editor"?"editor":"sidebar",[]),n=d.useMemo(()=>{const D=typeof window<"u"?window.__VSCODE_CONFIG__?.initialSessionId:null;return typeof D=="string"&&D.trim().length>0?D.trim():null},[]),r=d.useRef(!1),o=d.useMemo(()=>{try{return!!Ze.getState().newSessionDraft?.open}catch{return!1}},[]),[a,l]=d.useState(()=>o?"chat":"sessions"),[i,c]=d.useState(0),u=d.useRef(null),m=Ze(D=>D.currentSessionId),f=Ze(D=>D.sessions),h=d.useMemo(()=>m?f.find(D=>D.id===m)?.title||"Session":null,[m,f]),p=Ze(D=>!!D.newSessionDraft?.open),g=Ze(D=>D.isSyncing),x=Ze(D=>{const L=D.sessionStatus;if(!L||L.size===0)return!1;for(const T of L.values())if(T?.type==="busy"||T?.type==="retry")return!0;return!1}),b=Ze(D=>D.openNewSessionDraft),[v,y]=d.useState(()=>(typeof window<"u"?window.__ARCHCODER_CONNECTION__?.status||window.__OPENCHAMBER_CONNECTION__?.status:"connecting")||"connecting"),w=rs(D=>D.isInitialized),C=rs(D=>D.initializeApp),N=Ze(D=>D.loadSessions),S=Ze(D=>D.loadMessages),k=Ze(D=>D.messages),[j,F]=d.useState(()=>w),[A,M]=d.useState(!1),B=d.useRef(0);d.useEffect(()=>{m&&l("chat")},[m]),d.useEffect(()=>{const D=t.vscode;D&&D.executeCommand("archcoder.setActiveSession",m,h)},[h,m,t.vscode]),d.useEffect(()=>{if(e==="editor"||a!=="chat"||m||p||g||x)return;const D=window.setTimeout(()=>{const L=Ze.getState(),T=!L.currentSessionId,_=!L.newSessionDraft?.open,z=L.isSyncing,R=(()=>{const W=L.sessionStatus;if(!W||W.size===0)return!1;for(const G of W.values())if(G?.type==="busy"||G?.type==="retry")return!0;return!1})();T&&_&&!z&&!R&&l("sessions")},900);return()=>{window.clearTimeout(D)}},[m,p,a,e,g,x]);const E=d.useCallback(()=>{l("sessions")},[]);d.useEffect(()=>{const D=typeof window<"u"?window.__ARCHCODER_CONNECTION__?.status||window.__OPENCHAMBER_CONNECTION__?.status:void 0;(D==="connected"||D==="connecting"||D==="error"||D==="disconnected")&&y(D);const L=T=>{const z=T.detail?.status;(z==="connected"||z==="connecting"||z==="error"||z==="disconnected")&&y(z)};return window.addEventListener("archcoder:connection-status",L),()=>window.removeEventListener("archcoder:connection-status",L)},[]),d.useEffect(()=>{const D=L=>{const _=L.detail?.view;_==="settings"?l("settings"):_==="chat"?l("chat"):_==="sessions"&&l("sessions")};return window.addEventListener("archcoder:navigate",D),()=>window.removeEventListener("archcoder:navigate",D)},[]),d.useEffect(()=>{(async()=>{if(A||j||v!=="connected")return;const L=Date.now();if(!(L-B.current<750)){B.current=L,M(!0);try{const T=(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem("archcoder_stream_debug")==="1"}catch{return!1}})();T&&console.log("[ArchCoder][VSCode][bootstrap] attempt",{configInitialized:w}),w||await C();const _=rs.getState();_.isConnected&&(_.providers.length===0&&await _.loadProviders(),_.agents.length===0&&await _.loadAgents());const z=rs.getState();if(!z.isInitialized||!z.isConnected||z.providers.length===0||z.agents.length===0)return;await N();const R=Ze.getState().error;if(T&&console.log("[OpenChamber][VSCode][bootstrap] post-load",{providers:z.providers.length,agents:z.agents.length,sessions:Ze.getState().sessions.length,sessionsError:R}),typeof R=="string"&&R.length>0)return;F(!0)}catch{}finally{M(!1)}}})()},[v,w,j,C,A,N]),d.useEffect(()=>{if(e==="editor"&&!r.current&&!(!j||v!=="connected")){if(!n){r.current=!0,b();return}f.some(D=>D.id===n)&&(r.current=!0,Ze.getState().setCurrentSession(n))}},[v,j,n,b,f,e]),d.useEffect(()=>{(async()=>{if(!(!j||v!=="connected"||a!=="chat"||p||!m||k.has(m)))try{await S(m)}catch{}})()},[v,m,a,j,S,k,p]),d.useEffect(()=>{const D=u.current;if(!D)return;const L=new ResizeObserver(T=>{for(const _ of T)c(_.contentRect.width)});return L.observe(D),c(D.clientWidth),()=>L.disconnect()},[]);const I=i>0&&i<QZ,P=i>=JZ;return d.useEffect(()=>{P&&a==="sessions"&&e==="sidebar"&&l("chat")},[P,a,e]),s.jsx("div",{ref:u,className:"h-full w-full bg-background text-foreground flex flex-col",children:e==="editor"?s.jsxs("div",{className:"flex flex-col h-full",children:[s.jsx(B0,{title:f.find(D=>D.id===m)?.title||"Chat",showMcp:!0,showContextUsage:!0}),s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(An,{children:s.jsx(wi,{})})})]}):a==="settings"?s.jsx(U7,{onClose:()=>l(P?"chat":"sessions"),forceMobile:I}):P?s.jsxs("div",{className:"flex h-full",children:[s.jsx("div",{className:"h-full border-r border-border overflow-hidden flex-shrink-0",style:{width:eK},children:s.jsx(_2,{mobileVariant:!0,allowReselect:!0,hideDirectoryControls:!0,showOnlyMainWorkspace:!0})}),s.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[s.jsx(B0,{title:p&&!m?"New session":f.find(D=>D.id===m)?.title||"Chat",showMcp:!0,showContextUsage:!0}),s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(An,{children:s.jsx(wi,{})})})]})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:Q("flex flex-col h-full",a!=="sessions"&&"hidden"),children:[s.jsx(B0,{title:"Sessions"}),s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(_2,{mobileVariant:!0,allowReselect:!0,onSessionSelected:()=>l("chat"),hideDirectoryControls:!0,showOnlyMainWorkspace:!0})})]}),s.jsxs("div",{className:Q("flex flex-col h-full",a!=="chat"&&"hidden"),children:[s.jsx(B0,{title:p&&!m?"New session":f.find(D=>D.id===m)?.title||"Chat",showBack:!0,onBack:E,showMcp:!0,showContextUsage:!0,showRateLimits:!0}),s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(An,{children:s.jsx(wi,{})})})]})]})})},B0=t=>{const e=Fe.c(46),{title:n,showBack:r,onBack:o,onNewSession:a,onSettings:l,onAgentManager:i,showMcp:c,showContextUsage:u,showRateLimits:m}=t,{getCurrentModel:f}=rs(),h=Ze(sK),p=Ws(nK),g=Ws(rK),x=Ws(oK),b=Ws(aK),v=Ws(lK),y=Ws(iK),w=Ws(cK),C=Ws(dK);zu();let N,S;e[0]!==w?(N=()=>{w()},S=[w],e[0]=w,e[1]=N,e[2]=S):(N=e[1],S=e[2]),d.useEffect(N,S);let k;if(e[3]!==h||e[4]!==f){const G=f(),Y=G?.limit&&typeof G.limit=="object"?G.limit:null,J=typeof Y?.context=="number"?Y.context:0,V=typeof Y?.output=="number"?Y.output:0;k=h(J,V),e[3]=h,e[4]=f,e[5]=k}else k=e[5];const j=k;let F;if(e[6]!==y||e[7]!==p){F=[];for(const G of Oo){if(!y.includes(G.id))continue;const Y=p.find(U=>U.providerId===G.id),J=Y?.usage?.windows??{},V=Object.entries(J),te=Y&&!Y.ok&&Y.configured?Y.error:void 0;(V.length>0||te)&&F.push({providerId:G.id,providerName:G.name,entries:V,error:te})}e[6]=y,e[7]=p,e[8]=F}else F=e[8];const A=F,M=A.length>0;let B;e[9]!==C?(B=async G=>{C(G);try{await ln({usageDisplayMode:G})}catch(Y){console.warn("Failed to update usage display mode:",Y)}},e[9]=C,e[10]=B):B=e[10];const E=B;let I;e[11]!==o||e[12]!==r?(I=r&&o&&s.jsx("button",{onClick:o,className:"inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Back to sessions",children:s.jsx(Su,{className:"h-5 w-5"})}),e[11]=o,e[12]=r,e[13]=I):I=e[13];let P;e[14]!==n?(P=s.jsx("h1",{className:"text-sm font-medium truncate flex-1",title:n,children:n}),e[14]=n,e[15]=P):P=e[15];let D;e[16]!==a?(D=a&&s.jsx("button",{onClick:a,className:"inline-flex h-9 w-9 items-center justify-center p-2 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"New session",children:s.jsx(Qs,{className:"h-5 w-5"})}),e[16]=a,e[17]=D):D=e[17];let L;e[18]!==i?(L=i&&s.jsx("button",{onClick:i,className:"inline-flex h-9 w-9 items-center justify-center p-2 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Open Agent Manager",children:s.jsx(zo,{className:"h-5 w-5"})}),e[18]=i,e[19]=L):L=e[19];let T;e[20]!==c?(T=c&&s.jsx(qy,{headerIconButtonClass:"inline-flex h-9 w-9 items-center justify-center p-2 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"}),e[20]=c,e[21]=T):T=e[21];let _;e[22]!==g||e[23]!==E||e[24]!==M||e[25]!==x||e[26]!==v||e[27]!==b||e[28]!==p||e[29]!==A||e[30]!==m?(_=m&&s.jsxs(qs,{onOpenChange:G=>{G&&p.length===0&&g()},children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":"Rate limits",className:"inline-flex h-9 w-9 items-center justify-center p-2 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:x,children:s.jsx(wd,{className:"h-5 w-5"})})}),s.jsxs(Ys,{align:"end",className:"w-80 max-h-[70vh] overflow-y-auto overflow-x-hidden bg-[var(--surface-elevated)] p-0",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)]",children:s.jsxs(sa,{className:"flex items-center justify-between gap-3 typography-ui-header font-semibold text-foreground",children:[s.jsx("span",{children:"Rate limits"}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("div",{className:"flex items-center rounded-md border border-[var(--interactive-border)] p-0.5",children:[s.jsx("button",{type:"button",className:`px-2 py-0.5 rounded-sm typography-micro text-[10px] transition-colors ${v==="usage"?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{E("usage")},"aria-label":"Show used quota",children:"Used"}),s.jsx("button",{type:"button",className:`px-2 py-0.5 rounded-sm typography-micro text-[10px] transition-colors ${v==="remaining"?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{E("remaining")},"aria-label":"Show remaining quota",children:"Remaining"})]}),s.jsx("button",{type:"button",className:"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:()=>g(),disabled:x,"aria-label":"Refresh rate limits",children:s.jsx(Qn,{className:"h-4 w-4"})})]})]})}),s.jsxs("div",{className:"border-b border-[var(--interactive-border)] px-2 pb-2 typography-micro text-muted-foreground text-[10px]",children:["Last updated ",XZ(b)]}),!M&&s.jsx(Jt,{className:"cursor-default",onSelect:uK,children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:"No rate limits available."})}),A.map((G,Y)=>s.jsxs(d.Fragment,{children:[s.jsxs(sa,{className:"flex items-center gap-2 bg-[var(--surface-elevated)] typography-ui-label text-foreground",children:[s.jsx(Mn,{providerId:G.providerId,className:"h-4 w-4"}),G.providerName]}),G.entries.length===0?s.jsx(Jt,{className:"cursor-default",onSelect:fK,children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:G.error??"No rate limits reported."})},`${G.providerId}-empty`):G.entries.map(J=>{const[V,te]=J,U=v==="remaining"?te.remainingPercent:te.usedPercent,X=ci(te.usedPercent,te.resetAt,te.windowSeconds,V),$=X?.dailyAllocationPercent!=null?v==="remaining"?100-Mo(X.elapsedRatio):Mo(X.elapsedRatio):null;return s.jsx(Jt,{className:"cursor-default items-start",onSelect:mK,children:s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[s.jsxs("span",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:i2(V)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Ao(U)==="-"?"":Ao(U)})]}),s.jsx(di,{percent:U,tonePercent:te.usedPercent,className:"h-1",expectedMarkerPercent:$}),X&&s.jsx("div",{className:"mt-0.5",children:s.jsx(ui,{paceInfo:X,compact:!0})}),s.jsx("span",{className:"flex items-center justify-between typography-micro text-muted-foreground text-[10px]",children:s.jsx("span",{children:te.resetAfterFormatted??te.resetAtFormatted??""})})]})},`${G.providerId}-${V}`)}),Y<A.length-1&&s.jsx(Zn,{})]},G.providerId))]})]}),e[22]=g,e[23]=E,e[24]=M,e[25]=x,e[26]=v,e[27]=b,e[28]=p,e[29]=A,e[30]=m,e[31]=_):_=e[31];let z;e[32]!==l?(z=l&&s.jsx("button",{onClick:l,className:"inline-flex h-9 w-9 items-center justify-center p-2 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Settings",children:s.jsx(xa,{className:"h-5 w-5"})}),e[32]=l,e[33]=z):z=e[33];let R;e[34]!==j||e[35]!==u?(R=u&&j&&j.totalTokens>0&&s.jsx(G6,{totalTokens:j.totalTokens,percentage:j.percentage,contextLimit:j.contextLimit,outputLimit:j.outputLimit??0,size:"compact"}),e[34]=j,e[35]=u,e[36]=R):R=e[36];let W;return e[37]!==_||e[38]!==z||e[39]!==R||e[40]!==I||e[41]!==P||e[42]!==D||e[43]!==L||e[44]!==T?(W=s.jsxs("div",{className:"flex items-center gap-1.5 pl-1 pr-2 py-1 border-b border-border bg-background shrink-0",children:[I,P,D,L,T,_,z,R]}),e[37]=_,e[38]=z,e[39]=R,e[40]=I,e[41]=P,e[42]=D,e[43]=L,e[44]=T,e[45]=W):W=e[45],W};function sK(t){return t.getContextUsage}function nK(t){return t.results}function rK(t){return t.fetchAllQuotas}function oK(t){return t.isLoading}function aK(t){return t.lastUpdated}function lK(t){return t.displayMode}function iK(t){return t.dropdownProviderIds}function cK(t){return t.loadSettings}function dK(t){return t.setDisplayMode}function uK(t){return t.preventDefault()}function fK(t){return t.preventDefault()}function mK(t){return t.preventDefault()}const _0=t=>{const e=vs.getState(),n=e.activeProjectId,r=n?e.projects.find(o=>o.id===n)?.path:void 0;return typeof r=="string"&&r.trim().length>0?r:t?Un(t):null},Un=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},mh=(t,e)=>{const n=Un(t),r=Un(e);if(!n||!r)return!1;if(n===r)return!0;const o=r==="/"?"/":`${r}/`;return n.startsWith(o)},tg=async(t,e)=>{const n=Un(e);if(!n)return n;try{const r=await t.path.get({directory:n});return Un(r.data?.directory??"")||n}catch{return n}},sg=async(t,e)=>{const n=Un(e);if(!n)return[];const r=await tg(t,n),o=l=>l.filter(i=>{const c=Un(i.directory??"");return c?mh(c,n)||r!==n&&mh(c,r):!1}),a=async l=>{const i=await t.session.list({directory:l});return Array.isArray(i.data)?i.data:[]};try{const l=o(await a(n));if(l.length>0)return l}catch{}if(r&&r!==n)try{const l=o(await a(r));if(l.length>0)return l}catch{}try{const l=await t.session.list(void 0),i=Array.isArray(l.data)?l.data:[];return o(i)}catch{return[]}},hK=async(t,e)=>{const n=new Map;t.sessions.forEach(o=>{o.worktreeMetadata&&n.set(Un(o.path),o.worktreeMetadata)});const r=Array.from(new Set(t.sessions.map(o=>Un(o.path)))).filter(Boolean).filter(o=>!n.has(o));if(r.length===0)return n;try{const o=await E1({id:`path:${e}`,path:e}),a=new Map(o.map(l=>[Un(l.path),l]));r.forEach(l=>{const i=a.get(l);i&&n.set(l,i)})}catch{}return n},pK=async t=>{const{apiClient:e,group:n,projectDirectory:r,worktreePaths:o}=t,a=await hK(n,r),l=Ze.getState(),i=Array.from(new Set(o.map(h=>Un(h)).filter(Boolean))),c=5;let u=0;const m=[],f=async()=>{for(;u<i.length;){const h=i[u];u+=1;const p=n.sessions.filter(y=>Un(y.path)===h).map(y=>y.id),g=l.getSessionsByDirectory(h),x=Array.isArray(g)?g.map(y=>y.id):[];let b=[];if(x.length===0)try{b=(await sg(e,h)).map(w=>w.id)}catch{b=[]}const v=Array.from(new Set([...x,...b,...p].filter(Boolean)));m.push({worktreePath:h,sessionIds:v,metadata:a.get(h)})}};return await Promise.all(Array.from({length:Math.min(c,i.length)},f)),m},xd=async t=>{const e=En.getApiClient(),n=await pK({apiClient:e,group:t.group,projectDirectory:t.projectDirectory,worktreePaths:t.worktreePaths}),r=Ze.getState(),o=new Set;return n.forEach(({worktreePath:a,sessionIds:l,metadata:i})=>{l.forEach(c=>{o.add(c),i&&(r.setWorktreeMetadata(c,i),r.setSessionDirectory(c,a))})}),o.size===0?{failedIds:[]}:r.deleteSessions(Array.from(o),{archiveWorktree:!0,silent:!0})};function gK(t){if(!t)return null;const e=t.split("/");if(e.length<3)return null;const n=e[0];if(!n||n.includes(" "))return null;const r=e[1];if(!r)return null;const o=e[e.length-1],a=parseInt(o,10),l=e.length>=4&&!isNaN(a)&&String(a)===o,i=l?e.slice(2,-1):e.slice(2);if(i.length===0)return null;const c=i.join("/");return{groupSlug:n,provider:r,model:c,index:l?a:1}}const Wa=Dr()(wa((t,e)=>({groups:[],selectedGroupName:null,selectedSessionId:null,isLoading:!1,error:null,loadGroups:async()=>{const n=dn.getState().currentDirectory,r=_0(n);if(!r){t({groups:[],isLoading:!1,error:"No project directory selected"});return}const o=Un(r),i={id:vs.getState().projects.find(u=>Un(u.path)===o)?.id??`path:${o}`,path:o},c=e().groups;t({isLoading:!0,error:null});try{const u=En.getApiClient(),m=await tg(u,o),f=m&&m!==o?{...i,path:m}:null,h=await E1(i).catch(()=>[]),p=f?await E1(f).catch(()=>[]):[],g=new Set,x=new Map;[...h,...p].forEach(k=>{if(k?.path){const j=Un(k.path);g.add(j),x.has(j)||x.set(j,k)}});const b=async()=>{try{const j=await u.session.list({directory:o}),F=Array.isArray(j.data)?j.data:[];if(F.some(A=>{const M=Un(A.directory??"");return M?g.has(M):!1}))return F}catch{}const k=await u.session.list(void 0);return Array.isArray(k.data)?k.data:[]},v=async k=>{const j=new Map,F=5;let A=0;const M=async()=>{for(;A<k.length;){const B=k[A];A+=1;const E=Un(B);if(E)try{(await sg(u,E)).forEach(P=>j.set(P.id,P))}catch(I){console.debug("Failed to fetch sessions from worktree:",E,I)}}};return await Promise.all(Array.from({length:Math.min(F,k.length)},M)),Array.from(j.values())};let w=(await b()).filter(k=>{const j=Un(k.directory??"");return j?g.has(j):!1});if(w.length===0){const k=new Set;g.forEach(j=>k.add(j)),k.size>0&&(w=await v(Array.from(k)))}const C=new Map;for(const k of w){const j=k.time?.updated??0;C.set(k.id,typeof j=="number"?j:0)}const N=new Map;for(const k of w){const j=gK(k.title);if(!j)continue;const F=Un(k.directory),A=x.get(F),M={id:k.id,path:F,providerId:j.provider,modelId:j.model,instanceNumber:j.index,branch:A?.branch??"",displayLabel:`${j.provider}/${j.model}`,worktreeMetadata:A},B=N.get(j.groupSlug);B?B.push(M):N.set(j.groupSlug,[M])}const S=Array.from(N.entries()).map(([k,j])=>{const F=j.reduce((A,M)=>{const B=C.get(M.id)??0;return Math.max(A,B)},0);return{name:k,sessions:j.sort((A,M)=>{const B=A.providerId.localeCompare(M.providerId);if(B!==0)return B;const E=A.modelId.localeCompare(M.modelId);return E!==0?E:A.instanceNumber-M.instanceNumber}),lastActive:F||Date.now(),sessionCount:j.length}});S.sort((k,j)=>k.name.localeCompare(j.name)),t({groups:S,isLoading:!1,error:null})}catch(u){console.error("Failed to load agent groups:",u),t({groups:c.length>0?c:[],isLoading:!1,error:u instanceof Error?u.message:"Failed to load agent groups"})}},selectGroup:n=>{const{groups:r}=e(),o=r.find(a=>a.name===n);t({selectedGroupName:n,selectedSessionId:o?.sessions[0]?.id??null})},selectSession:n=>{t({selectedSessionId:n})},deleteGroup:async n=>{const r=e().groups.find(l=>l.name===n);if(!r)return!1;const o=dn.getState().currentDirectory,a=_0(o);if(!a)return t({error:"No project directory selected"}),!1;t({isLoading:!0,error:null});try{const{failedIds:l}=await xd({group:r,projectDirectory:Un(a),worktreePaths:r.sessions.map(i=>i.path)});return l.length>0&&t({error:"Failed to delete some sessions"}),e().selectedGroupName===n&&t({selectedGroupName:null,selectedSessionId:null}),await e().loadGroups(),l.length===0}catch(l){return t({error:l instanceof Error?l.message:"Failed to delete group"}),!1}finally{t({isLoading:!1})}},deleteGroupWorktree:async(n,r)=>{const o=e().groups.find(c=>c.name===n);if(!o)return!1;const a=Un(r);if(!a)return!1;const l=dn.getState().currentDirectory,i=_0(l);if(!i)return t({error:"No project directory selected"}),!1;t({isLoading:!0,error:null});try{const{failedIds:c}=await xd({group:o,projectDirectory:Un(i),worktreePaths:[a]});c.length>0&&t({error:"Failed to delete some sessions"}),await e().loadGroups();const u=e().groups.find(m=>m.name===n);if(!u)return e().selectedGroupName===n&&t({selectedGroupName:null,selectedSessionId:null}),c.length===0;if(e().selectedGroupName===n){const m=e().selectedSessionId,f=new Set(u.sessions.map(h=>h.id));(!m||!f.has(m))&&t({selectedSessionId:u.sessions[0]?.id??null})}return c.length===0}catch(c){return t({error:c instanceof Error?c.message:"Failed to delete worktree"}),!1}finally{t({isLoading:!1})}},keepOnlyGroupWorktree:async(n,r)=>{const o=e().groups.find(m=>m.name===n);if(!o)return!1;const a=Un(r);if(!a)return!1;const i=Array.from(new Set(o.sessions.map(m=>Un(m.path)).filter(Boolean))).filter(m=>m!==a);if(i.length===0)return!0;const c=dn.getState().currentDirectory,u=_0(c);if(!u)return t({error:"No project directory selected"}),!1;t({isLoading:!0,error:null});try{const{failedIds:m}=await xd({group:o,projectDirectory:Un(u),worktreePaths:i});if(m.length>0&&t({error:"Failed to delete some sessions"}),await e().loadGroups(),e().selectedGroupName===n){const f=e().groups.find(p=>p.name===n),h=f?.sessions.find(p=>Un(p.path)===a)??f?.sessions[0]??null;t({selectedSessionId:h?.id??null})}return m.length===0}catch(m){return t({error:m instanceof Error?m.message:"Failed to remove other worktrees"}),!1}finally{t({isLoading:!1})}},getSelectedGroup:()=>{const{groups:n,selectedGroupName:r}=e();return r?n.find(o=>o.name===r)??null:null},getSelectedSession:()=>{const{selectedSessionId:n}=e(),r=e().getSelectedGroup();return!r||!n?null:r.sessions.find(o=>o.id===n)??null},clearError:()=>{t({error:null})}}),{name:"agent-groups-store"})),xK=t=>{const n=Date.now()-t,r=Math.floor(n/(60*1e3)),o=Math.floor(n/(3600*1e3)),a=Math.floor(n/(1440*60*1e3));return r<1?"now":r<60?`${r}m`:o<24?`${o}h`:`${a}d`},bK=t=>{const e=Fe.c(62),{group:n,isSelected:r,onSelect:o}=t,[a,l]=d.useState(!1),[i,c]=d.useState(!1),[u,m]=d.useState(!1),f=Wa(yK);let h;e[0]!==f||e[1]!==n.name||e[2]!==u?(h=async()=>{if(u)return;if(m(!0),fe.info(`Deleting "${n.name}"...`),await f(n.name))fe.success(`Deleted "${n.name}"`);else{const U=Wa.getState().error;fe.error(U||`Failed to delete "${n.name}"`)}m(!1),c(!1)},e[0]=f,e[1]=n.name,e[2]=u,e[3]=h):h=e[3];const p=h,g=r?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[4]!==g?(x=Q("group relative flex items-center rounded-md px-1.5 py-1.5 cursor-pointer",g),e[4]=g,e[5]=x):x=e[5];let b;e[6]!==n.name?(b=s.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:n.name}),e[6]=n.name,e[7]=b):b=e[7];let v;e[8]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(on,{className:"h-3 w-3"}),e[8]=v):v=e[8];const y=n.sessionCount!==1?"s":"";let w;e[9]!==n.sessionCount||e[10]!==y?(w=s.jsxs("span",{className:"typography-micro text-muted-foreground/60 flex items-center gap-1",children:[v,n.sessionCount," model",y]}),e[9]=n.sessionCount,e[10]=y,e[11]=w):w=e[11];let C;e[12]!==n.lastActive?(C=xK(n.lastActive),e[12]=n.lastActive,e[13]=C):C=e[13];let N;e[14]!==C?(N=s.jsx("span",{className:"typography-micro text-muted-foreground/60",children:C}),e[14]=C,e[15]=N):N=e[15];let S;e[16]!==w||e[17]!==N?(S=s.jsxs("div",{className:"flex items-center gap-2",children:[w,N]}),e[16]=w,e[17]=N,e[18]=S):S=e[18];let k;e[19]!==S||e[20]!==b?(k=s.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 flex-col gap-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[b,S]}),e[19]=S,e[20]=b,e[21]=k):k=e[21];const j=a&&"opacity-100";let F;e[22]!==j?(F=Q("inline-flex h-3.5 w-[18px] items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","opacity-0 group-hover:opacity-100",j),e[22]=j,e[23]=F):F=e[23];let A;e[24]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(Qr,{className:"h-3.5 w-3.5"}),e[24]=A):A=e[24];let M;e[25]!==F?(M=s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:F,"aria-label":"Group menu",onClick:wK,children:A})}),e[25]=F,e[26]=M):M=e[26];let B;e[27]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(Ys,{align:"end",className:"min-w-[140px]",children:s.jsx(Jt,{variant:"destructive",onSelect:te=>{te.stopPropagation(),l(!1),c(!0)},children:"Delete"})}),e[27]=B):B=e[27];let E;e[28]!==a||e[29]!==M?(E=s.jsx("div",{className:"flex items-center gap-1.5 self-stretch",children:s.jsxs(qs,{open:a,onOpenChange:l,children:[M,B]})}),e[28]=a,e[29]=M,e[30]=E):E=e[30];let I;e[31]!==k||e[32]!==E?(I=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[k,E]}),e[31]=k,e[32]=E,e[33]=I):I=e[33];let P;e[34]!==o||e[35]!==I||e[36]!==x?(P=s.jsx("div",{className:x,onClick:o,children:I}),e[34]=o,e[35]=I,e[36]=x,e[37]=P):P=e[37];let D;e[38]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(Us,{children:"Delete agent group"}),e[38]=D):D=e[38];let L;e[39]!==n.name?(L=s.jsxs(Zs,{children:[D,s.jsxs(sn,{children:["Delete ",s.jsx("span",{className:"text-foreground font-medium",children:n.name}),"? This removes all worktrees and sessions in this group."]})]}),e[39]=n.name,e[40]=L):L=e[40];let T;e[41]===Symbol.for("react.memo_cache_sentinel")?(T=()=>c(!1),e[41]=T):T=e[41];let _;e[42]!==u?(_=s.jsx(Be,{variant:"outline",onClick:T,disabled:u,children:"Cancel"}),e[42]=u,e[43]=_):_=e[43];let z;e[44]!==p?(z=()=>{p()},e[44]=p,e[45]=z):z=e[45];const R=u?"Deleting…":"Delete";let W;e[46]!==u||e[47]!==z||e[48]!==R?(W=s.jsx(Be,{variant:"destructive",onClick:z,disabled:u,children:R}),e[46]=u,e[47]=z,e[48]=R,e[49]=W):W=e[49];let G;e[50]!==_||e[51]!==W?(G=s.jsxs(yn,{children:[_,W]}),e[50]=_,e[51]=W,e[52]=G):G=e[52];let Y;e[53]!==L||e[54]!==G?(Y=s.jsxs(Vs,{className:"max-w-md",keyboardAvoid:!0,children:[L,G]}),e[53]=L,e[54]=G,e[55]=Y):Y=e[55];let J;e[56]!==i||e[57]!==Y?(J=s.jsx(Os,{open:i,onOpenChange:c,children:Y}),e[56]=i,e[57]=Y,e[58]=J):J=e[58];let V;return e[59]!==P||e[60]!==J?(V=s.jsxs(s.Fragment,{children:[P,J]}),e[59]=P,e[60]=J,e[61]=V):V=e[61],V},vK=t=>{const e=Fe.c(54),{className:n,selectedGroupName:r,onGroupSelect:o,onNewAgent:a}=t,[l,i]=d.useState(""),[c,u]=d.useState(!1),{groups:m,isLoading:f,loadGroups:h}=Wa(),p=dn(jK);let g,x;e[0]!==p||e[1]!==h?(g=()=>{p&&h()},x=[p,h],e[0]=p,e[1]=h,e[2]=g,e[3]=x):(g=e[2],x=e[3]),d.useEffect(g,x);let b;e:{if(!l.trim()){b=m;break e}let W;if(e[4]!==m||e[5]!==l){const G=l.toLowerCase();W=m.filter(Y=>Y.name.toLowerCase().includes(G)),e[4]=m,e[5]=l,e[6]=W}else W=e[6];b=W}const v=b;let y;e[7]!==v||e[8]!==c?(y=c?v:v.slice(0,5),e[7]=v,e[8]=c,e[9]=y):y=e[9];const w=y,C=v.length-5;let N;e[10]!==n?(N=Q("flex h-full flex-col text-foreground border-r border-border/30",n),e[10]=n,e[11]=N):N=e[11];let S;e[12]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(xr,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e[12]=S):S=e[12];let k;e[13]===Symbol.for("react.memo_cache_sentinel")?(k=W=>i(W.target.value),e[13]=k):k=e[13];let j;e[14]!==l?(j=s.jsx("div",{className:"px-2.5 pt-3 pb-2",children:s.jsxs("div",{className:"relative",children:[S,s.jsx(Xt,{value:l,onChange:k,placeholder:"Search Agent Groups...",className:"pl-8 h-8 rounded-lg border-border/40 bg-background/50 typography-meta"})]})}),e[14]=l,e[15]=j):j=e[15];let F,A;e[16]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(Qs,{className:"h-4 w-4"}),F=s.jsx("span",{className:"typography-ui-label",children:"New Agent Group"}),e[16]=F,e[17]=A):(F=e[16],A=e[17]);let M;e[18]!==a?(M=s.jsx("div",{className:"px-2.5 pb-2",children:s.jsxs(Be,{variant:"outline",className:"w-full justify-start gap-2 h-8",onClick:a,children:[A,F]})}),e[18]=a,e[19]=M):M=e[19];let B,E;e[20]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(Ds,{className:"h-4 w-4 text-muted-foreground"}),E=s.jsx("span",{className:"typography-micro font-medium text-muted-foreground uppercase tracking-wider",children:"Agent Groups"}),e[20]=B,e[21]=E):(B=e[20],E=e[21]);let I;e[22]!==f?(I=f&&s.jsx("span",{className:"typography-micro text-muted-foreground/50 ml-auto",children:"Loading..."}),e[22]=f,e[23]=I):I=e[23];let P;e[24]!==I?(P=s.jsxs("div",{className:"px-2.5 py-1.5 flex items-center gap-1",children:[B,E,I]}),e[24]=I,e[25]=P):P=e[25];let D;if(e[26]!==o||e[27]!==r||e[28]!==w){let W;e[30]!==o||e[31]!==r?(W=G=>s.jsx(bK,{group:G,isSelected:r===G.name,onSelect:()=>o?.(G.name)},G.name),e[30]=o,e[31]=r,e[32]=W):W=e[32],D=w.map(W),e[26]=o,e[27]=r,e[28]=w,e[29]=D}else D=e[29];let L;e[33]!==C||e[34]!==c?(L=!c&&C>0&&s.jsxs("button",{type:"button",onClick:()=>u(!0),className:"mt-1 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left typography-micro text-muted-foreground/70 hover:text-foreground hover:underline",children:["... More (",C,")"]}),e[33]=C,e[34]=c,e[35]=L):L=e[35];let T;e[36]!==v.length||e[37]!==c?(T=c&&v.length>5&&s.jsx("button",{type:"button",onClick:()=>u(!1),className:"mt-1 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left typography-micro text-muted-foreground/70 hover:text-foreground hover:underline",children:"Show less"}),e[36]=v.length,e[37]=c,e[38]=T):T=e[38];let _;e[39]!==v.length||e[40]!==f||e[41]!==l?(_=!f&&v.length===0&&s.jsxs("div",{className:"py-4 text-center",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:l.trim()?"No groups found":"No agent groups yet"}),!l.trim()&&s.jsx("p",{className:"typography-micro text-muted-foreground/60 mt-1",children:"Create a new agent group to get started"})]}),e[39]=v.length,e[40]=f,e[41]=l,e[42]=_):_=e[42];let z;e[43]!==D||e[44]!==L||e[45]!==T||e[46]!==_?(z=s.jsxs(ks,{outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-2.5 pb-2",children:[D,L,T,_]}),e[43]=D,e[44]=L,e[45]=T,e[46]=_,e[47]=z):z=e[47];let R;return e[48]!==M||e[49]!==P||e[50]!==z||e[51]!==N||e[52]!==j?(R=s.jsxs("div",{className:N,children:[j,M,P,z]}),e[48]=M,e[49]=P,e[50]=z,e[51]=N,e[52]=j,e[53]=R):R=e[53],R};function yK(t){return t.deleteGroup}function wK(t){return t.stopPropagation()}function jK(t){return t.currentDirectory}const kK=10*1024*1024,NK=5,SK=({className:t,onCreateGroup:e,isCreating:n=!1})=>{const[r,o]=d.useState(""),[a,l]=d.useState(""),[i,c]=d.useState([]),[u,m]=d.useState(""),[f,h]=d.useState(""),[p,g]=d.useState([]),[x,b]=d.useState(!1),[v,y]=d.useState([]),[w,C]=d.useState(!1),[N,S]=d.useState(!1),k=d.useRef(null),j=d.useRef(null),{currentTheme:F}=qn(),A=dn(te=>te.currentDirectory??null),{isGitRepository:M,isLoading:B}=g3(A),E=d.useMemo(()=>{if(typeof window>"u")return null;const te=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof te=="string"&&te.trim().length>0?te.trim():null},[]),I=d.useMemo(()=>typeof window>"u"?!1:!!window.__OPENCHAMBER_RUNTIME_APIS__?.runtime?.isVSCode,[]),P=vs(te=>te.activeProjectId),D=vs(te=>te.projects),L=d.useMemo(()=>{if(I&&E)return{id:`vscode:${E}`,path:E};if(P){const te=D.find(U=>U.id===P);if(te?.path)return{id:te.id,path:te.path}}return A?{id:`path:${A}`,path:A}:null},[P,D,A,E,I]);d.useEffect(()=>{if(!L)return;let te=!1;return S(!0),(async()=>{try{const U=await zi(L);te||y(U)}catch{}finally{te||S(!1)}})(),()=>{te=!0}},[L]);const T=d.useCallback(te=>{i.length>=NK||c(U=>[...U,te])},[i.length]),_=d.useCallback(te=>{c(U=>U.filter((X,$)=>$!==te))},[]),z=d.useCallback((te,U)=>{c(X=>X.map(($,q)=>q===te?U:$))},[]),R=async te=>{const U=te.target.files;if(!U)return;let X=0;for(let $=0;$<U.length;$++){const q=U[$];if(q.size>kK){fe.error(`File "${q.name}" is too large (max 10MB)`);continue}try{const ee=await new Promise((ve,ge)=>{const xe=new FileReader;xe.onload=()=>ve(xe.result),xe.onerror=ge,xe.readAsDataURL(q)}),ce={id:F2(),filename:q.name,mimeType:q.type||"application/octet-stream",size:q.size,dataUrl:ee};g(ve=>[...ve,ce]),X++}catch(ee){console.error("File attach failed",ee),fe.error(`Failed to attach "${q.name}"`)}}X>0&&fe.success(`Attached ${X} file${X>1?"s":""}`),k.current&&(k.current.value="")},W=te=>{g(U=>U.filter(X=>X.id!==te))},G=x||n,Y=!!(r.trim()&&a.trim()&&i.length>=1&&f&&M&&!B),J=async te=>{if(te.preventDefault(),!(!Y||G)){b(!0);try{const U=i.map(({providerID:q,modelID:ee,displayName:ce,variant:ve})=>({providerID:q,modelID:ee,displayName:ce,variant:ve})),X=p.length>0?p.map(q=>({mime:q.mimeType,filename:q.filename,url:q.dataUrl})):void 0,$=v.filter(q=>q.trim().length>0);await e?.({name:r.trim(),prompt:a.trim(),models:U,agent:u||void 0,worktreeBaseBranch:f,files:X,setupCommands:$.length>0?$:void 0}),o(""),l(""),c([]),m(""),g([]),h("HEAD")}catch(U){console.error("Failed to create agent group:",U),fe.error("Failed to create agent group")}finally{b(!1)}}},V=te=>{Xu(te)||te.key==="Enter"&&!te.shiftKey&&(te.preventDefault(),Y&&!G&&J(te))};return s.jsx("div",{className:Q("flex flex-col items-center justify-center h-full w-full p-4",t),children:s.jsxs("form",{onSubmit:J,className:"w-full max-w-2xl space-y-4",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{htmlFor:"group-name",className:"typography-ui-label font-medium text-foreground",children:"Group Name"}),s.jsx(Xt,{id:"group-name",value:r,onChange:te=>o(te.target.value),placeholder:"e.g. feature-auth, bugfix-login",className:"typography-body"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:"Used for worktree directory and branch naming"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("label",{className:"typography-ui-label font-medium text-foreground flex items-center gap-1.5",children:[s.jsx(on,{className:"h-4 w-4 text-muted-foreground"}),"Base Branch"]}),s.jsx(G7,{directory:A,value:f,onChange:h}),s.jsxs("p",{className:"typography-micro text-muted-foreground",children:["Creates new branches from ",s.jsx("code",{className:"font-mono text-xs",children:f})]})]}),s.jsxs(Jr,{open:w,onOpenChange:C,children:[s.jsxs(vo,{className:"w-full flex items-center justify-between py-1 hover:bg-[var(--interactive-hover)] rounded-md px-1 -mx-1 transition-colors",children:[s.jsxs("p",{className:"typography-ui-label font-medium text-foreground",children:["Setup commands",v.filter(te=>te.trim()).length>0&&s.jsxs("span",{className:"font-normal text-muted-foreground/70",children:[" ","(",v.filter(te=>te.trim()).length," configured)"]})]}),s.jsx(Ds,{className:Q("h-4 w-4 text-muted-foreground transition-transform duration-200",w&&"rotate-180")})]}),s.jsx(eo,{children:s.jsxs("div",{className:"pt-2 space-y-2",children:[s.jsxs("p",{className:"typography-micro text-muted-foreground/70",children:["Commands run in each new worktree. Use ",s.jsx("code",{className:"font-mono text-xs",children:"$ROOT_PROJECT_PATH"})," for project root."]}),N?s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:"Loading..."}):s.jsxs("div",{className:"space-y-1.5",children:[v.map((te,U)=>s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Xt,{value:te,onChange:X=>{const $=[...v];$[U]=X.target.value,y($)},placeholder:"e.g., bun install",className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const X=v.filter(($,q)=>q!==U);y(X)},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":"Remove command",children:s.jsx(Ps,{className:"h-4 w-4"})})]},U)),s.jsxs("button",{type:"button",onClick:()=>y([...v,""]),className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(Qs,{className:"h-3.5 w-3.5"}),"Add command"]})]})]})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:"Agent"}),s.jsx(Z7,{value:u,onChange:m}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:"Defaults to your configured default agent"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:"Models"}),s.jsx(q7,{selectedModels:i,onAdd:T,onRemove:_,onUpdate:z,minModels:1,addButtonLabel:"Add model",maxModels:5})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{htmlFor:"prompt",className:"typography-ui-label font-medium text-foreground",children:"Prompt"}),s.jsxs("div",{className:"rounded-xl border border-border/80 overflow-hidden focus-within:ring-1 focus-within:ring-primary/50",style:{backgroundColor:F?.colors?.surface?.subtle},children:[s.jsx(hr,{ref:j,id:"prompt",value:a,onChange:te=>l(te.target.value),onKeyDown:V,placeholder:"Ask anything...",className:"min-h-[100px] max-h-[300px] resize-none border-0 bg-transparent dark:bg-transparent px-4 py-3 typography-markdown focus-visible:ring-0 focus-visible:ring-offset-0"}),p.length>0&&s.jsx("div",{className:"flex flex-wrap gap-2 px-3 pb-2",children:p.map(te=>s.jsxs("div",{className:"inline-flex items-center gap-1.5 px-2 py-1 bg-muted/30 border border-border/30 rounded-md typography-meta",children:[te.mimeType.startsWith("image/")?s.jsx(Fl,{className:"h-3.5 w-3.5 text-muted-foreground"}):s.jsx(Ml,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[120px]",title:te.filename,children:te.filename}),s.jsx("button",{type:"button",onClick:()=>W(te.id),className:"text-muted-foreground hover:text-destructive ml-0.5",children:s.jsx(Ps,{className:"h-3.5 w-3.5"})})]},te.id))}),s.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-t border-border/40 bg-transparent",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{ref:k,type:"file",multiple:!0,className:"hidden",onChange:R,accept:"*/*"}),s.jsx("button",{type:"button",onClick:()=>k.current?.click(),className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-foreground transition-colors","aria-label":"Add attachment",children:s.jsx(Ph,{className:"h-[18px] w-[18px]"})})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[i.length," model",i.length!==1?"s":""," selected"]})}),s.jsx("button",{type:"submit",disabled:!Y||G,className:Q("flex items-center justify-center text-muted-foreground transition-none outline-none focus:outline-none flex-shrink-0",Y?"text-primary hover:text-primary":"opacity-30"),"aria-label":"Start Agent Group",children:G?s.jsx(zb,{className:"h-[18px] w-[18px] animate-spin"}):s.jsx(kd,{className:"h-[18px] w-[18px]"})})]})]})]})]})})},CK=({group:t,className:e})=>{const{selectedSessionId:n,selectSession:r,deleteGroupWorktree:o,keepOnlyGroupWorktree:a}=Wa(),{setCurrentSession:l,currentSessionId:i}=Ze(),[c,u]=d.useState(null),[m,f]=d.useState(!1),h=d.useMemo(()=>n?t.sessions.find(w=>w.id===n)??t.sessions[0]??null:t.sessions[0]??null,[t.sessions,n]),p=d.useCallback(w=>{r(w.id),l(w.id)},[r,l]);d.useEffect(()=>{if(t.sessions.length>0){const w=n?t.sessions.find(C=>C.id===n)??t.sessions[0]:t.sessions[0];w&&(w.id!==i&&l(w.id),n||r(w.id))}},[t.name,t.sessions,n,i,r,l]);const g=h?.id===i,x=d.useCallback(()=>{if(!h?.path){fe.error("No worktree path available");return}Dn(h.path).then(w=>{if(w.ok){fe.success("Worktree path copied");return}fe.error("Failed to copy path")})},[h?.path]),b=d.useCallback(async()=>{h&&u({kind:"remove",path:h.path,label:h.displayLabel})},[h]),v=d.useCallback(async()=>{h&&u({kind:"keepOnly",path:h.path,label:h.displayLabel})},[h]),y=d.useCallback(async()=>{if(!(!c||m)){f(!0);try{if(c.kind==="remove")if(fe.info("Removing worktree..."),await o(t.name,c.path))fe.success("Worktree removed");else{const C=Wa.getState().error;fe.error(C||"Failed to remove worktree");return}else if(fe.info("Removing other worktrees..."),await a(t.name,c.path))fe.success("Removed other worktrees");else{const C=Wa.getState().error;fe.error(C||"Failed to remove other worktrees");return}u(null)}finally{f(!1)}}},[o,t.name,m,a,c]);return s.jsxs("div",{className:Q("flex h-full flex-col bg-background",e),children:[s.jsxs("div",{className:"flex-shrink-0 border-b border-border/30 px-4 py-3",children:[s.jsx("div",{className:"flex items-start justify-between gap-4",children:s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("h1",{className:"typography-heading-lg text-foreground truncate",children:t.name}),s.jsxs("div",{className:"flex items-center gap-2 mt-1 typography-meta text-muted-foreground",children:[s.jsxs("span",{children:[t.sessionCount," model",t.sessionCount!==1?"s":""]}),s.jsx("span",{children:"·"}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(on,{className:"h-3.5 w-3.5"}),h?.worktreeMetadata?.label||h?.branch||"No branch"]})]})]})}),t.sessions.length>0&&s.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[s.jsx("div",{className:"flex-1 min-w-0",children:s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsxs(Be,{variant:"outline",className:"w-full justify-between h-10 px-3",children:[s.jsx("div",{className:"flex items-center gap-2 min-w-0",children:h&&s.jsxs(s.Fragment,{children:[s.jsx(Mn,{providerId:h.providerId,className:"h-5 w-5 flex-shrink-0"}),s.jsx("span",{className:"truncate typography-body",children:h.modelId}),h.instanceNumber>1&&s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["#",h.instanceNumber]})]})}),s.jsx(Ds,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Ys,{align:"start",className:"w-[var(--radix-dropdown-menu-trigger-width)]",children:t.sessions.map(w=>s.jsxs(Jt,{onClick:()=>p(w),className:"flex items-center gap-2 py-2",children:[s.jsx(Mn,{providerId:w.providerId,className:"h-5 w-5 flex-shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-body",children:w.modelId}),w.instanceNumber>1&&s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["#",w.instanceNumber]})]}),w.branch&&s.jsxs("div",{className:"flex items-center gap-1 typography-micro text-muted-foreground/60",children:[s.jsx(on,{className:"h-3 w-3"}),s.jsx("span",{className:"truncate",children:w.worktreeMetadata?.label||w.branch})]})]}),h?.id===w.id&&s.jsx(js,{className:"h-4 w-4 text-primary flex-shrink-0"})]},w.id))})]})}),s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsx(Be,{variant:"outline",size:"icon",className:"flex-shrink-0","aria-label":"Worktree actions",children:s.jsx(Qr,{className:"h-4 w-4"})})}),s.jsxs(Ys,{align:"end",className:"min-w-[220px]",children:[s.jsx(Jt,{onSelect:w=>{w.preventDefault(),b()},variant:"destructive",children:"Remove this worktree"}),s.jsx(Jt,{onSelect:w=>{w.preventDefault(),v()},children:"Leave this one, remove others"}),s.jsxs(Jt,{onClick:w=>{w.stopPropagation(),x()},disabled:!h?.path,children:[s.jsx(nr,{className:"h-4 w-4 mr-px"}),"Copy Worktree Path"]})]})]})]})]}),s.jsx(Os,{open:!!c,onOpenChange:w=>{w||u(null)},children:s.jsxs(Vs,{className:"max-w-md",keyboardAvoid:!0,children:[s.jsxs(Zs,{children:[s.jsx(Us,{children:c?.kind==="remove"?"Remove worktree":"Remove other worktrees"}),s.jsx(sn,{children:c?.kind==="remove"?s.jsxs(s.Fragment,{children:["Remove ",s.jsx("span",{className:"text-foreground font-medium",children:c?.label}),"? This deletes all sessions in that worktree and removes the worktree itself."]}):s.jsxs(s.Fragment,{children:["Keep ",s.jsx("span",{className:"text-foreground font-medium",children:c?.label})," and remove the other worktrees in ",s.jsx("span",{className:"text-foreground font-medium",children:t.name}),"."]})})]}),s.jsxs(yn,{children:[s.jsx(Be,{variant:"outline",onClick:()=>u(null),disabled:m,children:"Cancel"}),s.jsx(Be,{variant:c?.kind==="remove"?"destructive":"default",onClick:()=>{y()},disabled:m,children:m?"Working…":c?.kind==="remove"?"Remove":"Remove others"})]})]})}),s.jsx("div",{className:"flex-1 min-h-0",children:h?g?s.jsx(Kp,{sessionId:h.id,children:s.jsx(Zp,{})}):s.jsxs("div",{className:"h-full flex flex-col",children:[s.jsx("div",{className:"px-4 py-2 bg-muted/30 border-b border-border/30",children:s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(Mn,{providerId:h.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"font-medium text-foreground",children:h.displayLabel}),s.jsx("span",{children:"·"}),s.jsx("span",{className:"font-mono text-xs truncate",children:h.path})]})}),s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center p-8",children:[s.jsxs("p",{className:"typography-body text-muted-foreground mb-2",children:["Loading session for ",s.jsx("span",{className:"font-medium text-foreground",children:h.displayLabel})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground/60",children:["Session ID: ",h.id]})]})})]}):s.jsx("div",{className:"h-full flex items-center justify-center",children:s.jsx("p",{className:"typography-body text-muted-foreground",children:"No sessions in this group"})})})]})},AK=({className:t})=>{const e=!!(typeof window<"u"&&(window.__ARCHCODER_RUNTIME_APIS__?.runtime?.isVSCode||window.__OPENCHAMBER_RUNTIME_APIS__?.runtime?.isVSCode)),[n,r]=d.useState(()=>(typeof window<"u"?window.__ARCHCODER_CONNECTION__?.status||window.__OPENCHAMBER_CONNECTION__?.status:"connecting")||"connecting"),o=rs(w=>w.isInitialized),a=rs(w=>w.initializeApp),l=Ze(w=>w.loadSessions),i=dn(w=>w.setDirectory),c=d.useRef(0),{selectedGroupName:u,selectGroup:m,getSelectedGroup:f,loadGroups:h}=Wa(),{createMultiRun:p,isLoading:g}=k1();d.useEffect(()=>{if(!e)return;const w=typeof window<"u"?window.__ARCHCODER_CONNECTION__?.status||window.__OPENCHAMBER_CONNECTION__?.status:void 0;(w==="connected"||w==="connecting"||w==="error"||w==="disconnected")&&r(w);const C=N=>{const k=N.detail?.status;(k==="connected"||k==="connecting"||k==="error"||k==="disconnected")&&r(k)};return window.addEventListener("archcoder:connection-status",C),()=>window.removeEventListener("archcoder:connection-status",C)},[e]),d.useEffect(()=>{if(!e||n!=="connected")return;const w=Date.now();if(w-c.current<750)return;c.current=w;const C=typeof window<"u"?window.__VSCODE_CONFIG__?.workspaceFolder:null;if(typeof C=="string"&&C.trim().length>0)try{i(C,{showOverlay:!1})}catch{}(async()=>{try{o||await a();const S=rs.getState();if(!S.isInitialized||!S.isConnected||S.providers.length===0||S.agents.length===0)return;await l(),D6()&&console.log("[OpenChamber][VSCode][agentManager] bootstrap complete",{providers:S.providers.length,agents:S.agents.length,sessions:Ze.getState().sessions.length})}catch{}})()},[n,o,a,e,l,i]);const x=d.useCallback(w=>{m(w)},[m]),b=d.useCallback(()=>{m(null)},[m]),v=d.useCallback(async w=>{fe.info(`Creating agent group "${w.name}" with ${w.models.length} model(s)...`);const C=await p(w);if(C){fe.success(`Agent group "${w.name}" created with ${C.sessionIds.length} session(s)`);const N=C.groupSlug,S=async(k=6)=>{for(let j=0;j<k;j+=1){if(await h(),Wa.getState().groups.some(A=>A.name===N))return!0;await new Promise(A=>setTimeout(A,500))}return!1};try{await Ze.getState().loadSessions()}catch{}await S(),m(N)}else{const N=k1.getState().error;fe.error(N||"Failed to create agent group")}},[p,h,m]),y=f();return s.jsxs("div",{className:Q("flex h-full w-full bg-background",t),children:[s.jsx("div",{className:"w-64 flex-shrink-0",children:s.jsx(vK,{selectedGroupName:u,onGroupSelect:x,onNewAgent:b})}),s.jsx("div",{className:"flex-1 min-w-0",children:y?s.jsx(CK,{group:y}):s.jsx(SK,{onCreateGroup:v,isCreating:g})})]})},MK=t=>{const e=Fe.c(51),{onClose:n}=t,{sessions:r,messages:o,sessionMemoryState:a,currentSessionId:l}=Ze(),i=mo(FK);let c;e[0]!==o?(c=0,o.forEach(L=>{c=c+L.length}),e[0]=o,e[1]=c):c=e[1];const u=c;let m;if(e[2]!==l||e[3]!==o||e[4]!==a||e[5]!==r){let L;e[7]!==l||e[8]!==o||e[9]!==a?(L=T=>{const _=o.get(T.id)?.length||0,z=a.get(T.id);return{id:T.id,title:T.title||"Untitled",messageCount:_,isStreaming:z?.isStreaming||!1,isZombie:z?.isZombie||!1,backgroundCount:z?.backgroundMessageCount||0,lastAccessed:z?.lastAccessedAt||0,isCurrent:T.id===l}},e[7]=l,e[8]=o,e[9]=a,e[10]=L):L=e[10],m=r.map(L).sort(BK),e[2]=l,e[3]=o,e[4]=a,e[5]=r,e[6]=m}else m=e[6];const f=m,h=o.size;let p;e[11]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Hb,{className:"h-4 w-4"}),s.jsx("h3",{className:"font-semibold typography-ui-label",children:"Memory Debug Panel"})]}),e[11]=p):p=e[11];let g;e[12]!==n?(g=n&&s.jsx(Be,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(Ps,{className:"h-4 w-4"})}),e[12]=n,e[13]=g):g=e[13];let x;e[14]!==g?(x=s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[p,g]}),e[14]=g,e[15]=x):x=e[15];let b;e[16]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx("div",{className:"text-muted-foreground",children:"Total Messages"}),e[16]=b):b=e[16];let v;e[17]!==u?(v=s.jsxs("div",{className:"bg-muted/50 rounded p-2",children:[b,s.jsx("div",{className:"typography-markdown font-semibold",children:u})]}),e[17]=u,e[18]=v):v=e[18];let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"text-muted-foreground",children:"Cached Sessions"}),e[19]=y):y=e[19];let w;e[20]!==h?(w=s.jsxs("div",{className:"bg-muted/50 rounded p-2",children:[y,s.jsxs("div",{className:"typography-markdown font-semibold",children:[h," / ",H3.MAX_SESSIONS]})]}),e[20]=h,e[21]=w):w=e[21];let C;e[22]!==v||e[23]!==w?(C=s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[v,w]}),e[22]=v,e[23]=w,e[24]=C):C=e[24];let N;e[25]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted-foreground",children:"Viewport Window:"}),s.jsxs("span",{children:[Cv()," messages"]})]}),e[25]=N):N=e[25];let S;e[26]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted-foreground",children:"Zombie Timeout:"}),s.jsxs("span",{children:[H3.ZOMBIE_TIMEOUT/1e3/60," minutes"]})]}),e[26]=S):S=e[26];let k;e[27]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx("span",{className:"text-muted-foreground",children:"GitHub Total Requests:"}),e[27]=k):k=e[27];let j;e[28]!==i?(j=s.jsxs("div",{className:"typography-meta space-y-1 border-t pt-2",children:[N,S,s.jsxs("div",{className:"flex justify-between",children:[k,s.jsx("span",{children:i})]})]}),e[28]=i,e[29]=j):j=e[29];let F;e[30]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx("div",{className:"typography-meta font-semibold mb-1",children:"Sessions in Memory:"}),e[30]=F):F=e[30];let A;e[31]!==f?(A=f.map(_K),e[31]=f,e[32]=A):A=e[32];let M;e[33]!==A?(M=s.jsxs("div",{className:"border-t pt-2",children:[F,s.jsx(ks,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:A})]}),e[33]=A,e[34]=M):M=e[34];let B;e[35]!==l||e[36]!==o||e[37]!==a||e[38]!==r?(B=s.jsx(It,{asChild:!0,children:s.jsx(Be,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[MemoryDebug] Session store state:",{sessions:r.map(EK),currentSessionId:l,cachedSessions:Array.from(o.keys()),memoryStates:Object.fromEntries(a)})},children:"Log State"})}),e[35]=l,e[36]=o,e[37]=a,e[38]=r,e[39]=B):B=e[39];let E;e[40]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(_t,{side:"top",children:"Log current memory state to browser console"}),e[40]=E):E=e[40];let I;e[41]!==B?(I=s.jsx("div",{className:"flex gap-2 pt-2 border-t",children:s.jsxs(Dt,{delayDuration:1e3,children:[B,E]})}),e[41]=B,e[42]=I):I=e[42];let P;e[43]!==j||e[44]!==M||e[45]!==I||e[46]!==C?(P=s.jsxs("div",{className:"space-y-3",children:[C,null,j,M,I]}),e[43]=j,e[44]=M,e[45]=I,e[46]=C,e[47]=P):P=e[47];let D;return e[48]!==P||e[49]!==x?(D=s.jsxs(Wu,{className:"fixed bottom-4 right-4 w-96 p-4 shadow-none z-50 bg-background/95 bottom-safe-area",children:[x,P]}),e[48]=P,e[49]=x,e[50]=D):D=e[50],D};function FK(t){return t.totalRequestCount}function BK(t,e){return e.lastAccessed-t.lastAccessed}function _K(t){return s.jsxs("div",{className:`typography-meta p-1.5 rounded flex items-center justify-between ${t.isCurrent?"bg-primary/10":"bg-muted/30"}`,children:[s.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[s.jsx("span",{className:"truncate",children:t.title}),t.isStreaming&&s.jsx(Lb,{className:"h-3 w-3 text-primary animate-pulse"}),t.isZombie&&s.jsx("span",{className:"text-status-warning",children:"!"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:`font-mono ${t.messageCount>Sv()?"text-status-warning":""}`,children:[t.messageCount," msgs"]}),t.backgroundCount>0&&s.jsxs("span",{className:"text-primary",children:["+",t.backgroundCount]})]})]},t.id)}function EK(t){return{id:t.id,title:t.title}}const DK=()=>{const t=Ze.getState(),e=t.currentSessionId;if(!e)return"";const n=t.sessions.find(r=>r.id===e);return typeof n?.directory=="string"?n.directory:""},IK=async(t,e=6e3)=>{const n=new AbortController,r=setTimeout(()=>n.abort(),e),o=Date.now();try{const a=await fetch(t,{method:"GET",headers:{Accept:"application/json"},signal:n.signal}),l=Date.now()-o,i=a.headers.get("content-type")||"",c=i.toLowerCase(),u=c.includes("json")&&!c.includes("text/html");let m="";if(u){const f=await a.json().catch(()=>null);if(Array.isArray(f))m=`json[array] len=${f.length}`;else if(f&&typeof f=="object"){const h=Object.keys(f).slice(0,8);m=`json[object] keys=${h.join(",")}${Object.keys(f).length>h.length?",…":""}`}else m=`json[${typeof f}]`}else m=i?`content-type=${i}`:"no content-type";return{ok:a.ok&&u,status:a.status,elapsedMs:l,summary:m}}catch(a){const l=Date.now()-o,c=n.signal.aborted||a instanceof Error&&(a.name==="AbortError"||a.message.toLowerCase().includes("aborted"))?`timeout after ${e}ms`:a instanceof Error?a.message:String(a);return{ok:!1,status:0,elapsedMs:l,summary:`error=${c}`}}finally{clearTimeout(r)}},TK=t=>{if(!t||!Number.isFinite(t))return"(n/a)";try{return new Date(t).toISOString()}catch{return"(invalid)"}},PK=t=>{if(typeof t=="number"&&Number.isFinite(t)&&t>0)return Math.trunc(t);if(typeof t=="string"){const e=Number.parseInt(t,10);if(Number.isFinite(e)&&e>0)return e}return null},RK=async()=>{const t=new Date,e="2.0.2",n=typeof navigator<"u"?navigator.userAgent:"(no navigator)",r=DK(),o=Ee.getState().eventStreamStatus,a=typeof window<"u"?window.location.origin:"",l=a?`${a.replace(/\/+$/,"")}/api/`:"",i=await(async()=>{if(!a)return null;const x=new AbortController,b=setTimeout(()=>x.abort(),5e3);try{const v=await fetch(`${a.replace(/\/+$/,"")}/health`,{method:"GET",headers:{Accept:"application/json"},signal:x.signal});if(!v.ok)return null;const y=await v.json().catch(()=>null);return!y||typeof y!="object"||Array.isArray(y)?null:y}catch{return null}finally{clearTimeout(b)}})(),c=await(async()=>{if(!a)return null;const x=new AbortController,b=setTimeout(()=>x.abort(),7e3);try{const v=await fetch(`${a.replace(/\/+$/,"")}/api/config/opencode-resolution`,{method:"GET",headers:{Accept:"application/json"},signal:x.signal}),y=v.headers.get("content-type")||"(none)";if(!v.ok)return{data:null,status:v.status,error:`http ${v.status} content-type=${y}`};const w=await v.text();let C=null;try{C=JSON.parse(w)}catch{const N=w.replace(/\s+/g," ").slice(0,120);return{data:null,status:v.status,error:`invalid json content-type=${y} body=${N||"(empty)"}`}}return!C||typeof C!="object"||Array.isArray(C)?{data:null,status:v.status,error:`invalid json-shape content-type=${y}`}:{data:C,status:v.status,error:null}}catch(v){return{data:null,status:null,error:v instanceof Error?v.message:String(v)}}finally{clearTimeout(b)}})()||{data:null,error:null},u=(x,b=!0)=>{if(!l)return null;const v=new URL(x.replace(/^\/+/,""),l);return b&&r&&v.searchParams.set("directory",r),v.toString()},m=[{label:"health",path:"/global/health",includeDirectory:!1},{label:"config",path:"/config",includeDirectory:!0},{label:"providers",path:"/config/providers",includeDirectory:!0},{label:"agents",path:"/agent",includeDirectory:!0,timeoutMs:12e3},{label:"commands",path:"/command",includeDirectory:!0,timeoutMs:1e4},{label:"project",path:"/project/current",includeDirectory:!0},{label:"path",path:"/path",includeDirectory:!0},{label:"sessions",path:"/session",includeDirectory:!0,timeoutMs:12e3},{label:"sessionStatus",path:"/session/status",includeDirectory:!0}],f=l?await Promise.all(m.map(async x=>{const b=u(x.path,x.includeDirectory!==!1);if(!b)return{label:x.label,url:"(none)",result:null};const v=await IK(b,typeof x.timeoutMs=="number"?x.timeoutMs:void 0);return{label:x.label,url:b,result:v}})):[],h=[];h.push(`Time: ${t.toISOString()}`),h.push(`OpenChamber version: ${e}`),h.push(`Runtime: ${a||"(unknown)"} (api=${a?a+"/api":"(unknown)"})`),h.push(`Event stream: ${o}`),h.push(`Directory: ${r||"(none)"}`),h.push(`Platform: ${n}`);const p=PK(i?.openCodePort);if(h.push(`OpenCode runtime port: ${p??"(unknown)"}`),typeof i?.openCodeRunning=="boolean"&&h.push(`OpenCode runtime running: ${i.openCodeRunning?"yes":"no"}`),typeof i?.openCodeSecureConnection=="boolean"&&h.push(`Secure OpenCode connection: ${i.openCodeSecureConnection?"true":"false"}`),typeof i?.openCodeAuthSource=="string"&&i.openCodeAuthSource.trim()&&h.push(`OpenCode auth source: ${i.openCodeAuthSource}`),typeof window<"u"){const x=window.__OPENCHAMBER_MACOS_MAJOR__;typeof x=="number"&&Number.isFinite(x)&&x>0&&h.push(`macOS major: ${x}`)}if(/Mac OS X|Macintosh/.test(n)){h.push(""),h.push("OpenCode CLI resolution:");const x=c.data,b=x&&typeof x.configured=="string"?x.configured:null,v=x&&typeof x.resolved=="string"?x.resolved:i&&typeof i.opencodeBinaryResolved=="string"?i.opencodeBinaryResolved:"",y=x&&typeof x.resolvedDir=="string"?x.resolvedDir:"",w=x&&typeof x.source=="string"?x.source:i&&typeof i.opencodeBinarySource=="string"?i.opencodeBinarySource:"",C=x&&typeof x.shim=="string"?x.shim:i&&typeof i.opencodeShimInterpreter=="string"?i.opencodeShimInterpreter:"",N=x&&typeof x.node=="string"?x.node:i&&typeof i.nodeBinaryResolved=="string"?i.nodeBinaryResolved:"",S=x&&typeof x.bun=="string"?x.bun:i&&typeof i.bunBinaryResolved=="string"?i.bunBinaryResolved:"",k=x&&typeof x.detectedNow=="string"?x.detectedNow:"",j=x&&typeof x.detectedSourceNow=="string"?x.detectedSourceNow:"";if(b!==null&&h.push(`- configured: ${b.trim().length===0?"(cleared)":b}`),v){const F=y||(v.includes("/")?v.split("/").slice(0,-1).join("/")||"/":"");h.push(`- opencode: ${v}${F?` (dir=${F})`:""}`)}else h.push("- opencode: (n/a)");h.push(`- source: ${w||"(n/a)"}`),k&&(h.push(`- detected-now: ${k}`),h.push(`- detected-source: ${j||"(n/a)"}`)),h.push(`- shim: ${C||"(n/a)"}`),h.push(`- node: ${N||"(n/a)"}`),h.push(`- bun: ${S||"(n/a)"}`),!x&&c.error&&h.push(`- resolution-endpoint: ${c.error}`)}if(h.push(""),f.length){h.push("OpenCode API probes:");for(const x of f){if(!x.result){h.push(`- ${x.label}: (no url)`);continue}const{ok:b,status:v,elapsedMs:y,summary:w}=x.result,C=b?"":` url=${x.url}`;h.push(`- ${x.label}: ${b?"ok":"fail"} status=${v} time=${y}ms ${w}${C}`)}}else h.push("OpenCode API probes: (skipped)");return h.push(""),h.push(`Generated: ${TK(Date.now())}`),h.join(`
8011
+ \`\`\``;w(z,"append"),fe.success("Todo sent to current session"),r?.()},[v,r,P,w]),T=d.useCallback(async(_,z)=>{if(t){if(!n){fe.error("Worktree actions are only available for Git repositories");return}g(_);try{if(P(),!await U8({initialPrompt:z}))return;fe.success("Todo sent to new worktree session"),r?.()}finally{g(null)}}},[n,r,t,P]);return t?s.jsxs("div",{className:Q("w-full min-w-0 space-y-3 p-3",o),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:["Quick notes - ",e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[i.length,"/",L3]})]}),s.jsx(hr,{value:i,onChange:_=>c(_.target.value.slice(0,L3)),onBlur:k,placeholder:"Capture context, reminders, or links",className:"min-h-28 max-h-80 resize-none",useScrollShadow:!0,scrollShadowSize:56,disabled:a})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:"Todo"}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[u.length," item",u.length===1?"":"s"]}),s.jsx("button",{type:"button",onClick:B,disabled:a||I===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:"Clear completed"})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[E.length,"/",t0]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Xt,{value:E,onChange:_=>h(_.target.value.slice(0,t0)),onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),j())},placeholder:"Add a todo",disabled:a,className:"h-8"}),s.jsx("button",{type:"button",onClick:j,disabled:a||E.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 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 disabled:opacity-50","aria-label":"Add todo",children:s.jsx(Qs,{className:"h-4 w-4"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:u.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:"No todos yet. Add a small checklist for this project."}):s.jsx("ul",{className:"divide-y divide-border/50",children:u.map(_=>{const z=x.has(_.id);return s.jsxs("li",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx(fn,{checked:_.completed,onChange:R=>A(_.id,R),ariaLabel:`Mark "${_.text}" complete`,className:"mt-[3px] self-start"}),s.jsx("button",{type:"button",onClick:()=>F(_.id),className:Q("mt-[3px] min-w-0 flex-1 self-start bg-transparent p-0 text-left typography-ui-label text-foreground",z?"whitespace-normal break-words":"truncate","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",_.completed&&"text-muted-foreground line-through"),title:z?void 0:_.text,"aria-label":z?`Collapse todo "${_.text}"`:`Expand todo "${_.text}"`,children:_.text}),s.jsxs("div",{className:"mt-0.5 flex self-start items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>M(_.id),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":`Delete "${_.text}"`,children:s.jsx(Pn,{className:"h-3.5 w-3.5"})}),s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",disabled:p===_.id,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 disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Send "${_.text}"`,children:s.jsx(Ab,{className:"h-3.5 w-3.5"})})}),s.jsxs(Ys,{align:"end",className:"w-56",children:[s.jsx(Jt,{onClick:()=>L(_.text),children:"Send to current session"}),s.jsx(Jt,{onClick:()=>D(_.text),children:"Send to new session"}),s.jsx(Jt,{onClick:()=>{T(_.id,_.text)},disabled:!n,children:"Send to new worktree session"})]})]})]})]},_.id)})})})]})]}):s.jsx("div",{className:Q("w-full min-w-0 p-3",o),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:"Select a project to add notes and todos."})})},Hq=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(i=>nn(i.path)??i.path).filter(i=>!!i)]),a=(i=>i.filter(c=>P1(c,t.normalizedPath,r)))(e.archivedSessions),l=e.sessions.filter(i=>i.time?.archived||nn(i.directory??null)?!1:P1(i,t.normalizedPath,r));return Ai([...a,...l])},$q=t=>{const e=Fe.c(12),{normalizedProjects:n,sessions:r,archivedSessions:o,availableWorktreesByProject:a,isVSCode:l,isSessionsLoading:i,foldersMap:c,createFolder:u,addSessionToFolder:m,cleanupSessions:f}=t;let h,p;e[0]!==m||e[1]!==o||e[2]!==a||e[3]!==f||e[4]!==u||e[5]!==c||e[6]!==i||e[7]!==l||e[8]!==n||e[9]!==r?(h=()=>{i||n.forEach(g=>{const x=Uu(g.normalizedPath),b=Hq(g,{sessions:r,archivedSessions:o,availableWorktreesByProject:a,isVSCode:l}),v=new Set(b.map(Oq)),y=c[x]??[],w=new Map(y.map(Vq));b.forEach(C=>{const N=xj(C,g.normalizedPath),S=N.toLowerCase();let k=w.get(S);k||(k=u(x,N),w.set(S,k)),k.sessionIds.includes(C.id)||m(x,k.id,C.id)}),f(x,v)})},p=[n,r,o,a,l,i,c,u,m,f],e[0]=m,e[1]=o,e[2]=a,e[3]=f,e[4]=u,e[5]=c,e[6]=i,e[7]=l,e[8]=n,e[9]=r,e[10]=h,e[11]=p):(h=e[10],p=e[11]),d.useEffect(h,p)};function Oq(t){return t.id}function Vq(t){return[t.name.toLowerCase(),t]}const Uq=t=>{const e=Fe.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:o,availableWorktreesByProject:a,projectRepoStatus:l,projectRootBranches:i,lastRepoStatus:c,buildGroupedSessions:u,hasSessionSearchQuery:m,normalizedSessionSearchQuery:f,filterSessionNodesForSearch:h,buildGroupSearchText:p,getFoldersForScope:g}=t;let x;if(e[0]!==a||e[1]!==u||e[2]!==o||e[3]!==r||e[4]!==c||e[5]!==n||e[6]!==l||e[7]!==i){let A;e[9]!==a||e[10]!==u||e[11]!==o||e[12]!==r||e[13]!==c||e[14]!==l||e[15]!==i?(A=M=>{const B=Ai([...r(M),...o(M)]),E=a.get(M.normalizedPath)??[],I=l.has(M.id)?!!l.get(M.id):c,P=u(B,M.normalizedPath,E,i.get(M.id)??null,I);return{project:M,groups:P}},e[9]=a,e[10]=u,e[11]=o,e[12]=r,e[13]=c,e[14]=l,e[15]=i,e[16]=A):A=e[16],x=n.map(A),e[0]=a,e[1]=u,e[2]=o,e[3]=r,e[4]=c,e[5]=n,e[6]=l,e[7]=i,e[8]=x}else x=e[8];const b=x,v=b;let y;if(e[17]!==p||e[18]!==h||e[19]!==g||e[20]!==m||e[21]!==f||e[22]!==v){e:{const A=new WeakMap;if(!m){y=A;break e}const M=B=>B.reduce((E,I)=>E+1+M(I.children),0);v.forEach(B=>{B.groups.forEach(E=>{const I=h(E.sessions,f),P=M(I),D=p(E).includes(f),L=nn(E.directory??null),T=L?g(L).filter(_=>_.name.toLowerCase().includes(f)).length:0;A.set(E,{filteredNodes:I,matchedSessionCount:P,folderNameMatchCount:T,groupMatches:D,hasMatch:D||P>0||T>0})})}),y=A}e[17]=p,e[18]=h,e[19]=g,e[20]=m,e[21]=f,e[22]=v,e[23]=y}else y=e[23];const w=y;let C;e:{if(!m){C=v;break e}let A;if(e[24]!==w||e[25]!==v){let M;e[27]!==w?(M=B=>({...B,groups:B.groups.filter(E=>w.get(E)?.hasMatch===!0)}),e[27]=w,e[28]=M):M=e[28],A=v.map(M).filter(Wq),e[24]=w,e[25]=v,e[26]=A}else A=e[26];C=A}const N=C,S=m?N:v;let k;e:{if(!m){k=0;break e}let A;if(e[29]!==w||e[30]!==S){let M;e[32]!==w?(M=(B,E)=>B+E.groups.reduce((I,P)=>{const D=w.get(P);if(!D)return I;const L=D.folderNameMatchCount+(D.groupMatches?1:0);return I+D.matchedSessionCount+L},0),e[32]=w,e[33]=M):M=e[33],A=S.reduce(M,0),e[29]=w,e[30]=S,e[31]=A}else A=e[31];k=A}const j=k;let F;return e[34]!==w||e[35]!==b||e[36]!==j||e[37]!==N||e[38]!==S||e[39]!==v?(F={projectSections:b,visibleProjectSections:v,groupSearchDataByGroup:w,searchableProjectSections:N,sectionsForRender:S,searchMatchCount:j},e[34]=w,e[35]=b,e[36]=j,e[37]=N,e[38]=S,e[39]=v,e[40]=F):F=e[40],F};function Wq(t){return t.groups.length>0}const qq=t=>{const e=Fe.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:o,setActiveSessionByProject:a,currentSessionId:l,handleSessionSelect:i,newSessionDraftOpen:c,mobileVariant:u,openNewSessionDraft:m,setActiveMainTab:f,setSessionSwitcherOpen:h,sessions:p,worktreeMetadata:g}=t;let x,b;if(e[0]!==n){b=new Map,x=new Map;const M=(B,E,I,P)=>{b.has(B)||b.set(B,new Map);const D=b.get(B);P.forEach(L=>{const T=nn(L.worktree?.path??L.session.directory??I??E);D.set(L.session.id,{directory:T}),x.has(B)||x.set(B,{id:L.session.id,directory:T}),L.children.length>0&&M(B,E,T,L.children)})};n.forEach(B=>{B.groups.forEach(E=>{M(B.project.id,B.project.normalizedPath,E.directory,E.sessions)})}),e[0]=n,e[1]=x,e[2]=b}else x=e[1],b=e[2];let v;e[3]!==x||e[4]!==b?(v={metaByProject:b,firstSessionByProject:x},e[3]=x,e[4]=b,e[5]=v):v=e[5];const y=v,w=d.useRef(null);let C,N;e[6]!==r||e[7]!==o||e[8]!==l||e[9]!==i||e[10]!==u||e[11]!==c||e[12]!==m||e[13]!==n||e[14]!==y||e[15]!==f||e[16]!==a||e[17]!==h?(C=()=>{if(!r||c||w.current===r)return;const M=n.find(T=>T.project.id===r);if(!M)return;w.current=r;const B=y.metaByProject.get(r);if(l&&B&&B.has(l)){a(T=>{if(T.get(r)===l)return T;const _=new Map(T);return _.set(r,l),_});return}if(!B||B.size===0){f("chat"),u&&h(!1),m({directoryOverride:M.project.normalizedPath});return}const E=o.get(r),I=E&&B.has(E)?E:null,P=y.firstSessionByProject.get(r)?.id??null,D=I??P;if(!D||D===l)return;const L=B.get(D)?.directory??null;i(D,L,!1,r)},N=[r,o,l,i,c,u,m,n,y,f,h,a],e[6]=r,e[7]=o,e[8]=l,e[9]=i,e[10]=u,e[11]=c,e[12]=m,e[13]=n,e[14]=y,e[15]=f,e[16]=a,e[17]=h,e[18]=C,e[19]=N):(C=e[18],N=e[19]),d.useLayoutEffect(C,N);let S,k;e[20]!==r||e[21]!==l||e[22]!==y||e[23]!==a?(S=()=>{if(!r||!l)return;const M=y.metaByProject.get(r);!M||!M.has(l)||a(B=>{if(B.get(r)===l)return B;const E=new Map(B);return E.set(r,l),E})},k=[r,l,y,a],e[20]=r,e[21]=l,e[22]=y,e[23]=a,e[24]=S,e[25]=k):(S=e[24],k=e[25]),d.useEffect(S,k);let j;if(e[26]!==l||e[27]!==p||e[28]!==g){e:{if(!l){j=null;break e}const M=g.get(l)?.path;if(M){j=nn(M)??M;break e}let B;e[30]!==l?(B=I=>I.id===l,e[30]=l,e[31]=B):B=e[31];const E=p.find(B);if(!E){j=null;break e}j=nn(E.directory??null)}e[26]=l,e[27]=p,e[28]=g,e[29]=j}else j=e[29];const F=j;let A;return e[32]!==F?(A={currentSessionDirectory:F},e[32]=F,e[33]=A):A=e[33],A},Gq=t=>{const e=Fe.c(4);let n;e[0]!==t?(n=(a,l)=>{const i=t.get(a);if(!i||i.length===0)return l;const c=new Map(l.map(Zq)),u=[];return i.forEach(m=>{const f=c.get(m);f&&(u.push(f),c.delete(m))}),l.forEach(m=>{c.has(m.id)&&u.push(m)}),u},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 Zq(t){return[t.id,t]}const A0=t=>!!t.time?.archived,Kq=t=>{const e=d.useCallback(a=>[a.label,a.branch??"",a.description??"",a.directory??""].join(" ").toLowerCase(),[]),n=d.useCallback(a=>{const l=nn(a.directory??null)??"";return`${(a.title||"Untitled Session").trim()} ${l}`.toLowerCase()},[]),r=d.useCallback((a,l)=>l?a.flatMap(i=>{if(n(i.session).includes(l))return[i];const u=r(i.children,l);return u.length===0?[]:[{...i,children:u}]}):a,[n]),o=d.useCallback((a,l,i,c,u)=>{const m=nn(l??null),f=Ai(a).sort((F,A)=>T1(F,A,t.pinnedSessionIds)),h=new Map(f.map(F=>[F.id,F])),p=new Map;f.forEach(F=>{const A=F.parentID;if(!A)return;const M=h.get(A);if(!M||A0(M)!==A0(F))return;const B=p.get(A)??[];B.push(F),p.set(A,B)}),p.forEach(F=>F.sort((A,M)=>T1(A,M,t.pinnedSessionIds)));const g=new Map;i.forEach(F=>{if(F.path){const A=nn(F.path)??F.path;g.set(A,F)}});const x=F=>{const A=nn(F.directory??null),M=t.worktreeMetadata.get(F.id)??null;if(M)return M;if(A){const B=g.get(A)??null;if(B&&A!==m)return B}return null},b=F=>{const A=p.get(F.id)??[];return{session:F,children:A.map(M=>b(M)),worktree:x(F)}},v=f.filter(F=>{const A=F.parentID;if(!A)return!0;const M=h.get(A);return M?A0(M)!==A0(F):!0}),y=new Map,w="__archived__",C=F=>{if(F.time?.archived)return w;const A=nn(t.worktreeMetadata.get(F.id)?.path??null),M=nn(F.directory??null);if(!A&&!M)return w;const B=nn(F.project?.worktree??null),E=A??M??B;return E?E!==m&&g.has(E)?E:E===m?m??"__project_root__":w:w};v.forEach(F=>{const A=b(F),M=C(F);y.has(M)||y.set(M,[]),y.get(M)?.push(A)});const N=m??"__project_root__",S=[{id:"root",label:u&&c&&c!=="HEAD"?`project root: ${c}`:"project root",branch:c??null,description:m?va(m,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:m,folderScopeKey:m,sessions:y.get(N)??[]}],k=new Map;return i.forEach(F=>{const A=nn(F.path)??F.path,M=y.get(A)??[],B=M.length>0,E=M.reduce((I,P)=>{const D=Number(P.session.time?.updated??P.session.time?.created??0);return Number.isFinite(D)?Math.max(I,D):I},0);k.set(A,{hasActiveSession:B,lastUpdatedAt:E})}),[...i].sort((F,A)=>{const M=nn(F.path)??F.path,B=nn(A.path)??A.path,E=k.get(M)??{hasActiveSession:!1,lastUpdatedAt:0},I=k.get(B)??{hasActiveSession:!1,lastUpdatedAt:0};if(E.hasActiveSession!==I.hasActiveSession)return E.hasActiveSession?-1:1;if(E.hasActiveSession&&I.hasActiveSession)return I.lastUpdatedAt-E.lastUpdatedAt;const P=(F.label||F.branch||F.name||F.path||"").toLowerCase(),D=(A.label||A.branch||A.name||A.path||"").toLowerCase();return P.localeCompare(D)}).forEach(F=>{const A=nn(F.path)??F.path,M=t.gitDirectories.get(A)?.status?.current?.trim()||null,B=F.branch?.trim()||null,I=!!(M&&B&&F.label&&h2(F.label)===h2(B))?M:F.label||F.name||Or(A,t.homeDirectory)||A;S.push({id:`worktree:${A}`,label:I,branch:M||B,description:va(A,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:F,directory:A,folderScopeKey:A,sessions:y.get(A)??[]})}),S.push({id:"archived",label:"archived",branch:null,description:"Archived and unassigned sessions",isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&m?Uu(m):null,sessions:y.get(w)??[]}),S},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitDirectories,t.isVSCode]);return{buildGroupSearchText:e,buildSessionSearchText:n,filterSessionNodesForSearch:r,buildGroupedSessions:o}},Yq=t=>{const e=Fe.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:o,sessionSearchContainerRef:a}=t;let l,i;e[0]!==n||e[1]!==o?(l=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.select()});return()=>window.cancelAnimationFrame(m)},i=[n,o],e[0]=n,e[1]=o,e[2]=l,e[3]=i):(l=e[2],i=e[3]),d.useEffect(l,i);let c,u;e[4]!==n||e[5]!==a||e[6]!==r?(c=()=>{if(!n||typeof document>"u")return;const m=f=>{a.current&&(a.current.contains(f.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},u=[n,r,a],e[4]=n,e[5]=a,e[6]=r,e[7]=c,e[8]=u):(c=e[7],u=e[8]),d.useEffect(c,u)},Xq=180,Qq=1,Jq=6,eG=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],loadMessages:r})=>{const o=d.useRef(new Map),a=d.useRef([]),l=d.useRef(new Set),i=d.useCallback(()=>{if(!(typeof window>"u"))for(;l.current.size<Qq&&a.current.length>0;){const u=a.current.shift();if(!u)break;const m=Ze.getState();if(m.currentSessionId===u)continue;const f=m.messages.has(u),h=m.sessionHistoryMeta.get(u);f&&typeof h?.complete=="boolean"||(l.current.add(u),r(u).catch(()=>{}).finally(()=>{l.current.delete(u),i()}))}},[r]),c=d.useCallback(u=>{if(!u||u===t||typeof window>"u")return;const m=Ze.getState(),f=m.messages.has(u),h=m.sessionHistoryMeta.get(u);if(f&&typeof h?.complete=="boolean"||l.current.has(u)||a.current.includes(u))return;a.current.length>=Jq&&a.current.shift();const g=o.current.get(u);g!==void 0&&window.clearTimeout(g);const x=window.setTimeout(()=>{o.current.delete(u),a.current.push(u),i()},Xq);o.current.set(u,x)},[t,i]);d.useEffect(()=>{if(!t||e.length===0)return;const u=e.findIndex(m=>m.id===t);u<0||(c(e[u-1]?.id),c(e[u+1]?.id))},[t,c,e]),d.useEffect(()=>{if(!t||n.length===0)return;const u=n.indexOf(t);u<0||(c(n[u-1]),c(n[u+1]))},[t,n,c]),d.useEffect(()=>{const u=o.current;return()=>{u.forEach(m=>{clearTimeout(m)}),u.clear(),a.current=[]}},[])},tG=t=>{const e=Fe.c(10),{sortedSessions:n,projects:r,directoryStatus:o,setDirectoryStatus:a}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=new Map,e[0]=l):l=e[0];const i=d.useRef(l);let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c=new Set,e[1]=c):c=e[1];const u=d.useRef(c);let m,f;e[2]!==o?(m=()=>{i.current=o},f=[o],e[2]=o,e[3]=m,e[4]=f):(m=e[3],f=e[4]),d.useEffect(m,f);let h,p;e[5]!==r||e[6]!==a||e[7]!==n?(h=()=>{const g=new Set;n.forEach(x=>{const b=nn(x.directory??null);b&&g.add(b)}),r.forEach(x=>{const b=nn(x.path);b&&g.add(b)}),g.forEach(x=>{const b=i.current.get(x);b&&b!=="unknown"||u.current.has(x)||(u.current.add(x),En.listLocalDirectory(x).then(()=>{a(v=>{const y=new Map(v);return y.get(x)==="exists"?v:(y.set(x,"exists"),y)})}).catch(async()=>{if((x.includes("/opencode/worktree/")||x.includes("/.opencode/data/worktree/")||x.includes("/.local/share/opencode/worktree/"))&&await En.probeDirectory(x).catch(sG)){a(w=>{const C=new Map(w);return C.get(x)==="exists"?w:(C.set(x,"exists"),C)});return}a(y=>{const w=new Map(y);return w.get(x)==="missing"?y:(w.set(x,"missing"),w)})}).finally(()=>{u.current.delete(x)}))})},p=[n,r,a],e[5]=r,e[6]=a,e[7]=n,e[8]=h,e[9]=p):(h=e[8],p=e[9]),d.useEffect(h,p)};function sG(){return!1}const nG=t=>{const e=Fe.c(37),[n,r]=d.useState(null),o=d.useRef(null);let a,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>()=>{o.current&&clearTimeout(o.current)},l=[],e[0]=a,e[1]=l):(a=e[0],l=e[1]),d.useEffect(a,l);let i;e[2]!==t?(i=(I,P,D,L)=>{if(D)return;const T=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(L&&L!==t.activeProjectId&&t.setActiveProjectIdOnly(L),P&&P!==t.currentDirectory&&t.setDirectory(P,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),I===t.currentSessionId){t.allowReselect&&(typeof window<"u"&&window.dispatchEvent(new CustomEvent("archcoder:session-reselected",{detail:I})),t.onSessionSelected?.(I)),T();return}t.setCurrentSession(I),t.onSessionSelected?.(I),T()},e[2]=t,e[3]=i):i=e[3];const c=i;let u;e[4]!==t?(u=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=u):u=e[5];const m=u;let f;e[6]!==t?(f=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=f):f=e[7];const h=f;let p;e[8]!==t?(p=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=p):p=e[9];const g=p;let x;e[10]!==t?(x=async I=>{const P=await t.shareSession(I.id);P&&P.share?.url?fe.success("Session shared",{description:"You can copy the link from the menu."}):fe.error("Unable to share session")},e[10]=t,e[11]=x):x=e[11];const b=x;let v;e[12]===Symbol.for("react.memo_cache_sentinel")?(v=(I,P)=>{Dn(I).then(D=>{if(!D.ok){fe.error("Failed to copy URL");return}r(P),o.current&&clearTimeout(o.current),o.current=window.setTimeout(()=>{r(null),o.current=null},2e3)}).catch(rG)},e[12]=v):v=e[12];const y=v;let w;e[13]!==t?(w=async I=>{await t.unshareSession(I)?fe.success("Session unshared"):fe.error("Unable to unshare session")},e[13]=t,e[14]=w):w=e[14];const C=w;let N;e[15]!==t.childrenMap?(N=I=>{const P=[],D=L=>{(t.childrenMap.get(L)??[]).forEach(_=>{P.push(_),D(_.id)})};return D(I),P},e[15]=t.childrenMap,e[16]=N):N=e[16];const S=N;let k;e[17]!==t||e[18]!==S?(k=async(I,P)=>{const D=S(I.id),L=P?.archivedBucket===!0;if(D.length===0){(L?await t.deleteSession(I.id):await t.archiveSession(I.id))?fe.success(L?"Session deleted":"Session archived"):fe.error(L?"Failed to delete session":"Failed to archive session");return}const T=[I.id,...D.map(oG)];if(L){const{deletedIds:R,failedIds:W}=await t.deleteSessions(T);R.length>0&&fe.success(`Deleted ${R.length} session${R.length===1?"":"s"}`),W.length>0&&fe.error(`Failed to delete ${W.length} session${W.length===1?"":"s"}`);return}const{archivedIds:_,failedIds:z}=await t.archiveSessions(T);_.length>0&&fe.success(`Archived ${_.length} session${_.length===1?"":"s"}`),z.length>0&&fe.error(`Failed to archive ${z.length} session${z.length===1?"":"s"}`)},e[17]=t,e[18]=S,e[19]=k):k=e[19];const j=k;let F;e[20]!==t||e[21]!==S||e[22]!==j?(F=(I,P)=>{const D=S(I.id);if(!t.showDeletionDialog){j(I,P);return}t.setDeleteSessionConfirm({session:I,descendantCount:D.length,archivedBucket:P?.archivedBucket===!0})},e[20]=t,e[21]=S,e[22]=j,e[23]=F):F=e[23];const A=F;let M;e[24]!==t||e[25]!==j?(M=async()=>{if(!t.deleteSessionConfirm)return;const{session:I,archivedBucket:P}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await j(I,{archivedBucket:P})},e[24]=t,e[25]=j,e[26]=M):M=e[26];const B=M;let E;return e[27]!==B||e[28]!==n||e[29]!==g||e[30]!==A||e[31]!==h||e[32]!==m||e[33]!==c||e[34]!==b||e[35]!==C?(E={copiedSessionId:n,handleSessionSelect:c,handleSessionDoubleClick:m,handleSaveEdit:h,handleCancelEdit:g,handleShareSession:b,handleCopyShareUrl:y,handleUnshareSession:C,handleDeleteSession:A,confirmDeleteSession:B},e[27]=B,e[28]=n,e[29]=g,e[30]=A,e[31]=h,e[32]=m,e[33]=c,e[34]=b,e[35]=C,e[36]=E):E=e[36],E};function rG(){fe.error("Failed to copy URL")}function oG(t){return t.id}const aG=t=>{const e=Fe.c(40),{isVSCode:n,safeStorage:r,keys:o,sessions:a,pinnedSessionIds:l,setPinnedSessionIds:i,groupOrderByProject:c,activeSessionByProject:u,collapsedGroups:m,setExpandedParents:f,setCollapsedProjects:h}=t,p=d.useRef(null),g=d.useRef(null);let x;e[0]!==n?(x=()=>{if(n)return;const T=g.current;if(g.current=null,p.current=null,!T)return;const{projects:_}=vs.getState(),z=_.map(R=>({...R,sidebarCollapsed:T.has(R.id)}));ln({projects:z}).catch(lG)},e[0]=n,e[1]=x):x=e[1];const b=x;let v;e[2]!==b||e[3]!==n?(v=T=>{typeof window>"u"||n||(g.current=T,p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{b()},700))},e[2]=b,e[3]=n,e[4]=v):v=e[4];const y=v;let w,C;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=()=>()=>{typeof window<"u"&&p.current!==null&&window.clearTimeout(p.current),p.current=null,g.current=null},C=[],e[5]=w,e[6]=C):(w=e[5],C=e[6]),d.useEffect(w,C);let N,S;e[7]!==o.projectCollapse||e[8]!==o.sessionExpanded||e[9]!==r||e[10]!==h||e[11]!==f?(N=()=>{try{const T=r.getItem(o.sessionExpanded);if(T){const z=JSON.parse(T);Array.isArray(z)&&f(new Set(z.filter(iG)))}const _=r.getItem(o.projectCollapse);if(_){const z=JSON.parse(_);Array.isArray(z)&&h(new Set(z.filter(cG)))}}catch{}},S=[o.projectCollapse,o.sessionExpanded,r,h,f],e[7]=o.projectCollapse,e[8]=o.sessionExpanded,e[9]=r,e[10]=h,e[11]=f,e[12]=N,e[13]=S):(N=e[12],S=e[13]),d.useEffect(N,S);let k,j;e[14]!==a||e[15]!==i?(k=()=>{const T=new Set(a.map(dG));i(_=>{let z=!1;const R=new Set;return _.forEach(W=>{T.has(W)?R.add(W):z=!0}),z?R:_})},j=[a,i],e[14]=a,e[15]=i,e[16]=k,e[17]=j):(k=e[16],j=e[17]),d.useEffect(k,j);let F,A;e[18]!==o.sessionPinned||e[19]!==l||e[20]!==r?(F=()=>{try{r.setItem(o.sessionPinned,JSON.stringify(Array.from(l)))}catch{}},A=[o.sessionPinned,l,r],e[18]=o.sessionPinned,e[19]=l,e[20]=r,e[21]=F,e[22]=A):(F=e[21],A=e[22]),d.useEffect(F,A);let M,B;e[23]!==c||e[24]!==o.groupOrder||e[25]!==r?(M=()=>{try{const T=Object.fromEntries(c.entries());r.setItem(o.groupOrder,JSON.stringify(T))}catch{}},B=[c,o.groupOrder,r],e[23]=c,e[24]=o.groupOrder,e[25]=r,e[26]=M,e[27]=B):(M=e[26],B=e[27]),d.useEffect(M,B);let E,I;e[28]!==u||e[29]!==o.projectActiveSession||e[30]!==r?(E=()=>{try{const T=Object.fromEntries(u.entries());r.setItem(o.projectActiveSession,JSON.stringify(T))}catch{}},I=[u,o.projectActiveSession,r],e[28]=u,e[29]=o.projectActiveSession,e[30]=r,e[31]=E,e[32]=I):(E=e[31],I=e[32]),d.useEffect(E,I);let P,D;e[33]!==m||e[34]!==o.groupCollapse||e[35]!==r?(P=()=>{try{r.setItem(o.groupCollapse,JSON.stringify(Array.from(m)))}catch{}},D=[m,o.groupCollapse,r],e[33]=m,e[34]=o.groupCollapse,e[35]=r,e[36]=P,e[37]=D):(P=e[36],D=e[37]),d.useEffect(P,D);let L;return e[38]!==y?(L={scheduleCollapsedProjectsPersist:y},e[38]=y,e[39]=L):L=e[39],L};function lG(){}function iG(t){return typeof t=="string"}function cG(t){return typeof t=="string"}function dG(t){return t.id}const uG=t=>{const e=Fe.c(17),{projects:n,normalizedProjects:r,normalizePath:o,gitDirectories:a,setProjectRepoStatus:l,setProjectRootBranches:i}=t;let c,u;e[0]!==o||e[1]!==n||e[2]!==l?(c=()=>{let g=!1;const x=n.map(b=>({id:b.id,path:o(b.path)})).filter(fG);return l(new Map),x.length===0?()=>{g=!0}:(x.forEach(b=>{Ri(b.path).then(v=>{g||l(y=>{const w=new Map(y);return w.set(b.id,v),w})}).catch(()=>{g||l(v=>{const y=new Map(v);return y.set(b.id,null),y})})}),()=>{g=!0})},u=[o,n,l],e[0]=o,e[1]=n,e[2]=l,e[3]=c,e[4]=u):(c=e[3],u=e[4]),d.useEffect(c,u);let m;if(e[5]!==a||e[6]!==r){let g;e[8]!==a?(g=x=>{const b=a.get(x.normalizedPath);return`${x.id}:${b?.status?.current??""}`},e[8]=a,e[9]=g):g=e[9],m=r.map(g).join("|"),e[5]=a,e[6]=r,e[7]=m}else m=e[7];const f=m;let h;e[10]!==r||e[11]!==i?(h=()=>{let g=!1;return(async()=>{const b=await Promise.all(r.map(hG));g||i(v=>{const y=new Map(v);return b.forEach(w=>{const{id:C,branch:N}=w;N&&y.set(C,N)}),y})})(),()=>{g=!0}},e[10]=r,e[11]=i,e[12]=h):h=e[12];let p;e[13]!==r||e[14]!==f||e[15]!==i?(p=[r,f,i],e[13]=r,e[14]=f,e[15]=i,e[16]=p):p=e[16],d.useEffect(h,p)};function fG(t){return!!t.path}function mG(){return null}async function hG(t){const e=await $l(t.normalizedPath).catch(mG);return{id:t.id,branch:e}}const pG=t=>{const e=Fe.c(13),{isVSCode:n,sessions:r,archivedSessions:o,sessionsByDirectory:a,getSessionsByDirectory:l,availableWorktreesByProject:i}=t;let c;e[0]!==i||e[1]!==l||e[2]!==n||e[3]!==a?(c=p=>{const g=n?[]:i.get(p.normalizedPath)??[],x=[p.normalizedPath,...g.map(gG).filter(xG)],b=new Set,v=[];return x.forEach(y=>{(a.get(y)??l(y)).forEach(C=>{b.has(C.id)||(b.add(C.id),v.push(C))})}),v},e[0]=i,e[1]=l,e[2]=n,e[3]=a,e[4]=c):c=e[4];const u=c;let m;e[5]!==o||e[6]!==i||e[7]!==n||e[8]!==r?(m=p=>{if(n){const w=o.filter(N=>{const S=nn(N.directory??null),k=nn(N.project?.worktree??null);return S?S===p.normalizedPath:k===p.normalizedPath}),C=r.filter(N=>N.time?.archived||nn(N.directory??null)?!1:nn(N.project?.worktree??null)===p.normalizedPath);return Ai([...w,...C])}const g=n?[]:i.get(p.normalizedPath)??[],x=new Set([p.normalizedPath,...g.map(bG).filter(vG)]),v=(w=>w.filter(C=>P1(C,p.normalizedPath,x)))(o),y=r.filter(w=>{if(w.time?.archived||nn(w.directory??null))return!1;const N=nn(w.project?.worktree??null);return N?N===p.normalizedPath||N.startsWith(`${p.normalizedPath}/`):!1});return Ai([...v,...y])},e[5]=o,e[6]=i,e[7]=n,e[8]=r,e[9]=m):m=e[9];const f=m;let h;return e[10]!==f||e[11]!==u?(h={getSessionsForProject:u,getArchivedSessionsForProject:f},e[10]=f,e[11]=u,e[12]=h):h=e[12],h};function gG(t){return nn(t.path)??t.path}function xG(t){return!!t}function bG(t){return nn(t.path)??t.path}function vG(t){return!!t}const yG=t=>{const e=Fe.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:o,normalizedProjects:a,isVSCode:l,availableWorktreesByProject:i,cleanupSessions:c}=t;let u,m;e[0]!==o||e[1]!==i||e[2]!==c||e[3]!==n||e[4]!==l||e[5]!==a||e[6]!==r?(u=()=>{if(n)return;const f=new Map;r.forEach(g=>{const x=nn(g.directory??null);if(!x)return;const b=f.get(x);if(b){b.add(g.id);return}f.set(x,new Set([g.id]))}),a.forEach(g=>{const x=Uu(g.normalizedPath),b=l?[]:i.get(g.normalizedPath)??[],v=new Set([g.normalizedPath,...b.map(wG).filter(jG)]),y=Ai([...o,...r.filter(w=>w.time?.archived||nn(w.directory??null)?!1:P1(w,g.normalizedPath,v))]).filter(w=>P1(w,g.normalizedPath,v));f.set(x,new Set(y.map(kG)))});const h=uo.getState().foldersMap;new Set([...Object.keys(h),...f.keys()]).forEach(g=>{c(g,f.get(g)??new Set)})},m=[o,i,c,n,l,a,r],e[0]=o,e[1]=i,e[2]=c,e[3]=n,e[4]=l,e[5]=a,e[6]=r,e[7]=u,e[8]=m):(u=e[7],m=e[8]),d.useEffect(u,m)};function wG(t){return nn(t.path)??t.path}function jG(t){return!!t}function kG(t){return t.id}const NG=t=>{const e=Fe.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:o}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[l,i]=d.useState(a);let c;e[1]!==n||e[2]!==o?(c=()=>{if(!n)return;const m=new IntersectionObserver(f=>{f.forEach(h=>{const p=h.target.dataset.projectId;p&&i(g=>{const x=new Set(g);return h.isIntersecting?x.delete(p):x.add(p),x})})},{threshold:0});return o.current.forEach(f=>{f&&m.observe(f)}),()=>m.disconnect()},e[1]=n,e[2]=o,e[3]=c):c=e[3];let u;return e[4]!==n||e[5]!==o||e[6]!==r?(u=[n,o,r],e[4]=n,e[5]=o,e[6]=r,e[7]=u):u=e[7],d.useEffect(c,u),l},SG=t=>{const e=Fe.c(78),{folder:n,sessions:r,subFolderItems:o,isCollapsed:a,onToggle:l,onRename:i,onDelete:c,renderSessionNode:u,groupDirectory:m,projectId:f,mobileVariant:h,isRenaming:p,renameDraft:g,onRenameDraftChange:x,onRenameSave:b,onRenameCancel:v,droppableRef:y,isDropTarget:w,onNewSession:C,onNewSubFolder:N,depth:S,hideActions:k,archivedBucket:j}=t,F=h===void 0?!1:h,A=p===void 0?!1:p,M=g===void 0?"":g,B=w===void 0?!1:w,E=S===void 0?0:S,I=k===void 0?!1:k,P=j===void 0?!1:j,[D,L]=d.useState(!1),[T,_]=d.useState(""),z=d.useRef(null),R=A||D,W=A?M:T;let G;e[0]!==n.name?(G=()=>{_(n.name),L(!0)},e[0]=n.name,e[1]=G):G=e[1];const Y=G;let J;e[2]!==W||e[3]!==n.name||e[4]!==A||e[5]!==i||e[6]!==b?(J=()=>{const _e=W.trim();_e&&_e!==n.name&&i(_e),A&&b&&b(),L(!1),_("")},e[2]=W,e[3]=n.name,e[4]=A,e[5]=i,e[6]=b,e[7]=J):J=e[7];const V=J;let te;e[8]!==A||e[9]!==v?(te=()=>{A&&v&&v(),L(!1),_("")},e[8]=A,e[9]=v,e[10]=te):te=e[10];const U=te;let X;e[11]!==A||e[12]!==x?(X=_e=>{A&&x?x(_e):_(_e)},e[11]=A,e[12]=x,e[13]=X):X=e[13];const $=X;let q,ee;e[14]!==A?(q=()=>{if(!A)return;const _e=()=>{const je=z.current;je&&(je.focus(),je.select())},de=requestAnimationFrame(_e),we=window.setTimeout(_e,0);return()=>{cancelAnimationFrame(de),window.clearTimeout(we)}},ee=[A],e[14]=A,e[15]=q,e[16]=ee):(q=e[15],ee=e[16]),d.useEffect(q,ee);const ce=a?jr:Mb,ge=E>0&&"ml-3";let xe;e[17]!==ge?(xe=Q("oc-folder",ge),e[17]=ge,e[18]=xe):xe=e[18];const ne=B&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let O;e[19]!==ne?(O=Q("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",ne),e[19]=ne,e[20]=O):O=e[20];const H=R?void 0:l,K=R?void 0:"button",re=R?void 0:0;let le;e[21]!==l||e[22]!==R?(le=R?void 0:_e=>{(_e.key==="Enter"||_e.key===" ")&&(_e.preventDefault(),l())},e[21]=l,e[22]=R,e[23]=le):le=e[23];const ae=a?`Expand folder ${n.name}`:`Collapse folder ${n.name}`,ue=P?F?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let be;e[24]!==ue?(be=Q("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",ue),e[24]=ue,e[25]=be):be=e[25];const oe=B?"text-primary":"text-muted-foreground";let Z;e[26]!==oe?(Z=Q("h-3.5 w-3.5 flex-shrink-0",oe),e[26]=oe,e[27]=Z):Z=e[27];let ie;e[28]!==ce||e[29]!==Z?(ie=s.jsx(ce,{className:Z}),e[28]=ce,e[29]=Z,e[30]=ie):ie=e[30];let pe;e[31]!==W||e[32]!==n.name||e[33]!==U||e[34]!==$||e[35]!==V||e[36]!==a||e[37]!==B||e[38]!==R||e[39]!==r?(pe=R?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1","data-keyboard-avoid":"true",onPointerDown:AG,onMouseDown:MG,onSubmit:_e=>{_e.preventDefault(),V()},children:[s.jsx("input",{ref:z,value:W,onChange:_e=>$(_e.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:"Folder name",onClick:FG,onPointerDown:BG,onMouseDown:_G,onKeyDown:_e=>{if(_e.key==="Escape"){_e.stopPropagation(),U();return}(_e.key===" "||_e.key==="Enter")&&_e.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:EG,onPointerDown:DG,onMouseDown:IG,children:s.jsx(js,{className:"size-4"})}),s.jsx("button",{type:"button",onClick:_e=>{_e.stopPropagation(),U()},onPointerDown:TG,onMouseDown:PG,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(Ps,{className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:Q("typography-ui-label font-semibold truncate",B?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),a?s.jsx(On,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(Ds,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[31]=W,e[32]=n.name,e[33]=U,e[34]=$,e[35]=V,e[36]=a,e[37]=B,e[38]=R,e[39]=r,e[40]=pe):pe=e[40];let me;e[41]!==be||e[42]!==ie||e[43]!==pe?(me=s.jsxs("div",{className:be,children:[ie,pe]}),e[41]=be,e[42]=ie,e[43]=pe,e[44]=me):me=e[44];let Se;e[45]!==P||e[46]!==E||e[47]!==n.name||e[48]!==Y||e[49]!==I||e[50]!==F||e[51]!==c||e[52]!==C||e[53]!==N||e[54]!==R?(Se=!R&&(!I||P)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:Q("flex items-center gap-0.5 transition-opacity",F?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",P&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!P&&C?s.jsx("button",{type:"button",onClick:_e=>{_e.stopPropagation(),C()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`New session in ${n.name}`,title:"New session",children:s.jsx(Qs,{className:"h-3.5 w-3.5"})}):null,!P&&N&&E===0?s.jsx("button",{type:"button",onClick:_e=>{_e.stopPropagation(),N()},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":`New sub-folder in ${n.name}`,title:"New sub-folder",children:s.jsx(Pi,{className:"h-3.5 w-3.5"})}):null,P?null:s.jsx("button",{type:"button",onClick:_e=>{_e.stopPropagation(),Y()},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":`Rename folder ${n.name}`,children:s.jsx(_o,{className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:_e=>{_e.stopPropagation(),c()},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":P?`Delete archived sessions in folder ${n.name}`:`Delete folder ${n.name}`,children:s.jsx(Pn,{className:"h-3.5 w-3.5"})})]})}):null,e[45]=P,e[46]=E,e[47]=n.name,e[48]=Y,e[49]=I,e[50]=F,e[51]=c,e[52]=C,e[53]=N,e[54]=R,e[55]=Se):Se=e[55];let ke;e[56]!==y||e[57]!==O||e[58]!==H||e[59]!==K||e[60]!==re||e[61]!==le||e[62]!==ae||e[63]!==me||e[64]!==Se?(ke=s.jsxs("div",{ref:y,className:O,onClick:H,role:K,tabIndex:re,onKeyDown:le,"aria-label":ae,children:[me,Se]}),e[56]=y,e[57]=O,e[58]=H,e[59]=K,e[60]=re,e[61]=le,e[62]=ae,e[63]=me,e[64]=Se,e[65]=ke):ke=e[65];let ye;e[66]!==P||e[67]!==m||e[68]!==a||e[69]!==f||e[70]!==u||e[71]!==r||e[72]!==o?(ye=a?null:s.jsxs("div",{className:"pb-1 pl-2",children:[o,r.length>0?r.map(_e=>u(_e,0,m??null,f??null,P)):o?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:"Empty folder"})]}),e[66]=P,e[67]=m,e[68]=a,e[69]=f,e[70]=u,e[71]=r,e[72]=o,e[73]=ye):ye=e[73];let Ne;return e[74]!==xe||e[75]!==ke||e[76]!==ye?(Ne=s.jsxs("div",{className:xe,children:[ke,ye]}),e[74]=xe,e[75]=ke,e[76]=ye,e[77]=Ne):Ne=e[77],Ne},CG=d.memo(SG);function AG(t){return t.stopPropagation()}function MG(t){return t.stopPropagation()}function FG(t){return t.stopPropagation()}function BG(t){return t.stopPropagation()}function _G(t){return t.stopPropagation()}function EG(t){return t.stopPropagation()}function DG(t){return t.stopPropagation()}function IG(t){return t.stopPropagation()}function TG(t){return t.stopPropagation()}function PG(t){return t.stopPropagation()}const RG=t=>{const e=Fe.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:o,children:a}=t,l=`session-drag:${n}`;let i;e[0]!==r||e[1]!==n||e[2]!==o?(i={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:o},e[0]=r,e[1]=n,e[2]=o,e[3]=i):i=e[3];let c;e[4]!==l||e[5]!==i?(c={id:l,data:i},e[4]=l,e[5]=i,e[6]=c):c=e[6];const{attributes:u,listeners:m,setNodeRef:f,isDragging:h}=Bb(c);let p;e[7]!==m?(p=v=>{v.stopPropagation(),m?.onPointerDown&&m.onPointerDown(v)},e[7]=m,e[8]=p):p=e[8];const g=p,x=h?"opacity-30":void 0;let b;return e[9]!==u||e[10]!==a||e[11]!==g||e[12]!==f||e[13]!==x?(b=s.jsx("div",{ref:f,...u,onPointerDown:g,className:x,children:a}),e[9]=u,e[10]=a,e[11]=g,e[12]=f,e[13]=x,e[14]=b):b=e[14],b},zG=t=>{const e=Fe.c(11),{folderId:n,children:r}=t,o=`folder-drop:${n}`;let a;e[0]!==n?(a={type:"folder",folderId:n},e[0]=n,e[1]=a):a=e[1];let l;e[2]!==o||e[3]!==a?(l={id:o,data:a},e[2]=o,e[3]=a,e[4]=l):l=e[4];const{setNodeRef:i,isOver:c}=Fb(l);let u;e[5]!==r||e[6]!==c||e[7]!==i?(u=r(i,c),e[5]=r,e[6]=c,e[7]=i,e[8]=u):u=e[8];let m;return e[9]!==u?(m=s.jsx(s.Fragment,{children:u}),e[9]=u,e[10]=m):m=e[10],m},LG=t=>{const e=Fe.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:o,children:a}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[0]=l):l=e[0];const i=N1(xl(S1,l)),[c,u]=d.useState(null),[m,f]=d.useState("Session"),[h,p]=d.useState(null),[g,x]=d.useState(null);if(!n){let k;return e[1]!==a?(k=s.jsx(s.Fragment,{children:a}),e[1]=a,e[2]=k):k=e[2],k}let b;e[3]!==o?(b=k=>{u(null),p(null),x(null);const{active:j,over:F}=k;if(!F)return;const A=j.data.current,M=F.data.current;A?.type==="session"&&A.sessionId&&M?.type==="folder"&&M.folderId&&o(A.sessionId,M.folderId)},e[3]=o,e[4]=b):b=e[4];const v=b;let y,w;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=k=>{const j=k.active.data.current;if(j?.type==="session"&&j.sessionId){u(j.sessionId),f(j.sessionTitle??"Session");const F=k.active.rect.current.initial?.width,A=k.active.rect.current.initial?.height;p(typeof F=="number"?F:null),x(typeof A=="number"?A:null)}},w=()=>{u(null),p(null),x(null)},e[5]=y,e[6]=w):(y=e[5],w=e[6]);let C;e[7]!==g||e[8]!==c||e[9]!==m||e[10]!==h||e[11]!==r?(C=c&&r?s.jsxs("div",{style:{width:h?`${h}px`:"auto",height:g?`${g}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(Md,{className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=g,e[8]=c,e[9]=m,e[10]=h,e[11]=r,e[12]=C):C=e[12];let N;e[13]!==C?(N=s.jsx(Q0,{children:C}),e[13]=C,e[14]=N):N=e[14];let S;return e[15]!==a||e[16]!==v||e[17]!==i||e[18]!==N?(S=s.jsxs(C1,{sensors:i,collisionDetection:A1,onDragStart:y,onDragCancel:w,onDragEnd:v,children:[a,N]}),e[15]=a,e[16]=v,e[17]=i,e[18]=N,e[19]=S):S=e[19],S},B2=Dr()(Pl(t=>({displayMode:"default",setDisplayMode:e=>t({displayMode:e})}),{name:"session-display-mode"}));function HG(t){const e=Fe.c(158),{group:n,groupKey:r,projectId:o,hideGroupLabel:a,hasSessionSearchQuery:l,normalizedSessionSearchQuery:i,groupSearchDataByGroup:c,expandedSessionGroups:u,collapsedGroups:m,hideDirectoryControls:f,getFoldersForScope:h,collapsedFolderIds:p,toggleFolderCollapse:g,renameFolder:x,deleteFolder:b,showDeletionDialog:v,setDeleteFolderConfirm:y,renderSessionNode:w,projectRepoStatus:C,lastRepoStatus:N,toggleGroupSessionLimit:S,mobileVariant:k,activeProjectId:j,setActiveProjectIdOnly:F,setActiveMainTab:A,setSessionSwitcherOpen:M,openNewSessionDraft:B,addSessionToFolder:E,createFolderAndStartRename:I,renamingFolderId:P,renameFolderDraft:D,setRenameFolderDraft:L,setRenamingFolderId:T,pinnedSessionIds:_,prVisualStateByDirectoryBranch:z,onToggleCollapsedGroup:R,dragHandleProps:W}=t,G=l?c.get(n):null,J=B2(ZG)==="minimal";let V;e[0]!==u||e[1]!==r?(V=u.has(r),e[0]=u,e[1]=r,e[2]=V):V=e[2];const te=V;let U;e[3]!==m||e[4]!==r||e[5]!==l?(U=l?!1:m.has(r),e[3]=m,e[4]=r,e[5]=l,e[6]=U):U=e[6];const X=U,$=f?10:5,q=l?G?.groupMatches===!0:!1,ce=l?G?.filteredNodes??[]:n.sessions,ve=n.folderScopeKey??nn(n.directory??null),ge=ve?h(ve):[],xe=new Map,ne=Ae=>{Ae.forEach(Xe=>{xe.set(Xe.session.id,Xe),Xe.children.length>0&&ne(Xe.children)})};ne(ce);const O=ge.map(Ae=>{const Xe=Ae.sessionIds.map(yt=>xe.get(yt)).filter(GG).sort((yt,Tt)=>T1(yt.session,Tt.session,_));return{folder:Ae,nodes:Xe}}),H=new Map(O.map(qG)),K=Ae=>{const Xe=H.get(Ae);return Xe?!l||Xe.folder.name.toLowerCase().includes(i)||Xe.nodes.length>0?!0:O.filter(Tt=>{const{folder:Yt}=Tt;return Yt.parentId===Ae}).some(Tt=>{const{folder:Yt}=Tt;return K(Yt.id)}):!1},re=l?O.filter(Ae=>{const{folder:Xe}=Ae;return K(Xe.id)}):O,le=new Set(re.flatMap(WG)),ae=ce.filter(Ae=>!le.has(Ae.session.id)),ue=re.filter(UG);if(l&&!q&&ue.length===0&&ae.length===0)return null;const be=ae.length,oe=n.isArchivedBucket||l||te?ae:ae.slice(0,$),Z=be-oe.length,ie=VG,pe=ie(ce);let me;e[7]!==N||e[8]!==o||e[9]!==C?(me=o&&C.has(o)?!!C.get(o):N,e[7]=N,e[8]=o,e[9]=C,e[10]=me):me=e[10];const Se=me,ke=n.directory??null;let ye;e[11]!==ke?(ye=nn(ke),e[11]=ke,e[12]=ye):ye=e[12];const Ne=ye;let _e;e[13]!==n.branch?(_e=n.branch?.trim()??null,e[13]=n.branch,e[14]=_e):_e=e[14];const de=_e;let we;e[15]!==de||e[16]!==Ne||e[17]!==z?(we=Ne&&de?z.get(`${Ne}::${de}`)??null:null,e[15]=de,e[16]=Ne,e[17]=z,e[18]=we):we=e[18];const je=we,Ce=!!(je&&n.branch),ze=!je&&!n.isMain&&!!n.branch,Ge=je?.visualState??null,Le=je&&je.state==="open"&&je.checks?`${je.checks.success}/${je.checks.total} checks passed`:null;let qe;e[19]!==je?(qe=je&&je.state==="open"&&je.checks?[je.checks.failure>0?`${je.checks.failure} failing`:null,je.checks.pending>0?`${je.checks.pending} pending`:null].filter(OG).join(", "):null,e[19]=je,e[20]=qe):qe=e[20];const rt=qe,st=je&&je.state==="open"?je.mergeableState==="blocked"||je.mergeableState==="dirty"?"Conflicts or blocked":je.mergeableState==="clean"||je.canMerge===!0?"Mergeable":null:null,it=je&&je.state==="open"&&je.mergeableState?`Merge state: ${je.mergeableState}`:null,lt=je?.base??null,He=je?.head??null;let Oe;e:{if(!je){let Ae;e[21]!==n.branch||e[22]!==n.label?(Ae=n.branch&&gj(n.branch,n.label)?{label:n.branch,color:null}:null,e[21]=n.branch,e[22]=n.label,e[23]=Ae):Ae=e[23],Oe=Ae;break e}switch(je.visualState){case"merged":{let Ae;e[24]===Symbol.for("react.memo_cache_sentinel")?(Ae={label:"Merged",color:"var(--pr-merged)"},e[24]=Ae):Ae=e[24],Oe=Ae;break e}case"open":{let Ae;e[25]!==je.canMerge||e[26]!==je.checks?.state||e[27]!==je.mergeableState?(Ae=je.canMerge===!0||je.mergeableState==="clean"||je.checks?.state==="success"?{label:"Ready to merge",color:"var(--pr-open)"}:{label:"PR open",color:"var(--pr-open)"},e[25]=je.canMerge,e[26]=je.checks?.state,e[27]=je.mergeableState,e[28]=Ae):Ae=e[28],Oe=Ae;break e}case"blocked":{const Ae=je.mergeableState==="dirty"?"Merge conflicts":"Merge blocked";let Xe;e[29]!==Ae?(Xe={label:Ae,color:"var(--pr-blocked)"},e[29]=Ae,e[30]=Xe):Xe=e[30],Oe=Xe;break e}case"draft":{let Ae;e[31]===Symbol.for("react.memo_cache_sentinel")?(Ae={label:"Draft PR",color:"var(--pr-draft)"},e[31]=Ae):Ae=e[31],Oe=Ae;break e}case"closed":{let Ae;e[32]===Symbol.for("react.memo_cache_sentinel")?(Ae={label:"Closed",color:"var(--pr-closed)"},e[32]=Ae):Ae=e[32],Oe=Ae;break e}default:Oe=null}}const se=Oe,Pe=se?.color??(Ge?`var(--pr-${Ge})`:void 0);let Ye;e[33]!==je?.url?(Ye=Ae=>{Ae.preventDefault(),Ae.stopPropagation();const Xe=je?.url;Xe&&Xr(Xe)},e[33]=je?.url,e[34]=Ye):Ye=e[34];const We=Ye,xt=(Ae,Xe,yt)=>{const Tt=re.filter(Fs=>{const{folder:ds}=Fs;return ds.parentId===Ae.id}),Yt=Tt.length>0?s.jsx(s.Fragment,{children:Tt.map(Fs=>{const{folder:ds,nodes:es}=Fs;return s.jsx(d.Fragment,{children:xt(ds,es,yt+1)},ds.id)})}):void 0,Ut=Fs=>{const ds=re.find(gs=>{const{folder:Ks}=gs;return Ks.id===Fs})?.nodes??[],es=re.filter(gs=>{const{folder:Ks}=gs;return Ks.parentId===Fs});return[...ie(ds),...es.flatMap(gs=>{const{folder:Ks}=gs;return Ut(Ks.id)})]},Es=n.isArchivedBucket?Ut(Ae.id):[];return s.jsx(zG,{folderId:Ae.id,children:(Fs,ds)=>s.jsx(CG,{folder:Ae,sessions:Xe,subFolderItems:Yt,isCollapsed:l?!1:p.has(Ae.id),onToggle:()=>g(Ae.id),onRename:es=>{ve&&x(ve,Ae.id,es)},onDelete:()=>{if(n.isArchivedBucket){na.requestDelete({sessions:Es,mode:"session"});return}if(!ve)return;if(!v){b(ve,Ae.id);return}const es=re.filter(Ks=>{const{folder:Rs}=Ks;return Rs.parentId===Ae.id}).length,gs=Xe.length;y({scopeKey:ve,folderId:Ae.id,folderName:Ae.name,subFolderCount:es,sessionCount:gs})},renderSessionNode:w,groupDirectory:n.directory,projectId:o,mobileVariant:k,isRenaming:P===Ae.id,renameDraft:P===Ae.id?D:void 0,onRenameDraftChange:es=>L(es),onRenameSave:()=>{const es=D.trim();es&&ve&&x(ve,Ae.id,es),T(null),L("")},onRenameCancel:()=>{T(null),L("")},droppableRef:Fs,isDropTarget:ds,depth:yt,onNewSession:()=>{o&&o!==j&&F(o),A("chat"),k&&M(!1),B({directoryOverride:n.directory,targetFolderId:Ae.id})},onNewSubFolder:yt===0?()=>{ve&&I(ve,Ae.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Ae.id)},et=()=>ue.map(Ae=>{const{folder:Xe,nodes:yt}=Ae;return xt(Xe,yt,0)}),tt=!!(!n.isMain&&n.worktree),ht=k?tt?"pr-14":"pr-7":J?tt?"pr-10 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-10":tt?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",St=LG,Ue=re.length>0,ct=(Ae,Xe)=>{ve&&E(ve,Xe,Ae)},Qe=et();let at;e[35]!==n.directory||e[36]!==n.isArchivedBucket||e[37]!==o||e[38]!==w?(at=Ae=>s.jsx(d.Fragment,{children:w(Ae,0,n.directory,o,n.isArchivedBucket===!0)},Ae.session.id),e[35]=n.directory,e[36]=n.isArchivedBucket,e[37]=o,e[38]=w,e[39]=at):at=e[39];const Nt=oe.map(at);let jt;e[40]!==re||e[41]!==n.isArchivedBucket||e[42]!==be?(jt=be===0&&re.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?"No archived sessions yet.":"No sessions in this workspace yet."}):null,e[40]=re,e[41]=n.isArchivedBucket,e[42]=be,e[43]=jt):jt=e[43];let qt;e[44]!==r||e[45]!==te||e[46]!==Z||e[47]!==S?(qt=Z>0&&!te?s.jsxs("button",{type:"button",onClick:()=>S(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:["Show ",Z," more ",Z===1?"session":"sessions"]}):null,e[44]=r,e[45]=te,e[46]=Z,e[47]=S,e[48]=qt):qt=e[48];let Zt;e[49]!==r||e[50]!==te||e[51]!==$||e[52]!==S||e[53]!==be?(Zt=te&&be>$?s.jsx("button",{type:"button",onClick:()=>S(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:"Show fewer sessions"}):null,e[49]=r,e[50]=te,e[51]=$,e[52]=S,e[53]=be,e[54]=Zt):Zt=e[54];let Pt;e[55]!==St||e[56]!==ve||e[57]!==Ue||e[58]!==ct||e[59]!==Qe||e[60]!==Nt||e[61]!==jt||e[62]!==qt||e[63]!==Zt?(Pt=s.jsxs(St,{scopeKey:ve,hasFolders:Ue,onSessionDroppedOnFolder:ct,children:[Qe,Nt,jt,qt,Zt]}),e[55]=St,e[56]=ve,e[57]=Ue,e[58]=ct,e[59]=Qe,e[60]=Nt,e[61]=jt,e[62]=qt,e[63]=Zt,e[64]=Pt):Pt=e[64];const cs=Pt;if(a){let Ae;return e[65]!==cs?(Ae=s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:"oc-group-body pb-3 pl-4",children:cs})}),e[65]=cs,e[66]=Ae):Ae=e[66],Ae}let ss;e[67]===Symbol.for("react.memo_cache_sentinel")?(ss=Q("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),e[67]=ss):ss=e[67];let Wt;e[68]!==r||e[69]!==R?(Wt=()=>R(r),e[68]=r,e[69]=R,e[70]=Wt):Wt=e[70];let ls;e[71]!==r||e[72]!==R?(ls=Ae=>{(Ae.key==="Enter"||Ae.key===" ")&&(Ae.preventDefault(),R(r))},e[71]=r,e[72]=R,e[73]=ls):ls=e[73];const us=X?`Expand ${n.label}`:`Collapse ${n.label}`,ys=!X,ws=W?.setActivatorNodeRef;let Is;e[74]!==ht?(Is=Q("min-w-0 flex items-start gap-1 pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",ht),e[74]=ht,e[75]=Is):Is=e[75];let bs;e[76]!==W?.listeners?(bs=W?.listeners??{},e[76]=W?.listeners,e[77]=bs):bs=e[77];let Ss;e[78]!==lt||e[79]!==Pe||e[80]!==Le||e[81]!==rt||e[82]!==n.branch||e[83]!==n.isArchivedBucket||e[84]!==n.isMain||e[85]!==n.label||e[86]!==n.worktree||e[87]!==We||e[88]!==He||e[89]!==X||e[90]!==it||e[91]!==st||e[92]!==i||e[93]!==je||e[94]!==Ce?(Ss=Ce&&je?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(on,{className:"h-3.5 w-3.5 shrink-0 group-hover/gh:hidden",style:Pe?{color:Pe}:void 0}),s.jsx("span",{className:"hidden text-muted-foreground group-hover/gh:inline-flex h-3.5 w-3.5 items-center justify-center",children:X?s.jsx(On,{className:"h-3.5 w-3.5"}):s.jsx(Ds,{className:"h-3.5 w-3.5"})})]}),je.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:$G,onClick:We,children:["#",je.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",je.number]})]})}),s.jsx(_t,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[lt||He?s.jsx("div",{className:"text-muted-foreground truncate",children:lt&&He?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:lt}),s.jsx(_3,{className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:He})]}):s.jsx("span",{children:lt??He??""})}):null,it?s.jsx("div",{className:"text-muted-foreground truncate",children:it}):null,st||Le?s.jsxs("div",{className:"text-muted-foreground truncate",children:[st??"",st&&Le?" • ":"",Le??"",rt?` (${rt})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:n.branch})]}):n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 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(E3,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground group-hover/gh:hidden"}),s.jsx("span",{className:"hidden text-muted-foreground group-hover/gh:inline-flex h-3.5 w-3.5 items-center justify-center",children:X?s.jsx(On,{className:"h-3.5 w-3.5"}):s.jsx(Ds,{className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"truncate",children:p1(n.label,i)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 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(on,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground group-hover/gh:hidden",style:Pe?{color:Pe}:void 0}),s.jsx("span",{className:"hidden text-muted-foreground group-hover/gh:inline-flex h-3.5 w-3.5 items-center justify-center",children:X?s.jsx(On,{className:"h-3.5 w-3.5"}):s.jsx(Ds,{className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"truncate",children:p1(n.label,i)})]}):p1(n.label,i),e[78]=lt,e[79]=Pe,e[80]=Le,e[81]=rt,e[82]=n.branch,e[83]=n.isArchivedBucket,e[84]=n.isMain,e[85]=n.label,e[86]=n.worktree,e[87]=We,e[88]=He,e[89]=X,e[90]=it,e[91]=st,e[92]=i,e[93]=je,e[94]=Ce,e[95]=Ss):Ss=e[95];let Cs;e[96]!==Ss?(Cs=s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:Ss}),e[96]=Ss,e[97]=Cs):Cs=e[97];let ut;e[98]!==lt||e[99]!==Pe||e[100]!==Le||e[101]!==rt||e[102]!==n.isArchivedBucket||e[103]!==n.isMain||e[104]!==He||e[105]!==Se||e[106]!==it||e[107]!==st||e[108]!==je||e[109]!==ze||e[110]!==Ce||e[111]!==se?(ut=ze&&se?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(E3,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||Se?Ce&&je?s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(on,{className:"h-3.5 w-3.5 text-muted-foreground",style:Pe?{color:Pe}:void 0})})}),s.jsx(_t,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[lt||He?s.jsx("div",{className:"text-muted-foreground truncate",children:lt&&He?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:lt}),s.jsx(_3,{className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:He})]}):s.jsx("span",{children:lt??He??""})}):null,it?s.jsx("div",{className:"text-muted-foreground truncate",children:it}):null,st||Le?s.jsxs("div",{className:"text-muted-foreground truncate",children:[st??"",st&&Le?" • ":"",Le??"",rt?` (${rt})`:""]}):null]})})]}):s.jsx(on,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Pe?{color:Pe}:void 0}):null,s.jsx("span",{className:Q("min-w-0 truncate text-[11px] font-medium",!se.color&&"text-muted-foreground/80"),style:se.color?{color:se.color}:void 0,children:se.label})]}):null,e[98]=lt,e[99]=Pe,e[100]=Le,e[101]=rt,e[102]=n.isArchivedBucket,e[103]=n.isMain,e[104]=He,e[105]=Se,e[106]=it,e[107]=st,e[108]=je,e[109]=ze,e[110]=Ce,e[111]=se,e[112]=ut):ut=e[112];let Mt;e[113]!==Cs||e[114]!==ut?(Mt=s.jsxs("div",{className:"min-w-0 flex flex-col justify-center gap-0.5",children:[Cs,ut]}),e[113]=Cs,e[114]=ut,e[115]=Mt):Mt=e[115];let Kt;e[116]!==ws||e[117]!==Is||e[118]!==bs||e[119]!==Mt?(Kt=s.jsx("div",{ref:ws,className:Is,...bs,children:Mt}),e[116]=ws,e[117]=Is,e[118]=bs,e[119]=Mt,e[120]=Kt):Kt=e[120];let Ft;e[121]!==pe||e[122]!==n.isArchivedBucket||e[123]!==n.label||e[124]!==k?(Ft=n.isArchivedBucket&&pe.length>0?s.jsx("div",{className:Q("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",k?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ae=>{Ae.stopPropagation(),na.requestDelete({sessions:pe,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":`Delete archived sessions in ${n.label}`,children:s.jsx(Pn,{className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Delete archived sessions"})})]})}):null,e[121]=pe,e[122]=n.isArchivedBucket,e[123]=n.label,e[124]=k,e[125]=Ft):Ft=e[125];let Et;e[126]!==pe||e[127]!==n.directory||e[128]!==n.isMain||e[129]!==n.label||e[130]!==n.worktree||e[131]!==k?(Et=n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:Q("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",k?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ae=>{Ae.stopPropagation(),na.requestDelete({sessions:pe,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":`Delete ${n.label}`,children:s.jsx(Pn,{className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Delete worktree"})})]})}):null,e[126]=pe,e[127]=n.directory,e[128]=n.isMain,e[129]=n.label,e[130]=n.worktree,e[131]=k,e[132]=Et):Et=e[132];let bt;e[133]!==j||e[134]!==n.directory||e[135]!==n.label||e[136]!==k||e[137]!==B||e[138]!==o||e[139]!==A||e[140]!==F||e[141]!==M?(bt=n.directory?s.jsx("div",{className:Q("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",k?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ae=>{Ae.stopPropagation(),o&&o!==j&&F(o),A("chat"),k&&M(!1),B({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":`New draft session in ${n.label}`,children:s.jsx(Qs,{className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"New draft session"})})]})}):null,e[133]=j,e[134]=n.directory,e[135]=n.label,e[136]=k,e[137]=B,e[138]=o,e[139]=A,e[140]=F,e[141]=M,e[142]=bt):bt=e[142];let kt;e[143]!==Wt||e[144]!==ls||e[145]!==us||e[146]!==ys||e[147]!==Kt||e[148]!==Ft||e[149]!==Et||e[150]!==bt?(kt=s.jsxs("div",{className:ss,onClick:Wt,role:"button",tabIndex:0,onKeyDown:ls,"aria-label":us,"aria-expanded":ys,children:[Kt,Ft,Et,bt]}),e[143]=Wt,e[144]=ls,e[145]=us,e[146]=ys,e[147]=Kt,e[148]=Ft,e[149]=Et,e[150]=bt,e[151]=kt):kt=e[151];let as;e[152]!==cs||e[153]!==X?(as=X?null:s.jsx("div",{className:"oc-group-body pb-3 pl-4",children:cs}),e[152]=cs,e[153]=X,e[154]=as):as=e[154];let Gt;return e[155]!==kt||e[156]!==as?(Gt=s.jsxs("div",{className:"oc-group",children:[kt,as]}),e[155]=kt,e[156]=as,e[157]=Gt):Gt=e[157],Gt}function $G(t){return t.stopPropagation()}function OG(t){return!!t}function VG(t){const e=[],n=r=>{r.forEach(o=>{e.push(o.session),o.children.length>0&&n(o.children)})};return n(t),e}function UG(t){const{folder:e}=t;return!e.parentId}function WG(t){return t.folder.sessionIds}function qG(t){return[t.folder.id,t]}function GG(t){return!!t}function ZG(t){return t.displayMode}function KG(t){const e=Fe.c(27),{hideDirectoryControls:n,handleOpenDirectoryDialog:r,handleNewSession:o,useMobileNotesPanel:a,projectNotesPanelOpen:l,setProjectNotesPanelOpen:i,activeProjectRefForHeader:c,activeProjectLabelForHeader:u,canOpenMultiRun:m,openMultiRunLauncher:f,stableActiveProjectIsRepo:h,headerActionIconClass:p,reserveHeaderActionsSpace:g,headerActionButtonClass:x,isSessionSearchOpen:b,setIsSessionSearchOpen:v,sessionSearchInputRef:y,sessionSearchQuery:w,setSessionSearchQuery:C,hasSessionSearchQuery:N,searchMatchCount:S,collapseAllProjects:k,expandAllProjects:j}=t,F=B2(QG),A=B2(XG);if(n)return null;let M;e[0]!==u||e[1]!==c||e[2]!==m||e[3]!==k||e[4]!==F||e[5]!==j||e[6]!==o||e[7]!==r||e[8]!==N||e[9]!==x||e[10]!==p||e[11]!==b||e[12]!==f||e[13]!==l||e[14]!==g||e[15]!==S||e[16]!==y||e[17]!==w||e[18]!==A||e[19]!==v||e[20]!==i||e[21]!==C||e[22]!==h||e[23]!==a?(M=g?s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:x,"aria-label":"Add project",children:s.jsx(Pi,{className:p})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Add project"})})]}),s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:x,"aria-label":"New session",children:s.jsx(F1,{className:p})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"New session"})})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:x,"aria-label":"New multi-run",disabled:!m,children:s.jsx(Ap,{className:p})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"New multi-run"})})]}),a?s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>i(!0),className:x,"aria-label":"Project notes",disabled:!c,children:s.jsx(Md,{className:p})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Project notes"})})]}):s.jsxs(qs,{open:l,onOpenChange:i,modal:!1,children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:x,"aria-label":"Project notes",disabled:!c,children:s.jsx(Md,{className:p})})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Project notes"})})]}),s.jsx(Ys,{align:"start",className:"w-[420px] max-w-[min(92vw,420px)] p-0",children:s.jsx(X7,{projectRef:c,projectLabel:u,canCreateWorktree:h,onActionComplete:()=>i(!1)})})]}),s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>v(YG),className:x,"aria-label":"Search sessions","aria-expanded":b,children:s.jsx(xr,{className:p})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Search sessions"})})]}),s.jsxs(qs,{children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:x,"aria-label":"Session display mode",children:s.jsx(_b,{className:p})})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Display mode"})})]}),s.jsxs(Ys,{align:"end",className:"min-w-[160px]",children:[s.jsxs(Jt,{onClick:()=>A("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:"Default"}),F==="default"?s.jsx(js,{className:"h-4 w-4 text-primary"}):null]}),s.jsxs(Jt,{onClick:()=>A("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:"Minimal"}),F==="minimal"?s.jsx(js,{className:"h-4 w-4 text-primary"}):null]}),s.jsx(Zn,{}),s.jsxs(Jt,{onClick:k,className:"flex items-center gap-2",children:[s.jsx(Eb,{className:"h-4 w-4"}),s.jsx("span",{children:"Collapse all"})]}),s.jsxs(Jt,{onClick:j,className:"flex items-center gap-2",children:[s.jsx(Db,{className:"h-4 w-4"}),s.jsx("span",{children:"Expand all"})]})]})]})]})]}),b?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[N?s.jsxs("span",{children:[S," ",S===1?"match":"matches"]}):s.jsx("span",{}),s.jsx("span",{children:"Esc to clear"})]}),s.jsxs("div",{className:"relative",children:[s.jsx(xr,{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:y,value:w,onChange:E=>C(E.target.value),placeholder:"Search sessions...",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:E=>{E.key==="Escape"&&(E.stopPropagation(),N?C(""):v(!1))}}),w.length>0?s.jsx("button",{type:"button",onClick:()=>C(""),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":"Clear search",children:s.jsx(Ps,{className:"h-3.5 w-3.5"})}):null]})]}):null]}):null,e[0]=u,e[1]=c,e[2]=m,e[3]=k,e[4]=F,e[5]=j,e[6]=o,e[7]=r,e[8]=N,e[9]=x,e[10]=p,e[11]=b,e[12]=f,e[13]=l,e[14]=g,e[15]=S,e[16]=y,e[17]=w,e[18]=A,e[19]=v,e[20]=i,e[21]=C,e[22]=h,e[23]=a,e[24]=M):M=e[24];let B;return e[25]!==M?(B=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:M}),e[25]=M,e[26]=B):B=e[26],B}function YG(t){return!t}function XG(t){return t.setDisplayMode}function QG(t){return t.displayMode}const sh=7;function JG(t){const e=Fe.c(18),{sections:n,renderSessionNode:r}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=new Set,e[0]=o):o=e[0];const[a,l]=d.useState(o);let i;e[1]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[1]=i):i=e[1];const[c,u]=d.useState(i);let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=y=>{l(w=>{const C=new Set(w);return C.has(y)?C.delete(y):C.add(y),C})},e[2]=m):m=e[2];const f=m;let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h=y=>{u(w=>{const C=new Set(w);return C.has(y)?C.delete(y):C.add(y),C})},e[3]=h):h=e[3];const p=h;let g,x,b;if(e[4]!==a||e[5]!==c||e[6]!==r||e[7]!==n){b=Symbol.for("react.early_return_sentinel");e:{const y=n.filter(eZ);if(y.length===0){b=null;break e}g="space-y-2 pb-2 pt-1";let w;e[11]!==a||e[12]!==c||e[13]!==r?(w=C=>{const N=a.has(C.key),S=c.has(C.key),k=S?C.items:C.items.slice(0,sh),j=C.items.length-k.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>f(C.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!N,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:N?s.jsx(On,{className:"h-3.5 w-3.5"}):s.jsx(Ds,{className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:C.title})]}),N?null:s.jsxs("div",{className:Q("space-y-0.5 pl-7"),children:[k.map(F=>r(F.node,0,F.groupDirectory,F.projectId,!1,F.secondaryMeta,"recent")),j>0&&!S?s.jsxs("button",{type:"button",onClick:()=>p(C.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:["Show ",j," more ",j===1?"session":"sessions"]}):null,S&&C.items.length>sh?s.jsx("button",{type:"button",onClick:()=>p(C.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:"Show fewer sessions"}):null]})]},C.key)},e[11]=a,e[12]=c,e[13]=r,e[14]=w):w=e[14],x=y.map(w)}e[4]=a,e[5]=c,e[6]=r,e[7]=n,e[8]=g,e[9]=x,e[10]=b}else g=e[8],x=e[9],b=e[10];if(b!==Symbol.for("react.early_return_sentinel"))return b;let v;return e[15]!==g||e[16]!==x?(v=s.jsx("div",{className:g,children:x}),e[15]=g,e[16]=x,e[17]=v):v=e[17],v}function eZ(t){return t.items.length>0}const pd="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 tZ(t){const e=Fe.c(11),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:o,onOpenUpdate:a,showRuntimeButtons:l,showUpdateButton:i}=t,c=l===void 0?!0:l,u=i===void 0?!0:i;let m;e[0]!==o||e[1]!==n||e[2]!==r||e[3]!==c?(m=c?s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:pd,"aria-label":"Settings",children:s.jsx(xa,{className:"h-4.5 w-4.5"})})}),s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:"Settings"})})]}),s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:pd,"aria-label":"Shortcuts",children:s.jsx(Bl,{className:"h-4.5 w-4.5"})})}),s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:"Shortcuts"})})]}),s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:pd,"aria-label":"About ArchCoder",children:s.jsx(Fn,{className:"h-4.5 w-4.5"})})}),s.jsx(_t,{side:"top",sideOffset:4,children:s.jsx("p",{children:"About ArchCoder"})})]})]}):null,e[0]=o,e[1]=n,e[2]=r,e[3]=c,e[4]=m):m=e[4];let f;e[5]!==a||e[6]!==u?(f=u?s.jsx(Be,{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)]",onClick:a,children:"Update"}):null,e[5]=a,e[6]=u,e[7]=f):f=e[7];let h;return e[8]!==m||e[9]!==f?(h=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[m,f]}),e[8]=m,e[9]=f,e[10]=h):h=e[10],h}const sZ=t=>{const e=Fe.c(59),{id:n,projectLabel:r,projectDescription:o,projectIcon:a,projectColor:l,projectIconImage:i,projectIconBackground:c,isCollapsed:u,isActiveProject:m,isHovered:f,isRepo:h,isDesktopShell:p,isStuck:g,hideDirectoryControls:x,mobileVariant:b,onToggle:v,onHoverChange:y,onNewSession:w,onNewWorktreeSession:C,onRenameStart:N,onClose:S,sentinelRef:k,children:j,showCreateButtons:F,hideHeader:A,openSidebarMenuKey:M,setOpenSidebarMenuKey:B}=t,E=F===void 0?!0:F,I=A===void 0?!1:A,{currentTheme:P}=qn();let D;e[0]!==n?(D={id:n},e[0]=n,e[1]=D):D=e[1];const{attributes:L,listeners:T,setNodeRef:_,transform:z,transition:R,isDragging:W}=E2(D),[G,Y]=d.useState(!1),J=d.useRef(!1),V=`project:${n}`,te=M===V;let U;e[2]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{Y(!1)},e[2]=U):U=e[2];const X=i?.updatedAt;let $;e[3]!==n||e[4]!==X?($=[n,X],e[3]=n,e[4]=X,e[5]=$):$=e[5],d.useEffect(U,$);const q=a?Hl[a]:null,ee=l?ja[l]??null:null;let ce;e[6]!==P||e[7]!==n||e[8]!==G||e[9]!==i?(ce=G?null:ka({id:n,iconImage:i},{themeVariant:P.metadata.variant,iconColor:P.colors.surface.foreground}),e[6]=P,e[7]=n,e[8]=G,e[9]=i,e[10]=ce):ce=e[10];const ve=ce;let ge;e[11]!==V||e[12]!==B?(ge=ie=>{B(ie?V:null)},e[11]=V,e[12]=B,e[13]=ge):ge=e[13];const xe=ge,ne=oZ;let O;e[14]===Symbol.for("react.memo_cache_sentinel")?(O=ie=>{(ie.button===2||ie.button===0&&ie.ctrlKey)&&(J.current=!0)},e[14]=O):O=e[14];const H=O;let K;e[15]!==v?(K=()=>{if(J.current){J.current=!1;return}v()},e[15]=v,e[16]=K):K=e[16];const re=K;let le;e[17]!==z?(le=D2.Transform.toString(z),e[17]=z,e[18]=le):le=e[18];let ae;e[19]!==le||e[20]!==R?(ae={transform:le,transition:R},e[19]=le,e[20]=R,e[21]=ae):ae=e[21];const ue=W&&"opacity-30";let be;e[22]!==ue?(be=Q("relative",ue),e[22]=ue,e[23]=be):be=e[23];let oe;e[24]!==q||e[25]!==L||e[26]!==xe||e[27]!==re||e[28]!==x||e[29]!==I||e[30]!==ee||e[31]!==n||e[32]!==ve||e[33]!==m||e[34]!==u||e[35]!==p||e[36]!==f||e[37]!==te||e[38]!==h||e[39]!==g||e[40]!==T||e[41]!==b||e[42]!==S||e[43]!==y||e[44]!==w||e[45]!==C||e[46]!==N||e[47]!==o||e[48]!==c||e[49]!==r||e[50]!==k||e[51]!==E?(oe=I?null:s.jsxs(s.Fragment,{children:[p&&s.jsx("div",{ref:k,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:Q("w-full text-left group/project select-none"),style:{backgroundColor:p&&g?"transparent":void 0},onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",...L,children:[s.jsxs(Dt,{delayDuration:1500,children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:H,onClick:re,...T,className:Q("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]",h&&!x?b||f?"pr-20":"pr-7":b||f?"pr-14":"pr-7"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:Q("hidden text-muted-foreground h-3.5 w-3.5 items-center justify-center",f&&"inline-flex"),children:u?s.jsx(On,{className:"h-3.5 w-3.5"}):s.jsx(Ds,{className:"h-3.5 w-3.5"})}),ve?s.jsx("span",{className:Q("inline-flex h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",f&&"hidden"),style:c?{backgroundColor:c}:void 0,children:s.jsx("img",{src:ve,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>Y(!0)})}):q?s.jsx(q,{className:Q("h-3.5 w-3.5",f&&"hidden"),style:ee?{color:ee}:void 0}):s.jsx(jr,{className:Q("h-3.5 w-3.5 text-muted-foreground/80",f&&"hidden"),style:ee?{color:ee}:void 0})]}),s.jsx("span",{className:Q("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(_t,{side:"right",sideOffset:8,children:o})]}),s.jsxs("div",{className:Q("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",E?"right-7":"right-0.5"),children:[E&&h&&!x&&C?s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),C()},className:Q("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||f?"opacity-100":"opacity-0 pointer-events-none"),"aria-label":"New worktree",children:s.jsx(Ib,{className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"New worktree..."})})]}):null,s.jsxs(qs,{open:te,onOpenChange:xe,children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:Q("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",te?"opacity-100 pointer-events-auto":b||f?"opacity-100":"opacity-0 pointer-events-none"),"aria-label":"Project menu",onClick:ne,children:s.jsx(Qr,{className:"h-3.5 w-3.5"})})}),s.jsxs(Ys,{align:"end",className:"min-w-[180px]",children:[E&&!h&&!x&&w&&s.jsxs(Jt,{onClick:w,children:[s.jsx(Qs,{className:"mr-1.5 h-4 w-4"}),"New Session"]}),s.jsxs(Jt,{onClick:N,children:[s.jsx(_o,{className:"mr-1.5 h-4 w-4"}),"Rename"]}),s.jsxs(Jt,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(Ps,{className:"mr-1.5 h-4 w-4"}),"Close Project"]})]})]})]}),E&&w?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),w()},className:Q("h-6 w-6 rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",b||f?"inline-flex items-center justify-center":"hidden"),"aria-label":h?"New draft session":"New session",children:s.jsx(Qs,{className:"h-4 w-4"})})}),s.jsx(_t,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:h?"New draft session":"New session"})})]})}):null]})})]}),e[24]=q,e[25]=L,e[26]=xe,e[27]=re,e[28]=x,e[29]=I,e[30]=ee,e[31]=n,e[32]=ve,e[33]=m,e[34]=u,e[35]=p,e[36]=f,e[37]=te,e[38]=h,e[39]=g,e[40]=T,e[41]=b,e[42]=S,e[43]=y,e[44]=w,e[45]=C,e[46]=N,e[47]=o,e[48]=c,e[49]=r,e[50]=k,e[51]=E,e[52]=oe):oe=e[52];let Z;return e[53]!==j||e[54]!==_||e[55]!==ae||e[56]!==be||e[57]!==oe?(Z=s.jsxs("div",{ref:_,style:ae,className:be,children:[oe,j]}),e[53]=j,e[54]=_,e[55]=ae,e[56]=be,e[57]=oe,e[58]=Z):Z=e[58],Z},nZ=t=>{const e=Fe.c(21),{id:n,disabled:r,children:o}=t,a=r===void 0?!1:r;let l;e[0]!==a||e[1]!==n?(l={id:n,disabled:a},e[0]=a,e[1]=n,e[2]=l):l=e[2];const{listeners:i,setNodeRef:c,setActivatorNodeRef:u,transform:m,transition:f,isDragging:h}=E2(l);let p;e[3]!==i||e[4]!==u?(p={listeners:i,setActivatorNodeRef:u},e[3]=i,e[4]=u,e[5]=p):p=e[5];const g=p;let x;e[6]!==m?(x=D2.Transform.toString(m),e[6]=m,e[7]=x):x=e[7];let b;e[8]!==x||e[9]!==f?(b={transform:x,transition:f},e[8]=x,e[9]=f,e[10]=b):b=e[10];const v=h&&"opacity-50";let y;e[11]!==v?(y=Q("space-y-0.5 rounded-md",v),e[11]=v,e[12]=y):y=e[12];let w;e[13]!==o||e[14]!==g?(w=typeof o=="function"?o(g):o,e[13]=o,e[14]=g,e[15]=w):w=e[15];let C;return e[16]!==c||e[17]!==b||e[18]!==y||e[19]!==w?(C=s.jsx("div",{ref:c,style:b,className:y,children:w}),e[16]=c,e[17]=b,e[18]=y,e[19]=w,e[20]=C):C=e[20],C},rZ=d.memo(nZ);function oZ(t){t.stopPropagation()}function aZ(t){const e=Fe.c(24);let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={activationConstraint:{distance:8}},e[0]=n):n=e[0];let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r={coordinateGetter:Th},e[1]=r):r=e[1];const o=N1(xl(S1,n),xl(Ih,r));let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={activationConstraint:{distance:8}},e[2]=a):a=e[2];const l=N1(xl(S1,a));if(t.projectSections.length===0){const f=(t.mobileVariant,"");let h;e[3]!==f?(h=Q("space-y-1 pb-1 pl-2.5 pr-2",f),e[3]=f,e[4]=h):h=e[4];let p;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==h?(p=s.jsxs(ks,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:h,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=h,e[8]=p):p=e[8],p}if(t.sectionsForRender.length===0){const f=(t.mobileVariant,"");let h;e[9]!==f?(h=Q("space-y-1 pb-1 pl-2.5 pr-2",f),e[9]=f,e[10]=h):h=e[10];let p;return e[11]!==t.searchEmptyState||e[12]!==h?(p=s.jsx(ks,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:h,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=h,e[13]=p):p=e[13],p}const i=(t.mobileVariant,"");let c;e[14]!==i?(c=Q("space-y-1 pb-1 pl-2.5 pr-2",i),e[14]=i,e[15]=c):c=e[15];let u;e[16]!==l||e[17]!==o||e[18]!==t?(u=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const f=t.sectionsForRender.find(x=>x.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!f)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const h=f.groups.find(hZ)??f.groups.find(mZ)??f.groups.find(fZ)??f.groups[0];if(!h)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:"No sessions yet."});const p=f.groups.find(uZ);return[h,...p&&p.id!==h.id?[p]:[]].map(x=>{const b=`${f.project.id}:${x.id}`,v=x.id===h.id;return s.jsx(d.Fragment,{children:t.renderGroupSessions(x,b,f.project.id,v)},b)})})()}):s.jsx(s.Fragment,{children:s.jsxs(C1,{sensors:o,collisionDetection:A1,onDragEnd:f=>{if(t.isInlineEditing)return;const{active:h,over:p}=f;if(!p||h.id===p.id)return;const g=t.sectionsForRender.findIndex(b=>b.project.id===h.id),x=t.sectionsForRender.findIndex(b=>b.project.id===p.id);g===-1||x===-1||g===x||t.reorderProjects(g,x)},children:[s.jsx(X0,{items:t.sectionsForRender.map(dZ),strategy:jd,children:t.sectionsForRender.map(f=>{const h=f.project,p=h.id,g=u8(h.label?.trim()||Or(h.normalizedPath,t.homeDirectory)||h.normalizedPath),x=va(h.normalizedPath,t.homeDirectory),b=t.collapsedProjects.has(p),v=p===t.activeProjectId,y=t.hoveredProjectId===p,w=t.projectRepoStatus.get(p),C=t.getOrderedGroups(p,f.groups),N=C.find(cZ)??null,S=N?C.filter(k=>k.id!==N.id):C;return s.jsx(sZ,{id:p,projectLabel:g,projectDescription:x,projectIcon:h.icon,projectColor:h.color,projectIconImage:h.iconImage,projectIconBackground:h.iconBackground,isCollapsed:b,isActiveProject:v,isHovered:y,isRepo:!!w,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(p),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,onToggle:()=>t.toggleProject(p),onHoverChange:k=>t.setHoveredProjectId(k?p:null),onNewSession:()=>{p!==t.activeProjectId&&t.setActiveProjectIdOnly(p),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:h.normalizedPath})},onNewWorktreeSession:()=>{p!==t.activeProjectId&&t.setActiveProjectIdOnly(p),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(p),onClose:()=>t.removeProject(p),sentinelRef:k=>{t.projectHeaderSentinelRefs.current.set(p,k)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:b?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:f.groups.length>0?s.jsxs(C1,{sensors:l,collisionDetection:A1,onDragEnd:k=>{if(t.isInlineEditing)return;const{active:j,over:F}=k;if(!F||j.id===F.id)return;const A=S.findIndex(I=>I.id===j.id),M=S.findIndex(I=>I.id===F.id);if(A===-1||M===-1||A===M)return;const B=T0(S,A,M).map(iZ),E=N?[N.id,...B]:B;t.setGroupOrderByProject(I=>{const P=new Map(I);return P.set(p,E),P})},children:[N?t.renderGroupSessions(N,`${p}:${N.id}`,p,!0):null,s.jsx(X0,{items:S.map(lZ),strategy:jd,children:S.map(k=>{const j=`${p}:${k.id}`;return s.jsx(rZ,{id:k.id,disabled:t.isInlineEditing,children:F=>t.renderGroupSessions(k,j,p,!1,F)},k.id)})}),s.jsx(Q0,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:"No sessions yet."})})},p)})}),s.jsx(Q0,{dropAnimation:null})]})}),e[16]=l,e[17]=o,e[18]=t,e[19]=u):u=e[19];let m;return e[20]!==t.topContent||e[21]!==c||e[22]!==u?(m=s.jsxs(ks,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:c,children:[t.topContent,u]}),e[20]=t.topContent,e[21]=c,e[22]=u,e[23]=m):m=e[23],m}function lZ(t){return t.id}function iZ(t){return t.id}function cZ(t){return t.isMain}function dZ(t){return t.project.id}function uZ(t){return t.isArchivedBucket}function fZ(t){return t.isMain}function mZ(t){return t.sessions.length>0}function hZ(t){return t.isMain&&t.sessions.length>0}const pZ=new Set([1,3,4,5,7]),gZ=t=>t===4?"0ms":"130ms";function xZ(t){const e=Fe.c(276),{node:n,depth:r,groupDirectory:o,projectId:a,archivedBucket:l,directoryStatus:i,sessionMemoryState:c,currentSessionId:u,pinnedSessionIds:m,expandedParents:f,hasSessionSearchQuery:h,normalizedSessionSearchQuery:p,sessionAttentionStates:g,notifyOnSubtasks:x,sessionStatus:b,permissions:v,editingId:y,setEditingId:w,editTitle:C,setEditTitle:N,handleSaveEdit:S,handleCancelEdit:k,toggleParent:j,handleSessionSelect:F,handleSessionDoubleClick:A,togglePinnedSession:M,handleShareSession:B,copiedSessionId:E,handleCopyShareUrl:I,handleUnshareSession:P,openSidebarMenuKey:D,setOpenSidebarMenuKey:L,renamingFolderId:T,getFoldersForScope:_,getSessionFolderId:z,removeSessionFromFolder:R,addSessionToFolder:W,createFolderAndStartRename:G,openContextPanelTab:Y,handleDeleteSession:J,mobileVariant:V,renderSessionNode:te,secondaryMeta:U,renderContext:X}=t,$=r===void 0?0:r,q=l===void 0?!1:l,ee=X===void 0?"project":X,ce=!!U?.projectLabel,ve=!!U?.branchLabel,xe=B2(jZ)==="minimal";let ne;e[0]===Symbol.for("react.memo_cache_sentinel")?(ne=xn(),e[0]=ne):ne=e[0];const O=ne,H=d.useRef(!1),K=n.session,re=`${ee}:${q?"archived":"active"}:${K.id}`;let le,ae,ue,be,oe,Z,ie,pe,me,Se,ke,ye,Ne,_e,de,we,je,Ce,ze,Ge,Le,qe,rt,st,it,lt,He,Oe,se;if(e[1]!==W||e[2]!==q||e[3]!==E||e[4]!==G||e[5]!==u||e[6]!==$||e[7]!==i||e[8]!==C||e[9]!==y||e[10]!==f||e[11]!==_||e[12]!==z||e[13]!==o||e[14]!==k||e[15]!==I||e[16]!==S||e[17]!==F||e[18]!==B||e[19]!==P||e[20]!==ve||e[21]!==ce||e[22]!==h||e[23]!==xe||e[24]!==re||e[25]!==n.children.length||e[26]!==x||e[27]!==D||e[28]!==v||e[29]!==m||e[30]!==a||e[31]!==R||e[32]!==T||e[33]!==U?.branchLabel||e[34]!==U?.projectLabel||e[35]!==K||e[36]!==g||e[37]!==c||e[38]!==b||e[39]!==N||e[40]!==w||e[41]!==L||e[42]!==j||e[43]!==M){rt=Symbol.for("react.early_return_sentinel");e:{je=nn(K.directory??null)??nn(o??null),ke=(je?i.get(je):null)==="missing";let ys;e[73]!==K.id||e[74]!==c?(ys=c.get(K.id),e[73]=K.id,e[74]=c,e[75]=ys):ys=e[75];const ws=ys;pe=u===K.id,Ce=K.title||"Untitled Session",Z=n.children.length>0;let Is;e[76]!==m||e[77]!==K.id?(Is=m.has(K.id),e[76]=m,e[77]=K.id,e[78]=Is):Is=e[78],ye=Is;let bs;e[79]!==f||e[80]!==h||e[81]!==K.id?(bs=h?!0:f.has(K.id),e[79]=f,e[80]=h,e[81]=K.id,e[82]=bs):bs=e[82],me=bs;const Ss=!!K.parentID;let Cs;e[83]!==K.id||e[84]!==g?(Cs=g.get(K.id)?.needsAttention,e[83]=K.id,e[84]=g,e[85]=Cs):Cs=e[85];const Mt=Cs===!0&&(!Ss||x),Kt=K.summary;let Ft;e[86]!==Kt?(Ft=d8(Kt),e[86]=Kt,e[87]=Ft):Ft=e[87],we=Ft;let Et;e[88]!==K.time?.created||e[89]!==K.time?.updated?(Et=K.time?.updated||K.time?.created||Date.now(),e[88]=K.time?.created,e[89]=K.time?.updated,e[90]=Et):Et=e[90];const bt=Et;let kt;e[91]!==bt?(kt=hj(bt),e[91]=bt,e[92]=kt):kt=e[92],ze=kt;let as;if(e[93]!==bt?(as=pj(bt),e[93]=bt,e[94]=as):as=e[94],de=as,Se=D===re,y===K.id){const Ve=K.id,ft=$>0&&"pl-[20px]";let Bt;e[95]!==ft?(Bt=Q("group relative flex items-center rounded-sm px-1.5 py-1",ft),e[95]=ft,e[96]=Bt):Bt=e[96];let At;e[97]!==S?(At=zs=>{zs.preventDefault(),S()},e[97]=S,e[98]=At):At=e[98];let mt;e[99]!==N?(mt=zs=>N(zs.target.value),e[99]=N,e[100]=mt):mt=e[100];let Lt;e[101]!==k?(Lt=zs=>{if(zs.key==="Escape"){zs.stopPropagation(),k();return}(zs.key===" "||zs.key==="Enter")&&zs.stopPropagation()},e[101]=k,e[102]=Lt):Lt=e[102];let $t;e[103]!==C||e[104]!==mt||e[105]!==Lt?($t=s.jsx("input",{value:C,onChange:mt,className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:"Rename session",onKeyDown:Lt}),e[103]=C,e[104]=mt,e[105]=Lt,e[106]=$t):$t=e[106];let Xs;e[107]===Symbol.for("react.memo_cache_sentinel")?(Xs=s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(js,{className:"size-4"})}),e[107]=Xs):Xs=e[107];let As;e[108]===Symbol.for("react.memo_cache_sentinel")?(As=s.jsx(Ps,{className:"size-4"}),e[108]=As):As=e[108];let Ot;e[109]!==k?(Ot=s.jsx("button",{type:"button",onClick:k,className:"shrink-0 text-muted-foreground hover:text-foreground",children:As}),e[109]=k,e[110]=Ot):Ot=e[110];let fs;e[111]!==At||e[112]!==$t||e[113]!==Ot?(fs=s.jsxs("form",{className:"flex w-full items-center gap-2","data-keyboard-avoid":"true",onSubmit:At,children:[$t,Xs,Ot]}),e[111]=At,e[112]=$t,e[113]=Ot,e[114]=fs):fs=e[114];let ms;e[115]!==Z||e[116]!==ve||e[117]!==ce||e[118]!==me||e[119]!==xe||e[120]!==U?.branchLabel||e[121]!==U?.projectLabel||e[122]!==we||e[123]!==ze?(ms=xe?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[Z?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:me?s.jsx(Ds,{className:"h-3 w-3"}):s.jsx(On,{className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:ze}),we?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",we.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",we.deletions]})]}):null,ce?s.jsx("span",{className:"truncate",children:U?.projectLabel}):null,ve?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(on,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:U?.branchLabel})]}):null]})}),e[115]=Z,e[116]=ve,e[117]=ce,e[118]=me,e[119]=xe,e[120]=U?.branchLabel,e[121]=U?.projectLabel,e[122]=we,e[123]=ze,e[124]=ms):ms=e[124];let Hs;e[125]!==fs||e[126]!==ms?(Hs=s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[fs,ms]}),e[125]=fs,e[126]=ms,e[127]=Hs):Hs=e[127];let rn;e[128]!==K.id||e[129]!==Bt||e[130]!==Hs?(rn=s.jsx("div",{className:Bt,children:Hs},Ve),e[128]=K.id,e[129]=Bt,e[130]=Hs,e[131]=rn):rn=e[131],rt=rn;break e}let Gt;e[132]!==K.id||e[133]!==b?(Gt=b?.get(K.id)?.type??"idle",e[132]=K.id,e[133]=b,e[134]=Gt):Gt=e[134];const Ae=Gt,Xe=Ae==="busy"||Ae==="retry";let yt;e[135]!==v||e[136]!==K.id?(yt=v.get(K.id)?.length??0,e[135]=v,e[136]=K.id,e[137]=yt):yt=e[137],_e=yt;const Yt=Xe||!Xe&&Mt&&!pe;let Ut;e[138]!==Xe?(Ut=Xe?s.jsx(h3,{size:"xs",className:"text-primary"}):s.jsx("span",{className:"grid grid-cols-3 gap-[1px] text-[var(--status-info)]","aria-label":"Unread updates",title:"Unread updates",children:Array.from({length:9},wZ)}),e[138]=Xe,e[139]=Ut):Ut=e[139];const Es=Ut;let Fs;e[140]!==xe||e[141]!==Yt||e[142]!==Es?(Fs=!xe&&Yt?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:Es}):null,e[140]=xe,e[141]=Yt,e[142]=Es,e[143]=Fs):Fs=e[143],ie=Fs;let ds;e[144]!==Z||e[145]!==xe||e[146]!==Yt||e[147]!==Es?(ds=xe&&Yt?s.jsx("span",{className:Q("pointer-events-none absolute left-[-10px] top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center transition-opacity",Z?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:Es}):null,e[144]=Z,e[145]=xe,e[146]=Yt,e[147]=Es,e[148]=ds):ds=e[148],Ne=ds;let es;e[149]!==Z||e[150]!==me||e[151]!==xe||e[152]!==K.id||e[153]!==Yt||e[154]!==j?(es=Z?s.jsx("span",{role:"button",tabIndex:0,onClick:Ve=>{Ve.stopPropagation(),j(K.id)},onKeyDown:Ve=>{(Ve.key==="Enter"||Ve.key===" ")&&(Ve.preventDefault(),Ve.stopPropagation(),j(K.id))},className:Q("absolute left-[-10px] 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",xe&&Yt?"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":me?"Collapse subsessions":"Expand subsessions",children:me?s.jsx(Ds,{className:"h-3 w-3"}):s.jsx(On,{className:"h-3 w-3"})}):null,e[149]=Z,e[150]=me,e[151]=xe,e[152]=K.id,e[153]=Yt,e[154]=j,e[155]=es):es=e[155],Le=es;let gs;e[156]!==ws?.isZombie?(gs=ws?.isZombie?s.jsx(ba,{className:"h-4 w-4 text-status-warning"}):null,e[156]=ws?.isZombie,e[157]=gs):gs=e[157],Ge=gs;let Ks;e[158]!==re||e[159]!==L?(Ks=Ve=>{L(Ve?re:null)},e[158]=re,e[159]=L,e[160]=Ks):Ks=e[160],ae=Ks,ue=yZ,oe=()=>{if(H.current){H.current=!1;return}F(K.id,je,ke,a)};let Rs;e[161]===Symbol.for("react.memo_cache_sentinel")?(Rs=Ve=>{(Ve.button===2||Ve.button===0&&Ve.ctrlKey)&&(H.current=!0)},e[161]=Rs):Rs=e[161],be=Rs,le=Ys,st="end",it="min-w-[180px]",e[162]!==T?(lt=Ve=>{T&&Ve.preventDefault()},e[162]=T,e[163]=lt):lt=e[163];let un;e[164]!==K.id||e[165]!==Ce||e[166]!==N||e[167]!==w?(un=()=>{w(K.id),N(Ce)},e[164]=K.id,e[165]=Ce,e[166]=N,e[167]=w,e[168]=un):un=e[168];let zn;e[169]===Symbol.for("react.memo_cache_sentinel")?(zn=s.jsx(_o,{className:"mr-1 h-4 w-4"}),e[169]=zn):zn=e[169],e[170]!==un?(He=s.jsxs(Jt,{onClick:un,className:"[&>svg]:mr-1",children:[zn,"Rename"]}),e[170]=un,e[171]=He):He=e[171];let Te;e[172]!==K.id||e[173]!==M?(Te=()=>M(K.id),e[172]=K.id,e[173]=M,e[174]=Te):Te=e[174];let Ie;e[175]!==ye?(Ie=ye?s.jsx(Rb,{className:"mr-1 h-4 w-4"}):s.jsx(z0,{className:"mr-1 h-4 w-4"}),e[175]=ye,e[176]=Ie):Ie=e[176];const Ke=ye?"Unpin session":"Pin session";e[177]!==Te||e[178]!==Ie||e[179]!==Ke?(Oe=s.jsxs(Jt,{onClick:Te,className:"[&>svg]:mr-1",children:[Ie,Ke]}),e[177]=Te,e[178]=Ie,e[179]=Ke,e[180]=Oe):Oe=e[180],e[181]!==E||e[182]!==I||e[183]!==B||e[184]!==P||e[185]!==K?(se=K.share?s.jsxs(s.Fragment,{children:[s.jsx(Jt,{onClick:()=>{K.share?.url&&I(K.share.url,K.id)},className:"[&>svg]:mr-1",children:E===K.id?s.jsxs(s.Fragment,{children:[s.jsx(js,{className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),"Copied"]}):s.jsxs(s.Fragment,{children:[s.jsx(nr,{className:"mr-1 h-4 w-4"}),"Copy link"]})}),s.jsxs(Jt,{onClick:()=>P(K.id),className:"[&>svg]:mr-1",children:[s.jsx(Pb,{className:"mr-1 h-4 w-4"}),"Unshare"]})]}):s.jsxs(Jt,{onClick:()=>B(K),className:"[&>svg]:mr-1",children:[s.jsx(Tb,{className:"mr-1 h-4 w-4"}),"Share"]}),e[181]=E,e[182]=I,e[183]=B,e[184]=P,e[185]=K,e[186]=se):se=e[186],qe=je&&!q?(()=>{const Ve=_(je),ft=z(je,K.id);return s.jsxs(s.Fragment,{children:[s.jsx(Zn,{}),s.jsxs(Ev,{children:[s.jsxs(Dv,{className:"[&>svg]:mr-1",children:[s.jsx(jr,{className:"h-4 w-4"}),"Move to folder"]}),s.jsxs(Iv,{className:"min-w-[180px]",children:[Ve.length===0?s.jsx(Jt,{disabled:!0,className:"text-muted-foreground",children:"No folders yet"}):Ve.map(Bt=>s.jsxs(Jt,{onClick:()=>{ft===Bt.id?R(je,K.id):W(je,Bt.id,K.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:Bt.name}),ft===Bt.id?s.jsx(js,{className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},Bt.id)),s.jsx(Zn,{}),s.jsxs(Jt,{onClick:()=>{const Bt=G(je);Bt&&W(je,Bt.id,K.id)},children:[s.jsx(Qs,{className:"mr-1 h-4 w-4"}),"New folder..."]}),ft?s.jsxs(Jt,{onClick:()=>{R(je,K.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(Ps,{className:"mr-1 h-4 w-4"}),"Remove from folder"]}):null]})]})]})})():null}e[1]=W,e[2]=q,e[3]=E,e[4]=G,e[5]=u,e[6]=$,e[7]=i,e[8]=C,e[9]=y,e[10]=f,e[11]=_,e[12]=z,e[13]=o,e[14]=k,e[15]=I,e[16]=S,e[17]=F,e[18]=B,e[19]=P,e[20]=ve,e[21]=ce,e[22]=h,e[23]=xe,e[24]=re,e[25]=n.children.length,e[26]=x,e[27]=D,e[28]=v,e[29]=m,e[30]=a,e[31]=R,e[32]=T,e[33]=U?.branchLabel,e[34]=U?.projectLabel,e[35]=K,e[36]=g,e[37]=c,e[38]=b,e[39]=N,e[40]=w,e[41]=L,e[42]=j,e[43]=M,e[44]=le,e[45]=ae,e[46]=ue,e[47]=be,e[48]=oe,e[49]=Z,e[50]=ie,e[51]=pe,e[52]=me,e[53]=Se,e[54]=ke,e[55]=ye,e[56]=Ne,e[57]=_e,e[58]=de,e[59]=we,e[60]=je,e[61]=Ce,e[62]=ze,e[63]=Ge,e[64]=Le,e[65]=qe,e[66]=rt,e[67]=st,e[68]=it,e[69]=lt,e[70]=He,e[71]=Oe,e[72]=se}else le=e[44],ae=e[45],ue=e[46],be=e[47],oe=e[48],Z=e[49],ie=e[50],pe=e[51],me=e[52],Se=e[53],ke=e[54],ye=e[55],Ne=e[56],_e=e[57],de=e[58],we=e[59],je=e[60],Ce=e[61],ze=e[62],Ge=e[63],Le=e[64],qe=e[65],rt=e[66],st=e[67],it=e[68],lt=e[69],He=e[70],Oe=e[71],se=e[72];if(rt!==Symbol.for("react.early_return_sentinel"))return rt;let Pe;e[187]!==Y||e[188]!==K.id||e[189]!==je||e[190]!==Ce?(Pe=O?null:s.jsxs(Jt,{disabled:!je,onClick:()=>{je&&Y(je,{mode:"chat",dedupeKey:`session:${K.id}`,label:Ce})},className:"[&>svg]:mr-1",children:[s.jsx(I2,{className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:"Open in Side Panel"}),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:"beta"})]}),e[187]=Y,e[188]=K.id,e[189]=je,e[190]=Ce,e[191]=Pe):Pe=e[191];let Ye;e[192]===Symbol.for("react.memo_cache_sentinel")?(Ye=s.jsx(Zn,{}),e[192]=Ye):Ye=e[192];let We;e[193]!==q||e[194]!==J||e[195]!==K?(We=()=>J(K,{archivedBucket:q}),e[193]=q,e[194]=J,e[195]=K,e[196]=We):We=e[196];let xt;e[197]===Symbol.for("react.memo_cache_sentinel")?(xt=s.jsx(Pn,{className:"mr-1 h-4 w-4"}),e[197]=xt):xt=e[197];const et=q?"Delete":"Archive";let tt;e[198]!==We||e[199]!==et?(tt=s.jsxs(Jt,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:We,children:[xt,et]}),e[198]=We,e[199]=et,e[200]=tt):tt=e[200];let ht;e[201]!==le||e[202]!==qe||e[203]!==Pe||e[204]!==tt||e[205]!==st||e[206]!==it||e[207]!==lt||e[208]!==He||e[209]!==Oe||e[210]!==se?(ht=s.jsxs(le,{align:st,className:it,onCloseAutoFocus:lt,children:[He,Oe,se,qe,Pe,Ye,tt]}),e[201]=le,e[202]=qe,e[203]=Pe,e[204]=tt,e[205]=st,e[206]=it,e[207]=lt,e[208]=He,e[209]=Oe,e[210]=se,e[211]=ht):ht=e[211];const St=ht,Ue=K.id,ct=K.id,Qe=je??null,at=ke?"opacity-75":"",Nt=$>0&&"pl-[20px]";let jt;e[212]!==at||e[213]!==Nt?(jt=Q("group relative flex items-center rounded-sm px-1.5 py-1",at,Nt),e[212]=at,e[213]=Nt,e[214]=jt):jt=e[214];let qt;e[215]!==ae||e[216]!==ue||e[217]!==be||e[218]!==oe||e[219]!==A||e[220]!==ve||e[221]!==ce||e[222]!==ie||e[223]!==pe||e[224]!==Se||e[225]!==xe||e[226]!==ke||e[227]!==ye||e[228]!==V||e[229]!==p||e[230]!==_e||e[231]!==U||e[232]!==de||e[233]!==we||e[234]!==St||e[235]!==Ce||e[236]!==ze?(qt=s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:xe?s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",disabled:ke,onMouseDown:be,onClick:oe,onDoubleClick:us=>{us.stopPropagation(),A()},className:Q("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",V?"pr-7":""),children:s.jsxs("div",{className:Q("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[ye?s.jsx(z0,{className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":"Pinned session"}):null,s.jsx("div",{className:Q("block min-w-0 flex-1 truncate typography-ui-label font-normal",pe?"text-primary":"text-foreground"),children:p1(Ce,p)}),V?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:de}):null,V?null:s.jsxs("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:[s.jsx("span",{className:Q("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",Se?"opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0"),children:de}),s.jsxs(qs,{open:Se,onOpenChange:ae,children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:Q("absolute inset-y-0 right-0 inline-flex h-4 w-4 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",Se?"opacity-100 pointer-events-auto":"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":"Session menu",onClick:ue,onKeyDown:vZ,children:s.jsx(Qr,{className:"h-2.5 w-2.5"})})}),St]})]}),_e>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:"Permission required","aria-label":"Permission required",children:[s.jsx(D3,{className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:_e})]}):null]})})}),s.jsx(_t,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:Q("flex items-center gap-3 text-left text-muted-foreground",U?.projectLabel?"justify-between":"justify-start"),children:[U?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:U.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:ze})]}),U?.branchLabel||we?s.jsxs("div",{className:Q("flex items-center gap-3 text-left text-muted-foreground",U?.branchLabel?"justify-between":"justify-start"),children:[U?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(on,{className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:U.branchLabel})]})}):null,we?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",we.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",we.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:ke,onMouseDown:be,onClick:oe,onDoubleClick:us=>{us.stopPropagation(),A()},className:Q("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",V?"pr-7":"group-hover:pr-5 group-focus-within:pr-5"),children:[s.jsxs("div",{className:Q("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[ie,ye?s.jsx(z0,{className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":"Pinned session"}):null,s.jsx("div",{className:Q("block min-w-0 flex-1 truncate typography-ui-label font-normal",pe?"text-primary":"text-foreground"),children:p1(Ce,p)}),_e>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:"Permission required","aria-label":"Permission required",children:[s.jsx(D3,{className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:_e})]}):null]}),xe?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[s.jsx("span",{className:"flex-shrink-0",children:ze}),we?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",we.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",we.deletions]})]}):null,ce?s.jsx("span",{className:"truncate",children:U?.projectLabel}):null,ve?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(on,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:U?.branchLabel})]}):null]})})]})}),e[215]=ae,e[216]=ue,e[217]=be,e[218]=oe,e[219]=A,e[220]=ve,e[221]=ce,e[222]=ie,e[223]=pe,e[224]=Se,e[225]=xe,e[226]=ke,e[227]=ye,e[228]=V,e[229]=p,e[230]=_e,e[231]=U,e[232]=de,e[233]=we,e[234]=St,e[235]=Ce,e[236]=ze,e[237]=qt):qt=e[237];let Zt;e[238]!==xe||e[239]!==V||e[240]!==Ge?(Zt=Ge&&!V?s.jsx("div",{className:Q("absolute top-1/2 -translate-y-1/2 z-10",xe?"right-0":"right-[30px]"),children:Ge}):null,e[238]=xe,e[239]=V,e[240]=Ge,e[241]=Zt):Zt=e[241];let Pt;e[242]!==ae||e[243]!==ue||e[244]!==Se||e[245]!==xe||e[246]!==V||e[247]!==St?(Pt=!xe||V?s.jsx("div",{className:Q("absolute right-0 top-1/2 z-10 -translate-y-1/2",Q("transition-opacity",Se||V?"opacity-100 pointer-events-auto":"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")),children:s.jsxs(qs,{open:Se,onOpenChange:ae,children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:Q("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",xe&&!V?Se?"h-4 w-4 opacity-100 pointer-events-auto":"h-4 w-4 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":"h-6 w-6 opacity-100"),"aria-label":"Session menu",onClick:ue,onKeyDown:bZ,children:s.jsx(Qr,{className:Q(xe&&!V?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),St]})}):null,e[242]=ae,e[243]=ue,e[244]=Se,e[245]=xe,e[246]=V,e[247]=St,e[248]=Pt):Pt=e[248];let cs;e[249]!==Ne||e[250]!==Le||e[251]!==jt||e[252]!==qt||e[253]!==Zt||e[254]!==Pt?(cs=s.jsxs("div",{className:jt,children:[Ne,Le,qt,Zt,Pt]}),e[249]=Ne,e[250]=Le,e[251]=jt,e[252]=qt,e[253]=Zt,e[254]=Pt,e[255]=cs):cs=e[255];let ss;e[256]!==K.id||e[257]!==Ce||e[258]!==Qe||e[259]!==cs?(ss=s.jsx(RG,{sessionId:ct,sessionDirectory:Qe,sessionTitle:Ce,children:cs}),e[256]=K.id,e[257]=Ce,e[258]=Qe,e[259]=cs,e[260]=ss):ss=e[260];let Wt;e[261]!==q||e[262]!==$||e[263]!==o||e[264]!==Z||e[265]!==me||e[266]!==n.children||e[267]!==a||e[268]!==ee||e[269]!==te||e[270]!==je?(Wt=Z&&me?n.children.map(us=>te(us,$+1,je??o,a,q,void 0,ee)):null,e[261]=q,e[262]=$,e[263]=o,e[264]=Z,e[265]=me,e[266]=n.children,e[267]=a,e[268]=ee,e[269]=te,e[270]=je,e[271]=Wt):Wt=e[271];let ls;return e[272]!==K.id||e[273]!==ss||e[274]!==Wt?(ls=s.jsxs(d.Fragment,{children:[ss,Wt]},Ue),e[272]=K.id,e[273]=ss,e[274]=Wt,e[275]=ls):ls=e[275],ls}function bZ(t){return t.stopPropagation()}function vZ(t){return t.stopPropagation()}function yZ(t){t.stopPropagation()}function wZ(t,e){return pZ.has(e)?s.jsx("span",{className:"h-[3px] w-[3px] rounded-full bg-current animate-attention-diamond-pulse",style:{animationDelay:gZ(e)}},e):s.jsx("span",{className:"h-[3px] w-[3px]"},e)}function jZ(t){return t.displayMode}function kZ(t){const e=Fe.c(38),{value:n,setValue:r,showDeletionDialog:o,setShowDeletionDialog:a,onConfirm:l}=t,i=!!n;let c;e[0]!==r?(c=A=>{A||r(null)},e[0]=r,e[1]=c):c=e[1];const u=n?.archivedBucket?"Delete session?":"Archive session?";let m;e[2]!==u?(m=s.jsx(Us,{children:u}),e[2]=u,e[3]=m):m=e[3];const f=n&&n.descendantCount>0?n.archivedBucket?`"${n.session.title||"Untitled Session"}" and its ${n.descendantCount} sub-task${n.descendantCount===1?"":"s"} will be permanently deleted.`:`"${n.session.title||"Untitled Session"}" and its ${n.descendantCount} sub-task${n.descendantCount===1?"":"s"} will be archived.`:n?.archivedBucket?`"${n?.session.title||"Untitled Session"}" will be permanently deleted.`:`"${n?.session.title||"Untitled Session"}" will be archived.`;let h;e[4]!==f?(h=s.jsx(sn,{children:f}),e[4]=f,e[5]=h):h=e[5];let p;e[6]!==m||e[7]!==h?(p=s.jsxs(Zs,{children:[m,h]}),e[6]=m,e[7]=h,e[8]=p):p=e[8];let g;e[9]!==a||e[10]!==o?(g=()=>a(!o),e[9]=a,e[10]=o,e[11]=g):g=e[11];const x=!o;let b;e[12]!==o?(b=o?s.jsx(ea,{className:"h-4 w-4"}):s.jsx(Jo,{className:"h-4 w-4 text-primary"}),e[12]=o,e[13]=b):b=e[13];let v;e[14]!==g||e[15]!==x||e[16]!==b?(v=s.jsxs("button",{type:"button",onClick:g,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":x,children:[b,"Never ask"]}),e[14]=g,e[15]=x,e[16]=b,e[17]=v):v=e[17];let y;e[18]!==r?(y=s.jsx("button",{type:"button",onClick:()=>r(null),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:"Cancel"}),e[18]=r,e[19]=y):y=e[19];let w;e[20]!==l?(w=()=>{l()},e[20]=l,e[21]=w):w=e[21];const C=n?.archivedBucket?"Delete":"Archive";let N;e[22]!==w||e[23]!==C?(N=s.jsx("button",{type:"button",onClick:w,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:C}),e[22]=w,e[23]=C,e[24]=N):N=e[24];let S;e[25]!==y||e[26]!==N?(S=s.jsxs("div",{className:"flex items-center gap-2",children:[y,N]}),e[25]=y,e[26]=N,e[27]=S):S=e[27];let k;e[28]!==v||e[29]!==S?(k=s.jsxs(yn,{className:"w-full sm:items-center sm:justify-between",children:[v,S]}),e[28]=v,e[29]=S,e[30]=k):k=e[30];let j;e[31]!==k||e[32]!==p?(j=s.jsxs(Vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,k]}),e[31]=k,e[32]=p,e[33]=j):j=e[33];let F;return e[34]!==i||e[35]!==c||e[36]!==j?(F=s.jsx(Os,{open:i,onOpenChange:c,children:j}),e[34]=i,e[35]=c,e[36]=j,e[37]=F):F=e[37],F}function NZ(t){const e=Fe.c(19),{value:n,setValue:r,onConfirm:o}=t,a=!!n;let l;e[0]!==r?(l=x=>{x||r(null)},e[0]=r,e[1]=l):l=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Us,{children:"Delete folder?"}),e[2]=i):i=e[2];const c=n&&(n.subFolderCount>0||n.sessionCount>0)?`"${n.folderName}" will be deleted${n.subFolderCount>0?` along with ${n.subFolderCount} sub-folder${n.subFolderCount===1?"":"s"}`:""}. Sessions inside will not be deleted.`:`"${n?.folderName}" will be permanently deleted.`;let u;e[3]!==c?(u=s.jsxs(Zs,{children:[i,s.jsx(sn,{children:c})]}),e[3]=c,e[4]=u):u=e[4];let m;e[5]!==r?(m=s.jsx("button",{type:"button",onClick:()=>r(null),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:"Cancel"}),e[5]=r,e[6]=m):m=e[6];let f;e[7]!==o?(f=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:"Delete"}),e[7]=o,e[8]=f):f=e[8];let h;e[9]!==m||e[10]!==f?(h=s.jsxs(yn,{children:[m,f]}),e[9]=m,e[10]=f,e[11]=h):h=e[11];let p;e[12]!==u||e[13]!==h?(p=s.jsxs(Vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[u,h]}),e[12]=u,e[13]=h,e[14]=p):p=e[14];let g;return e[15]!==a||e[16]!==l||e[17]!==p?(g=s.jsx(Os,{open:a,onOpenChange:l,children:p}),e[15]=a,e[16]=l,e[17]=p,e[18]=g):g=e[18],g}const Q7="oc.sessions.activeNow",SZ=2160*60*1e3,CZ=t=>!!t.parentID,J7=t=>!!t.time?.archived,pu=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},AZ=t=>{try{const e=t.getItem(Q7);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,o=[];return n.forEach(a=>{const l=typeof a=="string"?a:a&&typeof a=="object"&&"sessionId"in a&&typeof a.sessionId=="string"?a.sessionId:null;!l||r.has(l)||(r.add(l),o.push({sessionId:l}))}),o}catch{return[]}},gd=(t,e)=>{try{t.setItem(Q7,JSON.stringify(e))}catch{}},MZ=(t,e,n=Date.now())=>{const r=n-SZ;return t.filter(o=>{const a=e.get(o.sessionId);return a?J7(a)?!1:pu(a)>=r:!0})},nh=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],FZ=t=>[...t].sort((e,n)=>pu(n)-pu(e)),BZ=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!J7(r)).filter(r=>!CZ(r));return FZ(n)},M0="oc.sessions.projectCollapse",rh="oc.sessions.groupOrder",oh="oc.sessions.groupCollapse",ah="oc.sessions.activeSessionByProject",lh="oc.sessions.expandedParents",ih="oc.sessions.pinned",_Z=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"},ch=t=>{switch(t){case"open":return 5;case"blocked":return 4;case"draft":return 3;case"merged":return 2;case"closed":return 1;default:return 0}},_2=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:o=!1})=>{const[a,l]=d.useState(!1),[i,c]=d.useState(""),u=d.useRef(null),m=d.useRef(null),[f,h]=d.useState(null),[p,g]=d.useState(""),[x,b]=d.useState(null),[v,y]=d.useState(new Set),[w,C]=d.useState(()=>new Map),N=d.useMemo(()=>Ko(),[]),[S,k]=d.useState(()=>AZ(N)),[j,F]=d.useState(new Set),[A,M]=d.useState(new Map),[B,E]=d.useState(new Set),[I,P]=d.useState(null),[D,L]=d.useState(!1),[T,_]=d.useState(!1),[z,R]=d.useState(!1),[W,G]=d.useState(null),[Y,J]=d.useState(null),[V,te]=d.useState(""),[U,X]=d.useState(null),[$,q]=d.useState(null),[ee,ce]=d.useState(()=>{try{const De=Ko().getItem(ih);if(!De)return new Set;const wt=JSON.parse(De);return new Set(Array.isArray(wt)?wt.filter(Ht=>typeof Ht=="string"):[])}catch{return new Set}}),[ve,ge]=d.useState(()=>{try{const De=Ko().getItem(oh);if(!De)return new Set;const wt=JSON.parse(De);return new Set(Array.isArray(wt)?wt.filter(Ht=>typeof Ht=="string"):[])}catch{return new Set}}),[xe,ne]=d.useState(()=>{try{const De=Ko().getItem(rh);if(!De)return new Map;const wt=JSON.parse(De),Ht=new Map;return Object.entries(wt).forEach(([Ts,gn])=>{Array.isArray(gn)&&Ht.set(Ts,gn.filter($s=>typeof $s=="string"))}),Ht}catch{return new Map}}),[O,H]=d.useState(()=>{try{const De=Ko().getItem(ah);if(!De)return new Map;const wt=JSON.parse(De),Ht=new Map;return Object.entries(wt).forEach(([Ts,gn])=>{typeof gn=="string"&&gn.length>0&&Ht.set(Ts,gn)}),Ht}catch{return new Map}}),[K,re]=d.useState(new Map),le=d.useRef(new Map),ae=d.useRef(0),ue=dn(De=>De.homeDirectory),be=dn(De=>De.currentDirectory),oe=dn(De=>De.setDirectory),Z=vs(De=>De.projects),ie=vs(De=>De.activeProjectId),pe=vs(De=>De.addProject),me=vs(De=>De.removeProject),Se=vs(De=>De.setActiveProjectIdOnly),ke=vs(De=>De.updateProjectMeta),ye=vs(De=>De.reorderProjects),Ne=Ee(De=>De.setActiveMainTab),_e=Ee(De=>De.openContextPanelTab),de=Ee(De=>De.setSettingsDialogOpen),we=Ee(De=>De.toggleHelpDialog),je=Ee(De=>De.setAboutDialogOpen),Ce=wn(),ze=Ee(De=>De.setSessionSwitcherOpen),Ge=Ee(De=>De.toggleSidebar),Le=Ee(De=>De.openMultiRunLauncher),qe=Ee(De=>De.notifyOnSubtasks),rt=Ee(De=>De.showDeletionDialog),st=Ee(De=>De.setShowDeletionDialog),it=Z1(i,120),lt=d.useMemo(()=>it.trim().toLowerCase(),[it]),He=lt.length>0,Oe=uo(De=>De.collapsedFolderIds),se=uo(De=>De.foldersMap),Pe=uo(De=>De.getFoldersForScope),Ye=uo(De=>De.createFolder),We=uo(De=>De.renameFolder),xt=uo(De=>De.deleteFolder),et=uo(De=>De.addSessionToFolder),tt=uo(De=>De.removeSessionFromFolder),ht=uo(De=>De.toggleFolderCollapse),St=uo(De=>De.cleanupSessions),Ue=uo(De=>De.getSessionFolderId);Yq({isSessionSearchOpen:a,setIsSessionSearchOpen:l,sessionSearchInputRef:m,sessionSearchContainerRef:u});const ct=Wn(De=>De.directories),Qe=Ze(De=>De.sessions),at=Ze(De=>De.archivedSessions),Nt=Ze(De=>De.sessionsByDirectory),jt=Ze(De=>De.currentSessionId),qt=Ze(De=>!!De.newSessionDraft?.open),Zt=Ze(De=>De.setCurrentSession),Pt=Ze(De=>De.loadMessages),cs=Ze(De=>De.updateSessionTitle),ss=Ze(De=>De.shareSession),Wt=Ze(De=>De.unshareSession),ls=Ze(De=>De.sessionMemoryState),us=Ze(De=>De.sessionStatus),ys=Ze(De=>De.sessionAttentionStates),ws=Ze(De=>De.permissions),Is=Ze(De=>De.worktreeMetadata),bs=Ze(De=>De.availableWorktreesByProject),Ss=Ze(De=>De.getSessionsByDirectory),Cs=Ze(De=>De.openNewSessionDraft),ut=mo(De=>De.entries),Mt=Sl(),Kt=d.useMemo(()=>Rn(),[]),[Ft,Et]=d.useState(!1),bt=d.useMemo(()=>xn(),[]),kt=d.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),as=!t&&!bt,Gt=Kt&&kt&&!Ft?"pl-[5.5rem]":"pl-3",Ae="app-region-no-drag inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";d.useEffect(()=>{if(!Kt||!kt){Et(!1);return}let De=!1,wt=null;const Ht=async()=>{try{const{getCurrentWindow:gn}=await Kn(async()=>{const{getCurrentWindow:Tr}=await import("./vendor-.bun-HTKwyaEM.js").then(Fr=>Fr.fG);return{getCurrentWindow:Tr}},__vite__mapDeps([0,1])),gr=await gn().isFullscreen();De||Et(gr)}catch{De||Et(!1)}},Ts=async()=>{try{const{getCurrentWindow:gn}=await Kn(async()=>{const{getCurrentWindow:gr}=await import("./vendor-.bun-HTKwyaEM.js").then(Tr=>Tr.fG);return{getCurrentWindow:gr}},__vite__mapDeps([0,1]));wt=await gn().onResized(()=>{Ht()})}catch{}};return Ht(),Ts(),()=>{De=!0,wt&&wt()}},[Kt,kt]);const Xe=d.useCallback(async De=>{const wt=De.target;if(!wt.closest(".app-region-no-drag")&&!wt.closest("button, a, input, select, textarea")&&De.button===0&&Kt)try{const{getCurrentWindow:Ht}=await Kn(async()=>{const{getCurrentWindow:gn}=await import("./vendor-.bun-HTKwyaEM.js").then($s=>$s.fG);return{getCurrentWindow:gn}},__vite__mapDeps([0,1]));await Ht().startDragging()}catch(Ht){console.error("Failed to start window dragging:",Ht)}},[Kt]),{buildGroupSearchText:yt,filterSessionNodesForSearch:Tt,buildGroupedSessions:Yt}=Kq({homeDirectory:ue,worktreeMetadata:Is,pinnedSessionIds:ee,gitDirectories:ct,isVSCode:bt}),{scheduleCollapsedProjectsPersist:Ut}=aG({isVSCode:bt,safeStorage:N,keys:{sessionExpanded:lh,projectCollapse:M0,sessionPinned:ih,groupOrder:rh,projectActiveSession:ah,groupCollapse:oh},sessions:Qe,pinnedSessionIds:ee,setPinnedSessionIds:ce,groupOrderByProject:xe,activeSessionByProject:O,collapsedGroups:ve,setExpandedParents:y,setCollapsedProjects:F}),Es=d.useCallback(De=>{ce(wt=>{const Ht=new Set(wt);return Ht.has(De)?Ht.delete(De):Ht.add(De),Ht})},[]),Fs=d.useMemo(()=>[...Qe].sort((De,wt)=>T1(De,wt,ee)),[Qe,ee]),ds=d.useMemo(()=>{const De=new Map;return[...Qe,...at].forEach(wt=>{De.set(wt.id,wt)}),De},[Qe,at]);d.useEffect(()=>{const De=MZ(S,ds);De.length===S.length&&De.every((wt,Ht)=>wt.sessionId===S[Ht]?.sessionId)||(k(De),gd(N,De))},[S,ds,N]);const es=d.useRef(new Set);d.useEffect(()=>{const De=new Set;us?.forEach((Ts,gn)=>{(Ts?.type==="busy"||Ts?.type==="retry")&&De.add(gn)});const wt=es.current,Ht=Array.from(De).filter(Ts=>!wt.has(Ts));Ht.length>0&&k(Ts=>{const gn=Ht.reduce(($s,gr)=>nh($s,gr),Ts);return gn===Ts?Ts:(gd(N,gn),gn)}),es.current=De},[us,N]),d.useEffect(()=>{const De=[];us?.forEach((wt,Ht)=>{(wt?.type==="busy"||wt?.type==="retry")&&De.push(Ht)}),De.length!==0&&k(wt=>{const Ht=new Set(wt.map($s=>$s.sessionId));let Ts=wt,gn=!1;return De.forEach($s=>{if(Ht.has($s))return;const gr=ds.get($s);!gr||gr.time?.archived||gr.parentID||(Ts=nh(Ts,$s),Ht.add($s),gn=!0)}),gn?(gd(N,Ts),Ts):wt})},[us,ds,N]);const gs=d.useMemo(()=>{const De=new Map;return Fs.forEach(wt=>{const Ht=wt.parentID;if(!Ht)return;const Ts=De.get(Ht)??[];Ts.push(wt),De.set(Ht,Ts)}),De.forEach(wt=>wt.sort((Ht,Ts)=>T1(Ht,Ts,ee))),De},[Fs,ee]);tG({sortedSessions:Fs,projects:Z,directoryStatus:w,setDirectoryStatus:C});const Ks=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:"No sessions yet"}),s.jsx("p",{className:"typography-meta mt-1",children:"Create your first session to start coding."})]}),Rs=d.useMemo(()=>Z.find(De=>De.id===x)??null,[Z,x]),un=d.useCallback(De=>{x&&(ke(x,De),b(null))},[x,ke]),zn=d.useCallback(()=>{L(!0)},[]),Te=d.useCallback(()=>{const De=Sl.getState();if(De.available&&De.info){_(!0);return}Mt.checkForUpdates().then(()=>{const{available:wt,error:Ht}=Sl.getState();if(Ht){fe.error("Failed to check for updates",{description:Ht});return}if(!wt){fe.success("You are on the latest version");return}_(!0)})},[Mt]),Ie=Mt.available&&(Mt.runtimeType==="desktop"||Mt.runtimeType==="web"),Ke=Ze(De=>De.deleteSession),Ve=Ze(De=>De.deleteSessions),ft=Ze(De=>De.archiveSession),Bt=Ze(De=>De.archiveSessions),{copiedSessionId:At,handleSessionSelect:mt,handleSessionDoubleClick:Lt,handleSaveEdit:$t,handleCancelEdit:Xs,handleShareSession:As,handleCopyShareUrl:Ot,handleUnshareSession:fs,handleDeleteSession:ms,confirmDeleteSession:Hs}=nG({activeProjectId:ie,currentDirectory:be,currentSessionId:jt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:a,sessionSearchQuery:i,setSessionSearchQuery:c,setIsSessionSearchOpen:l,setActiveProjectIdOnly:Se,setDirectory:oe,setActiveMainTab:Ne,setSessionSwitcherOpen:ze,setCurrentSession:Zt,updateSessionTitle:cs,shareSession:ss,unshareSession:Wt,deleteSession:Ke,deleteSessions:Ve,archiveSession:ft,archiveSessions:Bt,childrenMap:gs,showDeletionDialog:rt,setDeleteSessionConfirm:X,deleteSessionConfirm:U,setEditingId:h,setEditTitle:g,editingId:f,editTitle:p}),rn=d.useCallback(()=>{if(!$)return;const{scopeKey:De,folderId:wt}=$;q(null),xt(De,wt)},[$,xt]),zs=d.useCallback(()=>{if(!Kt||!$o()){na.requestDirectoryDialog();return}Kn(async()=>{const{requestDirectoryAccess:De}=await import("./index-Bdws7PjD.js").then(wt=>wt.b5);return{requestDirectoryAccess:De}},__vite__mapDeps([3,0,1,4])).then(({requestDirectoryAccess:De})=>De("")).then(De=>{De.success&&De.path?pe(De.path,{id:De.projectId})||fe.error("Failed to add project",{description:"Please select a valid directory."}):De.error&&De.error!=="Directory selection cancelled"&&fe.error("Failed to select directory",{description:De.error})}).catch(De=>{console.error("Desktop: Error selecting directory:",De),fe.error("Failed to select directory")})},[pe,Kt]),Vn=d.useCallback(De=>{y(wt=>{const Ht=new Set(wt);Ht.has(De)?Ht.delete(De):Ht.add(De);try{N.setItem(lh,JSON.stringify(Array.from(Ht)))}catch{}return Ht})},[N]),Ln=d.useCallback((De,wt)=>{if(!De)return null;wt&&Oe.has(wt)&&ht(wt);const Ht=Ye(De,"New folder",wt);return J(Ht.id),te(Ht.name),Ht},[Oe,ht,Ye]),Jn=d.useCallback(De=>{E(wt=>{const Ht=new Set(wt);return Ht.has(De)?Ht.delete(De):Ht.add(De),Ht})},[]),br=d.useCallback(()=>{ae.current=Date.now()+150,F(()=>{const De=new Set(Z.map(wt=>wt.id));try{N.setItem(M0,JSON.stringify(Array.from(De)))}catch{}return bt||Ut(De),De})},[Z,bt,N,Ut]),Ar=d.useCallback(()=>{ae.current=Date.now()+150,F(()=>{const De=new Set;try{N.setItem(M0,JSON.stringify([]))}catch{}return bt||Ut(De),De})},[bt,N,Ut]),Vr=d.useCallback(De=>{ae.current=Date.now()+150,F(wt=>{const Ht=new Set(wt);Ht.has(De)?Ht.delete(De):Ht.add(De);try{N.setItem(M0,JSON.stringify(Array.from(Ht)))}catch{}return bt||Ut(Ht),Ht})},[bt,N,Ut]),hn=d.useMemo(()=>Z.map(De=>({...De,normalizedPath:nn(De.path)})).filter(De=>!!De.normalizedPath),[Z]);uG({projects:Z,normalizedProjects:hn,normalizePath:nn,gitDirectories:ct,setProjectRepoStatus:M,setProjectRootBranches:re});const kn=Ze(De=>De.isLoading);yG({isSessionsLoading:kn,sessions:Qe,archivedSessions:at,normalizedProjects:hn,isVSCode:bt,availableWorktreesByProject:bs,cleanupSessions:St});const{getSessionsForProject:rr,getArchivedSessionsForProject:or}=pG({isVSCode:bt,sessions:Qe,archivedSessions:at,sessionsByDirectory:Nt,getSessionsByDirectory:Ss,availableWorktreesByProject:bs});$q({normalizedProjects:hn,sessions:Qe,archivedSessions:at,availableWorktreesByProject:bs,isVSCode:bt,isSessionsLoading:kn,foldersMap:se,createFolder:Ye,addSessionToFolder:et,cleanupSessions:St});const fr=d.useRef(!1);ie&&A.has(ie)&&(fr.current=!!A.get(ie));const{projectSections:bn,groupSearchDataByGroup:jn,sectionsForRender:pr,searchMatchCount:Ur}=Uq({normalizedProjects:hn,getSessionsForProject:rr,getArchivedSessionsForProject:or,availableWorktreesByProject:bs,projectRepoStatus:A,projectRootBranches:K,lastRepoStatus:fr.current,buildGroupedSessions:Yt,hasSessionSearchQuery:He,normalizedSessionSearchQuery:lt,filterSessionNodesForSearch:Tt,buildGroupSearchText:yt,getFoldersForScope:Pe}),Xn=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:"No matching sessions"}),s.jsx("p",{className:"typography-meta mt-1",children:"Try a different title, branch, folder, or path."})]}),an=d.useMemo(()=>hn.find(De=>De.id===ie)??hn[0]??null,[hn,ie]),Mr=d.useMemo(()=>an?{id:an.id,path:an.normalizedPath}:null,[an]),Ms=d.useMemo(()=>an?an.label?.trim()||Or(an.normalizedPath,ue)||an.normalizedPath:null,[an,ue]),ar=d.useMemo(()=>an?!!A.get(an.id):!1,[an,A]),Ir=an&&A.has(an.id)?ar:fr.current,Vo=!0,Uo=t||Ce.isMobile;d.useEffect(()=>{an||R(!1)},[an]);const{currentSessionDirectory:$e}=qq({projectSections:bn,activeProjectId:ie,activeSessionByProject:O,setActiveSessionByProject:H,currentSessionId:jt,handleSessionSelect:mt,newSessionDraftOpen:qt,mobileVariant:t,openNewSessionDraft:Cs,setActiveMainTab:Ne,setSessionSwitcherOpen:ze,sessions:Qe,worktreeMetadata:Is}),{getOrderedGroups:Je}=Gq(xe),ot=d.useRef(!1);d.useEffect(()=>{if(ot.current||bn.length===0)return;const De=bn.flatMap(wt=>wt.groups.filter(Ht=>Ht.isArchivedBucket).map(Ht=>`${wt.project.id}:${Ht.id}`));De.length>0&&ge(wt=>new Set([...wt,...De])),ot.current=!0},[bn]);const gt=d.useMemo(()=>{const De=new Map;return bn.forEach(wt=>{const Ht=u8(wt.project.label?.trim()||Or(wt.project.normalizedPath,ue)||wt.project.normalizedPath);wt.groups.forEach(Ts=>{const gn=Ts.branch&&Ts.branch!==Ht?{projectLabel:Ht,branchLabel:Ts.branch}:{projectLabel:Ht,branchLabel:null},$s=gr=>{gr.forEach(Tr=>{De.set(Tr.session.id,{node:Tr,projectId:wt.project.id,groupDirectory:Ts.directory,secondaryMeta:gn}),Tr.children.length>0&&$s(Tr.children)})};$s(Ts.sessions)})}),De},[bn,ue]),hs=d.useMemo(()=>BZ(S,new Map(Qe.map(De=>[De.id,De]))),[S,Qe]);eG({currentSessionId:jt,sortedSessions:Fs,recentSessionIds:hs.map(De=>De.id),loadMessages:Pt});const xs=d.useMemo(()=>{const De=wt=>{const Ht=gt.get(wt.id),Ts=nn(wt.directory??null);return{node:Ht?.node??{session:wt,children:[],worktree:null},projectId:Ht?.projectId??null,groupDirectory:Ht?.groupDirectory??Ts,secondaryMeta:Ht?.secondaryMeta??null}};return[{key:"active-now",title:"recent",items:hs.map(De)}]},[hs,gt]),la=t?"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",Ol="h-4.5 w-4.5",el=NG({isDesktopShellRuntime:Kt,projectSections:bn,projectHeaderSentinelRefs:le}),ia=d.useCallback((De,wt=0,Ht,Ts,gn=!1,$s,gr="project")=>s.jsx(xZ,{node:De,depth:wt,groupDirectory:Ht,projectId:Ts,archivedBucket:gn,directoryStatus:w,sessionMemoryState:ls,currentSessionId:jt,pinnedSessionIds:ee,expandedParents:v,hasSessionSearchQuery:He,normalizedSessionSearchQuery:lt,sessionAttentionStates:ys,notifyOnSubtasks:qe,sessionStatus:us,permissions:ws,editingId:f,setEditingId:h,editTitle:p,setEditTitle:g,handleSaveEdit:$t,handleCancelEdit:Xs,toggleParent:Vn,handleSessionSelect:mt,handleSessionDoubleClick:Lt,togglePinnedSession:Es,handleShareSession:As,copiedSessionId:At,handleCopyShareUrl:Ot,handleUnshareSession:fs,openSidebarMenuKey:W,setOpenSidebarMenuKey:G,renamingFolderId:Y,getFoldersForScope:Pe,getSessionFolderId:Ue,removeSessionFromFolder:tt,addSessionToFolder:et,createFolderAndStartRename:Ln,openContextPanelTab:_e,handleDeleteSession:ms,mobileVariant:t,renderSessionNode:ia,secondaryMeta:$s,renderContext:gr}),[w,ls,jt,ee,v,He,lt,ys,qe,us,ws,f,h,p,g,$t,Xs,Vn,mt,Lt,Es,As,At,Ot,fs,W,G,Y,Pe,Ue,tt,et,Ln,_e,ms,t]),tl=d.useCallback(De=>{ge(wt=>{const Ht=new Set(wt);return Ht.has(De)?Ht.delete(De):Ht.add(De),Ht})},[]),Vl=d.useMemo(()=>{const De=new Map;return Object.values(ut).forEach(wt=>{const Ht=nn(wt.params?.directory??wt.identity?.directory??null),Ts=wt.params?.branch?.trim()??wt.identity?.branch?.trim();if(!Ht||!Ts)return;const gn=_Z(wt.status??null),$s=wt.status?.pr;if(!gn||!$s?.number)return;const gr=`${Ht}::${Ts}`,Tr={visualState:gn,number:$s.number,url:typeof $s.url=="string"&&$s.url.trim().length>0?$s.url:null,state:$s.state,draft:!!$s.draft,title:typeof $s.title=="string"&&$s.title.trim().length>0?$s.title:null,base:typeof $s.base=="string"&&$s.base.trim().length>0?$s.base:null,head:typeof $s.head=="string"&&$s.head.trim().length>0?$s.head:null,checks:wt.status?.checks?{state:wt.status.checks.state,total:wt.status.checks.total,success:wt.status.checks.success,failure:wt.status.checks.failure,pending:wt.status.checks.pending}:null,canMerge:typeof wt.status?.canMerge=="boolean"?wt.status.canMerge:null,mergeableState:typeof $s.mergeableState=="string"?$s.mergeableState:null,repo:wt.status?.repo?{owner:wt.status.repo.owner,repo:wt.status.repo.repo}:null},Fr=De.get(gr);(!Fr||ch(Tr.visualState)>ch(Fr.visualState))&&De.set(gr,Tr)}),De},[ut]),Re=d.useCallback((De,wt,Ht,Ts,gn)=>s.jsx(HG,{group:De,groupKey:wt,projectId:Ht,hideGroupLabel:Ts,hasSessionSearchQuery:He,normalizedSessionSearchQuery:lt,groupSearchDataByGroup:jn,expandedSessionGroups:B,collapsedGroups:ve,hideDirectoryControls:r,getFoldersForScope:Pe,collapsedFolderIds:Oe,toggleFolderCollapse:ht,renameFolder:We,deleteFolder:xt,showDeletionDialog:rt,setDeleteFolderConfirm:q,renderSessionNode:ia,currentSessionDirectory:$e,projectRepoStatus:A,lastRepoStatus:fr.current,toggleGroupSessionLimit:Jn,mobileVariant:t,activeProjectId:ie,setActiveProjectIdOnly:Se,setActiveMainTab:Ne,setSessionSwitcherOpen:ze,openNewSessionDraft:Cs,addSessionToFolder:et,createFolderAndStartRename:Ln,renamingFolderId:Y,renameFolderDraft:V,setRenameFolderDraft:te,setRenamingFolderId:J,pinnedSessionIds:ee,prVisualStateByDirectoryBranch:Vl,onToggleCollapsedGroup:tl,dragHandleProps:gn}),[He,lt,jn,B,ve,r,Pe,Oe,ht,We,xt,rt,ia,$e,A,Jn,t,ie,Se,Ne,ze,Cs,et,Ln,Y,V,ee,Vl,tl]),pt=He?null:s.jsx(JG,{sections:xs,renderSessionNode:ia}),Ct=!!(Y||f||x),Vt=d.useCallback(()=>{Ne("chat"),t&&ze(!1),Cs()},[t,Cs,Ne,ze]),os=d.useCallback(()=>{Ne("chat"),t&&ze(!1),Le()},[t,Le,Ne,ze]);return s.jsxs("div",{ref:u,className:Q("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[as?s.jsxs("div",{onMouseDown:Xe,className:Q("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",Gt),children:[Eu()&&s.jsx(Bq,{className:"mr-3"}),s.jsxs(Dt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ge,className:Ae,"aria-label":"Close sessions",children:s.jsx(ji,{className:"h-[18px] w-[18px]"})})}),s.jsx(_t,{children:s.jsx("p",{children:"Close sessions"})})]})]}):null,s.jsx(KG,{hideDirectoryControls:r,handleOpenDirectoryDialog:zs,handleNewSession:Vt,useMobileNotesPanel:Uo,projectNotesPanelOpen:z,setProjectNotesPanelOpen:R,activeProjectRefForHeader:Mr,activeProjectLabelForHeader:Ms,canOpenMultiRun:Z.length>0,openMultiRunLauncher:os,stableActiveProjectIsRepo:Ir,headerActionIconClass:Ol,reserveHeaderActionsSpace:Vo,headerActionButtonClass:la,isSessionSearchOpen:a,setIsSessionSearchOpen:l,sessionSearchInputRef:m,sessionSearchQuery:i,setSessionSearchQuery:c,hasSessionSearchQuery:He,searchMatchCount:Ur,collapseAllProjects:br,expandAllProjects:Ar}),s.jsx(aZ,{topContent:pt,sectionsForRender:pr,projectSections:bn,activeProjectId:ie,showOnlyMainWorkspace:o,hasSessionSearchQuery:He,emptyState:Ks,searchEmptyState:Xn,renderGroupSessions:Re,homeDirectory:ue,collapsedProjects:j,hideDirectoryControls:r,projectRepoStatus:A,hoveredProjectId:I,setHoveredProjectId:P,isDesktopShellRuntime:Kt,stuckProjectHeaders:el,mobileVariant:t,toggleProject:Vr,setActiveProjectIdOnly:Se,setActiveMainTab:Ne,setSessionSwitcherOpen:ze,openNewSessionDraft:Cs,openNewWorktreeDialog:zn,openProjectEditDialog:b,removeProject:me,projectHeaderSentinelRefs:le,reorderProjects:ye,getOrderedGroups:Je,setGroupOrderByProject:ne,openSidebarMenuKey:W,setOpenSidebarMenuKey:G,isInlineEditing:Ct}),s.jsx(tZ,{onOpenSettings:()=>de(!0),onOpenShortcuts:we,onOpenAbout:()=>je(!0),onOpenUpdate:Te,showRuntimeButtons:!bt,showUpdateButton:Ie}),s.jsx(fu,{open:T,onOpenChange:_,info:Mt.info,downloading:Mt.downloading,downloaded:Mt.downloaded,progress:Mt.progress,error:Mt.error,onDownload:Mt.downloadUpdate,onRestart:Mt.restartToUpdate,runtimeType:Mt.runtimeType}),Rs?s.jsx(E8,{open:!!Rs,onOpenChange:De=>{De||b(null)},projectId:Rs.id,projectName:Rs.label||Or(Rs.path,ue),projectPath:Rs.path,initialIcon:Rs.icon,initialColor:Rs.color,initialIconBackground:Rs.iconBackground,onSave:un}):null,s.jsx(zq,{open:D,onOpenChange:L,onWorktreeCreated:(De,wt)=>{if(Ne("chat"),t&&ze(!1),wt?.sessionId){Zt(wt.sessionId);return}Cs({directoryOverride:De})}}),Uo?s.jsx(cr,{open:z,onClose:()=>R(!1),title:Ms?`Project notes - ${Ms}`:"Project notes",children:s.jsx(X7,{projectRef:Mr,projectLabel:Ms,canCreateWorktree:Ir,onActionComplete:()=>R(!1),className:"p-0"})}):null,s.jsx(kZ,{value:U,setValue:X,showDeletionDialog:rt,setShowDeletionDialog:st,onConfirm:Hs}),s.jsx(NZ,{value:$,setValue:q,onConfirm:rn})]})},rc=()=>{const t=Fe.c(13),[e,n]=he.useState(!1);let r,o;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(_n()||Eu())},o=[],t[0]=r,t[1]=o):(r=t[0],o=t[1]),he.useEffect(r,o);let a;t[2]!==e?(a=async h=>e?await Tu(h):{success:!0,path:h},t[2]=e,t[3]=a):a=t[3];const l=a;let i;t[4]!==e?(i=async h=>e?await jv():{success:!0},t[4]=e,t[5]=i):i=t[5];const c=i;let u;t[6]!==e?(u=async h=>e?await kv():{success:!0},t[6]=e,t[7]=u):u=t[7];const m=u;let f;return t[8]!==e||t[9]!==l||t[10]!==c||t[11]!==m?(f={isDesktop:e,requestAccess:l,startAccessing:c,stopAccessing:m},t[8]=e,t[9]=l,t[10]=c,t[11]=m,t[12]=f):f=t[12],f},dh=({currentPath:t,onSelectPath:e,triggerClassName:n,variant:r="dropdown",className:o,selectionBehavior:a="immediate",onDoubleClickPath:l,showHidden:i=!1,rootDirectory:c=null,isRootReady:u,alwaysShowActions:m=!1})=>{const{isMobile:f}=wn(),[h,p]=d.useState([]),[g,x]=d.useState(new Set),[b,v]=d.useState(!0),[y,w]=d.useState(!1),[C,N]=d.useState(""),[S,k]=d.useState(new Set),[j,F]=d.useState(null),[A,M]=d.useState(""),[B,E]=d.useState(!0),I=d.useRef(null),{requestAccess:P,startAccessing:D,isDesktop:L}=rc(),T=d.useRef(i),_=d.useCallback(H=>{if(!H)return H;if(H==="/"||H.length===0)return"/";let K=H;for(;K.length>1&&K.endsWith("/");)K=K.slice(0,-1);return K.length===0?"/":K},[]),z=d.useMemo(()=>{if(!C)return null;const H=C.replace(/\\/g,"/");return _(H)},[C,_]),R=d.useMemo(()=>{if(typeof c=="string"&&c.length>0){const H=c.replace(/\\/g,"/"),K=_(H);if(K&&K!=="/")return K}return z&&z!=="/"?z:null},[c,z,_]),W=d.useMemo(()=>typeof u=="boolean"?!!(u&&R):!!R,[u,R]);d.useEffect(()=>{W||(v(!0),p([]))},[W]);const G=d.useCallback(H=>{if(!H||!W||!R)return!1;const K=H.replace(/\\/g,"/"),re=_(K)??K;if(re===R)return!0;const le=`${R}/`;return re.startsWith(le)},[W,R,_]),Y=async H=>{if(W){if(a==="deferred"){e(H);return}if(L){const K=await P(H);K.success&&K.path?(await D(K.path),e(K.path)):(console.error("Failed to get directory access:",K.error),e(H))}else e(H)}};d.useEffect(()=>{let H=!1;const K=ae=>{if(!ae)return!1;const ue=_(ae.replace(/\\/g,"/"));return!ue||ue==="/"?!1:(N(typeof ue=="string"?ue:ae.replace(/\\/g,"/")),!0)};return c&&K(c)||(async()=>{try{const ae=await En.getFilesystemHome();if(!H&&K(ae))return}catch(ae){console.warn("Failed to resolve filesystem home directory:",ae)}try{const ae=await En.getSystemInfo();if(!H&&K(ae?.homeDirectory))return}catch(ae){console.warn("Failed to resolve home directory from system info:",ae)}})(),()=>{H=!0}},[c,_]),d.useEffect(()=>{let H=!1;const K=ue=>{if(H)return;const be=ue.filter(oe=>typeof oe=="string"&&oe.length>0).map(oe=>{const Z=oe.replace(/\\/g,"/");return _(Z)??Z});k(new Set(be))},re=()=>{try{const ue=localStorage.getItem("pinnedDirectories");if(!ue)return;const be=JSON.parse(ue);Array.isArray(be)&&K(be)}catch(ue){console.warn("Failed to load pinned directories from local storage:",ue)}},le=async()=>{try{let ue=[];const be=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(be.ok){const oe=await be.json();ue=Array.isArray(oe?.pinnedDirectories)?oe.pinnedDirectories:[]}if(H)return;K(ue)}catch(ue){console.warn("Failed to load pinned directories:",ue)}};re();const ae=ue=>{const be=ue.detail;be&&Array.isArray(be.pinnedDirectories)&&K(be.pinnedDirectories)};return window.addEventListener("archcoder:settings-synced",ae),le(),()=>{H=!0,window.removeEventListener("archcoder:settings-synced",ae)}},[_]);const J=d.useRef(!0);d.useEffect(()=>{if(J.current){J.current=!1;return}const H={pinnedDirectories:Array.from(S)};ln(H)},[S]),d.useEffect(()=>{R&&k(H=>{const K=Array.from(H).map(re=>_(re.replace(/\\/g,"/"))??re).filter(re=>G(re));return new Set(K)})},[R,G,_]),d.useEffect(()=>{T.current!==i&&(T.current=i)},[i]);const V=H=>{k(K=>{if(!G(H))return K;const re=_(H.replace(/\\/g,"/"))??H.replace(/\\/g,"/"),le=new Set(K);return le.has(re)?le.delete(re):le.add(re),le})},te=d.useMemo(()=>Array.from(S).map(H=>_(H.replace(/\\/g,"/"))??H).filter(H=>G(H)).map(H=>({path:H,name:H.split("/").pop()||H})).sort((H,K)=>H.name.localeCompare(K.name)),[S,G,_]),U=d.useCallback(async H=>{const K=be=>i||!be.startsWith("."),re=R;if(!W||!re)return[];const le=H&&H.length>0?H:re,ae=le?le.replace(/\\/g,"/"):null,ue=ae?_(ae)??ae:null;if(ue){const be=`${re}/`;if(!(ue===re||ue.startsWith(be)))return[]}try{return(await En.listLocalDirectory(H)).filter(oe=>{if(!oe.isDirectory||!K(oe.name))return!1;const Z=oe.path.replace(/\\/g,"/"),ie=_(Z)??Z,pe=ie===re?re:`${re}/`;return ie===re||ie.startsWith(pe)}).map(oe=>({name:oe.name,path:oe.path.replace(/\\/g,"/"),isDirectory:!0})).sort((oe,Z)=>oe.name.localeCompare(Z.name))}catch{try{const oe=await En.getApiClient().file.list({path:".",directory:H});return oe.data?oe.data.filter(Z=>{if(Z.type!=="directory"||!Z.name||!K(Z.name))return!1;const ie=String(Z.absolute||Z.path||Z.name).replace(/\\/g,"/"),pe=_(ie)??ie,me=pe===re?re:`${re}/`;return pe===re||pe.startsWith(me)}).map(Z=>({name:Z.name||"",path:String(Z.absolute||Z.path||Z.name).replace(/\\/g,"/"),isDirectory:!0})).filter(Z=>Z.name!=="").sort((Z,ie)=>Z.name.localeCompare(ie.name)):[]}catch{return[]}}},[i,R,_,W]),X=d.useRef(!1),$=d.useCallback(async()=>{if(!W||!R){v(!0),p([]);return}X.current||v(!0);try{const H=await U(R);p(H),X.current=!0}catch{}finally{v(!1)}},[W,R,U]);d.useEffect(()=>{W&&(r==="inline"||y)&&$()},[r,y,W,$]);const q=async H=>{if(!W)return;const K=g.has(H.path),re=new Set(g);if(K){re.delete(H.path),x(re);return}re.add(H.path),x(re);const le=await U(H.path),ae=ue=>ue.map(be=>be.path===H.path?{...be,children:le}:be.children?{...be,children:ae(be.children)}:be);p(ue=>ae(ue))};d.useEffect(()=>{j&&I.current&&(I.current.focus(),I.current.select())},[j]);const ee=(H,K=[])=>{const re="new_directory",le=K.map(oe=>oe.name);if(!le.includes(re))return re;let ae=1;const ue=new RegExp(`^${re}(\\d+)$`);for(const oe of le){const Z=oe.match(ue);if(Z){const ie=parseInt(Z[1],10);ie>ae&&(ae=ie)}}let be=2;for(;le.includes(`${re}${be}`);)be++;return`${re}${Math.max(be,ae+1)}`},ce=async H=>{if(W){if(g.has(H.path)){const K=ee(H.path,H.children);M(K)}else{const K=new Set(g);if(K.add(H.path),x(K),H.children){const re=ee(H.path,H.children);M(re)}else{const re=await U(H.path),le=ue=>ue.map(be=>be.path===H.path?{...be,children:re}:be.children?{...be,children:le(be.children)}:be);p(ue=>le(ue));const ae=ee(H.path,re);M(ae)}}F(H.path)}},ve=async()=>{if(!j||!W)return;const H=A.trim()||"new_directory",K=`${j}/${H}`;try{await En.createDirectory(K,{allowOutsideWorkspace:!0});const re=await U(j),le=ae=>ae.map(ue=>ue.path===j?{...ue,children:re}:ue.children?{...ue,children:le(ue.children)}:ue);p(ae=>le(ae)),F(null),M("")}catch(re){console.error("Failed to create directory:",re)}},ge=()=>{F(null),M("")},xe=(H,K=0)=>{const re=g.has(H.path),le=H.isDirectory,ae=S.has(H.path),ue=t===H.path,be=r==="inline",oe=s.jsxs(s.Fragment,{children:[le&&s.jsx("button",{onClick:Z=>{Z.stopPropagation(),q(H)},className:Q("hover:bg-interactive-hover rounded","p-0.5"),children:re?s.jsx(Ds,{className:f?"h-3.5 w-3.5":"h-3 w-3"}):s.jsx(On,{className:f?"h-3.5 w-3.5":"h-3 w-3"})}),!le&&s.jsx("div",{className:f?"w-4.5":"w-4"}),s.jsxs("button",{onClick:Z=>{Z.stopPropagation(),Y(H.path),r==="dropdown"&&a==="immediate"&&w(!1)},onDoubleClick:Z=>{Z.stopPropagation(),l&&l(H.path)},className:Q("flex items-center flex-1 text-left focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/60 rounded","gap-1.5",be&&ue?"text-primary":"text-foreground"),children:[s.jsx(Pa,{className:Q("text-muted-foreground flex-shrink-0",f?"h-4 w-4":"h-3.5 w-3.5",be&&ue&&"text-primary")}),s.jsx("span",{className:Q("font-medium truncate","typography-ui-label",be&&ue?"text-primary":"text-foreground"),children:H.name})]}),s.jsx("button",{onClick:Z=>{Z.stopPropagation(),ce(H)},className:Q("hover:bg-interactive-hover rounded transition-opacity",f?"p-1.5":"p-1",m?"opacity-60":"opacity-0 group-hover:opacity-100"),title:"Create new directory",children:s.jsx(Qs,{className:Q("text-muted-foreground",f?"h-3.5 w-3.5":"h-3 w-3")})}),s.jsx("button",{onClick:Z=>{Z.stopPropagation(),V(H.path)},className:Q("hover:bg-interactive-hover rounded transition-opacity",f?"p-1.5":"p-1",m?"opacity-60":"opacity-0 group-hover:opacity-100"),title:ae?"Unpin directory":"Pin directory",children:ae?s.jsx(lc,{className:Q("text-primary",f?"h-3.5 w-3.5":"h-3 w-3")}):s.jsx(z0,{className:Q("text-muted-foreground",f?"h-3.5 w-3.5":"h-3 w-3")})})]});return r==="inline"?s.jsxs("div",{children:[s.jsx("div",{className:Q("group flex items-center gap-1 rounded-lg mx-1 text-left transition-colors",f?"px-1.5 py-1":"px-2 py-1.5",ue?"bg-primary/10 text-primary":"hover:bg-interactive-hover/50 text-foreground"),style:{paddingLeft:`${K*(f?12:14)+(f?4:6)}px`},children:oe}),re&&s.jsxs(s.Fragment,{children:[j===H.path&&s.jsxs("div",{className:"flex items-center gap-1 mx-1 px-2 py-1.5",style:{paddingLeft:`${(K+1)*14+6}px`},children:[s.jsx("div",{className:"w-4"}),s.jsx(Pa,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Xt,{ref:I,value:A,onChange:Z=>M(Z.target.value),onKeyDown:Z=>{Z.key==="Enter"?(Z.preventDefault(),Z.stopPropagation(),ve()):Z.key==="Escape"&&(Z.preventDefault(),Z.stopPropagation(),ge())},onBlur:ve,className:"h-6 typography-meta flex-1 selection:bg-interactive-selection selection:text-interactive-selection-foreground",placeholder:"new_directory"}),s.jsx("button",{onClick:Z=>{Z.preventDefault(),Z.stopPropagation(),ve()},className:"p-1 hover:bg-interactive-hover rounded",title:"Create directory",children:s.jsx(js,{className:"h-3 w-3 text-green-600"})}),s.jsx("button",{onClick:Z=>{Z.preventDefault(),Z.stopPropagation(),ge()},className:"p-1 hover:bg-interactive-hover rounded",title:"Cancel",children:s.jsx(Ps,{className:"h-3 w-3 text-muted-foreground"})})]}),H.children&&H.children.map(Z=>xe(Z,K+1))]})]},H.path):s.jsxs("div",{children:[s.jsxs(Jt,{className:Q("flex items-center gap-1 cursor-pointer group",t===H.path&&"bg-interactive-selection"),style:{paddingLeft:`${K*12+8}px`},onSelect:Z=>{Z.preventDefault()},children:[le&&s.jsx("button",{onClick:Z=>{Z.stopPropagation(),q(H)},className:"p-0.5 hover:bg-interactive-hover rounded",children:re?s.jsx(Ds,{className:"h-3 w-3"}):s.jsx(On,{className:"h-3 w-3"})}),!le&&s.jsx("div",{className:"w-4"}),oe]}),re&&s.jsxs("div",{children:[j===H.path&&s.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5",style:{paddingLeft:`${(K+1)*12+8}px`},children:[s.jsx("div",{className:"w-4"}),s.jsx(Pa,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Xt,{ref:I,value:A,onChange:Z=>M(Z.target.value),onKeyDown:Z=>{Z.key==="Enter"?(Z.preventDefault(),Z.stopPropagation(),ve()):Z.key==="Escape"&&(Z.preventDefault(),Z.stopPropagation(),ge())},onBlur:ve,className:"h-6 typography-meta flex-1 selection:bg-interactive-selection selection:text-interactive-selection-foreground",placeholder:"new_directory"}),s.jsx("button",{onClick:Z=>{Z.preventDefault(),Z.stopPropagation(),ve()},className:"p-1 hover:bg-interactive-hover rounded",title:"Create directory",children:s.jsx(js,{className:"h-3 w-3 text-green-600"})}),s.jsx("button",{onClick:Z=>{Z.preventDefault(),Z.stopPropagation(),ge()},className:"p-1 hover:bg-interactive-hover rounded",title:"Cancel",children:s.jsx(Ps,{className:"h-3 w-3 text-muted-foreground"})})]}),H.children&&H.children.map(Z=>xe(Z,K+1))]})]},H.path)},ne=(H,K)=>{if(r==="inline"){const re=t===K;return s.jsxs("div",{className:Q("group flex items-center gap-2 mx-1 rounded-lg transition-colors",f?"px-1.5 py-1":"px-2 py-1.5",re?"bg-primary/10":"hover:bg-interactive-hover/50"),children:[s.jsxs("button",{onClick:()=>Y(K),onDoubleClick:le=>{le.stopPropagation(),l&&l(K)},className:Q("flex flex-1 items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/60 rounded min-w-0",re?"text-primary":"text-foreground"),children:[s.jsx(Pa,{className:Q("flex-shrink-0",f?"h-4 w-4":"h-3.5 w-3.5",re?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:Q("typography-ui-label font-medium truncate flex-shrink-0",re?"text-primary":"text-foreground"),children:H}),s.jsx("span",{className:"typography-meta text-muted-foreground/60 truncate",children:va(K,C)})]}),s.jsx("button",{onClick:()=>V(K),className:Q("hover:bg-interactive-hover rounded-md transition-opacity",f?"p-1.5 opacity-60":"p-1 opacity-0 group-hover:opacity-100"),title:"Unpin directory",children:s.jsx(lc,{className:Q("text-primary","h-3.5 w-3.5")})})]},K)}return s.jsxs(Jt,{onSelect:re=>{re.preventDefault(),Y(K),a==="immediate"&&w(!1)},className:Q("flex items-start gap-2 cursor-pointer group py-2",t===K&&"bg-interactive-selection"),children:[s.jsx(Pa,{className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("div",{className:"typography-ui-label font-medium",children:H}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:va(K,C)})]}),s.jsx("button",{onClick:re=>{re.stopPropagation(),re.preventDefault(),V(K)},className:"p-1 opacity-0 group-hover:opacity-100 hover:bg-interactive-hover rounded transition-opacity",title:"Unpin directory",children:s.jsx(lc,{className:"h-3 w-3 text-primary"})})]},K)},O=s.jsx(s.Fragment,{children:W?s.jsxs(s.Fragment,{children:[te.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",onClick:()=>E(H=>!H),className:Q("flex w-full items-center gap-1.5 typography-meta font-medium text-muted-foreground/80 hover:bg-interactive-hover/30 rounded transition-colors uppercase tracking-wide",f?"px-1.5 py-1":"px-2 py-1.5"),children:[B?s.jsx(Ds,{className:f?"h-3.5 w-3.5":"h-3 w-3"}):s.jsx(On,{className:f?"h-3.5 w-3.5":"h-3 w-3"}),s.jsx("span",{children:"Pinned"}),s.jsx("span",{className:"ml-auto typography-micro text-muted-foreground/60 normal-case tracking-normal",children:te.length})]}),B&&te.map(({name:H,path:K})=>ne(H,K)),r==="dropdown"&&s.jsx(Zn,{}),r==="inline"&&B&&s.jsx("div",{className:"mx-3 my-2 border-t border-border/40"})]}),s.jsx("div",{className:Q("typography-meta font-medium text-muted-foreground/80 flex items-center gap-1.5 uppercase tracking-wide",f?"px-1.5 py-1":"px-2 py-1.5"),children:"Browse"}),b?s.jsx("div",{className:"px-3 py-2 typography-ui-label text-muted-foreground",children:"Loading..."}):h.map(H=>xe(H)),!b&&h.length===0&&s.jsx("div",{className:"px-3 py-2 typography-ui-label text-muted-foreground",children:"No directories found"})]}):s.jsx("div",{className:"px-3 py-2 typography-ui-label text-muted-foreground",children:"Locating home directory..."})});return r==="inline"?s.jsx("div",{className:Q("overflow-hidden flex flex-col",o),children:s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"w-full py-1",children:O})}):s.jsxs(qs,{open:y,onOpenChange:w,children:[s.jsx(Gs,{asChild:!0,children:s.jsxs(Be,{variant:"ghost",className:Q("w-full h-8 px-2.5 justify-between items-center rounded-lg border border-transparent bg-sidebar-accent/40 text-foreground/90 hover:bg-sidebar-accent/60 typography-meta",n),"aria-label":"Select working directory",children:[s.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:[s.jsx(Pa,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"truncate",title:t,children:va(t,C)})]}),s.jsx(Ds,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Ys,{align:"start",className:"w-[350px]",children:s.jsx(ks,{outerClassName:"h-full",className:"w-full",children:O})})]})},eg=d.forwardRef((t,e)=>{const n=Fe.c(40),{inputValue:r,homeDirectory:o,onSelectSuggestion:a,visible:l,onClose:i,showHidden:c}=t;let u;n[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],n[0]=u):u=n[0];const[m,f]=d.useState(u),[h,p]=d.useState(!1),[g,x]=d.useState(0),b=d.useRef(null);let v;n[1]===Symbol.for("react.memo_cache_sentinel")?(v=[],n[1]=v):v=n[1];const y=d.useRef(v),w=EZ;let C;n[2]!==o?(C=Y=>Y.startsWith("~")&&o?Y.replace(/^~/,o):Y,n[2]=o,n[3]=C):C=n[3];const N=C;let S;n[4]!==N?(S=Y=>{const J=N(Y);if(J.endsWith("/"))return J;const V=J.lastIndexOf("/");return V===-1?"":V===0?"/":J.substring(0,V+1)},n[4]=N,n[5]=S):S=n[5];const k=S;let j;n[6]!==N?(j=Y=>{const J=N(Y);if(J.endsWith("/"))return"";const V=J.lastIndexOf("/");return V===-1?J:J.substring(V+1)},n[6]=N,n[7]=j):j=n[7];const F=j,A=Z1(r,150);let M,B;n[8]!==A||n[9]!==k||n[10]!==F||n[11]!==c||n[12]!==l?(M=()=>{if(!l||!A){f([]);return}const Y=k(A),J=F(A).toLowerCase();if(!Y){f([]);return}let V=!1;return p(!0),En.listLocalDirectory(Y).then(te=>{if(V)return;const U=te.filter($=>!(!$.isDirectory||!c&&$.name.startsWith("."))),X=J?U.map($=>{const q=w(J,$.name);return q!==null?{entry:$,score:q}:null}).filter(DZ).sort(IZ).map(TZ):U.sort(PZ);f(X.slice(0,10)),x(0)}).catch(()=>{V||f([])}).finally(()=>{V||p(!1)}),()=>{V=!0}},B=[l,A,k,F,c,w],n[8]=A,n[9]=k,n[10]=F,n[11]=c,n[12]=l,n[13]=M,n[14]=B):(M=n[13],B=n[14]),d.useEffect(M,B);let E,I;n[15]!==g?(E=()=>{y.current[g]?.scrollIntoView({behavior:"smooth",block:"nearest"})},I=[g],n[15]=g,n[16]=E,n[17]=I):(E=n[16],I=n[17]),d.useEffect(E,I);let P,D;n[18]!==i||n[19]!==l?(P=()=>{if(!l)return;const Y=J=>{const V=J.target;!V||!b.current||b.current.contains(V)||i()};return document.addEventListener("pointerdown",Y,!0),()=>{document.removeEventListener("pointerdown",Y,!0)}},D=[l,i],n[18]=i,n[19]=l,n[20]=P,n[21]=D):(P=n[20],D=n[21]),d.useEffect(P,D);let L;n[22]!==a?(L=Y=>{const J=Y.path.endsWith("/")?Y.path:Y.path+"/";a(J)},n[22]=a,n[23]=L):L=n[23];const T=L;let _,z;if(n[24]!==T||n[25]!==i||n[26]!==g||n[27]!==m||n[28]!==l?(_=()=>({handleKeyDown:Y=>{if(!l||m.length===0)return!1;const J=m.length;if(Y.key==="Tab"){if(Y.preventDefault(),Y.shiftKey)x(V=>(V-1+J)%J);else if(J===1){const V=m[0];V&&T(V)}else x(V=>(V+1)%J);return!0}if(Y.key==="ArrowDown")return Y.preventDefault(),x(V=>(V+1)%J),!0;if(Y.key==="ArrowUp")return Y.preventDefault(),x(V=>(V-1+J)%J),!0;if(Y.key==="Enter"){Y.preventDefault();const V=(g%J+J)%J,te=m[V];return te&&T(te),i(),!0}return Y.key==="Escape"?(Y.preventDefault(),i(),!0):!1}}),z=[l,m,g,T,i],n[24]=T,n[25]=i,n[26]=g,n[27]=m,n[28]=l,n[29]=_,n[30]=z):(_=n[29],z=n[30]),d.useImperativeHandle(e,_,z),!l||m.length===0&&!h)return null;let R;n[31]!==T||n[32]!==h||n[33]!==i||n[34]!==g||n[35]!==m?(R=h?s.jsx("div",{className:"flex items-center justify-center py-3",children:s.jsx(Qn,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):s.jsx("div",{className:"overflow-y-auto py-1",children:m.map((Y,J)=>{const V=g===J;return s.jsxs("div",{ref:te=>{y.current[J]=te},className:Q("flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label",V&&"bg-interactive-selection"),onClick:()=>{T(Y),i()},onMouseEnter:()=>x(J),children:[s.jsx(jr,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Y.name})]},Y.path)})}),n[31]=T,n[32]=h,n[33]=i,n[34]=g,n[35]=m,n[36]=R):R=n[36];let W;n[37]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx("div",{className:"px-3 py-1.5 border-t typography-meta text-muted-foreground bg-sidebar/50",children:"Tab cycle • ↑↓ navigate • Enter select"}),n[37]=W):W=n[37];let G;return n[38]!==R?(G=s.jsxs("div",{ref:b,className:"absolute z-[100] w-full max-h-48 bg-background border border-border rounded-lg shadow-none top-full mt-1 left-0 flex flex-col overflow-hidden",children:[R,W]}),n[38]=R,n[39]=G):G=n[39],G});eg.displayName="DirectoryAutocomplete";function EZ(t,e){const n=t.trim().toLowerCase();if(!n)return 0;const r=e.toLowerCase();let o=0,a=-1,l=0;for(let i=0;i<n.length;i=i+1,i){const c=n[i];if(!c||c===" ")continue;const u=r.indexOf(c,a+1);if(u===-1)return null;const m=u-a-1;if(m===0?l=l+1:l=0,o=o+10,o=o+Math.max(0,18-u),o=o-Math.max(0,m),u===0)o=o+12;else{const f=r[u-1];(f==="/"||f==="_"||f==="-"||f==="."||f===" ")&&(o=o+10)}o=o+(l>0?12:0),a=u}return o=o+Math.max(0,24-Math.round(r.length/3)),o}function DZ(t){return t!==null}function IZ(t,e){return e.score-t.score||t.entry.name.localeCompare(e.entry.name)}function TZ(t){return t.entry}function PZ(t,e){return t.name.localeCompare(e.name)}const RZ=({open:t,onOpenChange:e})=>{const{currentDirectory:n,homeDirectory:r,isHomeReady:o}=dn(),{addProject:a,getActiveProject:l}=vs(),[i,c]=d.useState(null),[u,m]=d.useState(""),[f,h]=d.useState(!1),[p,g]=d.useState(!1),x=q1(),{isDesktop:b,requestAccess:v,startAccessing:y}=rc(),{isMobile:w}=wn(),[C,N]=d.useState(!1),S=d.useRef(null),k=d.useCallback(J=>J?va(J,r):"",[r]);d.useEffect(()=>{if(t){h(!1),g(!1),N(!1);const V=l()?.path||n||r||"";c(V),m(k(V))}},[t,n,r,k,l]),d.useEffect(()=>{!t||f||i||r&&o&&(c(r),h(!0),m("~"))},[t,f,i,r,o]);const j=d.useCallback(()=>{e(!1)},[e]),F=d.useCallback(async J=>{if(!(!J||p)){g(!0);try{let V=J,te;if(b){const X=await v(J);if(!X.success){fe.error("Unable to access directory",{description:X.error||"Desktop denied directory access."});return}V=X.path??J,te=X.projectId;const $=await y(V);if(!$.success){fe.error("Failed to open directory",{description:$.error||"Desktop could not grant file access."});return}}if(!a(V,{id:te})){fe.error("Failed to add project",{description:"Please select a valid directory path."});return}j()}catch(V){fe.error("Failed to select directory",{description:V instanceof Error?V.message:"Unknown error occurred."})}finally{g(!1)}}},[a,j,b,v,y,p]),A=d.useCallback(async()=>{const J=u.trim()||i;J&&await F(J)},[F,u,i]),M=d.useCallback(J=>{c(J),h(!0),m(k(J))},[k]),B=d.useCallback(async J=>{c(J),h(!0),m(k(J)),await F(J)},[F,k]),E=d.useCallback(J=>{const V=J.target.value;if(m(V),h(!0),N(V.startsWith("/")||V.startsWith("~")),V.startsWith("/")||V.startsWith("~")){const te=V.startsWith("~")&&r?V.replace(/^~/,r):V;c(te)}},[r]),I=d.useCallback(J=>{S.current?.handleKeyDown(J)||J.key==="Enter"&&(J.preventDefault(),A())},[A]),P=d.useCallback(J=>{c(J),h(!0),m(k(J))},[k]),D=d.useCallback(()=>{N(!1)},[]),L=d.useCallback(()=>{H0(!x)},[x]),T=s.jsxs("button",{type:"button",onClick:L,className:"flex items-center gap-2 px-2 py-1 rounded-lg hover:bg-interactive-hover/40 transition-colors typography-meta text-muted-foreground flex-shrink-0",children:[x?s.jsx(Jo,{className:"h-4 w-4 text-primary"}):s.jsx(ea,{className:"h-4 w-4"}),"Show hidden"]}),_=s.jsxs(Zs,{className:"flex-shrink-0 px-4 pb-2 pt-[calc(var(--oc-safe-area-top,0px)+0.5rem)] sm:px-0 sm:pb-3 sm:pt-0",children:[s.jsx(Us,{children:"Add project directory"}),s.jsxs("div",{className:"hidden sm:flex sm:items-center sm:justify-between sm:gap-4",children:[s.jsx(sn,{className:"flex-1",children:"Choose a folder to add as a project."}),T]})]}),z=s.jsxs("div",{className:"relative",children:[s.jsx(Xt,{value:u,onChange:E,onKeyDown:I,placeholder:"Enter path or select from tree...",className:"font-mono typography-meta",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),s.jsx(eg,{ref:S,inputValue:u,homeDirectory:r,onSelectSuggestion:P,visible:C,onClose:D,showHidden:x})]}),R=s.jsx("div",{className:"flex-1 min-h-0 rounded-xl border border-border/40 bg-sidebar/70 overflow-hidden flex flex-col",children:s.jsx(dh,{variant:"inline",currentPath:i??n,onSelectPath:M,onDoubleClickPath:B,className:"flex-1 min-h-0 sm:min-h-[280px] sm:max-h-[380px]",selectionBehavior:"deferred",showHidden:x,rootDirectory:o?r:null,isRootReady:o})}),W=s.jsxs("div",{className:"flex flex-col gap-3 h-full",children:[s.jsx("div",{className:"flex-shrink-0",children:z}),s.jsx("div",{className:"flex-shrink-0 flex items-center justify-end",children:T}),s.jsx("div",{className:"flex-1 min-h-0 rounded-xl border border-border/40 bg-sidebar/70 overflow-hidden flex flex-col",children:s.jsx(dh,{variant:"inline",currentPath:i??n,onSelectPath:M,onDoubleClickPath:B,className:"flex-1 min-h-0",selectionBehavior:"deferred",showHidden:x,rootDirectory:o?r:null,isRootReady:o,alwaysShowActions:!0})})]}),G=s.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col gap-3",children:[z,R]}),Y=()=>s.jsxs(s.Fragment,{children:[s.jsx(Be,{variant:"ghost",onClick:j,disabled:p,className:"flex-1 sm:flex-none sm:w-auto",children:"Cancel"}),s.jsx(Be,{onClick:A,disabled:p||!f||!i&&!u.trim(),className:"flex-1 sm:flex-none sm:w-auto sm:min-w-[140px]",children:p?"Adding...":"Add Project"})]});return w?s.jsx(cr,{open:t,onClose:()=>e(!1),title:"Add project directory",className:"max-w-full",contentMaxHeightClassName:"max-h-[min(70vh,520px)] h-[min(70vh,520px)]",footer:s.jsx("div",{className:"flex flex-row gap-2",children:Y()}),children:W}):s.jsx(Os,{open:t,onOpenChange:e,children:s.jsxs(Vs,{className:Q("flex w-full max-w-[min(560px,100vw)] max-h-[calc(100vh-32px)] flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh] sm:max-w-xl sm:p-6"),onOpenAutoFocus:J=>{J.preventDefault()},children:[_,G,s.jsx(yn,{className:"sticky bottom-0 flex w-full flex-shrink-0 flex-row gap-2 border-t border-border/40 bg-sidebar px-4 py-3 sm:static sm:justify-end sm:border-0 sm:bg-transparent sm:px-0 sm:pt-4 sm:pb-0",children:Y()})]})})},dl=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,So=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},zZ=()=>{const[t,e]=d.useState(!1),[n,r]=d.useState(!1),[o,a]=d.useState(null),[l,i]=d.useState([]),[c,u]=d.useState(!1),[m,f]=d.useState(!1),[h,p]=d.useState(!1),[g,x]=d.useState(!1),[b,v]=d.useState(new Set),{deleteSession:y,deleteSessions:w,archiveSession:C,archiveSessions:N,loadSessions:S,getWorktreeMetadata:k,newSessionDraft:j,setNewSessionDraftTarget:F,setDraftBootstrapPendingDirectory:A}=Ze(),M=Ee(Z=>Z.showDeletionDialog),B=Ee(Z=>Z.setShowDeletionDialog),{currentDirectory:E,homeDirectory:I,isHomeReady:P}=dn(),{projects:D,addProject:L,activeProjectId:T}=vs(),{requestAccess:_,startAccessing:z}=rc(),{isMobile:R,isTablet:W,hasTouchInput:G}=wn(),Y=R||W||G,J=d.useMemo(()=>{const ie=(T?D.find(pe=>pe.id===T)??null:null)?.path??E;return So(ie)},[T,E,D]),V=d.useCallback(Z=>{const pe=So(Z.projectDirectory)||J;return{id:(D.find(Se=>So(Se.path)===pe)??null)?.id??`path:${pe}`,path:pe}},[J,D]),te=g&&b.size>0,U=d.useMemo(()=>{const Z=o?.worktree;return Z&&typeof Z.branch=="string"&&Z.branch.trim().length>0?!0:l.length>0&&l.every(({metadata:ie})=>typeof ie.branch=="string"&&ie.branch.trim().length>0)},[o?.worktree,l]),X=o?.mode==="worktree",$=X,q=h||!X||!U,ee=h||!X;d.useEffect(()=>{S()},[S,E]);const ce=d.useMemo(()=>D.map(Z=>`${Z.id}:${Z.path}`).join("|"),[D]),ve=d.useRef(ce);d.useEffect(()=>{ce!==ve.current&&(ve.current=ce,S())},[S,ce]),d.useEffect(()=>{if(!(n||!P||D.length>0)){if(r(!0),Rn()&&$o()){_("").then(async Z=>{if(!Z.success||!Z.path){Z.error&&Z.error!=="Directory selection cancelled"&&fe.error("Failed to select directory",{description:Z.error});return}const ie=await z(Z.path);if(!ie.success){fe.error("Failed to open directory",{description:ie.error||"Desktop could not grant file access."});return}L(Z.path,{id:Z.projectId})||fe.error("Failed to add project",{description:"Please select a valid directory path."})}).catch(Z=>{console.error("Desktop: Error selecting directory:",Z),fe.error("Failed to select directory")});return}e(!0)}},[L,n,P,D.length,_,z]);const ge=d.useCallback(Z=>{a({sessions:Z.sessions,dateLabel:Z.dateLabel,mode:Z.mode??"session",worktree:Z.worktree??null})},[]),xe=d.useCallback(()=>{a(null),i([]),u(!1),f(!1),p(!1),x(!1),v(new Set)},[]),ne=d.useCallback(async Z=>{if(Z.sessions.length===0)return;if(Z.sessions.length===1){const Se=Z.sessions[0];await y(Se.id)?fe.success("Session deleted"):fe.error("Failed to delete session");return}const ie=Z.sessions.map(Se=>Se.id),{deletedIds:pe,failedIds:me}=await w(ie);if(pe.length>0){const Se=me.length>0?`${me.length} session${me.length===1?"":"s"} could not be deleted.`:Z.dateLabel?`Removed all sessions from ${Z.dateLabel}.`:void 0;fe.success(`Deleted ${pe.length} session${pe.length===1?"":"s"}`,{description:dl(Se)})}me.length>0&&fe.error(`Failed to delete ${me.length} session${me.length===1?"":"s"}`,{description:dl("Please try again in a moment.")})},[y,w]);d.useEffect(()=>na.onDeleteRequest(Z=>{if(!M&&(Z.mode??"session")==="session"){ne(Z);return}ge(Z)}),[ge,M,ne]),d.useEffect(()=>na.onDirectoryRequest(()=>{e(!0)}),[]),d.useEffect(()=>{if(!o){i([]),u(!1),f(!1),x(!1),v(new Set);return}const Z=o.sessions.map(me=>{const Se=k(me.id);return Se?{session:me,metadata:Se}:null}).filter(me=>!!me);i(Z),u(!1),x(!1),v(new Set);const ie=new Map;if(o.worktree?.path&&ie.set(So(o.worktree.path),o.worktree),Z.forEach(({metadata:me})=>{me.path&&ie.set(So(me.path),me)}),ie.size===0){x(!0);return}let pe=!1;return(async()=>{const me=new Map,Se=new Set;await Promise.all(Array.from(ie.entries()).map(async([ke,ye])=>{try{const Ne=await Nv(ye.path);me.set(ke,Ne),Ne?.isDirty&&Se.add(ke)}catch{ye.status&&(me.set(ke,ye.status),ye.status.isDirty&&Se.add(ke))}})).catch(ke=>{console.warn("Failed to inspect worktree status before deletion:",ke)}),!pe&&(v(Se),x(!0),a(ke=>{if(!ke?.worktree?.path)return ke;const ye=So(ke.worktree.path),Ne=me.get(ye);if(!Ne)return ke;const _e=ke.worktree.status;return _e?.isDirty===Ne.isDirty&&_e?.ahead===Ne.ahead&&_e?.behind===Ne.behind&&_e?.upstream===Ne.upstream?ke:{...ke,worktree:{...ke.worktree,status:Ne}}}),i(ke=>ke.map(ye=>{const Ne=So(ye.metadata.path),_e=me.get(Ne);return _e?{session:ye.session,metadata:{...ye.metadata,status:_e}}:ye})))})(),()=>{pe=!0}},[o,k]),d.useEffect(()=>{U||u(!1)},[U]);const O=d.useCallback(async(Z,ie)=>{const pe=c&&U,me=V(Z),Se=So(Z.path),ke=So(me.path);try{await F6(me,Z,{deleteRemoteBranch:pe,deleteLocalBranch:ie});const ye=So(j?.directoryOverride);return j?.open&&Se&&ye===Se&&ke&&(A(null),F({projectId:me.id,directoryOverride:ke},{force:!0})),So(E)===Se&&ke&&dn.getState().setDirectory(ke,{showOverlay:!1}),!0}catch(ye){return fe.error("Failed to remove worktree",{description:dl(ye instanceof Error?ye.message:"Please try again.")}),!1}},[U,E,c,V,j?.directoryOverride,j?.open,A,F]),H=d.useCallback(async()=>{if(o){p(!0);try{const Z=$,ie=Z&&c,pe=Z&&m;if(o.sessions.length===0&&X&&o.worktree){if(!await O(o.worktree,pe)){xe();return}const ke=c&&U?"Worktree and remote branch removed.":"Worktree removed.";fe.success("Worktree removed",{description:dl(ke)}),xe(),S();return}if(o.sessions.length===1){const me=o.sessions[0];if(!(X?await C(me.id):await y(me.id,{archiveWorktree:!1,deleteRemoteBranch:ie,deleteLocalBranch:pe}))){fe.error(X?"Failed to archive session":"Failed to delete session"),p(!1);return}const ke=!X&&Z?ie?"Worktree and remote branch removed.":"Attached worktree archived.":void 0;fe.success(X?"Session archived":"Session deleted",{description:dl(ke),action:{label:"OK",onClick:()=>{}}})}else{const me=o.sessions.map(ye=>ye.id);let Se=[],ke=[];if(X){const ye=await N(me);Se=ye.archivedIds,ke=ye.failedIds}else{const ye=await w(me,{archiveWorktree:!1,deleteRemoteBranch:ie,deleteLocalBranch:pe});Se=ye.deletedIds,ke=ye.failedIds}if(X&&o.worktree&&ke.length===0&&await O(o.worktree,pe)&&await S(),Se.length>0){const ye=!X&&Z?ie?"Archived worktrees and removed remote branches.":"Attached worktrees archived.":void 0,_e=[ke.length>0?`${ke.length} session${ke.length===1?"":"s"} could not be ${X?"archived":"deleted"}.`:o.dateLabel?`Removed all sessions from ${o.dateLabel}.`:void 0,ye].filter(Boolean).join(" ");fe.success(`${X?"Archived":"Deleted"} ${Se.length} session${Se.length===1?"":"s"}`,{description:dl(_e||void 0),action:{label:"OK",onClick:()=>{}}})}if(ke.length>0&&(fe.error(`Failed to ${X?"archive":"delete"} ${ke.length} session${ke.length===1?"":"s"}`,{description:dl("Please try again in a moment.")}),Se.length===0)){p(!1);return}}X&&o.sessions.length===1&&o.worktree&&await O(o.worktree,pe)&&await S(),xe()}finally{p(!1)}}},[o,c,m,y,w,C,N,xe,$,X,U,O,S]),K=o?.worktree??l[0]?.metadata??null,re=o?o.mode==="worktree"?o.sessions.length===0?"This removes the selected worktree.":`This removes the selected worktree and archives ${o.sessions.length===1?"1 linked session":`${o.sessions.length} linked sessions`}.`:`This action permanently removes ${o.sessions.length===1?"1 session":`${o.sessions.length} sessions`}${o.dateLabel?` from ${o.dateLabel}`:""}.`:"",le=o?s.jsxs("div",{className:Q(X?"space-y-3":"space-y-2"),children:[o.sessions.length>0&&s.jsxs("div",{className:Q(X?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[X&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:o.sessions.length===1?"Linked session":"Linked sessions"}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:o.sessions.length})]}),s.jsxs("ul",{className:Q(X?"mt-2 space-y-1":"space-y-0.5"),children:[o.sessions.slice(0,5).map(Z=>s.jsxs("li",{className:Q(X?"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:Q(!X&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:Z.title||"Untitled Session"})]},Z.id)),o.sessions.length>5&&s.jsxs("li",{className:Q(X?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:["+",o.sessions.length-5," more"]})]})]}),X?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(on,{className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:"Worktree"}),K?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:K.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:K?va(K.path,I):"Worktree path unavailable."}),te&&s.jsx("p",{className:"typography-micro text-status-warning",children:"Uncommitted changes will be discarded."})]}):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:"Worktree directories stay intact. Subsessions linked to the selected sessions will also be removed."})})]}):null,ae=X?U?s.jsxs("button",{type:"button",onClick:()=>{q||u(Z=>!Z)},disabled:q,className:Q("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",q?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[c?s.jsx(Jo,{className:"size-4 text-primary"}):s.jsx(ea,{className:"size-4"}),"Delete remote branch"]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:"Remote branch info unavailable"}):null,ue=X?s.jsxs("button",{type:"button",onClick:()=>{ee||f(Z=>!Z)},disabled:ee,className:Q("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",ee?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[m?s.jsx(Jo,{className:"size-4 text-primary"}):s.jsx(ea,{className:"size-4"}),"Delete local branch"]}):null,be=X?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:[ue,ae]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{variant:"ghost",onClick:xe,disabled:h,children:"Cancel"}),s.jsx(Be,{variant:"destructive",onClick:H,disabled:h,children:h?"Deleting…":"Delete worktree"})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>B(!M),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":!M,children:[M?s.jsx(ea,{className:"size-4"}):s.jsx(Jo,{className:"size-4 text-primary"}),"Never ask"]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{variant:"ghost",onClick:xe,disabled:h,children:"Cancel"}),s.jsx(Be,{variant:"destructive",onClick:H,disabled:h,children:h?"Deleting…":o?.sessions.length===1?"Delete session":"Delete sessions"})]})]}),oe=X?"Delete worktree":o?.sessions.length===1?"Delete session":"Delete sessions";return s.jsxs(s.Fragment,{children:[Y?s.jsx(cr,{open:!!o,onClose:()=>{h||xe()},title:oe,footer:s.jsx("div",{className:"flex justify-end gap-2",children:be}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[re&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:re}),le]})}):s.jsx(Os,{open:!!o,onOpenChange:Z=>{if(!Z){if(h)return;xe()}},children:s.jsxs(Vs,{className:Q(X?"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(Zs,{children:[s.jsxs(Us,{className:Q(X&&"flex items-center gap-2"),children:[X&&s.jsx(Pn,{className:"h-5 w-5"}),oe]}),re&&s.jsx(sn,{children:re})]}),s.jsx("div",{className:Q(X&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:le}),s.jsx(yn,{className:"mt-2 gap-2 pt-1 pb-1",children:be})]})}),s.jsx(RZ,{open:t,onOpenChange:e})]})},LZ=d.lazy(()=>Kn(()=>Promise.resolve().then(()=>uz),void 0).then(t=>({default:t.PlanView}))),uh=d.lazy(()=>Kn(()=>Promise.resolve().then(()=>HL),void 0).then(t=>({default:t.GitView}))),HZ=d.lazy(()=>Kn(()=>Promise.resolve().then(()=>CH),void 0).then(t=>({default:t.DiffView}))),fh=d.lazy(()=>Kn(()=>import("./TerminalView-DYFvA1o0.js"),__vite__mapDeps([6,0,1,3,4])).then(t=>({default:t.TerminalView}))),$Z=d.lazy(()=>Kn(()=>Promise.resolve().then(()=>ZH),void 0).then(t=>({default:t.FilesView}))),OZ=d.lazy(()=>Kn(()=>Promise.resolve().then(()=>WU),void 0).then(t=>({default:t.SettingsView}))),VZ=d.lazy(()=>Kn(()=>import("./SettingsWindow-DCnW8z6c.js"),__vite__mapDeps([7,0,1,3,4])).then(t=>({default:t.SettingsWindow}))),UZ=d.lazy(()=>Kn(()=>import("./MultiRunWindow-t-TdKGA_.js"),__vite__mapDeps([8,0,1,3,4])).then(t=>({default:t.MultiRunWindow}))),F0=85,WZ=250,qZ=500,GZ=400,ZZ=860,KZ=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},YZ=()=>{const{isSidebarOpen:o,isRightSidebarOpen:a,isBottomTerminalOpen:l,setRightSidebarOpen:i,setBottomTerminalOpen:c,activeMainTab:u,setIsMobile:m,isSessionSwitcherOpen:f,isSettingsDialogOpen:h,setSettingsDialogOpen:p,isMultiRunLauncherOpen:g,setMultiRunLauncherOpen:x,multiRunLauncherPrefillPrompt:b}=Ee(),{isMobile:v}=wn(),y=d.useMemo(()=>Rn(),[]),w=Ee(V=>V.sidebarWidth),C=Ee(V=>V.rightSidebarWidth),[N,S]=d.useState(null),k=Ca()??"",j=d.useMemo(()=>KZ(k),[k]),F=Ee(V=>{if(!j)return!1;const te=V.contextPanelByDirectory[j],U=te?.tabs??[],X=U.find($=>$.id===te?.activeTabId)??U[U.length-1];return!!(te?.isOpen&&X)}),A=Ee(V=>V.setSidebarOpen),M=d.useRef(!1),B=d.useRef(!1),E=d.useRef(!1),[I,P]=d.useState(!1),D=d.useRef(!1),L=I3(0),T=he.useRef(0),_=I3(0),z=he.useRef(0);he.useEffect(()=>{v&&(T.current=window.innerWidth*(F0/100),z.current=window.innerWidth*(F0/100))},[v]),he.useEffect(()=>{if(!v)return;const V=I?0:-T.current;ml(L,V,{type:"spring",stiffness:400,damping:35,mass:.8})},[I,v,L]),he.useEffect(()=>{if(!v)return;D.current=a;const V=a?0:z.current;ml(_,V,{type:"spring",stiffness:400,damping:35,mass:.8})},[v,a,_]),he.useEffect(()=>{v&&P(f)},[f,v]),he.useEffect(()=>{v&&(D.current=a)},[a,v]);const R=Sl(V=>V.checkForUpdates);d.useEffect(()=>{let $=!1,q=null;const ee=ve=>{const ge=Math.round(ve*1e3);return Math.max(3e5,Math.min(864e5,ge))},ce=ve=>{$||(q=window.setTimeout(async()=>{const ge=await R(),xe=typeof ge=="number"&&Number.isFinite(ge)?ee(ge):36e5;ce(xe)},ve))};return ce(3e3),()=>{$=!0,q!==null&&window.clearTimeout(q)}},[R]),d.useEffect(()=>{Ee.getState().isMobile!==v&&m(v)},[v,m]),d.useEffect(()=>{if(typeof window>"u")return;let V;const te=()=>{V!==void 0&&window.clearTimeout(V),V=window.setTimeout(()=>{Ee.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",te),()=>{window.removeEventListener("resize",te),V!==void 0&&window.clearTimeout(V)}},[]),d.useEffect(()=>{if(F){Ee.getState().isSidebarOpen&&(A(!1),E.current=!0);return}E.current&&(A(!0),E.current=!1)},[F,A]),d.useEffect(()=>{if(typeof window>"u")return;let V;const te=()=>{const X=Ee.getState(),$=window.innerWidth,q=window.innerHeight,ee=$<1140,ce=$>=1220;ee?X.isRightSidebarOpen&&(i(!1),M.current=!0):ce&&M.current&&(i(!0),M.current=!1);const ve=q<640,ge=q>=700;ve?X.isBottomTerminalOpen&&(c(!1),B.current=!0):ge&&B.current&&(c(!0),B.current=!1)},U=()=>{V!==void 0&&window.clearTimeout(V),V=window.setTimeout(()=>{te()},100)};return te(),window.addEventListener("resize",U),()=>{window.removeEventListener("resize",U),V!==void 0&&window.clearTimeout(V)}},[c,i]),d.useEffect(()=>{if(typeof window>"u")return;const V=Ee.subscribe((te,U)=>{const X=window.innerWidth,$=window.innerHeight,q=X>=1220,ee=$>=700;te.isRightSidebarOpen!==U.isRightSidebarOpen&&q&&(M.current=!1),te.isBottomTerminalOpen!==U.isBottomTerminalOpen&&ee&&(B.current=!1)});return()=>{V()}},[]),d.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const V=document.documentElement;let te=0,U=!1,X=0,$=null;const q=Ee.getState().setKeyboardOpen,ee=()=>{$&&($.style.setProperty("--oc-keyboard-avoid-offset","0px"),$.removeAttribute("data-keyboard-avoid-active"),$=null)},ce=le=>{if(!le)return null;const ae=le.getAttribute("data-keyboard-avoid-target-id");if(ae){const be=document.getElementById(ae);if(be instanceof HTMLElement)return be}const ue=le.closest("[data-keyboard-avoid]");if(ue)return ue.getAttribute("data-keyboard-avoid")==="none"?null:ue;if(le.classList.contains("overlay-scrollbar-container")){const be=le.parentElement;if(be instanceof HTMLElement)return be}return le},ve=()=>{te=0,U=!0,V.style.setProperty("--oc-keyboard-inset","0px"),q(!1)};let ge=0;const xe=()=>{const le=window.visualViewport,ae=le?Math.round(le.height):window.innerHeight,ue=le?Math.max(0,Math.round(le.offsetTop)):0;V.style.setProperty("--oc-visual-viewport-offset-top",`${ue}px`);const be=document.activeElement,oe=be?.tagName,ie=oe==="INPUT"||oe==="TEXTAREA"||oe==="SELECT"||!!be?.isContentEditable,pe=Math.round(V.clientHeight||window.innerHeight),me=ae+ue,Se=Math.max(0,pe-me),ye=Se>=(ie?120:180)?Se:0;if(U)ye===0&&(U=!1),te=0;else if(te===0)ye>0&&ie&&(te=ye);else{const we=!ie&&ae>X+6;ye===0?(te=0,q(!1)):we?ve():(ye>0&&ie||ye>te)&&(te=ye,q(!0))}V.style.setProperty("--oc-keyboard-inset",`${te}px`),X=ae;const _e=/iPad|iPhone|iPod/.test(navigator.userAgent)&&te>0?34:0;V.style.setProperty("--oc-keyboard-home-indicator",`${_e}px`);const de=ie?ce(be):null;if(!v||!de||!be)ee();else{de!==$&&(ee(),$=de);const we=ue+ae,Ce=be.getBoundingClientRect().bottom-we,ze=8,Ge=Math.max(te,ye),Le=Ce>ze&&Ge>0?Math.min(Ce,Ge):0,qe=$;qe&&(qe.style.setProperty("--oc-keyboard-avoid-offset",`${Le}px`),qe.setAttribute("data-keyboard-avoid-active","true"))}if(v&&ie){const we=document.scrollingElement;we&&we.scrollTop!==0&&(we.scrollTop=0),window.scrollY!==0&&window.scrollTo(0,0)}},ne=()=>{ge||(ge=requestAnimationFrame(()=>{ge=0,xe()}))};xe();const O=window.visualViewport;O?.addEventListener("resize",ne),O?.addEventListener("scroll",ne),window.addEventListener("resize",ne),window.addEventListener("orientationchange",ne);const H=le=>{if(!le)return!1;const ae=le.tagName;return ae==="INPUT"||ae==="TEXTAREA"||ae==="SELECT"||le.isContentEditable},K=le=>{const ae=le.target;H(ae)&&(U=!1),ne()};document.addEventListener("focusin",K,!0);const re=le=>{const ae=le.target;if(!H(ae))return;const ue=le.relatedTarget;H(ue)||window.requestAnimationFrame(()=>{if(H(document.activeElement))return;const be=window.visualViewport,oe=be?Math.round(be.height):window.innerHeight,Z=be?Math.max(0,Math.round(be.offsetTop)):0,ie=Math.round(V.clientHeight||window.innerHeight),pe=oe+Z;if(Math.max(0,ie-pe)>0){xe();return}ve(),xe()})};return document.addEventListener("focusout",re,!0),()=>{ge&&cancelAnimationFrame(ge),O?.removeEventListener("resize",ne),O?.removeEventListener("scroll",ne),window.removeEventListener("resize",ne),window.removeEventListener("orientationchange",ne),document.removeEventListener("focusin",K,!0),document.removeEventListener("focusout",re,!0),ee()}},[v]);const W=d.useMemo(()=>{const V=(()=>{switch(u){case"plan":return s.jsx(LZ,{});case"git":return s.jsx(uh,{});case"diff":return s.jsx(HZ,{});case"terminal":return s.jsx(fh,{});case"files":return s.jsx($Z,{});default:return null}})();return u!=="chat"?s.jsx(d.Suspense,{fallback:s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsx("div",{className:"animate-pulse",children:"Loading..."})}),children:V}):null},[u]),G=u==="chat",Y=d.useMemo(()=>Math.min(qZ,Math.max(WZ,w||Od)),[w]),J=d.useMemo(()=>Math.min(ZZ,Math.max(GZ,C||p8)),[C]);return s.jsx(WL,{children:s.jsxs("div",{className:Q("main-content-safe-area h-[100dvh]",v?"flex flex-col":"flex",y?"bg-transparent":"bg-background"),children:[s.jsx(Nq,{}),s.jsx(Aq,{}),s.jsx(Fq,{}),s.jsx(zZ,{}),v?s.jsxs($N,{value:{leftDrawerOpen:I,rightDrawerOpen:a,toggleLeftDrawer:()=>{a&&i(!1),P(!I)},toggleRightDrawer:()=>{I&&P(!1),i(!a)},leftDrawerX:L,rightDrawerX:_,leftDrawerWidth:T,rightDrawerWidth:z,setMobileLeftDrawerOpen:P,setRightSidebarOpen:i},children:[!h&&s.jsx(w4,{onToggleLeftDrawer:()=>{a&&i(!1),P(!I)},onToggleRightDrawer:()=>{I&&P(!1),i(!a)},leftDrawerOpen:I,rightDrawerOpen:a}),s.jsx(fa.button,{type:"button",initial:!1,animate:{opacity:I||a?1:0,pointerEvents:I||a?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{P(!1),i(!1)},"aria-label":"Close drawer"}),s.jsx(fa.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(T.current||window.innerWidth*.85),right:0},style:{width:`${F0}%`,x:L},onDragEnd:(V,te)=>{const U=T.current||window.innerWidth*.85,X=U*.3,$=500,q=L.get(),ee=te.offset.x<-X||te.velocity.x<-$,ce=te.offset.x>X||te.velocity.x>$;ee?(L.set(-U),P(!1)):ce?(L.set(0),P(!0)):q>-U/2?L.set(0):L.set(-U)},className:Q("fixed left-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-transparent","cursor-grab active:cursor-grabbing"),"aria-hidden":!I,children:s.jsx("div",{className:"h-full overflow-hidden flex bg-[var(--surface-background)] shadow-none drawer-safe-area",style:{backgroundImage:"linear-gradient(var(--surface-muted), var(--surface-muted))"},children:s.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col",children:s.jsx(An,{children:s.jsx(_2,{mobileVariant:!0})})})})}),s.jsx(fa.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:z.current||window.innerWidth*.85},style:{width:`${F0}%`,x:_},onDragEnd:(V,te)=>{const U=z.current||window.innerWidth*.85,X=U*.3,$=500,q=_.get(),ee=te.offset.x>X||te.velocity.x>$,ce=te.offset.x<-X||te.velocity.x<-$;ee?(_.set(U),i(!1)):ce?(_.set(0),i(!0)):q<U/2?_.set(0):_.set(U)},className:Q("fixed right-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-transparent","cursor-grab active:cursor-grabbing"),"aria-hidden":!a,children:s.jsx("div",{className:"h-full overflow-hidden flex flex-col bg-background shadow-none drawer-safe-area",children:s.jsx(An,{children:s.jsx(uh,{})})})}),s.jsx("div",{className:Q("flex flex-1 overflow-hidden relative",h&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative",children:[s.jsx("div",{className:Q("absolute inset-0",!G&&"invisible"),children:s.jsx(An,{children:s.jsx(wi,{})})}),W&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(An,{children:W})}),g&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(An,{children:s.jsx(cW,{initialPrompt:b,onCreated:()=>x(!1),onCancel:()=>x(!1)})})})]})}),h&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(An,{children:s.jsx(d.Suspense,{fallback:null,children:s.jsx(OZ,{onClose:()=>p(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:Q("absolute inset-0 flex overflow-hidden",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar"),children:[o?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:Q("pointer-events-none absolute top-0 z-0",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar"),style:{left:`${Y}px`,width:"var(--radius-md)",height:"var(--radius-md)",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))"}}),s.jsx("div",{"aria-hidden":!0,className:Q("pointer-events-none absolute bottom-0 z-0",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar"),style:{left:`${Y}px`,width:"var(--radius-md)",height:"var(--radius-md)",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))"}})]}):null,a?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:Q("pointer-events-none absolute top-0 z-0",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar"),style:{right:`${J}px`,width:"var(--radius-md)",height:"var(--radius-md)",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))",maskImage:"radial-gradient(circle at 0 100%, transparent calc(var(--radius-md) - 1px), black var(--radius-md))"}}),s.jsx("div",{"aria-hidden":!0,className:Q("pointer-events-none absolute bottom-0 z-0",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar"),style:{right:`${J}px`,width:"var(--radius-md)",height:"var(--radius-md)",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(var(--radius-md) - 1px), black var(--radius-md))",maskImage:"radial-gradient(circle at 0 0, transparent calc(var(--radius-md) - 1px), black var(--radius-md))"}})]}):null,s.jsx(_j,{isOpen:o,isMobile:v,className:"border-0",children:s.jsx(_2,{})}),s.jsxs("div",{className:Q("relative flex flex-1 min-w-0 flex-col overflow-hidden",y?"bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]":"bg-sidebar",o&&"border-l border-border/50 rounded-tl-md rounded-bl-md",a&&"border-r border-border/50 rounded-tr-md rounded-br-md"),"data-blur-bg":!0,style:y?{WebkitBackdropFilter:"blur(20px)",backdropFilter:"blur(20px)"}:void 0,children:[s.jsx(w4,{desktopRightSidebarActionsHost:N}),s.jsx("div",{className:Q("flex flex-1 min-h-0 overflow-hidden",o||G?"":"border-l border-border/50",a?"":"border-r border-border/50"),children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative",children:[s.jsx("div",{className:Q("absolute inset-0",!G&&"invisible"),children:s.jsx(An,{children:s.jsx(wi,{})})}),W&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(An,{children:W})})]}),s.jsx(kq,{})]})}),s.jsx(Sj,{isOpen:l,isMobile:v,children:s.jsx(An,{children:s.jsx(fh,{})})})]}),s.jsx(Ej,{isOpen:a,className:"border-0",onTopActionsHostChange:S,children:s.jsx(An,{children:s.jsx($W,{})})})]})}),s.jsx(d.Suspense,{fallback:null,children:s.jsx(VZ,{open:h,onOpenChange:p})}),s.jsx(d.Suspense,{fallback:null,children:s.jsx(UZ,{open:g,onOpenChange:x,initialPrompt:b})})]})]})})},XZ=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},QZ=550,JZ=1400,eK=280,tK=()=>{const t=ur(),e=d.useMemo(()=>(typeof window<"u"?window.__VSCODE_CONFIG__?.viewMode:null)==="editor"?"editor":"sidebar",[]),n=d.useMemo(()=>{const D=typeof window<"u"?window.__VSCODE_CONFIG__?.initialSessionId:null;return typeof D=="string"&&D.trim().length>0?D.trim():null},[]),r=d.useRef(!1),o=d.useMemo(()=>{try{return!!Ze.getState().newSessionDraft?.open}catch{return!1}},[]),[a,l]=d.useState(()=>o?"chat":"sessions"),[i,c]=d.useState(0),u=d.useRef(null),m=Ze(D=>D.currentSessionId),f=Ze(D=>D.sessions),h=d.useMemo(()=>m?f.find(D=>D.id===m)?.title||"Session":null,[m,f]),p=Ze(D=>!!D.newSessionDraft?.open),g=Ze(D=>D.isSyncing),x=Ze(D=>{const L=D.sessionStatus;if(!L||L.size===0)return!1;for(const T of L.values())if(T?.type==="busy"||T?.type==="retry")return!0;return!1}),b=Ze(D=>D.openNewSessionDraft),[v,y]=d.useState(()=>(typeof window<"u"?window.__ARCHCODER_CONNECTION__?.status||window.__OPENCHAMBER_CONNECTION__?.status:"connecting")||"connecting"),w=rs(D=>D.isInitialized),C=rs(D=>D.initializeApp),N=Ze(D=>D.loadSessions),S=Ze(D=>D.loadMessages),k=Ze(D=>D.messages),[j,F]=d.useState(()=>w),[A,M]=d.useState(!1),B=d.useRef(0);d.useEffect(()=>{m&&l("chat")},[m]),d.useEffect(()=>{const D=t.vscode;D&&D.executeCommand("archcoder.setActiveSession",m,h)},[h,m,t.vscode]),d.useEffect(()=>{if(e==="editor"||a!=="chat"||m||p||g||x)return;const D=window.setTimeout(()=>{const L=Ze.getState(),T=!L.currentSessionId,_=!L.newSessionDraft?.open,z=L.isSyncing,R=(()=>{const W=L.sessionStatus;if(!W||W.size===0)return!1;for(const G of W.values())if(G?.type==="busy"||G?.type==="retry")return!0;return!1})();T&&_&&!z&&!R&&l("sessions")},900);return()=>{window.clearTimeout(D)}},[m,p,a,e,g,x]);const E=d.useCallback(()=>{l("sessions")},[]);d.useEffect(()=>{const D=typeof window<"u"?window.__ARCHCODER_CONNECTION__?.status||window.__OPENCHAMBER_CONNECTION__?.status:void 0;(D==="connected"||D==="connecting"||D==="error"||D==="disconnected")&&y(D);const L=T=>{const z=T.detail?.status;(z==="connected"||z==="connecting"||z==="error"||z==="disconnected")&&y(z)};return window.addEventListener("archcoder:connection-status",L),()=>window.removeEventListener("archcoder:connection-status",L)},[]),d.useEffect(()=>{const D=L=>{const _=L.detail?.view;_==="settings"?l("settings"):_==="chat"?l("chat"):_==="sessions"&&l("sessions")};return window.addEventListener("archcoder:navigate",D),()=>window.removeEventListener("archcoder:navigate",D)},[]),d.useEffect(()=>{(async()=>{if(A||j||v!=="connected")return;const L=Date.now();if(!(L-B.current<750)){B.current=L,M(!0);try{const T=(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem("archcoder_stream_debug")==="1"}catch{return!1}})();T&&console.log("[ArchCoder][VSCode][bootstrap] attempt",{configInitialized:w}),w||await C();const _=rs.getState();_.isConnected&&(_.providers.length===0&&await _.loadProviders(),_.agents.length===0&&await _.loadAgents());const z=rs.getState();if(!z.isInitialized||!z.isConnected||z.providers.length===0||z.agents.length===0)return;await N();const R=Ze.getState().error;if(T&&console.log("[OpenChamber][VSCode][bootstrap] post-load",{providers:z.providers.length,agents:z.agents.length,sessions:Ze.getState().sessions.length,sessionsError:R}),typeof R=="string"&&R.length>0)return;F(!0)}catch{}finally{M(!1)}}})()},[v,w,j,C,A,N]),d.useEffect(()=>{if(e==="editor"&&!r.current&&!(!j||v!=="connected")){if(!n){r.current=!0,b();return}f.some(D=>D.id===n)&&(r.current=!0,Ze.getState().setCurrentSession(n))}},[v,j,n,b,f,e]),d.useEffect(()=>{(async()=>{if(!(!j||v!=="connected"||a!=="chat"||p||!m||k.has(m)))try{await S(m)}catch{}})()},[v,m,a,j,S,k,p]),d.useEffect(()=>{const D=u.current;if(!D)return;const L=new ResizeObserver(T=>{for(const _ of T)c(_.contentRect.width)});return L.observe(D),c(D.clientWidth),()=>L.disconnect()},[]);const I=i>0&&i<QZ,P=i>=JZ;return d.useEffect(()=>{P&&a==="sessions"&&e==="sidebar"&&l("chat")},[P,a,e]),s.jsx("div",{ref:u,className:"h-full w-full bg-background text-foreground flex flex-col",children:e==="editor"?s.jsxs("div",{className:"flex flex-col h-full",children:[s.jsx(B0,{title:f.find(D=>D.id===m)?.title||"Chat",showMcp:!0,showContextUsage:!0}),s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(An,{children:s.jsx(wi,{})})})]}):a==="settings"?s.jsx(U7,{onClose:()=>l(P?"chat":"sessions"),forceMobile:I}):P?s.jsxs("div",{className:"flex h-full",children:[s.jsx("div",{className:"h-full border-r border-border overflow-hidden flex-shrink-0",style:{width:eK},children:s.jsx(_2,{mobileVariant:!0,allowReselect:!0,hideDirectoryControls:!0,showOnlyMainWorkspace:!0})}),s.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[s.jsx(B0,{title:p&&!m?"New session":f.find(D=>D.id===m)?.title||"Chat",showMcp:!0,showContextUsage:!0}),s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(An,{children:s.jsx(wi,{})})})]})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:Q("flex flex-col h-full",a!=="sessions"&&"hidden"),children:[s.jsx(B0,{title:"Sessions"}),s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(_2,{mobileVariant:!0,allowReselect:!0,onSessionSelected:()=>l("chat"),hideDirectoryControls:!0,showOnlyMainWorkspace:!0})})]}),s.jsxs("div",{className:Q("flex flex-col h-full",a!=="chat"&&"hidden"),children:[s.jsx(B0,{title:p&&!m?"New session":f.find(D=>D.id===m)?.title||"Chat",showBack:!0,onBack:E,showMcp:!0,showContextUsage:!0,showRateLimits:!0}),s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(An,{children:s.jsx(wi,{})})})]})]})})},B0=t=>{const e=Fe.c(46),{title:n,showBack:r,onBack:o,onNewSession:a,onSettings:l,onAgentManager:i,showMcp:c,showContextUsage:u,showRateLimits:m}=t,{getCurrentModel:f}=rs(),h=Ze(sK),p=Ws(nK),g=Ws(rK),x=Ws(oK),b=Ws(aK),v=Ws(lK),y=Ws(iK),w=Ws(cK),C=Ws(dK);zu();let N,S;e[0]!==w?(N=()=>{w()},S=[w],e[0]=w,e[1]=N,e[2]=S):(N=e[1],S=e[2]),d.useEffect(N,S);let k;if(e[3]!==h||e[4]!==f){const G=f(),Y=G?.limit&&typeof G.limit=="object"?G.limit:null,J=typeof Y?.context=="number"?Y.context:0,V=typeof Y?.output=="number"?Y.output:0;k=h(J,V),e[3]=h,e[4]=f,e[5]=k}else k=e[5];const j=k;let F;if(e[6]!==y||e[7]!==p){F=[];for(const G of Oo){if(!y.includes(G.id))continue;const Y=p.find(U=>U.providerId===G.id),J=Y?.usage?.windows??{},V=Object.entries(J),te=Y&&!Y.ok&&Y.configured?Y.error:void 0;(V.length>0||te)&&F.push({providerId:G.id,providerName:G.name,entries:V,error:te})}e[6]=y,e[7]=p,e[8]=F}else F=e[8];const A=F,M=A.length>0;let B;e[9]!==C?(B=async G=>{C(G);try{await ln({usageDisplayMode:G})}catch(Y){console.warn("Failed to update usage display mode:",Y)}},e[9]=C,e[10]=B):B=e[10];const E=B;let I;e[11]!==o||e[12]!==r?(I=r&&o&&s.jsx("button",{onClick:o,className:"inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Back to sessions",children:s.jsx(Su,{className:"h-5 w-5"})}),e[11]=o,e[12]=r,e[13]=I):I=e[13];let P;e[14]!==n?(P=s.jsx("h1",{className:"text-sm font-medium truncate flex-1",title:n,children:n}),e[14]=n,e[15]=P):P=e[15];let D;e[16]!==a?(D=a&&s.jsx("button",{onClick:a,className:"inline-flex h-9 w-9 items-center justify-center p-2 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"New session",children:s.jsx(Qs,{className:"h-5 w-5"})}),e[16]=a,e[17]=D):D=e[17];let L;e[18]!==i?(L=i&&s.jsx("button",{onClick:i,className:"inline-flex h-9 w-9 items-center justify-center p-2 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Open Agent Manager",children:s.jsx(zo,{className:"h-5 w-5"})}),e[18]=i,e[19]=L):L=e[19];let T;e[20]!==c?(T=c&&s.jsx(qy,{headerIconButtonClass:"inline-flex h-9 w-9 items-center justify-center p-2 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"}),e[20]=c,e[21]=T):T=e[21];let _;e[22]!==g||e[23]!==E||e[24]!==M||e[25]!==x||e[26]!==v||e[27]!==b||e[28]!==p||e[29]!==A||e[30]!==m?(_=m&&s.jsxs(qs,{onOpenChange:G=>{G&&p.length===0&&g()},children:[s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":"Rate limits",className:"inline-flex h-9 w-9 items-center justify-center p-2 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:x,children:s.jsx(wd,{className:"h-5 w-5"})})}),s.jsxs(Ys,{align:"end",className:"w-80 max-h-[70vh] overflow-y-auto overflow-x-hidden bg-[var(--surface-elevated)] p-0",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)]",children:s.jsxs(sa,{className:"flex items-center justify-between gap-3 typography-ui-header font-semibold text-foreground",children:[s.jsx("span",{children:"Rate limits"}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("div",{className:"flex items-center rounded-md border border-[var(--interactive-border)] p-0.5",children:[s.jsx("button",{type:"button",className:`px-2 py-0.5 rounded-sm typography-micro text-[10px] transition-colors ${v==="usage"?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{E("usage")},"aria-label":"Show used quota",children:"Used"}),s.jsx("button",{type:"button",className:`px-2 py-0.5 rounded-sm typography-micro text-[10px] transition-colors ${v==="remaining"?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{E("remaining")},"aria-label":"Show remaining quota",children:"Remaining"})]}),s.jsx("button",{type:"button",className:"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:()=>g(),disabled:x,"aria-label":"Refresh rate limits",children:s.jsx(Qn,{className:"h-4 w-4"})})]})]})}),s.jsxs("div",{className:"border-b border-[var(--interactive-border)] px-2 pb-2 typography-micro text-muted-foreground text-[10px]",children:["Last updated ",XZ(b)]}),!M&&s.jsx(Jt,{className:"cursor-default",onSelect:uK,children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:"No rate limits available."})}),A.map((G,Y)=>s.jsxs(d.Fragment,{children:[s.jsxs(sa,{className:"flex items-center gap-2 bg-[var(--surface-elevated)] typography-ui-label text-foreground",children:[s.jsx(Mn,{providerId:G.providerId,className:"h-4 w-4"}),G.providerName]}),G.entries.length===0?s.jsx(Jt,{className:"cursor-default",onSelect:fK,children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:G.error??"No rate limits reported."})},`${G.providerId}-empty`):G.entries.map(J=>{const[V,te]=J,U=v==="remaining"?te.remainingPercent:te.usedPercent,X=ci(te.usedPercent,te.resetAt,te.windowSeconds,V),$=X?.dailyAllocationPercent!=null?v==="remaining"?100-Mo(X.elapsedRatio):Mo(X.elapsedRatio):null;return s.jsx(Jt,{className:"cursor-default items-start",onSelect:mK,children:s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[s.jsxs("span",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:i2(V)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Ao(U)==="-"?"":Ao(U)})]}),s.jsx(di,{percent:U,tonePercent:te.usedPercent,className:"h-1",expectedMarkerPercent:$}),X&&s.jsx("div",{className:"mt-0.5",children:s.jsx(ui,{paceInfo:X,compact:!0})}),s.jsx("span",{className:"flex items-center justify-between typography-micro text-muted-foreground text-[10px]",children:s.jsx("span",{children:te.resetAfterFormatted??te.resetAtFormatted??""})})]})},`${G.providerId}-${V}`)}),Y<A.length-1&&s.jsx(Zn,{})]},G.providerId))]})]}),e[22]=g,e[23]=E,e[24]=M,e[25]=x,e[26]=v,e[27]=b,e[28]=p,e[29]=A,e[30]=m,e[31]=_):_=e[31];let z;e[32]!==l?(z=l&&s.jsx("button",{onClick:l,className:"inline-flex h-9 w-9 items-center justify-center p-2 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Settings",children:s.jsx(xa,{className:"h-5 w-5"})}),e[32]=l,e[33]=z):z=e[33];let R;e[34]!==j||e[35]!==u?(R=u&&j&&j.totalTokens>0&&s.jsx(G6,{totalTokens:j.totalTokens,percentage:j.percentage,contextLimit:j.contextLimit,outputLimit:j.outputLimit??0,size:"compact"}),e[34]=j,e[35]=u,e[36]=R):R=e[36];let W;return e[37]!==_||e[38]!==z||e[39]!==R||e[40]!==I||e[41]!==P||e[42]!==D||e[43]!==L||e[44]!==T?(W=s.jsxs("div",{className:"flex items-center gap-1.5 pl-1 pr-2 py-1 border-b border-border bg-background shrink-0",children:[I,P,D,L,T,_,z,R]}),e[37]=_,e[38]=z,e[39]=R,e[40]=I,e[41]=P,e[42]=D,e[43]=L,e[44]=T,e[45]=W):W=e[45],W};function sK(t){return t.getContextUsage}function nK(t){return t.results}function rK(t){return t.fetchAllQuotas}function oK(t){return t.isLoading}function aK(t){return t.lastUpdated}function lK(t){return t.displayMode}function iK(t){return t.dropdownProviderIds}function cK(t){return t.loadSettings}function dK(t){return t.setDisplayMode}function uK(t){return t.preventDefault()}function fK(t){return t.preventDefault()}function mK(t){return t.preventDefault()}const _0=t=>{const e=vs.getState(),n=e.activeProjectId,r=n?e.projects.find(o=>o.id===n)?.path:void 0;return typeof r=="string"&&r.trim().length>0?r:t?Un(t):null},Un=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},mh=(t,e)=>{const n=Un(t),r=Un(e);if(!n||!r)return!1;if(n===r)return!0;const o=r==="/"?"/":`${r}/`;return n.startsWith(o)},tg=async(t,e)=>{const n=Un(e);if(!n)return n;try{const r=await t.path.get({directory:n});return Un(r.data?.directory??"")||n}catch{return n}},sg=async(t,e)=>{const n=Un(e);if(!n)return[];const r=await tg(t,n),o=l=>l.filter(i=>{const c=Un(i.directory??"");return c?mh(c,n)||r!==n&&mh(c,r):!1}),a=async l=>{const i=await t.session.list({directory:l});return Array.isArray(i.data)?i.data:[]};try{const l=o(await a(n));if(l.length>0)return l}catch{}if(r&&r!==n)try{const l=o(await a(r));if(l.length>0)return l}catch{}try{const l=await t.session.list(void 0),i=Array.isArray(l.data)?l.data:[];return o(i)}catch{return[]}},hK=async(t,e)=>{const n=new Map;t.sessions.forEach(o=>{o.worktreeMetadata&&n.set(Un(o.path),o.worktreeMetadata)});const r=Array.from(new Set(t.sessions.map(o=>Un(o.path)))).filter(Boolean).filter(o=>!n.has(o));if(r.length===0)return n;try{const o=await E1({id:`path:${e}`,path:e}),a=new Map(o.map(l=>[Un(l.path),l]));r.forEach(l=>{const i=a.get(l);i&&n.set(l,i)})}catch{}return n},pK=async t=>{const{apiClient:e,group:n,projectDirectory:r,worktreePaths:o}=t,a=await hK(n,r),l=Ze.getState(),i=Array.from(new Set(o.map(h=>Un(h)).filter(Boolean))),c=5;let u=0;const m=[],f=async()=>{for(;u<i.length;){const h=i[u];u+=1;const p=n.sessions.filter(y=>Un(y.path)===h).map(y=>y.id),g=l.getSessionsByDirectory(h),x=Array.isArray(g)?g.map(y=>y.id):[];let b=[];if(x.length===0)try{b=(await sg(e,h)).map(w=>w.id)}catch{b=[]}const v=Array.from(new Set([...x,...b,...p].filter(Boolean)));m.push({worktreePath:h,sessionIds:v,metadata:a.get(h)})}};return await Promise.all(Array.from({length:Math.min(c,i.length)},f)),m},xd=async t=>{const e=En.getApiClient(),n=await pK({apiClient:e,group:t.group,projectDirectory:t.projectDirectory,worktreePaths:t.worktreePaths}),r=Ze.getState(),o=new Set;return n.forEach(({worktreePath:a,sessionIds:l,metadata:i})=>{l.forEach(c=>{o.add(c),i&&(r.setWorktreeMetadata(c,i),r.setSessionDirectory(c,a))})}),o.size===0?{failedIds:[]}:r.deleteSessions(Array.from(o),{archiveWorktree:!0,silent:!0})};function gK(t){if(!t)return null;const e=t.split("/");if(e.length<3)return null;const n=e[0];if(!n||n.includes(" "))return null;const r=e[1];if(!r)return null;const o=e[e.length-1],a=parseInt(o,10),l=e.length>=4&&!isNaN(a)&&String(a)===o,i=l?e.slice(2,-1):e.slice(2);if(i.length===0)return null;const c=i.join("/");return{groupSlug:n,provider:r,model:c,index:l?a:1}}const Wa=Dr()(wa((t,e)=>({groups:[],selectedGroupName:null,selectedSessionId:null,isLoading:!1,error:null,loadGroups:async()=>{const n=dn.getState().currentDirectory,r=_0(n);if(!r){t({groups:[],isLoading:!1,error:"No project directory selected"});return}const o=Un(r),i={id:vs.getState().projects.find(u=>Un(u.path)===o)?.id??`path:${o}`,path:o},c=e().groups;t({isLoading:!0,error:null});try{const u=En.getApiClient(),m=await tg(u,o),f=m&&m!==o?{...i,path:m}:null,h=await E1(i).catch(()=>[]),p=f?await E1(f).catch(()=>[]):[],g=new Set,x=new Map;[...h,...p].forEach(k=>{if(k?.path){const j=Un(k.path);g.add(j),x.has(j)||x.set(j,k)}});const b=async()=>{try{const j=await u.session.list({directory:o}),F=Array.isArray(j.data)?j.data:[];if(F.some(A=>{const M=Un(A.directory??"");return M?g.has(M):!1}))return F}catch{}const k=await u.session.list(void 0);return Array.isArray(k.data)?k.data:[]},v=async k=>{const j=new Map,F=5;let A=0;const M=async()=>{for(;A<k.length;){const B=k[A];A+=1;const E=Un(B);if(E)try{(await sg(u,E)).forEach(P=>j.set(P.id,P))}catch(I){console.debug("Failed to fetch sessions from worktree:",E,I)}}};return await Promise.all(Array.from({length:Math.min(F,k.length)},M)),Array.from(j.values())};let w=(await b()).filter(k=>{const j=Un(k.directory??"");return j?g.has(j):!1});if(w.length===0){const k=new Set;g.forEach(j=>k.add(j)),k.size>0&&(w=await v(Array.from(k)))}const C=new Map;for(const k of w){const j=k.time?.updated??0;C.set(k.id,typeof j=="number"?j:0)}const N=new Map;for(const k of w){const j=gK(k.title);if(!j)continue;const F=Un(k.directory),A=x.get(F),M={id:k.id,path:F,providerId:j.provider,modelId:j.model,instanceNumber:j.index,branch:A?.branch??"",displayLabel:`${j.provider}/${j.model}`,worktreeMetadata:A},B=N.get(j.groupSlug);B?B.push(M):N.set(j.groupSlug,[M])}const S=Array.from(N.entries()).map(([k,j])=>{const F=j.reduce((A,M)=>{const B=C.get(M.id)??0;return Math.max(A,B)},0);return{name:k,sessions:j.sort((A,M)=>{const B=A.providerId.localeCompare(M.providerId);if(B!==0)return B;const E=A.modelId.localeCompare(M.modelId);return E!==0?E:A.instanceNumber-M.instanceNumber}),lastActive:F||Date.now(),sessionCount:j.length}});S.sort((k,j)=>k.name.localeCompare(j.name)),t({groups:S,isLoading:!1,error:null})}catch(u){console.error("Failed to load agent groups:",u),t({groups:c.length>0?c:[],isLoading:!1,error:u instanceof Error?u.message:"Failed to load agent groups"})}},selectGroup:n=>{const{groups:r}=e(),o=r.find(a=>a.name===n);t({selectedGroupName:n,selectedSessionId:o?.sessions[0]?.id??null})},selectSession:n=>{t({selectedSessionId:n})},deleteGroup:async n=>{const r=e().groups.find(l=>l.name===n);if(!r)return!1;const o=dn.getState().currentDirectory,a=_0(o);if(!a)return t({error:"No project directory selected"}),!1;t({isLoading:!0,error:null});try{const{failedIds:l}=await xd({group:r,projectDirectory:Un(a),worktreePaths:r.sessions.map(i=>i.path)});return l.length>0&&t({error:"Failed to delete some sessions"}),e().selectedGroupName===n&&t({selectedGroupName:null,selectedSessionId:null}),await e().loadGroups(),l.length===0}catch(l){return t({error:l instanceof Error?l.message:"Failed to delete group"}),!1}finally{t({isLoading:!1})}},deleteGroupWorktree:async(n,r)=>{const o=e().groups.find(c=>c.name===n);if(!o)return!1;const a=Un(r);if(!a)return!1;const l=dn.getState().currentDirectory,i=_0(l);if(!i)return t({error:"No project directory selected"}),!1;t({isLoading:!0,error:null});try{const{failedIds:c}=await xd({group:o,projectDirectory:Un(i),worktreePaths:[a]});c.length>0&&t({error:"Failed to delete some sessions"}),await e().loadGroups();const u=e().groups.find(m=>m.name===n);if(!u)return e().selectedGroupName===n&&t({selectedGroupName:null,selectedSessionId:null}),c.length===0;if(e().selectedGroupName===n){const m=e().selectedSessionId,f=new Set(u.sessions.map(h=>h.id));(!m||!f.has(m))&&t({selectedSessionId:u.sessions[0]?.id??null})}return c.length===0}catch(c){return t({error:c instanceof Error?c.message:"Failed to delete worktree"}),!1}finally{t({isLoading:!1})}},keepOnlyGroupWorktree:async(n,r)=>{const o=e().groups.find(m=>m.name===n);if(!o)return!1;const a=Un(r);if(!a)return!1;const i=Array.from(new Set(o.sessions.map(m=>Un(m.path)).filter(Boolean))).filter(m=>m!==a);if(i.length===0)return!0;const c=dn.getState().currentDirectory,u=_0(c);if(!u)return t({error:"No project directory selected"}),!1;t({isLoading:!0,error:null});try{const{failedIds:m}=await xd({group:o,projectDirectory:Un(u),worktreePaths:i});if(m.length>0&&t({error:"Failed to delete some sessions"}),await e().loadGroups(),e().selectedGroupName===n){const f=e().groups.find(p=>p.name===n),h=f?.sessions.find(p=>Un(p.path)===a)??f?.sessions[0]??null;t({selectedSessionId:h?.id??null})}return m.length===0}catch(m){return t({error:m instanceof Error?m.message:"Failed to remove other worktrees"}),!1}finally{t({isLoading:!1})}},getSelectedGroup:()=>{const{groups:n,selectedGroupName:r}=e();return r?n.find(o=>o.name===r)??null:null},getSelectedSession:()=>{const{selectedSessionId:n}=e(),r=e().getSelectedGroup();return!r||!n?null:r.sessions.find(o=>o.id===n)??null},clearError:()=>{t({error:null})}}),{name:"agent-groups-store"})),xK=t=>{const n=Date.now()-t,r=Math.floor(n/(60*1e3)),o=Math.floor(n/(3600*1e3)),a=Math.floor(n/(1440*60*1e3));return r<1?"now":r<60?`${r}m`:o<24?`${o}h`:`${a}d`},bK=t=>{const e=Fe.c(62),{group:n,isSelected:r,onSelect:o}=t,[a,l]=d.useState(!1),[i,c]=d.useState(!1),[u,m]=d.useState(!1),f=Wa(yK);let h;e[0]!==f||e[1]!==n.name||e[2]!==u?(h=async()=>{if(u)return;if(m(!0),fe.info(`Deleting "${n.name}"...`),await f(n.name))fe.success(`Deleted "${n.name}"`);else{const U=Wa.getState().error;fe.error(U||`Failed to delete "${n.name}"`)}m(!1),c(!1)},e[0]=f,e[1]=n.name,e[2]=u,e[3]=h):h=e[3];const p=h,g=r?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[4]!==g?(x=Q("group relative flex items-center rounded-md px-1.5 py-1.5 cursor-pointer",g),e[4]=g,e[5]=x):x=e[5];let b;e[6]!==n.name?(b=s.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:n.name}),e[6]=n.name,e[7]=b):b=e[7];let v;e[8]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(on,{className:"h-3 w-3"}),e[8]=v):v=e[8];const y=n.sessionCount!==1?"s":"";let w;e[9]!==n.sessionCount||e[10]!==y?(w=s.jsxs("span",{className:"typography-micro text-muted-foreground/60 flex items-center gap-1",children:[v,n.sessionCount," model",y]}),e[9]=n.sessionCount,e[10]=y,e[11]=w):w=e[11];let C;e[12]!==n.lastActive?(C=xK(n.lastActive),e[12]=n.lastActive,e[13]=C):C=e[13];let N;e[14]!==C?(N=s.jsx("span",{className:"typography-micro text-muted-foreground/60",children:C}),e[14]=C,e[15]=N):N=e[15];let S;e[16]!==w||e[17]!==N?(S=s.jsxs("div",{className:"flex items-center gap-2",children:[w,N]}),e[16]=w,e[17]=N,e[18]=S):S=e[18];let k;e[19]!==S||e[20]!==b?(k=s.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 flex-col gap-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[b,S]}),e[19]=S,e[20]=b,e[21]=k):k=e[21];const j=a&&"opacity-100";let F;e[22]!==j?(F=Q("inline-flex h-3.5 w-[18px] items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","opacity-0 group-hover:opacity-100",j),e[22]=j,e[23]=F):F=e[23];let A;e[24]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(Qr,{className:"h-3.5 w-3.5"}),e[24]=A):A=e[24];let M;e[25]!==F?(M=s.jsx(Gs,{asChild:!0,children:s.jsx("button",{type:"button",className:F,"aria-label":"Group menu",onClick:wK,children:A})}),e[25]=F,e[26]=M):M=e[26];let B;e[27]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(Ys,{align:"end",className:"min-w-[140px]",children:s.jsx(Jt,{variant:"destructive",onSelect:te=>{te.stopPropagation(),l(!1),c(!0)},children:"Delete"})}),e[27]=B):B=e[27];let E;e[28]!==a||e[29]!==M?(E=s.jsx("div",{className:"flex items-center gap-1.5 self-stretch",children:s.jsxs(qs,{open:a,onOpenChange:l,children:[M,B]})}),e[28]=a,e[29]=M,e[30]=E):E=e[30];let I;e[31]!==k||e[32]!==E?(I=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[k,E]}),e[31]=k,e[32]=E,e[33]=I):I=e[33];let P;e[34]!==o||e[35]!==I||e[36]!==x?(P=s.jsx("div",{className:x,onClick:o,children:I}),e[34]=o,e[35]=I,e[36]=x,e[37]=P):P=e[37];let D;e[38]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(Us,{children:"Delete agent group"}),e[38]=D):D=e[38];let L;e[39]!==n.name?(L=s.jsxs(Zs,{children:[D,s.jsxs(sn,{children:["Delete ",s.jsx("span",{className:"text-foreground font-medium",children:n.name}),"? This removes all worktrees and sessions in this group."]})]}),e[39]=n.name,e[40]=L):L=e[40];let T;e[41]===Symbol.for("react.memo_cache_sentinel")?(T=()=>c(!1),e[41]=T):T=e[41];let _;e[42]!==u?(_=s.jsx(Be,{variant:"outline",onClick:T,disabled:u,children:"Cancel"}),e[42]=u,e[43]=_):_=e[43];let z;e[44]!==p?(z=()=>{p()},e[44]=p,e[45]=z):z=e[45];const R=u?"Deleting…":"Delete";let W;e[46]!==u||e[47]!==z||e[48]!==R?(W=s.jsx(Be,{variant:"destructive",onClick:z,disabled:u,children:R}),e[46]=u,e[47]=z,e[48]=R,e[49]=W):W=e[49];let G;e[50]!==_||e[51]!==W?(G=s.jsxs(yn,{children:[_,W]}),e[50]=_,e[51]=W,e[52]=G):G=e[52];let Y;e[53]!==L||e[54]!==G?(Y=s.jsxs(Vs,{className:"max-w-md",keyboardAvoid:!0,children:[L,G]}),e[53]=L,e[54]=G,e[55]=Y):Y=e[55];let J;e[56]!==i||e[57]!==Y?(J=s.jsx(Os,{open:i,onOpenChange:c,children:Y}),e[56]=i,e[57]=Y,e[58]=J):J=e[58];let V;return e[59]!==P||e[60]!==J?(V=s.jsxs(s.Fragment,{children:[P,J]}),e[59]=P,e[60]=J,e[61]=V):V=e[61],V},vK=t=>{const e=Fe.c(54),{className:n,selectedGroupName:r,onGroupSelect:o,onNewAgent:a}=t,[l,i]=d.useState(""),[c,u]=d.useState(!1),{groups:m,isLoading:f,loadGroups:h}=Wa(),p=dn(jK);let g,x;e[0]!==p||e[1]!==h?(g=()=>{p&&h()},x=[p,h],e[0]=p,e[1]=h,e[2]=g,e[3]=x):(g=e[2],x=e[3]),d.useEffect(g,x);let b;e:{if(!l.trim()){b=m;break e}let W;if(e[4]!==m||e[5]!==l){const G=l.toLowerCase();W=m.filter(Y=>Y.name.toLowerCase().includes(G)),e[4]=m,e[5]=l,e[6]=W}else W=e[6];b=W}const v=b;let y;e[7]!==v||e[8]!==c?(y=c?v:v.slice(0,5),e[7]=v,e[8]=c,e[9]=y):y=e[9];const w=y,C=v.length-5;let N;e[10]!==n?(N=Q("flex h-full flex-col text-foreground border-r border-border/30",n),e[10]=n,e[11]=N):N=e[11];let S;e[12]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(xr,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e[12]=S):S=e[12];let k;e[13]===Symbol.for("react.memo_cache_sentinel")?(k=W=>i(W.target.value),e[13]=k):k=e[13];let j;e[14]!==l?(j=s.jsx("div",{className:"px-2.5 pt-3 pb-2",children:s.jsxs("div",{className:"relative",children:[S,s.jsx(Xt,{value:l,onChange:k,placeholder:"Search Agent Groups...",className:"pl-8 h-8 rounded-lg border-border/40 bg-background/50 typography-meta"})]})}),e[14]=l,e[15]=j):j=e[15];let F,A;e[16]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(Qs,{className:"h-4 w-4"}),F=s.jsx("span",{className:"typography-ui-label",children:"New Agent Group"}),e[16]=F,e[17]=A):(F=e[16],A=e[17]);let M;e[18]!==a?(M=s.jsx("div",{className:"px-2.5 pb-2",children:s.jsxs(Be,{variant:"outline",className:"w-full justify-start gap-2 h-8",onClick:a,children:[A,F]})}),e[18]=a,e[19]=M):M=e[19];let B,E;e[20]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(Ds,{className:"h-4 w-4 text-muted-foreground"}),E=s.jsx("span",{className:"typography-micro font-medium text-muted-foreground uppercase tracking-wider",children:"Agent Groups"}),e[20]=B,e[21]=E):(B=e[20],E=e[21]);let I;e[22]!==f?(I=f&&s.jsx("span",{className:"typography-micro text-muted-foreground/50 ml-auto",children:"Loading..."}),e[22]=f,e[23]=I):I=e[23];let P;e[24]!==I?(P=s.jsxs("div",{className:"px-2.5 py-1.5 flex items-center gap-1",children:[B,E,I]}),e[24]=I,e[25]=P):P=e[25];let D;if(e[26]!==o||e[27]!==r||e[28]!==w){let W;e[30]!==o||e[31]!==r?(W=G=>s.jsx(bK,{group:G,isSelected:r===G.name,onSelect:()=>o?.(G.name)},G.name),e[30]=o,e[31]=r,e[32]=W):W=e[32],D=w.map(W),e[26]=o,e[27]=r,e[28]=w,e[29]=D}else D=e[29];let L;e[33]!==C||e[34]!==c?(L=!c&&C>0&&s.jsxs("button",{type:"button",onClick:()=>u(!0),className:"mt-1 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left typography-micro text-muted-foreground/70 hover:text-foreground hover:underline",children:["... More (",C,")"]}),e[33]=C,e[34]=c,e[35]=L):L=e[35];let T;e[36]!==v.length||e[37]!==c?(T=c&&v.length>5&&s.jsx("button",{type:"button",onClick:()=>u(!1),className:"mt-1 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left typography-micro text-muted-foreground/70 hover:text-foreground hover:underline",children:"Show less"}),e[36]=v.length,e[37]=c,e[38]=T):T=e[38];let _;e[39]!==v.length||e[40]!==f||e[41]!==l?(_=!f&&v.length===0&&s.jsxs("div",{className:"py-4 text-center",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:l.trim()?"No groups found":"No agent groups yet"}),!l.trim()&&s.jsx("p",{className:"typography-micro text-muted-foreground/60 mt-1",children:"Create a new agent group to get started"})]}),e[39]=v.length,e[40]=f,e[41]=l,e[42]=_):_=e[42];let z;e[43]!==D||e[44]!==L||e[45]!==T||e[46]!==_?(z=s.jsxs(ks,{outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-2.5 pb-2",children:[D,L,T,_]}),e[43]=D,e[44]=L,e[45]=T,e[46]=_,e[47]=z):z=e[47];let R;return e[48]!==M||e[49]!==P||e[50]!==z||e[51]!==N||e[52]!==j?(R=s.jsxs("div",{className:N,children:[j,M,P,z]}),e[48]=M,e[49]=P,e[50]=z,e[51]=N,e[52]=j,e[53]=R):R=e[53],R};function yK(t){return t.deleteGroup}function wK(t){return t.stopPropagation()}function jK(t){return t.currentDirectory}const kK=10*1024*1024,NK=5,SK=({className:t,onCreateGroup:e,isCreating:n=!1})=>{const[r,o]=d.useState(""),[a,l]=d.useState(""),[i,c]=d.useState([]),[u,m]=d.useState(""),[f,h]=d.useState(""),[p,g]=d.useState([]),[x,b]=d.useState(!1),[v,y]=d.useState([]),[w,C]=d.useState(!1),[N,S]=d.useState(!1),k=d.useRef(null),j=d.useRef(null),{currentTheme:F}=qn(),A=dn(te=>te.currentDirectory??null),{isGitRepository:M,isLoading:B}=g3(A),E=d.useMemo(()=>{if(typeof window>"u")return null;const te=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof te=="string"&&te.trim().length>0?te.trim():null},[]),I=d.useMemo(()=>typeof window>"u"?!1:!!window.__OPENCHAMBER_RUNTIME_APIS__?.runtime?.isVSCode,[]),P=vs(te=>te.activeProjectId),D=vs(te=>te.projects),L=d.useMemo(()=>{if(I&&E)return{id:`vscode:${E}`,path:E};if(P){const te=D.find(U=>U.id===P);if(te?.path)return{id:te.id,path:te.path}}return A?{id:`path:${A}`,path:A}:null},[P,D,A,E,I]);d.useEffect(()=>{if(!L)return;let te=!1;return S(!0),(async()=>{try{const U=await zi(L);te||y(U)}catch{}finally{te||S(!1)}})(),()=>{te=!0}},[L]);const T=d.useCallback(te=>{i.length>=NK||c(U=>[...U,te])},[i.length]),_=d.useCallback(te=>{c(U=>U.filter((X,$)=>$!==te))},[]),z=d.useCallback((te,U)=>{c(X=>X.map(($,q)=>q===te?U:$))},[]),R=async te=>{const U=te.target.files;if(!U)return;let X=0;for(let $=0;$<U.length;$++){const q=U[$];if(q.size>kK){fe.error(`File "${q.name}" is too large (max 10MB)`);continue}try{const ee=await new Promise((ve,ge)=>{const xe=new FileReader;xe.onload=()=>ve(xe.result),xe.onerror=ge,xe.readAsDataURL(q)}),ce={id:F2(),filename:q.name,mimeType:q.type||"application/octet-stream",size:q.size,dataUrl:ee};g(ve=>[...ve,ce]),X++}catch(ee){console.error("File attach failed",ee),fe.error(`Failed to attach "${q.name}"`)}}X>0&&fe.success(`Attached ${X} file${X>1?"s":""}`),k.current&&(k.current.value="")},W=te=>{g(U=>U.filter(X=>X.id!==te))},G=x||n,Y=!!(r.trim()&&a.trim()&&i.length>=1&&f&&M&&!B),J=async te=>{if(te.preventDefault(),!(!Y||G)){b(!0);try{const U=i.map(({providerID:q,modelID:ee,displayName:ce,variant:ve})=>({providerID:q,modelID:ee,displayName:ce,variant:ve})),X=p.length>0?p.map(q=>({mime:q.mimeType,filename:q.filename,url:q.dataUrl})):void 0,$=v.filter(q=>q.trim().length>0);await e?.({name:r.trim(),prompt:a.trim(),models:U,agent:u||void 0,worktreeBaseBranch:f,files:X,setupCommands:$.length>0?$:void 0}),o(""),l(""),c([]),m(""),g([]),h("HEAD")}catch(U){console.error("Failed to create agent group:",U),fe.error("Failed to create agent group")}finally{b(!1)}}},V=te=>{Xu(te)||te.key==="Enter"&&!te.shiftKey&&(te.preventDefault(),Y&&!G&&J(te))};return s.jsx("div",{className:Q("flex flex-col items-center justify-center h-full w-full p-4",t),children:s.jsxs("form",{onSubmit:J,className:"w-full max-w-2xl space-y-4",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{htmlFor:"group-name",className:"typography-ui-label font-medium text-foreground",children:"Group Name"}),s.jsx(Xt,{id:"group-name",value:r,onChange:te=>o(te.target.value),placeholder:"e.g. feature-auth, bugfix-login",className:"typography-body"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:"Used for worktree directory and branch naming"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("label",{className:"typography-ui-label font-medium text-foreground flex items-center gap-1.5",children:[s.jsx(on,{className:"h-4 w-4 text-muted-foreground"}),"Base Branch"]}),s.jsx(G7,{directory:A,value:f,onChange:h}),s.jsxs("p",{className:"typography-micro text-muted-foreground",children:["Creates new branches from ",s.jsx("code",{className:"font-mono text-xs",children:f})]})]}),s.jsxs(Jr,{open:w,onOpenChange:C,children:[s.jsxs(vo,{className:"w-full flex items-center justify-between py-1 hover:bg-[var(--interactive-hover)] rounded-md px-1 -mx-1 transition-colors",children:[s.jsxs("p",{className:"typography-ui-label font-medium text-foreground",children:["Setup commands",v.filter(te=>te.trim()).length>0&&s.jsxs("span",{className:"font-normal text-muted-foreground/70",children:[" ","(",v.filter(te=>te.trim()).length," configured)"]})]}),s.jsx(Ds,{className:Q("h-4 w-4 text-muted-foreground transition-transform duration-200",w&&"rotate-180")})]}),s.jsx(eo,{children:s.jsxs("div",{className:"pt-2 space-y-2",children:[s.jsxs("p",{className:"typography-micro text-muted-foreground/70",children:["Commands run in each new worktree. Use ",s.jsx("code",{className:"font-mono text-xs",children:"$ROOT_PROJECT_PATH"})," for project root."]}),N?s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:"Loading..."}):s.jsxs("div",{className:"space-y-1.5",children:[v.map((te,U)=>s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Xt,{value:te,onChange:X=>{const $=[...v];$[U]=X.target.value,y($)},placeholder:"e.g., bun install",className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const X=v.filter(($,q)=>q!==U);y(X)},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":"Remove command",children:s.jsx(Ps,{className:"h-4 w-4"})})]},U)),s.jsxs("button",{type:"button",onClick:()=>y([...v,""]),className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(Qs,{className:"h-3.5 w-3.5"}),"Add command"]})]})]})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:"Agent"}),s.jsx(Z7,{value:u,onChange:m}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:"Defaults to your configured default agent"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:"Models"}),s.jsx(q7,{selectedModels:i,onAdd:T,onRemove:_,onUpdate:z,minModels:1,addButtonLabel:"Add model",maxModels:5})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{htmlFor:"prompt",className:"typography-ui-label font-medium text-foreground",children:"Prompt"}),s.jsxs("div",{className:"rounded-xl border border-border/80 overflow-hidden focus-within:ring-1 focus-within:ring-primary/50",style:{backgroundColor:F?.colors?.surface?.subtle},children:[s.jsx(hr,{ref:j,id:"prompt",value:a,onChange:te=>l(te.target.value),onKeyDown:V,placeholder:"Ask anything...",className:"min-h-[100px] max-h-[300px] resize-none border-0 bg-transparent dark:bg-transparent px-4 py-3 typography-markdown focus-visible:ring-0 focus-visible:ring-offset-0"}),p.length>0&&s.jsx("div",{className:"flex flex-wrap gap-2 px-3 pb-2",children:p.map(te=>s.jsxs("div",{className:"inline-flex items-center gap-1.5 px-2 py-1 bg-muted/30 border border-border/30 rounded-md typography-meta",children:[te.mimeType.startsWith("image/")?s.jsx(Fl,{className:"h-3.5 w-3.5 text-muted-foreground"}):s.jsx(Ml,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[120px]",title:te.filename,children:te.filename}),s.jsx("button",{type:"button",onClick:()=>W(te.id),className:"text-muted-foreground hover:text-destructive ml-0.5",children:s.jsx(Ps,{className:"h-3.5 w-3.5"})})]},te.id))}),s.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-t border-border/40 bg-transparent",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{ref:k,type:"file",multiple:!0,className:"hidden",onChange:R,accept:"*/*"}),s.jsx("button",{type:"button",onClick:()=>k.current?.click(),className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-foreground transition-colors","aria-label":"Add attachment",children:s.jsx(Ph,{className:"h-[18px] w-[18px]"})})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[i.length," model",i.length!==1?"s":""," selected"]})}),s.jsx("button",{type:"submit",disabled:!Y||G,className:Q("flex items-center justify-center text-muted-foreground transition-none outline-none focus:outline-none flex-shrink-0",Y?"text-primary hover:text-primary":"opacity-30"),"aria-label":"Start Agent Group",children:G?s.jsx(zb,{className:"h-[18px] w-[18px] animate-spin"}):s.jsx(kd,{className:"h-[18px] w-[18px]"})})]})]})]})]})})},CK=({group:t,className:e})=>{const{selectedSessionId:n,selectSession:r,deleteGroupWorktree:o,keepOnlyGroupWorktree:a}=Wa(),{setCurrentSession:l,currentSessionId:i}=Ze(),[c,u]=d.useState(null),[m,f]=d.useState(!1),h=d.useMemo(()=>n?t.sessions.find(w=>w.id===n)??t.sessions[0]??null:t.sessions[0]??null,[t.sessions,n]),p=d.useCallback(w=>{r(w.id),l(w.id)},[r,l]);d.useEffect(()=>{if(t.sessions.length>0){const w=n?t.sessions.find(C=>C.id===n)??t.sessions[0]:t.sessions[0];w&&(w.id!==i&&l(w.id),n||r(w.id))}},[t.name,t.sessions,n,i,r,l]);const g=h?.id===i,x=d.useCallback(()=>{if(!h?.path){fe.error("No worktree path available");return}Dn(h.path).then(w=>{if(w.ok){fe.success("Worktree path copied");return}fe.error("Failed to copy path")})},[h?.path]),b=d.useCallback(async()=>{h&&u({kind:"remove",path:h.path,label:h.displayLabel})},[h]),v=d.useCallback(async()=>{h&&u({kind:"keepOnly",path:h.path,label:h.displayLabel})},[h]),y=d.useCallback(async()=>{if(!(!c||m)){f(!0);try{if(c.kind==="remove")if(fe.info("Removing worktree..."),await o(t.name,c.path))fe.success("Worktree removed");else{const C=Wa.getState().error;fe.error(C||"Failed to remove worktree");return}else if(fe.info("Removing other worktrees..."),await a(t.name,c.path))fe.success("Removed other worktrees");else{const C=Wa.getState().error;fe.error(C||"Failed to remove other worktrees");return}u(null)}finally{f(!1)}}},[o,t.name,m,a,c]);return s.jsxs("div",{className:Q("flex h-full flex-col bg-background",e),children:[s.jsxs("div",{className:"flex-shrink-0 border-b border-border/30 px-4 py-3",children:[s.jsx("div",{className:"flex items-start justify-between gap-4",children:s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("h1",{className:"typography-heading-lg text-foreground truncate",children:t.name}),s.jsxs("div",{className:"flex items-center gap-2 mt-1 typography-meta text-muted-foreground",children:[s.jsxs("span",{children:[t.sessionCount," model",t.sessionCount!==1?"s":""]}),s.jsx("span",{children:"·"}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(on,{className:"h-3.5 w-3.5"}),h?.worktreeMetadata?.label||h?.branch||"No branch"]})]})]})}),t.sessions.length>0&&s.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[s.jsx("div",{className:"flex-1 min-w-0",children:s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsxs(Be,{variant:"outline",className:"w-full justify-between h-10 px-3",children:[s.jsx("div",{className:"flex items-center gap-2 min-w-0",children:h&&s.jsxs(s.Fragment,{children:[s.jsx(Mn,{providerId:h.providerId,className:"h-5 w-5 flex-shrink-0"}),s.jsx("span",{className:"truncate typography-body",children:h.modelId}),h.instanceNumber>1&&s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["#",h.instanceNumber]})]})}),s.jsx(Ds,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Ys,{align:"start",className:"w-[var(--radix-dropdown-menu-trigger-width)]",children:t.sessions.map(w=>s.jsxs(Jt,{onClick:()=>p(w),className:"flex items-center gap-2 py-2",children:[s.jsx(Mn,{providerId:w.providerId,className:"h-5 w-5 flex-shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-body",children:w.modelId}),w.instanceNumber>1&&s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["#",w.instanceNumber]})]}),w.branch&&s.jsxs("div",{className:"flex items-center gap-1 typography-micro text-muted-foreground/60",children:[s.jsx(on,{className:"h-3 w-3"}),s.jsx("span",{className:"truncate",children:w.worktreeMetadata?.label||w.branch})]})]}),h?.id===w.id&&s.jsx(js,{className:"h-4 w-4 text-primary flex-shrink-0"})]},w.id))})]})}),s.jsxs(qs,{children:[s.jsx(Gs,{asChild:!0,children:s.jsx(Be,{variant:"outline",size:"icon",className:"flex-shrink-0","aria-label":"Worktree actions",children:s.jsx(Qr,{className:"h-4 w-4"})})}),s.jsxs(Ys,{align:"end",className:"min-w-[220px]",children:[s.jsx(Jt,{onSelect:w=>{w.preventDefault(),b()},variant:"destructive",children:"Remove this worktree"}),s.jsx(Jt,{onSelect:w=>{w.preventDefault(),v()},children:"Leave this one, remove others"}),s.jsxs(Jt,{onClick:w=>{w.stopPropagation(),x()},disabled:!h?.path,children:[s.jsx(nr,{className:"h-4 w-4 mr-px"}),"Copy Worktree Path"]})]})]})]})]}),s.jsx(Os,{open:!!c,onOpenChange:w=>{w||u(null)},children:s.jsxs(Vs,{className:"max-w-md",keyboardAvoid:!0,children:[s.jsxs(Zs,{children:[s.jsx(Us,{children:c?.kind==="remove"?"Remove worktree":"Remove other worktrees"}),s.jsx(sn,{children:c?.kind==="remove"?s.jsxs(s.Fragment,{children:["Remove ",s.jsx("span",{className:"text-foreground font-medium",children:c?.label}),"? This deletes all sessions in that worktree and removes the worktree itself."]}):s.jsxs(s.Fragment,{children:["Keep ",s.jsx("span",{className:"text-foreground font-medium",children:c?.label})," and remove the other worktrees in ",s.jsx("span",{className:"text-foreground font-medium",children:t.name}),"."]})})]}),s.jsxs(yn,{children:[s.jsx(Be,{variant:"outline",onClick:()=>u(null),disabled:m,children:"Cancel"}),s.jsx(Be,{variant:c?.kind==="remove"?"destructive":"default",onClick:()=>{y()},disabled:m,children:m?"Working…":c?.kind==="remove"?"Remove":"Remove others"})]})]})}),s.jsx("div",{className:"flex-1 min-h-0",children:h?g?s.jsx(Kp,{sessionId:h.id,children:s.jsx(Zp,{})}):s.jsxs("div",{className:"h-full flex flex-col",children:[s.jsx("div",{className:"px-4 py-2 bg-muted/30 border-b border-border/30",children:s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(Mn,{providerId:h.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"font-medium text-foreground",children:h.displayLabel}),s.jsx("span",{children:"·"}),s.jsx("span",{className:"font-mono text-xs truncate",children:h.path})]})}),s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center p-8",children:[s.jsxs("p",{className:"typography-body text-muted-foreground mb-2",children:["Loading session for ",s.jsx("span",{className:"font-medium text-foreground",children:h.displayLabel})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground/60",children:["Session ID: ",h.id]})]})})]}):s.jsx("div",{className:"h-full flex items-center justify-center",children:s.jsx("p",{className:"typography-body text-muted-foreground",children:"No sessions in this group"})})})]})},AK=({className:t})=>{const e=!!(typeof window<"u"&&(window.__ARCHCODER_RUNTIME_APIS__?.runtime?.isVSCode||window.__OPENCHAMBER_RUNTIME_APIS__?.runtime?.isVSCode)),[n,r]=d.useState(()=>(typeof window<"u"?window.__ARCHCODER_CONNECTION__?.status||window.__OPENCHAMBER_CONNECTION__?.status:"connecting")||"connecting"),o=rs(w=>w.isInitialized),a=rs(w=>w.initializeApp),l=Ze(w=>w.loadSessions),i=dn(w=>w.setDirectory),c=d.useRef(0),{selectedGroupName:u,selectGroup:m,getSelectedGroup:f,loadGroups:h}=Wa(),{createMultiRun:p,isLoading:g}=k1();d.useEffect(()=>{if(!e)return;const w=typeof window<"u"?window.__ARCHCODER_CONNECTION__?.status||window.__OPENCHAMBER_CONNECTION__?.status:void 0;(w==="connected"||w==="connecting"||w==="error"||w==="disconnected")&&r(w);const C=N=>{const k=N.detail?.status;(k==="connected"||k==="connecting"||k==="error"||k==="disconnected")&&r(k)};return window.addEventListener("archcoder:connection-status",C),()=>window.removeEventListener("archcoder:connection-status",C)},[e]),d.useEffect(()=>{if(!e||n!=="connected")return;const w=Date.now();if(w-c.current<750)return;c.current=w;const C=typeof window<"u"?window.__VSCODE_CONFIG__?.workspaceFolder:null;if(typeof C=="string"&&C.trim().length>0)try{i(C,{showOverlay:!1})}catch{}(async()=>{try{o||await a();const S=rs.getState();if(!S.isInitialized||!S.isConnected||S.providers.length===0||S.agents.length===0)return;await l(),D6()&&console.log("[OpenChamber][VSCode][agentManager] bootstrap complete",{providers:S.providers.length,agents:S.agents.length,sessions:Ze.getState().sessions.length})}catch{}})()},[n,o,a,e,l,i]);const x=d.useCallback(w=>{m(w)},[m]),b=d.useCallback(()=>{m(null)},[m]),v=d.useCallback(async w=>{fe.info(`Creating agent group "${w.name}" with ${w.models.length} model(s)...`);const C=await p(w);if(C){fe.success(`Agent group "${w.name}" created with ${C.sessionIds.length} session(s)`);const N=C.groupSlug,S=async(k=6)=>{for(let j=0;j<k;j+=1){if(await h(),Wa.getState().groups.some(A=>A.name===N))return!0;await new Promise(A=>setTimeout(A,500))}return!1};try{await Ze.getState().loadSessions()}catch{}await S(),m(N)}else{const N=k1.getState().error;fe.error(N||"Failed to create agent group")}},[p,h,m]),y=f();return s.jsxs("div",{className:Q("flex h-full w-full bg-background",t),children:[s.jsx("div",{className:"w-64 flex-shrink-0",children:s.jsx(vK,{selectedGroupName:u,onGroupSelect:x,onNewAgent:b})}),s.jsx("div",{className:"flex-1 min-w-0",children:y?s.jsx(CK,{group:y}):s.jsx(SK,{onCreateGroup:v,isCreating:g})})]})},MK=t=>{const e=Fe.c(51),{onClose:n}=t,{sessions:r,messages:o,sessionMemoryState:a,currentSessionId:l}=Ze(),i=mo(FK);let c;e[0]!==o?(c=0,o.forEach(L=>{c=c+L.length}),e[0]=o,e[1]=c):c=e[1];const u=c;let m;if(e[2]!==l||e[3]!==o||e[4]!==a||e[5]!==r){let L;e[7]!==l||e[8]!==o||e[9]!==a?(L=T=>{const _=o.get(T.id)?.length||0,z=a.get(T.id);return{id:T.id,title:T.title||"Untitled",messageCount:_,isStreaming:z?.isStreaming||!1,isZombie:z?.isZombie||!1,backgroundCount:z?.backgroundMessageCount||0,lastAccessed:z?.lastAccessedAt||0,isCurrent:T.id===l}},e[7]=l,e[8]=o,e[9]=a,e[10]=L):L=e[10],m=r.map(L).sort(BK),e[2]=l,e[3]=o,e[4]=a,e[5]=r,e[6]=m}else m=e[6];const f=m,h=o.size;let p;e[11]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Hb,{className:"h-4 w-4"}),s.jsx("h3",{className:"font-semibold typography-ui-label",children:"Memory Debug Panel"})]}),e[11]=p):p=e[11];let g;e[12]!==n?(g=n&&s.jsx(Be,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(Ps,{className:"h-4 w-4"})}),e[12]=n,e[13]=g):g=e[13];let x;e[14]!==g?(x=s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[p,g]}),e[14]=g,e[15]=x):x=e[15];let b;e[16]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx("div",{className:"text-muted-foreground",children:"Total Messages"}),e[16]=b):b=e[16];let v;e[17]!==u?(v=s.jsxs("div",{className:"bg-muted/50 rounded p-2",children:[b,s.jsx("div",{className:"typography-markdown font-semibold",children:u})]}),e[17]=u,e[18]=v):v=e[18];let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"text-muted-foreground",children:"Cached Sessions"}),e[19]=y):y=e[19];let w;e[20]!==h?(w=s.jsxs("div",{className:"bg-muted/50 rounded p-2",children:[y,s.jsxs("div",{className:"typography-markdown font-semibold",children:[h," / ",H3.MAX_SESSIONS]})]}),e[20]=h,e[21]=w):w=e[21];let C;e[22]!==v||e[23]!==w?(C=s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[v,w]}),e[22]=v,e[23]=w,e[24]=C):C=e[24];let N;e[25]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted-foreground",children:"Viewport Window:"}),s.jsxs("span",{children:[Cv()," messages"]})]}),e[25]=N):N=e[25];let S;e[26]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted-foreground",children:"Zombie Timeout:"}),s.jsxs("span",{children:[H3.ZOMBIE_TIMEOUT/1e3/60," minutes"]})]}),e[26]=S):S=e[26];let k;e[27]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx("span",{className:"text-muted-foreground",children:"GitHub Total Requests:"}),e[27]=k):k=e[27];let j;e[28]!==i?(j=s.jsxs("div",{className:"typography-meta space-y-1 border-t pt-2",children:[N,S,s.jsxs("div",{className:"flex justify-between",children:[k,s.jsx("span",{children:i})]})]}),e[28]=i,e[29]=j):j=e[29];let F;e[30]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx("div",{className:"typography-meta font-semibold mb-1",children:"Sessions in Memory:"}),e[30]=F):F=e[30];let A;e[31]!==f?(A=f.map(_K),e[31]=f,e[32]=A):A=e[32];let M;e[33]!==A?(M=s.jsxs("div",{className:"border-t pt-2",children:[F,s.jsx(ks,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:A})]}),e[33]=A,e[34]=M):M=e[34];let B;e[35]!==l||e[36]!==o||e[37]!==a||e[38]!==r?(B=s.jsx(It,{asChild:!0,children:s.jsx(Be,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[MemoryDebug] Session store state:",{sessions:r.map(EK),currentSessionId:l,cachedSessions:Array.from(o.keys()),memoryStates:Object.fromEntries(a)})},children:"Log State"})}),e[35]=l,e[36]=o,e[37]=a,e[38]=r,e[39]=B):B=e[39];let E;e[40]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(_t,{side:"top",children:"Log current memory state to browser console"}),e[40]=E):E=e[40];let I;e[41]!==B?(I=s.jsx("div",{className:"flex gap-2 pt-2 border-t",children:s.jsxs(Dt,{delayDuration:1e3,children:[B,E]})}),e[41]=B,e[42]=I):I=e[42];let P;e[43]!==j||e[44]!==M||e[45]!==I||e[46]!==C?(P=s.jsxs("div",{className:"space-y-3",children:[C,null,j,M,I]}),e[43]=j,e[44]=M,e[45]=I,e[46]=C,e[47]=P):P=e[47];let D;return e[48]!==P||e[49]!==x?(D=s.jsxs(Wu,{className:"fixed bottom-4 right-4 w-96 p-4 shadow-none z-50 bg-background/95 bottom-safe-area",children:[x,P]}),e[48]=P,e[49]=x,e[50]=D):D=e[50],D};function FK(t){return t.totalRequestCount}function BK(t,e){return e.lastAccessed-t.lastAccessed}function _K(t){return s.jsxs("div",{className:`typography-meta p-1.5 rounded flex items-center justify-between ${t.isCurrent?"bg-primary/10":"bg-muted/30"}`,children:[s.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[s.jsx("span",{className:"truncate",children:t.title}),t.isStreaming&&s.jsx(Lb,{className:"h-3 w-3 text-primary animate-pulse"}),t.isZombie&&s.jsx("span",{className:"text-status-warning",children:"!"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:`font-mono ${t.messageCount>Sv()?"text-status-warning":""}`,children:[t.messageCount," msgs"]}),t.backgroundCount>0&&s.jsxs("span",{className:"text-primary",children:["+",t.backgroundCount]})]})]},t.id)}function EK(t){return{id:t.id,title:t.title}}const DK=()=>{const t=Ze.getState(),e=t.currentSessionId;if(!e)return"";const n=t.sessions.find(r=>r.id===e);return typeof n?.directory=="string"?n.directory:""},IK=async(t,e=6e3)=>{const n=new AbortController,r=setTimeout(()=>n.abort(),e),o=Date.now();try{const a=await fetch(t,{method:"GET",headers:{Accept:"application/json"},signal:n.signal}),l=Date.now()-o,i=a.headers.get("content-type")||"",c=i.toLowerCase(),u=c.includes("json")&&!c.includes("text/html");let m="";if(u){const f=await a.json().catch(()=>null);if(Array.isArray(f))m=`json[array] len=${f.length}`;else if(f&&typeof f=="object"){const h=Object.keys(f).slice(0,8);m=`json[object] keys=${h.join(",")}${Object.keys(f).length>h.length?",…":""}`}else m=`json[${typeof f}]`}else m=i?`content-type=${i}`:"no content-type";return{ok:a.ok&&u,status:a.status,elapsedMs:l,summary:m}}catch(a){const l=Date.now()-o,c=n.signal.aborted||a instanceof Error&&(a.name==="AbortError"||a.message.toLowerCase().includes("aborted"))?`timeout after ${e}ms`:a instanceof Error?a.message:String(a);return{ok:!1,status:0,elapsedMs:l,summary:`error=${c}`}}finally{clearTimeout(r)}},TK=t=>{if(!t||!Number.isFinite(t))return"(n/a)";try{return new Date(t).toISOString()}catch{return"(invalid)"}},PK=t=>{if(typeof t=="number"&&Number.isFinite(t)&&t>0)return Math.trunc(t);if(typeof t=="string"){const e=Number.parseInt(t,10);if(Number.isFinite(e)&&e>0)return e}return null},RK=async()=>{const t=new Date,e="2.0.4",n=typeof navigator<"u"?navigator.userAgent:"(no navigator)",r=DK(),o=Ee.getState().eventStreamStatus,a=typeof window<"u"?window.location.origin:"",l=a?`${a.replace(/\/+$/,"")}/api/`:"",i=await(async()=>{if(!a)return null;const x=new AbortController,b=setTimeout(()=>x.abort(),5e3);try{const v=await fetch(`${a.replace(/\/+$/,"")}/health`,{method:"GET",headers:{Accept:"application/json"},signal:x.signal});if(!v.ok)return null;const y=await v.json().catch(()=>null);return!y||typeof y!="object"||Array.isArray(y)?null:y}catch{return null}finally{clearTimeout(b)}})(),c=await(async()=>{if(!a)return null;const x=new AbortController,b=setTimeout(()=>x.abort(),7e3);try{const v=await fetch(`${a.replace(/\/+$/,"")}/api/config/opencode-resolution`,{method:"GET",headers:{Accept:"application/json"},signal:x.signal}),y=v.headers.get("content-type")||"(none)";if(!v.ok)return{data:null,status:v.status,error:`http ${v.status} content-type=${y}`};const w=await v.text();let C=null;try{C=JSON.parse(w)}catch{const N=w.replace(/\s+/g," ").slice(0,120);return{data:null,status:v.status,error:`invalid json content-type=${y} body=${N||"(empty)"}`}}return!C||typeof C!="object"||Array.isArray(C)?{data:null,status:v.status,error:`invalid json-shape content-type=${y}`}:{data:C,status:v.status,error:null}}catch(v){return{data:null,status:null,error:v instanceof Error?v.message:String(v)}}finally{clearTimeout(b)}})()||{data:null,error:null},u=(x,b=!0)=>{if(!l)return null;const v=new URL(x.replace(/^\/+/,""),l);return b&&r&&v.searchParams.set("directory",r),v.toString()},m=[{label:"health",path:"/global/health",includeDirectory:!1},{label:"config",path:"/config",includeDirectory:!0},{label:"providers",path:"/config/providers",includeDirectory:!0},{label:"agents",path:"/agent",includeDirectory:!0,timeoutMs:12e3},{label:"commands",path:"/command",includeDirectory:!0,timeoutMs:1e4},{label:"project",path:"/project/current",includeDirectory:!0},{label:"path",path:"/path",includeDirectory:!0},{label:"sessions",path:"/session",includeDirectory:!0,timeoutMs:12e3},{label:"sessionStatus",path:"/session/status",includeDirectory:!0}],f=l?await Promise.all(m.map(async x=>{const b=u(x.path,x.includeDirectory!==!1);if(!b)return{label:x.label,url:"(none)",result:null};const v=await IK(b,typeof x.timeoutMs=="number"?x.timeoutMs:void 0);return{label:x.label,url:b,result:v}})):[],h=[];h.push(`Time: ${t.toISOString()}`),h.push(`OpenChamber version: ${e}`),h.push(`Runtime: ${a||"(unknown)"} (api=${a?a+"/api":"(unknown)"})`),h.push(`Event stream: ${o}`),h.push(`Directory: ${r||"(none)"}`),h.push(`Platform: ${n}`);const p=PK(i?.openCodePort);if(h.push(`OpenCode runtime port: ${p??"(unknown)"}`),typeof i?.openCodeRunning=="boolean"&&h.push(`OpenCode runtime running: ${i.openCodeRunning?"yes":"no"}`),typeof i?.openCodeSecureConnection=="boolean"&&h.push(`Secure OpenCode connection: ${i.openCodeSecureConnection?"true":"false"}`),typeof i?.openCodeAuthSource=="string"&&i.openCodeAuthSource.trim()&&h.push(`OpenCode auth source: ${i.openCodeAuthSource}`),typeof window<"u"){const x=window.__OPENCHAMBER_MACOS_MAJOR__;typeof x=="number"&&Number.isFinite(x)&&x>0&&h.push(`macOS major: ${x}`)}if(/Mac OS X|Macintosh/.test(n)){h.push(""),h.push("OpenCode CLI resolution:");const x=c.data,b=x&&typeof x.configured=="string"?x.configured:null,v=x&&typeof x.resolved=="string"?x.resolved:i&&typeof i.opencodeBinaryResolved=="string"?i.opencodeBinaryResolved:"",y=x&&typeof x.resolvedDir=="string"?x.resolvedDir:"",w=x&&typeof x.source=="string"?x.source:i&&typeof i.opencodeBinarySource=="string"?i.opencodeBinarySource:"",C=x&&typeof x.shim=="string"?x.shim:i&&typeof i.opencodeShimInterpreter=="string"?i.opencodeShimInterpreter:"",N=x&&typeof x.node=="string"?x.node:i&&typeof i.nodeBinaryResolved=="string"?i.nodeBinaryResolved:"",S=x&&typeof x.bun=="string"?x.bun:i&&typeof i.bunBinaryResolved=="string"?i.bunBinaryResolved:"",k=x&&typeof x.detectedNow=="string"?x.detectedNow:"",j=x&&typeof x.detectedSourceNow=="string"?x.detectedSourceNow:"";if(b!==null&&h.push(`- configured: ${b.trim().length===0?"(cleared)":b}`),v){const F=y||(v.includes("/")?v.split("/").slice(0,-1).join("/")||"/":"");h.push(`- opencode: ${v}${F?` (dir=${F})`:""}`)}else h.push("- opencode: (n/a)");h.push(`- source: ${w||"(n/a)"}`),k&&(h.push(`- detected-now: ${k}`),h.push(`- detected-source: ${j||"(n/a)"}`)),h.push(`- shim: ${C||"(n/a)"}`),h.push(`- node: ${N||"(n/a)"}`),h.push(`- bun: ${S||"(n/a)"}`),!x&&c.error&&h.push(`- resolution-endpoint: ${c.error}`)}if(h.push(""),f.length){h.push("OpenCode API probes:");for(const x of f){if(!x.result){h.push(`- ${x.label}: (no url)`);continue}const{ok:b,status:v,elapsedMs:y,summary:w}=x.result,C=b?"":` url=${x.url}`;h.push(`- ${x.label}: ${b?"ok":"fail"} status=${v} time=${y}ms ${w}${C}`)}}else h.push("OpenCode API probes: (skipped)");return h.push(""),h.push(`Generated: ${TK(Date.now())}`),h.join(`
8012
8012
  `)},ng=async()=>{const t=await RK(),e=Ee.getState();e.setOpenCodeStatusText(t),e.setOpenCodeStatusDialogOpen(!0)},zK=()=>{const t=Fe.c(32),{openNewSessionDraft:e,abortCurrentOperation:n,armAbortPrompt:r,clearAbortPrompt:o,currentSessionId:a}=Ze(),{toggleCommandPalette:l,toggleHelpDialog:i,toggleSidebar:c,toggleRightSidebar:u,setRightSidebarOpen:m,setRightSidebarTab:f,toggleBottomTerminal:h,setBottomTerminalExpanded:p,isMobile:g,setSessionSwitcherOpen:x,setActiveMainTab:b,setSettingsDialogOpen:v,setModelSelectorOpen:y,toggleExpandedInput:w,shortcutOverrides:C}=Ee(),{themeMode:N,setThemeMode:S}=qn(),{working:k}=Yu(),j=d.useRef(null),F=d.useRef(null),A=d.useRef(N);let M,B;t[0]!==N?(M=()=>{A.current=N},B=[N],t[0]=N,t[1]=M,t[2]=B):(M=t[1],B=t[2]),d.useEffect(M,B);let E;t[3]!==o?(E=()=>{F.current&&(clearTimeout(F.current),F.current=null),j.current=null,o()},t[3]=o,t[4]=E):E=t[4];const I=E;let P,D;t[5]!==n||t[6]!==r||t[7]!==a||t[8]!==g||t[9]!==e||t[10]!==I||t[11]!==b||t[12]!==p||t[13]!==y||t[14]!==m||t[15]!==f||t[16]!==x||t[17]!==v||t[18]!==S||t[19]!==C||t[20]!==h||t[21]!==l||t[22]!==w||t[23]!==i||t[24]!==u||t[25]!==c||t[26]!==k?(P=()=>{const _=R=>ha(R,C),z=R=>{if(Gn(R,_("open_command_palette"))){R.preventDefault(),l();return}if(Gn(R,_("open_status"))){R.preventDefault(),ng();return}if(Gn(R,_("open_help"))){R.preventDefault(),i();return}const W=Gn(R,_("new_chat")),G=Gn(R,_("new_chat_worktree"));if(W||G){if(R.preventDefault(),b("chat"),x(!1),!xn()&&G){Ju();return}e();return}if(Gn(R,_("cycle_theme"))){R.preventDefault();const Y=["light","dark","system"],J=document.activeElement,te=(Y.indexOf(A.current)+1)%Y.length;S(Y[te]),requestAnimationFrame(()=>{typeof document>"u"||typeof window>"u"||(document.hasFocus()||window.focus(),J&&document.contains(J)&&J.focus({preventScroll:!0}))});return}if(Gn(R,_("open_timeline"))){R.preventDefault();const{isTimelineDialogOpen:Y,setTimelineDialogOpen:J}=Ee.getState();J(!Y);return}if(Gn(R,_("open_settings"))){R.preventDefault();const{isSettingsDialogOpen:Y}=Ee.getState();v(!Y);return}if(Gn(R,_("toggle_sidebar"))){R.preventDefault();const{isMobile:Y,isSessionSwitcherOpen:J}=Ee.getState();Y?x(!J):c();return}if(Gn(R,_("focus_input"))){R.preventDefault(),document.querySelector('textarea[data-chat-input="true"]')?.focus();return}if(Gn(R,_("toggle_right_sidebar"))){const{isMobile:Y}=Ee.getState();if(Y)return;R.preventDefault(),u();return}if(Gn(R,_("open_right_sidebar_git"))){const{isMobile:Y}=Ee.getState();if(Y)return;R.preventDefault(),m(!0),f("git");return}if(Gn(R,_("open_right_sidebar_files"))){const{isMobile:Y}=Ee.getState();if(Y)return;R.preventDefault(),m(!0),f("files");return}if(Gn(R,_("cycle_right_sidebar_tab"))){const{isMobile:Y,rightSidebarTab:J}=Ee.getState();if(Y)return;const V=["git","files"],te=V.indexOf(J),U=V[(te+1)%V.length];R.preventDefault(),m(!0),f(U);return}if(Gn(R,_("toggle_terminal"))){const{isMobile:Y}=Ee.getState();if(Y)return;R.preventDefault(),h();return}if(Gn(R,_("toggle_terminal_expanded"))){const{isMobile:Y,isBottomTerminalExpanded:J}=Ee.getState();if(Y)return;R.preventDefault(),p(!J);return}if(Gn(R,_("open_model_selector"))){const{isSettingsDialogOpen:Y,isCommandPaletteOpen:J,isHelpDialogOpen:V,isSessionSwitcherOpen:te,isAboutDialogOpen:U,activeMainTab:X,isModelSelectorOpen:$}=Ee.getState();if(Y||J||V||te||U||!(X==="chat"))return;R.preventDefault(),y(!$);return}if(Gn(R,_("cycle_thinking_variant"))){const{isSettingsDialogOpen:Y,isCommandPaletteOpen:J,isHelpDialogOpen:V,isSessionSwitcherOpen:te,isAboutDialogOpen:U,activeMainTab:X}=Ee.getState();if(Y||J||V||te||U||!(X==="chat"))return;const ee=rs.getState();if(ee.getCurrentModelVariants().length===0)return;R.preventDefault(),ee.cycleCurrentVariant();const ve=rs.getState().currentVariant,ge=Ze.getState(),xe=ge.currentSessionId,ne=rs.getState().currentAgentName,O=rs.getState().currentProviderId,H=rs.getState().currentModelId;xe&&ne&&O&&H&&ge.saveAgentModelVariantForSession(xe,ne,O,H,ve);return}if(Gn(R,_("cycle_favorite_model_forward"))||Gn(R,_("cycle_favorite_model_backward"))){const{isSettingsDialogOpen:Y,isCommandPaletteOpen:J,isHelpDialogOpen:V,isSessionSwitcherOpen:te,isAboutDialogOpen:U,activeMainTab:X,favoriteModels:$,addRecentModel:q}=Ee.getState();if(Y||J||V||te||U||!(X==="chat")||$.length===0)return;R.preventDefault();const{currentProviderId:ve,currentModelId:ge,setProvider:xe,setModel:ne}=rs.getState(),O=$.length,H=$.findIndex(le=>le.providerID===ve&&le.modelID===ge),K=Gn(R,_("cycle_favorite_model_forward"))?1:-1,re=$[(H+K+O)%O];xe(re.providerID),ne(re.modelID),q(re.providerID,re.modelID);return}if(Gn(R,_("expand_input"))){if(g)return;R.preventDefault(),w();return}if(R.key==="Escape"){const J=!!R.target?.closest('[role="dialog"]'),V=!!document.querySelector('[data-settings-view="true"]');if(J||V){I();return}const{isSettingsDialogOpen:te,isCommandPaletteOpen:U,isHelpDialogOpen:X,isSessionSwitcherOpen:$,isAboutDialogOpen:q,isMultiRunLauncherOpen:ee,isImagePreviewOpen:ce,activeMainTab:ve}=Ee.getState();if(te){R.preventDefault(),v(!1),I();return}if(U||X||$||q||ee||ce||!(ve==="chat")){I();return}const ne=a;if(!(k.canAbort&&!!ne)){I();return}const H=Date.now(),K=j.current;if(K&&H<K){R.preventDefault(),I(),n(ne||void 0);return}R.preventDefault();const re=r(3e3)??H+3e3;j.current=re,F.current&&clearTimeout(F.current);const le=Math.max(re-H,0);F.current=setTimeout(()=>{j.current&&Date.now()>=j.current&&I()},le||0);return}};return window.addEventListener("keydown",z),()=>{window.removeEventListener("keydown",z)}},D=[e,n,l,i,c,u,m,f,h,p,g,x,b,v,y,w,S,k,r,I,a,C],t[5]=n,t[6]=r,t[7]=a,t[8]=g,t[9]=e,t[10]=I,t[11]=b,t[12]=p,t[13]=y,t[14]=m,t[15]=f,t[16]=x,t[17]=v,t[18]=S,t[19]=C,t[20]=h,t[21]=l,t[22]=w,t[23]=i,t[24]=u,t[25]=c,t[26]=k,t[27]=P,t[28]=D):(P=t[27],D=t[28]),d.useEffect(P,D);let L,T;t[29]!==I?(L=()=>()=>{I()},T=[I],t[29]=I,t[30]=L,t[31]=T):(L=t[30],T=t[31]),d.useEffect(L,T)},hh="archcoder:menu-action",bd="archcoder:check-for-updates",LK=t=>{const{openNewSessionDraft:e}=Ze(),{toggleCommandPalette:n,toggleHelpDialog:r,toggleSidebar:o,setSessionSwitcherOpen:a,setActiveMainTab:l,setSettingsDialogOpen:i,setAboutDialogOpen:c}=Ee(),{addProject:u}=vs(),m=Sl(y=>y.checkForUpdates),{requestAccess:f,startAccessing:h}=rc(),{setThemeMode:p}=qn(),g=d.useRef(!1),x=d.useCallback(()=>{g.current||(g.current=!0,m().then(()=>{const{available:y,error:w}=Sl.getState();if(w){fe.error("Failed to check for updates",{description:w});return}y||fe.success("You are on the latest version")}).finally(()=>{g.current=!1}))},[m]),b=d.useCallback(()=>{Rn()?f("").then(async y=>{if(!y.success||!y.path){y.error&&y.error!=="Directory selection cancelled"&&fe.error("Failed to select directory",{description:y.error});return}const w=await h(y.path);if(!w.success){fe.error("Failed to open directory",{description:w.error||"Desktop could not grant file access."});return}u(y.path,{id:y.projectId})||fe.error("Failed to add project",{description:"Please select a valid directory path."})}).catch(y=>{console.error("Desktop: Error selecting directory:",y),fe.error("Failed to select directory")}):na.requestDirectoryDialog()},[u,f,h]),v=d.useCallback(y=>{switch(y){case"about":c(!0);break;case"settings":i(!0);break;case"command-palette":n();break;case"new-session":l("chat"),a(!1),e();break;case"new-worktree-session":l("chat"),a(!1),Ju();break;case"change-workspace":b();break;case"open-git-tab":{const{activeMainTab:w}=Ee.getState();l(w==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:w}=Ee.getState();l(w==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:w}=Ee.getState();l(w==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:w}=Ee.getState();l(w==="terminal"?"chat":"terminal");break}case"copy":{const w=new Event("archcoder:copy",{cancelable:!0});!window.dispatchEvent(w)||document.execCommand("copy");break}case"theme-light":p("light");break;case"theme-dark":p("dark");break;case"theme-system":p("system");break;case"toggle-sidebar":o();break;case"toggle-memory-debug":t?.();break;case"help-dialog":r();break;case"download-logs":{ng().catch(()=>{fe.error("Failed to collect OpenCode status")});break}}},[b,t,e,c,l,a,i,p,n,r,o]);d.useEffect(()=>{const y=C=>{const N=C.detail;N&&v(N)},w=()=>{x()};return window.addEventListener(hh,y),window.addEventListener(bd,w),()=>{window.removeEventListener(hh,y),window.removeEventListener(bd,w)}},[v,x]),d.useEffect(()=>{if(typeof window>"u")return;const w=window.__TAURI__?.event?.listen;if(typeof w!="function")return;let C=null,N=null;return w("archcoder:menu-action",S=>{const k=S?.payload;typeof k=="string"&&v(k)}).then(S=>{C=S}).catch(()=>{}),w("archcoder:check-for-updates",()=>{window.dispatchEvent(new Event(bd))}).then(S=>{N=S}).catch(()=>{}),()=>{(async()=>{try{const k=C?.();k instanceof Promise&&await k}catch{}try{const k=N?.();k instanceof Promise&&await k}catch{}})()}},[v])},HK=t=>{const e=t?.enabled??!0;d.useEffect(()=>{if(!e)return;let n=!1;return(async()=>{try{const o=await En.getGlobalSessionStatus();if(n||!o)return;const a=new Map;Object.entries(o).forEach(([l,i])=>{if(!l||!i)return;const c=i;a.set(l,c)}),a.size>0&&Ze.setState({sessionStatus:a})}catch{}})(),()=>{n=!0}},[e])},$K=2e3,OK=t=>{const e=Ze.getState().sessionAbortFlags.get(t);return e?Date.now()-e.timestamp<$K:!1},ph=(t,e)=>{Ze.setState(n=>{const r=new Map(n.sessionStatus??new Map);return r.set(t,{type:e}),{sessionStatus:r}})},VK=t=>{const e=rs.getState().getVisibleAgents();let n="",r=[],o;const a=[];for(let l=0;l<t.length;l+=1){const i=t[l],{sanitizedText:c,mention:u}=Wd(i.content,e);!o&&u?.name&&(o=u.name),l===0?(n=c,r=i.attachments??[]):a.push({text:c,attachments:i.attachments})}return{primaryText:n,primaryAttachments:r,agentMentionName:o,additionalParts:a.length>0?a:void 0}},UK=t=>{const e=sr.getState(),n=rs.getState(),r=_l.getState(),o=e.getSessionAgentSelection(t)??e.getCurrentAgent(t)??n.currentAgentName??void 0,a=e.getSessionModelSelection(t),l=o?e.getAgentModelForSession(t,o):null,i=l?.providerId??a?.providerId??n.currentProviderId??r.lastUsedProvider?.providerID,c=l?.modelId??a?.modelId??n.currentModelId??r.lastUsedProvider?.modelID,u=o&&i&&c?e.getAgentModelVariantForSession(t,o,i,c):void 0;return{providerID:i,modelID:c,agent:o,variant:u}};function WK(t){const e=t?.enabled??!0,n=Eo(l=>l.queuedMessages),r=Ze(l=>l.sessionStatus),o=d.useRef(new Set),a=d.useRef(new Map);d.useEffect(()=>{if(!e)return;const l=async(m,f)=>{if(f.length===0||o.current.has(m)||OK(m)||(Ze.getState().sessionStatus?.get(m)?.type??"idle")!=="idle")return;const p=VK(f);if(!p.primaryText&&!p.additionalParts?.length)return;const g=UK(m);if(!(!g.providerID||!g.modelID)){o.current.add(m),ph(m,"busy");try{await _l.getState().sendMessage(p.primaryText,g.providerID,g.modelID,g.agent,m,p.primaryAttachments,p.agentMentionName,p.additionalParts,g.variant,"normal");const x=Eo.getState().removeFromQueue;f.forEach(b=>{x(m,b.id)})}catch(x){ph(m,"idle"),console.warn("[queue] queued auto-send failed:",x)}finally{o.current.delete(m)}}},i=new Map(a.current);(r?Array.from(r.entries()):[]).forEach(([m,f])=>{i.set(m,f.type)}),Object.entries(n).forEach(([m,f])=>{const h=r?.get(m)?.type??"idle",p=a.current.get(m),g=(p==="busy"||p==="retry")&&h==="idle",x=p===void 0&&h==="idle";f.length>0&&(g||x)&&l(m,f),i.set(m,h)}),a.current=i},[e,n,r])}const qK=["chat","git","diff","terminal","files"],GK=["settings","agents","commands","skills","providers","usage","git-identities"],xo={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function gh(t){const e=ZK();return{sessionId:KK(e),tab:YK(e),settingsPath:XK(e),diffFile:QK(e)}}function ZK(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function KK(t){const e=t.get(xo.SESSION);return!e||e.trim().length===0?null:e.trim()}function YK(t){const e=t.get(xo.TAB);if(!e)return null;const n=e.toLowerCase().trim();return qK.includes(n)?n:null}function XK(t){const e=t.get(xo.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(GK.includes(n),n)}function QK(t){const e=t.get(xo.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function xh(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(xo.SESSION)||t.has(xo.TAB)||t.has(xo.SETTINGS)||t.has(xo.FILE)}catch{return!1}}const JK="chat";function rg(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(xo.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(xo.SETTINGS,n),e}return t.tab!==JK&&e.set(xo.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(xo.FILE,t.diffFile),e}function eY(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function tY(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=rg(t),r=[...e.entries()].sort((a,l)=>a[0].localeCompare(l[0])),o=[...n.entries()].sort((a,l)=>a[0].localeCompare(l[0]));if(r.length!==o.length)return!1;for(let a=0;a<r.length;a++)if(r[a][0]!==o[a][0]||r[a][1]!==o[a][1])return!1;return!0}catch{return!0}}function sY(t,e={}){if(!(typeof window>"u")&&!nY()&&!(!e.force&&tY(t)))try{const n=rg(t),r=eY(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function nY(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function rY(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function oY(){const t=d.useMemo(()=>rY(),[]),e=d.useRef(!1),n=d.useRef(!1),r=Ze(f=>f.setCurrentSession),o=Ee(f=>f.setActiveMainTab),a=Ee(f=>f.setSettingsDialogOpen),l=Ee(f=>f.setSettingsPage),i=Ee(f=>f.navigateToDiff),c=d.useCallback(async f=>{if(!n.current){n.current=!0;try{if(f.sessionId){const h=Ze.getState().currentSessionId;f.sessionId!==h&&await r(f.sessionId)}if(f.settingsPath){l(V7(f.settingsPath)),a(!0);return}Ee.getState().isSettingsDialogOpen&&a(!1),f.tab&&o(f.tab),f.diffFile&&(f.tab==="diff"||!f.tab)&&i(f.diffFile)}finally{n.current=!1}}},[r,o,a,l,i]),u=d.useCallback(()=>{const f=Ze.getState(),h=Ee.getState();return{sessionId:f.currentSessionId,tab:h.activeMainTab,isSettingsOpen:h.isSettingsDialogOpen,settingsPath:h.settingsPage,diffFile:h.pendingDiffFile}},[]),m=d.useCallback((f={})=>{if(t||n.current)return;const h=u();sY(h,f)},[t,u]);d.useEffect(()=>{if(e.current||(e.current=!0,!xh()))return;const f=gh();(async()=>(await c(f),t||m({replace:!0})))()},[c,t,m]),d.useEffect(()=>{if(t)return;let f=Ze.getState().currentSessionId;return Ze.subscribe(p=>{const g=p.currentSessionId;g===f||n.current||(f=g,m())})},[t,m]),d.useEffect(()=>{if(t)return;let f=Ee.getState().activeMainTab,h=Ee.getState().isSettingsDialogOpen,p=Ee.getState().settingsPage,g=Ee.getState().pendingDiffFile;return Ee.subscribe(b=>{if(n.current)return;const v=b.activeMainTab!==f,y=b.isSettingsDialogOpen!==h,w=b.settingsPage!==p,C=b.pendingDiffFile!==g&&b.activeMainTab==="diff";f=b.activeMainTab,h=b.isSettingsDialogOpen,p=b.settingsPage,g=b.pendingDiffFile,(v||y||w||C)&&m()})},[t,m]),d.useEffect(()=>{if(typeof window>"u"||t)return;const f=()=>{const h=gh();if(xh())c(h);else{const p=Ee.getState();p.isSettingsDialogOpen&&a(!1),p.activeMainTab!=="chat"&&o("chat")}};return window.addEventListener("popstate",f),()=>{window.removeEventListener("popstate",f)}},[c,t,o,a])}const aY=2e4,og=()=>{if(typeof document>"u")return"visible";const t=document.visibilityState;return t==="hidden"&&document.hasFocus()?"visible":t},ag=t=>{if(!Na())return;const e=Ho();e?.push?.setVisibility&&e.push.setVisibility({visible:t})},lY=t=>{const e=Fe.c(3),n=t?.enabled??!0;let r,o;e[0]!==n?(r=()=>{if(!n||!Na()||typeof document>"u")return;const a=iY,l=cY;a();const i=window.setInterval(l,aY);return document.addEventListener("visibilitychange",a),window.addEventListener("pagehide",a),window.addEventListener("pageshow",a),window.addEventListener("focus",a),window.addEventListener("blur",a),()=>{window.clearInterval(i),document.removeEventListener("visibilitychange",a),window.removeEventListener("pagehide",a),window.removeEventListener("pageshow",a),window.removeEventListener("focus",a),window.removeEventListener("blur",a)}},o=[n],e[0]=n,e[1]=r,e[2]=o):(r=e[1],o=e[2]),d.useEffect(r,o)};function iY(){ag(og()==="visible")}function cY(){og()==="visible"&&ag(!0)}const dY=3,uY=(t,e)=>{if(typeof t!="string")return e;const n=t.trim().replace(/\s+/g," ");return n?n.slice(0,48):e},fY=(t,e)=>{const n=e?[...t.filter(a=>a.id===e),...t.filter(a=>a.id!==e)]:t,r=[],o=new Set;for(const a of n){const l=typeof a.id=="string"?a.id.trim():"";if(!(!l||o.has(l))&&(o.add(l),r.push({sessionId:l,title:uY(a.title,`Session ${r.length+1}`)}),r.length>=dY))break}return r},mY=()=>{const t=Fe.c(9),e=Ze(hY),n=Ze(pY);let r;t[0]!==n||t[1]!==e?(r=fY(e,n),t[0]=n,t[1]=e,t[2]=r):r=t[2];const o=r;let a;t[3]!==o?(a=JSON.stringify(o),t[3]=o,t[4]=a):a=t[4];const l=a;let i,c;t[5]!==o||t[6]!==l?(i=()=>{if(typeof window>"u"||!Na())return;try{o.length===0?localStorage.removeItem(M5):localStorage.setItem(M5,l)}catch{return}window.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},c=[o,l],t[5]=o,t[6]=l,t[7]=i,t[8]=c):(i=t[7],c=t[8]),d.useEffect(i,c)};function hY(t){return t.sessions}function pY(t){return t.currentSessionId}const gY=()=>{const t=Fe.c(3),{browserTab:e}=P7();let n,r;t[0]!==e?(n=()=>{if(typeof window>"u"||!Na()||!e)return;let o=null,a=null;const l=()=>{a!==null&&(fe.dismiss(a),a=null)},i=async()=>{if(!o)return;const m=o;o=null,l(),await m.prompt();const{outcome:f}=await m.userChoice;f==="accepted"&&fe.success("Install started")},c=m=>{const f=m;typeof f.prompt=="function"&&(f.preventDefault(),o=f,a===null&&(a=fe.info("Install ArchCoder for quicker access",{duration:1/0,action:{label:"Install",onClick:()=>{i()}}})))},u=()=>{o=null,l(),fe.success("ArchCoder installed")};return window.addEventListener("beforeinstallprompt",c),window.addEventListener("appinstalled",u),()=>{l(),window.removeEventListener("beforeinstallprompt",c),window.removeEventListener("appinstalled",u)}},r=[e],t[0]=e,t[1]=n,t[2]=r):(n=t[1],r=t[2]),d.useEffect(n,r)},xY="ArchCoder",bh=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),bY=t=>{const n=t.replace(/\\/g,"/").replace(/\/+$/,"").split("/").filter(Boolean);return n[n.length-1]??""},vY=(t,e)=>[t,e,xY].filter(r=>typeof r=="string"&&r.trim().length>0).join(" | "),yY=()=>{const t=vs(a=>a.activeProjectId?a.projects.find(l=>l.id===a.activeProjectId)??null:null),e=d.useMemo(()=>{if(!t)return null;const a=t.label?.trim();if(a)return bh(a);const l=bY(t.path);return l?bh(l):null},[t]),[n,r]=d.useState(null);d.useEffect(()=>{if(typeof window>"u"||!Rn()){r(null);return}let a=!1;const l=async()=>{try{const c=window.location.href,u=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(Ci(c,u)){a||r(null);return}const f=(await Vu()).hosts.find(p=>Ci(c,p.url)),h=f?.label?.trim()?Br(f.label.trim()):"Instance";a||r(h)}catch{a||r("Instance")}};l();const i=()=>{l()};return window.addEventListener("focus",i),()=>{a=!0,window.removeEventListener("focus",i)}},[]);const o=d.useMemo(()=>vY(e,n),[e,n]);d.useEffect(()=>{if(typeof document<"u"&&(document.title=o),!_n())return;let a=!1;return(async()=>{try{const{getCurrentWindow:i}=await Kn(async()=>{const{getCurrentWindow:m}=await import("./vendor-.bun-HTKwyaEM.js").then(f=>f.fG);return{getCurrentWindow:m}},__vite__mapDeps([0,1]));if(a||typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""))return;await i().setTitle(o)}catch{return}})(),()=>{a=!0}},[o])},wY=50,jY=15e3,kY=2*6e4,NY=15e3,SY=5e3,CY=t=>{if(typeof t!="string")return null;const e=t.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n==="/"?"/":n.replace(/\/+$/,"")},AY=(t,e)=>t===e?jY:kY,MY=(t,e)=>t?t.branch!==e.branch||t.tracking!==e.tracking||t.ahead!==e.ahead||t.behind!==e.behind:!!e.branch,vd=(t,e)=>{const n=[];return e.forEach(r=>{const o=t.get(r);o?.branch&&n.push({directory:r,branch:o.branch,remoteName:null})}),n},FY=(t,e)=>{const n=dn(N=>N.currentDirectory),r=vs(N=>N.projects),o=Ze(N=>N.sessions),a=Ze(N=>N.archivedSessions),l=Ze(N=>N.availableWorktreesByProject),i=Ze(N=>N.worktreeMetadata),c=ir(N=>N.status),u=ir(N=>N.hasChecked),m=ir(N=>N.refreshStatus),f=mo(N=>N.syncBackgroundTargets),h=mo(N=>N.refreshTargets),[p,g]=d.useState(new Map),x=d.useRef(new Map),b=d.useRef([]),v=d.useRef(new Map);d.useEffect(()=>{x.current=p},[p]);const y=d.useCallback(N=>{if(N.length===0)return;const S=new Map;N.forEach(k=>{const j=`${k.directory}::${k.branch}`;S.set(j,k)}),S.forEach((k,j)=>{const F=v.current.get(j);typeof F=="number"&&window.clearTimeout(F);const A=window.setTimeout(()=>{v.current.delete(j),h([k],{force:!0,silent:!0,markInitialResolved:!0})},SY);v.current.set(j,A)})},[h]);d.useEffect(()=>{!t||u||m(t)},[t,u,m]);const w=d.useMemo(()=>{const N=new Map,S=k=>{const j=CY(k);!j||N.has(j)||N.set(j,j)};return S(n),r.forEach(k=>{S(k.path)}),l.forEach(k=>{k.forEach(j=>{S(j.path)})}),i.forEach(k=>{S(k.path)}),[...o,...a].sort((k,j)=>(j.time?.updated??0)-(k.time?.updated??0)).forEach(k=>{const j=k;S(j.directory??null),S(j.project?.worktree??null)}),Array.from(N.values()).slice(0,wY)},[a,l,n,r,o,i]);d.useEffect(()=>{let N=!1;const S=async(F=!1)=>{const A=Date.now(),M=w.filter(P=>{const D=x.current.get(P);return!D||F?!0:A-D.fetchedAt>AY(P,n)});if(M.length===0)return vd(x.current,w);const B=await Promise.all(M.map(async P=>{try{const D=await e.getGitStatus(P),L=typeof D.current=="string"?D.current.trim():"";return{directory:P,branch:L&&L!=="HEAD"?L:null,tracking:typeof D.tracking=="string"?D.tracking:null,ahead:typeof D.ahead=="number"?D.ahead:0,behind:typeof D.behind=="number"?D.behind:0}}catch{return{directory:P,branch:null,tracking:null,ahead:0,behind:0}}}));if(N)return[];const E=new Map(x.current),I=[];return B.forEach(({directory:P,branch:D,tracking:L,ahead:T,behind:_})=>{const z=E.get(P),R={branch:D,tracking:L,ahead:T,behind:_,fetchedAt:Date.now()};E.set(P,R),D&&MY(z,R)&&I.push({directory:P,branch:D,remoteName:null})}),g(P=>{let D=!1;if(P.size!==E.size)D=!0;else for(const[L,T]of E.entries()){const _=P.get(L);if(!_||_.branch!==T.branch||_.tracking!==T.tracking||_.ahead!==T.ahead||_.behind!==T.behind){D=!0;break}}return x.current=E,D?E:P}),I.length>0&&(h(I,{force:!0,silent:!0,markInitialResolved:!0}),y(I)),vd(E,w)};S();const k=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||S()},NY),j=()=>{typeof document<"u"&&document.visibilityState!=="visible"||S(!0).then(F=>{const A=F.length>0?F:b.current;if(A.length===0)return;const M=n?A.filter(B=>B.directory===n):[];M.length>0&&h(M,{force:!0,silent:!0,markInitialResolved:!0}),h(A,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})})};return window.addEventListener("focus",j),document.addEventListener("visibilitychange",j),()=>{N=!0,window.clearInterval(k),window.removeEventListener("focus",j),document.removeEventListener("visibilitychange",j)}},[w,n,e,h,y]),d.useEffect(()=>{const N=new Set(w);g(S=>{let k=!1;const j=new Map;return S.forEach((F,A)=>{if(!N.has(A)){k=!0;return}j.set(A,F)}),k?(x.current=j,j):S})},[w]);const C=d.useMemo(()=>vd(p,w),[p,w]);d.useEffect(()=>{b.current=C},[C]),d.useEffect(()=>{const N=v.current;return()=>{N.forEach(S=>{window.clearTimeout(S)}),N.clear()}},[]),d.useEffect(()=>{f({targets:C,github:t,githubAuthChecked:u,githubConnected:c?.connected??null})},[t,u,c?.connected,f,C])};function BY(){const t=Fe.c(41);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Set(["edit","multiedit","apply_patch","write","file_write","create"]),t[0]=e):e=t[0];const n=e,{git:r}=ur(),o=dn(_Y),{currentSessionId:a,sessions:l,worktreeMetadata:i,sessionStatus:c}=Ze(),{setActiveDirectory:u,startPolling:m,setPollingMode:f,stopPolling:h,fetchAll:p,fetchStatus:g,clearDiffCache:x}=Wn(),b=d.useRef(null),v=d.useRef(0);let y;t[1]!==a||t[2]!==i?(y=a?i.get(a)??void 0:void 0,t[1]=a,t[2]=i,t[3]=y):y=t[3];const w=y;let C;if(t[4]!==a||t[5]!==l){let R;t[7]!==a?(R=W=>W.id===a,t[7]=a,t[8]=R):R=t[8],C=l.find(R),t[4]=a,t[5]=l,t[6]=C}else C=t[6];const S=C?.directory??null,k=w?.path??S??o??null;let j;e:{if(!a){j="idle";break e}let R;t[9]!==a||t[10]!==c?(R=c?.get(a)?.type,t[9]=a,t[10]=c,t[11]=R):R=t[11];const W=R;if(W==="busy"||W==="retry"){j=W;break e}j="idle"}const F=j,A=F==="busy"||F==="retry"?"busy":"normal";let M,B;t[12]!==A||t[13]!==f?(M=()=>{f(A)},B=[A,f],t[12]=A,t[13]=f,t[14]=M,t[15]=B):(M=t[14],B=t[15]),d.useEffect(M,B);let E;t[16]!==x||t[17]!==k||t[18]!==g||t[19]!==r?(E=(R,W)=>{const G=R===void 0?300:R;if(!r)return;const J=(typeof W?.directory=="string"&&W.directory.trim().length>0&&W.directory!=="global"?W.directory.trim():null)??k;if(!J)return;const V=W?.forceDiffRefresh===!0;Date.now()-v.current<800||(b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{b.current=null,v.current=Date.now(),(async()=>{const U=await g(J,r,{silent:!0});V&&!U&&x(J)})()},G))},t[16]=x,t[17]=k,t[18]=g,t[19]=r,t[20]=E):E=t[20];const I=E;let P;t[21]!==k||t[22]!==p||t[23]!==r||t[24]!==u||t[25]!==m||t[26]!==h?(P=()=>{if(!k||!r){h();return}return u(k),p(k,r,{silentIfCached:!0}),m(r),()=>{h()}},t[21]=k,t[22]=p,t[23]=r,t[24]=u,t[25]=m,t[26]=h,t[27]=P):P=t[27];let D;t[28]!==F||t[29]!==k||t[30]!==p||t[31]!==r||t[32]!==u||t[33]!==m||t[34]!==h?(D=[F,k,p,r,u,m,h],t[28]=F,t[29]=k,t[30]=p,t[31]=r,t[32]=u,t[33]=m,t[34]=h,t[35]=D):D=t[35],d.useEffect(P,D);let L,T;t[36]!==I?(T=()=>{if(typeof window>"u")return;const R=W=>{const G=W,Y=typeof G.detail?.toolName=="string"?G.detail.toolName.toLowerCase():null;I(200,{directory:G.detail?.directory??null,forceDiffRefresh:!!(Y&&n.has(Y))})};return window.addEventListener("archcoder:git-refresh-hint",R),()=>{window.removeEventListener("archcoder:git-refresh-hint",R)}},L=[n,I],t[36]=I,t[37]=L,t[38]=T):(L=t[37],T=t[38]),d.useEffect(T,L);let _,z;t[39]===Symbol.for("react.memo_cache_sentinel")?(_=()=>()=>{b.current&&(clearTimeout(b.current),b.current=null)},z=[],t[39]=_,t[40]=z):(_=t[39],z=t[40]),d.useEffect(_,z)}function _Y(t){return t.currentDirectory}function EY(t){const e=Fe.c(2),{children:n}=t;BY();let r;return e[0]!==n?(r=s.jsx(s.Fragment,{children:n}),e[0]=n,e[1]=r):r=e[1],r}const DY="curl -fsSL https://opencode.ai/install | bash",IY=3e3,TY="https://opencode.ai/docs",PY="https://opencode.ai/docs/windows-wsl";function RY(t){const e=Fe.c(4),{onCopy:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs("code",{children:[s.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),s.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),s.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),s.jsx("span",{className:"text-muted-foreground",children:" | "}),s.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),e[0]=r):r=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(nr,{className:"h-4 w-4"}),e[1]=o):o=e[1];let a;return e[2]!==n?(a=s.jsxs("div",{className:"flex items-center justify-center gap-3",children:[r,s.jsx("button",{onClick:n,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors",title:"Copy to clipboard",children:o})]}),e[2]=n,e[3]=a):a=e[3],a}const zY=3e4;function LY({onCliAvailable:t}){const[e,n]=d.useState(!1),[r,o]=d.useState(!1),[a,l]=d.useState(!1),[i,c]=d.useState(!1),[u,m]=d.useState(""),[f,h]=d.useState("unknown");d.useEffect(()=>{const N=setTimeout(()=>o(!0),zY);return()=>clearTimeout(N)},[]),d.useEffect(()=>{l(Rn())},[]),d.useEffect(()=>{if(typeof navigator>"u"){h("unknown");return}const N=navigator.userAgent||"";if(/Windows/i.test(N)){h("windows");return}if(/Macintosh|Mac OS X/i.test(N)){h("macos");return}if(/Linux/i.test(N)){h("linux");return}h("unknown")},[]),d.useEffect(()=>{let N=!1;return(async()=>{try{const S=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const k=await S.json().catch(()=>null);if(!k||N)return;const j=typeof k.opencodeBinary=="string"?k.opencodeBinary.trim():"";j&&m(j)}catch{}})(),()=>{N=!0}},[]);const p=d.useCallback(async N=>{if(!N.target.closest("button, a, input, select, textarea, code")&&N.button===0&&a&&_n())try{const{getCurrentWindow:S}=await Kn(async()=>{const{getCurrentWindow:j}=await import("./vendor-.bun-HTKwyaEM.js").then(F=>F.fG);return{getCurrentWindow:j}},__vite__mapDeps([0,1]));await S().startDragging()}catch(S){console.error("Failed to start window dragging:",S)}},[a]),g=d.useCallback(async()=>{try{const N=await fetch("/health");if(!N.ok)return!1;const S=await N.json();return S.openCodeRunning===!0||S.isOpenCodeReady===!0}catch{return!1}},[]),x=d.useCallback(async()=>{c(!0);try{await fetch("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>c(!1),1e3)}},[]),b=d.useCallback(async()=>{if(typeof window>"u"||!a)return;const N=await Pu({filters:[{name:"Executables",extensions:["*"]}]});N.success&&N.path&&m(N.path.trim())},[a]),v=d.useCallback(async()=>{c(!0);try{await ln({opencodeBinary:u.trim()}),await fetch("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>c(!1),1e3)}},[u]),y=d.useCallback(async()=>{const N=await Dn(DY);N.ok?(n(!0),setTimeout(()=>n(!1),2e3)):console.error("Failed to copy:",N.error)},[]);d.useEffect(()=>{const N=async()=>{await g()&&t?.()},S=setInterval(N,IY);return N(),()=>clearInterval(S)},[g,t]);const w=f==="windows"?PY:TY,C=f==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":f==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode";return s.jsxs("div",{className:"h-full flex items-center justify-center bg-transparent p-8 relative cursor-default select-none",onMouseDown:p,children:[s.jsxs("div",{className:"w-full space-y-4 text-center",children:[s.jsxs("div",{className:"space-y-4",children:[s.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-foreground",children:"Welcome to ArchCoder"}),s.jsxs("p",{className:"text-muted-foreground",children:[s.jsxs("a",{href:"https://opencode.ai",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline inline-flex items-center gap-1",children:["OpenCode CLI",s.jsx(wr,{className:"h-4 w-4"})]})," ","is required to continue."]})]}),f==="windows"&&s.jsxs("div",{className:"mx-auto max-w-2xl rounded-lg border border-border bg-background/50 p-4 text-left",children:[s.jsx("div",{className:"text-sm text-foreground",children:"Windows setup (WSL recommended)"}),s.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[s.jsxs("li",{children:["Install WSL (if needed) with ",s.jsx("code",{className:"text-foreground/80",children:"wsl --install"})," in PowerShell."]}),s.jsx("li",{children:"Run the install command below inside your WSL terminal."}),s.jsx("li",{children:"If ArchCoder does not detect OpenCode automatically, set the binary path below."})]})]}),s.jsx("div",{className:"flex justify-center",children:s.jsx("div",{className:"bg-background/60 backdrop-blur-sm border border-border rounded-lg px-5 py-3 font-mono text-sm w-fit",children:e?s.jsxs("div",{className:"flex items-center justify-center gap-2",style:{color:"var(--status-success)"},children:[s.jsx(js,{className:"h-4 w-4"}),"Copied to clipboard"]}):s.jsx(RY,{onCopy:y})})}),s.jsxs("a",{href:w,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1 justify-center",children:[f==="windows"?"View Windows + WSL documentation":"View documentation",s.jsx(wr,{className:"h-3 w-3"})]}),s.jsx("p",{className:"text-sm text-muted-foreground animate-pulse",children:"Waiting for OpenCode installation..."}),s.jsx("div",{className:"flex justify-center",children:s.jsx("button",{type:"button",onClick:x,disabled:i,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:i?"Retrying…":"Retry"})}),s.jsx("div",{className:"mx-auto w-full max-w-xl pt-4",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"text-sm text-muted-foreground",children:"Already installed? Set the OpenCode CLI path:"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Xt,{value:u,onChange:N=>m(N.target.value),placeholder:C,disabled:i,className:"flex-1 font-mono text-xs"}),s.jsx(Be,{type:"button",variant:"secondary",onClick:b,disabled:i||!a,children:"Browse"}),s.jsx(Be,{type:"button",onClick:v,disabled:i,children:"Apply"})]}),s.jsx("div",{className:"text-xs text-muted-foreground/70",children:"Saves to ArchCoder settings and reloads OpenCode configuration."})]})})]}),r&&s.jsx("div",{className:"absolute bottom-8 left-0 right-0 text-center space-y-1",children:f==="windows"?s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"text-sm text-muted-foreground/70",children:"On Windows, install and run OpenCode in WSL for best compatibility."}),s.jsxs("p",{className:"text-sm text-muted-foreground/70",children:["If detection fails, set a native path (",s.jsx("code",{className:"text-foreground/70",children:"opencode.cmd"}),"/",s.jsx("code",{className:"text-foreground/70",children:"opencode.exe"}),"), ",s.jsx("code",{className:"text-foreground/70",children:"wsl.exe"}),", or ",s.jsx("code",{className:"text-foreground/70",children:"wsl:/usr/local/bin/opencode"}),"."]})]}):s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"text-sm text-muted-foreground/70",children:["Already installed? Make sure ",s.jsx("code",{className:"text-foreground/70",children:"opencode"})," is in your PATH"]}),s.jsxs("p",{className:"text-sm text-muted-foreground/70",children:["or set ",s.jsx("code",{className:"text-foreground/70",children:"OPENCODE_BINARY"})," environment variable."]}),s.jsxs("p",{className:"text-sm text-muted-foreground/70",children:["If you see ",s.jsx("code",{className:"text-foreground/70",children:"env: node: No such file or directory"})," or ",s.jsx("code",{className:"text-foreground/70",children:"env: bun: No such file or directory"}),", install that runtime or ensure it is on PATH."]})]})})]})}const HY=()=>{const t=Fe.c(5),[e,n]=d.useState($Y),{isUpdating:r,message:o}=e;let a,l;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>Mv(n),l=[],t[0]=a,t[1]=l):(a=t[0],l=t[1]),d.useEffect(a,l),!r)return null;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(tc,{width:80,height:80,isAnimated:!0}),t[2]=i):i=t[2];let c;return t[3]!==o?(c=s.jsxs("div",{"data-blur-bg":!0,className:"fixed inset-0 z-[9999] flex flex-col items-center justify-center gap-6 backdrop-blur-md",children:[i,s.jsx("p",{className:"typography-body text-muted-foreground",children:o})]}),t[3]=o,t[4]=c):c=t[4],c};function $Y(){return Av()}const gu={getLastAssistantMessage(){const t=Ze.getState(),e=t.currentSessionId;if(!e)return console.log("[ERROR] No active session"),null;const n=t.messages.get(e);if(!n||n.length===0)return console.log("[ERROR] No messages in current session"),null;for(let r=n.length-1;r>=0;r--){const o=n[r];if(o.info.role==="assistant"){const a=o.parts.map(h=>{const p={id:h.id,type:h.type};return h.type==="text"?(p.text=h.text,p.textLength=h.text?.length||0):h.type==="tool"?(p.tool=h.tool,p.state=h.state?.status):(h.type==="step-start"||h.type==="step-finish")&&(p.isStepMarker=!0),p}),l=a.some(h=>h.type==="text"&&h.text&&h.text.trim().length>0),i=a.some(h=>h.type==="tool"),c=a.some(h=>h.type==="step-start"||h.type==="step-finish"),u=a.length===0,m=!l&&!i&&(!u||c),f={messageId:o.info.id,role:o.info.role,timestamp:o.info.time?.created||0,partsCount:a.length,parts:a,isEmpty:u,isEmptyResponse:m,raw:o};return console.log("[INSPECT] Last Assistant Message:",f),console.log("[SUMMARY] Summary:",{messageId:f.messageId,partsCount:f.partsCount,isEmpty:f.isEmpty,isEmptyResponse:f.isEmptyResponse,hasText:l,hasTools:i,hasStepMarkers:c,onlyStepMarkers:c&&!l&&!i}),f.isEmpty&&console.warn("[WARNING] Message has NO parts!"),f.isEmptyResponse&&(console.warn("[WARNING] Message has parts but NO meaningful content (empty text, no tools)!"),c&&!l&&!i&&(console.warn("[CRITICAL] CLAUDE EMPTY RESPONSE BUG: Only step-start/step-finish markers, no actual content!"),console.log("This is a known issue with Claude models (anthropic provider)"),console.log("Recommendation: Send a follow-up message or try a different model"))),f}}return console.log("[ERROR] No assistant messages found in current session"),null},truncateString(t,e=80){return!t||typeof t!="string"||t.length<=e?t:t.substring(0,e)+"…"},truncateMessages(t){return t.map(e=>({...e,parts:(e.parts||[]).map(n=>{const r={...n};return"text"in n&&(r.text=this.truncateString(n.text)),"textPreview"in n&&(r.textPreview=this.truncateString(n.textPreview)),n.state&&(r.state={...n.state},"output"in n.state&&(r.state.output=this.truncateString(n.state.output)),"error"in n.state&&(r.state.error=this.truncateString(n.state.error)),n.state.metadata&&"preview"in n.state.metadata&&(r.state.metadata={...n.state.metadata,preview:this.truncateString(n.state.metadata.preview)})),r})}))},getAllMessages(t=!1){const e=Ze.getState(),n=e.currentSessionId;if(!n)return console.log("[ERROR] No active session"),[];const r=e.messages.get(n)||[];return console.log(`[MESSAGES] Total messages in session: ${r.length}`),r.forEach((o,a)=>{console.log(`[${a}] ${o.info.role} - ${o.info.id} - ${o.parts.length} parts`)}),t?this.truncateMessages(r):r},async getAppStatus(){const t=dn.getState(),e=Ze.getState(),n=vs.getState(),r=t.currentDirectory||null,o=En.getDirectory()??null,a=e.sessions||[],l=new Set,i={};a.forEach(k=>{const j=k.directory;typeof j=="string"&&j.trim().length>0?(l.add(j),i[j]=(i[j]??0)+1):i["(none)"]=(i["(none)"]??0)+1});const c=(()=>{if(typeof window>"u")return{available:!1};try{return{available:!0,lastDirectory:window.localStorage.getItem("lastDirectory"),homeDirectory:window.localStorage.getItem("homeDirectory")}}catch(k){return{available:!1,error:k instanceof Error?k.message:String(k)}}})(),u=typeof window<"u"?window.__OPENCHAMBER_RUNTIME_APIS__:null,m=typeof window<"u"&&!!window.__TAURI__,f=async k=>{try{return await k.json()}catch{return null}},h=async k=>{try{return await k.text()}catch{return null}},p=async k=>{try{const j=await fetch(k);return j.ok?await f(j):{status:j.status}}catch(j){return{error:j instanceof Error?j.message:String(j)}}};let g=null,x=null,b=null,v=null;const y=r?`/api/path?directory=${encodeURIComponent(r)}`:"/api/path";g=await p(y);const w=r?`/api/project/current?directory=${encodeURIComponent(r)}`:"/api/project/current";x=await p(w),b=await p("/api/config/settings");try{const k=await fetch("/api/health"),j=k.headers.get("content-type")||"",F=await h(k),A=j.toLowerCase().includes("application/json");let M=null;if(A&&F)try{const B=JSON.parse(F);B&&typeof B=="object"&&!Array.isArray(B)&&(M=B)}catch{M=null}v={status:k.status,ok:k.ok,contentType:j,type:A?"json":"html",openCodePort:M?.openCodePort??null,openCodeRunning:M?.openCodeRunning??null,openCodeSecureConnection:M?.openCodeSecureConnection??null,openCodeAuthSource:M?.openCodeAuthSource??null,isOpenCodeReady:M?.isOpenCodeReady??null,lastOpenCodeError:M?.lastOpenCodeError??null,preview:F?F.slice(0,120):null}}catch(k){v={error:k instanceof Error?k.message:String(k)}}let C={isGitRepo:null};if(r)try{C.isGitRepo=await Ri(r)}catch(k){C={isGitRepo:null,error:k instanceof Error?k.message:String(k)}}const N=n.projects.map(k=>({id:k.id,path:k.path,label:k.label})),S={runtime:{platform:u?.runtime?.platform??null,isDesktop:m,isVSCode:!!u?.runtime?.isVSCode,hasRuntimeApis:!!u,desktopServerOrigin:null},location:typeof window<"u"?{href:window.location?.href??null,origin:window.location?.origin??null}:null,directories:{currentDirectory:r,opencodeDirectory:g?.directory||g?.worktree||o,homeDirectory:t.homeDirectory||null,isHomeReady:t.isHomeReady,hasPersistedDirectory:t.hasPersistedDirectory,isSwitchingDirectory:t.isSwitchingDirectory},projects:{total:n.projects.length,activeProjectId:n.activeProjectId,samples:N},sessions:{total:a.length,currentSessionId:e.currentSessionId,lastLoadedDirectory:e.lastLoadedDirectory,uniqueDirectories:l.size,directorySamples:Array.from(l).slice(0,5),directoryCounts:i},worktrees:{available:e.availableWorktrees.length,metadataEntries:e.worktreeMetadata.size},git:C,localStorage:c,opencode:{pathInfo:g,projectInfo:x,health:v},openchamber:{settingsInfo:b}};return console.log("[DEBUG] App status snapshot:",S),S},async buildDiagnosticsReport(){const t=await this.getAppStatus();return JSON.stringify(t,null,2)},async copyTextToClipboard(t){return Dn(t)},async copyDiagnosticsReport(){const t=await this.buildDiagnosticsReport();return{...await this.copyTextToClipboard(t),report:t}},checkLastMessage(){const t=this.getLastAssistantMessage();if(!t)return!1;const e=t.isEmpty||t.isEmptyResponse;return e?(console.error("[ALERT] PROBLEMATIC MESSAGE DETECTED!"),console.log("Details:",{messageId:t.messageId,isEmpty:t.isEmpty,isEmptyResponse:t.isEmptyResponse,partsCount:t.partsCount}),t.parts.length>0&&console.log("Parts:",t.parts)):console.log("[OK] Last message looks good!"),e},getStreamingState(){const t=Ze.getState(),e=t.currentSessionId?t.streamingMessageIds.get(t.currentSessionId)??null:null;return console.log("[STREAM] Streaming State:",{streamingMessageId:e,streamingMessageIds:Array.from(t.streamingMessageIds.entries()),messageStreamStates:Array.from(t.messageStreamStates.entries())}),{streamingMessageId:e,streamingMessageIds:t.streamingMessageIds,streamStates:t.messageStreamStates}},findEmptyMessages(){const t=Ze.getState(),e=t.currentSessionId;if(!e)return console.log("[ERROR] No active session"),[];const r=(t.messages.get(e)||[]).filter(o=>o.info.role==="assistant").filter(o=>{const a=o.parts||[],l=a.some(c=>c.type==="text"&&c.text&&c.text.trim().length>0),i=a.some(c=>c.type==="tool");return a.length===0||!l&&!i});return console.log(`[INSPECT] Found ${r.length} empty assistant messages`),r.forEach((o,a)=>{console.log(`[${a}] Empty message:`,{messageId:o.info.id,partsCount:o.parts.length,provider:o.info.providerID,model:o.info.modelID,timestamp:o.info.time?.created})}),r},showRetryHelp(){console.log(`[DEBUG] How to handle empty Claude responses:
8013
8013
  `),console.log("1. Check the last message:"),console.log(` __opencodeDebug.getLastAssistantMessage()
8014
8014
  `),console.log("2. Find all empty messages in session:"),console.log(` __opencodeDebug.findEmptyMessages()
8015
8015
  `),console.log("3. To retry, you can:"),console.log(" - Edit your last user message and resend"),console.log(' - Send a follow-up message like "Please provide the response"'),console.log(` - Try a different model (OpenAI models tend to be more reliable)
8016
- `),console.log("[TIP] Empty responses are usually due to:"),console.log(" - Model rate limits"),console.log(" - Context length issues"),console.log(" - Model refusing to respond to certain prompts"),console.log(" - API errors from provider")},analyzeMessageCompletionConsistency(t={}){const{includeNonAssistant:e=!1,verbose:n=!0,maxTableRows:r=25}=t,o=Ze.getState(),a=o.currentSessionId;if(!a)return console.log("[ERROR] No active session"),{summary:null,rows:[]};const l=o.messages.get(a)||[],i=e?l:l.filter(h=>h.info.role==="assistant"),c={totalMessages:l.length,analyzedMessages:i.length,completedMissing:0,completedBeforeTool:0,completedBeforeReasoning:0,runningToolsWhenCompleted:0,reasoningOpenWhenCompleted:0,withTools:0,withReasoning:0},u=h=>typeof h=="number"&&Number.isFinite(h)?h:null,m=h=>{const p=h.filter(g=>typeof g=="number");return p.length>0?Math.max(...p):null},f=i.map((h,p)=>{const g=h.info??{},x=Array.isArray(h.parts)?h.parts:[],b=g.time??{},v=u(b.completed),y=v!==null,w=x.filter(B=>B.type==="tool"),C=x.filter(B=>B.type==="reasoning"),N=m(w.map(B=>u(B.state?.time?.end??B.state?.time?.start))),S=m(C.map(B=>u(B.time?.end??B.time?.start))),k=m([N,S].filter(B=>B!==null)),j=w.some(B=>["pending","running","started"].includes(B.state?.status)),F=C.some(B=>typeof B.time?.end!="number");w.length>0&&(c.withTools+=1),C.length>0&&(c.withReasoning+=1),y||(c.completedMissing+=1);const A=!!(y&&typeof N=="number"&&v<N);A&&(c.completedBeforeTool+=1);const M=!!(y&&typeof S=="number"&&v<S);return M&&(c.completedBeforeReasoning+=1),y&&j&&(c.runningToolsWhenCompleted+=1),y&&F&&(c.reasoningOpenWhenCompleted+=1),{index:p,messageId:g.id,role:g.role,completedAt:v,latestToolTimestamp:N,latestReasoningTimestamp:S,latestPartTimestamp:k,completed_missing:!y,completed_before_tool:A,completed_before_reasoning:M,running_tools_when_completed:!!(y&&j),reasoning_open_when_completed:!!(y&&F),has_tools:w.length>0,has_reasoning:C.length>0}});return n&&(console.table(f.slice(0,r)),f.length>r&&console.log(`Displayed first ${r} rows out of ${f.length}.`),console.log("[SUMMARY] Message completion timing:",c)),{summary:c,rows:f}},checkCompletionStatus(){const t=Ze.getState(),e=t.currentSessionId;if(!e)return console.log("[ERROR] No active session"),null;const r=(t.messages.get(e)||[]).filter(b=>b.info.role==="assistant");if(r.length===0)return console.log("[ERROR] No assistant messages"),null;const o=r[r.length-1],a=o.parts.filter(b=>b.type==="step-finish"),l=o.info.finish==="stop",c=o.info.time?.completed,u=o.info.status,m=typeof c=="number"&&c>0||u==="completed",f=!!(m&&l),h=t.messageStreamStates,p=o.info.sessionID?t.streamingMessageIds.get(o.info.sessionID)??null:null,g=h.get(o.info.id),x=o.info.id===p;return console.log("[SUMMARY] Completion Status:"),console.log("Message ID:",o.info.id),console.log("time.completed:",c,"(type:",typeof c,")"),console.log("status:",u),console.log("hasCompletedFlag:",m),console.log("hasStopReason:",l),console.log("messageIsComplete:",f),console.log("lifecycle phase:",g?.phase),console.log("isStreamingCandidate:",x),console.log("streamingMessageId:",p),console.log("Step-finish parts:",a),{messageId:o.info.id,completed:c,status:u,hasCompletedFlag:m,hasStopReason:l,messageIsComplete:f,stepFinishParts:a,raw:o}}};typeof window<"u"&&(window.__opencodeDebug=gu,D6()&&(console.log("[DEBUG] OpenCode Debug Utils loaded! Use window.__opencodeDebug in console"),console.log("Available commands:"),console.log(" __opencodeDebug.getLastAssistantMessage() - Get last assistant message details"),console.log(" __opencodeDebug.getAllMessages(truncate?) - List all messages (truncate=true for short preview)"),console.log(" __opencodeDebug.truncateMessages(messages) - Truncate long fields in messages array"),console.log(" __opencodeDebug.getAppStatus() - Show app status snapshot"),console.log(" __opencodeDebug.checkLastMessage() - Check if last message is problematic"),console.log(" __opencodeDebug.findEmptyMessages() - Find all empty assistant messages"),console.log(" __opencodeDebug.showRetryHelp() - Show instructions for handling empty responses"),console.log(" __opencodeDebug.getStreamingState() - Get streaming state info"),console.log(" __opencodeDebug.analyzeMessageCompletionConsistency(opts?) - Compare time.completed vs part timings"),console.log(" __opencodeDebug.checkCompletionStatus() - Check completion status of last message")),window.addEventListener("error",t=>{try{const e=t.message||"",n=t.filename||"";typeof e=="string"&&e.includes("this._renderer.value.dimensions")&&/xterm/i.test(String(n))&&t.preventDefault()}catch{}}));const OY=({open:t,onOpenChange:e})=>{const[n,r]=d.useState(null),[o,a]=d.useState(!1),[l,i]=d.useState(!1),[c,u]=d.useState(null),[m,f]=d.useState(!1),h=d.useCallback(async()=>{if(!o){a(!0),i(!1);try{if(!c){fe.error("Copy failed",{description:"Diagnostics not ready yet. Wait a second and retry."});return}const g=await gu.copyTextToClipboard(c);g.ok?(i(!0),fe.success("Diagnostics copied")):fe.error("Copy failed",{description:g.error})}catch(g){fe.error("Copy failed"),console.error("Failed to copy diagnostics:",g)}finally{a(!1)}}},[c,o]);d.useEffect(()=>{if(!t)return;typeof window<"u"&&!!window.__TAURI__?(async()=>{try{const{getVersion:b}=await Kn(async()=>{const{getVersion:y}=await import("./vendor-.bun-HTKwyaEM.js").then(w=>w.fI);return{getVersion:y}},__vite__mapDeps([0,1])),v=await b();r(v)}catch{r("2.0.2")}})():r("2.0.2")},[t]),d.useEffect(()=>{if(!t){u(null),f(!1);return}let g=!1;return f(!0),gu.buildDiagnosticsReport().then(x=>{g||u(x)}).catch(x=>{g||(console.error("Failed to prepare diagnostics:",x),u(null))}).finally(()=>{g||f(!1)}),()=>{g=!0}},[t]);const p=n;return s.jsx(Os,{open:t,onOpenChange:e,children:s.jsx(Vs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(tc,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"ArchCoder"}),p&&s.jsxs("p",{className:"typography-meta text-muted-foreground",children:["Version ",p]})]}),s.jsxs("p",{className:"typography-meta text-muted-foreground",children:["A fan-made interface for"," ",s.jsx("a",{href:"https://opencode.ai/",target:"_blank",rel:"noopener noreferrer",className:"hover:text-foreground transition-colors",children:"OpenCode"})," ","agent"]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:h,disabled:o||m||!c,className:Q("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:l?"Diagnostics copied":m?"Preparing diagnostics...":"Copy diagnostics"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:"Includes ArchCoder state, OpenCode health, directories, and projects."})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",children:[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(w6,{className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/btriapitsyn",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(Ad,{className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:"Made with love to comunity"})]})})})};function E0(t){const e=Fe.c(3),{apis:n,children:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx(Z2.Provider,{value:n,children:r}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o}const VY=/ENOENT|spawn\s+opencode|Unable\s+to\s+locate\s+the\s+opencode\s+CLI|OpenCode\s+CLI\s+not\s+found|opencode(\.exe)?\s+not\s+found|opencode(\.exe)?:\s*command\s+not\s+found|not\s+recognized\s+as\s+an\s+internal\s+or\s+external\s+command|env:\s*['"]?(node|bun)['"]?:\s*No\s+such\s+file\s+or\s+directory|(node|bun):\s*No\s+such\s+file\s+or\s+directory/i,UY=1500,WY=()=>rs($r(XY)),qY=()=>Ze($r(QY)),GY=()=>dn($r(JY)),ZY=()=>{const t=Fe.c(3),{isAboutDialogOpen:e,setAboutDialogOpen:n}=Ee();let r;return t[0]!==e||t[1]!==n?(r=s.jsx(OY,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},KY=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search);if(t.get("ocPanel")!=="session-chat")return null;const 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}};function YY({apis:t}){const{initializeApp:e,isInitialized:n,isConnected:r}=rs(),{providersCount:o,agentsCount:a,loadProviders:l,loadAgents:i}=WY(),{error:c,clearError:u,loadSessions:m}=Ze(),{currentSessionId:f,setCurrentSession:h,sessions:p}=qY(),{currentDirectory:g,setDirectory:x,isSwitchingDirectory:b}=GY(),[v,y]=d.useState(!1),{uiFont:w,monoFont:C}=AH(),N=ir(z=>z.refreshStatus),[S,k]=d.useState(()=>t.runtime.isVSCode),[j,F]=d.useState(!1),[A,M]=d.useState(!0),B=d.useMemo(()=>Rn(),[]),E=d.useRef(!1),I=d.useMemo(()=>KY(),[]),P=!I||A;d.useEffect(()=>{k(t.runtime.isVSCode)},[t.runtime.isVSCode]),d.useEffect(()=>($3(t),()=>$3(null)),[t]),d.useEffect(()=>{I||N(t.github,{force:!0})},[t.github,I,N]),FY(P?t.github:void 0,t.git),d.useEffect(()=>{if(typeof document>"u")return;const z=document.documentElement,R=o5[w]?.stack??o5[BH].stack,W=a5[C]?.stack??a5[_H].stack;z.style.setProperty("--font-sans",R),z.style.setProperty("--font-heading",R),z.style.setProperty("--font-family-sans",R),z.style.setProperty("--font-mono",W),z.style.setProperty("--font-family-mono",W),z.style.setProperty("--ui-regular-font-weight","400"),document.body&&(document.body.style.fontFamily=R)},[w,C]),d.useEffect(()=>{if(n){const R=setTimeout(()=>{const W=document.getElementById("initial-loading");W&&(W.classList.add("fade-out"),setTimeout(()=>{W.remove()},300))},150);return()=>clearTimeout(R)}},[n]),d.useEffect(()=>{const z=setTimeout(()=>{const R=document.getElementById("initial-loading");R&&!n&&(R.classList.add("fade-out"),setTimeout(()=>{R.remove()},300))},5e3);return()=>clearTimeout(z)},[n]),d.useEffect(()=>{(async()=>S||await e())()},[e,S]);const D=d.useRef(!1),L=d.useRef(0);d.useEffect(()=>{if(S||!r||o>0&&a>0||D.current)return;const z=Date.now();if(z-L.current<750)return;L.current=z,D.current=!0,(async()=>{try{o===0&&await l(),a===0&&await i()}catch{}finally{D.current=!1}})()},[a,r,S,i,l,o]),d.useEffect(()=>{if(b)return;(async()=>S||r&&(En.setDirectory(g),await m()))()},[g,b,m,r,S]),d.useEffect(()=>{if(!I||typeof window>"u")return;const z=G=>{const Y=G?.visible===!0;M(Y)},R=G=>{if(G.origin!==window.location.origin)return;const Y=G.data;Y?.type==="archcoder:embedded-visibility"&&z(Y.payload)},W=window;return W.__archcoderSetEmbeddedVisibility=z,window.addEventListener("message",R),()=>{window.removeEventListener("message",R),W.__archcoderSetEmbeddedVisibility===z&&delete W.__archcoderSetEmbeddedVisibility}},[I]),d.useEffect(()=>{!I?.directory||S||g!==I.directory&&x(I.directory,{showOverlay:!1})},[g,I,S,x]),d.useEffect(()=>{!I||S||f!==I.sessionId&&p.some(z=>z.id===I.sessionId)&&h(I.sessionId)},[f,I,S,p,h]),d.useEffect(()=>{if(!I||typeof window>"u")return;const z=R=>{R.storageArea===window.localStorage&&R.key==="ui-store"&&Ee.persist.rehydrate()};return window.addEventListener("storage",z),()=>{window.removeEventListener("storage",z)}},[I]),d.useEffect(()=>{typeof window>"u"||!n||b||E.current||(E.current=!0,window.__archcoderAppReady=!0,window.dispatchEvent(new Event("archcoder:app-ready")))},[n,b]),Fv({enabled:P}),Bv({enabled:P}),lY({enabled:P}),mY(),gY(),yY(),oY(),zK();const T=d.useCallback(()=>{y(z=>!z)},[]);LK(T),HK({enabled:P}),z7({enabled:P}),WK({enabled:P}),d.useEffect(()=>{if(I)return;const z=R=>{Du(R)&&R.shiftKey&&R.key==="D"&&(R.preventDefault(),y(W=>!W))};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[I]),d.useEffect(()=>{I||c&&setTimeout(()=>u(),5e3)},[u,I,c]),d.useEffect(()=>{if(I||!Rn()||!$o())return;let z=!1;const R=async()=>{const G=await fetch("/health",{method:"GET"}).catch(()=>null);if(!G||!G.ok||z)return;const Y=await G.json().catch(()=>null);if(!Y||z)return;const J=Y.openCodeRunning===!0,V=Y.isOpenCodeReady===!0,U=(typeof Y.opencodeBinaryResolved=="string"?Y.opencodeBinaryResolved.trim():"").length>0,X=typeof Y.lastOpenCodeError=="string"?Y.lastOpenCodeError:"",$=!J&&(VY.test(X)||!U&&!V);F($)};R();const W=window.setInterval(()=>{R()},UY);return()=>{z=!0,window.clearInterval(W)}},[I]);const _=d.useCallback(()=>{F(!1),window.location.reload()},[]);return j?s.jsx(An,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(LY,{onCliAvailable:_})})}):I?s.jsx(An,{children:s.jsx(E0,{apis:t,children:s.jsx(ii,{delayDuration:700,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(wi,{}),s.jsx(l0,{})]})})})}):S?(typeof window<"u"?window.__ARCHCODER_PANEL_TYPE__:"chat")==="agentManager"?s.jsx(An,{children:s.jsx(E0,{apis:t,children:s.jsx(ii,{delayDuration:700,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(AK,{}),s.jsx(l0,{})]})})})}):s.jsx(An,{children:s.jsx(E0,{apis:t,children:s.jsx(qm,{children:s.jsx(ii,{delayDuration:700,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(tK,{}),s.jsx(l0,{})]})})})})}):s.jsx(An,{children:s.jsx(E0,{apis:t,children:s.jsx(EY,{children:s.jsx(qm,{children:s.jsx(Tj,{children:s.jsx(ii,{delayDuration:700,skipDelayDuration:150,children:s.jsxs("div",{className:B?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(YZ,{}),s.jsx(l0,{}),s.jsx(HY,{}),s.jsx(ZY,{}),v&&s.jsx(MK,{onClose:()=>y(!1)})]})})})})})})})}function XY(t){return{providersCount:t.providers.length,agentsCount:t.agents.length,loadProviders:t.loadProviders,loadAgents:t.loadAgents}}function QY(t){return{currentSessionId:t.currentSessionId,setCurrentSession:t.setCurrentSession,sessions:t.sessions}}function JY(t){return{currentDirectory:t.currentDirectory,setDirectory:t.setDirectory,isSwitchingDirectory:t.isSwitchingDirectory}}const lg=async()=>{if(typeof window>"u")return;let t=null,e=null;try{t=window.localStorage.getItem("homeDirectory"),e=window.localStorage.getItem("lastDirectory")}catch(r){console.warn("Failed to read saved directory preferences:",r)}const n=dn.getState();t&&n.homeDirectory!==t&&n.synchronizeHomeDirectory(t),e&&!xn()&&n.setDirectory(e,{showOverlay:!1})},ig="/auth/session",eX=async()=>{console.log("[Frontend Auth] Checking session status...");const t=await fetch(ig,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return console.log("[Frontend Auth] Session status response:",t.status,t.statusText),t},tX=async t=>{console.log("[Frontend Auth] Submitting password...");const e=await fetch(ig,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:t})});return console.log("[Frontend Auth] Password submit response:",e.status,e.statusText),e},cg=t=>{const e=Fe.c(5),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={fontFamily:'"Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif'},e[0]=r):r=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-55",style:{background:"radial-gradient(120% 140% at 50% -20%, var(--surface-overlay) 0%, transparent 68%)"}}),e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx("div",{className:"pointer-events-none absolute inset-0",style:{backgroundColor:"var(--surface-subtle)",opacity:.22}}),e[2]=a):a=e[2];let l;return e[3]!==n?(l=s.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background text-foreground",style:r,children:[o,a,s.jsx("div",{className:"relative z-10 flex w-full justify-center px-4 py-12 sm:px-6",children:n})]}),e[3]=n,e[4]=l):l=e[4],l},sX=()=>{const t=Fe.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background text-foreground",children:s.jsx(tc,{width:120,height:120,isAnimated:!0})}),t[0]=e):e=t[0],e},vh=t=>{const e=Fe.c(12),{onRetry:n,errorType:r,retryAfter:o}=t,l=(r===void 0?"network":r)==="rate-limit",i=o?Math.ceil(o/60):1,c=l?"Too many attempts":"Unable to reach server";let u;e[0]!==c?(u=s.jsx("h1",{className:"typography-ui-header font-semibold text-destructive",children:c}),e[0]=c,e[1]=u):u=e[1];const m=l?`Please wait ${i} minute${i>1?"s":""} before trying again.`:"We couldn't verify the UI session. Check that the service is running and try again.";let f;e[2]!==m?(f=s.jsx("p",{className:"typography-meta text-muted-foreground max-w-xs",children:m}),e[2]=m,e[3]=f):f=e[3];let h;e[4]!==u||e[5]!==f?(h=s.jsxs("div",{className:"space-y-2",children:[u,f]}),e[4]=u,e[5]=f,e[6]=h):h=e[6];let p;e[7]!==n?(p=s.jsx(Be,{type:"button",onClick:n,className:"w-full max-w-xs",children:"Retry"}),e[7]=n,e[8]=p):p=e[8];let g;return e[9]!==h||e[10]!==p?(g=s.jsx(cg,{children:s.jsxs("div",{className:"flex flex-col items-center gap-6 text-center",children:[h,p]})}),e[9]=h,e[10]=p,e[11]=g):g=e[11],g},nX=({children:t})=>{const e=d.useMemo(()=>xn(),[]),n=e,r=d.useMemo(()=>Rn()&&!e,[e]),[o,a]=d.useState(()=>n?"authenticated":"pending"),[l,i]=d.useState(""),[c,u]=d.useState(!1),[m,f]=d.useState(""),[h,p]=d.useState(void 0),[g,x]=d.useState(!1),b=d.useRef(null),v=d.useRef(n),y=d.useCallback(async()=>{if(n){console.log("[Frontend Auth] VSCode runtime, skipping auth"),a("authenticated");return}const C=document.cookie,N=C.includes("oc_ui_session="),S=C.includes("oc_ui_refresh=");console.log("[Frontend Auth] Cookies check - access:",N,"refresh:",S),console.log("[Frontend Auth] All cookies:",C.split(";").map(k=>k.trim().split("=")[0])),a(k=>k==="authenticated"?k:"pending");try{const k=await eX(),j=await k.text();if(console.log("[Frontend Auth] Raw response:",k.status,j),k.ok){console.log("[Frontend Auth] Session is authenticated"),a("authenticated"),x(!1),f(""),p(void 0);return}if(k.status===401){let F={};try{F=JSON.parse(j)}catch{F={}}console.warn("[Frontend Auth] Session is locked (401)",F),F.debug&&console.warn("[Frontend Auth] Debug info:",F.debug),x(F.tunnelLocked===!0),a("locked"),p(void 0);return}if(k.status===429){let F={};try{F=JSON.parse(j)}catch{F={}}p(F.retryAfter),x(!1),a("rate-limited");return}console.error("[Frontend Auth] Unexpected response status:",k.status),a("error"),x(!1)}catch(k){console.warn("Failed to check session status:",k),a("error"),x(!1)}},[n]);d.useEffect(()=>{n||y()},[y,n]),d.useEffect(()=>{!n&&o==="locked"&&(v.current=!1)},[n,o]),d.useEffect(()=>{o==="locked"&&b.current&&(b.current.focus(),b.current.select())},[o]),d.useEffect(()=>{n||o==="authenticated"&&!v.current&&(v.current=!0,(async()=>(await I6(),await T6(),await lg()))())},[n,o]);const w=async C=>{if(C.preventDefault(),!g&&!(!l||c)){u(!0),f("");try{const N=await tX(l);if(N.ok){console.log("[Frontend Auth] Login successful");const S=document.cookie,k=S.includes("oc_ui_session="),j=S.includes("oc_ui_refresh=");console.log("[Frontend Auth] After login - access:",k,"refresh:",j),console.log("[Frontend Auth] All cookies after login:",S.split(";").map(F=>F.trim().split("=")[0]).filter(Boolean)),i(""),x(!1),a("authenticated");return}if(N.status===401){console.warn("[Frontend Auth] Login failed: Invalid password"),f("Incorrect password. Try again."),x(!1),a("locked");return}if(N.status===429){console.warn("[Frontend Auth] Login failed: Rate limited");const S=await N.json().catch(()=>({}));p(S.retryAfter),x(!1),a("rate-limited");return}console.error("[Frontend Auth] Login failed: Unexpected response",N.status),f("Unexpected response from server."),x(!1),a("error")}catch(N){console.warn("Failed to submit UI password:",N),f("Network error. Check connection and retry."),x(!1),a("error")}finally{u(!1)}}};return o==="pending"?s.jsx(sX,{}):o==="error"?s.jsx(vh,{onRetry:()=>{y()},errorType:"network"}):o==="rate-limited"?s.jsx(vh,{onRetry:()=>{y()},errorType:"rate-limit",retryAfter:h}):o==="locked"?s.jsx(cg,{children:s.jsxs("div",{className:"flex flex-col items-center gap-6 w-full max-w-xs",children:[s.jsxs("div",{className:"flex flex-col items-center gap-1 text-center",children:[s.jsx("h1",{className:"text-xl font-semibold text-foreground",children:g?"Tunnel access required":"Unlock ArchCoder"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:g?"Open this tunnel using the one-time connect link from the desktop app.":"This session is password-protected."})]}),!g&&s.jsxs("form",{onSubmit:w,className:"w-full space-y-2","data-keyboard-avoid":"true",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsx($b,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/60"}),s.jsx(Xt,{id:"openchamber-ui-password",ref:b,type:"password",autoComplete:"current-password",placeholder:"Enter password",value:l,onChange:C=>{i(C.target.value),m&&f("")},className:"pl-10","aria-invalid":!!m||void 0,"aria-describedby":m?"oc-ui-auth-error":void 0,disabled:c})]}),s.jsx(Be,{type:"submit",size:"icon",disabled:!l||c,"aria-label":c?"Unlocking":"Unlock",children:c?s.jsx(ts,{className:"h-4 w-4 animate-spin"}):s.jsx(Ob,{className:"h-4 w-4"})})]}),m&&s.jsx("p",{id:"oc-ui-auth-error",className:"typography-meta text-destructive",children:m})]}),r&&s.jsxs("div",{className:"w-full",children:[s.jsx(zw,{}),s.jsx("p",{className:"mt-1 text-center typography-micro text-muted-foreground",children:"Use Local if remote is unreachable."})]})]})}):s.jsx(s.Fragment,{children:t})},yd=t=>{if(!t||typeof t!="string")return null;const e=t.trim();if(!e.startsWith("#"))return null;let n=e.slice(1);if((n.length===3||n.length===4)&&(n=n.split("").map(i=>i+i).join("")),n.length===8&&(n=n.slice(0,6)),n.length!==6)return null;const r=Number.parseInt(n,16);if(Number.isNaN(r))return null;const o=r>>16&255,a=r>>8&255,l=r&255;return`${o} ${a} ${l}`};class rX{inheritanceMap=new Map;constructor(){this.initializeInheritanceMap()}generate(e){const n=[];return n.push(...this.generateTailwindVariables(e)),n.push(...this.generatePrimaryColors(e.colors.primary)),n.push(...this.generateSurfaceColors(e.colors.surface)),n.push(...this.generateInteractiveColors(e.colors.interactive)),n.push(...this.generateStatusColors(e.colors.status)),n.push(...this.generatePullRequestColors(e)),n.push(...this.generateSyntaxColors(e.colors.syntax)),n.push(...this.generateComponentColors(e.colors,e)),n.push(...this.generateTypographyVariables()),e.config&&n.push(...this.generateConfigVariables(e.config)),n.join(`
8016
+ `),console.log("[TIP] Empty responses are usually due to:"),console.log(" - Model rate limits"),console.log(" - Context length issues"),console.log(" - Model refusing to respond to certain prompts"),console.log(" - API errors from provider")},analyzeMessageCompletionConsistency(t={}){const{includeNonAssistant:e=!1,verbose:n=!0,maxTableRows:r=25}=t,o=Ze.getState(),a=o.currentSessionId;if(!a)return console.log("[ERROR] No active session"),{summary:null,rows:[]};const l=o.messages.get(a)||[],i=e?l:l.filter(h=>h.info.role==="assistant"),c={totalMessages:l.length,analyzedMessages:i.length,completedMissing:0,completedBeforeTool:0,completedBeforeReasoning:0,runningToolsWhenCompleted:0,reasoningOpenWhenCompleted:0,withTools:0,withReasoning:0},u=h=>typeof h=="number"&&Number.isFinite(h)?h:null,m=h=>{const p=h.filter(g=>typeof g=="number");return p.length>0?Math.max(...p):null},f=i.map((h,p)=>{const g=h.info??{},x=Array.isArray(h.parts)?h.parts:[],b=g.time??{},v=u(b.completed),y=v!==null,w=x.filter(B=>B.type==="tool"),C=x.filter(B=>B.type==="reasoning"),N=m(w.map(B=>u(B.state?.time?.end??B.state?.time?.start))),S=m(C.map(B=>u(B.time?.end??B.time?.start))),k=m([N,S].filter(B=>B!==null)),j=w.some(B=>["pending","running","started"].includes(B.state?.status)),F=C.some(B=>typeof B.time?.end!="number");w.length>0&&(c.withTools+=1),C.length>0&&(c.withReasoning+=1),y||(c.completedMissing+=1);const A=!!(y&&typeof N=="number"&&v<N);A&&(c.completedBeforeTool+=1);const M=!!(y&&typeof S=="number"&&v<S);return M&&(c.completedBeforeReasoning+=1),y&&j&&(c.runningToolsWhenCompleted+=1),y&&F&&(c.reasoningOpenWhenCompleted+=1),{index:p,messageId:g.id,role:g.role,completedAt:v,latestToolTimestamp:N,latestReasoningTimestamp:S,latestPartTimestamp:k,completed_missing:!y,completed_before_tool:A,completed_before_reasoning:M,running_tools_when_completed:!!(y&&j),reasoning_open_when_completed:!!(y&&F),has_tools:w.length>0,has_reasoning:C.length>0}});return n&&(console.table(f.slice(0,r)),f.length>r&&console.log(`Displayed first ${r} rows out of ${f.length}.`),console.log("[SUMMARY] Message completion timing:",c)),{summary:c,rows:f}},checkCompletionStatus(){const t=Ze.getState(),e=t.currentSessionId;if(!e)return console.log("[ERROR] No active session"),null;const r=(t.messages.get(e)||[]).filter(b=>b.info.role==="assistant");if(r.length===0)return console.log("[ERROR] No assistant messages"),null;const o=r[r.length-1],a=o.parts.filter(b=>b.type==="step-finish"),l=o.info.finish==="stop",c=o.info.time?.completed,u=o.info.status,m=typeof c=="number"&&c>0||u==="completed",f=!!(m&&l),h=t.messageStreamStates,p=o.info.sessionID?t.streamingMessageIds.get(o.info.sessionID)??null:null,g=h.get(o.info.id),x=o.info.id===p;return console.log("[SUMMARY] Completion Status:"),console.log("Message ID:",o.info.id),console.log("time.completed:",c,"(type:",typeof c,")"),console.log("status:",u),console.log("hasCompletedFlag:",m),console.log("hasStopReason:",l),console.log("messageIsComplete:",f),console.log("lifecycle phase:",g?.phase),console.log("isStreamingCandidate:",x),console.log("streamingMessageId:",p),console.log("Step-finish parts:",a),{messageId:o.info.id,completed:c,status:u,hasCompletedFlag:m,hasStopReason:l,messageIsComplete:f,stepFinishParts:a,raw:o}}};typeof window<"u"&&(window.__opencodeDebug=gu,D6()&&(console.log("[DEBUG] OpenCode Debug Utils loaded! Use window.__opencodeDebug in console"),console.log("Available commands:"),console.log(" __opencodeDebug.getLastAssistantMessage() - Get last assistant message details"),console.log(" __opencodeDebug.getAllMessages(truncate?) - List all messages (truncate=true for short preview)"),console.log(" __opencodeDebug.truncateMessages(messages) - Truncate long fields in messages array"),console.log(" __opencodeDebug.getAppStatus() - Show app status snapshot"),console.log(" __opencodeDebug.checkLastMessage() - Check if last message is problematic"),console.log(" __opencodeDebug.findEmptyMessages() - Find all empty assistant messages"),console.log(" __opencodeDebug.showRetryHelp() - Show instructions for handling empty responses"),console.log(" __opencodeDebug.getStreamingState() - Get streaming state info"),console.log(" __opencodeDebug.analyzeMessageCompletionConsistency(opts?) - Compare time.completed vs part timings"),console.log(" __opencodeDebug.checkCompletionStatus() - Check completion status of last message")),window.addEventListener("error",t=>{try{const e=t.message||"",n=t.filename||"";typeof e=="string"&&e.includes("this._renderer.value.dimensions")&&/xterm/i.test(String(n))&&t.preventDefault()}catch{}}));const OY=({open:t,onOpenChange:e})=>{const[n,r]=d.useState(null),[o,a]=d.useState(!1),[l,i]=d.useState(!1),[c,u]=d.useState(null),[m,f]=d.useState(!1),h=d.useCallback(async()=>{if(!o){a(!0),i(!1);try{if(!c){fe.error("Copy failed",{description:"Diagnostics not ready yet. Wait a second and retry."});return}const g=await gu.copyTextToClipboard(c);g.ok?(i(!0),fe.success("Diagnostics copied")):fe.error("Copy failed",{description:g.error})}catch(g){fe.error("Copy failed"),console.error("Failed to copy diagnostics:",g)}finally{a(!1)}}},[c,o]);d.useEffect(()=>{if(!t)return;typeof window<"u"&&!!window.__TAURI__?(async()=>{try{const{getVersion:b}=await Kn(async()=>{const{getVersion:y}=await import("./vendor-.bun-HTKwyaEM.js").then(w=>w.fI);return{getVersion:y}},__vite__mapDeps([0,1])),v=await b();r(v)}catch{r("2.0.4")}})():r("2.0.4")},[t]),d.useEffect(()=>{if(!t){u(null),f(!1);return}let g=!1;return f(!0),gu.buildDiagnosticsReport().then(x=>{g||u(x)}).catch(x=>{g||(console.error("Failed to prepare diagnostics:",x),u(null))}).finally(()=>{g||f(!1)}),()=>{g=!0}},[t]);const p=n;return s.jsx(Os,{open:t,onOpenChange:e,children:s.jsx(Vs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(tc,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"ArchCoder"}),p&&s.jsxs("p",{className:"typography-meta text-muted-foreground",children:["Version ",p]})]}),s.jsxs("p",{className:"typography-meta text-muted-foreground",children:["A fan-made interface for"," ",s.jsx("a",{href:"https://opencode.ai/",target:"_blank",rel:"noopener noreferrer",className:"hover:text-foreground transition-colors",children:"OpenCode"})," ","agent"]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:h,disabled:o||m||!c,className:Q("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:l?"Diagnostics copied":m?"Preparing diagnostics...":"Copy diagnostics"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:"Includes ArchCoder state, OpenCode health, directories, and projects."})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",children:[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(w6,{className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/btriapitsyn",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(Ad,{className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:"Made with love to comunity"})]})})})};function E0(t){const e=Fe.c(3),{apis:n,children:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx(Z2.Provider,{value:n,children:r}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o}const VY=/ENOENT|spawn\s+opencode|Unable\s+to\s+locate\s+the\s+opencode\s+CLI|OpenCode\s+CLI\s+not\s+found|opencode(\.exe)?\s+not\s+found|opencode(\.exe)?:\s*command\s+not\s+found|not\s+recognized\s+as\s+an\s+internal\s+or\s+external\s+command|env:\s*['"]?(node|bun)['"]?:\s*No\s+such\s+file\s+or\s+directory|(node|bun):\s*No\s+such\s+file\s+or\s+directory/i,UY=1500,WY=()=>rs($r(XY)),qY=()=>Ze($r(QY)),GY=()=>dn($r(JY)),ZY=()=>{const t=Fe.c(3),{isAboutDialogOpen:e,setAboutDialogOpen:n}=Ee();let r;return t[0]!==e||t[1]!==n?(r=s.jsx(OY,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},KY=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search);if(t.get("ocPanel")!=="session-chat")return null;const 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}};function YY({apis:t}){const{initializeApp:e,isInitialized:n,isConnected:r}=rs(),{providersCount:o,agentsCount:a,loadProviders:l,loadAgents:i}=WY(),{error:c,clearError:u,loadSessions:m}=Ze(),{currentSessionId:f,setCurrentSession:h,sessions:p}=qY(),{currentDirectory:g,setDirectory:x,isSwitchingDirectory:b}=GY(),[v,y]=d.useState(!1),{uiFont:w,monoFont:C}=AH(),N=ir(z=>z.refreshStatus),[S,k]=d.useState(()=>t.runtime.isVSCode),[j,F]=d.useState(!1),[A,M]=d.useState(!0),B=d.useMemo(()=>Rn(),[]),E=d.useRef(!1),I=d.useMemo(()=>KY(),[]),P=!I||A;d.useEffect(()=>{k(t.runtime.isVSCode)},[t.runtime.isVSCode]),d.useEffect(()=>($3(t),()=>$3(null)),[t]),d.useEffect(()=>{I||N(t.github,{force:!0})},[t.github,I,N]),FY(P?t.github:void 0,t.git),d.useEffect(()=>{if(typeof document>"u")return;const z=document.documentElement,R=o5[w]?.stack??o5[BH].stack,W=a5[C]?.stack??a5[_H].stack;z.style.setProperty("--font-sans",R),z.style.setProperty("--font-heading",R),z.style.setProperty("--font-family-sans",R),z.style.setProperty("--font-mono",W),z.style.setProperty("--font-family-mono",W),z.style.setProperty("--ui-regular-font-weight","400"),document.body&&(document.body.style.fontFamily=R)},[w,C]),d.useEffect(()=>{if(n){const R=setTimeout(()=>{const W=document.getElementById("initial-loading");W&&(W.classList.add("fade-out"),setTimeout(()=>{W.remove()},300))},150);return()=>clearTimeout(R)}},[n]),d.useEffect(()=>{const z=setTimeout(()=>{const R=document.getElementById("initial-loading");R&&!n&&(R.classList.add("fade-out"),setTimeout(()=>{R.remove()},300))},5e3);return()=>clearTimeout(z)},[n]),d.useEffect(()=>{(async()=>S||await e())()},[e,S]);const D=d.useRef(!1),L=d.useRef(0);d.useEffect(()=>{if(S||!r||o>0&&a>0||D.current)return;const z=Date.now();if(z-L.current<750)return;L.current=z,D.current=!0,(async()=>{try{o===0&&await l(),a===0&&await i()}catch{}finally{D.current=!1}})()},[a,r,S,i,l,o]),d.useEffect(()=>{if(b)return;(async()=>S||r&&(En.setDirectory(g),await m()))()},[g,b,m,r,S]),d.useEffect(()=>{if(!I||typeof window>"u")return;const z=G=>{const Y=G?.visible===!0;M(Y)},R=G=>{if(G.origin!==window.location.origin)return;const Y=G.data;Y?.type==="archcoder:embedded-visibility"&&z(Y.payload)},W=window;return W.__archcoderSetEmbeddedVisibility=z,window.addEventListener("message",R),()=>{window.removeEventListener("message",R),W.__archcoderSetEmbeddedVisibility===z&&delete W.__archcoderSetEmbeddedVisibility}},[I]),d.useEffect(()=>{!I?.directory||S||g!==I.directory&&x(I.directory,{showOverlay:!1})},[g,I,S,x]),d.useEffect(()=>{!I||S||f!==I.sessionId&&p.some(z=>z.id===I.sessionId)&&h(I.sessionId)},[f,I,S,p,h]),d.useEffect(()=>{if(!I||typeof window>"u")return;const z=R=>{R.storageArea===window.localStorage&&R.key==="ui-store"&&Ee.persist.rehydrate()};return window.addEventListener("storage",z),()=>{window.removeEventListener("storage",z)}},[I]),d.useEffect(()=>{typeof window>"u"||!n||b||E.current||(E.current=!0,window.__archcoderAppReady=!0,window.dispatchEvent(new Event("archcoder:app-ready")))},[n,b]),Fv({enabled:P}),Bv({enabled:P}),lY({enabled:P}),mY(),gY(),yY(),oY(),zK();const T=d.useCallback(()=>{y(z=>!z)},[]);LK(T),HK({enabled:P}),z7({enabled:P}),WK({enabled:P}),d.useEffect(()=>{if(I)return;const z=R=>{Du(R)&&R.shiftKey&&R.key==="D"&&(R.preventDefault(),y(W=>!W))};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[I]),d.useEffect(()=>{I||c&&setTimeout(()=>u(),5e3)},[u,I,c]),d.useEffect(()=>{if(I||!Rn()||!$o())return;let z=!1;const R=async()=>{const G=await fetch("/health",{method:"GET"}).catch(()=>null);if(!G||!G.ok||z)return;const Y=await G.json().catch(()=>null);if(!Y||z)return;const J=Y.openCodeRunning===!0,V=Y.isOpenCodeReady===!0,U=(typeof Y.opencodeBinaryResolved=="string"?Y.opencodeBinaryResolved.trim():"").length>0,X=typeof Y.lastOpenCodeError=="string"?Y.lastOpenCodeError:"",$=!J&&(VY.test(X)||!U&&!V);F($)};R();const W=window.setInterval(()=>{R()},UY);return()=>{z=!0,window.clearInterval(W)}},[I]);const _=d.useCallback(()=>{F(!1),window.location.reload()},[]);return j?s.jsx(An,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(LY,{onCliAvailable:_})})}):I?s.jsx(An,{children:s.jsx(E0,{apis:t,children:s.jsx(ii,{delayDuration:700,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(wi,{}),s.jsx(l0,{})]})})})}):S?(typeof window<"u"?window.__ARCHCODER_PANEL_TYPE__:"chat")==="agentManager"?s.jsx(An,{children:s.jsx(E0,{apis:t,children:s.jsx(ii,{delayDuration:700,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(AK,{}),s.jsx(l0,{})]})})})}):s.jsx(An,{children:s.jsx(E0,{apis:t,children:s.jsx(qm,{children:s.jsx(ii,{delayDuration:700,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(tK,{}),s.jsx(l0,{})]})})})})}):s.jsx(An,{children:s.jsx(E0,{apis:t,children:s.jsx(EY,{children:s.jsx(qm,{children:s.jsx(Tj,{children:s.jsx(ii,{delayDuration:700,skipDelayDuration:150,children:s.jsxs("div",{className:B?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(YZ,{}),s.jsx(l0,{}),s.jsx(HY,{}),s.jsx(ZY,{}),v&&s.jsx(MK,{onClose:()=>y(!1)})]})})})})})})})}function XY(t){return{providersCount:t.providers.length,agentsCount:t.agents.length,loadProviders:t.loadProviders,loadAgents:t.loadAgents}}function QY(t){return{currentSessionId:t.currentSessionId,setCurrentSession:t.setCurrentSession,sessions:t.sessions}}function JY(t){return{currentDirectory:t.currentDirectory,setDirectory:t.setDirectory,isSwitchingDirectory:t.isSwitchingDirectory}}const lg=async()=>{if(typeof window>"u")return;let t=null,e=null;try{t=window.localStorage.getItem("homeDirectory"),e=window.localStorage.getItem("lastDirectory")}catch(r){console.warn("Failed to read saved directory preferences:",r)}const n=dn.getState();t&&n.homeDirectory!==t&&n.synchronizeHomeDirectory(t),e&&!xn()&&n.setDirectory(e,{showOverlay:!1})},ig="/auth/session",eX=async()=>{console.log("[Frontend Auth] Checking session status...");const t=await fetch(ig,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return console.log("[Frontend Auth] Session status response:",t.status,t.statusText),t},tX=async t=>{console.log("[Frontend Auth] Submitting password...");const e=await fetch(ig,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:t})});return console.log("[Frontend Auth] Password submit response:",e.status,e.statusText),e},cg=t=>{const e=Fe.c(5),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={fontFamily:'"Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif'},e[0]=r):r=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-55",style:{background:"radial-gradient(120% 140% at 50% -20%, var(--surface-overlay) 0%, transparent 68%)"}}),e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx("div",{className:"pointer-events-none absolute inset-0",style:{backgroundColor:"var(--surface-subtle)",opacity:.22}}),e[2]=a):a=e[2];let l;return e[3]!==n?(l=s.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background text-foreground",style:r,children:[o,a,s.jsx("div",{className:"relative z-10 flex w-full justify-center px-4 py-12 sm:px-6",children:n})]}),e[3]=n,e[4]=l):l=e[4],l},sX=()=>{const t=Fe.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background text-foreground",children:s.jsx(tc,{width:120,height:120,isAnimated:!0})}),t[0]=e):e=t[0],e},vh=t=>{const e=Fe.c(12),{onRetry:n,errorType:r,retryAfter:o}=t,l=(r===void 0?"network":r)==="rate-limit",i=o?Math.ceil(o/60):1,c=l?"Too many attempts":"Unable to reach server";let u;e[0]!==c?(u=s.jsx("h1",{className:"typography-ui-header font-semibold text-destructive",children:c}),e[0]=c,e[1]=u):u=e[1];const m=l?`Please wait ${i} minute${i>1?"s":""} before trying again.`:"We couldn't verify the UI session. Check that the service is running and try again.";let f;e[2]!==m?(f=s.jsx("p",{className:"typography-meta text-muted-foreground max-w-xs",children:m}),e[2]=m,e[3]=f):f=e[3];let h;e[4]!==u||e[5]!==f?(h=s.jsxs("div",{className:"space-y-2",children:[u,f]}),e[4]=u,e[5]=f,e[6]=h):h=e[6];let p;e[7]!==n?(p=s.jsx(Be,{type:"button",onClick:n,className:"w-full max-w-xs",children:"Retry"}),e[7]=n,e[8]=p):p=e[8];let g;return e[9]!==h||e[10]!==p?(g=s.jsx(cg,{children:s.jsxs("div",{className:"flex flex-col items-center gap-6 text-center",children:[h,p]})}),e[9]=h,e[10]=p,e[11]=g):g=e[11],g},nX=({children:t})=>{const e=d.useMemo(()=>xn(),[]),n=e,r=d.useMemo(()=>Rn()&&!e,[e]),[o,a]=d.useState(()=>n?"authenticated":"pending"),[l,i]=d.useState(""),[c,u]=d.useState(!1),[m,f]=d.useState(""),[h,p]=d.useState(void 0),[g,x]=d.useState(!1),b=d.useRef(null),v=d.useRef(n),y=d.useCallback(async()=>{if(n){console.log("[Frontend Auth] VSCode runtime, skipping auth"),a("authenticated");return}const C=document.cookie,N=C.includes("oc_ui_session="),S=C.includes("oc_ui_refresh=");console.log("[Frontend Auth] Cookies check - access:",N,"refresh:",S),console.log("[Frontend Auth] All cookies:",C.split(";").map(k=>k.trim().split("=")[0])),a(k=>k==="authenticated"?k:"pending");try{const k=await eX(),j=await k.text();if(console.log("[Frontend Auth] Raw response:",k.status,j),k.ok){console.log("[Frontend Auth] Session is authenticated"),a("authenticated"),x(!1),f(""),p(void 0);return}if(k.status===401){let F={};try{F=JSON.parse(j)}catch{F={}}console.warn("[Frontend Auth] Session is locked (401)",F),F.debug&&console.warn("[Frontend Auth] Debug info:",F.debug),x(F.tunnelLocked===!0),a("locked"),p(void 0);return}if(k.status===429){let F={};try{F=JSON.parse(j)}catch{F={}}p(F.retryAfter),x(!1),a("rate-limited");return}console.error("[Frontend Auth] Unexpected response status:",k.status),a("error"),x(!1)}catch(k){console.warn("Failed to check session status:",k),a("error"),x(!1)}},[n]);d.useEffect(()=>{n||y()},[y,n]),d.useEffect(()=>{!n&&o==="locked"&&(v.current=!1)},[n,o]),d.useEffect(()=>{o==="locked"&&b.current&&(b.current.focus(),b.current.select())},[o]),d.useEffect(()=>{n||o==="authenticated"&&!v.current&&(v.current=!0,(async()=>(await I6(),await T6(),await lg()))())},[n,o]);const w=async C=>{if(C.preventDefault(),!g&&!(!l||c)){u(!0),f("");try{const N=await tX(l);if(N.ok){console.log("[Frontend Auth] Login successful");const S=document.cookie,k=S.includes("oc_ui_session="),j=S.includes("oc_ui_refresh=");console.log("[Frontend Auth] After login - access:",k,"refresh:",j),console.log("[Frontend Auth] All cookies after login:",S.split(";").map(F=>F.trim().split("=")[0]).filter(Boolean)),i(""),x(!1),a("authenticated");return}if(N.status===401){console.warn("[Frontend Auth] Login failed: Invalid password"),f("Incorrect password. Try again."),x(!1),a("locked");return}if(N.status===429){console.warn("[Frontend Auth] Login failed: Rate limited");const S=await N.json().catch(()=>({}));p(S.retryAfter),x(!1),a("rate-limited");return}console.error("[Frontend Auth] Login failed: Unexpected response",N.status),f("Unexpected response from server."),x(!1),a("error")}catch(N){console.warn("Failed to submit UI password:",N),f("Network error. Check connection and retry."),x(!1),a("error")}finally{u(!1)}}};return o==="pending"?s.jsx(sX,{}):o==="error"?s.jsx(vh,{onRetry:()=>{y()},errorType:"network"}):o==="rate-limited"?s.jsx(vh,{onRetry:()=>{y()},errorType:"rate-limit",retryAfter:h}):o==="locked"?s.jsx(cg,{children:s.jsxs("div",{className:"flex flex-col items-center gap-6 w-full max-w-xs",children:[s.jsxs("div",{className:"flex flex-col items-center gap-1 text-center",children:[s.jsx("h1",{className:"text-xl font-semibold text-foreground",children:g?"Tunnel access required":"Unlock ArchCoder"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:g?"Open this tunnel using the one-time connect link from the desktop app.":"This session is password-protected."})]}),!g&&s.jsxs("form",{onSubmit:w,className:"w-full space-y-2","data-keyboard-avoid":"true",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsx($b,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/60"}),s.jsx(Xt,{id:"openchamber-ui-password",ref:b,type:"password",autoComplete:"current-password",placeholder:"Enter password",value:l,onChange:C=>{i(C.target.value),m&&f("")},className:"pl-10","aria-invalid":!!m||void 0,"aria-describedby":m?"oc-ui-auth-error":void 0,disabled:c})]}),s.jsx(Be,{type:"submit",size:"icon",disabled:!l||c,"aria-label":c?"Unlocking":"Unlock",children:c?s.jsx(ts,{className:"h-4 w-4 animate-spin"}):s.jsx(Ob,{className:"h-4 w-4"})})]}),m&&s.jsx("p",{id:"oc-ui-auth-error",className:"typography-meta text-destructive",children:m})]}),r&&s.jsxs("div",{className:"w-full",children:[s.jsx(zw,{}),s.jsx("p",{className:"mt-1 text-center typography-micro text-muted-foreground",children:"Use Local if remote is unreachable."})]})]})}):s.jsx(s.Fragment,{children:t})},yd=t=>{if(!t||typeof t!="string")return null;const e=t.trim();if(!e.startsWith("#"))return null;let n=e.slice(1);if((n.length===3||n.length===4)&&(n=n.split("").map(i=>i+i).join("")),n.length===8&&(n=n.slice(0,6)),n.length!==6)return null;const r=Number.parseInt(n,16);if(Number.isNaN(r))return null;const o=r>>16&255,a=r>>8&255,l=r&255;return`${o} ${a} ${l}`};class rX{inheritanceMap=new Map;constructor(){this.initializeInheritanceMap()}generate(e){const n=[];return n.push(...this.generateTailwindVariables(e)),n.push(...this.generatePrimaryColors(e.colors.primary)),n.push(...this.generateSurfaceColors(e.colors.surface)),n.push(...this.generateInteractiveColors(e.colors.interactive)),n.push(...this.generateStatusColors(e.colors.status)),n.push(...this.generatePullRequestColors(e)),n.push(...this.generateSyntaxColors(e.colors.syntax)),n.push(...this.generateComponentColors(e.colors,e)),n.push(...this.generateTypographyVariables()),e.config&&n.push(...this.generateConfigVariables(e.config)),n.join(`
8017
8017
  `)}generateTailwindVariables(e){const n=[];n.push(` --background: ${e.colors.surface.background} !important;`),n.push(` --foreground: ${e.colors.surface.foreground} !important;`),n.push(` --muted: ${e.colors.surface.muted} !important;`),n.push(` --muted-foreground: ${e.colors.surface.mutedForeground} !important;`),n.push(` --card: ${e.colors.surface.elevated} !important;`),n.push(` --card-foreground: ${e.colors.surface.elevatedForeground} !important;`),n.push(` --popover: ${e.colors.surface.elevated} !important;`),n.push(` --popover-foreground: ${e.colors.surface.elevatedForeground} !important;`),n.push(` --border: ${e.colors.interactive.border} !important;`),n.push(` --input: ${e.colors.interactive.border} !important;`),n.push(` --primary: ${e.colors.primary.base} !important;`),n.push(` --primary-foreground: ${e.colors.primary.foreground} !important;`),n.push(` --secondary: ${e.colors.surface.muted} !important;`),n.push(` --secondary-foreground: ${e.colors.surface.mutedForeground} !important;`),n.push(` --accent: ${e.colors.surface.subtle} !important;`),n.push(` --accent-foreground: ${e.colors.surface.foreground} !important;`),n.push(` --destructive: ${e.colors.status.error} !important;`),n.push(` --destructive-foreground: ${e.colors.status.errorForeground} !important;`),n.push(` --ring: ${e.colors.interactive.focusRing} !important;`),e.config?.radius?.md&&n.push(` --radius: ${e.config.radius.md} !important;`);const r=yd(e.colors.surface.muted),o=yd(e.colors.surface.subtle),a=yd(e.colors.interactive.border);n.push(` --sidebar-base: ${e.colors.surface.muted} !important;`),r&&n.push(` --sidebar-base-rgb: ${r} !important;`),n.push(" --sidebar: var(--sidebar-base) !important;"),n.push(` --sidebar-foreground: ${e.colors.surface.mutedForeground} !important;`),n.push(` --sidebar-primary: ${e.colors.primary.base} !important;`),n.push(` --sidebar-primary-foreground: ${e.colors.primary.foreground} !important;`),n.push(` --sidebar-accent-base: ${e.colors.surface.subtle} !important;`),o&&n.push(` --sidebar-accent-base-rgb: ${o} !important;`),n.push(" --sidebar-accent: var(--sidebar-accent-base) !important;"),n.push(` --sidebar-accent-foreground: ${e.colors.surface.foreground} !important;`),n.push(` --sidebar-border: ${e.colors.interactive.border} !important;`),a&&n.push(` --sidebar-border-rgb: ${a} !important;`),n.push(` --sidebar-ring: ${e.colors.interactive.focusRing} !important;`);const l=e.metadata.variant==="dark",i=l?.35:.75,c=l?.2:.6;if(r)n.push(` --sidebar-overlay-strong: rgb(${r} / ${i}) !important;`),n.push(` --sidebar-overlay-soft: rgb(${r} / ${c}) !important;`);else{const u=e.colors.surface.muted;n.push(` --sidebar-overlay-strong: ${this.opacity(u,i)} !important;`),n.push(` --sidebar-overlay-soft: ${this.opacity(u,c)} !important;`)}return e.colors.charts?.series&&Array.isArray(e.colors.charts.series)&&e.colors.charts.series.forEach((u,m)=>{n.push(` --chart-${m+1}: ${u};`)}),e.colors.loading?(n.push(` --loading-spinner: ${e.colors.loading.spinner||e.colors.primary.base};`),n.push(` --loading-spinner-track: ${e.colors.loading.spinnerTrack||e.colors.surface.muted};`)):(n.push(` --loading-spinner: ${e.colors.primary.base};`),n.push(` --loading-spinner-track: ${e.colors.surface.muted};`)),n}apply(e){const n=this.generate(e),r=document.createElement("style");r.id="opencode-theme-variables";let o="";e.metadata.variant==="dark"?(o=`:root {
8018
8018
  ${n}
8019
8019
  }