@pi-chamber/web 1.0.4-rc.2 → 1.0.4
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/dist/assets/DiagramView-BpG1c3Hi.js +1 -0
- package/dist/assets/{DiffView-Cay8VAqL.js → DiffView-BxwoRCYx.js} +5 -5
- package/dist/assets/FileSaveConflictDialog-DP7k9a-i.js +3 -0
- package/dist/assets/{FilesView-CEeQzjc6.js → FilesView-D_2QcdUt.js} +4 -4
- package/dist/assets/{GitHubDetailScaffold-q4YP8iyJ.js → GitHubDetailScaffold-UxLAMAOl.js} +2 -2
- package/dist/assets/GitHubLinkPicker-Bh9RO1yK.js +1 -0
- package/dist/assets/{GitHubListPrimitives-XkALat1v.js → GitHubListPrimitives-DQyhT5wG.js} +1 -1
- package/dist/assets/{GitView-DV3d0oSJ.js → GitView-XBBheKRM.js} +4 -4
- package/dist/assets/{IssuesSurface-OTyt9f3A.js → IssuesSurface-BA1kpvAJ.js} +3 -3
- package/dist/assets/{JsonTreeView-X2Auiy_q.js → JsonTreeView-BAaEPL4O.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-DzgDmUsL.js +12 -0
- package/dist/assets/{PatchDiff-GMQAv4en.js → PatchDiff-BMEUsgXH.js} +1 -1
- package/dist/assets/{PierreDiffViewer-0X__nypk.js → PierreDiffViewer-BW8MO-O6.js} +2 -2
- package/dist/assets/PullRequestsSurface-B3ictm4I.js +2 -0
- package/dist/assets/SessionSwitcherContent-rLoyVqgs.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-CfySKnUu.js +2 -0
- package/dist/assets/{SessionUnreadDot-CJFawQpo.js → SessionUnreadDot-CmEF9sxM.js} +1 -1
- package/dist/assets/SettingsView-BiwlwnTK.js +6 -0
- package/dist/assets/SettingsWindow-j0e99YI0.js +1 -0
- package/dist/assets/ToolOutputDialog-VlS12Xyq.js +8 -0
- package/dist/assets/ToolPartDiffPreview-DdSneZws.js +1 -0
- package/dist/assets/{VirtualizedFileDiff-CUWx7JVZ.js → VirtualizedFileDiff-BqiXjvP6.js} +1 -1
- package/dist/assets/{Virtualizer-wpC51ZBQ.js → Virtualizer-Cp_cJWbI.js} +1 -1
- package/dist/assets/{collapsible-Ce85nuXX.js → collapsible-C7oyikVm.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-3PpRLd5B.js → computeVirtualFileMetrics-BJjC-tXV.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-PoBklHMz.js → contextFileOpenGuard-BBzqKGei.js} +1 -1
- package/dist/assets/{gitStatusPredicates-BvzxqidP.js → gitStatusPredicates-Dq-E5DaH.js} +1 -1
- package/dist/assets/{githubLink-iQ51wqRa.js → githubLink-Cryd7GkG.js} +5 -5
- package/dist/assets/index-BbhXFTId.js +1 -0
- package/dist/assets/index-BnZVqcki.js +11 -0
- package/dist/assets/index-BnieExes.css +1 -0
- package/dist/assets/{main-PSCt716b.js → main-9O5IAtT_.js} +4 -4
- package/dist/assets/{main-FasHq7Ck.js → main-DWGwALIw.js} +2 -2
- package/dist/assets/{markdownCore-BH56o6Wu.js → markdownCore-B9AuEyYi.js} +1 -1
- package/dist/assets/miniChat-CgOaJfD8.js +2 -0
- package/dist/assets/mobile-BbJcYVym.js +2 -0
- package/dist/assets/nativeFileSave-BzhtrDoD.js +1 -0
- package/dist/assets/{pi-session-focus-preference-D2-1HWmY.js → pi-session-focus-preference-Bmk1iOvn.js} +4 -4
- package/dist/assets/{renderDiffWithHighlighter-l8hZWWBO.js → renderDiffWithHighlighter-CVLsdtQ5.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-R5o9NwFC.js +2 -0
- package/dist/assets/{renderFileWithHighlighter-BvDoP7ob.js → renderFileWithHighlighter-DJ9mk2bZ.js} +1 -1
- package/dist/assets/renderMobileApp-CQ9tWYIj.js +11 -0
- package/dist/assets/runtimeEndpointReset-CtK4C_5h.js +62 -0
- package/dist/assets/{runtimeSurface-B1GRkkKC.js → runtimeSurface-DBiUWYK2.js} +1 -1
- package/dist/assets/useAppFontEffects-DviRbaCJ.js +212 -0
- package/dist/assets/{useFilesViewSearch-D1jsGQrN.js → useFilesViewSearch-D2Au5Xgt.js} +1 -1
- package/dist/assets/{useGitHubRemoteSearch-zNgy2bSt.js → useGitHubRemoteSearch-D-K7aolk.js} +1 -1
- package/dist/assets/{useSwitcherItems-OCRYcHeu.js → useSwitcherItems-Dej8BzXI.js} +1 -1
- package/dist/assets/vendor-aparajita-capacitor-secure-storage-BYohCVY0.js +1 -0
- package/dist/assets/{vendor-base-ui-DIkTOIJS.js → vendor-base-ui-BscvGUFt.js} +1 -1
- package/dist/assets/vendor-boot-Dgb9NVFe.js +69 -0
- package/dist/assets/vendor-capacitor-app-BjdQVib9.js +1 -0
- package/dist/assets/vendor-capacitor-keyboard-eTtI5go3.js +1 -0
- package/dist/assets/vendor-capacitor-push-notifications-CBKq2Arn.js +1 -0
- package/dist/assets/vendor-capacitor-status-bar-9rNIGxlO.js +1 -0
- package/dist/assets/{vendor-codemirror-autocomplete-DsFn4GLp.js → vendor-codemirror-autocomplete-DxS3jwvE.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-B_NMmBbS.js → vendor-codemirror-lang-angular-DdjXl9e2.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-cpp--aMr7NVt.js +1 -0
- package/dist/assets/vendor-codemirror-lang-css-CZ_qxZY9.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-go-C2KHbcll.js → vendor-codemirror-lang-go-Ca-y2Alu.js} +2 -2
- package/dist/assets/vendor-codemirror-lang-html-COZ0L5wT.js +1 -0
- package/dist/assets/vendor-codemirror-lang-java-D3Rf3QNJ.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-javascript-DpTUrvx8.js → vendor-codemirror-lang-javascript-DwJ-IvCs.js} +2 -2
- package/dist/assets/vendor-codemirror-lang-jinja-D_5lod6k.js +1 -0
- package/dist/assets/vendor-codemirror-lang-json-BG8C7OpC.js +1 -0
- package/dist/assets/vendor-codemirror-lang-less-CVEkoaTw.js +1 -0
- package/dist/assets/vendor-codemirror-lang-liquid-U9vj0m8w.js +1 -0
- package/dist/assets/vendor-codemirror-lang-markdown-DqlYH9gY.js +1 -0
- package/dist/assets/vendor-codemirror-lang-php-BFEiEVA1.js +1 -0
- package/dist/assets/vendor-codemirror-lang-python-Cz1dQXQd.js +3 -0
- package/dist/assets/vendor-codemirror-lang-rust-C_CoD9mj.js +1 -0
- package/dist/assets/vendor-codemirror-lang-sass-BuR0aKh5.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-sql-C_RazIaB.js → vendor-codemirror-lang-sql-DggNUjdM.js} +2 -2
- package/dist/assets/{vendor-codemirror-lang-vue-BYL0r7KR.js → vendor-codemirror-lang-vue-DFZHi2J3.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-wast-zuTN3SHT.js +1 -0
- package/dist/assets/vendor-codemirror-lang-xml-CrcvhI-k.js +1 -0
- package/dist/assets/vendor-codemirror-lang-yaml-DcVWsakb.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-DglcKYWT.js → vendor-codemirror-language-data-CCLITgCF.js} +2 -2
- package/dist/assets/{vendor-codemirror-search-DaE6R5gH.js → vendor-codemirror-search-H7NOEdbX.js} +2 -2
- package/dist/assets/{vendor-lezer-cpp-Dt99h3WT.js → vendor-lezer-cpp-C8aD2KAr.js} +1 -1
- package/dist/assets/{vendor-lezer-css-DNU_fzPI.js → vendor-lezer-css-2lbTJF-Y.js} +1 -1
- package/dist/assets/{vendor-lezer-go-BEFtcNyS.js → vendor-lezer-go-Bw6LFTrZ.js} +1 -1
- package/dist/assets/{vendor-lezer-html-DDGRhRUz.js → vendor-lezer-html-D7ym2z7S.js} +1 -1
- package/dist/assets/{vendor-lezer-java-DmfZtW09.js → vendor-lezer-java-CZhK7w21.js} +1 -1
- package/dist/assets/{vendor-lezer-javascript-oje4tdp_.js → vendor-lezer-javascript-rpKeTHZp.js} +1 -1
- package/dist/assets/{vendor-lezer-json-BRXb_bDX.js → vendor-lezer-json-C7jwsd2G.js} +1 -1
- package/dist/assets/{vendor-lezer-lr-BU2qmu_5.js → vendor-lezer-lr-DR-ylqNN.js} +1 -1
- package/dist/assets/{vendor-lezer-markdown-CicYv7V9.js → vendor-lezer-markdown-Bir0m5nB.js} +1 -1
- package/dist/assets/{vendor-lezer-php-COORrTpE.js → vendor-lezer-php-y0hIEfo1.js} +1 -1
- package/dist/assets/{vendor-lezer-python-Cuvm9X9Y.js → vendor-lezer-python-D64A9lNV.js} +1 -1
- package/dist/assets/{vendor-lezer-rust-C_zOfHbX.js → vendor-lezer-rust-E3ZA9T2L.js} +1 -1
- package/dist/assets/{vendor-lezer-sass-DWP4w7O1.js → vendor-lezer-sass-C5UFI9SP.js} +1 -1
- package/dist/assets/{vendor-lezer-xml-Br6nOYeG.js → vendor-lezer-xml-DOy7FzCR.js} +1 -1
- package/dist/assets/{vendor-lezer-yaml-CYQmm6Sb.js → vendor-lezer-yaml-kEjaSCvZ.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-CZy3BUVv.js → vendor-replit-codemirror-vim-BLfh0LPy.js} +1 -1
- package/dist/assets/{web-components-v9fuidaX.js → web-components-C7CmoFxi.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/lib/pi/routes.js +1 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -1
- package/server/lib/pi/session-daemon/supervisor.js +13 -1
- package/server/lib/pi/session-daemon/supervisor.test.js +92 -0
- package/server/lib/relay/DOCUMENTATION.md +4 -0
- package/server/lib/terminal/DOCUMENTATION.md +1 -0
- package/dist/assets/DiagramView-GKGxPczP.js +0 -1
- package/dist/assets/FileSaveConflictDialog-BRM9TJo0.js +0 -3
- package/dist/assets/GitHubLinkPicker-B9xgIW8y.js +0 -1
- package/dist/assets/MarkdownRendererImpl-1HameF6j.js +0 -12
- package/dist/assets/PullRequestsSurface-Dec20SIg.js +0 -2
- package/dist/assets/SessionSwitcherContent-DEw4nz7K.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-DmLhbRzE.js +0 -2
- package/dist/assets/SettingsView-CwSspvq-.js +0 -6
- package/dist/assets/SettingsWindow-DkPv9MaU.js +0 -1
- package/dist/assets/ToolOutputDialog-DDwbOpTO.js +0 -8
- package/dist/assets/ToolPartDiffPreview-DZRP7p-Q.js +0 -1
- package/dist/assets/index-CkMnC_GK.js +0 -1
- package/dist/assets/index-Dd2OcIUY.js +0 -10
- package/dist/assets/index-DvN8zlLT.css +0 -1
- package/dist/assets/miniChat-BzfobBDq.js +0 -2
- package/dist/assets/mobile-DAzZE2EL.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-DGYSIihR.js +0 -2
- package/dist/assets/renderMobileApp-CwgWG0lU.js +0 -11
- package/dist/assets/runtimeEndpointReset-CmI6dBKM.js +0 -62
- package/dist/assets/useAppFontEffects--lKKtKVo.js +0 -212
- package/dist/assets/vendor-aparajita-capacitor-secure-storage-5IShChL0.js +0 -1
- package/dist/assets/vendor-boot-DyL2td56.js +0 -69
- package/dist/assets/vendor-capacitor-app-BrDJj9I_.js +0 -1
- package/dist/assets/vendor-capacitor-core-B4EWRrHz.js +0 -1
- package/dist/assets/vendor-capacitor-keyboard-CYccoJjr.js +0 -1
- package/dist/assets/vendor-capacitor-push-notifications-KNe1zSBF.js +0 -1
- package/dist/assets/vendor-capacitor-status-bar-B-N0EOVk.js +0 -1
- package/dist/assets/vendor-codemirror-lang-cpp-GOE7Gjd0.js +0 -1
- package/dist/assets/vendor-codemirror-lang-css-Dwf2XpnZ.js +0 -1
- package/dist/assets/vendor-codemirror-lang-html-DcKqyeGk.js +0 -1
- package/dist/assets/vendor-codemirror-lang-java-6eGbyB2k.js +0 -1
- package/dist/assets/vendor-codemirror-lang-jinja-xSUJjXhr.js +0 -1
- package/dist/assets/vendor-codemirror-lang-json-CLGxdOCz.js +0 -1
- package/dist/assets/vendor-codemirror-lang-less-6nXi1rS9.js +0 -1
- package/dist/assets/vendor-codemirror-lang-liquid-B9hmb9P8.js +0 -1
- package/dist/assets/vendor-codemirror-lang-markdown-DmFP9s6x.js +0 -1
- package/dist/assets/vendor-codemirror-lang-php-DC6To8iX.js +0 -1
- package/dist/assets/vendor-codemirror-lang-python-yuxIkjit.js +0 -3
- package/dist/assets/vendor-codemirror-lang-rust-di1Sjz-0.js +0 -1
- package/dist/assets/vendor-codemirror-lang-sass-BWpV9NPV.js +0 -1
- package/dist/assets/vendor-codemirror-lang-wast-BiVarhcz.js +0 -1
- package/dist/assets/vendor-codemirror-lang-xml-Cn1lY1ts.js +0 -1
- package/dist/assets/vendor-codemirror-lang-yaml-BZ6mZw9L.js +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BbhXFTId.js","assets/useAppFontEffects-DviRbaCJ.js","assets/index-BnZVqcki.js","assets/vendor-zustand-CUi8eEds.js","assets/vendor-react-DASdDPIk.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-BnieExes.css","assets/vendor-boot-Dgb9NVFe.js","assets/runtimeSurface-DBiUWYK2.js","assets/nativeFileSave-BzhtrDoD.js","assets/computeVirtualFileMetrics-BJjC-tXV.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-yJ9XpNMI.js","assets/vendor-pierre-theming-Dgp7B_O4.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/renderFileWithHighlighter-DJ9mk2bZ.js","assets/renderDiffWithHighlighter-CVLsdtQ5.js","assets/vendor-diff-C3JhlQdm.js","assets/vendor-lru_map-DOPmc7GU.js","assets/appThemeRegistry-gegrE2dq.js","assets/registerCustomTheme-DmolaWWZ.js","assets/vendor-capacitor-keyboard-eTtI5go3.js","assets/SessionSwitcherDropdown-CfySKnUu.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as ht}from"./vendor-vite-runtime-DD1OZmLC.js";import{k as s,b2 as kd,b3 as Ad,b4 as Nd,b5 as Id,b6 as Ed,b7 as Rd,b8 as Dd,aO as Oo,aP as Pn,aQ as Pd,aR as Bo,aS as _o,aV as Md,b9 as Td,ba as Fd,bb as Ld,bc as Sa,bd as ja,be as Ca,bf as ka,bg as Aa,bh as Na,bi as Ia,aT as Ea,a$ as Ra,aY as Da,aZ as Pa,aW as zo,aX as Uo,bj as ro,aL as Od}from"./vendor-boot-Dgb9NVFe.js";import{a as Ee,R as a}from"./vendor-react-DASdDPIk.js";import{aW as Qs,aX as Bd,t as ie,a as ut,h as Te,a4 as an,B as Ne,I as P,ai as Mn,aY as Ma,ak as ns,al as rs,am as vs,an as us,ao as Ss,ap as Ts,aM as Ds,aZ as Ps,a_ as _d,g as Ys,a$ as Or,b0 as wi,b1 as vi,aF as An,e as er,o as Ta,aj as As,b2 as Si,ae as ys,a9 as Ue,aa as $e,ac as Ke,b3 as oo,b4 as zd,b5 as Ud,b6 as $d,b7 as Kd,b8 as Wd,b9 as io,ba as Gd,a8 as Wt,ab as Gt,ad as Ht,H as $t,bb as Hd,bc as qd,bd as Yd,be as Vd,bf as Qd,bg as Jd,aJ as ao,r as Nn,x as $o,at as Xd,aE as Zd,aI as Fa,bh as La,S as ws,bi as eu,bj as tu,bk as su,bl as nu,d as Oa,q as Fs,aD as Ba,bm as wr,bn as ji,bo as _a,bp as pt,bq as ru,aK as za,br as Ua,bs as $a,bt as Ka,af as ft,bu as Wa,ay as ou,i as Ga,k as iu,bv as au,j as lu,bw as Ws,b as Ci,c as cu,bx as du,u as uu,aL as fu,aO as hu,by as lo,bz as mu,bA as pu,aN as gu,bB as bu,bC as xu,V as yu,ag as en,aq as Ha,F as wu,p as vu,bD as Su,m as ju,bE as Cu,bF as qa,bG as ku,bH as Au,bI as Nu,bJ as Iu,bK as Eu,bL as Ru,bM as Du,bN as Pu,bO as Mu,bP as Tu,a5 as Fu,bQ as Lu}from"./useAppFontEffects-DviRbaCJ.js";import{_ as ki,D as Ou,$ as Bu,S as tn,a0 as Ya,a1 as Va,a2 as _u,a3 as zu,u as sn,L as Uu,a4 as $u,a5 as Ku,t as le,m as Tt,o as _,a6 as Wu,f as Qe,a as Mt,A as On,C as Ie,a7 as Tn,a8 as Kt,a9 as co,aa as uo,ab as Qa,v as ds,U as Ko,V as lr,ac as Gu,w as Ja,ad as Hu,ae as Xa,H as qu,R as Za,E as In,af as fo,h as ho,d as Kn,ag as Yu,ah as Vu,ai as Qu,aj as Ai,ak as bn,al as Br,am as mo,an as cr,ao as Ns,ap as Ni,aq as po,ar as el,as as go,at as Ju,au as Xu,av as Zu,aw as ef,ax as tf,ay as sf,az as nf,aA as rf,aB as of,Z as tl,aC as af,aD as lf,Q as cf,aE as df,K as uf}from"./index-BnZVqcki.js";import{g as bs,b as ff,c as sl,r as hf,d as nl,s as tr,e as rl,h as Ms,i as nn,j as mf,k as pf,l as gf,m as bf,n as Wo,o as ol,f as xf,a as Ii,S as yf,t as wf,p as vf}from"./SessionUnreadDot-CmEF9sxM.js";import{c as Ls,d as vr,p as il,a as Sf}from"./vendor-zustand-CUi8eEds.js";/* empty css */import{saveOrShareFile as jf}from"./nativeFileSave-BzhtrDoD.js";import{usePermissionStore as Cf}from"./permissionStore-B9Hkrqny.js";const kf="chat";function al(e){const t=new URLSearchParams;if(e.sessionId&&e.sessionId.trim().length>0&&t.set(Qs.SESSION,e.sessionId),e.isSettingsOpen){const n=e.settingsPath.trim().length>0?e.settingsPath:"home";return t.set(Qs.SETTINGS,n),t}return e.tab!==kf&&t.set(Qs.TAB,e.tab),e.tab==="diff"&&e.diffFile&&e.diffFile.trim().length>0&&t.set(Qs.FILE,e.diffFile),t}function Af(e,t){const n=typeof window<"u"?window.location.pathname:"/",r=n.startsWith("/session")||n.startsWith("/s/")?"/":n,o=e.toString();return o?`${r}?${o}`:r}function Nf(e){if(typeof window>"u")return!0;try{const t=new URLSearchParams(window.location.search),n=al(e),r=window.location.pathname.match(/^\/(?:session|s)\/([^/?#]+)/i),o=r?.[1]?decodeURIComponent(r[1].trim()):null;o&&!t.has(Qs.SESSION)&&t.set(Qs.SESSION,o);const i=[...t.entries()].sort((c,d)=>c[0].localeCompare(d[0])),l=[...n.entries()].sort((c,d)=>c[0].localeCompare(d[0]));if(i.length!==l.length)return!1;for(let c=0;c<i.length;c++)if(i[c][0]!==l[c][0]||i[c][1]!==l[c][1])return!1;return!0}catch{return!0}}function bo(e,t={}){if(!(typeof window>"u")&&!(!t.force&&Nf(e)))try{const n=al(e),r=Af(n);t.replace?window.history.replaceState({...window.history.state,route:e},"",r):window.history.pushState({route:e},"",r)}catch{}}const If=["typescript","javascript","tsx","jsx","json","markdown"],ll={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Ei=null;const cl=()=>(Ei??=Promise.all([ht(()=>import("./index-BbhXFTId.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42])),ht(()=>import("./workerFactory-tw7cIdmV.js"),[]),ht(()=>import("./appThemeRegistry-gegrE2dq.js"),__vite__mapDeps([43,44,30,31,5,15,16,17,18,19,20,21,22,23,24,25,26,27,28]))]).then(([e,t,n])=>({WorkerPoolManager:e.WorkerPoolManager,workerFactory:t.workerFactory,ensurePierreThemeRegistered:n.ensurePierreThemeRegistered})),Ei),Fn={},Ri=new Set,xo=new Set;let sr={light:"pierre-light",dark:"pierre-dark"};const Ef=()=>{for(const e of xo)e()},dl=(e,t)=>{t.setRenderOptions({theme:sr,lineDiffType:ll[e].lineDiffType})},yo=e=>{typeof window>"u"||Ri.has(e)||(Ri.add(e),cl().then(t=>{if(Fn[e])return;const n=ll[e],r=new t.WorkerPoolManager({workerFactory:t.workerFactory,poolSize:n.poolSize,totalASTLRUCacheSize:n.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:If,lineDiffType:n.lineDiffType,preferredHighlighter:"shiki-wasm"});r.initialize(),Fn[e]=r,dl(e,r),Ef()}))},Rf=e=>(xo.add(e),()=>xo.delete(e)),Df=e=>{if(!(sr.light===e.light&&sr.dark===e.dark)){sr=e;for(const t of Object.keys(Fn)){const n=Fn[t];n&&dl(t,n)}}},cx=({children:e})=>{const t=Bd(),n=ki(!1),r=ki(!0),o=t?.lightThemeId??n.metadata.id,i=t?.darkThemeId??r.metadata.id,l=t?.availableThemes.find(d=>d.metadata.id===o)??n,c=t?.availableThemes.find(d=>d.metadata.id===i)??r;return Ee.useEffect(()=>{let d=!1;return cl().then(u=>{d||(u.ensurePierreThemeRegistered(l),u.ensurePierreThemeRegistered(c),Df({light:l.metadata.id,dark:c.metadata.id}))}),()=>{d=!0}},[c,l]),Ee.useEffect(()=>{if(typeof window>"u")return;const d=()=>{yo("unified"),yo("split")};if(typeof window.requestIdleCallback=="function"){const f=window.requestIdleCallback(d,{timeout:5e3});return()=>window.cancelIdleCallback(f)}const u=window.setTimeout(d,2e3);return()=>window.clearTimeout(u)},[]),s.jsx(s.Fragment,{children:e})},dx=(e="unified")=>{const t=Ee.useSyncExternalStore(Rf,()=>Fn[e],()=>{});return Ee.useEffect(()=>{yo(e)},[e]),t};let Wn=null;const ux=()=>{if(typeof window>"u"||typeof document>"u"||Wn)return()=>{};const e=()=>{document.visibilityState!=="hidden"&&Ou()};document.addEventListener("visibilitychange",e),window.addEventListener("focus",e),window.addEventListener("online",e);let t=!1;const n=()=>{t||(t=!0,document.removeEventListener("visibilitychange",e),window.removeEventListener("focus",e),window.removeEventListener("online",e),Wn===n&&(Wn=null))};return Wn=n,n},Pf=e=>e==="/",rn=e=>e.replace(/\\/g,"/"),on=e=>{if(!e||Pf(e))return e;let t=e;for(;t.length>1&&t.endsWith("/");)t=t.slice(0,-1);return t},Xs=e=>e.endsWith("/"),dr=e=>{const t=e.trim();return!t||Xs(t)?t:`${t}/`},Go=e=>e.lastIndexOf("/"),ul=e=>{if(Xs(e))return e;const t=Go(e);return t<0?e:e.slice(0,t+1)},fl=e=>{const t=Go(e);return e.slice(t+1)},hl=e=>{const t=on(e.trim());if(!t||t==="~"||t==="~/"||t==="/")return null;const n=Go(t);return n<0?null:t.startsWith("~/")&&n<=1?"~/":n===0?"/":`${t.slice(0,n)}/`},ml=e=>Xs(e)&&hl(e)!==null,Mf=e=>{if(!ml(e))return null;const t=on(e.trim());return fl(t)||t},Tf=(e,t)=>`${ul(e)}${t}/`,Is=e=>{if(!e)return null;const t=on(rn(e.trim()));return t?t.toLowerCase():null},Di=(e,t)=>{const n=e.trim();return n==="~"?t:n.startsWith("~/")?`${t}${n.slice(1)}`:n},Ff=(e,t)=>{const n=on(rn(e.trim())),r=on(rn(t.trim()));if(!n)return"";if(!r)return dr(n);if(n.toLowerCase()===r.toLowerCase())return"~/";const o=`${r}/`;return n.toLowerCase().startsWith(o.toLowerCase())?`~/${n.slice(r.length+1)}/`:dr(n)},Lf=e=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey,wo=e=>{if(!e)return;e.focus({preventScroll:!0});const t=e.value.length;e.setSelectionRange(t,t),e.scrollLeft=e.scrollWidth},Of=async()=>Bu({fresh:!0}),Bf=()=>{const[e,t]=Ee.useState(!1),[n,r]=Ee.useState(!1);Ee.useEffect(()=>{t(tn()),r(Ya())},[]);const o=Ee.useCallback(async c=>e?await Va(c):{success:!0,path:c},[e]),i=Ee.useCallback(async c=>e?await _u():{success:!0},[e]),l=Ee.useCallback(async c=>e?await zu():{success:!0},[e]);return{isDesktop:e,canRequestAccess:n,requestAccess:o,startAccessing:i,stopAccessing:l}};function _f({open:e,addedProjectPaths:t,shouldSuppressAutoFocus:n}){const r=sn(se=>se.homeDirectory),{canRequestAccess:o,startAccessing:i}=Bf(),l=a.useRef(null),c=a.useRef(new Map),[d,u]=a.useState(""),[f,p]=a.useState("~/"),[x,y]=a.useState([]),[m,h]=a.useState(!1),[b,g]=a.useState(!1),[S,v]=a.useState(null),[E,j]=a.useState(0),[k,C]=a.useState(0),[w,N]=a.useState(!1),[T,O]=a.useState(!1),[$,U]=a.useState("right"),K=a.useRef("~/"),L=d||r;a.useEffect(()=>{if(!e)return;p("~/"),y([]),C(0),N(!1),O(!1),K.current="~/",U("right"),n||requestAnimationFrame(()=>wo(l.current));let se=!1;return(async()=>{const Ce=await Of();se||(u(Ce||r||""),n||requestAnimationFrame(()=>wo(l.current)))})(),()=>{se=!0}},[r,e,n]);const D=a.useMemo(()=>ul(f),[f]),R=a.useMemo(()=>Xs(f)?"":fl(f),[f]),I=a.useMemo(()=>L?Di(D,L):"",[D,L]);a.useEffect(()=>{const se=K.current;se!==D&&(U(D.length>=se.length?"right":"left"),K.current=D)},[D]),a.useEffect(()=>{if(!e||!I){y([]),v(null);return}let se=!1;return h(!0),g(!1),v(null),Uu(I).then(ce=>{if(se)return;g(!1),v(null);const Ce=ce.filter(ve=>ve.isDirectory).map(ve=>({name:ve.name,path:rn(ve.path)})).sort((ve,Ge)=>ve.name.localeCompare(Ge.name));y(Ce)}).catch(ce=>{if(!se){y([]);const Ce=$u(ce)?ce.reason:"unknown";v(Ce),g(Ce==="not-found")}}).finally(()=>{se||h(!1)}),()=>{se=!0}},[I,E,e]);const M=a.useMemo(()=>{const se=R.toLowerCase(),ce=T||R.startsWith(".");return x.filter(Ce=>Ce.name.toLowerCase().startsWith(se)&&(ce||!Ce.name.startsWith(".")))},[R,x,T]),W=a.useMemo(()=>Mf(f),[f]),G=a.useMemo(()=>hl(f),[f]),B=a.useMemo(()=>{const se=[],ce=Is(I);ml(f)&&W&&G&&se.push({type:"parent",value:"browse:up",name:W,path:G,alreadyAdded:!!(ce&&t.has(ce))});for(const Ce of M){const ve=Is(Ce.path);se.push({type:"directory",value:`browse:${Ce.path}`,name:Ce.name,path:Ce.path,alreadyAdded:!!(ve&&t.has(ve))})}return se},[t,I,W,M,G,f]);a.useEffect(()=>{C(0)},[f,B.length]);const xe=a.useMemo(()=>L?on(Di(f,L)):"",[L,f]),V=Is(xe),je=!!(V&&t.has(V)),Re=a.useMemo(()=>R?M.find(se=>se.name===R)??null:null,[R,M]),H=!!(xe&&!je&&(S===null||S==="not-found")&&(Xs(f)&&b||!Xs(f)&&R.trim().length>0&&Re===null)),z=B[k]??null,Y=!!z,X=a.useCallback(se=>{p(dr(se))},[]),te=a.useCallback(se=>{p(Tf(f,se.name))},[f]),ue=a.useCallback(se=>{if(se){if(se.type==="parent"){X(se.path);return}te(se)}},[X,te]),he=a.useCallback(async se=>{const ce=await i(se);if(!ce.success)return ie.error("Failed to open directory",{description:ce.error||"Desktop could not grant file access."}),!1;const Ce=L?Ff(se,L):dr(rn(se));return X(Ce),!0},[X,L,i]),Q=a.useCallback(async()=>{if(!w){N(!0);try{if(Ya()){const ce=await Va(xe);if(!ce.success||!ce.path){ce.error&&ce.error!=="Directory selection cancelled"&&ie.error("Failed to select directory",{description:ce.error});return}await he(ce.path);return}const se=await Ku(xe);if(se.status==="cancelled")return;if(se.status!=="picked"){ie.error("Couldn't open a folder picker",{description:se.error});return}await he(se.path)}catch(se){ie.error("Failed to select directory",{description:se instanceof Error?se.message:"Unknown error occurred."})}finally{N(!1)}}},[he,w,xe]);return{inputRef:l,rowRefs:c,query:f,setQuery:p,isLoading:m,isBrowseDirectoryMissing:b,browseErrorReason:S,browseReloadKey:E,setBrowseReloadKey:j,highlightedIndex:k,setHighlightedIndex:C,isPickingLocation:w,showHidden:T,setShowHidden:O,folderEnterFrom:$,explorerRootDirectory:L,browseDirectoryDisplayPath:D,browseDirectoryAbsolutePath:I,browseFilterQuery:R,filteredEntries:M,rows:B,targetPath:xe,isAlreadyAdded:je,shouldCreateTarget:H,highlightedRow:z,hasHighlightedBrowseItem:Y,canRequestAccess:o,browseToDisplayPath:X,browseToEntry:te,executeRow:ue,applyPickedLocation:he,handleBrowseLocation:Q}}function zf({open:e,onClose:t,isMobile:n,addedProjectPaths:r,targetPath:o,shouldCreateTarget:i,browseErrorReason:l,browseDirectoryAbsolutePath:c,isAlreadyAdded:d,isPickingLocation:u}){const f=ut(O=>O.addProject),p=le(O=>O.setActiveMainTab),x=le(O=>O.setSessionSwitcherOpen),y=Te(O=>O.openNewSessionDraft),[m,h]=a.useState(!1),[b,g]=a.useState(!1),[S,v]=a.useState("");a.useEffect(()=>{e&&(h(!1),g(!1),v(""))},[e]);const E=a.useCallback((O,$)=>{p("chat"),n&&x(!1),y({selectedProjectId:O,directoryOverride:$}),t()},[n,t,y,p,x]),j=a.useCallback(async O=>{if(!O||m)return;const $=Is(O);if($&&r.has($))return;let U=O;h(!0);try{const K=!b&&i&&Is(O)===Is(o);if(b){const D=S.trim();if(!D){ie.error("Enter a repository URL before cloning.");return}const R=await Tt("/api/fs/clone",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({remoteUrl:D,destinationPath:O})});if(!R.ok)throw new Error("Failed to clone git repository");U=(await R.json()).path||O}else if(K&&!(await Tt("/api/fs/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},query:c?{directory:c}:void 0,body:JSON.stringify({path:O})})).ok)throw new Error("Failed to select directory");const L=f(U);if(!L){ie.error("Failed to add folder",{description:"Please select a valid directory path."});return}E(L.id,L.path)}catch(K){ie.error("Failed to select directory",{description:K instanceof Error?K.message:"Unknown error occurred."})}finally{h(!1)}},[f,r,c,S,b,m,E,i,o]),k=!m&&!u&&!d&&l!=="os-permission"&&l!=="invalid-response"&&l!=="unknown"&&!!o,C=k&&S.trim().length>0,w=b?C:k,N=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl";return{isConfirming:m,isCloneMode:b,setIsCloneMode:g,cloneRemoteUrl:S,setCloneRemoteUrl:v,canSubmit:w,submitActionLabel:d?"Already added":b?m?"Cloning...":"Clone & add":m?"Adding...":i?"Create & add":"Add folder",submitModifierLabel:N,finalizeSelection:j}}const Uf=({open:e,onOpenChange:t})=>{const n=ut(Q=>Q.projects),{isMobile:r,isTablet:o}=an(),i=r||o,l=a.useMemo(()=>new Set(n.map(Q=>Is(Q.path)).filter(Q=>!!Q)),[n]),c=a.useCallback(()=>{t(!1)},[t]),{inputRef:d,rowRefs:u,query:f,setQuery:p,isLoading:x,browseErrorReason:y,setBrowseReloadKey:m,highlightedIndex:h,setHighlightedIndex:b,isPickingLocation:g,showHidden:S,setShowHidden:v,folderEnterFrom:E,browseDirectoryDisplayPath:j,browseDirectoryAbsolutePath:k,rows:C,targetPath:w,isAlreadyAdded:N,shouldCreateTarget:T,highlightedRow:O,hasHighlightedBrowseItem:$,canRequestAccess:U,executeRow:K,handleBrowseLocation:L}=_f({open:e,addedProjectPaths:l,shouldSuppressAutoFocus:i}),{isConfirming:D,isCloneMode:R,setIsCloneMode:I,cloneRemoteUrl:M,setCloneRemoteUrl:W,canSubmit:G,submitActionLabel:B,submitModifierLabel:xe,finalizeSelection:V}=zf({open:e,onClose:c,isMobile:r,addedProjectPaths:l,targetPath:w,shouldCreateTarget:T,browseErrorReason:y,browseDirectoryAbsolutePath:k,isAlreadyAdded:N,isPickingLocation:g});a.useLayoutEffect(()=>{const Q=d.current;Q&&(Q.scrollLeft=Q.scrollWidth)},[d,f]),a.useLayoutEffect(()=>{!e||i||wo(d.current)},[d,e,i]),a.useLayoutEffect(()=>{const Q=C[h];Q&&u.current.get(Q.value)?.scrollIntoView({block:"nearest"})},[h,u,C]);const je=a.useCallback(Q=>{if(Q.key==="ArrowDown"){Q.preventDefault(),b(se=>Math.min(C.length-1,se+1));return}if(Q.key==="ArrowUp"){Q.preventDefault(),b(se=>Math.max(0,se-1));return}if(Q.key==="Enter"){if(Q.preventDefault(),Lf(Q)){V(w);return}$&&K(O);return}Q.key==="Backspace"&&f===""&&(Q.preventDefault(),c())},[K,V,c,$,O,f,C.length,b,w]),Re=s.jsxs("button",{type:"button",onClick:()=>v(Q=>!Q),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[S?s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}),"Show hidden"]}),H=s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs("div",{className:"relative min-w-0 flex-1",children:[s.jsx(P,{name:"folder-3",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),s.jsx(Mn,{ref:d,value:f,onChange:Q=>p(rn(Q.target.value)),onKeyDown:je,placeholder:"Enter a folder path...",className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"})]}),s.jsxs(Ne,{variant:"outline",size:"xs",className:"h-8 shrink-0 gap-1 px-2",disabled:D||g,onMouseDown:Q=>Q.preventDefault(),onClick:()=>{L()},title:"Browse location","aria-label":"Browse location",children:[s.jsx(P,{name:"folder-open",className:"h-3.5 w-3.5"}),g?"Opening...":"Browse"]})]})}),z=C.some(Q=>Q.type==="parent"),Y=s.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:s.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 pb-1 pt-0.5",children:[s.jsx("div",{className:"typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:"Directories"}),s.jsxs(Ne,{variant:"ghost",size:"xs",className:"h-6 shrink-0 gap-1 text-muted-foreground","aria-pressed":R,disabled:D||g,onClick:()=>I(Q=>!Q),children:[s.jsx(P,{name:"git-repository",className:"h-3.5 w-3.5"}),"Clone"]})]}),R?s.jsxs("div",{className:"mb-2 space-y-1.5 px-2 pb-1",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:"Clone into the folder path above."}),s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsx(Mn,{value:M,onChange:Q=>W(Q.target.value),placeholder:"Repository URL (HTTPS or SSH)",className:"min-w-0 flex-1 font-mono typography-ui-label",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"})})]}):null,N?s.jsx("p",{className:"px-2 pb-2 typography-meta text-muted-foreground",children:"This folder is already added. Open a subfolder to add that instead."}):null,s.jsx("div",{className:_("mt-3","animate-in fade-in-0 duration-200 motion-reduce:animate-none",E==="left"?"slide-in-from-left-2":"slide-in-from-right-2"),children:x?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:"Loading directories..."}):y&&y!=="not-found"?s.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-10 text-center",children:[s.jsx("div",{className:"typography-ui-label text-status-error",children:y==="os-permission"?"PiChamber needs access to this folder.":"Could not load this folder."}),s.jsxs("div",{className:"flex items-center gap-2",children:[y==="os-permission"&&U?s.jsx(Ne,{size:"xs",onClick:()=>{L()},disabled:g,children:"Grant access"}):null,s.jsx(Ne,{variant:"outline",size:"xs",onClick:()=>m(Q=>Q+1),children:"Try again"})]})]}):C.length===0?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:"No matching directories."}):s.jsx("div",{className:"space-y-0.5",children:C.map((Q,se)=>{const ce=se===h,Ce=Q.type==="directory"&&z;return s.jsxs("button",{ref:ve=>{ve?u.current.set(Q.value,ve):u.current.delete(Q.value)},type:"button","aria-label":Q.type==="parent"?Q.alreadyAdded?`Go back from ${Q.name}, already added`:`Go back from ${Q.name}`:Q.alreadyAdded?`Open ${Q.name}, already added`:`Open ${Q.name}`,onMouseEnter:()=>b(se),onMouseDown:ve=>ve.preventDefault(),onClick:()=>K(Q),className:_("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",ce&&"bg-interactive-selection text-interactive-selection-foreground",!ce&&"hover:bg-interactive-hover/50"),children:[s.jsxs("span",{className:_("flex min-w-0 flex-1 items-center gap-2",Ce&&"pl-4"),children:[Q.type==="parent"?s.jsx(P,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(P,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Q.name})]}),Q.alreadyAdded?s.jsx("span",{className:_("inline-flex shrink-0 items-center rounded-md px-1.5 py-0.5 typography-meta font-medium",ce?"bg-interactive-selection-foreground/15 text-interactive-selection-foreground":"bg-[var(--surface-muted)] text-foreground"),children:"Added"}):null,Q.type==="parent"?s.jsx(P,{name:"arrow-up-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80","aria-hidden":"true"}):s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80","aria-hidden":"true"})]},Q.value)})})},j)]})}),X=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[H,Y]}),te=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(P,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(P,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),"Navigate"]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(P,{name:"corner-down-left",className:"h-3.5 w-3.5"}),"Open folder"]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:xe}),s.jsx(P,{name:"corner-down-left",className:"h-3.5 w-3.5"}),"Add folder"]})]}),ue=s.jsx(Ne,{size:r?"xs":"default",onClick:()=>{V(w)},disabled:!G,className:_(r&&"w-full flex-1"),children:B}),he=()=>s.jsxs(s.Fragment,{children:[r?null:te,s.jsx("div",{className:_("flex w-full flex-row justify-end gap-2 sm:w-auto",r&&"justify-stretch"),children:ue})]});return r?s.jsx(Ma,{open:e,onClose:c,title:"Add folder",className:"h-[88dvh] max-h-[720px]",contentMaxHeightClassName:"flex-1",footer:s.jsx("div",{className:"flex flex-col gap-2",children:he()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:Re}),X]})}):s.jsx(ns,{open:e,onOpenChange:t,children:s.jsxs(rs,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(vs,{className:"px-5 pb-2 pt-5",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx(us,{children:"Add folder"}),s.jsx(Ss,{className:"mt-2",children:"Choose a folder from the path above, then add it."})]}),Re]})}),s.jsx("div",{className:"min-h-0 flex-1 px-5 pb-0",children:X}),s.jsx(Ts,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:he()})]})})},Gn=e=>e?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:e}):void 0,fx=()=>{const[e,t]=a.useState(!1),[n,r]=a.useState(null),[o,i]=a.useState(!1),l=Te(k=>k.deleteSession),c=Te(k=>k.deleteSessions),d=le(k=>k.showDeletionDialog),u=le(k=>k.setShowDeletionDialog),{isMobile:f,isTablet:p,hasTouchInput:x}=an(),y=f||p||x;a.useEffect(()=>Wu(()=>{t(!1)}),[]);const m=a.useCallback(k=>{r({sessions:k.sessions,dateLabel:k.dateLabel})},[]),h=a.useCallback(()=>{r(null),i(!1)},[]),b=a.useCallback(async k=>{if(k.sessions.length===0)return;if(k.sessions.length===1){const T=k.sessions[0];await l(T.id)?ie.success("Session deleted"):ie.error("Failed to delete session");return}const C=k.sessions.map(T=>T.id),{deletedIds:w,failedIds:N}=await c(C);if(w.length>0){const T=N.length>0?N.length===1?`${N.length} session could not be deleted.`:`${N.length} sessions could not be deleted.`:k.dateLabel?`Removed all sessions from ${k.dateLabel}.`:void 0;ie.success(w.length===1?"Deleted {count} session":`Deleted ${w.length} sessions`,{description:Gn(T)})}N.length>0&&ie.error(N.length===1?`Failed to delete ${N.length} session`:`Failed to delete ${N.length} sessions`,{description:Gn("Please try again in a moment.")})},[l,c]);a.useEffect(()=>Ds.onDeleteRequest(k=>{if(!d){b(k);return}m(k)}),[m,d,b]),a.useEffect(()=>Ds.onDirectoryRequest(()=>{t(!0)}),[]);const g=a.useCallback(async()=>{if(n){i(!0);try{if(n.sessions.length===1){const k=n.sessions[0];if(!await l(k.id)){ie.error("Failed to delete session"),i(!1);return}ie.success("Session deleted",{action:{label:"OK",onClick:()=>{}}})}else{const k=n.sessions.map(T=>T.id),C=await c(k),w=C.deletedIds,N=C.failedIds;if(w.length>0){const T=N.length>0?N.length===1?`${N.length} session could not be deleted.`:`${N.length} sessions could not be deleted.`:n.dateLabel?`Removed all sessions from ${n.dateLabel}.`:void 0;ie.success(w.length===1?"Deleted {count} session":`Deleted ${w.length} sessions`,{description:Gn(T),action:{label:"OK",onClick:()=>{}}})}if(N.length>0&&(ie.error(N.length===1?`Failed to delete ${N.length} session`:`Failed to delete ${N.length} sessions`,{description:Gn("Please try again in a moment.")}),w.length===0)){i(!1);return}}h()}finally{i(!1)}}},[n,l,c,h]),S=n?n.sessions.length===1?n.dateLabel?`This action permanently removes 1 session from ${n.dateLabel}.`:"This action permanently removes 1 session.":n.dateLabel?`This action permanently removes ${n.sessions.length} sessions from ${n.dateLabel}.`:`This action permanently removes ${n.sessions.length} sessions.`:"",v=n?s.jsxs("div",{className:"space-y-2",children:[n.sessions.length>0&&s.jsx("div",{className:"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsxs("ul",{className:"space-y-0.5",children:[n.sessions.slice(0,5).map(k=>s.jsx("li",{className:"typography-micro text-muted-foreground/80",children:s.jsx("span",{className:"truncate",children:bs(k)})},k.id)),n.sessions.length>5&&s.jsx("li",{className:"typography-micro text-muted-foreground/70",children:`+${n.sessions.length-5} more`})]})}),s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:"Worktree directories stay intact. Subsessions linked to the selected sessions will also be removed."})})]}):null,E=s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>u(!d),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":!d,children:[d?s.jsx(P,{name:"checkbox-blank",className:"size-4"}):s.jsx(P,{name:"checkbox",className:"size-4 text-primary"}),"Never ask"]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ne,{variant:"ghost",onClick:h,disabled:o,children:"Cancel"}),s.jsx(Ne,{variant:"destructive",onClick:g,disabled:o,children:o?"Deleting…":n?.sessions.length===1?"Delete session":"Delete sessions"})]})]}),j=n?.sessions.length===1?"Delete session":"Delete sessions";return s.jsxs(s.Fragment,{children:[y?s.jsx(Ma,{open:!!n,onClose:()=>{o||h()},title:j,footer:s.jsx("div",{className:"flex justify-end gap-2",children:E}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[S&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:S}),v]})}):s.jsx(ns,{open:!!n,onOpenChange:k=>{if(!k){if(o)return;h()}},children:s.jsxs(rs,{className:"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2",children:[s.jsxs(vs,{children:[s.jsx(us,{children:j}),S&&s.jsx(Ss,{children:S})]}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-2",children:v}),s.jsx(Ts,{className:"mt-2 gap-2 pt-1 pb-1",children:E})]})}),s.jsx(Uf,{open:e,onOpenChange:t})]})},hx=()=>{const e=Ps(t=>t.entries);return a.useEffect(()=>{for(const t of e.values())!_d(t)||!t.receipt||(Ps.getState().markNotificationSent(t.key),ie.success("Worktree ready",{id:`worktree-ready:${t.key}`,description:t.receipt.branch||t.receipt.path}))},[e]),null},$f=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"general",title:"General",group:"general",kind:"single",keywords:["general","startup","launch at login","autostart","tray","password","passkey","security","privacy","telemetry","transport","network","lan","binary","cli","diagnostics","performance"]},{slug:"projects",title:"Projects",group:"projects",kind:"single",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"single",keywords:["ssh","remote","instances","tunnels","forwarding","connection"]},{slug:"providers",title:"Providers",group:"agent",kind:"single",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"behavior",title:"Behavior",group:"agent",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"skills.installed",title:"Skills",group:"agent",kind:"single",keywords:["skill","skills","instructions","install","catalog"]},{slug:"git",title:"Git",group:"projects",kind:"single",keywords:["git","github","ssh","commit","oauth","prs","issues"]},{slug:"appearance",title:"Appearance",group:"general",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"dictation",title:"Dictation",group:"general",kind:"single",description:"Record speech and insert a final transcript into the composer.",keywords:["voice","speech","microphone","transcription","stt","whisper","parakeet"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"]},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"snippets",title:"Snippets",group:"agent",kind:"single",keywords:["snippet","snippets","text expansion"]},{slug:"prompt-templates",title:"Prompt templates",group:"agent",kind:"single",keywords:["prompt template","prompt templates","slash command","slash commands"]},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"tunnel",title:"External Tunnel",group:"projects",kind:"single",keywords:["tunnel","external","cloudflare","qr","remote","mobile","share"],isAvailable:()=>!1},{slug:"about",title:"About",group:"general",kind:"single",keywords:["about","version","updates","release","changelog","pi","pichamber","open source"]}],Kf={sessions:"sessions",skills:"skills.installed",providers:"providers","git-identities":"git",settings:"home"};function Wf(e){const t=e.trim().toLowerCase();return $f.find(n=>n.slug===t)??null}function Gf(e){const t=(e??"").trim().toLowerCase();if(!t)return"home";const n=Kf[t];if(n)return n;const r=Wf(t);return r?r.slug:"home"}function mx(e){switch(e){case"general":return"equalizer";case"projects":return"folders";case"remote-instances":return"server";case"appearance":return"brush";case"chat":return"chat-1";case"dictation":return"voiceprint";case"snippets":return"sticky-note";case"prompt-templates":return"terminal-box";case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"history";case"providers":return"cloud";case"behavior":return"brain";case"skills.installed":return"puzzle";case"git":return"git-repository";case"tunnel":return"global";case"about":return"pichamber";case"home":return null;default:return"robot-2"}}function px(){const e=a.useRef(!1),t=a.useRef(!1),n=Te(f=>f.setCurrentSession),r=le(f=>f.setActiveMainTab),o=le(f=>f.setSettingsDialogOpen),i=le(f=>f.setSettingsPage),l=le(f=>f.navigateToDiff),c=a.useCallback(async f=>{if(!t.current){t.current=!0;try{if(f.sessionId){const p=Te.getState().currentSessionId,x=Ys().getState().selectedSessionId;if(f.sessionId!==p||f.sessionId!==x){const y=Te.getState().getDirectoryForSession(f.sessionId);n(f.sessionId,y)}}if(f.settingsPath){i(Gf(f.settingsPath)),o(!0);return}le.getState().isSettingsDialogOpen&&o(!1),f.tab&&r(f.tab),f.diffFile&&(f.tab==="diff"||!f.tab)&&l(f.diffFile)}finally{t.current=!1}}},[n,r,o,i,l]),d=a.useCallback(()=>{const f=Te.getState(),p=Ys().getState(),x=le.getState();return{sessionId:Or({currentSessionId:f.currentSessionId,piSelectedSessionId:p.selectedSessionId,draft:f.newSessionDraft}),tab:x.activeMainTab,isSettingsOpen:x.isSettingsDialogOpen,settingsPath:x.settingsPage,diffFile:x.pendingDiffFile}},[]),u=a.useCallback((f={})=>{if(t.current)return;const p=d();bo(p,f)},[d]);a.useEffect(()=>{if(e.current||(e.current=!0,!wi()))return;const f=vi();(async()=>(await c(f),bo({...d(),sessionId:f.sessionId??Or({currentSessionId:Te.getState().currentSessionId,piSelectedSessionId:Ys().getState().selectedSessionId,draft:Te.getState().newSessionDraft}),tab:f.tab??le.getState().activeMainTab,settingsPath:f.settingsPath??le.getState().settingsPage,diffFile:f.diffFile??le.getState().pendingDiffFile},{replace:!0,force:!0})))()},[c,d]),a.useEffect(()=>{const f=()=>{const b=Te.getState(),g=Ys().getState();return Or({currentSessionId:b.currentSessionId,piSelectedSessionId:g.selectedSessionId,draft:b.newSessionDraft})};let p=f(),x=Te.getState().newSessionDraft?.open===!0;const y=()=>{const b=Te.getState(),g=f(),S=b.newSessionDraft?.open===!0;g===p&&S===x||t.current||(p=g,x=S,u({replace:!0}))},m=Te.subscribe(()=>{y()}),h=Ys().subscribe(()=>{y()});return()=>{m(),h()}},[u]),a.useEffect(()=>{let f=le.getState().activeMainTab,p=le.getState().isSettingsDialogOpen,x=le.getState().settingsPage,y=le.getState().pendingDiffFile;return le.subscribe(h=>{if(t.current)return;const b=h.activeMainTab!==f,g=h.isSettingsDialogOpen!==p,S=h.settingsPage!==x,v=h.pendingDiffFile!==y&&h.activeMainTab==="diff";f=h.activeMainTab,p=h.isSettingsDialogOpen,x=h.settingsPage,y=h.pendingDiffFile,(b||g||S||v)&&u()})},[u]),a.useEffect(()=>{if(typeof window>"u")return;const f=()=>{const p=vi();if(wi())c(p);else{const x=le.getState();x.isSettingsDialogOpen&&o(!1),x.activeMainTab!=="chat"&&r("chat")}};return window.addEventListener("popstate",f),()=>{window.removeEventListener("popstate",f)}},[c,r,o])}function Hf(e=!0){const t=er(r=>r.checkForUpdates),n=a.useRef(t);a.useEffect(()=>{n.current=t},[t]),a.useEffect(()=>{if(!e)return;const r=3e3,o=3600*1e3,i=300*1e3,l=1440*60*1e3;let c=!1,d=null;const u=p=>{const x=Math.round(p*1e3);return Math.max(i,Math.min(l,x))},f=p=>{c||(d=window.setTimeout(async()=>{const x=await n.current(),y=typeof x=="number"&&Number.isFinite(x)?u(x):o;f(y)},p))};return f(r),()=>{c=!0,d!==null&&window.clearTimeout(d)}},[e])}function gx(){const e=An(t=>t.connection==="ready",void 0,"chrome");return Hf(e),null}const Pi=12,qf=[{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"}],Yf=({isActive:e,burstKey:t=0,className:n,durationMs:r=900,bursts:o=qf,onComplete:i})=>{const l=Ee.useRef(!1);Ee.useEffect(()=>{!e&&l.current&&i?.(),e&&(l.current=!0)},[e,i]);const c=Ee.useMemo(()=>Array.from({length:Pi},(d,u)=>{const f=Math.PI*2*u/Pi;return{x:Math.cos(f),y:Math.sin(f),delay:u*18}}),[]);return e?s.jsx("div",{className:_("fireworks-overlay pointer-events-none",n),"aria-hidden":"true","data-burst-key":t,children:o.map(d=>{const u={"--burst-delay":`${d.delay}ms`,"--burst-x":`${d.x}%`,"--burst-y":`${d.y}%`,"--firework-color":`var(${d.colorVar})`,"--firework-duration":`${r}ms`};return s.jsx("div",{className:"firework-burst",style:u,children:c.map((f,p)=>{const x=f.x*d.radius,y=f.y*d.radius,m={"--translate-x":`${x}px`,"--translate-y":`${y}px`,"--particle-delay":`${f.delay}ms`,color:`var(${d.colorVar})`};return s.jsx("span",{className:"firework-particle",style:m},`${d.id}-${p}-${t}`)})},`${d.id}-${t}`)})}):null},Vf=({durationMs:e=3400}={})=>{const[t,n]=Ee.useState({isActive:!1,cycle:0}),r=Ee.useRef(null),o=Ee.useCallback(()=>{r.current&&(window.clearTimeout(r.current),r.current=null)},[]),i=Ee.useCallback(()=>{o(),n(c=>c.isActive?{...c,isActive:!1}:c)},[o]),l=Ee.useCallback(()=>{o(),n(c=>({isActive:!0,cycle:c.cycle+1})),r.current=window.setTimeout(()=>{n(c=>c.isActive?{...c,isActive:!1}:c),r.current=null},e)},[o,e]);return Ee.useEffect(()=>()=>o(),[o]),{isActive:t.isActive,burstKey:t.cycle,triggerFireworks:l,dismissFireworks:i}},pl=a.createContext(void 0),bx=({children:e})=>{const{isActive:t,burstKey:n,triggerFireworks:r,dismissFireworks:o}=Vf(),i=a.useMemo(()=>({triggerFireworks:r,dismissFireworks:o}),[r,o]);return s.jsxs(pl.Provider,{value:i,children:[e,s.jsx(Yf,{isActive:t,burstKey:n})]})},Qf={triggerFireworks:()=>{},dismissFireworks:()=>{}},xx=()=>a.useContext(pl)??Qf,ur=2e3,gl=600*1e3;async function Jf(){try{const e=await Tt("/api/pi/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});if(!e.ok){const n=await e.json().catch(()=>({}));return{success:!1,error:n.error||`Server error: ${e.status}`,commands:Array.isArray(n.commands)?n.commands.filter(r=>typeof r=="string"):void 0}}const t=await e.json().catch(()=>({}));return{success:!0,autoRestart:t.autoRestart!==!1,jobId:typeof t.jobId=="string"?t.jobId:void 0,channel:t.channel==="rc"?"rc":t.channel==="stable"?"stable":void 0,targetVersion:typeof t.targetVersion=="string"?t.targetVersion:void 0}}catch(e){return{success:!1,error:e instanceof Error?e.message:void 0}}}async function Xf(e,t=Math.ceil(gl/ur),n=ur,r=Qe()){for(let o=0;o<t;o++){if(Qe()!==r)return{applied:!1,stale:!0};try{const i=await Tt("/api/pi/update-check",{method:"GET",headers:{Accept:"application/json"}});if(Qe()!==r)return{applied:!1,stale:!0};if(i.ok){const l=await i.json().catch(()=>null);if(Qe()!==r)return{applied:!1,stale:!0};if(typeof l?.error=="string"&&l.error.length>0)return{applied:!1,error:l.error};if(l&&l.available===!1)return{applied:!0};if(l&&typeof l.currentVersion=="string"&&typeof e=="string"&&l.currentVersion!==e)return{applied:!0}}else if(i.status===401||i.status===403)return{applied:!1,error:"Authentication was lost while following the update. Reauthenticate to check its status."}}catch{if(Qe()!==r)return{applied:!1,stale:!0}}await new Promise(i=>setTimeout(i,n))}return{applied:!1}}async function Zf(e,t,n=Math.ceil(gl/ur),r=ur,o=Qe()){for(let i=0;i<n;i++){if(Qe()!==o)return{applied:!1,stale:!0};try{const l=await Tt(`/api/pi/update-install/${encodeURIComponent(e)}`,{method:"GET",headers:{Accept:"application/json"}});if(Qe()!==o)return{applied:!1,stale:!0};if(l.ok){const c=await l.json().catch(()=>null);if(Qe()!==o)return{applied:!1,stale:!0};if(c?.state==="complete")return{applied:!0};if(c?.state==="failed")return{applied:!1,error:c.error||"Update failed"};c?.state==="restarting"?t("restarting"):(c?.state==="queued"||c?.state==="installing"||c?.state==="verifying")&&t("updating")}else{if(l.status===401||l.status===403)return{applied:!1,error:"Authentication was lost while following the update. Reauthenticate to check its status."};if(l.status===404)return{applied:!1,error:"The server lost the update status. Check the installed version or run: pichamber update"};if(l.status===503){const c=await l.json().catch(()=>null);if(Qe()!==o)return{applied:!1,stale:!0};if(c?.error==="Update status is unavailable")return{applied:!1,error:c.error};t("reconnecting")}else t("reconnecting")}}catch{if(Qe()!==o)return{applied:!1,stale:!0};t("reconnecting")}await new Promise(l=>setTimeout(l,r))}return{applied:!1}}const Mi="https://github.com/RyderAsKing/PiChamber/releases";function eh(e){const t=new Date(`${e}T00:00:00`);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric"}).format(t)}function th(e){return e.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Ti(e){return e.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function sh(e,t){const n=u=>{const f=u.indexOf("-");return f<0?[u,""]:[u.slice(0,f),u.slice(f+1)]},[r,o]=n(e),[i,l]=n(t),c=r.split(".").map(u=>Number.parseInt(u,10)),d=i.split(".").map(u=>Number.parseInt(u,10));for(let u=0;u<3;u+=1){const f=Number.isFinite(c[u])?c[u]:0,p=Number.isFinite(d[u])?d[u]:0;if(f!==p)return p-f}return!o||!l?(o?1:0)-(l?1:0):l.localeCompare(o,void 0,{numeric:!0})}function nh(e){const t=/^## \[(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let r;for(;(r=t.exec(e))!==null;)n.push({version:r[1]??"",date:r[2]??"",start:r.index});return n.length===0?[]:n.map((o,i)=>{const l=n[i+1]?.start??e.length,c=e.slice(o.start,l).trim();return{version:o.version,date:o.date,start:o.start,end:l,raw:c}})}const bl=({open:e,onOpenChange:t,info:n,downloading:r,downloaded:o,progress:i,error:l,onDownload:c,onRestart:d,runtimeType:u="desktop"})=>{const[f,p]=Ee.useState(null),[x,y]=Ee.useState("idle"),[m,h]=Ee.useState(null),[b,g]=Ee.useState(null),[S,v]=Ee.useState({}),E=n?.version?n.releaseUrl||`${Mi}/tag/v${n.version}`:Mi,j=n?.downloadUrl||E,k=i?.total?Math.round(i.downloaded/i.total*100):0,C=u==="web",w=u==="mobile",N=n?.updateCommand||"pichamber update",T=S.version||n?.version,O=S.channel||n?.channel;Ee.useEffect(()=>{e||(y("idle"),h(null),g(null),v({}))},[e]);const $=async(I=N)=>{(await ys(I)).ok&&(p(I),setTimeout(()=>p(null),2e3))},U=Ee.useCallback(async I=>{await Ta(I)},[]),K=Ee.useCallback(async()=>{const I=Qe();y("updating"),h(null),g(null),v({});const M=await Jf();if(Qe()!==I)return;if(!M.success){y("error"),h(M.error||"Update failed"),g(M.commands??null);return}if(v({version:M.targetVersion,channel:M.channel}),M.jobId){const G=await Zf(M.jobId,B=>{Qe()===I&&y(B)},void 0,void 0,I);if(G.stale||Qe()!==I)return;if(G.applied){window.location.reload();return}y("error"),h(G.error||"Update is taking longer than expected. Wait a bit and refresh, or run: pichamber update");return}y(M.autoRestart?"restarting":"reconnecting");const W=await Xf(n?.currentVersion,void 0,void 0,I);if(!(W.stale||Qe()!==I)){if(W.applied){window.location.reload();return}y("error"),h(W.error||"Update is taking longer than expected. Wait a bit and refresh, or run: pichamber update")}},[n?.currentVersion]),L=Ee.useCallback(()=>{U(j)},[U,j]),D=x!=="idle"&&x!=="error",R=Ee.useMemo(()=>{if(!n?.body)return null;const I=n.body.trim();if(!I)return null;const M=nh(I);return M.length===0?{kind:"raw",title:"What's new",content:Ti(I)}:{kind:"sections",title:"What's new",sections:[...M].sort((G,B)=>sh(G.version,B.version)).map(G=>({version:G.version,dateLabel:eh(G.date),content:Ti(th(G.raw)||I)}))}},[n?.body]);return s.jsx(ns,{open:e,onOpenChange:D?void 0:t,children:s.jsxs(rs,{className:"max-w-4xl p-4 sm:p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[s.jsxs("div",{className:"mb-1 space-y-1 pr-8",children:[s.jsxs(us,{className:"flex items-center gap-2.5",children:[s.jsx(P,{name:"download-cloud",className:"h-5 w-5 shrink-0 text-[var(--primary-base)]"}),s.jsx("span",{className:"text-lg font-semibold text-foreground",children:x==="restarting"||x==="reconnecting"?"Updating PiChamber...":"Update available"})]}),(n?.currentVersion||T||C&&O)&&s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 pl-[1.875rem]",children:[(n?.currentVersion||T)&&s.jsxs("div",{className:"flex items-center gap-2 whitespace-nowrap font-mono text-sm",children:[n?.currentVersion&&s.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&T&&s.jsx("span",{className:"text-muted-foreground/50","aria-hidden":"true",children:"→"}),T&&s.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:T})]}),C&&O&&s.jsx("span",{className:"whitespace-nowrap typography-meta text-muted-foreground",children:O==="rc"?"RC channel":"Stable channel"})]})]}),s.jsxs("div",{className:"space-y-2",children:[C&&D&&s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(P,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),s.jsxs("div",{className:"typography-ui-label text-foreground",children:[x==="updating"&&"Installing update...",x==="restarting"&&"Server restarting...",x==="reconnecting"&&"Waiting for server..."]})]}),s.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"The page will reload automatically when the update is complete."})]}),R&&!D&&s.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:s.jsx(As,{className:"max-h-[min(400px,50dvh)] p-0",fillContainer:!1,children:R.kind==="raw"?s.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:I=>{const W=I.target.closest("a");W&&W.href&&(I.preventDefault(),I.stopPropagation(),U(W.href))},children:s.jsx(Si,{content:R.content,disableLinkSafety:!0,enableFileReferences:!1})}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:R.sections.map(I=>s.jsxs("div",{className:"p-4",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[s.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",I.version]}),s.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:I.dateLabel})]}),s.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:M=>{const G=M.target.closest("a");G&&G.href&&(M.preventDefault(),M.stopPropagation(),U(G.href))},children:s.jsx(Si,{content:I.content,disableLinkSafety:!0,enableFileReferences:!1})})]},I.version))})})}),(l||m)&&s.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:s.jsx("p",{className:"text-sm text-[var(--status-error)]",children:l||m})}),C&&x==="error"&&(b??[N]).length>0&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(P,{name:"terminal",className:"h-4 w-4"}),s.jsx("span",{children:b?"Run these commands:":"Or update via terminal:"})]}),(b??[N]).map(I=>s.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[s.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:I}),s.jsx(Ne,{variant:"ghost",size:"icon",onClick:()=>{$(I)},className:f===I?"text-[var(--status-success)]":void 0,title:f===I?"Copied!":"Copy command","aria-label":f===I?"Copied!":"Copy command",children:f===I?s.jsx(P,{name:"check",className:"h-4 w-4"}):s.jsx(P,{name:"clipboard",className:"h-4 w-4"})})]},I))]}),!C&&!w&&r&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center justify-between text-sm",children:[s.jsx("span",{className:"text-muted-foreground",children:"Downloading update payload..."}),s.jsxs("span",{className:"font-mono text-foreground",children:[k,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${k}%`}})})]})]}),s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-x-4 gap-y-2",children:[s.jsxs("a",{href:E,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[s.jsx(P,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),s.jsxs("div",{className:"flex-1 flex justify-end",children:[!C&&!w&&!o&&!r&&s.jsxs(Ne,{onClick:c,children:[s.jsx(P,{name:"download",className:"h-4 w-4"}),"Download update"]}),!C&&!w&&r&&s.jsxs(Ne,{disabled:!0,children:[s.jsx(P,{name:"loader",className:"h-4 w-4 animate-spin"}),"Downloading..."]}),!C&&!w&&o&&s.jsxs("button",{onClick:d,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[s.jsx(P,{name:"restart",className:"h-4 w-4"}),"Restart to Update"]}),w&&s.jsxs(Ne,{onClick:L,size:"default",children:[s.jsx(P,{name:"external-link",className:"h-4 w-4"}),"Open update"]}),C&&!D&&s.jsxs(Ne,{onClick:K,children:[s.jsx(P,{name:"download",className:"h-4 w-4"}),"Update now"]}),C&&D&&s.jsxs(Ne,{disabled:!0,children:[s.jsx(P,{name:"loader",className:"h-4 w-4 animate-spin"}),"Updating..."]})]})]})]})})},xl=a.memo(function({checked:t,onChange:n,disabled:r=!1,ariaLabel:o,decorative:i=!1,className:l,iconClassName:c}){const d=a.useCallback(x=>{x.preventDefault(),x.stopPropagation(),!r&&!t&&n()},[t,r,n]),u=a.useCallback(x=>{(x.key===" "||x.key==="Enter")&&(x.preventDefault(),!r&&!t&&n())},[t,r,n]),f=s.jsx("span",{"aria-hidden":!0,className:_("block h-[5px] w-[5px] rounded-full bg-white",!t&&"opacity-0",c)}),p=_("relative flex h-[14px] w-[14px] min-h-[14px] min-w-[14px] shrink-0 self-center items-center justify-center rounded-full","transition-[background-color,box-shadow] duration-200 ease-out",t?"bg-[color-mix(in_srgb,var(--primary-base)_80%,transparent)] shadow-none":"bg-[var(--surface-muted)] shadow-[inset_0_0_0_1px_var(--interactive-border)]");return i?s.jsx("span",{"aria-hidden":!0,className:_(p,r&&"opacity-50",l),children:f}):s.jsx("button",{type:"button",role:"radio",onClick:d,onKeyDown:u,disabled:r,"aria-checked":t,"aria-label":o,className:_("group/radio outline-none",p,t?"hover:bg-[var(--primary-base)]":"hover:bg-[var(--interactive-hover)]","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background","disabled:cursor-not-allowed disabled:opacity-50",l),children:f})}),Bn=({children:e,className:t,contentClassName:n})=>{const[r,o]=a.useState(!1),i=a.useRef(null);return a.useEffect(()=>{if(!r)return;const l=c=>{const d=i.current;d&&c.target instanceof Node&&d.contains(c.target)||o(!1)};return document.addEventListener("pointerdown",l,!0),()=>document.removeEventListener("pointerdown",l,!0)},[r]),s.jsxs(Ue,{open:r,onOpenChange:o,children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{ref:i,type:"button","aria-label":"More information","aria-expanded":r,onClick:l=>{l.preventDefault(),l.stopPropagation(),o(c=>!c)},className:_("inline-flex h-5 w-5 shrink-0 cursor-help items-center justify-center rounded text-muted-foreground/60 hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",t),children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(Ke,{sideOffset:8,className:_("max-w-sm",n),children:e})]})},yx="w-full min-w-40 max-w-48",wx="settings",rh="w-full min-w-40 max-w-48",vx="h-8 w-8 px-0 text-muted-foreground hover:text-foreground",oh="w-full max-w-[24rem]",Sx="min-w-0 flex-1",jx="flex w-full min-w-0 items-center gap-2",Cx="typography-meta shrink-0 text-muted-foreground tabular-nums",yl="space-y-3.5",ih="space-y-1.5",kx="typography-settings-page-title text-muted-foreground",ah="typography-settings-section-title text-foreground",wl="typography-settings-group-title text-foreground",Ho="typography-settings-field-label text-foreground",lh="typography-settings-description text-muted-foreground",_n="typography-meta text-muted-foreground",Ax="typography-meta font-medium text-foreground",Nx="typography-settings-section-title text-foreground",ch=({title:e,description:t,titleAccessory:n,info:r,headerAction:o,children:i,divider:l=!0,className:c,contentClassName:d,settingsItem:u})=>{const f=e!=null||t!=null||o!=null||r!=null;return s.jsxs("section",{"data-settings-item":u,className:_("space-y-4",l?"border-t border-border/60 py-6":"pb-6",c),children:[f?s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[e!=null?s.jsxs("div",{className:"flex items-center gap-2",children:[typeof e=="string"||typeof e=="number"?s.jsx("h2",{className:ah,children:e}):e,n,r!=null?s.jsx(Bn,{children:r}):null]}):null,t!=null?s.jsx("div",{className:lh,children:t}):null]}),o?s.jsx("div",{className:"shrink-0",children:o}):null]}):null,s.jsx("div",{className:_(d),children:i})]})},Ix=({children:e,className:t})=>s.jsx("div",{className:_("grid grid-cols-1 gap-6 @3xl:grid-cols-2 @3xl:gap-10",t),children:e}),dh=({children:e,className:t,as:n="h3"})=>s.jsx(n,{className:_(wl,t),children:e}),Ex=({title:e,description:t,info:n,children:r,className:o,contentClassName:i,settingsItem:l})=>s.jsxs("div",{"data-settings-item":l,className:_("space-y-2",o),children:[e!=null||t!=null||n!=null?s.jsxs("div",{className:"space-y-0.5",children:[e!=null?s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(dh,{children:e}),n!=null?s.jsx(Bn,{children:n}):null]}):null,t!=null?s.jsx("p",{className:_n,children:t}):null]}):null,s.jsx("div",{className:_(i),children:r})]}),En=({label:e,description:t,info:n,descriptionPlacement:r="before",children:o,settingsItem:i,className:l,controlClassName:c})=>{const d=t!=null?s.jsx("p",{className:_n,children:t}):null;return s.jsxs("div",{"data-settings-item":i,className:_("space-y-2",l),children:[s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:Ho,children:e}),n!=null?s.jsx(Bn,{children:n}):null]}),r==="before"?d:null]}),s.jsx("div",{className:_("flex min-w-0 max-w-[24rem] items-center gap-2",c),children:o}),r==="after"?d:null]})},Rx=({label:e,description:t,info:n,children:r,settingsItem:o,className:i,labelClassName:l,controlClassName:c,alignEnd:d=!0})=>s.jsxs("div",{"data-settings-item":o,className:_("flex flex-col gap-2 py-0.5 @xl:flex-row @xl:items-center @xl:gap-8",i),children:[s.jsxs("div",{className:_("min-w-0 @xl:w-56 @xl:shrink-0",l),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:Ho,children:e}),n!=null?s.jsx(Bn,{children:n}):null]}),t!=null?s.jsx("p",{className:_(_n,"mt-0.5"),children:t}):null]}),s.jsx("div",{className:_("flex min-w-0 flex-1 items-center gap-2 @xl:w-fit @xl:flex-none",d&&"@xl:justify-end",c),children:r})]}),Dx=({children:e,className:t,settingsItem:n})=>s.jsx("div",{"data-settings-item":n,className:_("pt-4",t),children:e}),Px=({label:e,children:t,divider:n=!0,className:r,contentClassName:o})=>s.jsxs("details",{className:_("group/disclosure",n?"border-t border-border/60 py-6":"pb-6",r),children:[s.jsxs("summary",{className:"flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-md typography-ui-label text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] [&::-webkit-details-marker]:hidden",children:[s.jsx(P,{name:"arrow-right-s",className:"size-4 transition-transform group-open/disclosure:rotate-90"}),e]}),s.jsx("div",{className:_("pt-4",o),children:t})]}),uh=({checked:e,onChange:t,label:n,description:r,disabled:o=!1,ariaLabel:i,settingsItem:l,className:c,labelAccessory:d,info:u})=>{const f=()=>{o||t(!e)},p=r!=null;return s.jsxs("div",{"data-settings-item":l,className:_("group flex cursor-pointer gap-2 py-0.5",p?"items-start":"items-center",o&&"cursor-not-allowed opacity-60",c),role:"button",tabIndex:o?-1:0,"aria-pressed":e,"aria-disabled":o||void 0,onClick:f,onKeyDown:x=>{(x.key===" "||x.key==="Enter")&&(x.preventDefault(),f())},children:[s.jsx(oo,{checked:e,onChange:t,disabled:o,ariaLabel:i}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:Ho,children:n}),d,u!=null?s.jsx(Bn,{children:u}):null]}),p?s.jsx("span",{className:_n,children:r}):null]})]})},Mx=({selected:e,onSelect:t,label:n,description:r,ariaLabel:o,disabled:i=!1,className:l})=>s.jsxs("div",{className:_("flex cursor-pointer gap-2 py-0.5",r!=null?"items-start":"items-center",i&&"cursor-not-allowed opacity-60",l),role:"button",tabIndex:i?-1:0,"aria-pressed":e,"aria-disabled":i||void 0,onClick:()=>{i||t()},onKeyDown:c=>{(c.key===" "||c.key==="Enter")&&(c.preventDefault(),i||t())},children:[s.jsx(xl,{checked:e,onChange:t,disabled:i,ariaLabel:o,className:r!=null?"mt-0.5":void 0}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:_("typography-settings-field-label font-normal",e?"text-foreground":"text-foreground/50"),children:n}),r!=null?s.jsx("span",{className:_n,children:r}):null]})]}),Tx=({selected:e,onSelect:t,label:n,preview:r,ariaLabel:o,disabled:i=!1,className:l})=>s.jsxs("div",{className:_("group/preview flex min-w-0 cursor-pointer flex-col gap-2",i&&"cursor-not-allowed opacity-60",l),role:"radio",tabIndex:i?-1:0,"aria-checked":e,"aria-label":o,"aria-disabled":i||void 0,onClick:()=>{i||t()},onKeyDown:c=>{(c.key===" "||c.key==="Enter")&&(c.preventDefault(),i||t())},children:[s.jsx("div",{"aria-hidden":!0,className:_("aspect-[4/3] overflow-hidden rounded-lg border transition-colors",e?"border-[var(--primary-base)] ring-1 ring-[var(--primary-base)]":"border-border group-hover/preview:border-foreground/30"),children:r}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(xl,{checked:e,onChange:t,disabled:i,decorative:!0}),s.jsx("span",{className:_("min-w-0 truncate typography-settings-field-label font-normal",e?"text-foreground":"text-foreground/50"),children:n})]})]}),Fx=({"aria-label":e,children:t,className:n})=>s.jsx("div",{role:"radiogroup","aria-label":e,className:_(ih,n),children:t});function Lx({value:e,options:t,onChange:n,className:r,"aria-label":o}){return s.jsx("div",{role:"group","aria-label":o,className:_("flex flex-wrap items-center gap-1",r),children:t.map(i=>s.jsx(Ne,{type:"button",variant:"chip",size:"xs",disabled:i.disabled,"aria-pressed":e===i.value,className:"!font-normal",onClick:()=>n(i.value),children:i.label},i.value))})}const vo="pichamber:server-update-channel-changed",Ox=()=>{typeof window<"u"&&window.dispatchEvent(new Event(vo))},fh=e=>typeof window>"u"?()=>{}:(window.addEventListener(vo,e),()=>window.removeEventListener(vo,e));class hh extends a.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){this.setState({error:t,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(zd,{className:"w-full max-w-md",children:[s.jsx(Ud,{className:"text-center",children:s.jsxs($d,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(P,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Kd,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(Ne,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(P,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function mh(e){return s.jsx(hh,{...e,texts:{title:"Chat Error",description:"The chat interface encountered an error. This might be due to a temporary network issue or corrupted message data.",sessionLabel:"Session",detailsSummary:"Error details",resetAction:"Reset Chat",persistentHint:"If the problem persists, try refreshing the page."}})}const Bx=({active:e=!0})=>{const t=Te(n=>n.currentSessionId);return s.jsx(mh,{sessionId:t||void 0,children:s.jsx(Wd,{active:e},t??"no-session")})};function ph({onResizeStart:e,ariaLabel:t}){return s.jsx("div",{role:"separator","aria-orientation":"horizontal","aria-label":t,onPointerDown:e,className:"pointer-events-auto -m-2 flex size-7 cursor-ns-resize items-end justify-end p-2 touch-none select-none",children:s.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,children:s.jsx("path",{d:"M9.11111 2L2 9.11111M10 6.44444L6.44444 10",className:"stroke-muted-foreground",strokeLinecap:"round"})})})}const vl=Ee.forwardRef(({className:e,outerClassName:t,scrollbarClassName:n,fillContainer:r=!1,useScrollShadow:o=!1,scrollShadowSize:i,hasError:l,resizedHeight:c,onResizeHeightChange:d,disabled:u,simple:f,endSlot:p,...x},y)=>{const m=Ee.useRef(null),h=Ee.useRef(null),[b,g]=Ee.useState(null),S=c??b,v=Ee.useCallback(j=>{const k=m.current;if(!k)return;h.current={startY:j.clientY,startHeight:k.getBoundingClientRect().height};const C=j.currentTarget;C.setPointerCapture(j.pointerId);const w=T=>{const O=h.current;if(!O)return;const $=O.startHeight+(T.clientY-O.startY),U=Math.max(82,$);d?d(U):g(U)},N=()=>{h.current=null,C.removeEventListener("pointermove",w),C.removeEventListener("pointerup",N),C.removeEventListener("pointercancel",N)};C.addEventListener("pointermove",w),C.addEventListener("pointerup",N),C.addEventListener("pointercancel",N),j.preventDefault()},[d]),E=Ee.useCallback(j=>{if(j.target.closest('textarea, button, [role="separator"]'))return;const C=m.current?.querySelector("textarea");C&&document.activeElement!==C&&(j.preventDefault(),C.focus())},[]);return f?s.jsx(As,{as:"textarea",ref:y,disableHorizontal:!0,fillContainer:r,useScrollShadow:o,scrollShadowSize:i,outerClassName:t,scrollbarClassName:n,className:_("block w-full appearance-none resize-none bg-transparent text-foreground typography-markdown outline-none","px-3 py-2 md:typography-ui-label","placeholder:text-muted-foreground focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r?"[field-sizing:fixed]":"field-sizing-content",e),spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",disabled:u,...x}):s.jsx("div",{ref:m,onPointerDown:E,style:S!==null?{height:`${S}px`}:void 0,className:_("group/textarea relative flex w-full flex-col rounded-[var(--radius-xl)] bg-[var(--surface-elevated)] pb-2.5","ring-1 ring-inset ring-border/60 transition duration-200 ease-out","hover:[&:not(:focus-within)]:bg-[var(--surface-subtle)]","has-[[disabled]]:pointer-events-none has-[[disabled]]:bg-[var(--surface-subtle)] has-[[disabled]]:ring-transparent",!l&&["hover:[&:not(:focus-within)]:ring-transparent","focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]"],l&&["ring-[var(--status-error)]","focus-within:ring-2 focus-within:ring-[var(--status-error)]"],t),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col gap-2",children:[s.jsx("textarea",{ref:y,className:_("block w-full flex-1 min-h-0 appearance-none resize-none bg-transparent text-foreground typography-markdown outline-none","min-h-[82px] pl-3 pr-2.5 pt-2.5 md:typography-ui-label","focus-visible:outline-none disabled:cursor-not-allowed",!u&&["placeholder:select-none placeholder:text-muted-foreground placeholder:transition placeholder:duration-200 placeholder:ease-out","group-hover/textarea:placeholder:text-foreground/80","focus:placeholder:text-foreground/80"],u&&"text-muted-foreground/60 placeholder:text-muted-foreground/60",e),spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",disabled:u,...x}),s.jsxs("div",{className:"flex items-center justify-end gap-1.5 pl-3 pr-2.5",children:[p,s.jsx(ph,{onResizeStart:v,ariaLabel:"Resize textarea"})]})]})})});vl.displayName="Textarea";const Sl=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],Rn=Object.fromEntries(Sl.map(e=>[e.key,e.Icon])),So="pichamber:project-actions-updated",jl=e=>{const t=(e||"").trim().replace(/\\/g,"/");return t?t==="/"?"/":t.length>1?t.replace(/\/+$/,""):t:""},ls=(e,t)=>`${jl(e)}::${t}`,Cl=({title:e,description:t,info:n,settingsItem:r,titleAccessory:o,headerAction:i,children:l,className:c,contentClassName:d,divider:u=!0})=>s.jsx(ch,{title:e,description:t,info:n,settingsItem:r,titleAccessory:o,headerAction:i,divider:u,className:c,contentClassName:d,children:l}),jo=e=>e.name.trim().length>0&&e.command.trim().length>0,gh=e=>e.name.trim().length===0&&e.command.trim().length===0,bh=e=>!jo(e)&&!gh(e),xh=(e,t)=>e.some(r=>t.has(r.id)&&!jo(r))?{canPersist:!1,actions:e}:{canPersist:!0,actions:e.filter(jo)},yh=450,wh=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,vh=()=>({id:wh(),name:"",command:"",icon:"play"}),Sh=({projectRef:e})=>{const[t,n]=a.useState([]),[r,o]=a.useState(!1),[i,l]=a.useState(null),[c,d]=a.useState(new Set),u=a.useRef(!1);a.useEffect(()=>{let g=!1;return o(!0),(async()=>{try{const S=await io(e);if(g)return;n(S.actions),l(JSON.stringify({actions:S.actions})),d(new Set(S.actions.map(v=>v.id)))}catch{if(g)return;n([]),l(JSON.stringify({actions:[]})),d(new Set)}finally{g||o(!1)}})(),()=>{g=!0}},[e]);const f=a.useMemo(()=>xh(t,c),[t,c]),p=a.useMemo(()=>JSON.stringify({actions:f.actions}),[f.actions]),x=i!==null&&f.canPersist&&p!==i,y=a.useCallback(async g=>await Gd(e,{actions:g,primaryActionId:null})?(l(JSON.stringify({actions:g})),d(new Set(g.map(v=>v.id))),typeof window<"u"&&window.dispatchEvent(new CustomEvent(So,{detail:{projectId:e.id}})),!0):(ie.error("Failed to save actions"),!1),[e]);a.useEffect(()=>{if(!x||r||u.current)return;const g=window.setTimeout(()=>{u.current||(u.current=!0,(async()=>{try{await y(f.actions)}finally{u.current=!1}})())},yh);return()=>{window.clearTimeout(g)}},[x,r,y,f.actions]);const m=a.useCallback(()=>{const g=vh();n(S=>[...S,g])},[]),h=a.useCallback(g=>{n(S=>S.filter(v=>v.id!==g))},[]),b=a.useCallback((g,S)=>{n(v=>v.map(E=>E.id===g?S(E):E))},[]);return s.jsx(Cl,{title:"Actions",info:"Per-project commands shown in the header next to the project name.",settingsItem:"projects.actions",headerAction:s.jsxs(Ne,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:m,children:[s.jsx(P,{name:"add",className:"h-3.5 w-3.5"}),"Add action"]}),contentClassName:"space-y-4",children:r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:"Loading..."}):t.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:"No actions configured yet."}):s.jsx("div",{className:_("space-y-6",oh),children:t.map((g,S)=>{const v=g.icon||"play",E=Rn[v]||"play",j=g.name.trim()||`Action ${S+1}`,k=bh(g);return s.jsxs("div",{className:yl,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:wl,children:j}),s.jsx(Ne,{type:"button",variant:"ghost",size:"xs",className:"h-8 w-8 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>h(g.id),"aria-label":`Delete ${j}`,children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsxs(En,{label:"Name",controlClassName:"w-full max-w-none",children:[s.jsxs(Wt,{children:[s.jsx(Gt,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":"Select icon",children:s.jsx(P,{name:E,className:"h-4 w-4"})})}),s.jsx(Ht,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:Sl.map(C=>{const w=C.Icon,N=(g.icon||"play")===C.key;return s.jsx("button",{type:"button",onClick:()=>b(g.id,T=>({...T,icon:C.key})),className:_("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",N&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":`Icon ${C.label}`,children:s.jsx(P,{name:w,className:"h-4 w-4"})},C.key)})})})]}),s.jsx(Mn,{value:g.name,onChange:C=>b(g.id,w=>({...w,name:C.target.value})),placeholder:"Action name",className:"h-8 min-w-0 flex-1 rounded-md px-3"})]}),s.jsx(En,{label:"Command",controlClassName:"w-full max-w-none",children:s.jsx(vl,{value:g.command,onChange:C=>b(g.id,w=>({...w,command:C.target.value})),placeholder:"e.g. bun run lint",className:"min-h-[88px] w-full font-mono text-xs"})}),k?s.jsx("p",{className:"typography-meta text-muted-foreground",children:"Enter a name and command to save this action."}):null,s.jsx(uh,{checked:g.autoOpenUrl===!0,onChange:C=>b(g.id,w=>({...w,...C?{autoOpenUrl:!0}:{autoOpenUrl:void 0,openUrl:void 0}})),label:"Auto-open URL",info:"Opens a URL from command output, or a custom URL if you set one.",ariaLabel:`Auto-open URL for ${j}`}),g.autoOpenUrl===!0?s.jsx(s.Fragment,{children:s.jsx(En,{label:"Custom URL",info:"Leave empty to use the best URL from command output.",controlClassName:"w-full max-w-none",children:s.jsx(Mn,{value:g.openUrl||"",onChange:C=>b(g.id,w=>({...w,openUrl:C.target.value})),placeholder:"https://localhost:3000",className:"h-8 w-full rounded-md px-3"})})}):null]},g.id)})})})},jh={searchPlaceholder:"Search models",noResults:"No models found",favorites:"Favorites",recent:"Recent",favorite:"Favorite",unfavorite:"Unfavorite",capabilities:"Capabilities",capabilityToolCalling:"Tool calling",capabilityReasoning:"Reasoning",input:"Input",output:"Output",costPerMillion:"Cost ($/1M tokens)"},Ch=({value:e,noneLabel:t,ariaLabel:n,disabled:r=!1,className:o,isModelAllowed:i,onChange:l})=>{const c=$t(w=>w.providers),d=$t(w=>w.modelsMetadata),u=le(w=>w.hiddenModels),f=le(w=>w.isFavoriteModel),p=le(w=>w.toggleFavoriteModel),x=le(w=>w.reorderFavoriteModel),{favoriteModelsList:y,recentModelsList:m}=Hd(),[h,b]=a.useState(!1),[g,S]=a.useState("");a.useEffect(()=>{h?$t.getState().ensureModelMetadata():S("")},[h]);const v=e?c.find(w=>w.id===e.providerId):void 0,E=e&&v?(Array.isArray(v.models)?v.models:[]).find(w=>w.id===e.modelId):void 0,j=e?qd(E,e.modelId):t,k=a.useMemo(()=>e?u.filter(w=>!(w.providerID===e.providerId&&w.modelID===e.modelId)):u,[u,e]),C=a.useCallback(w=>{l({providerId:w.providerID,modelId:w.modelID}),b(!1)},[l]);return s.jsxs(Wt,{modal:!1,open:h,onOpenChange:w=>{r||b(w)},children:[s.jsx(Gt,{asChild:!0,disabled:r,children:s.jsxs("button",{type:"button","aria-label":n,disabled:r,className:_(Vd({size:"default"}),rh,"min-w-0",o),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e?.providerId?s.jsx(Yd,{providerId:e.providerId,className:"size-4 shrink-0"}):null,s.jsx("span",{className:_("truncate",e?"text-foreground":"text-muted-foreground"),children:j})]}),s.jsx(P,{name:"arrow-down-s",className:"size-4 shrink-0"})]})}),s.jsx(Ht,{align:"start",portalToBody:!0,positionerClassName:"z-[80]",className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",children:s.jsx(Qd,{providers:c,favoriteModels:y,recentModels:m,modelsMetadata:d,searchQuery:g,onSearchQueryChange:S,onSelect:C,labels:{...jh,notSelected:t},selectedModel:e?{providerID:e.providerId,modelID:e.modelId}:null,hiddenModels:k,isModelAllowed:i,includeNotSelected:!0,onSelectNone:()=>{l(null),b(!1)},disabled:r,autoFocus:!0,onEscape:()=>b(!1),isFavorite:w=>f(w.providerID,w.modelID),onToggleFavorite:w=>p(w.providerID,w.modelID),onReorderFavorite:(w,N)=>x(w.providerID,w.modelID,N.providerID,N.modelID),reorderFavoriteAriaLabel:"Reorder favorite",reorderFavoriteTitle:"Drag to reorder favorite"})})]})},_r="w-full max-w-none",kh=({form:e})=>{const{name:t,setName:n,parsedDefaultModel:r,handleDefaultModelChange:o,project:i}=e,l=$t(c=>c.loadProviders);return a.useEffect(()=>{l({source:"projectSettings"})},[l]),i?s.jsx(Cl,{title:"Project",divider:!1,children:s.jsxs("div",{className:yl,children:[s.jsx(En,{label:"Name",settingsItem:"projects.name",controlClassName:_r,children:s.jsx(Mn,{value:t,onChange:c=>n(c.target.value),placeholder:"Project name","aria-label":"Project name",className:"h-8 w-full rounded-md px-3"})}),s.jsx(En,{label:"Default model",info:"Used when starting a new chat in this project. Unset keeps the global session default.",settingsItem:"projects.default-model",controlClassName:_r,children:s.jsx(Ch,{value:r,noneLabel:"Use global default",ariaLabel:"Default model for new chats",className:_r,onChange:c=>{if(!c){o("","");return}o(c.providerId,c.modelId)}})})]})}):null},Ah=e=>{const[t,n]=a.useState(""),[r,o]=a.useState(void 0);a.useEffect(()=>{if(!e){n(""),o(void 0);return}n(e.label??""),o(e.defaultModel)},[e]);const i=a.useMemo(()=>Jd(r),[r]),l=!!e&&(t.trim()!==(e?.label??"").trim()||(r??void 0)!==(e?.defaultModel??void 0)),c=a.useCallback((u,f)=>{o(u&&f?`${u}/${f}`:void 0)},[]),d=a.useCallback(async()=>{if(!e)return null;const u=t.trim();return u?{label:u,defaultModel:r??null}:null},[r,t,e]);return{name:t,setName:n,defaultModel:r,parsedDefaultModel:i,handleDefaultModelChange:c,hasChanges:l,prepareSaveData:d,project:e}},Nh=450,Ih=(e,t)=>{const{hasChanges:n,name:r,defaultModel:o,prepareSaveData:i}=e,l=a.useRef(!1);a.useEffect(()=>{if(!n||!r.trim()||l.current)return;const c=window.setTimeout(()=>{l.current||(l.current=!0,(async()=>{try{const d=await i();if(d)try{await t(d)}catch{ie.error("Failed to save project settings")}}finally{l.current=!1}})())},Nh);return()=>{window.clearTimeout(c)}},[o,n,r,t,i])},Eh=({project:e,onIdentitySave:t})=>{const n=Ah(e),r=a.useMemo(()=>e?{id:e.id,path:e.path}:null,[e]),o=a.useCallback(async i=>{await t(i)},[t]);return Ih(n,o),!e||!r?null:s.jsxs("div",{className:"space-y-0",children:[s.jsx(kh,{form:n}),s.jsx(Sh,{projectRef:r})]})},Rh=6e4,Dh=3e4,xn=new Map;let Fi=0,Li=!1;const Ph=()=>{if(Li||typeof window>"u")return;Li=!0;const e=()=>{const t=Date.now();t-Fi<Dh||typeof document<"u"&&document.hidden||(Fi=t,ht(async()=>{const{getRegisteredRuntimeAPIs:n}=await import("./index-BnZVqcki.js").then(r=>r.cy);return{getRegisteredRuntimeAPIs:n}},__vite__mapDeps([2,3,4,5,6,7,8,9])).then(({getRegisteredRuntimeAPIs:n})=>{const r=n()?.github;r&&Sr.getState().refresh(r)}).catch(()=>{}))};window.addEventListener("focus",e),typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.hidden||e()})},Sr=Ls()(vr((e,t)=>({status:null,fetchedAt:null,isLoading:!1,error:null,runtimeKey:Mt(),resetForRuntimeSwitch:n=>{const r=n??Mt();xn.clear(),e({status:null,fetchedAt:null,isLoading:!1,error:null,runtimeKey:r})},refresh:async(n,r)=>{Ph();const o=Mt();t().runtimeKey!==o&&t().resetForRuntimeSwitch(o);const i=t(),l=Date.now();if(!r?.force&&i.status&&i.fetchedAt&&l-i.fetchedAt<Rh)return i.status;const c=xn.get(o);if(c)return c;const d=n??null;if(!d)return t().status;const u=(async()=>{e({isLoading:!0});try{const f=await d.status();return Mt()!==o?null:(e({status:f,fetchedAt:Date.now(),isLoading:!1,error:null,runtimeKey:o}),f)}catch(f){return Mt()!==o?null:(e({isLoading:!1,error:f instanceof Error?f.message:"GitHub status check failed"}),t().status)}})();xn.set(o,u);try{return await u}finally{xn.get(o)===u&&xn.delete(o)}}}),{name:"github-status-store"}));typeof window<"u"&&On(e=>{Sr.getState().resetForRuntimeSwitch(e.runtimeKey)});const Mh=()=>Sr(e=>(e.status?.hosts??[]).find(n=>n.authenticated)?.login??null),Hn=100;function _x(){const e=le(w=>w.isArchivePageOpen),t=le(w=>w.setArchivePageOpen),n=le(w=>w.setActiveMainTab),r=Te(w=>w.setCurrentSession),o=Te(w=>w.unarchiveSession),i=sn(w=>w.homeDirectory),l=ao({archived:!0}),[c,d]=a.useState(""),[u,f]=a.useState(null),[p,x]=a.useState(Hn),y=c.trim().toLowerCase(),m=a.useMemo(()=>e?[...l].sort((w,N)=>(N.time?.archived??0)-(w.time?.archived??0)):[],[l,e]),h=a.useMemo(()=>{const w=new Map;for(const N of m){const T=Ie(Nn(N))??"",O=w.get(T);if(O){O.sessions.push(N);continue}w.set(T,{directory:T,label:T?Tn(T,i)||T:"other projects",sessions:[N]})}return[...w.values()].sort((N,T)=>T.sessions.length-N.sessions.length)},[i,m]),b=a.useMemo(()=>y?m.filter(w=>(w.title??"").toLowerCase().includes(y)):u===null?m:h.find(w=>w.directory===u)?.sessions??[],[h,y,u,m]),g=b.slice(0,p),S=b.length-g.length,v=l.length,E=a.useCallback(w=>{f(w),x(Hn)},[]),j=a.useCallback(w=>{const N=Ie(Nn(w));r(w.id,N??void 0),n("chat"),t(!1)},[n,r,t]),k=a.useCallback(w=>{o(w.id).then(N=>{N?ie.success("Session restored"):ie.error("Failed to restore session")})},[o]);if(!e)return null;const C=(w,N,T,O,$,U,K)=>s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:$,title:U,className:_("flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left typography-ui-label transition-[padding] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",K?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",O?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:N}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:T})]}),K?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>Ds.requestDelete({sessions:K,mode:"session"}),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover/dir:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Delete all archived sessions in ${N}`,children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:"Delete all archived sessions in this project"})]}):null]},w);return s.jsx(kd,{open:e,onOpenChange:t,children:s.jsxs(Ad,{children:[s.jsx(Nd,{className:"fixed inset-0 z-50 bg-black/25 dark:bg-black/40 transition-opacity duration-150 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0"}),s.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 max-[640px]:p-2 pointer-events-none",children:s.jsxs(Id,{className:"pointer-events-auto relative flex h-[min(84vh,720px)] max-h-[calc(100dvh-2rem)] w-[min(92vw,960px)] flex-col overflow-hidden rounded-2xl border border-border/80 bg-background shadow-2xl transition-all duration-150 data-[starting-style]:scale-[0.98] data-[starting-style]:opacity-0 data-[ending-style]:scale-[0.98] data-[ending-style]:opacity-0 max-[640px]:h-[calc(100dvh-1rem)] max-[640px]:max-h-none max-[640px]:w-[calc(100vw-1rem)] max-[640px]:rounded-xl",children:[s.jsx(Ed,{className:"sr-only",children:"Archived sessions"}),s.jsx(Rd,{className:"sr-only",children:"Browse and restore archived sessions."}),s.jsx(Dd,{"aria-label":"Close archived sessions",className:"absolute right-3 top-3 z-10 inline-flex size-8 items-center justify-center rounded-md bg-background/80 text-muted-foreground backdrop-blur-sm hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:s.jsx(P,{name:"close",className:"size-4"})}),s.jsxs("div",{className:"flex min-h-0 flex-1",children:[s.jsx("div",{className:"flex w-64 flex-shrink-0 flex-col border-r border-border/50 max-[640px]:w-40",children:s.jsxs("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:[C("__all__","All directories",v,u===null,()=>E(null)),h.map(w=>C(w.directory||"__none__",w.label,w.sessions.length,u===w.directory,()=>E(w.directory),w.directory||void 0,w.sessions))]})}),s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsxs("div",{className:"flex items-center gap-3 px-6 pr-12 pt-3",children:[s.jsxs("div",{className:"relative min-w-0 flex-1",children:[s.jsx(P,{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",{value:c,onChange:w=>{d(w.target.value),x(Hn)},placeholder:"Search archived sessions",className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-3 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"})]}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:b.length===1?`${b.length} archived session`:`${b.length} archived sessions`})]}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl space-y-0.5",children:[g.length===0?s.jsx("div",{className:"py-10 text-center text-muted-foreground",children:s.jsx("p",{className:"typography-ui-label font-semibold",children:y?"No matching archived sessions":"No archived sessions"})}):g.map(w=>{const N=Ie(Nn(w))??"",T=N?Tn(N,i)||N:null;return s.jsxs("div",{className:"group relative flex cursor-pointer items-center gap-3 rounded-md py-1 pl-2 pr-2 transition-[padding] hover:bg-interactive-hover/40 hover:pr-14 focus-within:pr-14",onClick:()=>j(w),role:"button",tabIndex:0,onKeyDown:O=>{(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),j(w))},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:bs(w)}),y&&T?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:N,children:T}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:ff(w.time?.archived??w.time?.updated??w.time?.created??Date.now())}),s.jsx("button",{type:"button",onClick:O=>{O.stopPropagation(),k(w)},className:"absolute right-7 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-foreground group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Restore ${bs(w)}`,children:s.jsx(P,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:O=>{O.stopPropagation(),Ds.requestDelete({sessions:[w],mode:"session"})},className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-destructive group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Delete ${bs(w)}`,children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},w.id)}),S>0?s.jsx("button",{type:"button",onClick:()=>x(w=>w+Hn),className:"mt-1 flex items-center justify-start rounded-md px-2 py-1 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:"Show more sessions"}):null]})})]})]})]})})]})})}const Th=e=>{if(!e||typeof e!="object")return{percent:0,hasInput:!1};const t=e.input??0,n=e.cache&&typeof e.cache=="object"?e.cache.read??0:0,r=e.cache&&typeof e.cache=="object"?e.cache.write??0:0,o=t+n+r;if(o<=0)return{percent:0,hasInput:!1};const i=Math.max(0,n);return{percent:Math.min(100,Math.max(0,i/o*100)),hasInput:!0}},Fh=e=>{if(!e||typeof e!="object")return 0;const t=typeof e.input=="number"&&Number.isFinite(e.input)&&e.input>=0?e.input:0,n=typeof e.cacheRead=="number"&&Number.isFinite(e.cacheRead)&&e.cacheRead>=0?e.cacheRead:0,r=typeof e.cacheWrite=="number"&&Number.isFinite(e.cacheWrite)&&e.cacheWrite>=0?e.cacheWrite:0;return t+n+r},es=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?e:0,Lh=e=>{if(!e||typeof e!="object")return null;const t=es(e.input),n=es(e.output),r=es(e.cacheRead),o=es(e.cacheWrite);return{input:t,output:n,reasoning:null,cacheRead:r,cacheWrite:o,total:t+n+r+o}},Oi=e=>{const t=Lh(e.info.usage);if(t)return t;const n=e.info.tokens,r=n!==void 0?n:e.parts.find(f=>f.tokens!==void 0)?.tokens;if(typeof r=="number")return{input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:es(r)};if(!r||typeof r!="object")return{input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0};const o=r,i=es(o.input),l=es(o.output),c=es(o.reasoning),d=es(o.cache?.read),u=es(o.cache?.write);return{input:i,output:l,reasoning:c,cacheRead:d,cacheWrite:u,total:i+l+c+d+u}},kl=380,zr=8,Oh=140;function Bh({open:e,onClose:t,anchorRef:n,closeOnWheel:r=!1}){const o=a.useRef(null),i=a.useRef(null),[l,c]=a.useState(e),[d,u]=a.useState(!1),[f,p]=a.useState(null),{enabled:x}=$o();return a.useLayoutEffect(()=>{if(!e||!x||!l)return;const y=()=>{const b=n.current?.getBoundingClientRect(),g=i.current?.getBoundingClientRect();if(!b||!g){p(null);return}const S=b.left-g.left;p(Math.min(Math.max(S,zr),Math.max(zr,g.width-kl-zr)))};y();const m=i.current;if(typeof ResizeObserver>"u"||!m)return;const h=new ResizeObserver(y);return h.observe(m),()=>h.disconnect()},[n,x,e,l]),a.useEffect(()=>{if(e){c(!0),u(!1);return}if(!l)return;u(!0);const y=window.setTimeout(()=>{c(!1),u(!1)},Oh);return()=>window.clearTimeout(y)},[e,l]),a.useEffect(()=>{if(!e)return;const y=m=>{m.key==="Escape"&&t()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[t,e]),a.useEffect(()=>{if(!e)return;const y=m=>{const h=m.target;if(!(h instanceof Node)){t();return}o.current?.contains(h)||n.current?.contains(h)||t()};return document.addEventListener("pointerdown",y,!0),r&&document.addEventListener("wheel",y,!0),()=>{document.removeEventListener("pointerdown",y,!0),r&&document.removeEventListener("wheel",y,!0)}},[n,r,t,e]),{panelRef:o,wrapperRef:i,shouldRender:l,isExiting:d,anchorLeft:f,isPopover:x&&f!==null}}const Bi=(e,t)=>{if(!e||typeof e!="object")return;const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:void 0},fr=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e),qn=({icon:e,iconNode:t,label:n,children:r})=>s.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[s.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:t??(e?s.jsx(P,{name:e,className:"size-[18px]"}):null)}),s.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:n}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:r})]}),_h=({open:e,onClose:t,anchorRef:n,contextDisplay:r})=>{const{panelRef:o,wrapperRef:i,shouldRender:l,isExiting:c,anchorLeft:d,isPopover:u}=Bh({open:e,onClose:t,anchorRef:n,closeOnWheel:!0});return l?s.jsxs("div",{ref:i,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[s.jsx("div",{ref:o,role:"tooltip","aria-label":"Context usage for current conversation",className:_("overflow-y-auto overscroll-contain rounded-lg border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_8px_24px_rgb(0_0_0_/_0.18)] will-change-transform",u?"absolute origin-top-left":"mx-3 mt-2",c?"pointer-events-none":"pointer-events-auto"),style:{animation:`${c?"session-metadata-out":"session-metadata-in"} ${c?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...u?{top:8,left:d??8,width:`min(${kl}px, calc(100% - 16px))`}:null},children:s.jsx("div",{className:"space-y-1",children:r?s.jsxs(s.Fragment,{children:[s.jsx(qn,{iconNode:s.jsx(Fa,{percentage:r.percentage}),label:"Context",children:s.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[s.jsxs("span",{className:_("font-semibold",r.colorClass),children:[r.percentage.toFixed(1),"%"]}),s.jsx("span",{className:"text-muted-foreground",children:r.tokens})]})}),r.cacheRead!==null&&r.cacheWrite!==null?s.jsxs(s.Fragment,{children:[s.jsx(qn,{icon:"stack",label:"Cache read",children:s.jsx("span",{className:"tabular-nums",children:fr(r.cacheRead)})}),s.jsx(qn,{icon:"edit",label:"Cache write",children:s.jsx("span",{className:"tabular-nums",children:fr(r.cacheWrite)})})]}):null,r.cacheHitPercent!==null?s.jsx(qn,{icon:"check",label:"Cache hit",children:s.jsxs("span",{className:"tabular-nums",children:[r.cacheHitPercent.toFixed(1),"%"]})}):null]}):s.jsx("div",{className:"px-2.5 py-2 typography-meta text-muted-foreground",children:"Context usage is not available for this conversation yet."})})}),s.jsx("style",{children:`
|
|
3
|
+
@keyframes session-metadata-in {
|
|
4
|
+
from { opacity: 0; transform: translateY(-8px) scale(0.985); }
|
|
5
|
+
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
6
|
+
}
|
|
7
|
+
@keyframes session-metadata-out {
|
|
8
|
+
from { opacity: 1; transform: translateY(0) scale(1); }
|
|
9
|
+
to { opacity: 0; transform: translateY(-6px) scale(0.985); }
|
|
10
|
+
}
|
|
11
|
+
`})]}):null},zh=a.memo(function({open:t,onOpenChange:n,currentSessionId:r,effectiveDirectory:o,isNewSessionDraftOpen:i}){const l=a.useRef(null),c=Xd(r??""),d=$t(D=>D.providers),u=$t(D=>D.currentProviderId),f=$t(D=>D.currentModelId),p=$t(D=>D.getCurrentModel()),x=$t(D=>D.getModelMetadata);$t(D=>D.modelsMetadata.size);const y=Zd(a.useCallback(D=>r?D.sessionModelSelections.get(r)??null:null,[r])),m=a.useMemo(()=>{for(let D=c.length-1;D>=0;D-=1){const R=c[D]?.info;if(R.role!=="user")continue;const I=R.model,M=I?.providerID??I?.providerId,W=I?.modelID??I?.modelId,G=typeof M=="string"&&M.trim().length>0?M:void 0,B=typeof W=="string"&&W.trim().length>0?W:void 0;if(G&&B)return{providerID:G,modelID:B}}return null},[c]),h=a.useMemo(()=>{for(let D=c.length-1;D>=0;D-=1){const R=c[D];if(R?.info.role==="assistant"&&Oi(R).total>0)return R}return null},[c]),b=m??(()=>{const D=h?.info.model,R=D?.providerID??D?.providerId,I=D?.modelID??D?.modelId;return R&&I?{providerID:R,modelID:I}:null})()??(y?{providerID:y.providerId,modelID:y.modelId}:null)??(u&&f?{providerID:u,modelID:f}:null),S=(b?d.find(D=>D.id===b.providerID):void 0)?.models.find(D=>D.id===b?.modelID),v=b?x(b.providerID,b.modelID):void 0,E=Bi(S?.limit,"context")??v?.limit?.context??Bi(p?.limit,"context")??0,j=h?Oi(h):null,k=h?.info?.usage,C=k?Fh(k):j?.total??0,w=!i&&C>0&&E>0?Math.min(C/E*100,999):null,N=w!==null?`${fr(C)}/${fr(E)}`:null,T=w===null?"":w>=90?"text-[var(--status-error)]":w>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",O=j?.cacheRead??null,$=j?.cacheWrite??null,U=j?Th({input:j.input,cache:{read:j.cacheRead,write:j.cacheWrite}}):{percent:0,hasInput:!1},K=U.hasInput?U.percent:null,L=w!==null&&N?{percentage:w,tokens:N,colorClass:T,cacheRead:O,cacheWrite:$,cacheHitPercent:K}:null;return s.jsxs(s.Fragment,{children:[s.jsx("button",{ref:l,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Show context usage for current conversation",title:"Context usage","aria-expanded":t,onClick:()=>n(D=>!D),style:{touchAction:"manipulation"},children:s.jsx(Fa,{percentage:L?.percentage??0,size:20,className:"size-5 -rotate-90"})}),s.jsx(_h,{open:t,onClose:()=>n(!1),anchorRef:l,contextDisplay:L})]})}),ln="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",Uh="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",$h=a.memo(function({visible:t=!0,title:n,ariaLabel:r,onClick:o,className:i,Icon:l,iconClassName:c,pressed:d=!1}){return t?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,"aria-label":r,"aria-pressed":d,className:_(i??ln,d&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(P,{name:l,className:c??"h-[18px] w-[18px]"})})}),s.jsx(Ke,{children:s.jsx("p",{children:n})})]}):null}),Kh=e=>{let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36).padStart(7,"0").slice(-6)},Al=({variant:e="desktop"})=>{const t=Ps(f=>f.entries),[n,r]=a.useState(!1),o=a.useRef(null),i=a.useMemo(()=>[...t.values()].sort((f,p)=>p.startedAt-f.startedAt),[t]),l=i.filter(f=>f.state&&f.state.phase!=="failed"||La(f)).length,c=a.useCallback(()=>{o.current&&(clearTimeout(o.current),o.current=null)},[]),d=a.useCallback(()=>{c(),o.current=setTimeout(()=>r(!1),150)},[c]);if(a.useEffect(()=>()=>c(),[c]),i.length===0)return null;const u=f=>{if(!nu(f))return;const p=f.receipt;if(!p)return;const x=Te.getState();x.newSessionDraft.open?x.setNewSessionDraftTarget({directoryOverride:p.path,worktreeIntent:null}):x.openNewSessionDraft({directoryOverride:p.path}),Ps.getState().clearEntry(f.key),le.getState().setActiveMainTab("chat"),r(!1)};return s.jsxs(Wt,{open:n,onOpenChange:r,children:[s.jsx(Gt,{asChild:!0,children:s.jsxs("button",{type:"button",className:_(e==="desktop"?ln:"pointer-events-auto inline-flex h-10 w-full items-center justify-center gap-2 rounded-lg border border-border bg-sidebar px-3 typography-ui-label font-medium text-foreground shadow-lg hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",e==="desktop"&&"relative w-auto px-2.5"),"aria-label":"Background tasks",onPointerEnter:f=>{f.pointerType==="mouse"&&(c(),r(!0))},onPointerLeave:f=>{f.pointerType==="mouse"&&d()},children:[l>0?s.jsx(ws,{variant:"inline",text:null,animationType:"spinner"}):s.jsx(P,{name:"task",className:"size-[18px]"}),s.jsx("span",{children:"Background tasks"})]})}),s.jsxs(Ht,{align:"end",side:e==="mobile"?"top":"bottom",className:"w-[min(26rem,calc(100vw-2rem))] max-h-[70vh] overflow-y-auto p-0",onPointerEnter:c,onPointerLeave:d,children:[s.jsxs("div",{className:"border-b border-border px-3 py-2.5",children:[s.jsx("p",{className:"typography-ui-label font-medium text-foreground",children:"Background tasks"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l===1?"1 worktree is being created":`${l} worktrees are being created`})]}),s.jsx("div",{className:"divide-y divide-border",children:i.map(f=>s.jsx(Wh,{entry:f,onOpen:()=>u(f)},f.key))})]})]})},Wh=({entry:e,onOpen:t})=>{const n=e.state?.phase==="failed",r=!!(e.state&&!n),o=La(e),i=eu(e),l=n?e.state?.label??"Worktree creation failed":r?e.state?.label??"Creating worktree...":o?"Sending prompt...":`Worktree ready: ${e.branch??e.receipt?.branch??"new worktree"}`;return s.jsxs("div",{className:"flex items-start gap-3 px-3 py-3",children:[s.jsx("div",{className:"mt-0.5 shrink-0",children:r||o?s.jsx(ws,{variant:"inline",text:null,animationType:"spinner"}):n?s.jsx(P,{name:"alert",className:"size-4 text-[var(--status-error)]"}):s.jsx(P,{name:"git-branch",className:"size-4 text-[var(--status-success)]"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"truncate typography-ui-label text-foreground",children:l}),s.jsx("p",{className:"mt-0.5 truncate typography-micro text-muted-foreground",children:n?e.state?.error:e.path??e.intent.sourceDirectory})]}),n?s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.failedSend?s.jsx(Ne,{type:"button",size:"xs","aria-label":`Restore draft for ${e.intent.sourceDirectory} from ${e.intent.startRef} (task ${Kh(e.key)})`,onClick:()=>{const c=tu(e.key),d=su(c,"background-task");d&&ie.error(d.title,{description:d.description})},children:"Restore draft"}):null,s.jsx(Ne,{type:"button",variant:"ghost",size:"xs",onClick:()=>Ps.getState().dismissFailed(e.key),children:"Dismiss"})]}):null,i?s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(Ne,{type:"button",size:"xs",onClick:t,children:"Open"}),s.jsx(Ne,{type:"button",variant:"ghost",size:"icon",className:"size-6",onClick:()=>Ps.getState().clearEntry(e.key),"aria-label":"Dismiss completed task",children:s.jsx(P,{name:"close",className:"size-3.5"})})]}):null]})},Gh=["pinned","today","yesterday","thisWeek","lastWeek","older"],Hh={pinned:"Pinned",today:"Today",yesterday:"Yesterday",thisWeek:"This week",lastWeek:"Last week",older:"Older"},qh=(e,t)=>{if(e==="sunday")return 0;if(e==="monday")return 1;try{const n=t||(typeof Intl<"u"&&Intl.DateTimeFormat?Intl.DateTimeFormat().resolvedOptions().locale:"en-US");if(typeof Intl<"u"&&typeof Intl.Locale=="function"){const r=new Intl.Locale(n),i=(typeof r.getWeekInfo=="function"?r.getWeekInfo():r.weekInfo)?.firstDay;if(i===7||i===0)return 0;if(i!==void 0)return 1}}catch{}return 1},Co=(e,t)=>{const n=new Date(e);n.setHours(0,0,0,0);const r=n.getTime(),o=new Date(r);o.setDate(o.getDate()-1),o.setHours(0,0,0,0);const i=o.getTime(),c=(n.getDay()-t+7)%7,d=new Date(r);d.setDate(d.getDate()-c),d.setHours(0,0,0,0);const u=d.getTime(),f=new Date(u);f.setDate(f.getDate()-7),f.setHours(0,0,0,0);const p=f.getTime();return{startOfToday:r,startOfYesterday:i,startOfThisWeek:u,startOfLastWeek:p}},Yh=(e,t)=>!Number.isFinite(e)||e<=0?"older":e>=t.startOfToday?"today":e>=t.startOfYesterday?"yesterday":e>=t.startOfThisWeek?"thisWeek":e>=t.startOfLastWeek?"lastWeek":"older",Vh=(e,t)=>{const n={pinned:[],today:[],yesterday:[],thisWeek:[],lastWeek:[],older:[]},{getTimestamp:r,isPinned:o,boundaries:i}=t,l=e.length;for(let d=0;d<l;d++){const u=e[d];if(o(u))n.pinned.push(u);else{const f=r(u),p=Yh(f,i);n[p].push(u)}}const c=[];for(const d of Gh){const u=n[d];u.length>0&&c.push({id:d,items:u})}return c},Qh=e=>{const t=new Date(e);return t.setDate(t.getDate()+1),t.setHours(0,0,0,0),t.getTime()},Jh=(e,t)=>{const[n,r]=a.useState(0),o=a.useMemo(()=>e?Co(Date.now(),t):null,[e,t,n]),i=o?.startOfToday??null;return a.useEffect(()=>{if(i===null||typeof window>"u"||typeof document>"u")return;const l=Date.now(),c=window.setTimeout(()=>{r(u=>u+1)},Math.max(50,Qh(l)-l+50)),d=()=>{document.visibilityState==="visible"&&Co(Date.now(),t).startOfToday!==i&&r(u=>u+1)};return document.addEventListener("visibilitychange",d),()=>{window.clearTimeout(c),document.removeEventListener("visibilitychange",d)}},[i,t,n]),o},Xh=e=>{const{normalizedProjects:t,enabled:n=!0,ownership:r,hasAuthoritativeGlobalSessions:o,isWorktreeTopologyLoading:i,unresolvedWorktreeProjectPaths:l,foldersMap:c,createFolder:d,addSessionToFolder:u}=e;a.useEffect(()=>{!n||!o||i||t.forEach(f=>{if(l.has(f.normalizedPath))return;const p=sl(f.normalizedPath),x=r.archivedSessionsByProject.get(f.id)??[],y=c[p]??[],m=new Map(y.map(h=>[h.name.toLowerCase(),h]));x.forEach(h=>{const b=hf(h,f.normalizedPath),g=b.toLowerCase();let S=m.get(g);S||(S=d(p,b),m.set(g,S)),S.sessionIds.includes(h.id)||u(p,S.id,h.id)})})},[t,n,r,o,i,l,c,d,u])},Zh=e=>({getOrderedGroups:a.useCallback((n,r)=>{const o=e.get(n);if(!o||o.length===0)return r;const i=new Map(r.map(u=>[u.id,u])),l=[];o.forEach(u=>{const f=i.get(u);f&&(l.push(f),i.delete(u))});const c=[],d=[];return r.forEach(u=>{i.has(u.id)&&(u.isArchivedBucket?d.push(u):c.push(u))}),[...c,...l,...d]},[e])}),em=e=>{const{normalizedProjects:t,getSessionsForProject:n,getArchivedSessionsForProject:r,availableWorktreesByProject:o,projectRepoStatus:i,projectRootBranches:l,lastRepoStatus:c,buildGroupedSessions:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:f,filterSessionNodesForSearch:p,buildGroupSearchText:x,foldersMap:y}=e,m=a.useRef(new Map),h=a.useMemo(()=>{const C=m.current,w=new Map;let N=0,T=0;const O=(U,K)=>U.length===K.length&&U.every((L,D)=>L===K[D]),$=t.map(U=>{const K=n(U.id),L=r(U.id),D=i.has(U.id)?!!i.get(U.id):c,R=l.get(U.id)??null,I=o.get(U.normalizedPath)??[],M=C.get(U.id);if(M&&M.project===U&&O(M.activeSessions,K)&&O(M.archivedSessions,L)&&M.rootBranch===R&&M.isRepo===D&&M.worktrees===I&&M.buildGroupedSessions===d)return N+=1,w.set(U.id,M),M.section;T+=1;const W=nl([...K,...L]),G=d(W,U.normalizedPath,I,R,D),B={project:U,groups:G};return w.set(U.id,{project:U,activeSessions:K,archivedSessions:L,rootBranch:R,isRepo:D,worktrees:I,buildGroupedSessions:d,section:B}),B});return m.current=w,N>0&&Kt("ui.sidebar.project_section.reused",N),T>0&&Kt("ui.sidebar.project_section.rebuilt",T),$},[t,n,r,o,i,c,d,l]),b=a.useMemo(()=>h,[h]),g=a.useMemo(()=>{const C=new WeakMap;if(!u)return C;const w=N=>N.reduce((T,O)=>T+1+w(O.children),0);return b.forEach(N=>{N.groups.forEach(T=>{const O=p(T.sessions,f),$=w(O),U=x(T).includes(f),K=Ie(T.directory??null),D=(K?y[K]??[]:[]).filter(R=>R.name.toLowerCase().includes(f)).length;C.set(T,{filteredNodes:O,matchedSessionCount:$,folderNameMatchCount:D,groupMatches:U,hasMatch:U||$>0||D>0})})}),C},[u,b,p,f,x,y]),S=a.useMemo(()=>u?b.map(C=>({...C,groups:C.groups.filter(w=>g.get(w)?.hasMatch===!0)})).filter(C=>C.groups.length>0):b,[u,b,g]),v=u?S:b,E=a.useRef(new WeakMap),j=a.useMemo(()=>{const C=E.current;return v.map(w=>{const N=C.get(w);if(N&&N.query===f)return N.section;const T=w.groups.filter(R=>!R.isArchivedBucket),O=w.groups.filter(R=>R.isArchivedBucket),$=T.flatMap(R=>u?g.get(R)?.filteredNodes??[]:R.sessions),U=T.map(R=>({scopeKey:R.folderScopeKey??Ie(R.directory??null),directory:R.directory??null})).filter(R=>!!R.scopeKey),K=T.find(R=>R.isMain)??null,L={id:"flat",label:K?.label??"",branch:K?.branch??null,description:K?.description??null,isMain:!0,isArchivedBucket:!1,directory:K?.directory??w.project.normalizedPath,folderScopeKey:K?.folderScopeKey??w.project.normalizedPath,folderScopes:U,sessions:$};if(u){const R=T.map(I=>g.get(I)).filter(I=>!!I);g.set(L,{filteredNodes:$,matchedSessionCount:R.reduce((I,M)=>I+M.matchedSessionCount,0),folderNameMatchCount:R.reduce((I,M)=>I+M.folderNameMatchCount,0),groupMatches:R.some(I=>I.groupMatches),hasMatch:R.some(I=>I.hasMatch)})}const D={project:w.project,groups:[L,...O]};return C.set(w,{query:f,section:D}),D})},[g,u,f,v]),k=a.useMemo(()=>u?v.reduce((C,w)=>C+w.groups.reduce((N,T)=>{const O=g.get(T);if(!O)return N;const $=O.folderNameMatchCount+(O.groupMatches?1:0);return N+O.matchedSessionCount+$},0),0):0,[u,v,g]);return{projectSections:h,visibleProjectSections:b,groupSearchDataByGroup:g,searchableProjectSections:S,sectionsForRender:v,flatSectionsForRender:j,searchMatchCount:k}},tm=e=>{const{projectSections:t,activeProjectId:n,activeSessionByProject:r,setActiveSessionByProject:o,currentSessionId:i,handleSessionSelect:l,newSessionDraftOpen:c,mobileVariant:d,openNewSessionDraft:u,setActiveMainTab:f,setSessionSwitcherOpen:p}=e,x=a.useMemo(()=>{const m=new Map,h=new Map,b=(g,S,v,E)=>{m.has(g)||m.set(g,new Map);const j=m.get(g);E.forEach(k=>{const C=Ie(k.session.directory??v??S);j.set(k.session.id,{directory:C}),h.has(g)||h.set(g,{id:k.session.id,directory:C}),k.children.length>0&&b(g,S,C,k.children)})};return t.forEach(g=>{g.groups.forEach(S=>{b(g.project.id,g.project.normalizedPath,S.directory,S.sessions)})}),{metaByProject:m,firstSessionByProject:h}},[t]),y=a.useRef(null);a.useLayoutEffect(()=>{if(!n)return;if(c){y.current=n;return}if(y.current===n)return;const m=t.find(k=>k.project.id===n);if(!m)return;y.current=n;const h=x.metaByProject.get(n);if(i&&h&&h.has(i)){o(k=>{if(k.get(n)===i)return k;const C=new Map(k);return C.set(n,i),C});return}const b=i?Array.from(x.metaByProject.entries()).some(([k,C])=>k!==n&&C.has(i)):!1;if(i&&h&&!b)return;if(!h||h.size===0){f("chat"),d&&p(!1),u({selectedProjectId:m.project.id,directoryOverride:m.project.normalizedPath});return}const g=r.get(n),S=g&&h.has(g)?g:null,v=x.firstSessionByProject.get(n)?.id??null,E=S??v;if(!E||E===i)return;const j=h.get(E)?.directory??null;l(E,j,{keepPanelOpen:!0})},[n,r,i,l,c,d,u,t,x,f,p,o]),a.useEffect(()=>{if(!n||!i)return;const m=x.metaByProject.get(n);!m||!m.has(i)||o(h=>{if(h.get(n)===i)return h;const b=new Map(h);return b.set(n,i),b})},[n,i,x,o])},sm=({initialActiveSessionByProject:e,persistActiveSessionByProject:t,...n})=>{const r=Te(c=>c.currentSessionId),o=Te(c=>!!c.newSessionDraft?.open),[i,l]=a.useState(()=>new Map(e));return tm({...n,activeSessionByProject:i,setActiveSessionByProject:l,currentSessionId:r,newSessionDraftOpen:o}),a.useEffect(()=>{t(i)},[i,t]),null},_i=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)"],nm=e=>{let t=5381;for(let n=0;n<e.length;n+=1)t=t*33^e.charCodeAt(n);return t>>>0},rm=(e,t,n)=>(n.get(e)??0)>0?e:t.get(e)??null,Nl=e=>{if(!e||typeof e!="string"||e.trim().length===0)return null;const t=nm(e.trim())%_i.length;return _i[t]},om=(e,t)=>{const n=Nl(e);return n?t?.active?`color-mix(in srgb, ${n} 30%, var(--interactive-selection))`:`color-mix(in srgb, ${n} 18%, transparent)`:null},zi=e=>!!e.time?.archived,im=e=>{const t=a.useCallback(i=>[i.label,i.branch??"",i.description??"",i.directory??""].join(" ").toLowerCase(),[]),n=a.useCallback(i=>{const l=Ie(i.directory??null)??"";return`${bs(i)} ${l}`.toLowerCase()},[]),r=a.useCallback((i,l)=>l?i.flatMap(c=>{if(n(c.session).includes(l))return[c];const u=r(c.children,l);return u.length===0?[]:[{...c,children:u}]}):i,[n]),o=a.useCallback((i,l,c=[],d,u)=>{const f=Ie(l??null),p=nl(i).sort(Oa(e.pinnedSessionIds,e.sessionOrderRanks)),x=new Map(p.map(C=>[C.id,C])),y=new Map,m=new Map;p.forEach(C=>{const w=C.parentID??null,N=w?x.get(w):null,T=N&&zi(N)===zi(C)?w:null;y.set(C.id,T),T&&m.set(T,(m.get(T)??0)+1)});const h=c.map(C=>({worktree:C,directory:Ie(C.path)})).filter(C=>!!C.directory&&!C.worktree.isPrimary).sort((C,w)=>w.directory.length-C.directory.length),b=(C,w)=>w===C||w.startsWith(`${C}/`),g=C=>{const w=Ie(C.directory??null);return w?h.find(N=>b(N.directory,w))?.worktree??null:null},S=(C,w)=>{const N=rm(C.id,y,m);return{session:C,children:[],worktree:w,forkColorId:N}},v=[],E=new Map,j=[];for(const C of h)E.set(C.directory,[]);p.forEach(C=>{const w=g(C),N=S(C,w);C.time?.archived?j.push(N):w?E.get(Ie(w.path)??"")?.push(N):v.push(N)});const k=[{id:"root",label:u&&d&&d!=="HEAD"?`project root: ${d}`:"project root",branch:d??null,description:f?co(f,e.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:f,folderScopeKey:f,sessions:v}];for(const{worktree:C,directory:w}of h)k.push({id:`worktree:${w}`,label:C.branch||(C.detached?"Detached HEAD":C.name),branch:C.branch,description:co(w,e.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:C,directory:w,folderScopeKey:w,sessions:E.get(w)??[]});return j.length>0&&k.push({id:"archived",label:"archived",branch:null,description:"Archived and unassigned sessions",isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:f?sl(f):null,sessions:j}),k},[e.homeDirectory,e.pinnedSessionIds,e.sessionOrderRanks]);return{buildGroupSearchText:t,buildSessionSearchText:n,filterSessionNodesForSearch:r,buildGroupedSessions:o}},am=({mobileVariant:e,isTablet:t})=>!e&&!t,lm=({enabled:e=!0,isSessionSearchOpen:t,setIsSessionSearchOpen:n,sessionSearchInputRef:r,sessionSearchContainerRef:o})=>{a.useEffect(()=>{if(!e||!t||typeof window>"u")return;const i=window.requestAnimationFrame(()=>{r.current?.focus(),r.current?.select()});return()=>window.cancelAnimationFrame(i)},[e,t,r]),a.useEffect(()=>{if(!e||!t||typeof document>"u")return;const i=l=>{o.current&&(o.current.contains(l.target)||n(!1))};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[e,t,n,o])},cm=e=>{const[t,n]=a.useState(null),r=a.useRef(null);a.useEffect(()=>()=>{r.current&&clearTimeout(r.current)},[]);const o=a.useCallback((v,E,j)=>{uo("navigation.session_select"),le.getState().closeMainSurfaces();const k=()=>{!e.isSessionSearchOpen&&e.sessionSearchQuery.length===0||(e.setSessionSearchQuery(""),e.setIsSessionSearchOpen(!1))},C=j?.keepPanelOpen!==!0;if(e.mobileVariant&&(e.setActiveMainTab("chat"),e.setSessionSwitcherOpen(!1)),v===Te.getState().currentSessionId){e.allowReselect&&C&&e.onSessionSelected?.(v),k();return}uo("navigation.session_state_set"),e.setCurrentSession(v,E??null),C&&e.onSessionSelected?.(v),k()},[e]),i=a.useCallback((v,E)=>{e.setEditingId(v),e.setEditTitle(E)},[e]),l=a.useCallback(async v=>{if(!e.editingId)return;const E=(v??e.editTitle).trim();E&&await e.updateSessionTitle(e.editingId,E),e.setEditingId(null),e.setEditTitle("")},[e]),c=a.useCallback(()=>{e.setEditingId(null),e.setEditTitle("")},[e]),d=a.useCallback(async(v,E)=>{try{return(await ys(v)).ok?(n(E),r.current&&clearTimeout(r.current),r.current=window.setTimeout(()=>{n(null),r.current=null},2e3),!0):!1}catch{return!1}},[]),u=a.useCallback(async v=>{const E=await e.shareSession(v.id);if(!E?.share?.url){ie.error("Unable to share session");return}const j=await d(E.share.url,v.id);ie[j?"success":"warning"]("Session shared",{description:j?"Share link copied to clipboard.":"Failed to copy URL"})},[e,d]),f=a.useCallback((v,E)=>{d(v,E).then(j=>{j||ie.error("Failed to copy URL")})},[d]),p=a.useCallback(v=>{ys(v).then(E=>{if(E.ok){ie.success("Session ID copied");return}ie.error("Failed to copy session ID")}).catch(()=>ie.error("Failed to copy session ID"))},[]),x=a.useCallback(async v=>{await e.unshareSession(v)?ie.success("Session unshared"):ie.error("Unable to unshare session")},[e]),y=a.useCallback(v=>{const E=[],j=k=>{(e.childrenMap.get(k)??[]).forEach(w=>{E.push(w),j(w.id)})};return j(v),E},[e.childrenMap]),m=a.useCallback((v,E)=>E?v:v.filter(j=>!j.time?.archived),[]),h=a.useCallback(async(v,E,j)=>{const k=E?.archivedBucket===!0||E?.hardDelete===!0,C=j?.descendantIds??m(y(v.id),k).map(O=>O.id);if(C.length===0){(k?await e.deleteSession(v.id):await e.archiveSession(v.id))?ie.success(k?"Session deleted":"Session archived"):ie.error(k?"Failed to delete session":"Failed to archive session");return}const w=[v.id,...C];if(k){const{deletedIds:O,failedIds:$}=await e.deleteSessions(w);if($.length===0){const U=O.length;ie.success(U===1?`Deleted ${U} session`:`Deleted ${U} sessions`)}else ie.error("Failed to delete session");return}const{archivedIds:N,failedIds:T}=await e.archiveSessions(w);N.length>0&&ie.success(N.length===1?`Archived ${N.length} session`:`Archived ${N.length} sessions`),T.length>0&&ie.error(T.length===1?`Failed to archive ${T.length} session`:`Failed to archive ${T.length} sessions`)},[e,y,m]),b=a.useCallback((v,E)=>{const j=E?.archivedBucket===!0||E?.hardDelete===!0,k=m(y(v.id),j).map(C=>C.id);if(!e.showDeletionDialog||E?.skipConfirm===!0){h(v,E,{descendantIds:k});return}e.setDeleteSessionConfirm({session:v,descendantCount:k.length,descendantIds:k,archivedBucket:j})},[e,y,h,m]),g=a.useCallback(async()=>{if(!e.deleteSessionConfirm)return;const{session:v,archivedBucket:E,descendantIds:j}=e.deleteSessionConfirm;e.setDeleteSessionConfirm(null),await h(v,{archivedBucket:E},{descendantIds:j})},[e,h]),S=a.useCallback(async v=>{await e.unarchiveSession(v.id)?ie.success("Session restored"):ie.error("Failed to restore session")},[e]);return{copiedSessionId:t,handleSessionSelect:o,handleSessionDoubleClick:i,handleSaveEdit:l,handleCancelEdit:c,handleShareSession:u,handleCopyShareUrl:f,handleCopySessionId:p,handleUnshareSession:x,handleDeleteSession:b,handleRestoreSession:S,confirmDeleteSession:g}},dm=e=>{const{safeStorage:t,keys:n,groupOrderByProject:r,collapsedGroups:o,setExpandedParents:i,setCollapsedProjects:l}=e,c=a.useRef(null),d=a.useRef(null),u=a.useCallback(()=>{const p=d.current;if(d.current=null,c.current=null,!p)return;const{projects:x}=ut.getState(),y=x.map(m=>({...m,sidebarCollapsed:p.has(m.id)}));Qa({projects:y}).catch(()=>{})},[]),f=a.useCallback(p=>{typeof window>"u"||(d.current=p,c.current!==null&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>{u()},700))},[u]);return a.useEffect(()=>()=>{typeof window<"u"&&c.current!==null&&window.clearTimeout(c.current),c.current=null,d.current=null},[]),a.useEffect(()=>{try{const p=t.getItem(n.sessionExpanded);if(p){const y=JSON.parse(p);Array.isArray(y)&&i(new Set(y.filter(m=>typeof m=="string")))}const x=t.getItem(n.projectCollapse);if(x){const y=JSON.parse(x);Array.isArray(y)&&l(new Set(y.filter(m=>typeof m=="string")))}}catch{}},[n.projectCollapse,n.sessionExpanded,t,l,i]),a.useEffect(()=>{try{const p=Object.fromEntries(r.entries());t.setItem(n.groupOrder,JSON.stringify(p))}catch{}},[r,n.groupOrder,t]),a.useEffect(()=>{try{t.setItem(n.groupCollapse,JSON.stringify(Array.from(o)))}catch{}},[o,n.groupCollapse,t]),{scheduleCollapsedProjectsPersist:f}},um=3;let hr=0;const Il=[],fm=()=>hr<um?(hr+=1,Promise.resolve()):new Promise(e=>{Il.push(e)}),hm=()=>{const e=Il.shift();if(e){e();return}hr=Math.max(0,hr-1)},mm=async e=>{await fm();try{return await e()}finally{hm()}},pm=5*6e4,gm=e=>{const{normalizedProjects:t,enabled:n=!0,gitRepoStatus:r,setProjectRepoStatus:o,setProjectRootBranches:i}=e,{git:l}=Fs(),c=Ba(m=>m.ensureStatus),d=a.useMemo(()=>t.map(m=>m.normalizedPath).slice().sort().join("\0"),[t]),u=a.useRef(null);a.useEffect(()=>{if(!n||!l||t.length===0){u.current=null,o(new Map);return}const m=`${Mt()}\0${d}`;u.current!==m&&(u.current=m,t.forEach(h=>{mm(()=>c(h.normalizedPath,l))}))},[n,t,d,l,c,o]);const f=a.useRef(null);a.useEffect(()=>{if(!n){f.current=null;return}const m=new Map;t.forEach(b=>{m.set(b.id,r.get(b.normalizedPath)?.isGitRepo??null)});const h=t.map(b=>`${b.id}:${String(m.get(b.id))}`).join("|");f.current!==h&&(f.current=h,o(m))},[n,t,d,r,o]);const p=a.useMemo(()=>t.map(m=>{const h=r.get(m.normalizedPath)?.branch??"";return`${m.id}:${h}`}).join("|"),[t,r]),x=a.useRef(new Map),y=a.useRef(new Map);a.useEffect(()=>{if(!n)return;let m=!1;const h=setTimeout(()=>{(async()=>{const g=new Set(t.map(k=>k.id));for(const k of x.current.keys())g.has(k)||(x.current.delete(k),y.current.delete(k));const S=Date.now();if(t.filter(k=>{const C=r.get(k.normalizedPath);if(C?.isGitRepo===!1)return x.current.delete(k.id),y.current.delete(k.id),!1;if(C?.isGitRepo!==!0||C.branch===null)return!1;const w=C.branch.trim(),N=`${k.normalizedPath}\0${w}`,T=x.current.get(k.id);if(T===N){const O=y.current.get(k.id);return O&&(O.at=S),!1}return!(T!==void 0&&S-(y.current.get(k.id)?.at??0)<pm)}).length===0)return;const E=[];if(t.forEach(k=>{const C=r.get(k.normalizedPath)?.branch?.trim()??"",w=`${k.normalizedPath}\0${C}`;C&&E.push({id:k.id,inputKey:w,branch:C})}),m||E.length===0)return;const j=Date.now();i(k=>{const C=new Map(k);return E.forEach(({id:w,branch:N})=>{N&&C.set(w,N)}),C}),E.forEach(({id:k,inputKey:C,branch:w})=>{x.current.set(k,C),w&&y.current.set(k,{branch:w,at:j})})})()},150);return()=>{m=!0,clearTimeout(h)}},[n,t,p,r,i])},bm=e=>{const{ownership:t}=e,n=a.useCallback(o=>t.sessionsByProject.get(o)??[],[t]),r=a.useCallback(o=>t.archivedSessionsByProject.get(o)??[],[t]);return{getSessionsForProject:n,getArchivedSessionsForProject:r}},xm=e=>{const t=new Map;for(const n of e){const r=Nn(n);r&&t.set(n.id,{directory:r,sessionId:n.id})}return t},ym=(e,t)=>{if(!e)return[];const n=[];return e.forEach((r,o)=>{t.has(o)||n.push(r)}),n},wm=e=>{const{enabled:t=!0,hasAuthoritativeGlobalSessions:n,sessions:r}=e,o=a.useRef(null);a.useEffect(()=>{if(!t||!n)return;const i=Mt(),l=xm(r),c=o.current?.runtimeKey===i?o.current.identities:null;for(const d of ym(c,l))Ys().commitMissedDeletion(d.sessionId,d.directory);o.current={runtimeKey:i,identities:l}},[t,n,r])},vm=(e,t)=>e?t.kind!==e.kind?t.kind==="project":t.projectRoot.length!==e.projectRoot.length?t.projectRoot.length>e.projectRoot.length:t.projectId.localeCompare(e.projectId)<0:!0,Ui=(e,t,n)=>{vm(e.get(t),n)&&e.set(t,n)},El=e=>{const t=e;return Ie(t.directory)??Ie(t.project?.worktree)},Sm=(e,t,n)=>{if(e.time?.archived)return!0;const r=El(e);if(!r)return n?.allowUnknownDirectory??!0;if(wr(r,n?.homeDirectory))return!0;if(t.size===0)return n?.allowEmptyDirectorySet??!0;const o=r.toLowerCase();for(const i of t)if(Ie(i)?.toLowerCase()===o)return!0;return!1},jm=e=>{if(e==="/"||/^[A-Z]:$/.test(e))return null;const t=e.lastIndexOf("/");return t<0?null:t===0?"/":t===2&&/^[A-Z]:\//.test(e)?e.slice(0,2):e.slice(0,t)},Cm=(e,t,n,r=[])=>{const o=new Map,i=new Map;for(const y of t){const m=Ie(y.normalizedPath);if(!m)continue;const h=i.get(m);(!h||y.id.localeCompare(h.id)<0)&&i.set(m,y),Ui(o,m,{projectId:y.id,projectRoot:m,scopeDirectory:m,kind:"project"})}if(n)for(const[y,m]of n){const h=Ie(y),b=h?i.get(h):void 0;if(!(!b||!h))for(const g of m||[]){const S=Ie(g?.path);S&&Ui(o,S,{projectId:b.id,projectRoot:h,scopeDirectory:S,kind:"worktree"})}}const l=new Map,c=new Map,d=new Map,u=new Map,f=new Map,p=y=>{if(!y)return null;if(l.has(y))return l.get(y)??null;const m=[];let h=y,b=null;for(;h;){if(l.has(h)){b=l.get(h)??null;break}if(m.push(h),b=o.get(h)??null,b)break;h=jm(h)}for(const g of m)l.set(g,b);return b},x=(y,m,h)=>{for(const b of y){const g=El(b);if(wr(g))continue;const S=p(g);if(!S)continue;c.set(b.id,S);const v=m.get(S.projectId);if(v?v.push(b):m.set(S.projectId,[b]),!h)continue;const E=h.get(S.scopeDirectory);E?E.add(b.id):h.set(S.scopeDirectory,new Set([b.id]))}};return x(e,d,f),x(r,u),{bySessionId:c,sessionsByProject:d,archivedSessionsByProject:u,sessionsByScope:f,directoryResolutions:l.size}};function Rl({state:e,activeLabel:t,unreadLabel:n,className:r}){return e==="unread"?s.jsx("span",{className:_("inline-flex items-center",r),"aria-label":n??t,title:n??t,children:s.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-foreground"})}):s.jsx("span",{className:_("inline-flex items-center",r),"aria-label":t,title:t,children:s.jsx(ws,{variant:"inline",text:null,animationType:"spinner",speedMs:80,className:"text-primary text-xs shrink-0"})})}const km=({folder:e,displayName:t,sessions:n,subFolderItems:r,isCollapsed:o,collapsedActivityState:i=null,onToggle:l,onRename:c,onDelete:d,renderSessionNode:u,getRenderExtras:f,groupDirectory:p,projectId:x,mobileVariant:y=!1,alwaysShowActions:m=y,isRenaming:h=!1,renameDraft:b="",onRenameDraftChange:g,onRenameSave:S,onRenameCancel:v,droppableRef:E,isDropTarget:j=!1,onNewSession:k,depth:C=0,hideActions:w=!1,archivedBucket:N=!1})=>{const[T,O]=a.useState(!1),[$,U]=a.useState(""),K=a.useRef(null),L=h||T,D=h?b:$,R=a.useCallback(()=>{U(e.name),O(!0)},[e.name]),I=a.useCallback(()=>{const B=D.trim();B&&B!==e.name&&c(B),h&&S&&S(),O(!1),U("")},[D,e.name,h,c,S]),M=a.useCallback(()=>{h&&v&&v(),O(!1),U("")},[h,v]),W=a.useCallback(B=>{h&&g?g(B):U(B)},[h,g]);a.useEffect(()=>{if(!h)return;const B=()=>{const je=K.current;je&&(je.focus(),je.select())},xe=requestAnimationFrame(B),V=window.setTimeout(B,0);return()=>{cancelAnimationFrame(xe),window.clearTimeout(V)}},[h]);const G=o?"folder":"folder-open";return s.jsxs("div",{className:"oc-folder",children:[s.jsxs("div",{ref:E,className:_("group/folder relative flex items-center justify-between gap-2 px-3 py-1.5 min-w-0 rounded-lg transition-colors","cursor-pointer hover:bg-interactive-hover",j&&"bg-primary/10 ring-1 ring-inset ring-primary/30"),onClick:L?void 0:B=>{B.currentTarget.blur(),l()},role:L?void 0:"button",tabIndex:L?void 0:0,onKeyDown:L?void 0:B=>{(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),l())},"aria-label":o?`Expand folder ${e.name}`:`Collapse folder ${e.name}`,children:[s.jsxs("div",{className:_("min-w-0 flex items-center gap-1.5 flex-1 transition-[padding]",N?m?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":m?"pr-20":"group-hover/folder:pr-20 group-focus-within/folder:pr-20"),children:[s.jsx(P,{name:G,className:_(tr,j?"text-primary":"text-muted-foreground")}),L?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:B=>B.stopPropagation(),onMouseDown:B=>B.stopPropagation(),onSubmit:B=>{B.preventDefault(),I()},children:[s.jsx("input",{ref:K,value:D,onChange:B=>W(B.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:"Folder name",onClick:B=>B.stopPropagation(),onPointerDown:B=>B.stopPropagation(),onMouseDown:B=>B.stopPropagation(),onKeyDown:B=>{if(B.key==="Escape"){B.stopPropagation(),M();return}(B.key===" "||B.key==="Enter")&&B.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:B=>B.stopPropagation(),onPointerDown:B=>B.stopPropagation(),onMouseDown:B=>B.stopPropagation(),children:s.jsx(P,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:B=>{B.stopPropagation(),M()},onPointerDown:B=>B.stopPropagation(),onMouseDown:B=>B.stopPropagation(),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("span",{className:_(rl,j?"text-primary":"text-muted-foreground"),children:t??e.name})}),s.jsx(Ke,{side:"right",sideOffset:8,className:"max-w-xs",children:t??e.name})]}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",n.length]}),i?s.jsx(Rl,{state:i,activeLabel:"Session active",unreadLabel:"Unread updates"}):null,o?s.jsx(P,{name:"arrow-right-s",className:_(tr,"text-muted-foreground")}):s.jsx(P,{name:"arrow-down-s",className:_(tr,"text-muted-foreground")})]})]}),!L&&(!w||N)?s.jsx("div",{className:_("absolute right-0.5 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",m?"opacity-100":"opacity-0 pointer-events-none group-hover/folder:opacity-100 group-hover/folder:pointer-events-auto group-focus-within/folder:opacity-100 group-focus-within/folder:pointer-events-auto"),children:s.jsxs("div",{className:"flex items-center gap-0.5",children:[!N&&k?s.jsx("button",{type:"button",onClick:B=>{B.stopPropagation(),k()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`New session in ${e.name}`,title:"New session",children:s.jsx(P,{name:"add",className:"size-4"})}):null,N?null:s.jsx("button",{type:"button",onClick:B=>{B.stopPropagation(),R()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Rename folder ${e.name}`,children:s.jsx(P,{name:"pencil-ai",className:"size-4"})}),s.jsx("button",{type:"button",onClick:B=>{B.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":N?`Delete archived sessions in folder ${e.name}`:`Delete folder ${e.name}`,children:s.jsx(P,{name:"delete-bin",className:"size-4"})})]})}):null]}),o?null:s.jsxs("div",{className:"pb-1",children:[r,n.length>0?n.map(B=>s.jsx(a.Fragment,{children:u(B,0,p??null,x??null,N,void 0,"project",f?.(B))},B.session.id)):r?null:s.jsx("div",{className:"py-1 px-3 text-left typography-micro text-muted-foreground/70",children:"Empty folder"})]})]})},Am=a.memo(km),Nm=({sessionId:e,sessionDirectory:t,sessionTitle:n,children:r})=>{const{attributes:o,listeners:i,setNodeRef:l,isDragging:c}=Td({id:`session-drag:${e}`,data:{type:"session",sessionId:e,sessionDirectory:t,sessionTitle:n}}),d=a.useCallback(u=>{u.stopPropagation(),i?.onPointerDown&&i.onPointerDown(u)},[i]);return s.jsx("div",{ref:l,...o,onPointerDown:d,className:c?"opacity-30":void 0,children:r})},Im=({folderId:e,children:t})=>{const{setNodeRef:n,isOver:r}=Fd({id:`folder-drop:${e}`,data:{type:"folder",folderId:e}});return s.jsx(s.Fragment,{children:t(n,r)})},Em=({scopeKey:e,hasFolders:t,onSessionDroppedOnFolder:n,children:r})=>{const o=Oo(Pn(Pd,{activationConstraint:{distance:8}})),[i,l]=a.useState(null),[c,d]=a.useState("Session"),[u,f]=a.useState(null),[p,x]=a.useState(null);if(!e)return s.jsx(s.Fragment,{children:r});const y=m=>{l(null),f(null),x(null);const{active:h,over:b}=m;if(!b)return;const g=h.data.current,S=b.data.current;g?.type==="session"&&g.sessionId&&S?.type==="folder"&&S.folderId&&n(g.sessionId,S.folderId)};return s.jsxs(Bo,{sensors:o,collisionDetection:_o,onDragStart:m=>{const h=m.active.data.current;if(h?.type==="session"&&h.sessionId){l(h.sessionId),d(h.sessionTitle??"Session");const b=m.active.rect.current.initial?.width,g=m.active.rect.current.initial?.height;f(typeof b=="number"?b:null),x(typeof g=="number"?g:null)}},onDragCancel:()=>{l(null),f(null),x(null)},onDragEnd:y,children:[r,s.jsx(Md,{children:i&&t?s.jsxs("div",{style:{width:u?`${u}px`:"auto",height:p?`${p}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-1 shadow-none pointer-events-none",children:[s.jsx(P,{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:c})]}):null})]})},jr="gap-2",Dl="my-0.5 rounded-lg py-1.5",qo=a.createContext("card"),ts=({icon:e,children:t,onClick:n,className:r,mobileVariant:o=!1})=>{const i=a.useContext(qo)==="tree";return s.jsxs("button",{type:"button",onClick:n,"data-sidebar-tree-row":i?"":void 0,className:_(o?mf:pf,i&&jr,i&&Dl,r),children:[s.jsx(P,{name:e,className:_(Ms(o),"text-muted-foreground")}),s.jsx("span",{className:_(nn(o),"flex-1 text-muted-foreground"),children:t})]})},$i=(e,t,n)=>{if(!t)return;const r=o=>{let i=o.session.id===t;for(const l of o.children)i=r(l)||i;return i&&n.add(o.session.id),i};for(const o of e)r(o)},cs=(e,t)=>{if(!t)return!1;if(e.session.id===t)return!0;for(const n of e.children)if(cs(n,t))return!0;return!1},Rm=(e,t)=>{const n=new Set(e);return e.map(r=>t.get(r)).filter(r=>{if(!r)return!1;const o=new Set;let i=r.session.parentID??null;for(;i&&!o.has(i);){if(n.has(i)&&t.has(i))return!1;o.add(i),i=t.get(i)?.session?.parentID??null}return!0})},Ki=new WeakMap;let Wi=1;const Dm=e=>{const t=Ki.get(e);if(t!==void 0)return t;const n=Wi;return Wi+=1,Ki.set(e,n),n},ko=e=>e.children.length===0?"":e.children.map(n=>{const r=Dm(n.session);return n.children.length===0?`${n.session.id}@${r}`:`${n.session.id}@${r}:${ko(n)}`}).join("|"),Pl=(e,t,n,r,o,i)=>{const l=Mt(),c=(d,u)=>{if(d.session.id!==u.session.id||d.children.length!==u.children.length)return!0;const f=d.session.directory??o,p=u.session.directory??i,x=ji(l,f??"",d.session.id),y=ji(l,p??"",u.session.id);return(x?n.has(x):!1)!==(y?r.has(y):!1)?!0:d.children.some((m,h)=>c(m,u.children[h]))};return c(e,t)},mr=(e,t,n,r)=>{if(!t)return null;const o=r?"archived":"active";let i=null;const l=c=>{if(`${n}:${o}:${c.session.id}`===t)return i=c.session.id,!0;for(const u of c.children)if(l(u))return!0;return!1};return e.forEach(c=>l(c)),i},Pm=5*6e4,Mm=6e4,Gi=5*6e4,Hi=100,yn=new Map,Vs=new Map,Es=new Map,Zs=new Map,Ln=(e,t)=>{const n=ds((e??"").trim()),r=(t??"").trim();return!n||!r?"":`${Mt()}
|
|
12
|
+
${n}
|
|
13
|
+
${r}`},qi=()=>({pr:null,checks:null,fetchedAt:null,isLoading:!1,stale:!1,error:null}),Tm=e=>{const t=e?.body;return t&&typeof t.kind=="string"?t:{kind:"failed",message:e instanceof Error?e.message:"PR status check failed"}},Fm=e=>{const t=Object.keys(e);if(t.length<=Hi)return e;const n=t.sort((o,i)=>(Zs.get(o)??0)-(Zs.get(i)??0)),r={...e};for(let o=0;o<n.length-Hi;o+=1){const i=n[o];delete r[i],Zs.delete(i),Vs.delete(i);const l=Es.get(i);l!==void 0&&(clearTimeout(l),Es.delete(i))}return r},Ml=e=>e.pr?e.pr.state!=="open"?Gi:e.checks?.state==="pending"?Mm:Gi:Pm,Ao=(e,t,n,r)=>{if(typeof window>"u"||Es.has(e))return;const o=ss.getState().results[e];if(!o)return;const i=Ml(o),l=setTimeout(()=>{if(Es.delete(e),!!ss.getState().results[e]){if(typeof document<"u"&&document.hidden){Ao(e,t,n,r);return}ss.getState().refresh(t,n,r)}},i);typeof l=="object"&&l!==null&&typeof l.unref=="function"&&l.unref(),Es.set(e,l)},ss=Ls()(vr((e,t)=>({results:{},refresh:async(n,r,o,i)=>{const l=ds((n||"").trim()),c=(r||"").trim();if(!l||!c)return null;const d=Ln(l,c);if(!d)return null;const u=yn.get(d);if(u&&!i?.force)return u;const f=o??null;if(!f)return t().results[d]??null;const p=(Vs.get(d)??0)+1;Vs.set(d,p);const x=t().results[d]??qi();e(m=>({results:{...m.results,[d]:{...x,isLoading:!0}}}));const y=(async()=>{try{const m=await f.prStatus(l,c);if(Vs.get(d)!==p||Mt()!==d.split(`
|
|
14
|
+
`)[0])return t().results[d]??null;const h={pr:m.pr??null,checks:m.checks??null,checksStale:m.checksStale,defaultBranch:m.defaultBranch??null,skippedDefaultBranch:m.skippedDefaultBranch,fetchedAt:m.fetchedAt??Date.now(),isLoading:!1,stale:!1,error:null};return Zs.set(d,Date.now()),e(b=>({results:Fm({...b.results,[d]:h})})),Ao(d,l,c,f),h}catch(m){if(Vs.get(d)!==p)return t().results[d]??null;const h=Tm(m),b=x.pr||x.fetchedAt?{...x,isLoading:!1,stale:!0,error:h}:{...qi(),error:h};return e(g=>({results:{...g.results,[d]:b}})),Ao(d,l,c,f),b}})();yn.set(d,y);try{return await y}finally{yn.get(d)===y&&yn.delete(d)}},load:async(n,r,o)=>{const i=ds((n||"").trim()),l=(r||"").trim();if(!i||!l)return null;const c=Ln(i,l);Zs.set(c,Date.now());const d=t().results[c];return d&&(d.pr||d.fetchedAt)?(t().refresh(i,l,o),d):t().refresh(i,l,o)},resetForRuntimeSwitch:()=>{yn.clear(),Vs.clear(),Zs.clear(),Sn=null;for(const n of Es.values())clearTimeout(n);Es.clear(),e({results:{}})}}),{name:"github-pr-status-store"}));typeof window<"u"&&(On(()=>{ss.getState().resetForRuntimeSwitch()}),document.addEventListener("visibilitychange",()=>{document.hidden||(async()=>{const e=await ht(async()=>{const{getRegisteredRuntimeAPIs:r}=await import("./index-BnZVqcki.js").then(o=>o.cy);return{getRegisteredRuntimeAPIs:r}},__vite__mapDeps([2,3,4,5,6,7,8,9])).then(({getRegisteredRuntimeAPIs:r})=>r()?.github??null).catch(()=>null);if(!e)return;const t=Date.now(),n=Object.entries(ss.getState().results).filter(([,r])=>r.fetchedAt&&t-r.fetchedAt>=Ml(r)).map(([r])=>r);for(const r of n){const[,o,i]=r.split(`
|
|
15
|
+
`);if(!(!o||!i)){if(typeof document<"u"&&document.hidden)return;await ss.getState().refresh(o,i,e).catch(()=>null)}}})()}));let Sn=null;const zx=e=>{if(Sn&&Sn.results===e)return Sn.index;const t=new Map;for(const n of Object.values(e)){const r=n.pr?.url;!r||t.has(r)||t.set(r,n.checks?.state??null)}return Sn={results:e,index:t},t},Lm=e=>{const t=e?.pr;if(!t)return null;if(t.state==="merged")return{visualState:"merged",number:t.number,draft:t.draft,title:t.title};if(t.state==="closed")return{visualState:"closed",number:t.number,draft:t.draft,title:t.title};if(t.draft)return{visualState:"draft",number:t.number,draft:!0,title:t.title,mergeableState:t.mergeableState??void 0,checks:e?.checks?{state:e.checks.state}:void 0};const n=e?.checks?.state,r=t.mergeableState??void 0;return r==="dirty"||r==="blocked"||n==="failure"?{visualState:"blocked",number:t.number,draft:!1,title:t.title,mergeableState:r,checks:e?.checks?{state:e.checks.state,total:e.checks.total,failure:e.checks.failure,pending:e.checks.pending,success:e.checks.success}:void 0}:{visualState:"open",number:t.number,draft:!1,title:t.title,mergeableState:r,checks:e?.checks?{state:e.checks.state,total:e.checks.total,failure:e.checks.failure,pending:e.checks.pending,success:e.checks.success}:void 0}},Tl=e=>{const t=ss(n=>e?n.results[e]??null:null);return a.useMemo(()=>Lm(t),[t])},Fl=(e,t,n)=>{const r=a.useMemo(()=>Ln(e,t),[e,t]),o=n??null;a.useEffect(()=>{if(!r||!e?.trim()||!t?.trim())return;let i=!1;return ht(async()=>{const{getRegisteredRuntimeAPIs:l}=await import("./index-BnZVqcki.js").then(c=>c.cy);return{getRegisteredRuntimeAPIs:l}},__vite__mapDeps([2,3,4,5,6,7,8,9])).then(({getRegisteredRuntimeAPIs:l})=>{if(i)return;const c=o??l()?.github??null;c&&ss.getState().load(e,t,c)}).catch(()=>{}),()=>{i=!0}},[r,e,t,o])},Yo=(e,t)=>e==="active"||t==="active"?"active":e==="unread"||t==="unread"?"unread":null,Ll=(e,t,n)=>{if(t.has(e.session.id))return"active";let r=n.has(e.session.id)?"unread":null;for(const o of e.children)if(r=Yo(r,Ll(o,t,n)),r==="active")return r;return r},Ol=(e,t,n)=>{let r=null;for(const o of e)if(r=Yo(r,Ll(o,t,n)),r==="active")return r;return r},Om=50,Bm=28;function _m({visibleSessions:e,shouldVirtualize:t,hasExpandedParent:n,scrollContainerRef:r,groupDirectory:o,projectId:i,isArchivedBucket:l,renderSessionNode:c,getRenderExtras:d}){const u=a.useRef(null),[f,p]=a.useState(null),[x,y]=a.useState(0),[,m]=a.useState(0);a.useEffect(()=>{if(!t)return;const g=u.current;if(!g||typeof ResizeObserver>"u")return;const S=new ResizeObserver(()=>m(v=>v+1));return S.observe(g),()=>S.disconnect()},[t]),a.useLayoutEffect(()=>{if(!t){f!==null&&p(null),x!==0&&y(0);return}const g=u.current;if(!g)return;let S=f;const v=r?.current??null;if(v&&v.contains(g)){if(S=v,S!==f){p(S);return}}else if(!S||!S.contains(g)){let j=g.parentElement;for(;j;){const k=window.getComputedStyle(j);if(k.overflowY==="auto"||k.overflowY==="scroll"){S=j;break}j=j.parentElement}if(S!==f){p(S);return}}if(!S)return;const E=g.getBoundingClientRect().top-S.getBoundingClientRect().top+S.scrollTop;y(j=>Math.abs(j-E)<1?j:E)},[f,x,r,t]);const h=t&&f!==null,b=Ld({count:e.length,enabled:h,getScrollElement:()=>f,initialOffset:()=>f?.scrollTop??0,estimateSize:()=>Bm,overscan:n?20:8,scrollMargin:x,getItemKey:g=>e[g]?.session.id??g});return s.jsx("div",{ref:u,children:t?s.jsx("div",{style:{height:b.getTotalSize(),position:"relative"},children:b.getVirtualItems().map(g=>{const S=e[g.index];return S?s.jsx("div",{"data-index":g.index,ref:b.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${g.start-x}px)`},children:c(S,0,o,i,l,void 0,"project",d(S))},S.session.id):null})}):e.map(g=>s.jsx(a.Fragment,{children:c(g,0,o,i,l,void 0,"project",d(g))},g.session.id))})}const nr=(e,t)=>{if(!t)return e;const n=e.toLowerCase(),r=t.toLowerCase(),o=r.length;if(o===0)return e;const i=[];let l=0,c=n.indexOf(r,l);for(;c!==-1;){c>l&&i.push(e.slice(l,c));const d=e.slice(c,c+o);i.push(s.jsx("mark",{className:"bg-primary text-primary-foreground ring-1 ring-primary/90",children:d},`${c}-${d}`)),l=c+o,c=n.indexOf(r,l)}return l<e.length&&i.push(e.slice(l)),i.length>0?i:e},cn=e=>[Mt(),...e.map(t=>(t??"").toString())].join(`
|
|
16
|
+
`),Yn=e=>{const t=e?.body;return t&&typeof t.kind=="string"?t:{kind:"failed",message:e instanceof Error?e.message:"GitHub request failed"}},zm=200,Js=(e={})=>{const t=e.maxEntries??zm,n=new Map,r=new Map,o=new Map;let i=0;const l=new Map,c=new Map,d=h=>{const b=n.get(h)??null;return b&&l.set(h,i+=1),b},u=h=>{const b=c.get(h);if(b)for(const g of[...b])try{g()}catch{}},f=()=>{if(n.size<=t)return;const h=[...n.keys()].filter(g=>!r.has(g)&&(c.get(g)?.size??0)===0).sort((g,S)=>(l.get(g)??0)-(l.get(S)??0)),b=n.size-t;for(let g=0;g<b&&g<h.length;g+=1){const S=h[g];n.delete(S),l.delete(S),o.set(S,(o.get(S)??0)+1)}};let p=!1;const x=()=>{if(p||n.size<=t)return;p=!0;const h=()=>{p=!1,f()};typeof queueMicrotask=="function"?queueMicrotask(h):setTimeout(h,0)},y=(h,b)=>{const S={...n.get(h)??{data:null,fetchedAt:null,isLoading:!1,stale:!1,error:null,generation:o.get(h)??0},...b};return n.set(h,S),l.set(h,i+=1),x(),u(h),S},m=async(h,b)=>{const g=r.get(h);if(g)return g;const S=(o.get(h)??0)+1;o.set(h,S);const v=n.get(h);y(h,{isLoading:!0,generation:S});const E=(async()=>{try{const j=await b();return o.get(h)!==S?n.get(h)??{data:j,fetchedAt:Date.now(),isLoading:!1,stale:!1,error:null,generation:S}:y(h,{data:j,fetchedAt:Date.now(),isLoading:!1,stale:!1,error:null,generation:S})}catch(j){return o.get(h)!==S?n.get(h)??{data:v?.data??null,fetchedAt:v?.fetchedAt??null,isLoading:!1,stale:!0,error:Yn(j),generation:S}:v?.data!=null?y(h,{isLoading:!1,stale:!0,error:Yn(j),generation:S}):y(h,{data:null,fetchedAt:null,isLoading:!1,stale:!1,error:Yn(j),generation:S})}})();r.set(h,E);try{return await E}finally{r.get(h)===E&&r.delete(h),e.onSettle?.(h)}};return{getEntry:d,snapshot:()=>Object.fromEntries(n),subscribe:(h,b)=>{let g=c.get(h);return g||(g=new Set,c.set(h,g)),g.add(b),()=>{const S=c.get(h);S&&(S.delete(b),S.size===0&&c.delete(h))}},ensure:(h,b,g)=>!g?.force&&r.has(h)?r.get(h):!g?.force&&n.get(h)?.data!=null&&n.get(h)?.isLoading?r.get(h)??Promise.resolve(n.get(h)):!g?.force&&n.get(h)?.data!=null?(m(h,b),Promise.resolve(n.get(h))):m(h,b),refresh:(h,b)=>m(h,b),invalidate:async(h,b,g)=>{if(g?.exact??!0)return o.set(h,(o.get(h)??0)+1),n.delete(h),l.delete(h),r.has(h)&&r.delete(h),u(h),b?m(h,b):null;for(const v of[...n.keys()])(v===h||v.startsWith(h))&&(o.set(v,(o.get(v)??0)+1),n.delete(v),l.delete(v),r.delete(v),u(v));return null},markStale:h=>{const b=n.get(h);b?.data&&(b.stale||y(h,{stale:!0}))},setError:(h,b)=>{const g=n.get(h);return g?.data?y(h,{isLoading:!1,stale:!0,error:Yn(b)}):g??null},remove:h=>{o.set(h,(o.get(h)??0)+1),n.delete(h),l.delete(h),r.delete(h),u(h)},reset:()=>{const h=[...n.keys()];n.clear(),r.clear(),o.clear(),l.clear();for(const b of h)u(b)}}},dn=(e,t)=>Ee.useSyncExternalStore(n=>t?e.subscribe(t,n):()=>{},()=>t?e.getEntry(t):null,()=>t?e.getEntry(t):null),Ux=e=>{const t=e.trim().match(/^#?(\d{1,7})$/);if(!t)return null;const n=Number(t[1]);return Number.isSafeInteger(n)&&n>0?n:null},Bl=(e,t)=>!e||!t?!1:e.toLowerCase()===t.toLowerCase(),No=e=>{if(!e)return[];const t=[];for(const n of e)n?.login&&t.push(n.login.toLowerCase());return t},_l=e=>{const t=[],n=[];for(const r of e.trim().toLowerCase().split(/\s+/))r&&(r.startsWith("label:")&&r.length>6?n.push(r.slice(6)):t.push(r));return{tokens:t,labelTokens:n}},Vo=e=>{if(!e)return[];const t=[];for(const n of e)n?.name&&t.push(n.name.toLowerCase());return t},zl=(e,t,n)=>{const r=Vo(e??null),o=t.split(",").map(i=>i.trim().toLowerCase()).filter(Boolean);for(const i of[...o,...n])if(!r.some(l=>l===i||l.includes(i)))return!1;return!0},Um=e=>{const t=[e.title.toLowerCase(),`#${e.number}`,`${e.number}`,e.author?.login?.toLowerCase()??"",e.head.toLowerCase(),e.base.toLowerCase()];for(const n of Vo(e.labels))t.push(n);return t},$m=e=>{const t=[e.title.toLowerCase(),`#${e.number}`,`${e.number}`,e.author?.login?.toLowerCase()??""];for(const n of Vo(e.labels))t.push(n);return t},Ul=(e,t)=>{for(const n of t){let r=!1;for(const o of e)if(o.includes(n)){r=!0;break}if(!r)return!1}return!0},Yi=e=>e.state==="merged"||!!e.mergedAt,Km=(e,t)=>t==="all"?e:t==="open"?e.filter(n=>n.state==="open"):t==="merged"?e.filter(n=>Yi(n)):e.filter(n=>n.state==="closed"&&!Yi(n)),Wm=(e,t)=>t==="all"?e:e.filter(n=>n.state===t),Gm=(e,t,n)=>t==="all"||!n?!0:t==="mine"?Bl(e.author?.login,n):t==="review"?No(e.requestedReviewers).includes(n.toLowerCase()):No(e.assignees).includes(n.toLowerCase()),Hm=(e,t,n)=>t==="all"||!n||t==="mentioned"?!0:t==="mine"?Bl(e.author?.login,n):No(e.assignees).includes(n.toLowerCase()),Gs=e=>{if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0},$l=(e,t)=>{const n=[...e];return t==="newest"?(n.sort((r,o)=>Gs(o.createdAt)-Gs(r.createdAt)||o.number-r.number),n):t==="oldest"?(n.sort((r,o)=>Gs(r.createdAt)-Gs(o.createdAt)||r.number-o.number),n):(n.sort((r,o)=>Gs(o.updatedAt)-Gs(r.updatedAt)||o.number-r.number),n)},$x=(e,t)=>{const{tokens:n,labelTokens:r}=_l(t.search),o=[];for(const i of Km(e,t.state))Gm(i,t.involvement,t.viewerLogin)&&zl(i.labels,"",r)&&Ul(Um(i),n)&&o.push(i);return $l(o,t.sort)},Kx=(e,t)=>{const{tokens:n,labelTokens:r}=_l(t.search),o=[];for(const i of Wm(e,t.state))Hm(i,t.involvement,t.viewerLogin)&&zl(i.labels,t.labels,r)&&Ul($m(i),n)&&o.push(i);return $l(o,t.sort)},Vn=(e,t)=>{if(t.length===0)return e;const n=new Map;for(const i of t)n.set(i.number,i);const r=e.map(i=>n.get(i.number)??i),o=new Set(e.map(i=>i.number));for(const i of t)o.has(i.number)||r.push(i);return r},Wx=(e,t)=>e.filter(n=>!t.has(n.number)),qm=(e,t)=>{if(t.length===0)return e;const n=new Set(e.map(o=>o.id)),r=[...e];for(const o of t)n.has(o.id)||(n.add(o.id),r.push(o));return r},Vi=Object.freeze({repo:null,number:null}),Ur=e=>e.split(`
|
|
17
|
+
`)[1]??"",Io=(e,t)=>`${ds(e)}
|
|
18
|
+
${t}`,wn=(e,t)=>`${e}#${t}`,Ym=(e,t)=>{const n=e?.body;return n&&typeof n.kind=="string"?n:{kind:"failed",message:e instanceof Error?e.message:t}},ks=async(e,t)=>{if(e)try{await e.invalidate(t)}catch{}},Qi=(e,t)=>!e?.data||!e.fetchedAt?!1:Date.now()-e.fetchedAt<t,Ji=10,Vm=(e,t)=>{const n=Js(),r=Js({maxEntries:60}),o=Js(),i=Js(),l=new Map,c=new Map,d=async(L,D)=>{const R=c.get(L);if(R)return await R.catch(()=>null),{ran:!1,result:null};const I=D();c.set(L,I);try{return{ran:!0,result:await I}}finally{c.get(L)===I&&c.delete(L)}},u=(L,D)=>{if(D.length===0)return;const R=e.collectionKeyFor(L,e.openCollection);let I=l.get(R);I||(I=new Map,l.set(R,I));for(const M of D)I.set(M.number,M)},f=L=>{const D=Object.keys(r.snapshot()).filter(I=>Ur(I)===L&&!r.getEntry(I)?.isLoading);if(D.length<=Ji)return;const R=D.map(I=>({key:I,fetchedAt:r.getEntry(I)?.data?.fetchedAt??0})).sort((I,M)=>I.fetchedAt-M.fetchedAt);for(let I=0;I<R.length-Ji;I+=1)r.remove(R[I].key)},p=L=>{const D=n.getEntry(e.collectionKeyFor(L,e.openCollection))?.data?.items??[],R=n.getEntry(e.collectionKeyFor(L,e.closedCollection))?.data?.items??[],I=Vn(D,R),M=l.get(e.collectionKeyFor(L,e.openCollection));return!M||M.size===0?I:Vn(I,[...M.values()])},x=(L,D,R)=>{const I=Io(L,D),M=t.get().filtersByScope[I]??e.defaultFilters;t.set(W=>({filtersByScope:{...W.filtersByScope,[I]:{...M,...R}}}))},y=(L,D)=>{const R=Io(L,D);t.set(I=>({filtersByScope:{...I.filtersByScope,[R]:{...e.defaultFilters}}}))},m=(L,D,R)=>{const I=ds(L);I&&t.set(M=>({selectionByDirectory:{...M.selectionByDirectory,[I]:{repo:D,number:R}}}))},h=(L,D,R,I)=>{const M=e.collectionKeyFor(D,R);return n.ensure(M,async()=>{const W=await e.fetchList(I,L,D,e.buildCollectionQuery(R));return{items:W.items,nextCursor:W.nextCursor,fetchedAt:W.fetchedAt}})},b=(L,D,R)=>{const I=e.collectionKeyFor(D,e.closedCollection);n.getEntry(I)?.data||n.getEntry(I)?.isLoading||h(L,D,e.closedCollection,R).catch(()=>null)},g=async(L,D,R,I)=>{const M=R==="open"||R==="both",W=R==="closed"||R==="both",G=[],B=n.getEntry(e.collectionKeyFor(D,e.openCollection)),xe=n.getEntry(e.collectionKeyFor(D,e.closedCollection));M&&(!Qi(B,e.freshWindowMs)||B?.stale)&&G.push(h(L,D,e.openCollection,I)),W&&(!Qi(xe,e.freshWindowMs)||xe?.stale)&&G.push(h(L,D,e.closedCollection,I)),await Promise.all(G.map(V=>V.catch(()=>null))),M&&!n.getEntry(e.collectionKeyFor(D,e.closedCollection))?.data&&b(L,D,I)},S=async(L,D,R,I)=>{const M=e.collectionKeyFor(D,R),W=n.getEntry(M),G=W?.data?.nextCursor??null;if(!G||W?.isLoading)return W;try{const B=await d(`${M}:more`,async()=>{const xe=await e.fetchList(I,L,D,{...e.buildCollectionQuery(R),cursor:G}),V=n.getEntry(M)?.data,je={items:Vn(V?.items??[],xe.items),nextCursor:xe.nextCursor,fetchedAt:xe.fetchedAt};return n.refresh(M,async()=>je)});return B.ran?B.result??n.getEntry(M):n.getEntry(M)}catch(B){return n.setError(M,B)??n.getEntry(M)}},v=async(L,D,R,I)=>{const M=R==="both"?[e.openCollection,e.closedCollection]:[R];await Promise.all(M.map(W=>{const G=e.collectionKeyFor(D,W);return n.refresh(G,async()=>{const B=await e.fetchList(I,L,D,e.buildCollectionQuery(W));return{items:B.items,nextCursor:B.nextCursor,fetchedAt:B.fetchedAt}}).catch(()=>null)}))},E=async(L,D,R,I)=>{const M=e.remoteKeyFor(D,R),W=await r.refresh(M,async()=>{const G=await e.fetchList(I,L,D,e.buildRemoteQuery(R));return{items:G.items,nextCursor:G.nextCursor,fetchedAt:G.fetchedAt}});return W.data&&(u(D,W.data.items),f(D)),W},j=async(L,D,R,I)=>{const M=e.remoteKeyFor(D,R),W=r.getEntry(M),G=W?.data?.nextCursor??null;if(!G||W?.isLoading)return W;try{const B=await e.fetchList(I,L,D,e.buildRemoteQuery(R,G)),xe=r.getEntry(M)?.data,V={items:Vn(xe?.items??[],B.items),nextCursor:B.nextCursor,fetchedAt:B.fetchedAt},je=await r.refresh(M,async()=>V);return je.data&&(u(D,je.data.items),f(D)),je}catch(B){return r.setError(M,B)??r.getEntry(M)}},k=L=>{for(const D of Object.keys(r.snapshot()))Ur(D)===L&&r.remove(D);for(const D of[...l.keys()])Ur(D)===L&&l.delete(D)},C=(L,D,R,I)=>{const M=e.detailKeyFor(D,R);return o.refresh(M,async()=>({detail:await e.fetchDetail(I,L,D,R)}))};return{initialState:{filtersByScope:{},selectionByDirectory:{}},resources:{collections:n,remote:r,details:o,comments:i},setFilters:x,resetFilters:y,select:m,ensureCollection:h,ensureCollectionsFresh:g,prefetchClosedCollection:b,loadMoreCollection:S,refreshCollections:v,searchRemote:E,loadMoreRemote:j,dropRemoteForRepo:k,refreshAllForScope:async(L,D,R)=>{await ks(R,{directory:L,repo:D,kind:e.serverKind}),k(D),await v(L,D,"both",R).catch(()=>null);const I=t.get().selectionByDirectory[ds(L)];I?.repo===D&&typeof I.number=="number"&&await C(L,D,I.number,R).catch(()=>null)},ensureDetail:(L,D,R,I)=>{const M=e.detailKeyFor(D,R);return o.ensure(M,async()=>({detail:await e.fetchDetail(I,L,D,R)}))},refreshDetail:C,ensureComments:(L,D,R,I)=>{const M=e.commentsKeyFor(D,R);return i.ensure(M,async()=>{const W=await e.fetchComments(I,L,D,R);return{comments:W.comments,nextCursor:W.nextCursor,fetchedAt:W.fetchedAt}})},loadMoreComments:async(L,D,R,I)=>{const M=e.commentsKeyFor(D,R),W=i.getEntry(M),G=W?.data?.nextCursor??null;if(!G||W?.isLoading)return W;try{const B=await e.fetchComments(I,L,D,R,G),xe=i.getEntry(M)?.data,V={comments:qm(xe?.comments??[],B.comments),nextCursor:B.nextCursor,fetchedAt:B.fetchedAt};return await i.refresh(M,async()=>V)}catch(B){return i.setError(M,B)??i.getEntry(M)}},refreshComments:(L,D,R,I)=>{const M=e.commentsKeyFor(D,R);return i.refresh(M,async()=>{const W=await e.fetchComments(I,L,D,R);return{comments:W.comments,nextCursor:W.nextCursor,fetchedAt:W.fetchedAt}})},markCollectionsStale:L=>{n.markStale(e.collectionKeyFor(L,e.openCollection)),n.markStale(e.collectionKeyFor(L,e.closedCollection))},getLocalIndex:p,withSingleFlight:d,resetCore:()=>{n.reset(),r.reset(),l.clear(),o.reset(),i.reset(),c.clear(),t.set({filtersByScope:{},selectionByDirectory:{}})},toStoreError:L=>Ym(L,e.errorFallback)}},Eo={state:"open",involvement:"all",search:"",sort:"updated"},Qm=3e4,Jm=100,Xm=50,Kl=(e,t)=>cn([e,"pulls-collection",t]),Wl=(e,t)=>cn([e,"pulls-remote",t.state,t.involvement,t.q.trim()]),pr=(e,t)=>cn([e,"pull-detail",t]),Qo=(e,t)=>cn([e,"pull-comments",t]),Ro=(e,t)=>cn([e,"pull-files",t]),Do=(e,t)=>cn([e,"pull-checks",t]),Zm=e=>({state:e,perPage:Jm}),ep=(e,t)=>({state:e.state,filter:e.involvement,q:e.q.trim()?e.q.trim():void 0,perPage:Xm,...t?{cursor:t}:{}}),gr=e=>`pichamber:pr-merge-method:${e}`,Gl=new Map,tp=e=>{try{if(typeof localStorage<"u")return localStorage.getItem(e)}catch{}return null},sp=(e,t)=>{try{if(typeof localStorage<"u"){localStorage.setItem(e,t);return}}catch{}},Gx=e=>{if(!e)return null;const t=tp(gr(e));return t==="merge"||t==="squash"||t==="rebase"?t:Gl.get(gr(e))??null},np=(e,t)=>{if(e){Gl.set(gr(e),t);try{sp(gr(e),t)}catch{}}},rp={set:e=>{typeof e=="function"?xs.setState(t=>{const n={filtersByScope:t.filtersByScope,selectionByDirectory:t.selectionByDirectory};return e(n)}):xs.setState(e)},get:()=>{const e=xs.getState();return{filtersByScope:e.filtersByScope,selectionByDirectory:e.selectionByDirectory}}},De=Vm({openCollection:"open",closedCollection:"closed",defaultFilters:Eo,freshWindowMs:Qm,serverKind:"pulls",errorFallback:"Pull request request failed",collectionKeyFor:Kl,remoteKeyFor:Wl,detailKeyFor:pr,commentsKeyFor:Qo,buildCollectionQuery:e=>({...Zm(e)}),buildRemoteQuery:(e,t)=>({...ep(e,t)}),fetchList:async(e,t,n,r)=>{const o=await e.pullsList(t,n,r);return{items:o.items,nextCursor:o.nextCursor,fetchedAt:o.fetchedAt}},fetchDetail:async(e,t,n,r)=>e.pullGet(t,n,r),fetchComments:async(e,t,n,r,o)=>{const i=await e.pullComments(t,n,r,o);return{comments:i.comments,nextCursor:i.nextCursor,fetchedAt:i.fetchedAt}}},rp),Zt=Js(),rr=Js(),xs=Ls()(vr((e,t)=>({...De.initialState,actionErrorByDetail:{},actingActions:{},setFilters:De.setFilters,resetFilters:De.resetFilters,selectPullRequest:De.select,ensureCollection:De.ensureCollection,ensureCollectionsFresh:De.ensureCollectionsFresh,prefetchClosedCollection:De.prefetchClosedCollection,loadMoreCollection:De.loadMoreCollection,refreshCollections:De.refreshCollections,searchRemote:De.searchRemote,loadMoreRemote:De.loadMoreRemote,dropRemoteForRepo:De.dropRemoteForRepo,refreshAllForScope:De.refreshAllForScope,ensureDetail:De.ensureDetail,refreshDetail:De.refreshDetail,ensureComments:De.ensureComments,loadMoreComments:De.loadMoreComments,refreshComments:De.refreshComments,ensureFiles:(n,r,o,i)=>{const l=Ro(r,o);return Zt.ensure(l,async()=>i.pullFiles(n,r,o))},loadMoreFiles:async(n,r,o,i)=>{const l=Ro(r,o),c=Zt.getEntry(l),d=c?.data?.nextCursor??null;if(!d||c?.isLoading)return c;try{const u=await De.withSingleFlight(`${l}:more`,async()=>{const f=await i.pullFiles(n,r,o,d),p=Zt.getEntry(l)?.data,x=new Set((p?.files??[]).map(m=>m.filename)),y={repo:f.repo,number:f.number,files:[...p?.files??[],...f.files.filter(m=>!x.has(m.filename))],nextCursor:f.nextCursor,fetchedAt:f.fetchedAt};return Zt.refresh(l,async()=>y)});return u.ran?u.result??Zt.getEntry(l):Zt.getEntry(l)}catch(u){return Zt.setError(l,u)??Zt.getEntry(l)}},ensureChecks:(n,r,o,i)=>{const l=Do(r,o);return rr.ensure(l,async()=>i.pullChecks(n,r,o,!0))},refreshChecks:(n,r,o,i)=>{const l=Do(r,o);return rr.refresh(l,async()=>i.pullChecks(n,r,o,!0))},performAction:async(n,r,o,i,l)=>{const c=wn(r,o),d=pr(r,o);if(t().actingActions[c])return{ok:!1,error:{kind:"failed",message:"Action already in progress"}};e(x=>({actingActions:{...x.actingActions,[c]:!0},actionErrorByDetail:{...x.actionErrorByDetail,[c]:null}}));const u=De.resources.details.getEntry(d)?.data?.detail??null,f=u?.pr??null,p=f?{...f,state:i==="close"?"closed":i==="reopen"?"open":i==="merge"||i==="squash"||i==="rebase"?"merged":f.state,draft:i==="ready"?!1:i==="draft"?!0:f.draft}:null;p&&u&&await De.resources.details.refresh(d,async()=>({detail:{...u,pr:p}})).catch(()=>null);try{return await l.pullAction(n,r,o,i),(i==="merge"||i==="squash"||i==="rebase")&&t().setMergeMethod(r,i),await ks(l,{directory:n,repo:r,kind:"pulls",number:o}),t().dropRemoteForRepo(r),await t().refreshCollections(n,r,"both",l).catch(()=>null),await t().refreshDetail(n,r,o,l).catch(()=>null),await t().refreshChecks(n,r,o,l).catch(()=>null),e(x=>({actingActions:{...x.actingActions,[c]:!1}})),{ok:!0}}catch(x){const y=De.toStoreError(x);return u&&await De.resources.details.refresh(d,async()=>({detail:u})).catch(()=>null),e(m=>({actingActions:{...m.actingActions,[c]:!1},actionErrorByDetail:{...m.actionErrorByDetail,[c]:y}})),{ok:!1,error:y}}},updateTitleBody:async(n,r,o,i,l)=>{const c=wn(r,o),d=pr(r,o),u=De.resources.details.getEntry(d)?.data?.detail??null,f=u?.pr??null,p=f&&(i.title!==void 0||i.body!==void 0)?{...f,title:i.title??f.title,body:i.body??f.body}:null;p&&u&&await De.resources.details.refresh(d,async()=>({detail:{...u,pr:p}})).catch(()=>null);try{return await l.pullUpdate(n,r,o,i),await ks(l,{directory:n,repo:r,kind:"pulls",number:o}),t().dropRemoteForRepo(r),await t().refreshCollections(n,r,"both",l).catch(()=>null),await t().refreshDetail(n,r,o,l).catch(()=>null),{ok:!0}}catch(x){const y=De.toStoreError(x);return u&&await De.resources.details.refresh(d,async()=>({detail:u})).catch(()=>null),e(m=>({actionErrorByDetail:{...m.actionErrorByDetail,[c]:y}})),{ok:!1,error:y}}},addComment:async(n,r,o,i,l)=>{const c=wn(r,o),d=Qo(r,o),u=i.trim(),f={id:-Date.now(),url:"",body:u,author:null,createdAt:new Date().toISOString(),updatedAt:null},p=De.resources.comments.getEntry(d)?.data??null;if(p){const x={comments:[...p.comments,f],nextCursor:p.nextCursor,fetchedAt:p.fetchedAt};await De.resources.comments.refresh(d,async()=>x).catch(()=>null)}try{return await l.pullComment(n,r,o,u),await ks(l,{directory:n,repo:r,kind:"pulls",number:o}),await t().refreshComments(n,r,o,l).catch(()=>null),await t().refreshDetail(n,r,o,l).catch(()=>null),{ok:!0}}catch(x){const y=De.toStoreError(x);return p?await De.resources.comments.refresh(d,async()=>p).catch(()=>null):De.resources.comments.remove(d),e(m=>({actionErrorByDetail:{...m.actionErrorByDetail,[c]:y}})),{ok:!1,error:y}}},submitReview:async(n,r,o,i,l)=>{const c=wn(r,o);try{return await l.pullReview(n,r,o,{event:i.event,body:i.body,comments:i.comments}),await ks(l,{directory:n,repo:r,kind:"pulls",number:o}),await t().refreshDetail(n,r,o,l).catch(()=>null),{ok:!0}}catch(d){const u=De.toStoreError(d);return e(f=>({actionErrorByDetail:{...f.actionErrorByDetail,[c]:u}})),{ok:!1,error:u}}},threadAction:async(n,r,o,i,l,c)=>{const d=wn(r,o);try{return await c.pullThread(n,r,o,i,l),await ks(c,{directory:n,repo:r,kind:"pulls",number:o}),await t().refreshDetail(n,r,o,c).catch(()=>null),{ok:!0}}catch(u){const f=De.toStoreError(u);return e(p=>({actionErrorByDetail:{...p.actionErrorByDetail,[d]:f}})),{ok:!1,error:f}}},checkout:async(n,r,o,i,l)=>{try{const c=await l.pullCheckout(n,r,o,i);return{ok:!0,path:c.path,branch:c.branch}}catch(c){return{ok:!1,error:De.toStoreError(c)}}},createPullRequest:async(n,r)=>{try{const o=await r.pullCreate(n);return await ks(r,{directory:n.directory,repo:n.repo,kind:"pulls"}),t().dropRemoteForRepo(n.repo),await t().refreshCollections(n.directory,n.repo,"both",r).catch(()=>null),{ok:!0,number:o.pr.number}}catch(o){return{ok:!1,error:De.toStoreError(o)}}},rerunFailedChecks:async(n,r,o,i)=>{try{return await i.checksRerun(n,r,o),{ok:!0}}catch(l){return{ok:!1,error:De.toStoreError(l)}}},setMergeMethod:(n,r)=>{np(n,r)},notifyAgentTurnComplete:n=>{const r=ds((n||"").trim());if(!r)return;const o=ss.getState();for(const l of Object.keys(o.results)){const[,c]=l.split(`
|
|
19
|
+
`);if(c!==r)continue;const[,,d]=l.split(`
|
|
20
|
+
`);d&&ht(async()=>{const{getRegisteredRuntimeAPIs:u}=await import("./index-BnZVqcki.js").then(f=>f.cy);return{getRegisteredRuntimeAPIs:u}},__vite__mapDeps([2,3,4,5,6,7,8,9])).then(({getRegisteredRuntimeAPIs:u})=>{const f=u()?.github??null;if(f)return o.refresh(r,d,f,{force:!0})}).catch(()=>{})}const i=t().selectionByDirectory[r];i?.repo&&typeof i.number=="number"&&(De.markCollectionsStale(i.repo),ht(async()=>{const{getRegisteredRuntimeAPIs:l}=await import("./index-BnZVqcki.js").then(c=>c.cy);return{getRegisteredRuntimeAPIs:l}},__vite__mapDeps([2,3,4,5,6,7,8,9])).then(({getRegisteredRuntimeAPIs:l})=>{const c=l()?.github??null;if(c)return t().refreshDetail(r,i.repo,i.number,c)}).catch(()=>{}))},resetForRuntimeSwitch:()=>{De.resetCore(),Zt.reset(),rr.reset(),e({actionErrorByDetail:{},actingActions:{}})}}),{name:"github-pull-requests-store"}));typeof window<"u"&&(On(()=>{xs.getState().resetForRuntimeSwitch()}),window.addEventListener("focus",()=>{typeof document<"u"&&document.hidden}));const Hx=e=>{if(typeof window>"u")return()=>{};let t=new Set,n=!1,r=!1,o=null;return ht(async()=>{const{useNotificationStore:i}=await import("./useAppFontEffects-DviRbaCJ.js").then(l=>l.dR);return{useNotificationStore:i}},__vite__mapDeps([1,2,3,4,5,6,7,8,9,10,11,12])).then(({useNotificationStore:i})=>{if(r)return;const l=()=>{const c=i.getState().list,d=new Set(c.map(u=>`${u.type}:${u.session??""}:${u.time}`));if(!n){t=d,n=!0;return}for(const u of c){const f=`${u.type}:${u.session??""}:${u.time}`;t.has(f)||(t.add(f),u.type==="turn-complete"&&u.directory&&(xs.getState().notifyAgentTurnComplete(u.directory),e?.(u.directory)))}};l(),o=i.subscribe(l)}).catch(()=>{}),()=>{r=!0,o?.(),o=null}},qx=e=>De.getLocalIndex(e),Yx=(e,t)=>De.getLocalIndex(e).find(n=>n.number===t)??null,Vx=(e,t)=>dn(De.resources.collections,e?Kl(e,t):null),Qx=(e,t)=>dn(De.resources.remote,e?Wl(e,t):null),Jx=(e,t)=>dn(De.resources.details,e!=null&&t!=null?pr(e,t):null),Xx=(e,t)=>dn(De.resources.comments,e!=null&&t!=null?Qo(e,t):null),Zx=(e,t)=>dn(Zt,e!=null&&t!=null?Ro(e,t):null),ey=(e,t)=>dn(rr,e!=null&&t!=null?Do(e,t):null),ty=(e,t)=>xs(n=>!e||!t?Eo:n.filtersByScope[Io(e,t)]??Eo),sy=e=>xs(t=>e?t.selectionByDirectory[ds(e)]??Vi:Vi),Hl=(e,t,n)=>{xs.getState().selectPullRequest(e,t,n);const r=ds(e);ht(async()=>{const{useUIStore:o}=await import("./index-BnZVqcki.js").then(i=>i.cB);return{useUIStore:o}},__vite__mapDeps([2,3,4,5,6,7,8,9])).then(({useUIStore:o})=>{o.getState().openContextSurface(r,"pull-requests")}).catch(()=>{}),ht(async()=>{const{useGitHubScopeStore:o}=await import("./useAppFontEffects-DviRbaCJ.js").then(i=>i.dT);return{useGitHubScopeStore:o}},__vite__mapDeps([1,2,3,4,5,6,7,8,9,10,11,12])).then(({useGitHubScopeStore:o})=>{o.getState().setSelectedRepo(e,t)}).catch(()=>{})},op=({directory:e,number:t,color:n})=>{const r=_a(e);return!e||!r?s.jsxs("span",{className:"ml-auto flex-shrink-0 text-[0.72rem] font-medium leading-none",style:n?{color:n}:void 0,children:["#",t]}):s.jsxs("button",{type:"button",onClick:o=>{o.stopPropagation(),Hl(e,r,t)},className:"ml-auto flex-shrink-0 rounded text-[0.72rem] font-medium leading-none hover:bg-interactive-hover",style:n?{color:n}:void 0,title:`Open PR #${t} in Pull requests`,"aria-label":`Open pull request #${t} in Pull requests`,children:["#",t]})};function ip({group:e,groupKey:t,isCollapsed:n,onToggleCollapsedGroup:r,normalizedSessionSearchQuery:o,alwaysShowActions:i,groupHeaderRightPadding:l,dragHandleProps:c,groupPrColor:d,groupPrSummary:u,groupActivityIndicator:f,showBranchSubtitle:p,statusLine:x,allGroupSessions:y,projectId:m,activeProjectId:h,setActiveProjectIdOnly:b,setActiveMainTab:g,mobileVariant:S,setSessionSwitcherOpen:v,openNewSessionDraft:E}){return s.jsxs("div",{className:_("group/gh relative flex items-start justify-between gap-1 py-1 px-3 min-w-0 rounded-md","cursor-pointer"),onClick:()=>r(t),role:"button",tabIndex:0,onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),r(t))},"aria-label":n?`Expand ${e.label}`:`Collapse ${e.label}`,"aria-expanded":!n,children:[s.jsx("div",{ref:c?.setActivatorNodeRef,className:_("min-w-0 flex flex-1 items-start gap-1 overflow-hidden transition-[padding]",l),...c?.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:"typography-ui-label font-normal truncate text-foreground/92",children:e.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex size-4 shrink-0 items-center justify-center",children:[s.jsx(P,{name:"archive",className:_("size-4 shrink-0 text-muted-foreground",i?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:_("text-muted-foreground size-4 items-center justify-center",i?"inline-flex":"hidden group-hover/gh:inline-flex"),children:n?s.jsx(P,{name:"arrow-right-s",className:"size-4"}):s.jsx(P,{name:"arrow-down-s",className:"size-4"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:nr(e.label,o)}),f]}):!e.isMain||e.worktree?s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[s.jsxs("span",{className:"inline-flex size-4 shrink-0 items-center justify-center",children:[s.jsx(P,{name:"git-branch",className:_("size-4 shrink-0",!d&&"text-muted-foreground",i?"hidden":"group-hover/gh:hidden"),style:d?{color:d}:void 0}),s.jsx("span",{className:_("text-muted-foreground size-4 items-center justify-center",i?"inline-flex":"hidden group-hover/gh:inline-flex"),children:n?s.jsx(P,{name:"arrow-right-s",className:"size-4"}):s.jsx(P,{name:"arrow-down-s",className:"size-4"})})]}),s.jsx("span",{className:"min-w-0 truncate typography-ui-label font-normal text-muted-foreground",children:nr(e.label,o)}),f,u?s.jsx(op,{directory:e.directory??null,number:u.number,color:d}):null]}):s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"min-w-0 truncate",children:nr(e.label,o)}),f]})}),p&&x?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[e.isArchivedBucket?s.jsx(P,{name:"archive",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(P,{name:"git-branch",className:"size-4 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-muted-foreground/80",children:x.label})]}):null]})}),e.isArchivedBucket&&y.length>0?s.jsx("div",{className:_("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",i?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),Ds.requestDelete({sessions:y,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Delete archived sessions in ${e.label}`,children:s.jsx(P,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Delete archived sessions"})})]})}):null,e.directory?s.jsx("div",{className:_("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",i?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),m&&m!==h&&b(m),g("chat"),S&&v(!1),E({selectedProjectId:m,directoryOverride:e.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`New draft session in ${e.label}`,children:s.jsx(P,{name:"add",className:"h-4 w-4"})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"New draft session"})})]})}):null]})}const Qn=(e,t)=>t?e.sessions.some(n=>cs(n,t)):!1,ap=(e,t,n)=>e.sessions.some(r=>Pl(r,r,t,n,e.directory,e.directory)),lp=(e,t,n)=>{const r=o=>{const i=o.session.id;return t.get(i)!==n.get(i)?!0:o.children.some(r)};return e.sessions.some(r)},Xi=(e,t,n)=>{const r=o=>t.has(o.session.id)!==n.has(o.session.id)?!0:o.children.some(r);return e.sessions.some(r)},cp=(e,t,n)=>{const r=e.isArchivedBucket?"archived":"active",o=i=>{const l=`project:${r}:${i.session.id}`;return t.has(l)!==n.has(l)?!0:i.children.some(o)};return e.sessions.some(o)},dp=(e,t)=>{if(e.group!==t.group||e.groupKey!==t.groupKey||e.projectId!==t.projectId||e.hideGroupLabel!==t.hideGroupLabel||e.compactBodyPadding!==t.compactBodyPadding||e.groupSearchDataByGroup!==t.groupSearchDataByGroup||e.visibleSessionCount!==t.visibleSessionCount||e.collapsedGroups!==t.collapsedGroups&&e.collapsedGroups.has(e.groupKey)!==t.collapsedGroups.has(t.groupKey)||e.pinnedSessionIds!==t.pinnedSessionIds&&ap(t.group,e.pinnedSessionIds,t.pinnedSessionIds)||e.expandedParents!==t.expandedParents&&cp(t.group,e.expandedParents,t.expandedParents)||e.sessionOrderIndex!==t.sessionOrderIndex&&lp(t.group,e.sessionOrderIndex,t.sessionOrderIndex)||e.editingId!==t.editingId&&(Qn(e.group,e.editingId)||Qn(t.group,t.editingId))||e.editTitle!==t.editTitle&&(Qn(e.group,e.editingId)||Qn(t.group,t.editingId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){const n=mr(e.group.sessions,e.openSidebarMenuKey,"project",!!e.group.isArchivedBucket),r=mr(t.group.sessions,t.openSidebarMenuKey,"project",!!t.group.isArchivedBucket);if(n||r)return!1}return e.activeActivitySessionIds!==t.activeActivitySessionIds&&Xi(t.group,e.activeActivitySessionIds,t.activeActivitySessionIds)||e.unreadActivitySessionIds!==t.unreadActivitySessionIds&&Xi(t.group,e.unreadActivitySessionIds,t.unreadActivitySessionIds)?!1:e.hasSessionSearchQuery===t.hasSessionSearchQuery&&e.normalizedSessionSearchQuery===t.normalizedSessionSearchQuery&&e.hideDirectoryControls===t.hideDirectoryControls&&e.collapsedFolderIds===t.collapsedFolderIds&&e.toggleFolderCollapse===t.toggleFolderCollapse&&e.renameFolder===t.renameFolder&&e.deleteFolder===t.deleteFolder&&e.showDeletionDialog===t.showDeletionDialog&&e.setDeleteFolderConfirm===t.setDeleteFolderConfirm&&e.renderSessionNode===t.renderSessionNode&&e.showMoreGroupSessions===t.showMoreGroupSessions&&e.resetGroupSessionLimit===t.resetGroupSessionLimit&&e.mobileVariant===t.mobileVariant&&e.alwaysShowActions===t.alwaysShowActions&&e.activeProjectId===t.activeProjectId&&e.setActiveProjectIdOnly===t.setActiveProjectIdOnly&&e.setActiveMainTab===t.setActiveMainTab&&e.setSessionSwitcherOpen===t.setSessionSwitcherOpen&&e.openNewSessionDraft===t.openNewSessionDraft&&e.addSessionToFolder===t.addSessionToFolder&&e.createFolderAndStartRename===t.createFolderAndStartRename&&e.renamingFolderId===t.renamingFolderId&&e.renameFolderDraft===t.renameFolderDraft&&e.setRenameFolderDraft===t.setRenameFolderDraft&&e.setRenamingFolderId===t.setRenamingFolderId&&e.onToggleCollapsedGroup===t.onToggleCollapsedGroup&&e.dragHandleProps===t.dragHandleProps&&e.scrollContainerRef===t.scrollContainerRef};function up({group:e,sourceGroupNodes:t,hasSessionSearchQuery:n,normalizedSessionSearchQuery:r,compareSessionNodes:o,activeActivitySessionIds:i,unreadActivitySessionIds:l,collectGroupSessions:c}){const d=pt(j=>j.foldersMap),u=e.folderScopeKey??Ie(e.directory??null),f=a.useMemo(()=>e.folderScopes&&e.folderScopes.length>0?e.folderScopes:u?[{scopeKey:u,directory:e.directory??null}]:[],[u,e.directory,e.folderScopes]),p=a.useMemo(()=>f.flatMap(({scopeKey:j,directory:k})=>(d[j]??[]).map(C=>({folder:C,scopeKey:j,scopeDirectory:k}))),[f,d]),x=a.useMemo(()=>{const j=new Map,k=C=>{C.forEach(w=>{j.set(w.session.id,w),w.children.length>0&&k(w.children)})};return k(t),j},[t]),y=a.useMemo(()=>p.map(({folder:j,scopeKey:k,scopeDirectory:C})=>{const w=Rm(j.sessionIds,x).sort(o);return{folder:j,scopeKey:k,scopeDirectory:C,nodes:w}}),[p,x,o]),m=a.useMemo(()=>{const j=new Map(y.map(N=>[N.folder.id,N])),k=new Map;for(const{folder:N}of y){if(!N.parentId)continue;const T=k.get(N.parentId);T?T.push(N.id):k.set(N.parentId,[N.id])}const C=new Map,w=N=>{const T=C.get(N);if(T!==void 0)return T;const O=j.get(N);if(!O)return C.set(N,!1),!1;const $=k.get(N)??[];if(e.isArchivedBucket&&O.nodes.length===0){const L=$.some(D=>w(D));return C.set(N,L),L}if(!n||O.folder.name.toLowerCase().includes(r)||O.nodes.length>0)return C.set(N,!0),!0;const K=$.some(L=>w(L));return C.set(N,K),K};return y.filter(({folder:N})=>w(N.id))},[y,e.isArchivedBucket,n,r]),h=a.useMemo(()=>new Set(m.flatMap(j=>j.folder.sessionIds)),[m]),b=a.useMemo(()=>t.filter(j=>!h.has(j.session.id)),[t,h]),g=a.useMemo(()=>m.filter(({folder:j})=>!j.parentId),[m]),S=a.useMemo(()=>{const j=new Map;return m.forEach(k=>{if(!k.folder.parentId)return;const C=j.get(k.folder.parentId)??[];C.push(k),j.set(k.folder.parentId,C)}),j},[m]),v=a.useMemo(()=>{const j=new Map(m.map(w=>[w.folder.id,w])),k=new Map,C=(w,N)=>{const T=k.get(w);if(T!==void 0)return T;if(N.has(w))return null;N.add(w);const O=j.get(w);let $=O?Ol(O.nodes,i,l):null;for(const U of S.get(w)??[])if($=Yo($,C(U.folder.id,N)),$==="active")break;return k.set(w,$),$};return m.forEach(({folder:w})=>C(w.id,new Set)),k},[i,m,S,l]),E=a.useMemo(()=>{if(!e.isArchivedBucket)return new Map;const j=new Map,k=new Map;for(const{folder:w}of m){if(!w.parentId)continue;const N=k.get(w.parentId)??[];N.push(w.id),k.set(w.parentId,N)}const C=(w,N)=>{if(N.has(w))return[];N.add(w);const T=m.find(({folder:U})=>U.id===w),O=T?c(T.nodes):[],$=k.get(w)??[];for(const U of $)O.push(...C(U,N));return O};for(const{folder:w}of m)j.set(w.id,C(w.id,new Set));return j},[m,c,e.isArchivedBucket]);return{folderScopeKey:u,folderScopes:f,allFoldersForGroup:m,rootFolders:g,ungroupedSessions:b,folderActivityStateById:v,folderSessionsForDeleteById:E}}function fp(e){const{group:t,groupKey:n,projectId:r,hideGroupLabel:o,hasSessionSearchQuery:i,normalizedSessionSearchQuery:l,groupSearchDataByGroup:c,visibleSessionCount:d,collapsedGroups:u,hideDirectoryControls:f,collapsedFolderIds:p,toggleFolderCollapse:x,renameFolder:y,deleteFolder:m,showDeletionDialog:h,setDeleteFolderConfirm:b,renderSessionNode:g,showMoreGroupSessions:S,resetGroupSessionLimit:v,mobileVariant:E,alwaysShowActions:j,activeProjectId:k,setActiveProjectIdOnly:C,setActiveMainTab:w,setSessionSwitcherOpen:N,openNewSessionDraft:T,addSessionToFolder:O,createFolderAndStartRename:$,renamingFolderId:U,renameFolderDraft:K,setRenameFolderDraft:L,setRenamingFolderId:D,pinnedSessionIds:R,expandedParents:I,sessionOrderIndex:M,editingId:W,openSidebarMenuKey:G,activeActivitySessionIds:B,unreadActivitySessionIds:xe,onToggleCollapsedGroup:V,dragHandleProps:je,compactBodyPadding:Re=!1,scrollContainerRef:H}=e,z=a.useCallback((ke,He)=>{const Ae=M.get(ke.session.id),Oe=M.get(He.session.id);if(Ae!==void 0||Oe!==void 0){if(Ae===void 0)return 1;if(Oe===void 0)return-1;if(Ae!==Oe)return Ae-Oe}return ru(ke.session,He.session,R,za)},[R,M]),Y=i?c.get(t):null,X=i?!1:u.has(n),te=!t.isMain&&!t.isArchivedBucket&&!o?Ie(t.directory??null):null,ue=!t.isMain&&!t.isArchivedBucket&&!o&&t.branch?.trim()||null,he=a.useMemo(()=>te&&ue?Ln(te,ue):null,[te,ue]),Q=Tl(he);Fl(te,ue);const se=Q?`var(--pr-${Q.visualState})`:void 0,ce=f?10:5,Ce=Math.max(ce,d??ce),ve=i?Y?.groupMatches===!0:!1,Ge=i,q=a.useMemo(()=>[...Ge?Y?.filteredNodes??[]:t.sessions].sort(z),[z,t.sessions,Y?.filteredNodes,Ge]),ae=a.useCallback(ke=>{const He=[],Ae=Oe=>{Oe.forEach(Fe=>{He.push(Fe.session),Fe.children.length>0&&Ae(Fe.children)})};return Ae(ke),He},[]),{folderScopeKey:ne,folderScopes:me,allFoldersForGroup:fe,rootFolders:Be,ungroupedSessions:Se,folderActivityStateById:ee,folderSessionsForDeleteById:we}=up({group:t,sourceGroupNodes:q,hasSessionSearchQuery:i,normalizedSessionSearchQuery:l,compareSessionNodes:z,activeActivitySessionIds:B,unreadActivitySessionIds:xe,collectGroupSessions:ae}),pe="project",ye=a.useMemo(()=>{const ke=new Set;return $i(q,W,ke),fe.forEach(({nodes:He})=>{$i(He,W,ke)}),ke},[q,fe,W]),We=a.useMemo(()=>{if(!G)return null;const ke=mr(q,G,pe,!!t.isArchivedBucket);if(ke)return ke;for(const{nodes:He}of fe){const Ae=mr(He,G,pe,!!t.isArchivedBucket);if(Ae)return Ae}return null},[G,q,fe,t.isArchivedBucket]),qe=a.useCallback(ke=>{const He=new WeakMap,Ae=Oe=>{He.set(Oe,ko(Oe));for(const Fe of Oe.children)Ae(Fe)};return ke.forEach(Ae),He},[]),Pe=a.useMemo(()=>qe(q),[qe,q]),Ye=a.useMemo(()=>{const ke=new WeakMap;return fe.forEach(({nodes:He})=>{He.forEach(Ae=>ke.set(Ae,ko(Ae)))}),ke},[fe]),re=a.useCallback(ke=>Pe.get(ke)??Ye.get(ke)??"",[Pe,Ye]),Le=a.useCallback(ke=>({subtreeContainsEditing:ye,menuOpenSessionId:We,nodeStructureKey:re(ke)}),[ye,We,re]),nt=Se.length,at=t.isArchivedBucket||i?Se:Se.slice(0,Ce),Ve=nt-at.length,mt=!t.isArchivedBucket&&!i&&nt>ce&&Ve===0,lt=t.isArchivedBucket===!0&&!i&&at.length>=Om,qt=t.isArchivedBucket?"archived":"active",Yt=lt&&at.some(ke=>{if(ke.children.length===0)return!1;const He=`project:${qt}:${ke.session.id}`;return I.has(He)}),Ze=a.useMemo(()=>ae(q),[ae,q]);if(i&&!ve&&Be.length===0&&Se.length===0)return null;const Ct=!t.isMain&&!!t.branch,Vt=t.branch&&gf(t.branch,t.label)?{label:t.branch,color:null}:null,kt=X?Ol(q,B,xe):null,Ft=kt?s.jsx(Rl,{state:kt,activeLabel:"Session active",unreadLabel:"Unread updates"}):null,gt=(ke,He)=>{const{folder:Ae,scopeKey:Oe,scopeDirectory:Fe,nodes:rt}=ke,vt=we.get(Ae.id)??[],Nt=i?!1:p.has(Ae.id);return s.jsx(Im,{folderId:Ae.id,children:(bt,ct)=>s.jsx(Am,{folder:Ae,displayName:He,sessions:rt,isCollapsed:Nt,collapsedActivityState:Nt?ee.get(Ae.id)??null:null,onToggle:()=>x(Ae.id),onRename:tt=>{y(Oe,Ae.id,tt)},onDelete:()=>{if(t.isArchivedBucket){Ds.requestDelete({sessions:vt,mode:"session"});return}if(!h){m(Oe,Ae.id);return}const tt=fe.filter(({folder:Et})=>Et.parentId===Ae.id).length,It=rt.length;b({scopeKey:Oe,folderId:Ae.id,folderName:Ae.name,subFolderCount:tt,sessionCount:It})},renderSessionNode:g,getRenderExtras:re?tt=>({subtreeContainsEditing:ye,menuOpenSessionId:We,nodeStructureKey:re(tt),childRenderExtrasFor:Le}):void 0,groupDirectory:Fe??t.directory,projectId:r,mobileVariant:E,alwaysShowActions:j,isRenaming:U===Ae.id,renameDraft:U===Ae.id?K:void 0,onRenameDraftChange:tt=>L(tt),onRenameSave:()=>{const tt=K.trim();tt&&y(Oe,Ae.id,tt),D(null),L("")},onRenameCancel:()=>{D(null),L("")},droppableRef:bt,isDropTarget:ct,depth:0,onNewSession:()=>{r&&r!==k&&C(r),w("chat"),E&&N(!1),T({selectedProjectId:r,directoryOverride:Fe??t.directory,targetFolderId:Ae.id})},hideActions:!1,archivedBucket:t.isArchivedBucket===!0})},Ae.id)},wt=()=>{const ke=new Map;for(const Oe of fe){const Fe=Oe.folder.parentId;if(!Fe)continue;const rt=ke.get(Fe);rt?rt.push(Oe):ke.set(Fe,[Oe])}const He=[],Ae=(Oe,Fe)=>{const rt=Fe?`${Fe} / ${Oe.folder.name}`:Oe.folder.name;He.push(gt(Oe,rt)),!(!i&&p.has(Oe.folder.id))&&(ke.get(Oe.folder.id)??[]).forEach(Nt=>Ae(Nt,rt))};return Be.forEach(Oe=>Ae(Oe,"")),He},st=j?"pr-7":"pr-2 group-hover/gh:pr-7 group-focus-within/gh:pr-7",At=s.jsxs(Em,{scopeKey:me[0]?.scopeKey??ne,hasFolders:fe.length>0,onSessionDroppedOnFolder:(ke,He)=>{const Ae=fe.find(({folder:Fe})=>Fe.id===He);if(!Ae)return;const Oe=pt.getState();for(const{scopeKey:Fe}of me)Fe!==Ae.scopeKey&&Oe.getSessionFolderId(Fe,ke)&&Oe.removeSessionFromFolder(Fe,ke);O(Ae.scopeKey,He,ke)},children:[wt(),t.isArchivedBucket?s.jsx(_m,{visibleSessions:at,shouldVirtualize:lt,hasExpandedParent:Yt,scrollContainerRef:H,groupDirectory:t.directory,projectId:r,isArchivedBucket:t.isArchivedBucket===!0,renderSessionNode:g,getRenderExtras:ke=>({subtreeContainsEditing:ye,menuOpenSessionId:We,nodeStructureKey:re(ke),childRenderExtrasFor:Le})}):at.map(ke=>s.jsx(a.Fragment,{children:g(ke,0,t.directory,r,t.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:ye,menuOpenSessionId:We,nodeStructureKey:re(ke),childRenderExtrasFor:Le})},ke.session.id)),nt===0&&fe.length===0?t.isArchivedBucket?s.jsx("div",{className:"py-1 px-3 text-left typography-ui-label text-muted-foreground",children:"No archived sessions yet."}):s.jsx(ts,{icon:"chat-new",onClick:()=>{T({selectedProjectId:r,directoryOverride:t.directory})},children:"New session"}):null,Ve>0?s.jsx(ts,{icon:"arrow-down-s",onClick:()=>S(n,at.length),children:Ve===1?"Show 1 more session":`Show ${Ve} more sessions`}):null,mt?s.jsx(ts,{icon:"arrow-up-s",onClick:()=>v(n),children:"Show fewer sessions"}):null]});return o?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:"oc-group-body",children:At})}):s.jsxs("div",{className:"oc-group",children:[s.jsx(ip,{group:t,groupKey:n,isCollapsed:X,onToggleCollapsedGroup:V,normalizedSessionSearchQuery:l,alwaysShowActions:j,groupHeaderRightPadding:st,dragHandleProps:je,groupPrColor:se,groupPrSummary:Q,groupActivityIndicator:Ft,showBranchSubtitle:Ct,statusLine:Vt,allGroupSessions:Ze,projectId:r,activeProjectId:k,setActiveProjectIdOnly:C,setActiveMainTab:w,mobileVariant:E,setSessionSwitcherOpen:N,openNewSessionDraft:T}),X?null:s.jsx("div",{className:"oc-group-body",children:At})]})}const hp=a.memo(fp,dp);function mp(e){const{hideDirectoryControls:t,handleOpenDirectoryDialog:n,onOpenArchive:r,onOpenSettings:o,onOpenInstances:i,instanceLabel:l,onOpenUpdate:c,headerActionIconClass:d,headerActionButtonClass:u,isSessionSearchOpen:f,setIsSessionSearchOpen:p,sessionSearchInputRef:x,sessionSearchQuery:y,setSessionSearchQuery:m,hasSessionSearchQuery:h,searchMatchCount:b,selectionModeEnabled:g,onToggleSelectionMode:S,mobileVariant:v=!1}=e;if(t)return null;const E=_(u,"text-muted-foreground hover:text-foreground",!v&&"hover:bg-transparent");return s.jsx("div",{className:_("select-none flex-shrink-0",v?"px-2":"px-2 py-1"),children:s.jsxs("div",{className:_("flex flex-col",v?"gap-0":"h-auto min-h-8 gap-1"),children:[s.jsxs("div",{className:_("flex items-center justify-between",v?"h-[var(--oc-header-height,56px)] gap-1":"min-h-8 gap-2 px-2"),children:[s.jsxs("div",{className:_("flex min-w-0 items-center",v?"gap-1 overflow-x-auto":"gap-1.5"),"data-no-drawer-swipe":v?"true":void 0,children:[o?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:E,"aria-label":"Settings",children:s.jsx(P,{name:"settings-3",className:d})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Settings"})})]}):null,!v&&i?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:E,"aria-label":l?`Instances: ${l}`:"Instances",children:s.jsx(P,{name:"server",className:d})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:l||"Instances"})})]}):null,c?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:E,"aria-label":"Update",children:s.jsx(P,{name:"download",className:d})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Update"})})]}):null,v?null:s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:E,"aria-label":"Add project",children:s.jsx(P,{name:"folder-add",className:d})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Add project"})})]}),v?null:s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:E,"aria-label":"Archive",children:s.jsx(P,{name:"archive",className:d})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Archive"})})]})]}),s.jsxs("div",{className:_("flex shrink-0 items-center",v?"gap-1":"gap-1.5"),children:[s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>p(j=>!j),className:E,"aria-label":"Search sessions","aria-expanded":f,children:s.jsx(P,{name:"search",className:d})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"Search sessions"})})]}),s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:S,className:_(E,g&&"bg-interactive-hover text-primary"),"aria-label":g?"Exit selection":"Select sessions","aria-pressed":g,children:s.jsx(P,{name:"checkbox-multiple",className:d})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:g?"Exit selection":"Select sessions"})})]})]})]}),f?s.jsxs("div",{className:_(v?"pb-2":"pb-1"),children:[s.jsx("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:h?s.jsx("span",{children:b===1?`${b} match`:`${b} matches`}):s.jsx("span",{})}),s.jsxs("div",{className:"relative",children:[s.jsx(P,{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:y,onChange:j=>m(j.target.value),placeholder:"Search sessions...",className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:j=>{j.key==="Escape"&&(j.stopPropagation(),h?m(""):p(!1))}}),y.length>0?s.jsx("button",{type:"button",onClick:()=>m(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":"Clear search",children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null]})})}const $r="0.75rem";function pp(e){const t=le(o=>o.toggleSidebar),n=le(o=>o.shortcutOverrides),r=Ko(lr("toggle_sidebar",n));return s.jsxs("div",{className:"app-region-drag select-none flex h-[var(--oc-header-height,3rem)] shrink-0 items-center pr-3",children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:`var(--oc-titlebar-left-inset, ${$r})`}}),s.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:`max(0px, calc(var(--oc-titlebar-overlay-width, 0px) - var(--oc-titlebar-left-inset, ${$r})))`}}),s.jsxs("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center gap-1.5",children:[s.jsxs("button",{type:"button",onClick:e.onNewSession,className:_("group flex min-w-0 flex-1 items-center gap-1.5 text-left text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",e.touchFriendly&&"min-h-11"),style:{paddingLeft:`max(3px, calc(${bf} - max(var(--oc-titlebar-left-inset, ${$r}), var(--oc-titlebar-overlay-width, 0px))))`},children:[s.jsx(P,{name:"chat-new",className:_(tr,"text-current")}),s.jsx("span",{className:rl,children:"New session"})]}),e.showSidebarToggle?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:t,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":"Hide sessions",children:s.jsx(P,{name:"layout-left",className:"size-4"})})}),s.jsx(Ke,{children:s.jsx("p",{children:`Hide sessions (${r})`})})]}):null]})]})}function Cr({...e}){return s.jsx(Sa,{...e})}function kr({...e}){return s.jsx(ja,{...e})}function Ar({className:e,positionerClassName:t,children:n,style:r,...o}){return s.jsx(Ca,{children:s.jsx(ka,{className:_("app-region-no-drag z-50",t),children:s.jsx(Aa,{"data-slot":"dropdown-menu-content",style:{color:"var(--surface-elevated-foreground)",...r},className:_(Ua,e),...o,children:n})})})}function Rs({className:e,...t}){return s.jsx(Na,{className:_($a,e),...t})}function ql({className:e,...t}){return s.jsx(Ia,{className:_(Ka,e),...t})}const Yl=500,gp=({projectId:e,worktree:t,isSelected:n,hasActive:r,onSelect:o,onClose:i,mobileVariant:l=!1})=>{const[c,d]=a.useState(!1),u=a.useRef(null),f=t.branch||(t.detached?"Detached HEAD":t.name),p=a.useCallback(()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},[]);a.useEffect(()=>()=>p(),[p]);const x=a.useCallback(()=>{p(),u.current=window.setTimeout(()=>{u.current=null,d(!0)},Yl)},[p]);return s.jsxs(Cr,{open:c,onOpenChange:d,children:[s.jsxs(kr,{render:s.jsx("button",{type:"button",onClick:()=>{c||o()},onTouchStart:x,onTouchMove:p,onTouchEnd:p,onTouchCancel:p,style:{touchAction:"manipulation"},className:_(br(l,n),"pl-6"),"aria-pressed":n,title:t.path}),children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[s.jsx(P,{name:"git-branch",className:_(Ms(l),"text-muted-foreground")}),s.jsx("span",{className:nn(l),children:f})]}),s.jsx("div",{className:"flex items-center gap-1 shrink-0 ml-1",children:r?s.jsx(ws,{variant:"inline",text:null,animationType:"spinner",speedMs:80,className:"text-primary text-xs shrink-0"}):null})]}),s.jsx(Ar,{className:"min-w-[160px]",children:s.jsxs(Rs,{disabled:!i,title:r?"Stop the active session before closing this worktree.":void 0,onClick:()=>i?.(e,t),className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"close",className:"mr-2 h-3.5 w-3.5"}),s.jsx("span",{children:"Close worktree"})]})})]})},br=(e,t)=>_("relative flex w-full items-center gap-1.5 rounded-xl px-3 py-2 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",e&&"py-1.5",t?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),bp=({project:e,label:t,isSelected:n,hasActive:r,hasWorktrees:o,worktreeError:i,isExpanded:l,canDrag:c,onSelect:d,onOpenProjectEditDialog:u,onRemoveProject:f,mobileVariant:p=!1})=>{const{listeners:x,setNodeRef:y,transform:m,transition:h,isDragging:b}=zo({id:e.id,disabled:!c}),[g,S]=a.useState(!1),v=a.useRef(null),E=a.useCallback(()=>{v.current!==null&&(window.clearTimeout(v.current),v.current=null)},[]);a.useEffect(()=>()=>E(),[E]);const j=a.useCallback(()=>{E(),v.current=window.setTimeout(()=>{v.current=null,S(!0)},Yl)},[E]);return s.jsx("div",{ref:y,style:{transform:Uo.Translate.toString(m),transition:h},className:_(b&&"opacity-60"),children:s.jsxs(Cr,{open:g,onOpenChange:S,children:[s.jsxs(kr,{render:s.jsx("button",{type:"button",onClick:()=>{g||d()},onTouchStart:j,onTouchMove:E,onTouchEnd:E,onTouchCancel:E,style:{touchAction:"manipulation"},className:br(p,n),"aria-pressed":n}),children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[s.jsx("span",{className:_("inline-flex size-4 shrink-0 items-center justify-center",c&&"touch-none select-none cursor-grab active:cursor-grabbing"),"aria-label":c?`Reorder ${t}`:void 0,...c?x:{},children:s.jsx(P,{name:"folder",className:_(Ms(p),"text-muted-foreground")})}),s.jsx("span",{className:nn(p),children:t})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-1",children:[r?s.jsx(ws,{variant:"inline",text:null,animationType:"spinner",speedMs:80,className:"text-primary text-xs shrink-0"}):null,i?s.jsx("span",{title:i,"aria-label":"Worktree discovery failed",children:s.jsx(P,{name:"error-warning",className:"size-4 text-[var(--status-warning)]"})}):null,o?s.jsx(P,{name:l?"arrow-down-s":"arrow-right-s",className:"size-4 text-muted-foreground"}):null]})]}),s.jsxs(Ar,{className:"min-w-[160px]",children:[s.jsxs(Rs,{onClick:()=>u(e.id),children:[s.jsx(P,{name:"edit",className:"mr-2 h-3.5 w-3.5"}),s.jsx("span",{children:"Edit folder"})]}),s.jsx(ql,{}),s.jsxs(Rs,{onClick:()=>f(e.id),className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"close",className:"mr-2 h-3.5 w-3.5"}),s.jsx("span",{children:"Close folder"})]})]})]})})},xp=({projects:e,selectedProjectId:t,selectedWorktreePath:n=null,worktreesByProject:r=new Map,worktreeErrorsByProject:o=new Map,onSelectProject:i,onSelectWorktree:l,onCloseWorktree:c,onOpenDirectoryDialog:d,onOpenProjectEditDialog:u,onRemoveProject:f,hasActiveSessionByProject:p,activeDirectoriesByProject:x,homeDirectory:y,className:m,mobileVariant:h=!1})=>{const b=t===null,g=ut(j=>j.reorderProjects),S=e.length>1,v=Oo(Pn(Pa,{activationConstraint:{distance:8}}),Pn(Da,{activationConstraint:{delay:200,tolerance:6}})),E=a.useCallback(j=>{const{active:k,over:C}=j;if(!C||k.id===C.id)return;const w=ut.getState().projects,N=w.findIndex(O=>O.id===k.id),T=w.findIndex(O=>O.id===C.id);N<0||T<0||g(N,T)},[g]);return s.jsxs("div",{className:_("select-none px-2 pt-1 pb-2 border-b border-border/40 space-y-0.5",m),children:[s.jsx("button",{type:"button",onClick:()=>i(null),className:br(h,b),"aria-pressed":b,children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(P,{name:"chat-history",className:Ms(h)}),s.jsx("span",{className:nn(h),children:"All sessions"})]})}),s.jsx(Bo,{sensors:v,collisionDetection:_o,onDragEnd:E,children:s.jsx(Ea,{items:e.map(j=>j.id),strategy:Ra,children:e.map(j=>{const k=t===j.id,C=k&&!n,w=r.get(j.normalizedPath)??[],N=Wo(j.label?.trim()||Tn(j.normalizedPath,y)||j.normalizedPath),T=x?.get(j.id),O=Ie(j.normalizedPath)?.toLowerCase()??"",$=O?T?.has(O)??!1:!1,U=(T?.size??0)>0,K=p?.(j.id)??!1,L=x?k?$:U:K;return s.jsxs(a.Fragment,{children:[s.jsx(bp,{project:j,label:N,isSelected:C,hasActive:L,hasWorktrees:w.length>0,worktreeError:o.get(j.normalizedPath),isExpanded:k,canDrag:S,onSelect:()=>i(j.id),onOpenProjectEditDialog:u,onRemoveProject:f,mobileVariant:h}),k?w.map(D=>{const R=n===D.path,I=Ie(D.path)?.toLowerCase()??"",M=I?T?.has(I)??!1:!1,W=x?M:!1;return s.jsx(gp,{projectId:j.id,worktree:D,isSelected:R,hasActive:W,onSelect:()=>l?.(j.id,D.path),onClose:c,mobileVariant:h},D.path)}):null]},j.id)})})}),s.jsxs("button",{type:"button",onClick:d,className:br(h,!1),children:[s.jsx(P,{name:"add",className:Ms(h)}),s.jsx("span",{className:nn(h),children:"Add folder"})]})]})},Kr="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 yp({onOpenSettings:e,onOpenShortcuts:t,onOpenAbout:n,onOpenUpdate:r,showRuntimeButtons:o=!0,showUpdateButton:i=!0}){return!o&&!i?null:s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-3 py-2",children:[o?s.jsxs(s.Fragment,{children:[s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:Kr,"aria-label":"Settings",children:s.jsx(P,{name:"settings-3",className:"size-4"})})}),s.jsx(Ke,{side:"top",sideOffset:4,children:s.jsx("p",{children:"Settings"})})]}),s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:t,className:Kr,"aria-label":"Shortcuts",children:s.jsx(P,{name:"command",className:"size-4"})})}),s.jsx(Ke,{side:"top",sideOffset:4,children:s.jsx("p",{children:"Shortcuts"})})]}),s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:Kr,"aria-label":"About PiChamber",children:s.jsx(P,{name:"information",className:"size-4"})})}),s.jsx(Ke,{side:"top",sideOffset:4,children:s.jsx("p",{children:"About PiChamber"})})]})]}):null,i?s.jsx(Ne,{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:r,children:"Update"}):null]})}const Vl=({projectLabel:e,mobileVariant:t=!1})=>{const n=Ms(t),r=nn(t);return s.jsxs(s.Fragment,{children:[s.jsx("span",{className:_("inline-flex shrink-0 items-center justify-center",n),children:s.jsx(P,{name:"folder",className:_(n,"text-muted-foreground/80")})}),s.jsx("span",{className:_(r,"text-foreground"),children:e})]})},Ql=({isCollapsed:e,mobileVariant:t=!1,className:n})=>s.jsx("span",{className:_("ml-auto inline-flex shrink-0 items-center text-muted-foreground",n),children:s.jsx(P,{name:e?"arrow-right-s":"arrow-down-s",className:Ms(t)})}),wp=({id:e,disabled:t=!1,projectLabel:n,projectDescription:r,isCollapsed:o,hideDirectoryControls:i,mobileVariant:l,alwaysShowActions:c,stickyHeader:d=!1,onToggle:u,onNewSession:f,onRenameStart:p,onClose:x,children:y,showCreateButtons:m=!0,hideHeader:h=!1,openSidebarMenuKey:b,setOpenSidebarMenuKey:g,statusIndicator:S=null})=>{const{listeners:v,setNodeRef:E,transform:j,transition:k,isDragging:C}=zo({id:e,disabled:t}),w=a.useRef(!1),N=`project:${e}`,T=b===N,[O,$]=a.useState(!1),U=d&&!o,K=a.useCallback(G=>{G&&$(!1),g(G?N:null)},[N,g]),L=G=>s.jsxs(s.Fragment,{children:[m&&!i&&f&&s.jsxs(G,{onClick:f,children:[s.jsx(P,{name:"add",className:"mr-1.5 h-4 w-4"}),"New session"]}),s.jsxs(G,{onClick:p,children:[s.jsx(P,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),"Edit folder"]}),s.jsxs(G,{onClick:x,className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"close",className:"mr-1.5 h-4 w-4"}),"Close folder"]})]}),D=a.useCallback(G=>{G.stopPropagation()},[]),R=a.useCallback(G=>{G.stopPropagation()},[]),I=a.useCallback(G=>{G.stopPropagation()},[]),M=a.useCallback(G=>{(G.button===2||G.button===0&&G.ctrlKey)&&(w.current=!0)},[]),W=a.useCallback(G=>{if(G.currentTarget.blur(),w.current){w.current=!1;return}u()},[u]);return s.jsxs("div",{ref:E,style:{transform:Uo.Translate.toString(j),transition:k},className:_("relative",C&&"opacity-60"),children:[h?null:s.jsxs(Cr,{open:O,onOpenChange:$,children:[s.jsxs(kr,{render:s.jsx("div",{className:_("text-left group/project select-none",U&&"oc-sidebar-sticky-header sticky top-0 z-20 bg-sidebar before:pointer-events-none before:absolute before:inset-x-0 before:bottom-full before:h-2 before:bg-sidebar"),"data-sidebar-sticky-header":U?"true":void 0,onContextMenu:G=>{i||C||(G.preventDefault(),$(!0))}}),children:[s.jsxs("div",{"data-sidebar-tree-row":"",className:"relative flex items-center gap-1 py-1.5 px-3 rounded-xl transition-colors hover:bg-interactive-hover",children:[s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsxs("button",{type:"button","aria-expanded":!o,style:{touchAction:"manipulation"},onMouseDown:M,onClick:W,...v,className:_(jr,"flex-1 min-w-0 flex items-center text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing"),children:[s.jsx(Vl,{id:e,projectLabel:n,mobileVariant:l}),S?s.jsx("span",{className:"ml-1 inline-flex flex-shrink-0 items-center",children:S}):null,s.jsx(Ql,{isCollapsed:o,mobileVariant:l,className:_("transition-[padding]",c?"pl-16":"pl-2 group-hover/project:pl-14 group-focus-within/project:pl-14")})]})}),s.jsx(Ke,{side:"right",sideOffset:8,children:r})]}),s.jsx("div",{className:"absolute right-[calc(3.25rem*var(--padding-scale,1))] top-1/2 z-10 -translate-y-1/2",children:i?null:s.jsxs(Wt,{open:T,onOpenChange:K,children:[s.jsx(Gt,{asChild:!0,children:s.jsx("button",{type:"button",className:_("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",T?"opacity-100 pointer-events-auto":c?"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":"Folder menu",onPointerDown:R,onMouseDown:I,onClick:D,children:s.jsx(P,{name:"more-2",className:"size-4"})})}),s.jsx(Ht,{align:"end",className:"min-w-[180px]",children:L(ft)})]})}),m&&!i&&f?s.jsx("div",{className:"absolute right-7 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:G=>{G.stopPropagation(),f()},className:_("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",c?"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":"New session",children:s.jsx(P,{name:"add",className:"h-4 w-4"})})}),s.jsx(Ke,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:"New session"})})]})}):null]}),U?s.jsx("span",{"aria-hidden":!0,className:"oc-sidebar-sticky-header-fade pointer-events-none absolute inset-x-0 top-full h-4 bg-gradient-to-b from-sidebar to-transparent"}):null]}),s.jsx(Ar,{className:"min-w-[180px]",children:L(Rs)})]}),y]})},vp=({id:e,disabled:t=!1,children:n})=>{const{listeners:r,setNodeRef:o,setActivatorNodeRef:i,transform:l,transition:c,isDragging:d}=zo({id:e,disabled:t}),u=a.useMemo(()=>({listeners:r,setActivatorNodeRef:i}),[r,i]);return s.jsx("div",{ref:o,style:{transform:Uo.Transform.toString(l),transition:c},className:_("space-y-0.5 rounded-md",d&&"opacity-50"),children:typeof n=="function"?n(u):n})};a.memo(vp);const Zi="pt-0.5 pb-1",Sp=({sections:e,homeSection:t,homeDirectory:n,collapsedProjects:r,toggleProject:o,hasSessionSearchQuery:i,activeProjectId:l,hideDirectoryControls:c,mobileVariant:d,alwaysShowActions:u,isInlineEditing:f,stickyFolderHeaders:p,renderGroupSessions:x,renderSessionNode:y,getOrderedGroups:m,renderProjectStatusIndicator:h,scrollContainerRef:b,setActiveProjectIdOnly:g,setActiveMainTab:S,setSessionSwitcherOpen:v,openNewSessionDraft:E,openProjectEditDialog:j,removeProject:k,reorderProjects:C,openSidebarMenuKey:w,setOpenSidebarMenuKey:N,onOpenDirectoryDialog:T,emptyState:O,searchEmptyState:$})=>{const U=Oo(Pn(Pa,{activationConstraint:{distance:8}}),Pn(Da,{activationConstraint:{delay:200,tolerance:6}})),K=e.length>1&&!i&&!f,L=a.useCallback(B=>{if(f||i)return;const{active:xe,over:V}=B;if(!V||xe.id===V.id)return;const je=ut.getState().projects,Re=je.findIndex(z=>z.id===xe.id),H=je.findIndex(z=>z.id===V.id);Re<0||H<0||Re===H||C(Re,H)},[f,i,C]),[D,R]=a.useState(5);a.useEffect(()=>{R(5)},[i]);const I=a.useMemo(()=>t?t.groups.filter(B=>!B.isArchivedBucket).flatMap(B=>B.sessions):[],[t]),M=i?I:I.slice(0,D),W=I.length-M.length,G=i?!1:r.has("__home__");return e.length===0&&!t?i?$:O:s.jsxs("div",{className:"space-y-2",children:[s.jsx(Bo,{sensors:U,collisionDetection:_o,onDragEnd:L,children:s.jsx(Ea,{items:e.map(B=>B.project.id),strategy:Ra,children:e.map(B=>{const xe=B.project,V=xe.id,je=ol(xe,n),Re=co(xe.normalizedPath,n),H=i?!1:r.has(V),z=H?[]:m(V,B.groups),Y=H?null:z.find(te=>te.isMain)??null,X=H?[]:Y?z.filter(te=>te.id!==Y.id):z;return s.jsx(wp,{id:V,disabled:!K,projectLabel:je,projectDescription:Re,isCollapsed:H,hideDirectoryControls:c,mobileVariant:d,alwaysShowActions:u,stickyHeader:p,statusIndicator:H?h?.(V,B.groups):null,onToggle:()=>o(V),onNewSession:()=>{V!==l&&g(V),S("chat"),d&&v(!1),E({selectedProjectId:V,directoryOverride:xe.normalizedPath})},onRenameStart:()=>j(V),onClose:()=>k(V),openSidebarMenuKey:w,setOpenSidebarMenuKey:N,children:H?null:s.jsxs("div",{className:Zi,children:[Y?x(Y,`${V}:${Y.id}`,V,!0,null,void 0,b):null,X.map(te=>{const ue=`${V}:${te.id}`,he=z.length===1;return s.jsx(a.Fragment,{children:x(te,ue,V,he,null,void 0,b)},te.id)})]})},V)})})}),t?s.jsxs("div",{children:[s.jsx("div",{"data-sidebar-tree-row":"",className:"relative flex items-center gap-1 py-1.5 px-3 rounded-xl transition-colors hover:bg-interactive-hover",children:s.jsxs("button",{type:"button","aria-expanded":!G,style:{touchAction:"manipulation"},onClick:()=>o("__home__"),className:`${jr} flex-1 min-w-0 flex items-center text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md`,children:[s.jsx(Vl,{id:"__home__",projectLabel:"No folder",mobileVariant:d}),s.jsx(Ql,{isCollapsed:G,mobileVariant:d})]})}),G?null:s.jsxs("div",{className:Zi,children:[M.map(B=>s.jsx(a.Fragment,{children:y?.(B,0,B.session.directory??"~","__home__",!1,{globalSession:!0},"project")},B.session.id)),!i&&W>0?s.jsx(ts,{icon:"arrow-down-s",mobileVariant:d,onClick:()=>R(B=>B+7),children:W===1?"Show 1 more session":`Show ${W} more sessions`}):null,!i&&D>5&&I.length>5?s.jsx(ts,{icon:"arrow-up-s",mobileVariant:d,onClick:()=>R(5),children:"Show fewer sessions"}):null]})]}):null,!c&&T?s.jsx(ts,{icon:"add",mobileVariant:d,onClick:T,children:"Add folder"}):null]})},jp=a.memo(Sp);function Cp(e){Kt("ui.sidebar_projects_list.render");const t=e.viewMode??"workspace",n=t==="timeline",r=a.useRef(new Map),o=a.useRef(e.getOrderedGroups);o.current!==e.getOrderedGroups&&(o.current=e.getOrderedGroups,r.current.clear());const i=(b,g)=>{const S=r.current,v=S.get(b);if(v&&v.groups===g)return v.ordered;const E=e.getOrderedGroups(b,g);if(S.set(b,{groups:g,ordered:E}),S.size>256){const j=S.keys().next().value;j!==void 0&&S.delete(j)}return E},l=a.useRef(null),c=!!(e.isAllFoldersView||n),d=a.useMemo(()=>{if(!c)return[];const b=[],g=e.allFoldersOnlySection?[e.allFoldersOnlySection,...e.sectionsForRender]:e.sectionsForRender;for(const S of g){const v=ol(S.project,e.homeDirectory);for(const E of S.groups)if(!E.isArchivedBucket)for(const j of E.sessions){const k=!!e.pinnedSessionIds?.has(j.session.id),C=j.session.time?.updated||j.session.time?.created||0;b.push({node:j,project:S.project,projectLabel:v,isPinned:k,timestamp:C,globalSession:S===e.allFoldersOnlySection})}}return b.sort((S,v)=>S.isPinned!==v.isPinned?S.isPinned?-1:1:v.timestamp-S.timestamp),b},[e.allFoldersOnlySection,c,e.sectionsForRender,e.homeDirectory,e.pinnedSessionIds]),[u,f]=a.useState(30);a.useEffect(()=>{f(30)},[e.hasSessionSearchQuery]);const p=a.useMemo(()=>d.slice(0,u),[d,u]),x=a.useMemo(()=>e.timelineBoundaries??Co(Date.now(),1),[e.timelineBoundaries]),y=a.useMemo(()=>n?Vh(p,{getTimestamp:b=>b.timestamp,isPinned:b=>b.isPinned,boundaries:x}):[],[n,p,x]);if(e.sharedSessionsOnly)return s.jsx(As,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:_("pt-2 pb-1",e.mobileVariant&&"pb-32"),children:s.jsxs("div",{className:"space-y-1 px-2",children:[e.topContent,e.hasSharedSessions?null:e.hasSessionSearchQuery?e.searchEmptyState:e.emptyState]})});const m=(e.isAllFoldersView||t==="timeline"||t==="folder")&&!!e.allFoldersOnlySection;if(e.projectSections.length===0&&!m)return s.jsx(As,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:_("pt-2 pb-1",e.mobileVariant&&"pb-32"),children:s.jsxs("div",{className:"space-y-1 px-2",children:[e.topContent,e.emptyState]})});if(e.sectionsForRender.length===0&&!m)return s.jsx(As,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:_("pt-2 pb-1",e.mobileVariant&&"pb-32"),children:s.jsx("div",{className:"space-y-1 px-2",children:e.searchEmptyState})});const h=()=>{const b=d.length-p.length;return s.jsxs(s.Fragment,{children:[b>0?s.jsx(ts,{icon:"arrow-down-s",onClick:()=>f(g=>g+30),children:b===1?"Show 1 more session":`Show ${b} more sessions`}):null,u>30&&d.length>30?s.jsx(ts,{icon:"arrow-up-s",onClick:()=>f(30),children:"Show fewer sessions"}):null]})};return s.jsx("div",{className:"relative flex min-h-0 flex-1",children:s.jsx(As,{ref:l,useScrollShadow:!0,hideTopScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:_("oc-sidebar-scroller pt-2 pb-1 [overflow-anchor:none]",e.mobileVariant&&"pb-32"),children:s.jsxs("div",{className:"space-y-1 px-2",children:[e.topContent,e.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem]",children:(()=>{const b=e.sectionsForRender.find(E=>E.project.id===e.activeProjectId)??e.sectionsForRender[0];if(!b)return e.hasSessionSearchQuery?e.searchEmptyState:e.emptyState;const g=b.groups.find(E=>E.isMain&&E.sessions.length>0)??b.groups.find(E=>E.sessions.length>0)??b.groups.find(E=>E.isMain)??b.groups[0];if(!g)return s.jsx(ts,{icon:"chat-new",onClick:()=>e.openNewSessionDraft({selectedProjectId:b.project.id,directoryOverride:b.project.normalizedPath}),children:"New session"});const S=b.groups.find(E=>E.isArchivedBucket);return[g,...S&&S.id!==g.id?[S]:[]].map(E=>{const j=`${b.project.id}:${E.id}`,k=E.id===g.id;return s.jsx(a.Fragment,{children:e.renderGroupSessions(E,j,b.project.id,k,null,!0,l)},j)})})()}):t==="folder"?s.jsx(qo.Provider,{value:"tree",children:s.jsx(jp,{sections:e.sectionsForRender,homeSection:e.allFoldersOnlySection,homeDirectory:e.homeDirectory,collapsedProjects:e.collapsedProjects,toggleProject:e.toggleProject,hasSessionSearchQuery:e.hasSessionSearchQuery,activeProjectId:e.activeProjectId,hideDirectoryControls:e.hideDirectoryControls,mobileVariant:e.mobileVariant,alwaysShowActions:e.alwaysShowActions,isInlineEditing:e.isInlineEditing,stickyFolderHeaders:e.stickyFolderHeaders,renderGroupSessions:e.renderGroupSessions,renderSessionNode:e.renderSessionNode,getOrderedGroups:i,renderProjectStatusIndicator:e.renderProjectStatusIndicator,scrollContainerRef:l,setActiveProjectIdOnly:e.setActiveProjectIdOnly,setActiveMainTab:e.setActiveMainTab,setSessionSwitcherOpen:e.setSessionSwitcherOpen,openNewSessionDraft:e.openNewSessionDraft,openProjectEditDialog:e.openProjectEditDialog,removeProject:e.removeProject,reorderProjects:e.reorderProjects,openSidebarMenuKey:e.openSidebarMenuKey,setOpenSidebarMenuKey:e.setOpenSidebarMenuKey,onOpenDirectoryDialog:e.onOpenDirectoryDialog,emptyState:e.emptyState,searchEmptyState:e.searchEmptyState})}):t==="timeline"&&e.renderSessionNode?s.jsx("div",{children:d.length===0?e.hasSessionSearchQuery?e.searchEmptyState:e.emptyState:s.jsxs(s.Fragment,{children:[y.map((b,g)=>{const S=Hh[b.id];return s.jsxs("section",{"aria-label":S,"data-timeline-bucket":b.id,children:[s.jsx("div",{role:"heading","aria-level":3,className:_("select-none px-3 pb-1 text-xs leading-4 font-medium text-muted-foreground",g===0?"pt-1":"pt-3"),children:S}),b.items.map(({node:v,project:E,projectLabel:j,globalSession:k})=>{const C=v.session.directory??E.normalizedPath;return s.jsx(a.Fragment,{children:e.renderSessionNode(v,0,C,E.id,!1,{projectLabel:j,showFolderLabel:!0,globalSession:k},"project")},v.session.id)})]},b.id)}),h()]})}):e.isAllFoldersView&&e.renderSessionNode?s.jsx("div",{children:d.length===0?e.hasSessionSearchQuery?e.searchEmptyState:e.emptyState:s.jsxs(s.Fragment,{children:[p.map(({node:b,project:g,projectLabel:S,globalSession:v})=>{const E=b.session.directory??g.normalizedPath;return s.jsx(a.Fragment,{children:e.renderSessionNode(b,0,E,g.id,!1,{projectLabel:S,showFolderLabel:!0,globalSession:v},"project")},b.session.id)}),h()]})}):s.jsx("div",{children:e.sectionsForRender.map(b=>{const g=b.project.id,S=i(g,b.groups),v=S.find(j=>j.isMain)??null,E=v?S.filter(j=>j.id!==v.id):S;return s.jsxs("div",{children:[v?e.renderGroupSessions(v,`${g}:${v.id}`,g,!0,null,void 0,l):null,E.map(j=>{const k=`${g}:${j.id}`,C=S.length===1;return s.jsx(a.Fragment,{children:e.renderGroupSessions(j,k,g,C,null,void 0,l)},j.id)})]},g)})})]})})})}const kp=a.memo(Cp);let Po=!1;const Mo=new Set;let ea=!1;function Ap(){for(const e of Mo)e()}function Jo(e){Po!==e&&(Po=e,Ap())}function Np(e){e.key==="Shift"&&Jo(!0)}function Ip(e){e.key==="Shift"&&Jo(!1)}function Ep(){Jo(!1)}function Rp(){ea||typeof window>"u"||(ea=!0,window.addEventListener("keydown",Np),window.addEventListener("keyup",Ip),window.addEventListener("blur",Ep))}function Dp(e){return Rp(),Mo.add(e),()=>{Mo.delete(e)}}function Pp(){return Po}function Mp(){return!1}function Tp(){return Ee.useSyncExternalStore(Dp,Pp,Mp)}const Fp=a.memo(function({archiveLabel:t,deleteLabel:n,buttonSizeClass:r,iconSizeClass:o,onPointerDown:i,onMouseDown:l,onArchive:c,onDelete:d}){const u=Tp(),f=u?n:t,p=x=>{if(u||x.shiftKey){d(x);return}c(x)};return s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",className:_("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",u?"text-destructive hover:text-destructive":"text-muted-foreground hover:text-foreground",r),"aria-label":f,onPointerDown:i,onMouseDown:l,onClick:p,onKeyDown:x=>x.stopPropagation(),children:s.jsx(P,{name:u?"delete-bin":"archive",className:o})})}),s.jsx(Ke,{side:"left",sideOffset:8,children:f})]})}),Lp=a.memo(function({open:t,onOpenChange:n,descendantCount:r,exportIncludeSubtasks:o,setExportIncludeSubtasks:i,onExport:l}){return s.jsx(ns,{open:t,onOpenChange:n,children:s.jsxs(rs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(vs,{children:[s.jsx(us,{children:"Export Markdown"}),s.jsx(Ss,{children:r===1?`This session has ${r} sub-agent task. Include it in the export?`:`This session has ${r} sub-agent tasks. Include them in the export?`})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:o,onChange:c=>i(c.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),"Include sub-agent tasks"]}),s.jsxs(Ts,{children:[s.jsx(Ne,{type:"button",onClick:()=>n(!1),variant:"outline",size:"sm",children:"Cancel"}),s.jsx(Ne,{type:"button",onClick:()=>{n(!1),l(o)},size:"sm",children:"Export"})]})]})})});function Op(e,t){const{session:n,sessionTitle:r,sessionDirectory:o,isPinnedSession:i,archivedBucket:l,isElectron:c,pendingRenameRef:d,handleCopySessionId:u,togglePinnedSession:f,handleExportSession:p,handleOpenMiniChatWindow:x,handleDeleteSession:y,handleRestoreSession:m}=e,{Item:h,Separator:b}=t;return s.jsxs(s.Fragment,{children:[s.jsxs(h,{onClick:()=>{d.current={id:n.id,title:r}},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),"Rename"]}),s.jsxs(h,{onClick:()=>u(n.id),className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"file-copy",className:"mr-1 h-4 w-4"}),"Copy session ID"]}),s.jsxs(h,{onClick:()=>o&&f({directory:o,sessionId:n.id}),className:"[&>svg]:mr-1",children:[i?s.jsx(P,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(P,{name:"pushpin",className:"mr-1 h-4 w-4"}),i?"Unpin session":"Pin session"]}),s.jsxs(h,{onClick:()=>{p()},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"download",className:"mr-1 h-4 w-4"}),"Export Markdown"]}),c?s.jsxs(h,{disabled:!o,onClick:x,className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:"Open in Mini Chat Window"})]}):null,s.jsx(b,{}),l?null:s.jsxs(h,{className:"[&>svg]:mr-1",onClick:()=>y(n,{archivedBucket:l}),children:[s.jsx(P,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),"Archive"]}),l?s.jsxs(h,{className:"[&>svg]:mr-1",onClick:()=>m(n),children:[s.jsx(P,{name:"inbox-unarchive",className:"mr-1 h-4 w-4"}),"Restore"]}):null,s.jsxs(h,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>y(n,{archivedBucket:l,hardDelete:!0}),children:[s.jsx(P,{name:"delete-bin",className:"mr-1 h-4 w-4"}),"Delete"]})]})}function Bp(e){const{renamingFolderId:t,editingIdRef:n}=e;return s.jsx(Ca,{children:s.jsx(ka,{className:"app-region-no-drag z-50",children:s.jsx(Aa,{"data-slot":"dropdown-menu-content",finalFocus:()=>!(t||n.current),style:{color:"var(--surface-elevated-foreground)"},className:_(Ua,"min-w-[180px]"),children:Op(e,{Item:({className:r,...o})=>s.jsx(Na,{className:_($a,r),...o}),Separator:({className:r,...o})=>s.jsx(Ia,{className:_(Ka,r),...o})})})})})}const Wr=new WeakMap,_p=e=>{if(typeof window>"u")return;const t=e.closest("[data-session-row]"),n=t?.closest(".overlay-scrollbar-container");if(!t||!n)return;Wr.get(n)?.();const r=t.getBoundingClientRect().top;let o=3,i=!1,l=null;const c=()=>{i=!0,l!==null&&window.cancelAnimationFrame(l),l=null,Wr.delete(n),n.removeEventListener("wheel",c),n.removeEventListener("touchstart",c)},d=()=>{if(i||!t.isConnected||!n.isConnected){c();return}const u=t.getBoundingClientRect().top-r;if(Math.abs(u)>.5&&(n.scrollTop+=u,Kt("ui.sidebar.selection_scroll_anchor_adjustment")),o-=1,o<=0){c();return}l=window.requestAnimationFrame(d)};n.addEventListener("wheel",c,{passive:!0}),n.addEventListener("touchstart",c,{passive:!0}),Wr.set(n,c),l=window.requestAnimationFrame(d)};function zp(e){if(typeof e!="number"||!Number.isFinite(e))return"";const t=new Date(e);if(Number.isNaN(t.getTime()))return"";const n=t.toLocaleString("en-US",{month:"short"}),r=t.getDate(),o=t.getFullYear(),i=String(t.getHours()).padStart(2,"0"),l=String(t.getMinutes()).padStart(2,"0");return`${n} ${r}, ${o}, ${i}:${l}`}function Up(e){if(e.info.role==="user")return"";const t=typeof e.info.providerID=="string"?e.info.providerID.trim():"",n=typeof e.info.modelID=="string"?e.info.modelID.trim():"";return t&&n?`${t}/${n}`:n||t}function $p(e){const t=e.info.role==="user"?"User":"Assistant",n=zp(e.info.time?.created),r=Up(e),o=n&&r?`${n} (${r})`:n||r;return o?`**${t}**
|
|
21
|
+
|
|
22
|
+
*${o}*`:`**${t}**`}function Kp(e){return e.filter(t=>t.type==="text"&&typeof t.text=="string").map(t=>t.text).join("")}function Jl(e){const t=$p(e),n=Kp(e.parts).trim();return n?`${t}
|
|
23
|
+
|
|
24
|
+
${n}`:""}function Xl(e,t){const n="#".repeat(Math.min(t+1,6)),r=e.agent?` — ${e.agent}`:"",o=`${n} Sub-agent: ${e.title}${r}
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
`,i=e.records.map(Jl).filter(Boolean).join(`
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
`),l=[o+i];for(const c of e.children)l.push(Xl(c,t+1));return l.join(`
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
`)}function Zl(e,t,n){const r=t?.trim()||"Session",o=new Date().toISOString().split("T")[0],i=`# ${r}
|
|
37
|
+
|
|
38
|
+
*Exported on ${o}*
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
`,l=e.map(Jl).filter(Boolean).join(`
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
`);let c=i+l;if(n&&n.length>0){const d=n.map(u=>Xl(u,1)).join(`
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
`);c+=`
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
`+d}return c}function ec(e,t){jf({filename:t,mimeType:"text/markdown;charset=utf-8",data:e}).catch(n=>console.warn("[export] Markdown save failed",n))}async function tc(e,t){const n=await Gu(t,e);return n||null}async function Wp(e){const t=Ja()?.files;if(t?.revealPath)try{return!!(await t.revealPath(e))?.success}catch{return!1}return await Hu(e)?!0:Xa(e)}function Gp(){return qu()}function sc(e){const r=(e?.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 xr=e=>{const t=[],n=r=>{r.children.forEach(o=>{t.push(o.session.id),n(o)})};return n(e),t};function Hp(e,t){const[n,r]=a.useState(!1),[o,i]=a.useState(!0),l=e.session,c=a.useMemo(()=>xr(e).length,[e]),d=a.useCallback(async x=>{const y=[];let m=0;for(const h of x)try{if(!t)throw new Error("Session directory is required for export");const b=[],g=h.session.title||"Untitled Sub-agent",S=typeof h.session.agent=="string"?h.session.agent:void 0,v=await d(h.children);m+=v.skipped,y.push({title:g,agent:S,records:b,children:v.children})}catch{m+=xr(h).length+1}return{children:y,skipped:m}},[t]),u=a.useCallback(x=>{x<=0||ie.warning(x===1?`Exported session, but skipped ${x} sub-agent task that could not be loaded.`:`Exported session, but skipped ${x} sub-agent tasks that could not be loaded.`)},[]),f=a.useCallback(async x=>{if(!t){ie.error("Nothing to export");return}const y=[];if(y.length===0){ie.error("Nothing to export");return}let m,h=0;if(x&&e.children.length>0){const v=await d(e.children);m=v.children,h=v.skipped}const b=Zl(y,l.title??null,m),g=sc(l.title??null),S=await tc(b,g);if(S){ie.success("Session exported",{action:{label:Gp(),onClick:()=>{Wp(S).then(v=>{v||ie.error("Failed to reveal path")})}}}),u(h);return}ec(b,g),ie.success("Session exported"),u(h)},[d,e.children,l.title,t,u]),p=a.useCallback(async()=>{if(e.children.length>0){i(!0),r(!0);return}await f(!1)},[f,e.children.length]);return{exportDialogOpen:n,setExportDialogOpen:r,exportIncludeSubtasks:o,setExportIncludeSubtasks:i,descendantCount:c,handleExportSession:p,doExportSession:f}}const qp=(e,t)=>{if(!t)return Array.from(e);const n=[],r=new Set;for(const o of e){r.has(o)||(r.add(o),n.push(o));const i=t.get(o);if(i)for(const l of i)r.has(l)||(r.add(l),n.push(l))}return n},dt=Ls()((e,t)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{t().enabled||e({enabled:!0})},disable:()=>{e({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{t().enabled?e({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):e({enabled:!0})},toggleSelected:(n,r,o)=>{const i=t(),l=new Set(i.selectedIds);let c=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(l.clear(),c=r,d=null):c===null&&r!==null&&(c=r);const f=o&&o.length>0?[n,...o]:[n];if(l.has(n)){for(const x of f)l.delete(x);d===n&&(d=null)}else{for(const x of f)l.add(x);d=n}l.size===0?e({selectedIds:l,scopeKey:null,anchorId:null}):e({selectedIds:l,scopeKey:c,anchorId:d})},setRange:(n,r,o,i,l)=>{const c=t();if(o.length===0)return;const d=n&&o.includes(n)?n:o[0],u=o.indexOf(d),f=o.indexOf(r);if(u<0||f<0)return;const[p,x]=u<=f?[u,f]:[f,u],y=o.slice(p,x+1),m=qp(y,l),b=i!==null&&c.scopeKey!==null&&i!==c.scopeKey?new Set:new Set(c.selectedIds);for(const g of m)b.add(g);e({selectedIds:b,scopeKey:i??c.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){e({selectedIds:new Set,scopeKey:null,anchorId:null});return}e({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{e({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=t();if(r.selectedIds.size===0||n.length===0)return;const o=new Set(r.selectedIds);for(const i of n)o.delete(i);o.size!==r.selectedIds.size&&(o.size===0?e({selectedIds:o,scopeKey:null,anchorId:null}):e({selectedIds:o}))}})),ta=e=>Ie(e.session.directory??null),Yp=(e,t)=>(e?.projectLabel??null)===(t?.projectLabel??null)&&(e?.branchLabel??null)===(t?.branchLabel??null)&&(e?.showFolderLabel??!1)===(t?.showFolderLabel??!1),Vp=e=>{if(!e.openSidebarMenuKey)return null;const t=e.archivedBucket?"archived":"active",n=`${e.renderContext??"project"}:${t}:`;return e.openSidebarMenuKey.startsWith(n)?e.openSidebarMenuKey.slice(n.length):null},Jn=e=>e.menuOpenSessionId??Vp(e),Xn=(e,t,n)=>t?n.has(e.node.session.id)?!0:cs(e.node,t):!1,To=(e,t,n,r,o)=>{if(e.session.id!==t.session.id)return!0;const i=o(e);if(n.has(i)!==r.has(i)||e.children.length!==t.children.length)return!0;for(let l=0;l<e.children.length;l+=1)if(To(e.children[l],t.children[l],n,r,o))return!0;return!1},Qp=(e,t)=>{if(e.hasSessionSearchQuery||t.hasSessionSearchQuery)return!1;const n=e.archivedBucket?"archived":"active",r=t.archivedBucket?"archived":"active";return To(e.node,t.node,e.expandedParents,t.expandedParents,o=>`${e.renderContext??"project"}:${n}:${o.session.id}`)||To(e.node,t.node,e.expandedParents,t.expandedParents,o=>`${t.renderContext??"project"}:${r}:${o.session.id}`)},Jp=(e,t)=>{if(e.node.session.id!==t.node.session.id||e.node.session!==t.node.session||e.depth!==t.depth||e.groupDirectory!==t.groupDirectory||e.projectId!==t.projectId||e.archivedBucket!==t.archivedBucket||(e.renderContext??"project")!==(t.renderContext??"project")||e.mobileVariant!==t.mobileVariant||e.alwaysShowActions!==t.alwaysShowActions||e.allowQuickArchiveAction!==t.allowQuickArchiveAction||e.hasSessionSearchQuery!==t.hasSessionSearchQuery||e.normalizedSessionSearchQuery!==t.normalizedSessionSearchQuery||e.nodeStructureKey!==t.nodeStructureKey||ta(e.node)!==ta(t.node)||!Yp(e.secondaryMeta,t.secondaryMeta)||e.pinnedSessionIds!==t.pinnedSessionIds&&Pl(e.node,t.node,e.pinnedSessionIds,t.pinnedSessionIds,e.groupDirectory,t.groupDirectory)||e.expandedParents!==t.expandedParents&&Qp(e,t)||e.editingId!==t.editingId&&(Xn(e,e.editingId,e.subtreeContainsEditing)||Xn(t,t.editingId,t.subtreeContainsEditing))||e.editTitle!==t.editTitle&&(Xn(e,e.editingId,e.subtreeContainsEditing)||Xn(t,t.editingId,t.subtreeContainsEditing))||e.copiedSessionId!==t.copiedSessionId&&(cs(e.node,e.copiedSessionId)||cs(t.node,t.copiedSessionId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){const n=Jn(e),r=Jn(t);if(cs(e.node,n)||cs(t.node,r))return!1}if(e.renamingFolderId!==t.renamingFolderId){const n=Jn(e),r=Jn(t);if(cs(e.node,n)||cs(t.node,r))return!1}return e.setEditingId===t.setEditingId&&e.setEditTitle===t.setEditTitle&&e.handleSaveEdit===t.handleSaveEdit&&e.handleCancelEdit===t.handleCancelEdit&&e.toggleParent===t.toggleParent&&e.handleSessionSelect===t.handleSessionSelect&&e.handleSessionDoubleClick===t.handleSessionDoubleClick&&e.togglePinnedSession===t.togglePinnedSession&&e.handleShareSession===t.handleShareSession&&e.handleCopyShareUrl===t.handleCopyShareUrl&&e.handleCopySessionId===t.handleCopySessionId&&e.handleUnshareSession===t.handleUnshareSession&&e.setOpenSidebarMenuKey===t.setOpenSidebarMenuKey&&e.getFoldersForScope===t.getFoldersForScope&&e.getSessionFolderId===t.getSessionFolderId&&e.removeSessionFromFolder===t.removeSessionFromFolder&&e.addSessionToFolder===t.addSessionToFolder&&e.createFolderAndStartRename===t.createFolderAndStartRename&&e.handleDeleteSession===t.handleDeleteSession&&e.handleRestoreSession===t.handleRestoreSession&&e.renderSessionNode===t.renderSessionNode};function Xp({node:e,groupDirectory:t,projectId:n,secondaryMeta:r,pinnedSessionIds:o,expandedParents:i,expansionKey:l,hasSessionSearchQuery:c}){const d=e.session,u=Ie(d.directory??null)??Ie(t??null),f=Te(ue=>ue.currentSessionId===d.id),p=Wa(u),x=ou(u),y=ut(a.useCallback(ue=>{if(r?.projectLabel||!n)return null;const he=ue.projects.find(Q=>Q.id===n);return he?he.label?.trim()||Tn(Ie(he.path)??he.path,null)||he.path:null},[n,r?.projectLabel])),m=r?.projectLabel??(y?Wo(y):null),h=e.worktree,b=r?.branchLabel??h?.branch??(p&&p!=="HEAD"?p:null),g=b,S=x===!0||!!(b||h),v=e.children.length,E=d.agent,j=h?.branch?.trim()||b?.trim()||null,k=Ie(h?.path??u),C=a.useMemo(()=>j&&k?Ln(k,j):null,[j,k]),w=Tl(C);Fl(k,j);const N=w?`var(--pr-${w.visualState})`:void 0,T=a.useMemo(()=>{if(!w)return null;switch(w.visualState){case"merged":return"Merged";case"open":return w.canMerge===!0||w.mergeableState==="clean"||w.checks?.state==="success"?"Ready to merge":"PR open";case"blocked":return w.mergeableState==="dirty"?"Merge conflicts":"Merge blocked";case"draft":return"Draft PR";case"closed":return"Closed";default:return null}},[w]),O=n??u??null,$=dt(ue=>ue.enabled),U=dt(a.useCallback(ue=>ue.selectedIds.has(d.id),[d.id])),K=dt(ue=>ue.toggleSelected),L=dt(ue=>ue.setRange),R=Ga(d.id)?.type??"idle",I=R==="busy"||R==="retry",M=iu(d.id,I),W=bs(d),G=e.children.length>0,B=au(o,u,d.id),xe=c?!0:i.has(l),je=lu(d.id)>0,Re=d.time?.updated||d.time?.created||Date.now(),H=xf(Re),z=a.useMemo(()=>Nl(e.forkColorId),[e.forkColorId]),Y=a.useMemo(()=>om(e.forkColorId,{active:f||U}),[e.forkColorId,f,U]),X=r?.globalSession&&!f&&!U?"var(--surface-elevated)":null,te=Y??X;return{session:d,sessionDirectory:u,prDirectory:k,prBranch:j,prNumber:w?.number??null,isActive:f,tooltipProjectLabel:m,tooltipBranchLabel:g,isGitRepo:S,subtaskCount:v,agentName:E,prSummary:w,prIconColor:N,prStatusLabel:T,selectionScopeKey:O,selectionModeEnabled:$,isRowSelected:U,toggleRowSelected:K,setRowRange:L,isStreaming:I,hasActivityDuration:M,sessionTitle:W,hasChildren:G,isPinnedSession:B,isExpanded:xe,needsAttention:je,sessionCompactUpdatedLabel:H,forkSolid:z,rowBackground:te}}const Zp=({prDirectory:e,prNumber:t,prStatusLabel:n,prIconColor:r})=>{const o=_a(e);if(!e||!o)return s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1",style:r?{color:r}:void 0,title:n?`PR #${t} — ${n}`:`PR #${t}`,children:[s.jsx(P,{name:"git-pull-request",className:"size-3.5 shrink-0"}),s.jsxs("span",{children:["#",t]})]});const i=l=>{l.stopPropagation(),l.preventDefault(),Hl(e,o,t)};return s.jsxs("span",{role:"button",tabIndex:0,onClick:i,onDoubleClick:l=>{l.stopPropagation(),l.preventDefault()},onKeyDown:l=>{if(!(l.key!=="Enter"&&l.key!==" ")){if(l.repeat){l.stopPropagation(),l.preventDefault();return}i(l)}},className:"inline-flex shrink-0 cursor-pointer items-center gap-1 rounded hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",style:r?{color:r}:void 0,title:n?`PR #${t} — ${n}. Open in Pull requests`:`Open PR #${t} in Pull requests`,"aria-label":n?`Open pull request #${t}, ${n}, in Pull requests`:`Open pull request #${t} in Pull requests`,children:[s.jsx(P,{name:"git-pull-request",className:"size-3.5 shrink-0"}),s.jsxs("span",{children:["#",t]})]})};function eg(e){Kt("ui.sidebar_session_node.render");const{node:t,depth:n=0,groupDirectory:r,projectId:o,archivedBucket:i=!1,pinnedSessionIds:l,expandedParents:c,hasSessionSearchQuery:d,normalizedSessionSearchQuery:u,editingId:f,setEditingId:p,editTitle:x,setEditTitle:y,handleSaveEdit:m,handleCancelEdit:h,toggleParent:b,handleSessionSelect:g,handleSessionDoubleClick:S,togglePinnedSession:v,handleShareSession:E,copiedSessionId:j,handleCopyShareUrl:k,handleCopySessionId:C,handleUnshareSession:w,openSidebarMenuKey:N,setOpenSidebarMenuKey:T,renamingFolderId:O,getFoldersForScope:$,getSessionFolderId:U,removeSessionFromFolder:K,addSessionToFolder:L,createFolderAndStartRename:D,handleDeleteSession:R,handleRestoreSession:I,alwaysShowActions:M,allowQuickArchiveAction:W,renderSessionNode:G,secondaryMeta:B,renderContext:xe="project",subtreeContainsEditing:V,menuOpenSessionId:je,childRenderExtrasFor:Re}=e,H=a.useContext(qo)==="tree",z="size-3 shrink-0",Y=a.useMemo(()=>Za(),[]),X=!i&&W,te=a.useRef(!1),ue=a.useRef(f);ue.current=f;const he=a.useRef(null),Q=a.useRef(m);Q.current=m;const[se,ce]=a.useState(x),Ce=a.useRef(se);Ce.current=se;const ve=a.useRef(null),Ge=a.useRef(null),ae=`${xe}:${i?"archived":"active"}:${t.session.id}`,{session:ne,sessionDirectory:me,prDirectory:fe,prNumber:Be,isActive:Se,tooltipProjectLabel:ee,tooltipBranchLabel:we,isGitRepo:pe,subtaskCount:ye,agentName:We,prSummary:qe,prIconColor:Pe,prStatusLabel:Ye,selectionScopeKey:re,selectionModeEnabled:Le,isRowSelected:nt,toggleRowSelected:at,setRowRange:Ve,isStreaming:mt,hasActivityDuration:lt,sessionTitle:qt,hasChildren:Yt,isPinnedSession:Ze,isExpanded:Ct,needsAttention:Vt,sessionCompactUpdatedLabel:kt,forkSolid:Ft,rowBackground:gt}=Xp({node:t,groupDirectory:r,projectId:o,secondaryMeta:B,pinnedSessionIds:l,expandedParents:c,expansionKey:ae,hasSessionSearchQuery:d}),{exportDialogOpen:wt,setExportDialogOpen:st,exportIncludeSubtasks:At,setExportIncludeSubtasks:ke,descendantCount:He,handleExportSession:Ae,doExportSession:Oe}=Hp(t,me),[Fe,rt]=a.useState(!1),vt=a.useCallback(()=>{me&&In("desktop_open_session_mini_chat_window",{sessionId:ne.id,directory:me,apiBaseUrl:ho(),clientToken:fo()}).catch(de=>{console.warn("[session-sidebar] failed to open mini chat window",de)})},[ne.id,me]);a.useEffect(()=>{if(f!==ne.id)return;const de=F=>{const be=F.target?.closest?.(`[data-session-rename-form="${CSS.escape(ne.id)}"]`);Ge.current&&!be&&Q.current(Ce.current)};return document.addEventListener("mousedown",de),()=>document.removeEventListener("mousedown",de)},[f,ne.id]),a.useLayoutEffect(()=>{if(f!==ne.id){ve.current===ne.id&&(ve.current=null);return}ve.current!==ne.id&&(ve.current=ne.id,ce(x))},[f,x,ne.id]);const Nt=!mt&&Vt&&!Se,bt=mt&<,ct=X&&(M||Fe),tt=mt&&!H&&!ct&&f!==ne.id,It=!!(B?.showFolderLabel&&ee),Et=!!we||pe,os=!!(We&&We!=="default"),Qt=!!qe&&Be!=null,Jt=bt&&!tt,xt=It&&Et||Qt||ye>0||os||Jt,Os=de=>we?s.jsxs("span",{className:_("inline-flex min-w-0 items-center gap-1",de?"shrink":"flex-1"),children:[s.jsx(P,{name:"git-branch",className:z,style:Pe?{color:Pe}:void 0}),s.jsx("span",{className:"truncate",children:we})]}):pe?s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1",children:[s.jsx(P,{name:"git-repository",className:z}),s.jsx("span",{children:"git"})]}):null,un=Ze,Bs=s.jsx(P,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":"Pinned session"}),_s=un?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:Bs}):null,Lt=Yt?s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),b(ae)},onKeyDown:de=>{(de.key==="Enter"||de.key===" ")&&(de.preventDefault(),de.stopPropagation(),b(ae))},className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-label":Ct?"Collapse subsessions":"Expand subsessions",children:Ct?s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(P,{name:"arrow-right-s",className:"h-3 w-3"})}):null,fs=de=>{if(!de&&he.current){const{id:F,title:oe}=he.current;he.current=null,p(F),y(oe)}},St=de=>{rt(de)},is=de=>{de.preventDefault(),de.stopPropagation()},as=de=>{de.preventDefault(),de.stopPropagation()},ot=de=>{de.preventDefault(),de.stopPropagation(),T(null),R(ne,{archivedBucket:i})},Ot=de=>{de.preventDefault(),de.stopPropagation(),T(null),R(ne,{archivedBucket:i,hardDelete:!0,skipConfirm:!0})},js=de=>{if(te.current){te.current=!1;return}if(Le){if(de?.preventDefault(),de?.stopPropagation(),de?.shiftKey){const oe=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(Je=>Je.getAttribute("data-session-row")).filter(Je=>typeof Je=="string"&&Je.length>0),be=dt.getState().anchorId,_e=new Map;_e.set(ne.id,xr(t)),Ve(be,ne.id,oe,re,_e);return}at(ne.id,re,xr(t));return}de?.currentTarget&&_p(de.currentTarget),g(ne.id,me)},Rt=de=>{de.defaultPrevented||de.target?.closest('button, a, input, [role="menuitem"], [role="menu"]')||js(de)},fn=de=>{(de.button===2||de.button===0&&de.ctrlKey&&!Le)&&(te.current=!0)},zs={session:ne,sessionTitle:qt,sessionDirectory:me,isPinnedSession:Ze,archivedBucket:i,isElectron:Y,renamingFolderId:O,editingIdRef:ue,pendingRenameRef:he,handleCopySessionId:C,togglePinnedSession:v,handleExportSession:Ae,handleOpenMiniChatWindow:vt,handleDeleteSession:R,handleRestoreSession:I},hn=s.jsx(Bp,{...zs});return s.jsxs(a.Fragment,{children:[s.jsx(Nm,{sessionId:ne.id,sessionDirectory:me??null,sessionTitle:qt,children:s.jsxs(Sa,{open:Fe,onOpenChange:St,onOpenChangeComplete:fs,children:[s.jsxs(ja,{render:s.jsx("div",{"data-session-row":ne.id,"data-session-scope":re??"","data-session-archived":i?"1":"0","data-fork-color":Ft?t.forkColorId:void 0,"data-global-session":B?.globalSession?"1":void 0,"data-sidebar-tree-row":H?"":void 0,onClick:Rt,style:{...n>0?{marginLeft:`${n*14}px`}:void 0,...gt?{backgroundColor:gt}:void 0},className:_("group relative flex cursor-pointer items-start px-3 transition-colors",H?Dl:"my-0.5 rounded-xl py-2",!gt&&n>0?"bg-secondary/30 hover:bg-interactive-hover":gt?"hover:brightness-[1.07] dark:hover:brightness-[1.18]":"hover:bg-interactive-hover",!gt&&Se&&!nt&&"bg-interactive-selection",!gt&&nt&&"bg-interactive-selection")}),children:[s.jsxs("div",{className:_("flex min-w-0 flex-1 items-start",tt&&"oc-session-row-working-fade"),"data-clear-on-hover":tt&&X?"true":void 0,"data-working-duration":tt&&bt?"true":void 0,children:[s.jsxs("div",{className:_("flex min-w-0 flex-1 items-center",H?jr:"gap-1.5"),children:[H?s.jsx("span",{"data-session-row-gutter":!0,className:"inline-flex size-4 shrink-0 items-center justify-center",children:mt?s.jsx(ws,{variant:"inline",text:null,animationType:"spinner",speedMs:80,className:"text-primary text-xs shrink-0"}):null}):null,Lt,_s,f===ne.id?s.jsxs("form",{ref:Ge,"data-session-rename-form":ne.id,className:_("flex min-w-0 flex-1 items-center gap-2",H?"min-h-5":"min-h-8"),onPointerDown:de=>de.stopPropagation(),onMouseDown:de=>de.stopPropagation(),onSubmit:de=>{de.preventDefault(),m(se)},children:[s.jsx("input",{value:se,onChange:de=>ce(de.target.value),className:"min-w-0 flex-1 bg-transparent typography-ui-label text-foreground outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:"Rename",onKeyDown:de=>{de.stopPropagation(),de.key==="Escape"&&h()}}),s.jsx("button",{type:"submit","aria-label":"Save session name",title:"Save session name",className:"shrink-0 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:s.jsx(P,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:h,"aria-label":"Cancel renaming session",title:"Cancel renaming session",className:"shrink-0 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:s.jsx(P,{name:"close",className:"size-4"})})]}):s.jsxs("button",{type:"button",onMouseDown:fn,onClick:de=>js(de),onDoubleClick:de=>{de.stopPropagation(),S(ne.id,qt)},className:"flex min-w-0 flex-1 cursor-pointer flex-col gap-1 overflow-hidden text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none",children:[s.jsxs("div",{className:"flex w-full items-center min-w-0 flex-1 gap-1.5 overflow-hidden",children:[s.jsx("div",{className:_("block min-w-0 flex-1 truncate font-normal typography-ui-label",Vt?"text-foreground":H&&!Se?"text-muted-foreground transition-colors group-hover:text-foreground":"text-foreground/90"),children:nr(qt,u)}),Ze?s.jsx(P,{name:"star-fill",className:"h-3 w-3 text-primary shrink-0"}):null,s.jsx("span",{"aria-hidden":"true",className:"invisible ml-1 min-w-6 shrink-0 whitespace-nowrap text-[11px]",children:Nt?null:kt})]}),!H&&(It||Et||xt)?s.jsxs("div",{className:"flex w-full min-w-0 items-center justify-between gap-2 overflow-hidden text-xs leading-4 font-normal text-muted-foreground/80",children:[It?s.jsxs("span",{className:_("inline-flex min-w-0 items-center gap-1",xt?"max-w-[60%] shrink-0":"flex-1"),children:[s.jsx(P,{name:"folder",className:z}),s.jsx("span",{className:"truncate",children:ee})]}):Os(!1),xt?s.jsxs("span",{className:_("ml-auto flex min-w-0 items-center justify-end gap-2 overflow-hidden",It?"flex-1":"shrink-0"),children:[It?Os(!0):null,Qt?s.jsx(Zp,{prDirectory:fe,prNumber:Be,prStatusLabel:Ye,prIconColor:Pe}):null,ye>0?s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1",children:[s.jsx(P,{name:"node-tree",className:z}),s.jsx("span",{children:ye})]}):null,os?s.jsx("span",{className:"min-w-0 max-w-[80px] shrink-0 truncate",children:We}):null,Jt?s.jsx(Ii,{sessionId:ne.id,running:mt,className:"shrink-0 text-muted-foreground/70"}):null]}):null]}):null]})]}),s.jsxs("div",{className:_("absolute right-3 flex h-5 min-w-6 items-center justify-end",H?"top-1/2 -translate-y-1/2":"top-2",f===ne.id&&"hidden"),children:[s.jsx("div",{className:_("flex items-center justify-end",ct?"opacity-0":X?"group-hover:opacity-0 group-focus-within:opacity-0":null),children:Nt?s.jsx(yf,{label:"Session complete"}):s.jsx("span",{className:"text-[11px] text-muted-foreground/75 whitespace-nowrap",children:kt})}),X?s.jsx("div",{className:_("absolute inset-0 flex items-center justify-end",M||Fe?"opacity-100":"pointer-events-none opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100"),children:s.jsx(Fp,{archiveLabel:"Archive",deleteLabel:"Delete",buttonSizeClass:"h-6 w-6",iconSizeClass:"h-3.5 w-3.5",onPointerDown:is,onMouseDown:as,onArchive:ot,onDelete:Ot})}):null]})]}),tt?s.jsxs("span",{"data-session-working":!0,className:_("pointer-events-none absolute inset-y-0 right-0 flex items-center rounded-r-[inherit] pr-3 transition-opacity",X&&"group-hover:opacity-0 group-focus-within:opacity-0"),children:[s.jsx("span",{"aria-hidden":"true",className:"oc-session-row-working-aura absolute inset-y-0 right-0 w-24 rounded-r-[inherit] bg-gradient-to-l from-primary/15 to-transparent"}),s.jsxs("span",{className:"relative flex flex-col items-end gap-1",children:[s.jsx("span",{className:"flex h-5 items-center",children:s.jsx(ws,{variant:"inline",text:null,animationType:"spinner",speedMs:80,className:"text-primary text-xs shrink-0"})}),bt?s.jsx(Ii,{sessionId:ne.id,running:mt,className:"text-[11px] leading-4"}):null]})]}):null]}),hn]})}),Yt&&Ct?t.children.map(de=>{const F=Re?Re(de):{subtreeContainsEditing:V,menuOpenSessionId:je,nodeStructureKey:""};return s.jsx(a.Fragment,{children:G(de,n+1,me??r,o,i,B?.globalSession?{globalSession:!0}:void 0,xe,F)},de.session.id)}):null,s.jsx(Lp,{open:wt,onOpenChange:st,descendantCount:He,exportIncludeSubtasks:At,setExportIncludeSubtasks:ke,onExport:Oe})]},ne.id)}const tg=a.memo(eg,Jp),sg=({open:e,onOpenChange:t,project:n,onSave:r})=>s.jsx(ns,{open:e,onOpenChange:t,children:s.jsx(rs,{className:"w-full max-w-2xl gap-0 overflow-hidden p-0",children:s.jsx(As,{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:e&&n?s.jsx(Eh,{project:n,onIdentitySave:r}):null})})})});function nc(e){const{showDeletionDialog:t,setShowDeletionDialog:n,onCancel:r,onConfirm:o,confirmLabel:i}=e;return s.jsxs(Ts,{className:"w-full sm:items-center sm:justify-between",children:[s.jsxs("button",{type:"button",onClick:()=>n(!t),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":!t,children:[t?s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}),"Never ask"]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("button",{type:"button",onClick:r,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:"Cancel"}),s.jsx("button",{type:"button",onClick:()=>{o()},className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:i})]})]})}function ng(e){const{value:t,setValue:n,showDeletionDialog:r,setShowDeletionDialog:o,onConfirm:i}=e,l=c=>bs(c);return s.jsx(ns,{open:!!t,onOpenChange:c=>{c||n(null)},children:s.jsxs(rs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(vs,{children:[s.jsx(us,{children:t?.archivedBucket?"Delete session?":"Archive session?"}),s.jsx(Ss,{children:t&&t.descendantCount>0?t.archivedBucket?t.descendantCount===1?`"${l(t.session)}" and its ${t.descendantCount} sub-task will be permanently deleted.`:`"${l(t.session)}" and its ${t.descendantCount} sub-tasks will be permanently deleted.`:t.descendantCount===1?`"${l(t.session)}" and its ${t.descendantCount} sub-task will be archived.`:`"${l(t.session)}" and its ${t.descendantCount} sub-tasks will be archived.`:t?.archivedBucket?`"${t?.session?l(t.session):"Untitled Session"}" will be permanently deleted.`:`"${t?.session?l(t.session):"Untitled Session"}" will be archived.`})]}),s.jsx(nc,{showDeletionDialog:r,setShowDeletionDialog:o,onCancel:()=>n(null),onConfirm:i,confirmLabel:t?.archivedBucket?"Delete":"Archive"})]})})}function rg(e){const{value:t,setValue:n,showDeletionDialog:r,setShowDeletionDialog:o,onConfirm:i}=e,l=t?.archivedBucket===!0,c=t?.sessionCount??0,d=l?c===1?"Delete session?":"Delete sessions?":c===1?"Archive session?":"Archive sessions?",u=l?c===1?`${c} session will be permanently deleted.`:`${c} sessions will be permanently deleted.`:c===1?`${c} session will be archived.`:`${c} sessions will be archived.`;return s.jsx(ns,{open:!!t,onOpenChange:f=>{f||n(null)},children:s.jsxs(rs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(vs,{children:[s.jsx(us,{children:d}),s.jsx(Ss,{children:u})]}),s.jsx(nc,{showDeletionDialog:r,setShowDeletionDialog:o,onCancel:()=>n(null),onConfirm:i,confirmLabel:l?"Delete":"Archive"})]})})}function og(e){const{value:t,setValue:n,onConfirm:r}=e,{git:o}=Fs(),[i,l]=a.useState(null),[c,d]=a.useState(!1),[u,f]=a.useState(!1),[p,x]=a.useState(!1),y=t?.worktree.path??null;a.useEffect(()=>{let j=!1;return l(null),d(!1),f(!1),x(!1),!t||!y?()=>{j=!0}:(o.getGitStatus(y).then(k=>{if(!j){if(typeof k?.isClean!="boolean"){d(!0);return}l(k)}}).catch(()=>{j||d(!0)}),()=>{j=!0})},[o,t,y]);const m=i?.isClean===!1,h=(i?.ahead??0)>0,b=h&&!t?.worktree.branch,g=t?.worktree.branch?"The local branch will be kept.":"No local branch will be deleted.",S=!!(t&&i&&!c&&!t.hasActiveSession&&(!m&&!b||u)&&!p),v=t?.worktree.branch||t?.worktree.name||t?.worktree.path||"",E=async()=>{if(S){x(!0);try{await r({force:m})}finally{x(!1)}}};return s.jsx(ns,{open:!!t,onOpenChange:j=>{!j&&!p&&n(null)},children:s.jsxs(rs,{showCloseButton:!1,className:"max-w-md gap-5",children:[s.jsxs(vs,{children:[s.jsx(us,{children:"Close worktree?"}),s.jsx(Ss,{children:`Closing "${v}" removes its worktree directory. ${g}`})]}),c?s.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3",children:[s.jsx(P,{name:"alert",className:"mt-0.5 size-4 shrink-0 text-[var(--status-error)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:"Unable to check this worktree's status. Refresh and try again."})]}):i===null?s.jsx("p",{className:"typography-ui-label text-muted-foreground","aria-live":"polite",children:"Checking worktree status…"}):null,t?.hasActiveSession?s.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:[s.jsx(P,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:"Stop the active session before closing this worktree."})]}):null,m?s.jsxs("div",{className:"space-y-3 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(P,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:"This worktree has uncommitted changes. They will be permanently removed."})]}),s.jsxs("label",{className:"flex items-start gap-2 pl-6 typography-ui-label text-foreground",children:[s.jsx(oo,{checked:u,onChange:f,ariaLabel:"Confirm removal of uncommitted changes",className:"mt-0.5"}),s.jsx("span",{children:"I understand that the uncommitted changes will be lost."})]})]}):null,h?s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:i?.ahead===1?`This worktree has 1 unpushed commit. ${g}`:`This worktree has ${i?.ahead} unpushed commits. ${g}`}),b?s.jsxs("div",{className:"space-y-3 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(P,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:"Because this worktree is detached, its unpushed commits may be lost."})]}),s.jsxs("label",{className:"flex items-start gap-2 pl-6 typography-ui-label text-foreground",children:[s.jsx(oo,{checked:u,onChange:f,ariaLabel:"Confirm removal of unpushed detached commits",className:"mt-0.5"}),s.jsx("span",{children:"I understand that the unpushed commits may be lost."})]})]}):null]}):null,s.jsxs(Ts,{className:"sm:justify-end",children:[s.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>n(null),disabled:p,children:"Cancel"}),s.jsx(Ne,{variant:"destructive",size:"sm",onClick:()=>{E()},disabled:!S,children:p?"Closing…":"Close worktree"})]})]})})}function ig(e){const{value:t,setValue:n,onConfirm:r}=e;return s.jsx(ns,{open:!!t,onOpenChange:o=>{o||n(null)},children:s.jsxs(rs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(vs,{children:[s.jsx(us,{children:"Delete folder?"}),s.jsx(Ss,{children:t&&(t.subFolderCount>0||t.sessionCount>0)?t.subFolderCount>0?t.subFolderCount===1?`"${t.folderName}" will be deleted along with ${t.subFolderCount} sub-folder. Sessions inside will not be deleted.`:`"${t.folderName}" will be deleted along with ${t.subFolderCount} sub-folders. Sessions inside will not be deleted.`:`"${t.folderName}" will be deleted. Sessions inside will not be deleted.`:`"${t?.folderName??""}" will be permanently deleted.`})]}),s.jsxs(Ts,{children:[s.jsx("button",{type:"button",onClick:()=>n(null),className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:"Cancel"}),s.jsx("button",{type:"button",onClick:r,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:"Delete"})]})]})})}const ag=({updateDialogOpen:e,setUpdateDialogOpen:t,updateStore:n,editingProject:r,setEditingProjectDialogId:o,handleSaveProjectEdit:i,deleteSessionConfirm:l,setDeleteSessionConfirm:c,showDeletionDialog:d,setShowDeletionDialog:u,confirmDeleteSession:f,deleteFolderConfirm:p,setDeleteFolderConfirm:x,confirmDeleteFolder:y,closeWorktreeConfirm:m,setCloseWorktreeConfirm:h,confirmCloseWorktree:b,bulkDeleteConfirm:g,setBulkDeleteConfirm:S,confirmBulkDelete:v})=>s.jsxs(s.Fragment,{children:[s.jsx(bl,{open:e,onOpenChange:t,info:n.info,downloading:n.downloading,downloaded:n.downloaded,progress:n.progress,error:n.error,onDownload:n.downloadUpdate,onRestart:n.restartToUpdate,runtimeType:n.runtimeType}),s.jsx(sg,{open:!!r,onOpenChange:E=>{E||o(null)},project:r,onSave:i}),s.jsx(ng,{value:l,setValue:c,showDeletionDialog:d,setShowDeletionDialog:u,onConfirm:f}),s.jsx(ig,{value:p,setValue:x,onConfirm:y}),s.jsx(og,{value:m,setValue:h,onConfirm:b}),s.jsx(rg,{value:g,setValue:S,showDeletionDialog:d,setShowDeletionDialog:u,onConfirm:v})]}),lg=({directories:e})=>{const t=a.useMemo(()=>{const r=new Set;return e.forEach(o=>{const i=Ie(o)?.toLowerCase();i&&r.add(i)}),r},[e]);return An(r=>{for(const o of r.catalog.byId.values()){if(o.lifecycle!=="busy"&&o.lifecycle!=="retry")continue;const i=Ie(o.directory)?.toLowerCase();if(i&&t.has(i))return!0}return!1},void 0,"catalog")?s.jsx("span",{className:"inline-flex items-center","aria-label":"Session active",title:"Session active",children:s.jsx(ws,{variant:"inline",text:null,animationType:"spinner",speedMs:80,className:"text-primary text-xs shrink-0"})}):null},cg=e=>{let t=0;for(const n of e)for(const r of n.groups)r.isArchivedBucket||(t+=r.sessions.length);return t},dg=e=>{const t=new Map;for(const n of e){let r=0;for(const o of n.groups)o.isArchivedBucket||(r+=o.sessions.length);t.set(n.project.id,r)}return t},ug=(e,t)=>e.groups.some(n=>n.isArchivedBucket?!1:n.sessions.some(r=>t.has(r.session.id))),fg=(e,t)=>e.groups.some(n=>n.isArchivedBucket?!1:n.sessions.some(r=>t.has(r.session.id))),hg=(e,t)=>{const n=new Map;for(const r of e){const o=new Set;for(const i of r.groups){if(i.isArchivedBucket)continue;if(i.sessions.some(c=>t.has(c.session.id))&&i.directory){const c=Ie(i.directory)?.toLowerCase();c&&o.add(c)}}o.size>0&&n.set(r.project.id,o)}return n},mg=e=>e.map(t=>t.groups.some(n=>n.isArchivedBucket)?{...t,groups:t.groups.filter(n=>!n.isArchivedBucket)}:t),pg=(e,t,n,r)=>{if(!n)return t;const o=e.find(c=>c.project.id===n);if(!o)return[];const i=Ie(r??o.project.normalizedPath),l=o.groups.find(c=>!c.isArchivedBucket&&Ie(c.directory)===i);return l?[{...o,groups:[l]}]:[]},gg=(e,t)=>{const n=new Map,r=new Map;return e.forEach(o=>{const i=Wo(o.project.label?.trim()||Tn(o.project.normalizedPath,t)||o.project.normalizedPath);o.groups.forEach(l=>{const c=l.branch&&l.branch!=="HEAD"&&l.branch!==i?l.branch:null,d={projectLabel:i,branchLabel:c},u=f=>{f.forEach(p=>{const x=o.project.normalizedPath.length,y=r.get(p.session.id)??-1;x<y||(n.set(p.session.id,{node:p,projectId:o.project.id,groupDirectory:l.directory,secondaryMeta:d}),r.set(p.session.id,x),p.children.length>0&&u(p.children))})};u(l.sessions)})}),n};function bg({projectSections:e,flatSectionsForRender:t,sectionsForRender:n,selectedSpaceId:r,selectedWorktreePath:o,homeDirectory:i,activeSessionIdSet:l,unreadSessionIdSet:c}){const d=a.useMemo(()=>gg(e,i),[e,i]),u=a.useMemo(()=>mg(t),[t]),f=a.useMemo(()=>pg(n,u,r,o),[n,u,r,o]),p=a.useMemo(()=>cg(e),[e]),x=a.useMemo(()=>dg(e),[e]),y=a.useCallback(b=>{const g=e.find(S=>S.project.id===b);return g?ug(g,l):!1},[l,e]),m=a.useMemo(()=>hg(e,l),[l,e]),h=a.useCallback(b=>{const g=e.find(S=>S.project.id===b);return g?fg(g,c):!1},[e,c]);return{sessionSidebarMetaById:d,sectionsForSidebarRender:u,filteredSectionsForSidebarRender:f,totalSessionCount:p,sessionCountByProject:x,hasActiveSessionByProject:y,activeDirectoriesByProject:m,hasUnseenByProject:h}}const xg=({selectedCount:e,archivedBucket:t,onRestore:n,onDelete:r,onDone:o})=>{const i=t?"Delete":"Archive",l="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";return s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border pl-5 pr-3.5 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:`${e} selected`}),s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[t?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:l,"aria-label":"Restore",children:s.jsx(P,{name:"inbox-unarchive",className:"h-4 w-4"})})}),s.jsx(Ke,{side:"top",sideOffset:4,children:s.jsx("p",{children:"Restore"})})]}):null,s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:_("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"),"aria-label":i,children:s.jsx(P,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Ke,{side:"top",sideOffset:4,children:s.jsx("p",{children:i})})]}),s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:l,"aria-label":"Exit selection",children:s.jsx(P,{name:"close",className:"h-4 w-4"})})}),s.jsx(Ke,{side:"top",sideOffset:4,children:s.jsx("p",{children:"Exit selection"})})]})]})]})},yg=e=>{const{isInlineEditing:t,showDeletionDialog:n,foldersMap:r,folderScopesByProject:o,addSessionsToFolder:i,removeSessionsFromFolders:l,createFolderAndStartRename:c,archiveSessions:d,unarchiveSessions:u,deleteSessions:f,setBulkDeleteConfirm:p}=e,x=dt(R=>R.enabled),y=dt(R=>R.selectedIds.size),m=y>0,h=dt(R=>R.selectedIds),b=dt(R=>R.scopeKey),g=a.useCallback(()=>{dt.getState().toggleMode()},[]),S=a.useCallback(()=>{dt.getState().disable()},[]),v=a.useMemo(()=>{if(!m||typeof document>"u")return!1;let R=!1,I=!1;for(const M of h){const W=document.querySelectorAll(`[data-session-row="${CSS.escape(M)}"]`);for(const G of W)G.getAttribute("data-session-archived")==="1"?I=!0:R=!0}return I&&!R},[m,h]),E=a.useMemo(()=>{if(b)return b;if(!m||typeof document>"u")return null;for(const R of h){const M=document.querySelector(`[data-session-row="${CSS.escape(R)}"]`)?.getAttribute("data-session-scope");if(M&&M.length>0)return M}return null},[m,h,b]),j=a.useMemo(()=>{if(!E)return[];const R=o.get(E);return R&&R.length>0?R.map(I=>I.scopeKey):[E]},[E,o]),k=a.useMemo(()=>j.flatMap(R=>r[R]??[]),[r,j]),C=a.useCallback(R=>{for(const I of j)if((r[I]??[]).some(M=>M.id===R))return I;return null},[r,j]),w=a.useMemo(()=>{if(!m)return!1;for(const R of j)for(const I of r[R]??[])for(const M of I.sessionIds)if(h.has(M))return!0;return!1},[r,j,m,h]),N=a.useCallback((R,I)=>{const M=Array.from(h);for(const W of j)W!==R&&l(W,M);i(R,I,M)},[i,l,h,j]),T=a.useCallback(R=>{if(!m)return;const I=C(R);I&&N(I,R)},[m,N,C]),O=a.useCallback(()=>{const R=j[0];if(!R||!m)return;const I=c(R);I&&N(R,I.id)},[c,m,N,j]),$=a.useCallback(()=>{if(!m)return;const R=Array.from(h);for(const I of j)l(I,R)},[l,h,j,m]),U=a.useCallback(async()=>{const R=Array.from(h);if(R.length!==0){if(v){const{deletedIds:I,failedIds:M}=await f(R);I.length>0&&ie.success(I.length===1?`Deleted ${I.length} session`:`Deleted ${I.length} sessions`),M.length>0&&ie.error(M.length===1?`Failed to delete ${M.length} session`:`Failed to delete ${M.length} sessions`)}else{const{archivedIds:I,failedIds:M}=await d(R);I.length>0&&ie.success(I.length===1?`Archived ${I.length} session`:`Archived ${I.length} sessions`),M.length>0&&ie.error(M.length===1?`Failed to archive ${M.length} session`:`Failed to archive ${M.length} sessions`)}dt.getState().clear()}},[d,v,f,h]),K=a.useCallback(()=>{if(!m)return;const R=h.size;if(!n){U();return}p({sessionCount:R,archivedBucket:v})},[v,U,h,n,p,m]),L=a.useCallback(async()=>{if(!m||!v)return;const R=Array.from(h),{restoredIds:I,failedIds:M}=await u(R);I.length>0&&ie.success(I.length===1?`Restored ${I.length} session`:`Restored ${I.length} sessions`),M.length>0&&ie.error(M.length===1?`Failed to restore ${M.length} session`:`Failed to restore ${M.length} sessions`),dt.getState().clear()},[v,m,h,u]),D=a.useCallback(async()=>{p(null),await U()},[U]);return a.useEffect(()=>{if(!x)return;const R=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),I=M=>{if(t)return;const W=M.target;if(W&&(W.tagName==="INPUT"||W.tagName==="TEXTAREA"||W.isContentEditable))return;const G=R?M.metaKey:M.ctrlKey;if(M.key==="Escape"){M.preventDefault(),dt.getState().disable();return}if(G&&M.key==="Backspace"){M.preventDefault(),K();return}if(G&&(M.key==="a"||M.key==="A")){const B=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(B.length===0)return;M.preventDefault();const V=dt.getState().scopeKey??B[0]?.getAttribute("data-session-scope")??null,je=H=>V?H.getAttribute("data-session-scope")===V:!0,Re=B.filter(je).map(H=>H.getAttribute("data-session-row")).filter(H=>typeof H=="string"&&H.length>0);if(Re.length===0)return;dt.getState().replaceAll(Re,V||null)}};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[K,t,x]),{selectionModeEnabled:x,hasSelection:m,selectedIdsSize:y,bulkScopeIsArchived:v,derivedSelectionScope:E,bulkScopeFolders:k,bulkCanRemoveFromFolder:w,handleToggleSelectionMode:g,handleExitSelectionMode:S,handleBulkMoveToFolder:T,handleBulkCreateFolderAndMove:O,handleBulkRemoveFromFolder:$,handleBulkDelete:K,handleBulkRestore:L,confirmBulkDelete:D}},wg=(e,t)=>{const n=e??{};return delete n.projectSortOrder,t<4&&delete n.displayMode,t<5&&delete n.sessionGroupingMode,n},sa=Ls()(il(e=>({stickyZoneHeaders:!0,toggleStickyZoneHeaders:()=>e(t=>({stickyZoneHeaders:!t.stickyZoneHeaders})),showRecentSection:!0,showArchivedSessions:!1,setShowRecentSection:t=>e({showRecentSection:t}),setShowArchivedSessions:t=>e({showArchivedSessions:t}),toggleRecentSection:()=>e(t=>({showRecentSection:!t.showRecentSection})),toggleArchivedSessions:()=>e(t=>({showArchivedSessions:!t.showArchivedSessions}))}),{name:"pichamber:session-display-settings",version:6,migrate:wg})),na="oc.sessions.projectCollapse",ra="oc.sessions.groupOrder",oa="oc.sessions.groupCollapse",ia="oc.sessions.activeSessionByProject",aa="oc.sessions.expandedParents.v3",vg=new Set,Gr=[],Dt=e=>{const t=a.useRef(e);return t.current=e,a.useCallback((...n)=>t.current(...n),[])},Sg=({isVisible:e=!0,mobileVariant:t=!1,onSessionSelected:n,onNavigateAway:r,allowReselect:o=!1,hideDirectoryControls:i=!1,showOnlyMainWorkspace:l=!1})=>{uo("react.session_sidebar_render"),Kt("ui.session_sidebar.render"),Kt(`ui.session_sidebar.render.${t?"mobile":"desktop"}`),Kt(`ui.session_sidebar.render.${e?"visible":"hidden"}`);const[c,d]=a.useState(!1),[u,f]=a.useState(""),p=a.useRef(null),x=a.useRef(null),[y,m]=a.useState(null),[h,b]=a.useState(""),[g,S]=a.useState(null),[v,E]=a.useState(new Set),j=a.useMemo(()=>Kn(),[]),[k,C]=a.useState(new Set),w=Ws(A=>A.selectedSpaceId),N=Ws(A=>A.selectedWorktreePath),[T,O]=a.useState(new Map),[$,U]=a.useState(new Map),[K,L]=a.useState(!1),[D,R]=a.useState(null),[I,M]=a.useState(null),[W,G]=a.useState(""),[B,xe]=a.useState(null),[V,je]=a.useState(null),[Re,H]=a.useState(null),[z,Y]=a.useState(null),X=Ci(A=>A.ids),te=cu(a.useCallback(A=>e?A.rankById:za,[e])),ue=An(A=>e?du(A.catalog):"",void 0,"catalog"),he=a.useMemo(()=>ue?ue.split("|"):Gr,[ue]),Q=a.useMemo(()=>new Set(he),[he]),se=uu(ro(A=>e?Object.entries(A.index.session.unseenCount).filter(([,J])=>J>0).map(([J])=>J).sort():Gr)),ce=a.useMemo(()=>new Set(se),[se]),Ce=Ci(A=>A.toggle),[ve,Ge]=a.useState(()=>{try{const A=Kn().getItem(oa);if(!A)return new Set;const J=JSON.parse(A);return new Set(Array.isArray(J)?J.filter(Z=>typeof Z=="string"):[])}catch{return new Set}}),[q,ae]=a.useState(()=>{try{const A=Kn().getItem(ra);if(!A)return new Map;const J=JSON.parse(A),Z=new Map;return Object.entries(J).forEach(([Me,ze])=>{Array.isArray(ze)&&Z.set(Me,ze.filter(et=>typeof et=="string"))}),Z}catch{return new Map}}),ne=a.useMemo(()=>{try{const A=Kn().getItem(ia);if(!A)return new Map;const J=JSON.parse(A),Z=new Map;return Object.entries(J).forEach(([Me,ze])=>{typeof ze=="string"&&ze.length>0&&Z.set(Me,ze)}),Z}catch{return new Map}},[]),me=a.useCallback(A=>{try{j.setItem(ia,JSON.stringify(Object.fromEntries(A.entries())))}catch{}},[j]),[fe,Be]=a.useState(new Map),Se=a.useRef(0),ee=sn(A=>A.homeDirectory),we=sn(A=>A.currentDirectory),pe=ut(A=>A.projects),ye=ut(A=>A.activeProjectId),We=ut(A=>A.removeProject),qe=ut(A=>A.setActiveProjectIdOnly),Pe=ut(A=>A.updateProjectMeta),Ye=ut(A=>A.reorderProjects),re=le(A=>A.setActiveMainTab),Le=le(A=>A.setSettingsDialogOpen),nt=le(A=>A.setSettingsPage),at=le(A=>A.toggleHelpDialog),Ve=le(A=>A.setSessionSwitcherOpen),mt=le(A=>A.setArchivePageOpen),lt=le(A=>A.showDeletionDialog),qt=le(A=>A.setShowDeletionDialog),Yt=le(A=>A.sidebarViewMode),Ze=i||l||!Yu(Yt)?"workspace":Yt,Ct=le(A=>A.weekStartPreference),Vt=a.useMemo(()=>qh(Ct),[Ct]),kt=Jh(e&&Ze==="timeline",Vt),Ft=sa(A=>A.stickyZoneHeaders),gt=fu(u,120),wt=a.useMemo(()=>gt.trim().toLowerCase(),[gt]),st=wt.length>0,At=pt(A=>A.collapsedFolderIds),ke=pt(A=>A.foldersMap),He=pt(A=>A.getFoldersForScope),Ae=pt(A=>A.createFolder),Oe=pt(A=>A.renameFolder),Fe=pt(A=>A.deleteFolder),rt=pt(A=>A.addSessionToFolder),vt=pt(A=>A.addSessionsToFolder),Nt=pt(A=>A.removeSessionFromFolder),bt=pt(A=>A.removeSessionsFromFolders),ct=pt(A=>A.toggleFolderCollapse),tt=pt(A=>A.getSessionFolderId);lm({enabled:e,isSessionSearchOpen:c,setIsSessionSearchOpen:d,sessionSearchInputRef:x,sessionSearchContainerRef:p});const It=hu(e),{git:Et}=Fs(),os=An(A=>A.connection,void 0,"chrome"),Qt=An(A=>{for(const J of A.catalog.listStatusByDirectory.values())if(J==="ready")return!0;return!1},void 0,"catalog"),Jt=ao({archived:!1}),xt=ao({archived:!0}),Os=Te(A=>A.setCurrentSession),un=Te(A=>A.updateSessionTitle),Bs=Te(A=>A.shareSession),_s=Te(A=>A.unshareSession),Lt=lo(A=>A.projects),fs=lo(A=>A.refreshProject),St=a.useMemo(()=>mu(pe,{projects:Lt}),[pe,Lt]),is=a.useMemo(()=>{const A=new Map;for(const J of pe){const Z=Ie(J.path);if(!Z)continue;const Me=Lt.get(Z)?.error;Me&&A.set(Z,Me)}return A},[pe,Lt]);a.useEffect(()=>{if(!w)return;const A=pe.find(Z=>Z.id===w);if(!A){Ws.getState().clearSpaceSelection();return}if(!N)return;(St.get(Ie(A.path)??A.path)??[]).some(Z=>Ie(Z.path)===Ie(N))||(Ws.getState().clearSelectedWorktree(),ie.warning("The selected worktree is no longer available. Showing the project checkout instead."))},[St,pe,w,N]);const as=Te(A=>A.openNewSessionDraft),ot=a.useCallback(A=>{le.getState().closeMainSurfaces(),as(A),r?.()},[r,as]),Ot=er(ro(A=>({checkForUpdates:A.checkForUpdates,available:A.available,runtimeType:A.runtimeType,info:A.info,downloading:A.downloading,downloaded:A.downloaded,progress:A.progress,error:A.error,downloadUpdate:A.downloadUpdate,restartToUpdate:A.restartToUpdate}))),js=a.useMemo(()=>pu(pe,St,{includeWorktrees:!0}),[St,pe]),Rt=a.useMemo(()=>Jt.filter(A=>Sm(A,js,{allowUnknownDirectory:!0,allowEmptyDirectorySet:!0,homeDirectory:ee})),[Jt,ee,js]),fn=a.useMemo(()=>[...Rt,...xt],[xt,Rt]),zs=Mt(),hn=a.useMemo(()=>`${zs}|${pe.map(A=>`${A.id}:${Ie(A.path)??""}`).join("|")}`,[pe,zs]),de=a.useMemo(()=>{const A=new Set;let J=!0;for(const Z of pe){const Me=Ie(Z.path);if(!Me)continue;const ze=Lt.get(Me)?.status??"idle";ze==="failed"&&A.add(Me),(ze==="idle"||ze==="loading")&&(J=!1)}return{complete:J,unresolved:A}},[pe,Lt]),F=de.complete?hn:null,oe=!de.complete,be=de.unresolved,{isTablet:_e}=an(),Je=t||_e,Xe=am({mobileVariant:t,isTablet:_e}),{buildGroupSearchText:hs,filterSessionNodesForSearch:Bt,buildGroupedSessions:Nr}=im({homeDirectory:ee,pinnedSessionIds:X,sessionOrderRanks:te}),{scheduleCollapsedProjectsPersist:Xo}=dm({safeStorage:j,keys:{sessionExpanded:aa,projectCollapse:na,groupOrder:ra,groupCollapse:oa},groupOrderByProject:q,collapsedGroups:ve,setExpandedParents:E,setCollapsedProjects:C}),Us=a.useMemo(()=>gu(Rt,X,te),[X,te,Rt]),Ir=a.useMemo(()=>Us.map(A=>A.id).join("|"),[Us]),Zo=a.useRef(null),ei=a.useMemo(()=>{const A=Zo.current;if(A&&A.signature===Ir)return A.map;const J=new Map(Us.map((Z,Me)=>[Z.id,Me]));return Zo.current={signature:Ir,map:J},J},[Us,Ir]),lc=a.useMemo(()=>{const A=new Map;Us.forEach(Z=>{const Me=Z.parentID;if(!Me)return;const ze=A.get(Me)??[];ze.push(Z),A.set(Me,ze)});const J=Oa(X,te);return A.forEach(Z=>Z.sort(J)),A},[Us,X,te]),cc=a.useMemo(()=>s.jsx(ts,{icon:"chat-new",mobileVariant:t,onClick:()=>ot(),children:"New session"}),[t,ot]),dc=a.useMemo(()=>pe.find(A=>A.id===g)??null,[pe,g]),uc=a.useCallback(A=>{g&&Pe(g,{label:A.label,defaultModel:A.defaultModel??null})},[g,Pe]),fc=a.useCallback(()=>{const A=er.getState();if(A.available&&A.info){L(!0);return}Ot.checkForUpdates().then(()=>{const{available:J,error:Z}=er.getState();if(Z){ie.error("Failed to check for updates",{description:Z});return}if(!J){ie.success("You are on the latest version");return}L(!0)})},[Ot]),$s=bu(),ti=a.useCallback(()=>{if(t&&Ve(!1),r?.(),$s?.openSettings){$s.openSettings();return}Le(!0)},[$s,t,r,Ve,Le]),hc=Ot.available&&(Ot.runtimeType==="desktop"||Ot.runtimeType==="web"),mc=Te(A=>A.deleteSession),si=Te(A=>A.deleteSessions),pc=Te(A=>A.archiveSession),ni=Te(A=>A.archiveSessions),gc=Te(A=>A.unarchiveSession),bc=Te(A=>A.unarchiveSessions),{copiedSessionId:xc,handleSessionSelect:yc,handleSessionDoubleClick:wc,handleSaveEdit:vc,handleCancelEdit:Sc,handleShareSession:jc,handleCopyShareUrl:Cc,handleCopySessionId:kc,handleUnshareSession:Ac,handleDeleteSession:Nc,handleRestoreSession:Ic,confirmDeleteSession:Ec}=cm({mobileVariant:t,allowReselect:o,onSessionSelected:n,isSessionSearchOpen:c,sessionSearchQuery:u,setSessionSearchQuery:f,setIsSessionSearchOpen:d,setActiveMainTab:re,setSessionSwitcherOpen:Ve,setCurrentSession:Os,updateSessionTitle:un,shareSession:Bs,unshareSession:_s,deleteSession:mc,deleteSessions:si,archiveSession:pc,archiveSessions:ni,unarchiveSession:gc,childrenMap:lc,showDeletionDialog:lt,setDeleteSessionConfirm:xe,deleteSessionConfirm:B,setEditingId:m,setEditTitle:b,editingId:y,editTitle:h}),Rc=a.useCallback(()=>{if(!V)return;const{scopeKey:A,folderId:J}=V;je(null),Fe(A,J)},[V,Fe]),Er=a.useCallback(()=>{Ds.requestDirectoryDialog()},[]),Dc=a.useCallback(A=>{E(J=>{const Z=wf(J,A);try{j.setItem(aa,JSON.stringify(Array.from(Z)))}catch{}return Z})},[j]),ri=a.useCallback((A,J)=>{if(!A)return null;J&&At.has(J)&&ct(J);const Z=Ae(A,"New folder",J);return M(Z.id),G(Z.name),Z},[At,ct,Ae]),mn=Dt(yc),Pc=Dt(wc),Mc=Dt(vc),Tc=Dt(Sc),Fc=Dt(jc),Lc=Dt(Cc),Oc=Dt(kc),Bc=Dt(Ac),_c=Dt(Nc),zc=Dt(Ic),Rr=Dt(ri),oi=a.useCallback((A,J)=>{U(Z=>{const Me=new Map(Z);return Me.set(A,J+7),Me})},[]),zn=a.useCallback(A=>{U(J=>{if(!J.has(A))return J;const Z=new Map(J);return Z.delete(A),Z})},[]),ii=a.useCallback(A=>{U(J=>{let Z=!1;const Me=new Map(J),ze=`${A}:`;for(const et of Me.keys())et.startsWith(ze)&&(Me.delete(et),Z=!0);return Z?Me:J})},[]),Dr=a.useCallback(A=>{Se.current=Date.now()+150,ii(A),C(J=>{const Z=new Set(J);Z.has(A)?Z.delete(A):Z.add(A);try{j.setItem(na,JSON.stringify(Array.from(Z)))}catch{}return Xo(Z),Z})},[ii,j,Xo]),ai=a.useRef(null);a.useEffect(()=>{const A=ai.current;ai.current=ye,Ze==="folder"&&(!A||!ye||A===ye||k.has(ye)&&Dr(ye))},[ye,k,Ze,Dr]);const ms=a.useMemo(()=>pe.map(A=>({...A,normalizedPath:Ie(A.path)})).filter(A=>!!A.normalizedPath),[pe]),Uc=a.useMemo(()=>ms.map(A=>A.normalizedPath),[ms]),li=xu(e?Uc:Gr);gm({enabled:e,normalizedProjects:ms,gitRepoStatus:li,setProjectRepoStatus:O,setProjectRootBranches:Be});const ci=a.useMemo(()=>Cm(Rt,ms,St,xt),[xt,St,ms,Rt]);wm({enabled:e,hasAuthoritativeGlobalSessions:Qt,sessions:fn});const{getSessionsForProject:$c,getArchivedSessionsForProject:Kc}=bm({ownership:ci});Xh({enabled:e,normalizedProjects:ms,ownership:ci,hasAuthoritativeGlobalSessions:Qt,isWorktreeTopologyLoading:oe,unresolvedWorktreeProjectPaths:be,foldersMap:ke,createFolder:Ae,addSessionToFolder:rt});const di=a.useRef(!1);ye&&T.has(ye)&&(di.current=!!T.get(ye));const Wc=sa(A=>A.showArchivedSessions),Pr=ut(A=>A.manualProjectOrder),ui=a.useRef(new Set),Un=vf(ui.current,v,"project");ui.current=Un;const Mr={isVisible:e,mobileVariant:t,onSessionSelected:n,allowReselect:o,hideDirectoryControls:i,showOnlyMainWorkspace:l,isTablet:_e,catalogSessions:Jt,archivedSessions:xt,projects:pe,activeProjectId:ye,manualProjectOrder:Pr,currentDirectory:we,availableWorktreesByProject:St,pinnedSessionIds:X,sessionOrderRanks:te,foldersMap:ke,collapsedFolderIds:At,gitBranches:It,gitRepoStatus:li,updateStore:Ot,showArchivedSessions:Wc,projectRepoStatus:T,projectRootBranches:fe,resolvedWorktreeTopologyKey:F,unresolvedWorktreeProjectPaths:be,isSessionSearchOpen:c,sessionSearchQuery:u,editingId:y,editTitle:h,editingProjectDialogId:g,expandedParents:v,collapsedProjects:k,visibleSessionCountByGroup:$,updateDialogOpen:K,openSidebarMenuKey:D,renamingFolderId:I,renameFolderDraft:W,deleteSessionConfirm:B,deleteFolderConfirm:V,bulkDeleteConfirm:z,collapsedGroups:ve},fi=a.useRef(null),hi=fi.current;if(hi){let A=!1;for(const J of Object.keys(Mr))Object.is(hi[J],Mr[J])||(Kt(`ui.session_sidebar.source.${J}`),A=!0);A||Kt("ui.session_sidebar.source.parent_or_context")}fi.current=Mr;const Gc=a.useMemo(()=>{const A=new Map(Pr.map((J,Z)=>[J,Z]));return[...ms].sort((J,Z)=>(A.get(J.id)??1/0)-(A.get(Z.id)??1/0))},[Pr,ms]),{projectSections:_t,groupSearchDataByGroup:mi,sectionsForRender:Hc,flatSectionsForRender:Tr,searchMatchCount:qc}=em({normalizedProjects:Gc,getSessionsForProject:$c,getArchivedSessionsForProject:Kc,availableWorktreesByProject:St,projectRepoStatus:T,projectRootBranches:fe,lastRepoStatus:di.current,buildGroupedSessions:Nr,hasSessionSearchQuery:st,normalizedSessionSearchQuery:wt,filterSessionNodesForSearch:Bt,buildGroupSearchText:hs,foldersMap:ke}),pn=a.useMemo(()=>{const A=Rt.filter(Z=>wr(Nn(Z),ee));if(A.length===0)return null;const J=Nr(A,"~",[],null,!1).map(Z=>st?{...Z,sessions:Bt(Z.sessions,wt)}:Z).filter(Z=>Z.sessions.length>0&&!Z.isArchivedBucket);return J.length===0?null:{project:{id:"__home__",path:"~",normalizedPath:"~",label:"No folder"},groups:J}},[Nr,Bt,st,ee,wt,Rt]),Yc=a.useMemo(()=>{if(!st||!pn)return 0;const A=J=>J.reduce((Z,Me)=>Z+1+A(Me.children),0);return pn.groups.reduce((J,Z)=>J+A(Z.sessions),0)},[pn,st]),Vc=a.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:"No matching sessions"}),s.jsx("p",{className:"typography-meta mt-1",children:"Try a different title, branch, folder, or path."})]}),[]),{getOrderedGroups:Qc}=Zh(q),pi=a.useRef(!1);a.useEffect(()=>{if(pi.current||_t.length===0)return;const A=_t.flatMap(J=>J.groups.filter(Z=>Z.isArchivedBucket).map(Z=>`${J.project.id}:${Z.id}`));A.length>0&&Ge(J=>new Set([...J,...A])),pi.current=!0},[_t]);const{sectionsForSidebarRender:Jc,filteredSectionsForSidebarRender:Xc,totalSessionCount:Zc,sessionCountByProject:ed,hasActiveSessionByProject:td,activeDirectoriesByProject:gn,hasUnseenByProject:sd}=bg({projectSections:_t,flatSectionsForRender:Tr,sectionsForRender:Hc,selectedSpaceId:w,selectedWorktreePath:N,homeDirectory:ee,activeSessionIdSet:Q,unreadSessionIdSet:ce}),Fr=a.useCallback(A=>{if(Ws.getState().selectSpace(A),!A)return;qe(A);const J=_t.find(ze=>ze.project.id===A),Z=J?.groups.find(ze=>ze.isMain),Me=Z?.sessions[0]?.session;Me?mn(Me.id,Z?.directory??J?.project.normalizedPath??null,{keepPanelOpen:!0}):J&&ot({selectedProjectId:A,directoryOverride:J.project.normalizedPath})},[ot,_t,qe,mn]),nd=t?"flex size-10 shrink-0 items-center justify-center rounded-full leading-none text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary 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",rd=t?"size-5":"size-4",$n=Dt((A,J=0,Z,Me,ze=!1,et,Xt="project",Ks)=>s.jsx(tg,{node:A,depth:J,groupDirectory:Z,projectId:Me,archivedBucket:ze,pinnedSessionIds:X,expandedParents:Un,hasSessionSearchQuery:st,normalizedSessionSearchQuery:wt,editingId:y,setEditingId:m,editTitle:h,setEditTitle:b,handleSaveEdit:Mc,handleCancelEdit:Tc,toggleParent:Dc,handleSessionSelect:mn,handleSessionDoubleClick:Pc,togglePinnedSession:Ce,handleShareSession:Fc,copiedSessionId:xc,handleCopyShareUrl:Lc,handleCopySessionId:Oc,handleUnshareSession:Bc,openSidebarMenuKey:D,setOpenSidebarMenuKey:R,renamingFolderId:I,getFoldersForScope:He,getSessionFolderId:tt,removeSessionFromFolder:Nt,addSessionToFolder:rt,createFolderAndStartRename:Rr,handleDeleteSession:_c,handleRestoreSession:zc,mobileVariant:t,alwaysShowActions:Je,allowQuickArchiveAction:Xe,renderSessionNode:$n,secondaryMeta:et,renderContext:Xt,subtreeContainsEditing:Ks?.subtreeContainsEditing??vg,menuOpenSessionId:Ks?.menuOpenSessionId??null,nodeStructureKey:Ks?.nodeStructureKey??"",childRenderExtrasFor:Ks?.childRenderExtrasFor})),od=a.useMemo(()=>{const A=new Map;return Tr.forEach(J=>{const Z=J.groups.find(Me=>!Me.isArchivedBucket);Z?.folderScopes&&Z.folderScopes.length>0&&A.set(J.project.id,Z.folderScopes)}),A},[Tr]),id=a.useCallback((A,J)=>{const Z=[];return J.forEach(Me=>{Me.isArchivedBucket||(Z.push(Me.directory),Me.folderScopes?.forEach(ze=>Z.push(ze.directory)))}),s.jsx(lg,{directories:Z})},[]),gi=a.useCallback(A=>{zn(A),Ge(J=>{const Z=new Set(J);return Z.has(A)?Z.delete(A):Z.add(A),Z})},[zn]),ad=a.useCallback((A,J,Z,Me,ze,et,Xt)=>s.jsx(hp,{group:A,groupKey:J,projectId:Z,hideGroupLabel:Me,dragHandleProps:ze,compactBodyPadding:et,hasSessionSearchQuery:st,normalizedSessionSearchQuery:wt,groupSearchDataByGroup:mi,visibleSessionCount:$.get(J),collapsedGroups:ve,hideDirectoryControls:i,collapsedFolderIds:At,toggleFolderCollapse:ct,renameFolder:Oe,deleteFolder:Fe,showDeletionDialog:lt,setDeleteFolderConfirm:je,renderSessionNode:$n,showMoreGroupSessions:oi,resetGroupSessionLimit:zn,mobileVariant:t,alwaysShowActions:Je,activeProjectId:ye,setActiveProjectIdOnly:qe,setActiveMainTab:re,setSessionSwitcherOpen:Ve,openNewSessionDraft:ot,addSessionToFolder:rt,createFolderAndStartRename:Rr,renamingFolderId:I,renameFolderDraft:W,setRenameFolderDraft:G,setRenamingFolderId:M,pinnedSessionIds:X,expandedParents:Un,sessionOrderIndex:ei,editingId:y,editTitle:h,openSidebarMenuKey:D,activeActivitySessionIds:Q,unreadActivitySessionIds:ce,onToggleCollapsedGroup:gi,scrollContainerRef:Xt}),[st,wt,mi,$,ve,i,At,ct,Oe,Fe,lt,$n,oi,zn,t,Je,ye,qe,re,Ve,ot,rt,Rr,I,W,X,Un,ei,y,h,D,Q,ce,gi]),bi=!!(I||y||g),{selectionModeEnabled:Lr,hasSelection:xi,selectedIdsSize:ld,bulkScopeIsArchived:cd,derivedSelectionScope:dd,bulkScopeFolders:ud,bulkCanRemoveFromFolder:fd,handleToggleSelectionMode:hd,handleExitSelectionMode:md,handleBulkMoveToFolder:pd,handleBulkCreateFolderAndMove:gd,handleBulkRemoveFromFolder:bd,handleBulkDelete:xd,handleBulkRestore:yd,confirmBulkDelete:wd}=yg({isInlineEditing:bi,showDeletionDialog:lt,foldersMap:ke,folderScopesByProject:od,addSessionsToFolder:vt,removeSessionsFromFolders:bt,createFolderAndStartRename:ri,archiveSessions:ni,unarchiveSessions:bc,deleteSessions:si,setBulkDeleteConfirm:Y}),yi=a.useCallback(()=>{le.getState().closeMainSurfaces(),re("chat"),t&&Ve(!1),as(),r?.()},[t,r,as,re,Ve]),vd=a.useCallback((A,J)=>{const Z=pe.find(et=>et.id===A);if(!Z)return;const Me=Ie(J.path)?.toLowerCase(),ze=!!(Me&&gn.get(A)?.has(Me));H({projectId:A,projectPath:Z.path,worktree:J,hasActiveSession:ze})},[gn,pe]),Sd=a.useCallback(async({force:A})=>{const J=Re;if(!J)return;const Z=Ie(J.worktree.path)?.toLowerCase();if(!!(Z&&gn.get(J.projectId)?.has(Z))){H({...J,hasActiveSession:!0}),ie.warning("Stop the active session before closing this worktree.");return}if(!Et.deleteGitWorktree){ie.error("Closing worktrees is not supported by this runtime.");return}try{if(!(await Et.deleteGitWorktree(J.projectPath,{directory:J.worktree.path,force:A}))?.success)throw new Error("Git worktree removal was not confirmed by the server.");let et=await fs(J.projectPath,Et,{force:!0});const Xt=Ie(J.worktree.path);et!==null&&Xt!==null&&et.some(Cd=>Ie(Cd.path)===Xt)&&(et=await fs(J.projectPath,Et,{force:!0}));const Ks=Xt!==null&&Ie(we)===Xt,jd=Xt!==null&&w===J.projectId&&Ie(N)===Xt;(Ks||jd)&&Fr(J.projectId),H(null),et===null?ie.warning("Worktree closed, but the sidebar could not be refreshed."):ie.success("Worktree closed.")}catch(ze){const et=ze instanceof Error?ze.message:"Try again.";ie.error("Failed to close worktree.",{description:et})}},[gn,Re,we,Et,Fr,fs,w,N]);return s.jsx(yu,{delay:400,closeDelay:150,timeout:600,children:s.jsxs("div",{ref:p,className:_("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[s.jsx(sm,{projectSections:_t,activeProjectId:ye,initialActiveSessionByProject:ne,persistActiveSessionByProject:me,handleSessionSelect:mn,mobileVariant:t,openNewSessionDraft:as,setActiveMainTab:re,setSessionSwitcherOpen:Ve}),!i&&!t?s.jsx(pp,{onNewSession:yi,showSidebarToggle:!0}):null,s.jsx(mp,{hideDirectoryControls:i,handleOpenDirectoryDialog:Er,onOpenArchive:()=>{t&&Ve(!1),mt(!0)},onOpenSettings:t?ti:void 0,onOpenInstances:t?$s?.openInstances:void 0,instanceLabel:t?$s?.instanceLabel:void 0,onOpenUpdate:t?$s?.openUpdate:void 0,headerActionIconClass:rd,headerActionButtonClass:nd,isSessionSearchOpen:c,setIsSessionSearchOpen:d,sessionSearchInputRef:x,sessionSearchQuery:u,setSessionSearchQuery:f,hasSessionSearchQuery:st,searchMatchCount:qc+(Ze!=="workspace"||w===null?Yc:0),selectionModeEnabled:Lr,onToggleSelectionMode:hd,mobileVariant:t}),os==="error"||os==="unavailable"?s.jsx("div",{role:"alert",className:"mx-2 mb-2 rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-2 text-xs text-foreground",children:"Unable to reach server"}):null,!i&&_t.length>0&&Ze==="workspace"?s.jsx(xp,{projects:_t.map(A=>A.project),selectedProjectId:w,selectedWorktreePath:N,worktreesByProject:St,worktreeErrorsByProject:is,onSelectProject:Fr,onSelectWorktree:(A,J)=>{Ws.getState().selectWorktree(A,J),qe(A);const ze=_t.find(et=>et.project.id===A)?.groups.find(et=>Ie(et.directory)===Ie(J))?.sessions[0]?.session;ze?mn(ze.id,J,{keepPanelOpen:!0}):ot({selectedProjectId:A,directoryOverride:J})},onCloseWorktree:vd,onOpenDirectoryDialog:Er,onOpenProjectEditDialog:S,onRemoveProject:We,totalSessionCount:Zc,getSessionCountForProject:A=>ed.get(A)??0,hasActiveSessionByProject:td,activeDirectoriesByProject:gn,hasUnseenByProject:sd,homeDirectory:ee,mobileVariant:t}):null,s.jsx(kp,{viewMode:Ze,timelineBoundaries:kt,onOpenDirectoryDialog:Er,stickyFolderHeaders:Ft,sectionsForRender:Ze==="workspace"?Xc:Jc,allFoldersOnlySection:Ze==="workspace"?w===null?pn:null:pn,isAllFoldersView:Ze==="workspace"?w===null:Ze==="timeline",projectSections:_t,activeProjectId:ye,showOnlyMainWorkspace:l,hasSessionSearchQuery:st,emptyState:cc,searchEmptyState:Vc,pinnedSessionIds:X,renderSessionNode:$n,renderGroupSessions:ad,homeDirectory:ee,collapsedProjects:k,hideDirectoryControls:i,projectRepoStatus:T,mobileVariant:t,alwaysShowActions:Je,toggleProject:Dr,setActiveProjectIdOnly:qe,setActiveMainTab:re,setSessionSwitcherOpen:Ve,openNewSessionDraft:ot,openProjectEditDialog:S,removeProject:We,reorderProjects:Ye,getOrderedGroups:Qc,setGroupOrderByProject:ae,renderProjectStatusIndicator:id,openSidebarMenuKey:D,setOpenSidebarMenuKey:R,isInlineEditing:bi}),t&&!(Lr&&xi)?s.jsxs("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 flex flex-col gap-2 bg-gradient-to-t from-sidebar via-sidebar/85 to-transparent px-4 pb-[calc(0.75rem+var(--oc-safe-area-bottom,0px))] pt-10",children:[s.jsx(Al,{variant:"mobile"}),s.jsx(Ne,{type:"button",variant:"default",size:"lg",className:"pointer-events-auto w-full shadow-lg",onClick:yi,"aria-label":"New session",children:s.jsx(P,{name:"chat-new",className:"size-4"})})]}):null,Lr&&xi?s.jsx(xg,{selectedCount:ld,scopeKey:dd,scopeFolders:ud,archivedBucket:cd,onMoveToFolder:pd,onCreateFolderAndMove:gd,onRemoveFromFolder:bd,canRemoveFromFolder:fd,onRestore:yd,onDelete:xd,onDone:md}):null,t?null:s.jsx(yp,{onOpenSettings:ti,onOpenShortcuts:at,onOpenAbout:()=>{nt("about"),Le(!0)},onOpenUpdate:fc,showRuntimeButtons:!0,showUpdateButton:hc}),s.jsx(ag,{updateDialogOpen:K,setUpdateDialogOpen:L,updateStore:Ot,editingProject:dc,setEditingProjectDialogId:S,handleSaveProjectEdit:uc,deleteSessionConfirm:B,setDeleteSessionConfirm:xe,showDeletionDialog:lt,setShowDeletionDialog:qt,confirmDeleteSession:Ec,deleteFolderConfirm:V,setDeleteFolderConfirm:je,confirmDeleteFolder:Rc,closeWorktreeConfirm:Re,setCloseWorktreeConfirm:H,confirmCloseWorktree:Sd,bulkDeleteConfirm:z,setBulkDeleteConfirm:Y,confirmBulkDelete:wd})]})})},ny=a.memo(Sg),la=6,Pt=.18,jn=1.2,Cn=.38,or=48,jg=(e,t)=>e==="left"?t<0:t>0,ry=(e,t,n)=>Math.min(1,Math.max(0,e==="left"?1+t/n:1-t/n)),oy=(e,t)=>t>=.999?"none":e==="left"?`translateX(${(t-1)*100}%)`:`translateX(${(1-t)*100}%)`,ca=(e,t,n,r)=>e==="left"?t?Math.min(1,Math.max(0,1+n/r)):Math.min(1,Math.max(0,n/r)):t?Math.min(1,Math.max(0,1-n/r)):Math.min(1,Math.max(0,-n/r)),iy=e=>{const{side:t,dx:n,dy:r,dt:o,progress:i,isDragging:l}=e,c=n/Math.max(1,o);if(l){const d=t==="left"?c<-Pt:c>Pt,u=t==="left"?c>Pt:c<-Pt;return d||!u&&i<Cn}return Math.abs(n)>=or&&Math.abs(r)<=Math.abs(n)*jn&&jg(t,n)},Cg=e=>{const{side:t,isOpenAtStart:n,dx:r,dt:o,progress:i}=e,l=r/Math.max(1,o);return t==="left"?n?l<-Pt?!1:l>Pt?!0:i>Cn:l>Pt?!0:l<-Pt?!1:i>Cn:n?l>Pt?!1:l<-Pt?!0:i>Cn:l<-Pt?!0:l>Pt?!1:i>Cn},kg='button, a, input, textarea, select, [contenteditable="true"], [data-no-drawer-swipe]',Ag=(e,t,n)=>{if(!(e instanceof Element))return!1;if(n?.excludeInteractive??!0){const i=e.closest(kg);if(i&&t.contains(i))return!0}else{const i=e.closest("[data-no-drawer-swipe]");if(i&&t.contains(i))return!0}let o=e;for(;o&&o!==t;){if(o instanceof HTMLElement&&o.scrollWidth>o.clientWidth){const i=getComputedStyle(o).overflowX;if(i==="auto"||i==="scroll")return!0}o=o.parentElement}return!1},ir=Object.freeze({chunks:Object.freeze([]),byteLength:0,lastSequence:-1}),Fo=512*1024,Ng=new TextEncoder,Ig=new TextDecoder,Hr=e=>{const t=Ng.encode(e);if(t.byteLength<=Fo)return{text:e,byteLength:t.byteLength};let n=t.byteLength-Fo;for(;n<t.byteLength&&(t[n]&192)===128;)n+=1;const r=t.subarray(n);return{text:Ig.decode(r),byteLength:r.byteLength}},Hs=(e,t)=>`${e}\0${t}`,qr=(e,t)=>{let n=null;for(const r of e.keys())t(r)&&(n??=new Map(e),n.delete(r));return n},Eg="terminal-store";let da=!1,ua=0;const Zn=()=>typeof globalThis.crypto?.randomUUID=="function"?`tab-${globalThis.crypto.randomUUID()}`:(ua+=1,`tab-${Date.now().toString(36)}-${ua.toString(36)}`),Yr=e=>typeof e=="object"&&e!==null,Rg=e=>{const t=/^tab-(\d+)$/.exec(e);if(!t)return null;const n=Number(t[1]);return Number.isFinite(n)?n:null};function it(e){let t=e.trim();for(;t.length>1&&t.endsWith("/");)t=t.slice(0,-1);return t}const Dg=/^Terminal(?: (\d+))?$/,Pg=e=>{let t=0;for(const n of e){const r=Dg.exec(n.label);if(!r)continue;const o=r[1]?Number.parseInt(r[1],10):1;Number.isSafeInteger(o)&&(t=Math.max(t,o))}return t===0?"Terminal":`Terminal ${t+1}`},Vr=(e,t)=>({id:e,terminalSessionId:null,lifecycle:"idle",label:t,iconKey:null,isConnecting:!1,createdAt:Date.now(),previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1}),Qr=e=>({tabs:[e],activeTabId:e.id}),zt=(e,t)=>e.tabs.findIndex(n=>n.id===t);let Jr=null,Xr=null;const Mg=e=>{if(Xr&&Jr?.sessions===e.sessions&&Jr.nextTabId===e.nextTabId)return Xr;const t={sessions:Array.from(e.sessions.entries()).map(([n,r])=>[n,{activeTabId:r.activeTabId,tabs:r.tabs.map(o=>({id:o.id,label:o.label,iconKey:o.iconKey,createdAt:o.createdAt}))}]),nextTabId:e.nextTabId};return Jr={sessions:e.sessions,nextTabId:e.nextTabId},Xr=t,t},Tg=()=>{const e=Sf(()=>Vu());if(!e)return;let t=null;return{getItem:n=>e.getItem(n),setItem:(n,r)=>{if(r.state!==t)return t=r.state,e.setItem(n,r)},removeItem:n=>(t=null,e.removeItem(n))}},ge=Ls()(vr(il((e,t)=>({sessions:new Map,buffers:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=it(n);r&&e(o=>{if(o.sessions.has(r))return o;const i=new Map(o.sessions),l=Zn(),c=Vr(l,"Terminal");return i.set(r,Qr(c)),{sessions:i,nextTabId:o.nextTabId+1}})},getDirectoryState:n=>{const r=it(n);return t().sessions.get(r)},getActiveTab:n=>{const r=it(n),o=t().sessions.get(r);if(!o)return;const i=o.activeTabId;return i?o.tabs.find(l=>l.id===i)??o.tabs[0]:o.tabs[0]},getBuffer:(n,r)=>t().buffers.get(Hs(it(n),r))??ir,createTab:n=>{const r=it(n);if(!r)return"tab-invalid";const o=Zn();return e(i=>{const l=new Map(i.sessions),c=l.get(r),d=i.nextTabId+1,u=Pg(c?.tabs??[]),f=Vr(o,u);return c?l.set(r,{...c,tabs:[...c.tabs,f]}):l.set(r,Qr(f)),{sessions:l,nextTabId:d}}),o},setActiveTab:(n,r)=>{const o=it(n);e(i=>{const l=new Map(i.sessions),c=l.get(o);return!c||c.activeTabId===r||zt(c,r)<0?i:(l.set(o,{...c,activeTabId:r}),{sessions:l})})},setTabLabel:(n,r,o)=>{const i=it(n),l=o.trim();l&&e(c=>{const d=new Map(c.sessions),u=d.get(i);if(!u)return c;const f=zt(u,r);if(f<0||u.tabs[f]?.label===l)return c;const p=[...u.tabs];return p[f]={...p[f],label:l},d.set(i,{...u,tabs:p}),{sessions:d}})},setTabIconKey:(n,r,o)=>{const i=it(n);e(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const u=zt(d,r);if(u<0)return l;const f=o?.trim()||null;if(d.tabs[u]?.iconKey===f)return l;const p=[...d.tabs];return p[u]={...p[u],iconKey:f},c.set(i,{...d,tabs:p}),{sessions:c}})},closeTab:(n,r)=>{const o=it(n);e(i=>{const l=new Map(i.sessions),c=l.get(o);if(!c)return i;const d=zt(c,r);if(d<0)return i;const u=c.tabs.filter(h=>h.id!==r),f=Object.fromEntries(Object.entries(i.projectActionRuns).filter(([,h])=>!(h.directory===o&&h.tabId===r))),p=Object.keys(f).length!==Object.keys(i.projectActionRuns).length,x=Hs(o,r),y=i.buffers.has(x)?qr(i.buffers,h=>h===x):null;if(u.length===0){const h=Zn(),b=Vr(h,"Terminal");return l.set(o,Qr(b)),{sessions:l,nextTabId:i.nextTabId+1,...y?{buffers:y}:{},...p?{projectActionRuns:f}:{}}}let m=c.activeTabId;return c.activeTabId===r&&(m=u[Math.min(d,u.length-1)]?.id??u[0]?.id??null),l.set(o,{...c,tabs:u,activeTabId:m}),{sessions:l,...y?{buffers:y}:{},...p?{projectActionRuns:f}:{}}})},setTabSessionId:(n,r,o)=>{const i=it(n);e(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const u=zt(d,r);if(u<0)return l;const f=d.tabs[u],p=o!==null&&f.terminalSessionId!==o,x=o?"running":f.terminalSessionId?"exited":f.lifecycle,y={...f,terminalSessionId:o,lifecycle:x,isConnecting:!1},m=Hs(i,r),h=p&&l.buffers.has(m)?qr(l.buffers,g=>g===m):null,b=[...d.tabs];return b[u]=y,c.set(i,{...d,tabs:b}),{sessions:c,...h?{buffers:h}:{}}})},setTabLifecycle:(n,r,o)=>{const i=it(n);e(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const u=zt(d,r);if(u<0)return l;const f=[...d.tabs];return f[u]={...f[u],lifecycle:o,isConnecting:!1},c.set(i,{...d,tabs:f}),{sessions:c}})},setConnecting:(n,r,o)=>{const i=it(n);e(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const u=zt(d,r);if(u<0)return l;const f=[...d.tabs];return f[u]={...f[u],isConnecting:o},c.set(i,{...d,tabs:f}),{sessions:c}})},replaceBuffer:(n,r,o,i)=>{const l=it(n);e(c=>{const d=c.sessions.get(l);if(!d||zt(d,r)<0)return c;const u=Hs(l,r),f=c.buffers.get(u)??ir;if(f.lastSequence>i)return c;const p=Hr(o);if(f.lastSequence===i&&f.byteLength===p.byteLength&&f.chunks.map(m=>m.data).join("")===p.text)return c;const x=c.nextChunkId,y=new Map(c.buffers);return y.set(u,{chunks:p.text?[{id:x,data:p.text,byteLength:p.byteLength}]:[],byteLength:p.byteLength,lastSequence:i}),{buffers:y,nextChunkId:p.text?x+1:x}})},appendToBuffer:(n,r,o,i,l)=>{if(!o)return;const c=it(n);e(d=>{const u=d.sessions.get(c);if(!u||zt(u,r)<0)return d;const f=Hs(c,r),p=d.buffers.get(f)??ir;if(i!==void 0&&i<=p.lastSequence)return d;const x=d.nextChunkId,y=Hr(o),m=l!==void 0&&l!==o?Hr(l).text:void 0,h={id:x,data:y.text,...m!==void 0?{replayData:m}:{},byteLength:y.byteLength},b=[...p.chunks,h];let g=p.byteLength+h.byteLength;for(;g>Fo&&b.length>1;){const v=b.shift();if(!v)break;g-=v.byteLength}const S=new Map(d.buffers);return S.set(f,{chunks:b,byteLength:g,lastSequence:i??p.lastSequence}),{buffers:S,nextChunkId:x+1}})},setTabPreviewUrl:(n,r,o,i={})=>{const l=it(n);e(c=>{const d=new Map(c.sessions),u=d.get(l);if(!u)return c;const f=zt(u,r);if(f<0)return c;const p=u.tabs[f],x=i.autoOpened??p.previewAutoOpened,y=i.locked??p.previewUrlLocked;if(p.previewUrl===o&&p.previewAutoOpened===x&&p.previewUrlLocked===y)return c;const m=[...u.tabs];return m[f]={...p,previewUrl:o,previewAutoOpened:x,previewUrlLocked:y},d.set(l,{...u,tabs:m}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const o=it(n);e(i=>{const l=new Map(i.sessions),c=l.get(o);if(!c)return i;const d=zt(c,r);if(d<0)return i;const u=c.tabs[d];if(!u.previewUrl||u.previewAutoOpened)return i;const f=[...c.tabs];return f[d]={...u,previewAutoOpened:!0},l.set(o,{...c,tabs:f}),{sessions:l}})},setProjectActionRun:n=>{e(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)=>{e(o=>{const i=o.projectActionRuns[n];return!i||i.status===r?o:{projectActionRuns:{...o.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{e(r=>{if(!r.projectActionRuns[n])return r;const o={...r.projectActionRuns};return delete o[n],{projectActionRuns:o}})},removeDirectory:n=>{const r=it(n);e(o=>{const i=new Map(o.sessions);i.delete(r);const l=Hs(r,""),c=qr(o.buffers,u=>u.startsWith(l)),d=Object.fromEntries(Object.entries(o.projectActionRuns).filter(([,u])=>u.directory!==r));return{sessions:i,...c?{buffers:c}:{},projectActionRuns:d}})},clearAll:()=>{e({sessions:new Map,buffers:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:Eg,storage:Tg(),partialize:Mg,merge:(e,t)=>{if(!Yr(e))return t;const n=Array.isArray(e.sessions)?e.sessions:[],r=new Map;let o=0;for(const c of n){if(!Array.isArray(c)||c.length!==2)continue;const[d,u]=c;if(typeof d!="string"||!Yr(u))continue;const f=Array.isArray(u.tabs)?u.tabs:[],p=[],x=new Map;for(const b of f){if(!Yr(b))continue;const g=typeof b.id=="string"?b.id:null;if(!g)continue;const S=Rg(g);S!==null&&(o=Math.max(o,S));const v=S===null?g:Zn();x.set(g,v),p.push({id:v,label:typeof b.label=="string"?b.label:"Terminal",iconKey:typeof b.iconKey=="string"?b.iconKey:null,terminalSessionId:null,lifecycle:"idle",createdAt:typeof b.createdAt=="number"?b.createdAt:Date.now(),isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(p.length===0)continue;const y=typeof u.activeTabId=="string"?u.activeTabId:null,m=y?x.get(y)??y:null,h=m?p.some(b=>b.id===m):!1;r.set(d,{tabs:p,activeTabId:h?m:p[0].id})}const i=typeof e.nextTabId=="number"&&Number.isFinite(e.nextTabId)?e.nextTabId:1,l=Math.max(t.nextTabId,i,o+1);return{...t,sessions:r,buffers:new Map,nextChunkId:1,nextTabId:l,hasHydrated:!0}}})));if(typeof window<"u"&&!da){da=!0;const e=ge.persist,t=()=>{ge.getState().hasHydrated||ge.setState({hasHydrated:!0})};e?.hasHydrated?.()?t():e?.onFinishHydration?e.onFinishHydration(t):t()}function Fg(e){const{colors:t}=e,n=t.syntax.base;return{background:t.surface.background,foreground:n.foreground,cursor:t.interactive.cursor,cursorAccent:t.surface.background,selectionBackground:t.interactive.selection,selectionForeground:t.interactive.selectionForeground,selectionInactiveBackground:t.interactive.selection+"50",black:t.surface.muted,red:t.status.error,green:t.status.success,yellow:t.status.warning,blue:n.function,magenta:n.keyword,cyan:n.type,white:n.foreground,brightBlack:n.comment,brightRed:t.status.error,brightGreen:t.status.success,brightYellow:t.status.warning,brightBlue:n.function,brightMagenta:n.keyword,brightCyan:n.type,brightWhite:t.surface.elevatedForeground}}function Zr(e,t,n){const o=`${e}, "JetBrainsMonoNL Nerd Font", "FiraCode Nerd Font", "Cascadia Code PL", "Fira Code", "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", "Courier New", monospace`;return{cursorBlink:!1,cursorStyle:"bar",cursorInactiveStyle:"none",fontSize:t,fontFamily:o,allowTransparency:!1,convertEol:!0,scrollback:1e4,theme:{background:n.background,foreground:n.foreground,cursor:n.cursor,cursorAccent:n.cursorAccent,selectionBackground:n.selectionBackground,selectionForeground:n.selectionForeground,selectionInactiveBackground:n.selectionInactiveBackground,black:n.black,red:n.red,green:n.green,yellow:n.yellow,blue:n.blue,magenta:n.magenta,cyan:n.cyan,white:n.white,brightBlack:n.brightBlack,brightRed:n.brightRed,brightGreen:n.brightGreen,brightYellow:n.brightYellow,brightBlue:n.brightBlue,brightMagenta:n.brightMagenta,brightCyan:n.brightCyan,brightWhite:n.brightWhite}}}const Lg=(e,t)=>{const n=`${e??""} ${t??""}`;return/mac|iphone|ipad|darwin/i.test(n)?"mac":"other"},Og=e=>e.key.length===1?e.key.toLowerCase():e.code==="KeyC"?"c":e.code==="KeyV"?"v":e.code==="Insert"?"insert":e.key.toLowerCase(),Bg=(e,t,n)=>{if(e.altKey)return null;const r=Og(e);return t==="mac"?!e.metaKey||e.ctrlKey?null:r==="c"&&!e.shiftKey?n?"copy":"ignore":null:e.metaKey?null:e.ctrlKey&&!e.shiftKey&&r==="insert"?n?"copy":"ignore":!e.ctrlKey||!e.shiftKey?null:r==="c"?n?"copy":"ignore":null},kn=e=>typeof e=="string"&&e.trim().length>0;async function fa(e){return kn(e)?(await ys(e)).ok:!1}async function _g(){if(typeof navigator>"u"||!navigator.clipboard?.readText)return null;try{return await navigator.clipboard.readText()||null}catch{return null}}const zg=(e,t,n,r,o)=>{if(n.width<=0||n.height<=0||r<=0||o<=0)return null;const i=Math.floor((e-n.left)/n.width*r),l=Math.floor((t-n.top)/n.height*o);return{column:Math.max(0,Math.min(r-1,i)),row:Math.max(0,Math.min(o-1,l))}},Ug=(e,t)=>{const n=Math.max(0,Math.min(e.length-1,t)),r=l=>!!(l&&!/^\s+$/u.test(l));if(!r(e[n]))return{startColumn:n,endColumn:n};let o=n,i=n;for(;o>0&&r(e[o-1]);)o-=1;for(;i<e.length-1&&r(e[i+1]);)i+=1;return{startColumn:o,endColumn:i}};let $g=null;const Kg=()=>$g??=Promise.all([ht(()=>import("./vendor-xterm-xterm-B-qIQCd3.js"),[]),ht(()=>import("./vendor-xterm-addon-fit-DX4qG4td.js"),[])]).then(([e,t])=>({Xterm:e,Fit:t})),Wg=2e3,Gg=()=>{if(typeof window>"u")return Promise.resolve();const e=window.__pichamberEnsureNerdFonts;return typeof e!="function"?Promise.resolve():Promise.race([Promise.resolve(e()).catch(()=>{}),new Promise(t=>setTimeout(t,Wg))]).then(()=>{})},Hg=(e,t,n)=>{if(typeof window>"u"||typeof document>"u")return null;const r=document.createElement("canvas").getContext("2d");if(!r||e.clientWidth<24||e.clientHeight<24)return null;r.font=`${n}px ${t}`;const o=r.measureText("M"),i=Math.ceil(o.width),l=Math.ceil((o.actualBoundingBoxAscent||n*.8)+(o.actualBoundingBoxDescent||n*.2))+2;if(i<1||l<1)return null;const c=window.getComputedStyle(e),d=(Number.parseInt(c.paddingLeft,10)||0)+(Number.parseInt(c.paddingRight,10)||0),u=(Number.parseInt(c.paddingTop,10)||0)+(Number.parseInt(c.paddingBottom,10)||0);return{cols:Math.max(2,Math.floor((e.clientWidth-d-15)/i)),rows:Math.max(1,Math.floor((e.clientHeight-u)/l))}},rc=a.forwardRef(({sessionKey:e,chunks:t,onInput:n,onResize:r,theme:o,fontFamily:i,fontSize:l,className:c,enableTouchScroll:d=!1,autoFocus:u=!0,isVisible:f=!0},p)=>{const x=a.useRef(null),y=a.useRef(null),m=a.useRef(null),h=a.useRef(n),b=a.useRef(r),g=a.useRef(o),S=a.useRef(i),v=a.useRef(l),E=a.useRef(null),j=a.useRef(null),k=a.useRef(null),C=a.useRef(""),w=a.useRef(!1),N=a.useRef(0),T=a.useRef(f),O=a.useRef(!1),[$,U]=a.useState(0),[K,L]=a.useState(0),[D,R]=a.useState(!1),[I,M]=a.useState(!1);h.current=n,b.current=r,T.current=f,g.current=o,S.current=i,v.current=l,a.useLayoutEffect(()=>{const H=x.current;if(!H)return;const z=Hg(H,i,l);j.current=z,z&&b.current(z.cols,z.rows)},[i,l]);const W=a.useCallback(()=>{const H=x.current,z=y.current;if(!H||!z||!m.current||!T.current)return;const Y=H.getBoundingClientRect();if(!(Y.width<24||Y.height<24))try{m.current.fit();const X={cols:z.cols,rows:z.rows};(!E.current||E.current.cols!==X.cols||E.current.rows!==X.rows)&&(E.current=X,b.current(X.cols,X.rows)),O.current||(O.current=!0,U(te=>te+1))}catch{}},[]),G=a.useCallback(()=>{if(w.current||!C.current||!y.current)return;const H=y.current,z=C.current;if(C.current="",!z)return;w.current=!0;const Y=N.current;H.write(z,()=>{y.current!==H||N.current!==Y||(w.current=!1,C.current&&G())})},[]),B=a.useCallback(()=>{k.current=null,C.current="",w.current=!1,N.current+=1;const H=y.current;if(!H){L(z=>z+1);return}try{H.reset()}catch{L(z=>z+1)}},[]),xe=a.useCallback(H=>{H?.preventDefault(),M(kn(y.current?.getSelection())),R(!0)},[]),V=a.useCallback(H=>{H.stopPropagation();const z=y.current,Y=z?.getSelection()??"";z?.focus(),kn(Y)&&fa(Y)},[]),je=a.useCallback(H=>{H.stopPropagation();const z=y.current;z?.focus(),_g().then(Y=>{Y&&y.current===z&&z&&z.paste(Y)})},[]),Re=a.useCallback(H=>{H.stopPropagation();const z=y.current;z?.focus();try{z?.selectAll()}catch{}M(kn(z?.getSelection()))},[]);return a.useEffect(()=>{const H=x.current;if(!H)return;let z=!1,Y=null,X=null,te=null,ue=null,he=[];const Q=()=>{Y&&T.current&&(Y.options.cursorBlink=!0)},se=ve=>{ve.relatedTarget instanceof Node&&H.contains(ve.relatedTarget)||Y&&(Y.options.cursorBlink=!1)},ce=()=>{Y&&T.current&&H.contains(document.activeElement)&&(Y.options.cursorBlink=!0)},Ce=()=>{Y&&(Y.options.cursorBlink=!1)};return H.addEventListener("focusin",Q),H.addEventListener("focusout",se),window.addEventListener("focus",ce),window.addEventListener("blur",Ce),Promise.all([Kg(),Gg()]).then(([{Xterm:ve,Fit:Ge}])=>{if(z)return;const q=g.current,ae=S.current,ne=v.current;Y=new ve.Terminal({...Zr(ae,ne,q),...j.current??{}});const me=new Ge.FitAddon;Y.loadAddon(me),Y.open(H),y.current=Y,m.current=me;const fe=typeof navigator>"u"?"other":Lg(navigator.userAgentData?.platform??navigator.platform??"",navigator.userAgent??""),Be=Y;Y.attachCustomKeyEventHandler(Se=>{if(Se.type!=="keydown")return!0;const ee=Be.getSelection(),we=Bg({key:Se.key,code:Se.code,ctrlKey:Se.ctrlKey,shiftKey:Se.shiftKey,metaKey:Se.metaKey,altKey:Se.altKey},fe,kn(ee));return we==="copy"?(fa(ee),!1):we!=="ignore"}),he=[Y.onData(Se=>h.current(Se))],X=new ResizeObserver(()=>{te&&clearTimeout(te),te=setTimeout(W,80)}),X.observe(H),W(),ue=requestAnimationFrame(W)}),()=>{z=!0;const ve=document.activeElement;ve instanceof HTMLElement&&H.contains(ve)&&(ve.blur(),window.Capacitor?.getPlatform?.()==="android"&&ht(async()=>{const{Keyboard:q}=await import("./vendor-capacitor-keyboard-eTtI5go3.js");return{Keyboard:q}},__vite__mapDeps([45,10,4,6])).then(({Keyboard:q})=>q.hide()).catch(()=>{})),X?.disconnect(),te&&clearTimeout(te),ue!==null&&cancelAnimationFrame(ue),H.removeEventListener("focusin",Q),H.removeEventListener("focusout",se),window.removeEventListener("focus",ce),window.removeEventListener("blur",Ce),he.forEach(Ge=>Ge.dispose()),Y?.dispose(),y.current=null,m.current=null,E.current=null,k.current=null,C.current="",w.current=!1,N.current+=1,O.current=!1}},[W,K]),a.useEffect(()=>{const H=y.current;H&&(H.options.theme=Zr(i,l,o).theme,H.options.fontFamily=Zr(i,l,o).fontFamily,H.options.fontSize=l)},[i,l,o]),a.useEffect(()=>{const H=y.current,z=x.current;!H||!z||(H.options.cursorBlink=f&&document.hasFocus()&&z.contains(document.activeElement))},[f,$]),a.useEffect(()=>{if(!y.current)return;if(t.length===0){k.current!==null&&B();return}const z=k.current;let Y=-1;if(z!==null){for(let ue=t.length-1;ue>=0;ue-=1){const he=t[ue].id;if(he===z){Y=ue;break}if(he<z)break}if(Y<0){B();return}}const X=Y<0,te=Y>=0?t.slice(Y+1):t;C.current+=te.map(ue=>X?ue.replayData??ue.data:ue.data).join(""),k.current=t.at(-1)?.id??null,G()},[t,G,$,B]),a.useEffect(()=>{if(!u||!f)return;const H=requestAnimationFrame(()=>y.current?.focus());return()=>cancelAnimationFrame(H)},[u,f,$,e]),a.useEffect(()=>{const H=x.current,z=y.current;if(!d||!H||!z)return;let Y=null,X=null,te="idle",ue=0,he=0,Q=0,se=0,ce=null;const Ce=Math.max(12,l+2),ve=()=>{window.Capacitor?.getPlatform?.()==="android"&&ht(async()=>{const{Keyboard:we}=await import("./vendor-capacitor-keyboard-eTtI5go3.js");return{Keyboard:we}},__vite__mapDeps([45,10,4,6])).then(({Keyboard:we})=>we.show()).catch(()=>{})},Ge=()=>{X&&(clearTimeout(X),X=null)},q=(ee,we)=>{const pe=H.querySelector("canvas");return pe?zg(ee,we,pe.getBoundingClientRect(),z.cols,z.rows):null},ae=(ee,we)=>{const pe=H.querySelector("canvas");if(!pe)return;const ye=pe.getBoundingClientRect(),We=ye.left+(we.column+.5)/z.cols*ye.width,qe=ye.top+(we.row+.5)/z.rows*ye.height;pe.dispatchEvent(new MouseEvent(ee,{bubbles:!0,cancelable:!0,button:0,buttons:1,clientX:We,clientY:qe}))},ne=()=>{document.dispatchEvent(new MouseEvent("mouseup",{bubbles:!0,cancelable:!0,button:0,buttons:0}))},me=ee=>{ee.pointerType!=="touch"||Y!==null||(Y=ee.pointerId,te="pending",ue=ee.clientX,he=ee.clientY,Q=ee.clientY,se=0,ce=null,H.setPointerCapture(ee.pointerId),X=setTimeout(()=>{if(X=null,Y!==ee.pointerId||te!=="pending")return;const we=q(ue,he);if(!we)return;const pe=z.buffer.active,ye=Math.max(0,pe.length-z.rows-pe.viewportY+we.row),We=pe.getLine(ye),qe=Array.from({length:z.cols},(re,Le)=>We?.getCell(Le)?.getChars()??""),Pe=Ug(qe,we.column),Ye={column:Pe.startColumn,row:we.row};ce={column:Pe.endColumn,row:we.row},te="selecting",ae("mousedown",Ye),ae("mousemove",ce)},350))},fe=ee=>{if(Y!==ee.pointerId)return;if(te==="selecting"){const ye=q(ee.clientX,ee.clientY);ye&&(!ce||ye.column!==ce.column||ye.row!==ce.row)&&(ce=ye,ae("mousemove",ye)),ee.cancelable&&ee.preventDefault();return}if(te==="pending"){if(Math.hypot(ee.clientX-ue,ee.clientY-he)<8)return;Ge(),te="scrolling"}if(te!=="scrolling")return;const we=Q-ee.clientY;Q=ee.clientY,se+=we;const pe=Math.trunc(se/Ce);pe&&(z.scrollLines(pe),se-=pe*Ce),ee.cancelable&&ee.preventDefault()},Be=ee=>{if(Y!==ee.pointerId)return;const we=te==="pending",pe=te==="selecting";Ge(),H.hasPointerCapture(ee.pointerId)&&H.releasePointerCapture(ee.pointerId),Y=null,te="idle",pe&&ne(),we&&(z.focus(),ve())},Se=ee=>{if(Y!==ee.pointerId)return;const we=te==="selecting";Ge(),H.hasPointerCapture(ee.pointerId)&&H.releasePointerCapture(ee.pointerId),Y=null,te="idle",we&&ne()};return H.addEventListener("pointerdown",me),H.addEventListener("pointermove",fe,{passive:!1}),H.addEventListener("pointerup",Be),H.addEventListener("pointercancel",Se),()=>{Ge(),H.removeEventListener("pointerdown",me),H.removeEventListener("pointermove",fe),H.removeEventListener("pointerup",Be),H.removeEventListener("pointercancel",Se)}},[d,l,$]),a.useImperativeHandle(p,()=>({focus:()=>y.current?.focus(),fit:W,getSelection:()=>{const H=y.current,z=H?.getSelectionPosition(),Y=H?.getSelection()??"";return!z||!Y.trim()?null:{text:Y,startLine:z.start.y+1,endLine:z.end.y+1}}}),[W]),s.jsxs(Cr,{open:D,onOpenChange:R,children:[s.jsx(kr,{render:s.jsx("div",{ref:x,"data-terminal-owner":"main",className:_("terminal-viewport-container h-full w-full overflow-hidden touch-none",c),onContextMenu:xe})}),s.jsxs(Ar,{className:"min-w-[180px]",children:[s.jsxs(Rs,{disabled:!I,onClick:V,children:[s.jsx(P,{name:"file-copy",className:"mr-2 h-4 w-4"})," ","Copy"]}),s.jsxs(Rs,{onClick:je,children:[s.jsx(P,{name:"clipboard",className:"mr-2 h-4 w-4"})," ","Paste"]}),s.jsx(ql,{}),s.jsx(Rs,{onClick:Re,children:"Select All"})]})]})});rc.displayName="TerminalViewport";const qg=({directory:e,tabId:t,sessionId:n,sessionKey:r,isActive:o,isTerminalVisible:i,terminal:l,theme:c,fontFamily:d,fontSize:u,enableTouchScroll:f,lastViewportSizeRef:p,onInput:x,controllerRef:y})=>{const m=ge(v=>e&&t?v.getBuffer(e,t).chunks:ir.chunks),h=a.useRef(null),b=o&&i,g=a.useCallback(v=>{h.current=v,y&&(y.current=o?v:y.current),!o&&y&&y.current===v&&(y.current=null)},[y,o]);a.useEffect(()=>{if(!o||!i)return;const v=requestAnimationFrame(()=>{h.current?.fit()});return()=>cancelAnimationFrame(v)},[o,i,r,n]);const S=a.useCallback((v,E)=>{if(!o)return;const j=p.current;(!j||j.cols!==v||j.rows!==E)&&(p.current={cols:v,rows:E}),n&&l.resize({sessionId:n,cols:v,rows:E}).catch(()=>{})},[o,p,n,l]);return s.jsx("div",{className:_("h-full w-full",o?"block":"hidden"),"aria-hidden":!o,children:s.jsx(rc,{ref:g,sessionKey:r,chunks:m,onInput:x,onResize:S,theme:c,fontFamily:d,fontSize:u,enableTouchScroll:f,autoFocus:b,isVisible:b},r)})},ha=({items:e,activeId:t,onSelect:n,onClose:r,onCreate:o,disabled:i=!1})=>{const l=e.find(c=>c.id===t)??e[0]??null;return s.jsxs(Wt,{modal:!1,children:[s.jsx(Gt,{asChild:!0,children:s.jsxs(Ne,{type:"button",variant:"ghost",size:"sm",disabled:i,title:l?`Switch terminal, current: ${l.label}`:"Switch terminal","aria-label":l?`Switch terminal, current: ${l.label}`:"Switch terminal",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1 normal-case",children:[l?.icon??s.jsx(P,{name:"terminal",className:"size-4 shrink-0"}),s.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:l?.label??"Terminal"}),s.jsx(P,{name:"arrow-down-s",className:"size-4 shrink-0 opacity-60"})]})}),s.jsxs(Ht,{align:"start",className:"w-64",children:[e.map(c=>{const d=c.id===(l?.id??t);return s.jsxs(ft,{title:c.title??c.label,onClick:()=>n(c.id),className:"group/tab min-w-0",children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[c.icon,s.jsx("span",{className:"min-w-0 flex-1 truncate",children:c.label})]}),d?s.jsx(P,{name:"check",className:"size-3.5 shrink-0 text-primary"}):null,s.jsx("button",{type:"button",title:c.closeLabel,"aria-label":c.closeLabel,onClick:u=>{u.preventDefault(),u.stopPropagation(),r(c.id)},className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground opacity-0 transition-opacity hover:bg-interactive-hover hover:text-foreground focus-visible:opacity-100 focus-visible:outline-none group-hover/tab:opacity-100",children:s.jsx(P,{name:"close",className:"size-3"})})]},c.id)}),s.jsx(en,{}),s.jsxs(ft,{onClick:o,children:[s.jsx(P,{name:"add",className:"size-3.5"}),"New tab"]})]})]})},Yg=({leading:e,icon:t,title:n,actions:r,className:o})=>s.jsxs("header",{className:_("flex h-11 shrink-0 items-center gap-1 border-b border-border bg-background pl-3 pr-2",o),children:[e,n!=null?typeof n=="string"?s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[typeof t=="string"?s.jsx(P,{name:t,className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}):t??null,s.jsx("h2",{className:"truncate typography-ui-label font-medium text-foreground",children:n})]}):s.jsx("div",{className:"min-w-0 flex-1",children:n}):null,r?s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:r}):null]}),Vg=({isTouchTerminal:e,activeModifier:t,disabled:n,onKeyPress:r,onModifierToggle:o})=>{const i=e?"lg":"xs",l=e?"w-10 p-0":"w-9 p-0",c=d=>{e&&d.preventDefault()};return s.jsxs(s.Fragment,{children:[s.jsx(Ne,{type:"button",size:i,variant:"outline",onPointerDown:c,onClick:()=>r("esc"),disabled:n,children:"Esc"}),s.jsxs(Ne,{type:"button",size:i,variant:"outline",className:l,onPointerDown:c,onClick:()=>r("tab"),disabled:n,children:[s.jsx(P,{name:"arrow-right",className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"Tab"})]}),s.jsxs(Ne,{type:"button",size:i,variant:"chip","aria-pressed":t==="ctrl",className:e?"px-3":"px-2",onPointerDown:c,onClick:()=>o("ctrl"),disabled:n,children:[s.jsx("span",{className:"text-xs font-medium",children:"Ctrl"}),s.jsx("span",{className:"sr-only",children:"Control modifier"})]}),s.jsxs(Ne,{type:"button",size:i,variant:"chip","aria-pressed":t==="alt",className:e?"px-3":"px-2",onPointerDown:c,onClick:()=>o("alt"),disabled:n,children:[s.jsx("span",{className:"text-xs font-medium",children:"Alt"}),s.jsx("span",{className:"sr-only",children:"Alt modifier"})]}),s.jsxs(Ne,{type:"button",size:i,variant:"outline",className:l,onPointerDown:c,onClick:()=>r("arrow-up"),disabled:n,children:[s.jsx(P,{name:"arrow-up"}),s.jsx("span",{className:"sr-only",children:"Arrow up"})]}),s.jsxs(Ne,{type:"button",size:i,variant:"outline",className:l,onPointerDown:c,onClick:()=>r("arrow-left"),disabled:n,children:[s.jsx(P,{name:"arrow-left"}),s.jsx("span",{className:"sr-only",children:"Arrow left"})]}),s.jsxs(Ne,{type:"button",size:i,variant:"outline",className:l,onPointerDown:c,onClick:()=>r("arrow-down"),disabled:n,children:[s.jsx(P,{name:"arrow-down"}),s.jsx("span",{className:"sr-only",children:"Arrow down"})]}),s.jsxs(Ne,{type:"button",size:i,variant:"outline",className:l,onPointerDown:c,onClick:()=>r("arrow-right"),disabled:n,children:[s.jsx(P,{name:"arrow-right"}),s.jsx("span",{className:"sr-only",children:"Arrow right"})]}),s.jsxs(Ne,{type:"button",size:i,variant:"outline",className:l,onPointerDown:c,onClick:()=>r("enter"),disabled:n,children:[s.jsx(P,{name:"arrow-go-back"}),s.jsx("span",{className:"sr-only",children:"Enter"})]})]})},Qg="\x1B",Jg=new RegExp(`${Qg}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Xg=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[^\s<>'"`]*)?)/gi,Zg=/(?:➜\s*(?:Local|Network):)|\b(?:local|network|loopback|serving|listening|available|ready|started|running|server|vite|webpack|next\.js|astro|sveltekit|nuxt)\b/i,eb=/Serving HTTP on .*? port (\d{2,5})/i,tb=new Set([".",",",";",":","!","?"]),sb=e=>{let t=e;for(;t.length>0;){const n=t[t.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",o=t.slice(0,-1),i=(o.match(new RegExp(`\\${r}`,"g"))||[]).length,l=(o.match(new RegExp(`\\${n}`,"g"))||[]).length;if(i>l)break;t=o;continue}if(tb.has(n)){t=t.slice(0,-1);continue}break}return t},ma=e=>{let t=sb(e);return t=t.replace("0.0.0.0","127.0.0.1"),t=t.replace("[::1]","127.0.0.1"),t=t.replace("[::]","127.0.0.1"),t},nb=e=>{if(!e)return null;const t=e.replace(Jg,""),n=t.match(eb);if(n?.[1]){const o=Number.parseInt(n[1],10);if(Number.isFinite(o)&&o>0&&o<=65535)return`http://127.0.0.1:${o}/`}const r=t.split(`
|
|
55
|
+
`);for(const o of r){if(!Zg.test(o))continue;const i=Array.from(o.matchAll(Xg));if(i.length===0)continue;const l=i.find(c=>{try{return!!new URL(ma(c[1])).port}catch{return!1}});return ma((l??i[0])[1])}return null},rb=async(e,t=1500)=>{if(!e||typeof window>"u")return!1;let n;try{n=new URL(e)}catch{return!1}if(n.protocol!=="http:"&&n.protocol!=="https:")return!1;const r=n.hostname.toLowerCase();if(r!=="localhost"&&r!=="127.0.0.1"&&r!=="0.0.0.0"&&r!=="::1"&&r!=="::")return!1;const o=new AbortController,i=window.setTimeout(()=>o.abort(),t);try{const l=await Tt("/api/system/probe-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:n.toString()}),cache:"no-store",signal:o.signal});return l.ok?(await l.json().catch(()=>null))?.ok===!0:!1}catch{return!1}finally{window.clearTimeout(i)}},ob={esc:"\x1B",tab:" ",enter:"\r","arrow-up":"\x1B[A","arrow-down":"\x1B[B","arrow-left":"\x1B[D","arrow-right":"\x1B[C"},ib=(e,t)=>{if(t&&e.startsWith("arrow-")){const n=t==="ctrl"?"5":"3",r={"arrow-up":"A","arrow-down":"B","arrow-right":"C","arrow-left":"D"}[e];return`\x1B[1;${n}${r}`}return ob[e]},oc=e=>{const t=e[0]?.toUpperCase();return!t||t<"A"||t>"Z"?null:String.fromCharCode(t.charCodeAt(0)&31)},ab=(e,t)=>e&&(t==="ctrl"?oc(e)??e:e.length===1&&e!=="\x1B"?`\x1B${e}`:e),ic={cols:80,rows:24},pa={Tab:"tab",Enter:"enter",ArrowUp:"arrow-up",ArrowDown:"arrow-down",ArrowLeft:"arrow-left",ArrowRight:"arrow-right",Escape:"esc"};class lb{tail="";pendingUrls=new Set;probeGeneration=0;reset(){this.tail="",this.pendingUrls.clear(),this.probeGeneration+=1}scan(t,n,r,o){if(!r)return;const i=`${this.tail}${r}`.replace(/\r\n|\r/g,`
|
|
56
|
+
`),l=i.split(`
|
|
57
|
+
`),c=i.endsWith(`
|
|
58
|
+
`)?l.join(`
|
|
59
|
+
`):l.slice(0,-1).join(`
|
|
60
|
+
`);if(this.tail=i.endsWith(`
|
|
61
|
+
`)?"":(l[l.length-1]??"").slice(-1024),!c)return;const d=nb(c);if(!d||this.pendingUrls.has(d))return;const u=this.probeGeneration;this.pendingUrls.add(d),rb(d).then(f=>{if(this.pendingUrls.delete(d),!f||this.probeGeneration!==u)return;const p=ge.getState().getDirectoryState(t)?.tabs.find(x=>x.id===n);!p||p.previewUrlLocked||p.previewUrl===d||o(t,n,d,{locked:!1,autoOpened:!1})})}}const cb=(e,t)=>{if(t!=="ctrl")return null;const n=e.key,r=e.code??"",o=n.length===1&&/[a-zA-Z]/.test(n)?n.toUpperCase():r.startsWith("Key")&&r.length===4?r.slice(3).toUpperCase():null;return o&&o.length===1&&o>="A"&&o<="Z"?oc(o):null};function db({terminal:e,effectiveDirectory:t,activeTabId:n,terminalSessionId:r,terminalLifecycle:o,hasOpenedTerminalViewport:i,terminalHydrated:l,terminalShell:c,terminalLoginShell:d,terminalAppearanceRef:u,enableTabs:f,hasActiveContext:p,focusTerminalWhenWindowActive:x,tabs:y}){const m=ge(z=>z.ensureDirectory),h=ge(z=>z.setTabSessionId),b=ge(z=>z.setTabLifecycle),g=ge(z=>z.setConnecting),S=ge(z=>z.appendToBuffer),v=ge(z=>z.replaceBuffer),E=ge(z=>z.setTabPreviewUrl),[j,k]=a.useState(null),[C,w]=a.useState(!1),[N,T]=a.useState(!1),O=a.useRef(new Map),$=a.useRef(null),U=a.useRef(n),K=a.useRef(r),L=a.useRef(t),D=a.useRef(null),R=a.useRef(new Set),I=a.useRef(new Map),M=a.useRef(y),W=a.useRef(l),G=a.useRef(i),B=a.useRef(e);M.current=y,W.current=l,G.current=i,B.current=e;const xe=a.useCallback(()=>{const z=U.current;z&&I.current.get(z)?.reset()},[]);a.useEffect(()=>{K.current=r},[r]),a.useEffect(()=>{!r||!e.updateAppearance||e.updateAppearance(r,u.current).catch(()=>{})},[u,e,r]),a.useEffect(()=>{U.current=n},[n]),a.useEffect(()=>{L.current=t},[t]);const V=a.useCallback(()=>{for(const z of O.current.values())try{z()}catch{}O.current.clear(),$.current=null,T(!1)},[]);a.useEffect(()=>()=>{V(),K.current=null},[V]);const je=a.useCallback((z,Y,X)=>{let te=I.current.get(Y);te||(te=new lb,I.current.set(Y,te)),te.scan(z,Y,X,E)},[E]),Re=a.useCallback((z,Y,X)=>{if(O.current.has(X)){$.current=X;return}const te=Ai(),ue=()=>Ai()===te&&L.current===z&&ge.getState().getDirectoryState(z)?.tabs.find(Q=>Q.id===Y)?.terminalSessionId===X,he=e.connect(X,{onEvent:Q=>{if(ue())switch(Q.type){case"snapshot":{U.current===Y&&K.current===X?(g(z,Y,!1),k(null),w(!1),T(!1),x()):g(z,Y,!1),v(z,Y,Q.data??"",Q.sequence??0),je(z,Y,Q.data??""),Q.status==="exited"&&b(z,Y,"exited");break}case"reconnecting":{U.current===Y&&(k(null),w(!1),T(!0));break}case"data":{Q.data&&(S(z,Y,Q.data,Q.sequence,Q.replayData),je(z,Y,Q.data));break}case"exit":{const se=typeof Q.exitCode=="number"?Q.exitCode:null,ce=typeof Q.signal=="number"?Q.signal:null,ve=!!ge.getState().getDirectoryState(z)?.tabs.find(Ge=>Ge.id===Y)?.label?.startsWith("Action:");S(z,Y,`\\r\\n[Process exited${se!==null?` with code ${se}`:""}${ce!==null?` (signal ${ce})`:""}]\\r\\n`),b(z,Y,"exited"),U.current===Y&&(g(z,Y,!1),k(ve?null:"Terminal session ended"),w(!1),T(!1));break}}},onError:(Q,se)=>{if(!ue())return;const ce=U.current===Y;if(!se){ce&&(k(null),w(!1));return}if(Q.code==="SESSION_NOT_FOUND"&&!ge.getState().getDirectoryState(z)?.tabs.find(ve=>ve.id===Y)?.label?.startsWith("Action:")){ce&&(k(null),w(!1),g(z,Y,!1),T(!1)),h(z,Y,null),b(z,Y,"idle");return}ce&&(T(!1),k(`Connection failed: ${Q.message}`),w(!0),g(z,Y,!1),b(z,Y,"exited"),h(z,Y,null))}});O.current.set(X,()=>he.close()),$.current=X},[S,x,v,je,g,b,h,e]),H=a.useMemo(()=>y.map(z=>`${z.id}:${z.terminalSessionId??""}`).join(","),[y]);return a.useEffect(()=>{if(!l||!i||!t)return;const z=t,Y=new Set;for(const X of y)X.terminalSessionId&&(Y.add(X.terminalSessionId),Re(z,X.id,X.terminalSessionId));for(const[X,te]of O.current)if(!Y.has(X)){try{te()}catch{}O.current.delete(X)}},[H,y,t,l,i,Re]),a.useEffect(()=>Qu(()=>{if(!W.current||!G.current)return;const z=L.current;if(!z)return;const Y=[];for(const te of M.current){if(!te.terminalSessionId)continue;ge.getState().getDirectoryState(z)?.tabs.find(he=>he.id===te.id)?.terminalSessionId===te.terminalSessionId&&Y.push({id:te.id,terminalSessionId:te.terminalSessionId})}if(O.current.clear(),$.current=null,Y.length===0)return;T(!0),k(null),w(!1);for(const te of Y)Re(z,te.id,te.terminalSessionId);const X=D.current;if(X)for(const te of Y)B.current.resize({sessionId:te.terminalSessionId,...X}).catch(()=>{})}),[Re]),a.useEffect(()=>{let z=!1;if(!l||!i)return;if(!t){k(p?"No working directory available for terminal.":"Select a session to open the terminal.");return}return(async()=>{const X=t;if(!L.current||L.current!==X)return;if(!ge.getState().getDirectoryState(X)){m(X);return}const ue=ge.getState().getDirectoryState(X);if(!ue||ue.tabs.length===0)return;const he=ue.activeTabId??ue.tabs[0]?.id??null;if(!he)return;const Q=ue.tabs.find(q=>q.id===he)??ue.tabs[0],se=Q?.terminalSessionId??null,ce=Q?.lifecycle??"idle",Ce=!!Q?.label?.startsWith("Action:"),ve=ge.getState().getBuffer(X,he),Ge=ve.byteLength>0||ve.chunks.length>0;if(!se){if(ce==="exited"){g(X,he,!1);return}if(Ce&&Ge){g(X,he,!1);return}const q=`${X}\0${he}`;if(R.current.has(q))return;const ae=D.current??ic;R.current.add(q),k(null),w(!1),T(!1),g(X,he,!0);try{const ne=await e.createSession({cwd:X,sessionId:he,cols:ae.cols,rows:ae.rows,shell:c,loginShell:d,...u.current});if(!ge.getState().getDirectoryState(X)?.tabs.find(Be=>Be.id===he)){try{await e.close(ne.sessionId)}catch{}return}h(X,he,ne.sessionId);const fe=D.current;fe&&(fe.cols!==ae.cols||fe.rows!==ae.rows)&&e.resize({sessionId:ne.sessionId,...fe}).catch(()=>{});return}catch(ne){const me=ge.getState().getDirectoryState(X)?.tabs.find(fe=>fe.id===he);if(!me||me.terminalSessionId||(g(X,he,!1),L.current!==X||U.current!==he))return;k(ne instanceof Error?ne.message:"Failed to start terminal session"),w(!0),T(!1);return}finally{R.current.delete(q)}}!se||z||(K.current=se)})(),()=>{z=!0}},[p,t,r,o,n,i,f,l,m,g,b,h,e,d,c,u]),{connectionError:j,setConnectionError:k,isFatalError:C,setIsFatalError:w,isReconnectPending:N,setIsReconnectPending:T,terminalIdRef:K,lastViewportSizeRef:D,directoryRef:L,activeTabIdRef:U,disconnectStream:V,resetTerminalPreviewScan:xe,startStream:Re}}function ub({terminal:e,terminalIdRef:t,isReconnectPending:n,setConnectionError:r,showQuickKeys:o,isTerminalVisible:i,lastViewportSizeRef:l,terminalSessionId:c,useTouchTerminalInput:d}){const[u,f]=a.useState(null),p=a.useRef(null),x=a.useCallback(()=>{d||p.current?.focus()},[d]),y=a.useCallback(()=>{d||typeof document<"u"&&!document.hasFocus()||p.current?.focus()},[d]);a.useEffect(()=>{!o&&u!==null&&f(null)},[o,u]),a.useEffect(()=>{!c&&u!==null&&f(null)},[c,u]);const m=a.useCallback(v=>{if(!v||n)return;let E=v,j=!1;u&&v.length>0&&(E=ab(v,u),j=!0);const k=t.current;k&&(e.sendInput(k,E).catch(C=>{n||r(C instanceof Error?C.message:"Failed to send input")}),j&&(f(null),x()))},[u,x,n,r,e,t]),h=a.useCallback((v,E)=>{const j=l.current;if((!j||j.cols!==v||j.rows!==E)&&(l.current={cols:v,rows:E}),!i)return;const k=t.current;k&&e.resize({sessionId:k,cols:v,rows:E}).catch(()=>{})},[i,l,e,t]),b=a.useCallback(v=>{f(E=>E===v?null:v),x()},[x]),g=a.useCallback(v=>{const E=ib(v,u);E&&(m(E),f(null),x())},[u,x,m]),S=a.useCallback(v=>{if(v.repeat)return;const E=v.key;if(!E||E==="Control"||E==="Meta"||E==="Alt"||E==="Shift")return;const j=E.length===1?E.toLowerCase():E;if(j in pa){v.preventDefault(),v.stopPropagation(),g(pa[j]);return}const k=cb(v,u);k&&(v.preventDefault(),v.stopPropagation(),m(k),f(null),x())},[u,x,g,m]);return a.useEffect(()=>{if(!(!o||!u||!c))return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[u,S,o,c]),{activeModifier:u,setActiveModifier:f,terminalControllerRef:p,focusTerminalController:x,focusTerminalWhenWindowActive:y,handleViewportInput:m,handleViewportResize:h,handleModifierToggle:b,handleMobileKeyPress:g}}function fb({terminal:e,effectiveDirectory:t,activeTabId:n,enableTabs:r,terminalShell:o,terminalLoginShell:i,terminalAppearanceRef:l,lastViewportSizeRef:c,directoryRef:d,activeTabIdRef:u,terminalIdRef:f,resetTerminalPreviewScan:p,startStream:x,setConnectionError:y,setIsFatalError:m,setIsReconnectPending:h}){const b=ge($=>$.createTab),g=ge($=>$.setActiveTab),S=ge($=>$.closeTab),v=ge($=>$.setTabSessionId),E=ge($=>$.setTabLifecycle),[j,k]=a.useState(!1),C=a.useCallback(async()=>{if(!t||j)return;const $=ge.getState().getDirectoryState(t),U=n??$?.activeTabId??$?.tabs[0]?.id??null;if(!U)return;const K=$?.tabs.find(L=>L.id===U)?.terminalSessionId??null;if(!(!K||!e.restartSession)){k(!0),y(null),m(!1),h(!1),p();try{const L=c.current??ic,D=await e.restartSession(K,{cwd:t,shell:o,loginShell:i,...L,...l.current});if(ge.getState().getDirectoryState(t)?.tabs.find(I=>I.id===U)?.terminalSessionId!==K||(v(t,U,D.sessionId),E(t,U,"running"),d.current!==t||u.current!==U))return;f.current=D.sessionId,x(t,U,D.sessionId)}catch(L){if(ge.getState().getDirectoryState(t)?.tabs.find(R=>R.id===U)?.terminalSessionId!==K||d.current!==t||u.current!==U)return;y(L instanceof Error?L.message:"Failed to restart terminal"),m(!1),h(!1),f.current=K,x(t,U,K)}finally{k(!1)}}},[n,u,d,t,r,j,c,p,y,m,h,E,v,x,e,l,f,i,o]),w=a.useCallback(async()=>{await C()},[C]),N=a.useCallback(()=>{if(!t)return;const $=b(t);g(t,$),y(null),m(!1),h(!1)},[b,t,g,y,m,h]),T=a.useCallback($=>{t&&(g(t,$),y(null),m(!1),h(!1))},[t,g,y,m,h]),O=a.useCallback($=>{if(!t)return;y(null),m(!1),h(!1);const U=ge.getState().getDirectoryState(t)?.tabs.find(K=>K.id===$)?.terminalSessionId;(async()=>{U&&await e.close(U),S(t,$)})().catch(K=>y(K instanceof Error?K.message:"Terminal session ended"))},[S,t,y,m,h,e]);return{isRestarting:j,handleRestart:C,handleHardRestart:w,handleCreateTab:N,handleSelectTab:T,handleCloseTab:O}}const ay=({visible:e,onCloseView:t,terminalHeaderSlot:n})=>{const{terminal:r,runtime:o}=Fs(),{currentTheme:i}=Ha(),l=a.useRef({themeMode:"dark",terminalBackground:"",terminalForeground:""});l.current={themeMode:i.metadata.variant==="light"?"light":"dark",terminalBackground:i.colors.surface.background,terminalForeground:i.colors.syntax.base.foreground};const{monoFont:c}=wu(),d=le(re=>re.terminalFontSize),u=le(re=>re.terminalShell),f=le(re=>re.terminalLoginShells.includes(re.terminalShell)),{isMobile:p,isTablet:x,hasTouchOnlyPointer:y}=an(),m=p||x,h=(m||y)&&o.platform==="web",b=!0,g=le(re=>re.showTerminalQuickKeysOnDesktop),S=m||g,v=Te(re=>re.currentSessionId),E=Te(re=>re.newSessionDraft),j=v!==null||E?.open===!0,k=vu()??null,C=ge(re=>k?re.sessions.get(k):void 0),w=ge(re=>re.hasHydrated),N=le(re=>re.openContextPreview),T=a.useMemo(()=>C?C.activeTabId??C.tabs[0]?.id??null:null,[C,b]),O=a.useMemo(()=>{if(C)return T?C.tabs.find(re=>re.id===T)??C.tabs[0]:C.tabs[0]},[C,T]),$=a.useMemo(()=>(C?.tabs??[]).map(re=>({icon:(()=>{const Le=re.iconKey?Rn[re.iconKey]??"terminal":"terminal";return s.jsx(P,{name:Le,className:"h-4 w-4"})})(),id:re.id,label:re.label,title:re.label,closeLabel:"Close tab"})),[C?.tabs]),U=O?.terminalSessionId??null,K=O?.lifecycle??"idle",L=a.useMemo(()=>(C?.tabs??[]).map(re=>({id:re.id,terminalSessionId:re.terminalSessionId,label:re.label})),[C?.tabs]),D=O?.isConnecting??!1,R=O?.previewUrl??null,M=le(re=>re.activeMainTab)==="terminal",W=e??M,[G,B]=a.useState(W);a.useEffect(()=>{W&&B(!0)},[W]);const{connectionError:xe,setConnectionError:V,isFatalError:je,setIsFatalError:Re,isReconnectPending:H,setIsReconnectPending:z,terminalIdRef:Y,lastViewportSizeRef:X,directoryRef:te,activeTabIdRef:ue,resetTerminalPreviewScan:he,startStream:Q}=db({terminal:r,effectiveDirectory:k,activeTabId:T,terminalSessionId:U,terminalLifecycle:K,hasOpenedTerminalViewport:G,terminalHydrated:w,terminalShell:u,terminalLoginShell:f,terminalAppearanceRef:l,enableTabs:b,hasActiveContext:j,tabs:L,focusTerminalWhenWindowActive:()=>{!h&&typeof document<"u"&&document.hasFocus()&&ce.current?.focus()}}),{activeModifier:se,terminalControllerRef:ce,focusTerminalWhenWindowActive:Ce,handleViewportInput:ve,handleModifierToggle:Ge,handleMobileKeyPress:q}=ub({terminal:r,terminalIdRef:Y,isReconnectPending:H,setConnectionError:V,showQuickKeys:S,isTerminalVisible:W,lastViewportSizeRef:X,terminalSessionId:U,useTouchTerminalInput:h}),{isRestarting:ae,handleRestart:ne,handleHardRestart:me,handleCreateTab:fe,handleSelectTab:Be,handleCloseTab:Se}=fb({terminal:r,effectiveDirectory:k,activeTabId:T,enableTabs:b,terminalShell:u,terminalLoginShell:f,terminalAppearanceRef:l,lastViewportSizeRef:X,directoryRef:te,activeTabIdRef:ue,terminalIdRef:Y,resetTerminalPreviewScan:he,startStream:Q,setConnectionError:V,setIsFatalError:Re,setIsReconnectPending:z});a.useEffect(()=>{if(!W||h)return;if(typeof window>"u"){Ce();return}const re=window.requestAnimationFrame(()=>{Ce()});return()=>{window.cancelAnimationFrame(re)}},[T,Ce,W,h]);const ee=a.useMemo(()=>{const re=bn[Br].stack;if(typeof window>"u")return(bn[c]??bn[Br]).stack;const nt=window.getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono");return nt&&nt.trim().length>0?nt.trim():(bn[c]??bn[Br]).stack??re},[c]),we=a.useMemo(()=>Fg(i),[i]),pe=`${k??"no-dir"}::${T??"no-tab"}`;if(a.useEffect(()=>{if(!W||h)return;const re=ce.current;if(!re)return;const Le=()=>{re.fit()};if(typeof window<"u"){const nt=window.requestAnimationFrame(()=>{Le(),Ce()}),at=[220,400].map(Ve=>window.setTimeout(Le,Ve));return()=>{window.cancelAnimationFrame(nt),at.forEach(Ve=>window.clearTimeout(Ve))}}Le()},[Ce,W,h,ce,pe,U]),a.useEffect(()=>{if(!W||!h)return;let re=null;const Le=()=>{re!==null&&window.cancelAnimationFrame(re),re=window.requestAnimationFrame(()=>{re=null,ce.current?.fit()})};return window.addEventListener("oc:keyboard-settled",Le),()=>{window.removeEventListener("oc:keyboard-settled",Le),re!==null&&window.cancelAnimationFrame(re)}},[W,ce,pe,h]),!j)return s.jsx("div",{className:"flex h-full items-center justify-center p-4 text-center text-sm text-muted-foreground",children:"Select a session to open the terminal."});if(!k)return s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-sm text-muted-foreground",children:[s.jsx("p",{children:"No working directory available for this session."}),s.jsx("button",{onClick:ne,className:"rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:"Retry"})]});const ye=!U||D||ae||H,We=G,qe=C?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(ha,{items:$,activeId:T,onSelect:Be,onClose:Se,onCreate:fe})}),s.jsx(Ne,{type:"button",size:"xs",variant:"ghost",className:"h-8 w-8 shrink-0 p-0",onClick:fe,title:"New tab","aria-label":"New tab",children:s.jsx(P,{name:"add",className:"h-4 w-4"})}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1 overflow-visible",children:[s.jsx(Ne,{type:"button",size:"xs",variant:"ghost",className:"h-8 w-8 p-0",onClick:()=>{ne()},disabled:ae,title:"Restart terminal","aria-label":"Restart terminal",children:s.jsx(P,{name:"restart",className:"h-4 w-4"})}),R?s.jsxs(Ne,{type:"button",size:"xs",variant:"outline",className:"h-6 shrink-0 gap-1 px-2",onClick:()=>{k&&N(k,R)},title:"Open preview pane",children:[s.jsx(P,{name:"global",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"whitespace-nowrap",children:"Preview"})]}):null]})]}):null,Pe=s.jsx(Vg,{isTouchTerminal:m,activeModifier:se,disabled:ye,onKeyPress:q,onModifierToggle:Ge}),Ye=!n||m||S;return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[qe&&n?Od.createPortal(s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:qe}),n):null,m&&qe&&!n&&C?s.jsx(Yg,{leading:s.jsx("div",{className:"min-w-0 flex-1 -ml-2",children:s.jsx(ha,{items:$,activeId:T,onSelect:Be,onClose:Se,onCreate:fe})}),actions:s.jsxs(s.Fragment,{children:[s.jsx(Ne,{type:"button",variant:"ghost",size:"icon",onClick:fe,title:"New tab","aria-label":"New tab",children:s.jsx(P,{name:"add",className:"size-4"})}),s.jsx(Ne,{type:"button",variant:"ghost",size:"icon",onClick:()=>{ne()},disabled:ae,title:"Restart terminal","aria-label":"Restart terminal",children:s.jsx(P,{name:"restart",className:"size-4"})}),R?s.jsxs(Ne,{type:"button",variant:"outline",size:"sm",className:"h-8 shrink-0 gap-1 px-2",onClick:()=>{k&&N(k,R)},title:"Open preview pane",children:[s.jsx(P,{name:"global",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"whitespace-nowrap",children:"Preview"})]}):null,t?s.jsx(Ne,{type:"button",variant:"ghost",size:"icon",onClick:t,title:"Close terminal view","aria-label":"Close terminal view",children:s.jsx(P,{name:"close",className:"size-4"})}):null]})}):null,!m&&Ye?s.jsxs("div",{className:_("app-region-no-drag sticky top-0 z-20 shrink-0 bg-background text-xs","px-3 py-2"),children:[qe&&!n?s.jsxs("div",{className:"flex items-center gap-2 pl-1 pr-1",children:[qe,t?s.jsx(Ne,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0",onClick:t,title:"Close terminal view","aria-label":"Close terminal view",children:s.jsx(P,{name:"close",className:"h-4 w-4"})}):null]}):null,!m&&S&&b&&C?s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1 pl-1 pr-1",children:Pe}):null,!m&&S&&!C?s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1",children:Pe}):null]}):null,s.jsxs("div",{className:"relative flex-1 overflow-hidden",style:{backgroundColor:we.background},children:[s.jsx("div",{className:"h-full w-full box-border pl-4 pr-1.5 pt-3 pb-4",children:We&&k&&C?C.tabs.map(re=>{const Le=re.id===T;return s.jsx(qg,{directory:k,tabId:re.id,sessionId:re.terminalSessionId,sessionKey:`${k}::${re.id}`,isActive:Le,isTerminalVisible:W,terminal:r,theme:we,fontFamily:ee,fontSize:d,enableTouchScroll:h,lastViewportSizeRef:X,onInput:ve,controllerRef:ce},re.id)}):null}),!H&&xe&&s.jsxs("div",{className:"absolute inset-x-0 bottom-0 border-t border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 text-xs text-foreground flex items-center justify-between gap-2",children:[s.jsx("span",{children:xe}),je&&m&&s.jsx(Ne,{size:"sm",variant:"secondary",className:"h-6 px-2 py-0 text-xs",onClick:me,disabled:ae,title:"Force kill and create fresh session",type:"button",children:"Hard Restart"})]})]}),m&&S?s.jsx("div",{className:"shrink-0 overflow-x-auto border-t border-border/40 bg-[var(--surface-background)] px-2 pt-1.5 pb-[max(0.375rem,calc(var(--oc-app-bottom-safe,0px)-var(--oc-keyboard-inset,0px)))] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","data-no-drawer-swipe":"true",children:s.jsx("div",{className:"flex min-w-max items-center gap-1.5",children:Pe})}):null]})},Lo=[{id:"changes",label:"Changes",icon:"git-branch"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal-box"},{id:"pull-requests",label:"PRs",icon:"git-pull-request"},{id:"issues",label:"Issues",icon:"task"}],hb=new Set(Lo.map(e=>e.id)),mb=e=>typeof e=="string"&&hb.has(e),ly=e=>mb(e)?e:"changes",ac=e=>e==="pull-requests"||e==="issues",pb=e=>e?Lo:Lo.filter(t=>!ac(t.id)),cy=(e,t)=>ac(e)?"changes":e,gb=48,bb=96,yt=(e,...t)=>{try{e?.(...t)}catch{}},eo=(e,t)=>{if(typeof e=="function"){const n=e();return n>0?n:t}return typeof e=="number"&&e>0?e:t},dy=(e,t)=>{const n=a.useRef(t);n.current=t;const r=t.enabled;a.useEffect(()=>{const o=e.current;if(!o||r===!1)return;const i=o.style.touchAction;o.style.touchAction="pan-x pan-y";const c=window.Capacitor?.getPlatform?.()==="android"?bb:gb;let d=!1,u=!1,f=!1,p=null,x=!1,y=0,m=0,h=0,b=0;const g=()=>{d=!1,u=!1,f=!1,p=null},S=()=>{const N=n.current,T=p,O=x;u&&T&&(yt(T==="left"?N.onLeftProgress:N.onRightProgress,O?1:0),yt(N.onDragEnd,T,O)),g()},v=()=>{S(),u||g()},E=N=>{const T=n.current;if(T.enabled===!1){u&&p?S():g();return}if(N.touches.length!==1){u&&p?S():g();return}const O=N.touches[0],$=o.getBoundingClientRect(),U=o.clientWidth,K=!!T.leftOpen,L=!!T.rightOpen,D=R=>Ag(R,o);if(K||L){if(D(N.target)){g();return}if(K&&L){const R=O.clientX<=$.left+c;O.clientX>=$.right-c?(p="right",x=!0):R?(p="left",x=!0):(p=K?"left":"right",x=!0)}else K?(p="left",x=!0):(p="right",x=!0);b=eo(p==="left"?T.leftWidth:T.rightWidth,U),b<10&&(b=U||window.innerWidth||320),b<10&&(b=320),d=!0}else{if(D(N.target)){g();return}p=null,x=!1,b=0,d=!0}y=O.clientX,m=O.clientY,h=Date.now(),u=!1,f=!1},j=N=>{if(!d)return;if(N.touches.length!==1){v();return}const T=N.touches[0],O=T.clientX-y,$=T.clientY-m;if(!f){if(Math.abs(O)<la&&Math.abs($)<la)return;if(Math.abs($)>Math.abs(O)*jn){g();return}if(!p){const L=n.current;p=O>0?"left":"right",b=eo(p==="left"?L.leftWidth:L.rightWidth,o.clientWidth),b<10&&(b=window.innerWidth||320)}if(p==="left"){if(!x&&O<=0){g();return}if(x&&O>=0){g();return}}else{if(!x&&O>=0){g();return}if(x&&O<=0){g();return}}f=!0,u=!0,yt(n.current.onDragStart,p)}if(!u)return;N.cancelable&&N.preventDefault();const U=n.current,K=ca(p,x,O,b);yt(p==="left"?U.onLeftProgress:U.onRightProgress,K)},k=(N,T)=>{if(!d){g();return}const O=N-y,$=T-m;if(!p&&!x&&Math.abs(O)>=or&&Math.abs($)<=Math.abs(O)*jn){const I=n.current;p=O>0?"left":"right",b=eo(p==="left"?I.leftWidth:I.rightWidth,o.clientWidth),b<10&&(b=window.innerWidth||320)}if(!p){g();return}const U=Math.max(1,Date.now()-h),K=n.current;if(!u){const I=Math.abs(O),M=Math.abs($);I>=or&&M<=I*jn?p==="left"&&!x&&O>0?(yt(K.onLeftProgress,1),yt(K.onLeftOpen)):p==="right"&&!x&&O<0?(yt(K.onRightProgress,1),yt(K.onRightOpen)):yt(p==="left"?K.onLeftProgress:K.onRightProgress,x?1:0):yt(p==="left"?K.onLeftProgress:K.onRightProgress,x?1:0);const W=p;g(),yt(K.onDragEnd,W);return}const L=ca(p,x,O,b),D=Cg({side:p,isOpenAtStart:x,dx:O,dt:U,progress:L}),R=p;yt(R==="left"?D?K.onLeftOpen:K.onLeftClose:D?K.onRightOpen:K.onRightClose),g(),yt(K.onDragEnd,R,D)},C=N=>{const T=N.changedTouches[0];if(!T){g();return}const O=T.clientX-y,$=T.clientY-m;d&&(u||Math.abs(O)>=or&&Math.abs($)<=Math.abs(O)*jn)&&N.cancelable&&N.preventDefault(),k(T.clientX,T.clientY)},w=()=>{v()};return o.addEventListener("touchstart",E,{passive:!0}),o.addEventListener("touchmove",j,{passive:!1}),o.addEventListener("touchend",C,{passive:!1}),o.addEventListener("touchcancel",w,{passive:!0}),()=>{try{u&&p&&S()}catch{}o.style.touchAction=i,o.removeEventListener("touchstart",E),o.removeEventListener("touchmove",j),o.removeEventListener("touchend",C),o.removeEventListener("touchcancel",w)}},[e,r])};function uy({className:e="h-5 w-5"}){return s.jsxs("span",{"aria-hidden":"true",className:`relative inline-block overflow-hidden rounded-[2px] ${e}`,children:[s.jsx("span",{className:"absolute left-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-error)]/25"}),s.jsx("span",{className:"absolute right-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-success)]/25"}),s.jsx(P,{name:"layout-column",className:"absolute inset-0 h-full w-full"})]})}function ga({size:e,className:t,style:n,...r}){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:t,style:{width:typeof e=="number"?`${e}px`:e,height:typeof e=="number"?`${e}px`:e,...n},...r,children: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"})})}const xb=({sessionDirectory:e,draftDirectory:t,isNewSessionDraftOpen:n})=>n?t:e,yb=({activeProjectLabel:e,openDirectory:t,homeDirectory:n})=>wr(t,n)?null:e,to=()=>Ns.filter(e=>po.has(e.id)).map(e=>({...el(e)})),wb=()=>{if(typeof window>"u")return go;const e=window.localStorage.getItem("openInAppId");return e&&mo(e)?e:go};let so=!1,qs=!1,ps=!1,gs=0,Dn=null;const ba=()=>{Dn&&(clearTimeout(Dn),Dn=null)},Cs=Ls()((e,t)=>({selectedAppId:wb(),availableApps:to(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(so||typeof window>"u")return;so=!0;const n=(d,u=!0)=>{if(!Array.isArray(d)||d.length===0){e({availableApps:to(),hasLoadedApps:u});return}const f=new Set(d.map(m=>m.name)),p=new Map(d.map(m=>[m.name,m.iconDataUrl??void 0])),y=Ns.filter(m=>f.has(m.appName)||po.has(m.id)).map(m=>({...el(m),iconDataUrl:p.get(m.appName)}));e({availableApps:y,hasLoadedApps:!0})},r=async d=>{if(!tn()||!cr()||qs||t().hasLoadedApps&&!d)return;const f=Ns.map(p=>p.appName);ba(),qs=!0,ps=!1,e({isScanning:!0});try{const{apps:p,success:x,hasCache:y,isCacheStale:m}=await Ni(f,d),h=x&&!y&&p.length===0&&gs<3;if(e({isCacheStale:y?m:!1}),n(p,x?!h:!1),x){if(h){const g=[800,1600,3200][gs]??3200;gs+=1,ps=!0,Dn=setTimeout(()=>{r()},g);return}gs=0,ps=!1;return}if(gs<3){const g=[1e3,3e3,7e3][gs]??7e3;gs+=1,ps=!0,Dn=setTimeout(()=>{r()},g)}}finally{qs=!1,ps||e({isScanning:!1})}};r();const o=d=>{const u=d.detail,f=u&&typeof u.openInAppId=="string"&&u.openInAppId.length>0&&mo(u.openInAppId)?u.openInAppId:null;f&&(window.localStorage.setItem("openInAppId",f),e({selectedAppId:f}))},i=()=>{r()},l=d=>{const u=d.detail;Array.isArray(u)&&(gs=3,ps=!1,e({isScanning:!1,isCacheStale:!1}),n(u))};window.addEventListener("pichamber:settings-synced",o),window.addEventListener("pichamber:app-ready",i),window.addEventListener("pichamber:installed-apps-updated",l),window.__pichamberAppReady&&r(),window.setTimeout(()=>{t().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(so||t().initialize(),!tn()||!cr()||qs||t().hasLoadedApps&&!n)return;const o=Ns.map(i=>i.appName);ba(),n&&e({hasLoadedApps:!1}),qs=!0,ps=!1,e({isScanning:!0});try{const{apps:i,hasCache:l,isCacheStale:c}=await Ni(o,n),d=new Set(i.map(x=>x.name)),u=new Map(i.map(x=>[x.name,x.iconDataUrl??void 0])),p=Ns.filter(x=>d.has(x.appName)||po.has(x.id)).map(x=>({...x,iconDataUrl:u.get(x.appName)}));e({availableApps:p.length>0?p:to(),hasLoadedApps:p.length>0,isCacheStale:l?c:!1})}finally{qs=!1,ps||e({isScanning:!1})}},selectApp:async n=>{mo(n)&&(e({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Qa({openInAppId:n}))}})),vb="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",Sb="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",no=e=>({...e,fallbackIconDataUrl:e.id==="finder"&&window.__PICHAMBER_PLATFORM__==="darwin"?vb:e.id==="terminal"?Sb:void 0}),xa=({label:e,iconDataUrl:t,fallbackIconDataUrl:n})=>{const[r,o]=a.useState(!1),i=e.trim().slice(0,1).toUpperCase()||"?",l=t||n;return l&&!r?s.jsx("img",{src:l,alt:"",className:"h-4 w-4 rounded-sm",onError:()=>o(!0)}):s.jsx("span",{className:_("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),children:i})},jb=({directory:e,className:t})=>{const n=Cs(m=>m.selectedAppId),r=Cs(m=>m.availableApps),o=Cs(m=>m.isCacheStale),i=Cs(m=>m.isScanning),l=Cs(m=>m.initialize),c=Cs(m=>m.loadInstalledApps),d=Cs(m=>m.selectApp);a.useEffect(()=>{l()},[l]);const u=tn()&&cr(),f=a.useMemo(()=>{const m=r.find(h=>h.id===n)??r.find(h=>h.id===go)??r[0]??Ns[0];return no(m||Ns[0])},[r,n]);if(!u||!e||r.length===0)return null;const p=async m=>{await Ju(e,m.id,m.appName)||await Xa(e,m.appName)},x=async m=>{await d(m.id),await p(m)},y=async()=>{(await ys(e)).ok&&ie.success("Path copied to clipboard")};return s.jsxs("div",{className:_("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",t),children:[s.jsx("button",{type:"button",onClick:()=>{p(f)},className:_("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",i&&"animate-pulse"),"aria-label":`Open in ${f.label}`,children:s.jsx(xa,{label:f.label,iconDataUrl:f.iconDataUrl,fallbackIconDataUrl:f.fallbackIconDataUrl})}),s.jsxs(Wt,{children:[s.jsx(Gt,{asChild:!0,children:s.jsx("button",{type:"button",className:_("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"),"aria-label":"Choose app to open",children:s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Ht,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[s.jsxs(ft,{className:"flex items-center gap-2",onClick:()=>{y()},children:[s.jsx(P,{name:"file-copy",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:"Copy Path"})]}),s.jsx(en,{}),r.map(m=>{const h=no(m);return s.jsxs(ft,{className:"flex items-center gap-2",onClick:()=>{x(m)},children:[s.jsx(xa,{label:m.label,iconDataUrl:m.iconDataUrl,fallbackIconDataUrl:h.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:m.label}),f.id===m.id?s.jsx(P,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},m.id)}),o?s.jsxs(ft,{className:"flex items-center gap-2",onClick:()=>{c(!0)},children:[s.jsx(P,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:"Refresh Apps"})]}):null]})]})]})},Cb="\x1B",kb=new RegExp(`${Cb}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Ab=/https?:\/\/[^\s<>'"`]+/gi,jt="__pichamber_auto_discover_preview__",Nb=15e3,Ib=e=>{let t="";for(let n=0;n<e.length;n+=1){const r=e.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(t+=e[n])}return t},Eb=e=>{const t=(e||"").trim();if(!t)return null;const n=/^https?:\/\//i.test(t)?t:`http://${t}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},Rb=e=>{const n=e.replace(kb,"").match(Ab);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const o=[];for(const i of r)try{const l=new URL(i);l.port&&l.port.length>0&&o.push({raw:i,parsed:l})}catch{}if(o.length>0){const i=l=>{const{parsed:c}=l,d=c.hostname.toLowerCase(),u=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",f=c.pathname||"/",p=f.split("/").filter(Boolean).length,x=f==="/"||f==="",y=!!(c.search||c.hash);let m=0;return u&&(m+=50),x&&(m+=30),m-=Math.min(p*5,20),y&&(m-=10),m};return o.sort((l,c)=>i(c)-i(l)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},Db=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Pb=["dev","start","preview","serve"];async function Mb(e,t,n){if(!e)return null;const r=Lb(t);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const o=Ob(n);if(o){const i=await Bb(e);return{command:`${i==="npm"?"npm run":i==="yarn"?"yarn":i==="pnpm"?"pnpm":i==="bun"?"bun run --shell=bun":"npm run"} ${o}`,label:`Start (${o})`}}}if(await Tb(e)){const o=await Fb(),i=typeof o=="number"&&Number.isFinite(o)&&o>0?o:8e3;return{command:`python3 -m http.server ${i}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${i}/`}}return null}async function Tb(e){const t=`${e}/index.html`,n=await yr(t,e);return typeof n=="string"&&n.trim().length>0}async function Fb(){try{const e=await Tt("/api/system/free-port",{cache:"no-store"});if(!e.ok)return null;const t=await e.json().catch(()=>null),n=typeof t?.port=="number"?t.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Lb(e){for(const t of e){const n=`${t.name} ${t.command}`.toLowerCase();if(Pb.some(o=>n.includes(o)))return t}return null}function Ob(e){for(const{pattern:t}of Db)for(const n of Object.keys(e))if(t.test(n))return n;return null}async function Bb(e){const t=await yr(`${e}/package.json`,e);if(t)try{const r=JSON.parse(t),o=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(o.startsWith("bun@"))return"bun";if(o.startsWith("pnpm@"))return"pnpm";if(o.startsWith("yarn@"))return"yarn";if(o.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,o]of n){const i=await yr(`${e}/${r}`,e);if(typeof i=="string"&&i.trim().length>0)return o}return"npm"}async function yr(e,t){if(t?.trim())try{const r=new URLSearchParams({path:e,directory:t,optional:"true"}),o=await Tt(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=Ja()?.files;if(n?.readFile)try{const r=await n.readFile(e,{optional:!0});return typeof r?.content=="string"?r.content:null}catch{return null}try{const r=await Tt(`/api/fs/read?path=${encodeURIComponent(e)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function _b(e){try{const t=await yr(`${e}/package.json`,e);if(t==null)return null;const r=JSON.parse(t).scripts;return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}const zb=(e,t,n)=>new Promise(r=>{let o=!1,i=null,l=null;const c=d=>{o||(o=!0,l&&clearTimeout(l),i?.close(),r(d))};i=e.connect(t,{onEvent:d=>{(d.type==="exit"||d.type==="snapshot"&&d.status==="exited")&&c(!0)},onError:(d,u)=>{u&&c(!0)}}),o?i.close():l=setTimeout(()=>c(!1),n)});function Ub({projectRef:e,directory:t,allowMobile:n=!1}){const{currentTheme:r}=Ha(),{terminal:o}=Fs(),{isMobile:i}=an(),l=le(q=>q.terminalShell),c=le(q=>q.terminalLoginShells.includes(q.terminalShell)),d=le(q=>q.setSettingsPage),u=le(q=>q.setSettingsDialogOpen),f=le(q=>q.setSettingsProjectsSelectedId),p=le(q=>q.openContextPreview),x=ge(q=>q.ensureDirectory),y=ge(q=>q.setTabLabel),m=ge(q=>q.setTabIconKey),h=ge(q=>q.setActiveTab),b=ge(q=>q.setConnecting),g=ge(q=>q.setTabSessionId),S=ge(q=>q.setTabPreviewUrl),v=ge(q=>q.projectActionRuns),E=ge(q=>q.setProjectActionRun),j=ge(q=>q.updateProjectActionRunStatus),k=ge(q=>q.removeProjectActionRun),[C,w]=a.useState([]),[N,T]=a.useState(null),[O,$]=a.useState(!1),U=a.useRef({}),K=a.useRef({}),L=a.useRef({}),D=a.useRef({}),R=a.useRef(new Set),I=a.useRef(0),M=e?.id??null,W=e?.path??"",G=a.useMemo(()=>M?{id:M,path:W}:null,[M,W]),B=a.useCallback(async q=>{await Ta(q)},[]),xe=a.useCallback(async()=>{if(!G)return;const q=I.current+1;I.current=q,$(!0);try{const ae=await io(G);if(I.current!==q)return;const ne=ae.actions;w(ne),T(me=>me===jt||me&&ne.some(fe=>fe.id===me)?me:null)}catch{if(I.current!==q)return}finally{I.current===q&&$(!1)}},[G]),V=a.useMemo(()=>jl(t||G?.path||""),[t,G?.path]),je=a.useMemo(()=>N?C.find(q=>q.id===N)??null:null,[C,N]),Re=a.useMemo(()=>({id:jt,name:"Auto-discover",command:"",icon:"scan-2",autoOpenUrl:!0}),[]),H=!i,z=a.useMemo(()=>H?[Re,...C]:C,[C,Re,H]);a.useEffect(()=>{xe()},[xe]),a.useEffect(()=>{if(typeof window>"u")return;const q=ae=>{const ne=ae.detail;M&&(ne?.projectId&&ne.projectId!==M||xe())};return window.addEventListener(So,q),()=>{window.removeEventListener(So,q)}},[xe,M]),a.useEffect(()=>{N&&(N===jt&&H||C.some(q=>q.id===N)||T(null))},[C,H,N]),a.useEffect(()=>{const q=()=>{const ae=ge.getState(),ne=ae.sessions,me=ae.projectActionRuns;for(const[fe,Be]of Object.entries(me)){const ee=ne.get(Be.directory)?.tabs.find(Le=>Le.id===Be.tabId);if(!ee||ee.terminalSessionId!==Be.sessionId){k(fe);continue}const we=K.current[fe]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};K.current[fe]=we;const pe=z.find(Le=>Le.id===Be.actionId),ye=ae.getBuffer(Be.directory,Be.tabId).chunks;if(!pe||ye.length===0)continue;const We=ye.filter(Le=>we.lastSeenChunkId===null||Le.id>we.lastSeenChunkId);if(We.length===0)continue;const qe=We.map(Le=>Le.data).join(""),Pe=`${we.tail}${qe}`,Ye=!we.openedUrl&&pe.autoOpenUrl===!0?Rb(Pe):null,re=We[We.length-1]?.id??we.lastSeenChunkId;if(we.lastSeenChunkId=re,we.tail=Pe.slice(-512),Ye)if(we.openedUrl=!0,we.openInPreview){const Le=me[fe];Le&&(S(Le.directory,Le.tabId,Ye,{locked:!1,autoOpened:!1}),Le.status==="waiting-for-preview"&&j(fe,"running"),window.clearTimeout(D.current[fe]),delete D.current[fe],p(Le.directory,Ye))}else B(Ye),ie.success("Opened URL from action output");K.current[fe]=we}for(const fe of Object.keys(K.current))me[fe]||(delete K.current[fe],window.clearTimeout(D.current[fe]),delete D.current[fe])};return q(),ge.subscribe((ae,ne)=>{(ae.sessions!==ne.sessions||ae.buffers!==ne.buffers)&&q()})},[z,p,B,v,k,S,j]);const Y=a.useCallback(async(q,ae={})=>{if(!V)throw new Error("No active directory");const ne=ls(V,q.id);x(V);const me=ge.getState(),fe=me.getDirectoryState(V);let Be=U.current[ne]||null;const Se=Be?!!fe?.tabs.some(pe=>pe.id===Be):!1;(!Be||!Se)&&(Be=me.createTab(V),U.current[ne]=Be),y(V,Be,`Action: ${q.name}`),m(V,Be,q.icon||"play"),h(V,Be),ae.revealTerminal!==!1&&le.getState().openContextPanelTab(V,{mode:"terminal"});const we=ge.getState().getDirectoryState(V)?.tabs.find(pe=>pe.id===Be);return{key:ne,tabId:Be,sessionId:we?.terminalSessionId??null}},[x,V,h,m,y]),X=a.useCallback(async q=>{if(!n&&i)return;if(!V){ie.error("No active directory for action");return}const ae=ls(V,q.id),ne=v[ae];if(!(ne&&ne.status==="running")&&!R.current.has(ae)){R.current.add(ae);try{const me=q.id===jt?await(async()=>{const[Pe,Ye]=await Promise.all([io({id:G?.id??"",path:V}),_b(V)]),re=await Mb(V,Pe.actions,Ye);if(!re)throw new Error('No dev server command found. Configure a project action or add a "dev" script to package.json.');return{id:jt,name:"Auto-discover",command:re.command,icon:"scan-2",autoOpenUrl:!0,openUrl:re.previewUrlHint||""}})():q,fe=me.autoOpenUrl===!0&&(me.openUrl||"").trim().length>0,Be=!fe&&q.id!==jt,{key:Se,tabId:ee,sessionId:we}=await Y(me,{revealTerminal:Be});let pe=we;if(!pe){b(V,ee,!0);try{pe=(await o.createSession({cwd:V,sessionId:ee,shell:l,loginShell:c,themeMode:r.metadata.variant==="light"?"light":"dark",terminalBackground:r.colors.surface.background,terminalForeground:r.colors.syntax.base.foreground})).sessionId,g(V,ee,pe)}finally{b(V,ee,!1)}}if(!pe)throw new Error("Failed to create terminal session");L.current[Se]?.(),b(V,ee,!0);const ye=o.connect(pe,{onEvent:Pe=>{Pe.type==="snapshot"&&(ge.getState().replaceBuffer(V,ee,Pe.data??"",Pe.sequence??0),ge.getState().setConnecting(V,ee,!1)),Pe.type==="data"&&typeof Pe.data=="string"&&Pe.data.length>0&&ge.getState().appendToBuffer(V,ee,Pe.data,Pe.sequence,Pe.replayData),Pe.type==="exit"&&(ge.getState().setTabLifecycle(V,ee,"exited"),ge.getState().setConnecting(V,ee,!1),ge.getState().removeProjectActionRun(Se),delete K.current[Se],L.current[Se]?.(),delete L.current[Se],window.clearTimeout(D.current[Se]),delete D.current[Se])},onError:(Pe,Ye)=>{ge.getState().setConnecting(V,ee,!1),Ye&&(ge.getState().setTabLifecycle(V,ee,"exited"),ge.getState().setTabSessionId(V,ee,null),ge.getState().removeProjectActionRun(Se))}});L.current[Se]=ye.close;const We=me.autoOpenUrl?Eb(me.openUrl):null;E({key:Se,directory:V,actionId:me.id,tabId:ee,sessionId:pe,status:me.id===jt&&!We?"waiting-for-preview":"running"}),window.clearTimeout(D.current[Se]),delete D.current[Se],me.id===jt&&!We&&(D.current[Se]=window.setTimeout(()=>{const Pe=ge.getState(),Ye=Pe.projectActionRuns[Se];Pe.updateProjectActionRunStatus(Se,"running"),Ye&&(Pe.setActiveTab(Ye.directory,Ye.tabId),le.getState().openContextPanelTab(Ye.directory,{mode:"terminal"})),delete D.current[Se]},Nb)),K.current[Se]={lastSeenChunkId:null,openedUrl:!!We||fe,tail:"",openInPreview:me.id===jt};const qe=Ib(me.command.trim().replace(/\r\n|\r/g,`
|
|
62
|
+
`));await o.sendInput(pe,`${qe}\r`),We?(S(V,ee,We,{locked:!0,autoOpened:!0}),p(V,We),ie.success("Opened action URL")):fe?(S(V,ee,null,{locked:!0}),ie.error("Invalid custom URL format")):S(V,ee,null,{locked:!1,autoOpened:!1})}catch(me){k(ae),delete K.current[ae],L.current[ae]?.(),delete L.current[ae],window.clearTimeout(D.current[ae]),delete D.current[ae],ie.error(me instanceof Error?me.message:"Failed to run action")}finally{R.current.delete(ae)}}},[r.colors.surface.background,r.colors.syntax.base.foreground,r.metadata.variant,Y,n,i,V,c,l,p,v,k,b,E,S,g,G?.id,o]),te=a.useCallback(async q=>{const ae=ls(V,q.id),ne=v[ae];if(!ne)return;j(ae,"stopping");const me=zb(o,ne.sessionId,1e3);try{await o.sendInput(ne.sessionId,"")}catch{}const fe=await me;if(ge.getState().getDirectoryState(ne.directory)?.tabs.find(ee=>ee.id===ne.tabId)?.terminalSessionId===ne.sessionId&&!fe){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:ne.sessionId})}catch{}else try{await o.close(ne.sessionId)}catch{}g(ne.directory,ne.tabId,null)}k(ae),delete K.current[ae],L.current[ae]?.(),delete L.current[ae],window.clearTimeout(D.current[ae]),delete D.current[ae]},[V,v,k,g,o,j]),ue=a.useCallback(()=>{const q=je??z[0];if(!q)return;const ae=ls(V,q.id),ne=v[ae];if(ne?.status!=="stopping"){if(ne){te(q);return}X(q)}},[z,V,X,v,je,te]),he=a.useCallback((q,ae=!1)=>{if(T(q.id),!ae){X(q);return}const ne=ls(V,q.id),me=v[ne];if(me?.status!=="stopping"){if(me){te(q);return}X(q)}},[V,X,v,te]),Q=a.useCallback(()=>{G?.id&&(f(G.id),d("projects"),u(!0))},[u,d,f,G?.id]),se=je??z[0]??null,ce=se?v[ls(V,se.id)]:null,Ce=ge(q=>ce?q.sessions.get(ce.directory)?.tabs.find(ae=>ae.id===ce.tabId)?.previewUrl??null:null),ve=!!((n||!i)&&G&&V),Ge=je??z[0]??null;return{shouldRender:ve,isLoading:O,normalizedDirectory:V,resolvedSelected:Ge,displayActions:z,projectActionRuns:v,selectedRunPreviewUrl:Ce,handlePrimaryClick:ue,handleSelectAction:he,openProjectActionsSettings:Q,openContextPreview:p}}const ya=({projectRef:e,directory:t,className:n,compact:r=!1,allowMobile:o=!1})=>{const{shouldRender:i,isLoading:l,normalizedDirectory:c,resolvedSelected:d,displayActions:u,projectActionRuns:f,selectedRunPreviewUrl:p,handlePrimaryClick:x,handleSelectAction:y,openProjectActionsSettings:m,openContextPreview:h}=Ub({projectRef:e,directory:t,allowMobile:o});if(!i||!d)return null;const b=d.icon||"play",g=d.id===jt?"scan-2":Rn[b]||"play",S=ls(c,d.id),v=f[S],E=v?.status==="stopping",j=v?.status==="waiting-for-preview",k=!!(v&&p),C=()=>{!v||!p||h(v.directory,p)},w=d.id===jt;return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",disabled:l||E,className:_("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:x,"aria-label":v?`Stop ${d.name}`:`Run ${d.name}`,children:E||j?s.jsx(P,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):v?s.jsx(P,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(P,{name:g,className:"h-5 w-5"})})}),w?s.jsx(Ke,{sideOffset:6,children:"Automatically discover and run the development server"}):null]}),k?s.jsxs(Ue,{children:[s.jsx($e,{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":"Open Preview",onClick:C,children:s.jsx(P,{name:"global",className:"h-4 w-4"})})}),s.jsx(Ke,{sideOffset:6,children:"Open Preview"})]}):null,s.jsxs(Wt,{children:[s.jsx(Gt,{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":"Choose project action",children:s.jsx(P,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Ht,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(ft,{className:"flex items-center gap-2",onClick:m,children:[s.jsx(P,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),s.jsx(en,{}),u.map(N=>{const T=N.icon||"play",O=N.id===jt?"scan-2":Rn[T]||"play",$=ls(c,N.id),U=f[$],K=!!U,L=U?.status==="stopping";return s.jsxs(ft,{className:"flex items-center gap-2",onClick:()=>{y(N,!0)},children:[s.jsx(P,{name:O,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:N.name}),L||U?.status==="waiting-for-preview"?s.jsx(P,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):K?s.jsx(P,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},N.id)})]})]})]}):s.jsxs("div",{className:_("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:x,disabled:l||E,className:_("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":v?`Stop ${d.name}`:`Run ${d.name}`,children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:E||j?s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):v?s.jsx(P,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(P,{name:g,className:"h-4 w-4"})})})}),w?s.jsx(Ke,{sideOffset:6,children:"Automatically discover and run the development server"}):null]}),k?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:C,className:_(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":"Open Preview",children:s.jsx(P,{name:"global",className:"h-4 w-4"})})}),s.jsx(Ke,{sideOffset:6,children:"Open Preview"})]}):null,s.jsxs(Wt,{children:[s.jsx(Gt,{asChild:!0,children:s.jsx("button",{type:"button",className:_(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":"Choose project action",children:s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Ht,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(ft,{className:"flex items-center gap-2",onClick:m,children:[s.jsx(P,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),s.jsx(en,{}),u.map(N=>{const T=N.icon||"play",O=N.id===jt?"scan-2":Rn[T]||"play",$=ls(c,N.id),U=f[$],K=!!U,L=U?.status==="stopping";return s.jsxs(ft,{className:"flex items-center gap-2",onClick:()=>{y(N,!0)},children:[s.jsx(P,{name:O,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:N.name}),L||U?.status==="waiting-for-preview"?s.jsx(P,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):K?s.jsx(P,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},N.id)})]})]})]})},Ut={docker:"docker",windows:"windows",ubuntu:"ubuntu-fill",arch:"arch-linux",nixos:"nixos",fedora:"fedora",debian:"debian",centos:"centos-fill",linux:"terminal-box",darwin:"apple",unknown:"server"};function ar(e){return e?.deploymentKind==="docker"?{name:Ut.docker,color:"#2496ED"}:e?.serverPlatform==="win32"?{name:Ut.windows,color:"#0078D4"}:e?.serverPlatform==="linux"?e.serverDistribution==="ubuntu"?{name:Ut.ubuntu,color:"#E95420"}:e.serverDistribution==="arch"?{name:Ut.arch,color:"#1793D1"}:e.serverDistribution==="nixos"?{name:Ut.nixos,color:"#5277C3"}:e.serverDistribution==="fedora"?{name:Ut.fedora,color:"#51A2DA"}:e.serverDistribution==="debian"?{name:Ut.debian,color:"#A81D33"}:e.serverDistribution==="centos"?{name:Ut.centos,color:"#932279"}:{name:Ut.linux}:e?.serverPlatform==="darwin"?{name:Ut.darwin}:{name:Ut.unknown}}const $b=e=>e?.deploymentKind==="docker"?"Docker":e?.serverPlatform==="win32"?"Windows":e?.serverPlatform==="darwin"?"macOS":e?.serverPlatform==="linux"?typeof e.serverDistribution=="string"&&e.serverDistribution.trim()?{ubuntu:"Ubuntu",arch:"Arch Linux",nixos:"NixOS",fedora:"Fedora",debian:"Debian",centos:"CentOS"}[e.serverDistribution]??"Linux":"Linux":"Server";function Kb({open:e,onOpenChange:t}){const[n,r]=a.useState(null),o=a.useCallback(async()=>{const u=Qe();try{const f=await Tt("/api/version");if(!f.ok)throw new Error("Version request failed");const p=await f.json().catch(()=>null);u===Qe()&&r(p)}catch{u===Qe()&&r(null)}},[]);a.useEffect(()=>(o(),On(()=>{o()})),[o]);const i=ar(n),l=$b(n),c=typeof n?.pichamberVersion=="string"?n.pichamberVersion:null,d=typeof window<"u"?window.location.origin:"";return s.jsxs(Wt,{open:e,onOpenChange:u=>{t(u),u&&o()},children:[s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx(Gt,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":"Show connected server information",className:_(ln,"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5"),children:[s.jsx(P,{name:i.name,className:"h-[18px] w-[18px] shrink-0",style:i.color?{color:i.color}:void 0}),s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:"This server"})]})})}),s.jsx(Ke,{children:s.jsx("p",{children:"Connected server information"})})]}),s.jsxs(Ht,{align:"end",className:"w-80 max-w-[calc(100vw-2rem)] p-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[s.jsx(P,{name:i.name,className:"size-5 shrink-0",style:i.color?{color:i.color}:void 0}),s.jsx("div",{className:"truncate typography-ui-label font-medium text-foreground",children:l})]}),c?s.jsx("div",{className:"shrink-0 typography-micro text-muted-foreground",children:`v${c}`}):null]}),s.jsx("div",{className:"mt-3 border-t border-[var(--interactive-border)] pt-3 typography-micro",children:s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx("span",{className:"shrink-0 text-muted-foreground",children:"Address"}),s.jsxs("button",{type:"button",className:"ml-auto flex min-w-0 items-center gap-1.5 rounded px-1 py-0.5 text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:`Copy ${d}`,"aria-label":"Copy server address",onClick:()=>{ys(d).then(u=>{u.ok?ie.success("Server address copied"):ie.error("Could not copy server address")})},children:[s.jsx("span",{className:"block max-w-[30ch] truncate font-mono",children:d}),s.jsx(P,{name:"file-copy",className:"size-3.5 shrink-0 text-muted-foreground"})]})]})})]})]})}const Wb=({isMobile:e})=>{const n=Fs().github??null,r=Sr(i=>i.refresh),o=Mh();return a.useEffect(()=>{!n||e||r(n)},[n,e,r]),e||!n||!o?null:s.jsxs("span",{className:_(ln,"app-region-no-drag inline-flex w-auto cursor-default gap-1.5 px-2"),title:`${o} via GitHub CLI`,"aria-label":`Signed in to GitHub as ${o} via GitHub CLI`,children:[s.jsx(P,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0 text-foreground"}),s.jsxs("span",{className:"max-w-28 truncate typography-micro text-muted-foreground",children:["@",o]})]})},Gb=a.memo(function({isDesktopApp:t,currentInstanceLabel:n,compactCurrentInstanceLabel:r,currentInstanceIsLocal:o,currentInstanceIcon:i,isDesktopServicesOpen:l,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,shortcutLabel:u,remoteUpdateInfo:f,remoteUpdateChecking:p,remoteUpdateError:x,onOpenRemoteUpdate:y}){return s.jsxs(Wt,{open:l,onOpenChange:m=>{c(m),m&&d()},children:[s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx(Gt,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":t?`Open instance, usage and MCP (current: ${n})`:"Open services, usage and MCP",className:_(ln,t?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8"),children:[s.jsx(P,{name:i.name,className:"h-[18px] w-[18px]",style:i.color?{color:i.color}:void 0}),t?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:r}):null]})})}),s.jsx(Ke,{children:s.jsx("p",{children:`Current instance: ${n} (${u("toggle_services_menu")})`})})]}),s.jsx(Ht,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto p-0",children:t?s.jsxs("div",{children:[o?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:"Remote instance update"}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:f?.available?`Version ${f.version||""} is available for this instance.`:p?"Looking for updates...":x||"This instance is up to date."})]}),f?.available?s.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-[var(--primary-base)] px-3 py-1.5 typography-ui-label font-medium text-[var(--primary-foreground)] hover:opacity-90",onClick:y,children:"Update"}):null]})}),s.jsx(Su,{embedded:!0,open:l,onOpenChange:()=>{},onHostSwitched:()=>c(!1)})]}):null})]})}),Hb=({action:e,onClose:t,sessionTitle:n,onConfirm:r})=>s.jsx(ns,{open:e!==null,onOpenChange:o=>{o||t()},children:s.jsxs(rs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(vs,{children:[s.jsx(us,{children:e==="delete"?"Delete session?":"Archive session?"}),s.jsx(Ss,{children:e==="delete"?`"${n}" will be permanently deleted.`:`"${n}" will be archived.`})]}),s.jsxs(Ts,{children:[s.jsx(Ne,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),s.jsx(Ne,{variant:"destructive",size:"sm",onClick:r,children:e==="delete"?"Delete":"Archive"})]})]})}),qb=e=>{const t=e.trim();if(!t)return"";const n=t.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],o=n[1].slice(0,3),i=`${r} ${o}`.trim();return n.length>2||i.length<t.length?`${i}...`:i}return t.length>12?`${t.slice(0,9).trimEnd()}...`:t},vn=e=>{if(!e)return"";const t=e.replace(/\\/g,"/");return t==="/"?"/":t.replace(/\/+$/,"")},Yb=a.lazy(()=>ht(()=>import("./SessionSwitcherDropdown-CfySKnUu.js"),__vite__mapDeps([46,5,10,4,6,1,2,3,7,8,9,11,12])).then(e=>({default:e.SessionSwitcherDropdown}))),fy=({onToggleLeftDrawer:e,onToggleRightDrawer:t,leftDrawerOpen:n,rightDrawerOpen:r,tabletWorkspaceTab:o,onSelectTabletWorkspaceTab:i,tabletGitHubTabsAvailable:l=!1})=>{Kt("ui.header.render");const c=le(F=>F.setSessionSwitcherOpen),d=le(F=>F.toggleSidebar),u=le(F=>F.isSidebarOpen),f=le(F=>F.activeMainTab),p=le(F=>F.setActiveMainTab),x=le(F=>F.shortcutOverrides);le(F=>F.timeFormatPreference),Fs();const y=Te(F=>!!F.newSessionDraft?.open),m=Te(F=>F.currentSessionId),h=Ga(m??""),b=ju(m),g=a.useMemo(()=>{if(!b)return null;const F=b;return{title:b.title??null,directory:F.directory??null,created:b.time?.created??null,slug:F.slug??null,shareUrl:b.share?.url??null,parentId:b.parentID??null}},[b]),S=ut(ro(F=>{if(!F.activeProjectId)return null;const oe=F.projects.find(be=>be.id===F.activeProjectId);return oe?{id:oe.id,path:oe.path,label:oe.label}:null})),v=sn(F=>F.homeDirectory),E=a.useMemo(()=>{if(!S)return null;const F=S.label?.trim();if(F)return F;const oe=S.path.split(/[\\/]/).filter(Boolean);return oe[oe.length-1]??null},[S]),{isMobile:j}=an(),{enabled:k}=$o(),C=!!(k&&i&&o!==void 0),w=a.useMemo(()=>[...pb(l)],[l]),[N,T]=a.useState(!1),O=a.useRef(null),[$,U]=a.useState(()=>typeof window>"u"?!1:tn()),K=a.useMemo(()=>Za(),[]),L=Cu(),[D,R]=a.useState(!1),I=a.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),M=qa(),W=a.useMemo(()=>{if(typeof window>"u")return null;const F=window.__PICHAMBER_MACOS_MAJOR__;if(typeof F=="number"&&Number.isFinite(F)&&F>0)return F;if(typeof navigator>"u")return null;const oe=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!oe)return null;const be=Number.parseInt(oe[1],10),_e=Number.parseInt(oe[2],10);return Number.isNaN(be)?null:be===10?_e:be},[]);Ee.useEffect(()=>{typeof window>"u"||U(tn())},[]);const G=le(F=>F.isSessionSwitcherOpen),[B,xe]=a.useState(!1),[V,je]=a.useState("Local"),[Re,H]=a.useState(!0),[z,Y]=a.useState(()=>ar(null)),[X,te]=a.useState(!1),[ue,he]=a.useState(null),[Q,se]=a.useState(!1),[ce,Ce]=a.useState(null),ve=a.useRef(0),Ge=a.useMemo(()=>qb(V),[V]),q=a.useCallback(async()=>{if(typeof window>"u"||!$)return;const F=Qe(),oe=()=>Qe()===F;try{const be=await Tt("/api/version");if(!oe())return;const _e=be.ok?await be.json().catch(()=>null):null;if(!oe())return;if(Y(ar(_e)),cr()){je("Local"),H(!0);return}H(!1);const Je=await Xu();if(!oe())return;const Xe=Zu(),hs=ef([tf(Xe),...Je.hosts]);if(hs.id===sf){je("Local"),H(!0);return}je(nf(hs.label.trim()||"Instance"))}catch{oe()&&(je("Local"),H(!0),Y(ar(null)))}},[$]);Ee.useEffect(()=>(q(),On(()=>{ve.current+=1,he(null),Ce(null),se(!1),te(!1),q()})),[q]);const ae=a.useCallback(async()=>{const F=ve.current+1;ve.current=F;const oe=Qe(),be=()=>ve.current===F&&Qe()===oe;if(Re){he(null),Ce(null);return}se(!0),Ce(null);try{const _e=new URLSearchParams({appType:"web",instanceMode:"remote"}),Je=await Tt(`/api/pi/update-check?${_e.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!Je.ok)throw new Error(`Server responded with ${Je.status}`);const Xe=await Je.json();if(!be())return;he({available:Xe.available??!1,version:Xe.version,currentVersion:Xe.currentVersion??"unknown",body:Xe.body,nextSuggestedCheckInSec:typeof Xe.nextSuggestedCheckInSec=="number"?Xe.nextSuggestedCheckInSec:void 0,packageManager:Xe.packageManager,updateCommand:Xe.updateCommand,channel:Xe.channel==="rc"?"rc":"stable"})}catch(_e){if(!be())return;he(null),Ce(_e instanceof Error?_e.message:"Failed to check remote instance updates")}finally{be()&&se(!1)}},[Re]);a.useEffect(()=>fh(()=>{Re||ae()}),[ae,Re]),a.useEffect(()=>{ve.current+=1,he(null),Ce(null),se(!1),te(!1)},[Re,V]),a.useEffect(()=>{if(!$||Re)return;const F=3e3,oe=3600*1e3;let be=!1,_e=null;const Je=Xe=>{_e=window.setTimeout(()=>{if(be||typeof document<"u"&&document.visibilityState!=="visible"){Je(oe);return}ae().finally(()=>{be||Je(oe)})},Xe)};return Je(F),()=>{be=!0,_e!==null&&window.clearTimeout(_e)}},[ae,Re,V,$]);const ne=a.useCallback(()=>{if(ue?.available){te(!0);return}ae()},[ae,ue?.available]),me=m?g??null:null,fe=a.useRef(null),[Be,Se]=a.useState(0);a.useEffect(()=>{if(!m){fe.current&&(fe.current=null,Se(_e=>_e+1));return}if(me){fe.current={sessionId:m,session:me,expiresAt:Date.now()+2e3};return}const F=fe.current;if(!F||F.sessionId!==m)return;const oe=F.expiresAt-Date.now();if(oe<=0){fe.current=null,Se(_e=>_e+1);return}const be=window.setTimeout(()=>{fe.current?.sessionId===m&&(fe.current=null),Se(_e=>_e+1)},oe);return()=>{window.clearTimeout(be)}},[m,me]);const ee=(()=>{if(me)return me;if(!m)return null;const F=fe.current;return F&&F.sessionId===m&&F.expiresAt>Date.now()?F.session:null})(),we=a.useMemo(()=>{const F=typeof ee?.directory=="string"?ee.directory:"";return vn(F||"")},[ee?.directory]),pe=Te(F=>F.newSessionDraft?.open?vn(F.newSessionDraft.directoryOverride??""):""),ye=a.useMemo(()=>xb({sessionDirectory:we,draftDirectory:pe,isNewSessionDraftOpen:y}),[pe,y,we]),qe=Wa(ye||null),Pe=a.useMemo(()=>yb({activeProjectLabel:E,openDirectory:ye,homeDirectory:v}),[E,v,ye]),Ye=!!(Pe||qe),re=a.useMemo(()=>m?bs(ee):Pe??"PiChamber",[ee,m,Pe]),Le=ku(),nt=Te(F=>F.updateSessionTitle),at=Te(F=>F.archiveSessions),Ve=Te(F=>F.deleteSessions),[mt,lt]=a.useState(!1),[qt,Yt]=a.useState(!1),Ze=a.useRef(!1),[Ct,Vt]=a.useState(""),[kt,Ft]=a.useState(null),gt=a.useRef(null);a.useEffect(()=>{Ze.current=!1,Yt(!1),lt(!1),Vt(""),Ft(null)},[m]);const wt=a.useCallback(()=>{m&&(Vt(ee?.title?.trim()||re),lt(!0))},[ee?.title,m,re]),st=a.useCallback(async()=>{if(!m)return;const F=Ct.trim();F&&F!==ee?.title?.trim()&&await nt(m,F),lt(!1)},[ee?.title,m,Ct,nt]);a.useEffect(()=>{if(!mt)return;const F=oe=>{const be=oe.target;(!be||!gt.current?.contains(be))&&st()};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},[mt,st]);const At=a.useCallback(()=>{m&&ys(m).then(F=>{ie[F.ok?"success":"error"](F.ok?"Session ID copied":"Failed to copy session ID")}).catch(()=>ie.error("Failed to copy session ID"))},[m]),ke=a.useCallback(async()=>{if(!m||!ye){ie.error("Nothing to export");return}try{await Le.syncSession(m)}catch{ie.error("Failed to load the complete session history");return}const F=[];if(F.length===0){ie.error("Nothing to export");return}const oe=Zl(F,ee?.title??null),be=sc(ee?.title??null);await tc(oe,be)||ec(oe,be),ie.success("Session exported")},[ee?.title,m,ye,Le]);h?.type==="busy"||h?.type;const He=a.useCallback(async()=>{if(!m||!kt)return;const F=Au(),oe=[m];for(let Xe=0;Xe<oe.length;Xe+=1){const hs=oe[Xe];for(const Bt of F)Bt.parentID===hs&&!oe.includes(Bt.id)&&oe.push(Bt.id)}const be=kt;if(Ft(null),(be==="archive"?await at(oe):await Ve(oe)).failedIds.length>0){ie.error(be==="archive"?"Failed to archive session":"Failed to delete session");return}ie.success(be==="archive"?"Session archived":"Session deleted")},[at,m,Ve,kt]),Ae=le(F=>F.isArchivePageOpen),Oe=a.useMemo(()=>Ae?{title:"Archive",subtitle:null}:null,[Ae]),Fe=a.useMemo(()=>vn(ye||S?.path||""),[S?.path,ye]),rt=a.useCallback(()=>{Fe&&ys(Fe).then(F=>{ie[F.ok?"success":"error"](F.ok?"Working directory copied":"Failed to copy working directory")}).catch(()=>ie.error("Failed to copy working directory"))},[Fe]),vt=a.useMemo(()=>S?{id:S.id,path:S.path}:null,[S]),Nt=a.useRef(null);a.useEffect(()=>{!vt||!Fe||(Nt.current={projectRef:vt,directory:Fe})},[Fe,vt]);const bt=a.useMemo(()=>vt&&Fe?{projectRef:vt,directory:Fe}:Nt.current,[Fe,vt]),ct=a.useCallback(()=>{if(typeof document>"u")return;const F=document.activeElement;if(!F)return;const oe=F.tagName;(oe==="INPUT"||oe==="TEXTAREA"||oe==="SELECT"||F.isContentEditable)&&F.blur()},[]),tt=a.useCallback(()=>{if(j){ct(),c(!G);return}d()},[ct,j,G,c,d]),It=a.useCallback(()=>{In("desktop_open_draft_mini_chat_window",{directory:vn(ye||S?.path||""),projectId:S?.id??null,apiBaseUrl:ho(),clientToken:fo()}).catch(F=>{console.warn("[header] failed to open draft mini chat window",F)})},[S?.id,S?.path,ye]),Et=a.useCallback(()=>{if(y){It();return}m&&In("desktop_open_session_mini_chat_window",{sessionId:m,directory:vn(ye||S?.path||""),apiBaseUrl:ho(),clientToken:fo()}).catch(F=>{console.warn("[header] failed to open session mini chat window",F)})},[S?.path,m,It,y,ye]),os=ln,Qt=Uh,Jt=a.useMemo(()=>n?"sessions":C?r&&o?o:null:r?"git":f,[f,C,n,r,o]),xt=a.useCallback(()=>{n&&e&&e(),r&&t&&t(),!e&&G&&c(!1)},[G,n,e,t,r,c]),Os=a.useCallback(()=>{e?.()},[e]),un=a.useCallback(()=>{t?.()},[t]),Bs=a.useMemo(()=>$&&I&&!D?"5.5rem":L?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":!$||M?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[$,D,I,L,M]);Ee.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",Bs)},[Bs]);const _s=u?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",Lt=u?"0px":$&&M?"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)":k?"2.75rem":"2.5rem";Ee.useEffect(()=>{if(!$||!I){R(!1);return}let F=!1;const oe=async()=>{try{const _e=await In("desktop_is_window_fullscreen");F||R(_e===!0)}catch{F||R(!1)}},be=()=>{oe()};return oe(),window.addEventListener("pichamber:window-resized",be),()=>{F=!0,window.removeEventListener("pichamber:window-resized",be)}},[$,I]);const fs=a.useMemo(()=>!$||!I||W===null?"":W>=26?"h-12":W<=15?"h-14":"",[$,I,W]),St=a.useMemo(()=>{if(!($&&!M))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))"}},[$,M]),is=a.useCallback(()=>{if(typeof document>"u")return;const F=O.current?.getBoundingClientRect().height;if(F){const oe=`${F}px`,be=document.documentElement.style;be.getPropertyValue("--oc-header-height")!==oe&&be.setProperty("--oc-header-height",oe)}},[]);Ee.useEffect(()=>{if(typeof window>"u")return;is();const F=O.current;if(!F||typeof ResizeObserver>"u")return()=>{};let oe=0;const be=()=>{oe||(oe=requestAnimationFrame(()=>{oe=0,is()}))},_e=new ResizeObserver(be);return _e.observe(F),window.addEventListener("resize",be),window.addEventListener("orientationchange",be),()=>{oe&&cancelAnimationFrame(oe),_e.disconnect(),window.removeEventListener("resize",be),window.removeEventListener("orientationchange",be)}},[is]),Ee.useEffect(()=>{is()},[is,j,fs]);const as=a.useCallback(async F=>{const oe=F.target;oe.closest(".app-region-no-drag")||oe.closest("button, a, input, select, textarea")||F.button===0&&$&&await Nu()},[$]),ot=a.useMemo(()=>j?[{id:"chat",label:"Chat",icon:"chat-4"},{id:"diff",label:"Diff",icon:"diff"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal-box"},{id:"context",label:"Context",icon:"file-list-2"},{id:"diagram",label:"Diagram",icon:"file"}]:[],[j]),Ot=a.useCallback(F=>Ko(lr(F,x)),[x]);Ee.useEffect(()=>{!j&&f!=="chat"&&f!=="terminal"&&f!=="diagram"&&p("chat")},[f,j,p]),Ee.useEffect(()=>{const F=oe=>{if(rf(oe)&&!oe.shiftKey&&!oe.altKey){const be=parseInt(oe.key,10);be>=1&&be<=ot.length&&(oe.preventDefault(),j&&(ct(),xt()),p(ot[be-1].id))}};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[ct,xt,j,p,ot]),Ee.useEffect(()=>{const F=oe=>{const be=lr("toggle_services_menu",x);if(of(oe,be)){oe.preventDefault(),B?xe(!1):(xe(!0),q());return}};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[x,B,q]);const js=F=>{const oe=f===F.id,be=F.icon==="diff",_e=be?null:F.icon,Je=F.id==="chat",Xe=Bt=>be?s.jsx(ga,{size:Bt}):_e?s.jsx(P,{name:_e,className:`h-${Bt/4} w-${Bt/4}`}):null,hs=s.jsxs("button",{type:"button",onClick:()=>p(F.id),className:_("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",oe?"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",Je&&!j&&"min-w-[100px] justify-center"),"aria-label":F.label,"aria-selected":oe,role:"tab",children:[j?Xe(20):s.jsxs(s.Fragment,{children:[Xe(16),s.jsx("span",{className:"header-tab-label",children:F.label})]}),F.badge!==void 0&&F.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:F.badge})]});return s.jsx(a.Fragment,{children:hs},F.id)},Rt=s.jsxs(s.Fragment,{children:[s.jsx(jb,{directory:Fe,className:"mr-1"}),$?s.jsx(Gb,{isDesktopApp:$,currentInstanceLabel:V,compactCurrentInstanceLabel:Ge,currentInstanceIsLocal:Re,currentInstanceIcon:z,isDesktopServicesOpen:B,setIsDesktopServicesOpen:xe,refreshCurrentInstanceLabel:q,shortcutLabel:Ot,remoteUpdateInfo:ue,remoteUpdateChecking:Q,remoteUpdateError:ce,onOpenRemoteUpdate:ne}):s.jsx(Kb,{open:B,onOpenChange:xe}),s.jsx(Wb,{isMobile:j})]}),fn=K&&(y||!!m),zs=()=>s.jsxs("div",{onMouseDown:as,className:_("app-region-drag relative flex h-12 select-none items-center pr-3",fs),style:St,role:"tablist","aria-label":"Main navigation",children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:_s}}),s.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:Lt}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[Oe?s.jsxs("div",{className:"mr-3 flex min-w-0 items-center gap-1.5 px-1 py-0.5 -my-0.5 text-left",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:Oe.title}),Oe.subtitle?s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":"true",className:"h-3 w-px shrink-0 bg-border"}),s.jsx("span",{className:"truncate typography-ui-label font-normal leading-tight text-muted-foreground/75 max-w-full",children:Oe.subtitle})]}):null]}):s.jsxs("div",{className:"app-region-no-drag mr-3 flex min-w-0 max-w-full items-center gap-0.5 py-0.5 -my-0.5 text-left",children:[u?null:s.jsx(a.Suspense,{fallback:s.jsx("button",{type:"button",className:os,"aria-label":"Open session switcher",children:s.jsx(P,{name:"history",className:"h-[18px] w-[18px]"})}),children:s.jsx(Yb,{align:"start",children:s.jsx("button",{type:"button",className:os,"aria-label":"Open session switcher",children:s.jsx(P,{name:"history",className:"h-[18px] w-[18px]"})})})}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 px-1",children:[mt?s.jsxs("form",{ref:gt,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onSubmit:F=>{F.preventDefault(),st()},children:[s.jsx("input",{value:Ct,onChange:F=>Vt(F.target.value),autoFocus:!0,onKeyDown:F=>{F.stopPropagation(),F.key==="Escape"&<(!1)},placeholder:"Rename",className:"min-w-0 flex-1 bg-transparent typography-ui-label font-normal leading-tight outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"submit","aria-label":"Save session name",title:"Save session name",className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>lt(!1),"aria-label":"Cancel renaming session",title:"Cancel renaming session",className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"size-4"})})]}):s.jsx("span",{className:"min-w-0 truncate typography-ui-label font-normal leading-tight text-foreground",children:y?"New session":re}),Ye?s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":"true",className:"h-3 w-px shrink-0 bg-border"}),s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate typography-ui-label font-normal leading-tight text-muted-foreground/75",children:[Pe?s.jsx("span",{className:"truncate",children:Pe}):null,qe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:qe})]}):null]})]}):null]}),s.jsx("div",{className:"flex h-[18px] shrink-0 items-center justify-center self-center",children:m&&!y&&!mt?s.jsxs(Wt,{open:qt,onOpenChange:Yt,onOpenChangeComplete:F=>{!F&&Ze.current&&(Ze.current=!1,wt())},children:[s.jsx(Gt,{asChild:!0,children:s.jsx(Ne,{variant:"ghost",size:"xs",className:"h-[18px] w-6 px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-label":"Open session actions",children:s.jsx(P,{name:"more",className:"size-4"})})}),s.jsxs(Ht,{align:"end",className:"min-w-[190px]",children:[s.jsxs(ft,{onClick:()=>{Ze.current=!0},children:[s.jsx(P,{name:"pencil-ai",className:"mr-2 size-4"}),"Rename"]}),s.jsxs(ft,{onClick:At,children:[s.jsx(P,{name:"file-copy",className:"mr-2 size-4"}),"Copy session ID"]}),s.jsxs(ft,{onClick:rt,disabled:!Fe,children:[s.jsx(P,{name:"folder",className:"mr-2 size-4"}),"Copy working directory"]}),s.jsx(en,{}),s.jsxs(ft,{onClick:()=>{ke()},children:[s.jsx(P,{name:"download",className:"mr-2 size-4"}),"Export Markdown"]}),s.jsx(en,{}),s.jsxs(ft,{onClick:()=>Ft("archive"),children:[s.jsx(P,{name:"inbox-archive",className:"mr-2 size-4"}),"Archive"]}),s.jsxs(ft,{className:"text-destructive focus:text-destructive",onClick:()=>Ft("delete"),children:[s.jsx(P,{name:"delete-bin",className:"mr-2 size-4"}),"Delete"]})]})]}):null})]}),ot.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:ot.map(F=>js(F))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(Al,{}),bt?s.jsx(ya,{projectRef:bt.projectRef,directory:bt.directory,className:"mr-1"}):null,s.jsx($h,{visible:fn,title:y?"New Mini Chat Window":"Open Session in Mini Chat",ariaLabel:y?"Open a new Mini Chat window":"Open current session in Mini Chat",onClick:Et,className:_(os,"mr-1"),Icon:"picture-in-picture-2"}),Rt,s.jsx(Iu,{visible:M})]})]})]}),hn=()=>s.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[k&&s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:_s}}),s.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:Lt}})]}),!k&&s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e?s.jsx("button",{type:"button",onClick:Os,className:_(Qt,Jt==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":n?"Close sessions":"Open sessions",children:s.jsx(P,{name:"layout-left",className:"h-5 w-5"})}):G?s.jsx("button",{type:"button",onClick:()=>c(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":"Back",children:s.jsx(P,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:tt,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":"Open sessions",children:s.jsx(P,{name:"play-list-add",className:"h-5 w-5"})}),!e&&G&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:"Sessions"})]}),(!G||!!e)&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:!C&&s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain","data-no-drawer-swipe":"true",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":"Main navigation",children:ot.map(F=>{const oe=f===F.id,be=F.icon==="diff",_e=be?null:F.icon;return s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{j&&(ct(),xt()),p(F.id)},"aria-label":F.label,"aria-selected":oe,role:"tab",className:_(Qt,"relative rounded-lg",Jt===F.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[be?s.jsx(ga,{className:"h-5 w-5"}):_e?s.jsx(P,{name:_e,className:"h-5 w-5"}):null,F.badge!==void 0&&F.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:F.badge}),F.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":"Changes available"})]})}),s.jsx(Ke,{children:s.jsx("p",{children:F.label})})]},F.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[C&&s.jsxs(s.Fragment,{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":"Workspace",children:w.map(F=>{const oe=r&&o===F.id;return s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>{j&&(ct(),xt()),T(!1),i?.(F.id)},"aria-label":F.label,"aria-selected":oe,role:"tab",className:_(Qt,"relative h-11 w-11 rounded-lg",oe&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(P,{name:F.icon,className:"h-5 w-5"})})}),s.jsx(Ke,{children:s.jsx("p",{children:F.label})})]},F.id)})}),s.jsx(zh,{open:N,onOpenChange:T,currentSessionId:m,effectiveDirectory:ye||null,isNewSessionDraftOpen:y})]}),bt&&s.jsx(ya,{projectRef:bt.projectRef,directory:bt.directory,compact:!0,allowMobile:!0,className:"h-9"}),t&&!C?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:un,className:_(Qt,"relative",Jt==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(P,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(Ke,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),de=_("header-safe-area relative z-10 bg-background",j&&"border-b border-border/50");return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:O,className:de,style:{"--padding-scale":"1"},children:j?hn():zs()}),s.jsx(Hb,{action:kt,onClose:()=>Ft(null),sessionTitle:re,onConfirm:()=>{He()}}),s.jsx(bl,{open:X,onOpenChange:te,info:ue,downloading:!1,downloaded:!1,progress:null,error:ce,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})},wa="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",Vb="app-region-no-drag flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50",hy=()=>{const e=le(y=>y.isSidebarOpen),t=le(y=>y.toggleSidebar),n=le(y=>y.shortcutOverrides),r=a.useRef(null),o=a.useRef(null),i=Ko(lr("toggle_sidebar",n)),l=qa(),{enabled:c}=$o(),d=!e,u=l,f=d||u,p=u,x=a.useCallback(()=>{In("desktop_show_app_menu").catch(y=>{console.warn("[titlebar] failed to open app menu",y)})},[]);return a.useEffect(()=>{if(typeof document>"u")return;const y=v=>{document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(v)}px`)},m=v=>{document.documentElement.style.setProperty("--oc-titlebar-overlay-width",`${Math.round(v)}px`)};if(!p)return;const h=o.current,b=r.current;if(!h||!b){y(0),m(0);return}const g=()=>{const v=Math.max(h.getBoundingClientRect().width,h.scrollWidth);y(v),m(b.getBoundingClientRect().width)};if(g(),typeof ResizeObserver>"u")return;const S=new ResizeObserver(g);return S.observe(h),S.observe(b),()=>{S.disconnect()}},[p]),f?s.jsx("div",{ref:r,className:"app-region-no-drag absolute left-0 z-40 flex select-none items-center pr-2",style:{top:"var(--oc-safe-area-top, 0px)",height:"calc(var(--oc-header-height, 3rem) - var(--oc-safe-area-top, 0px))",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},children:s.jsxs("div",{ref:o,className:"flex items-center gap-2",children:[u?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:x,"aria-label":"Open PiChamber menu",className:_(wa,"shrink-0"),children:s.jsx(P,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(Ke,{children:s.jsx("p",{children:"PiChamber menu"})})]}):null,d?s.jsxs(Ue,{children:[s.jsx($e,{asChild:!0,children:s.jsx("button",{type:"button",onClick:t,"aria-label":"Open sessions",className:_(c?Vb:wa,"shrink-0"),children:s.jsx(P,{name:"layout-left",className:c?"size-[18px]":"h-[18px] w-[18px]"})})}),s.jsx(Ke,{children:s.jsx("p",{children:`Open sessions (${i})`})})]}):null]})}):null},va=200,Qb="cubic-bezier(0.22, 1, 0.36, 1)",my=e=>{const t=a.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[n,r]=a.useState(e),[o,i]=a.useState(e);return a.useLayoutEffect(()=>{if(t){i(e),r(e);return}if(e){i(!0),r(!1);let c=0;const d=window.requestAnimationFrame(()=>{c=window.requestAnimationFrame(()=>r(!0))});return()=>{window.cancelAnimationFrame(d),window.cancelAnimationFrame(c)}}r(!1);const l=window.setTimeout(()=>i(!1),va);return()=>window.clearTimeout(l)},[e,t]),{slidIn:n,layoutVisible:o,prefersReducedMotion:t,transition:t?"none":`transform ${va}ms ${Qb}`}},py=()=>{tl()},gy=e=>{Te.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),le.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),ge.getState().clearAll(),tl(),sn.getState().resetForRuntimeSwitch(),Eu.getState().resetForRuntimeSwitch(),Ru.getState().resetForRuntimeSwitch(),Du(),af(),lf(),Lu(),Pu.getState().resetForRuntimeSwitch(),$t.setState({providers:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),ut.getState().resetForRuntimeSwitch(),Mu(),Tu(),Cf.getState().reset(),cf.getState().resetForRuntimeSwitch(),Ba.getState().resetForRuntimeSwitch(e.runtimeKey),lo.getState().resetForRuntimeSwitch(e.runtimeKey),df(),Ps.getState().resetForRuntimeSwitch(e.runtimeKey),Fu.getState().resetForRuntimeSwitch(),ss.getState().resetForRuntimeSwitch(),pt.getState().resetForRuntimeSwitch(e.runtimeKey),uf.getState().resetForRuntimeSwitch(e.runtimeKey),Te.getState().restoreForRuntimeSwitch(e.runtimeKey),le.getState().restoreForRuntimeSwitch(e.runtimeKey);const t=le.getState();bo({sessionId:Te.getState().currentSessionId,tab:t.activeMainTab,isSettingsOpen:t.isSettingsDialogOpen,settingsPath:t.settingsPage,diffFile:t.pendingDiffFile},{replace:!0,force:!0})};export{Gx as $,_x as A,Ar as B,Bx as C,la as D,Rs as E,bx as F,ql as G,fy as H,Th as I,Fh as J,Oi as K,uy as L,kl as M,$f as N,mx as O,Cs as P,xs as Q,ss as R,ny as S,ay as T,Hl as U,Fl as V,hx as W,Ln as X,Tl as Y,xx as Z,vl as _,zh as a,dx as a$,zx as a0,Hx as a1,ty as a2,sy as a3,Mh as a4,Vx as a5,qx as a6,$x as a7,Yx as a8,Jx as a9,xl as aA,dh as aB,Bn as aC,_n as aD,vx as aE,uh as aF,yl as aG,Ix as aH,En as aI,yx as aJ,oh as aK,ih as aL,Ex as aM,Fx as aN,Mx as aO,Tx as aP,Lx as aQ,Dx as aR,Sx as aS,jx as aT,Cx as aU,Px as aV,Ch as aW,Ax as aX,Wf as aY,ah as aZ,Gf as a_,Xx as aa,Zx as ab,ey as ac,Qx as ad,Io as ae,Vi as af,ks as ag,wn as ah,dn as ai,Vm as aj,cn as ak,Kx as al,Sr as am,Wx as an,Ux as ao,ch as ap,Rx as aq,rh as ar,wx as as,Ox as at,Nx as au,bl as av,Ho as aw,kx as ax,lh as ay,Eh as az,jn as b,jg as c,ry as d,or as e,pb as f,oy as g,Yg as h,Ag as i,ly as j,ac as k,my as l,dy as m,hy as n,py as o,gy as p,px as q,cy as r,iy as s,gx as t,Bh as u,fx as v,cx as w,ux as x,Cr as y,kr as z};
|