@vantran-se/openchamber-web 1.22.1 → 1.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/bin/cli.js +4 -1
- package/bin/cli.test.js +92 -0
- package/bin/lib/cli-startup.js +49 -0
- package/bin/lib/commands-startup.js +41 -6
- package/dist/assets/{CodeMirrorCommentWidgets-C53Q7pbX.js → CodeMirrorCommentWidgets-CV1HNV5l.js} +1 -1
- package/dist/assets/{DiffView-Dh1ey2x9.js → DiffView-DkkSa30n.js} +3 -3
- package/dist/assets/DirtyBranchSwitchDialog-DW4WaXPc.js +1 -0
- package/dist/assets/FilesView-DDu8zDy5.js +17 -0
- package/dist/assets/GitView-1Ixo8z-M.js +6 -0
- package/dist/assets/{JsonTreeView-Bl0lp9Rs.js → JsonTreeView-DvCLL7dT.js} +1 -1
- package/dist/assets/LinearIssuesView-Bs1rZrF2.js +1 -0
- package/dist/assets/{MarkdownImageGallery-bA0PS-tn.js → MarkdownImageGallery-DyJUc6h9.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-Bdm8vMkS.js +12 -0
- package/dist/assets/{OnboardingScreen-D3kYJIb6.js → OnboardingScreen-Dg66B6oB.js} +1 -1
- package/dist/assets/{PatchDiff-D6NXAfJk.js → PatchDiff-CAduNjfZ.js} +1 -1
- package/dist/assets/{PierreDiffViewer-Ct2A13NO.js → PierreDiffViewer-CTIb1GYD.js} +2 -2
- package/dist/assets/PlanView-trDaszfq.js +5 -0
- package/dist/assets/SettingsView-DStMfBmy.js +28 -0
- package/dist/assets/{SettingsWindow-BiWDBRvb.js → SettingsWindow-DQQFnrSZ.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BQexMQIm.js → ToolOutputDialog-SjY2XZlA.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-DJdzUQPE.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-Dpz2ra8h.js → VirtualizedFileDiff-Iehm4iMH.js} +1 -1
- package/dist/assets/{WalkthroughView-AX-u2pFg.js → WalkthroughView-BALp2d9O.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-DtyozJdt.js → computeVirtualFileMetrics-BKZA43vN.js} +2 -2
- package/dist/assets/{contextPanelEmbeddedChat-C9EcRSDF.js → contextPanelEmbeddedChat-D2PM_pEv.js} +1 -1
- package/dist/assets/{de-DqVn5vme.js → de-DlSNLAcy.js} +6 -5
- package/dist/assets/{es-hj43Z53i.js → es-D1GbowZ3.js} +6 -5
- package/dist/assets/{fr-BmkZt2mF.js → fr-BPOLXIAY.js} +6 -5
- package/dist/assets/{index-DmhujXbT.js → index-Ce0LR32V.js} +1 -1
- package/dist/assets/index-D42fPvt4.css +1 -0
- package/dist/assets/index-DlFbCkEy.js +39 -0
- package/dist/assets/{isDiffPlainText-XyulMHxx.js → isDiffPlainText-DaB2u_Kv.js} +1 -1
- package/dist/assets/{isFilePlainText-B19Ddps1.js → isFilePlainText-yJZa2IAC.js} +1 -1
- package/dist/assets/{ja-DioMIEGF.js → ja-Dm2-m9io.js} +7 -6
- package/dist/assets/{ko-BqPgaQJb.js → ko-CIXlzQ5-.js} +7 -6
- package/dist/assets/main-B7qTsd_w.js +930 -0
- package/dist/assets/{main-B2a_JfKZ.js → main-CyQrD9dG.js} +2 -2
- package/dist/assets/{markdownCore-CWRCqSH2.js → markdownCore-CeEwGgEK.js} +2 -2
- package/dist/assets/{miniChat-B3CSU_Ps.js → miniChat-7cPEx4sV.js} +2 -2
- package/dist/assets/{mobile-QNcFIVCW.js → mobile-QtzkPTM8.js} +2 -2
- package/dist/assets/{patchFileDiff-BpMQZnYu.js → patchFileDiff-No55fDiD.js} +1 -1
- package/dist/assets/pl-B2zmkOpw.js +16 -0
- package/dist/assets/{pt-BR-BqH8fuCH.js → pt-BR-C-JE5H6y.js} +6 -5
- package/dist/assets/{renderElectronMiniChatApp-D77bmLqo.js → renderElectronMiniChatApp-ePTkBJNS.js} +2 -2
- package/dist/assets/renderMobileApp-D9RjB9DX.js +25 -0
- package/dist/assets/runtimeEndpointReset-DfJIWwwo.js +17 -0
- package/dist/assets/{scheduledTasksApi-BSRCtP6T.js → scheduledTasksApi-DuhdyYEa.js} +1 -1
- package/dist/assets/{shikiHighlight-DE-OwqGw.js → shikiHighlight-EHEg58-n.js} +1 -1
- package/dist/assets/tr-MJmRIzEY.js +7 -0
- package/dist/assets/{uk-BkkfxbOs.js → uk-BmD7eM8k.js} +6 -5
- package/dist/assets/{useAppFontEffects-COAeIX-D.js → useAppFontEffects-CuJPKtI1.js} +151 -180
- package/dist/assets/useInlineCommentController-DD7_7OP_.js +2 -0
- package/dist/assets/{useRootScrollLock-C0N9mCwz.js → useRootScrollLock-DRGAe8PN.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-BG3v1Ghq.js → vendor-codemirror-language-data-9ZzoH0o0.js} +2 -2
- package/dist/assets/vendor-zod-CK21ihK-.js +39 -0
- package/dist/assets/{web-components-BNMwa0qm.js → web-components-PttKBrhi.js} +1 -1
- package/dist/assets/{zh-CN-C6FMdVgv.js → zh-CN-JJHl4ehT.js} +6 -5
- package/dist/assets/{zh-TW-CdcMjDxv.js → zh-TW-DPc4DEEW.js} +6 -5
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +8 -4
- package/server/index.js +38 -5
- package/server/lib/agent-tool/runtime.js +2 -19
- package/server/lib/changelog/update-notes.js +82 -0
- package/server/lib/changelog/update-notes.test.js +59 -0
- package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
- package/server/lib/dev-tunnel/runtime.js +4 -4
- package/server/lib/dev-tunnel/tunnel.test.js +20 -0
- package/server/lib/fs/DOCUMENTATION.md +2 -0
- package/server/lib/fs/routes.js +32 -21
- package/server/lib/fs/routes.test.js +77 -0
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/routes.js +16 -0
- package/server/lib/git/service.js +107 -17
- package/server/lib/git/service.test.js +171 -0
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
- package/server/lib/mcp-reconnect/runtime.js +122 -0
- package/server/lib/mcp-reconnect/runtime.test.js +140 -0
- package/server/lib/message-queue/DOCUMENTATION.md +158 -0
- package/server/lib/message-queue/runtime.js +870 -0
- package/server/lib/message-queue/runtime.test.js +482 -0
- package/server/lib/openchamber-sessions/routes.js +102 -0
- package/server/lib/openchamber-sessions/routes.test.js +88 -0
- package/server/lib/opencode/DOCUMENTATION.md +13 -5
- package/server/lib/opencode/config-paths.test.js +116 -0
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/input-history-scope.js +14 -0
- package/server/lib/opencode/managed-plugin-config.js +35 -0
- package/server/lib/opencode/openchamber-routes.test.js +2 -2
- package/server/lib/opencode/plugins.js +2 -2
- package/server/lib/opencode/providers.js +44 -2
- package/server/lib/opencode/providers.test.js +131 -4
- package/server/lib/opencode/routes.js +4 -4
- package/server/lib/opencode/server-startup-runtime.js +1 -1
- package/server/lib/opencode/settings-helpers.js +28 -0
- package/server/lib/opencode/settings-helpers.test.js +177 -0
- package/server/lib/opencode/settings-runtime.js +2 -2
- package/server/lib/opencode/settings-runtime.test.js +29 -0
- package/server/lib/opencode/shared.js +4 -1
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/skill-routes.js +2 -1
- package/server/lib/opencode/snippets.js +1 -2
- package/server/lib/package-manager.js +4 -29
- package/server/lib/package-manager.test.js +2 -2
- package/server/lib/quota/DOCUMENTATION.md +2 -1
- package/server/lib/quota/credentials/providers.js +4 -0
- package/server/lib/quota/credentials/store.js +1 -1
- package/server/lib/quota/credentials/store.test.js +4 -4
- package/server/lib/quota/providers/exe-dev.js +75 -0
- package/server/lib/quota/providers/exe-dev.test.js +47 -0
- package/server/lib/quota/providers/index.js +7 -0
- package/server/lib/quota/providers/opencode-go.js +1 -0
- package/server/lib/quota/providers/opencode-go.test.js +5 -1
- package/server/lib/quota/routes.js +2 -0
- package/server/lib/quota/utils/auth.js +1 -1
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/host-client.test.js +9 -1
- package/server/lib/relay/tunnel-host.js +3 -1
- package/server/lib/relay/tunnel-host.test.js +9 -1
- package/server/lib/security/request-security.js +21 -6
- package/server/lib/security/request-security.test.js +42 -8
- package/server/lib/session-assist/runtime.js +1 -0
- package/server/lib/session-goal/DOCUMENTATION.md +20 -7
- package/server/lib/session-goal/create.js +3 -1
- package/server/lib/session-goal/runtime.js +77 -11
- package/server/lib/session-goal/runtime.test.js +426 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
- package/server/lib/skills-catalog/install.js +3 -2
- package/server/lib/small-model/DOCUMENTATION.md +4 -0
- package/server/lib/small-model/call.js +8 -2
- package/server/lib/small-model/call.test.js +23 -0
- package/server/lib/small-model/index.js +2 -1
- package/server/lib/small-model/routes.js +2 -1
- package/server/lib/system-prompt/runtime.js +2 -21
- package/server/lib/terminal/DOCUMENTATION.md +11 -7
- package/server/lib/terminal/runtime.js +180 -26
- package/server/lib/terminal/runtime.test.js +553 -26
- package/server/lib/terminal/shells.js +17 -0
- package/server/lib/terminal/shells.test.js +32 -1
- package/server/lib/ui-auth/ui-auth.js +4 -1
- package/server/lib/ui-auth/ui-auth.test.js +16 -0
- package/server/lib/walkthrough/index.js +1 -0
- package/server/lib/walkthrough/routes.test.js +26 -5
- package/dist/assets/CommitSection-X-f2RgYr.js +0 -1
- package/dist/assets/FilesView-3ZYP72ki.js +0 -17
- package/dist/assets/GitView-CMuN7z2Z.js +0 -6
- package/dist/assets/LinearIssuesView-CQiUDU8b.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BGQi2PLq.js +0 -12
- package/dist/assets/PlanView-6AUjzNQn.js +0 -5
- package/dist/assets/SettingsView-CHI8fFaK.js +0 -28
- package/dist/assets/ToolPartDiffPreview-DPAATNn6.js +0 -8
- package/dist/assets/index-L_ncV-6H.css +0 -1
- package/dist/assets/index-qES19dlJ.js +0 -7
- package/dist/assets/main-CYgSu6dx.js +0 -928
- package/dist/assets/pl-slULBF4R.js +0 -15
- package/dist/assets/renderMobileApp-BQ3Kdm-d.js +0 -25
- package/dist/assets/runtimeEndpointReset-CRGn1gVj.js +0 -16
- package/dist/assets/tr-CjEbw1Aw.js +0 -6
- package/dist/assets/useInlineCommentController-JsBboQwt.js +0 -2
- package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
|
@@ -0,0 +1,930 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/WalkthroughView-BALp2d9O.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/useAppFontEffects-CuJPKtI1.js","assets/index-DlFbCkEy.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-zustand-BAGL70zf.js","assets/vendor-zod-CK21ihK-.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/index-D42fPvt4.css","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-BeMD8X_w.js","assets/vendor-floating-ui-utils-D6FqdtJt.js","assets/vendor-floating-ui-react-dom-DxYCWdHj.js","assets/vendor-floating-ui-dom-BTvzWks8.js","assets/vendor-floating-ui-core-PuGzNPnN.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-D2PM_pEv.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-dnd-kit-core-BZknOX2w.js","assets/vendor-dnd-kit-utilities-B_MdXhJC.js","assets/vendor-dnd-kit-accessibility-BHxJPORy.js","assets/vendor-dnd-kit-sortable-CsEagZ81.js","assets/vendor-framer-motion-livSKyyV.js","assets/vendor-motion-dom-D_o3BTI3.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-cmdk-DgLInKvT.js","assets/vendor-radix-ui-react-dialog-B94Bt2qq.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-DcAh5WdT.js","assets/vendor-radix-ui-react-context-Czxm7Z62.js","assets/vendor-radix-ui-react-id-f5BLKEVw.js","assets/vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js","assets/vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js","assets/vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js","assets/vendor-radix-ui-react-primitive-DhVoX9SD.js","assets/vendor-radix-ui-react-slot-BQgQOasS.js","assets/vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js","assets/vendor-radix-ui-react-use-escape-keydown-oph88g-F.js","assets/vendor-radix-ui-react-focus-scope-CiaxW4dD.js","assets/vendor-radix-ui-react-portal-BMJYHWck.js","assets/vendor-radix-ui-react-presence-CNxf-uq4.js","assets/vendor-radix-ui-react-focus-guards-B6qJXYua.js","assets/vendor-react-remove-scroll-DO7dCTnK.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-BcFYyj3E.js","assets/vendor-react-style-singleton-q6EMHnwf.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-zDC0RhA3.js","assets/vendor-use-callback-ref-D3RC8gqK.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BgPj_McA.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-C9awkmn-.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-CiLROUVV.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-DzPz9Wgq.js","assets/vendor-codemirror-lang-json-CMBS2tG9.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-O0cZX78y.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CfgK872x.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-BPGOH9ye.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-9ZzoH0o0.js","assets/vendor-codemirror-lang-python-HahnQaAS.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-B7H_j0iU.js","assets/vendor-legendapp-list-gg7YLRW7.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/PierreDiffViewer-CTIb1GYD.js","assets/web-components-PttKBrhi.js","assets/computeVirtualFileMetrics-BKZA43vN.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-BmJyTmjJ.js","assets/vendor-pierre-theming-C6Z4M5_u.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-Iehm4iMH.js","assets/isDiffPlainText-DaB2u_Kv.js","assets/vendor-diff-C3JhlQdm.js","assets/Virtualizer-D_a8gKmg.js","assets/useInlineCommentController-DD7_7OP_.js","assets/runtimeEndpointReset-DfJIWwwo.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/patchFileDiff-No55fDiD.js","assets/useRootScrollLock-DRGAe8PN.js","assets/scheduledTasksApi-DuhdyYEa.js","assets/vendor-cron-parser-CUcP7OfX.js","assets/vendor-luxon-BZ0puJYg.js","assets/DiffView-DkkSa30n.js","assets/FilesView-DDu8zDy5.js","assets/shikiHighlight-EHEg58-n.js","assets/vendor-codemirror-search-BmS-GmcX.js","assets/vendor-replit-codemirror-vim-B2DJlAhT.js","assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js","assets/JsonTreeView-DvCLL7dT.js","assets/Virtualizer-CZlLSacm.js","assets/isFilePlainText-yJZa2IAC.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/CodeMirrorCommentWidgets-CV1HNV5l.js","assets/GitView-1Ixo8z-M.js","assets/DirtyBranchSwitchDialog-DW4WaXPc.js","assets/LinearIssuesView-Bs1rZrF2.js","assets/PlanView-trDaszfq.js","assets/SettingsWindow-DQQFnrSZ.js","assets/SettingsView-DStMfBmy.js","assets/vendor-yaml-3778uTud.js","assets/vendor-qrcode-DTJ12-WC.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/OnboardingScreen-Dg66B6oB.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{f as nt,R as c,j as s,r as xt,h as qm}from"./vendor-react-BUCujlKS.js";import{z as xn,A as Go,O as Za,D as Qm,B as Ym,C as fd,r as ds,o as qo,u as Pe,E as Et,F as Xm,G as Pn,H as Jm,I as wt,J as Gs,K as Qo,L as hd,N as Zm,P as ef,Q as tf,R as sf,S as pd,v as Yo,m as es,T as Mn,U as Wr,e as An,V as nf,a as ps,W as rf,X as of,Y as af,Z as gd,n as mn,w as qs,_ as lf,$ as wa,a0 as cf,a1 as el,a2 as df,a3 as uf,a4 as xd,f as mf,a5 as ff,a6 as or,a7 as Sa,d as Eo,a8 as Rr,a9 as ls,aa as bd,ab as hf,ac as Di,ad as pf,ae as gf,i as xf,af as xo,ag as bo,ah as bf,ai as tl,aj as yf,ak as wf,al as Sf,am as vf,an as sl,ao as nl,ap as rl,aq as ol,ar as jf,t as il,as as kf,at as Cf,au as Nf,x as Af,y as Df}from"./index-DlFbCkEy.js";import{_ as _n}from"./vendor-vite-runtime-DD1OZmLC.js";import{f as Nt,h as Ie,b2 as zt,I as R,g as pn,t as Re,b3 as Qs,b4 as Os,b5 as Ys,b6 as Xs,N as er,W as wn,ac as Sr,b7 as Ln,o as Xo,b8 as al,a7 as Dt,a8 as Pt,a9 as It,b as Vt,y as et,G as Pf,b9 as yd,ba as so,u as Ps,A as va,C as wd,bb as Pi,bc as If,bd as Sd,be as vd,r as $s,bf as jd,bg as ja,bh as Jo,bi as kd,bj as Cd,bk as Tf,bl as ll,bm as Ef,bn as Rf,bo as ka,bp as Ii,bq as Mf,br as Of,L as Nd,bs as Bf,l as Ht,bt as Ff,n as ar,bu as Ad,p as _f,bv as Dd,bw as Lf,bx as $f,by as Wf,bz as Pd,bA as Id,bB as zf,ax as Ca,bC as Qn,bD as Jr,bE as Vf,bF as ws,bG as Ss,bH as Ws,bI as Is,bJ as Ts,bK as bn,B as bt,aq as Hs,bL as Uf,bM as Kf,av as Dn,bN as yo,bO as Ks,bP as Zo,bQ as Td,bR as Ti,bS as Hf,bT as Bs,bU as Fs,bV as Cs,bW as _s,bX as ts,T as Cn,bY as lr,bZ as cl,b_ as ur,M as ei,ad as Gf,ae as Na,af as Ed,ag as Rd,ai as Bn,b$ as ti,c0 as Nn,a2 as Aa,c1 as qf,c2 as Qf,ap as Yf,c3 as Xf,c4 as Jf,c5 as Zf,ar as Da,c6 as Pa,c7 as mr,c8 as Md,c9 as eh,ca as th,cb as Zr,cc as sh,cd as nh,ce as ir,O as Od,cf as rh,cg as oh,ch as $n,ci as ih,cj as ah,ck as li,cl as Bd,cm as Fd,cn as lh,aw as Ei,co as Ri,cp as ch,cq as dl,cr as Mr,c as zr,d as Ia,_ as dh,cs as _d,ct as Cr,cu as Or,cv as uh,cw as mh,cx as fh,X as Ld,as as hh,cy as ph,cz as gh,cA as xh,cB as bh,cC as $d,cD as gn,cE as yh,cF as Wd,cG as wh,cH as Mi,cI as Sh,cJ as vh,cK as zd,cL as jh,cM as Vd,a0 as Ro,cN as Oi,R as Ta,Q as Ea,S as Ra,cO as Ma,a as Oa,$ as kh,cP as ul,cQ as Bi,cR as Ud,cS as Ch,cT as Kd,cU as Nh,P as Fi,H as Ah,cV as ml,cW as Dh,cX as fl,cY as Ph,cZ as cs,c_ as Ih,c$ as Fn,d0 as Ba,d1 as Hd,d2 as Th,d3 as Gd,d4 as qd,d5 as Eh,D as Rh,d6 as Mh,d7 as Oh,d8 as Bh,d9 as hl,da as Fh,db as _h,dc as Qd,E as Lh,dd as wo,de as Yd,df as $h,dg as Wh,dh as zh,di as Vh,e as Xd,dj as Fa,dk as Uh,dl as Vr,dm as Kh,dn as pl,dp as Hh,dq as Gh,Z as qh,dr as Qh,ds as Yh,aJ as _i,a3 as gl,aN as xl,a4 as bl,dt as Xh,J as Jh,K as ci,du as Zh,dv as ep,dw as Jd,dx as Zd,dy as eu,dz as tp,F as _a,dA as sp,a1 as np,dB as rp,dC as op,dD as ip,dE as ap,dF as lp,dG as cp,dH as dp,dI as up,dJ as Mo,ah as mp,dK as fp,dL as yl,dM as hp,dN as pp,dO as gp,dP as xp,dQ as Oo,dR as bp,dS as wl,dT as yp,dU as wp,dV as Sp,dW as vp,dX as jp,dY as kp,dZ as So,d_ as Cp,i as Np,d$ as Ap,e0 as Dp,e1 as Pp,e2 as Ip,a5 as Tp,e3 as Ep,e4 as Rp,e5 as Mp,e6 as Op,e7 as Sl,e8 as Bp,aD as Fp,aE as _p,aF as Lp,aH as vl,aI as jl,aL as kl,aK as tu,aM as su,e9 as $p,aZ as Wp,a_ as zp,a$ as Vp,b0 as Up,b1 as Kp,aT as Hp,aV as Gp,aW as qp,aX as Qp,aY as Yp}from"./useAppFontEffects-CuJPKtI1.js";import{u as nu,S as Cl,C as Xp,W as ru,f as Jp,a as Zp}from"./useRootScrollLock-DRGAe8PN.js";import{k as Nl,n as di,t as cn,o as Li,l as Al,m as eg,q as tg,s as sg,v as ng,w as rg,x as og,y as ig,z as ag,U as ou,A as $i,E as Wi,d as iu,F as au,c as lg,b as cg,G as lu,H as zi,I as Kn,J as cu,K as du,P as dg,T as ug,L as mg,M as fg,Q as hg,R as pg,S as Dl,V as gg,W as xg,X as bg,u as Fr,N as yg,D as wg,Y as Sg,Z as Pl,_ as vg,h as jg,f as kg,i as uu,j as Cg,$ as Ng,a0 as Ag,a1 as Dg,e as Pg,g as Ig,O as mu,C as Tg}from"./runtimeEndpointReset-DfJIWwwo.js";import{u as zn,n as Eg,f as Rg,a as Il,s as Mg,d as Og,b as Bg,r as Fg}from"./scheduledTasksApi-DuhdyYEa.js";import{f as Ur,h as On,T as fu,M as hu,D as Kr,j as Hr,d as _g,P as Vi,b as Lg,k as Ui,i as $g}from"./vendor-dnd-kit-core-BZknOX2w.js";import{u as si,S as Bo,h as Wg,a as pu,v as Ki,s as zg}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as ni}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{S as gu,M as xu,C as bu,a as Hi,b as Gi,c as qi,d as yu,e as Vg,f as Ug}from"./vendor-base-ui-BeMD8X_w.js";import{c as tr,u as Zn,d as wu,p as Kg}from"./vendor-zustand-BAGL70zf.js";import{g as Hg,b as Gg,E as Su,c as qg,d as Qg,e as Yg,f as Xg,i as Jg}from"./contextPanelEmbeddedChat-D2PM_pEv.js";import{a as La,s as wr,r as vu}from"./vendor-zod-CK21ihK-.js";import{u as Zg}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{d as ju}from"./vendor-cron-parser-CUcP7OfX.js";const ex="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",tx="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",ui=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__==="darwin"?ex:t.id==="terminal"?tx:void 0}),Tl=t=>{const e=nt.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:i}=t,[o,l]=c.useState(!1);let a;e[0]!==n?(a=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=a):a=e[1];const u=a,d=r||i;if(d&&!o){let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>l(!0),e[2]=p):p=e[2];let g;return e[3]!==d?(g=s.jsx("img",{src:d,alt:"",className:"h-4 w-4 rounded-sm",onError:p}),e[3]=d,e[4]=g):g=e[4],g}let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=Ie("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=h):h=e[5];let f;return e[6]!==u?(f=s.jsx("span",{className:h,children:u}),e[6]=u,e[7]=f):f=e[7],f},sx=t=>{const e=nt.c(75),{directory:n,className:r}=t,{t:i}=Nt(),o=zn(nx),l=zn(rx),a=zn(ox),u=zn(ix),d=zn(ax),h=zn(lx),f=zn(cx);let p,g;e[0]!==d?(p=()=>{d()},g=[d],e[0]=d,e[1]=p,e[2]=g):(p=e[1],g=e[2]),c.useEffect(p,g);const w=xn()&&Go();let v;e:{let _;e[3]!==l||e[4]!==o?(_=l.find(ae=>ae.id===o)??l.find(dx)??l[0]??Za[0],e[3]=l,e[4]=o,e[5]=_):_=e[5];const ie=_;if(ie){let ae;e[6]!==ie?(ae=ui(ie),e[6]=ie,e[7]=ae):ae=e[7],v=ae;break e}let ge;e[8]===Symbol.for("react.memo_cache_sentinel")?(ge=ui(Za[0]),e[8]=ge):ge=e[8],v=ge}const x=v;if(!w||!n||l.length===0)return null;let m;e[9]!==n?(m=async _=>{await Ym(n,_.id,_.appName)||await fd(n,_.appName)},e[9]=n,e[10]=m):m=e[10];const b=m;let y;e[11]!==b||e[12]!==f?(y=async _=>{await f(_.id),await b(_)},e[11]=b,e[12]=f,e[13]=y):y=e[13];const S=y;let N;e[14]!==n||e[15]!==i?(N=async()=>{(await pn(n)).ok&&Re.success(i("openInApp.toast.pathCopied"))},e[14]=n,e[15]=i,e[16]=N):N=e[16];const C=N;let j;e[17]!==r?(j=Ie("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=j):j=e[18];let A;e[19]!==b||e[20]!==x?(A=()=>{b(x)},e[19]=b,e[20]=x,e[21]=A):A=e[21];const D=u&&"animate-pulse";let I;e[22]!==D?(I=Ie("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",D),e[22]=D,e[23]=I):I=e[23];let M;e[24]!==x.label||e[25]!==i?(M=i("openInApp.actions.openInAria",{app:x.label}),e[24]=x.label,e[25]=i,e[26]=M):M=e[26];let $;e[27]!==x.fallbackIconDataUrl||e[28]!==x.iconDataUrl||e[29]!==x.label?($=s.jsx(Tl,{label:x.label,iconDataUrl:x.iconDataUrl,fallbackIconDataUrl:x.fallbackIconDataUrl}),e[27]=x.fallbackIconDataUrl,e[28]=x.iconDataUrl,e[29]=x.label,e[30]=$):$=e[30];let E;e[31]!==I||e[32]!==M||e[33]!==$||e[34]!==A?(E=s.jsx("button",{type:"button",onClick:A,className:I,"aria-label":M,children:$}),e[31]=I,e[32]=M,e[33]=$,e[34]=A,e[35]=E):E=e[35];let K;e[36]===Symbol.for("react.memo_cache_sentinel")?(K=Ie("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[36]=K):K=e[36];let B;e[37]!==i?(B=i("openInApp.actions.chooseAppAria"),e[37]=i,e[38]=B):B=e[38];let O;e[39]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=O):O=e[39];let T;e[40]!==B?(T=s.jsx(Qs,{asChild:!0,children:s.jsx("button",{type:"button",className:K,"aria-label":B,children:O})}),e[40]=B,e[41]=T):T=e[41];let k;e[42]!==C?(k=()=>{C()},e[42]=C,e[43]=k):k=e[43];let P;e[44]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(R,{name:"file-copy",className:"h-4 w-4"}),e[44]=P):P=e[44];let F;e[45]!==i?(F=i("openInApp.actions.copyPath"),e[45]=i,e[46]=F):F=e[46];let q;e[47]!==F?(q=s.jsx("span",{className:"typography-ui-label text-foreground",children:F}),e[47]=F,e[48]=q):q=e[48];let Q;e[49]!==k||e[50]!==q?(Q=s.jsxs(zt,{className:"flex items-center gap-2",onClick:k,children:[P,q]}),e[49]=k,e[50]=q,e[51]=Q):Q=e[51];let Y;e[52]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(Os,{}),e[52]=Y):Y=e[52];let ce;if(e[53]!==l||e[54]!==S||e[55]!==x.id){let _;e[57]!==S||e[58]!==x.id?(_=ie=>{const ge=ui(ie);return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{S(ie)},children:[s.jsx(Tl,{label:ie.label,iconDataUrl:ie.iconDataUrl,fallbackIconDataUrl:ge.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ie.label}),x.id===ie.id?s.jsx(R,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},ie.id)},e[57]=S,e[58]=x.id,e[59]=_):_=e[59],ce=l.map(_),e[53]=l,e[54]=S,e[55]=x.id,e[56]=ce}else ce=e[56];let X;e[60]!==a||e[61]!==h||e[62]!==i?(X=a?s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{h(!0)},children:[s.jsx(R,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("openInApp.actions.refreshApps")})]}):null,e[60]=a,e[61]=h,e[62]=i,e[63]=X):X=e[63];let oe;e[64]!==Q||e[65]!==ce||e[66]!==X?(oe=s.jsxs(Ys,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Q,Y,ce,X]}),e[64]=Q,e[65]=ce,e[66]=X,e[67]=oe):oe=e[67];let te;e[68]!==T||e[69]!==oe?(te=s.jsxs(Xs,{children:[T,oe]}),e[68]=T,e[69]=oe,e[70]=te):te=e[70];let he;return e[71]!==E||e[72]!==te||e[73]!==j?(he=s.jsxs("div",{className:j,children:[E,te]}),e[71]=E,e[72]=te,e[73]=j,e[74]=he):he=e[74],he};function nx(t){return t.selectedAppId}function rx(t){return t.availableApps}function ox(t){return t.isCacheStale}function ix(t){return t.isScanning}function ax(t){return t.initialize}function lx(t){return t.loadInstalledApps}function cx(t){return t.selectApp}function dx(t){return t.id===Qm}const Fo=new Map,Qi=new Set,ku=()=>{for(const t of Qi)t()},mi=(t,e)=>{const n=t.trim();n&&(e.length===0?Fo.delete(n):Fo.set(n,[...e]),ku())},ux=t=>{Fo.delete(t.trim())&&ku()},Cu=[],mx=t=>Fo.get(t.trim())??Cu,fx=t=>(Qi.add(t),()=>{Qi.delete(t)}),hx=t=>{const e=nt.c(2);let n;return e[0]!==t?(n=()=>mx(t),e[0]=t,e[1]=n):n=e[1],c.useSyncExternalStore(fx,n,px)};function px(){return Cu}const gx=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],xx=["dev","start","preview","serve"];async function bx(t,e,n){if(!t)return null;const r=Sx(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const i=vx(n);if(i){const o=await jx(t);return{command:`${o==="npm"?"npm run":o==="yarn"?"yarn":o==="pnpm"?"pnpm":o==="bun"?"bun run --shell=bun":"npm run"} ${i}`,label:`Start (${i})`}}}if(await yx(t)){const i=await wx(),o=typeof i=="number"&&Number.isFinite(i)&&i>0?i:8e3;return{command:`python3 -m http.server ${o}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${o}/`}}return null}async function yx(t){const e=`${t}/index.html`,n=await _o(e,t);return typeof n=="string"&&n.trim().length>0}async function wx(){try{const t=await ds("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Sx(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(xx.some(i=>n.includes(i)))return e}return null}function vx(t){for(const{pattern:e}of gx)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function jx(t){const e=await _o(`${t}/package.json`,t);if(e)try{const r=JSON.parse(e),i=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(i.startsWith("bun@"))return"bun";if(i.startsWith("pnpm@"))return"pnpm";if(i.startsWith("yarn@"))return"yarn";if(i.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,i]of n){const o=await _o(`${t}/${r}`,t);if(typeof o=="string"&&o.trim().length>0)return i}return"npm"}async function _o(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),i=await ds(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(i.ok)return i.text()}catch{}const n=qo()?.files;if(n?.readFile)try{const r=await n.readFile(t,{optional:!0});return typeof r?.content=="string"?r.content:null}catch{return null}try{const r=await ds(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function kx(t){try{const e=await _o(`${t}/package.json`,t);if(e==null)return null;const r=JSON.parse(e).scripts;return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}const un="__openchamber_auto_discover_preview__",Cx=15e3,Nx=3e3,fi=t=>t.id===un?"scan-2":ag.find(n=>n.key===t.icon)?.Icon??"play",Ax=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},Dx=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:i=!1})=>{const{t:o}=Nt(),{currentTheme:l}=er(),{terminal:a,runtime:u}=wn(),d=Sr(),{isMobile:h}=Ln(),f=c.useMemo(()=>xn(),[]),p=Nl(ee=>ee.instances),g=Nl(ee=>ee.load),w=Pe(ee=>ee.terminalShell),v=Pe(ee=>ee.terminalLoginShells.includes(ee.terminalShell)),x=Pe(ee=>ee.setSettingsPage),m=Pe(ee=>ee.setSettingsDialogOpen),b=Pe(ee=>ee.setSettingsProjectsSelectedId),y=Pe(ee=>ee.openContextPreview),S=Et(ee=>ee.ensureDirectory),N=Et(ee=>ee.reconcileServerSessions),C=Et(ee=>ee.setTabLabel),j=Et(ee=>ee.setTabIconKey),A=Et(ee=>ee.setActiveTab),D=Et(ee=>ee.setConnecting),I=Et(ee=>ee.setTabSessionId),M=Et(ee=>ee.setTabPurpose),$=Et(ee=>ee.allocateActionExecution),E=Et(ee=>ee.setTabLifecycle),K=Et(ee=>ee.setTabPreviewUrl),B=Et(ee=>ee.matchesActionExecution),O=Et(ee=>ee.captureStartedActionMutationRevisions),[T,k]=c.useState([]),[P,F]=c.useState(null),[q,Q]=c.useState(!1),Y=c.useRef({}),ce=c.useRef({}),X=c.useRef({}),oe=c.useRef(new Set),te=c.useRef(0),[he,_]=c.useState({}),ie=t?.id??null,ge=t?.path??"",ae=c.useMemo(()=>ie?{id:ie,path:ge}:null,[ie,ge]);c.useEffect(()=>{f&&g().catch(()=>{})},[f,g]);const z=c.useCallback(async ee=>{await Xo(ee)},[]),ne=c.useCallback(async()=>{if(!ae)return;const ee=te.current+1;te.current=ee,Q(!0);try{const ze=await al(ae);if(te.current!==ee)return;const _e=ze.actions;k(_e),F(pe=>pe===un||pe&&_e.some(qe=>qe.id===pe)?pe:null)}catch{if(te.current!==ee)return}finally{te.current===ee&&Q(!1)}},[ae]),ue=c.useMemo(()=>di(e||ae?.path||""),[e,ae?.path]),me=c.useMemo(()=>di(ae?.path||""),[ae?.path]),ke=c.useMemo(()=>di(d||"")||ue,[d,ue]),Te=c.useRef(ke);c.useEffect(()=>{Te.current=ke},[ke]);const je=Et(ee=>ue?ee.getDirectoryState(ue):void 0),Ee=Et(ee=>me&&me!==ue?ee.getDirectoryState(me):void 0),xe=c.useMemo(()=>{const ee=ue?[{directory:ue,state:je}]:[];return me&&me!==ue&&ee.push({directory:me,state:Ee}),ee},[je,ue,me,Ee]),H=c.useMemo(()=>{const ee=ue?[ue]:[];return me&&me!==ue&&ee.push(me),ee},[ue,me]),Ce=c.useCallback(ee=>ee.id!==un&&ee.runIn==="parent"&&me||ue,[ue,me]),ve=c.useCallback((ee,ze,_e)=>`${ee}::${ze}::${_e}`,[]),re=c.useCallback((ee,ze,_e=Et.getState())=>ee?_e.getDirectoryState(ee)?.tabs.find(pe=>pe.purpose.type==="project-action"&&pe.purpose.actionId===ze)??null:null,[]),le=c.useMemo(()=>{const ee={};for(const{directory:ze,state:_e}of xe)for(const pe of _e?.tabs??[]){if(pe.purpose.type!=="project-action"||!pe.purpose.executionId||!pe.terminalSessionId||pe.lifecycle==="idle"||pe.lifecycle==="exited")continue;const qe=cn(ze,pe.purpose.actionId),tt=ve(ze,pe.purpose.actionId,pe.purpose.executionId);ee[qe]={directory:ze,actionId:pe.purpose.actionId,tabId:pe.id,sessionId:pe.terminalSessionId,executionId:pe.purpose.executionId,status:pe.lifecycle==="stopping"?"stopping":he[tt]?"waiting-for-preview":"running"}}return ee},[ve,he,xe]),se=c.useCallback((ee,ze,_e)=>{const pe=cn(ee,ze),qe=ve(ee,ze,_e),pt=Y.current[pe]?.executionId===_e,gt=globalThis.window,Je=St=>{gt?.clearTimeout(X.current[St]),delete X.current[St]};pt&&(delete Y.current[pe],Je(pe)),ce.current[qe]?.(),delete ce.current[qe],Je(qe),_(St=>{if(!St[qe])return St;const Ze={...St};return delete Ze[qe],Ze})},[ve]),G=c.useCallback(ee=>{ce.current[ee]?.(),delete ce.current[ee]},[]),U=c.useCallback(ee=>{window.clearTimeout(X.current[ee]),delete X.current[ee]},[]);c.useEffect(()=>{const ee=ce.current,ze=X.current;return()=>{for(const _e of Object.keys(ee))G(_e);for(const _e of Object.keys(ze))U(_e)}},[U,G]),c.useEffect(()=>{const ee=new Set(H);for(const ze of Object.values(Y.current))ee.has(ze.directory)||se(ze.directory,ze.actionId,ze.executionId);for(const ze of Object.keys(ce.current)){const _e=ze.split("::",1)[0]??"";ee.has(_e)||G(ze)}},[se,G,H]);const be=c.useCallback((ee,ze)=>{Pe.getState().openContextPanelTab(ee,{mode:"terminal",targetDirectory:ze===ee?null:ze})},[]),W=c.useMemo(()=>P?T.find(ee=>ee.id===P)??null:null,[T,P]),Ne=c.useMemo(()=>({id:un,name:o("projectActions.actions.autoDiscover"),command:"",icon:"scan-2",autoOpenUrl:!0}),[o]),Oe=!h,ye=c.useMemo(()=>Oe?[Ne,...T]:T,[T,Ne,Oe]);c.useEffect(()=>{ne()},[ne]),c.useEffect(()=>{const ee=H.map(ze=>Li(a,ze,O,_e=>N(ze,_e.sessions,{startedActionMutationRevisions:_e.startedActionMutationRevisions})));return()=>{for(const ze of ee)ze()}},[O,N,a,H]),c.useEffect(()=>{for(const{directory:ee,state:ze}of xe)if(ee)for(const _e of ze?.tabs??[]){if(_e.purpose.type!=="project-action")continue;const pe=_e.purpose.actionId,qe=ye.find(gt=>gt.id===pe),tt=qe?.name??pe,pt=qe?.icon||"play";_e.label!==tt&&C(ee,_e.id,tt),_e.iconKey!==pt&&j(ee,_e.id,pt)}},[ye,j,C,xe]),c.useEffect(()=>{const ee=globalThis.window;if(!ee)return;const ze=_e=>{const pe=_e.detail;ie&&(pe?.projectId&&pe.projectId!==ie||ne())};return ee.addEventListener(Al,ze),()=>{ee.removeEventListener(Al,ze)}},[ne,ie]),c.useEffect(()=>{P&&(P===un&&Oe||T.some(ee=>ee.id===P)||F(null))},[T,Oe,P]),c.useEffect(()=>{const ee=_e=>{delete X.current[_e];const pe=Y.current[_e];if(!pe||pe.openedUrl)return;const qe=ve(pe.directory,pe.actionId,pe.executionId),tt=pe.announced;if(tt.length!==0){if(window.clearTimeout(X.current[qe]),delete X.current[qe],pe.openedUrl=!0,_(pt=>{if(!pt[qe])return pt;const gt={...pt};return delete gt[qe],gt}),tt.length===1){mi(pe.directory,[]),K(pe.directory,pe.tabId,tt[0],{locked:!1,autoOpened:!0}),y(pe.directory,tt[0]);return}pe.offering=!0,mi(pe.directory,tt),Pe.getState().openContextSurface(pe.directory,"browser"),Re.info(o("projectActions.toast.multipleServers"))}},ze=()=>{const _e=Et.getState(),pe=_e.sessions,qe=le;for(const[tt,pt]of Object.entries(qe)){const Je=pe.get(pt.directory)?.tabs.find(Xe=>Xe.id===pt.tabId);if(!Je||Je.terminalSessionId!==pt.sessionId){se(pt.directory,pt.actionId,pt.executionId);continue}const St=Y.current[tt],Ze=St?.executionId===pt.executionId?St:{hostDirectory:Te.current||pt.directory,directory:pt.directory,tabId:pt.tabId,actionId:pt.actionId,executionId:pt.executionId,lastSeenChunkId:null,openedUrl:!0,tail:"",openInPreview:!1,announced:[],offering:!1};Y.current[tt]=Ze;const vt=ye.find(Xe=>Xe.id===pt.actionId),rt=_e.getBuffer(pt.directory,pt.tabId).chunks;if(!vt||rt.length===0)continue;const we=rt.filter(Xe=>Ze.lastSeenChunkId===null||Xe.id>Ze.lastSeenChunkId);if(we.length===0)continue;const ct=we.map(Xe=>Xe.data).join(""),dt=`${Ze.tail}${ct}`;if(Ze.openInPreview&&(!Ze.openedUrl||Ze.offering)){const Xe=og(dt),Tt=Ze.announced.length;for(const kt of Xe)Ze.announced.includes(kt)||Ze.announced.push(kt);const ut=Ze.announced.length-Tt;Ze.offering&&ut>0?mi(pt.directory,Ze.announced):!Ze.openedUrl&&Tt===0&&Ze.announced.length>0&&(window.clearTimeout(X.current[tt]),X.current[tt]=window.setTimeout(()=>ee(tt),Nx))}const At=!Ze.openedUrl&&vt.autoOpenUrl===!0&&!Ze.openInPreview?ig(dt):null,We=we[we.length-1]?.id??Ze.lastSeenChunkId;if(Ze.lastSeenChunkId=We,Ze.tail=dt.slice(-512),At)if(Ze.openedUrl=!0,Ze.openInPreview){const Xe=qe[tt];Xe&&(K(Xe.directory,Xe.tabId,At,{locked:!1,autoOpened:!1,expectedExecutionId:Xe.executionId}),Xe.status==="waiting-for-preview"&&_(Tt=>{const ut=ve(Xe.directory,Xe.actionId,Xe.executionId);if(!Tt[ut])return Tt;const kt={...Tt};return delete kt[ut],kt}),window.clearTimeout(X.current[tt]),delete X.current[tt],y(Xe.directory,At))}else z(At),Re.success(o("projectActions.toast.openedUrlFromOutput"));Y.current[tt]=Ze}for(const tt of Object.keys(Y.current))if(!qe[tt]){const pt=Y.current[tt],gt=pt?pe.get(pt.directory)?.tabs.find(St=>St.id===pt.tabId):void 0;if(gt?.purpose.type==="project-action"&>.purpose.executionId===pt?.executionId&&!!gt.terminalSessionId&>.lifecycle!=="idle"&>.lifecycle!=="exited")continue;delete Y.current[tt],window.clearTimeout(X.current[tt]),delete X.current[tt]}};return ze(),Et.subscribe((_e,pe)=>{(_e.sessions!==pe.sessions||_e.buffers!==pe.buffers)&&ze()})},[se,Te,ye,ve,y,z,le,K,o]),c.useEffect(()=>{for(const{directory:ee,state:ze}of xe)for(const _e of ze?.tabs??[]){if(_e.purpose.type!=="project-action"||!_e.purpose.executionId||!_e.terminalSessionId||_e.lifecycle!=="running")continue;const pe=_e.purpose.actionId,qe=_e.purpose.executionId,tt=ve(ee,pe,qe);if(ce.current[tt])continue;const pt=a.connect(_e.terminalSessionId,{onEvent:gt=>{if(!B(ee,_e.id,qe))return;gt.type==="snapshot"&&(Et.getState().replaceBuffer(ee,_e.id,gt.data??"",gt.sequence??0),gt.status==="running"&&Et.getState().setTabLifecycle(ee,_e.id,"running",{expectedExecutionId:qe}),gt.status==="exited"&&(Et.getState().setTabLifecycle(ee,_e.id,"exited",{expectedExecutionId:qe}),Et.getState().setTabPurpose(ee,_e.id,{type:"project-action",actionId:pe,executionId:null}),se(ee,pe,qe)));const Je=gt.type==="data"?gt.data??"":"";Je&&Et.getState().appendToBuffer(ee,_e.id,Je,gt.sequence,gt.replayData),gt.type==="exit"&&(Et.getState().setTabLifecycle(ee,_e.id,"exited",{expectedExecutionId:qe}),Et.getState().setTabPurpose(ee,_e.id,{type:"project-action",actionId:pe,executionId:null}),se(ee,pe,qe))},onError:(gt,Je)=>{!Je||!B(ee,_e.id,qe)||(Et.getState().setTabLifecycle(ee,_e.id,"exited",{expectedExecutionId:qe}),Et.getState().setTabSessionId(ee,_e.id,null,{expectedExecutionId:qe}),Et.getState().setTabPurpose(ee,_e.id,{type:"project-action",actionId:pe,executionId:null}),se(ee,pe,qe))}});ce.current[tt]=pt.close}},[se,ve,B,a,xe]);const Fe=c.useCallback(async ee=>{const ze=Ce(ee);if(!ze)throw new Error(o("projectActions.error.noActiveDirectory"));const _e=cn(ze,ee.id);S(ze);const pe=Et.getState(),qe=re(ze,ee.id,pe),tt=qe?.id??pe.createTab(ze);C(ze,tt,ee.name),j(ze,tt,ee.icon||"play"),qe||M(ze,tt,{type:"project-action",actionId:ee.id,executionId:null}),A(ze,tt);const gt=Et.getState().getDirectoryState(ze)?.tabs.find(Je=>Je.id===tt);return{executionDirectory:ze,key:_e,tabId:tt,sessionId:gt?.terminalSessionId??null,executionId:gt?.purpose.type==="project-action"?gt.purpose.executionId:null}},[S,Ce,re,A,j,C,M,o]),Ke=c.useCallback(async ee=>{if(u.isVSCode||!i&&h)return;if(!ue){Re.error(o("projectActions.error.noActiveDirectoryForAction"));return}const ze=cn(Ce(ee),ee.id),_e=le[ze];if(_e&&_e.status==="running"||oe.current.has(ze))return;oe.current.add(ze);let pe=null;try{const qe=ee.id===un?await(async()=>{const[ut,kt]=await Promise.all([al({id:ae?.id??"",path:ue}),kx(ue)]),Rt=await bx(ue,ut.actions,kt);if(!Rt)throw new Error(o("contextPanel.preview.noDevServer"));return{id:un,name:o("projectActions.actions.autoDiscover"),command:Rt.command,icon:"scan-2",autoOpenUrl:!0,openUrl:Rt.previewUrlHint||""}})():ee,tt=qe.autoOpenUrl===!0&&(qe.openUrl||"").trim().length>0,pt=!tt&&ee.id!==un,gt=Te.current||ue,{executionDirectory:Je,key:St,tabId:Ze}=await Fe(qe),vt=eg(qe.command);if(!vt)throw new Error(o("projectActions.error.failedToRunAction"));const rt=qe.autoOpenUrl===!0&&f&&(qe.desktopOpenSshForward||"").trim().length>0,we=qe.autoOpenUrl?Ax(qe.openUrl):null,ct=qe.autoOpenUrl&&f?tg(qe.desktopOpenSshForward,p):null;if(a.listSessions){const ut=re(Je,qe.id);if(ut?.purpose.type==="project-action"&&ut.purpose.executionId===null){const kt=await sg(a,Je,{captureStartedActionMutationRevisions:O});kt&&N(Je,kt.sessions,{startedActionMutationRevisions:kt.startedActionMutationRevisions})}}const dt=re(Je,qe.id);let At,We;if(dt?.lifecycle==="running"&&dt.terminalSessionId&&dt.purpose.type==="project-action"&&dt.purpose.executionId)At=dt.terminalSessionId,We=dt.purpose.executionId;else{const ut=dt?.purpose.type==="project-action"?dt.purpose.executionId:null;ut&&se(Je,qe.id,ut);const kt=$(Je,Ze,qe.id);if(!kt)throw new Error(o("projectActions.error.failedToCreateTerminalSession"));pe={directory:Je,tabId:Ze,id:kt},D(Je,Ze,!0,{expectedExecutionId:kt});const Rt=await ng({terminal:a,createOptions:{cwd:Je,shell:w,loginShell:v,themeMode:l.metadata.variant==="light"?"light":"dark",terminalBackground:l.colors.surface.background,terminalForeground:l.colors.syntax.base.foreground},command:vt,isRunStillExpected:()=>B(Je,Ze,kt),purpose:{type:"project-action",actionId:qe.id,executionId:kt}});if(!B(Je,Ze,kt)){Rt.sessionId===kt&&await a.close(Rt.sessionId).catch(()=>{});return}We=Rt.purpose?.type==="project-action"?Rt.purpose.executionId:kt,At=Rt.sessionId,M(Je,Ze,{type:"project-action",actionId:qe.id,executionId:We}),I(Je,Ze,At,{expectedExecutionId:We}),D(Je,Ze,!1,{expectedExecutionId:We})}pt&>&&be(gt,Je),Y.current[St]={hostDirectory:gt,directory:Je,tabId:Ze,actionId:qe.id,executionId:We,lastSeenChunkId:null,openedUrl:!!ct||!!we||tt,tail:"",openInPreview:qe.id===un,announced:[],offering:!1};const Xe=ve(Je,qe.id,We);D(Je,Ze,!0,{expectedExecutionId:We});const Tt=a.connect(At,{onEvent:ut=>{if(!B(Je,Ze,We)||ut.purpose?.type==="project-action"&&ut.purpose.executionId!==We)return;ut.type==="snapshot"&&(Et.getState().replaceBuffer(Je,Ze,ut.data??"",ut.sequence??0),Et.getState().setConnecting(Je,Ze,!1,{expectedExecutionId:We}),ut.purpose?.type==="project-action"&&Et.getState().setTabPurpose(Je,Ze,{type:"project-action",actionId:ut.purpose.actionId,executionId:ut.purpose.executionId}),ut.status==="running"&&Et.getState().setTabLifecycle(Je,Ze,"running",{expectedExecutionId:We}),ut.status==="exited"&&(Et.getState().setTabLifecycle(Je,Ze,"exited",{expectedExecutionId:We}),Et.getState().setTabPurpose(Je,Ze,{type:"project-action",actionId:qe.id,executionId:null}),se(Je,qe.id,We)));const kt=ut.type==="data"?ut.data??"":"";kt&&Et.getState().appendToBuffer(Je,Ze,kt,ut.sequence,ut.replayData),ut.type==="exit"&&(Et.getState().setTabLifecycle(Je,Ze,"exited",{expectedExecutionId:We}),Et.getState().setConnecting(Je,Ze,!1,{expectedExecutionId:We}),Et.getState().setTabPurpose(Je,Ze,{type:"project-action",actionId:qe.id,executionId:null}),se(Je,qe.id,We))},onError:(ut,kt)=>{B(Je,Ze,We)&&(Et.getState().setConnecting(Je,Ze,!1,{expectedExecutionId:We}),kt&&(Et.getState().setTabLifecycle(Je,Ze,"exited",{expectedExecutionId:We}),Et.getState().setTabSessionId(Je,Ze,null,{expectedExecutionId:We}),Et.getState().setTabPurpose(Je,Ze,{type:"project-action",actionId:qe.id,executionId:null}),se(Je,qe.id,We)))}});if(!B(Je,Ze,We)){Tt.close();return}ce.current[Xe]?.(),ce.current[Xe]=Tt.close,window.clearTimeout(X.current[Xe]),delete X.current[Xe],qe.id===un&&!we&&(_(ut=>({...ut,[Xe]:!0})),X.current[Xe]=window.setTimeout(()=>{delete X.current[Xe];const ut=Y.current[St];!ut||ut.executionId!==We||ut.openedUrl||ut.offering||B(Je,Ze,We)&&(_(kt=>{if(!kt[Xe])return kt;const Rt={...kt};return delete Rt[Xe],Rt}),Et.getState().setActiveTab(Je,Ze),be(ut.hostDirectory,Je))},Cx)),ct?(K(Je,Ze,null,{locked:!0,expectedExecutionId:We}),z(ct),Re.success(o("projectActions.toast.openedForwardedUrl"))):we?(K(Je,Ze,we,{locked:!0,autoOpened:!0,expectedExecutionId:We}),y(gt,we),Re.success(o("projectActions.toast.openedActionUrl"))):tt?(K(Je,Ze,null,{locked:!0,expectedExecutionId:We}),Re.error(o("projectActions.error.invalidCustomUrlFormat"))):rt?(K(Je,Ze,null,{locked:!0,expectedExecutionId:We}),Re.error(o("projectActions.error.selectedDesktopSshForwardUnavailable"))):K(Je,Ze,null,{locked:!1,autoOpened:!1,expectedExecutionId:We})}catch(qe){if(pe&&B(pe.directory,pe.tabId,pe.id)){const{directory:tt,tabId:pt,id:gt}=pe;se(tt,ee.id,gt),E(tt,pt,"exited",{expectedExecutionId:gt}),M(tt,pt,{type:"project-action",actionId:ee.id,executionId:null})}if(qe instanceof Error&&qe.message==="PROJECT_ACTION_RUN_CANCELLED")return;if(qe instanceof Error&&(qe.message==="COMMAND_MODE_UNSUPPORTED"||qe.message==="PROJECT_ACTION_PURPOSE_UNSUPPORTED")){Re.error(o("projectActions.error.failedToCreateTerminalSession"));return}Re.error(qe instanceof Error?qe.message:o("projectActions.error.failedToRunAction"))}finally{oe.current.delete(ze)}},[l.colors.surface.background,l.colors.syntax.base.foreground,l.metadata.variant,Te,p,Fe,i,h,f,ue,v,w,z,y,le,be,u.isVSCode,Ce,B,se,ve,re,N,$,O,D,E,M,K,I,ae?.id,o,a]),$e=c.useCallback(async ee=>{const ze=cn(Ce(ee),ee.id),_e=le[ze];_e&&await rg({terminal:a,sessionId:_e.sessionId,isExecutionStillCurrent:()=>B(_e.directory,_e.tabId,_e.executionId),markStopping:()=>{E(_e.directory,_e.tabId,"stopping",{expectedExecutionId:_e.executionId})},restoreRunning:()=>{E(_e.directory,_e.tabId,"running",{expectedExecutionId:_e.executionId})},clearSession:()=>{I(_e.directory,_e.tabId,null,{expectedExecutionId:_e.executionId})},finalizeExit:()=>{E(_e.directory,_e.tabId,"exited",{expectedExecutionId:_e.executionId}),M(_e.directory,_e.tabId,{type:"project-action",actionId:_e.actionId,executionId:null}),se(_e.directory,_e.actionId,_e.executionId)}})},[se,Ce,B,le,E,M,I,a]),V=c.useCallback(()=>{const ee=W??ye[0];if(!ee)return;const ze=cn(Ce(ee),ee.id),_e=le[ze];if(_e?.status!=="stopping"){if(_e){$e(ee);return}Ke(ee)}},[ye,Ce,Ke,le,W,$e]),fe=c.useCallback((ee,ze=!1)=>{if(F(ee.id),!ze){Ke(ee);return}const _e=cn(Ce(ee),ee.id),pe=le[_e];if(pe?.status!=="stopping"){if(pe){$e(ee);return}Ke(ee)}},[Ce,Ke,le,$e]),Me=c.useCallback(()=>{ae?.id&&(b(ae.id),x("projects"),m(!0))},[m,x,b,ae?.id]),De=W??ye[0]??null,at=De?le[cn(Ce(De),De.id)]:null,Qe=Et(ee=>at?ee.getDirectoryState(at.directory)?.tabs.find(ze=>ze.id===at.tabId)?.previewUrl??null:null);if(u.isVSCode||!i&&h||!ae||!ue)return null;const lt=W??ye[0]??null;if(!lt)return null;const de=fi(lt),J=cn(Ce(lt),lt.id),Se=le[J],Ve=Se?.status==="stopping",He=Se?.status==="waiting-for-preview",it=!!(Se&&Qe),Ue=()=>{!Se||!Qe||y(Se.directory,Qe)},st=lt.id===un;return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",disabled:q||Ve,className:Ie("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:V,"aria-label":Se?o("projectActions.actions.stopNamedAria",{name:lt.name}):o("projectActions.actions.runNamedAria",{name:lt.name}),children:Ve||He?s.jsx(R,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):Se?s.jsx(R,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(R,{name:de,className:"h-5 w-5"})})}),st?s.jsx(It,{sideOffset:6,children:o("projectActions.actions.autoDiscoverTooltip")}):null]}),it?s.jsxs(Dt,{children:[s.jsx(Pt,{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":o("projectActions.actions.openPreview"),onClick:Ue,children:s.jsx(R,{name:"global",className:"h-4 w-4"})})}),s.jsx(It,{sideOffset:6,children:o("projectActions.actions.openPreview")})]}):null,s.jsxs(Xs,{children:[s.jsx(Qs,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("projectActions.actions.chooseActionAria"),children:s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Ys,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(zt,{className:"flex items-center gap-2",onClick:Me,children:[s.jsx(R,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("projectActions.actions.addNewAction")})]}),s.jsx(Os,{}),ye.map(ee=>{const ze=fi(ee),_e=cn(Ce(ee),ee.id),pe=le[_e],qe=!!pe,tt=pe?.status==="stopping";return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{fe(ee,!0)},children:[s.jsx(R,{name:ze,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ee.name}),tt||pe?.status==="waiting-for-preview"?s.jsx(R,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):qe?s.jsx(R,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ee.id)})]})]})]}):s.jsxs("div",{className:Ie("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(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:V,disabled:q||Ve,className:Ie("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":Se?o("projectActions.actions.stopNamedAria",{name:lt.name}):o("projectActions.actions.runNamedAria",{name:lt.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:Ve||He?s.jsx(R,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):Se?s.jsx(R,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(R,{name:de,className:"h-4 w-4"})})})}),st?s.jsx(It,{sideOffset:6,children:o("projectActions.actions.autoDiscoverTooltip")}):null]}),it?s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ue,className:Ie(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":o("projectActions.actions.openPreview"),children:s.jsx(R,{name:"global",className:"h-4 w-4"})})}),s.jsx(It,{sideOffset:6,children:o("projectActions.actions.openPreview")})]}):null,s.jsxs(Xs,{children:[s.jsx(Qs,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie(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":o("projectActions.actions.chooseActionAria"),children:s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Ys,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(zt,{className:"flex items-center gap-2",onClick:Me,children:[s.jsx(R,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("projectActions.actions.addNewAction")})]}),s.jsx(Os,{}),ye.map(ee=>{const ze=fi(ee),_e=cn(Ce(ee),ee.id),pe=le[_e],qe=!!pe,tt=pe?.status==="stopping";return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{fe(ee,!0)},children:[s.jsx(R,{name:ze,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ee.name}),tt||pe?.status==="waiting-for-preview"?s.jsx(R,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):qe?s.jsx(R,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ee.id)})]})]})]})},Br=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Px=({projects:t,worktreesByProject:e,directory:n,activeProjectId:r})=>{const i=Br(n??"");if(i){const o=yd(t,e,i);if(o)return o}return t.find(o=>o.id===r)??null};function Ix(){const t=Vt(w=>w.projects),e=Vt(w=>w.activeProjectId),n=et(w=>w.availableWorktreesByProject),r=et(w=>w.currentSessionId),i=Pf(r??null),o=et(w=>r?w.worktreeMetadata.get(r)?.path??"":""),l=et(w=>w.newSessionDraft?.open?Br(w.newSessionDraft.bootstrapPendingDirectory??w.newSessionDraft.directoryOverride??""):""),a=c.useMemo(()=>Br(o||""),[o]),u=c.useMemo(()=>{const w=typeof i?.directory=="string"?i.directory:"";return Br(w||"")},[i?.directory]),d=a||u||l,h=c.useMemo(()=>Px({projects:t,worktreesByProject:n,directory:d,activeProjectId:e}),[e,d,t,n]),f=c.useMemo(()=>Br(d||h?.path||""),[d,h?.path]),p=c.useMemo(()=>h?{id:h.id,path:h.path}:null,[h]),g=c.useRef(null);return c.useEffect(()=>{p&&f&&(g.current={projectRef:p,directory:f})},[f,p]),c.useMemo(()=>p&&f?{projectRef:p,directory:f}:g.current,[p,f])}const Tx=({transform:t})=>({...t,y:0}),Ex={Item:zt,Separator:Os},Rx={Item:({className:t,...e})=>s.jsx(xu,{className:Ie(vd,t),...e}),Separator:({className:t,...e})=>s.jsx(gu,{className:Ie(Sd,t),...e})},Mx=t=>{const e=nt.c(62),{tab:n,isActive:r,suppressControls:i,onSelect:o,onClose:l,renderMenu:a,closeOtherTabs:u,onMenuOpenChangeComplete:d,children:h}=t,{t:f}=Nt(),[p,g]=c.useState(!1),[w,v]=c.useState(!1),[x,m]=c.useState(!1);let b;e[0]!==n.id?(b={id:n.id},e[0]=n.id,e[1]=b):b=e[1];const{attributes:y,listeners:S,setNodeRef:N,transform:C,transition:j,isDragging:A}=si(b);let D;e[2]!==f||e[3]!==n.session.title?(D=n.session.title?.trim()||f("sessions.sidebar.session.untitled"),e[2]=f,e[3]=n.session.title,e[4]=D):D=e[4];const I=D,M=!i&&(p||w),$=va(n.id),E=$?.type==="busy"||$?.type==="retry",B=wd(n.id)>0&&!r&&!E,O=E||B;let T;e[5]!==E||e[6]!==f?(T=f(E?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),e[5]=E,e[6]=f,e[7]=T):T=e[7];const k=T;let P;e[8]!==u||e[9]!==r||e[10]!==o||e[11]!==n?(P=ue=>({session:n.session,isActive:r,select:()=>o(n),closeOtherTabs:()=>u(n.id),components:ue}),e[8]=u,e[9]=r,e[10]=o,e[11]=n,e[12]=P):P=e[12];const F=P;let q;e[13]!==C?(q=ni.Translate.toString(C),e[13]=C,e[14]=q):q=e[14];let Q;e[15]!==q||e[16]!==j?(Q={transform:q,transition:j},e[15]=q,e[16]=j,e[17]=Q):Q=e[17];const Y=A&&"z-10 opacity-60";let ce;e[18]!==Y?(ce=Ie("session-tab-slot flex h-7 w-44 shrink-0 touch-none",Y),e[18]=Y,e[19]=ce):ce=e[19];const X=r?"true":"false";let oe;e[20]!==r?(oe=r?{"data-active-session-tab":!0}:{},e[20]=r,e[21]=oe):oe=e[21];let te;e[22]!==d?(te=ue=>d?.(ue),e[22]=d,e[23]=te):te=e[23];let he;e[24]!==h||e[25]!==k||e[26]!==r||e[27]!==E||e[28]!==F||e[29]!==p||e[30]!==l||e[31]!==d||e[32]!==o||e[33]!==M||e[34]!==a||e[35]!==O||e[36]!==i||e[37]!==f||e[38]!==n||e[39]!==I?(he=s.jsx(bu,{render:ue=>s.jsxs("div",{...ue,role:"tab","aria-selected":r,tabIndex:r?void 0:0,onClick:r?void 0:()=>o(n),onKeyDown:r?void 0:me=>{(me.key==="Enter"||me.key===" ")&&(me.preventDefault(),o(n))},onAuxClick:me=>{me.button===1&&(me.preventDefault(),l(n.id))},"data-controls-open":M?"true":"false",className:Ie("session-tab group/session-tab relative flex h-7 w-full min-w-0 select-none items-center rounded-md px-2",r?"bg-interactive-selection":Ie("cursor-pointer text-muted-foreground hover:bg-interactive-hover hover:text-foreground",M&&"bg-interactive-hover text-foreground")),children:[s.jsxs("div",{className:Ie("flex min-w-0 flex-1 items-center",!i&&"group-hover/session-tab:pr-10",M&&"pr-10"),children:[s.jsx("div",{className:Ie("min-w-0 flex-1 overflow-hidden whitespace-nowrap",!i&&"session-tab-title"),children:r?h:s.jsx("div",{className:"flex min-w-0 flex-col justify-center",children:s.jsx("span",{className:"block max-w-full overflow-hidden whitespace-nowrap text-[13px] font-medium leading-4",children:I})})}),O?s.jsx("span",{className:Ie("ml-1.5 h-1.5 w-1.5 shrink-0 rounded-full",E?"bg-primary":"bg-[var(--status-info)]",!i&&"group-hover/session-tab:opacity-0",M&&"opacity-0"),"aria-label":k}):null]}),i?null:s.jsxs("div",{onClick:Bx,onPointerDown:Fx,className:Ie("absolute right-1 top-1/2 hidden -translate-y-1/2 items-center gap-0.5","opacity-0 transition-opacity duration-150","group-hover/session-tab:flex group-hover/session-tab:opacity-100",M&&"flex opacity-100"),children:[s.jsxs(Xs,{open:p,onOpenChange:me=>{g(me),me&&v(!0)},onOpenChangeComplete:me=>{me||v(!1),d?.(me)},children:[s.jsx(Qs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":f("header.sessionTabs.tabMenuAria"),className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"more",className:"size-4"})})}),s.jsx(Ys,{align:"start",className:"min-w-[190px]",children:a(F(Ex))})]}),s.jsx("button",{type:"button","aria-label":f("header.sessionTabs.closeTab"),onClick:()=>l(n.id),className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"size-4"})})]})]})}),e[24]=h,e[25]=k,e[26]=r,e[27]=E,e[28]=F,e[29]=p,e[30]=l,e[31]=d,e[32]=o,e[33]=M,e[34]=a,e[35]=O,e[36]=i,e[37]=f,e[38]=n,e[39]=I,e[40]=he):he=e[40];let _,ie;e[41]===Symbol.for("react.memo_cache_sentinel")?(_={color:"var(--surface-elevated-foreground)"},ie=Ie(Pi,"min-w-[190px]"),e[41]=_,e[42]=ie):(_=e[41],ie=e[42]);let ge;e[43]!==F||e[44]!==a?(ge=a(F(Rx)),e[43]=F,e[44]=a,e[45]=ge):ge=e[45];let ae;e[46]!==ge?(ae=s.jsx(Hi,{children:s.jsx(Gi,{className:"app-region-no-drag z-50",children:s.jsx(qi,{"data-slot":"dropdown-menu-content",style:_,className:ie,children:ge})})}),e[46]=ge,e[47]=ae):ae=e[47];let z;e[48]!==x||e[49]!==te||e[50]!==he||e[51]!==ae?(z=s.jsxs(yu,{open:x,onOpenChange:m,onOpenChangeComplete:te,children:[he,ae]}),e[48]=x,e[49]=te,e[50]=he,e[51]=ae,e[52]=z):z=e[52];let ne;return e[53]!==y||e[54]!==S||e[55]!==N||e[56]!==oe||e[57]!==z||e[58]!==Q||e[59]!==ce||e[60]!==X?(ne=s.jsx("div",{ref:N,style:Q,className:ce,"data-active":X,...oe,...y,...S,children:z}),e[53]=y,e[54]=S,e[55]=N,e[56]=oe,e[57]=z,e[58]=Q,e[59]=ce,e[60]=X,e[61]=ne):ne=e[61],ne},Ox=t=>{const e=nt.c(64),{renderMenu:n,onMenuOpenChangeComplete:r,suppressActiveTabControls:i,children:o}=t,l=i===void 0?!1:i,{t:a}=Nt(),u=so(_x),d=so(Lx),h=so($x),f=so(Wx),p=et(zx),g=et(Vx),w=Ps(Ux);let v,x;e[0]!==p||e[1]!==d?(v=()=>{p&&d(p)},x=[p,d],e[0]=p,e[1]=d,e[2]=v,e[3]=x):(v=e[2],x=e[3]),c.useEffect(v,x);let m;if(e[4]!==w){m=new Map;for(const je of w)m.set(je.id,je);e[4]=w,e[5]=m}else m=e[5];const b=m;let y;if(e[6]!==b||e[7]!==u){y=[];for(const je of u){const Ee=b.get(je);Ee&&y.push({id:je,session:Ee})}e[6]=b,e[7]=u,e[8]=y}else y=e[8];const S=y;let N;e[9]!==g?(N=je=>{g(je.id,$s(je.session))},e[9]=g,e[10]=N):N=e[10];const C=N,j=Kx;let A;e[11]!==h||e[12]!==p||e[13]!==C||e[14]!==S?(A=je=>{if(h(je),p&&p!==je){const Ee=S.find(xe=>xe.id===je);Ee&&C(Ee)}},e[11]=h,e[12]=p,e[13]=C,e[14]=S,e[15]=A):A=e[15];const D=A;let I;e[16]===Symbol.for("react.memo_cache_sentinel")?(I={activationConstraint:{distance:8}},e[16]=I):I=e[16];let M;e[17]===Symbol.for("react.memo_cache_sentinel")?(M={activationConstraint:{delay:200,tolerance:6}},e[17]=M):M=e[17];const $=Ur(On(hu,I),On(fu,M));let E;e[18]!==f?(E=je=>{const{active:Ee,over:xe}=je;xe&&Ee.id!==xe.id&&f(String(Ee.id),String(xe.id))},e[18]=f,e[19]=E):E=e[19];const K=E,B=c.useRef(null);let O;e[20]===Symbol.for("react.memo_cache_sentinel")?(O={left:!1,right:!1},e[20]=O):O=e[20];const[T,k]=c.useState(O);let P;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const je=B.current;if(!je)return;const Ee=je.scrollLeft>2,xe=je.scrollLeft+je.clientWidth<je.scrollWidth-2;k(H=>H.left===Ee&&H.right===xe?H:{left:Ee,right:xe})},e[21]=P):P=e[21];const F=P;let q;e[22]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{F();const je=B.current;if(!je||!globalThis.ResizeObserver)return;const Ee=new ResizeObserver(F);return Ee.observe(je),()=>Ee.disconnect()},e[22]=q):q=e[22];let Q;e[23]!==S.length?(Q=[F,S.length],e[23]=S.length,e[24]=Q):Q=e[24],c.useEffect(q,Q);let Y;e[25]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>{B.current?.querySelector("[data-active-session-tab]")?.scrollIntoView({block:"nearest",inline:"nearest"})},e[25]=Y):Y=e[25];let ce;e[26]!==p?(ce=[p],e[26]=p,e[27]=ce):ce=e[27],c.useEffect(Y,ce);const X=T.left&&T.right?"linear-gradient(to right, transparent, black 24px, black calc(100% - 24px), transparent)":T.left?"linear-gradient(to right, transparent, black 24px)":T.right?"linear-gradient(to right, black calc(100% - 24px), transparent)":void 0;let oe;e[28]!==S?(oe=S.map(Hx),e[28]=S,e[29]=oe):oe=e[29];const te=oe;let he;e[30]!==p||e[31]!==S?(he=!p||!S.some(je=>je.id===p),e[30]=p,e[31]=S,e[32]=he):he=e[32];const _=he;let ie;e[33]!==a?(ie=a("header.sessionTabs.stripAria"),e[33]=a,e[34]=ie):ie=e[34];let ge;e[35]!==X?(ge=X?{maskImage:X,WebkitMaskImage:X}:void 0,e[35]=X,e[36]=ge):ge=e[36];let ae;e[37]===Symbol.for("react.memo_cache_sentinel")?(ae=[Tx],e[37]=ae):ae=e[37];let z;e[38]!==o||e[39]!==p||e[40]!==D||e[41]!==C||e[42]!==r||e[43]!==n||e[44]!==l||e[45]!==S?(z=S.map(je=>s.jsx(Mx,{tab:je,isActive:je.id===p,suppressControls:je.id===p&&l,onSelect:C,onClose:j,renderMenu:n,closeOtherTabs:D,onMenuOpenChangeComplete:r,children:je.id===p?o:null},je.id)),e[38]=o,e[39]=p,e[40]=D,e[41]=C,e[42]=r,e[43]=n,e[44]=l,e[45]=S,e[46]=z):z=e[46];let ne;e[47]!==z||e[48]!==te?(ne=s.jsx(Bo,{items:te,strategy:Wg,children:z}),e[47]=z,e[48]=te,e[49]=ne):ne=e[49];let ue;e[50]!==K||e[51]!==$||e[52]!==ne?(ue=s.jsx(Kr,{sensors:$,collisionDetection:Hr,modifiers:ae,onDragEnd:K,children:ne}),e[50]=K,e[51]=$,e[52]=ne,e[53]=ue):ue=e[53];let me;e[54]!==o||e[55]!==_?(me=_?s.jsx("div",{role:"tab","aria-selected":!0,className:"session-tab-slot flex h-7 w-44 shrink-0 items-center rounded-md bg-interactive-selection px-2","data-active":"true",children:s.jsx("div",{className:"min-w-0 flex-1",children:o})}):null,e[54]=o,e[55]=_,e[56]=me):me=e[56];let ke;e[57]!==ge||e[58]!==ue||e[59]!==me?(ke=s.jsxs("div",{ref:B,onScroll:F,className:"session-tabs-scroll flex min-w-0 flex-1 items-center gap-1.5 overflow-x-auto overscroll-x-contain",style:ge,children:[ue,me]}),e[57]=ge,e[58]=ue,e[59]=me,e[60]=ke):ke=e[60];let Te;return e[61]!==ie||e[62]!==ke?(Te=s.jsx("div",{className:"app-region-no-drag flex h-full min-w-0 flex-1 items-center",role:"tablist","aria-label":ie,children:ke}),e[61]=ie,e[62]=ke,e[63]=Te):Te=e[63],Te};function Bx(t){return t.stopPropagation()}function Fx(t){return t.stopPropagation()}function _x(t){return t.tabIds}function Lx(t){return t.ensureTab}function $x(t){return t.closeOtherTabs}function Wx(t){return t.reorderTabs}function zx(t){return t.currentSessionId}function Vx(t){return t.setCurrentSession}function Ux(t){return t.activeSessions}function Kx(t){If(t)}function Hx(t){return t.id}function Gx(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(ja(),{month:"short"}),r=e.getDate(),i=e.getFullYear(),o=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${i}, ${o}:${l}`}function qx(t){if(t.info.role==="user")return"";const e=typeof t.info.providerID=="string"?t.info.providerID.trim():"",n=typeof t.info.modelID=="string"?t.info.modelID.trim():"";return e&&n?`${e}/${n}`:n||e}function Qx(t){const e=t.info.role==="user"?"User":"Assistant",n=Gx(t.info.time?.created),r=qx(t),i=n&&r?`${n} (${r})`:n||r;return i?`**${e}**
|
|
3
|
+
|
|
4
|
+
*${i}*`:`**${e}**`}function Yx(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Nu(t){const e=Qx(t),n=Yx(t.parts).trim();return n?`${e}
|
|
5
|
+
|
|
6
|
+
${n}`:""}function Au(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",i=`${n} Sub-agent: ${t.title}${r}
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
`,o=t.records.map(Nu).filter(Boolean).join(`
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
`),l=[i+o];for(const a of t.children)l.push(Au(a,e+1));return l.join(`
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
`)}function Du(t,e,n){const r=e?.trim()||"Session",i=new Date().toISOString().split("T")[0],o=`# ${r}
|
|
19
|
+
|
|
20
|
+
*Exported on ${i}*
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
`,l=t.map(Nu).filter(Boolean).join(`
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
`);let a=o+l;if(n&&n.length>0){const u=n.map(d=>Au(d,1)).join(`
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
`);a+=`
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
`+u}return a}function Pu(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}async function Iu(t,e){const n=await Xm(e,t);if(n)return n;if(!Pn())return null;try{const r=await qo()?.vscode?.saveMarkdown?.({fileName:e,content:t});if(!r||r.saved!==!0)return null;const i=typeof r.path=="string"?r.path.trim():"";return i.length>0?i:null}catch{return null}}async function Xx(t){const e=qo()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Jm(t)?!0:fd(t)}function Jx(){return jd()}function Tu(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",i=new Date().toISOString().split("T")[0];return`${r}-${i}.md`}const Yi=(t,e)=>({success:t(e.success),failure:t(e.failure),sourceVerificationFailed:t("sessions.sidebar.session.moveToWorktree.sourceVerificationFailed"),applyChangesFailed:t("sessions.sidebar.session.moveToWorktree.applyChangesFailed"),changesMayBeInDestination:t("sessions.sidebar.session.moveToWorktree.changesMayBeInDestination")}),Wn=tr(()=>({pendingSessionIds:new Set,requestingSessionIds:new Set,confirmation:null})),Eu=t=>{const e=nt.c(2);let n;return e[0]!==t?(n=r=>r.pendingSessionIds.has(t)||r.requestingSessionIds.has(t),e[0]=t,e[1]=n):n=e[1],Wn(n)},Zx=()=>Wn(cb),Ru=()=>Wn.getState().confirmation,$a=t=>{Wn.setState(e=>e.confirmation===t?e:{...e,confirmation:t})},El=(t,e)=>{Wn.setState(n=>{if(n.pendingSessionIds.has(t)===e)return n;const r=new Set(n.pendingSessionIds);return e?r.add(t):r.delete(t),{...n,pendingSessionIds:r}})},cr=(t,e)=>{Wn.setState(n=>{if(n.requestingSessionIds.has(t)===e)return n;const r=new Set(n.requestingSessionIds);return e?r.add(t):r.delete(t),{...n,requestingSessionIds:r}})},eb="Unable to apply your changes in the destination directory",tb=t=>t.status===400&&t.message.includes(eb),sb=async(t,e)=>{try{const u=(await kd(t,{mode:"light"})).current?.trim();if(u)return u}catch{}const n=wt(t),r=wt(e)??e,i=et.getState().availableWorktreesByProject,l=(i.get(r)??i.get(e)??[]).find(a=>wt(a.path)===n)?.branch?.trim();if(l)return l;throw new Error("Unable to determine the current branch")},Rl=t=>{for(const e of t){const n=Ef(e.id);if(n==="unknown")throw new Error("Session status is unavailable");if(n==="active")throw new Error("Session is not idle")}};class Mu extends Error{changesMayBeInDestination;constructor(e,n,r){super(e,{cause:n}),this.name="IncompleteRollbackError",this.changesMayBeInDestination=r}}const nb=(t,e,n)=>{const r=e.map(({sessionId:i,error:o})=>`${i}: ${o.message}`).join(", ");return new Mu(`Session move partially failed and could not be fully rolled back: ${t.message}. Rollback failures: ${r}`,{moveError:t,rollbackFailures:e},n)},rb=async(t,e,n,r)=>{const i=[];for(const o of[...t].reverse()){if(Rf(o.id)){i.push({sessionId:o.id,error:new Error("Session is not idle")});continue}try{await Cd(o,n,e,!1),et.getState().setWorktreeMetadata(o.id,r.get(o.id)??null)}catch(l){i.push({sessionId:o.id,error:l instanceof Error?l:new Error(String(l))})}}return i};class Ou extends Error{constructor(e){super(e.message,{cause:e}),this.name="ChangesMayBeInDestinationError"}}const Ml=async(t,e,n)=>{try{await Nd(t,e,{deleteLocalBranch:!0})}catch{throw new Error(`Session move failed and the new worktree could not be removed: ${n.message}`)}throw n},Ol=async(t,e)=>{const n=e?[t,e]:[t];try{await ka(n)}catch(r){console.warn("[session-worktree-move] Failed to refresh moved sessions",r)}},Bu=async(t,e)=>{if(Wn.getState().pendingSessionIds.has(t.root.id))throw new Error("Session move already in progress");El(t.root.id,!0);try{const n=[...t.descendants,t.root],r=new Map(n.map(a=>[a.id,et.getState().getWorktreeMetadata(a.id)]));Rl(n);let i=null;const o=[];let l=!1;try{i=await e();for(const[a,u]of n.entries()){Rl(n.slice(a));const d=u.id===t.root.id&&t.moveChanges;try{await Cd(u,t.sourceDirectory,i.directory,d)}catch(h){throw d&&Tf(h)&&(l=!0),h}o.push(u),u.id!==t.root.id&&et.getState().setWorktreeMetadata(u.id,ll(i.metadata))}}catch(a){const u=a instanceof Error?a:new Error(String(a)),d=await rb(o,t.sourceDirectory,i?.directory??t.sourceDirectory,r);if(l&&await Ol(t.sourceDirectory,i?.directory),d.length>0)throw nb(u,d,l);if(l)throw new Ou(u);if(i?.onMoveFailure)return i.onMoveFailure(u);throw u}return et.getState().setWorktreeMetadata(t.root.id,ll(i.metadata)),await Ol(t.sourceDirectory,i.directory),i.directory}finally{El(t.root.id,!1)}},ob=async t=>{const e=wt(t.sourceDirectory)??t.sourceDirectory,n=wt(t.destination.path)??t.destination.path;if(e===n)throw new Error("Source and destination are the same");if(t.destination.worktreeStatus!=="ready")throw new Error("Destination worktree is not ready");return Bu(t,async()=>({directory:t.destination.path,metadata:t.destination}))},ib=async t=>Bu(t,async()=>{const e=Ii(t.sourceDirectory);if(!e)throw new Error("Unable to find the project for this session");const n=await Jo(t.sourceDirectory)?await sb(t.sourceDirectory,e.path):null,r=await Mf(e,n?{startRef:n}:{});try{await Of(r.path)}catch(i){const o=i instanceof Error?i:new Error(String(i));return Ml(e,r,o)}return{directory:r.path,metadata:r,onMoveFailure:async i=>Ml(e,r,i)}}),ab=(t,e,n)=>e instanceof Ou?t.changesMayBeInDestination:e instanceof Mu&&e.changesMayBeInDestination?`${e.message} ${t.changesMayBeInDestination}`:n&&tb(e)?t.applyChangesFailed:e.message,Xi=(t,e)=>{(t.kind==="existing"?ob({root:t.root,descendants:t.descendants,sourceDirectory:t.sourceDirectory,destination:t.destination,moveChanges:e}):ib({root:t.root,descendants:t.descendants,sourceDirectory:t.sourceDirectory,moveChanges:e})).then(()=>Re.success(t.messages.success)).catch(r=>{const i=r instanceof Error?r:new Error(String(r));Re.error(t.messages.failure,{description:ab(t.messages,i,e)})})},lb=()=>{const t=Ru();t&&(cr(t.intent.root.id,!1),$a(null))},Fu=t=>{const e=Ru();if(!e)return;const{intent:n}=e;$a(null),cr(n.root.id,!1),Xi(n,t)},Ji=t=>{const e=Wn.getState();e.confirmation||e.pendingSessionIds.has(t.root.id)||e.requestingSessionIds.has(t.root.id)||(cr(t.root.id,!0),(async()=>{try{if(!await Jo(t.sourceDirectory)){cr(t.root.id,!1),Xi(t,!1);return}const r=await kd(t.sourceDirectory);if(r.isClean){cr(t.root.id,!1),Xi(t,!1);return}const i=r.files.filter(o=>{const l=o.index.trim();return l!==""&&l!=="?"}).length;$a({intent:t,dirtyFileCount:r.files.length,stagedFileCount:i})}catch{Re.error(t.messages.failure,{description:t.messages.sourceVerificationFailed}),cr(t.root.id,!1)}})())};function cb(t){return t.confirmation}const Lo="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",db=c.memo(function(e){const n=nt.c(17),{visible:r,title:i,ariaLabel:o,onClick:l,className:a,Icon:u,iconClassName:d,pressed:h}=e,f=r===void 0?!0:r,p=h===void 0?!1:h;if(!f)return null;const g=a??Lo,w=p&&"bg-interactive-selection text-interactive-selection-foreground";let v;n[0]!==g||n[1]!==w?(v=Ie(g,w),n[0]=g,n[1]=w,n[2]=v):v=n[2];const x=d??"h-[18px] w-[18px]";let m;n[3]!==u||n[4]!==x?(m=s.jsx(R,{name:u,className:x}),n[3]=u,n[4]=x,n[5]=m):m=n[5];let b;n[6]!==o||n[7]!==l||n[8]!==p||n[9]!==v||n[10]!==m?(b=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,"aria-label":o,"aria-pressed":p,className:v,children:m})}),n[6]=o,n[7]=l,n[8]=p,n[9]=v,n[10]=m,n[11]=b):b=n[11];let y;n[12]!==i?(y=s.jsx(It,{children:s.jsx("p",{children:i})}),n[12]=i,n[13]=y):y=n[13];let S;return n[14]!==b||n[15]!==y?(S=s.jsxs(Dt,{children:[b,y]}),n[14]=b,n[15]=y,n[16]=S):S=n[16],S}),ub=c.memo(function(e){const n=nt.c(43),{isDesktopApp:r,currentInstanceLabel:i,currentInstanceIsLocal:o,isDesktopServicesOpen:l,setIsDesktopServicesOpen:a,refreshCurrentInstanceLabel:u,shortcutLabel:d,remoteUpdateInfo:h,remoteUpdateChecking:f,remoteUpdateError:p,onOpenRemoteUpdate:g}=e,{t:w}=Nt();let v;n[0]!==u||n[1]!==a?(v=$=>{a($),$&&u()},n[0]=u,n[1]=a,n[2]=v):v=n[2];let x;n[3]!==i||n[4]!==r||n[5]!==w?(x=r?w("header.services.openWithCurrent",{current:i}):w("header.services.open"),n[3]=i,n[4]=r,n[5]=w,n[6]=x):x=n[6];const m=r?"w-auto max-w-[20rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let b;n[7]!==m?(b=Ie(Lo,m),n[7]=m,n[8]=b):b=n[8];let y;n[9]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(R,{name:"server",className:"h-[18px] w-[18px]"}),n[9]=y):y=n[9];let S;n[10]!==i||n[11]!==r?(S=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[10]=i,n[11]=r,n[12]=S):S=n[12];let N;n[13]!==x||n[14]!==b||n[15]!==S?(N=s.jsx(Pt,{asChild:!0,children:s.jsx(Qs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":x,className:b,children:[y,S]})})}),n[13]=x,n[14]=b,n[15]=S,n[16]=N):N=n[16];let C;n[17]!==i||n[18]!==d||n[19]!==w?(C=w("header.services.tooltip.currentInstance",{current:i,toggle:d("toggle_services_menu")}),n[17]=i,n[18]=d,n[19]=w,n[20]=C):C=n[20];let j;n[21]!==C?(j=s.jsx(It,{children:s.jsx("p",{children:C})}),n[21]=C,n[22]=j):j=n[22];let A;n[23]!==N||n[24]!==j?(A=s.jsxs(Dt,{children:[N,j]}),n[23]=N,n[24]=j,n[25]=A):A=n[25];let D;n[26]!==o||n[27]!==r||n[28]!==l||n[29]!==g||n[30]!==f||n[31]!==p||n[32]!==h||n[33]!==a||n[34]!==w?(D=r?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:w("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:h?.available?w("header.services.remoteUpdate.available",{version:h.version||""}):f?w("header.services.remoteUpdate.checking"):p||w("header.services.remoteUpdate.upToDate")})]}),h?.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:g,children:w("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(Bf,{embedded:!0,open:l,onOpenChange:hb,onHostSwitched:()=>a(!1)})]}):null,n[26]=o,n[27]=r,n[28]=l,n[29]=g,n[30]=f,n[31]=p,n[32]=h,n[33]=a,n[34]=w,n[35]=D):D=n[35];let I;n[36]!==D?(I=s.jsx(Ys,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto p-0",children:D}),n[36]=D,n[37]=I):I=n[37];let M;return n[38]!==l||n[39]!==v||n[40]!==A||n[41]!==I?(M=s.jsxs(Xs,{open:l,onOpenChange:v,children:[A,I]}),n[38]=l,n[39]=v,n[40]=A,n[41]=I,n[42]=M):M=n[42],M}),mb=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),vn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Bl=t=>!t?.isOpen||!Array.isArray(t.tabs)||t.tabs.length===0?null:(t.tabs.find(n=>n.id===t.activeTabId)??t.tabs[t.tabs.length-1])?.mode??null,fb=()=>{Gs("ui.header.render");const{t}=Nt(),e=Pe(L=>L.isSidebarOpen),n=Pe(L=>L.openContextOverview),r=Pe(L=>L.closeContextPanel),i=Pe(L=>L.shortcutOverrides),o=Pe(L=>L.sessionTabsEnabled),l=Ht(L=>L.getCurrentModel),a=et(L=>L.getContextUsage),u=et(L=>!!L.newSessionDraft?.open),d=et(L=>L.currentSessionId),h=Ff(d??""),f=va(d??""),p=Eu(d??""),g=Ps(Zn(c.useCallback(L=>{if(!d)return null;const Le=[...L.activeSessions,...L.archivedSessions].find(jt=>jt.id===d);if(!Le)return null;const ot=Le;return{title:Le.title??null,directory:ot.directory??null,created:Le.time?.created??null,slug:ot.slug??null,shareUrl:Le.share?.url??null,parentId:Le.parentID??null}},[d]))),w=Vt(Zn(L=>{if(!L.activeProjectId)return null;const Le=L.projects.find(ot=>ot.id===L.activeProjectId);return Le?{id:Le.id,path:Le.path,label:Le.label}:null})),v=c.useMemo(()=>{if(!w)return null;const L=w.label?.trim();if(L)return L;const Le=w.path.split(/[\\/]/).filter(Boolean);return Le[Le.length-1]??null},[w]),x=ar(L=>L.loadSettings),{isMobile:m}=Ln(),b=c.useRef(null),[y,S]=c.useState(()=>typeof window>"u"?!1:xn()),N=c.useMemo(()=>Qo(),[]),C=Ad(),[j,A]=c.useState(!1),D=c.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),{usesFramelessChrome:I,side:M}=nu(),$=c.useMemo(()=>{if(typeof window>"u")return null;const L=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof L=="number"&&Number.isFinite(L)&&L>0)return L;if(typeof navigator>"u")return null;const Le=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Le)return null;const ot=Number.parseInt(Le[1],10),jt=Number.parseInt(Le[2],10);return Number.isNaN(ot)?null:ot===10?jt:ot},[]);xt.useEffect(()=>{typeof window>"u"||S(xn())},[]);const E=l(),K=E&&typeof E.limit=="object"&&E.limit!==null?E.limit:null,B=K&&typeof K.context=="number"?K.context:0,O=K&&typeof K.output=="number"?K.output:0,T=a(B,O),[k,P]=c.useState(null),F=!d||h;xt.useEffect(()=>{if(!d){P(L=>L===null?L:null);return}if(T&&T.totalTokens>0){P(L=>mb(L,T)?L:T);return}F&&P(L=>L===null?L:null)},[T,d,F]);const[q,Q]=c.useState(!1),[Y,ce]=c.useState("Local"),[X,oe]=c.useState(!0),[te,he]=c.useState(!1),[_,ie]=c.useState(null),[ge,ae]=c.useState(!1),[z,ne]=c.useState(null),ue=c.useMemo(()=>Pn(),[]),me=Pe(L=>L.workStatusPanelVisible),ke=Pe(L=>L.workStatusPanelEnabled),Te=Pe(L=>L.setWorkStatusPanelEnabled),je=Pe(L=>L.workStatusPanelFits),Ee=Pe(L=>L.workStatusOverlayOpen),xe=Pe(L=>L.setWorkStatusOverlayOpen),Ce=ke&&je||Ee,ve=c.useCallback(()=>{if(ke&&!je){xe(!Ee);return}Te(!ke)},[xe,Te,Ee,ke,je]),re=!ue&&!me&&!!k&&k.totalTokens>0,le=k&&k.contextLimit>0?Math.min(999,k.totalTokens/k.contextLimit*100):0,se=c.useCallback(async()=>{if(!(typeof window>"u"||!y))try{if(Go()){ce("Local"),oe(!0);return}oe(!1);const L=await hd(),Le=Zm(),ot=ef([tf(Le),...L.hosts]);if(ot.id===sf){ce("Local"),oe(!0);return}ce(pd(ot.label.trim()||"Instance"))}catch{ce("Local"),oe(!0)}},[y]);xt.useEffect(()=>(se(),Yo(()=>{se()})),[se]);const G=c.useCallback(async()=>{if(X){ie(null),ne(null);return}ae(!0),ne(null);try{const L=new URLSearchParams({appType:"web",instanceMode:"remote",reportUsage:"false"}),Le=await ds(`/api/openchamber/update-check?${L.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!Le.ok)throw new Error(`Server responded with ${Le.status}`);const ot=await Le.json();ie({available:ot.available??!1,version:ot.version,currentVersion:ot.currentVersion??"unknown",body:ot.body,nextSuggestedCheckInSec:typeof ot.nextSuggestedCheckInSec=="number"?ot.nextSuggestedCheckInSec:void 0,packageManager:ot.packageManager,updateCommand:ot.updateCommand})}catch(L){ie(null),ne(L instanceof Error?L.message:t("header.services.remoteUpdate.error"))}finally{ae(!1)}},[X,t]);c.useEffect(()=>{ie(null),ne(null),he(!1)},[X,Y]),c.useEffect(()=>{if(!y||X)return;const L=3e3,Le=3600*1e3;let ot=!1,jt=null;const Ct=Bt=>{jt=window.setTimeout(()=>{if(ot||typeof document<"u"&&document.visibilityState!=="visible"){Ct(Le);return}G().finally(()=>{ot||Ct(Le)})},Bt)};return Ct(L),()=>{ot=!0,jt!==null&&window.clearTimeout(jt)}},[G,X,Y,y]);const U=c.useCallback(()=>{if(_?.available){he(!0);return}G()},[G,_?.available]);_f(),c.useEffect(()=>{x()},[x]);const be=d?g??null:null,W=c.useRef(null),[Ne,Oe]=c.useState(0);c.useEffect(()=>{if(!d){W.current&&(W.current=null,Oe(jt=>jt+1));return}if(be){W.current={sessionId:d,session:be,expiresAt:Date.now()+2e3};return}const L=W.current;if(!L||L.sessionId!==d)return;const Le=L.expiresAt-Date.now();if(Le<=0){W.current=null,Oe(jt=>jt+1);return}const ot=window.setTimeout(()=>{W.current?.sessionId===d&&(W.current=null),Oe(jt=>jt+1)},Le);return()=>{window.clearTimeout(ot)}},[d,be]);const ye=(()=>{if(be)return be;if(!d)return null;const L=W.current;return L&&L.sessionId===d&&L.expiresAt>Date.now()?L.session:null})(),Fe=et(L=>d?L.worktreeMetadata.get(d)?.path??"":""),Ke=et(L=>d?L.worktreeMetadata.get(d)?.branch?.trim()??null:null),$e=Dd(L=>d?L.getAttachment(d):void 0),V=c.useMemo(()=>$e?Lf($e,{pending:t("gitView.empty.worktreeSetupInProgress"),missing:t("sessions.sidebar.group.worktreeMissing")}):null,[t,$e]),fe=c.useMemo(()=>$e?$e.legacy?"legacy":$e.degraded?"degraded":$e.worktreeStatus==="pending"?"pending":$e.worktreeStatus==="missing"?"missing":$e.worktreeStatus==="invalid"?"invalid":$e.attentionReason?"attention":null:null,[$e]),Me=c.useMemo(()=>vn(Fe||""),[Fe]),De=c.useMemo(()=>{const L=typeof ye?.directory=="string"?ye.directory:"";return vn(L||"")},[ye?.directory]),at=et(L=>L.newSessionDraft?.open?vn(L.newSessionDraft.bootstrapPendingDirectory??L.newSessionDraft.directoryOverride??""):""),Qe=et(L=>L.newSessionDraft.target),lt=et(L=>L.newSessionDraft.selectedProjectId),de=et(L=>L.currentSessionDirectory),J=es(L=>L.homeDirectory),Se=c.useMemo(()=>Me||De||at,[at,De,Me]),Ve=Pe(c.useCallback(L=>{const Le=vn(Se||"");return Le?Bl(L.contextPanelByDirectory[Le]):null},[Se])),He=et(L=>{const Le=vn(Me||De||"");if(!Le)return null;for(const ot of L.availableWorktreesByProject.values()){const Ct=ot.find(Bt=>vn(Bt.path)===Le)?.branch?.trim();if(Ct)return Ct}return null}),Ue=$f(Se||null)||Ke||He,st=u?Qe==="chat":Wf(De||de,J),ee=!st&&!me&&!!(v||Ue||!u&&fe),ze=c.useMemo(()=>{if(!d)return v??"OpenChamber";const L=ye?.title?.trim();return L&&L.length>0?L:"Untitled Session"},[v,ye?.title,d]),_e=Pd(Se||void 0,{bootstrap:!1}),pe=Id(),qe=et(L=>L.updateSessionTitle),tt=et(L=>L.shareSession),pt=et(L=>L.unshareSession),gt=et(L=>L.archiveSessions),Je=et(L=>L.deleteSessions),[St,Ze]=c.useState(!1),[vt,rt]=c.useState(!1),we=c.useRef(null),[ct,dt]=c.useState(""),[At,We]=c.useState(null),Xe=c.useRef(null),Tt=c.useCallback(()=>{d&&(dt(ye?.title?.trim()||ze),Ze(!0))},[ye?.title,d,ze]),ut=c.useRef(Tt);ut.current=Tt;const kt=c.useCallback(L=>{L&&(L.focus(),L.select())},[]);c.useEffect(()=>{if(rt(!1),We(null),d&&we.current===d){we.current=null,ut.current();return}Ze(!1),dt("")},[d]);const Rt=c.useCallback(async()=>{if(!d)return;const L=ct.trim();L&&L!==ye?.title?.trim()&&await qe(d,L),Ze(!1)},[ye?.title,d,ct,qe]);c.useEffect(()=>{if(!St)return;const L=Le=>{const ot=Le.target;(!ot||!Xe.current?.contains(ot))&&Rt()};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[St,Rt]);const ss=c.useCallback(L=>{L&&pn(L).then(Le=>{Re[Le.ok?"success":"error"](t(Le.ok?"sessions.sidebar.session.copyId.success":"sessions.sidebar.session.copyId.error"))}).catch(()=>Re.error(t("sessions.sidebar.session.copyId.error")))},[t]),Ut=c.useCallback(async L=>{if(!L)return;const Le=await tt(L);if(Le?.share?.url){const ot=await pn(Le.share.url);Re[ot.ok?"success":"warning"](t("sessions.sidebar.session.share.successTitle"),{description:t(ot.ok?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")});return}Re.error(t("sessions.sidebar.session.share.error"))},[tt,t]),Wt=c.useCallback(L=>{L&&pn(L).then(Le=>{Re[Le.ok?"success":"error"](t(Le.ok?"sessions.sidebar.session.menu.copied":"sessions.sidebar.session.share.copyUrlError"))}).catch(()=>Re.error(t("sessions.sidebar.session.share.copyUrlError")))},[t]),Qt=c.useCallback(async L=>{if(!L)return;const Le=await pt(L);Re[Le?"success":"error"](t(Le?"sessions.sidebar.session.unshare.success":"sessions.sidebar.session.unshare.error"))},[t,pt]),Kt=c.useCallback(async()=>{if(!d||!Se){Re.error(t("sessions.sidebar.session.export.nothingToExport"));return}try{await pe.loadCompleteHistory(d,Se)}catch{Re.error(t("sessions.sidebar.session.export.failedLoadHistory"));return}const L=zf(_e.getState(),d).list;if(L.length===0){Re.error(t("sessions.sidebar.session.export.nothingToExport"));return}const Le=Du(L,ye?.title??null),ot=Tu(ye?.title??null);await Iu(Le,ot)||Pu(Le,ot),Re.success(t("sessions.sidebar.session.export.success"))},[ye?.title,d,_e,Se,pe,t]),Ft=f?.type==="busy"||f?.type==="retry",$t=c.useCallback(()=>{if(!d||!De||Ft||p)return;const L=Ps.getState().activeSessions,Le=L.find(Ct=>Ct.id===d);if(!Le)return;const ot=[],jt=[d];for(let Ct=0;Ct<jt.length;Ct+=1){const Bt=jt[Ct];for(const os of L)os.parentID===Bt&&(ot.push(os),jt.push(os.id))}Ji({kind:"quick",root:Le,descendants:ot,sourceDirectory:De,messages:Yi(t,{success:"sessions.sidebar.session.moveToWorktree.success",failure:"sessions.sidebar.session.moveToWorktree.failed"})})},[d,Ft,p,De,t]),Be=c.useCallback(async()=>{if(!At)return;const L=Ps.getState().activeSessions,Le=[At.sessionId];for(let Bt=0;Bt<Le.length;Bt+=1){const os=Le[Bt];for(const Gt of L)Gt.parentID===os&&!Le.includes(Gt.id)&&Le.push(Gt.id)}const ot=At.action;if(We(null),(ot==="archive"?await gt(Le):await Je(Le)).failedIds.length>0){Re.error(t(ot==="archive"?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error"));return}Re.success(t(ot==="archive"?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"))},[gt,Je,At,t]),Ye=Pe(L=>L.isScheduledTasksDialogOpen),ft=Pe(L=>L.isArchivePageOpen),yt=Pe(L=>L.worktreesPageProjectId),ht=Pe(L=>L.isMultiRunLauncherOpen),mt=Vt(L=>{if(!yt)return null;const Le=L.projects.find(ot=>ot.id===yt);return Le?.label?.trim()||Le?.path?.split("/").pop()||null}),_t=c.useMemo(()=>Ye?{title:t("sessions.scheduledTasks.dialog.title"),subtitle:null}:ft?{title:t("sessions.archivePage.title"),subtitle:null}:yt?{title:t("sessions.worktreesPage.title",{project:mt??""}),subtitle:null}:ht?{title:t("sessions.sidebar.header.actions.newMultiRun"),subtitle:null}:null,[ft,ht,Ye,t,yt,mt]),Jt=c.useMemo(()=>vn(Se||w?.path||""),[w?.path,Se]),Yt=Ix(),Ns=Ca(L=>L.planModeEnabled),Xt=et(L=>L.isSessionPlanAvailable),zs=Ns&&d?Xt(d):!1,Js=c.useRef("");c.useEffect(()=>{if(!Ns||!d)return;const L=`${d||"none"}:${De||"none"}:${ye?.created||0}:${ye?.slug||"none"}`;Js.current!==L&&(Js.current=L)},[Ns,zs,ye?.slug,ye?.created,d,De]);const rs=c.useCallback(()=>{Mn("desktop_open_draft_mini_chat_window",{directory:st?"":at,projectId:st?null:lt,apiBaseUrl:An(),clientToken:Wr()}).catch(L=>{console.warn("[header] failed to open draft mini chat window",L)})},[at,lt,st]),Vs=c.useCallback(()=>{if(u){rs();return}d&&Mn("desktop_open_session_mini_chat_window",{sessionId:d,directory:De||vn(de||"")||Me,apiBaseUrl:An(),clientToken:Wr()}).catch(L=>{console.warn("[header] failed to open session mini chat window",L)})},[d,rs,u,de,De,Me]),Es=c.useCallback(()=>{const L=vn(Se||"");if(!L)return;const Le=Pe.getState().contextPanelByDirectory[L];if(Bl(Le)==="context"){r(L);return}n(L)},[r,n,Se]),ln=Ve==="context",gs=Lo,vs=c.useMemo(()=>y&&D&&!j?"5.5rem":C?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!y||I)&&!ue?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[y,j,D,C,ue,I]);xt.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",vs)},[vs]);const Zs=e?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",Rs=e?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";xt.useEffect(()=>{if(!y||!D){A(!1);return}let L=!1;const Le=async()=>{try{const jt=await Mn("desktop_is_window_fullscreen");L||A(jt===!0)}catch{L||A(!1)}},ot=()=>{Le()};return Le(),window.addEventListener("openchamber:window-resized",ot),()=>{L=!0,window.removeEventListener("openchamber:window-resized",ot)}},[y,D]);const As=c.useMemo(()=>!y||!D||$===null?"":$>=26?"h-12":$<=15?"h-14":"",[y,D,$]),Ds=c.useMemo(()=>{if(!(y&&!I||ue)&&!(I&&M==="right"))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))"}},[y,ue,I,M]),js=c.useCallback(()=>{if(typeof document>"u")return;const L=b.current?.getBoundingClientRect().height;L&&document.documentElement.style.setProperty("--oc-header-height",`${L}px`)},[]);xt.useEffect(()=>{if(typeof window>"u")return;js();const L=b.current;if(!L||typeof ResizeObserver>"u")return()=>{};let Le=0;const ot=()=>{Le||(Le=requestAnimationFrame(()=>{Le=0,js()}))},jt=new ResizeObserver(ot);return jt.observe(L),window.addEventListener("resize",ot),window.addEventListener("orientationchange",ot),()=>{Le&&cancelAnimationFrame(Le),jt.disconnect(),window.removeEventListener("resize",ot),window.removeEventListener("orientationchange",ot)}},[js]),xt.useEffect(()=>{js()},[js,m,As]);const Mt=c.useCallback(async L=>{const Le=L.target;Le.closest(".app-region-no-drag")||Le.closest("button, a, input, select, textarea")||L.button===0&&y&&await nf()},[y]),Lt=c.useCallback(L=>Qn(Jr(L,i)),[i]);Vf({rename_current_session:()=>{if(!d||m)return!1;Tt()},toggle_services_menu:()=>{if(q){Q(!1);return}Q(!0),se()}});const ns=s.jsxs(s.Fragment,{children:[Yt?s.jsx(Dx,{projectRef:Yt.projectRef,directory:Yt.directory,className:"mr-2"}):null,s.jsx(sx,{directory:Jt,className:"mr-1"}),y?s.jsx(ub,{isDesktopApp:y,currentInstanceLabel:Y,currentInstanceIsLocal:X,isDesktopServicesOpen:q,setIsDesktopServicesOpen:Q,refreshCurrentInstanceLabel:se,shortcutLabel:Lt,remoteUpdateInfo:_,remoteUpdateChecking:ge,remoteUpdateError:z,onOpenRemoteUpdate:U}):null]}),us=N&&(u||!!d),xs=c.useCallback(({session:L,isActive:Le,select:ot,closeOtherTabs:jt,components:Ct})=>{const{Item:Bt,Separator:os}=Ct,Gt=L.share?.url??null,en=Le&&!ue&&!st&&ye&&!ye.parentId;return s.jsxs(s.Fragment,{children:[s.jsxs(Bt,{onClick:()=>{Le||ot(),we.current=L.id},children:[s.jsx(R,{name:"pencil-ai",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.rename")]}),s.jsxs(Bt,{onClick:()=>ss(L.id),children:[s.jsx(R,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyId")]}),s.jsx(os,{}),Gt?s.jsxs(s.Fragment,{children:[s.jsxs(Bt,{onClick:()=>Wt(Gt),children:[s.jsx(R,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(Bt,{onClick:()=>{Qt(L.id)},children:[s.jsx(R,{name:"link-unlink-m",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Bt,{onClick:()=>{Ut(L.id)},children:[s.jsx(R,{name:"share-2",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.share")]}),Le?s.jsxs(Bt,{onClick:()=>{Kt()},children:[s.jsx(R,{name:"download",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.exportMarkdown")]}):null,en?s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(Bt,{disabled:!De||Ft||p,onClick:$t,className:"w-full",children:[s.jsx(R,{name:"folder-shared",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(It,{side:"right",className:"max-w-72",children:t(p?"sessions.sidebar.session.moveToWorktree.tooltipMoving":Ft?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(os,{}),s.jsxs(Bt,{onClick:jt,children:[s.jsx(R,{name:"close-circle",className:"mr-2 size-4"}),t("header.sessionTabs.closeOtherTabs")]}),s.jsx(os,{}),s.jsxs(Bt,{onClick:()=>We({action:"archive",sessionId:L.id}),children:[s.jsx(R,{name:"inbox-archive",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.archive")]}),s.jsxs(Bt,{className:"text-destructive focus:text-destructive",onClick:()=>We({action:"delete",sessionId:L.id}),children:[s.jsx(R,{name:"delete-bin",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.delete")]})]})},[ss,Wt,ye,Kt,st,Ft,p,ue,$t,De,Ut,t,Qt]),Z=()=>s.jsxs("div",{onMouseDown:Mt,className:Ie("app-region-drag relative flex h-12 select-none items-center",I&&M==="right"?"pr-0":"pr-3",As),style:Ds,role:"tablist","aria-label":t("header.navigation.mainAria"),children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:Zs}}),s.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:Rs}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[_t?s.jsxs("div",{className:"mr-3 flex min-w-0 flex-col items-start px-1 py-0.5 -my-0.5 text-left",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:_t.title}),_t.subtitle?s.jsx("span",{className:"truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75 max-w-full",children:_t.subtitle}):null]}):ue||!o?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:[e?null:s.jsx(Cl,{align:"start",children:s.jsx("button",{type:"button",className:gs,"aria-label":t("sessions.switcher.openAria"),children:s.jsx(R,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsxs("div",{className:"flex min-w-0 flex-col justify-center px-1",children:[St?s.jsxs("form",{ref:Xe,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onPointerDown:L=>L.stopPropagation(),onSubmit:L=>{L.preventDefault(),Rt()},children:[s.jsx("input",{ref:kt,value:ct,onChange:L=>dt(L.target.value),onKeyDown:L=>{L.stopPropagation(),L.key==="Escape"&&Ze(!1)},placeholder:t("sessions.sidebar.session.menu.rename"),className:"min-w-0 flex-1 bg-transparent typography-ui-label text-[14px] font-normal leading-tight outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"submit","aria-label":t("sessions.sidebar.session.rename.save"),title:t("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>Ze(!1),"aria-label":t("sessions.sidebar.session.rename.cancel"),title:t("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"size-4"})})]}):s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:u?t("sessions.switcher.draftTitle"):ze}),ee?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[v?s.jsx("span",{className:"truncate",children:v}):null,Ue?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(R,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:Ue})]}):null,!u&&fe?s.jsxs("span",{className:Ie("inline-flex min-w-0 items-center gap-0.5",fe==="attention"||fe==="invalid"||fe==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(R,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:V})]}):null]}):null]}),s.jsx("div",{className:Ie("flex h-[18px] shrink-0 items-center justify-center",ee?"self-start":"self-center"),children:d&&!u&&!St?s.jsxs(Xs,{open:vt,onOpenChange:rt,onOpenChangeComplete:L=>{!L&&we.current&&we.current===d&&(we.current=null,Tt())},children:[s.jsx(Qs,{asChild:!0,children:s.jsx(bt,{variant:"ghost",size:"xs",className:"h-[18px] w-6 px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-label":t("header.sessionActions.openAria"),children:s.jsx(R,{name:"more",className:"size-4"})})}),s.jsxs(Ys,{align:"end",className:"min-w-[190px]",children:[s.jsxs(zt,{onClick:()=>{we.current=d},children:[s.jsx(R,{name:"pencil-ai",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.rename")]}),s.jsxs(zt,{onClick:()=>d&&ss(d),children:[s.jsx(R,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyId")]}),s.jsx(Os,{}),ye?.shareUrl?s.jsxs(s.Fragment,{children:[s.jsxs(zt,{onClick:()=>Wt(ye?.shareUrl),children:[s.jsx(R,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(zt,{onClick:()=>{d&&Qt(d)},children:[s.jsx(R,{name:"link-unlink-m",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(zt,{onClick:()=>{d&&Ut(d)},children:[s.jsx(R,{name:"share-2",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.share")]}),s.jsxs(zt,{onClick:()=>{Kt()},children:[s.jsx(R,{name:"download",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.exportMarkdown")]}),!ue&&!st&&ye&&!ye.parentId?s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(zt,{disabled:!De||Ft||p,onClick:$t,className:"w-full",children:[s.jsx(R,{name:"folder-shared",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(It,{side:"right",className:"max-w-72",children:t(p?"sessions.sidebar.session.moveToWorktree.tooltipMoving":Ft?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(Os,{}),s.jsxs(zt,{onClick:()=>{d&&We({action:"archive",sessionId:d})},children:[s.jsx(R,{name:"inbox-archive",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.archive")]}),s.jsxs(zt,{className:"text-destructive focus:text-destructive",onClick:()=>{d&&We({action:"delete",sessionId:d})},children:[s.jsx(R,{name:"delete-bin",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.delete")]})]})]}):null})]}):s.jsxs("div",{className:"app-region-no-drag flex h-full min-w-0 flex-1 items-center gap-0.5 text-left",children:[e?null:s.jsx(Cl,{align:"start",children:s.jsx("button",{type:"button",className:gs,"aria-label":t("sessions.switcher.openAria"),children:s.jsx(R,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsx(Ox,{renderMenu:xs,suppressActiveTabControls:St,onMenuOpenChangeComplete:L=>{!L&&we.current&&we.current===d&&(we.current=null,Tt())},children:s.jsx("div",{className:"flex min-w-0 flex-col justify-center",children:St?s.jsxs("form",{ref:Xe,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onPointerDown:L=>L.stopPropagation(),onSubmit:L=>{L.preventDefault(),Rt()},children:[s.jsx("input",{ref:kt,value:ct,onChange:L=>dt(L.target.value),onKeyDown:L=>{L.stopPropagation(),L.key==="Escape"&&Ze(!1)},placeholder:t("sessions.sidebar.session.menu.rename"),className:"min-w-0 flex-1 bg-transparent text-[13px] font-medium leading-4 outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"submit","aria-label":t("sessions.sidebar.session.rename.save"),title:t("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>Ze(!1),"aria-label":t("sessions.sidebar.session.rename.cancel"),title:t("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"size-4"})})]}):s.jsx("span",{className:"block overflow-hidden whitespace-nowrap text-[13px] font-medium leading-4 text-foreground max-w-full",children:u?t("sessions.switcher.draftTitle"):ze})})})]}),_t||ue||!o?s.jsx("div",{className:"flex-1"}):null,s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[re&&k?s.jsx(Xp,{totalTokens:k.totalTokens,percentage:le,colorPercentage:k.percentage,contextLimit:k.contextLimit,outputLimit:k.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:Es,pressed:ln,className:us?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,s.jsx(db,{visible:us,title:t(u?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:t(u?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:Vs,className:Ie(gs,"mr-1"),Icon:"picture-in-picture-2"}),ue?null:s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button","data-work-status-toggle":"true","aria-pressed":Ce,"aria-label":t("header.workStatusPanel.toggleAria"),onClick:ve,className:Ie(Lo,"mr-1",Ce?"text-foreground":"text-muted-foreground/50"),children:s.jsx(R,{name:"list-indefinite",className:"h-[18px] w-[18px]"})})}),s.jsx(It,{side:"bottom",children:t(ke&&!je?Ee?"header.workStatusPanel.hide":"header.workStatusPanel.showOverlay":ke?"header.workStatusPanel.hide":"header.workStatusPanel.show")})]}),ns,s.jsx(ru,{visible:I&&M==="right",position:"right"})]})]})]});return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:b,className:"header-safe-area relative z-10 bg-background",style:{"--padding-scale":"1"},children:Z()}),s.jsx(ws,{open:At!==null,onOpenChange:L=>{L||We(null)},children:s.jsxs(Ss,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Ws,{children:[s.jsx(Is,{children:At?.action==="delete"?t("sessions.sidebar.dialogs.deleteSession.title"):t("sessions.sidebar.dialogs.archiveSession.title")}),s.jsx(Ts,{children:At?.action==="delete"?t("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:ze}):t("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:ze})})]}),s.jsxs(bn,{children:[s.jsx(bt,{variant:"outline",size:"sm",onClick:()=>We(null),children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(bt,{variant:"destructive",size:"sm",onClick:()=>{Be()},children:At?.action==="delete"?t("sessions.sidebar.bulkActions.delete"):t("sessions.sidebar.bulkActions.archive")})]})]})}),s.jsx(ou,{open:te,onOpenChange:he,info:_,downloading:!1,downloaded:!1,progress:null,error:z,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function hb(){}const Fl=280,_l=280,Ll=500,pb=({isOpen:t,isMobile:e,children:n,className:r,topBar:i})=>{const{t:o}=Nt(),l=Pe(j=>j.sidebarWidth),a=Pe(j=>j.setSidebarWidth),[u,d]=c.useState(!1),h=c.useRef(0),f=c.useRef(l||Fl),p=c.useRef(null),g=c.useRef(null),w=c.useRef(null),v=c.useCallback(j=>Math.min(Ll,Math.max(_l,j)),[]),x=c.useCallback(j=>{const A=w.current;A&&(A.style.width=`${j}px`,A.style.minWidth=`${j}px`,A.style.maxWidth=`${j}px`,A.style.setProperty("--oc-left-sidebar-width",`${j}px`))},[]);if(c.useEffect(()=>{e&&u&&d(!1)},[e,u]),c.useEffect(()=>{u||(p.current=null,g.current=null)},[u]),e)return null;const m=Math.min(Ll,Math.max(_l,l||Fl)),b=t?m:0,y=j=>{if(t){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}g.current=j.pointerId,d(!0),h.current=j.clientX,f.current=b,p.current=b,x(b),j.preventDefault()}},S=j=>{if(e||!u||g.current!==j.pointerId)return;const A=j.clientX-h.current,D=v(f.current+A);p.current!==D&&(p.current=D,x(D))},N=j=>{if(g.current!==j.pointerId||e)return;try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}const A=v(p.current??b);g.current=null,p.current=null,d(!1),a(A)},C=u?p.current??b:b;return s.jsxs("aside",{ref:w,className:Ie("relative flex h-full overflow-hidden border-r border-border will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-r-0",r),style:{width:`${C}px`,minWidth:`${C}px`,maxWidth:`${C}px`,"--oc-left-sidebar-width":`${u?C:m}px`,overflowX:"clip",transitionProperty:u?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||b===0,children:[t&&s.jsx("div",{className:"pointer-events-none absolute inset-0 z-30 shadow-[inset_-2px_0_10px_-2px_rgb(0_0_0_/_0.06)]","aria-hidden":"true"}),t&&s.jsx("div",{className:Ie("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",u&&"bg-[var(--interactive-border)]"),onPointerDown:y,onPointerMove:S,onPointerUp:N,onPointerCancel:N,role:"separator","aria-orientation":"vertical","aria-label":o("sidebar.resize.leftPanelAria")}),s.jsxs("div",{className:Ie("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",u&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[i,s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx(Hs,{children:n})})]})]})},gb=()=>{const t=nt.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={height:"var(--oc-header-height, 3rem)"},t[0]=e):e=t[0];let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("div",{className:"app-region-drag shrink-0",style:{width:"var(--oc-titlebar-left-inset, 0.75rem)"}}),t[1]=n):n=t[1];let r;return t[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs("div",{"aria-hidden":!0,className:"flex shrink-0",style:e,children:[n,s.jsx("div",{className:"app-region-no-drag shrink-0",style:{width:"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)"}}),s.jsx("div",{className:"app-region-drag flex-1"})]}),t[2]=r):r=t[2],r},$l="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",xb=()=>{const t=nt.c(32),{t:e}=Nt(),n=Pe(bb),r=Pe(yb),i=c.useRef(null),o=Qn(Jr("toggle_sidebar",r)),{usesFramelessChrome:l,side:a}=nu(),u=Sb;let d,h;t[0]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{if(typeof document>"u")return;const $=i.current;if(!$)return;const E=()=>{const B=Math.max($.getBoundingClientRect().width,$.scrollWidth);document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(B)}px`)};if(E(),typeof ResizeObserver>"u")return;const K=new ResizeObserver(E);return K.observe($),()=>{K.disconnect()}},h=[],t[0]=d,t[1]=h):(d=t[0],h=t[1]),c.useEffect(d,h);const f="app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2";let p;t[2]===Symbol.for("react.memo_cache_sentinel")?(p={height:"var(--oc-header-height, 3rem)",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},t[2]=p):p=t[2];const g="flex items-center gap-2";let w;t[3]!==l||t[4]!==a?(w=l&&a==="left"?s.jsx(ru,{visible:!0,position:"left"}):null,t[3]=l,t[4]=a,t[5]=w):w=t[5];let v;t[6]!==e||t[7]!==l?(v=l?s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,"aria-label":e("header.actions.openAppMenuAria"),className:Ie($l,"shrink-0"),children:s.jsx(R,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(It,{children:s.jsx("p",{children:e("header.actions.openAppMenu")})})]}):null,t[6]=e,t[7]=l,t[8]=v):v=t[8];const x=Dt;let m;t[9]!==e?(m=e("header.actions.openSessionsAria"),t[9]=e,t[10]=m):m=t[10];let b,y;t[11]===Symbol.for("react.memo_cache_sentinel")?(b=Ie($l,"shrink-0"),y=s.jsx(R,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[11]=b,t[12]=y):(b=t[11],y=t[12]);let S;t[13]!==m||t[14]!==n?(S=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":m,className:b,children:y})}),t[13]=m,t[14]=n,t[15]=S):S=t[15];const N=It,C=e("header.actions.openSessionsWithShortcut",{shortcut:o});let j;t[16]!==C?(j=s.jsx("p",{children:C}),t[16]=C,t[17]=j):j=t[17];let A;t[18]!==N||t[19]!==j?(A=s.jsx(N,{children:j}),t[18]=N,t[19]=j,t[20]=A):A=t[20];let D;t[21]!==x||t[22]!==S||t[23]!==A?(D=s.jsxs(x,{children:[S,A]}),t[21]=x,t[22]=S,t[23]=A,t[24]=D):D=t[24];let I;t[25]!==D||t[26]!==w||t[27]!==v?(I=s.jsxs("div",{ref:i,className:g,children:[w,v,D]}),t[25]=D,t[26]=w,t[27]=v,t[28]=I):I=t[28];let M;return t[29]!==I||t[30]!==p?(M=s.jsx("div",{className:f,style:p,children:I}),t[29]=I,t[30]=p,t[31]=M):M=t[31],M};function bb(t){return t.toggleSidebar}function yb(t){return t.shortcutOverrides}function wb(t){console.warn("[titlebar] failed to open app menu",t)}function Sb(t){const e=t.currentTarget.getBoundingClientRect();Mn("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(wb)}function _u(t){const e=nt.c(5),{className:n}=t,i=`relative inline-block overflow-hidden rounded-[2px] ${n===void 0?"h-5 w-5":n}`;let o,l,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("span",{className:"absolute left-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-error)]/25"}),l=s.jsx("span",{className:"absolute right-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-success)]/25"}),a=s.jsx(R,{name:"layout-column",className:"absolute inset-0 h-full w-full"}),e[0]=o,e[1]=l,e[2]=a):(o=e[0],l=e[1],a=e[2]);let u;return e[3]!==i?(u=s.jsxs("span",{"aria-hidden":"true",className:i,children:[o,l,a]}),e[3]=i,e[4]=u):u=e[4],u}const Wl=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function vb(t,e,n){const r=nt.c(5),[i,o]=c.useState();let l,a;return r[0]!==n||r[1]!==t||r[2]!==e?(l=()=>{if(e){o(void 0);return}if(!t){o(void 0);return}o(void 0);let u=!1;return(async()=>{const[d,h]=await Promise.all([Uf(t),Kf(t)]).catch(jb);if(u)return;const f=Wl(d),p=Wl(h);if(!f||!p||p===f)return;const g=n||"",w=p.split("/").filter(Boolean).pop()||p;o({source:"sdk",path:p,projectDirectory:f,branch:g,label:g||w,name:w,worktreeRoot:p,worktreeStatus:"ready",headState:g?"branch":"unborn",worktreeSource:"existing"})})(),()=>{u=!0}},a=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=l,r[4]=a):(l=r[3],a=r[4]),c.useEffect(l,a),e??i}function jb(){return["",""]}const zl="flex h-6 w-6 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",kb=async(t,e)=>{if(t)return t.authActivate(e);const n=await ds("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:e})}),r=await n.json().catch(()=>null);if(!n.ok||!r)throw new Error(r?.error||n.statusText);return r},Vl=({className:t})=>{const{t:e}=Nt(),{github:n}=wn(),r=Dn(g=>g.status),i=Dn(g=>g.setStatus),[o,l]=c.useState(!1),a=c.useCallback(async g=>{if(!(!g||o)){l(!0);try{i(await kb(n,g))}catch(w){console.error("Failed to switch GitHub account:",w)}finally{l(!1)}}},[n,o,i]);if(!r?.connected)return null;const u=r.user?.login??null,d=r.user?.avatarUrl??null,h=r.accounts??[],f=u?e("header.github.connectedWithLogin",{login:u}):e("header.github.connected"),p=d?s.jsx("img",{src:d,alt:u?e("header.github.avatarWithLogin",{login:u}):e("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(R,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"});return h.length<=1?s.jsx("div",{className:Ie(zl,t),title:f,children:p}):s.jsxs(Xs,{children:[s.jsx(Qs,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie(zl,"p-0 hover:ring-2 hover:ring-primary/40 disabled:opacity-50",t),title:f,disabled:o,children:p})}),s.jsxs(Ys,{align:"end",className:"w-64",children:[s.jsx(yo,{className:"typography-ui-header font-semibold text-foreground",children:e("header.github.accountsTitle")}),s.jsx(Os,{}),h.map(g=>{const w=g.user,v=!!g.current,x=g.source==="gh-cli"?e("header.github.accountSource.cli"):e("header.github.accountSource.oauth");return s.jsxs(zt,{className:"gap-2",disabled:o,onSelect:()=>{v||a(g.id)},children:[w?.avatarUrl?s.jsx("img",{src:w.avatarUrl,alt:w.login?e("header.github.avatarWithLogin",{login:w.login}):e("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(R,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:w?.name?.trim()||w?.login||"GitHub"}),w?.login?s.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:w.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:x})]}):null]}),v?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]},g.id)})]})]})};class ri extends Error{code;model;requiredChars;availableChars;constructor(e,n={}){super(e),this.name="WalkthroughError",this.code=n.code,this.model=n.model,this.requiredChars=n.requiredChars,this.availableChars=n.availableChars}}const oi="/api/walkthrough",Lu=t=>/^application\/(?:[\w.+-]+\+)?json\b/i.test(t.headers.get("content-type")??""),$u=()=>new ri("This OpenChamber server has no walkthrough API",{code:"server-unsupported"}),Cb=t=>!Lu(t)&&(t.ok||t.status===404),Wa=async(t,e)=>{if(Cb(t))throw $u();const n=await t.json().catch(()=>null);throw new ri(typeof n?.error=="string"?n.error:e,{code:typeof n?.code=="string"?n.code:void 0,model:n?.model??void 0,requiredChars:typeof n?.requiredChars=="number"?n.requiredChars:void 0,availableChars:typeof n?.availableChars=="number"?n.availableChars:void 0})},Wu=async t=>{if(!Lu(t))throw $u();try{return await t.json()}catch{throw new ri("The server returned a malformed walkthrough response")}};async function Nb(t,e,n={}){const r=await ds(oi,{query:{directory:t,source:JSON.stringify(e),...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}},signal:n.signal});return r.ok?Wu(r):Wa(r,"Failed to load walkthrough")}async function Ab(t,e,n={}){const r=await ds(`${oi}/generate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e,force:n.force===!0,...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}}),signal:n.signal});return r.ok?Wu(r):Wa(r,"Failed to generate walkthrough")}async function Db(t,e){const n=await ds(`${oi}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e})});n.ok||await Wa(n,"Failed to cancel walkthrough generation")}async function Pb(t,e,n){const r=await ds(`${oi}/progress`,{query:{directory:t,source:JSON.stringify(e)},signal:n});if(!r.ok)return null;const i=await r.json().catch(()=>null);return typeof i?.stage=="string"?i.stage:null}const Nr={status:"idle",stage:null,result:null,readiness:null,error:null},Ib=t=>t.kind==="working-tree"?`working-tree:${t.scope}`:t.kind==="branch"?`branch:${t.baseRef}...${t.headRef}`:`pr:${t.number}`,In=(t,e)=>`${ps()}\0${t}\0${Ib(e)}`,Ul=t=>t instanceof ri?{message:t.message,code:t.code,model:t.model,requiredChars:t.requiredChars,availableChars:t.availableChars}:{message:t instanceof Error?t.message:"Something went wrong"},nn=new Map,Ar=new Map,Tb=1e3,Eb=tr()(wu((t,e)=>({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{},selectLanguage:(n,r,i)=>{const o=In(n,r);t(l=>{const a={...l.selectedLanguage};return i?a[o]=i:delete a[o],{selectedLanguage:a}})},getSelectedLanguage:(n,r)=>e().selectedLanguage[In(n,r)],selectModel:(n,r,i)=>{const o=In(n,r);t(l=>{const a={...l.selectedModel};return i?a[o]=i:delete a[o],{selectedModel:a}})},getSelectedModel:(n,r)=>e().selectedModel[In(n,r)],requestSource:(n,r)=>{t(i=>({requestedSource:{...i.requestedSource,[n]:r}}))},clearRequestedSource:n=>{t(r=>{if(!r.requestedSource[n])return r;const i={...r.requestedSource};return delete i[n],{requestedSource:i}})},getEntry:(n,r)=>e().entries[In(n,r)]??Nr,load:async(n,r,i={})=>{if(!n)return;const o=In(n,r);if(e().entries[o]?.status==="generating")return;nn.get(o)?.abort();const a=new AbortController;nn.set(o,a),t(u=>({entries:{...u.entries,[o]:{...u.entries[o]??Nr,status:"loading",error:null}}}));try{const u=await Nb(n,r,{model:e().selectedModel[o],language:i.language,signal:a.signal});if(a.signal.aborted)return;t(d=>({entries:{...d.entries,[o]:{status:"ready",stage:null,result:u,readiness:u.readiness??null,error:null}}})),u.generating&&e().generate(n,r,{language:i.language})}catch(u){if(a.signal.aborted)return;t(d=>({entries:{...d.entries,[o]:{...d.entries[o]??Nr,status:"error",stage:null,error:Ul(u)}}}))}finally{nn.get(o)===a&&nn.delete(o)}},generate:async(n,r,i={})=>{if(!n)return;const o=In(n,r);nn.get(o)?.abort();const l=new AbortController;nn.set(o,l),t(u=>({entries:{...u.entries,[o]:{...u.entries[o]??Nr,status:"generating",stage:"collecting",error:null}}}));const a=()=>{const u=Ar.get(o);u!==void 0&&(clearInterval(u),Ar.delete(o))};a(),Ar.set(o,setInterval(()=>{Pb(n,r).then(u=>{!u||l.signal.aborted||t(d=>{const h=d.entries[o];return!h||h.status!=="generating"||h.stage===u?d:{entries:{...d.entries,[o]:{...h,stage:u}}}})}).catch(()=>{})},Tb));try{const u=await Ab(n,r,{force:i.force,model:e().selectedModel[o],language:i.language,signal:l.signal});if(l.signal.aborted)return;t(d=>({entries:{...d.entries,[o]:{status:"ready",stage:null,result:u,readiness:d.entries[o]?.readiness??null,error:null}}}))}catch(u){if(l.signal.aborted)return;t(d=>({entries:{...d.entries,[o]:{...d.entries[o]??Nr,status:"error",stage:null,error:Ul(u)}}}))}finally{a(),nn.get(o)===l&&nn.delete(o)}},cancel:(n,r)=>{const i=In(n,r);Db(n,r).catch(()=>{}),nn.get(i)?.abort(),nn.delete(i),t(o=>{const l=o.entries[i];return l?{entries:{...o.entries,[i]:{...l,status:l.result?"ready":"idle",stage:null,error:null}}}:o})},reset:()=>{for(const n of nn.values())n.abort();nn.clear();for(const n of Ar.values())clearInterval(n);Ar.clear(),t({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{}})}}),{name:"walkthrough-store"})),Rb="border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)] hover:text-[var(--status-info)]",Mb=3e4,Kl=20,zu=(t,e)=>JSON.stringify([ps(),t,e]),Ob=t=>{try{const e=JSON.parse(t);if(!Array.isArray(e)||e.length!==3)return null;const[n,r,i]=e;return typeof n!="string"||typeof r!="string"||typeof i!="number"?null:{runtimeKey:n,directory:r,number:i}}catch{return null}},Hl=()=>({result:null,hasCheckDetails:!1,fetchedAt:0,isLoading:!1,error:null}),no=new Map,Bb=t=>{const e=Object.entries(t);return e.length<=Kl?t:Object.fromEntries(e.sort(([,n],[,r])=>r.fetchedAt-n.fetchedAt).slice(0,Kl))},Gl=tr()((t,e)=>({entries:{},ensure:async(n,r,i,o)=>{const l=zu(r,i),a=o?.includeCheckDetails??!1,u=e().entries[l],d=u&&u.result&&Date.now()-u.fetchedAt<Mb&&(u.hasCheckDetails||!a);if(!o?.force&&d)return u.result;const h=`${l}::${a?"details":"plain"}`,p=no.get(`${l}::details`)??(a?null:no.get(h));if(p&&!o?.force)return p;const g=(async()=>{t(w=>({entries:{...w.entries,[l]:{...w.entries[l]??Hl(),isLoading:!0,error:null}}}));try{const w=await n.prContext(r,i,{includeDiff:!1,includeCheckDetails:a,sourceRepo:o?.sourceRepo??null});return t(v=>({entries:Bb({...v.entries,[l]:{result:w,hasCheckDetails:a,fetchedAt:Date.now(),isLoading:!1,error:null}})})),w}catch(w){const v=w instanceof Error?w.message:"Failed to load pull request context";return t(x=>({entries:{...x.entries,[l]:{...x.entries[l]??Hl(),isLoading:!1,error:v}}})),null}finally{no.delete(h)}})();return no.set(h,g),g},invalidate:(n,r)=>{t(i=>{const o={};for(const[l,a]of Object.entries(i.entries)){const u=Ob(l);u&&u.directory===n&&(r==null||u.number===r)||(o[l]=a)}return{entries:o}})}})),Fb=t=>{const e={success:0,failure:0,pending:0,inProgress:0,queued:0};let n;for(const o of t){if(o.status==="in_progress"){e.pending+=1,e.inProgress+=1,o.startedAt&&(!n||o.startedAt<n)&&(n=o.startedAt);continue}if(o.status==="queued"){e.pending+=1,e.queued+=1;continue}const l=typeof o.conclusion=="string"?o.conclusion.toLowerCase():"";if(!l){e.pending+=1;continue}l==="success"||l==="neutral"||l==="skipped"?e.success+=1:e.failure+=1}const r=e.success+e.failure+e.pending;return{state:e.failure>0?"failure":e.pending>0?"pending":r>0?"success":"unknown",total:r,...e,...n?{startedAt:n}:{}}},_b=35e3,hi=(t,e,n)=>{if(!t)return null;const r=Date.parse(t);if(!Number.isFinite(r))return null;const i=e?Date.parse(e):n??Date.now();if(!Number.isFinite(i)||i<=r)return null;const o=Math.floor((i-r)/6e4);if(o<1)return"<1m";if(o<60)return`${o}m`;const l=Math.floor(o/60),a=o%60;return a>0?`${l}h ${a}m`:`${l}h`},pi=t=>{const e=typeof t=="string"?t.toLowerCase():"";return!!e&&!["success","neutral","skipped"].includes(e)},ql=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},Lb=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",i=e.mergeable===!1||r==="blocked"||r==="dirty";return n||i?"blocked":"open"},$b=[2e3,5e3],Wb=600,Ql=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),En=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},zb=(t,e)=>{const n=En(t);if(!n||n.includes("->"))return"";if(e){const i=`${e}/`;return n.startsWith(i)?n.slice(i.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},Vb=(t,e)=>`${t}::${e}`,za=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},gi=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const o=t.find(l=>l.name===n);if(o)return o}const r=za(e.trackingBranch);if(r){const o=r==="origin"?t.find(a=>a.name==="upstream"):null;if(o)return o;const l=t.find(a=>a.name===r);if(l)return l}const i=t.find(o=>o.name==="origin");return i||(t[0]??null)},Ub=t=>t.startsWith("pr-"),Kb=(t,e)=>{const n=za(e),r=new Map(t.map(l=>[l.name,l])),i=[],o=l=>{l&&(i.some(a=>a.name===l.name)||i.push(l))};return n&&o(r.get(n)),o(r.get("upstream")),o(r.get("origin")),t.filter(l=>!Ub(l.name)).forEach(l=>o(l)),t.forEach(l=>o(l)),i},Dr=new Map,ro=Xo;function Hb(t,e){const[n,r]=c.useState(null),[i,o]=c.useState([]),l=c.useRef(null);return c.useEffect(()=>{r(null),o([])},[t]),c.useEffect(()=>{if(!t||!e?.repoUpstream||l.current===t)return;l.current=t;let a=!1;return(async()=>{try{const u=await e.repoUpstream(t);if(a||!u?.isFork||!u.upstream||(r(u.upstream),!e.repoBranches))return;try{const d=await e.repoBranches(u.upstream.owner,u.upstream.repo);a||o(d)}catch{}}catch{}})(),()=>{a=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:i}}const Gb=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:i=[],remoteBranches:o=[],onGeneratedDescription:l})=>{const{t:a}=Nt(),u=Pe(Z=>Z.timeFormatPreference),{github:d}=wn(),h=Dn(Z=>Z.status),f=Dn(Z=>Z.hasChecked),p=Pe(Z=>Z.setSettingsDialogOpen),g=Pe(Z=>Z.setSettingsPage),w=et(Z=>Z.currentSessionId),v=et(Z=>!!Z.newSessionDraft?.open),{isMobile:x,hasTouchInput:m,screenWidth:b}=Ln(),y=Pe(Z=>Z.openContextSurface),S=Eb(Z=>Z.requestSource),N=!x&&b>=768&&!Pn(),C=c.useCallback(()=>{g("integrations"),p(!0)},[p,g]),j=c.useMemo(()=>Vb(t,e),[t,e]),A=c.useMemo(()=>Dr.get(j)??null,[j]),D=Ks(Z=>Z.ensureEntry),I=Ks(Z=>Z.setParams),M=Ks(Z=>Z.startWatching),$=Ks(Z=>Z.stopWatching),E=Ks(Z=>Z.refresh),K=Ks(Z=>Z.updateStatus),[B,O]=c.useState(()=>A?.title??Ql(e)),[T,k]=c.useState(()=>A?.body??""),[P,F]=c.useState(()=>A?.draft??!1),[q,Q]=c.useState(()=>A?.additionalContext??""),[Y,ce]=c.useState(()=>{const Z=typeof A?.targetBaseBranch=="string"?En(A.targetBaseBranch):"";return Z||En(n)}),[X,oe]=c.useState("squash"),[te,he]=c.useState(!1),[_,ie]=c.useState(!1),[ge,ae]=c.useState(!1),[z,ne]=c.useState(!1),[ue,me]=c.useState(!1),[ke,Te]=c.useState(!1),[je,Ee]=c.useState(null),[xe,H]=c.useState(""),[Ce,ve]=c.useState(""),[re,le]=c.useState(!1),[se,G]=c.useState(!1),[U,be]=c.useState(()=>gi(i,{selectedRemoteName:A?.selectedRemoteName,trackingBranch:r})),[W,Ne]=c.useState(!1),{detectedUpstream:Oe,upstreamBranches:ye}=Hb(t,d);c.useEffect(()=>{Ne(!1)},[t]);const Fe=i.some(Z=>Z.name==="upstream"),$e=!!(t&&e&&n&&(e!==n||(Fe||Oe!==null))),V=c.useMemo(()=>Zo(t,e,U?.name??null),[t,e,U?.name]),fe=Ks(Z=>Z.entries[V]),Me=fe?.isLoading??!1,De=fe?.status??null,at=fe?.error??null,Qe=fe?.isInitialStatusResolved??!1,lt=c.useMemo(()=>{const Z=W?null:U?.name?.trim()||null,Ge=new Set;for(const ot of o){const jt=zb(ot,Z);!jt||jt==="HEAD"||Ge.add(jt)}if(W)for(const ot of ye)ot&&ot!=="HEAD"&&Ge.add(ot);const L=En(n);L&&L!=="HEAD"&&Ge.add(L);const Le=En(Y);return Le&&Le!=="HEAD"&&Ge.add(Le),Array.from(Ge).sort((ot,jt)=>ot.localeCompare(jt))},[n,o,U?.name,Y,ye,W]);c.useEffect(()=>{if(i.length===0){U&&be(null);return}(!U||!i.some(Z=>Z.name===U.name))&&be(gi(i,{selectedRemoteName:A?.selectedRemoteName,trackingBranch:r}))},[A?.selectedRemoteName,i,U,r]),c.useEffect(()=>{const Z=En(n);if(!Y&&Z){ce(Z);return}if(lt.length!==0&&!lt.includes(Y)){const Ge=lt.includes(Z)?Z:lt[0];Ge&&ce(Ge)}},[lt,n,Y]);const[de,J]=c.useState(()=>A?.activeSegment??"overview"),[Se,Ve]=c.useState(new Set),[He,it]=c.useState(new Set),Ue=c.useRef(new Set),st=c.useRef(null),ee=c.useRef(!1),ze=c.useRef(new Set),_e=c.useRef([]);c.useEffect(()=>{Oe&&!Fe&&Ne(!0)},[Oe,Fe]),c.useEffect(()=>{W&&Oe?.defaultBranch&&ce(Oe.defaultBranch)},[W,Oe?.defaultBranch]);const pe=De?.pr??null,qe=pe?.state==="merged"||pe?.state==="closed",tt=qe?null:pe,pt=tt?zu(t,tt.number):null,gt=Gl(Z=>pt?Z.entries[pt]:void 0),Je=Gl(Z=>Z.ensure),St=gt?.result??null,Ze=gt?.isLoading??!1,vt=c.useCallback(Z=>{J(Z);const Ge=Dr.get(j);Ge&&Dr.set(j,{...Ge,activeSegment:Z})},[j]);c.useEffect(()=>{!tt||!d?.prContext||de==="overview"||Je(d,t,tt.number,{includeCheckDetails:de==="checks",sourceRepo:De?.repo??null})},[de,t,Je,d,tt,De?.repo]);const rt=De?.checks??null,we=(rt?.pending??0)>0,ct=St?.checkRuns??null,dt=St?.fetchedAt;c.useEffect(()=>{if(!ct||ct.length===0)return;const Z=Fb(ct);K(V,Ge=>{if(!Ge?.pr||typeof dt=="number"&&typeof Ge.fetchedAt=="number"&&dt<Ge.fetchedAt)return Ge;const L=Ge.checks;return L&&L.state===Z.state&&L.total===Z.total&&L.success===Z.success&&L.failure===Z.failure&&L.pending===Z.pending&&L.inProgress===Z.inProgress&&L.queued===Z.queued&&L.startedAt===Z.startedAt?Ge:{...Ge,checks:Z,...typeof dt=="number"?{fetchedAt:dt}:{}}})},[ct,dt,V,K]),c.useEffect(()=>{if(de!=="checks"||!we||!pe||!d?.prContext)return;const Z=window.setInterval(()=>{Je(d,t,pe.number,{includeCheckDetails:!0,sourceRepo:De?.repo??null,force:!0})},_b);return()=>window.clearInterval(Z)},[de,we,t,Je,d,pe,De?.repo]);const[At,We]=c.useState(()=>Date.now());c.useEffect(()=>{if(!we)return;We(Date.now());const Z=window.setInterval(()=>We(Date.now()),3e4);return()=>window.clearInterval(Z)},[we]);const Xe=pe?`${t}#${pe.number}`:null,Tt=!!(Xe&&je===Xe);c.useEffect(()=>{if(!d?.prContext||!pe||typeof pe.body=="string"&&pe.body.length>0)return;const Z=`${t}#${pe.number}`;if(Ue.current.has(Z))return;Ue.current.add(Z),Ee(Z);let Ge=!1;return Je(d,t,pe.number,{sourceRepo:De?.repo??null}).then(L=>{if(Ge)return;const Le=L?.pr;Le&&K(V,ot=>!ot?.pr||ot.pr.number!==pe.number?ot:{...ot,pr:{...ot.pr,body:Le.body||""}})}).catch(()=>{}).finally(()=>{Ge||Ee(L=>L===Z?null:L)}),()=>{Ge=!0}},[t,Je,d,pe,V,De?.repo,K]),c.useEffect(()=>{if(!pe){Te(!1),H(""),ve(""),st.current=null;return}const Z=st.current!==null&&st.current!==pe.number;Z&&Te(!1),(!ke||Z)&&(H(pe.title||""),ve(pe.body||"")),st.current=pe.number},[ke,pe]);const ut=c.useCallback(Z=>{if(!Z)return"";const Ge=Date.parse(Z);return Number.isFinite(Ge)?Td(Ge,u,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):Z},[u]),kt=c.useMemo(()=>{const Z=h?.user?.login;return typeof Z=="string"?Z.trim():""},[h]),Rt=c.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),ss=c.useCallback(Z=>{const Ge=kt.toLowerCase(),L=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return Z.replace(L,(Le,ot,jt)=>{const Ct=`@${jt}`,Bt=jt.toLowerCase();return`${ot}[${Ct}](https://github.com/${Bt}${Ge&&Bt===Ge?"?oc-self-mention=1":""})`})},[kt]),Ut=c.useMemo(()=>{const Z=(St?.issueComments??[]).map(Le=>({id:`issue-${Le.id}`,body:Le.body||"",authorName:Le.author?.name||Le.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:Le.author?.login||null,avatarUrl:Le.author?.avatarUrl||null,createdAt:Le.createdAt,context:a("gitView.pr.comments.generalContext"),path:null,line:null})),Ge=(St?.reviewComments??[]).map(Le=>({id:`review-${Le.id}`,body:Le.body||"",authorName:Le.author?.name||Le.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:Le.author?.login||null,avatarUrl:Le.author?.avatarUrl||null,createdAt:Le.createdAt,context:a("gitView.pr.comments.reviewContext"),path:Le.path||null,line:Le.line??null})),L=[...Z,...Ge];return L.sort((Le,ot)=>{const jt=Le.createdAt?Date.parse(Le.createdAt):0,Ct=ot.createdAt?Date.parse(ot.createdAt):0,Bt=Number.isFinite(jt)?jt:0,os=Number.isFinite(Ct)?Ct:0;return Bt-os}),L},[St,a]),Wt=c.useCallback(()=>{const Z=w??(v?"draft":null);return Z?{directory:t,sessionKey:Z}:(Re.error(a("gitView.pr.toast.noActiveSession"),{description:a("gitView.pr.toast.noActiveSessionDescription")}),null)},[w,t,v,a]),Qt=c.useCallback((Z,Ge)=>{const L=Ge.authorLogin?`@${Ge.authorLogin}`:Ge.authorName,Le=Ge.path?` · ${Ge.path}${Ge.line?`:${Ge.line}`:""}`:"";Ti.getState().addDraft(Z,{source:"pr-comment",fileLabel:`PR #${pe?.number??""} ${L}${Le}`,startLine:Ge.line??0,endLine:Ge.line??0,code:Ge.body,language:"markdown",text:""})},[pe?.number]),Kt=c.useCallback((Z,Ge)=>{const L=Z.status||"unknown",Le=Z.conclusion??void 0,ot=Le?`${L} / ${Le}`:L,jt=Z.app?.name||Z.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:Ge?.hideHeader?"flex items-start justify-end gap-3":"flex items-start justify-between gap-3",children:[Ge?.hideHeader?null:s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:Z.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:jt?`${jt} · ${ot}`:ot})]}),Z.detailsUrl?s.jsx(bt,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:Z.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(R,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),Z.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:Z.output.title}):null,Z.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:Z.output.summary}):null,Z.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap break-words max-h-48 overflow-y-auto",children:Z.output.text}):null,Array.isArray(Z.annotations)&&Z.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",Z.annotations.length>20?` (showing 20/${Z.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:Z.annotations.slice(0,20).map((Ct,Bt)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro break-words text-[var(--status-error)]",children:[Ct.title||Ct.level||"Issue",Ct.path?` · ${Ct.path}`:"",typeof Ct.startLine=="number"?`:${Ct.startLine}`:"",typeof Ct.endLine=="number"&&Ct.endLine!==Ct.startLine?`-${Ct.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap break-words mt-1",children:Ct.message}),Ct.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:Ct.rawDetails}):null]},`${Ct.path||"file"}:${Ct.startLine||Bt}:${Bt}`))})]}):null,Z.job?.steps&&Z.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:Z.job.steps.map((Ct,Bt)=>{const os=(Ct.conclusion||"").toLowerCase(),Gt=os&&!["success","neutral","skipped"].includes(os),en=`${Z.id??"run"}:${Z.job?.jobId??"job"}:${Ct.number??Bt}:${Ct.name}`,Sn=Se.has(en);return Gt?s.jsxs($i,{open:Sn,children:[s.jsxs("button",{type:"button",onClick:()=>{Ve(ai=>{const sr=new Set(ai);return sr.has(en)?sr.delete(en):sr.add(en),sr})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Gt?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Sn?s.jsx(R,{name:"arrow-down-s",className:"size-4"}):s.jsx(R,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:Ct.name}),Ct.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Ct.conclusion}):null]}),s.jsx(Wi,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof Ct.number=="number"?s.jsxs("div",{children:[a("gitView.pr.checks.stepLabel"),": ",Ct.number]}):null,Ct.status?s.jsxs("div",{children:[a("gitView.pr.checks.statusLabel"),": ",Ct.status]}):null,Ct.conclusion?s.jsxs("div",{children:[a("gitView.pr.checks.conclusionLabel"),": ",Ct.conclusion]}):null,Ct.startedAt?s.jsxs("div",{children:[a("gitView.pr.checks.startedLabel"),": ",ut(Ct.startedAt)]}):null,Ct.completedAt?s.jsxs("div",{children:[a("gitView.pr.checks.completedLabel"),": ",ut(Ct.completedAt)]}):null]})})]},en):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:Ct.name}),Ct.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Ct.conclusion}):null]},en)})})]}):null]})},[Se,ut,a]),[Ft,$t]=c.useState(!1),[Be,Ye]=c.useState(!1),ft=c.useCallback(async()=>{if(!d?.prContext){Re.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!pe)return;const Z=Wt();if(Z){$t(!0);try{const Ge=await Je(d,t,pe.number,{includeCheckDetails:!0,sourceRepo:De?.repo??null});if(!Ge){Re.error(a("gitView.pr.toast.loadChecksFailed"));return}const Le=(Ge.checkRuns??[]).filter(jt=>pi(jt.conclusion));if(Le.length===0){Re.message(a("gitView.pr.toast.noFailedChecks"));return}const ot=Ti.getState();for(const jt of Le){const Ct=(jt.annotations??[]).map(Gt=>[[Gt.level,Gt.title].filter(Boolean).join(" "),Gt.path?`${Gt.path}${typeof Gt.startLine=="number"?`:${Gt.startLine}`:""}`:null,Gt.message,Gt.rawDetails].filter(Boolean).join(`
|
|
37
|
+
`)),Bt=(jt.job?.steps??[]).filter(Gt=>pi(Gt.conclusion)).map(Gt=>`step ${Gt.number??"?"}: ${Gt.name} → ${Gt.conclusion}`),os=[`check: ${jt.job?.workflowName?`${jt.job.workflowName} / ${jt.name}`:jt.name}`,`status: ${jt.status??"unknown"} / ${jt.conclusion??"unknown"}`,jt.detailsUrl?`url: ${jt.detailsUrl}`:null,jt.output?.title?`title: ${jt.output.title}`:null,jt.output?.summary?`summary:
|
|
38
|
+
${jt.output.summary}`:null,Bt.length>0?`failed steps:
|
|
39
|
+
${Bt.join(`
|
|
40
|
+
`)}`:null,Ct.length>0?`annotations:
|
|
41
|
+
${Ct.join(`
|
|
42
|
+
---
|
|
43
|
+
`)}`:null].filter(Boolean).join(`
|
|
44
|
+
|
|
45
|
+
`);ot.addDraft(Z,{source:"pr-check",fileLabel:`PR #${pe.number} · ${jt.name}`,startLine:0,endLine:0,code:os,language:"text",text:""})}}catch(Ge){const L=Ge instanceof Error?Ge.message:String(Ge);Re.error(a("gitView.pr.toast.loadChecksFailed"),{description:L})}finally{$t(!1)}}},[t,Je,d,pe,Wt,De?.repo,a]),yt=c.useCallback(async()=>{if(!d?.prContext){Re.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!pe)return;const Z=Wt();if(Z){Ye(!0);try{if(!await Je(d,t,pe.number,{sourceRepo:De?.repo??null})){Re.error(a("gitView.pr.toast.loadPrCommentsFailed"));return}if(Ut.length===0){Re.message(a("gitView.pr.toast.noPrComments"));return}for(const L of Ut)Qt(Z,L)}catch(Ge){const L=Ge instanceof Error?Ge.message:String(Ge);Re.error(a("gitView.pr.toast.loadPrCommentsFailed"),{description:L})}finally{Ye(!1)}}},[Qt,t,Je,d,pe,Wt,De?.repo,a,Ut]),ht=c.useCallback(async Z=>{const Ge=Wt();Ge&&Qt(Ge,Z)},[Qt,Wt]),mt=c.useCallback(async Z=>{await E(V,Z)},[V,E]),[_t,Jt]=c.useState(!1),Yt=c.useRef(!0);c.useEffect(()=>(Yt.current=!0,()=>{Yt.current=!1}),[]);const Ns=c.useCallback(async()=>{if(_t)return;Jt(!0);const Z=Date.now();try{await mt({force:!0})}finally{const Ge=Wb-(Date.now()-Z);Ge>0&&await new Promise(L=>window.setTimeout(L,Ge)),Yt.current&&Jt(!1)}},[_t,mt]),Xt=c.useCallback(()=>{_e.current.forEach(Z=>{window.clearTimeout(Z)}),_e.current=$b.map(Z=>window.setTimeout(()=>{mt({force:!0,silent:!0,markInitialResolved:!0})},Z))},[mt]);c.useEffect(()=>{if(!d?.prStatus||!$e||i.length<=1||ee.current||De?.pr)return;const Z=`${j}::${U?.name??""}`;if(ze.current.has(Z))return;ze.current.add(Z);const Ge=Kb(i,r).filter(ot=>ot.name!==U?.name);if(Ge.length===0)return;let L=!1;return(async()=>{for(const ot of Ge){if(L)return;try{if(!(await d.prStatus(t,e,ot.name))?.pr)continue;if(L)return;be(Ct=>Ct?.name===ot.name?Ct:ot);return}catch{}}})(),()=>{L=!0}},[e,$e,t,d,i,U?.name,j,De?.pr,r]),c.useEffect(()=>{D(V),I(V,{directory:t,branch:e,remoteName:U?.name??null,canShow:$e,github:d,githubAuthChecked:f,githubConnected:h?.connected??null})},[e,$e,t,D,d,f,h?.connected,V,U?.name,I]),c.useEffect(()=>(M(V),()=>{$(V)}),[V,M,$]),c.useEffect(()=>{const Z=Dr.get(j)??null;O(Z?.title??Ql(e)),k(Z?.body??""),F(Z?.draft??!1),ce(Z?.targetBaseBranch?En(Z.targetBaseBranch):En(n));const Ge=gi(i,{selectedRemoteName:Z?.selectedRemoteName,trackingBranch:r});be(L=>L?.name===Ge?.name?L:Ge)},[n,e,i,j,r]),c.useEffect(()=>{mt({markInitialResolved:!0})},[V,mt]),c.useEffect(()=>{!$e||!U?.name||mt({force:!0,silent:!0,markInitialResolved:!0})},[$e,mt,U?.name]),c.useEffect(()=>{const Z=De?.resolvedRemoteName?.trim();if(!Z||ee.current)return;const Ge=i.find(L=>L.name===Z);Ge&&be(L=>L?.name===Ge.name?L:Ge)},[i,De?.resolvedRemoteName]),c.useEffect(()=>{const Z=()=>{const L=Ks.getState().entries[V]?.lastRefreshAt??0;Date.now()-L>6e4&&mt({force:!0,silent:!0})},Ge=()=>{document.visibilityState==="visible"&&Z()};return window.addEventListener("focus",Z),document.addEventListener("visibilitychange",Ge),()=>{window.removeEventListener("focus",Z),document.removeEventListener("visibilitychange",Ge)}},[V,mt]),c.useEffect(()=>{f&&h?.connected===!1&&mt({force:!0,silent:!0,markInitialResolved:!0})},[f,h,mt]),c.useEffect(()=>{!t||!e||Dr.set(j,{title:B,body:T,draft:P,additionalContext:q,targetBaseBranch:Y,selectedRemoteName:U?.name,activeSegment:de})},[j,B,T,P,q,Y,U?.name,t,e,de]),c.useEffect(()=>{const Z=_e.current;return()=>{Z.forEach(Ge=>{window.clearTimeout(Ge)}),_e.current=[]}},[]);const zs=c.useCallback(async()=>{if(!te&&t){he(!0);try{const Ge={base:W&&Oe?.defaultBranchSha?Oe.defaultBranchSha:Y,head:e};q&&(Ge.context=q);const L=await Hf(t,Ge);L.title?.trim()&&O(L.title.trim()),L.body?.trim()&&k(L.body.trim()),l?.()}catch(Z){const Ge=Z instanceof Error?Z.message:String(Z);Re.error(a("gitView.pr.toast.generateDescriptionFailed"),{description:Ge})}finally{he(!1)}}},[q,e,Oe?.defaultBranchSha,t,te,l,Y,a,W]),Js=c.useCallback(async()=>{if(!d?.prCreate){Re.error(a("gitView.pr.toast.githubApiUnavailable"));return}const Z=B.trim();if(!Z){Re.error(a("gitView.pr.toast.titleRequired"));return}const Ge=Y.trim();if(!Ge){Re.error(a("gitView.pr.toast.baseBranchRequired"));return}if(!W&&Ge===e){Re.error(a("gitView.pr.toast.baseMustDifferFromHead"));return}ie(!0);try{const L=za(r),Le=W&&Oe,ot=await d.prCreate({directory:t,title:Z,head:e,base:Ge,...T.trim()?{body:T}:{},draft:P,...Le?{targetRepo:{owner:Oe.owner,repo:Oe.repo},headRemote:"origin"}:{...U?{remote:U.name}:{},...L&&L!==U?.name?{headRemote:L}:{}}});Re.success(a("gitView.pr.toast.prCreated")),K(V,jt=>jt&&{...jt,pr:ot}),await mt({force:!0}),Xt()}catch(L){const Le=L instanceof Error?L.message:String(L);Re.error(a("gitView.pr.toast.createPrFailed"),{description:Le})}finally{ie(!1)}},[T,e,Oe,t,P,d,V,mt,Xt,U,Y,B,r,K,W,a]),rs=c.useCallback(async Z=>{if(!d?.prMerge){Re.error(a("gitView.pr.toast.githubApiUnavailable"));return}ne(!0);try{const Ge=await d.prMerge({directory:t,number:Z.number,method:X});Ge.merged?Re.success(a("gitView.pr.toast.prMerged")):Re.message(a("gitView.pr.toast.prNotMerged"),{description:Ge.message||a("gitView.pr.notMergeable")}),await mt({force:!0}),Xt()}catch(Ge){const L=Ge instanceof Error?Ge.message:String(Ge);Re.error(a("gitView.pr.toast.mergeFailed"),{description:L}),Z.url&&ro(Z.url)}finally{ne(!1)}},[t,d,X,mt,Xt,a]),Vs=c.useCallback(async Z=>{if(!d?.prReady){Re.error(a("gitView.pr.toast.githubApiUnavailable"));return}me(!0);try{await d.prReady({directory:t,number:Z.number}),Re.success(a("gitView.pr.toast.markedReady")),await mt({force:!0}),Xt()}catch(Ge){const L=Ge instanceof Error?Ge.message:String(Ge);Re.error(a("gitView.pr.toast.markReadyFailed"),{description:L}),Z.url&&ro(Z.url)}finally{me(!1)}},[t,d,mt,Xt,a]),Es=c.useCallback(async Z=>{if(!d?.prUpdate){Re.error(a("gitView.pr.toast.githubApiUnavailable"));return}const Ge=xe.trim();if(!Ge){Re.error(a("gitView.pr.toast.titleRequired"));return}ae(!0);try{const L=await d.prUpdate({directory:t,number:Z.number,title:Ge,body:Ce});K(V,Le=>Le&&{...Le,pr:{...Le.pr??Z,...L}}),Te(!1),Re.success(a("gitView.pr.toast.prUpdated")),await mt({force:!0}),Xt()}catch(L){const Le=L instanceof Error?L.message:String(L);Re.error(a("gitView.pr.toast.updatePrFailed"),{description:Le})}finally{ae(!1)}},[t,Ce,xe,d,V,mt,Xt,K,a]);if(!$e)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:a("gitView.pullRequest.title")}),s.jsx(Vl,{})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pullRequest.availableOnFeatureBranches")})]})});const ln=De?.repo?.url||null,gs=W&&Oe?.url?Oe.url:ln,vs=!!De?.canMerge,Zs=!!De?.connected,Rs=f&&De?.connected===!1,As=Lb(De),Ds=As?`var(--pr-${As})`:"var(--status-info)",js=As==="draft"?"git-pr-draft":As==="merged"?"git-merge":As==="closed"?"git-close-pull-request":"git-pull-request",Mt=pe?[`${pe.state}${pe.draft?" (draft)":""}`,pe.mergeable===!1?a("gitView.pr.notMergeable"):null,pe.state==="open"&&typeof pe.mergeableState=="string"&&pe.mergeableState&&pe.mergeableState!=="unknown"?pe.mergeableState:null].filter(Boolean).join(" · "):"",Lt=rt?rt.total>0?`${rt.success}/${rt.total} ${a("gitView.pr.checks.label")}`:`${rt.state} ${a("gitView.pr.checks.label")}`:"";return s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex flex-col gap-1",children:[s.jsxs("div",{className:"@container/pr-actions flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[pe?s.jsxs(bt,{type:"button",variant:"outline",size:"xs",className:"shrink-0",onClick:()=>{ro(pe.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:[s.jsx(R,{name:js,className:"size-4 shrink-0",style:{color:Ds}}),a("gitView.pr.actions.openOnGitHub")]}):s.jsx(R,{name:js,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:a("gitView.pullRequest.title")}),pe?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",pe.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[pe&&N?s.jsxs(bt,{variant:"outline",size:"sm",className:Ie("pr-actions__walkthrough-button h-7 shrink-0 gap-1.5 px-2",Rb),onClick:()=>{S(t,{kind:"pr",number:pe.number}),y(t,"walkthrough")},"aria-label":a("walkthrough.action.open"),children:[s.jsx(R,{name:"route",className:"size-4"}),s.jsx("span",{className:"pr-actions__walkthrough-label typography-ui-label",children:a("walkthrough.action.open")})]}):null,s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(bt,{variant:"ghost",size:"sm",className:"h-7 w-7 px-0",disabled:Me||_t,onClick:()=>{Ns()},"aria-label":a("gitView.pr.actions.refreshAria"),children:Me||_t?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):s.jsx(R,{name:"refresh",className:"size-4 text-muted-foreground"})})}),s.jsx(It,{children:s.jsx("p",{children:a("gitView.pr.actions.refresh")})})]}),s.jsx(Vl,{className:"h-7 w-7"})]})]}),pe?s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:Ds},children:Mt}),rt?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${ql(rt.state)}`}),Lt]}):null,r&&U&&r.split("/")[0]!==U.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",U.name]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[vs&&pe.draft&&pe.state==="open"?s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(bt,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Vs(pe),disabled:ue||z||ge||ke,"aria-label":a("gitView.pr.actions.markReadyAria"),children:ue?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:a("gitView.pr.actions.markReady")})})]}):null,vs?s.jsxs(s.Fragment,{children:[s.jsxs(Bs,{value:X,onValueChange:Z=>oe(Z),disabled:z||pe.state!=="open",children:[s.jsx(Fs,{size:"sm",className:"h-7 w-auto min-w-0",children:s.jsx(Cs,{})}),s.jsxs(_s,{children:[s.jsx(ts,{value:"squash",children:a("gitView.pr.mergeMethod.squash")}),s.jsx(ts,{value:"merge",children:a("gitView.pr.mergeMethod.merge")}),s.jsx(ts,{value:"rebase",children:a("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(bt,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>rs(pe),disabled:z||ue||pe.state!=="open"||pe.draft||ge||ke,"aria-label":a("gitView.pr.actions.mergePrAria"),children:z?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"git-merge",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:a("gitView.pr.actions.mergePr")})})]})]}):null]})]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Rs?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("gitView.pr.githubNotConnected")}),s.jsx(bt,{variant:"outline",size:"sm",onClick:C,className:"w-fit",children:a("gitView.pr.actions.openSettings")})]}):null,at?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:a("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:at}),gs?s.jsx(bt,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:gs,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(R,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!pe&&!Qe&&!at&&!Rs?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.pr.checkingStatus")]}):pe&&!qe?s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("div",{className:"h-8 min-w-0",children:s.jsx(iu,{className:"h-full",items:[{id:"overview",label:a("gitView.pr.segment.overview")},{id:"checks",label:rt&&rt.total>0?`${a("gitView.pr.segment.checks")} ${rt.success}/${rt.total}`:a("gitView.pr.segment.checks"),icon:rt?s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${ql(rt.state)}`}):void 0},{id:"comments",label:St?`${a("gitView.pr.segment.comments")} ${(St.issueComments?.length??0)+(St.reviewComments?.length??0)}`:a("gitView.pr.segment.comments")}],activeId:de,onSelect:Z=>vt(Z),layoutMode:"fit",variant:"active-pill",activePillButtonClassName:"h-7"})}),de==="overview"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[vs&&pe.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.draftMustBeReady")}):null,vs?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.noMergePermission")}),s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:ke?s.jsx(Cn,{value:xe,onChange:Z=>H(Z.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:m?"on":"off",autoCapitalize:m?"sentences":"off",spellCheck:m}):s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:pe.title})}),pe.state==="open"?s.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:ke?s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(bt,{variant:"outline",size:"sm",className:"h-9 w-9 px-0",onClick:()=>{Te(!1),H(pe.title||""),ve(pe.body||"")},disabled:ge,"aria-label":a("gitView.pr.actions.cancelEditingAria"),children:s.jsx(R,{name:"close",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:a("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(bt,{size:"sm",className:"h-9 w-9 px-0",onClick:()=>Es(pe),disabled:ge||!xe.trim(),"aria-label":a("gitView.pr.actions.savePrAria"),children:ge?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"check",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:a("gitView.pr.actions.savePr")})})]})]}):s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(bt,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Te(!0),"aria-label":a("gitView.pr.actions.editPrAria"),children:s.jsx(R,{name:"edit",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:a("gitView.pr.actions.editPr")})})]})}):null]}),ke?s.jsx(lr,{value:Ce,onChange:Z=>ve(Z.target.value),outerClassName:"min-h-[60vh]",placeholder:a("gitView.pr.placeholder.description"),autoCorrect:m?"on":"off",autoCapitalize:m?"sentences":"off",spellCheck:m}):null,ke?null:pe.body?.trim()?s.jsx(cl,{content:pe.body,className:"typography-markdown-body min-w-0 text-muted-foreground break-words",enableFileReferences:!1}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:a(Tt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}):null,de==="checks"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[rt&&rt.total>0?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-muted/40",children:[rt.success>0?s.jsx("div",{className:"bg-[color:var(--status-success)]",style:{width:`${rt.success/rt.total*100}%`}}):null,rt.failure>0?s.jsx("div",{className:"bg-[color:var(--status-error)]",style:{width:`${rt.failure/rt.total*100}%`}}):null,rt.pending>0?s.jsx("div",{className:"bg-[color:var(--status-warning)]",style:{width:`${rt.pending/rt.total*100}%`}}):null]}),s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[rt.success,"/",rt.total," ",a("gitView.pr.checks.label")]}),(rt.inProgress??0)>0?s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 typography-micro text-[var(--status-warning)]",children:[s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}),hi(rt.startedAt,void 0,At)]}):null]}):null,rt?.failure?s.jsxs(bt,{variant:"outline",size:"sm",className:"w-fit gap-1.5 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:ft,disabled:Ft,"aria-label":a("gitView.pr.actions.resolveFailedChecksAria"),children:[Ft?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"ai-generate-2",className:"size-4"}),a("gitView.pr.actions.resolveFailedChecks")]}):null,(St?.checkRuns?.length??0)>0?s.jsx("div",{className:"flex flex-col gap-1.5",children:(St?.checkRuns??[]).map((Z,Ge)=>{const L=`${Z.id??"run"}:${Z.name}:${Ge}`,Le=Z.status==="in_progress",ot=Z.status==="queued",jt=pi(Z.conclusion),Ct=He.has(L),Bt=!!(Z.output?.title||Z.output?.summary||Z.output?.text||(Z.annotations?.length??0)>0||(Z.job?.steps?.length??0)>0||Z.detailsUrl),os=Z.job?.workflowName,Gt=Le?hi(Z.startedAt,void 0,At):hi(Z.startedAt,Z.completedAt);return s.jsxs("div",{className:Ie("rounded-md border border-border/40",jt&&"border-[var(--status-error-border)]"),children:[s.jsxs("button",{type:"button",disabled:!Bt,onClick:()=>{it(en=>{const Sn=new Set(en);return Sn.has(L)?Sn.delete(L):Sn.add(L),Sn})},className:"flex w-full items-center gap-2 px-2.5 py-2 text-left disabled:cursor-default",children:[Le?s.jsx(R,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-warning)]"}):ot?s.jsx(R,{name:"time",className:"size-4 shrink-0 text-muted-foreground"}):jt?s.jsx(R,{name:"close-circle",className:"size-4 shrink-0 text-[var(--status-error)]"}):s.jsx(R,{name:"checkbox-circle",className:"size-4 shrink-0 text-[var(--status-success)]"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:os&&os!==Z.name?`${os} / ${Z.name}`:Z.name}),Gt?s.jsx("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:Gt}):null,Bt?s.jsx(R,{name:"arrow-down-s",className:Ie("size-4 shrink-0 text-muted-foreground transition-transform",Ct&&"rotate-180")}):null]}),Ct&&Bt?s.jsx("div",{className:"min-w-0 overflow-hidden border-t border-border/40 p-2.5",children:Kt(Z,{hideHeader:!0})}):null]},L)})}):Ze?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:a("gitView.pr.checkDetails.empty")})]}):null,de==="comments"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Ut.length>0?s.jsx("div",{className:"flex items-center justify-end",children:s.jsxs(bt,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)]",onClick:yt,disabled:Be,"aria-label":a("gitView.pr.actions.shareCommentsAria"),children:[Be?s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(R,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.comments.addAll")]})}):null,Ut.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Ut.map((Z,Ge)=>{const L=(Z.authorName||"?").charAt(0).toUpperCase(),Le=Ge===Ut.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Le?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:Z.avatarUrl?s.jsx("img",{src:Z.avatarUrl,alt:Z.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:L})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[Z.authorName,Z.authorLogin&&Z.authorLogin!==Z.authorName?` · @${Z.authorLogin}`:""]}),Z.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:ut(Z.createdAt)}):null,s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs(bt,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{ht(Z)},"aria-label":a("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(R,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.actions.sendToAgent")]})}),s.jsx(It,{children:s.jsx("p",{children:a("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Z.context,Z.path?` · ${Z.path}`:"",Z.line?`:${Z.line}`:""]}),s.jsx(cl,{content:ss(Z.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Rt].filter(Boolean).join(" "),enableFileReferences:!1})]})]},Z.id)})})}):Ze&&!St?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:a("gitView.pr.comments.empty")})]}):null]}):s.jsxs("div",{className:"flex flex-col gap-3",children:[pe&&qe?s.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-md border border-border/60 bg-surface-muted/40 px-2.5 py-2",children:[s.jsx(R,{name:pe.state==="merged"?"git-merge":"git-close-pull-request",className:"size-4 shrink-0",style:{color:Ds}}),s.jsx("div",{className:"min-w-0 flex-1 typography-micro text-muted-foreground",children:pe.state==="merged"?a("gitView.pr.history.merged",{number:pe.number,base:pe.base||Y}):a("gitView.pr.history.closed",{number:pe.number})}),s.jsx(bt,{type:"button",variant:"ghost",size:"xs",className:"shrink-0",onClick:()=>{ro(pe.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(R,{name:"external-link",className:"size-3.5"})})]}):null,s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:a("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",Y," ",s.jsxs("span",{className:"opacity-60",children:["(",W&&Oe?"upstream":"remote",")"]})]})]}),gs?s.jsx(bt,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:gs,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(R,{name:"external-link",className:"size-4"}),a("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.title")}),s.jsx(Cn,{value:B,onChange:Z=>O(Z.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:m?"on":"off",autoCapitalize:m?"sentences":"off",spellCheck:m})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.baseBranch")}),lt.length>0?s.jsxs(Bs,{value:Y,onValueChange:ce,children:[s.jsx(Fs,{size:"lg",children:s.jsx(Cs,{placeholder:a("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(_s,{children:lt.map(Z=>s.jsx(ts,{value:Z,children:Z},Z))})]}):s.jsx(Cn,{value:Y,onChange:Z=>ce(Z.target.value),placeholder:a("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.description")}),s.jsx(lr,{value:T,onChange:Z=>k(Z.target.value),className:"min-h-[110px]",placeholder:a("gitView.pr.placeholder.whatChanged"),autoCorrect:m?"on":"off",autoCapitalize:m?"sentences":"off",spellCheck:m})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":P,onClick:()=>F(Z=>!Z),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),F(Ge=>!Ge))},children:[s.jsx(ur,{size:"sm",checked:P,onChange:Z=>F(Z),ariaLabel:a("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:a("gitView.pr.field.draft")})]}),x?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.optional")}),s.jsx(bt,{variant:"outline",size:"sm",onClick:()=>G(!0),children:q.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),q.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:a("gitView.pr.additionalContext.added")})})]}):s.jsxs($i,{open:re,onOpenChange:le,children:[s.jsxs(au,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:re?a("gitView.pr.actions.hide"):q.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),s.jsx(Wi,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(lr,{value:q,onChange:Z=>Q(Z.target.value),className:"min-h-[100px] bg-transparent",placeholder:a("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(ei,{open:se,onClose:()=>G(!1),title:a("gitView.pr.additionalContext.title"),footer:s.jsx(bt,{size:"sm",onClick:()=>G(!1),className:"w-full",children:a("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(lr,{value:q,onChange:Z=>Q(Z.target.value),className:"min-h-[200px] bg-transparent",placeholder:a("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(bt,{variant:"outline",size:"sm",onClick:zs,disabled:te||_,children:[te?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"ai-generate-2",className:"size-4 text-primary"}),a("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(bt,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Js,disabled:_||!Zs||!Y.trim()||!W&&Y.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:_?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:a("gitView.pr.actions.createPr")})]})]})]})]})]})},qb=t=>{const{remoteNames:e,localBranches:n,worktreeCreatedFromBranch:r,rootBranchHint:i,defaultBranch:o,headBranch:l}=t,a=typeof l=="string"?l.trim():"",u=g=>{if(!g)return"";let w=g.trim();if(!w||w==="HEAD")return"";if(n.includes(w))return w;w.startsWith("refs/heads/")&&(w=w.slice(11)),w.startsWith("heads/")&&(w=w.slice(6)),w.startsWith("remotes/")&&(w=w.slice(8));const v=w.indexOf("/");if(v>0){const x=w.slice(0,v);if(e.has(x)){const m=w.slice(v+1).trim();m&&(w=m)}}return w},d=g=>{const w=u(typeof g=="string"?g:"");return w&&w!==a?w:""},h=d(r);if(h)return h;const f=d(i);if(f)return f;const p=d(o);return p||(n.includes("main")?"main":n.includes("master")?"master":n.includes("develop")?"develop":"main")},j5=t=>{const{baseBranch:e,localBranches:n,remoteBranches:r}=t;return n.includes(e)?!0:r.some(i=>{const o=i.indexOf("/");return o>0&&i.slice(o+1)===e})},xi=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),oo=new Map,io=new Map,Tn=t=>`${ps()}::${t}`,Qb=()=>{const t=nt.c(115),{t:e}=Nt(),{git:n}=wn(),r=Sr(),{rootIsGitRepo:i,gitDirectory:o,nestedRepos:l}=Gf(r??null),a=Na(o??null),u=Ed(o??null),d=Rd(o??null),{ensureAll:h,ensureNestedRepos:f,selectNestedRepo:p}=Bn(Zn(Yb)),g=et(Xb),w=et(Jb),v=et(Zb),x=et(ey);let m;t[0]!==r?(m=xi(r),t[0]=r,t[1]=m):m=t[1];const b=m;let y;if(t[2]!==x||t[3]!==b||t[4]!==v){e:{if(!b){y=void 0;break e}let U;if(t[6]!==x||t[7]!==b){let W;t[9]!==b?(W=Ne=>xi(Ne.path)===b,t[9]=b,t[10]=W):W=t[10],U=x.find(W),t[6]=x,t[7]=b,t[8]=U}else U=t[8];const be=U;if(be){y=be;break e}for(const W of v.values())if(xi(W.path)===b){y=W;break e}y=void 0}t[2]=x,t[3]=b,t[4]=v,t[5]=y}else y=t[5];const S=y;let N;t[11]!==g||t[12]!==S||t[13]!==w?.open||t[14]!==v?(N=()=>{if(g)return v.get(g)??S;if(w?.open)return S},t[11]=g,t[12]=S,t[13]=w?.open,t[14]=v,t[15]=N):N=t[15],w?.open;let C;t[16]!==N?(C=N(),t[16]=N,t[17]=C):C=t[17];const j=C;let A;t[18]!==g?(A=U=>g?U.getAttachment(g):void 0,t[18]=g,t[19]=A):A=t[19];const D=Dd(A),I=D&&!D.degraded&&!D.legacy?D.worktreeRoot??void 0:void 0,M=vb(r,j,a?.current??void 0);let $,E;t[20]!==h||t[21]!==n||t[22]!==o?($=()=>{!o||!n||h(o,n)},E=[o,h,n],t[20]=h,t[21]=n,t[22]=o,t[23]=$,t[24]=E):($=t[23],E=t[24]),c.useEffect($,E);const[K,B]=c.useState(null);let O;t[25]!==I||t[26]!==M?.projectDirectory?(O=()=>{const U=I||M?.projectDirectory;if(!U){B(null);return}let be=!1;return ti(U).then(W=>{if(be)return;const Ne=W.trim();B(Ne&&Ne!=="HEAD"?Ne:null)}).catch(()=>{be||B(null)}),()=>{be=!0}},t[25]=I,t[26]=M?.projectDirectory,t[27]=O):O=t[27];const T=M?.projectDirectory;let k;t[28]!==I||t[29]!==T?(k=[I,T],t[28]=I,t[29]=T,t[30]=k):k=t[30],c.useEffect(O,k);let P;t[31]!==o?(P=()=>(o?oo.get(Tn(o)):void 0)??[],t[31]=o,t[32]=P):P=t[32];const[F,q]=c.useState(P);let Q;t[33]!==o?(Q=()=>(o?io.get(Tn(o)):void 0)??null,t[33]=o,t[34]=Q):Q=t[34];const[Y,ce]=c.useState(Q);let X,oe;t[35]!==n||t[36]!==o?(X=()=>{if(!o||!n?.getRemotes){q([]);return}q(oo.get(Tn(o))??[]);let U=!1;return n.getRemotes(o).then(be=>{U||(oo.set(Tn(o),be??[]),q(be??[]))}).catch(()=>{U||q(oo.get(Tn(o))??[])}),()=>{U=!0}},oe=[o,n],t[35]=n,t[36]=o,t[37]=X,t[38]=oe):(X=t[37],oe=t[38]),c.useEffect(X,oe);let te,he;t[39]!==n||t[40]!==o?(te=()=>{if(!o||!n?.getRemoteUrl){ce(null);return}ce(io.get(Tn(o))??null);let U=!1;return n.getRemoteUrl(o).then(be=>{U||(io.set(Tn(o),be),ce(be))}).catch(()=>{U||ce(io.get(Tn(o))??null)}),()=>{U=!0}},he=[o,n],t[39]=n,t[40]=o,t[41]=te,t[42]=he):(te=t[41],he=t[42]),c.useEffect(te,he);let _;e:{if(!u?.all){let be;t[43]===Symbol.for("react.memo_cache_sentinel")?(be=[],t[43]=be):be=t[43],_=be;break e}let U;t[44]!==u.all?(U=u.all.filter(ty).sort(),t[44]=u.all,t[45]=U):U=t[45],_=U}const ie=_;let ge;e:{if(!u?.all){let be;t[46]===Symbol.for("react.memo_cache_sentinel")?(be=[],t[46]=be):be=t[46],ge=be;break e}let U;t[47]!==u.all?(U=u.all.filter(sy).map(ny).sort(),t[47]=u.all,t[48]=U):U=t[48],ge=U}const ae=ge;let z;t[49]!==ae||t[50]!==Y||t[51]!==F||t[52]!==a?.tracking?(z=()=>{if(F.length>0)return F;const U=new Set,be=a?.tracking?.trim();be&&be.includes("/")&&U.add(be.split("/")[0]);for(const W of ae){const Ne=W.indexOf("/");Ne>0&&U.add(W.slice(0,Ne))}return U.size===0&&Y&&U.add("origin"),Array.from(U).map(W=>({name:W,fetchUrl:Y??"",pushUrl:Y??""}))},t[49]=ae,t[50]=Y,t[51]=F,t[52]=a?.tracking,t[53]=z):z=t[53],a?.tracking;let ne;t[54]!==z?(ne=z(),t[54]=z,t[55]=ne):ne=t[55];const ue=ne,me=a?.current??null;a?.tracking;let ke;t[56]!==a?.tracking?(ke=a?.tracking?.trim().split("/")[0],t[56]=a?.tracking,t[57]=ke):ke=t[57];const Te=ke,je=(Te&&u?.defaultBranches?.[Te])??u?.defaultBranches?.origin;let Ee;t[58]!==me||t[59]!==je||t[60]!==ue||t[61]!==ie||t[62]!==K||t[63]!==M?.createdFromBranch?(Ee=()=>qb({remoteNames:new Set(ue.map(ry)),localBranches:ie,worktreeCreatedFromBranch:M?.createdFromBranch,rootBranchHint:K,defaultBranch:je,headBranch:me}),t[58]=me,t[59]=je,t[60]=ue,t[61]=ie,t[62]=K,t[63]=M?.createdFromBranch,t[64]=Ee):Ee=t[64],M?.createdFromBranch;let xe;t[65]!==Ee?(xe=Ee(),t[65]=Ee,t[66]=xe):xe=t[66];const H=xe;if(!r){let U;t[67]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(R,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[67]=U):U=t[67];let be;t[68]!==e?(be=e("gitView.pullRequest.title"),t[68]=e,t[69]=be):be=t[69];let W;t[70]!==be?(W=s.jsx("div",{className:"typography-ui-header text-foreground",children:be}),t[70]=be,t[71]=W):W=t[71];let Ne;t[72]!==e?(Ne=e("gitView.pullRequest.createHint"),t[72]=e,t[73]=Ne):Ne=t[73];let Oe;t[74]!==Ne?(Oe=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:Ne}),t[74]=Ne,t[75]=Oe):Oe=t[75];let ye;return t[76]!==W||t[77]!==Oe?(ye=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[U,W,Oe]}),t[76]=W,t[77]=Oe,t[78]=ye):ye=t[78],ye}if(i===!1&&d!==!0){let U;t[79]!==r||t[80]!==f?(U=()=>{f(r,{force:!0})},t[79]=r,t[80]=f,t[81]=U):U=t[81];let be;return t[82]!==d||t[83]!==l||t[84]!==i||t[85]!==U?(be=s.jsx(lg,{rootIsGitRepo:i,resolvedIsGitRepo:d,nestedRepos:l,onRetryDiscovery:U}),t[82]=d,t[83]=l,t[84]=i,t[85]=U,t[86]=be):be=t[86],be}if(!me){let U;t[87]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(R,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[87]=U):U=t[87];let be;t[88]!==e?(be=e("gitView.pullRequest.title"),t[88]=e,t[89]=be):be=t[89];let W;t[90]!==be?(W=s.jsx("div",{className:"typography-ui-header text-foreground",children:be}),t[90]=be,t[91]=W):W=t[91];let Ne;t[92]!==e?(Ne=e("gitView.pullRequest.createHint"),t[92]=e,t[93]=Ne):Ne=t[93];let Oe;t[94]!==Ne?(Oe=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:Ne}),t[94]=Ne,t[95]=Oe):Oe=t[95];let ye;return t[96]!==W||t[97]!==Oe?(ye=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[U,W,Oe]}),t[96]=W,t[97]=Oe,t[98]=ye):ye=t[98],ye}const Ce=i===!1&&Array.isArray(l)&&l.length>0;let ve;t[99]!==r||t[100]!==o||t[101]!==l||t[102]!==p||t[103]!==Ce?(ve=Ce?s.jsx("div",{className:"flex shrink-0 items-center border-b border-border/60 px-4 py-2",children:s.jsx(cg,{repositories:l,selectedRepository:o??null,onSelectRepository:U=>{r&&p(r,U)},repositoryRoot:r??void 0})}):null,t[99]=r,t[100]=o,t[101]=l,t[102]=p,t[103]=Ce,t[104]=ve):ve=t[104];const re=o??r,le=a?.tracking??void 0;let se;t[105]!==H||t[106]!==me||t[107]!==ae||t[108]!==F||t[109]!==re||t[110]!==le?(se=s.jsx(Nn,{as:Aa,outerClassName:"h-full min-h-0 flex-1",className:"px-4 py-3",disableHorizontal:!0,preventOverscroll:!0,children:s.jsx(Gb,{directory:re,branch:me,baseBranch:H,trackingBranch:le,remotes:F,remoteBranches:ae})}),t[105]=H,t[106]=me,t[107]=ae,t[108]=F,t[109]=re,t[110]=le,t[111]=se):se=t[111];let G;return t[112]!==ve||t[113]!==se?(G=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[ve,se]}),t[112]=ve,t[113]=se,t[114]=G):G=t[114],G};function Yb(t){return{ensureAll:t.ensureAll,ensureNestedRepos:t.ensureNestedRepos,selectNestedRepo:t.selectNestedRepo}}function Xb(t){return t.currentSessionId}function Jb(t){return t.newSessionDraft}function Zb(t){return t.worktreeMetadata}function ey(t){return t.availableWorktrees}function ty(t){return!t.startsWith("remotes/")}function sy(t){return t.startsWith("remotes/")}function ny(t){return t.replace(/^remotes\//,"")}function ry(t){return t.name}const Zi=2e4,oy=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},ao=(t,e)=>Jf(Zf.getState().dictionary,t,e),iy=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")?"missing":"unreadable"},ay=async(t,e,n)=>{if(t.readFile)return(await t.readFile(e,{optional:!0,directory:n?.directory})).content??"";const r=new URLSearchParams({path:e,optional:"true"});n?.directory&&r.set("directory",n.directory);const i=await ds(`/api/fs/read?${r.toString()}`,{cache:"no-store",headers:n?.directory?{"x-opencode-directory":n.directory}:void 0});if(!i.ok){const o=await i.json().catch(()=>({error:i.statusText}));throw new Error(o.error||"Failed to read file")}return i.text()},Vu=async(t,e,n)=>{if(qf(e)||Qf(e)||Yf(e))return{ok:!0};try{const r=await ay(t,e,n);return Xf(r)?{ok:!1,reason:"binary"}:oy(r,Zi)>Zi?{ok:!1,reason:"too-large"}:{ok:!0}}catch(r){return{ok:!1,reason:iy(r)}}},Uu=t=>{if(t==="too-large"){const e=Zi.toLocaleString(ja());return ao("contextFileOpen.failure.tooLarge",{count:e})}return ao(t==="missing"?"contextFileOpen.failure.missing":t==="binary"?"filesView.editor.cannotPreviewBinary":"contextFileOpen.failure.unreadable")},Yl=8;let ea=null;const Ku=t=>{ea={x:t.clientX,y:t.clientY}},Hu=t=>{const e=ea;return ea=null,!e||t.dataTransfer&&t.dataTransfer.dropEffect!=="none"?!1:Math.abs(t.clientX-e.x)<=Yl&&Math.abs(t.clientY-e.y)<=Yl},Xl=3,fr=t=>Array.from(t.types).includes("Files"),ly=t=>{const e=Array.from(t.items);return e.length===0?Array.from(t.files):e.flatMap(n=>{if(n.kind!=="file"||n.webkitGetAsEntry()?.isDirectory)return[];const r=n.getAsFile();return r?[r]:[]})},Jl=t=>{const e=t.name;return!e||e==="."||e===".."||e.includes("/")||e.includes("\\")?null:e},cy=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),as=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},Va=(t,e)=>{const n=as(e),r=as(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},dy=(t,e)=>{const n=Va(t,e);if(n!==".")return n;const r=as(t);return r.split("/").filter(Boolean).pop()??r},uy=t=>{const e=as(t),n=e.lastIndexOf("/");return n<0?"":n===0?"/":e.slice(0,n)},my=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),fy=new Set(["node_modules"]),hy=t=>fy.has(t),py=t=>{const e=as(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},gy=8,fn=new Map,Ua=t=>JSON.stringify([ps(),t]),xy=t=>{const e=Ua(t),n=fn.get(e);return n?(n.touchedAt=Date.now(),fn.delete(e),fn.set(e,n),n):null},bi=t=>{const e=Ua(t),n=fn.get(e);if(n)return n.touchedAt=Date.now(),n;if(fn.size>=gy){const i=fn.keys().next().value;i!==void 0&&fn.delete(i)}const r={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return fn.set(e,r),r},by=t=>{fn.delete(Ua(t))},Gu=(t,e)=>s.jsx(Da,{filePath:t,extension:e}),yy=t=>{const e=nt.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const i=r[n];let o;return e[1]!==i?(o=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:i}}),e[1]=i,e[2]=o):o=e[2],o},wy=t=>{const e=nt.c(87),{node:n,root:r,isExpanded:i,isActive:o,isBrowserClient:l,status:a,badge:u,isDropTarget:d,canUpload:h,permissions:f,downloadFile:p,onSelect:g,onToggle:w,onRevealPath:v,onOpenDialog:x,onSetDropTarget:m,onDropFiles:b}=t,{t:y}=Nt(),S=n.type==="directory";let N;e[0]!==S||e[1]!==n.path?(N=S?n.path:uy(n.path),e[0]=S,e[1]=n.path,e[2]=N):N=e[2];const C=N,{canRename:j,canCreateFile:A,canCreateFolder:D,canDelete:I,canReveal:M}=f,$=!S&&!!p,E=M&&!l,K=j||A||D||I||$||E,[B,O]=c.useState(!1),[T,k]=c.useState(!1);let P;e[3]!==K?(P=U=>{K&&(U?.preventDefault(),k(!0))},e[3]=K,e[4]=P):P=e[4];const F=P;let q;e[5]!==S||e[6]!==n||e[7]!==g||e[8]!==w?(q=()=>{S?w(n.path):g(n)},e[5]=S,e[6]=n,e[7]=g,e[8]=w,e[9]=q):q=e[9];const Q=q;let Y;e[10]===Symbol.for("react.memo_cache_sentinel")?(Y=U=>{U.stopPropagation(),k(!1),O(!0)},e[10]=Y):Y=e[10];const ce=Y;let X;e[11]!==A||e[12]!==D||e[13]!==I||e[14]!==j||e[15]!==E||e[16]!==p||e[17]!==l||e[18]!==S||e[19]!==n||e[20]!==x||e[21]!==v||e[22]!==y?(X=U=>{const{Item:be,Separator:W}=U;return s.jsxs(s.Fragment,{children:[j&&s.jsxs(be,{onClick:Ne=>{Ne.stopPropagation(),x("rename",n)},children:[s.jsx(R,{name:"edit",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.rename")]}),s.jsxs(be,{onClick:Ne=>{Ne.stopPropagation(),pn(n.path).then(Oe=>{if(Oe.ok){Re.success(y("sidebarFilesTree.toast.pathCopied"));return}Re.error(y("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(R,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.copyPath")]}),!S&&p&&s.jsxs(be,{onClick:Ne=>{Ne.stopPropagation(),p(n.path).catch(Oe=>{console.error("Download failed:",Oe),Re.error(y("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(R,{name:"download",className:"mr-2 h-4 w-4"})," ",y(l?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),E&&s.jsxs(be,{onClick:Ne=>{Ne.stopPropagation(),v(n.path)},children:[s.jsx(R,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",y(jd())]}),S&&(A||D)&&s.jsxs(s.Fragment,{children:[s.jsx(W,{}),A&&s.jsxs(be,{onClick:Ne=>{Ne.stopPropagation(),x("createFile",n)},children:[s.jsx(R,{name:"file-add",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.newFile")]}),D&&s.jsxs(be,{onClick:Ne=>{Ne.stopPropagation(),x("createFolder",n)},children:[s.jsx(R,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.newFolder")]})]}),I&&s.jsxs(s.Fragment,{children:[s.jsx(W,{}),s.jsxs(be,{onClick:Ne=>{Ne.stopPropagation(),x("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.delete")]})]})]})},e[11]=A,e[12]=D,e[13]=I,e[14]=j,e[15]=E,e[16]=p,e[17]=l,e[18]=S,e[19]=n,e[20]=x,e[21]=v,e[22]=y,e[23]=X):X=e[23];const oe=X;let te;e[24]!==n.path||e[25]!==r?(te=U=>{Ku(U);const be=Va(r,n.path);!be||be==="."||(U.dataTransfer.setData("application/x-openchamber-file-path",be),U.dataTransfer.effectAllowed="copy")},e[24]=n.path,e[25]=r,e[26]=te):te=e[26];const he=te;let _;e[27]!==Q?(_=U=>{Hu(U)&&Q()},e[27]=Q,e[28]=_):_=e[28];const ie=_;let ge;e[29]!==h||e[30]!==m||e[31]!==C?(ge=U=>{!h||!C||!fr(U.dataTransfer)||(U.preventDefault(),U.stopPropagation(),U.dataTransfer.dropEffect="copy",m(C))},e[29]=h,e[30]=m,e[31]=C,e[32]=ge):ge=e[32];const ae=ge;let z;e[33]!==h||e[34]!==m||e[35]!==C?(z=U=>{!h||!C||!fr(U.dataTransfer)||U.relatedTarget instanceof Node&&U.currentTarget.contains(U.relatedTarget)||(U.stopPropagation(),m(null))},e[33]=h,e[34]=m,e[35]=C,e[36]=z):z=e[36];const ne=z;let ue;e[37]!==h||e[38]!==b||e[39]!==C?(ue=U=>{!h||!C||!fr(U.dataTransfer)||(U.preventDefault(),U.stopPropagation(),b(C,U.dataTransfer))},e[37]=h,e[38]=b,e[39]=C,e[40]=ue):ue=e[40];const me=ue;let ke;e[41]!==F||e[42]!==ne||e[43]!==ae||e[44]!==me?(ke=s.jsx("div",{className:"group relative flex items-center",onContextMenu:F,onDragEnter:ae,onDragOver:ae,onDragLeave:ne,onDrop:me}),e[41]=F,e[42]=ne,e[43]=ae,e[44]=me,e[45]=ke):ke=e[45];const Te=d?"bg-interactive-selection ring-2 ring-inset ring-primary":o?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let je;e[46]!==Te?(je=Ie("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",Te),e[46]=Te,e[47]=je):je=e[47];let Ee;e[48]!==S||e[49]!==i||e[50]!==n.extension||e[51]!==n.path?(Ee=S?i?s.jsx(R,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):s.jsx(R,{name:"folder-3",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):Gu(n.path,n.extension),e[48]=S,e[49]=i,e[50]=n.extension,e[51]=n.path,e[52]=Ee):Ee=e[52];let xe;e[53]!==n.name||e[54]!==n.path?(xe=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[53]=n.name,e[54]=n.path,e[55]=xe):xe=e[55];let H;e[56]!==S||e[57]!==a?(H=!S&&a&&s.jsx(yy,{status:a}),e[56]=S,e[57]=a,e[58]=H):H=e[58];let Ce;e[59]!==u||e[60]!==S?(Ce=S&&u&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[u.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",u.modified]}),u.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",u.added]})]}),e[59]=u,e[60]=S,e[61]=Ce):Ce=e[61];let ve;e[62]!==F||e[63]!==ie||e[64]!==he||e[65]!==Q||e[66]!==je||e[67]!==Ee||e[68]!==xe||e[69]!==H||e[70]!==Ce?(ve=s.jsxs("button",{type:"button",onClick:Q,onContextMenu:F,draggable:!0,onDragStart:he,onDragEnd:ie,className:je,children:[Ee,xe,H,Ce]}),e[62]=F,e[63]=ie,e[64]=he,e[65]=Q,e[66]=je,e[67]=Ee,e[68]=xe,e[69]=H,e[70]=Ce,e[71]=ve):ve=e[71];let re;e[72]!==B||e[73]!==K||e[74]!==oe||e[75]!==y?(re=K&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(Xs,{open:B,onOpenChange:O,children:[s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Qs,{asChild:!0,children:s.jsx(bt,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:ce,title:y("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":y("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(R,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:y("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(Ys,{align:"end",side:"bottom",onCloseAutoFocus:()=>O(!1),children:oe({Item:zt,Separator:Os})})]})}),e[72]=B,e[73]=K,e[74]=oe,e[75]=y,e[76]=re):re=e[76];let le;e[77]!==ke||e[78]!==ve||e[79]!==re?(le=s.jsxs(cu,{render:ke,children:[ve,re]}),e[77]=ke,e[78]=ve,e[79]=re,e[80]=le):le=e[80];let se;e[81]!==oe?(se=s.jsx(lu,{className:"min-w-[180px]",children:oe({Item:Kn,Separator:zi})}),e[81]=oe,e[82]=se):se=e[82];let G;return e[83]!==T||e[84]!==le||e[85]!==se?(G=s.jsxs(du,{open:T,onOpenChange:k,children:[le,se]}),e[83]=T,e[84]=le,e[85]=se,e[86]=G):G=e[86],G},Sy=(t,e)=>t.node===e.node&&t.root===e.root&&t.isExpanded===e.isExpanded&&t.isActive===e.isActive&&t.isBrowserClient===e.isBrowserClient&&t.status===e.status&&t.badge===e.badge&&t.isDropTarget===e.isDropTarget&&t.canUpload===e.canUpload&&t.permissions===e.permissions&&t.downloadFile===e.downloadFile&&t.onSelect===e.onSelect&&t.onToggle===e.onToggle&&t.onRevealPath===e.onRevealPath&&t.onOpenDialog===e.onOpenDialog&&t.onSetDropTarget===e.onSetDropTarget&&t.onDropFiles===e.onDropFiles,vy=c.memo(wy,Sy),jy=()=>{const{t}=Nt(),{files:e,runtime:n}=wn(),r=rf(n.platform),i=Sr()??"",o=as(i.trim()),l=of(),a=af(),u=gd(J=>J.searchFiles),d=Pe(J=>J.openContextFile),h=Na(i),[f,p]=c.useState(""),g=Pa(f,200),w=c.useRef(null),[v,x]=c.useState([]),[m,b]=c.useState(!1),[y,S]=c.useState(null),[N,C]=c.useState(!1),[j,A]=c.useState(null),D=c.useRef(!1),I=c.useRef(o);I.current=o;const[M,$]=c.useState({}),[E,K]=c.useState({}),B=c.useRef(new Set),O=c.useRef(new Set),T=c.useRef(null);c.useEffect(()=>{if(S(null),A(null),!o){$({}),K({}),B.current=new Set;return}const J=xy(o);J?($({...J.childrenByDir}),K({...J.loadErrorsByDir}),B.current=new Set(J.loadedDirs)):($({}),K({}),B.current=new Set)},[o]),c.useEffect(()=>{if(!o)return;const J=bi(o);J.childrenByDir=M},[o,M]),c.useEffect(()=>{if(!o)return;const J=bi(o);J.loadErrorsByDir=E},[o,E]),c.useEffect(()=>{if(!o)return;const J=bi(o);J.loadedDirs=new Set(B.current)},[o,M,E]),c.useEffect(()=>()=>{if(!o)return;const J=fn.get(o);J&&J.loadedDirs.size===0&&Object.keys(J.childrenByDir).length===0&&by(o)},[o]);const k=c.useMemo(()=>[],[]),P=c.useMemo(()=>[],[]),F=mn(J=>o?J.byRoot[o]?.expandedPaths??k:k),q=mn(J=>o?J.byRoot[o]?.selectedPath??null:null),Q=mn(J=>J.setSelectedPath),Y=mn(J=>J.addOpenPath),ce=mn(J=>J.removeOpenPathsByPrefix),X=mn(J=>J.toggleExpandedPath),oe=mn(J=>J.collapseAllExpandedPaths),te=Pe(J=>o?J.contextPanelByDirectory[o]?.tabs??P:P),he=c.useMemo(()=>new Set(te.map(J=>J.mode==="file"?J.targetPath:null).filter(J=>typeof J=="string"&&J.length>0).map(J=>as(J))),[te]),[_,ie]=c.useState(null),[ge,ae]=c.useState(null),[z,ne]=c.useState(""),[ue,me]=c.useState(!1),ke=!!e.writeFile,Te=!!e.createDirectory,je=!!e.rename,Ee=!!e.delete,xe=!!e.revealPath,H=!!e.uploadFile,Ce=c.useMemo(()=>({canRename:je,canCreateFile:ke,canCreateFolder:Te,canDelete:Ee,canReveal:xe}),[je,ke,Te,Ee,xe]),ve=c.useCallback(J=>{e.revealPath&&e.revealPath(J).catch(()=>{Re.error(t("sidebarFilesTree.toast.revealFailed"))})},[e,t]),re=c.useCallback((J,Se)=>{ie(J),ae(Se),ne(J==="rename"&&Se.name||""),me(!1)},[]),le=c.useCallback((J,Se)=>{const Ve=Se.filter(He=>He&&typeof He.name=="string"&&He.name.length>0).filter(He=>l||!He.name.startsWith(".")).filter(He=>a||!hy(He.name)).map(He=>{const it=He.name,Ue=as(He.path||""),st=Ue?my(Ue)?Ue:as(`${J}/${Ue}`):as(`${J}/${it}`),ee=He.isDirectory?"directory":"file",ze=ee==="file"&&it.includes(".")?it.split(".").pop()?.toLowerCase():void 0;return{name:it,path:st,type:ee,extension:ze}});return cy(Ve)},[a,l]),se=c.useCallback(async(J,Se)=>{const Ve=as(J.trim());if(!Ve||B.current.has(Ve)||O.current.has(Ve))return;O.current=new Set(O.current),O.current.add(Ve);const He=e.listDirectory?e.listDirectory(Ve).then(it=>it.entries.map(Ue=>({name:Ue.name,path:Ue.path,isDirectory:Ue.isDirectory}))):qs.listLocalDirectory(Ve).then(it=>it.map(Ue=>({name:Ue.name,path:Ue.path,isDirectory:Ue.isDirectory})));try{const it=await He;if(Se?.())return;const Ue=le(Ve,it);B.current=new Set(B.current),B.current.add(Ve),K(st=>{if(!st[Ve])return st;const ee={...st};return delete ee[Ve],ee}),$(st=>({...st,[Ve]:Ue}))}catch(it){if(Se?.())return;const Ue=it instanceof Error?it.message:String(it??"");console.error("Failed to load sidebar directory:",it),K(st=>({...st,[Ve]:Ue}))}finally{O.current=new Set(O.current),O.current.delete(Ve)}},[e,le]),G=c.useCallback(async()=>{if(!o)return;T.current?.abort();const J=new AbortController;T.current=J;try{const Ve=(mn.getState().byRoot[o]?.expandedPaths??[]).map(Ue=>as(Ue)).filter(Ue=>!!Ue&&Ue!==o&&Ue.startsWith(`${o}/`)),He=[o,...Ve];B.current=new Set(B.current);for(const Ue of He)B.current.delete(Ue);K(Ue=>{if(Object.keys(Ue).length===0)return Ue;const st={...Ue};let ee=!1;for(const ze of He)ze in st&&(delete st[ze],ee=!0);return ee?st:Ue});const it=()=>J.signal.aborted;await se(o,it);for(let Ue=0;Ue<Ve.length&&!J.signal.aborted;Ue+=3){const st=Ve.slice(Ue,Ue+3);await Promise.all(st.map(ee=>se(ee,it)))}}catch(Se){if(J.signal.aborted)return;console.error("Failed to refresh sidebar tree:",Se)}finally{T.current===J&&(T.current=null)}},[se,o]),U=c.useCallback(async J=>{if(!J){await G();return}const Se=as(J);B.current=new Set(B.current),B.current.delete(Se),O.current=new Set(O.current),O.current.delete(Se),await se(Se)},[se,G]);c.useEffect(()=>{o&&(T.current?.abort(),B.current=new Set,O.current=new Set,K({}),$(J=>Object.keys(J).length===0?J:{}),se(o))},[se,o,l,a]),c.useEffect(()=>{if(!o||F.length===0)return;const J=F.map(He=>as(He)).filter(He=>!!He&&He!==o&&He.startsWith(`${o}/`)&&!B.current.has(He)&&!O.current.has(He)).sort((He,it)=>He.split("/").length-it.split("/").length);if(J.length===0)return;let Se=!1;const Ve=()=>Se;return(async()=>{for(let He=0;He<J.length&&!Se;He+=3){const it=J.slice(He,He+3);await Promise.all(it.map(Ue=>se(Ue,Ve)))}})(),()=>{Se=!0}},[F,se,o]),c.useEffect(()=>{if(!i){x([]),b(!1);return}const J=g.trim();if(!J){x([]),b(!1);return}let Se=!1;return b(!0),u(i,J,150,{includeHidden:l,respectGitignore:!a,type:"file"}).then(Ve=>{if(Se)return;const it=Ve.filter(Ue=>a||!py(Ue.path)).map(Ue=>({name:Ue.name,path:as(Ue.path),type:"file",extension:Ue.extension,relativePath:Ue.relativePath}));x(it)}).catch(()=>{Se||x([])}).finally(()=>{Se||b(!1)}),()=>{Se=!0}},[i,g,u,l,a]);const be=c.useMemo(()=>{const J=new Map;if(!h?.files)return J;for(const Se of h.files)Se.index==="A"||Se.working_dir==="?"?J.set(Se.path,"git-added"):Se.index==="D"?J.set(Se.path,"git-deleted"):(Se.index==="M"||Se.working_dir==="M")&&J.set(Se.path,"git-modified");return J},[h]),W=c.useMemo(()=>{const J=new Map;if(!h?.files||!o)return J;for(const Se of h.files){const Ve=Se.index==="M"||Se.working_dir==="M",He=Se.index==="A"||Se.working_dir==="?";if(!Ve&&!He)continue;const it=Se.path.split("/");if(it.length<=1)continue;let Ue=o;for(let st=0;st<it.length-1;st++){Ue=`${Ue}/${it[st]}`;let ee=J.get(Ue);ee||(ee={modified:0,added:0},J.set(Ue,ee)),Ve&&ee.modified++,He&&ee.added++}}return J},[h,o]),Ne=c.useCallback(J=>{if(he.has(J))return"open";if(be.size===0)return null;const Se=J.startsWith(o+"/")?J.slice(o.length+1):J;return be.get(Se)??null},[he,be,o]),Oe=c.useCallback(J=>{if(W.size===0)return null;const Se=W.get(J);return Se&&Se.modified+Se.added>0?Se:null},[W]),ye=c.useCallback(async J=>{if(!o)return;const Se=await Vu(e,J.path,{directory:o});if(!Se.ok){Re.error(Uu(Se.reason));return}Q(o,J.path),Y(o,J.path),d(o,J.path)},[Y,e,d,o,Q]),Fe=c.useCallback(async J=>{const Se=as(J);o&&(X(o,Se),B.current.has(Se)||await se(Se))},[se,o,X]),Ke=c.useCallback(async(J,Se,Ve=!1)=>{const He=e.uploadFile;if(!He||Se.length===0||D.current||!o)return;const it=o,Ue=ps();D.current=!0,C(!0),S(J),Ve&&A(null);const st=[];for(let tt=0;tt<Se.length;tt+=Xl){const pt=Se.slice(tt,tt+Xl),gt=await Promise.all(pt.map(async Je=>{const St=Jl(Je);if(!St||ps()!==Ue)return"failed";try{return(await He(as(`${J}/${St}`),Je,{directory:it,overwrite:Ve})).success?"uploaded":"failed"}catch(Ze){return!Ve&&lf(Ze)&&Ze.reason==="already-exists"?"conflict":"failed"}}));st.push(...gt)}const ee=st.filter(tt=>tt==="uploaded").length,ze=st.filter(tt=>tt==="failed").length,_e=Se.filter((tt,pt)=>st[pt]==="conflict"),pe=Se.flatMap((tt,pt)=>{const gt=Jl(tt);return st[pt]==="uploaded"&>?[as(`${J}/${gt}`)]:[]}),qe=I.current===it&&ps()===Ue;try{pe.length>0&&Eg({runtimeKey:Ue,paths:pe}),ee>0&&qe&&await U(J),ee>0&&Re.success(t(_e.length>0?"sidebarFilesTree.toast.uploadedWithoutConflicts":"sidebarFilesTree.toast.uploaded")),ze>0&&Re.error(t("sidebarFilesTree.toast.uploadFailed")),_e.length>0&&qe&&A({directory:J,files:_e,runtimeKey:Ue,workspaceRoot:it})}finally{D.current=!1,C(!1),S(null)}},[e.uploadFile,U,o,t]),$e=c.useCallback((J,Se)=>{const Ve=ly(Se);Ve.length!==0&&Ke(J,Ve)},[Ke]),V=c.useCallback(J=>{!H||D.current||!o||!fr(J.dataTransfer)||(J.preventDefault(),J.dataTransfer.dropEffect="copy",S(o))},[H,o]),fe=c.useCallback(J=>{fr(J.dataTransfer)&&(J.relatedTarget instanceof Node&&J.currentTarget.contains(J.relatedTarget)||S(null))},[]),Me=c.useCallback(J=>{!H||D.current||!o||!fr(J.dataTransfer)||(J.preventDefault(),$e(o,J.dataTransfer))},[H,$e,o]),De=c.useCallback(async J=>{if(J?.preventDefault(),!ge||!_)return;me(!0);const Se=()=>me(!1),Ve=()=>ie(null);if(_==="createFile"){if(!z.trim()){Re.error(t("sidebarFilesTree.toast.filenameRequired")),Se();return}if(!e.writeFile){Re.error(t("sidebarFilesTree.toast.writeNotSupported")),Se();return}const He=ge.path,it=He?`${He}/`:"",Ue=as(`${it}${z.trim()}`);await e.writeFile(Ue,"").then(async st=>{st.success&&(Re.success(t("sidebarFilesTree.toast.fileCreated")),await U(He)),Ve()}).catch(()=>Re.error(t("sidebarFilesTree.toast.operationFailed"))).finally(Se);return}if(_==="createFolder"){if(!z.trim()){Re.error(t("sidebarFilesTree.toast.folderNameRequired")),Se();return}const He=ge.path,it=He?`${He}/`:"",Ue=as(`${it}${z.trim()}`);await e.createDirectory(Ue).then(async st=>{st.success&&(Re.success(t("sidebarFilesTree.toast.folderCreated")),await U(He)),Ve()}).catch(()=>Re.error(t("sidebarFilesTree.toast.operationFailed"))).finally(Se);return}if(_==="rename"){if(!z.trim()){Re.error(t("sidebarFilesTree.toast.nameRequired")),Se();return}if(!e.rename){Re.error(t("sidebarFilesTree.toast.renameNotSupported")),Se();return}const He=ge.path,it=He.split("/").slice(0,-1).join("/"),Ue=it?`${it}/`:"",st=as(`${Ue}${z.trim()}`);await e.rename(He,st).then(async ee=>{ee.success&&(Re.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await U(it),o&&ce(o,He),(q===He||q&&q.startsWith(`${He}/`))&&Q(o,null)),Ve()}).catch(()=>Re.error(t("sidebarFilesTree.toast.operationFailed"))).finally(Se);return}if(_==="delete"){if(!e.delete){Re.error(t("sidebarFilesTree.toast.deleteNotSupported")),Se();return}const He=ge.path,it=He.split("/").slice(0,-1).join("/");await e.delete(He).then(async Ue=>{Ue.success&&(Re.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await U(it),o&&ce(o,He),(q===He||q&&q.startsWith(He+"/"))&&Q(o,null)),Ve()}).catch(()=>Re.error(t("sidebarFilesTree.toast.operationFailed"))).finally(Se);return}Se()},[_,ge,z,e,U,ce,o,q,Q,t]);function at(J,Se){const Ve=M[J]??[];return Ve.map((He,it)=>{const Ue=He.type==="directory",st=Ue&&F.includes(He.path),ee=q===He.path,ze=it===Ve.length-1;return s.jsxs("li",{className:"relative",children:[Se>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),ze&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(vy,{node:He,root:o,isExpanded:st,isActive:ee,isBrowserClient:r,status:Ue?void 0:Ne(He.path),badge:Ue?Oe(He.path):void 0,isDropTarget:Ue&&y===He.path,canUpload:H&&!N,permissions:Ce,downloadFile:e.downloadFile,onSelect:ye,onToggle:Fe,onRevealPath:ve,onOpenDialog:re,onSetDropTarget:S,onDropFiles:$e}),Ue&&st&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[E[He.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:E[He.path],children:E[He.path]}),s.jsxs(bt,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{U(He.path)},children:[s.jsx(R,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):null,at(He.path,Se+1)]})]},He.path)})}const Qe=!!(o&&M[o]),lt=o?E[o]:null,de=y?dy(o,y):"";return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[ke&&s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(bt,{variant:"ghost",size:"sm",onClick:()=>re("createFile",{path:i,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFileTitle"),"aria-label":t("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(R,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFileTitle")})]}),Te&&s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(bt,{variant:"ghost",size:"sm",onClick:()=>re("createFolder",{path:i,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFolderTitle"),"aria-label":t("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(R,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFolderTitle")})]}),s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(bt,{variant:"ghost",size:"sm",onClick:()=>{G()},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.refreshTitle"),"aria-label":t("sidebarFilesTree.actions.refreshTitle"),children:s.jsx(R,{name:"refresh",className:"h-4 w-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.refreshTitle")})]}),s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(bt,{variant:"ghost",size:"sm",onClick:()=>{o&&oe(o)},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.collapseAllTitle"),"aria-label":t("sidebarFilesTree.actions.collapseAllTitle"),children:s.jsx(R,{name:"collapse-vertical",className:"h-4 w-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.collapseAllTitle")})]})]}),s.jsxs("div",{className:"relative min-w-0",children:[s.jsx(R,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Cn,{ref:w,value:f,onChange:J=>p(J.target.value),placeholder:t("sidebarFilesTree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),f.trim().length>0?s.jsx("button",{type:"button","aria-label":t("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{p(""),w.current?.focus()},children:s.jsx(R,{name:"close",className:"h-4 w-4"})}):null]})]}),s.jsxs("div",{className:"relative flex-1 min-h-0",children:[s.jsx(Nn,{outerClassName:"h-full min-h-0",className:Ie("p-2",y===o&&"bg-interactive-selection/10"),onDragEnter:V,onDragOver:V,onDragLeave:fe,onDrop:Me,children:s.jsx("ul",{className:"flex flex-col",children:m?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(R,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("sidebarFilesTree.state.searching")]}):v.length>0?v.map(J=>{const Se=q===J.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>ye(J),draggable:!0,onDragStart:Ve=>{Ku(Ve);const He=J.relativePath||Va(o??"",J.path);!He||He==="."||(Ve.dataTransfer.setData("application/x-openchamber-file-path",He),Ve.dataTransfer.effectAllowed="copy")},onDragEnd:Ve=>{Hu(Ve)&&ye(J)},className:Ie("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",Se?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:J.path,children:[Gu(J.path,J.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:J.relativePath??J.path})]})},J.path)}):lt?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:lt}),s.jsxs(bt,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{G()},children:[s.jsx(R,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):Qe&&o?at(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("sidebarFilesTree.state.loading")})})}),y?s.jsxs("div",{className:"pointer-events-none absolute left-2 right-2 top-2 z-50 flex items-center gap-2 rounded-md border border-primary bg-background/95 px-2 py-1.5 shadow-sm",children:[s.jsx(R,{name:N?"loader-4":"folder-received",className:Ie("size-4 flex-shrink-0",N&&"animate-spin")}),s.jsx("span",{className:"min-w-0 truncate typography-meta",title:de,children:t(N?"sidebarFilesTree.drop.uploading":"sidebarFilesTree.drop.target",{path:de})})]}):null]}),s.jsx(ws,{open:!!j,onOpenChange:J=>!J&&A(null),children:s.jsxs(Ss,{children:[s.jsxs(Ws,{children:[s.jsx(Is,{children:t("sidebarFilesTree.dialog.uploadConflicts.title")}),s.jsx(Ts,{children:t("sidebarFilesTree.dialog.uploadConflicts.description",{path:j?.directory??""})})]}),s.jsx(Nn,{outerClassName:"max-h-52",className:"flex flex-col gap-1 pr-2",children:j?.files.map((J,Se)=>s.jsx("div",{className:"truncate rounded-md bg-muted px-2 py-1 typography-meta",title:J.name,children:J.name},`${J.name}-${J.size}-${Se}`))}),s.jsxs(bn,{children:[s.jsx(bt,{variant:"outline",onClick:()=>A(null),disabled:N,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(bt,{onClick:()=>{if(j){if(j.runtimeKey!==ps()||j.workspaceRoot!==o){A(null);return}Ke(j.directory,j.files,!0)}},disabled:N,children:t("sidebarFilesTree.dialog.uploadConflicts.replace")})]})]})}),s.jsx(ws,{open:!!_,onOpenChange:J=>!J&&ie(null),children:s.jsxs(Ss,{children:[s.jsxs(Ws,{children:[s.jsxs(Is,{children:[_==="createFile"&&t("sidebarFilesTree.dialog.createFile.title"),_==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.title"),_==="rename"&&t("sidebarFilesTree.dialog.rename.title"),_==="delete"&&t("sidebarFilesTree.dialog.delete.title")]}),s.jsxs(Ts,{children:[_==="createFile"&&t("sidebarFilesTree.dialog.createFile.description",{path:ge?.path??t("sidebarFilesTree.dialog.rootFallback")}),_==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.description",{path:ge?.path??t("sidebarFilesTree.dialog.rootFallback")}),_==="rename"&&t("sidebarFilesTree.dialog.rename.description",{name:ge?.name??""}),_==="delete"&&t("sidebarFilesTree.dialog.delete.description",{name:ge?.name??""})]})]}),_!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Cn,{value:z,onChange:J=>ne(J.target.value),placeholder:t(_==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:J=>{J.key==="Enter"&&De()},autoFocus:!0})}),s.jsxs(bn,{children:[s.jsx(bt,{variant:"outline",onClick:()=>ie(null),disabled:ue,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(bt,{variant:_==="delete"?"destructive":"default",onClick:()=>{De()},disabled:ue||_!=="delete"&&!z.trim(),children:ue?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):t(_==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})},Zl=60,ky=t=>{try{return new URL(t).origin}catch{return""}},yi=new Set,qu=tr()((t,e)=>({byOrigin:{},resolve:(n,r)=>{const i=ky(n);!i||!r||e().byOrigin[i]||yi.has(i)||(yi.add(i),mr("desktop_browser_fetch_favicon",{url:r}).then(o=>{const l=typeof o?.dataUrl=="string"?o.dataUrl:"";l&&t(a=>{const u={...a.byOrigin,[i]:l},d=Object.keys(u);if(d.length<=Zl)return{byOrigin:u};for(const h of d.slice(0,d.length-Zl))delete u[h];return{byOrigin:u}})}).catch(()=>{}).finally(()=>{yi.delete(i)}))}})),Ka=t=>t,ta=t=>{const e=Ka(t).type;return typeof e=="string"?e:""},Cy=t=>{const e=Ka(t).tool;return typeof e=="string"?e:""},Ny=t=>{const e=Ka(t).text;return typeof e=="string"?e:""},Ay=t=>{const e=ta(t);return e==="tool"?Cy(t).trim().toLowerCase()||"tool":e||"unknown"},Dy=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=Ay(n);e.includes(r)||e.push(r)}return e.join(" + ")},Py=t=>t.replace(/\s+/g," ").trim(),Iy=t=>{for(const n of t)if(ta(n)==="text"){const r=Py(Ny(n));if(r.length===0)continue;return r}const e=t.filter(n=>ta(n)!=="text").length;return e===0?"":`${e} attachment${e===1?"":"s"}`},Ty=(t,e,n)=>`${n(t)} / ${n(e)}`,Ey=t=>{if(t==="12h")return!0;if(t==="24h")return!1},Ry=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=Ey(e);return new Date(t).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:n===!1?"2-digit":"numeric",minute:"2-digit",...n===void 0?{}:{hour12:n}})},sa={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},vo={user:0,assistant:0,tool:0,other:0},Rn=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,wi=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(h=>h.tokens!==void 0)?.tokens;if(typeof n=="number")return{...sa,total:Rn(n)};if(!n||typeof n!="object")return sa;const r=n,i=Rn(r.input),o=Rn(r.output),l=Rn(r.reasoning),a=Rn(r.cache?.read),u=Rn(r.cache?.write),d=Rn(r.total);return{input:i,output:o,reasoning:l,cacheRead:a,cacheWrite:u,total:d>0?d:i+o+l+a+u}},My=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},Us=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+Us(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+Us(n),0):0,Oy=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...vo,assistant:Us(n.text)+Us(n.content)};const i=My(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:Us(n.input)+Us(n.output)+Us(n.error)+Us(n.call?.input)+Us(n.call?.output)+Us(n.call?.error)+Us(n.raw)+Math.round(Us(n.metadata)*.25)+Math.round(Us(n.state)*.1),other:0}:e==="user"?{user:i.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:i.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:i.length}},ec=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),By=t=>{const e=Zr(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},Fy=(t,e)=>{if(t.length===0)return{...vo};const n=t.reduce((r,i)=>{const o=By(i);let l={...vo};for(const a of i.parts)l=ec(l,Oy(a,o));return ec(r,l)},{...vo});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},Un=t=>t.toLocaleString(ja()),_y=(t,e)=>!t||!Number.isFinite(t)?"-":Td(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),Ly=(t,e,n)=>{const r=t.find(o=>o.id===e),i=r?.models?.find(o=>o.id===n);return{providerName:r?.name||e||"-",modelName:i?.name||n||"-",contextLimit:typeof i?.limit?.context=="number"?i.limit.context:null}},$y=()=>{const t=nt.c(203),{t:e}=Nt(),n=Pe(Wy);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0];const[i,o]=c.useState(r),[l,a]=c.useState(null),u=c.useRef(null),d=et(zy),h=et(Vy),f=Md(h??void 0),p=eh(d??"",h??void 0),g=Ht(Uy);let w;t[1]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null),o(Ky),a(null)},t[1]=w):w=t[1];let v;t[2]!==h||t[3]!==d?(v=[h,d],t[2]=h,t[3]=d,t[4]=v):v=t[4],c.useEffect(w,v);let x,m;t[5]===Symbol.for("react.memo_cache_sentinel")?(x=()=>()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},m=[],t[5]=x,t[6]=m):(x=t[5],m=t[6]),c.useEffect(x,m);let b;t[7]===Symbol.for("react.memo_cache_sentinel")?(b=async(vt,rt)=>{(await pn(rt)).ok?(a(vt),u.current!==null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{a(ct=>ct===vt?null:ct),u.current=null},2e3)):a(null)},t[7]=b):b=t[7];const y=b;let S;t[8]!==d||t[9]!==f?(S=d?f.find(vt=>vt.id===d)??null:null,t[8]=d,t[9]=f,t[10]=S):S=t[10];const N=S;let C,j,A,D,I,M;if(t[11]!==g||t[12]!==p){C=p.filter(Hy);let vt;t[19]!==p?(vt=p.filter(Gy),t[19]=p,t[20]=vt):vt=t[20],M=vt;let rt=null;for(let ct=C.length-1;ct>=0;ct=ct-1,ct){const dt=C[ct];if(wi(dt).total>0){rt=dt;break}}D=rt?wi(rt):sa,j=th({input:D.input,cache:{read:D.cacheRead,write:D.cacheWrite}}),I=C.reduce(qy,0);const we=rt?.info??null;A=Ly(g,we?.providerID||"",we?.modelID||""),t[11]=g,t[12]=p,t[13]=C,t[14]=j,t[15]=A,t[16]=D,t[17]=I,t[18]=M}else C=t[13],j=t[14],A=t[15],D=t[16],I=t[17],M=t[18];const $=A,E=$.contextLimit,K=E&&E>0?Math.min(999,D.total/E*100):0;let B;if(t[21]!==p){const vt=[...p].reverse().find(Qy)?.info?.system||"";B=Fy(p,vt),t[21]=p,t[22]=B}else B=t[22];const O=B,T=O.user,k=O.assistant,P=O.tool,F=Math.max(0,D.input-T-k-P),q=T+k+P+F,Q=p[0]?.info?.time?.created,Y=p.length>0?p[p.length-1]?.info?.time?.created:null;let ce;t[23]!==N?.title||t[24]!==e?(ce=N?.title||e("contextSidebar.session.untitled"),t[23]=N?.title,t[24]=e,t[25]=ce):ce=t[25];const X=N?.time?.created??Q??null,oe=Y??N?.time?.created??null;let te;t[26]!==k||t[27]!==F||t[28]!==P||t[29]!==T?(te={user:T,assistant:k,tool:P,other:F},t[26]=k,t[27]=F,t[28]=P,t[29]=T,t[30]=te):te=t[30];let he;t[31]!==C.length||t[32]!==q||t[33]!==j||t[34]!==E||t[35]!==$||t[36]!==p.length||t[37]!==X||t[38]!==oe||t[39]!==te||t[40]!==ce||t[41]!==D||t[42]!==I||t[43]!==K||t[44]!==M.length?(he={sessionTitle:ce,messagesCount:p.length,userMessagesCount:M.length,assistantMessagesCount:C.length,createdAt:X,lastActivityAt:oe,providerModel:$,tokenBreakdown:D,usagePercent:K,cacheHitRate:j,totalAssistantCost:I,contextLimit:E,breakdown:te,breakdownTotal:q},t[31]=C.length,t[32]=q,t[33]=j,t[34]=E,t[35]=$,t[36]=p.length,t[37]=X,t[38]=oe,t[39]=te,t[40]=ce,t[41]=D,t[42]=I,t[43]=K,t[44]=M.length,t[45]=he):he=t[45];const _=he;if(!d){let vt;t[46]!==e?(vt=e("contextSidebar.empty.openSession"),t[46]=e,t[47]=vt):vt=t[47];let rt;return t[48]!==vt?(rt=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:vt}),t[48]=vt,t[49]=rt):rt=t[49],rt}let ie;t[50]!==e?(ie=e("contextSidebar.breakdown.user"),t[50]=e,t[51]=ie):ie=t[51];let ge;t[52]!==ie||t[53]!==_.breakdown.user?(ge={key:"user",label:ie,value:_.breakdown.user,color:"var(--status-success)"},t[52]=ie,t[53]=_.breakdown.user,t[54]=ge):ge=t[54];let ae;t[55]!==e?(ae=e("contextSidebar.breakdown.assistant"),t[55]=e,t[56]=ae):ae=t[56];let z;t[57]!==ae||t[58]!==_.breakdown.assistant?(z={key:"assistant",label:ae,value:_.breakdown.assistant,color:"var(--primary-base)"},t[57]=ae,t[58]=_.breakdown.assistant,t[59]=z):z=t[59];let ne;t[60]!==e?(ne=e("contextSidebar.breakdown.toolCalls"),t[60]=e,t[61]=ne):ne=t[61];let ue;t[62]!==ne||t[63]!==_.breakdown.tool?(ue={key:"tool",label:ne,value:_.breakdown.tool,color:"var(--status-warning)"},t[62]=ne,t[63]=_.breakdown.tool,t[64]=ue):ue=t[64];let me;t[65]!==e?(me=e("contextSidebar.breakdown.other"),t[65]=e,t[66]=me):me=t[66];let ke;t[67]!==me||t[68]!==_.breakdown.other?(ke={key:"other",label:me,value:_.breakdown.other,color:"var(--surface-muted-foreground)"},t[67]=me,t[68]=_.breakdown.other,t[69]=ke):ke=t[69];let Te;t[70]!==ge||t[71]!==z||t[72]!==ue||t[73]!==ke?(Te=[ge,z,ue,ke],t[70]=ge,t[71]=z,t[72]=ue,t[73]=ke,t[74]=Te):Te=t[74];const je=Te;let Ee;t[75]!==_.sessionTitle?(Ee=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:_.sessionTitle}),t[75]=_.sessionTitle,t[76]=Ee):Ee=t[76];let xe;t[77]!==_.providerModel.modelName||t[78]!==_.providerModel.providerName?(xe=s.jsxs("span",{children:[_.providerModel.providerName," / ",_.providerModel.modelName]}),t[77]=_.providerModel.modelName,t[78]=_.providerModel.providerName,t[79]=xe):xe=t[79];let H;t[80]!==n||t[81]!==_.createdAt?(H=_.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:_y(_.createdAt,n)})]}),t[80]=n,t[81]=_.createdAt,t[82]=H):H=t[82];let Ce;t[83]!==xe||t[84]!==H?(Ce=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[xe,H]}),t[83]=xe,t[84]=H,t[85]=Ce):Ce=t[85];let ve;t[86]!==Ee||t[87]!==Ce?(ve=s.jsxs("div",{className:"mb-6",children:[Ee,Ce]}),t[86]=Ee,t[87]=Ce,t[88]=ve):ve=t[88];let re;t[89]!==e?(re=e("contextSidebar.section.context"),t[89]=e,t[90]=re):re=t[90];let le;t[91]!==re?(le=s.jsx("span",{className:"typography-micro text-muted-foreground",children:re}),t[91]=re,t[92]=le):le=t[92];let se;t[93]!==_.tokenBreakdown.total?(se=Un(_.tokenBreakdown.total),t[93]=_.tokenBreakdown.total,t[94]=se):se=t[94];let G;t[95]!==_.contextLimit?(G=_.contextLimit?` / ${Un(_.contextLimit)}`:"",t[95]=_.contextLimit,t[96]=G):G=t[96];let U;t[97]!==se||t[98]!==G?(U=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[se,G]}),t[97]=se,t[98]=G,t[99]=U):U=t[99];let be;t[100]!==le||t[101]!==U?(be=s.jsxs("div",{className:"flex items-baseline justify-between",children:[le,U]}),t[100]=le,t[101]=U,t[102]=be):be=t[102];let W;t[103]!==_.usagePercent?(W=_.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,_.usagePercent)}%`,backgroundColor:_.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[103]=_.usagePercent,t[104]=W):W=t[104];let Ne;t[105]!==W?(Ne=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:W}),t[105]=W,t[106]=Ne):Ne=t[106];let Oe;t[107]!==e||t[108]!==_.usagePercent?(Oe=e("contextSidebar.context.percentUsed",{percent:_.usagePercent.toFixed(1)}),t[107]=e,t[108]=_.usagePercent,t[109]=Oe):Oe=t[109];let ye;t[110]!==Oe?(ye=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Oe}),t[110]=Oe,t[111]=ye):ye=t[111];let Fe;t[112]!==be||t[113]!==Ne||t[114]!==ye?(Fe=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[be,Ne,ye]}),t[112]=be,t[113]=Ne,t[114]=ye,t[115]=Fe):Fe=t[115];let Ke;t[116]!==e?(Ke=e("contextSidebar.stats.messages"),t[116]=e,t[117]=Ke):Ke=t[117];let $e;t[118]!==_.messagesCount?($e=Un(_.messagesCount),t[118]=_.messagesCount,t[119]=$e):$e=t[119];let V;t[120]!==Ke||t[121]!==$e?(V={label:Ke,value:$e},t[120]=Ke,t[121]=$e,t[122]=V):V=t[122];let fe;t[123]!==e?(fe=e("contextSidebar.stats.user"),t[123]=e,t[124]=fe):fe=t[124];let Me;t[125]!==_.userMessagesCount?(Me=Un(_.userMessagesCount),t[125]=_.userMessagesCount,t[126]=Me):Me=t[126];let De;t[127]!==fe||t[128]!==Me?(De={label:fe,value:Me},t[127]=fe,t[128]=Me,t[129]=De):De=t[129];let at;t[130]!==e?(at=e("contextSidebar.stats.assistant"),t[130]=e,t[131]=at):at=t[131];let Qe;t[132]!==_.assistantMessagesCount?(Qe=Un(_.assistantMessagesCount),t[132]=_.assistantMessagesCount,t[133]=Qe):Qe=t[133];let lt;t[134]!==at||t[135]!==Qe?(lt={label:at,value:Qe},t[134]=at,t[135]=Qe,t[136]=lt):lt=t[136];let de;t[137]!==e?(de=e("contextSidebar.stats.cost"),t[137]=e,t[138]=de):de=t[138];let J;t[139]!==_.totalAssistantCost?(J=Jp(_.totalAssistantCost),t[139]=_.totalAssistantCost,t[140]=J):J=t[140];let Se;t[141]!==de||t[142]!==J?(Se={label:de,value:J},t[141]=de,t[142]=J,t[143]=Se):Se=t[143];let Ve;t[144]!==V||t[145]!==De||t[146]!==lt||t[147]!==Se?(Ve=[V,De,lt,Se],t[144]=V,t[145]=De,t[146]=lt,t[147]=Se,t[148]=Ve):Ve=t[148];const He=Ve;let it;t[149]!==He?(it=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:He.map(Yy)}),t[149]=He,t[150]=it):it=t[150];let Ue;t[151]!==e?(Ue=e("contextSidebar.section.lastAssistantMessage"),t[151]=e,t[152]=Ue):Ue=t[152];let st;t[153]!==Ue?(st=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:Ue}),t[153]=Ue,t[154]=st):st=t[154];let ee;t[155]!==e||t[156]!==_.cacheHitRate.hasInput||t[157]!==_.cacheHitRate.percent||t[158]!==_.tokenBreakdown.cacheRead||t[159]!==_.tokenBreakdown.cacheWrite||t[160]!==_.tokenBreakdown.input||t[161]!==_.tokenBreakdown.output||t[162]!==_.tokenBreakdown.reasoning?(ee=s.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:_.tokenBreakdown.input,format:"count"},{label:e("contextSidebar.tokens.output"),value:_.tokenBreakdown.output,format:"count"},{label:e("contextSidebar.tokens.reasoning"),value:_.tokenBreakdown.reasoning,format:"count"},{label:e("contextSidebar.tokens.cacheRead"),value:_.tokenBreakdown.cacheRead,format:"count"},{label:e("contextSidebar.tokens.cacheWrite"),value:_.tokenBreakdown.cacheWrite,format:"count"},{label:e("contextSidebar.tokens.cacheHit"),value:_.cacheHitRate.hasInput?_.cacheHitRate.percent:null,format:"percent"}].map(Xy)}),t[155]=e,t[156]=_.cacheHitRate.hasInput,t[157]=_.cacheHitRate.percent,t[158]=_.tokenBreakdown.cacheRead,t[159]=_.tokenBreakdown.cacheWrite,t[160]=_.tokenBreakdown.input,t[161]=_.tokenBreakdown.output,t[162]=_.tokenBreakdown.reasoning,t[163]=ee):ee=t[163];let ze;t[164]!==st||t[165]!==ee?(ze=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[st,ee]}),t[164]=st,t[165]=ee,t[166]=ze):ze=t[166];let _e;t[167]!==je||t[168]!==_.breakdownTotal?(_e=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:je.map(vt=>vt.value<=0||_.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${vt.value/_.breakdownTotal*100}%`,backgroundColor:vt.color}},vt.key))}),t[167]=je,t[168]=_.breakdownTotal,t[169]=_e):_e=t[169];let pe;t[170]!==je||t[171]!==_.breakdownTotal?(pe=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:je.map(vt=>{const rt=_.breakdownTotal>0?vt.value/_.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:vt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[vt.label," ",s.jsxs("span",{className:"tabular-nums",children:[rt.toFixed(0),"%"]})]})]},vt.key)})}),t[170]=je,t[171]=_.breakdownTotal,t[172]=pe):pe=t[172];let qe;t[173]!==_e||t[174]!==pe?(qe=s.jsxs("div",{className:"mb-6",children:[_e,pe]}),t[173]=_e,t[174]=pe,t[175]=qe):qe=t[175];let tt;t[176]!==e?(tt=e("contextSidebar.section.rawMessages"),t[176]=e,t[177]=tt):tt=t[177];let pt;t[178]!==tt?(pt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:tt}),t[178]=tt,t[179]=pt):pt=t[179];let gt;if(t[180]!==l||t[181]!==i||t[182]!==p||t[183]!==e||t[184]!==n){let vt;t[186]!==l||t[187]!==i||t[188]!==e||t[189]!==n?(vt=rt=>{const ct=Zr(rt.info).role,dt=ct==="assistant",At=ct==="user",We=i[rt.info.id]===!0,Xe=l===rt.info.id,Tt=rt.info.time?.created??null,ut=Dy(rt.parts),kt=dt?wi({info:rt.info,parts:rt.parts}):null,Rt=At?Iy(rt.parts):"",ss=Ry(Tt,n),Ut=ut||"—",Wt=kt?Ty(kt.input,kt.output,Un):"",Qt=ct||"unknown",Kt=ut?`${Qt}: ${ut}`:Qt,Ft=We?JSON.stringify({info:rt.info,parts:rt.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":We,onClick:()=>{o($t=>({...$t,[rt.info.id]:$t[rt.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:dt?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[At?s.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",Rt]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:dt?Ut:Kt}),dt&&s.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:Wt})]}),s.jsx("span",{className:"text-right text-muted-foreground",children:ss})]})}),We&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:$t=>{$t.stopPropagation(),y(rt.info.id,Ft)},"aria-label":e(Xe?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Xe?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Xe?s.jsx(R,{name:"check",className:"size-3.5"}):s.jsx(R,{name:"file-copy",className:"size-3.5"})})}),s.jsx(sh,{language:"json",code:Ft,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},rt.info.id)},t[186]=l,t[187]=i,t[188]=e,t[189]=n,t[190]=vt):vt=t[190],gt=[...p].reverse().map(vt),t[180]=l,t[181]=i,t[182]=p,t[183]=e,t[184]=n,t[185]=gt}else gt=t[185];let Je;t[191]!==gt?(Je=s.jsx("div",{className:"mt-2.5 space-y-1",children:gt}),t[191]=gt,t[192]=Je):Je=t[192];let St;t[193]!==pt||t[194]!==Je?(St=s.jsxs("div",{children:[pt,Je]}),t[193]=pt,t[194]=Je,t[195]=St):St=t[195];let Ze;return t[196]!==ve||t[197]!==Fe||t[198]!==it||t[199]!==ze||t[200]!==qe||t[201]!==St?(Ze=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[ve,Fe,it,ze,qe,St]})}),t[196]=ve,t[197]=Fe,t[198]=it,t[199]=ze,t[200]=qe,t[201]=St,t[202]=Ze):Ze=t[202],Ze};function Wy(t){return t.timeFormatPreference}function zy(t){return t.currentSessionId}function Vy(t){return t.currentSessionDirectory}function Uy(t){return t.providers}function Ky(t){return Object.keys(t).length>0?{}:t}function Hy(t){return Zr(t.info).role==="assistant"}function Gy(t){return Zr(t.info).isUser}function qy(t,e){const n=Rn(e.info.cost);return t+n}function Qy(t){return Zr(t.info).isUser&&typeof t.info.system=="string"}function Yy(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function Xy(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value!==null&&t.value!==void 0?t.format==="percent"?`${t.value.toFixed(1)}%`:Un(t.value):"—"})]},t.label)}const Qu=new Set(["localhost","127.0.0.1","0.0.0.0","::1","[::1]"]),Jy=t=>{const e=t.split("/")[0]?.split("?")[0]??"",n=e.startsWith("[")?e.slice(0,e.indexOf("]")+1):e.split(":")[0]??"";return Qu.has(n.toLowerCase())},an="about:blank",hr=t=>{const e=t.trim();if(!e)return an;const n=e.includes("://")?e:`${Jy(e)?"http":"https"}://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?an:r.toString()}catch{return an}},vr=t=>{try{return Qu.has(new URL(t).hostname.toLowerCase())}catch{return!1}},Ha=t=>{if(!t||t===an)return"";try{return new URL(t).host||t}catch{return t}},Zy=new Set([-2,-7,-101,-102,-104,-109,-118,-324]),e1=(t,e)=>Zy.has(t)&&vr(e),t1=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.port=="number"&&Number.isFinite(e.port)&&typeof e.url=="string"&&e.url.length>0&&typeof e.command=="string"},s1=async t=>{try{const e=await ds("/api/dev-servers",{signal:t});if(!e.ok)return{kind:"unavailable"};const n=await e.json();if(!n||typeof n!="object")return{kind:"unavailable"};const r=n.servers;return Array.isArray(r)?{kind:"ready",servers:r.filter(t1)}:{kind:"unavailable"}}catch{return{kind:"unavailable"}}},n1=async t=>{try{const e=await ds("/api/system/probe-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:t})});if(!e.ok)return null;const n=await e.json();if(!n||typeof n!="object")return null;const r=n.status;return typeof r=="number"&&Number.isFinite(r)?r:null}catch{return null}},r1=t=>{try{const e=new URL(t),n=Number.parseInt(e.port||(e.protocol==="https:"?"443":"80"),10);return Number.isInteger(n)&&n>0?n:null}catch{return null}},o1=({announced:t,discovered:e})=>{const n=new Map;for(const r of t){const i=r1(r);i!==null&&!n.has(i)&&n.set(i,r)}return e?e.map(r=>{const i=n.get(r.port);return{url:i??r.url,port:r.port,announced:i!==void 0}}).sort((r,i)=>r.announced!==i.announced?r.announced?-1:1:r.port-i.port):[...n.entries()].map(([r,i])=>({url:i,port:r,announced:!0})).sort((r,i)=>r.port-i.port)},na="__openchamberBrowserAnnotationActive",i1=`(() => {
|
|
46
|
+
try {
|
|
47
|
+
var host = document.querySelector('[data-openchamber-annotation]');
|
|
48
|
+
if (host && host.parentNode) host.parentNode.removeChild(host);
|
|
49
|
+
} catch (error) { /* page navigated away */ }
|
|
50
|
+
try {
|
|
51
|
+
var cursor = document.getElementById('openchamber-annotation-cursor');
|
|
52
|
+
if (cursor && cursor.parentNode) cursor.parentNode.removeChild(cursor);
|
|
53
|
+
} catch (error) { /* page navigated away */ }
|
|
54
|
+
try { delete window['${na}']; } catch (error) { /* non-configurable */ }
|
|
55
|
+
})();`,a1=(t,e)=>{const n=JSON.stringify({theme:t,labels:e});return String.raw`new Promise((resolve) => {
|
|
56
|
+
var CONFIG = ${n};
|
|
57
|
+
var THEME = CONFIG.theme;
|
|
58
|
+
var LABELS = CONFIG.labels;
|
|
59
|
+
var OVERLAY_ATTR = 'data-openchamber-annotation';
|
|
60
|
+
var Z_OVERLAY = 2147483646;
|
|
61
|
+
var MAX_TEXT = 400;
|
|
62
|
+
var MIN_RECT = 3;
|
|
63
|
+
var EDITOR_GAP = 10;
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
var stale = document.querySelector('[' + OVERLAY_ATTR + ']');
|
|
67
|
+
if (stale && stale.parentNode) stale.parentNode.removeChild(stale);
|
|
68
|
+
} catch (error) { /* nothing to clean */ }
|
|
69
|
+
|
|
70
|
+
window['${na}'] = true;
|
|
71
|
+
|
|
72
|
+
var counter = 0;
|
|
73
|
+
var nextId = function (prefix) { counter += 1; return prefix + '-' + counter; };
|
|
74
|
+
|
|
75
|
+
var selected = null;
|
|
76
|
+
var regions = [];
|
|
77
|
+
var strokes = [];
|
|
78
|
+
var tool = 'select';
|
|
79
|
+
var settled = false;
|
|
80
|
+
|
|
81
|
+
// ---------------------------------------------------------------- geometry
|
|
82
|
+
|
|
83
|
+
var rectFrom = function (domRect) {
|
|
84
|
+
return { x: domRect.left, y: domRect.top, width: domRect.width, height: domRect.height };
|
|
85
|
+
};
|
|
86
|
+
var normalizeRect = function (ax, ay, bx, by) {
|
|
87
|
+
return { x: Math.min(ax, bx), y: Math.min(ay, by), width: Math.abs(bx - ax), height: Math.abs(by - ay) };
|
|
88
|
+
};
|
|
89
|
+
var usableRect = function (rect) { return rect.width >= MIN_RECT && rect.height >= MIN_RECT; };
|
|
90
|
+
|
|
91
|
+
// ------------------------------------------------------------- description
|
|
92
|
+
|
|
93
|
+
var isOverlayNode = function (element) {
|
|
94
|
+
var node = element;
|
|
95
|
+
while (node) {
|
|
96
|
+
if (node.nodeType === 1 && node.hasAttribute && node.hasAttribute(OVERLAY_ATTR)) return true;
|
|
97
|
+
node = node.parentNode || (node.host || null);
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
var elementFromPoint = function (x, y) {
|
|
103
|
+
var found = document.elementFromPoint(x, y);
|
|
104
|
+
if (!found || isOverlayNode(found)) return null;
|
|
105
|
+
return found;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
var selectorPart = function (element) {
|
|
109
|
+
var part = element.tagName.toLowerCase();
|
|
110
|
+
if (element.id) return part + '#' + element.id;
|
|
111
|
+
var className = typeof element.className === 'string' ? element.className.trim() : '';
|
|
112
|
+
if (className) {
|
|
113
|
+
var first = className.split(/\s+/).filter(Boolean).slice(0, 2).join('.');
|
|
114
|
+
if (first) part += '.' + first;
|
|
115
|
+
}
|
|
116
|
+
return part;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
var buildSelector = function (element) {
|
|
120
|
+
if (element.id) return '#' + element.id;
|
|
121
|
+
var parts = [];
|
|
122
|
+
var node = element;
|
|
123
|
+
var depth = 0;
|
|
124
|
+
while (node && node.nodeType === 1 && depth < 5) {
|
|
125
|
+
var part = selectorPart(node);
|
|
126
|
+
var parent = node.parentElement;
|
|
127
|
+
if (parent) {
|
|
128
|
+
var siblings = Array.prototype.filter.call(parent.children, function (child) {
|
|
129
|
+
return child.tagName === node.tagName;
|
|
130
|
+
});
|
|
131
|
+
if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
|
|
132
|
+
}
|
|
133
|
+
parts.unshift(part);
|
|
134
|
+
if (node.id) break;
|
|
135
|
+
node = parent;
|
|
136
|
+
depth += 1;
|
|
137
|
+
}
|
|
138
|
+
return parts.join(' > ');
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
var INTERESTING_ATTRS = ['id', 'class', 'name', 'type', 'href', 'src', 'alt', 'title', 'role', 'placeholder', 'aria-label', 'data-testid'];
|
|
142
|
+
var STYLE_PROPS = [
|
|
143
|
+
'display', 'position', 'color', 'backgroundColor', 'fontSize', 'fontWeight', 'fontFamily',
|
|
144
|
+
'lineHeight', 'padding', 'margin', 'border', 'borderRadius', 'width', 'height', 'opacity',
|
|
145
|
+
'zIndex', 'flexDirection', 'justifyContent', 'alignItems', 'gap', 'textAlign'
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
var describe = function (element) {
|
|
149
|
+
var computed = window.getComputedStyle(element);
|
|
150
|
+
var attributes = {};
|
|
151
|
+
for (var i = 0; i < INTERESTING_ATTRS.length; i += 1) {
|
|
152
|
+
var name = INTERESTING_ATTRS[i];
|
|
153
|
+
var value = element.getAttribute(name);
|
|
154
|
+
if (value) attributes[name] = String(value).slice(0, 200);
|
|
155
|
+
}
|
|
156
|
+
var computedStyle = {};
|
|
157
|
+
for (var j = 0; j < STYLE_PROPS.length; j += 1) {
|
|
158
|
+
var prop = STYLE_PROPS[j];
|
|
159
|
+
computedStyle[prop] = String(computed[prop] == null ? '' : computed[prop]);
|
|
160
|
+
}
|
|
161
|
+
var ancestry = [];
|
|
162
|
+
var node = element.parentElement;
|
|
163
|
+
var depth = 0;
|
|
164
|
+
while (node && node.nodeType === 1 && depth < 4) {
|
|
165
|
+
var entry = { tag: node.tagName.toLowerCase(), selectorPart: selectorPart(node) };
|
|
166
|
+
if (node.id) entry.id = node.id;
|
|
167
|
+
var cls = typeof node.className === 'string' ? node.className.trim() : '';
|
|
168
|
+
if (cls) entry.className = cls.slice(0, 200);
|
|
169
|
+
ancestry.unshift(entry);
|
|
170
|
+
node = node.parentElement;
|
|
171
|
+
depth += 1;
|
|
172
|
+
}
|
|
173
|
+
var box = element.getBoundingClientRect();
|
|
174
|
+
var text = (element.textContent == null ? '' : String(element.textContent)).replace(/\s+/g, ' ').trim();
|
|
175
|
+
return {
|
|
176
|
+
tag: element.tagName.toLowerCase(),
|
|
177
|
+
text: text.slice(0, MAX_TEXT),
|
|
178
|
+
selector: buildSelector(element),
|
|
179
|
+
path: ancestry.map(function (e) { return e.selectorPart; }).concat([selectorPart(element)]).join(' > '),
|
|
180
|
+
bounds: rectFrom(box),
|
|
181
|
+
center: { x: box.left + box.width / 2, y: box.top + box.height / 2 },
|
|
182
|
+
attributes: attributes,
|
|
183
|
+
computedStyle: computedStyle,
|
|
184
|
+
ancestry: ancestry
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// ------------------------------------------------------------------ chrome
|
|
189
|
+
|
|
190
|
+
var host = document.createElement('div');
|
|
191
|
+
host.setAttribute(OVERLAY_ATTR, '');
|
|
192
|
+
host.style.cssText = 'position:fixed;inset:0;z-index:' + Z_OVERLAY + ';pointer-events:none';
|
|
193
|
+
var shadow = host.attachShadow({ mode: 'closed' });
|
|
194
|
+
|
|
195
|
+
var style = document.createElement('style');
|
|
196
|
+
style.textContent = [
|
|
197
|
+
':host{all:initial}',
|
|
198
|
+
'*{box-sizing:border-box;font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif}',
|
|
199
|
+
'.layer{position:fixed;inset:0;pointer-events:none}',
|
|
200
|
+
'.box{position:fixed;left:0;top:0;display:none;pointer-events:none;border:1.5px solid ' + THEME.primary + ';background:' + THEME.primarySoft + ';border-radius:2px}',
|
|
201
|
+
'.label{position:fixed;left:0;top:0;display:none;pointer-events:none;padding:1px 6px;border-radius:4px;background:' + THEME.primary + ';color:' + THEME.primaryContrast + ';font-size:11px;line-height:17px;white-space:nowrap;font-weight:600}',
|
|
202
|
+
'.tools{position:fixed;top:14px;left:50%;transform:translateX(-50%);display:flex;gap:2px;padding:4px;border-radius:999px;border:1px solid ' + THEME.border + ';background:' + THEME.glassSurface + ';-webkit-backdrop-filter:' + THEME.glassFilter + ';backdrop-filter:' + THEME.glassFilter + ';box-shadow:0 6px 20px rgba(0,0,0,.24);pointer-events:auto}',
|
|
203
|
+
'.tools button{appearance:none;border:none;background:transparent;color:' + THEME.mutedText + ';border-radius:999px;padding:5px 14px;font-size:12px;line-height:18px;font-weight:500;cursor:pointer;white-space:nowrap}',
|
|
204
|
+
'.tools button:hover{background:' + THEME.primaryFaint + '}',
|
|
205
|
+
'.tools button[aria-pressed="true"]{background:' + THEME.primarySoft + ';color:' + THEME.primary + ';font-weight:600}',
|
|
206
|
+
'.editor{position:fixed;left:0;top:0;display:none;align-items:center;gap:8px;width:min(420px,calc(100vw - 24px));padding:6px;padding-left:16px;border-radius:22px;border:1px solid ' + THEME.border + ';background:' + THEME.glassSurface + ';-webkit-backdrop-filter:' + THEME.glassFilter + ';backdrop-filter:' + THEME.glassFilter + ';box-shadow:0 8px 28px rgba(0,0,0,.3);pointer-events:auto}',
|
|
207
|
+
'.editor textarea{flex:1;min-width:0;resize:none;border:none;background:transparent;color:' + THEME.text + ';font-size:13px;line-height:20px;outline:none;padding:6px 0;min-height:32px;max-height:104px;display:block}',
|
|
208
|
+
'.editor textarea::placeholder{color:' + THEME.mutedText + '}',
|
|
209
|
+
'.editor button{appearance:none;border:none;background:' + THEME.primary + ';color:' + THEME.primaryContrast + ';border-radius:999px;width:32px;height:32px;padding:0;display:flex;align-items:center;justify-content:center;flex-shrink:0;cursor:pointer}',
|
|
210
|
+
'.editor button svg{width:16px;height:16px;display:block}',
|
|
211
|
+
'.editor button[disabled]{opacity:.5;cursor:default}'
|
|
212
|
+
].join('');
|
|
213
|
+
shadow.appendChild(style);
|
|
214
|
+
|
|
215
|
+
var cursorStyle = document.createElement('style');
|
|
216
|
+
cursorStyle.id = 'openchamber-annotation-cursor';
|
|
217
|
+
document.head.appendChild(cursorStyle);
|
|
218
|
+
var setCursor = function (value) {
|
|
219
|
+
cursorStyle.textContent = value ? '*{cursor:' + value + ' !important}' : '';
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
var svgNS = 'http://www.w3.org/2000/svg';
|
|
223
|
+
var svg = document.createElementNS(svgNS, 'svg');
|
|
224
|
+
svg.setAttribute('class', 'layer');
|
|
225
|
+
svg.style.overflow = 'visible';
|
|
226
|
+
shadow.appendChild(svg);
|
|
227
|
+
|
|
228
|
+
var hoverBox = document.createElement('div');
|
|
229
|
+
hoverBox.className = 'box';
|
|
230
|
+
var hoverLabel = document.createElement('div');
|
|
231
|
+
hoverLabel.className = 'label';
|
|
232
|
+
var marqueeBox = document.createElement('div');
|
|
233
|
+
marqueeBox.className = 'box';
|
|
234
|
+
shadow.append(hoverBox, hoverLabel, marqueeBox);
|
|
235
|
+
|
|
236
|
+
var positionBox = function (node, rect) {
|
|
237
|
+
node.style.display = 'block';
|
|
238
|
+
node.style.transform = 'translate(' + rect.x + 'px,' + rect.y + 'px)';
|
|
239
|
+
node.style.width = rect.width + 'px';
|
|
240
|
+
node.style.height = rect.height + 'px';
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
var tools = document.createElement('div');
|
|
244
|
+
tools.className = 'tools';
|
|
245
|
+
shadow.appendChild(tools);
|
|
246
|
+
|
|
247
|
+
var toolButtons = {};
|
|
248
|
+
[['select', LABELS.select], ['marquee', LABELS.marquee], ['draw', LABELS.draw]].forEach(function (entry) {
|
|
249
|
+
var button = document.createElement('button');
|
|
250
|
+
button.type = 'button';
|
|
251
|
+
button.textContent = entry[1];
|
|
252
|
+
button.addEventListener('click', function () { setTool(entry[0]); });
|
|
253
|
+
toolButtons[entry[0]] = button;
|
|
254
|
+
tools.appendChild(button);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
var editor = document.createElement('div');
|
|
258
|
+
editor.className = 'editor';
|
|
259
|
+
shadow.appendChild(editor);
|
|
260
|
+
|
|
261
|
+
var comment = document.createElement('textarea');
|
|
262
|
+
comment.rows = 1;
|
|
263
|
+
comment.placeholder = LABELS.commentPlaceholder;
|
|
264
|
+
var submit = document.createElement('button');
|
|
265
|
+
submit.type = 'button';
|
|
266
|
+
// Icon-only attach button (Remix attachment-2), matching the chat comment
|
|
267
|
+
// input; the localized label stays available to assistive tech.
|
|
268
|
+
submit.setAttribute('aria-label', LABELS.submit);
|
|
269
|
+
submit.title = LABELS.submit;
|
|
270
|
+
submit.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M14.8287 7.75737L9.1718 13.4142C8.78127 13.8047 8.78127 14.4379 9.1718 14.8284C9.56232 15.219 10.1955 15.219 10.586 14.8284L16.2429 9.17158C17.4144 8.00001 17.4144 6.10052 16.2429 4.92894C15.0713 3.75737 13.1718 3.75737 12.0002 4.92894L6.34337 10.5858C4.39075 12.5384 4.39075 15.7042 6.34337 17.6569C8.29599 19.6095 11.4618 19.6095 13.4144 17.6569L19.0713 12L20.4855 13.4142L14.8287 19.0711C12.095 21.8047 7.66283 21.8047 4.92916 19.0711C2.19549 16.3374 2.19549 11.9053 4.92916 9.17158L10.586 3.51473C12.5386 1.56211 15.7045 1.56211 17.6571 3.51473C19.6097 5.46735 19.6097 8.63317 17.6571 10.5858L12.0002 16.2427C10.8287 17.4142 8.92916 17.4142 7.75759 16.2427C6.58601 15.0711 6.58601 13.1716 7.75759 12L13.4144 6.34316L14.8287 7.75737Z" fill="currentColor"/></svg>';
|
|
271
|
+
editor.append(comment, submit);
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Grows the box with its content.
|
|
275
|
+
*
|
|
276
|
+
* A hidden element reports scrollHeight 0, so measuring one collapses the
|
|
277
|
+
* field to nothing — which is what left a sliver of a click target and an
|
|
278
|
+
* invisible caret. Measuring only while visible, and never below the CSS
|
|
279
|
+
* min-height, keeps it usable.
|
|
280
|
+
*/
|
|
281
|
+
var resizeComment = function () {
|
|
282
|
+
if (editor.style.display === 'none') return;
|
|
283
|
+
comment.style.height = 'auto';
|
|
284
|
+
comment.style.height = Math.max(32, Math.min(comment.scrollHeight, 104)) + 'px';
|
|
285
|
+
};
|
|
286
|
+
comment.addEventListener('input', resizeComment);
|
|
287
|
+
|
|
288
|
+
// -------------------------------------------------------------- selection
|
|
289
|
+
|
|
290
|
+
var lastTargetRect = null;
|
|
291
|
+
|
|
292
|
+
/** Places the comment box under whatever was just marked, kept on screen. */
|
|
293
|
+
var positionEditor = function () {
|
|
294
|
+
if (!lastTargetRect) {
|
|
295
|
+
editor.style.display = 'none';
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
var wasHidden = editor.style.display === 'none';
|
|
299
|
+
editor.style.display = 'flex';
|
|
300
|
+
// Measured now that it is laid out, not while it was still hidden.
|
|
301
|
+
if (wasHidden) resizeComment();
|
|
302
|
+
var box = editor.getBoundingClientRect();
|
|
303
|
+
var left = lastTargetRect.x + lastTargetRect.width / 2 - box.width / 2;
|
|
304
|
+
var top = lastTargetRect.y + lastTargetRect.height + EDITOR_GAP;
|
|
305
|
+
// Above the target when there is no room below, so the box is never left
|
|
306
|
+
// half off the bottom of the page.
|
|
307
|
+
if (top + box.height > window.innerHeight - 8) {
|
|
308
|
+
top = Math.max(8, lastTargetRect.y - box.height - EDITOR_GAP);
|
|
309
|
+
}
|
|
310
|
+
left = Math.max(8, Math.min(left, window.innerWidth - box.width - 8));
|
|
311
|
+
editor.style.transform = 'translate(' + Math.round(left) + 'px,' + Math.round(top) + 'px)';
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
/** Focus after layout: focusing a zero-height field puts the caret nowhere. */
|
|
315
|
+
var focusComment = function () {
|
|
316
|
+
requestAnimationFrame(function () {
|
|
317
|
+
try {
|
|
318
|
+
comment.focus({ preventScroll: true });
|
|
319
|
+
comment.setSelectionRange(comment.value.length, comment.value.length);
|
|
320
|
+
} catch (error) { /* field went away */ }
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
var hasTargets = function () {
|
|
325
|
+
return Boolean(selected) || regions.length > 0 || strokes.length > 0;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
var syncChrome = function () {
|
|
329
|
+
submit.disabled = !hasTargets();
|
|
330
|
+
if (!hasTargets()) {
|
|
331
|
+
lastTargetRect = null;
|
|
332
|
+
editor.style.display = 'none';
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
positionEditor();
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
var syncSelectionVisuals = function () {
|
|
339
|
+
if (!selected) return;
|
|
340
|
+
var rect = rectFrom(selected.element.getBoundingClientRect());
|
|
341
|
+
if (!usableRect(rect)) {
|
|
342
|
+
selected.outline.style.display = 'none';
|
|
343
|
+
selected.badge.style.display = 'none';
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
positionBox(selected.outline, rect);
|
|
347
|
+
selected.badge.style.display = 'block';
|
|
348
|
+
selected.badge.style.transform = 'translate(' + Math.max(2, rect.x) + 'px,' + Math.max(2, rect.y - 19) + 'px)';
|
|
349
|
+
lastTargetRect = rect;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
var dropSelection = function () {
|
|
353
|
+
if (!selected) return;
|
|
354
|
+
selected.outline.remove();
|
|
355
|
+
selected.badge.remove();
|
|
356
|
+
selected = null;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
var selectElement = function (element) {
|
|
360
|
+
var wasSelected = selected && selected.element === element;
|
|
361
|
+
dropSelection();
|
|
362
|
+
if (wasSelected) {
|
|
363
|
+
// Clicking the chosen element again clears it, so a misclick costs one
|
|
364
|
+
// click rather than starting over.
|
|
365
|
+
lastTargetRect = null;
|
|
366
|
+
syncChrome();
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
var outline = document.createElement('div');
|
|
370
|
+
outline.className = 'box';
|
|
371
|
+
var badge = document.createElement('div');
|
|
372
|
+
badge.className = 'label';
|
|
373
|
+
badge.textContent = selectorPart(element);
|
|
374
|
+
shadow.append(outline, badge);
|
|
375
|
+
selected = { id: nextId('element'), element: element, outline: outline, badge: badge };
|
|
376
|
+
syncSelectionVisuals();
|
|
377
|
+
syncChrome();
|
|
378
|
+
focusComment();
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
var setTool = function (next) {
|
|
382
|
+
tool = next;
|
|
383
|
+
hoverBox.style.display = 'none';
|
|
384
|
+
hoverLabel.style.display = 'none';
|
|
385
|
+
marqueeBox.style.display = 'none';
|
|
386
|
+
setCursor(next === 'select' ? '' : 'crosshair');
|
|
387
|
+
for (var key in toolButtons) {
|
|
388
|
+
if (Object.prototype.hasOwnProperty.call(toolButtons, key)) {
|
|
389
|
+
toolButtons[key].setAttribute('aria-pressed', key === next ? 'true' : 'false');
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// ------------------------------------------------------------- interaction
|
|
395
|
+
|
|
396
|
+
var drag = null;
|
|
397
|
+
|
|
398
|
+
var onPointerMove = function (event) {
|
|
399
|
+
if (drag) {
|
|
400
|
+
if (drag.kind === 'marquee') {
|
|
401
|
+
drag.rect = normalizeRect(drag.startX, drag.startY, event.clientX, event.clientY);
|
|
402
|
+
positionBox(marqueeBox, drag.rect);
|
|
403
|
+
} else if (drag.kind === 'draw') {
|
|
404
|
+
drag.points.push({ x: event.clientX, y: event.clientY });
|
|
405
|
+
drag.path.setAttribute('d', drag.points.map(function (point, index) {
|
|
406
|
+
return (index === 0 ? 'M' : 'L') + point.x + ' ' + point.y;
|
|
407
|
+
}).join(' '));
|
|
408
|
+
}
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (tool !== 'select') return;
|
|
413
|
+
var element = elementFromPoint(event.clientX, event.clientY);
|
|
414
|
+
if (!element) {
|
|
415
|
+
hoverBox.style.display = 'none';
|
|
416
|
+
hoverLabel.style.display = 'none';
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
var rect = rectFrom(element.getBoundingClientRect());
|
|
420
|
+
positionBox(hoverBox, rect);
|
|
421
|
+
hoverLabel.textContent = selectorPart(element);
|
|
422
|
+
hoverLabel.style.display = 'block';
|
|
423
|
+
hoverLabel.style.transform = 'translate(' + Math.max(2, rect.x) + 'px,' + Math.max(2, rect.y - 19) + 'px)';
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
var onPointerDown = function (event) {
|
|
427
|
+
if (event.button !== 0) return;
|
|
428
|
+
if (isOverlayNode(event.target)) return;
|
|
429
|
+
event.preventDefault();
|
|
430
|
+
event.stopPropagation();
|
|
431
|
+
|
|
432
|
+
if (tool === 'select') {
|
|
433
|
+
var element = elementFromPoint(event.clientX, event.clientY);
|
|
434
|
+
if (element) selectElement(element);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (tool === 'marquee') {
|
|
439
|
+
drag = { kind: 'marquee', startX: event.clientX, startY: event.clientY, rect: null };
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
var path = document.createElementNS(svgNS, 'path');
|
|
444
|
+
path.setAttribute('fill', 'none');
|
|
445
|
+
path.setAttribute('stroke', THEME.primary);
|
|
446
|
+
path.setAttribute('stroke-width', '2.5');
|
|
447
|
+
path.setAttribute('stroke-linecap', 'round');
|
|
448
|
+
path.setAttribute('stroke-linejoin', 'round');
|
|
449
|
+
svg.appendChild(path);
|
|
450
|
+
drag = { kind: 'draw', path: path, points: [{ x: event.clientX, y: event.clientY }] };
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
var onPointerUp = function () {
|
|
454
|
+
if (!drag) return;
|
|
455
|
+
var finished = drag;
|
|
456
|
+
drag = null;
|
|
457
|
+
|
|
458
|
+
if (finished.kind === 'marquee') {
|
|
459
|
+
marqueeBox.style.display = 'none';
|
|
460
|
+
var rect = finished.rect;
|
|
461
|
+
if (!rect || !usableRect(rect)) return;
|
|
462
|
+
// A region marks an area, not the elements inside it: expanding it into a
|
|
463
|
+
// selection made the result depend on the page's markup rather than on
|
|
464
|
+
// what was drawn.
|
|
465
|
+
regions.push({ id: nextId('region'), rect: rect });
|
|
466
|
+
var outline = document.createElementNS(svgNS, 'rect');
|
|
467
|
+
outline.setAttribute('x', String(rect.x));
|
|
468
|
+
outline.setAttribute('y', String(rect.y));
|
|
469
|
+
outline.setAttribute('width', String(rect.width));
|
|
470
|
+
outline.setAttribute('height', String(rect.height));
|
|
471
|
+
outline.style.fill = THEME.primarySoft;
|
|
472
|
+
outline.setAttribute('stroke', THEME.primary);
|
|
473
|
+
outline.setAttribute('stroke-width', '1.5');
|
|
474
|
+
outline.setAttribute('rx', '2');
|
|
475
|
+
svg.appendChild(outline);
|
|
476
|
+
lastTargetRect = rect;
|
|
477
|
+
syncChrome();
|
|
478
|
+
focusComment();
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
var points = finished.points;
|
|
483
|
+
if (points.length < 2) {
|
|
484
|
+
if (finished.path.parentNode) finished.path.parentNode.removeChild(finished.path);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
var minX = points[0].x, minY = points[0].y, maxX = points[0].x, maxY = points[0].y;
|
|
488
|
+
for (var p = 1; p < points.length; p += 1) {
|
|
489
|
+
minX = Math.min(minX, points[p].x);
|
|
490
|
+
minY = Math.min(minY, points[p].y);
|
|
491
|
+
maxX = Math.max(maxX, points[p].x);
|
|
492
|
+
maxY = Math.max(maxY, points[p].y);
|
|
493
|
+
}
|
|
494
|
+
var bounds = { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
495
|
+
strokes.push({ id: nextId('stroke'), points: points, bounds: bounds });
|
|
496
|
+
lastTargetRect = bounds;
|
|
497
|
+
syncChrome();
|
|
498
|
+
focusComment();
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Swallows the page's own mouse handling while annotating.
|
|
503
|
+
*
|
|
504
|
+
* Blocking pointerdown is not enough: a click still follows it, so marking a
|
|
505
|
+
* button pressed that button and marking a link navigated away from the page
|
|
506
|
+
* being annotated. These are the events that reach page code, so these are
|
|
507
|
+
* the ones that have to stop.
|
|
508
|
+
*/
|
|
509
|
+
var blockPageInteraction = function (event) {
|
|
510
|
+
if (isOverlayNode(event.target)) return;
|
|
511
|
+
event.preventDefault();
|
|
512
|
+
event.stopPropagation();
|
|
513
|
+
};
|
|
514
|
+
var BLOCKED_EVENTS = ['click', 'auxclick', 'dblclick', 'mousedown', 'mouseup', 'contextmenu'];
|
|
515
|
+
|
|
516
|
+
var onScrollOrResize = function () {
|
|
517
|
+
syncSelectionVisuals();
|
|
518
|
+
positionEditor();
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
var onKeyDown = function (event) {
|
|
522
|
+
if (event.isComposing || event.keyCode === 229) return;
|
|
523
|
+
if (event.key === 'Escape') {
|
|
524
|
+
event.preventDefault();
|
|
525
|
+
event.stopImmediatePropagation();
|
|
526
|
+
finish(null);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
var onCommentKeyDown = function (event) {
|
|
531
|
+
// Do not let the annotated page treat typed letters as its own shortcuts.
|
|
532
|
+
event.stopPropagation();
|
|
533
|
+
// WebKit can report the composition-confirming Enter as keyCode 229.
|
|
534
|
+
if (event.isComposing || event.keyCode === 229) return;
|
|
535
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
536
|
+
event.preventDefault();
|
|
537
|
+
attach();
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
document.addEventListener('pointermove', onPointerMove, true);
|
|
542
|
+
document.addEventListener('pointerdown', onPointerDown, true);
|
|
543
|
+
document.addEventListener('pointerup', onPointerUp, true);
|
|
544
|
+
BLOCKED_EVENTS.forEach(function (name) {
|
|
545
|
+
window.addEventListener(name, blockPageInteraction, { capture: true, passive: false });
|
|
546
|
+
});
|
|
547
|
+
window.addEventListener('scroll', onScrollOrResize, true);
|
|
548
|
+
window.addEventListener('resize', onScrollOrResize, true);
|
|
549
|
+
window.addEventListener('keydown', onKeyDown, true);
|
|
550
|
+
comment.addEventListener('keydown', onCommentKeyDown);
|
|
551
|
+
|
|
552
|
+
// ------------------------------------------------------------------ finish
|
|
553
|
+
|
|
554
|
+
var teardown = function () {
|
|
555
|
+
document.removeEventListener('pointermove', onPointerMove, true);
|
|
556
|
+
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
557
|
+
document.removeEventListener('pointerup', onPointerUp, true);
|
|
558
|
+
BLOCKED_EVENTS.forEach(function (name) {
|
|
559
|
+
window.removeEventListener(name, blockPageInteraction, true);
|
|
560
|
+
});
|
|
561
|
+
window.removeEventListener('scroll', onScrollOrResize, true);
|
|
562
|
+
window.removeEventListener('resize', onScrollOrResize, true);
|
|
563
|
+
window.removeEventListener('keydown', onKeyDown, true);
|
|
564
|
+
comment.removeEventListener('keydown', onCommentKeyDown);
|
|
565
|
+
setCursor('');
|
|
566
|
+
if (cursorStyle.parentNode) cursorStyle.parentNode.removeChild(cursorStyle);
|
|
567
|
+
if (host.parentNode) host.parentNode.removeChild(host);
|
|
568
|
+
try { delete window['${na}']; } catch (error) { /* non-configurable */ }
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
var finish = function (payload) {
|
|
572
|
+
if (settled) return;
|
|
573
|
+
settled = true;
|
|
574
|
+
teardown();
|
|
575
|
+
// Removing the chrome is not enough: the host screenshots this page right
|
|
576
|
+
// after we resolve, and the compositor can still hold a frame containing
|
|
577
|
+
// our outlines. Yield two frames so the page has actually repainted.
|
|
578
|
+
requestAnimationFrame(function () {
|
|
579
|
+
requestAnimationFrame(function () { resolve(payload); });
|
|
580
|
+
});
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
var attach = function () {
|
|
584
|
+
if (!hasTargets()) return;
|
|
585
|
+
finish({
|
|
586
|
+
id: 'annotation-' + Date.now(),
|
|
587
|
+
pageUrl: String(location.href),
|
|
588
|
+
pageTitle: String(document.title || ''),
|
|
589
|
+
viewport: { width: window.innerWidth, height: window.innerHeight },
|
|
590
|
+
devicePixelRatio: window.devicePixelRatio || 1,
|
|
591
|
+
comment: comment.value,
|
|
592
|
+
// Zero or one element, never more. Kept as a list so elements, regions
|
|
593
|
+
// and strokes stay one uniform shape for everything downstream.
|
|
594
|
+
elements: selected ? [{ id: selected.id, element: describe(selected.element) }] : [],
|
|
595
|
+
regions: regions.map(function (entry) { return { id: entry.id, rect: entry.rect }; }),
|
|
596
|
+
strokes: strokes.map(function (entry) {
|
|
597
|
+
return { id: entry.id, points: entry.points, bounds: entry.bounds };
|
|
598
|
+
})
|
|
599
|
+
});
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
submit.addEventListener('click', attach);
|
|
603
|
+
|
|
604
|
+
(document.body || document.documentElement).appendChild(host);
|
|
605
|
+
setTool('select');
|
|
606
|
+
syncChrome();
|
|
607
|
+
});`},l1={kind:"idle"},yn=t=>typeof t=="object"&&t!==null,kn=t=>typeof t=="number"&&Number.isFinite(t),tc=t=>yn(t)&&Object.values(t).every(e=>typeof e=="string"),Ga=t=>yn(t)&&kn(t.x)&&kn(t.y)&&kn(t.width)&&kn(t.height),Yu=t=>yn(t)&&kn(t.x)&&kn(t.y),c1=t=>yn(t)&&typeof t.tag=="string"&&typeof t.selectorPart=="string"&&(t.id===void 0||typeof t.id=="string")&&(t.className===void 0||typeof t.className=="string"),d1=t=>yn(t)&&typeof t.tag=="string"&&typeof t.text=="string"&&typeof t.selector=="string"&&typeof t.path=="string"&&Ga(t.bounds)&&Yu(t.center)&&tc(t.attributes)&&tc(t.computedStyle)&&Array.isArray(t.ancestry)&&t.ancestry.every(c1),u1=t=>yn(t)&&typeof t.id=="string"&&d1(t.element),m1=t=>yn(t)&&typeof t.id=="string"&&Ga(t.rect),f1=t=>yn(t)&&typeof t.id=="string"&&Ga(t.bounds)&&Array.isArray(t.points)&&t.points.every(Yu),h1=t=>yn(t)&&typeof t.id=="string"&&typeof t.pageUrl=="string"&&typeof t.pageTitle=="string"&&typeof t.comment=="string"&&yn(t.viewport)&&kn(t.viewport.width)&&kn(t.viewport.height)&&kn(t.devicePixelRatio)&&Array.isArray(t.elements)&&t.elements.every(u1)&&Array.isArray(t.regions)&&t.regions.every(m1)&&Array.isArray(t.strokes)&&t.strokes.every(f1),p1=1600,g1=t=>new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=()=>n(new Error("Failed to decode browser page capture")),r.src=t}),x1=async({base64:t,mime:e,captureWidth:n,captureHeight:r,cssWidth:i,cssHeight:o,payload:l,accentColor:a,accentFill:u})=>{if(!t)return null;try{const d=await g1(`data:${e};base64,${t}`),h=Math.max(1,d.naturalWidth||n),f=Math.max(1,d.naturalHeight||r),p=h/Math.max(1,i||h),g=f/Math.max(1,o||f),w=Math.min(1,p1/h),v=document.createElement("canvas");v.width=Math.max(1,Math.floor(h*w)),v.height=Math.max(1,Math.floor(f*w));const x=v.getContext("2d");if(!x)return null;x.scale(w,w),x.drawImage(d,0,0,h,f);const m=N=>({x:N.x*p,y:N.y*g,width:N.width*p,height:N.height*g}),b=Math.max(2,2.5*p/Math.max(w,.2));x.strokeStyle=a,x.fillStyle=u;const y=N=>{const C=m(N);x.lineWidth=b,x.fillRect(C.x,C.y,C.width,C.height),x.strokeRect(C.x,C.y,C.width,C.height)};for(const N of l.elements)y(N.element.bounds);for(const N of l.regions)y(N.rect);for(const N of l.strokes)N.points.length<2||(x.beginPath(),N.points.forEach((C,j)=>{const A=C.x*p,D=C.y*g;j===0?x.moveTo(A,D):x.lineTo(A,D)}),x.lineCap="round",x.lineJoin="round",x.lineWidth=b*1.4,x.stroke());const S=await new Promise(N=>v.toBlob(N,"image/jpeg",.85));return S?new File([S],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},b1="({ width: window.innerWidth, height: window.innerHeight })",y1=async t=>{try{const e=await t.executeJavaScript(b1,!0);if(!e||typeof e!="object")return null;const n=e;return typeof n.width!="number"||typeof n.height!="number"||!Number.isFinite(n.width)||!Number.isFinite(n.height)?null:{width:n.width,height:n.height}}catch{return null}},jo=async t=>{try{await t.executeJavaScript(i1,!1)}catch{}},w1=async({host:t,theme:e,labels:n})=>{const r=a1(e,n),i=await t.executeJavaScript(r,!0);if(i==null)return null;if(!h1(i))return await jo(t),null;const o=i;try{const l=await y1(t)??o.viewport,a=await t.capturePage();if(!a||!a.base64)return{payload:o,screenshot:null};const u=await x1({base64:a.base64,mime:a.mime||"image/jpeg",captureWidth:a.width,captureHeight:a.height,cssWidth:l.width,cssHeight:l.height,payload:o,accentColor:e.primary,accentFill:e.primarySoft});return{payload:o,screenshot:u}}catch{return{payload:o,screenshot:null}}},rn={colorScheme:"dark",primary:"rgb(59, 130, 246)",primarySoft:"rgba(59, 130, 246, 0.16)",primaryFaint:"rgba(59, 130, 246, 0.10)",primaryContrast:"rgb(255, 255, 255)",surface:"rgb(24, 24, 27)",surfaceElevated:"rgb(32, 32, 36)",glassSurface:"rgba(32, 32, 36, 0.64)",glassFilter:"blur(26px) saturate(1.16)",border:"rgba(255, 255, 255, 0.14)",text:"rgb(244, 244, 245)",mutedText:"rgba(244, 244, 245, 0.62)"},S1=()=>{if(typeof document>"u"||!document.body)return null;const t=document.createElement("div");return t.setAttribute("aria-hidden","true"),t.style.cssText="position:fixed;left:-9999px;top:-9999px;width:1px;height:1px;pointer-events:none",document.body.appendChild(t),{read:e=>{t.style.backgroundColor="",t.style.backgroundColor=e;const n=window.getComputedStyle(t).backgroundColor;return n&&n!=="rgba(0, 0, 0, 0)"?n:""},readVariable:e=>window.getComputedStyle(document.documentElement).getPropertyValue(e).trim(),dispose:()=>t.remove()}},v1=t=>{const e=S1();if(!e)return{...rn,colorScheme:t};try{const n=(a,u)=>e.read(`var(${a})`)||u,r=(a,u,d)=>e.read(`color-mix(in srgb, var(${a}) ${u}%, transparent)`)||d,i=e.readVariable("--oc-glass-tooltip-opacity")||"62%",o=e.readVariable("--oc-glass-blur")||"26px",l=e.readVariable("--oc-glass-saturation")||"1.16";return{colorScheme:t,glassSurface:e.read(`color-mix(in srgb, var(--surface-elevated) ${i}, transparent)`)||rn.glassSurface,glassFilter:`blur(${o}) saturate(${l})`,primary:n("--primary",rn.primary),primarySoft:r("--primary",16,rn.primarySoft),primaryFaint:r("--primary",10,rn.primaryFaint),primaryContrast:n("--primary-foreground",rn.primaryContrast),surface:n("--surface-background",rn.surface),surfaceElevated:n("--surface-elevated",rn.surfaceElevated),border:n("--border",rn.border),text:n("--foreground",rn.text),mutedText:n("--muted-foreground",rn.mutedText)}}catch{return{...rn,colorScheme:t}}finally{e.dispose()}};let pr=null,gr=null,ko=null,Gr=0,$o=null;const hn=new Set,j1=3e4,k1=45e3,Xu=()=>{ko&&(clearTimeout(ko),ko=null)},Ju=()=>{if(gr||hn.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(Gr,5)),j1);gr=setTimeout(()=>{gr=null,Gr+=1,qa()},t)},qr=()=>{Xu(),pr&&pr.close(),pr=null},sc=()=>{Xu(),hn.size!==0&&(ko=setTimeout(()=>{qr(),Ju()},k1))},C1=t=>{if(!t||t.trim().length===0)return null;try{const e=JSON.parse(t),n=typeof e?.type=="string"?e.type:"",r=e?.properties;return n?{type:n,properties:r}:null}catch{return null}},lo=t=>!t||typeof t!="object"?null:t,N1=t=>{if(t.type==="openchamber:event-stream-ready"){Gr=0;return}if(t.type==="openchamber:heartbeat")return;if(t.type==="openchamber:agent-memory-changed"){const u=lo(t.properties),h={type:"agent-memory-changed",scope:u?.scope==="project"?"project":"global",...typeof u?.projectId=="string"&&u.projectId.length>0?{projectId:u.projectId}:{}};for(const f of hn)f(h);return}if(t.type==="openchamber:session-created"){const u=lo(t.properties),d=typeof u?.sessionId=="string"?u.sessionId:"",h=typeof u?.directory=="string"?u.directory:"";if(!d||!h)return;const f={type:"session-created",sessionId:d,directory:h,createdAt:typeof u?.createdAt=="number"?u.createdAt:Date.now(),promptDispatched:u?.promptDispatched===!0,dispatchedAsCommand:u?.dispatchedAsCommand===!0,...typeof u?.projectId=="string"&&u.projectId.length>0?{projectId:u.projectId}:{}};for(const p of hn)p(f);return}if(t.type==="openchamber:browser-control-request"){const u=lo(t.properties),d=typeof u?.requestId=="string"?u.requestId:"",h=typeof u?.action=="string"?u.action:"";if(!d||!h)return;const f=u?.parameters,p={type:"browser-control-request",requestId:d,action:h,parameters:f&&typeof f=="object"&&!Array.isArray(f)?f:{}};for(const g of hn)g(p);return}if(t.type!=="openchamber:scheduled-task-ran")return;const e=lo(t.properties),n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",i=typeof e?.ranAt=="number"?e.ranAt:Date.now(),o=e?.status,l=o==="running"||o==="error"?o:"success";if(!n||!r)return;const a={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:i,status:l,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const u of hn)u(a)},qa=()=>{if(typeof window>"u"||hn.size===0||typeof EventSource!="function"||pr&&pr.readyState!==EventSource.CLOSED)return;qr();const t=typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,e=new EventSource(wa().sse("/api/openchamber/events",t?{browser:"1"}:void 0));e.onopen=()=>{sc()},e.onmessage=n=>{sc();const r=C1(n.data);r&&N1(r)},e.onerror=()=>{qr(),Ju()},pr=e},A1=()=>{$o||typeof window>"u"||($o=Yo(()=>{qr(),Gr=0,qa()}))},D1=()=>{$o?.(),$o=null},eo=t=>(hn.add(t),A1(),qa(),()=>{hn.delete(t),hn.size===0&&(gr&&(clearTimeout(gr),gr=null),Gr=0,qr(),D1())}),P1=2e3,I1=50;let Yn=null,xr=null,_r=null;const T1=async t=>{try{const e=await ds("/api/browser-control/claim",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:t})});return e.ok?(await e.json())?.granted===!0:!1}catch{return!1}},rr=async(t,e)=>{try{const n=await ds("/api/browser-control/result",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:t,...e})});n.ok||console.warn(`[browser-control] the server rejected the result for ${t} (HTTP ${n.status}); the agent will see this action time out`)}catch(n){console.warn(`[browser-control] could not deliver the result for ${t}:`,n)}},E1=async(t=P1)=>{const e=Date.now()+t;for(;!Yn&&Date.now()<e;)await new Promise(n=>setTimeout(n,I1));return Yn},R1=async t=>{const e=t.action==="browser.open",n=Yn;if(!(!n&&!(e&&xr))&&await T1(t.requestId))try{if(e&&!n){const i=typeof t.parameters.url=="string"?t.parameters.url:"";if(!i){await rr(t.requestId,{ok:!1,error:"url is required"});return}xr?.(i);const o=typeof t.parameters.viewport=="string"?t.parameters.viewport:"";if(!o||o==="fill"){await rr(t.requestId,{ok:!0,data:{url:i,opened:!0}});return}const l=await E1();if(!l){await rr(t.requestId,{ok:!0,data:{url:i,opened:!0,viewportApplied:!1,note:"The panel had no browser view yet, so the viewport was not applied. Call browser.resize now that one exists."}});return}const a=await l.run("browser.resize",{viewport:o}),u=a&&typeof a=="object"?a.viewport??null:null;await rr(t.requestId,{ok:!0,data:{url:i,opened:!0,viewportApplied:!0,viewport:u}});return}const r=await n.run(t.action,t.parameters);await rr(t.requestId,{ok:!0,data:r})}catch(r){await rr(t.requestId,{ok:!1,error:r instanceof Error?r.message:String(r)})}},Zu=()=>{_r||(_r=eo(t=>{t.type==="browser-control-request"&&R1({requestId:t.requestId,action:t.action,parameters:t.parameters})}))},em=()=>{Yn||xr||!_r||(_r(),_r=null)},M1=t=>(Yn=t,Zu(),()=>{Yn===t&&(Yn=null),em()}),O1=t=>(xr=t,Zu(),()=>{xr===t&&(xr=null),em()}),B1=50,F1=6,_1=2048,L1=200,tm=t=>{const e=hr(String(t??"").trim());if(!e||e.length>_1)return"";try{const n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?"":n.toString()}catch{return""}},$1=(t,e)=>{const n=tm(e.url);if(!n)return t;const r=t.find(l=>l.url===n),i=String(e.title??"").trim().slice(0,L1)||r?.title||"";return[{url:n,title:i,lastVisitedAt:e.at},...t.filter(l=>l.url!==n)].slice(0,B1)},W1=(t,e)=>{const n=tm(e);return t.filter(r=>r.url!==n)},z1=t=>`${t.url.replace(/^https?:\/\//,"")} ${t.title}`.toLowerCase(),sm=(t,e,n=F1)=>{const r=String(e??"").trim().toLowerCase(),i=[...t].sort((l,a)=>a.lastVisitedAt-l.lastVisitedAt);if(!r)return i.slice(0,n);const o=r.replace(/^https?:\/\//,"");return i.filter(l=>{const a=z1(l);return l.url===r||a===o?!1:a.includes(o)}).slice(0,n)},nc=20,Co=t=>{const e=wt((t||"").trim());return e?JSON.stringify([ps(),e]):""},V1=t=>{const e=Object.keys(t);if(e.length<=nc)return t;const n=e.map(r=>[r,t[r]?.[0]?.lastVisitedAt??0]).sort((r,i)=>i[1]-r[1]).slice(0,nc);return Object.fromEntries(n.map(([r])=>[r,t[r]??[]]))},br=tr()(Kg(t=>({byProject:{},recordVisit:(e,n)=>{const r=Co(e);r&&t(i=>{const o=i.byProject[r]??[],l=$1(o,{...n,at:Date.now()});return l===o?i:{byProject:V1({...i.byProject,[r]:l})}})},forget:(e,n)=>{const r=Co(e);r&&t(i=>{const o=i.byProject[r];return o?{byProject:{...i.byProject,[r]:W1(o,n)}}:i})},clear:e=>{const n=Co(e);n&&t(r=>{if(!(n in r.byProject))return r;const i={...r.byProject};return delete i[n],{byProject:i}})}}),{name:"openchamber-browser-history",version:1,storage:cf(),partialize:t=>({byProject:t.byProject})})),U1=[],nm=t=>e=>{const n=Co(t);return(n?e.byProject[n]:void 0)??U1},ra=new Map,ii=new Map,Xn=new Map,Jn=new Set,K1=async(t,e)=>{if(!el()){Jn.delete(t),ir(t,{type:"close"});return}if(await df(An()),!Jn.has(t)||!el())return;const n=wa().websocket(`/api/dev-tunnel?port=${e}`),r=uf(n);Xn.set(t,r),r.binaryType="arraybuffer",r.onopen=()=>ir(t,{type:"ready"}),r.onmessage=i=>ir(t,{type:"data",data:i.data instanceof ArrayBuffer?i.data:new TextEncoder().encode(i.data)}),r.onerror=()=>ir(t,{type:"close"}),r.onclose=()=>{Jn.delete(t),Xn.delete(t),ir(t,{type:"close"})}};nh(({connectionId:t,remotePort:e,message:n})=>{switch(n.type){case"data":{const r=Xn.get(t);r&&n.data&&r.send(n.data);return}case"close":Jn.delete(t),Xn.get(t)?.close(),Xn.delete(t);return;case"connect":Jn.add(t),K1(t,e).catch(()=>{Jn.delete(t),ir(t,{type:"close"})})}});const rm=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,om=t=>{if(!t)return!1;try{const e=new URL(t,typeof window<"u"?window.location.href:void 0),n=typeof window<"u"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"";return n&&e.origin===n?!1:!vr(e.toString())}catch{return!1}},im=t=>{try{const e=new URL(t),n=Number.parseInt(e.port||(e.protocol==="https:"?"443":"80"),10);return Number.isInteger(n)&&n>0?n:0}catch{return 0}},rc=(t,e)=>{try{const n=new URL(t);return n.protocol="http:",n.hostname="127.0.0.1",n.port=String(e),n.toString()}catch{return t}},oc=(t,e)=>{try{ii.set(e,new URL(t).origin)}catch{}};class Lr extends Error{constructor(e){super(e),this.name="DevTunnelUnavailableError"}}const ic=async t=>{if(!t||!rm()||!vr(t))return t;const e=An();if(!om(e))return t;const n=im(t);if(!n)return t;const r=`${e}|${n}`,i=ra.get(r);if(i)return oc(t,i),rc(t,i);try{const o=await mr("desktop_dev_tunnel_open",{baseUrl:e,port:n,relay:mf(),targetKey:ps(),clientToken:Wr(),requestHeaders:xd()});if(!o||!Number.isInteger(o.localPort)||o.localPort<=0)throw new Lr(t);return ra.set(r,o.localPort),oc(t,o.localPort),rc(t,o.localPort)}catch(o){throw o instanceof Lr?o:new Lr(t)}},ac=t=>{if(!t||!rm()||!vr(t)||!om(An()))return!1;const e=im(t);return e>0&&!ii.has(e)},Pr=t=>{if(!t)return t;try{const e=new URL(t);if(e.hostname!=="127.0.0.1")return t;const n=ii.get(Number.parseInt(e.port||"0",10));return n?`${n}${e.pathname}${e.search}${e.hash}`:t}catch{return t}},H1=()=>{ra.clear(),ii.clear(),Jn.clear();for(const t of Xn.values())t.close();Xn.clear(),mr("desktop_relay_dev_tunnel_close_all").catch(()=>{})};typeof window<"u"&&Yo(H1);const lc=6e3,G1=120,q1=80,Q1=`
|
|
608
|
+
var MAX_ELEMENTS = ${G1};
|
|
609
|
+
var MAX_LABEL_CHARS = ${q1};
|
|
610
|
+
var visible = function (element) {
|
|
611
|
+
var rect = element.getBoundingClientRect();
|
|
612
|
+
if (rect.width < 1 || rect.height < 1) return false;
|
|
613
|
+
var style = window.getComputedStyle(element);
|
|
614
|
+
return style.visibility !== 'hidden' && style.display !== 'none' && Number(style.opacity) !== 0;
|
|
615
|
+
};
|
|
616
|
+
var label = function (element) {
|
|
617
|
+
var aria = element.getAttribute('aria-label');
|
|
618
|
+
if (aria) return aria.trim();
|
|
619
|
+
var value = element.getAttribute('value');
|
|
620
|
+
var text = (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim();
|
|
621
|
+
if (text) return text.slice(0, MAX_LABEL_CHARS);
|
|
622
|
+
if (value) return String(value).slice(0, MAX_LABEL_CHARS);
|
|
623
|
+
var placeholder = element.getAttribute('placeholder');
|
|
624
|
+
return placeholder ? placeholder.trim().slice(0, MAX_LABEL_CHARS) : '';
|
|
625
|
+
};
|
|
626
|
+
var isUnique = function (selector) {
|
|
627
|
+
try {
|
|
628
|
+
return document.querySelectorAll(selector).length === 1;
|
|
629
|
+
} catch (error) {
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Names an element by what it is, falling back to where it sits.
|
|
636
|
+
*
|
|
637
|
+
* A positional chain like 'main > section:nth-of-type(3) > div > a' survives
|
|
638
|
+
* only until the markup shifts, and says nothing about what it points at.
|
|
639
|
+
* Anything the page states about identity — an id, a test id, an accessible
|
|
640
|
+
* name — outlives edits and reads as the thing it selects. The chain remains
|
|
641
|
+
* as the last resort, because something always has to work.
|
|
642
|
+
*/
|
|
643
|
+
var cssPath = function (element) {
|
|
644
|
+
var tag = element.tagName.toLowerCase();
|
|
645
|
+
|
|
646
|
+
if (element.id) {
|
|
647
|
+
var byId = '#' + CSS.escape(element.id);
|
|
648
|
+
if (isUnique(byId)) return byId;
|
|
649
|
+
}
|
|
650
|
+
var stableAttrs = ['data-testid', 'data-test-id', 'data-test', 'name', 'aria-label'];
|
|
651
|
+
for (var a = 0; a < stableAttrs.length; a += 1) {
|
|
652
|
+
var value = element.getAttribute(stableAttrs[a]);
|
|
653
|
+
if (!value) continue;
|
|
654
|
+
var raw = String(value);
|
|
655
|
+
// A value containing a quote would need escaping for no real gain: such
|
|
656
|
+
// attributes are rare, and the positional chain still covers them.
|
|
657
|
+
if (raw.indexOf('"') !== -1) continue;
|
|
658
|
+
var byAttr = tag + '[' + stableAttrs[a] + '="' + raw + '"]';
|
|
659
|
+
if (isUnique(byAttr)) return byAttr;
|
|
660
|
+
}
|
|
661
|
+
var className = typeof element.className === 'string' ? element.className.trim() : '';
|
|
662
|
+
if (className) {
|
|
663
|
+
var classes = className.split(/\\s+/).filter(Boolean);
|
|
664
|
+
for (var c = 0; c < classes.length; c += 1) {
|
|
665
|
+
var byClass = tag + '.' + CSS.escape(classes[c]);
|
|
666
|
+
if (isUnique(byClass)) return byClass;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
var parts = [];
|
|
671
|
+
var node = element;
|
|
672
|
+
var depth = 0;
|
|
673
|
+
while (node && node.nodeType === 1 && depth < 6) {
|
|
674
|
+
var part = node.tagName.toLowerCase();
|
|
675
|
+
var parent = node.parentElement;
|
|
676
|
+
if (!parent) { parts.unshift(part); break; }
|
|
677
|
+
var siblings = Array.prototype.filter.call(parent.children, function (child) {
|
|
678
|
+
return child.tagName === node.tagName;
|
|
679
|
+
});
|
|
680
|
+
if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
|
|
681
|
+
parts.unshift(part);
|
|
682
|
+
if (node.id) { parts[0] = '#' + CSS.escape(node.id); break; }
|
|
683
|
+
node = parent;
|
|
684
|
+
depth += 1;
|
|
685
|
+
}
|
|
686
|
+
return parts.join(' > ');
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
/** What a screen reader would announce, or '' when there is nothing to say. */
|
|
690
|
+
var accessibleName = function (element) {
|
|
691
|
+
var aria = element.getAttribute('aria-label');
|
|
692
|
+
if (aria && aria.trim()) return aria.trim();
|
|
693
|
+
var labelled = element.getAttribute('aria-labelledby');
|
|
694
|
+
if (labelled) {
|
|
695
|
+
var source = document.getElementById(labelled.split(/\\s+/)[0]);
|
|
696
|
+
if (source && (source.innerText || '').trim()) return source.innerText.trim();
|
|
697
|
+
}
|
|
698
|
+
var title = element.getAttribute('title');
|
|
699
|
+
if (title && title.trim()) return title.trim();
|
|
700
|
+
var alt = element.getAttribute('alt');
|
|
701
|
+
if (alt && alt.trim()) return alt.trim();
|
|
702
|
+
var text = (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim();
|
|
703
|
+
if (text) return text;
|
|
704
|
+
var value = element.getAttribute('value');
|
|
705
|
+
return value && String(value).trim() ? String(value).trim() : '';
|
|
706
|
+
};
|
|
707
|
+
var findByText = function (needle) {
|
|
708
|
+
var wanted = String(needle).replace(/\\s+/g, ' ').trim().toLowerCase();
|
|
709
|
+
var candidates = document.querySelectorAll('a, button, [role="button"], [role="link"], input[type="submit"], input[type="button"], summary, label');
|
|
710
|
+
var exact = null;
|
|
711
|
+
var partial = null;
|
|
712
|
+
for (var i = 0; i < candidates.length; i += 1) {
|
|
713
|
+
var element = candidates[i];
|
|
714
|
+
if (!visible(element)) continue;
|
|
715
|
+
var text = label(element).toLowerCase();
|
|
716
|
+
if (!text) continue;
|
|
717
|
+
if (text === wanted) { exact = element; break; }
|
|
718
|
+
if (!partial && text.indexOf(wanted) !== -1) partial = element;
|
|
719
|
+
}
|
|
720
|
+
return exact || partial;
|
|
721
|
+
};
|
|
722
|
+
`,to=t=>`(() => {
|
|
723
|
+
${Q1}
|
|
724
|
+
${t}
|
|
725
|
+
})()`,Y1=({selector:t}={})=>to(`
|
|
726
|
+
var scopeSelector = ${JSON.stringify(t??"")};
|
|
727
|
+
var root = document;
|
|
728
|
+
if (scopeSelector) {
|
|
729
|
+
try { root = document.querySelector(scopeSelector); }
|
|
730
|
+
catch (error) { return { ok: false, error: 'Invalid selector: ' + scopeSelector }; }
|
|
731
|
+
if (!root) return { ok: false, error: 'No element matches ' + scopeSelector };
|
|
732
|
+
}
|
|
733
|
+
var interactive = root.querySelectorAll('a[href], button, input, select, textarea, [role="button"], [role="link"], [role="tab"], [contenteditable="true"]');
|
|
734
|
+
var elements = [];
|
|
735
|
+
var visibleTotal = 0;
|
|
736
|
+
for (var i = 0; i < interactive.length; i += 1) {
|
|
737
|
+
var element = interactive[i];
|
|
738
|
+
if (!visible(element)) continue;
|
|
739
|
+
visibleTotal += 1;
|
|
740
|
+
if (elements.length >= MAX_ELEMENTS) continue;
|
|
741
|
+
|
|
742
|
+
var rect = element.getBoundingClientRect();
|
|
743
|
+
// Empty and default-valued fields are left out rather than serialized as
|
|
744
|
+
// "" and false. Repeated across a hundred entries that overhead dwarfed
|
|
745
|
+
// the information it carried.
|
|
746
|
+
var entry = {
|
|
747
|
+
selector: cssPath(element),
|
|
748
|
+
tag: element.tagName.toLowerCase(),
|
|
749
|
+
bounds: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) }
|
|
750
|
+
};
|
|
751
|
+
// The list covers the whole document so anything can be clicked without
|
|
752
|
+
// scrolling to it first, which means bounds alone do not say what is on
|
|
753
|
+
// screen — a negative y reads as a bug otherwise.
|
|
754
|
+
if (rect.bottom > 0 && rect.top < window.innerHeight) entry.inViewport = true;
|
|
755
|
+
var type = element.getAttribute('type');
|
|
756
|
+
if (type) entry.type = type;
|
|
757
|
+
var role = element.getAttribute('role');
|
|
758
|
+
if (role) entry.role = role;
|
|
759
|
+
var labelText = label(element);
|
|
760
|
+
if (labelText) entry.label = labelText;
|
|
761
|
+
if (element.disabled === true) entry.disabled = true;
|
|
762
|
+
// Flagged rather than described: reporting the accessible name of every
|
|
763
|
+
// element would cost more than it tells, while its absence on something
|
|
764
|
+
// clickable is a defect worth naming.
|
|
765
|
+
if (!accessibleName(element)) entry.missingAccessibleName = true;
|
|
766
|
+
elements.push(entry);
|
|
767
|
+
}
|
|
768
|
+
var body = document.body ? (document.body.innerText || '') : '';
|
|
769
|
+
var text = body.replace(/\\n{3,}/g, '\\n\\n').trim();
|
|
770
|
+
var docEl = document.documentElement;
|
|
771
|
+
var result = {
|
|
772
|
+
ok: true,
|
|
773
|
+
url: String(location.href),
|
|
774
|
+
title: String(document.title || ''),
|
|
775
|
+
scope: scopeSelector || 'document',
|
|
776
|
+
scrollY: Math.round(window.scrollY),
|
|
777
|
+
maxScrollY: Math.max(0, Math.round(docEl.scrollHeight - window.innerHeight)),
|
|
778
|
+
text: text.slice(0, ${lc}),
|
|
779
|
+
elements: elements
|
|
780
|
+
};
|
|
781
|
+
// State what was dropped. A capped list that reports only its own length
|
|
782
|
+
// reads as the whole page, and the agent acts as if it had seen everything.
|
|
783
|
+
if (text.length > ${lc}) {
|
|
784
|
+
result.textTruncated = true;
|
|
785
|
+
result.textTotalChars = text.length;
|
|
786
|
+
}
|
|
787
|
+
if (visibleTotal > elements.length) {
|
|
788
|
+
result.elementsTruncated = true;
|
|
789
|
+
result.interactiveElementsOnPage = visibleTotal;
|
|
790
|
+
}
|
|
791
|
+
return result;
|
|
792
|
+
`),X1=({selector:t,text:e})=>to(`
|
|
793
|
+
var selector = ${JSON.stringify(t??"")};
|
|
794
|
+
var text = ${JSON.stringify(e??"")};
|
|
795
|
+
var target = null;
|
|
796
|
+
if (selector) {
|
|
797
|
+
try { target = document.querySelector(selector); }
|
|
798
|
+
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
799
|
+
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
800
|
+
} else {
|
|
801
|
+
target = findByText(text);
|
|
802
|
+
if (!target) return { ok: false, error: 'No clickable element has the label ' + text };
|
|
803
|
+
}
|
|
804
|
+
if (target.disabled === true) return { ok: false, error: 'Element is disabled' };
|
|
805
|
+
target.scrollIntoView({ block: 'center', inline: 'center' });
|
|
806
|
+
target.click();
|
|
807
|
+
return { ok: true, clicked: cssPath(target), label: label(target), url: String(location.href) };
|
|
808
|
+
`),J1=({selector:t,value:e,submit:n})=>to(`
|
|
809
|
+
var selector = ${JSON.stringify(t)};
|
|
810
|
+
var value = ${JSON.stringify(e)};
|
|
811
|
+
var target = null;
|
|
812
|
+
try { target = document.querySelector(selector); }
|
|
813
|
+
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
814
|
+
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
815
|
+
|
|
816
|
+
var editable = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;
|
|
817
|
+
if (!editable) return { ok: false, error: selector + ' is not a text field' };
|
|
818
|
+
if (target.disabled === true || target.readOnly === true) return { ok: false, error: 'Field is not editable' };
|
|
819
|
+
|
|
820
|
+
target.scrollIntoView({ block: 'center' });
|
|
821
|
+
target.focus();
|
|
822
|
+
if (target.isContentEditable) {
|
|
823
|
+
target.textContent = value;
|
|
824
|
+
} else {
|
|
825
|
+
// Frameworks track the value through the native setter; assigning the
|
|
826
|
+
// property directly leaves React and friends unaware of the change.
|
|
827
|
+
var prototype = target.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
828
|
+
var setter = Object.getOwnPropertyDescriptor(prototype, 'value');
|
|
829
|
+
if (setter && setter.set) setter.set.call(target, value);
|
|
830
|
+
else target.value = value;
|
|
831
|
+
}
|
|
832
|
+
target.dispatchEvent(new Event('input', { bubbles: true }));
|
|
833
|
+
target.dispatchEvent(new Event('change', { bubbles: true }));
|
|
834
|
+
|
|
835
|
+
if (${n?"true":"false"}) {
|
|
836
|
+
var enter = { key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true };
|
|
837
|
+
target.dispatchEvent(new KeyboardEvent('keydown', enter));
|
|
838
|
+
target.dispatchEvent(new KeyboardEvent('keyup', enter));
|
|
839
|
+
var form = target.form;
|
|
840
|
+
if (form && typeof form.requestSubmit === 'function') form.requestSubmit();
|
|
841
|
+
}
|
|
842
|
+
return { ok: true, selector: cssPath(target), url: String(location.href) };
|
|
843
|
+
`),Z1=({selector:t,direction:e})=>to(`
|
|
844
|
+
var selector = ${JSON.stringify(t??"")};
|
|
845
|
+
var direction = ${JSON.stringify(e??"")};
|
|
846
|
+
|
|
847
|
+
var settle = function (extra) {
|
|
848
|
+
return new Promise(function (resolve) {
|
|
849
|
+
requestAnimationFrame(function () {
|
|
850
|
+
requestAnimationFrame(function () {
|
|
851
|
+
var doc = document.documentElement;
|
|
852
|
+
var maxScrollY = Math.max(0, doc.scrollHeight - window.innerHeight);
|
|
853
|
+
var scrollY = Math.round(window.scrollY);
|
|
854
|
+
var result = { ok: true, scrollY: scrollY, maxScrollY: Math.round(maxScrollY) };
|
|
855
|
+
result.atTop = scrollY <= 1;
|
|
856
|
+
result.atBottom = scrollY >= maxScrollY - 1;
|
|
857
|
+
for (var key in extra) {
|
|
858
|
+
if (Object.prototype.hasOwnProperty.call(extra, key)) result[key] = extra[key];
|
|
859
|
+
}
|
|
860
|
+
resolve(result);
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
});
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
if (selector) {
|
|
867
|
+
var target = null;
|
|
868
|
+
try { target = document.querySelector(selector); }
|
|
869
|
+
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
870
|
+
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
871
|
+
// Instant on purpose: the page's own smooth scrolling would still be
|
|
872
|
+
// animating when the next action runs against it.
|
|
873
|
+
target.scrollIntoView({ block: 'center', behavior: 'instant' });
|
|
874
|
+
return settle({ scrolledTo: cssPath(target) });
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
var doc = document.documentElement;
|
|
878
|
+
var page = Math.round(window.innerHeight * 0.85);
|
|
879
|
+
var bottom = Math.max(0, doc.scrollHeight - window.innerHeight);
|
|
880
|
+
if (direction === 'down') window.scrollTo({ top: window.scrollY + page, behavior: 'instant' });
|
|
881
|
+
else if (direction === 'up') window.scrollTo({ top: window.scrollY - page, behavior: 'instant' });
|
|
882
|
+
else if (direction === 'top') window.scrollTo({ top: 0, behavior: 'instant' });
|
|
883
|
+
else if (direction === 'bottom') window.scrollTo({ top: bottom, behavior: 'instant' });
|
|
884
|
+
else return { ok: false, error: 'Unknown scroll direction: ' + direction };
|
|
885
|
+
return settle({ direction: direction });
|
|
886
|
+
`),ew=["color","background-color","background-image","opacity","font-family","font-size","font-weight","line-height","letter-spacing","text-align","border-radius","border-width","border-style","border-color","box-shadow","display","position","width","height","padding","margin","gap","flex-direction","justify-content","align-items","z-index","overflow","visibility"],tw=({selector:t})=>to(`
|
|
887
|
+
var selector = ${JSON.stringify(t)};
|
|
888
|
+
var target = null;
|
|
889
|
+
try { target = document.querySelector(selector); }
|
|
890
|
+
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
891
|
+
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
892
|
+
|
|
893
|
+
var computed = window.getComputedStyle(target);
|
|
894
|
+
var styles = {};
|
|
895
|
+
var props = ${JSON.stringify(ew)};
|
|
896
|
+
for (var i = 0; i < props.length; i += 1) {
|
|
897
|
+
var value = computed.getPropertyValue(props[i]);
|
|
898
|
+
if (value) styles[props[i]] = String(value).trim();
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
var rect = target.getBoundingClientRect();
|
|
902
|
+
return {
|
|
903
|
+
ok: true,
|
|
904
|
+
selector: cssPath(target),
|
|
905
|
+
tag: target.tagName.toLowerCase(),
|
|
906
|
+
label: label(target),
|
|
907
|
+
bounds: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) },
|
|
908
|
+
inViewport: rect.bottom > 0 && rect.top < window.innerHeight,
|
|
909
|
+
styles: styles
|
|
910
|
+
};
|
|
911
|
+
`),sw=t=>{const e=nt.c(18),{entries:n,activeIndex:r,onSelect:i,onForget:o,onHighlight:l}=t,{t:a}=Nt();if(n.length===0)return null;let u;e[0]!==a?(u=a("contextPanel.browser.history.label"),e[0]=a,e[1]=u):u=e[1];let d;if(e[2]!==r||e[3]!==n||e[4]!==o||e[5]!==l||e[6]!==i||e[7]!==a){let f;e[9]!==r||e[10]!==o||e[11]!==l||e[12]!==i||e[13]!==a?(f=(p,g)=>s.jsxs("div",{role:"option","aria-selected":g===r,className:Ie("group flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1",g===r?"bg-interactive-hover":"hover:bg-interactive-hover"),onPointerDown:w=>{w.preventDefault(),i(p.url)},onPointerEnter:()=>l(g),children:[s.jsx(R,{name:"global",className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate typography-micro text-foreground",children:p.title||Ha(p.url)}),s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:p.url})]}),s.jsx("button",{type:"button",className:Ie("shrink-0 rounded-md p-1 text-muted-foreground opacity-0 transition-opacity","hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100"),"aria-label":a("contextPanel.browser.history.forget"),title:a("contextPanel.browser.history.forget"),onPointerDown:w=>{w.preventDefault(),w.stopPropagation(),o(p.url)},children:s.jsx(R,{name:"close",className:"size-3","aria-hidden":"true"})})]},p.url),e[9]=r,e[10]=o,e[11]=l,e[12]=i,e[13]=a,e[14]=f):f=e[14],d=n.map(f),e[2]=r,e[3]=n,e[4]=o,e[5]=l,e[6]=i,e[7]=a,e[8]=d}else d=e[8];let h;return e[15]!==u||e[16]!==d?(h=s.jsx("div",{className:"oc-glass-popover oc-glass-floating absolute inset-x-0 top-full z-50 mt-1 overflow-hidden rounded-xl p-1",role:"listbox","aria-label":u,children:d}),e[15]=u,e[16]=d,e[17]=h):h=e[17],h},on=t=>{const e=nt.c(17),{icon:n,label:r,onClick:i,disabled:o,pressed:l}=t,a=l?"secondary":"ghost",u=l&&"text-foreground";let d;e[0]!==u?(d=Ie("w-6 shrink-0 rounded-full px-0 text-muted-foreground","hover:text-foreground",u),e[0]=u,e[1]=d):d=e[1];let h;e[2]!==n?(h=s.jsx(R,{name:n,className:"size-3.5","aria-hidden":"true"}),e[2]=n,e[3]=h):h=e[3];let f;e[4]!==o||e[5]!==r||e[6]!==i||e[7]!==l||e[8]!==a||e[9]!==d||e[10]!==h?(f=s.jsx(Pt,{asChild:!0,children:s.jsx(bt,{type:"button",variant:a,size:"xs",className:d,onClick:i,disabled:o,"aria-label":r,"aria-pressed":l,children:h})}),e[4]=o,e[5]=r,e[6]=i,e[7]=l,e[8]=a,e[9]=d,e[10]=h,e[11]=f):f=e[11];let p;e[12]!==r?(p=s.jsx(It,{sideOffset:6,children:r}),e[12]=r,e[13]=p):p=e[13];let g;return e[14]!==f||e[15]!==p?(g=s.jsxs(Dt,{children:[f,p]}),e[14]=f,e[15]=p,e[16]=g):g=e[16],g},am=t=>{const e=nt.c(104),{address:n,suggestions:r,onForgetSuggestion:i,onAddressChange:o,onSubmit:l,onBack:a,onForward:u,onReload:d,onOpenExternal:h,canGoBack:f,canGoForward:p,isLoading:g,onAnnotate:w,onOpenDevTools:v,isAnnotating:x,onHardReload:m,onZoomIn:b,onZoomOut:y,onZoomReset:S,zoomPercent:N,onClearCookies:C,onClearCache:j,onToggleDeviceBar:A,isDeviceBarOpen:D}=t;let I;e[0]!==r?(I=r===void 0?[]:r,e[0]=r,e[1]=I):I=e[1];const M=I,$=N===void 0?100:N,{t:E}=Nt(),[K,B]=c.useState(!1),[O,T]=c.useState(-1);let k;e[2]!==K||e[3]!==M?(k=K?M:[],e[2]=K,e[3]=M,e[4]=k):k=e[4];const P=k;let F;e[5]===Symbol.for("react.memo_cache_sentinel")?(F=()=>{T(-1)},e[5]=F):F=e[5];let q;e[6]!==n||e[7]!==K?(q=[n,K],e[6]=n,e[7]=K,e[8]=q):q=e[8],c.useEffect(F,q);let Q;e[9]!==l?(Q=Fe=>{B(!1),T(-1),l(Fe)},e[9]=l,e[10]=Q):Q=e[10];const Y=Q;let ce;e[11]!==O||e[12]!==Y||e[13]!==P?(ce=Fe=>{if(P.length!==0){if(Fe.key==="ArrowDown"||Fe.key==="ArrowUp"){Fe.preventDefault();const Ke=Fe.key==="ArrowDown"?1:-1,$e=P.length;T(V=>{const fe=V+Ke;return fe<-1?$e-1:fe>=$e?-1:fe});return}if(Fe.key==="Escape"&&O>=0){Fe.preventDefault(),T(-1);return}if(Fe.key==="Enter"&&O>=0){Fe.preventDefault();const Ke=P[O];Ke&&Y(Ke.url)}}},e[11]=O,e[12]=Y,e[13]=P,e[14]=ce):ce=e[14];const X=ce;let oe;e[15]!==E?(oe=E("contextPanel.browser.back"),e[15]=E,e[16]=oe):oe=e[16];const te=!f;let he;e[17]!==a||e[18]!==te||e[19]!==oe?(he=s.jsx(on,{icon:"arrow-left",label:oe,onClick:a,disabled:te}),e[17]=a,e[18]=te,e[19]=oe,e[20]=he):he=e[20];let _;e[21]!==E?(_=E("contextPanel.browser.forward"),e[21]=E,e[22]=_):_=e[22];const ie=!p;let ge;e[23]!==u||e[24]!==_||e[25]!==ie?(ge=s.jsx(on,{icon:"arrow-right",label:_,onClick:u,disabled:ie}),e[23]=u,e[24]=_,e[25]=ie,e[26]=ge):ge=e[26];let ae;e[27]!==g||e[28]!==E?(ae=E(g?"contextPanel.browser.stop":"contextPanel.browser.reload"),e[27]=g,e[28]=E,e[29]=ae):ae=e[29];let z;e[30]!==d||e[31]!==ae?(z=s.jsx(on,{icon:"refresh",label:ae,onClick:d}),e[30]=d,e[31]=ae,e[32]=z):z=e[32];let ne;e[33]!==m||e[34]!==E?(ne=m?s.jsx(on,{icon:"restart",label:E("contextPanel.browser.hardReload"),onClick:m}):null,e[33]=m,e[34]=E,e[35]=ne):ne=e[35];let ue;e[36]!==n||e[37]!==Y?(ue=Fe=>{Fe.preventDefault(),Y(n)},e[36]=n,e[37]=Y,e[38]=ue):ue=e[38];let me;e[39]!==o?(me=Fe=>o(Fe.target.value),e[39]=o,e[40]=me):me=e[40];let ke,Te;e[41]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>B(!0),Te=()=>B(!1),e[41]=ke,e[42]=Te):(ke=e[41],Te=e[42]);const je=P.length>0;let Ee;e[43]===Symbol.for("react.memo_cache_sentinel")?(Ee=Ie("h-6 w-full rounded-full border border-border/50 bg-[var(--surface-elevated)] px-3","typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[43]=Ee):Ee=e[43];let xe;e[44]!==E?(xe=E("contextPanel.browser.addressAria"),e[44]=E,e[45]=xe):xe=e[45];let H;e[46]!==n||e[47]!==X||e[48]!==me||e[49]!==je||e[50]!==xe?(H=s.jsx("input",{value:n,onChange:me,onFocus:ke,onBlur:Te,onKeyDown:X,spellCheck:!1,autoComplete:"off",role:"combobox","aria-expanded":je,"aria-controls":"openchamber-browser-address-suggestions",className:Ee,"aria-label":xe}),e[46]=n,e[47]=X,e[48]=me,e[49]=je,e[50]=xe,e[51]=H):H=e[51];let Ce;e[52]!==i?(Ce=Fe=>i?.(Fe),e[52]=i,e[53]=Ce):Ce=e[53];let ve;e[54]!==O||e[55]!==Y||e[56]!==Ce||e[57]!==P?(ve=s.jsx("div",{id:"openchamber-browser-address-suggestions",children:s.jsx(sw,{entries:P,activeIndex:O,onSelect:Y,onForget:Ce,onHighlight:T})}),e[54]=O,e[55]=Y,e[56]=Ce,e[57]=P,e[58]=ve):ve=e[58];let re;e[59]!==ue||e[60]!==H||e[61]!==ve?(re=s.jsxs("form",{className:"relative min-w-0 flex-1",onSubmit:ue,children:[H,ve]}),e[59]=ue,e[60]=H,e[61]=ve,e[62]=re):re=e[62];let le;e[63]!==b||e[64]!==y||e[65]!==S||e[66]!==E||e[67]!==$?(le=y&&b?s.jsxs("div",{className:"flex shrink-0 items-center",children:[s.jsx(on,{icon:"subtract",label:E("contextPanel.browser.zoomOut"),onClick:y}),$!==100&&S?s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs(bt,{type:"button",variant:"ghost",size:"xs",className:"shrink-0 rounded-full px-1.5 typography-micro tabular-nums text-muted-foreground",onClick:S,"aria-label":E("contextPanel.browser.zoomReset"),children:[$,"%"]})}),s.jsx(It,{sideOffset:6,children:E("contextPanel.browser.zoomReset")})]}):null,s.jsx(on,{icon:"add",label:E("contextPanel.browser.zoomIn"),onClick:b})]}):null,e[63]=b,e[64]=y,e[65]=S,e[66]=E,e[67]=$,e[68]=le):le=e[68];let se;e[69]!==C||e[70]!==E?(se=C?s.jsx(on,{icon:"delete-bin",label:E("contextPanel.browser.clearCookies"),onClick:C}):null,e[69]=C,e[70]=E,e[71]=se):se=e[71];let G;e[72]!==j||e[73]!==E?(G=j?s.jsx(on,{icon:"database-2",label:E("contextPanel.browser.clearCache"),onClick:j}):null,e[72]=j,e[73]=E,e[74]=G):G=e[74];let U;e[75]!==D||e[76]!==A||e[77]!==E?(U=A?s.jsx(on,{icon:"smartphone",label:E("contextPanel.browser.deviceToolbar"),onClick:A,pressed:D}):null,e[75]=D,e[76]=A,e[77]=E,e[78]=U):U=e[78];let be;e[79]!==x||e[80]!==w||e[81]!==E?(be=w?s.jsx(on,{icon:"markup",label:E("contextPanel.browser.annotate.toggle"),onClick:w,pressed:x}):null,e[79]=x,e[80]=w,e[81]=E,e[82]=be):be=e[82];let W;e[83]!==v||e[84]!==E?(W=v?s.jsx(on,{icon:"terminal-box",label:E("contextPanel.browser.devTools"),onClick:v}):null,e[83]=v,e[84]=E,e[85]=W):W=e[85];let Ne;e[86]!==E?(Ne=E("contextPanel.browser.openExternal"),e[86]=E,e[87]=Ne):Ne=e[87];let Oe;e[88]!==h||e[89]!==Ne?(Oe=s.jsx(on,{icon:"external-link",label:Ne,onClick:h}),e[88]=h,e[89]=Ne,e[90]=Oe):Oe=e[90];let ye;return e[91]!==he||e[92]!==ge||e[93]!==z||e[94]!==ne||e[95]!==re||e[96]!==le||e[97]!==se||e[98]!==G||e[99]!==U||e[100]!==be||e[101]!==W||e[102]!==Oe?(ye=s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[he,ge,z,ne,re,le,se,G,U,be,W,Oe]}),e[91]=he,e[92]=ge,e[93]=z,e[94]=ne,e[95]=re,e[96]=le,e[97]=se,e[98]=G,e[99]=U,e[100]=be,e[101]=W,e[102]=Oe,e[103]=ye):ye=e[103],ye},Wo={kind:"fill"},cc=240,nw=3840,lm=[{id:"iphone-se",label:"iPhone SE",width:375,height:667},{id:"iphone-14",label:"iPhone 14",width:390,height:844},{id:"iphone-14-pro-max",label:"iPhone 14 Pro Max",width:430,height:932},{id:"pixel-7",label:"Pixel 7",width:412,height:915},{id:"ipad-mini",label:"iPad mini",width:768,height:1024},{id:"ipad-pro",label:"iPad Pro",width:1024,height:1366},{id:"laptop",label:"Laptop",width:1280,height:800},{id:"desktop",label:"Desktop",width:1440,height:900}],dc=t=>Number.isFinite(t)?Math.round(Math.min(nw,Math.max(cc,t))):cc,zo=t=>t.kind==="fill"?null:{width:t.width,height:t.height},cm=t=>{const e=lm.find(n=>n.id===t);return e?{kind:"preset",id:e.id,width:e.width,height:e.height}:null},rw=t=>t.kind==="fill"?t:{kind:"custom",width:t.height,height:t.width},ow=(t,e)=>{const n=zo(t);if(!n)return null;const r=Math.max(1,e.width),i=Math.max(1,e.height),o=Math.min(1,r/n.width,i/n.height);return{width:n.width,height:n.height,scale:o}},iw=["mobile","tablet","desktop","fill"],aw={mobile:"iphone-14",tablet:"ipad-mini",desktop:"desktop"},uc=t=>typeof t=="string"&&iw.includes(t),oa=t=>t==="fill"?Wo:cm(aw[t])??Wo,co=t=>{const e=zo(t);if(!e)return{mode:"fill",width:null,height:null};for(const n of["mobile","tablet","desktop"]){const r=oa(n),i=zo(r);if(i&&i.width===e.width&&i.height===e.height)return{mode:n,width:e.width,height:e.height}}return{mode:"custom",width:e.width,height:e.height}},lw=t=>{const e=nt.c(70),{viewport:n,onViewportChange:r,colorScheme:i,onColorSchemeChange:o,scale:l}=t,{t:a}=Nt();let u;e[0]!==n?(u=zo(n),e[0]=n,e[1]=u):u=e[1];const d=u,h=n.kind==="preset"?n.id:"";let f;e[2]!==r||e[3]!==d?(f=(te,he)=>{const _=Number.parseInt(he,10);if(!Number.isFinite(_))return;const ie=d??{width:1280,height:800};r({kind:"custom",width:dc(te==="width"?_:ie.width),height:dc(te==="height"?_:ie.height)})},e[2]=r,e[3]=d,e[4]=f):f=e[4];const p=f;let g;e[5]===Symbol.for("react.memo_cache_sentinel")?(g=Ie("h-6 w-14 rounded-full border border-border/50 bg-[var(--surface-elevated)] px-2 text-center","typography-micro tabular-nums text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[5]=g):g=e[5];const w=g;let v;e[6]!==r?(v=te=>{const he=cm(te.target.value);r(he??Wo)},e[6]=r,e[7]=v):v=e[7];let x;e[8]!==a?(x=a("contextPanel.browser.device.preset"),e[8]=a,e[9]=x):x=e[9];let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=Ie("h-6 shrink-0 rounded-full border border-border/50 bg-[var(--surface-elevated)] px-2","typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[10]=m):m=e[10];let b;e[11]!==a?(b=a("contextPanel.browser.device.responsive"),e[11]=a,e[12]=b):b=e[12];let y;e[13]!==b?(y=s.jsx("option",{value:"",children:b}),e[13]=b,e[14]=y):y=e[14];let S;e[15]===Symbol.for("react.memo_cache_sentinel")?(S=lm.map(cw),e[15]=S):S=e[15];let N;e[16]!==h||e[17]!==v||e[18]!==x||e[19]!==y?(N=s.jsxs("select",{value:h,onChange:v,"aria-label":x,className:m,children:[y,S]}),e[16]=h,e[17]=v,e[18]=x,e[19]=y,e[20]=N):N=e[20];const C=d?String(d.width):"";let j;e[21]!==p?(j=te=>p("width",te.target.value),e[21]=p,e[22]=j):j=e[22];let A;e[23]!==a?(A=a("contextPanel.browser.device.width"),e[23]=a,e[24]=A):A=e[24];let D;e[25]!==C||e[26]!==j||e[27]!==A?(D=s.jsx("input",{value:C,onChange:j,placeholder:"—",inputMode:"numeric","aria-label":A,className:w}),e[25]=C,e[26]=j,e[27]=A,e[28]=D):D=e[28];let I;e[29]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx("span",{className:"typography-micro text-muted-foreground",children:"×"}),e[29]=I):I=e[29];const M=d?String(d.height):"";let $;e[30]!==p?($=te=>p("height",te.target.value),e[30]=p,e[31]=$):$=e[31];let E;e[32]!==a?(E=a("contextPanel.browser.device.height"),e[32]=a,e[33]=E):E=e[33];let K;e[34]!==M||e[35]!==$||e[36]!==E?(K=s.jsx("input",{value:M,onChange:$,placeholder:"—",inputMode:"numeric","aria-label":E,className:w}),e[34]=M,e[35]=$,e[36]=E,e[37]=K):K=e[37];let B;e[38]!==r||e[39]!==n?(B=()=>r(rw(n)),e[38]=r,e[39]=n,e[40]=B):B=e[40];const O=!d;let T;e[41]!==a?(T=a("contextPanel.browser.device.rotate"),e[41]=a,e[42]=T):T=e[42];let k;e[43]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(R,{name:"refresh",className:"size-3.5","aria-hidden":"true"}),e[43]=k):k=e[43];let P;e[44]!==B||e[45]!==O||e[46]!==T?(P=s.jsx(Pt,{asChild:!0,children:s.jsx(bt,{type:"button",variant:"ghost",size:"xs",className:"w-6 shrink-0 rounded-full px-0 text-muted-foreground hover:text-foreground",onClick:B,disabled:O,"aria-label":T,children:k})}),e[44]=B,e[45]=O,e[46]=T,e[47]=P):P=e[47];let F;e[48]!==a?(F=a("contextPanel.browser.device.rotate"),e[48]=a,e[49]=F):F=e[49];let q;e[50]!==F?(q=s.jsx(It,{sideOffset:6,children:F}),e[50]=F,e[51]=q):q=e[51];let Q;e[52]!==P||e[53]!==q?(Q=s.jsxs(Dt,{children:[P,q]}),e[52]=P,e[53]=q,e[54]=Q):Q=e[54];let Y;e[55]!==l||e[56]!==d?(Y=d&&l<1?s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[Math.round(l*100),"%"]}):null,e[55]=l,e[56]=d,e[57]=Y):Y=e[57];let ce;e[58]===Symbol.for("react.memo_cache_sentinel")?(ce=["system","light","dark"],e[58]=ce):ce=e[58];let X;e[59]!==i||e[60]!==o||e[61]!==a?(X=s.jsx("div",{className:"ml-auto flex shrink-0 items-center gap-1",children:ce.map(te=>s.jsx(bt,{type:"button",variant:i===te?"secondary":"ghost",size:"xs",className:Ie("shrink-0 rounded-full px-2.5 typography-micro",i===te?"text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>o(te),"aria-pressed":i===te,children:a(te==="system"?"contextPanel.browser.device.schemeSystem":te==="light"?"contextPanel.browser.device.schemeLight":"contextPanel.browser.device.schemeDark")},te))}),e[59]=i,e[60]=o,e[61]=a,e[62]=X):X=e[62];let oe;return e[63]!==N||e[64]!==D||e[65]!==K||e[66]!==Q||e[67]!==Y||e[68]!==X?(oe=s.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[N,D,I,K,Q,Y,X]}),e[63]=N,e[64]=D,e[65]=K,e[66]=Q,e[67]=Y,e[68]=X,e[69]=oe):oe=e[69],oe};function cw(t){return s.jsx("option",{value:t.id,children:t.label},t.id)}const dw=t=>{try{const e=new URL(t).pathname;return e==="/"?"":e}catch{return""}},uw=2e3,mw=()=>{if(typeof window>"u"||window.__OPENCHAMBER_ELECTRON__)return!1;const t=An();if(!t)return!1;try{return!vr(new URL(t,window.location.href).toString())}catch{return!1}},dm=t=>{const e=nt.c(33),{onOpen:n,directory:r}=t,i=r===void 0?"":r,{t:o}=Nt();let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={kind:"loading"},e[0]=l):l=e[0];const[a,u]=c.useState(l),d=hx(i),[h]=c.useState(mw);let f,p;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{let D=!0,I=null;const M=new AbortController,$=()=>{s1(M.signal).then(E=>{D&&(u(E),I=setTimeout($,uw))})};return $(),()=>{D=!1,I&&clearTimeout(I),M.abort()}},p=[],e[1]=f,e[2]=p):(f=e[1],p=e[2]),c.useEffect(f,p);const g=a.kind==="ready"?a.servers:null;let w;e[3]!==d||e[4]!==g?(w=o1({announced:d,discovered:g}),e[3]=d,e[4]=g,e[5]=w):w=e[5];const v=w;let x;e[6]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(Od,{width:110,height:110,className:"shrink-0 opacity-20"}),e[6]=x):x=e[6];let m;e[7]!==o?(m=o("contextPanel.browser.empty"),e[7]=o,e[8]=m):m=e[8];let b;e[9]!==m?(b=s.jsx("span",{className:"typography-ui-header text-foreground",children:m}),e[9]=m,e[10]=b):b=e[10];let y;e[11]!==o?(y=o("contextPanel.browser.emptyHint"),e[11]=o,e[12]=y):y=e[12];let S;e[13]!==y?(S=s.jsx("span",{className:"typography-micro text-muted-foreground",children:y}),e[13]=y,e[14]=S):S=e[14];let N;e[15]!==S||e[16]!==b?(N=s.jsxs("div",{className:"flex shrink-0 flex-col gap-1",children:[b,S]}),e[15]=S,e[16]=b,e[17]=N):N=e[17];let C;e[18]!==d||e[19]!==v||e[20]!==i||e[21]!==n||e[22]!==h||e[23]!==o?(C=v.length>0?s.jsxs("div",{className:"flex min-h-0 w-full max-w-sm flex-col gap-1",children:[s.jsx("span",{className:"shrink-0 typography-micro text-left text-muted-foreground",children:d.length>0?o("contextPanel.browser.devServers.justStarted"):o("contextPanel.browser.devServers.title")}),h?s.jsx("span",{className:"shrink-0 pb-1 text-left typography-micro text-muted-foreground",children:o("contextPanel.browser.devServers.remoteOnly")}):null,s.jsx("div",{className:"flex min-h-0 flex-col gap-1 overflow-y-auto pr-0.5",children:v.map(D=>s.jsxs(bt,{type:"button",variant:"outline",size:"sm",className:"w-full shrink-0 justify-start gap-2",onClick:()=>{ux(i),n(D.url)},children:[s.jsx(R,{name:"global",className:"size-3.5 shrink-0","aria-hidden":"true"}),s.jsx("span",{className:"truncate",children:Ha(D.url)||D.url}),s.jsx("span",{className:"ml-auto truncate typography-micro text-muted-foreground",children:dw(D.url)})]},D.port))})]}):null,e[18]=d,e[19]=v,e[20]=i,e[21]=n,e[22]=h,e[23]=o,e[24]=C):C=e[24];let j;e[25]!==v.length||e[26]!==a.kind||e[27]!==o?(j=v.length===0&&a.kind==="unavailable"?s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("contextPanel.browser.devServers.unavailable")}):null,e[25]=v.length,e[26]=a.kind,e[27]=o,e[28]=j):j=e[28];let A;return e[29]!==N||e[30]!==C||e[31]!==j?(A=s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-5 overflow-hidden bg-background p-6 text-center",children:[x,N,C,j]}),e[29]=N,e[30]=C,e[31]=j,e[32]=A):A=e[32],A},Ls=t=>Math.round(t),fw=(t,e)=>{const n=t.text.trim(),r=Object.entries(t.attributes).map(([a,u])=>`${a}="${u}"`).join(" "),i=t.ancestry.map(a=>a.selectorPart).join(" > "),o=t.computedStyle,l=t.bounds;return[`Element ${e+1}: ${t.tag}`,n?`- Text: ${n}`:null,`- Selector: ${t.selector}`,`- Path: ${t.path}`,i?`- Ancestry: ${i}`:null,r?`- Attributes: ${r}`:null,`- Bounds: x=${Ls(l.x)}, y=${Ls(l.y)}, width=${Ls(l.width)}, height=${Ls(l.height)}`,`- Styles: display=${o.display??""}; position=${o.position??""}; font=${o.fontWeight??""} ${o.fontSize??""} / ${o.lineHeight??""} ${o.fontFamily??""}; color=${o.color??""}; background=${o.backgroundColor??""}`].filter(a=>typeof a=="string")},hw=(t,e)=>{const n=t.rect;return`Region ${e+1}: x=${Ls(n.x)}, y=${Ls(n.y)}, width=${Ls(n.width)}, height=${Ls(n.height)}`},pw=(t,e)=>{const n=t.bounds;return`Drawing ${e+1}: ${t.points.length} points over x=${Ls(n.x)}, y=${Ls(n.y)}, width=${Ls(n.width)}, height=${Ls(n.height)}`},gw=({payload:t,screenshotAttached:e,intro:n})=>{const r=n.replace(/[.:]+$/g,""),i=t.comment.trim(),o=[`${r}:`,`Page: ${t.pageTitle.trim()||t.pageUrl||"browser"}`,t.pageTitle.trim()&&t.pageUrl?`URL: ${t.pageUrl}`:null,`Viewport: ${Ls(t.viewport.width)}x${Ls(t.viewport.height)}, DPR ${t.devicePixelRatio}`,`Screenshot: ${e?"attached":"not attached"}`,i?`Comment: ${i}`:null];for(const[l,a]of t.elements.entries())o.push("",...fw(a.element,l));return t.regions.length>0&&(o.push(""),t.regions.forEach((l,a)=>o.push(hw(l,a)))),t.strokes.length>0&&(o.push(""),t.strokes.forEach((l,a)=>o.push(pw(l,a)))),o.filter(l=>typeof l=="string").join(`
|
|
912
|
+
`)},xw=t=>{const e=nt.c(7),{t:n}=Nt(),r=et(yw),i=et(ww),o=Ti(Sw),l=rh(vw);let a;return e[0]!==l||e[1]!==o||e[2]!==r||e[3]!==t||e[4]!==i||e[5]!==n?(a=async u=>{const d=r??(i?"draft":null);if(!d){Re.error(n("contextPanel.browser.annotate.noSession"));return}let h=!1;if(u.screenshot)try{await l(u.screenshot),h=!0}catch{h=!1}o({directory:t,sessionKey:d},{source:"preview-annotation",fileLabel:u.payload.pageUrl||"browser",startLine:1,endLine:1,code:gw({payload:u.payload,screenshotAttached:h,intro:n("contextPanel.browser.annotate.intro")}),language:"markdown",text:""}),Re.success(n("contextPanel.browser.annotate.attached"))},e[0]=l,e[1]=o,e[2]=r,e[3]=t,e[4]=i,e[5]=n,e[6]=a):a=e[6],a},bw=()=>{const t=nt.c(16),{t:e}=Nt();let n;t[0]!==e?(n=e("contextPanel.browser.annotate.tool.element"),t[0]=e,t[1]=n):n=t[1];let r;t[2]!==e?(r=e("contextPanel.browser.annotate.tool.region"),t[2]=e,t[3]=r):r=t[3];let i;t[4]!==e?(i=e("contextPanel.browser.annotate.tool.draw"),t[4]=e,t[5]=i):i=t[5];let o;t[6]!==e?(o=e("contextPanel.browser.annotate.commentPlaceholder"),t[6]=e,t[7]=o):o=t[7];let l;t[8]!==e?(l=e("contextPanel.browser.annotate.submit"),t[8]=e,t[9]=l):l=t[9];let a;return t[10]!==n||t[11]!==r||t[12]!==i||t[13]!==o||t[14]!==l?(a={select:n,marquee:r,draw:i,commentPlaceholder:o,submit:l},t[10]=n,t[11]=r,t[12]=i,t[13]=o,t[14]=l,t[15]=a):a=t[15],a};function yw(t){return t.currentSessionId}function ww(t){return t.newSessionDraft?.open}function Sw(t){return t.addDraft}function vw(t){return t.addAttachedFile}const jw=3e4,kw=3,Cw=250,Nw={attempts:0,windowStartedAt:null},Aw=(t,e)=>{const n=t.windowStartedAt===null||e-t.windowStartedAt>=jw,r=n?0:t.attempts;return r>=kw?null:{delayMs:Cw*2**r,state:{attempts:r+1,windowStartedAt:n?e:t.windowStartedAt}}},Dw=-3,uo=t=>typeof t=="string"&&t.length>0&&t!=="about:blank",dr=t=>{const e=t;return e.detail&&typeof e.detail=="object"?e.detail:t},Pw=(t,{initialUrl:e,onUrlChange:n})=>{const[r,i]=c.useState(e?{kind:"loading",url:e}:l1),[o,l]=c.useState(e),[a,u]=c.useState(""),[d,h]=c.useState(!1),[f,p]=c.useState(!1),g=c.useRef(n);g.current=n;const w=c.useRef(Nw);return c.useEffect(()=>{if(!t)return;const v=()=>{try{const I=t.getURL();return uo(I)?I:""}catch{return""}},x=()=>{try{h(t.canGoBack()),p(t.canGoForward())}catch{}},m=I=>{uo(I)&&(l(I),g.current(I))},b=()=>{const I=v();i({kind:"loading",url:I})},y=()=>{const I=v();let M="";try{M=t.getTitle()||""}catch{M=""}u(M),m(I),x(),i($=>$.kind==="failed"&&$.url===I?$:{kind:"ready",url:I,title:M})},S=I=>{const M=dr(I);uo(M.url)&&(m(M.url),x())},N=I=>{const M=dr(I),$=Array.isArray(M.favicons)?M.favicons.find(Boolean):"",E=v();$&&E&&qu.getState().resolve(E,$)},C=I=>{const M=dr(I);typeof M.title=="string"&&u(M.title)},j=I=>{const M=dr(I);if(M.isMainFrame===!1)return;const $=typeof M.errorCode=="number"?M.errorCode:0;$!==Dw&&i({kind:"failed",url:uo(M.validatedURL)?M.validatedURL:v(),code:$,description:typeof M.errorDescription=="string"?M.errorDescription:""})};let A=null;const D=()=>{const I=v(),M=Aw(w.current,Date.now());if(!M){i({kind:"failed",url:I,code:0,description:"",crashed:!0});return}w.current=M.state,i({kind:"loading",url:I}),A=setTimeout(()=>{A=null;try{t.reload()}catch{i({kind:"failed",url:I,code:0,description:"",crashed:!0})}},M.delayMs)};t.addEventListener("did-start-loading",b),t.addEventListener("did-stop-loading",y),t.addEventListener("did-navigate",S),t.addEventListener("did-navigate-in-page",S),t.addEventListener("page-title-updated",C),t.addEventListener("page-favicon-updated",N),t.addEventListener("did-fail-load",j),t.addEventListener("render-process-gone",D),t.addEventListener("crashed",D);try{!t.isLoading()&&v()&&y()}catch{}return()=>{A!==null&&clearTimeout(A),t.removeEventListener("render-process-gone",D),t.removeEventListener("crashed",D),t.removeEventListener("did-start-loading",b),t.removeEventListener("did-stop-loading",y),t.removeEventListener("did-navigate",S),t.removeEventListener("did-navigate-in-page",S),t.removeEventListener("page-title-updated",C),t.removeEventListener("page-favicon-updated",N),t.removeEventListener("did-fail-load",j)}},[t]),{status:r,url:o,title:a,canGoBack:d,canGoForward:f}},Iw=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,Tw=4e4,mc=.5,Ew=-3,Rw=4,Mw="persist:openchamber-browser",fc=20,Ow=600,Bw=2e4,Fw=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=Nt(),{currentTheme:i}=er(),o=c.useRef(null),[l,a]=c.useState(null),u=c.useCallback(re=>{o.current=re,a(re)},[]),d=Pe(re=>re.setContextPanelTabTargetPath),h=c.useRef(hr(t)),f=h.current!==an?h.current:"",[p,g]=c.useState(f?null:an),[w,v]=c.useState(f),[x,m]=c.useState(!1),[b,y]=c.useState(!1),[S,N]=c.useState(0),[C,j]=c.useState(!1),[A,D]=c.useState(Wo),I=c.useRef(A);I.current=A;const M=c.useRef([]),[$,E]=c.useState("system"),[K,B]=c.useState({width:0,height:0}),O=c.useRef(null),T=c.useRef(null),k=c.useRef(!1),P=c.useRef(Date.now()),F=c.useCallback(re=>{!re||re===an||!e||!n||d(e,n,re)},[e,n,d]),q=Pw(l,{initialUrl:f,onUrlChange:c.useCallback(re=>{const le=Pr(re);v(le),F(le)},[F])}),[Q,Y]=c.useState(null),ce=xw(e),X=bw(),oe=q.status.kind==="loading",te=br(nm(e)),he=br(re=>re.recordVisit),_=br(re=>re.forget);c.useEffect(()=>{q.status.kind==="ready"&&he(e,{url:Pr(q.status.url),title:q.status.title})},[e,q.status,he]);const ie=c.useMemo(()=>sm(te,w),[te,w]),ge=c.useCallback(re=>{const le=hr(re);le!==an&&(v(le),Y(null),ic(le).then(se=>{const G=o.current;if(!G){g(se);return}try{G.loadURL(se)}catch{g(se)}}).catch(se=>{se instanceof Lr&&Y(le)}))},[]);c.useEffect(()=>{if(!f)return;let re=!0;return ic(f).then(le=>{re&&g(le)}).catch(le=>{if(re){if(le instanceof Lr){Y(f),g(an);return}g(f)}}),()=>{re=!1}},[]);const ae=c.useMemo(()=>({executeJavaScript:async(re,le)=>{const se=o.current;if(!se)throw new Error("Browser view is not available");return se.executeJavaScript(re,le)},capturePage:async()=>{const re=o.current;if(!re)return null;const le=re.getWebContentsId();return Number.isFinite(le)?await mr("desktop_browser_capture_page",{webContentsId:le}):null}}),[]),z=c.useCallback(()=>{if(x){m(!1),jo(ae);return}if(!q.url){Re.error(r("contextPanel.browser.annotate.noPage"));return}const re=v1(i.metadata.variant==="light"?"light":"dark");m(!0),w1({host:ae,theme:re,labels:X}).then(async le=>{m(!1),le&&await ce(le)}).catch(()=>{m(!1),Re.error(r("contextPanel.browser.annotate.failed"))})},[ae,ce,i,x,q.url,X,r]);c.useEffect(()=>{if(!x)return;const re=le=>{oh(le)||le.key!=="Escape"||(le.preventDefault(),le.stopImmediatePropagation(),m(!1),jo(ae))};return window.addEventListener("keydown",re,!0),()=>window.removeEventListener("keydown",re,!0)},[ae,x]);const ne=c.useCallback(async(re=8e3)=>{const le=Date.now();for(;;){const se=o.current;if(!se)return!1;let G=!1;try{G=se.isLoading()}catch{return!1}if(!G)return!0;if(Date.now()-le>re)return!1;await new Promise(U=>setTimeout(U,120))}},[]),ue=c.useCallback(async(re,le)=>{const se=o.current;if(!se)throw new Error("The browser panel is not ready");const G=()=>{uc(le.viewport)&&(D(oa(le.viewport)),j(!0))};if(re==="browser.back"||re==="browser.forward"){const ye=re==="browser.back";if(!(ye?se.canGoBack():se.canGoForward()))throw new Error(ye?"There is nothing to go back to in this tab":"There is nothing to go forward to in this tab");ye?se.goBack():se.goForward(),await new Promise($e=>setTimeout($e,150)),await ne();let Ke="";try{Ke=se.getTitle()||""}catch{Ke=""}return{url:Pr(se.getURL()),title:Ke}}if(re==="browser.capture"){Pe.getState().openContextBrowser(e,se.getURL());const ye=Date.now()+1200;let Fe=0,Ke=0;for(;Ke<2&&Date.now()<ye;){const fe=se.getBoundingClientRect().width;Ke=fe>=2&&Math.abs(fe-Fe)<.5?Ke+1:0,Fe=fe,await new Promise(Me=>setTimeout(Me,50))}await new Promise(fe=>{requestAnimationFrame(()=>requestAnimationFrame(()=>fe()))}),await ne();const $e=await ae.capturePage();if(!$e)throw new Error("The page could not be captured");let V="";try{V=se.getTitle()||""}catch{V=""}return{...$e,url:Pr(se.getURL()),title:V,viewport:co(I.current)}}if(re==="browser.resize"){if(!uc(le.viewport))throw new Error("viewport is required");return G(),await new Promise(ye=>setTimeout(ye,200)),await ne(),{viewport:co(oa(le.viewport))}}if(re==="browser.open"){const ye=typeof le.url=="string"?le.url:"";if(!ye)throw new Error("url is required");G(),ge(ye),await new Promise($e=>setTimeout($e,150));const Fe=await ne(25e3);let Ke="";try{Ke=se.getTitle()||""}catch{Ke=""}return{url:hr(ye),title:Ke,opened:!0,settled:Fe,viewport:co(I.current)}}await ne();const U=ye=>typeof ye=="string"&&ye?ye:void 0,W=(()=>{switch(re){case"browser.snapshot":return Y1({selector:U(le.selector)});case"browser.click":return X1({selector:U(le.selector),text:U(le.text)});case"browser.type":return J1({selector:String(le.selector??""),value:String(le.value??""),submit:le.submit===!0});case"browser.inspect":return tw({selector:String(le.selector??"")});case"browser.scroll":return Z1({selector:U(le.selector),direction:U(le.direction)});default:return null}})();if(!W)throw new Error(`Unsupported browser action: ${re}`);const Ne=await se.executeJavaScript(W,!0);if(!Ne||typeof Ne!="object")throw new Error("The page returned no result");const Oe=Ne;if(Oe.ok!==!0)throw new Error(typeof Oe.error=="string"&&Oe.error?Oe.error:"Browser action failed");if(re==="browser.snapshot"){const ye=M.current;return{...Oe,viewport:co(I.current),...ye.length>0?{consoleProblems:[...ye]}:{}}}return(re==="browser.click"||re==="browser.type"&&le.submit===!0)&&(await new Promise(ye=>setTimeout(ye,150)),await ne()),Ne},[ae,e,ge,ne]);c.useEffect(()=>M1({run:ue}),[ue]),c.useEffect(()=>{const re=ae;return()=>{jo(re)}},[ae]),c.useEffect(()=>{if(!l)return;const re=se=>{const G=se;if(typeof G.level!="number"||G.level<2)return;const U=G.sourceId?`${G.sourceId}${G.line?`:${G.line}`:""}`:"";M.current.push({level:G.level>=3?"error":"warning",message:String(G.message??"").slice(0,400),source:U}),M.current.length>fc&&M.current.splice(0,M.current.length-fc)},le=()=>{M.current=[]};return l.addEventListener("console-message",re),l.addEventListener("did-start-loading",le),()=>{l.removeEventListener("console-message",re),l.removeEventListener("did-start-loading",le)}},[l]);const me=c.useRef(new Set),ke=c.useCallback(re=>{me.current.clear(),ge(re)},[ge]);c.useEffect(()=>{if(!l)return;const re=se=>{const G=dr(se),U=typeof G.url=="string"?G.url:"";!U||!ac(U)||(se.preventDefault(),ge(U))},le=se=>{const G=dr(se);if(G.isMainFrame===!1||G.errorCode===-3)return;const U=typeof G.validatedURL=="string"?G.validatedURL:"";!U||!ac(U)||me.current.has(U)||(me.current.add(U),ge(U))};return l.addEventListener("will-navigate",re),l.addEventListener("did-fail-load",le),()=>{l.removeEventListener("will-navigate",re),l.removeEventListener("did-fail-load",le)}},[ge,l]),c.useEffect(()=>{if(!l)return;const re=le=>{const se=le.detail;le.preventDefault(),se?.url&&ge(se.url)};return l.addEventListener("new-window",re),()=>l.removeEventListener("new-window",re)},[ge,l]);const Te=c.useCallback(re=>{const le=Math.min(Rw,Math.max(Ew,re));N(le);try{o.current?.setZoomLevel(le)}catch{}},[]),je=c.useCallback(re=>{mr("desktop_browser_clear_data",{partition:Mw,cookies:re==="cookies",cache:re==="cache"}).then(()=>{Re.success(r(re==="cookies"?"contextPanel.browser.clearedCookies":"contextPanel.browser.clearedCache"));try{o.current?.reloadIgnoringCache()}catch{}}).catch(()=>Re.error(r("contextPanel.browser.clearFailed")))},[r]);c.useEffect(()=>{const re=O.current;if(!re||typeof ResizeObserver>"u")return;const le=new ResizeObserver(se=>{const G=se[0]?.contentRect;G&&B({width:G.width,height:G.height})});return le.observe(re),()=>le.disconnect()},[]);const Ee=c.useCallback(re=>{E(re);const le=o.current;if(!le)return;let se=-1;try{se=le.getWebContentsId()}catch{return}mr("desktop_browser_set_color_scheme",{webContentsId:se,scheme:re}).catch(G=>{E("system"),Re.error(G instanceof Error?G.message:r("contextPanel.browser.device.schemeFailed"))})},[r]),xe=c.useCallback(()=>{try{oe?o.current?.stop():o.current?.reload()}catch{}},[oe]),H=q.status;c.useEffect(()=>{const re=()=>{y(!0);const G=setTimeout(()=>{try{o.current?.reload()}catch{}},Ow);return()=>clearTimeout(G)};if(H.kind==="failed"){if(!e1(H.code,H.url)){y(!1);return}const G=Date.now(),U=T.current?.url===H.url?T.current:{url:H.url,startedAt:G};if(T.current=U,G-U.startedAt>Tw){y(!1);return}return re()}if(H.kind==="loading")return;if(T.current=null,H.kind!=="ready"||!H.url||!vr(H.url)){k.current=!0,y(!1);return}if(k.current||Date.now()-P.current>Bw){k.current=!0,y(!1);return}let le=!1,se=null;return n1(Pr(H.url)).then(G=>{if(!le){if(G===null||G<500){k.current=!0,y(!1);return}se=re()}}),()=>{le=!0,se?.()}},[H]);const Ce=q.status.kind==="failed"&&!b?q.status:null,ve=ow(A,K);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsx(am,{address:w,onAddressChange:v,onSubmit:ke,suggestions:ie,onForgetSuggestion:re=>_(e,re),onBack:()=>{try{o.current?.goBack()}catch{}},onForward:()=>{try{o.current?.goForward()}catch{}},onReload:xe,onOpenExternal:()=>{Xo(q.url||w)},canGoBack:q.canGoBack,canGoForward:q.canGoForward,isLoading:oe,onAnnotate:z,isAnnotating:x,onOpenDevTools:()=>{try{o.current?.openDevTools()}catch{}},onHardReload:()=>{try{o.current?.reloadIgnoringCache()}catch{}},onZoomIn:()=>Te(S+mc),onZoomOut:()=>Te(S-mc),onZoomReset:()=>Te(0),zoomPercent:Math.round(Math.pow(1.2,S)*100),onClearCookies:()=>je("cookies"),onClearCache:()=>je("cache"),onToggleDeviceBar:()=>j(re=>!re),isDeviceBarOpen:C}),C?s.jsx(lw,{viewport:A,onViewportChange:D,colorScheme:$,onColorSchemeChange:Ee,scale:ve?.scale??1}):null,s.jsxs("div",{ref:O,className:Ie("relative min-h-0 flex-1 bg-background",ve&&"flex items-center justify-center overflow-hidden bg-[var(--surface-muted)]"),children:[p!==null?s.jsx("webview",{ref:u,src:p,partition:"persist:openchamber-browser",allowpopups:!0,style:ve?{width:`${ve.width}px`,height:`${ve.height}px`,transform:`scale(${ve.scale})`,border:"none",flex:"none",boxShadow:"0 2px 18px rgba(0,0,0,.28)"}:{width:"100%",height:"100%",border:"none"}}):null,p!==null&&!f&&!q.url&&!oe?s.jsx(dm,{onOpen:ke,directory:e}):null,b?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:r("contextPanel.browser.waitingForServer")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:r("contextPanel.browser.waitingForServerHint")})]}):null,Q?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:r("contextPanel.browser.tunnelFailed")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:r("contextPanel.browser.tunnelFailedHint",{url:Q})})]}):null,Ce&&!Q?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:Ce.crashed?r("contextPanel.browser.crashed"):r("contextPanel.browser.loadFailed")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:Ce.crashed?r("contextPanel.browser.crashedHint"):Ce.description||r("contextPanel.browser.loadFailedUnknown")})]}):null,oe?s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-0.5 overflow-hidden",children:s.jsx("div",{className:"h-full w-1/3 animate-[browser-progress_1.1s_ease-in-out_infinite] bg-[var(--primary)]"})}):null]})]})},_w=t=>{const e=nt.c(49),{initialUrl:n,directory:r,tabID:i}=t,{t:o}=Nt(),l=Pe($w);let a;e[0]!==n?(a=hr(n),e[0]=n,e[1]=a):a=e[1];const u=a,d=u!==an?u:"",[h,f]=c.useState(d),[p,g]=c.useState(d);let w;e[2]!==d?(w=d?[d]:[],e[2]=d,e[3]=w):w=e[3];const[v,x]=c.useState(w),[m,b]=c.useState(d?0:-1),[y,S]=c.useReducer(Ww,0);let N;e[4]!==r||e[5]!==l||e[6]!==i?(N=oe=>{!oe||oe===an||!r||!i||l(r,i,oe)},e[4]=r,e[5]=l,e[6]=i,e[7]=N):N=e[7];const C=N;let j;e[8]!==r?(j=nm(r),e[8]=r,e[9]=j):j=e[9];const A=br(j),D=br(zw),I=br(Vw);let M;e[10]!==h||e[11]!==A?(M=sm(A,h),e[10]=h,e[11]=A,e[12]=M):M=e[12];const $=M;let E;e[13]!==r||e[14]!==m||e[15]!==C||e[16]!==D?(E=oe=>{const te=hr(oe);te!==an&&(f(te),g(te),C(te),D(r,{url:te}),x(he=>{const _=m>=0?he.slice(0,m+1):[];return _[_.length-1]===te?(b(_.length-1),_):(b(_.length),[..._,te])}))},e[13]=r,e[14]=m,e[15]=C,e[16]=D,e[17]=E):E=e[17];const K=E;let B;e[18]!==v||e[19]!==C?(B=oe=>{const te=v[oe];te&&(b(oe),f(te),g(te),C(te))},e[18]=v,e[19]=C,e[20]=B):B=e[20];const O=B;let T;e[21]!==r||e[22]!==I?(T=oe=>I(r,oe),e[21]=r,e[22]=I,e[23]=T):T=e[23];let k,P;e[24]!==O||e[25]!==m?(P=()=>O(m-1),k=()=>O(m+1),e[24]=O,e[25]=m,e[26]=k,e[27]=P):(k=e[26],P=e[27]);let F;e[28]!==h||e[29]!==p?(F=()=>{Xo(p||h)},e[28]=h,e[29]=p,e[30]=F):F=e[30];const q=m>0,Q=m>=0&&m<v.length-1;let Y;e[31]!==h||e[32]!==K||e[33]!==$||e[34]!==k||e[35]!==F||e[36]!==q||e[37]!==Q||e[38]!==T||e[39]!==P?(Y=s.jsx(am,{address:h,onAddressChange:f,onSubmit:K,suggestions:$,onForgetSuggestion:T,onBack:P,onForward:k,onReload:S,onOpenExternal:F,canGoBack:q,canGoForward:Q,isLoading:!1}),e[31]=h,e[32]=K,e[33]=$,e[34]=k,e[35]=F,e[36]=q,e[37]=Q,e[38]=T,e[39]=P,e[40]=Y):Y=e[40];let ce;e[41]!==p||e[42]!==K||e[43]!==y||e[44]!==o?(ce=s.jsx("div",{className:"relative min-h-0 flex-1 bg-background",children:p?s.jsx("iframe",{src:p,title:o("contextPanel.browser.frameTitle"),className:"h-full w-full border-none bg-white",sandbox:"allow-scripts allow-forms allow-same-origin allow-popups"},`${p}|${y}`):s.jsx(dm,{onOpen:K})}),e[41]=p,e[42]=K,e[43]=y,e[44]=o,e[45]=ce):ce=e[45];let X;return e[46]!==Y||e[47]!==ce?(X=s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[Y,ce]}),e[46]=Y,e[47]=ce,e[48]=X):X=e[48],X},Lw=t=>{const e=nt.c(3),[n]=c.useState(Iw);let r;return e[0]!==n||e[1]!==t?(r=n?s.jsx(Fw,{...t}):s.jsx(_w,{...t}),e[0]=n,e[1]=t,e[2]=r):r=e[2],r};function $w(t){return t.setContextPanelTabTargetPath}function Ww(t){return t+1}function zw(t){return t.recordVisit}function Vw(t){return t.forget}const Uw=$n(()=>_n(()=>import("./WalkthroughView-BALp2d9O.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123])).then(t=>({default:t.WalkthroughView}))),Kw=$n(()=>_n(()=>import("./DiffView-DkkSa30n.js"),__vite__mapDeps([124,1,2,4,5,6,7,8,9,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,116,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,117,118,119,120,121,122,123])).then(t=>({default:t.DiffView}))),Hw=$n(()=>_n(()=>import("./FilesView-DDu8zDy5.js"),__vite__mapDeps([125,1,2,4,5,6,7,8,9,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,116,126,127,128,129,130,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,131,132,117,118,114,121,133,115,134])).then(t=>({default:t.FilesView}))),Gw=$n(()=>_n(()=>import("./GitView-1Ixo8z-M.js"),__vite__mapDeps([135,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,116,136,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,117,118,120,121,122,123])).then(t=>({default:t.GitView}))),qw=$n(()=>_n(()=>import("./LinearIssuesView-Bs1rZrF2.js"),__vite__mapDeps([137,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82])).then(t=>({default:t.LinearIssuesView}))),Qw=$n(()=>_n(()=>import("./PlanView-trDaszfq.js"),__vite__mapDeps([138,1,2,4,5,6,7,8,9,126,57,58,59,60,61,62,79,55,56,63,127,128,129,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,80,81,82,115,116,134,117,118,102,103,87,88,89,90,91,92,93,94,95,96,97,98,99,100])).then(t=>({default:t.PlanView}))),Yw=380,Xw=1400,um=600,Jw=100,Zw=24,Vo=new Map,eS=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},hc=t=>Number.isFinite(t)?Math.min(Xw,Math.max(Yw,Math.round(t))):um,tS=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},sS=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},mm=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="walkthrough"?"contextPanel.mode.walkthrough":t==="plan"?"contextPanel.mode.plan":t==="browser"?"contextPanel.mode.browser":t==="git"?"layout.rightSidebar.git":t==="pr"?"contextPanel.mode.pr":t==="linear"?"contextPanel.mode.linear":t==="notes"?"contextRail.surface.notes":t==="terminal"?"layout.mainTab.terminal":"contextPanel.mode.context"),nS=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},rS=(t,e,n)=>{if(t.mode==="chat"){const r=ia(t.dedupeKey);if(r){const o=e.get(r)?.trim();if(o)return o}const i=t.sessionTitleFallback?.trim();return i||n("contextPanel.mode.chat")}return t.mode==="browser"?Ha(t.targetPath??"")||t.label||n("contextPanel.mode.browser"):t.label?t.label:t.mode==="file"?nS(t.targetPath)||n("contextPanel.mode.files"):t.mode==="diff"?n("contextPanel.mode.diff"):mm(t.mode,n)},pc=(t,e={})=>{if(t.mode==="file")return t.targetPath?s.jsx(Da,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(_u,{className:"h-3.5 w-3.5"});if(t.mode==="walkthrough")return s.jsx(R,{name:"route",className:"h-3.5 w-3.5"});if(t.mode==="git")return s.jsx(R,{name:"git-branch",className:"h-3.5 w-3.5"});if(t.mode==="pr")return s.jsx(R,{name:"github",className:"h-3.5 w-3.5"});if(t.mode==="linear")return s.jsx(R,{name:"linear",className:"h-3.5 w-3.5"});if(t.mode==="notes")return s.jsx(R,{name:"sticky-note",className:"h-3.5 w-3.5"});if(t.mode==="terminal")return s.jsx(R,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(R,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(R,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(R,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="browser"){const n=oS(t.targetPath??"",e);return n?s.jsx("img",{src:n,alt:"","aria-hidden":"true",className:"h-3.5 w-3.5 rounded-[3px] object-contain"}):s.jsx(R,{name:"global",className:"h-3.5 w-3.5"})}},oS=(t,e)=>{try{return e[new URL(t).origin]??""}catch{return""}},iS=200,aS=480,lS=({visible:t})=>{const{t:e}=Nt(),n=Pe(m=>m.contextEditorTreeWidth),r=Pe(m=>m.setContextEditorTreeWidth),[i,o]=c.useState(!1),l=c.useRef(0),a=c.useRef(n),u=c.useRef(null),d=c.useRef(null),h=c.useRef(null),f=c.useCallback(m=>Math.min(aS,Math.max(iS,Math.round(m))),[]),p=c.useCallback(m=>{const b=h.current;b&&(b.style.width=`${m}px`,b.style.setProperty("--oc-editor-tree-width",`${m}px`))},[]),g=m=>{if(t){try{m.currentTarget.setPointerCapture(m.pointerId)}catch{}d.current=m.pointerId,o(!0),l.current=m.clientX,a.current=n,u.current=n,m.preventDefault()}},w=m=>{if(!i||d.current!==m.pointerId)return;const b=l.current-m.clientX,y=f(a.current+b);u.current!==y&&(u.current=y,p(y))},v=m=>{if(d.current!==m.pointerId)return;try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}const b=f(u.current??n);d.current=null,u.current=null,o(!1),r(b)},x=t?n:0;return s.jsxs("div",{ref:h,className:Ie("relative h-full flex-shrink-0 overflow-hidden border-l border-border bg-background will-change-[width] motion-reduce:transition-none",!t&&"border-l-0"),style:{width:`${i?u.current??x:x}px`,"--oc-editor-tree-width":`${i?u.current??n:n}px`,overflowX:"clip",transitionProperty:i?"none":"width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t,children:[t&&s.jsx("div",{className:Ie("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",i&&"bg-[var(--interactive-border)]"),onPointerDown:g,onPointerMove:w,onPointerUp:v,onPointerCancel:v,role:"separator","aria-orientation":"vertical","aria-label":e("contextPanel.actions.resizePanelAria")}),s.jsx("div",{className:Ie("relative z-10 h-full shrink-0 transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",i&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-editor-tree-width)"},"aria-hidden":!t,children:s.jsx(jy,{})})]})},ia=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,cS=(t,e)=>{if(t.size!==e.size)return!1;for(const[n,r]of t)if(e.get(n)!==r)return!1;return!0},dS=(t,e)=>{if(e.length===0)return Vo;const n=new Set(e),r=new Map;for(const i of t){if(!n.has(i.id))continue;const o=i.title?.trim();o&&r.set(i.id,o)}return r.size===0?Vo:r},uS=(t,e)=>{const n=Pd(t),r=c.useRef(Vo),i=c.useRef(e);return i.current=e,c.useSyncExternalStore(n.subscribe,c.useCallback(()=>{const o=dS(n.getState().session,i.current);return cS(r.current,o)?r.current:(r.current=o,o)},[n]),()=>Vo)},mS=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,fS=()=>{const{t}=Nt(),e=Sr()??"",n=c.useMemo(()=>eS(e),[e]),r=Pe(de=>n?de.contextPanelByDirectory[n]:void 0),i=Pe(de=>de.closeContextPanel),o=Pe(de=>de.closeContextPanelTab),l=Pe(de=>de.openContextPanelTab),a=Pe(de=>de.toggleContextPanelExpanded),u=Pe(de=>de.setContextPanelWidth),d=Pe(de=>de.setActiveContextPanelTab),h=Pe(de=>de.openContextBrowser);c.useEffect(()=>{if(e)return O1(de=>h(e,de))},[e,h]);const f=Pe(de=>de.reorderContextPanelTabs),p=mn(de=>de.setSelectedPath),g=Pe(de=>de.contextEditorTreeVisible),w=Pe(de=>de.toggleContextEditorTree),v=Pe(de=>de.openNewContextBrowserTab),x=qu(de=>de.byOrigin),m=Pe(de=>de.allowPromptingSubagentSessions),{themeMode:b,setThemeMode:y,lightThemeId:S,darkThemeId:N,currentTheme:C}=er(),j=c.useMemo(()=>r?.tabs??[],[r?.tabs]),A=j.find(de=>de.id===r?.activeTabId)??j[j.length-1]??null,D=!!(r?.isOpen&&A),I=!!(D&&r?.expanded),[M,$]=c.useState(null),E=A?.mode??null,K=E?r?.widthByMode?.[E]:void 0,B=E?ih(E):.5,O=M??(typeof window<"u"?window.innerWidth:um*2),T=hc(K??Math.round(B*O)),k=c.useMemo(()=>{const de=[];for(const J of j){if(J.mode!=="chat")continue;const Se=ia(J.dedupeKey);Se&&!de.includes(Se)&&de.push(Se)}return de},[j]),P=uS(n||void 0,k),[F,q]=c.useState(!1),Q=c.useRef(0),Y=c.useRef(T),ce=c.useRef(null),X=c.useRef(null),oe=c.useRef(null),te=c.useRef(new Map),he=c.useRef(new Map),_=c.useRef(!1);c.useLayoutEffect(()=>{const de=oe.current?.parentElement;if(!de||typeof ResizeObserver>"u")return;const J=new ResizeObserver(()=>{$(de.clientWidth||null)});return J.observe(de),$(de.clientWidth||null),()=>J.disconnect()},[]),c.useEffect(()=>{if(!D||_.current){_.current=D;return}const de=window.requestAnimationFrame(()=>{oe.current?.focus({preventScroll:!0})});return _.current=!0,()=>window.cancelAnimationFrame(de)},[D]);const ie=c.useRef(null),ge=c.useRef(null),ae=c.useCallback(()=>{ge.current=null;const de=oe.current,J=ce.current;!de||J===null||de.style.setProperty("--oc-context-panel-width",`${J}px`)},[]);c.useEffect(()=>()=>{ge.current!==null&&clearTimeout(ge.current)},[]);const z=c.useCallback(de=>{const J=hc(de),Se=ie.current;return Se===null?J:Math.min(J,Math.max(1,Se))},[]),ne=c.useCallback(de=>{!D||I||!n||(X.current=de.pointerId,q(!0),Q.current=de.clientX,Y.current=T,ce.current=T,ie.current=tS(oe.current),document.documentElement.style.cursor="col-resize",de.preventDefault())},[n,I,D,T]),ue=c.useCallback(()=>{const de=z(ce.current??T);ce.current=null,ie.current=null,ge.current!==null&&(clearTimeout(ge.current),ge.current=null),document.documentElement.style.cursor="",n&&E&&u(n,E,de),q(!1),X.current=null},[E,z,n,u,T]);c.useEffect(()=>{if(!F)return;const de=Ve=>{if(X.current!==Ve.pointerId)return;const He=Q.current-Ve.clientX,it=z(Y.current+He);ce.current!==it&&(ce.current=it,ge.current===null&&(ge.current=setTimeout(ae,Jw)))},J=Ve=>{X.current===Ve.pointerId&&ue()},Se=()=>{ue()};return window.addEventListener("pointermove",de),window.addEventListener("pointerup",J),window.addEventListener("pointercancel",J),window.addEventListener("blur",Se),()=>{window.removeEventListener("pointermove",de),window.removeEventListener("pointerup",J),window.removeEventListener("pointercancel",J),window.removeEventListener("blur",Se)}},[ae,z,ue,F]),c.useEffect(()=>{F||(ce.current=null,document.documentElement.style.cursor="")},[F]);const me=c.useCallback(()=>{n&&i(n)},[i,n]),ke=c.useCallback(()=>{n&&a(n)},[n,a]),Te=c.useCallback(de=>{de.key==="Escape"&&(ah(de.target)||(de.preventDefault(),de.stopPropagation(),me()))},[me]);c.useEffect(()=>{if(!(!n||!A)&&A.mode==="file"&&A.targetPath){p(n,A.targetPath,{allowOutsideRoot:!0});return}},[A,n,p]);const je=c.useMemo(()=>j.filter(de=>de.mode==="chat"),[j]),Ee=D&&A?.mode==="chat"?A.id:null,xe=D&&A?.mode==="chat"?ia(A.dedupeKey):null,H=Hg(je,Ee);c.useEffect(()=>{if(!D||!n||!xe||typeof window>"u")return;const de=()=>{if(document.visibilityState==="hidden"||!document.hasFocus()){li(n,xe,!1);return}Bd(xe),li(n,xe,!0)};de();const J=window.setInterval(de,1e4);return window.addEventListener("focus",de),window.addEventListener("blur",de),document.addEventListener("visibilitychange",de),()=>{window.clearInterval(J),window.removeEventListener("focus",de),window.removeEventListener("blur",de),document.removeEventListener("visibilitychange",de),li(n,xe,!1)}},[xe,n,D]);const Ce=c.useCallback((de,J,Se)=>Gg(he.current,de,J,n||null,Se,{mode:b,lightThemeId:S,darkThemeId:N,currentTheme:C},{allowPromptingSubagentSessions:m}),[m,C,N,n,S,b]),ve=H&&xe?Ce(H.id,xe,H.readOnly):null;c.useEffect(()=>{const de=new Set(j.map(J=>J.id));for(const J of he.current.keys())de.has(J)||he.current.delete(J)},[j]);const re=c.useCallback(de=>{!n||A?.mode!=="diff"||l(n,{mode:"diff",targetPath:A.targetPath,stagedDiff:de==="staged",diffScope:de})},[A,n,l]),le=c.useCallback(()=>{if(typeof window>"u")return;const de={themeMode:b,lightThemeId:S,darkThemeId:N,currentTheme:C};for(const J of te.current.values()){const Se=J.contentWindow;Se&&Se.postMessage({type:"openchamber:theme-sync",payload:de},window.location.origin)}},[C,N,S,b]),se=c.useCallback(()=>{if(typeof window>"u")return;const de={allowPromptingSubagentSessions:m};for(const J of te.current.values()){const Se=J.contentWindow;Se&&Se.postMessage({type:"openchamber:chat-settings-sync",payload:de},window.location.origin)}},[m]),G=c.useCallback((de,J,Se)=>{const Ve=J.contentWindow;Ve&&Ve.postMessage({type:Su,payload:{visible:Ee===de}},Se)},[Ee]),U=c.useCallback(()=>{if(!(typeof window>"u"))for(const[de,J]of te.current.entries())G(de,J,window.location.origin)},[G]);c.useEffect(()=>{if(typeof window>"u")return;const de=J=>{if(J.origin!==window.location.origin)return;const Se=Array.from(te.current.entries()).find(([,st])=>st.contentWindow===J.source);if(!Se)return;const Ve=J.data;if(Ve?.type===qg){const[st,ee]=Se;G(st,ee,J.origin);return}if(Ve?.type===Qg){if(typeof Ve.requestId!="string"||!Ve.requestId)return;const st=ps(),ee={apiBaseUrl:An(),clientToken:Wr(),localOrigin:typeof window.__OPENCHAMBER_LOCAL_ORIGIN__=="string"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"",runtimeHeaders:xd(),relayHostId:st.startsWith("host:")?st.slice(5):"",relay:ff()??void 0};J.source?.postMessage({type:Yg,requestId:Ve.requestId,payload:ee},J.origin);return}if(Ve?.type==="openchamber:theme-sync-request"){le();return}if(Ve?.type==="openchamber:chat-settings-request"){se();return}if(Ve?.type!=="openchamber:cycle-theme-request")return;const He=["light","dark","system"],Ue=(He.indexOf(b)+1)%He.length;y(He[Ue])};return window.addEventListener("message",de),()=>window.removeEventListener("message",de)},[se,G,le,y,b]),c.useLayoutEffect(()=>{j.some(J=>J.mode==="chat")&&(le(),se(),U())},[N,S,se,U,le,j,b]);const be=A?.mode==="file"||A?.mode==="chat"||A?.mode==="browser",W=c.useMemo(()=>A?j.filter(de=>de.mode===A.mode):[],[A,j]),Ne=c.useMemo(()=>W.map(de=>{const J=rS(de,P,t),Se=mS(J,Zw),Ve=sS(de.targetPath,e);return{id:de.id,label:Se,icon:pc(de,x),title:Ve?`${J}: ${Ve}`:J,closeLabel:t("contextPanel.tab.closeTabAria",{label:Se})}}),[W,e,x,P,t]),Oe=A?.mode==="context"?s.jsx($y,{}):A?.mode==="git"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(Gw,{isActive:D})}):A?.mode==="pr"?s.jsx(Qb,{}):A?.mode==="linear"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(qw,{})}):A?.mode==="notes"?s.jsx(dg,{}):A?.mode==="plan"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(Qw,{targetPath:A.targetPath,savedProjectPlan:A.projectPlanId&&A.projectPlanRef?{projectRef:A.projectPlanRef,planId:A.projectPlanId}:null})}):null,ye=c.useMemo(()=>j.filter(de=>de.mode==="browser"),[j]),Fe=c.useMemo(()=>j.filter(de=>de.mode==="diff"),[j]),Ke=c.useMemo(()=>j.find(de=>de.mode==="terminal")??null,[j]),$e=c.useMemo(()=>j.some(de=>de.mode==="walkthrough"),[j]),V=c.useMemo(()=>j.some(de=>de.mode==="file"),[j]),fe=c.useMemo(()=>j.some(de=>de.mode==="file"&&de.targetPath),[j]),Me=A?.mode==="file",De=Pe(de=>de.closeContextPanelTabs),at=c.useCallback(de=>{if(!n)return null;const{id:J,index:Se,allIds:Ve,close:He}=de,it=()=>De(n,Ve.filter(qe=>qe!==J)),Ue=()=>De(n,Ve.slice(0,Se)),st=()=>De(n,Ve.slice(Se+1)),ee=()=>De(n,Ve),ze=Ve.length>1,_e=Se===0,pe=Se===Ve.length-1;return s.jsxs(s.Fragment,{children:[s.jsxs(Kn,{onClick:He,children:[s.jsx(R,{name:"close",className:"mr-2 size-4"}),t("contextPanel.tab.menu.close")]}),s.jsx(zi,{}),s.jsxs(Kn,{onClick:it,disabled:!ze,children:[s.jsx(R,{name:"expand-horizontal",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeOthers")]}),s.jsxs(Kn,{onClick:Ue,disabled:_e,children:[s.jsx(R,{name:"expand-left",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeToLeft")]}),s.jsxs(Kn,{onClick:st,disabled:pe,children:[s.jsx(R,{name:"expand-right",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeToRight")]}),s.jsx(zi,{}),s.jsxs(Kn,{onClick:ee,disabled:!ze,children:[s.jsx(R,{name:"close-circle",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeAll")]})]})},[De,n,t]),Qe=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[be?s.jsx(iu,{items:Ne,activeId:A?.id??null,onSelect:de=>{n&&d(n,de)},onClose:de=>{n&&o(n,de)},onReorder:(de,J)=>{n&&f(n,de,J)},layoutMode:"scrollable",variant:"default",tabContextMenu:at}):s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[A?pc(A,x):null,s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:A?mm(A.mode,t):null})]}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[A?.mode==="browser"?s.jsx(bt,{type:"button",variant:"ghost",size:"sm",onClick:()=>{n&&v(n)},className:"h-7 w-7 p-0",title:t("contextPanel.browser.newTab"),"aria-label":t("contextPanel.browser.newTab"),children:s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})}):null,Me?s.jsx(bt,{type:"button",variant:"ghost",size:"sm",onClick:w,className:"h-7 w-7 p-0",title:t("contextRail.editorTree.toggle"),"aria-label":t("contextRail.editorTree.toggle"),"aria-pressed":g,children:s.jsx(R,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,s.jsx(bt,{type:"button",variant:"ghost",size:"sm",onClick:ke,className:"h-7 w-7 p-0",title:t(I?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(I?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:I?s.jsx(R,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(bt,{type:"button",variant:"ghost",size:"sm",onClick:me,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]})]}),lt=D?I?{"--oc-context-panel-width":M!==null?`${M}px`:"100%",width:M!==null?`${M}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${T}px`}:{"--oc-context-panel-width":`${T}px`,width:0,maxWidth:"100%",overflowX:"clip"};return s.jsxs("aside",{ref:oe,"data-context-panel":"true",tabIndex:-1,inert:!D||void 0,className:Ie("flex min-h-0 flex-col overflow-hidden bg-background",I?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!D&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:Te,style:lt,children:[D&&!I&&s.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),D&&s.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!I&&s.jsx("div",{className:Ie("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",F&&"bg-[var(--interactive-border)]"),onPointerDown:ne,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),s.jsxs("div",{className:Ie("relative z-10 flex h-full min-h-0 shrink-0 flex-col duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none","transition-[width,opacity]",!D&&"pointer-events-none select-none opacity-0"),style:{width:I?M!==null?`${M}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!D,children:[Qe,s.jsxs("div",{className:Ie("relative min-h-0 flex-1 overflow-hidden",F&&"pointer-events-none"),children:[V?s.jsxs("div",{className:Ie("absolute inset-0 flex",Me?"flex":"hidden"),children:[s.jsx("div",{className:"h-full min-w-0 flex-1",children:fe?s.jsx(c.Suspense,{fallback:null,children:s.jsx(Hw,{mode:"editor-only"})}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(R,{name:"file-code",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.editorEmpty.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.editorEmpty.description")})]})}),s.jsx(lS,{visible:g})]}):null,H&&xe&&ve?s.jsx("iframe",{ref:de=>{if(!de){te.current.delete(H.id);return}te.current.set(H.id,de)},src:ve,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:xe}),className:"absolute inset-0 h-full w-full border-0 bg-background",onLoad:()=>{le(),se(),U()}},H.id):null,ye.map(de=>s.jsx("div",{className:Ie("absolute inset-0",A?.id!==de.id&&"hidden"),children:s.jsx(Lw,{initialUrl:de.targetPath??"",directory:n,tabID:de.id})},de.id)),Fe.map(de=>s.jsx("div",{className:Ie("absolute inset-0",A?.id!==de.id&&"hidden"),children:s.jsx(c.Suspense,{fallback:null,children:s.jsx(Kw,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:de.diffScope??(de.stagedDiff?"staged":"working"),onDiffScopeChange:re,targetFilePath:de.targetPath,flushContent:!0})})},de.id)),Ke?s.jsx("div",{className:Ie("absolute inset-0",A?.mode==="terminal"?"block":"hidden"),children:s.jsx(ug,{visible:D&&A?.mode==="terminal",directory:Ke.targetDirectory})}):null,$e?s.jsx("div",{className:Ie("absolute inset-0",A?.mode==="walkthrough"?"block":"hidden"),children:s.jsx(c.Suspense,{fallback:null,children:s.jsx(Uw,{directory:e,visible:A?.mode==="walkthrough"})})}):null,A?.mode!=="chat"&&!Me&&A?.mode!=="browser"&&A?.mode!=="diff"&&A?.mode!=="terminal"&&A?.mode!=="walkthrough"?Oe:null]})]})]})},hS=t=>{const e=nt.c(42),{open:n,onOpenChange:r}=t,{t:i}=Nt(),o=Pe(pS),l=Pe(gS),a=Pe(xS),u=Pe(bS);let d;e[0]!==o?(d=Fd(o),e[0]=o,e[1]=d):d=e[1];const h=d,f=l.length===0;let p;if(e[2]!==l||e[3]!==h){let A;e[5]!==l?(A=D=>l.includes(D.id),e[5]=l,e[6]=A):A=e[6],p=h.every(A),e[2]=l,e[3]=h,e[4]=p}else p=e[4];const g=p;let w;e[7]!==i?(w=i("contextRail.configure.dialogTitle"),e[7]=i,e[8]=w):w=e[8];let v;e[9]!==w?(v=s.jsx(Is,{children:w}),e[9]=w,e[10]=v):v=e[10];let x;e[11]!==i?(x=i("contextRail.configure.dialogDescription"),e[11]=i,e[12]=x):x=e[12];let m;e[13]!==x?(m=s.jsx(Ts,{children:x}),e[13]=x,e[14]=m):m=e[14];let b;e[15]!==v||e[16]!==m?(b=s.jsxs(Ws,{children:[v,m]}),e[15]=v,e[16]=m,e[17]=b):b=e[17];let y;if(e[18]!==l||e[19]!==a||e[20]!==h||e[21]!==i){let A;e[23]!==l||e[24]!==a||e[25]!==i?(A=D=>s.jsx(lh,{settingsItem:`layout.context-rail.surface.${D.id}`,checked:!l.includes(D.id),onChange:I=>a(D.id,I),label:i(D.labelKey),ariaLabel:i(D.labelKey)},D.id),e[23]=l,e[24]=a,e[25]=i,e[26]=A):A=e[26],y=h.map(A),e[18]=l,e[19]=a,e[20]=h,e[21]=i,e[22]=y}else y=e[22];let S;e[27]!==y?(S=s.jsx("div",{className:"flex flex-col",children:y}),e[27]=y,e[28]=S):S=e[28];let N;e[29]!==f||e[30]!==g||e[31]!==u||e[32]!==i?(N=f?null:s.jsxs("div",{className:"flex items-center justify-between border-t pt-3",children:[g?s.jsx("span",{className:"text-xs text-destructive",children:i("contextRail.configure.noneWarning")}):s.jsx("span",{}),s.jsx(bt,{variant:"link",size:"xs",onClick:()=>u([]),className:"normal-case text-muted-foreground hover:text-foreground",children:i("contextRail.configure.showAll")})]}),e[29]=f,e[30]=g,e[31]=u,e[32]=i,e[33]=N):N=e[33];let C;e[34]!==N||e[35]!==b||e[36]!==S?(C=s.jsxs(Ss,{className:"max-w-md",children:[b,S,N]}),e[34]=N,e[35]=b,e[36]=S,e[37]=C):C=e[37];let j;return e[38]!==r||e[39]!==n||e[40]!==C?(j=s.jsx(ws,{open:n,onOpenChange:r,children:C}),e[38]=r,e[39]=n,e[40]=C,e[41]=j):j=e[41],j};function pS(t){return t.contextRailOrder}function gS(t){return t.contextRailHiddenSurfaces}function xS(t){return t.setContextRailSurfaceVisible}function bS(t){return t.setContextRailHiddenSurfaces}const fm=150,yS=500,wS=[],SS=t=>t>99?"99+":String(t),vS=t=>{const e=nt.c(51),{surface:n,isActive:r,showActivityDot:i,label:o,description:l,badgeCount:a,badgeAriaLabel:u,badgeDescription:d,orderNumber:h,showOrderNumber:f,onSelect:p}=t;let g;e[0]!==n.id?(g={id:n.id},e[0]=n.id,e[1]=g):g=e[1];const{attributes:w,listeners:v,setNodeRef:x,transform:m,transition:b,isDragging:y}=si(g);let S;e[2]!==a?(S=a!=null&&a>0?SS(a):null,e[2]=a,e[3]=S):S=e[3];const N=S;let C;e[4]!==m?(C=ni.Translate.toString(m),e[4]=m,e[5]=C):C=e[5];let j;e[6]!==C||e[7]!==b?(j={transform:C,transition:b},e[6]=C,e[7]=b,e[8]=j):j=e[8];const A=y&&"z-10 opacity-70";let D;e[9]!==A?(D=Ie("relative",A),e[9]=A,e[10]=D):D=e[10];let I;e[11]!==p||e[12]!==n?(I=()=>p(n),e[11]=p,e[12]=n,e[13]=I):I=e[13];const M=u??o,$=r?"text-primary":"text-muted-foreground hover:text-foreground";let E;e[14]!==$?(E=Ie("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",$),e[14]=$,e[15]=E):E=e[15];let K;e[16]!==n.icon||e[17]!==n.id?(K=n.id==="diff"?s.jsx(_u,{}):s.jsx(R,{name:n.icon,className:"h-[18px] w-[18px]"}),e[16]=n.icon,e[17]=n.id,e[18]=K):K=e[18];let B;e[19]!==N||e[20]!==h||e[21]!==i||e[22]!==f?(B=f&&h!=null?s.jsx("span",{"aria-hidden":"true",className:"absolute right-0 top-0 flex h-4 min-w-4 items-center justify-center rounded-full bg-surface-muted px-1 text-[0.625rem] font-medium leading-none text-muted-foreground",children:h===10?"0":h}):N?s.jsx("span",{"aria-hidden":"true",className:"absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[0.625rem] font-semibold leading-none",style:{backgroundColor:"var(--status-info-background)",color:"var(--status-info)"},children:N}):i?s.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-[var(--status-info)]"}):null,e[19]=N,e[20]=h,e[21]=i,e[22]=f,e[23]=B):B=e[23];let O;e[24]!==w||e[25]!==r||e[26]!==v||e[27]!==E||e[28]!==K||e[29]!==B||e[30]!==I||e[31]!==M?(O=s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",...w,...v,onClick:I,"aria-label":M,"aria-pressed":r,className:E,children:[K,B]})}),e[24]=w,e[25]=r,e[26]=v,e[27]=E,e[28]=K,e[29]=B,e[30]=I,e[31]=M,e[32]=O):O=e[32];let T;e[33]!==o?(T=s.jsx("span",{children:o}),e[33]=o,e[34]=T):T=e[34];let k;e[35]!==l?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:l}),e[35]=l,e[36]=k):k=e[36];let P;e[37]!==d?(P=d?s.jsx("span",{className:"typography-micro text-muted-foreground",children:d}):null,e[37]=d,e[38]=P):P=e[38];let F;e[39]!==T||e[40]!==k||e[41]!==P?(F=s.jsx(It,{side:"left",sideOffset:8,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[T,k,P]})}),e[39]=T,e[40]=k,e[41]=P,e[42]=F):F=e[42];let q;e[43]!==O||e[44]!==F?(q=s.jsxs(Dt,{delayDuration:fm,children:[O,F]}),e[43]=O,e[44]=F,e[45]=q):q=e[45];let Q;return e[46]!==x||e[47]!==q||e[48]!==j||e[49]!==D?(Q=s.jsx("div",{ref:x,style:j,className:D,children:q}),e[46]=x,e[47]=q,e[48]=j,e[49]=D,e[50]=Q):Q=e[50],Q},jS=()=>{const t=nt.c(86),{t:e}=Nt(),n=Sr();let r;t[0]!==n?(r=n?or(n):"",t[0]=n,t[1]=r):r=t[1];const i=r;let o;t[2]!==i?(o=Ce=>i?Ce.contextPanelByDirectory[i]:void 0,t[2]=i,t[3]=o):o=t[3];const l=Pe(o),a=Pe(kS),u=Pe(CS),d=Pe(NS),h=Pe(AS),f=Pe(DS),p=Pe(PS),g=Pe(IS),w=Ca(TS),v=Ei(ES),x=Ei(RS),m=Dn(MS),b=Dn(OS),{screenWidth:y}=Ln(),S=Na(i||null);let N;t[4]!==g?(N=Ri("switch_context_surface",g),t[4]=g,t[5]=N):N=t[5];const C=N,[j,A]=c.useState(!1);let D,I;t[6]!==C?(D=()=>{const Ce=new Set;let ve=null,re=!1;const le=BS,se=()=>{dl(C,Ce)?!re&&ve===null&&(ve=setTimeout(()=>A(!0),yS)):(re=!1,ve!==null&&(clearTimeout(ve),ve=null),A(!1))},G=W=>{if(Ce.add(W.key.toLowerCase()),le(W.key)&&dl(C,Ce)){re=!0,ve!==null&&(clearTimeout(ve),ve=null),A(!1);return}se()},U=W=>{Ce.delete(W.key.toLowerCase()),se()},be=()=>{Ce.clear(),re=!1,ve!==null&&(clearTimeout(ve),ve=null),A(!1)};return window.addEventListener("keydown",G,!0),window.addEventListener("keyup",U,!0),window.addEventListener("blur",be),()=>{window.removeEventListener("keydown",G,!0),window.removeEventListener("keyup",U,!0),window.removeEventListener("blur",be),ve!==null&&clearTimeout(ve)}},I=[C],t[6]=C,t[7]=D,t[8]=I):(D=t[7],I=t[8]),c.useEffect(D,I);let M;t[9]===Symbol.for("react.memo_cache_sentinel")?(M={activationConstraint:{distance:8}},t[9]=M):M=t[9];let $;t[10]===Symbol.for("react.memo_cache_sentinel")?($={activationConstraint:{delay:200,tolerance:6}},t[10]=$):$=t[10];const E=Ur(On(hu,M),On(fu,$)),K=l?.tabs??wS;let B;t[11]!==l?.activeTabId||t[12]!==K?(B=K.find(Ce=>Ce.id===l?.activeTabId)??null,t[11]=l?.activeTabId,t[12]=K,t[13]=B):B=t[13];const O=B,T=l?.isOpen?O?.mode??null:null,k=S?.files.length??0;let P;t[14]!==d||t[15]!==u||t[16]!==b||t[17]!==x||t[18]!==w||t[19]!==y||t[20]!==K?(P=ch({railOrder:u,hiddenSurfaces:d,planModeEnabled:w,isVSCode:Pn(),screenWidth:y,tabs:K,linearConnected:x,githubConnected:b}),t[14]=d,t[15]=u,t[16]=b,t[17]=x,t[18]=w,t[19]=y,t[20]=K,t[21]=P):P=t[21];const F=P;let q,Q;t[22]!==T||t[23]!==p||t[24]!==i||t[25]!==v||t[26]!==x?(Q=()=>{!i||!v||x||T!=="linear"||p(i)},q=[T,p,i,v,x],t[22]=T,t[23]=p,t[24]=i,t[25]=v,t[26]=x,t[27]=q,t[28]=Q):(q=t[27],Q=t[28]),c.useEffect(Q,q);let Y,ce;t[29]!==T||t[30]!==p||t[31]!==i||t[32]!==m||t[33]!==b?(Y=()=>{!i||!m||b||T!=="pr"||p(i)},ce=[T,p,i,m,b],t[29]=T,t[30]=p,t[31]=i,t[32]=m,t[33]=b,t[34]=Y,t[35]=ce):(Y=t[34],ce=t[35]),c.useEffect(Y,ce);const[X,oe]=c.useState(!1);let te;t[36]!==h?(te=Ce=>{const{active:ve,over:re}=Ce;if(!re||ve.id===re.id)return;const le=Fd(Pe.getState().contextRailOrder).map(FS),se=le.indexOf(ve.id),G=le.indexOf(re.id);se===-1||G===-1||h(pu(le,se,G))},t[36]=h,t[37]=te):te=t[37];const he=te;if(!i)return null;let _;t[38]!==e?(_=e("contextRail.aria.rail"),t[38]=e,t[39]=_):_=t[39];let ie;t[40]!==F?(ie=F.map(_S),t[40]=F,t[41]=ie):ie=t[41];let ge;if(t[42]!==T||t[43]!==k||t[44]!==i||t[45]!==f||t[46]!==j||t[47]!==F||t[48]!==e||t[49]!==a){let Ce;t[51]!==T||t[52]!==k||t[53]!==i||t[54]!==f||t[55]!==j||t[56]!==e||t[57]!==a?(Ce=(ve,re)=>{const le=e(ve.labelKey),se=ve.id==="git"&&!a?k:0,G=se>0?se:null;return s.jsx(vS,{surface:ve,isActive:T===ve.mode,showActivityDot:!1,label:le,description:e(ve.descriptionKey),badgeCount:G,badgeAriaLabel:G!==null?e(G===1?"contextRail.surface.git.changesCountAriaSingle":"contextRail.surface.git.changesCountAriaPlural",{label:le,count:G}):null,badgeDescription:G!==null?e(G===1?"contextRail.surface.git.changesCountTooltipSingle":"contextRail.surface.git.changesCountTooltipPlural",{count:G}):null,orderNumber:re+1,showOrderNumber:j,onSelect:U=>f(i,U.mode)},ve.id)},t[51]=T,t[52]=k,t[53]=i,t[54]=f,t[55]=j,t[56]=e,t[57]=a,t[58]=Ce):Ce=t[58],ge=F.map(Ce),t[42]=T,t[43]=k,t[44]=i,t[45]=f,t[46]=j,t[47]=F,t[48]=e,t[49]=a,t[50]=ge}else ge=t[50];let ae;t[59]!==ie||t[60]!==ge?(ae=s.jsx(Bo,{items:ie,strategy:Ki,children:ge}),t[59]=ie,t[60]=ge,t[61]=ae):ae=t[61];let z;t[62]!==he||t[63]!==E||t[64]!==ae?(z=s.jsx(Kr,{sensors:E,collisionDetection:Hr,onDragEnd:he,children:ae}),t[62]=he,t[63]=E,t[64]=ae,t[65]=z):z=t[65];let ne;t[66]!==e?(ne=e("contextRail.configure.open"),t[66]=e,t[67]=ne):ne=t[67];let ue;t[68]===Symbol.for("react.memo_cache_sentinel")?(ue=()=>oe(!0),t[68]=ue):ue=t[68];let me;t[69]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx(R,{name:"equalizer-2",className:"h-[18px] w-[18px]"}),t[69]=me):me=t[69];let ke;t[70]!==ne?(ke=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":ne,onClick:ue,className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground",children:me})}),t[70]=ne,t[71]=ke):ke=t[71];let Te;t[72]!==e?(Te=e("contextRail.configure.open"),t[72]=e,t[73]=Te):Te=t[73];let je;t[74]!==Te?(je=s.jsx(It,{side:"left",sideOffset:8,children:Te}),t[74]=Te,t[75]=je):je=t[75];let Ee;t[76]!==ke||t[77]!==je?(Ee=s.jsxs(Dt,{delayDuration:fm,children:[ke,je]}),t[76]=ke,t[77]=je,t[78]=Ee):Ee=t[78];let xe;t[79]!==X?(xe=s.jsx(hS,{open:X,onOpenChange:oe}),t[79]=X,t[80]=xe):xe=t[80];let H;return t[81]!==_||t[82]!==z||t[83]!==Ee||t[84]!==xe?(H=s.jsxs("nav",{"aria-label":_,className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:[z,Ee,xe]}),t[81]=_,t[82]=z,t[83]=Ee,t[84]=xe,t[85]=H):H=t[85],H};function kS(t){return t.workStatusPanelVisible}function CS(t){return t.contextRailOrder}function NS(t){return t.contextRailHiddenSurfaces}function AS(t){return t.setContextRailOrder}function DS(t){return t.openContextSurface}function PS(t){return t.closeContextPanel}function IS(t){return t.shortcutOverrides}function TS(t){return t.planModeEnabled}function ES(t){return t.hasChecked}function RS(t){return t.status?.connected===!0}function MS(t){return t.hasChecked}function OS(t){return t.status?.connected===!0}function BS(t){return t.length===1&&t>="0"&&t<="9"}function FS(t){return t.id}function _S(t){return t.id}const LS=(t,e)=>!t||e.length===0?"":JSON.stringify([t,e]),$S=(t,e,n,r)=>!n||r!==n||t.length===0?[]:Mr(t,e,i=>i.relativePath||i.name,{limit:10,threshold:.4}),WS=new Set,zS=[],aa=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const i=r==="/",o=/^[A-Za-z]:\/$/.test(r);return!i&&!o&&(r=r.replace(/\/+$/,"")),r},VS=()=>{const t=nt.c(182),{t:e}=Nt(),n=Pe(US),r=Pe(KS),i=Pe(HS),o=Pe(GS),l=Pe(qS),a=Pe(QS),u=Pe(YS),d=Pe(XS),h=Pe(JS),f=Pe(ZS),p=Pe(ev),g=Pe(tv),w=Pe(sv),v=et(nv),x=et(rv),m=et(ov),b=zr(iv);let y;t[0]!==n?(y=We=>n?We.activeSessions:zS,t[0]=n,t[1]=y):y=t[1];const S=Ps(y);let N;t[2]!==n?(N=We=>n?We.ids:WS,t[2]=n,t[3]=N):N=t[3];const C=zr(N);let j;t[4]!==n?(j=We=>n?We.rankById:Ld,t[4]=n,t[5]=j):j=t[5];const A=Ia(j),D=es(av),I=Vt(lv),M=Vt(cv),$=Sr(),E=gd(dv),{files:K,git:B}=wn(),O=Bn(uv),{isMobile:T}=Ln();let k;t[6]!==$?(k=$?aa($):null,t[6]=$,t[7]=k):k=t[7];const P=k,[F,q]=c.useState(""),Y=Pa(F,200).trim();let ce;t[8]!==F?(ce=F.trim(),t[8]=F,t[9]=ce):ce=t[9];const X=ce;let oe,te;t[10]!==n?(oe=()=>{n&&q("")},te=[n],t[10]=n,t[11]=oe,t[12]=te):(oe=t[11],te=t[12]),c.useEffect(oe,te);let he,_;t[13]!==S||t[14]!==O||t[15]!==B||t[16]!==n?(he=()=>{if(!n||!B)return;const We=setTimeout(()=>{const Xe=new Set;for(const Tt of S){const ut=$s(Tt);!ut||Xe.has(ut)||(Xe.add(ut),O(ut,B))}},0);return()=>clearTimeout(We)},_=[n,S,B,O],t[13]=S,t[14]=O,t[15]=B,t[16]=n,t[17]=he,t[18]=_):(he=t[17],_=t[18]),c.useEffect(he,_);let ie;t[19]!==r?(ie=()=>r(!1),t[19]=r,t[20]=ie):ie=t[20];const ge=ie;let ae;t[21]!==ge?(ae=We=>()=>{ge(),We()},t[21]=ge,t[22]=ae):ae=t[22];const z=ae;let ne;t[23]!==I?.id||t[24]!==I?.path||t[25]!==D||t[26]!==m||t[27]!==T||t[28]!==u||t[29]!==d||t[30]!==p||t[31]!==v||t[32]!==z||t[33]!==g||t[34]!==w||t[35]!==l||t[36]!==i||t[37]!==e||t[38]!==b||t[39]!==a?(ne=()=>{const We=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(R,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:z(()=>{l(!1),v()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(R,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:z(mv)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(R,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:z(fv)},{id:"toggle-sidebar",title:e(T?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(R,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(T?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:z(()=>{if(T){const{isSessionSwitcherOpen:Xe}=Pe.getState();l(!Xe)}else a()})},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(R,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:z(()=>{D&&d(D,"terminal")})},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(R,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:z(()=>{D&&u(D)})},{id:"cycle-theme",secondary:!0,title:e("commandPalette.item.cycleTheme"),icon:s.jsx(R,{name:"palette",className:"mr-2 h-4 w-4"}),shortcutId:"cycle_theme",searchText:e("commandPalette.item.cycleTheme"),onSelect:z(hv)},{id:"open-status",secondary:!0,title:e("commandPalette.item.showOpenCodeStatus"),icon:s.jsx(R,{name:"pulse",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showOpenCodeStatus"),onSelect:z(pv)},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(R,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:z(()=>i(!0))}];return We.push({id:"pin-session",secondary:!0,title:e("commandPalette.item.pinSession"),icon:s.jsx(R,{name:"pushpin",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.pinSession"),onSelect:z(()=>{m&&D&&b({directory:D,sessionId:m})})},{id:"copy-session-id",secondary:!0,title:e("commandPalette.item.copySessionId"),icon:s.jsx(R,{name:"file-copy",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.copySessionId"),onSelect:z(()=>{m&&pn(m).then(Xe=>{if(Xe.ok){Re.success(e("sessions.sidebar.session.copyId.success"));return}Re.error(e("sessions.sidebar.session.copyId.error"))}).catch(()=>Re.error(e("sessions.sidebar.session.copyId.error")))})},{id:"open-multi-run",secondary:!0,title:e("commandPalette.item.openMultiRun"),icon:s.jsx(R,{name:"checkbox-multiple",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openMultiRun"),onSelect:z(()=>{l(!1),p()})},{id:"open-archive",secondary:!0,title:e("commandPalette.item.openArchive"),icon:s.jsx(R,{name:"archive",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openArchive"),onSelect:z(()=>{l(!1),g(!0)})},{id:"open-notes",secondary:!0,title:e("commandPalette.item.openNotes"),icon:s.jsx(R,{name:"sticky-note",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openNotes"),onSelect:z(()=>{D&&(w("notes"),d(D,"notes"))})},{id:"open-todos",secondary:!0,title:e("commandPalette.item.openTodos"),icon:s.jsx(R,{name:"checkbox-circle",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openTodos"),onSelect:z(()=>{D&&(w("todos"),d(D,"notes"))})}),We.push({id:"toggle-memory-debug",secondary:!0,title:e("commandPalette.item.toggleMemoryDebug"),icon:s.jsx(R,{name:"bug",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.toggleMemoryDebug"),onSelect:z(gv)}),Qo()&&We.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(R,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:z(()=>{Mn("desktop_open_draft_mini_chat_window",{directory:aa(D||I?.path||""),projectId:I?.id??null}).catch(xv)})}),We},t[23]=I?.id,t[24]=I?.path,t[25]=D,t[26]=m,t[27]=T,t[28]=u,t[29]=d,t[30]=p,t[31]=v,t[32]=z,t[33]=g,t[34]=w,t[35]=l,t[36]=i,t[37]=e,t[38]=b,t[39]=a,t[40]=ne):ne=t[40],I?.id,I?.path;let ue;t[41]!==ne?(ue=ne(),t[41]=ne,t[42]=ue):ue=t[42];const me=ue;let ke;t[43]===Symbol.for("react.memo_cache_sentinel")?(ke=xn(),t[43]=ke):ke=t[43];const Te=ke;let je,Ee;t[44]===Symbol.for("react.memo_cache_sentinel")?(je=Pn(),Ee=!Te&&Sa(),t[44]=je,t[45]=Ee):(je=t[44],Ee=t[45]);let xe;t[46]!==T?(xe={isVSCode:je,isWeb:Ee,isDesktop:Te,isMobile:T},t[46]=T,t[47]=xe):xe=t[47];const H=xe;let Ce;if(t[48]!==z||t[49]!==i||t[50]!==o||t[51]!==H){let We;t[53]!==H?(We=Tt=>Tt.isAvailable?Tt.isAvailable(H):!0,t[53]=H,t[54]=We):We=t[54];let Xe;t[55]!==z||t[56]!==i||t[57]!==o?(Xe=Tt=>{const ut=fg(Tt.slug)??"settings-3",kt=(Tt.keywords??[]).join(" ");return{id:`settings:${Tt.slug}`,title:Tt.title,icon:Tt.slug==="mcp"?s.jsx(hh,{className:"mr-2 h-4 w-4"}):s.jsx(R,{name:ut,className:"mr-2 h-4 w-4"}),searchText:`${Tt.title} ${Tt.group} ${kt}`,onSelect:z(()=>{o(Tt.slug),i(!0)})}},t[55]=z,t[56]=i,t[57]=o,t[58]=Xe):Xe=t[58],Ce=mg.filter(bv).filter(We).map(Xe),t[48]=z,t[49]=i,t[50]=o,t[51]=H,t[52]=Ce}else Ce=t[52];const ve=Ce;let re;if(t[59]!==S||t[60]!==C||t[61]!==A){const We=S.filter(yv);re=dh(We,C,A),t[59]=S,t[60]=C,t[61]=A,t[62]=re}else re=t[62];const le=re,se=_d(),G=et(wv);let U;t[63]!==se||t[64]!==G?(U=(We,Xe)=>{const Tt=G.get(We);return Tt?.branch?Tt.branch.trim()||null:Xe&&se.get(Xe)?.trim()||null},t[63]=se,t[64]=G,t[65]=U):U=t[65];const be=U;let W;t[66]===Symbol.for("react.memo_cache_sentinel")?(W=[],t[66]=W):W=t[66];const[Ne,Oe]=c.useState(W),[ye,Fe]=c.useState(""),Ke=LS(P,Y);let $e;t[67]!==P||t[68]!==Ke||t[69]!==n||t[70]!==E||t[71]!==Oe||t[72]!==Fe||t[73]!==Y?($e=()=>{if(!n){Oe([]),Fe("");return}if(!Ke){Oe([]),Fe("");return}if(!P){Oe([]),Fe("");return}let We=!1;return E(P,Y,40,{type:"file"}).then(Xe=>{We||(Oe(Xe.map(Sv)),Fe(Ke))}).catch(()=>{We||(Oe([]),Fe(Ke))}),()=>{We=!0}},t[67]=P,t[68]=Ke,t[69]=n,t[70]=E,t[71]=Oe,t[72]=Fe,t[73]=Y,t[74]=$e):$e=t[74];let V;t[75]!==P||t[76]!==Ke||t[77]!==n||t[78]!==E||t[79]!==Y?(V=[n,P,Y,Ke,E],t[75]=P,t[76]=Ke,t[77]=n,t[78]=E,t[79]=Y,t[80]=V):V=t[80],c.useEffect($e,V);const fe=X.length>0;let Me;e:{if(!fe){let Xe;t[81]!==me?(Xe=me.filter(vv).map(jv),t[81]=me,t[82]=Xe):Xe=t[82],Me=Xe;break e}let We;t[83]!==me||t[84]!==X?(We=Mr(me,X,kv,{limit:7,noFuzzy:!0}),t[83]=me,t[84]=X,t[85]=We):We=t[85],Me=We}const De=Me;let at;e:{if(!fe){let Xe;t[86]===Symbol.for("react.memo_cache_sentinel")?(Xe=[],t[86]=Xe):Xe=t[86],at=Xe;break e}let We;t[87]!==X||t[88]!==ve?(We=Mr(ve,X,Cv,{limit:7,noFuzzy:!0}),t[87]=X,t[88]=ve,t[89]=We):We=t[89],at=We}const Qe=at;let lt;e:{if(!fe){let Xe;t[90]!==le?(Xe=le.slice(0,5).map(Nv),t[90]=le,t[91]=Xe):Xe=t[91],lt=Xe;break e}let We;t[92]!==X||t[93]!==le?(We=Mr(le,X,Av,{limit:7,threshold:.2}),t[92]=X,t[93]=le,t[94]=We):We=t[94],lt=We}const de=lt;let J;e:{if(!n){let Xe;t[95]===Symbol.for("react.memo_cache_sentinel")?(Xe=[],t[95]=Xe):Xe=t[95],J=Xe;break e}let We;t[96]!==Ne||t[97]!==ye||t[98]!==Ke||t[99]!==Y?(We=$S(Ne,Y,Ke,ye),t[96]=Ne,t[97]=ye,t[98]=Ke,t[99]=Y,t[100]=We):We=t[100],J=We}const Se=J,Ve=n&&Ke.length>0&&ye!==Ke;let He;e:{if(!fe){let Xe;t[101]===Symbol.for("react.memo_cache_sentinel")?(Xe=[],t[101]=Xe):Xe=t[101],He=Xe;break e}let We;if(t[102]!==X||t[103]!==M){const Xe=M.map(Dv);We=Mr(Xe,X,Pv,{limit:7,threshold:.4}),t[102]=X,t[103]=M,t[104]=We}else We=t[104];He=We}const it=He;let Ue,st,ee,ze,_e,pe,qe,tt,pt,gt,Je,St,Ze,vt;if(t[105]!==be||t[106]!==ge||t[107]!==P||t[108]!==K||t[109]!==fe||t[110]!==n||t[111]!==h||t[112]!==v||t[113]!==F||t[114]!==De||t[115]!==Se||t[116]!==it||t[117]!==de||t[118]!==Qe||t[119]!==r||t[120]!==x||t[121]!==f||t[122]!==e){const We=De.map(Iv),Xe=Qe.map(Tv),Tt=de.map(Ev),ut=fe?Se.map(Rv):[],kt=fe?it.map(Mv):[];let Rt;e:{if(!fe){Rt=["commands","sessions"];break e}const ht=Ov,mt=[{key:"commands",score:ht(De)},{key:"settings",score:ht(Qe)},{key:"sessions",score:ht(de)},{key:"files",score:ht(Se)},{key:"projects",score:ht(it)}];mt.sort(Bv),Rt=mt.map(Fv)}const ss=Rt,Ut=ht=>{ge(),x(ht.id,$s(ht))},Wt=async ht=>{if(!P)return;const mt=await Vu(K,ht,{directory:P});if(!mt.ok){Re.error(Uu(mt.reason));return}h(P,ht),ge()},Qt=(ht,mt)=>{ge(),v({selectedProjectId:ht,directoryOverride:mt})},Kt=ht=>Qn(Jr(ht,f));ze=ws,St=n,Ze=r;let Ft;t[137]!==e?(Ft=e("commandPalette.title"),t[137]=e,t[138]=Ft):Ft=t[138];let $t;t[139]!==Ft?($t=s.jsx(Is,{children:Ft}),t[139]=Ft,t[140]=$t):$t=t[140];let Be;t[141]!==e?(Be=e("commandPalette.description"),t[141]=e,t[142]=Be):Be=t[142];let Ye;t[143]!==Be?(Ye=s.jsx(Ts,{children:Be}),t[143]=Be,t[144]=Ye):Ye=t[144],t[145]!==$t||t[146]!==Ye?(vt=s.jsxs(Ws,{className:"sr-only",children:[$t,Ye]}),t[145]=$t,t[146]=Ye,t[147]=vt):vt=t[147],ee=Ss,gt="overflow-hidden p-0",Je=!0,st=ph,qe=!1,tt="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let ft;t[148]!==e?(ft=e("commandPalette.input.placeholder"),t[148]=e,t[149]=ft):ft=t[149],t[150]!==F||t[151]!==ft?(pt=s.jsx(gh,{value:F,onValueChange:q,placeholder:ft}),t[150]=F,t[151]=ft,t[152]=pt):pt=t[152],Ue=xh;let yt;t[153]!==e?(yt=e("commandPalette.empty.noResults"),t[153]=e,t[154]=yt):yt=t[154],t[155]!==yt?(_e=s.jsx(bh,{children:yt}),t[155]=yt,t[156]=_e):_e=t[156],pe=ss.map(ht=>ht==="commands"&&We.length>0?s.jsx(Cr,{children:We.map(mt=>s.jsxs(Or,{value:mt.id,onSelect:mt.onSelect,children:[mt.icon,s.jsx("span",{children:mt.title}),mt.shortcutId?s.jsx(uh,{children:Kt(mt.shortcutId)}):null]},mt.id))},"commands"):ht==="settings"&&Xe.length>0?s.jsx(Cr,{children:Xe.map(_v)},"settings"):ht==="sessions"&&Tt.length>0?s.jsx(Cr,{children:Tt.map(mt=>{const _t=mt.title||e("commandPalette.session.untitled"),Jt=$s(mt),Yt=be(mt.id,Jt);return s.jsxs(Or,{value:`session:${mt.id}`,onSelect:()=>Ut(mt),children:[s.jsx(R,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:_t}),Yt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(R,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:Yt})]}):null]},mt.id)})},"sessions"):ht==="files"&&ut.length>0?s.jsx(Cr,{children:ut.map(mt=>{const _t=mh(mt.relativePath||mt.name,{maxLength:80});return s.jsxs(Or,{value:`file:${mt.path}`,onSelect:()=>{Wt(mt.path)},children:[s.jsx(Da,{filePath:mt.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":mt.relativePath,children:_t})]},`file:${mt.path}`)})},"files"):ht==="projects"&&kt.length>0?s.jsx(Cr,{children:kt.map(mt=>{const _t=mt.displayName;return s.jsxs(Or,{value:`project:${mt.id}`,onSelect:()=>Qt(mt.id,mt.path),children:[s.jsx(R,{name:"folder",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:_t}),s.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:mt.path})]},`project:${mt.id}`)})},"projects"):null),t[105]=be,t[106]=ge,t[107]=P,t[108]=K,t[109]=fe,t[110]=n,t[111]=h,t[112]=v,t[113]=F,t[114]=De,t[115]=Se,t[116]=it,t[117]=de,t[118]=Qe,t[119]=r,t[120]=x,t[121]=f,t[122]=e,t[123]=Ue,t[124]=st,t[125]=ee,t[126]=ze,t[127]=_e,t[128]=pe,t[129]=qe,t[130]=tt,t[131]=pt,t[132]=gt,t[133]=Je,t[134]=St,t[135]=Ze,t[136]=vt}else Ue=t[123],st=t[124],ee=t[125],ze=t[126],_e=t[127],pe=t[128],qe=t[129],tt=t[130],pt=t[131],gt=t[132],Je=t[133],St=t[134],Ze=t[135],vt=t[136];let rt;t[157]!==Ve||t[158]!==e?(rt=Ve?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[157]=Ve,t[158]=e,t[159]=rt):rt=t[159];let we;t[160]!==Ue||t[161]!==_e||t[162]!==pe||t[163]!==rt?(we=s.jsxs(Ue,{children:[_e,pe,rt]}),t[160]=Ue,t[161]=_e,t[162]=pe,t[163]=rt,t[164]=we):we=t[164];let ct;t[165]!==st||t[166]!==qe||t[167]!==tt||t[168]!==pt||t[169]!==we?(ct=s.jsxs(st,{shouldFilter:qe,className:tt,children:[pt,we]}),t[165]=st,t[166]=qe,t[167]=tt,t[168]=pt,t[169]=we,t[170]=ct):ct=t[170];let dt;t[171]!==ee||t[172]!==gt||t[173]!==Je||t[174]!==ct?(dt=s.jsx(ee,{className:gt,showCloseButton:Je,children:ct}),t[171]=ee,t[172]=gt,t[173]=Je,t[174]=ct,t[175]=dt):dt=t[175];let At;return t[176]!==ze||t[177]!==St||t[178]!==Ze||t[179]!==vt||t[180]!==dt?(At=s.jsxs(ze,{open:St,onOpenChange:Ze,children:[vt,dt]}),t[176]=ze,t[177]=St,t[178]=Ze,t[179]=vt,t[180]=dt,t[181]=At):At=t[181],At};function US(t){return t.isCommandPaletteOpen}function KS(t){return t.setCommandPaletteOpen}function HS(t){return t.setSettingsDialogOpen}function GS(t){return t.setSettingsPage}function qS(t){return t.setSessionSwitcherOpen}function QS(t){return t.toggleSidebar}function YS(t){return t.openContextOverview}function XS(t){return t.openContextSurface}function JS(t){return t.openContextFile}function ZS(t){return t.shortcutOverrides}function ev(t){return t.openMultiRunLauncher}function tv(t){return t.setArchivePageOpen}function sv(t){return t.setProjectContextTab}function nv(t){return t.openNewSessionDraft}function rv(t){return t.setCurrentSession}function ov(t){return t.currentSessionId}function iv(t){return t.toggle}function av(t){return t.currentDirectory}function lv(t){return t.getActiveProject()}function cv(t){return t.projects}function dv(t){return t.searchFiles}function uv(t){return t.ensureStatus}function mv(){$d()}function fv(){gn.requestDirectoryDialog()}function hv(){yh.invoke("cycle_theme")}function pv(){Wd()}function gv(){window.dispatchEvent(new CustomEvent("openchamber:memory-debug-toggle"))}function xv(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function bv(t){return t.slug!=="home"}function yv(t){return!fh(t)}function wv(t){return t.worktreeMetadata}function Sv(t){return{path:aa(t.path),name:t.name,relativePath:t.relativePath}}function vv(t){return!t.secondary}function jv(t){return{item:t,score:0}}function kv(t){return t.searchText}function Cv(t){return t.searchText}function Nv(t){return{item:t,score:0}}function Av(t){return t.title||""}function Dv(t){return{...t,displayName:t.label||t.path.split("/").pop()||t.path,searchText:`${t.label||""} ${t.path}`}}function Pv(t){return t.searchText}function Iv(t){return t.item}function Tv(t){return t.item}function Ev(t){return t.item}function Rv(t){return t.item}function Mv(t){return t.item}function Ov(t){return t.length?t[0].score:1/0}function Bv(t,e){return t.score-e.score}function Fv(t){return t.key}function _v(t){return s.jsxs(Or,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const gc=(t,e,n)=>Qn(Jr(t,e),n),Lv=()=>{const t=nt.c(68),{t:e}=Nt(),n=Pe($v),r=Pe(Wv),i=Pe(zv);let o;t[0]===Symbol.for("react.memo_cache_sentinel")?(o=Pn(),t[0]=o):o=t[0];const l=o;let a,u,d,h,f,p,g,w,v;if(t[1]!==n||t[2]!==r||t[3]!==i||t[4]!==e){const B=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"add_selection_to_chat",descriptionKey:"helpDialog.item.addSelectionToChat",icon:"add",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[Qn("mod+shift+alt+n")],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"open_draft_project_picker",icon:"folder",keys:""},{id:"open_draft_worktree_picker",icon:"git-branch",keys:""},{id:"open_session_list",icon:"list-unordered",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"toggle_prompt_navigator",descriptionKey:"helpDialog.item.togglePromptNavigator",icon:"list-unordered",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{keys:[`${Qn(Ri("switch_context_surface",i))} + 1...0`],descriptionKey:"helpDialog.item.switchContextSurface",icon:"layout-right"},{keys:[`${Qn(Ri("switch_session_tab",i))} + 1...9`],descriptionKey:"helpDialog.item.switchSessionTab",icon:"layout-right"}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];u=ws,w=n,v=r,a=Ss,p="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let O;t[14]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(R,{name:"command",className:"h-5 w-5"}),t[14]=O):O=t[14];let T;t[15]!==e?(T=e("helpDialog.title"),t[15]=e,t[16]=T):T=t[16];let k;t[17]!==T?(k=s.jsxs(Is,{className:"flex items-center gap-2",children:[O,T]}),t[17]=T,t[18]=k):k=t[18];let P;t[19]!==e?(P=e("helpDialog.description"),t[19]=e,t[20]=P):P=t[20];let F;t[21]!==P?(F=s.jsx(Ts,{children:P}),t[21]=P,t[22]=F):F=t[22],t[23]!==k||t[24]!==F?(g=s.jsxs(Ws,{children:[k,F]}),t[23]=k,t[24]=F,t[25]=g):g=t[25],f="flex-1 overflow-y-auto mt-3 pr-1",d="space-y-4",h=B.map(q=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(q.categoryKey)}),s.jsx("div",{className:"space-y-1",children:q.items.filter(Q=>!(l&&Q.id==="toggle_prompt_navigator")).map(Q=>{const Y=Q.id?wh(Q.id):void 0,ce=Q.descriptionKey??(Y?.customizable?Y.settingsLabelKey:void 0);if(!ce||Q.id&&!Jr(Q.id,i))return null;const X=Q.id?gc(Q.id,i,e("settings.openchamber.keyboardShortcuts.unassigned")):Array.isArray(Q.keys)?Q.keys:Q.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[Q.icon&&s.jsx(R,{name:Q.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(ce)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(X)?X:[X]).map((oe,te)=>s.jsxs(c.Fragment,{children:[te>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:oe})]},`${oe}-${te}`))})]},Q.id||ce)})})]},q.categoryKey)),t[1]=n,t[2]=r,t[3]=i,t[4]=e,t[5]=a,t[6]=u,t[7]=d,t[8]=h,t[9]=f,t[10]=p,t[11]=g,t[12]=w,t[13]=v}else a=t[5],u=t[6],d=t[7],h=t[8],f=t[9],p=t[10],g=t[11],w=t[12],v=t[13];let x;t[26]!==d||t[27]!==h?(x=s.jsx("div",{className:d,children:h}),t[26]=d,t[27]=h,t[28]=x):x=t[28];let m;t[29]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(R,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=m):m=t[29];let b;t[30]!==e?(b=e("helpDialog.proTips.title"),t[30]=e,t[31]=b):b=t[31];let y;t[32]!==b?(y=s.jsx("p",{className:"font-medium mb-1",children:b}),t[32]=b,t[33]=y):y=t[33];let S;t[34]!==i||t[35]!==e?(S=e("helpDialog.proTips.commandPalette",{shortcut:gc("open_command_palette",i,e("settings.openchamber.keyboardShortcuts.unassigned"))}),t[34]=i,t[35]=e,t[36]=S):S=t[36];let N;t[37]!==S?(N=s.jsxs("li",{children:["• ",S]}),t[37]=S,t[38]=N):N=t[38];let C;t[39]!==e?(C=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=C):C=t[40];let j;t[41]!==C?(j=s.jsxs("li",{children:["• ",C]}),t[41]=C,t[42]=j):j=t[42];let A;t[43]!==e?(A=e("helpDialog.proTips.leaderSequences"),t[43]=e,t[44]=A):A=t[44];let D;t[45]!==A?(D=s.jsxs("li",{children:["• ",A]}),t[45]=A,t[46]=D):D=t[46];let I;t[47]!==N||t[48]!==j||t[49]!==D?(I=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[N,j,D]}),t[47]=N,t[48]=j,t[49]=D,t[50]=I):I=t[50];let M;t[51]!==y||t[52]!==I?(M=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[m,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[y,I]})]})}),t[51]=y,t[52]=I,t[53]=M):M=t[53];let $;t[54]!==M||t[55]!==f||t[56]!==x?($=s.jsxs("div",{className:f,children:[x,M]}),t[54]=M,t[55]=f,t[56]=x,t[57]=$):$=t[57];let E;t[58]!==a||t[59]!==$||t[60]!==p||t[61]!==g?(E=s.jsxs(a,{className:p,children:[g,$]}),t[58]=a,t[59]=$,t[60]=p,t[61]=g,t[62]=E):E=t[62];let K;return t[63]!==u||t[64]!==E||t[65]!==w||t[66]!==v?(K=s.jsx(u,{open:w,onOpenChange:v,children:E}),t[63]=u,t[64]=E,t[65]=w,t[66]=v,t[67]=K):K=t[67],K};function $v(t){return t.isHelpDialogOpen}function Wv(t){return t.setHelpDialogOpen}function zv(t){return t.shortcutOverrides}const Vv=()=>{const t=nt.c(32),{t:e}=Nt(),n=Pe(Uv),r=Pe(Kv),i=Pe(Hv);let o;t[0]!==i||t[1]!==e?(o=async()=>{if(!i)return;if((await pn(i)).ok){Re.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}Re.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=i,t[1]=e,t[2]=o):o=t[2];const l=o;let a;t[3]!==e?(a=e("openCodeStatusDialog.title"),t[3]=e,t[4]=a):a=t[4];let u;t[5]!==a?(u=s.jsx(Is,{children:a}),t[5]=a,t[6]=u):u=t[6];let d;t[7]!==e?(d=e("openCodeStatusDialog.description"),t[7]=e,t[8]=d):d=t[8];let h;t[9]!==d?(h=s.jsx(Ts,{children:d}),t[9]=d,t[10]=h):h=t[10];let f;t[11]!==u||t[12]!==h?(f=s.jsxs(Ws,{children:[u,h]}),t[11]=u,t[12]=h,t[13]=f):f=t[13];let p;t[14]!==e?(p=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=p):p=t[15];let g;t[16]!==l||t[17]!==p?(g=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:l,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:p})}),t[16]=l,t[17]=p,t[18]=g):g=t[18];let w;t[19]!==i||t[20]!==e?(w=i||e("openCodeStatusDialog.empty.noData"),t[19]=i,t[20]=e,t[21]=w):w=t[21];let v;t[22]!==w?(v=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:w}),t[22]=w,t[23]=v):v=t[23];let x;t[24]!==f||t[25]!==g||t[26]!==v?(x=s.jsxs(Ss,{className:"max-w-2xl",children:[f,g,v]}),t[24]=f,t[25]=g,t[26]=v,t[27]=x):x=t[27];let m;return t[28]!==n||t[29]!==r||t[30]!==x?(m=s.jsx(ws,{open:n,onOpenChange:r,children:x}),t[28]=n,t[29]=r,t[30]=x,t[31]=m):m=t[31],m};function Uv(t){return t.isOpenCodeStatusDialogOpen}function Kv(t){return t.setOpenCodeStatusDialogOpen}function Hv(t){return t.openCodeStatusText}const Gv=t=>{const e=nt.c(16),{enabled:n,isSessionSearchOpen:r,setIsSessionSearchOpen:i,sessionSearchInputRef:o,sessionSearchContainerRef:l}=t,a=n===void 0?!0:n;let u,d;e[0]!==a||e[1]!==r||e[2]!==o?(u=()=>{if(!a||!r||typeof window>"u")return;const w=window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.select()});return()=>window.cancelAnimationFrame(w)},d=[a,r,o],e[0]=a,e[1]=r,e[2]=o,e[3]=u,e[4]=d):(u=e[3],d=e[4]),c.useEffect(u,d);let h,f;e[5]!==a||e[6]!==o||e[7]!==i?(h=()=>{if(!a||typeof window>"u")return;const w=()=>{i(!0),o.current?.focus(),o.current?.select()};return window.addEventListener("openchamber:sidebar-session-search",w),()=>window.removeEventListener("openchamber:sidebar-session-search",w)},f=[a,i,o],e[5]=a,e[6]=o,e[7]=i,e[8]=h,e[9]=f):(h=e[8],f=e[9]),c.useEffect(h,f);let p,g;e[10]!==a||e[11]!==r||e[12]!==l||e[13]!==i?(p=()=>{if(!a||!r||typeof document>"u")return;const w=v=>{l.current&&(l.current.contains(v.target)||i(!1))};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},g=[a,r,i,l],e[10]=a,e[11]=r,e[12]=l,e[13]=i,e[14]=p,e[15]=g):(p=e[14],g=e[15]),c.useEffect(p,g)},qv=t=>{const e=nt.c(4);let n;e[0]!==t?(n=(o,l)=>{const a=t.get(o);if(!a||a.length===0)return l;const u=new Map(l.map(Qv)),d=[];a.forEach(p=>{const g=u.get(p);g&&(d.push(g),u.delete(p))});const h=[],f=[];return l.forEach(p=>{u.has(p.id)&&(p.isArchivedBucket?f.push(p):h.push(p))}),[...h,...d,...f]},e[0]=t,e[1]=n):n=e[1];const r=n;let i;return e[2]!==r?(i={getOrderedGroups:r},e[2]=r,e[3]=i):i=e[3],i};function Qv(t){return[t.id,t]}const mo="oc.sessions.projectCollapse",xc="oc.sessions.groupOrder",bc="oc.sessions.groupCollapse",yc=t=>{if(!t)return new Set;try{const e=La(wr()).safeParse(JSON.parse(t));return new Set(e.success?e.data:[])}catch{return new Set}},Yv=t=>{if(!t)return new Map;try{const e=vu(wr(),La(wr())).safeParse(JSON.parse(t));if(!e.success)return new Map;const n=new Map;for(const[r,i]of Object.entries(e.data))n.set(r,i);return n}catch{return new Map}},Xv=t=>{const e=nt.c(39),{isVSCode:n,projects:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=Eo(),e[0]=i):i=e[0];const o=i;let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=()=>yc(o.getItem(mo)),e[1]=l):l=e[1];const[a,u]=c.useState(l);let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=()=>yc(o.getItem(bc)),e[2]=d):d=e[2];const[h,f]=c.useState(d);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=()=>Yv(o.getItem(xc)),e[3]=p):p=e[3];const[g,w]=c.useState(p),v=c.useRef(0),x=c.useRef(!1),m=c.useRef(!1),b=c.useRef(null),y=c.useRef(null);let S;e[4]!==n?(S=()=>{if(n)return;const ie=y.current;if(y.current=null,b.current=null,!ie)return;const{projects:ge}=Vt.getState(),ae=ge.map(z=>({...z,sidebarCollapsed:ie.has(z.id)}));Rr({projects:ae}).catch(Jv)},e[4]=n,e[5]=S):S=e[5];const N=S;let C;e[6]!==N||e[7]!==n?(C=ie=>{!globalThis.window||n||(y.current=ie,b.current!==null&&window.clearTimeout(b.current),b.current=window.setTimeout(()=>{N()},700))},e[6]=N,e[7]=n,e[8]=C):C=e[8];const j=C;let A,D;e[9]===Symbol.for("react.memo_cache_sentinel")?(A=()=>()=>{globalThis.window&&b.current!==null&&window.clearTimeout(b.current),b.current=null,y.current=null},D=[],e[9]=A,e[10]=D):(A=e[9],D=e[10]),c.useEffect(A,D);let I,M;e[11]!==g?(M=()=>{if(m.current)try{o.setItem(xc,JSON.stringify(Object.fromEntries(g.entries())))}catch{}},I=[g,o],e[11]=g,e[12]=I,e[13]=M):(I=e[12],M=e[13]),c.useEffect(M,I);let $,E;e[14]!==h?($=()=>{if(x.current)try{o.setItem(bc,JSON.stringify(Array.from(h)))}catch{}},E=[h,o],e[14]=h,e[15]=$,e[16]=E):($=e[15],E=e[16]),c.useEffect($,E);let K;e[17]!==r||e[18]!==j?(K=()=>{v.current=Date.now()+150,x.current=!0,f(new Set),u(()=>{const ie=new Set(r.map(Zv));try{o.setItem(mo,JSON.stringify(Array.from(ie)))}catch{}return j(ie),ie})},e[17]=r,e[18]=j,e[19]=K):K=e[19];const B=K;let O;e[20]!==j?(O=()=>{v.current=Date.now()+150,x.current=!0,f(new Set),u(()=>{const ie=new Set;try{o.setItem(mo,JSON.stringify([]))}catch{}return j(ie),ie})},e[20]=j,e[21]=O):O=e[21];const T=O;let k;e[22]!==j?(k=ie=>{v.current=Date.now()+150,u(ge=>{const ae=new Set(ge);ae.has(ie)?ae.delete(ie):ae.add(ie);try{o.setItem(mo,JSON.stringify(Array.from(ae)))}catch{}return j(ae),ae})},e[22]=j,e[23]=k):k=e[23];const P=k;let F;e[24]===Symbol.for("react.memo_cache_sentinel")?(F=ie=>{x.current=!0,f(ge=>{const ae=new Set(ge);return ae.has(ie)?ae.delete(ie):ae.add(ie),ae})},e[24]=F):F=e[24];const q=F;let Q;e[25]===Symbol.for("react.memo_cache_sentinel")?(Q=ie=>{m.current=!0,w(ie)},e[25]=Q):Q=e[25];const Y=Q,{getOrderedGroups:ce}=qv(g);let X;e[26]!==h||e[27]!==a||e[28]!==g?(X={collapsedProjects:a,collapsedGroups:h,groupOrderByProject:g},e[26]=h,e[27]=a,e[28]=g,e[29]=X):X=e[29];const oe=X;let te;e[30]!==B||e[31]!==T||e[32]!==ce||e[33]!==j||e[34]!==P?(te={setCollapsedProjects:u,toggleProject:P,collapseAllProjects:B,expandAllProjects:T,scheduleCollapsedProjectsPersist:j,setCollapsedGroups:f,toggleGroup:q,setGroupOrderByProject:Y,getOrderedGroups:ce},e[30]=B,e[31]=T,e[32]=ce,e[33]=j,e[34]=P,e[35]=te):te=e[35];const he=te;let _;return e[36]!==he||e[37]!==oe?(_={state:oe,actions:he},e[36]=he,e[37]=oe,e[38]=_):_=e[38],_};function Jv(){}function Zv(t){return t.id}const e0=5*6e4,t0=t=>{const e=nt.c(31),{normalizedProjects:n,enabled:r,gitRepoStatus:i,setProjectRepoStatus:o,setProjectRootBranches:l}=t,a=r===void 0?!0:r,{git:u}=wn(),d=Bn(s0);let h,f;e[0]!==a||e[1]!==d||e[2]!==u||e[3]!==n||e[4]!==o?(h=()=>{if(!a||!u||n.length===0){o(new Map);return}n.forEach(C=>{Mi(()=>d(C.normalizedPath,u))})},f=[a,n,u,d,o],e[0]=a,e[1]=d,e[2]=u,e[3]=n,e[4]=o,e[5]=h,e[6]=f):(h=e[5],f=e[6]),c.useEffect(h,f);let p,g;e[7]!==a||e[8]!==i||e[9]!==n||e[10]!==o?(p=()=>{if(!a)return;const C=new Map;n.forEach(j=>{C.set(j.id,i.get(j.normalizedPath)?.isGitRepo??null)}),o(C)},g=[a,n,i,o],e[7]=a,e[8]=i,e[9]=n,e[10]=o,e[11]=p,e[12]=g):(p=e[11],g=e[12]),c.useEffect(p,g);let w;if(e[13]!==i||e[14]!==n){let C;e[16]!==i?(C=j=>{const A=i.get(j.normalizedPath)?.branch??"";return`${j.id}:${A}`},e[16]=i,e[17]=C):C=e[17],w=n.map(C).join("|"),e[13]=i,e[14]=n,e[15]=w}else w=e[15];const v=w;let x;e[18]===Symbol.for("react.memo_cache_sentinel")?(x=new Map,e[18]=x):x=e[18];const m=c.useRef(x);let b;e[19]===Symbol.for("react.memo_cache_sentinel")?(b=new Map,e[19]=b):b=e[19];const y=c.useRef(b);let S;e[20]!==a||e[21]!==i||e[22]!==n||e[23]!==l?(S=()=>{if(!a)return;let C=!1;const j=setTimeout(()=>{(async()=>{const D=new Set(n.map(n0));for(const B of m.current.keys())D.has(B)||(m.current.delete(B),y.current.delete(B));const I=Date.now(),M=n.filter(B=>{const O=i.get(B.normalizedPath);if(O?.isGitRepo===!1)return m.current.delete(B.id),y.current.delete(B.id),!1;if(O?.isGitRepo!==!0||O.branch===null)return!1;const T=O.branch.trim(),k=`${B.normalizedPath}\0${T}`,P=m.current.get(B.id);if(P===k){const F=y.current.get(B.id);return F&&(F.at=I),!1}return!(P!==void 0&&I-(y.current.get(B.id)?.at??0)<e0)});if(M.length===0)return;const $=await Sh(M,2,async B=>{const O=i.get(B.normalizedPath)?.branch?.trim()??"",T=`${B.normalizedPath}\0${O}`,k=await Mi(()=>ti(B.normalizedPath,O?{knownBranch:O}:void 0)).catch(r0);return{id:B.id,inputKey:T,branch:k}});if(C)return;const E=$.filter(o0);if(E.length===0)return;const K=Date.now();l(B=>{const O=new Map(B);return E.forEach(T=>{const{id:k,branch:P}=T;P&&O.set(k,P)}),O}),E.forEach(B=>{const{id:O,inputKey:T,branch:k}=B;m.current.set(O,T),k&&y.current.set(O,{branch:k,at:K})})})()},150);return()=>{C=!0,clearTimeout(j)}},e[20]=a,e[21]=i,e[22]=n,e[23]=l,e[24]=S):S=e[24];let N;e[25]!==a||e[26]!==i||e[27]!==n||e[28]!==v||e[29]!==l?(N=[a,n,v,i,l],e[25]=a,e[26]=i,e[27]=n,e[28]=v,e[29]=l,e[30]=N):N=e[30],c.useEffect(S,N)};function s0(t){return t.ensureStatus}function n0(t){return t.id}function r0(){return null}function o0(t){return t.branch}const i0=t=>{const e=nt.c(10),{open:n,onOpenChange:r,project:i,onSave:o}=t;let l;e[0]!==o||e[1]!==n||e[2]!==i?(l=n&&i?s.jsx(hg,{project:i,onIdentitySave:o,showWorktrees:!1}):null,e[0]=o,e[1]=n,e[2]=i,e[3]=l):l=e[3];let a;e[4]!==l?(a=s.jsx(Ss,{className:"w-full max-w-2xl gap-0 overflow-hidden p-0",children:s.jsx(Nn,{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:l})})}),e[4]=l,e[5]=a):a=e[5];let u;return e[6]!==r||e[7]!==n||e[8]!==a?(u=s.jsx(ws,{open:n,onOpenChange:r,children:a}),e[6]=r,e[7]=n,e[8]=a,e[9]=u):u=e[9],u},a0=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const i of t){r.has(i)||(r.add(i),n.push(i));const o=e.get(i);if(o)for(const l of o)r.has(l)||(r.add(l),n.push(l))}return n},hs=tr()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,i)=>{const o=e(),l=new Set(o.selectedIds);let a=o.scopeKey,u=o.anchorId;r!==null&&o.scopeKey!==null&&r!==o.scopeKey?(l.clear(),a=r,u=null):a===null&&r!==null&&(a=r);const h=i&&i.length>0?[n,...i]:[n];if(l.has(n)){for(const p of h)l.delete(p);u===n&&(u=null)}else{for(const p of h)l.add(p);u=n}l.size===0?t({selectedIds:l,scopeKey:null,anchorId:null}):t({selectedIds:l,scopeKey:a,anchorId:u})},setRange:(n,r,i,o,l)=>{const a=e();if(i.length===0)return;const u=n&&i.includes(n)?n:i[0],d=i.indexOf(u),h=i.indexOf(r);if(d<0||h<0)return;const[f,p]=d<=h?[d,h]:[h,d],g=i.slice(f,p+1),w=a0(g,l),x=o!==null&&a.scopeKey!==null&&o!==a.scopeKey?new Set:new Set(a.selectedIds);for(const m of w)x.add(m);t({selectedIds:x,scopeKey:o??a.scopeKey,anchorId:u})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const i=new Set(r.selectedIds);for(const o of n)i.delete(o);i.size!==r.selectedIds.size&&(i.size===0?t({selectedIds:i,scopeKey:null,anchorId:null}):t({selectedIds:i}))}}));function l0(t){const e=nt.c(213),{t:n}=Nt(),{hideDirectoryControls:r,showProjectDisplayControls:i,showRecentControls:o,handleOpenDirectoryDialog:l,onOpenScheduled:a,onOpenMultiRun:u,canOpenMultiRun:d,onOpenArchive:h,headerActionIconClass:f,headerActionButtonClass:p,isSessionSearchOpen:g,setIsSessionSearchOpen:w,sessionSearchInputRef:v,sessionSearchQuery:x,setSessionSearchQuery:m,hasSessionSearchQuery:b,searchMatchCount:y,collapseAllProjects:S,expandAllProjects:N}=t,C=hs(S0),j=hs(w0),A=ls(y0),D=ls(b0),I=ls(x0),M=ls(g0),$=ls(p0),E=ls(h0),K=ls(f0),B=ls(m0),O=ls(u0),T=ls(d0),k=i&&O==="single";if(r)return null;let P;e[0]!==p?(P=Ie(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[0]=p,e[1]=P):P=e[1];let F;e[2]!==n?(F=n("sessions.sidebar.header.actions.addProject"),e[2]=n,e[3]=F):F=e[3];let q;e[4]!==f?(q=s.jsx(R,{name:"folder-add",className:f}),e[4]=f,e[5]=q):q=e[5];let Q;e[6]!==l||e[7]!==P||e[8]!==F||e[9]!==q?(Q=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,className:P,"aria-label":F,children:q})}),e[6]=l,e[7]=P,e[8]=F,e[9]=q,e[10]=Q):Q=e[10];let Y;e[11]!==n?(Y=n("sessions.sidebar.header.actions.addProject"),e[11]=n,e[12]=Y):Y=e[12];let ce;e[13]!==Y?(ce=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Y})}),e[13]=Y,e[14]=ce):ce=e[14];let X;e[15]!==Q||e[16]!==ce?(X=s.jsxs(Dt,{children:[Q,ce]}),e[15]=Q,e[16]=ce,e[17]=X):X=e[17];let oe;e[18]!==p?(oe=Ie(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[18]=p,e[19]=oe):oe=e[19];let te;e[20]!==n?(te=n("sessions.sidebar.header.actions.scheduledTasks"),e[20]=n,e[21]=te):te=e[21];let he;e[22]!==f?(he=s.jsx(R,{name:"calendar-schedule",className:f}),e[22]=f,e[23]=he):he=e[23];let _;e[24]!==a||e[25]!==oe||e[26]!==te||e[27]!==he?(_=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:oe,"aria-label":te,children:he})}),e[24]=a,e[25]=oe,e[26]=te,e[27]=he,e[28]=_):_=e[28];let ie;e[29]!==n?(ie=n("sessions.sidebar.header.actions.scheduledTasks"),e[29]=n,e[30]=ie):ie=e[30];let ge;e[31]!==ie?(ge=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ie})}),e[31]=ie,e[32]=ge):ge=e[32];let ae;e[33]!==_||e[34]!==ge?(ae=s.jsxs(Dt,{children:[_,ge]}),e[33]=_,e[34]=ge,e[35]=ae):ae=e[35];let z;e[36]!==p?(z=Ie(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[36]=p,e[37]=z):z=e[37];let ne;e[38]!==n?(ne=n("sessions.sidebar.header.actions.newMultiRun"),e[38]=n,e[39]=ne):ne=e[39];const ue=!d;let me;e[40]!==f?(me=s.jsx(vh,{className:f}),e[40]=f,e[41]=me):me=e[41];let ke;e[42]!==u||e[43]!==z||e[44]!==ne||e[45]!==ue||e[46]!==me?(ke=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:z,"aria-label":ne,disabled:ue,children:me})}),e[42]=u,e[43]=z,e[44]=ne,e[45]=ue,e[46]=me,e[47]=ke):ke=e[47];let Te;e[48]!==n?(Te=n("sessions.sidebar.header.actions.newMultiRun"),e[48]=n,e[49]=Te):Te=e[49];let je;e[50]!==Te?(je=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Te})}),e[50]=Te,e[51]=je):je=e[51];let Ee;e[52]!==ke||e[53]!==je?(Ee=s.jsxs(Dt,{children:[ke,je]}),e[52]=ke,e[53]=je,e[54]=Ee):Ee=e[54];let xe;e[55]!==p?(xe=Ie(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[55]=p,e[56]=xe):xe=e[56];let H;e[57]!==n?(H=n("sessions.sidebar.nav.archive"),e[57]=n,e[58]=H):H=e[58];let Ce;e[59]!==f?(Ce=s.jsx(R,{name:"archive",className:f}),e[59]=f,e[60]=Ce):Ce=e[60];let ve;e[61]!==h||e[62]!==xe||e[63]!==H||e[64]!==Ce?(ve=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:h,className:xe,"aria-label":H,children:Ce})}),e[61]=h,e[62]=xe,e[63]=H,e[64]=Ce,e[65]=ve):ve=e[65];let re;e[66]!==n?(re=n("sessions.sidebar.nav.archive"),e[66]=n,e[67]=re):re=e[67];let le;e[68]!==re?(le=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:re})}),e[68]=re,e[69]=le):le=e[69];let se;e[70]!==ve||e[71]!==le?(se=s.jsxs(Dt,{children:[ve,le]}),e[70]=ve,e[71]=le,e[72]=se):se=e[72];let G;e[73]!==ae||e[74]!==Ee||e[75]!==se||e[76]!==X?(G=s.jsxs("div",{className:"ml-[3px] flex items-center gap-1.5",children:[X,ae,Ee,se]}),e[73]=ae,e[74]=Ee,e[75]=se,e[76]=X,e[77]=G):G=e[77];let U;e[78]!==w?(U=()=>w(c0),e[78]=w,e[79]=U):U=e[79];let be;e[80]!==p?(be=Ie(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[80]=p,e[81]=be):be=e[81];let W;e[82]!==n?(W=n("sessions.sidebar.header.actions.searchSessions"),e[82]=n,e[83]=W):W=e[83];let Ne;e[84]!==f?(Ne=s.jsx(R,{name:"search",className:f}),e[84]=f,e[85]=Ne):Ne=e[85];let Oe;e[86]!==g||e[87]!==U||e[88]!==be||e[89]!==W||e[90]!==Ne?(Oe=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:U,className:be,"aria-label":W,"aria-expanded":g,children:Ne})}),e[86]=g,e[87]=U,e[88]=be,e[89]=W,e[90]=Ne,e[91]=Oe):Oe=e[91];let ye;e[92]!==n?(ye=n("sessions.sidebar.header.actions.searchSessions"),e[92]=n,e[93]=ye):ye=e[93];let Fe;e[94]!==ye?(Fe=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ye})}),e[94]=ye,e[95]=Fe):Fe=e[95];let Ke;e[96]!==Oe||e[97]!==Fe?(Ke=s.jsxs(Dt,{children:[Oe,Fe]}),e[96]=Oe,e[97]=Fe,e[98]=Ke):Ke=e[98];const $e=C&&"bg-interactive-hover text-primary";let V;e[99]!==p||e[100]!==$e?(V=Ie(p,"text-muted-foreground hover:text-foreground hover:bg-transparent",$e),e[99]=p,e[100]=$e,e[101]=V):V=e[101];let fe;e[102]!==C||e[103]!==n?(fe=n(C?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[102]=C,e[103]=n,e[104]=fe):fe=e[104];let Me;e[105]!==f?(Me=s.jsx(R,{name:"checkbox-multiple",className:f}),e[105]=f,e[106]=Me):Me=e[106];let De;e[107]!==C||e[108]!==V||e[109]!==fe||e[110]!==Me||e[111]!==j?(De=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:V,"aria-label":fe,"aria-pressed":C,children:Me})}),e[107]=C,e[108]=V,e[109]=fe,e[110]=Me,e[111]=j,e[112]=De):De=e[112];let at;e[113]!==C||e[114]!==n?(at=n(C?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[113]=C,e[114]=n,e[115]=at):at=e[115];let Qe;e[116]!==at?(Qe=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:at})}),e[116]=at,e[117]=Qe):Qe=e[117];let lt;e[118]!==De||e[119]!==Qe?(lt=s.jsxs(Dt,{children:[De,Qe]}),e[118]=De,e[119]=Qe,e[120]=lt):lt=e[120];let de;e[121]!==p?(de=Ie(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[121]=p,e[122]=de):de=e[122];let J;e[123]!==n?(J=n("sessions.sidebar.header.displayMode.label"),e[123]=n,e[124]=J):J=e[124];let Se;e[125]!==f?(Se=s.jsx(R,{name:"equalizer-2",className:f}),e[125]=f,e[126]=Se):Se=e[126];let Ve;e[127]!==de||e[128]!==J||e[129]!==Se?(Ve=s.jsx(Pt,{asChild:!0,children:s.jsx(Qs,{asChild:!0,children:s.jsx("button",{type:"button",className:de,"aria-label":J,children:Se})})}),e[127]=de,e[128]=J,e[129]=Se,e[130]=Ve):Ve=e[130];let He;e[131]!==n?(He=n("sessions.sidebar.header.displayMode.label"),e[131]=n,e[132]=He):He=e[132];let it;e[133]!==He?(it=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:He})}),e[133]=He,e[134]=it):it=e[134];let Ue;e[135]!==Ve||e[136]!==it?(Ue=s.jsxs(Dt,{children:[Ve,it]}),e[135]=Ve,e[136]=it,e[137]=Ue):Ue=e[137];let st;e[138]!==n?(st=n("sessions.sidebar.header.actions.sortProjects"),e[138]=n,e[139]=st):st=e[139];let ee;e[140]!==st?(ee=s.jsx(yo,{children:st}),e[140]=st,e[141]=ee):ee=e[141];let ze;e[142]!==I||e[143]!==M||e[144]!==n?(ze=[["manual","sessions.sidebar.header.projectSort.manual"],["a-z","sessions.sidebar.header.projectSort.aToZ"],["z-a","sessions.sidebar.header.projectSort.zToA"],["date-added","sessions.sidebar.header.projectSort.dateAdded"],["recent","sessions.sidebar.header.projectSort.recent"]].map(ut=>{const[kt,Rt]=ut;return s.jsxs(zt,{onClick:()=>{M(kt),Rr({sidebarProjectSortOrder:kt})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Rt)}),I===kt?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]},kt)}),e[142]=I,e[143]=M,e[144]=n,e[145]=ze):ze=e[145];let _e;e[146]===Symbol.for("react.memo_cache_sentinel")?(_e=s.jsx(Os,{}),e[146]=_e):_e=e[146];let pe;e[147]!==O||e[148]!==T||e[149]!==i||e[150]!==n?(pe=i?s.jsxs(s.Fragment,{children:[s.jsx(yo,{children:n("sessions.sidebar.header.projectDisplay.label")}),[["all","sessions.sidebar.header.projectDisplay.all"],["single","sessions.sidebar.header.projectDisplay.single"]].map(ut=>{const[kt,Rt]=ut;return s.jsxs(zt,{onClick:()=>{T(kt),Rr({sidebarProjectDisplayMode:kt})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Rt)}),O===kt?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]},kt)}),s.jsx(Os,{})]}):null,e[147]=O,e[148]=T,e[149]=i,e[150]=n,e[151]=pe):pe=e[151];let qe;e[152]!==n?(qe=n("sessions.sidebar.header.grouping.label"),e[152]=n,e[153]=qe):qe=e[153];let tt;e[154]!==qe?(tt=s.jsx(yo,{children:qe}),e[154]=qe,e[155]=tt):tt=e[155];let pt;e[156]!==$||e[157]!==E||e[158]!==n?(pt=[["by-worktree","sessions.sidebar.header.grouping.byWorktree"],["flat","sessions.sidebar.header.grouping.flat"]].map(ut=>{const[kt,Rt]=ut;return s.jsxs(zt,{onClick:()=>{E(kt),Rr({sidebarSessionGroupingMode:kt})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Rt)}),$===kt?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]},kt)}),e[156]=$,e[157]=E,e[158]=n,e[159]=pt):pt=e[159];let gt;e[160]===Symbol.for("react.memo_cache_sentinel")?(gt=s.jsx(Os,{}),e[160]=gt):gt=e[160];let Je;e[161]!==k||e[162]!==o||e[163]!==A||e[164]!==n||e[165]!==D?(Je=o&&!k?s.jsxs(zt,{onClick:()=>{D(),Rr({sidebarShowRecentSection:!A})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),A?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]}):null,e[161]=k,e[162]=o,e[163]=A,e[164]=n,e[165]=D,e[166]=Je):Je=e[166];let St;e[167]!==n?(St=n("sessions.sidebar.header.displayMode.stickyHeaders"),e[167]=n,e[168]=St):St=e[168];let Ze;e[169]!==St?(Ze=s.jsx("span",{children:St}),e[169]=St,e[170]=Ze):Ze=e[170];let vt;e[171]!==K?(vt=K?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null,e[171]=K,e[172]=vt):vt=e[172];let rt;e[173]!==Ze||e[174]!==vt||e[175]!==B?(rt=s.jsxs(zt,{onClick:B,className:"flex items-center justify-between",children:[Ze,vt]}),e[173]=Ze,e[174]=vt,e[175]=B,e[176]=rt):rt=e[176];let we;e[177]!==S||e[178]!==N||e[179]!==k||e[180]!==n?(we=k?null:s.jsxs(s.Fragment,{children:[s.jsx(Os,{}),s.jsxs(zt,{onClick:S,className:"flex items-center gap-2",children:[s.jsx(R,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs(zt,{onClick:N,className:"flex items-center gap-2",children:[s.jsx(R,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]}),e[177]=S,e[178]=N,e[179]=k,e[180]=n,e[181]=we):we=e[181];let ct;e[182]!==ee||e[183]!==ze||e[184]!==pe||e[185]!==tt||e[186]!==pt||e[187]!==Je||e[188]!==rt||e[189]!==we?(ct=s.jsxs(Ys,{align:"end",className:"min-w-[180px]",children:[ee,ze,_e,pe,tt,pt,gt,Je,rt,we]}),e[182]=ee,e[183]=ze,e[184]=pe,e[185]=tt,e[186]=pt,e[187]=Je,e[188]=rt,e[189]=we,e[190]=ct):ct=e[190];let dt;e[191]!==Ue||e[192]!==ct?(dt=s.jsxs(Xs,{children:[Ue,ct]}),e[191]=Ue,e[192]=ct,e[193]=dt):dt=e[193];let At;e[194]!==Ke||e[195]!==lt||e[196]!==dt?(At=s.jsxs("div",{className:"flex items-center gap-1.5",children:[Ke,lt,dt]}),e[194]=Ke,e[195]=lt,e[196]=dt,e[197]=At):At=e[197];let We;e[198]!==G||e[199]!==At?(We=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[G,At]}),e[198]=G,e[199]=At,e[200]=We):We=e[200];let Xe;e[201]!==b||e[202]!==g||e[203]!==y||e[204]!==v||e[205]!==x||e[206]!==w||e[207]!==m||e[208]!==n?(Xe=g?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[b?s.jsx("span",{children:y===1?n("sessions.sidebar.header.search.matchCountSingle",{count:y}):n("sessions.sidebar.header.search.matchCountPlural",{count:y})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(R,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:v,value:x,onChange:ut=>m(ut.target.value),placeholder:n("sessions.sidebar.header.search.placeholder"),className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:ut=>{ut.key==="Escape"&&(ut.stopPropagation(),b?m(""):w(!1))}}),x.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":n("sessions.sidebar.header.search.clear"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[201]=b,e[202]=g,e[203]=y,e[204]=v,e[205]=x,e[206]=w,e[207]=m,e[208]=n,e[209]=Xe):Xe=e[209];let Tt;return e[210]!==We||e[211]!==Xe?(Tt=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[We,Xe]})}),e[210]=We,e[211]=Xe,e[212]=Tt):Tt=e[212],Tt}function c0(t){return!t}function d0(t){return t.setProjectDisplayMode}function u0(t){return t.projectDisplayMode}function m0(t){return t.toggleStickyZoneHeaders}function f0(t){return t.stickyZoneHeaders}function h0(t){return t.setSessionGroupingMode}function p0(t){return t.sessionGroupingMode}function g0(t){return t.setProjectSortOrder}function x0(t){return t.projectSortOrder}function b0(t){return t.toggleRecentSection}function y0(t){return t.showRecentSection}function w0(t){return t.toggleMode}function S0(t){return t.enabled}function v0(t){const e=nt.c(8),{t:n}=Nt(),r=t.onNewSession;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(R,{name:"chat-new",className:"h-4 w-4 flex-shrink-0"}),e[0]=i):i=e[0];let o;e[1]!==n?(o=n("sessions.sidebar.header.actions.newSession"),e[1]=n,e[2]=o):o=e[2];let l;e[3]!==o?(l=s.jsx("span",{className:"truncate",children:o}),e[3]=o,e[4]=l):l=e[4];let a;return e[5]!==t.onNewSession||e[6]!==l?(a=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 pt-1.5",children:s.jsxs("button",{type:"button",onClick:r,className:"flex w-full min-w-0 items-center gap-2 rounded-md px-1.5 py-1 text-left typography-ui-label font-normal text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[i,l]})}),e[5]=t.onNewSession,e[6]=l,e[7]=a):a=e[7],a}const Si="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 j0(t){const e=nt.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:i,onOpenUpdate:o,showRuntimeButtons:l,showUpdateButton:a}=t,u=l===void 0?!0:l,d=a===void 0?!0:a,{t:h}=Nt();if(!u&&!d)return null;let f;e[0]!==i||e[1]!==n||e[2]!==r||e[3]!==u||e[4]!==h?(f=u?s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:Si,"aria-label":h("sessions.sidebar.footer.actions.settings"),children:s.jsx(R,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:Si,"aria-label":h("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(R,{name:"command",className:"h-4.5 w-4.5"})})}),s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:Si,"aria-label":h("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(R,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=i,e[1]=n,e[2]=r,e[3]=u,e[4]=h,e[5]=f):f=e[5];let p;e[6]!==o||e[7]!==d||e[8]!==h?(p=d?s.jsx(bt,{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:o,children:h("sessions.sidebar.footer.actions.update")}):null,e[6]=o,e[7]=d,e[8]=h,e[9]=p):p=e[9];let g;return e[10]!==f||e[11]!==p?(g=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[f,p]}),e[10]=f,e[11]=p,e[12]=g):g=e[12],g}const k0=t=>{for(const e of t.sessions.values())if(e.tabs.some(bd))return!0;return!1},C0=()=>{const t=nt.c(4),{terminal:e}=wn(),n=Et(k0);let r,i;return t[0]!==n||t[1]!==e?(r=()=>{const o=N0,l=A0;if(n)return Li(e,"",l,o);let a=D0;return a=Li(e,"",l,u=>{o(u),a()}),()=>a()},i=[e,n],t[0]=n,t[1]=e,t[2]=r,t[3]=i):(r=t[2],i=t[3]),c.useEffect(r,i),null};function N0(t){const e=Et.getState(),n=pg(t.sessions),r=new Set([...e.sessions.keys(),...n.keys()]);for(const i of r)e.reconcileServerSessions(i,n.get(i)??[],{startedActionMutationRevisions:t.startedActionMutationRevisions})}function A0(){return new Map(Et.getState().actionMutationRevisions)}function D0(){}const P0=t=>{const e=nt.c(12),{normalizedProjects:n,enabled:r,ownership:i,isSessionsLoading:o,hasAuthoritativeGlobalSessions:l,isWorktreeTopologyLoading:a,unresolvedWorktreeProjectPaths:u,foldersMap:d,createFolder:h,addSessionToFolder:f}=t,p=r===void 0?!0:r;let g,w;e[0]!==f||e[1]!==h||e[2]!==p||e[3]!==d||e[4]!==l||e[5]!==o||e[6]!==a||e[7]!==n||e[8]!==i||e[9]!==u?(g=()=>{!p||o||!l||a||n.forEach(v=>{if(u.has(v.normalizedPath))return;const x=zd(v.normalizedPath),m=i.archivedSessionsByProject.get(v.id)??[],b=d[x]??[],y=new Map(b.map(I0));m.forEach(S=>{const N=jh(S,v.normalizedPath),C=N.toLowerCase();let j=y.get(C);j||(j=h(x,N),y.set(C,j)),j.sessionIds.includes(S.id)||f(x,j.id,S.id)})})},w=[n,p,i,o,l,a,u,d,h,f],e[0]=f,e[1]=h,e[2]=p,e[3]=d,e[4]=l,e[5]=o,e[6]=a,e[7]=n,e[8]=i,e[9]=u,e[10]=g,e[11]=w):(g=e[10],w=e[11]),c.useEffect(g,w)};function I0(t){return[t.name.toLowerCase(),t]}function T0({activeProjectId:t,currentSessionId:e,currentSessionOwnerProjectId:n,projectMap:r,metaByProject:i,rememberedSessionId:o,fallbackSessionId:l}){if(e&&n===t)return{kind:"preserve-current"};if(n==null){const d=!!(e&&Array.from(i.entries()).some(([h,f])=>h!==t&&f.has(e)));if(e&&r&&!d)return{kind:"preserve-current"}}if(!r||r.size===0)return{kind:"open-draft"};const u=(o&&r.has(o)?o:null)??l;return!u||u===e?{kind:"none"}:{kind:"select-session",sessionId:u}}const E0=t=>{const e=nt.c(26),{projectSections:n,activeProjectId:r,activeSessionByProject:i,setActiveSessionByProject:o,currentSessionId:l,currentSessionOwnerProjectId:a,handleSessionSelect:u,newSessionDraftOpen:d,mobileVariant:h,openNewSessionDraft:f,setSessionSwitcherOpen:p}=t;let g,w;if(e[0]!==n){w=new Map,g=new Map;const C=(j,A,D,I)=>{w.has(j)||w.set(j,new Map);const M=w.get(j);I.forEach($=>{const E=wt($.worktree?.path??$.session.directory??D??A);M.set($.session.id,{directory:E}),g.has(j)||g.set(j,{id:$.session.id,directory:E}),$.children.length>0&&C(j,A,E,$.children)})};n.forEach(j=>{j.groups.forEach(A=>{C(j.project.id,j.project.normalizedPath,A.directory,A.sessions)})}),e[0]=n,e[1]=g,e[2]=w}else g=e[1],w=e[2];let v;e[3]!==g||e[4]!==w?(v={metaByProject:w,firstSessionByProject:g},e[3]=g,e[4]=w,e[5]=v):v=e[5];const x=v,m=c.useRef(null);let b,y;e[6]!==r||e[7]!==i||e[8]!==l||e[9]!==a||e[10]!==u||e[11]!==h||e[12]!==d||e[13]!==f||e[14]!==n||e[15]!==x||e[16]!==o||e[17]!==p?(b=()=>{if(!r||d||Pe.getState().isNewWorktreeDialogOpen||m.current===r)return;const C=n.find(I=>I.project.id===r);if(!C)return;const j=x.metaByProject.get(r);if(l&&j&&j.has(l)){m.current=r,o(I=>{if(I.get(r)===l)return I;const M=new Map(I);return M.set(r,l),M});return}const A=T0({activeProjectId:r,currentSessionId:l,currentSessionOwnerProjectId:a,projectMap:j,metaByProject:x.metaByProject,rememberedSessionId:i.get(r),fallbackSessionId:x.firstSessionByProject.get(r)?.id??null});if(A.kind==="preserve-current"){a===r&&(m.current=r);return}if(m.current=r,A.kind==="open-draft"){h&&p(!1),f({selectedProjectId:C.project.id,directoryOverride:C.project.normalizedPath});return}if(A.kind!=="select-session")return;const D=j?.get(A.sessionId)?.directory??null;u(A.sessionId,D)},y=[r,i,l,a,u,d,h,f,n,x,p,o],e[6]=r,e[7]=i,e[8]=l,e[9]=a,e[10]=u,e[11]=h,e[12]=d,e[13]=f,e[14]=n,e[15]=x,e[16]=o,e[17]=p,e[18]=b,e[19]=y):(b=e[18],y=e[19]),c.useLayoutEffect(b,y);let S,N;e[20]!==r||e[21]!==l||e[22]!==x||e[23]!==o?(S=()=>{if(!r||!l)return;const C=x.metaByProject.get(r);!C||!C.has(l)||o(j=>{if(j.get(r)===l)return j;const A=new Map(j);return A.set(r,l),A})},N=[r,l,x,o],e[20]=r,e[21]=l,e[22]=x,e[23]=o,e[24]=S,e[25]=N):(S=e[24],N=e[25]),c.useEffect(S,N)},R0=t=>{const e=nt.c(20);let n,r,i,o;e[0]!==t?({initialActiveSessionByProject:r,persistActiveSessionByProject:i,sessionOwnerBySessionId:o,...n}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=o):(n=e[1],r=e[2],i=e[3],o=e[4]);const l=et(M0),a=et(O0);let u;e[5]!==l||e[6]!==o?(u=l?o?.get(l)?.projectId??null:null,e[5]=l,e[6]=o,e[7]=u):u=e[7];const d=u;let h;e[8]!==r?(h=()=>new Map(r),e[8]=r,e[9]=h):h=e[9];const[f,p]=c.useState(h);let g;e[10]!==f||e[11]!==n||e[12]!==l||e[13]!==d||e[14]!==a?(g={...n,activeSessionByProject:f,setActiveSessionByProject:p,currentSessionId:l,currentSessionOwnerProjectId:d,newSessionDraftOpen:a},e[10]=f,e[11]=n,e[12]=l,e[13]=d,e[14]=a,e[15]=g):g=e[15],E0(g);let w,v;return e[16]!==f||e[17]!==i?(w=()=>{i(f)},v=[f,i],e[16]=f,e[17]=i,e[18]=w,e[19]=v):(w=e[18],v=e[19]),c.useEffect(w,v),null};function M0(t){return t.currentSessionId}function O0(t){return!!t.newSessionDraft?.open}const wc={selected:0,"active-project":1,expanded:2,visible:3,background:4};function hm(t){const e=new Map,n=(r,i,o)=>{const l=wt(r??null);if(!l)return;const a=e.get(l);a&&wc[a.priority]<=wc[i]||e.set(l,{directory:l,priority:i,reason:o})};for(const r of t.knownDirectories??[])n(r,"background","known-project");n(t.activeProjectDirectory,"active-project","project-expanded");for(const r of t.projectSections??[]){const i=!t.collapsedProjects.has(r.project.id);let o="background";r.project.id===t.activeProjectId?o="active-project":i&&(o="expanded"),n(r.project.normalizedPath,o,i?"project-expanded":"known-project");for(const l of r.groups){if(!l.directory||l.isArchivedBucket||l.isMain)continue;const a=i&&!t.collapsedGroups.has(`${r.project.id}:${l.id}`);let u="background";a?u="expanded":i&&(u="visible"),n(l.directory,u,a?"worktree-expanded":"known-worktree")}}return n(t.currentDirectory,"selected","current-directory"),n(t.currentSessionDirectory,"selected","selected-session"),[...e.values()]}const B0=(t,e)=>t?e.kind!==t.kind?e.kind==="project":e.projectRoot.length!==t.projectRoot.length?e.projectRoot.length>t.projectRoot.length:e.projectId.localeCompare(t.projectId)<0:!0,Sc=(t,e,n)=>{B0(t.get(e),n)&&t.set(e,n)},F0=t=>{const e=t;return wt(e.directory)??wt(e.project?.worktree)},_0=t=>{if(t==="/"||/^[A-Z]:$/.test(t))return null;const e=t.lastIndexOf("/");return e<0?null:e===0?"/":e===2&&/^[A-Z]:\//.test(t)?t.slice(0,2):t.slice(0,e)},L0=(t,e,n,r,i=[])=>{const o=new Map,l=new Map;for(const w of e){const v=wt(w.normalizedPath);if(!v)continue;const x=l.get(v);(!x||w.id.localeCompare(x.id)<0)&&l.set(v,w),Sc(o,v,{projectId:w.id,projectRoot:v,scopeDirectory:v,kind:"project"})}if(!r)for(const[w,v]of n){const x=wt(w),m=x?l.get(x):void 0;if(!(!m||!x))for(const b of v){const y=wt(b.path);y&&Sc(o,y,{projectId:m.id,projectRoot:x,scopeDirectory:y,kind:"worktree"})}}const a=new Map,u=new Map,d=new Map,h=new Map,f=new Map,p=w=>{if(!w)return null;if(a.has(w))return a.get(w)??null;if(r){const b=o.get(w)??null;return a.set(w,b),b}const v=[];let x=w,m=null;for(;x;){if(a.has(x)){m=a.get(x)??null;break}if(v.push(x),m=o.get(x)??null,m)break;x=_0(x)}for(const b of v)a.set(b,m);return m},g=(w,v,x)=>{for(const m of w){const b=p(F0(m));if(!b)continue;u.set(m.id,b);const y=v.get(b.projectId);if(y?y.push(m):v.set(b.projectId,[m]),!x)continue;const S=x.get(b.scopeDirectory);S?S.add(m.id):x.set(b.scopeDirectory,new Set([m.id]))}};return g(t,d,f),g(i,h),{bySessionId:u,sessionsByProject:d,archivedSessionsByProject:h,sessionsByScope:f,directoryResolutions:a.size}},$0=t=>{const e=nt.c(7),{ownership:n}=t;let r;e[0]!==n?(r=u=>n.sessionsByProject.get(u)??[],e[0]=n,e[1]=r):r=e[1];const i=r;let o;e[2]!==n?(o=u=>n.archivedSessionsByProject.get(u)??[],e[2]=n,e[3]=o):o=e[3];const l=o;let a;return e[4]!==l||e[5]!==i?(a={getSessionsForProject:i,getArchivedSessionsForProject:l},e[4]=l,e[5]=i,e[6]=a):a=e[6],a},W0=(t,e)=>t.map(n=>{const r=wt(n.path)??n.path;return`${r}=${e.get(r)??""}`}).join(`
|
|
913
|
+
`),z0=[],V0=t=>{const{normalizedProjects:e,getSessionsForProject:n,getArchivedSessionsForProject:r,availableWorktreesByProject:i,projectRepoStatus:o,projectRootBranches:l,gitBranches:a,lastRepoStatus:u,buildGroupedSessions:d,hasSessionSearchQuery:h,normalizedSessionSearchQuery:f,filterSessionNodesForSearch:p,buildGroupSearchText:g,foldersMap:w,standaloneGroups:v}=t,x=c.useRef(new Map),m=c.useMemo(()=>{const D=x.current,I=new Map;let M=0,$=0;const E=(B,O)=>B.length===O.length&&B.every((T,k)=>T===O[k]),K=e.map(B=>{const O=n(B.id),T=r(B.id),k=i.get(B.normalizedPath)??z0,P=o.has(B.id)?!!o.get(B.id):u,F=l.get(B.id)??null,q=W0(k,a),Q=D.get(B.id);if(Q&&Q.project===B&&E(Q.activeSessions,O)&&E(Q.archivedSessions,T)&&Q.availableWorktrees===k&&Q.rootBranch===F&&Q.worktreeBranchesKey===q&&Q.isRepo===P&&Q.buildGroupedSessions===d)return M+=1,I.set(B.id,Q),Q.section;if($+=1,Q){const oe=Q.project!==B?"project":E(Q.activeSessions,O)?E(Q.archivedSessions,T)?Q.availableWorktrees!==k?"worktrees":Q.rootBranch!==F?"branch":Q.worktreeBranchesKey!==q?"worktreeBranches":Q.isRepo!==P?"repo":"builder":"archived":"sessions";Gs(`ui.sidebar.project_section.rebuilt_reason.${oe}`)}const Y=Vd([...O,...T]),ce=d(Y,B.normalizedPath,k,F,P),X={project:B,groups:ce};return I.set(B.id,{project:B,activeSessions:O,archivedSessions:T,availableWorktrees:k,rootBranch:F,worktreeBranchesKey:q,isRepo:P,buildGroupedSessions:d,section:X}),X});return x.current=I,M>0&&Gs("ui.sidebar.project_section.reused",M),$>0&&Gs("ui.sidebar.project_section.rebuilt",$),K},[e,n,r,i,o,u,d,l,a]),b=c.useMemo(()=>m,[m]),y=c.useMemo(()=>{const D=new WeakMap;if(!h)return D;const I=$=>$.reduce((E,K)=>E+1+I(K.children),0),M=$=>{const E=p($.sessions,f),K=I(E),B=Ro([g($)],f),O=wt($.directory??null),k=(O?w[O]??[]:[]).filter(P=>Ro([P.name],f)).length;D.set($,{filteredNodes:E,matchedSessionCount:K,folderNameMatchCount:k,groupMatches:B,hasMatch:B||K>0||k>0})};return b.forEach($=>{$.groups.forEach(M)}),v.forEach(M),D},[h,b,v,p,f,g,w]),S=c.useMemo(()=>h?b.map(D=>({...D,groups:D.groups.filter(I=>y.get(I)?.hasMatch===!0)})).filter(D=>D.groups.length>0):b,[h,b,y]),N=h?S:b,C=c.useRef(new WeakMap),j=c.useMemo(()=>{const D=C.current;return N.map(I=>{const M=D.get(I);if(M&&M.query===f)return M.section;const $=I.groups.filter(P=>!P.isArchivedBucket),E=I.groups.filter(P=>P.isArchivedBucket),K=$.flatMap(P=>h?y.get(P)?.filteredNodes??[]:P.sessions),B=$.map(P=>({scopeKey:P.folderScopeKey??wt(P.directory??null),directory:P.directory??null})).filter(P=>!!P.scopeKey),O=$.find(P=>P.isMain)??null,T={id:"flat",label:O?.label??"",branch:O?.branch??null,description:O?.description??null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:O?.directory??I.project.normalizedPath,folderScopeKey:O?.folderScopeKey??I.project.normalizedPath,folderScopes:B,sessions:K};if(h){const P=$.map(F=>y.get(F)).filter(F=>!!F);y.set(T,{filteredNodes:K,matchedSessionCount:P.reduce((F,q)=>F+q.matchedSessionCount,0),folderNameMatchCount:P.reduce((F,q)=>F+q.folderNameMatchCount,0),groupMatches:P.some(F=>F.groupMatches),hasMatch:P.some(F=>F.hasMatch)})}const k={project:I.project,groups:[T,...E]};return D.set(I,{query:f,section:k}),k})},[y,h,f,N]),A=c.useMemo(()=>{if(!h)return 0;const D=(M,$)=>{const E=y.get($);if(!E)return M;const K=E.folderNameMatchCount+(E.groupMatches?1:0);return M+E.matchedSessionCount+K},I=N.reduce((M,$)=>$.groups.reduce(D,M),0);return v.reduce(D,I)},[h,N,v,y]);return{projectSections:m,visibleProjectSections:b,groupSearchDataByGroup:y,searchableProjectSections:S,sectionsForRender:N,flatSectionsForRender:j,searchMatchCount:A}},U0=180,vc=150,K0=2,H0=8,jc=[-1,1,-2,2],vi=t=>`${t.directory}
|
|
914
|
+
${t.sessionId}`,G0=t=>t?.directory?.trim()||null,q0=({enabled:t=!0,currentSessionId:e,sortedSessions:n,recentSessions:r=[],prefetchSession:i})=>{const o=c.useRef(new Map),l=c.useRef([]),a=c.useRef(new Set),u=c.useRef(0),d=c.useMemo(()=>Pn(),[]),h=c.useCallback(()=>{u.current+=1,l.current=[],o.current.forEach(g=>window.clearTimeout(g)),o.current.clear()},[]),f=c.useCallback(()=>{if(!(!t||d))for(;a.current.size<K0&&l.current.length>0;){const g=l.current.shift();if(!g)break;if(g.generation!==u.current||et.getState().currentSessionId===g.sessionId||Oi(g.sessionId,g.directory).renderable)continue;const v=vi(g);a.current.add(v),i({directory:g.directory,sessionID:g.sessionId}).catch(()=>{}).finally(()=>{a.current.delete(v),f()})}},[t,d,i]),p=c.useCallback(g=>{const w=g?.id,v=G0(g);if(!t||d||!w||!v||w===e)return;const x={sessionId:w,directory:v,generation:u.current},m=vi(x);if(Oi(w,v).renderable||a.current.has(m)||l.current.some(S=>vi(S)===m))return;const b=o.current.get(m);b!==void 0&&window.clearTimeout(b);const y=window.setTimeout(()=>{if(o.current.delete(m),x.generation!==u.current)return;const S=l.current;S.length>=H0&&S.shift(),S.push(x),f()},U0);o.current.set(m,y)},[e,t,d,f]);c.useEffect(()=>{h()},[h,e,t,d]),c.useEffect(()=>{if(!t||d||!e||n.length===0)return;const g=window.setTimeout(()=>{const w=n.findIndex(v=>v.id===e);if(!(w<0))for(const v of jc)p(n[w+v])},vc);return()=>window.clearTimeout(g)},[e,t,d,p,n]),c.useEffect(()=>{if(!t||d||!e||r.length===0)return;const g=window.setTimeout(()=>{const w=r.findIndex(v=>v.id===e);if(!(w<0))for(const v of jc)p(r[w+v])},vc);return()=>window.clearTimeout(g)},[e,t,d,r,p]),c.useEffect(()=>h,[h])},Q0=t=>{const e=nt.c(3),n=et(Y0);let r;return e[0]!==t||e[1]!==n?(r={...t,currentSessionId:n},e[0]=t,e[1]=n,e[2]=r):r=e[2],q0(r),null};function Y0(t){return t.currentSessionId}const Qr=t=>{const e=nt.c(13),{directory:n,className:r}=t,{t:i}=Nt();let o;e[0]!==n?(o=hf(n),e[0]=n,e[1]=o):o=e[1];const l=o;let a;if(e[2]!==l?(a=v=>v.sessions.get(l),e[2]=l,e[3]=a):a=e[3],!Et(a)?.tabs.some(bd))return null;let h;e[4]!==i?(h=i("sessions.sidebar.projectAction.active"),e[4]=i,e[5]=h):h=e[5];const f=h;let p;e[6]!==r?(p=Ie("inline-flex shrink-0 items-center text-status-info",r),e[6]=r,e[7]=p):p=e[7];let g;e[8]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(R,{name:"pulse",className:"size-3.5"}),e[8]=g):g=e[8];let w;return e[9]!==l||e[10]!==f||e[11]!==p?(w=s.jsx("span",{className:p,role:"img","aria-label":f,title:f,"data-action-directory":l,children:g}),e[9]=l,e[10]=f,e[11]=p,e[12]=w):w=e[12],w},No=t=>{const e=nt.c(22),{id:n,projectLabel:r,projectIcon:i,projectColor:o,projectIconImage:l,projectIconBackground:a,isCollapsed:u,alwaysShowActions:d}=t,h=d===void 0?!1:d,{currentTheme:f}=er(),p=i?Ta[i]:null,g=o?Ea[o]??null:null,w=u!==void 0,v=w?h?"hidden":"group-hover/project:hidden group-focus-within/project:hidden":void 0;let x;e[0]!==h||e[1]!==w||e[2]!==u?(x=w?s.jsx("span",{className:Ie("h-3.5 w-3.5 items-center justify-center text-muted-foreground",h?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:s.jsx(R,{name:u?"arrow-right-s":"arrow-down-s",className:"h-3.5 w-3.5"})}):null,e[0]=h,e[1]=w,e[2]=u,e[3]=x):x=e[3];let m;e[4]!==h||e[5]!==f||e[6]!==w||e[7]!==g||e[8]!==v||e[9]!==n||e[10]!==a||e[11]!==l||e[12]!==p?(m=l?s.jsx("span",{className:Ie("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",w&&h?"hidden":"inline-flex",v),style:a?{backgroundColor:a}:void 0,children:s.jsx(Ra,{project:{id:n,iconImage:l},options:{themeVariant:f.metadata.variant,iconColor:f.colors.surface.foreground},className:"h-full w-full object-contain",fallback:p?s.jsx(R,{name:p,className:"h-3.5 w-3.5",style:g?{color:g}:void 0}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:g?{color:g}:void 0})})}):p?s.jsx(R,{name:p,className:Ie("h-3.5 w-3.5",v),style:g?{color:g}:void 0}):s.jsx(R,{name:"folder",className:Ie("h-3.5 w-3.5 text-muted-foreground/80",v),style:g?{color:g}:void 0}),e[4]=h,e[5]=f,e[6]=w,e[7]=g,e[8]=v,e[9]=n,e[10]=a,e[11]=l,e[12]=p,e[13]=m):m=e[13];let b;e[14]!==x||e[15]!==m?(b=s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[x,m]}),e[14]=x,e[15]=m,e[16]=b):b=e[16];let y;e[17]!==r?(y=s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:r}),e[17]=r,e[18]=y):y=e[18];let S;return e[19]!==b||e[20]!==y?(S=s.jsxs(s.Fragment,{children:[b,y]}),e[19]=b,e[20]=y,e[21]=S):S=e[21],S},X0=t=>{const e=nt.c(63),{id:n,disabled:r,projectLabel:i,projectDescription:o,projectDirectory:l,projectIcon:a,projectColor:u,projectIconImage:d,projectIconBackground:h,isCollapsed:f,isRepo:p,isDesktopShell:g,hideDirectoryControls:w,alwaysShowActions:v,onToggle:x,onNewSession:m,onNewWorktreeSession:b,onManageWorktrees:y,onRenameStart:S,onClose:N,sentinelRef:C,children:j,showCreateButtons:A,hideHeader:D,statusIndicator:I,openSidebarMenuKey:M,setOpenSidebarMenuKey:$,projectPickerOptions:E,onProjectSelect:K}=t,B=r===void 0?!1:r,O=A===void 0?!0:A,T=D===void 0?!1:D,k=I===void 0?null:I,{t:P}=Nt(),F=ls(ej);let q;e[0]!==B||e[1]!==n?(q={id:n,disabled:B},e[0]=B,e[1]=n,e[2]=q):q=e[2];const{attributes:Q,listeners:Y,setNodeRef:ce,transform:X,transition:oe,isDragging:te}=si(q),he=c.useRef(!1),_=`project:${n}`,ie=M===_,[ge,ae]=c.useState(!1),z=!!(E&&K);let ne;e[3]!==_||e[4]!==$?(ne=W=>{W&&ae(!1),$(W?_:null)},e[3]=_,e[4]=$,e[5]=ne):ne=e[5];const ue=ne;let me;e[6]!==w||e[7]!==p||e[8]!==N||e[9]!==y||e[10]!==m||e[11]!==S||e[12]!==O||e[13]!==P?(me=W=>s.jsxs(s.Fragment,{children:[O&&!p&&!w&&m&&s.jsxs(W,{onClick:m,children:[s.jsx(R,{name:"add",className:"mr-1.5 h-4 w-4"}),P("sessions.sidebar.project.actions.newSession")]}),p&&!w&&y&&s.jsxs(W,{onClick:y,children:[s.jsx(R,{name:"node-tree",className:"mr-1.5 h-4 w-4"}),P("sessions.sidebar.project.actions.manageWorktrees")]}),s.jsxs(W,{onClick:S,children:[s.jsx(R,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),P("sessions.sidebar.project.actions.edit")]}),s.jsxs(W,{onClick:N,className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"close",className:"mr-1.5 h-4 w-4"}),P("sessions.sidebar.project.actions.closeProject")]})]}),e[6]=w,e[7]=p,e[8]=N,e[9]=y,e[10]=m,e[11]=S,e[12]=O,e[13]=P,e[14]=me):me=e[14];const ke=me,Te=tj,je=sj,Ee=nj;let xe;e[15]===Symbol.for("react.memo_cache_sentinel")?(xe=W=>{(W.button===2||W.button===0&&W.ctrlKey)&&(he.current=!0)},e[15]=xe):xe=e[15];const H=xe;let Ce;e[16]!==x?(Ce=W=>{if(W.currentTarget.blur(),he.current){he.current=!1;return}x()},e[16]=x,e[17]=Ce):Ce=e[17];const ve=Ce;let re;e[18]!==X?(re=ni.Transform.toString(X),e[18]=X,e[19]=re):re=e[19];let le;e[20]!==re||e[21]!==oe?(le={transform:re,transition:oe},e[20]=re,e[21]=oe,e[22]=le):le=e[22];const se=te&&"opacity-30";let G;e[23]!==se?(G=Ie("relative",se),e[23]=se,e[24]=G):G=e[24];let U;e[25]!==v||e[26]!==Q||e[27]!==ue||e[28]!==ve||e[29]!==w||e[30]!==T||e[31]!==n||e[32]!==f||e[33]!==ge||e[34]!==g||e[35]!==ie||e[36]!==z||e[37]!==p||e[38]!==Y||e[39]!==m||e[40]!==b||e[41]!==K||e[42]!==u||e[43]!==o||e[44]!==l||e[45]!==a||e[46]!==h||e[47]!==d||e[48]!==i||e[49]!==E||e[50]!==ke||e[51]!==C||e[52]!==O||e[53]!==k||e[54]!==F||e[55]!==P?(U=T?null:s.jsxs(s.Fragment,{children:[g&&s.jsx("div",{ref:C,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsxs(du,{open:ge,onOpenChange:ae,children:[s.jsx(cu,{render:s.jsx("div",{className:Ie("-ml-2.5 -mr-2 text-left group/project select-none",F&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":F?"true":void 0,onContextMenu:W=>{w||(W.preventDefault(),ae(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 py-1 pl-4 pr-3.5",...Q,children:[z?s.jsxs(Xs,{children:[s.jsx(Qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:Ie("flex min-w-0 flex-1 items-center gap-1.5 rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-[padding]",p&&!w?v||ie?"pr-20":"pr-0 group-hover/project:pr-20 group-focus-within/project:pr-20":v||ie?"pr-14":"pr-0 group-hover/project:pr-14 group-focus-within/project:pr-14"),"aria-label":P("sessions.sidebar.project.selectAria",{project:i}),children:[s.jsx(No,{id:n,projectLabel:i,projectIcon:a,projectColor:u,projectIconImage:d,projectIconBackground:h}),s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}),l?s.jsx(Qr,{directory:l,className:"ml-auto"}):null]})}),s.jsx(Ys,{align:"start",className:"max-h-[70vh] min-w-[220px] overflow-y-auto",children:E?.map(W=>s.jsxs(zt,{onClick:()=>K?.(W.id),className:"flex items-center justify-between gap-3",title:W.projectDescription,children:[s.jsx("span",{className:"flex min-w-0 items-center gap-1.5",children:s.jsx(No,{...W})}),W.id===n?s.jsx(R,{name:"check",className:"h-4 w-4 flex-shrink-0 text-primary"}):null]},W.id))})]}):s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:H,onClick:ve,...Y,className:Ie("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",p&&!w?v||ie?"pr-20":"pr-0 group-hover/project:pr-20 group-focus-within/project:pr-20":v||ie?"pr-14":"pr-0 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsx(No,{id:n,projectLabel:i,projectIcon:a,projectColor:u,projectIconImage:d,projectIconBackground:h,isCollapsed:f,alwaysShowActions:v}),k?s.jsx("span",{className:"ml-1 inline-flex flex-shrink-0 items-center",children:k}):null,l?s.jsx(Qr,{directory:l,className:"ml-auto"}):null]})}),s.jsx(It,{side:"right",sideOffset:8,children:o})]}),s.jsxs("div",{className:Ie("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",O?"right-7":"right-0.5"),children:[O&&p&&!w&&b?s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:W=>{W.stopPropagation(),b()},className:Ie("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",v?"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":P("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(R,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:P("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,w?null:s.jsxs(Xs,{open:ie,onOpenChange:ue,children:[s.jsx(Qs,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie("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",ie?"opacity-100 pointer-events-auto":v?"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":P("sessions.sidebar.project.actions.projectMenu"),onPointerDown:je,onMouseDown:Ee,onClick:Te,children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ys,{align:"end",className:"min-w-[180px]",children:ke(zt)})]})]}),O&&m?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:W=>{W.stopPropagation(),m()},className:Ie("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",v?"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":P(p?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(R,{name:"add",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:P(p?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx(lu,{className:"min-w-[180px]",children:ke(Kn)})]})]}),e[25]=v,e[26]=Q,e[27]=ue,e[28]=ve,e[29]=w,e[30]=T,e[31]=n,e[32]=f,e[33]=ge,e[34]=g,e[35]=ie,e[36]=z,e[37]=p,e[38]=Y,e[39]=m,e[40]=b,e[41]=K,e[42]=u,e[43]=o,e[44]=l,e[45]=a,e[46]=h,e[47]=d,e[48]=i,e[49]=E,e[50]=ke,e[51]=C,e[52]=O,e[53]=k,e[54]=F,e[55]=P,e[56]=U):U=e[56];let be;return e[57]!==j||e[58]!==ce||e[59]!==le||e[60]!==G||e[61]!==U?(be=s.jsxs("div",{ref:ce,style:le,className:G,children:[U,j]}),e[57]=j,e[58]=ce,e[59]=le,e[60]=G,e[61]=U,e[62]=be):be=e[62],be},J0=t=>{const e=nt.c(21),{id:n,disabled:r,children:i}=t,o=r===void 0?!1:r;let l;e[0]!==o||e[1]!==n?(l={id:n,disabled:o},e[0]=o,e[1]=n,e[2]=l):l=e[2];const{listeners:a,setNodeRef:u,setActivatorNodeRef:d,transform:h,transition:f,isDragging:p}=si(l);let g;e[3]!==a||e[4]!==d?(g={listeners:a,setActivatorNodeRef:d},e[3]=a,e[4]=d,e[5]=g):g=e[5];const w=g;let v;e[6]!==h?(v=ni.Transform.toString(h),e[6]=h,e[7]=v):v=e[7];let x;e[8]!==v||e[9]!==f?(x={transform:v,transition:f},e[8]=v,e[9]=f,e[10]=x):x=e[10];const m=p&&"opacity-50";let b;e[11]!==m?(b=Ie("space-y-0.5 rounded-md",m),e[11]=m,e[12]=b):b=e[12];let y;e[13]!==i||e[14]!==w?(y=i(w),e[13]=i,e[14]=w,e[15]=y):y=e[15];let S;return e[16]!==u||e[17]!==x||e[18]!==b||e[19]!==y?(S=s.jsx("div",{ref:u,style:x,className:b,children:y}),e[16]=u,e[17]=x,e[18]=b,e[19]=y,e[20]=S):S=e[20],S},Z0=c.memo(J0);function ej(t){return t.stickyZoneHeaders}function tj(t){t.stopPropagation()}function sj(t){t.stopPropagation()}function nj(t){t.stopPropagation()}const rj=(t,e)=>{const n=new Set,r=new Set,i=(o,l)=>{n.add(o.session.id),(!l||e)&&r.add(o.session.id),o.children.forEach(a=>i(a,!0))};return t.forEach(o=>i(o,!1)),{active:n,unread:r}},pm=t=>{const e=nt.c(9),{nodes:n,includeUnreadSubtasks:r,enabled:i}=t,o=i===void 0?!0:i;let l;e[0]!==r||e[1]!==n?(l=rj(n,r),e[0]=r,e[1]=n,e[2]=l):l=e[2];const a=l;let u;e[3]!==o||e[4]!==a.active?(u=p=>{if(!o)return null;for(const g of a.active){const w=p.statusById.get(g)?.status.type;if(w==="busy"||w==="retry")return"active"}return null},e[3]=o,e[4]=a.active,e[5]=u):u=e[5];const d=Ma(u);let h;e[6]!==o||e[7]!==a.unread?(h=p=>{if(!o)return null;for(const g of a.unread)if((p.index.session.unseenCount[g]??0)>0)return"unread";return null},e[6]=o,e[7]=a.unread,e[8]=h):h=e[8];const f=Oa(h);return d??f};function gm(t){const e=nt.c(6),{state:n,activeLabel:r,unreadLabel:i,className:o}=t,l=n==="active"?r:i,a=n==="active"?"bg-primary":"bg-[var(--status-info)]";let u;e[0]!==o||e[1]!==a?(u=Ie("h-1.5 w-1.5 shrink-0 rounded-full",a,o),e[0]=o,e[1]=a,e[2]=u):u=e[2];let d;return e[3]!==l||e[4]!==u?(d=s.jsx("span",{className:u,"aria-label":l,title:l}),e[3]=l,e[4]=u,e[5]=d):d=e[5],d}const oj=t=>{const e=nt.c(11),{nodes:n,includeUnreadSubtasks:r}=t,{t:i}=Nt();let o;e[0]!==r||e[1]!==n?(o={nodes:n,includeUnreadSubtasks:r},e[0]=r,e[1]=n,e[2]=o):o=e[2];const l=pm(o);if(!l)return null;let a;e[3]!==i?(a=i("sessions.sidebar.session.status.active"),e[3]=i,e[4]=a):a=e[4];let u;e[5]!==i?(u=i("sessions.sidebar.session.status.unread"),e[5]=i,e[6]=u):u=e[6];let d;return e[7]!==l||e[8]!==a||e[9]!==u?(d=s.jsx(gm,{state:l,activeLabel:a,unreadLabel:u}),e[7]=l,e[8]=a,e[9]=u,e[10]=d):d=e[10],d},ij=t=>{const e=nt.c(82),{folder:n,displayName:r,sessions:i,subFolderItems:o,isCollapsed:l,collapsedActivityState:a,onToggle:u,onRename:d,onDelete:h,children:f,mobileVariant:p,alwaysShowActions:g,isRenaming:w,renameDraft:v,onRenameDraftChange:x,onRenameSave:m,onRenameCancel:b,droppableRef:y,isDropTarget:S,onNewSession:N,depth:C,hideActions:j,archivedBucket:A}=t,D=a===void 0?null:a,M=g===void 0?p===void 0?!1:p:g,$=w===void 0?!1:w,E=v===void 0?"":v,K=S===void 0?!1:S,B=j===void 0?!1:j,O=A===void 0?!1:A,{t:T}=Nt(),[k,P]=c.useState(!1),[F,q]=c.useState(""),Q=c.useRef(null),Y=$||k,ce=$?E:F;let X;e[0]!==n.name?(X=()=>{q(n.name),P(!0)},e[0]=n.name,e[1]=X):X=e[1];const oe=X;let te;e[2]!==ce||e[3]!==n.name||e[4]!==$||e[5]!==d||e[6]!==m?(te=()=>{const ye=ce.trim();ye&&ye!==n.name&&d(ye),$&&m&&m(),P(!1),q("")},e[2]=ce,e[3]=n.name,e[4]=$,e[5]=d,e[6]=m,e[7]=te):te=e[7];const he=te;let _;e[8]!==$||e[9]!==b?(_=()=>{$&&b&&b(),P(!1),q("")},e[8]=$,e[9]=b,e[10]=_):_=e[10];const ie=_;let ge;e[11]!==$||e[12]!==x?(ge=ye=>{$&&x?x(ye):q(ye)},e[11]=$,e[12]=x,e[13]=ge):ge=e[13];const ae=ge;let z,ne;e[14]!==$?(z=()=>{if(!$)return;const ye=()=>{const $e=Q.current;$e&&($e.focus(),$e.select())},Fe=requestAnimationFrame(ye),Ke=window.setTimeout(ye,0);return()=>{cancelAnimationFrame(Fe),window.clearTimeout(Ke)}},ne=[$],e[14]=$,e[15]=z,e[16]=ne):(z=e[15],ne=e[16]),c.useEffect(z,ne);const ue=l?"folder":"folder-open",me=K&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ke;e[17]!==me?(ke=Ie("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",me),e[17]=me,e[18]=ke):ke=e[18];let Te;e[19]!==u||e[20]!==Y?(Te=Y?void 0:ye=>{ye.currentTarget.blur(),u()},e[19]=u,e[20]=Y,e[21]=Te):Te=e[21];const je=Y?void 0:"button",Ee=Y?void 0:0;let xe;e[22]!==u||e[23]!==Y?(xe=Y?void 0:ye=>{(ye.key==="Enter"||ye.key===" ")&&(ye.preventDefault(),u())},e[22]=u,e[23]=Y,e[24]=xe):xe=e[24];let H;e[25]!==n.name||e[26]!==l||e[27]!==T?(H=l?T("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):T("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[25]=n.name,e[26]=l,e[27]=T,e[28]=H):H=e[28];const Ce=O?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";let ve;e[29]!==Ce?(ve=Ie("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",Ce),e[29]=Ce,e[30]=ve):ve=e[30];const re=K?"text-primary":"text-muted-foreground";let le;e[31]!==re?(le=Ie("h-3.5 w-3.5 flex-shrink-0",re),e[31]=re,e[32]=le):le=e[32];let se;e[33]!==ue||e[34]!==le?(se=s.jsx(R,{name:ue,className:le}),e[33]=ue,e[34]=le,e[35]=se):se=e[35];let G;e[36]!==D||e[37]!==r||e[38]!==ce||e[39]!==n.name||e[40]!==ie||e[41]!==ae||e[42]!==he||e[43]!==l||e[44]!==K||e[45]!==Y||e[46]!==i||e[47]!==T?(G=Y?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:lj,onMouseDown:cj,onSubmit:ye=>{ye.preventDefault(),he()},children:[s.jsx("input",{ref:Q,value:ce,onChange:ye=>ae(ye.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:T("sessions.sidebar.folderItem.namePlaceholder"),onClick:dj,onPointerDown:uj,onMouseDown:mj,onKeyDown:ye=>{if(ye.key==="Escape"){ye.stopPropagation(),ie();return}(ye.key===" "||ye.key==="Enter")&&ye.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:fj,onPointerDown:hj,onMouseDown:pj,children:s.jsx(R,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:ye=>{ye.stopPropagation(),ie()},onPointerDown:gj,onMouseDown:xj,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:Ie("typography-ui-label font-semibold truncate",K?"text-primary":"text-muted-foreground"),children:r??n.name})}),s.jsx(It,{side:"right",sideOffset:8,className:"max-w-xs",children:r??n.name})]}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",i.length]}),D?s.jsx(gm,{state:D,activeLabel:T("sessions.sidebar.session.status.active"),unreadLabel:T("sessions.sidebar.session.status.unread")}):null,l?s.jsx(R,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[36]=D,e[37]=r,e[38]=ce,e[39]=n.name,e[40]=ie,e[41]=ae,e[42]=he,e[43]=l,e[44]=K,e[45]=Y,e[46]=i,e[47]=T,e[48]=G):G=e[48];let U;e[49]!==ve||e[50]!==se||e[51]!==G?(U=s.jsxs("div",{className:ve,children:[se,G]}),e[49]=ve,e[50]=se,e[51]=G,e[52]=U):U=e[52];let be;e[53]!==M||e[54]!==O||e[55]!==n.name||e[56]!==oe||e[57]!==B||e[58]!==h||e[59]!==N||e[60]!==Y||e[61]!==T?(be=!Y&&(!B||O)?s.jsx("div",{className:Ie("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:[!O&&N?s.jsx("button",{type:"button",onClick:ye=>{ye.stopPropagation(),N()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":T("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:T("sessions.sidebar.project.actions.newSession"),children:s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})}):null,O?null:s.jsx("button",{type:"button",onClick:ye=>{ye.stopPropagation(),oe()},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":T("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(R,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:ye=>{ye.stopPropagation(),h()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":O?T("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):T("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[53]=M,e[54]=O,e[55]=n.name,e[56]=oe,e[57]=B,e[58]=h,e[59]=N,e[60]=Y,e[61]=T,e[62]=be):be=e[62];let W;e[63]!==y||e[64]!==ke||e[65]!==Te||e[66]!==je||e[67]!==Ee||e[68]!==xe||e[69]!==H||e[70]!==U||e[71]!==be?(W=s.jsxs("div",{ref:y,className:ke,onClick:Te,role:je,tabIndex:Ee,onKeyDown:xe,"aria-label":H,children:[U,be]}),e[63]=y,e[64]=ke,e[65]=Te,e[66]=je,e[67]=Ee,e[68]=xe,e[69]=H,e[70]=U,e[71]=be,e[72]=W):W=e[72];let Ne;e[73]!==f||e[74]!==l||e[75]!==i||e[76]!==o||e[77]!==T?(Ne=l?null:s.jsxs("div",{className:"pb-1",children:[o,i.length>0?f:o?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:T("sessions.sidebar.folderItem.emptyFolder")})]}),e[73]=f,e[74]=l,e[75]=i,e[76]=o,e[77]=T,e[78]=Ne):Ne=e[78];let Oe;return e[79]!==W||e[80]!==Ne?(Oe=s.jsxs("div",{className:"oc-folder",children:[W,Ne]}),e[79]=W,e[80]=Ne,e[81]=Oe):Oe=e[81],Oe},aj=c.memo(ij);function lj(t){return t.stopPropagation()}function cj(t){return t.stopPropagation()}function dj(t){return t.stopPropagation()}function uj(t){return t.stopPropagation()}function mj(t){return t.stopPropagation()}function fj(t){return t.stopPropagation()}function hj(t){return t.stopPropagation()}function pj(t){return t.stopPropagation()}function gj(t){return t.stopPropagation()}function xj(t){return t.stopPropagation()}const bj=t=>{const e=nt.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:i,children:o}=t,l=`session-drag:${n}`;let a;e[0]!==r||e[1]!==n||e[2]!==i?(a={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:i},e[0]=r,e[1]=n,e[2]=i,e[3]=a):a=e[3];let u;e[4]!==l||e[5]!==a?(u={id:l,data:a},e[4]=l,e[5]=a,e[6]=u):u=e[6];const{attributes:d,listeners:h,setNodeRef:f,isDragging:p}=_g(u);let g;e[7]!==h?(g=m=>{m.stopPropagation(),h?.onPointerDown&&h.onPointerDown(m)},e[7]=h,e[8]=g):g=e[8];const w=g,v=p?"opacity-30":void 0;let x;return e[9]!==d||e[10]!==o||e[11]!==w||e[12]!==f||e[13]!==v?(x=s.jsx("div",{ref:f,...d,onPointerDown:w,className:v,children:o}),e[9]=d,e[10]=o,e[11]=w,e[12]=f,e[13]=v,e[14]=x):x=e[14],x},yj=t=>{const e=nt.c(11),{folderId:n,children:r}=t,i=`folder-drop:${n}`;let o;e[0]!==n?(o={type:"folder",folderId:n},e[0]=n,e[1]=o):o=e[1];let l;e[2]!==i||e[3]!==o?(l={id:i,data:o},e[2]=i,e[3]=o,e[4]=l):l=e[4];const{setNodeRef:a,isOver:u}=Lg(l);let d;e[5]!==r||e[6]!==u||e[7]!==a?(d=r(a,u),e[5]=r,e[6]=u,e[7]=a,e[8]=d):d=e[8];let h;return e[9]!==d?(h=s.jsx(s.Fragment,{children:d}),e[9]=d,e[10]=h):h=e[10],h},wj=t=>{const e=nt.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:i,children:o}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[0]=l):l=e[0];const a=Ur(On(Vi,l)),[u,d]=c.useState(null),[h,f]=c.useState("Session"),[p,g]=c.useState(null),[w,v]=c.useState(null);if(!n){let j;return e[1]!==o?(j=s.jsx(s.Fragment,{children:o}),e[1]=o,e[2]=j):j=e[2],j}let x;e[3]!==i?(x=j=>{d(null),g(null),v(null);const{active:A,over:D}=j;if(!D)return;const I=A.data.current,M=D.data.current;I?.type==="session"&&I.sessionId&&M?.type==="folder"&&M.folderId&&i(I.sessionId,M.folderId)},e[3]=i,e[4]=x):x=e[4];const m=x;let b,y;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=j=>{const A=j.active.data.current;if(A?.type==="session"&&A.sessionId){d(A.sessionId),f(A.sessionTitle??"Session");const D=j.active.rect.current.initial?.width,I=j.active.rect.current.initial?.height;g(typeof D=="number"?D:null),v(typeof I=="number"?I:null)}},y=()=>{d(null),g(null),v(null)},e[5]=b,e[6]=y):(b=e[5],y=e[6]);let S;e[7]!==w||e[8]!==u||e[9]!==h||e[10]!==p||e[11]!==r?(S=u&&r?s.jsxs("div",{style:{width:p?`${p}px`:"auto",height:w?`${w}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(R,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:h})]}):null,e[7]=w,e[8]=u,e[9]=h,e[10]=p,e[11]=r,e[12]=S):S=e[12];let N;e[13]!==S?(N=s.jsx(Ui,{children:S}),e[13]=S,e[14]=N):N=e[14];let C;return e[15]!==o||e[16]!==m||e[17]!==a||e[18]!==N?(C=s.jsxs(Kr,{sensors:a,collisionDetection:Hr,onDragStart:b,onDragCancel:y,onDragEnd:m,children:[o,N]}),e[15]=o,e[16]=m,e[17]=a,e[18]=N,e[19]=C):C=e[19],C},la=(t,e,n)=>{if(!e)return;const r=i=>{let o=i.session.id===e;for(const l of i.children)o=r(l)||o;return o&&n.add(i.session.id),o};for(const i of t)r(i)},Gn=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Gn(n,e))return!0;return!1},Sj=({isSubtaskSession:t,archivedBucket:e,isVSCode:n,sessionDirectory:r})=>!t&&!e&&!n&&!kh(r),vj=({sessionDirectory:t,isStreaming:e,isMovingToWorktree:n})=>!t||e||n,jj=(t,e,n)=>{const r=new Map,i=o=>{const l=$s(o.session)??wt(o.worktree?.path)??n;if(l){const a=r.get(l)??[];a.push(o.session.id),r.set(l,a)}if(!(o===t&&e))for(const a of o.children)i(a)};return i(t),[...r].map(([o,l])=>({directory:o,sessionIDs:l}))},kj=(t,e)=>{const n=new Set(t);return t.map(r=>e.get(r)).filter(r=>{if(!r)return!1;const i=new Set;let o=r.session.parentID??null;for(;o&&!i.has(o);){if(n.has(o)&&e.has(o))return!1;i.add(o),o=e.get(o)?.session?.parentID??null}return!0})},Cj=t=>{const e=new Map(t.map(l=>[l.id,l])),n=new Map;for(const l of t){if(!l.parentId||!e.has(l.parentId))continue;const a=n.get(l.parentId)??[];a.push(l),n.set(l.parentId,a)}const r=new Set,i=[],o=l=>{if(r.has(l.id))return;i.push(l);const a=[l.id];for(;a.length>0;){const u=a.pop();if(!(!u||r.has(u))){r.add(u);for(const d of n.get(u)??[])a.push(d.id)}}};return t.forEach(l=>{(!l.parentId||!e.has(l.parentId))&&o(l)}),t.forEach(o),i},Nj=(t,e)=>{const n=new Map(t.map(u=>[u.id,u])),r=new Map,i=new Set;for(const u of t){if(u.parentId&&!n.has(u.parentId)){i.add(u.id);continue}if(u.parentId){const f=r.get(u.parentId)??[];f.push(u.id),r.set(u.parentId,f)}const d=new Set;let h=u.id;for(;h;){if(d.has(h)){i.add(u.id);break}d.add(h),h=n.get(h)?.parentId}}const o=new Set,l=new Set,a=u=>{if(o.has(u))return!0;if(l.has(u))return!1;const d=n.get(u);if(!d)return!1;l.add(u);let h=i.has(u);return!h&&e.archivedBucket&&d.nodeCount===0?h=(r.get(u)??[]).some(a):(!h&&!e.searchQuery&&(h=!0),!h&&(d.nodeCount>0||Ro([d.name],e.searchQuery))&&(h=!0),h||(h=(r.get(u)??[]).some(a))),l.delete(u),h&&o.add(u),h};return t.forEach(u=>a(u.id)),new Set(t.filter(u=>o.has(u.id)).map(u=>u.id))},kc=new WeakMap;let Cc=1;const Aj=t=>{const e=kc.get(t);if(e!==void 0)return e;const n=Cc;return Cc+=1,kc.set(t,n),n},Uo=t=>t.children.length===0?"":t.children.map(n=>{const r=Aj(n.session);return n.children.length===0?`${n.session.id}@${r}`:`${n.session.id}@${r}:${Uo(n)}`}).join("|"),xm=(t,e,n,r,i,o)=>{const l=ps(),a=(u,d)=>{if(u.session.id!==d.session.id||u.children.length!==d.children.length)return!0;const h=u.session.directory??i,f=d.session.directory??o,p=ul(l,h??"",u.session.id),g=ul(l,f??"",d.session.id);return(p?n.has(p):!1)!==(g?r.has(g):!1)?!0:u.children.some((w,v)=>a(w,d.children[v]))};return a(t,e)},Dj=t=>t.actionsAlwaysVisible?"":`transition-opacity duration-150 ${t.menuOpen?"opacity-0":t.hideOnHoverClass}`,Yr=(t,e,n,r)=>{if(!e)return null;const i=r?"archived":"active";let o=null;const l=a=>{if(`${n}:${i}:${a.session.id}`===e)return o=a.session.id,!0;for(const d of a.children)if(l(d))return!0;return!1};return t.forEach(a=>l(a)),o};let ca=!1;const da=new Set;let Nc=!1;function Pj(){for(const t of da)t()}function Qa(t){ca!==t&&(ca=t,Pj())}function Ij(t){t.key==="Shift"&&Qa(!0)}function Tj(t){t.key==="Shift"&&Qa(!1)}function Ej(){Qa(!1)}function Rj(){Nc||typeof window>"u"||(Nc=!0,window.addEventListener("keydown",Ij),window.addEventListener("keyup",Tj),window.addEventListener("blur",Ej))}function Mj(t){return Rj(),da.add(t),()=>{da.delete(t)}}function Oj(){return ca}function Bj(){return!1}function Fj(){return xt.useSyncExternalStore(Mj,Oj,Bj)}const _j=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,bm=/^g[1-9]\d*$/,Ir=(t,e,n,r,i)=>{if(!_j.test(t)||e!==void 0&&!bm.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(i===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(i==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(i))return null;const o=Number.parseInt(i,10);return!Number.isSafeInteger(o)||o<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:o,fusion:!1}},Ao=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return Ir(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,a,u,d]=e;return bm.test(a)?Ir(n,a,u,d,void 0):Ir(n,void 0,a,u,d)}const[,r,i,o,l]=e;return r===""?Ir(n,void 0,i,o,l):Ir(n,r,i,o,l)},Lj=t=>{const e=[t.groupSlug];return t.runGroup&&e.push(t.runGroup),e.push(t.providerID,t.modelID),t.index!==void 0&&e.push(String(t.index)),e.join("/")},$j=(t,e,n,r)=>{const i=[t];return r&&i.push(r),i.push(e,n,"fusion"),i.join("/")},ym=t=>{const e=nt.c(36),{value:n,onChange:r,className:i,disabled:o,id:l,portalToBody:a}=t,{t:u}=Nt(),d=Ht(Wj),h=Ht(zj),f=Ht(Vj);let p;e[0]!==d?(p=d(),e[0]=d,e[1]=p):p=e[1];const g=p;let w;e[2]!==g?(w=g.filter(Uj),e[2]=g,e[3]=w):w=e[3];const v=w;let x,m;e[4]!==g.length||e[5]!==h?(x=()=>{g.length===0&&h()},m=[g.length,h],e[4]=g.length,e[5]=h,e[6]=x,e[7]=m):(x=e[6],m=e[7]),c.useEffect(x,m);let b,y;e[8]!==f||e[9]!==o||e[10]!==r||e[11]!==v||e[12]!==n?(b=()=>{if(o)return;const $=n.trim();if($.length>0&&v.some(B=>B.name===$))return;const E=typeof f=="string"&&f.trim().length>0?f.trim():null;if(E&&v.some(B=>B.name===E)){r(E);return}const K=v[0]?.name;K&&r(K)},y=[f,o,r,v,n],e[8]=f,e[9]=o,e[10]=r,e[11]=v,e[12]=n,e[13]=b,e[14]=y):(b=e[13],y=e[14]),c.useEffect(b,y);const S=n.trim().length>0?n:void 0;let N;e[15]!==i?(N=Ie("max-w-full",i),e[15]=i,e[16]=N):N=e[16];let C;e[17]!==u?(C=u("multirun.agentSelector.placeholder"),e[17]=u,e[18]=C):C=e[18];let j;e[19]!==C?(j=s.jsx(Cs,{placeholder:C}),e[19]=C,e[20]=j):j=e[20];let A;e[21]!==l||e[22]!==N||e[23]!==j?(A=s.jsx(Fs,{id:l,size:"lg",className:N,children:j}),e[21]=l,e[22]=N,e[23]=j,e[24]=A):A=e[24];let D;e[25]!==v?(D=v.length>0&&s.jsx(Bi,{children:v.map(Kj)}),e[25]=v,e[26]=D):D=e[26];let I;e[27]!==a||e[28]!==D?(I=s.jsx(_s,{fitContent:!0,portalToBody:a,children:D}),e[27]=a,e[28]=D,e[29]=I):I=e[29];let M;return e[30]!==o||e[31]!==r||e[32]!==S||e[33]!==A||e[34]!==I?(M=s.jsxs(Bs,{value:S,onValueChange:r,disabled:o,children:[A,I]}),e[30]=o,e[31]=r,e[32]=S,e[33]=A,e[34]=I,e[35]=M):M=e[35],M};function Wj(t){return t.getVisibleAgents}function zj(t){return t.loadAgents}function Vj(t){return t.currentAgentName}function Uj(t){return Ud(t.mode)}function Kj(t){return s.jsx(ts,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Hj="h-7",$r=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,Gj=t=>{const e=nt.c(12),{model:n,instanceIndex:r,totalSameModel:i,onRemove:o}=t,l=n.displayName||`${n.providerID}/${n.modelID}`,a=i>1?`${l} (${r})`:l;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Ie("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Hj),e[0]=u):u=e[0];let d;e[1]!==n.providerID?(d=s.jsx(Fi,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=d):d=e[2];let h;e[3]!==a?(h=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:a}),e[3]=a,e[4]=h):h=e[4];let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(R,{name:"close",className:"h-3.5 w-3.5"}),e[5]=f):f=e[5];let p;e[6]!==o?(p=s.jsx("button",{type:"button",onClick:o,className:"text-muted-foreground hover:text-foreground ml-0.5",children:f}),e[6]=o,e[7]=p):p=e[7];let g;return e[8]!==d||e[9]!==h||e[10]!==p?(g=s.jsxs("div",{className:u,children:[d,h,p]}),e[8]=d,e[9]=h,e[10]=p,e[11]=g):g=e[11],g},wm=t=>{const e=nt.c(120),{selectedModels:n,onAdd:r,onRemove:i,onUpdate:o,minModels:l,addButtonLabel:a,showChips:u,maxModels:d,addButtonClassName:h,dropdownSide:f,dropdownClassName:p,containerClassName:g,triggerIcon:w}=t,v=u===void 0?!0:u,x=f===void 0?"top":f,{t:m}=Nt(),b=Ht(qj),y=Ht(Qj),S=Pe(Yj),N=Pe(Xj),{favoriteModelsList:C,recentModelsList:j}=Ch(),A=Pe(Jj),D=Pe(Zj),[I,M]=c.useState(!1),[$,E]=c.useState(""),[K,B]=c.useState(null),O=c.useRef(null),T=c.useRef(null),k=d===1,P=d===void 0||n.length<d||k;let F;if(e[0]!==n){F=new Map;for(const De of n){const at=`${De.providerID}:${De.modelID}`;F.set(at,(F.get(at)||0)+1)}e[0]=n,e[1]=F}else F=e[1];const q=F;let Q;e[2]!==n?(Q=De=>n.filter(Qe=>Qe.providerID===De.providerID&&Qe.modelID===De.modelID).findIndex(Qe=>Qe.instanceId===De.instanceId)+1,e[2]=n,e[3]=Q):Q=e[3];const Y=Q;let ce,X;e[4]!==x||e[5]!==I?(ce=()=>{if(!I||!T.current)return;const De=T.current.getBoundingClientRect();if(x==="bottom"){const Se=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-De.bottom-16-112;B(Math.max(160,Math.min(320,Se)));return}let at=T.current.parentElement;for(;at&&!at.matches('[role="dialog"], [data-scroll-shadow-scroller]');){const de=getComputedStyle(at);if(de.overflow==="auto"||de.overflow==="hidden"||de.overflowY==="auto"||de.overflowY==="hidden")break;at=at.parentElement}const Qe=at?at.getBoundingClientRect().top:0,lt=De.top-Qe-16;B(Math.max(150,Math.min(300,lt)))},X=[x,I],e[4]=x,e[5]=I,e[6]=ce,e[7]=X):(ce=e[6],X=e[7]),c.useEffect(ce,X);let oe,te;e[8]!==P||e[9]!==I?(oe=()=>{!P&&I&&(M(!1),E(""))},te=[P,I],e[8]=P,e[9]=I,e[10]=oe,e[11]=te):(oe=e[10],te=e[11]),c.useEffect(oe,te);let he,_;e[12]!==I?(he=()=>{if(!I)return;const De=at=>{O.current&&!O.current.contains(at.target)&&(M(!1),E(""))};return document.addEventListener("mousedown",De),()=>document.removeEventListener("mousedown",De)},_=[I],e[12]=I,e[13]=he,e[14]=_):(he=e[13],_=e[14]),c.useEffect(he,_);let ie;e[15]!==k||e[16]!==r||e[17]!==o||e[18]!==n.length?(ie=De=>{const at={providerID:De.providerID,modelID:De.modelID,displayName:De.model.name||De.modelID,instanceId:$r()};k&&n.length>0&&o?o(0,at):r(at),k&&(M(!1),E(""))},e[15]=k,e[16]=r,e[17]=o,e[18]=n.length,e[19]=ie):ie=e[19];const ge=ie;let ae;e[20]!==m?(ae=m("multirun.modelMultiSelect.search.placeholder"),e[20]=m,e[21]=ae):ae=e[21];let z;e[22]!==m?(z=m("multirun.modelMultiSelect.search.noResults"),e[22]=m,e[23]=z):z=e[23];let ne;e[24]!==m?(ne=m("multirun.modelMultiSelect.sections.favorites"),e[24]=m,e[25]=ne):ne=e[25];let ue;e[26]!==m?(ue=m("multirun.modelMultiSelect.sections.recent"),e[26]=m,e[27]=ue):ue=e[27];let me;e[28]!==m?(me=m("multirun.modelMultiSelect.keyboard.hint"),e[28]=m,e[29]=me):me=e[29];let ke;e[30]!==m?(ke=m("settings.agents.modelSelector.actions.favorite"),e[30]=m,e[31]=ke):ke=e[31];let Te;e[32]!==m?(Te=m("settings.agents.modelSelector.actions.unfavorite"),e[32]=m,e[33]=Te):Te=e[33];let je;e[34]!==m?(je=m("chat.modelControls.capabilities"),e[34]=m,e[35]=je):je=e[35];let Ee;e[36]!==m?(Ee=m("chat.modelControls.capability.toolCalling"),e[36]=m,e[37]=Ee):Ee=e[37];let xe;e[38]!==m?(xe=m("chat.modelControls.capability.reasoning"),e[38]=m,e[39]=xe):xe=e[39];let H;e[40]!==m?(H=m("chat.modelControls.input"),e[40]=m,e[41]=H):H=e[41];let Ce;e[42]!==m?(Ce=m("chat.modelControls.output"),e[42]=m,e[43]=Ce):Ce=e[43];let ve;e[44]!==m?(ve=m("chat.modelControls.costPerMillion"),e[44]=m,e[45]=ve):ve=e[45];let re;e[46]!==ae||e[47]!==z||e[48]!==ne||e[49]!==ue||e[50]!==me||e[51]!==ke||e[52]!==Te||e[53]!==je||e[54]!==Ee||e[55]!==xe||e[56]!==H||e[57]!==Ce||e[58]!==ve?(re={searchPlaceholder:ae,noResults:z,favorites:ne,recent:ue,keyboardHint:me,favorite:ke,unfavorite:Te,capabilities:je,capabilityToolCalling:Ee,capabilityReasoning:xe,input:H,output:Ce,costPerMillion:ve},e[46]=ae,e[47]=z,e[48]=ne,e[49]=ue,e[50]=me,e[51]=ke,e[52]=Te,e[53]=je,e[54]=Ee,e[55]=xe,e[56]=H,e[57]=Ce,e[58]=ve,e[59]=re):re=e[59];const le=re;let se;e[60]!==g?(se=Ie("relative",g),e[60]=g,e[61]=se):se=e[61];const G=I?"":void 0;let U;e[62]!==h?(U=Ie(Kd({size:"default"}),"w-fit",h),e[62]=h,e[63]=U):U=e[63];const be=!P;let W;e[64]!==I?(W=()=>{M(!I)},e[64]=I,e[65]=W):W=e[65];let Ne;e[66]!==w?(Ne=w??s.jsx(R,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=w,e[67]=Ne):Ne=e[67];let Oe;e[68]!==a||e[69]!==m?(Oe=a??m("multirun.modelMultiSelect.actions.addModel"),e[68]=a,e[69]=m,e[70]=Oe):Oe=e[70];let ye;e[71]!==G||e[72]!==U||e[73]!==be||e[74]!==W||e[75]!==Ne||e[76]!==Oe?(ye=s.jsxs("button",{ref:T,type:"button","data-popup-open":G,className:U,disabled:be,onClick:W,children:[Ne,Oe]}),e[71]=G,e[72]=U,e[73]=be,e[74]=W,e[75]=Ne,e[76]=Oe,e[77]=ye):ye=e[77];let Fe;e[78]!==K||e[79]!==P||e[80]!==p||e[81]!==x||e[82]!==C||e[83]!==ge||e[84]!==A||e[85]!==N||e[86]!==I||e[87]!==le||e[88]!==q||e[89]!==y||e[90]!==D||e[91]!==b||e[92]!==j||e[93]!==$||e[94]!==S?(Fe=I?s.jsx("div",{className:Ie("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",x==="top"?"bottom-full mb-1":"top-full mt-1",p),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(Nh,{providers:b,providerOrder:D,favoriteModels:C,recentModels:j,modelsMetadata:y,hiddenModels:A,searchQuery:$,onSearchQueryChange:E,onSelect:ge,labels:le,selectionCount:De=>q.get(`${De.providerID}:${De.modelID}`)||0,disabled:!P,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:K?`${K}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:I,isFavorite:De=>N(De.providerID,De.modelID),onToggleFavorite:De=>S(De.providerID,De.modelID),onEscape:()=>{M(!1),E("")}})}):null,e[78]=K,e[79]=P,e[80]=p,e[81]=x,e[82]=C,e[83]=ge,e[84]=A,e[85]=N,e[86]=I,e[87]=le,e[88]=q,e[89]=y,e[90]=D,e[91]=b,e[92]=j,e[93]=$,e[94]=S,e[95]=Fe):Fe=e[95];let Ke;e[96]!==se||e[97]!==ye||e[98]!==Fe?(Ke=s.jsxs("div",{className:se,ref:O,children:[ye,Fe]}),e[96]=se,e[97]=ye,e[98]=Fe,e[99]=Ke):Ke=e[99];let $e;e[100]!==Y||e[101]!==q||e[102]!==i||e[103]!==o||e[104]!==b||e[105]!==n||e[106]!==v||e[107]!==m?($e=v&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((De,at)=>{const Qe=`${De.providerID}:${De.modelID}`,lt=q.get(Qe)||1,de=Y(De),Se=b.find(Ue=>Ue.id===De.providerID)?.models?.find(Ue=>Ue.id===De.modelID),Ve=Se?.variants?Object.keys(Se.variants):[],He=Ve.length>0,it=De.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Gj,{model:De,instanceIndex:de,totalSameModel:lt,onRemove:()=>i(at)}),He&&s.jsxs(Bs,{value:it,onValueChange:Ue=>{if(!o)return;o(at,{...De,variant:Ue==="__default__"?void 0:Ue})},children:[s.jsxs(Fs,{size:"sm",className:"gap-1.5",children:[s.jsx(R,{name:"brain-ai-3",className:Ie("h-3.5 w-3.5 flex-shrink-0",it==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(Cs,{placeholder:m("multirun.modelMultiSelect.variant.placeholder"),children:Ue=>Ue==="__default__"?m("multirun.modelMultiSelect.variant.default"):Ue})]}),s.jsxs(_s,{fitContent:!0,children:[s.jsx(ts,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:m("multirun.modelMultiSelect.variant.default")}),Ve.map(e2)]})]})]},De.instanceId)})}),e[100]=Y,e[101]=q,e[102]=i,e[103]=o,e[104]=b,e[105]=n,e[106]=v,e[107]=m,e[108]=$e):$e=e[108];let V;e[109]!==Ke||e[110]!==$e?(V=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Ke,$e]}),e[109]=Ke,e[110]=$e,e[111]=V):V=e[111];let fe;e[112]!==d||e[113]!==l||e[114]!==n.length||e[115]!==m?(fe=l!==void 0&&n.length<l&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:d!==void 0?m("multirun.modelMultiSelect.validation.minToMax",{min:l,max:d}):m("multirun.modelMultiSelect.validation.minOnly",{min:l})}),e[112]=d,e[113]=l,e[114]=n.length,e[115]=m,e[116]=fe):fe=e[116];let Me;return e[117]!==V||e[118]!==fe?(Me=s.jsxs("div",{className:"space-y-2",children:[V,fe]}),e[117]=V,e[118]=fe,e[119]=Me):Me=e[119],Me};function qj(t){return t.providers}function Qj(t){return t.modelsMetadata}function Yj(t){return t.toggleFavoriteModel}function Xj(t){return t.isFavoriteModel}function Jj(t){return t.hiddenModels}function Zj(t){return t.providerOrder}function e2(t){return s.jsx(ts,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const t2=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
915
|
+
|
|
916
|
+
--- RESULT ${n+1}: ${r} ---
|
|
917
|
+
${e.trim()}
|
|
918
|
+
--- END RESULT ${n+1} ---`},Ac=(t,e)=>et.getState().getWorktreeMetadata(t)?.projectDirectory??e,s2=async t=>{const e=t.directory??void 0,n=Dh(t.session.id,e);if(n.length===0&&t.directory){const i=(await qs.withDirectory(t.directory,()=>qs.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let o=i.length-1;o>=0;o-=1){const l=i[o];if(l.info?.role==="assistant")return fl(l.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const i=n[r];if(i.role==="assistant")return fl(Ph(i.id,e)).trim()}return""};function n2({session:t,open:e,onOpenChange:n}){const{t:r}=Nt(),i=Ah(),o=Ps(k=>k.activeSessions),l=Ps(k=>k.archivedSessions),a=Ht(k=>k.providers),u=Ht(k=>k.currentProviderId),d=Ht(k=>k.currentModelId),h=Ht(k=>k.currentAgentName),[f,p]=c.useState(u??""),[g,w]=c.useState(d??""),[v,x]=c.useState(()=>u&&d?[{providerID:u,modelID:d,instanceId:$r()}]:[]),[m,b]=c.useState(""),[y,S]=c.useState(h??""),[N,C]=c.useState([]),[j,A]=c.useState(!1),D=c.useMemo(()=>Ao(t.title),[t.title]),I=c.useMemo(()=>{const k=new Map;for(const P of i)k.set(P.id,P);for(const P of o)k.set(P.id,P);for(const P of l)k.set(P.id,P);return t.id&&k.set(t.id,t),Array.from(k.values())},[o,l,i,t]);c.useEffect(()=>{if(!e||!D)return;const k=et.getState().getDirectoryForSession(t.id),P=Ac(t.id,k),F=I.map(q=>{const Q=Ao(q.title);if(!Q||Q.groupSlug!==D.groupSlug||Q.fusion||(Q.runGroup??null)!==(D.runGroup??null))return null;const Y=et.getState().getDirectoryForSession(q.id)??$s(q),ce=Ac(q.id,Y);return P&&ce&&P!==ce?null:{session:q,directory:Y,projectDirectory:ce}}).filter(q=>q!==null).sort((q,Q)=>(q.session.time?.created??0)-(Q.session.time?.created??0));C(F)},[I,e,D,t.id]);const $=a.find(k=>k.id===f)?.models.find(k=>k.id===g),E=$?.variants?Object.keys($.variants):[],K=!!(D&&f&&g&&N.length>0&&!j),B=c.useCallback(k=>{x([k]),p(k.providerID),w(k.modelID),b("")},[]),O=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),T=async()=>{if(!(!D||!f||!g)){A(!0);try{const k=await Promise.all(N.map(X=>s2(X))),P=N.map((X,oe)=>({source:X,text:k[oe]??""})).filter(X=>X.text.trim().length>0);if(P.length===0){Re.error(r("multirun.fusion.toast.noOutputs"));return}const F=N[0]?.projectDirectory??N[0]?.directory??null,q=$j(D.groupSlug,f,g,D.runGroup),[Q,Y]=await Promise.all([ml("session.fusion.visible"),ml("session.fusion.instructions")]),ce=await et.getState().createSession(q,F,null);if(!ce)throw new Error("Failed to create fusion session");et.getState().setCurrentSession(ce.id,F),n(!1),await qs.sendMessage({id:ce.id,providerID:f,modelID:g,variant:m||void 0,agent:y||void 0,text:Q,additionalParts:[{text:Y,synthetic:!0},...P.map((X,oe)=>({text:t2(X.source,X.text,oe),synthetic:!0})),{text:`
|
|
919
|
+
|
|
920
|
+
--- FUSION INPUTS END ---
|
|
921
|
+
Now write the final fused answer.`,synthetic:!0}],directory:F??qs.getDirectory()})}catch(k){console.error("[MultiRunFusion] Failed to start fusion",k),Re.error(r("multirun.fusion.toast.failed"))}finally{A(!1)}}};return s.jsx(ws,{open:e,onOpenChange:n,children:s.jsxs(Ss,{className:"max-w-xl overflow-visible",children:[s.jsxs(Ws,{children:[s.jsx(Is,{children:r("multirun.fusion.title")}),s.jsx(Ts,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx(wm,{selectedModels:v,onAdd:B,onUpdate:(k,P)=>B(P),onRemove:()=>{x([]),p(""),w(""),b("")},maxModels:1,addButtonLabel:O,showChips:!1,addButtonClassName:"w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:f?s.jsx(Fi,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),E.length>0?s.jsxs(Bs,{value:m||"__default__",onValueChange:k=>b(k==="__default__"?"":k),children:[s.jsxs(Fs,{size:"lg",className:"w-fit",children:[s.jsx(R,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Cs,{children:k=>k==="__default__"?r("multirun.modelMultiSelect.variant.default"):k})]}),s.jsxs(_s,{fitContent:!0,portalToBody:!0,children:[s.jsx(ts,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),E.map(k=>s.jsx(ts,{value:k,children:k},k))]})]}):null,s.jsx(ym,{value:y,onChange:S,portalToBody:!0})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:N.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:N.map(k=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(Fi,{providerId:Ao(k.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:k.session.title||k.session.id}),s.jsx("button",{type:"button",onClick:()=>C(P=>P.filter(F=>F.session.id!==k.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"h-4 w-4"})})]},k.session.id))})]}),s.jsxs(bn,{children:[s.jsx(bt,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(bt,{onClick:T,disabled:!K,children:r(j?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function r2(t){const e=nt.c(7);let n,r,i,o,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),i=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),o=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),l=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=i,e[3]=o,e[4]=l):(n=e[0],r=e[1],i=e[2],o=e[3],l=e[4]);let a;return e[5]!==t?(a=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,i,o,l]}),e[5]=t,e[6]=a):a=e[6],a}const o2=(t,e)=>(t.current.runtimeKey!==e||(t.current={...t.current,revision:t.current.revision+1}),t.current.revision),Sm=t=>new Map([...t.entries()].map(([e,n])=>[e,n.map(r=>Xr(r))])),ua=t=>((t.rawWorktreesByProjectRef.current.runtimeKey!==t.runtimeKey||t.rawWorktreesByProjectRef.current.worktreesByProject.size===0&&t.publishedWorktreesByProject.size>0)&&(t.rawWorktreesByProjectRef.current={runtimeKey:t.runtimeKey,revision:t.rawWorktreesByProjectRef.current.runtimeKey===t.runtimeKey?t.rawWorktreesByProjectRef.current.revision:0,worktreesByProject:Sm(t.publishedWorktreesByProject)}),t.rawWorktreesByProjectRef.current),vm=(t,e)=>{const n=t.metadata.branch||t.metadata.name||t.metadata.label||t.metadata.path,r=e.metadata.branch||e.metadata.name||e.metadata.label||e.metadata.path,i=n.localeCompare(r,void 0,{sensitivity:"base"});return i!==0?i:t.metadata.path.localeCompare(e.metadata.path,void 0,{sensitivity:"base"})},Dc=t=>{const e=t.split("/").filter(Boolean);return e[e.length-1]??t},Xr=t=>({...t,path:wt(t.path)??t.path,projectDirectory:wt(t.projectDirectory)??t.projectDirectory,worktreeRoot:wt(t.worktreeRoot??t.path)??t.worktreeRoot}),Pc=t=>{const{currentWorktree:e,path:n,projectDirectory:r,projectRootBranch:i}=t,l=wt(e?.path??null)===n,a=l?e?.branch??"":i??"",u={path:n,projectDirectory:r,branch:a,label:l?e?.label||e?.branch||e?.name||Dc(n):i||Dc(n),name:l?e?.name:void 0,worktreeRoot:l?wt(e?.worktreeRoot??n)??n:n,worktreeStatus:l?e?.worktreeStatus??"ready":"ready",worktreeSource:l?e?.worktreeSource??"existing":"existing",headState:l?e?.headState:i?"branch":void 0};return l&&e?{...e,...u}:u},Ic=t=>{const e=wt(t.projectPath??null),n=wt(t.sourceDirectory??null)??wt(t.currentWorktree?.path??null),r=wt(t.discoveredWorktrees.find(h=>wt(h.projectDirectory??null))?.projectDirectory??null),i=wt(t.currentWorktree?.projectDirectory??null),o=r??i??e,l=new Map,a=h=>{const f=wt(h.metadata.path??null);!f||l.has(f)||l.set(f,{...h,metadata:Xr({...h.metadata,path:f})})};for(const h of t.discoveredWorktrees){const f=wt(h.path??null);f&&a({metadata:Xr({...h,path:f,projectDirectory:wt(h.projectDirectory??null)??o??e??f}),isPrimary:o===f,isCurrent:n===f})}o&&!l.has(o)&&a({metadata:Pc({path:o,projectDirectory:o,currentWorktree:t.currentWorktree,projectRootBranch:t.projectRootBranch}),isPrimary:!0,isCurrent:n===o}),n&&!l.has(n)&&a({metadata:Pc({path:n,projectDirectory:o??e??n,currentWorktree:t.currentWorktree,projectRootBranch:t.projectRootBranch}),isPrimary:o===n,isCurrent:!0});const u=[],d=[];for(const h of l.values()){if(h.isPrimary){u.push(h);continue}d.push(h)}return u.sort((h,f)=>h.metadata.path.localeCompare(f.metadata.path,void 0,{sensitivity:"base"})),d.sort(vm),[...u,...d]},i2=(t,e)=>{const n=e.getRuntimeKey(),r=e.getPublishedWorktreesByProject(),i=ua({rawWorktreesByProjectRef:e.rawWorktreesByProjectRef,publishedWorktreesByProject:r,runtimeKey:n}),l=(t.projectId?e.projects.find(d=>d.id===t.projectId)??null:null)??(t.sourceDirectory?e.resolveProject(t.sourceDirectory):null),a=wt(l?.path??null);return{cachedTargets:Ic({projectPath:a,discoveredWorktrees:a?i.worktreesByProject.get(a)??[]:[],sourceDirectory:t.sourceDirectory,currentWorktree:t.currentWorktree,projectRootBranch:e.projectRootBranch}),refreshTargets:(async()=>{if(!l||!a)throw new Error("Unable to resolve worktree project");const d=await e.listProjectWorktrees(l,{force:!0});if(e.getRuntimeKey()!==n)throw new Error("Runtime changed during worktree refresh");const h=e.getCurrentProjects(),f=h.find(S=>S.id===l.id)??null;if(!f||wt(f.path??null)!==a)throw new Error("Project removed during worktree refresh");const p=ua({rawWorktreesByProjectRef:e.rawWorktreesByProjectRef,publishedWorktreesByProject:e.getPublishedWorktreesByProject(),runtimeKey:n}),g=Sm(p.worktreesByProject),w=[...d].map(S=>Xr(S)).sort((S,N)=>vm({metadata:S},{metadata:N})),v=wt(w.find(S=>wt(S.projectDirectory??null))?.projectDirectory??t.currentWorktree?.projectDirectory??l.path),x=new Set([a]);for(const[S,N]of g.entries()){const C=wt(N.find(j=>wt(j.projectDirectory??null))?.projectDirectory??S);C&&C===v&&x.add(S)}for(const S of x){if(w.length===0){g.delete(S);continue}g.set(S,w.map(N=>Xr(N)))}o2(e.rawWorktreesByProjectRef,n),e.rawWorktreesByProjectRef.current={runtimeKey:n,revision:e.rawWorktreesByProjectRef.current.revision,worktreesByProject:g};const m=e.partitionWorktreesByRegisteredProject(h,g),b=[...m.values()].flat();e.recordWorktreesSeen(b.map(S=>S.path),e.now());const y=e.getPublishedWorktreesByProject();return e.worktreeMapsEqual(m,y)||e.publishTopology({availableWorktrees:b,availableWorktreesByProject:m}),Ic({projectPath:a,discoveredWorktrees:w,sourceDirectory:t.sourceDirectory,currentWorktree:t.currentWorktree,projectRootBranch:e.projectRootBranch})})()}},a2=t=>{if(t.rawWorktreesByProjectRef.current.runtimeKey!==t.runtimeKey)return!1;if(t.rawWorktreesByProjectRef.current.revision!==t.capturedRevision)return t.requestRediscovery(),!1;const e=t.partitionWorktreesByRegisteredProject(t.projects,t.nextRawWorktreesByProject),n=[...e.values()].flat();return t.recordWorktreesSeen(n.map(r=>r.path),t.now()),t.rawWorktreesByProjectRef.current={runtimeKey:t.runtimeKey,revision:t.capturedRevision,worktreesByProject:new Map(t.nextRawWorktreesByProject)},t.worktreeMapsEqual(e,t.publishedWorktreesByProject)||t.publishTopology({availableWorktrees:n,availableWorktreesByProject:e}),!0},l2=t=>({refreshState:t.isRefreshing?"loading":t.loadFailed&&t.targets.length===0?"error":null,showNewWorktreeAction:!0}),c2=(t,e)=>wt(t.worktree?.path??null)===wt(e.worktree?.path??null)&&t.worktree?.branch===e.worktree?.branch,ma=6,fo=14,Tc=ma+14+6,ji=new WeakMap,d2=t=>{const e=t.closest("[data-session-row]"),n=e?.closest(".overlay-scrollbar-container");if(!e||!n)return;ji.get(n)?.();const r=e.getBoundingClientRect().top;let i=3,o=!1,l=null;const a=()=>{o=!0,l!==null&&window.cancelAnimationFrame(l),l=null,ji.delete(n),n.removeEventListener("wheel",a),n.removeEventListener("touchstart",a)},u=()=>{if(o||!e.isConnected||!n.isConnected){a();return}const d=e.getBoundingClientRect().top-r;if(Math.abs(d)>.5&&(n.scrollTop+=d,Gs("ui.sidebar.selection_scroll_anchor_adjustment")),i-=1,i<=0){a();return}l=window.requestAnimationFrame(u)};n.addEventListener("wheel",a,{passive:!0}),n.addEventListener("touchstart",a,{passive:!0}),ji.set(n,a),l=window.requestAnimationFrame(u)},u2=c.memo(function(e){const n=nt.c(22),{archiveLabel:r,deleteLabel:i,buttonSizeClass:o,iconSizeClass:l,onPointerDown:a,onMouseDown:u,onArchive:d,onDelete:h}=e,f=Fj(),p=f?i:r;let g;n[0]!==d||n[1]!==h||n[2]!==f?(g=C=>{if(f||C.shiftKey){h(C);return}d(C)},n[0]=d,n[1]=h,n[2]=f,n[3]=g):g=n[3];const w=g,v=f?"text-destructive hover:text-destructive":"text-muted-foreground hover:text-foreground";let x;n[4]!==o||n[5]!==v?(x=Ie("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",v,o),n[4]=o,n[5]=v,n[6]=x):x=n[6];const m=f?"delete-bin":"archive";let b;n[7]!==l||n[8]!==m?(b=s.jsx(R,{name:m,className:l}),n[7]=l,n[8]=m,n[9]=b):b=n[9];let y;n[10]!==w||n[11]!==p||n[12]!==u||n[13]!==a||n[14]!==x||n[15]!==b?(y=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",className:x,"aria-label":p,onPointerDown:a,onMouseDown:u,onClick:w,onKeyDown:w2,children:b})}),n[10]=w,n[11]=p,n[12]=u,n[13]=a,n[14]=x,n[15]=b,n[16]=y):y=n[16];let S;n[17]!==p?(S=s.jsx(It,{side:"left",sideOffset:8,children:p}),n[17]=p,n[18]=S):S=n[18];let N;return n[19]!==y||n[20]!==S?(N=s.jsxs(Dt,{children:[y,S]}),n[19]=y,n[20]=S,n[21]=N):N=n[21],N});function m2(t){Gs("ui.sidebar_session_node.render");const{t:e}=Nt(),{node:n,depth:r=0,groupDirectory:i,projectId:o,archivedBucket:l=!1,pinnedSessionIds:a,expandedParents:u,hasSessionSearchQuery:d,normalizedSessionSearchQuery:h,notifyOnSubtasks:f,editingId:p,setEditingId:g,editTitle:w,setEditTitle:v,handleSaveEdit:x,handleCancelEdit:m,toggleParent:b,handleSessionSelect:y,handleSessionDoubleClick:S,handleShareSession:N,copiedSessionId:C,handleCopyShareUrl:j,handleCopySessionId:A,handleUnshareSession:D,openSidebarMenuKey:I,setOpenSidebarMenuKey:M,createFolderAndStartRename:$,handleDeleteSession:E,handleRestoreSession:K,startSessionWorktreeMenuLoad:B,mobileVariant:O,alwaysShowActions:T,secondaryMeta:k,renderContext:P="project",children:F}=t,q=zr(Ae=>Ae.toggle),Q=cs(Ae=>Ae.getFoldersForScope),Y=cs(Ae=>Ae.getSessionFolderId),ce=cs(Ae=>Ae.removeSessionFromFolder),X=cs(Ae=>Ae.addSessionToFolder),oe=Pe(Ae=>Ae.openContextPanelTab),te=c.useMemo(()=>Pn(),[]),he=c.useMemo(()=>Qo(),[]),_=c.useContext(Ih),ie=te?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",ge=te?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",ae=te,z=!l&&!O,ne=te?z&&ae?"group-hover:pr-18":z||ae?"group-hover:pr-14":"group-hover:pr-8":z?"group-hover:pr-7 group-focus-within:pr-7":"group-hover:pr-3 group-focus-within:pr-3",ue=z?"pr-13":"pr-7",me=te?z?"pr-18":"pr-14":z?"pr-7":"pr-3",ke=c.useRef(!1),[Te,je]=c.useState(!1),Ee=c.useRef(p);Ee.current=p;const xe=c.useRef(null),H=c.useRef(!1),Ce=c.useRef(x);Ce.current=x;const[ve,re]=c.useState(w),le=c.useRef(ve);le.current=ve;const se=c.useRef(null),G=c.useRef(!1),U=c.useRef(null),be=c.useRef(null),W=n.session,Ne=W,Oe=Vt(c.useCallback(Ae=>{if(k?.projectLabel||!o)return null;const Ot=Ae.projects.find(qt=>qt.id===o);return Ot?Ot.label?.trim()||Fn(wt(Ot.path)??Ot.path,null)||Ot.path:null},[o,k?.projectLabel])),ye=k?.projectLabel??(Oe?Ba(Oe):null),Fe=k?.branchLabel??n.worktree?.branch??null,Ke=c.useMemo(()=>{if(te)return null;const Ae=n.worktree?.branch?.trim(),Ot=wt(n.worktree?.path??null);return Ae&&Ot?Zo(Ot,Ae):null},[te,n.worktree]),$e=Hd(Ke),V=$e?`var(--pr-${$e.visualState})`:void 0,fe=ls(Ae=>Ae.sessionGroupingMode),Me=!!Fe&&(P==="recent"||fe==="flat"),De=c.useMemo(()=>{if(!$e)return null;switch($e.visualState){case"merged":return e("sessions.sidebar.group.pr.status.merged");case"open":return $e.canMerge===!0||$e.mergeableState==="clean"||$e.checks?.state==="success"?e("sessions.sidebar.group.pr.status.readyToMerge"):e("sessions.sidebar.group.pr.status.open");case"blocked":return $e.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked");case"draft":return e("sessions.sidebar.group.pr.status.draft");case"closed":return e("sessions.sidebar.group.pr.status.closed");default:return null}},[$e,e]),at=et(Ae=>Ae.currentSessionId===W.id),Qe=wt(W.directory??null)??wt(i??null),lt=o??Qe??null,de=Th(),J=Gd(),Se=te,Ve=hs(Ae=>Ae.enabled),He=hs(c.useCallback(Ae=>Ae.selectedIds.has(W.id),[W.id])),it=hs(Ae=>Ae.toggleSelected),Ue=hs(Ae=>Ae.setRange),st=c.useCallback(Ae=>{const Ot=[],qt=is=>{is.children.forEach(bs=>{Ot.push(bs.session.id),qt(bs)})};return qt(Ae),Ot},[]),ee=c.useCallback(Ae=>{const Ot=[],qt=is=>{is.children.forEach(bs=>{Ot.push(bs.session),qt(bs)})};return qt(Ae),Ot},[]),[ze,_e]=c.useState(!1),[pe,qe]=c.useState(!0),tt=`${P}:${l?"archived":"active"}:${W.id}`,pt=qd(c.useCallback(Ae=>!!Ae.sessionMemoryState.get(Eh(W.id))?.isZombie,[W.id])),Je=va(W.id)?.type??"idle",St=Je==="busy"||Je==="retry",Ze=Rh(W.id,St),vt=Eu(W.id),rt=n.worktree??et.getState().getWorktreeMetadata(W.id)??null,[we,ct]=c.useState([]),[dt,At]=c.useState(!1),[We,Xe]=c.useState(!1),Tt=c.useRef(!1),ut=c.useRef(0),kt=Mh(W.id,Qe??void 0,{bootstrap:!1}),Rt=Oh(Ne),ss=Rt?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center",title:e(hl[Rt.status]),"aria-label":e(hl[Rt.status]),children:s.jsx(R,{name:"target",className:"h-3 w-3",style:{color:Bh[Rt.status]}})}):null,Ut=Ne.title||e("sessions.sidebar.session.untitled"),Wt=n.children.length>0,Qt=Fh(a,Qe,W.id),Kt=tt,Ft=d?!0:u.has(Kt),$t=c.useMemo(()=>jj(n,Ft,Qe),[Ft,n,Qe]),Be=_h($t),Ye=!!Ne.parentID,yt=wd(W.id)>0&&(!Ye||f),ht=Ne.time?.updated||Ne.time?.created||Date.now(),mt=Qd(ht),_t=Lh(ht),Jt=I===tt,[Yt,Ns]=c.useState(!1),Xt=Jt||Yt,zs=c.useMemo(()=>Ao(Ne.title)!==null,[Ne.title]),[Js,rs]=c.useState(!1),Vs=c.useMemo(()=>st(n).length,[st,n]),Es=c.useCallback(async Ae=>{const Ot=[];let qt=0;for(const is of Ae)try{if(!Qe)throw new Error("Session directory is required for export");const bs=await de({directory:Qe,sessionID:is.session.id});if(!bs)throw new Error("Session runtime changed during export");const ms=is.session.title||e("sessions.sidebar.session.export.untitledSubagent"),tn=is.session.agent,Zt=await Es(is.children);qt+=Zt.skipped,Ot.push({title:ms,agent:tn,records:bs,children:Zt.children})}catch{qt+=st(is).length+1}return{children:Ot,skipped:qt}},[st,de,Qe,e]),ln=c.useCallback(Ae=>{Ae<=0||Re.warning(Ae===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:Ae}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:Ae}))},[e]),gs=c.useCallback(async Ae=>{if(!Qe){Re.error(e("sessions.sidebar.session.export.nothingToExport"));return}const Ot=await de({directory:Qe,sessionID:W.id}).catch(()=>null);if(!Ot){Re.error(e("sessions.sidebar.session.export.failedLoadHistory"));return}if(Ot.length===0){Re.error(e("sessions.sidebar.session.export.nothingToExport"));return}let qt,is=0;if(Ae&&n.children.length>0){const Zt=await Es(n.children);qt=Zt.children,is=Zt.skipped}const bs=Du(Ot,Ne.title??null,qt),ms=Tu(Ne.title??null),tn=await Iu(bs,ms);if(tn){Re.success(e("sessions.sidebar.session.export.success"),{action:{label:e(Jx()),onClick:()=>{Xx(tn).then(Zt=>{Zt||Re.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),ln(is);return}Pu(bs,ms),Re.success(e("sessions.sidebar.session.export.success")),ln(is)},[Es,de,n.children,Ne.title,W.id,Qe,ln,e]),vs=c.useCallback(async()=>{if(n.children.length>0){qe(!0),_e(!0);return}await gs(!1)},[gs,n.children.length]),Zs=c.useCallback(()=>{Qe&&Mn("desktop_open_session_mini_chat_window",{sessionId:W.id,directory:Qe,apiBaseUrl:An(),clientToken:Wr()}).catch(Ae=>{console.warn("[session-sidebar] failed to open mini chat window",Ae)})},[W.id,Qe]);if(c.useEffect(()=>{if(p!==W.id)return;const Ae=Ot=>{const is=(Ot.target instanceof HTMLElement?Ot.target:null)?.closest?.(`[data-session-rename-form="${CSS.escape(W.id)}"]`);be.current&&!is&&Ce.current(le.current)};return document.addEventListener("mousedown",Ae),()=>document.removeEventListener("mousedown",Ae)},[p,W.id]),c.useLayoutEffect(()=>{if(p!==W.id){se.current===W.id&&(se.current=null);return}se.current!==W.id&&(se.current=W.id,G.current=!0,re(w))},[p,w,W.id]),c.useLayoutEffect(()=>{if(p!==W.id||!G.current)return;const Ae=U.current;!Ae||Ae.value!==w||(G.current=!1,Ae.focus(),Ae.select())},[p,w,ve,W.id]),p===W.id)return s.jsx("div",{style:{paddingLeft:Tc+r*fo},className:"group relative my-0.5 flex items-center rounded-sm py-1 pr-1.5",children:s.jsx("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:s.jsxs("form",{ref:be,"data-session-rename-form":W.id,className:"flex w-full items-center gap-2",onSubmit:Ae=>{Ae.preventDefault(),x(ve)},children:[s.jsx("input",{ref:U,value:ve,onChange:Ae=>re(Ae.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:Ae=>{if(Ae.stopPropagation(),Ae.key==="Escape"){m();return}}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:m,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"size-4"})})]})})},W.id);const Rs=kt.length,As=Be===1?e("sessions.sidebar.session.status.questionPendingSingle"):e("sessions.sidebar.session.status.questionPendingMany",{count:Be}),Ds=Dj({actionsAlwaysVisible:T&&!te,menuOpen:Xt,hideOnHoverClass:ge}),js=!vt&&!St&&yt&&!at,Mt=St||js,Lt=e(St?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),ns=s.jsx("span",{className:Ie("h-1.5 w-1.5 rounded-full",St?"bg-primary":"bg-[var(--status-info)]"),"aria-label":Lt,title:Lt}),us=(St||js)&&Ze,xs=!T&&Wt&&(vt||Mt||Qt),Z=Qt&&!vt&&!Mt,Ge=s.jsx(R,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}),L=vt||Mt||Z?s.jsx("span",{style:{left:ma+r*fo},className:Ie("pointer-events-none absolute top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center transition-opacity",xs?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:vt?s.jsx(R,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":e("sessions.sidebar.session.status.movingToWorktree")}):Mt?ns:Z?Ge:null}):null,Le=Wt&&!T&&(vt||Mt||Qt),ot=Wt?s.jsx("span",{role:"button",tabIndex:0,onClick:Ae=>{Ae.stopPropagation(),Ae.currentTarget.blur(),b(Kt)},onKeyDown:Ae=>{(Ae.key==="Enter"||Ae.key===" ")&&(Ae.preventDefault(),Ae.stopPropagation(),b(Kt))},style:{minWidth:14,minHeight:14,left:ma+r*fo},className:Ie("absolute top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",Le?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(Ft?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Ft?s.jsx(R,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(R,{name:"arrow-right-s",className:"h-3 w-3"})}):null,jt=pt?s.jsx(R,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Ct=Ae=>{Ae&&Ns(!1),M(Ae?tt:null)},Bt=Ae=>{if(!Ae&&xe.current){const{id:Ot,title:qt}=xe.current;xe.current=null,g(Ot),v(qt)}},os=Ae=>{Ns(Ae)},Gt=Ae=>{Ae.preventDefault(),Ae.stopPropagation(),M(Jt?null:tt)},en=Ae=>{Ae.preventDefault(),Ae.stopPropagation()},Sn=Ae=>{Ae.preventDefault(),Ae.stopPropagation()},ai=Ae=>{Ae.preventDefault(),Ae.stopPropagation()},sr=Ae=>{Ae.preventDefault(),Ae.stopPropagation()},Fm=Ae=>{Ae.preventDefault(),Ae.stopPropagation(),M(null),E(W,{archivedBucket:l})},_m=Ae=>{Ae.preventDefault(),Ae.stopPropagation(),M(null),E(W,{archivedBucket:l,hardDelete:!0,skipConfirm:!0})},Lm=Ae=>{Ae.preventDefault(),Ae.stopPropagation()},$m=Ae=>{Ae.preventDefault(),Ae.stopPropagation()},Wm=Ae=>{Ae.preventDefault(),Ae.stopPropagation(),_?.vscode?.executeCommand("openchamber.openSessionInEditor",W.id,Ut)},Ya=Ae=>{if(ke.current){ke.current=!1;return}if(Ve){if(Ae?.preventDefault(),Ae?.stopPropagation(),Ae?.shiftKey){const qt=Array.from(document.querySelectorAll("[data-session-row]")).map(ms=>ms.getAttribute("data-session-row")).filter(ms=>ms!==null&&ms.length>0),is=hs.getState().anchorId,bs=new Map;bs.set(W.id,st(n)),Ue(is,W.id,qt,lt,bs);return}it(W.id,lt,st(n));return}Ae?.currentTarget&&d2(Ae.currentTarget),y(W.id,Qe)},zm=Ae=>{Ae.defaultPrevented||(Ae.target instanceof HTMLElement?Ae.target:null)?.closest('button, a, input, [role="menuitem"], [role="menu"]')||Ya(Ae)},Vm=Ae=>{(Ae.button===2||Ae.button===0&&Ae.ctrlKey&&!Ve)&&(ke.current=!0)},Um=Ae=>{O&&Ae.pointerType==="touch"&&je(!0),Ae.button===0&&!at&&!Ve&&!Se&&Qe&&!Oi(W.id,Qe).renderable&&J({directory:Qe,sessionID:W.id}).catch(()=>{})},Xa=Ae=>{O&&Ae.pointerType==="touch"&&je(!1)},Km=Ae=>{Tt.current=Ae,ut.current+=1;const Ot=ut.current;if(!Ae){At(!1),Xe(!1);return}const qt=B({projectId:o??null,sourceDirectory:Qe,currentWorktree:rt});ct(qt.cachedTargets),At(!0),Xe(!1),qt.refreshTargets.then(is=>{!Tt.current||ut.current!==Ot||(ct(is),At(!1),Xe(!1))}).catch(()=>{!Tt.current||ut.current!==Ot||(At(!1),Xe(!0))})},Ja=({Item:Ae,Separator:Ot,Sub:qt,SubTrigger:is,SubContent:bs})=>s.jsxs(s.Fragment,{children:[s.jsxs(Ae,{onClick:()=>{xe.current={id:W.id,title:Ut}},className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(Ae,{onClick:()=>A(W.id),className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyId")]}),s.jsxs(Ae,{onClick:()=>Qe&&q({directory:Qe,sessionId:W.id}),className:"[&>svg]:mr-1",children:[Qt?s.jsx(R,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(R,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(Qt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Ne.share?s.jsxs(s.Fragment,{children:[s.jsx(Ae,{onClick:()=>{Ne.share?.url&&j(Ne.share.url,W.id)},className:"[&>svg]:mr-1",children:C===W.id?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(Ae,{onClick:()=>D(W.id),className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Ae,{onClick:()=>N(Ne),className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(Ae,{onClick:()=>{vs()},className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),Sj({isSubtaskSession:Ye,archivedBucket:!!l,isVSCode:te,sessionDirectory:Qe})?(()=>{const ms=vj({sessionDirectory:Qe,isStreaming:St,isMovingToWorktree:vt}),tn=l2({targets:we,isRefreshing:dt,loadFailed:We});return s.jsxs(qt,{onOpenChange:Km,children:[s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs(is,{disabled:ms,className:"w-full [&>svg]:mr-1","data-session-worktree-submenu-trigger":W.id,children:[s.jsx(R,{name:"folder-shared",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.moveToWorktreeTargets")]})}),s.jsx(It,{side:"right",className:"max-w-72",children:e(vt?"sessions.sidebar.session.moveToWorktree.tooltipMoving":St?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltipTargets")})]}),s.jsxs(bs,{className:"min-w-[220px]","data-session-worktree-submenu":W.id,children:[we.map(Zt=>{const sn=wt(Zt.metadata.path??null)??Zt.metadata.path,kr=Zt.isPrimary?e("sessions.sidebar.session.moveToWorktree.main"):Zt.metadata.label||Zt.metadata.branch||Zt.metadata.name||Zt.metadata.path,fs=Zt.isCurrent||Zt.metadata.worktreeStatus!=="ready";return s.jsxs(Ae,{disabled:fs,title:Zt.metadata.path,"data-session-worktree-target":sn,onClick:()=>{fs||!Qe||Ji({kind:"existing",root:Ne,descendants:ee(n),sourceDirectory:Qe,destination:Zt.metadata,messages:Yi(e,{success:"sessions.sidebar.session.moveToWorktree.existingSuccess",failure:"sessions.sidebar.session.moveToWorktree.existingFailed"})})},children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1 truncate",children:[s.jsx("span",{className:"truncate",children:kr}),Zt.isCurrent?s.jsx("span",{className:"sr-only",children:e("sessions.sidebar.session.moveToWorktree.current")}):null]}),Zt.isCurrent?s.jsx(R,{name:"check",className:"ml-2 h-3.5 w-3.5 flex-shrink-0 text-primary","aria-hidden":"true"}):null]},sn)}),tn.refreshState==="loading"?s.jsx(Ae,{disabled:!0,"data-session-worktree-refresh-state":"loading",className:"py-0.5 text-muted-foreground typography-micro",children:e("sessions.sidebar.session.moveToWorktree.refreshing")}):null,tn.refreshState==="error"?s.jsx(Ae,{disabled:!0,"data-session-worktree-refresh-state":"error",className:"py-0.5 text-muted-foreground typography-micro",children:e("sessions.sidebar.session.moveToWorktree.loadFailed")}):null,s.jsx(Ot,{}),s.jsxs(Ae,{disabled:ms,"data-session-worktree-new-action":"true",onClick:()=>{ms||!Qe||Ji({kind:"quick",root:Ne,descendants:ee(n),sourceDirectory:Qe,messages:Yi(e,{success:"sessions.sidebar.session.moveToWorktree.success",failure:"sessions.sidebar.session.moveToWorktree.failed"})})},className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.newWorktree")]})]})]})})():null,zs?s.jsxs(Ae,{onClick:()=>rs(!0),className:"[&>svg]:mr-1",children:[s.jsx(r2,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Qe&&!l?(()=>{const ms=[],tn=fs=>{const ks=wt(fs??null);ks&&!ms.includes(ks)&&ms.push(ks)};if(o&&!te){const fs=Vt.getState().projects.find(nr=>nr.id===o),ks=wt(fs?.path??null);tn(ks),ks&&(et.getState().availableWorktreesByProject.get(ks)??[]).forEach(nr=>tn(nr.path))}tn(Yd(Qe)),tn(Qe);const Zt=ms.flatMap(fs=>Q(fs).map(ks=>({scope:fs,folder:ks}))),sn=Zt.find(({scope:fs,folder:ks})=>Y(fs,W.id)===ks.id)??null,kr=ms[0]??Qe;return s.jsxs(s.Fragment,{children:[s.jsx(Ot,{}),s.jsxs(qt,{children:[s.jsxs(is,{className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(bs,{className:"min-w-[180px]",children:[Zt.length===0?s.jsx(Ae,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Zt.map(({scope:fs,folder:ks})=>{const nr=sn?.folder.id===ks.id;return s.jsxs(Ae,{onClick:()=>{if(nr){ce(fs,W.id);return}sn&&sn.scope!==fs&&ce(sn.scope,W.id),X(fs,ks.id,W.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:ks.name}),nr?s.jsx(R,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},ks.id)}),s.jsx(Ot,{}),s.jsxs(Ae,{onClick:()=>{const fs=$(kr);fs&&(H.current=!0,sn&&sn.scope!==kr&&ce(sn.scope,W.id),X(kr,fs.id,W.id))},children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),sn?s.jsxs(Ae,{onClick:()=>{ce(sn.scope,W.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,te?null:s.jsxs(Ae,{disabled:!Qe,onClick:()=>{Qe&&oe(Qe,{mode:"chat",dedupeKey:`session:${W.id}`,label:Ut,sessionTitleFallback:Ut})},className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),he?s.jsxs(Ae,{disabled:!Qe,onClick:Zs,className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Ot,{}),l?null:s.jsxs(Ae,{className:"[&>svg]:mr-1",onClick:()=>E(W,{archivedBucket:l}),children:[s.jsx(R,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),l?s.jsxs(Ae,{className:"[&>svg]:mr-1",onClick:()=>K(W),children:[s.jsx(R,{name:"inbox-unarchive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.restore")]}):null,s.jsxs(Ae,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>E(W,{archivedBucket:l,hardDelete:!0}),children:[s.jsx(R,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),Hm=s.jsx(Ys,{align:"end",className:"min-w-[180px]",finalFocus:()=>H.current?(H.current=!1,!1):!Ee.current,children:Ja({Item:zt,Separator:Os,Sub:Wh,SubTrigger:zh,SubContent:Vh})}),Gm=s.jsx(Hi,{children:s.jsx(Gi,{className:"app-region-no-drag z-50",children:s.jsx(qi,{"data-slot":"dropdown-menu-content",finalFocus:()=>H.current?(H.current=!1,!1):!Ee.current,style:{color:"var(--surface-elevated-foreground)"},className:Ie(Pi,"min-w-[180px]"),children:Ja({Item:({className:Ae,...Ot})=>s.jsx(xu,{className:Ie(vd,Ae),...Ot}),Separator:({className:Ae,...Ot})=>s.jsx(gu,{className:Ie(Sd,Ae),...Ot}),Sub:Vg,SubTrigger:({className:Ae,children:Ot,...qt})=>s.jsxs(Ug,{className:Ie($h,Ae),...qt,children:[Ot,s.jsx(R,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:Ae,children:Ot,...qt})=>s.jsx(Hi,{children:s.jsx(Gi,{className:"app-region-no-drag z-50",children:s.jsx(qi,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:Ie(Pi,Ae),...qt,children:Ot})})})})})})});return s.jsxs(c.Fragment,{children:[s.jsx(bj,{sessionId:W.id,sessionDirectory:Qe??null,sessionTitle:Ut,children:s.jsxs(yu,{open:Yt,onOpenChange:os,onOpenChangeComplete:Bt,children:[s.jsxs(bu,{render:s.jsx("div",{"data-session-row":W.id,"data-session-scope":lt??"","data-session-archived":l?"1":"0","aria-current":at?"page":void 0,onClick:zm,style:{paddingLeft:Tc+r*fo},className:Ie("group relative my-0.5 flex cursor-pointer items-center rounded-md py-1 pr-1.5",at&&!He&&"bg-primary/10",He&&"bg-interactive-selection")}),children:[L,ot,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onPointerDown:Um,onPointerUp:Xa,onPointerCancel:Xa,onMouseDown:Vm,onClick:Ae=>Ya(Ae),onDoubleClick:Ae=>{Ae.stopPropagation(),S(W.id,Ut)},className:Ie("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none transition-[padding]",Te&&"bg-interactive-hover/70",T?te?ne:ue:Xt?me:ne),children:s.jsxs("div",{className:"flex w-full items-center min-w-0 flex-1 gap-1 overflow-hidden",children:[s.jsx("div",{className:Ie("block min-w-0 flex-1 truncate typography-ui-label font-normal",at?"text-primary":yt?"text-foreground":"text-foreground/80"),children:wo(Ut,h)}),!l&&Qe&&(P==="recent"||fe==="flat"&&n.worktree&&wt(n.worktree.path)!==wt(n.worktree.projectDirectory))?s.jsx(Qr,{directory:Qe,className:T?void 0:Xt?"mr-1":te?"group-hover:mr-1":"group-hover:mr-1 group-focus-within:mr-1"}):null,T?s.jsx("span",{className:"ml-2 inline-flex flex-shrink-0 items-center gap-1 typography-micro text-muted-foreground/75",children:us?s.jsx(Dl,{sessionId:W.id,running:St}):s.jsxs(s.Fragment,{children:[ss,Me?s.jsx(R,{name:"git-branch",className:Ie("h-3 w-3",!V&&"text-muted-foreground/60"),style:V?{color:V}:void 0}):null,_t]})}):us||ss||Me||P==="recent"?s.jsx("div",{className:Ie("relative ml-1 flex h-4 flex-shrink-0 items-center justify-end",Xt?"hidden":te?"group-hover:hidden":"group-hover:hidden group-focus-within:hidden"),children:s.jsx("span",{className:"inline-flex items-center gap-1 whitespace-nowrap text-right",children:us?s.jsx(Dl,{sessionId:W.id,running:St,className:"typography-micro"}):s.jsxs(s.Fragment,{children:[ss,Me?s.jsx(R,{name:"git-branch",className:Ie("h-3 w-3",!V&&"text-muted-foreground/60"),style:V?{color:V}:void 0}):null,P==="recent"?s.jsx("span",{className:"flex-shrink-0 typography-micro leading-none text-muted-foreground/75 tabular-nums",children:_t}):null]})})}):null,Rs>0?s.jsxs("span",{className:Ie("inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",Ds),title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(R,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Rs})]}):null,Be>0?s.jsxs("span",{className:Ie("inline-flex items-center gap-1 rounded bg-status-info/10 px-1 py-0.5 text-[0.7rem] text-status-info flex-shrink-0",Ds),title:As,"aria-label":As,children:[s.jsx(R,{name:"question",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Be})]}):null]})})}),te?null:s.jsx(It,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex min-w-44 flex-col gap-1.5 text-left text-xs",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{className:"min-w-0 truncate font-medium text-foreground",children:Ut}),s.jsx("span",{className:"flex-shrink-0 text-muted-foreground",title:mt,children:_t})]}),ye?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(R,{name:"folder",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 truncate",children:ye})]}):null,Fe?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(R,{name:"git-branch",className:"h-3 w-3 flex-shrink-0",style:V?{color:V}:void 0}),s.jsx("span",{className:"min-w-0 truncate",children:Fe})]}):null,$e&&De?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(R,{name:"git-pull-request",className:"h-3 w-3 flex-shrink-0",style:V?{color:V}:void 0}),s.jsxs("span",{className:"min-w-0 truncate",style:V?{color:V}:void 0,children:["#",$e.number," · ",De]})]}):null]})})]})}),jt&&!O?s.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 z-10",children:jt}):null,s.jsxs("div",{className:Ie("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",Xt||T&&!te?"opacity-100":Ie("opacity-0",ie)),children:[z?s.jsx(u2,{archiveLabel:e("sessions.sidebar.bulkActions.archive"),deleteLabel:e("sessions.sidebar.bulkActions.delete"),buttonSizeClass:T?"h-6 w-6":"h-4 w-4",iconSizeClass:T?"h-3.5 w-3.5":"h-2.5 w-2.5",onPointerDown:ai,onMouseDown:sr,onArchive:Fm,onDelete:_m}):null,ae?s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",T?"h-6 w-6":"h-4 w-4"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:Lm,onMouseDown:$m,onClick:Wm,onKeyDown:Ae=>Ae.stopPropagation(),children:s.jsx(R,{name:"external-link",className:Ie(T?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),s.jsx(It,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(Xs,{open:Jt,onOpenChange:Ct,onOpenChangeComplete:Bt,children:[s.jsx(Qs,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",T?"h-6 w-6 opacity-100":Xt?"h-4 w-4 opacity-100":Ie("h-4 w-4 opacity-0",ie)),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:en,onMouseDown:Sn,onClick:Gt,onKeyDown:Ae=>Ae.stopPropagation(),children:s.jsx(R,{name:"more-2",className:Ie(T?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),Hm]})]})]}),Gm]})}),Wt&&Ft?F:null,s.jsx(ws,{open:ze,onOpenChange:_e,children:s.jsxs(Ss,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Ws,{children:[s.jsx(Is,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ts,{children:Vs===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Vs}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Vs})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:pe,onChange:Ae=>qe(Ae.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(bn,{children:[s.jsx(bt,{type:"button",onClick:()=>_e(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(bt,{type:"button",onClick:()=>{_e(!1),gs(pe)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),zs?s.jsx(n2,{session:Ne,open:Js,onOpenChange:rs}):null]},W.id)}const Ec=t=>wt(t.session.directory??null),f2=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),h2=t=>{if(!t.openSidebarMenuKey)return null;const e=t.archivedBucket?"archived":"active",n=`${t.renderContext??"project"}:${e}:`;return t.openSidebarMenuKey.startsWith(n)?t.openSidebarMenuKey.slice(n.length):null},Rc=t=>t.menuOpenSessionId??h2(t),ho=(t,e,n)=>e?n.has(t.node.session.id)?!0:Gn(t.node,e):!1,fa=(t,e,n,r,i)=>{if(t.session.id!==e.session.id)return!0;const o=i(t);if(n.has(o)!==r.has(o)||t.children.length!==e.children.length)return!0;for(let l=0;l<t.children.length;l+=1)if(fa(t.children[l],e.children[l],n,r,i))return!0;return!1},p2=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return fa(t.node,e.node,t.expandedParents,e.expandedParents,i=>`${t.renderContext??"project"}:${n}:${i.session.id}`)||fa(t.node,e.node,t.expandedParents,e.expandedParents,i=>`${e.renderContext??"project"}:${r}:${i.session.id}`)},g2=(t,e)=>t.id===e.id&&t.title===e.title&&t.directory===e.directory&&t.parentID===e.parentID&&t.share?.url===e.share?.url&&t.time?.created===e.time?.created&&t.time?.updated===e.time?.updated&&t.time?.archived===e.time?.archived,x2=(t,e)=>{if(t.node.session.id!==e.node.session.id||!g2(t.node.session,e.node.session)||!c2(t.node,e.node))return"node";if(t.depth!==e.depth)return"depth";if(t.groupDirectory!==e.groupDirectory)return"groupDirectory";if(t.projectId!==e.projectId)return"projectId";if(t.archivedBucket!==e.archivedBucket)return"archivedBucket";if((t.renderContext??"project")!==(e.renderContext??"project"))return"renderContext";if(t.mobileVariant!==e.mobileVariant)return"mobileVariant";if(t.alwaysShowActions!==e.alwaysShowActions)return"alwaysShowActions";if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery)return"hasSessionSearchQuery";if(t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery)return"normalizedSessionSearchQuery";if(t.notifyOnSubtasks!==e.notifyOnSubtasks)return"notifyOnSubtasks";if(t.nodeStructureKey!==e.nodeStructureKey)return"nodeStructureKey";if(t.relativeTimeTick!==e.relativeTimeTick)return"relativeTimeTick";if(Ec(t.node)!==Ec(e.node))return"nodeDirectory";if(!f2(t.secondaryMeta,e.secondaryMeta))return"secondaryMeta";if(t.pinnedSessionIds!==e.pinnedSessionIds&&xm(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,t.groupDirectory,e.groupDirectory))return"pinnedSessionIds";if(t.expandedParents!==e.expandedParents&&p2(t,e))return"expandedParents";if(t.editingId!==e.editingId&&(ho(t,t.editingId,t.subtreeContainsEditing)||ho(e,e.editingId,e.subtreeContainsEditing)))return"editingId";if(t.editTitle!==e.editTitle&&(ho(t,t.editingId,t.subtreeContainsEditing)||ho(e,e.editingId,e.subtreeContainsEditing)))return"editTitle";if(t.copiedSessionId!==e.copiedSessionId&&(Gn(t.node,t.copiedSessionId)||Gn(e.node,e.copiedSessionId)))return"copiedSessionId";if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const r=Rc(t),i=Rc(e);if(Gn(t.node,r)||Gn(e.node,i))return"openSidebarMenuKey"}return t.setEditingId===e.setEditingId&&t.setEditTitle===e.setEditTitle&&t.handleSaveEdit===e.handleSaveEdit&&t.handleCancelEdit===e.handleCancelEdit&&t.toggleParent===e.toggleParent&&t.handleSessionSelect===e.handleSessionSelect&&t.handleSessionDoubleClick===e.handleSessionDoubleClick&&t.handleShareSession===e.handleShareSession&&t.handleCopyShareUrl===e.handleCopyShareUrl&&t.handleCopySessionId===e.handleCopySessionId&&t.handleUnshareSession===e.handleUnshareSession&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.handleDeleteSession===e.handleDeleteSession&&t.handleRestoreSession===e.handleRestoreSession&&t.startSessionWorktreeMenuLoad===e.startSessionWorktreeMenuLoad&&t.children===e.children?null:"callbacks"},b2=(t,e)=>{const n=x2(t,e);return n===null?!0:(Gs(`ui.sidebar_session_node.props_changed.${n}`),!1)},y2=c.memo(m2,b2);function w2(t){return t.stopPropagation()}const S2=t=>{const{t:e}=Nt(),n=c.useRef(null),r=c.useRef(t.editingId),i=c.useRef(t.editTitle),o=c.useRef(t.deleteSessionConfirm);r.current=t.editingId,i.current=t.editTitle,o.current=t.deleteSessionConfirm;const l=Pe(oe=>oe.setSessionSwitcherOpen),a=et(oe=>oe.setCurrentSession),u=et(oe=>oe.updateSessionTitle),d=et(oe=>oe.shareSession),h=et(oe=>oe.unshareSession),f=et(oe=>oe.deleteSession),p=et(oe=>oe.deleteSessions),g=et(oe=>oe.archiveSession),w=et(oe=>oe.archiveSessions),v=et(oe=>oe.unarchiveSession),{mobileVariant:x,allowReselect:m,onSessionSelected:b,isSessionSearchOpen:y,sessionSearchQuery:S,setSessionSearchQuery:N,setIsSessionSearchOpen:C,descendantIds:j,showDeletionDialog:A,setDeleteSessionConfirm:D,setEditingId:I,setEditTitle:M,setCopiedSessionId:$}=t;c.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]);const E=c.useCallback((oe,te)=>{Di("navigation.session_select"),Pe.getState().closeMainSurfaces();const he=()=>{!y&&S.length===0||(N(""),C(!1))};if(x&&l(!1),oe===et.getState().currentSessionId){m&&b?.(oe),he();return}Di("navigation.session_state_set"),a(oe,te??null),b?.(oe),he()},[m,y,x,b,S,a,C,N,l]),K=c.useCallback((oe,te)=>{I(oe),M(te)},[M,I]),B=c.useCallback(async oe=>{const te=r.current;if(!te)return;const he=(oe??i.current).trim();he&&await u(te,he),I(null),M("")},[M,I,u]),O=c.useCallback(()=>{I(null),M("")},[M,I]),T=c.useCallback(async(oe,te)=>{try{return(await pn(oe)).ok?($(te),n.current&&clearTimeout(n.current),n.current=window.setTimeout(()=>{$(null),n.current=null},2e3),!0):!1}catch{return!1}},[$]),k=c.useCallback(async oe=>{const te=await d(oe.id);if(!te?.share?.url){Re.error(e("sessions.sidebar.session.share.error"));return}const he=await T(te.share.url,oe.id);Re[he?"success":"warning"](e("sessions.sidebar.session.share.successTitle"),{description:e(he?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")})},[T,d,e]),P=c.useCallback((oe,te)=>{T(oe,te).then(he=>{he||Re.error(e("sessions.sidebar.session.share.copyUrlError"))})},[T,e]),F=c.useCallback(oe=>{pn(oe).then(te=>{if(te.ok){Re.success(e("sessions.sidebar.session.copyId.success"));return}Re.error(e("sessions.sidebar.session.copyId.error"))}).catch(()=>Re.error(e("sessions.sidebar.session.copyId.error")))},[e]),q=c.useCallback(async oe=>{await h(oe)?Re.success(e("sessions.sidebar.session.unshare.success")):Re.error(e("sessions.sidebar.session.unshare.error"))},[e,h]),Q=c.useCallback(async(oe,te,he)=>{const _=te?.archivedBucket===!0||te?.hardDelete===!0,ie=he?.descendantIds??j;if(ie.length===0){(_?await f(oe.id):await g(oe.id))?Re.success(e(_?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):Re.error(e(_?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const ge=[oe.id,...ie];if(_){const{deletedIds:ne,failedIds:ue}=await p(ge);if(ue.length===0){const me=ne.length;Re.success(me===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:me}):e("sessions.sidebar.bulkActions.deletedPlural",{count:me}))}else Re.error(e("sessions.sidebar.session.delete.error"));return}const{archivedIds:ae,failedIds:z}=await w(ge);ae.length>0&&Re.success(ae.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:ae.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:ae.length})),z.length>0&&Re.error(z.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:z.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:z.length}))},[g,w,f,p,j,e]),Y=c.useCallback((oe,te)=>{const he=te?.archivedBucket===!0||te?.hardDelete===!0,_=[...j];if(!A||te?.skipConfirm===!0){Q(oe,te,{descendantIds:_});return}D({session:oe,descendantCount:_.length,descendantIds:_,archivedBucket:he})},[j,Q,D,A]),ce=c.useCallback(async()=>{const oe=o.current;if(!oe)return;const{session:te,archivedBucket:he,descendantIds:_}=oe;D(null),await Q(te,{archivedBucket:he},{descendantIds:_})},[Q,D]),X=c.useCallback(async oe=>{await v(oe.id)?Re.success(e("sessions.sidebar.session.restore.success")):Re.error(e("sessions.sidebar.session.restore.error"))},[e,v]);return c.useMemo(()=>({handleSessionSelect:E,handleSessionDoubleClick:K,handleSaveEdit:B,handleCancelEdit:O,handleShareSession:k,handleCopyShareUrl:P,handleCopySessionId:F,handleUnshareSession:q,handleDeleteSession:Y,handleRestoreSession:X,confirmDeleteSession:ce}),[O,F,P,Y,X,B,K,E,k,q,ce])};function v2(t){const e=nt.c(71),{t:n}=Nt(),{value:r,setValue:i,showDeletionDialog:o,setShowDeletionDialog:l,onConfirm:a}=t;let u,d,h,f,p,g,w,v,x,m;if(e[0]!==i||e[1]!==n||e[2]!==r){const P=n("sessions.sidebar.session.untitled");f=ws,x=!!r,e[13]!==i?(m=q=>{q||i(null)},e[13]=i,e[14]=m):m=e[14],h=Ss,w=!1,v="max-w-sm gap-5",d=Ws;let F;e[15]!==n||e[16]!==r?.archivedBucket?(F=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=F):F=e[17],e[18]!==F?(g=s.jsx(Is,{children:F}),e[18]=F,e[19]=g):g=e[19],u=Ts,p=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||P,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||P,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||P,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||P,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||P}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||P}),e[0]=i,e[1]=n,e[2]=r,e[3]=u,e[4]=d,e[5]=h,e[6]=f,e[7]=p,e[8]=g,e[9]=w,e[10]=v,e[11]=x,e[12]=m}else u=e[3],d=e[4],h=e[5],f=e[6],p=e[7],g=e[8],w=e[9],v=e[10],x=e[11],m=e[12];let b;e[20]!==u||e[21]!==p?(b=s.jsx(u,{children:p}),e[20]=u,e[21]=p,e[22]=b):b=e[22];let y;e[23]!==d||e[24]!==g||e[25]!==b?(y=s.jsxs(d,{children:[g,b]}),e[23]=d,e[24]=g,e[25]=b,e[26]=y):y=e[26];let S;e[27]!==l||e[28]!==o?(S=()=>l(!o),e[27]=l,e[28]=o,e[29]=S):S=e[29];const N=!o;let C;e[30]!==o?(C=o?s.jsx(R,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(R,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=o,e[31]=C):C=e[31];let j;e[32]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=j):j=e[33];let A;e[34]!==C||e[35]!==j||e[36]!==S||e[37]!==N?(A=s.jsxs("button",{type:"button",onClick:S,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":N,children:[C,j]}),e[34]=C,e[35]=j,e[36]=S,e[37]=N,e[38]=A):A=e[38];let D;e[39]!==i?(D=()=>i(null),e[39]=i,e[40]=D):D=e[40];let I;e[41]!==n?(I=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=I):I=e[42];let M;e[43]!==D||e[44]!==I?(M=s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:I}),e[43]=D,e[44]=I,e[45]=M):M=e[45];let $;e[46]!==a?($=()=>{a()},e[46]=a,e[47]=$):$=e[47];let E;e[48]!==n||e[49]!==r?.archivedBucket?(E=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=E):E=e[50];let K;e[51]!==$||e[52]!==E?(K=s.jsx("button",{type:"button",onClick:$,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:E}),e[51]=$,e[52]=E,e[53]=K):K=e[53];let B;e[54]!==M||e[55]!==K?(B=s.jsxs("div",{className:"flex items-center gap-2",children:[M,K]}),e[54]=M,e[55]=K,e[56]=B):B=e[56];let O;e[57]!==A||e[58]!==B?(O=s.jsxs(bn,{className:"w-full sm:items-center sm:justify-between",children:[A,B]}),e[57]=A,e[58]=B,e[59]=O):O=e[59];let T;e[60]!==h||e[61]!==w||e[62]!==O||e[63]!==v||e[64]!==y?(T=s.jsxs(h,{showCloseButton:w,className:v,children:[y,O]}),e[60]=h,e[61]=w,e[62]=O,e[63]=v,e[64]=y,e[65]=T):T=e[65];let k;return e[66]!==f||e[67]!==T||e[68]!==x||e[69]!==m?(k=s.jsx(f,{open:x,onOpenChange:m,children:T}),e[66]=f,e[67]=T,e[68]=x,e[69]=m,e[70]=k):k=e[70],k}function j2(t){const e=nt.c(57),{t:n}=Nt(),{value:r,setValue:i,showDeletionDialog:o,setShowDeletionDialog:l,onConfirm:a}=t,u=r?.archivedBucket===!0,d=r?.sessionCount??0;let h;e[0]!==u||e[1]!==d||e[2]!==n?(h=n(u?d===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":d===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=u,e[1]=d,e[2]=n,e[3]=h):h=e[3];const f=h;let p;e[4]!==u||e[5]!==d||e[6]!==n?(p=u?d===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:d}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:d}):d===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:d}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:d}),e[4]=u,e[5]=d,e[6]=n,e[7]=p):p=e[7];const g=p,w=!!r;let v;e[8]!==i?(v=k=>{k||i(null)},e[8]=i,e[9]=v):v=e[9];let x;e[10]!==f?(x=s.jsx(Is,{children:f}),e[10]=f,e[11]=x):x=e[11];let m;e[12]!==g?(m=s.jsx(Ts,{children:g}),e[12]=g,e[13]=m):m=e[13];let b;e[14]!==x||e[15]!==m?(b=s.jsxs(Ws,{children:[x,m]}),e[14]=x,e[15]=m,e[16]=b):b=e[16];let y;e[17]!==l||e[18]!==o?(y=()=>l(!o),e[17]=l,e[18]=o,e[19]=y):y=e[19];const S=!o;let N;e[20]!==o?(N=o?s.jsx(R,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(R,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=o,e[21]=N):N=e[21];let C;e[22]!==n?(C=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=C):C=e[23];let j;e[24]!==C||e[25]!==y||e[26]!==S||e[27]!==N?(j=s.jsxs("button",{type:"button",onClick:y,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":S,children:[N,C]}),e[24]=C,e[25]=y,e[26]=S,e[27]=N,e[28]=j):j=e[28];let A;e[29]!==i?(A=()=>i(null),e[29]=i,e[30]=A):A=e[30];let D;e[31]!==n?(D=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=D):D=e[32];let I;e[33]!==A||e[34]!==D?(I=s.jsx("button",{type:"button",onClick:A,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:D}),e[33]=A,e[34]=D,e[35]=I):I=e[35];let M;e[36]!==a?(M=()=>{a()},e[36]=a,e[37]=M):M=e[37];let $;e[38]!==u||e[39]!==n?($=n(u?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=u,e[39]=n,e[40]=$):$=e[40];let E;e[41]!==M||e[42]!==$?(E=s.jsx("button",{type:"button",onClick:M,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:$}),e[41]=M,e[42]=$,e[43]=E):E=e[43];let K;e[44]!==I||e[45]!==E?(K=s.jsxs("div",{className:"flex items-center gap-2",children:[I,E]}),e[44]=I,e[45]=E,e[46]=K):K=e[46];let B;e[47]!==j||e[48]!==K?(B=s.jsxs(bn,{className:"w-full sm:items-center sm:justify-between",children:[j,K]}),e[47]=j,e[48]=K,e[49]=B):B=e[49];let O;e[50]!==B||e[51]!==b?(O=s.jsxs(Ss,{showCloseButton:!1,className:"max-w-sm gap-5",children:[b,B]}),e[50]=B,e[51]=b,e[52]=O):O=e[52];let T;return e[53]!==w||e[54]!==O||e[55]!==v?(T=s.jsx(ws,{open:w,onOpenChange:v,children:O}),e[53]=w,e[54]=O,e[55]=v,e[56]=T):T=e[56],T}function k2(t){const e=nt.c(36),{t:n}=Nt(),{value:r,setValue:i,onConfirm:o}=t,l=!!r;let a;e[0]!==i?(a=N=>{N||i(null)},e[0]=i,e[1]=a):a=e[1];let u;e[2]!==n?(u=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=u):u=e[3];let d;e[4]!==u?(d=s.jsx(Is,{children:u}),e[4]=u,e[5]=d):d=e[5];let h;e[6]!==n||e[7]!==r?(h=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=h):h=e[8];let f;e[9]!==h?(f=s.jsx(Ts,{children:h}),e[9]=h,e[10]=f):f=e[10];let p;e[11]!==d||e[12]!==f?(p=s.jsxs(Ws,{children:[d,f]}),e[11]=d,e[12]=f,e[13]=p):p=e[13];let g;e[14]!==i?(g=()=>i(null),e[14]=i,e[15]=g):g=e[15];let w;e[16]!==n?(w=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=w):w=e[17];let v;e[18]!==g||e[19]!==w?(v=s.jsx("button",{type:"button",onClick:g,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:w}),e[18]=g,e[19]=w,e[20]=v):v=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=x):x=e[22];let m;e[23]!==o||e[24]!==x?(m=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:x}),e[23]=o,e[24]=x,e[25]=m):m=e[25];let b;e[26]!==m||e[27]!==v?(b=s.jsxs(bn,{children:[v,m]}),e[26]=m,e[27]=v,e[28]=b):b=e[28];let y;e[29]!==b||e[30]!==p?(y=s.jsxs(Ss,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,b]}),e[29]=b,e[30]=p,e[31]=y):y=e[31];let S;return e[32]!==l||e[33]!==a||e[34]!==y?(S=s.jsx(ws,{open:l,onOpenChange:a,children:y}),e[32]=l,e[33]=a,e[34]=y,e[35]=S):S=e[35],S}const C2=new Set;function Ko(t){const e=nt.c(142),{node:n,depth:r,groupDirectory:i,projectId:o,archivedBucket:l,secondaryMeta:a,renderContext:u,renderExtras:d,pinnedSessionIds:h,expandedParents:f,hasSessionSearchQuery:p,normalizedSessionSearchQuery:g,notifyOnSubtasks:w,editingId:v,setEditingId:x,editTitle:m,setEditTitle:b,toggleParent:y,openSidebarMenuKey:S,setOpenSidebarMenuKey:N,allowReselect:C,onSessionSelected:j,isSessionSearchOpen:A,sessionSearchQuery:D,setSessionSearchQuery:I,setIsSessionSearchOpen:M,deleteSessionConfirm:$,setDeleteSessionConfirm:E,startFolderRename:K,copiedSessionId:B,setCopiedSessionId:O,startSessionWorktreeMenuLoad:T,mobileVariant:k,alwaysShowActions:P}=t,F=r===void 0?0:r,q=l===void 0?!1:l,Q=u===void 0?"project":u,Y=cs(P2),ce=cs(D2),X=Pe(A2),oe=Pe(N2);let te;if(e[0]!==n){te=[];const $e=V=>V.children.forEach(fe=>{te.push(fe.session.id),$e(fe)});$e(n),e[0]=n,e[1]=te}else te=e[1];const he=te.join(`
|
|
922
|
+
`);let _;e[2]!==he?(_=he?he.split(`
|
|
923
|
+
`):[],e[2]=he,e[3]=_):_=e[3];const ie=_;let ge;e[4]!==Y||e[5]!==K||e[6]!==ce?(ge=($e,V)=>{if(!$e)return null;V&&cs.getState().collapsedFolderIds.has(V)&&ce(V);const fe=Y($e,"New folder",V);return K($e,fe),fe},e[4]=Y,e[5]=K,e[6]=ce,e[7]=ge):ge=e[7];const ae=ge;let z;e[8]!==C||e[9]!==B||e[10]!==$||e[11]!==ie||e[12]!==m||e[13]!==v||e[14]!==A||e[15]!==k||e[16]!==j||e[17]!==D||e[18]!==O||e[19]!==E||e[20]!==b||e[21]!==x||e[22]!==M||e[23]!==I||e[24]!==X?(z={mobileVariant:k,allowReselect:C,onSessionSelected:j,isSessionSearchOpen:A,sessionSearchQuery:D,setSessionSearchQuery:I,setIsSessionSearchOpen:M,descendantIds:ie,showDeletionDialog:X,setDeleteSessionConfirm:E,deleteSessionConfirm:$,editingId:v,setEditingId:x,editTitle:m,setEditTitle:b,copiedSessionId:B,setCopiedSessionId:O},e[8]=C,e[9]=B,e[10]=$,e[11]=ie,e[12]=m,e[13]=v,e[14]=A,e[15]=k,e[16]=j,e[17]=D,e[18]=O,e[19]=E,e[20]=b,e[21]=x,e[22]=M,e[23]=I,e[24]=X,e[25]=z):z=e[25];const ne=S2(z),ue=d?.childRenderExtrasFor,me=n.session.directory??i;let ke;e[26]!==q||e[27]!==o||e[28]!==Q||e[29]!==me?(ke={groupDirectory:me,projectId:o,archivedBucket:q,renderContext:Q},e[26]=q,e[27]=o,e[28]=Q,e[29]=me,e[30]=ke):ke=e[30];const Te=ke,je=ne.handleSaveEdit,Ee=ne.handleCancelEdit,xe=ne.handleSessionSelect,H=ne.handleSessionDoubleClick,Ce=ne.handleShareSession,ve=ne.handleCopyShareUrl,re=ne.handleCopySessionId,le=ne.handleUnshareSession,se=ne.handleDeleteSession,G=ne.handleRestoreSession,U=d?.subtreeContainsEditing??C2,be=d?.menuOpenSessionId??null,W=d?.nodeStructureKey??"",Ne=d?.relativeTimeTick;let Oe;if(e[31]!==C||e[32]!==P||e[33]!==Te||e[34]!==ue||e[35]!==B||e[36]!==$||e[37]!==F||e[38]!==m||e[39]!==v||e[40]!==f||e[41]!==p||e[42]!==A||e[43]!==k||e[44]!==n.children||e[45]!==g||e[46]!==w||e[47]!==j||e[48]!==S||e[49]!==h||e[50]!==D||e[51]!==O||e[52]!==E||e[53]!==b||e[54]!==x||e[55]!==M||e[56]!==N||e[57]!==I||e[58]!==K||e[59]!==T||e[60]!==y){let $e;e[62]!==C||e[63]!==P||e[64]!==Te||e[65]!==ue||e[66]!==B||e[67]!==$||e[68]!==F||e[69]!==m||e[70]!==v||e[71]!==f||e[72]!==p||e[73]!==A||e[74]!==k||e[75]!==g||e[76]!==w||e[77]!==j||e[78]!==S||e[79]!==h||e[80]!==D||e[81]!==O||e[82]!==E||e[83]!==b||e[84]!==x||e[85]!==M||e[86]!==N||e[87]!==I||e[88]!==K||e[89]!==T||e[90]!==y?($e=V=>s.jsx(Ko,{node:V,pinnedSessionIds:h,expandedParents:f,hasSessionSearchQuery:p,normalizedSessionSearchQuery:g,notifyOnSubtasks:w,editingId:v,setEditingId:x,editTitle:m,copiedSessionId:B,setEditTitle:b,toggleParent:y,openSidebarMenuKey:S,setOpenSidebarMenuKey:N,allowReselect:C,onSessionSelected:j,isSessionSearchOpen:A,sessionSearchQuery:D,setSessionSearchQuery:I,setIsSessionSearchOpen:M,deleteSessionConfirm:$,setDeleteSessionConfirm:E,startFolderRename:K,setCopiedSessionId:O,startSessionWorktreeMenuLoad:T,mobileVariant:k,alwaysShowActions:P,depth:F+1,...Te,renderExtras:ue?.(V)},V.session.id),e[62]=C,e[63]=P,e[64]=Te,e[65]=ue,e[66]=B,e[67]=$,e[68]=F,e[69]=m,e[70]=v,e[71]=f,e[72]=p,e[73]=A,e[74]=k,e[75]=g,e[76]=w,e[77]=j,e[78]=S,e[79]=h,e[80]=D,e[81]=O,e[82]=E,e[83]=b,e[84]=x,e[85]=M,e[86]=N,e[87]=I,e[88]=K,e[89]=T,e[90]=y,e[91]=$e):$e=e[91],Oe=n.children.map($e),e[31]=C,e[32]=P,e[33]=Te,e[34]=ue,e[35]=B,e[36]=$,e[37]=F,e[38]=m,e[39]=v,e[40]=f,e[41]=p,e[42]=A,e[43]=k,e[44]=n.children,e[45]=g,e[46]=w,e[47]=j,e[48]=S,e[49]=h,e[50]=D,e[51]=O,e[52]=E,e[53]=b,e[54]=x,e[55]=M,e[56]=N,e[57]=I,e[58]=K,e[59]=T,e[60]=y,e[61]=Oe}else Oe=e[61];let ye;e[92]!==P||e[93]!==q||e[94]!==B||e[95]!==ae||e[96]!==F||e[97]!==m||e[98]!==v||e[99]!==f||e[100]!==i||e[101]!==p||e[102]!==k||e[103]!==n||e[104]!==g||e[105]!==w||e[106]!==S||e[107]!==h||e[108]!==o||e[109]!==Q||e[110]!==a||e[111]!==ne.handleCancelEdit||e[112]!==ne.handleCopySessionId||e[113]!==ne.handleCopyShareUrl||e[114]!==ne.handleDeleteSession||e[115]!==ne.handleRestoreSession||e[116]!==ne.handleSaveEdit||e[117]!==ne.handleSessionDoubleClick||e[118]!==ne.handleSessionSelect||e[119]!==ne.handleShareSession||e[120]!==ne.handleUnshareSession||e[121]!==b||e[122]!==x||e[123]!==N||e[124]!==T||e[125]!==U||e[126]!==be||e[127]!==W||e[128]!==Ne||e[129]!==Oe||e[130]!==y?(ye=s.jsx(y2,{expandedParents:f,hasSessionSearchQuery:p,normalizedSessionSearchQuery:g,notifyOnSubtasks:w,editingId:v,setEditingId:x,editTitle:m,setEditTitle:b,handleSaveEdit:je,handleCancelEdit:Ee,toggleParent:y,handleSessionSelect:xe,handleSessionDoubleClick:H,handleShareSession:Ce,copiedSessionId:B,handleCopyShareUrl:ve,handleCopySessionId:re,handleUnshareSession:le,openSidebarMenuKey:S,setOpenSidebarMenuKey:N,createFolderAndStartRename:ae,handleDeleteSession:se,handleRestoreSession:G,startSessionWorktreeMenuLoad:T,mobileVariant:k,alwaysShowActions:P,pinnedSessionIds:h,node:n,depth:F,groupDirectory:i,projectId:o,archivedBucket:q,secondaryMeta:a,renderContext:Q,subtreeContainsEditing:U,menuOpenSessionId:be,nodeStructureKey:W,relativeTimeTick:Ne,children:Oe}),e[92]=P,e[93]=q,e[94]=B,e[95]=ae,e[96]=F,e[97]=m,e[98]=v,e[99]=f,e[100]=i,e[101]=p,e[102]=k,e[103]=n,e[104]=g,e[105]=w,e[106]=S,e[107]=h,e[108]=o,e[109]=Q,e[110]=a,e[111]=ne.handleCancelEdit,e[112]=ne.handleCopySessionId,e[113]=ne.handleCopyShareUrl,e[114]=ne.handleDeleteSession,e[115]=ne.handleRestoreSession,e[116]=ne.handleSaveEdit,e[117]=ne.handleSessionDoubleClick,e[118]=ne.handleSessionSelect,e[119]=ne.handleShareSession,e[120]=ne.handleUnshareSession,e[121]=b,e[122]=x,e[123]=N,e[124]=T,e[125]=U,e[126]=be,e[127]=W,e[128]=Ne,e[129]=Oe,e[130]=y,e[131]=ye):ye=e[131];let Fe;e[132]!==$||e[133]!==n.session.id||e[134]!==ne.confirmDeleteSession||e[135]!==E||e[136]!==oe||e[137]!==X?(Fe=$?.session.id===n.session.id?s.jsx(v2,{value:$,setValue:E,showDeletionDialog:X,setShowDeletionDialog:oe,onConfirm:ne.confirmDeleteSession}):null,e[132]=$,e[133]=n.session.id,e[134]=ne.confirmDeleteSession,e[135]=E,e[136]=oe,e[137]=X,e[138]=Fe):Fe=e[138];let Ke;return e[139]!==ye||e[140]!==Fe?(Ke=s.jsxs(s.Fragment,{children:[ye,Fe]}),e[139]=ye,e[140]=Fe,e[141]=Ke):Ke=e[141],Ke}function N2(t){return t.setShowDeletionDialog}function A2(t){return t.showDeletionDialog}function D2(t){return t.toggleFolderCollapse}function P2(t){return t.createFolder}const I2=50,T2=28,Mc=[],E2=t=>{const e=nt.c(6),{nodes:n,includeUnreadSubtasks:r,children:i}=t;let o;e[0]!==r||e[1]!==n?(o={nodes:n,includeUnreadSubtasks:r},e[0]=r,e[1]=n,e[2]=o):o=e[2];const l=pm(o);let a;return e[3]!==i||e[4]!==l?(a=i(l),e[3]=i,e[4]=l,e[5]=a):a=e[5],a},Tr=(t,e)=>e?t.sessions.some(n=>Gn(n,e)):!1,R2=(t,e,n)=>t.sessions.some(r=>xm(r,r,e,n,t.directory,t.directory)),M2=(t,e,n)=>{const r=i=>{const o=i.session.id;return e.get(o)!==n.get(o)?!0:i.children.some(r)};return t.sessions.some(r)},O2=(t,e,n)=>{const r=t.isArchivedBucket?"archived":"active",i=o=>{const l=`project:${r}:${o.session.id}`;return e.has(l)!==n.has(l)?!0:o.children.some(i)};return t.sessions.some(i)},B2=(t,e)=>{if(t.group!==e.group||t.groupKey!==e.groupKey||t.projectId!==e.projectId||t.hideGroupLabel!==e.hideGroupLabel||t.compactBodyPadding!==e.compactBodyPadding||t.groupSearchDataByGroup!==e.groupSearchDataByGroup||t.visibleSessionCount!==e.visibleSessionCount||t.sessionBatchSize!==e.sessionBatchSize||t.collapsedGroups!==e.collapsedGroups&&t.collapsedGroups.has(t.groupKey)!==e.collapsedGroups.has(e.groupKey)||t.pinnedSessionIds!==e.pinnedSessionIds&&R2(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.sessionOrderIndex!==e.sessionOrderIndex&&M2(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.expandedParents!==e.expandedParents&&O2(e.group,t.expandedParents,e.expandedParents)||t.editingId!==e.editingId&&(Tr(e.group,t.editingId)||Tr(e.group,e.editingId))||t.editTitle!==e.editTitle&&Tr(e.group,e.editingId)||t.copiedSessionId!==e.copiedSessionId&&(Tr(e.group,t.copiedSessionId)||Tr(e.group,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=e.group.isArchivedBucket===!0,r=Yr(e.group.sessions,t.openSidebarMenuKey,"project",n),i=Yr(e.group.sessions,e.openSidebarMenuKey,"project",n);if(r||i)return!1}if(t.folderRename!==e.folderRename){const n=e.group.folderScopes?.map(r=>r.scopeKey)??[e.group.folderScopeKey??wt(e.group.directory??null)];if(n.includes(t.folderRename?.scopeKey??null)||n.includes(e.folderRename?.scopeKey??null))return!1}return t.hasSessionSearchQuery===e.hasSessionSearchQuery&&t.normalizedSessionSearchQuery===e.normalizedSessionSearchQuery&&t.hideDirectoryControls===e.hideDirectoryControls&&t.showMoreGroupSessions===e.showMoreGroupSessions&&t.resetGroupSessionLimit===e.resetGroupSessionLimit&&t.mobileVariant===e.mobileVariant&&t.alwaysShowActions===e.alwaysShowActions&&t.setActiveProjectIdOnly===e.setActiveProjectIdOnly&&t.setSessionSwitcherOpen===e.setSessionSwitcherOpen&&t.openNewSessionDraft===e.openNewSessionDraft&&t.onToggleCollapsedGroup===e.onToggleCollapsedGroup&&t.dragHandleProps===e.dragHandleProps&&t.scrollContainerRef===e.scrollContainerRef&&t.notifyOnSubtasks===e.notifyOnSubtasks&&t.setEditingId===e.setEditingId&&t.setEditTitle===e.setEditTitle&&t.toggleParent===e.toggleParent&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.allowReselect===e.allowReselect&&t.onSessionSelected===e.onSessionSelected&&t.isSessionSearchOpen===e.isSessionSearchOpen&&t.sessionSearchQuery===e.sessionSearchQuery&&t.setSessionSearchQuery===e.setSessionSearchQuery&&t.setIsSessionSearchOpen===e.setIsSessionSearchOpen&&t.deleteSessionConfirm===e.deleteSessionConfirm&&t.setDeleteSessionConfirm===e.setDeleteSessionConfirm&&t.startFolderRename===e.startFolderRename&&t.setCopiedSessionId===e.setCopiedSessionId&&t.startSessionWorktreeMenuLoad===e.startSessionWorktreeMenuLoad&&t.setFolderRenameDraft===e.setFolderRenameDraft&&t.clearFolderRename===e.clearFolderRename};function F2(t){const{t:e}=Nt(),{group:n,groupKey:r,projectId:i,hideGroupLabel:o,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,groupSearchDataByGroup:u,visibleSessionCount:d,sessionBatchSize:h,collapsedGroups:f,hideDirectoryControls:p,showMoreGroupSessions:g,resetGroupSessionLimit:w,mobileVariant:v,alwaysShowActions:x,activeProjectId:m,setActiveProjectIdOnly:b,setSessionSwitcherOpen:y,openNewSessionDraft:S,pinnedSessionIds:N,sessionOrderIndex:C,notifyOnSubtasks:j,onToggleCollapsedGroup:A,dragHandleProps:D,compactBodyPadding:I=!1,scrollContainerRef:M,expandedParents:$,editingId:E,openSidebarMenuKey:K,editTitle:B,copiedSessionId:O,folderRename:T,setFolderRenameDraft:k,clearFolderRename:P}=t,F=cs(Be=>Be.toggleFolderCollapse),q=cs(Be=>Be.renameFolder),Q=cs(Be=>Be.deleteFolder),Y=cs(Be=>Be.addSessionToFolder),ce=Pe(Be=>Be.showDeletionDialog),[X,oe]=c.useState(null),te=c.useCallback((Be,Ye)=>{const ft=C.get(Be.session.id),yt=C.get(Ye.session.id);if(ft!==void 0||yt!==void 0){if(ft===void 0)return 1;if(yt===void 0)return-1;if(ft!==yt)return ft-yt}return Xd(Be.session,Ye.session,N,Ld)},[N,C]),he=l?u.get(n):null,_=l?!1:f.has(r),ie=c.useMemo(()=>{if(n.isMain||n.isArchivedBucket||o)return null;const Be=wt(n.directory??null),Ye=n.branch?.trim();return Be&&Ye?Zo(Be,Ye):null},[n.branch,n.directory,n.isArchivedBucket,n.isMain,o]),ge=Hd(ie),ae=ge?`var(--pr-${ge.visualState})`:void 0,z=Fa(),ne=c.useMemo(()=>{const Be=n.folderScopes?.map(Ye=>wt(Ye.directory))??[wt(n.directory??null)];return[...new Set(Be.filter(Ye=>!!Ye))]},[n.directory,n.folderScopes]);c.useSyncExternalStore(c.useCallback(Be=>ne.length>0?z.subscribeBootstrap(Be):()=>{},[ne.length,z]),c.useCallback(()=>ne.map(Be=>`${Be}\0${z.getBootstrapState(Be)??""}\0${z.getBootstrapFailure(Be)??""}`).join(""),[ne,z]),c.useCallback(()=>"",[]));const ue=ne.some(Be=>{const Ye=z.getBootstrapState(Be);return Ye==="queued"||Ye==="running"}),me=ne.find(Be=>z.getBootstrapState(Be)==="failed")??null,ke=me?z.getBootstrapFailure(me):void 0,Te=ke==="os-permission"&&pf(),[je,Ee]=c.useState(!1),xe=c.useCallback(()=>{me&&z.requestBootstrap({directory:me,priority:_?"visible":"expanded",reason:n.isMain?"project-expanded":"worktree-expanded",force:!0})},[z,me,n.isMain,_]),H=c.useCallback(async()=>{if(!(!me||!Te||je)){Ee(!0);try{(await gf(me)).success&&xe()}finally{Ee(!1)}}},[Te,me,je,xe]),Ce=h??(p?10:5),ve=Math.max(Ce,d??Ce),re=l?he?.groupMatches===!0:!1,le=l,se=c.useMemo(()=>[...le?he?.filteredNodes??[]:n.sessions].sort(te),[te,n.sessions,he?.filteredNodes,le]),G=n.folderScopeKey??wt(n.directory??null),U=c.useMemo(()=>n.folderScopes&&n.folderScopes.length>0?n.folderScopes:G?[{scopeKey:G,directory:n.directory??null}]:[],[G,n.directory,n.folderScopes]),be=cs(Zn(c.useCallback(Be=>U.map(({scopeKey:Ye})=>Be.foldersMap[Ye]??Mc),[U]))),W=c.useMemo(()=>U.flatMap(({scopeKey:Be,directory:Ye},ft)=>(be[ft]??Mc).map(ht=>({folder:ht,scopeKey:Be,scopeDirectory:Ye}))),[be,U]),Ne=cs(Zn(c.useCallback(Be=>new Set(be.flatMap(Ye=>Ye.filter(ft=>Be.collapsedFolderIds.has(ft.id)).map(ft=>ft.id))),[be]))),Oe=c.useMemo(()=>{const Be=new Map,Ye=ft=>{ft.forEach(yt=>{Be.set(yt.session.id,yt),yt.children.length>0&&Ye(yt.children)})};return Ye(se),Be},[se]),ye=c.useMemo(()=>W.map(({folder:Be,scopeKey:Ye,scopeDirectory:ft})=>{const yt=kj(Be.sessionIds,Oe).sort(te);return{folder:Be,scopeKey:Ye,scopeDirectory:ft,nodes:yt}}),[W,Oe,te]),Fe=c.useMemo(()=>{const Be=Nj(ye.map(({folder:Ye,nodes:ft})=>({id:Ye.id,name:Ye.name,parentId:Ye.parentId,nodeCount:ft.length})),{archivedBucket:n.isArchivedBucket===!0,searchQuery:l?a:""});return ye.filter(({folder:Ye})=>Be.has(Ye.id))},[ye,n.isArchivedBucket,l,a]),Ke=E,$e=K,V=$,fe=c.useMemo(()=>new Set(Fe.flatMap(Be=>Be.folder.sessionIds)),[Fe]),Me=c.useMemo(()=>se.filter(Be=>!fe.has(Be.session.id)),[se,fe]),De=c.useMemo(()=>{const Be=new Map(Fe.map(Ye=>[Ye.folder.id,Ye]));return Cj(Fe.map(Ye=>Ye.folder)).map(Ye=>Be.get(Ye.id)).filter(Ye=>!!Ye)},[Fe]),at=c.useMemo(()=>{const Be=new Map;return Fe.forEach(Ye=>{if(!Ye.folder.parentId)return;const ft=Be.get(Ye.folder.parentId)??[];ft.push(Ye),Be.set(Ye.folder.parentId,ft)}),Be},[Fe]),Qe=c.useMemo(()=>{const Be=new Map(Fe.map(yt=>[yt.folder.id,yt])),Ye=new Map,ft=(yt,ht)=>{const mt=Ye.get(yt);if(mt!==void 0)return mt;if(ht.has(yt))return[];ht.add(yt);const _t=Be.get(yt),Jt=_t?[..._t.nodes]:[];for(const Yt of at.get(yt)??[])Jt.push(...ft(Yt.folder.id,ht));return Ye.set(yt,Jt),Jt};return Fe.forEach(({folder:yt})=>ft(yt.id,new Set)),Ye},[Fe,at]),lt="project",de=c.useMemo(()=>{const Be=new Set;return la(se,Ke,Be),Fe.forEach(({nodes:Ye})=>{la(Ye,Ke,Be)}),Be},[se,Fe,Ke]),J=c.useMemo(()=>{if(!$e)return null;const Be=Yr(se,$e,lt,!!n.isArchivedBucket);if(Be)return Be;for(const{nodes:Ye}of Fe){const ft=Yr(Ye,$e,lt,!!n.isArchivedBucket);if(ft)return ft}return null},[$e,se,Fe,n.isArchivedBucket]),Se=c.useCallback(Be=>{const Ye=new WeakMap,ft=yt=>{Ye.set(yt,Uo(yt));for(const ht of yt.children)ft(ht)};return Be.forEach(ft),Ye},[]),Ve=c.useMemo(()=>Se(se),[Se,se]),He=c.useMemo(()=>{const Be=new WeakMap;return Fe.forEach(({nodes:Ye})=>{Ye.forEach(ft=>Be.set(ft,Uo(ft)))}),Be},[Fe]),it=c.useCallback(Be=>Ve.get(Be)??He.get(Be)??"",[Ve,He]),Ue=c.useCallback(Be=>({subtreeContainsEditing:de,menuOpenSessionId:J,nodeStructureKey:it(Be)}),[de,J,it]),st=Me.length,ee=n.isArchivedBucket||l?Me:Me.slice(0,ve),ze=st-ee.length,_e=!n.isArchivedBucket&&!l&&st>Ce&&ze===0,pe=n.isArchivedBucket===!0&&!l&&ee.length>=I2,qe=n.isArchivedBucket?"archived":"active",tt=pe&&ee.some(Be=>{if(Be.children.length===0)return!1;const Ye=`project:${qe}:${Be.session.id}`;return V.has(Ye)}),pt=c.useRef(null),[gt,Je]=c.useState(null),[St,Ze]=c.useState(0),[,vt]=c.useState(0);c.useEffect(()=>{if(!pe)return;const Be=pt.current;if(!Be||!globalThis.ResizeObserver)return;const Ye=new ResizeObserver(()=>vt(ft=>ft+1));return Ye.observe(Be),()=>Ye.disconnect()},[pe]),c.useLayoutEffect(()=>{if(!pe){gt!==null&&Je(null),St!==0&&Ze(0);return}const Be=pt.current;if(!Be)return;let Ye=gt;const ft=M?.current??null;if(ft&&ft.contains(Be)){if(Ye=ft,Ye!==gt){Je(Ye);return}}else if(!Ye||!Ye.contains(Be)){let ht=Be.parentElement;for(;ht;){const mt=window.getComputedStyle(ht);if(mt.overflowY==="auto"||mt.overflowY==="scroll"){Ye=ht;break}ht=ht.parentElement}if(Ye!==gt){Je(Ye);return}}if(!Ye)return;const yt=Be.getBoundingClientRect().top-Ye.getBoundingClientRect().top+Ye.scrollTop;Ze(ht=>Math.abs(ht-yt)<1?ht:yt)});const rt=pe&>!==null,we=Zg({count:ee.length,enabled:rt,getScrollElement:()=>gt,initialOffset:()=>gt?.scrollTop??0,estimateSize:()=>T2,overscan:tt?20:8,scrollMargin:St,getItemKey:Be=>ee[Be]?.session.id??Be}),ct=c.useCallback(Be=>{const Ye=[],ft=yt=>{yt.forEach(ht=>{Ye.push(ht.session),ht.children.length>0&&ft(ht.children)})};return ft(Be),Ye},[]),dt=c.useMemo(()=>ct(se),[ct,se]),At=c.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const Be=new Map,Ye=new Map;for(const{folder:yt}of Fe){if(!yt.parentId)continue;const ht=Ye.get(yt.parentId)??[];ht.push(yt.id),Ye.set(yt.parentId,ht)}const ft=(yt,ht)=>{if(ht.has(yt))return[];ht.add(yt);const mt=Fe.find(({folder:Yt})=>Yt.id===yt),_t=mt?ct(mt.nodes):[],Jt=Ye.get(yt)??[];for(const Yt of Jt)_t.push(...ft(Yt,ht));return _t};for(const{folder:yt}of Fe)Be.set(yt.id,ft(yt.id,new Set));return Be},[Fe,ct,n.isArchivedBucket]);if(l&&!re&&De.length===0&&Me.length===0)return null;const We=!n.isMain&&!!n.branch,Xe=n.branch&&Uh(n.branch,n.label)?{label:n.branch}:null,Tt=_?s.jsx(oj,{nodes:se,includeUnreadSubtasks:j}):null,ut=(Be,Ye)=>{const{folder:ft,scopeKey:yt,scopeDirectory:ht,nodes:mt}=Be,_t=At.get(ft.id)??[],Jt=T?.folderId===ft.id&&T?.scopeKey===yt,Yt=l?!1:Ne.has(ft.id),Ns=Xt=>s.jsx(yj,{folderId:ft.id,children:(zs,Js)=>s.jsx(aj,{folder:ft,displayName:Ye,sessions:mt,isCollapsed:Yt,collapsedActivityState:Xt,onToggle:()=>F(ft.id),onRename:rs=>{q(yt,ft.id,rs)},onDelete:()=>{if(n.isArchivedBucket){gn.requestDelete({sessions:_t,mode:"session"});return}if(!ce){Q(yt,ft.id);return}const rs=Fe.filter(({folder:Es})=>Es.parentId===ft.id).length,Vs=mt.length;oe({scopeKey:yt,folderId:ft.id,folderName:ft.name,subFolderCount:rs,sessionCount:Vs})},groupDirectory:ht??n.directory,projectId:i,mobileVariant:v,alwaysShowActions:x,isRenaming:Jt,renameDraft:Jt?T?.draft:void 0,onRenameDraftChange:k,onRenameSave:()=>{const rs=T?.draft.trim()??"";rs&&q(yt,ft.id,rs),P()},onRenameCancel:P,droppableRef:zs,isDropTarget:Js,depth:0,onNewSession:()=>{i&&i!==m&&b(i),v&&y(!1),S({selectedProjectId:i,directoryOverride:ht??n.directory,targetFolderId:ft.id,target:n.draftTarget})},hideActions:!1,archivedBucket:n.isArchivedBucket===!0,children:mt.map(rs=>s.jsx(Ko,{node:rs,pinnedSessionIds:N,expandedParents:$,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,notifyOnSubtasks:j,editingId:E,editTitle:B,copiedSessionId:O,openSidebarMenuKey:K,mobileVariant:v,alwaysShowActions:x,groupDirectory:ht??n.directory,projectId:i,archivedBucket:n.isArchivedBucket===!0,renderExtras:{subtreeContainsEditing:de,menuOpenSessionId:J,nodeStructureKey:it(rs),childRenderExtrasFor:Ue},setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad},rs.session.id))})},ft.id);return Yt?s.jsx(E2,{nodes:Qe.get(ft.id)??mt,includeUnreadSubtasks:j,children:Ns},ft.id):Ns(null)},kt=()=>{const Be=new Map;for(const ht of Fe){const mt=ht.folder.parentId;if(!mt)continue;const _t=Be.get(mt);_t?_t.push(ht):Be.set(mt,[ht])}const Ye=[],ft=new Set,yt=(ht,mt)=>{if(ft.has(ht.folder.id))return;ft.add(ht.folder.id);const _t=mt?`${mt} / ${ht.folder.name}`:ht.folder.name;Ye.push(ut(ht,_t)),!(!l&&Ne.has(ht.folder.id))&&(Be.get(ht.folder.id)??[]).forEach(Yt=>yt(Yt,_t))};return De.forEach(ht=>yt(ht,"")),Ye},Rt=!!(!n.isMain&&n.worktree),ss=n.worktree?.worktreeStatus==="missing"?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center text-status-warning",title:e("sessions.sidebar.group.worktreeMissing"),"aria-label":e("sessions.sidebar.group.worktreeMissing"),children:s.jsx(R,{name:"alert",className:"h-3 w-3"})}):null,Ut=x?Rt?"pr-14":"pr-7":Rt?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2 group-hover/gh:pr-7 group-focus-within/gh:pr-7",Wt=me?s.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5",children:[e(ke==="os-permission"?"sessions.sidebar.group.empty.permissionDenied":"sessions.sidebar.group.empty.loadFailed"),Te?s.jsx(bt,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",disabled:je,onClick:()=>{H()},children:e("sessions.sidebar.group.empty.grantAccess")}):null,s.jsx(bt,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",onClick:xe,children:e("sessions.sidebar.group.empty.retry")})]}):null,Qt=Be=>s.jsx(Ko,{node:Be,pinnedSessionIds:N,expandedParents:$,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,notifyOnSubtasks:j,editingId:E,editTitle:B,copiedSessionId:O,openSidebarMenuKey:K,mobileVariant:v,alwaysShowActions:x,groupDirectory:n.directory,projectId:i,archivedBucket:n.isArchivedBucket===!0,renderExtras:{subtreeContainsEditing:de,menuOpenSessionId:J,nodeStructureKey:it(Be),childRenderExtrasFor:Ue},setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad},Be.session.id),Kt=s.jsxs(wj,{scopeKey:U[0]?.scopeKey??G,hasFolders:Fe.length>0,onSessionDroppedOnFolder:(Be,Ye)=>{const ft=Fe.find(({folder:ht})=>ht.id===Ye);if(!ft)return;const yt=cs.getState();for(const{scopeKey:ht}of U)ht!==ft.scopeKey&&yt.getSessionFolderId(ht,Be)&&yt.removeSessionFromFolder(ht,Be);Y(ft.scopeKey,Ye,Be)},children:[kt(),pe?s.jsx("div",{ref:pt,children:rt?s.jsx("div",{style:{height:we.getTotalSize(),position:"relative"},children:we.getVirtualItems().map(Be=>{const Ye=ee[Be.index];return Ye?s.jsx("div",{"data-index":Be.index,ref:we.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Be.start-St}px)`},children:Qt(Ye)},Ye.session.id):null})}):ee.map(Qt)}):ee.map(Qt),st===0&&Fe.length===0?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):ue?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(R,{name:"loader-4",className:"size-3 animate-spin"}),e("sessions.sidebar.group.empty.loadingSessions")]}):Wt||(n.emptyMessage??e("sessions.sidebar.group.empty.noSessionsInWorkspace"))}):null,st>0&&Wt?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-status-error",children:Wt}):null,ze>0?s.jsx("button",{type:"button",onClick:()=>g(r,ee.length,h??7),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,_e?s.jsx("button",{type:"button",onClick:()=>w(r),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),Ft="pb-2",$t=s.jsx(k2,{value:X,setValue:oe,onConfirm:()=>{const Be=X;Be&&(Q(Be.scopeKey,Be.folderId),oe(null))}});return o?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:Ie("oc-group-body",Ft),children:Kt})}),$t]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:Ie("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>A(r),role:"button",tabIndex:0,onKeyDown:Be=>{(Be.key==="Enter"||Be.key===" ")&&(Be.preventDefault(),A(r))},"aria-label":_?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!_,children:[s.jsxs("div",{ref:D?.setActivatorNodeRef,className:Ie("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-1.5 transition-[padding]",Ut),...D?.listeners??{},children:[s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(R,{name:"archive",className:Ie("h-3.5 w-3.5 shrink-0 text-muted-foreground",x?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:Ie("text-muted-foreground h-3.5 w-3.5 items-center justify-center",x?"inline-flex":"hidden group-hover/gh:inline-flex"),children:_?s.jsx(R,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:wo(n.label,a)}),ss,Tt]}):!n.isMain||n.worktree?s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(R,{name:"git-branch",className:Ie("h-3.5 w-3.5 shrink-0",!ae&&"text-muted-foreground",x?"hidden":"group-hover/gh:hidden"),style:ae?{color:ae}:void 0}),s.jsx("span",{className:Ie("text-muted-foreground h-3.5 w-3.5 items-center justify-center",x?"inline-flex":"hidden group-hover/gh:inline-flex"),children:_?s.jsx(R,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 truncate typography-ui-label font-semibold text-muted-foreground",children:wo(n.label,a)}),ss,Tt,ge?s.jsxs("span",{className:"ml-auto flex-shrink-0 text-[0.72rem] font-medium leading-none",style:ae?{color:ae}:void 0,children:["#",ge.number]}):null]}):s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"min-w-0 truncate",children:wo(n.label,a)}),Tt]})}),We&&Xe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(R,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(R,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-muted-foreground/80",children:Xe.label})]}):null]}),!n.isArchivedBucket&&n.directory?s.jsx(Qr,{directory:n.directory,className:"self-center"}):null]}),n.isArchivedBucket&&dt.length>0?s.jsx("div",{className:Ie("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",x?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Be=>{Be.stopPropagation(),gn.requestDelete({sessions:dt,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:Ie("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",x?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Be=>{Be.stopPropagation(),gn.requestDelete({sessions:dt,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:Ie("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",x?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Be=>{Be.stopPropagation(),i&&i!==m&&b(i),v&&y(!1),S({selectedProjectId:i,directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(R,{name:"add",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),_?null:s.jsx("div",{className:Ie("oc-group-body",Ft),children:Kt})]}),$t]})}const Do=c.memo(F2,B2),_2=(t,e,n)=>e?t.filter(r=>r.project.id===n):t,L2=t=>t?"top-content":"empty-state",$2=(t,e)=>{const n=t.groups.find(o=>o.isMain&&o.sessions.length>0)??t.groups.find(o=>o.sessions.length>0)??t.groups.find(o=>o.isMain)??t.groups[0];if(!n)return[];const r=t.groups.find(o=>o.isArchivedBucket&&o.id!==n.id);return[n,...r?[r]:[]].map(o=>({group:o,groupKey:`${t.project.id}:${o.id}`,projectId:t.project.id,hideGroupLabel:o.id===n.id}))},W2=48,z2=32,V2=24,ki=(t,e)=>Ba(t.label?.trim()||Fn(t.normalizedPath,e)||t.normalizedPath);function U2(t){const e=nt.c(42);Gs("ui.sidebar_projects_list.render");const{t:n}=Nt(),{model:r,view:i,actions:o}=t,l=r.state.editingId!==null,a=i.isDesktopShellRuntime&&i.stickyZoneHeaders&&!r.singleProjectMode;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={activationConstraint:{distance:8}},e[0]=u):u=e[0];let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={coordinateGetter:zg},e[1]=d):d=e[1];const h=Ur(On(Vi,u),On($g,d));let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f={activationConstraint:{distance:8}},e[2]=f):f=e[2];const p=Ur(On(Vi,f)),g=c.useRef(null),w=c.useRef(0);let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v=he=>{const ie=he.scrollTop>1?Math.min(z2+he.scrollTop,W2):0;w.current=ie;const ge=he.closest(".oc-sticky-fade-root");ge?.style.setProperty("--scroll-shadow-top-size",`${ie}px`),ge?.style.setProperty("--scroll-shadow-top-clear-size",`${Math.min(Math.max(ie-8,0),V2)}px`)},e[3]=v):v=e[3];const x=v;let m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m=he=>{he.target.closest("[data-overlay-scrollbar-thumb], [data-sidebar-sticky-header]")||he.clientY-he.currentTarget.getBoundingClientRect().top>=w.current||(he.preventDefault(),he.stopPropagation())},e[4]=m):m=e[4];const b=m,y=_2(r.sectionsForRender,r.singleProjectMode,r.singleProjectId),S=r.projectSections.length>0&&y.length>0;let N,C;e[5]!==a||e[6]!==S?(N=()=>{a&&S&&g.current&&x(g.current)},C=[a,S,x],e[5]=a,e[6]=S,e[7]=N,e[8]=C):(N=e[7],C=e[8]),c.useLayoutEffect(N,C);let j=null;for(const he of r.projectSections)r.stuckProjectHeaders.has(he.project.id)&&(j=he.project);const A=j??(r.hasSharedSessions?null:y[0]?.project??null),D=A?ki(A,i.homeDirectory):null;let I;if(e[9]!==r.projectSections||e[10]!==i.homeDirectory){let he;e[12]!==i.homeDirectory?(he=_=>({id:_.project.id,projectLabel:ki(_.project,i.homeDirectory),projectDescription:Vr(_.project.normalizedPath,i.homeDirectory),projectIcon:_.project.icon,projectColor:_.project.color,projectIconImage:_.project.iconImage,projectIconBackground:_.project.iconBackground}),e[12]=i.homeDirectory,e[13]=he):he=e[13],I=r.projectSections.map(he),e[9]=r.projectSections,e[10]=i.homeDirectory,e[11]=I}else I=e[11];const M=I;if(r.projectSections.length===0){let he;return e[14]!==r.emptyState||e[15]!==r.topContent?(he=s.jsxs(Nn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:"space-y-1 pb-1 pl-2.5 pr-2",children:[r.topContent,r.emptyState]}),e[14]=r.emptyState,e[15]=r.topContent,e[16]=he):he=e[16],he}if(r.sectionsForRender.length===0){const _=L2(r.topContentHasSearchMatches===!0)==="top-content"?r.topContent:r.searchEmptyState;let ie;return e[17]!==_?(ie=s.jsx(Nn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:"space-y-1 pb-1 pl-2.5 pr-2",children:_}),e[17]=_,e[18]=ie):ie=e[18],ie}const $="oc-sticky-fade-root relative flex min-h-0 flex-1";let E;e[19]!==a?(E=a?{"--scroll-shadow-top-size":"0px"}:void 0,e[19]=a,e[20]=E):E=e[20];const K=a?b:void 0,B=a?b:void 0,O=a?b:void 0,T=Nn,k=!0,P=!a,F=96,q="flex-1 min-h-0",Q="oc-sidebar-scroller oc-sticky-fade-scroller space-y-1.5 pb-1 pl-2.5 pr-2 [overflow-anchor:none]";let Y;e[21]!==a?(Y=a?he=>x(he.currentTarget):void 0,e[21]=a,e[22]=Y):Y=e[22];const ce=i.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const he=y.find(ie=>ie.project.id===r.activeProjectId)??y[0];if(!he)return i.hasSessionSearchQuery?r.searchEmptyState:r.emptyState;const _=$2(he);return _.length?_.map(ie=>{const{group:ge,groupKey:ae,projectId:z,hideGroupLabel:ne}=ie;return s.jsx(c.Fragment,{children:s.jsx(Do,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:ge,groupKey:ae,projectId:z,hideGroupLabel:ne,visibleSessionCount:r.state.visibleSessionCountByGroup.get(ae),compactBodyPadding:!0,scrollContainerRef:g})},ae)}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})()}):s.jsxs(Kr,{sensors:h,collisionDetection:Hr,onDragEnd:he=>{if(l||i.projectSortOrder!=="manual")return;const{active:_,over:ie}=he;if(!ie||_.id===ie.id)return;const ge=r.sectionsForRender.findIndex(z=>z.project.id===_.id),ae=r.sectionsForRender.findIndex(z=>z.project.id===ie.id);ge===-1||ae===-1||ge===ae||o.reorderProjects(ge,ae)},children:[s.jsx(Bo,{items:y.map(q2),strategy:Ki,children:y.map(he=>{const _=he.project,ie=_.id,ge=ki(_,i.homeDirectory),ae=Vr(_.normalizedPath,i.homeDirectory),z=r.singleProjectMode?!1:i.collapsedProjects.has(ie),ne=r.projectRepoStatus.get(ie);return s.jsx(X0,{id:ie,disabled:r.singleProjectMode||i.projectSortOrder!=="manual",projectLabel:ge,projectDescription:ae,projectDirectory:_.normalizedPath,projectIcon:_.icon,projectColor:_.color,projectIconImage:_.iconImage,projectIconBackground:_.iconBackground,isCollapsed:z,isRepo:!!ne,isDesktopShell:i.isDesktopShellRuntime,hideDirectoryControls:i.hideDirectoryControls,mobileVariant:i.mobileVariant,alwaysShowActions:i.alwaysShowActions,statusIndicator:z?o.renderProjectStatusIndicator?.(ie,he.groups):null,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,projectPickerOptions:r.singleProjectMode?M:void 0,onProjectSelect:r.singleProjectMode?o.setSingleProjectId:void 0,onToggle:()=>{r.singleProjectMode||o.toggleProject(ie)},onNewSession:()=>{ie!==r.activeProjectId&&o.setActiveProjectIdOnly(ie),i.mobileVariant&&o.setSessionSwitcherOpen(!1),o.openNewSessionDraft({selectedProjectId:ie,directoryOverride:_.normalizedPath})},onNewWorktreeSession:()=>{ie!==r.activeProjectId&&o.setActiveProjectIdOnly(ie),o.openNewWorktreeDialog()},onManageWorktrees:()=>o.openWorktreesPage(ie),onRenameStart:()=>o.openProjectEditDialog(ie),onClose:()=>o.removeProject(ie),sentinelRef:ue=>{r.projectHeaderSentinelRefs.current.set(ie,ue)},showCreateButtons:!0,children:z?null:s.jsx("div",{className:"space-y-0 pt-0.5 pb-0.5",children:(()=>{const ue=he.groups,me=ue.find(G2)??null,ke=me?ue.filter(Te=>Te.id!==me.id):ue;return s.jsxs(Kr,{sensors:p,collisionDetection:Hr,onDragEnd:Te=>{if(l)return;const{active:je,over:Ee}=Te;if(!Ee||je.id===Ee.id)return;const xe=ke.findIndex(re=>re.id===je.id),H=ke.findIndex(re=>re.id===Ee.id);if(xe===-1||H===-1||xe===H)return;const Ce=pu(ke,xe,H).map(H2),ve=me?[me.id,...Ce]:Ce;o.setGroupOrderByProject(re=>{const le=new Map(re);return le.set(ie,ve),le})},children:[me?s.jsx(Do,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:me,groupKey:`${ie}:${me.id}`,projectId:ie,hideGroupLabel:!0,visibleSessionCount:r.state.visibleSessionCountByGroup.get(`${ie}:${me.id}`),scrollContainerRef:g}):null,s.jsx(Bo,{items:ke.map(K2),strategy:Ki,children:ke.map(Te=>{const je=`${ie}:${Te.id}`;return s.jsx(Z0,{id:Te.id,disabled:l,children:Ee=>s.jsx(Do,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:Te,groupKey:je,projectId:ie,visibleSessionCount:r.state.visibleSessionCountByGroup.get(je),dragHandleProps:Ee,scrollContainerRef:g})},Te.id)})}),s.jsx(Ui,{dropAnimation:null})]})})()})},ie)})}),s.jsx(Ui,{dropAnimation:null})]});let X;e[23]!==T||e[24]!==r.topContent||e[25]!==P||e[26]!==Y||e[27]!==ce?(X=s.jsxs(T,{ref:g,useScrollShadow:k,hideTopScrollShadow:P,scrollShadowSize:F,outerClassName:q,className:Q,onScroll:Y,children:[r.topContent,ce]}),e[23]=T,e[24]=r.topContent,e[25]=P,e[26]=Y,e[27]=ce,e[28]=X):X=e[28];let oe;e[29]!==a||e[30]!==A||e[31]!==D||e[32]!==r.hasSharedSessions||e[33]!==n?(oe=a&&(A||r.hasSharedSessions)?s.jsx("div",{className:"oc-sticky-fade-overlay pointer-events-none absolute inset-x-0 top-0 z-30 flex items-center gap-1.5 py-1 pl-4 pr-5","aria-hidden":"true",children:A&&D?s.jsxs(s.Fragment,{children:[s.jsx(No,{id:A.id,projectLabel:D,projectIcon:A.icon,projectColor:A.color,projectIconImage:A.iconImage,projectIconBackground:A.iconBackground}),s.jsx(Qr,{directory:A.normalizedPath,className:"ml-auto"})]}):s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"history",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:n("sessions.sidebar.activity.recentTitle")})]})}):null,e[29]=a,e[30]=A,e[31]=D,e[32]=r.hasSharedSessions,e[33]=n,e[34]=oe):oe=e[34];let te;return e[35]!==K||e[36]!==B||e[37]!==O||e[38]!==X||e[39]!==oe||e[40]!==E?(te=s.jsxs("div",{className:$,style:E,onPointerDownCapture:K,onClickCapture:B,onContextMenuCapture:O,children:[X,oe]}),e[35]=K,e[36]=B,e[37]=O,e[38]=X,e[39]=oe,e[40]=E,e[41]=te):te=e[41],te}function K2(t){return t.id}function H2(t){return t.id}function G2(t){return t.isMain}function q2(t){return t.project.id}const Q2=c.memo(U2),ha=new Map,Oc=(t,e)=>{for(const n of t){const r=wt(n??null);r&&!ha.has(r)&&ha.set(r,e)}},Bc=t=>{const e=wt(t??null);return e?ha.get(e)??0:0},po=t=>!!t.time?.archived,Y2=t=>{const{t:e}=Nt(),n=c.useRef(t.gitBranches);n.current=t.gitBranches;const r=c.useCallback(a=>[a.label,a.branch??"",a.description??"",a.directory??""].join(" ").toLowerCase(),[]),i=c.useCallback(a=>{const u=wt(a.directory??null)??"";return`${(a.title||e("sessions.sidebar.session.untitled")).trim()} ${u}`.toLowerCase()},[e]),o=c.useCallback((a,u)=>u?a.flatMap(d=>{if(Ro([i(d.session)],u))return[d];const f=o(d.children,u);return f.length===0?[]:[{...d,children:f}]}):a,[i]),l=c.useCallback((a,u,d,h,f)=>{const p=wt(u??null),g=Vd(a),w=new Map(g.map(O=>[O.id,O])),v=new Map;g.forEach(O=>{const T=O.parentID;if(!T)return;const k=w.get(T);if(!k||po(k)!==po(O))return;const P=v.get(T)??[];P.push(O),v.set(T,P)});const x=new Map;d.forEach(O=>{if(O.path){const T=wt(O.path)??O.path;x.set(T,O)}});const m=O=>{const T=wt(O.directory??null),k=t.worktreeMetadata.get(O.id)??null;if(k)return k;if(T){const P=x.get(T)??null;if(P&&T!==p)return P}return null},b=new Set,y=O=>{b.add(O.id);const T=v.get(O.id)??[],k=[];for(const P of T)b.has(P.id)||k.push(y(P));return{session:O,children:k,worktree:m(O)}},S=g.filter(O=>{const T=O.parentID;if(!T)return!0;const k=w.get(T);return k?po(k)!==po(O):!0}),N=[],C=O=>{b.has(O.id)||N.push(y(O))};S.forEach(C),g.forEach(C);const j=new Map,A="__archived__",D=O=>{if(O.time?.archived)return A;if(t.isVSCode)return p??"__project_root__";const k=wt(t.worktreeMetadata.get(O.id)?.path??null)??$s(O);return k?k!==p&&x.has(k)?k:k===p?p??"__project_root__":A:A};N.forEach(O=>{const T=D(O.session);j.has(T)||j.set(T,[]),j.get(T)?.push(O)});const I=p??"__project_root__",M=[{id:"root",label:f&&h&&h!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:h}):e("sessions.sidebar.grouping.projectRoot"),branch:h??null,description:p?Vr(p,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:p,folderScopeKey:p,sessions:j.get(I)??[]}],$=new Map;d.forEach(O=>{const T=wt(O.path)??O.path,k=j.get(T)??[],P=k.length>0,F=k.reduce((q,Q)=>{const Y=Kh(Q.session,t.sessionOrderRanks);return Number.isFinite(Y)?Math.max(q,Y):q},0);$.set(T,{hasActiveSession:P,lastUpdatedAt:F})});const E=[...d].sort((O,T)=>{const k=wt(O.path)??O.path,P=wt(T.path)??T.path,F=$.get(k)??{hasActiveSession:!1,lastUpdatedAt:0},q=$.get(P)??{hasActiveSession:!1,lastUpdatedAt:0};if(F.hasActiveSession!==q.hasActiveSession)return F.hasActiveSession?-1:1;if(F.hasActiveSession&&q.hasActiveSession)return q.lastUpdatedAt-F.lastUpdatedAt;const Q=Bc(O.path),Y=Bc(T.path);if(Q!==Y)return Y-Q;const ce=(O.label||O.branch||O.name||O.path||"").toLowerCase(),X=(T.label||T.branch||T.name||T.path||"").toLowerCase();return ce.localeCompare(X)});(t.isVSCode?[]:E).forEach(O=>{const T=wt(O.path)??O.path,k=n.current.get(T)?.trim()||null,P=O.branch?.trim()||null,q=!!(k&&P&&O.label&&pl(O.label)===pl(P))?k:O.label||O.name||Fn(T,t.homeDirectory)||T;M.push({id:`worktree:${T}`,label:q,branch:k||P,description:Vr(T,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:O,directory:T,folderScopeKey:T,sessions:j.get(T)??[]})});const B=j.get(A)??[];return B.length>0&&M.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&p?zd(p):null,sessions:B}),M},[t.homeDirectory,t.worktreeMetadata,t.sessionOrderRanks,t.isVSCode,e]);return{buildGroupSearchText:r,buildSessionSearchText:i,filterSessionNodesForSearch:o,buildGroupedSessions:l}},X2=t=>{const e=nt.c(10),{enabled:n,isDesktopShellRuntime:r,projectSections:i,projectHeaderSentinelRefs:o}=t,l=n===void 0?!0:n;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[u,d]=c.useState(a);let h;e[1]!==l||e[2]!==r||e[3]!==o?(h=()=>{if(!l||!r){d(J2);return}const g=Array.from(o.current.values()).find(Z2)?.closest(".oc-sidebar-scroller")??null;if(!g)return;const w=new IntersectionObserver(v=>{d(x=>{const m=new Set(x);let b=!1;for(const y of v){const S=y.target.dataset.projectId;if(!S)continue;const N=y.rootBounds?.top??g.getBoundingClientRect().top,C=!y.isIntersecting&&y.boundingClientRect.top<N;m.has(S)!==C&&(b=!0,C?m.add(S):m.delete(S))}return b?m:x})},{root:g,threshold:0});return o.current.forEach(v=>{v&&w.observe(v)}),()=>w.disconnect()},e[1]=l,e[2]=r,e[3]=o,e[4]=h):h=e[4];let f;return e[5]!==l||e[6]!==r||e[7]!==o||e[8]!==i?(f=[l,r,o,i],e[5]=l,e[6]=r,e[7]=o,e[8]=i,e[9]=f):f=e[9],c.useEffect(h,f),u};function J2(t){return t.size===0?t:new Set}function Z2(t){return t!==null}const ek=t=>{const e=nt.c(51),{selectedCount:n,scopeKey:r,scopeFolders:i,archivedBucket:o,onMoveToFolder:l,onCreateFolderAndMove:a,onRemoveFromFolder:u,canRemoveFromFolder:d,onRestore:h,onDelete:f,onDone:p}=t,{t:g}=Nt(),w=!!r&&!o;let v;e[0]!==o||e[1]!==g?(v=g(o?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=o,e[1]=g,e[2]=v):v=e[2];const x=v;let m;e[3]!==n||e[4]!==g?(m=g("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=g,e[5]=m):m=e[5];let b;e[6]!==m?(b=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:m}),e[6]=m,e[7]=b):b=e[7];let y;e[8]!==w||e[9]!==d||e[10]!==a||e[11]!==l||e[12]!==u||e[13]!==i||e[14]!==g?(y=w?s.jsxs(Xs,{children:[s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Qs,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":g("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(R,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:g("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Ys,{align:"end",className:"min-w-[180px]",children:[i.length===0?s.jsx(zt,{disabled:!0,className:"text-muted-foreground",children:g("sessions.sidebar.folders.none")}):i.map(k=>s.jsx(zt,{onClick:()=>l(k.id),children:s.jsx("span",{className:"flex-1 truncate",children:k.name})},k.id)),s.jsx(Os,{}),s.jsxs(zt,{onClick:a,children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"}),g("sessions.sidebar.folders.newFolderEllipsis")]}),d?s.jsxs(zt,{onClick:u,className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"close",className:"mr-1 h-4 w-4"}),g("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=w,e[9]=d,e[10]=a,e[11]=l,e[12]=u,e[13]=i,e[14]=g,e[15]=y):y=e[15];let S;e[16]!==o||e[17]!==h||e[18]!==g?(S=o?s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:h,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":g("sessions.sidebar.bulkActions.restore"),children:s.jsx(R,{name:"inbox-unarchive",className:"h-4 w-4"})})}),s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:g("sessions.sidebar.bulkActions.restore")})})]}):null,e[16]=o,e[17]=h,e[18]=g,e[19]=S):S=e[19];let N;e[20]===Symbol.for("react.memo_cache_sentinel")?(N=Ie("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[20]=N):N=e[20];let C;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(R,{name:"delete-bin",className:"h-4 w-4"}),e[21]=C):C=e[21];let j;e[22]!==x||e[23]!==f?(j=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:N,"aria-label":x,children:C})}),e[22]=x,e[23]=f,e[24]=j):j=e[24];let A;e[25]!==x?(A=s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:x})}),e[25]=x,e[26]=A):A=e[26];let D;e[27]!==j||e[28]!==A?(D=s.jsxs(Dt,{children:[j,A]}),e[27]=j,e[28]=A,e[29]=D):D=e[29];let I;e[30]!==g?(I=g("sessions.sidebar.header.actions.exitSelection"),e[30]=g,e[31]=I):I=e[31];let M;e[32]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(R,{name:"close",className:"h-4 w-4"}),e[32]=M):M=e[32];let $;e[33]!==p||e[34]!==I?($=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:p,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":I,children:M})}),e[33]=p,e[34]=I,e[35]=$):$=e[35];let E;e[36]!==g?(E=g("sessions.sidebar.header.actions.exitSelection"),e[36]=g,e[37]=E):E=e[37];let K;e[38]!==E?(K=s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:E})}),e[38]=E,e[39]=K):K=e[39];let B;e[40]!==$||e[41]!==K?(B=s.jsxs(Dt,{children:[$,K]}),e[40]=$,e[41]=K,e[42]=B):B=e[42];let O;e[43]!==D||e[44]!==B||e[45]!==y||e[46]!==S?(O=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[y,S,D,B]}),e[43]=D,e[44]=B,e[45]=y,e[46]=S,e[47]=O):O=e[47];let T;return e[48]!==O||e[49]!==b?(T=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[b,O]}),e[48]=O,e[49]=b,e[50]=T):T=e[50],T},tk=(t,e)=>{if(!t)return[];const n=e(t);return n.length>0?n.map(r=>r.scopeKey):[t]},sk=t=>{const{t:e}=Nt(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:i,getFolderScopesForProject:o,addSessionsToFolder:l,removeSessionsFromFolders:a,createFolderAndStartRename:u,archiveSessions:d,unarchiveSessions:h,deleteSessions:f,setBulkDeleteConfirm:p}=t,g=hs(k=>k.enabled),w=hs(k=>k.selectedIds.size),v=w>0,x=hs(k=>k.selectedIds),m=hs(k=>k.scopeKey),b=c.useCallback(()=>{hs.getState().toggleMode()},[]),y=c.useCallback(()=>{hs.getState().disable()},[]),S=c.useMemo(()=>{if(!v||typeof document>"u")return!1;let k=!1,P=!1;for(const F of x){const q=document.querySelectorAll(`[data-session-row="${CSS.escape(F)}"]`);for(const Q of q)Q.getAttribute("data-session-archived")==="1"?P=!0:k=!0}return P&&!k},[v,x]),N=c.useMemo(()=>{if(m)return m;if(!v||typeof document>"u")return null;for(const k of x){const F=document.querySelector(`[data-session-row="${CSS.escape(k)}"]`)?.getAttribute("data-session-scope");if(F&&F.length>0)return F}return null},[v,x,m]),C=c.useMemo(()=>tk(N,o),[N,o]),j=c.useMemo(()=>C.flatMap(k=>i[k]??[]),[i,C]),A=c.useCallback(k=>{for(const P of C)if((i[P]??[]).some(F=>F.id===k))return P;return null},[i,C]),D=c.useMemo(()=>{if(!v)return!1;for(const k of C)for(const P of i[k]??[])for(const F of P.sessionIds)if(x.has(F))return!0;return!1},[i,C,v,x]),I=c.useCallback((k,P)=>{const F=Array.from(x);for(const q of C)q!==k&&a(q,F);l(k,P,F)},[l,a,x,C]),M=c.useCallback(k=>{if(!v)return;const P=A(k);P&&I(P,k)},[v,I,A]),$=c.useCallback(()=>{const k=C[0];if(!k||!v)return;const P=u(k);P&&I(k,P.id)},[u,v,I,C]),E=c.useCallback(()=>{if(!v)return;const k=Array.from(x);for(const P of C)a(P,k)},[a,x,C,v]),K=c.useCallback(async()=>{const k=Array.from(x);if(k.length!==0){if(S){const{deletedIds:P,failedIds:F}=await f(k);P.length>0&&Re.success(P.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:P.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:P.length})),F.length>0&&Re.error(F.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:F.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:F.length}))}else{const{archivedIds:P,failedIds:F}=await d(k);P.length>0&&Re.success(P.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:P.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:P.length})),F.length>0&&Re.error(F.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:F.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:F.length}))}hs.getState().clear()}},[d,S,f,x,e]),B=c.useCallback(()=>{if(!v)return;const k=x.size;if(!r){K();return}p({sessionCount:k,archivedBucket:S})},[S,K,x,r,p,v]),O=c.useCallback(async()=>{if(!v||!S)return;const k=Array.from(x),{restoredIds:P,failedIds:F}=await h(k);P.length>0&&Re.success(P.length===1?e("sessions.sidebar.bulkActions.restoredSingle",{count:P.length}):e("sessions.sidebar.bulkActions.restoredPlural",{count:P.length})),F.length>0&&Re.error(F.length===1?e("sessions.sidebar.bulkActions.failedRestoreSingle",{count:F.length}):e("sessions.sidebar.bulkActions.failedRestorePlural",{count:F.length})),hs.getState().clear()},[S,v,x,e,h]),T=c.useCallback(async()=>{p(null),await K()},[K]);return c.useEffect(()=>{if(!g)return;const k=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),P=F=>{if(n)return;const q=F.target;if(q&&(q.tagName==="INPUT"||q.tagName==="TEXTAREA"||q.isContentEditable))return;const Q=k?F.metaKey:F.ctrlKey;if(F.key==="Escape"){F.preventDefault(),hs.getState().disable();return}if(Q&&F.key==="Backspace"){F.preventDefault(),B();return}if(Q&&(F.key==="a"||F.key==="A")){const Y=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Y.length===0)return;F.preventDefault();const X=hs.getState().scopeKey??Y[0]?.getAttribute("data-session-scope")??null,oe=he=>X?he.getAttribute("data-session-scope")===X:!0,te=Y.filter(oe).map(he=>he.getAttribute("data-session-row")).filter(he=>typeof he=="string"&&he.length>0);if(te.length===0)return;hs.getState().replaceAll(te,X||null)}};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[B,n,g]),{selectionModeEnabled:g,hasSelection:v,selectedIdsSize:w,bulkScopeIsArchived:S,derivedSelectionScope:N,bulkScopeFolders:j,bulkCanRemoveFromFolder:D,handleToggleSelectionMode:b,handleExitSelectionMode:y,handleBulkMoveToFolder:M,handleBulkCreateFolderAndMove:$,handleBulkRemoveFromFolder:E,handleBulkDelete:B,handleBulkRestore:O,confirmBulkDelete:T}};function nk(t){const e=nt.c(36),{getFolderScopesForProject:n,isInlineEditing:r,startFolderRename:i}=t,[o,l]=c.useState(null),a=Pe(mk),u=Pe(uk),d=cs(dk),h=cs(ck),f=cs(lk),p=cs(ak),g=et(ik),w=et(ok),v=et(rk);let x;e[0]!==h||e[1]!==i?(x=C=>{const j=h(C,"New folder");return i(C,j),j},e[0]=h,e[1]=i,e[2]=x):x=e[2];let m;e[3]!==f||e[4]!==g||e[5]!==v||e[6]!==d||e[7]!==n||e[8]!==r||e[9]!==p||e[10]!==a||e[11]!==x||e[12]!==w?(m={isInlineEditing:r,showDeletionDialog:a,foldersMap:d,getFolderScopesForProject:n,addSessionsToFolder:f,removeSessionsFromFolders:p,createFolderAndStartRename:x,archiveSessions:g,unarchiveSessions:w,deleteSessions:v,setBulkDeleteConfirm:l},e[3]=f,e[4]=g,e[5]=v,e[6]=d,e[7]=n,e[8]=r,e[9]=p,e[10]=a,e[11]=x,e[12]=w,e[13]=m):m=e[13];const b=sk(m);let y;e[14]!==b.bulkCanRemoveFromFolder||e[15]!==b.bulkScopeFolders||e[16]!==b.bulkScopeIsArchived||e[17]!==b.derivedSelectionScope||e[18]!==b.handleBulkCreateFolderAndMove||e[19]!==b.handleBulkDelete||e[20]!==b.handleBulkMoveToFolder||e[21]!==b.handleBulkRemoveFromFolder||e[22]!==b.handleBulkRestore||e[23]!==b.handleExitSelectionMode||e[24]!==b.hasSelection||e[25]!==b.selectedIdsSize||e[26]!==b.selectionModeEnabled?(y=b.selectionModeEnabled&&b.hasSelection?s.jsx(ek,{selectedCount:b.selectedIdsSize,scopeKey:b.derivedSelectionScope,scopeFolders:b.bulkScopeFolders,archivedBucket:b.bulkScopeIsArchived,onMoveToFolder:b.handleBulkMoveToFolder,onCreateFolderAndMove:b.handleBulkCreateFolderAndMove,onRemoveFromFolder:b.handleBulkRemoveFromFolder,canRemoveFromFolder:b.bulkCanRemoveFromFolder,onRestore:b.handleBulkRestore,onDelete:b.handleBulkDelete,onDone:b.handleExitSelectionMode}):null,e[14]=b.bulkCanRemoveFromFolder,e[15]=b.bulkScopeFolders,e[16]=b.bulkScopeIsArchived,e[17]=b.derivedSelectionScope,e[18]=b.handleBulkCreateFolderAndMove,e[19]=b.handleBulkDelete,e[20]=b.handleBulkMoveToFolder,e[21]=b.handleBulkRemoveFromFolder,e[22]=b.handleBulkRestore,e[23]=b.handleExitSelectionMode,e[24]=b.hasSelection,e[25]=b.selectedIdsSize,e[26]=b.selectionModeEnabled,e[27]=y):y=e[27];let S;e[28]!==b.confirmBulkDelete||e[29]!==o||e[30]!==u||e[31]!==a?(S=s.jsx(j2,{value:o,setValue:l,showDeletionDialog:a,setShowDeletionDialog:u,onConfirm:b.confirmBulkDelete}),e[28]=b.confirmBulkDelete,e[29]=o,e[30]=u,e[31]=a,e[32]=S):S=e[32];let N;return e[33]!==y||e[34]!==S?(N=s.jsxs(s.Fragment,{children:[y,S]}),e[33]=y,e[34]=S,e[35]=N):N=e[35],N}function rk(t){return t.deleteSessions}function ok(t){return t.unarchiveSessions}function ik(t){return t.archiveSessions}function ak(t){return t.removeSessionsFromFolders}function lk(t){return t.addSessionsToFolder}function ck(t){return t.createFolder}function dk(t){return t.foldersMap}function uk(t){return t.setShowDeletionDialog}function mk(t){return t.showDeletionDialog}const Fc=7,fk=6e4,hk=()=>{const t=nt.c(2),[e,n]=c.useState(0);let r,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{const o=setInterval(()=>{n(gk)},fk);return()=>clearInterval(o)},i=[],t[0]=r,t[1]=i):(r=t[0],i=t[1]),c.useEffect(r,i),e};function pk(t){const{sections:e,variant:n="section",initialVisibleCount:r=Fc,batchSize:i=Fc}=t,{t:o}=Nt(),{pinnedSessionIds:l}=t,a=ls(y=>y.stickyZoneHeaders),[u,d]=c.useState(new Set),[h,f]=c.useState(new Map),p=n==="flat",g=c.useCallback(y=>{f(S=>{if(!S.has(y))return S;const N=new Map(S);return N.delete(y),N})},[]),w=c.useCallback(y=>{g(y),d(S=>{const N=new Set(S);return N.has(y)?N.delete(y):N.add(y),N})},[g]),v=c.useCallback((y,S,N)=>{f(C=>{const j=Math.min(N,S+i),A=new Map(C);return A.set(y,j),A})},[i]),x=hk(),m=c.useCallback(y=>{const S=new Set;la(y,t.editingId,S);const N=Yr(y,t.openSidebarMenuKey,"recent",!1),C=new WeakMap,j=D=>{C.set(D,Uo(D)),D.children.forEach(j)};y.forEach(j);const A=D=>({subtreeContainsEditing:S,menuOpenSessionId:N,nodeStructureKey:C.get(D)??"",relativeTimeTick:x,childRenderExtrasFor:A});return D=>({subtreeContainsEditing:S,menuOpenSessionId:N,nodeStructureKey:C.get(D)??"",relativeTimeTick:x,childRenderExtrasFor:A})},[t.editingId,t.openSidebarMenuKey,x]),b=e.filter(y=>y.items.length>0||y.key==="chats");return b.length===0?null:s.jsx("div",{className:Ie(p?"space-y-0.5 pb-2":"space-y-2 pb-2"),children:b.map(y=>{const S=u.has(y.key),N=Math.max(r,h.get(y.key)??r),C=y.items.slice(0,N),j=y.items.length-C.length,A=y.key==="chats"&&!!t.renderChatsSection,D=!A&&!p&&y.items.length>r&&j===0,I=m(C.map($=>$.node)),M=$=>s.jsx(Ko,{node:$.node,pinnedSessionIds:l,expandedParents:t.expandedParents,hasSessionSearchQuery:t.hasSessionSearchQuery,normalizedSessionSearchQuery:t.normalizedSessionSearchQuery,notifyOnSubtasks:t.notifyOnSubtasks,editingId:t.editingId,editTitle:t.editTitle,copiedSessionId:t.copiedSessionId,openSidebarMenuKey:t.openSidebarMenuKey,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,groupDirectory:$.groupDirectory,projectId:$.projectId,secondaryMeta:$.secondaryMeta,renderContext:"recent",renderExtras:I($.node),setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad},$.node.session.id);return p?s.jsxs("div",{className:"space-y-0.5",children:[C.map(M),j>0?s.jsx("button",{type:"button",onClick:()=>v(y.key,C.length,y.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showMore")}):null]},y.key):s.jsxs("div",{className:"relative space-y-1",children:[s.jsxs("div",{className:Ie("relative group/chats","-ml-2.5 -mr-2",a&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":a?"true":void 0,children:[s.jsxs("button",{type:"button",onClick:()=>w(y.key),className:Ie("group flex w-full items-center gap-1.5 py-1 pl-4 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",y.key==="chats"?"pr-10":"pr-3.5"),"aria-expanded":!S,children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 items-center justify-center",children:[s.jsx(R,{name:y.key==="chats"?"chat-4":"history",className:Ie("h-3.5 w-3.5 text-muted-foreground/80","group-hover:hidden")}),s.jsx("span",{className:"hidden h-3.5 w-3.5 items-center justify-center text-muted-foreground group-hover:inline-flex",children:S?s.jsx(R,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"text-[14px] font-semibold lowercase text-foreground",children:y.title})]}),y.key==="chats"&&t.onNewChat?s.jsx("button",{type:"button",onClick:$=>{$.stopPropagation(),t.onNewChat?.()},className:Ie("absolute right-0.5 top-1/2 z-10 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",t.alwaysShowActions?"opacity-100":"opacity-0 pointer-events-none group-hover/chats:opacity-100 group-hover/chats:pointer-events-auto group-focus-within/chats:opacity-100 group-focus-within/chats:pointer-events-auto"),"aria-label":o("sessions.sidebar.header.actions.newSession"),children:s.jsx(R,{name:"add",className:"h-4 w-4"})}):null]}),S?null:s.jsxs("div",{className:Ie("space-y-0.5"),children:[A?t.renderChatsSection?.(y.items):C.map(M),!A&&j>0?s.jsx("button",{type:"button",onClick:()=>v(y.key,C.length,y.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showMore")}):null,D?s.jsx("button",{type:"button",onClick:()=>g(y.key),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showFewer")}):null]})]},y.key)})})}function gk(t){return t+1}const xk=t=>{const e=nt.c(61),{projects:n,availableWorktreesByProject:r,gitBranches:i,homeDirectory:o,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,isDesktopShellRuntime:u,sessions:d,childrenMap:h,pinnedSessionIds:f,recentSessions:p,chatSessions:g,showRecentSection:w}=t,{t:v}=Nt();let x;if(e[0]!==r||e[1]!==i||e[2]!==o||e[3]!==n||e[4]!==d){x=new Map;for(const B of d){const O=wt(B.directory??null);if(!O)continue;let T=null,k=-1;for(const Q of n){const Y=wt(Q.normalizedPath);Y&&(O===Y||O.startsWith(`${Y}/`))&&Y.length>k&&(T=Q,k=Y.length)}if(!T)continue;const P=r.get(T.normalizedPath)?.find(Q=>wt(Q.path)===O),F=Ba(T.label?.trim()||Fn(T.normalizedPath,o)||T.normalizedPath),q=P?.branch?.trim()||i.get(O)?.trim()||null;x.set(B.id,{projectId:T.id,groupDirectory:O,projectLabel:F,branchLabel:q&&q!=="HEAD"&&q!==F?q:null})}e[0]=r,e[1]=i,e[2]=o,e[3]=n,e[4]=d,e[5]=x}else x=e[5];const m=x;let b;e[6]!==m?(b=B=>m.get(B)??null,e[6]=m,e[7]=b):b=e[7];const y=b;let S;e[8]!==h?(S=B=>({session:B,children:(h.get(B.id)??[]).filter(bk).map(yk),worktree:null}),e[8]=h,e[9]=S):S=e[9];const N=S,C=l?a:"";let j;e[10]!==y||e[11]!==N||e[12]!==p||e[13]!==C?(j=gg({sessions:p,getSessionLocation:y,getSessionNode:N,query:C}),e[10]=y,e[11]=N,e[12]=p,e[13]=C,e[14]=j):j=e[14];const A=j;let D;e[15]!==v?(D=v("sessions.sidebar.activity.chatsTitle"),e[15]=v,e[16]=D):D=e[16];let I;if(e[17]!==g||e[18]!==N){let B;e[20]!==N?(B=O=>({node:N(O),projectId:null,groupDirectory:O.directory??null,secondaryMeta:null}),e[20]=N,e[21]=B):B=e[21],I=g.map(B),e[17]=g,e[18]=N,e[19]=I}else I=e[19];let M;e[22]!==D||e[23]!==I?(M={key:"chats",title:D,items:I},e[22]=D,e[23]=I,e[24]=M):M=e[24];let $;e[25]!==A||e[26]!==w||e[27]!==v||e[28]!==M?($=[M,...w?A.map(B=>({...B,title:v("sessions.sidebar.activity.recentTitle")})):[]],e[25]=A,e[26]=w,e[27]=v,e[28]=M,e[29]=$):$=e[29];const E=$;let K;return e[30]!==u||e[31]!==f||e[32]!==t.allowReselect||e[33]!==t.alwaysShowActions||e[34]!==t.copiedSessionId||e[35]!==t.deleteSessionConfirm||e[36]!==t.editTitle||e[37]!==t.editingId||e[38]!==t.expandedParents||e[39]!==t.hasSessionSearchQuery||e[40]!==t.isSessionSearchOpen||e[41]!==t.mobileVariant||e[42]!==t.normalizedSessionSearchQuery||e[43]!==t.notifyOnSubtasks||e[44]!==t.onNewChat||e[45]!==t.onSessionSelected||e[46]!==t.openSidebarMenuKey||e[47]!==t.renderChatsSection||e[48]!==t.sessionSearchQuery||e[49]!==t.setCopiedSessionId||e[50]!==t.setDeleteSessionConfirm||e[51]!==t.setEditTitle||e[52]!==t.setEditingId||e[53]!==t.setIsSessionSearchOpen||e[54]!==t.setOpenSidebarMenuKey||e[55]!==t.setSessionSearchQuery||e[56]!==t.startFolderRename||e[57]!==t.startSessionWorktreeMenuLoad||e[58]!==t.toggleParent||e[59]!==E?(K=s.jsx(pk,{sections:E,variant:"section",isDesktopShellRuntime:u,pinnedSessionIds:f,expandedParents:t.expandedParents,hasSessionSearchQuery:t.hasSessionSearchQuery,normalizedSessionSearchQuery:t.normalizedSessionSearchQuery,notifyOnSubtasks:t.notifyOnSubtasks,editingId:t.editingId,editTitle:t.editTitle,copiedSessionId:t.copiedSessionId,openSidebarMenuKey:t.openSidebarMenuKey,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onNewChat:t.onNewChat,renderChatsSection:t.renderChatsSection,setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad}),e[30]=u,e[31]=f,e[32]=t.allowReselect,e[33]=t.alwaysShowActions,e[34]=t.copiedSessionId,e[35]=t.deleteSessionConfirm,e[36]=t.editTitle,e[37]=t.editingId,e[38]=t.expandedParents,e[39]=t.hasSessionSearchQuery,e[40]=t.isSessionSearchOpen,e[41]=t.mobileVariant,e[42]=t.normalizedSessionSearchQuery,e[43]=t.notifyOnSubtasks,e[44]=t.onNewChat,e[45]=t.onSessionSelected,e[46]=t.openSidebarMenuKey,e[47]=t.renderChatsSection,e[48]=t.sessionSearchQuery,e[49]=t.setCopiedSessionId,e[50]=t.setDeleteSessionConfirm,e[51]=t.setEditTitle,e[52]=t.setEditingId,e[53]=t.setIsSessionSearchOpen,e[54]=t.setOpenSidebarMenuKey,e[55]=t.setSessionSearchQuery,e[56]=t.startFolderRename,e[57]=t.startSessionWorktreeMenuLoad,e[58]=t.toggleParent,e[59]=E,e[60]=K):K=e[60],K};function bk(t){return!t.time?.archived}function yk(t){return{session:t,children:[],worktree:null}}const jm="oc.sessions.expandedParents.v3",wk=La(wr()),Sk=()=>{try{const t=globalThis.localStorage.getItem(jm);if(t===null)return new Set;const e=wk.safeParse(JSON.parse(t));return e.success?new Set(e.data):new Set}catch{return new Set}},vk=()=>{const[t,e]=c.useState(Sk),n=c.useRef(t);n.current=t;const r=c.useCallback(i=>{const o=Hh(n.current,i);n.current=o,e(o);try{globalThis.localStorage.setItem(jm,JSON.stringify([...o]))}catch{}},[]);return{expandedParents:t,toggleParent:r}},jk=5*6e4,kk=[],Ck=t=>!t.parentID,Nk=t=>{const e=nt.c(293),{topology:n,view:r,actions:i}=t;let o,l,a,u,d;e[0]!==i?({alwaysShowActions:o,notifyOnSubtasks:l,projectViewActions:a,rowActions:u,...d}=i,e[0]=i,e[1]=o,e[2]=l,e[3]=a,e[4]=u,e[5]=d):(o=e[1],l=e[2],a=e[3],u=e[4],d=e[5]);const h=cs(Dk),f=cs(Pk),p=cs(Ik),g=r.projectView,{getOrderedGroups:w,setGroupOrderByProject:v,toggleGroup:x,toggleProject:m}=a;let b;e[6]!==n.isVSCode||e[7]!==n.knownDirectories?(b={knownDirectories:n.knownDirectories,isVSCode:n.isVSCode,isVisible:!0},e[6]=n.isVSCode,e[7]=n.knownDirectories,e[8]=b):b=e[8];const y=xg(b);let S;e[9]===Symbol.for("react.memo_cache_sentinel")?(S=new Map,e[9]=S):S=e[9];const[N,C]=c.useState(S);let j;e[10]===Symbol.for("react.memo_cache_sentinel")?(j=(Mt,Lt)=>{C(ns=>new Map(ns).set(Mt,Lt+7))},e[10]=j):j=e[10];const A=j;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=Mt=>{C(Lt=>{if(!Lt.has(Mt))return Lt;const ns=new Map(Lt);return ns.delete(Mt),ns})},e[11]=D):D=e[11];const I=D,M=ls(Tk),$=ls(Ek),E=ls(Rk),K=ls(Mk);let B;e[12]!==n.isVSCode?(B=!n.isVSCode&&!xf(),e[12]=n.isVSCode,e[13]=B):B=e[13];const T=B&&$==="single",k=M&&!T;let P;e[14]!==y.pinnedSessionIds||e[15]!==y.rootSessions||e[16]!==y.sessionOrderRanks||e[17]!==k||e[18]!==n.isVSCode?(P={enabled:k,isVSCode:n.isVSCode,pinnedSessionIds:y.pinnedSessionIds,sessionOrderRanks:y.sessionOrderRanks,sessions:y.rootSessions},e[14]=y.pinnedSessionIds,e[15]=y.rootSessions,e[16]=y.sessionOrderRanks,e[17]=k,e[18]=n.isVSCode,e[19]=P):P=e[19];const F=bg(P),[q,Q]=c.useState(null),[Y,ce]=c.useState(""),[X,oe]=c.useState(null),[te,he]=c.useState(null),[_,ie]=c.useState(null),[ge,ae]=c.useState(null);let z;e[20]===Symbol.for("react.memo_cache_sentinel")?(z=(Mt,Lt)=>{ae({scopeKey:Mt,folderId:Lt.id,draft:Lt.name})},e[20]=z):z=e[20];const ne=z;let ue;e[21]===Symbol.for("react.memo_cache_sentinel")?(ue=Mt=>{ae(Lt=>Lt?{...Lt,draft:Mt}:null)},e[21]=ue):ue=e[21];const me=ue;let ke;e[22]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>ae(null),e[22]=ke):ke=e[22];const Te=ke,{expandedParents:je,toggleParent:Ee}=vk(),xe=et(Ok);let H;e[23]!==xe?(H=(Mt,Lt)=>{Mt!==et.getState().currentSessionId&&xe(Mt,Lt)},e[23]=xe,e[24]=H):H=e[24];const Ce=H,ve=Gd();let re;e[25]!==y.pinnedSessionIds||e[26]!==y.sessionOrderRanks||e[27]!==n.gitBranches||e[28]!==n.isVSCode||e[29]!==n.worktreeMetadata||e[30]!==r.homeDirectory?(re={homeDirectory:r.homeDirectory,worktreeMetadata:n.worktreeMetadata,pinnedSessionIds:y.pinnedSessionIds,sessionOrderRanks:y.sessionOrderRanks,gitBranches:n.gitBranches,isVSCode:n.isVSCode},e[25]=y.pinnedSessionIds,e[26]=y.sessionOrderRanks,e[27]=n.gitBranches,e[28]=n.isVSCode,e[29]=n.worktreeMetadata,e[30]=r.homeDirectory,e[31]=re):re=e[31];const{buildGroupedSessions:le,filterSessionNodesForSearch:se,buildGroupSearchText:G}=Y2(re);let U;e[32]!==y.archivedSessions||e[33]!==y.sessions||e[34]!==n.availableWorktreesByProject||e[35]!==n.isVSCode||e[36]!==n.projects?(U=L0(y.sessions,n.projects,n.availableWorktreesByProject,n.isVSCode,y.archivedSessions),e[32]=y.archivedSessions,e[33]=y.sessions,e[34]=n.availableWorktreesByProject,e[35]=n.isVSCode,e[36]=n.projects,e[37]=U):U=e[37];const be=U;let W;e[38]!==be?(W={ownership:be},e[38]=be,e[39]=W):W=e[39];const{getSessionsForProject:Ne,getArchivedSessionsForProject:Oe}=$0(W);let ye;e:{if(n.isVSCode){ye=null;break e}let Mt;e[40]!==y.chatSessions||e[41]!==r.homeDirectory?(Mt=Gh(r.homeDirectory)??y.chatSessions.map(Bk).find(Boolean)??null,e[40]=y.chatSessions,e[41]=r.homeDirectory,e[42]=Mt):Mt=e[42];const Lt=Mt;if(!Lt){ye=null;break e}let ns;if(e[43]!==Lt||e[44]!==y.chatSessions){const Ge=[Lt,...y.chatSessions.map(Fk).filter(Boolean)];let L;e[46]!==Ge?(L=new Set(Ge),e[46]=Ge,e[47]=L):L=e[47],ns=Array.from(L).filter(_k).map(Lk),e[43]=Lt,e[44]=y.chatSessions,e[45]=ns}else ns=e[45];const us=ns;let xs;if(e[48]!==y.chatSessions||e[49]!==y.childrenMap){let Ge;e[51]!==y.childrenMap?(Ge=L=>({session:L,children:(y.childrenMap.get(L.id)??[]).filter(Wk).map(zk),worktree:null}),e[51]=y.childrenMap,e[52]=Ge):Ge=e[52],xs=y.chatSessions.filter($k).map(Ge),e[48]=y.chatSessions,e[49]=y.childrenMap,e[50]=xs}else xs=e[50];let Z;e[53]!==Lt||e[54]!==us||e[55]!==xs?(Z={id:"managed-chats",label:"",branch:null,description:null,isMain:!0,worktree:null,directory:Lt,folderScopeKey:Lt,folderScopes:us,draftTarget:"chat",sessions:xs},e[53]=Lt,e[54]=us,e[55]=xs,e[56]=Z):Z=e[56],ye=Z}const Fe=ye;let Ke;e[57]!==Fe?(Ke=Fe?[Fe]:kk,e[57]=Fe,e[58]=Ke):Ke=e[58];const $e=Ke;let V;e[59]!==G||e[60]!==le||e[61]!==se||e[62]!==h||e[63]!==Oe||e[64]!==Ne||e[65]!==$e||e[66]!==n.availableWorktreesByProject||e[67]!==n.gitBranches||e[68]!==n.lastRepoStatus||e[69]!==n.projectRepoStatus||e[70]!==n.projectRootBranches||e[71]!==n.projects||e[72]!==r.hasSessionSearchQuery||e[73]!==r.normalizedSessionSearchQuery?(V={normalizedProjects:n.projects,getSessionsForProject:Ne,getArchivedSessionsForProject:Oe,availableWorktreesByProject:n.availableWorktreesByProject,projectRepoStatus:n.projectRepoStatus,projectRootBranches:n.projectRootBranches,gitBranches:n.gitBranches,lastRepoStatus:n.lastRepoStatus,buildGroupedSessions:le,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,filterSessionNodesForSearch:se,buildGroupSearchText:G,foldersMap:h,standaloneGroups:$e},e[59]=G,e[60]=le,e[61]=se,e[62]=h,e[63]=Oe,e[64]=Ne,e[65]=$e,e[66]=n.availableWorktreesByProject,e[67]=n.gitBranches,e[68]=n.lastRepoStatus,e[69]=n.projectRepoStatus,e[70]=n.projectRootBranches,e[71]=n.projects,e[72]=r.hasSessionSearchQuery,e[73]=r.normalizedSessionSearchQuery,e[74]=V):V=e[74];const{projectSections:fe,groupSearchDataByGroup:Me,sectionsForRender:De,flatSectionsForRender:at,searchMatchCount:Qe}=V0(V),lt=r.onSearchMatchCountChange;let de,J;e[75]!==lt||e[76]!==Qe?(de=()=>{lt(Qe)},J=[lt,Qe],e[75]=lt,e[76]=Qe,e[77]=de,e[78]=J):(de=e[77],J=e[78]),c.useEffect(de,J);let Se,Ve;e[79]!==lt?(Se=()=>()=>lt(0),Ve=[lt],e[79]=lt,e[80]=Se,e[81]=Ve):(Se=e[80],Ve=e[81]),c.useEffect(Se,Ve);const He=Fa(),it=`session-collection-expansion:${c.useId()}`;let Ue,st;e[82]!==He||e[83]!==it||e[84]!==fe||e[85]!==g.collapsedGroups||e[86]!==g.collapsedProjects||e[87]!==r.activeProjectId?(Ue=()=>(He.setBootstrapDemand(it,hm({projectSections:fe,activeProjectId:r.activeProjectId,collapsedProjects:g.collapsedProjects,collapsedGroups:g.collapsedGroups,currentDirectory:null,currentSessionDirectory:null})),()=>He.clearBootstrapDemand(it)),st=[He,it,fe,g.collapsedProjects,g.collapsedGroups,r.activeProjectId],e[82]=He,e[83]=it,e[84]=fe,e[85]=g.collapsedGroups,e[86]=g.collapsedProjects,e[87]=r.activeProjectId,e[88]=Ue,e[89]=st):(Ue=e[88],st=e[89]),c.useEffect(Ue,st);const ee=r.useGroupedSections?De:at;let ze;e[90]!==ee||e[91]!==r.showInlineArchived?(ze=r.showInlineArchived?ee:ee.map(Kk),e[90]=ee,e[91]=r.showInlineArchived,e[92]=ze):ze=e[92];const _e=ze;let pe;e[93]!==at?(pe=Mt=>at.find(ns=>ns.project.id===Mt)?.groups.find(Hk)?.folderScopes??[],e[93]=at,e[94]=pe):pe=e[94];const qe=pe;let tt;e[95]===Symbol.for("react.memo_cache_sentinel")?(tt=new Map,e[95]=tt):tt=e[95];const pt=c.useRef(tt);let gt;e[96]!==fe||e[97]!==r.isDesktopShellRuntime||e[98]!==r.stickyZoneHeaders?(gt={enabled:r.stickyZoneHeaders,isDesktopShellRuntime:r.isDesktopShellRuntime,projectSections:fe,projectHeaderSentinelRefs:pt},e[96]=fe,e[97]=r.isDesktopShellRuntime,e[98]=r.stickyZoneHeaders,e[99]=gt):gt=e[99];const Je=X2(gt);let St;e[100]!==p||e[101]!==y.hasAuthoritativeGlobalSessions||e[102]!==f||e[103]!==h||e[104]!==be||e[105]!==n.projects||e[106]!==r.isSessionsLoading||e[107]!==r.isWorktreeTopologyLoading||e[108]!==r.unresolvedWorktreeProjectPaths?(St={enabled:!0,normalizedProjects:n.projects,ownership:be,isSessionsLoading:r.isSessionsLoading,hasAuthoritativeGlobalSessions:y.hasAuthoritativeGlobalSessions,isWorktreeTopologyLoading:r.isWorktreeTopologyLoading,unresolvedWorktreeProjectPaths:r.unresolvedWorktreeProjectPaths,foldersMap:h,createFolder:f,addSessionToFolder:p},e[100]=p,e[101]=y.hasAuthoritativeGlobalSessions,e[102]=f,e[103]=h,e[104]=be,e[105]=n.projects,e[106]=r.isSessionsLoading,e[107]=r.isWorktreeTopologyLoading,e[108]=r.unresolvedWorktreeProjectPaths,e[109]=St):St=e[109],P0(St);const{github:Ze}=wn(),vt=Dn(Gk),rt=Dn(qk),we=Ks(Qk),ct=Ks(Yk),dt=Ks(Xk);let At;e[110]===Symbol.for("react.memo_cache_sentinel")?(At=new Set,e[110]=At):At=e[110];const We=c.useRef(At);let Xe;e[111]!==we||e[112]!==Ze||e[113]!==rt||e[114]!==vt||e[115]!==fe||e[116]!==g.collapsedProjects||e[117]!==dt||e[118]!==ct||e[119]!==n.gitBranches?(Xe=()=>{if(!Ze||!rt||!vt?.connected)return;const Mt=new Map,Lt=Date.now();fe.forEach(ns=>{g.collapsedProjects.has(ns.project.id)||ns.groups.forEach(us=>{if(us.isArchivedBucket||us.isMain)return;const xs=wt(us.directory??null),Z=us.branch?.trim()||n.gitBranches.get(xs||"")?.trim();if(!xs||!Z)return;const Ge=Zo(xs,Z),L=Ks.getState().entries[Ge],Le=L?.status?.pr?.state==="closed"||L?.status?.pr?.state==="merged",ot=`${xs}::${Z}`,jt=Math.max(L?.lastRefreshAt??0,L?.lastDiscoveryPollAt??0),Ct=!!(L?.isInitialStatusResolved&&(!L.status?.pr||Le)&&(!We.current.has(ot)||Lt-jt>=jk));(!L||!L.isInitialStatusResolved||Ct)&&(Ct&&We.current.add(ot),Mt.set(Ge,{directory:xs,branch:Z}))})}),Mt.forEach((ns,us)=>{we(us),ct(us,{...ns,remoteName:null,canShow:!0,github:Ze,githubAuthChecked:rt,githubConnected:vt.connected})}),Mt.size&&dt([...Mt.values()],{silent:!0,markInitialResolved:!0})},e[111]=we,e[112]=Ze,e[113]=rt,e[114]=vt,e[115]=fe,e[116]=g.collapsedProjects,e[117]=dt,e[118]=ct,e[119]=n.gitBranches,e[120]=Xe):Xe=e[120];const Tt=vt?.connected;let ut;e[121]!==we||e[122]!==Ze||e[123]!==rt||e[124]!==fe||e[125]!==g.collapsedProjects||e[126]!==dt||e[127]!==ct||e[128]!==Tt||e[129]!==n.gitBranches?(ut=[we,Ze,rt,Tt,fe,g.collapsedProjects,dt,ct,n.gitBranches],e[121]=we,e[122]=Ze,e[123]=rt,e[124]=fe,e[125]=g.collapsedProjects,e[126]=dt,e[127]=ct,e[128]=Tt,e[129]=n.gitBranches,e[130]=ut):ut=e[130],c.useEffect(Xe,ut);let kt;e[131]!==y.orderedSessions?(kt=new Map(y.orderedSessions.map(Jk)),e[131]=y.orderedSessions,e[132]=kt):kt=e[132];const Rt=kt;let ss;if(e[133]!==w||e[134]!==_e){let Mt;e[136]!==w?(Mt=Lt=>{const ns=w(Lt.project.id,Lt.groups);return ns===Lt.groups?Lt:{...Lt,groups:ns}},e[136]=w,e[137]=Mt):Mt=e[137],ss=_e.map(Mt),e[133]=w,e[134]=_e,e[135]=ss}else ss=e[135];const Ut=ss;let Wt;e[138]!==fe||e[139]!==E||e[140]!==T||e[141]!==r.activeProjectId?(Wt=null,T&&(fe.some(Mt=>Mt.project.id===E)?Wt=E:fe.some(Mt=>Mt.project.id===r.activeProjectId)?Wt=r.activeProjectId:Wt=fe[0]?.project.id??null),e[138]=fe,e[139]=E,e[140]=T,e[141]=r.activeProjectId,e[142]=Wt):Wt=e[142];const Qt=T&&!r.useGroupedSections?20:void 0;let Kt;e[143]!==i.startSessionWorktreeMenuLoad||e[144]!==o||e[145]!==y.pinnedSessionIds||e[146]!==_||e[147]!==te||e[148]!==Y||e[149]!==q||e[150]!==je||e[151]!==ge||e[152]!==Me||e[153]!==l||e[154]!==g.collapsedGroups||e[155]!==u.allowReselect||e[156]!==u.isSessionSearchOpen||e[157]!==u.onSessionSelected||e[158]!==u.sessionSearchQuery||e[159]!==u.setIsSessionSearchOpen||e[160]!==u.setSessionSearchQuery||e[161]!==Rt||e[162]!==Qt||e[163]!==Ee||e[164]!==r.activeProjectId||e[165]!==r.hasSessionSearchQuery||e[166]!==r.hideDirectoryControls||e[167]!==r.mobileVariant||e[168]!==r.normalizedSessionSearchQuery?(Kt={hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,groupSearchDataByGroup:Me,collapsedGroups:g.collapsedGroups,hideDirectoryControls:r.hideDirectoryControls,mobileVariant:r.mobileVariant,alwaysShowActions:o,activeProjectId:r.activeProjectId,notifyOnSubtasks:l,pinnedSessionIds:y.pinnedSessionIds,sessionOrderIndex:Rt,expandedParents:je,editingId:q,editTitle:Y,copiedSessionId:_,sessionBatchSize:Qt,setEditingId:Q,setEditTitle:ce,toggleParent:Ee,allowReselect:u.allowReselect,onSessionSelected:u.onSessionSelected,isSessionSearchOpen:u.isSessionSearchOpen,sessionSearchQuery:u.sessionSearchQuery,setSessionSearchQuery:u.setSessionSearchQuery,setIsSessionSearchOpen:u.setIsSessionSearchOpen,deleteSessionConfirm:te,setDeleteSessionConfirm:he,startFolderRename:ne,setCopiedSessionId:ie,startSessionWorktreeMenuLoad:i.startSessionWorktreeMenuLoad,folderRename:ge,setFolderRenameDraft:me,clearFolderRename:Te},e[143]=i.startSessionWorktreeMenuLoad,e[144]=o,e[145]=y.pinnedSessionIds,e[146]=_,e[147]=te,e[148]=Y,e[149]=q,e[150]=je,e[151]=ge,e[152]=Me,e[153]=l,e[154]=g.collapsedGroups,e[155]=u.allowReselect,e[156]=u.isSessionSearchOpen,e[157]=u.onSessionSelected,e[158]=u.sessionSearchQuery,e[159]=u.setIsSessionSearchOpen,e[160]=u.setSessionSearchQuery,e[161]=Rt,e[162]=Qt,e[163]=Ee,e[164]=r.activeProjectId,e[165]=r.hasSessionSearchQuery,e[166]=r.hideDirectoryControls,e[167]=r.mobileVariant,e[168]=r.normalizedSessionSearchQuery,e[169]=Kt):Kt=e[169];const Ft=Kt;let $t;e[170]!==d.openNewSessionDraft||e[171]!==d.setActiveProjectIdOnly||e[172]!==d.setSessionSwitcherOpen||e[173]!==x?($t={showMoreGroupSessions:A,resetGroupSessionLimit:I,setActiveProjectIdOnly:d.setActiveProjectIdOnly,setSessionSwitcherOpen:d.setSessionSwitcherOpen,openNewSessionDraft:d.openNewSessionDraft,onToggleCollapsedGroup:x},e[170]=d.openNewSessionDraft,e[171]=d.setActiveProjectIdOnly,e[172]=d.setSessionSwitcherOpen,e[173]=x,e[174]=$t):$t=e[174];const Be=$t;let Ye;e[175]!==Fe||e[176]!==Be||e[177]!==Ft||e[178]!==X?(Ye=()=>Fe?s.jsx(Do,{...Ft,...Be,group:Fe,groupKey:"managed-chats",projectId:null,hideGroupLabel:!0,sessionBatchSize:20,scrollContainerRef:void 0,openSidebarMenuKey:X,setOpenSidebarMenuKey:oe}):null,e[175]=Fe,e[176]=Be,e[177]=Ft,e[178]=X,e[179]=Ye):Ye=e[179];const ft=Ye;let yt;e[180]!==d||e[181]!==r.mobileVariant?(yt=()=>{Pe.getState().closeMainSurfaces(),r.mobileVariant&&d.setSessionSwitcherOpen(!1),d.openNewSessionDraft({selectedProjectId:qh,directoryOverride:null})},e[180]=d,e[181]=r.mobileVariant,e[182]=yt):yt=e[182];const ht=yt;let mt;e[183]!==i.startSessionWorktreeMenuLoad||e[184]!==o||e[185]!==y.chatSessions||e[186]!==y.childrenMap||e[187]!==y.pinnedSessionIds||e[188]!==_||e[189]!==te||e[190]!==Y||e[191]!==q||e[192]!==je||e[193]!==ht||e[194]!==l||e[195]!==X||e[196]!==F||e[197]!==ft||e[198]!==u.allowReselect||e[199]!==u.isSessionSearchOpen||e[200]!==u.onSessionSelected||e[201]!==u.sessionSearchQuery||e[202]!==u.setIsSessionSearchOpen||e[203]!==u.setSessionSearchQuery||e[204]!==M||e[205]!==T||e[206]!==Ee||e[207]!==n.availableWorktreesByProject||e[208]!==n.gitBranches||e[209]!==n.isVSCode||e[210]!==n.projects||e[211]!==r.hasSessionSearchQuery||e[212]!==r.homeDirectory||e[213]!==r.isDesktopShellRuntime||e[214]!==r.mobileVariant||e[215]!==r.normalizedSessionSearchQuery?(mt=n.isVSCode?null:s.jsx(xk,{projects:n.projects,availableWorktreesByProject:n.availableWorktreesByProject,gitBranches:n.gitBranches,homeDirectory:r.homeDirectory,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,isDesktopShellRuntime:r.isDesktopShellRuntime,sessions:F,childrenMap:y.childrenMap,pinnedSessionIds:y.pinnedSessionIds,recentSessions:F,expandedParents:je,notifyOnSubtasks:l,editingId:q,editTitle:Y,copiedSessionId:_,openSidebarMenuKey:X,mobileVariant:r.mobileVariant,alwaysShowActions:o,setEditingId:Q,setEditTitle:ce,toggleParent:Ee,setOpenSidebarMenuKey:oe,allowReselect:u.allowReselect,onSessionSelected:u.onSessionSelected,isSessionSearchOpen:u.isSessionSearchOpen,sessionSearchQuery:u.sessionSearchQuery,setSessionSearchQuery:u.setSessionSearchQuery,setIsSessionSearchOpen:u.setIsSessionSearchOpen,deleteSessionConfirm:te,setDeleteSessionConfirm:he,startFolderRename:ne,setCopiedSessionId:ie,startSessionWorktreeMenuLoad:i.startSessionWorktreeMenuLoad,chatSessions:y.chatSessions,renderChatsSection:ft,onNewChat:ht,showRecentSection:M&&!T}),e[183]=i.startSessionWorktreeMenuLoad,e[184]=o,e[185]=y.chatSessions,e[186]=y.childrenMap,e[187]=y.pinnedSessionIds,e[188]=_,e[189]=te,e[190]=Y,e[191]=q,e[192]=je,e[193]=ht,e[194]=l,e[195]=X,e[196]=F,e[197]=ft,e[198]=u.allowReselect,e[199]=u.isSessionSearchOpen,e[200]=u.onSessionSelected,e[201]=u.sessionSearchQuery,e[202]=u.setIsSessionSearchOpen,e[203]=u.setSessionSearchQuery,e[204]=M,e[205]=T,e[206]=Ee,e[207]=n.availableWorktreesByProject,e[208]=n.gitBranches,e[209]=n.isVSCode,e[210]=n.projects,e[211]=r.hasSessionSearchQuery,e[212]=r.homeDirectory,e[213]=r.isDesktopShellRuntime,e[214]=r.mobileVariant,e[215]=r.normalizedSessionSearchQuery,e[216]=mt):mt=e[216];const _t=mt;let Jt;e[217]!==Me||e[218]!==$e||e[219]!==r.hasSessionSearchQuery?(Jt=r.hasSessionSearchQuery&&$e.some(Mt=>Me.get(Mt)?.hasMatch===!0),e[217]=Me,e[218]=$e,e[219]=r.hasSessionSearchQuery,e[220]=Jt):Jt=e[220];const Yt=Jt,Ns=!!_t;let Xt;e[221]!==q||e[222]!==X||e[223]!==N?(Xt={editingId:q,openSidebarMenuKey:X,setOpenSidebarMenuKey:oe,visibleSessionCountByGroup:N},e[221]=q,e[222]=X,e[223]=N,e[224]=Xt):Xt=e[224];let zs;e[225]!==Ft||e[226]!==Ut||e[227]!==fe||e[228]!==_t||e[229]!==Wt||e[230]!==T||e[231]!==Je||e[232]!==Ns||e[233]!==Xt||e[234]!==Yt||e[235]!==n.projectRepoStatus||e[236]!==r.activeProjectId||e[237]!==r.emptyState||e[238]!==r.searchEmptyState?(zs={topContent:_t,topContentHasSearchMatches:Yt,hasSharedSessions:Ns,sectionsForRender:Ut,projectSections:fe,activeProjectId:r.activeProjectId,singleProjectMode:T,singleProjectId:Wt,emptyState:r.emptyState,searchEmptyState:r.searchEmptyState,projectRepoStatus:n.projectRepoStatus,stuckProjectHeaders:Je,projectHeaderSentinelRefs:pt,state:Xt,groupProps:Ft},e[225]=Ft,e[226]=Ut,e[227]=fe,e[228]=_t,e[229]=Wt,e[230]=T,e[231]=Je,e[232]=Ns,e[233]=Xt,e[234]=Yt,e[235]=n.projectRepoStatus,e[236]=r.activeProjectId,e[237]=r.emptyState,e[238]=r.searchEmptyState,e[239]=zs):zs=e[239];const Js=zs;let rs;e[240]!==o||e[241]!==g.collapsedProjects||e[242]!==r.hasSessionSearchQuery||e[243]!==r.hideDirectoryControls||e[244]!==r.homeDirectory||e[245]!==r.isDesktopShellRuntime||e[246]!==r.mobileVariant||e[247]!==r.normalizedSessionSearchQuery||e[248]!==r.projectSortOrder||e[249]!==r.showOnlyMainWorkspace||e[250]!==r.stickyZoneHeaders?(rs={homeDirectory:r.homeDirectory,collapsedProjects:g.collapsedProjects,showOnlyMainWorkspace:r.showOnlyMainWorkspace,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,hideDirectoryControls:r.hideDirectoryControls,isDesktopShellRuntime:r.isDesktopShellRuntime,stickyZoneHeaders:r.stickyZoneHeaders,mobileVariant:r.mobileVariant,alwaysShowActions:o,projectSortOrder:r.projectSortOrder},e[240]=o,e[241]=g.collapsedProjects,e[242]=r.hasSessionSearchQuery,e[243]=r.hideDirectoryControls,e[244]=r.homeDirectory,e[245]=r.isDesktopShellRuntime,e[246]=r.mobileVariant,e[247]=r.normalizedSessionSearchQuery,e[248]=r.projectSortOrder,e[249]=r.showOnlyMainWorkspace,e[250]=r.stickyZoneHeaders,e[251]=rs):rs=e[251];const Vs=rs;let Es;e[252]!==Be||e[253]!==d.openNewSessionDraft||e[254]!==d.openNewWorktreeDialog||e[255]!==d.openProjectEditDialog||e[256]!==d.openWorktreesPage||e[257]!==d.removeProject||e[258]!==d.renderProjectStatusIndicator||e[259]!==d.reorderProjects||e[260]!==d.setActiveProjectIdOnly||e[261]!==d.setSessionSwitcherOpen||e[262]!==v||e[263]!==K||e[264]!==m?(Es={group:Be,toggleProject:m,setActiveProjectIdOnly:d.setActiveProjectIdOnly,setSessionSwitcherOpen:d.setSessionSwitcherOpen,openNewSessionDraft:d.openNewSessionDraft,openNewWorktreeDialog:d.openNewWorktreeDialog,openWorktreesPage:d.openWorktreesPage,openProjectEditDialog:d.openProjectEditDialog,removeProject:d.removeProject,reorderProjects:d.reorderProjects,setGroupOrderByProject:v,renderProjectStatusIndicator:d.renderProjectStatusIndicator,setSingleProjectId:K},e[252]=Be,e[253]=d.openNewSessionDraft,e[254]=d.openNewWorktreeDialog,e[255]=d.openProjectEditDialog,e[256]=d.openWorktreesPage,e[257]=d.removeProject,e[258]=d.renderProjectStatusIndicator,e[259]=d.reorderProjects,e[260]=d.setActiveProjectIdOnly,e[261]=d.setSessionSwitcherOpen,e[262]=v,e[263]=K,e[264]=m,e[265]=Es):Es=e[265];const ln=Es;let gs;e[266]===Symbol.for("react.memo_cache_sentinel")?(gs=s.jsx(C0,{}),e[266]=gs):gs=e[266];let vs;e[267]!==i.initialActiveSessionByProject||e[268]!==i.openNewSessionDraft||e[269]!==i.persistActiveSessionByProject||e[270]!==i.setSessionSwitcherOpen||e[271]!==be.bySessionId||e[272]!==fe||e[273]!==Ce||e[274]!==r.activeProjectId||e[275]!==r.mobileVariant?(vs=s.jsx(R0,{projectSections:fe,activeProjectId:r.activeProjectId,initialActiveSessionByProject:i.initialActiveSessionByProject,persistActiveSessionByProject:i.persistActiveSessionByProject,mobileVariant:r.mobileVariant,openNewSessionDraft:i.openNewSessionDraft,setSessionSwitcherOpen:i.setSessionSwitcherOpen,sessionOwnerBySessionId:be.bySessionId,handleSessionSelect:Ce}),e[267]=i.initialActiveSessionByProject,e[268]=i.openNewSessionDraft,e[269]=i.persistActiveSessionByProject,e[270]=i.setSessionSwitcherOpen,e[271]=be.bySessionId,e[272]=fe,e[273]=Ce,e[274]=r.activeProjectId,e[275]=r.mobileVariant,e[276]=vs):vs=e[276];let Zs;e[277]!==y.orderedSessions||e[278]!==ve||e[279]!==F?(Zs=s.jsx(Q0,{sortedSessions:y.orderedSessions,recentSessions:F,prefetchSession:ve}),e[277]=y.orderedSessions,e[278]=ve,e[279]=F,e[280]=Zs):Zs=e[280];let Rs;e[281]!==ln||e[282]!==Js||e[283]!==Vs?(Rs=s.jsx(Q2,{model:Js,view:Vs,actions:ln}),e[281]=ln,e[282]=Js,e[283]=Vs,e[284]=Rs):Rs=e[284];const As=q!==null;let Ds;e[285]!==qe||e[286]!==As?(Ds=s.jsx(nk,{getFolderScopesForProject:qe,isInlineEditing:As,startFolderRename:ne}),e[285]=qe,e[286]=As,e[287]=Ds):Ds=e[287];let js;return e[288]!==vs||e[289]!==Zs||e[290]!==Rs||e[291]!==Ds?(js=s.jsxs(s.Fragment,{children:[gs,vs,Zs,Rs,Ds]}),e[288]=vs,e[289]=Zs,e[290]=Rs,e[291]=Ds,e[292]=js):js=e[292],js},Ak=t=>{const e=nt.c(2);let n;return e[0]!==t?(n=t.view.isVisible?s.jsx(Nk,{...t}):null,e[0]=t,e[1]=n):n=e[1],n};function Dk(t){return t.foldersMap}function Pk(t){return t.createFolder}function Ik(t){return t.addSessionToFolder}function Tk(t){return t.showRecentSection}function Ek(t){return t.projectDisplayMode}function Rk(t){return t.singleProjectId}function Mk(t){return t.setSingleProjectId}function Ok(t){return t.setCurrentSession}function Bk(t){return Yd(t.directory)}function Fk(t){return wt(t.directory??null)}function _k(t){return!!t}function Lk(t){return{scopeKey:t,directory:t}}function $k(t){return!t.time?.archived&&Ck(t)}function Wk(t){return!t.time?.archived}function zk(t){return{session:t,children:[],worktree:null}}function Vk(t){return t.isArchivedBucket}function Uk(t){return!t.isArchivedBucket}function Kk(t){return t.groups.some(Vk)?{...t,groups:t.groups.filter(Uk)}:t}function Hk(t){return!t.isArchivedBucket}function Gk(t){return t.status}function qk(t){return t.hasChecked}function Qk(t){return t.ensureEntry}function Yk(t){return t.setParams}function Xk(t){return t.refreshTargets}function Jk(t,e){return[t.id,e]}const km=(t,e,n)=>{const r=new Set;for(const i of t){const o=wt(i.path)?.toLowerCase();o&&r.add(o)}if(n?.includeWorktrees===!1)return r;for(const i of e.values())for(const o of i){const l=wt(o.path)?.toLowerCase();l&&r.add(l)}return r},_c="oc.sessions.activeSessionByProject",Zk=[],e4=vu(wr(),wr().min(1).catch("")),t4=({isVisible:t=!0,mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:i=!1,showOnlyMainWorkspace:o=!1})=>{Di("react.session_sidebar_render"),Gs("ui.session_sidebar.render"),Gs(`ui.session_sidebar.render.${e?"mobile":"desktop"}`),Gs(`ui.session_sidebar.render.${t?"visible":"hidden"}`);const{t:l}=Nt(),[a,u]=c.useState(!1),[d,h]=c.useState(""),[f,p]=c.useState(0),g=c.useRef(null),w=c.useRef(null),[v,x]=c.useState(null),m=c.useMemo(()=>Eo(),[]),[b,y]=c.useState(new Map),S=Pe(we=>we.isNewWorktreeDialogOpen),N=Pe(we=>we.setNewWorktreeDialogOpen),[C,j]=c.useState(!1),A=c.useMemo(()=>{try{const we=m.getItem(_c);if(!we)return new Map;const ct=e4.safeParse(JSON.parse(we));if(!ct.success)return new Map;const dt=new Map;return Object.entries(ct.data).forEach(([At,We])=>{We&&dt.set(At,We)}),dt}catch{return new Map}},[m]),D=c.useCallback(we=>{try{m.setItem(_c,JSON.stringify(Object.fromEntries(we.entries())))}catch{}},[m]),[I,M]=c.useState(new Map),$=es(we=>we.homeDirectory),E=Vt(we=>we.projects),K=Vt(we=>we.activeProjectId),B=Vt(we=>we.removeProject),O=Vt(we=>we.setActiveProjectIdOnly),T=Vt(we=>we.updateProjectMeta),k=Vt(we=>we.reorderProjects),P=Pe(we=>we.setSettingsDialogOpen),F=Pe(we=>we.toggleHelpDialog),q=Pe(we=>we.setAboutDialogOpen),Q=Pe(we=>we.setSessionSwitcherOpen),Y=Pe(we=>we.setScheduledTasksDialogOpen),ce=Pe(we=>we.setArchivePageOpen),X=Pe(we=>we.setWorktreesPageProjectId),oe=Pe(we=>we.openMultiRunLauncher),te=Pe(we=>we.notifyOnSubtasks),he=Pa(d,120),_=c.useMemo(()=>he.trim().toLowerCase(),[he]),ie=_.length>0;Gv({enabled:t,isSessionSearchOpen:a,setIsSessionSearchOpen:u,sessionSearchInputRef:w,sessionSearchContainerRef:g});const ge=_d(t),ae=c.useMemo(()=>Pn(),[]),z=et(we=>we.setCurrentSession),ne=et(we=>we.worktreeMetadata),ue=et(we=>we.availableWorktreesByProject),me=et(we=>we.openNewSessionDraft),ke=c.useMemo(()=>km(E,ue,{includeWorktrees:!ae}),[ue,ae,E]),Te=c.useCallback(we=>{Pe.getState().closeMainSurfaces(),me(we),ae&&window.dispatchEvent(new CustomEvent("openchamber:navigate",{detail:{view:"chat"}}))},[ae,me]),je=Fr(Zn(we=>({checkForUpdates:we.checkForUpdates,available:we.available,runtimeType:we.runtimeType,info:we.info,downloading:we.downloading,downloaded:we.downloaded,progress:we.progress,error:we.error,downloadUpdate:we.downloadUpdate,restartToUpdate:we.restartToUpdate}))),Ee=ps(),xe=c.useMemo(()=>`${Ee}|${E.map(we=>`${we.id}:${wt(we.path)??""}`).join("|")}`,[E,Ee]),[H,Ce]=c.useState(ae?xe:null),[ve,re]=c.useReducer(we=>we+1,0),le=!ae&&H!==xe,[se,G]=c.useState(new Set),U=c.useRef({runtimeKey:null,revision:0,worktreesByProject:new Map});c.useEffect(()=>{let we=!1;return(async()=>{const dt=Ee,At=Vt.getState().projects;if(At.length===0||ae){we||(U.current={runtimeKey:null,revision:0,worktreesByProject:new Map},G(new Set),Ce(xe));return}const We=et.getState().availableWorktreesByProject,Xe=ua({rawWorktreesByProjectRef:U,publishedWorktreesByProject:We,runtimeKey:dt}),Tt=Xe.revision,ut=new Map(Xe.worktreesByProject),kt=new Set,Rt=3;let ss=0;const Ut=Array.from({length:Rt},async()=>{for(;;){const Kt=ss;if(ss+=1,Kt>=At.length)return;const Ft=At[Kt],$t=wt(Ft.path);if($t)try{const Be=await Mi(async()=>Bn.getState().directories.get($t)?.isGitRepo??await Jo($t)?gl({id:Ft.id,path:$t}):null);if(Be===null){ut.delete($t);continue}if(we)return;Be.length===0?ut.delete($t):ut.set($t,Be)}catch{kt.add($t)}}});if(await Promise.all(Ut),we||ps()!==dt)return;const Wt=new Set(At.map(Kt=>wt(Kt.path)).filter(Boolean));for(const Kt of ut.keys())Wt.has(Kt)||ut.delete(Kt);a2({rawWorktreesByProjectRef:U,runtimeKey:dt,capturedRevision:Tt,nextRawWorktreesByProject:ut,publishedWorktreesByProject:We,partitionWorktreesByRegisteredProject:bl,projects:At,worktreeMapsEqual:xl,recordWorktreesSeen:Oc,publishTopology:Kt=>{et.setState(Kt)},requestRediscovery:()=>{re()},now:()=>Date.now()})&&(G(kt),Ce(xe))})(),()=>{we=!0}},[ae,xe,Ee,ve]),c.useEffect(()=>{if(!ae)return eo(we=>{we.type==="session-created"&&re()})},[ae]),c.useEffect(()=>{if(!ae)return Qh(()=>re())},[ae]);const be=c.useMemo(()=>xn(),[]),{isTablet:W}=Ln(),Ne=e||W,Oe=c.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:l("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:l("sessions.sidebar.empty.noSessions.description")})]}),[l]),ye=c.useMemo(()=>E.find(we=>we.id===v)??null,[E,v]),Fe=c.useCallback(we=>{v&&T(v,{label:we.label,icon:we.icon,color:we.color,iconBackground:we.iconBackground,defaultModel:we.defaultModel??null})},[v,T]),Ke=c.useCallback(()=>{N(!0)},[N]),$e=c.useCallback(()=>{const we=Fr.getState();if(we.available&&we.info){j(!0);return}je.checkForUpdates().then(()=>{const{available:ct,error:dt}=Fr.getState();if(dt){Re.error(l("sessions.sidebar.updateCheck.errorTitle"),{description:dt});return}if(!ct){Re.success(l("sessions.sidebar.updateCheck.latestVersion"));return}j(!0)})},[l,je]),V=c.useCallback(()=>{e&&Q(!1),P(!0)},[e,Q,P]),fe=je.available&&(je.runtimeType==="desktop"||je.runtimeType==="web"),Me=c.useCallback(()=>{gn.requestDirectoryDialog()},[]),De=c.useMemo(()=>E.flatMap(we=>{const ct=wt(we.path);return ct?[{id:we.id,path:we.path,label:we.label,normalizedPath:ct,icon:we.icon??void 0,color:we.color??void 0,iconImage:we.iconImage??void 0,iconBackground:we.iconBackground??void 0,addedAt:we.addedAt,lastOpenedAt:we.lastOpenedAt,sidebarCollapsed:we.sidebarCollapsed}]:[]}),[E]),at=c.useMemo(()=>De.map(we=>we.normalizedPath),[De]),Qe=Yh(t?at:Zk);t0({enabled:t,normalizedProjects:De,gitRepoStatus:Qe,setProjectRepoStatus:y,setProjectRootBranches:M});const lt=et(we=>we.isLoading),de=c.useRef(!1);K&&b.has(K)&&(de.current=!!b.get(K));const J=ls(we=>we.showArchivedSessions),Se=ls(we=>we.projectSortOrder),Ve=ls(we=>we.stickyZoneHeaders),He=Vt(we=>we.manualProjectOrder),it={isVisible:t,mobileVariant:e,onSessionSelected:n,allowReselect:r,hideDirectoryControls:i,showOnlyMainWorkspace:o,t:l,isTablet:W,projects:E,activeProjectId:K,manualProjectOrder:He,worktreeMetadata:ne,availableWorktreesByProject:ue,gitBranches:ge,gitRepoStatus:Qe,updateStore:je,showArchivedSessions:J,projectSortOrder:Se,projectRepoStatus:b,projectRootBranches:I,resolvedWorktreeTopologyKey:H,unresolvedWorktreeProjectPaths:se,isSessionSearchOpen:a,sessionSearchQuery:d,editingProjectDialogId:v,updateDialogOpen:C},Ue=c.useRef(null),st=Ue.current;if(st){let we=!1;for(const ct of Object.keys(it))Object.is(st[ct],it[ct])||(Gs(`ui.session_sidebar.source.${ct}`),we=!0);we||Gs("ui.session_sidebar.source.parent_or_context")}Ue.current=it;const ee=c.useMemo(()=>{const we=[...De];switch(Se){case"a-z":we.sort((ct,dt)=>{const At=(ct.label||ct.path).toLowerCase(),We=(dt.label||dt.path).toLowerCase();return At.localeCompare(We)});break;case"z-a":we.sort((ct,dt)=>{const At=(ct.label||ct.path).toLowerCase();return(dt.label||dt.path).toLowerCase().localeCompare(At)});break;case"date-added":we.sort((ct,dt)=>(dt.addedAt??0)-(ct.addedAt??0));break;case"recent":we.sort((ct,dt)=>(dt.lastOpenedAt??0)-(ct.lastOpenedAt??0));break;case"manual":{const ct=new Map(He.map((dt,At)=>[dt,At]));we.sort((dt,At)=>{const We=ct.get(dt.id)??1/0,Xe=ct.get(At.id)??1/0;return We-Xe});break}}return we},[De,Se,He]),ze=Xv({isVSCode:ae,projects:ee}),_e=c.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:l("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:l("sessions.sidebar.empty.noMatches.description")})]}),[l]),pe=ae&&J,tt=ls(we=>we.sessionGroupingMode)==="by-worktree"&&!ae,Je=e?"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed":"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed",St="h-4.5 w-4.5",Ze=c.useCallback(()=>{e&&Q(!1),oe()},[e,oe,Q]),vt=c.useCallback(we=>{const ct=we.projectId?E.find(dt=>dt.id===we.projectId)??null:we.sourceDirectory?Ii(we.sourceDirectory):null;return i2(we,{projects:E,getCurrentProjects:()=>Vt.getState().projects,rawWorktreesByProjectRef:U,getPublishedWorktreesByProject:()=>et.getState().availableWorktreesByProject,resolveProject:dt=>Ii(dt),listProjectWorktrees:gl,partitionWorktreesByRegisteredProject:bl,worktreeMapsEqual:xl,recordWorktreesSeen:Oc,publishTopology:dt=>{et.setState(dt)},getRuntimeKey:ps,now:()=>Date.now(),projectRootBranch:ct?I.get(ct.id)??null:null})},[I,E]),rt=c.useCallback(()=>{Pe.getState().closeMainSurfaces(),e&&Q(!1),me()},[e,me,Q]);return s.jsx(_i,{delay:400,closeDelay:0,timeout:300,children:s.jsxs("div",{ref:g,className:Ie("relative flex h-full flex-col text-foreground overflow-x-hidden",e?"":"bg-transparent"),children:[!i&&!ae?s.jsx(v0,{onNewSession:rt}):null,s.jsx(l0,{hideDirectoryControls:i,showProjectDisplayControls:!ae,showRecentControls:!ae,handleOpenDirectoryDialog:Me,onOpenScheduled:()=>{e&&Q(!1),Y(!0)},onOpenMultiRun:Ze,canOpenMultiRun:E.length>0,onOpenArchive:()=>{e&&Q(!1),ce(!0)},headerActionIconClass:St,headerActionButtonClass:Je,isSessionSearchOpen:a,setIsSessionSearchOpen:u,sessionSearchInputRef:w,sessionSearchQuery:d,setSessionSearchQuery:h,hasSessionSearchQuery:ie,searchMatchCount:f,collapseAllProjects:ze.actions.collapseAllProjects,expandAllProjects:ze.actions.expandAllProjects}),s.jsx(Ak,{topology:{projects:ee,availableWorktreesByProject:ue,knownDirectories:ke,isVSCode:ae,worktreeMetadata:ne,gitBranches:ge,projectRepoStatus:b,projectRootBranches:I,lastRepoStatus:de.current},view:{isVisible:t,hasSessionSearchQuery:ie,normalizedSessionSearchQuery:_,activeProjectId:K,showInlineArchived:pe,useGroupedSections:tt,homeDirectory:$,mobileVariant:e,hideDirectoryControls:i,showOnlyMainWorkspace:o,isDesktopShellRuntime:be,stickyZoneHeaders:Ve,projectSortOrder:Se,emptyState:Oe,searchEmptyState:_e,isSessionsLoading:lt,isWorktreeTopologyLoading:le,unresolvedWorktreeProjectPaths:se,projectView:ze.state,onSearchMatchCountChange:p},actions:{rowActions:{allowReselect:r,onSessionSelected:n,isSessionSearchOpen:a,sessionSearchQuery:d,setSessionSearchQuery:h,setIsSessionSearchOpen:u},alwaysShowActions:Ne,notifyOnSubtasks:te,setActiveProjectIdOnly:O,setSessionSwitcherOpen:Q,openNewSessionDraft:Te,openNewWorktreeDialog:Ke,openWorktreesPage:we=>{e&&Q(!1),X(we)},openProjectEditDialog:x,removeProject:B,reorderProjects:k,startSessionWorktreeMenuLoad:vt,initialActiveSessionByProject:A,persistActiveSessionByProject:D,projectViewActions:ze.actions}}),s.jsx(j0,{onOpenSettings:V,onOpenShortcuts:F,onOpenAbout:()=>q(!0),onOpenUpdate:$e,showRuntimeButtons:!ae,showUpdateButton:fe}),s.jsx(ou,{open:C,onOpenChange:j,info:je.info,downloading:je.downloading,downloaded:je.downloaded,progress:je.progress,error:je.error,onDownload:je.downloadUpdate,onRestart:je.restartToUpdate,runtimeType:je.runtimeType}),s.jsx(i0,{open:!!ye,onOpenChange:we=>{we||x(null)},project:ye,onSave:Fe}),s.jsx(yg,{open:S,onOpenChange:N,onWorktreeCreated:(we,ct)=>{if(Pe.getState().closeMainSurfaces(),e&&Q(!1),ct?.sessionId){z(ct.sessionId,we);return}me({directoryOverride:we,preserveDirectoryOverride:!0})}})]})})},s4=c.memo(t4),jn=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,dn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},n4=()=>{const{t}=Nt(),[e,n]=c.useState(!1),[r,i]=c.useState(!1),[o,l]=c.useState(null),[a,u]=c.useState([]),[d,h]=c.useState(!1),[f,p]=c.useState(!1),[g,w]=c.useState(!1),[v,x]=c.useState(!1),[m,b]=c.useState(new Set),y=et(H=>H.getWorktreeMetadata),S=et(H=>H.newSessionDraft),N=et(H=>H.setNewSessionDraftTarget),C=et(H=>H.setDraftBootstrapPendingDirectory),j=Xh,A=et(H=>H.deleteSessions),D=et(H=>H.archiveSessions),I=Pe(H=>H.showDeletionDialog),M=Pe(H=>H.setShowDeletionDialog),$=es(H=>H.currentDirectory),E=es(H=>H.homeDirectory),K=es(H=>H.isHomeReady),B=Vt(H=>H.projects),O=Vt(H=>H.activeProjectId),{isMobile:T,isTablet:k,hasTouchInput:P}=Ln(),F=T||k||P,q=c.useMemo(()=>{const Ce=(O?B.find(ve=>ve.id===O)??null:null)?.path??$;return dn(Ce)},[O,$,B]),Q=c.useCallback(H=>{const ve=dn(H.projectDirectory)||q;return{id:(B.find(le=>dn(le.path)===ve)??null)?.id??`path:${ve}`,path:ve}},[q,B]),Y=v&&m.size>0,ce=c.useMemo(()=>{const H=o?.worktree;return H&&typeof H.branch=="string"&&H.branch.trim().length>0?!0:a.length>0&&a.every(({metadata:Ce})=>typeof Ce.branch=="string"&&Ce.branch.trim().length>0)},[o?.worktree,a]),X=o?.mode==="worktree",oe=X,te=g||!X||!ce,he=g||!X;c.useEffect(()=>{r||!K||B.length>0||(i(!0),n(!0))},[r,K,B.length]);const _=c.useCallback(H=>{l({sessions:H.sessions,dateLabel:H.dateLabel,mode:H.mode??"session",worktree:H.worktree??null})},[]),ie=c.useCallback(()=>{l(null),u([]),h(!1),p(!1),w(!1),x(!1),b(new Set)},[]),ge=c.useCallback(async H=>{if(H.sessions.length===0)return;if(H.sessions.length===1){const le=H.sessions[0];await j(le.id)?Re.success(t("sessions.sidebar.session.delete.success")):Re.error(t("sessions.sidebar.session.delete.error"));return}const Ce=H.sessions.map(le=>le.id),{deletedIds:ve,failedIds:re}=await A(Ce);if(ve.length>0){const le=re.length>0?re.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:re.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:re.length}):H.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:H.dateLabel}):void 0;Re.success(ve.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ve.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ve.length}),{description:jn(le)})}re.length>0&&Re.error(re.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:re.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:re.length}),{description:jn(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[j,A,t]);c.useEffect(()=>gn.onDeleteRequest(H=>{if(!I&&(H.mode??"session")==="session"){ge(H);return}_(H)}),[_,I,ge]),c.useEffect(()=>gn.onDirectoryRequest(()=>{n(!0)}),[]),c.useEffect(()=>{if(!o){u([]),h(!1),p(!1),x(!1),b(new Set);return}const H=o.sessions.map(re=>{const le=y(re.id);return le?{session:re,metadata:le}:null}).filter(re=>!!re);u(H),h(!1),x(!1),b(new Set);const Ce=new Map;if(o.worktree?.path&&Ce.set(dn(o.worktree.path),o.worktree),H.forEach(({metadata:re})=>{re.path&&Ce.set(dn(re.path),re)}),Ce.size===0){x(!0);return}let ve=!1;return(async()=>{const re=new Map,le=new Set;await Promise.all(Array.from(Ce.entries()).map(async([se,G])=>{try{const U=await Jh(G.path);re.set(se,U),U?.isDirty&&le.add(se)}catch{G.status&&(re.set(se,G.status),G.status.isDirty&&le.add(se))}})).catch(se=>{console.warn("Failed to inspect worktree status before deletion:",se)}),!ve&&(b(le),x(!0),l(se=>{if(!se?.worktree?.path)return se;const G=dn(se.worktree.path),U=re.get(G);if(!U)return se;const be=se.worktree.status;return be?.isDirty===U.isDirty&&be?.ahead===U.ahead&&be?.behind===U.behind&&be?.upstream===U.upstream?se:{...se,worktree:{...se.worktree,status:U}}}),u(se=>se.map(G=>{const U=dn(G.metadata.path),be=re.get(U);return be?{session:G.session,metadata:{...G.metadata,status:be}}:G})))})(),()=>{ve=!0}},[o,y]),c.useEffect(()=>{ce||h(!1)},[ce]);const ae=c.useCallback(async(H,Ce,ve)=>{const re=d&&ce,le=Q(H),se=dn(H.path),G=dn(le.path);try{await Nd(le,H,{deleteRemoteBranch:re,deleteLocalBranch:Ce});const U=dn(S?.directoryOverride);return S?.open&&se&&U===se&&G&&(C(null),N({projectId:le.id,directoryOverride:G},{force:!0})),dn($)===se&&G&&es.getState().setDirectory(G,{showOverlay:!1}),!0}catch(U){return Re.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle",{name:ci(H)}),{id:ve,description:jn(U instanceof Error?U.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ce,$,d,Q,S?.directoryOverride,S?.open,C,N,t]),z=c.useCallback((H,Ce,ve)=>{const re=d&&ce,le=Re.loading(t("sessions.sidebar.sessionDialogs.worktree.removingTitle",{name:ci(H)}));(async()=>{try{if(Ce.length>0){const{failedIds:U}=await D(Ce);if(U.length>0){Re.error(U.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:U.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:U.length}),{id:le,description:jn(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))});return}}if(!await ae(H,ve,le))return;const G=t(re?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");Re.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle",{name:ci(H)}),{id:le,description:jn(G)})}catch(se){Re.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{id:le,description:jn(se instanceof Error?se.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})}})()},[D,ce,d,ae,t]),ne=c.useCallback(async()=>{if(o){w(!0);try{const H=oe,Ce=H&&d,ve=H&&f;if(X&&o.worktree){z(o.worktree,o.sessions.map(re=>re.id),ve),ie();return}if(o.sessions.length===1){const re=o.sessions[0];if(!await j(re.id)){Re.error(t("sessions.sidebar.session.delete.error")),w(!1);return}const se=!X&&H?t(Ce?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;Re.success(t("sessions.sidebar.session.delete.success"),{description:jn(se),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const re=o.sessions.map(U=>U.id);let le=[],se=[];const G=await A(re);if(le=G.deletedIds,se=G.failedIds,le.length>0){const U=!X&&H?t(Ce?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,W=[se.length>0?se.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:se.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:se.length}):o.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:o.dateLabel}):void 0,U].filter(Boolean).join(" ");Re.success(le.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:le.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:le.length}),{description:jn(W||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(se.length>0&&(Re.error(se.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:se.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:se.length}),{description:jn(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),le.length===0)){w(!1);return}}ie()}finally{w(!1)}}},[o,d,f,j,A,ie,oe,X,z,t]),ue=o?.worktree??a[0]?.metadata??null,me=o?o.mode==="worktree"?o.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):o.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:o.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:o.sessions.length}):o.sessions.length===1?o.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:o.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):o.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:o.sessions.length,dateLabel:o.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:o.sessions.length}):"",ke=o?s.jsxs("div",{className:Ie(X?"space-y-3":"space-y-2"),children:[o.sessions.length>0&&s.jsxs("div",{className:Ie(X?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[X&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:o.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:o.sessions.length})]}),s.jsxs("ul",{className:Ie(X?"mt-2 space-y-1":"space-y-0.5"),children:[o.sessions.slice(0,5).map(H=>s.jsxs("li",{className:Ie(X?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:Ie(!X&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:H.title||t("sessions.sidebar.session.untitled")})]},H.id)),o.sessions.length>5&&s.jsx("li",{className:Ie(X?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:o.sessions.length-5})})]})]}),X?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),ue?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ue.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ue?Vr(ue.path,E):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),Y&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,Te=X?ce?s.jsxs("button",{type:"button",onClick:()=>{te||h(H=>!H)},disabled:te,className:Ie("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",te?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[d?s.jsx(R,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(R,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,je=X?s.jsxs("button",{type:"button",onClick:()=>{he||p(H=>!H)},disabled:he,className:Ie("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",he?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(R,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(R,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,Ee=X?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[je,Te]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(bt,{variant:"ghost",onClick:ie,disabled:g,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(bt,{variant:"destructive",onClick:ne,disabled:g,children:t(g?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>M(!I),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":!I,children:[I?s.jsx(R,{name:"checkbox-blank",className:"size-4"}):s.jsx(R,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(bt,{variant:"ghost",onClick:ie,disabled:g,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(bt,{variant:"destructive",onClick:ne,disabled:g,children:g?t("sessions.sidebar.sessionDialogs.actions.deleting"):o?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),xe=X?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):o?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[F?s.jsx(ei,{open:!!o,onClose:()=>{g||ie()},title:xe,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Ee}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[me&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:me}),ke]})}):s.jsx(ws,{open:!!o,onOpenChange:H=>{if(!H){if(g)return;ie()}},children:s.jsxs(Ss,{className:Ie(X?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(Ws,{children:[s.jsxs(Is,{className:Ie(X&&"flex items-center gap-2"),children:[X&&s.jsx(R,{name:"delete-bin",className:"h-5 w-5"}),xe]}),me&&s.jsx(Ts,{children:me})]}),s.jsx("div",{className:Ie(X&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:ke}),s.jsx(bn,{className:"mt-2 gap-2 pt-1 pb-1",children:Ee})]})}),s.jsx(wg,{open:e,onOpenChange:n})]})};function r4(t){const e=nt.c(64),{t:n}=Nt(),{value:r,onMoveSessionOnly:i,onMoveAllChanges:o,onCancel:l}=t,a=!!r;let u;e[0]!==l?(u=T=>{T||l()},e[0]=l,e[1]=u):u=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.session.moveToWorktree.confirm.title"),e[2]=n,e[3]=d):d=e[3];let h;e[4]!==d?(h=s.jsx(Is,{children:d}),e[4]=d,e[5]=h):h=e[5];const f=r?.dirtyFileCount??0;let p;e[6]!==n||e[7]!==f?(p=n("sessions.sidebar.session.moveToWorktree.confirm.changedFiles",{count:f}),e[6]=n,e[7]=f,e[8]=p):p=e[8];let g;e[9]!==n?(g=n("sessions.sidebar.session.moveToWorktree.confirm.ownership"),e[9]=n,e[10]=g):g=e[10];let w;e[11]!==p||e[12]!==g?(w=s.jsxs(Ts,{children:[p," ",g]}),e[11]=p,e[12]=g,e[13]=w):w=e[13];let v;e[14]!==h||e[15]!==w?(v=s.jsxs(Ws,{children:[h,w]}),e[14]=h,e[15]=w,e[16]=v):v=e[16];let x;e[17]!==n?(x=n("sessions.sidebar.session.moveToWorktree.confirm.sessionOnlyHelp"),e[17]=n,e[18]=x):x=e[18];let m;e[19]!==x?(m=s.jsx("p",{children:x}),e[19]=x,e[20]=m):m=e[20];let b;e[21]!==n?(b=n("sessions.sidebar.session.moveToWorktree.confirm.allChangesHelp"),e[21]=n,e[22]=b):b=e[22];let y;e[23]!==b?(y=s.jsx("p",{children:b}),e[23]=b,e[24]=y):y=e[24];let S;e[25]!==n||e[26]!==r?(S=r&&r.stagedFileCount>0?s.jsx("p",{"data-session-worktree-move-staged-warning":"true",children:n("sessions.sidebar.session.moveToWorktree.confirm.stagedWarning")}):null,e[25]=n,e[26]=r,e[27]=S):S=e[27];let N;e[28]!==n?(N=n("sessions.sidebar.session.moveToWorktree.confirm.baseWarning"),e[28]=n,e[29]=N):N=e[29];let C;e[30]!==N?(C=s.jsx("p",{children:N}),e[30]=N,e[31]=C):C=e[31];let j;e[32]!==m||e[33]!==y||e[34]!==S||e[35]!==C?(j=s.jsxs("div",{className:"space-y-2 typography-ui-label text-muted-foreground",children:[m,y,S,C]}),e[32]=m,e[33]=y,e[34]=S,e[35]=C,e[36]=j):j=e[36];let A;e[37]!==n?(A=n("sessions.sidebar.session.moveToWorktree.confirm.cancel"),e[37]=n,e[38]=A):A=e[38];let D;e[39]!==l||e[40]!==A?(D=s.jsx(bt,{type:"button",variant:"neutral","data-session-worktree-move-action":"cancel",onClick:l,children:A}),e[39]=l,e[40]=A,e[41]=D):D=e[41];let I;e[42]!==n?(I=n("sessions.sidebar.session.moveToWorktree.confirm.allChanges"),e[42]=n,e[43]=I):I=e[43];let M;e[44]!==o||e[45]!==I?(M=s.jsx(bt,{type:"button",variant:"outline","data-session-worktree-move-action":"all-changes",onClick:o,children:I}),e[44]=o,e[45]=I,e[46]=M):M=e[46];let $;e[47]!==n?($=n("sessions.sidebar.session.moveToWorktree.confirm.sessionOnly"),e[47]=n,e[48]=$):$=e[48];let E;e[49]!==i||e[50]!==$?(E=s.jsx(bt,{type:"button",autoFocus:!0,"data-session-worktree-move-action":"session-only",onClick:i,children:$}),e[49]=i,e[50]=$,e[51]=E):E=e[51];let K;e[52]!==D||e[53]!==M||e[54]!==E?(K=s.jsxs(bn,{className:"gap-2 sm:justify-end",children:[D,M,E]}),e[52]=D,e[53]=M,e[54]=E,e[55]=K):K=e[55];let B;e[56]!==j||e[57]!==K||e[58]!==v?(B=s.jsxs(Ss,{id:"session-worktree-move-confirm-dialog",showCloseButton:!1,className:"max-w-md gap-5",children:[v,j,K]}),e[56]=j,e[57]=K,e[58]=v,e[59]=B):B=e[59];let O;return e[60]!==a||e[61]!==u||e[62]!==B?(O=s.jsx(ws,{open:a,onOpenChange:u,children:B}),e[60]=a,e[61]=u,e[62]=B,e[63]=O):O=e[63],O}function Cm(t){if(!t||!t.trim())return{valid:!1,error:"required"};try{return ju.CronExpressionParser.parse(t),{valid:!0}}catch(e){return{valid:!1,error:e instanceof Error?e.message:"Invalid cron expression"}}}function o4(t,e,n=4){try{const r=e?{tz:e,currentDate:new Date}:{currentDate:new Date},i=ju.CronExpressionParser.parse(t,r),o=[];for(let l=0;l<n;l+=1){const a=i.next();a&&o.push(a.toDate())}return o}catch{return[]}}const i4=[{expression:"*/5 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.every5min"},{expression:"0 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.everyHour"},{expression:"0 9 * * 1",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.monday9am"},{expression:"0 9,17 * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.9am5pm"},{expression:"0 0 1 * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.firstOfMonth"}],a4={"Europe/Kiev":"Europe/Kyiv","Asia/Calcutta":"Asia/Kolkata","Asia/Saigon":"Asia/Ho_Chi_Minh","Asia/Rangoon":"Asia/Yangon","Asia/Katmandu":"Asia/Kathmandu","America/Godthab":"America/Nuuk","Atlantic/Faeroe":"Atlantic/Faroe","Pacific/Enderbury":"Pacific/Kanton"},qn=t=>a4[t]??t,Nm=[0,1,2,3,4,5,6],Lc="flex h-6 w-6 cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0",pa=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?[...new Set(Intl.supportedValuesOf("timeZone").map(qn))]:["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],$c=()=>{const t=new Date,e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},Po=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),i=Number(e[3]),o=new Date(n,r-1,i);return Number.isNaN(o.getTime())||o.getFullYear()!==n||o.getMonth()!==r-1||o.getDate()!==i?null:o},Wc=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},l4=(t,e,n)=>{const r=Po(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},zc=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),c4=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),l=(new Date(n,r,1).getDay()-e+7)%7,a=new Date(n,r+1,0).getDate(),u=new Date(n,r,0).getDate(),d=[];for(let h=0;h<42;h+=1){const f=h-l+1;if(f<=0){const p=u+f;d.push({date:new Date(n,r-1,p),inCurrentMonth:!1});continue}if(f>a){d.push({date:new Date(n,r+1,f-a),inCurrentMonth:!1});continue}d.push({date:new Date(n,r,f),inCurrentMonth:!0})}return d},d4=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],i=n>=12?"PM":"AM",o=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(o).padStart(2,"0"),minute:r,meridiem:i}},Vn=(t,e,n)=>{const r=Number(t),i=Number(e),o=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,l=Number.isFinite(i)?Math.min(59,Math.max(0,i)):0;let a=o%12;return n==="PM"&&(a+=12),`${String(a).padStart(2,"0")}:${String(l).padStart(2,"0")}`},jr=(t,e)=>{const{max:n,min:r=0,loop:i=!1}=e;let o=Number.parseInt(t,10);return Number.isFinite(o)?(i?(o>n&&(o=r),o<r&&(o=n)):(o>n&&(o=n),o<r&&(o=r)),String(o).padStart(2,"0")):"00"},Vc=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:jr(t,{min:1,max:12}),go=t=>/^[0-5][0-9]$/.test(t)?t:jr(t,{max:59}),u4=(t,e)=>jr(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),Uc=(t,e)=>jr(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),m4=t=>{try{const e=Intl.Locale;if(typeof e!="function")return 1;const r=new e(t).weekInfo?.firstDay;return typeof r!="number"?1:r%7}catch{return 1}},f4=t=>{try{const e=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions();return typeof e.hour12=="boolean"?!e.hour12:e.hourCycle==="h23"||e.hourCycle==="h24"}catch{return!0}},h4=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Nm.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},p4=(t,e)=>[...t.slice(e),...t.slice(0,e)],Ms=t=>{const e=nt.c(6),{htmlFor:n,required:r,children:i}=t;let o;e[0]!==r?(o=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=o):o=e[1];let l;return e[2]!==i||e[3]!==n||e[4]!==o?(l=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,o]})}),e[2]=i,e[3]=n,e[4]=o,e[5]=l):l=e[5],l},Kc=t=>{const e=nt.c(84),{value:n,onChange:r,use24Hour:i,hourAriaLabel:o,minuteAriaLabel:l,periodAriaLabel:a,amLabel:u,pmLabel:d}=t;let h;e[0]!==n?(h=d4(n),e[0]=n,e[1]=h):h=e[1];const f=h,p=xt.useRef(null),g=xt.useRef(null),[w,v]=xt.useState(null),[x,m]=xt.useState(null),b=xt.useRef(null),y=xt.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=H=>{b.current=H,v(H)},e[2]=S):S=e[2];const N=S;let C;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=H=>{y.current=H,m(H)},e[3]=C):C=e[3];const j=C,A=v4,D=j4,I=k4;let M;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==i?(M=H=>{const Ce=H.replace(/\D/g,"").slice(0,2);N(Ce),Ce.length===2&&(r(i?I(A(Ce),f.minute):Vn(Vc(Ce),f.minute,f.meridiem)),N(null),g.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=i,e[8]=M):M=e[8];const $=M;let E;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==i?(E=()=>{const H=b.current;if(H!==null&&(N(null),H.length!==0)){if(i){r(I(A(H.padStart(2,"0")),f.minute));return}r(Vn(Vc(H.padStart(2,"0")),f.minute,f.meridiem))}},e[9]=r,e[10]=f.meridiem,e[11]=f.minute,e[12]=i,e[13]=E):E=e[13];const K=E;let B;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==i?(B=H=>{const Ce=H.replace(/\D/g,"").slice(0,2);j(Ce),Ce.length===2&&(r(i?I(f.hour24,go(Ce)):Vn(f.hour12,go(Ce),f.meridiem)),j(null))},e[14]=r,e[15]=f.hour12,e[16]=f.hour24,e[17]=f.meridiem,e[18]=i,e[19]=B):B=e[19];const O=B;let T;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==i?(T=()=>{const H=y.current;H!==null&&(j(null),H.length!==0&&r(i?I(f.hour24,go(H.padStart(2,"0"))):Vn(f.hour12,go(H.padStart(2,"0")),f.meridiem)))},e[20]=r,e[21]=f.hour12,e[22]=f.hour24,e[23]=f.meridiem,e[24]=i,e[25]=T):T=e[25];const k=T;let P;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==i?(P=H=>r(i?I(D(f.hour24,H),f.minute):Vn(u4(f.hour12,H),f.minute,f.meridiem)),e[26]=r,e[27]=f.hour12,e[28]=f.hour24,e[29]=f.meridiem,e[30]=f.minute,e[31]=i,e[32]=P):P=e[32];const F=P;let q;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==i?(q=H=>r(i?I(f.hour24,Uc(f.minute,H)):Vn(f.hour12,Uc(f.minute,H),f.meridiem)),e[33]=r,e[34]=f.hour12,e[35]=f.hour24,e[36]=f.meridiem,e[37]=f.minute,e[38]=i,e[39]=q):q=e[39];const Q=q;let Y;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(Y=H=>{H!==f.meridiem&&r(Vn(f.hour12,f.minute,H))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=Y):Y=e[44];const ce=Y;let X;e[45]!==K||e[46]!==F?(X=H=>{if(H.key==="ArrowRight"){H.preventDefault(),K(),g.current?.focus();return}(H.key==="ArrowUp"||H.key==="ArrowDown")&&(H.preventDefault(),N(null),F(H.key==="ArrowUp"?1:-1))},e[45]=K,e[46]=F,e[47]=X):X=e[47];const oe=X;let te;e[48]!==k||e[49]!==Q?(te=H=>{if(H.key==="ArrowLeft"&&(H.currentTarget.selectionStart??0)===0){H.preventDefault(),k(),p.current?.focus();return}(H.key==="ArrowUp"||H.key==="ArrowDown")&&(H.preventDefault(),j(null),Q(H.key==="ArrowUp"?1:-1))},e[48]=k,e[49]=Q,e[50]=te):te=e[50];const he=te,_=i?"px-2":"pl-2 pr-1";let ie;e[51]!==_?(ie=Ie("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",_),e[51]=_,e[52]=ie):ie=e[52];const ge=w??(i?f.hour24:f.hour12);let ae;e[53]!==$?(ae=H=>$(H.target.value),e[53]=$,e[54]=ae):ae=e[54];let z;e[55]===Symbol.for("react.memo_cache_sentinel")?(z=()=>N(""),e[55]=z):z=e[55];let ne;e[56]!==K||e[57]!==o||e[58]!==oe||e[59]!==ge||e[60]!==ae?(ne=s.jsx("input",{ref:p,inputMode:"numeric",value:ge,onChange:ae,onKeyDown:oe,onFocus:z,onBlur:K,maxLength:2,"aria-label":o,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=K,e[57]=o,e[58]=oe,e[59]=ge,e[60]=ae,e[61]=ne):ne=e[61];let ue;e[62]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=ue):ue=e[62];const me=x??f.minute;let ke;e[63]!==O?(ke=H=>O(H.target.value),e[63]=O,e[64]=ke):ke=e[64];let Te;e[65]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>j(""),e[65]=Te):Te=e[65];let je;e[66]!==k||e[67]!==l||e[68]!==he||e[69]!==me||e[70]!==ke?(je=s.jsx("input",{ref:g,inputMode:"numeric",value:me,onChange:ke,onKeyDown:he,onFocus:Te,onBlur:k,maxLength:2,"aria-label":l,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=k,e[67]=l,e[68]=he,e[69]=me,e[70]=ke,e[71]=je):je=e[71];let Ee;e[72]!==u||e[73]!==f.meridiem||e[74]!==a||e[75]!==d||e[76]!==ce||e[77]!==i?(Ee=i?null:s.jsxs(Bs,{value:f.meridiem,onValueChange:H=>ce(H),children:[s.jsx(Fs,{"aria-label":a,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(Cs,{})}),s.jsxs(_s,{children:[s.jsx(ts,{value:"AM",children:u}),s.jsx(ts,{value:"PM",children:d})]})]}),e[72]=u,e[73]=f.meridiem,e[74]=a,e[75]=d,e[76]=ce,e[77]=i,e[78]=Ee):Ee=e[78];let xe;return e[79]!==ie||e[80]!==ne||e[81]!==je||e[82]!==Ee?(xe=s.jsxs("div",{className:ie,children:[ne,ue,je,Ee]}),e[79]=ie,e[80]=ne,e[81]=je,e[82]=Ee,e[83]=xe):xe=e[83],xe},Hc=t=>new Date(t.getFullYear(),t.getMonth(),1),g4=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Gc=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),x4=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(i=>typeof i=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(i)).map(i=>i.trim()),r=Array.from(new Set(n)).sort((i,o)=>i.localeCompare(o));return r.length>0?r:["09:00"]},qc=(t,e)=>{const n=qn(Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC");return t?{id:t.id,name:t.name,enabled:t.enabled,schedule:{kind:t.schedule.kind==="cron"?"cron":t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:x4(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:$c(),onceTime:typeof t.schedule.time=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.time)?t.schedule.time:"09:00",weekdays:Array.isArray(t.schedule.weekdays)?t.schedule.weekdays:[1],timezone:qn(t.schedule.timezone||n),cronExpression:t.schedule.kind==="cron"&&typeof t.schedule.cron=="string"?t.schedule.cron:""},execution:{prompt:t.execution.prompt,providerID:t.execution.providerID,modelID:t.execution.modelID,variant:t.execution.variant||"",agent:t.execution.agent||"",goalEnabled:t.execution.goalEnabled===!0,goalTokenBudget:typeof t.execution.goalTokenBudget=="number"&&t.execution.goalTokenBudget>0?t.execution.goalTokenBudget:null,permissionAutoAccept:t.execution.permissionAutoAccept===!0},state:t.state}:{name:"",enabled:!0,schedule:{kind:"daily",times:["09:00"],onceDate:$c(),onceTime:"09:00",weekdays:[1],timezone:n,cronExpression:""},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent,goalEnabled:!1,goalTokenBudget:null,permissionAutoAccept:!1}}},b4=(t,e)=>{if(!t.name.trim())return e("sessions.scheduledTasks.editor.validation.taskNameRequired");if(!t.execution.prompt.trim())return e("sessions.scheduledTasks.editor.validation.promptRequired");if(!t.execution.providerID.trim()||!t.execution.modelID.trim())return e("sessions.scheduledTasks.editor.validation.modelRequired");if(t.schedule.kind==="once"){if(!/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.onceDate))return e("sessions.scheduledTasks.editor.validation.dateFormat");if(!/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.onceTime))return e("sessions.scheduledTasks.editor.validation.timeFormat")}else if(t.schedule.kind==="cron"){if(!t.schedule.cronExpression.trim())return e("sessions.scheduledTasks.editor.validation.cronRequired");if(!Cm(t.schedule.cronExpression).valid)return e("sessions.scheduledTasks.editor.validation.cronInvalid")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},y4=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))},w4=t=>{const e=nt.c(64),{draft:n,setDraft:r,locale:i,t:o}=t,l=n.schedule.cronExpression;let a;e[0]!==l?(a=l.trim()?Cm(l):null,e[0]=l,e[1]=a):a=e[1];const u=a;let d;e:{if(!u?.valid||!l.trim()){let P;e[2]===Symbol.for("react.memo_cache_sentinel")?(P=[],e[2]=P):P=e[2],d=P;break e}let k;e[3]!==l||e[4]!==n.schedule.timezone?(k=o4(l,n.schedule.timezone),e[3]=l,e[4]=n.schedule.timezone,e[5]=k):k=e[5],d=k}const h=d;let f;e[6]!==n.schedule.timezone||e[7]!==i?(f=k=>new Intl.DateTimeFormat(i,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(k),e[6]=n.schedule.timezone,e[7]=i,e[8]=f):f=e[8];const p=f;let g;e[9]!==o?(g=o("sessions.scheduledTasks.editor.cronExpression.label"),e[9]=o,e[10]=g):g=e[10];let w;e[11]!==g?(w=s.jsx(Ms,{htmlFor:"sched-cron",required:!0,children:g}),e[11]=g,e[12]=w):w=e[12];let v;e[13]!==r?(v=k=>r(P=>({...P,schedule:{...P.schedule,cronExpression:k.target.value}})),e[13]=r,e[14]=v):v=e[14];let x;e[15]!==o?(x=o("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=o,e[16]=x):x=e[16];let m;e[17]!==l||e[18]!==v||e[19]!==x?(m=s.jsx(Cn,{id:"sched-cron",value:l,onChange:v,placeholder:x,className:"w-full max-w-xs font-mono"}),e[17]=l,e[18]=v,e[19]=x,e[20]=m):m=e[20];let b;e[21]!==l||e[22]!==u||e[23]!==o?(b=u&&!u.valid&&l.trim()?s.jsx("span",{className:"typography-micro text-destructive",children:o("sessions.scheduledTasks.editor.validation.cronInvalid")}):null,e[21]=l,e[22]=u,e[23]=o,e[24]=b):b=e[24];let y;e[25]!==w||e[26]!==m||e[27]!==b?(y=s.jsxs("div",{className:"flex flex-col gap-1",children:[w,m,b]}),e[25]=w,e[26]=m,e[27]=b,e[28]=y):y=e[28];let S;e[29]!==p||e[30]!==h||e[31]!==o?(S=h.length>0?s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:o("sessions.scheduledTasks.editor.cronExpression.nextRuns")}),s.jsx("span",{className:"typography-micro text-foreground",children:h.map(p).join(", ")})]}):null,e[29]=p,e[30]=h,e[31]=o,e[32]=S):S=e[32];let N;e[33]!==o?(N=o("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=o,e[34]=N):N=e[34];let C;e[35]!==N?(C=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[35]=N,e[36]=C):C=e[36];let j;e[37]!==r||e[38]!==o?(j=i4.map(k=>s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 typography-micro text-foreground hover:bg-interactive-hover",onClick:()=>r(P=>({...P,schedule:{...P.schedule,cronExpression:k.expression}})),children:[s.jsx("span",{className:"font-mono",children:k.expression}),s.jsx("span",{className:"text-muted-foreground",children:o(k.labelKey)})]},k.expression)),e[37]=r,e[38]=o,e[39]=j):j=e[39];let A;e[40]!==j?(A=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:j}),e[40]=j,e[41]=A):A=e[41];let D;e[42]!==C||e[43]!==A?(D=s.jsxs("div",{className:"flex flex-col gap-1",children:[C,A]}),e[42]=C,e[43]=A,e[44]=D):D=e[44];let I;e[45]!==o?(I=o("sessions.scheduledTasks.editor.timezone.label"),e[45]=o,e[46]=I):I=e[46];let M;e[47]!==I?(M=s.jsx(Ms,{children:I}),e[47]=I,e[48]=M):M=e[48];let $;e[49]!==r?($=k=>{r(P=>({...P,schedule:{...P.schedule,timezone:k}}))},e[49]=r,e[50]=$):$=e[50];let E;e[51]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Fs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Cs,{})}),e[51]=E):E=e[51];let K;e[52]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(_s,{children:pa.map(C4)}),e[52]=K):K=e[52];let B;e[53]!==n.schedule.timezone||e[54]!==$?(B=s.jsxs(Bs,{value:n.schedule.timezone,onValueChange:$,children:[E,K]}),e[53]=n.schedule.timezone,e[54]=$,e[55]=B):B=e[55];let O;e[56]!==M||e[57]!==B?(O=s.jsxs("div",{className:"flex flex-col gap-1",children:[M,B]}),e[56]=M,e[57]=B,e[58]=O):O=e[58];let T;return e[59]!==y||e[60]!==S||e[61]!==D||e[62]!==O?(T=s.jsxs("div",{className:"flex flex-col gap-3",children:[y,S,D,O]}),e[59]=y,e[60]=S,e[61]=D,e[62]=O,e[63]=T):T=e[63],T};function S4(t){const{open:e,task:n,onOpenChange:r,onSave:i}=t,{t:o,locale:l}=Nt(),a=Ht(V=>V.loadProviders),u=Ht(V=>V.loadAgents),d=Ht(V=>V.providers),h=Ht(V=>V.currentProviderId),f=Ht(V=>V.currentModelId),p=Ht(V=>V.currentVariant||""),g=Ht(V=>V.currentAgentName||""),w=Pe(V=>V.timeFormatPreference),v=Pe(V=>V.weekStartPreference),x=Pe(V=>V.isMobile),[m,b]=xt.useState(()=>qc(n,{providerID:h,modelID:f,variant:p,agent:g})),[y,S]=xt.useState(!1),[N,C]=xt.useState(!1),[j,A]=xt.useState(!1),[D,I]=xt.useState(""),[M,$]=xt.useState(!1),[E,K]=xt.useState(""),[B,O]=xt.useState(!1),[T,k]=xt.useState(""),[P,F]=xt.useState(()=>{const V=Po(n?.schedule?.date||"")||new Date;return new Date(V.getFullYear(),V.getMonth(),1)}),q=xt.useRef(null),Q=xt.useRef(null),Y=xt.useRef(null),ce=xt.useRef(null),X=xt.useRef(null),oe=xt.useMemo(()=>f4(l),[l]),te=xt.useMemo(()=>m4(l),[l]),he=xt.useMemo(()=>w==="24h"?!0:w==="12h"?!1:oe,[w,oe]),_=xt.useMemo(()=>v==="sunday"?0:v==="monday"?1:te,[v,te]),ie=xt.useMemo(()=>{const V=h4(l);return p4(Nm.map(fe=>({value:fe,label:V[fe]||""})),_)},[l,_]);xt.useEffect(()=>{e&&(a({source:"scheduledTaskEditor"}),u({source:"scheduledTaskEditor"}))},[e,a,u]),xt.useEffect(()=>{if(!e)return;b(qc(n,{providerID:h,modelID:f,variant:p,agent:g}));const V=Po(n?.schedule?.date||"")||new Date;F(new Date(V.getFullYear(),V.getMonth(),1)),C(!1),$(!1),A(!1),K(""),I("")},[e,n,h,f,p,g]),xt.useEffect(()=>{if(!N)return;const V=fe=>{q.current&&!q.current.contains(fe.target)&&C(!1)};return document.addEventListener("mousedown",V),()=>{document.removeEventListener("mousedown",V)}},[N]);const ge=xt.useMemo(()=>{const fe=d.find(Me=>Me.id===m.execution.providerID)?.models?.find(Me=>Me.id===m.execution.modelID);return fe?.variants?Object.keys(fe.variants):[]},[d,m.execution.providerID,m.execution.modelID]),ae=ge.length>0,z=xt.useMemo(()=>!ae||!m.execution.variant?"__default":ge.includes(m.execution.variant)?m.execution.variant:"__default",[m.execution.variant,ae,ge]);xt.useEffect(()=>{ae||!m.execution.variant||b(V=>({...V,execution:{...V.execution,variant:""}}))},[ae,m.execution.variant]);const ne=xt.useCallback((V,fe)=>{b(Me=>{const De=new Set(Me.schedule.weekdays);return fe?De.add(V):De.delete(V),{...Me,schedule:{...Me.schedule,weekdays:Array.from(De).sort((at,Qe)=>at-Qe)}}})},[]),ue=xt.useCallback((V,fe)=>{b(Me=>{const De=Me.schedule.times.slice();return De[V]=fe,{...Me,schedule:{...Me.schedule,times:De}}})},[]),me=xt.useCallback(V=>{b(fe=>{const Me=fe.schedule.times.filter((De,at)=>at!==V);return{...fe,schedule:{...fe.schedule,times:Me.length>0?Me:["09:00"]}}})},[]),ke=xt.useCallback(()=>{b(V=>({...V,schedule:{...V.schedule,times:[...V.schedule.times,"12:00"]}}))},[]),Te=xt.useMemo(()=>g4(),[]),je=xt.useMemo(()=>Hc(Te),[Te]),Ee=xt.useMemo(()=>{const V=Po(m.schedule.onceDate);return V?Gc(V,Te)?o("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(l,{weekday:"short"}).format(V):null},[m.schedule.onceDate,l,o,Te]),xe=xt.useMemo(()=>Hc(P).getTime()<=je.getTime(),[P,je]),H=xt.useMemo(()=>ie.map(V=>V.label),[ie]),Ce=xt.useCallback(V=>{b(fe=>({...fe,schedule:{...fe.schedule,onceDate:V}}))},[]),ve=xt.useCallback((V,fe)=>{if(V.startsWith("/")){const Qe=V.indexOf(" "),lt=V.indexOf(`
|
|
924
|
+
`),de=Math.min(Qe===-1?V.length:Qe,lt===-1?V.length:lt);if(fe<=de&&Qe===-1){K(V.substring(1,de)),$(!0),A(!1),O(!1);return}}$(!1);const Me=V.substring(0,fe),De=Me.lastIndexOf("#");if(De!==-1){const Qe=De>0?Me[De-1]:null,lt=Me.substring(De+1);if((!Qe||/\s/.test(Qe))&&!lt.includes(" ")&&!lt.includes(`
|
|
925
|
+
`)){k(lt),O(!0),A(!1);return}}O(!1);const at=Me.lastIndexOf("@");if(at!==-1){const Qe=at>0?Me[at-1]:null,lt=Me.substring(at+1);(!Qe||/\s/.test(Qe))&&!lt.includes(" ")&&!lt.includes(`
|
|
926
|
+
`)?(I(lt),A(!0)):A(!1);return}A(!1)},[]),re=xt.useCallback(V=>{b(fe=>({...fe,execution:{...fe.execution,prompt:V}}))},[]),le=xt.useCallback(V=>{const fe=m.execution.prompt,De=Q.current?.selectionStart??fe.length,Qe=fe.substring(0,De).lastIndexOf("@"),lt=V.relativePath&&V.relativePath.trim().length>0?V.relativePath.trim():V.path||V.name,de=Qe!==-1?Qe:De,J=`${fe.substring(0,de)}@${lt} ${fe.substring(De)}`,Se=de+lt.length+2;re(J),A(!1),I(""),requestAnimationFrame(()=>{const Ve=Q.current;Ve&&(Ve.selectionStart=Se,Ve.selectionEnd=Se,Ve.focus()),ve(J,Se)})},[m.execution.prompt,re,ve]),se=xt.useCallback(V=>{const fe=m.execution.prompt,De=Q.current?.selectionStart??fe.length,Qe=fe.substring(0,De).lastIndexOf("@"),lt=Qe!==-1?Qe:De,de=`${fe.substring(0,lt)}@${V} ${fe.substring(De)}`,J=lt+V.length+2;re(de),A(!1),I(""),requestAnimationFrame(()=>{const Se=Q.current;Se&&(Se.selectionStart=J,Se.selectionEnd=J,Se.focus()),ve(de,J)})},[m.execution.prompt,re,ve]),G=xt.useCallback(V=>{const fe=`/${V.name} `;re(fe),$(!1),K(""),O(!1),requestAnimationFrame(()=>{const Me=Q.current;Me&&(Me.focus(),Me.selectionStart=Me.value.length,Me.selectionEnd=Me.value.length),ve(fe,fe.length)})},[re,ve]),U=xt.useCallback((V,fe)=>{const Me=m.execution.prompt,at=Q.current?.selectionStart??Me.length,lt=Me.substring(0,at).lastIndexOf("#"),de=lt!==-1?lt:at,J=`${Me.substring(0,de)}#${fe} ${Me.substring(at)}`,Se=de+fe.length+2;re(J),O(!1),k(""),requestAnimationFrame(()=>{const Ve=Q.current;Ve&&(Ve.selectionStart=Se,Ve.selectionEnd=Se,Ve.focus()),ve(J,Se)})},[m.execution.prompt,re,ve]),be=xt.useCallback(V=>{if(M&&ce.current&&(V.key==="Enter"||V.key==="ArrowUp"||V.key==="ArrowDown"||V.key==="Escape"||V.key==="Tab")){V.preventDefault(),ce.current.handleKeyDown(V.key);return}j&&Y.current&&(V.key==="Enter"||V.key==="ArrowUp"||V.key==="ArrowDown"||V.key==="Escape"||V.key==="Tab")&&(V.preventDefault(),Y.current.handleKeyDown(V.key)),B&&X.current&&(V.key==="Enter"||V.key==="ArrowUp"||V.key==="ArrowDown"||V.key==="Escape"||V.key==="Tab")&&(V.preventDefault(),X.current.handleKeyDown(V.key))},[M,j,B]),W=xt.useCallback(async()=>{const V=b4(m,o);if(V){Re.error(V);return}const fe={...m.id?{id:m.id}:{},name:m.name.trim(),enabled:m.enabled,schedule:{kind:m.schedule.kind,timezone:m.schedule.timezone.trim(),...m.schedule.kind==="cron"?{cron:m.schedule.cronExpression.trim()}:m.schedule.kind==="once"?{date:m.schedule.onceDate,time:m.schedule.onceTime}:{times:y4(m.schedule.times),...m.schedule.kind==="weekly"?{weekdays:m.schedule.weekdays}:{}}},execution:{prompt:m.execution.prompt,providerID:m.execution.providerID,modelID:m.execution.modelID,...m.execution.variant.trim()?{variant:m.execution.variant.trim()}:{},...m.execution.agent.trim()?{agent:m.execution.agent.trim()}:{},...m.execution.permissionAutoAccept?{permissionAutoAccept:!0}:{},...m.execution.goalEnabled?{goalEnabled:!0}:{},...m.execution.goalEnabled&&m.execution.goalTokenBudget?{goalTokenBudget:m.execution.goalTokenBudget}:{}},...m.state?{state:m.state}:{}};S(!0);try{await i(fe),r(!1)}catch(Me){Re.error(Me instanceof Error?Me.message:o("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[m,r,i,o]),Ne=xt.useId(),Oe=xt.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]'),[]),ye=o(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),Fe=o("sessions.scheduledTasks.editor.description"),Ke=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ms,{htmlFor:"sched-name",required:!0,children:o("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Cn,{id:"sched-name",value:m.name,onChange:V=>b(fe=>({...fe,name:V.target.value})),placeholder:o("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ms,{children:o("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(Bs,{value:m.schedule.kind,onValueChange:V=>{b(fe=>({...fe,schedule:{...fe.schedule,kind:V,...V==="cron"&&!fe.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx(Fs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Cs,{children:V=>o(V==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":V==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":V==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(_s,{children:[s.jsx(ts,{value:"daily",children:o("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(ts,{value:"weekly",children:o("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(ts,{value:"once",children:o("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(ts,{value:"cron",children:o("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),m.schedule.kind==="cron"?s.jsx(w4,{draft:m,setDraft:b,locale:l,t:o}):m.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:q,children:[s.jsx(Ms,{children:o("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:Ie(Kd({size:"default"}),"w-fit max-w-full"),onClick:()=>C(V=>!V),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(R,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:l4(m.schedule.onceDate,o("sessions.scheduledTasks.editor.date.placeholder"),l)})]}),s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),N?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>F(V=>zc(V,-1)),"aria-label":o("sessions.scheduledTasks.editor.date.previousMonth"),disabled:xe,children:s.jsx(R,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(l,{month:"long",year:"numeric"}).format(P)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>F(V=>zc(V,1)),"aria-label":o("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:H.map((V,fe)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:V},`${V}-${fe}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:c4(P,_).map(({date:V,inCurrentMonth:fe})=>{const Me=Wc(V),De=Me===m.schedule.onceDate,at=Gc(V,Te),Qe=V.getTime()<Te.getTime(),lt=De?"bg-interactive-selection text-interactive-selection-foreground":Qe?"text-muted-foreground/40":fe?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{Qe||(Ce(Me),C(!1))},disabled:Qe,className:["h-8 rounded-md typography-ui-label",lt,at&&!De?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",Qe?"cursor-not-allowed opacity-45":""].join(" "),children:V.getDate()},Me)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ee||""}),s.jsx(bt,{type:"button",size:"xs",variant:"ghost",onClick:()=>{Ce(Wc(Te)),F(new Date(Te.getFullYear(),Te.getMonth(),1))},children:o("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ms,{children:o("sessions.scheduledTasks.editor.time.label")}),s.jsx(Kc,{value:m.schedule.onceTime,use24Hour:he,hourAriaLabel:o("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:o("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:o("sessions.scheduledTasks.editor.time.periodAria"),amLabel:o("sessions.scheduledTasks.editor.time.period.am"),pmLabel:o("sessions.scheduledTasks.editor.time.period.pm"),onChange:V=>b(fe=>({...fe,schedule:{...fe.schedule,onceTime:V}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Ms,{children:o("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Bs,{value:m.schedule.timezone,onValueChange:V=>{b(fe=>({...fe,schedule:{...fe.schedule,timezone:V}}))},children:[s.jsx(Fs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Cs,{})}),s.jsx(_s,{children:pa.map(V=>s.jsx(ts,{value:V,children:V},V))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[m.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(Ms,{children:o("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:ie.map(V=>{const fe=m.schedule.weekdays.includes(V.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",fe?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(ur,{checked:fe,onChange:Me=>ne(V.value,Me),ariaLabel:V.label}),s.jsx("button",{type:"button",onClick:()=>ne(V.value,!fe),className:"group-hover:text-foreground",children:V.label})]},V.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Ms,{children:o("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:m.schedule.times.map((V,fe)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Kc,{value:V,use24Hour:he,hourAriaLabel:o("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:o("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:o("sessions.scheduledTasks.editor.time.periodAria"),amLabel:o("sessions.scheduledTasks.editor.time.period.am"),pmLabel:o("sessions.scheduledTasks.editor.time.period.pm"),onChange:Me=>ue(fe,Me)}),m.schedule.times.length>1?s.jsx(bt,{type:"button",size:"icon",variant:"ghost",onClick:()=>me(fe),"aria-label":o("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(R,{name:"close",className:"h-4 w-4"})}):null]},fe))}),s.jsx("div",{children:s.jsxs(bt,{type:"button",size:"sm",variant:"outline",onClick:ke,children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"})," ",o("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ms,{children:o("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Bs,{value:m.schedule.timezone,onValueChange:V=>{b(fe=>({...fe,schedule:{...fe.schedule,timezone:V}}))},children:[s.jsx(Fs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Cs,{})}),s.jsx(_s,{children:pa.map(V=>s.jsx(ts,{value:V,children:V},V))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ms,{required:!0,children:o("sessions.scheduledTasks.editor.model.label")}),s.jsx(Zh,{providerId:m.execution.providerID,modelId:m.execution.modelID,onChange:(V,fe)=>{b(Me=>({...Me,execution:{...Me.execution,providerID:V,modelID:fe,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ms,{children:o("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(Bs,{value:z,disabled:!ae,onValueChange:V=>{b(fe=>({...fe,execution:{...fe.execution,variant:V==="__default"?"":V}}))},children:[s.jsx(Fs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Cs,{children:V=>V==="__default"?o("sessions.scheduledTasks.editor.thinkingLevel.default"):V})}),s.jsxs(_s,{children:[s.jsx(ts,{value:"__default",children:o("sessions.scheduledTasks.editor.thinkingLevel.default")}),ge.map(V=>s.jsx(ts,{value:V,children:V},V))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ms,{children:o("sessions.scheduledTasks.editor.agent.label")}),s.jsx(ep,{agentName:m.execution.agent,filter:V=>Ud(V.mode),onChange:V=>b(fe=>({...fe,execution:{...fe.execution,agent:V}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ms,{htmlFor:"sched-prompt",required:!0,children:o("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(lr,{id:"sched-prompt",ref:Q,value:m.execution.prompt,onChange:V=>{const fe=V.target.value;re(fe);const Me=V.target.selectionStart??fe.length;ve(fe,Me)},onKeyDown:be,rows:8,placeholder:o("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),M?s.jsx(Jd,{ref:ce,searchQuery:E,onCommandSelect:G,onClose:()=>$(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,j?s.jsx(Zd,{ref:Y,searchQuery:D,onFileSelect:le,onAgentSelect:se,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,B?s.jsx(eu,{ref:X,searchQuery:T,onSnippetSelect:U,onClose:()=>O(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]}),m.execution.goalEnabled?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-8 gap-y-2",children:[s.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2",children:[s.jsx(ur,{checked:m.execution.goalTokenBudget!==null,onChange:V=>b(fe=>({...fe,execution:{...fe.execution,goalTokenBudget:V?2e5:null}})),ariaLabel:o("sessions.scheduledTasks.editor.goal.budgetAria")}),s.jsx("span",{className:"typography-meta",children:o("sessions.scheduledTasks.editor.goal.budgetLabel")})]}),m.execution.goalTokenBudget!==null?s.jsx(tp,{value:m.execution.goalTokenBudget,onValueChange:V=>{typeof V=="number"&&Number.isFinite(V)&&V>0&&b(fe=>({...fe,execution:{...fe.execution,goalTokenBudget:Math.floor(V)}}))},min:1e3,max:1e8,step:5e4}):null]}):null]}),$e=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(ur,{checked:m.enabled,onChange:V=>b(fe=>({...fe,enabled:V})),ariaLabel:o("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:o("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie(Lc),onClick:()=>b(V=>({...V,execution:{...V.execution,permissionAutoAccept:!V.execution.permissionAutoAccept}})),"aria-pressed":m.execution.permissionAutoAccept,"aria-label":o("sessions.scheduledTasks.editor.permissionAutoAccept.aria"),children:m.execution.permissionAutoAccept?s.jsx(R,{name:"shield-check",className:"h-[18px] w-[18px]",style:{color:"var(--status-info)"},"aria-hidden":"true"}):s.jsx(R,{name:"shield-user",className:"h-[18px] w-[18px]","aria-hidden":"true"})})}),s.jsx(It,{side:"top",sideOffset:6,children:o("sessions.scheduledTasks.editor.permissionAutoAccept.label")})]}),s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie(Lc,m.execution.goalEnabled&&"text-[var(--status-info)]"),onClick:()=>b(V=>({...V,execution:{...V.execution,goalEnabled:!V.execution.goalEnabled}})),"aria-pressed":m.execution.goalEnabled,"aria-label":o("sessions.scheduledTasks.editor.goal.aria"),children:m.execution.goalEnabled?s.jsx(R,{name:"target-fill",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"}):s.jsx(R,{name:"target",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"})})}),s.jsx(It,{side:"top",sideOffset:6,children:o("sessions.scheduledTasks.editor.goal.label")})]}),s.jsx(bt,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:y,children:o("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(bt,{type:"button",size:"sm",onClick:W,disabled:y,children:o(y?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(ei,{open:e,title:ye,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:V=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:ye}),V]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:Fe})]}),footer:$e,children:Ke}):s.jsx(ws,{open:e,onOpenChange:V=>{!V&&Oe()||r(V)},children:s.jsxs(Ss,{"aria-describedby":Ne,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ts,{id:Ne,className:"sr-only",children:Fe}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(Is,{className:"typography-ui-label font-medium text-foreground",children:ye}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:Fe})]})}),s.jsx(Aa,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:Ke})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:$e})})]})})}function v4(t){return jr(t,{min:0,max:23})}function j4(t,e){return jr(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function k4(t,e){const n=Number(t),r=Number(e),i=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,o=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(i).padStart(2,"0")}:${String(o).padStart(2,"0")}`}function C4(t){return s.jsx(ts,{value:t,children:t},t)}const N4=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,i)=>r.localeCompare(i))},A4=(t,e)=>{const n=N4(t).join(", ")||"--:--",r=i=>e(i===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":i===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":i===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":i===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":i===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":i===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":i===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:qn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const i=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(o=>r(o)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:i,time:n,timezone:qn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:i,time:n})}if(t.schedule.kind==="once"){const i=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),o=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:i,time:o,timezone:qn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.once",{date:i,time:o})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:qn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},D4=(t,e)=>!t||!Number.isFinite(t)?"":sp(t,e),Qc=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),i=6e4,o=60*i,l=24*o,a=n>=0;if(r<i)return e(a?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<o){const f=Math.round(r/i);return a?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:f}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:f})}if(r<l){const f=Math.floor(r/o),p=Math.round(r%o/i),g=p>0?`${f}h ${p}m`:`${f}h`;return a?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:g}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:g})}const u=Math.floor(r/l),d=Math.round(r%l/o),h=d>0?`${u}d ${d}h`:`${u}d`;return a?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:h}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:h})},P4={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},I4=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function T4(){const{t}=Nt(),e=Pe(k=>k.isScheduledTasksDialogOpen),n=Pe(k=>k.setScheduledTasksDialogOpen),r=Pe(k=>k.isMobile),i=Pe(k=>k.timeFormatPreference),o=Vt(k=>k.projects),l=Vt(k=>k.getActiveProject()),a=es(k=>k.homeDirectory),{currentTheme:u}=er(),[d,h]=xt.useState(""),[f,p]=xt.useState([]),[g,w]=xt.useState(!0),[v,x]=xt.useState(!1),[m,b]=xt.useState(null),[y,S]=xt.useState(null),N=xt.useMemo(()=>o.find(k=>k.id===d)||null,[o,d]),C=xt.useCallback(k=>{const P=k.label?.trim()||Fn(k.path,a||void 0),F=k.icon?Ta[k.icon]:null,q=k.color?Ea[k.color]:void 0,Q=F?s.jsx(R,{name:F,className:"h-3.5 w-3.5 shrink-0",style:q?{color:q}:void 0}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:q?{color:q}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[k.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:k.iconBackground?{backgroundColor:k.iconBackground}:void 0,children:s.jsx(Ra,{project:{id:k.id,iconImage:k.iconImage??null},options:{themeVariant:u.metadata.variant,iconColor:u.colors.surface.foreground},className:"h-full w-full object-contain",fallback:Q})}):Q,s.jsx("span",{className:"truncate",children:P})]})},[a,u.metadata.variant,u.colors.surface.foreground]),j=xt.useCallback(async(k,P)=>{if(!k){p([]);return}P?.silent||w(!0);try{const F=await Rg(k);F.sort((q,Q)=>{if(q.enabled!==Q.enabled)return q.enabled?-1:1;const Y=q.name.localeCompare(Q.name);return Y!==0?Y:(q.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(Q.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),p(F)}catch(F){Re.error(F instanceof Error?F.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),P?.silent||p([])}finally{P?.silent||w(!1)}},[t]);xt.useEffect(()=>{if(!e)return;const k=l?.id||o[0]?.id||"";h(k),k?j(k):(p([]),w(!1))},[e,l,o,j]),xt.useEffect(()=>{if(!e)return;let k=null;const P=eo(F=>{F.type==="scheduled-task-ran"&&F.projectId===d&&(k&&clearTimeout(k),k=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{k&&clearTimeout(k),P()}},[e,d,j]);const A=xt.useCallback(async k=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Il(d,k),await j(d),Re.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),D=xt.useCallback(async(k,P)=>{if(d){S(k.id),p(F=>F.map(q=>q.id===k.id?{...q,enabled:P}:q));try{k.loopFile?await Mg(d,k.id,P):await Il(d,{...k,enabled:P}),await j(d,{silent:!0})}catch(F){Re.error(F instanceof Error?F.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{S(null)}}},[d,j,t]),I=xt.useCallback(async k=>{if(!(!d||!window.confirm(k.loopFile?t("sessions.scheduledTasks.dialog.confirm.deleteLoopFile",{taskName:k.name}):t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:k.name})))){S(k.id);try{k.loopFile?await Og(d,k.id):await Bg(d,k.id),await j(d,{silent:!0}),Re.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(F){Re.error(F instanceof Error?F.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{S(null)}}},[d,j,t]),M=xt.useCallback(k=>{if(!k.loopFile){b(k),x(!0);return}N?.path&&(n(!1),mn.getState().setSelectedPath(N.path,k.loopFile,{allowOutsideRoot:!0}),Pe.getState().openContextFile(N.path,k.loopFile))},[N?.path,n]),$=xt.useCallback(async k=>{if(d){S(k.id);try{const{sessionId:P,persistError:F}=await Fg(d,k.id);if(await Promise.all([j(d,{silent:!0}),_a()]),F?Re.warning(t("sessions.scheduledTasks.dialog.toast.startedPersistWarning")):Re.success(t("sessions.scheduledTasks.dialog.toast.started")),P){const q=o.find(Q=>Q.id===d);et.getState().setCurrentSession(P,q?.path??null)}}catch(P){Re.error(P instanceof Error?P.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{S(null)}}},[d,o,j,t]),E=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(Bs,{value:d||"__none",onValueChange:k=>{const P=k==="__none"?"":k;h(P),P?j(P):p([])},children:[s.jsx(Fs,{size:"lg",className:r?"w-full":void 0,children:N?s.jsx(Cs,{children:C(N)}):s.jsx(Cs,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(_s,{children:[o.length===0?s.jsx(ts,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,o.map(k=>s.jsx(ts,{value:k.id,children:C(k)},k.id))]})]})]}),K=()=>{b(null),x(!0)},B=k=>{h(k),k?j(k):p([])},O=s.jsx("div",{className:"min-h-[280px]",children:g?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(R,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):f.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:f.map(k=>{const P=y===k.id,F=k.state?.lastStatus||"idle",q=P4[F],Q=t(F==="success"?"sessions.scheduledTasks.dialog.status.success":F==="error"?"sessions.scheduledTasks.dialog.status.error":F==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),Y=k.state?.nextRunAt,ce=k.state?.lastRunAt;return s.jsxs("div",{className:Ie("rounded-lg border border-border p-4 transition-opacity",!k.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:k.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:A4(k,t)}),k.loopFile?s.jsx("div",{className:"typography-micro truncate text-muted-foreground/70",title:k.loopFile,children:t("sessions.scheduledTasks.dialog.loopFile.note",{file:k.loopFile})}):null]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(R,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),Y?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Qc(Y,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:D4(Y,i)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(R,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),F==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(R,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):ce?s.jsxs(s.Fragment,{children:[q.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${q.tone})`},children:[s.jsx(R,{name:q.Icon,className:"h-3.5 w-3.5"}),Q]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Qc(ce,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),k.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:I4("error"),children:[s.jsx(R,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:k.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:Ie("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",k.enabled?"text-foreground":"text-muted-foreground",P&&"cursor-not-allowed opacity-50"),children:[s.jsx(ur,{checked:k.enabled,onChange:X=>{D(k,X)},ariaLabel:k.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:k.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:k.name}),disabled:P}),k.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(bt,{variant:"outline",size:"sm",onClick:()=>{$(k)},disabled:P,children:[s.jsx(R,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(bt,{variant:"outline",size:"sm",onClick:()=>M(k),disabled:P,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:k.name}),children:[s.jsx(R,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(bt,{variant:"destructive",size:"sm",onClick:()=>{I(k)},disabled:P,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:k.name}),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},k.id)})})}),T=s.jsxs("div",{className:"space-y-4",children:[E,O]});return s.jsxs(s.Fragment,{children:[r?s.jsx(ei,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:k=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),k]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(bt,{className:"w-full",onClick:K,disabled:!d,children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:T}):e?s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsxs("div",{className:"flex min-h-0 flex-1",children:[s.jsx("div",{className:"flex w-60 flex-shrink-0 flex-col border-r border-border/50",children:s.jsx("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:o.length===0?s.jsx("div",{className:"px-2 py-2 typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.empty")}):o.map(k=>s.jsx("button",{type:"button",onClick:()=>B(k.id),className:Ie("flex w-full min-w-0 items-center rounded-md px-2 py-1.5 text-left typography-ui-label focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",d===k.id?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:C(k)},k.id))})}),s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("div",{className:"flex items-center px-6 pt-3",children:s.jsxs(bt,{size:"sm",onClick:K,disabled:!d,children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-4",children:s.jsx("div",{className:"mx-auto w-full max-w-3xl",children:O})})]})]})}):null,s.jsx(S4,{open:v,task:m,onOpenChange:x,onSave:A})]})}const Io=100;function E4(){const t=nt.c(101),{t:e}=Nt(),n=Pe(W4),r=Pe($4),i=et(L4),o=et(_4),l=es(F4);let a;t[0]!==n?(a=Y=>n?Y.archivedSessions:[],t[0]=n,t[1]=a):a=t[1];const u=Ps(Zn(a)),[d,h]=c.useState(""),[f,p]=c.useState(null),[g,w]=c.useState(Io);let v;t[2]!==d?(v=d.trim().toLowerCase(),t[2]=d,t[3]=v):v=t[3];const x=v;let m;e:{if(!n){let ce;t[4]===Symbol.for("react.memo_cache_sentinel")?(ce=[],t[4]=ce):ce=t[4],m=ce;break e}let Y;t[5]!==u?(Y=[...u].sort(B4),t[5]=u,t[6]=Y):Y=t[6],m=Y}const b=m;let y;if(t[7]!==l||t[8]!==b||t[9]!==e){const Y=new Map;for(const ce of b){const X=wt($s(ce))??"",oe=Y.get(X);if(oe){oe.sessions.push(ce);continue}Y.set(X,{directory:X,label:X?Fn(X,l)||X:e("sessions.archivePage.otherProjects"),sessions:[ce]})}y=[...Y.values()].sort(O4),t[7]=l,t[8]=b,t[9]=e,t[10]=y}else y=t[10];const S=y;let N;e:{if(x){let ce;t[11]!==x||t[12]!==b?(ce=np(b,x,M4),t[11]=x,t[12]=b,t[13]=ce):ce=t[13],N=ce;break e}if(f===null){N=b;break e}let Y;t[14]!==S||t[15]!==f?(Y=S.find(ce=>ce.directory===f)?.sessions??[],t[14]=S,t[15]=f,t[16]=Y):Y=t[16],N=Y}const C=N;let j,A,D,I,M,$,E,K,B,O;if(t[17]!==u.length||t[18]!==S||t[19]!==C||t[20]!==l||t[21]!==x||t[22]!==n||t[23]!==d||t[24]!==f||t[25]!==i||t[26]!==r||t[27]!==e||t[28]!==o||t[29]!==g){M=Symbol.for("react.early_return_sentinel");e:{const Y=C.slice(0,g);j=C.length-Y.length;const ce=u.length;let X;t[40]===Symbol.for("react.memo_cache_sentinel")?(X=xe=>{p(xe),w(Io)},t[40]=X):X=t[40];const oe=X;let te;t[41]!==i||t[42]!==r?(te=xe=>{const H=wt($s(xe));i(xe.id,H??void 0),r(!1)},t[41]=i,t[42]=r,t[43]=te):te=t[43];const he=te;let _;t[44]!==e||t[45]!==o?(_=xe=>{o(xe.id).then(H=>{H?Re.success(e("sessions.sidebar.session.restore.success")):Re.error(e("sessions.sidebar.session.restore.error"))})},t[44]=e,t[45]=o,t[46]=_):_=t[46];const ie=_;if(!n){M=null;break e}let ge;t[47]!==e?(ge=(xe,H,Ce,ve,re,le,se)=>s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:re,title:le,className:Ie("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",se?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",ve?"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:H}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:Ce})]}),se?s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>gn.requestDelete({sessions:se,mode:"session"}),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover/dir:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.deleteProjectAria",{label:H}),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:e("sessions.archivePage.deleteProject")})]}):null]},xe),t[47]=e,t[48]=ge):ge=t[48];const ae=ge;I="absolute inset-0 z-10 flex flex-col bg-background",A="flex min-h-0 flex-1";let z;if(t[49]!==ae||t[50]!==f||t[51]!==e||t[52]!==ce){let xe;t[54]===Symbol.for("react.memo_cache_sentinel")?(xe=()=>oe(null),t[54]=xe):xe=t[54],z=ae("__all__",e("sessions.archivePage.allDirectories"),ce,f===null,xe),t[49]=ae,t[50]=f,t[51]=e,t[52]=ce,t[53]=z}else z=t[53];let ne;if(t[55]!==S||t[56]!==ae||t[57]!==f){let xe;t[59]!==ae||t[60]!==f?(xe=H=>ae(H.directory||"__none__",H.label,H.sessions.length,f===H.directory,()=>oe(H.directory),H.directory||void 0,H.sessions),t[59]=ae,t[60]=f,t[61]=xe):xe=t[61],ne=S.map(xe),t[55]=S,t[56]=ae,t[57]=f,t[58]=ne}else ne=t[58];t[62]!==z||t[63]!==ne?(D=s.jsx("div",{className:"flex w-64 flex-shrink-0 flex-col border-r border-border/50",children:s.jsxs("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:[z,ne]})}),t[62]=z,t[63]=ne,t[64]=D):D=t[64],B="flex min-w-0 flex-1 flex-col";let ue;t[65]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx(R,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t[65]=ue):ue=t[65];let me;t[66]===Symbol.for("react.memo_cache_sentinel")?(me=xe=>{h(xe.target.value),w(Io)},t[66]=me):me=t[66];let ke;t[67]!==e?(ke=e("sessions.archivePage.searchPlaceholder"),t[67]=e,t[68]=ke):ke=t[68];let Te;t[69]!==d||t[70]!==ke?(Te=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[ue,s.jsx("input",{value:d,onChange:me,placeholder:ke,className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-3 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"})]}),t[69]=d,t[70]=ke,t[71]=Te):Te=t[71];let je;t[72]!==C.length||t[73]!==e?(je=C.length===1?e("sessions.archivePage.countSingle",{count:C.length}):e("sessions.archivePage.countPlural",{count:C.length}),t[72]=C.length,t[73]=e,t[74]=je):je=t[74];let Ee;t[75]!==je?(Ee=s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:je}),t[75]=je,t[76]=Ee):Ee=t[76],t[77]!==Te||t[78]!==Ee?(O=s.jsxs("div",{className:"flex items-center gap-3 px-6 pt-3",children:[Te,Ee]}),t[77]=Te,t[78]=Ee,t[79]=O):O=t[79],K="min-h-0 flex-1 overflow-y-auto px-6 py-3",$="mx-auto w-full max-w-3xl space-y-0.5",E=Y.length===0?s.jsx("div",{className:"py-10 text-center text-muted-foreground",children:s.jsx("p",{className:"typography-ui-label font-semibold",children:e(x?"sessions.archivePage.empty.noMatches":"sessions.archivePage.empty.noArchived")})}):Y.map(xe=>{const H=wt($s(xe))??"",Ce=H?Fn(H,l)||H: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:()=>he(xe),role:"button",tabIndex:0,onKeyDown:ve=>{(ve.key==="Enter"||ve.key===" ")&&(ve.preventDefault(),he(xe))},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:xe.title||e("sessions.sidebar.session.untitled")}),x&&Ce?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:H,children:Ce}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Qd(xe.time?.archived??xe.time?.updated??xe.time?.created??Date.now())}),s.jsx("button",{type:"button",onClick:ve=>{ve.stopPropagation(),ie(xe)},className:"absolute right-7 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-foreground group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.restoreSessionAria",{title:xe.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(R,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:ve=>{ve.stopPropagation(),gn.requestDelete({sessions:[xe],mode:"session"})},className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-destructive group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.deleteSessionAria",{title:xe.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},xe.id)})}t[17]=u.length,t[18]=S,t[19]=C,t[20]=l,t[21]=x,t[22]=n,t[23]=d,t[24]=f,t[25]=i,t[26]=r,t[27]=e,t[28]=o,t[29]=g,t[30]=j,t[31]=A,t[32]=D,t[33]=I,t[34]=M,t[35]=$,t[36]=E,t[37]=K,t[38]=B,t[39]=O}else j=t[30],A=t[31],D=t[32],I=t[33],M=t[34],$=t[35],E=t[36],K=t[37],B=t[38],O=t[39];if(M!==Symbol.for("react.early_return_sentinel"))return M;let T;t[80]!==j||t[81]!==e?(T=j>0?s.jsx("button",{type:"button",onClick:()=>w(R4),className:"mt-1 flex items-center justify-start rounded-md px-2 py-1 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,t[80]=j,t[81]=e,t[82]=T):T=t[82];let k;t[83]!==T||t[84]!==$||t[85]!==E?(k=s.jsxs("div",{className:$,children:[E,T]}),t[83]=T,t[84]=$,t[85]=E,t[86]=k):k=t[86];let P;t[87]!==k||t[88]!==K?(P=s.jsx("div",{className:K,children:k}),t[87]=k,t[88]=K,t[89]=P):P=t[89];let F;t[90]!==P||t[91]!==B||t[92]!==O?(F=s.jsxs("div",{className:B,children:[O,P]}),t[90]=P,t[91]=B,t[92]=O,t[93]=F):F=t[93];let q;t[94]!==A||t[95]!==D||t[96]!==F?(q=s.jsxs("div",{className:A,children:[D,F]}),t[94]=A,t[95]=D,t[96]=F,t[97]=q):q=t[97];let Q;return t[98]!==I||t[99]!==q?(Q=s.jsx("div",{className:I,children:q}),t[98]=I,t[99]=q,t[100]=Q):Q=t[100],Q}function R4(t){return t+Io}function M4(t){return[t.title]}function O4(t,e){return e.sessions.length-t.sessions.length}function B4(t,e){return(e.time?.archived??0)-(t.time?.archived??0)}function F4(t){return t.homeDirectory}function _4(t){return t.unarchiveSession}function L4(t){return t.setCurrentSession}function $4(t){return t.setArchivePageOpen}function W4(t){return t.isArchivePageOpen}function z4(){const t=nt.c(18),{t:e}=Nt(),n=Pe(K4),r=Pe(U4),i=Vt(V4);let o;t[0]!==n?(o=g=>g.projects.find(w=>w.id===n)??null,t[0]=n,t[1]=o):o=t[1];const l=Vt(o);if(!n||!l)return null;let a;t[2]!==l.id||t[3]!==i||t[4]!==r?(a=()=>{i(l.id),r(!0)},t[2]=l.id,t[3]=i,t[4]=r,t[5]=a):a=t[5];let u;t[6]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(R,{name:"node-tree",className:"mr-1 h-3.5 w-3.5"}),t[6]=u):u=t[6];let d;t[7]!==e?(d=e("sessions.sidebar.project.actions.newWorktree"),t[7]=e,t[8]=d):d=t[8];let h;t[9]!==a||t[10]!==d?(h=s.jsx("div",{className:"flex items-center",children:s.jsxs(bt,{size:"sm",onClick:a,children:[u,d]})}),t[9]=a,t[10]=d,t[11]=h):h=t[11];let f;t[12]!==l.id||t[13]!==l.path?(f=s.jsx(Sg,{projectRef:{id:l.id,path:l.path},sections:"list-only"}),t[12]=l.id,t[13]=l.path,t[14]=f):f=t[14];let p;return t[15]!==h||t[16]!==f?(p=s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl space-y-4",children:[h,f]})})}),t[15]=h,t[16]=f,t[17]=p):p=t[17],p}function V4(t){return t.setActiveProjectIdOnly}function U4(t){return t.setNewWorktreeDialogOpen}function K4(t){return t.worktreesPageProjectId}const ga=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),H4=(t,e)=>{const n=ga(t),r=ga(e);return`${n}-${r}`.substring(0,60)},Yc=(t,e)=>`${t}/${e}`,G4=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},Xc=(t,e)=>{const n=G4(e),r=t.directory,i=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};up(t.id,n),et.getState().markSessionAsOpenChamberCreated(t.id),Ps.getState().upsertSession(i);try{Mo().ensureChild(n,{bootstrap:!1}).setState(l=>{const a=l.session.findIndex(d=>d.id===t.id);if(a>=0&&l.session[a]===i)return l;const u=a>=0?l.session.map((d,h)=>h===a?i:d):[...l.session,i].sort((d,h)=>d.id.localeCompare(h.id));return{session:u,sessionTotal:Math.max(l.sessionTotal,u.length),limit:Math.max(l.limit,u.length)}})}catch{}return i},q4=()=>{const t=Vt.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(i=>i.id===e);if(n?.path)return{id:n.id,path:n.path};const r=es.getState().currentDirectory??null;if(r&&r.trim().length>0){const i=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${i}`,path:i}}return null},Ci=tr()(wu(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:i,files:o,setupCommands:l}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let a=0;a<r.length;a++){if(!r[a].prompt.trim())return t({error:`Group ${a+1}: prompt is required`}),null;if(r[a].models.length<1)return t({error:`Group ${a+1}: select at least 1 model`}),null}t({isLoading:!0,error:null});try{const a=q4();if(!a)return t({error:"Select a project",isLoading:!1}),null;const u=a.path,h=await Jo(u)&&e.isolateRuns!==!1,f=ga(n),p=h?await ti(u):void 0,g=h?await rp(u):null,w=[],v=l?.filter(S=>S.trim().length>0)??[];for(let S=0;S<r.length;S++){const N=r[S],C=N.prompt,j=new Map;for(const D of N.models){const I=`${D.providerID}:${D.modelID}`;j.set(I,(j.get(I)||0)+1)}const A=new Map;for(const D of N.models){const I=`${D.providerID}:${D.modelID}`,M=j.get(I)||1,$=(A.get(I)||0)+1;A.set(I,$);const E=H4(D.providerID,D.modelID),K=r.length>1?`g${S+1}`:void 0,B=M>1?Yc(f,`${E}/${$}`):Yc(f,E),O=K?`${K}/${B}`:B,T=Lj({groupSlug:f,runGroup:K,providerID:D.providerID,modelID:D.modelID,index:M>1?$:void 0});try{if(!h){const q=await qs.withDirectory(u,()=>qs.createSession({title:T}));Xc(q,u),w.push({sessionId:q.id,worktreePath:u,providerID:D.providerID,modelID:D.modelID,variant:D.variant,prompt:C});continue}const k=await op(a,{preferredName:O,mode:"new",branchName:O,worktreeName:O,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:v,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:g}),P={...k,createdFromBranch:p,kind:"standard"};await ip(a)&&await ap(k.path);const F=await qs.withDirectory(k.path,()=>qs.createSession({title:T}));Xc(F,k.path),et.getState().setWorktreeMetadata(F.id,P),w.push({sessionId:F.id,worktreePath:k.path,providerID:D.providerID,modelID:D.modelID,variant:D.variant,prompt:C})}catch(k){console.warn("[MultiRun] Failed to create session:",k)}}}const x=l?.filter(S=>S.trim().length>0)??[];x.length>0&&lp(a,x).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const m=w.map(S=>S.sessionId),b=w[0]?.sessionId??null;if(m.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const y=o?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{const S=cp.getState().expandText;await Promise.allSettled(w.map(async N=>{try{const C=await S(N.prompt).catch(()=>N.prompt);await dp({sessionId:N.sessionId,directory:N.worktreePath,content:C,providerID:N.providerID,modelID:N.modelID,variant:N.variant,agent:i,files:y})}catch(C){console.warn("[MultiRun] Failed to start run:",C)}}))}catch(S){console.warn("[MultiRun] Failed to start runs:",S)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:m,firstSessionId:b}}catch(a){return t({error:a instanceof Error?a.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"}));function Am(t){const e=nt.c(30),{git:n}=wn(),r=Ed(t),i=Rd(t),o=mp(t),l=fp(t),a=Bn(Z4),u=Bn(J4);let d,h;e[0]!==t||e[1]!==u||e[2]!==n||e[3]!==i||e[4]!==o?(d=()=>{!t||!n||i!==null||o||u(t,n,{silent:!0})},h=[t,n,u,i,o],e[0]=t,e[1]=u,e[2]=n,e[3]=i,e[4]=o,e[5]=d,e[6]=h):(d=e[5],h=e[6]),c.useEffect(d,h);let f;e[7]!==r?.all||e[8]!==t||e[9]!==a||e[10]!==n||e[11]!==i?(f=()=>{!t||!n||i===!0&&(r?.all||a(t,n))},e[7]=r?.all,e[8]=t,e[9]=a,e[10]=n,e[11]=i,e[12]=f):f=e[12];const p=r?.all;let g;e[13]!==t||e[14]!==a||e[15]!==n||e[16]!==i||e[17]!==p?(g=[t,n,i,p,a],e[13]=t,e[14]=a,e[15]=n,e[16]=i,e[17]=p,e[18]=g):g=e[18],c.useEffect(f,g);const w=o||i===!0&&l;let v;e:{if(!r?.all){let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=[],e[19]=j):j=e[19],v=j;break e}let C;e[20]!==r.all?(C=r.all.filter(X4).sort(),e[20]=r.all,e[21]=C):C=e[21],v=C}const x=v;let m;e:{if(!r?.all){let j;e[22]===Symbol.for("react.memo_cache_sentinel")?(j=[],e[22]=j):j=e[22],m=j;break e}let C;e[23]!==r.all?(C=r.all.filter(Y4).map(Q4).sort(),e[23]=r.all,e[24]=C):C=e[24],m=C}const b=m;let y;e:{if(!t){y=null;break e}if(i!==null){y=i;break e}if(w){y=null;break e}y=r?.all?!0:null}const S=y;let N;return e[25]!==S||e[26]!==w||e[27]!==x||e[28]!==b?(N={localBranches:x,remoteBranches:b,isLoading:w,isGitRepository:S},e[25]=S,e[26]=w,e[27]=x,e[28]=b,e[29]=N):N=e[29],N}function Q4(t){return t.replace(/^remotes\//,"")}function Y4(t){return t.startsWith("remotes/")}function X4(t){return!t.startsWith("remotes/")}function J4(t){return t.fetchStatus}function Z4(t){return t.fetchBranches}const e3=({directory:t,value:e,onChange:n,className:r,disabled:i,id:o})=>{const{t:l}=Nt(),{localBranches:a,remoteBranches:u,isLoading:d,isGitRepository:h}=Am(t),f=c.useMemo(()=>[...a,...u.map(g=>`remotes/${g}`)],[a,u]);c.useEffect(()=>{if(i||d||f.length===0||e&&f.includes(e))return;const g=e;let w=!1;return(async()=>{try{const x=t?await ti(t).catch(()=>null):null;if(w)return;const m=localStorage.getItem(Pl),{sourceBranch:b,shouldClearSavedSourceBranch:y}=vg({branches:f,savedSourceBranch:m,rootBranch:x});if(y&&localStorage.removeItem(Pl),w||g&&f.includes(g))return;b&&n(b)}catch{}})(),()=>{w=!0}},[f,t,i,d,n,e]);const p=i||!h||d;return s.jsxs("div",{children:[s.jsxs(Bs,{value:e,onValueChange:n,disabled:p,children:[s.jsx(Fs,{id:o,size:"lg",className:Ie("min-w-0 max-w-full *:data-[slot=select-value]:truncate",r??"w-fit"),children:s.jsx(Cs,{placeholder:l(d?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(_s,{className:"max-h-[280px] max-w-[320px]",children:d?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.loadingBranches")}):a.length===0&&u.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[a.length>0&&s.jsxs(Bi,{children:[s.jsx(yl,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.localBranches")}),a.map(g=>s.jsx(ts,{value:g,className:"whitespace-normal break-all",children:g},g))]}),a.length>0&&u.length>0&&s.jsx(hp,{}),u.length>0&&s.jsxs(Bi,{children:[s.jsx(yl,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.remoteBranches")}),u.map(g=>s.jsx(ts,{value:`remotes/${g}`,className:"whitespace-normal break-all",children:g},`remotes/${g}`))]})]})})]}),h===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:l("multiRun.branchSelector.status.notInGitRepository")})]})},t3=10*1024*1024,To=t=>{const e=nt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(R,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let i;return e[1]!==n?(i=s.jsxs(Dt,{children:[r,s.jsx(It,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=i):i=e[2],i},Hn=t=>{const e=nt.c(9),{htmlFor:n,required:r,children:i,info:o}=t;let l;e[0]!==r?(l=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=l):l=e[1];let a;e[2]!==i||e[3]!==n||e[4]!==l?(a=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,l]}),e[2]=i,e[3]=n,e[4]=l,e[5]=a):a=e[5];const u=o&&o;let d;return e[6]!==a||e[7]!==u?(d=s.jsxs("div",{className:"flex items-center gap-1.5",children:[a,u]}),e[6]=a,e[7]=u,e[8]=d):d=e[8],d},s3=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:i}=Nt(),[o,l]=c.useState(""),[a,u]=c.useState(()=>[{id:$r(),prompt:"",models:[]}]),[d,h]=c.useState(""),[f,p]=c.useState([]),[g,w]=c.useState(!1),[v,x]=c.useState([]),[m,b]=c.useState(!1),[y,S]=c.useState(!1),[N,C]=c.useState(!0),j=c.useRef(null),A=es(G=>G.currentDirectory??null),D=es(G=>G.homeDirectory??null),I=c.useMemo(()=>{if(typeof window>"u")return null;const G=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof G=="string"&&G.trim().length>0?G.trim():null},[]),M=Vt(G=>G.activeProjectId),$=Vt(G=>G.setActiveProjectIdOnly),E=Vt(G=>G.projects),[K,B]=c.useState(()=>M??null);c.useEffect(()=>{if(M){B(M);return}!K&&E.length>0&&B(E[0].id)},[M,E,K]);const O=c.useMemo(()=>K?E.find(G=>G.id===K)??null:null,[E,K]),T=O?.path??A,k=c.useCallback(G=>{B(G),G!==M&&$(G)},[M,$]),{currentTheme:P}=er(),F=c.useCallback(G=>{const U=G.label?.trim()||Fn(G.path,D),be=G.icon?Ta[G.icon]:null,W=G.color?Ea[G.color]:void 0,Ne=be?s.jsx(R,{name:be,className:"h-3.5 w-3.5 shrink-0",style:W?{color:W}:void 0}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:W?{color:W}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[G.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:G.iconBackground?{backgroundColor:G.iconBackground}:void 0,children:s.jsx(Ra,{project:{id:G.id,iconImage:G.iconImage??null},options:{themeVariant:P.metadata.variant,iconColor:P.colors.surface.foreground},className:"h-full w-full object-contain",fallback:Ne})}):Ne,s.jsx("span",{className:"truncate",children:U})]})},[D,P.metadata.variant,P.colors.surface.foreground]),q=c.useMemo(()=>{if(O?.path)return{id:O.id,path:O.path};const G=A??I;return G?{id:`path:${G}`,path:G}:null},[O,A,I]),[Q]=c.useState(()=>typeof window<"u"?xn():!1),Y=c.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ce=Ad(),X=c.useMemo(()=>{if(typeof window>"u")return null;const G=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof G=="number"&&Number.isFinite(G)&&G>0)return G;if(typeof navigator>"u")return null;const U=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!U)return null;const be=Number.parseInt(U[1],10),W=Number.parseInt(U[2],10);return Number.isNaN(be)?null:be===10?W:be},[]),oe=c.useMemo(()=>Q&&Y||ce?"pl-[5.5rem]":"pl-3",[Q,Y,ce]),te=c.useMemo(()=>!Q||!Y||X===null?"":X>=26?"h-12":X<=15?"h-14":"",[Q,Y,X]),he=c.useCallback(async G=>{G.target.closest("button, a, input, select, textarea")||G.button===0&&Q&&await pp()},[Q]);c.useEffect(()=>{if(!n)return;const G=U=>{U.key==="Escape"&&(U.preventDefault(),U.stopPropagation(),n())};return window.addEventListener("keydown",G,!0),()=>window.removeEventListener("keydown",G,!0)},[n]);const[_,ie]=c.useState(""),{isLoading:ge,isGitRepository:ae}=Am(T),z=c.useRef(!1),ne=ae===!0,ue=ne&&N;c.useEffect(()=>{if(ae===!1){z.current=!0,C(!1);return}ae===!0&&z.current&&(z.current=!1,C(!0))},[ae]);const me=Ci(G=>G.createMultiRun),ke=Ci(G=>G.error),Te=Ci(G=>G.clearError);c.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&u(G=>{const U=[...G];return U.length>0&&!U[0].prompt.trim()&&(U[0]={...U[0],prompt:t}),U})},[t]),c.useEffect(()=>{if(!q)return;let G=!1;return S(!0),(async()=>{try{const U=await gp(q);G||x(U)}catch{}finally{G||S(!1)}})(),()=>{G=!0}},[q]);const je=c.useCallback((G,U)=>{u(be=>be.map(W=>W.id===G?{...W,...U}:W))},[]),Ee=c.useCallback(G=>{u(U=>U.filter(be=>be.id!==G))},[]),xe=c.useCallback(()=>{u(G=>[...G,{id:$r(),prompt:"",models:[]}])},[]),H=async G=>{const U=G.target.files;if(!U)return;let be=0;for(let W=0;W<U.length;W++){const Ne=U[W];if(Ne.size>t3){Re.error(i("multirun.launcher.toast.fileTooLarge",{fileName:Ne.name}));continue}try{const Oe=await new Promise((ye,Fe)=>{const Ke=new FileReader;Ke.onload=()=>ye(Ke.result),Ke.onerror=Fe,Ke.readAsDataURL(Ne)});p(ye=>[...ye,{id:$r(),filename:Ne.name,mimeType:Ne.type||"application/octet-stream",size:Ne.size,dataUrl:Oe}]),be++}catch(Oe){console.error("File attach failed",Oe),Re.error(i("multirun.launcher.toast.attachFailed",{fileName:Ne.name}))}}be>0&&Re.success(be===1?i("multirun.launcher.toast.attachedSingle",{count:be}):i("multirun.launcher.toast.attachedPlural",{count:be})),j.current&&(j.current.value="")},Ce=G=>{p(U=>U.filter(be=>be.id!==G))},ve=c.useMemo(()=>a.reduce((G,U)=>G+U.models.length,0),[a]),re=async G=>{G.preventDefault();const U=a.filter(be=>be.prompt.trim()&&be.models.length>=1);if(U.length!==0&&!(ve<1)){w(!0),Te();try{K&&K!==M&&$(K);const be=f.map(Fe=>({mime:Fe.mimeType,filename:Fe.filename,url:Fe.dataUrl})),W=v.filter(Fe=>Fe.trim().length>0),Ne=U.map(Fe=>({prompt:Fe.prompt.trim(),models:Fe.models.map(Ke=>({providerID:Ke.providerID,modelID:Ke.modelID,displayName:Ke.displayName,variant:Ke.variant}))})),Oe={name:o.trim(),groups:Ne,agent:d||void 0,worktreeBaseBranch:ue?_:void 0,isolateRuns:ue,files:be.length>0?be:void 0,setupCommands:W.length>0?W:void 0},ye=await me(Oe);ye&&(ye.firstSessionId&&et.getState().setCurrentSession(ye.firstSessionId),e?.())}finally{w(!1)}}},le=!!(o.trim()&&a.some(G=>G.prompt.trim()&&G.models.length>=1)&&ve>=1&&T&&!ge&&(ae===!1||!ue||_)),se=v.filter(G=>G.trim()).length;return s.jsxs("form",{onSubmit:re,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:he,className:Ie("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",oe,te),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:i("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(R,{name:"close",className:"h-5 w-5"})})}),s.jsx(It,{children:s.jsx("p",{children:i("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Aa,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hn,{htmlFor:"multirun-project",required:!0,children:i("multirun.launcher.project.label")}),E.length>0?s.jsxs(Bs,{value:K??void 0,onValueChange:k,children:[s.jsx(Fs,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:O?s.jsx(Cs,{children:F(O)}):s.jsx(Cs,{placeholder:i("multirun.launcher.project.placeholder")})}),s.jsx(_s,{fitContent:!0,children:E.map(G=>s.jsx(ts,{value:G.id,className:"max-w-[24rem]",children:F(G)},G.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:i("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hn,{htmlFor:"group-name",required:!0,info:s.jsx(To,{children:i("multirun.launcher.groupName.info")}),children:i("multirun.launcher.groupName.label")}),s.jsx(Cn,{id:"group-name",value:o,onChange:G=>l(G.target.value),placeholder:i("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hn,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(To,{children:i("multirun.launcher.baseBranch.info")}),children:i("multirun.launcher.baseBranch.label")}),s.jsx(e3,{directory:T,value:_,onChange:ie,disabled:!ue,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(ur,{checked:N,onChange:C,disabled:!ne,ariaLabel:i("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:i("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hn,{htmlFor:"multirun-agent",info:s.jsx(To,{children:i("multirun.launcher.agent.info")}),children:i("multirun.launcher.agent.label")}),s.jsx(ym,{value:d,onChange:h,id:"multirun-agent"})]})]}),s.jsxs($i,{open:m,onOpenChange:b,children:[s.jsxs(au,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(R,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:i("multirun.launcher.setupCommands.label")}),se>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:se}),s.jsx(R,{name:"arrow-down-s",className:Ie("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",m&&"rotate-180")})]}),s.jsx(Wi,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:y?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:i("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[v.map((G,U)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Cn,{value:G,onChange:be=>{const W=[...v];W[U]=be.target.value,x(W)},placeholder:i("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>x(v.filter((be,W)=>W!==U)),className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]},`${G}-${U}`)),s.jsxs("button",{type:"button",onClick:()=>x([...v,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(R,{name:"add",className:"h-3 w-3"}),i("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Hn,{htmlFor:"prompt",required:!0,children:i("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:j,type:"file",multiple:!0,className:"hidden",onChange:H,accept:"*/*"}),s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>j.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(R,{name:"attachment-2",className:"h-3 w-3"}),i("multirun.launcher.attachments.attach")]})}),s.jsx(It,{children:i("multirun.launcher.attachments.tooltip")})]}),f.map(G=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[G.mimeType.startsWith("image/")?s.jsx(R,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(R,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:G.filename,children:G.filename}),s.jsx("button",{type:"button",onClick:()=>Ce(G.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(R,{name:"close",className:"h-3 w-3"})})]},G.id))]})]}),a.map((G,U)=>s.jsx(n3,{group:G,groupIndex:U,canRemove:a.length>1,onUpdate:je,onRemove:Ee},G.id)),s.jsxs("button",{type:"button",onClick:xe,className:"flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),i("multirun.launcher.groups.addGroup")]}),ke&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:ke})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[!ue&&ae!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(R,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:i("multirun.launcher.project.gitRequired")})]}):null,!r&&n?s.jsx(bt,{type:"button",variant:"ghost",size:"sm",onClick:n,children:i("multirun.launcher.actions.cancel")}):null,s.jsx(bt,{type:"submit",size:"sm",disabled:!le||g,children:g?i("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:i("multirun.launcher.actions.startWithRunCount",{count:ve})})})]})})]})},n3=t=>{const e=nt.c(99),{group:n,groupIndex:r,canRemove:i,onUpdate:o,onRemove:l}=t,{t:a}=Nt(),[u,d]=c.useState(!1),[h,f]=c.useState(""),[p,g]=c.useState(!1),[w,v]=c.useState(""),[x,m]=c.useState(!1),[b,y]=c.useState(""),S=c.useRef(null),N=c.useRef(null),C=c.useRef(null),j=c.useRef(null);let A;e[0]!==n.id||e[1]!==n.models||e[2]!==o?(A=W=>{o(n.id,{models:[...n.models,W]})},e[0]=n.id,e[1]=n.models,e[2]=o,e[3]=A):A=e[3];const D=A;let I;e[4]!==n.id||e[5]!==n.models||e[6]!==o?(I=W=>{o(n.id,{models:n.models.filter((Ne,Oe)=>Oe!==W)})},e[4]=n.id,e[5]=n.models,e[6]=o,e[7]=I):I=e[7];const M=I;let $;e[8]!==n.id||e[9]!==n.models||e[10]!==o?($=(W,Ne)=>{o(n.id,{models:n.models.map((Oe,ye)=>ye===W?Ne:Oe)})},e[8]=n.id,e[9]=n.models,e[10]=o,e[11]=$):$=e[11];const E=$;let K;e[12]===Symbol.for("react.memo_cache_sentinel")?(K=(W,Ne)=>{if(W.startsWith("/")){const Ke=W.indexOf(" "),$e=W.indexOf(`
|
|
927
|
+
`),V=Math.min(Ke===-1?W.length:Ke,$e===-1?W.length:$e);if(Ne<=V&&Ke===-1){v(W.substring(1,V)),g(!0),d(!1),m(!1);return}}g(!1);const Oe=W.substring(0,Ne),ye=Oe.lastIndexOf("#");if(ye!==-1){const Ke=ye>0?Oe[ye-1]:null,$e=Oe.substring(ye+1);if((!Ke||/\s/.test(Ke))&&!$e.includes(" ")&&!$e.includes(`
|
|
928
|
+
`)){y($e),m(!0),d(!1);return}}m(!1);const Fe=Oe.lastIndexOf("@");if(Fe!==-1){const Ke=Fe>0?Oe[Fe-1]:null,$e=Oe.substring(Fe+1);(!Ke||/\s/.test(Ke))&&!$e.includes(" ")&&!$e.includes(`
|
|
929
|
+
`)?(f($e),d(!0)):d(!1);return}d(!1)},e[12]=K):K=e[12];const B=K;let O;e[13]!==n.id||e[14]!==o?(O=W=>{o(n.id,{prompt:W})},e[13]=n.id,e[14]=o,e[15]=O):O=e[15];const T=O;let k;e[16]!==n.prompt||e[17]!==T?(k=W=>{const Ne=n.prompt,ye=S.current?.selectionStart??Ne.length,Ke=Ne.substring(0,ye).lastIndexOf("@"),$e=W.relativePath&&W.relativePath.trim().length>0?W.relativePath.trim():W.path||W.name,V=Ke!==-1?Ke:ye,fe=`${Ne.substring(0,V)}@${$e} ${Ne.substring(ye)}`,Me=V+$e.length+2;T(fe),d(!1),f(""),requestAnimationFrame(()=>{const De=S.current;De&&(De.selectionStart=Me,De.selectionEnd=Me,De.focus()),B(fe,Me)})},e[16]=n.prompt,e[17]=T,e[18]=k):k=e[18];const P=k;let F;e[19]!==n.prompt||e[20]!==T?(F=W=>{const Ne=n.prompt,ye=S.current?.selectionStart??Ne.length,Ke=Ne.substring(0,ye).lastIndexOf("@"),$e=Ke!==-1?Ke:ye,V=`${Ne.substring(0,$e)}@${W} ${Ne.substring(ye)}`,fe=$e+W.length+2;T(V),d(!1),f(""),requestAnimationFrame(()=>{const Me=S.current;Me&&(Me.selectionStart=fe,Me.selectionEnd=fe,Me.focus()),B(V,fe)})},e[19]=n.prompt,e[20]=T,e[21]=F):F=e[21];const q=F;let Q;e[22]!==T?(Q=W=>{const Ne=`/${W.name} `;T(Ne),g(!1),v(""),m(!1),requestAnimationFrame(()=>{const Oe=S.current;Oe&&(Oe.focus(),Oe.selectionStart=Oe.value.length,Oe.selectionEnd=Oe.value.length),B(Ne,Ne.length)})},e[22]=T,e[23]=Q):Q=e[23];const Y=Q;let ce;e[24]!==n.prompt||e[25]!==T?(ce=(W,Ne)=>{const Oe=n.prompt,Fe=S.current?.selectionStart??Oe.length,$e=Oe.substring(0,Fe).lastIndexOf("#"),V=$e!==-1?$e:Fe,fe=`${Oe.substring(0,V)}#${Ne} ${Oe.substring(Fe)}`,Me=V+Ne.length+2;T(fe),m(!1),y(""),requestAnimationFrame(()=>{const De=S.current;De&&(De.selectionStart=Me,De.selectionEnd=Me,De.focus()),B(fe,Me)})},e[24]=n.prompt,e[25]=T,e[26]=ce):ce=e[26];const X=ce;let oe;e[27]!==p||e[28]!==u||e[29]!==x?(oe=W=>{if(p&&C.current&&(W.key==="Enter"||W.key==="ArrowUp"||W.key==="ArrowDown"||W.key==="Escape"||W.key==="Tab")){W.preventDefault(),C.current.handleKeyDown(W.key);return}u&&N.current&&(W.key==="Enter"||W.key==="ArrowUp"||W.key==="ArrowDown"||W.key==="Escape"||W.key==="Tab")&&(W.preventDefault(),N.current.handleKeyDown(W.key)),x&&j.current&&(W.key==="Enter"||W.key==="ArrowUp"||W.key==="ArrowDown"||W.key==="Escape"||W.key==="Tab")&&(W.preventDefault(),j.current.handleKeyDown(W.key))},e[27]=p,e[28]=u,e[29]=x,e[30]=oe):oe=e[30];const te=oe,he=r+1;let _;e[31]!==a||e[32]!==he?(_=a("multirun.launcher.groups.groupLabel",{index:he}),e[31]=a,e[32]=he,e[33]=_):_=e[33];let ie;e[34]!==_?(ie=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:_}),e[34]=_,e[35]=ie):ie=e[35];let ge;e[36]!==i||e[37]!==n.id||e[38]!==l||e[39]!==a?(ge=i&&s.jsx("button",{type:"button",onClick:()=>l(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":a("multirun.launcher.groups.removeGroup"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=i,e[37]=n.id,e[38]=l,e[39]=a,e[40]=ge):ge=e[40];let ae;e[41]!==ie||e[42]!==ge?(ae=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ie,ge]}),e[41]=ie,e[42]=ge,e[43]=ae):ae=e[43];let z;e[44]!==a?(z=a("multirun.launcher.groups.prompt.label"),e[44]=a,e[45]=z):z=e[45];let ne;e[46]!==z?(ne=s.jsx(Hn,{required:!0,children:z}),e[46]=z,e[47]=ne):ne=e[47];const ue=n.prompt;let me;e[48]!==T?(me=W=>{const Ne=W.target.value;T(Ne);const Oe=W.target.selectionStart??Ne.length;B(Ne,Oe)},e[48]=T,e[49]=me):me=e[49];let ke;e[50]!==a?(ke=a("multirun.launcher.groups.prompt.placeholder"),e[50]=a,e[51]=ke):ke=e[51];let Te;e[52]!==n.prompt||e[53]!==te||e[54]!==me||e[55]!==ke?(Te=s.jsx(lr,{ref:S,value:ue,onChange:me,onKeyDown:te,placeholder:ke,className:"typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content",required:!0}),e[52]=n.prompt,e[53]=te,e[54]=me,e[55]=ke,e[56]=Te):Te=e[56];let je;e[57]!==w||e[58]!==Y||e[59]!==p?(je=p?s.jsx(Jd,{ref:C,searchQuery:w,onCommandSelect:Y,onClose:()=>g(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=w,e[58]=Y,e[59]=p,e[60]=je):je=e[60];let Ee;e[61]!==q||e[62]!==P||e[63]!==h||e[64]!==u?(Ee=u?s.jsx(Zd,{ref:N,searchQuery:h,onFileSelect:P,onAgentSelect:q,onClose:()=>d(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=q,e[62]=P,e[63]=h,e[64]=u,e[65]=Ee):Ee=e[65];let xe;e[66]!==X||e[67]!==x||e[68]!==b?(xe=x?s.jsx(eu,{ref:j,searchQuery:b,onSnippetSelect:X,onClose:()=>m(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=X,e[67]=x,e[68]=b,e[69]=xe):xe=e[69];let H;e[70]!==Te||e[71]!==je||e[72]!==Ee||e[73]!==xe?(H=s.jsxs("div",{className:"relative",children:[Te,je,Ee,xe]}),e[70]=Te,e[71]=je,e[72]=Ee,e[73]=xe,e[74]=H):H=e[74];let Ce;e[75]!==ne||e[76]!==H?(Ce=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ne,H]}),e[75]=ne,e[76]=H,e[77]=Ce):Ce=e[77];let ve;e[78]!==a?(ve=a("multirun.launcher.models.info"),e[78]=a,e[79]=ve):ve=e[79];let re;e[80]!==ve?(re=s.jsx(To,{children:ve}),e[80]=ve,e[81]=re):re=e[81];let le;e[82]!==a?(le=a("multirun.launcher.models.label"),e[82]=a,e[83]=le):le=e[83];let se;e[84]!==re||e[85]!==le?(se=s.jsx(Hn,{required:!0,info:re,children:le}),e[84]=re,e[85]=le,e[86]=se):se=e[86];let G;e[87]!==n.models||e[88]!==D||e[89]!==M||e[90]!==E?(G=s.jsx(wm,{selectedModels:n.models,onAdd:D,onRemove:M,onUpdate:E,minModels:1}),e[87]=n.models,e[88]=D,e[89]=M,e[90]=E,e[91]=G):G=e[91];let U;e[92]!==se||e[93]!==G?(U=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[se,G]}),e[92]=se,e[93]=G,e[94]=U):U=e[94];let be;return e[95]!==ae||e[96]!==Ce||e[97]!==U?(be=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[ae,Ce,U]}),e[95]=ae,e[96]=Ce,e[97]=U,e[98]=be):be=e[98],be},r3=t=>{const e=new Map;for(const n of t){const r=$s(n);r&&e.set(n.id,{directory:r,sessionId:n.id})}return e},o3=(t,e)=>{if(!t)return[];const n=[];return t.forEach((r,i)=>{e.has(i)||n.push(r)}),n},i3=t=>{const e=nt.c(5),{enabled:n,hasAuthoritativeGlobalSessions:r,sessions:i}=t,o=n===void 0?!0:n,l=c.useRef(null);let a,u;e[0]!==o||e[1]!==r||e[2]!==i?(a=()=>{if(!o||!r)return;const d=ps(),h=r3(i),f=l.current?.runtimeKey===d?l.current.identities:null;for(const p of o3(f,h))xp({runtimeKey:d,...p});l.current={runtimeKey:d,identities:h}},u=[o,r,i],e[0]=o,e[1]=r,e[2]=i,e[3]=a,e[4]=u):(a=e[3],u=e[4]),c.useEffect(a,u)},a3=new Map,l3=t=>{const e=nt.c(26),{isVSCode:n}=t,r=Fa(),i=Vt(c3),o=Vt(d3),l=es(u3),a=et(m3);let u;e[0]!==n?(u=I=>n?a3:I.availableWorktreesByProject,e[0]=n,e[1]=u):u=e[1];const d=et(u),h=!n;let f;e[2]!==d||e[3]!==i||e[4]!==h?(f=km(i,d,{includeWorktrees:h}),e[2]=d,e[3]=i,e[4]=h,e[5]=f):f=e[5];const p=f,g=Ps(f3),w=Ps(h3),v=Ps(p3),x=`session-list-sync:${c.useId()}`;let m,b;e[6]!==o||e[7]!==x||e[8]!==r||e[9]!==l||e[10]!==a||e[11]!==p||e[12]!==i?(m=()=>(r.setBootstrapDemand(x,hm({knownDirectories:p,activeProjectDirectory:wt(i.find(I=>I.id===o)?.path??null),activeProjectId:o,collapsedProjects:new Set,collapsedGroups:new Set,currentDirectory:l,currentSessionDirectory:a})),()=>r.clearBootstrapDemand(x)),b=[o,x,r,l,a,p,i],e[6]=o,e[7]=x,e[8]=r,e[9]=l,e[10]=a,e[11]=p,e[12]=i,e[13]=m,e[14]=b):(m=e[13],b=e[14]),c.useEffect(m,b);const y=c.useRef(null);let S,N;e[15]!==n||e[16]!==p?(S=()=>{const I=new Set(p),M=y.current;y.current=I;const $=M?[...I].filter(E=>!M.has(E)):n?[...I]:[];$.length&&ka($,Oo())},N=[n,p],e[15]=n,e[16]=p,e[17]=S,e[18]=N):(S=e[17],N=e[18]),c.useEffect(S,N);let C;e[19]===Symbol.for("react.memo_cache_sentinel")?(C=[],e[19]=C):C=e[19],c.useEffect(g3,C);let j;e[20]!==w||e[21]!==g?(j=[...g,...w],e[20]=w,e[21]=g,e[22]=j):j=e[22];const A=j;let D;e[23]!==A||e[24]!==v?(D={enabled:!0,hasAuthoritativeGlobalSessions:v,sessions:A},e[23]=A,e[24]=v,e[25]=D):D=e[25],i3(D)};function c3(t){return t.projects}function d3(t){return t.activeProjectId}function u3(t){return t.currentDirectory}function m3(t){return t.currentSessionDirectory}function f3(t){return t.activeSessions}function h3(t){return t.archivedSessions}function p3(t){return t.status==="ready"}function g3(){let t=null,e=!1;const n=new Set,r=eo(i=>{if(i.type==="scheduled-task-ran")e=!0;else if(i.type==="session-created")n.add(i.directory);else return;t&&clearTimeout(t),t=setTimeout(()=>{if(t=null,e){e=!1,n.clear(),_a(Oo());return}const o=[...n];n.clear(),o.length&&ka(o,Oo())},500)});return()=>{t&&clearTimeout(t),r()}}const x3=$n(()=>_n(()=>import("./SettingsWindow-DQQFnrSZ.js"),__vite__mapDeps([139,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,140,116,141,126,127,128,129,117,118,102,103,87,88,89,90,91,92,93,94,95,96,97,98,99,100,142,143])).then(t=>({default:t.SettingsWindow}))),b3=()=>{const t=nt.c(58);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={isVSCode:!1},t[0]=e):e=t[0],l3(e),jg();const n=Pe(y3),r=Pe(w3),i=Pe(S3),o=Pe(v3),[l,a]=c.useState(!1);let u,d;t[1]!==i?(u=()=>{i&&a(!0)},d=[i],t[1]=i,t[2]=u,t[3]=d):(u=t[2],d=t[3]),c.useEffect(u,d);const h=Pe(j3),f=Pe(k3),p=Pe(C3),g=Pe(N3),w=Pe(A3),v=Pe(D3),x=g||w||!!v||h;let m;t[4]===Symbol.for("react.memo_cache_sentinel")?(m=[],t[4]=m):m=t[4],c.useEffect(I3,m);const{isMobile:b}=Ln();kg();const y=Zx();let S,N;t[5]!==b||t[6]!==r?(S=()=>{Pe.getState().isMobile!==b&&r(b)},N=[b,r],t[5]=b,t[6]=r,t[7]=S,t[8]=N):(S=t[7],N=t[8]),c.useEffect(S,N);let C,j,A,D;t[9]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(VS,{}),j=s.jsx(Lv,{}),A=s.jsx(Vv,{}),D=s.jsx(n4,{}),t[9]=C,t[10]=j,t[11]=A,t[12]=D):(C=t[9],j=t[10],A=t[11],D=t[12]);let I;t[13]!==y?(I=s.jsx(r4,{value:y,onMoveSessionOnly:T3,onMoveAllChanges:E3,onCancel:lb}),t[13]=y,t[14]=I):I=t[14];let M;t[15]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(xb,{}),t[15]=M):M=t[15];let $;t[16]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(gb,{}),t[16]=$):$=t[16];let E;t[17]!==n?(E=s.jsx(s4,{isVisible:n}),t[17]=n,t[18]=E):E=t[18];let K;t[19]!==b||t[20]!==n||t[21]!==E?(K=s.jsx(pb,{isOpen:n,isMobile:b,className:"border-border",topBar:$,children:E}),t[19]=b,t[20]=n,t[21]=E,t[22]=K):K=t[22];let B;t[23]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(fb,{}),t[23]=B):B=t[23];const O=x&&"invisible";let T;t[24]!==O?(T=Ie("absolute inset-0",O),t[24]=O,t[25]=T):T=t[25];const k=!i&&!x;let P;t[26]!==k?(P=s.jsx(Hs,{children:s.jsx(uu,{active:k})}),t[26]=k,t[27]=P):P=t[27];let F;t[28]!==T||t[29]!==P?(F=s.jsx("div",{className:T,children:P}),t[28]=T,t[29]=P,t[30]=F):F=t[30];let q;t[31]!==h||t[32]!==p||t[33]!==f?(q=h&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Hs,{children:s.jsx(s3,{isWindowed:!0,initialPrompt:p,onCreated:()=>f(!1),onCancel:()=>f(!1)})})}),t[31]=h,t[32]=p,t[33]=f,t[34]=q):q=t[34];let Q;t[35]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(Hs,{children:s.jsx(T4,{})}),t[35]=Q):Q=t[35];let Y;t[36]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(Hs,{children:s.jsx(E4,{})}),t[36]=Y):Y=t[36];let ce;t[37]===Symbol.for("react.memo_cache_sentinel")?(ce=s.jsx(Hs,{children:s.jsx(z4,{})}),t[37]=ce):ce=t[37];let X;t[38]!==F||t[39]!==q?(X=s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[F,q,Q,Y,ce]}),t[38]=F,t[39]=q,t[40]=X):X=t[40];let oe;t[41]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx(fS,{}),t[41]=oe):oe=t[41];let te;t[42]!==X?(te=s.jsx("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border bg-background","data-page-scroll-lock":"true",children:s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true","data-chat-area":"true",children:[X,oe]})})}),t[42]=X,t[43]=te):te=t[43];let he;t[44]===Symbol.for("react.memo_cache_sentinel")?(he=s.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:s.jsx(Hs,{children:s.jsx(jS,{})})}),t[44]=he):he=t[44];let _;t[45]!==te?(_=s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[B,s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[te,he]})]}),t[45]=te,t[46]=_):_=t[46];let ie;t[47]!==K||t[48]!==_?(ie=s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[K,_]}),t[47]=K,t[48]=_,t[49]=ie):ie=t[49];let ge;t[50]!==i||t[51]!==o||t[52]!==l?(ge=l?s.jsx(c.Suspense,{fallback:null,children:s.jsx(x3,{open:i,onOpenChange:o})}):null,t[50]=i,t[51]=o,t[52]=l,t[53]=ge):ge=t[53];let ae;return t[54]!==I||t[55]!==ie||t[56]!==ge?(ae=s.jsx(Cg,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:"main-content-safe-area relative flex h-[100dvh] bg-background",children:[C,j,A,D,I,M,ie,ge]})}),t[54]=I,t[55]=ie,t[56]=ge,t[57]=ae):ae=t[57],ae};function y3(t){return t.isSidebarOpen}function w3(t){return t.setIsMobile}function S3(t){return t.isSettingsDialogOpen}function v3(t){return t.setSettingsDialogOpen}function j3(t){return t.isMultiRunLauncherOpen}function k3(t){return t.setMultiRunLauncherOpen}function C3(t){return t.multiRunLauncherPrefillPrompt}function N3(t){return t.isScheduledTasksDialogOpen}function A3(t){return t.isArchivePageOpen}function D3(t){return t.worktreesPageProjectId}function P3(){return Pe.getState().closeMainSurfaces()}function I3(){const t=P3,e=et.subscribe((n,r)=>{const i=!!n.currentSessionId&&n.currentSessionId!==r.currentSessionId,o=!!n.newSessionDraft?.open&&n.newSessionDraft!==r.newSessionDraft;(i||o)&&t()});return()=>{e()}}function T3(){return Fu(!1)}function E3(){return Fu(!0)}const Dm=12,R3=[{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"}],M3=t=>{const e=nt.c(18),{isActive:n,burstKey:r,className:i,durationMs:o,bursts:l,onComplete:a}=t,u=r===void 0?0:r,d=o===void 0?900:o,h=l===void 0?R3:l,f=xt.useRef(!1);let p,g;e[0]!==n||e[1]!==a?(p=()=>{!n&&f.current&&a?.(),n&&(f.current=!0)},g=[n,a],e[0]=n,e[1]=a,e[2]=p,e[3]=g):(p=e[2],g=e[3]),xt.useEffect(p,g);let w;e[4]===Symbol.for("react.memo_cache_sentinel")?(w=Array.from({length:Dm},O3),e[4]=w):w=e[4];const v=w;if(!n)return null;let x;e[5]!==i?(x=Ie("fireworks-overlay pointer-events-none",i),e[5]=i,e[6]=x):x=e[6];let m;if(e[7]!==u||e[8]!==h||e[9]!==d){let y;e[11]!==u||e[12]!==d?(y=S=>{const N={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${d}ms`};return s.jsx("div",{className:"firework-burst",style:N,children:v.map((C,j)=>{const A=C.x*S.radius,D=C.y*S.radius,I={"--translate-x":`${A}px`,"--translate-y":`${D}px`,"--particle-delay":`${C.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:I},`${S.id}-${j}-${u}`)})},`${S.id}-${u}`)},e[11]=u,e[12]=d,e[13]=y):y=e[13],m=h.map(y),e[7]=u,e[8]=h,e[9]=d,e[10]=m}else m=e[10];let b;return e[14]!==u||e[15]!==x||e[16]!==m?(b=s.jsx("div",{className:x,"aria-hidden":"true","data-burst-key":u,children:m}),e[14]=u,e[15]=x,e[16]=m,e[17]=b):b=e[17],b};function O3(t,e){const n=Math.PI*2*e/Dm;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const B3=t=>{const e=nt.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,i=r===void 0?3400:r;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={isActive:!1,cycle:0},e[2]=o):o=e[2];const[l,a]=xt.useState(o),u=xt.useRef(null);let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{u.current&&(window.clearTimeout(u.current),u.current=null)},e[3]=d):d=e[3];const h=d;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{h(),a(F3)},e[4]=f):f=e[4];const p=f;let g;e[5]!==i?(g=()=>{h(),a(_3),u.current=window.setTimeout(()=>{a(L3),u.current=null},i)},e[5]=i,e[6]=g):g=e[6];const w=g;let v,x;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>h(),x=[h],e[7]=v,e[8]=x):(v=e[7],x=e[8]),xt.useEffect(v,x);let m;return e[9]!==l.cycle||e[10]!==l.isActive||e[11]!==w?(m={isActive:l.isActive,burstKey:l.cycle,triggerFireworks:w,dismissFireworks:p},e[9]=l.cycle,e[10]=l.isActive,e[11]=w,e[12]=m):m=e[12],m};function F3(t){return t.isActive?{...t,isActive:!1}:t}function _3(t){return{isActive:!0,cycle:t.cycle+1}}function L3(t){return t.isActive?{...t,isActive:!1}:t}const Pm=c.createContext(void 0),$3=t=>{const e=nt.c(10),{children:n}=t,{isActive:r,burstKey:i,triggerFireworks:o,dismissFireworks:l}=B3();let a;e[0]!==l||e[1]!==o?(a={triggerFireworks:o,dismissFireworks:l},e[0]=l,e[1]=o,e[2]=a):a=e[2];const u=a;let d;e[3]!==i||e[4]!==r?(d=s.jsx(M3,{isActive:r,burstKey:i}),e[3]=i,e[4]=r,e[5]=d):d=e[5];let h;return e[6]!==n||e[7]!==d||e[8]!==u?(h=s.jsxs(Pm.Provider,{value:u,children:[n,d]}),e[6]=n,e[7]=d,e[8]=u,e[9]=h):h=e[9],h},k5=()=>{const t=c.useContext(Pm);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},xa="openchamber_requests_in_flight",Im=1e3,W3=300*1e3,Ho=Math.ceil(W3/Im),z3=()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(xa)==="1"}catch{return!1}},Tm=()=>({enabled:!0,startedAt:Date.now(),inFlight:0,peak:0,totalStarted:0,totalSettled:0,samples:[],p50Samples:[],p90Samples:[],p99Samples:[],maxSamples:[],peakAgeMs:0,inFlightStarts:new Map,sampleCount:0,lastSampleAt:null,fetchWrapped:!1,originalFetch:null,sampleTimer:null});let V3=1;const U3=(t,e)=>{const n=window.__openchamberRequestsInFlight__;!n||!n.enabled||(n.inFlight+=1,n.totalStarted+=1,n.inFlight>n.peak&&(n.peak=n.inFlight),n.inFlightStarts.set(t,e))},K3=t=>{const e=window.__openchamberRequestsInFlight__;!e||!e.enabled||(e.inFlight=Math.max(0,e.inFlight-1),e.totalSettled+=1,e.inFlightStarts.delete(t))},Em=t=>{if(t.inFlightStarts.size===0)return[];const e=Date.now(),n=[];for(const r of t.inFlightStarts.values())n.push(Math.max(0,e-r));return n.sort((r,i)=>r-i),n},yr=(t,e)=>{const n=t.length;if(n===0)return 0;if(n===1)return t[0];const r=e/100*(n-1),i=Math.floor(r),o=Math.ceil(r);return i===o?t[i]:t[i]+(t[o]-t[i])*(r-i)},H3=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;if(!t||t.fetchWrapped)return;const e=window.fetch.bind(window);t.originalFetch=e,t.fetchWrapped=!0;const n=async(r,i)=>{const o=V3++;U3(o,Date.now());try{return await e(r,i)}finally{K3(o)}};window.fetch=n},Jc=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;!t||!t.fetchWrapped||!t.originalFetch||(window.fetch=t.originalFetch,t.fetchWrapped=!1,t.originalFetch=null)},Er=t=>{t.length>Ho&&t.splice(0,t.length-Ho)},G3=()=>{const t=window.__openchamberRequestsInFlight__;if(!t||!t.enabled)return;t.samples.push(t.inFlight);const e=Em(t),n=e.length>0?e[e.length-1]:0;t.p50Samples.push(yr(e,50)),t.p90Samples.push(yr(e,90)),t.p99Samples.push(yr(e,99)),t.maxSamples.push(n),n>t.peakAgeMs&&(t.peakAgeMs=n),t.sampleCount+=1,Er(t.samples),Er(t.p50Samples),Er(t.p90Samples),Er(t.p99Samples),Er(t.maxSamples),t.lastSampleAt=Date.now()},q3=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;!t||t.sampleTimer!=null||(t.sampleTimer=window.setInterval(G3,Im))},Zc=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;!t||t.sampleTimer==null||(window.clearInterval(t.sampleTimer),t.sampleTimer=null)},ed=t=>{if(!(typeof window>"u"))try{if(t){Zc(),Jc(),window.localStorage.setItem(xa,"1"),window.__openchamberRequestsInFlight__=Tm(),H3(),q3();return}window.localStorage.removeItem(xa),Zc(),Jc(),delete window.__openchamberRequestsInFlight__}catch{}},Q3=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;if(!t)return;const e=Tm();t.startedAt=e.startedAt,t.inFlight=e.inFlight,t.peak=e.peak,t.totalStarted=e.totalStarted,t.totalSettled=e.totalSettled,t.samples=e.samples,t.p50Samples=e.p50Samples,t.p90Samples=e.p90Samples,t.p99Samples=e.p99Samples,t.maxSamples=e.maxSamples,t.peakAgeMs=e.peakAgeMs,t.inFlightStarts=e.inFlightStarts,t.sampleCount=e.sampleCount,t.lastSampleAt=e.lastSampleAt},ba=()=>{if(typeof window>"u")return td();const t=window.__openchamberRequestsInFlight__;if(!z3()||!t)return td();const e=Em(t);return{enabled:!0,startedAt:t.startedAt,durationMs:Math.max(0,Date.now()-t.startedAt),inFlight:t.inFlight,peak:t.peak,totalStarted:t.totalStarted,totalSettled:t.totalSettled,samples:t.samples.slice(),ageP50:yr(e,50),ageP90:yr(e,90),ageP99:yr(e,99),ageMax:e.length>0?e[e.length-1]:0,peakAgeMs:t.peakAgeMs,p50Samples:t.p50Samples.slice(),p90Samples:t.p90Samples.slice(),p99Samples:t.p99Samples.slice(),maxSamples:t.maxSamples.slice(),sampleCount:t.sampleCount,lastSampleAt:t.lastSampleAt,windowSeconds:Ho}},td=()=>({enabled:!1,startedAt:null,durationMs:0,inFlight:0,peak:0,totalStarted:0,totalSettled:0,samples:[],ageP50:0,ageP90:0,ageP99:0,ageMax:0,peakAgeMs:0,p50Samples:[],p90Samples:[],p99Samples:[],maxSamples:[],sampleCount:0,lastSampleAt:null,windowSeconds:Ho});function Y3(t){switch(t){case"memory":return"database-2";case"streaming":return"bar-chart-box";case"requests":return"pulse"}}const Rm=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},ya=t=>`${(t/1e3).toFixed(2)} s`,ys=t=>{const e=nt.c(8),{label:n,value:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=i):i=e[0];let o;e[1]!==n?(o=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=o):o=e[2];let l;e[3]!==r?(l=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=l):l=e[4];let a;return e[5]!==o||e[6]!==l?(a=s.jsxs("div",{className:"rounded-md p-2",style:i,children:[o,l]}),e[5]=o,e[6]=l,e[7]=a):a=e[7],a},sd=t=>{const e=nt.c(43),{title:n,snapshot:r,emptyLabel:i}=t,{t:o}=Nt();let l;if(e[0]!==i||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==o||e[6]!==n){const a=r.entries.slice(0,12);let u;e[8]!==r.entries?(u=r.entries.reduce(Z3,0),e[8]=r.entries,e[9]=u):u=e[9];const d=u;let h;e[10]!==n?(h=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=h):h=e[11];let f;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==o?(f=r.startedAt?Rm(r.durationMs):o("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=o,e[15]=f):f=e[15];let p;e[16]!==f?(p=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:f}),e[16]=f,e[17]=p):p=e[17];let g;e[18]!==h||e[19]!==p?(g=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h,p]}),e[18]=h,e[19]=p,e[20]=g):g=e[20];let w;e[21]!==o?(w=o("memoryDebugPanel.metric.metrics"),e[21]=o,e[22]=w):w=e[22];let v;e[23]!==r.entries.length||e[24]!==w?(v=s.jsx(ys,{label:w,value:r.entries.length}),e[23]=r.entries.length,e[24]=w,e[25]=v):v=e[25];let x;e[26]!==o?(x=o("memoryDebugPanel.metric.samples"),e[26]=o,e[27]=x):x=e[27];let m;e[28]!==x||e[29]!==d?(m=s.jsx(ys,{label:x,value:d}),e[28]=x,e[29]=d,e[30]=m):m=e[30];let b;e[31]!==o?(b=o("memoryDebugPanel.metric.lastUpdate"),e[31]=o,e[32]=b):b=e[32];let y;e[33]!==r.lastUpdatedAt||e[34]!==o?(y=r.lastUpdatedAt?o("memoryDebugPanel.common.live"):o("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=o,e[35]=y):y=e[35];let S;e[36]!==b||e[37]!==y?(S=s.jsx(ys,{label:b,value:y}),e[36]=b,e[37]=y,e[38]=S):S=e[38];let N;e[39]!==m||e[40]!==S||e[41]!==v?(N=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,m,S]}),e[39]=m,e[40]=S,e[41]=v,e[42]=N):N=e[42],l=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[g,N,a.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:i}):s.jsx(Nn,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:a.map(C=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:C.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:o("memoryDebugPanel.metric.countValue",{value:C.count})}),s.jsx("span",{children:o("memoryDebugPanel.metric.avgValue",{value:C.avg})}),s.jsx("span",{children:o("memoryDebugPanel.metric.maxValue",{value:C.max})}),s.jsx("span",{children:o("memoryDebugPanel.metric.totalValue",{value:C.total})})]})]},C.metric))})})]}),e[0]=i,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=o,e[6]=n,e[7]=l}else l=e[7];return l},nd=t=>{const e=nt.c(24),{series:n,peak:r,windowSeconds:i,ariaLabel:o,maxLabel:l}=t,a=i,u=n.reduce(eC,0),d=r>0?52/r:0;let h;e[0]!==u||e[1]!==a?(h=S=>a-u+S,e[0]=u,e[1]=a,e[2]=h):h=e[2];const f=h;let p;e[3]!==d?(p=S=>56-S*d,e[3]=d,e[4]=p):p=e[4];const g=p;let w;e[5]!==l?(w=s.jsx("span",{className:"pointer-events-none absolute left-0 top-0 typography-meta text-[var(--surface-muted-foreground)]",children:l}),e[5]=l,e[6]=w):w=e[6];const v=`0 0 ${a} 56`;let x;e[7]!==a?(x=s.jsx("line",{x1:0,y1:56,x2:a,y2:56,stroke:"var(--interactive-border)",strokeWidth:1,vectorEffect:"non-scaling-stroke"}),e[7]=a,e[8]=x):x=e[8];let m;if(e[9]!==n||e[10]!==f||e[11]!==g){let S;e[13]!==f||e[14]!==g?(S=(N,C)=>{const j=N.samples.length;if(j===0)return null;const A=N.samples.map((I,M)=>`${f(M)},${g(I).toFixed(2)}`),D=`M ${A.join(" L ")}`;return s.jsxs(c.Fragment,{children:[N.filled?s.jsx("path",{d:`M ${f(0)},56 L ${A.join(" L ")} L ${f(j-1)},56 Z`,fill:`color-mix(in srgb, ${N.color} 18%, transparent)`,stroke:"none"}):null,s.jsx("path",{d:D,fill:"none",stroke:N.color,strokeWidth:1.5,strokeLinejoin:"round",strokeLinecap:"round",vectorEffect:"non-scaling-stroke"})]},C)},e[13]=f,e[14]=g,e[15]=S):S=e[15],m=n.map(S),e[9]=n,e[10]=f,e[11]=g,e[12]=m}else m=e[12];let b;e[16]!==o||e[17]!==v||e[18]!==x||e[19]!==m?(b=s.jsxs("svg",{viewBox:v,preserveAspectRatio:"none",className:"h-14 w-full",role:"img","aria-label":o,children:[x,m]}),e[16]=o,e[17]=v,e[18]=x,e[19]=m,e[20]=b):b=e[20];let y;return e[21]!==w||e[22]!==b?(y=s.jsxs("div",{className:"relative w-full",children:[w,b]}),e[21]=w,e[22]=b,e[23]=y):y=e[23],y},X3=t=>{const e=nt.c(100),{onClose:n}=t,{t:r}=Nt(),[i,o]=c.useState("memory"),[l,a]=c.useState("idle"),u=et(tC),d=qd(sC),h=Md(),f=bp(nC),p=Ks(rC),[g,w]=c.useState(oC),[v,x]=c.useState(iC),[m,b]=c.useState(aC),y=[{label:"p50",current:m.ageP50,samples:m.p50Samples,color:"var(--status-success)"},{label:"p90",current:m.ageP90,samples:m.p90Samples,color:"var(--status-info)"},{label:"p99",current:m.ageP99,samples:m.p99Samples,color:"var(--status-warning)"},{label:"max",current:m.ageMax,samples:m.maxSamples,color:"var(--status-error)"}];let S;e[0]!==m.samples?(S=m.samples.reduce(lC,0),e[0]=m.samples,e[1]=S):S=e[1];const N=S,C=y.reduce(dC,0);let j;e[2]!==g.entries?(j=new Map,g.entries.forEach(Me=>{j.set(Me.metric,Me.count)}),e[2]=g.entries,e[3]=j):j=e[3];let A;e[4]!==j?(A=j.get("ui.message_list.render")??0,e[4]=j,e[5]=A):A=e[5];let D;e[6]!==j?(D=j.get("ui.message_list.render.streaming")??0,e[6]=j,e[7]=D):D=e[7];let I;e[8]!==j?(I=j.get("ui.chat_message.render")??0,e[8]=j,e[9]=I):I=e[9];let M;e[10]!==j?(M=j.get("ui.chat_message.render.streaming")??0,e[10]=j,e[11]=M):M=e[11];let $;e[12]!==j?($=j.get("ui.chat_message.render.static_during_stream")??0,e[12]=j,e[13]=$):$=e[13];let E;e[14]!==j?(E=j.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[14]=j,e[15]=E):E=e[15];let K;e[16]!==A||e[17]!==D||e[18]!==I||e[19]!==M||e[20]!==$||e[21]!==E?(K={messageListRender:A,messageListRenderStreaming:D,chatMessageRender:I,chatMessageRenderStreaming:M,chatMessageRenderStaticDuringStream:$,chatMessageRenderStaticOutsideActiveTurnDuringStream:E},e[16]=A,e[17]=D,e[18]=I,e[19]=M,e[20]=$,e[21]=E,e[22]=K):K=e[22];const B=K;let O,T;e[23]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{const Me=()=>{w(xo()),x(bo()),b(ba())};Me();const De=window.setInterval(Me,500);return()=>window.clearInterval(De)},O=[],e[23]=O,e[24]=T):(O=e[23],T=e[24]),c.useEffect(T,O);let k,P;e[25]!==l?(k=()=>{if(l==="idle")return;const Me=window.setTimeout(()=>{a("idle")},1500);return()=>window.clearTimeout(Me)},P=[l],e[25]=l,e[26]=k,e[27]=P):(k=e[26],P=e[27]),c.useEffect(k,P);let F=0,q=0,Q=0;for(const Me of Object.keys(f)){const De=f[Me]??[];q=q+De.length;for(const at of De)at.role==="user"?Q=Q+1:at.role==="assistant"&&(F=F+1)}let Y;e[28]!==F||e[29]!==q||e[30]!==Q?(Y={assistant:F,total:q,user:Q},e[28]=F,e[29]=q,e[30]=Q,e[31]=Y):Y=e[31];const ce=Y;let X;if(e[32]!==u||e[33]!==f||e[34]!==d||e[35]!==h||e[36]!==r){let Me;e[38]!==u||e[39]!==f||e[40]!==d||e[41]!==r?(Me=De=>{const at=f[De.id]??[];let Qe=0,lt=0;for(const J of at)J.role==="user"?lt=lt+1:J.role==="assistant"&&(Qe=Qe+1);const de=d.get(De.id);return{id:De.id,title:De.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:Qe,messageCount:at.length,userMessageCount:lt,isStreaming:de?.isStreaming||!1,isZombie:de?.isZombie||!1,backgroundCount:de?.backgroundMessageCount||0,lastAccessed:de?.lastAccessedAt||0,isCurrent:De.id===u}},e[38]=u,e[39]=f,e[40]=d,e[41]=r,e[42]=Me):Me=e[42],X=h.map(Me).sort(uC),e[32]=u,e[33]=f,e[34]=d,e[35]=h,e[36]=r,e[37]=X}else X=e[37];const oe=X;let te;e[43]!==f?(te=Object.keys(f),e[43]=f,e[44]=te):te=e[44];const he=te.length;let _;e[45]===Symbol.for("react.memo_cache_sentinel")?(_=async()=>{try{const Me={generatedAt:new Date().toISOString(),ui:xo(),vscode:bo()};await navigator.clipboard.writeText(JSON.stringify(Me,null,2)),a("copied")}catch{a("error")}},e[45]=_):_=e[45];const ie=_,ge=wp,ae="fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area";let z;e[46]===Symbol.for("react.memo_cache_sentinel")?(z={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=z):z=e[46];let ne;e[47]!==i?(ne=Y3(i),e[47]=i,e[48]=ne):ne=e[48];let ue;e[49]!==ne?(ue=s.jsx(R,{name:ne,className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[49]=ne,e[50]=ue):ue=e[50];let me;e[51]!==r?(me=r("memoryDebugPanel.title"),e[51]=r,e[52]=me):me=e[52];let ke;e[53]!==me?(ke=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:me}),e[53]=me,e[54]=ke):ke=e[54];let Te;e[55]!==ue||e[56]!==ke?(Te=s.jsxs("div",{className:"flex items-center gap-2",children:[ue,ke]}),e[55]=ue,e[56]=ke,e[57]=Te):Te=e[57];let je;e[58]!==i?(je=i==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(bt,{size:"xs",variant:"ghost",onClick:ie,children:s.jsx(R,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(bt,{size:"xs",variant:"ghost",onClick:()=>{bf(),w(xo()),x(bo())},children:s.jsx(R,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[58]=i,e[59]=je):je=e[59];let Ee;e[60]!==i?(Ee=i==="requests"?s.jsx(bt,{size:"xs",variant:"ghost",onClick:()=>{Q3(),b(ba())},children:s.jsx(R,{name:"refresh",className:"h-3.5 w-3.5"})}):null,e[60]=i,e[61]=Ee):Ee=e[61];let xe;e[62]!==n?(xe=n?s.jsx(bt,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(R,{name:"close",className:"h-4 w-4"})}):null,e[62]=n,e[63]=xe):xe=e[63];let H;e[64]!==je||e[65]!==Ee||e[66]!==xe?(H=s.jsxs("div",{className:"flex items-center gap-1",children:[je,Ee,xe]}),e[64]=je,e[65]=Ee,e[66]=xe,e[67]=H):H=e[67];let Ce;e[68]!==Te||e[69]!==H?(Ce=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[Te,H]}),e[68]=Te,e[69]=H,e[70]=Ce):Ce=e[70];let ve;e[71]===Symbol.for("react.memo_cache_sentinel")?(ve={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[71]=ve):ve=e[71];const re=i==="memory"?"secondary":"ghost";let le;e[72]===Symbol.for("react.memo_cache_sentinel")?(le=()=>o("memory"),e[72]=le):le=e[72];let se;e[73]!==r?(se=r("memoryDebugPanel.tabs.memory"),e[73]=r,e[74]=se):se=e[74];let G;e[75]!==re||e[76]!==se?(G=s.jsx(bt,{size:"sm",variant:re,className:"flex-1",onClick:le,children:se}),e[75]=re,e[76]=se,e[77]=G):G=e[77];const U=i==="streaming"?"secondary":"ghost";let be;e[78]===Symbol.for("react.memo_cache_sentinel")?(be=()=>o("streaming"),e[78]=be):be=e[78];let W;e[79]!==r?(W=r("memoryDebugPanel.tabs.streaming"),e[79]=r,e[80]=W):W=e[80];let Ne;e[81]!==U||e[82]!==W?(Ne=s.jsx(bt,{size:"sm",variant:U,className:"flex-1",onClick:be,children:W}),e[81]=U,e[82]=W,e[83]=Ne):Ne=e[83];const Oe=i==="requests"?"secondary":"ghost";let ye;e[84]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>o("requests"),e[84]=ye):ye=e[84];let Fe;e[85]!==r?(Fe=r("memoryDebugPanel.tabs.requests"),e[85]=r,e[86]=Fe):Fe=e[86];let Ke;e[87]!==Oe||e[88]!==Fe?(Ke=s.jsx(bt,{size:"sm",variant:Oe,className:"flex-1",onClick:ye,children:Fe}),e[87]=Oe,e[88]=Fe,e[89]=Ke):Ke=e[89];let $e;e[90]!==G||e[91]!==Ne||e[92]!==Ke?($e=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:ve,children:[G,Ne,Ke]}),e[90]=G,e[91]=Ne,e[92]=Ke,e[93]=$e):$e=e[93];const V=i==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(ys,{label:r("memoryDebugPanel.metric.totalMessages"),value:ce.total}),s.jsx(ys,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${he} / ${wl.MAX_SESSIONS}`}),s.jsx(ys,{label:r("memoryDebugPanel.metric.userMessages"),value:ce.user}),s.jsx(ys,{label:r("memoryDebugPanel.metric.assistantMessages"),value:ce.assistant})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:yp()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:wl.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:p})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(Nn,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:oe.map(Me=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Me.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:Me.title}),Me.isStreaming?s.jsx(R,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Me.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.roleMsgsValue",{assistant:Me.assistantMessageCount,user:Me.userMessageCount})}),s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Me.messageCount})}),Me.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Me.backgroundCount]}):null]})]},Me.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Dt,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(bt,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:h.map(mC),currentSessionId:u,cachedSessions:Object.keys(f),messageRoleCounts:ce,sessionMessageRoleCounts:oe.map(fC),memoryStates:Object.fromEntries(d)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(It,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):i==="streaming"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(l==="copied"?"memoryDebugPanel.streaming.copy.copied":l==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(bt,{size:"xs",variant:"outline",onClick:ie,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(ys,{label:r("memoryDebugPanel.metric.uiMetrics"),value:g.entries.length}),s.jsx(ys,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(ys,{label:r("memoryDebugPanel.metric.messageListRenders"),value:B.messageListRender}),s.jsx(ys,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:B.messageListRenderStreaming}),s.jsx(ys,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:B.chatMessageRender}),s.jsx(ys,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:B.chatMessageRenderStreaming}),s.jsx(ys,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:B.chatMessageRenderStaticDuringStream}),s.jsx(ys,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:B.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(sd,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:g,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(sd,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(ys,{label:r("memoryDebugPanel.requests.totalRequests"),value:`${m.totalSettled} / ${m.totalStarted}`}),s.jsx(ys,{label:r("memoryDebugPanel.requests.tracking"),value:m.startedAt?Rm(m.durationMs):r("memoryDebugPanel.common.idle")})]}),m.samples.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:r("memoryDebugPanel.requests.noSamples")}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between typography-meta",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.requests.inFlight")}),s.jsxs("span",{children:[s.jsx("span",{className:"font-medium text-[var(--surface-foreground)]",children:m.inFlight}),s.jsxs("span",{className:"text-[var(--surface-muted-foreground)]",children:[" · ",r("memoryDebugPanel.requests.peak")," "]}),s.jsx("span",{className:"font-medium text-[var(--surface-foreground)]",children:m.peak})]})]}),s.jsx(nd,{series:[{samples:m.samples,color:"var(--status-info)",filled:!0}],peak:N,windowSeconds:m.windowSeconds,ariaLabel:r("memoryDebugPanel.requests.chartLabel",{peak:m.peak}),maxLabel:`${N}`}),s.jsxs("div",{className:"flex items-center justify-between typography-meta",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.requests.duration")}),s.jsx("span",{className:"font-medium tabular-nums text-[var(--surface-foreground)]",children:ya(m.peakAgeMs)})]}),s.jsx(nd,{series:y.map(hC),peak:C,windowSeconds:m.windowSeconds,ariaLabel:r("memoryDebugPanel.requests.percentileChartLabel"),maxLabel:ya(C)}),s.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-meta",children:y.map(pC)}),s.jsxs("div",{className:"flex items-center justify-between typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r("memoryDebugPanel.requests.windowHint",{seconds:m.windowSeconds})}),s.jsx("span",{children:r("memoryDebugPanel.requests.now")})]})]})]});let fe;return e[94]!==ge||e[95]!==z||e[96]!==Ce||e[97]!==$e||e[98]!==V?(fe=s.jsxs(ge,{className:ae,style:z,children:[Ce,$e,V]}),e[94]=ge,e[95]=z,e[96]=Ce,e[97]=$e,e[98]=V,e[99]=fe):fe=e[99],fe},J3=X3;function Z3(t,e){return t+e.count}function eC(t,e){return Math.max(t,e.samples.length)}function tC(t){return t.currentSessionId}function sC(t){return t.sessionMemoryState}function nC(t){return t.message}function rC(t){return t.totalRequestCount}function oC(){return xo()}function iC(){return bo()}function aC(){return ba()}function lC(t,e){return Math.max(t,e)}function cC(t,e){return Math.max(t,e)}function dC(t,e){return e.samples.reduce(cC,t)}function uC(t,e){return e.lastAccessed-t.lastAccessed}function mC(t){return{id:t.id,title:t.title}}function fC(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}function hC(t){return{samples:t.samples,color:t.color}}function pC(t){return s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:t.color}}),s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:t.label}),s.jsx("span",{className:"font-medium tabular-nums text-[var(--surface-foreground)]",children:ya(t.current)})]},t.label)}const gC=()=>{if(typeof document>"u")return"";const t=document.activeElement;if(t instanceof HTMLTextAreaElement)return t.value.slice(t.selectionStart??0,t.selectionEnd??0);if(t instanceof HTMLInputElement){const e=t.type?.toLowerCase()??"text";if(["text","search","url","tel","password"].includes(e))return t.value.slice(t.selectionStart??0,t.selectionEnd??0)}return t instanceof HTMLElement&&t.isContentEditable?t.ownerDocument.defaultView?.getSelection?.()?.toString()??"":""},xC=async()=>{const t=gC()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},rd="openchamber:menu-action",Ni="openchamber:check-for-updates",bC=t=>{const e=et(m=>m.openNewSessionDraft),n=Pe(m=>m.toggleCommandPalette),r=Pe(m=>m.setCommandPaletteOpen),i=Pe(m=>m.toggleHelpDialog),o=Pe(m=>m.toggleSidebar),l=Pe(m=>m.setSessionSwitcherOpen),a=Pe(m=>m.setSettingsDialogOpen),u=Pe(m=>m.setAboutDialogOpen),d=Fr(m=>m.checkForUpdates),{setThemeMode:h}=er(),f=c.useRef(!1),p=c.useCallback(()=>{f.current||(f.current=!0,d().then(()=>{const{available:m,error:b}=Fr.getState();if(b){Re.error("Failed to check for updates",{description:b});return}m||Re.success("You are on the latest version")}).finally(()=>{f.current=!1}))},[d]),g=c.useCallback(()=>{gn.requestDirectoryDialog()},[]),w=c.useCallback(m=>{const b=Sp();if(b.length===0)return;const y=et.getState().currentSessionId,S=b.findIndex(j=>j.id===y);let N=m>0?0:b.length-1;S>=0&&(N=(S+m+b.length)%b.length);const C=b[N];C&&(l(!1),et.getState().setCurrentSession(C.id))},[l]),v=c.useCallback(m=>{const{activeProjectId:b,projects:y,setActiveProject:S}=Vt.getState();if(y.length===0)return;const N=y.findIndex(A=>A.id===b);let C=m>0?0:y.length-1;N>=0&&(C=(N+m+y.length)%y.length);const j=y[C];j&&S(j.id)},[]),x=c.useCallback(m=>{switch(m){case"about":u(!0);break;case"settings":a(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":l(!1);{const b=et.getState(),y=es.getState().currentDirectory;e(b.currentSessionId&&y?{directoryOverride:y}:void 0)}break;case"new-worktree-session":l(!1),$d();break;case"change-workspace":g();break;case"toggle-right-sidebar":{const b=es.getState().currentDirectory;if(!b)break;const y=Pe.getState(),S=or(b),N=y.contextPanelByDirectory[S];N?.isOpen?y.closeContextPanel(S):N?.activeTabId?y.setActiveContextPanelTab(S,N.activeTabId):y.openContextSurface(S,"git");break}case"open-right-sidebar-git":{const b=es.getState().currentDirectory;if(!b)break;Pe.getState().openContextSurface(or(b),"git");break}case"open-right-sidebar-files":{const b=es.getState().currentDirectory;if(!b)break;Pe.getState().openContextSurface(or(b),"file");break}case"toggle-terminal":{const b=es.getState().currentDirectory;if(!b)break;Pe.getState().openContextSurface(or(b),"terminal");break}case"toggle-terminal-expanded":{const b=es.getState().currentDirectory;if(!b)break;const y=or(b),S=Pe.getState(),N=S.contextPanelByDirectory[y];(N?.isOpen?N.tabs.find(j=>j.id===N.activeTabId)?.mode:null)!=="terminal"&&S.openContextSurface(y,"terminal"),S.toggleContextPanelExpanded(y);break}case"copy":{const b=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(b)||xC();break}case"theme-light":h("light");break;case"theme-dark":h("dark");break;case"theme-system":h("system");break;case"add-selection-to-chat":vp();break;case"toggle-sidebar":o();break;case"toggle-memory-debug":t?.();break;case"go-back":es.getState().goBack();break;case"go-forward":es.getState().goForward();break;case"previous-session":w(-1);break;case"next-session":w(1);break;case"previous-project":v(-1);break;case"next-project":v(1);break;case"help-dialog":i();break;case"download-logs":{Wd().catch(()=>{Re.error("Failed to collect OpenCode status")});break}}},[g,v,w,t,e,u,l,r,a,h,n,i,o]);c.useEffect(()=>{const m=y=>{const S=y.detail;S&&x(S)},b=()=>{p()};return window.addEventListener(rd,m),window.addEventListener(Ni,b),()=>{window.removeEventListener(rd,m),window.removeEventListener(Ni,b)}},[x,p]),c.useEffect(()=>{if(typeof window>"u")return;const b=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof b!="function")return;let y=null,S=null;return b("openchamber:menu-action",N=>{const C=N?.payload;typeof C=="string"&&x(C)}).then(N=>{y=N}).catch(()=>{}),b("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Ni))}).then(N=>{S=N}).catch(()=>{}),()=>{(async()=>{try{const C=y?.();C instanceof Promise&&await C}catch{}try{const C=S?.();C instanceof Promise&&await C}catch{}})()}},[x])},yC="openchamber:tray-action",od=5e3,wC=500,Mm=20,id=()=>{if(typeof window>"u")return!1;const t=window.__OPENCHAMBER_PLATFORM__;return t==="darwin"||t==="win32"||t==="linux"},ad=()=>typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.trayEnabled!==!1,SC=t=>{const e=typeof t.permission=="string"?t.permission:"Permission",n=Array.isArray(t.patterns)?t.patterns.find(r=>typeof r=="string"&&r.trim()):"";return n?`${e}: ${n}`:e},vC=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},Om=(t,e)=>Xd(t,e,zr.getState().ids,Ia.getState().rankById),jC=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},kC=(t,e,n,r,i)=>{if(!t)return"";const o=yd(n,r,t),l=e.project?.name,a=o?.label?.trim()||l?.trim()||jC(t),u=So(t);let d=u&&i.get(u)||"";if(!d){for(const[h,f]of Bn.getState().directories)if(So(h)===u){d=f.status?.current??"";break}}if(!d)for(const h of r.values()){const f=h.find(p=>So(p.path)===u);if(f?.branch){d=f.branch;break}}return d?`${a} · ${d}`:a},CC=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=ar.getState(),r=n==="remaining"?"remaining":"usage";if(!e.length)return{mode:r,groups:[]};const i=new Map(t.map(l=>[l.providerId,l])),o=[];for(const l of Cp){if(!e.includes(l.id))continue;const a=i.get(l.id);if(!a||a.configured!==!0)continue;const u=[];for(const[h,f]of Object.entries(a.usage?.windows??{})){const p=r==="remaining"?f.remainingPercent:f.usedPercent;u.push({label:Ap(h),value:Np(f.valueLabel,p)})}const d=!a.ok&&a.error?a.error:u.length===0?"No rate limits reported":null;o.push({provider:l.name,rows:u,status:d})}return{mode:r,groups:o}},NC=async()=>{try{if(Go())return"Local OpenChamber";const t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,e=An();if(e&&tl(e,t))return"Local OpenChamber";const r=(await hd()).hosts.find(i=>e?tl(e,yf(i)):!1);return r?.label?.trim()?pd(r.label.trim()):"Instance"}catch{return""}},AC=()=>{const t=new Map,e=new Map,n=[],r=new Map;let i;try{i=Mo()}catch{return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}}for(const[o,l]of i.children.entries()){const a=l.getState();a.vcs?.branch&&e.set(So(o)??o,a.vcs.branch);for(const u of a.session)u?.id&&r.set(u.id,u.title);for(const[u,d]of Object.entries(a.session_status??{})){const h=d?.type,f=h==="busy"?"busy":h==="retry"?"retry":"idle",p=t.get(u);(!p||p==="idle")&&t.set(u,f)}for(const[u,d]of Object.entries(a.permission??{}))for(const h of d??[]){if(!h?.id)continue;const f=h.sessionID||u;n.push({kind:"permission",id:h.id,sessionId:f,sessionTitle:"",label:SC(h),directory:o})}for(const[u,d]of Object.entries(a.question??{}))for(const h of d??[]){if(!h?.id)continue;const f=h.sessionID||u;n.push({kind:"question",id:h.id,sessionId:f,sessionTitle:"",label:vC(h),directory:o})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},DC=()=>{const t=Ps.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort(Om).slice(0,Mm).forEach(r=>{const i=$s(r);i&&e.add(i)});const n=new Map;for(const r of t){if(!r?.id)continue;const i=$s(r);if(!i||!e.has(i))continue;const o=n.get(i)??[];o.push(r.id),n.set(i,o)}return n},PC=t=>{const e=AC(),n=Oa.getState().index.session,r=Ps.getState().activeSessions,i=new Map(e.titleById),o=new Map;for(const x of r)if(x?.id&&(x.title&&i.set(x.id,x.title),x.parentID)){const m=o.get(x.parentID)??[];m.push(x.id),o.set(x.parentID,m)}const l=x=>{const m=[],b=[...o.get(x)??[]],y=new Set;for(;b.length;){const S=b.pop();y.has(S)||(y.add(S),m.push(S),b.push(...o.get(S)??[]))}return m},a=Ma.getState().statusById,u=x=>{const m=e.statusById.get(x);return m&&m!=="idle"?m:a.get(x)?.status.type??m??"idle"},d=x=>{const m=x.map(b=>u(b));return m.includes("busy")?"busy":m.includes("retry")?"retry":"idle"},h=Vt.getState().projects,f=et.getState().availableWorktreesByProject,p=r.filter(x=>x?.id&&!x.parentID).slice().sort(Om).slice(0,Mm).map(x=>{const m=[x.id,...l(x.id)],b=$s(x)??"";return{id:x.id,title:x.title||"Untitled session",status:d(m),branch:b?e.branchByDirectory.get(b)??"":"",unseen:m.reduce((y,S)=>y+(n.unseenCount[S]??0),0),hasError:m.some(y=>n.unseenHasError[y]??!1),directory:b,subtitle:kC(b,x,h,f,e.branchByDirectory)}}),g=e.approvals.map(x=>({...x,sessionTitle:i.get(x.sessionId)||""})),w=Pe.getState();let v=0;if(w.dockBadgeEnabled)for(const x of r){if(!x?.id||x.parentID)continue;let m=n.unseenCount[x.id]??0;m===0&&w.notifyOnSubtasks&&(m=l(x.id).reduce((b,y)=>b+(n.unseenCount[y]??0),0)),m>0&&(v+=1)}return{sessions:p,approvals:g,instanceName:t,usage:CC(),dockBadgeCount:v}},IC=()=>{c.useEffect(()=>{if(!id()||!ad()||!Qo())return;let t=!1,e="",n=null,r="";const i=()=>{if(t)return;const C=PC(r),j=JSON.stringify(C);j!==e&&(e=j,Mn("desktop_tray_update",C))};NC().then(C=>{t||(r=C,i())});const o=async()=>{const C=DC();await Promise.all([...C.entries()].map(async([j,A])=>{const D=await qs.getSessionStatusForDirectory(j).catch(()=>null);t||D===null||jp(j,D,A)}))},l=()=>{t||n!==null||(n=window.setTimeout(()=>{n=null,i()},wC))},a=new Map,u=()=>{if(t)return;let C;try{C=Mo()}catch{return}const j=new Set;for(const[A,D]of C.children.entries())j.add(A),a.has(A)||a.set(A,D.subscribe(()=>l()));for(const[A,D]of a)j.has(A)||(D(),a.delete(A))};let d=null;try{d=Mo().subscribeRegistry(()=>{u(),l()})}catch{}u();const h=Oa.subscribe(()=>l()),f=Ps.subscribe(()=>l()),p=Vt.subscribe(()=>l()),g=et.subscribe(()=>l()),w=Bn.subscribe(()=>l()),v=Pe.subscribe(()=>l()),x=Ma.subscribe(()=>l()),m=Ia.subscribe(()=>l()),b=zr.subscribe(()=>l());o();const y=window.setInterval(()=>{o()},od),S=ar.subscribe(()=>l());ar.getState().loadSettings().then(()=>{if(t)return;const{dropdownProviderIds:C,results:j}=ar.getState();C.length>0&&C.some(D=>!j.some(I=>I.providerId===D))&&ar.getState().fetchQuotas(C)});const N=window.setInterval(()=>{u(),i()},od);return i(),()=>{t=!0,n!==null&&window.clearTimeout(n),window.clearInterval(N),window.clearInterval(y),h(),f(),p(),g(),w(),v(),x(),m(),b(),S(),d?.();for(const C of a.values())C();a.clear()}},[]),c.useEffect(()=>{if(!id()||!ad()||typeof window>"u")return;const e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!="function")return;const n=i=>{i.type==="respond-permission"&&kp(i.sessionId,i.id,i.response).catch(()=>{Re.error("Failed to respond to permission request")})};let r=null;return e(yC,i=>{const o=i?.payload;!o||typeof o!="object"||typeof o.type!="string"||n(o)}).then(i=>{r=i}).catch(()=>{}),()=>{try{const i=r?.();i instanceof Promise&&i.catch(()=>{})}catch{}}},[])},TC=45e3,EC=(t,e,n=window.setInterval.bind(window),r=window.clearInterval.bind(window))=>{t();const i=n(e,TC);return()=>r(i)},RC=t=>{const e=nt.c(3);let n,r;e[0]!==t?(n=()=>{if(t)return EC(MC,OC)},r=[t],e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),c.useEffect(n,r)};function MC(){Dp(Oo())}function OC(){_a()}const BC="/api/notifications/stream",FC=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),_C=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="openchamber:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},LC=t=>{const e=nt.c(3),n=t?.enabled??!0;let r,i;e[0]!==n?(r=()=>{if(!n||xn()||!Sa()||typeof window>"u"||typeof EventSource>"u")return;const o=new EventSource(wa().sse(BC));return o.onmessage=$C,()=>{o.close()}},i=[n],e[0]=n,e[1]=r,e[2]=i):(r=e[1],i=e[2]),c.useEffect(r,i)};function $C(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Pe.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&FC())return;const r=_C(e);if(!r)return;qo()?.notifications?.notifyAgentCompletion(r)}const WC=6e4,zC=t=>{const e=nt.c(10),n=Pe(VC),r=Pp(UC),o=Ng(t)?.path??null;let l,a;e[0]!==n||e[1]!==r||e[2]!==o?(l=()=>{n&&r(o,{maxAgeMs:WC})},a=[n,r,o],e[0]=n,e[1]=r,e[2]=o,e[3]=l,e[4]=a):(l=e[3],a=e[4]),c.useEffect(l,a);let u,d;e[5]!==n||e[6]!==r||e[7]!==o?(u=()=>{if(n)return eo(h=>{h.type==="agent-memory-changed"&&r(o)})},d=[n,r,o],e[5]=n,e[6]=r,e[7]=o,e[8]=u,e[9]=d):(u=e[8],d=e[9]),c.useEffect(u,d)};function VC(t){return t.agentMemoryFeatureAvailable&&t.agentMemoryToolEnabled}function UC(t){return t.load}const ld="pwa-install-toast-shown",cd="pwa-install-toast-dismissed",KC=()=>{const t=nt.c(6),{browserTab:e}=Ag(),{t:n}=Nt(),r=c.useRef(n);let i,o;t[0]!==n?(i=()=>{r.current=n},o=[n],t[0]=n,t[1]=i,t[2]=o):(i=t[1],o=t[2]),c.useEffect(i,o);let l,a;t[3]!==e?(l=()=>{if(typeof window>"u"||!Sa()||!e)return;let u=null,d=null;const h=()=>{d!==null&&(Re.dismiss(d),d=null)},f=async()=>{if(!u)return;const w=u;u=null,h(),await w.prompt();const{outcome:v}=await w.userChoice;v==="accepted"&&Re.success(r.current("pwa.installPrompt.started"))},p=w=>{const v=w;if(typeof v.prompt!="function")return;v.preventDefault(),u=v;const x=Eo(),m=wf();Dg({dismissed:x.getItem(cd),sessionShown:m.getItem(ld),hasActiveToast:d!==null})&&(m.setItem(ld,"true"),d=Re.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{f()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{Eo().setItem(cd,"true"),h()}}}))},g=()=>{u=null,h(),Re.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",p),window.addEventListener("appinstalled",g),()=>{h(),window.removeEventListener("beforeinstallprompt",p),window.removeEventListener("appinstalled",g)}},a=[e],t[3]=e,t[4]=l,t[5]=a):(l=t[4],a=t[5]),c.useEffect(l,a)},HC=({open:t,onOpenChange:e})=>{const{t:n}=Nt(),r=!1,[i,o]=c.useState(null),[l,a]=c.useState(null),[u,d]=c.useState(!1),[h,f]=c.useState(!1),[p,g]=c.useState(null),[w,v]=c.useState(!1);c.useCallback(async()=>{},[p,u,r,n]),c.useEffect(()=>{if(!t)return;(async()=>{try{const b=await ds("/api/system/info");if(b.ok){const y=await b.json();if(typeof y.openchamberVersion=="string"&&y.openchamberVersion.trim()){o(y.openchamberVersion);return}}}catch{}o(await Ip())})()},[t]),c.useEffect(()=>{if(!t)return;let m=!1;return(async()=>{try{const y=await ds("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!y.ok)return;const S=await y.json().catch(()=>null),N=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!m&&N&&a(N)}catch{}})(),()=>{m=!0}},[t]),c.useEffect(()=>{{g(null),v(!1);return}},[t,r]);const x=i;return s.jsx(ws,{open:t,onOpenChange:e,children:s.jsx(Ss,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(Od,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[x&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:x})}),l&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:l})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/openchamber/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(R,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(R,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:"https://x.com/openchamber_dev",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(R,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},dd=t=>{if(!(typeof window>"u")){if(t){window.location.href="openchamber://focus/mcp-auth";return}window.location.replace("/")}},Ai=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},GC=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to OpenChamber and click Authorize again.":n},qC=()=>{const t=Tp(a=>a.completeAuth),[e,n]=c.useState("working"),[r,i]=c.useState(!1),[o,l]=c.useState("Completing MCP authorization...");return c.useEffect(()=>{if(typeof window>"u"){n("error"),l("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),u=Ai(a,"code"),d=Ep(a),h=Rp(a),f=Ai(a,"error"),p=Ai(a,"error_description");if(f){h&&ds(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`,{method:"DELETE"}).catch(()=>{}),n("error"),l(p??f);return}(async()=>{try{if(!u)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let g=d,w=!1;if(h){const v=await ds(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`);if(v.ok){const x=await v.json().catch(()=>null);w=x?.origin===Mp,i(w),!g&&x?.name?.trim()&&(g={name:x.name.trim(),directory:typeof x.directory=="string"&&x.directory.trim()?x.directory.trim():null})}}if(!g?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(g.name,u,g.directory),h&&await ds(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`,{method:"DELETE"}).catch(()=>{}),n("success"),w&&dd(!0),l("Authorization completed. You can close this tab and return to OpenChamber.")}catch(g){h&&await ds(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`,{method:"DELETE"}).catch(()=>{}),n("error"),l(GC(g,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("h1",{className:Op,children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"}),s.jsx("p",{className:Ie("typography-body",e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]"),children:o})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(bt,{type:"button",onClick:()=>dd(r),children:"Return to OpenChamber"})})]})})},ud=$n(()=>_n(()=>import("./OnboardingScreen-Dg66B6oB.js"),__vite__mapDeps([144,1,2,4,5,6,7,8,9,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82])).then(t=>({default:t.OnboardingScreen}))),QC=()=>{const t=nt.c(3),e=Pe(t5),n=Pe(s5);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(HC,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},YC=t=>{const e=nt.c(21),{onRetry:n,isRetrying:r}=t,{t:i}=Nt();let o;e[0]!==i?(o=i("startup.initRecovery.title"),e[0]=i,e[1]=o):o=e[1];let l;e[2]!==o?(l=s.jsx("h1",{className:"typography-title text-foreground",children:o}),e[2]=o,e[3]=l):l=e[3];let a;e[4]!==i?(a=i("startup.initRecovery.description"),e[4]=i,e[5]=a):a=e[5];let u;e[6]!==a?(u=s.jsx("p",{className:"typography-body text-muted-foreground",children:a}),e[6]=a,e[7]=u):u=e[7];let d;e[8]!==l||e[9]!==u?(d=s.jsxs("div",{className:"flex flex-col gap-2",children:[l,u]}),e[8]=l,e[9]=u,e[10]=d):d=e[10];let h;e[11]!==r||e[12]!==i?(h=i(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=i,e[13]=h):h=e[13];let f;e[14]!==r||e[15]!==n||e[16]!==h?(f=s.jsx(bt,{type:"button",onClick:n,disabled:r,children:h}),e[14]=r,e[15]=n,e[16]=h,e[17]=f):f=e[17];let p;return e[18]!==d||e[19]!==f?(p=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[d,f]})}),e[18]=d,e[19]=f,e[20]=p):p=e[20],p},md=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",XC=()=>{if(typeof window>"u"||!Jg())return null;const t=new URLSearchParams(window.location.search),e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),i=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:i,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true",allowPromptingSubagentSessions:t.has("allowPromptingSubagentSessions")?t.get("allowPromptingSubagentSessions")==="1":void 0}},JC=()=>typeof window>"u"?!1:window.location.pathname===$p,ZC=t=>{const e=nt.c(25),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=t,o=es(n5),l=et(r5),a=et(o5),u=Id(),d=c.useRef(null);let h;e[0]!==n.directory?(h=md(n.directory),e[0]=n.directory,e[1]=h):h=e[1];const f=h;let p;e[2]!==o?(p=md(o),e[2]=o,e[3]=p):p=e[3];const g=p;let w,v;if(e[4]!==g||e[5]!==l||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==f||e[9]!==r||e[10]!==a||e[11]!==u?(w=()=>{if(r||f&&g!==f)return;const N=`${f}
|
|
930
|
+
${n.sessionId}`;d.current===N&&l||(d.current=N,a(n.sessionId,n.directory),u.ensureSessionRenderable(n.sessionId,!0))},v=[g,l,n.directory,n.sessionId,f,r,a,u],e[4]=g,e[5]=l,e[6]=n.directory,e[7]=n.sessionId,e[8]=f,e[9]=r,e[10]=a,e[11]=u,e[12]=w,e[13]=v):(w=e[12],v=e[13]),c.useEffect(w,v),f&&g!==f)return null;let x;e[14]!==i?(x=s.jsx(tu,{embeddedBackgroundWorkEnabled:i}),e[14]=i,e[15]=x):x=e[15];let m;e[16]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(mu,{}),e[16]=m):m=e[16];let b;e[17]!==i||e[18]!==n.allowPromptingSubagentSessions||e[19]!==n.readOnly?(b=s.jsx(uu,{active:i,messagesEnabled:!0,readOnly:n.readOnly,initialAllowPromptingSubagentSessions:n.allowPromptingSubagentSessions}),e[17]=i,e[18]=n.allowPromptingSubagentSessions,e[19]=n.readOnly,e[20]=b):b=e[20];let y;e[21]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(su,{}),e[21]=y):y=e[21];let S;return e[22]!==x||e[23]!==b?(S=s.jsxs(s.Fragment,{children:[x,m,b,y]}),e[22]=x,e[23]=b,e[24]=S):S=e[24],S};function e5({apis:t}){c.useEffect(()=>{Sf("App:mounted"),vf()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=Ht(z=>z.initializeApp),n=Ht(z=>z.isInitialized),r=Ht(z=>z.isConnected),i=Ht(z=>z.providers.length),o=Ht(z=>z.agents.length),l=Ht(z=>z.loadProviders),a=Ht(z=>z.loadAgents),u=et(z=>z.error),d=et(z=>z.clearError),h=es(z=>z.currentDirectory),f=es(z=>z.setDirectory),p=es(z=>z.isSwitchingDirectory),[g,w]=c.useState(!1),v=Dn(z=>z.refreshStatus),x=Ei(z=>z.refreshStatus),[m,b]=c.useState(()=>t.runtime.isVSCode),[y,S]=c.useState(!1),[N,C]=c.useState(!1),[j,A]=c.useState(0),[D,I]=c.useState(0),[M,$]=c.useState(!1),E=Pe(z=>z.wideChatLayoutEnabled),K=Pe(z=>z.mobileKeyboardMode),B=c.useMemo(()=>xn(),[]),O=Ca(z=>z.setPlanModeEnabled),[T,k]=c.useState(()=>sl()),[P,F]=c.useState(()=>{const z=nl();return z!==null?rl({isDesktopShell:!0,bootOutcome:z}):null}),q=c.useRef(!1),Q=c.useMemo(()=>XC(),[]),Y=!Q||y,ce=c.useMemo(()=>JC(),[]);c.useEffect(()=>(ol(g),()=>{ol(!1)}),[g]),c.useEffect(()=>(ed(g),()=>{ed(!1)}),[g]),c.useEffect(()=>{jf(K)},[K]),c.useEffect(()=>{b(t.runtime.isVSCode)},[t.runtime.isVSCode]),c.useEffect(()=>Yo(z=>{Pg(z),I(ne=>ne+1),C(!1),A(ne=>ne+1)}),[]);const X=Sl(z=>{const ne=ps();return Object.values(z.runsByOriginalSessionID).filter(ue=>ue.status==="running"&&ue.runtimeKey===ne).map(ue=>`${ue.originalSessionID}:${ue.phase}:${ue.lastForwardedMessageID??""}:${ue.expectedAssistantParentID??""}`).sort().join("|")});c.useEffect(()=>{if(Q)return;const z=ps(),ne=Object.values(Sl.getState().runsByOriginalSessionID).filter(ue=>ue.status==="running"&&ue.runtimeKey===z);for(const ue of ne)Bp(ue.originalSessionID)},[X,Q,D]),c.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",E),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[E]),c.useEffect(()=>(il(t),()=>il(null)),[t]),c.useEffect(()=>{Q||(v(t.github,{force:!0}),x(t.linear,{force:!0}))},[t.github,t.linear,Q,r,v,x,D]),Fp();const oe=T==="valid",te=P?.screen==="main";c.useEffect(()=>{if(!kf({isDesktopShell:B,isInitialized:n,bootOutcomeKnown:oe,bootViewIsMain:te}))return;const z=setTimeout(()=>{const ne=document.getElementById("initial-loading");ne&&(ne.classList.add("fade-out"),setTimeout(()=>{ne.remove()},300))},150);return()=>clearTimeout(z)},[B,n,oe,te]),c.useEffect(()=>{if(!B||T!=="malformed")return;const z=document.getElementById("initial-loading");z&&(z.textContent="Desktop startup failed — please restart the app.")},[B,T]),c.useEffect(()=>{if(B)return;const z=setTimeout(()=>{const ne=document.getElementById("initial-loading");ne&&!n&&(ne.classList.add("fade-out"),setTimeout(()=>{ne.remove()},300))},5e3);return()=>clearTimeout(z)},[B,n]),c.useEffect(()=>{let z=!1;return(async()=>{const ue=await ds("/health",{method:"GET"}).catch(()=>null);if(!ue||!ue.ok||z)return;const me=await ue.json().catch(()=>null);if(!me||z)return;const ke=me.planModeExperimentalEnabled;O(ke===!0||ke===1||ke==="1"||ke==="true")})(),()=>{z=!0}},[O]),c.useEffect(()=>{m||e()},[e,m]),c.useEffect(()=>{if(m||n)return;let z=!0,ne,ue=0;const me=10,ke=1e3,Te=async()=>{if(!z)return;if(ue>=me){C(!0);return}const je=Ht.getState();if(je.isInitialized){C(!1);return}ue+=1,await je.initializeApp();const Ee=Ht.getState();if(!z)return;if(Ee.isInitialized){C(!1);return}if(ue>=me){C(!0);return}const xe=Math.min(ke*Math.pow(2,ue-1),16e3);ne=setTimeout(Te,xe)};return ne=setTimeout(Te,ke),()=>{z=!1,ne&&clearTimeout(ne)}},[j,n,m]),c.useEffect(()=>{n&&C(!1)},[n]),c.useEffect(()=>{if(!N)return;const z=document.getElementById("initial-loading");z&&(z.classList.add("fade-out"),setTimeout(()=>{z.remove()},300))},[N]),c.useEffect(()=>{if(m||!r||i>0&&o>0)return;let z=!0,ne=0;const ue=15,me=async()=>{const Te=Ht.getState();if(!(Te.providers.length>0&&Te.agents.length>0))try{Te.providers.length===0&&await l({source:"startupRecovery"}),Ht.getState().agents.length===0&&await a({source:"startupRecovery"})}catch{}};me();const ke=setInterval(()=>{if(z){if(++ne>=ue){clearInterval(ke);return}me()}},2e3);return()=>{z=!1,clearInterval(ke)}},[r,m,a,l,i,o]),c.useEffect(()=>{p||m||r&&qs.setDirectory(h)},[h,p,r,m]),c.useEffect(()=>{if(!Q||typeof window>"u")return;const z=me=>{S(me?.visible===!0)},ne=me=>{if(me.origin!==window.location.origin||me.source!==window.parent)return;const ke=me.data;ke?.type===Su&&z(ke.payload)},ue=window;return ue.__openchamberSetEmbeddedVisibility=z,window.addEventListener("message",ne),Xg(),()=>{window.removeEventListener("message",ne),ue.__openchamberSetEmbeddedVisibility===z&&delete ue.__openchamberSetEmbeddedVisibility}},[Q]),c.useEffect(()=>{!Q?.directory||m||h!==Q.directory&&f(Q.directory,{showOverlay:!1})},[h,Q,m,f]),c.useEffect(()=>{if(!Q||typeof window>"u")return;const z=ne=>{ne.storageArea===window.localStorage&&ne.key==="ui-store"&&Pe.persist.rehydrate()};return window.addEventListener("storage",z),()=>{window.removeEventListener("storage",z)}},[Q]),c.useEffect(()=>{if(typeof window>"u")return;const z=ne=>{const ue=ne.detail,me=typeof ue?.sessionId=="string"?ue.sessionId.trim():"";if(!me)return;const ke=typeof ue?.directory=="string"&&ue.directory.trim().length>0?ue.directory.trim():null;et.getState().setCurrentSession(me,ke)};return window.addEventListener("openchamber:open-session",z),()=>window.removeEventListener("openchamber:open-session",z)},[]),c.useEffect(()=>{if(typeof window>"u")return;const z=()=>{Mn("desktop_open_draft_mini_chat_window",{directory:"",projectId:null})};return window.addEventListener("openchamber:open-mini-chat",z),()=>window.removeEventListener("openchamber:open-mini-chat",z)},[]),c.useEffect(()=>{if(typeof window>"u")return;const z=()=>{const ne=et.getState().currentSessionId;ne&&Bd(ne)};return window.addEventListener("focus",z),()=>window.removeEventListener("focus",z)},[]),c.useEffect(()=>{if(typeof window>"u")return;const z=ne=>{const ue=ne.detail,me=typeof ue?.directory=="string"&&ue.directory.trim().length>0?ue.directory.trim():null,ke=typeof ue?.projectId=="string"&&ue.projectId.trim().length>0?ue.projectId.trim():null,Te=!!(me||ke);Pe.getState().setSessionSwitcherOpen(!1),et.getState().openNewSessionDraft({target:Te?"project":"chat",selectedProjectId:Te?ke:null,directoryOverride:Te?me:null,preserveDirectoryOverride:!!me})};return window.addEventListener("openchamber:open-draft-session",z),()=>window.removeEventListener("openchamber:open-draft-session",z)},[]),c.useEffect(()=>{typeof window>"u"||!n||p||q.current||(q.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,p]),_p({enabled:Y}),LC({enabled:Y}),zC(h||null),KC(),Lp(),Zp(),Ig();const he=c.useCallback(()=>{w(z=>!z)},[]);bC(he),IC(),RC(!Q),c.useEffect(()=>{if(Q)return;const z=()=>w(ne=>!ne);return window.addEventListener("openchamber:memory-debug-toggle",z),()=>window.removeEventListener("openchamber:memory-debug-toggle",z)},[Q]),c.useEffect(()=>{Q||u&&setTimeout(()=>d(),5e3)},[d,Q,u]),c.useEffect(()=>{if(!B||T!=="not-injected")return;let z=!1,ne=0;const ue=200,me=2e3,ke=50,Te=()=>{if(z)return;ne++;const je=sl();if(je!=="not-injected"){if(z=!0,k(je),je==="valid"){const xe=nl();xe&&F(rl({isDesktopShell:!0,bootOutcome:xe}))}return}const Ee=Math.min(ue*Math.pow(1.1,ne),me);if(ne>=ke){const xe=document.getElementById("initial-loading");xe&&!xe.textContent?.includes("taking longer")&&(xe.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(Te,Ee)};return window.setTimeout(Te,ue),()=>{z=!0}},[B,T]);const _=c.useCallback(async()=>{if(Cf({isDesktopShell:xn(),isDesktopLocalOriginActive:Go()})){await Nf();return}window.location.reload()},[]),ie=c.useCallback(async()=>{if(!M){C(!1),$(!0);try{await Ht.getState().initializeApp()}finally{$(!1)}Ht.getState().isInitialized||A(z=>z+1)}},[M]),ge=z=>{if(z.screen==="recovery")return z.variant};if(B&&P&&P.screen!=="main"){if(P.screen==="chooser")return s.jsx(Hs,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(c.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(ud,{mode:"first-launch",localAvailable:P.localAvailable!==!1,onCliAvailable:_,onChooseRemote:()=>{}})})})});const z=ge(P),ne=P.screen==="recovery"&&"url"in P?P.url:void 0;return s.jsx(Hs,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(c.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(ud,{mode:"recovery",recoveryVariant:z,recoveryHostUrl:ne,recoveryHostLabel:void 0,localAvailable:P.localAvailable!==!1,onCliAvailable:_})})})})}if(Q)return s.jsx(Hs,{children:s.jsx(vl,{sdk:qs.getSdkClient(),directory:h||"",children:s.jsx(jl,{apis:t,children:s.jsx(_i,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(ZC,{embeddedSessionChat:Q,isVSCodeRuntime:m,embeddedBackgroundWorkEnabled:Y}),s.jsx(kl,{})]})})})},D)});if(ce)return s.jsx(Hs,{children:s.jsx(qC,{})});if(N&&!n&&!m&&!Q)return s.jsx(Hs,{children:s.jsx(YC,{onRetry:()=>{ie()},isRetrying:M})});const ae=!n&&!B;return s.jsx(Hs,{children:s.jsx(vl,{sdk:qs.getSdkClient(),directory:h||"",children:s.jsx(jl,{apis:t,children:s.jsx($3,{children:s.jsx(_i,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:B?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(tu,{embeddedBackgroundWorkEnabled:Y}),s.jsx(mu,{}),s.jsx(b3,{}),s.jsx(su,{}),s.jsx(kl,{}),!ae&&s.jsxs(s.Fragment,{children:[s.jsx(Tg,{}),s.jsx(QC,{}),g&&s.jsx(J3,{onClose:()=>w(!1)})]})]})})})})},D)})}function t5(t){return t.isAboutDialogOpen}function s5(t){return t.setAboutDialogOpen}function n5(t){return t.currentDirectory}function r5(t){return t.currentSessionId}function o5(t){return t.setCurrentSession}const i5=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();Wp();Af().then(()=>{Promise.all([Df(),zp()]).catch(t=>{console.error("[main] settings init failed:",t)}),Vp(),Up(),Kp()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Bm=document.getElementById("root");if(!Bm)throw new Error("Root element not found");Hp();qm.createRoot(Bm).render(s.jsx(xt.StrictMode,{children:s.jsx(Gp,{children:s.jsx(qp,{children:s.jsx(Qp,{children:s.jsx(Yp,{children:s.jsx(e5,{apis:i5})})})})})}));const C5=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{Rb as W,vb as a,k5 as b,qb as d,Uu as g,j5 as h,C5 as m,Eb as u,Vu as v};
|