@openchamber/web 1.16.0 → 1.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/assets/{DiagramView-he_RFVx5.js → DiagramView-Elkp8b4l.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-CdBIHSPZ.js → MarkdownRendererImpl-DLhrL6oX.js} +4 -4
- package/dist/assets/{MultiRunWindow-B_C-tvVq.js → MultiRunWindow-DVpNCqnE.js} +1 -1
- package/dist/assets/{OnboardingScreen-BBnTt-9w.js → OnboardingScreen-CpcR0gyq.js} +1 -1
- package/dist/assets/SessionSwitcherDropdown-DHO5Je6v.js +1 -0
- package/dist/assets/{SettingsWindow-CjqLdpTE.js → SettingsWindow-Bewo7vwh.js} +1 -1
- package/dist/assets/{TerminalView-DQcdegHp.js → TerminalView-D9C7fNLm.js} +1 -1
- package/dist/assets/es-D9nOo8Wx.js +15 -0
- package/dist/assets/fr-DEF71lgt.js +13 -0
- package/dist/assets/index-BklNmnVr.js +2 -0
- package/dist/assets/index-C3uMIExE.css +1 -0
- package/dist/assets/ja-CpNfaEje.js +15 -0
- package/dist/assets/ko-DLS_rnE-.js +15 -0
- package/dist/assets/main-B0CxEOP5.js +237 -0
- package/dist/assets/{main-Dfm-VKZ9.js → main-Ck3ZNw8-.js} +2 -2
- package/dist/assets/miniChat-BAJj2Ome.js +2 -0
- package/dist/assets/mobile-CJoX4Cdj.js +2 -0
- package/dist/assets/pl-BjtFn5-n.js +15 -0
- package/dist/assets/pt-BR-C0_4Rnzn.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-D4-OXCXM.js +2 -0
- package/dist/assets/{renderMobileApp-o7Fs9EBx.js → renderMobileApp-DHWdI195.js} +3 -3
- package/dist/assets/runtimeEndpointReset-B0P2DED1.js +167 -0
- package/dist/assets/uk-BDu4E0s0.js +15 -0
- package/dist/assets/{useAppFontEffects-DkPuAMXD.js → useAppFontEffects-9LFMCKYW.js} +127 -127
- package/dist/assets/zh-CN-BcwMqxIR.js +15 -0
- package/dist/assets/zh-TW-bNDQjKEu.js +15 -0
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/lib/opencode/settings-helpers.js +9 -0
- package/server/lib/package-manager.js +1 -1
- package/server/lib/small-model/DOCUMENTATION.md +3 -1
- package/server/lib/small-model/call.js +45 -8
- package/server/lib/small-model/call.test.js +338 -0
- package/server/lib/small-model/index.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-CWWrCFzr.js +0 -1
- package/dist/assets/es-r0_jT91q.js +0 -15
- package/dist/assets/fr-Bo8rtAJ1.js +0 -13
- package/dist/assets/index-8J6waVO6.js +0 -2
- package/dist/assets/index-DEMqM4Lz.css +0 -1
- package/dist/assets/ja-BPWtkG-c.js +0 -15
- package/dist/assets/ko-Bv0k-0E3.js +0 -15
- package/dist/assets/main-B-GA5Tg5.js +0 -237
- package/dist/assets/miniChat-CfmCFFfu.js +0 -2
- package/dist/assets/mobile-CXJqeDlm.js +0 -2
- package/dist/assets/pl-CiTP50bz.js +0 -15
- package/dist/assets/pt-BR-DadIjX5L.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-DS7Dy2ii.js +0 -2
- package/dist/assets/runtimeEndpointReset-MTaPPm4F.js +0 -167
- package/dist/assets/uk-2RpsWGoZ.js +0 -15
- package/dist/assets/zh-CN-BwKWaTuz.js +0 -15
- package/dist/assets/zh-TW--f_BqBpD.js +0 -15
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalView-D9C7fNLm.js","assets/vendor-.bun-BE757pvp.js","assets/useAppFontEffects-9LFMCKYW.js","assets/index-BklNmnVr.js","assets/index-C3uMIExE.css","assets/runtimeEndpointReset-B0P2DED1.js","assets/mobileLayoutPreference-Dio-WWkI.js","assets/SessionSwitcherDropdown-DHO5Je6v.js","assets/DiagramView-Elkp8b4l.js","assets/SettingsWindow-Bewo7vwh.js","assets/MultiRunWindow-DVpNCqnE.js","assets/OnboardingScreen-CpcR0gyq.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as s,b as gt,a as fo,R as i,d as Hf,p as xc,L as qh,r as nt,N as Gf,u as ja,l as Do,n as Sa,D as Na,q as ka,S as Gl,v as Kl,w as bc,C as wc,O as ql,T as Yh,W as Qh,X as Jh,Y as Xh,$ as mi,a0 as Zh,a1 as ep,F as tp,a2 as sp,a3 as np,a4 as rp,a5 as Kf,a6 as ip,a7 as op,a8 as Yl,a9 as ap,s as lp,m as cp,aa as yd,ab as vd,ac as jd,ad as dp,ae as up,af as fp,ag as mp,ah as hp,ai as pp,_ as mo,aj as Sd,ak as Nd,al as kd,I as gp}from"./vendor-.bun-BE757pvp.js";import{t as yc,v as pr,w as io,x as Cd,y as xp,z as Ca,A as qf,B as bp,h as Is,l as Wo,u as Ee,C as wp,D as Wa,E as Cr,F as Yf,d as Xr,G as Aa,H as Qf,I as Jf,J as Zr,K as Ql,L as yp,M as vp,R as Ad,N as Dd,e as Js,O as jp,P as Sp,Q as Xf,S as Zf,T as vc,o as sr,U as Np,b as Li,V as kp,r as jc,W as Cp,X as Sc,n as em,Y as Ap,Z as Dp,a as Qi,_ as la,$ as ca,a0 as Tp,a1 as Pp,a2 as Ip,a3 as Td,a4 as Pd,a5 as Id,a6 as Rd,a7 as Rp,f as Ed,m as Md,a8 as Ep,a9 as Mp,aa as Fp,p as Op,q as Lp}from"./index-BklNmnVr.js";import{c as yt,v as Pe,aC as ls,I as A,y as gr,t as le,aD as Xs,aE as $r,aF as Zs,aG as en,d as nr,aH as zr,o as si,aI as Fd,aJ as At,aK as Dt,aL as Tt,aM as Bp,ao as Lo,aN as Da,aO as hi,ap as Bo,aq as tm,al as Nc,aP as sm,aQ as Vp,Y as rs,G as ht,aR as _p,ae as nm,u as kr,E as kc,b as Ds,Z as $i,aS as rm,aT as im,aU as om,aV as $p,aW as zp,_ as Cc,aX as Ua,aY as pi,aZ as Ac,a_ as da,a4 as an,a$ as Wp,b0 as am,b1 as Up,b2 as lm,b3 as Vr,b4 as Dc,b5 as tn,b6 as Gs,B as ze,b7 as Vs,b8 as _s,b9 as xi,ba as Hp,bb as Gp,bc as Yo,bd as Fn,be as cm,bf as dm,ai as Tc,bg as Kp,bh as Od,bi as Ld,bj as Oi,w as Ln,bk as oo,bl as qp,bm as Yp,bn as Qp,bo as Jp,bp as Ha,bq as Ga,br as Ka,bs as qa,bt as Qr,bu as Jr,bv as Xp,bw as Zp,bx as dn,by as eg,bz as tg,bA as sg,bB as ng,bC as rg,p as Bi,bD as Pc,bE as ig,bF as og,bG as ag,bH as lg,bI as cg,bJ as dg,bK as ug,bL as On,bM as Un,bN as Hn,bO as Dn,bP as Gn,bQ as Bs,bR as fg,D as ao,M as Ya,S as Qa,bS as mg,bT as xr,bU as hg,e as bi,h as Ic,f as Ja,bV as pg,bW as um,bX as gg,bY as xg,i as Rc,bZ as bg,j as yn,b_ as Xa,aj as _r,n as wg,b$ as yg,c0 as ul,c1 as vg,c2 as jg,F as ei,c3 as Ec,c4 as Za,c5 as cn,c6 as ho,q as Vi,c7 as fm,ah as Sg,c8 as Ng,c9 as kg,ca as Cg,cb as fl,cc as Ag,z as wi,A as Bd,C as Vd,cd as _d,ce as mm,cf as ml,cg as $d,ch as hm,ci as Dg,cj as pm,x as zd,J as Tg,ck as hl,cl as Mc,cm as Pg,cn as Ig,co as Rg,cp as Eg,cq as Uo,cr as Mg,cs as pl,ct as Fg,cu as gm,cv as xm,cw as Fc,cx as Og,a2 as Oc,cy as Co,cz as bm,cA as Lg,r as ti,cB as Bg,cC as wm,cD as Vg,cE as _g,cF as Wd,cG as ym,cH as vm,cI as jm,cJ as $g,L as Lc,P as Bc,N as Vc,R as Ta,cK as ws,cL as Pa,cM as Zn,cN as zg,cO as Jl,cP as Wg,cQ as Ug,cR as Hg,cS as Ud,cT as Gg,cU as Kg,cV as _c,cW as Sm,cX as qg,cY as Yg,cZ as Qg,c_ as Jg,c$ as Xg,d0 as Hd,d1 as Zg,d2 as Gd,d3 as Kd,d4 as ex,d5 as tx,d6 as sx,d7 as nx,d8 as rx,d9 as ix,T as ox,da as qd,db as ax,dc as Nm,U as lx,aa as cx,dd as dx,H as ux,K as fx,de as mx,df as hx,dg as px,dh as gx,di as xx,dj as bx,dk as wx,dl as yx,dm as vx,dn as Ia,dp as jx,dq as Yd,dr as Sx,ds as Nx,dt as kx,du as po,dv as Cx,dw as Qd,dx as Ax,dy as Dx,dz as Tx,dA as Px,a as km,dB as Cm,dC as Ix,dD as Rx,dE as Ex,dF as ua,ag as Mx,dG as Fx,dH as Jd,dI as Ox,$ as Lx,a0 as Bx,a1 as Vx,a5 as Xd,a6 as Zd,a7 as eu,a8 as Am,a9 as Dm,dJ as _x,ax as $x,ay as zx,az as Wx,aA as Ux,aB as Hx,at as Gx,au as Kx,av as qx,aw as Yx}from"./useAppFontEffects-9LFMCKYW.js";import{I as tu,q as Qx,s as su,t as Jx,v as nu,w as ai,x as Xx,y as gl,z as Vo,U as Ra,B as Ea,E as lo,F as Ho,G as co,n as Tm,j as Pm,l as pn,m as Zx,Q as Im,H as eb,J as tb,K as sb,M as Xl,L as Rm,P as Em,R as nb,T as rb,C as ib,a as ob,V as $c,W as Mm,X as zc,Y as Wc,Z as Uc,_ as Fm,$ as Om,a0 as Zl,a1 as Lm,a2 as ec,a3 as fa,a4 as ab,a5 as lb,a6 as cb,u as To,N as db,D as ub,a7 as ru,a8 as fb,d as mb,o as hb,i as tc,a9 as pb,aa as gb,h as xb,ab as bb,ac as wb,c as yb,e as vb,O as Bm,f as jb,ad as Sb}from"./runtimeEndpointReset-B0P2DED1.js";import{u as Vm,S as Nb,C as kb,W as _m,g as Hc,r as Cb,d as $m,c as eo,n as iu,i as Ab,a as Po,f as zm,b as Db,e as Tb,h as xl}from"./SessionSwitcherDropdown-DHO5Je6v.js";function Wm(t){const{drafts:e,editingDraftId:n,commentText:r,onTextChange:o,selection:a,isDragging:c,fileLabel:l,newWidgetId:d,mapDraftToRange:f,onSave:m,onCancel:u,onEdit:p,onDelete:x}=t,b=[];for(const w of e){const g=f(w);if(w.id===n){b.push({afterLine:g.end,id:`edit-${w.id}`,content:s.jsx(tu,{initialText:r,onTextChange:o,fileLabel:l,lineRange:g,isEditing:!0,onSave:m,onCancel:u},`edit-${w.id}`)});continue}b.push({afterLine:g.end,id:`card-${w.id}`,content:s.jsx(Qx,{draft:w,onEdit:()=>p(w),onDelete:()=>x(w)},`card-${w.id}`)})}if(a&&!n&&!c){const w={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};b.push({afterLine:w.end,id:d,content:s.jsx(tu,{initialText:r,onTextChange:o,fileLabel:l,lineRange:w,isEditing:!1,onSave:m,onCancel:u},d)})}return b}function ou(t){const e=gt.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 c=typeof o=="number"?`${o}px`:o,l=typeof o=="number"?`${o}px`:o;let d;e[5]!==a||e[6]!==c||e[7]!==l?(d={width:c,height:l,...a},e[5]=a,e[6]=c,e[7]=l,e[8]=d):d=e[8];let f;e[9]===Symbol.for("react.memo_cache_sentinel")?(f=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]=f):f=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:f}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const gi=[{id:"finder",label:"Finder",appName:"Finder"},{id:"terminal",label:"Terminal",appName:"Terminal"},{id:"iterm2",label:"iTerm2",appName:"iTerm"},{id:"ghostty",label:"Ghostty",appName:"Ghostty"},{id:"vscode",label:"VS Code",appName:"Visual Studio Code"},{id:"vscode-insiders",label:"VS Code Insiders",appName:"Visual Studio Code - Insiders"},{id:"intellij",label:"IntelliJ",appName:"IntelliJ IDEA"},{id:"visual-studio",label:"Visual Studio",appName:"Visual Studio"},{id:"cursor",label:"Cursor",appName:"Cursor"},{id:"android-studio",label:"Android Studio",appName:"Android Studio"},{id:"pycharm",label:"PyCharm",appName:"PyCharm"},{id:"xcode",label:"Xcode",appName:"Xcode"},{id:"sublime-text",label:"Sublime",appName:"Sublime Text"},{id:"webstorm",label:"WebStorm",appName:"WebStorm"},{id:"rider",label:"Rider",appName:"Rider"},{id:"zed",label:"Zed",appName:"Zed"},{id:"phpstorm",label:"PhpStorm",appName:"PhpStorm"},{id:"eclipse",label:"Eclipse",appName:"Eclipse"},{id:"windsurf",label:"Windsurf",appName:"Windsurf"},{id:"vscodium",label:"VSCodium",appName:"VSCodium"},{id:"rustrover",label:"RustRover",appName:"RustRover"},{id:"kiro",label:"Kiro",appName:"Kiro"},{id:"antigravity",label:"Antigravity",appName:"Antigravity"},{id:"trae",label:"Trae",appName:"Trae"}],sc="finder",nc=new Set(["finder","terminal"]),Gc=t=>typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32"&&t.id==="finder"?{...t,label:"Explorer",appName:"File Explorer"}:t,rc=t=>{if(!t)return null;const e=gi.find(n=>n.id===t)??null;return e?Gc(e):null},bl=()=>gi.filter(t=>nc.has(t.id)).map(t=>({...Gc(t)})),Pb=()=>{if(typeof window>"u")return sc;const t=window.localStorage.getItem("openInAppId");return t&&rc(t)?t:sc};let wl=!1,Gi=!1,li=!1,ci=0,Io=null;const au=()=>{Io&&(clearTimeout(Io),Io=null)},Sr=fo()((t,e)=>({selectedAppId:Pb(),availableApps:bl(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(wl||typeof window>"u")return;wl=!0;const n=(d,f=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:bl(),hasLoadedApps:f});return}const m=new Set(d.map(b=>b.name)),u=new Map(d.map(b=>[b.name,b.iconDataUrl??void 0])),x=gi.filter(b=>m.has(b.appName)||nc.has(b.id)).map(b=>({...Gc(b),iconDataUrl:u.get(b.appName)}));t({availableApps:x,hasLoadedApps:!0})},r=async d=>{if(!pr()||!io()||Gi||e().hasLoadedApps&&!d)return;const m=gi.map(u=>u.appName);au(),Gi=!0,li=!1,t({isScanning:!0});try{const{apps:u,success:p,hasCache:x,isCacheStale:b}=await Cd(m,d),w=p&&!x&&u.length===0&&ci<3;if(t({isCacheStale:x?b:!1}),n(u,p?!w:!1),p){if(w){const h=[800,1600,3200][ci]??3200;ci+=1,li=!0,Io=setTimeout(()=>{r()},h);return}ci=0,li=!1;return}if(ci<3){const h=[1e3,3e3,7e3][ci]??7e3;ci+=1,li=!0,Io=setTimeout(()=>{r()},h)}}finally{Gi=!1,li||t({isScanning:!1})}};r();const o=d=>{const f=d.detail,m=f&&typeof f.openInAppId=="string"&&f.openInAppId.length>0&&rc(f.openInAppId)?f.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},a=()=>{r()},c=d=>{const f=d.detail;Array.isArray(f)&&(ci=3,li=!1,t({isScanning:!1,isCacheStale:!1}),n(f))};window.addEventListener("openchamber:settings-synced",o),window.addEventListener("openchamber:app-ready",a),window.addEventListener("openchamber:installed-apps-updated",c),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(wl||e().initialize(),!pr()||!io()||Gi||e().hasLoadedApps&&!n)return;const o=gi.map(a=>a.appName);au(),n&&t({hasLoadedApps:!1}),Gi=!0,li=!1,t({isScanning:!0});try{const{apps:a,hasCache:c,isCacheStale:l}=await Cd(o,n),d=new Set(a.map(p=>p.name)),f=new Map(a.map(p=>[p.name,p.iconDataUrl??void 0])),u=gi.filter(p=>d.has(p.appName)||nc.has(p.id)).map(p=>({...p,iconDataUrl:f.get(p.appName)}));t({availableApps:u.length>0?u:bl(),hasLoadedApps:u.length>0,isCacheStale:c?l:!1})}finally{Gi=!1,li||t({isScanning:!1})}},selectApp:async n=>{rc(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await yc({openInAppId:n}))}})),Ib="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",Rb="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",yl=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__!=="win32"?Ib:t.id==="terminal"?Rb:void 0}),lu=t=>{const e=gt.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:o}=t,[a,c]=i.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const d=l,f=r||o;if(f&&!a){let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>c(!0),e[2]=p):p=e[2];let x;return e[3]!==f?(x=s.jsx("img",{src:f,alt:"",className:"h-4 w-4 rounded-sm",onError:p}),e[3]=f,e[4]=x):x=e[4],x}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=Pe("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 u;return e[6]!==d?(u=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=u):u=e[7],u},Eb=t=>{const e=gt.c(75),{directory:n,className:r}=t,{t:o}=yt(),a=Sr(Mb),c=Sr(Fb),l=Sr(Ob),d=Sr(Lb),f=Sr(Bb),m=Sr(Vb),u=Sr(_b);let p,x;e[0]!==f?(p=()=>{f()},x=[f],e[0]=f,e[1]=p,e[2]=x):(p=e[1],x=e[2]),i.useEffect(p,x);const b=pr()&&io();let w;e:{let ye;e[3]!==c||e[4]!==a?(ye=c.find(z=>z.id===a)??c.find($b)??c[0]??gi[0],e[3]=c,e[4]=a,e[5]=ye):ye=e[5];const he=ye;if(he){let z;e[6]!==he?(z=yl(he),e[6]=he,e[7]=z):z=e[7],w=z;break e}let Fe;e[8]===Symbol.for("react.memo_cache_sentinel")?(Fe=yl(gi[0]),e[8]=Fe):Fe=e[8],w=Fe}const g=w;if(!b||!n||c.length===0)return null;let h;e[9]!==n?(h=async ye=>{await xp(n,ye.id,ye.appName)||await Ca(n,ye.appName)},e[9]=n,e[10]=h):h=e[10];const k=h;let j;e[11]!==k||e[12]!==u?(j=async ye=>{await u(ye.id),await k(ye)},e[11]=k,e[12]=u,e[13]=j):j=e[13];const S=j;let N;e[14]!==n||e[15]!==o?(N=async()=>{(await gr(n)).ok&&le.success(o("openInApp.toast.pathCopied"))},e[14]=n,e[15]=o,e[16]=N):N=e[16];const C=N;let y;e[17]!==r?(y=Pe("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=y):y=e[18];let P;e[19]!==k||e[20]!==g?(P=()=>{k(g)},e[19]=k,e[20]=g,e[21]=P):P=e[21];const _=d&&"animate-pulse";let v;e[22]!==_?(v=Pe("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",_),e[22]=_,e[23]=v):v=e[23];let F;e[24]!==g.label||e[25]!==o?(F=o("openInApp.actions.openInAria",{app:g.label}),e[24]=g.label,e[25]=o,e[26]=F):F=e[26];let I;e[27]!==g.fallbackIconDataUrl||e[28]!==g.iconDataUrl||e[29]!==g.label?(I=s.jsx(lu,{label:g.label,iconDataUrl:g.iconDataUrl,fallbackIconDataUrl:g.fallbackIconDataUrl}),e[27]=g.fallbackIconDataUrl,e[28]=g.iconDataUrl,e[29]=g.label,e[30]=I):I=e[30];let R;e[31]!==v||e[32]!==F||e[33]!==I||e[34]!==P?(R=s.jsx("button",{type:"button",onClick:P,className:v,"aria-label":F,children:I}),e[31]=v,e[32]=F,e[33]=I,e[34]=P,e[35]=R):R=e[35];let B;e[36]===Symbol.for("react.memo_cache_sentinel")?(B=Pe("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[36]=B):B=e[36];let D;e[37]!==o?(D=o("openInApp.actions.chooseAppAria"),e[37]=o,e[38]=D):D=e[38];let W;e[39]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=W):W=e[39];let U;e[40]!==D?(U=s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button",className:B,"aria-label":D,children:W})}),e[40]=D,e[41]=U):U=e[41];let L;e[42]!==C?(L=()=>{C()},e[42]=C,e[43]=L):L=e[43];let M;e[44]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(A,{name:"file-copy",className:"h-4 w-4"}),e[44]=M):M=e[44];let ee;e[45]!==o?(ee=o("openInApp.actions.copyPath"),e[45]=o,e[46]=ee):ee=e[46];let ie;e[47]!==ee?(ie=s.jsx("span",{className:"typography-ui-label text-foreground",children:ee}),e[47]=ee,e[48]=ie):ie=e[48];let te;e[49]!==L||e[50]!==ie?(te=s.jsxs(ls,{className:"flex items-center gap-2",onClick:L,children:[M,ie]}),e[49]=L,e[50]=ie,e[51]=te):te=e[51];let H;e[52]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx($r,{}),e[52]=H):H=e[52];let J;if(e[53]!==c||e[54]!==S||e[55]!==g.id){let ye;e[57]!==S||e[58]!==g.id?(ye=he=>{const Fe=yl(he);return s.jsxs(ls,{className:"flex items-center gap-2",onClick:()=>{S(he)},children:[s.jsx(lu,{label:he.label,iconDataUrl:he.iconDataUrl,fallbackIconDataUrl:Fe.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:he.label}),g.id===he.id?s.jsx(A,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},he.id)},e[57]=S,e[58]=g.id,e[59]=ye):ye=e[59],J=c.map(ye),e[53]=c,e[54]=S,e[55]=g.id,e[56]=J}else J=e[56];let re;e[60]!==l||e[61]!==m||e[62]!==o?(re=l?s.jsxs(ls,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(A,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("openInApp.actions.refreshApps")})]}):null,e[60]=l,e[61]=m,e[62]=o,e[63]=re):re=e[63];let oe;e[64]!==te||e[65]!==J||e[66]!==re?(oe=s.jsxs(Zs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[te,H,J,re]}),e[64]=te,e[65]=J,e[66]=re,e[67]=oe):oe=e[67];let ve;e[68]!==U||e[69]!==oe?(ve=s.jsxs(en,{children:[U,oe]}),e[68]=U,e[69]=oe,e[70]=ve):ve=e[70];let ne;return e[71]!==R||e[72]!==ve||e[73]!==y?(ne=s.jsxs("div",{className:y,children:[R,ve]}),e[71]=R,e[72]=ve,e[73]=y,e[74]=ne):ne=e[74],ne};function Mb(t){return t.selectedAppId}function Fb(t){return t.availableApps}function Ob(t){return t.isCacheStale}function Lb(t){return t.isScanning}function Bb(t){return t.initialize}function Vb(t){return t.loadInstalledApps}function _b(t){return t.selectApp}function $b(t){return t.id===sc}const zb=1e6,Wb="terminal-store";let cu=!1;const vl=t=>typeof t=="object"&&t!==null,Ub=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function En(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const jl=(t,e)=>({id:t,terminalSessionId:null,lifecycle:"idle",label:e,iconKey:null,bufferChunks:[],bufferLength:0,isConnecting:!1,createdAt:Date.now(),previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1}),Sl=t=>({tabs:[t],activeTabId:t.id}),vr=(t,e)=>t.tabs.findIndex(n=>n.id===e),Ws=fo()(Hf(xc((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=En(n);r&&t(o=>{if(o.sessions.has(r))return o;const a=new Map(o.sessions),c=`tab-${o.nextTabId}`,l=jl(c,"Terminal");return a.set(r,Sl(l)),{sessions:a,nextTabId:o.nextTabId+1}})},getDirectoryState:n=>{const r=En(n);return e().sessions.get(r)},getActiveTab:n=>{const r=En(n),o=e().sessions.get(r);if(!o)return;const a=o.activeTabId;return a?o.tabs.find(c=>c.id===a)??o.tabs[0]:o.tabs[0]},createTab:n=>{const r=En(n);if(!r)return"tab-invalid";const o=`tab-${e().nextTabId}`;return t(a=>{const c=new Map(a.sessions),l=c.get(r),d=a.nextTabId+1,m=`Terminal ${(l?.tabs.length??0)+1}`,u=jl(o,m);return l?c.set(r,{...l,tabs:[...l.tabs,u]}):c.set(r,Sl(u)),{sessions:c,nextTabId:d}}),o},setActiveTab:(n,r)=>{const o=En(n);t(a=>{const c=new Map(a.sessions),l=c.get(o);return!l||l.activeTabId===r||vr(l,r)<0?a:(c.set(o,{...l,activeTabId:r}),{sessions:c})})},setTabLabel:(n,r,o)=>{const a=En(n),c=o.trim();c&&t(l=>{const d=new Map(l.sessions),f=d.get(a);if(!f)return l;const m=vr(f,r);if(m<0||f.tabs[m]?.label===c)return l;const u=[...f.tabs];return u[m]={...u[m],label:c},d.set(a,{...f,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,o)=>{const a=En(n);t(c=>{const l=new Map(c.sessions),d=l.get(a);if(!d)return c;const f=vr(d,r);if(f<0)return c;const m=o?.trim()||null;if(d.tabs[f]?.iconKey===m)return c;const u=[...d.tabs];return u[f]={...u[f],iconKey:m},l.set(a,{...d,tabs:u}),{sessions:l}})},closeTab:async(n,r)=>{const o=En(n),l=e().sessions.get(o)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(l)try{await bp(l)}catch{}t(d=>{const f=new Map(d.sessions),m=f.get(o);if(!m)return d;const u=vr(m,r);if(u<0)return d;const p=m.tabs.filter(g=>g.id!==r),x=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,g])=>!(g.directory===o&&g.tabId===r))),b=Object.keys(x).length!==Object.keys(d.projectActionRuns).length;if(p.length===0){const g=`tab-${d.nextTabId}`,h=jl(g,"Terminal");return f.set(o,Sl(h)),{sessions:f,nextTabId:d.nextTabId+1,...b?{projectActionRuns:x}:{}}}let w=m.activeTabId;return m.activeTabId===r&&(w=p[Math.min(u,p.length-1)]?.id??p[0]?.id??null),f.set(o,{...m,tabs:p,activeTabId:w}),{sessions:f,...b?{projectActionRuns:x}:{}}})},setTabSessionId:(n,r,o)=>{const a=En(n);t(c=>{const l=new Map(c.sessions),d=l.get(a);if(!d)return c;const f=vr(d,r);if(f<0)return c;const m=d.tabs[f],u=o!==null&&m.terminalSessionId!==o,p=o?"running":m.terminalSessionId?"exited":m.lifecycle,x={...m,terminalSessionId:o,lifecycle:p,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},b=[...d.tabs];return b[f]=x,l.set(a,{...d,tabs:b}),{sessions:l}})},setTabLifecycle:(n,r,o)=>{const a=En(n);t(c=>{const l=new Map(c.sessions),d=l.get(a);if(!d)return c;const f=vr(d,r);if(f<0)return c;const m=[...d.tabs];return m[f]={...m[f],lifecycle:o,isConnecting:!1},l.set(a,{...d,tabs:m}),{sessions:l}})},setConnecting:(n,r,o)=>{const a=En(n);t(c=>{const l=new Map(c.sessions),d=l.get(a);if(!d)return c;const f=vr(d,r);if(f<0)return c;const m=[...d.tabs];return m[f]={...m[f],isConnecting:o},l.set(a,{...d,tabs:m}),{sessions:l}})},appendToBuffer:(n,r,o)=>{if(!o)return;const a=En(n);t(c=>{const l=new Map(c.sessions),d=l.get(a);if(!d)return c;const f=vr(d,r);if(f<0)return c;const m=d.tabs[f],u=c.nextChunkId,p={id:u,data:o},x=[...m.bufferChunks,p];let b=m.bufferLength+o.length;for(;b>zb&&x.length>1;){const g=x.shift();if(!g)break;b-=g.data.length}const w=[...d.tabs];return w[f]={...m,bufferChunks:x,bufferLength:b},l.set(a,{...d,tabs:w}),{sessions:l,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,o,a={})=>{const c=En(n);t(l=>{const d=new Map(l.sessions),f=d.get(c);if(!f)return l;const m=vr(f,r);if(m<0)return l;const u=f.tabs[m],p=a.autoOpened??u.previewAutoOpened,x=a.locked??u.previewUrlLocked;if(u.previewUrl===o&&u.previewAutoOpened===p&&u.previewUrlLocked===x)return l;const b=[...f.tabs];return b[m]={...u,previewUrl:o,previewAutoOpened:p,previewUrlLocked:x},d.set(c,{...f,tabs:b}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const o=En(n);t(a=>{const c=new Map(a.sessions),l=c.get(o);if(!l)return a;const d=vr(l,r);if(d<0)return a;const f=l.tabs[d];if(!f.previewUrl||f.previewAutoOpened)return a;const m=[...l.tabs];return m[d]={...f,previewAutoOpened:!0},c.set(o,{...l,tabs:m}),{sessions:c}})},setProjectActionRun:n=>{t(r=>{const o=r.projectActionRuns[n.key];return o&&o.directory===n.directory&&o.actionId===n.actionId&&o.tabId===n.tabId&&o.sessionId===n.sessionId&&o.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(o=>{const a=o.projectActionRuns[n];return!a||a.status===r?o:{projectActionRuns:{...o.projectActionRuns,[n]:{...a,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const o={...r.projectActionRuns};return delete o[n],{projectActionRuns:o}})},clearBuffer:(n,r)=>{const o=En(n);t(a=>{const c=new Map(a.sessions),l=c.get(o);if(!l)return a;const d=vr(l,r);if(d<0)return a;const f=[...l.tabs];return f[d]={...f[d],bufferChunks:[],bufferLength:0},c.set(o,{...l,tabs:f}),{sessions:c}})},removeDirectory:n=>{const r=En(n);t(o=>{const a=new Map(o.sessions);a.delete(r);const c=Object.fromEntries(Object.entries(o.projectActionRuns).filter(([,l])=>l.directory!==r));return{sessions:a,projectActionRuns:c}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:Wb,storage:qh(()=>qf()),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,iconKey:r.iconKey,terminalSessionId:r.terminalSessionId,lifecycle:r.lifecycle,createdAt:r.createdAt}))}]),nextTabId:t.nextTabId}),merge:(t,e)=>{if(!vl(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let o=0;for(const l of n){if(!Array.isArray(l)||l.length!==2)continue;const[d,f]=l;if(typeof d!="string"||!vl(f))continue;const m=Array.isArray(f.tabs)?f.tabs:[],u=[];for(const b of m){if(!vl(b))continue;const w=typeof b.id=="string"?b.id:null;if(!w)continue;const g=Ub(w);g!==null&&(o=Math.max(o,g));const h=typeof b.terminalSessionId=="string"||b.terminalSessionId===null?b.terminalSessionId:null,k=b.lifecycle,j=k==="idle"||k==="running"||k==="exited"?k:h?"running":"idle";u.push({id:w,label:typeof b.label=="string"?b.label:"Terminal",iconKey:typeof b.iconKey=="string"?b.iconKey:null,terminalSessionId:h,lifecycle:j,createdAt:typeof b.createdAt=="number"?b.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const p=typeof f.activeTabId=="string"?f.activeTabId:null,x=p?u.some(b=>b.id===p):!1;r.set(d,{tabs:u,activeTabId:x?p:u[0].id})}const a=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,c=Math.max(e.nextTabId,a,o+1);return{...e,sessions:r,nextChunkId:1,nextTabId:c,hasHydrated:!0}}})));if(typeof window<"u"&&!cu){cu=!0;const t=Ws.persist,e=()=>{Ws.getState().hasHydrated||Ws.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const Hb=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Gb=["dev","start","preview","serve"];async function Kb(t,e,n){if(!t)return null;const r=Qb(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const o=Jb(n);if(o){const a=await Xb(t);return{command:`${a==="npm"?"npm run":a==="yarn"?"yarn":a==="pnpm"?"pnpm":a==="bun"?"bun run --shell=bun":"npm run"} ${o}`,label:`Start (${o})`}}}if(await qb(t)){const o=await Yb(),a=typeof o=="number"&&Number.isFinite(o)&&o>0?o:8e3;return{command:`python3 -m http.server ${a}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${a}/`}}return null}async function qb(t){const e=`${t}/index.html`,n=await Ma(e,t);return typeof n=="string"&&n.trim().length>0}async function Yb(){try{const t=await Is("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Qb(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(Gb.some(o=>n.includes(o)))return e}return null}function Jb(t){for(const{pattern:e}of Hb)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Xb(t){const e=await Ma(`${t}/package.json`,t);if(e)try{const r=JSON.parse(e),o=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(o.startsWith("bun@"))return"bun";if(o.startsWith("pnpm@"))return"pnpm";if(o.startsWith("yarn@"))return"yarn";if(o.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,o]of n){const a=await Ma(`${t}/${r}`,t);if(typeof a=="string"&&a.trim().length>0)return o}return"npm"}async function Ma(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),o=await Is(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=Wo()?.files;if(n?.readFile)try{const r=await n.readFile(t,{optional:!0});return typeof r?.content=="string"?r.content:null}catch{return null}try{const r=await Is(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function Zb(t){try{const e=await Ma(`${t}/package.json`,t);if(e==null)return null;const r=JSON.parse(e).scripts;return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}const ew=t=>new Promise(e=>{window.setTimeout(e,t)}),tw="\x1B",sw=new RegExp(`${tw}\\[[0-9;?]*[ -/]*[@-~]`,"g"),nw=/https?:\/\/[^\s<>'"`]+/gi,lr="__openchamber_auto_discover_preview__",rw=15e3,iw=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},ow=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}},aw=t=>{const n=t.replace(sw,"").match(nw);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 c=new URL(a);c.port&&c.port.length>0&&o.push({raw:a,parsed:c})}catch{}if(o.length>0){const a=c=>{const{parsed:l}=c,d=l.hostname.toLowerCase(),f=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=l.pathname||"/",u=m.split("/").filter(Boolean).length,p=m==="/"||m==="",x=!!(l.search||l.hash);let b=0;return f&&(b+=50),p&&(b+=30),b-=Math.min(u*5,20),x&&(b-=10),b};return o.sort((c,l)=>a(l)-a(c)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},Um=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{t:a}=yt(),{terminal:c,runtime:l}=nr(),{isMobile:d}=zr(),f=i.useMemo(()=>pr(),[]),m=su(E=>E.instances),u=su(E=>E.load),p=Ee(E=>E.setBottomTerminalOpen),x=Ee(E=>E.setActiveMainTab),b=Ee(E=>E.setSettingsPage),w=Ee(E=>E.setSettingsDialogOpen),g=Ee(E=>E.setSettingsProjectsSelectedId),h=Ee(E=>E.openContextPreview),k=Ws(E=>E.sessions),j=Ws(E=>E.ensureDirectory),S=Ws(E=>E.setTabLabel),N=Ws(E=>E.setTabIconKey),C=Ws(E=>E.setActiveTab),y=Ws(E=>E.setConnecting),P=Ws(E=>E.setTabSessionId),_=Ws(E=>E.setTabPreviewUrl),v=Ws(E=>E.projectActionRuns),F=Ws(E=>E.setProjectActionRun),I=Ws(E=>E.updateProjectActionRunStatus),R=Ws(E=>E.removeProjectActionRun),[B,D]=i.useState([]),[W,U]=i.useState(null),[L,M]=i.useState(!1),ee=i.useRef({}),ie=i.useRef({}),te=i.useRef({}),H=i.useRef({}),J=i.useRef(0),re=t?.id??null,oe=t?.path??"",ve=i.useMemo(()=>re?{id:re,path:oe}:null,[re,oe]);i.useEffect(()=>{f&&u().catch(()=>{})},[f,u]);const ne=i.useCallback(async E=>{await si(E)},[]),ye=i.useCallback(async()=>{if(!ve)return;const E=J.current+1;J.current=E,M(!0);try{const de=await Fd(ve);if(J.current!==E)return;const fe=de.actions;D(fe),U($=>$===lr||$&&fe.some(ke=>ke.id===$)?$:null)}catch{if(J.current!==E)return}finally{J.current===E&&M(!1)}},[ve]),he=i.useMemo(()=>Jx(e||ve?.path||""),[e,ve?.path]),Fe=i.useMemo(()=>W?B.find(E=>E.id===W)??null:null,[B,W]),z=i.useMemo(()=>({id:lr,name:a("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[a]),K=!d,Y=i.useMemo(()=>K?[z,...B]:B,[B,z,K]);i.useEffect(()=>{ye()},[ye]),i.useEffect(()=>{if(typeof window>"u")return;const E=de=>{const fe=de.detail;re&&(fe?.projectId&&fe.projectId!==re||ye())};return window.addEventListener(nu,E),()=>{window.removeEventListener(nu,E)}},[ye,re]),i.useEffect(()=>{W&&(W===lr&&K||B.some(E=>E.id===W)||U(null))},[B,K,W]),i.useEffect(()=>{for(const[E,de]of Object.entries(v)){const $=k.get(de.directory)?.tabs.find(ke=>ke.id===de.tabId);(!$||$.terminalSessionId!==de.sessionId)&&R(E)}},[v,R,k]),i.useEffect(()=>{for(const[E,de]of Object.entries(v)){const fe=ie.current[E]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};ie.current[E]=fe;const $=Y.find(ae=>ae.id===de.actionId);if(!$)continue;const Ve=k.get(de.directory)?.tabs.find(ae=>ae.id===de.tabId);if(!Ve||!Array.isArray(Ve.bufferChunks)||Ve.bufferChunks.length===0)continue;const Se=Ve.bufferChunks.filter(ae=>fe.lastSeenChunkId===null?!0:ae.id>fe.lastSeenChunkId);if(Se.length===0)continue;const q=Se.map(ae=>ae.data).join(""),O=`${fe.tail}${q}`,se=!fe.openedUrl&&$.autoOpenUrl===!0?aw(O):null,Le=Se[Se.length-1]?.id??fe.lastSeenChunkId;if(fe.lastSeenChunkId=Le,fe.tail=O.slice(-512),se)if(fe.openedUrl=!0,fe.openInPreview){const ae=v[E];ae&&(_(ae.directory,ae.tabId,se,{locked:!1,autoOpened:!1}),ae.status==="waiting-for-preview"&&I(E,"running"),window.clearTimeout(H.current[E]),delete H.current[E],h(ae.directory,se))}else ne(se),le.success(a("projectActions.toast.openedUrlFromOutput"));ie.current[E]=fe}for(const E of Object.keys(ie.current))v[E]||(delete ie.current[E],window.clearTimeout(H.current[E]),delete H.current[E])},[Y,h,ne,v,_,a,k,I]);const me=i.useCallback(async(E,de={})=>{if(!he)throw new Error(a("projectActions.error.noActiveDirectory"));const fe=ai(he,E.id);j(he);const $=Ws.getState(),ke=$.getDirectoryState(he);let Ve=ee.current[fe]||null;const Se=Ve?!!ke?.tabs.some(se=>se.id===Ve):!1;(!Ve||!Se)&&(Ve=$.createTab(he),ee.current[fe]=Ve),S(he,Ve,`Action: ${E.name}`),N(he,Ve,E.icon||"play"),de.revealTerminal!==!1&&(C(he,Ve),p(!0),x("terminal"));const O=Ws.getState().getDirectoryState(he)?.tabs.find(se=>se.id===Ve);return{key:fe,tabId:Ve,sessionId:O?.terminalSessionId??null}},[j,he,x,C,p,N,S,a]),Ne=i.useCallback(async E=>{if(l.isVSCode||!o&&d)return;if(!he){le.error(a("projectActions.error.noActiveDirectoryForAction"));return}const de=ai(he,E.id),fe=v[de];if(!(fe&&fe.status==="running"))try{const $=E.id===lr?await(async()=>{const[Qe,st]=await Promise.all([Fd({id:ve?.id??"",path:he}),Zb(he)]),pt=await Kb(he,Qe.actions,st);if(!pt)throw new Error(a("contextPanel.preview.noDevServer"));return{id:lr,name:a("projectActions.actions.autoDiscover"),command:pt.command,icon:"search",autoOpenUrl:!0,openUrl:pt.previewUrlHint||""}})():E,ke=$.autoOpenUrl===!0&&($.openUrl||"").trim().length>0,{key:Ve,tabId:Se,sessionId:q}=await me($,{revealTerminal:!ke&&E.id!==lr});let O=q,se=!1;if(!O){y(he,Se,!0);try{O=(await c.createSession({cwd:he})).sessionId,se=!0,P(he,Se,O)}finally{y(he,Se,!1)}}if(!O)throw new Error(a("projectActions.error.failedToCreateTerminalSession"));se&&await ew(350),$.id===lr&&(te.current[Ve]?.(),y(he,Se,!0),te.current[Ve]=wp(O,Qe=>{Qe.type==="data"&&typeof Qe.data=="string"&&Qe.data.length>0&&Ws.getState().appendToBuffer(he,Se,Qe.data),Qe.type==="exit"&&(Ws.getState().setTabLifecycle(he,Se,"exited"),Ws.getState().setConnecting(he,Se,!1),Ws.getState().removeProjectActionRun(Ve),delete ie.current[Ve],te.current[Ve]?.(),delete te.current[Ve],window.clearTimeout(H.current[Ve]),delete H.current[Ve])},()=>{Ws.getState().setConnecting(he,Se,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Le=$.autoOpenUrl===!0&&f&&($.desktopOpenSshForward||"").trim().length>0,ae=$.autoOpenUrl?ow($.openUrl):null,We=$.autoOpenUrl&&f?Xx($.desktopOpenSshForward,m):null;F({key:Ve,directory:he,actionId:$.id,tabId:Se,sessionId:O,status:$.id===lr&&!ae?"waiting-for-preview":"running"}),window.clearTimeout(H.current[Ve]),delete H.current[Ve],$.id===lr&&!ae&&(H.current[Ve]=window.setTimeout(()=>{Ws.getState().updateProjectActionRunStatus(Ve,"running"),delete H.current[Ve]},rw)),We?(_(he,Se,null,{locked:!0}),ne(We),le.success(a("projectActions.toast.openedForwardedUrl"))):ae?(_(he,Se,ae,{locked:!0,autoOpened:!0}),h(he,ae),le.success(a("projectActions.toast.openedActionUrl"))):ke?(_(he,Se,null,{locked:!0}),le.error(a("projectActions.error.invalidCustomUrlFormat"))):Le?(_(he,Se,null,{locked:!0}),le.error(a("projectActions.error.selectedDesktopSshForwardUnavailable"))):_(he,Se,null,{locked:!1,autoOpened:!1}),ie.current[Ve]={lastSeenChunkId:null,openedUrl:!!We||!!ae||ke,tail:"",openInPreview:$.id===lr};const Ye=iw($.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
+
`));await c.sendInput(O,`${Ye}\r`)}catch($){R(de),delete ie.current[de],te.current[de]?.(),delete te.current[de],window.clearTimeout(H.current[de]),delete H.current[de],le.error($ instanceof Error?$.message:a("projectActions.error.failedToRunAction"))}},[m,me,o,d,f,he,ne,h,v,l.isVSCode,R,y,F,_,P,ve?.id,a,c]),Be=i.useCallback(async E=>{const de=ai(he,E.id),fe=v[de];if(!fe)return;I(de,"stopping");try{await c.sendInput(fe.sessionId,"")}catch{}if(await new Promise(Ve=>{window.setTimeout(Ve,1e3)}),Ws.getState().getDirectoryState(fe.directory)?.tabs.find(Ve=>Ve.id===fe.tabId)?.terminalSessionId===fe.sessionId){if(typeof c.forceKill=="function")try{await c.forceKill({sessionId:fe.sessionId})}catch{}else try{await c.close(fe.sessionId)}catch{}P(fe.directory,fe.tabId,null)}R(de),delete ie.current[de],te.current[de]?.(),delete te.current[de],window.clearTimeout(H.current[de]),delete H.current[de]},[he,v,R,P,c,I]),_e=i.useCallback(()=>{const E=Fe??Y[0];if(!E)return;const de=ai(he,E.id),fe=v[de];if(fe?.status!=="stopping"){if(fe){Be(E);return}Ne(E)}},[Y,he,Ne,v,Fe,Be]),Oe=i.useCallback((E,de=!1)=>{if(U(E.id),!de){Ne(E);return}const fe=ai(he,E.id),$=v[fe];if($?.status!=="stopping"){if($){Be(E);return}Ne(E)}},[he,Ne,v,Be]),pe=i.useCallback(()=>{ve?.id&&(g(ve.id),b("projects"),w(!0))},[w,b,g,ve?.id]);if(l.isVSCode||!o&&d||!ve||!he)return null;const Re=Fe??Y[0]??null;if(!Re)return null;const ge=Re.icon||"play",ce=Re.id===lr?"search":gl[ge]||"play",Ce=ai(he,Re.id),be=v[Ce],ue=be?.status==="stopping",De=be?.status==="waiting-for-preview",T=be?k.get(be.directory)?.tabs.find(E=>E.id===be.tabId)?.previewUrl??null:null,V=!!(be&&T),we=()=>{!be||!T||h(be.directory,T)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:L||ue,className:Pe("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:_e,"aria-label":be?a("projectActions.actions.stopNamedAria",{name:Re.name}):a("projectActions.actions.runNamedAria",{name:Re.name}),children:ue||De?s.jsx(A,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):be?s.jsx(A,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(A,{name:ce,className:"h-5 w-5"})}),V?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":a("projectActions.actions.openPreview"),onClick:we,children:s.jsx(A,{name:"global",className:"h-4 w-4"})})}),s.jsx(Tt,{sideOffset:6,children:a("projectActions.actions.openPreview")})]}):null,s.jsxs(en,{children:[s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":a("projectActions.actions.chooseActionAria"),children:s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Zs,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(ls,{className:"flex items-center gap-2",onClick:pe,children:[s.jsx(A,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("projectActions.actions.addNewAction")})]}),s.jsx($r,{}),Y.map(E=>{const de=E.icon||"play",fe=E.id===lr?"search":gl[de]||"play",$=ai(he,E.id),ke=v[$],Ve=!!ke,Se=ke?.status==="stopping";return s.jsxs(ls,{className:"flex items-center gap-2",onClick:()=>{Oe(E,!0)},children:[s.jsx(A,{name:fe,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:E.name}),Se||ke?.status==="waiting-for-preview"?s.jsx(A,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):Ve?s.jsx(A,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},E.id)})]})]})]}):s.jsxs("div",{className:Pe("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsx("button",{type:"button",onClick:_e,disabled:L||ue,className:Pe("inline-flex h-full items-center justify-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 px-0":"px-2.5","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":be?a("projectActions.actions.stopNamedAria",{name:Re.name}):a("projectActions.actions.runNamedAria",{name:Re.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:ue||De?s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):be?s.jsx(A,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(A,{name:ce,className:"h-4 w-4"})})}),V?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:we,className:Pe(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":a("projectActions.actions.openPreview"),children:s.jsx(A,{name:"global",className:"h-4 w-4"})})}),s.jsx(Tt,{sideOffset:6,children:a("projectActions.actions.openPreview")})]}):null,s.jsxs(en,{children:[s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe(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":a("projectActions.actions.chooseActionAria"),children:s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Zs,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(ls,{className:"flex items-center gap-2",onClick:pe,children:[s.jsx(A,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("projectActions.actions.addNewAction")})]}),s.jsx($r,{}),Y.map(E=>{const de=E.icon||"play",fe=E.id===lr?"search":gl[de]||"play",$=ai(he,E.id),ke=v[$],Ve=!!ke,Se=ke?.status==="stopping";return s.jsxs(ls,{className:"flex items-center gap-2",onClick:()=>{Oe(E,!0)},children:[s.jsx(A,{name:fe,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:E.name}),Se||ke?.status==="waiting-for-preview"?s.jsx(A,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):Ve?s.jsx(A,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},E.id)})]})]})]})},el="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",lw="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",Qo=i.memo(function(e){const n=gt.c(17),{visible:r,title:o,ariaLabel:a,onClick:c,className:l,Icon:d,iconClassName:f,pressed:m}=e,u=r===void 0?!0:r,p=m===void 0?!1:m;if(!u)return null;const x=l??el,b=p&&"bg-interactive-selection text-interactive-selection-foreground";let w;n[0]!==x||n[1]!==b?(w=Pe(x,b),n[0]=x,n[1]=b,n[2]=w):w=n[2];const g=f??"h-[18px] w-[18px]";let h;n[3]!==d||n[4]!==g?(h=s.jsx(A,{name:d,className:g}),n[3]=d,n[4]=g,n[5]=h):h=n[5];let k;n[6]!==a||n[7]!==c||n[8]!==p||n[9]!==w||n[10]!==h?(k=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,"aria-label":a,"aria-pressed":p,className:w,children:h})}),n[6]=a,n[7]=c,n[8]=p,n[9]=w,n[10]=h,n[11]=k):k=n[11];let j;n[12]!==o?(j=s.jsx(Tt,{children:s.jsx("p",{children:o})}),n[12]=o,n[13]=j):j=n[13];let S;return n[14]!==k||n[15]!==j?(S=s.jsxs(At,{children:[k,j]}),n[14]=k,n[15]=j,n[16]=S):S=n[16],S}),cw=i.memo(function(e){const n=gt.c(42),{isMobile:r,githubAuthStatus:o,githubAccounts:a,githubAvatarUrl:c,githubLogin:l,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:f}=e,{t:m}=yt();if(!o?.connected||r)return null;if(a.length>1){let b;n[0]===Symbol.for("react.memo_cache_sentinel")?(b=Pe(el,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=b):b=n[0];let w;n[1]!==l||n[2]!==m?(w=l?m("header.github.connectedWithLogin",{login:l}):m("header.github.connected"),n[1]=l,n[2]=m,n[3]=w):w=n[3];let g;n[4]!==c||n[5]!==l||n[6]!==m?(g=c?s.jsx("img",{src:c,alt:l?m("header.github.avatarWithLogin",{login:l}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=c,n[5]=l,n[6]=m,n[7]=g):g=n[7];let h;n[8]!==d||n[9]!==w||n[10]!==g?(h=s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button",className:b,title:w,disabled:d,children:g})}),n[8]=d,n[9]=w,n[10]=g,n[11]=h):h=n[11];let k;n[12]!==m?(k=m("header.github.accountsTitle"),n[12]=m,n[13]=k):k=n[13];let j;n[14]!==k?(j=s.jsx(Vp,{className:"typography-ui-header font-semibold text-foreground",children:k}),n[14]=k,n[15]=j):j=n[15];let S;n[16]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx($r,{}),n[16]=S):S=n[16];let N;if(n[17]!==a||n[18]!==f||n[19]!==d||n[20]!==m){let P;n[22]!==f||n[23]!==d||n[24]!==m?(P=_=>{const v=_.user,F=!!_.current,I=_.source==="gh-cli"?m("header.github.accountSource.cli"):m("header.github.accountSource.oauth");return s.jsxs(ls,{className:"gap-2",disabled:d,onSelect:()=>{F||f(_.id)},children:[v?.avatarUrl?s.jsx("img",{src:v.avatarUrl,alt:v.login?m("header.github.avatarWithLogin",{login:v.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(A,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:v?.name?.trim()||v?.login||"GitHub"}),v?.login?s.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:v.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:I})]}):null]}),F?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]},_.id)},n[22]=f,n[23]=d,n[24]=m,n[25]=P):P=n[25],N=a.map(P),n[17]=a,n[18]=f,n[19]=d,n[20]=m,n[21]=N}else N=n[21];let C;n[26]!==j||n[27]!==N?(C=s.jsxs(Zs,{align:"end",className:"w-64",children:[j,S,N]}),n[26]=j,n[27]=N,n[28]=C):C=n[28];let y;return n[29]!==h||n[30]!==C?(y=s.jsxs(en,{children:[h,C]}),n[29]=h,n[30]=C,n[31]=y):y=n[31],y}let u;n[32]!==l||n[33]!==m?(u=l?m("header.github.connectedWithLogin",{login:l}):m("header.github.connected"),n[32]=l,n[33]=m,n[34]=u):u=n[34];let p;n[35]!==c||n[36]!==l||n[37]!==m?(p=c?s.jsx("img",{src:c,alt:l?m("header.github.avatarWithLogin",{login:l}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=c,n[36]=l,n[37]=m,n[38]=p):p=n[38];let x;return n[39]!==u||n[40]!==p?(x=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:u,children:p}),n[39]=u,n[40]=p,n[41]=x):x=n[41],x}),dw=i.memo(function(e){const n=gt.c(84),{isDesktopApp:r,currentInstanceLabel:o,compactCurrentInstanceLabel:a,currentInstanceIsLocal:c,isDesktopServicesOpen:l,setIsDesktopServicesOpen:d,refreshCurrentInstanceLabel:f,desktopServicesTab:m,setDesktopServicesTab:u,quotaResultsLength:p,fetchAllQuotas:x,servicesTabItems:b,quotaLastUpdated:w,quotaDisplayMode:g,quotaDisplayTabItems:h,handleDisplayModeChange:k,handleUsageRefresh:j,isQuotaLoading:S,isUsageRefreshSpinning:N,hasRateLimits:C,rateLimitGroups:y,expandedFamilies:P,toggleFamilyExpanded:_,shortcutLabel:v,showDevShutdown:F,isDevShutdownInFlight:I,onDevShutdown:R,remoteUpdateInfo:B,remoteUpdateChecking:D,remoteUpdateError:W,onOpenRemoteUpdate:U,showPredValues:L,timeFormatPreference:M}=e,{t:ee}=yt();let ie;n[0]!==m||n[1]!==x||n[2]!==p||n[3]!==f||n[4]!==d?(ie=Oe=>{d(Oe),Oe&&(f(),m==="usage"&&p===0&&x())},n[0]=m,n[1]=x,n[2]=p,n[3]=f,n[4]=d,n[5]=ie):ie=n[5];let te;n[6]!==o||n[7]!==r||n[8]!==ee?(te=r?ee("header.services.openWithCurrent",{current:o}):ee("header.services.open"),n[6]=o,n[7]=r,n[8]=ee,n[9]=te):te=n[9];const H=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let J;n[10]!==H?(J=Pe(el,H),n[10]=H,n[11]=J):J=n[11];let re;n[12]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(A,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=re):re=n[12];let oe;n[13]!==a||n[14]!==r?(oe=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:a}):null,n[13]=a,n[14]=r,n[15]=oe):oe=n[15];let ve;n[16]!==te||n[17]!==J||n[18]!==oe?(ve=s.jsx(Dt,{asChild:!0,children:s.jsx(Xs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":te,className:J,children:[re,oe]})})}),n[16]=te,n[17]=J,n[18]=oe,n[19]=ve):ve=n[19];let ne;n[20]!==o||n[21]!==r||n[22]!==v||n[23]!==ee?(ne=r?ee("header.services.tooltip.currentInstanceWithShortcuts",{current:o,toggle:v("toggle_services_menu"),nextTab:v("cycle_services_tab")}):ee("header.services.tooltip.servicesWithShortcuts",{toggle:v("toggle_services_menu"),nextTab:v("cycle_services_tab")}),n[20]=o,n[21]=r,n[22]=v,n[23]=ee,n[24]=ne):ne=n[24];let ye;n[25]!==ne?(ye=s.jsx(Tt,{children:s.jsx("p",{children:ne})}),n[25]=ne,n[26]=ye):ye=n[26];let he;n[27]!==ve||n[28]!==ye?(he=s.jsxs(At,{children:[ve,ye]}),n[27]=ve,n[28]=ye,n[29]=he):he=n[29];let Fe;n[30]!==x||n[31]!==p||n[32]!==u?(Fe=Oe=>{const pe=Oe;u(pe),pe==="usage"&&p===0&&x()},n[30]=x,n[31]=p,n[32]=u,n[33]=Fe):Fe=n[33];let z;n[34]!==m||n[35]!==b||n[36]!==Fe?(z=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(Vo,{items:b,activeId:m,onSelect:Fe,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=m,n[35]=b,n[36]=Fe,n[37]=z):z=n[37];let K;n[38]!==c||n[39]!==m||n[40]!==r||n[41]!==l||n[42]!==U||n[43]!==D||n[44]!==W||n[45]!==B||n[46]!==d||n[47]!==ee?(K=r&&m==="instance"?s.jsxs("div",{children:[c?null:s.jsx("div",{className:"border-b border-[var(--interactive-border)] px-4 py-2.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:ee("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:B?.available?ee("header.services.remoteUpdate.available",{version:B.version||""}):D?ee("header.services.remoteUpdate.checking"):W||ee("header.services.remoteUpdate.upToDate")})]}),B?.available?s.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-[var(--primary-base)] px-3 py-1.5 typography-ui-label font-medium text-[var(--primary-foreground)] hover:opacity-90",onClick:U,children:ee("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(Bp,{embedded:!0,open:l&&m==="instance",onOpenChange:mw,onHostSwitched:()=>d(!1)})]}):null,n[38]=c,n[39]=m,n[40]=r,n[41]=l,n[42]=U,n[43]=D,n[44]=W,n[45]=B,n[46]=d,n[47]=ee,n[48]=K):K=n[48];let Y;n[49]!==m||n[50]!==l?(Y=m==="mcp"?s.jsx(Pm,{active:l&&m==="mcp"}):null,n[49]=m,n[50]=l,n[51]=Y):Y=n[51];let me;n[52]!==m||n[53]!==P||n[54]!==k||n[55]!==j||n[56]!==C||n[57]!==S||n[58]!==N||n[59]!==g||n[60]!==h||n[61]!==w||n[62]!==y||n[63]!==L||n[64]!==ee||n[65]!==M||n[66]!==_?(me=m==="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:ee("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Hm(w,M)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Vo,{items:h,activeId:g,onSelect:Oe=>{k(Oe)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:Pe("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:j,disabled:S||N,"aria-label":ee("header.services.refreshRateLimitsAria"),children:s.jsx(A,{name:"refresh",className:Pe("h-4 w-4",N&&"animate-spin")})})]})]}),C?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:ee("header.services.noRateLimits")})}),s.jsx("div",{className:"space-y-2 px-3 py-2.5",children:y.map(Oe=>{const pe=P[Oe.providerId]??[];return s.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 pb-2",children:[s.jsx(Lo,{providerId:Oe.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Oe.providerName})]}),Oe.entries.length===0&&(!Oe.modelFamilies||Oe.modelFamilies.length===0)?s.jsx("div",{children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Oe.error??ee("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3",children:[Oe.entries.map(Re=>{const[ge,ce]=Re,Ce=g==="remaining"?ce.remainingPercent:ce.usedPercent,be=Da(ce.usedPercent,ce.resetAt,ce.windowSeconds,ge),ue=be?.dailyAllocationPercent!=null?g==="remaining"?100-hi(be.elapsedRatio):hi(be.elapsedRatio):null,De=Bo(ce.valueLabel,Ce),T=tm(ce.resetAt,ce.resetAfterFormatted??ce.resetAtFormatted,M);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:Nc(ge)}),T?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:T}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:De==="-"?"":De})]}),s.jsx(Ra,{percent:Ce,tonePercent:ce.usedPercent,className:"h-1.5",expectedMarkerPercent:ue}),be&&L?s.jsx(Ea,{paceInfo:be,compact:!0}):null]},`${Oe.providerId}-${ge}`)}),Oe.modelFamilies&&Oe.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:Oe.modelFamilies.map(Re=>{const ge=Re.familyId??"other",ce=pe.includes(ge);return s.jsxs(lo,{open:ce,onOpenChange:()=>_(Oe.providerId,ge),children:[s.jsxs(Ho,{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:Re.familyLabel}),ce?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(co,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Re.models.map(Ce=>{const[be,ue]=Ce,De=g==="remaining"?ue.remainingPercent:ue.usedPercent,T=Da(ue.usedPercent,ue.resetAt,ue.windowSeconds),V=T?.dailyAllocationPercent!=null?g==="remaining"?100-hi(T.elapsedRatio):hi(T.elapsedRatio):null,we=Bo(ue.valueLabel,De);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:Tm(be)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:we==="-"?"":we})]}),s.jsx(Ra,{percent:De,tonePercent:ue.usedPercent,className:"h-1.5",expectedMarkerPercent:V}),T&&L?s.jsx(Ea,{paceInfo:T,compact:!0}):null]},`${Oe.providerId}-${be}`)})})})]},ge)})}):null]})]},Oe.providerId)})})]}):null,n[52]=m,n[53]=P,n[54]=k,n[55]=j,n[56]=C,n[57]=S,n[58]=N,n[59]=g,n[60]=h,n[61]=w,n[62]=y,n[63]=L,n[64]=ee,n[65]=M,n[66]=_,n[67]=me):me=n[67];let Ne;n[68]!==I||n[69]!==R||n[70]!==F||n[71]!==ee?(Ne=F?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx(ls,{disabled:I,onSelect:()=>{R()},children:ee("header.services.shutdownDev")})})]}):null,n[68]=I,n[69]=R,n[70]=F,n[71]=ee,n[72]=Ne):Ne=n[72];let Be;n[73]!==z||n[74]!==K||n[75]!==Y||n[76]!==me||n[77]!==Ne?(Be=s.jsxs(Zs,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[z,K,Y,me,Ne]}),n[73]=z,n[74]=K,n[75]=Y,n[76]=me,n[77]=Ne,n[78]=Be):Be=n[78];let _e;return n[79]!==l||n[80]!==ie||n[81]!==he||n[82]!==Be?(_e=s.jsxs(en,{open:l,onOpenChange:ie,children:[he,Be]}),n[79]=l,n[80]=ie,n[81]=he,n[82]=Be,n[83]=_e):_e=n[83],_e}),uw=(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??""),fw=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},Hm=(t,e)=>{if(!t)return"-";try{return sm(t,e,{fallback:"-"})}catch{return"-"}},Mn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},di=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,du=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{const{t:o}=yt(),a=Ee(X=>X.setSessionSwitcherOpen),c=Ee(X=>X.toggleSidebar),l=Ee(X=>X.isSidebarOpen),d=Ee(X=>X.toggleBottomTerminal),f=Ee(X=>X.toggleRightSidebar),m=Ee(X=>X.openContextOverview),u=Ee(X=>X.openContextPlan),p=Ee(X=>X.openContextBrowser),x=Ee(X=>X.openContextPanelTab),b=Ee(X=>X.closeContextPanel),w=Ee(X=>X.contextPanelByDirectory),g=Ee(X=>X.activeMainTab),h=Ee(X=>X.setActiveMainTab),k=Ee(X=>X.shortcutOverrides),j=Ee(X=>X.timeFormatPreference),S=rs(X=>X.getCurrentModel),N=nr(),[C,y]=i.useState(!1),P=ht(X=>X.getContextUsage),_=ht(X=>!!X.newSessionDraft?.open),v=ht(X=>X.currentSessionId),F=_p(v??""),I=nm(v??null),R=kr(X=>X.activeSessions),B=kc(),D=Ds(X=>X.activeProjectId?X.projects.find(it=>it.id===X.activeProjectId)??null:null),W=i.useMemo(()=>{if(!D)return null;const X=D.label?.trim();if(X)return X;const it=D.path.split(/[\\/]/).filter(Boolean);return it[it.length-1]??null},[D]),U=pn(X=>X.results),L=pn(X=>X.fetchAllQuotas),M=pn(X=>X.isLoading),ee=pn(X=>X.lastUpdated),ie=pn(X=>X.displayMode),te=pn(X=>X.showPredValues),H=pn(X=>X.dropdownProviderIds),J=pn(X=>X.loadSettings),re=pn(X=>X.setDisplayMode),{isMobile:oe}=zr(),ve=$i(X=>X.status),ne=$i(X=>X.setStatus),ye=i.useRef(null),[he,Fe]=i.useState(()=>typeof window>"u"?!1:pr()),z=i.useMemo(()=>Wa(),[]),K=rm(),[Y,me]=i.useState(!1),Ne=i.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),{usesFramelessChrome:Be,side:_e}=Vm(),Oe=i.useMemo(()=>{if(typeof window>"u")return null;const X=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof X=="number"&&Number.isFinite(X)&&X>0)return X;if(typeof navigator>"u")return null;const it=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!it)return null;const dt=Number.parseInt(it[1],10),kt=Number.parseInt(it[2],10);return Number.isNaN(dt)?null:dt===10?kt:dt},[]);nt.useEffect(()=>{typeof window>"u"||Fe(pr())},[]);const pe=S(),Re=pe&&typeof pe.limit=="object"&&pe.limit!==null?pe.limit:null,ge=Re&&typeof Re.context=="number"?Re.context:0,ce=Re&&typeof Re.output=="number"?Re.output:0,Ce=P(ge,ce),[be,ue]=i.useState(null),De=!v||F;nt.useEffect(()=>{if(!v){ue(X=>X===null?X:null);return}if(Ce&&Ce.totalTokens>0){ue(X=>uw(X,Ce)?X:Ce);return}De&&ue(X=>X===null?X:null)},[Ce,v,De]);const T=Ee(X=>X.isSessionSwitcherOpen),V=ve?.connected?ve.user?.avatarUrl??null:null,we=ve?.connected?ve.user?.login??null:null,E=ve?.accounts??[],[de,fe]=i.useState(!1),[$,ke]=i.useState(!1),[Ve,Se]=i.useState(!1),[q,O]=i.useState(!1),[se,Le]=i.useState("Local"),[ae,We]=i.useState(!0),[Ye,Qe]=i.useState(!1),[st,pt]=i.useState(null),[jt,Et]=i.useState(!1),[Rt,Ut]=i.useState(null),ts=i.useMemo(()=>fw(se),[se]),[Kt,is]=i.useState(he?"instance":"usage"),[qt,Te]=i.useState("usage");nt.useEffect(()=>{!he&&Kt==="instance"&&is("usage")},[Kt,he]);const Ke=i.useMemo(()=>Cr(),[]),rt=!Ke&&g==="chat"&&!!be&&be.totalTokens>0,vt=be&&be.contextLimit>0?Math.min(999,be.totalTokens/be.contextLimit*100):0,Je=i.useCallback(async()=>{if(!(typeof window>"u"||!he))try{if(io()){Le("Local"),We(!0);return}We(!1);const X=await Yf(),it=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,dt=Xr();if(dt&&Aa(dt,it)){Le("Local"),We(!0);return}const kt=X.hosts.find(Wt=>dt?Aa(dt,Qf(Wt)):!1);if(kt?.label?.trim()){Le(Jf(kt.label.trim()));return}Le("Instance")}catch{Le("Local"),We(!0)}},[he]);nt.useEffect(()=>{Je()},[Je]);const St=i.useCallback(async()=>{if(ae){pt(null),Ut(null);return}Et(!0),Ut(null);try{const X=new URLSearchParams({appType:"web",instanceMode:"remote"}),it=await Is(`/api/openchamber/update-check?${X.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!it.ok)throw new Error(`Server responded with ${it.status}`);const dt=await it.json();pt({available:dt.available??!1,version:dt.version,currentVersion:dt.currentVersion??"unknown",body:dt.body,nextSuggestedCheckInSec:typeof dt.nextSuggestedCheckInSec=="number"?dt.nextSuggestedCheckInSec:void 0,packageManager:dt.packageManager,updateCommand:dt.updateCommand})}catch(X){pt(null),Ut(X instanceof Error?X.message:o("header.services.remoteUpdate.error"))}finally{Et(!1)}},[ae,o]);i.useEffect(()=>{pt(null),Ut(null),Qe(!1)},[ae,se]),i.useEffect(()=>{if(!he||ae)return;const X=3e3,it=3600*1e3;let dt=!1,kt=null;const Wt=fs=>{kt=window.setTimeout(()=>{if(dt||typeof document<"u"&&document.visibilityState!=="visible"){Wt(it);return}St().finally(()=>{dt||Wt(it)})},fs)};return Wt(X),()=>{dt=!0,kt!==null&&window.clearTimeout(kt)}},[St,ae,se,he]);const Xe=i.useCallback(()=>{if(st?.available){Qe(!0);return}St()},[St,st?.available]);Zx();const qe=pn(X=>X.selectedModels),et=pn(X=>X.expandedFamilies),Vt=pn(X=>X.toggleFamilyExpanded),Ct=i.useMemo(()=>{const X=[];for(const it of Im){if(!H.includes(it.id))continue;const dt=U.find(zs=>zs.providerId===it.id),kt=dt?.usage?.windows??{},Wt=dt?.usage?.models,fs=Object.entries(kt),bs={providerId:it.id,providerName:it.name,entries:fs,error:dt&&!dt.ok&&dt.configured?dt.error:void 0};if(Wt&&Object.keys(Wt).length>0){const zs=qe[it.id]??[],Ys=zs.length>0,xn=eb(Wt,it.id),fr=tb(it.id),Nn=sb(fr);bs.modelFamilies=[];for(const kn of Nn){const ln=xn.get(kn.id)??[];if(ln.length===0)continue;const In=Ys?ln.filter(ir=>zs.includes(ir)):ln;if(In.length===0)continue;const fn=[];for(const ir of In){const Qn=Wt[ir];if(Qn?.windows){const Rn=Object.entries(Qn.windows);Rn.length>0&&fn.push([ir,Rn[0][1]])}}fn.length>0&&bs.modelFamilies.push({familyId:kn.id,familyLabel:kn.label,models:fn})}const Wr=xn.get(null)??[],Tr=Ys?Wr.filter(kn=>zs.includes(kn)):Wr;if(Tr.length>0){const kn=[];for(const ln of Tr){const In=Wt[ln];if(In?.windows){const fn=Object.entries(In.windows);fn.length>0&&kn.push([ln,fn[0][1]])}}kn.length>0&&bs.modelFamilies.push({familyId:null,familyLabel:o("header.services.modelFamily.other"),models:kn})}}(fs.length>0||bs.modelFamilies&&bs.modelFamilies.length>0||bs.error)&&X.push(bs)}return X},[H,U,qe,o]),Ht=Ct.length>0;i.useEffect(()=>{J()},[J]);const ss=i.useCallback(async X=>{re(X);try{await yc({usageDisplayMode:X})}catch(it){console.warn("Failed to update usage display mode:",it)}},[re]),Xt=i.useCallback(()=>{if(q)return;O(!0);const X=new Promise(it=>setTimeout(it,500));Promise.all([L(),X]).finally(()=>{O(!1)})},[L,q]),Ft=i.useMemo(()=>v?B.find(X=>X.id===v)??R.find(X=>X.id===v)??I??im().find(X=>X.id===v)??null:null,[v,I,R,B]),_t=i.useRef(null),[hs,Zt]=i.useState(0);i.useEffect(()=>{if(!v){_t.current&&(_t.current=null,Zt(kt=>kt+1));return}if(Ft){_t.current={sessionId:v,session:Ft,expiresAt:Date.now()+2e3};return}const X=_t.current;if(!X||X.sessionId!==v)return;const it=X.expiresAt-Date.now();if(it<=0){_t.current=null,Zt(kt=>kt+1);return}const dt=window.setTimeout(()=>{_t.current?.sessionId===v&&(_t.current=null),Zt(kt=>kt+1)},it);return()=>{window.clearTimeout(dt)}},[v,Ft]);const ns=(()=>{if(Ft)return Ft;if(!v)return null;const X=_t.current;return X&&X.sessionId===v&&X.expiresAt>Date.now()?X.session:null})(),gs=ht(X=>v?X.worktreeMetadata.get(v)?.path??"":""),Mt=ht(X=>v?X.worktreeMetadata.get(v)?.branch?.trim()??null:null),Bt=om(X=>v?X.getAttachment(v):void 0),$t=i.useMemo(()=>Bt?$p(Bt,{pending:o("gitView.empty.worktreeSetupInProgress")}):null,[o,Bt]),os=i.useMemo(()=>Bt?Bt.legacy?"legacy":Bt.degraded?"degraded":Bt.worktreeStatus==="pending"?"pending":Bt.worktreeStatus==="missing"?"missing":Bt.worktreeStatus==="invalid"?"invalid":Bt.attentionReason?"attention":null:null,[Bt]),Gt=i.useMemo(()=>Mn(gs||""),[gs]),Me=i.useMemo(()=>{const X=typeof ns?.directory=="string"?ns.directory:"";return Mn(X||"")},[ns?.directory]),ft=ht(X=>X.newSessionDraft?.open?Mn(X.newSessionDraft.bootstrapPendingDirectory??X.newSessionDraft.directoryOverride??""):""),at=i.useMemo(()=>Gt||Me||ft,[ft,Me,Gt]),Nt=ht(X=>{const it=Mn(Gt||Me||"");if(!it)return null;for(const dt of X.availableWorktreesByProject.values()){const Wt=dt.find(fs=>Mn(fs.path)===it)?.branch?.trim();if(Wt)return Wt}return null}),es=zp(at||null)||Mt||Nt,xs=i.useMemo(()=>{if(!v)return W??"OpenChamber";const X=ns?.title?.trim();return X&&X.length>0?X:"Untitled Session"},[W,ns?.title,v]),Yt=i.useMemo(()=>Mn(at||D?.path||""),[D?.path,at]),Lt=i.useMemo(()=>D?{id:D.id,path:D.path}:null,[D]),Es=i.useRef(null);i.useEffect(()=>{!Lt||!Yt||(Es.current={projectRef:Lt,directory:Yt})},[Yt,Lt]);const ms=i.useMemo(()=>Lt&&Yt?{projectRef:Lt,directory:Yt}:Es.current,[Yt,Lt]),Ns=Cc(X=>X.planModeEnabled),Us=ht(X=>X.isSessionPlanAvailable),Ms=Ns&&v?Us(v):!1,Tn=Ms,Hs=i.useRef("");i.useEffect(()=>{if(!Ns){Ee.getState().activeMainTab==="plan"&&Ee.getState().setActiveMainTab("chat");return}if(!v)return;const X=`${v||"none"}:${Me||"none"}:${ns?.time?.created||0}:${ns?.slug||"none"}`;Hs.current!==X&&(Hs.current=X),!Ms&&Ee.getState().activeMainTab==="plan"&&Ee.getState().setActiveMainTab("chat")},[Ns,Ms,ns?.slug,ns?.time?.created,v,Me]);const xe=i.useCallback(async X=>{if(!(!X||de)){fe(!0);try{const it=N.github?await N.github.authActivate(X):await(async()=>{const dt=await Is("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:X})}),kt=await dt.json().catch(()=>null);if(!dt.ok||!kt)throw new Error(kt?.error||dt.statusText);return kt})();ne(it)}catch(it){console.error("Failed to switch GitHub account:",it)}finally{fe(!1)}}},[de,N.github,ne]),tt=i.useCallback(()=>{if(typeof document>"u")return;const X=document.activeElement;if(!X)return;const it=X.tagName;(it==="INPUT"||it==="TEXTAREA"||it==="SELECT"||X.isContentEditable)&&X.blur()},[]),ut=i.useCallback(()=>{if(oe){tt(),a(!T);return}c()},[tt,oe,T,a,c]),wt=i.useCallback(()=>{Zr("desktop_open_draft_mini_chat_window",{directory:Mn(at||D?.path||""),projectId:D?.id??null,apiBaseUrl:Xr(),clientToken:Ql()}).catch(X=>{console.warn("[header] failed to open draft mini chat window",X)})},[D?.id,D?.path,at]),zt=i.useCallback(()=>{if(_){wt();return}v&&Zr("desktop_open_session_mini_chat_window",{sessionId:v,directory:Mn(at||D?.path||""),apiBaseUrl:Xr(),clientToken:Ql()}).catch(X=>{console.warn("[header] failed to open session mini chat window",X)})},[D?.path,v,wt,_,at]),xt=i.useCallback(()=>{const X=Mn(at||"");if(!X)return;const it=w[X];if(di(it)==="context"){b(X);return}m(X)},[b,w,m,at]),ps=i.useMemo(()=>{const X=Mn(at||"");if(!X)return!1;const it=w[X];return di(it)==="context"},[w,at]),cs=i.useCallback(()=>{const X=Mn(at||"");if(!X)return;const it=w[X];if(di(it)==="plan"){b(X);return}u(X)},[b,w,u,at]),js=i.useCallback(()=>{const X=Mn(at||"");if(!X)return;const it=w[X];if(di(it)==="diff"){b(X);return}x(X,{mode:"diff",stagedDiff:!1})},[b,w,x,at]),Ss=i.useCallback(()=>{const X=Mn(at||"");if(!X)return;const it=w[X];if(di(it)==="browser"){b(X);return}p(X)},[b,w,p,at]),Fs=i.useMemo(()=>{const X=Mn(at||"");if(!X)return!1;const it=w[X];return di(it)==="plan"},[w,at]),Bn=i.useMemo(()=>{const X=Mn(at||"");if(!X)return!1;const it=w[X];return di(it)==="diff"},[w,at]),sn=i.useMemo(()=>{const X=Mn(at||"");if(!X)return!1;const it=w[X];return di(it)==="browser"},[w,at]),Kn=el,Pn=lw,vn=i.useMemo(()=>$?"services":n?"sessions":r?"git":g,[g,$,n,r]),Ks=i.useCallback(()=>{ke(!1),n&&t&&t(),r&&e&&e(),!t&&T&&a(!1)},[T,n,t,e,r,a]),jn=i.useCallback(()=>{n||ke(!1),t?.()},[n,t]),nn=i.useCallback(()=>{r||ke(!1),e?.()},[e,r]),Ge=i.useMemo(()=>he&&Ne&&!Y?"5.5rem":K?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!he||Be)&&!Ke?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[he,Y,Ne,K,Ke,Be]);nt.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",Ge)},[Ge]);const ds=l?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",ks=l?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";nt.useEffect(()=>{if(!he||!Ne){me(!1);return}let X=!1;const it=async()=>{try{const kt=await Zr("desktop_is_window_fullscreen");X||me(kt===!0)}catch{X||me(!1)}},dt=()=>{it()};return it(),window.addEventListener("openchamber:window-resized",dt),()=>{X=!0,window.removeEventListener("openchamber:window-resized",dt)}},[he,Ne]);const Os=i.useMemo(()=>!he||!Ne||Oe===null?"":Oe>=26?"h-12":Oe<=15?"h-14":"",[he,Ne,Oe]),qs=i.useMemo(()=>{if(!(he&&!Be||Ke))return{paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[he,Ke,Be]),$s=i.useCallback(()=>{if(typeof document>"u")return;const X=ye.current?.getBoundingClientRect().height;X&&document.documentElement.style.setProperty("--oc-header-height",`${X}px`)},[]);nt.useEffect(()=>{if(typeof window>"u")return;$s();const X=ye.current;if(!X||typeof ResizeObserver>"u")return()=>{};let it=0;const dt=()=>{it||(it=requestAnimationFrame(()=>{it=0,$s()}))},kt=new ResizeObserver(dt);return kt.observe(X),window.addEventListener("resize",dt),window.addEventListener("orientationchange",dt),()=>{it&&cancelAnimationFrame(it),kt.disconnect(),window.removeEventListener("resize",dt),window.removeEventListener("orientationchange",dt)}},[$s]),nt.useEffect(()=>{$s()},[$s,oe,Os]);const gn=i.useCallback(async X=>{const it=X.target;it.closest(".app-region-no-drag")||it.closest("button, a, input, select, textarea")||X.button===0&&he&&await yp()},[he]),Cs=i.useMemo(()=>{if(oe){const X=[{id:"chat",label:o("layout.mainTab.chat"),icon:"chat-4"}];return Tn&&X.push({id:"plan",label:o("layout.mainTab.plan"),icon:"file-text"}),X.push({id:"diff",label:o("layout.mainTab.diff"),icon:"diff"},{id:"files",label:o("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:o("layout.mainTab.terminal"),icon:"terminal-box"},{id:"context",label:o("layout.mainTab.context"),icon:"file-list-2"},{id:"diagram",label:o("layout.mainTab.diagram"),icon:"file"}),X}return[]},[oe,Tn,o]),qn=i.useCallback(X=>Ua(pi(X,k)),[k]);nt.useEffect(()=>{!oe&&(g==="git"||g==="terminal"||g==="diff"||g==="files"||g==="context")&&h("chat")},[g,oe,h]);const us=i.useMemo(()=>{const X=[];return he&&X.push({value:"instance",label:o("layout.services.instance"),icon:s.jsx(A,{name:"server",className:"h-3.5 w-3.5"})}),X.push({value:"usage",label:o("layout.services.usage"),icon:s.jsx(A,{name:"timer",className:"h-3.5 w-3.5"})},{value:"mcp",label:"MCP",icon:s.jsx(Xl,{className:"h-3.5 w-3.5"})}),X},[he,o]),Ls=i.useMemo(()=>us.map(X=>({id:X.value,label:X.label,icon:X.icon})),[us]),br=i.useMemo(()=>{if(typeof window>"u"||he||Ke)return!1;const X=window.location.hostname;return X==="localhost"||X==="127.0.0.1"||X==="::1"},[he,Ke]),Yn=i.useCallback(async()=>{if(C)return;y(!0),Se(!1);const X=[];let it=!1;try{try{for(const[,dt]of Ws.getState().sessions.entries())for(const kt of dt.tabs)kt.previewUrl&&X.push(kt.previewUrl)}catch{}try{await vp({})}catch{}try{(await Is("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:X})})).ok?it=!0:it=(await Is("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{it||y(!1)}},[C,Se]),un=i.useMemo(()=>[{value:"usage",label:o("header.services.used")},{value:"remaining",label:o("header.services.remaining")}],[o]),Ar=i.useMemo(()=>un.map(X=>({id:X.value,label:X.label})),[un]),ni=i.useMemo(()=>[{id:"usage",label:o("layout.services.usage"),icon:s.jsx(A,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(Xl,{className:"h-3.5 w-3.5"})}],[o]);nt.useEffect(()=>{const X=it=>{if(Ac(it)&&!it.shiftKey&&!it.altKey){const dt=parseInt(it.key,10);dt>=1&&dt<=Cs.length&&(it.preventDefault(),oe&&(tt(),Ks()),h(Cs[dt-1].id))}};return window.addEventListener("keydown",X),()=>window.removeEventListener("keydown",X)},[tt,Ks,oe,h,Cs]),nt.useEffect(()=>{const X=it=>{const dt=pi("toggle_services_menu",k);if(da(it,dt)){it.preventDefault(),Ve?Se(!1):(Se(!0),Je(),Kt==="usage"&&U.length===0&&L());return}const kt=pi("cycle_services_tab",k);if(da(it,kt)){it.preventDefault();const fs=us.map(xn=>xn.value);if(fs.length===0)return;const bs=fs.indexOf(Kt),zs=bs===-1?0:(bs+1)%fs.length,Ys=fs[zs];is(Ys),Se(!0),Je(),Ys==="usage"&&U.length===0&&L();return}const Wt=pi("toggle_context_plan",k);da(it,Wt)&&(it.preventDefault(),cs())};return window.addEventListener("keydown",X),()=>window.removeEventListener("keydown",X)},[k,Ve,Kt,us,U.length,L,Je,cs]);const ri=X=>{const it=g===X.id,dt=X.icon==="diff",kt=dt?null:X.icon,Wt=X.id==="chat",fs=zs=>dt?s.jsx(ou,{size:zs}):kt?s.jsx(A,{name:kt,className:`h-${zs/4} w-${zs/4}`}):null,bs=s.jsxs("button",{type:"button",onClick:()=>h(X.id),className:Pe("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",it?"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",Wt&&!oe&&"min-w-[100px] justify-center"),"aria-label":X.label,"aria-selected":it,role:"tab",children:[oe?fs(20):s.jsxs(s.Fragment,{children:[fs(16),s.jsx("span",{className:"header-tab-label",children:X.label})]}),X.badge!==void 0&&X.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:X.badge})]});return s.jsx(i.Fragment,{children:bs},X.id)},yi=Ke?null:s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.actions.toggleChangesPanelAria"),"aria-pressed":Bn,onClick:js,className:Kn,children:s.jsxs("span",{className:"relative h-5 w-5 overflow-hidden rounded-[2px]",children:[s.jsx("span",{className:"absolute left-[4px] top-[4px] h-3 w-[5px] bg-[var(--status-error)]/25"}),s.jsx("span",{className:"absolute right-[4px] top-[4px] h-3 w-[5px] bg-[var(--status-success)]/25"}),s.jsx(A,{name:"layout-column",className:"absolute inset-0 h-5 w-5"})]})})}),s.jsx(Tt,{children:s.jsx("p",{children:o("header.actions.toggleChangesPanel")})})]}),Dr=s.jsxs(s.Fragment,{children:[Tn&&s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.actions.openPlanAria"),onClick:cs,className:Pe(Kn,Fs&&"bg-[var(--interactive-hover)]"),children:s.jsx(A,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(Tt,{children:s.jsx("p",{children:o("header.actions.planWithShortcut",{shortcut:qn("toggle_context_plan")})})})]}),s.jsx(Eb,{directory:Yt,className:"mr-1"}),s.jsx(dw,{isDesktopApp:he,currentInstanceLabel:se,compactCurrentInstanceLabel:ts,currentInstanceIsLocal:ae,isDesktopServicesOpen:Ve,setIsDesktopServicesOpen:Se,refreshCurrentInstanceLabel:Je,desktopServicesTab:Kt,setDesktopServicesTab:is,quotaResultsLength:U.length,fetchAllQuotas:L,servicesTabItems:Ls,quotaLastUpdated:ee,quotaDisplayMode:ie,showPredValues:te,quotaDisplayTabItems:Ar,handleDisplayModeChange:ss,handleUsageRefresh:Xt,isQuotaLoading:M,isUsageRefreshSpinning:q,hasRateLimits:Ht,rateLimitGroups:Ct,expandedFamilies:et,toggleFamilyExpanded:Vt,shortcutLabel:qn,showDevShutdown:br,isDevShutdownInFlight:C,onDevShutdown:Yn,remoteUpdateInfo:st,remoteUpdateChecking:jt,remoteUpdateError:Rt,onOpenRemoteUpdate:Xe,timeFormatPreference:j}),s.jsx(Qo,{title:o("header.actions.terminalPanelWithShortcut",{shortcut:qn("toggle_terminal")}),ariaLabel:o("header.actions.toggleTerminalPanelAria"),onClick:d,Icon:"terminal-box"}),oe?null:s.jsx(Qo,{title:o("contextPanel.browser.open"),ariaLabel:o("contextPanel.browser.open"),onClick:Ss,pressed:sn,Icon:"global"}),s.jsx(Qo,{title:o("header.actions.rightSidebarWithShortcut",{shortcut:qn("toggle_right_sidebar")}),ariaLabel:o("header.actions.toggleRightSidebarAria"),onClick:f,Icon:"layout-right"}),s.jsx(cw,{isMobile:oe,githubAuthStatus:ve,githubAccounts:E,githubAvatarUrl:V,githubLogin:we,isSwitchingGitHubAccount:de,handleGitHubAccountSwitch:xe})]}),ys=z&&(_||!!v),rn=()=>s.jsxs("div",{onMouseDown:gn,className:Pe("app-region-drag relative flex h-12 select-none items-center pr-3",Os),style:qs,role:"tablist","aria-label":o("header.navigation.mainAria"),children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:ds}}),s.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:ks}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[s.jsx(Nb,{children:s.jsxs("button",{type:"button","aria-label":o("sessions.switcher.openAria"),className:"app-region-no-drag mr-3 flex min-w-0 flex-col items-start rounded-md px-1 py-0.5 -my-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:_?o("sessions.switcher.draftTitle"):xs}),W||es||!_&&os?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[W?s.jsx("span",{className:"truncate",children:W}):null,es?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:es})]}):null,!_&&os?s.jsxs("span",{className:Pe("inline-flex min-w-0 items-center gap-0.5",os==="attention"||os==="invalid"||os==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(A,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:$t})]}):null]}):null]})}),Cs.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Cs.map(X=>ri(X))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[rt&&be?s.jsx(kb,{totalTokens:be.totalTokens,percentage:vt,colorPercentage:be.percentage,contextLimit:be.contextLimit,outputLimit:be.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:xt,pressed:ps,className:ys?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,yi,s.jsx(Qo,{visible:ys,title:o(_?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:o(_?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:zt,className:Pe(Kn,"mr-1"),Icon:"picture-in-picture-2"}),Dr,s.jsx(_m,{visible:Be&&_e==="right",position:"right"})]})]})]}),rr=()=>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:jn,className:Pe(Pn,vn==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":o(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(A,{name:"layout-left",className:"h-5 w-5"})}):T?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":o("header.actions.backAria"),children:s.jsx(A,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:ut,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":o("header.actions.openSessionsAria"),children:s.jsx(A,{name:"play-list-add",className:"h-5 w-5"})}),!t&&T&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:o("header.sessions.title")})]}),(!T||!!t)&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":o("header.navigation.mainAria"),children:Cs.map(X=>{const it=g===X.id,dt=X.icon==="diff",kt=dt?null:X.icon;return s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{oe&&(tt(),Ks()),h(X.id)},"aria-label":X.label,"aria-selected":it,role:"tab",className:Pe(Pn,"relative rounded-lg",vn===X.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[dt?s.jsx(ou,{className:"h-5 w-5"}):kt?s.jsx(A,{name:kt,className:"h-5 w-5"}):null,X.badge!==void 0&&X.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:X.badge}),X.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":o("header.changes.availableAria")})]})}),s.jsx(Tt,{children:s.jsx("p",{children:X.label})})]},X.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[ms&&s.jsx(Um,{projectRef:ms.projectRef,directory:ms.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(en,{open:$,onOpenChange:X=>{X&&(n&&t&&t(),r&&e&&e()),ke(X),X&&U.length===0&&L()},children:[s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.services.viewAria"),className:Pe(Pn,vn==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(A,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(Tt,{children:s.jsx("p",{children:o("header.services.title")})})]}),s.jsx(Zs,{align:"end",sideOffset:0,positionerClassName:"!fixed !bottom-0 !left-0 !right-0 !top-[var(--oc-header-height,56px)] !transform-none",className:"h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(Vo,{items:ni,activeId:qt,onSelect:X=>{const it=X;Te(it),it==="usage"&&U.length===0&&L()},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:()=>ke(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":o("header.services.closeAria"),children:s.jsx(A,{name:"close",className:"h-5 w-5"})})]})}),qt==="mcp"&&s.jsx(Pm,{active:$&&qt==="mcp"}),qt==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:o("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Hm(ee,j)})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"flex items-center h-6",children:[s.jsx("button",{type:"button",onClick:()=>ss("usage"),className:Pe("typography-ui-label px-1 pb-0.5 transition-colors",ie==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>ss("remaining"),className:Pe("typography-ui-label px-1 pb-0.5 transition-colors",ie==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.remaining")})]}),s.jsx("button",{type:"button",className:Pe("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:Xt,disabled:M||q,"aria-label":o("header.services.refreshRateLimitsAria"),children:s.jsx(A,{name:"refresh",className:Pe("h-4 w-4",q&&"animate-spin")})})]})]})}),!Ht&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:o("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:Ct.map((X,it)=>s.jsxs(i.Fragment,{children:[it>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(Lo,{providerId:X.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:X.providerName})]}),X.entries.length===0&&(!X.modelFamilies||X.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:X.error??o("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[X.entries.map(([dt,kt])=>{const Wt=ie==="remaining"?kt.remainingPercent:kt.usedPercent,fs=Da(kt.usedPercent,kt.resetAt,kt.windowSeconds,dt),bs=fs?.dailyAllocationPercent!=null?ie==="remaining"?100-hi(fs.elapsedRatio):hi(fs.elapsedRatio):null,zs=Bo(kt.valueLabel,Wt),Ys=tm(kt.resetAt,kt.resetAfterFormatted??kt.resetAtFormatted,j);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Nc(dt)}),Ys?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Ys}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:zs==="-"?"":zs})]}),s.jsx(Ra,{percent:Wt,tonePercent:kt.usedPercent,className:"h-1.5",expectedMarkerPercent:bs}),fs&&te?s.jsx(Ea,{paceInfo:fs,compact:!0}):null]},`${X.providerId}-${dt}`)}),X.modelFamilies&&X.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:X.modelFamilies.map(dt=>{const Wt=(et[X.providerId]??[]).includes(dt.familyId??"other");return s.jsxs(lo,{open:Wt,onOpenChange:()=>Vt(X.providerId,dt.familyId??"other"),children:[s.jsxs(Ho,{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:dt.familyLabel}),Wt?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(co,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:dt.models.map(([fs,bs])=>{const zs=ie==="remaining"?bs.remainingPercent:bs.usedPercent,Ys=Da(bs.usedPercent,bs.resetAt,bs.windowSeconds),xn=Ys?.dailyAllocationPercent!=null?ie==="remaining"?100-hi(Ys.elapsedRatio):hi(Ys.elapsedRatio):null,fr=Bo(bs.valueLabel,zs);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:Tm(fs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:fr==="-"?"":fr})]}),s.jsx(Ra,{percent:zs,tonePercent:bs.usedPercent,className:"h-1.5",expectedMarkerPercent:xn}),Ys&&te?s.jsx(Ea,{paceInfo:Ys,compact:!0}):null]},`${X.providerId}-${fs}`)})})})]},dt.familyId??"other")})})]})]},X.providerId))})]})]})})]}),e?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:nn,className:Pe(Pn,"relative",vn==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(A,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(Tt,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Sn=Pe("header-safe-area relative z-10 bg-background",oe&&"border-b border-border/50");return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:ye,className:Sn,style:{"--padding-scale":"1"},children:oe?rr():rn()}),s.jsx(Rm,{open:Ye,onOpenChange:Qe,info:st,downloading:!1,downloaded:!1,progress:null,error:Rt,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function mw(){}const uu=180,fu=640,hw=110,pw=t=>{const e=gt.c(44),{isOpen:n,isMobile:r,children:o}=t,{t:a}=yt(),c=Ee(gw),l=Ee(xw),d=Ee(bw),f=Ee(ww),[m,u]=i.useState(null),[p,x]=i.useState(!1),b=i.useRef(null),w=i.useRef(0),g=i.useRef(c||300),h=Math.min(fu,Math.max(uu,c||300));let k,j;e[0]!==n?(k=()=>{n||(u(null),x(!1))},j=[n],e[0]=n,e[1]=k,e[2]=j):(k=e[1],j=e[2]),i.useEffect(k,j);let S,N;e[3]!==l||e[4]!==r||e[5]!==n?(S=()=>{if(r||!n||!l)return;const J=()=>{const ve=b.current?.parentElement?.getBoundingClientRect().height;if(!ve||ve<=0)return;const ne=Math.max(0,Math.round(ve));u(ye=>ye===ne?ye:ne)};J();const re=b.current?.parentElement;if(!re)return;const oe=new ResizeObserver(J);return oe.observe(re),()=>{oe.disconnect()}},N=[l,r,n],e[3]=l,e[4]=r,e[5]=n,e[6]=S,e[7]=N):(S=e[6],N=e[7]),i.useEffect(S,N);let C,y;if(e[8]!==l||e[9]!==r||e[10]!==p||e[11]!==d||e[12]!==f?(C=()=>{if(r||!p||l)return;const J=oe=>{const ve=w.current-oe.clientY,ne=Math.min(fu,Math.max(uu,g.current+ve));d(ne)},re=()=>{x(!1),Ee.getState().bottomTerminalHeight<=hw&&f(!1)};return window.addEventListener("pointermove",J),window.addEventListener("pointerup",re,{once:!0}),()=>{window.removeEventListener("pointermove",J),window.removeEventListener("pointerup",re)}},y=[l,r,p,d,f],e[8]=l,e[9]=r,e[10]=p,e[11]=d,e[12]=f,e[13]=C,e[14]=y):(C=e[13],y=e[14]),i.useEffect(C,y),r)return null;const P=n?l?Math.max(0,m??h):h:0,_=n&&l;let v;e[15]!==P||e[16]!==l||e[17]!==n?(v=J=>{!n||l||(x(!0),w.current=J.clientY,g.current=P,J.preventDefault())},e[15]=P,e[16]=l,e[17]=n,e[18]=v):v=e[18];const F=v,I=_?"absolute inset-x-0 bottom-0 z-40":"relative",R=p?"transition-none":"transition-[height] duration-300 ease-in-out",B=(!n||_)&&"border-t-0";let D;e[19]!==B||e[20]!==I||e[21]!==R?(D=Pe("flex overflow-hidden border-t border-border bg-sidebar",I,R,B),e[19]=B,e[20]=I,e[21]=R,e[22]=D):D=e[22];let W;e[23]!==P||e[24]!==_?(W=_?{top:0}:{height:`${P}px`,minHeight:`${P}px`,maxHeight:`${P}px`},e[23]=P,e[24]=_,e[25]=W):W=e[25];const U=!n||!l&&P===0;let L;e[26]!==F||e[27]!==l||e[28]!==n||e[29]!==p||e[30]!==a?(L=n&&!l&&s.jsx("div",{className:Pe("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",p&&"bg-[var(--interactive-border)]"),onPointerDown:F,role:"separator","aria-orientation":"horizontal","aria-label":a("terminalView.bottomDock.resizeAria")}),e[26]=F,e[27]=l,e[28]=n,e[29]=p,e[30]=a,e[31]=L):L=e[31];const M=!n&&"pointer-events-none select-none opacity-0";let ee;e[32]!==M?(ee=Pe("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",M),e[32]=M,e[33]=ee):ee=e[33];const ie=!n;let te;e[34]!==o||e[35]!==ee||e[36]!==ie?(te=s.jsx("div",{className:ee,"aria-hidden":ie,children:o}),e[34]=o,e[35]=ee,e[36]=ie,e[37]=te):te=e[37];let H;return e[38]!==D||e[39]!==W||e[40]!==U||e[41]!==L||e[42]!==te?(H=s.jsxs("section",{ref:b,className:D,style:W,"aria-hidden":U,children:[L,te]}),e[38]=D,e[39]=W,e[40]=U,e[41]=L,e[42]=te,e[43]=H):H=e[43],H};function gw(t){return t.bottomTerminalHeight}function xw(t){return t.isBottomTerminalExpanded}function bw(t){return t.setBottomTerminalHeight}function ww(t){return t.setBottomTerminalOpen}const mu=280,hu=280,pu=500,yw=({isOpen:t,isMobile:e,children:n,className:r,topBar:o})=>{const{t:a}=yt(),c=Ee(y=>y.sidebarWidth),l=Ee(y=>y.setSidebarWidth),[d,f]=i.useState(!1),m=i.useRef(0),u=i.useRef(c||mu),p=i.useRef(null),x=i.useRef(null),b=i.useRef(null),w=i.useCallback(y=>Math.min(pu,Math.max(hu,y)),[]),g=i.useCallback(y=>{const P=b.current;P&&(P.style.width=`${y}px`,P.style.minWidth=`${y}px`,P.style.maxWidth=`${y}px`,P.style.setProperty("--oc-left-sidebar-width",`${y}px`))},[]);if(i.useEffect(()=>{e&&d&&f(!1)},[e,d]),i.useEffect(()=>{d||(p.current=null,x.current=null)},[d]),e)return null;const h=Math.min(pu,Math.max(hu,c||mu)),k=t?h:0,j=y=>{if(t){try{y.currentTarget.setPointerCapture(y.pointerId)}catch{}x.current=y.pointerId,f(!0),m.current=y.clientX,u.current=k,p.current=k,g(k),y.preventDefault()}},S=y=>{if(e||!d||x.current!==y.pointerId)return;const P=y.clientX-m.current,_=w(u.current+P);p.current!==_&&(p.current=_,g(_))},N=y=>{if(x.current!==y.pointerId||e)return;try{y.currentTarget.releasePointerCapture(y.pointerId)}catch{}const P=w(p.current??k);x.current=null,p.current=null,f(!1),l(P)},C=d?p.current??k:k;return s.jsxs("aside",{ref:b,className:Pe("relative flex h-full overflow-hidden border-r border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar oc-vibrancy-surface",!t&&"border-r-0",r),style:{width:`${C}px`,minWidth:`${C}px`,maxWidth:`${C}px`,"--oc-left-sidebar-width":`${d?C:h}px`,overflowX:"clip",transitionProperty:d?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||k===0,children:[t&&s.jsx("div",{className:Pe("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",d&&"bg-[var(--interactive-border)]"),onPointerDown:j,onPointerMove:S,onPointerUp:N,onPointerCancel:N,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsxs("div",{className:Pe("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",d&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[o,s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx(an,{children:n})})]})]})},vw=()=>{const t=gt.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={height:"var(--oc-header-height, 3rem)"},t[0]=e):e=t[0];let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("div",{className:"app-region-drag shrink-0",style:{width:"var(--oc-titlebar-left-inset, 0.75rem)"}}),t[1]=n):n=t[1];let r;return t[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs("div",{"aria-hidden":!0,className:"flex shrink-0",style:e,children:[n,s.jsx("div",{className:"app-region-no-drag shrink-0",style:{width:"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)"}}),s.jsx("div",{className:"app-region-drag flex-1"})]}),t[2]=r):r=t[2],r},Jo=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function jw(){const t=Ds(u=>u.activeProjectId?u.projects.find(p=>p.id===u.activeProjectId)??null:null),e=ht(u=>u.currentSessionId),n=nm(e??null),r=ht(u=>e?u.worktreeMetadata.get(e)?.path??"":""),o=ht(u=>u.newSessionDraft?.open?Jo(u.newSessionDraft.bootstrapPendingDirectory??u.newSessionDraft.directoryOverride??""):""),a=i.useMemo(()=>Jo(r||""),[r]),c=i.useMemo(()=>{const u=typeof n?.directory=="string"?n.directory:"";return Jo(u||"")},[n?.directory]),l=a||c||o,d=i.useMemo(()=>Jo(l||t?.path||""),[t?.path,l]),f=i.useMemo(()=>t?{id:t.id,path:t.path}:null,[t]),m=i.useRef(null);return i.useEffect(()=>{f&&d&&(m.current={projectRef:f,directory:d})},[d,f]),i.useMemo(()=>f&&d?{projectRef:f,directory:d}:m.current,[f,d])}const gu="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover transition-colors",Sw=()=>{const t=gt.c(36),{t:e}=yt(),n=Ee(Nw),r=Ee(kw),o=Ee(Cw),a=jw(),c=i.useRef(null),l=Ua(pi("toggle_sidebar",o)),{usesFramelessChrome:d,side:f}=Vm(),m=Dw;let u,p;t[0]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{if(typeof document>"u")return;const D=c.current;if(!D)return;const W=()=>{const L=D.getBoundingClientRect().width;document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(L)}px`)};if(W(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(W);return U.observe(D),()=>{U.disconnect()}},p=[],t[0]=u,t[1]=p):(u=t[0],p=t[1]),i.useEffect(u,p);const x="app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2";let b;t[2]===Symbol.for("react.memo_cache_sentinel")?(b={height:"var(--oc-header-height, 3rem)",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},t[2]=b):b=t[2];const w="flex items-center gap-2";let g;t[3]!==d||t[4]!==f?(g=d&&f==="left"?s.jsx(_m,{visible:!0,position:"left"}):null,t[3]=d,t[4]=f,t[5]=g):g=t[5];let h;t[6]!==e||t[7]!==d?(h=d?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,"aria-label":e("header.actions.openAppMenuAria"),className:Pe(gu,"shrink-0"),children:s.jsx(A,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(Tt,{children:s.jsx("p",{children:e("header.actions.openAppMenu")})})]}):null,t[6]=e,t[7]=d,t[8]=h):h=t[8];const k=At;let j;t[9]!==e?(j=e("header.actions.openSessionsAria"),t[9]=e,t[10]=j):j=t[10];let S,N;t[11]===Symbol.for("react.memo_cache_sentinel")?(S=Pe(gu,"shrink-0"),N=s.jsx(A,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[11]=S,t[12]=N):(S=t[11],N=t[12]);let C;t[13]!==j||t[14]!==n?(C=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":j,className:S,children:N})}),t[13]=j,t[14]=n,t[15]=C):C=t[15];const y=Tt,P=e("header.actions.openSessionsWithShortcut",{shortcut:l});let _;t[16]!==P?(_=s.jsx("p",{children:P}),t[16]=P,t[17]=_):_=t[17];let v;t[18]!==y||t[19]!==_?(v=s.jsx(y,{children:_}),t[18]=y,t[19]=_,t[20]=v):v=t[20];let F;t[21]!==k||t[22]!==C||t[23]!==v?(F=s.jsxs(k,{children:[C,v]}),t[21]=k,t[22]=C,t[23]=v,t[24]=F):F=t[24];let I;t[25]!==r||t[26]!==a?(I=a?s.jsx(Um,{projectRef:a.projectRef,directory:a.directory,className:r?"oc-vibrancy-pill":void 0}):null,t[25]=r,t[26]=a,t[27]=I):I=t[27];let R;t[28]!==F||t[29]!==I||t[30]!==g||t[31]!==h?(R=s.jsxs("div",{ref:c,className:w,children:[g,h,F,I]}),t[28]=F,t[29]=I,t[30]=g,t[31]=h,t[32]=R):R=t[32];let B;return t[33]!==R||t[34]!==b?(B=s.jsx("div",{className:x,style:b,children:R}),t[33]=R,t[34]=b,t[35]=B):B=t[35],B};function Nw(t){return t.toggleSidebar}function kw(t){return t.isSidebarOpen}function Cw(t){return t.shortcutOverrides}function Aw(t){console.warn("[titlebar] failed to open app menu",t)}function Dw(t){const e=t.currentTarget.getBoundingClientRect();Zr("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(Aw)}const xu=420,Tw=({isOpen:t,children:e,className:n})=>{const{t:r}=yt(),o=Ee(N=>N.rightSidebarWidth),a=Ee(N=>N.setRightSidebarWidth),[c,l]=i.useState(!1),d=i.useRef(0),f=i.useRef(o||xu),m=i.useRef(null),u=i.useRef(null),p=i.useRef(null),x=i.useCallback(N=>Math.min(Ad,Math.max(Dd,N)),[]),b=i.useCallback(N=>{const C=p.current;C&&(C.style.width=`${N}px`,C.style.minWidth=`${N}px`,C.style.maxWidth=`${N}px`,C.style.setProperty("--oc-right-sidebar-width",`${N}px`))},[]),w=Math.min(Ad,Math.max(Dd,o||xu)),g=t?w:0;i.useLayoutEffect(()=>{if(c)return;const N=p.current;N&&(N.style.minWidth="",N.style.maxWidth="")},[t,c,w]);const h=N=>{if(t){try{N.currentTarget.setPointerCapture(N.pointerId)}catch{}u.current=N.pointerId,l(!0),d.current=N.clientX,f.current=g,m.current=g,b(g),N.preventDefault()}},k=N=>{if(!c||u.current!==N.pointerId)return;const C=d.current-N.clientX,y=x(f.current+C);m.current!==y&&(m.current=y,b(y))},j=N=>{if(u.current!==N.pointerId)return;try{N.currentTarget.releasePointerCapture(N.pointerId)}catch{}const C=x(m.current??g);u.current=null,m.current=null,l(!1),a(C)},S=c?m.current??g:g;return s.jsxs("aside",{ref:p,className:Pe("relative flex h-full overflow-hidden border-l border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-l-0",n),style:{width:`${S}px`,"--oc-right-sidebar-width":`${c?S:w}px`,overflowX:"clip",transitionProperty:c?"none":"width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||g===0,children:[t&&s.jsx("div",{className:Pe("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",c&&"bg-[var(--interactive-border)]"),onPointerDown:h,onPointerMove:k,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":r("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:Pe("relative z-10 flex h-full min-h-0 shrink-0 flex-col pt-2 transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",c&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-right-sidebar-width)"},"aria-hidden":!t,children:t?e:null})]})},bu=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent});function Gm(t){const e=gt.c(131),{t:n}=yt(),{open:r,onOpenChange:o,target:a,projectDirectory:c,submitting:l,allowRunAsGoal:d,onConfirm:f}=t,m=l===void 0?!1:l,u=d===void 0?!1:d;let p;e[0]!==u?(p=u&&!Cr(),e[0]=u,e[1]=p):p=e[1];const x=p,b=rs(_w),w=rs(Vw),g=Wp(Bw),h=rs(Lw),k=rs(Ow),j=rs(Fw),S=rs(Mw),N=rs(Ew);let C;e[2]!==N||e[3]!==j||e[4]!==k||e[5]!==S?(C=()=>bu({providerID:k,modelID:j,variant:S,agent:N}),e[2]=N,e[3]=j,e[4]=k,e[5]=S,e[6]=C):C=e[6];const[y,P]=i.useState(C);let _,v;e[7]!==g||e[8]!==w||e[9]!==b||e[10]!==r||e[11]!==c?(_=()=>{r&&(b({directory:c,source:"todoSendDialog"}),w({directory:c}),g())},v=[r,b,w,g,c],e[7]=g,e[8]=w,e[9]=b,e[10]=r,e[11]=c,e[12]=_,e[13]=v):(_=e[12],v=e[13]),i.useEffect(_,v);let F,I;e[14]!==N||e[15]!==j||e[16]!==k||e[17]!==S||e[18]!==r?(F=()=>{r&&P(bu({providerID:k,modelID:j,variant:S,agent:N}))},I=[r,k,j,S,N],e[14]=N,e[15]=j,e[16]=k,e[17]=S,e[18]=r,e[19]=F,e[20]=I):(F=e[19],I=e[20]),i.useEffect(F,I);let R,B;e[21]!==y.modelID||e[22]!==y.providerID||e[23]!==r||e[24]!==h?(R=()=>{if(!r||h.length===0)return;const ae=h.find(st=>st.id===y.providerID)??h[0],We=Array.isArray(ae?.models)?ae.models:[],Ye=We.some(st=>st.id===y.modelID),Qe=We[0]?.id??"";ae?.id===y.providerID&&Ye||P(st=>({...st,providerID:ae?.id??"",modelID:Ye?st.modelID:Qe,variant:""}))},B=[r,h,y.providerID,y.modelID],e[21]=y.modelID,e[22]=y.providerID,e[23]=r,e[24]=h,e[25]=R,e[26]=B):(R=e[25],B=e[26]),i.useEffect(R,B);const D=Rw;let W;if(e[27]!==y.modelID||e[28]!==y.providerID||e[29]!==h){let ae;e[31]!==y.providerID?(ae=Ye=>Ye.id===y.providerID,e[31]=y.providerID,e[32]=ae):ae=e[32],W=h.find(ae)?.models?.find(Ye=>Ye.id===y.modelID),e[27]=y.modelID,e[28]=y.providerID,e[29]=h,e[30]=W}else W=e[30];const U=W;let L;e[33]!==U?(L=U?.variants?Object.keys(U.variants):[],e[33]=U,e[34]=L):L=e[34];const M=L,ee=M.length>0;let ie,te;e[35]!==y.variant||e[36]!==ee?(ie=()=>{ee||!y.variant||P(Iw)},te=[ee,y.variant],e[35]=y.variant,e[36]=ee,e[37]=ie,e[38]=te):(ie=e[37],te=e[38]),i.useEffect(ie,te);let H;e[39]!==y.modelID||e[40]!==y.providerID?(H=y.providerID.trim().length>0&&y.modelID.trim().length>0,e[39]=y.modelID,e[40]=y.providerID,e[41]=H):H=e[41];const J=H;let re;e[42]!==J||e[43]!==y||e[44]!==f||e[45]!==m?(re=()=>{!J||m||f(y)},e[42]=J,e[43]=y,e[44]=f,e[45]=m,e[46]=re):re=e[46];const oe=re;let ve,ne;e[47]!==oe||e[48]!==r?(ve=()=>{if(!r)return;const ae=We=>{(We.metaKey||We.ctrlKey)&&We.key==="Enter"&&(We.preventDefault(),oe())};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},ne=[r,oe],e[47]=oe,e[48]=r,e[49]=ve,e[50]=ne):(ve=e[49],ne=e[50]),i.useEffect(ve,ne);let ye;e[51]!==n||e[52]!==a?(ye=n(a==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[51]=n,e[52]=a,e[53]=ye):ye=e[53];const he=ye;let Fe;e[54]!==o||e[55]!==m?(Fe=ae=>{m||o(ae)},e[54]=o,e[55]=m,e[56]=Fe):Fe=e[56];let z;e[57]!==he?(z=s.jsx(tn,{children:s.jsx(Gs,{children:he})}),e[57]=he,e[58]=z):z=e[58];let K;e[59]!==n?(K=n("chat.modelControls.model"),e[59]=n,e[60]=K):K=e[60];let Y;e[61]!==K?(Y=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:K}),e[61]=K,e[62]=Y):Y=e[62];let me;e[63]===Symbol.for("react.memo_cache_sentinel")?(me=(ae,We)=>{P(Ye=>({...Ye,providerID:ae,modelID:We,variant:""}))},e[63]=me):me=e[63];let Ne;e[64]!==y.modelID||e[65]!==y.providerID?(Ne=s.jsx(am,{providerId:y.providerID,modelId:y.modelID,className:"max-w-[320px] justify-between",dropdownPortalToBody:!0,onChange:me}),e[64]=y.modelID,e[65]=y.providerID,e[66]=Ne):Ne=e[66];let Be;e[67]!==Y||e[68]!==Ne?(Be=s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[Y,Ne]}),e[67]=Y,e[68]=Ne,e[69]=Be):Be=e[69];let _e;e[70]!==n?(_e=n("sessions.scheduledTasks.editor.thinkingLevel.label"),e[70]=n,e[71]=_e):_e=e[71];let Oe;e[72]!==_e?(Oe=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:_e}),e[72]=_e,e[73]=Oe):Oe=e[73];const pe=!ee;let Re;e[74]===Symbol.for("react.memo_cache_sentinel")?(Re=ae=>P(We=>({...We,variant:ae})),e[74]=Re):Re=e[74];let ge;e[75]!==y.variant||e[76]!==pe||e[77]!==M?(ge=s.jsx(Up,{value:y.variant,options:M,disabled:pe,onChange:Re}),e[75]=y.variant,e[76]=pe,e[77]=M,e[78]=ge):ge=e[78];let ce;e[79]!==Oe||e[80]!==ge?(ce=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[Oe,ge]}),e[79]=Oe,e[80]=ge,e[81]=ce):ce=e[81];let Ce;e[82]!==n?(Ce=n("sessions.scheduledTasks.editor.agent.label"),e[82]=n,e[83]=Ce):Ce=e[83];let be;e[84]!==Ce?(be=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:Ce}),e[84]=Ce,e[85]=be):be=e[85];let ue;e[86]===Symbol.for("react.memo_cache_sentinel")?(ue=ae=>P(We=>({...We,agent:ae})),e[86]=ue):ue=e[86];let De;e[87]!==y.agent?(De=s.jsx(lm,{agentName:y.agent,filter:D,dropdownPortalToBody:!0,onChange:ue}),e[87]=y.agent,e[88]=De):De=e[88];let T;e[89]!==be||e[90]!==De?(T=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[be,De]}),e[89]=be,e[90]=De,e[91]=T):T=e[91];let V;e[92]!==Be||e[93]!==ce||e[94]!==T?(V=s.jsxs("div",{className:"flex flex-col gap-4",children:[Be,ce,T]}),e[92]=Be,e[93]=ce,e[94]=T,e[95]=V):V=e[95];const we=`flex items-center gap-3 ${x?"justify-between":"justify-end"}`;let E;e[96]!==y.runAsGoal||e[97]!==x||e[98]!==m||e[99]!==n?(E=x?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(Vr,{checked:y.runAsGoal===!0,onChange:ae=>P(We=>({...We,runAsGoal:ae})),disabled:m,ariaLabel:n("sessions.scheduledTasks.editor.goal.aria")}),s.jsx("button",{type:"button",className:"truncate typography-ui-label text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:m,onClick:()=>P(Pw),children:n("sessions.scheduledTasks.editor.goal.label")})]}):null,e[96]=y.runAsGoal,e[97]=x,e[98]=m,e[99]=n,e[100]=E):E=e[100];let de;e[101]!==o?(de=()=>o(!1),e[101]=o,e[102]=de):de=e[102];let fe;e[103]!==n?(fe=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[103]=n,e[104]=fe):fe=e[104];let $;e[105]!==m||e[106]!==de||e[107]!==fe?($=s.jsx(ze,{variant:"ghost",size:"sm",onClick:de,disabled:m,children:fe}),e[105]=m,e[106]=de,e[107]=fe,e[108]=$):$=e[108];const ke=!J||m;let Ve;e[109]!==m||e[110]!==n?(Ve=n(m?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[109]=m,e[110]=n,e[111]=Ve):Ve=e[111];let Se;e[112]!==oe||e[113]!==ke||e[114]!==Ve?(Se=s.jsx(ze,{size:"sm",onClick:oe,disabled:ke,children:Ve}),e[112]=oe,e[113]=ke,e[114]=Ve,e[115]=Se):Se=e[115];let q;e[116]!==$||e[117]!==Se?(q=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[$,Se]}),e[116]=$,e[117]=Se,e[118]=q):q=e[118];let O;e[119]!==we||e[120]!==E||e[121]!==q?(O=s.jsxs("div",{className:we,children:[E,q]}),e[119]=we,e[120]=E,e[121]=q,e[122]=O):O=e[122];let se;e[123]!==z||e[124]!==V||e[125]!==O?(se=s.jsxs(Vs,{className:"max-w-md overflow-visible",children:[z,V,O]}),e[123]=z,e[124]=V,e[125]=O,e[126]=se):se=e[126];let Le;return e[127]!==r||e[128]!==Fe||e[129]!==se?(Le=s.jsx(_s,{open:r,onOpenChange:Fe,children:se}),e[127]=r,e[128]=Fe,e[129]=se,e[130]=Le):Le=e[130],Le}function Pw(t){return{...t,runAsGoal:t.runAsGoal!==!0}}function Iw(t){return{...t,variant:""}}function Rw(t){return Dc(t.mode)}function Ew(t){return t.currentAgentName||""}function Mw(t){return t.currentVariant||""}function Fw(t){return t.currentModelId}function Ow(t){return t.currentProviderId}function Lw(t){return t.providers}function Bw(t){return t.loadAgents}function Vw(t){return t.loadAgents}function _w(t){return t.loadProviders}const ic=5,Km=15,Xo=new Map,ma=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},$w=(t,e)=>{const n=ma(e);return Math.max(n*ic,Math.min(n*Km,n*t))},zw=async(t,e)=>{const n=await qp(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},Ww=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,wu=t=>[...t.filter(e=>!e.completed),...t.filter(e=>e.completed)],yu=(t,e)=>{const n=t.findIndex(r=>r.completed);return n===-1?[...t,e]:[...t.slice(0,n),e,...t.slice(n)]},Uw=t=>{const e=gt.c(20),{id:n,children:r}=t;let o;e[0]!==n?(o={id:n},e[0]=n,e[1]=o):o=e[1];const{attributes:a,listeners:c,setNodeRef:l,setActivatorNodeRef:d,transform:f,transition:m,isDragging:u}=bc(o);let p;e[2]!==f?(p=wc.Transform.toString(f),e[2]=f,e[3]=p):p=e[3];let x;e[4]!==p||e[5]!==m?(x={transform:p,transition:m},e[4]=p,e[5]=m,e[6]=x):x=e[6];const b=u&&"opacity-60";let w;e[7]!==b?(w=Pe(b),e[7]=b,e[8]=w):w=e[8];let g;e[9]!==a||e[10]!==r||e[11]!==u||e[12]!==c||e[13]!==d?(g=r({attributes:a,listeners:c,setActivatorNodeRef:d,isDragging:u}),e[9]=a,e[10]=r,e[11]=u,e[12]=c,e[13]=d,e[14]=g):g=e[14];let h;return e[15]!==l||e[16]!==x||e[17]!==w||e[18]!==g?(h=s.jsx("li",{ref:l,style:x,className:w,children:g}),e[15]=l,e[16]=x,e[17]=w,e[18]=g,e[19]=h):h=e[19],h},Hw=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:o})=>{const{t:a}=yt(),[c,l]=i.useState(!1),[d,f]=i.useState(""),[m,u]=i.useState([]),[p,x]=i.useState(""),[b,w]=i.useState(null),[g,h]=i.useState(()=>new Set),[k,j]=i.useState([]),[S,N]=i.useState(null),[C,y]=i.useState(!1),[P,_]=i.useState(0),v=i.useRef(!1),F=i.useRef(""),I=i.useRef(null),R=Ee(O=>O.todoPanelHeight),B=Ee(O=>O.setTodoPanelHeight),D=Ee(O=>O.notesPanelHeight),W=Ee(O=>O.setNotesPanelHeight),[U,L]=i.useState(!1),M=i.useRef(0),ee=i.useRef(R),ie=ht(O=>O.currentSessionId),te=ht(O=>O.createSession),H=ht(O=>O.initializeNewOpenChamberSession),J=ht(O=>O.sendMessage),re=ht(O=>O.setCurrentSession),oe=xi(O=>O.setPendingInputText),ve=Js(O=>O.currentDirectory),ne=Ee(O=>O.openContextPanelTab),ye=Ee(O=>O.setActiveMainTab),he=Ee(O=>O.setSessionSwitcherOpen),Fe=Ee(O=>O.padding),z=i.useCallback(async(O,se)=>{if(!t)return!1;const Le=t.id,We=(Xo.get(Le)??Promise.resolve()).catch(()=>{}).then(()=>Hp(t,{notes:O,todos:se}));Xo.set(Le,We);try{const Ye=await We;return Ye||le.error(a("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),Ye}finally{Xo.get(Le)===We&&Xo.delete(Le)}},[t,a]);i.useEffect(()=>{if(!t){f(""),u([]),j([]),x(""),h(new Set);return}let O=!1;return l(!0),(async()=>{try{const se=await Gp(t),Le=await Promise.all(se.plans.map(ae=>zw(ae,a("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(O)return;f(se.notes),u(wu(se.todos)),j(Le),F.current=se.notes,v.current=!0,x(""),h(new Set)}catch{O||(le.error(a("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),f(""),u([]),j([]),F.current="",v.current=!0)}finally{O||l(!1)}})(),()=>{O=!0}},[P,t,a]),i.useEffect(()=>{if(!t)return;const O=se=>{const Le=se.detail;Le?.projectId&&Le.projectId!==t.id||_(ae=>ae+1)};return window.addEventListener("openchamber:project-plan-saved",O),window.addEventListener("openchamber:project-notes-updated",O),()=>{window.removeEventListener("openchamber:project-plan-saved",O),window.removeEventListener("openchamber:project-notes-updated",O)}},[t]),i.useEffect(()=>{if(m.length<7)return;const O=$w(m.length,Fe),se=ma(Fe)*ic;R!==O&&(R<se||R>O)&&B(O)},[m.length,Fe,R,B]),i.useEffect(()=>{if(!U)return;const O=Le=>{const ae=Le.clientY-M.current,We=Math.min(ma(Fe)*Km,Math.max(ma(Fe)*ic,ee.current+ae));B(We)},se=()=>{L(!1)};return window.addEventListener("pointermove",O),window.addEventListener("pointerup",se,{once:!0}),window.addEventListener("pointercancel",se,{once:!0}),()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",se),window.removeEventListener("pointercancel",se)}},[U,Fe,B]);const K=i.useCallback(O=>{L(!0),M.current=O.clientY,ee.current=R,O.preventDefault()},[R]),Y=i.useCallback(()=>{I.current!==null&&(window.clearTimeout(I.current),I.current=null)},[]),me=i.useCallback(()=>{Y(),F.current=d,z(d,m)},[Y,d,z,m]);i.useEffect(()=>{if(!(!t||!v.current)&&d!==F.current)return I.current=window.setTimeout(()=>{I.current=null,F.current=d,z(d,m)},400),()=>{Y()}},[Y,d,z,t,m]),i.useEffect(()=>()=>Y(),[Y]);const Ne=i.useCallback(()=>{const O=p.trim();if(!O)return;const se=yu(m,{id:Ww(),text:O.slice(0,Yo),completed:!1,createdAt:Date.now()});u(se),x(""),z(d,se)},[p,d,z,m]),Be=i.useCallback(O=>{h(se=>{const Le=new Set(se);return Le.has(O)?Le.delete(O):Le.add(O),Le})},[]),_e=i.useCallback((O,se)=>{const Le=m.find(Qe=>Qe.id===O);if(!Le||Le.completed===se)return;const ae=m.filter(Qe=>Qe.id!==O),We={...Le,completed:se},Ye=se?[...ae,We]:yu(ae,We);u(Ye),z(d,Ye)},[d,z,m]),Oe=i.useCallback(O=>{const se=m.filter(Le=>Le.id!==O);u(se),z(d,se)},[d,z,m]),pe=i.useCallback(()=>{const O=m.filter(se=>!se.completed);O.length!==m.length&&(u(O),z(d,O))},[d,z,m]),Re=i.useCallback(O=>{const{active:se,over:Le}=O;if(!Le||se.id===Le.id)return;const ae=m.findIndex(Qe=>Qe.id===se.id),We=m.findIndex(Qe=>Qe.id===Le.id);if(ae===-1||We===-1)return;const Ye=wu(Gf(m,ae,We));u(Ye),z(d,Ye)},[d,z,m]),ge=ja(Do(Sa,{activationConstraint:{distance:8}})),ce=p.slice(0,Yo),Ce=m.reduce((O,se)=>O+(se.completed?1:0),0),be=i.useCallback(()=>{ye("chat"),he(!1)},[ye,he]),ue=i.useCallback((O,se)=>{!t||b||N({kind:"session",todoId:O,todoText:se})},[t,b]),De=i.useCallback(O=>{if(!ie){le.error(a("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}be();const se=`\`\`\`md
|
|
4
|
+
${O}
|
|
5
|
+
\`\`\``;oe(se,"append"),le.success(a("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[ie,r,be,oe,a]),T=i.useCallback((O,se)=>{if(!(!t||b)){if(!n){le.error(a("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}N({kind:"worktree",todoId:O,todoText:se})}},[n,t,b,a]),V=i.useCallback(async O=>{if(!t||!S)return;const se=await Fn("plan.todo.visible",{todo_text:S.todoText}),ae=[{synthetic:!0,text:await Fn("plan.todo.instructions",{todo_text:S.todoText})}];y(!0),w(S.todoId);try{be();let We=null,Ye=t.path;if(S.kind==="worktree"){if(!n){le.error(a("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const st=await cm(t.path,dm());if(!st?.id)return;We=st.id,Ye=st.path}else{const st=await te(void 0,t.path,null);if(!st?.id){le.error(a("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}We=st.id,Ye=st.directory??t.path,H(st.id,rs.getState().agents??[])}if(!We)return;const Qe=Tc.getState();Qe.saveSessionModelSelection(We,O.providerID,O.modelID),O.agent.trim()&&(Qe.saveSessionAgentSelection(We,O.agent),Qe.saveAgentModelForSession(We,O.agent,O.providerID,O.modelID),Qe.saveAgentModelVariantForSession(We,O.agent,O.providerID,O.modelID,O.variant||void 0)),re(We,Ye),await J(se,O.providerID,O.modelID,O.agent.trim()||void 0,void 0,void 0,ae,O.variant||void 0),le.success(S.kind==="worktree"?a("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):a("rightSidebar.contextNotesTodo.toast.sentToNewSession")),N(null),r?.()}catch(We){const Ye=We instanceof Error?We.message:void 0;le.error(a("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Ye?{description:Ye}:void 0)}finally{y(!1),w(null)}},[n,te,H,r,S,t,be,J,re,a]),we=i.useRef(null),[E,de]=i.useState(!1),[fe,$]=i.useState(null),ke=i.useCallback(async O=>{if(!(!t||fe)){$(O);try{if(!await Kp(t,O)){le.error(a("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}j(Le=>Le.filter(ae=>ae.id!==O)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{$(null)}}},[fe,t,a]),Ve=i.useCallback(async()=>{if(!t||E)return;const O=await jp({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(O.success&&O.path){de(!0);try{const se=new URLSearchParams({path:O.path,allowOutsideWorkspace:"true"});O.outsideFileGrant&&se.set("outsideFileGrant",O.outsideFileGrant);const Le=await Is(`/api/fs/read?${se.toString()}`,{cache:"no-store"});if(!Le.ok){le.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const ae=await Le.text();if(!ae.trim()){le.error(a("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const We=O.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await Od(t,ae,We)){le.error(a("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),le.success(a("rightSidebar.contextNotesTodo.toast.planImported"))}catch(se){const Le=se instanceof Error?se.message:void 0;le.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),Le?{description:Le}:void 0)}finally{de(!1)}}else O.error==="Native file picker not available"&&we.current?.click()},[E,t,a]),Se=i.useCallback(async O=>{if(!(!t||!O)){de(!0);try{const se=await O.text();if(!se.trim()){le.error(a("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Le=O.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await Od(t,se,Le)){le.error(a("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),le.success(a("rightSidebar.contextNotesTodo.toast.planImported"))}catch(se){const Le=se instanceof Error?se.message:void 0;le.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),Le?{description:Le}:void 0)}finally{de(!1)}}},[t,a]),q=i.useCallback(O=>{const se=t?.path?.trim(),Le=ve?.trim()||se;Le&&ne(Le,{mode:"plan",targetPath:O.path,dedupeKey:O.path,label:O.title})},[ve,ne,t]);return t?s.jsxs("div",{className:Pe("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.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:a("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d.length,"/",Ld]})]}),s.jsx(Oi,{value:d,onChange:O=>f(O.target.value.slice(0,Ld)),onBlur:me,placeholder:a("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:D,onResizeHeightChange:W,useScrollShadow:!0,scrollShadowSize:56,disabled:c})]}),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:a("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?a("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):a("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:pe,disabled:c||Ce===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:a("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[ce.length,"/",Yo]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ln,{value:ce,onChange:O=>x(O.target.value.slice(0,Yo)),onKeyDown:O=>{O.key==="Enter"&&(O.preventDefault(),Ne())},placeholder:a("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:c,className:"h-8"}),s.jsx("button",{type:"button",onClick:Ne,disabled:c||ce.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":a("rightSidebar.contextNotesTodo.todo.addAria"),title:a("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(A,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:Pe("overflow-y-auto rounded-lg border border-border/60 bg-background/40",U&&"transition-none"),style:m.length<7?void 0:{height:`${R}px`,maxHeight:`${R}px`},children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(Na,{sensors:ge,collisionDetection:ka,onDragEnd:Re,children:s.jsx(Gl,{items:m.map(O=>O.id),strategy:Kl,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(O=>{const se=g.has(O.id);return s.jsx(Uw,{id:O.id,children:Le=>s.jsxs("div",{className:Pe("flex gap-1.5 px-2.5 py-1.5",se?"items-start":"items-center"),children:[s.jsx("button",{type:"button",ref:Le.setActivatorNodeRef,...Le.attributes,...Le.listeners,onClick:ae=>{ae.preventDefault(),ae.stopPropagation()},className:"flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground","aria-label":a("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:O.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:O.text}),children:s.jsx(A,{name:"draggable",className:"h-3.5 w-3.5"})}),s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(Vr,{checked:O.completed,onChange:ae=>_e(O.id,ae),ariaLabel:a("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:O.text})})}),s.jsx("button",{type:"button",onClick:()=>Be(O.id),className:Pe("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-normal text-foreground",se?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",O.completed&&"text-muted-foreground line-through"),title:se?void 0:O.text,"aria-label":se?a("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:O.text}):a("rightSidebar.contextNotesTodo.todo.actions.expand",{text:O.text}),children:O.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>Oe(O.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":a("rightSidebar.contextNotesTodo.todo.actions.delete",{text:O.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.delete",{text:O.text}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(en,{children:[s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button",disabled:b===O.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":a("rightSidebar.contextNotesTodo.todo.actions.send",{text:O.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.send",{text:O.text}),children:s.jsx(A,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(Zs,{align:"end",className:"w-56",children:[s.jsx(ls,{onClick:()=>De(O.text),children:a("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(ls,{onClick:()=>ue(O.id,O.text),children:a("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(ls,{onClick:()=>{T(O.id,O.text)},disabled:!n,children:a("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},O.id)})})})})}),m.length>=7&&s.jsx("div",{className:Pe("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",U&&"bg-[var(--interactive-border)]"),onPointerDown:K,role:"separator","aria-orientation":"horizontal","aria-label":a("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),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:a("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:k.length===1?a("rightSidebar.contextNotesTodo.plans.filesSingle",{count:k.length}):a("rightSidebar.contextNotesTodo.plans.filesPlural",{count:k.length})})]}),s.jsx("input",{ref:we,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:O=>{const se=O.target.files?.[0]??null;Se(se),O.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:Ve,disabled:!t||E,className:"inline-flex h-6 w-6 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":a("rightSidebar.contextNotesTodo.plans.importFromFile"),title:a("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:k.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:k.map(O=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>q(O),className:"flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-foreground",children:O.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(O.createdAt).toLocaleDateString(oo())})]}),s.jsx("button",{type:"button",onClick:()=>{ke(O.id)},disabled:fe===O.id,className:"inline-flex h-6 w-6 flex-shrink-0 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",title:a("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":a("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:O.title}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},O.id))})})]}),s.jsx(Gm,{open:S!==null,onOpenChange:O=>{!O&&!C&&N(null)},target:S?.kind??"session",projectDirectory:t?.path??null,submitting:C,onConfirm:V})]}):s.jsx("div",{className:Pe("w-full min-w-0 p-3",o),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.empty.selectProject")})})},qm=12,Gw=[{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"}],Kw=t=>{const e=gt.c(18),{isActive:n,burstKey:r,className:o,durationMs:a,bursts:c,onComplete:l}=t,d=r===void 0?0:r,f=a===void 0?900:a,m=c===void 0?Gw:c,u=nt.useRef(!1);let p,x;e[0]!==n||e[1]!==l?(p=()=>{!n&&u.current&&l?.(),n&&(u.current=!0)},x=[n,l],e[0]=n,e[1]=l,e[2]=p,e[3]=x):(p=e[2],x=e[3]),nt.useEffect(p,x);let b;e[4]===Symbol.for("react.memo_cache_sentinel")?(b=Array.from({length:qm},qw),e[4]=b):b=e[4];const w=b;if(!n)return null;let g;e[5]!==o?(g=Pe("fireworks-overlay pointer-events-none",o),e[5]=o,e[6]=g):g=e[6];let h;if(e[7]!==d||e[8]!==m||e[9]!==f){let j;e[11]!==d||e[12]!==f?(j=S=>{const N={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${f}ms`};return s.jsx("div",{className:"firework-burst",style:N,children:w.map((C,y)=>{const P=C.x*S.radius,_=C.y*S.radius,v={"--translate-x":`${P}px`,"--translate-y":`${_}px`,"--particle-delay":`${C.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:v},`${S.id}-${y}-${d}`)})},`${S.id}-${d}`)},e[11]=d,e[12]=f,e[13]=j):j=e[13],h=m.map(j),e[7]=d,e[8]=m,e[9]=f,e[10]=h}else h=e[10];let k;return e[14]!==d||e[15]!==g||e[16]!==h?(k=s.jsx("div",{className:g,"aria-hidden":"true","data-burst-key":d,children:h}),e[14]=d,e[15]=g,e[16]=h,e[17]=k):k=e[17],k};function qw(t,e){const n=Math.PI*2*e/qm;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Yw=t=>{const e=gt.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[c,l]=nt.useState(a),d=nt.useRef(null);let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=f):f=e[3];const m=f;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{m(),l(Qw)},e[4]=u):u=e[4];const p=u;let x;e[5]!==o?(x=()=>{m(),l(Jw),d.current=window.setTimeout(()=>{l(Xw),d.current=null},o)},e[5]=o,e[6]=x):x=e[6];const b=x;let w,g;e[7]===Symbol.for("react.memo_cache_sentinel")?(w=()=>()=>m(),g=[m],e[7]=w,e[8]=g):(w=e[7],g=e[8]),nt.useEffect(w,g);let h;return e[9]!==c.cycle||e[10]!==c.isActive||e[11]!==b?(h={isActive:c.isActive,burstKey:c.cycle,triggerFireworks:b,dismissFireworks:p},e[9]=c.cycle,e[10]=c.isActive,e[11]=b,e[12]=h):h=e[12],h};function Qw(t){return t.isActive?{...t,isActive:!1}:t}function Jw(t){return{isActive:!0,cycle:t.cycle+1}}function Xw(t){return t.isActive?{...t,isActive:!1}:t}const Ym=i.createContext(void 0),Zw=t=>{const e=gt.c(10),{children:n}=t,{isActive:r,burstKey:o,triggerFireworks:a,dismissFireworks:c}=Yw();let l;e[0]!==c||e[1]!==a?(l={triggerFireworks:a,dismissFireworks:c},e[0]=c,e[1]=a,e[2]=l):l=e[2];const d=l;let f;e[3]!==o||e[4]!==r?(f=s.jsx(Kw,{isActive:r,burstKey:o}),e[3]=o,e[4]=r,e[5]=f):f=e[5];let m;return e[6]!==n||e[7]!==f||e[8]!==d?(m=s.jsxs(Ym.Provider,{value:d,children:[n,f]}),e[6]=n,e[7]=f,e[8]=d,e[9]=m):m=e[9],m},ey=()=>{const t=i.useContext(Ym);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Qm="gitmojiCache",ty=1e3*60*60*24*7,Jm="1",sy="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Xm=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Nl=()=>{if(typeof window>"u")return null;try{const t=window.localStorage.getItem(Qm);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==Jm||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Xm),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},ny=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:Jm};window.localStorage.setItem(Qm,JSON.stringify(e))}catch{return}},vu=t=>Date.now()-t.fetchedAt<ty;let Zo=null;const Ro=new Set,ju=async()=>{if(Zo)return Zo;const t=(async()=>{try{const e=await fetch(sy);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),r=Array.isArray(n.gitmojis)?n.gitmojis.filter(Xm):[];return ny(r),Ro.forEach(o=>o(r)),r}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return Ro.forEach(r=>r(n)),n}finally{Zo=null}})();return Zo=t,t},ry=t=>{const[e,n]=i.useState(()=>t?Nl()?.gitmojis??[]:[]),[r,o]=i.useState(!1),a=i.useRef(t);a.current=t,i.useEffect(()=>{if(!t){Ro.delete(n),n([]),o(!1);return}const l=Nl();if(l&&(n(l.gitmojis),vu(l)))return;Ro.add(n),o(!0);let d=!1;return ju().finally(()=>{!d&&a.current&&o(!1)}),()=>{d=!0,Ro.delete(n)}},[t]);const c=i.useCallback(async()=>{if(!a.current)return[];if(e.length>0)return e;const l=Nl();return l&&vu(l)?l.gitmojis:ju()},[e]);return{gitmojis:e,isLoading:r,ensureLoaded:c}},Su=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function iy(t,e,n){const r=gt.c(5),[o,a]=i.useState();let c,l;return r[0]!==n||r[1]!==t||r[2]!==e?(c=()=>{if(e){a(void 0);return}if(!t){a(void 0);return}a(void 0);let d=!1;return(async()=>{const[f,m]=await Promise.all([Yp(t),Qp(t)]).catch(oy);if(d)return;const u=Su(f),p=Su(m);if(!u||!p||p===u)return;const x=n||"",b=p.split("/").filter(Boolean).pop()||p;a({source:"sdk",path:p,projectDirectory:u,branch:x,label:x||b,name:b,worktreeRoot:p,worktreeStatus:"ready",headState:x?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},l=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=c,r[4]=l):(c=r[3],l=r[4]),i.useEffect(c,l),e??o}function oy(){return["",""]}const go=async(t,e)=>{const n=await Is(`/api/git/integrate/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>null);throw new Error(r?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function jo(t){return go("plan",t)}async function ay(t){return go("conflict-details",{tempWorktreePath:t})}async function ly(t){return(await go("cherry-pick-status",{tempWorktreePath:t})).inProgress}async function cy(t){return go("run",{plan:t})}async function dy(t){await go("abort",{state:t})}async function uy(t){return go("continue",{state:t})}const fy=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:o,refreshKey:a,onRefresh:c})=>{const{t:l}=yt(),d=ht(M=>M.currentSessionId),f=Ee(M=>M.setActiveMainTab),[m,u]=nt.useState(!1),p=nt.useRef(null),[x,b]=nt.useState(o);nt.useEffect(()=>{b(o)},[o]),nt.useEffect(()=>{if(m){const M=setTimeout(()=>{p.current?.focus()},0);return()=>clearTimeout(M)}},[m]);const w=!!(t&&e&&x&&x!=="HEAD"&&e!==x),[g,h]=nt.useState({kind:"idle"}),[k,j]=nt.useState(!1),[S,N]=nt.useState([]),C=nt.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);nt.useEffect(()=>{if(!C||typeof window>"u")return;const M=window.localStorage.getItem(C);if(!M)return;let ee=!1;try{const ie=JSON.parse(M);if(!ie?.tempWorktreePath||ie.repoRoot!==t){window.localStorage.removeItem(C);return}(async()=>{const te=await ly(ie.tempWorktreePath).catch(()=>!1);if(ee)return;if(!te){window.localStorage.removeItem(C);return}const H=await ay(ie.tempWorktreePath).catch(()=>null);ee||H&&h({kind:"conflict",state:ie,details:H})})()}catch{window.localStorage.removeItem(C)}return()=>{ee=!0}},[C,t]),nt.useEffect(()=>{if(!w){h({kind:"idle"});return}let M=!1;return h({kind:"loading"}),(async()=>{try{const ee=await jo({repoRoot:t,sourceBranch:e,targetBranch:x});if(M)return;if(h({kind:"ready",plan:ee}),ee.commits.length>0){const te=ee.commits.slice(-50).reverse(),H=await Jp(t,te);M||(N(H),j(!1))}else M||(N([]),j(!1))}catch{M||h({kind:"idle"})}})(),()=>{M=!0}},[w,t,e,x,a]);const y=nt.useCallback(M=>{d&&ht.getState().setWorktreeMetadata(d,{...n,createdFromBranch:M})},[d,n]),P=ht(M=>M.openNewSessionDraft),_=nt.useCallback(async M=>{const ee=await Fn("git.integrate.cherrypick.resolve.visible",{current_commit:M.state.currentCommit,target_branch:M.state.targetBranch}),ie=await Fn("git.integrate.cherrypick.resolve.instructions",{repo_root:M.state.repoRoot,temp_worktree_path:M.state.tempWorktreePath,source_branch:M.state.sourceBranch,target_branch:M.state.targetBranch,current_commit:M.state.currentCommit}),te=`Cherry-pick conflict context (JSON)
|
|
6
|
+
${JSON.stringify({repoRoot:M.state.repoRoot,tempWorktreePath:M.state.tempWorktreePath,sourceBranch:M.state.sourceBranch,targetBranch:M.state.targetBranch,currentCommit:M.state.currentCommit,remainingCommits:M.state.remainingCommits,statusPorcelain:M.details.statusPorcelain,unmergedFiles:M.details.unmergedFiles,currentPatchMeta:M.details.currentPatchMeta,currentPatch:M.details.currentPatch,diff:M.details.diff},null,2)}`;return{visibleText:ee,instructionsText:ie,payloadText:te}},[]),v=xi(M=>M.setPendingInputText),F=xi(M=>M.setPendingSyntheticParts),I=nt.useCallback(async(M,ee)=>{const ie=await _(M);if(ee){P({directoryOverride:M.state.tempWorktreePath,initialPrompt:ie.visibleText,syntheticParts:[{text:ie.instructionsText,synthetic:!0},{text:ie.payloadText,synthetic:!0}]}),f("chat");return}if(!d){le.error(l("gitView.integrate.noActiveSession"),{description:l("gitView.integrate.noActiveSessionDescription")});return}v(ie.visibleText,"replace"),F([{text:ie.instructionsText,synthetic:!0},{text:ie.payloadText,synthetic:!0}]),f("chat")},[d,f,_,P,v,F,l]),R=nt.useCallback(async()=>{if(g.kind==="ready"){if(g.plan.commits.length===0){le.message(l("gitView.integrate.noCommitsToMoveToast"));return}h({kind:"running",plan:g.plan});try{const M=await cy(g.plan);if(M.kind==="success"){le.success(l("gitView.integrate.commitsMovedToast"),{description:M.moved===1?l("gitView.integrate.commitsMovedDescriptionSingle",{count:M.moved,branch:g.plan.targetBranch}):l("gitView.integrate.commitsMovedDescriptionPlural",{count:M.moved,branch:g.plan.targetBranch})});const ee=await jo(g.plan);h({kind:"ready",plan:ee}),c?.();return}M.kind==="conflict"&&(le.error(l("gitView.integrate.cherryPickConflictToast"),{description:l("gitView.integrate.cherryPickConflictDescription")}),h({kind:"conflict",state:M.state,details:M.details}),C&&typeof window<"u"&&window.localStorage.setItem(C,JSON.stringify(M.state)))}catch(M){const ee=M instanceof Error?M.message:String(M);le.error(l("gitView.integrate.failedToMoveToast"),{description:ee});const ie=await jo({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);h(ie?{kind:"ready",plan:ie}:{kind:"idle"})}}},[g,c,t,e,x,C,l]),B=nt.useCallback(async()=>{if(g.kind==="conflict")try{await dy(g.state),le.message(l("gitView.integrate.cherryPickAbortedToast")),C&&typeof window<"u"&&window.localStorage.removeItem(C)}finally{const M=await jo({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);h(M?{kind:"ready",plan:M}:{kind:"idle"})}},[g,t,e,x,C,l]),D=nt.useCallback(async()=>{if(g.kind==="conflict")try{const M=await uy(g.state);if(M.kind==="success"){le.success(l("gitView.integrate.cherryPickFinishedToast"));const ee=await jo({repoRoot:t,sourceBranch:e,targetBranch:x}).catch(()=>null);h(ee?{kind:"ready",plan:ee}:{kind:"idle"}),C&&typeof window<"u"&&window.localStorage.removeItem(C),c?.();return}M.kind==="conflict"&&(h({kind:"conflict",state:M.state,details:M.details}),C&&typeof window<"u"&&window.localStorage.setItem(C,JSON.stringify(M.state)))}catch(M){const ee=M instanceof Error?M.message:String(M);le.error(l("gitView.integrate.cherryPickContinueFailedToast"),{description:ee})}},[g,t,e,x,c,C,l]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(A,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:l("gitView.integrate.title")}),g.kind==="ready"&&g.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:l("gitView.integrate.toMoveCount",{count:g.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:g.kind==="loading"||g.kind==="running"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.integrate.moveCommits")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",x]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(en,{open:m,onOpenChange:u,children:[s.jsx(Xs,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"sm",className:"gap-1.5",children:[l("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:x}),s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(Zs,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(Ha,{className:"h-full min-h-0",children:[s.jsx(Ga,{ref:p,placeholder:l("gitView.branch.searchPlaceholder"),onKeyDown:M=>M.stopPropagation()}),s.jsxs(Ka,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(qa,{children:l("gitView.branch.empty")}),s.jsx(Qr,{heading:l("gitView.branch.localBranches"),children:r.map(M=>s.jsx(Jr,{value:M,onSelect:()=>{b(M),y(M),u(!1)},children:M},M))})]})]})})]}),g.kind==="ready"?s.jsx(ze,{size:"sm",onClick:()=>{R()},disabled:!w||g.plan.commits.length===0,children:l("gitView.integrate.move")}):g.kind==="loading"?s.jsx(ze,{size:"sm",variant:"outline",disabled:!0,children:l("gitView.integrate.checking")}):g.kind==="running"?s.jsx(ze,{size:"sm",variant:"outline",disabled:!0,children:l("gitView.integrate.moving")}):null]}),g.kind==="ready"&&g.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.integrate.noCommitsToMove")}),g.kind==="ready"&&g.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[l("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",g.plan.commits.length,")"]})]}),S.length>0&&g.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>j(M=>!M),className:"typography-micro text-muted-foreground hover:text-foreground",children:l(k?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(k?S:S.slice(0,5)).map(M=>s.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:M.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:M.subject||M.sha})]},M.sha)),S.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.integrate.previewUnavailable")}),g.plan.commits.length>S.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:l("gitView.integrate.showingFirstCommits",{count:S.length})})]})]}),g.kind==="conflict"&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[s.jsx("div",{className:"typography-meta text-foreground",children:l("gitView.integrate.conflictsInFiles",{count:g.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[l("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:g.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[g.details.unmergedFiles.slice(0,6).map(M=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:M},M)),g.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:l("gitView.integrate.moreFiles",{count:g.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ze,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{B()},children:l("gitView.operation.abort")}),s.jsxs(ze,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{I({state:g.state,details:g.details},!1)},children:[s.jsx(A,{name:"sparkling",className:"size-3.5"}),l("gitView.integrate.currentSession")]}),s.jsxs(ze,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{I({state:g.state,details:g.details},!0)},children:[s.jsx(A,{name:"sparkling",className:"size-3.5"}),l("gitView.integrate.newSession")]}),s.jsx(ze,{size:"sm",className:"typography-meta",onClick:()=>{D()},children:l("gitView.operation.continue")})]})]})]})]})},my=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:o=!1,uncommittedFileCount:a,onChanged:c})=>{const{t:l}=yt(),[d,f]=i.useState([]),[m,u]=i.useState(!1),[p,x]=i.useState(""),[b,w]=i.useState(""),[g,h]=i.useState(null),[k,j]=i.useState({}),S=i.useCallback(async()=>{if(n){u(!0);try{const v=await Xp(n);f(v.stashes),j({})}catch(v){le.error(v instanceof Error?v.message:l("gitView.stashes.toast.loadFailed"))}finally{u(!1)}}},[n,l]);i.useEffect(()=>{t&&S()},[S,t]),i.useEffect(()=>{if(!t||!n||d.length===0)return;let v=!1;const F=d.map(I=>I.ref);return Zp(n,F).then(I=>{v||j(I.counts)}).catch(()=>{}),()=>{v=!0}},[n,t,d]);const N=i.useMemo(()=>{const v=p.trim().toLowerCase();return v?d.filter(F=>`${F.ref} ${F.message} ${F.relativeTime}`.toLowerCase().includes(v)):d},[p,d]),C=i.useCallback(async v=>{await S(),await c?.(v)},[S,c]),y=async()=>{if(!(!n||g)){h("create");try{const v=await eg(n,{message:b.trim()||void 0});v.created?(le.success(l("gitView.stashes.toast.created")),w("")):le.info(l("gitView.stashes.toast.noChanges")),await C({affectsIndex:!!(v.created&&o)})}catch(v){le.error(v instanceof Error?v.message:l("gitView.stashes.toast.createFailed"))}finally{h(null)}}},P=async(v,F)=>{if(!(!n||g)&&!(F==="drop"&&!window.confirm(l("gitView.stashes.confirm.drop",{ref:v.ref})))){h(`${F}:${v.ref}`);try{F==="apply"&&await tg(n,{ref:v.ref}),F==="pop"&&await sg(n,{ref:v.ref}),F==="drop"&&await ng(n,{ref:v.ref});const I=F==="apply"?"gitView.stashes.toast.applySuccess":F==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";le.success(l(I)),await C({affectsIndex:F!=="drop"})}catch(I){const R=F==="apply"?"gitView.stashes.toast.applyFailed":F==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";le.error(I instanceof Error?I.message:l(R)),await C({affectsIndex:F!=="drop"})}finally{h(null)}}},_=g!==null;return s.jsx(_s,{open:t,onOpenChange:e,children:s.jsxs(Vs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(tn,{children:[s.jsxs(Gs,{className:"flex items-center gap-2",children:[s.jsx(A,{name:"archive-stack",className:"h-5 w-5"}),l("gitView.stashes.title")]}),s.jsx(dn,{children:l("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(Ln,{value:b,onChange:v=>w(v.target.value),placeholder:l("gitView.stashes.messagePlaceholder"),disabled:_||!r,className:"flex-1"}),s.jsxs(ze,{onClick:y,disabled:!r||_||!n,children:[g==="create"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"inbox-archive",className:"size-4"}),l("gitView.stashes.actions.stashCurrentWithCount",{count:a})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:l("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(A,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(Ln,{value:p,onChange:v=>x(v.target.value),placeholder:l("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:m?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(A,{name:"loader-4",className:"size-5 animate-spin"})}):N.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:l(p?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):N.map((v,F)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:v.message||l("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{children:F===0&&!p.trim()?l("gitView.stashes.latestLabel"):l("gitView.stashes.itemNumber",{number:F+1})})}),s.jsx(Tt,{sideOffset:6,children:v.ref})]})," · ",v.relativeTime," · ",typeof k[v.ref]=="number"?l("gitView.stashes.fileCount",{count:k[v.ref]}):l("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(kl,{label:l("gitView.stashes.actions.apply"),loading:g===`apply:${v.ref}`,onClick:()=>P(v,"apply"),disabled:_,children:s.jsx(A,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(kl,{label:l("gitView.stashes.actions.pop"),loading:g===`pop:${v.ref}`,onClick:()=>P(v,"pop"),disabled:_,children:s.jsx(A,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(kl,{label:l("gitView.stashes.actions.drop"),loading:g===`drop:${v.ref}`,onClick:()=>P(v,"drop"),disabled:_,destructive:!0,children:s.jsx(A,{name:"delete-bin",className:"size-4"})})]})]},v.ref))})]})})},kl=t=>{const e=gt.c(17),{label:n,loading:r,disabled:o,destructive:a,onClick:c,children:l}=t,d=r||void 0,f=a?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let m;e[0]!==f?(m=Pe("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",f),e[0]=f,e[1]=m):m=e[1];let u;e[2]!==l||e[3]!==r?(u=r?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):l,e[2]=l,e[3]=r,e[4]=u):u=e[4];let p;e[5]!==o||e[6]!==n||e[7]!==c||e[8]!==d||e[9]!==m||e[10]!==u?(p=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:m,onClick:c,disabled:o,children:u})}),e[5]=o,e[6]=n,e[7]=c,e[8]=d,e[9]=m,e[10]=u,e[11]=p):p=e[11];let x;e[12]!==n?(x=s.jsx(Tt,{sideOffset:6,children:n}),e[12]=n,e[13]=x):x=e[13];let b;return e[14]!==p||e[15]!==x?(b=s.jsxs(At,{children:[p,x]}),e[14]=p,e[15]=x,e[16]=b):b=e[16],b},hy=t=>{const e=gt.c(16),{onOpenStashes:n}=t,{t:r}=yt();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(A,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=o):o=e[0];let a;e[1]!==r?(a=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=a):a=e[2];let c;e[3]!==a?(c=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:a}),e[3]=a,e[4]=c):c=e[4];let l;e[5]!==r?(l=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=l):l=e[6];let d;e[7]!==l?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:l}),e[7]=l,e[8]=d):d=e[8];let f;e[9]!==n||e[10]!==r?(f=n?s.jsxs(ze,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(A,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=f):f=e[11];let m;return e[12]!==c||e[13]!==d||e[14]!==f?(m=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[o,c,d,f]}),e[12]=c,e[13]=d,e[14]=f,e[15]=m):m=e[15],m},ui=8,py=t=>{const e=gt.c(18),{laned:n,totalLanes:r,isExpanded:o}=t,{lane:a,color:c,connectors:l}=n,f=Math.max(r,a+1)*ui+ui/2,m=i.useRef(null),u=i.useRef(null);let p;e[0]!==c||e[1]!==l||e[2]!==a||e[3]!==f?(p=()=>{const h=m.current,k=u.current;if(!h||!k)return;const j=h.offsetHeight;if(j===0)return;const S=window.devicePixelRatio||1;k.width=f*S,k.height=j*S;const N=k.getContext("2d");if(!N)return;N.scale(S,S),N.clearRect(0,0,f,j);const C=j/2,y=a*ui+ui/2,P=getComputedStyle(k),_=P.getPropertyValue("--surface-muted-foreground").trim()||P.color,v=R=>{if(!R.startsWith("var("))return R;const B=R.slice(4,-1).trim();return P.getPropertyValue(B).trim()||_},F=[...l].sort(xy);for(const R of F){const B=R.fromLane*ui+ui/2,D=R.toLane*ui+ui/2,W=R.type==="passing"?.72:R.type==="branch-out"||R.type==="merge-in"?.95:1;N.beginPath(),N.strokeStyle=v(R.color),N.globalAlpha=W,N.lineWidth=1.25,N.lineCap="round";e:switch(R.type){case"passing":case"commit-lane":{N.moveTo(B,0),N.lineTo(B,j);break e}case"top-stub":{N.moveTo(B,0),N.lineTo(B,C);break e}case"bottom-stub":{N.moveTo(B,C),N.lineTo(B,j);break e}case"branch-out":{const U=(C+j)/2;N.moveTo(y,C),N.bezierCurveTo(y,U,D,U,D,j);break e}case"merge-in":{const U=C/2;N.moveTo(B,0),N.bezierCurveTo(B,U,y,U,y,C);break e}default:continue}N.stroke(),N.globalAlpha=1}const I=P.getPropertyValue("--background").trim()||P.getPropertyValue("--surface-background").trim();N.beginPath(),N.arc(y,C,4,0,Math.PI*2),N.fillStyle=v(c),N.fill(),N.beginPath(),N.arc(y,C,5,0,Math.PI*2),N.strokeStyle=I||_,N.lineWidth=2,N.stroke()},e[0]=c,e[1]=l,e[2]=a,e[3]=f,e[4]=p):p=e[4];let x;e[5]!==c||e[6]!==l||e[7]!==o||e[8]!==a||e[9]!==n||e[10]!==r||e[11]!==f?(x=[n,a,c,l,r,o,f],e[5]=c,e[6]=l,e[7]=o,e[8]=a,e[9]=n,e[10]=r,e[11]=f,e[12]=x):x=e[12],i.useLayoutEffect(p,x);let b;e[13]!==f?(b={width:f,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=f,e[14]=b):b=e[14];let w;e[15]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx("canvas",{ref:u,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=w):w=e[15];let g;return e[16]!==b?(g=s.jsx("div",{ref:m,style:b,children:w}),e[16]=b,e[17]=g):g=e[17],g};function gy(t){return t==="branch-out"||t==="merge-in"}function xy(t,e){const n=gy;return(n(t.type)?1:0)-(n(e.type)?1:0)}const Nu=15e3,ku=500,Cu=12,Au=8*1024*1024,Du=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),Tu=t=>{if(t.size<=Cu){let o=0;for(const a of t.values())o+=Du(a);if(o<=Au)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[o,a]of e){if(n.size>=Cu)continue;const c=Du(a);r+c>Au&&n.size>0||(n.set(o,a),r+=c)}return new Map(Array.from(n.entries()).reverse())};function Pu(t,e){const n=new Date(t);return Number.isNaN(n.getTime())?t:Pc(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function by(t){switch(t){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}function wy(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const yy=i.memo(({entry:t,mode:e="history",laned:n,totalLanes:r,isExpanded:o,onToggle:a,files:c,isLoadingFiles:l,onCopyHash:d,directory:f,onConflict:m,onActionSuccess:u})=>{const{t:p}=yt(),x=Ee(H=>H.timeFormatPreference),b=e==="graph",[w,g]=i.useState(null),[h,k]=i.useState(!1),[j,S]=i.useState(""),[N,C]=i.useState(null),[y,P]=i.useState(new Set),[_,v]=i.useState(new Map),[F,I]=i.useState(new Set),R=async()=>{if(f){g("checkout");try{await ug(f,t.hash),le.success(p("gitView.history.actions.detachedHead")),u?.()}catch(H){le.error(String(H.message))}finally{g(null)}}},B=async()=>{if(!(!f||!j.trim())){g("createBranch");try{await ig(f,j.trim(),t.hash),k(!1),S(""),u?.()}catch(H){le.error(String(H.message))}finally{g(null)}}},D=async()=>{if(f){g("cherryPick");try{const H=await dg(f,t.hash);H.conflict?m?.({conflict:!0,conflictFiles:H.conflictFiles,operation:"cherry-pick"}):u?.()}catch(H){le.error(String(H.message))}finally{g(null)}}},W=async()=>{if(f){g("revert");try{const H=await cg(f,t.hash);H.conflict?m?.({conflict:!0,conflictFiles:H.conflictFiles,operation:"revert"}):u?.()}catch(H){le.error(String(H.message))}finally{g(null)}}},U=async(H,J=!1)=>{if(!(!f||w!==null)){g("reset");try{await og(f,t.hash,H,J),u?.()}catch(re){le.error(String(re.message))}finally{g(null)}}},L=async()=>{if(!N)return;const H=N;switch(C(null),H){case"checkout":return R();case"cherryPick":return D();case"revert":return W();case"merge":return M();case"rebase":return ee();case"resetSoft":return U("soft");case"resetMixed":return U("mixed");case"resetHard":return U("hard",!0)}},M=async()=>{if(f){g("merge");try{const H=await lg(f,{branch:t.hash});H.conflict?m?.({conflict:!0,conflictFiles:H.conflictFiles,operation:"merge"}):u?.()}catch(H){le.error(String(H.message))}finally{g(null)}}},ee=async()=>{if(f){g("rebase");try{const H=await ag(f,{onto:t.hash});H.conflict?m?.({conflict:!0,conflictFiles:H.conflictFiles,operation:"rebase"}):u?.()}catch(H){le.error(String(H.message))}finally{g(null)}}},ie=i.useCallback(async H=>{const J=H.path;if(!f){v(re=>new Map(re).set(J,"error"));return}v(re=>Tu(new Map(re).set(J,"loading")));try{const re=rg(f,t.hash,H.path,!1),oe=new Promise((ne,ye)=>{setTimeout(()=>ye(new Error(`Timed out after ${Nu}ms`)),Nu)}),ve=await Promise.race([re,oe]);v(ne=>Tu(new Map(ne).set(J,ve)))}catch{v(re=>new Map(re).set(J,"error"))}},[f,t.hash]),te=i.useCallback(async H=>{const J=H.path;if(H.changeType==="R"||H.isBinary){P(ne=>{const ye=new Set(ne);return ye.has(J)?ye.delete(J):ye.add(J),ye});return}const re=_.get(J);if(y.has(J)&&re&&re!=="error"){P(ne=>{const ye=new Set(ne);return ye.delete(J),ye});return}P(ne=>{const ye=new Set(ne);return ye.add(J),ye}),!(re&&re!=="error"||H.insertions+H.deletions>ku&&!F.has(J))&&await ie(H)},[_,F,ie,y]);return s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:a,className:Pe("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",b?"hover:bg-[var(--interactive-hover)]/40":o?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[b&&n&&r!==void 0?s.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:s.jsx(py,{laned:n,totalLanes:r,isExpanded:o})}):s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),s.jsxs("div",{className:"min-w-0 flex-1",children:[b?(()=>{const H=wy(t.refs);return H.length>0?s.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:H.map(J=>s.jsx("span",{className:Pe("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",J.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":J.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:J.label},J.label))}):null})():null,s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:t.message}),s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[s.jsx("span",{className:"truncate min-w-[3ch]",title:t.author_name,children:t.author_name}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("span",{className:"truncate min-w-0",title:Pu(t.date,x),children:Pu(t.date,x)})]}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("code",{className:"shrink-0 font-mono",children:t.hash.slice(0,8)}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:H=>{H.stopPropagation(),d(t.hash)},children:s.jsx(A,{name:"file-copy",className:"size-3"})})}),s.jsx(Tt,{sideOffset:8,children:p("gitView.history.copySha")})]})]})]})]}),o&&s.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[b&&N?s.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:p(`gitView.history.actions.${N}Confirm`)}),s.jsxs(ze,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:w!==null,onClick:H=>{H.stopPropagation(),L()},children:[w!==null?s.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.confirmButton")]}),s.jsx(ze,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:w!==null,onClick:H=>{H.stopPropagation(),C(null)},children:p("gitView.history.actions.cancelButton")})]}):b?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:w!==null,onClick:H=>{H.stopPropagation(),C("checkout")},children:p("gitView.history.actions.checkout")}),h?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("input",{autoFocus:!0,value:j,onChange:H=>S(H.target.value),onKeyDown:H=>{H.key==="Enter"&&B(),H.key==="Escape"&&(k(!1),S(""))},placeholder:p("gitView.history.actions.createBranchPlaceholder"),className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),s.jsxs(ze,{variant:"outline",size:"xs",className:"h-6",disabled:!j.trim()||w!==null,onClick:H=>{H.stopPropagation(),B()},children:[w==="createBranch"?s.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.createBranchConfirm")]})]}):s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",onClick:H=>{H.stopPropagation(),k(!0)},children:p("gitView.history.actions.createBranch")}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:w!==null,onClick:H=>{H.stopPropagation(),C("cherryPick")},children:p("gitView.history.actions.cherryPick")}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:w!==null,onClick:H=>{H.stopPropagation(),C("revert")},children:p("gitView.history.actions.revert")}),s.jsxs(en,{children:[s.jsx(Xs,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"xs",className:"h-6",disabled:w!==null,onClick:H=>H.stopPropagation(),children:[w==="reset"?s.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.reset")]})}),s.jsx(Zs,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(H=>s.jsx(ls,{disabled:w!==null,onSelect:J=>{J.stopPropagation(),C(`reset${H.charAt(0).toUpperCase()+H.slice(1)}`)},children:p(`gitView.history.actions.reset${H.charAt(0).toUpperCase()+H.slice(1)}`)},H))})]}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:w!==null,onClick:H=>{H.stopPropagation(),C("merge")},children:p("gitView.history.actions.merge")}),s.jsx(ze,{variant:"outline",size:"xs",className:"h-6",disabled:w!==null,onClick:H=>{H.stopPropagation(),C("rebase")},children:p("gitView.history.actions.rebase")})]}):null,l?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:p("gitView.history.loadingFiles")})]}):c.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:p("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:c.map(H=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>te(H),className:Pe("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",y.has(H.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:Pe("font-semibold w-3 text-center shrink-0",by(H.changeType)),children:H.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:H.path,children:H.path}),!H.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",H.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",H.deletions]})]}),H.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:p("gitView.history.binary")}),s.jsx(A,{name:y.has(H.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),y.has(H.path)&&s.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:H.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.renamedNoDiff")}):H.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.binaryNoDiff")}):(()=>{const J=H.insertions+H.deletions;if(!F.has(H.path)&&J>ku)return s.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:p("gitView.history.largeDiffTitle",{count:J})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:p("gitView.history.largeDiffDescription")}),s.jsx(ze,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{I(oe=>new Set(oe).add(H.path)),ie(H)},children:p("gitView.history.renderDiffAnyway")})]});const re=_.get(H.path);return re==="loading"||re===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.loadingDiff")}):re==="error"?s.jsx("button",{type:"button",onClick:()=>te(H),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:p("gitView.history.diffError")}):s.jsx(Em,{original:re.original,modified:re.modified,language:Bi(H.path)||"",fileName:H.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},H.path))})]})]})}),Iu=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--syntax-keyword)","var(--syntax-string)","var(--status-info)"];function ea(t){return Iu[t%Iu.length]}function vy(t){if(t.length===0)return[];const e=[],n=[];for(let r=0;r<t.length;r++){const o=t[r],a=[];for(let x=0;x<e.length;x++)e[x]===o.hash&&a.push(x);let c=a.length>0?a[0]:-1;if(c===-1){const x=e.indexOf(null);x!==-1?c=x:(c=e.length,e.push(null))}const l=a.slice(1),d=ea(c),f=e[c]===o.hash,m=o.parents.length>0;m?e[c]=o.parents[0]:e[c]=null;const u=[];for(let x=1;x<o.parents.length;x++){const b=o.parents[x],w=e.indexOf(b);if(w!==-1)u.push(w);else{const g=e.indexOf(null),h=g!==-1?g:e.length;e[h]=b,h===e.length&&e.push(b),u.push(h)}}const p=[];f&&m?p.push({fromLane:c,toLane:c,color:d,type:"commit-lane"}):f&&!m?p.push({fromLane:c,toLane:c,color:d,type:"top-stub"}):!f&&m&&p.push({fromLane:c,toLane:c,color:d,type:"bottom-stub"});for(const x of l)p.push({fromLane:x,toLane:c,color:ea(x),type:"merge-in"}),e[x]=null;for(const x of u)p.push({fromLane:c,toLane:x,color:ea(x),type:"branch-out"});for(let x=0;x<e.length;x++)e[x]!==null&&x!==c&&(u.includes(x)||p.push({fromLane:x,toLane:x,color:ea(x),type:"passing"}));n.push({commit:o,lane:c,color:d,connectors:p})}return n}const jy=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],Sy=t=>{const e=gt.c(84),{mode:n,log:r,isLogLoading:o,logMaxCount:a,onLogMaxCountChange:c,expandedCommitHashes:l,onToggleCommit:d,commitFilesMap:f,loadingCommitHashes:m,onCopyHash:u,directory:p,showHeader:x,contentMaxHeightClassName:b,branchDivider:w,onConflict:g,onActionSuccess:h}=t,k=n===void 0?"history":n,j=x===void 0?!0:x,S=b===void 0?"max-h-[50vh]":b,N=w===void 0?null:w,{t:C}=yt(),[y,P]=i.useState(!0),_=k==="graph";let v;e[0]!==_||e[1]!==r?(v=_&&r?vy(r.all):[],e[0]=_,e[1]=r,e[2]=v):v=e[2];const F=v;let I;e[3]!==F?(I=Math.max(1,...F.map(Ny)),e[3]=F,e[4]=I):I=e[4];const R=I;let B;e[5]!==F?(B=new Map(F.map(ky)),e[5]=F,e[6]=B):B=e[6];const D=B;if(!r)return null;const W=N!==null&&N.insertBeforeIndex>0&&N.insertBeforeIndex<r.all.length,U=N!==null&&N.insertBeforeIndex===r.all.length,L=W||U;let M;e[7]!==N||e[8]!==W||e[9]!==U||e[10]!==r.all?(M=W?r.all.slice(0,N.insertBeforeIndex):U?r.all:[],e[7]=N,e[8]=W,e[9]=U,e[10]=r.all,e[11]=M):M=e[11];const ee=M;let ie;if(e[12]!==N||e[13]!==f||e[14]!==S||e[15]!==p||e[16]!==l||e[17]!==W||e[18]!==L||e[19]!==_||e[20]!==o||e[21]!==D||e[22]!==m||e[23]!==r.all||e[24]!==a||e[25]!==R||e[26]!==k||e[27]!==h||e[28]!==g||e[29]!==u||e[30]!==c||e[31]!==d||e[32]!==C||e[33]!==ee){const Fe=W?r.all.slice(N.insertBeforeIndex):[];let z;e[35]!==N?.direction?(z=N?.direction==="down"?s.jsx(A,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(A,{name:"arrow-up",className:"size-3.5"}),e[35]=N?.direction,e[36]=z):z=e[36];const K=z;let Y;e[37]!==f||e[38]!==p||e[39]!==l||e[40]!==_||e[41]!==D||e[42]!==m||e[43]!==R||e[44]!==k||e[45]!==h||e[46]!==g||e[47]!==u||e[48]!==d?(Y=_e=>s.jsx("ul",{className:"divide-y divide-border/60",children:_e.map(Oe=>s.jsx(yy,{entry:Oe,mode:k,laned:_?D.get(Oe.hash):void 0,totalLanes:_?R:void 0,isExpanded:l.has(Oe.hash),onToggle:()=>d(Oe.hash),files:f.get(Oe.hash)??[],isLoadingFiles:m.has(Oe.hash),onCopyHash:u,directory:p,onConflict:g,onActionSuccess:h},Oe.hash))}),e[37]=f,e[38]=p,e[39]=l,e[40]=_,e[41]=D,e[42]=m,e[43]=R,e[44]=k,e[45]=h,e[46]=g,e[47]=u,e[48]=d,e[49]=Y):Y=e[49];const me=Y;let Ne;e[50]!==o||e[51]!==r.all.length||e[52]!==a||e[53]!==c||e[54]!==C?(Ne=r.all.length>=a?s.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:s.jsx(ze,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(a+25),disabled:o,className:"px-3 text-muted-foreground hover:text-foreground",children:o?s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(A,{name:"loader-4",className:"size-3 animate-spin"}),C("gitView.history.loadingMore")]}):C("gitView.history.loadMore")})}):null,e[50]=o,e[51]=r.all.length,e[52]=a,e[53]=c,e[54]=C,e[55]=Ne):Ne=e[55];const Be=Ne;ie=s.jsx(On,{outerClassName:`min-h-0 ${S}`,className:"h-full w-full",children:r.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:C("gitView.history.noCommits")})}):L&&N?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-0",children:[ee.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:me(ee)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:N.branchName,children:N.branchName}),K]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),Fe.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:me(Fe)}):null]}),Be]}):s.jsxs(s.Fragment,{children:[me(r.all),Be]})}),e[12]=N,e[13]=f,e[14]=S,e[15]=p,e[16]=l,e[17]=W,e[18]=L,e[19]=_,e[20]=o,e[21]=D,e[22]=m,e[23]=r.all,e[24]=a,e[25]=R,e[26]=k,e[27]=h,e[28]=g,e[29]=u,e[30]=c,e[31]=d,e[32]=C,e[33]=ee,e[34]=ie}else ie=e[34];const te=ie;if(!j){if(L){let z;return e[56]!==te?(z=s.jsx("section",{className:"h-full min-h-0",children:te}),e[56]=te,e[57]=z):z=e[57],z}let Fe;return e[58]!==te?(Fe=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:te}),e[58]=te,e[59]=Fe):Fe=e[59],Fe}let H;e[60]!==C?(H=C("gitView.history.title"),e[60]=C,e[61]=H):H=e[61];let J;e[62]!==H?(J=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:H}),e[62]=H,e[63]=J):J=e[63];let re;e[64]!==o||e[65]!==y||e[66]!==a||e[67]!==c||e[68]!==C?(re=y&&s.jsx("div",{onClick:Cy,onPointerDown:Ay,children:s.jsxs(Un,{value:String(a),onValueChange:Fe=>c(Number(Fe)),disabled:o,children:[s.jsx(Hn,{size:"sm",className:"data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0",disabled:o,children:s.jsx(Dn,{placeholder:C("gitView.history.commitsPlaceholder")})}),s.jsx(Gn,{children:jy.map(Fe=>s.jsx(Bs,{value:String(Fe.value),children:C(Fe.labelKey)},Fe.value))})]})}),e[64]=o,e[65]=y,e[66]=a,e[67]=c,e[68]=C,e[69]=re):re=e[69];let oe;e[70]!==y?(oe=y?s.jsx(A,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=y,e[71]=oe):oe=e[71];let ve;e[72]!==re||e[73]!==oe?(ve=s.jsxs("div",{className:"flex items-center gap-2",children:[re,oe]}),e[72]=re,e[73]=oe,e[74]=ve):ve=e[74];let ne;e[75]!==J||e[76]!==ve?(ne=s.jsxs(Ho,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[J,ve]}),e[75]=J,e[76]=ve,e[77]=ne):ne=e[77];let ye;e[78]!==te?(ye=s.jsx(co,{children:te}),e[78]=te,e[79]=ye):ye=e[79];let he;return e[80]!==y||e[81]!==ne||e[82]!==ye?(he=s.jsxs(lo,{open:y,onOpenChange:P,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[ne,ye]}),e[80]=y,e[81]=ne,e[82]=ye,e[83]=he):he=e[83],he};function Ny(t){return t.lane+1}function ky(t){return[t.commit.hash,t]}function Cy(t){return t.stopPropagation()}function Ay(t){return t.stopPropagation()}const Zm=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),o=new Array(t.length);let a=0;const c=async()=>{for(;;){const l=a;if(a+=1,l>=t.length)return;o[l]=await n(t[l])}};return await Promise.all(Array.from({length:r},()=>c())),o},Dy=9e4,Ty=15e3,Py=5*6e4,Iy=[2e3,5e3],Ry=6e4,Ey=2*6e4,My=5*6e4,Fy=4,Oy=720*6e4,Ly="openchamber.github-pr-status",By=t=>t==="closed"||t==="merged",Vy=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Eo=(t,e,n)=>`${t}::${e}`,ta=new Map,sa=new Map,So=new Set,Ru=new Map,_y=2;let Fa=0;const eh=[],$y=()=>Fa<_y?(Fa+=1,Promise.resolve()):new Promise(t=>{eh.push(t)}),zy=()=>{const t=eh.shift();if(t){t();return}Fa=Math.max(0,Fa-1)},Ao=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),Oa=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,Kc=t=>{const e=Oa(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},th=(t,e)=>Object.entries(t).filter(([,n])=>Kc(n)===e).map(([n])=>n),Wy=(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}}},na=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},Uy=(t,e,n)=>{const r=th(t,e),o=r.map(d=>na(t[d])).filter(d=>!!d);if(o.length===0)return null;const a=na(t[n]);if(a&&Kc(t[n])===e)return a;const c=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&na(d)));if(c)return na(c);const l=o.find(d=>!!d.remoteName);return l||(o[0]??null)},Hy=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:Oa(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),Gy=t=>({...Ao(),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}),ur=fo()(xc((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:Ao()}})},setParams:(n,r)=>{t(o=>{const a=o.entries[n]??Ao();return{entries:{...o.entries,[n]:Wy(a,r)}}})},startWatching:n=>{if(t(a=>{const c=a.entries[n]??Ao();return{entries:{...a.entries,[n]:{...c,watchers:c.watchers+1}}}}),ta.has(n))return;const r=a=>{const c=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const d=e().entries[n];!d||d.watchers<=0||d.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},a),l=sa.get(n)??[];l.push(c),sa.set(n,l)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),Iy.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 f=Date.now();if(f-a.lastDiscoveryPollAt<Py)return;t(m=>{const u=m.entries[n];return u?{entries:{...m.entries,[n]:{...u,lastDiscoveryPollAt:f}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(By(a.status?.pr?.state))return;const l=Date.now()-a.lastRefreshAt,d=Vy(a.status)?Ry:a.status?.checks&&a.status.checks.state!=="pending"?My:Ey;l<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},Ty);ta.set(n,o)},stopWatching:n=>{t(c=>{const l=c.entries[n];if(!l)return c;const d=Math.max(0,l.watchers-1);return{entries:{...c.entries,[n]:{...l,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const o=ta.get(n);typeof o=="number"&&window.clearInterval(o),ta.delete(n);const a=sa.get(n);a&&a.length>0&&a.forEach(c=>{window.clearTimeout(c)}),sa.delete(n)},refresh:async(n,r)=>{const o=e(),a=o.entries[n],c=Kc(a);if(!a||!c)return;const l=th(o.entries,c),d=l.some(u=>!!o.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const f=Ru.get(c)??0;if(!r?.force&&Date.now()-f<Dy||So.has(c))return;const m=Uy(o.entries,c,n);if(m){if(So.add(c),Ru.set(c,Date.now()),t(u=>{const p={...u.entries};return l.forEach(x=>{const b=p[x];b&&(p[x]={...b,lastRefreshAt:Date.now(),isLoading:r?.silent?b.isLoading:!0,error:null})}),{entries:p}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const p={...u.entries};return l.forEach(x=>{const b=p[x];b&&(p[x]={...b,status:{connected:!1},error:null,isLoading:r?.silent?b.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?b.isInitialStatusResolved:!0})}),{entries:p}}),So.delete(c);return}if(!m.github?.prStatus){t(u=>{const p={...u.entries};return l.forEach(x=>{const b=p[x];b&&(p[x]={...b,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?b.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?b.isInitialStatusResolved:!0})}),{entries:p}}),So.delete(c);return}try{t(p=>({...p,activeRequestCount:p.activeRequestCount+1,totalRequestCount:p.totalRequestCount+1})),await $y();let u;try{u=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force})}finally{zy()}t(p=>{const x={...p.entries};return l.forEach(b=>{const w=x[b];if(!w)return;const g=w.status?.pr,h=u.pr,j=!!(h&&g&&h.number===g.number&&(!h.body||!h.body.trim())&&typeof g.body=="string"&&g.body.trim().length>0)&&h&&g?.body?{...u,pr:{...h,body:g.body}}:u,S=j.resolvedRemoteName??w.resolvedRemoteName??m.remoteName??null,N=Oa(w)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};x[b]={...w,status:j,error:null,isLoading:r?.silent?w.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?w.isInitialStatusResolved:!0,resolvedRemoteName:S,identity:{...N,remoteName:S??N.remoteName??null}}}),{entries:x}})}catch(u){const p=u instanceof Error?u.message:String(u);t(x=>{const b={...x.entries};return l.forEach(w=>{const g=b[w];g&&(b[w]={...g,error:p||"Failed to load PR status",isLoading:r?.silent?g.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?g.isInitialStatusResolved:!0})}),{entries:b}})}finally{So.delete(c),t(u=>({...u,activeRequestCount:Math.max(0,u.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const o=Array.from(new Set(n.map(a=>{const c=a.directory.trim(),l=a.branch.trim();return!c||!l?null:Eo(c,l,a.remoteName??null)}).filter(a=>!!a)));await Zm(o,Fy,a=>e().refresh(a,r))},updateStatus:(n,r)=>{t(o=>{const a=o.entries[n]??Ao();return{entries:{...o.entries,[n]:{...a,status:r(a.status)}}}})}}),{name:Ly,storage:Sp(),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=Oa(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<Oy}).map(([e,n])=>[e,Hy(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([o,a])=>[o,Gy(a)]))}}})),Ky=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"},qy=t=>{const e=Ky(t.status??null),n=t.status?.pr;return!e||!n?.number?null:{number:n.number,visualState:e,prState:n.state,draft:!!n.draft,title:typeof n.title=="string"&&n.title.trim().length>0?n.title:null,url:typeof n.url=="string"&&n.url.trim().length>0?n.url:null,base:typeof n.base=="string"&&n.base.trim().length>0?n.base:null,head:typeof n.head=="string"&&n.head.trim().length>0?n.head:null,checks:t.status?.checks?{state:t.status.checks.state,total:t.status.checks.total,success:t.status.checks.success,failure:t.status.checks.failure,pending:t.status.checks.pending}:null,canMerge:typeof t.status?.canMerge=="boolean"?t.status.canMerge:null,mergeableState:typeof n.mergeableState=="string"?n.mergeableState:null,repo:t.status?.repo?{owner:t.status.repo.owner,repo:t.status.repo.repo}:null}},Yy=t=>`${t.number}:${t.visualState}:${t.prState}:${t.draft}:${t.title??""}:${t.url??""}:${t.base??""}:${t.head??""}:${t.canMerge??""}:${t.mergeableState??""}:${t.checks?.state??""}:${t.checks?.total??""}:${t.checks?.success??""}:${t.checks?.failure??""}:${t.checks?.pending??""}:${t.repo?.owner??""}:${t.repo?.repo??""}`;let Cl=new Map,Eu=new Map;const Qy=t=>{const e=gt.c(2);let n;return e[0]!==t?(n=r=>{const o=new Map,a=new Map;for(const c of t){const l=r.entries[c];if(!l)continue;const d=qy(l);if(!d)continue;const f=Yy(d);o.set(c,f),a.set(c,d)}if(o.size===Cl.size){let c=!0;for(const[l,d]of o)if(Cl.get(l)!==d){c=!1;break}if(c)return Eu}return Cl=o,Eu=a,a},e[0]=t,e[1]=n):n=e[1],ur(n)},Jy=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},Xy=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"},Zy=[2e3,5e3],Mu=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),fi=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},ev=(t,e)=>{const n=fi(t);if(!n||n.includes("->"))return"";if(e){const o=`${e}/`;return n.startsWith(o)?n.slice(o.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},tv=(t,e)=>`${t}::${e}`,qc=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},Al=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const a=t.find(c=>c.name===n);if(a)return a}const r=qc(e.trackingBranch);if(r){const a=r==="origin"?t.find(l=>l.name==="upstream"):null;if(a)return a;const c=t.find(l=>l.name===r);if(c)return c}const o=t.find(a=>a.name==="origin");return o||(t[0]??null)},sv=t=>t.startsWith("pr-"),nv=(t,e)=>{const n=qc(e),r=new Map(t.map(c=>[c.name,c])),o=[],a=c=>{c&&(o.some(l=>l.name===c.name)||o.push(c))};return n&&a(r.get(n)),a(r.get("upstream")),a(r.get("origin")),t.filter(c=>!sv(c.name)).forEach(c=>a(c)),t.forEach(c=>a(c)),o},Dl=new Map,Tl=si;function rv(t,e){const[n,r]=i.useState(null),[o,a]=i.useState([]),c=i.useRef(null);return i.useEffect(()=>{r(null),a([])},[t]),i.useEffect(()=>{if(!t||!e?.repoUpstream||c.current===t)return;c.current=t;let l=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(l||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const f=await e.repoBranches(d.upstream.owner,d.upstream.repo);l||a(f)}catch{}}catch{}})(),()=>{l=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:o}}const iv=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:o=[],remoteBranches:a=[],onGeneratedDescription:c})=>{const{t:l}=yt(),d=Ee(xe=>xe.timeFormatPreference),{github:f}=nr(),m=$i(xe=>xe.status),u=$i(xe=>xe.hasChecked),p=Ee(xe=>xe.setSettingsDialogOpen),x=Ee(xe=>xe.setSettingsPage),b=Ee(xe=>xe.setActiveMainTab),w=ht(xe=>xe.currentSessionId),{isMobile:g,hasTouchInput:h}=zr(),k=i.useCallback(()=>{x("github"),p(!0)},[p,x]),j=i.useMemo(()=>tv(t,e),[t,e]),S=i.useMemo(()=>Dl.get(j)??null,[j]),N=ur(xe=>xe.ensureEntry),C=ur(xe=>xe.setParams),y=ur(xe=>xe.startWatching),P=ur(xe=>xe.stopWatching),_=ur(xe=>xe.refresh),v=ur(xe=>xe.updateStatus),[F,I]=i.useState(()=>S?.title??Mu(e)),[R,B]=i.useState(()=>S?.body??""),[D,W]=i.useState(()=>S?.draft??!1),[U,L]=i.useState(()=>S?.additionalContext??""),[M,ee]=i.useState(()=>{const xe=typeof S?.targetBaseBranch=="string"?fi(S.targetBaseBranch):"";return xe||fi(n)}),[ie,te]=i.useState("squash"),[H,J]=i.useState(!1),[re,oe]=i.useState(!1),[ve,ne]=i.useState(!1),[ye,he]=i.useState(!1),[Fe,z]=i.useState(!1),[K,Y]=i.useState(!1),[me,Ne]=i.useState(null),[Be,_e]=i.useState(""),[Oe,pe]=i.useState(""),[Re,ge]=i.useState(!1),[ce,Ce]=i.useState(!1),[be,ue]=i.useState(()=>Al(o,{selectedRemoteName:S?.selectedRemoteName,trackingBranch:r})),[De,T]=i.useState(!1),{detectedUpstream:V,upstreamBranches:we}=rv(t,f);i.useEffect(()=>{T(!1)},[t]);const E=o.some(xe=>xe.name==="upstream"),fe=!!(t&&e&&n&&(e!==n||(E||V!==null))),$=i.useMemo(()=>Eo(t,e),[t,e]),ke=ur(xe=>xe.entries[$]),Ve=ke?.isLoading??!1,Se=ke?.status??null,q=ke?.error??null,O=ke?.isInitialStatusResolved??!1,se=i.useMemo(()=>{const xe=De?null:be?.name?.trim()||null,tt=new Set;for(const zt of a){const xt=ev(zt,xe);!xt||xt==="HEAD"||tt.add(xt)}if(De)for(const zt of we)zt&&zt!=="HEAD"&&tt.add(zt);const ut=fi(n);ut&&ut!=="HEAD"&&tt.add(ut);const wt=fi(M);return wt&&wt!=="HEAD"&&tt.add(wt),Array.from(tt).sort((zt,xt)=>zt.localeCompare(xt))},[n,a,be?.name,M,we,De]);i.useEffect(()=>{if(o.length===0){be&&ue(null);return}(!be||!o.some(xe=>xe.name===be.name))&&ue(Al(o,{selectedRemoteName:S?.selectedRemoteName,trackingBranch:r}))},[S?.selectedRemoteName,o,be,r]),i.useEffect(()=>{const xe=fi(n);if(!M&&xe){ee(xe);return}if(se.length!==0&&!se.includes(M)){const tt=se.includes(xe)?xe:se[0];tt&&ee(tt)}},[se,n,M]);const[Le,ae]=i.useState(!1),[We,Ye]=i.useState(null),[Qe,st]=i.useState(!1),[pt,jt]=i.useState(new Set),[Et,Rt]=i.useState(!1),[Ut,ts]=i.useState(null),[Kt,is]=i.useState(!1),qt=i.useRef(new Set),Te=i.useRef(null),Ke=i.useRef(!1),rt=i.useRef(new Set),vt=i.useRef([]);i.useEffect(()=>{V&&!E&&T(!0)},[V,E]),i.useEffect(()=>{De&&V?.defaultBranch&&ee(V.defaultBranch)},[De,V?.defaultBranch]);const Je=Se?.pr??null,St=Je?`${t}#${Je.number}`:null,Xe=!!(St&&me===St);i.useEffect(()=>{if(!f?.prContext||!Je||typeof Je.body=="string"&&Je.body.length>0)return;const xe=`${t}#${Je.number}`;if(qt.current.has(xe))return;qt.current.add(xe),Ne(xe);let tt=!1;return f.prContext(t,Je.number,{includeDiff:!1,includeCheckDetails:!1,sourceRepo:Se?.repo??null}).then(ut=>{if(tt)return;const wt=ut?.pr;wt&&v($,zt=>!zt?.pr||zt.pr.number!==Je.number?zt:{...zt,pr:{...zt.pr,body:wt.body||""}})}).catch(()=>{}).finally(()=>{tt||Ne(ut=>ut===xe?null:ut)}),()=>{tt=!0}},[t,f,Je,$,Se?.repo,v]),i.useEffect(()=>{if(!Je){Y(!1),_e(""),pe(""),Te.current=null;return}const xe=Te.current!==null&&Te.current!==Je.number;xe&&Y(!1),(!K||xe)&&(_e(Je.title||""),pe(Je.body||"")),Te.current=Je.number},[K,Je]);const qe=i.useCallback(async()=>{if(!f?.prContext){le.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(Je){ae(!0),jt(new Set),st(!0);try{const xe=await f.prContext(t,Je.number,{includeDiff:!1,includeCheckDetails:!0,sourceRepo:Se?.repo??null});Ye(xe)}catch(xe){const tt=xe instanceof Error?xe.message:String(xe);le.error(l("gitView.pr.toast.loadCheckDetailsFailed"),{description:tt})}finally{st(!1)}}},[t,f,Je,Se?.repo,l]),et=i.useCallback(async()=>{if(!f?.prContext){le.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(Je){Rt(!0),is(!0);try{const xe=await f.prContext(t,Je.number,{includeDiff:!1,includeCheckDetails:!1,sourceRepo:Se?.repo??null});ts(xe)}catch(xe){const tt=xe instanceof Error?xe.message:String(xe);le.error(l("gitView.pr.toast.loadCommentsFailed"),{description:tt})}finally{is(!1)}}},[t,f,Je,Se?.repo,l]),Vt=i.useCallback(xe=>{if(!xe)return"";const tt=Date.parse(xe);return Number.isFinite(tt)?Pc(tt,d,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):xe},[d]),Ct=i.useMemo(()=>{const xe=m?.user?.login;return typeof xe=="string"?xe.trim():""},[m]),Ht=i.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),ss=i.useCallback(xe=>{const tt=Ct.toLowerCase(),ut=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return xe.replace(ut,(wt,zt,xt)=>{const ps=`@${xt}`,cs=xt.toLowerCase();return`${zt}[${ps}](https://github.com/${cs}${tt&&cs===tt?"?oc-self-mention=1":""})`})},[Ct]),Xt=i.useMemo(()=>{const xe=(Ut?.issueComments??[]).map(wt=>({id:`issue-${wt.id}`,body:wt.body||"",authorName:wt.author?.name||wt.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:wt.author?.login||null,avatarUrl:wt.author?.avatarUrl||null,createdAt:wt.createdAt,context:l("gitView.pr.comments.generalContext"),path:null,line:null})),tt=(Ut?.reviewComments??[]).map(wt=>({id:`review-${wt.id}`,body:wt.body||"",authorName:wt.author?.name||wt.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:wt.author?.login||null,avatarUrl:wt.author?.avatarUrl||null,createdAt:wt.createdAt,context:l("gitView.pr.comments.reviewContext"),path:wt.path||null,line:wt.line??null})),ut=[...xe,...tt];return ut.sort((wt,zt)=>{const xt=wt.createdAt?Date.parse(wt.createdAt):0,ps=zt.createdAt?Date.parse(zt.createdAt):0,cs=Number.isFinite(xt)?xt:0,js=Number.isFinite(ps)?ps:0;return cs-js}),ut},[Ut,l]),Ft=i.useCallback(()=>{if(!w)return le.error(l("gitView.pr.toast.noActiveSession"),{description:l("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:xe,currentModelId:tt,currentAgentName:ut,currentVariant:wt}=rs.getState(),zt=Tc.getState().lastUsedProvider,xt=xe||zt?.providerID,ps=tt||zt?.modelID;return!xt||!ps?(le.error(l("gitView.pr.toast.noModelSelected")),null):{sessionId:w,providerID:xt,modelID:ps,currentAgentName:ut??null,currentVariant:wt??null}},[w,l]),_t=i.useCallback((xe,tt,ut,wt)=>{ht.getState().sendMessage(tt,xe.providerID,xe.modelID,xe.currentAgentName??void 0,void 0,void 0,[{text:ut,synthetic:!0},{text:wt,synthetic:!0}],xe.currentVariant??void 0).catch(zt=>{const xt=zt instanceof Error?zt.message:String(zt);le.error(l("gitView.pr.toast.sendMessageFailed"),{description:xt})})},[l]),hs=i.useCallback(xe=>{const tt=xe.status||"unknown",ut=xe.conclusion??void 0,wt=ut?`${tt} / ${ut}`:tt,zt=xe.app?.name||xe.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:xe.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:zt?`${zt} · ${wt}`:wt})]}),xe.detailsUrl?s.jsx(ze,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:xe.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),xe.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:xe.output.title}):null,xe.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:xe.output.summary}):null,xe.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:xe.output.text}):null,Array.isArray(xe.annotations)&&xe.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",xe.annotations.length>20?` (showing 20/${xe.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:xe.annotations.slice(0,20).map((xt,ps)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro text-[var(--status-error)]",children:[xt.title||xt.level||"Issue",xt.path?` · ${xt.path}`:"",typeof xt.startLine=="number"?`:${xt.startLine}`:"",typeof xt.endLine=="number"&&xt.endLine!==xt.startLine?`-${xt.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:xt.message}),xt.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:xt.rawDetails}):null]},`${xt.path||"file"}:${xt.startLine||ps}:${ps}`))})]}):null,xe.job?.steps&&xe.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:xe.job.steps.map((xt,ps)=>{const cs=(xt.conclusion||"").toLowerCase(),js=cs&&!["success","neutral","skipped"].includes(cs),Ss=`${xe.id??"run"}:${xe.job?.jobId??"job"}:${xt.number??ps}:${xt.name}`,Fs=pt.has(Ss);return js?s.jsxs(lo,{open:Fs,children:[s.jsxs("button",{type:"button",onClick:()=>{jt(Bn=>{const sn=new Set(Bn);return sn.has(Ss)?sn.delete(Ss):sn.add(Ss),sn})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(js?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Fs?s.jsx(A,{name:"arrow-down-s",className:"size-4"}):s.jsx(A,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:xt.name}),xt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:xt.conclusion}):null]}),s.jsx(co,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof xt.number=="number"?s.jsxs("div",{children:[l("gitView.pr.checks.stepLabel"),": ",xt.number]}):null,xt.status?s.jsxs("div",{children:[l("gitView.pr.checks.statusLabel"),": ",xt.status]}):null,xt.conclusion?s.jsxs("div",{children:[l("gitView.pr.checks.conclusionLabel"),": ",xt.conclusion]}):null,xt.startedAt?s.jsxs("div",{children:[l("gitView.pr.checks.startedLabel"),": ",Vt(xt.startedAt)]}):null,xt.completedAt?s.jsxs("div",{children:[l("gitView.pr.checks.completedLabel"),": ",Vt(xt.completedAt)]}):null]})})]},Ss):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:xt.name}),xt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:xt.conclusion}):null]},Ss)})})]}):null]})},[pt,Vt,l]),Zt=i.useCallback(async()=>{if(b("chat"),!f?.prContext){le.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Je)return;const xe=Ft();if(xe)try{const tt=await f.prContext(t,Je.number,{includeDiff:!1,includeCheckDetails:!0,sourceRepo:Se?.repo??null}),wt=(tt.checkRuns??[]).filter(js=>{const Ss=typeof js.conclusion=="string"?js.conclusion.toLowerCase():"";return Ss?!["success","neutral","skipped"].includes(Ss):!1});if(wt.length===0){le.message(l("gitView.pr.toast.noFailedChecks"));return}const zt=await Fn("github.pr.checks.review.visible"),xt=await Fn("github.pr.checks.review.instructions"),ps=wt.flatMap(js=>(Array.isArray(js.annotations)?js.annotations:[]).map(Fs=>({run:js.name,level:Fs.level,title:Fs.title,path:Fs.path,startLine:Fs.startLine,endLine:Fs.endLine,message:Fs.message,rawDetails:Fs.rawDetails}))),cs=`GitHub PR failed checks (JSON)
|
|
7
|
+
${JSON.stringify({repo:tt.repo??null,pr:tt.pr??null,failedChecks:wt,failedAnnotations:ps},null,2)}`;_t(xe,zt,xt,cs)}catch(tt){const ut=tt instanceof Error?tt.message:String(tt);le.error(l("gitView.pr.toast.loadChecksFailed"),{description:ut})}},[t,_t,f,Je,Ft,b,Se?.repo,l]),ns=i.useCallback(async()=>{if(b("chat"),!f?.prContext){le.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Je)return;const xe=Ft();if(xe)try{const tt=await f.prContext(t,Je.number,{includeDiff:!1,includeCheckDetails:!1,sourceRepo:Se?.repo??null}),ut=tt.issueComments??[],wt=tt.reviewComments??[];if(ut.length+wt.length===0){le.message(l("gitView.pr.toast.noPrComments"));return}const xt=await Fn("github.pr.comments.review.visible"),ps=await Fn("github.pr.comments.review.instructions"),cs=`GitHub PR comments (JSON)
|
|
8
|
+
${JSON.stringify({repo:tt.repo??null,pr:tt.pr??null,issueComments:ut,reviewComments:wt},null,2)}`;_t(xe,xt,ps,cs)}catch(tt){const ut=tt instanceof Error?tt.message:String(tt);le.error(l("gitView.pr.toast.loadPrCommentsFailed"),{description:ut})}},[t,_t,f,Je,Ft,b,Se?.repo,l]),gs=i.useCallback(async xe=>{Rt(!1),b("chat");const tt=Ft();if(!tt)return;const ut=await Fn("github.pr.comment.single.visible"),wt=await Fn("github.pr.comment.single.instructions"),zt=`GitHub PR comment (JSON)
|
|
9
|
+
${JSON.stringify({repo:Ut?.repo??null,pr:Ut?.pr??Je??null,comment:xe},null,2)}`;_t(tt,ut,wt,zt)},[Ut,_t,Je,Ft,b]),Mt=i.useCallback(async xe=>{await _($,xe)},[$,_]),Bt=i.useCallback(()=>{vt.current.forEach(xe=>{window.clearTimeout(xe)}),vt.current=Zy.map(xe=>window.setTimeout(()=>{Mt({force:!0,silent:!0,markInitialResolved:!0})},xe))},[Mt]);i.useEffect(()=>{if(!f?.prStatus||!fe||o.length<=1||Ke.current||Se?.pr)return;const xe=`${j}::${be?.name??""}`;if(rt.current.has(xe))return;rt.current.add(xe);const tt=nv(o,r).filter(zt=>zt.name!==be?.name);if(tt.length===0)return;let ut=!1;return(async()=>{for(const zt of tt){if(ut)return;try{if(!(await f.prStatus(t,e,zt.name))?.pr)continue;if(ut)return;ue(ps=>ps?.name===zt.name?ps:zt);return}catch{}}})(),()=>{ut=!0}},[e,fe,t,f,o,be?.name,j,Se?.pr,r]),i.useEffect(()=>{N($),C($,{directory:t,branch:e,remoteName:be?.name??null,canShow:fe,github:f,githubAuthChecked:u,githubConnected:m?.connected??null})},[e,fe,t,N,f,u,m?.connected,$,be?.name,C]),i.useEffect(()=>(y($),()=>{P($)}),[$,y,P]),i.useEffect(()=>{const xe=Dl.get(j)??null;I(xe?.title??Mu(e)),B(xe?.body??""),W(xe?.draft??!1),ee(xe?.targetBaseBranch?fi(xe.targetBaseBranch):fi(n));const tt=Al(o,{selectedRemoteName:xe?.selectedRemoteName,trackingBranch:r});ue(ut=>ut?.name===tt?.name?ut:tt)},[n,e,o,j,r]),i.useEffect(()=>{Mt({markInitialResolved:!0})},[$,Mt]),i.useEffect(()=>{!fe||!be?.name||Mt({force:!0,silent:!0,markInitialResolved:!0})},[fe,Mt,be?.name]),i.useEffect(()=>{const xe=Se?.resolvedRemoteName?.trim();if(!xe||Ke.current)return;const tt=o.find(ut=>ut.name===xe);tt&&ue(ut=>ut?.name===tt.name?ut:tt)},[o,Se?.resolvedRemoteName]),i.useEffect(()=>{const xe=Se?.pr?.state==="closed"||Se?.pr?.state==="merged",tt=ke?.lastRefreshAt??0,ut=Date.now()-tt>6e4,wt=!xe&&ut,zt=()=>{wt&&Mt({force:!0,silent:!0})},xt=()=>{document.visibilityState==="visible"&&wt&&Mt({force:!0,silent:!0})};return window.addEventListener("focus",zt),document.addEventListener("visibilitychange",xt),()=>{window.removeEventListener("focus",zt),document.removeEventListener("visibilitychange",xt)}},[Mt,Se?.pr?.state,ke?.lastRefreshAt]),i.useEffect(()=>{u&&m?.connected===!1&&Mt({force:!0,silent:!0,markInitialResolved:!0})},[u,m,Mt]),i.useEffect(()=>{!t||!e||Dl.set(j,{title:F,body:R,draft:D,additionalContext:U,targetBaseBranch:M,selectedRemoteName:be?.name})},[j,F,R,D,U,M,be?.name,t,e]),i.useEffect(()=>{const xe=vt.current;return()=>{xe.forEach(tt=>{window.clearTimeout(tt)}),vt.current=[]}},[]);const $t=i.useCallback(async()=>{if(!H&&t){J(!0);try{const tt={base:De&&V?.defaultBranchSha?V.defaultBranchSha:M,head:e};U&&(tt.context=U);const ut=await fg(t,tt);ut.title?.trim()&&I(ut.title.trim()),ut.body?.trim()&&B(ut.body.trim()),c?.()}catch(xe){const tt=xe instanceof Error?xe.message:String(xe);le.error(l("gitView.pr.toast.generateDescriptionFailed"),{description:tt})}finally{J(!1)}}},[U,e,V?.defaultBranchSha,t,H,c,M,l,De]),os=i.useCallback(async()=>{if(!f?.prCreate){le.error(l("gitView.pr.toast.githubApiUnavailable"));return}const xe=F.trim();if(!xe){le.error(l("gitView.pr.toast.titleRequired"));return}const tt=M.trim();if(!tt){le.error(l("gitView.pr.toast.baseBranchRequired"));return}if(!De&&tt===e){le.error(l("gitView.pr.toast.baseMustDifferFromHead"));return}oe(!0);try{const ut=qc(r),wt=De&&V,zt=await f.prCreate({directory:t,title:xe,head:e,base:tt,...R.trim()?{body:R}:{},draft:D,...wt?{targetRepo:{owner:V.owner,repo:V.repo},headRemote:"origin"}:{...be?{remote:be.name}:{},...ut&&ut!==be?.name?{headRemote:ut}:{}}});le.success(l("gitView.pr.toast.prCreated")),v($,xt=>xt&&{...xt,pr:zt}),await Mt({force:!0}),Bt()}catch(ut){const wt=ut instanceof Error?ut.message:String(ut);le.error(l("gitView.pr.toast.createPrFailed"),{description:wt})}finally{oe(!1)}},[R,e,V,t,D,f,$,Mt,Bt,be,M,F,r,v,De,l]),Gt=i.useCallback(async xe=>{if(!f?.prMerge){le.error(l("gitView.pr.toast.githubApiUnavailable"));return}he(!0);try{const tt=await f.prMerge({directory:t,number:xe.number,method:ie});tt.merged?le.success(l("gitView.pr.toast.prMerged")):le.message(l("gitView.pr.toast.prNotMerged"),{description:tt.message||l("gitView.pr.notMergeable")}),await Mt({force:!0}),Bt()}catch(tt){const ut=tt instanceof Error?tt.message:String(tt);le.error(l("gitView.pr.toast.mergeFailed"),{description:ut}),xe.url&&Tl(xe.url)}finally{he(!1)}},[t,f,ie,Mt,Bt,l]),Me=i.useCallback(async xe=>{if(!f?.prReady){le.error(l("gitView.pr.toast.githubApiUnavailable"));return}z(!0);try{await f.prReady({directory:t,number:xe.number}),le.success(l("gitView.pr.toast.markedReady")),await Mt({force:!0}),Bt()}catch(tt){const ut=tt instanceof Error?tt.message:String(tt);le.error(l("gitView.pr.toast.markReadyFailed"),{description:ut}),xe.url&&Tl(xe.url)}finally{z(!1)}},[t,f,Mt,Bt,l]),ft=i.useCallback(async xe=>{if(!f?.prUpdate){le.error(l("gitView.pr.toast.githubApiUnavailable"));return}const tt=Be.trim();if(!tt){le.error(l("gitView.pr.toast.titleRequired"));return}ne(!0);try{const ut=await f.prUpdate({directory:t,number:xe.number,title:tt,body:Oe});v($,wt=>wt&&{...wt,pr:{...wt.pr??xe,...ut}}),Y(!1),le.success(l("gitView.pr.toast.prUpdated")),await Mt({force:!0}),Bt()}catch(ut){const wt=ut instanceof Error?ut.message:String(ut);le.error(l("gitView.pr.toast.updatePrFailed"),{description:wt})}finally{ne(!1)}},[t,Oe,Be,f,$,Mt,Bt,v,l]);if(!fe)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:l("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pullRequest.availableOnFeatureBranches")})]})});const at=Se?.repo?.url||null,Nt=De&&V?.url?V.url:at,Pt=Se?.checks??null,es=!!Se?.canMerge,xs=!!Se?.connected,Yt=u&&Se?.connected===!1,Lt=Xy(Se),Es=Lt?`var(--pr-${Lt})`:"var(--status-info)",ms=Lt==="draft"?"git-pr-draft":Lt==="merged"?"git-merge":Lt==="closed"?"git-close-pull-request":"git-pull-request",Ns=Je?[`${Je.state}${Je.draft?" (draft)":""}`,Je.mergeable===!1?l("gitView.pr.notMergeable"):null,Je.state==="open"&&typeof Je.mergeableState=="string"&&Je.mergeableState&&Je.mergeableState!=="unknown"?Je.mergeableState:null].filter(Boolean).join(" · "):"",Us=Pt?Pt.total>0?`${Pt.success}/${Pt.total} ${l("gitView.pr.checks.label")}`:`${Pt.state} ${l("gitView.pr.checks.label")}`:"";return s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[Je?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background/70 hover:bg-interactive-hover/60",onClick:()=>{Tl(Je.url)},"aria-label":l("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(A,{name:ms,className:"size-4 shrink-0",style:{color:Es}})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(A,{name:ms,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:l("gitView.pullRequest.title")}),Je?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",Je.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ve?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-5 items-center justify-center rounded hover:bg-interactive-hover/60 disabled:opacity-40",disabled:Ve,onClick:()=>{Mt({force:!0})},"aria-label":l("gitView.pr.actions.refreshAria"),children:s.jsx(A,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.refresh")})})]})]})]}),Je?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:Es},children:Ns}),Pt?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${Jy(Pt.state)}`}),Us]}):null,r&&be&&r.split("/")[0]!==be.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",be.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Yt?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.pr.githubNotConnected")}),s.jsx(ze,{variant:"outline",size:"sm",onClick:k,className:"w-fit",children:l("gitView.pr.actions.openSettings")})]}):null,q?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:q}),Nt?s.jsx(ze,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:Nt,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!Je&&!O&&!q&&!Yt?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),l("gitView.pr.checkingStatus")]}):Je?s.jsx("div",{className:"flex flex-col gap-2",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[K?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ln,{value:Be,onChange:xe=>_e(xe.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h}),s.jsx(Oi,{value:Oe,onChange:xe=>pe(xe.target.value),className:"min-h-[120px] bg-background/80",placeholder:l("gitView.pr.placeholder.description"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:Je.title}),Je.body?.trim()?s.jsx(ao,{content:Je.body,className:"typography-markdown-body text-muted-foreground break-words mt-1",enableFileReferences:!1}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:l(Xe?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),es&&Je.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.draftMustBeReady")}):null,es?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.noMergePermission")})]}),s.jsxs("div",{className:"order-first w-full flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Je.state==="open"?K?s.jsxs(s.Fragment,{children:[s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{Y(!1),_e(Je.title||""),pe(Je.body||"")},disabled:ve,"aria-label":l("gitView.pr.actions.cancelEditingAria"),children:s.jsx(A,{name:"close",className:"size-4"})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>ft(Je),disabled:ve||!Be.trim(),"aria-label":l("gitView.pr.actions.savePrAria"),children:ve?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"check",className:"size-4"})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.savePr")})})]})]}):s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Y(!0),"aria-label":l("gitView.pr.actions.editPrAria"),children:s.jsx(A,{name:"edit",className:"size-4"})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.editPr")})})]}):null,Pt?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:qe,disabled:Qe,"aria-label":l("gitView.pr.actions.openChecksAria"),children:Qe?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"information",className:"size-4"})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.openChecks")})})]}):null,Pt?.failure?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:Zt,"aria-label":l("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(A,{name:"error-warning",className:"size-4"})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:et,"aria-label":l("gitView.pr.actions.openCommentsAria"),children:s.jsx(A,{name:"chat-4",className:"size-4"})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.openComments")})})]}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:ns,"aria-label":l("gitView.pr.actions.shareCommentsAria"),children:s.jsx(A,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.shareComments")})})]}),es&&Je.draft&&Je.state==="open"?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Me(Je),disabled:Fe||ye||ve||K,"aria-label":l("gitView.pr.actions.markReadyAria"),children:Fe?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:es?s.jsxs(s.Fragment,{children:[s.jsxs(Un,{value:ie,onValueChange:xe=>te(xe),disabled:ye||Je.state!=="open",children:[s.jsx(Hn,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(Dn,{})}),s.jsxs(Gn,{children:[s.jsx(Bs,{value:"squash",children:l("gitView.pr.mergeMethod.squash")}),s.jsx(Bs,{value:"merge",children:l("gitView.pr.mergeMethod.merge")}),s.jsx(Bs,{value:"rebase",children:l("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>Gt(Je),disabled:ye||Fe||Je.state!=="open"||Je.draft||ve||K,"aria-label":l("gitView.pr.actions.mergePrAria"),children:ye?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-merge",className:"size-4"})})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.mergePr")})})]})]}):null})]})]})}):s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",M," ",s.jsxs("span",{className:"opacity-60",children:["(",De&&V?"upstream":"remote",")"]})]})]}),Nt?s.jsx(ze,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:Nt,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{name:"external-link",className:"size-4"}),l("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.title")}),s.jsx(Ln,{value:F,onChange:xe=>I(xe.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.baseBranch")}),se.length>0?s.jsxs(Un,{value:M,onValueChange:ee,children:[s.jsx(Hn,{className:"h-9",children:s.jsx(Dn,{placeholder:l("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(Gn,{children:se.map(xe=>s.jsx(Bs,{value:xe,children:xe},xe))})]}):s.jsx(Ln,{value:M,onChange:xe=>ee(xe.target.value),placeholder:l("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.description")}),s.jsx(Oi,{value:R,onChange:xe=>B(xe.target.value),className:"min-h-[110px]",placeholder:l("gitView.pr.placeholder.whatChanged"),autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:h})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":D,onClick:()=>W(xe=>!xe),onKeyDown:xe=>{(xe.key===" "||xe.key==="Enter")&&(xe.preventDefault(),W(tt=>!tt))},children:[s.jsx(Vr,{size:"sm",checked:D,onChange:xe=>W(xe),ariaLabel:l("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:l("gitView.pr.field.draft")})]}),g?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.optional")}),s.jsx(ze,{variant:"outline",size:"sm",onClick:()=>Ce(!0),children:U.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),U.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:l("gitView.pr.additionalContext.added")})})]}):s.jsxs(lo,{open:Re,onOpenChange:ge,children:[s.jsxs(Ho,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:Re?l("gitView.pr.actions.hide"):U.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),s.jsx(co,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(Oi,{value:U,onChange:xe=>L(xe.target.value),className:"min-h-[100px] bg-transparent",placeholder:l("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(Ya,{open:ce,onClose:()=>Ce(!1),title:l("gitView.pr.additionalContext.title"),footer:s.jsx(ze,{size:"sm",onClick:()=>Ce(!1),className:"w-full",children:l("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(Oi,{value:U,onChange:xe=>L(xe.target.value),className:"min-h-[200px] bg-transparent",placeholder:l("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ze,{variant:"outline",size:"sm",onClick:$t,disabled:H||re,children:[H?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"ai-generate-2",className:"size-4 text-primary"}),l("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(ze,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:os,disabled:re||!xs||!M.trim()||!De&&M.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:re?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:l("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(_s,{open:Le,onOpenChange:ae,children:s.jsxs(Vs,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(tn,{children:[s.jsxs(Gs,{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-pull-request",className:"h-5 w-5"}),l("gitView.pr.checkDetails.title")]}),s.jsx(dn,{children:Je?l("gitView.pr.numberLabel",{number:Je.number}):l("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[Qe?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"}),l("gitView.loading.loading")]}):null,Qe?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(We?.checkRuns)&&We?.checkRuns.length>0?We.checkRuns.map((xe,tt)=>{const ut=`${xe.id??"run"}:${xe.job?.jobId??"job"}:${xe.name}:${tt}`;return s.jsx("div",{className:"p-1",children:hs(xe)},ut)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:l("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(_s,{open:Et,onOpenChange:Rt,children:s.jsxs(Vs,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(tn,{children:s.jsxs(Gs,{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-pull-request",className:"h-5 w-5"}),l("gitView.pr.comments.title"),Je?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l("gitView.pr.numberLabel",{number:Je.number})}):null]})}),s.jsxs(Qa,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[Kt?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"}),l("gitView.loading.loading")]}):null,Kt?null:s.jsx("div",{className:"space-y-4",children:Xt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Xt.map((xe,tt)=>{const ut=(xe.authorName||"?").charAt(0).toUpperCase(),wt=tt===Xt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[wt?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:xe.avatarUrl?s.jsx("img",{src:xe.avatarUrl,alt:xe.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:ut})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[xe.authorName,xe.authorLogin&&xe.authorLogin!==xe.authorName?` · @${xe.authorLogin}`:""]}),xe.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:Vt(xe.createdAt)}):null,s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsxs(ze,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{gs(xe)},"aria-label":l("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(A,{name:"ai-generate-2",className:"size-3.5"}),l("gitView.pr.actions.sendToAgent")]})}),s.jsx(Tt,{children:s.jsx("p",{children:l("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[xe.context,xe.path?` · ${xe.path}`:"",xe.line?`:${xe.line}`:""]}),s.jsx(ao,{content:ss(xe.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Ht].filter(Boolean).join(" "),enableFileReferences:!1})]})]},xe.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:l("gitView.pr.comments.empty")})})]})]})})]})},ov=t=>{const e=gt.c(150),{open:n,onOpenChange:r,conflictFiles:o,directory:a,operation:c,onAbort:l,onClearState:d}=t;let f;e[0]!==o?(f=o===void 0?[]:o,e[0]=o,e[1]=f):f=e[1];const m=f,{t:u}=yt(),p=ht(av),x=ht(lv),b=xi(cv),w=xi(dv),g=Ee(uv),[h,k]=i.useState(!1),[j,S]=i.useState(null),[N,C]=i.useState(null);let y,P;e[2]!==a||e[3]!==n||e[4]!==u?(y=()=>{!n||!a||(k(!0),C(null),S(null),mg(a).then(De=>{S(De)}).catch(De=>{const T=De instanceof Error?De.message:u("gitView.conflict.loadFailed");C(T)}).finally(()=>{k(!1)}))},P=[n,a,u],e[2]=a,e[3]=n,e[4]=u,e[5]=y,e[6]=P):(y=e[5],P=e[6]),i.useEffect(y,P);let _;e[7]!==j||e[8]!==a||e[9]!==c?(_=async()=>{if(!j)return null;const De=c==="merge"?"merge":"rebase",T=j.headInfo||(c==="merge"?"MERGE_HEAD":"REBASE_HEAD"),V=c==="merge"?"git commit --no-edit":"git rebase --continue",we=await Fn("git.conflict.resolve.visible",{operation_label:De,head_ref:T}),E=await Fn("git.conflict.resolve.instructions",{operation_label:De,directory:a,operation:c,head_info:j.headInfo||"N/A",continue_cmd:V}),de=`${De} conflict context (JSON)
|
|
10
|
+
${JSON.stringify({directory:a,operation:j.operation,headInfo:j.headInfo,statusPorcelain:j.statusPorcelain,unmergedFiles:j.unmergedFiles,diff:j.diff},null,2)}`;return{visibleText:we,instructionsText:E,payloadText:de}},e[7]=j,e[8]=a,e[9]=c,e[10]=_):_=e[10];const v=_;let F;e[11]!==l||e[12]!==r?(F=()=>{l(),r(!1)},e[11]=l,e[12]=r,e[13]=F):F=e[13];const I=F;let R;e[14]!==d||e[15]!==r?(R=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=R):R=e[16];const B=R;let D;e[17]!==v||e[18]!==x||e[19]!==d||e[20]!==r||e[21]!==g||e[22]!==b||e[23]!==w||e[24]!==u?(D=async()=>{const De=await v();if(!De){le.error(u("gitView.conflict.noDetailsAvailable"));return}if(!x){le.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}b(De.visibleText,"replace"),w([{text:De.instructionsText,synthetic:!0},{text:De.payloadText,synthetic:!0}]),g("chat"),d?.(),r(!1)},e[17]=v,e[18]=x,e[19]=d,e[20]=r,e[21]=g,e[22]=b,e[23]=w,e[24]=u,e[25]=D):D=e[25];const W=D;let U;e[26]!==v||e[27]!==a||e[28]!==d||e[29]!==r||e[30]!==p||e[31]!==g||e[32]!==u?(U=async()=>{const De=await v();if(!De){le.error(u("gitView.conflict.noDetailsAvailable"));return}p({directoryOverride:a,initialPrompt:De.visibleText,syntheticParts:[{text:De.instructionsText,synthetic:!0},{text:De.payloadText,synthetic:!0}]}),g("chat"),d?.(),r(!1)},e[26]=v,e[27]=a,e[28]=d,e[29]=r,e[30]=p,e[31]=g,e[32]=u,e[33]=U):U=e[33];const L=U;let M,ee,ie,te,H,J,re,oe,ve,ne,ye,he,Fe,z,K,Y,me,Ne,Be,_e,Oe,pe;if(e[34]!==j||e[35]!==m||e[36]!==x||e[37]!==I||e[38]!==B||e[39]!==W||e[40]!==L||e[41]!==h||e[42]!==N||e[43]!==r||e[44]!==n||e[45]!==c||e[46]!==u){const De=u(c==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),T=j?.unmergedFiles||m;ie=_s,Oe=n,pe=r,ee=Vs,_e="max-w-md w-[calc(100vw-2rem)]",z="flex flex-col gap-4 overflow-hidden";let V;e[69]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(A,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=V):V=e[69];const we=s.jsxs("div",{className:"flex items-center gap-2",children:[V,s.jsx(Gs,{children:u("gitView.conflict.detectedTitle",{operation:De})})]});let E;e[70]!==c||e[71]!==u?(E=u("gitView.conflict.detectedDescription",{operation:c}),e[70]=c,e[71]=u,e[72]=E):E=e[72];let de;e[73]!==E?(de=s.jsx(dn,{children:E}),e[73]=E,e[74]=de):de=e[74],e[75]!==we||e[76]!==de?(K=s.jsxs(tn,{children:[we,de]}),e[75]=we,e[76]=de,e[77]=K):K=e[77],e[78]!==h||e[79]!==u?(Y=h&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:u("gitView.conflict.loading")})]}),e[78]=h,e[79]=u,e[80]=Y):Y=e[80],e[81]!==N||e[82]!==u?(me=N&&s.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:u("gitView.conflict.errorLoadingDetails",{message:N})}),e[81]=N,e[82]=u,e[83]=me):me=e[83],e[84]!==T||e[85]!==u?(Ne=T.length>0&&s.jsxs("div",{className:"space-y-2 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.conflictedFiles")}),s.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:T.length})]}),s.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:s.jsx("ul",{className:"space-y-1",children:T.map(fv)})})]}),e[84]=T,e[85]=u,e[86]=Ne):Ne=e[86],e[87]!==j||e[88]!==u?(Be=j?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.headInfo")}),s.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:j.headInfo})]}),e[87]=j,e[88]=u,e[89]=Be):Be=e[89],ye="flex flex-col gap-2 pt-2";let fe;e[90]!==L?(fe=()=>{L()},e[90]=L,e[91]=fe):fe=e[91];const $=h||!j;let ke;e[92]!==h?(ke=h?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"add",className:"size-4"}),e[92]=h,e[93]=ke):ke=e[93];let Ve;e[94]!==u?(Ve=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=Ve):Ve=e[95],e[96]!==fe||e[97]!==$||e[98]!==ke||e[99]!==Ve?(he=s.jsxs(ze,{variant:"default",onClick:fe,disabled:$,className:"w-full gap-2",children:[ke,Ve]}),e[96]=fe,e[97]=$,e[98]=ke,e[99]=Ve,e[100]=he):he=e[100];let Se;e[101]!==W?(Se=()=>{W()},e[101]=W,e[102]=Se):Se=e[102];const q=h||!j||!x;let O;e[103]!==h?(O=h?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"chat-1",className:"size-4"}),e[103]=h,e[104]=O):O=e[104];let se;e[105]!==u?(se=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=se):se=e[106],e[107]!==Se||e[108]!==q||e[109]!==O||e[110]!==se?(Fe=s.jsxs(ze,{variant:"outline",onClick:Se,disabled:q,className:"w-full gap-2",children:[O,se]}),e[107]=Se,e[108]=q,e[109]=O,e[110]=se,e[111]=Fe):Fe=e[111],ve="flex gap-2 pt-1";let Le;e[112]!==u?(Le=u("gitView.conflict.continueLater"),e[112]=u,e[113]=Le):Le=e[113],e[114]!==B||e[115]!==Le?(ne=s.jsx(ze,{variant:"ghost",size:"sm",onClick:B,className:"flex-1",children:Le}),e[114]=B,e[115]=Le,e[116]=ne):ne=e[116],M=ze,te="destructive",H="sm",J=I,re="flex-1",oe=u("gitView.conflict.abortOperation",{operation:De}),e[34]=j,e[35]=m,e[36]=x,e[37]=I,e[38]=B,e[39]=W,e[40]=L,e[41]=h,e[42]=N,e[43]=r,e[44]=n,e[45]=c,e[46]=u,e[47]=M,e[48]=ee,e[49]=ie,e[50]=te,e[51]=H,e[52]=J,e[53]=re,e[54]=oe,e[55]=ve,e[56]=ne,e[57]=ye,e[58]=he,e[59]=Fe,e[60]=z,e[61]=K,e[62]=Y,e[63]=me,e[64]=Ne,e[65]=Be,e[66]=_e,e[67]=Oe,e[68]=pe}else M=e[47],ee=e[48],ie=e[49],te=e[50],H=e[51],J=e[52],re=e[53],oe=e[54],ve=e[55],ne=e[56],ye=e[57],he=e[58],Fe=e[59],z=e[60],K=e[61],Y=e[62],me=e[63],Ne=e[64],Be=e[65],_e=e[66],Oe=e[67],pe=e[68];let Re;e[117]!==M||e[118]!==te||e[119]!==H||e[120]!==J||e[121]!==re||e[122]!==oe?(Re=s.jsx(M,{variant:te,size:H,onClick:J,className:re,children:oe}),e[117]=M,e[118]=te,e[119]=H,e[120]=J,e[121]=re,e[122]=oe,e[123]=Re):Re=e[123];let ge;e[124]!==ve||e[125]!==ne||e[126]!==Re?(ge=s.jsxs("div",{className:ve,children:[ne,Re]}),e[124]=ve,e[125]=ne,e[126]=Re,e[127]=ge):ge=e[127];let ce;e[128]!==ye||e[129]!==he||e[130]!==Fe||e[131]!==ge?(ce=s.jsxs("div",{className:ye,children:[he,Fe,ge]}),e[128]=ye,e[129]=he,e[130]=Fe,e[131]=ge,e[132]=ce):ce=e[132];let Ce;e[133]!==z||e[134]!==K||e[135]!==Y||e[136]!==me||e[137]!==Ne||e[138]!==Be||e[139]!==ce?(Ce=s.jsxs("div",{className:z,children:[K,Y,me,Ne,Be,ce]}),e[133]=z,e[134]=K,e[135]=Y,e[136]=me,e[137]=Ne,e[138]=Be,e[139]=ce,e[140]=Ce):Ce=e[140];let be;e[141]!==ee||e[142]!==_e||e[143]!==Ce?(be=s.jsx(ee,{className:_e,children:Ce}),e[141]=ee,e[142]=_e,e[143]=Ce,e[144]=be):be=e[144];let ue;return e[145]!==ie||e[146]!==Oe||e[147]!==pe||e[148]!==be?(ue=s.jsx(ie,{open:Oe,onOpenChange:pe,children:be}),e[145]=ie,e[146]=Oe,e[147]=pe,e[148]=be,e[149]=ue):ue=e[149],ue};function av(t){return t.openNewSessionDraft}function lv(t){return t.currentSessionId}function cv(t){return t.setPendingInputText}function dv(t){return t.setPendingSyntheticParts}function uv(t){return t.setActiveMainTab}function fv(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const mv=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:o})=>{const{t:a}=yt(),[c,l]=i.useState(!0),[d,f]=i.useState(!1),m=a(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{f(!0);try{await o(c),e(!1)}catch(x){const b=x instanceof Error?x.message:`Failed to ${n}`;le.error(b)}finally{f(!1)}},p=()=>{d||e(!1)};return s.jsx(_s,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(Vs,{className:"max-w-md",children:[s.jsxs(tn,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(Gs,{children:a("gitView.stash.title")})]}),s.jsx(dn,{children:a("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:a("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:a("gitView.stash.stepStash")}),s.jsxs("li",{children:[a(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",a(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),c&&s.jsx("li",{children:a("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(Vr,{checked:c,onChange:l,disabled:d,ariaLabel:a("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&l(!c),children:a("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(xr,{className:"gap-2",children:[s.jsx(ze,{variant:"ghost",size:"sm",onClick:p,disabled:d,children:a("gitView.common.cancel")}),s.jsx(ze,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.common.processing")]}):a("gitView.stash.confirmButton",{operation:m})})]})]})})},hv=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:o,hasUnresolvedConflicts:a=!1,isLoading:c=!1})=>{const{t:l}=yt(),[d,f]=i.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),p=m?"merge":u?"rebase":null;if(!p)return null;const x=async()=>{f("continue");try{await n()}finally{f(null)}},b=async()=>{f("abort");try{await r()}finally{f(null)}},w=d!==null,g=l(p==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),h=p==="merge"?"git-merge":"git-branch";let k="";return t?k=t.message?l("gitView.operation.mergingMessage",{message:t.message}):l("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(k=e.headName?l("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):l("gitView.operation.rebaseInProgress")),s.jsx("div",{className:"bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.jsx(A,{name:h,className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:l("gitView.operation.inProgressTitle",{operation:g})}),k&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:k})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a&&o&&s.jsxs(ze,{variant:"outline",size:"sm",onClick:o,disabled:w||c,className:"gap-1.5",children:[s.jsx(A,{name:"sparkling",className:"size-4"}),l("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(ze,{variant:"ghost",size:"sm",onClick:b,disabled:w||c,className:"gap-1.5",children:[d==="abort"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"close",className:"size-4"}),l("gitView.operation.abort")]}),!a&&s.jsxs(ze,{variant:"default",size:"sm",onClick:x,disabled:w||c,className:"gap-1.5",children:[d==="continue"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"check",className:"size-4"}),l("gitView.operation.continue")]})]}),a&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:l("gitView.operation.resolveConflictsHint")})]})})},pv=t=>{const e=gt.c(104),{currentBranch:n,localBranches:r,remoteBranches:o,onMerge:a,onRebase:c,disabled:l,isOperating:d,operationLogs:f,onOperationComplete:m,mode:u,defaultTargetBranch:p}=t,x=l===void 0?!1:l,b=d===void 0?!1:d,w=f===void 0?[]:f,g=u===void 0?"dialog":u,{t:h}=yt(),[k,j]=i.useState(!1),[S,N]=i.useState("merge"),[C,y]=i.useState(null),[P,_]=i.useState(!1),[v,F]=i.useState(""),I=i.useRef(null),R=i.useRef(null),B=x||b,D=n||h("gitView.branch.currentBranchFallback"),W=w.length>0&&w.every(gv),U=w.some(xv);let L;e[0]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{R.current&&(R.current.scrollTop=R.current.scrollHeight)},e[0]=L):L=e[0],i.useEffect(L,[w]);let M;if(e[1]!==v||e[2]!==n||e[3]!==r||e[4]!==o){e:{const Se=v.toLowerCase();let q;e[6]!==o?(q=new Set(o.map(bv).filter(Boolean)),e[6]=o,e[7]=q):q=e[7];const O=q;let se;e[8]!==n||e[9]!==O?(se=ae=>ae!==n&&!O.has(ae),e[8]=n,e[9]=O,e[10]=se):se=e[10];const Le=r.filter(se);if(!Se){M=Le;break e}M=Le.filter(ae=>ae.toLowerCase().includes(Se))}e[1]=v,e[2]=n,e[3]=r,e[4]=o,e[5]=M}else M=e[5];const ee=M;let ie;if(e[11]!==v||e[12]!==o){e:{const Se=v.toLowerCase();if(!Se){ie=o;break e}ie=o.filter(q=>q.toLowerCase().includes(Se))}e[11]=v,e[12]=o,e[13]=ie}else ie=e[13];const te=ie;let H;e[14]!==p||e[15]!==r||e[16]!==o?(H=()=>p&&(o.includes(p)||r.includes(p))?p:null,e[14]=p,e[15]=r,e[16]=o,e[17]=H):H=e[17];const J=H;let re;e[18]!==J||e[19]!==j?(re=()=>{j(!0),y(J()),N("merge"),F("")},e[18]=J,e[19]=j,e[20]=re):re=e[20];const oe=re;let ve;e[21]===Symbol.for("react.memo_cache_sentinel")?(ve=Se=>{y(Se),_(!1),F("")},e[21]=ve):ve=e[21];const ne=ve;let ye;e[22]!==a||e[23]!==c||e[24]!==S||e[25]!==C?(ye=()=>{C&&(S==="merge"?a(C):c(C))},e[22]=a,e[23]=c,e[24]=S,e[25]=C,e[26]=ye):ye=e[26];const he=ye;let Fe;e[27]!==b||e[28]!==j?(Fe=()=>{b||(y(null),N("merge"),F(""),j(!1))},e[27]=b,e[28]=j,e[29]=Fe):Fe=e[29];const z=Fe,K=()=>{b&&!W||(W&&m?.(),y(null),N("merge"),F(""),j(!1))};let Y,me;e[30]!==P?(Y=()=>{P||F("")},me=[P],e[30]=P,e[31]=Y,e[32]=me):(Y=e[31],me=e[32]),i.useEffect(Y,me);let Ne,Be;e[33]!==g||e[34]!==J||e[35]!==C?(Ne=()=>{g!=="inline"||C||y(J())},Be=[g,J,C],e[33]=g,e[34]=J,e[35]=C,e[36]=Ne,e[37]=Be):(Ne=e[36],Be=e[37]),i.useEffect(Ne,Be);const pe=b?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:R,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:w.map(wv)})}),W?g==="dialog"?s.jsx(xr,{children:s.jsx(ze,{variant:"default",size:"sm",onClick:K,children:h(U?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(ze,{variant:"default",size:"sm",onClick:K,children:h(U?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:h("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>N("merge"),className:Pe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-merge",className:Pe("size-4",S==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:Pe("typography-ui-label",S==="merge"?"text-foreground":"text-muted-foreground"),children:h("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:h("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>N("rebase"),className:Pe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-branch",className:Pe("size-4",S==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:Pe("typography-ui-label",S==="rebase"?"text-foreground":"text-muted-foreground"),children:h("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:h("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:S==="merge"?h("gitView.branch.branchToMergeInto",{branch:D}):h("gitView.branch.branchToRebaseOnto")}),s.jsxs(en,{open:P,onOpenChange:_,modal:!1,children:[s.jsx(Xs,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:Pe("truncate",!C&&"text-muted-foreground"),children:C||h("gitView.branch.selectBranch")}),s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(Zs,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(Ha,{className:"h-full min-h-0",children:[s.jsx(Ga,{ref:I,placeholder:h("gitView.branch.searchPlaceholder"),value:v,onValueChange:F,onKeyDown:yv}),s.jsxs(Ka,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(qa,{children:h("gitView.branch.empty")}),ee.length>0&&s.jsx(Qr,{heading:h("gitView.branch.localBranches"),children:ee.map(Se=>s.jsx(Jr,{onSelect:()=>ne(Se),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Se})},`local-${Se}`))}),ee.length>0&&te.length>0?s.jsx(hg,{}):null,te.length>0&&s.jsx(Qr,{heading:h("gitView.branch.remoteBranches"),children:te.map(Se=>s.jsx(Jr,{onSelect:()=>ne(Se),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Se})},`remote-${Se}`))})]})]})})]})]}),C?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:S==="merge"?s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:C})," ",h("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:D})]}):s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:D})," ",h("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:C})]})})}):null,g==="dialog"?s.jsxs(xr,{className:"gap-2 pt-1",children:[s.jsx(ze,{variant:"ghost",size:"sm",onClick:z,children:h("gitView.common.cancel")}),s.jsx(ze,{variant:"default",size:"sm",onClick:he,disabled:!C,className:"gap-1.5",children:S==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"git-merge",className:"size-4"}),h("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"git-branch",className:"size-4"}),h("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ze,{variant:"destructive",size:"sm",onClick:z,disabled:B,children:h("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(ze,{variant:"default",size:"sm",onClick:he,disabled:B||!C,children:h(S==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(g==="inline"){let Se;e[38]!==h?(Se=h("gitView.branch.updateTitle"),e[38]=h,e[39]=Se):Se=e[39];let q;e[40]!==Se?(q=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:Se}),e[40]=Se,e[41]=q):q=e[41];let O;e[42]!==h?(O=h("gitView.branch.updateDescriptionPrefix"),e[42]=h,e[43]=O):O=e[43];let se;e[44]!==D?(se=s.jsx("span",{className:"font-mono text-foreground",children:D}),e[44]=D,e[45]=se):se=e[45];let Le;e[46]!==O||e[47]!==se?(Le=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[O," ",se,"."]}),e[46]=O,e[47]=se,e[48]=Le):Le=e[48];let ae;e[49]!==q||e[50]!==Le?(ae=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[q,Le]})}),e[49]=q,e[50]=Le,e[51]=ae):ae=e[51];let We;e[52]!==pe?(We=s.jsx("div",{className:"pt-3",children:pe}),e[52]=pe,e[53]=We):We=e[53];let Ye;return e[54]!==ae||e[55]!==We?(Ye=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[ae,We]}),e[54]=ae,e[55]=We,e[56]=Ye):Ye=e[56],Ye}let Re;e[57]!==b?(Re=b?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-merge",className:"size-4"}),e[57]=b,e[58]=Re):Re=e[58];let ge;e[59]!==h?(ge=h("gitView.branch.mergeRebase"),e[59]=h,e[60]=ge):ge=e[60];let ce;e[61]!==ge?(ce=s.jsx("span",{children:ge}),e[61]=ge,e[62]=ce):ce=e[62];let Ce;e[63]!==oe||e[64]!==B||e[65]!==Re||e[66]!==ce?(Ce=s.jsx(Dt,{asChild:!0,children:s.jsxs(ze,{variant:"outline",size:"sm",className:"gap-1.5",onClick:oe,disabled:B,children:[Re,ce]})}),e[63]=oe,e[64]=B,e[65]=Re,e[66]=ce,e[67]=Ce):Ce=e[67];let be;e[68]!==h?(be=h("gitView.branch.mergeRebaseTooltip"),e[68]=h,e[69]=be):be=e[69];let ue;e[70]!==be?(ue=s.jsx(Tt,{sideOffset:8,children:be}),e[70]=be,e[71]=ue):ue=e[71];let De;e[72]!==Ce||e[73]!==ue?(De=s.jsxs(At,{children:[Ce,ue]}),e[72]=Ce,e[73]=ue,e[74]=De):De=e[74];let T;e[75]!==K||e[76]!==j?(T=Se=>{Se?j(!0):K()},e[75]=K,e[76]=j,e[77]=T):T=e[77];let V;e[78]!==h?(V=h("gitView.branch.updateTitle"),e[78]=h,e[79]=V):V=e[79];let we;e[80]!==V?(we=s.jsx(Gs,{children:V}),e[80]=V,e[81]=we):we=e[81];let E;e[82]!==U||e[83]!==b||e[84]!==S||e[85]!==W||e[86]!==h||e[87]!==D?(E=b?h(W?U?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":S==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[h("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:D}),"."]}),e[82]=U,e[83]=b,e[84]=S,e[85]=W,e[86]=h,e[87]=D,e[88]=E):E=e[88];let de;e[89]!==E?(de=s.jsx(dn,{children:E}),e[89]=E,e[90]=de):de=e[90];let fe;e[91]!==we||e[92]!==de?(fe=s.jsxs(tn,{children:[we,de]}),e[91]=we,e[92]=de,e[93]=fe):fe=e[93];let $;e[94]!==pe||e[95]!==fe?($=s.jsxs(Vs,{className:"max-w-md",children:[fe,pe]}),e[94]=pe,e[95]=fe,e[96]=$):$=e[96];let ke;e[97]!==k||e[98]!==T||e[99]!==$?(ke=s.jsx(_s,{open:k,onOpenChange:T,children:$}),e[97]=k,e[98]=T,e[99]=$,e[100]=ke):ke=e[100];let Ve;return e[101]!==De||e[102]!==ke?(Ve=s.jsxs(s.Fragment,{children:[De,ke]}),e[101]=De,e[102]=ke,e[103]=Ve):Ve=e[103],Ve};function gv(t){return t.status==="done"||t.status==="error"}function xv(t){return t.status==="error"}function bv(t){return t.slice(t.indexOf("/")+1)}function wv(t,e){return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"mt-0.5 shrink-0",children:[t.status==="running"&&s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(A,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(A,{name:"close",className:"size-3.5 text-destructive"}),t.status==="pending"&&s.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),s.jsx("span",{className:Pe("typography-micro",t.status==="error"&&"text-destructive",t.status==="done"&&"text-muted-foreground",t.status==="running"&&"text-foreground",t.status==="pending"&&"text-muted-foreground/60"),children:t.message})]},e)}function yv(t){return t.stopPropagation()}const vv=({runMutation:t,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:o})=>{const a=[];let c=!1;return{enqueue:d=>{const f=a[a.length-1];if(f?.directory===d.directory&&f.direction===d.direction){d.paths.forEach(m=>f.paths.add(m));return}a.push(d)},flush:()=>{if(c)return;const d=a.shift();if(!d)return;c=!0;const f={directory:d.directory,direction:d.direction,paths:Array.from(d.paths),rollback:d.rollback};(async()=>{try{await t(f),e(f)}catch(m){n(f,m)}finally{r(f.paths),c=!1,a.length>0&&o()}})()},clear:()=>{a.length=0},size:()=>a.length,isRunning:()=>c}},Fu="oc.git.actionTab",jv=15e3,Sv=t=>t==="commit"||t==="branch"||t==="pr",Nv=40,kv=20,Ou={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Cv=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,o=n.match(r);if(o){const l=o[1],d=Ou[l];if(d)return e.find(f=>f.code===d)||null}const a=n.split(" ")[0],c=Ou[a];return c&&e.find(l=>l.code===c)||null},Av=20,Yi=new Map,Dv=(t,e)=>{if(Yi.delete(t),Yi.set(t,e),Yi.size>Av){const n=Yi.keys().next().value;n!==void 0&&Yi.delete(n)}},qr=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Lu=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},Tv=t=>{const e=t.working_dir?.trim(),n=t.index?.trim();return!!(e||n==="?")},oc=({isActive:t})=>{const{t:e}=yt(),{git:n}=nr(),r=bi(),[o,a]=i.useState(null),[c,l]=i.useState(!1),d=ht(Q=>Q.currentSessionId),f=ht(Q=>Q.newSessionDraft),m=ht(Q=>Q.setDraftBootstrapPendingDirectory),u=ht(Q=>Q.worktreeMetadata),p=ht(Q=>Q.availableWorktrees),x=qr(r),b=i.useMemo(()=>{if(!x)return;const Q=p.find(je=>qr(je.path)===x);if(Q)return Q;for(const je of u.values())if(qr(je.path)===x)return je},[p,x,u]),w=i.useMemo(()=>{if(d)return u.get(d)??b;if(f?.open)return b},[d,b,f?.open,u]),{profiles:g,globalIdentity:h,defaultGitIdentityId:k,loadProfiles:j,loadGlobalIdentity:S,loadDefaultGitIdentityId:N}=nb(ql(Q=>({profiles:Q.profiles,globalIdentity:Q.globalIdentity,defaultGitIdentityId:Q.defaultGitIdentityId,loadProfiles:Q.loadProfiles,loadGlobalIdentity:Q.loadGlobalIdentity,loadDefaultGitIdentityId:Q.loadDefaultGitIdentityId}))),C=Ic(r??null),y=Ja(r??null),P=om(Q=>d?Q.getAttachment(d):void 0),_=P?pg(P):[],v=P&&!P.degraded&&!P.legacy?P.worktreeRoot??void 0:void 0,F=iy(r,w,y?.current??void 0),I=um(r??null),R=gg(r??null),B=xg(r??null),D=Rc(r??null),W=bg(r??null),{setActiveDirectory:U,fetchAll:L,ensureAll:M,fetchStatus:ee,fetchBranches:ie,fetchLog:te,setLogMaxCount:H,fetchIdentity:J,prefetchDiffs:re,moveStatusPathsOptimistically:oe,restoreStatus:ve,bumpIndexRevision:ne}=yn(ql(Q=>({setActiveDirectory:Q.setActiveDirectory,fetchAll:Q.fetchAll,ensureAll:Q.ensureAll,fetchStatus:Q.fetchStatus,fetchBranches:Q.fetchBranches,fetchLog:Q.fetchLog,setLogMaxCount:Q.setLogMaxCount,fetchIdentity:Q.fetchIdentity,prefetchDiffs:Q.prefetchDiffs,moveStatusPathsOptimistically:Q.moveStatusPathsOptimistically,restoreStatus:Q.restoreStatus,bumpIndexRevision:Q.bumpIndexRevision}))),ye=Ee(Q=>Q.isMobile),he=Ee(Q=>Q.openContextDiff),Fe=Ee(Q=>Q.navigateToDiff),z=Ee(Q=>Q.setRightSidebarOpen),K=i.useRef(null),Y=i.useRef(null),me=i.useRef(null),Ne=i.useRef(null),Be=i.useRef(!0);i.useEffect(()=>()=>{Be.current=!1},[]);const _e=i.useCallback(()=>{Y.current!==null&&(window.clearTimeout(Y.current),Y.current=null)},[]),Oe=i.useCallback(Q=>{_e(),Y.current=window.setTimeout(()=>{Y.current=null,qr(Q)===qr(r)&&ee(Q,n,{silent:!0})},jv)},[_e,r,ee,n]);i.useEffect(()=>_e,[_e]);const pe=i.useCallback(()=>{me.current!==null&&(window.clearTimeout(me.current),me.current=null)},[]),Re=i.useCallback(()=>{me.current===null&&(me.current=window.setTimeout(()=>{me.current=null,Ne.current?.()},0))},[]),ge=i.useCallback(async(Q,je,Ie)=>{if(je==="stage"){if(n.stageGitFiles){await n.stageGitFiles(Q,Ie);return}await Promise.all(Ie.map($e=>n.stageGitFile(Q,$e)));return}if(n.unstageGitFiles){await n.unstageGitFiles(Q,Ie);return}await Promise.all(Ie.map($e=>n.unstageGitFile(Q,$e)))},[n]),ce=i.useMemo(()=>vv({runMutation:({directory:Q,direction:je,paths:Ie})=>ge(Q,je,Ie),onMutationComplete:({directory:Q})=>{ne(Q),Oe(Q)},onMutationError:({directory:Q,direction:je,rollback:Ie},$e)=>{Ie?.(),ne(Q),Oe(Q);const mt=e(je==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");le.error($e instanceof Error?$e.message:mt)},onPathsComplete:Q=>{rt(je=>{const Ie=new Set(je);return Q.forEach($e=>Ie.delete($e)),Ie})},scheduleFlush:Re}),[ne,ge,Re,Oe,e]);i.useEffect(()=>(Ne.current=ce.flush,()=>{Ne.current=null}),[ce]),i.useEffect(()=>()=>ce.clear(),[ce]),i.useEffect(()=>pe,[pe]),i.useEffect(()=>{if(!t)return;if(!r){a(null),l(!1);return}let Q=!1,je=null;const Ie=async()=>{try{const $e=await yg(r);if(Q)return;a($e.status),$e.status==="pending"&&(je=window.setTimeout(()=>{Ie()},500))}catch{Q||a(null)}};return Ie(),()=>{Q=!0,je!==null&&window.clearTimeout(je)}},[t,r]),i.useEffect(()=>{const Q=K.current;K.current=o,!(!r||!n)&&(Q==="pending"&&o==="ready"&&(l(!0),L(r,n).finally(()=>{window.setTimeout(()=>{l(!1)},1200)})),o==="failed"&&(m(null),l(!1)))},[r,L,n,m,o]);const Ce=qr(f?.bootstrapPendingDirectory??null),be=!!(r&&Ce&&Ce===qr(r)),De=!!(r&&(o==="pending"||be))||c,T=i.useMemo(()=>r?Yi.get(r)??null:null,[r]),V=rs(Q=>Q.settingsGitmojiEnabled),[we,E]=i.useState(null),{gitmojis:de}=ry(V);i.useEffect(()=>{const Q=v||F?.projectDirectory;if(!Q){E(null);return}let je=!1;return Xa(Q).then(Ie=>{if(je)return;const $e=Ie.trim();E($e&&$e!=="HEAD"?$e:null)}).catch(()=>{je||E(null)}),()=>{je=!0}},[v,F?.projectDirectory]);const[fe,$]=i.useState(T?.commitMessage??""),[ke,Ve]=i.useState([]),[Se,q]=i.useState(!1),O=i.useRef(null),[se,Le]=i.useState(null),[ae,We]=i.useState(!1),[Ye,Qe]=i.useState(null),[st,pt]=i.useState(25),[jt,Et]=i.useState(!1),{triggerFireworks:Rt}=ey(),Ut=i.useRef(new Map),ts=i.useRef(0),Kt=i.useCallback(()=>{ts.current+=1,Be.current&&Et(!0)},[]),is=i.useCallback(()=>{ts.current=Math.max(0,ts.current-1),Be.current&&ts.current===0&&Et(!1)},[]),[qt,Te]=i.useState(new Set),[Ke,rt]=i.useState(new Set),[vt,Je]=i.useState(!1),[St,Xe]=i.useState(0),[qe,et]=i.useState(!1),[Vt,Ct]=i.useState(T?.generatedHighlights??[]),Ht=Ke.size>0||ce.size()>0||ce.isRunning(),ss=i.useCallback(()=>{const Q=O.current;Q&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q.scrollTo({top:Q.scrollHeight,behavior:"smooth"})})})},[]),Xt=v||F?.projectDirectory||null,Ft=y?.current||null,_t=i.useMemo(()=>{const Q=y?.tracking;return Q?Q.startsWith("origin/"):!0},[y?.tracking]),hs=i.useMemo(()=>{const Q=F?.createdFromBranch,je=typeof Q=="string"?Q.trim():"",Ie=typeof y?.current=="string"?y.current.trim():"",$e=typeof we=="string"?we.trim():"";return je?je===Ie&&je.startsWith("opencode/")&&$e.length>0&&$e!==je?$e:je:$e||Ie||"HEAD"},[F?.createdFromBranch,y,we]),Zt=i.useCallback(()=>{Ct([])},[]),[ns,gs]=i.useState(new Set),[Mt,Bt]=i.useState(new Map),[$t,os]=i.useState(new Set),Gt=i.useRef(Mt),Me=i.useRef($t),[ft,at]=i.useState(null),[Nt,Pt]=i.useState(null),[es,xs]=i.useState(""),[Yt,Lt]=i.useState(null),Es=i.useMemo(()=>[{id:"commit",label:e("gitView.tabs.commit"),icon:s.jsx(A,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:e("gitView.tabs.update"),icon:s.jsx(A,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:e("gitView.tabs.pr"),icon:s.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[e]),[ms,Ns]=i.useState(()=>{if(typeof window>"u")return"commit";const Q=window.localStorage.getItem(Fu);return Q==="worktree"?"branch":Sv(Q)?Q:"commit"}),[Us,Ms]=i.useState([]),[Tn,Hs]=i.useState(null),[xe,tt]=i.useState(null),[ut,wt]=i.useState([]),[zt,xt]=i.useState(!1),[ps,cs]=i.useState([]),[js,Ss]=i.useState("merge"),[Fs,Bn]=i.useState(null),[sn,Kn]=i.useState(!1),[Pn,vn]=i.useState(100),Ks=i.useMemo(()=>d?`openchamber.conflict:${d}`:null,[d]),jn=i.useCallback((Q,je,Ie)=>{if(!Ks||typeof window>"u")return;const $e={directory:Q,conflictFiles:je,operation:Ie};window.localStorage.setItem(Ks,JSON.stringify($e))},[Ks]),nn=i.useCallback(()=>{!Ks||typeof window>"u"||window.localStorage.removeItem(Ks)},[Ks]);i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Fu,ms)},[ms]),i.useEffect(()=>{if(!Ks||typeof window>"u"||!r)return;const Q=window.localStorage.getItem(Ks);if(Q)try{const je=JSON.parse(Q);if(je.directory!==r){window.localStorage.removeItem(Ks);return}cs(je.conflictFiles??[]),Ss(je.operation??"merge"),xt(!0)}catch{window.localStorage.removeItem(Ks)}},[Ks,r]);const[Ge,ds]=i.useState(!1),[ks,Os]=i.useState("merge"),[qs,$s]=i.useState(""),gn=i.useCallback(Q=>{gr(Q).then(je=>{if(je.ok){le.success(e("gitView.toast.commitHashCopied"));return}le.error(e("gitView.toast.copyFailed"))})},[e]),Cs=i.useCallback(Q=>{gs(je=>{const Ie=new Set(je);return Ie.has(Q)?Ie.delete(Q):Ie.add(Q),Ie})},[]);i.useEffect(()=>{Gt.current=Mt},[Mt]),i.useEffect(()=>{Me.current=$t},[$t]),i.useEffect(()=>{if(!r||!n)return;const Q=Array.from(ns).filter(Ie=>!Gt.current.has(Ie)&&!Me.current.has(Ie));if(Q.length===0)return;let je=!1;return os(Ie=>{const $e=new Set(Ie);for(const mt of Q)$e.add(mt);return Me.current=$e,$e}),Promise.all(Q.map(Ie=>n.getCommitFiles(r,Ie).then($e=>({hash:Ie,files:$e.files})).catch($e=>(console.error("Failed to fetch commit files:",$e),{hash:Ie,files:[]})))).then(Ie=>{je||(Bt($e=>{const mt=new Map($e);for(const{hash:It,files:Qt}of Ie)mt.set(It,Qt);return Gt.current=mt,mt}),os($e=>{const mt=new Set($e);for(const{hash:It}of Ie)mt.delete(It);return Me.current=mt,mt}))}),()=>{je=!0,os(Ie=>{let $e=!1;const mt=new Set(Ie);for(const It of Q)mt.delete(It)&&($e=!0);return $e?(Me.current=mt,mt):Ie})}},[ns,r,n]),i.useEffect(()=>{r&&Dv(r,{directory:r,commitMessage:fe,generatedHighlights:Vt})},[fe,r,Vt]),i.useEffect(()=>{t&&(j(),S(),N())},[t,j,S,N]),i.useEffect(()=>{if(!t)return;if(!r||!n?.getRemoteUrl){Pt(null);return}let Q=!1;return n.getRemoteUrl(r).then(je=>{Q||Pt(je)}).catch(()=>{Q||Pt(null)}),()=>{Q=!0}},[t,r,n]);const qn=i.useCallback(async()=>{if(!r||!n?.getRemotes){Ms([]);return}try{const Q=await n.getRemotes(r);Be.current&&Ms(Q)}catch{Be.current&&Ms([])}},[r,n]);i.useEffect(()=>{t&&qn()},[t,qn]),i.useEffect(()=>{t&&r&&(U(r),M(r,n))},[t,r,U,M,n]),i.useEffect(()=>{if(t&&r)return _r.onGitRefreshHint(Q=>{qr(Q.directory)===qr(r)&&ee(r,n)})},[t,r,ee,n]);const us=i.useCallback(async(Q=!0)=>{if(r)try{await Promise.all([ee(r,n),ie(r,n)])}catch(je){if(Q){const Ie=je instanceof Error?je.message:e("gitView.toast.refreshRepositoryFailed");le.error(Ie)}}},[r,n,ee,ie,e]),Ls=i.useCallback(async()=>{r&&await te(r,n,st)},[r,n,te,st]),br=i.useCallback(async()=>{r&&await J(r,n)},[r,n,J]);i.useEffect(()=>{if(!t||!r||!n?.hasLocalIdentity||C!==!0)return;const Q=typeof k=="string"?k.trim():"";if(!Q||Q==="global"||Ut.current.get(r)===Q)return;let Ie=!1;return(async()=>{try{const mt=await n.hasLocalIdentity?.(r);if(Ie||mt===!0)return;Kt(),await n.setGitIdentity(r,Q),Ut.current.set(r,Q),await br()}catch(mt){console.warn("Failed to auto-apply default git identity:",mt)}finally{Ie||is()}})(),()=>{Ie=!0}},[t,Kt,r,k,is,n,C,br]);const Yn=i.useMemo(()=>y?[...y.files??[]].sort((je,Ie)=>je.path.localeCompare(Ie.path)):[],[y]),un=i.useMemo(()=>Yn.filter(Lu),[Yn]),Ar=i.useMemo(()=>Yn.filter(Tv),[Yn]);i.useEffect(()=>{if(!r||Yn.length===0)return;const Q=[],je=new Set,Ie=mt=>{!mt||je.has(mt)||(je.add(mt),Q.push(mt))};if(un.forEach(mt=>Ie(mt.path)),ke.forEach(Ie),Yn.slice(0,kv).forEach(mt=>Ie(mt.path)),Q.length===0)return;const $e=window.setTimeout(()=>{re(r,n,Q,{maxFiles:Nv})},120);return()=>{window.clearTimeout($e)}},[Yn,r,n,re,un,ke]);const ni=Q=>Q?.pushed[0]?.remote||y?.tracking?.split("/")[0]||Wt.find(je=>je.name==="origin")?.name||Wt[0]?.name||"origin",ri=async(Q,je)=>{if(r){Le(Q);try{const Ie=$e=>{const mt=`${$e.name}/`,It=y?.tracking?.startsWith(mt)?y.tracking.slice(mt.length):void 0;return{remote:$e.name,branch:It,rebase:!0}};if(Q==="fetch"){if(!je)throw new Error("No remote available for fetch");await n.gitFetch(r,{remote:je.name}),le.success(e("gitView.toast.fetchedFromRemote",{name:je.name}))}else if(Q==="pull"){if(!je)throw new Error("No remote available for pull");const $e=await n.gitPull(r,Ie(je));le.success($e.files.length===1?e("gitView.toast.pulledFilesSingle",{count:$e.files.length,name:je.name}):e("gitView.toast.pulledFilesPlural",{count:$e.files.length,name:je.name}))}else if(Q==="push"){const $e=await n.gitPush(r);le.success(e("gitView.toast.pushedToUpstream",{name:ni($e)}))}else if(Q==="sync"){if(!je)throw new Error("No remote available for sync");let $e=0,mt=!1;await n.gitFetch(r,{remote:je.name});const It=await n.getGitStatus(r);if((It.behind??0)>0){if((It.files?.length??0)>0){le.error(e("gitView.toast.commitOrStashBeforeSync"));return}$e=(await n.gitPull(r,Ie(je))).files.length}((await n.getGitStatus(r)).ahead??0)>0&&(await n.gitPush(r),mt=!0),$e>0&&mt?le.success($e===1?e("gitView.toast.syncedPulledSingleAndPushed",{count:$e,name:je.name}):e("gitView.toast.syncedPulledPluralAndPushed",{count:$e,name:je.name})):$e>0?le.success($e===1?e("gitView.toast.pulledFilesSingle",{count:$e,name:je.name}):e("gitView.toast.pulledFilesPlural",{count:$e,name:je.name})):mt?le.success(e("gitView.toast.pushedToUpstream",{name:je.name})):le.success(e("gitView.toast.alreadyUpToDate"))}await us(!1),await Ls()}catch(Ie){const $e=Ie instanceof Error?Ie.message:e("gitView.toast.syncActionFailed",{action:Q==="sync"?e("gitView.sync.syncChanges"):Q==="pull"?e("gitView.sync.pull"):Q});le.error($e)}finally{Le(null)}}},yi=i.useCallback(async Q=>{if(!r)return;const je=Q.name.trim();if(!je){le.error(e("gitView.toast.remoteNameRequired"));return}if(je==="origin"){le.error(e("gitView.toast.cannotRemoveOriginRemote"));return}Hs(je);try{await n.removeRemote(r,{remote:je}),le.success(e("gitView.toast.removedRemote",{name:je})),await Promise.all([us(!1),qn()])}catch(Ie){const $e=Ie instanceof Error?Ie.message:`Failed to remove ${je}`;le.error($e)}finally{Hs(null)}},[r,n,qn,us,e]),Dr=async(Q={})=>{if(!r)return;if(!fe.trim()){le.error(e("gitView.toast.enterCommitMessage"));return}const je=un.map($e=>$e.path).sort();if(je.length===0){le.error(e("gitView.toast.stageFileToCommit"));return}const Ie=Q.pushAfter?"commitAndPush":"commit";Qe(Ie);try{if(await n.createGitCommit(r,fe.trim(),{files:je,stageFiles:[]}),ne(r),le.success(e("gitView.toast.commitCreated")),$(""),Zt(),await us(),Q.pushAfter){const $e=y?.tracking?.split("/")[0],mt=Wt.find(Er=>Er.name===$e)??Wt[0];if(!mt)throw new Error(e("mobile.changes.noRemote"));Le("sync");const It=`${mt.name}/`,Qt=y?.tracking?.startsWith(It)?y.tracking.slice(It.length):void 0;await n.gitFetch(r,{remote:mt.name});const Jt=await n.getGitStatus(r);if((Jt.behind??0)>0){if((Jt.files?.length??0)>0){le.error(e("gitView.toast.commitOrStashBeforeSync")),await us(!1);return}await n.gitPull(r,{remote:mt.name,branch:Qt,rebase:!0})}const vs=await n.getGitStatus(r);let wr;(vs.ahead??0)>0&&(wr=await n.gitPush(r)),le.success(e("gitView.toast.pushedToUpstream",{name:ni(wr)})),Rt(),await us(!1)}else await us(!1);await Ls(),Xe($e=>$e+1)}catch($e){const mt=$e instanceof Error?$e.message:e("gitView.toast.createCommitFailed");le.error(mt)}finally{Qe(null),Q.pushAfter&&Le(null)}},ys=i.useCallback(async()=>{if(!r)return;const Q=un.map(je=>je.path).sort();if(Q.length===0){le.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:Q.length}),et(!0);try{const{message:je}=await wg(r,Q),Ie=je.subject?.trim()??"",$e=Array.isArray(je.highlights)?je.highlights:[];if(Ie){let mt=Ie;if(V&&de.length>0){const It=Cv(Ie,de);if(It){const{code:Qt,emoji:Jt}=It;!Ie.startsWith(Qt)&&!Ie.startsWith(Jt)&&(mt=`${Qt} ${Ie}`)}}$(mt)}Ct($e),ss()}catch(je){console.error("[git-generation][browser] GitView generate handler failed",{message:je instanceof Error?je.message:String(je),error:je});const Ie=je instanceof Error?je.message:e("gitView.toast.generateCommitMessageFailed");le.error(Ie)}finally{et(!1)}},[r,un,V,de,ss,e]),rn=Q=>Q.reason==="attention"?`${Q.attentionReason} in progress`:Q.reason==="missing"?"worktree is missing":"worktree is invalid",rr=async(Q,je)=>{if(!r||!y)return;const Ie=ul(P);if(Ie.length>0){le.error(e("gitView.toast.cannotCreateBranch",{reason:rn(Ie[0])}));return}const $e=y.current??null,mt=je?.name??"origin";try{await n.createBranch(r,Q,$e??"HEAD"),le.success(e("gitView.toast.createdBranch",{name:Q})),await n.checkoutBranch(r,Q);let It=!1;try{await n.gitPush(r,{remote:mt,branch:Q,options:["--set-upstream"]}),It=!0}catch(Qt){const Jt=Qt instanceof Error?Qt.message:`Unable to push new branch to ${mt}.`;le.warning(e("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Jt]})})}await us(),await Ls(),It&&le.success(e("gitView.toast.upstreamSet",{branch:Q,remote:mt}))}catch(It){const Qt=It instanceof Error?It.message:e("gitView.toast.createBranchFailed");throw le.error(Qt),It}},Sn=async(Q,je)=>{if(!r)return;const Ie=ul(P);if(Ie.length>0){le.error(e("gitView.toast.cannotRenameBranch",{reason:rn(Ie[0])}));return}try{await n.renameBranch(r,Q,je),le.success(e("gitView.toast.renamedBranch",{oldName:Q,newName:je})),await us(),await Ls()}catch($e){const mt=$e instanceof Error?$e.message:e("gitView.toast.renameBranchFailed",{oldName:Q,newName:je});le.error(mt)}},X=async Q=>{if(!r)return;const je=ul(P);if(je.length>0){le.error(e("gitView.toast.cannotCheckout",{reason:rn(je[0])}));return}const Ie=Q.replace(/^remotes\//,"");if(y?.current!==Ie)try{await n.checkoutBranch(r,Ie),le.success(e("gitView.toast.checkedOut",{name:Ie})),await us(),await Ls()}catch($e){const mt=$e instanceof Error?$e.message:e("gitView.toast.checkoutFailed",{name:Ie});le.error(mt)}},it=async Q=>{if(r){Kt();try{await n.setGitIdentity(r,Q.id),le.success(e("gitView.toast.appliedIdentity",{name:Q.name})),await br()}catch(je){const Ie=je instanceof Error?je.message:e("gitView.toast.applyIdentityFailed");le.error(Ie)}finally{is()}}},dt=i.useMemo(()=>I?.all?I.all.filter(Q=>!Q.startsWith("remotes/")).sort():[],[I]),kt=i.useMemo(()=>I?.all?I.all.filter(Q=>Q.startsWith("remotes/")).map(Q=>Q.replace(/^remotes\//,"")).sort():[],[I]),Wt=i.useMemo(()=>{if(Us.length>0)return Us;const Q=new Set,je=y?.tracking?.trim();je&&je.includes("/")&&Q.add(je.split("/")[0]);for(const Ie of kt){const $e=Ie.indexOf("/");$e>0&&Q.add(Ie.slice(0,$e))}return Q.size===0&&Nt&&Q.add("origin"),Array.from(Q).map(Ie=>({name:Ie,fetchUrl:Nt??"",pushUrl:Nt??""}))},[Us,kt,Nt,y?.tracking]),fs=i.useMemo(()=>{const Q=new Set(Wt.map(mt=>mt.name)),je=mt=>{if(!mt)return"";let It=mt.trim();if(!It||It==="HEAD")return"";if(dt.includes(It))return It;It.startsWith("refs/heads/")&&(It=It.slice(11)),It.startsWith("heads/")&&(It=It.slice(6)),It.startsWith("remotes/")&&(It=It.slice(8));const Qt=It.indexOf("/");if(Qt>0){const Jt=It.slice(0,Qt);if(Q.has(Jt)){const vs=It.slice(Qt+1).trim();vs&&(It=vs)}}return It},Ie=je(typeof F?.createdFromBranch=="string"?F.createdFromBranch:"");if(Ie)return Ie;const $e=je(typeof we=="string"?we:"");return $e||(dt.includes("main")?"main":dt.includes("master")?"master":dt.includes("develop")?"develop":"main")},[Wt,dt,we,F?.createdFromBranch]),bs=i.useMemo(()=>Wt.map(Ie=>Ie.name).map(Ie=>`${Ie}/${fs}`).find(Ie=>kt.includes(Ie))??fs,[fs,Wt,kt]),zs=i.useMemo(()=>{const Q=new Map;h&&Q.set(h.id,h);let je=null;if(Nt)try{let Ie=Nt.trim();Ie.startsWith("git@")&&(Ie=`https://${Ie.slice(4).replace(":","/")}`),Ie.endsWith(".git")&&(Ie=Ie.slice(0,-4));const $e=new URL(Ie);je=$e.hostname+$e.pathname}catch{}for(const Ie of g){if(Ie.authType!=="token"){Q.set(Ie.id,Ie);continue}const $e=Ie.host;if(!$e){Q.set(Ie.id,Ie);continue}if(!$e.includes("/")){Q.set(Ie.id,Ie);continue}je&&je===$e&&Q.set(Ie.id,Ie)}return Array.from(Q.values())},[g,h,Nt]),Ys=i.useMemo(()=>{if(B?.userName&&B?.userEmail){const Q=g.find(je=>je.userName===B.userName&&je.userEmail===B.userEmail);return Q||(h&&h.userName===B.userName&&h.userEmail===B.userEmail?h:{id:"local-config",name:B.userName,userName:B.userName,userEmail:B.userEmail,sshKey:B.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return h??null},[B,g,h]),xn=un.length,fr=D||se!==null||Ye!==null,Nn=y?.current??null,Wr=!!(F&&Xt&&Ft&&_t),Tr=!!(r&&Nn),kn=!!Nn,ln=Wr&&Xt&&Ft&&F?{repoRoot:Xt,sourceBranch:Ft,worktreeMetadata:F}:null,In=i.useMemo(()=>!Tr||!r||!Nn?null:{directory:r,branch:Nn},[Tr,Nn,r]);i.useEffect(()=>{if(!r||!n||!R?.all?.length||!Nn||!fs||Nn===fs){at(null);return}let Q=!1;return(async()=>{try{const Ie=await n.getGitLog(r,{from:fs,to:"HEAD",maxCount:st});if(Q)return;const $e=new Set((Ie?.all??[]).map(It=>It.hash).filter(It=>typeof It=="string"&&It.length>0));if($e.size===0){at(null);return}const mt=R.all.findIndex(It=>!$e.has(It.hash));if(mt===0){at(null);return}if(mt===-1){at({insertBeforeIndex:R.all.length,branchName:Nn,direction:"up"});return}at({insertBeforeIndex:mt,branchName:Nn,direction:"up"})}catch{Q||at(null)}})(),()=>{Q=!0}},[fs,Nn,r,n,R,st]),i.useEffect(()=>{Bn(null)},[r]),i.useEffect(()=>{if(Yt!=="graph"||!r){Yt!=="graph"&&Bn(null);return}let Q=!1;return Kn(!0),n.getGitLog(r,{maxCount:Pn,all:!0}).then(je=>{Q||Bn(je)}).catch(je=>{console.error("Failed to fetch graph log:",je)}).finally(()=>{Q||Kn(!1)}),()=>{Q=!0}},[Yt,r,Pn,n]);const fn=i.useCallback((Q,je)=>{if(!r||Q.length===0)return;const Ie=Array.from(new Set(Q));rt(mt=>{const It=new Set(mt);return Ie.forEach(Qt=>It.add(Qt)),It});const $e=oe(r,Ie,je);ce.enqueue({directory:r,direction:je,paths:new Set(Ie),rollback:()=>ve(r,$e)}),Re()},[r,ce,oe,ve,Re]),ir=i.useCallback(async Q=>{if(r){Te(je=>{const Ie=new Set(je);return Ie.add(Q),Ie});try{await n.revertGitFile(r,Q,{scope:"working"}),le.success(e("gitView.toast.revertedFile",{path:Q})),await us(!1)}catch(je){const Ie=je instanceof Error?je.message:e("gitView.toast.revertFailed");le.error(Ie)}finally{Te(je=>{const Ie=new Set(je);return Ie.delete(Q),Ie})}}},[r,us,n,e]),Qn=i.useCallback(async(Q,je,Ie="all")=>{if(!r||Q.length===0)return;const $e=Array.from(new Set(Q));if(vt||$e.some(Jt=>qt.has(Jt)))return;const mt=new Set(un.map(Jt=>Jt.path)),It=Ie==="all"&&$e.some(Jt=>mt.has(Jt));je&&Je(!0),Te(Jt=>{const vs=new Set(Jt);return $e.forEach(wr=>vs.add(wr)),vs});const Qt=[];try{if(await Promise.all($e.map(async Jt=>{try{await n.revertGitFile(r,Jt,{scope:Ie})}catch(vs){Qt.push({path:Jt,message:vs instanceof Error?vs.message:e("gitView.toast.revertFailed")})}})),It&&Qt.length<$e.length&&ne(r),await us(!1),Qt.length===0)le.success($e.length===1?e("gitView.toast.revertedFilesSingle",{count:$e.length}):e("gitView.toast.revertedFilesPlural",{count:$e.length}));else if(Qt.length===$e.length)le.error(Qt[0]?.message||e("gitView.toast.revertFailed"));else{const Jt=$e.length-Qt.length;le.warning(Jt===1?e("gitView.toast.revertedSomeSingle",{success:Jt,failed:Qt.length}):e("gitView.toast.revertedSomePlural",{success:Jt,failed:Qt.length}))}}finally{Te(Jt=>{const vs=new Set(Jt);return $e.forEach(wr=>vs.delete(wr)),vs}),je&&Je(!1)}},[ne,r,n,vt,us,qt,un,e]),Rn=i.useCallback(async Q=>{await Qn(Q,!0)},[Qn]),vi=i.useCallback(async Q=>{await Qn(Q,!1,"working")},[Qn]),Pr=i.useCallback((Q,je)=>{if(r&&!ye){he(r,Q,je);return}Fe(Q,je),ye&&z(!1)},[r,ye,Fe,he,z]),ji=i.useCallback(()=>We(!0),[]),zi=i.useMemo(()=>{const Q=[];return un.length>0&&Q.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:un,actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:je=>e("gitView.changes.unstageFileAria",{path:je}),onActionFile:je=>{fn([je],"unstage")},onActionAll:je=>{fn(je,"unstage")},onViewDiff:je=>Pr(je,!0),onRevertFile:ir,showRevertActions:!1,accent:!0}),Ar.length>0&&Q.push({id:"unstaged",title:e("gitView.changes.title"),entries:Ar,actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:je=>e("gitView.changes.stageFileAria",{path:je}),onActionFile:je=>{fn([je],"stage")},onActionAll:je=>{fn(je,"stage")},onViewDiff:je=>Pr(je,!1),onRevertFile:ir}),Q},[ir,Pr,fn,un,e,Ar]),or=i.useCallback(Q=>{if(Q.length===0)return;const je=Q.map(Ie=>Ie.trim()).filter(Boolean);if(je.length===0){Zt();return}$(Ie=>{const $e=Ie.trim(),mt=$e.length>0?`
|
|
11
|
+
|
|
12
|
+
`:"";return`${$e}${mt}${je.join(`
|
|
13
|
+
`)}`.trim()}),Zt()},[Zt]),Cn=i.useCallback((Q,je)=>{const Ie=je||Q;$($e=>{const mt=$e.trimStart();return mt.startsWith(Q)||je&&mt.startsWith(je)?$e:`${Ie.endsWith(" ")?Ie:`${Ie} `}${$e}`.trimStart()}),xs(""),q(!1)},[]),ar=i.useCallback(Q=>{const je=Q instanceof Error?Q.message.toLowerCase():"";return je.includes("uncommitted changes")||je.includes("local changes")||je.includes("your local changes would be overwritten")||je.includes("please commit your changes or stash them")||je.includes("cannot rebase: you have unstaged changes")||je.includes("error: cannot pull with rebase")},[]),on=i.useCallback((Q,je)=>{wt(Ie=>[...Ie,{message:Q,status:je,timestamp:Date.now()}])},[]),mn=i.useCallback((Q,je)=>{wt(Ie=>{if(Ie.length===0)return Ie;const $e=[...Ie];return $e[$e.length-1]={...$e[$e.length-1],status:Q,...je?{message:je}:{}},$e})},[]),Ur=i.useCallback(()=>{wt([])},[]),Wi=i.useCallback(()=>{wt([]),tt(null)},[]),Ir=i.useCallback(Q=>{const je=Q.trim(),Ie=new Set(Wt.map(mt=>mt.name)),$e=je.indexOf("/");if($e>0){const mt=je.slice(0,$e),It=je.slice($e+1);if(Ie.has(mt)&&It)return{branch:je,remote:mt,remoteBranch:It}}for(const mt of Wt){const It=`${mt.name}/${je}`;if(kt.includes(It))return{branch:It,remote:mt.name,remoteBranch:je}}return{branch:je,remote:null,remoteBranch:null}},[Wt,kt]),Vn=i.useCallback(async Q=>{if(!r)return;tt("merge"),Ur();const je=y?.current,Ie=Ir(Q);try{Ie.remote&&Ie.remoteBranch&&(on(`Fetching ${Ie.remote}/${Ie.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:Ie.remote,branch:Ie.remoteBranch}),mn("done",`Fetched ${Ie.remote}/${Ie.remoteBranch}`)),on(`Merging ${Ie.branch} into ${je}...`,"running");const $e=await n.merge(r,{branch:Ie.branch});$e.conflict?(mn("error","Merge conflicts detected"),cs($e.conflictFiles??[]),Ss("merge"),xt(!0),jn(r,$e.conflictFiles??[],"merge")):(mn("done",`Merged ${Ie.branch} into ${je}`),nn(),on("Refreshing repository status...","running"),await us(),await Ls(),mn("done","Repository status updated"))}catch($e){if(ar($e))mn("error","Uncommitted changes detected"),Os("merge"),$s(Ie.branch),ds(!0);else{const mt=$e instanceof Error?$e.message:`Failed to merge ${Ie.branch}`;mn("error",mt)}}},[r,n,y,Ir,us,Ls,ar,jn,nn,on,mn,Ur]),Hr=i.useCallback(async Q=>{if(!r)return;tt("rebase"),Ur();const je=y?.current,Ie=Ir(Q);try{Ie.remote&&Ie.remoteBranch&&(on(`Fetching ${Ie.remote}/${Ie.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:Ie.remote,branch:Ie.remoteBranch}),mn("done",`Fetched ${Ie.remote}/${Ie.remoteBranch}`)),on(`Rebasing ${je} onto ${Ie.branch}...`,"running");const $e=await n.rebase(r,{onto:Ie.branch});$e.conflict?(mn("error","Rebase conflicts detected"),cs($e.conflictFiles??[]),Ss("rebase"),xt(!0),jn(r,$e.conflictFiles??[],"rebase")):(mn("done",`Rebased ${je} onto ${Ie.branch}`),nn(),on("Refreshing repository status...","running"),await us(),await Ls(),mn("done","Repository status updated"))}catch($e){if(ar($e))mn("error","Uncommitted changes detected"),Os("rebase"),$s(Ie.branch),ds(!0);else{const mt=$e instanceof Error?$e.message:`Failed to rebase onto ${Ie.branch}`;mn("error",mt)}}},[r,n,y,Ir,us,Ls,ar,jn,nn,on,mn,Ur]),bn=i.useCallback(async()=>{if(r)try{js==="merge"?(await n.abortMerge(r),le.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),le.success(e("gitView.toast.rebaseAborted"))),nn(),await us(),await Ls()}catch(Q){const je=Q instanceof Error?Q.message:`Failed to abort ${js}`;le.error(je)}},[r,n,js,us,Ls,nn,e]),mr=i.useMemo(()=>y?.files?y.files.some(Q=>Q.index==="U"||Q.working_dir==="U"||Q.index==="A"&&Q.working_dir==="A"||Q.index==="D"&&Q.working_dir==="D"):!1,[y?.files]),Ui=i.useCallback(async()=>{if(r)try{const Q=!!y?.mergeInProgress?.head,je=!!(y?.rebaseInProgress?.headName||y?.rebaseInProgress?.onto);if(Q){const Ie=await n.continueMerge(r);Ie.conflict?(cs(Ie.conflictFiles??[]),Ss("merge"),xt(!0),jn(r,Ie.conflictFiles??[],"merge"),le.error(e("gitView.toast.mergeConflictsDetected"))):(nn(),le.success(e("gitView.toast.mergeCompleted")),await us(),await Ls())}else if(je){const Ie=await n.continueRebase(r);Ie.conflict?(cs(Ie.conflictFiles??[]),Ss("rebase"),xt(!0),jn(r,Ie.conflictFiles??[],"rebase"),le.error(e("gitView.toast.rebaseConflictsDetected"))):(nn(),le.success(e("gitView.toast.rebaseStepCompleted")),await us(),await Ls())}}catch(Q){const je=Q instanceof Error?Q.message:e("gitView.toast.continueOperationFailed");le.error(je)}},[r,n,y,us,Ls,jn,nn,e]),Rr=i.useCallback(async()=>{if(r)try{!!y?.mergeInProgress?.head?(await n.abortMerge(r),le.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),le.success(e("gitView.toast.rebaseAborted"))),nn(),await us(),await Ls()}catch(Q){const je=Q instanceof Error?Q.message:e("gitView.toast.abortOperationFailed");le.error(je)}},[r,n,y,us,Ls,nn,e]),ii=i.useCallback(()=>{if(!r)return;const je=!!y?.mergeInProgress?.head?"merge":"rebase",Ie=y?.files?.filter($e=>$e.index==="U"||$e.working_dir==="U").map($e=>$e.path)??[];Ie.length>0&&cs(Ie),Ss(je),xt(!0)},[r,y]),Si=i.useCallback(async Q=>{if(!r)return;const je=y?.current,Ie=ks,$e=qs,mt=(y?.files??[]).some(Lu);try{await n.stash(r,{message:`Auto-stash before ${Ie} with ${$e}`,includeUntracked:!0}),mt&&ne(r)}catch(Jt){const vs=Jt instanceof Error?Jt.message:"Failed to stash changes";le.error(vs);return}let It=!1,Qt=!1;try{if(Ie==="merge"){const Jt=await n.merge(r,{branch:$e});Jt.conflict?(Qt=!0,cs(Jt.conflictFiles??[]),Ss("merge"),xt(!0)):(It=!0,le.success(e("gitView.toast.mergedIntoBranch",{branch:$e,currentBranch:je||""})))}else{const Jt=await n.rebase(r,{onto:$e});Jt.conflict?(Qt=!0,cs(Jt.conflictFiles??[]),Ss("rebase"),xt(!0)):(It=!0,le.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:je||"",branch:$e})))}if(Q&&It)try{await n.stashPop(r),ne(r),le.success(e("gitView.toast.stashedRestored"))}catch(Jt){const vs=Jt instanceof Error?Jt.message:e("gitView.toast.restoreStashFailed");le.error(vs)}else Q&&Qt&&le.info(e("gitView.toast.restoreStashManually"));await us(),await Ls()}catch(Jt){if(Q)try{await n.stashPop(r),ne(r)}catch{}throw Jt}},[ne,r,n,y,ks,qs,us,Ls,e]),hn=i.useCallback(Q=>{pt(Q),r&&(H(r,Q),te(r,n,Q))},[r,te,n,H]),bo=i.useCallback(Q=>{vn(Q)},[]),wo=i.useCallback(()=>{Lt(null),r&&(ee(r,n),ie(r,n),te(r,n,st))},[r,ee,ie,te,st,n]),yo=i.useCallback(Q=>{if(Q.conflict){if(Q.operation==="cherry-pick"||Q.operation==="revert"){le.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:Q.conflictFiles?.join(", ")??"unknown files"})}),r&&(ee(r,n),ie(r,n),te(r,n,st));return}cs(Q.conflictFiles??[]),Ss(Q.operation),xt(!0),r&&jn(r,Q.conflictFiles??[],Q.operation)}},[e,cs,Ss,xt,jn,r,ee,ie,te,st,n]);return r?C===null||C===!0&&!y?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):C===!1?De?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(A,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(A,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.notGitRepositoryDescription")}),_.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:e("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:Pe("flex h-full flex-col overflow-hidden"),children:[s.jsx(rb,{status:y,localBranches:dt,remoteBranches:kt,branchInfo:I?.branches,syncAction:se,remotes:Wt,onFetch:Q=>ri("fetch",Q),onSync:Q=>ri("sync",Q),onRemoveRemote:yi,removingRemoteName:Tn,onCheckoutBranch:X,onCreateBranch:rr,onRenameBranch:Sn,activeIdentityProfile:Ys,availableIdentities:zs,onSelectIdentity:it,isApplyingIdentity:jt,isWorktreeMode:!!F,onOpenHistory:()=>Lt("history"),onOpenGraph:()=>Lt("graph"),onOpenStashes:ji,actionTabItems:Es,activeActionTab:ms,onSelectActionTab:Q=>Ns(Q)}),r&&(y?.mergeInProgress?.head||y?.rebaseInProgress?.headName||y?.rebaseInProgress?.onto)&&s.jsx(hv,{mergeInProgress:y?.mergeInProgress,rebaseInProgress:y?.rebaseInProgress,onContinue:Ui,onAbort:Rr,onResolveWithAI:ii,hasUnresolvedConflicts:mr,isLoading:D}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:Pe("min-w-0 min-h-0 h-full flex flex-col"),children:s.jsxs(On,{as:Qa,ref:O,outerClassName:"flex-1 min-h-0",className:Pe("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[ms==="commit"?s.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(Yn?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(ib,{groups:zi,diffStats:y?.diffStats,revertingPaths:qt,isRevertingAll:vt,onVisiblePathsChange:Ve,onRevertAll:Rn,onRevertDirectory:vi,headerBackgroundClassName:"bg-background"})}),s.jsx(ob,{stagedCount:xn,commitMessage:fe,onCommitMessageChange:$,generatedHighlights:Vt,onInsertHighlights:or,onGenerateMessage:ys,isGeneratingMessage:qe,onCommit:()=>Dr({pushAfter:!1}),onCommitAndPush:()=>Dr({pushAfter:!0}),commitAction:Ye,hasPendingIndexMutation:Ht,gitmojiEnabled:V,onOpenGitmojiPicker:()=>q(!0)})]}):s.jsx(hy,{onOpenStashes:()=>We(!0)})}):null,ms==="branch"?s.jsx("div",{className:"space-y-4",children:kn?s.jsxs(s.Fragment,{children:[s.jsx(pv,{mode:"inline",currentBranch:y?.current,localBranches:dt,remoteBranches:kt,defaultTargetBranch:bs,onMerge:Vn,onRebase:Hr,disabled:fr,isOperating:xe!==null,operationLogs:ut,onOperationComplete:Wi}),ln?s.jsx(fy,{repoRoot:ln.repoRoot,sourceBranch:ln.sourceBranch,worktreeMetadata:ln.worktreeMetadata,localBranches:dt,defaultTargetBranch:hs,refreshKey:St,onRefresh:()=>{r&&(ee(r,n),ie(r,n),te(r,n,st))}},ln.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})}):null,ms==="pr"?s.jsx("div",{className:"space-y-4",children:In?s.jsx(iv,{directory:In.directory,branch:In.branch,baseBranch:fs,trackingBranch:y?.tracking??void 0,remotes:Us,remoteBranches:kt,onGeneratedDescription:ss}):s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:e("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:e("gitView.pullRequest.createHint")})]})}):null]})})})}),s.jsx(_s,{open:Yt!==null,onOpenChange:Q=>{Q||Lt(null)},children:s.jsxs(Vs,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(tn,{children:[s.jsx(Gs,{children:e(Yt==="graph"?"gitView.graph.title":"gitView.history.title")}),s.jsx(dn,{children:e("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(Sy,{mode:Yt==="graph"?"graph":"history",log:Yt==="graph"?Fs??R:R,isLogLoading:Yt==="graph"&&sn||W,logMaxCount:Yt==="graph"?Pn:st,onLogMaxCountChange:Yt==="graph"?bo:hn,expandedCommitHashes:ns,onToggleCommit:Cs,commitFilesMap:Mt,loadingCommitHashes:$t,onCopyHash:gn,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Yt==="graph"?null:ft,onConflict:Yt==="graph"?yo:void 0,onActionSuccess:Yt==="graph"?wo:void 0})})]})}),s.jsx(my,{open:ae,onOpenChange:We,directory:r,hasUncommittedChanges:(y?.files?.length??0)>0,hasStagedChanges:un.length>0,uncommittedFileCount:y?.files?.length??0,onChanged:async Q=>{r&&Q?.affectsIndex&&ne(r),await us(!1),await Ls()}}),s.jsx(_s,{open:Se,onOpenChange:q,children:s.jsxs(Vs,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(tn,{className:"px-4 pt-4",children:s.jsx(Gs,{children:e("gitView.gitmoji.title")})}),s.jsxs(Ha,{className:"h-[420px]",children:[s.jsx(Ga,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:es,onValueChange:xs}),s.jsxs(Ka,{children:[s.jsx(qa,{children:e("gitView.gitmoji.empty")}),s.jsx(Qr,{children:(de.length===0?[]:de.filter(Q=>{const je=es.trim().toLowerCase();return je?Q.emoji.includes(je)||Q.code.toLowerCase().includes(je)||Q.description.toLowerCase().includes(je):!0})).map(Q=>s.jsxs(Jr,{onSelect:()=>Cn(Q.emoji,Q.code),children:[s.jsx("span",{className:"text-lg",children:Q.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Q.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Q.description})]},Q.code))})]})]})]})}),r&&s.jsx(ov,{open:zt,onOpenChange:xt,conflictFiles:ps,directory:r,operation:js,onAbort:bn,onClearState:nn}),s.jsx(mv,{open:Ge,onOpenChange:ds,operation:ks,targetBranch:qs,onConfirm:Si})]}):s.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:e("gitView.empty.selectSessionOrDirectory")})})},ac=5e3,Pv=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},Pl=(t,e)=>vg(jg.getState().dictionary,t,e),Iv=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")?"missing":"unreadable"},Rv=async(t,e)=>{if(t.readFile)return(await t.readFile(e,{optional:!0})).content??"";const n=new URLSearchParams({path:e,optional:"true"}),r=await Is(`/api/fs/read?${n.toString()}`,{cache:"no-store"});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to read file")}return r.text()},Yc=async(t,e)=>{try{const n=await Rv(t,e);return Pv(n,ac)>ac?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:Iv(n)}}},Qc=t=>{if(t==="too-large"){const e=ac.toLocaleString(oo());return Pl("contextFileOpen.failure.tooLarge",{count:e})}return Pl(t==="missing"?"contextFileOpen.failure.missing":"contextFileOpen.failure.unreadable")},Ev=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),An=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},sh=(t,e)=>{const n=An(e),r=An(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},Mv=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Fv=new Set(["node_modules"]),Ov=t=>Fv.has(t),Lv=t=>{const e=An(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Bv=8,Br=new Map,Vv=t=>{const e=Br.get(t);return e?(e.touchedAt=Date.now(),Br.delete(t),Br.set(t,e),e):null},Il=t=>{const e=Br.get(t);if(e)return e.touchedAt=Date.now(),e;if(Br.size>=Bv){const r=Br.keys().next().value;r!==void 0&&Br.delete(r)}const n={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return Br.set(t,n),n},_v=t=>{Br.delete(t)},nh=(t,e)=>s.jsx(ei,{filePath:t,extension:e}),$v=t=>{const e=gt.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const o=r[n];let a;return e[1]!==o?(a=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=a):a=e[2],a},zv=t=>{const e=gt.c(73),{node:n,root:r,isExpanded:o,isActive:a,status:c,badge:l,permissions:d,downloadFile:f,onSelect:m,onToggle:u,onRevealPath:p,onOpenDialog:x}=t,{t:b}=yt(),w=n.type==="directory",{canRename:g,canCreateFile:h,canCreateFolder:k,canDelete:j,canReveal:S}=d,[N,C]=i.useState(!1),[y,P]=i.useState(!1);let _;e[0]!==h||e[1]!==k||e[2]!==j||e[3]!==g||e[4]!==S?(_=Fe=>{!g&&!h&&!k&&!j&&!S||(Fe?.preventDefault(),P(!0))},e[0]=h,e[1]=k,e[2]=j,e[3]=g,e[4]=S,e[5]=_):_=e[5];const v=_;let F;e[6]!==w||e[7]!==n||e[8]!==m||e[9]!==u?(F=()=>{w?u(n.path):m(n)},e[6]=w,e[7]=n,e[8]=m,e[9]=u,e[10]=F):F=e[10];const I=F;let R;e[11]===Symbol.for("react.memo_cache_sentinel")?(R=Fe=>{Fe.stopPropagation(),P(!1),C(!0)},e[11]=R):R=e[11];const B=R;let D;e[12]!==h||e[13]!==k||e[14]!==j||e[15]!==g||e[16]!==S||e[17]!==f||e[18]!==w||e[19]!==n||e[20]!==x||e[21]!==p||e[22]!==b?(D=Fe=>{const{Item:z,Separator:K}=Fe;return s.jsxs(s.Fragment,{children:[g&&s.jsxs(z,{onClick:Y=>{Y.stopPropagation(),x("rename",n)},children:[s.jsx(A,{name:"edit",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.rename")]}),s.jsxs(z,{onClick:Y=>{Y.stopPropagation(),gr(n.path).then(me=>{if(me.ok){le.success(b("sidebarFilesTree.toast.pathCopied"));return}le.error(b("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(A,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.copyPath")]}),!w&&f&&s.jsxs(z,{onClick:Y=>{Y.stopPropagation(),f(n.path).catch(me=>{console.error("Download failed:",me),le.error(b("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(A,{name:"download",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.save")]}),S&&s.jsxs(z,{onClick:Y=>{Y.stopPropagation(),p(n.path)},children:[s.jsx(A,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",b(Ec())]}),w&&(h||k)&&s.jsxs(s.Fragment,{children:[s.jsx(K,{}),h&&s.jsxs(z,{onClick:Y=>{Y.stopPropagation(),x("createFile",n)},children:[s.jsx(A,{name:"file-add",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.newFile")]}),k&&s.jsxs(z,{onClick:Y=>{Y.stopPropagation(),x("createFolder",n)},children:[s.jsx(A,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.newFolder")]})]}),j&&s.jsxs(s.Fragment,{children:[s.jsx(K,{}),s.jsxs(z,{onClick:Y=>{Y.stopPropagation(),x("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.delete")]})]})]})},e[12]=h,e[13]=k,e[14]=j,e[15]=g,e[16]=S,e[17]=f,e[18]=w,e[19]=n,e[20]=x,e[21]=p,e[22]=b,e[23]=D):D=e[23];const W=D;let U;e[24]!==n.path||e[25]!==r?(U=Fe=>{const z=sh(r,n.path);!z||z==="."||(Fe.dataTransfer.setData("application/x-openchamber-file-path",z),Fe.dataTransfer.effectAllowed="copy")},e[24]=n.path,e[25]=r,e[26]=U):U=e[26];const L=U;let M;e[27]!==v?(M=s.jsx("div",{className:"group relative flex items-center",onContextMenu:v}),e[27]=v,e[28]=M):M=e[28];const ee=a?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let ie;e[29]!==ee?(ie=Pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",ee,"cursor-grab active:cursor-grabbing"),e[29]=ee,e[30]=ie):ie=e[30];let te;e[31]!==w||e[32]!==o||e[33]!==n.extension||e[34]!==n.path?(te=w?o?s.jsx(A,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(A,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):nh(n.path,n.extension),e[31]=w,e[32]=o,e[33]=n.extension,e[34]=n.path,e[35]=te):te=e[35];let H;e[36]!==n.name||e[37]!==n.path?(H=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[36]=n.name,e[37]=n.path,e[38]=H):H=e[38];let J;e[39]!==w||e[40]!==c?(J=!w&&c&&s.jsx($v,{status:c}),e[39]=w,e[40]=c,e[41]=J):J=e[41];let re;e[42]!==l||e[43]!==w?(re=w&&l&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[l.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",l.modified]}),l.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",l.added]})]}),e[42]=l,e[43]=w,e[44]=re):re=e[44];let oe;e[45]!==v||e[46]!==L||e[47]!==I||e[48]!==H||e[49]!==J||e[50]!==re||e[51]!==ie||e[52]!==te?(oe=s.jsxs("button",{type:"button",onClick:I,onContextMenu:v,draggable:!0,onDragStart:L,className:ie,children:[te,H,J,re]}),e[45]=v,e[46]=L,e[47]=I,e[48]=H,e[49]=J,e[50]=re,e[51]=ie,e[52]=te,e[53]=oe):oe=e[53];let ve;e[54]!==h||e[55]!==k||e[56]!==j||e[57]!==g||e[58]!==S||e[59]!==N||e[60]!==W||e[61]!==b?(ve=(g||h||k||j||S)&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(en,{open:N,onOpenChange:C,children:[s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Xs,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:B,title:b("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":b("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(A,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:b("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(Zs,{align:"end",side:"bottom",onCloseAutoFocus:()=>C(!1),children:W({Item:ls,Separator:$r})})]})}),e[54]=h,e[55]=k,e[56]=j,e[57]=g,e[58]=S,e[59]=N,e[60]=W,e[61]=b,e[62]=ve):ve=e[62];let ne;e[63]!==oe||e[64]!==ve||e[65]!==M?(ne=s.jsxs(Wc,{render:M,children:[oe,ve]}),e[63]=oe,e[64]=ve,e[65]=M,e[66]=ne):ne=e[66];let ye;e[67]!==W?(ye=s.jsx($c,{className:"min-w-[180px]",children:W({Item:zc,Separator:Mm})}),e[67]=W,e[68]=ye):ye=e[68];let he;return e[69]!==y||e[70]!==ne||e[71]!==ye?(he=s.jsxs(Uc,{open:y,onOpenChange:P,children:[ne,ye]}),e[69]=y,e[70]=ne,e[71]=ye,e[72]=he):he=e[72],he},Wv=(t,e)=>t.node===e.node&&t.root===e.root&&t.isExpanded===e.isExpanded&&t.isActive===e.isActive&&t.status===e.status&&t.badge===e.badge&&t.permissions===e.permissions&&t.downloadFile===e.downloadFile&&t.onSelect===e.onSelect&&t.onToggle===e.onToggle&&t.onRevealPath===e.onRevealPath&&t.onOpenDialog===e.onOpenDialog,Uv=i.memo(zv,Wv),Hv=()=>{const{t}=yt(),{files:e}=nr(),n=bi()??"",r=An(n.trim()),o=Xf(),a=Zf(),c=vc(T=>T.searchFiles),l=Ee(T=>T.openContextFile),d=Ja(n),[f,m]=i.useState(""),u=Za(f,200),p=i.useRef(null),[x,b]=i.useState([]),[w,g]=i.useState(!1),[h,k]=i.useState({}),[j,S]=i.useState({}),N=i.useRef(new Set),C=i.useRef(new Set),y=i.useRef(null);i.useEffect(()=>{if(!r){k({}),S({}),N.current=new Set;return}const T=Vv(r);T?(k({...T.childrenByDir}),S({...T.loadErrorsByDir}),N.current=new Set(T.loadedDirs)):(k({}),S({}),N.current=new Set)},[r]),i.useEffect(()=>{if(!r)return;const T=Il(r);T.childrenByDir=h},[r,h]),i.useEffect(()=>{if(!r)return;const T=Il(r);T.loadErrorsByDir=j},[r,j]),i.useEffect(()=>{if(!r)return;const T=Il(r);T.loadedDirs=new Set(N.current)},[r,h,j]),i.useEffect(()=>()=>{if(!r)return;const T=Br.get(r);T&&T.loadedDirs.size===0&&Object.keys(T.childrenByDir).length===0&&_v(r)},[r]);const P=i.useMemo(()=>[],[]),_=i.useMemo(()=>[],[]),v=cn(T=>r?T.byRoot[r]?.expandedPaths??P:P),F=cn(T=>r?T.byRoot[r]?.selectedPath??null:null),I=cn(T=>T.setSelectedPath),R=cn(T=>T.addOpenPath),B=cn(T=>T.removeOpenPathsByPrefix),D=cn(T=>T.toggleExpandedPath),W=Ee(T=>r?T.contextPanelByDirectory[r]?.tabs??_:_),U=i.useMemo(()=>new Set(W.map(T=>T.mode==="file"?T.targetPath:null).filter(T=>typeof T=="string"&&T.length>0).map(T=>An(T))),[W]),[L,M]=i.useState(null),[ee,ie]=i.useState(null),[te,H]=i.useState(""),[J,re]=i.useState(!1),oe=!!e.writeFile,ve=!!e.createDirectory,ne=!!e.rename,ye=!!e.delete,he=!!e.revealPath,Fe=i.useMemo(()=>({canRename:ne,canCreateFile:oe,canCreateFolder:ve,canDelete:ye,canReveal:he}),[ne,oe,ve,ye,he]),z=i.useCallback(T=>{e.revealPath&&e.revealPath(T).catch(()=>{le.error(t("sidebarFilesTree.toast.revealFailed"))})},[e,t]),K=i.useCallback((T,V)=>{M(T),ie(V),H(T==="rename"&&V.name||""),re(!1)},[]),Y=i.useCallback((T,V)=>{const we=V.filter(E=>E&&typeof E.name=="string"&&E.name.length>0).filter(E=>o||!E.name.startsWith(".")).filter(E=>a||!Ov(E.name)).map(E=>{const de=E.name,fe=An(E.path||""),$=fe?Mv(fe)?fe:An(`${T}/${fe}`):An(`${T}/${de}`),ke=E.isDirectory?"directory":"file",Ve=ke==="file"&&de.includes(".")?de.split(".").pop()?.toLowerCase():void 0;return{name:de,path:$,type:ke,extension:Ve}});return Ev(we)},[a,o]),me=i.useCallback(async(T,V)=>{const we=An(T.trim());if(!we||N.current.has(we)||C.current.has(we))return;C.current=new Set(C.current),C.current.add(we);const E=e.listDirectory?e.listDirectory(we).then(de=>de.entries.map(fe=>({name:fe.name,path:fe.path,isDirectory:fe.isDirectory}))):sr.listLocalDirectory(we).then(de=>de.map(fe=>({name:fe.name,path:fe.path,isDirectory:fe.isDirectory})));try{const de=await E;if(V?.())return;const fe=Y(we,de);N.current=new Set(N.current),N.current.add(we),S($=>{if(!$[we])return $;const ke={...$};return delete ke[we],ke}),k($=>({...$,[we]:fe}))}catch(de){if(V?.())return;const fe=de instanceof Error?de.message:String(de??"");console.error("Failed to load sidebar directory:",de),S($=>({...$,[we]:fe}))}finally{C.current=new Set(C.current),C.current.delete(we)}},[e,Y]),Ne=i.useCallback(async()=>{if(!r)return;y.current?.abort();const T=new AbortController;y.current=T;try{const we=(cn.getState().byRoot[r]?.expandedPaths??[]).map(fe=>An(fe)).filter(fe=>!!fe&&fe!==r&&fe.startsWith(`${r}/`)),E=[r,...we];N.current=new Set(N.current);for(const fe of E)N.current.delete(fe);S(fe=>{if(Object.keys(fe).length===0)return fe;const $={...fe};let ke=!1;for(const Ve of E)Ve in $&&(delete $[Ve],ke=!0);return ke?$:fe});const de=()=>T.signal.aborted;await me(r,de);for(let fe=0;fe<we.length&&!T.signal.aborted;fe+=3){const $=we.slice(fe,fe+3);await Promise.all($.map(ke=>me(ke,de)))}}catch(V){if(T.signal.aborted)return;console.error("Failed to refresh sidebar tree:",V)}finally{y.current===T&&(y.current=null)}},[me,r]),Be=i.useCallback(async T=>{if(!T){await Ne();return}const V=An(T);N.current=new Set(N.current),N.current.delete(V),C.current=new Set(C.current),C.current.delete(V),await me(V)},[me,Ne]);i.useEffect(()=>{r&&(y.current?.abort(),N.current=new Set,C.current=new Set,S({}),k(T=>Object.keys(T).length===0?T:{}),me(r))},[me,r,o,a]),i.useEffect(()=>{if(!r||v.length===0)return;const T=v.map(E=>An(E)).filter(E=>!!E&&E!==r&&E.startsWith(`${r}/`)&&!N.current.has(E)&&!C.current.has(E)).sort((E,de)=>E.split("/").length-de.split("/").length);if(T.length===0)return;let V=!1;const we=()=>V;return(async()=>{for(let E=0;E<T.length&&!V;E+=3){const de=T.slice(E,E+3);await Promise.all(de.map(fe=>me(fe,we)))}})(),()=>{V=!0}},[v,me,r]),i.useEffect(()=>{if(!n){b([]),g(!1);return}const T=u.trim();if(!T){b([]),g(!1);return}let V=!1;return g(!0),c(n,T,150,{includeHidden:o,respectGitignore:!a,type:"file"}).then(we=>{if(V)return;const de=we.filter(fe=>a||!Lv(fe.path)).map(fe=>({name:fe.name,path:An(fe.path),type:"file",extension:fe.extension,relativePath:fe.relativePath}));b(de)}).catch(()=>{V||b([])}).finally(()=>{V||g(!1)}),()=>{V=!0}},[n,u,c,o,a]);const _e=i.useMemo(()=>{const T=new Map;if(!d?.files)return T;for(const V of d.files)V.index==="A"||V.working_dir==="?"?T.set(V.path,"git-added"):V.index==="D"?T.set(V.path,"git-deleted"):(V.index==="M"||V.working_dir==="M")&&T.set(V.path,"git-modified");return T},[d]),Oe=i.useMemo(()=>{const T=new Map;if(!d?.files||!r)return T;for(const V of d.files){const we=V.index==="M"||V.working_dir==="M",E=V.index==="A"||V.working_dir==="?";if(!we&&!E)continue;const de=V.path.split("/");if(de.length<=1)continue;let fe=r;for(let $=0;$<de.length-1;$++){fe=`${fe}/${de[$]}`;let ke=T.get(fe);ke||(ke={modified:0,added:0},T.set(fe,ke)),we&&ke.modified++,E&&ke.added++}}return T},[d,r]),pe=i.useCallback(T=>{if(U.has(T))return"open";if(_e.size===0)return null;const V=T.startsWith(r+"/")?T.slice(r.length+1):T;return _e.get(V)??null},[U,_e,r]),Re=i.useCallback(T=>{if(Oe.size===0)return null;const V=Oe.get(T);return V&&V.modified+V.added>0?V:null},[Oe]),ge=i.useCallback(async T=>{if(!r)return;const V=await Yc(e,T.path);if(!V.ok){le.error(Qc(V.reason));return}I(r,T.path),R(r,T.path),l(r,T.path)},[R,e,l,r,I]),ce=i.useCallback(async T=>{const V=An(T);r&&(D(r,V),N.current.has(V)||await me(V))},[me,r,D]),Ce=i.useCallback(async T=>{if(T?.preventDefault(),!ee||!L)return;re(!0);const V=()=>re(!1),we=()=>M(null);if(L==="createFile"){if(!te.trim()){le.error(t("sidebarFilesTree.toast.filenameRequired")),V();return}if(!e.writeFile){le.error(t("sidebarFilesTree.toast.writeNotSupported")),V();return}const E=ee.path,de=E?`${E}/`:"",fe=An(`${de}${te.trim()}`);await e.writeFile(fe,"").then(async $=>{$.success&&(le.success(t("sidebarFilesTree.toast.fileCreated")),await Be(E)),we()}).catch(()=>le.error(t("sidebarFilesTree.toast.operationFailed"))).finally(V);return}if(L==="createFolder"){if(!te.trim()){le.error(t("sidebarFilesTree.toast.folderNameRequired")),V();return}const E=ee.path,de=E?`${E}/`:"",fe=An(`${de}${te.trim()}`);await e.createDirectory(fe).then(async $=>{$.success&&(le.success(t("sidebarFilesTree.toast.folderCreated")),await Be(E)),we()}).catch(()=>le.error(t("sidebarFilesTree.toast.operationFailed"))).finally(V);return}if(L==="rename"){if(!te.trim()){le.error(t("sidebarFilesTree.toast.nameRequired")),V();return}if(!e.rename){le.error(t("sidebarFilesTree.toast.renameNotSupported")),V();return}const E=ee.path,de=E.split("/").slice(0,-1).join("/"),fe=de?`${de}/`:"",$=An(`${fe}${te.trim()}`);await e.rename(E,$).then(async ke=>{ke.success&&(le.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await Be(de),r&&B(r,E),(F===E||F&&F.startsWith(`${E}/`))&&I(r,null)),we()}).catch(()=>le.error(t("sidebarFilesTree.toast.operationFailed"))).finally(V);return}if(L==="delete"){if(!e.delete){le.error(t("sidebarFilesTree.toast.deleteNotSupported")),V();return}const E=ee.path,de=E.split("/").slice(0,-1).join("/");await e.delete(E).then(async fe=>{fe.success&&(le.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await Be(de),r&&B(r,E),(F===E||F&&F.startsWith(E+"/"))&&I(r,null)),we()}).catch(()=>le.error(t("sidebarFilesTree.toast.operationFailed"))).finally(V);return}V()},[L,ee,te,e,Be,B,r,F,I,t]);function be(T,V){const we=h[T]??[];return we.map((E,de)=>{const fe=E.type==="directory",$=fe&&v.includes(E.path),ke=F===E.path,Ve=de===we.length-1;return s.jsxs("li",{className:"relative",children:[V>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Ve&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(Uv,{node:E,root:r,isExpanded:$,isActive:ke,status:fe?void 0:pe(E.path),badge:fe?Re(E.path):void 0,permissions:Fe,downloadFile:e.downloadFile,onSelect:ge,onToggle:ce,onRevealPath:z,onOpenDialog:K}),fe&&$&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[j[E.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:j[E.path],children:j[E.path]}),s.jsxs(ze,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Be(E.path)},children:[s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):null,be(E.path,V+1)]})]},E.path)})}const ue=!!(r&&h[r]),De=r?j[r]:null;return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"relative min-w-0 flex-1",children:[s.jsx(A,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Ln,{ref:p,value:f,onChange:T=>m(T.target.value),placeholder:t("sidebarFilesTree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),f.trim().length>0?s.jsx("button",{type:"button","aria-label":t("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{m(""),p.current?.focus()},children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null]}),oe&&s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>K("createFile",{path:n,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFileTitle"),"aria-label":t("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(A,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFileTitle")})]}),ve&&s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>K("createFolder",{path:n,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFolderTitle"),"aria-label":t("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(A,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFolderTitle")})]}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>{Ne()},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.refreshTitle"),"aria-label":t("sidebarFilesTree.actions.refreshTitle"),children:s.jsx(A,{name:"refresh",className:"h-4 w-4"})})})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.refreshTitle")})]})]}),s.jsx(On,{outerClassName:"flex-1 min-h-0",className:"p-2",children:s.jsx("ul",{className:"flex flex-col",children:w?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("sidebarFilesTree.state.searching")]}):x.length>0?x.map(T=>{const V=F===T.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>ge(T),draggable:!0,onDragStart:we=>{const E=T.relativePath||sh(r??"",T.path);!E||E==="."||(we.dataTransfer.setData("application/x-openchamber-file-path",E),we.dataTransfer.effectAllowed="copy")},className:Pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",V?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:T.path,children:[nh(T.path,T.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:T.relativePath??T.path})]})},T.path)}):De?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:De}),s.jsxs(ze,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{Ne()},children:[s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):ue&&r?be(r,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("sidebarFilesTree.state.loading")})})}),s.jsx(_s,{open:!!L,onOpenChange:T=>!T&&M(null),children:s.jsxs(Vs,{children:[s.jsxs(tn,{children:[s.jsxs(Gs,{children:[L==="createFile"&&t("sidebarFilesTree.dialog.createFile.title"),L==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.title"),L==="rename"&&t("sidebarFilesTree.dialog.rename.title"),L==="delete"&&t("sidebarFilesTree.dialog.delete.title")]}),s.jsxs(dn,{children:[L==="createFile"&&t("sidebarFilesTree.dialog.createFile.description",{path:ee?.path??t("sidebarFilesTree.dialog.rootFallback")}),L==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.description",{path:ee?.path??t("sidebarFilesTree.dialog.rootFallback")}),L==="rename"&&t("sidebarFilesTree.dialog.rename.description",{name:ee?.name??""}),L==="delete"&&t("sidebarFilesTree.dialog.delete.description",{name:ee?.name??""})]})]}),L!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Ln,{value:te,onChange:T=>H(T.target.value),placeholder:t(L==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:T=>{T.key==="Enter"&&Ce()},autoFocus:!0})}),s.jsxs(xr,{children:[s.jsx(ze,{variant:"outline",onClick:()=>M(null),disabled:J,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(ze,{variant:L==="delete"?"destructive":"default",onClick:()=>{Ce()},disabled:J||L!=="delete"&&!te.trim(),children:J?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t(L==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})},Gv=t=>t==="git"||t==="files"||t==="context",Kv="files",qv=()=>!(typeof document<"u"&&document.hidden||typeof navigator<"u"&&!navigator.onLine);function Yv(t,e,n,r){const o=gt.c(6),{git:a}=nr(),c=yn(Qv),l=!!(t&&a&&e&&n==="git"&&r!=="git");let d,f;o[0]!==t||o[1]!==c||o[2]!==a||o[3]!==l?(d=()=>{if(!l||!t||!a)return;c(t,a);const m=window.setInterval(()=>{qv()&&c(t,a)},1e4);return()=>window.clearInterval(m)},f=[l,t,a,c],o[0]=t,o[1]=c,o[2]=a,o[3]=l,o[4]=d,o[5]=f):(d=o[4],f=o[5]),i.useEffect(d,f)}function Qv(t){return t.ensureStatus}const rh=()=>{const t=gt.c(17),e=Ds(Xv),n=Ds(Zv),r=Js(e1),o=yn(t1);let a;e:{if(e){let b;t[0]!==e||t[1]!==n?(b=n.find(w=>w.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=b):b=t[2],a=b;break e}a=n[0]??null}const c=a;let l;e:{if(!c){l=null;break e}let b;t[3]!==c.id||t[4]!==c.path?(b={id:c.id,path:c.path},t[3]=c.id,t[4]=c.path,t[5]=b):b=t[5],l=b}const d=l;let f;e:{if(!c){f=null;break e}let b;t[6]!==c.label||t[7]!==c.path||t[8]!==r?(b=c.label?.trim()||ho(c.path,r)||c.path,t[6]=c.label,t[7]=c.path,t[8]=r,t[9]=b):b=t[9],f=b}const m=f;let u;e:{if(!c){u=!1;break e}let b;t[10]!==c.path||t[11]!==o?(b=o.get(c.path)?.isGitRepo,t[10]=c.path,t[11]=o,t[12]=b):b=t[12],u=b===!0}const p=u;let x;return t[13]!==p||t[14]!==m||t[15]!==d?(x=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-background",children:s.jsx(Hw,{projectRef:d,projectLabel:m,canCreateWorktree:p})}),t[13]=p,t[14]=m,t[15]=d,t[16]=x):x=t[16],x},Jv=()=>{const t=gt.c(57),{t:e}=yt(),n=Ee(s1),r=Ee(n1),o=Ee(r1),a=Ee(i1),c=bi();Yv(c,o,n,a);const l=a==="git"?"git":a==="context"?"context":null;let d,f;t[0]!==l||t[1]!==n||t[2]!==r?(d=()=>{l&&n===l&&r(Kv)},f=[l,n,r],t[0]=l,t[1]=n,t[2]=r,t[3]=d,t[4]=f):(d=t[3],f=t[4]),i.useEffect(d,f);let m;t[5]!==e?(m=e("layout.rightSidebar.git"),t[5]=e,t[6]=m):m=t[6];let u;t[7]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"}),t[7]=u):u=t[7];let p;t[8]!==m?(p={id:"git",label:m,icon:u},t[8]=m,t[9]=p):p=t[9];let x;t[10]!==e?(x=e("layout.rightSidebar.files"),t[10]=e,t[11]=x):x=t[11];let b;t[12]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(A,{name:"folder-3",className:"h-3.5 w-3.5"}),t[12]=b):b=t[12];let w;t[13]!==x?(w={id:"files",label:x,icon:b},t[13]=x,t[14]=w):w=t[14];let g;t[15]!==e?(g=e("layout.rightSidebar.context"),t[15]=e,t[16]=g):g=t[16];let h;t[17]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(A,{name:"file-list-2",className:"h-3.5 w-3.5"}),t[17]=h):h=t[17];let k;t[18]!==g?(k={id:"context",label:g,icon:h},t[18]=g,t[19]=k):k=t[19];let j;t[20]!==k||t[21]!==p||t[22]!==w?(j=[p,w,k],t[20]=k,t[21]=p,t[22]=w,t[23]=j):j=t[23];const S=j;let N;t[24]!==l||t[25]!==S?(N=l?S.filter(re=>re.id!==l):S,t[24]=l,t[25]=S,t[26]=N):N=t[26];const C=N,y=o&&n==="git"&&l!=="git";let P;t[27]!==r?(P=re=>{Gv(re)&&r(re)},t[27]=r,t[28]=P):P=t[28];const _=P;let v;t[29]!==_||t[30]!==n||t[31]!==C?(v=s.jsx("div",{className:"h-9 bg-background pt-1 px-2",children:s.jsx(Vo,{items:C,activeId:n,onSelect:_,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[29]=_,t[30]=n,t[31]=C,t[32]=v):v=t[32];const F=n!=="git"&&"hidden";let I;t[33]!==F?(I=Pe("h-full",F),t[33]=F,t[34]=I):I=t[34];let R;t[35]!==y?(R=s.jsx(oc,{isActive:y}),t[35]=y,t[36]=R):R=t[36];let B;t[37]!==I||t[38]!==R?(B=s.jsx("div",{className:I,children:R}),t[37]=I,t[38]=R,t[39]=B):B=t[39];const D=n!=="files"&&"hidden";let W;t[40]!==D?(W=Pe("h-full",D),t[40]=D,t[41]=W):W=t[41];let U;t[42]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(Hv,{}),t[42]=U):U=t[42];let L;t[43]!==W?(L=s.jsx("div",{className:W,children:U}),t[43]=W,t[44]=L):L=t[44];const M=n!=="context"&&"hidden";let ee;t[45]!==M?(ee=Pe("h-full",M),t[45]=M,t[46]=ee):ee=t[46];let ie;t[47]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(rh,{}),t[47]=ie):ie=t[47];let te;t[48]!==ee?(te=s.jsx("div",{className:ee,children:ie}),t[48]=ee,t[49]=te):te=t[49];let H;t[50]!==B||t[51]!==L||t[52]!==te?(H=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[B,L,te]}),t[50]=B,t[51]=L,t[52]=te,t[53]=H):H=t[53];let J;return t[54]!==v||t[55]!==H?(J=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-background",children:[v,H]}),t[54]=v,t[55]=H,t[56]=J):J=t[56],J};function Xv(t){return t.activeProjectId}function Zv(t){return t.projects}function e1(t){return t.homeDirectory}function t1(t){return t.directories}function s1(t){return t.rightSidebarTab}function n1(t){return t.setRightSidebarTab}function r1(t){return t.isRightSidebarOpen}function i1(t){return t.activeMainTab}const o1=64,a1=3,Pi=new Map,l1=(t,e,n=a1)=>{const r=`${t}\0${n}\0${e}`,o=Pi.get(r);if(o)return Pi.delete(r),Pi.set(r,o),o;const a=d1(e),c=a?Yh(Qh(e,n),{oldFile:{name:t,contents:a.before},newFile:{name:t,contents:a.after}})??Vu(t):Jh(c1(t,e))[0]?.files[0]??Vu(t);for(Pi.set(r,c);Pi.size>o1;){const l=Pi.keys().next().value;if(!l)break;Pi.delete(l)}return c},c1=(t,e)=>!e.trim()||e.startsWith("diff --git ")||/^--- [^\n]*\r?\n\+\+\+ /m.test(e)?e:`Index: ${t}
|
|
14
|
+
===================================================================
|
|
15
|
+
--- ${t}
|
|
16
|
+
+++ ${t}
|
|
17
|
+
${e}`,d1=t=>{if(!t.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(t))return;const e=[...t.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(e.length!==1)return;const n=e[0],r=Number.parseInt(n[1]??"",10),o=Number.parseInt(n[2]??"",10);if(r>1||o>1||!Number.isFinite(r)||!Number.isFinite(o))return;const a=(n.index??0)+n[0].length,c=t.slice(a),l=[],d=[];let f;for(const m of c.split(/\r?\n/)){if(m.startsWith("diff --git ")||m.startsWith("@@ "))break;if(m.startsWith("\\")){if(f==="-"||f===" "){const u=l.at(-1);u&&(u.newline=!1)}if(f==="+"||f===" "){const u=d.at(-1);u&&(u.newline=!1)}continue}if(m.startsWith("-")){l.push({text:m.slice(1),newline:!0}),f="-";continue}if(m.startsWith("+")){d.push({text:m.slice(1),newline:!0}),f="+";continue}m.startsWith(" ")&&(l.push({text:m.slice(1),newline:!0}),d.push({text:m.slice(1),newline:!0}),f=" ")}return{before:Bu(l),after:Bu(d)}},Bu=t=>t.map(e=>e.text+(e.newline?`
|
|
18
|
+
`:"")).join(""),Vu=t=>Xh({name:t,contents:""},{name:t,contents:""}),_u=t=>{if(!t)return null;const e=t.split(`
|
|
19
|
+
`);let n=null;for(const r of e){const o=r.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(o){const a=Number.parseInt(o[1]??"",10);n=Number.isFinite(a)&&a>=1?a:null;continue}if(n!==null){if(r.startsWith(" ")){n+=1;continue}if(r.startsWith("+"))return n;if(r.startsWith("-"))return Math.max(1,n)}}return null},u1=1100,f1=15e3,$u=500,zu=300,m1=1e6,h1=3,p1=t=>t<=6?t:t<=12?6:t<=25?4:2,g1=i.memo(()=>{const t=gt.c(4),{t:e}=yt();let n;t[0]!==e?(n=e("diffView.binary.unavailable"),t[0]=e,t[1]=n):n=t[1];let r;return t[2]!==n?(r=s.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:n})}),t[2]=n,t[3]=r):r=t[3],r}),ih={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},x1=ih.M,b1=t=>{const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"},oh=t=>{const e=b1(t);return ih[e]??x1},w1=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},Wu=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},Uu=t=>!!t.working_dir?.trim()||t.index==="?",y1=(t,e)=>Cg(t,e),Hu=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Gu=(t,e)=>{const n=t.split(`
|
|
20
|
+
`),r=e.split(`
|
|
21
|
+
`),o=Math.min(n.length,r.length);for(let a=0;a<o;a+=1)if(n[a]!==r[a])return a+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},v1=t=>/^Binary files .+ differ$/m.test(t)||/^GIT binary patch$/m.test(t),j1=t=>Array.isArray(t)?t.filter(e=>!e||typeof e!="object"?!1:typeof e.file=="string"):[],S1=t=>t==="added"?"A":t==="deleted"?"D":"M",ah=(t,e,n)=>v1(e)?{original:"",modified:"",isBinary:!0,patch:e,contextMode:n}:{original:"",modified:"",patch:e,fileDiff:l1(t,e),contextMode:n},lh=(t,e,n)=>{const r=t??0,o=e??0;return!r&&!o?null:s.jsxs("span",{className:Pe("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",n?.className),children:[r?s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",r]}):null,o?s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",o]}):null]})},N1=i.memo(t=>{const e=gt.c(53),{scope:n,workingCount:r,stagedCount:o,turnCount:a,onScopeChange:c}=t,{t:l}=yt(),[d,f]=i.useState(!1),m=n==="staged"?o:n==="turn"?a:r;let u;e[0]!==n||e[1]!==l?(u=l(n==="staged"?"diffView.scope.staged":n==="turn"?"diffView.scope.lastTurn":"diffView.scope.changed"),e[0]=n,e[1]=l,e[2]=u):u=e[2];const p=u;let x;e[3]!==l?(x=l("diffView.scope.selectorAria"),e[3]=l,e[4]=x):x=e[4];let b;e[5]!==m?(b=s.jsxs("span",{className:"diff-toolbar__scope-count",children:[": ",m]}),e[5]=m,e[6]=b):b=e[6];let w;e[7]!==p||e[8]!==b?(w=s.jsxs("span",{className:"whitespace-nowrap",children:[p,b]}),e[7]=p,e[8]=b,e[9]=w):w=e[9];let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"}),e[10]=g):g=e[10];let h;e[11]!==x||e[12]!==w?(h=s.jsx(Xs,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":x,children:[w,g]})}),e[11]=x,e[12]=w,e[13]=h):h=e[13];let k;e[14]!==c?(k=U=>{(U==="working"||U==="staged"||U==="turn")&&(c?.(U),f(!1))},e[14]=c,e[15]=k):k=e[15];let j;e[16]!==l?(j=l("diffView.scope.changed"),e[16]=l,e[17]=j):j=e[17];let S;e[18]!==j?(S=s.jsx("span",{children:j}),e[18]=j,e[19]=S):S=e[19];let N;e[20]!==r?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:r}),e[20]=r,e[21]=N):N=e[21];let C;e[22]!==N||e[23]!==S?(C=s.jsx(fl,{value:"working",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[S,N]})}),e[22]=N,e[23]=S,e[24]=C):C=e[24];let y;e[25]!==l?(y=l("diffView.scope.staged"),e[25]=l,e[26]=y):y=e[26];let P;e[27]!==y?(P=s.jsx("span",{children:y}),e[27]=y,e[28]=P):P=e[28];let _;e[29]!==o?(_=s.jsx("span",{className:"typography-meta text-muted-foreground",children:o}),e[29]=o,e[30]=_):_=e[30];let v;e[31]!==P||e[32]!==_?(v=s.jsx(fl,{value:"staged",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[P,_]})}),e[31]=P,e[32]=_,e[33]=v):v=e[33];let F;e[34]!==l?(F=l("diffView.scope.lastTurn"),e[34]=l,e[35]=F):F=e[35];let I;e[36]!==F?(I=s.jsx("span",{children:F}),e[36]=F,e[37]=I):I=e[37];let R;e[38]!==a?(R=s.jsx("span",{className:"typography-meta text-muted-foreground",children:a}),e[38]=a,e[39]=R):R=e[39];let B;e[40]!==I||e[41]!==R?(B=s.jsx(fl,{value:"turn",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[I,R]})}),e[40]=I,e[41]=R,e[42]=B):B=e[42];let D;e[43]!==n||e[44]!==C||e[45]!==v||e[46]!==B||e[47]!==k?(D=s.jsx(Zs,{align:"start",className:"w-40",children:s.jsxs(Ag,{value:n,onValueChange:k,children:[C,v,B]})}),e[43]=n,e[44]=C,e[45]=v,e[46]=B,e[47]=k,e[48]=D):D=e[48];let W;return e[49]!==d||e[50]!==D||e[51]!==h?(W=s.jsxs(en,{open:d,onOpenChange:f,children:[h,D]}),e[49]=d,e[50]=D,e[51]=h,e[52]=W):W=e[52],W}),k1=i.memo(t=>{const e=gt.c(11),{changedFiles:n,selectedFile:r,onSelectFile:o}=t,{t:a}=yt();if(n.length===0)return null;let c;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==a){let d;e[5]!==o||e[6]!==r||e[7]!==a?(d=f=>{const m=oh(f),u=r===f.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>o(f.path),className:Pe("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(ei,{filePath:f.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:m.color},title:a(m.descriptionKey),"aria-label":a(m.descriptionKey),children:m.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:f.path,children:f.path}),lh(f.insertions,f.deletions)]})},f.path)},e[5]=o,e[6]=r,e[7]=a,e[8]=d):d=e[8],c=n.map(d),e[0]=n,e[1]=o,e[2]=r,e[3]=a,e[4]=c}else c=e[4];let l;return e[9]!==c?(l=s.jsx(On,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:c})}),e[9]=c,e[10]=l):l=e[10],l}),C1=i.memo(t=>{const e=gt.c(20),{filePath:n,diff:r,renderSideBySide:o}=t,{t:a}=yt(),c=r.original.length>0,l=r.modified.length>0,d=o?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",f=o?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={contain:"layout"},e[0]=m):m=e[0];let u;e[1]!==r.original||e[2]!==n||e[3]!==c||e[4]!==f||e[5]!==o||e[6]!==a?(u=c&&s.jsxs("div",{className:f,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a("diffView.image.original")}),s.jsx("img",{src:r.original,alt:a("diffView.image.originalAlt",{path:n}),className:o?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=c,e[4]=f,e[5]=o,e[6]=a,e[7]=u):u=e[7];let p;e[8]!==r.modified||e[9]!==n||e[10]!==l||e[11]!==c||e[12]!==f||e[13]!==o||e[14]!==a?(p=l&&s.jsxs("div",{className:f,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:a("diffView.image.modifiedAlt",{path:n}),className:o?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=l,e[11]=c,e[12]=f,e[13]=o,e[14]=a,e[15]=p):p=e[15];let x;return e[16]!==d||e[17]!==u||e[18]!==p?(x=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[u,p]})}),e[16]=d,e[17]=u,e[18]=p,e[19]=x):x=e[19],x}),A1=i.memo(t=>{const e=gt.c(16),{filePath:n,diff:r,renderSideBySide:o,wrapLines:a}=t;let c;e[0]!==n?(c=Bi(n)||"text",e[0]=n,e[1]=c):c=e[1];const l=c;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(g1,{}),e[2]=m):m=e[2],m}if(Vi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==o?(m=s.jsx(C1,{filePath:n,diff:r,renderSideBySide:o}),e[3]=r,e[4]=n,e[5]=o,e[6]=m):m=e[6],m}let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[7]=d):d=e[7];let f;return e[8]!==r.fileDiff||e[9]!==r.modified||e[10]!==r.original||e[11]!==n||e[12]!==l||e[13]!==o||e[14]!==a?(f=s.jsx("div",{className:"w-full",style:d,children:s.jsx(Em,{original:r.original,modified:r.modified,fileDiff:r.fileDiff,language:l,fileName:n,renderSideBySide:o,wrapLines:a,layout:"inline"})}),e[8]=r.fileDiff,e[9]=r.modified,e[10]=r.original,e[11]=n,e[12]=l,e[13]=o,e[14]=a,e[15]=f):f=e[15],f}),D1=i.memo(t=>{const e=gt.c(7),{filePath:n,staged:r,busyAction:o,disabled:a,onAction:c}=t,{t:l}=yt();let d;return e[0]!==o||e[1]!==a||e[2]!==n||e[3]!==c||e[4]!==r||e[5]!==l?(d=s.jsx("div",{className:"flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-lg backdrop-blur-md",children:r?s.jsx(Rl,{label:l("gitView.changes.unstageFileAria",{path:n}),icon:"arrow-go-back",loading:o==="unstage",disabled:a,onClick:()=>c("unstage")}):s.jsxs(s.Fragment,{children:[s.jsx(Rl,{label:l("gitView.changes.revertFileAria",{path:n}),icon:"arrow-go-back",loading:o==="discard",disabled:a,tone:"failure",onClick:()=>c("discard")}),s.jsx(Rl,{label:l("gitView.changes.stageFileAria",{path:n}),icon:"add",loading:o==="stage",disabled:a,tone:"success",onClick:()=>c("stage")})]})}),e[0]=o,e[1]=a,e[2]=n,e[3]=c,e[4]=r,e[5]=l,e[6]=d):d=e[6],d}),Rl=t=>{const e=gt.c(14),{label:n,icon:r,loading:o,disabled:a,tone:c,onClick:l}=t,d=c==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",f=c==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]";let m;e[0]!==d||e[1]!==f?(m=Pe("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",d,f),e[0]=d,e[1]=f,e[2]=m):m=e[2];let u;e[3]!==l?(u=b=>{b.stopPropagation(),l()},e[3]=l,e[4]=u):u=e[4];let p;e[5]!==r||e[6]!==o?(p=o?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:r,className:r==="add"?"size-4":"size-3.5"}),e[5]=r,e[6]=o,e[7]=p):p=e[7];let x;return e[8]!==a||e[9]!==n||e[10]!==m||e[11]!==u||e[12]!==p?(x=s.jsx(ze,{variant:"ghost",size:"sm",className:m,disabled:a,title:n,"aria-label":n,onClick:u,children:p}),e[8]=a,e[9]=n,e[10]=m,e[11]=u,e[12]=p,e[13]=x):x=e[13],x},T1=i.memo(({directory:t,file:e,layout:n,wrapLines:r,isSelected:o,isExpanded:a,isMounted:c,onSelect:l,onExpandedChange:d,registerSectionRef:f,showOpenInEditorAction:m=!1,isOpeningInEditor:u=!1,onOpenInEditor:p,staged:x=!1,loadFullFiles:b=!1,initialDiffData:w=null})=>{const{t:g}=yt(),{git:h}=nr(),k=yn(i.useCallback(K=>K.directories.get(t)?.diffCache.get(e.path)??null,[t,e.path])),j=yn(K=>K.setDiff),S=yn(K=>K.fetchStatus),N=Ee(K=>K.setDiffFileLayout),[C,y]=i.useState(0),[P,_]=i.useState(null),[v,F]=i.useState(!1),[I,R]=i.useState(null),[B,D]=i.useState(!1),[W,U]=i.useState(null),[L,M]=i.useState(null),ee=i.useRef(null),ie=i.useRef(null),te=i.useMemo(()=>oh(e),[e]),H=n==="side-by-side",J=b?"full":"patch",re=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,oe=i.useMemo(()=>w||(x?L:W||(k?{original:k.original,modified:k.modified,isBinary:k.isBinary,contextMode:"full"}:null)),[k,w,W,x,L]),ve=oe?.contextMode===J,ne=i.useCallback(K=>{ie.current=K,f(e.path,K)},[e.path,f]),ye=i.useCallback(K=>{d(e.path,K)},[e.path,d]),he=i.useCallback(()=>{l(e.path)},[e.path,l]);i.useEffect(()=>{x?M(null):U(null),_(null),ee.current=null},[re,x]),i.useEffect(()=>{if(!a||!c)return;if(!t||w||oe&&ve){ee.current=null,F(!1);return}const K=`${t}::${e.path}::${x?"staged":"unstaged"}::${re}::${J}::${C}`;if(ee.current===K)return;ee.current=K,_(null),F(!0);let Y=!1;const me=b?m1:h1,Ne=Vi(e.path)?h.getGitFileDiff(t,{path:e.path,staged:x}):h.getGitDiff(t,{path:e.path,staged:x,contextLines:me}),Be=f1,_e=new Promise((Oe,pe)=>{setTimeout(()=>pe(new Error(`Timed out after ${Be}ms`)),Be)});return Promise.race([Ne,_e]).then(Oe=>{if(!Y){if("diff"in Oe){const pe=ah(e.path,Oe.diff,J);x?M(pe):U(pe)}else{const pe={original:Oe.original??"",modified:Oe.modified??"",isBinary:Oe.isBinary,contextMode:"full"};x?M(pe):j(t,e.path,pe)}F(!1)}}).catch(Oe=>{if(Y)return;const pe=Oe instanceof Error?Oe.message:String(Oe);_(pe),F(!1)}),()=>{Y=!0,ee.current===K&&(ee.current=null)}},[J,oe,ve,C,t,e.path,re,h,w,a,c,b,j,x]);const Fe=i.useCallback(()=>{ye(!a),he()},[ye,he,a]),z=i.useCallback(async K=>{if(!(!t||I!==null)){R(K);try{K==="stage"?await h.stageGitFile(t,e.path):K==="unstage"?await h.unstageGitFile(t,e.path):await h.revertGitFile(t,e.path,{scope:"working"}),y(Y=>Y+1),await S(t,h)}catch(Y){const me=K==="unstage"?"gitView.toast.unstageFileFailed":K==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.revertFailed";le.error(Y instanceof Error?Y.message:g(me))}finally{R(Y=>Y===K?null:Y)}}},[t,S,e.path,I,h,g]);return s.jsxs("div",{ref:ne,className:"scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0",children:[s.jsx("div",{className:"sticky top-0 z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80",children:s.jsxs("div",{role:"button",tabIndex:0,onClick:Fe,onKeyDown:K=>{K.target===K.currentTarget&&(K.key==="Enter"||K.key===" ")&&(K.preventDefault(),Fe())},className:Pe("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",o?"bg-[var(--interactive-selection)]/35":null),children:[s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:a?s.jsx(A,{name:"arrow-down-s",className:"size-4"}):s.jsx(A,{name:"arrow-right-s",className:"size-4"})}),s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:te.color},title:g(te.descriptionKey),"aria-label":g(te.descriptionKey),children:te.code}),s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(ei,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const K=e.path.lastIndexOf("/");if(K===-1)return s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const Y=e.path.slice(0,K),me=e.path.slice(K+1);return s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:Y}),s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[s.jsx("span",{className:"text-muted-foreground",children:"/"}),s.jsx("span",{className:"text-foreground",children:me})]})]})})()]})})]}),s.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[lh(e.insertions,e.deletions),m&&p?s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:g("diffView.actions.openFileInEditorAtChange"),onClick:K=>{K.stopPropagation(),p(e.path,oe)},disabled:u,children:u?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"edit",className:"size-3.5"})}):null,s.jsx(fm,{mode:H?"side-by-side":"unified",onModeChange:K=>{const Y=K==="side-by-side"?"side-by-side":"inline";N(e.path,Y)},className:"opacity-70"})]})]})}),a&&s.jsxs("div",{className:"relative bg-background overflow-hidden",children:[!c&&!P?s.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,P?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:g("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:P}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>y(K=>K+1),children:g("diffView.actions.retry")})]}):null,c&&v&&!oe&&!P?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),g("diffView.state.loadingDiff")]}):null,c&&oe&&!B&&e.insertions+e.deletions>$u?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:g("diffView.state.largeDiff",{count:e.insertions+e.deletions})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:g("diffView.state.largeDiffDescription")}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>D(!0),children:g("diffView.actions.renderAnyway")})]}):null,c&&oe&&(B||e.insertions+e.deletions<=$u)?s.jsxs(s.Fragment,{children:[s.jsx(A1,{filePath:e.path,diff:oe,renderSideBySide:H,wrapLines:r}),s.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:s.jsx("div",{className:"pointer-events-auto",children:s.jsx(D1,{filePath:e.path,staged:x,busyAction:I,disabled:I!==null,onAction:z})})})]}):null]})]})}),ch=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:n=!1,showOpenInEditorAction:r=!1,diffScope:o="all",onDiffScopeChange:a,targetFilePath:c=null,flushContent:l=!1})=>{const{t:d}=yt(),{git:f,files:m}=nr(),u=bi(),{screenWidth:p,isMobile:x}=zr(),b=Ic(u??null),w=Ja(u??null),g=Rc(u??null),h=yn(Te=>Te.setActiveDirectory),k=yn(Te=>Te.ensureStatus),j=yn(Te=>Te.fetchStatus),S=yn(Te=>Te.setDiff),[N,C]=i.useState(null),[y,P]=i.useState(!1),[_,v]=i.useState(null),[F,I]=i.useState(()=>new Set),[R,B]=i.useState(()=>new Set),[D,W]=i.useState(!1),[U,L]=i.useState(0),[M,ee]=i.useState(!1),[ie,te]=i.useState(!1),[H,J]=i.useState(o);i.useEffect(()=>{J(o)},[o]);const re=Ee(Te=>Te.pendingDiffFile),oe=Ee(Te=>Te.pendingDiffStaged),ve=Ee(Te=>Te.pendingDiffScope),ne=Ee(Te=>Te.setPendingDiffFile),ye=Ee(Te=>Te.diffLayoutPreference),he=Ee(Te=>Te.diffFileLayout),Fe=Ee(Te=>Te.setDiffFileLayout),z=Ee(Te=>Te.diffWrapLines),K=Ee(Te=>Te.setDiffWrapLines),Y=Ee(Te=>Te.openContextFileAtLine),me=ht(Te=>Te.currentSessionId),Ne=Sg(me??"",u??void 0),Be=z,_e=H==="staged"?!0:H==="working"?!1:null,Oe=_e??y,pe=x||p<=768,Re=!!me&&H!=="turn"&&!pe&&!Cr(),ge=!t&&!pe&&p>=1024,ce=i.useRef(null),Ce=i.useRef(new Map),be=i.useRef(null),ue=i.useRef(null),De=i.useRef(!1),T=i.useRef(null),V=i.useRef(null),we=i.useCallback(()=>{be.current=null,De.current=!1,v(null),ue.current!==null&&(window.cancelAnimationFrame(ue.current),ue.current=null)},[]),E=i.useCallback(Te=>{I(Ke=>{if(Ke.has(Te))return Ke;const rt=new Set(Ke);return rt.add(Te),rt})},[]),de=i.useMemo(()=>{for(let Te=Ne.length-1;Te>=0;Te-=1){const Ke=Ne[Te];if(Ke.role==="user")return j1(Ke.summary?.diffs)}return[]},[Ne]),fe=i.useMemo(()=>{const Te=new Map;for(const Ke of de)if(Ke.file){if(typeof Ke.patch=="string"){Te.set(Ke.file,ah(Ke.file,Ke.patch,"patch"));continue}Te.set(Ke.file,{original:Ke.before??"",modified:Ke.after??"",contextMode:"full"})}return Te},[de]),$=i.useMemo(()=>{if(H==="turn")return de.map(rt=>({path:rt.file??"",index:"",working_dir:S1(rt.status),insertions:rt.additions??0,deletions:rt.deletions??0,isNew:rt.status==="added"})).filter(rt=>rt.path).sort((rt,vt)=>rt.path.localeCompare(vt.path));if(!w?.files)return[];const Te=w.diffStats??{},Ke=H==="staged"?Wu:H==="working"?Uu:()=>!0;return w.files.filter(Ke).map(rt=>({...rt,insertions:Te[rt.path]?.insertions??0,deletions:Te[rt.path]?.deletions??0,isNew:w1(rt)})).sort((rt,vt)=>rt.path.localeCompare(vt.path))},[H,de,w]),ke=i.useMemo(()=>w?.files?w.files.filter(Uu).length:0,[w]),Ve=i.useMemo(()=>w?.files?w.files.filter(Wu).length:0,[w]),Se=de.length,q=i.useMemo(()=>$.map(Te=>Te.path).join("\0"),[$]);i.useEffect(()=>{const Te=q?q.split("\0"):[],Ke=new Set(Te),rt=`${u??""}:${H}:${e?"collapsed":"default"}`,vt=V.current!==rt;V.current=rt,I(Je=>{if(vt){const qe=e?0:p1(Te.length);return new Set(Te.slice(0,qe))}let St=!1;const Xe=new Set;for(const qe of Je){if(!Ke.has(qe)){St=!0;continue}Xe.add(qe)}return St?Xe:Je}),B(Je=>{if(vt)return new Set;let St=!1;const Xe=new Set;for(const qe of Je){if(!Ke.has(qe)){St=!0;continue}Xe.add(qe)}return St?Xe:Je})},[H,q,u,e]);const O=i.useCallback(()=>{T.current=null;const Te=ce.current;if(!Te)return;const Ke=Te.getBoundingClientRect(),rt=Ke.top-zu,vt=Ke.bottom+zu,Je={};for(const[St,Xe]of Ce.current){if(!Xe||!F.has(St))continue;const qe=Xe.getBoundingClientRect();qe.bottom<rt||qe.top>vt||(Je[St]=!0)}B(St=>{let Xe=!1;const qe=new Set(St);for(const et of Object.keys(Je))qe.has(et)||(qe.add(et),Xe=!0);return Xe?qe:St})},[F]),se=i.useCallback(()=>{typeof window>"u"||T.current===null&&(T.current=window.requestAnimationFrame(O))},[O]);i.useEffect(()=>{const Te=ce.current;if(Te)return se(),Te.addEventListener("scroll",se,{passive:!0}),window.addEventListener("resize",se),()=>{Te.removeEventListener("scroll",se),window.removeEventListener("resize",se),T.current!==null&&(window.cancelAnimationFrame(T.current),T.current=null)}},[$,F,se]);const Le=i.useCallback(Te=>{const Ke=he[Te.path];if(Ke)return Ke;if(ye==="inline")return"inline";if(ye==="side-by-side")return"side-by-side";const rt=p<u1;return Te.isNew||rt?"inline":"side-by-side"},[he,ye,p]),ae=i.useMemo(()=>$.length===0?null:$.every(Te=>Le(Te)==="side-by-side")?"side-by-side":"inline",[$,Le]);i.useEffect(()=>{u&&(h(u),k(u,f))},[u,h,k,f]),i.useEffect(()=>{if(u)return _r.onGitRefreshHint(Te=>{Hu(Te.directory)===Hu(u)&&j(u,f)})},[u,j,f]),i.useEffect(()=>{H!=="all"&&!ve||re&&(ve&&J(ve),C(re),P(ve==="staged"||!ve&&oe),ne(null),De.current=!0,be.current=re,E(re),L(Te=>Te+1))},[H,E,re,ve,oe,ne]),i.useEffect(()=>{if(H==="all")return;const Te=c?.trim();Te&&(C(Te),P(H==="staged"),De.current=!0,be.current=Te,E(Te),L(Ke=>Ke+1))},[H,E,c]),i.useEffect(()=>{if(!N)return;$.some(Ke=>Ke.path===N)||(C(null),P(!1))},[$,N]);const We=i.useCallback((Te,Ke)=>{const rt=Ce.current;Ke?rt.set(Te,Ke):rt.delete(Te),se()},[se]),Ye=i.useCallback((Te,Ke)=>{we(),I(rt=>{const vt=rt.has(Te);if(Ke===vt)return rt;const Je=new Set(rt);return Ke?Je.add(Te):Je.delete(Te),Je}),Ke||B(rt=>{if(!rt.has(Te))return rt;const vt=new Set(rt);return vt.delete(Te),vt}),se()},[we,se]),Qe=i.useCallback(()=>{we(),I(Te=>Te.size>0?new Set:new Set($.map(Ke=>Ke.path))),B(new Set),se()},[we,$,se]),st=i.useCallback(async Te=>{if(!me)return;const Ke=ht.getState().getDirectoryForSession(me)||u||"";if(!Ke){le.error(d("diffView.reviewDialog.toast.noSessionDirectory"));return}te(!0);try{await Ng({originalSessionID:me,directory:Ke,providerID:Te.providerID,modelID:Te.modelID,agent:Te.agent||void 0,variant:Te.variant||void 0,generateHandoff:Te.generateHandoff,returnAfterHandoffRequest:Te.generateHandoff,autoReview:Te.autoReview}),ee(!1)}catch(rt){console.error("[review-flow] failed to start review flow",rt),le.error(rt instanceof Error?rt.message:d("diffView.reviewDialog.toast.startFailed"))}finally{te(!1)}},[me,u,d]),pt=i.useCallback(Te=>{const Ke=Ce.current.get(Te),rt=ce.current;if(!Ke||!rt)return!1;const vt=rt.getBoundingClientRect(),St=Ke.getBoundingClientRect().top-vt.top,Xe=Math.max(0,rt.scrollHeight-rt.clientHeight);return rt.scrollTop=Math.min(Xe,Math.max(0,rt.scrollTop+St)),!0},[]);i.useEffect(()=>{if(!be.current)return;let Ke=0;const rt=20;let vt=!1;const Je=()=>{vt||(vt=!0,be.current=null,De.current=!1,v(null),ue.current!==null&&(window.cancelAnimationFrame(ue.current),ue.current=null))},St=()=>{if(vt){ue.current=null;return}const Xe=be.current;if(!Xe){Je(),ue.current=null;return}if(!pt(Xe)){Ke+=1,Ke<rt?ue.current=window.requestAnimationFrame(St):(Je(),ue.current=null);return}n&&De.current&&v(Xe),Je()};return ue.current=window.requestAnimationFrame(St),()=>{vt=!0,ue.current!==null&&(window.cancelAnimationFrame(ue.current),ue.current=null)}},[n,U,pt]);const jt=i.useCallback(Te=>{},[]),Et=i.useCallback(Te=>{we(),C(Te),P(!1),De.current=!0,be.current=Te,E(Te),L(Ke=>Ke+1),pt(Te)},[we,E,pt]),Rt=i.useCallback(Te=>{const Ke=Te==="side-by-side"?"side-by-side":"inline";$.forEach(rt=>{Fe(rt.path,Ke)})},[$,Fe]),[Ut,ts]=i.useState(null),Kt=i.useCallback(async(Te,Ke)=>{if(!(!u||!Te)){ts(Te);try{let rt=null;if(Ke?.patch&&!Ke.isBinary&&!Vi(Te)?rt=_u(Ke.patch):Ke&&Ke.contextMode==="full"&&!Ke.isBinary&&!Vi(Te)&&(rt=Gu(Ke.original,Ke.modified)),rt===null)try{const qe=await f.getGitDiff(u,{path:Te,staged:Oe,contextLines:3});rt=_u(qe.diff)}catch{rt=null}let vt=Ke;if(rt===null||!vt){const qe=await f.getGitFileDiff(u,{path:Te,staged:Oe});vt={original:qe.original??"",modified:qe.modified??"",isBinary:qe.isBinary},Oe||S(u,Te,vt)}const Je=rt??(vt.isBinary||Vi(Te)?1:Gu(vt.original,vt.modified)),St=y1(u,Te),Xe=await Yc(m,St);if(!Xe.ok){le.error(Qc(Xe.reason));return}Y(u,St,Je,1)}finally{ts(rt=>rt===Te?null:rt)}}},[Oe,u,m,f,Y,S]),is=()=>{if(!u)return null;const Te=Ke=>_e!==null?_e:y&&Ke===N;return s.jsxs("div",{className:Pe("flex min-w-0 flex-1 min-h-0 h-full",l?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[ge&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:d("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:$.length})]}),s.jsx(k1,{changedFiles:$,selectedFile:null,onSelectFile:Et})]}),s.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:s.jsx(On,{ref:ce,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:s.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:$.map(Ke=>s.jsx(T1,{directory:u,file:Ke,layout:Le(Ke),wrapLines:Be,isSelected:!1,isExpanded:F.has(Ke.path),isMounted:R.has(Ke.path)||Ke.path===_,onSelect:jt,onExpandedChange:Ye,registerSectionRef:We,showOpenInEditorAction:r&&H!=="turn",isOpeningInEditor:Ut===Ke.path,onOpenInEditor:(rt,vt)=>{Kt(rt,vt)},staged:Te(Ke.path),loadFullFiles:D,initialDiffData:H==="turn"?fe.get(Ke.path)??null:null},Ke.path))})})})]})},qt=()=>u?H!=="turn"&&g&&!w?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),d("diffView.state.loadingRepositoryStatus")]}):H!=="turn"&&b===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d("diffView.state.notGitRepository")}):$.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d(H==="turn"?"diffView.state.noLastTurnChanges":"diffView.state.cleanWorkingTree")}):is():s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[!x&&(H==="working"||H==="staged"||H==="turn"?s.jsx(N1,{scope:H,workingCount:ke,stagedCount:Ve,turnCount:Se,onScopeChange:Te=>{J(Te),a?.(Te)}}):s.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:g&&!w?d("diffView.state.loadingChanges"):$.length===1?d("diffView.summary.changedFilesSingle",{count:$.length}):d("diffView.summary.changedFilesPlural",{count:$.length})})})),$.length>0&&s.jsxs(ze,{variant:"ghost",size:"sm",onClick:Qe,className:Pe("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:F.size>0?d("diffView.actions.collapseAll"):d("diffView.actions.expandAll"),children:[s.jsx(A,{name:"expand-up-down",className:"size-4"}),s.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:F.size>0?d("diffView.actions.collapseAll"):d("diffView.actions.expandAll")})]}),$.length>0&&Re&&s.jsxs(ze,{variant:"default",size:"sm",onClick:()=>ee(!0),disabled:ie,className:"diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2","aria-label":d("diffView.actions.reviewAria"),children:[ie?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"search-eye",className:"size-4"}),s.jsx("span",{className:"diff-toolbar__review-label typography-ui-label",children:d("diffView.actions.review")})]}),$.length>0&&s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>W(Te=>!Te),"aria-pressed":D,"aria-label":d(D?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles"),className:Pe("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",D&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(A,{name:"file-download",className:"size-4"})})}),s.jsx(Tt,{children:s.jsx("p",{children:d(D?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles")})})]}),$.length>0&&s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>K(!z),className:Pe("h-5 w-5 p-0 transition-opacity",Be?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:d(Be?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(A,{name:"text-wrap",className:"size-4"})}),ae&&s.jsx(fm,{mode:ae==="side-by-side"?"side-by-side":"unified",onModeChange:Rt})]}),s.jsx(kg,{open:M,onOpenChange:ee,projectDirectory:u??null,submitting:ie,onConfirm:st}),qt()]})},P1=(t,e)=>{if(!e)return null;const n=Number.parseInt(t.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,e.state.doc.lines)},Ku=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},qu=(t,e,n)=>{const r=t.state.doc.line(e),o=Math.max(1,Math.min(n,r.length+1)),a=r.from+o-1;t.dispatch({selection:Zh.cursor(a),effects:mi.scrollIntoView(a,{y:"center"})})};function I1({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:o}=yt(),[a,c]=i.useState(""),l=i.useRef(null),d=i.useRef(!1),f=i.useRef(null),m=i.useRef(null),u=i.useMemo(()=>P1(a,n),[a,n]);i.useEffect(()=>{!t||!n||(d.current=!1,l.current=Ku(n,n.state.selection),c(""))},[t,n]),i.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),i.useEffect(()=>{if(!(!t||!n||!l.current)){if(u===null){const{selection:g}=l.current;n.dispatch({selection:g,effects:mi.scrollIntoView(g.main.from,{y:"center"})});return}qu(n,u,l.current.character)}},[u,t,n]);const p=i.useCallback(()=>{if(!n||d.current||!l.current)return;const{selection:g}=l.current;n.dispatch({selection:g,effects:mi.scrollIntoView(g.main.from,{y:"center"})})},[n]),x=i.useCallback(g=>{g||p(),e(g)},[e,p]),b=i.useCallback(()=>{!n||u===null||!l.current||(d.current=!0,qu(n,u,l.current.character),e(!1),n.focus())},[u,e,n]);i.useEffect(()=>{if(!t)return;const g=k=>{const j=f.current,S=k.target;!j||!(S instanceof Node)||j.contains(S)||x(!1)},h=k=>{k.key==="Escape"&&(k.preventDefault(),x(!1))};return document.addEventListener("pointerdown",g,!0),document.addEventListener("keydown",h,!0),()=>{document.removeEventListener("pointerdown",g,!0),document.removeEventListener("keydown",h,!0)}},[x,t,r]);const w=i.useMemo(()=>{if(!n)return o("goToLineDialog.helper.editorUnavailable");if(u===null){const g=l.current??Ku(n,n.state.selection);return o("goToLineDialog.helper.currentLineRange",{current:g.lineNumber,max:n.state.doc.lines})}return o("goToLineDialog.helper.goToLine",{line:u})},[u,o,n]);return r==="inline"?t?s.jsxs("div",{ref:f,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Ln,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:a,onChange:g=>c(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),b())},placeholder:o("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(ze,{variant:"outline",size:"xs",onClick:b,disabled:!n||u===null,className:"h-6 px-2",children:o("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:f,className:Pe("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",t?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(Ln,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:a,onChange:g=>c(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),b())},placeholder:o("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:w})]})})}const R1='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function Yu(){if(typeof document>"u")return!1;const t=document.documentElement.getAttribute("data-theme");return t==="dark"||!t&&window.matchMedia("(prefers-color-scheme: dark)").matches}const E1=i.forwardRef(function({xml:e,readOnly:n,className:r,onChange:o},a){const c=i.useRef(e),l=i.useRef(null),d=i.useRef(!1),[f,m]=i.useState(Yu),u=i.useRef(e),p=i.useRef(e);p.current!==e&&(p.current=e,u.current=e,c.current=e);const x=i.useRef(f);x.current!==f&&(x.current=f,u.current=c.current);const b=i.useRef(null);i.useEffect(()=>{const h=()=>m(Yu());h();const k=new MutationObserver(h);return k.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>k.disconnect()},[]),i.useEffect(()=>{const h=setTimeout(()=>{b.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(h)},[]),i.useImperativeHandle(a,()=>({getXml:()=>c.current}));const w=i.useCallback(()=>{!e&&!d.current&&(d.current=!0,setTimeout(()=>{l.current?.template({})},500))},[e]),g=i.useCallback(h=>{c.current=h.xml,o?.(h.xml)},[o]);return s.jsx("div",{ref:b,className:Pe("h-full w-full",r),children:s.jsx(ep,{ref:l,xml:u.current||R1,autosave:!0,urlParameters:{ui:n?"simple":f?"dark":"kennedy",spin:!0,libraries:!n,chrome:n,nav:n,layers:n,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:w,onAutoSave:g},f?"dark":"light")})}),M1=t=>{const e=Qs(t);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const r=e.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},F1=t=>{const e=gt.c(8),{label:n,iconDataUrl:r}=t,[o,a]=i.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const l=c;if(r&&!o){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>a(!0),e[2]=m):m=e[2];let u;return e[3]!==r?(u=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=r,e[4]=u):u=e[4],u}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=Pe("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let f;return e[6]!==l?(f=s.jsx("span",{className:d,children:l}),e[6]=l,e[7]=f):f=e[7],f},O1=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Qs=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},L1=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Ji=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,La=(t,e)=>{const n=Qs(e),r=Qs(t);if(!n||!r)return!1;const o=Ji(n),a=Ji(r);return a===o||a.startsWith(`${o}/`)},Qu=(t,e)=>{const n=Qs(e),r=Qs(t);if(!La(r,n))return[];const a=r.slice(n.length).replace(/^\//,"").split("/"),c=[];let l=n;for(let d=0;d<a.length-1;d++)l=l?`${l}/${a[d]}`:a[d],c.push(l);return c},lc=(t,e)=>{if(!e)return"";const n=Qs(e);if(!t||!La(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},B1=new Set(["node_modules"]),V1=t=>{const e=gt.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const o=r[n];let a;return e[1]!==o?(a=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=a):a=e[2],a},Ju=t=>{const e=gt.c(11),{name:n}=t,r=i.useRef(null),o=i.useRef(null),[a,c]=i.useState(!1);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{const p=r.current,x=o.current;if(!p||!x)return;const b=()=>{c(x.scrollWidth>p.clientWidth+1)};b();const w=new ResizeObserver(b);return w.observe(p),w.observe(x),()=>{w.disconnect()}},e[0]=l):l=e[0];let d;e[1]!==n?(d=[n],e[1]=n,e[2]=d):d=e[2],i.useLayoutEffect(l,d);let f;e[3]!==n?(f=s.jsx("span",{ref:o,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:n}),e[3]=n,e[4]=f):f=e[4];let m;e[5]!==n||e[6]!==a?(m=a?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:n}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:n})]}):s.jsx("span",{className:"block min-w-0 truncate",children:n}),e[5]=n,e[6]=a,e[7]=m):m=e[7];let u;return e[8]!==f||e[9]!==m?(u=s.jsxs("span",{ref:r,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[f,m]}),e[8]=f,e[9]=m,e[10]=u):u=e[10],u},_1=t=>B1.has(t),$1=t=>{const e=Qs(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},z1=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},Xu=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")},No=2e5,dh="openchamber:files:auto-save-enabled",W1=t=>{let e=0,n=0;for(let r=0;r<t.length;r+=1)t.charCodeAt(r)===10&&(r>0&&t.charCodeAt(r-1)===13?e+=1:n+=1);return e>n?`\r
|
|
22
|
+
`:`
|
|
23
|
+
`},uh=t=>t.replace(/\r\n/g,`
|
|
24
|
+
`).replace(/\r/g,`
|
|
25
|
+
`),U1=(t,e)=>{const n=uh(t);return e===`\r
|
|
26
|
+
`?n.replace(/\n/g,`\r
|
|
27
|
+
`):n},H1=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(dh)!=="false"}catch{return!0}},fh=(t,e)=>s.jsx(ei,{filePath:t,extension:e}),Zu=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},G1=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},El=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},K1=t=>{const e=gt.c(83),{node:n,root:r,isExpanded:o,isActive:a,isMobile:c,alwaysShowActions:l,status:d,badge:f,permissions:m,downloadFile:u,contextMenuPath:p,setContextMenuPath:x,rightClickMenuPath:b,setRightClickMenuPath:w,onSelect:g,onToggle:h,onRevealPath:k,onOpenDialog:j}=t,{t:S}=yt(),N=n.type==="directory",{canRename:C,canCreateFile:y,canCreateFolder:P,canDelete:_,canReveal:v}=m;let F;e[0]!==y||e[1]!==P||e[2]!==_||e[3]!==C||e[4]!==v||e[5]!==n.path||e[6]!==w?(F=me=>{!C&&!y&&!P&&!_&&!v||(me?.preventDefault(),w(n.path))},e[0]=y,e[1]=P,e[2]=_,e[3]=C,e[4]=v,e[5]=n.path,e[6]=w,e[7]=F):F=e[7];const I=F;let R;e[8]!==N||e[9]!==n||e[10]!==g||e[11]!==h?(R=()=>{N?h(n.path):g(n)},e[8]=N,e[9]=n,e[10]=g,e[11]=h,e[12]=R):R=e[12];const B=R;let D;e[13]!==n.path||e[14]!==x||e[15]!==w?(D=me=>{me.stopPropagation(),w(null),x(n.path)},e[13]=n.path,e[14]=x,e[15]=w,e[16]=D):D=e[16];const W=D;let U;e[17]!==y||e[18]!==P||e[19]!==_||e[20]!==C||e[21]!==v||e[22]!==u||e[23]!==N||e[24]!==n||e[25]!==j||e[26]!==k||e[27]!==r||e[28]!==S?(U=me=>{const{Item:Ne,Separator:Be}=me;return s.jsxs(s.Fragment,{children:[C&&s.jsxs(Ne,{onClick:_e=>{_e.stopPropagation(),j("rename",n)},children:[s.jsx(A,{name:"edit",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.rename")]}),s.jsxs(Ne,{onClick:_e=>{_e.stopPropagation(),gr(n.path).then(Oe=>{if(Oe.ok){le.success(S("sidebarFilesTree.toast.pathCopied"));return}le.error(S("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(A,{name:"file-copy",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.copyPath")]}),s.jsxs(Ne,{onClick:_e=>{_e.stopPropagation();const Oe=lc(r,n.path)||n.path;gr(Oe).then(pe=>{if(pe.ok){le.success(S("filesView.toast.relativePathCopied"));return}le.error(S("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(A,{name:"file-copy-2",className:"mr-2 size-4"})," ",S("filesView.tree.menu.copyRelativePath")]}),!N&&u&&s.jsxs(Ne,{onClick:_e=>{_e.stopPropagation(),u(n.path).catch(Oe=>{console.error("Download failed:",Oe),le.error(S("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(A,{name:"download",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.save")]}),v&&s.jsxs(Ne,{onClick:_e=>{_e.stopPropagation(),k(n.path)},children:[s.jsx(A,{name:"folder-received",className:"mr-2 size-4"})," ",S(Ec())]}),N&&(y||P)&&s.jsxs(s.Fragment,{children:[s.jsx(Be,{}),y&&s.jsxs(Ne,{onClick:_e=>{_e.stopPropagation(),j("createFile",n)},children:[s.jsx(A,{name:"file-add",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.newFile")]}),P&&s.jsxs(Ne,{onClick:_e=>{_e.stopPropagation(),j("createFolder",n)},children:[s.jsx(A,{name:"folder-add",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.newFolder")]})]}),_&&s.jsxs(s.Fragment,{children:[s.jsx(Be,{}),s.jsxs(Ne,{onClick:_e=>{_e.stopPropagation(),j("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"mr-2 size-4"})," ",S("sidebarFilesTree.menu.delete")]})]})]})},e[17]=y,e[18]=P,e[19]=_,e[20]=C,e[21]=v,e[22]=u,e[23]=N,e[24]=n,e[25]=j,e[26]=k,e[27]=r,e[28]=S,e[29]=U):U=e[29];const L=U,M=b===n.path;let ee;e[30]!==n.path||e[31]!==w?(ee=me=>w(me?n.path:null),e[30]=n.path,e[31]=w,e[32]=ee):ee=e[32];const ie=c?void 0:I;let te;e[33]!==ie?(te=s.jsx("div",{className:"group relative flex items-center",onContextMenu:ie}),e[33]=ie,e[34]=te):te=e[34];const H=c?void 0:I,J=a?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let re;e[35]!==J?(re=Pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",J),e[35]=J,e[36]=re):re=e[36];let oe;e[37]!==N||e[38]!==o||e[39]!==n.extension||e[40]!==n.path?(oe=N?o?s.jsx(A,{name:"folder-open-fill",className:"size-4 flex-shrink-0 text-primary/60"}):s.jsx(A,{name:"folder-3-fill",className:"size-4 flex-shrink-0 text-primary/60"}):fh(n.path,n.extension),e[37]=N,e[38]=o,e[39]=n.extension,e[40]=n.path,e[41]=oe):oe=e[41];let ve;e[42]!==n.name||e[43]!==n.path?(ve=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[42]=n.name,e[43]=n.path,e[44]=ve):ve=e[44];let ne;e[45]!==N||e[46]!==d?(ne=!N&&d&&s.jsx(V1,{status:d}),e[45]=N,e[46]=d,e[47]=ne):ne=e[47];let ye;e[48]!==f||e[49]!==N?(ye=N&&f&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[f.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",f.modified]}),f.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",f.added]})]}),e[48]=f,e[49]=N,e[50]=ye):ye=e[50];let he;e[51]!==B||e[52]!==re||e[53]!==oe||e[54]!==ve||e[55]!==ne||e[56]!==ye||e[57]!==H?(he=s.jsxs("button",{type:"button",onClick:B,onContextMenu:H,className:re,children:[oe,ve,ne,ye]}),e[51]=B,e[52]=re,e[53]=oe,e[54]=ve,e[55]=ne,e[56]=ye,e[57]=H,e[58]=he):he=e[58];let Fe;e[59]!==l||e[60]!==y||e[61]!==P||e[62]!==_||e[63]!==C||e[64]!==v||e[65]!==p||e[66]!==W||e[67]!==c||e[68]!==n.path||e[69]!==L||e[70]!==x?(Fe=(C||y||P||_||v)&&s.jsx("div",{className:Pe("absolute right-1 top-1/2 -translate-y-1/2",l?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(en,{open:p===n.path,onOpenChange:me=>x(me?n.path:null),children:[s.jsx(Xs,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"icon",className:"size-6",onClick:W,children:s.jsx(A,{name:"more-2-fill",className:"size-4"})})}),s.jsx(Zs,{align:"end",side:"bottom",onCloseAutoFocus:()=>x(null),children:L({Item:ls,Separator:$r})})]})}),e[59]=l,e[60]=y,e[61]=P,e[62]=_,e[63]=C,e[64]=v,e[65]=p,e[66]=W,e[67]=c,e[68]=n.path,e[69]=L,e[70]=x,e[71]=Fe):Fe=e[71];let z;e[72]!==he||e[73]!==Fe||e[74]!==te?(z=s.jsxs(Wc,{render:te,children:[he,Fe]}),e[72]=he,e[73]=Fe,e[74]=te,e[75]=z):z=e[75];let K;e[76]!==L?(K=s.jsx($c,{className:"min-w-[180px]",children:L({Item:zc,Separator:Mm})}),e[76]=L,e[77]=K):K=e[77];let Y;return e[78]!==z||e[79]!==K||e[80]!==M||e[81]!==ee?(Y=s.jsxs(Uc,{open:M,onOpenChange:ee,children:[z,K]}),e[78]=z,e[79]=K,e[80]=M,e[81]=ee,e[82]=Y):Y=e[82],Y},q1=t=>{const e=gt.c(83),{activeDialog:n,dialogData:r,dialogInputValue:o,onDialogInputChange:a,isDialogSubmitting:c,onDialogSubmit:l,onClose:d,inputRef:f}=t,{t:m}=yt(),u=!!n;let p;e[0]!==d?(p=M=>!M&&d(),e[0]=d,e[1]=p):p=e[1];let x;e[2]!==n||e[3]!==m?(x=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=x):x=e[4];let b;e[5]!==n||e[6]!==m?(b=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=b):b=e[7];let w;e[8]!==n||e[9]!==m?(w=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=w):w=e[10];let g;e[11]!==n||e[12]!==m?(g=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=g):g=e[13];let h;e[14]!==x||e[15]!==b||e[16]!==w||e[17]!==g?(h=s.jsxs(Gs,{children:[x,b,w,g]}),e[14]=x,e[15]=b,e[16]=w,e[17]=g,e[18]=h):h=e[18];let k;e[19]!==n||e[20]!==r?.path||e[21]!==m?(k=n==="createFile"&&m("filesView.dialog.createFile.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=m,e[22]=k):k=e[22];let j;e[23]!==n||e[24]!==r?.path||e[25]!==m?(j=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=m,e[26]=j):j=e[26];let S;e[27]!==n||e[28]!==r?.name||e[29]!==m?(S=n==="rename"&&m("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=m,e[30]=S):S=e[30];let N;e[31]!==n||e[32]!==r?.name||e[33]!==m?(N=n==="delete"&&m("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=m,e[34]=N):N=e[34];let C;e[35]!==S||e[36]!==N||e[37]!==k||e[38]!==j?(C=s.jsxs(dn,{children:[k,j,S,N]}),e[35]=S,e[36]=N,e[37]=k,e[38]=j,e[39]=C):C=e[39];let y;e[40]!==C||e[41]!==h?(y=s.jsxs(tn,{children:[h,C]}),e[40]=C,e[41]=h,e[42]=y):y=e[42];let P;e[43]!==n||e[44]!==o||e[45]!==f||e[46]!==a||e[47]!==l||e[48]!==m?(P=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Ln,{value:o,onChange:M=>a(M.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:M=>{M.key==="Enter"&&l()},ref:f})}),e[43]=n,e[44]=o,e[45]=f,e[46]=a,e[47]=l,e[48]=m,e[49]=P):P=e[49];let _;e[50]!==m?(_=m("filesView.dialog.cancel"),e[50]=m,e[51]=_):_=e[51];let v;e[52]!==c||e[53]!==d||e[54]!==_?(v=s.jsx(ze,{variant:"outline",onClick:d,disabled:c,children:_}),e[52]=c,e[53]=d,e[54]=_,e[55]=v):v=e[55];const F=n==="delete"?"destructive":"default";let I;e[56]!==l?(I=()=>{l()},e[56]=l,e[57]=I):I=e[57];let R;e[58]!==n||e[59]!==o||e[60]!==c?(R=c||n!=="delete"&&!o.trim(),e[58]=n,e[59]=o,e[60]=c,e[61]=R):R=e[61];let B;e[62]!==n||e[63]!==c||e[64]!==m?(B=c?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=c,e[64]=m,e[65]=B):B=e[65];let D;e[66]!==F||e[67]!==I||e[68]!==R||e[69]!==B?(D=s.jsx(ze,{variant:F,onClick:I,disabled:R,children:B}),e[66]=F,e[67]=I,e[68]=R,e[69]=B,e[70]=D):D=e[70];let W;e[71]!==v||e[72]!==D?(W=s.jsxs(xr,{children:[v,D]}),e[71]=v,e[72]=D,e[73]=W):W=e[73];let U;e[74]!==f||e[75]!==y||e[76]!==P||e[77]!==W?(U=s.jsxs(Vs,{initialFocus:f,children:[y,P,W]}),e[74]=f,e[75]=y,e[76]=P,e[77]=W,e[78]=U):U=e[78];let L;return e[79]!==u||e[80]!==p||e[81]!==U?(L=s.jsx(_s,{open:u,onOpenChange:p,children:U}),e[79]=u,e[80]=p,e[81]=U,e[82]=L):L=e[82],L},Ml=(t,e,n)=>{const r=gt.c(8),[o,a]=i.useState(""),[c,l]=i.useState(0);let d,f;r[0]!==t||r[1]!==n||r[2]!==e?(d=()=>{if(!t){a("");return}let u=!1;a("");const p=Xr(),x=kp(p);jc(p).then(w=>{u||!w||(a(t),e(null))}).catch(w=>{u||(e(w instanceof Error?w.message:n),a(t))});const b=Cp(()=>{u||(a(t),l(Y1),e(null))});return()=>{u=!0,x(),b()}},f=[t,e,n],r[0]=t,r[1]=n,r[2]=e,r[3]=d,r[4]=f):(d=r[3],f=r[4]),i.useEffect(d,f);let m;return r[5]!==c||r[6]!==o?(m={readyKey:o,nonce:c},r[5]=c,r[6]=o,r[7]=m):m=r[7],m},mh=({mode:t="full"})=>{const{t:e}=yt(),{files:n,runtime:r}=nr(),{currentTheme:o,availableThemes:a,lightThemeId:c,darkThemeId:l}=wi(),{isMobile:d,isTablet:f,screenWidth:m}=zr(),u=d||f,p=Xf(),x=Zf(),b=bi()??"",w=Qs(b.trim()),g=d||t!=="editor-only",h=t==="editor-only"&&!d,k=vc(G=>G.searchFiles),j=Ja(b),[S,N]=i.useState(""),C=Za(S,200),y=i.useRef(null),[P,_]=i.useState(!1),[v,F]=i.useState(!0),[I,R]=i.useState(!1),[B,D]=i.useState(!1),[W,U]=i.useState(!1),L=i.useRef(null),M=i.useRef(0),ee=i.useCallback(G=>{M.current=Math.max(0,M.current+(G?1:-1))},[]),ie=i.useCallback(G=>G instanceof Element?G.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);i.useEffect(()=>{if(!W)return;const G=Ae=>{M.current>0||ie(Ae.target)||L.current&&!L.current.contains(Ae.target)&&U(!1)};return document.addEventListener("mousedown",G),()=>document.removeEventListener("mousedown",G)},[ie,W]);const[te,H]=i.useState("edit"),[J,re]=i.useState("edit"),[oe,ve]=i.useState("tree"),[ne,ye]=i.useState("edit"),[he,Fe]=i.useState("preview"),[z,K]=i.useState(0),Y=i.useRef({}),me=i.useRef({}),Ne=i.useRef({}),Be=i.useRef({}),_e=i.useMemo(()=>a.find(G=>G.metadata.id===c)??Bd(!1),[a,c]),Oe=i.useMemo(()=>a.find(G=>G.metadata.id===l)??Bd(!0),[a,l]);i.useEffect(()=>{Vd(_e),Vd(Oe)},[_e,Oe]);const pe=i.useMemo(()=>[],[]),Re=cn(G=>w?G.byRoot[w]?.openPaths??pe:pe),ge=cn(G=>w?G.byRoot[w]?.selectedPath??null:null),ce=cn(G=>w?G.byRoot[w]?.expandedPaths??pe:pe),Ce=cn(G=>G.addOpenPath),be=cn(G=>G.removeOpenPath),ue=cn(G=>G.removeOpenPathsByPrefix),De=cn(G=>G.removeExpandedPathsByPrefix),T=cn(G=>G.setSelectedPath),V=cn(G=>G.toggleExpandedPath),we=cn(G=>G.expandPaths),E=i.useCallback(G=>{const Ae=Qs(G),Ue=Ae.split("/"),He=Ue[Ue.length-1]||Ae,lt=He.includes(".")?He.split(".").pop()?.toLowerCase():void 0;return{name:He,path:Ae,type:"file",extension:lt}},[]),de=i.useMemo(()=>Re.map(E),[Re,E]),fe=i.useMemo(()=>{if(ge){const G=Ji(ge);if(Re.some(Ae=>Ji(Ae)===G))return ge}return Re[0]??null},[Re,ge]),$=i.useMemo(()=>fe?E(fe):null,[fe,E]),ke=$?.path??"";i.useEffect(()=>{if(!w||!ge)return;const G=Ji(ge);Re.some(Ue=>Ji(Ue)===G)||T(w,Re[0]??null)},[Re,w,ge,T]);const Ve=!!(w&&ke&&!La(ke,w)),Se=Ve?_d(ke):void 0,q=i.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Ve,outsideFileGrant:Se,directory:w||void 0}),[t,Ve,Se,w]),O=i.useRef(null),[se,Le]=i.useState({left:!1,right:!1}),ae=i.useCallback(()=>{const G=O.current;G&&Le({left:G.scrollLeft>2,right:G.scrollLeft+G.clientWidth<G.scrollWidth-2})},[]),We=i.useRef(ae);We.current=ae,i.useEffect(()=>{const G=O.current;if(!G)return;const Ae=()=>We.current();Ae(),G.addEventListener("scroll",Ae,{passive:!0});const Ue=new ResizeObserver(Ae);return Ue.observe(G),()=>{G.removeEventListener("scroll",Ae),Ue.disconnect()}},[de.length]);const[Ye,Qe]=i.useState({}),[st,pt]=i.useState({}),jt=i.useRef(new Set),Et=i.useRef(new Set),Rt=i.useRef(new Map),Ut=i.useRef(0),[ts,Kt]=i.useState([]),[is,qt]=i.useState(!1),[Te,Ke]=i.useState(""),{isPlaying:rt,play:vt,stop:Je}=mm(),[St,Xe]=i.useState(!1),[qe,et]=i.useState(null),[Vt,Ct]=i.useState(""),Ht=i.useRef(""),[ss,Xt]=i.useState(null),[Ft,_t]=i.useState(""),[hs,Zt]=i.useState(!1),[ns,gs]=i.useState(`
|
|
28
|
+
`),Mt=i.useRef(null),Bt=i.useRef(null),$t=i.useRef(null),os=i.useRef(""),Gt=i.useRef(""),Me=i.useRef(null),ft=i.useRef(null),at=i.useRef(null),Nt=i.useRef(0),[Pt,es]=i.useState("idle"),[xs,Yt]=i.useState(!1),[Lt,Es]=i.useState(H1),[ms,Ns]=i.useState(!1),Us=i.useRef(null),Ms=i.useRef(null),Tn=i.useRef(null),Hs=i.useRef(!1),xe=i.useRef(null),tt=i.useRef(null),ut=i.useRef(null),wt=i.useRef(null),[zt,xt]=i.useState(0),ps=i.useRef(null),cs=i.useRef({key:"",attempts:0});i.useEffect(()=>()=>{ps.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(ps.current),ps.current=null)},[]);const[js,Ss]=i.useState(null),[Fs,Bn]=i.useState(null),[sn,Kn]=i.useState(""),[Pn,vn]=i.useState(!1),[Ks,jn]=i.useState(null),[nn,Ge]=i.useState(null),[ds,ks]=i.useState(!1),[Os,qs]=i.useState(!1),[$s,gn]=i.useState(!1),Cs=!!n.writeFile,qn=!!n.createDirectory,us=!!n.rename,Ls=!!n.delete,br=!!n.revealPath,Yn=Sr(G=>G.availableApps),un=Sr(G=>G.isCacheStale),Ar=Sr(G=>G.initialize),ni=Sr(G=>G.loadInstalledApps);i.useEffect(()=>{Ar()},[Ar]);const ri=i.useCallback(G=>{n.revealPath&&n.revealPath(G).catch(()=>{le.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),yi=i.useCallback(async G=>{if(!$?.path||await Np($.path,G.id,G.appName)||await Ca($.path,G.appName))return;const He=M1($.path)||w;He&&await Ca(He,G.appName)||le.error(e("filesView.toast.openInAppFailed",{app:G.appName}))},[w,$?.path,e]),Dr=i.useCallback((G,Ae)=>{Ss(G),Bn(Ae),Kn(G==="rename"&&Ae.name||""),vn(!1)},[]),[ys,rn]=i.useState(null),rr=i.useRef(!1),Sn=i.useRef(null),[X,it]=i.useState(!1),dt=Ee(G=>G.setMainTabGuard),kt=Ee(G=>G.pendingFileNavigation),Wt=Ee(G=>G.setPendingFileNavigation),fs=Ee(G=>G.pendingFileFocusPath),bs=Ee(G=>G.setPendingFileFocusPath),zs=Ee(G=>G.shortcutOverrides),Ys=Ee(G=>G.fileEditorKeymap),xn=rs(G=>G.settingsDefaultFileViewerPreview),fr=rs(G=>G.showMessageTTSButtons),Nn=Ee(G=>G.expandedEditorToolbar);i.useEffect(()=>{const G=()=>{rr.current=!1,Sn.current=null,it(!1)};return document.addEventListener("mouseup",G),()=>document.removeEventListener("mouseup",G)},[]),i.useEffect(()=>()=>{xe.current!==null&&window.clearTimeout(xe.current),tt.current!==null&&window.clearTimeout(tt.current)},[]);const Wr=i.useCallback((G,Ae)=>{const Ue=G.split(`
|
|
29
|
+
`),He=Math.max(1,Ae.start),lt=Math.min(Ue.length,Ae.end);return He>lt?"":Ue.slice(He-1,lt).join(`
|
|
30
|
+
`)},[]),Tr=Fm({source:"file",fileLabel:$?.path??null,language:$?.path&&Bi($.path)||"text",getCodeForRange:G=>Wr(Te,Om(G)),toStoreRange:G=>({startLine:G.start,endLine:G.end}),fromDraftRange:G=>({start:G.startLine,end:G.endLine})}),{drafts:kn,commentText:ln,setCommentText:In,editingDraftId:fn,setSelection:ir,saveComment:Qn,cancel:Rn,reset:vi,startEdit:Pr,deleteDraft:ji}=Tr;i.useEffect(()=>{rn(null),vi(),dt(null),_t(""),Zt(!1)},[$?.path,vi,dt]),i.useEffect(()=>{ir(ys)},[ys,ir]),i.useEffect(()=>{if(!ys&&!fn)return;const G=Ue=>{const He=Ue.target;He.closest('[data-comment-input="true"]')||He.closest('[data-comment-card="true"]')||He.closest(".cm-gutterElement")||He.closest("[data-sonner-toast]")||He.closest("[data-sonner-toaster]")||ln.trim()||(rn(null),Rn())},Ae=setTimeout(()=>{document.addEventListener("click",G)},100);return()=>{clearTimeout(Ae),document.removeEventListener("click",G)}},[Rn,ln,fn,ys]);const zi=i.useCallback((G,Ae)=>{const Ue=Ae??ys??void 0;Ae&&rn(Ae),Qn(G,Ue),rn(null)},[ys,Qn]),or=i.useCallback((G,Ae)=>{const Ue=[];for(const He of Ae){if(!(He&&typeof He.name=="string"&&He.name.length>0)||!p&&He.name.startsWith(".")||!x&&_1(He.name))continue;const lt=He.name,ct=Qs(He.path||""),as=ct?L1(ct)?ct:Qs(`${G}/${ct}`):Qs(`${G}/${lt}`),Ps=He.isDirectory?"directory":"file",Rs=Ps==="file"&<.includes(".")?lt.split(".").pop()?.toLowerCase():void 0;Ue.push({name:lt,path:as,type:Ps,extension:Rs})}return O1(Ue)},[x,p]),Cn=i.useCallback(async G=>{const Ae=Qs(G.trim());if(!Ae||jt.current.has(Ae)||Et.current.has(Ae))return;Et.current=new Set(Et.current),Et.current.add(Ae);const Ue=Ut.current+1;Ut.current=Ue,Rt.current=new Map(Rt.current),Rt.current.set(Ae,Ue);const He=()=>Rt.current.get(Ae)===Ue;await(n.listDirectory?n.listDirectory(Ae).then(ct=>ct.entries.map(as=>({name:as.name,path:as.path,isDirectory:as.isDirectory}))):sr.listLocalDirectory(Ae).then(ct=>ct.map(as=>({name:as.name,path:as.path,isDirectory:as.isDirectory})))).then(ct=>{if(!He())return;const as=or(Ae,ct);jt.current=new Set(jt.current),jt.current.add(Ae),pt(Ps=>{if(!Ps[Ae])return Ps;const Rs={...Ps};return delete Rs[Ae],Rs}),Qe(Ps=>({...Ps,[Ae]:as}))}).catch(ct=>{if(!He())return;const as=ct instanceof Error?ct.message:String(ct??"");if(as==="Directory not found"&&w&&Ae!==w){De(w,Ae),pt(Ps=>{if(!Ps[Ae])return Ps;const Rs={...Ps};return delete Rs[Ae],Rs});return}console.error("Failed to load files directory:",ct),pt(Ps=>({...Ps,[Ae]:as}))}).finally(()=>{He()&&(Rt.current=new Map(Rt.current),Rt.current.delete(Ae),Et.current=new Set(Et.current),Et.current.delete(Ae))})},[n,or,De,w]),ar=i.useCallback(async()=>{w&&(jt.current=new Set,Et.current=new Set,Rt.current=new Map,pt({}),Qe(G=>Object.keys(G).length===0?G:{}),await Cn(w))},[Cn,w]),on=i.useCallback(async G=>{if(!G){await ar();return}const Ae=Qs(G);jt.current=new Set(jt.current),jt.current.delete(Ae),Et.current=new Set(Et.current),Et.current.delete(Ae),await Cn(Ae)},[Cn,ar]),mn=i.useRef(""),Ur=i.useRef("");i.useEffect(()=>{if(!w)return;const G=`${w}|h${p?"1":"0"}|g${x?"1":"0"}`,Ae=mn.current!==w,Ue=Ur.current!==G;!Ae&&!Ue||(Ae&&(mn.current=w,Ke(""),et(null),Ct(""),Xt(null),_(!1)),Ue&&(Ur.current=G,jt.current=new Set,Et.current=new Set,Rt.current=new Map,pt({}),Qe(He=>Object.keys(He).length===0?He:{}),Cn(w)))},[Cn,w,x,p]),i.useEffect(()=>{if(!n.listDirectory)return;const G=()=>{if(!document.hidden&&ce.length>0)for(const Ae of ce)on(Ae)};return document.addEventListener("visibilitychange",G),()=>document.removeEventListener("visibilitychange",G)},[ce,n.listDirectory,on]),i.useEffect(()=>{if(!n.listDirectory||ce.length===0)return;const G=setInterval(()=>{if(!document.hidden)for(const Ae of ce)on(Ae)},8e3);return()=>clearInterval(G)},[ce,n.listDirectory,on]);const Wi=i.useCallback(async G=>{if(G?.preventDefault(),!Fs||!js)return;vn(!0);const Ae=()=>{Ss(null)},Ue=lt=>{le.error(lt)},He=()=>{vn(!1)};if(js==="createFile"){if(!sn.trim()){Ue(e("sidebarFilesTree.toast.filenameRequired")),He();return}if(!n.writeFile){Ue(e("sidebarFilesTree.toast.writeNotSupported")),He();return}const lt=Fs.path,ct=lt?`${lt}/`:"",as=Qs(`${ct}${sn.trim()}`);await n.writeFile(as,"").then(async Ps=>{Ps.success&&(le.success(e("sidebarFilesTree.toast.fileCreated")),await on(lt)),Ae()}).catch(()=>Ue(e("sidebarFilesTree.toast.operationFailed"))).finally(He);return}if(js==="createFolder"){if(!sn.trim()){Ue(e("sidebarFilesTree.toast.folderNameRequired")),He();return}const lt=Fs.path,ct=lt?`${lt}/`:"",as=Qs(`${ct}${sn.trim()}`);await n.createDirectory(as).then(async Ps=>{Ps.success&&(le.success(e("sidebarFilesTree.toast.folderCreated")),await on(lt)),Ae()}).catch(()=>Ue(e("sidebarFilesTree.toast.operationFailed"))).finally(He);return}if(js==="rename"){if(!sn.trim()){Ue(e("sidebarFilesTree.toast.nameRequired")),He();return}if(!n.rename){Ue(e("sidebarFilesTree.toast.renameNotSupported")),He();return}const lt=Fs.path,ct=lt.split("/").slice(0,-1).join("/"),as=ct?`${ct}/`:"",Ps=Qs(`${as}${sn.trim()}`);await n.rename(lt,Ps).then(async Rs=>{Rs.success&&(le.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await on(ct),w&&ue(w,lt),($?.path===lt||$?.path.startsWith(`${lt}/`))&&(w&&T(w,null),Ke(""),et(null),Ct(""),Xt(null),d&&_(!1))),Ae()}).catch(()=>Ue(e("sidebarFilesTree.toast.operationFailed"))).finally(He);return}if(js==="delete"){if(!n.delete){Ue(e("sidebarFilesTree.toast.deleteNotSupported")),He();return}const lt=Fs.path,ct=lt.split("/").slice(0,-1).join("/");await n.delete(lt).then(async as=>{as.success&&(le.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await on(ct),w&&ue(w,lt),($?.path===lt||$?.path.startsWith(`${lt}/`))&&(w&&T(w,null),Ke(""),et(null),Ct(""),Xt(null),d&&_(!1))),Ae()}).catch(()=>Ue(e("sidebarFilesTree.toast.operationFailed"))).finally(He);return}He()},[js,Fs,sn,n,on,d,ue,w,$?.path,T,e]);i.useEffect(()=>{if(!b){Kt([]),qt(!1);return}const G=C.trim();if(!G){Kt([]),qt(!1);return}let Ae=!1;return qt(!0),k(b,G,150,{includeHidden:p,respectGitignore:!x,type:"file"}).then(Ue=>{if(Ae)return;const lt=Ue.filter(ct=>x||!$1(ct.path)).map(ct=>({name:ct.name,path:Qs(ct.path),type:"file",extension:ct.extension,relativePath:ct.relativePath}));Kt(lt)}).catch(()=>{Ae||Kt([])}).finally(()=>{Ae||qt(!1)}),()=>{Ae=!0}},[b,C,k,p,x]);const Ir=i.useCallback(async(G,Ae)=>{if(n.readFile)return(await n.readFile(G,{...Ae??{},directory:w||void 0})).content??"";const Ue=new URLSearchParams({path:G});Ae?.allowOutsideWorkspace&&Ue.set("allowOutsideWorkspace","true"),Ae?.outsideFileGrant&&Ue.set("outsideFileGrant",Ae.outsideFileGrant),Ae?.optional&&Ue.set("optional","true"),w&&Ue.set("directory",w);const He=await Is(`/api/fs/read?${Ue.toString()}`,{cache:Ae?.optional?"no-store":"default"});if(!He.ok){const lt=await He.json().catch(()=>({error:He.statusText}));throw new Error(lt.error||e("filesView.error.readFileFailed"))}return He.text()},[n,w,e]),Vn=i.useCallback(async(G,Ae)=>{if(n.statFile){const Ue=await n.statFile(G,{...Ae??{},directory:w||void 0});return{path:Ue.path,size:Ue.size,mtimeMs:Ue.mtimeMs}}return null},[n,w]);i.useEffect(()=>{if(!w||!n.statFile||Re.length===0)return;let G=!1;const Ae=[...Re];return Promise.all(Ae.map(async Ue=>{try{const He=await n.statFile?.(Ue,{directory:w||void 0});!G&&He&&!He.isFile&&ue(w,Ue)}catch(He){!G&&Xu(He)&&ue(w,Ue)}})),()=>{G=!0}},[n,Re,ue,w]);const Hr=i.useMemo(()=>Te.length>No?`${Te.slice(0,No)}
|
|
31
|
+
|
|
32
|
+
… truncated …`:Te,[Te]),bn=Ft!==Hr,mr=i.useCallback(async()=>{if(!$||!n.writeFile)return le.error(e("filesView.toast.savingNotSupported")),!1;if(!bn)return!0;if(Ft===""&&Te!==""&&ss!==$.path)return console.warn(`[saveDraft] refusing to save empty draft for "${$.path}" (${Te.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;Zt(!0);try{const G=U1(Ft,ns);return(await n.writeFile($.path,G))?.success?(Ke(Ft),$?.path&&ml($.path)&&(os.current=Ft,Gt.current=Ft),Vn($.path).then(Ue=>{Ue&&(at.current=Ue)}).catch(()=>{}),!0):(le.error(e("filesView.toast.writeFileFailed")),!1)}catch(G){return le.error(G instanceof Error?G.message:e("filesView.toast.saveFailed")),!1}finally{Zt(!1)}},[Ft,Te,n,bn,ns,ss,Vn,$,e]);i.useEffect(()=>{if(!bn){dt(null);return}const G=Ae=>Hs.current?(Hs.current=!1,!0):(Ns(!0),Ms.current=Ae,!1);return dt(G),()=>{Ee.getState().mainTabGuard===G&&dt(null)}},[bn,dt]),i.useEffect(()=>{try{window.localStorage.setItem(dh,Lt?"true":"false")}catch{}},[Lt]),i.useEffect(()=>{Lt||(es("idle"),Bt.current&&(clearTimeout(Bt.current),Bt.current=null))},[Lt]);const Ui=1500;i.useEffect(()=>{const G=!!($&&n.writeFile);if(!(!Lt||!bn||!G||hs))return Bt.current=setTimeout(()=>{mr().then(Ae=>{Ae&&(es("saved"),setTimeout(()=>es("idle"),2e3))})},Ui),()=>{Bt.current&&(clearTimeout(Bt.current),Bt.current=null)}},[Lt,Ft,bn,$,n.writeFile,hs,mr]),i.useEffect(()=>{es("idle")},[$?.path]),i.useEffect(()=>{const G=Ae=>{Ac(Ae)&&(Ae.key.toLowerCase()==="s"?(Ae.preventDefault(),Bt.current&&(clearTimeout(Bt.current),Bt.current=null),hs||mr().then(Ue=>{Ue&&(es("saved"),setTimeout(()=>es("idle"),2e3))})):Ae.key.toLowerCase()==="f"&&(Ae.preventDefault(),D(!0)))};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[hs,mr]);const Rr=i.useCallback(async G=>{const Ae=Nt.current+1;Nt.current=Ae;const Ue=()=>{if(!w)return!1;const Rs=cn.getState().byRoot[w],yr=Rs?.selectedPath??Rs?.openPaths[0]??null;return Nt.current===Ae&&yr===G.path};et(null),Ct(""),Xt(null);const He=Vi(G.path),lt=G.path.toLowerCase().endsWith(".svg"),ct=$d(G.path);if(d&&_(!0),r.isDesktop&&He&&!lt){Ke(""),_t(""),Xe(!0);return}if(!r.isDesktop&&He&&!lt){Ke(""),_t(""),Xt(G.path),Xe(!1);return}if(ct){Ke(""),_t(""),Xt(G.path),Xe(!1);return}Xe(!0);const as=_d(G.path),Ps={allowOutsideWorkspace:t==="editor-only"&&!!w&&!La(G.path,w),outsideFileGrant:as};await Ir(G.path,Ps).then(Rs=>{if(!Ue())return;const yr=uh(Rs);gs(W1(Rs)),Ke(yr),os.current=yr,Gt.current=yr,_t(yr.length>No?`${yr.slice(0,No)}
|
|
33
|
+
|
|
34
|
+
… truncated …`:yr),Xt(G.path),Vn(G.path,Ps).then(hr=>{hr&&Ue()&&(at.current=hr)}).catch(()=>{})}).catch(Rs=>{if(Ue()){if(z1(Rs)){if(Xe(!1),w&&T(w,null),et(null),Ke(""),_t(""),Xt(null),at.current=null,S.trim().length>0&&N(""),d&&_(!1),w){const hr=[...Qu(G.path,w),G.path];hr.length>0&&we(w,hr);for(const cl of hr)jt.current.has(cl)||Cn(cl)}return}if(Xu(Rs)){w&&ue(w,G.path),Ke(""),_t(""),et(null),at.current=null,d&&_(!1);return}Ke(""),_t(""),et(Rs instanceof Error?Rs.message:e("filesView.error.readFileFailed")),at.current=null}}).finally(()=>{Ue()&&Xe(!1)})},[we,d,Cn,t,Ir,Vn,ue,w,r.isDesktop,S,T,e]),ii=i.useCallback(async(G,Ae)=>{if(!w)return;const Ue=Qu(G,w),He=Ae?[...Ue,G]:Ue;He.length>0&&we(w,He);const lt=He.map(ct=>{if(!jt.current.has(ct))return Cn(ct)}).filter(Boolean);await Promise.all(lt)},[we,Cn,w]),Si=i.useCallback((G,Ae)=>{const Ue=Ae.findIndex(He=>He.path===G);return Ue===-1||Ae.length<=1?null:Ae[Ue+1]??Ae[Ue-1]??null},[]),hn=i.useCallback(async G=>{if(Hs.current)Hs.current=!1;else if(bn){Ns(!0),Us.current=G;return}w&&(T(w,G.path),Ce(w,G.path),ii(G.path,!1)),et(null),Ct(""),Ke(""),os.current="",Gt.current="",_t(""),Xt(null),d&&_(!0)},[Ce,ii,bn,d,w,T]);i.useEffect(()=>{$?.path&&ii($.path,!1)},[ii,$?.path]),i.useEffect(()=>{if(!$){Nt.current+=1,Xe(!1);return}ss!==$.path&&Rr($)},[Rr,ss,$]);const bo=i.useRef(bn);bo.current=bn,i.useEffect(()=>{if(!$?.path||ss!==$.path)return;let G=!1;const Ae=window.setInterval(()=>{document.hidden||Vn($.path,q).then(Ue=>{if(G||!Ue)return;const He=at.current;if(!He||He.path!==$.path){at.current=Ue;return}const lt=Ue.mtimeMs!==void 0&&He.mtimeMs!==void 0&&Ue.mtimeMs!==He.mtimeMs,ct=Ue.size!==He.size;!lt&&!ct||bo.current||(at.current=Ue,Xt(null))}).catch(()=>{})},2e3);return()=>{G=!0,window.clearInterval(Ae)}},[ss,Vn,$?.path,q]);const wo=i.useCallback(()=>{const G=Us.current,Ae=Ms.current,Ue=Tn.current;if(Us.current=null,Ms.current=null,Tn.current=null,Hs.current=!0,Ns(!1),_t(Hr),Ue){w&&be(w,Ue),$?.path===Ue&&(G?hn(G):(w&&T(w,null),Ke(""),et(null),Ct(""),Xt(null),d&&_(!1)));return}if(G){hn(G);return}Ae&&(dt(null),Ee.getState().setActiveMainTab(Ae))},[Hr,hn,d,be,w,$?.path,dt,T]),yo=i.useCallback(async()=>{const G=Us.current,Ae=Ms.current,Ue=Tn.current;if(!await mr()){Hs.current=!1;return}if(Us.current=null,Ms.current=null,Tn.current=null,Hs.current=!0,Ns(!1),Ue){w&&be(w,Ue),$?.path===Ue&&(G?await hn(G):(w&&T(w,null),Ke(""),et(null),Ct(""),Xt(null),d&&_(!1)));return}if(G){await hn(G);return}Ae&&(dt(null),Ee.getState().setActiveMainTab(Ae))},[hn,d,be,w,mr,$?.path,dt,T]),Q=i.useCallback(G=>{const Ae=$?.path===G,Ue=Si(G,de);if(Ae&&bn){Ns(!0),Us.current=Ue,Tn.current=G;return}if(w&&be(w,G),!!Ae){if(Ue){hn(Ue);return}w&&T(w,null),Ke(""),et(null),Ct(""),Xt(null),d&&_(!1)}},[Si,hn,bn,d,de,be,w,$?.path,T]),je=i.useCallback(G=>{if(Re.includes(G))return"open";if(j?.files){const Ae=G.startsWith(w+"/")?G.slice(w.length+1):G,Ue=j.files.find(He=>He.path===Ae);if(Ue){if(Ue.index==="A"||Ue.working_dir==="?")return"git-added";if(Ue.index==="D")return"git-deleted";if(Ue.index==="M"||Ue.working_dir==="M")return"git-modified"}}return null},[Re,j,w]),Ie=i.useCallback(G=>{if(!j?.files)return null;const Ae=G.startsWith(w+"/")?G.slice(w.length+1):G,Ue=Ae?`${Ae}/`:"";let He=0,lt=0;for(const ct of j.files)ct.path.startsWith(Ue)&&((ct.index==="M"||ct.working_dir==="M")&&He++,(ct.index==="A"||ct.working_dir==="?")&<++);return He+lt>0?{modified:He,added:lt}:null},[j,w]),$e=i.useCallback(async G=>{const Ae=Qs(G);w&&(V(w,Ae),jt.current.has(Ae)||await Cn(Ae))},[Cn,w,V]),mt=i.useMemo(()=>({canRename:us,canCreateFile:Cs,canCreateFolder:qn,canDelete:Ls,canReveal:br}),[us,Cs,qn,Ls,br]);function It(G,Ae){const Ue=Ye[G]??[];return Ue.map((He,lt)=>{const ct=He.type==="directory",as=ct&&ce.includes(He.path),Ps=$?.path===He.path,Rs=lt===Ue.length-1;return s.jsxs("li",{className:"relative",children:[Ae>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Rs&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(K1,{node:He,root:w,isExpanded:as,isActive:Ps,isMobile:d,alwaysShowActions:u,status:ct?void 0:je(He.path),badge:ct?Ie(He.path):void 0,permissions:mt,downloadFile:n.downloadFile,contextMenuPath:Ks,setContextMenuPath:jn,rightClickMenuPath:nn,setRightClickMenuPath:Ge,onSelect:hn,onToggle:$e,onRevealPath:ri,onOpenDialog:Dr}),ct&&as&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[st[He.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:st[He.path],children:st[He.path]}),s.jsxs(ze,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{on(He.path)},children:[s.jsx(A,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,It(He.path,Ae+1)]})]},He.path)})}const Qt=!!($?.path&&Vi($.path)),Jt=!!($?.path&&$.path.toLowerCase().endsWith(".svg")),vs=!!($?.path&&$d($.path)),wr=i.useMemo(()=>Qs(kt?.path??""),[kt?.path]),Er=!!(kt&&wr&&ke&&ke===wr&&!St&&!qe&&!Qt&&!vs),Mr=i.useMemo(()=>lc(w,ke),[ke,w]),sl=!!($&&(!Qt||Jt)&&!vs&&Te.length>0),nl=!!($&&Mr.length>0),Jn=!!($&&!Ve&&!Qt&&!vs&&n.writeFile&&Te.length<=No),Fr=!!($?.path&&Zu($.path)),Ni=!!($?.path&&G1($.path)),oi=!!($?.path&&El($.path)),ki=!!($?.path&&ml($.path)),vo=!!($&&!Qt&&!vs)&&!Fr&&!ki&&!(oi&&ne==="preview"),rl=Fr&&J==="edit"||oi&&ne==="edit"||Ni&&oe==="text"||!Fr&&!oi&&!Ni&&te==="edit",Hi=i.useMemo(()=>ke?hm(ke):null,[ke]),[Z,ot]=i.useState(null);i.useEffect(()=>{let G=!1;const Ae=$?.path;if(!Ae||Hi){ot(null);return}return ot(null),Dg(Ae).then(Ue=>{G||ot(Ue)}),()=>{G=!0}},[$?.path,Hi]),i.useEffect(()=>{!Jn&&te==="edit"&&H("view")},[Jn,te]);const Ze="openchamber:files:md-viewer-mode",bt="openchamber:files:html-viewer-mode",Ot="openchamber:files:json-viewer-mode";i.useEffect(()=>{const G=$?.path;if(!G)return;H(Y.current[G]??"edit");let Ae=xn?"preview":"edit";try{const lt=localStorage.getItem(Ze);(lt==="preview"||lt==="edit")&&(Ae=lt)}catch{}re(me.current[G]??Ae);let Ue=xn?"preview":"edit";try{const lt=localStorage.getItem(bt);(lt==="preview"||lt==="edit")&&(Ue=lt)}catch{}ye(Ne.current[G]??Ue),Fe(Be.current[G]??(xn?"preview":"edit"));let He=xn?"tree":"text";try{const lt=localStorage.getItem(Ot);(lt==="tree"||lt==="text")&&(He=lt)}catch{}ve(He)},[$?.path,xn]);const Ts=i.useCallback(G=>{const Ae=$?.path;Ae&&(Y.current[Ae]=G),H(G)},[$?.path]),wn=i.useCallback(G=>{const Ae=$?.path;Ae&&(me.current[Ae]=G),re(G);try{localStorage.setItem(Ze,G)}catch{}},[$?.path]),As=i.useCallback(()=>J,[J]),_n=i.useCallback(G=>{ve(G);try{localStorage.setItem(Ot,G)}catch{}},[]),Xn=i.useCallback(G=>{const Ae=$?.path;Ae&&(Ne.current[Ae]=G),ye(G);try{localStorage.setItem(bt,G)}catch{}},[$?.path]),Gr=i.useCallback(G=>{const Ae=$?.path;if(Ae&&(Be.current[Ae]=G),$t.current&&(clearTimeout($t.current),$t.current=null),Me.current!==null&&(cancelAnimationFrame(Me.current),Me.current=null),G==="edit")_t(os.current||Te),Fe(G);else{os.current=Ft;const Ue=Ae;Fe("edit"),Me.current=requestAnimationFrame(()=>{Me.current=requestAnimationFrame(()=>{Me.current=null,!(w&&Ue&&cn.getState().byRoot[w]?.selectedPath!==Ue)&&(K(He=>He+1),Fe("preview"))})});return}},[Ft,Te,w,$?.path]),$n=i.useCallback(async(G,Ae)=>{if(!n.writeFile||Ae===Gt.current)return!1;if(!(await n.writeFile(G,Ae))?.success)return le.error(e("filesView.toast.writeFileFailed")),!1;os.current=Ae,Gt.current=Ae,_t(Ae);const He=await Vn(G,q).catch(()=>null);return He&&(at.current=He),!0},[n,Vn,q,e]);i.useEffect(()=>()=>{$t.current&&(clearTimeout($t.current),$t.current=null),Me.current!==null&&(cancelAnimationFrame(Me.current),Me.current=null)},[he,$?.path]);const Ci=i.useCallback(G=>{if(os.current=G,!$?.path||he!=="preview"||!n.writeFile)return;$t.current&&clearTimeout($t.current);const Ae=$.path;$t.current=setTimeout(()=>{$t.current=null,$n(Ae,G).then(Ue=>{Ue&&(Yt(!0),setTimeout(()=>Yt(!1),1500))}).catch(Ue=>{le.error(Ue instanceof Error?Ue.message:e("filesView.toast.saveFailed"))})},Ui)},[he,n.writeFile,$n,$?.path,e]),Or=i.useMemo(()=>ki&&(os.current||Ft)||Te,[Ft,Te,ki]),il=i.useCallback(()=>ne,[ne]);i.useEffect(()=>{const G=Ue=>{const He=Ue?"preview":"edit",lt=Ue?"tree":"text";for(const ct of Re)Y.current[ct]="edit",Zu(ct)&&(me.current[ct]=He),El(ct)&&(Ne.current[ct]=He),ml(ct)&&(Be.current[ct]=He);H("edit"),re(He),ye(He),Fe(He),ve(lt);try{localStorage.setItem(Ze,He),localStorage.setItem(bt,He),localStorage.setItem(Ot,lt)}catch{}},Ae=Ue=>{const He=!!Ue.detail?.enabled;G(He)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",Ae),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",Ae)}},[Re]),i.useEffect(()=>{if(!kt||!w)return;const G=()=>{typeof window>"u"||ps.current===null&&(ps.current=window.requestAnimationFrame(()=>{ps.current=null,xt(Kr=>Kr+1)}))},Ae=(Kr,Ti)=>{if(Kr.state.doc.length!==Ti.length)return!1;if(Ti.length===0)return!0;const dl=Math.min(128,Ti.length);if(Kr.state.sliceDoc(0,dl)!==Ti.slice(0,dl))return!1;const wd=Math.max(0,Ti.length-dl);return Kr.state.sliceDoc(wd,Ti.length)===Ti.slice(wd)},Ue=Qs(kt.path);if(!Ue){Wt(null),cs.current={key:"",attempts:0};return}const He=`${Ue}:${kt.line}:${kt.column??1}`;if(cs.current.key!==He&&(cs.current={key:He,attempts:0}),$?.path!==Ue){if(ms)return;hn(E(Ue));return}if(St||ss!==Ue)return;if(qe||Qt||vs){Wt(null),cs.current={key:"",attempts:0};return}if(!Jn)return;if(te!=="edit"){H("edit");return}const lt=ut.current;if(!lt){G();return}if(!Ae(lt,Ft)){G();return}const ct=Math.max(1,Math.min(kt.line,lt.state.doc.lines)),as=lt.state.doc.line(ct),Ps=Math.max(1,kt.column||1),Rs=Math.max(0,as.to-as.from),yr=Math.min(Rs,Ps-1),hr=as.from+yr;if(!(lt.state.selection.main.head===hr)||cs.current.attempts===0){cs.current.attempts+=1,lt.dispatch({selection:{anchor:hr},effects:mi.scrollIntoView(hr,{y:"center"})}),lt.focus(),G();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const Kr=ut.current;Kr&&(Kr.dispatch({selection:{anchor:hr},effects:mi.scrollIntoView(hr,{y:"center"})}),Kr.focus())}),Wt(null),cs.current={key:"",attempts:0}},[Jn,ms,Ft,zt,qe,St,Qt,vs,ss,hn,kt,w,$?.path,Wt,te,E]),i.useEffect(()=>{if(!fs||!w)return;const G=Qs(fs);if(!G){bs(null);return}if($?.path!==G){if(ms)return;hn(E(G));return}if(!(St||ss!==G||qe||Qt||vs)){if(Jn&&te==="edit"){const Ae=ut.current;if(!Ae)return;Ae.focus()}bs(null)}},[Jn,ms,qe,St,hn,Qt,vs,ss,fs,w,$?.path,bs,te,E]);const Ai=i.useCallback(G=>{if(!d||!G||!G.hasFocus||typeof window>"u")return;const Ae=window.visualViewport;if(!Ae)return;const Ue=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,Ue-(Ae.offsetTop+Ae.height))<=0)return;const lt=G.state.selection.main.head,ct=G.coordsAtPos(lt);if(!ct)return;const as=Math.round(Ae.offsetTop+Ae.height),Rs=ct.bottom+20-as;Rs<=0||(G.scrollDOM.scrollTop+=Rs)},[d]);i.useEffect(()=>{if(!d||typeof window>"u")return;const G=()=>{window.requestAnimationFrame(()=>{Ai(ut.current)})},Ae=window.visualViewport;return Ae?.addEventListener("resize",G),Ae?.addEventListener("scroll",G,{passive:!0}),document.addEventListener("selectionchange",G),()=>{Ae?.removeEventListener("resize",G),Ae?.removeEventListener("scroll",G),document.removeEventListener("selectionchange",G)}},[d,Ai]),i.useEffect(()=>{if(!Jn||te!=="edit"||d)return;const G=pi("open_go_to_line",zs),Ae=Ue=>{const He=Ue.target;if(He?.closest('[role="dialog"]'))return;const lt=!!He?.closest(".cm-editor");He?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!lt||!document.activeElement?.closest(".cm-editor")||da(Ue,G)&&(Ue.preventDefault(),gn(!0))};return window.addEventListener("keydown",Ae),()=>window.removeEventListener("keydown",Ae)},[Jn,d,zs,te]);const Di=Ee(G=>G.editorFontSize),rd=i.useMemo(()=>{if(!$?.path)return[Zl(o,{fontSize:Di})];const G=Bi($.path),Ae=[Zl(o,G?{syntaxColors:!1,fontSize:Di}:{fontSize:Di})],Ue=Hi??Z;return Ue&&Ae.push(Ue),G&&Ae.push(Lm({language:G,themeName:o.metadata.id,theme:pm(o)})),v&&Ae.push(mi.lineWrapping),d&&Ae.push(mi.updateListener.of(He=>{He.view.hasFocus&&(He.selectionSet||He.focusChanged||He.viewportChanged||He.geometryChanged)&&window.requestAnimationFrame(()=>{Ai(He.view)})})),Ae},[o,$?.path,Hi,Z,v,d,Ai,Di]),id=i.useMemo(()=>({light:_e.metadata.id,dark:Oe.metadata.id}),[_e.metadata.id,Oe.metadata.id]),Go=$?.path&&Qt&&!r.isDesktop&&!Jt?`${$.path}|${q.allowOutsideWorkspace?"outside":"workspace"}|${q.outsideFileGrant??""}`:"",Ko=$?.path&&vs?`${$.path}|${q.allowOutsideWorkspace?"outside":"workspace"}|${q.outsideFileGrant??""}`:"",qo=$?.path&&oi&&ne==="preview"&&!r.isVSCode?$.path:"",ol=e("filesView.error.readFileFailed"),{readyKey:od,nonce:ad}=Ml(Go,et,ol),{readyKey:ld,nonce:zh}=Ml(qo,et,ol),{readyKey:cd,nonce:dd}=Ml(Ko,et,ol),ud=!!(Go&&od!==Go),Wh=!!(qo&&ld!==qo),fd=!!(Ko&&cd!==Ko),md=$?.path&&Qt?r.isDesktop?Jt?`data:${zd($.path)};utf8,${encodeURIComponent(Te)}`:Vt:Jt?`data:${zd($.path)};utf8,${encodeURIComponent(Te)}`:od===Go?Li().authenticatedAsset("/api/fs/raw",{path:$.path,allowOutsideWorkspace:q.allowOutsideWorkspace?"true":void 0,outsideFileGrant:q.outsideFileGrant,directory:w||void 0}):"":"",hd=$?.path&&vs&&cd===Ko?Li().authenticatedAsset("/api/fs/raw",{path:$.path,allowOutsideWorkspace:q.allowOutsideWorkspace?"true":void 0,outsideFileGrant:q.outsideFileGrant,directory:w||void 0}):"",pd=i.useCallback(G=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:hd,className:"h-full w-full border-0",title:G.name},dd)}),[hd,dd]);i.useEffect(()=>{let G=!1;return(async()=>{if(!r.isDesktop||!$?.path||!Qt||Jt){Ht.current&&(URL.revokeObjectURL(Ht.current),Ht.current=""),Ct("");return}et(null),Ht.current&&(URL.revokeObjectURL(Ht.current),Ht.current=""),await(n.readFileBinary?n.readFileBinary($.path,q).then(He=>He.dataUrl):(async()=>{const He=await Is("/api/fs/raw",{query:{path:$.path,allowOutsideWorkspace:q.allowOutsideWorkspace?"true":void 0,outsideFileGrant:q.outsideFileGrant,directory:w||void 0}});if(!He.ok)throw new Error(e("filesView.error.readFileFailed"));const lt=await He.blob(),ct=URL.createObjectURL(lt);return G?(URL.revokeObjectURL(ct),""):(Ht.current=ct,ct)})()).then(He=>{G||(Ct(He),Xt($.path))}).catch(He=>{Ht.current&&(URL.revokeObjectURL(Ht.current),Ht.current=""),G||(Ct(""),et(He instanceof Error?He.message:e("filesView.error.readFileFailed")),Xt(null))}).finally(()=>{G||Xe(!1)})})(),()=>{G=!0}},[n,Qt,Jt,w,r.isDesktop,$?.path,q,e]),i.useEffect(()=>()=>{Ht.current&&(URL.revokeObjectURL(Ht.current),Ht.current="")},[]);const Uh=i.useCallback(()=>Ss(null),[]),Hh=i.useMemo(()=>Wm({drafts:kn,editingDraftId:fn,commentText:ln,onTextChange:In,selection:ys,isDragging:X,fileLabel:$?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:G=>({start:G.startLine,end:G.endLine}),onSave:zi,onCancel:()=>{rn(null),Rn()},onEdit:G=>{Pr(G),rn({start:G.startLine,end:G.endLine})},onDelete:ji}),[Rn,ln,ji,fn,kn,zi,X,ys,$?.path,In,Pr]),gd=i.useCallback((G,Ae)=>s.jsx("div",{className:"h-full",children:s.jsx(tp,{file:{name:G.name,contents:Ae,lang:Bi(G.path)||void 0},options:{disableFileHeader:!0,overflow:v?"wrap":"scroll",theme:id,themeType:o.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[o.metadata.variant,id,v]),al=({exitFullscreenOnly:G=!1,layout:Ae="floating"}={})=>{if(!$)return null;const He=Ae==="docked"?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",lt=(ct,as)=>s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:as})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:ct})]});return s.jsxs("div",{className:He,children:[Jn&&rl&&s.jsxs(s.Fragment,{children:[hs?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):Lt&&Pt==="saved"&&!bn?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(A,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):bn?lt(e(Lt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${hl()}+S`}),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>{mr()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(Lt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${hl()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${hl()}+S`}),children:s.jsx(A,{name:"save-3",className:"size-4"})})):null,lt(e(Lt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Es(ct=>!ct),className:Pe("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",Lt?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(Lt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(Lt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:Lt?s.jsx(A,{name:"file-check-fill",className:"size-4"}):s.jsx(A,{name:"file-check",className:"size-4"})}))]}),s.jsxs(en,{onOpenChange:ee,children:[s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Xs,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(A,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(Zs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Yn.map(ct=>s.jsxs(ls,{className:"flex items-center gap-2",onClick:()=>{yi(ct)},children:[s.jsx(F1,{label:ct.label,iconDataUrl:ct.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ct.label})]},ct.id)),un?s.jsxs(ls,{className:"flex items-center gap-2",onClick:()=>{ni(!0)},children:[s.jsx(A,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Qt&&!vs&&s.jsxs(s.Fragment,{children:[lt(e(v?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>F(!v),className:Pe("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",v?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(v?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(A,{name:"text-wrap",className:"size-4"})})),te==="edit"&&s.jsxs(s.Fragment,{children:[lt(e("filesView.editor.findInFile"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:ct=>{D(!B),ct.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(A,{name:"search",className:"size-4"})})),lt(e("filesView.editor.goToLine"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:ct=>{gn(as=>!as),ct.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(A,{name:"menu-fold-2",className:"size-4"})})),s.jsx(I1,{open:$s,onOpenChange:gn,view:ut.current,variant:"inline"})]})]}),vo&&Jn&&!Ni&&!oi&&s.jsx(fa,{currentMode:te==="view"?"preview":"edit",onToggle:()=>{Ts(te==="view"?"edit":"view")}}),Fr&<(e(As()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>wn(As()==="preview"?"edit":"preview"),className:Pe("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",As()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(As()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(As()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(A,{name:As()==="preview"?"eye":"eye-off",className:"size-4"})})),El($?.path??"")&&s.jsx(fa,{currentMode:il(),onToggle:()=>{Xn(il()==="preview"?"edit":"preview")}}),Fr&&As()==="preview"&&fr&&s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(rt?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{rt?Je():Te.trim()&&vt(Te)},children:rt?s.jsx(A,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"volume-up",className:"size-4"})})}),s.jsx(Tt,{sideOffset:8,children:e(rt?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),ki&&s.jsxs(s.Fragment,{children:[s.jsx(fa,{currentMode:he,onToggle:()=>Gr(he==="preview"?"edit":"preview")}),he==="preview"&&s.jsx(ze,{variant:"ghost",size:"sm",onClick:async()=>{const ct=ft.current?.getXml();if($t.current&&(clearTimeout($t.current),$t.current=null),$?.path&&ct){if(!await $n($.path,ct))return;Yt(!0),setTimeout(()=>Yt(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:xs?s.jsx(A,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"save-3",className:"size-4"})})]}),Ni&<(e(oe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>_n(oe==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(oe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:oe==="tree"?s.jsx(A,{name:"code-sslash",className:"size-4"}):s.jsx(A,{name:"node-tree",className:"size-4"})})),sl&<(e("filesView.editor.copyFileContents"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:async()=>{(await gr(Te)).ok?(ks(!0),xe.current!==null&&window.clearTimeout(xe.current),xe.current=window.setTimeout(()=>{ks(!1)},1200)):le.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:ds?s.jsx(A,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"clipboard",className:"size-4"})})),nl&<(e("filesView.editor.copyFilePathTitle",{path:Mr}),s.jsx(ze,{variant:"ghost",size:"sm",onClick:async()=>{(await gr(Mr)).ok?(qs(!0),tt.current!==null&&window.clearTimeout(tt.current),tt.current=window.setTimeout(()=>{qs(!1)},1200)):le.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:Mr}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:Mr}),children:Os?s.jsx(A,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"file-copy-2",className:"size-4"})})),n.downloadFile&<(e("filesView.editor.saveFile"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>{const ct=n.downloadFile;ct&&ct($.path).catch(as=>{console.error("Download failed:",as),le.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(A,{name:"download",className:"size-4"})})),G?lt(e("filesView.editor.exitFullscreen"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>R(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(A,{name:"fullscreen-exit",className:"size-4"})})):!d&&t==="full"&<(e(I?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>R(!I),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(I?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(I?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:I?s.jsx(A,{name:"fullscreen-exit",className:"size-4"}):s.jsx(A,{name:"fullscreen",className:"size-4"})}))]})},ll=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(_s,{open:ms,onOpenChange:G=>{G||Ns(!0)},children:s.jsxs(Vs,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(tn,{children:[s.jsx(Gs,{children:e("filesView.unsaved.title")}),s.jsx(dn,{children:e("filesView.unsaved.description")})]}),s.jsxs(xr,{children:[s.jsx(ze,{variant:"outline",onClick:()=>{yo()},disabled:hs,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(ze,{variant:"destructive",onClick:wo,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:Pe("flex flex-col flex-shrink-0",g&&"border-b border-border/40"),children:[g?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[d&&P&&s.jsx("button",{type:"button",onClick:()=>_(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(A,{name:"arrow-left-s",className:"size-5"})}),d?$?s.jsxs(en,{children:[s.jsx(Xs,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(ei,{filePath:$.path,extension:$.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Ju,{name:$.name}),s.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Zs,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:de.map(G=>{const Ae=$?.path===G.path;return s.jsxs(ls,{onSelect:Ue=>{if(Ue.target.closest("[data-close-open-file]")){Ue.preventDefault();return}Ae||hn(G)},className:Pe("flex min-w-0 items-center justify-between gap-2 overflow-hidden",Ae&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(ei,{filePath:G.path,extension:G.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Ju,{name:G.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:Ue=>{Ue.preventDefault(),Ue.stopPropagation()},onClick:Ue=>{Ue.preventDefault(),Ue.stopPropagation(),Q(G.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:G.name}),children:s.jsx(A,{name:"close",className:"size-3.5"})})]},G.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):de.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[se.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),se.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:O,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:de.map(G=>{const Ae=$?.path===G.path;return s.jsxs("div",{title:lc(w,G.path),className:Pe("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",Ae?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(ei,{filePath:G.path,extension:G.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{Ae||hn(G)},className:"max-w-[12rem] truncate text-left",children:G.name}),s.jsx("button",{type:"button",onClick:Ue=>{Ue.stopPropagation(),Q(G.path)},className:Pe("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!Ae&&!u&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:G.name}),children:s.jsx(A,{name:"close",className:"size-3.5"})})]},G.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,Nn&&!d&&$?s.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[Mr?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:Mr,children:Mr}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:al({layout:"docked"})})]}):null]}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[$&&!B&&!(Nn&&!d)&&s.jsx("div",{ref:L,className:"absolute right-3 top-3 z-30",onMouseLeave:()=>{M.current>0||U(!1)},children:W?al():s.jsxs("div",{className:"flex items-center gap-1",children:[Fr?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>wn(As()==="preview"?"edit":"preview"),className:Pe("size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors",As()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]":"text-muted-foreground hover:text-foreground"),"aria-label":e(As()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),title:e(As()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(A,{name:As()==="preview"?"eye":"eye-off",className:"size-4"})})})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:e(As()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode")})]}):null,s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",onMouseEnter:()=>U(!0),children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>U(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(A,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})]})}),s.jsx(On,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:$?St||ud||fd?h?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):qe?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:qe}):Qt?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:md,alt:$?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},ad)}):vs?pd($):$&&ki&&he==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(E1,{ref:ft,xml:Or,onChange:Ci},`${$.path}:${z}`)}):$&&Ni&&oe==="tree"?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:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Tg,{jsonString:Te,maxHeight:"100%",initiallyExpandedDepth:2})})}):$&&Fr&&As()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[Te.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(Te.length/1024)})}),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:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(ao,{content:Te,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):$&&oi&&ne==="preview"?Wh?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!r.isVSCode&&ld===qo?(()=>{const G=$.path.split("/").map(Ae=>encodeURIComponent(Ae)).join("/");return Li().authenticatedAsset(`/api/fs/serve${G.startsWith("/")?G:`/${G}`}`)})():void 0,srcDoc:r.isVSCode?(()=>{const G=$.path.substring(0,$.path.lastIndexOf("/")+1);return G?Te.replace(/<head([^>]*)>/i,`<head$1><base href="${G}">`):Te})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},zh)}):$&&vo&&te==="view"?gd($,Ft):s.jsxs("div",{className:Pe("relative h-full",Er&&"overflow-hidden"),ref:wt,children:[s.jsx("div",{className:Pe("h-full",Er&&"invisible"),children:s.jsx(ec,{value:Ft,onChange:_t,readOnly:!Jn,vimMode:Ys==="vim",extensions:rd,className:"h-full",blockWidgets:Hh,onViewReady:G=>{ut.current=G,xt(Ae=>Ae+1),window.requestAnimationFrame(()=>{Ai(G)})},onViewDestroy:()=>{ut.current&&(ut.current=null),xt(G=>G+1)},enableSearch:!0,searchOpen:B,onSearchOpenChange:D,highlightLines:ys?{start:Math.min(ys.start,ys.end),end:Math.max(ys.start,ys.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(G,Ae,Ue)=>{if(!(Ue instanceof MouseEvent)||Ue.button!==0)return!1;Ue.preventDefault();const He=G.state.doc.lineAt(Ae.from).number;if(ys&&!Ue.shiftKey&&Math.min(ys.start,ys.end)===He&&Math.max(ys.start,ys.end)===He)return rn(null),Rn(),rr.current=!1,Sn.current=null,it(!1),!0;if(d&&ys&&!Ue.shiftKey){const lt=Math.min(ys.start,ys.end,He),ct=Math.max(ys.start,ys.end,He);return rn({start:lt,end:ct}),rr.current=!1,Sn.current=null,it(!1),!0}if(rr.current=!0,Sn.current=He,it(!0),ys&&Ue.shiftKey){const lt=Math.min(ys.start,He),ct=Math.max(ys.end,He);rn({start:lt,end:ct})}else rn({start:He,end:He});return!0},mouseover:(G,Ae,Ue)=>{if(!(Ue instanceof MouseEvent)||Ue.buttons!==1||!rr.current||Sn.current===null)return!1;const He=G.state.doc.lineAt(Ae.from).number,lt=Math.min(Sn.current,He),ct=Math.max(Sn.current,He);return rn({start:lt,end:ct}),it(!0),!1},mouseup:()=>(rr.current=!1,Sn.current=null,it(!1),!1)}}})}),Er&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),Gh=!!(w&&Ye[w]),xd=w?st[w]:null,bd=s.jsxs("section",{className:Pe("flex min-h-0 flex-col overflow-hidden",d?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:Pe("flex flex-col gap-2 py-2",d?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(A,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(Ln,{ref:y,value:S,onChange:G=>N(G.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),S.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{N(""),y.current?.focus()},children:s.jsx(A,{name:"close",className:"size-4"})})]}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Dr("createFile",{path:b,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(A,{name:"file-add",className:"size-4"})})})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Dr("createFolder",{path:b,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(A,{name:"folder-add",className:"size-4"})})})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>{ar()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(A,{name:"refresh",className:"size-4"})})})}),s.jsx(Tt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(On,{outerClassName:"flex-1 min-h-0",className:Pe("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:is?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):ts.length>0?ts.map(G=>{const Ae=$?.path===G.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{hn(G)},className:Pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",Ae?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[fh(G.path,G.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:G.path,children:G.relativePath??G.path})]})},G.path)}):xd?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:xd}),s.jsxs(ze,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{ar()},children:[s.jsx(A,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):Gh?It(w,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Kh=t==="full"&&I&&$&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:al({exitFullscreenOnly:!0})}),s.jsx(On,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:St||ud||fd?h?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):qe?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:qe}):Qt?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:md,alt:$.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},ad)}):vs?pd($):Fr&&As()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[Te.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(Te.length/1024)})}),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:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(ao,{content:Te,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):vo&&te==="view"?gd($,Ft):s.jsxs("div",{className:Pe("relative h-full",Er&&"overflow-hidden"),children:[s.jsx("div",{className:Pe("h-full",Er&&"invisible"),children:s.jsx(ec,{value:Ft,onChange:_t,readOnly:!Jn,vimMode:Ys==="vim",extensions:rd,className:"h-full",onViewReady:G=>{ut.current=G,window.requestAnimationFrame(()=>{Ai(G)})},onViewDestroy:()=>{ut.current&&(ut.current=null)}})}),Er&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(q1,{activeDialog:js,dialogData:Fs,dialogInputValue:sn,onDialogInputChange:Kn,isDialogSubmitting:Pn,onDialogSubmit:Wi,onClose:Uh,inputRef:Mt}),Kh,d?P?ll:bd:t==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:ll})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[m>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:bd}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:ll})]})]})};function Y1(t){return t+1}const Nr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Fl=(t,e)=>{const n=Nr(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},Q1=(t,e,n)=>Fl(Fl(Fl(t,".opencode"),"plans"),`${e}-${n}.md`),J1=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,X1=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},Z1=(t,e)=>{const n=Nr(e.currentDirectory),r=Nr(e.homeDirectory),o=Nr(t);return n&&o.startsWith(n+"/")?o.slice(n.length+1):r&&o===r?"~":r&&o.startsWith(r+"/")?`~${o.slice(r.length)}`:o},ej=(t,e,n)=>{const r=Nr(t.trim());if(!r)return null;const o=n?e.find(c=>c.id===n)??null:null;if(o?.path){const c=Nr(o.path);if(r===c||r.startsWith(`${c}/`))return{id:o.id,path:o.path}}const a=e.filter(c=>{const l=Nr(c.path);return r===l||r.startsWith(`${l}/`)}).sort((c,l)=>Nr(l.path).length-Nr(c.path).length)[0];return a?{id:a.id,path:a.path}:null},hh=({targetPath:t=null})=>{const{t:e}=yt(),n=ht(ae=>ae.currentSessionId),r=ht(ae=>ae.createSession),o=ht(ae=>ae.initializeNewOpenChamberSession),a=ht(ae=>ae.sendMessage),c=ht(ae=>ae.setCurrentSession),l=Mc(),d=Js(ae=>ae.homeDirectory),f=Cc(ae=>ae.planModeEnabled),m=Ds(ae=>ae.projects),u=Ds(ae=>ae.activeProjectId),p=yn(ae=>ae.directories),x=bi()??"",b=Ee(ae=>ae.setActiveMainTab),w=Ee(ae=>ae.setSessionSwitcherOpen),g=nr(),{isMobile:h}=zr(),{currentTheme:k}=wi(),j=i.useMemo(()=>n?l.find(ae=>ae.id===n)??null:null,[n,l]),S=i.useMemo(()=>{const ae=typeof j?.directory=="string"?j.directory:"";return Nr(ae||"")},[j?.directory]),N=i.useMemo(()=>Nr(x||S),[x,S]),C=i.useMemo(()=>ej(N,m,u),[u,N,m]),y=i.useMemo(()=>C?p.get(C.path)?.isGitRepo===!0:!1,[C,p]),[P,_]=i.useState(null),[v,F]=i.useState(!1),[I,R]=i.useState(null),B=i.useMemo(()=>!I||!S||!d?I:Z1(I,{currentDirectory:S,homeDirectory:d}),[I,S,d]),[D,W]=i.useState(""),{isPlaying:U,play:L,stop:M}=mm(),ee=rs(ae=>ae.showMessageTTSButtons),[ie,te]=i.useState(null),H=i.useMemo(()=>B&&B.split("/").pop()||e("planView.file.defaultName"),[B,e]),J=i.useMemo(()=>D.trim()&&Pg(D).title||e("planView.title.default"),[D,e]),re=i.useMemo(()=>J.trim()||e("planView.title.default"),[J,e]),[oe,ve]=i.useState(!1),[ne,ye]=i.useState(!1),[he,Fe]=i.useState("edit"),z=i.useRef(null),[K,Y]=i.useState(null),me=i.useRef(null),Ne=i.useRef(null),Be="openchamber:plan:md-viewer-mode";i.useEffect(()=>{try{const ae=localStorage.getItem(Be);if(!ae)return;const We=JSON.parse(ae);(We==="preview"||We==="edit")&&Fe(We)}catch{}},[]);const _e=i.useCallback(ae=>{Fe(ae);try{localStorage.setItem(Be,JSON.stringify(ae))}catch{}},[]),Oe=i.useRef(!1),pe=i.useRef(null),[Re,ge]=i.useState(!1);i.useEffect(()=>{const ae=()=>{Oe.current=!1,pe.current=null,ge(!1)};return document.addEventListener("mouseup",ae),()=>document.removeEventListener("mouseup",ae)},[]);const ce=i.useCallback((ae,We)=>{const Ye=ae.split(`
|
|
35
|
+
`),Qe=Math.max(1,We.start),st=Math.min(Ye.length,We.end);return Qe>st?"":Ye.slice(Qe-1,st).join(`
|
|
36
|
+
`)},[]),Ce=Fm({source:"plan",fileLabel:H,language:I&&Bi(I)||"markdown",getCodeForRange:ae=>ce(D,Om(ae)),toStoreRange:ae=>({startLine:ae.start,endLine:ae.end}),fromDraftRange:ae=>({start:ae.startLine,end:ae.endLine})}),{drafts:be,commentText:ue,setCommentText:De,editingDraftId:T,setSelection:V,saveComment:we,cancel:E,reset:de,startEdit:fe,deleteDraft:$}=Ce;i.useEffect(()=>{Y(null),de()},[D,de]),i.useEffect(()=>{V(K)},[K,V]);const ke=i.useCallback(()=>{Y(null),E()},[E]),Ve=i.useCallback((ae,We)=>{We&&Y(We),we(ae,We??K??void 0),Y(null)},[K,we]);i.useEffect(()=>{if(!K)return;const ae=Ye=>{const Qe=Ye.target;Qe.closest('[data-comment-card="true"]')||Qe.closest('[data-comment-input="true"]')||Qe.closest(".oc-block-widget")||Qe.closest(".cm-gutterElement")||Qe.closest("[data-sonner-toast]")||Qe.closest("[data-sonner-toaster]")||ue.trim()||(Y(null),E())},We=window.setTimeout(()=>{document.addEventListener("click",ae)},100);return()=>{window.clearTimeout(We),document.removeEventListener("click",ae)}},[E,ue,T,h,K]);const Se=Ee(ae=>ae.editorFontSize),q=i.useMemo(()=>{const ae=I?Bi(I):null,We=!!ae&&ae!=="markdown",Ye=[Zl(k,We?{syntaxColors:!1,fontSize:Se}:{fontSize:Se})],Qe=hm(I||"plan.md");return Qe&&Ye.push(Qe),We&&ae&&Ye.push(Lm({language:ae,themeName:k.metadata.id,theme:pm(k)})),Ye.push(mi.lineWrapping),Ye},[k,I,Se]);i.useEffect(()=>{if(!f&&!t){R(null),W(""),ve(!1);return}let ae=!1;const We=async Qe=>{if(g.files?.readFile)return(await g.files.readFile(Qe))?.content??"";const st=Wo()?.files;if(st?.readFile)return(await st.readFile(Qe,{optional:!0}))?.content??"";const pt=await Is(`/api/fs/read?path=${encodeURIComponent(Qe)}&optional=true`,{cache:"no-store"});if(!pt.ok)throw new Error(`Failed to read plan file (${pt.status})`);return pt.text()};return(async()=>{if(R(null),W(""),te(null),t){ve(!0);try{const Qe=await We(t);if(ae)return;R(t),W(Qe)}catch{if(ae)return;R(null),W("")}finally{ae||ve(!1)}return}if(!j?.slug||!j?.time?.created||!S){R(null),W("");return}ve(!0);try{const Qe=Q1(S,j.time.created,j.slug),st=X1(J1(j.time.created,j.slug),d||null);let pt=null,jt=null;try{jt=await We(Qe),pt=Qe}catch{}if(!pt)try{jt=await We(st),pt=st}catch{}if(ae)return;if(!pt||jt===null){R(null),W("");return}R(pt),W(jt)}catch{if(ae)return;R(null),W("")}finally{ae||ve(!1)}})(),()=>{ae=!0}},[d,f,g.files,S,j?.slug,j?.time?.created,t]),i.useEffect(()=>{if(!I){te(null);return}const ae=window.setTimeout(async()=>{te(null);try{if(g.files?.writeFile){if(!(await g.files.writeFile(I,D))?.success)throw new Error(e("planView.error.writeFailed"))}else{const We=await Is("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:I,content:D})});if(!We.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:We.status}))}}catch(We){te(We instanceof Error?We.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(ae)}},[D,I,g.files,e]),i.useEffect(()=>()=>{z.current!==null&&window.clearTimeout(z.current)},[]);const O=i.useCallback(()=>{b("chat"),w(!1)},[b,w]),se=i.useCallback(async ae=>{if(!C||!P)return;const We=await Fn(P.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:re}),Qe=[{synthetic:!0,text:await Fn(P.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:re,plan_path:I??""})}];F(!0);try{O();let st=null,pt=C.path;if(P.target==="worktree"){if(!y)return;const Rt=await cm(C.path,dm());if(!Rt?.id)return;st=Rt.id,pt=Rt.path}else{const Rt=await r(void 0,C.path,null);if(!Rt?.id)return;st=Rt.id,pt=Rt.directory??C.path,o(Rt.id,rs.getState().agents??[])}if(!st)return;const jt=Tc.getState();jt.saveSessionModelSelection(st,ae.providerID,ae.modelID),ae.agent.trim()&&(jt.saveSessionAgentSelection(st,ae.agent),jt.saveAgentModelForSession(st,ae.agent,ae.providerID,ae.modelID),jt.saveAgentModelVariantForSession(st,ae.agent,ae.providerID,ae.modelID,ae.variant||void 0)),c(st,pt);const Et=ae.runAsGoal===!0?[`Implement the plan "${re}" end-to-end${I?` (plan file: ${I})`:""}.`,"Re-read that file for full details — it is the source of truth.","",D].join(`
|
|
37
|
+
`):null;Ig.getState().setArmed(ae.runAsGoal===!0,Et),await a(We,ae.providerID,ae.modelID,ae.agent.trim()||void 0,void 0,void 0,Qe,ae.variant||void 0),_(null)}finally{F(!1)}},[y,D,r,C,o,P,I,O,a,re,c]),Le=i.useMemo(()=>Wm({drafts:be,editingDraftId:T,commentText:ue,onTextChange:De,selection:K,isDragging:Re,fileLabel:H,newWidgetId:"plan-new-comment-input",mapDraftToRange:ae=>({start:ae.startLine,end:ae.endLine}),onSave:Ve,onCancel:ke,onEdit:ae=>{fe(ae),Y({start:ae.startLine,end:ae.endLine})},onDelete:$}),[ue,$,T,ke,Ve,Re,K,be,H,De,fe]);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:J}),ie?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:ie,children:e("planView.error.saveFailed")}):null]}),I?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(en,{children:[s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(Xs,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!D.trim(),children:s.jsx(A,{name:"loop-right-ai",className:"size-4"})})})}),s.jsx(Tt,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(Zs,{align:"end",children:[s.jsx(ls,{onClick:()=>_({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(ls,{onClick:()=>_({action:"improve",target:"worktree"}),disabled:!y,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(en,{children:[s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(Xs,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!D.trim(),children:s.jsx(A,{name:"code-ai",className:"size-4"})})})}),s.jsx(Tt,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(Zs,{align:"end",children:[s.jsx(ls,{onClick:()=>_({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(ls,{onClick:()=>_({action:"implement",target:"worktree"}),disabled:!y,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(fa,{currentMode:he,onToggle:()=>_e(he==="preview"?"edit":"preview")}),he==="preview"&&ee&&s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e(U?"planView.tts.stopSpeaking":"planView.tts.readAloud"),onClick:()=>{U?M():D.trim()&&L(D)},children:U?s.jsx(A,{name:"stop",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"volume-up",className:"h-4 w-4"})})}),s.jsx(Tt,{sideOffset:8,children:e(U?"planView.tts.stopSpeaking":"planView.tts.readAloud")})]}),s.jsx(ze,{variant:"ghost",size:"sm",onClick:async()=>{(await gr(D)).ok&&(ye(!0),z.current!==null&&window.clearTimeout(z.current),z.current=window.setTimeout(()=>{ye(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:ne?s.jsx(A,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),s.jsx(Gm,{open:P!==null,onOpenChange:ae=>{!ae&&!v&&_(null)},target:P?.target??"session",projectDirectory:C?.path??null,submitting:v,allowRunAsGoal:!0,onConfirm:se}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(On,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:oe?s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("planView.state.loading")}):s.jsx("div",{className:"relative h-full",children:s.jsx("div",{className:"h-full",children:he==="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:e("planView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("planView.error.switchToEditMode")})]}),children:s.jsx(ao,{content:D,className:"typography-markdown-body",enableFileReferences:!1})})}):s.jsx("div",{className:"relative h-full",ref:Ne,children:s.jsx(ec,{value:D,onChange:W,readOnly:!1,className:"h-full",extensions:q,onViewReady:ae=>{me.current=ae},onViewDestroy:()=>{me.current=null},blockWidgets:Le,highlightLines:K?{start:Math.min(K.start,K.end),end:Math.max(K.start,K.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(ae,We,Ye)=>{if(!(Ye instanceof MouseEvent)||Ye.button!==0)return!1;Ye.preventDefault();const Qe=ae.state.doc.lineAt(We.from).number;if(K&&!Ye.shiftKey&&Math.min(K.start,K.end)===Qe&&Math.max(K.start,K.end)===Qe)return Y(null),E(),Oe.current=!1,pe.current=null,ge(!1),!0;if(h&&K&&!Ye.shiftKey){const st=Math.min(K.start,K.end,Qe),pt=Math.max(K.start,K.end,Qe);return Y({start:st,end:pt}),Oe.current=!1,pe.current=null,ge(!1),!0}if(Oe.current=!0,pe.current=Qe,ge(!0),K&&Ye.shiftKey){const st=Math.min(K.start,Qe),pt=Math.max(K.end,Qe);Y({start:st,end:pt})}else Y({start:Qe,end:Qe});return!0},mouseover:(ae,We,Ye)=>{if(!(Ye instanceof MouseEvent)||Ye.buttons!==1||!Oe.current||pe.current===null)return!1;const Qe=ae.state.doc.lineAt(We.from).number,st=Math.min(pe.current,Qe),pt=Math.max(pe.current,Qe);return Y({start:st,end:pt}),ge(!0),!1},mouseup:()=>(Oe.current=!1,pe.current=null,ge(!1),!1)}}})})})})})})]})},Jc=t=>t,cc=t=>{const e=Jc(t).type;return typeof e=="string"?e:""},tj=t=>{const e=Jc(t).tool;return typeof e=="string"?e:""},sj=t=>{const e=Jc(t).text;return typeof e=="string"?e:""},nj=t=>{const e=cc(t);return e==="tool"?tj(t).trim().toLowerCase()||"tool":e||"unknown"},rj=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=nj(n);e.includes(r)||e.push(r)}return e.join(" + ")},ij=t=>t.replace(/\s+/g," ").trim(),oj=t=>{for(const n of t)if(cc(n)==="text"){const r=ij(sj(n));if(r.length===0)continue;return r}const e=t.filter(n=>cc(n)!=="text").length;return e===0?"":`${e} attachment${e===1?"":"s"}`},aj=(t,e,n)=>`${n(t)} / ${n(e)}`,lj=t=>{if(t==="12h")return!0;if(t==="24h")return!1},cj=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=lj(e);return new Date(t).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:n===!1?"2-digit":"numeric",minute:"2-digit",...n===void 0?{}:{hour12:n}})},dc={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},ha={user:0,assistant:0,tool:0,other:0},Ei=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Ol=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(f=>f.tokens!==void 0)?.tokens;if(typeof n=="number")return{...dc,total:Ei(n)};if(!n||typeof n!="object")return dc;const r=n,o=Ei(r.input),a=Ei(r.output),c=Ei(r.reasoning),l=Ei(r.cache?.read),d=Ei(r.cache?.write);return{input:o,output:a,reasoning:c,cacheRead:l,cacheWrite:d,total:o+a+c+l+d}},dj=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},cr=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+cr(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+cr(n),0):0,uj=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...ha,assistant:cr(n.text)+cr(n.content)};const o=dj(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:cr(n.input)+cr(n.output)+cr(n.error)+cr(n.call?.input)+cr(n.call?.output)+cr(n.call?.error)+cr(n.raw)+Math.round(cr(n.metadata)*.25)+Math.round(cr(n.state)*.1),other:0}:e==="user"?{user:o.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:o.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:o.length}},ef=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),fj=t=>{const e=Uo(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},mj=(t,e)=>{if(t.length===0)return{...ha};const n=t.reduce((r,o)=>{const a=fj(o);let c={...ha};for(const l of o.parts)c=ef(c,uj(l,a));return ef(r,c)},{...ha});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},Mi=t=>t.toLocaleString(oo()),hj=t=>!Number.isFinite(t)||t<=0?new Intl.NumberFormat(oo(),{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(oo(),{style:"currency",currency:"USD",minimumFractionDigits:t<.01?4:2,maximumFractionDigits:t<.01?4:2}).format(t),pj=(t,e)=>!t||!Number.isFinite(t)?"-":Pc(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),gj=(t,e,n)=>{const r=t.find(a=>a.id===e),o=r?.models?.find(a=>a.id===n);return{providerName:r?.name||e||"-",modelName:o?.name||n||"-",contextLimit:typeof o?.limit?.context=="number"?o.limit.context:null}},xj=()=>{const t=gt.c(202),{t:e}=yt(),n=Ee(bj);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0];const[o,a]=i.useState(r),[c,l]=i.useState(null),d=i.useRef(null),f=ht(wj),m=Mc(),u=Rg(f??""),p=rs(yj);let x;t[1]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null),a(vj),l(null)},t[1]=x):x=t[1];let b;t[2]!==f?(b=[f],t[2]=f,t[3]=b):b=t[3],i.useEffect(x,b);let w,g;t[4]===Symbol.for("react.memo_cache_sentinel")?(w=()=>()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null)},g=[],t[4]=w,t[5]=g):(w=t[4],g=t[5]),i.useEffect(w,g);let h;t[6]===Symbol.for("react.memo_cache_sentinel")?(h=async(qe,et)=>{(await gr(et)).ok?(l(qe),d.current!==null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>{l(Ct=>Ct===qe?null:Ct),d.current=null},2e3)):l(null)},t[6]=h):h=t[6];const k=h;let j;t[7]!==f||t[8]!==m?(j=f?m.find(qe=>qe.id===f)??null:null,t[7]=f,t[8]=m,t[9]=j):j=t[9];const S=j;let N,C,y,P,_,v;if(t[10]!==p||t[11]!==u){N=u.filter(jj);let qe;t[18]!==u?(qe=u.filter(Sj),t[18]=u,t[19]=qe):qe=t[19],v=qe;let et=null;for(let Ct=N.length-1;Ct>=0;Ct=Ct-1,Ct){const Ht=N[Ct];if(Ol(Ht).total>0){et=Ht;break}}P=et?Ol(et):dc,C=Eg({input:P.input,cache:{read:P.cacheRead,write:P.cacheWrite}}),_=N.reduce(Nj,0);const Vt=et?.info??null;y=gj(p,Vt?.providerID||"",Vt?.modelID||""),t[10]=p,t[11]=u,t[12]=N,t[13]=C,t[14]=y,t[15]=P,t[16]=_,t[17]=v}else N=t[12],C=t[13],y=t[14],P=t[15],_=t[16],v=t[17];const F=y,I=F.contextLimit,R=I&&I>0?Math.min(999,P.total/I*100):0;let B;if(t[20]!==u){const qe=[...u].reverse().find(kj)?.info?.system||"";B=mj(u,qe),t[20]=u,t[21]=B}else B=t[21];const D=B,W=D.user,U=D.assistant,L=D.tool,M=Math.max(0,P.input-W-U-L),ee=W+U+L+M,ie=u[0]?.info?.time?.created,te=u.length>0?u[u.length-1]?.info?.time?.created:null;let H;t[22]!==S?.title||t[23]!==e?(H=S?.title||e("contextSidebar.session.untitled"),t[22]=S?.title,t[23]=e,t[24]=H):H=t[24];const J=S?.time?.created??ie??null,re=te??S?.time?.created??null;let oe;t[25]!==U||t[26]!==M||t[27]!==L||t[28]!==W?(oe={user:W,assistant:U,tool:L,other:M},t[25]=U,t[26]=M,t[27]=L,t[28]=W,t[29]=oe):oe=t[29];let ve;t[30]!==N.length||t[31]!==ee||t[32]!==C||t[33]!==I||t[34]!==F||t[35]!==u.length||t[36]!==J||t[37]!==re||t[38]!==oe||t[39]!==H||t[40]!==P||t[41]!==_||t[42]!==R||t[43]!==v.length?(ve={sessionTitle:H,messagesCount:u.length,userMessagesCount:v.length,assistantMessagesCount:N.length,createdAt:J,lastActivityAt:re,providerModel:F,tokenBreakdown:P,usagePercent:R,cacheHitRate:C,totalAssistantCost:_,contextLimit:I,breakdown:oe,breakdownTotal:ee},t[30]=N.length,t[31]=ee,t[32]=C,t[33]=I,t[34]=F,t[35]=u.length,t[36]=J,t[37]=re,t[38]=oe,t[39]=H,t[40]=P,t[41]=_,t[42]=R,t[43]=v.length,t[44]=ve):ve=t[44];const ne=ve;if(!f){let qe;t[45]!==e?(qe=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=qe):qe=t[46];let et;return t[47]!==qe?(et=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:qe}),t[47]=qe,t[48]=et):et=t[48],et}let ye;t[49]!==e?(ye=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=ye):ye=t[50];let he;t[51]!==ye||t[52]!==ne.breakdown.user?(he={key:"user",label:ye,value:ne.breakdown.user,color:"var(--status-success)"},t[51]=ye,t[52]=ne.breakdown.user,t[53]=he):he=t[53];let Fe;t[54]!==e?(Fe=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=Fe):Fe=t[55];let z;t[56]!==Fe||t[57]!==ne.breakdown.assistant?(z={key:"assistant",label:Fe,value:ne.breakdown.assistant,color:"var(--primary-base)"},t[56]=Fe,t[57]=ne.breakdown.assistant,t[58]=z):z=t[58];let K;t[59]!==e?(K=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=K):K=t[60];let Y;t[61]!==K||t[62]!==ne.breakdown.tool?(Y={key:"tool",label:K,value:ne.breakdown.tool,color:"var(--status-warning)"},t[61]=K,t[62]=ne.breakdown.tool,t[63]=Y):Y=t[63];let me;t[64]!==e?(me=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=me):me=t[65];let Ne;t[66]!==me||t[67]!==ne.breakdown.other?(Ne={key:"other",label:me,value:ne.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=me,t[67]=ne.breakdown.other,t[68]=Ne):Ne=t[68];let Be;t[69]!==he||t[70]!==z||t[71]!==Y||t[72]!==Ne?(Be=[he,z,Y,Ne],t[69]=he,t[70]=z,t[71]=Y,t[72]=Ne,t[73]=Be):Be=t[73];const _e=Be;let Oe;t[74]!==ne.sessionTitle?(Oe=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ne.sessionTitle}),t[74]=ne.sessionTitle,t[75]=Oe):Oe=t[75];let pe;t[76]!==ne.providerModel.modelName||t[77]!==ne.providerModel.providerName?(pe=s.jsxs("span",{children:[ne.providerModel.providerName," / ",ne.providerModel.modelName]}),t[76]=ne.providerModel.modelName,t[77]=ne.providerModel.providerName,t[78]=pe):pe=t[78];let Re;t[79]!==n||t[80]!==ne.createdAt?(Re=ne.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:pj(ne.createdAt,n)})]}),t[79]=n,t[80]=ne.createdAt,t[81]=Re):Re=t[81];let ge;t[82]!==pe||t[83]!==Re?(ge=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[pe,Re]}),t[82]=pe,t[83]=Re,t[84]=ge):ge=t[84];let ce;t[85]!==Oe||t[86]!==ge?(ce=s.jsxs("div",{className:"mb-6",children:[Oe,ge]}),t[85]=Oe,t[86]=ge,t[87]=ce):ce=t[87];let Ce;t[88]!==e?(Ce=e("contextSidebar.section.context"),t[88]=e,t[89]=Ce):Ce=t[89];let be;t[90]!==Ce?(be=s.jsx("span",{className:"typography-micro text-muted-foreground",children:Ce}),t[90]=Ce,t[91]=be):be=t[91];let ue;t[92]!==ne.tokenBreakdown.total?(ue=Mi(ne.tokenBreakdown.total),t[92]=ne.tokenBreakdown.total,t[93]=ue):ue=t[93];let De;t[94]!==ne.contextLimit?(De=ne.contextLimit?` / ${Mi(ne.contextLimit)}`:"",t[94]=ne.contextLimit,t[95]=De):De=t[95];let T;t[96]!==ue||t[97]!==De?(T=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[ue,De]}),t[96]=ue,t[97]=De,t[98]=T):T=t[98];let V;t[99]!==be||t[100]!==T?(V=s.jsxs("div",{className:"flex items-baseline justify-between",children:[be,T]}),t[99]=be,t[100]=T,t[101]=V):V=t[101];let we;t[102]!==ne.usagePercent?(we=ne.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,ne.usagePercent)}%`,backgroundColor:ne.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[102]=ne.usagePercent,t[103]=we):we=t[103];let E;t[104]!==we?(E=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:we}),t[104]=we,t[105]=E):E=t[105];let de;t[106]!==e||t[107]!==ne.usagePercent?(de=e("contextSidebar.context.percentUsed",{percent:ne.usagePercent.toFixed(1)}),t[106]=e,t[107]=ne.usagePercent,t[108]=de):de=t[108];let fe;t[109]!==de?(fe=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:de}),t[109]=de,t[110]=fe):fe=t[110];let $;t[111]!==V||t[112]!==E||t[113]!==fe?($=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[V,E,fe]}),t[111]=V,t[112]=E,t[113]=fe,t[114]=$):$=t[114];let ke;t[115]!==e?(ke=e("contextSidebar.stats.messages"),t[115]=e,t[116]=ke):ke=t[116];let Ve;t[117]!==ne.messagesCount?(Ve=Mi(ne.messagesCount),t[117]=ne.messagesCount,t[118]=Ve):Ve=t[118];let Se;t[119]!==ke||t[120]!==Ve?(Se={label:ke,value:Ve},t[119]=ke,t[120]=Ve,t[121]=Se):Se=t[121];let q;t[122]!==e?(q=e("contextSidebar.stats.user"),t[122]=e,t[123]=q):q=t[123];let O;t[124]!==ne.userMessagesCount?(O=Mi(ne.userMessagesCount),t[124]=ne.userMessagesCount,t[125]=O):O=t[125];let se;t[126]!==q||t[127]!==O?(se={label:q,value:O},t[126]=q,t[127]=O,t[128]=se):se=t[128];let Le;t[129]!==e?(Le=e("contextSidebar.stats.assistant"),t[129]=e,t[130]=Le):Le=t[130];let ae;t[131]!==ne.assistantMessagesCount?(ae=Mi(ne.assistantMessagesCount),t[131]=ne.assistantMessagesCount,t[132]=ae):ae=t[132];let We;t[133]!==Le||t[134]!==ae?(We={label:Le,value:ae},t[133]=Le,t[134]=ae,t[135]=We):We=t[135];let Ye;t[136]!==e?(Ye=e("contextSidebar.stats.cost"),t[136]=e,t[137]=Ye):Ye=t[137];let Qe;t[138]!==ne.totalAssistantCost?(Qe=hj(ne.totalAssistantCost),t[138]=ne.totalAssistantCost,t[139]=Qe):Qe=t[139];let st;t[140]!==Ye||t[141]!==Qe?(st={label:Ye,value:Qe},t[140]=Ye,t[141]=Qe,t[142]=st):st=t[142];let pt;t[143]!==Se||t[144]!==se||t[145]!==We||t[146]!==st?(pt=[Se,se,We,st],t[143]=Se,t[144]=se,t[145]=We,t[146]=st,t[147]=pt):pt=t[147];const jt=pt;let Et;t[148]!==jt?(Et=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:jt.map(Cj)}),t[148]=jt,t[149]=Et):Et=t[149];let Rt;t[150]!==e?(Rt=e("contextSidebar.section.lastAssistantMessage"),t[150]=e,t[151]=Rt):Rt=t[151];let Ut;t[152]!==Rt?(Ut=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:Rt}),t[152]=Rt,t[153]=Ut):Ut=t[153];let ts;t[154]!==e||t[155]!==ne.cacheHitRate.hasInput||t[156]!==ne.cacheHitRate.percent||t[157]!==ne.tokenBreakdown.cacheRead||t[158]!==ne.tokenBreakdown.cacheWrite||t[159]!==ne.tokenBreakdown.input||t[160]!==ne.tokenBreakdown.output||t[161]!==ne.tokenBreakdown.reasoning?(ts=s.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:ne.tokenBreakdown.input,format:"count"},{label:e("contextSidebar.tokens.output"),value:ne.tokenBreakdown.output,format:"count"},{label:e("contextSidebar.tokens.reasoning"),value:ne.tokenBreakdown.reasoning,format:"count"},{label:e("contextSidebar.tokens.cacheRead"),value:ne.tokenBreakdown.cacheRead,format:"count"},{label:e("contextSidebar.tokens.cacheWrite"),value:ne.tokenBreakdown.cacheWrite,format:"count"},{label:e("contextSidebar.tokens.cacheHit"),value:ne.cacheHitRate.hasInput?ne.cacheHitRate.percent:null,format:"percent"}].map(Aj)}),t[154]=e,t[155]=ne.cacheHitRate.hasInput,t[156]=ne.cacheHitRate.percent,t[157]=ne.tokenBreakdown.cacheRead,t[158]=ne.tokenBreakdown.cacheWrite,t[159]=ne.tokenBreakdown.input,t[160]=ne.tokenBreakdown.output,t[161]=ne.tokenBreakdown.reasoning,t[162]=ts):ts=t[162];let Kt;t[163]!==Ut||t[164]!==ts?(Kt=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Ut,ts]}),t[163]=Ut,t[164]=ts,t[165]=Kt):Kt=t[165];let is;t[166]!==_e||t[167]!==ne.breakdownTotal?(is=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:_e.map(qe=>qe.value<=0||ne.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${qe.value/ne.breakdownTotal*100}%`,backgroundColor:qe.color}},qe.key))}),t[166]=_e,t[167]=ne.breakdownTotal,t[168]=is):is=t[168];let qt;t[169]!==_e||t[170]!==ne.breakdownTotal?(qt=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:_e.map(qe=>{const et=ne.breakdownTotal>0?qe.value/ne.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:qe.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[qe.label," ",s.jsxs("span",{className:"tabular-nums",children:[et.toFixed(0),"%"]})]})]},qe.key)})}),t[169]=_e,t[170]=ne.breakdownTotal,t[171]=qt):qt=t[171];let Te;t[172]!==is||t[173]!==qt?(Te=s.jsxs("div",{className:"mb-6",children:[is,qt]}),t[172]=is,t[173]=qt,t[174]=Te):Te=t[174];let Ke;t[175]!==e?(Ke=e("contextSidebar.section.rawMessages"),t[175]=e,t[176]=Ke):Ke=t[176];let rt;t[177]!==Ke?(rt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ke}),t[177]=Ke,t[178]=rt):rt=t[178];let vt;if(t[179]!==c||t[180]!==o||t[181]!==u||t[182]!==e||t[183]!==n){let qe;t[185]!==c||t[186]!==o||t[187]!==e||t[188]!==n?(qe=et=>{const Ct=Uo(et.info).role,Ht=Ct==="assistant",ss=Ct==="user",Xt=o[et.info.id]===!0,Ft=c===et.info.id,_t=et.info.time?.created??null,hs=rj(et.parts),Zt=Ht?Ol({info:et.info,parts:et.parts}):null,ns=ss?oj(et.parts):"",gs=cj(_t,n),Mt=hs||"—",Bt=Zt?aj(Zt.input,Zt.output,Mi):"",$t=Ct||"unknown",os=hs?`${$t}: ${hs}`:$t,Gt=Xt?JSON.stringify({info:et.info,parts:et.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":Xt,onClick:()=>{a(Me=>({...Me,[et.info.id]:Me[et.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:Ht?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[ss?s.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",ns]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:Ht?Mt:os}),Ht&&s.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:Bt})]}),s.jsx("span",{className:"text-right text-muted-foreground",children:gs})]})}),Xt&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:Me=>{Me.stopPropagation(),k(et.info.id,Gt)},"aria-label":e(Ft?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Ft?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Ft?s.jsx(A,{name:"check",className:"size-3.5"}):s.jsx(A,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Mg,{language:"json",code:Gt,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},et.info.id)},t[185]=c,t[186]=o,t[187]=e,t[188]=n,t[189]=qe):qe=t[189],vt=[...u].reverse().map(qe),t[179]=c,t[180]=o,t[181]=u,t[182]=e,t[183]=n,t[184]=vt}else vt=t[184];let Je;t[190]!==vt?(Je=s.jsx("div",{className:"mt-2.5 space-y-1",children:vt}),t[190]=vt,t[191]=Je):Je=t[191];let St;t[192]!==rt||t[193]!==Je?(St=s.jsxs("div",{children:[rt,Je]}),t[192]=rt,t[193]=Je,t[194]=St):St=t[194];let Xe;return t[195]!==ce||t[196]!==$||t[197]!==Et||t[198]!==Kt||t[199]!==Te||t[200]!==St?(Xe=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[ce,$,Et,Kt,Te,St]})}),t[195]=ce,t[196]=$,t[197]=Et,t[198]=Kt,t[199]=Te,t[200]=St,t[201]=Xe):Xe=t[201],Xe};function bj(t){return t.timeFormatPreference}function wj(t){return t.currentSessionId}function yj(t){return t.providers}function vj(t){return Object.keys(t).length>0?{}:t}function jj(t){return Uo(t.info).role==="assistant"}function Sj(t){return Uo(t.info).isUser}function Nj(t,e){const n=Ei(e.info.cost);return t+n}function kj(t){return Uo(t.info).isUser&&typeof t.info.system=="string"}function Cj(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function Aj(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value!==null&&t.value!==void 0?t.format==="percent"?`${t.value.toFixed(1)}%`:Mi(t.value):"—"})]},t.label)}const Dj=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.x=="number"&&typeof e.y=="number"},tf=t=>!t||typeof t!="object"?!1:Object.values(t).every(e=>typeof e=="string"),to=t=>{if(!t||typeof t!="object")return!1;const e=t,n=e.bounds;return typeof e.tag=="string"&&typeof e.text=="string"&&typeof e.selector=="string"&&typeof e.path=="string"&&!!n&&typeof n?.x=="number"&&typeof n?.y=="number"&&typeof n?.width=="number"&&typeof n?.height=="number"&&Dj(e.center)&&tf(e.attributes)&&tf(e.computedStyle)&&Array.isArray(e.ancestry)},Xc=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:o,intro:a})=>{const c=r.text.trim(),l=Object.entries(r.attributes).map(([x,b])=>`${x}="${b}"`).join(" "),d=r.computedStyle,f=r.bounds,m=r.center,u=a.replace(/[.:]+$/g,""),p=r.ancestry.map(x=>x.selectorPart).join(" > ");return[`${u}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${o?"attached":"not attached"}`,`Element: ${r.tag}`,c?`Text: ${c}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,p?`- Ancestry: ${p}`:null,l?`- Attributes: ${l}`:null,`- Bounds: x=${Math.round(f.x)}, y=${Math.round(f.y)}, width=${Math.round(f.width)}, height=${Math.round(f.height)}`,`- Center: x=${Math.round(m.x)}, y=${Math.round(m.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(x=>typeof x=="string").join(`
|
|
38
|
+
`)},ph=async(t,e)=>{if(typeof window<"u")try{const n=t.getBoundingClientRect(),r=await Zr("desktop_capture_page_rect",{x:n.left,y:n.top,width:n.width,height:n.height});if(!r)throw new Error("Desktop screenshot capture is not available");const o=new Image;await new Promise((b,w)=>{o.onload=()=>b(),o.onerror=()=>w(new Error("Failed to load desktop preview screenshot")),o.src=`data:${r.mime};base64,${r.base64}`});const a=Math.max(1,o.naturalWidth||r.width||Math.floor(n.width)),c=Math.max(1,o.naturalHeight||r.height||Math.floor(n.height)),d=Math.min(1,1200/a),f=document.createElement("canvas");f.width=Math.floor(a*d),f.height=Math.floor(c*d);const m=f.getContext("2d");if(!m)return null;m.scale(d,d),m.drawImage(o,0,0,a,c);const u=a/Math.max(1,n.width),p=c/Math.max(1,n.height);m.fillStyle="rgba(37, 99, 235, 0.28)",m.strokeStyle="rgb(37, 99, 235)",m.lineWidth=Math.max(2,2*u),m.fillRect(e.bounds.x*u,e.bounds.y*p,e.bounds.width*u,e.bounds.height*p),m.strokeRect(e.bounds.x*u,e.bounds.y*p,e.bounds.width*u,e.bounds.height*p);const x=await new Promise(b=>f.toBlob(b,"image/jpeg",.82));return x?new File([x],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(n){return console.warn("[preview] failed to capture annotation screenshot:",n),null}return await Wj(t,e)},Zc=async(t,e,n,r,o,a)=>{if(!t)return null;try{const c=new Image;await new Promise((g,h)=>{c.onload=()=>g(),c.onerror=()=>h(new Error("Failed to load desktop browser screenshot")),c.src=`data:image/jpeg;base64,${t}`});const l=Math.max(1,c.naturalWidth||e),d=Math.max(1,c.naturalHeight||n),m=Math.min(1,1200/l),u=document.createElement("canvas");u.width=Math.floor(l*m),u.height=Math.floor(d*m);const p=u.getContext("2d");if(!p)return null;p.scale(m,m),p.drawImage(c,0,0,l,d);const x=l/Math.max(1,r||l),b=d/Math.max(1,o||d);p.fillStyle="rgba(37, 99, 235, 0.14)",p.strokeStyle="rgb(37, 99, 235)",p.lineWidth=Math.max(2,2*x),p.fillRect(a.bounds.x*x,a.bounds.y*b,a.bounds.width*x,a.bounds.height*b),p.strokeRect(a.bounds.x*x,a.bounds.y*b,a.bounds.width*x,a.bounds.height*b);const w=await new Promise(g=>u.toBlob(g,"image/jpeg",.82));return w?new File([w],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},so="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=",tr=new Map,Ll=new Map,Tj=3e4,ed=t=>{const e=tr.get(t);return e?e.expiresAt-Date.now()<=Tj?(tr.delete(t),null):e:null},Pj=t=>{try{return new URL(t).origin}catch{return t}};function gh(t){const e="#ffffff",n=t.defaultView??window;try{const r=t.body?n.getComputedStyle(t.body).backgroundColor:"";if(r&&r!=="rgba(0, 0, 0, 0)"&&r!=="transparent")return r;const o=n.getComputedStyle(t.documentElement).backgroundColor;if(o&&o!=="rgba(0, 0, 0, 0)"&&o!=="transparent")return o}catch{}return e}const xh=t=>new Promise((e,n)=>{const r=new FileReader;r.onloadend=()=>e(typeof r.result=="string"?r.result:so),r.onerror=()=>n(r.error??new Error("Failed to read image blob")),r.readAsDataURL(t)}),Ij=async(t,e=.82)=>{const n=await new Promise(r=>t.toBlob(r,"image/jpeg",e));return n&&(await xh(n)).split(",",2)[1]||""},Rj=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},pa=(...t)=>{Rj()&&console.info("[preview-capture]",...t)},bh=(t,e=8)=>{const n=[];try{const r=t.querySelectorAll("*");for(const o of r){const a=o.scrollTop||0,c=o.scrollLeft||0;if(a<=0&&c<=0)continue;const l=o.tagName.toLowerCase(),d=o.id?`#${o.id}`:"",f=typeof o.className=="string"&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";if(n.push({selector:`${l}${d}${f}`,scrollTop:a,scrollLeft:c,clientWidth:o.clientWidth,clientHeight:o.clientHeight,scrollWidth:o.scrollWidth,scrollHeight:o.scrollHeight}),n.length>=e)break}}catch{}return n},Mo="data-oc-fixed-pin",Ej=(t,e,n)=>{if(e<=0&&n<=0)return()=>{};const r=t.defaultView;if(!r)return()=>{};const o=[],a=[];try{for(const c of t.querySelectorAll("*")){if(r.getComputedStyle(c).position!=="fixed")continue;const l=c.getBoundingClientRect();if(!(l.width>0&&l.height>0))continue;c.setAttribute(Mo,JSON.stringify({top:l.top+n,left:l.left+e,width:l.width,height:l.height})),o.push(c);const d=c.tagName.toLowerCase(),f=typeof c.className=="string"&&c.className?`.${c.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";a.push({selector:`${d}${f}`,top:Math.round(l.top),left:Math.round(l.left),width:Math.round(l.width),height:Math.round(l.height)})}}catch{}return pa("tagged fixed elements",a),()=>{for(const c of o)try{c.removeAttribute(Mo)}catch{}}},Mj={name:"oc-fixed-pin",afterClone(t){const e=t?.clone;if(!(!e||typeof e.querySelectorAll!="function"))for(const n of e.querySelectorAll(`[${Mo}]`)){let r;try{r=JSON.parse(n.getAttribute(Mo)||"")}catch{continue}n.style.setProperty("position","absolute","important"),n.style.setProperty("top",`${r.top}px`,"important"),n.style.setProperty("left",`${r.left}px`,"important"),n.style.setProperty("right","auto","important"),n.style.setProperty("bottom","auto","important"),n.style.setProperty("width",`${r.width}px`,"important"),n.style.setProperty("height",`${r.height}px`,"important"),n.removeAttribute(Mo)}}},Xi="data-oc-scroll-pin",Fj=t=>{const e=[],n=bh(t,64);try{const a=t.documentElement,c=t.body;for(const l of t.querySelectorAll("*")){const d=l.scrollTop||0,f=l.scrollLeft||0;if(d<=0&&f<=0)continue;const m=l!==a&&l!==c;m&&l.setAttribute(Xi,JSON.stringify({top:d,left:f})),e.push({el:l,top:d,left:f,tagged:m})}}catch{}return{reapply:()=>{for(const a of e)try{a.el.scrollHeight,a.el.scrollTop!==a.top&&(a.el.scrollTop=a.top),a.el.scrollLeft!==a.left&&(a.el.scrollLeft=a.left)}catch{}},cleanup:()=>{for(const a of e)if(a.tagged)try{a.el.removeAttribute(Xi)}catch{}},snapshot:n}},Oj={name:"oc-nested-scroll",afterClone(t){const e=t?.clone;if(!e||typeof e.querySelectorAll!="function")return;const n=e.ownerDocument;if(n)for(const r of e.querySelectorAll(`[${Xi}]`)){let o;try{o=JSON.parse(r.getAttribute(Xi)||"")}catch{r.removeAttribute(Xi);continue}const a=`translate(${-o.left}px, ${-o.top}px)`,c=r.children.length===1&&r.firstElementChild instanceof HTMLElement&&r.firstElementChild.style.willChange==="transform"?r.firstElementChild:null;if(c)c.style.transform=a;else{r.style.overflow="hidden";const l=n.createElement("div");for(l.style.transform=a,l.style.willChange="transform",l.style.display="inline-block",l.style.width="100%";r.firstChild;)l.appendChild(r.firstChild);r.appendChild(l)}r.removeAttribute(Xi)}}},Bl=async(t,e)=>{try{const n=await fetch(t,{credentials:e});return n.ok?await xh(await n.blob()):null}catch{return null}},Lj=async t=>{if(t.protocol!=="http:"&&t.protocol!=="https:")return"";const e=t.origin,n=ed(e);if(n)return`${n.proxyBasePath}${t.pathname}${t.search}${t.hash}`;const r=Ll.get(e),o=r??(async()=>{try{const c=await Is("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:t.toString(),allowExternal:!0})});if(!c.ok)return tr.delete(e),null;const l=await c.json(),d=typeof l.proxyBasePath=="string"?l.proxyBasePath:"",f=typeof l.expiresAt=="number"?l.expiresAt:0;if(!d)return tr.delete(e),null;const m={proxyBasePath:d,expiresAt:f};return tr.set(e,m),m}catch{return tr.delete(e),null}finally{Ll.delete(e)}})();r||Ll.set(e,o);const a=await o;return a?`${a.proxyBasePath}${t.pathname}${t.search}${t.hash}`:""},wh=async(t,e)=>{if(!t||t.startsWith("data:"))return t;try{const n=new URL(t,e.baseURI);if(n.origin===window.location.origin||n.protocol!=="http:"&&n.protocol!=="https:")return await Bl(n.toString(),"include")??so;const r=await Lj(n),o=r?await Bl(r,"include"):null;return o||(await Bl(n.toString(),"omit")??so)}catch{return so}},Bj=async(t,e)=>{if(!t||t==="none"||!t.includes("url("))return t;const n=Array.from(t.matchAll(/url\((['"]?)(.*?)\1\)/g));let r=t;for(const o of n){const a=o[2]||"";if(!a||a.startsWith("data:"))continue;const c=await wh(a,e);r=r.replace(o[0],`url("${c}")`)}return r},sf=t=>t.complete?Promise.resolve():new Promise(e=>{t.addEventListener("load",()=>e(),{once:!0}),t.addEventListener("error",()=>e(),{once:!0})}),yh=t=>{const e=t.style.cssText;return()=>{t.style.cssText=e}},Vj=t=>{const e=Number.parseFloat(t.lineHeight);if(Number.isFinite(e)&&e>0)return e;const n=Number.parseFloat(t.fontSize);return Number.isFinite(n)&&n>0?n*1.2:16},_j=(t,e,n)=>{const r=[],o=t.defaultView??window,c=Array.from(t.querySelectorAll('button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *'));for(const l of c){const d=l.textContent?.replace(/\s+/g," ").trim()??"";if(!d||!d.includes(" "))continue;const f=l.getBoundingClientRect();if(f.width<=0||f.height<=0||f.right<0||f.bottom<0||f.left>e||f.top>n)continue;const m=o.getComputedStyle(l);if(m.display==="none"||m.visibility==="hidden"||Number(m.opacity)===0)continue;const u=m.getPropertyValue("text-wrap"),p=m.getPropertyValue("text-wrap-mode"),x=m.whiteSpace.includes("nowrap")||u==="nowrap"||p==="nowrap",b=f.height<=Vj(m)*1.7;!x&&(!b||f.width>e*.72)||(r.push(yh(l)),l.style.whiteSpace="nowrap",l.style.overflowWrap="normal",l.style.wordBreak="normal",l.style.setProperty("text-wrap","nowrap"),l.style.setProperty("text-wrap-mode","nowrap"))}return()=>{for(let l=r.length-1;l>=0;l-=1)r[l]?.()}},$j=(t,e,n,r)=>{const o=[],a=t.defaultView??window,c=a.scrollX||t.documentElement.scrollLeft||t.body?.scrollLeft||0,l=a.scrollY||t.documentElement.scrollTop||t.body?.scrollTop||0,d=Array.from(t.querySelectorAll("*")).filter(f=>{const m=a.getComputedStyle(f);if(m.position!=="fixed"||m.display==="none"||m.visibility==="hidden"||Number(m.opacity)===0)return!1;const u=f.getBoundingClientRect();return u.width>0&&u.height>0&&u.right>=0&&u.bottom>=0&&u.left<=e&&u.top<=n}).filter((f,m,u)=>!u.some((p,x)=>x<m&&p.contains(f)));for(const f of d){const m=f.getBoundingClientRect(),u=a.getComputedStyle(f),p=Math.ceil(m.width)+8,x=Math.ceil(m.height)+2;r?.add(f),o.push(yh(f)),f.style.position="absolute",f.style.top=`${m.top+l}px`,f.style.left=`${m.left+c}px`,f.style.right="auto",f.style.bottom="auto",f.style.width=`${p}px`,f.style.minWidth=`${p}px`,f.style.height=`${x}px`,f.style.minHeight=`${x}px`,f.style.margin="0",f.style.boxSizing="border-box",f.style.transform="none",u.zIndex!=="auto"&&(f.style.zIndex=u.zIndex)}return()=>{for(let f=o.length-1;f>=0;f-=1)o[f]?.()}},vh=async(t,e,n,r={})=>{const o=[],a=t.defaultView??window,c=u=>{if(u===t.documentElement||u===t.body)return!0;try{const p=u.getBoundingClientRect();return p.width>0&&p.height>0&&p.right>=0&&p.bottom>=0&&p.left<=e&&p.top<=n}catch{return!1}};if(r.applyLayoutWorkarounds){const u=new WeakSet;o.push($j(t,e,n,u)),o.push(_j(t,e,n))}const l=new Map;for(const u of Array.from(t.images))l.set(u,u.currentSrc||u.src||u.getAttribute("src")||"");const d=Array.from(t.querySelectorAll("picture"));for(const u of d){const p=Array.from(u.querySelectorAll("source"));if(p.length===0)continue;const x=p.map(b=>({source:b,srcset:b.getAttribute("srcset"),sizes:b.getAttribute("sizes")}));o.push(()=>{for(const b of x)b.srcset===null?b.source.removeAttribute("srcset"):b.source.setAttribute("srcset",b.srcset),b.sizes===null?b.source.removeAttribute("sizes"):b.source.setAttribute("sizes",b.sizes)});for(const b of p)b.removeAttribute("srcset"),b.removeAttribute("sizes")}const f=Array.from(t.images).filter(u=>c(u));await Promise.all(f.map(async u=>{const p=l.get(u)||u.currentSrc||u.src||u.getAttribute("src")||"";if(!p)return;await sf(u);const x=await wh(p,t),b={src:u.getAttribute("src"),srcset:u.getAttribute("srcset"),sizes:u.getAttribute("sizes")};o.push(()=>{b.src===null?u.removeAttribute("src"):u.setAttribute("src",b.src),b.srcset===null?u.removeAttribute("srcset"):u.setAttribute("srcset",b.srcset),b.sizes===null?u.removeAttribute("sizes"):u.setAttribute("sizes",b.sizes)}),u.removeAttribute("srcset"),u.removeAttribute("sizes"),u.setAttribute("src",x||so),await sf(u)}));const m=Array.from(t.querySelectorAll("*")).filter(c);return await Promise.all(m.map(async u=>{const p=a.getComputedStyle(u).backgroundImage;if(!p||p==="none"||!p.includes("url("))return;const x=await Bj(p,t);if(x===p)return;const b=u.style.backgroundImage;o.push(()=>{u.style.backgroundImage=b}),u.style.backgroundImage=x})),()=>{for(let u=o.length-1;u>=0;u-=1)try{o[u]?.()}catch{}}};async function zj(t,e){try{const n=t.contentWindow,r=t.contentDocument??n?.document,o=r?.documentElement;if(!n||!r||!o)return null;const a=t.getBoundingClientRect(),c=Math.max(1,Math.ceil(n.innerWidth||t.clientWidth||a.width)),l=Math.max(1,Math.ceil(n.innerHeight||t.clientHeight||a.height)),d=r.body,f=r.scrollingElement instanceof HTMLElement?r.scrollingElement:null,m=n.scrollX||0,u=n.scrollY||0,p=n.pageXOffset||0,x=n.pageYOffset||0,b=n.visualViewport?.pageLeft||n.visualViewport?.offsetLeft||0,w=n.visualViewport?.pageTop||n.visualViewport?.offsetTop||0,g=o.scrollLeft||0,h=o.scrollTop||0,k=d?.scrollLeft||0,j=d?.scrollTop||0,S=f?.scrollLeft||0,N=f?.scrollTop||0,C=Math.max(m,p,b,g,k,S),y=Math.max(u,x,w,h,j,N);pa("scroll sources",{windowScrollX:m,windowScrollY:u,pageScrollX:p,pageScrollY:x,visualViewportScrollX:b,visualViewportScrollY:w,rootScrollX:g,rootScrollY:h,bodyScrollX:k,bodyScrollY:j,scrollingElementScrollX:S,scrollingElementScrollY:N,scrollingElementTag:f?.tagName?.toLowerCase()??null,resolvedScrollX:C,resolvedScrollY:y,nestedScrolledElements:bh(r)});const P=Math.max(c,o.scrollWidth||0,d?.scrollWidth||0,Math.ceil(o.getBoundingClientRect().width||0)),_=Math.max(l,o.scrollHeight||0,d?.scrollHeight||0,Math.ceil(o.getBoundingClientRect().height||0)),v=Math.min(2,Math.max(1,window.devicePixelRatio||1)),F=o.style.scrollBehavior,I=d?.style.scrollBehavior??"";o.style.scrollBehavior="auto",d&&(d.style.scrollBehavior="auto");const R=Fj(r);pa("nested scroll snapshot",R.snapshot);let B=()=>{},D=()=>{};try{await r.fonts?.ready.catch(()=>{}),B=await vh(r,c,l,{applyLayoutWorkarounds:!1}),n.scrollTo(C,y),D=Ej(r,C,y),R.reapply();const W={backgroundColor:gh(r),cache:"disabled",dpr:v,embedFonts:!0,fast:!1,height:_,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[Mj,Oj],quality:.82,width:P},L=await(await rp(o,W)).toCanvas();if(!L.width||!L.height)return null;const M=L.width/Math.max(1,P),ee=L.height/Math.max(1,_),ie=Math.min(L.width,Math.max(1,Math.round(c*M))),te=Math.min(L.height,Math.max(1,Math.round(l*ee))),H=Math.max(0,L.width-ie),J=Math.max(0,L.height-te),re=Math.min(H,Math.max(0,Math.round(C*M))),oe=Math.min(J,Math.max(0,Math.round(y*ee)));pa("capture geometry",{viewportWidth:c,viewportHeight:l,captureWidth:P,captureHeight:_,canvasWidth:L.width,canvasHeight:L.height,xScale:M,yScale:ee,sourceX:re,sourceY:oe,sourceWidth:ie,sourceHeight:te});const ve=r.createElement("canvas");ve.width=ie,ve.height=te;const ne=ve.getContext("2d");if(!ne)return null;ne.drawImage(L,re,oe,ie,te,0,0,ie,te);const ye=await Ij(ve,.82);return ye?await Zc(ye,c,l,c,l,e):null}finally{D(),R.cleanup(),B(),n.scrollTo(C,y),R.reapply(),o.style.scrollBehavior=F,d&&(d.style.scrollBehavior=I)}}catch(n){return console.warn("[preview] failed to capture iframe DOM screenshot with snapDOM:",n),null}}async function Wj(t,e){const n=await zj(t,e);if(n)return n;try{const r=t.contentWindow,o=t.contentDocument??r?.document,a=o?.documentElement;if(!r||!o||!a)return null;const c=t.getBoundingClientRect(),l=Math.max(1,Math.ceil(r.innerWidth||t.clientWidth||c.width)),d=Math.max(1,Math.ceil(r.innerHeight||t.clientHeight||c.height)),f=r.scrollX||o.documentElement.scrollLeft||o.body?.scrollLeft||0,m=r.scrollY||o.documentElement.scrollTop||o.body?.scrollTop||0,u=o.body,p=Math.max(d,a.scrollHeight||0,u?.scrollHeight||0),x=Math.min(2,Math.max(1,window.devicePixelRatio||1)),b=a.style.scrollBehavior,w=u?.style.scrollBehavior??"";a.style.scrollBehavior="auto",u&&(u.style.scrollBehavior="auto");let g="",h=()=>{};try{await o.fonts?.ready.catch(()=>{}),h=await vh(o,l,d,{applyLayoutWorkarounds:!0}),r.scrollTo(f,m);const j=await sp(a).catch(()=>"");g=await np(a,{quality:.82,pixelRatio:x,width:l,height:d,backgroundColor:gh(o),imagePlaceholder:so,fontEmbedCSS:j||void 0,style:{transform:`translate(${-f}px, ${-m}px)`,transformOrigin:"top left",minWidth:`${l}px`,minHeight:`${p}px`},cacheBust:!0})}finally{h(),r.scrollTo(f,m),a.style.scrollBehavior=b,u&&(u.style.scrollBehavior=w)}const k=g.split(",",2)[1]||"";return k?await Zc(k,l,d,l,d,e):null}catch(r){return console.warn("[preview] failed to capture iframe DOM screenshot:",r),null}}const jh=380,Uj=1400,Sh=600,Hj=24,Ba=new Map,nf=200,Gj=(t,e)=>e==="all"?!0:e==="errors"?t.level==="error"||t.level==="runtime"||t.level==="resource":e==="warnings"?t.level==="warn":t.level==="log"||t.level==="info"||t.level==="debug",Kj=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},Nh=t=>Number.isFinite(t)?Math.min(Uj,Math.max(jh,Math.round(t))):Sh,qj=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},Vl=(t,e)=>{const n=Nh(t),r=qj(e);return r===null?n:Math.min(n,Math.max(1,r))},Yj=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},Qj=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="plan"?"contextPanel.mode.plan":t==="preview"?"contextPanel.mode.preview":t==="browser"?"contextPanel.mode.browser":"contextPanel.mode.context"),Jj=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},Xj=(t,e,n)=>{if(t.mode==="chat"){const r=ga(t.dedupeKey);if(r){const a=e.get(r)?.trim();if(a)return a}const o=t.sessionTitleFallback?.trim();return o||n("contextPanel.mode.chat")}if(t.label)return t.label;if(t.mode==="file")return Jj(t.targetPath)||n("contextPanel.mode.files");if(t.mode==="preview"){const r=t.targetPath;if(r)try{const o=new URL(r);return o.host||o.hostname||n("contextPanel.mode.preview")}catch{}return n("contextPanel.mode.preview")}return t.mode==="diff"?n("contextPanel.mode.diff"):Qj(t.mode,n)},Zj=t=>{if(t.mode==="file")return t.targetPath?s.jsx(ei,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(A,{name:"arrow-left-right",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(A,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(A,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(A,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(A,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(A,{name:"global",className:"h-3.5 w-3.5"})},ga=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,e0=(t,e)=>{if(t.size!==e.size)return!1;for(const[n,r]of t)if(e.get(n)!==r)return!1;return!0},t0=(t,e)=>{if(e.length===0)return Ba;const n=new Set(e),r=new Map;for(const o of t){if(!n.has(o.id))continue;const a=o.title?.trim();a&&r.set(o.id,a)}return r.size===0?Ba:r},s0=(t,e)=>{const n=gm(t),r=i.useRef(Ba),o=i.useRef(e);return o.current=e,i.useSyncExternalStore(n.subscribe,i.useCallback(()=>{const a=t0(n.getState().session,o.current);return e0(r.current,a)?r.current:(r.current=a,a)},[n]),()=>Ba)},kh=`new Promise((resolve) => {
|
|
39
|
+
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
40
|
+
if (existing) existing.remove();
|
|
41
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
42
|
+
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
43
|
+
}
|
|
44
|
+
const overlay = document.createElement('div');
|
|
45
|
+
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
46
|
+
overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
|
|
47
|
+
document.documentElement.appendChild(overlay);
|
|
48
|
+
const cssEscape = (value) => {
|
|
49
|
+
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
50
|
+
};
|
|
51
|
+
const selectorPart = (element) => {
|
|
52
|
+
const tag = element.tagName.toLowerCase();
|
|
53
|
+
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
54
|
+
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
55
|
+
return tag + className;
|
|
56
|
+
};
|
|
57
|
+
const metadata = (element) => {
|
|
58
|
+
const rect = element.getBoundingClientRect();
|
|
59
|
+
const style = getComputedStyle(element);
|
|
60
|
+
const ancestry = [];
|
|
61
|
+
let current = element;
|
|
62
|
+
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
63
|
+
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
64
|
+
current = current.parentElement;
|
|
65
|
+
}
|
|
66
|
+
const attrs = {};
|
|
67
|
+
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
68
|
+
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
69
|
+
return {
|
|
70
|
+
frame: 'top',
|
|
71
|
+
tag: element.tagName.toLowerCase(),
|
|
72
|
+
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
73
|
+
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
74
|
+
path,
|
|
75
|
+
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
76
|
+
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
77
|
+
attributes: attrs,
|
|
78
|
+
computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
|
|
79
|
+
ancestry,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const move = (event) => {
|
|
83
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
84
|
+
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
85
|
+
const rect = element.getBoundingClientRect();
|
|
86
|
+
overlay.style.display = 'block';
|
|
87
|
+
overlay.style.left = rect.left + 'px';
|
|
88
|
+
overlay.style.top = rect.top + 'px';
|
|
89
|
+
overlay.style.width = rect.width + 'px';
|
|
90
|
+
overlay.style.height = rect.height + 'px';
|
|
91
|
+
};
|
|
92
|
+
const cleanup = () => {
|
|
93
|
+
window.removeEventListener('mousemove', move, true);
|
|
94
|
+
window.removeEventListener('click', click, true);
|
|
95
|
+
window.removeEventListener('keydown', keydown, true);
|
|
96
|
+
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
97
|
+
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const cancel = () => {
|
|
101
|
+
cleanup();
|
|
102
|
+
overlay.remove();
|
|
103
|
+
resolve(null);
|
|
104
|
+
};
|
|
105
|
+
const click = (event) => {
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
event.stopPropagation();
|
|
108
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
109
|
+
const result = element ? metadata(element) : null;
|
|
110
|
+
cleanup();
|
|
111
|
+
overlay.remove();
|
|
112
|
+
resolve(result);
|
|
113
|
+
};
|
|
114
|
+
const keydown = (event) => {
|
|
115
|
+
if (event.key !== 'Escape') return;
|
|
116
|
+
cancel();
|
|
117
|
+
};
|
|
118
|
+
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
119
|
+
window.addEventListener('mousemove', move, true);
|
|
120
|
+
window.addEventListener('click', click, true);
|
|
121
|
+
window.addEventListener('keydown', keydown, true);
|
|
122
|
+
});`,xa=`(() => {
|
|
123
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
124
|
+
window.__openchamberDesktopBrowserCancelInspect();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
128
|
+
if (overlay) overlay.remove();
|
|
129
|
+
})()`,n0=`(() => {
|
|
130
|
+
if (window.__openchamberSameWebviewNavigationInstalled) return;
|
|
131
|
+
window.__openchamberSameWebviewNavigationInstalled = true;
|
|
132
|
+
|
|
133
|
+
const navigate = (rawUrl) => {
|
|
134
|
+
if (typeof rawUrl !== 'string' || rawUrl.length === 0) return false;
|
|
135
|
+
try {
|
|
136
|
+
const url = new URL(rawUrl, window.location.href);
|
|
137
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
|
|
138
|
+
window.location.assign(url.href);
|
|
139
|
+
return true;
|
|
140
|
+
} catch (_error) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const originalOpen = window.open.bind(window);
|
|
146
|
+
window.open = (url, target, features) => {
|
|
147
|
+
if (navigate(url)) return null;
|
|
148
|
+
return originalOpen(url, target, features);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
document.addEventListener('click', (event) => {
|
|
152
|
+
if (event.defaultPrevented) return;
|
|
153
|
+
const target = event.target;
|
|
154
|
+
if (!(target instanceof Element)) return;
|
|
155
|
+
const anchor = target.closest('a[target="_blank"][href]');
|
|
156
|
+
if (!(anchor instanceof HTMLAnchorElement)) return;
|
|
157
|
+
if (!navigate(anchor.href)) return;
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
event.stopPropagation();
|
|
160
|
+
}, true);
|
|
161
|
+
})()`,Fo=t=>{const e=t.trim();if(!e)return"about:blank";try{const n=new URL(e.includes("://")?e:`https://${e}`);return n.protocol!=="http:"&&n.protocol!=="https:"?"about:blank":n.toString()}catch{return"about:blank"}},rf=async(t,e)=>{const n=t.contentWindow;if(!n)throw new Error("Iframe window is not available");const o=n.eval.call(n,e);return await Promise.resolve(o)},r0=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Ch=t=>{if(typeof window>"u")return"";try{return new URL(t||window.location.href,window.location.href).origin}catch{return window.location.origin}},of=(t,e,n)=>{const r=Ch(e);t.postMessage(n,r)},i0=t=>{if(!t)return t;try{const e=new URL(t);return e.searchParams.delete("oc_preview_token"),e.searchParams.delete("oc_client_token"),e.searchParams.delete("oc_url_token"),e.toString()}catch{return t}},af=t=>{if(!t)return t;try{const e=new URL(t);return e.searchParams.delete("ocPreview"),e.searchParams.delete("oc_preview_token"),e.searchParams.delete("oc_client_token"),e.searchParams.delete("oc_url_token"),e.toString()}catch{return t}},o0=({rawUrl:t,onNavigate:e})=>{const{t:n}=yt(),{currentTheme:r}=wi(),[o,a]=i.useReducer(pe=>pe+1,0),[c,l]=i.useReducer(pe=>pe+1,0),[d,f]=i.useState({status:"idle"}),[m,u]=i.useState(""),p=i.useRef(null),x=i.useRef(1),[b,w]=i.useState(!1),[g,h]=i.useState(!1),[k,j]=i.useState("all"),[S,N]=i.useState([]),[C,y]=i.useState(!1),[P,_]=i.useState(null),v=ht(pe=>pe.currentSessionId),F=ht(pe=>pe.newSessionDraft?.open),I=Fc(pe=>pe.addDraft),R=xi(pe=>pe.addAttachedFile);let B=null;try{B=t?new URL(t):null}catch{B=null}const D=B?B.hostname==="localhost"||B.hostname==="127.0.0.1"||B.hostname==="::1"||B.hostname==="[::1]"||B.hostname==="0.0.0.0":!1,W=B?B.hostname==="0.0.0.0"?new URL(B.toString().replace("0.0.0.0","127.0.0.1")):B:null,U=W?W.toString():"",L=U?`${Xr()||"same-origin"}|${U}`:"",M=r.metadata.variant;i.useEffect(()=>{if(!U||!D){f({status:"idle"});return}const pe=ed(L);if(pe?.previewToken){f({status:"ready",proxyBasePath:pe.proxyBasePath,previewToken:pe.previewToken,expiresAt:pe.expiresAt});return}pe&&tr.delete(L);let Re=!1;return f({status:"loading"}),(async()=>{try{const ge=await Is("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:U})});if(!ge.ok){tr.delete(L);const De=await ge.json().catch(()=>({})),T=typeof De?.error=="string"?De.error:`HTTP ${ge.status}`;Re||f({status:"error",message:T});return}const ce=await ge.json(),Ce=typeof ce.proxyBasePath=="string"?ce.proxyBasePath:"",be=typeof ce.previewToken=="string"?ce.previewToken:"",ue=typeof ce.expiresAt=="number"?ce.expiresAt:0;if(!Ce||!be){tr.delete(L),Re||f({status:"error",message:n("contextPanel.preview.proxyError")});return}tr.set(L,{proxyBasePath:Ce,previewToken:be,expiresAt:ue}),Re||f({status:"ready",proxyBasePath:Ce,previewToken:be,expiresAt:ue})}catch(ge){if(tr.delete(L),!Re){const ce=ge instanceof Error?ge.message:String(ge);f({status:"error",message:ce})}}})(),()=>{Re=!0}},[D,L,c,n,U]);const ee=W&&(W.protocol==="http:"||W.protocol==="https:")?W.toString():"",ie=D&&d.status==="ready"?`${d.proxyBasePath}|${d.previewToken||""}|${o}`:"";i.useEffect(()=>{if(!ie){u("");return}let pe=!1;return u(""),jc(Xr()).then(Re=>{!pe&&Re&&u(ie)}).catch(()=>{}),()=>{pe=!0}},[ie]);const te=D&&d.status==="ready"&&W&&m===ie?(()=>{const pe=W.pathname||"/",Re=new URLSearchParams(W.search);Re.delete("oc_url_token"),Re.delete("oc_client_token"),Re.set("ocPreview",String(o)),Re.set("oc_preview_token",d.previewToken||"");const ge=Re.toString(),ce=W.hash||"";return Li().authenticatedAsset(`${d.proxyBasePath}${pe}${ge?`?${ge}`:""}${ce}`)})():"",H=D?te:ee,J=D?i0(te):ee,re=D&&(d.status==="loading"||d.status==="idle"||m!==ie),oe=D&&d.status==="error",ve=i.useCallback(pe=>{const Re=v??(F?"draft":null);if(!Re){le.error(n("contextPanel.preview.inspect.attachNoSession"));return}const ge=t||H||"",ce=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},Ce=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let be=!1;try{const ue=p.current,De=ue?await ph(ue,pe):null;De&&(await R(De),be=!0)}catch{be=!1}I({sessionKey:Re,source:"preview-annotation",fileLabel:ge||"preview",startLine:1,endLine:1,code:Xc({pageUrl:ge,viewport:ce,devicePixelRatio:Ce,target:pe,screenshotAttached:be,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),le.success(n("contextPanel.preview.inspect.attached"))})()},[R,I,v,H,F,t,n]);i.useEffect(()=>{w(!1),N([]),h(!1),j("all"),y(!1),_(null),x.current=1},[H]),i.useEffect(()=>{const pe=p.current?.contentWindow;!b||!pe||of(pe,te,{source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:C})},[b,C,te]),i.useEffect(()=>{const pe=p.current?.contentWindow;!b||!pe||of(pe,te,{source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:M})},[b,M,te]),i.useEffect(()=>{if(!C||typeof window>"u")return;const pe=Re=>{Re.key==="Escape"&&(Re.preventDefault(),Re.stopImmediatePropagation(),y(!1))};return window.addEventListener("keydown",pe,!0),()=>window.removeEventListener("keydown",pe,!0)},[C]),i.useEffect(()=>{if(!D||typeof window>"u")return;const pe=ce=>{if(typeof ce=="string")return ce;if(ce==null)return"";try{return JSON.stringify(ce)}catch{return String(ce)}},Re=ce=>{const Ce=x.current;x.current+=1,N(be=>{const ue=[...be,{...ce,id:Ce}];return ue.length>nf?ue.slice(ue.length-nf):ue})},ge=ce=>{if(ce.source!==p.current?.contentWindow)return;const Ce=ce.data;if(!(!Ce||Ce.source!=="openchamber-preview-bridge"||Ce.version!==1)){if(Ce.type==="ready"){w(!0);return}if(Ce.type==="console"){const be=Ce.level==="error"||Ce.level==="warn"||Ce.level==="info"||Ce.level==="debug"?Ce.level:"log",ue=Array.isArray(Ce.args)?Ce.args.map(pe).filter(Boolean):[];Re({level:be,message:ue.join(" "),ts:typeof Ce.ts=="number"?Ce.ts:Date.now()});return}if(Ce.type==="runtime-error"){const be=pe(Ce.filename),ue=typeof Ce.line=="number"?Ce.line:null,De=typeof Ce.column=="number"?Ce.column:null,T=be?`${be}${ue!==null?`:${ue}${De!==null?`:${De}`:""}`:""}`:"",V=pe(Ce.stack);Re({level:"runtime",message:pe(Ce.message)||n("contextPanel.preview.console.runtimeError"),details:[T,V].filter(Boolean).join(`
|
|
162
|
+
`),ts:typeof Ce.ts=="number"?Ce.ts:Date.now()});return}if(Ce.type==="resource-error"){const be=pe(Ce.tag)||"resource",ue=pe(Ce.url);Re({level:"resource",message:ue?`${be}: ${ue}`:be,details:pe(Ce.outerHTML),ts:typeof Ce.ts=="number"?Ce.ts:Date.now()});return}if(Ce.type==="hover"){_(to(Ce.target)?Ce.target:null);return}if(Ce.type==="select"&&to(Ce.target)){_(Ce.target),y(!1),ve(Ce.target);return}if(Ce.type==="navigate-preview"){const be=typeof Ce.url=="string"?Ce.url:"",ue=Ce.navigation==="external"?"external":"proxy";if(be&&ue==="external"){si(be);return}be&&e(be)}}};return window.addEventListener("message",ge),()=>{window.removeEventListener("message",ge)}},[ve,D,e,n]);const ne=S.filter(pe=>pe.level==="error"||pe.level==="runtime"||pe.level==="resource").length,ye=S.filter(pe=>Gj(pe,k)),he=i.useCallback(()=>{const pe=[`Preview URL: ${t||H||""}`,`Events: ${S.length}`,""].join(`
|
|
163
|
+
`),Re=S.map(ge=>{const ce=new Date(ge.ts).toISOString(),Ce=ge.details?`
|
|
164
|
+
${ge.details}`:"";return`[${ce}] [${ge.level}] ${ge.message}${Ce}`}).join(`
|
|
165
|
+
`);gr(`${pe}${Re}`).then(ge=>{ge.ok?le.success(n("contextPanel.preview.console.copied")):le.error(n("contextPanel.preview.console.copyFailed"))})},[S,H,t,n]),Fe=i.useCallback(()=>{const pe=v??(F?"draft":null);if(!pe){le.error(n("contextPanel.preview.console.attachNoSession"));return}const Re=[`Preview URL: ${t||H||""}`,`Events: ${S.length}`,""].join(`
|
|
166
|
+
`),ge=S.map(ce=>{const Ce=new Date(ce.ts).toISOString(),be=ce.details?`
|
|
167
|
+
${ce.details}`:"";return`[${Ce}] [${ce.level}] ${ce.message}${be}`}).join(`
|
|
168
|
+
`);I({sessionKey:pe,source:"preview-console",fileLabel:t||H||"preview",startLine:1,endLine:Math.max(1,S.length),code:`${Re}${ge}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),le.success(n("contextPanel.preview.console.attached"))},[I,S,v,H,F,t,n]),[z,K]=i.useState("unknown"),Y=i.useRef(0),me=i.useRef(0),Ne=15e3;i.useEffect(()=>{if(!te){K("unknown"),Y.current=0,me.current=0;return}let pe=!1;return Y.current||(Y.current=Date.now(),me.current=0),K("unknown"),(async()=>{const ge=await(async()=>{try{return await Is(te,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(pe)return;if(!ge){K("unreachable");return}if(ge.status===403||ge.status===404){tr.delete(L),f({status:"loading"}),l();return}if(ge.status!==502){K("reachable");return}const ce=Y.current||Date.now();if(Date.now()-ce<Ne){K("starting"),me.current+=1;const be=me.current,ue=Math.min(2e3,250*Math.pow(2,Math.min(4,be)));setTimeout(()=>{pe||a()},ue).unref?.();return}K("unreachable")})(),()=>{pe=!0}},[L,te,o]);const Be=D&&d.status==="ready"&&(z==="unknown"||z==="starting"),_e=D&&d.status==="ready"&&z==="unreachable",Oe=i.useCallback(pe=>{if(!D||d.status!=="ready"||typeof window>"u")return;const Re=pe.currentTarget.contentWindow;if(Re)try{const ge=Re.location,ce=Ch(te);if(ge.origin!==ce||ge.pathname.startsWith(d.proxyBasePath))return;const Ce=`${d.proxyBasePath}${ge.pathname}${ge.search}${ge.hash}`;Re.location.replace(Ce)}catch{}},[D,te,d]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:J||t,children:J||t||n("contextPanel.preview.empty")}),s.jsx(ze,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>a(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!H,children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{ee&&si(ee)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!ee,children:s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"})}),D?s.jsx(ze,{type:"button",size:"sm",variant:C?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>y(pe=>!pe),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!b,children:s.jsx(A,{name:"cursor",className:"h-3.5 w-3.5"})}):null,D?s.jsxs(ze,{type:"button",size:"sm",variant:g?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>h(pe=>!pe),title:n(b?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(b?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!b&&S.length===0,children:[s.jsx(A,{name:"terminal-box",className:"h-3.5 w-3.5"}),ne>0?s.jsx("span",{className:"typography-micro text-status-error",children:ne}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[Be?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.startingServer")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.startingServerHint")})]}):_e?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(ze,{type:"button",size:"sm",variant:"outline",onClick:()=>a(),children:n("contextPanel.preview.actions.retry")})]}):H&&(!D||z==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:p,src:H,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:M},onLoad:Oe,sandbox:D?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${H}:${o}`),C&&P?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:P.bounds.x,top:P.bounds.y,width:P.bounds.width,height:P.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[P.tag,P.text?` · ${P.text}`:""]})}):null]}):re?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):oe?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),g?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:Fe,disabled:S.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:he,disabled:S.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:()=>N([]),disabled:S.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(pe=>s.jsx(ze,{type:"button",size:"xs",variant:k===pe?"secondary":"ghost",onClick:()=>j(pe),children:n(pe==="all"?"contextPanel.preview.console.filter.all":pe==="errors"?"contextPanel.preview.console.filter.errors":pe==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},pe))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:S.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):ye.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):ye.map(pe=>s.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:Pe("shrink-0 uppercase",pe.level==="error"||pe.level==="runtime"||pe.level==="resource"?"text-status-error":pe.level==="warn"?"text-status-warning":"text-muted-foreground"),children:pe.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:pe.message})]})},pe.id))})]}):null]})]})},a0=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,l0=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=yt(),o=i.useRef(null),a=Ee(z=>z.setContextPanelTabTargetPath),c=Fo(t),l=c!=="about:blank"?c:"",[d,f]=i.useState(l),[m,u]=i.useState(l),[p,x]=i.useState(l),[b,w]=i.useState(()=>l?[l]:[]),[g,h]=i.useState(()=>l?0:-1),[k,j]=i.useReducer(z=>z+1,0),[S,N]=i.useState(!!l),[C,y]=i.useState(!1),[P,_]=i.useState(null),[v,F]=i.useState({status:"idle"}),[I,R]=i.useState(""),B=ht(z=>z.currentSessionId),D=ht(z=>z.newSessionDraft?.open),W=Fc(z=>z.addDraft),U=xi(z=>z.addAttachedFile),L=i.useCallback(z=>{!z||z==="about:blank"||!e||!n||a(e,n,z)},[e,n,a]),M=i.useCallback((z,K)=>{const Y=Fo(z),me=Y!=="about:blank"?Y:"";u(me),f(me),K?.inFrame?N(!1):(x(me),N(!!me)),L(me),w(Ne=>{if(!me)return h(-1),[];if(K?.replaceHistory)return Ne;const Be=g>=0?Ne.slice(0,g+1):[];if(Be[Be.length-1]===me)return h(Be.length-1),Be;const Oe=[...Be,me];return h(Oe.length-1),Oe})},[g,L]),ee=i.useCallback(z=>{const K=b[z];K&&(h(z),u(K),x(K),f(K),N(!0),L(K))},[b,L]),ie=i.useCallback(()=>{if(m){N(!0);try{o.current?.contentWindow?.location.reload()}catch{j()}}},[m]);i.useEffect(()=>{if(!p){F({status:"idle"});return}const z=Pj(p),K=ed(z);if(K?.previewToken){F({status:"ready",proxyBasePath:K.proxyBasePath,previewToken:K.previewToken,expiresAt:K.expiresAt});return}K&&tr.delete(z);let Y=!1;return F({status:"loading"}),N(!0),(async()=>{try{const me=await Is("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:p,allowExternal:!0})});if(!me.ok){const pe=await me.json().catch(()=>({})),Re=typeof pe?.error=="string"?pe.error:`HTTP ${me.status}`;Y||F({status:"error",message:Re});return}const Ne=await me.json(),Be=typeof Ne.proxyBasePath=="string"?Ne.proxyBasePath:"",_e=typeof Ne.previewToken=="string"?Ne.previewToken:"",Oe=typeof Ne.expiresAt=="number"?Ne.expiresAt:0;if(!Be||!_e){Y||F({status:"error",message:r("contextPanel.preview.proxyError")});return}tr.set(z,{proxyBasePath:Be,previewToken:_e,expiresAt:Oe}),Y||F({status:"ready",proxyBasePath:Be,previewToken:_e,expiresAt:Oe})}catch(me){if(!Y){const Ne=me instanceof Error?me.message:String(me);F({status:"error",message:Ne})}}})(),()=>{Y=!0}},[p,r]);const te=p&&v.status==="ready"?`${v.proxyBasePath}|${v.previewToken||""}|${k}`:"";i.useEffect(()=>{if(!te){R("");return}let z=!1;return R(""),jc(Xr()).then(K=>{!z&&K&&R(te)}).catch(()=>{}),()=>{z=!0}},[te]);const H=i.useMemo(()=>{if(I!==te||!p||v.status!=="ready")return"";try{const z=new URL(p),K=z.pathname||"/",Y=new URLSearchParams(z.search);Y.delete("oc_url_token"),Y.delete("oc_client_token"),Y.set("ocPreview",String(k)),Y.set("oc_preview_token",v.previewToken||"");const me=Y.toString();return Li().authenticatedAsset(`${v.proxyBasePath}${K}${me?`?${me}`:""}${z.hash}`)}catch{return""}},[p,v,te,k,I]),J=H||(v.status==="error"?p:""),re=i.useCallback(z=>{if(!z||!p||v.status!=="ready")return"";try{const K=new URL(z,window.location.origin),Y=v.proxyBasePath.endsWith("/")?v.proxyBasePath.slice(0,-1):v.proxyBasePath;if(K.origin!==window.location.origin||!K.pathname.startsWith(Y))return"";const me=K.pathname.slice(Y.length)||"/",Ne=new URL(p).origin;return af(new URL(`${me}${K.search}${K.hash}`,Ne).toString())}catch{return""}},[p,v]),oe=i.useCallback(z=>{if(!z||!p||v.status!=="ready")return"";try{const K=new URL(z,window.location.origin),Y=new URL(p).origin;if(K.origin!==window.location.origin||Y===window.location.origin)return"";const me=v.proxyBasePath.endsWith("/")?v.proxyBasePath.slice(0,-1):v.proxyBasePath;return K.pathname.startsWith(me)?"":af(new URL(`${K.pathname}${K.search}${K.hash}`,Y).toString())}catch{return""}},[p,v]),ve=i.useCallback(z=>{const K=o.current?.contentWindow;K&&K.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:z},window.location.origin)},[]),ne=i.useCallback(async z=>{const K=B??(D?"draft":null);if(!K){le.error(r("contextPanel.preview.inspect.attachNoSession"));return}const Y=o.current,me=Y?.contentWindow,Ne=Y?.getBoundingClientRect(),Be={width:Number.isFinite(me?.innerWidth)?me?.innerWidth??Ne?.width??0:Ne?.width??0,height:Number.isFinite(me?.innerHeight)?me?.innerHeight??Ne?.height??0:Ne?.height??0},_e=Y?await ph(Y,z):null,Oe=!!_e;_e&&await U(_e),W({sessionKey:K,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:Xc({pageUrl:m,viewport:Be,devicePixelRatio:window.devicePixelRatio||1,target:z,screenshotAttached:Oe,intro:r(Oe?"contextPanel.preview.inspect.attachAnnotationWithScreenshot":"contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),le.success(r("contextPanel.preview.inspect.attached"))},[U,W,B,m,D,r]),ye=i.useCallback(()=>{const z=o.current;_(null),ve(!1),z&&rf(z,xa).catch(()=>{})},[ve]);i.useEffect(()=>{if(!C)return;const z=K=>{K.key==="Escape"&&(K.preventDefault(),K.stopImmediatePropagation(),y(!1),ye())};return window.addEventListener("keydown",z,!0),()=>window.removeEventListener("keydown",z,!0)},[ye,C]),i.useEffect(()=>()=>ye(),[ye]),i.useEffect(()=>{const z=K=>{if(K.source!==o.current?.contentWindow)return;const Y=K.data;if(!(!Y||Y.source!=="openchamber-preview-bridge"||Y.version!==1)){if(Y.type==="ready"){const me=typeof Y.url=="string"?Y.url:"",Ne=re(me);Ne&&Ne!==m&&M(Ne,{inFrame:!0});return}if(Y.type==="hover"){_(to(Y.target)?Y.target:null);return}if(Y.type==="select"&&to(Y.target)){_(null),y(!1),ve(!1),ne(Y.target);return}if(Y.type==="navigate-preview"){const me=typeof Y.url=="string"?Y.url:"",Ne=oe(me);if(Ne){M(Ne);return}me&&M(me)}}};return window.addEventListener("message",z),()=>window.removeEventListener("message",z)},[M,ne,m,re,oe,ve]);const he=i.useCallback(()=>{const z=o.current;if(!(!z||!m)){if(C){y(!1),ye();return}if(H){_(null),y(!0),ve(!0);return}y(!0),(async()=>{try{const K=await rf(z,kh);if(y(!1),!K||!to(K))return;await ne(K)}catch{y(!1),le.error(r("contextPanel.browser.inspectUnavailable"))}})()}},[ne,ye,m,C,ve,H,r]),Fe=i.useCallback(()=>{try{const z=o.current?.contentWindow?.location.href||"",K=oe(z);if(K){M(K,{inFrame:!0});return}}catch{}N(!1),C&&H&&ve(!0)},[M,oe,C,ve,H]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:g<=0,onClick:()=>ee(g-1),children:s.jsx(A,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:g<0||g>=b.length-1,onClick:()=>ee(g+1),children:s.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!m,onClick:ie,children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:z=>{z.preventDefault(),M(d)},children:s.jsx("input",{value:d,onChange:z=>f(z.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(ze,{type:"button",variant:C?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!m,onClick:he,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(A,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!m,onClick:()=>{si(m)},children:s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[J?s.jsxs("div",{className:"absolute inset-0",children:[s.jsx("iframe",{ref:o,src:J,title:r("contextPanel.browser.empty"),className:"absolute inset-0 h-full w-full border-0 bg-background",allow:"clipboard-read; clipboard-write; fullscreen",allowFullScreen:!0,onLoad:Fe},`${n}:${k}`),C&&P?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:P.bounds.x,top:P.bounds.y,width:P.bounds.width,height:P.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[P.tag,P.text?` · ${P.text}`:""]})}):null]}):s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(Oc,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")}),s.jsx("span",{className:"max-w-sm typography-micro text-muted-foreground",children:r("contextPanel.browser.emptyHint")}),s.jsx("span",{className:"max-w-md typography-micro leading-relaxed text-status-warning/70",children:r("contextPanel.browser.trustNotice")})]}),S?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},c0=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=yt(),o=i.useRef(null),a=Ee(v=>v.setContextPanelTabTargetPath),c=Fo(t),l=c!=="about:blank"?c:"",d=i.useRef(Fo(t)),[f,m]=i.useState(l),[u,p]=i.useState(l),[x,b]=i.useState(!1),[w,g]=i.useState(!0),h=i.useRef(null),k=w,j=i.useCallback(v=>{!v||v==="about:blank"||!e||!n||a(e,n,v)},[e,n,a]),S=ht(v=>v.currentSessionId),N=ht(v=>v.newSessionDraft?.open),C=Fc(v=>v.addDraft),y=xi(v=>v.addAttachedFile);i.useEffect(()=>{const v=o.current;if(!v)return;const F=()=>{try{const U=v.getURL();U&&U!=="about:blank"&&(p(U),m(U),j(U))}catch{}},I=U=>{const L=U.detail;typeof L?.url=="string"&&L.url&&(p(L.url),m(L.url),j(L.url))},R=()=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>g(!0),200)},B=()=>{h.current&&clearTimeout(h.current),g(!1),F()},D=U=>{const L=U.detail;if(L?.disposition==="new-window"||L?.disposition==="foreground-tab"||L?.disposition==="background-tab"){U.preventDefault();const M=o.current;typeof M?.loadURL=="function"&&L.url&&M.loadURL(L.url)}},W=()=>{try{v.executeJavaScript?.(n0,!0).catch(()=>{})}catch{}};v.addEventListener("did-navigate",I),v.addEventListener("did-navigate-in-page",I),v.addEventListener("did-start-loading",R),v.addEventListener("did-stop-loading",B),v.addEventListener("new-window",D),v.addEventListener("dom-ready",W);try{v.isLoading()||(g(!1),F())}catch{}return W(),()=>{h.current&&clearTimeout(h.current),v.removeEventListener("did-navigate",I),v.removeEventListener("did-navigate-in-page",I),v.removeEventListener("did-start-loading",R),v.removeEventListener("did-stop-loading",B),v.removeEventListener("new-window",D),v.removeEventListener("dom-ready",W)}},[j]),i.useEffect(()=>{const v=setTimeout(()=>g(!1),3e4);return()=>clearTimeout(v)},[]),i.useEffect(()=>{if(!x)return;const v=F=>{if(F.key!=="Escape")return;F.preventDefault(),F.stopImmediatePropagation(),b(!1);const I=o.current;try{I?.executeJavaScript?.(xa).catch(()=>{})}catch{}};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[x]),i.useEffect(()=>{const v=o.current;return()=>{try{const F=v?.getURL?.();F&&F!=="about:blank"&&a(e,n,F)}catch{}try{v?.executeJavaScript?.(xa).catch(()=>{})}catch{}}},[e,n,a]);const P=i.useCallback(v=>{const F=o.current;if(typeof F?.loadURL!="function")return;const I=Fo(v);try{F.loadURL(I)}catch{}},[]),_=i.useCallback(()=>{const v=o.current;if(v){if(x){b(!1);try{v.executeJavaScript?.(xa).catch(()=>{})}catch{}return}b(!0),v.executeJavaScript?.(kh,!0).then(async F=>{if(b(!1),!F||!to(F))return;const I=S??(N?"draft":null);if(!I){le.error(r("contextPanel.preview.inspect.attachNoSession"));return}const R=typeof v.getWebContentsId=="function"?v.getWebContentsId():null;if(R==null)return;const B=await Og("desktop_browser_capture_page",{webContentsId:R}),D=await v.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),W=Number.isFinite(D?.width)?D.width:B.width,U=Number.isFinite(D?.height)?D.height:B.height,L=await Zc(B.base64,B.width,B.height,W,U,F),M=!!L;L&&await y(L),C({sessionKey:I,source:"preview-annotation",fileLabel:u||"browser",startLine:1,endLine:1,code:Xc({pageUrl:u,viewport:{width:W,height:U},devicePixelRatio:window.devicePixelRatio||1,target:F,screenshotAttached:M,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),le.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[y,C,S,u,x,N,r]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goBack?.()}catch{}},children:s.jsx(A,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goForward?.()}catch{}},children:s.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.reload?.()}catch{}},children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:v=>{v.preventDefault(),P(f)},children:s.jsx("input",{value:f,onChange:v=>m(v.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(ze,{type:"button",variant:x?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:_,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(A,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{si(u)},children:s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[s.jsx("webview",{ref:o,src:d.current,partition:"persist:openchamber-browser",allowpopups:!0,style:{width:"100%",height:"100%",border:"none"}}),(!u||u==="about:blank")&&!w?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(Oc,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,k?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},d0=()=>{const{t}=yt(),e=bi()??"",n=i.useMemo(()=>Kj(e),[e]),r=Ee(V=>n?V.contextPanelByDirectory[n]:void 0),o=Ee(V=>V.closeContextPanel),a=Ee(V=>V.closeContextPanelTab),c=Ee(V=>V.openContextPanelTab),l=Ee(V=>V.toggleContextPanelExpanded),d=Ee(V=>V.setContextPanelWidth),f=Ee(V=>V.setActiveContextPanelTab),m=Ee(V=>V.reorderContextPanelTabs),u=cn(V=>V.setSelectedPath),p=Ee(V=>V.openContextPreview),x=Ee(V=>V.allowPromptingSubagentSessions),{themeMode:b,setThemeMode:w,lightThemeId:g,darkThemeId:h,currentTheme:k}=wi(),j=i.useMemo(()=>r?.tabs??[],[r?.tabs]),S=j.find(V=>V.id===r?.activeTabId)??j[j.length-1]??null,N=!!(r?.isOpen&&S),C=!!(N&&r?.expanded),y=Nh(r?.width??Sh),P=i.useMemo(()=>{const V=[];for(const we of j){if(we.mode!=="chat")continue;const E=ga(we.dedupeKey);E&&!V.includes(E)&&V.push(E)}return V},[j]),_=s0(n||void 0,P),[v,F]=i.useState(!1),[I,R]=i.useState(!1),B=i.useRef(0),D=i.useRef(y),W=i.useRef(null),U=i.useRef(null),L=i.useRef(null),M=i.useRef(new Map),ee=i.useRef(new Map),ie=i.useRef(!1),te=i.useRef(N),H=i.useRef(null),J=i.useCallback(()=>{R(!0),H.current!==null&&window.cancelAnimationFrame(H.current),H.current=window.requestAnimationFrame(()=>{H.current=null,R(!1)})},[]);i.useEffect(()=>()=>{H.current!==null&&window.cancelAnimationFrame(H.current)},[]),i.useLayoutEffect(()=>{const V=te.current;if(te.current=N,!N){R(!1);return}V||J()},[N,J]),i.useEffect(()=>{if(!N||ie.current){ie.current=N;return}const V=window.requestAnimationFrame(()=>{L.current?.focus({preventScroll:!0})});return ie.current=!0,()=>window.cancelAnimationFrame(V)},[N]);const re=i.useCallback(V=>{const we=L.current;we&&we.style.setProperty("--oc-context-panel-width",`${Vl(V,we)}px`)},[]),oe=i.useCallback(V=>{if(!(!N||C||!n)){try{V.currentTarget.setPointerCapture(V.pointerId)}catch{}U.current=V.pointerId,F(!0),B.current=V.clientX,D.current=y,W.current=y,re(y),V.preventDefault()}},[re,n,C,N,y]),ve=i.useCallback(V=>{if(!v||U.current!==V.pointerId)return;const we=B.current-V.clientX,E=Vl(D.current+we,L.current);W.current!==E&&(W.current=E,re(E))},[re,v]),ne=i.useCallback(V=>{if(U.current!==V.pointerId||!n)return;try{V.currentTarget.releasePointerCapture(V.pointerId)}catch{}const we=Vl(W.current??y,L.current);J(),re(we),W.current=we,d(n,we),F(!1),U.current=null},[re,n,d,J,y]);i.useEffect(()=>{v||(W.current=null)},[v]);const ye=i.useCallback(()=>{n&&o(n)},[o,n]),he=i.useCallback(()=>{n&&l(n)},[n,l]),Fe=i.useCallback(V=>{V.key==="Escape"&&(V.preventDefault(),V.stopPropagation(),ye())},[ye]);i.useEffect(()=>{if(!(!n||!S)&&S.mode==="file"&&S.targetPath){u(n,S.targetPath,{allowOutsideRoot:!0});return}},[S,n,u]);const z=S?.mode==="chat"?S.id:null,K=S?.mode==="chat"?ga(S.dedupeKey):null;i.useEffect(()=>{if(!N||!n||!K||typeof window>"u")return;const V=()=>{if(document.visibilityState==="hidden"||!document.hasFocus()){pl(n,K,!1);return}xm(K),pl(n,K,!0)};V();const we=window.setInterval(V,1e4);return window.addEventListener("focus",V),window.addEventListener("blur",V),document.addEventListener("visibilitychange",V),()=>{window.clearInterval(we),window.removeEventListener("focus",V),window.removeEventListener("blur",V),document.removeEventListener("visibilitychange",V),pl(n,K,!1)}},[K,n,N]);const Y=i.useCallback((V,we,E)=>Fg(ee.current,V,we,n||null,E,{mode:b,lightThemeId:g,darkThemeId:h,currentTheme:k}),[k,h,n,g,b]);i.useEffect(()=>{const V=new Set(j.map(we=>we.id));for(const we of ee.current.keys())V.has(we)||ee.current.delete(we)},[j]);const me=i.useCallback(V=>{!n||S?.mode!=="diff"||c(n,{mode:"diff",targetPath:S.targetPath,stagedDiff:V==="staged",diffScope:V})},[S,n,c]),Ne=i.useCallback(()=>{if(typeof window>"u")return;const V={themeMode:b,lightThemeId:g,darkThemeId:h,currentTheme:k};for(const we of M.current.values()){const E=we.contentWindow;if(!E)continue;const de=E.__openchamberApplyThemeSync;if(typeof de=="function")try{de(V);continue}catch{}E.postMessage({type:"openchamber:theme-sync",payload:V},window.location.origin)}},[k,h,g,b]),Be=i.useCallback(()=>{if(typeof window>"u")return;const V={allowPromptingSubagentSessions:x};for(const we of M.current.values()){const E=we.contentWindow;if(!E)continue;const de=E.__openchamberApplyChatSettingsSync;if(typeof de=="function")try{de(V);continue}catch{}E.postMessage({type:"openchamber:chat-settings-sync",payload:V},window.location.origin)}},[x]),_e=i.useCallback(()=>{if(!(typeof window>"u"))for(const[V,we]of M.current.entries()){const E=we.contentWindow;if(!E)continue;const de={visible:z===V},fe=E.__openchamberSetEmbeddedVisibility;if(typeof fe=="function")try{fe(de);continue}catch{}E.postMessage({type:"openchamber:embedded-visibility",payload:de},window.location.origin)}},[z]);i.useEffect(()=>{if(typeof window>"u")return;const V=we=>{if(we.origin!==window.location.origin||!Array.from(M.current.values()).some(Ve=>Ve.contentWindow===we.source))return;const de=we.data;if(de?.type==="openchamber:chat-settings-request"){Be();return}if(de?.type!=="openchamber:cycle-theme-request")return;const fe=["light","dark","system"],ke=(fe.indexOf(b)+1)%fe.length;w(fe[ke])};return window.addEventListener("message",V),()=>window.removeEventListener("message",V)},[Be,w,b]),i.useLayoutEffect(()=>{j.some(we=>we.mode==="chat")&&(Ne(),Be(),_e())},[h,g,Be,_e,Ne,j,b]);const Oe=i.useMemo(()=>j.map(V=>{const we=Xj(V,_,t),E=r0(we,Hj),de=Yj(V.targetPath,e);return{id:V.id,label:E,icon:Zj(V),title:de?`${we}: ${de}`:we,closeLabel:t("contextPanel.tab.closeTabAria",{label:E})}}),[e,_,t,j]),pe=S?.mode==="context"?s.jsx(xj,{}):S?.mode==="plan"?s.jsx(hh,{targetPath:S.targetPath}):S?.mode==="preview"?s.jsx(o0,{rawUrl:S.targetPath??"",onNavigate:V=>p(e,V)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(A,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),Re=i.useMemo(()=>j.filter(V=>V.mode==="chat"),[j]),ge=i.useMemo(()=>j.filter(V=>V.mode==="browser"),[j]),ce=i.useMemo(()=>j.filter(V=>V.mode==="diff"),[j]),Ce=a0()?c0:l0,be=i.useMemo(()=>j.some(V=>V.mode==="file"),[j]),ue=S?.mode==="file",De=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-transparent",children:[s.jsx(Vo,{items:Oe,activeId:S?.id??null,onSelect:V=>{n&&f(n,V)},onClose:V=>{n&&a(n,V)},onReorder:(V,we)=>{n&&m(n,V,we)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:he,className:"h-7 w-7 p-0",title:t(C?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(C?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:C?s.jsx(A,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:ye,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),T=N?C?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",minWidth:`min(${jh}px, 100%)`,maxWidth:"100%","--oc-context-panel-width":`${v?W.current??y:y}px`}:{"--oc-context-panel-width":`${v?W.current??y:y}px`,width:0,minWidth:0,maxWidth:0,opacity:0,overflow:"hidden",visibility:"hidden"};return s.jsxs("aside",{ref:L,"data-context-panel":"true",tabIndex:-1,inert:!N||void 0,className:Pe("flex min-h-0 flex-col overflow-hidden bg-background",!C&&"border-l border-border/40",C?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",!N&&"pointer-events-none",v||!N||I?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:Fe,style:T,children:[!C&&s.jsx("div",{className:Pe("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",v&&"bg-[var(--interactive-border)]"),onPointerDown:oe,onPointerMove:ve,onPointerUp:ne,onPointerCancel:ne,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),De,s.jsxs("div",{className:Pe("relative min-h-0 flex-1 overflow-hidden",v&&"pointer-events-none"),children:[be?s.jsx("div",{className:Pe("absolute inset-0",ue?"block":"hidden"),children:s.jsx(mh,{mode:"editor-only"})}):null,Re.map(V=>{const we=ga(V.dedupeKey);if(!we)return null;const E=Y(V.id,we,V.readOnly);return E?s.jsx("iframe",{ref:de=>{if(!de){M.current.delete(V.id);return}M.current.set(V.id,de)},src:E,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:we}),className:Pe("absolute inset-0 h-full w-full border-0 bg-background",z===V.id?"block":"hidden"),onLoad:()=>{Ne(),Be(),_e()}},V.id):null}),ge.map(V=>s.jsx("div",{className:Pe("absolute inset-0",S?.id!==V.id&&"hidden"),children:s.jsx(Ce,{initialUrl:V.targetPath??"",directory:n,tabID:V.id})},V.id)),ce.map(V=>s.jsx("div",{className:Pe("absolute inset-0",S?.id!==V.id&&"hidden"),children:s.jsx(ch,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:V.diffScope??(V.stagedDiff?"staged":"working"),onDiffScopeChange:me,targetFilePath:V.targetPath,flushContent:!0})},V.id)),S?.mode!=="chat"&&!ue&&S?.mode!=="browser"&&S?.mode!=="diff"?pe:null]})]})},u0=(t,e)=>!t||e.length===0?"":JSON.stringify([t,e]),f0=(t,e,n,r)=>!n||r!==n||t.length===0?[]:Co(t,e,o=>o.name,{limit:10,threshold:.4}),uc=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},m0=()=>{const t=gt.c(172),{t:e}=yt(),n=Ee(h0),r=Ee(p0),o=Ee(g0),a=Ee(x0),c=Ee(b0),l=Ee(w0),d=Ee(y0),f=Ee(v0),m=Ee(j0),u=Ee(S0),p=Ee(N0),x=Ee(k0),b=ht(C0),w=ht(A0),g=kr(D0),h=Js(T0),k=Ds(P0),j=Ds(I0),S=bi(),N=vc(R0),{files:C,git:y}=nr(),P=yn(E0),{isMobile:_}=zr();let v;t[0]!==S?(v=S?uc(S):null,t[0]=S,t[1]=v):v=t[1];const F=v,[I,R]=i.useState(""),D=Za(I,200).trim();let W;t[2]!==I?(W=I.trim(),t[2]=I,t[3]=W):W=t[3];const U=W;let L,M;t[4]!==n?(L=()=>{n&&R("")},M=[n],t[4]=n,t[5]=L,t[6]=M):(L=t[5],M=t[6]),i.useEffect(L,M);let ee,ie;t[7]!==g||t[8]!==P||t[9]!==y||t[10]!==n?(ee=()=>{if(!n||!y)return;const qe=setTimeout(()=>{const et=new Set;for(const Vt of g){const Ct=ti(Vt);!Ct||et.has(Ct)||(et.add(Ct),P(Ct,y))}},0);return()=>clearTimeout(qe)},ie=[n,g,y,P],t[7]=g,t[8]=P,t[9]=y,t[10]=n,t[11]=ee,t[12]=ie):(ee=t[11],ie=t[12]),i.useEffect(ee,ie);let te;t[13]!==r?(te=()=>r(!1),t[13]=r,t[14]=te):te=t[14];const H=te;let J;t[15]!==H?(J=qe=>()=>{H(),qe()},t[15]=H,t[16]=J):J=t[16];const re=J;let oe;t[17]!==k?.id||t[18]!==k?.path||t[19]!==h||t[20]!==_||t[21]!==u||t[22]!==b||t[23]!==re||t[24]!==o||t[25]!==l||t[26]!==a||t[27]!==e||t[28]!==m||t[29]!==f||t[30]!==d?(oe=()=>{const qe=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(A,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:re(()=>{o("chat"),l(!1),b()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(A,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:re(M0)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(A,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:re(F0)},{id:"toggle-sidebar",title:e(_?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(A,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(_?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:re(()=>{if(_){const{isSessionSwitcherOpen:et}=Ee.getState();l(!et)}else d()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(A,{name:"layout-right",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:re(()=>f())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(A,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:re(()=>m())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(A,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:re(()=>{h&&u(h)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(A,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:re(()=>a(!0))}];return Wa()&&qe.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(A,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:re(()=>{Zr("desktop_open_draft_mini_chat_window",{directory:uc(h||k?.path||""),projectId:k?.id??null}).catch(O0)})}),qe},t[17]=k?.id,t[18]=k?.path,t[19]=h,t[20]=_,t[21]=u,t[22]=b,t[23]=re,t[24]=o,t[25]=l,t[26]=a,t[27]=e,t[28]=m,t[29]=f,t[30]=d,t[31]=oe):oe=t[31],k?.id,k?.path;let ve;t[32]!==oe?(ve=oe(),t[32]=oe,t[33]=ve):ve=t[33];const ne=ve;let ye;t[34]===Symbol.for("react.memo_cache_sentinel")?(ye=pr(),t[34]=ye):ye=t[34];const he=ye;let Fe,z;t[35]===Symbol.for("react.memo_cache_sentinel")?(Fe=Cr(),z=!he&&Sc(),t[35]=Fe,t[36]=z):(Fe=t[35],z=t[36]);let K;t[37]!==_?(K={isVSCode:Fe,isWeb:z,isDesktop:he,isMobile:_},t[37]=_,t[38]=K):K=t[38];const Y=K;let me;if(t[39]!==re||t[40]!==a||t[41]!==c||t[42]!==Y){let qe;t[44]!==Y?(qe=Vt=>Vt.isAvailable?Vt.isAvailable(Y):!0,t[44]=Y,t[45]=qe):qe=t[45];let et;t[46]!==re||t[47]!==a||t[48]!==c?(et=Vt=>{const Ct=lb(Vt.slug)??"settings-3",Ht=(Vt.keywords??[]).join(" ");return{id:`settings:${Vt.slug}`,title:Vt.title,icon:Vt.slug==="mcp"?s.jsx(Xl,{className:"mr-2 h-4 w-4"}):s.jsx(A,{name:Ct,className:"mr-2 h-4 w-4"}),searchText:`${Vt.title} ${Vt.group} ${Ht}`,onSelect:re(()=>{c(Vt.slug),a(!0)})}},t[46]=re,t[47]=a,t[48]=c,t[49]=et):et=t[49],me=ab.filter(L0).filter(qe).map(et),t[39]=re,t[40]=a,t[41]=c,t[42]=Y,t[43]=me}else me=t[43];const Ne=me,Be=B0;let _e;if(t[50]!==g){let qe;t[52]===Symbol.for("react.memo_cache_sentinel")?(qe=(et,Vt)=>Be(Vt)-Be(et),t[52]=qe):qe=t[52],_e=[...g].sort(qe),t[50]=g,t[51]=_e}else _e=t[51];const Oe=_e,pe=bm(),Re=ht(V0);let ge;t[53]!==pe||t[54]!==Re?(ge=(qe,et)=>{const Vt=Re.get(qe);return Vt?.branch?Vt.branch.trim()||null:et&&pe.get(et)?.trim()||null},t[53]=pe,t[54]=Re,t[55]=ge):ge=t[55];const ce=ge;let Ce;t[56]===Symbol.for("react.memo_cache_sentinel")?(Ce=[],t[56]=Ce):Ce=t[56];const[be,ue]=i.useState(Ce),[De,T]=i.useState(""),V=u0(F,D);let we;t[57]!==F||t[58]!==V||t[59]!==n||t[60]!==N||t[61]!==ue||t[62]!==T||t[63]!==D?(we=()=>{if(!n){ue([]),T("");return}if(!V){ue([]),T("");return}if(!F){ue([]),T("");return}let qe=!1;return N(F,D,10,{type:"file"}).then(et=>{qe||(ue(et.map(_0)),T(V))}).catch(()=>{qe||(ue([]),T(V))}),()=>{qe=!0}},t[57]=F,t[58]=V,t[59]=n,t[60]=N,t[61]=ue,t[62]=T,t[63]=D,t[64]=we):we=t[64];let E;t[65]!==F||t[66]!==V||t[67]!==n||t[68]!==N||t[69]!==D?(E=[n,F,D,V,N],t[65]=F,t[66]=V,t[67]=n,t[68]=N,t[69]=D,t[70]=E):E=t[70],i.useEffect(we,E);const de=U.length>0;let fe;e:{if(!de){let et;t[71]!==ne?(et=ne.map($0),t[71]=ne,t[72]=et):et=t[72],fe=et;break e}let qe;t[73]!==ne||t[74]!==U?(qe=Co(ne,U,z0,{limit:7,noFuzzy:!0}),t[73]=ne,t[74]=U,t[75]=qe):qe=t[75],fe=qe}const $=fe;let ke;e:{if(!de){let et;t[76]===Symbol.for("react.memo_cache_sentinel")?(et=[],t[76]=et):et=t[76],ke=et;break e}let qe;t[77]!==U||t[78]!==Ne?(qe=Co(Ne,U,W0,{limit:7,noFuzzy:!0}),t[77]=U,t[78]=Ne,t[79]=qe):qe=t[79],ke=qe}const Ve=ke;let Se;e:{if(!de){let et;t[80]!==Oe?(et=Oe.slice(0,5).map(U0),t[80]=Oe,t[81]=et):et=t[81],Se=et;break e}let qe;t[82]!==U||t[83]!==Oe?(qe=Co(Oe,U,H0,{limit:7,threshold:.2}),t[82]=U,t[83]=Oe,t[84]=qe):qe=t[84],Se=qe}const q=Se;let O;e:{if(!n){let et;t[85]===Symbol.for("react.memo_cache_sentinel")?(et=[],t[85]=et):et=t[85],O=et;break e}let qe;t[86]!==be||t[87]!==De||t[88]!==V||t[89]!==D?(qe=f0(be,D,V,De),t[86]=be,t[87]=De,t[88]=V,t[89]=D,t[90]=qe):qe=t[90],O=qe}const se=O,Le=n&&V.length>0&&De!==V;let ae;e:{if(!de){let et;t[91]===Symbol.for("react.memo_cache_sentinel")?(et=[],t[91]=et):et=t[91],ae=et;break e}let qe;if(t[92]!==U||t[93]!==j){const et=j.map(G0);qe=Co(et,U,K0,{limit:7,threshold:.4}),t[92]=U,t[93]=j,t[94]=qe}else qe=t[94];ae=qe}const We=ae;let Ye,Qe,st,pt,jt,Et,Rt,Ut,ts,Kt,is,qt,Te,Ke;if(t[95]!==ce||t[96]!==H||t[97]!==F||t[98]!==C||t[99]!==de||t[100]!==n||t[101]!==p||t[102]!==b||t[103]!==I||t[104]!==$||t[105]!==se||t[106]!==We||t[107]!==q||t[108]!==Ve||t[109]!==r||t[110]!==w||t[111]!==x||t[112]!==e){const qe=$.map(q0),et=Ve.map(Y0),Vt=q.map(Q0),Ct=de?se.map(J0):[],Ht=de?We.map(X0):[];let ss;e:{if(!de){ss=["commands","sessions"];break e}const Gt=Z0,Me=[{key:"commands",score:Gt($)},{key:"settings",score:Gt(Ve)},{key:"sessions",score:Gt(q)},{key:"files",score:Gt(se)},{key:"projects",score:Gt(We)}];Me.sort(eS),ss=Me.map(tS)}const Xt=ss,Ft=Gt=>{H(),w(Gt.id,ti(Gt))},_t=async Gt=>{if(!F)return;const Me=await Yc(C,Gt);if(!Me.ok){le.error(Qc(Me.reason));return}p(F,Gt),H()},hs=(Gt,Me)=>{H(),b({selectedProjectId:Gt,directoryOverride:Me})},Zt=Gt=>Ua(pi(Gt,x));pt=_s,qt=n,Te=r;let ns;t[127]!==e?(ns=e("commandPalette.title"),t[127]=e,t[128]=ns):ns=t[128];let gs;t[129]!==ns?(gs=s.jsx(Gs,{children:ns}),t[129]=ns,t[130]=gs):gs=t[130];let Mt;t[131]!==e?(Mt=e("commandPalette.description"),t[131]=e,t[132]=Mt):Mt=t[132];let Bt;t[133]!==Mt?(Bt=s.jsx(dn,{children:Mt}),t[133]=Mt,t[134]=Bt):Bt=t[134],t[135]!==gs||t[136]!==Bt?(Ke=s.jsxs(tn,{className:"sr-only",children:[gs,Bt]}),t[135]=gs,t[136]=Bt,t[137]=Ke):Ke=t[137],st=Vs,Kt="overflow-hidden p-0",is=!0,Qe=Ha,Rt=!1,Ut="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let $t;t[138]!==e?($t=e("commandPalette.input.placeholder"),t[138]=e,t[139]=$t):$t=t[139],t[140]!==I||t[141]!==$t?(ts=s.jsx(Ga,{value:I,onValueChange:R,placeholder:$t}),t[140]=I,t[141]=$t,t[142]=ts):ts=t[142],Ye=Ka;let os;t[143]!==e?(os=e("commandPalette.empty.noResults"),t[143]=e,t[144]=os):os=t[144],t[145]!==os?(jt=s.jsx(qa,{children:os}),t[145]=os,t[146]=jt):jt=t[146],Et=Xt.map(Gt=>Gt==="commands"&&qe.length>0?s.jsx(Qr,{children:qe.map(Me=>s.jsxs(Jr,{value:Me.id,onSelect:Me.onSelect,children:[Me.icon,s.jsx("span",{children:Me.title}),Me.shortcutId?s.jsx(Lg,{children:Zt(Me.shortcutId)}):null]},Me.id))},"commands"):Gt==="settings"&&et.length>0?s.jsx(Qr,{children:et.map(sS)},"settings"):Gt==="sessions"&&Vt.length>0?s.jsx(Qr,{children:Vt.map(Me=>{const ft=Me.title||e("commandPalette.session.untitled"),at=ti(Me),Nt=ce(Me.id,at);return s.jsxs(Jr,{value:`session:${Me.id}`,onSelect:()=>Ft(Me),children:[s.jsx(A,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:ft}),Nt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:Nt})]}):null]},Me.id)})},"sessions"):Gt==="files"&&Ct.length>0?s.jsx(Qr,{children:Ct.map(Me=>{const ft=Bg(Me.relativePath||Me.name,{maxLength:80});return s.jsxs(Jr,{value:`file:${Me.path}`,onSelect:()=>{_t(Me.path)},children:[s.jsx(ei,{filePath:Me.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Me.relativePath,children:ft})]},`file:${Me.path}`)})},"files"):Gt==="projects"&&Ht.length>0?s.jsx(Qr,{children:Ht.map(Me=>{const ft=Me.displayName;return s.jsxs(Jr,{value:`project:${Me.id}`,onSelect:()=>hs(Me.id,Me.path),children:[s.jsx(A,{name:"folder",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:ft}),s.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:Me.path})]},`project:${Me.id}`)})},"projects"):null),t[95]=ce,t[96]=H,t[97]=F,t[98]=C,t[99]=de,t[100]=n,t[101]=p,t[102]=b,t[103]=I,t[104]=$,t[105]=se,t[106]=We,t[107]=q,t[108]=Ve,t[109]=r,t[110]=w,t[111]=x,t[112]=e,t[113]=Ye,t[114]=Qe,t[115]=st,t[116]=pt,t[117]=jt,t[118]=Et,t[119]=Rt,t[120]=Ut,t[121]=ts,t[122]=Kt,t[123]=is,t[124]=qt,t[125]=Te,t[126]=Ke}else Ye=t[113],Qe=t[114],st=t[115],pt=t[116],jt=t[117],Et=t[118],Rt=t[119],Ut=t[120],ts=t[121],Kt=t[122],is=t[123],qt=t[124],Te=t[125],Ke=t[126];let rt;t[147]!==Le||t[148]!==e?(rt=Le?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[147]=Le,t[148]=e,t[149]=rt):rt=t[149];let vt;t[150]!==Ye||t[151]!==jt||t[152]!==Et||t[153]!==rt?(vt=s.jsxs(Ye,{children:[jt,Et,rt]}),t[150]=Ye,t[151]=jt,t[152]=Et,t[153]=rt,t[154]=vt):vt=t[154];let Je;t[155]!==Qe||t[156]!==Rt||t[157]!==Ut||t[158]!==ts||t[159]!==vt?(Je=s.jsxs(Qe,{shouldFilter:Rt,className:Ut,children:[ts,vt]}),t[155]=Qe,t[156]=Rt,t[157]=Ut,t[158]=ts,t[159]=vt,t[160]=Je):Je=t[160];let St;t[161]!==st||t[162]!==Kt||t[163]!==is||t[164]!==Je?(St=s.jsx(st,{className:Kt,showCloseButton:is,children:Je}),t[161]=st,t[162]=Kt,t[163]=is,t[164]=Je,t[165]=St):St=t[165];let Xe;return t[166]!==pt||t[167]!==qt||t[168]!==Te||t[169]!==Ke||t[170]!==St?(Xe=s.jsxs(pt,{open:qt,onOpenChange:Te,children:[Ke,St]}),t[166]=pt,t[167]=qt,t[168]=Te,t[169]=Ke,t[170]=St,t[171]=Xe):Xe=t[171],Xe};function h0(t){return t.isCommandPaletteOpen}function p0(t){return t.setCommandPaletteOpen}function g0(t){return t.setActiveMainTab}function x0(t){return t.setSettingsDialogOpen}function b0(t){return t.setSettingsPage}function w0(t){return t.setSessionSwitcherOpen}function y0(t){return t.toggleSidebar}function v0(t){return t.toggleRightSidebar}function j0(t){return t.toggleBottomTerminal}function S0(t){return t.openContextOverview}function N0(t){return t.openContextFile}function k0(t){return t.shortcutOverrides}function C0(t){return t.openNewSessionDraft}function A0(t){return t.setCurrentSession}function D0(t){return t.activeSessions}function T0(t){return t.currentDirectory}function P0(t){return t.getActiveProject()}function I0(t){return t.projects}function R0(t){return t.searchFiles}function E0(t){return t.ensureStatus}function M0(){wm()}function F0(){_r.requestDirectoryDialog()}function O0(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function L0(t){return t.slug!=="home"}function B0(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function V0(t){return t.worktreeMetadata}function _0(t){return{path:uc(t.path),name:t.name,relativePath:t.relativePath}}function $0(t){return{item:t,score:0}}function z0(t){return t.searchText}function W0(t){return t.searchText}function U0(t){return{item:t,score:0}}function H0(t){return t.title||""}function G0(t){return{...t,displayName:t.label||t.path.split("/").pop()||t.path,searchText:`${t.label||""} ${t.path}`}}function K0(t){return t.searchText}function q0(t){return t.item}function Y0(t){return t.item}function Q0(t){return t.item}function J0(t){return t.item}function X0(t){return t.item}function Z0(t){return t.length?t[0].score:1/0}function eS(t,e){return t.score-e.score}function tS(t){return t.key}function sS(t){return s.jsxs(Jr,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const lf=(t,e,n)=>_g(t)?Ua(pi(t,n)):e,nS=()=>{const t=gt.c(69),{t:e}=yt(),n=Ee(rS),r=Ee(iS),o=Ee(oS);let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=Vg(),t[0]=a):a=t[0];const c=a;let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=Cr(),t[1]=l):l=t[1];const d=l;let f,m,u,p,x,b,w,g,h;if(t[2]!==n||t[3]!==r||t[4]!==o||t[5]!==e){const U=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${c} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"toggle_prompt_navigator",descriptionKey:"helpDialog.item.togglePromptNavigator",icon:"list-unordered",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${c} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];m=_s,g=n,h=r,f=Vs,b="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let L;t[15]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(A,{name:"settings-3",className:"h-5 w-5"}),t[15]=L):L=t[15];let M;t[16]!==e?(M=e("helpDialog.title"),t[16]=e,t[17]=M):M=t[17];let ee;t[18]!==M?(ee=s.jsxs(Gs,{className:"flex items-center gap-2",children:[L,M]}),t[18]=M,t[19]=ee):ee=t[19];let ie;t[20]!==e?(ie=e("helpDialog.description"),t[20]=e,t[21]=ie):ie=t[21];let te;t[22]!==ie?(te=s.jsx(dn,{children:ie}),t[22]=ie,t[23]=te):te=t[23],t[24]!==ee||t[25]!==te?(w=s.jsxs(tn,{children:[ee,te]}),t[24]=ee,t[25]=te,t[26]=w):w=t[26],x="flex-1 overflow-y-auto mt-3 pr-1",u="space-y-4",p=U.map(H=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(H.categoryKey)}),s.jsx("div",{className:"space-y-1",children:H.items.filter(J=>!(d&&J.id==="toggle_prompt_navigator")).map(J=>{const re=J.id?lf(J.id,Array.isArray(J.keys)?J.keys[0]:J.keys,o):Array.isArray(J.keys)?J.keys:J.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[J.icon&&s.jsx(A,{name:J.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(J.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(re)?re:[re]).map((oe,ve)=>s.jsxs(i.Fragment,{children:[ve>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:oe})]},`${oe}-${ve}`))})]},J.id||J.descriptionKey)})})]},H.categoryKey)),t[2]=n,t[3]=r,t[4]=o,t[5]=e,t[6]=f,t[7]=m,t[8]=u,t[9]=p,t[10]=x,t[11]=b,t[12]=w,t[13]=g,t[14]=h}else f=t[6],m=t[7],u=t[8],p=t[9],x=t[10],b=t[11],w=t[12],g=t[13],h=t[14];let k;t[27]!==u||t[28]!==p?(k=s.jsx("div",{className:u,children:p}),t[27]=u,t[28]=p,t[29]=k):k=t[29];let j;t[30]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(A,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[30]=j):j=t[30];let S;t[31]!==e?(S=e("helpDialog.proTips.title"),t[31]=e,t[32]=S):S=t[32];let N;t[33]!==S?(N=s.jsx("p",{className:"font-medium mb-1",children:S}),t[33]=S,t[34]=N):N=t[34];let C;t[35]!==o||t[36]!==e?(C=e("helpDialog.proTips.commandPalette",{shortcut:lf("open_command_palette",`${c} P`,o)}),t[35]=o,t[36]=e,t[37]=C):C=t[37];let y;t[38]!==C?(y=s.jsxs("li",{children:["• ",C]}),t[38]=C,t[39]=y):y=t[39];let P;t[40]!==e?(P=e("helpDialog.proTips.recentSessions"),t[40]=e,t[41]=P):P=t[41];let _;t[42]!==P?(_=s.jsxs("li",{children:["• ",P]}),t[42]=P,t[43]=_):_=t[43];let v;t[44]!==e?(v=e("helpDialog.proTips.themeCycling"),t[44]=e,t[45]=v):v=t[45];let F;t[46]!==v?(F=s.jsxs("li",{children:["• ",v]}),t[46]=v,t[47]=F):F=t[47];let I;t[48]!==y||t[49]!==_||t[50]!==F?(I=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[y,_,F]}),t[48]=y,t[49]=_,t[50]=F,t[51]=I):I=t[51];let R;t[52]!==N||t[53]!==I?(R=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[j,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[N,I]})]})}),t[52]=N,t[53]=I,t[54]=R):R=t[54];let B;t[55]!==R||t[56]!==x||t[57]!==k?(B=s.jsxs("div",{className:x,children:[k,R]}),t[55]=R,t[56]=x,t[57]=k,t[58]=B):B=t[58];let D;t[59]!==f||t[60]!==B||t[61]!==b||t[62]!==w?(D=s.jsxs(f,{className:b,children:[w,B]}),t[59]=f,t[60]=B,t[61]=b,t[62]=w,t[63]=D):D=t[63];let W;return t[64]!==m||t[65]!==D||t[66]!==g||t[67]!==h?(W=s.jsx(m,{open:g,onOpenChange:h,children:D}),t[64]=m,t[65]=D,t[66]=g,t[67]=h,t[68]=W):W=t[68],W};function rS(t){return t.isHelpDialogOpen}function iS(t){return t.setHelpDialogOpen}function oS(t){return t.shortcutOverrides}const aS=()=>{const t=gt.c(32),{t:e}=yt(),n=Ee(lS),r=Ee(cS),o=Ee(dS);let a;t[0]!==o||t[1]!==e?(a=async()=>{if(!o)return;if((await gr(o)).ok){le.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}le.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=o,t[1]=e,t[2]=a):a=t[2];const c=a;let l;t[3]!==e?(l=e("openCodeStatusDialog.title"),t[3]=e,t[4]=l):l=t[4];let d;t[5]!==l?(d=s.jsx(Gs,{children:l}),t[5]=l,t[6]=d):d=t[6];let f;t[7]!==e?(f=e("openCodeStatusDialog.description"),t[7]=e,t[8]=f):f=t[8];let m;t[9]!==f?(m=s.jsx(dn,{children:f}),t[9]=f,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(tn,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=u):u=t[13];let p;t[14]!==e?(p=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=p):p=t[15];let x;t[16]!==c||t[17]!==p?(x=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:c,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:p})}),t[16]=c,t[17]=p,t[18]=x):x=t[18];let b;t[19]!==o||t[20]!==e?(b=o||e("openCodeStatusDialog.empty.noData"),t[19]=o,t[20]=e,t[21]=b):b=t[21];let w;t[22]!==b?(w=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:b}),t[22]=b,t[23]=w):w=t[23];let g;t[24]!==u||t[25]!==x||t[26]!==w?(g=s.jsxs(Vs,{className:"max-w-2xl",children:[u,x,w]}),t[24]=u,t[25]=x,t[26]=w,t[27]=g):g=t[27];let h;return t[28]!==n||t[29]!==r||t[30]!==g?(h=s.jsx(_s,{open:n,onOpenChange:r,children:g}),t[28]=n,t[29]=r,t[30]=g,t[31]=h):h=t[31],h};function lS(t){return t.isOpenCodeStatusDialogOpen}function cS(t){return t.setOpenCodeStatusDialogOpen}function dS(t){return t.openCodeStatusText}const uS=180,cf=600,fS=1,mS=6,hS=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const o=i.useRef(new Map),a=i.useRef([]),c=i.useRef(new Set),l=i.useMemo(()=>Cr(),[]),d=i.useCallback(()=>{if(!(l||typeof window>"u"))for(;c.current.size<fS&&a.current.length>0;){const m=a.current.shift();if(!m)break;ht.getState().currentSessionId!==m&&(Wd(m).renderable||(c.current.add(m),r(m).catch(()=>{}).finally(()=>{c.current.delete(m),d()})))}},[r,l]),f=i.useCallback(m=>{if(l||!m||m===t||typeof window>"u"||Wd(m).renderable||c.current.has(m)||a.current.includes(m))return;a.current.length>=mS&&a.current.shift();const u=o.current.get(m);u!==void 0&&window.clearTimeout(u);const p=window.setTimeout(()=>{o.current.delete(m),a.current.push(m),d()},uS);o.current.set(m,p)},[t,l,d]);i.useEffect(()=>{if(l||!t||e.length===0)return;const m=window.setTimeout(()=>{const u=e.findIndex(p=>p.id===t);u<0||(f(e[u-1]?.id),f(e[u+1]?.id))},cf);return()=>window.clearTimeout(m)},[t,l,f,e]),i.useEffect(()=>{if(l||!t||n.length===0)return;const m=window.setTimeout(()=>{const u=n.indexOf(t);u<0||(f(n[u-1]),f(n[u+1]))},cf);return()=>window.clearTimeout(m)},[t,l,n,f]),i.useEffect(()=>{const m=o.current;return()=>{m.forEach(u=>{clearTimeout(u)}),m.clear(),a.current=[]}},[])};let no=null,ro=null,ba=null,_o=0,Va=null;const _i=new Set,pS=3e4,gS=45e3,Ah=()=>{ba&&(clearTimeout(ba),ba=null)},Dh=()=>{if(ro||_i.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(_o,5)),pS);ro=setTimeout(()=>{ro=null,_o+=1,td()},t)},$o=()=>{Ah(),no&&no.close(),no=null},df=()=>{Ah(),_i.size!==0&&(ba=setTimeout(()=>{$o(),Dh()},gS))},xS=t=>{if(!t||t.trim().length===0)return null;try{const e=JSON.parse(t),n=typeof e?.type=="string"?e.type:"",r=e?.properties;return n?{type:n,properties:r}:null}catch{return null}},bS=t=>{if(t.type==="openchamber:event-stream-ready"){_o=0;return}if(t.type==="openchamber:heartbeat"||t.type!=="openchamber:scheduled-task-ran")return;const e=t.properties&&typeof t.properties=="object"?t.properties:null,n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",o=typeof e?.ranAt=="number"?e.ranAt:Date.now(),a=e?.status,c=a==="running"||a==="error"?a:"success";if(!n||!r)return;const l={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:o,status:c,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of _i)d(l)},td=()=>{if(typeof window>"u"||_i.size===0||typeof EventSource!="function"||no&&no.readyState!==EventSource.CLOSED)return;$o();const t=new EventSource(Li().sse("/api/openchamber/events"));t.onopen=()=>{df()},t.onmessage=e=>{df();const n=xS(e.data);n&&bS(n)},t.onerror=()=>{$o(),Dh()},no=t},wS=()=>{Va||typeof window>"u"||(Va=em(()=>{$o(),_o=0,td()}))},yS=()=>{Va?.(),Va=null},Th=t=>(_i.add(t),wS(),td(),()=>{_i.delete(t),_i.size===0&&(ro&&(clearTimeout(ro),ro=null),_o=0,$o(),yS())}),tl=async(t,e)=>{try{const n=await t.json();if(n&&typeof n.error=="string"&&n.error.trim().length>0)return n.error}catch{return e}return e},uo=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},vS=async t=>{const e=uo(t),n=await Is(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await tl(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},uf=async(t,e)=>{const n=uo(t),r=await Is(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks`,{method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({task:e})});if(!r.ok)throw new Error(await tl(r,"Failed to save scheduled task"));const o=await r.json().catch(()=>null);return!o||!Array.isArray(o.tasks)?[]:o.tasks},jS=async(t,e)=>{const n=uo(t),r=uo(e),o=await Is(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await tl(o,"Failed to delete scheduled task"));const a=await o.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},SS=async(t,e)=>{const n=uo(t),r=uo(e),o=await Is(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await tl(o,"Failed to run scheduled task"));const a=await o.json().catch(()=>null);return{sessionId:typeof a?.sessionId=="string"&&a.sessionId.length>0?a.sessionId:void 0}};function Ph(t){if(!t||!t.trim())return{valid:!1,error:"required"};try{return Kf.CronExpressionParser.parse(t),{valid:!0}}catch(e){return{valid:!1,error:e instanceof Error?e.message:"Invalid cron expression"}}}function NS(t,e,n=4){try{const r=e?{tz:e,currentDate:new Date}:{currentDate:new Date},o=Kf.CronExpressionParser.parse(t,r),a=[];for(let c=0;c<n;c+=1){const l=o.next();l&&a.push(l.toDate())}return a}catch{return[]}}const kS=[{expression:"*/5 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.every5min"},{expression:"0 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.everyHour"},{expression:"0 9 * * 1",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.monday9am"},{expression:"0 9,17 * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.9am5pm"},{expression:"0 0 1 * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.firstOfMonth"}],Ih=[0,1,2,3,4,5,6],fc=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?Intl.supportedValuesOf("timeZone"):["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],ff=()=>{const t=new Date,e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},wa=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),o=Number(e[3]),a=new Date(n,r-1,o);return Number.isNaN(a.getTime())||a.getFullYear()!==n||a.getMonth()!==r-1||a.getDate()!==o?null:a},mf=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},CS=(t,e,n)=>{const r=wa(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},hf=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),AS=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),c=(new Date(n,r,1).getDay()-e+7)%7,l=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),f=[];for(let m=0;m<42;m+=1){const u=m-c+1;if(u<=0){const p=d+u;f.push({date:new Date(n,r-1,p),inCurrentMonth:!1});continue}if(u>l){f.push({date:new Date(n,r+1,u-l),inCurrentMonth:!1});continue}f.push({date:new Date(n,r,u),inCurrentMonth:!0})}return f},DS=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],o=n>=12?"PM":"AM",a=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(a).padStart(2,"0"),minute:r,meridiem:o}},Ii=(t,e,n)=>{const r=Number(t),o=Number(e),a=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,c=Number.isFinite(o)?Math.min(59,Math.max(0,o)):0;let l=a%12;return n==="PM"&&(l+=12),`${String(l).padStart(2,"0")}:${String(c).padStart(2,"0")}`},xo=(t,e)=>{const{max:n,min:r=0,loop:o=!1}=e;let a=Number.parseInt(t,10);return Number.isFinite(a)?(o?(a>n&&(a=r),a<r&&(a=n)):(a>n&&(a=n),a<r&&(a=r)),String(a).padStart(2,"0")):"00"},pf=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:xo(t,{min:1,max:12}),ra=t=>/^[0-5][0-9]$/.test(t)?t:xo(t,{max:59}),TS=(t,e)=>xo(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),gf=(t,e)=>xo(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),PS=t=>{try{const e=Intl.Locale;if(typeof e!="function")return 1;const r=new e(t).weekInfo?.firstDay;return typeof r!="number"?1:r%7}catch{return 1}},IS=t=>{try{const e=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions();return typeof e.hour12=="boolean"?!e.hour12:e.hourCycle==="h23"||e.hourCycle==="h24"}catch{return!0}},RS=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Ih.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},ES=(t,e)=>[...t.slice(e),...t.slice(0,e)],er=t=>{const e=gt.c(6),{htmlFor:n,required:r,children:o}=t;let a;e[0]!==r?(a=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=a):a=e[1];let c;return e[2]!==o||e[3]!==n||e[4]!==a?(c=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,a]})}),e[2]=o,e[3]=n,e[4]=a,e[5]=c):c=e[5],c},xf=t=>{const e=gt.c(84),{value:n,onChange:r,use24Hour:o,hourAriaLabel:a,minuteAriaLabel:c,periodAriaLabel:l,amLabel:d,pmLabel:f}=t;let m;e[0]!==n?(m=DS(n),e[0]=n,e[1]=m):m=e[1];const u=m,p=nt.useRef(null),x=nt.useRef(null),[b,w]=nt.useState(null),[g,h]=nt.useState(null),k=nt.useRef(null),j=nt.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=ge=>{k.current=ge,w(ge)},e[2]=S):S=e[2];const N=S;let C;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=ge=>{j.current=ge,h(ge)},e[3]=C):C=e[3];const y=C,P=_S,_=$S,v=zS;let F;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==o?(F=ge=>{const ce=ge.replace(/\D/g,"").slice(0,2);N(ce),ce.length===2&&(r(o?v(P(ce),u.minute):Ii(pf(ce),u.minute,u.meridiem)),N(null),x.current?.focus())},e[4]=r,e[5]=u.meridiem,e[6]=u.minute,e[7]=o,e[8]=F):F=e[8];const I=F;let R;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==o?(R=()=>{const ge=k.current;if(ge!==null&&(N(null),ge.length!==0)){if(o){r(v(P(ge.padStart(2,"0")),u.minute));return}r(Ii(pf(ge.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=o,e[13]=R):R=e[13];const B=R;let D;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==o?(D=ge=>{const ce=ge.replace(/\D/g,"").slice(0,2);y(ce),ce.length===2&&(r(o?v(u.hour24,ra(ce)):Ii(u.hour12,ra(ce),u.meridiem)),y(null))},e[14]=r,e[15]=u.hour12,e[16]=u.hour24,e[17]=u.meridiem,e[18]=o,e[19]=D):D=e[19];const W=D;let U;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==o?(U=()=>{const ge=j.current;ge!==null&&(y(null),ge.length!==0&&r(o?v(u.hour24,ra(ge.padStart(2,"0"))):Ii(u.hour12,ra(ge.padStart(2,"0")),u.meridiem)))},e[20]=r,e[21]=u.hour12,e[22]=u.hour24,e[23]=u.meridiem,e[24]=o,e[25]=U):U=e[25];const L=U;let M;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==o?(M=ge=>r(o?v(_(u.hour24,ge),u.minute):Ii(TS(u.hour12,ge),u.minute,u.meridiem)),e[26]=r,e[27]=u.hour12,e[28]=u.hour24,e[29]=u.meridiem,e[30]=u.minute,e[31]=o,e[32]=M):M=e[32];const ee=M;let ie;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==o?(ie=ge=>r(o?v(u.hour24,gf(u.minute,ge)):Ii(u.hour12,gf(u.minute,ge),u.meridiem)),e[33]=r,e[34]=u.hour12,e[35]=u.hour24,e[36]=u.meridiem,e[37]=u.minute,e[38]=o,e[39]=ie):ie=e[39];const te=ie;let H;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(H=ge=>{ge!==u.meridiem&&r(Ii(u.hour12,u.minute,ge))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=H):H=e[44];const J=H;let re;e[45]!==B||e[46]!==ee?(re=ge=>{if(ge.key==="ArrowRight"){ge.preventDefault(),B(),x.current?.focus();return}(ge.key==="ArrowUp"||ge.key==="ArrowDown")&&(ge.preventDefault(),N(null),ee(ge.key==="ArrowUp"?1:-1))},e[45]=B,e[46]=ee,e[47]=re):re=e[47];const oe=re;let ve;e[48]!==L||e[49]!==te?(ve=ge=>{if(ge.key==="ArrowLeft"&&(ge.currentTarget.selectionStart??0)===0){ge.preventDefault(),L(),p.current?.focus();return}(ge.key==="ArrowUp"||ge.key==="ArrowDown")&&(ge.preventDefault(),y(null),te(ge.key==="ArrowUp"?1:-1))},e[48]=L,e[49]=te,e[50]=ve):ve=e[50];const ne=ve,ye=o?"px-2":"pl-2 pr-1";let he;e[51]!==ye?(he=Pe("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",ye),e[51]=ye,e[52]=he):he=e[52];const Fe=b??(o?u.hour24:u.hour12);let z;e[53]!==I?(z=ge=>I(ge.target.value),e[53]=I,e[54]=z):z=e[54];let K;e[55]===Symbol.for("react.memo_cache_sentinel")?(K=()=>N(""),e[55]=K):K=e[55];let Y;e[56]!==B||e[57]!==a||e[58]!==oe||e[59]!==Fe||e[60]!==z?(Y=s.jsx("input",{ref:p,inputMode:"numeric",value:Fe,onChange:z,onKeyDown:oe,onFocus:K,onBlur:B,maxLength:2,"aria-label":a,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=B,e[57]=a,e[58]=oe,e[59]=Fe,e[60]=z,e[61]=Y):Y=e[61];let me;e[62]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=me):me=e[62];const Ne=g??u.minute;let Be;e[63]!==W?(Be=ge=>W(ge.target.value),e[63]=W,e[64]=Be):Be=e[64];let _e;e[65]===Symbol.for("react.memo_cache_sentinel")?(_e=()=>y(""),e[65]=_e):_e=e[65];let Oe;e[66]!==L||e[67]!==c||e[68]!==ne||e[69]!==Ne||e[70]!==Be?(Oe=s.jsx("input",{ref:x,inputMode:"numeric",value:Ne,onChange:Be,onKeyDown:ne,onFocus:_e,onBlur:L,maxLength:2,"aria-label":c,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=L,e[67]=c,e[68]=ne,e[69]=Ne,e[70]=Be,e[71]=Oe):Oe=e[71];let pe;e[72]!==d||e[73]!==u.meridiem||e[74]!==l||e[75]!==f||e[76]!==J||e[77]!==o?(pe=o?null:s.jsxs(Un,{value:u.meridiem,onValueChange:ge=>J(ge),children:[s.jsx(Hn,{"aria-label":l,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(Dn,{})}),s.jsxs(Gn,{children:[s.jsx(Bs,{value:"AM",children:d}),s.jsx(Bs,{value:"PM",children:f})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=l,e[75]=f,e[76]=J,e[77]=o,e[78]=pe):pe=e[78];let Re;return e[79]!==he||e[80]!==Y||e[81]!==Oe||e[82]!==pe?(Re=s.jsxs("div",{className:he,children:[Y,me,Oe,pe]}),e[79]=he,e[80]=Y,e[81]=Oe,e[82]=pe,e[83]=Re):Re=e[83],Re},bf=t=>new Date(t.getFullYear(),t.getMonth(),1),MS=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},wf=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),FS=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(o=>typeof o=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(o)).map(o=>o.trim()),r=Array.from(new Set(n)).sort((o,a)=>o.localeCompare(a));return r.length>0?r:["09:00"]},yf=(t,e)=>{const n=Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC";return t?{id:t.id,name:t.name,enabled:t.enabled,schedule:{kind:t.schedule.kind==="cron"?"cron":t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:FS(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:ff(),onceTime:typeof t.schedule.time=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.time)?t.schedule.time:"09:00",weekdays:Array.isArray(t.schedule.weekdays)?t.schedule.weekdays:[1],timezone:t.schedule.timezone||n,cronExpression:t.schedule.kind==="cron"&&typeof t.schedule.cron=="string"?t.schedule.cron:""},execution:{prompt:t.execution.prompt,providerID:t.execution.providerID,modelID:t.execution.modelID,variant:t.execution.variant||"",agent:t.execution.agent||"",goalEnabled:t.execution.goalEnabled===!0,goalTokenBudget:typeof t.execution.goalTokenBudget=="number"&&t.execution.goalTokenBudget>0?t.execution.goalTokenBudget:null},state:t.state}:{name:"",enabled:!0,schedule:{kind:"daily",times:["09:00"],onceDate:ff(),onceTime:"09:00",weekdays:[1],timezone:n,cronExpression:""},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent,goalEnabled:!1,goalTokenBudget:null}}},OS=(t,e)=>{if(!t.name.trim())return e("sessions.scheduledTasks.editor.validation.taskNameRequired");if(!t.execution.prompt.trim())return e("sessions.scheduledTasks.editor.validation.promptRequired");if(!t.execution.providerID.trim()||!t.execution.modelID.trim())return e("sessions.scheduledTasks.editor.validation.modelRequired");if(t.schedule.kind==="once"){if(!/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.onceDate))return e("sessions.scheduledTasks.editor.validation.dateFormat");if(!/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.onceTime))return e("sessions.scheduledTasks.editor.validation.timeFormat")}else if(t.schedule.kind==="cron"){if(!t.schedule.cronExpression.trim())return e("sessions.scheduledTasks.editor.validation.cronRequired");if(!Ph(t.schedule.cronExpression).valid)return e("sessions.scheduledTasks.editor.validation.cronInvalid")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},LS=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))},BS=t=>{const e=gt.c(64),{draft:n,setDraft:r,locale:o,t:a}=t,c=n.schedule.cronExpression;let l;e[0]!==c?(l=c.trim()?Ph(c):null,e[0]=c,e[1]=l):l=e[1];const d=l;let f;e:{if(!d?.valid||!c.trim()){let M;e[2]===Symbol.for("react.memo_cache_sentinel")?(M=[],e[2]=M):M=e[2],f=M;break e}let L;e[3]!==c||e[4]!==n.schedule.timezone?(L=NS(c,n.schedule.timezone),e[3]=c,e[4]=n.schedule.timezone,e[5]=L):L=e[5],f=L}const m=f;let u;e[6]!==n.schedule.timezone||e[7]!==o?(u=L=>new Intl.DateTimeFormat(o,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(L),e[6]=n.schedule.timezone,e[7]=o,e[8]=u):u=e[8];const p=u;let x;e[9]!==a?(x=a("sessions.scheduledTasks.editor.cronExpression.label"),e[9]=a,e[10]=x):x=e[10];let b;e[11]!==x?(b=s.jsx(er,{htmlFor:"sched-cron",required:!0,children:x}),e[11]=x,e[12]=b):b=e[12];let w;e[13]!==r?(w=L=>r(M=>({...M,schedule:{...M.schedule,cronExpression:L.target.value}})),e[13]=r,e[14]=w):w=e[14];let g;e[15]!==a?(g=a("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=a,e[16]=g):g=e[16];let h;e[17]!==c||e[18]!==w||e[19]!==g?(h=s.jsx(Ln,{id:"sched-cron",value:c,onChange:w,placeholder:g,className:"w-full max-w-xs font-mono"}),e[17]=c,e[18]=w,e[19]=g,e[20]=h):h=e[20];let k;e[21]!==c||e[22]!==d||e[23]!==a?(k=d&&!d.valid&&c.trim()?s.jsx("span",{className:"typography-micro text-destructive",children:a("sessions.scheduledTasks.editor.validation.cronInvalid")}):null,e[21]=c,e[22]=d,e[23]=a,e[24]=k):k=e[24];let j;e[25]!==b||e[26]!==h||e[27]!==k?(j=s.jsxs("div",{className:"flex flex-col gap-1",children:[b,h,k]}),e[25]=b,e[26]=h,e[27]=k,e[28]=j):j=e[28];let S;e[29]!==p||e[30]!==m||e[31]!==a?(S=m.length>0?s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("sessions.scheduledTasks.editor.cronExpression.nextRuns")}),s.jsx("span",{className:"typography-micro text-foreground",children:m.map(p).join(", ")})]}):null,e[29]=p,e[30]=m,e[31]=a,e[32]=S):S=e[32];let N;e[33]!==a?(N=a("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=a,e[34]=N):N=e[34];let C;e[35]!==N?(C=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[35]=N,e[36]=C):C=e[36];let y;e[37]!==r||e[38]!==a?(y=kS.map(L=>s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 typography-micro text-foreground hover:bg-interactive-hover",onClick:()=>r(M=>({...M,schedule:{...M.schedule,cronExpression:L.expression}})),children:[s.jsx("span",{className:"font-mono",children:L.expression}),s.jsx("span",{className:"text-muted-foreground",children:a(L.labelKey)})]},L.expression)),e[37]=r,e[38]=a,e[39]=y):y=e[39];let P;e[40]!==y?(P=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:y}),e[40]=y,e[41]=P):P=e[41];let _;e[42]!==C||e[43]!==P?(_=s.jsxs("div",{className:"flex flex-col gap-1",children:[C,P]}),e[42]=C,e[43]=P,e[44]=_):_=e[44];let v;e[45]!==a?(v=a("sessions.scheduledTasks.editor.timezone.label"),e[45]=a,e[46]=v):v=e[46];let F;e[47]!==v?(F=s.jsx(er,{children:v}),e[47]=v,e[48]=F):F=e[48];let I;e[49]!==r?(I=L=>{r(M=>({...M,schedule:{...M.schedule,timezone:L}}))},e[49]=r,e[50]=I):I=e[50];let R;e[51]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(Hn,{className:"w-fit max-w-full",children:s.jsx(Dn,{})}),e[51]=R):R=e[51];let B;e[52]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(Gn,{children:fc.map(WS)}),e[52]=B):B=e[52];let D;e[53]!==n.schedule.timezone||e[54]!==I?(D=s.jsxs(Un,{value:n.schedule.timezone,onValueChange:I,children:[R,B]}),e[53]=n.schedule.timezone,e[54]=I,e[55]=D):D=e[55];let W;e[56]!==F||e[57]!==D?(W=s.jsxs("div",{className:"flex flex-col gap-1",children:[F,D]}),e[56]=F,e[57]=D,e[58]=W):W=e[58];let U;return e[59]!==j||e[60]!==S||e[61]!==_||e[62]!==W?(U=s.jsxs("div",{className:"flex flex-col gap-3",children:[j,S,_,W]}),e[59]=j,e[60]=S,e[61]=_,e[62]=W,e[63]=U):U=e[63],U};function VS(t){const{open:e,task:n,onOpenChange:r,onSave:o}=t,{t:a,locale:c}=yt(),l=rs(q=>q.loadProviders),d=rs(q=>q.loadAgents),f=rs(q=>q.providers),m=rs(q=>q.currentProviderId),u=rs(q=>q.currentModelId),p=rs(q=>q.currentVariant||""),x=rs(q=>q.currentAgentName||""),b=Ee(q=>q.timeFormatPreference),w=Ee(q=>q.weekStartPreference),g=Ee(q=>q.isMobile),[h,k]=nt.useState(()=>yf(n,{providerID:m,modelID:u,variant:p,agent:x})),[j,S]=nt.useState(!1),[N,C]=nt.useState(!1),[y,P]=nt.useState(!1),[_,v]=nt.useState(""),[F,I]=nt.useState(!1),[R,B]=nt.useState(""),[D,W]=nt.useState(!1),[U,L]=nt.useState(""),[M,ee]=nt.useState(()=>{const q=wa(n?.schedule?.date||"")||new Date;return new Date(q.getFullYear(),q.getMonth(),1)}),ie=nt.useRef(null),te=nt.useRef(null),H=nt.useRef(null),J=nt.useRef(null),re=nt.useRef(null),oe=nt.useMemo(()=>IS(c),[c]),ve=nt.useMemo(()=>PS(c),[c]),ne=nt.useMemo(()=>b==="24h"?!0:b==="12h"?!1:oe,[b,oe]),ye=nt.useMemo(()=>w==="sunday"?0:w==="monday"?1:ve,[w,ve]),he=nt.useMemo(()=>{const q=RS(c);return ES(Ih.map(O=>({value:O,label:q[O]||""})),ye)},[c,ye]);nt.useEffect(()=>{e&&(l({source:"scheduledTaskEditor"}),d({source:"scheduledTaskEditor"}))},[e,l,d]),nt.useEffect(()=>{if(!e)return;k(yf(n,{providerID:m,modelID:u,variant:p,agent:x}));const q=wa(n?.schedule?.date||"")||new Date;ee(new Date(q.getFullYear(),q.getMonth(),1)),C(!1),I(!1),P(!1),B(""),v("")},[e,n,m,u,p,x]),nt.useEffect(()=>{if(!N)return;const q=O=>{ie.current&&!ie.current.contains(O.target)&&C(!1)};return document.addEventListener("mousedown",q),()=>{document.removeEventListener("mousedown",q)}},[N]);const Fe=nt.useMemo(()=>{const O=f.find(se=>se.id===h.execution.providerID)?.models?.find(se=>se.id===h.execution.modelID);return O?.variants?Object.keys(O.variants):[]},[f,h.execution.providerID,h.execution.modelID]),z=Fe.length>0,K=nt.useMemo(()=>!z||!h.execution.variant?"__default":Fe.includes(h.execution.variant)?h.execution.variant:"__default",[h.execution.variant,z,Fe]);nt.useEffect(()=>{z||!h.execution.variant||k(q=>({...q,execution:{...q.execution,variant:""}}))},[z,h.execution.variant]);const Y=nt.useCallback((q,O)=>{k(se=>{const Le=new Set(se.schedule.weekdays);return O?Le.add(q):Le.delete(q),{...se,schedule:{...se.schedule,weekdays:Array.from(Le).sort((ae,We)=>ae-We)}}})},[]),me=nt.useCallback((q,O)=>{k(se=>{const Le=se.schedule.times.slice();return Le[q]=O,{...se,schedule:{...se.schedule,times:Le}}})},[]),Ne=nt.useCallback(q=>{k(O=>{const se=O.schedule.times.filter((Le,ae)=>ae!==q);return{...O,schedule:{...O.schedule,times:se.length>0?se:["09:00"]}}})},[]),Be=nt.useCallback(()=>{k(q=>({...q,schedule:{...q.schedule,times:[...q.schedule.times,"12:00"]}}))},[]),_e=nt.useMemo(()=>MS(),[]),Oe=nt.useMemo(()=>bf(_e),[_e]),pe=nt.useMemo(()=>{const q=wa(h.schedule.onceDate);return q?wf(q,_e)?a("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(c,{weekday:"short"}).format(q):null},[h.schedule.onceDate,c,a,_e]),Re=nt.useMemo(()=>bf(M).getTime()<=Oe.getTime(),[M,Oe]),ge=nt.useMemo(()=>he.map(q=>q.label),[he]),ce=nt.useCallback(q=>{k(O=>({...O,schedule:{...O.schedule,onceDate:q}}))},[]),Ce=nt.useCallback((q,O)=>{if(q.startsWith("/")){const We=q.indexOf(" "),Ye=q.indexOf(`
|
|
169
|
+
`),Qe=Math.min(We===-1?q.length:We,Ye===-1?q.length:Ye);if(O<=Qe&&We===-1){B(q.substring(1,Qe)),I(!0),P(!1),W(!1);return}}I(!1);const se=q.substring(0,O),Le=se.lastIndexOf("#");if(Le!==-1){const We=Le>0?se[Le-1]:null,Ye=se.substring(Le+1);if((!We||/\s/.test(We))&&!Ye.includes(" ")&&!Ye.includes(`
|
|
170
|
+
`)){L(Ye),W(!0),P(!1);return}}W(!1);const ae=se.lastIndexOf("@");if(ae!==-1){const We=ae>0?se[ae-1]:null,Ye=se.substring(ae+1);(!We||/\s/.test(We))&&!Ye.includes(" ")&&!Ye.includes(`
|
|
171
|
+
`)?(v(Ye),P(!0)):P(!1);return}P(!1)},[]),be=nt.useCallback(q=>{k(O=>({...O,execution:{...O.execution,prompt:q}}))},[]),ue=nt.useCallback(q=>{const O=h.execution.prompt,Le=te.current?.selectionStart??O.length,We=O.substring(0,Le).lastIndexOf("@"),Ye=q.relativePath&&q.relativePath.trim().length>0?q.relativePath.trim():q.path||q.name,Qe=We!==-1?We:Le,st=`${O.substring(0,Qe)}@${Ye} ${O.substring(Le)}`,pt=Qe+Ye.length+2;be(st),P(!1),v(""),requestAnimationFrame(()=>{const jt=te.current;jt&&(jt.selectionStart=pt,jt.selectionEnd=pt,jt.focus()),Ce(st,pt)})},[h.execution.prompt,be,Ce]),De=nt.useCallback(q=>{const O=h.execution.prompt,Le=te.current?.selectionStart??O.length,We=O.substring(0,Le).lastIndexOf("@"),Ye=We!==-1?We:Le,Qe=`${O.substring(0,Ye)}@${q} ${O.substring(Le)}`,st=Ye+q.length+2;be(Qe),P(!1),v(""),requestAnimationFrame(()=>{const pt=te.current;pt&&(pt.selectionStart=st,pt.selectionEnd=st,pt.focus()),Ce(Qe,st)})},[h.execution.prompt,be,Ce]),T=nt.useCallback(q=>{const O=`/${q.name} `;be(O),I(!1),B(""),W(!1),requestAnimationFrame(()=>{const se=te.current;se&&(se.focus(),se.selectionStart=se.value.length,se.selectionEnd=se.value.length),Ce(O,O.length)})},[be,Ce]),V=nt.useCallback((q,O)=>{const se=h.execution.prompt,ae=te.current?.selectionStart??se.length,Ye=se.substring(0,ae).lastIndexOf("#"),Qe=Ye!==-1?Ye:ae,st=`${se.substring(0,Qe)}#${O} ${se.substring(ae)}`,pt=Qe+O.length+2;be(st),W(!1),L(""),requestAnimationFrame(()=>{const jt=te.current;jt&&(jt.selectionStart=pt,jt.selectionEnd=pt,jt.focus()),Ce(st,pt)})},[h.execution.prompt,be,Ce]),we=nt.useCallback(q=>{if(F&&J.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")){q.preventDefault(),J.current.handleKeyDown(q.key);return}y&&H.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")&&(q.preventDefault(),H.current.handleKeyDown(q.key)),D&&re.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")&&(q.preventDefault(),re.current.handleKeyDown(q.key))},[F,y,D]),E=nt.useCallback(async()=>{const q=OS(h,a);if(q){le.error(q);return}const O={...h.id?{id:h.id}:{},name:h.name.trim(),enabled:h.enabled,schedule:{kind:h.schedule.kind,timezone:h.schedule.timezone.trim(),...h.schedule.kind==="cron"?{cron:h.schedule.cronExpression.trim()}:h.schedule.kind==="once"?{date:h.schedule.onceDate,time:h.schedule.onceTime}:{times:LS(h.schedule.times),...h.schedule.kind==="weekly"?{weekdays:h.schedule.weekdays}:{}}},execution:{prompt:h.execution.prompt,providerID:h.execution.providerID,modelID:h.execution.modelID,...h.execution.variant.trim()?{variant:h.execution.variant.trim()}:{},...h.execution.agent.trim()?{agent:h.execution.agent.trim()}:{},...h.execution.goalEnabled?{goalEnabled:!0}:{},...h.execution.goalEnabled&&h.execution.goalTokenBudget?{goalTokenBudget:h.execution.goalTokenBudget}:{}},...h.state?{state:h.state}:{}};S(!0);try{await o(O),r(!1)}catch(se){le.error(se instanceof Error?se.message:a("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[h,r,o,a]),de=nt.useId(),fe=nt.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),$=a(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),ke=a("sessions.scheduledTasks.editor.description"),Ve=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(er,{htmlFor:"sched-name",required:!0,children:a("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Ln,{id:"sched-name",value:h.name,onChange:q=>k(O=>({...O,name:q.target.value})),placeholder:a("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(er,{children:a("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(Un,{value:h.schedule.kind,onValueChange:q=>{k(O=>({...O,schedule:{...O.schedule,kind:q,...q==="cron"&&!O.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx(Hn,{className:"w-fit max-w-full",children:s.jsx(Dn,{children:q=>a(q==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":q==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":q==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(Gn,{children:[s.jsx(Bs,{value:"daily",children:a("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Bs,{value:"weekly",children:a("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Bs,{value:"once",children:a("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(Bs,{value:"cron",children:a("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),h.schedule.kind==="cron"?s.jsx(BS,{draft:h,setDraft:k,locale:c,t:a}):h.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:ie,children:[s.jsx(er,{children:a("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>C(q=>!q),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(A,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:CS(h.schedule.onceDate,a("sessions.scheduledTasks.editor.date.placeholder"),c)})]}),s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),N?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>ee(q=>hf(q,-1)),"aria-label":a("sessions.scheduledTasks.editor.date.previousMonth"),disabled:Re,children:s.jsx(A,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(c,{month:"long",year:"numeric"}).format(M)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>ee(q=>hf(q,1)),"aria-label":a("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:ge.map((q,O)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:q},`${q}-${O}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:AS(M,ye).map(({date:q,inCurrentMonth:O})=>{const se=mf(q),Le=se===h.schedule.onceDate,ae=wf(q,_e),We=q.getTime()<_e.getTime(),Ye=Le?"bg-interactive-selection text-interactive-selection-foreground":We?"text-muted-foreground/40":O?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{We||(ce(se),C(!1))},disabled:We,className:["h-8 rounded-md typography-ui-label",Ye,ae&&!Le?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",We?"cursor-not-allowed opacity-45":""].join(" "),children:q.getDate()},se)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:pe||""}),s.jsx(ze,{type:"button",size:"xs",variant:"ghost",onClick:()=>{ce(mf(_e)),ee(new Date(_e.getFullYear(),_e.getMonth(),1))},children:a("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(er,{children:a("sessions.scheduledTasks.editor.time.label")}),s.jsx(xf,{value:h.schedule.onceTime,use24Hour:ne,hourAriaLabel:a("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:a("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:a("sessions.scheduledTasks.editor.time.periodAria"),amLabel:a("sessions.scheduledTasks.editor.time.period.am"),pmLabel:a("sessions.scheduledTasks.editor.time.period.pm"),onChange:q=>k(O=>({...O,schedule:{...O.schedule,onceTime:q}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(er,{children:a("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Un,{value:h.schedule.timezone,onValueChange:q=>{k(O=>({...O,schedule:{...O.schedule,timezone:q}}))},children:[s.jsx(Hn,{className:"w-fit max-w-full",children:s.jsx(Dn,{})}),s.jsx(Gn,{children:fc.map(q=>s.jsx(Bs,{value:q,children:q},q))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[h.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(er,{children:a("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:he.map(q=>{const O=h.schedule.weekdays.includes(q.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",O?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(Vr,{checked:O,onChange:se=>Y(q.value,se),ariaLabel:q.label}),s.jsx("button",{type:"button",onClick:()=>Y(q.value,!O),className:"group-hover:text-foreground",children:q.label})]},q.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(er,{children:a("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:h.schedule.times.map((q,O)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xf,{value:q,use24Hour:ne,hourAriaLabel:a("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:a("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:a("sessions.scheduledTasks.editor.time.periodAria"),amLabel:a("sessions.scheduledTasks.editor.time.period.am"),pmLabel:a("sessions.scheduledTasks.editor.time.period.pm"),onChange:se=>me(O,se)}),h.schedule.times.length>1?s.jsx(ze,{type:"button",size:"icon",variant:"ghost",onClick:()=>Ne(O),"aria-label":a("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null]},O))}),s.jsx("div",{children:s.jsxs(ze,{type:"button",size:"sm",variant:"outline",onClick:Be,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",a("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(er,{children:a("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Un,{value:h.schedule.timezone,onValueChange:q=>{k(O=>({...O,schedule:{...O.schedule,timezone:q}}))},children:[s.jsx(Hn,{className:"w-fit max-w-full",children:s.jsx(Dn,{})}),s.jsx(Gn,{children:fc.map(q=>s.jsx(Bs,{value:q,children:q},q))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(er,{required:!0,children:a("sessions.scheduledTasks.editor.model.label")}),s.jsx(am,{providerId:h.execution.providerID,modelId:h.execution.modelID,onChange:(q,O)=>{k(se=>({...se,execution:{...se.execution,providerID:q,modelID:O,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(er,{children:a("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(Un,{value:K,disabled:!z,onValueChange:q=>{k(O=>({...O,execution:{...O.execution,variant:q==="__default"?"":q}}))},children:[s.jsx(Hn,{className:"w-fit max-w-full",children:s.jsx(Dn,{children:q=>q==="__default"?a("sessions.scheduledTasks.editor.thinkingLevel.default"):q})}),s.jsxs(Gn,{children:[s.jsx(Bs,{value:"__default",children:a("sessions.scheduledTasks.editor.thinkingLevel.default")}),Fe.map(q=>s.jsx(Bs,{value:q,children:q},q))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(er,{children:a("sessions.scheduledTasks.editor.agent.label")}),s.jsx(lm,{agentName:h.execution.agent,filter:q=>Dc(q.mode),onChange:q=>k(O=>({...O,execution:{...O.execution,agent:q}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(er,{htmlFor:"sched-prompt",required:!0,children:a("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(Oi,{id:"sched-prompt",ref:te,value:h.execution.prompt,onChange:q=>{const O=q.target.value;be(O);const se=q.target.selectionStart??O.length;Ce(O,se)},onKeyDown:we,rows:8,placeholder:a("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),F?s.jsx(ym,{ref:J,searchQuery:R,onCommandSelect:T,onClose:()=>I(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,y?s.jsx(vm,{ref:H,searchQuery:_,onFileSelect:ue,onAgentSelect:De,onClose:()=>P(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,D?s.jsx(jm,{ref:re,searchQuery:U,onSnippetSelect:V,onClose:()=>W(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-x-8 gap-y-2",children:[s.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2",children:[s.jsx(Vr,{checked:h.execution.goalEnabled,onChange:q=>k(O=>({...O,execution:{...O.execution,goalEnabled:q}})),ariaLabel:a("sessions.scheduledTasks.editor.goal.aria")}),s.jsx("span",{className:"typography-meta",children:a("sessions.scheduledTasks.editor.goal.label")})]}),h.execution.goalEnabled?s.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2",children:[s.jsx(Vr,{checked:h.execution.goalTokenBudget!==null,onChange:q=>k(O=>({...O,execution:{...O.execution,goalTokenBudget:q?2e5:null}})),ariaLabel:a("sessions.scheduledTasks.editor.goal.budgetAria")}),s.jsx("span",{className:"typography-meta",children:a("sessions.scheduledTasks.editor.goal.budgetLabel")})]}):null,h.execution.goalEnabled&&h.execution.goalTokenBudget!==null?s.jsx($g,{value:h.execution.goalTokenBudget,onValueChange:q=>{typeof q=="number"&&Number.isFinite(q)&&q>0&&k(O=>({...O,execution:{...O.execution,goalTokenBudget:Math.floor(q)}}))},min:1e3,max:1e8,step:5e4}):null]})]}),Se=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(Vr,{checked:h.enabled,onChange:q=>k(O=>({...O,enabled:q})),ariaLabel:a("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:a("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:j,children:a("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(ze,{type:"button",size:"sm",onClick:E,disabled:j,children:a(j?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return g?s.jsx(Ya,{open:e,title:$,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:q=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:$}),q]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:ke})]}),footer:Se,children:Ve}):s.jsx(_s,{open:e,onOpenChange:q=>{!q&&fe()||r(q)},children:s.jsxs(Vs,{"aria-describedby":de,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(dn,{id:de,className:"sr-only",children:ke}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(Gs,{className:"typography-ui-label font-medium text-foreground",children:$}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:ke})]})}),s.jsx(Qa,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:Ve})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:Se})})]})})}function _S(t){return xo(t,{min:0,max:23})}function $S(t,e){return xo(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function zS(t,e){const n=Number(t),r=Number(e),o=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,a=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(o).padStart(2,"0")}:${String(a).padStart(2,"0")}`}function WS(t){return s.jsx(Bs,{value:t,children:t},t)}const US=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,o)=>r.localeCompare(o))},HS=(t,e)=>{const n=US(t).join(", ")||"--:--",r=o=>e(o===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":o===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":o===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":o===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":o===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":o===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":o===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const o=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(a=>r(a)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:o,time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:o,time:n})}if(t.schedule.kind==="once"){const o=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),a=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:o,time:a,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.once",{date:o,time:a})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},GS=(t,e)=>!t||!Number.isFinite(t)?"":sm(t,e),vf=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),o=6e4,a=60*o,c=24*a,l=n>=0;if(r<o)return e(l?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<a){const u=Math.round(r/o);return l?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:u}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:u})}if(r<c){const u=Math.floor(r/a),p=Math.round(r%a/o),x=p>0?`${u}h ${p}m`:`${u}h`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:x}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:x})}const d=Math.floor(r/c),f=Math.round(r%c/a),m=f>0?`${d}d ${f}h`:`${d}d`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},KS={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},qS=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function YS(){const{t}=yt(),e=Ee(D=>D.isScheduledTasksDialogOpen),n=Ee(D=>D.setScheduledTasksDialogOpen),r=Ee(D=>D.isMobile),o=Ee(D=>D.timeFormatPreference),a=Ds(D=>D.projects),c=Ds(D=>D.getActiveProject()),l=Js(D=>D.homeDirectory),{currentTheme:d}=wi(),[f,m]=nt.useState(""),[u,p]=nt.useState([]),[x,b]=nt.useState(!0),[w,g]=nt.useState(!1),[h,k]=nt.useState(null),[j,S]=nt.useState(null),N=nt.useMemo(()=>a.find(D=>D.id===f)||null,[a,f]),C=nt.useCallback(D=>{const W=D.label?.trim()||ho(D.path,l||void 0),U=D.icon?Lc[D.icon]:null,L=D.color?Bc[D.color]:void 0,M=U?s.jsx(A,{name:U,className:"h-3.5 w-3.5 shrink-0",style:L?{color:L}:void 0}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:L?{color:L}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[D.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:D.iconBackground?{backgroundColor:D.iconBackground}:void 0,children:s.jsx(Vc,{project:{id:D.id,iconImage:D.iconImage??null},options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:M})}):M,s.jsx("span",{className:"truncate",children:W})]})},[l,d.metadata.variant,d.colors.surface.foreground]),y=nt.useCallback(async(D,W)=>{if(!D){p([]);return}W?.silent||b(!0);try{const U=await vS(D);U.sort((L,M)=>{if(L.enabled!==M.enabled)return L.enabled?-1:1;const ee=L.name.localeCompare(M.name);return ee!==0?ee:(L.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(M.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),p(U)}catch(U){le.error(U instanceof Error?U.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),W?.silent||p([])}finally{W?.silent||b(!1)}},[t]);nt.useEffect(()=>{if(!e)return;const D=c?.id||a[0]?.id||"";m(D),D?y(D):(p([]),b(!1))},[e,c,a,y]),nt.useEffect(()=>{if(!e)return;let D=null;const W=Th(U=>{U.type==="scheduled-task-ran"&&U.projectId===f&&(D&&clearTimeout(D),D=setTimeout(()=>{y(f,{silent:!0})},400))});return()=>{D&&clearTimeout(D),W()}},[e,f,y]);const P=nt.useCallback(async D=>{if(!f)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await uf(f,D),await y(f),le.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[f,y,t]),_=nt.useCallback(async(D,W)=>{if(f){S(D.id),p(U=>U.map(L=>L.id===D.id?{...L,enabled:W}:L));try{await uf(f,{...D,enabled:W}),await y(f,{silent:!0})}catch(U){le.error(U instanceof Error?U.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await y(f,{silent:!0})}finally{S(null)}}},[f,y,t]),v=nt.useCallback(async D=>{if(!(!f||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:D.name})))){S(D.id);try{await jS(f,D.id),await y(f,{silent:!0}),le.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(U){le.error(U instanceof Error?U.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{S(null)}}},[f,y,t]),F=nt.useCallback(async D=>{if(f){S(D.id);try{await SS(f,D.id),await Promise.all([y(f,{silent:!0}),Ta()]),le.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(W){le.error(W instanceof Error?W.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{S(null)}}},[f,y,t]),I=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(Un,{value:f||"__none",onValueChange:D=>{const W=D==="__none"?"":D;m(W),W?y(W):p([])},children:[s.jsx(Hn,{className:r?"w-full":void 0,children:N?s.jsx(Dn,{children:C(N)}):s.jsx(Dn,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(Gn,{children:[a.length===0?s.jsx(Bs,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(D=>s.jsx(Bs,{value:D.id,children:C(D)},D.id))]})]})]}),R=()=>{k(null),g(!0)},B=s.jsxs("div",{className:"space-y-4",children:[r?I:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[I,s.jsxs(ze,{onClick:R,disabled:!f,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:x?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):u.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(f?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:u.map(D=>{const W=j===D.id,U=D.state?.lastStatus||"idle",L=KS[U],M=t(U==="success"?"sessions.scheduledTasks.dialog.status.success":U==="error"?"sessions.scheduledTasks.dialog.status.error":U==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),ee=D.state?.nextRunAt,ie=D.state?.lastRunAt;return s.jsxs("div",{className:Pe("rounded-lg border border-border p-4 transition-opacity",!D.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:D.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:HS(D,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(A,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),ee?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:vf(ee,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:GS(ee,o)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(A,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),U==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):ie?s.jsxs(s.Fragment,{children:[L.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${L.tone})`},children:[s.jsx(A,{name:L.Icon,className:"h-3.5 w-3.5"}),M]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:vf(ie,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),D.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:qS("error"),children:[s.jsx(A,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:D.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:Pe("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",D.enabled?"text-foreground":"text-muted-foreground",W&&"cursor-not-allowed opacity-50"),children:[s.jsx(Vr,{checked:D.enabled,onChange:te=>{_(D,te)},ariaLabel:D.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:D.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:D.name}),disabled:W}),D.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(ze,{variant:"outline",size:"sm",onClick:()=>{F(D)},disabled:W,children:[s.jsx(A,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(ze,{variant:"outline",size:"sm",onClick:()=>{k(D),g(!0)},disabled:W,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:D.name}),children:[s.jsx(A,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(ze,{variant:"destructive",size:"sm",onClick:()=>{v(D)},disabled:W,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:D.name}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},D.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Ya,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:D=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),D]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(ze,{className:"w-full",onClick:R,disabled:!f,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:B}):s.jsx(_s,{open:e,onOpenChange:n,children:s.jsxs(Vs,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(tn,{children:[s.jsx(Gs,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(dn,{children:t("sessions.scheduledTasks.dialog.description")})]}),B]})}),s.jsx(VS,{open:w,task:h,onOpenChange:g,onSave:P})]})}const QS=t=>{const e=gt.c(12),{normalizedProjects:n,ownership:r,isSessionsLoading:o,hasAuthoritativeGlobalSessions:a,isWorktreeTopologyLoading:c,unresolvedWorktreeProjectPaths:l,foldersMap:d,createFolder:f,addSessionToFolder:m,cleanupSessions:u}=t;let p,x;e[0]!==m||e[1]!==u||e[2]!==f||e[3]!==d||e[4]!==a||e[5]!==o||e[6]!==c||e[7]!==n||e[8]!==r||e[9]!==l?(p=()=>{o||!a||c||n.forEach(b=>{if(l.has(b.normalizedPath))return;const w=Hc(b.normalizedPath),g=r.archivedSessionsByProject.get(b.id)??[],h=new Set(g.map(JS)),k=d[w]??[],j=new Map(k.map(XS));g.forEach(S=>{const N=Cb(S,b.normalizedPath),C=N.toLowerCase();let y=j.get(C);y||(y=f(w,N),j.set(C,y)),y.sessionIds.includes(S.id)||m(w,y.id,S.id)}),u(w,h)})},x=[n,r,o,a,c,l,d,f,m,u],e[0]=m,e[1]=u,e[2]=f,e[3]=d,e[4]=a,e[5]=o,e[6]=c,e[7]=n,e[8]=r,e[9]=l,e[10]=p,e[11]=x):(p=e[10],x=e[11]),i.useEffect(p,x)};function JS(t){return t.id}function XS(t){return[t.name.toLowerCase(),t]}const ZS=t=>{const e=gt.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:o,availableWorktreesByProject:a,projectRepoStatus:c,projectRootBranches:l,lastRepoStatus:d,buildGroupedSessions:f,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:p,buildGroupSearchText:x,foldersMap:b}=t;let w;if(e[0]!==a||e[1]!==f||e[2]!==o||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==c||e[7]!==l){let v;e[9]!==a||e[10]!==f||e[11]!==o||e[12]!==r||e[13]!==d||e[14]!==c||e[15]!==l?(v=F=>{const I=$m([...r(F.id),...o(F.id)]),R=a.get(F.normalizedPath)??[],B=c.has(F.id)?!!c.get(F.id):d,D=f(I,F.normalizedPath,R,l.get(F.id)??null,B);return{project:F,groups:D}},e[9]=a,e[10]=f,e[11]=o,e[12]=r,e[13]=d,e[14]=c,e[15]=l,e[16]=v):v=e[16],w=n.map(v),e[0]=a,e[1]=f,e[2]=o,e[3]=r,e[4]=d,e[5]=n,e[6]=c,e[7]=l,e[8]=w}else w=e[8];const g=w,h=g;let k;if(e[17]!==x||e[18]!==p||e[19]!==b||e[20]!==m||e[21]!==u||e[22]!==h){e:{const v=new WeakMap;if(!m){k=v;break e}const F=I=>I.reduce((R,B)=>R+1+F(B.children),0);h.forEach(I=>{I.groups.forEach(R=>{const B=p(R.sessions,u),D=F(B),W=x(R).includes(u),U=ws(R.directory??null),M=(U?b[U]??[]:[]).filter(ee=>ee.name.toLowerCase().includes(u)).length;v.set(R,{filteredNodes:B,matchedSessionCount:D,folderNameMatchCount:M,groupMatches:W,hasMatch:W||D>0||M>0})})}),k=v}e[17]=x,e[18]=p,e[19]=b,e[20]=m,e[21]=u,e[22]=h,e[23]=k}else k=e[23];const j=k;let S;e:{if(!m){S=h;break e}let v;if(e[24]!==j||e[25]!==h){let F;e[27]!==j?(F=I=>({...I,groups:I.groups.filter(R=>j.get(R)?.hasMatch===!0)}),e[27]=j,e[28]=F):F=e[28],v=h.map(F).filter(e2),e[24]=j,e[25]=h,e[26]=v}else v=e[26];S=v}const N=S,C=m?N:h;let y;e:{if(!m){y=0;break e}let v;if(e[29]!==j||e[30]!==C){let F;e[32]!==j?(F=(I,R)=>I+R.groups.reduce((B,D)=>{const W=j.get(D);if(!W)return B;const U=W.folderNameMatchCount+(W.groupMatches?1:0);return B+W.matchedSessionCount+U},0),e[32]=j,e[33]=F):F=e[33],v=C.reduce(F,0),e[29]=j,e[30]=C,e[31]=v}else v=e[31];y=v}const P=y;let _;return e[34]!==j||e[35]!==g||e[36]!==P||e[37]!==N||e[38]!==C||e[39]!==h?(_={projectSections:g,visibleProjectSections:h,groupSearchDataByGroup:j,searchableProjectSections:N,sectionsForRender:C,searchMatchCount:P},e[34]=j,e[35]=g,e[36]=P,e[37]=N,e[38]=C,e[39]=h,e[40]=_):_=e[40],_};function e2(t){return t.groups.length>0}const t2=t=>{const e=gt.c(26),{projectSections:n,activeProjectId:r,activeSessionByProject:o,setActiveSessionByProject:a,currentSessionId:c,handleSessionSelect:l,newSessionDraftOpen:d,mobileVariant:f,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:p}=t;let x,b;if(e[0]!==n){b=new Map,x=new Map;const C=(y,P,_,v)=>{b.has(y)||b.set(y,new Map);const F=b.get(y);v.forEach(I=>{const R=ws(I.worktree?.path??I.session.directory??_??P);F.set(I.session.id,{directory:R}),x.has(y)||x.set(y,{id:I.session.id,directory:R}),I.children.length>0&&C(y,P,R,I.children)})};n.forEach(y=>{y.groups.forEach(P=>{C(y.project.id,y.project.normalizedPath,P.directory,P.sessions)})}),e[0]=n,e[1]=x,e[2]=b}else x=e[1],b=e[2];let w;e[3]!==x||e[4]!==b?(w={metaByProject:b,firstSessionByProject:x},e[3]=x,e[4]=b,e[5]=w):w=e[5];const g=w,h=i.useRef(null);let k,j;e[6]!==r||e[7]!==o||e[8]!==c||e[9]!==l||e[10]!==f||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==g||e[15]!==u||e[16]!==a||e[17]!==p?(k=()=>{if(!r||d||Ee.getState().isNewWorktreeDialogOpen||h.current===r)return;const C=n.find(R=>R.project.id===r);if(!C)return;h.current=r;const y=g.metaByProject.get(r);if(c&&y&&y.has(c)){a(R=>{if(R.get(r)===c)return R;const B=new Map(R);return B.set(r,c),B});return}if(c&&y)return;if(!y||y.size===0){u("chat"),f&&p(!1),m({directoryOverride:C.project.normalizedPath});return}const P=o.get(r),_=P&&y.has(P)?P:null,v=g.firstSessionByProject.get(r)?.id??null,F=_??v;if(!F||F===c)return;const I=y.get(F)?.directory??null;l(F,I,r)},j=[r,o,c,l,d,f,m,n,g,u,p,a],e[6]=r,e[7]=o,e[8]=c,e[9]=l,e[10]=f,e[11]=d,e[12]=m,e[13]=n,e[14]=g,e[15]=u,e[16]=a,e[17]=p,e[18]=k,e[19]=j):(k=e[18],j=e[19]),i.useLayoutEffect(k,j);let S,N;e[20]!==r||e[21]!==c||e[22]!==g||e[23]!==a?(S=()=>{if(!r||!c)return;const C=g.metaByProject.get(r);!C||!C.has(c)||a(y=>{if(y.get(r)===c)return y;const P=new Map(y);return P.set(r,c),P})},N=[r,c,g,a],e[20]=r,e[21]=c,e[22]=g,e[23]=a,e[24]=S,e[25]=N):(S=e[24],N=e[25]),i.useEffect(S,N)},s2=t=>{const e=gt.c(4);let n;e[0]!==t?(n=(a,c)=>{const l=t.get(a);if(!l||l.length===0)return c;const d=new Map(c.map(n2)),f=[];return l.forEach(m=>{const u=d.get(m);u&&(f.push(u),d.delete(m))}),c.forEach(m=>{d.has(m.id)&&f.push(m)}),f},e[0]=t,e[1]=n):n=e[1];const r=n;let o;return e[2]!==r?(o={getOrderedGroups:r},e[2]=r,e[3]=o):o=e[3],o};function n2(t){return[t.id,t]}const ia=t=>!!t.time?.archived,r2=t=>{const{t:e}=yt(),n=i.useCallback(c=>[c.label,c.branch??"",c.description??"",c.directory??""].join(" ").toLowerCase(),[]),r=i.useCallback(c=>{const l=ws(c.directory??null)??"";return`${(c.title||e("sessions.sidebar.session.untitled")).trim()} ${l}`.toLowerCase()},[e]),o=i.useCallback((c,l)=>l?c.flatMap(d=>{if(r(d.session).includes(l))return[d];const m=o(d.children,l);return m.length===0?[]:[{...d,children:m}]}):c,[r]),a=i.useCallback((c,l,d,f,m)=>{const u=ws(l??null),p=$m(c).sort((I,R)=>eo(I,R,t.pinnedSessionIds)),x=new Map(p.map(I=>[I.id,I])),b=new Map;p.forEach(I=>{const R=I.parentID;if(!R)return;const B=x.get(R);if(!B||ia(B)!==ia(I))return;const D=b.get(R)??[];D.push(I),b.set(R,D)}),b.forEach(I=>I.sort((R,B)=>eo(R,B,t.pinnedSessionIds)));const w=new Map;d.forEach(I=>{if(I.path){const R=ws(I.path)??I.path;w.set(R,I)}});const g=I=>{const R=ws(I.directory??null),B=t.worktreeMetadata.get(I.id)??null;if(B)return B;if(R){const D=w.get(R)??null;if(D&&R!==u)return D}return null},h=I=>{const R=b.get(I.id)??[];return{session:I,children:R.map(B=>h(B)),worktree:g(I)}},k=p.filter(I=>{const R=I.parentID;if(!R)return!0;const B=x.get(R);return B?ia(B)!==ia(I):!0}),j=new Map,S="__archived__",N=I=>{if(I.time?.archived)return S;if(t.isVSCode)return u??"__project_root__";const B=ws(t.worktreeMetadata.get(I.id)?.path??null)??ti(I);return B?B!==u&&w.has(B)?B:B===u?u??"__project_root__":S:S};k.forEach(I=>{const R=h(I),B=N(I);j.has(B)||j.set(B,[]),j.get(B)?.push(R)});const C=u??"__project_root__",y=[{id:"root",label:m&&f&&f!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:f}):e("sessions.sidebar.grouping.projectRoot"),branch:f??null,description:u?Pa(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:j.get(C)??[]}],P=new Map;d.forEach(I=>{const R=ws(I.path)??I.path,B=j.get(R)??[],D=B.length>0,W=B.reduce((U,L)=>{const M=Number(L.session.time?.updated??L.session.time?.created??0);return Number.isFinite(M)?Math.max(U,M):U},0);P.set(R,{hasActiveSession:D,lastUpdatedAt:W})});const _=[...d].sort((I,R)=>{const B=ws(I.path)??I.path,D=ws(R.path)??R.path,W=P.get(B)??{hasActiveSession:!1,lastUpdatedAt:0},U=P.get(D)??{hasActiveSession:!1,lastUpdatedAt:0};if(W.hasActiveSession!==U.hasActiveSession)return W.hasActiveSession?-1:1;if(W.hasActiveSession&&U.hasActiveSession)return U.lastUpdatedAt-W.lastUpdatedAt;const L=(I.label||I.branch||I.name||I.path||"").toLowerCase(),M=(R.label||R.branch||R.name||R.path||"").toLowerCase();return L.localeCompare(M)});(t.isVSCode?[]:_).forEach(I=>{const R=ws(I.path)??I.path,B=t.gitBranches.get(R)?.trim()||null,D=I.branch?.trim()||null,U=!!(B&&D&&I.label&&iu(I.label)===iu(D))?B:I.label||I.name||ho(R,t.homeDirectory)||R;y.push({id:`worktree:${R}`,label:U,branch:B||D,description:Pa(R,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:I,directory:R,folderScopeKey:R,sessions:j.get(R)??[]})});const F=j.get(S)??[];return F.length>0&&y.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&u?Hc(u):null,sessions:F}),y},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:o,buildGroupedSessions:a}},i2=t=>{const e=gt.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:o,sessionSearchContainerRef:a}=t;let c,l;e[0]!==n||e[1]!==o?(c=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.select()});return()=>window.cancelAnimationFrame(m)},l=[n,o],e[0]=n,e[1]=o,e[2]=c,e[3]=l):(c=e[2],l=e[3]),i.useEffect(c,l);let d,f;e[4]!==n||e[5]!==a||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=u=>{a.current&&(a.current.contains(u.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},f=[n,r,a],e[4]=n,e[5]=a,e[6]=r,e[7]=d,e[8]=f):(d=e[7],f=e[8]),i.useEffect(d,f)},o2=t=>{const e=gt.c(42),{t:n}=yt(),[r,o]=i.useState(null),a=i.useRef(null);let c,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>()=>{a.current&&clearTimeout(a.current)},l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),i.useEffect(c,l);let d;e[2]!==t?(d=(W,U,L)=>{const M=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(L&&L!==t.activeProjectId&&t.setActiveProjectIdOnly(L),U&&U!==t.currentDirectory&&t.setDirectory(U,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),W===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(W),M();return}t.setCurrentSession(W,U??null),t.onSessionSelected?.(W),M()},e[2]=t,e[3]=d):d=e[3];const f=d;let m;e[4]!==t?(m=(W,U)=>{t.setEditingId(W),t.setEditTitle(U)},e[4]=t,e[5]=m):m=e[5];const u=m;let p;e[6]!==t?(p=async W=>{if(!t.editingId)return;const U=(W??t.editTitle).trim();U&&await t.updateSessionTitle(t.editingId,U),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=p):p=e[7];const x=p;let b;e[8]!==t?(b=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=b):b=e[9];const w=b;let g;e[10]!==t||e[11]!==n?(g=async W=>{const U=await t.shareSession(W.id);U&&U.share?.url?le.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):le.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=g):g=e[12];const h=g;let k;e[13]!==n?(k=(W,U)=>{gr(W).then(L=>{if(!L.ok){le.error(n("sessions.sidebar.session.share.copyUrlError"));return}o(U),a.current&&clearTimeout(a.current),a.current=window.setTimeout(()=>{o(null),a.current=null},2e3)}).catch(()=>{le.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=k):k=e[14];const j=k;let S;e[15]!==t||e[16]!==n?(S=async W=>{await t.unshareSession(W)?le.success(n("sessions.sidebar.session.unshare.success")):le.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=S):S=e[17];const N=S;let C;e[18]!==t.childrenMap?(C=W=>{const U=[],L=M=>{(t.childrenMap.get(M)??[]).forEach(ie=>{U.push(ie),L(ie.id)})};return L(W),U},e[18]=t.childrenMap,e[19]=C):C=e[19];const y=C,P=l2;let _;e[20]!==t||e[21]!==y||e[22]!==n?(_=async(W,U,L)=>{const M=U?.archivedBucket===!0||U?.hardDelete===!0,ee=L?.descendantIds??P(y(W.id),M).map(c2);if(ee.length===0){(M?await t.deleteSession(W.id):await t.archiveSession(W.id))?le.success(n(M?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):le.error(n(M?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const ie=[W.id,...ee];if(M){const{deletedIds:J,failedIds:re}=await t.deleteSessions(ie);if(re.length===0){const oe=J.length;le.success(oe===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:oe}):n("sessions.sidebar.bulkActions.deletedPlural",{count:oe}))}else le.error(n("sessions.sidebar.session.delete.error"));return}const{archivedIds:te,failedIds:H}=await t.archiveSessions(ie);te.length>0&&le.success(te.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:te.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:te.length})),H.length>0&&le.error(H.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:H.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:H.length}))},e[20]=t,e[21]=y,e[22]=n,e[23]=_):_=e[23];const v=_;let F;e[24]!==t||e[25]!==y||e[26]!==v?(F=(W,U)=>{const L=U?.archivedBucket===!0||U?.hardDelete===!0,M=P(y(W.id),L).map(d2);if(!t.showDeletionDialog||U?.skipConfirm===!0){v(W,U,{descendantIds:M});return}t.setDeleteSessionConfirm({session:W,descendantCount:M.length,descendantIds:M,archivedBucket:L})},e[24]=t,e[25]=y,e[26]=v,e[27]=F):F=e[27];const I=F;let R;e[28]!==t||e[29]!==v?(R=async()=>{if(!t.deleteSessionConfirm)return;const{session:W,archivedBucket:U,descendantIds:L}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await v(W,{archivedBucket:U},{descendantIds:L})},e[28]=t,e[29]=v,e[30]=R):R=e[30];const B=R;let D;return e[31]!==B||e[32]!==r||e[33]!==w||e[34]!==j||e[35]!==I||e[36]!==x||e[37]!==u||e[38]!==f||e[39]!==h||e[40]!==N?(D={copiedSessionId:r,handleSessionSelect:f,handleSessionDoubleClick:u,handleSaveEdit:x,handleCancelEdit:w,handleShareSession:h,handleCopyShareUrl:j,handleUnshareSession:N,handleDeleteSession:I,confirmDeleteSession:B},e[31]=B,e[32]=r,e[33]=w,e[34]=j,e[35]=I,e[36]=x,e[37]=u,e[38]=f,e[39]=h,e[40]=N,e[41]=D):D=e[41],D};function a2(t){return!t.time?.archived}function l2(t,e){return e?t:t.filter(a2)}function c2(t){return t.id}function d2(t){return t.id}const u2=(t,e)=>{const n=new Set(t.map(a=>a.id));let r=!1;const o=new Set;return e.forEach(a=>{if(n.has(a)){o.add(a);return}r=!0}),r?o:e},f2=["project:active:","project:archived:","recent:active:","recent:archived:"],m2=t=>{const{isVSCode:e,hasAuthoritativeGlobalSessions:n,safeStorage:r,keys:o,sessions:a,setPinnedSessionIds:c,groupOrderByProject:l,activeSessionByProject:d,collapsedGroups:f,setExpandedParents:m,setCollapsedProjects:u}=t,p=i.useRef(null),x=i.useRef(null),b=i.useCallback(()=>{if(e)return;const g=x.current;if(x.current=null,p.current=null,!g)return;const{projects:h}=Ds.getState(),k=h.map(j=>({...j,sidebarCollapsed:g.has(j.id)}));yc({projects:k}).catch(()=>{})},[e]),w=i.useCallback(g=>{typeof window>"u"||e||(x.current=g,p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{b()},700))},[e,b]);return i.useEffect(()=>()=>{typeof window<"u"&&p.current!==null&&window.clearTimeout(p.current),p.current=null,x.current=null},[]),i.useEffect(()=>{try{const g=r.getItem(o.sessionExpanded);if(g){const k=JSON.parse(g);Array.isArray(k)&&m(new Set(k.filter(j=>typeof j=="string")))}else{const k=r.getItem(o.sessionExpandedLegacy);if(k){try{const j=JSON.parse(k);if(Array.isArray(j)){const S=new Set;if(j.forEach(N=>{typeof N!="string"||N.length===0||f2.forEach(C=>S.add(`${C}${N}`))}),S.size>0){m(S);try{r.setItem(o.sessionExpanded,JSON.stringify(Array.from(S)))}catch{}}}}catch{}try{r.removeItem?.(o.sessionExpandedLegacy)}catch{}}}const h=r.getItem(o.projectCollapse);if(h){const k=JSON.parse(h);Array.isArray(k)&&u(new Set(k.filter(j=>typeof j=="string")))}}catch{}},[o.projectCollapse,o.sessionExpanded,o.sessionExpandedLegacy,r,u,m]),i.useEffect(()=>{n&&c(g=>u2(a,g))},[n,a,c]),i.useEffect(()=>{try{const g=Object.fromEntries(l.entries());r.setItem(o.groupOrder,JSON.stringify(g))}catch{}},[l,o.groupOrder,r]),i.useEffect(()=>{try{const g=Object.fromEntries(d.entries());r.setItem(o.projectActiveSession,JSON.stringify(g))}catch{}},[d,o.projectActiveSession,r]),i.useEffect(()=>{try{r.setItem(o.groupCollapse,JSON.stringify(Array.from(f)))}catch{}},[f,o.groupCollapse,r]),{scheduleCollapsedProjectsPersist:w}},h2=t=>{const{normalizedProjects:e,gitRepoStatus:n,setProjectRepoStatus:r,setProjectRootBranches:o}=t,{git:a}=nr(),c=yn(u=>u.ensureStatus);i.useEffect(()=>{if(!a||e.length===0){r(new Map);return}e.forEach(u=>{c(u.normalizedPath,a)})},[e,a,c,r]),i.useEffect(()=>{const u=new Map;e.forEach(p=>{u.set(p.id,n.get(p.normalizedPath)?.isGitRepo??null)}),r(u)},[e,n,r]);const l=i.useMemo(()=>e.map(u=>{const p=n.get(u.normalizedPath)?.branch??"";return`${u.id}:${p}`}).join("|"),[e,n]),d=i.useRef(new Map),f=i.useRef(new Map),m=5*6e4;i.useEffect(()=>{let u=!1;const p=setTimeout(()=>{(async()=>{const b=new Set(e.map(S=>S.id));for(const S of d.current.keys())b.has(S)||(d.current.delete(S),f.current.delete(S));const w=Date.now(),g=e.filter(S=>{const N=n.get(S.normalizedPath);if(N?.isGitRepo===!1)return d.current.delete(S.id),f.current.delete(S.id),!1;if(N?.isGitRepo!==!0||N.branch===null)return!1;const C=N.branch.trim(),y=`${S.normalizedPath}\0${C}`,P=d.current.get(S.id);if(P===y){const _=f.current.get(S.id);return _&&(_.at=w),!1}return!(P!==void 0&&w-(f.current.get(S.id)?.at??0)<m)});if(g.length===0)return;const h=await Zm(g,2,async S=>{const N=n.get(S.normalizedPath)?.branch?.trim()??"",C=`${S.normalizedPath}\0${N}`,y=await Xa(S.normalizedPath,N?{knownBranch:N}:void 0).catch(()=>null);return{id:S.id,inputKey:C,branch:y}});if(u)return;const k=h.filter(S=>S.branch);if(k.length===0)return;const j=Date.now();o(S=>{const N=new Map(S);return k.forEach(({id:C,branch:y})=>{y&&N.set(C,y)}),N}),k.forEach(({id:S,inputKey:N,branch:C})=>{d.current.set(S,N),C&&f.current.set(S,{branch:C,at:j})})})()},150);return()=>{u=!0,clearTimeout(p)}},[e,l,n,o])},p2=t=>{const e=gt.c(7),{ownership:n}=t;let r;e[0]!==n?(r=d=>n.sessionsByProject.get(d)??[],e[0]=n,e[1]=r):r=e[1];const o=r;let a;e[2]!==n?(a=d=>n.archivedSessionsByProject.get(d)??[],e[2]=n,e[3]=a):a=e[3];const c=a;let l;return e[4]!==c||e[5]!==o?(l={getSessionsForProject:o,getArchivedSessionsForProject:c},e[4]=c,e[5]=o,e[6]=l):l=e[6],l},g2=t=>{const e=gt.c(10),{isSessionsLoading:n,hasAuthoritativeGlobalSessions:r,isWorktreeTopologyLoading:o,normalizedProjects:a,ownership:c,availableWorktreesByProject:l,unresolvedWorktreeProjectPaths:d,cleanupSessions:f}=t;let m,u;e[0]!==l||e[1]!==f||e[2]!==r||e[3]!==n||e[4]!==o||e[5]!==a||e[6]!==c||e[7]!==d?(m=()=>{if(n||!r||o||c.bySessionId.size===0)return;const p=new Map;c.sessionsByScope.forEach((x,b)=>{p.set(b,new Set(x))}),a.forEach(x=>{if(d.has(x.normalizedPath))return;const b=Hc(x.normalizedPath),w=c.archivedSessionsByProject.get(x.id)??[];p.set(b,new Set(w.map(x2))),p.has(x.normalizedPath)||p.set(x.normalizedPath,new Set);for(const g of l.get(x.normalizedPath)??[]){const h=ws(g.path);h&&!p.has(h)&&p.set(h,new Set)}}),p.forEach((x,b)=>{f(b,x)})},u=[l,f,r,o,n,a,c,d],e[0]=l,e[1]=f,e[2]=r,e[3]=n,e[4]=o,e[5]=a,e[6]=c,e[7]=d,e[8]=m,e[9]=u):(m=e[8],u=e[9]),i.useEffect(m,u)};function x2(t){return t.id}const b2=(t,e)=>t?e.kind!==t.kind?e.kind==="project":e.projectRoot.length!==t.projectRoot.length?e.projectRoot.length>t.projectRoot.length:e.projectId.localeCompare(t.projectId)<0:!0,jf=(t,e,n)=>{b2(t.get(e),n)&&t.set(e,n)},w2=t=>{const e=t;return ws(e.directory)??ws(e.project?.worktree)},y2=t=>{if(t==="/"||/^[A-Z]:$/.test(t))return null;const e=t.lastIndexOf("/");return e<0?null:e===0?"/":e===2&&/^[A-Z]:\//.test(t)?t.slice(0,2):t.slice(0,e)},v2=(t,e,n,r,o=[])=>{const a=new Map,c=new Map;for(const b of e){const w=ws(b.normalizedPath);if(!w)continue;const g=c.get(w);(!g||b.id.localeCompare(g.id)<0)&&c.set(w,b),jf(a,w,{projectId:b.id,projectRoot:w,scopeDirectory:w,kind:"project"})}if(!r)for(const[b,w]of n){const g=ws(b),h=g?c.get(g):void 0;if(!(!h||!g))for(const k of w){const j=ws(k.path);j&&jf(a,j,{projectId:h.id,projectRoot:g,scopeDirectory:j,kind:"worktree"})}}const l=new Map,d=new Map,f=new Map,m=new Map,u=new Map,p=b=>{if(!b)return null;if(l.has(b))return l.get(b)??null;if(r){const k=a.get(b)??null;return l.set(b,k),k}const w=[];let g=b,h=null;for(;g;){if(l.has(g)){h=l.get(g)??null;break}if(w.push(g),h=a.get(g)??null,h)break;g=y2(g)}for(const k of w)l.set(k,h);return h},x=(b,w,g)=>{for(const h of b){const k=p(w2(h));if(!k)continue;d.set(h.id,k);const j=w.get(k.projectId);if(j?j.push(h):w.set(k.projectId,[h]),!g)continue;const S=g.get(k.scopeDirectory);S?S.add(h.id):g.set(k.scopeDirectory,new Set([h.id]))}};return x(t,f,u),x(o,m),{bySessionId:d,sessionsByProject:f,archivedSessionsByProject:m,sessionsByScope:u,directoryResolutions:l.size}},j2=t=>{const e=gt.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[c,l]=i.useState(a);let d;e[1]!==n||e[2]!==o?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(p=>{const x=p.target.dataset.projectId;x&&l(b=>{const w=new Set(b);return p.isIntersecting?w.delete(x):w.add(x),w})})},{threshold:0});return o.current.forEach(u=>{u&&m.observe(u)}),()=>m.disconnect()},e[1]=n,e[2]=o,e[3]=d):d=e[3];let f;return e[4]!==n||e[5]!==o||e[6]!==r?(f=[n,o,r],e[4]=n,e[5]=o,e[6]=r,e[7]=f):f=e[7],i.useEffect(d,f),c},S2=t=>{const e=gt.c(10),{open:n,onOpenChange:r,project:o,onSave:a}=t;let c;e[0]!==a||e[1]!==n||e[2]!==o?(c=n&&o?s.jsx(cb,{project:o,onIdentitySave:a}):null,e[0]=a,e[1]=n,e[2]=o,e[3]=c):c=e[3];let l;e[4]!==c?(l=s.jsx(Vs,{className:"w-full max-w-2xl gap-0 overflow-hidden p-0",children:s.jsx(On,{outerClassName:"max-h-[min(90vh,48rem)]",className:"w-full bg-background",children:s.jsx("div",{className:"w-full p-3 sm:p-6 sm:pt-8",children:c})})}),e[4]=c,e[5]=l):l=e[5];let d;return e[6]!==r||e[7]!==n||e[8]!==l?(d=s.jsx(_s,{open:n,onOpenChange:r,children:l}),e[6]=r,e[7]=n,e[8]=l,e[9]=d):d=e[9],d},N2=`**Help shape what OpenChamber becomes next!**
|
|
172
|
+
|
|
173
|
+
Hey 👋,
|
|
174
|
+
|
|
175
|
+
OpenChamber has grown mostly through word of mouth, GitHub issues, Discord feedback, and people telling me what is broken, confusing, or surprisingly useful.
|
|
176
|
+
|
|
177
|
+
I'm planning the next chapter now - mobile, better remote access, a tighter VS Code ↔ desktop/web/mobile flow, and more, but before building too much, I want to hear from the people actually using it.
|
|
178
|
+
|
|
179
|
+
I'm doing a round of short 1-on-1 calls. No sales pitch, no formal script - just a real conversation about how you use OpenChamber, what you love, what frustrates you, and what would make it much more valuable.
|
|
180
|
+
|
|
181
|
+
You can book a call or use the short survey below.
|
|
182
|
+
|
|
183
|
+
What you get:
|
|
184
|
+
|
|
185
|
+
- A direct chance to influence the roadmap
|
|
186
|
+
- Your pain points and feature requests prioritized with more context
|
|
187
|
+
- A Power User role in Discord for people helping shape the product
|
|
188
|
+
- My genuine thanks for helping make OpenChamber better
|
|
189
|
+
|
|
190
|
+
**This project is what it is because of your feedback. Thank you, genuinely.**
|
|
191
|
+
|
|
192
|
+
I'll remove this button in 10 days 🙂`;function k2(t){const e=gt.c(25),{open:n,onOpenChange:r}=t,{t:o}=yt();let a;e[0]!==o?(a=o("shareOpinion.dialog.title"),e[0]=o,e[1]=a):a=e[1];let c;e[2]!==a?(c=s.jsx(Gs,{className:"sr-only",children:a}),e[2]=a,e[3]=c):c=e[3];let l;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx(ao,{content:N2,className:"typography-markdown-body",enableFileReferences:!1}),e[4]=l):l=e[4];let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(A,{name:"video-chat",className:"size-5 text-[var(--status-warning)]"}),e[5]=d):d=e[5];let f;e[6]!==o?(f=o("shareOpinion.actions.bookCall"),e[6]=o,e[7]=f):f=e[7];let m;e[8]!==f?(m=s.jsxs("button",{type:"button",className:"inline-flex items-center gap-2 rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-4 py-2.5 typography-ui-label text-foreground hover:bg-[var(--interactive-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",onClick:A2,children:[d,f]}),e[8]=f,e[9]=m):m=e[9];let u;e[10]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(A,{name:"survey",className:"size-5 text-[var(--pr-merged)]"}),e[10]=u):u=e[10];let p;e[11]!==o?(p=o("shareOpinion.actions.shortSurvey"),e[11]=o,e[12]=p):p=e[12];let x;e[13]!==p?(x=s.jsxs("button",{type:"button",className:"inline-flex items-center gap-2 rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-4 py-2.5 typography-ui-label text-foreground hover:bg-[var(--interactive-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",onClick:C2,children:[u,p]}),e[13]=p,e[14]=x):x=e[14];let b;e[15]!==m||e[16]!==x?(b=s.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[m,x]}),e[15]=m,e[16]=x,e[17]=b):b=e[17];let w;e[18]!==b||e[19]!==c?(w=s.jsxs(Vs,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[c,l,b]}),e[18]=b,e[19]=c,e[20]=w):w=e[20];let g;return e[21]!==r||e[22]!==n||e[23]!==w?(g=s.jsx(_s,{open:n,onOpenChange:r,children:w}),e[21]=r,e[22]=n,e[23]=w,e[24]=g):g=e[24],g}function C2(){si("https://forms.gle/cdMVKUGs5QuLWkA86")}function A2(){si("https://calendly.com/artmore/30min")}const D2=t=>{const e=gt.c(86),{folder:n,sessions:r,subFolderItems:o,isCollapsed:a,onToggle:c,onRename:l,onDelete:d,renderSessionNode:f,getRenderExtras:m,groupDirectory:u,projectId:p,mobileVariant:x,alwaysShowActions:b,isRenaming:w,renameDraft:g,onRenameDraftChange:h,onRenameSave:k,onRenameCancel:j,droppableRef:S,isDropTarget:N,onNewSession:C,onNewSubFolder:y,depth:P,hideActions:_,archivedBucket:v}=t,I=b===void 0?x===void 0?!1:x:b,R=w===void 0?!1:w,B=g===void 0?"":g,D=N===void 0?!1:N,W=P===void 0?0:P,U=_===void 0?!1:_,L=v===void 0?!1:v,{t:M}=yt(),[ee,ie]=i.useState(!1),[te,H]=i.useState(""),J=i.useRef(null),re=R||ee,oe=R?B:te;let ve;e[0]!==n.name?(ve=()=>{H(n.name),ie(!0)},e[0]=n.name,e[1]=ve):ve=e[1];const ne=ve;let ye;e[2]!==oe||e[3]!==n.name||e[4]!==R||e[5]!==l||e[6]!==k?(ye=()=>{const O=oe.trim();O&&O!==n.name&&l(O),R&&k&&k(),ie(!1),H("")},e[2]=oe,e[3]=n.name,e[4]=R,e[5]=l,e[6]=k,e[7]=ye):ye=e[7];const he=ye;let Fe;e[8]!==R||e[9]!==j?(Fe=()=>{R&&j&&j(),ie(!1),H("")},e[8]=R,e[9]=j,e[10]=Fe):Fe=e[10];const z=Fe;let K;e[11]!==R||e[12]!==h?(K=O=>{R&&h?h(O):H(O)},e[11]=R,e[12]=h,e[13]=K):K=e[13];const Y=K;let me,Ne;e[14]!==R?(me=()=>{if(!R)return;const O=()=>{const ae=J.current;ae&&(ae.focus(),ae.select())},se=requestAnimationFrame(O),Le=window.setTimeout(O,0);return()=>{cancelAnimationFrame(se),window.clearTimeout(Le)}},Ne=[R],e[14]=R,e[15]=me,e[16]=Ne):(me=e[15],Ne=e[16]),i.useEffect(me,Ne);const Be=a?"folder":"folder-open",Oe=W>0&&"ml-3";let pe;e[17]!==Oe?(pe=Pe("oc-folder",Oe),e[17]=Oe,e[18]=pe):pe=e[18];const Re=D&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ge;e[19]!==Re?(ge=Pe("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",Re),e[19]=Re,e[20]=ge):ge=e[20];const ce=re?void 0:c,Ce=re?void 0:"button",be=re?void 0:0;let ue;e[21]!==c||e[22]!==re?(ue=re?void 0:O=>{(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),c())},e[21]=c,e[22]=re,e[23]=ue):ue=e[23];let De;e[24]!==n.name||e[25]!==a||e[26]!==M?(De=a?M("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):M("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=a,e[26]=M,e[27]=De):De=e[27];const T=L?I?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let V;e[28]!==T?(V=Pe("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",T),e[28]=T,e[29]=V):V=e[29];const we=D?"text-primary":"text-muted-foreground";let E;e[30]!==we?(E=Pe("h-3.5 w-3.5 flex-shrink-0",we),e[30]=we,e[31]=E):E=e[31];let de;e[32]!==Be||e[33]!==E?(de=s.jsx(A,{name:Be,className:E}),e[32]=Be,e[33]=E,e[34]=de):de=e[34];let fe;e[35]!==oe||e[36]!==n.name||e[37]!==z||e[38]!==Y||e[39]!==he||e[40]!==a||e[41]!==D||e[42]!==re||e[43]!==r||e[44]!==M?(fe=re?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:P2,onMouseDown:I2,onSubmit:O=>{O.preventDefault(),he()},children:[s.jsx("input",{ref:J,value:oe,onChange:O=>Y(O.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:M("sessions.sidebar.folderItem.namePlaceholder"),onClick:R2,onPointerDown:E2,onMouseDown:M2,onKeyDown:O=>{if(O.key==="Escape"){O.stopPropagation(),z();return}(O.key===" "||O.key==="Enter")&&O.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:F2,onPointerDown:O2,onMouseDown:L2,children:s.jsx(A,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:O=>{O.stopPropagation(),z()},onPointerDown:B2,onMouseDown:V2,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:Pe("typography-ui-label font-semibold truncate",D?"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(A,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=oe,e[36]=n.name,e[37]=z,e[38]=Y,e[39]=he,e[40]=a,e[41]=D,e[42]=re,e[43]=r,e[44]=M,e[45]=fe):fe=e[45];let $;e[46]!==V||e[47]!==de||e[48]!==fe?($=s.jsxs("div",{className:V,children:[de,fe]}),e[46]=V,e[47]=de,e[48]=fe,e[49]=$):$=e[49];let ke;e[50]!==I||e[51]!==L||e[52]!==W||e[53]!==n.name||e[54]!==ne||e[55]!==U||e[56]!==d||e[57]!==C||e[58]!==y||e[59]!==re||e[60]!==M?(ke=!re&&(!U||L)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:Pe("flex items-center gap-0.5 transition-opacity",I?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",L&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!L&&C?s.jsx("button",{type:"button",onClick:O=>{O.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":M("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:M("sessions.sidebar.project.actions.newSession"),children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})}):null,!L&&y&&W===0?s.jsx("button",{type:"button",onClick:O=>{O.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":M("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:M("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(A,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,L?null:s.jsx("button",{type:"button",onClick:O=>{O.stopPropagation(),ne()},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":M("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(A,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:O=>{O.stopPropagation(),d()},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":L?M("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):M("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=I,e[51]=L,e[52]=W,e[53]=n.name,e[54]=ne,e[55]=U,e[56]=d,e[57]=C,e[58]=y,e[59]=re,e[60]=M,e[61]=ke):ke=e[61];let Ve;e[62]!==S||e[63]!==ge||e[64]!==ce||e[65]!==Ce||e[66]!==be||e[67]!==ue||e[68]!==De||e[69]!==$||e[70]!==ke?(Ve=s.jsxs("div",{ref:S,className:ge,onClick:ce,role:Ce,tabIndex:be,onKeyDown:ue,"aria-label":De,children:[$,ke]}),e[62]=S,e[63]=ge,e[64]=ce,e[65]=Ce,e[66]=be,e[67]=ue,e[68]=De,e[69]=$,e[70]=ke,e[71]=Ve):Ve=e[71];let Se;e[72]!==L||e[73]!==m||e[74]!==u||e[75]!==a||e[76]!==p||e[77]!==f||e[78]!==r||e[79]!==o||e[80]!==M?(Se=a?null:s.jsxs("div",{className:"pb-1 pl-2",children:[o,r.length>0?r.map(O=>f(O,0,u??null,p??null,L,void 0,"project",m?.(O))):o?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:M("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=L,e[73]=m,e[74]=u,e[75]=a,e[76]=p,e[77]=f,e[78]=r,e[79]=o,e[80]=M,e[81]=Se):Se=e[81];let q;return e[82]!==pe||e[83]!==Ve||e[84]!==Se?(q=s.jsxs("div",{className:pe,children:[Ve,Se]}),e[82]=pe,e[83]=Ve,e[84]=Se,e[85]=q):q=e[85],q},T2=i.memo(D2);function P2(t){return t.stopPropagation()}function I2(t){return t.stopPropagation()}function R2(t){return t.stopPropagation()}function E2(t){return t.stopPropagation()}function M2(t){return t.stopPropagation()}function F2(t){return t.stopPropagation()}function O2(t){return t.stopPropagation()}function L2(t){return t.stopPropagation()}function B2(t){return t.stopPropagation()}function V2(t){return t.stopPropagation()}const _2=t=>{const e=gt.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:o,children:a}=t,c=`session-drag:${n}`;let l;e[0]!==r||e[1]!==n||e[2]!==o?(l={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:o},e[0]=r,e[1]=n,e[2]=o,e[3]=l):l=e[3];let d;e[4]!==c||e[5]!==l?(d={id:c,data:l},e[4]=c,e[5]=l,e[6]=d):d=e[6];const{attributes:f,listeners:m,setNodeRef:u,isDragging:p}=op(d);let x;e[7]!==m?(x=h=>{h.stopPropagation(),m?.onPointerDown&&m.onPointerDown(h)},e[7]=m,e[8]=x):x=e[8];const b=x,w=p?"opacity-30":void 0;let g;return e[9]!==f||e[10]!==a||e[11]!==b||e[12]!==u||e[13]!==w?(g=s.jsx("div",{ref:u,...f,onPointerDown:b,className:w,children:a}),e[9]=f,e[10]=a,e[11]=b,e[12]=u,e[13]=w,e[14]=g):g=e[14],g},$2=t=>{const e=gt.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 c;e[2]!==o||e[3]!==a?(c={id:o,data:a},e[2]=o,e[3]=a,e[4]=c):c=e[4];const{setNodeRef:l,isOver:d}=ip(c);let f;e[5]!==r||e[6]!==d||e[7]!==l?(f=r(l,d),e[5]=r,e[6]=d,e[7]=l,e[8]=f):f=e[8];let m;return e[9]!==f?(m=s.jsx(s.Fragment,{children:f}),e[9]=f,e[10]=m):m=e[10],m},z2=t=>{const e=gt.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:o,children:a}=t;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={activationConstraint:{distance:8}},e[0]=c):c=e[0];const l=ja(Do(Sa,c)),[d,f]=i.useState(null),[m,u]=i.useState("Session"),[p,x]=i.useState(null),[b,w]=i.useState(null);if(!n){let y;return e[1]!==a?(y=s.jsx(s.Fragment,{children:a}),e[1]=a,e[2]=y):y=e[2],y}let g;e[3]!==o?(g=y=>{f(null),x(null),w(null);const{active:P,over:_}=y;if(!_)return;const v=P.data.current,F=_.data.current;v?.type==="session"&&v.sessionId&&F?.type==="folder"&&F.folderId&&o(v.sessionId,F.folderId)},e[3]=o,e[4]=g):g=e[4];const h=g;let k,j;e[5]===Symbol.for("react.memo_cache_sentinel")?(k=y=>{const P=y.active.data.current;if(P?.type==="session"&&P.sessionId){f(P.sessionId),u(P.sessionTitle??"Session");const _=y.active.rect.current.initial?.width,v=y.active.rect.current.initial?.height;x(typeof _=="number"?_:null),w(typeof v=="number"?v:null)}},j=()=>{f(null),x(null),w(null)},e[5]=k,e[6]=j):(k=e[5],j=e[6]);let S;e[7]!==b||e[8]!==d||e[9]!==m||e[10]!==p||e[11]!==r?(S=d&&r?s.jsxs("div",{style:{width:p?`${p}px`:"auto",height:b?`${b}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(A,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=b,e[8]=d,e[9]=m,e[10]=p,e[11]=r,e[12]=S):S=e[12];let N;e[13]!==S?(N=s.jsx(Yl,{children:S}),e[13]=S,e[14]=N):N=e[14];let C;return e[15]!==a||e[16]!==h||e[17]!==l||e[18]!==N?(C=s.jsxs(Na,{sensors:l,collisionDetection:ka,onDragStart:k,onDragCancel:j,onDragEnd:h,children:[a,N]}),e[15]=a,e[16]=h,e[17]=l,e[18]=N,e[19]=C):C=e[19],C},Zi=(t,e,n)=>{if(!e)return;const r=o=>{let a=o.session.id===e;for(const c of o.children)a=r(c)||a;return a&&n.add(o.session.id),a};for(const o of t)r(o)},Yr=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Yr(n,e))return!0;return!1},_a=t=>t.children.length===0?"":t.children.map(n=>n.children.length===0?n.session.id:`${n.session.id}:${_a(n)}`).join("|"),zo=(t,e,n,r)=>{if(!e)return null;const o=r?"archived":"active";let a=null;const c=l=>{if(`${n}:${o}:${l.session.id}`===e)return a=l.session.id,!0;for(const f of l.children)if(c(f))return!0;return!1};return t.forEach(l=>c(l)),a},dr=fo()(xc(t=>({displayMode:"minimal",showRecentSection:!0,showArchivedSessions:!1,projectSortOrder:"recent",setDisplayMode:e=>t({displayMode:e}),setShowRecentSection:e=>t({showRecentSection:e}),setShowArchivedSessions:e=>t({showArchivedSessions:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection})),toggleArchivedSessions:()=>t(e=>({showArchivedSessions:!e.showArchivedSessions})),setProjectSortOrder:e=>t({projectSortOrder:e})}),{name:"session-display-mode",version:2,migrate:(t,e)=>{const n=t??{};return e<1?{...n,displayMode:"minimal",projectSortOrder:"recent"}:e<2?{...n,projectSortOrder:"recent"}:n}})),W2=50,U2=30,H2=28,Ki=(t,e)=>e?t.sessions.some(n=>Yr(n,e)):!1,G2=(t,e,n)=>{const r=o=>{const a=o.session.id;return e.has(a)!==n.has(a)?!0:o.children.some(r)};return t.sessions.some(r)},K2=(t,e,n)=>{const r=o=>{const a=o.session.id;return e.get(a)!==n.get(a)?!0:o.children.some(r)};return t.sessions.some(r)},q2=(t,e,n)=>{const r=t.isArchivedBucket?"archived":"active",o=a=>{const c=`project:${r}:${a.session.id}`;return e.has(c)!==n.has(c)?!0:a.children.some(o)};return t.sessions.some(o)},Y2=(t,e,n)=>{const r=o=>{const a=o.session.id;return(e.get(a)??o.session)!==(n.get(a)??o.session)?!0:o.children.some(r)};return t.sessions.some(r)},Sf=t=>{if(t.projectId)return t.projectRepoStatus.has(t.projectId)?t.projectRepoStatus.get(t.projectId):void 0},Q2=(t,e)=>{if(t.group!==e.group||t.groupKey!==e.groupKey||t.projectId!==e.projectId||t.hideGroupLabel!==e.hideGroupLabel||t.compactBodyPadding!==e.compactBodyPadding||t.groupSearchDataByGroup!==e.groupSearchDataByGroup||t.visibleSessionCount!==e.visibleSessionCount||t.collapsedGroups!==e.collapsedGroups&&t.collapsedGroups.has(t.groupKey)!==e.collapsedGroups.has(e.groupKey)||t.projectRepoStatus!==e.projectRepoStatus&&Sf(t)!==Sf(e)||t.pinnedSessionIds!==e.pinnedSessionIds&&G2(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.expandedParents!==e.expandedParents&&q2(e.group,t.expandedParents,e.expandedParents)||t.sessionOrderIndex!==e.sessionOrderIndex&&K2(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.currentSessionId!==e.currentSessionId&&(Ki(t.group,t.currentSessionId)||Ki(e.group,e.currentSessionId))||t.editingId!==e.editingId&&(Ki(t.group,t.editingId)||Ki(e.group,e.editingId))||t.editTitle!==e.editTitle&&(Ki(t.group,t.editingId)||Ki(e.group,e.editingId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=zo(t.group.sessions,t.openSidebarMenuKey,"project",!!t.group.isArchivedBucket),r=zo(e.group.sessions,e.openSidebarMenuKey,"project",!!e.group.isArchivedBucket);if(n||r)return!1}if(t.liveSessionById!==e.liveSessionById&&Y2(e.group,t.liveSessionById,e.liveSessionById))return!1;if(t.prVisualStateByDirectoryBranch!==e.prVisualStateByDirectoryBranch){const n=t.group?.directory&&t.group?.branch?t.prVisualStateByDirectoryBranch.get(`${t.group.directory}::${t.group.branch.trim()}`):void 0,r=e.group?.directory&&e.group?.branch?e.prVisualStateByDirectoryBranch.get(`${e.group.directory}::${e.group.branch.trim()}`):void 0;if(!Object.is(n,r))return!1}return t.hasSessionSearchQuery===e.hasSessionSearchQuery&&t.normalizedSessionSearchQuery===e.normalizedSessionSearchQuery&&t.hideDirectoryControls===e.hideDirectoryControls&&t.collapsedFolderIds===e.collapsedFolderIds&&t.toggleFolderCollapse===e.toggleFolderCollapse&&t.renameFolder===e.renameFolder&&t.deleteFolder===e.deleteFolder&&t.showDeletionDialog===e.showDeletionDialog&&t.setDeleteFolderConfirm===e.setDeleteFolderConfirm&&t.renderSessionNode===e.renderSessionNode&&t.lastRepoStatus===e.lastRepoStatus&&t.showMoreGroupSessions===e.showMoreGroupSessions&&t.resetGroupSessionLimit===e.resetGroupSessionLimit&&t.mobileVariant===e.mobileVariant&&t.alwaysShowActions===e.alwaysShowActions&&t.activeProjectId===e.activeProjectId&&t.setActiveProjectIdOnly===e.setActiveProjectIdOnly&&t.setActiveMainTab===e.setActiveMainTab&&t.setSessionSwitcherOpen===e.setSessionSwitcherOpen&&t.openNewSessionDraft===e.openNewSessionDraft&&t.addSessionToFolder===e.addSessionToFolder&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.renamingFolderId===e.renamingFolderId&&t.renameFolderDraft===e.renameFolderDraft&&t.setRenameFolderDraft===e.setRenameFolderDraft&&t.setRenamingFolderId===e.setRenamingFolderId&&t.onToggleCollapsedGroup===e.onToggleCollapsedGroup&&t.dragHandleProps===e.dragHandleProps&&t.scrollContainerRef===e.scrollContainerRef};function J2(t){const{t:e}=yt(),{group:n,groupKey:r,projectId:o,hideGroupLabel:a,hasSessionSearchQuery:c,normalizedSessionSearchQuery:l,groupSearchDataByGroup:d,visibleSessionCount:f,collapsedGroups:m,hideDirectoryControls:u,collapsedFolderIds:p,toggleFolderCollapse:x,renameFolder:b,deleteFolder:w,showDeletionDialog:g,setDeleteFolderConfirm:h,renderSessionNode:k,projectRepoStatus:j,lastRepoStatus:S,showMoreGroupSessions:N,resetGroupSessionLimit:C,mobileVariant:y,alwaysShowActions:P,activeProjectId:_,setActiveProjectIdOnly:v,setActiveMainTab:F,setSessionSwitcherOpen:I,openNewSessionDraft:R,addSessionToFolder:B,createFolderAndStartRename:D,renamingFolderId:W,renameFolderDraft:U,setRenameFolderDraft:L,setRenamingFolderId:M,pinnedSessionIds:ee,expandedParents:ie,sessionOrderIndex:te,currentSessionId:H,editingId:J,openSidebarMenuKey:re,prVisualStateByDirectoryBranch:oe,onToggleCollapsedGroup:ve,dragHandleProps:ne,compactBodyPadding:ye=!1,scrollContainerRef:he}=t,Fe=i.useCallback((Me,ft)=>{const at=te.get(Me.session.id),Nt=te.get(ft.session.id);if(at!==void 0||Nt!==void 0){if(at===void 0)return 1;if(Nt===void 0)return-1;if(at!==Nt)return at-Nt}return eo(Me.session,ft.session,ee)},[ee,te]),z=c?d.get(n):null,K=dr(Me=>Me.displayMode),Y=Zn(Me=>Me.foldersMap),me=K==="minimal"&&!Cr(),Ne=c?!1:m.has(r),Be=u?10:5,_e=Math.max(Be,f??Be),Oe=c?z?.groupMatches===!0:!1,pe=c,Re=i.useMemo(()=>[...pe?z?.filteredNodes??[]:n.sessions].sort(Fe),[Fe,n.sessions,z?.filteredNodes,pe]),ge=n.folderScopeKey??ws(n.directory??null),ce=i.useMemo(()=>ge?Y[ge]??[]:[],[ge,Y]),Ce=i.useMemo(()=>{const Me=new Map,ft=at=>{at.forEach(Nt=>{Me.set(Nt.session.id,Nt),Nt.children.length>0&&ft(Nt.children)})};return ft(Re),Me},[Re]),be=i.useMemo(()=>ce.map(Me=>{const ft=Me.sessionIds.map(at=>Ce.get(at)).filter(at=>!!at).sort(Fe);return{folder:Me,nodes:ft}}),[ce,Ce,Fe]),ue=i.useMemo(()=>{const Me=new Map(be.map(Pt=>[Pt.folder.id,Pt])),ft=new Map;for(const{folder:Pt}of be){if(!Pt.parentId)continue;const es=ft.get(Pt.parentId);es?es.push(Pt.id):ft.set(Pt.parentId,[Pt.id])}const at=new Map,Nt=Pt=>{const es=at.get(Pt);if(es!==void 0)return es;const xs=Me.get(Pt);if(!xs)return at.set(Pt,!1),!1;const Yt=ft.get(Pt)??[];if(n.isArchivedBucket&&xs.nodes.length===0){const ms=Yt.some(Ns=>Nt(Ns));return at.set(Pt,ms),ms}if(!c||xs.folder.name.toLowerCase().includes(l)||xs.nodes.length>0)return at.set(Pt,!0),!0;const Es=Yt.some(ms=>Nt(ms));return at.set(Pt,Es),Es};return be.filter(({folder:Pt})=>Nt(Pt.id))},[be,n.isArchivedBucket,c,l]),De=i.useMemo(()=>new Set(ue.flatMap(Me=>Me.folder.sessionIds)),[ue]),T=i.useMemo(()=>Re.filter(Me=>!De.has(Me.session.id)),[Re,De]),V=i.useMemo(()=>ue.filter(({folder:Me})=>!Me.parentId),[ue]),we="project",E=i.useMemo(()=>{const Me=new Set;return Zi(Re,H,Me),ue.forEach(({nodes:ft})=>{Zi(ft,H,Me)}),Me},[Re,ue,H]),de=i.useMemo(()=>{const Me=new Set;return Zi(Re,J,Me),ue.forEach(({nodes:ft})=>{Zi(ft,J,Me)}),Me},[Re,ue,J]),fe=i.useMemo(()=>{if(!re)return null;const Me=zo(Re,re,we,!!n.isArchivedBucket);if(Me)return Me;for(const{nodes:ft}of ue){const at=zo(ft,re,we,!!n.isArchivedBucket);if(at)return at}return null},[re,Re,ue,n.isArchivedBucket]),$=i.useCallback(Me=>{const ft=new WeakMap,at=Nt=>{ft.set(Nt,_a(Nt));for(const Pt of Nt.children)at(Pt)};return Me.forEach(at),ft},[]),ke=i.useMemo(()=>$(Re),[$,Re]),Ve=i.useMemo(()=>{const Me=new WeakMap;return ue.forEach(({nodes:ft})=>{ft.forEach(at=>Me.set(at,_a(at)))}),Me},[ue]),Se=i.useCallback(Me=>ke.get(Me)??Ve.get(Me)??"",[ke,Ve]),q=i.useCallback(Me=>({subtreeContainsActive:E,subtreeContainsEditing:de,menuOpenSessionId:fe,nodeStructureKey:Se(Me)}),[E,de,fe,Se]),O=T.length,se=n.isArchivedBucket||c?T:T.slice(0,_e),Le=O-se.length,ae=!n.isArchivedBucket&&!c&&O>Be&&Le===0,We=n.isArchivedBucket===!0&&!c&&se.length>=W2,Ye=n.isArchivedBucket!==!0&&!c&&se.length>=U2,Qe=We||Ye,st=n.isArchivedBucket?"archived":"active",pt=Qe&&se.some(Me=>{if(Me.children.length===0)return!1;const ft=`project:${st}:${Me.session.id}`;return ie.has(ft)}),jt=i.useRef(null),[Et,Rt]=i.useState(null),[Ut,ts]=i.useState(0),[,Kt]=i.useState(0);i.useEffect(()=>{if(!Qe)return;const Me=jt.current;if(!Me||typeof ResizeObserver>"u")return;const ft=new ResizeObserver(()=>Kt(at=>at+1));return ft.observe(Me),()=>ft.disconnect()},[Qe]),i.useLayoutEffect(()=>{if(!Qe){Et!==null&&Rt(null),Ut!==0&&ts(0);return}const Me=jt.current;if(!Me)return;let ft=Et;const at=he?.current??null;if(at&&at.contains(Me)){if(ft=at,ft!==Et){Rt(ft);return}}else if(!ft||!ft.contains(Me)){let Pt=Me.parentElement;for(;Pt;){const es=window.getComputedStyle(Pt);if(es.overflowY==="auto"||es.overflowY==="scroll"){ft=Pt;break}Pt=Pt.parentElement}if(ft!==Et){Rt(ft);return}}if(!ft)return;const Nt=Me.getBoundingClientRect().top-ft.getBoundingClientRect().top+ft.scrollTop;ts(Pt=>Math.abs(Pt-Nt)<1?Pt:Nt)});const is=Qe&&Et!==null,qt=ap({count:se.length,enabled:is,getScrollElement:()=>Et,initialOffset:()=>Et?.scrollTop??0,estimateSize:()=>H2,overscan:pt?20:8,scrollMargin:Ut,getItemKey:Me=>se[Me]?.session.id??Me}),Te=i.useCallback(Me=>{const ft=[],at=Nt=>{Nt.forEach(Pt=>{ft.push(Pt.session),Pt.children.length>0&&at(Pt.children)})};return at(Me),ft},[]),Ke=i.useMemo(()=>Te(Re),[Te,Re]),rt=i.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const Me=new Map,ft=new Map;for(const{folder:Nt}of ue){if(!Nt.parentId)continue;const Pt=ft.get(Nt.parentId)??[];Pt.push(Nt.id),ft.set(Nt.parentId,Pt)}const at=(Nt,Pt)=>{if(Pt.has(Nt))return[];Pt.add(Nt);const es=ue.find(({folder:Lt})=>Lt.id===Nt),xs=es?Te(es.nodes):[],Yt=ft.get(Nt)??[];for(const Lt of Yt)xs.push(...at(Lt,Pt));return xs};for(const{folder:Nt}of ue)Me.set(Nt.id,at(Nt.id,new Set));return Me},[ue,Te,n.isArchivedBucket]);if(c&&!Oe&&V.length===0&&T.length===0)return null;const vt=o&&j.has(o)?!!j.get(o):S,Je=ws(n.directory??null),St=n.branch?.trim()??null,Xe=Je&&St?oe.get(`${Je}::${St}`)??null:null,qe=!!(Xe&&n.branch),et=!Xe&&!n.isMain&&!!n.branch,Vt=Xe?.visualState??null,Ct=Xe&&Xe.state==="open"&&Xe.checks?e("sessions.sidebar.group.pr.checksPassed",{success:Xe.checks.success,total:Xe.checks.total}):null,Ht=Xe&&Xe.state==="open"&&Xe.checks?[Xe.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:Xe.checks.failure}):null,Xe.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:Xe.checks.pending}):null].filter(Me=>!!Me).join(", "):null,ss=Xe&&Xe.state==="open"?Xe.mergeableState==="blocked"||Xe.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):Xe.mergeableState==="clean"||Xe.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,Xt=Xe&&Xe.state==="open"&&Xe.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:Xe.mergeableState}):null,Ft=Xe?.base??null,_t=Xe?.head??null,hs=(()=>{if(!Xe)return n.branch&&Ab(n.branch,n.label)?{label:n.branch,color:null}:null;switch(Xe.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return Xe.canMerge===!0||Xe.mergeableState==="clean"||Xe.checks?.state==="success"?{label:e("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:e("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"};case"blocked":return{label:Xe.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked"),color:"var(--pr-blocked)"};case"draft":return{label:e("sessions.sidebar.group.pr.status.draft"),color:"var(--pr-draft)"};case"closed":return{label:e("sessions.sidebar.group.pr.status.closed"),color:"var(--pr-closed)"};default:return null}})(),Zt=hs?.color??(Vt?`var(--pr-${Vt})`:void 0),ns=Me=>{Me.preventDefault(),Me.stopPropagation();const ft=Xe?.url;ft&&si(ft)},gs=(Me,ft,at)=>{const Nt=ue.filter(({folder:xs})=>xs.parentId===Me.id),Pt=Nt.length>0?s.jsx(s.Fragment,{children:Nt.map(({folder:xs,nodes:Yt})=>gs(xs,Yt,at+1))}):void 0,es=rt.get(Me.id)??[];return s.jsx($2,{folderId:Me.id,children:(xs,Yt)=>s.jsx(T2,{folder:Me,sessions:ft,subFolderItems:Pt,isCollapsed:c?!1:p.has(Me.id),onToggle:()=>x(Me.id),onRename:Lt=>{ge&&b(ge,Me.id,Lt)},onDelete:()=>{if(n.isArchivedBucket){_r.requestDelete({sessions:es,mode:"session"});return}if(!ge)return;if(!g){w(ge,Me.id);return}const Lt=ue.filter(({folder:ms})=>ms.parentId===Me.id).length,Es=ft.length;h({scopeKey:ge,folderId:Me.id,folderName:Me.name,subFolderCount:Lt,sessionCount:Es})},renderSessionNode:k,getRenderExtras:Se?Lt=>({subtreeContainsActive:E,subtreeContainsEditing:de,menuOpenSessionId:fe,nodeStructureKey:Se(Lt),childRenderExtrasFor:q}):void 0,groupDirectory:n.directory,projectId:o,mobileVariant:y,alwaysShowActions:P,isRenaming:W===Me.id,renameDraft:W===Me.id?U:void 0,onRenameDraftChange:Lt=>L(Lt),onRenameSave:()=>{const Lt=U.trim();Lt&&ge&&b(ge,Me.id,Lt),M(null),L("")},onRenameCancel:()=>{M(null),L("")},droppableRef:xs,isDropTarget:Yt,depth:at,onNewSession:()=>{o&&o!==_&&v(o),F("chat"),y&&I(!1),R({directoryOverride:n.directory,targetFolderId:Me.id})},onNewSubFolder:at===0?()=>{ge&&D(ge,Me.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Me.id)},Mt=()=>V.map(({folder:Me,nodes:ft})=>gs(Me,ft,0)),Bt=!!(!n.isMain&&n.worktree),$t=P?Bt?"pr-14":"pr-7":me?Bt?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":Bt?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",os=s.jsxs(z2,{scopeKey:ge,hasFolders:ue.length>0,onSessionDroppedOnFolder:(Me,ft)=>{ge&&B(ge,ft,Me)},children:[Mt(),Qe?s.jsx("div",{ref:jt,children:is?s.jsx("div",{style:{height:qt.getTotalSize(),position:"relative"},children:qt.getVirtualItems().map(Me=>{const ft=se[Me.index];return ft?s.jsx("div",{"data-index":Me.index,ref:qt.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Me.start-Ut}px)`},children:k(ft,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsActive:E,subtreeContainsEditing:de,menuOpenSessionId:fe,nodeStructureKey:Se(ft),childRenderExtrasFor:q})},ft.session.id):null})}):se.map(Me=>k(Me,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsActive:E,subtreeContainsEditing:de,menuOpenSessionId:fe,nodeStructureKey:Se(Me),childRenderExtrasFor:q}))}):se.map(Me=>k(Me,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsActive:E,subtreeContainsEditing:de,menuOpenSessionId:fe,nodeStructureKey:Se(Me),childRenderExtrasFor:q})),O===0&&ue.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,Le>0?s.jsx("button",{type:"button",onClick:()=>N(r,se.length),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:e("sessions.sidebar.group.showMore")}):null,ae?s.jsx("button",{type:"button",onClick:()=>C(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:e("sessions.sidebar.group.showFewer")}):null]}),Gt=ye?"pb-2 pl-1":"pb-3 pl-4";return a?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:Pe("oc-group-body",Gt),children:os})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:Pe("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>ve(r),role:"button",tabIndex:0,onKeyDown:Me=>{(Me.key==="Enter"||Me.key===" ")&&(Me.preventDefault(),ve(r))},"aria-label":Ne?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!Ne,children:[s.jsx("div",{ref:ne?.setActivatorNodeRef,className:Pe("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",$t),...ne?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:qe&&Xe?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(At,{children:[s.jsx(Dt,{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(A,{name:"git-branch",className:Pe("h-3.5 w-3.5 shrink-0",P?"hidden":"group-hover/gh:hidden"),style:Zt?{color:Zt}:void 0}),s.jsx("span",{className:Pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",P?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Ne?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),Xe.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:Me=>Me.stopPropagation(),onClick:ns,children:["#",Xe.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Xe.number]})]})}),s.jsx(Tt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Ft||_t?s.jsx("div",{className:"text-muted-foreground truncate",children:Ft&&_t?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Ft}),s.jsx(A,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:_t})]}):s.jsx("span",{children:Ft??_t??""})}):null,Xt?s.jsx("div",{className:"text-muted-foreground truncate",children:Xt}):null,ss||Ct?s.jsxs("div",{className:"text-muted-foreground truncate",children:[ss??"",ss&&Ct?" • ":"",Ct??"",Ht?` (${Ht})`:""]}):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 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(A,{name:"archive",className:Pe("h-3.5 w-3.5 shrink-0 text-muted-foreground",P?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:Pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",P?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Ne?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Po(n.label,l)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(A,{name:"git-branch",className:Pe("h-3.5 w-3.5 shrink-0 text-muted-foreground",P?"hidden":"group-hover/gh:hidden"),style:Zt?{color:Zt}:void 0}),s.jsx("span",{className:Pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",P?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Ne?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Po(n.label,l)})]}):Po(n.label,l)}),et&&hs?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(A,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||vt?qe&&Xe?s.jsxs(At,{children:[s.jsx(Dt,{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(A,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:Zt?{color:Zt}:void 0})})}),s.jsx(Tt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Ft||_t?s.jsx("div",{className:"text-muted-foreground truncate",children:Ft&&_t?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Ft}),s.jsx(A,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:_t})]}):s.jsx("span",{children:Ft??_t??""})}):null,Xt?s.jsx("div",{className:"text-muted-foreground truncate",children:Xt}):null,ss||Ct?s.jsxs("div",{className:"text-muted-foreground truncate",children:[ss??"",ss&&Ct?" • ":"",Ct??"",Ht?` (${Ht})`:""]}):null]})})]}):s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Zt?{color:Zt}:void 0}):null,s.jsx("span",{className:Pe("min-w-0 truncate text-[11px] font-medium",!hs.color&&"text-muted-foreground/80"),style:hs.color?{color:hs.color}:void 0,children:hs.label})]}):null]})}),n.isArchivedBucket&&Ke.length>0?s.jsx("div",{className:Pe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",P?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Me=>{Me.stopPropagation(),_r.requestDelete({sessions:Ke,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:Pe("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",P?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Me=>{Me.stopPropagation(),_r.requestDelete({sessions:Ke,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:Pe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",P?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Me=>{Me.stopPropagation(),o&&o!==_&&v(o),F("chat"),y&&I(!1),R({directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(A,{name:"add",className:"h-4 w-4"})})}),s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),Ne?null:s.jsx("div",{className:Pe("oc-group-body",Gt),children:os})]})}const X2=i.memo(J2,Q2);function Z2(t){const e=gt.c(267),{t:n}=yt(),{hideDirectoryControls:r,showRecentControls:o,handleOpenDirectoryDialog:a,openNewSessionDraft:c,canOpenMultiRun:l,openMultiRunLauncher:d,headerActionIconClass:f,headerActionButtonClass:m,isSessionSearchOpen:u,setIsSessionSearchOpen:p,sessionSearchInputRef:x,sessionSearchQuery:b,setSessionSearchQuery:w,hasSessionSearchQuery:g,searchMatchCount:h,collapseAllProjects:k,expandAllProjects:j,openScheduledTasksDialog:S,selectionModeEnabled:N,onToggleSelectionMode:C}=t,y=dr(lN),P=dr(aN),_=dr(oN),v=dr(iN),F=dr(rN),I=dr(nN),R=dr(sN),B=dr(tN);let D;e[0]===Symbol.for("react.memo_cache_sentinel")?(D=Cr(),e[0]=D):D=e[0];const W=!D;if(r)return null;let U;e[1]!==n?(U=n("sessions.sidebar.header.actions.addProject"),e[1]=n,e[2]=U):U=e[2];let L;e[3]!==f?(L=s.jsx(A,{name:"folder-add",className:f}),e[3]=f,e[4]=L):L=e[4];let M;e[5]!==a||e[6]!==m||e[7]!==U||e[8]!==L?(M=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:m,"aria-label":U,children:L})}),e[5]=a,e[6]=m,e[7]=U,e[8]=L,e[9]=M):M=e[9];let ee;e[10]!==n?(ee=n("sessions.sidebar.header.actions.addProject"),e[10]=n,e[11]=ee):ee=e[11];let ie;e[12]!==ee?(ie=s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ee})}),e[12]=ee,e[13]=ie):ie=e[13];let te;e[14]!==M||e[15]!==ie?(te=s.jsxs(At,{children:[M,ie]}),e[14]=M,e[15]=ie,e[16]=te):te=e[16];let H;e[17]!==n?(H=n("sessions.sidebar.header.actions.newSession"),e[17]=n,e[18]=H):H=e[18];let J;e[19]!==f?(J=s.jsx(A,{name:"chat-new",className:f}),e[19]=f,e[20]=J):J=e[20];let re;e[21]!==m||e[22]!==c||e[23]!==H||e[24]!==J?(re=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:m,"aria-label":H,children:J})}),e[21]=m,e[22]=c,e[23]=H,e[24]=J,e[25]=re):re=e[25];let oe;e[26]!==n?(oe=n("sessions.sidebar.header.actions.newSession"),e[26]=n,e[27]=oe):oe=e[27];let ve;e[28]!==oe?(ve=s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:oe})}),e[28]=oe,e[29]=ve):ve=e[29];let ne;e[30]!==ve||e[31]!==re?(ne=s.jsxs(At,{children:[re,ve]}),e[30]=ve,e[31]=re,e[32]=ne):ne=e[32];let ye;e[33]!==n?(ye=n("sessions.sidebar.header.actions.newMultiRun"),e[33]=n,e[34]=ye):ye=e[34];const he=!l;let Fe;e[35]!==f?(Fe=s.jsx(zg,{className:f}),e[35]=f,e[36]=Fe):Fe=e[36];let z;e[37]!==m||e[38]!==d||e[39]!==ye||e[40]!==he||e[41]!==Fe?(z=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:d,className:m,"aria-label":ye,disabled:he,children:Fe})}),e[37]=m,e[38]=d,e[39]=ye,e[40]=he,e[41]=Fe,e[42]=z):z=e[42];let K;e[43]!==n?(K=n("sessions.sidebar.header.actions.newMultiRun"),e[43]=n,e[44]=K):K=e[44];let Y;e[45]!==K?(Y=s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:K})}),e[45]=K,e[46]=Y):Y=e[46];let me;e[47]!==z||e[48]!==Y?(me=s.jsxs(At,{children:[z,Y]}),e[47]=z,e[48]=Y,e[49]=me):me=e[49];let Ne;e[50]!==n?(Ne=n("sessions.sidebar.header.actions.scheduledTasks"),e[50]=n,e[51]=Ne):Ne=e[51];let Be;e[52]!==f?(Be=s.jsx(A,{name:"calendar-schedule",className:f}),e[52]=f,e[53]=Be):Be=e[53];let _e;e[54]!==m||e[55]!==S||e[56]!==Ne||e[57]!==Be?(_e=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:S,className:m,"aria-label":Ne,children:Be})}),e[54]=m,e[55]=S,e[56]=Ne,e[57]=Be,e[58]=_e):_e=e[58];let Oe;e[59]!==n?(Oe=n("sessions.sidebar.header.actions.scheduledTasks"),e[59]=n,e[60]=Oe):Oe=e[60];let pe;e[61]!==Oe?(pe=s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Oe})}),e[61]=Oe,e[62]=pe):pe=e[62];let Re;e[63]!==_e||e[64]!==pe?(Re=s.jsxs(At,{children:[_e,pe]}),e[63]=_e,e[64]=pe,e[65]=Re):Re=e[65];let ge;e[66]!==ne||e[67]!==me||e[68]!==Re||e[69]!==te?(ge=s.jsxs("div",{className:"flex items-center gap-1.5",children:[te,ne,me,Re]}),e[66]=ne,e[67]=me,e[68]=Re,e[69]=te,e[70]=ge):ge=e[70];let ce;e[71]!==p?(ce=()=>p(eN),e[71]=p,e[72]=ce):ce=e[72];let Ce;e[73]!==n?(Ce=n("sessions.sidebar.header.actions.searchSessions"),e[73]=n,e[74]=Ce):Ce=e[74];let be;e[75]!==f?(be=s.jsx(A,{name:"search",className:f}),e[75]=f,e[76]=be):be=e[76];let ue;e[77]!==m||e[78]!==u||e[79]!==ce||e[80]!==Ce||e[81]!==be?(ue=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ce,className:m,"aria-label":Ce,"aria-expanded":u,children:be})}),e[77]=m,e[78]=u,e[79]=ce,e[80]=Ce,e[81]=be,e[82]=ue):ue=e[82];let De;e[83]!==n?(De=n("sessions.sidebar.header.actions.searchSessions"),e[83]=n,e[84]=De):De=e[84];let T;e[85]!==De?(T=s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:De})}),e[85]=De,e[86]=T):T=e[86];let V;e[87]!==ue||e[88]!==T?(V=s.jsxs(At,{children:[ue,T]}),e[87]=ue,e[88]=T,e[89]=V):V=e[89];const we=N&&"bg-interactive-hover text-primary";let E;e[90]!==m||e[91]!==we?(E=Pe(m,we),e[90]=m,e[91]=we,e[92]=E):E=e[92];let de;e[93]!==N||e[94]!==n?(de=n(N?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[93]=N,e[94]=n,e[95]=de):de=e[95];let fe;e[96]!==f?(fe=s.jsx(A,{name:"checkbox-multiple",className:f}),e[96]=f,e[97]=fe):fe=e[97];let $;e[98]!==C||e[99]!==N||e[100]!==E||e[101]!==de||e[102]!==fe?($=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:C,className:E,"aria-label":de,"aria-pressed":N,children:fe})}),e[98]=C,e[99]=N,e[100]=E,e[101]=de,e[102]=fe,e[103]=$):$=e[103];let ke;e[104]!==N||e[105]!==n?(ke=n(N?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[104]=N,e[105]=n,e[106]=ke):ke=e[106];let Ve;e[107]!==ke?(Ve=s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ke})}),e[107]=ke,e[108]=Ve):Ve=e[108];let Se;e[109]!==$||e[110]!==Ve?(Se=s.jsxs(At,{children:[$,Ve]}),e[109]=$,e[110]=Ve,e[111]=Se):Se=e[111];let q;e[112]!==n?(q=n("sessions.sidebar.header.actions.sortProjects"),e[112]=n,e[113]=q):q=e[113];let O;e[114]!==f?(O=s.jsx(A,{name:"sort-desc",className:f}),e[114]=f,e[115]=O):O=e[115];let se;e[116]!==m||e[117]!==q||e[118]!==O?(se=s.jsx(Dt,{asChild:!0,children:s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":q,children:O})})}),e[116]=m,e[117]=q,e[118]=O,e[119]=se):se=e[119];let Le;e[120]!==n?(Le=n("sessions.sidebar.header.actions.sortProjects"),e[120]=n,e[121]=Le):Le=e[121];let ae;e[122]!==Le?(ae=s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Le})}),e[122]=Le,e[123]=ae):ae=e[123];let We;e[124]!==se||e[125]!==ae?(We=s.jsxs(At,{children:[se,ae]}),e[124]=se,e[125]=ae,e[126]=We):We=e[126];let Ye;e[127]!==B?(Ye=()=>B("manual"),e[127]=B,e[128]=Ye):Ye=e[128];let Qe;e[129]!==n?(Qe=n("sessions.sidebar.header.projectSort.manual"),e[129]=n,e[130]=Qe):Qe=e[130];let st;e[131]!==Qe?(st=s.jsx("span",{children:Qe}),e[131]=Qe,e[132]=st):st=e[132];let pt;e[133]!==R?(pt=R==="manual"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[133]=R,e[134]=pt):pt=e[134];let jt;e[135]!==Ye||e[136]!==st||e[137]!==pt?(jt=s.jsxs(ls,{onClick:Ye,className:"flex items-center justify-between",children:[st,pt]}),e[135]=Ye,e[136]=st,e[137]=pt,e[138]=jt):jt=e[138];let Et;e[139]!==B?(Et=()=>B("a-z"),e[139]=B,e[140]=Et):Et=e[140];let Rt;e[141]!==n?(Rt=n("sessions.sidebar.header.projectSort.aToZ"),e[141]=n,e[142]=Rt):Rt=e[142];let Ut;e[143]!==Rt?(Ut=s.jsx("span",{children:Rt}),e[143]=Rt,e[144]=Ut):Ut=e[144];let ts;e[145]!==R?(ts=R==="a-z"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[145]=R,e[146]=ts):ts=e[146];let Kt;e[147]!==Et||e[148]!==Ut||e[149]!==ts?(Kt=s.jsxs(ls,{onClick:Et,className:"flex items-center justify-between",children:[Ut,ts]}),e[147]=Et,e[148]=Ut,e[149]=ts,e[150]=Kt):Kt=e[150];let is;e[151]!==B?(is=()=>B("z-a"),e[151]=B,e[152]=is):is=e[152];let qt;e[153]!==n?(qt=n("sessions.sidebar.header.projectSort.zToA"),e[153]=n,e[154]=qt):qt=e[154];let Te;e[155]!==qt?(Te=s.jsx("span",{children:qt}),e[155]=qt,e[156]=Te):Te=e[156];let Ke;e[157]!==R?(Ke=R==="z-a"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[157]=R,e[158]=Ke):Ke=e[158];let rt;e[159]!==is||e[160]!==Te||e[161]!==Ke?(rt=s.jsxs(ls,{onClick:is,className:"flex items-center justify-between",children:[Te,Ke]}),e[159]=is,e[160]=Te,e[161]=Ke,e[162]=rt):rt=e[162];let vt;e[163]!==B?(vt=()=>B("date-added"),e[163]=B,e[164]=vt):vt=e[164];let Je;e[165]!==n?(Je=n("sessions.sidebar.header.projectSort.dateAdded"),e[165]=n,e[166]=Je):Je=e[166];let St;e[167]!==Je?(St=s.jsx("span",{children:Je}),e[167]=Je,e[168]=St):St=e[168];let Xe;e[169]!==R?(Xe=R==="date-added"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[169]=R,e[170]=Xe):Xe=e[170];let qe;e[171]!==vt||e[172]!==St||e[173]!==Xe?(qe=s.jsxs(ls,{onClick:vt,className:"flex items-center justify-between",children:[St,Xe]}),e[171]=vt,e[172]=St,e[173]=Xe,e[174]=qe):qe=e[174];let et;e[175]!==B?(et=()=>B("recent"),e[175]=B,e[176]=et):et=e[176];let Vt;e[177]!==n?(Vt=n("sessions.sidebar.header.projectSort.recent"),e[177]=n,e[178]=Vt):Vt=e[178];let Ct;e[179]!==Vt?(Ct=s.jsx("span",{children:Vt}),e[179]=Vt,e[180]=Ct):Ct=e[180];let Ht;e[181]!==R?(Ht=R==="recent"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[181]=R,e[182]=Ht):Ht=e[182];let ss;e[183]!==et||e[184]!==Ct||e[185]!==Ht?(ss=s.jsxs(ls,{onClick:et,className:"flex items-center justify-between",children:[Ct,Ht]}),e[183]=et,e[184]=Ct,e[185]=Ht,e[186]=ss):ss=e[186];let Xt;e[187]!==jt||e[188]!==Kt||e[189]!==rt||e[190]!==qe||e[191]!==ss?(Xt=s.jsxs(Zs,{align:"end",className:"min-w-[160px]",children:[jt,Kt,rt,qe,ss]}),e[187]=jt,e[188]=Kt,e[189]=rt,e[190]=qe,e[191]=ss,e[192]=Xt):Xt=e[192];let Ft;e[193]!==We||e[194]!==Xt?(Ft=s.jsxs(en,{children:[We,Xt]}),e[193]=We,e[194]=Xt,e[195]=Ft):Ft=e[195];let _t;e[196]!==n?(_t=n("sessions.sidebar.header.actions.sessionDisplayMode"),e[196]=n,e[197]=_t):_t=e[197];let hs;e[198]!==f?(hs=s.jsx(A,{name:"equalizer-2",className:f}),e[198]=f,e[199]=hs):hs=e[199];let Zt;e[200]!==m||e[201]!==_t||e[202]!==hs?(Zt=s.jsx(Dt,{asChild:!0,children:s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":_t,children:hs})})}),e[200]=m,e[201]=_t,e[202]=hs,e[203]=Zt):Zt=e[203];let ns;e[204]!==n?(ns=n("sessions.sidebar.header.displayMode.label"),e[204]=n,e[205]=ns):ns=e[205];let gs;e[206]!==ns?(gs=s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ns})}),e[206]=ns,e[207]=gs):gs=e[207];let Mt;e[208]!==Zt||e[209]!==gs?(Mt=s.jsxs(At,{children:[Zt,gs]}),e[208]=Zt,e[209]=gs,e[210]=Mt):Mt=e[210];let Bt;e[211]!==y||e[212]!==v||e[213]!==n?(Bt=W?s.jsxs(s.Fragment,{children:[s.jsxs(ls,{onClick:()=>v("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),y==="default"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs(ls,{onClick:()=>v("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),y==="minimal"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]})]}):null,e[211]=y,e[212]=v,e[213]=n,e[214]=Bt):Bt=e[214];let $t;e[215]!==_||e[216]!==o||e[217]!==P||e[218]!==n||e[219]!==I||e[220]!==F?($t=o?s.jsxs(s.Fragment,{children:[W?s.jsx($r,{}):null,s.jsxs(ls,{onClick:F,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),P?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs(ls,{onClick:I,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showArchived")}),_?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]})]}):null,e[215]=_,e[216]=o,e[217]=P,e[218]=n,e[219]=I,e[220]=F,e[221]=$t):$t=e[221];let os;e[222]===Symbol.for("react.memo_cache_sentinel")?(os=s.jsx($r,{}),e[222]=os):os=e[222];let Gt;e[223]===Symbol.for("react.memo_cache_sentinel")?(Gt=s.jsx(A,{name:"contract-up-down",className:"h-4 w-4"}),e[223]=Gt):Gt=e[223];let Me;e[224]!==n?(Me=n("sessions.sidebar.header.displayMode.collapseAll"),e[224]=n,e[225]=Me):Me=e[225];let ft;e[226]!==Me?(ft=s.jsx("span",{children:Me}),e[226]=Me,e[227]=ft):ft=e[227];let at;e[228]!==k||e[229]!==ft?(at=s.jsxs(ls,{onClick:k,className:"flex items-center gap-2",children:[Gt,ft]}),e[228]=k,e[229]=ft,e[230]=at):at=e[230];let Nt;e[231]===Symbol.for("react.memo_cache_sentinel")?(Nt=s.jsx(A,{name:"expand-up-down",className:"h-4 w-4"}),e[231]=Nt):Nt=e[231];let Pt;e[232]!==n?(Pt=n("sessions.sidebar.header.displayMode.expandAll"),e[232]=n,e[233]=Pt):Pt=e[233];let es;e[234]!==Pt?(es=s.jsx("span",{children:Pt}),e[234]=Pt,e[235]=es):es=e[235];let xs;e[236]!==j||e[237]!==es?(xs=s.jsxs(ls,{onClick:j,className:"flex items-center gap-2",children:[Nt,es]}),e[236]=j,e[237]=es,e[238]=xs):xs=e[238];let Yt;e[239]!==Bt||e[240]!==$t||e[241]!==at||e[242]!==xs?(Yt=s.jsxs(Zs,{align:"end",className:"min-w-[160px]",children:[Bt,$t,os,at,xs]}),e[239]=Bt,e[240]=$t,e[241]=at,e[242]=xs,e[243]=Yt):Yt=e[243];let Lt;e[244]!==Mt||e[245]!==Yt?(Lt=s.jsxs(en,{children:[Mt,Yt]}),e[244]=Mt,e[245]=Yt,e[246]=Lt):Lt=e[246];let Es;e[247]!==V||e[248]!==Se||e[249]!==Ft||e[250]!==Lt?(Es=s.jsxs("div",{className:"flex items-center gap-1.5",children:[V,Se,Ft,Lt]}),e[247]=V,e[248]=Se,e[249]=Ft,e[250]=Lt,e[251]=Es):Es=e[251];let ms;e[252]!==ge||e[253]!==Es?(ms=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[ge,Es]}),e[252]=ge,e[253]=Es,e[254]=ms):ms=e[254];let Ns;e[255]!==g||e[256]!==u||e[257]!==h||e[258]!==x||e[259]!==b||e[260]!==p||e[261]!==w||e[262]!==n?(Ns=u?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:[g?s.jsx("span",{children:h===1?n("sessions.sidebar.header.search.matchCountSingle",{count:h}):n("sessions.sidebar.header.search.matchCountPlural",{count:h})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(A,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:x,value:b,onChange:Ms=>w(Ms.target.value),placeholder:n("sessions.sidebar.header.search.placeholder"),className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:Ms=>{Ms.key==="Escape"&&(Ms.stopPropagation(),g?w(""):p(!1))}}),b.length>0?s.jsx("button",{type:"button",onClick:()=>w(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[255]=g,e[256]=u,e[257]=h,e[258]=x,e[259]=b,e[260]=p,e[261]=w,e[262]=n,e[263]=Ns):Ns=e[263];let Us;return e[264]!==ms||e[265]!==Ns?(Us=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[ms,Ns]})}),e[264]=ms,e[265]=Ns,e[266]=Us):Us=e[266],Us}function eN(t){return!t}function tN(t){return t.setProjectSortOrder}function sN(t){return t.projectSortOrder}function nN(t){return t.toggleArchivedSessions}function rN(t){return t.toggleRecentSection}function iN(t){return t.setDisplayMode}function oN(t){return t.showArchivedSessions}function aN(t){return t.showRecentSection}function lN(t){return t.displayMode}const Nf=7;function cN({sections:t,renderSessionNode:e,currentSessionId:n,editingId:r,openSidebarMenuKey:o,variant:a="section",initialVisibleCount:c=Nf,batchSize:l=Nf}){const{t:d}=yt(),[f,m]=i.useState(new Set),[u,p]=i.useState(new Map),x=a==="flat",b=i.useCallback(j=>{p(S=>{if(!S.has(j))return S;const N=new Map(S);return N.delete(j),N})},[]),w=i.useCallback(j=>{b(j),m(S=>{const N=new Set(S);return N.has(j)?N.delete(j):N.add(j),N})},[b]),g=i.useCallback((j,S,N)=>{p(C=>{const y=Math.min(N,S+l),P=new Map(C);return P.set(j,y),P})},[l]),h=i.useCallback(j=>{const S=new Set;Zi(j,n,S);const N=new Set;Zi(j,r,N);const C=zo(j,o,"recent",!1),y=new WeakMap,P=v=>{y.set(v,_a(v)),v.children.forEach(P)};j.forEach(P);const _=v=>({subtreeContainsActive:S,subtreeContainsEditing:N,menuOpenSessionId:C,nodeStructureKey:y.get(v)??"",childRenderExtrasFor:_});return v=>({subtreeContainsActive:S,subtreeContainsEditing:N,menuOpenSessionId:C,nodeStructureKey:y.get(v)??"",childRenderExtrasFor:_})},[n,r,o]),k=t.filter(j=>j.items.length>0);return k.length===0?null:s.jsx("div",{className:Pe(x?"space-y-0.5 pb-2":"space-y-2 pb-2 pt-1"),children:k.map(j=>{const S=f.has(j.key),N=Math.max(c,u.get(j.key)??c),C=j.items.slice(0,N),y=j.items.length-C.length,P=!x&&j.items.length>c&&y===0,_=h(C.map(F=>F.node)),v=F=>e(F.node,0,F.groupDirectory,F.projectId,!1,F.secondaryMeta,"recent",_(F.node));return x?s.jsxs("div",{className:"space-y-0.5",children:[C.map(v),y>0?s.jsx("button",{type:"button",onClick:()=>g(j.key,C.length,j.items.length),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:d("sessions.sidebar.group.showMore")}):null]},j.key):s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>w(j.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":!S,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:S?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:j.title})]}),S?null:s.jsxs("div",{className:Pe("space-y-0.5 pl-7"),children:[C.map(v),y>0?s.jsx("button",{type:"button",onClick:()=>g(j.key,C.length,j.items.length),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:d("sessions.sidebar.group.showMore")}):null,P?s.jsx("button",{type:"button",onClick:()=>b(j.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:d("sessions.sidebar.group.showFewer")}):null]})]},j.key)})})}const _l="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 dN(t){const e=gt.c(14),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:o,onOpenUpdate:a,onOpenShareOpinion:c,showRuntimeButtons:l,showUpdateButton:d}=t,f=l===void 0?!0:l,m=d===void 0?!0:d,{t:u}=yt();let p;e[0]!==o||e[1]!==n||e[2]!==r||e[3]!==f||e[4]!==u?(p=f?s.jsxs(s.Fragment,{children:[s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:_l,"aria-label":u("sessions.sidebar.footer.actions.settings"),children:s.jsx(A,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(Tt,{side:"top",sideOffset:4,children:s.jsx("p",{children:u("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:_l,"aria-label":u("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(A,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(Tt,{side:"top",sideOffset:4,children:s.jsx("p",{children:u("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:_l,"aria-label":u("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(A,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(Tt,{side:"top",sideOffset:4,children:s.jsx("p",{children:u("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=o,e[1]=n,e[2]=r,e[3]=f,e[4]=u,e[5]=p):p=e[5];let x;e[6]!==c||e[7]!==a||e[8]!==m||e[9]!==u?(x=m?s.jsx(ze,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:a,children:u("sessions.sidebar.footer.actions.update")}):s.jsx(ze,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--primary-base)]/15 bg-[var(--primary-base)]/5 text-[var(--primary-base)]/60 hover:bg-[var(--primary-base)]/10 hover:text-[var(--primary-base)]/75",onClick:c,children:u("sessions.sidebar.footer.actions.shareOpinion")}),e[6]=c,e[7]=a,e[8]=m,e[9]=u,e[10]=x):x=e[10];let b;return e[11]!==p||e[12]!==x?(b=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[p,x]}),e[11]=p,e[12]=x,e[13]=b):b=e[13],b}const uN=t=>{const e=gt.c(59),{id:n,disabled:r,projectLabel:o,projectDescription:a,projectIcon:c,projectColor:l,projectIconImage:d,projectIconBackground:f,isCollapsed:m,isActiveProject:u,isRepo:p,isDesktopShell:x,isStuck:b,hideDirectoryControls:w,alwaysShowActions:g,onToggle:h,onNewSession:k,onNewWorktreeSession:j,onRenameStart:S,onClose:N,sentinelRef:C,children:y,showCreateButtons:P,hideHeader:_,openSidebarMenuKey:v,setOpenSidebarMenuKey:F}=t,I=r===void 0?!1:r,R=P===void 0?!0:P,B=_===void 0?!1:_,{t:D}=yt(),{currentTheme:W}=wi();let U;e[0]!==I||e[1]!==n?(U={id:n,disabled:I},e[0]=I,e[1]=n,e[2]=U):U=e[2];const{attributes:L,listeners:M,setNodeRef:ee,transform:ie,transition:te,isDragging:H}=bc(U),J=i.useRef(!1),re=`project:${n}`,oe=v===re,[ve,ne]=i.useState(!1),ye=c?Lc[c]:null,he=l?Bc[l]??null:null;let Fe;e[3]!==re||e[4]!==F?(Fe=T=>{T&&ne(!1),F(T?re:null)},e[3]=re,e[4]=F,e[5]=Fe):Fe=e[5];const z=Fe;let K;e[6]!==w||e[7]!==p||e[8]!==N||e[9]!==k||e[10]!==S||e[11]!==R||e[12]!==D?(K=T=>s.jsxs(s.Fragment,{children:[R&&!p&&!w&&k&&s.jsxs(T,{onClick:k,children:[s.jsx(A,{name:"add",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.newSession")]}),s.jsxs(T,{onClick:S,children:[s.jsx(A,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.edit")]}),s.jsxs(T,{onClick:N,className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.closeProject")]})]}),e[6]=w,e[7]=p,e[8]=N,e[9]=k,e[10]=S,e[11]=R,e[12]=D,e[13]=K):K=e[13];const Y=K,me=hN,Ne=pN,Be=gN;let _e;e[14]===Symbol.for("react.memo_cache_sentinel")?(_e=T=>{(T.button===2||T.button===0&&T.ctrlKey)&&(J.current=!0)},e[14]=_e):_e=e[14];const Oe=_e;let pe;e[15]!==h?(pe=()=>{if(J.current){J.current=!1;return}h()},e[15]=h,e[16]=pe):pe=e[16];const Re=pe;let ge;e[17]!==ie?(ge=wc.Transform.toString(ie),e[17]=ie,e[18]=ge):ge=e[18];let ce;e[19]!==ge||e[20]!==te?(ce={transform:ge,transition:te},e[19]=ge,e[20]=te,e[21]=ce):ce=e[21];const Ce=H&&"opacity-30";let be;e[22]!==Ce?(be=Pe("relative",Ce),e[22]=Ce,e[23]=be):be=e[23];let ue;e[24]!==g||e[25]!==L||e[26]!==W||e[27]!==z||e[28]!==Re||e[29]!==w||e[30]!==B||e[31]!==he||e[32]!==n||e[33]!==u||e[34]!==m||e[35]!==ve||e[36]!==x||e[37]!==oe||e[38]!==p||e[39]!==b||e[40]!==M||e[41]!==k||e[42]!==j||e[43]!==a||e[44]!==f||e[45]!==d||e[46]!==ye||e[47]!==o||e[48]!==Y||e[49]!==C||e[50]!==R||e[51]!==D?(ue=B?null:s.jsxs(s.Fragment,{children:[x&&s.jsx("div",{ref:C,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsxs(Uc,{open:ve,onOpenChange:ne,children:[s.jsx(Wc,{render:s.jsx("div",{className:Pe("w-full text-left group/project select-none"),style:{backgroundColor:x&&b?"transparent":void 0},onContextMenu:T=>{w||(T.preventDefault(),ne(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",...L,children:[s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:Oe,onClick:Re,...M,className:Pe("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]",p&&!w?g?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":g?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),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:Pe("h-3.5 w-3.5 items-center justify-center text-muted-foreground",g?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:m?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),d?s.jsx("span",{className:Pe("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",g?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:f?{backgroundColor:f}:void 0,children:s.jsx(Vc,{project:{id:n,iconImage:d},options:{themeVariant:W.metadata.variant,iconColor:W.colors.surface.foreground},className:"h-full w-full object-contain",fallback:ye?s.jsx(A,{name:ye,className:"h-3.5 w-3.5",style:he?{color:he}:void 0}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:he?{color:he}:void 0})})}):ye?s.jsx(A,{name:ye,className:Pe("h-3.5 w-3.5",g?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:he?{color:he}:void 0}):s.jsx(A,{name:"folder",className:Pe("h-3.5 w-3.5 text-muted-foreground/80",g?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:he?{color:he}:void 0})]}),s.jsx("span",{className:Pe("text-[14px] font-normal truncate lowercase",u?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:o})]})}),s.jsx(Tt,{side:"right",sideOffset:8,children:a})]}),s.jsxs("div",{className:Pe("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",R?"right-7":"right-0.5"),children:[R&&p&&!w&&j?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:T=>{T.stopPropagation(),j()},className:Pe("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",g?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":D("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(A,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,w?null:s.jsxs(en,{open:oe,onOpenChange:z,children:[s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",oe?"opacity-100 pointer-events-auto":g?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":D("sessions.sidebar.project.actions.projectMenu"),onPointerDown:Ne,onMouseDown:Be,onClick:me,children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Zs,{align:"end",className:"min-w-[180px]",children:Y(ls)})]})]}),R&&k?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:T=>{T.stopPropagation(),k()},className:Pe("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",g?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":D(p?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(A,{name:"add",className:"h-4 w-4"})})}),s.jsx(Tt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D(p?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx($c,{className:"min-w-[180px]",children:Y(zc)})]})]}),e[24]=g,e[25]=L,e[26]=W,e[27]=z,e[28]=Re,e[29]=w,e[30]=B,e[31]=he,e[32]=n,e[33]=u,e[34]=m,e[35]=ve,e[36]=x,e[37]=oe,e[38]=p,e[39]=b,e[40]=M,e[41]=k,e[42]=j,e[43]=a,e[44]=f,e[45]=d,e[46]=ye,e[47]=o,e[48]=Y,e[49]=C,e[50]=R,e[51]=D,e[52]=ue):ue=e[52];let De;return e[53]!==y||e[54]!==ee||e[55]!==ce||e[56]!==be||e[57]!==ue?(De=s.jsxs("div",{ref:ee,style:ce,className:be,children:[ue,y]}),e[53]=y,e[54]=ee,e[55]=ce,e[56]=be,e[57]=ue,e[58]=De):De=e[58],De},fN=t=>{const e=gt.c(21),{id:n,disabled:r,children:o}=t,a=r===void 0?!1:r;let c;e[0]!==a||e[1]!==n?(c={id:n,disabled:a},e[0]=a,e[1]=n,e[2]=c):c=e[2];const{listeners:l,setNodeRef:d,setActivatorNodeRef:f,transform:m,transition:u,isDragging:p}=bc(c);let x;e[3]!==l||e[4]!==f?(x={listeners:l,setActivatorNodeRef:f},e[3]=l,e[4]=f,e[5]=x):x=e[5];const b=x;let w;e[6]!==m?(w=wc.Transform.toString(m),e[6]=m,e[7]=w):w=e[7];let g;e[8]!==w||e[9]!==u?(g={transform:w,transition:u},e[8]=w,e[9]=u,e[10]=g):g=e[10];const h=p&&"opacity-50";let k;e[11]!==h?(k=Pe("space-y-0.5 rounded-md",h),e[11]=h,e[12]=k):k=e[12];let j;e[13]!==o||e[14]!==b?(j=typeof o=="function"?o(b):o,e[13]=o,e[14]=b,e[15]=j):j=e[15];let S;return e[16]!==d||e[17]!==g||e[18]!==k||e[19]!==j?(S=s.jsx("div",{ref:d,style:g,className:k,children:j}),e[16]=d,e[17]=g,e[18]=k,e[19]=j,e[20]=S):S=e[20],S},mN=i.memo(fN);function hN(t){t.stopPropagation()}function pN(t){t.stopPropagation()}function gN(t){t.stopPropagation()}function xN(t){const{t:e}=yt(),n=ja(Do(Sa,{activationConstraint:{distance:8}}),Do(cp,{coordinateGetter:lp})),r=ja(Do(Sa,{activationConstraint:{distance:8}})),o=i.useRef(null),a=i.useRef(new Map),c=i.useRef(t.getOrderedGroups);c.current!==t.getOrderedGroups&&(c.current=t.getOrderedGroups,a.current.clear());const l=(d,f)=>{const m=a.current,u=m.get(d);if(u&&u.groups===f)return u.ordered;const p=t.getOrderedGroups(d,f);if(m.set(d,{groups:f,ordered:p}),m.size>256){const x=m.keys().next().value;x!==void 0&&m.delete(x)}return p};return t.sharedSessionsOnly?s.jsxs(On,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Pe("space-y-1 pb-1 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.hasSharedSessions?null:t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState]}):t.projectSections.length===0?s.jsxs(On,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Pe("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.emptyState]}):t.sectionsForRender.length===0?s.jsx(On,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Pe("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:t.searchEmptyState}):s.jsxs(On,{ref:o,useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Pe("space-y-1 pb-1 pl-2.5 pr-2 [overflow-anchor:none]",(t.mobileVariant,"")),children:[t.topContent,t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const d=t.sectionsForRender.find(p=>p.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!d)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const f=d.groups.find(p=>p.isMain&&p.sessions.length>0)??d.groups.find(p=>p.sessions.length>0)??d.groups.find(p=>p.isMain)??d.groups[0];if(!f)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:e("sessions.sidebar.empty.noSessions.title")});const m=d.groups.find(p=>p.isArchivedBucket);return[f,...m&&m.id!==f.id?[m]:[]].map(p=>{const x=`${d.project.id}:${p.id}`,b=p.id===f.id;return s.jsx(i.Fragment,{children:t.renderGroupSessions(p,x,d.project.id,b,null,!0,o)},x)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Na,{sensors:n,collisionDetection:ka,onDragEnd:d=>{if(t.isInlineEditing||t.projectSortOrder!=="manual")return;const{active:f,over:m}=d;if(!m||f.id===m.id)return;const u=t.sectionsForRender.findIndex(x=>x.project.id===f.id),p=t.sectionsForRender.findIndex(x=>x.project.id===m.id);u===-1||p===-1||u===p||t.reorderProjects(u,p)},children:[s.jsx(Gl,{items:t.sectionsForRender.map(d=>d.project.id),strategy:Kl,children:t.sectionsForRender.map(d=>{const f=d.project,m=f.id,u=zm(f.label?.trim()||ho(f.normalizedPath,t.homeDirectory)||f.normalizedPath),p=Pa(f.normalizedPath,t.homeDirectory),x=t.collapsedProjects.has(m),b=m===t.activeProjectId,w=t.projectRepoStatus.get(m),g=l(m,d.groups),h=g.find(j=>j.isMain)??null,k=h?g.filter(j=>j.id!==h.id):g;return s.jsx(uN,{id:m,disabled:t.projectSortOrder!=="manual",projectLabel:u,projectDescription:p,projectIcon:f.icon,projectColor:f.color,projectIconImage:f.iconImage,projectIconBackground:f.iconBackground,isCollapsed:x,isActiveProject:b,isRepo:!!w,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(m),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(m),onNewSession:()=>{m!==t.activeProjectId&&t.setActiveProjectIdOnly(m),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:f.normalizedPath})},onNewWorktreeSession:()=>{m!==t.activeProjectId&&t.setActiveProjectIdOnly(m),t.setActiveMainTab("chat"),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(m),onClose:()=>t.removeProject(m),sentinelRef:j=>{t.projectHeaderSentinelRefs.current.set(m,j)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:x?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:d.groups.length>0?s.jsxs(Na,{sensors:r,collisionDetection:ka,onDragEnd:j=>{if(t.isInlineEditing)return;const{active:S,over:N}=j;if(!N||S.id===N.id)return;const C=k.findIndex(v=>v.id===S.id),y=k.findIndex(v=>v.id===N.id);if(C===-1||y===-1||C===y)return;const P=Gf(k,C,y).map(v=>v.id),_=h?[h.id,...P]:P;t.setGroupOrderByProject(v=>{const F=new Map(v);return F.set(m,_),F})},children:[h?t.renderGroupSessions(h,`${m}:${h.id}`,m,!0,null,void 0,o):null,s.jsx(Gl,{items:k.map(j=>j.id),strategy:Kl,children:k.map(j=>{const S=`${m}:${j.id}`;return s.jsx(mN,{id:j.id,disabled:t.isInlineEditing,children:N=>t.renderGroupSessions(j,S,m,!1,N,void 0,o)},j.id)})}),s.jsx(Yl,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:e("sessions.sidebar.empty.noSessions.title")})})},m)})}),s.jsx(Yl,{dropAnimation:null})]})})]})}function bN(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(oo(),{month:"short"}),r=e.getDate(),o=e.getFullYear(),a=String(e.getHours()).padStart(2,"0"),c=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${o}, ${a}:${c}`}function wN(t){if(t.info.role==="user")return"";const e=typeof t.info.providerID=="string"?t.info.providerID.trim():"",n=typeof t.info.modelID=="string"?t.info.modelID.trim():"";return e&&n?`${e}/${n}`:n||e}function yN(t){const e=t.info.role==="user"?"User":"Assistant",n=bN(t.info.time?.created),r=wN(t),o=n&&r?`${n} (${r})`:n||r;return o?`**${e}**
|
|
193
|
+
|
|
194
|
+
*${o}*`:`**${e}**`}function vN(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Rh(t){const e=yN(t),n=vN(t.parts).trim();return n?`${e}
|
|
195
|
+
|
|
196
|
+
${n}`:""}function Eh(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",o=`${n} Sub-agent: ${t.title}${r}
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
`,a=t.records.map(Rh).filter(Boolean).join(`
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
`),c=[o+a];for(const l of t.children)c.push(Eh(l,e+1));return c.join(`
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
`)}function jN(t,e,n){const r=e?.trim()||"Session",o=new Date().toISOString().split("T")[0],a=`# ${r}
|
|
209
|
+
|
|
210
|
+
*Exported on ${o}*
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
`,c=t.map(Rh).filter(Boolean).join(`
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
`);let l=a+c;if(n&&n.length>0){const d=n.map(f=>Eh(f,1)).join(`
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
`);l+=`
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
`+d}return l}function SN(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),o=document.createElement("a");o.href=r,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)}async function NN(t,e){const n=await Ap(e,t);if(n)return n;if(!Cr())return null;try{const r=await Wo()?.vscode?.saveMarkdown?.({fileName:e,content:t});if(!r||r.saved!==!0)return null;const o=typeof r.path=="string"?r.path.trim():"";return o.length>0?o:null}catch{return null}}async function kN(t){const e=Wo()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Dp(t)?!0:Ca(t)}function CN(){return Ec()}function AN(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",o=new Date().toISOString().split("T")[0];return`${r}-${o}.md`}const DN=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const o of t){r.has(o)||(r.add(o),n.push(o));const a=e.get(o);if(a)for(const c of a)r.has(c)||(r.add(c),n.push(c))}return n},Wn=fo()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,o)=>{const a=e(),c=new Set(a.selectedIds);let l=a.scopeKey,d=a.anchorId;r!==null&&a.scopeKey!==null&&r!==a.scopeKey?(c.clear(),l=r,d=null):l===null&&r!==null&&(l=r);const m=o&&o.length>0?[n,...o]:[n];if(c.has(n)){for(const p of m)c.delete(p);d===n&&(d=null)}else{for(const p of m)c.add(p);d=n}c.size===0?t({selectedIds:c,scopeKey:null,anchorId:null}):t({selectedIds:c,scopeKey:l,anchorId:d})},setRange:(n,r,o,a,c)=>{const l=e();if(o.length===0)return;const d=n&&o.includes(n)?n:o[0],f=o.indexOf(d),m=o.indexOf(r);if(f<0||m<0)return;const[u,p]=f<=m?[f,m]:[m,f],x=o.slice(u,p+1),b=DN(x,c),g=a!==null&&l.scopeKey!==null&&a!==l.scopeKey?new Set:new Set(l.selectedIds);for(const h of b)g.add(h);t({selectedIds:g,scopeKey:a??l.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const o=new Set(r.selectedIds);for(const a of n)o.delete(a);o.size!==r.selectedIds.size&&(o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o}))}}));let mc=!1;const hc=new Set;let kf=!1;function TN(){for(const t of hc)t()}function sd(t){mc!==t&&(mc=t,TN())}function PN(t){t.key==="Shift"&&sd(!0)}function IN(t){t.key==="Shift"&&sd(!1)}function RN(){sd(!1)}function EN(){kf||typeof window>"u"||(kf=!0,window.addEventListener("keydown",PN),window.addEventListener("keyup",IN),window.addEventListener("blur",RN))}function MN(t){return EN(),hc.add(t),()=>{hc.delete(t)}}function FN(){return mc}function ON(){return!1}function LN(){return nt.useSyncExternalStore(MN,FN,ON)}const BN=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,Mh=/^g[1-9]\d*$/,ko=(t,e,n,r,o)=>{if(!BN.test(t)||e!==void 0&&!Mh.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(o===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(o==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(o))return null;const a=Number.parseInt(o,10);return!Number.isSafeInteger(a)||a<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:a,fusion:!1}},ya=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return ko(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,l,d,f]=e;return Mh.test(l)?ko(n,l,d,f,void 0):ko(n,void 0,l,d,f)}const[,r,o,a,c]=e;return r===""?ko(n,void 0,o,a,c):ko(n,r,o,a,c)},VN=t=>{const e=[t.groupSlug];return t.runGroup&&e.push(t.runGroup),e.push(t.providerID,t.modelID),t.index!==void 0&&e.push(String(t.index)),e.join("/")},_N=(t,e,n,r)=>{const o=[t];return r&&o.push(r),o.push(e,n,"fusion"),o.join("/")},Fh=t=>{const e=gt.c(36),{value:n,onChange:r,className:o,disabled:a,id:c,portalToBody:l}=t,{t:d}=yt(),f=rs($N),m=rs(zN),u=rs(WN);let p;e[0]!==f?(p=f(),e[0]=f,e[1]=p):p=e[1];const x=p;let b;e[2]!==x?(b=x.filter(UN),e[2]=x,e[3]=b):b=e[3];const w=b;let g,h;e[4]!==x.length||e[5]!==m?(g=()=>{x.length===0&&m()},h=[x.length,m],e[4]=x.length,e[5]=m,e[6]=g,e[7]=h):(g=e[6],h=e[7]),i.useEffect(g,h);let k,j;e[8]!==u||e[9]!==a||e[10]!==r||e[11]!==w||e[12]!==n?(k=()=>{if(a)return;const I=n.trim();if(I.length>0&&w.some(D=>D.name===I))return;const R=typeof u=="string"&&u.trim().length>0?u.trim():null;if(R&&w.some(D=>D.name===R)){r(R);return}const B=w[0]?.name;B&&r(B)},j=[u,a,r,w,n],e[8]=u,e[9]=a,e[10]=r,e[11]=w,e[12]=n,e[13]=k,e[14]=j):(k=e[13],j=e[14]),i.useEffect(k,j);const S=n.trim().length>0?n:void 0;let N;e[15]!==o?(N=Pe("max-w-full typography-meta text-foreground !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 data-[popup-open]:!bg-[var(--interactive-active)]/70",o),e[15]=o,e[16]=N):N=e[16];let C;e[17]!==d?(C=d("multirun.agentSelector.placeholder"),e[17]=d,e[18]=C):C=e[18];let y;e[19]!==C?(y=s.jsx(Dn,{placeholder:C}),e[19]=C,e[20]=y):y=e[20];let P;e[21]!==c||e[22]!==N||e[23]!==y?(P=s.jsx(Hn,{id:c,size:"lg",className:N,children:y}),e[21]=c,e[22]=N,e[23]=y,e[24]=P):P=e[24];let _;e[25]!==w?(_=w.length>0&&s.jsx(Jl,{children:w.map(HN)}),e[25]=w,e[26]=_):_=e[26];let v;e[27]!==l||e[28]!==_?(v=s.jsx(Gn,{fitContent:!0,portalToBody:l,children:_}),e[27]=l,e[28]=_,e[29]=v):v=e[29];let F;return e[30]!==a||e[31]!==r||e[32]!==S||e[33]!==P||e[34]!==v?(F=s.jsxs(Un,{value:S,onValueChange:r,disabled:a,children:[P,v]}),e[30]=a,e[31]=r,e[32]=S,e[33]=P,e[34]=v,e[35]=F):F=e[35],F};function $N(t){return t.getVisibleAgents}function zN(t){return t.loadAgents}function WN(t){return t.currentAgentName}function UN(t){return Dc(t.mode)}function HN(t){return s.jsx(Bs,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Oh="h-7",Oo=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,GN=t=>{const e=gt.c(12),{model:n,instanceIndex:r,totalSameModel:o,onRemove:a}=t,c=n.displayName||`${n.providerID}/${n.modelID}`,l=o>1?`${c} (${r})`:c;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=Pe("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Oh),e[0]=d):d=e[0];let f;e[1]!==n.providerID?(f=s.jsx(Lo,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=f):f=e[2];let m;e[3]!==l?(m=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:l}),e[3]=l,e[4]=m):m=e[4];let u;e[5]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(A,{name:"close",className:"h-3.5 w-3.5"}),e[5]=u):u=e[5];let p;e[6]!==a?(p=s.jsx("button",{type:"button",onClick:a,className:"text-muted-foreground hover:text-foreground ml-0.5",children:u}),e[6]=a,e[7]=p):p=e[7];let x;return e[8]!==f||e[9]!==m||e[10]!==p?(x=s.jsxs("div",{className:d,children:[f,m,p]}),e[8]=f,e[9]=m,e[10]=p,e[11]=x):x=e[11],x},Lh=t=>{const e=gt.c(119),{selectedModels:n,onAdd:r,onRemove:o,onUpdate:a,minModels:c,addButtonLabel:l,showChips:d,maxModels:f,addButtonClassName:m,dropdownSide:u,dropdownClassName:p,containerClassName:x,triggerIcon:b}=t,w=d===void 0?!0:d,g=u===void 0?"top":u,{t:h}=yt(),k=rs(KN),j=rs(qN),S=Ee(YN),N=Ee(QN),{favoriteModelsList:C,recentModelsList:y}=Wg(),P=Ee(JN),_=Ee(XN),[v,F]=i.useState(!1),[I,R]=i.useState(""),[B,D]=i.useState(null),W=i.useRef(null),U=i.useRef(null),L=f===1,M=f===void 0||n.length<f||L;let ee;if(e[0]!==n){ee=new Map;for(const se of n){const Le=`${se.providerID}:${se.modelID}`;ee.set(Le,(ee.get(Le)||0)+1)}e[0]=n,e[1]=ee}else ee=e[1];const ie=ee;let te;e[2]!==n?(te=se=>n.filter(ae=>ae.providerID===se.providerID&&ae.modelID===se.modelID).findIndex(ae=>ae.instanceId===se.instanceId)+1,e[2]=n,e[3]=te):te=e[3];const H=te;let J,re;e[4]!==g||e[5]!==v?(J=()=>{if(!v||!U.current)return;const se=U.current.getBoundingClientRect();if(g==="bottom"){const st=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-se.bottom-16-112;D(Math.max(160,Math.min(320,st)));return}let Le=U.current.parentElement;for(;Le&&!(Le.getAttribute("role")==="dialog"||Le.hasAttribute("data-scroll-shadow"));){const Ye=getComputedStyle(Le);if(Ye.overflow==="auto"||Ye.overflow==="hidden"||Ye.overflowY==="auto"||Ye.overflowY==="hidden")break;Le=Le.parentElement}const ae=Le?Le.getBoundingClientRect().top:0,We=se.top-ae-16;D(Math.max(150,Math.min(300,We)))},re=[g,v],e[4]=g,e[5]=v,e[6]=J,e[7]=re):(J=e[6],re=e[7]),i.useEffect(J,re);let oe,ve;e[8]!==M||e[9]!==v?(oe=()=>{!M&&v&&(F(!1),R(""))},ve=[M,v],e[8]=M,e[9]=v,e[10]=oe,e[11]=ve):(oe=e[10],ve=e[11]),i.useEffect(oe,ve);let ne,ye;e[12]!==v?(ne=()=>{if(!v)return;const se=Le=>{W.current&&!W.current.contains(Le.target)&&(F(!1),R(""))};return document.addEventListener("mousedown",se),()=>document.removeEventListener("mousedown",se)},ye=[v],e[12]=v,e[13]=ne,e[14]=ye):(ne=e[13],ye=e[14]),i.useEffect(ne,ye);let he;e[15]!==L||e[16]!==r||e[17]!==a||e[18]!==n.length?(he=se=>{const Le={providerID:se.providerID,modelID:se.modelID,displayName:se.model.name||se.modelID,instanceId:Oo()};L&&n.length>0&&a?a(0,Le):r(Le),L&&(F(!1),R(""))},e[15]=L,e[16]=r,e[17]=a,e[18]=n.length,e[19]=he):he=e[19];const Fe=he;let z;e[20]!==h?(z=h("multirun.modelMultiSelect.search.placeholder"),e[20]=h,e[21]=z):z=e[21];let K;e[22]!==h?(K=h("multirun.modelMultiSelect.search.noResults"),e[22]=h,e[23]=K):K=e[23];let Y;e[24]!==h?(Y=h("multirun.modelMultiSelect.sections.favorites"),e[24]=h,e[25]=Y):Y=e[25];let me;e[26]!==h?(me=h("multirun.modelMultiSelect.sections.recent"),e[26]=h,e[27]=me):me=e[27];let Ne;e[28]!==h?(Ne=h("multirun.modelMultiSelect.keyboard.hint"),e[28]=h,e[29]=Ne):Ne=e[29];let Be;e[30]!==h?(Be=h("settings.agents.modelSelector.actions.favorite"),e[30]=h,e[31]=Be):Be=e[31];let _e;e[32]!==h?(_e=h("settings.agents.modelSelector.actions.unfavorite"),e[32]=h,e[33]=_e):_e=e[33];let Oe;e[34]!==h?(Oe=h("chat.modelControls.capabilities"),e[34]=h,e[35]=Oe):Oe=e[35];let pe;e[36]!==h?(pe=h("chat.modelControls.capability.toolCalling"),e[36]=h,e[37]=pe):pe=e[37];let Re;e[38]!==h?(Re=h("chat.modelControls.capability.reasoning"),e[38]=h,e[39]=Re):Re=e[39];let ge;e[40]!==h?(ge=h("chat.modelControls.input"),e[40]=h,e[41]=ge):ge=e[41];let ce;e[42]!==h?(ce=h("chat.modelControls.output"),e[42]=h,e[43]=ce):ce=e[43];let Ce;e[44]!==h?(Ce=h("chat.modelControls.costPerMillion"),e[44]=h,e[45]=Ce):Ce=e[45];let be;e[46]!==z||e[47]!==K||e[48]!==Y||e[49]!==me||e[50]!==Ne||e[51]!==Be||e[52]!==_e||e[53]!==Oe||e[54]!==pe||e[55]!==Re||e[56]!==ge||e[57]!==ce||e[58]!==Ce?(be={searchPlaceholder:z,noResults:K,favorites:Y,recent:me,keyboardHint:Ne,favorite:Be,unfavorite:_e,capabilities:Oe,capabilityToolCalling:pe,capabilityReasoning:Re,input:ge,output:ce,costPerMillion:Ce},e[46]=z,e[47]=K,e[48]=Y,e[49]=me,e[50]=Ne,e[51]=Be,e[52]=_e,e[53]=Oe,e[54]=pe,e[55]=Re,e[56]=ge,e[57]=ce,e[58]=Ce,e[59]=be):be=e[59];const ue=be;let De;e[60]!==x?(De=Pe("relative",x),e[60]=x,e[61]=De):De=e[61];let T;e[62]!==m?(T=Pe(Oh,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",m),e[62]=m,e[63]=T):T=e[63];const V=!M;let we;e[64]!==v?(we=()=>{F(!v)},e[64]=v,e[65]=we):we=e[65];let E;e[66]!==b?(E=b??s.jsx(A,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=b,e[67]=E):E=e[67];let de;e[68]!==l||e[69]!==h?(de=l??h("multirun.modelMultiSelect.actions.addModel"),e[68]=l,e[69]=h,e[70]=de):de=e[70];let fe;e[71]!==T||e[72]!==V||e[73]!==we||e[74]!==E||e[75]!==de?(fe=s.jsxs(ze,{ref:U,type:"button",variant:"outline",size:"sm",className:T,disabled:V,onClick:we,children:[E,de]}),e[71]=T,e[72]=V,e[73]=we,e[74]=E,e[75]=de,e[76]=fe):fe=e[76];let $;e[77]!==B||e[78]!==M||e[79]!==p||e[80]!==g||e[81]!==C||e[82]!==Fe||e[83]!==P||e[84]!==N||e[85]!==v||e[86]!==ue||e[87]!==ie||e[88]!==j||e[89]!==_||e[90]!==k||e[91]!==y||e[92]!==I||e[93]!==S?($=v?s.jsx("div",{className:Pe("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",g==="top"?"bottom-full mb-1":"top-full mt-1",p),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(Ug,{providers:k,providerOrder:_,favoriteModels:C,recentModels:y,modelsMetadata:j,hiddenModels:P,searchQuery:I,onSearchQueryChange:R,onSelect:Fe,labels:ue,selectionCount:se=>ie.get(`${se.providerID}:${se.modelID}`)||0,disabled:!M,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:B?`${B}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:v,isFavorite:se=>N(se.providerID,se.modelID),onToggleFavorite:se=>S(se.providerID,se.modelID),onEscape:()=>{F(!1),R("")}})}):null,e[77]=B,e[78]=M,e[79]=p,e[80]=g,e[81]=C,e[82]=Fe,e[83]=P,e[84]=N,e[85]=v,e[86]=ue,e[87]=ie,e[88]=j,e[89]=_,e[90]=k,e[91]=y,e[92]=I,e[93]=S,e[94]=$):$=e[94];let ke;e[95]!==De||e[96]!==fe||e[97]!==$?(ke=s.jsxs("div",{className:De,ref:W,children:[fe,$]}),e[95]=De,e[96]=fe,e[97]=$,e[98]=ke):ke=e[98];let Ve;e[99]!==H||e[100]!==ie||e[101]!==o||e[102]!==a||e[103]!==k||e[104]!==n||e[105]!==w||e[106]!==h?(Ve=w&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((se,Le)=>{const ae=`${se.providerID}:${se.modelID}`,We=ie.get(ae)||1,Ye=H(se),st=k.find(Rt=>Rt.id===se.providerID)?.models?.find(Rt=>Rt.id===se.modelID),pt=st?.variants?Object.keys(st.variants):[],jt=pt.length>0,Et=se.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(GN,{model:se,instanceIndex:Ye,totalSameModel:We,onRemove:()=>o(Le)}),jt&&s.jsxs(Un,{value:Et,onValueChange:Rt=>{if(!a)return;a(Le,{...se,variant:Rt==="__default__"?void 0:Rt})},children:[s.jsxs(Hn,{size:"chip",className:"px-2 gap-1.5 rounded-md !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground",children:[s.jsx(A,{name:"brain-ai-3",className:Pe("h-3.5 w-3.5 flex-shrink-0",Et==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(Dn,{placeholder:h("multirun.modelMultiSelect.variant.placeholder"),children:Rt=>Rt==="__default__"?h("multirun.modelMultiSelect.variant.default"):Rt})]}),s.jsxs(Gn,{fitContent:!0,children:[s.jsx(Bs,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:h("multirun.modelMultiSelect.variant.default")}),pt.map(ZN)]})]})]},se.instanceId)})}),e[99]=H,e[100]=ie,e[101]=o,e[102]=a,e[103]=k,e[104]=n,e[105]=w,e[106]=h,e[107]=Ve):Ve=e[107];let Se;e[108]!==ke||e[109]!==Ve?(Se=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[ke,Ve]}),e[108]=ke,e[109]=Ve,e[110]=Se):Se=e[110];let q;e[111]!==f||e[112]!==c||e[113]!==n.length||e[114]!==h?(q=c!==void 0&&n.length<c&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:f!==void 0?h("multirun.modelMultiSelect.validation.minToMax",{min:c,max:f}):h("multirun.modelMultiSelect.validation.minOnly",{min:c})}),e[111]=f,e[112]=c,e[113]=n.length,e[114]=h,e[115]=q):q=e[115];let O;return e[116]!==Se||e[117]!==q?(O=s.jsxs("div",{className:"space-y-2",children:[Se,q]}),e[116]=Se,e[117]=q,e[118]=O):O=e[118],O};function KN(t){return t.providers}function qN(t){return t.modelsMetadata}function YN(t){return t.toggleFavoriteModel}function QN(t){return t.isFavoriteModel}function JN(t){return t.hiddenModels}function XN(t){return t.providerOrder}function ZN(t){return s.jsx(Bs,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const ek=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
227
|
+
|
|
228
|
+
--- RESULT ${n+1}: ${r} ---
|
|
229
|
+
${e.trim()}
|
|
230
|
+
--- END RESULT ${n+1} ---`},Cf=(t,e)=>ht.getState().getWorktreeMetadata(t)?.projectDirectory??e,tk=async t=>{const e=t.directory??void 0,n=Hg(t.session.id,e);if(n.length===0&&t.directory){const o=(await sr.withDirectory(t.directory,()=>sr.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let a=o.length-1;a>=0;a-=1){const c=o[a];if(c.info?.role==="assistant")return Ud(c.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.role==="assistant")return Ud(Gg(o.id,e)).trim()}return""};function sk({session:t,open:e,onOpenChange:n}){const{t:r}=yt(),o=kc(),a=kr(L=>L.activeSessions),c=kr(L=>L.archivedSessions),l=rs(L=>L.providers),d=rs(L=>L.currentProviderId),f=rs(L=>L.currentModelId),m=rs(L=>L.currentAgentName),[u,p]=i.useState(d??""),[x,b]=i.useState(f??""),[w,g]=i.useState(()=>d&&f?[{providerID:d,modelID:f,instanceId:Oo()}]:[]),[h,k]=i.useState(""),[j,S]=i.useState(m??""),[N,C]=i.useState([]),[y,P]=i.useState(!1),_=i.useMemo(()=>ya(t.title),[t.title]),v=i.useMemo(()=>{const L=new Map;for(const M of o)L.set(M.id,M);for(const M of a)L.set(M.id,M);for(const M of c)L.set(M.id,M);return t.id&&L.set(t.id,t),Array.from(L.values())},[a,c,o,t]);i.useEffect(()=>{if(!e||!_)return;const L=ht.getState().getDirectoryForSession(t.id),M=Cf(t.id,L),ee=v.map(ie=>{const te=ya(ie.title);if(!te||te.groupSlug!==_.groupSlug||te.fusion||(te.runGroup??null)!==(_.runGroup??null))return null;const H=ht.getState().getDirectoryForSession(ie.id)??ti(ie),J=Cf(ie.id,H);return M&&J&&M!==J?null:{session:ie,directory:H,projectDirectory:J}}).filter(ie=>ie!==null).sort((ie,te)=>(ie.session.time?.created??0)-(te.session.time?.created??0));C(ee)},[v,e,_,t.id]);const I=l.find(L=>L.id===u)?.models.find(L=>L.id===x),R=I?.variants?Object.keys(I.variants):[],B=!!(_&&u&&x&&N.length>0&&!y),D=i.useCallback(L=>{g([L]),p(L.providerID),b(L.modelID),k("")},[]),W=w[0]?.displayName||w[0]?.modelID||r("multirun.fusion.model.placeholder"),U=async()=>{if(!(!_||!u||!x)){P(!0);try{const L=await Promise.all(N.map(re=>tk(re))),M=N.map((re,oe)=>({source:re,text:L[oe]??""})).filter(re=>re.text.trim().length>0);if(M.length===0){le.error(r("multirun.fusion.toast.noOutputs"));return}const ee=N[0]?.projectDirectory??N[0]?.directory??null,ie=_N(_.groupSlug,u,x,_.runGroup),[te,H]=await Promise.all([Fn("session.fusion.visible"),Fn("session.fusion.instructions")]),J=await ht.getState().createSession(ie,ee,null);if(!J)throw new Error("Failed to create fusion session");ht.getState().setCurrentSession(J.id,ee),n(!1),await sr.sendMessage({id:J.id,providerID:u,modelID:x,variant:h||void 0,agent:j||void 0,text:te,additionalParts:[{text:H,synthetic:!0},...M.map((re,oe)=>({text:ek(re.source,re.text,oe),synthetic:!0})),{text:`
|
|
231
|
+
|
|
232
|
+
--- FUSION INPUTS END ---
|
|
233
|
+
Now write the final fused answer.`,synthetic:!0}],directory:ee??sr.getDirectory()})}catch(L){console.error("[MultiRunFusion] Failed to start fusion",L),le.error(r("multirun.fusion.toast.failed"))}finally{P(!1)}}};return s.jsx(_s,{open:e,onOpenChange:n,children:s.jsxs(Vs,{className:"max-w-xl overflow-visible",children:[s.jsxs(tn,{children:[s.jsx(Gs,{children:r("multirun.fusion.title")}),s.jsx(dn,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx(Lh,{selectedModels:w,onAdd:D,onUpdate:(L,M)=>D(M),onRemove:()=>{g([]),p(""),b(""),k("")},maxModels:1,addButtonLabel:W,showChips:!1,addButtonClassName:"h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:u?s.jsx(Lo,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),R.length>0?s.jsxs(Un,{value:h||"__default__",onValueChange:L=>k(L==="__default__"?"":L),children:[s.jsxs(Hn,{size:"lg",className:"h-8 w-fit rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground px-3 py-1.5",children:[s.jsx(A,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Dn,{children:L=>L==="__default__"?r("multirun.modelMultiSelect.variant.default"):L})]}),s.jsxs(Gn,{fitContent:!0,portalToBody:!0,children:[s.jsx(Bs,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),R.map(L=>s.jsx(Bs,{value:L,children:L},L))]})]}):null,s.jsx(Fh,{value:j,onChange:S,portalToBody:!0,className:"h-8 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:N.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:N.map(L=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(Lo,{providerId:ya(L.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:L.session.title||L.session.id}),s.jsx("button",{type:"button",onClick:()=>C(M=>M.filter(ee=>ee.session.id!==L.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"h-4 w-4"})})]},L.session.id))})]}),s.jsxs(xr,{children:[s.jsx(ze,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(ze,{onClick:U,disabled:!B,children:r(y?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function nk(t){const e=gt.c(7);let n,r,o,a,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),o=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),a=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),c=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=o,e[3]=a,e[4]=c):(n=e[0],r=e[1],o=e[2],a=e[3],c=e[4]);let l;return e[5]!==t?(l=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,o,a,c]}),e[5]=t,e[6]=l):l=e[6],l}const rk=i.memo(function(e){const n=gt.c(22),{archiveLabel:r,deleteLabel:o,buttonSizeClass:a,iconSizeClass:c,onPointerDown:l,onMouseDown:d,onArchive:f,onDelete:m}=e,u=LN(),p=u?o:r;let x;n[0]!==f||n[1]!==m||n[2]!==u?(x=C=>{if(u||C.shiftKey){m(C);return}f(C)},n[0]=f,n[1]=m,n[2]=u,n[3]=x):x=n[3];const b=x,w=u?"text-destructive hover:text-destructive":"text-muted-foreground hover:text-foreground";let g;n[4]!==a||n[5]!==w?(g=Pe("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",w,a),n[4]=a,n[5]=w,n[6]=g):g=n[6];const h=u?"delete-bin":"archive";let k;n[7]!==c||n[8]!==h?(k=s.jsx(A,{name:h,className:c}),n[7]=c,n[8]=h,n[9]=k):k=n[9];let j;n[10]!==b||n[11]!==p||n[12]!==d||n[13]!==l||n[14]!==g||n[15]!==k?(j=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",className:g,"aria-label":p,onPointerDown:l,onMouseDown:d,onClick:b,onKeyDown:uk,children:k})}),n[10]=b,n[11]=p,n[12]=d,n[13]=l,n[14]=g,n[15]=k,n[16]=j):j=n[16];let S;n[17]!==p?(S=s.jsx(Tt,{side:"left",sideOffset:8,children:p}),n[17]=p,n[18]=S):S=n[18];let N;return n[19]!==j||n[20]!==S?(N=s.jsxs(At,{children:[j,S]}),n[19]=j,n[20]=S,n[21]=N):N=n[21],N});function ik(t){const{t:e}=yt(),{node:n,depth:r=0,groupDirectory:o,projectId:a,archivedBucket:c=!1,currentSessionId:l,pinnedSessionIds:d,expandedParents:f,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,notifyOnSubtasks:p,editingId:x,setEditingId:b,editTitle:w,setEditTitle:g,handleSaveEdit:h,handleCancelEdit:k,toggleParent:j,handleSessionSelect:S,handleSessionDoubleClick:N,togglePinnedSession:C,handleShareSession:y,copiedSessionId:P,handleCopyShareUrl:_,handleUnshareSession:v,openSidebarMenuKey:F,setOpenSidebarMenuKey:I,renamingFolderId:R,getFoldersForScope:B,getSessionFolderId:D,removeSessionFromFolder:W,addSessionToFolder:U,createFolderAndStartRename:L,openContextPanelTab:M,handleDeleteSession:ee,mobileVariant:ie,alwaysShowActions:te,renderSessionNode:H,secondaryMeta:J,renderContext:re="project",subtreeContainsActive:oe,subtreeContainsEditing:ve,menuOpenSessionId:ne,childRenderExtrasFor:ye,liveSessionById:he}=t,Fe=!!J?.projectLabel,z=!!J?.branchLabel,K=dr(Ge=>Ge.displayMode),Y=i.useMemo(()=>Cr(),[]),me=K==="minimal"||Y,Ne=i.useMemo(()=>Wa(),[]),Be=i.useContext(Kg),_e=Y?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",Oe=Y?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",pe=Y,Re=!c&&!ie,ge=me?Y?Re&&pe?"group-hover:pr-18":Re||pe?"group-hover:pr-14":"group-hover:pr-8":"group-hover:pr-2 group-focus-within:pr-2":Y?Re&&pe?"group-hover:pr-18":Re||pe?"group-hover:pr-12":"group-hover:pr-5":Re?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",ce=Re?"pr-13":"pr-7",Ce=i.useRef(!1),[be,ue]=i.useState(!1),De=i.useRef(x);De.current=x;const T=i.useRef(null),V=i.useRef(h);V.current=h;const[we,E]=i.useState(w),de=i.useRef(we);de.current=we;const fe=i.useRef(null),$=i.useRef(null),ke=n.session,Ve=he.get(ke.id)??ke,Se=ws(ke.directory??null)??ws(o??null),q=gm(Se??void 0,{bootstrap:!c}),O=_c(),se=Wn(Ge=>Ge.enabled),Le=Wn(i.useCallback(Ge=>Ge.selectedIds.has(ke.id),[ke.id])),ae=Wn(Ge=>Ge.toggleSelected),We=Wn(Ge=>Ge.setRange),Ye=i.useCallback(Ge=>{const ds=[],ks=Os=>{Os.children.forEach(qs=>{ds.push(qs.session.id),ks(qs)})};return ks(Ge),ds},[]),[Qe,st]=i.useState(!1),[pt,jt]=i.useState(!0),Et=`${re}:${c?"archived":"active"}:${ke.id}`,Rt=Sm(i.useCallback(Ge=>!!Ge.sessionMemoryState.get(qg(ke.id))?.isZombie,[ke.id])),Ut=Yg(ke.id),ts=Qg(ke.id,Se??void 0),Kt=Jg(Ve),is=Kt?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center",title:e(Hd[Kt.status]),"aria-label":e(Hd[Kt.status]),children:s.jsx(A,{name:"target",className:"h-3 w-3",style:{color:Xg[Kt.status]}})}):null,qt=l===ke.id,Te=Ve.title||e("sessions.sidebar.session.untitled"),Ke=n.children.length>0,rt=d.has(ke.id),vt=Et,Je=m?!0:f.has(vt),St=!!Ve.parentID,qe=Zg(ke.id)>0&&(!St||p),et=Ve.time?.updated||Ve.time?.created||Date.now(),Vt=Db(et),Ct=Tb(et),Ht=F===Et,[ss,Xt]=i.useState(!1),Ft=Ht||ss,_t=i.useMemo(()=>ya(Ve.title)!==null,[Ve.title]),[hs,Zt]=i.useState(!1),ns=Y&&re==="recent"&&!me,gs=Y&&re==="recent"&&me,Mt=i.useMemo(()=>Ye(n).length,[Ye,n]),Bt=i.useCallback(async Ge=>{const ds=[];let ks=0;for(const Os of Ge)try{await O.ensureSessionRenderable(Os.session.id);const qs=Gd(q.getState(),Os.session.id).list,$s=Os.session.title||e("sessions.sidebar.session.export.untitledSubagent"),gn=Os.session.agent,Cs=await Bt(Os.children);ks+=Cs.skipped,ds.push({title:$s,agent:gn,records:qs,children:Cs.children})}catch{ks+=Ye(Os).length+1}return{children:ds,skipped:ks}},[Ye,q,O,e]),$t=i.useCallback(Ge=>{Ge<=0||le.warning(Ge===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:Ge}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:Ge}))},[e]),os=i.useCallback(async Ge=>{if(!Se){le.error(e("sessions.sidebar.session.export.nothingToExport"));return}await O.ensureSessionRenderable(ke.id);const ds=Gd(q.getState(),ke.id).list;if(ds.length===0){le.error(e("sessions.sidebar.session.export.nothingToExport"));return}let ks,Os=0;if(Ge&&n.children.length>0){const Cs=await Bt(n.children);ks=Cs.children,Os=Cs.skipped}const qs=jN(ds,Ve.title??null,ks),$s=AN(Ve.title??null),gn=await NN(qs,$s);if(gn){le.success(e("sessions.sidebar.session.export.success"),{action:{label:e(CN()),onClick:()=>{kN(gn).then(Cs=>{Cs||le.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),$t(Os);return}SN(qs,$s),le.success(e("sessions.sidebar.session.export.success")),$t(Os)},[Bt,q,n.children,Ve.title,ke.id,Se,$t,O,e]),Gt=i.useCallback(async()=>{if(n.children.length>0){jt(!0),st(!0);return}await os(!1)},[os,n.children.length]),Me=i.useCallback(()=>{Se&&Zr("desktop_open_session_mini_chat_window",{sessionId:ke.id,directory:Se,apiBaseUrl:Xr(),clientToken:Ql()}).catch(Ge=>{console.warn("[session-sidebar] failed to open mini chat window",Ge)})},[ke.id,Se]);if(i.useEffect(()=>{if(x!==ke.id)return;const Ge=ds=>{$.current&&!$.current.contains(ds.target)&&V.current(de.current)};return document.addEventListener("mousedown",Ge),()=>document.removeEventListener("mousedown",Ge)},[x,ke.id]),i.useLayoutEffect(()=>{if(x!==ke.id){fe.current===ke.id&&(fe.current=null);return}fe.current!==ke.id&&(fe.current=ke.id,E(w))},[x,w,ke.id]),x===ke.id)return s.jsx("div",{className:Pe("group relative flex items-center rounded-sm px-1.5 py-1",r>0&&"pl-[20px]"),children:s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[s.jsxs("form",{ref:$,className:"flex w-full items-center gap-2",onSubmit:Ge=>{Ge.preventDefault(),h(we)},children:[s.jsx("input",{value:we,onChange:Ge=>E(Ge.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:Ge=>{if(Ge.stopPropagation(),Ge.key==="Escape"){k();return}}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:k,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"size-4"})})]}),me?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:[Ke?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Je?s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(A,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:Vt}),Fe?s.jsx("span",{className:"truncate",children:J?.projectLabel}):null,z?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:J?.branchLabel})]}):null]})})]})},ke.id);const ft=Ut?.type??"idle",at=ft==="busy"||ft==="retry",Nt=ts.length,es=at||!at&&qe&&!qt,xs=at?s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-busy-pulse","aria-label":e("sessions.sidebar.session.status.active"),title:e("sessions.sidebar.session.status.active")}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":e("sessions.sidebar.session.status.unread"),title:e("sessions.sidebar.session.status.unread")}),Yt=!te&&Ke&&(es||rt),Lt=rt&&!es,Es=s.jsx(A,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}),ms=es||Lt?s.jsxs("span",{className:Pe("pointer-events-none absolute left-0.5 inline-flex h-3.5 w-3.5 items-center justify-center transition-opacity",me?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",Yt?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[es?xs:null,Lt?Es:null]}):null,Ns=Ke&&!te&&(es||rt),Us=Ke?s.jsx("span",{role:"button",tabIndex:0,onClick:Ge=>{Ge.stopPropagation(),j(vt)},onKeyDown:Ge=>{(Ge.key==="Enter"||Ge.key===" ")&&(Ge.preventDefault(),Ge.stopPropagation(),j(vt))},style:{minWidth:14,minHeight:14},className:Pe("inline-flex h-3.5 w-3.5 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",ns?"absolute left-1.5 bottom-1":gs?"relative mr-0.5 shrink-0":Pe("absolute left-0.5",me?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2"),!ns&&!gs&&Ns?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(Je?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Je?s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(A,{name:"arrow-right-s",className:"h-3 w-3"})}):null,Ms=Rt?s.jsx(A,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Tn=Ge=>{Ge&&Xt(!1),I(Ge?Et:null)},Hs=Ge=>{if(!Ge&&T.current){const{id:ds,title:ks}=T.current;T.current=null,b(ds),g(ks)}},xe=Ge=>{Xt(Ge)},tt=Ge=>{Ge.preventDefault(),Ge.stopPropagation(),I(Ht?null:Et)},ut=Ge=>{Ge.preventDefault(),Ge.stopPropagation()},wt=Ge=>{Ge.preventDefault(),Ge.stopPropagation()},zt=Ge=>{Ge.preventDefault(),Ge.stopPropagation()},xt=Ge=>{Ge.preventDefault(),Ge.stopPropagation()},ps=Ge=>{Ge.preventDefault(),Ge.stopPropagation(),I(null),ee(ke,{archivedBucket:c})},cs=Ge=>{Ge.preventDefault(),Ge.stopPropagation(),I(null),ee(ke,{archivedBucket:c,hardDelete:!0,skipConfirm:!0})},js=Ge=>{Ge.preventDefault(),Ge.stopPropagation()},Ss=Ge=>{Ge.preventDefault(),Ge.stopPropagation()},Fs=Ge=>{Ge.preventDefault(),Ge.stopPropagation(),Be?.vscode?.executeCommand("openchamber.openSessionInEditor",ke.id,Te)},Bn=Ge=>{if(Ce.current){Ce.current=!1;return}if(se){if(Ge?.preventDefault(),Ge?.stopPropagation(),Ge?.shiftKey){const ks=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map($s=>$s.getAttribute("data-session-row")).filter($s=>typeof $s=="string"&&$s.length>0),Os=Wn.getState().anchorId,qs=new Map;qs.set(ke.id,Ye(n)),We(Os,ke.id,ks,Se??null,qs);return}ae(ke.id,Se??null,Ye(n));return}S(ke.id,Se,a)},sn=Ge=>{Ge.defaultPrevented||Ge.target?.closest('button, a, input, [role="menuitem"], [role="menu"]')||Bn(Ge)},Kn=Ge=>{(Ge.button===2||Ge.button===0&&Ge.ctrlKey&&!se)&&(Ce.current=!0)},Pn=Ge=>{ie&&Ge.pointerType==="touch"&&ue(!0)},vn=Ge=>{ie&&Ge.pointerType==="touch"&&ue(!1)},Ks=({Item:Ge,Separator:ds,Sub:ks,SubTrigger:Os,SubContent:qs})=>s.jsxs(s.Fragment,{children:[s.jsxs(Ge,{onClick:()=>{T.current={id:ke.id,title:Te}},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(Ge,{onClick:()=>C(ke.id),className:"[&>svg]:mr-1",children:[rt?s.jsx(A,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(A,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(rt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Ve.share?s.jsxs(s.Fragment,{children:[s.jsx(Ge,{onClick:()=>{Ve.share?.url&&_(Ve.share.url,ke.id)},className:"[&>svg]:mr-1",children:P===ke.id?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(Ge,{onClick:()=>v(ke.id),className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Ge,{onClick:()=>y(Ve),className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(Ge,{onClick:()=>{Gt()},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),_t?s.jsxs(Ge,{onClick:()=>Zt(!0),className:"[&>svg]:mr-1",children:[s.jsx(nk,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Se&&!c?(()=>{const $s=B(Se),gn=D(Se,ke.id);return s.jsxs(s.Fragment,{children:[s.jsx(ds,{}),s.jsxs(ks,{children:[s.jsxs(Os,{className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(qs,{className:"min-w-[180px]",children:[$s.length===0?s.jsx(Ge,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):$s.map(Cs=>s.jsxs(Ge,{onClick:()=>{gn===Cs.id?W(Se,ke.id):U(Se,Cs.id,ke.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:Cs.name}),gn===Cs.id?s.jsx(A,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},Cs.id)),s.jsx(ds,{}),s.jsxs(Ge,{onClick:()=>{const Cs=L(Se);Cs&&U(Se,Cs.id,ke.id)},children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),gn?s.jsxs(Ge,{onClick:()=>{W(Se,ke.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,Y?null:s.jsxs(Ge,{disabled:!Se,onClick:()=>{Se&&M(Se,{mode:"chat",dedupeKey:`session:${ke.id}`,label:Te,sessionTitleFallback:Te})},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),Ne?s.jsxs(Ge,{disabled:!Se,onClick:Me,className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(ds,{}),c?null:s.jsxs(Ge,{className:"[&>svg]:mr-1",onClick:()=>ee(ke,{archivedBucket:c}),children:[s.jsx(A,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),s.jsxs(Ge,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>ee(ke,{archivedBucket:c,hardDelete:!0}),children:[s.jsx(A,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),jn=s.jsx(Zs,{align:"end",className:"min-w-[180px]",finalFocus:()=>!(R||De.current),children:Ks({Item:ls,Separator:$r,Sub:nx,SubTrigger:rx,SubContent:ix})}),nn=s.jsx(yd,{children:s.jsx(vd,{className:"app-region-no-drag z-50",children:s.jsx(jd,{"data-slot":"dropdown-menu-content",finalFocus:()=>!(R||De.current),style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:Pe(Kd,"min-w-[180px]"),children:Ks({Item:({className:Ge,...ds})=>s.jsx(fp,{className:Pe(ex,Ge),...ds}),Separator:({className:Ge,...ds})=>s.jsx(mp,{className:Pe(tx,Ge),...ds}),Sub:hp,SubTrigger:({className:Ge,children:ds,...ks})=>s.jsxs(pp,{className:Pe(sx,Ge),...ks,children:[ds,s.jsx(A,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:Ge,children:ds,...ks})=>s.jsx(yd,{children:s.jsx(vd,{className:"app-region-no-drag z-50",children:s.jsx(jd,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:Pe(Kd,Ge),...ks,children:ds})})})})})})});return s.jsxs(i.Fragment,{children:[s.jsx(_2,{sessionId:ke.id,sessionDirectory:Se??null,sessionTitle:Te,children:s.jsxs(dp,{open:ss,onOpenChange:xe,onOpenChangeComplete:Hs,children:[s.jsxs(up,{render:s.jsx("div",{"data-session-row":ke.id,"data-session-scope":Se??"","data-session-archived":c?"1":"0",onClick:sn,className:Pe("group relative my-0.5 flex cursor-pointer items-center rounded-md py-1 pr-1.5","-ml-3",r>0?"pl-[32px]":"pl-[18px]",qt&&!Le&&"bg-primary/10",Le&&"bg-interactive-selection")}),children:[ms,Us,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:me?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onPointerDown:Pn,onPointerUp:vn,onPointerCancel:vn,onMouseDown:Kn,onClick:Ge=>Bn(Ge),onDoubleClick:Ge=>{Ge.stopPropagation(),N(ke.id,Te)},className:Pe("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none transition-[padding]",be&&"bg-interactive-hover/70",te?Y?ge:ce:ge),children:s.jsxs("div",{className:Pe("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:Pe("block min-w-0 flex-1 truncate typography-ui-label font-normal",qt?"text-primary":"text-foreground"),children:Po(Te,u)}),te?s.jsxs("span",{className:"ml-2 inline-flex flex-shrink-0 items-center gap-1 text-[0.72rem] text-muted-foreground/75",children:[is,Ct]}):null,te?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsxs("span",{className:Pe("inline-flex items-center gap-1 whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",Ft?"opacity-0":Oe),children:[is,Ct]})}),Nt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(A,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Nt})]}):null]})})}),Y?null:s.jsx(Tt,{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:Pe("flex items-center gap-3 text-left text-muted-foreground",J?.projectLabel?"justify-between":"justify-start"),children:[J?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:J.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:Vt})]}),J?.branchLabel?s.jsx("div",{className:"flex items-center gap-3 text-left text-muted-foreground justify-start",children: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(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:J.branchLabel})]})})}):null]})})]}):s.jsxs("button",{type:"button",onPointerDown:Pn,onPointerUp:vn,onPointerCancel:vn,onMouseDown:Kn,onClick:Ge=>Bn(Ge),onDoubleClick:Ge=>{Ge.stopPropagation(),N(ke.id,Te)},className:Pe("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none transition-[padding]",be&&"bg-interactive-hover/70",te?Y?ge:ce:ge),children:[s.jsxs("div",{className:Pe("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:Pe("block min-w-0 flex-1 truncate typography-ui-label font-normal",qt?"text-primary":"text-foreground"),children:Po(Te,u)}),Nt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(A,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Nt})]}):null]}),me?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:Pe("flex min-w-0 items-center gap-1.5 overflow-hidden",ns&&Ke?"pl-4":""),children:[is,s.jsx("span",{className:"flex-shrink-0",children:Vt}),Fe?s.jsx("span",{className:"truncate",children:J?.projectLabel}):null,z?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:J?.branchLabel})]}):null]})})]})}),Ms&&!ie?s.jsx("div",{className:Pe("absolute top-1/2 -translate-y-1/2 z-10",me?"right-0":"right-[30px]"),children:Ms}):null,s.jsxs("div",{className:Pe("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",Ft||te&&!Y?"opacity-100":Pe("opacity-0",_e)),children:[Re?s.jsx(rk,{archiveLabel:e("sessions.sidebar.bulkActions.archive"),deleteLabel:e("sessions.sidebar.bulkActions.delete"),buttonSizeClass:me&&!te?"h-4 w-4":"h-6 w-6",iconSizeClass:me&&!te?"h-2.5 w-2.5":"h-3.5 w-3.5",onPointerDown:zt,onMouseDown:xt,onArchive:ps,onDelete:cs}):null,pe?s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe("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",me&&!te?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:js,onMouseDown:Ss,onClick:Fs,onKeyDown:Ge=>Ge.stopPropagation(),children:s.jsx(A,{name:"external-link",className:Pe(me&&!te?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Tt,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(en,{open:Ht,onOpenChange:Tn,onOpenChangeComplete:Hs,children:[s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe("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",me&&!te?Ft?"h-4 w-4 opacity-100":Pe("h-4 w-4 opacity-0",_e):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:ut,onMouseDown:wt,onClick:tt,onKeyDown:Ge=>Ge.stopPropagation(),children:s.jsx(A,{name:"more-2",className:Pe(me&&!te?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),jn]})]})]}),nn]})}),Ke&&Je?n.children.map(Ge=>{const ds=ye?ye(Ge):{subtreeContainsActive:oe,subtreeContainsEditing:ve,menuOpenSessionId:ne,nodeStructureKey:""};return H(Ge,r+1,Se??o,a,c,void 0,re,ds)}):null,s.jsx(_s,{open:Qe,onOpenChange:st,children:s.jsxs(Vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(tn,{children:[s.jsx(Gs,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(dn,{children:Mt===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Mt}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Mt})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:pt,onChange:Ge=>jt(Ge.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(xr,{children:[s.jsx(ze,{type:"button",onClick:()=>st(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ze,{type:"button",onClick:()=>{st(!1),os(pt)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),_t?s.jsx(sk,{session:Ve,open:hs,onOpenChange:Zt}):null]},ke.id)}const Af=t=>ws(t.session.directory??null),ok=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),ak=t=>{if(!t.openSidebarMenuKey)return null;const e=t.archivedBucket?"archived":"active",n=`${t.renderContext??"project"}:${e}:`;return t.openSidebarMenuKey.startsWith(n)?t.openSidebarMenuKey.slice(n.length):null},oa=t=>t.menuOpenSessionId??ak(t),qi=(t,e,n)=>e?n.has(t.node.session.id)?!0:Yr(t.node,e):!1,$a=(t,e,n,r,o)=>{if(t.session.id!==e.session.id)return!0;const a=o(t);if(n.has(a)!==r.has(a)||t.children.length!==e.children.length)return!0;for(let c=0;c<t.children.length;c+=1)if($a(t.children[c],e.children[c],n,r,o))return!0;return!1},Bh=(t,e,n,r)=>{if(t.session.id!==e.session.id)return!0;const o=t.session.id;if((n.get(o)??t.session)!==(r.get(o)??e.session)||t.children.length!==e.children.length)return!0;for(let a=0;a<t.children.length;a+=1)if(Bh(t.children[a],e.children[a],n,r))return!0;return!1},lk=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return $a(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${t.renderContext??"project"}:${n}:${o.session.id}`)||$a(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${e.renderContext??"project"}:${r}:${o.session.id}`)},ck=(t,e)=>{if(t.node.session.id!==e.node.session.id||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket||(t.renderContext??"project")!==(e.renderContext??"project")||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks||t.nodeStructureKey!==e.nodeStructureKey||Af(t.node)!==Af(e.node)||!ok(t.secondaryMeta,e.secondaryMeta)||t.liveSessionById!==e.liveSessionById&&Bh(t.node,e.node,t.liveSessionById,e.liveSessionById)||t.pinnedSessionIds!==e.pinnedSessionIds&&$a(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,n=>n.session.id)||t.expandedParents!==e.expandedParents&&lk(t,e)||t.currentSessionId!==e.currentSessionId&&(qi(t,t.currentSessionId,t.subtreeContainsActive)||qi(e,e.currentSessionId,e.subtreeContainsActive))||t.editingId!==e.editingId&&(qi(t,t.editingId,t.subtreeContainsEditing)||qi(e,e.editingId,e.subtreeContainsEditing))||t.editTitle!==e.editTitle&&(qi(t,t.editingId,t.subtreeContainsEditing)||qi(e,e.editingId,e.subtreeContainsEditing))||t.copiedSessionId!==e.copiedSessionId&&(Yr(t.node,t.copiedSessionId)||Yr(e.node,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=oa(t),r=oa(e);if(Yr(t.node,n)||Yr(e.node,r))return!1}if(t.renamingFolderId!==e.renamingFolderId){const n=oa(t),r=oa(e);if(Yr(t.node,n)||Yr(e.node,r))return!1}return t.setEditingId===e.setEditingId&&t.setEditTitle===e.setEditTitle&&t.handleSaveEdit===e.handleSaveEdit&&t.handleCancelEdit===e.handleCancelEdit&&t.toggleParent===e.toggleParent&&t.handleSessionSelect===e.handleSessionSelect&&t.handleSessionDoubleClick===e.handleSessionDoubleClick&&t.togglePinnedSession===e.togglePinnedSession&&t.handleShareSession===e.handleShareSession&&t.handleCopyShareUrl===e.handleCopyShareUrl&&t.handleUnshareSession===e.handleUnshareSession&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.getFoldersForScope===e.getFoldersForScope&&t.getSessionFolderId===e.getSessionFolderId&&t.removeSessionFromFolder===e.removeSessionFromFolder&&t.addSessionToFolder===e.addSessionToFolder&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.openContextPanelTab===e.openContextPanelTab&&t.handleDeleteSession===e.handleDeleteSession&&t.renderSessionNode===e.renderSessionNode},dk=i.memo(ik,ck);function uk(t){return t.stopPropagation()}function fk(t){const e=gt.c(71),{t:n}=yt(),{value:r,setValue:o,showDeletionDialog:a,setShowDeletionDialog:c,onConfirm:l}=t;let d,f,m,u,p,x,b,w,g,h;if(e[0]!==o||e[1]!==n||e[2]!==r){const M=n("sessions.sidebar.session.untitled");u=_s,g=!!r,e[13]!==o?(h=ie=>{ie||o(null)},e[13]=o,e[14]=h):h=e[14],m=Vs,b=!1,w="max-w-sm gap-5",f=tn;let ee;e[15]!==n||e[16]!==r?.archivedBucket?(ee=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=ee):ee=e[17],e[18]!==ee?(x=s.jsx(Gs,{children:ee}),e[18]=ee,e[19]=x):x=e[19],d=dn,p=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||M,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||M,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||M,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||M,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||M}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||M}),e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=f,e[5]=m,e[6]=u,e[7]=p,e[8]=x,e[9]=b,e[10]=w,e[11]=g,e[12]=h}else d=e[3],f=e[4],m=e[5],u=e[6],p=e[7],x=e[8],b=e[9],w=e[10],g=e[11],h=e[12];let k;e[20]!==d||e[21]!==p?(k=s.jsx(d,{children:p}),e[20]=d,e[21]=p,e[22]=k):k=e[22];let j;e[23]!==f||e[24]!==x||e[25]!==k?(j=s.jsxs(f,{children:[x,k]}),e[23]=f,e[24]=x,e[25]=k,e[26]=j):j=e[26];let S;e[27]!==c||e[28]!==a?(S=()=>c(!a),e[27]=c,e[28]=a,e[29]=S):S=e[29];const N=!a;let C;e[30]!==a?(C=a?s.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=a,e[31]=C):C=e[31];let y;e[32]!==n?(y=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=y):y=e[33];let P;e[34]!==C||e[35]!==y||e[36]!==S||e[37]!==N?(P=s.jsxs("button",{type:"button",onClick:S,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":N,children:[C,y]}),e[34]=C,e[35]=y,e[36]=S,e[37]=N,e[38]=P):P=e[38];let _;e[39]!==o?(_=()=>o(null),e[39]=o,e[40]=_):_=e[40];let v;e[41]!==n?(v=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=v):v=e[42];let F;e[43]!==_||e[44]!==v?(F=s.jsx("button",{type:"button",onClick:_,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:v}),e[43]=_,e[44]=v,e[45]=F):F=e[45];let I;e[46]!==l?(I=()=>{l()},e[46]=l,e[47]=I):I=e[47];let R;e[48]!==n||e[49]!==r?.archivedBucket?(R=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=R):R=e[50];let B;e[51]!==I||e[52]!==R?(B=s.jsx("button",{type:"button",onClick:I,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:R}),e[51]=I,e[52]=R,e[53]=B):B=e[53];let D;e[54]!==F||e[55]!==B?(D=s.jsxs("div",{className:"flex items-center gap-2",children:[F,B]}),e[54]=F,e[55]=B,e[56]=D):D=e[56];let W;e[57]!==P||e[58]!==D?(W=s.jsxs(xr,{className:"w-full sm:items-center sm:justify-between",children:[P,D]}),e[57]=P,e[58]=D,e[59]=W):W=e[59];let U;e[60]!==m||e[61]!==b||e[62]!==W||e[63]!==w||e[64]!==j?(U=s.jsxs(m,{showCloseButton:b,className:w,children:[j,W]}),e[60]=m,e[61]=b,e[62]=W,e[63]=w,e[64]=j,e[65]=U):U=e[65];let L;return e[66]!==u||e[67]!==U||e[68]!==g||e[69]!==h?(L=s.jsx(u,{open:g,onOpenChange:h,children:U}),e[66]=u,e[67]=U,e[68]=g,e[69]=h,e[70]=L):L=e[70],L}function mk(t){const e=gt.c(57),{t:n}=yt(),{value:r,setValue:o,showDeletionDialog:a,setShowDeletionDialog:c,onConfirm:l}=t,d=r?.archivedBucket===!0,f=r?.sessionCount??0;let m;e[0]!==d||e[1]!==f||e[2]!==n?(m=n(d?f===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":f===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=f,e[2]=n,e[3]=m):m=e[3];const u=m;let p;e[4]!==d||e[5]!==f||e[6]!==n?(p=d?f===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:f}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:f}):f===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:f}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:f}),e[4]=d,e[5]=f,e[6]=n,e[7]=p):p=e[7];const x=p,b=!!r;let w;e[8]!==o?(w=L=>{L||o(null)},e[8]=o,e[9]=w):w=e[9];let g;e[10]!==u?(g=s.jsx(Gs,{children:u}),e[10]=u,e[11]=g):g=e[11];let h;e[12]!==x?(h=s.jsx(dn,{children:x}),e[12]=x,e[13]=h):h=e[13];let k;e[14]!==g||e[15]!==h?(k=s.jsxs(tn,{children:[g,h]}),e[14]=g,e[15]=h,e[16]=k):k=e[16];let j;e[17]!==c||e[18]!==a?(j=()=>c(!a),e[17]=c,e[18]=a,e[19]=j):j=e[19];const S=!a;let N;e[20]!==a?(N=a?s.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=a,e[21]=N):N=e[21];let C;e[22]!==n?(C=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=C):C=e[23];let y;e[24]!==C||e[25]!==j||e[26]!==S||e[27]!==N?(y=s.jsxs("button",{type:"button",onClick:j,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":S,children:[N,C]}),e[24]=C,e[25]=j,e[26]=S,e[27]=N,e[28]=y):y=e[28];let P;e[29]!==o?(P=()=>o(null),e[29]=o,e[30]=P):P=e[30];let _;e[31]!==n?(_=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=_):_=e[32];let v;e[33]!==P||e[34]!==_?(v=s.jsx("button",{type:"button",onClick:P,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:_}),e[33]=P,e[34]=_,e[35]=v):v=e[35];let F;e[36]!==l?(F=()=>{l()},e[36]=l,e[37]=F):F=e[37];let I;e[38]!==d||e[39]!==n?(I=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=I):I=e[40];let R;e[41]!==F||e[42]!==I?(R=s.jsx("button",{type:"button",onClick:F,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:I}),e[41]=F,e[42]=I,e[43]=R):R=e[43];let B;e[44]!==v||e[45]!==R?(B=s.jsxs("div",{className:"flex items-center gap-2",children:[v,R]}),e[44]=v,e[45]=R,e[46]=B):B=e[46];let D;e[47]!==y||e[48]!==B?(D=s.jsxs(xr,{className:"w-full sm:items-center sm:justify-between",children:[y,B]}),e[47]=y,e[48]=B,e[49]=D):D=e[49];let W;e[50]!==D||e[51]!==k?(W=s.jsxs(Vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[k,D]}),e[50]=D,e[51]=k,e[52]=W):W=e[52];let U;return e[53]!==b||e[54]!==W||e[55]!==w?(U=s.jsx(_s,{open:b,onOpenChange:w,children:W}),e[53]=b,e[54]=W,e[55]=w,e[56]=U):U=e[56],U}function hk(t){const e=gt.c(36),{t:n}=yt(),{value:r,setValue:o,onConfirm:a}=t,c=!!r;let l;e[0]!==o?(l=N=>{N||o(null)},e[0]=o,e[1]=l):l=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let f;e[4]!==d?(f=s.jsx(Gs,{children:d}),e[4]=d,e[5]=f):f=e[5];let m;e[6]!==n||e[7]!==r?(m=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=m):m=e[8];let u;e[9]!==m?(u=s.jsx(dn,{children:m}),e[9]=m,e[10]=u):u=e[10];let p;e[11]!==f||e[12]!==u?(p=s.jsxs(tn,{children:[f,u]}),e[11]=f,e[12]=u,e[13]=p):p=e[13];let x;e[14]!==o?(x=()=>o(null),e[14]=o,e[15]=x):x=e[15];let b;e[16]!==n?(b=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=b):b=e[17];let w;e[18]!==x||e[19]!==b?(w=s.jsx("button",{type:"button",onClick:x,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:b}),e[18]=x,e[19]=b,e[20]=w):w=e[20];let g;e[21]!==n?(g=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=g):g=e[22];let h;e[23]!==a||e[24]!==g?(h=s.jsx("button",{type:"button",onClick:a,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:g}),e[23]=a,e[24]=g,e[25]=h):h=e[25];let k;e[26]!==h||e[27]!==w?(k=s.jsxs(xr,{children:[w,h]}),e[26]=h,e[27]=w,e[28]=k):k=e[28];let j;e[29]!==k||e[30]!==p?(j=s.jsxs(Vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,k]}),e[29]=k,e[30]=p,e[31]=j):j=e[31];let S;return e[32]!==c||e[33]!==l||e[34]!==j?(S=s.jsx(_s,{open:c,onOpenChange:l,children:j}),e[32]=c,e[33]=l,e[34]=j,e[35]=S):S=e[35],S}const pk=t=>{const e=gt.c(46),{selectedCount:n,scopeKey:r,scopeFolders:o,archivedBucket:a,onMoveToFolder:c,onCreateFolderAndMove:l,onRemoveFromFolder:d,canRemoveFromFolder:f,onDelete:m,onDone:u}=t,{t:p}=yt(),x=!!r&&!a;let b;e[0]!==a||e[1]!==p?(b=p(a?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=a,e[1]=p,e[2]=b):b=e[2];const w=b;let g;e[3]!==n||e[4]!==p?(g=p("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=p,e[5]=g):g=e[5];let h;e[6]!==g?(h=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:g}),e[6]=g,e[7]=h):h=e[7];let k;e[8]!==x||e[9]!==f||e[10]!==l||e[11]!==c||e[12]!==d||e[13]!==o||e[14]!==p?(k=x?s.jsxs(en,{children:[s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(Xs,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":p("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(A,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Tt,{side:"top",sideOffset:4,children:s.jsx("p",{children:p("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Zs,{align:"end",className:"min-w-[180px]",children:[o.length===0?s.jsx(ls,{disabled:!0,className:"text-muted-foreground",children:p("sessions.sidebar.folders.none")}):o.map(W=>s.jsx(ls,{onClick:()=>c(W.id),children:s.jsx("span",{className:"flex-1 truncate",children:W.name})},W.id)),s.jsx($r,{}),s.jsxs(ls,{onClick:l,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.newFolderEllipsis")]}),f?s.jsxs(ls,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=x,e[9]=f,e[10]=l,e[11]=c,e[12]=d,e[13]=o,e[14]=p,e[15]=k):k=e[15];let j;e[16]===Symbol.for("react.memo_cache_sentinel")?(j=Pe("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=j):j=e[16];let S;e[17]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(A,{name:"delete-bin",className:"h-4 w-4"}),e[17]=S):S=e[17];let N;e[18]!==w||e[19]!==m?(N=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:j,"aria-label":w,children:S})}),e[18]=w,e[19]=m,e[20]=N):N=e[20];let C;e[21]!==w?(C=s.jsx(Tt,{side:"top",sideOffset:4,children:s.jsx("p",{children:w})}),e[21]=w,e[22]=C):C=e[22];let y;e[23]!==N||e[24]!==C?(y=s.jsxs(At,{children:[N,C]}),e[23]=N,e[24]=C,e[25]=y):y=e[25];let P;e[26]!==p?(P=p("sessions.sidebar.header.actions.exitSelection"),e[26]=p,e[27]=P):P=e[27];let _;e[28]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(A,{name:"close",className:"h-4 w-4"}),e[28]=_):_=e[28];let v;e[29]!==u||e[30]!==P?(v=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":P,children:_})}),e[29]=u,e[30]=P,e[31]=v):v=e[31];let F;e[32]!==p?(F=p("sessions.sidebar.header.actions.exitSelection"),e[32]=p,e[33]=F):F=e[33];let I;e[34]!==F?(I=s.jsx(Tt,{side:"top",sideOffset:4,children:s.jsx("p",{children:F})}),e[34]=F,e[35]=I):I=e[35];let R;e[36]!==v||e[37]!==I?(R=s.jsxs(At,{children:[v,I]}),e[36]=v,e[37]=I,e[38]=R):R=e[38];let B;e[39]!==R||e[40]!==k||e[41]!==y?(B=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[k,y,R]}),e[39]=R,e[40]=k,e[41]=y,e[42]=B):B=e[42];let D;return e[43]!==B||e[44]!==h?(D=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[h,B]}),e[43]=B,e[44]=h,e[45]=D):D=e[45],D},gk=t=>{const{t:e}=yt(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:o,addSessionsToFolder:a,removeSessionsFromFolders:c,createFolderAndStartRename:l,archiveSessions:d,deleteSessions:f,setBulkDeleteConfirm:m}=t,u=Wn(I=>I.enabled),p=Wn(I=>I.selectedIds.size),x=p>0,b=Wn(I=>I.selectedIds),w=Wn(I=>I.scopeKey),g=i.useCallback(()=>{Wn.getState().toggleMode()},[]),h=i.useCallback(()=>{Wn.getState().disable()},[]),k=i.useMemo(()=>{if(!x||typeof document>"u")return!1;let I=!1,R=!1;for(const B of b){const D=document.querySelectorAll(`[data-session-row="${CSS.escape(B)}"]`);for(const W of D)W.getAttribute("data-session-archived")==="1"?R=!0:I=!0}return R&&!I},[x,b]),j=i.useMemo(()=>{if(w)return w;if(!x||typeof document>"u")return null;for(const I of b){const B=document.querySelector(`[data-session-row="${CSS.escape(I)}"]`)?.getAttribute("data-session-scope");if(B&&B.length>0)return B}return null},[x,b,w]),S=i.useMemo(()=>j?o[j]??[]:[],[o,j]),N=i.useMemo(()=>{if(!j||!x)return!1;const I=o[j]??[];for(const R of I)for(const B of R.sessionIds)if(b.has(B))return!0;return!1},[o,j,x,b]),C=i.useCallback(I=>{!j||!x||a(j,I,Array.from(b))},[a,b,j,x]),y=i.useCallback(()=>{if(!j||!x)return;const I=l(j);I&&a(j,I.id,Array.from(b))},[a,l,b,j,x]),P=i.useCallback(()=>{!j||!x||c(j,Array.from(b))},[c,b,j,x]),_=i.useCallback(async()=>{const I=Array.from(b);if(I.length!==0){if(k){const{deletedIds:R,failedIds:B}=await f(I);R.length>0&&le.success(R.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:R.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:R.length})),B.length>0&&le.error(B.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:B.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:B.length}))}else{const{archivedIds:R,failedIds:B}=await d(I);R.length>0&&le.success(R.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:R.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:R.length})),B.length>0&&le.error(B.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:B.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:B.length}))}Wn.getState().clear()}},[d,k,f,b,e]),v=i.useCallback(()=>{if(!x)return;const I=b.size;if(!r){_();return}m({sessionCount:I,archivedBucket:k})},[k,_,b,r,m,x]),F=i.useCallback(async()=>{m(null),await _()},[_]);return i.useEffect(()=>{if(!u)return;const I=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),R=B=>{if(n)return;const D=B.target;if(D&&(D.tagName==="INPUT"||D.tagName==="TEXTAREA"||D.isContentEditable))return;const W=I?B.metaKey:B.ctrlKey;if(B.key==="Escape"){B.preventDefault(),Wn.getState().disable();return}if(W&&B.key==="Backspace"){B.preventDefault(),v();return}if(W&&(B.key==="a"||B.key==="A")){const U=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(U.length===0)return;B.preventDefault();const M=Wn.getState().scopeKey??U[0]?.getAttribute("data-session-scope")??null,ee=te=>M?te.getAttribute("data-session-scope")===M:!0,ie=U.filter(ee).map(te=>te.getAttribute("data-session-row")).filter(te=>typeof te=="string"&&te.length>0);if(ie.length===0)return;Wn.getState().replaceAll(ie,M||null)}};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[v,n,u]),{selectionModeEnabled:u,hasSelection:x,selectedIdsSize:p,bulkScopeIsArchived:k,derivedSelectionScope:j,bulkScopeFolders:S,bulkCanRemoveFromFolder:N,handleToggleSelectionMode:g,handleExitSelectionMode:h,handleBulkMoveToFolder:C,handleBulkCreateFolderAndMove:y,handleBulkRemoveFromFolder:P,handleBulkDelete:v,confirmBulkDelete:F}},xk=2880*60*1e3,bk=t=>!!t.parentID,wk=t=>!!t.time?.archived,pc=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},yk=t=>[...t].sort((e,n)=>pc(n)-pc(e)),vk=(t,e=Date.now())=>{const n=e-xk,r=t.filter(o=>wk(o)||bk(o)?!1:pc(o)>=n);return yk(r)},Df="openchamber.shareOpinionToast.dismissed.v2",aa="oc.sessions.projectCollapse",Tf="oc.sessions.groupOrder",Pf="oc.sessions.groupCollapse",If="oc.sessions.activeSessionByProject",$l="oc.sessions.expandedParents.v2",jk="oc.sessions.expandedParents",Sk="oc.sessions.pinned",Nk=(t,e,n)=>{const r=new Set;for(const o of t){const a=ws(o.path)?.toLowerCase();a&&r.add(a)}if(n?.includeWorktrees===!1)return r;for(const o of e.values())for(const a of o){const c=ws(a.path)?.toLowerCase();c&&r.add(c)}return r},kk=(t,e,n)=>{if(t.time?.archived)return!0;const r=ws(ti(t))?.toLowerCase();return r?e.size===0?n?.allowEmptyDirectorySet??!0:e.has(r):n?.allowUnknownDirectory??!0},Ck=5*6e4,Rf=new Set,Lr=t=>{const e=i.useRef(t);return e.current=t,i.useCallback((...n)=>e.current(...n),[])},Ef=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:o=!1})=>{const{t:a}=yt(),[c,l]=i.useState(!1),[d,f]=i.useState(""),m=i.useRef(null),u=i.useRef(null),p=i.useRef(new Set),[x,b]=i.useState(null),[w,g]=i.useState(""),[h,k]=i.useState(null),[j,S]=i.useState(new Set),N=i.useMemo(()=>Qi(),[]),[C,y]=i.useState(new Set),[P,_]=i.useState(new Map),[v,F]=i.useState(new Map),I=Ee(Z=>Z.isNewWorktreeDialogOpen),R=Ee(Z=>Z.setNewWorktreeDialogOpen),[B,D]=i.useState(!1),[W,U]=i.useState(!1),[L,M]=i.useState(null),[ee,ie]=i.useState(null),[te,H]=i.useState(""),[J,re]=i.useState(null),[oe,ve]=i.useState(null),[ne,ye]=i.useState(null),he=xl(Z=>Z.ids),Fe=xl(Z=>Z.setIds),z=xl(Z=>Z.toggle),[K,Y]=i.useState(()=>{try{const Z=Qi().getItem(Pf);if(!Z)return new Set;const ot=JSON.parse(Z);return new Set(Array.isArray(ot)?ot.filter(Ze=>typeof Ze=="string"):[])}catch{return new Set}}),[me,Ne]=i.useState(()=>{try{const Z=Qi().getItem(Tf);if(!Z)return new Map;const ot=JSON.parse(Z),Ze=new Map;return Object.entries(ot).forEach(([bt,Ot])=>{Array.isArray(Ot)&&Ze.set(bt,Ot.filter(Ts=>typeof Ts=="string"))}),Ze}catch{return new Map}}),[Be,_e]=i.useState(()=>{try{const Z=Qi().getItem(If);if(!Z)return new Map;const ot=JSON.parse(Z),Ze=new Map;return Object.entries(ot).forEach(([bt,Ot])=>{typeof Ot=="string"&&Ot.length>0&&Ze.set(bt,Ot)}),Ze}catch{return new Map}}),[Oe,pe]=i.useState(new Map),Re=i.useRef(new Map),ge=i.useRef(0),ce=Js(Z=>Z.homeDirectory),Ce=Js(Z=>Z.currentDirectory),be=Js(Z=>Z.setDirectory),ue=Ds(Z=>Z.projects),De=Ds(Z=>Z.activeProjectId),T=Ds(Z=>Z.removeProject),V=Ds(Z=>Z.setActiveProjectIdOnly),we=Ds(Z=>Z.updateProjectMeta),E=Ds(Z=>Z.reorderProjects),de=Ee(Z=>Z.setActiveMainTab),fe=Ee(Z=>Z.openContextPanelTab),$=Ee(Z=>Z.setSettingsDialogOpen),ke=Ee(Z=>Z.toggleHelpDialog),Ve=Ee(Z=>Z.setAboutDialogOpen),Se=Ee(Z=>Z.setSessionSwitcherOpen),q=Ee(Z=>Z.setScheduledTasksDialogOpen),O=Ee(Z=>Z.openMultiRunLauncher),se=Ee(Z=>Z.notifyOnSubtasks),Le=Ee(Z=>Z.showDeletionDialog),ae=Ee(Z=>Z.setShowDeletionDialog),We=Za(d,120),Ye=i.useMemo(()=>We.trim().toLowerCase(),[We]),Qe=Ye.length>0,st=Zn(Z=>Z.collapsedFolderIds),pt=Zn(Z=>Z.foldersMap),jt=Zn(Z=>Z.getFoldersForScope),Et=Zn(Z=>Z.createFolder),Rt=Zn(Z=>Z.renameFolder),Ut=Zn(Z=>Z.deleteFolder),ts=Zn(Z=>Z.addSessionToFolder),Kt=Zn(Z=>Z.addSessionsToFolder),is=Zn(Z=>Z.removeSessionFromFolder),qt=Zn(Z=>Z.removeSessionsFromFolders),Te=Zn(Z=>Z.toggleFolderCollapse),Ke=Zn(Z=>Z.cleanupSessions),rt=Zn(Z=>Z.getSessionFolderId);i2({isSessionSearchOpen:c,setIsSessionSearchOpen:l,sessionSearchInputRef:u,sessionSearchContainerRef:m});const vt=bm(),Je=_c(),St=kc(),Xe=i.useMemo(()=>Cr(),[]),qe=kr(Z=>Z.status==="ready"),et=kr(Z=>Z.activeSessions),Vt=kr(Z=>Z.archivedSessions),Ct=ht(Z=>Z.currentSessionId),Ht=ht(Z=>!!Z.newSessionDraft?.open),ss=ht(Z=>Z.setCurrentSession),Xt=ht(Z=>Z.updateSessionTitle),Ft=ht(Z=>Z.shareSession),_t=ht(Z=>Z.unshareSession),hs=ht(Z=>Z.worktreeMetadata),Zt=ht(Z=>Z.availableWorktreesByProject),ns=ht(Z=>Z.openNewSessionDraft),gs=i.useCallback(Z=>{ns(Z),Xe&&window.dispatchEvent(new CustomEvent("openchamber:navigate",{detail:{view:"chat"}}))},[Xe,ns]),Mt=To(ql(Z=>({checkForUpdates:Z.checkForUpdates,available:Z.available,runtimeType:Z.runtimeType,info:Z.info,downloading:Z.downloading,downloaded:Z.downloaded,progress:Z.progress,error:Z.error,downloadUpdate:Z.downloadUpdate,restartToUpdate:Z.restartToUpdate}))),Bt=i.useMemo(()=>Nk(ue,Zt,{includeWorktrees:!Xe}),[Zt,Xe,ue]),$t=i.useMemo(()=>{const Z=new Map(St.map(bt=>[bt.id,bt])),ot=et.map(bt=>{const Ot=Z.get(bt.id);return Ot?ox(Ot,bt):bt}),Ze=new Set(ot.map(bt=>bt.id));return St.forEach(bt=>{Ze.has(bt.id)||ot.push(bt)}),ot.filter(bt=>kk(bt,Bt,{allowUnknownDirectory:!Xe,allowEmptyDirectorySet:!Xe}))},[et,Xe,Bt,St]),os=i.useMemo(()=>[...et,...Vt],[Vt,et]),Gt=i.useMemo(()=>St.map(Z=>{const ot=ws(Z.directory??null)??"";return`${Z.id}:${Z.title??""}:${Z.time?.archived?1:0}:${ot}`}).join("|"),[St]),Me=i.useRef(St);i.useEffect(()=>{Me.current=St},[Gt,St]);const ft=i.useMemo(()=>new Map(St.map(Z=>[Z.id,Z])),[St]),at=i.useMemo(()=>ue.map(Z=>`${Z.id}:${ws(Z.path)??""}`).join("|"),[ue]),[Nt,Pt]=i.useState(Xe?at:null),es=!Xe&&Nt!==at,[xs,Yt]=i.useState(new Set),Lt=i.useRef(!1);i.useEffect(()=>{Lt.current||(Lt.current=!0,Ta(Me.current))},[]),i.useEffect(()=>{let Z=!1;return(async()=>{const Ze=Ds.getState().projects;if(Ze.length===0||Xe){Z||(Yt(new Set),Pt(at));return}const bt=ht.getState().availableWorktreesByProject,Ot=new Map(bt),Ts=new Set,wn=3;let As=0;const _n=Array.from({length:wn},async()=>{for(;;){const $n=As;if(As+=1,$n>=Ze.length)return;const Ci=Ze[$n],Or=ws(Ci.path);if(Or)try{if(!(yn.getState().directories.get(Or)?.isGitRepo??await Nm(Or))){Ot.delete(Or);continue}const Di=await lx({id:Ci.id,path:Or});if(Z)return;Di.length===0?Ot.delete(Or):Ot.set(Or,Di)}catch{Ts.add(Or)}}});if(await Promise.all(_n),Z)return;const Xn=new Set(Ze.map($n=>ws($n.path)).filter(Boolean));for(const $n of Ot.keys())Xn.has($n)||Ot.delete($n);const Gr=[...Ot.values()].flat();cx(Ot,bt)||ht.setState({availableWorktrees:Gr,availableWorktreesByProject:Ot}),Yt(Ts),Pt(at)})(),()=>{Z=!0}},[Xe,at]),i.useEffect(()=>{let Z=null;const ot=Th(Ze=>{Ze.type==="scheduled-task-ran"&&(Z&&clearTimeout(Z),Z=setTimeout(()=>{Ta(Me.current)},500))});return()=>{Z&&clearTimeout(Z),ot()}},[]);const Es=i.useMemo(()=>pr(),[]),{isTablet:ms}=zr(),Ns=t||ms,{buildGroupSearchText:Us,filterSessionNodesForSearch:Ms,buildGroupedSessions:Tn}=r2({homeDirectory:ce,worktreeMetadata:hs,pinnedSessionIds:he,gitBranches:vt,isVSCode:Xe}),{scheduleCollapsedProjectsPersist:Hs}=m2({isVSCode:Xe,hasAuthoritativeGlobalSessions:qe,safeStorage:N,keys:{sessionExpanded:$l,sessionExpandedLegacy:jk,projectCollapse:aa,sessionPinned:Sk,groupOrder:Tf,projectActiveSession:If,groupCollapse:Pf},sessions:os,setPinnedSessionIds:Fe,groupOrderByProject:me,activeSessionByProject:Be,collapsedGroups:K,setExpandedParents:S,setCollapsedProjects:y}),xe=i.useMemo(()=>[...$t].sort((Z,ot)=>eo(Z,ot,he)),[$t,he]),tt=i.useMemo(()=>xe.map(Z=>`${Z.id}:${Z.time?.updated??0}`).join("|"),[xe]),ut=i.useRef(null),wt=i.useMemo(()=>{const Z=ut.current;if(Z&&Z.signature===tt)return Z.map;const ot=new Map(xe.map((Ze,bt)=>[Ze.id,bt]));return ut.current={signature:tt,map:ot},ot},[tt,xe]),zt=i.useMemo(()=>{const Z=new Map;return xe.forEach(ot=>{const Ze=ot.parentID;if(!Ze)return;const bt=Z.get(Ze)??[];bt.push(ot),Z.set(Ze,bt)}),Z.forEach(ot=>ot.sort((Ze,bt)=>eo(Ze,bt,he))),Z},[xe,he]),xt=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noSessions.description")})]}),ps=i.useMemo(()=>ue.find(Z=>Z.id===h)??null,[ue,h]),cs=i.useCallback(Z=>{h&&we(h,{label:Z.label,icon:Z.icon,color:Z.color,iconBackground:Z.iconBackground,defaultModel:Z.defaultModel??null})},[h,we]),js=i.useCallback(()=>{R(!0)},[R]),Ss=i.useCallback(()=>{const Z=To.getState();if(Z.available&&Z.info){D(!0);return}Mt.checkForUpdates().then(()=>{const{available:ot,error:Ze}=To.getState();if(Ze){le.error(a("sessions.sidebar.updateCheck.errorTitle"),{description:Ze});return}if(!ot){le.success(a("sessions.sidebar.updateCheck.latestVersion"));return}D(!0)})},[a,Mt]),Fs=i.useCallback(()=>{U(!0)},[]);i.useEffect(()=>{if(typeof window>"u")return;try{if(window.localStorage.getItem(Df)==="true")return;window.localStorage.setItem(Df,"true")}catch{}const Z=window.setTimeout(()=>{le.info(a("shareOpinion.toast.title"),{description:a("shareOpinion.toast.description"),action:{label:a("shareOpinion.actions.shareOpinion"),onClick:()=>U(!0)},duration:12e3})},1e3);return()=>window.clearTimeout(Z)},[a]);const Bn=i.useCallback(()=>{t&&Se(!1),$(!0)},[t,Se,$]),sn=Mt.available&&(Mt.runtimeType==="desktop"||Mt.runtimeType==="web"),Kn=ht(Z=>Z.deleteSession),Pn=ht(Z=>Z.deleteSessions),vn=ht(Z=>Z.archiveSession),Ks=ht(Z=>Z.archiveSessions),{copiedSessionId:jn,handleSessionSelect:nn,handleSessionDoubleClick:Ge,handleSaveEdit:ds,handleCancelEdit:ks,handleShareSession:Os,handleCopyShareUrl:qs,handleUnshareSession:$s,handleDeleteSession:gn,confirmDeleteSession:Cs}=o2({activeProjectId:De,currentDirectory:Ce,currentSessionId:Ct,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:c,sessionSearchQuery:d,setSessionSearchQuery:f,setIsSessionSearchOpen:l,setActiveProjectIdOnly:V,setDirectory:be,setActiveMainTab:de,setSessionSwitcherOpen:Se,setCurrentSession:ss,updateSessionTitle:Xt,shareSession:Ft,unshareSession:_t,deleteSession:Kn,deleteSessions:Pn,archiveSession:vn,archiveSessions:Ks,childrenMap:zt,showDeletionDialog:Le,setDeleteSessionConfirm:re,deleteSessionConfirm:J,setEditingId:b,setEditTitle:g,editingId:x,editTitle:w}),qn=i.useCallback(()=>{if(!oe)return;const{scopeKey:Z,folderId:ot}=oe;ve(null),Ut(Z,ot)},[oe,Ut]),us=i.useCallback(()=>{_r.requestDirectoryDialog()},[]);i.useEffect(()=>{if(!Ct)return;const ot=$t.find(bt=>bt.id===Ct)?.parentID;if(!ot)return;const Ze=[`project:active:${ot}`,`project:archived:${ot}`,`recent:active:${ot}`,`recent:archived:${ot}`];S(bt=>{if(Ze.every(Ts=>bt.has(Ts)))return bt;const Ot=new Set(bt);Ze.forEach(Ts=>Ot.add(Ts));try{N.setItem($l,JSON.stringify(Array.from(Ot)))}catch{}return Ot})},[Ct,$t,N]);const Ls=i.useCallback(Z=>{S(ot=>{const Ze=new Set(ot);Ze.has(Z)?Ze.delete(Z):Ze.add(Z);try{N.setItem($l,JSON.stringify(Array.from(Ze)))}catch{}return Ze})},[N]),br=i.useCallback((Z,ot)=>{if(!Z)return null;ot&&st.has(ot)&&Te(ot);const Ze=Et(Z,a("sessions.sidebar.folder.newFolderName"),ot);return ie(Ze.id),H(Ze.name),Ze},[st,Te,Et,a]),Yn=Lr(nn),un=Lr(Ge),Ar=Lr(ds),ni=Lr(ks),ri=Lr(Os),yi=Lr(qs),Dr=Lr($s),ys=Lr(gn),rn=Lr(br),rr=i.useCallback((Z,ot)=>{F(Ze=>{const bt=new Map(Ze);return bt.set(Z,ot+7),bt})},[]),Sn=i.useCallback(Z=>{F(ot=>{if(!ot.has(Z))return ot;const Ze=new Map(ot);return Ze.delete(Z),Ze})},[]),X=i.useCallback(Z=>{F(ot=>{let Ze=!1;const bt=new Map(ot),Ot=`${Z}:`;for(const Ts of bt.keys())Ts.startsWith(Ot)&&(bt.delete(Ts),Ze=!0);return Ze?bt:ot})},[]),it=i.useCallback(()=>{ge.current=Date.now()+150,F(new Map),y(()=>{const Z=new Set(ue.map(ot=>ot.id));try{N.setItem(aa,JSON.stringify(Array.from(Z)))}catch{}return Xe||Hs(Z),Z})},[ue,Xe,N,Hs]),dt=i.useCallback(()=>{ge.current=Date.now()+150,F(new Map),y(()=>{const Z=new Set;try{N.setItem(aa,JSON.stringify([]))}catch{}return Xe||Hs(Z),Z})},[Xe,N,Hs]),kt=i.useCallback(Z=>{ge.current=Date.now()+150,X(Z),y(ot=>{const Ze=new Set(ot);Ze.has(Z)?Ze.delete(Z):Ze.add(Z);try{N.setItem(aa,JSON.stringify(Array.from(Ze)))}catch{}return Xe||Hs(Ze),Ze})},[Xe,X,N,Hs]),Wt=i.useMemo(()=>ue.map(Z=>({...Z,normalizedPath:ws(Z.path)})).filter(Z=>!!Z.normalizedPath),[ue]),fs=i.useMemo(()=>Wt.map(Z=>Z.normalizedPath),[Wt]),bs=i.useMemo(()=>{const Z=new Set(Wt.map(ot=>ot.normalizedPath));if(!Xe)for(const ot of Zt.values())for(const Ze of ot){const bt=ws(Ze.path);bt&&Z.add(bt)}return[...Z].sort()},[Zt,Xe,Wt]),zs=i.useRef(null);i.useEffect(()=>{const Z=new Set(bs),ot=zs.current;if(zs.current=Z,!ot){Xe&&bs.length>0&&qd(bs,Me.current);return}const Ze=bs.filter(bt=>!ot.has(bt));Ze.length!==0&&qd(Ze,Me.current)},[Xe,bs]);const{github:Ys}=nr(),xn=$i(Z=>Z.status),fr=$i(Z=>Z.hasChecked),Nn=ax(fs),Wr=ur(Z=>Z.ensureEntry),Tr=ur(Z=>Z.setParams),kn=ur(Z=>Z.refreshTargets);h2({normalizedProjects:Wt,gitRepoStatus:Nn,setProjectRepoStatus:_,setProjectRootBranches:pe});const ln=ht(Z=>Z.isLoading),In=i.useMemo(()=>v2($t,Wt,Zt,Xe,Vt),[Vt,Zt,Xe,Wt,$t]);g2({isSessionsLoading:ln,hasAuthoritativeGlobalSessions:qe,isWorktreeTopologyLoading:es,normalizedProjects:Wt,ownership:In,availableWorktreesByProject:Zt,unresolvedWorktreeProjectPaths:xs,cleanupSessions:Ke});const{getSessionsForProject:fn,getArchivedSessionsForProject:ir}=p2({ownership:In});QS({normalizedProjects:Wt,ownership:In,isSessionsLoading:ln,hasAuthoritativeGlobalSessions:qe,isWorktreeTopologyLoading:es,unresolvedWorktreeProjectPaths:xs,foldersMap:pt,createFolder:Et,addSessionToFolder:ts,cleanupSessions:Ke});const Qn=i.useRef(!1);De&&P.has(De)&&(Qn.current=!!P.get(De));const Rn=dr(Z=>Z.showRecentSection),vi=dr(Z=>Z.showArchivedSessions),Pr=dr(Z=>Z.projectSortOrder),ji=Ds(Z=>Z.manualProjectOrder),zi=i.useMemo(()=>{const Z=[...Wt];switch(Pr){case"a-z":Z.sort((ot,Ze)=>{const bt=(ot.label||ot.path).toLowerCase(),Ot=(Ze.label||Ze.path).toLowerCase();return bt.localeCompare(Ot)});break;case"z-a":Z.sort((ot,Ze)=>{const bt=(ot.label||ot.path).toLowerCase();return(Ze.label||Ze.path).toLowerCase().localeCompare(bt)});break;case"date-added":Z.sort((ot,Ze)=>(Ze.addedAt??0)-(ot.addedAt??0));break;case"recent":Z.sort((ot,Ze)=>(Ze.lastOpenedAt??0)-(ot.lastOpenedAt??0));break;case"manual":{const ot=new Map(ji.map((Ze,bt)=>[Ze,bt]));Z.sort((Ze,bt)=>{const Ot=ot.get(Ze.id)??1/0,Ts=ot.get(bt.id)??1/0;return Ot-Ts});break}}return Z},[Wt,Pr,ji]),{projectSections:or,groupSearchDataByGroup:Cn,sectionsForRender:ar,searchMatchCount:on}=ZS({normalizedProjects:zi,getSessionsForProject:fn,getArchivedSessionsForProject:ir,availableWorktreesByProject:Zt,projectRepoStatus:P,projectRootBranches:Oe,lastRepoStatus:Qn.current,buildGroupedSessions:Tn,hasSessionSearchQuery:Qe,normalizedSessionSearchQuery:Ye,filterSessionNodesForSearch:Ms,buildGroupSearchText:Us,foldersMap:pt}),mn=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noMatches.description")})]});t2({projectSections:or,activeProjectId:De,activeSessionByProject:Be,setActiveSessionByProject:_e,currentSessionId:Ct,handleSessionSelect:nn,newSessionDraftOpen:Ht,mobileVariant:t,openNewSessionDraft:ns,setActiveMainTab:de,setSessionSwitcherOpen:Se});const{getOrderedGroups:Ur}=s2(me),Wi=i.useRef(!1);i.useEffect(()=>{if(Wi.current||or.length===0)return;const Z=or.flatMap(ot=>ot.groups.filter(Ze=>Ze.isArchivedBucket).map(Ze=>`${ot.project.id}:${Ze.id}`));Z.length>0&&Y(ot=>new Set([...ot,...Z])),Wi.current=!0},[or]);const Ir=i.useMemo(()=>{const Z=new Map,ot=new Map;return or.forEach(Ze=>{const bt=zm(Ze.project.label?.trim()||ho(Ze.project.normalizedPath,ce)||Ze.project.normalizedPath);Ze.groups.forEach(Ot=>{const Ts=Ot.branch&&Ot.branch!=="HEAD"&&Ot.branch!==bt?Ot.branch:null,wn={projectLabel:bt,branchLabel:Ts},As=_n=>{_n.forEach(Xn=>{const Gr=Ze.project.normalizedPath.length,$n=ot.get(Xn.session.id)??-1;Gr<$n||(Z.set(Xn.session.id,{node:Xn,projectId:Ze.project.id,groupDirectory:Ot.directory,secondaryMeta:wn}),ot.set(Xn.session.id,Gr),Xn.children.length>0&&As(Xn.children))})};As(Ot.sessions)})}),Z},[or,ce]),Vn=i.useMemo(()=>!Rn||Xe?[]:vk($t).sort((Z,ot)=>eo(Z,ot,he)),[Xe,he,$t,Rn]),Hr=i.useMemo(()=>{if(Xe||!Rn)return[];const Z=Vn,ot=bt=>{const Ot=Ir.get(bt.id),Ts=ws(bt.directory??null),wn=Ot?.node??{session:bt,children:[],worktree:null},_n=(Qe?Ms([wn],Ye):[wn])[0];if(!_n)return null;const Xn=Ot?.secondaryMeta?{projectLabel:Ot.secondaryMeta.projectLabel,branchLabel:Xe?null:Ot.secondaryMeta.branchLabel}:null;return{node:_n,projectId:Ot?.projectId??null,groupDirectory:Ot?.groupDirectory??Ts,secondaryMeta:Xn}},Ze=Z.map(ot).filter(bt=>bt!==null);return[{key:"active-now",title:a("sessions.sidebar.activity.recentTitle"),items:Ze}]},[Vn,Ms,Qe,Xe,Ye,Ir,Rn,a]),bn=i.useMemo(()=>Hr.some(Z=>Z.items.length>0),[Hr]),mr=i.useMemo(()=>new Set(Vn.map(Z=>Z.id)),[Vn]),Ui=i.useMemo(()=>[...mr],[mr]);hS({currentSessionId:Ct,sortedSessions:xe,recentSessionIds:Ui,ensureSessionRenderable:Je.ensureSessionRenderable});const Rr=i.useMemo(()=>vi?ar:ar.map(Z=>({...Z,groups:Z.groups.filter(ot=>!ot.isArchivedBucket)})),[ar,vi]),ii=i.useMemo(()=>{const Z=new Set;return Rr.forEach(ot=>{ot.groups.forEach(Ze=>{const bt=ws(Ze.directory??null),Ot=Ze.branch?.trim()||vt.get(bt||"")?.trim();!bt||!Ot||Z.add(Eo(bt,Ot))})}),[...Z]},[vt,Rr]),Si=Qy(ii);i.useEffect(()=>{if(!fr||!xn?.connected||!Ys)return;const Z=[],ot=Date.now();if(Rr.forEach(bt=>{C.has(bt.project.id)||bt.groups.forEach(Ot=>{const Ts=ws(Ot.directory??null),wn=Ot.branch?.trim()||vt.get(Ts||"")?.trim();if(!Ts||!wn)return;const As=Eo(Ts,wn),_n=ur.getState().entries[As],Xn=!!_n?.status?.pr,Gr=`${Ts}::${wn}`,$n=Math.max(_n?.lastRefreshAt??0,_n?.lastDiscoveryPollAt??0),Ci=!!(_n?.isInitialStatusResolved&&!Xn&&(!p.current.has(Gr)||ot-$n>=Ck));(!_n||!_n.isInitialStatusResolved||Ci)&&(Ci&&p.current.add(Gr),Z.push({directory:Ts,branch:wn}))})}),Z.length===0)return;const Ze=new Map;Z.forEach(bt=>{const Ot=Eo(bt.directory,bt.branch,bt.remoteName??null);Ze.has(Ot)||Ze.set(Ot,bt)}),Ze.forEach((bt,Ot)=>{Wr(Ot),Tr(Ot,{directory:bt.directory,branch:bt.branch,remoteName:bt.remoteName??null,canShow:!0,github:Ys,githubAuthChecked:fr,githubConnected:xn.connected})}),kn([...Ze.values()],{silent:!0,markInitialResolved:!0})},[C,Wr,Ys,fr,xn?.connected,vt,kn,Rr,Tr]);const wo=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",yo="h-4.5 w-4.5",Q=j2({isDesktopShellRuntime:Es,projectSections:or,projectHeaderSentinelRefs:Re}),je=Lr((Z,ot=0,Ze,bt,Ot=!1,Ts,wn="project",As)=>s.jsx(dk,{node:Z,depth:ot,groupDirectory:Ze,projectId:bt,archivedBucket:Ot,currentSessionId:Ct,pinnedSessionIds:he,expandedParents:j,hasSessionSearchQuery:Qe,normalizedSessionSearchQuery:Ye,notifyOnSubtasks:se,editingId:x,setEditingId:b,editTitle:w,setEditTitle:g,handleSaveEdit:Ar,handleCancelEdit:ni,toggleParent:Ls,handleSessionSelect:Yn,handleSessionDoubleClick:un,togglePinnedSession:z,handleShareSession:ri,copiedSessionId:jn,handleCopyShareUrl:yi,handleUnshareSession:Dr,openSidebarMenuKey:L,setOpenSidebarMenuKey:M,renamingFolderId:ee,getFoldersForScope:jt,getSessionFolderId:rt,removeSessionFromFolder:is,addSessionToFolder:ts,createFolderAndStartRename:rn,openContextPanelTab:fe,handleDeleteSession:ys,mobileVariant:t,alwaysShowActions:Ns,renderSessionNode:je,secondaryMeta:Ts,renderContext:wn,subtreeContainsActive:As?.subtreeContainsActive??Rf,subtreeContainsEditing:As?.subtreeContainsEditing??Rf,menuOpenSessionId:As?.menuOpenSessionId??null,nodeStructureKey:As?.nodeStructureKey??"",childRenderExtrasFor:As?.childRenderExtrasFor,liveSessionById:ft})),Ie=i.useCallback(Z=>{Sn(Z),Y(ot=>{const Ze=new Set(ot);return Ze.has(Z)?Ze.delete(Z):Ze.add(Z),Ze})},[Sn]),$e=i.useMemo(()=>{const Z=new Map;for(const[ot,Ze]of Si)Z.set(ot,{visualState:Ze.visualState,number:Ze.number,url:Ze.url,state:Ze.prState,draft:Ze.draft,title:Ze.title,base:Ze.base,head:Ze.head,checks:Ze.checks,canMerge:Ze.canMerge,mergeableState:Ze.mergeableState,repo:Ze.repo});return Z},[Si]),mt=i.useCallback((Z,ot,Ze,bt,Ot,Ts,wn)=>s.jsx(X2,{group:Z,groupKey:ot,projectId:Ze,hideGroupLabel:bt,compactBodyPadding:Ts,hasSessionSearchQuery:Qe,normalizedSessionSearchQuery:Ye,groupSearchDataByGroup:Cn,visibleSessionCount:v.get(ot),collapsedGroups:K,hideDirectoryControls:r,collapsedFolderIds:st,toggleFolderCollapse:Te,renameFolder:Rt,deleteFolder:Ut,showDeletionDialog:Le,setDeleteFolderConfirm:ve,renderSessionNode:je,projectRepoStatus:P,lastRepoStatus:Qn.current,showMoreGroupSessions:rr,resetGroupSessionLimit:Sn,mobileVariant:t,alwaysShowActions:Ns,activeProjectId:De,setActiveProjectIdOnly:V,setActiveMainTab:de,setSessionSwitcherOpen:Se,openNewSessionDraft:gs,addSessionToFolder:ts,createFolderAndStartRename:rn,renamingFolderId:ee,renameFolderDraft:te,setRenameFolderDraft:H,setRenamingFolderId:ie,pinnedSessionIds:he,expandedParents:j,sessionOrderIndex:wt,currentSessionId:Ct,editingId:x,editTitle:w,openSidebarMenuKey:L,liveSessionById:ft,prVisualStateByDirectoryBranch:$e,onToggleCollapsedGroup:Ie,dragHandleProps:Ot,scrollContainerRef:wn}),[Qe,Ye,Cn,v,K,r,st,Te,Rt,Ut,Le,je,P,rr,Sn,t,Ns,De,V,de,Se,gs,ts,rn,ee,te,he,j,wt,Ct,x,w,L,ft,$e,Ie]),It=!Xe&&Rn&&!Qe?s.jsx(cN,{sections:Hr,renderSessionNode:je,currentSessionId:Ct,editingId:x,openSidebarMenuKey:L,variant:"section"}):null,Qt=!!(ee||x||h),{selectionModeEnabled:Jt,hasSelection:vs,selectedIdsSize:wr,bulkScopeIsArchived:Er,derivedSelectionScope:Mr,bulkScopeFolders:sl,bulkCanRemoveFromFolder:nl,handleToggleSelectionMode:Jn,handleExitSelectionMode:Fr,handleBulkMoveToFolder:Ni,handleBulkCreateFolderAndMove:oi,handleBulkRemoveFromFolder:ki,handleBulkDelete:nd,confirmBulkDelete:vo}=gk({isInlineEditing:Qt,showDeletionDialog:Le,foldersMap:pt,addSessionsToFolder:Kt,removeSessionsFromFolders:qt,createFolderAndStartRename:br,archiveSessions:Ks,deleteSessions:Pn,setBulkDeleteConfirm:ye}),rl=i.useCallback(()=>{de("chat"),t&&Se(!1),O()},[t,O,de,Se]),Hi=i.useCallback(()=>{de("chat"),t&&Se(!1),ns()},[t,ns,de,Se]);return s.jsxs("div",{ref:m,className:Pe("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[s.jsx(Z2,{hideDirectoryControls:r,showRecentControls:!Xe,handleOpenDirectoryDialog:us,openNewSessionDraft:Hi,canOpenMultiRun:ue.length>0,openMultiRunLauncher:rl,headerActionIconClass:yo,headerActionButtonClass:wo,isSessionSearchOpen:c,setIsSessionSearchOpen:l,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:f,hasSessionSearchQuery:Qe,searchMatchCount:on,collapseAllProjects:it,expandAllProjects:dt,openScheduledTasksDialog:()=>q(!0),selectionModeEnabled:Jt,onToggleSelectionMode:Jn}),s.jsx(xN,{topContent:It,hasSharedSessions:bn,sectionsForRender:Rr,projectSections:or,activeProjectId:De,showOnlyMainWorkspace:o,hasSessionSearchQuery:Qe,emptyState:xt,searchEmptyState:mn,renderGroupSessions:mt,homeDirectory:ce,collapsedProjects:C,hideDirectoryControls:r,projectRepoStatus:P,isDesktopShellRuntime:Es,stuckProjectHeaders:Q,mobileVariant:t,alwaysShowActions:Ns,toggleProject:kt,setActiveProjectIdOnly:V,setActiveMainTab:de,setSessionSwitcherOpen:Se,openNewSessionDraft:gs,openNewWorktreeDialog:js,openProjectEditDialog:k,removeProject:T,projectHeaderSentinelRefs:Re,reorderProjects:E,projectSortOrder:Pr,getOrderedGroups:Ur,setGroupOrderByProject:Ne,openSidebarMenuKey:L,setOpenSidebarMenuKey:M,isInlineEditing:Qt}),Jt&&vs?s.jsx(pk,{selectedCount:wr,scopeKey:Mr,scopeFolders:sl,archivedBucket:Er,onMoveToFolder:Ni,onCreateFolderAndMove:oi,onRemoveFromFolder:ki,canRemoveFromFolder:nl,onDelete:nd,onDone:Fr}):null,s.jsx(dN,{onOpenSettings:Bn,onOpenShortcuts:ke,onOpenAbout:()=>Ve(!0),onOpenUpdate:Ss,onOpenShareOpinion:Fs,showRuntimeButtons:!Xe,showUpdateButton:sn}),s.jsx(k2,{open:W,onOpenChange:U}),s.jsx(Rm,{open:B,onOpenChange:D,info:Mt.info,downloading:Mt.downloading,downloaded:Mt.downloaded,progress:Mt.progress,error:Mt.error,onDownload:Mt.downloadUpdate,onRestart:Mt.restartToUpdate,runtimeType:Mt.runtimeType}),s.jsx(S2,{open:!!ps,onOpenChange:Z=>{Z||k(null)},project:ps,onSave:cs}),s.jsx(db,{open:I,onOpenChange:R,onWorktreeCreated:(Z,ot)=>{if(de("chat"),t&&Se(!1),ot?.sessionId){ss(ot.sessionId,Z);return}ns({directoryOverride:Z,preserveDirectoryOverride:!0})}}),s.jsx(YS,{}),s.jsx(fk,{value:J,setValue:re,showDeletionDialog:Le,setShowDeletionDialog:ae,onConfirm:Cs}),s.jsx(hk,{value:oe,setValue:ve,onConfirm:qn}),s.jsx(mk,{value:ne,setValue:ye,showDeletionDialog:Le,setShowDeletionDialog:ae,onConfirm:vo})]})},Ri=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,jr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Ak=()=>{const{t}=yt(),[e,n]=i.useState(!1),[r,o]=i.useState(!1),[a,c]=i.useState(null),[l,d]=i.useState([]),[f,m]=i.useState(!1),[u,p]=i.useState(!1),[x,b]=i.useState(!1),[w,g]=i.useState(!1),[h,k]=i.useState(new Set),j=ht(ce=>ce.getWorktreeMetadata),S=ht(ce=>ce.newSessionDraft),N=ht(ce=>ce.setNewSessionDraftTarget),C=ht(ce=>ce.setDraftBootstrapPendingDirectory),y=dx,P=mx,_=ht(ce=>ce.deleteSessions),v=ht(ce=>ce.archiveSessions),F=Ee(ce=>ce.showDeletionDialog),I=Ee(ce=>ce.setShowDeletionDialog),R=Js(ce=>ce.currentDirectory),B=Js(ce=>ce.homeDirectory),D=Js(ce=>ce.isHomeReady),W=Ds(ce=>ce.projects),U=Ds(ce=>ce.activeProjectId),{isMobile:L,isTablet:M,hasTouchInput:ee}=zr(),ie=L||M||ee,te=i.useMemo(()=>{const Ce=(U?W.find(be=>be.id===U)??null:null)?.path??R;return jr(Ce)},[U,R,W]),H=i.useCallback(ce=>{const be=jr(ce.projectDirectory)||te;return{id:(W.find(De=>jr(De.path)===be)??null)?.id??`path:${be}`,path:be}},[te,W]),J=w&&h.size>0,re=i.useMemo(()=>{const ce=a?.worktree;return ce&&typeof ce.branch=="string"&&ce.branch.trim().length>0?!0:l.length>0&&l.every(({metadata:Ce})=>typeof Ce.branch=="string"&&Ce.branch.trim().length>0)},[a?.worktree,l]),oe=a?.mode==="worktree",ve=oe,ne=x||!oe||!re,ye=x||!oe;i.useEffect(()=>{r||!D||W.length>0||(o(!0),n(!0))},[r,D,W.length]);const he=i.useCallback(ce=>{c({sessions:ce.sessions,dateLabel:ce.dateLabel,mode:ce.mode??"session",worktree:ce.worktree??null})},[]),Fe=i.useCallback(()=>{c(null),d([]),m(!1),p(!1),b(!1),g(!1),k(new Set)},[]),z=i.useCallback(async ce=>{if(ce.sessions.length===0)return;if(ce.sessions.length===1){const De=ce.sessions[0];await y(De.id)?le.success(t("sessions.sidebar.session.delete.success")):le.error(t("sessions.sidebar.session.delete.error"));return}const Ce=ce.sessions.map(De=>De.id),{deletedIds:be,failedIds:ue}=await _(Ce);if(be.length>0){const De=ue.length>0?ue.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ue.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ue.length}):ce.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:ce.dateLabel}):void 0;le.success(be.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:be.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:be.length}),{description:Ri(De)})}ue.length>0&&le.error(ue.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ue.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ue.length}),{description:Ri(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[y,_,t]);i.useEffect(()=>_r.onDeleteRequest(ce=>{if(!F&&(ce.mode??"session")==="session"){z(ce);return}he(ce)}),[he,F,z]),i.useEffect(()=>_r.onDirectoryRequest(()=>{n(!0)}),[]),i.useEffect(()=>{if(!a){d([]),m(!1),p(!1),g(!1),k(new Set);return}const ce=a.sessions.map(ue=>{const De=j(ue.id);return De?{session:ue,metadata:De}:null}).filter(ue=>!!ue);d(ce),m(!1),g(!1),k(new Set);const Ce=new Map;if(a.worktree?.path&&Ce.set(jr(a.worktree.path),a.worktree),ce.forEach(({metadata:ue})=>{ue.path&&Ce.set(jr(ue.path),ue)}),Ce.size===0){g(!0);return}let be=!1;return(async()=>{const ue=new Map,De=new Set;await Promise.all(Array.from(Ce.entries()).map(async([T,V])=>{try{const we=await ux(V.path);ue.set(T,we),we?.isDirty&&De.add(T)}catch{V.status&&(ue.set(T,V.status),V.status.isDirty&&De.add(T))}})).catch(T=>{console.warn("Failed to inspect worktree status before deletion:",T)}),!be&&(k(De),g(!0),c(T=>{if(!T?.worktree?.path)return T;const V=jr(T.worktree.path),we=ue.get(V);if(!we)return T;const E=T.worktree.status;return E?.isDirty===we.isDirty&&E?.ahead===we.ahead&&E?.behind===we.behind&&E?.upstream===we.upstream?T:{...T,worktree:{...T.worktree,status:we}}}),d(T=>T.map(V=>{const we=jr(V.metadata.path),E=ue.get(we);return E?{session:V.session,metadata:{...V.metadata,status:E}}:V})))})(),()=>{be=!0}},[a,j]),i.useEffect(()=>{re||m(!1)},[re]);const K=i.useCallback(async(ce,Ce)=>{const be=f&&re,ue=H(ce),De=jr(ce.path),T=jr(ue.path);try{await fx(ue,ce,{deleteRemoteBranch:be,deleteLocalBranch:Ce});const V=jr(S?.directoryOverride);return S?.open&&De&&V===De&&T&&(C(null),N({projectId:ue.id,directoryOverride:T},{force:!0})),jr(R)===De&&T&&Js.getState().setDirectory(T,{showOverlay:!1}),!0}catch(V){return le.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Ri(V instanceof Error?V.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[re,R,f,H,S?.directoryOverride,S?.open,C,N,t]),Y=i.useCallback((ce,Ce)=>{const be=f&&re;(async()=>{if(!await K(ce,Ce))return;const De=t(be?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");le.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Ri(De)})})()},[re,f,K,t]),me=i.useCallback(async()=>{if(a){b(!0);try{const ce=ve,Ce=ce&&f,be=ce&&u;if(a.sessions.length===0&&oe&&a.worktree){Y(a.worktree,be),Fe();return}if(a.sessions.length===1){const ue=a.sessions[0];if(!(oe?await P(ue.id):await y(ue.id,{archiveWorktree:!1,deleteRemoteBranch:Ce,deleteLocalBranch:be}))){le.error(t(oe?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),b(!1);return}const T=!oe&&ce?t(Ce?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;le.success(t(oe?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Ri(T),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const ue=a.sessions.map(V=>V.id);let De=[],T=[];if(oe){const V=await v(ue);De=V.archivedIds,T=V.failedIds}else{const V=await _(ue);De=V.deletedIds,T=V.failedIds}if(oe&&a.worktree&&T.length===0&&Y(a.worktree,be),De.length>0){const V=!oe&&ce?t(Ce?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,E=[T.length>0?oe?T.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:T.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:T.length}):T.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:T.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:T.length}):a.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:a.dateLabel}):void 0,V].filter(Boolean).join(" ");le.success(oe?De.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:De.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:De.length}):De.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:De.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:De.length}),{description:Ri(E||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(T.length>0&&(le.error(oe?T.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:T.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:T.length}):T.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:T.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:T.length}),{description:Ri(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),De.length===0)){b(!1);return}}oe&&a.sessions.length===1&&a.worktree&&Y(a.worktree,be),Fe()}finally{b(!1)}}},[a,f,u,y,_,P,v,Fe,ve,oe,Y,t]),Ne=a?.worktree??l[0]?.metadata??null,Be=a?a.mode==="worktree"?a.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):a.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:a.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:a.sessions.length}):a.sessions.length===1?a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:a.sessions.length,dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:a.sessions.length}):"",_e=a?s.jsxs("div",{className:Pe(oe?"space-y-3":"space-y-2"),children:[a.sessions.length>0&&s.jsxs("div",{className:Pe(oe?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[oe&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:a.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:a.sessions.length})]}),s.jsxs("ul",{className:Pe(oe?"mt-2 space-y-1":"space-y-0.5"),children:[a.sessions.slice(0,5).map(ce=>s.jsxs("li",{className:Pe(oe?"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:Pe(!oe&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:ce.title||t("sessions.sidebar.session.untitled")})]},ce.id)),a.sessions.length>5&&s.jsx("li",{className:Pe(oe?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:a.sessions.length-5})})]})]}),oe?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(A,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),Ne?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:Ne.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:Ne?Pa(Ne.path,B):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),J&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,Oe=oe?re?s.jsxs("button",{type:"button",onClick:()=>{ne||m(ce=>!ce)},disabled:ne,className:Pe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",ne?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(A,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,pe=oe?s.jsxs("button",{type:"button",onClick:()=>{ye||p(ce=>!ce)},disabled:ye,className:Pe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",ye?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(A,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,Re=oe?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:[pe,Oe]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ze,{variant:"ghost",onClick:Fe,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ze,{variant:"destructive",onClick:me,disabled:x,children:t(x?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>I(!F),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":!F,children:[F?s.jsx(A,{name:"checkbox-blank",className:"size-4"}):s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ze,{variant:"ghost",onClick:Fe,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ze,{variant:"destructive",onClick:me,disabled:x,children:x?t("sessions.sidebar.sessionDialogs.actions.deleting"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ge=oe?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[ie?s.jsx(Ya,{open:!!a,onClose:()=>{x||Fe()},title:ge,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Re}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[Be&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:Be}),_e]})}):s.jsx(_s,{open:!!a,onOpenChange:ce=>{if(!ce){if(x)return;Fe()}},children:s.jsxs(Vs,{className:Pe(oe?"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(tn,{children:[s.jsxs(Gs,{className:Pe(oe&&"flex items-center gap-2"),children:[oe&&s.jsx(A,{name:"delete-bin",className:"h-5 w-5"}),ge]}),Be&&s.jsx(dn,{children:Be})]}),s.jsx("div",{className:Pe(oe&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:_e}),s.jsx(xr,{className:"mt-2 gap-2 pt-1 pb-1",children:Re})]})}),s.jsx(ub,{open:e,onOpenChange:n})]})},gc=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),Dk=(t,e)=>{const n=gc(t),r=gc(e);return`${n}-${r}`.substring(0,60)},Mf=(t,e)=>`${t}/${e}`,Tk=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},Ff=(t,e)=>{const n=Tk(e),r=t.directory,o=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};vx(t.id,n),ht.getState().markSessionAsOpenChamberCreated(t.id),kr.getState().upsertSession(o);try{Ia().ensureChild(n,{bootstrap:!1}).setState(c=>{const l=c.session.findIndex(f=>f.id===t.id);if(l>=0&&c.session[l]===o)return c;const d=l>=0?c.session.map((f,m)=>m===l?o:f):[...c.session,o].sort((f,m)=>f.id.localeCompare(m.id));return{session:d,sessionTotal:Math.max(c.sessionTotal,d.length),limit:Math.max(c.limit,d.length)}})}catch{}return o},Pk=()=>{const t=Ds.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(o=>o.id===e);if(n?.path)return{id:n.id,path:n.path};const r=Js.getState().currentDirectory??null;if(r&&r.trim().length>0){const o=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${o}`,path:o}}return null},zl=fo()(Hf(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:o,files:a,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let l=0;l<r.length;l++){if(!r[l].prompt.trim())return t({error:`Group ${l+1}: prompt is required`}),null;if(r[l].models.length<1)return t({error:`Group ${l+1}: select at least 1 model`}),null;if(r[l].models.length>5)return t({error:`Group ${l+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const l=Pk();if(!l)return t({error:"Select a project",isLoading:!1}),null;const d=l.path,m=await Nm(d)&&e.isolateRuns!==!1,u=gc(n),p=m?await Xa(d):void 0,x=m?await hx(d):null,b=[],w=c?.filter(S=>S.trim().length>0)??[];for(let S=0;S<r.length;S++){const N=r[S],C=N.prompt,y=new Map;for(const _ of N.models){const v=`${_.providerID}:${_.modelID}`;y.set(v,(y.get(v)||0)+1)}const P=new Map;for(const _ of N.models){const v=`${_.providerID}:${_.modelID}`,F=y.get(v)||1,I=(P.get(v)||0)+1;P.set(v,I);const R=Dk(_.providerID,_.modelID),B=r.length>1?`g${S+1}`:void 0,D=F>1?Mf(u,`${R}/${I}`):Mf(u,R),W=B?`${B}/${D}`:D,U=VN({groupSlug:u,runGroup:B,providerID:_.providerID,modelID:_.modelID,index:F>1?I:void 0});try{if(!m){const ie=await sr.withDirectory(d,()=>sr.createSession({title:U}));Ff(ie,d),b.push({sessionId:ie.id,worktreePath:d,providerID:_.providerID,modelID:_.modelID,variant:_.variant,prompt:C});continue}const L=await px(l,{preferredName:W,mode:"new",branchName:W,worktreeName:W,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:w,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:x}),M={...L,createdFromBranch:p,kind:"standard"};await gx(l)&&await xx(L.path);const ee=await sr.withDirectory(L.path,()=>sr.createSession({title:U}));Ff(ee,L.path),ht.getState().setWorktreeMetadata(ee.id,M),b.push({sessionId:ee.id,worktreePath:L.path,providerID:_.providerID,modelID:_.modelID,variant:_.variant,prompt:C})}catch(L){console.warn("[MultiRun] Failed to create session:",L)}}}const g=c?.filter(S=>S.trim().length>0)??[];g.length>0&&bx(l,g).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const h=b.map(S=>S.sessionId),k=b[0]?.sessionId??null;if(h.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const j=a?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{const S=wx.getState().expandText;await Promise.allSettled(b.map(async N=>{try{const C=await S(N.prompt).catch(()=>N.prompt);await yx({sessionId:N.sessionId,directory:N.worktreePath,content:C,providerID:N.providerID,modelID:N.modelID,variant:N.variant,agent:o,files:j})}catch(C){console.warn("[MultiRun] Failed to start run:",C)}}))}catch(S){console.warn("[MultiRun] Failed to start runs:",S)}})(),t({isLoading:!1}),{groupSlug:u,sessionIds:h,firstSessionId:k}}catch(l){return t({error:l instanceof Error?l.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"}));function Vh(t){const e=gt.c(30),{git:n}=nr(),r=um(t),o=Ic(t),a=Rc(t),c=jx(t),l=yn(Fk),d=yn(Mk);let f,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==o||e[4]!==a?(f=()=>{!t||!n||o!==null||a||d(t,n,{silent:!0})},m=[t,n,d,o,a],e[0]=t,e[1]=d,e[2]=n,e[3]=o,e[4]=a,e[5]=f,e[6]=m):(f=e[5],m=e[6]),i.useEffect(f,m);let u;e[7]!==r?.all||e[8]!==t||e[9]!==l||e[10]!==n||e[11]!==o?(u=()=>{!t||!n||o===!0&&(r?.all||l(t,n))},e[7]=r?.all,e[8]=t,e[9]=l,e[10]=n,e[11]=o,e[12]=u):u=e[12];const p=r?.all;let x;e[13]!==t||e[14]!==l||e[15]!==n||e[16]!==o||e[17]!==p?(x=[t,n,o,p,l],e[13]=t,e[14]=l,e[15]=n,e[16]=o,e[17]=p,e[18]=x):x=e[18],i.useEffect(u,x);const b=a||o===!0&&c;let w;e:{if(!r?.all){let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=[],e[19]=y):y=e[19],w=y;break e}let C;e[20]!==r.all?(C=r.all.filter(Ek).sort(),e[20]=r.all,e[21]=C):C=e[21],w=C}const g=w;let h;e:{if(!r?.all){let y;e[22]===Symbol.for("react.memo_cache_sentinel")?(y=[],e[22]=y):y=e[22],h=y;break e}let C;e[23]!==r.all?(C=r.all.filter(Rk).map(Ik).sort(),e[23]=r.all,e[24]=C):C=e[24],h=C}const k=h;let j;e:{if(!t){j=null;break e}if(o!==null){j=o;break e}if(b){j=null;break e}j=r?.all?!0:null}const S=j;let N;return e[25]!==S||e[26]!==b||e[27]!==g||e[28]!==k?(N={localBranches:g,remoteBranches:k,isLoading:b,isGitRepository:S},e[25]=S,e[26]=b,e[27]=g,e[28]=k,e[29]=N):N=e[29],N}function Ik(t){return t.replace(/^remotes\//,"")}function Rk(t){return t.startsWith("remotes/")}function Ek(t){return!t.startsWith("remotes/")}function Mk(t){return t.fetchStatus}function Fk(t){return t.fetchBranches}const Ok=({directory:t,value:e,onChange:n,className:r,disabled:o,id:a})=>{const{t:c}=yt(),{localBranches:l,remoteBranches:d,isLoading:f,isGitRepository:m}=Vh(t),u=i.useMemo(()=>[...l,...d.map(x=>`remotes/${x}`)],[l,d]);i.useEffect(()=>{if(o||f||u.length===0||e&&u.includes(e))return;const x=e;let b=!1;return(async()=>{try{const g=t?await Xa(t).catch(()=>null):null;if(b)return;const h=localStorage.getItem(ru),{sourceBranch:k,shouldClearSavedSourceBranch:j}=fb({branches:u,savedSourceBranch:h,rootBranch:g});if(j&&localStorage.removeItem(ru),b||x&&u.includes(x))return;k&&n(k)}catch{}})(),()=>{b=!0}},[u,t,o,f,n,e]);const p=o||!m||f;return s.jsxs("div",{children:[s.jsxs(Un,{value:e,onValueChange:n,disabled:p,children:[s.jsx(Hn,{id:a,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(Dn,{placeholder:c(f?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(Gn,{className:"max-h-[280px] max-w-[320px]",children:f?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.loadingBranches")}):l.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[l.length>0&&s.jsxs(Jl,{children:[s.jsx(Yd,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.localBranches")}),l.map(x=>s.jsx(Bs,{value:x,className:"whitespace-normal break-all",children:x},x))]}),l.length>0&&d.length>0&&s.jsx(Sx,{}),d.length>0&&s.jsxs(Jl,{children:[s.jsx(Yd,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.remoteBranches")}),d.map(x=>s.jsx(Bs,{value:`remotes/${x}`,className:"whitespace-normal break-all",children:x},`remotes/${x}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:c("multiRun.branchSelector.status.notInGitRepository")})]})},Lk=10*1024*1024,Wl=5,va=t=>{const e=gt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let o;return e[1]!==n?(o=s.jsxs(At,{children:[r,s.jsx(Tt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=o):o=e[2],o},Fi=t=>{const e=gt.c(9),{htmlFor:n,required:r,children:o,info:a}=t;let c;e[0]!==r?(c=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=c):c=e[1];let l;e[2]!==o||e[3]!==n||e[4]!==c?(l=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,c]}),e[2]=o,e[3]=n,e[4]=c,e[5]=l):l=e[5];const d=a&&a;let f;return e[6]!==l||e[7]!==d?(f=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,d]}),e[6]=l,e[7]=d,e[8]=f):f=e[8],f},Bk=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:o}=yt(),[a,c]=i.useState(""),[l,d]=i.useState(()=>[{id:Oo(),prompt:"",models:[]}]),[f,m]=i.useState(""),[u,p]=i.useState([]),[x,b]=i.useState(!1),[w,g]=i.useState([]),[h,k]=i.useState(!1),[j,S]=i.useState(!1),[N,C]=i.useState(!0),y=i.useRef(null),P=Js(T=>T.currentDirectory??null),_=Js(T=>T.homeDirectory??null),v=i.useMemo(()=>{if(typeof window>"u")return null;const T=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof T=="string"&&T.trim().length>0?T.trim():null},[]),F=Ds(T=>T.activeProjectId),I=Ds(T=>T.setActiveProjectIdOnly),R=Ds(T=>T.projects),[B,D]=i.useState(()=>F??null);i.useEffect(()=>{if(F){D(F);return}!B&&R.length>0&&D(R[0].id)},[F,R,B]);const W=i.useMemo(()=>B?R.find(T=>T.id===B)??null:null,[R,B]),U=W?.path??P,L=i.useCallback(T=>{D(T),T!==F&&I(T)},[F,I]),{currentTheme:M}=wi(),ee=i.useCallback(T=>{const V=T.label?.trim()||ho(T.path,_),we=T.icon?Lc[T.icon]:null,E=T.color?Bc[T.color]:void 0,de=we?s.jsx(A,{name:we,className:"h-3.5 w-3.5 shrink-0",style:E?{color:E}:void 0}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:E?{color:E}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[T.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:T.iconBackground?{backgroundColor:T.iconBackground}:void 0,children:s.jsx(Vc,{project:{id:T.id,iconImage:T.iconImage??null},options:{themeVariant:M.metadata.variant,iconColor:M.colors.surface.foreground},className:"h-full w-full object-contain",fallback:de})}):de,s.jsx("span",{className:"truncate",children:V})]})},[_,M.metadata.variant,M.colors.surface.foreground]),ie=i.useMemo(()=>{if(W?.path)return{id:W.id,path:W.path};const T=P??v;return T?{id:`path:${T}`,path:T}:null},[W,P,v]),[te]=i.useState(()=>typeof window<"u"?pr():!1),H=i.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),J=rm(),re=i.useMemo(()=>{if(typeof window>"u")return null;const T=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof T=="number"&&Number.isFinite(T)&&T>0)return T;if(typeof navigator>"u")return null;const V=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!V)return null;const we=Number.parseInt(V[1],10),E=Number.parseInt(V[2],10);return Number.isNaN(we)?null:we===10?E:we},[]),oe=i.useMemo(()=>te&&H||J?"pl-[5.5rem]":"pl-3",[te,H,J]),ve=i.useMemo(()=>!te||!H||re===null?"":re>=26?"h-12":re<=15?"h-14":"",[te,H,re]),ne=i.useCallback(async T=>{T.target.closest("button, a, input, select, textarea")||T.button===0&&te&&await Nx()},[te]);i.useEffect(()=>{if(!n)return;const T=V=>{V.key==="Escape"&&(V.preventDefault(),V.stopPropagation(),n())};return window.addEventListener("keydown",T,!0),()=>window.removeEventListener("keydown",T,!0)},[n]);const[ye,he]=i.useState(""),{isLoading:Fe,isGitRepository:z}=Vh(U),K=i.useRef(!1),Y=z===!0,me=Y&&N;i.useEffect(()=>{if(z===!1){K.current=!0,C(!1);return}z===!0&&K.current&&(K.current=!1,C(!0))},[z]);const Ne=zl(T=>T.createMultiRun),Be=zl(T=>T.error),_e=zl(T=>T.clearError);i.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(T=>{const V=[...T];return V.length>0&&!V[0].prompt.trim()&&(V[0]={...V[0],prompt:t}),V})},[t]),i.useEffect(()=>{if(!ie)return;let T=!1;return S(!0),(async()=>{try{const V=await kx(ie);T||g(V)}catch{}finally{T||S(!1)}})(),()=>{T=!0}},[ie]);const Oe=i.useCallback((T,V)=>{d(we=>we.map(E=>E.id===T?{...E,...V}:E))},[]),pe=i.useCallback(T=>{d(V=>V.filter(we=>we.id!==T))},[]),Re=i.useCallback(()=>{d(T=>[...T,{id:Oo(),prompt:"",models:[]}])},[]),ge=async T=>{const V=T.target.files;if(!V)return;let we=0;for(let E=0;E<V.length;E++){const de=V[E];if(de.size>Lk){le.error(o("multirun.launcher.toast.fileTooLarge",{fileName:de.name}));continue}try{const fe=await new Promise(($,ke)=>{const Ve=new FileReader;Ve.onload=()=>$(Ve.result),Ve.onerror=ke,Ve.readAsDataURL(de)});p($=>[...$,{id:Oo(),filename:de.name,mimeType:de.type||"application/octet-stream",size:de.size,dataUrl:fe}]),we++}catch(fe){console.error("File attach failed",fe),le.error(o("multirun.launcher.toast.attachFailed",{fileName:de.name}))}}we>0&&le.success(we===1?o("multirun.launcher.toast.attachedSingle",{count:we}):o("multirun.launcher.toast.attachedPlural",{count:we})),y.current&&(y.current.value="")},ce=T=>{p(V=>V.filter(we=>we.id!==T))},Ce=i.useMemo(()=>l.reduce((T,V)=>T+V.models.length,0),[l]),be=async T=>{T.preventDefault();const V=l.filter(we=>we.prompt.trim()&&we.models.length>=1);if(V.length!==0&&!(Ce<1)){b(!0),_e();try{B&&B!==F&&I(B);const we=u.map(ke=>({mime:ke.mimeType,filename:ke.filename,url:ke.dataUrl})),E=w.filter(ke=>ke.trim().length>0),de=V.map(ke=>({prompt:ke.prompt.trim(),models:ke.models.map(Ve=>({providerID:Ve.providerID,modelID:Ve.modelID,displayName:Ve.displayName,variant:Ve.variant}))})),fe={name:a.trim(),groups:de,agent:f||void 0,worktreeBaseBranch:me?ye:void 0,isolateRuns:me,files:we.length>0?we:void 0,setupCommands:E.length>0?E:void 0},$=await Ne(fe);$&&($.firstSessionId&&ht.getState().setCurrentSession($.firstSessionId),e?.())}finally{b(!1)}}},ue=!!(a.trim()&&l.some(T=>T.prompt.trim()&&T.models.length>=1)&&Ce>=1&&U&&!Fe&&(z===!1||!me||ye)),De=w.filter(T=>T.trim()).length;return s.jsxs("form",{onSubmit:be,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:ne,className:Pe("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",oe,ve),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:o("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":o("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(A,{name:"close",className:"h-5 w-5"})})}),s.jsx(Tt,{children:s.jsx("p",{children:o("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Qa,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Fi,{htmlFor:"multirun-project",required:!0,children:o("multirun.launcher.project.label")}),R.length>0?s.jsxs(Un,{value:B??void 0,onValueChange:L,children:[s.jsx(Hn,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:W?s.jsx(Dn,{children:ee(W)}):s.jsx(Dn,{placeholder:o("multirun.launcher.project.placeholder")})}),s.jsx(Gn,{fitContent:!0,children:R.map(T=>s.jsx(Bs,{value:T.id,className:"max-w-[24rem]",children:ee(T)},T.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:o("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Fi,{htmlFor:"group-name",required:!0,info:s.jsx(va,{children:o("multirun.launcher.groupName.info")}),children:o("multirun.launcher.groupName.label")}),s.jsx(Ln,{id:"group-name",value:a,onChange:T=>c(T.target.value),placeholder:o("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Fi,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(va,{children:o("multirun.launcher.baseBranch.info")}),children:o("multirun.launcher.baseBranch.label")}),s.jsx(Ok,{directory:U,value:ye,onChange:he,disabled:!me,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(Vr,{checked:N,onChange:C,disabled:!Y,ariaLabel:o("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:o("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Fi,{htmlFor:"multirun-agent",info:s.jsx(va,{children:o("multirun.launcher.agent.info")}),children:o("multirun.launcher.agent.label")}),s.jsx(Fh,{value:f,onChange:m,id:"multirun-agent"})]})]}),s.jsxs(lo,{open:h,onOpenChange:k,children:[s.jsxs(Ho,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(A,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:o("multirun.launcher.setupCommands.label")}),De>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:De}),s.jsx(A,{name:"arrow-down-s",className:Pe("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",h&&"rotate-180")})]}),s.jsx(co,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:j?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:o("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[w.map((T,V)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Ln,{value:T,onChange:we=>{const E=[...w];E[V]=we.target.value,g(E)},placeholder:o("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>g(w.filter((we,E)=>E!==V)),className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":o("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]},`${T}-${V}`)),s.jsxs("button",{type:"button",onClick:()=>g([...w,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(A,{name:"add",className:"h-3 w-3"}),o("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Fi,{htmlFor:"prompt",required:!0,children:o("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:y,type:"file",multiple:!0,className:"hidden",onChange:ge,accept:"*/*"}),s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>y.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(A,{name:"attachment-2",className:"h-3 w-3"}),o("multirun.launcher.attachments.attach")]})}),s.jsx(Tt,{children:o("multirun.launcher.attachments.tooltip")})]}),u.map(T=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[T.mimeType.startsWith("image/")?s.jsx(A,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(A,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:T.filename,children:T.filename}),s.jsx("button",{type:"button",onClick:()=>ce(T.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(A,{name:"close",className:"h-3 w-3"})})]},T.id))]})]}),l.map((T,V)=>s.jsx(Vk,{group:T,groupIndex:V,canRemove:l.length>1,onUpdate:Oe,onRemove:pe},T.id)),s.jsxs("button",{type:"button",onClick:Re,className:"flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),o("multirun.launcher.groups.addGroup")]}),Be&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:Be})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[!me&&z!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(A,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:o("multirun.launcher.project.gitRequired")})]}):null,s.jsx(ze,{type:"button",variant:"ghost",size:"sm",onClick:n,children:o("multirun.launcher.actions.cancel")}),s.jsx(ze,{type:"submit",size:"sm",disabled:!ue||x,children:x?o("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:o("multirun.launcher.actions.startWithRunCount",{count:Ce})})})]})})]})},Vk=t=>{const e=gt.c(99),{group:n,groupIndex:r,canRemove:o,onUpdate:a,onRemove:c}=t,{t:l}=yt(),[d,f]=i.useState(!1),[m,u]=i.useState(""),[p,x]=i.useState(!1),[b,w]=i.useState(""),[g,h]=i.useState(!1),[k,j]=i.useState(""),S=i.useRef(null),N=i.useRef(null),C=i.useRef(null),y=i.useRef(null);let P;e[0]!==n.id||e[1]!==n.models||e[2]!==a?(P=E=>{n.models.length>=Wl||a(n.id,{models:[...n.models,E]})},e[0]=n.id,e[1]=n.models,e[2]=a,e[3]=P):P=e[3];const _=P;let v;e[4]!==n.id||e[5]!==n.models||e[6]!==a?(v=E=>{a(n.id,{models:n.models.filter((de,fe)=>fe!==E)})},e[4]=n.id,e[5]=n.models,e[6]=a,e[7]=v):v=e[7];const F=v;let I;e[8]!==n.id||e[9]!==n.models||e[10]!==a?(I=(E,de)=>{a(n.id,{models:n.models.map((fe,$)=>$===E?de:fe)})},e[8]=n.id,e[9]=n.models,e[10]=a,e[11]=I):I=e[11];const R=I;let B;e[12]===Symbol.for("react.memo_cache_sentinel")?(B=(E,de)=>{if(E.startsWith("/")){const Ve=E.indexOf(" "),Se=E.indexOf(`
|
|
234
|
+
`),q=Math.min(Ve===-1?E.length:Ve,Se===-1?E.length:Se);if(de<=q&&Ve===-1){w(E.substring(1,q)),x(!0),f(!1),h(!1);return}}x(!1);const fe=E.substring(0,de),$=fe.lastIndexOf("#");if($!==-1){const Ve=$>0?fe[$-1]:null,Se=fe.substring($+1);if((!Ve||/\s/.test(Ve))&&!Se.includes(" ")&&!Se.includes(`
|
|
235
|
+
`)){j(Se),h(!0),f(!1);return}}h(!1);const ke=fe.lastIndexOf("@");if(ke!==-1){const Ve=ke>0?fe[ke-1]:null,Se=fe.substring(ke+1);(!Ve||/\s/.test(Ve))&&!Se.includes(" ")&&!Se.includes(`
|
|
236
|
+
`)?(u(Se),f(!0)):f(!1);return}f(!1)},e[12]=B):B=e[12];const D=B;let W;e[13]!==n.id||e[14]!==a?(W=E=>{a(n.id,{prompt:E})},e[13]=n.id,e[14]=a,e[15]=W):W=e[15];const U=W;let L;e[16]!==n.prompt||e[17]!==U?(L=E=>{const de=n.prompt,$=S.current?.selectionStart??de.length,Ve=de.substring(0,$).lastIndexOf("@"),Se=E.relativePath&&E.relativePath.trim().length>0?E.relativePath.trim():E.path||E.name,q=Ve!==-1?Ve:$,O=`${de.substring(0,q)}@${Se} ${de.substring($)}`,se=q+Se.length+2;U(O),f(!1),u(""),requestAnimationFrame(()=>{const Le=S.current;Le&&(Le.selectionStart=se,Le.selectionEnd=se,Le.focus()),D(O,se)})},e[16]=n.prompt,e[17]=U,e[18]=L):L=e[18];const M=L;let ee;e[19]!==n.prompt||e[20]!==U?(ee=E=>{const de=n.prompt,$=S.current?.selectionStart??de.length,Ve=de.substring(0,$).lastIndexOf("@"),Se=Ve!==-1?Ve:$,q=`${de.substring(0,Se)}@${E} ${de.substring($)}`,O=Se+E.length+2;U(q),f(!1),u(""),requestAnimationFrame(()=>{const se=S.current;se&&(se.selectionStart=O,se.selectionEnd=O,se.focus()),D(q,O)})},e[19]=n.prompt,e[20]=U,e[21]=ee):ee=e[21];const ie=ee;let te;e[22]!==U?(te=E=>{const de=`/${E.name} `;U(de),x(!1),w(""),h(!1),requestAnimationFrame(()=>{const fe=S.current;fe&&(fe.focus(),fe.selectionStart=fe.value.length,fe.selectionEnd=fe.value.length),D(de,de.length)})},e[22]=U,e[23]=te):te=e[23];const H=te;let J;e[24]!==n.prompt||e[25]!==U?(J=(E,de)=>{const fe=n.prompt,ke=S.current?.selectionStart??fe.length,Se=fe.substring(0,ke).lastIndexOf("#"),q=Se!==-1?Se:ke,O=`${fe.substring(0,q)}#${de} ${fe.substring(ke)}`,se=q+de.length+2;U(O),h(!1),j(""),requestAnimationFrame(()=>{const Le=S.current;Le&&(Le.selectionStart=se,Le.selectionEnd=se,Le.focus()),D(O,se)})},e[24]=n.prompt,e[25]=U,e[26]=J):J=e[26];const re=J;let oe;e[27]!==p||e[28]!==d||e[29]!==g?(oe=E=>{if(p&&C.current&&(E.key==="Enter"||E.key==="ArrowUp"||E.key==="ArrowDown"||E.key==="Escape"||E.key==="Tab")){E.preventDefault(),C.current.handleKeyDown(E.key);return}d&&N.current&&(E.key==="Enter"||E.key==="ArrowUp"||E.key==="ArrowDown"||E.key==="Escape"||E.key==="Tab")&&(E.preventDefault(),N.current.handleKeyDown(E.key)),g&&y.current&&(E.key==="Enter"||E.key==="ArrowUp"||E.key==="ArrowDown"||E.key==="Escape"||E.key==="Tab")&&(E.preventDefault(),y.current.handleKeyDown(E.key))},e[27]=p,e[28]=d,e[29]=g,e[30]=oe):oe=e[30];const ve=oe,ne=r+1;let ye;e[31]!==l||e[32]!==ne?(ye=l("multirun.launcher.groups.groupLabel",{index:ne}),e[31]=l,e[32]=ne,e[33]=ye):ye=e[33];let he;e[34]!==ye?(he=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:ye}),e[34]=ye,e[35]=he):he=e[35];let Fe;e[36]!==o||e[37]!==n.id||e[38]!==c||e[39]!==l?(Fe=o&&s.jsx("button",{type:"button",onClick:()=>c(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":l("multirun.launcher.groups.removeGroup"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=o,e[37]=n.id,e[38]=c,e[39]=l,e[40]=Fe):Fe=e[40];let z;e[41]!==he||e[42]!==Fe?(z=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[he,Fe]}),e[41]=he,e[42]=Fe,e[43]=z):z=e[43];let K;e[44]!==l?(K=l("multirun.launcher.groups.prompt.label"),e[44]=l,e[45]=K):K=e[45];let Y;e[46]!==K?(Y=s.jsx(Fi,{required:!0,children:K}),e[46]=K,e[47]=Y):Y=e[47];const me=n.prompt;let Ne;e[48]!==U?(Ne=E=>{const de=E.target.value;U(de);const fe=E.target.selectionStart??de.length;D(de,fe)},e[48]=U,e[49]=Ne):Ne=e[49];let Be;e[50]!==l?(Be=l("multirun.launcher.groups.prompt.placeholder"),e[50]=l,e[51]=Be):Be=e[51];let _e;e[52]!==n.prompt||e[53]!==ve||e[54]!==Ne||e[55]!==Be?(_e=s.jsx(Oi,{ref:S,value:me,onChange:Ne,onKeyDown:ve,placeholder:Be,className:"typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content",required:!0}),e[52]=n.prompt,e[53]=ve,e[54]=Ne,e[55]=Be,e[56]=_e):_e=e[56];let Oe;e[57]!==b||e[58]!==H||e[59]!==p?(Oe=p?s.jsx(ym,{ref:C,searchQuery:b,onCommandSelect:H,onClose:()=>x(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=b,e[58]=H,e[59]=p,e[60]=Oe):Oe=e[60];let pe;e[61]!==ie||e[62]!==M||e[63]!==m||e[64]!==d?(pe=d?s.jsx(vm,{ref:N,searchQuery:m,onFileSelect:M,onAgentSelect:ie,onClose:()=>f(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=ie,e[62]=M,e[63]=m,e[64]=d,e[65]=pe):pe=e[65];let Re;e[66]!==re||e[67]!==g||e[68]!==k?(Re=g?s.jsx(jm,{ref:y,searchQuery:k,onSnippetSelect:re,onClose:()=>h(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=re,e[67]=g,e[68]=k,e[69]=Re):Re=e[69];let ge;e[70]!==_e||e[71]!==Oe||e[72]!==pe||e[73]!==Re?(ge=s.jsxs("div",{className:"relative",children:[_e,Oe,pe,Re]}),e[70]=_e,e[71]=Oe,e[72]=pe,e[73]=Re,e[74]=ge):ge=e[74];let ce;e[75]!==Y||e[76]!==ge?(ce=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[Y,ge]}),e[75]=Y,e[76]=ge,e[77]=ce):ce=e[77];let Ce;e[78]!==l?(Ce=l("multirun.launcher.models.info",{max:Wl}),e[78]=l,e[79]=Ce):Ce=e[79];let be;e[80]!==Ce?(be=s.jsx(va,{children:Ce}),e[80]=Ce,e[81]=be):be=e[81];let ue;e[82]!==l?(ue=l("multirun.launcher.models.label"),e[82]=l,e[83]=ue):ue=e[83];let De;e[84]!==be||e[85]!==ue?(De=s.jsx(Fi,{required:!0,info:be,children:ue}),e[84]=be,e[85]=ue,e[86]=De):De=e[86];let T;e[87]!==n.models||e[88]!==_||e[89]!==F||e[90]!==R?(T=s.jsx(Lh,{selectedModels:n.models,onAdd:_,onRemove:F,onUpdate:R,minModels:1,maxModels:Wl}),e[87]=n.models,e[88]=_,e[89]=F,e[90]=R,e[91]=T):T=e[91];let V;e[92]!==De||e[93]!==T?(V=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[De,T]}),e[92]=De,e[93]=T,e[94]=V):V=e[94];let we;return e[95]!==z||e[96]!==ce||e[97]!==V?(we=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[z,ce,V]}),e[95]=z,e[96]=ce,e[97]=V,e[98]=we):we=e[98],we},_k=i.createContext(null),$k=t=>{const e=gt.c(3),{children:n,value:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx(_k.Provider,{value:r,children:n}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o},Of=po(()=>mo(()=>import("./TerminalView-D9C7fNLm.js"),__vite__mapDeps([0,1,2,3,4,5,6,7])).then(t=>({default:t.TerminalView}))),zk=po(()=>mo(()=>import("./DiagramView-Elkp8b4l.js"),__vite__mapDeps([8,1,3,4,2,5,6,7])).then(t=>({default:t.DiagramView}))),Wk=po(()=>mo(()=>import("./runtimeEndpointReset-B0P2DED1.js").then(t=>t.ae),__vite__mapDeps([5,1,2,3,4,6])).then(t=>({default:t.SettingsView}))),Uk=po(()=>mo(()=>import("./SettingsWindow-Bewo7vwh.js"),__vite__mapDeps([9,1,2,3,4,5,6])).then(t=>({default:t.SettingsWindow}))),Hk=po(()=>mo(()=>import("./MultiRunWindow-DVpNCqnE.js"),__vite__mapDeps([10,1,2,3,4,5,6,7])).then(t=>({default:t.MultiRunWindow}))),Gk=()=>{const o=Ee(J=>J.isSidebarOpen),a=Ee(J=>J.isRightSidebarOpen),c=Ee(J=>J.isBottomTerminalOpen),l=Ee(J=>J.setRightSidebarOpen),d=Ee(J=>J.setBottomTerminalOpen),f=Ee(J=>J.activeMainTab),m=Ee(J=>J.setIsMobile),u=Ee(J=>J.isSessionSwitcherOpen),p=Ee(J=>J.isSettingsDialogOpen),x=Ee(J=>J.setSettingsDialogOpen),b=Ee(J=>J.isMultiRunLauncherOpen),w=Ee(J=>J.setMultiRunLauncherOpen),g=Ee(J=>J.multiRunLauncherPrefillPrompt),{isMobile:h,isTablet:k}=zr(),j=i.useRef(!1),S=i.useRef(!1),N=i.useRef(!1),[C,y]=i.useState(!1),[P,_]=i.useState(!1),[v,F]=i.useState(!1),[I,R]=i.useState(!1),B=i.useCallback(J=>{y(J),Ee.getState().setSessionSwitcherOpen(J)},[]),D=i.useRef(!1),W=i.useRef(typeof window>"u"?0:window.innerWidth),U=Sd(-W.current),L=nt.useRef(0),M=Sd(W.current),ee=nt.useRef(0);nt.useEffect(()=>{h&&(L.current=window.innerWidth,ee.current=window.innerWidth)},[h]),nt.useEffect(()=>{if(!h){F(!1);return}C&&F(!0),Nd(U,C?0:-L.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[C,h,U]),nt.useEffect(()=>{if(!h){R(!1);return}D.current=P,P&&R(!0),Nd(M,P?0:ee.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[h,P,M]),nt.useEffect(()=>{if(h)return U.on("change",J=>{const re=L.current||W.current,oe=C||J>-re+.5;F(ve=>ve===oe?ve:oe)})},[h,U,C]),nt.useEffect(()=>{if(h)return M.on("change",J=>{const re=ee.current||W.current,oe=P||J<re-.5;R(ve=>ve===oe?ve:oe)})},[h,P,M]),nt.useEffect(()=>{h&&!u&&C&&B(!1)},[u,h,C,B]),nt.useEffect(()=>{if(!h){N.current=!1;return}N.current||(N.current=!0,B(!1),_(!1),Ee.getState().isRightSidebarOpen&&l(!1))},[h,B,l]),nt.useEffect(()=>{if(!h||f!=="chat"||C||P||p)return;let J=!1,re;const oe=ve=>{re=window.setTimeout(()=>{if(J)return;const ne=ht.getState(),ye=Ee.getState();if(!(ye.activeMainTab!=="chat"||ye.isSettingsDialogOpen||ne.currentSessionId||ne.newSessionDraft?.open)){if(ne.isLoading){oe(250);return}ne.openNewSessionDraft()}},ve)};return oe(500),()=>{J=!0,re!==void 0&&window.clearTimeout(re)}},[f,h,p,C,P]),nt.useEffect(()=>{!h||!p||(B(!1),_(!1),a&&l(!1))},[h,p,a,B,l]),mb(),i.useEffect(()=>{Ee.getState().isMobile!==h&&m(h)},[h,m]),i.useEffect(()=>{if(typeof window>"u")return;let J;const re=()=>{J===void 0&&(J=window.requestAnimationFrame(()=>{J=void 0,Ee.getState().updateProportionalSidebarWidths()}))};return window.addEventListener("resize",re),()=>{window.removeEventListener("resize",re),J!==void 0&&window.cancelAnimationFrame(J)}},[]),i.useEffect(()=>{if(typeof window>"u")return;let J;const re=()=>{const ve=Ee.getState(),ne=window.innerWidth,ye=window.innerHeight;if(!h&&!k){const he=ne<1140,Fe=ne>=1220;he?ve.isRightSidebarOpen&&(l(!1),j.current=!0):Fe&&j.current&&(l(!0),j.current=!1);const z=ye<640,K=ye>=700;z?ve.isBottomTerminalOpen&&(d(!1),S.current=!0):K&&S.current&&(d(!0),S.current=!1)}},oe=()=>{J===void 0&&(J=window.requestAnimationFrame(()=>{J=void 0,re()}))};return re(),window.addEventListener("resize",oe),()=>{window.removeEventListener("resize",oe),J!==void 0&&window.cancelAnimationFrame(J)}},[h,k,d,l]),i.useEffect(()=>{if(typeof window>"u")return;const J=Ee.subscribe((re,oe)=>{const ve=window.innerWidth,ne=window.innerHeight,ye=ve>=1220,he=ne>=700;re.isRightSidebarOpen!==oe.isRightSidebarOpen&&ye&&(j.current=!1),re.isBottomTerminalOpen!==oe.isBottomTerminalOpen&&he&&(S.current=!1)});return()=>{J()}},[h,k,d,l]);const ie=i.useCallback(()=>{C&&B(!1),_(!P)},[C,P,B]),te=i.useMemo(()=>{switch(f){case"plan":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(hh,{})});case"git":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(oc,{isActive:!P})});case"diff":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(ch,{})});case"terminal":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(Of,{})});case"files":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(mh,{})});case"context":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(rh,{})});case"diagram":return s.jsx(i.Suspense,{fallback:null,children:s.jsx(zk,{})});default:return null}},[f,P]),H=f==="chat";return s.jsx(hb,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:Pe("main-content-safe-area",h?"flex h-[100dvh] flex-col":"relative flex h-[100dvh]","bg-background"),children:[s.jsx(m0,{}),s.jsx(nS,{}),s.jsx(aS,{}),s.jsx(Ak,{}),h?s.jsxs($k,{value:{leftDrawerOpen:C,rightDrawerOpen:P,toggleLeftDrawer:()=>{const J=!C;P&&_(!1),B(J)},toggleRightDrawer:ie,leftDrawerX:U,rightDrawerX:M,leftDrawerWidth:L,rightDrawerWidth:ee,setMobileLeftDrawerOpen:B,setRightSidebarOpen:_},children:[!p&&s.jsx(du,{onToggleLeftDrawer:()=>{const J=!C;P&&_(!1),B(J)},onToggleRightDrawer:()=>{ie()},leftDrawerOpen:C,rightDrawerOpen:P}),s.jsx("div",{"data-page-scroll-lock":"true",className:Pe("flex flex-1 overflow-hidden relative",p&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:Pe("absolute inset-0",!H&&"invisible"),children:s.jsx(an,{children:s.jsx(tc,{})})}),te&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(an,{children:te})}),b&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(an,{children:s.jsx(Bk,{initialPrompt:g,onCreated:()=>w(!1),onCancel:()=>w(!1)})})}),s.jsx(kd.div,{className:Pe("absolute inset-0 z-20 bg-sidebar",!v&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:U},"aria-hidden":!C,children:s.jsx(an,{children:s.jsx(Ef,{mobileVariant:!0})})}),I&&s.jsx(kd.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:M},"aria-hidden":!P,children:s.jsx(an,{children:s.jsx(i.Suspense,{fallback:null,children:s.jsx(oc,{isActive:P})})})})]})}),p&&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(i.Suspense,{fallback:null,children:s.jsx(Wk,{onClose:()=>x(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx(Sw,{}),s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsx(yw,{isOpen:o,isMobile:h,className:"border-border/50",topBar:s.jsx(vw,{}),children:s.jsx(Ef,{})}),s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[s.jsx(du,{}),s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border/50 bg-background","data-page-scroll-lock":"true",children:[s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:Pe("absolute inset-0",!H&&"invisible"),children:s.jsx(an,{children:s.jsx(tc,{})})}),te&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(an,{children:te})})]}),s.jsx(d0,{})]})}),s.jsx(pw,{isOpen:c,isMobile:h,children:c?s.jsx(an,{children:s.jsx(i.Suspense,{fallback:null,children:s.jsx(Of,{})})}):null})]}),s.jsx(Tw,{isOpen:a,className:"bg-background border-t border-border/50",children:s.jsx(an,{children:s.jsx(Jv,{})})})]})]})]}),s.jsx(i.Suspense,{fallback:null,children:s.jsx(Uk,{open:p,onOpenChange:x})}),s.jsx(i.Suspense,{fallback:null,children:s.jsx(Hk,{open:b,onOpenChange:w,initialPrompt:g})})]})]})})},Kk=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},zn=t=>{const e=gt.c(8),{label:n,value:r}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=o):o=e[0];let a;e[1]!==n?(a=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=a):a=e[2];let c;e[3]!==r?(c=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=c):c=e[4];let l;return e[5]!==a||e[6]!==c?(l=s.jsxs("div",{className:"rounded-md p-2",style:o,children:[a,c]}),e[5]=a,e[6]=c,e[7]=l):l=e[7],l},Lf=t=>{const e=gt.c(43),{title:n,snapshot:r,emptyLabel:o}=t,{t:a}=yt();let c;if(e[0]!==o||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==a||e[6]!==n){const l=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(Qk,0),e[8]=r.entries,e[9]=d):d=e[9];const f=d;let m;e[10]!==n?(m=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=m):m=e[11];let u;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==a?(u=r.startedAt?Kk(r.durationMs):a("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=a,e[15]=u):u=e[15];let p;e[16]!==u?(p=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=p):p=e[17];let x;e[18]!==m||e[19]!==p?(x=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,p]}),e[18]=m,e[19]=p,e[20]=x):x=e[20];let b;e[21]!==a?(b=a("memoryDebugPanel.metric.metrics"),e[21]=a,e[22]=b):b=e[22];let w;e[23]!==r.entries.length||e[24]!==b?(w=s.jsx(zn,{label:b,value:r.entries.length}),e[23]=r.entries.length,e[24]=b,e[25]=w):w=e[25];let g;e[26]!==a?(g=a("memoryDebugPanel.metric.samples"),e[26]=a,e[27]=g):g=e[27];let h;e[28]!==g||e[29]!==f?(h=s.jsx(zn,{label:g,value:f}),e[28]=g,e[29]=f,e[30]=h):h=e[30];let k;e[31]!==a?(k=a("memoryDebugPanel.metric.lastUpdate"),e[31]=a,e[32]=k):k=e[32];let j;e[33]!==r.lastUpdatedAt||e[34]!==a?(j=r.lastUpdatedAt?a("memoryDebugPanel.common.live"):a("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=a,e[35]=j):j=e[35];let S;e[36]!==k||e[37]!==j?(S=s.jsx(zn,{label:k,value:j}),e[36]=k,e[37]=j,e[38]=S):S=e[38];let N;e[39]!==h||e[40]!==S||e[41]!==w?(N=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[w,h,S]}),e[39]=h,e[40]=S,e[41]=w,e[42]=N):N=e[42],c=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,N,l.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:o}):s.jsx(On,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:l.map(C=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:C.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:a("memoryDebugPanel.metric.countValue",{value:C.count})}),s.jsx("span",{children:a("memoryDebugPanel.metric.avgValue",{value:C.avg})}),s.jsx("span",{children:a("memoryDebugPanel.metric.maxValue",{value:C.max})}),s.jsx("span",{children:a("memoryDebugPanel.metric.totalValue",{value:C.total})})]})]},C.metric))})})]}),e[0]=o,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=a,e[6]=n,e[7]=c}else c=e[7];return c},qk=t=>{const e=gt.c(99),{onClose:n}=t,{t:r}=yt(),[o,a]=i.useState("memory"),[c,l]=i.useState("idle"),d=ht(Jk),f=Sm(Xk),m=Mc(),u=Cx(Zk),p=ur(eC),[x,b]=i.useState(tC),[w,g]=i.useState(sC);let h;e[0]!==x.entries?(h=new Map,x.entries.forEach(ue=>{h.set(ue.metric,ue.count)}),e[0]=x.entries,e[1]=h):h=e[1];let k;e[2]!==h?(k=h.get("ui.message_list.render")??0,e[2]=h,e[3]=k):k=e[3];let j;e[4]!==h?(j=h.get("ui.message_list.render.streaming")??0,e[4]=h,e[5]=j):j=e[5];let S;e[6]!==h?(S=h.get("ui.chat_message.render")??0,e[6]=h,e[7]=S):S=e[7];let N;e[8]!==h?(N=h.get("ui.chat_message.render.streaming")??0,e[8]=h,e[9]=N):N=e[9];let C;e[10]!==h?(C=h.get("ui.chat_message.render.static_during_stream")??0,e[10]=h,e[11]=C):C=e[11];let y;e[12]!==h?(y=h.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=h,e[13]=y):y=e[13];let P;e[14]!==k||e[15]!==j||e[16]!==S||e[17]!==N||e[18]!==C||e[19]!==y?(P={messageListRender:k,messageListRenderStreaming:j,chatMessageRender:S,chatMessageRenderStreaming:N,chatMessageRenderStaticDuringStream:C,chatMessageRenderStaticOutsideActiveTurnDuringStream:y},e[14]=k,e[15]=j,e[16]=S,e[17]=N,e[18]=C,e[19]=y,e[20]=P):P=e[20];const _=P;let v,F;e[21]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{const ue=()=>{b(la()),g(ca())};ue();const De=window.setInterval(ue,500);return()=>window.clearInterval(De)},F=[],e[21]=v,e[22]=F):(v=e[21],F=e[22]),i.useEffect(v,F);let I,R;e[23]!==c?(I=()=>{if(c==="idle")return;const ue=window.setTimeout(()=>{l("idle")},1500);return()=>window.clearTimeout(ue)},R=[c],e[23]=c,e[24]=I,e[25]=R):(I=e[24],R=e[25]),i.useEffect(I,R);let B=0,D=0,W=0;for(const ue of Object.keys(u)){const De=u[ue]??[];D=D+De.length;for(const T of De)T.role==="user"?W=W+1:T.role==="assistant"&&(B=B+1)}let U;e[26]!==B||e[27]!==D||e[28]!==W?(U={assistant:B,total:D,user:W},e[26]=B,e[27]=D,e[28]=W,e[29]=U):U=e[29];const L=U;let M;if(e[30]!==d||e[31]!==u||e[32]!==f||e[33]!==m||e[34]!==r){let ue;e[36]!==d||e[37]!==u||e[38]!==f||e[39]!==r?(ue=De=>{const T=u[De.id]??[];let V=0,we=0;for(const de of T)de.role==="user"?we=we+1:de.role==="assistant"&&(V=V+1);const E=f.get(De.id);return{id:De.id,title:De.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:V,messageCount:T.length,userMessageCount:we,isStreaming:E?.isStreaming||!1,isZombie:E?.isZombie||!1,backgroundCount:E?.backgroundMessageCount||0,lastAccessed:E?.lastAccessedAt||0,isCurrent:De.id===d}},e[36]=d,e[37]=u,e[38]=f,e[39]=r,e[40]=ue):ue=e[40],M=m.map(ue).sort(nC),e[30]=d,e[31]=u,e[32]=f,e[33]=m,e[34]=r,e[35]=M}else M=e[35];const ee=M;let ie;e[41]!==u?(ie=Object.keys(u),e[41]=u,e[42]=ie):ie=e[42];const te=ie.length;let H;e[43]===Symbol.for("react.memo_cache_sentinel")?(H=async()=>{try{const ue={generatedAt:new Date().toISOString(),ui:la(),vscode:ca()};await navigator.clipboard.writeText(JSON.stringify(ue,null,2)),l("copied")}catch{l("error")}},e[43]=H):H=e[43];const J=H;let re;e[44]===Symbol.for("react.memo_cache_sentinel")?(re={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[44]=re):re=e[44];let oe;e[45]!==o?(oe=o==="memory"?s.jsx(A,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(A,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[45]=o,e[46]=oe):oe=e[46];let ve;e[47]!==r?(ve=r("memoryDebugPanel.title"),e[47]=r,e[48]=ve):ve=e[48];let ne;e[49]!==ve?(ne=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ve}),e[49]=ve,e[50]=ne):ne=e[50];let ye;e[51]!==oe||e[52]!==ne?(ye=s.jsxs("div",{className:"flex items-center gap-2",children:[oe,ne]}),e[51]=oe,e[52]=ne,e[53]=ye):ye=e[53];let he;e[54]!==o?(he=o==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ze,{size:"xs",variant:"ghost",onClick:J,children:s.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(ze,{size:"xs",variant:"ghost",onClick:()=>{Tp(),b(la()),g(ca())},children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[54]=o,e[55]=he):he=e[55];let Fe;e[56]!==n?(Fe=n?s.jsx(ze,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null,e[56]=n,e[57]=Fe):Fe=e[57];let z;e[58]!==he||e[59]!==Fe?(z=s.jsxs("div",{className:"flex items-center gap-1",children:[he,Fe]}),e[58]=he,e[59]=Fe,e[60]=z):z=e[60];let K;e[61]!==ye||e[62]!==z?(K=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[ye,z]}),e[61]=ye,e[62]=z,e[63]=K):K=e[63];let Y;e[64]===Symbol.for("react.memo_cache_sentinel")?(Y={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[64]=Y):Y=e[64];const me=o==="memory"?"secondary":"ghost";let Ne;e[65]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>a("memory"),e[65]=Ne):Ne=e[65];let Be;e[66]!==r?(Be=r("memoryDebugPanel.tabs.memory"),e[66]=r,e[67]=Be):Be=e[67];let _e;e[68]!==me||e[69]!==Be?(_e=s.jsx(ze,{size:"sm",variant:me,className:"flex-1",onClick:Ne,children:Be}),e[68]=me,e[69]=Be,e[70]=_e):_e=e[70];const Oe=o==="streaming"?"secondary":"ghost";let pe;e[71]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>a("streaming"),e[71]=pe):pe=e[71];let Re;e[72]!==r?(Re=r("memoryDebugPanel.tabs.streaming"),e[72]=r,e[73]=Re):Re=e[73];let ge;e[74]!==Oe||e[75]!==Re?(ge=s.jsx(ze,{size:"sm",variant:Oe,className:"flex-1",onClick:pe,children:Re}),e[74]=Oe,e[75]=Re,e[76]=ge):ge=e[76];let ce;e[77]!==_e||e[78]!==ge?(ce=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:Y,children:[_e,ge]}),e[77]=_e,e[78]=ge,e[79]=ce):ce=e[79];let Ce;e[80]!==o||e[81]!==te||e[82]!==c||e[83]!==d||e[84]!==u||e[85]!==L||e[86]!==f||e[87]!==ee||e[88]!==m||e[89]!==_||e[90]!==x||e[91]!==r||e[92]!==p||e[93]!==w?(Ce=o==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(zn,{label:r("memoryDebugPanel.metric.totalMessages"),value:L.total}),s.jsx(zn,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${te} / ${Qd.MAX_SESSIONS}`}),s.jsx(zn,{label:r("memoryDebugPanel.metric.userMessages"),value:L.user}),s.jsx(zn,{label:r("memoryDebugPanel.metric.assistantMessages"),value:L.assistant})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:Ax()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:Qd.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:p})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(On,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:ee.map(ue=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:ue.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:ue.title}),ue.isStreaming?s.jsx(A,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,ue.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.roleMsgsValue",{assistant:ue.assistantMessageCount,user:ue.userMessageCount})}),s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:ue.messageCount})}),ue.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",ue.backgroundCount]}):null]})]},ue.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(At,{children:[s.jsx(Dt,{asChild:!0,children:s.jsx(ze,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(rC),currentSessionId:d,cachedSessions:Object.keys(u),messageRoleCounts:L,sessionMessageRoleCounts:ee.map(iC),memoryStates:Object.fromEntries(f)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Tt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(c==="copied"?"memoryDebugPanel.streaming.copy.copied":c==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ze,{size:"xs",variant:"outline",onClick:J,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(zn,{label:r("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),s.jsx(zn,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:w.entries.length}),s.jsx(zn,{label:r("memoryDebugPanel.metric.messageListRenders"),value:_.messageListRender}),s.jsx(zn,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:_.messageListRenderStreaming}),s.jsx(zn,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:_.chatMessageRender}),s.jsx(zn,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:_.chatMessageRenderStreaming}),s.jsx(zn,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:_.chatMessageRenderStaticDuringStream}),s.jsx(zn,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:_.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Lf,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),w.entries.length>0?s.jsx(Lf,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:w,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[80]=o,e[81]=te,e[82]=c,e[83]=d,e[84]=u,e[85]=L,e[86]=f,e[87]=ee,e[88]=m,e[89]=_,e[90]=x,e[91]=r,e[92]=p,e[93]=w,e[94]=Ce):Ce=e[94];let be;return e[95]!==K||e[96]!==ce||e[97]!==Ce?(be=s.jsxs(Dx,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:re,children:[K,ce,Ce]}),e[95]=K,e[96]=ce,e[97]=Ce,e[98]=be):be=e[98],be},Yk=qk;function Qk(t,e){return t+e.count}function Jk(t){return t.currentSessionId}function Xk(t){return t.sessionMemoryState}function Zk(t){return t.message}function eC(t){return t.totalRequestCount}function tC(){return la()}function sC(){return ca()}function nC(t,e){return e.lastAccessed-t.lastAccessed}function rC(t){return{id:t.id,title:t.title}}function iC(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}const oC=()=>{if(typeof document>"u")return"";const t=document.activeElement;if(t instanceof HTMLTextAreaElement)return t.value.slice(t.selectionStart??0,t.selectionEnd??0);if(t instanceof HTMLInputElement){const e=t.type?.toLowerCase()??"text";if(["text","search","url","tel","password"].includes(e))return t.value.slice(t.selectionStart??0,t.selectionEnd??0)}return t instanceof HTMLElement&&t.isContentEditable?t.ownerDocument.defaultView?.getSelection?.()?.toString()??"":""},aC=async()=>{const t=oC()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},Bf="openchamber:menu-action",Ul="openchamber:check-for-updates",lC=t=>{const e=ht(y=>y.openNewSessionDraft),n=Ee(y=>y.toggleCommandPalette),r=Ee(y=>y.setCommandPaletteOpen),o=Ee(y=>y.toggleHelpDialog),a=Ee(y=>y.toggleSidebar),c=Ee(y=>y.setSessionSwitcherOpen),l=Ee(y=>y.setActiveMainTab),d=Ee(y=>y.setSettingsDialogOpen),f=Ee(y=>y.setAboutDialogOpen),m=Ee(y=>y.toggleRightSidebar),u=Ee(y=>y.setRightSidebarOpen),p=Ee(y=>y.setRightSidebarTab),x=Ee(y=>y.toggleBottomTerminal),b=Ee(y=>y.setBottomTerminalExpanded),w=To(y=>y.checkForUpdates),{setThemeMode:g}=wi(),h=i.useRef(!1),k=i.useCallback(()=>{h.current||(h.current=!0,w().then(()=>{const{available:y,error:P}=To.getState();if(P){le.error("Failed to check for updates",{description:P});return}y||le.success("You are on the latest version")}).finally(()=>{h.current=!1}))},[w]),j=i.useCallback(()=>{_r.requestDirectoryDialog()},[]),S=i.useCallback(y=>{const P=Tx();if(P.length===0)return;const _=ht.getState().currentSessionId,v=P.findIndex(R=>R.id===_);let F=y>0?0:P.length-1;v>=0&&(F=(v+y+P.length)%P.length);const I=P[F];I&&(l("chat"),c(!1),ht.getState().setCurrentSession(I.id))},[l,c]),N=i.useCallback(y=>{const{activeProjectId:P,projects:_,setActiveProject:v}=Ds.getState();if(_.length===0)return;const F=_.findIndex(B=>B.id===P);let I=y>0?0:_.length-1;F>=0&&(I=(F+y+_.length)%_.length);const R=_[I];R&&v(R.id)},[]),C=i.useCallback(y=>{switch(y){case"about":f(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":l("chat"),c(!1),e();break;case"new-worktree-session":l("chat"),c(!1),wm();break;case"change-workspace":j();break;case"toggle-right-sidebar":m();break;case"open-right-sidebar-git":u(!0),p("git");break;case"open-right-sidebar-files":u(!0),p("files");break;case"toggle-terminal":x();break;case"toggle-terminal-expanded":b(!Ee.getState().isBottomTerminalExpanded);break;case"copy":{const P=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(P)||aC();break}case"theme-light":g("light");break;case"theme-dark":g("dark");break;case"theme-system":g("system");break;case"toggle-sidebar":a();break;case"toggle-memory-debug":t?.();break;case"go-back":Js.getState().goBack();break;case"go-forward":Js.getState().goForward();break;case"previous-session":S(-1);break;case"next-session":S(1);break;case"previous-project":N(-1);break;case"next-project":N(1);break;case"help-dialog":o();break;case"download-logs":{Px().catch(()=>{le.error("Failed to collect OpenCode status")});break}}},[j,N,S,t,e,f,l,c,r,d,b,u,p,g,x,n,o,m,a]);i.useEffect(()=>{const y=_=>{const v=_.detail;v&&C(v)},P=()=>{k()};return window.addEventListener(Bf,y),window.addEventListener(Ul,P),()=>{window.removeEventListener(Bf,y),window.removeEventListener(Ul,P)}},[C,k]),i.useEffect(()=>{if(typeof window>"u")return;const P=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof P!="function")return;let _=null,v=null;return P("openchamber:menu-action",F=>{const I=F?.payload;typeof I=="string"&&C(I)}).then(F=>{_=F}).catch(()=>{}),P("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Ul))}).then(F=>{v=F}).catch(()=>{}),()=>{(async()=>{try{const I=_?.();I instanceof Promise&&await I}catch{}try{const I=v?.();I instanceof Promise&&await I}catch{}})()}},[C])},cC="openchamber:tray-action",Vf=5e3,dC=120,uC=45e3,_h=20,_f=()=>{if(typeof window>"u")return!1;const t=window.__OPENCHAMBER_PLATFORM__;return t==="darwin"||t==="win32"},fC=t=>{const e=typeof t.permission=="string"?t.permission:"Permission",n=Array.isArray(t.patterns)?t.patterns.find(r=>typeof r=="string"&&r.trim()):"";return n?`${e}: ${n}`:e},mC=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},za=t=>t.time?.updated??t.time?.created??0,hC=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},pC=(t,e,n,r,o)=>{if(!t)return"";const a=Mx(n,r,t),c=e.project?.name,l=a?.label?.trim()||c?.trim()||hC(t),d=ua(t);let f=d&&o.get(d)||"";if(!f){for(const[m,u]of yn.getState().directories)if(ua(m)===d){f=u.status?.current??"";break}}if(!f)for(const m of r.values()){const u=m.find(p=>ua(p.path)===d);if(u?.branch){f=u.branch;break}}return f?`${l} · ${f}`:l},gC=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=pn.getState(),r=n==="remaining"?"remaining":"usage";if(!e.length)return{mode:r,groups:[]};const o=new Map(t.map(c=>[c.providerId,c])),a=[];for(const c of Im){if(!e.includes(c.id))continue;const l=o.get(c.id);if(!l||l.configured!==!0)continue;const d=[];for(const[m,u]of Object.entries(l.usage?.windows??{})){const p=r==="remaining"?u.remainingPercent:u.usedPercent;d.push({label:Nc(m),value:Bo(u.valueLabel,p)})}const f=!l.ok&&l.error?l.error:d.length===0?"No rate limits reported":null;a.push({provider:c.name,rows:d,status:f})}return{mode:r,groups:a}},xC=async()=>{try{if(io())return"Local OpenChamber";const t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,e=Xr();if(e&&Aa(e,t))return"Local OpenChamber";const r=(await Yf()).hosts.find(o=>e?Aa(e,Qf(o)):!1);return r?.label?.trim()?Jf(r.label.trim()):"Instance"}catch{return""}},bC=()=>{const t=new Map,e=new Map,n=[],r=new Map;let o;try{o=Ia()}catch{return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}}for(const[a,c]of o.children.entries()){const l=c.getState();l.vcs?.branch&&e.set(ua(a)??a,l.vcs.branch);for(const d of l.session)d?.id&&r.set(d.id,d.title);for(const[d,f]of Object.entries(l.session_status??{})){const m=f?.type,u=m==="busy"?"busy":m==="retry"?"retry":"idle",p=t.get(d);(!p||p==="idle")&&t.set(d,u)}for(const[d,f]of Object.entries(l.permission??{}))for(const m of f??[]){if(!m?.id)continue;const u=m.sessionID||d;n.push({kind:"permission",id:m.id,sessionId:u,sessionTitle:"",label:fC(m),directory:a})}for(const[d,f]of Object.entries(l.question??{}))for(const m of f??[]){if(!m?.id)continue;const u=m.sessionID||d;n.push({kind:"question",id:m.id,sessionId:u,sessionTitle:"",label:mC(m),directory:a})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},wC=()=>{const t=kr.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort((r,o)=>za(o)-za(r)).slice(0,_h).forEach(r=>{const o=ti(r);o&&e.add(o)});const n=new Map;for(const r of t){if(!r?.id)continue;const o=ti(r);if(!o||!e.has(o))continue;const a=n.get(o)??[];a.push(r.id),n.set(o,a)}return n},yC=t=>{const e=bC(),n=km.getState().index.session,r=kr.getState().activeSessions,o=new Map(e.titleById),a=new Map;for(const g of r)if(g?.id&&(g.title&&o.set(g.id,g.title),g.parentID)){const h=a.get(g.parentID)??[];h.push(g.id),a.set(g.parentID,h)}const c=g=>{const h=[],k=[...a.get(g)??[]],j=new Set;for(;k.length;){const S=k.pop();j.has(S)||(j.add(S),h.push(S),k.push(...a.get(S)??[]))}return h},l=Cm.getState().statusById,d=g=>{const h=e.statusById.get(g);return h&&h!=="idle"?h:l.get(g)?.status??h??"idle"},f=g=>{const h=g.map(k=>d(k));return h.includes("busy")?"busy":h.includes("retry")?"retry":"idle"},m=Ds.getState().projects,u=ht.getState().availableWorktreesByProject,p=r.filter(g=>g?.id&&!g.parentID).slice().sort((g,h)=>za(h)-za(g)).slice(0,_h).map(g=>{const h=[g.id,...c(g.id)],k=ti(g)??"";return{id:g.id,title:g.title||"Untitled session",status:f(h),branch:k?e.branchByDirectory.get(k)??"":"",unseen:h.reduce((j,S)=>j+(n.unseenCount[S]??0),0),hasError:h.some(j=>n.unseenHasError[j]??!1),directory:k,subtitle:pC(k,g,m,u,e.branchByDirectory)}}),x=e.approvals.map(g=>({...g,sessionTitle:o.get(g.sessionId)||""})),b=Ee.getState();let w=0;if(b.dockBadgeEnabled)for(const g of r){if(!g?.id||g.parentID)continue;let h=n.unseenCount[g.id]??0;h===0&&b.notifyOnSubtasks&&(h=c(g.id).reduce((k,j)=>k+(n.unseenCount[j]??0),0)),h>0&&(w+=1)}return{sessions:p,approvals:x,instanceName:t,usage:gC(),dockBadgeCount:w}},vC=()=>{i.useEffect(()=>{if(!_f()||!Wa())return;let t=!1,e="",n=null,r="";const o=()=>{if(t)return;const C=yC(r),y=JSON.stringify(C);y!==e&&(e=y,Zr("desktop_tray_update",C))};xC().then(C=>{t||(r=C,o())});const a=async()=>{const C=wC();await Promise.all([...C.entries()].map(async([y,P])=>{const _=await sr.getSessionStatusForDirectory(y).catch(()=>null);t||_===null||Rx(y,_,P)}))},c=()=>{t||n!==null||(n=window.setTimeout(()=>{n=null,o()},dC))},l=new Map,d=()=>{if(t)return;let C;try{C=Ia()}catch{return}const y=new Set;for(const[P,_]of C.children.entries())y.add(P),l.has(P)||l.set(P,_.subscribe(()=>c()));for(const[P,_]of l)y.has(P)||(_(),l.delete(P))};let f=null;try{f=Ia().subscribeRegistry(()=>{d(),c()})}catch{}d();const m=km.subscribe(()=>c()),u=kr.subscribe(()=>c()),p=Ds.subscribe(()=>c()),x=ht.subscribe(()=>c()),b=yn.subscribe(()=>c()),w=Ee.subscribe(()=>c()),g=Cm.subscribe(()=>c());Ix(im());const h=window.setInterval(()=>{Ta()},uC);a();const k=window.setInterval(()=>{a()},Vf),j=pn.subscribe(()=>c());pn.getState().loadSettings().then(()=>{if(t)return;const{dropdownProviderIds:C,results:y}=pn.getState();C.length>0&&C.some(_=>!y.some(v=>v.providerId===_))&&pn.getState().fetchAllQuotas()});const S=window.setInterval(()=>{const C=pn.getState();C.autoRefresh&&C.dropdownProviderIds.length>0&&C.fetchAllQuotas()},Math.max(3e4,pn.getState().refreshIntervalMs||6e4)),N=window.setInterval(()=>{d(),o()},Vf);return o(),()=>{t=!0,n!==null&&window.clearTimeout(n),window.clearInterval(N),window.clearInterval(h),window.clearInterval(k),window.clearInterval(S),m(),u(),p(),x(),b(),w(),g(),j(),f?.();for(const C of l.values())C();l.clear()}},[]),i.useEffect(()=>{if(!_f()||typeof window>"u")return;const e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!="function")return;const n=o=>{o.type==="respond-permission"&&Ex(o.sessionId,o.id,o.response).catch(()=>{le.error("Failed to respond to permission request")})};let r=null;return e(cC,o=>{const a=o?.payload;!a||typeof a!="object"||typeof a.type!="string"||n(a)}).then(o=>{r=o}).catch(()=>{}),()=>{try{const o=r?.();o instanceof Promise&&o.catch(()=>{})}catch{}}},[])},jC="/api/notifications/stream",SC=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),NC=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="openchamber:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},kC=t=>{const e=gt.c(3),n=t?.enabled??!0;let r,o;e[0]!==n?(r=()=>{if(!n||pr()||!Sc()||typeof window>"u"||typeof EventSource>"u")return;const a=new EventSource(Li().sse(jC));return a.onmessage=CC,()=>{a.close()}},o=[n],e[0]=n,e[1]=r,e[2]=o):(r=e[1],o=e[2]),i.useEffect(r,o)};function CC(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Ee.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&SC())return;const r=NC(e);if(!r)return;Wo()?.notifications?.notifyAgentCompletion(r)}const $f="pwa-install-toast-shown",zf="pwa-install-toast-dismissed",AC=()=>{const t=gt.c(6),{browserTab:e}=pb(),{t:n}=yt(),r=i.useRef(n);let o,a;t[0]!==n?(o=()=>{r.current=n},a=[n],t[0]=n,t[1]=o,t[2]=a):(o=t[1],a=t[2]),i.useEffect(o,a);let c,l;t[3]!==e?(c=()=>{if(typeof window>"u"||!Sc()||!e)return;let d=null,f=null;const m=()=>{f!==null&&(le.dismiss(f),f=null)},u=async()=>{if(!d)return;const b=d;d=null,m(),await b.prompt();const{outcome:w}=await b.userChoice;w==="accepted"&&le.success(r.current("pwa.installPrompt.started"))},p=b=>{const w=b;if(typeof w.prompt!="function")return;w.preventDefault(),d=w;const g=Qi(),h=qf();gb({dismissed:g.getItem(zf),sessionShown:h.getItem($f),hasActiveToast:f!==null})&&(h.setItem($f,"true"),f=le.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{Qi().setItem(zf,"true"),m()}}}))},x=()=>{d=null,m(),le.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",p),window.addEventListener("appinstalled",x),()=>{m(),window.removeEventListener("beforeinstallprompt",p),window.removeEventListener("appinstalled",x)}},l=[e],t[3]=e,t[4]=c,t[5]=l):(c=t[4],l=t[5]),i.useEffect(c,l)},DC=({open:t,onOpenChange:e})=>{const{t:n}=yt(),r=!1,[o,a]=i.useState(null),[c,l]=i.useState(null),[d,f]=i.useState(!1),[m,u]=i.useState(!1),[p,x]=i.useState(null),[b,w]=i.useState(!1);i.useCallback(async()=>{},[p,d,r,n]),i.useEffect(()=>{if(!t)return;(async()=>{try{const k=await Is("/api/system/info");if(k.ok){const j=await k.json();if(typeof j.openchamberVersion=="string"&&j.openchamberVersion.trim()){a(j.openchamberVersion);return}}}catch{}a(await Fx())})()},[t]),i.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{try{const j=await Is("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!j.ok)return;const S=await j.json().catch(()=>null),N=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!h&&N&&l(N)}catch{}})(),()=>{h=!0}},[t]),i.useEffect(()=>{{x(null),w(!1);return}},[t,r]);const g=o;return s.jsx(_s,{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(Oc,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[g&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:g})}),c&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:c})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/openchamber/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:"https://x.com/openchamber_dev",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},Hl=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},TC=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to OpenChamber and click Authorize again.":n},PC=()=>{const t=xb(a=>a.completeAuth),[e,n]=i.useState("working"),[r,o]=i.useState("Completing MCP authorization...");return i.useEffect(()=>{if(typeof window>"u"){n("error"),o("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),c=Hl(a,"code"),l=bb(a),d=wb(a),f=Hl(a,"error"),m=Hl(a,"error_description");if(f){d&&Is(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(m??f);return}(async()=>{try{if(!c)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let u=l;if(!u&&d){const p=await Is(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(p.ok){const x=await p.json().catch(()=>null);x?.name?.trim()&&(u={name:x.name.trim(),directory:typeof x.directory=="string"&&x.directory.trim()?x.directory.trim():null})}}if(!u?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(u.name,c,u.directory),d&&await Is(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),o("Authorization completed. You can close this tab and return to OpenChamber.")}catch(u){d&&await Is(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(TC(u,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(ze,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},Wf=po(()=>mo(()=>import("./OnboardingScreen-CpcR0gyq.js"),__vite__mapDeps([11,1,3,4,2])).then(t=>({default:t.OnboardingScreen}))),IC=()=>{const t=gt.c(3),e=Ee(LC),n=Ee(BC);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(DC,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},RC=t=>{const e=gt.c(21),{onRetry:n,isRetrying:r}=t,{t:o}=yt();let a;e[0]!==o?(a=o("startup.initRecovery.title"),e[0]=o,e[1]=a):a=e[1];let c;e[2]!==a?(c=s.jsx("h1",{className:"typography-title text-foreground",children:a}),e[2]=a,e[3]=c):c=e[3];let l;e[4]!==o?(l=o("startup.initRecovery.description"),e[4]=o,e[5]=l):l=e[5];let d;e[6]!==l?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:l}),e[6]=l,e[7]=d):d=e[7];let f;e[8]!==c||e[9]!==d?(f=s.jsxs("div",{className:"flex flex-col gap-2",children:[c,d]}),e[8]=c,e[9]=d,e[10]=f):f=e[10];let m;e[11]!==r||e[12]!==o?(m=o(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=o,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(ze,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let p;return e[18]!==f||e[19]!==u?(p=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[f,u]})}),e[18]=f,e[19]=u,e[20]=p):p=e[20],p},Uf=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",EC=()=>{if(typeof window>"u"||!_x())return null;const t=new URLSearchParams(window.location.search),e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),o=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:o,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},MC=()=>typeof window>"u"?!1:window.location.pathname===Sb,FC=t=>{const e=gt.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:o}=t,a=Js(VC),c=ht(_C),l=ht($C),d=_c(),f=i.useRef(null);let m;e[0]!==n.directory?(m=Uf(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let p;e[2]!==a?(p=Uf(a),e[2]=a,e[3]=p):p=e[3];const x=p;let b,w;if(e[4]!==x||e[5]!==c||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==u||e[9]!==r||e[10]!==l||e[11]!==d?(b=()=>{if(r||u&&x!==u)return;const N=`${u}
|
|
237
|
+
${n.sessionId}`;f.current===N&&c||(f.current=N,l(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},w=[x,c,n.directory,n.sessionId,u,r,l,d],e[4]=x,e[5]=c,e[6]=n.directory,e[7]=n.sessionId,e[8]=u,e[9]=r,e[10]=l,e[11]=d,e[12]=b,e[13]=w):(b=e[12],w=e[13]),i.useEffect(b,w),u&&x!==u)return null;let g;e[14]!==o?(g=s.jsx(Am,{embeddedBackgroundWorkEnabled:o}),e[14]=o,e[15]=g):g=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Bm,{}),e[16]=h):h=e[16];let k;e[17]!==n.readOnly?(k=s.jsx(tc,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=k):k=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Dm,{}),e[19]=j):j=e[19];let S;return e[20]!==g||e[21]!==k?(S=s.jsxs(s.Fragment,{children:[g,h,k,j]}),e[20]=g,e[21]=k,e[22]=S):S=e[22],S};function OC({apis:t}){i.useEffect(()=>{Pp("App:mounted"),Ip()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=rs(z=>z.initializeApp),n=rs(z=>z.isInitialized),r=rs(z=>z.isConnected),o=rs(z=>z.providers.length),a=rs(z=>z.agents.length),c=rs(z=>z.loadProviders),l=rs(z=>z.loadAgents),d=ht(z=>z.error),f=ht(z=>z.clearError),m=Js(z=>z.currentDirectory),u=Js(z=>z.setDirectory),p=Js(z=>z.isSwitchingDirectory),[x,b]=i.useState(!1),w=$i(z=>z.refreshStatus),[g,h]=i.useState(()=>t.runtime.isVSCode),[k,j]=i.useState(!0),[S,N]=i.useState(!1),[C,y]=i.useState(0),[P,_]=i.useState(0),[v,F]=i.useState(!1),I=Ee(z=>z.wideChatLayoutEnabled),R=Ee(z=>z.mobileKeyboardMode),B=i.useMemo(()=>pr(),[]),D=Cc(z=>z.setPlanModeEnabled),[W,U]=i.useState(()=>Td()),[L,M]=i.useState(()=>{const z=Pd();return z!==null?Id({isDesktopShell:!0,bootOutcome:z}):null}),ee=i.useRef(!1),ie=i.useMemo(()=>EC(),[]),te=!ie||k,H=i.useMemo(()=>MC(),[]);i.useEffect(()=>(Rd(x),()=>{Rd(!1)}),[x]),i.useEffect(()=>{Rp(R)},[R]),i.useEffect(()=>{h(t.runtime.isVSCode)},[t.runtime.isVSCode]),i.useEffect(()=>em(z=>{yb(z),_(K=>K+1),N(!1),y(K=>K+1)}),[]);const J=Jd(z=>{const K=Ed();return Object.values(z.runsByOriginalSessionID).filter(Y=>Y.status==="running"&&Y.runtimeKey===K).map(Y=>`${Y.originalSessionID}:${Y.phase}:${Y.lastForwardedMessageID??""}:${Y.expectedAssistantParentID??""}`).sort().join("|")});i.useEffect(()=>{if(ie)return;const z=Ed(),K=Object.values(Jd.getState().runsByOriginalSessionID).filter(Y=>Y.status==="running"&&Y.runtimeKey===z);for(const Y of K)Ox(Y.originalSessionID)},[J,ie,P]),i.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",I),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[I]),i.useEffect(()=>(Md(t),()=>Md(null)),[t]),i.useEffect(()=>{ie||w(t.github,{force:!0})},[t.github,ie,w]),Lx();const re=W==="valid",oe=L?.screen==="main";i.useEffect(()=>{if(!Ep({isDesktopShell:B,isInitialized:n,bootOutcomeKnown:re,bootViewIsMain:oe}))return;const z=setTimeout(()=>{const K=document.getElementById("initial-loading");K&&(K.classList.add("fade-out"),setTimeout(()=>{K.remove()},300))},150);return()=>clearTimeout(z)},[B,n,re,oe]),i.useEffect(()=>{if(!B||W!=="malformed")return;const z=document.getElementById("initial-loading");z&&(z.textContent="Desktop startup failed — please restart the app.")},[B,W]),i.useEffect(()=>{if(B)return;const z=setTimeout(()=>{const K=document.getElementById("initial-loading");K&&!n&&(K.classList.add("fade-out"),setTimeout(()=>{K.remove()},300))},5e3);return()=>clearTimeout(z)},[B,n]),i.useEffect(()=>{let z=!1;return(async()=>{const Y=await Is("/health",{method:"GET"}).catch(()=>null);if(!Y||!Y.ok||z)return;const me=await Y.json().catch(()=>null);if(!me||z)return;const Ne=me.planModeExperimentalEnabled;D(Ne===!0||Ne===1||Ne==="1"||Ne==="true")})(),()=>{z=!0}},[D]),i.useEffect(()=>{g||e()},[e,g]),i.useEffect(()=>{if(g||n)return;let z=!0,K,Y=0;const me=10,Ne=1e3,Be=async()=>{if(!z)return;if(Y>=me){N(!0);return}const _e=rs.getState();if(_e.isInitialized){N(!1);return}Y+=1,await _e.initializeApp();const Oe=rs.getState();if(!z)return;if(Oe.isInitialized){N(!1);return}if(Y>=me){N(!0);return}const pe=Math.min(Ne*Math.pow(2,Y-1),16e3);K=setTimeout(Be,pe)};return K=setTimeout(Be,Ne),()=>{z=!1,K&&clearTimeout(K)}},[C,n,g]),i.useEffect(()=>{n&&N(!1)},[n]),i.useEffect(()=>{if(!S)return;const z=document.getElementById("initial-loading");z&&(z.classList.add("fade-out"),setTimeout(()=>{z.remove()},300))},[S]),i.useEffect(()=>{if(g||!r||o>0&&a>0)return;let z=!0,K=0;const Y=15,me=async()=>{const Be=rs.getState();if(!(Be.providers.length>0&&Be.agents.length>0))try{Be.providers.length===0&&await c({source:"startupRecovery"}),rs.getState().agents.length===0&&await l({source:"startupRecovery"})}catch{}};me();const Ne=setInterval(()=>{if(z){if(++K>=Y){clearInterval(Ne);return}me()}},2e3);return()=>{z=!1,clearInterval(Ne)}},[r,g,l,c,o,a]),i.useEffect(()=>{p||g||r&&sr.setDirectory(m)},[m,p,r,g]),i.useEffect(()=>{if(!ie||typeof window>"u")return;const z=me=>{const Ne=me?.visible===!0;j(Ne)},K=me=>{if(me.origin!==window.location.origin)return;const Ne=me.data;Ne?.type==="openchamber:embedded-visibility"&&z(Ne.payload)},Y=window;return Y.__openchamberSetEmbeddedVisibility=z,window.addEventListener("message",K),()=>{window.removeEventListener("message",K),Y.__openchamberSetEmbeddedVisibility===z&&delete Y.__openchamberSetEmbeddedVisibility}},[ie]),i.useEffect(()=>{!ie?.directory||g||m!==ie.directory&&u(ie.directory,{showOverlay:!1})},[m,ie,g,u]),i.useEffect(()=>{if(!ie||typeof window>"u")return;const z=K=>{K.storageArea===window.localStorage&&K.key==="ui-store"&&Ee.persist.rehydrate()};return window.addEventListener("storage",z),()=>{window.removeEventListener("storage",z)}},[ie]),i.useEffect(()=>{if(typeof window>"u")return;const z=K=>{const Y=K.detail,me=typeof Y?.sessionId=="string"?Y.sessionId.trim():"";if(!me)return;const Ne=typeof Y?.directory=="string"&&Y.directory.trim().length>0?Y.directory.trim():null;Ee.getState().setActiveMainTab("chat"),ht.getState().setCurrentSession(me,Ne)};return window.addEventListener("openchamber:open-session",z),()=>window.removeEventListener("openchamber:open-session",z)},[]),i.useEffect(()=>{if(typeof window>"u")return;const z=()=>{const K=Js.getState().currentDirectory,{activeProjectId:Y,projects:me}=Ds.getState(),Ne=me.find(Be=>Be.id===Y)??null;Zr("desktop_open_draft_mini_chat_window",{directory:K||Ne?.path||"",projectId:Ne?.id??null})};return window.addEventListener("openchamber:open-mini-chat",z),()=>window.removeEventListener("openchamber:open-mini-chat",z)},[]),i.useEffect(()=>{if(typeof window>"u")return;const z=()=>{const K=ht.getState().currentSessionId;K&&xm(K)};return window.addEventListener("focus",z),()=>window.removeEventListener("focus",z)},[]),i.useEffect(()=>{if(typeof window>"u")return;const z=K=>{const Y=K.detail,me=typeof Y?.directory=="string"&&Y.directory.trim().length>0?Y.directory.trim():null,Ne=typeof Y?.projectId=="string"&&Y.projectId.trim().length>0?Y.projectId.trim():null;Ee.getState().setActiveMainTab("chat"),Ee.getState().setSessionSwitcherOpen(!1),ht.getState().openNewSessionDraft({selectedProjectId:Ne,directoryOverride:me,preserveDirectoryOverride:!!me})};return window.addEventListener("openchamber:open-draft-session",z),()=>window.removeEventListener("openchamber:open-draft-session",z)},[]),i.useEffect(()=>{if(typeof window>"u")return;const z=K=>{const Y=K.detail,me=typeof Y?.projectPath=="string"?Y.projectPath.trim():"";if(!me)return;const Ne=Ds.getState(),Be=Ne.projects.find(_e=>_e.path===me);Be?Ne.setActiveProject(Be.id):Ne.addProject(me)};return window.addEventListener("openchamber:open-project",z),()=>window.removeEventListener("openchamber:open-project",z)},[]),i.useEffect(()=>{typeof window>"u"||!n||p||ee.current||(ee.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,p]),Bx({enabled:te}),kC({enabled:te}),AC(),Vx(),vb();const ve=i.useCallback(()=>{b(z=>!z)},[]);lC(ve),vC(),i.useEffect(()=>{if(ie)return;const z=K=>{Ac(K)&&K.shiftKey&&!K.altKey&&(K.code==="KeyD"||K.key.toLowerCase()==="d")&&(K.preventDefault(),b(me=>!me))};return window.addEventListener("keydown",z,!0),()=>window.removeEventListener("keydown",z,!0)},[ie]),i.useEffect(()=>{ie||d&&setTimeout(()=>f(),5e3)},[f,ie,d]),i.useEffect(()=>{if(!B||W!=="not-injected")return;let z=!1,K=0;const Y=200,me=2e3,Ne=50,Be=()=>{if(z)return;K++;const _e=Td();if(_e!=="not-injected"){if(z=!0,U(_e),_e==="valid"){const pe=Pd();pe&&M(Id({isDesktopShell:!0,bootOutcome:pe}))}return}const Oe=Math.min(Y*Math.pow(1.1,K),me);if(K>=Ne){const pe=document.getElementById("initial-loading");pe&&!pe.textContent?.includes("taking longer")&&(pe.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(Be,Oe)};return window.setTimeout(Be,Y),()=>{z=!0}},[B,W]);const ne=i.useCallback(async()=>{if(Mp({isDesktopShell:pr(),isDesktopLocalOriginActive:io()})){await Fp();return}window.location.reload()},[]),ye=i.useCallback(async()=>{if(!v){N(!1),F(!0);try{await rs.getState().initializeApp()}finally{F(!1)}rs.getState().isInitialized||y(z=>z+1)}},[v]),he=z=>{if(z.screen==="recovery")return z.variant};if(B&&L&&L.screen!=="main"){if(L.screen==="chooser")return s.jsx(an,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(i.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Wf,{mode:"first-launch",onCliAvailable:ne,onChooseRemote:()=>{}})})})});const z=he(L),K=L.screen==="recovery"&&"url"in L?L.url:void 0;return s.jsx(an,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(i.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Wf,{mode:"recovery",recoveryVariant:z,recoveryHostUrl:K,recoveryHostLabel:void 0,onCliAvailable:ne})})})})}if(ie)return s.jsx(an,{children:s.jsx(Xd,{sdk:sr.getSdkClient(),directory:m||"",children:s.jsx(Zd,{apis:t,children:s.jsx(eu,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(FC,{embeddedSessionChat:ie,isVSCodeRuntime:g,embeddedBackgroundWorkEnabled:te})})})})},P)});if(H)return s.jsx(an,{children:s.jsx(PC,{})});if(S&&!n&&!g&&!ie)return s.jsx(an,{children:s.jsx(RC,{onRetry:()=>{ye()},isRetrying:v})});const Fe=!n&&!B;return s.jsx(an,{children:s.jsx(Xd,{sdk:sr.getSdkClient(),directory:m||"",children:s.jsx(Zd,{apis:t,children:s.jsx(Zw,{children:s.jsx(eu,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:B?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(Am,{embeddedBackgroundWorkEnabled:te}),s.jsx(Bm,{}),s.jsx(Gk,{}),s.jsx(Dm,{}),!Fe&&s.jsxs(s.Fragment,{children:[s.jsx(jb,{}),s.jsx(IC,{}),x&&s.jsx(Yk,{onClose:()=>b(!1)})]})]})})})})},P)})}function LC(t){return t.isAboutDialogOpen}function BC(t){return t.setAboutDialogOpen}function VC(t){return t.currentDirectory}function _C(t){return t.currentSessionId}function $C(t){return t.setCurrentSession}const zC=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();$x();Op().then(()=>{Promise.all([Lp(),zx()]).catch(t=>{console.error("[main] settings init failed:",t)}),Wx(),Ux(),Hx()}).catch(t=>{console.error("[main] appearance init failed:",t)});const $h=document.getElementById("root");if(!$h)throw new Error("Root element not found");gp.createRoot($h).render(s.jsx(nt.StrictMode,{children:s.jsx(Gx,{children:s.jsx(Kx,{children:s.jsx(qx,{children:s.jsx(Yx,{children:s.jsx(OC,{apis:zC})})})})})}));const JC=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{E1 as D,Bk as M,JC as m,Ws as u};
|