@openchamber/web 1.23.1 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-DL0imnlI.js → CodeMirrorCommentWidgets-C9kV-n7r.js} +1 -1
- package/dist/assets/DiffView-B7YkbY-u.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +1 -0
- package/dist/assets/FilesView-vjJx7VaM.js +13 -0
- package/dist/assets/GitView-BLhlMYEY.js +6 -0
- package/dist/assets/GuestAttachDialog-B-fwE8r3.js +3 -0
- package/dist/assets/{JsonTreeView-BPBDPY9B.js → JsonTreeView-D_4G5X6-.js} +1 -1
- package/dist/assets/LinearIssuesView-1uKhePfH.js +1 -0
- package/dist/assets/{MarkdownImageGallery-BNjimjiI.js → MarkdownImageGallery-Ix7N_2wp.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-Deel_y5S.js +12 -0
- package/dist/assets/{OnboardingScreen-CWXxIIAH.js → OnboardingScreen-ToIakxb_.js} +1 -1
- package/dist/assets/{PatchDiff-B6J3p3br.js → PatchDiff-BjMgezr1.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BjTRJJ1D.js → PierreDiffViewer-53Ghfnlr.js} +5 -5
- package/dist/assets/PlanView-BGAzxDwD.js +5 -0
- package/dist/assets/SettingsView-n2X-jfBB.js +29 -0
- package/dist/assets/SettingsWindow-Bi8LE9XI.js +1 -0
- package/dist/assets/SubmoduleDiffSummary--YFqK6Ih.js +1 -0
- package/dist/assets/ToolOutputDialog-DRWBvdaJ.js +15 -0
- package/dist/assets/{ToolPartDiffPreview-DRifZ2YH.js → ToolPartDiffPreview-BxZJCU28.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BOeQtAWV.js → VirtualizedFileDiff-DCXjBGRf.js} +3 -3
- package/dist/assets/{WalkthroughView-BD4p0vhD.js → WalkthroughView-CfIPvWWa.js} +2 -2
- package/dist/assets/appThemeRegistry-DDROzcUO.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-FZI1j1rE.js → computeVirtualFileMetrics-DHgQIkUq.js} +1 -1
- package/dist/assets/de-CX_f-T5U.js +10 -0
- package/dist/assets/es-BERmWNn_.js +16 -0
- package/dist/assets/fr-BjYYE_-z.js +14 -0
- package/dist/assets/index-DpzTz2UH.css +1 -0
- package/dist/assets/index-Dy8xgawx.js +40 -0
- package/dist/assets/{index-DddhnFNK.js → index-WjufPkIV.js} +1 -1
- package/dist/assets/{isDiffPlainText-D4ld2G-2.js → isDiffPlainText-D9faP70y.js} +1 -1
- package/dist/assets/{isFilePlainText-BW1Xfw0F.js → isFilePlainText-6qOcz5Ky.js} +1 -1
- package/dist/assets/ja-DxqeAk9N.js +16 -0
- package/dist/assets/ko-Dty1aUod.js +16 -0
- package/dist/assets/main-BOYSXfYn.js +896 -0
- package/dist/assets/{main-BBqRX3Po.js → main-Bjcre_GE.js} +2 -2
- package/dist/assets/{markdown-shiki.worker-D5fBU-lw.js → markdown-shiki.worker-CahLvHIq.js} +5 -5
- package/dist/assets/markdownCore-DPrwM1rU.js +5 -0
- package/dist/assets/{miniChat-CygpKLC_.js → miniChat-Dz_bPgMc.js} +2 -2
- package/dist/assets/{mobile-CSmUm4vb.js → mobile-BbZPBJrK.js} +2 -2
- package/dist/assets/{patchFileDiff-u4JuidC_.js → patchFileDiff-BvU6KOQC.js} +3 -3
- package/dist/assets/pl-CX-_ROkr.js +16 -0
- package/dist/assets/pt-BR-DhRR1arx.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +2 -0
- package/dist/assets/renderMobileApp-BK1kFlcJ.js +25 -0
- package/dist/assets/runtimeEndpointReset-BULHvOwb.js +25 -0
- package/dist/assets/{scheduledTasksApi-Og3jfb4K.js → scheduledTasksApi-DW3xqMQ8.js} +1 -1
- package/dist/assets/shikiHighlight-DsxD9QEa.js +1 -0
- package/dist/assets/textMateThemeFromAppTheme-Da7ed8qM.js +1 -0
- package/dist/assets/tr-cIQtYBpg.js +7 -0
- package/dist/assets/uk-CD21CXFV.js +16 -0
- package/dist/assets/useAppFontEffects-hfv2s6mZ.js +7333 -0
- package/dist/assets/useInlineCommentController-BmtfVbo8.js +2 -0
- package/dist/assets/useRootScrollLock-Cwc4kSl2.js +1 -0
- package/dist/assets/{vendor-base-ui-BY_5qla_.js → vendor-base-ui-CsXYnR5c.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-D5hG1bL9.js → vendor-codemirror-language-data-BPMJpOpT.js} +2 -2
- package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +1 -0
- package/dist/assets/{vendor-motion-dom-D_o3BTI3.js → vendor-motion-dom-DcCgeG69.js} +1 -1
- package/dist/assets/{vendor-remixicon-react-Dil0zKKT.js → vendor-remixicon-react-BDmGmFCA.js} +1 -1
- package/dist/assets/vendor-strip-json-comments-5dJlOkP1.js +4 -0
- package/dist/assets/{vendor-zod-B6551dwG.js → vendor-zod-fZppILAM.js} +4 -4
- package/dist/assets/{web-components-DCyJti1c.js → web-components-U-hWbgJo.js} +2 -2
- package/dist/assets/zh-CN-BWvlPHY-.js +16 -0
- package/dist/assets/zh-TW-CRp5dJU2.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +8 -6
- package/server/built-in-extensions/registry.json +4 -0
- package/server/index.d.ts +2 -0
- package/server/index.js +15 -3
- package/server/lib/fs/DOCUMENTATION.md +8 -0
- package/server/lib/fs/git-process.test.js +77 -0
- package/server/lib/fs/routes.js +2 -1
- package/server/lib/fs/search.js +2 -1
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/routes.js +16 -3
- package/server/lib/git/service.js +112 -8
- package/server/lib/git/service.test.js +127 -0
- package/server/lib/guests/DOCUMENTATION.md +66 -0
- package/server/lib/guests/auth-store.js +184 -0
- package/server/lib/guests/auth-store.test.js +112 -0
- package/server/lib/guests/builtins.js +34 -0
- package/server/lib/guests/builtins.test.js +174 -0
- package/server/lib/guests/catalog.js +466 -0
- package/server/lib/guests/catalog.test.js +390 -0
- package/server/lib/guests/clone.js +297 -0
- package/server/lib/guests/extract-zip.js +136 -0
- package/server/lib/guests/extract-zip.test.js +109 -0
- package/server/lib/guests/files.js +308 -0
- package/server/lib/guests/files.test.js +262 -0
- package/server/lib/guests/grant-scope.js +81 -0
- package/server/lib/guests/grant-scope.test.js +75 -0
- package/server/lib/guests/host-session.js +73 -0
- package/server/lib/guests/host-session.test.js +30 -0
- package/server/lib/guests/html-styles.js +6 -0
- package/server/lib/guests/html-styles.test.js +45 -0
- package/server/lib/guests/html-tokens.js +73 -0
- package/server/lib/guests/html-tokens.test.js +53 -0
- package/server/lib/guests/install.js +406 -0
- package/server/lib/guests/install.test.js +338 -0
- package/server/lib/guests/oauth.js +501 -0
- package/server/lib/guests/oauth.test.js +481 -0
- package/server/lib/guests/persist.js +336 -0
- package/server/lib/guests/persist.test.js +288 -0
- package/server/lib/guests/request.js +112 -0
- package/server/lib/guests/request.test.js +206 -0
- package/server/lib/guests/routes.js +838 -0
- package/server/lib/guests/service.js +538 -0
- package/server/lib/guests/service.test.js +277 -0
- package/server/lib/guests/sockets.js +129 -0
- package/server/lib/guests/sockets.test.js +110 -0
- package/server/lib/guests/ssh-install.test.js +188 -0
- package/server/lib/guests/storage.js +68 -0
- package/server/lib/guests/storage.test.js +59 -0
- package/server/lib/guests/updates.js +294 -0
- package/server/lib/guests/updates.test.js +334 -0
- package/server/lib/guests/upload.js +50 -0
- package/server/lib/guests/upload.test.js +131 -0
- package/server/lib/linear/DOCUMENTATION.md +1 -1
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -0
- package/server/lib/openchamber-sessions/routes.js +44 -11
- package/server/lib/openchamber-sessions/routes.test.js +47 -0
- package/server/lib/opencode/DOCUMENTATION.md +54 -0
- package/server/lib/opencode/core-routes.js +39 -1
- package/server/lib/opencode/feature-routes-runtime.js +10 -0
- package/server/lib/opencode/lifecycle-process.test.js +84 -0
- package/server/lib/opencode/lifecycle.js +54 -67
- package/server/lib/opencode/openchamber-routes.js +72 -14
- package/server/lib/opencode/openchamber-routes.test.js +71 -3
- package/server/lib/opencode/settings-helpers.js +5 -0
- package/server/lib/opencode/settings-helpers.test.js +13 -1
- package/server/lib/opencode/settings-normalization-runtime.js +2 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +13 -0
- package/server/lib/opencode/settings-registry.json +7 -0
- package/server/lib/opencode/shutdown-runtime.js +3 -0
- package/server/lib/opencode/shutdown-runtime.test.js +24 -0
- package/server/lib/opencode/theme-archive.js +53 -0
- package/server/lib/opencode/theme-catalog.js +171 -0
- package/server/lib/opencode/theme-catalog.test.js +125 -0
- package/server/lib/opencode/theme-import.test.js +144 -0
- package/server/lib/opencode/theme-runtime.js +100 -28
- package/server/lib/opencode/theme-runtime.test.js +15 -0
- package/server/lib/quota/DOCUMENTATION.md +0 -1
- package/server/lib/quota/providers/index.js +0 -7
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +17 -2
- package/server/lib/terminal/runtime.test.js +45 -0
- package/server/lib/ui-auth/ui-auth.js +43 -8
- package/server/lib/ui-auth/ui-auth.test.js +40 -0
- package/dist/assets/DiffView-q6z6MFdZ.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-to6K1rXL.js +0 -1
- package/dist/assets/FilesView-uwvKGOeu.js +0 -13
- package/dist/assets/GitView-CAqrkFYg.js +0 -6
- package/dist/assets/LinearIssuesView-Dq4Nz_DL.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BIYG3j5A.js +0 -12
- package/dist/assets/PlanView-Cs7Aa22g.js +0 -5
- package/dist/assets/SettingsView-DROvkdyX.js +0 -28
- package/dist/assets/SettingsWindow-AtPQGcRJ.js +0 -1
- package/dist/assets/ToolOutputDialog-DmAZDzlT.js +0 -15
- package/dist/assets/appThemeRegistry-BK0dHKa6.js +0 -1
- package/dist/assets/de-Byg3syd1.js +0 -10
- package/dist/assets/es-B-FGkjnQ.js +0 -16
- package/dist/assets/fr-Dvzik_Jj.js +0 -14
- package/dist/assets/index-zhgg-SDz.css +0 -1
- package/dist/assets/index-zzfsbdBe.js +0 -40
- package/dist/assets/ja-CFnftYdc.js +0 -16
- package/dist/assets/ko-CgZ13aWV.js +0 -16
- package/dist/assets/main-BX3ip8Oc.js +0 -930
- package/dist/assets/markdownCore-TRGNObm0.js +0 -5
- package/dist/assets/pl-BDk6AWIE.js +0 -16
- package/dist/assets/pt-BR-DV5hPNsk.js +0 -16
- package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-Bfh77YcY.js +0 -2
- package/dist/assets/renderMobileApp-DsYwHQBL.js +0 -25
- package/dist/assets/runtimeEndpointReset-MtnTGkZz.js +0 -41
- package/dist/assets/shikiHighlight-CVE7qsu3.js +0 -1
- package/dist/assets/tr-BwS5J324.js +0 -7
- package/dist/assets/uk-Dp60Q7VN.js +0 -16
- package/dist/assets/useAppFontEffects-DQXEYu1N.js +0 -7282
- package/dist/assets/useGitComparison-DjFXbxbu.js +0 -1
- package/dist/assets/useInlineCommentController-B4Vhtx-T.js +0 -2
- package/dist/assets/useRootScrollLock-B32nj08w.js +0 -1
- package/dist/assets/vendor-framer-motion-livSKyyV.js +0 -1
- package/dist/assets/zh-CN-D1MXOnJ7.js +0 -16
- package/dist/assets/zh-TW-MqRc5ECP.js +0 -16
- package/server/lib/quota/providers/crof.js +0 -96
- package/server/lib/quota/providers/crof.test.js +0 -98
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/WalkthroughView-CfIPvWWa.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/useAppFontEffects-hfv2s6mZ.js","assets/index-Dy8xgawx.js","assets/vendor-zod-fZppILAM.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-zustand-BAGL70zf.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/index-DpzTz2UH.css","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-CsXYnR5c.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/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-Bq3iTZ6r.js","assets/vendor-motion-dom-DcCgeG69.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/contextPanelEmbeddedChat-CirXEPJq.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-BPMJpOpT.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-BuBPBC3R.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/patchFileDiff-BvU6KOQC.js","assets/runtimeEndpointReset-BULHvOwb.js","assets/GuestAttachDialog-B-fwE8r3.js","assets/VirtualizedFileDiff-DCXjBGRf.js","assets/web-components-U-hWbgJo.js","assets/computeVirtualFileMetrics-DHgQIkUq.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/isDiffPlainText-D9faP70y.js","assets/vendor-diff-C3JhlQdm.js","assets/PierreDiffViewer-53Ghfnlr.js","assets/Virtualizer-D_a8gKmg.js","assets/useInlineCommentController-BmtfVbo8.js","assets/appThemeRegistry-DDROzcUO.js","assets/textMateThemeFromAppTheme-Da7ed8qM.js","assets/useRootScrollLock-Cwc4kSl2.js","assets/scheduledTasksApi-DW3xqMQ8.js","assets/vendor-cron-parser-CUcP7OfX.js","assets/vendor-luxon-BZ0puJYg.js","assets/DiffView-B7YkbY-u.js","assets/SubmoduleDiffSummary--YFqK6Ih.js","assets/FilesView-vjJx7VaM.js","assets/shikiHighlight-DsxD9QEa.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-D_4G5X6-.js","assets/Virtualizer-CZlLSacm.js","assets/isFilePlainText-6qOcz5Ky.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/CodeMirrorCommentWidgets-C9kV-n7r.js","assets/GitView-BLhlMYEY.js","assets/DirtyBranchSwitchDialog-CU0A93Zx.js","assets/LinearIssuesView-1uKhePfH.js","assets/PlanView-BGAzxDwD.js","assets/SettingsWindow-Bi8LE9XI.js","assets/SettingsView-n2X-jfBB.js","assets/vendor-yaml-3778uTud.js","assets/vendor-qrcode-DTJ12-WC.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/vendor-strip-json-comments-5dJlOkP1.js","assets/OnboardingScreen-ToIakxb_.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{f as nt,R as c,j as s,r as mt,c as df,h as uf}from"./vendor-react-BUCujlKS.js";import{E as yn,F as Ho,H as mf,I as ff,h as bs,x as wd,u as Ne,J as Ot,K as Ja,o as ft,L as sn,N as Ur,O as $n,P as Sd,Q as hf,R as pf,S as gf,T as xf,U as vd,A as Go,n as is,V as Fn,W as Kr,e as Pn,X as bf,a as ls,Y as yf,Z as wf,_ as Sf,$ as jd,v as pn,B as nn,a0 as vf,a1 as jf,a2 as Za,a3 as kf,a4 as ya,a5 as Cf,a6 as kd,f as Nf,a7 as Xn,a8 as ki,a9 as Af,aa as Ci,ab as lr,ac as Pf,ad as wa,d as Io,t as Or,q as gs,ae as Cd,af as Df,ag as If,ah as Ni,ai as Tf,aj as Ef,i as Rf,ak as bo,al as yo,am as Mf,an as el,ao as Of,ap as Bf,aq as Ff,ar as _f,as as tl,at as sl,au as nl,av as rl,aw as Lf,z as ol,ax as $f,ay as Wf,az as zf,C as Vf,D as Uf}from"./index-Dy8xgawx.js";import{_ as hn}from"./vendor-vite-runtime-DD1OZmLC.js";import{v as il,w as oi,x as un,y as Ai,z as al,E as Kf,F as Hf,G as Gf,H as qf,I as Qf,J as Yf,K as Xf,L as Jf,M as Sa,b as Zf,c as Nd,U as Ad,h as Pi,j as Pd,Q as eh,i as th,f as sh,R as Dd,V as Di,W as Gn,X as Id,Y as Td,P as nh,T as rh,Z as oh,_ as ih,$ as ah,a as Ed,a0 as lh,S as ll,r as ch,a1 as dh,a2 as Rd,a3 as uh,a4 as mh,u as $r,s as fh,N as hh,D as ph,a5 as gh,a6 as cl,a7 as xh,o as bh,m as yh,q as Md,t as wh,a8 as Sh,a9 as vh,aa as jh,l as kh,n as Ch,O as Od,A as Nh,C as Ah}from"./runtimeEndpointReset-BULHvOwb.js";import{f as vt,h as Ie,bd as Ut,I as B,g as xn,t as Fe,aq as qs,be as zs,as as Qs,ap as Ys,S as nr,Z as jn,af as rr,bf as Wn,o as qo,bg as dl,bh as Ph,bi as Dh,aa as Ct,ab as Nt,ac as At,b as qt,z as tt,H as Ih,bj as Bd,bk as ro,u as Gs,C as va,r as Fs,D as Fd,bl as Ii,bm as Th,bn as _d,bo as Ld,bp as Eh,bq as Rh,br as ul,bs as ml,bt as Qo,bu as $d,bv as Wd,bw as Mh,bx as fl,by as Oh,bz as Bh,bA as ja,bB as Ti,bC as Fh,bD as _h,Q as zd,bE as Lh,l as Yt,bF as $h,n as dr,bG as Vd,bH as Wh,p as zh,bI as Ud,bJ as Vh,bK as Uh,bL as Kh,bM as Kd,bN as Hd,bO as hl,bP as Gd,bQ as qd,bR as Qd,bS as Yd,bT as Xd,bU as Jd,bV as Jr,bW as Zd,aF as ka,bX as Jn,bY as Zr,bZ as Hh,b_ as Ds,b$ as Is,c0 as Xs,c1 as _s,c2 as Ls,c3 as wn,B as dt,c4 as Sn,ay as Bs,c5 as Gh,c6 as qh,aD as Dn,c7 as Br,c8 as tn,c9 as Yo,ca as eu,cb as Ei,cc as Ri,cd as Mi,ce as Qh,cf as Vs,cg as Us,ch as Ms,ci as Ks,cj as as,W as An,ck as ur,cl as pl,cm as hr,cn as tu,R as Xo,ag as Yh,ah as Ca,ai as su,J as nu,K as In,co as Jo,a5 as Na,cp as Xh,cq as Jh,aw as Zh,cr as ep,cs as ru,ct as tp,cu as sp,ax as Aa,cv as np,cw as ou,cx as pr,cy as iu,cz as rp,s as op,cA as ip,cB as eo,cC as ap,aL as to,cD as lp,cE as cr,O as au,cF as cp,cG as dp,cH as zn,cI as up,cJ as mp,aA as fp,cK as ii,cL as lu,cM as Pa,cN as hp,cO as cu,cP as pp,aE as Oi,cQ as Bi,cR as gl,cS as gp,cT as xl,cU as bl,cV as xp,cW as Fr,c as Hr,d as Da,a1 as bp,cX as du,cY as Nr,cZ as _r,c_ as yp,c$ as wp,d0 as Sp,_ as uu,az as vp,d1 as jp,d2 as kp,d3 as Cp,d4 as Np,d5 as mu,d6 as bn,d7 as Ap,d8 as fu,d9 as Pp,da as Fi,db as Dp,dc as hu,dd as Ip,de as Tp,df as Ep,dg as pu,dh as Rp,di as gu,a3 as To,dj as _i,U as Ia,T as Ta,V as Ea,dk as Ra,a as Ma,a2 as Mp,dl as yl,dm as Li,dn as xu,dp as Op,ar as bu,dq as Bp,P as $i,L as Fp,dr as wl,ds as _p,dt as Sl,du as Lp,dv as $p,dw as Wp,dx as xs,dy as zp,dz as Ln,dA as Oa,dB as yu,dC as Vp,dD as wu,dE as Su,dF as Up,E as Kp,dG as Hp,dH as Gp,dI as qp,dJ as vl,dK as Qp,dL as Yp,dM as vu,F as Xp,dN as Jp,dO as Zp,dP as wo,dQ as ju,dR as eg,dS as tg,dT as sg,dU as ng,e as ku,dV as Ba,dW as rg,dX as Gr,dY as og,dZ as jl,d_ as ig,d$ as ag,a0 as lg,e0 as cg,aX as kl,a7 as Cl,a6 as Nl,e1 as dg,aS as Wi,e2 as ug,M as mg,N as ai,e3 as fg,e4 as hg,e5 as Cu,e6 as Nu,e7 as Au,e8 as pg,G as Fa,e9 as gg,a4 as xg,ea as bg,eb as yg,ec as wg,ed as Sg,ee as vg,ef as jg,eg as kg,eh as Cg,ei as Eo,aj as Ng,ej as Ag,ek as Al,el as Pg,em as Dg,en as Ig,eo as Tg,ep as Ro,eq as Eg,er as Pl,es as Rg,et as Mg,eu as Og,ev as Bg,ew as Fg,ex as _g,ey as So,ez as Lg,i as $g,eA as Wg,eB as zg,eC as Vg,eD as Ug,a8 as Kg,eE as Hg,eF as Gg,eG as qg,eH as Qg,eI as Dl,eJ as Yg,aM as Xg,aN as Jg,aO as Zg,aQ as Il,aR as Tl,aU as El,aV as Rl,aT as Pu,aW as Du,eK as ex,b8 as tx,b9 as sx,ba as nx,bb as rx,bc as ox,b2 as ix,b4 as ax,b5 as lx,b6 as cx,b7 as dx}from"./useAppFontEffects-hfv2s6mZ.js";import{u as Iu,S as Ml,C as ux,t as mx,W as Tu,f as fx,a as hx}from"./useRootScrollLock-Cwc4kSl2.js";import{u as Un,O as Ol,D as px,a as gx,b as xx,n as bx,f as yx,c as Bl,s as wx,d as Sx,e as vx,r as jx}from"./scheduledTasksApi-DW3xqMQ8.js";import{f as qr,h as _n,T as Eu,M as Ru,D as Qr,j as Yr,d as kx,P as zi,b as Cx,k as Vi,i as Nx}from"./vendor-dnd-kit-core-BZknOX2w.js";import{u as Zo,S as Mo,h as Ax,a as Mu,v as Ui,s as Px}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as ei}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{S as Ou,M as Bu,C as Fu,a as Ki,b as Hi,c as Gi,d as _u,e as Dx,f as Ix}from"./vendor-base-ui-CsXYnR5c.js";import{c as or,u as sr,d as Lu,p as Tx}from"./vendor-zustand-BAGL70zf.js";import{g as Ex,a as Rx,E as $u,b as Mx,c as Ox,d as Bx,e as Fx,i as _x}from"./contextPanelEmbeddedChat-CirXEPJq.js";import{P as Lx}from"./GuestAttachDialog-B-fwE8r3.js";import{c as _a,s as Sr,r as Wu}from"./vendor-zod-fZppILAM.js";import{u as $x}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{d as zu}from"./vendor-cron-parser-CUcP7OfX.js";const Wx="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",zx="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",li=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__==="darwin"?Wx:t.id==="terminal"?zx:void 0}),Fl=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},Vx=t=>{const e=nt.c(75),{directory:n,className:r}=t,{t:i}=vt(),o=Un(Ux),l=Un(Kx),a=Un(Hx),u=Un(Gx),d=Un(qx),h=Un(Qx),f=Un(Yx);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=yn()&&Ho();let v;e:{let ue;e[3]!==l||e[4]!==o?(ue=l.find(be=>be.id===o)??l.find(Xx)??l[0]??Ol[0],e[3]=l,e[4]=o,e[5]=ue):ue=e[5];const ye=ue;if(ye){let be;e[6]!==ye?(be=li(ye),e[6]=ye,e[7]=be):be=e[7],v=be;break e}let ve;e[8]===Symbol.for("react.memo_cache_sentinel")?(ve=li(Ol[0]),e[8]=ve):ve=e[8],v=ve}const y=v;if(!w||!n||l.length===0)return null;let m;e[9]!==n?(m=async ue=>{await mf(n,ue.id,ue.appName)||await ff(n,ue.appName)},e[9]=n,e[10]=m):m=e[10];const x=m;let b;e[11]!==x||e[12]!==f?(b=async ue=>{await f(ue.id),await x(ue)},e[11]=x,e[12]=f,e[13]=b):b=e[13];const S=b;let C;e[14]!==n||e[15]!==i?(C=async()=>{(await xn(n)).ok&&Fe.success(i("openInApp.toast.pathCopied"))},e[14]=n,e[15]=i,e[16]=C):C=e[16];const N=C;let k;e[17]!==r?(k=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]=k):k=e[18];let R;e[19]!==x||e[20]!==y?(R=()=>{x(y)},e[19]=x,e[20]=y,e[21]=R):R=e[21];const I=u&&"animate-pulse";let P;e[22]!==I?(P=Ie("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",I),e[22]=I,e[23]=P):P=e[23];let T;e[24]!==y.label||e[25]!==i?(T=i("openInApp.actions.openInAria",{app:y.label}),e[24]=y.label,e[25]=i,e[26]=T):T=e[26];let E;e[27]!==y.fallbackIconDataUrl||e[28]!==y.iconDataUrl||e[29]!==y.label?(E=s.jsx(Fl,{label:y.label,iconDataUrl:y.iconDataUrl,fallbackIconDataUrl:y.fallbackIconDataUrl}),e[27]=y.fallbackIconDataUrl,e[28]=y.iconDataUrl,e[29]=y.label,e[30]=E):E=e[30];let O;e[31]!==P||e[32]!==T||e[33]!==E||e[34]!==R?(O=s.jsx("button",{type:"button",onClick:R,className:P,"aria-label":T,children:E}),e[31]=P,e[32]=T,e[33]=E,e[34]=R,e[35]=O):O=e[35];let W;e[36]===Symbol.for("react.memo_cache_sentinel")?(W=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]=W):W=e[36];let L;e[37]!==i?(L=i("openInApp.actions.chooseAppAria"),e[37]=i,e[38]=L):L=e[38];let F;e[39]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=F):F=e[39];let D;e[40]!==L?(D=s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:W,"aria-label":L,children:F})}),e[40]=L,e[41]=D):D=e[41];let j;e[42]!==N?(j=()=>{N()},e[42]=N,e[43]=j):j=e[43];let A;e[44]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(B,{name:"file-copy",className:"h-4 w-4"}),e[44]=A):A=e[44];let M;e[45]!==i?(M=i("openInApp.actions.copyPath"),e[45]=i,e[46]=M):M=e[46];let G;e[47]!==M?(G=s.jsx("span",{className:"typography-ui-label text-foreground",children:M}),e[47]=M,e[48]=G):G=e[48];let q;e[49]!==j||e[50]!==G?(q=s.jsxs(Ut,{className:"flex items-center gap-2",onClick:j,children:[A,G]}),e[49]=j,e[50]=G,e[51]=q):q=e[51];let Z;e[52]===Symbol.for("react.memo_cache_sentinel")?(Z=s.jsx(zs,{}),e[52]=Z):Z=e[52];let le;if(e[53]!==l||e[54]!==S||e[55]!==y.id){let ue;e[57]!==S||e[58]!==y.id?(ue=ye=>{const ve=li(ye);return s.jsxs(Ut,{className:"flex items-center gap-2",onClick:()=>{S(ye)},children:[s.jsx(Fl,{label:ye.label,iconDataUrl:ye.iconDataUrl,fallbackIconDataUrl:ve.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ye.label}),y.id===ye.id?s.jsx(B,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},ye.id)},e[57]=S,e[58]=y.id,e[59]=ue):ue=e[59],le=l.map(ue),e[53]=l,e[54]=S,e[55]=y.id,e[56]=le}else le=e[56];let X;e[60]!==a||e[61]!==h||e[62]!==i?(X=a?s.jsxs(Ut,{className:"flex items-center gap-2",onClick:()=>{h(!0)},children:[s.jsx(B,{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 te;e[64]!==q||e[65]!==le||e[66]!==X?(te=s.jsxs(Qs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[q,Z,le,X]}),e[64]=q,e[65]=le,e[66]=X,e[67]=te):te=e[67];let re;e[68]!==D||e[69]!==te?(re=s.jsxs(Ys,{children:[D,te]}),e[68]=D,e[69]=te,e[70]=re):re=e[70];let Se;return e[71]!==O||e[72]!==re||e[73]!==k?(Se=s.jsxs("div",{className:k,children:[O,re]}),e[71]=O,e[72]=re,e[73]=k,e[74]=Se):Se=e[74],Se};function Ux(t){return t.selectedAppId}function Kx(t){return t.availableApps}function Hx(t){return t.isCacheStale}function Gx(t){return t.isScanning}function qx(t){return t.initialize}function Qx(t){return t.loadInstalledApps}function Yx(t){return t.selectApp}function Xx(t){return t.id===px}const Oo=new Map,qi=new Set,Vu=()=>{for(const t of qi)t()},ci=(t,e)=>{const n=t.trim();n&&(e.length===0?Oo.delete(n):Oo.set(n,[...e]),Vu())},Jx=t=>{Oo.delete(t.trim())&&Vu()},Uu=[],Zx=t=>Oo.get(t.trim())??Uu,eb=t=>(qi.add(t),()=>{qi.delete(t)}),tb=t=>{const e=nt.c(2);let n;return e[0]!==t?(n=()=>Zx(t),e[0]=t,e[1]=n):n=e[1],c.useSyncExternalStore(eb,n,sb)};function sb(){return Uu}const nb=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],rb=["dev","start","preview","serve"];async function ob(t,e,n){if(!t)return null;const r=lb(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const i=cb(n);if(i){const o=await db(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 ib(t)){const i=await ab(),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 ib(t){const e=`${t}/index.html`,n=await Bo(e,t);return typeof n=="string"&&n.trim().length>0}async function ab(){try{const t=await bs("/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 lb(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(rb.some(i=>n.includes(i)))return e}return null}function cb(t){for(const{pattern:e}of nb)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function db(t){const e=await Bo(`${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 Bo(`${t}/${r}`,t);if(typeof o=="string"&&o.trim().length>0)return i}return"npm"}async function Bo(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),i=await bs(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(i.ok)return i.text()}catch{}const n=wd()?.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 bs(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function ub(t){try{const e=await Bo(`${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 fn="__openchamber_auto_discover_preview__",mb=15e3,fb=3e3,di=t=>t.id===fn?"scan-2":Jf.find(n=>n.key===t.icon)?.Icon??"play",hb=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}},pb=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:i=!1})=>{const{t:o}=vt(),{currentTheme:l}=nr(),{terminal:a,runtime:u}=jn(),d=rr(),{isMobile:h}=Wn(),f=c.useMemo(()=>yn(),[]),p=il(V=>V.instances),g=il(V=>V.load),w=Ne(V=>V.terminalShell),v=Ne(V=>V.terminalLoginShells.includes(V.terminalShell)),y=Ne(V=>V.setSettingsPage),m=Ne(V=>V.setSettingsDialogOpen),x=Ne(V=>V.setSettingsProjectsSelectedId),b=Ne(V=>V.openContextPreview),S=Ot(V=>V.ensureDirectory),C=Ot(V=>V.reconcileServerSessions),N=Ot(V=>V.setTabLabel),k=Ot(V=>V.setTabIconKey),R=Ot(V=>V.setActiveTab),I=Ot(V=>V.setConnecting),P=Ot(V=>V.setTabSessionId),T=Ot(V=>V.setTabPurpose),E=Ot(V=>V.allocateActionExecution),O=Ot(V=>V.setTabLifecycle),W=Ot(V=>V.setTabPreviewUrl),L=Ot(V=>V.matchesActionExecution),F=Ot(V=>V.captureStartedActionMutationRevisions),[D,j]=c.useState([]),A=c.useRef(null),[M,G]=c.useState(null),[q,Z]=c.useState(!1),le=c.useRef({}),X=c.useRef({}),te=c.useRef({}),re=c.useRef(new Set),Se=c.useRef(0),[ue,ye]=c.useState({}),ve=t?.id??null,be=t?.path??"",_=c.useMemo(()=>ve?{id:ve,path:be}:null,[ve,be]);c.useEffect(()=>{f&&g().catch(()=>{})},[f,g]);const oe=c.useCallback(async V=>{await qo(V)},[]),ce=c.useCallback(async()=>{if(!_)return;const V=Se.current+1;Se.current=V,Z(!0);try{const J=await dl(_);if(Se.current!==V)return;A.current=J;const ge=J.projectActions;j(ge),G(Ee=>Ee===fn||Ee&&ge.some($e=>$e.id===Ee)?Ee:null)}catch{if(Se.current!==V)return}finally{Se.current===V&&Z(!1)}},[_]),Q=c.useMemo(()=>oi(e||_?.path||""),[e,_?.path]),me=c.useMemo(()=>oi(_?.path||""),[_?.path]),ke=c.useMemo(()=>oi(d||"")||Q,[d,Q]),fe=c.useRef(ke);c.useEffect(()=>{fe.current=ke},[ke]);const De=Ot(V=>Q?V.getDirectoryState(Q):void 0),je=Ot(V=>me&&me!==Q?V.getDirectoryState(me):void 0),Y=c.useMemo(()=>{const V=Q?[{directory:Q,state:De}]:[];return me&&me!==Q&&V.push({directory:me,state:je}),V},[De,Q,me,je]),Re=c.useMemo(()=>{const V=Q?[Q]:[];return me&&me!==Q&&V.push(me),V},[Q,me]),Ce=c.useCallback(V=>V.id!==fn&&V.runIn==="parent"&&me||Q,[Q,me]),Me=c.useCallback((V,J,ge)=>`${V}::${J}::${ge}`,[]),ae=c.useCallback((V,J,ge=Ot.getState())=>V?ge.getDirectoryState(V)?.tabs.find(Ee=>Ee.purpose.type==="project-action"&&Ee.purpose.actionId===J)??null:null,[]),ee=c.useMemo(()=>{const V={};for(const{directory:J,state:ge}of Y)for(const Ee of ge?.tabs??[]){if(Ee.purpose.type!=="project-action"||!Ee.purpose.executionId||!Ee.terminalSessionId||Ee.lifecycle==="idle"||Ee.lifecycle==="exited")continue;const $e=un(J,Ee.purpose.actionId),st=Me(J,Ee.purpose.actionId,Ee.purpose.executionId);V[$e]={directory:J,actionId:Ee.purpose.actionId,tabId:Ee.id,sessionId:Ee.terminalSessionId,executionId:Ee.purpose.executionId,status:Ee.lifecycle==="stopping"?"stopping":ue[st]?"waiting-for-preview":"running"}}return V},[Me,ue,Y]),K=c.useCallback((V,J,ge)=>{const Ee=un(V,J),$e=Me(V,J,ge),Ze=le.current[Ee]?.executionId===ge,et=globalThis.window,Ue=jt=>{et?.clearTimeout(te.current[jt]),delete te.current[jt]};Ze&&(delete le.current[Ee],Ue(Ee)),X.current[$e]?.(),delete X.current[$e],Ue($e),ye(jt=>{if(!jt[$e])return jt;const ze={...jt};return delete ze[$e],ze})},[Me]),$=c.useCallback(V=>{X.current[V]?.(),delete X.current[V]},[]),ne=c.useCallback(V=>{window.clearTimeout(te.current[V]),delete te.current[V]},[]);c.useEffect(()=>{const V=X.current,J=te.current;return()=>{for(const ge of Object.keys(V))$(ge);for(const ge of Object.keys(J))ne(ge)}},[ne,$]),c.useEffect(()=>{const V=new Set(Re);for(const J of Object.values(le.current))V.has(J.directory)||K(J.directory,J.actionId,J.executionId);for(const J of Object.keys(X.current)){const ge=J.split("::",1)[0]??"";V.has(ge)||$(J)}},[K,$,Re]);const U=c.useCallback((V,J)=>{Ne.getState().openContextPanelTab(V,{mode:"terminal",targetDirectory:J===V?null:J})},[]),we=c.useMemo(()=>M?D.find(V=>V.id===M)??null:null,[D,M]),he=c.useMemo(()=>({id:fn,name:o("projectActions.actions.autoDiscover"),command:"",icon:"scan-2",autoOpenUrl:!0}),[o]),Te=!h,Oe=c.useMemo(()=>Te?[he,...D]:D,[D,he,Te]);c.useEffect(()=>{ce()},[ce]),c.useEffect(()=>{const V=Re.map(J=>Ai(a,J,F,ge=>C(J,ge.sessions,{startedActionMutationRevisions:ge.startedActionMutationRevisions})));return()=>{for(const J of V)J()}},[F,C,a,Re]),c.useEffect(()=>{for(const{directory:V,state:J}of Y)if(V)for(const ge of J?.tabs??[]){if(ge.purpose.type!=="project-action")continue;const Ee=ge.purpose.actionId,$e=Oe.find(et=>et.id===Ee),st=$e?.name??Ee,Ze=$e?.icon||"play";ge.label!==st&&N(V,ge.id,st),ge.iconKey!==Ze&&k(V,ge.id,Ze)}},[Oe,k,N,Y]),c.useEffect(()=>{const V=globalThis.window;if(!V)return;const J=ge=>{const Ee=ge.detail;ve&&(Ee?.projectId&&Ee.projectId!==ve||ce())};return V.addEventListener(al,J),()=>{V.removeEventListener(al,J)}},[ce,ve]),c.useEffect(()=>{M&&(M===fn&&Te||D.some(V=>V.id===M)||G(null))},[D,Te,M]),c.useEffect(()=>{const V=ge=>{delete te.current[ge];const Ee=le.current[ge];if(!Ee||Ee.openedUrl)return;const $e=Me(Ee.directory,Ee.actionId,Ee.executionId),st=Ee.announced;if(st.length!==0){if(window.clearTimeout(te.current[$e]),delete te.current[$e],Ee.openedUrl=!0,ye(Ze=>{if(!Ze[$e])return Ze;const et={...Ze};return delete et[$e],et}),st.length===1){ci(Ee.directory,[]),W(Ee.directory,Ee.tabId,st[0],{locked:!1,autoOpened:!0}),b(Ee.directory,st[0]);return}Ee.offering=!0,ci(Ee.directory,st),Ne.getState().openContextSurface(Ee.directory,"browser"),Fe.info(o("projectActions.toast.multipleServers"))}},J=()=>{const ge=Ot.getState(),Ee=ge.sessions,$e=ee;for(const[st,Ze]of Object.entries($e)){const Ue=Ee.get(Ze.directory)?.tabs.find(gt=>gt.id===Ze.tabId);if(!Ue||Ue.terminalSessionId!==Ze.sessionId){K(Ze.directory,Ze.actionId,Ze.executionId);continue}const jt=le.current[st],ze=jt?.executionId===Ze.executionId?jt:{hostDirectory:fe.current||Ze.directory,directory:Ze.directory,tabId:Ze.tabId,actionId:Ze.actionId,executionId:Ze.executionId,lastSeenChunkId:null,openedUrl:!0,tail:"",openInPreview:!1,announced:[],offering:!1};le.current[st]=ze;const xe=Oe.find(gt=>gt.id===Ze.actionId),bt=ge.getBuffer(Ze.directory,Ze.tabId).chunks;if(!xe||bt.length===0)continue;const ht=bt.filter(gt=>ze.lastSeenChunkId===null||gt.id>ze.lastSeenChunkId);if(ht.length===0)continue;const kt=ht.map(gt=>gt.data).join(""),Xe=`${ze.tail}${kt}`;if(ze.openInPreview&&(!ze.openedUrl||ze.offering)){const gt=Yf(Xe),Mt=ze.announced.length;for(const St of gt)ze.announced.includes(St)||ze.announced.push(St);const xt=ze.announced.length-Mt;ze.offering&&xt>0?ci(Ze.directory,ze.announced):!ze.openedUrl&&Mt===0&&ze.announced.length>0&&(window.clearTimeout(te.current[st]),te.current[st]=window.setTimeout(()=>V(st),fb))}const Ke=!ze.openedUrl&&xe.autoOpenUrl===!0&&!ze.openInPreview?Xf(Xe):null,Ye=ht[ht.length-1]?.id??ze.lastSeenChunkId;if(ze.lastSeenChunkId=Ye,ze.tail=Xe.slice(-512),Ke)if(ze.openedUrl=!0,ze.openInPreview){const gt=$e[st];gt&&(W(gt.directory,gt.tabId,Ke,{locked:!1,autoOpened:!1,expectedExecutionId:gt.executionId}),gt.status==="waiting-for-preview"&&ye(Mt=>{const xt=Me(gt.directory,gt.actionId,gt.executionId);if(!Mt[xt])return Mt;const St={...Mt};return delete St[xt],St}),window.clearTimeout(te.current[st]),delete te.current[st],b(gt.directory,Ke))}else oe(Ke),Fe.success(o("projectActions.toast.openedUrlFromOutput"));le.current[st]=ze}for(const st of Object.keys(le.current))if(!$e[st]){const Ze=le.current[st],et=Ze?Ee.get(Ze.directory)?.tabs.find(jt=>jt.id===Ze.tabId):void 0;if(et?.purpose.type==="project-action"&&et.purpose.executionId===Ze?.executionId&&!!et.terminalSessionId&&et.lifecycle!=="idle"&&et.lifecycle!=="exited")continue;delete le.current[st],window.clearTimeout(te.current[st]),delete te.current[st]}};return J(),Ot.subscribe((ge,Ee)=>{(ge.sessions!==Ee.sessions||ge.buffers!==Ee.buffers)&&J()})},[K,fe,Oe,Me,b,oe,ee,W,o]),c.useEffect(()=>{for(const{directory:V,state:J}of Y)for(const ge of J?.tabs??[]){if(ge.purpose.type!=="project-action"||!ge.purpose.executionId||!ge.terminalSessionId||ge.lifecycle!=="running")continue;const Ee=ge.purpose.actionId,$e=ge.purpose.executionId,st=Me(V,Ee,$e);if(X.current[st])continue;const Ze=a.connect(ge.terminalSessionId,{onEvent:et=>{if(!L(V,ge.id,$e))return;et.type==="snapshot"&&(Ot.getState().replaceBuffer(V,ge.id,et.data??"",et.sequence??0,Ja(et)),et.status==="running"&&Ot.getState().setTabLifecycle(V,ge.id,"running",{expectedExecutionId:$e}),et.status==="exited"&&(Ot.getState().setTabLifecycle(V,ge.id,"exited",{expectedExecutionId:$e}),Ot.getState().setTabPurpose(V,ge.id,{type:"project-action",actionId:Ee,executionId:null}),K(V,Ee,$e)));const Ue=et.type==="data"?et.data??"":"";Ue&&Ot.getState().appendToBuffer(V,ge.id,Ue,et.sequence,et.replayData),et.type==="exit"&&(Ot.getState().setTabLifecycle(V,ge.id,"exited",{expectedExecutionId:$e}),Ot.getState().setTabPurpose(V,ge.id,{type:"project-action",actionId:Ee,executionId:null}),K(V,Ee,$e))},onError:(et,Ue)=>{!Ue||!L(V,ge.id,$e)||(Ot.getState().setTabLifecycle(V,ge.id,"exited",{expectedExecutionId:$e}),Ot.getState().setTabSessionId(V,ge.id,null,{expectedExecutionId:$e}),Ot.getState().setTabPurpose(V,ge.id,{type:"project-action",actionId:Ee,executionId:null}),K(V,Ee,$e))}});X.current[st]=Ze.close}},[K,Me,L,a,Y]);const _e=c.useCallback(async V=>{const J=Ce(V);if(!J)throw new Error(o("projectActions.error.noActiveDirectory"));const ge=un(J,V.id);S(J);const Ee=Ot.getState(),$e=ae(J,V.id,Ee),st=$e?.id??Ee.createTab(J);N(J,st,V.name),k(J,st,V.icon||"play"),$e||T(J,st,{type:"project-action",actionId:V.id,executionId:null}),R(J,st);const et=Ot.getState().getDirectoryState(J)?.tabs.find(Ue=>Ue.id===st);return{executionDirectory:J,key:ge,tabId:st,sessionId:et?.terminalSessionId??null,executionId:et?.purpose.type==="project-action"?et.purpose.executionId:null}},[S,Ce,ae,R,k,N,T,o]),Ve=c.useCallback(async V=>{if(u.isVSCode||!i&&h)return;if(!Q){Fe.error(o("projectActions.error.noActiveDirectoryForAction"));return}const J=un(Ce(V),V.id),ge=ee[J];if(ge&&ge.status==="running"||re.current.has(J))return;re.current.add(J);let Ee=null;try{const $e=V.id===fn?await(async()=>{const[xt,St]=await Promise.all([Ph({id:_?.id??"",path:Q}),ub(Q)]),Tt=await ob(Q,xt.actions,St);if(!Tt)throw new Error(o("contextPanel.preview.noDevServer"));return{id:fn,name:o("projectActions.actions.autoDiscover"),command:Tt.command,icon:"scan-2",autoOpenUrl:!0,openUrl:Tt.previewUrlHint||""}})():V,st=$e.autoOpenUrl===!0&&($e.openUrl||"").trim().length>0,Ze=!st&&V.id!==fn,et=fe.current||Q,{executionDirectory:Ue,key:jt,tabId:ze}=await _e($e),xe=Kf($e.command);if(!xe)throw new Error(o("projectActions.error.failedToRunAction"));const bt=$e.autoOpenUrl===!0&&f&&($e.desktopOpenSshForward||"").trim().length>0,ht=$e.autoOpenUrl?hb($e.openUrl):null,kt=$e.autoOpenUrl&&f?Hf($e.desktopOpenSshForward,p):null;if(a.listSessions){const xt=ae(Ue,$e.id);if(xt?.purpose.type==="project-action"&&xt.purpose.executionId===null){const St=await Gf(a,Ue,{captureStartedActionMutationRevisions:F});St&&C(Ue,St.sessions,{startedActionMutationRevisions:St.startedActionMutationRevisions})}}const Xe=ae(Ue,$e.id);let Ke,Ye;if(Xe?.lifecycle==="running"&&Xe.terminalSessionId&&Xe.purpose.type==="project-action"&&Xe.purpose.executionId)Ke=Xe.terminalSessionId,Ye=Xe.purpose.executionId;else{const xt=Xe?.purpose.type==="project-action"?Xe.purpose.executionId:null;xt&&K(Ue,$e.id,xt);const St=E(Ue,ze,$e.id);if(!St)throw new Error(o("projectActions.error.failedToCreateTerminalSession"));Ee={directory:Ue,tabId:ze,id:St},I(Ue,ze,!0,{expectedExecutionId:St});const Tt=await qf({terminal:a,createOptions:{cwd:Ue,shell:w,loginShell:v,themeMode:l.metadata.variant==="light"?"light":"dark",terminalBackground:l.colors.surface.background,terminalForeground:l.colors.syntax.base.foreground},command:xe,isRunStillExpected:()=>L(Ue,ze,St),purpose:{type:"project-action",actionId:$e.id,executionId:St}});if(!L(Ue,ze,St)){Tt.sessionId===St&&await a.close(Tt.sessionId).catch(()=>{});return}Ye=Tt.purpose?.type==="project-action"?Tt.purpose.executionId:St,Ke=Tt.sessionId,T(Ue,ze,{type:"project-action",actionId:$e.id,executionId:Ye}),P(Ue,ze,Ke,{expectedExecutionId:Ye}),I(Ue,ze,!1,{expectedExecutionId:Ye})}Ze&&et&&U(et,Ue),le.current[jt]={hostDirectory:et,directory:Ue,tabId:ze,actionId:$e.id,executionId:Ye,lastSeenChunkId:null,openedUrl:!!kt||!!ht||st,tail:"",openInPreview:$e.id===fn,announced:[],offering:!1};const gt=Me(Ue,$e.id,Ye);I(Ue,ze,!0,{expectedExecutionId:Ye});const Mt=a.connect(Ke,{onEvent:xt=>{if(!L(Ue,ze,Ye)||xt.purpose?.type==="project-action"&&xt.purpose.executionId!==Ye)return;xt.type==="snapshot"&&(Ot.getState().replaceBuffer(Ue,ze,xt.data??"",xt.sequence??0,Ja(xt)),Ot.getState().setConnecting(Ue,ze,!1,{expectedExecutionId:Ye}),xt.purpose?.type==="project-action"&&Ot.getState().setTabPurpose(Ue,ze,{type:"project-action",actionId:xt.purpose.actionId,executionId:xt.purpose.executionId}),xt.status==="running"&&Ot.getState().setTabLifecycle(Ue,ze,"running",{expectedExecutionId:Ye}),xt.status==="exited"&&(Ot.getState().setTabLifecycle(Ue,ze,"exited",{expectedExecutionId:Ye}),Ot.getState().setTabPurpose(Ue,ze,{type:"project-action",actionId:$e.id,executionId:null}),K(Ue,$e.id,Ye)));const St=xt.type==="data"?xt.data??"":"";St&&Ot.getState().appendToBuffer(Ue,ze,St,xt.sequence,xt.replayData),xt.type==="exit"&&(Ot.getState().setTabLifecycle(Ue,ze,"exited",{expectedExecutionId:Ye}),Ot.getState().setConnecting(Ue,ze,!1,{expectedExecutionId:Ye}),Ot.getState().setTabPurpose(Ue,ze,{type:"project-action",actionId:$e.id,executionId:null}),K(Ue,$e.id,Ye))},onError:(xt,St)=>{L(Ue,ze,Ye)&&(Ot.getState().setConnecting(Ue,ze,!1,{expectedExecutionId:Ye}),St&&(Ot.getState().setTabLifecycle(Ue,ze,"exited",{expectedExecutionId:Ye}),Ot.getState().setTabSessionId(Ue,ze,null,{expectedExecutionId:Ye}),Ot.getState().setTabPurpose(Ue,ze,{type:"project-action",actionId:$e.id,executionId:null}),K(Ue,$e.id,Ye)))}});if(!L(Ue,ze,Ye)){Mt.close();return}X.current[gt]?.(),X.current[gt]=Mt.close,window.clearTimeout(te.current[gt]),delete te.current[gt],$e.id===fn&&!ht&&(ye(xt=>({...xt,[gt]:!0})),te.current[gt]=window.setTimeout(()=>{delete te.current[gt];const xt=le.current[jt];!xt||xt.executionId!==Ye||xt.openedUrl||xt.offering||L(Ue,ze,Ye)&&(ye(St=>{if(!St[gt])return St;const Tt={...St};return delete Tt[gt],Tt}),Ot.getState().setActiveTab(Ue,ze),U(xt.hostDirectory,Ue))},mb)),kt?(W(Ue,ze,null,{locked:!0,expectedExecutionId:Ye}),oe(kt),Fe.success(o("projectActions.toast.openedForwardedUrl"))):ht?(W(Ue,ze,ht,{locked:!0,autoOpened:!0,expectedExecutionId:Ye}),b(et,ht),Fe.success(o("projectActions.toast.openedActionUrl"))):st?(W(Ue,ze,null,{locked:!0,expectedExecutionId:Ye}),Fe.error(o("projectActions.error.invalidCustomUrlFormat"))):bt?(W(Ue,ze,null,{locked:!0,expectedExecutionId:Ye}),Fe.error(o("projectActions.error.selectedDesktopSshForwardUnavailable"))):W(Ue,ze,null,{locked:!1,autoOpened:!1,expectedExecutionId:Ye})}catch($e){if(Ee&&L(Ee.directory,Ee.tabId,Ee.id)){const{directory:st,tabId:Ze,id:et}=Ee;K(st,V.id,et),O(st,Ze,"exited",{expectedExecutionId:et}),T(st,Ze,{type:"project-action",actionId:V.id,executionId:null})}if($e instanceof Error&&$e.message==="PROJECT_ACTION_RUN_CANCELLED")return;if($e instanceof Error&&($e.message==="COMMAND_MODE_UNSUPPORTED"||$e.message==="PROJECT_ACTION_PURPOSE_UNSUPPORTED")){Fe.error(o("projectActions.error.failedToCreateTerminalSession"));return}Fe.error($e instanceof Error?$e.message:o("projectActions.error.failedToRunAction"))}finally{re.current.delete(J)}},[l.colors.surface.background,l.colors.syntax.base.foreground,l.metadata.variant,fe,p,_e,i,h,f,Q,v,w,oe,b,ee,U,u.isVSCode,Ce,L,K,Me,ae,C,E,F,I,O,T,W,P,_?.id,o,a]),z=c.useCallback(async V=>{const J=un(Ce(V),V.id),ge=ee[J];ge&&await Qf({terminal:a,sessionId:ge.sessionId,isExecutionStillCurrent:()=>L(ge.directory,ge.tabId,ge.executionId),markStopping:()=>{O(ge.directory,ge.tabId,"stopping",{expectedExecutionId:ge.executionId})},restoreRunning:()=>{O(ge.directory,ge.tabId,"running",{expectedExecutionId:ge.executionId})},clearSession:()=>{P(ge.directory,ge.tabId,null,{expectedExecutionId:ge.executionId})},finalizeExit:()=>{O(ge.directory,ge.tabId,"exited",{expectedExecutionId:ge.executionId}),T(ge.directory,ge.tabId,{type:"project-action",actionId:ge.actionId,executionId:null}),K(ge.directory,ge.actionId,ge.executionId)}})},[K,Ce,L,ee,O,T,P,a]),pe=c.useCallback(()=>{const V=we??Oe[0];if(!V)return;const J=un(Ce(V),V.id),ge=ee[J];if(ge?.status!=="stopping"){if(ge){z(V);return}Ve(V)}},[Oe,Ce,Ve,ee,we,z]),Ae=c.useCallback(async V=>{if(V.source==="shared"&&_){const J=A.current?.trust.trusted?A.current:await dl(_);if(A.current=J,!await Dh(_,J))return;A.current={...J,trust:{...J.trust,trusted:!0}}}await Ve(V)},[Ve,_]),Be=c.useCallback((V,J=!1)=>{if(G(V.id),!J){Ae(V);return}const ge=un(Ce(V),V.id),Ee=ee[ge];if(Ee?.status!=="stopping"){if(Ee){z(V);return}Ae(V)}},[Ce,Ae,ee,z]),rt=c.useCallback(()=>{_?.id&&(x(_.id),y("projects"),m(!0))},[m,y,x,_?.id]),Ge=we??Oe[0]??null,ut=Ge?ee[un(Ce(Ge),Ge.id)]:null,at=Ot(V=>ut?V.getDirectoryState(ut.directory)?.tabs.find(J=>J.id===ut.tabId)?.previewUrl??null:null);if(u.isVSCode||!i&&h||!_||!Q)return null;const wt=we??Oe[0]??null;if(!wt)return null;const pt=di(wt),It=un(Ce(wt),wt.id),Pt=ee[It],Rt=Pt?.status==="stopping",de=Pt?.status==="waiting-for-preview",We=!!(Pt&&at),lt=()=>{!Pt||!at||b(Pt.directory,at)},H=wt.id===fn;return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",disabled:q||Rt,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-ring","disabled:cursor-not-allowed",n),onClick:pe,"aria-label":Pt?o("projectActions.actions.stopNamedAria",{name:wt.name}):o("projectActions.actions.runNamedAria",{name:wt.name}),children:Rt||de?s.jsx(B,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):Pt?s.jsx(B,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(B,{name:pt,className:"h-5 w-5"})})}),H?s.jsx(At,{sideOffset:6,children:o("projectActions.actions.autoDiscoverTooltip")}):null]}),We?s.jsxs(Ct,{children:[s.jsx(Nt,{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-ring","aria-label":o("projectActions.actions.openPreview"),onClick:lt,children:s.jsx(B,{name:"global",className:"h-4 w-4"})})}),s.jsx(At,{sideOffset:6,children:o("projectActions.actions.openPreview")})]}):null,s.jsxs(Ys,{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-ring","aria-label":o("projectActions.actions.chooseActionAria"),children:s.jsx(B,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Qs,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Ut,{className:"flex items-center gap-2",onClick:rt,children:[s.jsx(B,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("projectActions.actions.addNewAction")})]}),s.jsx(zs,{}),Oe.map(V=>{const J=di(V),ge=un(Ce(V),V.id),Ee=ee[ge],$e=!!Ee,st=Ee?.status==="stopping";return s.jsxs(Ut,{className:"flex items-center gap-2",onClick:()=>{Be(V,!0)},children:[s.jsx(B,{name:J,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:V.name}),V.source==="shared"?s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-muted-foreground bg-[var(--surface-subtle)]",children:o("projectActions.menu.sharedBadge")}):null,st||Ee?.status==="waiting-for-preview"?s.jsx(B,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):$e?s.jsx(B,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},V.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(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:pe,disabled:q||Rt,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-ring disabled:cursor-not-allowed"),"aria-label":Pt?o("projectActions.actions.stopNamedAria",{name:wt.name}):o("projectActions.actions.runNamedAria",{name:wt.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:Rt||de?s.jsx(B,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):Pt?s.jsx(B,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(B,{name:pt,className:"h-4 w-4"})})})}),H?s.jsx(At,{sideOffset:6,children:o("projectActions.actions.autoDiscoverTooltip")}):null]}),We?s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:lt,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-ring"),"aria-label":o("projectActions.actions.openPreview"),children:s.jsx(B,{name:"global",className:"h-4 w-4"})})}),s.jsx(At,{sideOffset:6,children:o("projectActions.actions.openPreview")})]}):null,s.jsxs(Ys,{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-ring"),"aria-label":o("projectActions.actions.chooseActionAria"),children:s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Qs,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Ut,{className:"flex items-center gap-2",onClick:rt,children:[s.jsx(B,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("projectActions.actions.addNewAction")})]}),s.jsx(zs,{}),Oe.map(V=>{const J=di(V),ge=un(Ce(V),V.id),Ee=ee[ge],$e=!!Ee,st=Ee?.status==="stopping";return s.jsxs(Ut,{className:"flex items-center gap-2",onClick:()=>{Be(V,!0)},children:[s.jsx(B,{name:J,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:V.name}),V.source==="shared"?s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-muted-foreground bg-[var(--surface-subtle)]",children:o("projectActions.menu.sharedBadge")}):null,st||Ee?.status==="waiting-for-preview"?s.jsx(B,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):$e?s.jsx(B,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},V.id)})]})]})]})},Lr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},gb=({projects:t,worktreesByProject:e,directory:n,activeProjectId:r})=>{const i=Lr(n??"");if(i){const o=Bd(t,e,i);if(o)return o}return t.find(o=>o.id===r)??null};function xb(){const t=qt(w=>w.projects),e=qt(w=>w.activeProjectId),n=tt(w=>w.availableWorktreesByProject),r=tt(w=>w.currentSessionId),i=Ih(r??null),o=tt(w=>r?w.worktreeMetadata.get(r)?.path??"":""),l=tt(w=>w.newSessionDraft?.open?Lr(w.newSessionDraft.bootstrapPendingDirectory??w.newSessionDraft.directoryOverride??""):""),a=c.useMemo(()=>Lr(o||""),[o]),u=c.useMemo(()=>{const w=typeof i?.directory=="string"?i.directory:"";return Lr(w||"")},[i?.directory]),d=a||u||l,h=c.useMemo(()=>gb({projects:t,worktreesByProject:n,directory:d,activeProjectId:e}),[e,d,t,n]),f=c.useMemo(()=>Lr(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 bb=({transform:t})=>({...t,y:0}),yb={Item:Ut,Separator:zs},wb={Item:({className:t,...e})=>s.jsx(Bu,{className:Ie(Ld,t),...e}),Separator:({className:t,...e})=>s.jsx(Ou,{className:Ie(_d,t),...e})},Sb=t=>{const e=nt.c(67),{tab:n,isActive:r,suppressControls:i,onSelect:o,onClose:l,renderMenu:a,closeOtherTabs:u,onMenuOpenChangeComplete:d,children:h}=t,{t:f}=vt(),[p,g]=c.useState(!1),[w,v]=c.useState(!1),[y,m]=c.useState(!1);let x;e[0]!==n.id?(x={id:n.id},e[0]=n.id,e[1]=x):x=e[1];const{attributes:b,listeners:S,setNodeRef:C,transform:N,transition:k,isDragging:R}=Zo(x);let I;e[2]!==f||e[3]!==n.session.title?(I=n.session.title?.trim()||f("sessions.sidebar.session.untitled"),e[2]=f,e[3]=n.session.title,e[4]=I):I=e[4];const P=I,T=!i&&(p||w),E=va(n.id),O=n.id;let W;e[5]!==n.session?(W=Fs(n.session),e[5]=n.session,e[6]=W):W=e[6];const L=Sa(O,W),F=E?.type==="busy"||E?.type==="retry",j=Fd(n.id)>0&&!r&&!F,A=F||j;let M;e[7]!==F||e[8]!==f?(M=f(F?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),e[7]=F,e[8]=f,e[9]=M):M=e[9];const G=M;let q;e[10]!==u||e[11]!==y||e[12]!==r||e[13]!==p||e[14]!==o||e[15]!==n?(q=ke=>({session:n.session,open:p||y,isActive:r,select:()=>o(n),closeOtherTabs:()=>u(n.id),components:ke}),e[10]=u,e[11]=y,e[12]=r,e[13]=p,e[14]=o,e[15]=n,e[16]=q):q=e[16];const Z=q;let le;e[17]!==N?(le=ei.Translate.toString(N),e[17]=N,e[18]=le):le=e[18];let X;e[19]!==le||e[20]!==k?(X={transform:le,transition:k},e[19]=le,e[20]=k,e[21]=X):X=e[21];const te=R&&"z-10 opacity-60";let re;e[22]!==te?(re=Ie("session-tab-slot flex h-7 w-44 shrink-0 touch-none",te),e[22]=te,e[23]=re):re=e[23];const Se=r?"true":"false";let ue;e[24]!==r?(ue=r?{"data-active-session-tab":!0}:{},e[24]=r,e[25]=ue):ue=e[25];let ye;e[26]!==d?(ye=ke=>d?.(ke),e[26]=d,e[27]=ye):ye=e[27];let ve;e[28]!==h||e[29]!==G||e[30]!==r||e[31]!==L||e[32]!==F||e[33]!==Z||e[34]!==p||e[35]!==l||e[36]!==d||e[37]!==o||e[38]!==T||e[39]!==a||e[40]!==A||e[41]!==i||e[42]!==f||e[43]!==n||e[44]!==P?(ve=s.jsx(Fu,{render:ke=>s.jsxs("div",{...ke,role:"tab","aria-selected":r,tabIndex:r?void 0:0,onClick:r?void 0:()=>o(n),onKeyDown:r?void 0:fe=>{(fe.key==="Enter"||fe.key===" ")&&(fe.preventDefault(),o(n))},onAuxClick:fe=>{fe.button===1&&(fe.preventDefault(),l(n.id))},"data-controls-open":T?"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 text-interactive-selection-foreground":Ie("cursor-pointer text-muted-foreground hover:bg-interactive-hover hover:text-foreground",T&&"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",T&&"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:P})})}),L?s.jsx(B,{name:"loader-4",className:"ml-1.5 size-3 shrink-0 animate-spin text-primary","aria-label":f("sessions.aiRename.generating")}):A?s.jsx("span",{className:Ie("ml-1.5 h-1.5 w-1.5 shrink-0 rounded-full",F?"bg-primary":"bg-[var(--status-info)]",!i&&"group-hover/session-tab:opacity-0",T&&"opacity-0"),"aria-label":G}):null]}),i?null:s.jsxs("div",{onClick:jb,onPointerDown:kb,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",T&&"flex opacity-100"),children:[s.jsxs(Ys,{open:p,onOpenChange:fe=>{g(fe),fe&&v(!0)},onOpenChangeComplete:fe=>{fe||v(!1),d?.(fe)},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(B,{name:"more",className:"size-4"})})}),s.jsx(Qs,{align:"start",className:"min-w-[190px]",children:a(Z(yb))})]}),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(B,{name:"close",className:"size-4"})})]})]})}),e[28]=h,e[29]=G,e[30]=r,e[31]=L,e[32]=F,e[33]=Z,e[34]=p,e[35]=l,e[36]=d,e[37]=o,e[38]=T,e[39]=a,e[40]=A,e[41]=i,e[42]=f,e[43]=n,e[44]=P,e[45]=ve):ve=e[45];let be,_;e[46]===Symbol.for("react.memo_cache_sentinel")?(be={color:"var(--surface-elevated-foreground)"},_=Ie(Ii,"min-w-[190px]"),e[46]=be,e[47]=_):(be=e[46],_=e[47]);let oe;e[48]!==Z||e[49]!==a?(oe=a(Z(wb)),e[48]=Z,e[49]=a,e[50]=oe):oe=e[50];let ce;e[51]!==oe?(ce=s.jsx(Ki,{children:s.jsx(Hi,{className:"app-region-no-drag z-50",children:s.jsx(Gi,{"data-slot":"dropdown-menu-content",style:be,className:_,children:oe})})}),e[51]=oe,e[52]=ce):ce=e[52];let Q;e[53]!==y||e[54]!==ye||e[55]!==ve||e[56]!==ce?(Q=s.jsxs(_u,{open:y,onOpenChange:m,onOpenChangeComplete:ye,children:[ve,ce]}),e[53]=y,e[54]=ye,e[55]=ve,e[56]=ce,e[57]=Q):Q=e[57];let me;return e[58]!==b||e[59]!==S||e[60]!==C||e[61]!==re||e[62]!==Se||e[63]!==ue||e[64]!==Q||e[65]!==X?(me=s.jsx("div",{ref:C,style:X,className:re,"data-active":Se,...ue,...b,...S,children:Q}),e[58]=b,e[59]=S,e[60]=C,e[61]=re,e[62]=Se,e[63]=ue,e[64]=Q,e[65]=X,e[66]=me):me=e[66],me},vb=t=>{const e=nt.c(64),{renderMenu:n,onMenuOpenChangeComplete:r,suppressActiveTabControls:i,children:o}=t,l=i===void 0?!1:i,{t:a}=vt(),u=ro(Cb),d=ro(Nb),h=ro(Ab),f=ro(Pb),p=tt(Db),g=tt(Ib),w=Gs(Tb);let v,y;e[0]!==p||e[1]!==d?(v=()=>{p&&d(p)},y=[p,d],e[0]=p,e[1]=d,e[2]=v,e[3]=y):(v=e[2],y=e[3]),c.useEffect(v,y);let m;if(e[4]!==w){m=new Map;for(const fe of w)m.set(fe.id,fe);e[4]=w,e[5]=m}else m=e[5];const x=m;let b;if(e[6]!==x||e[7]!==u){b=[];for(const fe of u){const De=x.get(fe);De&&b.push({id:fe,session:De})}e[6]=x,e[7]=u,e[8]=b}else b=e[8];const S=b;let C;e[9]!==g?(C=fe=>{g(fe.id,Fs(fe.session))},e[9]=g,e[10]=C):C=e[10];const N=C,k=Eb;let R;e[11]!==h||e[12]!==p||e[13]!==N||e[14]!==S?(R=fe=>{if(h(fe),p&&p!==fe){const De=S.find(je=>je.id===fe);De&&N(De)}},e[11]=h,e[12]=p,e[13]=N,e[14]=S,e[15]=R):R=e[15];const I=R;let P;e[16]===Symbol.for("react.memo_cache_sentinel")?(P={activationConstraint:{distance:8}},e[16]=P):P=e[16];let T;e[17]===Symbol.for("react.memo_cache_sentinel")?(T={activationConstraint:{delay:200,tolerance:6}},e[17]=T):T=e[17];const E=qr(_n(Ru,P),_n(Eu,T));let O;e[18]!==f?(O=fe=>{const{active:De,over:je}=fe;je&&De.id!==je.id&&f(String(De.id),String(je.id))},e[18]=f,e[19]=O):O=e[19];const W=O,L=c.useRef(null);let F;e[20]===Symbol.for("react.memo_cache_sentinel")?(F={left:!1,right:!1},e[20]=F):F=e[20];const[D,j]=c.useState(F);let A;e[21]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{const fe=L.current;if(!fe)return;const De=fe.scrollLeft>2,je=fe.scrollLeft+fe.clientWidth<fe.scrollWidth-2;j(Y=>Y.left===De&&Y.right===je?Y:{left:De,right:je})},e[21]=A):A=e[21];const M=A;let G;e[22]===Symbol.for("react.memo_cache_sentinel")?(G=()=>{M();const fe=L.current;if(!fe||!globalThis.ResizeObserver)return;const De=new ResizeObserver(M);return De.observe(fe),()=>De.disconnect()},e[22]=G):G=e[22];let q;e[23]!==S.length?(q=[M,S.length],e[23]=S.length,e[24]=q):q=e[24],c.useEffect(G,q);let Z;e[25]===Symbol.for("react.memo_cache_sentinel")?(Z=()=>{L.current?.querySelector("[data-active-session-tab]")?.scrollIntoView({block:"nearest",inline:"nearest"})},e[25]=Z):Z=e[25];let le;e[26]!==p?(le=[p],e[26]=p,e[27]=le):le=e[27],c.useEffect(Z,le);const X=D.left&&D.right?"linear-gradient(to right, transparent, black 24px, black calc(100% - 24px), transparent)":D.left?"linear-gradient(to right, transparent, black 24px)":D.right?"linear-gradient(to right, black calc(100% - 24px), transparent)":void 0;let te;e[28]!==S?(te=S.map(Rb),e[28]=S,e[29]=te):te=e[29];const re=te;let Se;e[30]!==p||e[31]!==S?(Se=!p||!S.some(fe=>fe.id===p),e[30]=p,e[31]=S,e[32]=Se):Se=e[32];const ue=Se;let ye;e[33]!==a?(ye=a("header.sessionTabs.stripAria"),e[33]=a,e[34]=ye):ye=e[34];let ve;e[35]!==X?(ve=X?{maskImage:X,WebkitMaskImage:X}:void 0,e[35]=X,e[36]=ve):ve=e[36];let be;e[37]===Symbol.for("react.memo_cache_sentinel")?(be=[bb],e[37]=be):be=e[37];let _;e[38]!==o||e[39]!==p||e[40]!==I||e[41]!==N||e[42]!==r||e[43]!==n||e[44]!==l||e[45]!==S?(_=S.map(fe=>s.jsx(Sb,{tab:fe,isActive:fe.id===p,suppressControls:fe.id===p&&l,onSelect:N,onClose:k,renderMenu:n,closeOtherTabs:I,onMenuOpenChangeComplete:r,children:fe.id===p?o:null},fe.id)),e[38]=o,e[39]=p,e[40]=I,e[41]=N,e[42]=r,e[43]=n,e[44]=l,e[45]=S,e[46]=_):_=e[46];let oe;e[47]!==_||e[48]!==re?(oe=s.jsx(Mo,{items:re,strategy:Ax,children:_}),e[47]=_,e[48]=re,e[49]=oe):oe=e[49];let ce;e[50]!==W||e[51]!==E||e[52]!==oe?(ce=s.jsx(Qr,{sensors:E,collisionDetection:Yr,modifiers:be,onDragEnd:W,children:oe}),e[50]=W,e[51]=E,e[52]=oe,e[53]=ce):ce=e[53];let Q;e[54]!==o||e[55]!==ue?(Q=ue?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]=ue,e[56]=Q):Q=e[56];let me;e[57]!==ve||e[58]!==ce||e[59]!==Q?(me=s.jsxs("div",{ref:L,onScroll:M,className:"session-tabs-scroll flex min-w-0 flex-1 items-center gap-1.5 overflow-x-auto overscroll-x-contain",style:ve,children:[ce,Q]}),e[57]=ve,e[58]=ce,e[59]=Q,e[60]=me):me=e[60];let ke;return e[61]!==ye||e[62]!==me?(ke=s.jsx("div",{className:"app-region-no-drag flex h-full min-w-0 flex-1 items-center",role:"tablist","aria-label":ye,children:me}),e[61]=ye,e[62]=me,e[63]=ke):ke=e[63],ke};function jb(t){return t.stopPropagation()}function kb(t){return t.stopPropagation()}function Cb(t){return t.tabIds}function Nb(t){return t.ensureTab}function Ab(t){return t.closeOtherTabs}function Pb(t){return t.reorderTabs}function Db(t){return t.currentSessionId}function Ib(t){return t.setCurrentSession}function Tb(t){return t.activeSessions}function Eb(t){Th(t)}function Rb(t){return t.id}const Ku=async t=>{const{entry:e,session:n}=t,r={sessionId:n.id,sessionTitle:n.title,directory:n.directory};if(!(Eh(e.action)&&Rh(e.guest,"conversation"))){ul(e.guest,ml(e.action.id,r),n.directory);return}const o=await t.loadRecords();if(!o){t.onLoadFailed();return}ul(e.guest,ml(e.action.id,r,o),n.directory)};function Qi(t){const e=nt.c(16),{sessionID:n,directory:r,open:i,Item:o}=t,{t:l}=vt(),{pending:a,disabled:u,hint:d,run:h}=Zf(n,r,i),f=a?"loader-4":"ai-generate-2",p=a?"mr-1 size-4 animate-spin":"mr-1 size-[15px]";let g;e[0]!==f||e[1]!==p?(g=s.jsx(B,{name:f,className:p}),e[0]=f,e[1]=p,e[2]=g):g=e[2];let w;e[3]!==l?(w=l("sessions.aiRename.action"),e[3]=l,e[4]=w):w=e[4];let v;e[5]!==o||e[6]!==u||e[7]!==h||e[8]!==g||e[9]!==w?(v=s.jsx(Nt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(o,{disabled:u,onClick:h,className:"w-full",children:[g,w]})})}),e[5]=o,e[6]=u,e[7]=h,e[8]=g,e[9]=w,e[10]=v):v=e[10];let y;e[11]!==d?(y=s.jsx(At,{side:"right",children:d}),e[11]=d,e[12]=y):y=e[12];let m;return e[13]!==v||e[14]!==y?(m=s.jsxs(Ct,{children:[v,y]}),e[13]=v,e[14]=y,e[15]=m):m=e[15],m}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")}),Vn=or(()=>({pendingSessionIds:new Set,requestingSessionIds:new Set,confirmation:null})),Hu=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],Vn(n)},Mb=()=>Vn(Ub),Gu=()=>Vn.getState().confirmation,La=t=>{Vn.setState(e=>e.confirmation===t?e:{...e,confirmation:t})},_l=(t,e)=>{Vn.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}})},mr=(t,e)=>{Vn.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}})},Ob="Unable to apply your changes in the destination directory",Bb=t=>t.status===400&&t.message.includes(Ob),Fb=async(t,e)=>{try{const u=(await $d(t,{mode:"light"})).current?.trim();if(u)return u}catch{}const n=ft(t),r=ft(e)??e,i=tt.getState().availableWorktreesByProject,l=(i.get(r)??i.get(e)??[]).find(a=>ft(a.path)===n)?.branch?.trim();if(l)return l;throw new Error("Unable to determine the current branch")},Ll=t=>{for(const e of t){const n=Oh(e.id);if(n==="unknown")throw new Error("Session status is unavailable");if(n==="active")throw new Error("Session is not idle")}};class qu extends Error{changesMayBeInDestination;constructor(e,n,r){super(e,{cause:n}),this.name="IncompleteRollbackError",this.changesMayBeInDestination=r}}const _b=(t,e,n)=>{const r=e.map(({sessionId:i,error:o})=>`${i}: ${o.message}`).join(", ");return new qu(`Session move partially failed and could not be fully rolled back: ${t.message}. Rollback failures: ${r}`,{moveError:t,rollbackFailures:e},n)},Lb=async(t,e,n,r)=>{const i=[];for(const o of[...t].reverse()){if(Bh(o.id)){i.push({sessionId:o.id,error:new Error("Session is not idle")});continue}try{await Wd(o,n,e,!1),tt.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 Qu extends Error{constructor(e){super(e.message,{cause:e}),this.name="ChangesMayBeInDestinationError"}}const $l=async(t,e,n)=>{try{await zd(t,e,{deleteLocalBranch:!0})}catch{throw new Error(`Session move failed and the new worktree could not be removed: ${n.message}`)}throw n},Wl=async(t,e)=>{const n=e?[t,e]:[t];try{await ja(n)}catch(r){console.warn("[session-worktree-move] Failed to refresh moved sessions",r)}},Yu=async(t,e)=>{if(Vn.getState().pendingSessionIds.has(t.root.id))throw new Error("Session move already in progress");_l(t.root.id,!0);try{const n=[...t.descendants,t.root],r=new Map(n.map(a=>[a.id,tt.getState().getWorktreeMetadata(a.id)]));Ll(n);let i=null;const o=[];let l=!1;try{i=await e();for(const[a,u]of n.entries()){Ll(n.slice(a));const d=u.id===t.root.id&&t.moveChanges;try{await Wd(u,t.sourceDirectory,i.directory,d)}catch(h){throw d&&Mh(h)&&(l=!0),h}o.push(u),u.id!==t.root.id&&tt.getState().setWorktreeMetadata(u.id,fl(i.metadata))}}catch(a){const u=a instanceof Error?a:new Error(String(a)),d=await Lb(o,t.sourceDirectory,i?.directory??t.sourceDirectory,r);if(l&&await Wl(t.sourceDirectory,i?.directory),d.length>0)throw _b(u,d,l);if(l)throw new Qu(u);if(i?.onMoveFailure)return i.onMoveFailure(u);throw u}return tt.getState().setWorktreeMetadata(t.root.id,fl(i.metadata)),await Wl(t.sourceDirectory,i.directory),i.directory}finally{_l(t.root.id,!1)}},$b=async t=>{const e=ft(t.sourceDirectory)??t.sourceDirectory,n=ft(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 Yu(t,async()=>({directory:t.destination.path,metadata:t.destination}))},Wb=async t=>Yu(t,async()=>{const e=Ti(t.sourceDirectory);if(!e)throw new Error("Unable to find the project for this session");const n=await Qo(t.sourceDirectory)?await Fb(t.sourceDirectory,e.path):null,r=await Fh(e,n?{startRef:n}:{});try{await _h(r.path)}catch(i){const o=i instanceof Error?i:new Error(String(i));return $l(e,r,o)}return{directory:r.path,metadata:r,onMoveFailure:async i=>$l(e,r,i)}}),zb=(t,e,n)=>e instanceof Qu?t.changesMayBeInDestination:e instanceof qu&&e.changesMayBeInDestination?`${e.message} ${t.changesMayBeInDestination}`:n&&Bb(e)?t.applyChangesFailed:e.message,Xi=(t,e)=>{(t.kind==="existing"?$b({root:t.root,descendants:t.descendants,sourceDirectory:t.sourceDirectory,destination:t.destination,moveChanges:e}):Wb({root:t.root,descendants:t.descendants,sourceDirectory:t.sourceDirectory,moveChanges:e})).then(()=>Fe.success(t.messages.success)).catch(r=>{const i=r instanceof Error?r:new Error(String(r));Fe.error(t.messages.failure,{description:zb(t.messages,i,e)})})},Vb=()=>{const t=Gu();t&&(mr(t.intent.root.id,!1),La(null))},Xu=t=>{const e=Gu();if(!e)return;const{intent:n}=e;La(null),mr(n.root.id,!1),Xi(n,t)},Ji=t=>{const e=Vn.getState();e.confirmation||e.pendingSessionIds.has(t.root.id)||e.requestingSessionIds.has(t.root.id)||(mr(t.root.id,!0),(async()=>{try{if(!await Qo(t.sourceDirectory)){mr(t.root.id,!1),Xi(t,!1);return}const r=await $d(t.sourceDirectory);if(r.isClean){mr(t.root.id,!1),Xi(t,!1);return}const i=r.files.filter(o=>{const l=o.index.trim();return l!==""&&l!=="?"}).length;La({intent:t,dirtyFileCount:r.files.length,stagedFileCount:i})}catch{Fe.error(t.messages.failure,{description:t.messages.sourceVerificationFailed}),mr(t.root.id,!1)}})())};function Ub(t){return t.confirmation}const Fo="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-ring disabled:pointer-events-none disabled:opacity-50 hover:bg-interactive-hover transition-colors",Kb=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??Fo,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 y=d??"h-[18px] w-[18px]";let m;n[3]!==u||n[4]!==y?(m=s.jsx(B,{name:u,className:y}),n[3]=u,n[4]=y,n[5]=m):m=n[5];let x;n[6]!==o||n[7]!==l||n[8]!==p||n[9]!==v||n[10]!==m?(x=s.jsx(Nt,{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]=x):x=n[11];let b;n[12]!==i?(b=s.jsx(At,{children:s.jsx("p",{children:i})}),n[12]=i,n[13]=b):b=n[13];let S;return n[14]!==x||n[15]!==b?(S=s.jsxs(Ct,{children:[x,b]}),n[14]=x,n[15]=b,n[16]=S):S=n[16],S}),Hb=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}=vt();let v;n[0]!==u||n[1]!==a?(v=E=>{a(E),E&&u()},n[0]=u,n[1]=a,n[2]=v):v=n[2];let y;n[3]!==i||n[4]!==r||n[5]!==w?(y=r?w("header.services.openWithCurrent",{current:i}):w("header.services.open"),n[3]=i,n[4]=r,n[5]=w,n[6]=y):y=n[6];const m=r?"w-auto max-w-[20rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let x;n[7]!==m?(x=Ie(Fo,m),n[7]=m,n[8]=x):x=n[8];let b;n[9]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(B,{name:"server",className:"h-[18px] w-[18px]"}),n[9]=b):b=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 C;n[13]!==y||n[14]!==x||n[15]!==S?(C=s.jsx(Nt,{asChild:!0,children:s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":y,className:x,children:[b,S]})})}),n[13]=y,n[14]=x,n[15]=S,n[16]=C):C=n[16];let N;n[17]!==i||n[18]!==d||n[19]!==w?(N=w("header.services.tooltip.currentInstance",{current:i,toggle:d("toggle_services_menu")}),n[17]=i,n[18]=d,n[19]=w,n[20]=N):N=n[20];let k;n[21]!==N?(k=s.jsx(At,{children:s.jsx("p",{children:N})}),n[21]=N,n[22]=k):k=n[22];let R;n[23]!==C||n[24]!==k?(R=s.jsxs(Ct,{children:[C,k]}),n[23]=C,n[24]=k,n[25]=R):R=n[25];let I;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?(I=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(Lh,{embedded:!0,open:l,onOpenChange:qb,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]=I):I=n[35];let P;n[36]!==I?(P=s.jsx(Qs,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto p-0",children:I}),n[36]=I,n[37]=P):P=n[37];let T;return n[38]!==l||n[39]!==v||n[40]!==R||n[41]!==P?(T=s.jsxs(Ys,{open:l,onOpenChange:v,children:[R,P]}),n[38]=l,n[39]=v,n[40]=R,n[41]=P,n[42]=T):T=n[42],T}),kn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},zl=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,Gb=()=>{sn("ui.header.render");const{t}=vt(),e=Ne(ie=>ie.isSidebarOpen),n=Ne(ie=>ie.openContextOverview),r=Ne(ie=>ie.closeContextPanel),i=Ne(ie=>ie.shortcutOverrides),o=Ne(ie=>ie.sessionTabsEnabled),l=Yt(ie=>ie.getCurrentModel),a=tt(ie=>ie.getContextUsage),u=tt(ie=>!!ie.newSessionDraft?.open),d=tt(ie=>ie.currentSessionId),h=$h(d??""),f=va(d??""),p=Hu(d??""),g=Gs(sr(c.useCallback(ie=>{if(!d)return null;const Je=[...ie.activeSessions,...ie.archivedSessions].find(Vt=>Vt.id===d);if(!Je)return null;const yt=Je;return{title:Je.title??null,directory:yt.directory??null,created:Je.time?.created??null,slug:yt.slug??null,shareUrl:Je.share?.url??null,parentId:Je.parentID??null}},[d]))),w=qt(sr(ie=>{if(!ie.activeProjectId)return null;const Je=ie.projects.find(yt=>yt.id===ie.activeProjectId);return Je?{id:Je.id,path:Je.path,label:Je.label}:null})),v=c.useMemo(()=>{if(!w)return null;const ie=w.label?.trim();if(ie)return ie;const Je=w.path.split(/[\\/]/).filter(Boolean);return Je[Je.length-1]??null},[w]),y=dr(ie=>ie.loadSettings),{isMobile:m}=Wn(),x=c.useRef(null),[b,S]=c.useState(()=>typeof window>"u"?!1:yn()),C=c.useMemo(()=>Ur(),[]),N=Vd(),[k,R]=c.useState(!1),I=c.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),{usesFramelessChrome:P,side:T}=Iu(),E=c.useMemo(()=>{if(typeof window>"u")return null;const ie=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof ie=="number"&&Number.isFinite(ie)&&ie>0)return ie;if(typeof navigator>"u")return null;const Je=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Je)return null;const yt=Number.parseInt(Je[1],10),Vt=Number.parseInt(Je[2],10);return Number.isNaN(yt)?null:yt===10?Vt:yt},[]);mt.useEffect(()=>{typeof window>"u"||S(yn())},[]);const O=l(),W=O&&typeof O.limit=="object"&&O.limit!==null?O.limit:null,L=W&&typeof W.context=="number"?W.context:0,F=W&&typeof W.output=="number"?W.output:0,D=a(L,F),[j,A]=c.useState(null),M=!d||h;mt.useEffect(()=>{if(!d){A(ie=>ie===null?ie:null);return}if(D){A(ie=>Wh(ie,D)?ie:D);return}M&&A(ie=>ie===null?ie:null)},[D,d,M]);const[G,q]=c.useState(!1),[Z,le]=c.useState("Local"),[X,te]=c.useState(!0),[re,Se]=c.useState(!1),[ue,ye]=c.useState(null),[ve,be]=c.useState(!1),[_,oe]=c.useState(null),ce=c.useMemo(()=>$n(),[]),Q=Ne(ie=>ie.workStatusPanelVisible),me=Ne(ie=>ie.workStatusPanelEnabled),ke=Ne(ie=>ie.setWorkStatusPanelEnabled),fe=Ne(ie=>ie.workStatusPanelFits),De=Ne(ie=>ie.workStatusOverlayOpen),je=Ne(ie=>ie.setWorkStatusOverlayOpen),Re=me&&fe||De,Ce=c.useCallback(()=>{if(me&&!fe){je(!De);return}ke(!me)},[je,ke,De,me,fe]),Me=!ce&&!Q&&!!j,ae=c.useCallback(async()=>{if(!(typeof window>"u"||!b))try{if(Ho()){le("Local"),te(!0);return}te(!1);const ie=await Sd(),Je=hf(),yt=pf([gf(Je),...ie.hosts]);if(yt.id===xf){le("Local"),te(!0);return}le(vd(yt.label.trim()||"Instance"))}catch{le("Local"),te(!0)}},[b]);mt.useEffect(()=>(ae(),Go(()=>{ae()})),[ae]);const ee=c.useCallback(async()=>{if(X){ye(null),oe(null);return}be(!0),oe(null);try{const ie=new URLSearchParams({appType:"web",instanceMode:"remote",reportUsage:"false"}),Je=await bs(`/api/openchamber/update-check?${ie.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!Je.ok)throw new Error(`Server responded with ${Je.status}`);const yt=await Je.json();ye({available:yt.available??!1,version:yt.version,currentVersion:yt.currentVersion??"unknown",body:yt.body,nextSuggestedCheckInSec:typeof yt.nextSuggestedCheckInSec=="number"?yt.nextSuggestedCheckInSec:void 0,packageManager:yt.packageManager,updateCommand:yt.updateCommand})}catch(ie){ye(null),oe(ie instanceof Error?ie.message:t("header.services.remoteUpdate.error"))}finally{be(!1)}},[X,t]);c.useEffect(()=>{ye(null),oe(null),Se(!1)},[X,Z]),c.useEffect(()=>{if(!b||X)return;const ie=3e3,Je=3600*1e3;let yt=!1,Vt=null;const ws=$s=>{Vt=window.setTimeout(()=>{if(yt||typeof document<"u"&&document.visibilityState!=="visible"){ws(Je);return}ee().finally(()=>{yt||ws(Je)})},$s)};return ws(ie),()=>{yt=!0,Vt!==null&&window.clearTimeout(Vt)}},[ee,X,Z,b]);const K=c.useCallback(()=>{if(ue?.available){Se(!0);return}ee()},[ee,ue?.available]);zh(),c.useEffect(()=>{y()},[y]);const $=d?g??null:null,ne=c.useRef(null),[U,we]=c.useState(0);c.useEffect(()=>{if(!d){ne.current&&(ne.current=null,we(Vt=>Vt+1));return}if($){ne.current={sessionId:d,session:$,expiresAt:Date.now()+2e3};return}const ie=ne.current;if(!ie||ie.sessionId!==d)return;const Je=ie.expiresAt-Date.now();if(Je<=0){ne.current=null,we(Vt=>Vt+1);return}const yt=window.setTimeout(()=>{ne.current?.sessionId===d&&(ne.current=null),we(Vt=>Vt+1)},Je);return()=>{window.clearTimeout(yt)}},[d,$]);const he=(()=>{if($)return $;if(!d)return null;const ie=ne.current;return ie&&ie.sessionId===d&&ie.expiresAt>Date.now()?ie.session:null})(),Te=tt(ie=>d?ie.worktreeMetadata.get(d)?.path??"":""),Oe=tt(ie=>d?ie.worktreeMetadata.get(d)?.branch?.trim()??null:null),_e=Ud(ie=>d?ie.getAttachment(d):void 0),Ve=c.useMemo(()=>_e?Vh(_e,{pending:t("gitView.empty.worktreeSetupInProgress"),missing:t("sessions.sidebar.group.worktreeMissing")}):null,[t,_e]),z=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]),pe=c.useMemo(()=>kn(Te||""),[Te]),Ae=c.useMemo(()=>{const ie=typeof he?.directory=="string"?he.directory:"";return kn(ie||"")},[he?.directory]),Be=Sa(d??"",Ae),rt=tt(ie=>ie.newSessionDraft?.open?kn(ie.newSessionDraft.bootstrapPendingDirectory??ie.newSessionDraft.directoryOverride??""):""),Ge=tt(ie=>ie.newSessionDraft.target),ut=tt(ie=>ie.newSessionDraft.selectedProjectId),at=tt(ie=>ie.currentSessionDirectory),wt=is(ie=>ie.homeDirectory),pt=c.useMemo(()=>pe||Ae||rt,[rt,Ae,pe]),It=Ne(c.useCallback(ie=>{const Je=kn(pt||"");return Je?zl(ie.contextPanelByDirectory[Je]):null},[pt])),Pt=tt(ie=>{const Je=kn(pe||Ae||"");if(!Je)return null;for(const yt of ie.availableWorktreesByProject.values()){const ws=yt.find($s=>kn($s.path)===Je)?.branch?.trim();if(ws)return ws}return null}),de=Uh(pt||null)||Oe||Pt,We=u?Ge==="chat":Kh(Ae||at,wt),lt=!We&&!Q&&!!(v||de||!u&&z),H=c.useMemo(()=>{if(!d)return v??"OpenChamber";const ie=he?.title?.trim();return ie&&ie.length>0?ie:"Untitled Session"},[v,he?.title,d]),V=Kd(pt||void 0,{bootstrap:!1}),J=Hd(),ge=tt(ie=>ie.updateSessionTitle),Ee=tt(ie=>ie.shareSession),$e=tt(ie=>ie.unshareSession),st=tt(ie=>ie.archiveSessions),Ze=tt(ie=>ie.deleteSessions),[et,Ue]=c.useState(!1),[jt,ze]=c.useState(!1),xe=c.useRef(null),[bt,ht]=c.useState(""),[kt,Xe]=c.useState(null),Ke=c.useRef(null),Ye=c.useCallback(()=>{d&&(ht(he?.title?.trim()||H),Ue(!0))},[he?.title,d,H]),gt=c.useRef(Ye);gt.current=Ye;const Mt=c.useCallback(ie=>{ie&&(ie.focus(),ie.select())},[]);c.useEffect(()=>{if(ze(!1),Xe(null),d&&xe.current===d){xe.current=null,gt.current();return}Ue(!1),ht("")},[d]);const xt=c.useCallback(async()=>{if(!d)return;const ie=bt.trim();ie&&ie!==he?.title?.trim()&&await ge(d,ie),Ue(!1)},[he?.title,d,bt,ge]);c.useEffect(()=>{if(!et)return;const ie=Je=>{const yt=Je.target;(!yt||!Ke.current?.contains(yt))&&xt()};return document.addEventListener("mousedown",ie),()=>document.removeEventListener("mousedown",ie)},[et,xt]);const St=c.useCallback(ie=>{ie&&xn(ie).then(Je=>{Fe[Je.ok?"success":"error"](t(Je.ok?"sessions.sidebar.session.copyId.success":"sessions.sidebar.session.copyId.error"))}).catch(()=>Fe.error(t("sessions.sidebar.session.copyId.error")))},[t]),Tt=c.useCallback(async ie=>{if(!ie)return;const Je=await Ee(ie);if(Je?.share?.url){const yt=await xn(Je.share.url);Fe[yt.ok?"success":"warning"](t("sessions.sidebar.session.share.successTitle"),{description:t(yt.ok?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")});return}Fe.error(t("sessions.sidebar.session.share.error"))},[Ee,t]),Jt=c.useCallback(ie=>{ie&&xn(ie).then(Je=>{Fe[Je.ok?"success":"error"](t(Je.ok?"sessions.sidebar.session.menu.copied":"sessions.sidebar.session.share.copyUrlError"))}).catch(()=>Fe.error(t("sessions.sidebar.session.share.copyUrlError")))},[t]),Gt=c.useCallback(async ie=>{if(!ie)return;const Je=await $e(ie);Fe[Je?"success":"error"](t(Je?"sessions.sidebar.session.unshare.success":"sessions.sidebar.session.unshare.error"))},[t,$e]),$t=c.useCallback(async()=>{if(!d||!pt){Fe.error(t("sessions.sidebar.session.export.nothingToExport"));return}try{await J.loadCompleteHistory(d,pt)}catch{Fe.error(t("sessions.sidebar.session.export.failedLoadHistory"));return}const ie=hl(V.getState(),d).list;if(ie.length===0){Fe.error(t("sessions.sidebar.session.export.nothingToExport"));return}const Je=Gd(ie,he?.title??null),yt=qd(he?.title??null);await Qd(Je,yt)||Yd(Je,yt),Fe.success(t("sessions.sidebar.session.export.success"))},[he?.title,d,V,pt,J,t]),Kt=Xd(),Ht=c.useMemo(()=>Jd(Kt),[Kt]),Qt=c.useCallback(ie=>{d&&Ku({entry:ie,session:{id:d,title:he?.title,directory:Ae??pt},loadRecords:async()=>{if(!pt)return null;try{await J.loadCompleteHistory(d,pt)}catch{return null}return hl(V.getState(),d).list},onLoadFailed:()=>Fe.error(t("sessions.sidebar.session.export.failedLoadHistory"))})},[he?.title,d,V,pt,Ae,J,t]),Le=c.useCallback(ie=>Ht.map(Je=>s.jsxs(ie,{onClick:()=>Qt(Je),children:[s.jsx(Jr,{icon:Je.icon,iconSrc:Je.iconSrc,className:"mr-1 size-4"}),Je.action.label]},`${Je.guest.id}:${Je.action.id}`)),[Ht,Qt]),qe=f?.type==="busy"||f?.type==="retry",ot=c.useCallback(()=>{if(!d||!Ae||qe||p)return;const ie=Gs.getState().activeSessions,Je=ie.find(ws=>ws.id===d);if(!Je)return;const yt=[],Vt=[d];for(let ws=0;ws<Vt.length;ws+=1){const $s=Vt[ws];for(const vs of ie)vs.parentID===$s&&(yt.push(vs),Vt.push(vs.id))}Ji({kind:"quick",root:Je,descendants:yt,sourceDirectory:Ae,messages:Yi(t,{success:"sessions.sidebar.session.moveToWorktree.success",failure:"sessions.sidebar.session.moveToWorktree.failed"})})},[d,qe,p,Ae,t]),it=c.useCallback(async()=>{if(!kt)return;const ie=kt.action,Je=[kt.sessionId,...Nd(kt.sessionId,[],ie==="delete")];if(Xe(null),(ie==="archive"?await st(Je):await Ze(Je)).failedIds.length>0){Fe.error(t(ie==="archive"?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error"));return}Fe.success(t(ie==="archive"?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"))},[st,Ze,kt,t]),He=Ne(ie=>ie.openGuestPageId),Bt=Zd(ie=>ie.guests.find(Je=>Je.id===He)),ts=Ne(ie=>ie.isScheduledTasksDialogOpen),es=Ne(ie=>ie.isArchivePageOpen),ss=Ne(ie=>ie.worktreesPageProjectId),ds=Ne(ie=>ie.isMultiRunLauncherOpen),Js=qt(ie=>{if(!ss)return null;const Je=ie.projects.find(yt=>yt.id===ss);return Je?.label?.trim()||Je?.path?.split("/").pop()||null}),us=c.useMemo(()=>Bt?{title:Bt.pageTitle??Bt.name,subtitle:null}:ts?{title:t("sessions.scheduledTasks.dialog.title"),subtitle:null}:es?{title:t("sessions.archivePage.title"),subtitle:null}:ss?{title:t("sessions.worktreesPage.title",{project:Js??""}),subtitle:null}:ds?{title:t("sessions.sidebar.header.actions.newMultiRun"),subtitle:null}:null,[Bt,es,ds,ts,t,ss,Js]),Os=c.useMemo(()=>kn(pt||w?.path||""),[w?.path,pt]),ns=xb(),Cs=ka(ie=>ie.planModeEnabled),Zs=tt(ie=>ie.isSessionPlanAvailable),Ns=Cs&&d?Zs(d):!1,Ts=c.useRef("");c.useEffect(()=>{if(!Cs||!d)return;const ie=`${d||"none"}:${Ae||"none"}:${he?.created||0}:${he?.slug||"none"}`;Ts.current!==ie&&(Ts.current=ie)},[Cs,Ns,he?.slug,he?.created,d,Ae]);const Lt=c.useCallback(()=>{Fn("desktop_open_draft_mini_chat_window",{directory:We?"":rt,projectId:We?null:ut,apiBaseUrl:Pn(),clientToken:Kr()}).catch(ie=>{console.warn("[header] failed to open draft mini chat window",ie)})},[rt,ut,We]),Wt=c.useCallback(()=>{if(u){Lt();return}d&&Fn("desktop_open_session_mini_chat_window",{sessionId:d,directory:Ae||kn(at||"")||pe,apiBaseUrl:Pn(),clientToken:Kr()}).catch(ie=>{console.warn("[header] failed to open session mini chat window",ie)})},[d,Lt,u,at,Ae,pe]),Xt=c.useCallback(()=>{const ie=kn(pt||"");if(!ie)return;const Je=Ne.getState().contextPanelByDirectory[ie];if(zl(Je)==="context"){r(ie);return}n(ie)},[r,n,pt]),fs=It==="context",cs=Fo,Es=c.useMemo(()=>b&&I&&!k?"88px":N?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!b||P)&&!ce?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[b,k,I,N,ce,P]);mt.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",Es)},[Es]);const Ss=e?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",hs=e?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";mt.useEffect(()=>{if(!b||!I){R(!1);return}let ie=!1;const Je=async()=>{try{const Vt=await Fn("desktop_is_window_fullscreen");ie||R(Vt===!0)}catch{ie||R(!1)}},yt=()=>{Je()};return Je(),window.addEventListener("openchamber:window-resized",yt),()=>{ie=!0,window.removeEventListener("openchamber:window-resized",yt)}},[b,I]);const Tn=c.useMemo(()=>!b||!I||E===null?"":E>=26?"h-12":E<=15?"h-14":"",[b,I,E]),En=c.useMemo(()=>{if(!(b&&!P||ce)&&!(P&&T==="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))"}},[b,ce,P,T]),se=c.useCallback(()=>{if(typeof document>"u")return;const ie=x.current?.getBoundingClientRect().height;ie&&document.documentElement.style.setProperty("--oc-header-height",`${ie}px`)},[]);mt.useEffect(()=>{if(typeof window>"u")return;se();const ie=x.current;if(!ie||typeof ResizeObserver>"u")return()=>{};let Je=0;const yt=()=>{Je||(Je=requestAnimationFrame(()=>{Je=0,se()}))},Vt=new ResizeObserver(yt);return Vt.observe(ie),window.addEventListener("resize",yt),window.addEventListener("orientationchange",yt),()=>{Je&&cancelAnimationFrame(Je),Vt.disconnect(),window.removeEventListener("resize",yt),window.removeEventListener("orientationchange",yt)}},[se]),mt.useEffect(()=>{se()},[se,m,Tn]);const Qe=c.useCallback(async ie=>{const Je=ie.target;Je.closest(".app-region-no-drag")||Je.closest("button, a, input, select, textarea")||ie.button===0&&b&&await bf()},[b]),ct=c.useCallback(ie=>Jn(Zr(ie,i)),[i]);Hh({rename_current_session:()=>{if(!d||m)return!1;Ye()},toggle_services_menu:()=>{if(G){q(!1);return}q(!0),ae()}});const Dt=s.jsxs(s.Fragment,{children:[ns?s.jsx(pb,{projectRef:ns.projectRef,directory:ns.directory,className:"mr-2"}):null,s.jsx(Vx,{directory:Os,className:"mr-1"}),b?s.jsx(Hb,{isDesktopApp:b,currentInstanceLabel:Z,currentInstanceIsLocal:X,isDesktopServicesOpen:G,setIsDesktopServicesOpen:q,refreshCurrentInstanceLabel:ae,shortcutLabel:ct,remoteUpdateInfo:ue,remoteUpdateChecking:ve,remoteUpdateError:_,onOpenRemoteUpdate:K}):null]}),zt=C&&(u||!!d),Ft=c.useCallback(({session:ie,open:Je,isActive:yt,select:Vt,closeOtherTabs:ws,components:$s})=>{const{Item:vs,Separator:kr}=$s,no=ie.share?.url??null,ri=yt&&!ce&&!We&&he&&!he.parentId;return s.jsxs(s.Fragment,{children:[s.jsxs(vs,{onClick:()=>{yt||Vt(),xe.current=ie.id},children:[s.jsx(B,{name:"pencil-ai",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.rename")]}),s.jsx(Qi,{sessionID:ie.id,directory:ie.directory,open:Je,Item:vs}),s.jsxs(vs,{onClick:()=>St(ie.id),children:[s.jsx(B,{name:"file-copy",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.copyId")]}),s.jsx(kr,{}),no?s.jsxs(s.Fragment,{children:[s.jsxs(vs,{onClick:()=>Jt(no),children:[s.jsx(B,{name:"file-copy",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(vs,{onClick:()=>{Gt(ie.id)},children:[s.jsx(B,{name:"link-unlink-m",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(vs,{onClick:()=>{Tt(ie.id)},children:[s.jsx(B,{name:"share-2",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.share")]}),yt?s.jsxs(vs,{onClick:()=>{$t()},children:[s.jsx(B,{name:"download",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.exportMarkdown")]}):null,yt?Le(vs):null,ri?s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(vs,{disabled:!Ae||qe||p,onClick:ot,className:"w-full",children:[s.jsx(B,{name:"folder-shared",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(At,{side:"right",className:"max-w-72",children:t(p?"sessions.sidebar.session.moveToWorktree.tooltipMoving":qe?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(kr,{}),s.jsxs(vs,{onClick:ws,children:[s.jsx(B,{name:"close-circle",className:"mr-1 size-4"}),t("header.sessionTabs.closeOtherTabs")]}),s.jsx(kr,{}),s.jsxs(vs,{onClick:()=>Xe({action:"archive",sessionId:ie.id}),children:[s.jsx(B,{name:"inbox-archive",className:"mr-1 size-4"}),t("sessions.sidebar.bulkActions.archive")]}),s.jsxs(vs,{className:"text-destructive focus:text-destructive",onClick:()=>Xe({action:"delete",sessionId:ie.id}),children:[s.jsx(B,{name:"delete-bin",className:"mr-1 size-4"}),t("sessions.sidebar.bulkActions.delete")]})]})},[St,Jt,he,$t,We,qe,p,ce,ot,Le,Ae,Tt,t,Gt]),Et=()=>s.jsxs("div",{onMouseDown:Qe,className:Ie("app-region-drag relative flex h-12 select-none items-center",P&&T==="right"?"pr-0":"pr-3",Tn),style:En,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:Ss}}),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:hs}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[us?s.jsxs(s.Fragment,{children:[s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx(dt,{variant:"ghost",size:"icon",className:"app-region-no-drag mr-1 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-label":t("header.mainSurface.backToChat"),onClick:()=>Ne.getState().closeMainSurfaces(),children:s.jsx(B,{name:"arrow-left",className:"size-[18px]"})})}),s.jsx(At,{side:"bottom",children:t("header.mainSurface.backToChat")})]}),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:us.title}),us.subtitle?s.jsx("span",{className:"truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75 max-w-full",children:us.subtitle}):null]})]}):ce||!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:[Be?s.jsx(B,{name:"loader-4",className:"mr-1 size-3 shrink-0 animate-spin text-primary","aria-label":t("sessions.aiRename.generating")}):null,e?null:s.jsx(Ml,{align:"start",children:s.jsx("button",{type:"button",className:cs,"aria-label":t("sessions.switcher.openAria"),children:s.jsx(B,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsxs("div",{className:"flex min-w-0 flex-col justify-center px-1",children:[et?s.jsxs("form",{ref:Ke,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onPointerDown:ie=>ie.stopPropagation(),onSubmit:ie=>{ie.preventDefault(),xt()},children:[s.jsx("input",{ref:Mt,value:bt,onChange:ie=>ht(ie.target.value),onKeyDown:ie=>Pi(ie,()=>Ue(!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(B,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>Ue(!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(B,{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"):H}),lt?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,de?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(B,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:de})]}):null,!u&&z?s.jsxs("span",{className:Ie("inline-flex min-w-0 items-center gap-0.5",z==="attention"||z==="invalid"||z==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(B,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Ve})]}):null]}):null]}),s.jsx("div",{className:Ie("flex h-[18px] shrink-0 items-center justify-center",lt?"self-start":"self-center"),children:d&&!u&&!et?s.jsxs(Ys,{open:jt,onOpenChange:ze,onOpenChangeComplete:ie=>{!ie&&xe.current&&xe.current===d&&(xe.current=null,Ye())},children:[s.jsx(qs,{asChild:!0,children:s.jsx(dt,{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(B,{name:"more",className:"size-4"})})}),s.jsxs(Qs,{align:"end",className:"min-w-[190px]",children:[s.jsxs(Ut,{onClick:()=>{xe.current=d},children:[s.jsx(B,{name:"pencil-ai",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.rename")]}),s.jsx(Qi,{sessionID:d,directory:Ae,open:jt,Item:Ut}),s.jsxs(Ut,{onClick:()=>d&&St(d),children:[s.jsx(B,{name:"file-copy",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.copyId")]}),s.jsx(zs,{}),he?.shareUrl?s.jsxs(s.Fragment,{children:[s.jsxs(Ut,{onClick:()=>Jt(he?.shareUrl),children:[s.jsx(B,{name:"file-copy",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(Ut,{onClick:()=>{d&&Gt(d)},children:[s.jsx(B,{name:"link-unlink-m",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Ut,{onClick:()=>{d&&Tt(d)},children:[s.jsx(B,{name:"share-2",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.share")]}),s.jsxs(Ut,{onClick:()=>{$t()},children:[s.jsx(B,{name:"download",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.exportMarkdown")]}),Le(Ut),!ce&&!We&&he&&!he.parentId?s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(Ut,{disabled:!Ae||qe||p,onClick:ot,className:"w-full",children:[s.jsx(B,{name:"folder-shared",className:"mr-1 size-4"}),t("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(At,{side:"right",className:"max-w-72",children:t(p?"sessions.sidebar.session.moveToWorktree.tooltipMoving":qe?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(zs,{}),s.jsxs(Ut,{onClick:()=>{d&&Xe({action:"archive",sessionId:d})},children:[s.jsx(B,{name:"inbox-archive",className:"mr-1 size-4"}),t("sessions.sidebar.bulkActions.archive")]}),s.jsxs(Ut,{className:"text-destructive focus:text-destructive",onClick:()=>{d&&Xe({action:"delete",sessionId:d})},children:[s.jsx(B,{name:"delete-bin",className:"mr-1 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(Ml,{align:"start",children:s.jsx("button",{type:"button",className:cs,"aria-label":t("sessions.switcher.openAria"),children:s.jsx(B,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsx(vb,{renderMenu:Ft,suppressActiveTabControls:et,onMenuOpenChangeComplete:ie=>{!ie&&xe.current&&xe.current===d&&(xe.current=null,Ye())},children:s.jsx("div",{className:"flex min-w-0 flex-col justify-center",children:et?s.jsxs("form",{ref:Ke,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onPointerDown:ie=>ie.stopPropagation(),onSubmit:ie=>{ie.preventDefault(),xt()},children:[s.jsx("input",{ref:Mt,value:bt,onChange:ie=>ht(ie.target.value),onKeyDown:ie=>Pi(ie,()=>Ue(!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(B,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>Ue(!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(B,{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"):H})})})]}),us||ce||!o?s.jsx("div",{className:"flex-1"}):null,s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Me&&j?s.jsx(ux,{reading:mx(j),contextLimit:j.contextLimit,outputLimit:j.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:Xt,pressed:fs,className:zt?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,s.jsx(Kb,{visible:zt,title:t(u?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:t(u?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:Wt,className:Ie(cs,"mr-1"),Icon:"picture-in-picture-2"}),ce?null:s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button","data-work-status-toggle":"true","aria-pressed":Re,"aria-label":t("header.workStatusPanel.toggleAria"),onClick:Ce,className:Ie(Fo,"mr-1",Re?"text-foreground":"text-muted-foreground/50"),children:s.jsx(B,{name:"list-indefinite",className:"h-[18px] w-[18px]"})})}),s.jsx(At,{side:"bottom",children:t(me&&!fe?De?"header.workStatusPanel.hide":"header.workStatusPanel.showOverlay":me?"header.workStatusPanel.hide":"header.workStatusPanel.show")})]}),Dt,s.jsx(Tu,{visible:P&&T==="right",position:"right"})]})]})]});return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:x,className:"header-safe-area relative z-10 bg-background",style:{"--padding-scale":"1"},children:Et()}),s.jsx(Ds,{open:kt!==null,onOpenChange:ie=>{ie||Xe(null)},children:s.jsxs(Is,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Xs,{children:[s.jsx(_s,{children:kt?.action==="delete"?t("sessions.sidebar.dialogs.deleteSession.title"):t("sessions.sidebar.dialogs.archiveSession.title")}),s.jsx(Ls,{children:kt?.action==="delete"?t("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:H}):t("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:H})})]}),s.jsxs(wn,{children:[s.jsx(dt,{variant:"outline",size:"sm",onClick:()=>Xe(null),children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(dt,{variant:"destructive",size:"sm",onClick:()=>{it()},children:kt?.action==="delete"?t("sessions.sidebar.bulkActions.delete"):t("sessions.sidebar.bulkActions.archive")})]})]})}),s.jsx(Ad,{open:re,onOpenChange:Se,info:ue,downloading:!1,downloaded:!1,progress:null,error:_,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function qb(){}const Vl=280,Ul=168,Kl=500,Qb=({isOpen:t,isMobile:e,children:n,className:r,topBar:i})=>{const{t:o}=vt(),l=Ne(k=>k.sidebarWidth),a=Ne(k=>k.setSidebarWidth),[u,d]=c.useState(!1),h=c.useRef(0),f=c.useRef(l||Vl),p=c.useRef(null),g=c.useRef(null),w=c.useRef(null),v=c.useCallback(k=>Math.min(Kl,Math.max(Ul,k)),[]),y=c.useCallback(k=>{const R=w.current;R&&(R.style.width=`${k}px`,R.style.minWidth=`${k}px`,R.style.maxWidth=`${k}px`,R.style.setProperty("--oc-left-sidebar-width",`${k}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(Kl,Math.max(Ul,l||Vl)),x=t?m:0,b=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}g.current=k.pointerId,d(!0),h.current=k.clientX,f.current=x,p.current=x,y(x),k.preventDefault()}},S=k=>{if(e||!u||g.current!==k.pointerId)return;const R=k.clientX-h.current,I=v(f.current+R);p.current!==I&&(p.current=I,y(I))},C=k=>{if(g.current!==k.pointerId||e)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const R=v(p.current??x);g.current=null,p.current=null,d(!1),a(R)},N=u?p.current??x:x;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:`${N}px`,minWidth:`${N}px`,maxWidth:`${N}px`,"--oc-left-sidebar-width":`${u?N: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||x===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:b,onPointerMove:S,onPointerUp:C,onPointerCancel:C,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(Sn,{outerClassName:"flex-1 min-h-0",disableHorizontal:!0,children:s.jsx(Bs,{children:n})})]})]})},Yb=()=>{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},Hl="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-ring hover:bg-interactive-hover transition-colors",Xb=()=>{const t=nt.c(32),{t:e}=vt(),n=Ne(Jb),r=Ne(Zb),i=c.useRef(null),o=Jn(Zr("toggle_sidebar",r)),{usesFramelessChrome:l,side:a}=Iu(),u=ty;let d,h;t[0]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{if(typeof document>"u")return;const E=i.current;if(!E)return;const O=()=>{const L=Math.max(E.getBoundingClientRect().width,E.scrollWidth);document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(L)}px`)};if(O(),typeof ResizeObserver>"u")return;const W=new ResizeObserver(O);return W.observe(E),()=>{W.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(Tu,{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(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,"aria-label":e("header.actions.openAppMenuAria"),className:Ie(Hl,"shrink-0"),children:s.jsx(B,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(At,{children:s.jsx("p",{children:e("header.actions.openAppMenu")})})]}):null,t[6]=e,t[7]=l,t[8]=v):v=t[8];const y=Ct;let m;t[9]!==e?(m=e("header.actions.openSessionsAria"),t[9]=e,t[10]=m):m=t[10];let x,b;t[11]===Symbol.for("react.memo_cache_sentinel")?(x=Ie(Hl,"shrink-0"),b=s.jsx(B,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[11]=x,t[12]=b):(x=t[11],b=t[12]);let S;t[13]!==m||t[14]!==n?(S=s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":m,className:x,children:b})}),t[13]=m,t[14]=n,t[15]=S):S=t[15];const C=At,N=e("header.actions.openSessionsWithShortcut",{shortcut:o});let k;t[16]!==N?(k=s.jsx("p",{children:N}),t[16]=N,t[17]=k):k=t[17];let R;t[18]!==C||t[19]!==k?(R=s.jsx(C,{children:k}),t[18]=C,t[19]=k,t[20]=R):R=t[20];let I;t[21]!==y||t[22]!==S||t[23]!==R?(I=s.jsxs(y,{children:[S,R]}),t[21]=y,t[22]=S,t[23]=R,t[24]=I):I=t[24];let P;t[25]!==I||t[26]!==w||t[27]!==v?(P=s.jsxs("div",{ref:i,className:g,children:[w,v,I]}),t[25]=I,t[26]=w,t[27]=v,t[28]=P):P=t[28];let T;return t[29]!==P||t[30]!==p?(T=s.jsx("div",{className:f,style:p,children:P}),t[29]=P,t[30]=p,t[31]=T):T=t[31],T};function Jb(t){return t.toggleSidebar}function Zb(t){return t.shortcutOverrides}function ey(t){console.warn("[titlebar] failed to open app menu",t)}function ty(t){const e=t.currentTarget.getBoundingClientRect();Fn("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(ey)}function Ju(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(B,{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 Gl=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function sy(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([Gh(t),qh(t)]).catch(ny);if(u)return;const f=Gl(d),p=Gl(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 ny(){return["",""]}const ql="flex h-6 w-6 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",ry=async(t,e)=>{if(t)return t.authActivate(e);const n=await bs("/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},Ql=({className:t})=>{const{t:e}=vt(),{github:n}=jn(),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 ry(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(B,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"});return h.length<=1?s.jsx("div",{className:Ie(ql,t),title:f,children:p}):s.jsxs(Ys,{children:[s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie(ql,"p-0 hover:ring-2 hover:ring-primary/40 disabled:opacity-50",t),title:f,disabled:o,children:p})}),s.jsxs(Qs,{align:"end",className:"w-64",children:[s.jsx(Br,{className:"typography-ui-header font-semibold text-foreground",children:e("header.github.accountsTitle")}),s.jsx(zs,{}),h.map(g=>{const w=g.user,v=!!g.current,y=g.source==="gh-cli"?e("header.github.accountSource.cli"):e("header.github.accountSource.oauth");return s.jsxs(Ut,{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(B,{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:y})]}):null]}),v?s.jsx(B,{name:"check",className:"h-4 w-4 text-primary"}):null]},g.id)})]})]})};class ti 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 si="/api/walkthrough",Zu=t=>/^application\/(?:[\w.+-]+\+)?json\b/i.test(t.headers.get("content-type")??""),em=()=>new ti("This OpenChamber server has no walkthrough API",{code:"server-unsupported"}),oy=t=>!Zu(t)&&(t.ok||t.status===404),$a=async(t,e)=>{if(oy(t))throw em();const n=await t.json().catch(()=>null);throw new ti(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})},tm=async t=>{if(!Zu(t))throw em();try{return await t.json()}catch{throw new ti("The server returned a malformed walkthrough response")}};async function iy(t,e,n={}){const r=await bs(si,{query:{directory:t,source:JSON.stringify(e),...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}},signal:n.signal});return r.ok?tm(r):$a(r,"Failed to load walkthrough")}async function ay(t,e,n={}){const r=await bs(`${si}/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?tm(r):$a(r,"Failed to generate walkthrough")}async function ly(t,e){const n=await bs(`${si}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e})});n.ok||await $a(n,"Failed to cancel walkthrough generation")}async function cy(t,e,n){const r=await bs(`${si}/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 Ar={status:"idle",stage:null,result:null,readiness:null,error:null},dy=t=>t.kind==="working-tree"?`working-tree:${t.scope}`:t.kind==="branch"?`branch:${t.baseRef}...${t.headRef}`:t.kind==="commit"?`commit:${t.hash}`:t.sourceRepo?`pr:${t.sourceRepo.owner}/${t.sourceRepo.repo}:${t.number}`:`pr:${t.number}`,Rn=(t,e)=>`${ls()}\0${t}\0${dy(e)}`,Yl=t=>t instanceof ti?{message:t.message,code:t.code,model:t.model,requiredChars:t.requiredChars,availableChars:t.availableChars}:{message:t instanceof Error?t.message:"Something went wrong"},an=new Map,Pr=new Map,uy=1e3,my=or()(Lu((t,e)=>({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{},selectLanguage:(n,r,i)=>{const o=Rn(n,r);t(l=>{const a={...l.selectedLanguage};return i?a[o]=i:delete a[o],{selectedLanguage:a}})},getSelectedLanguage:(n,r)=>e().selectedLanguage[Rn(n,r)],selectModel:(n,r,i)=>{const o=Rn(n,r);t(l=>{const a={...l.selectedModel};return i?a[o]=i:delete a[o],{selectedModel:a}})},getSelectedModel:(n,r)=>e().selectedModel[Rn(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[Rn(n,r)]??Ar,load:async(n,r,i={})=>{if(!n)return;const o=Rn(n,r);if(e().entries[o]?.status==="generating")return;an.get(o)?.abort();const a=new AbortController;an.set(o,a),t(u=>({entries:{...u.entries,[o]:{...u.entries[o]??Ar,status:"loading",error:null}}}));try{const u=await iy(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]??Ar,status:"error",stage:null,error:Yl(u)}}}))}finally{an.get(o)===a&&an.delete(o)}},generate:async(n,r,i={})=>{if(!n)return;const o=Rn(n,r);an.get(o)?.abort();const l=new AbortController;an.set(o,l),t(u=>({entries:{...u.entries,[o]:{...u.entries[o]??Ar,status:"generating",stage:"collecting",error:null}}}));const a=()=>{const u=Pr.get(o);u!==void 0&&(clearInterval(u),Pr.delete(o))};a(),Pr.set(o,setInterval(()=>{cy(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(()=>{})},uy));try{const u=await ay(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]??Ar,status:"error",stage:null,error:Yl(u)}}}))}finally{a(),an.get(o)===l&&an.delete(o)}},cancel:(n,r)=>{const i=Rn(n,r);ly(n,r).catch(()=>{}),an.get(i)?.abort(),an.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 an.values())n.abort();an.clear();for(const n of Pr.values())clearInterval(n);Pr.clear(),t({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{}})}}),{name:"walkthrough-store"})),fy="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)]",hy=3e4,Xl=20,sm=(t,e)=>JSON.stringify([ls(),t,e]),py=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}},Jl=()=>({result:null,hasCheckDetails:!1,fetchedAt:0,isLoading:!1,error:null}),oo=new Map,gy=t=>{const e=Object.entries(t);return e.length<=Xl?t:Object.fromEntries(e.sort(([,n],[,r])=>r.fetchedAt-n.fetchedAt).slice(0,Xl))},Zl=or()((t,e)=>({entries:{},ensure:async(n,r,i,o)=>{const l=sm(r,i),a=o?.includeCheckDetails??!1,u=e().entries[l],d=u&&u.result&&Date.now()-u.fetchedAt<hy&&(u.hasCheckDetails||!a);if(!o?.force&&d)return u.result;const h=`${l}::${a?"details":"plain"}`,p=oo.get(`${l}::details`)??(a?null:oo.get(h));if(p&&!o?.force)return p;const g=(async()=>{t(w=>({entries:{...w.entries,[l]:{...w.entries[l]??Jl(),isLoading:!0,error:null}}}));try{const w=await n.prContext(r,i,{includeDiff:!1,includeCheckDetails:a,sourceRepo:o?.sourceRepo??null});return t(v=>({entries:gy({...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(y=>({entries:{...y.entries,[l]:{...y.entries[l]??Jl(),isLoading:!1,error:v}}})),null}finally{oo.delete(h)}})();return oo.set(h,g),g},invalidate:(n,r)=>{t(i=>{const o={};for(const[l,a]of Object.entries(i.entries)){const u=py(l);u&&u.directory===n&&(r==null||u.number===r)||(o[l]=a)}return{entries:o}})}})),xy=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}:{}}},by=35e3,ui=(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`},mi=t=>{const e=typeof t=="string"?t.toLowerCase():"";return!!e&&!["success","neutral","skipped"].includes(e)},ec=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"}},yy=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"},wy=[2e3,5e3],Sy=600,tc=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),On=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):""},vy=(t,e)=>{const n=On(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},jy=(t,e)=>`${t}::${e}`,Wa=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},fi=(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=Wa(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)},ky=t=>t.startsWith("pr-"),Cy=(t,e)=>{const n=Wa(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=>!ky(l.name)).forEach(l=>o(l)),t.forEach(l=>o(l)),i},Dr=new Map,io=qo;function Ny(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 Ay=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:i=[],remoteBranches:o=[],onGeneratedDescription:l})=>{const{t:a}=vt(),u=Ne(se=>se.timeFormatPreference),{github:d}=jn(),h=Dn(se=>se.status),f=Dn(se=>se.hasChecked),p=Ne(se=>se.setSettingsDialogOpen),g=Ne(se=>se.setSettingsPage),w=tt(se=>se.currentSessionId),v=tt(se=>!!se.newSessionDraft?.open),{isMobile:y,hasTouchInput:m,screenWidth:x}=Wn(),b=Ne(se=>se.openContextSurface),S=my(se=>se.requestSource),C=!y&&x>=768&&!$n(),N=c.useCallback(()=>{g("integrations"),p(!0)},[p,g]),k=c.useMemo(()=>jy(t,e),[t,e]),R=c.useMemo(()=>Dr.get(k)??null,[k]),I=tn(se=>se.ensureEntry),P=tn(se=>se.setParams),T=tn(se=>se.startWatching),E=tn(se=>se.stopWatching),O=tn(se=>se.refresh),W=tn(se=>se.updateStatus),[L,F]=c.useState(()=>R?.title??tc(e)),[D,j]=c.useState(()=>R?.body??""),[A,M]=c.useState(()=>R?.draft??!1),[G,q]=c.useState(()=>R?.additionalContext??""),[Z,le]=c.useState(()=>{const se=typeof R?.targetBaseBranch=="string"?On(R.targetBaseBranch):"";return se||On(n)}),[X,te]=c.useState("squash"),[re,Se]=c.useState(!1),[ue,ye]=c.useState(!1),[ve,be]=c.useState(!1),[_,oe]=c.useState(!1),[ce,Q]=c.useState(!1),[me,ke]=c.useState(!1),[fe,De]=c.useState(null),[je,Y]=c.useState(""),[Re,Ce]=c.useState(""),[Me,ae]=c.useState(!1),[ee,K]=c.useState(!1),[$,ne]=c.useState(()=>fi(i,{selectedRemoteName:R?.selectedRemoteName,trackingBranch:r})),[U,we]=c.useState(!1),{detectedUpstream:he,upstreamBranches:Te}=Ny(t,d);c.useEffect(()=>{we(!1)},[t]);const Oe=i.some(se=>se.name==="upstream"),Ve=!!(t&&e&&n&&(e!==n||(Oe||he!==null))),z=c.useMemo(()=>Yo(t,e,$?.name??null),[t,e,$?.name]),pe=tn(se=>se.entries[z]),Ae=pe?.isLoading??!1,Be=pe?.status??null,rt=pe?.error??null,Ge=pe?.isInitialStatusResolved??!1,ut=c.useMemo(()=>{const se=U?null:$?.name?.trim()||null,Qe=new Set;for(const zt of o){const Ft=vy(zt,se);!Ft||Ft==="HEAD"||Qe.add(Ft)}if(U)for(const zt of Te)zt&&zt!=="HEAD"&&Qe.add(zt);const ct=On(n);ct&&ct!=="HEAD"&&Qe.add(ct);const Dt=On(Z);return Dt&&Dt!=="HEAD"&&Qe.add(Dt),Array.from(Qe).sort((zt,Ft)=>zt.localeCompare(Ft))},[n,o,$?.name,Z,Te,U]);c.useEffect(()=>{if(i.length===0){$&&ne(null);return}(!$||!i.some(se=>se.name===$.name))&&ne(fi(i,{selectedRemoteName:R?.selectedRemoteName,trackingBranch:r}))},[R?.selectedRemoteName,i,$,r]),c.useEffect(()=>{const se=On(n);if(!Z&&se){le(se);return}if(ut.length!==0&&!ut.includes(Z)){const Qe=ut.includes(se)?se:ut[0];Qe&&le(Qe)}},[ut,n,Z]);const[at,wt]=c.useState(()=>R?.activeSegment??"overview"),[pt,It]=c.useState(new Set),[Pt,Rt]=c.useState(new Set),de=c.useRef(new Set),We=c.useRef(null),lt=c.useRef(!1),H=c.useRef(new Set),V=c.useRef([]);c.useEffect(()=>{he&&!Oe&&we(!0)},[he,Oe]),c.useEffect(()=>{U&&he?.defaultBranch&&le(he.defaultBranch)},[U,he?.defaultBranch]);const J=Be?.pr??null,ge=J?.state==="merged"||J?.state==="closed",Ee=ge?null:J,$e=Ee?sm(t,Ee.number):null,st=Zl(se=>$e?se.entries[$e]:void 0),Ze=Zl(se=>se.ensure),et=st?.result??null,Ue=st?.isLoading??!1,jt=c.useCallback(se=>{wt(se);const Qe=Dr.get(k);Qe&&Dr.set(k,{...Qe,activeSegment:se})},[k]);c.useEffect(()=>{!Ee||!d?.prContext||at==="overview"||Ze(d,t,Ee.number,{includeCheckDetails:at==="checks",sourceRepo:Be?.repo??null})},[at,t,Ze,d,Ee,Be?.repo]);const ze=Be?.checks??null,xe=(ze?.pending??0)>0,bt=et?.checkRuns??null,ht=et?.fetchedAt;c.useEffect(()=>{if(!bt||bt.length===0)return;const se=xy(bt);W(z,Qe=>{if(!Qe?.pr||typeof ht=="number"&&typeof Qe.fetchedAt=="number"&&ht<Qe.fetchedAt)return Qe;const ct=Qe.checks;return ct&&ct.state===se.state&&ct.total===se.total&&ct.success===se.success&&ct.failure===se.failure&&ct.pending===se.pending&&ct.inProgress===se.inProgress&&ct.queued===se.queued&&ct.startedAt===se.startedAt?Qe:{...Qe,checks:se,...typeof ht=="number"?{fetchedAt:ht}:{}}})},[bt,ht,z,W]),c.useEffect(()=>{if(at!=="checks"||!xe||!J||!d?.prContext)return;const se=window.setInterval(()=>{Ze(d,t,J.number,{includeCheckDetails:!0,sourceRepo:Be?.repo??null,force:!0})},by);return()=>window.clearInterval(se)},[at,xe,t,Ze,d,J,Be?.repo]);const[kt,Xe]=c.useState(()=>Date.now());c.useEffect(()=>{if(!xe)return;Xe(Date.now());const se=window.setInterval(()=>Xe(Date.now()),3e4);return()=>window.clearInterval(se)},[xe]);const Ke=J?`${t}#${J.number}`:null,Ye=!!(Ke&&fe===Ke);c.useEffect(()=>{if(!d?.prContext||!J||typeof J.body=="string"&&J.body.length>0)return;const se=`${t}#${J.number}`;if(de.current.has(se))return;de.current.add(se),De(se);let Qe=!1;return Ze(d,t,J.number,{sourceRepo:Be?.repo??null}).then(ct=>{if(Qe)return;const Dt=ct?.pr;Dt&&W(z,zt=>!zt?.pr||zt.pr.number!==J.number?zt:{...zt,pr:{...zt.pr,body:Dt.body||""}})}).catch(()=>{}).finally(()=>{Qe||De(ct=>ct===se?null:ct)}),()=>{Qe=!0}},[t,Ze,d,J,z,Be?.repo,W]),c.useEffect(()=>{if(!J){ke(!1),Y(""),Ce(""),We.current=null;return}const se=We.current!==null&&We.current!==J.number;se&&ke(!1),(!me||se)&&(Y(J.title||""),Ce(J.body||"")),We.current=J.number},[me,J]);const gt=c.useCallback(se=>{if(!se)return"";const Qe=Date.parse(se);return Number.isFinite(Qe)?eu(Qe,u,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):se},[u]),Mt=c.useMemo(()=>{const se=h?.user?.login;return typeof se=="string"?se.trim():""},[h]),xt=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)]",[]),St=c.useCallback(se=>{const Qe=Mt.toLowerCase(),ct=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return se.replace(ct,(Dt,zt,Ft)=>{const Et=`@${Ft}`,ys=Ft.toLowerCase();return`${zt}[${Et}](https://github.com/${ys}${Qe&&ys===Qe?"?oc-self-mention=1":""})`})},[Mt]),Tt=c.useMemo(()=>{const se=(et?.issueComments??[]).map(Dt=>({id:`issue-${Dt.id}`,body:Dt.body||"",authorName:Dt.author?.name||Dt.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:Dt.author?.login||null,avatarUrl:Dt.author?.avatarUrl||null,createdAt:Dt.createdAt,context:a("gitView.pr.comments.generalContext"),path:null,line:null})),Qe=(et?.reviewComments??[]).map(Dt=>({id:`review-${Dt.id}`,body:Dt.body||"",authorName:Dt.author?.name||Dt.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:Dt.author?.login||null,avatarUrl:Dt.author?.avatarUrl||null,createdAt:Dt.createdAt,context:a("gitView.pr.comments.reviewContext"),path:Dt.path||null,line:Dt.line??null})),ct=[...se,...Qe];return ct.sort((Dt,zt)=>{const Ft=Dt.createdAt?Date.parse(Dt.createdAt):0,Et=zt.createdAt?Date.parse(zt.createdAt):0,ys=Number.isFinite(Ft)?Ft:0,ie=Number.isFinite(Et)?Et:0;return ys-ie}),ct},[et,a]),Jt=c.useCallback(()=>{const se=w??(v?"draft":null);return se?{directory:t,sessionKey:se}:(Fe.error(a("gitView.pr.toast.noActiveSession"),{description:a("gitView.pr.toast.noActiveSessionDescription")}),null)},[w,t,v,a]),Gt=c.useCallback((se,Qe)=>{const ct=Qe.authorLogin?`@${Qe.authorLogin}`:Qe.authorName,Dt=Qe.path?` · ${Qe.path}${Qe.line?`:${Qe.line}`:""}`:"";Ei.getState().addDraft(se,{source:"pr-comment",fileLabel:`PR #${J?.number??""} ${ct}${Dt}`,startLine:Qe.line??0,endLine:Qe.line??0,code:Qe.body,language:"markdown",text:""})},[J?.number]),$t=c.useCallback((se,Qe)=>{const ct=se.status||"unknown",Dt=se.conclusion??void 0,zt=Dt?`${ct} / ${Dt}`:ct,Ft=se.app?.name||se.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:Qe?.hideHeader?"flex items-start justify-end gap-3":"flex items-start justify-between gap-3",children:[Qe?.hideHeader?null:s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:se.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:Ft?`${Ft} · ${zt}`:zt})]}),se.detailsUrl?s.jsx(dt,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:se.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(B,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),se.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:se.output.title}):null,se.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:se.output.summary}):null,se.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:se.output.text}):null,Array.isArray(se.annotations)&&se.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",se.annotations.length>20?` (showing 20/${se.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:se.annotations.slice(0,20).map((Et,ys)=>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:[Et.title||Et.level||"Issue",Et.path?` · ${Et.path}`:"",typeof Et.startLine=="number"?`:${Et.startLine}`:"",typeof Et.endLine=="number"&&Et.endLine!==Et.startLine?`-${Et.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap break-words mt-1",children:Et.message}),Et.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:Et.rawDetails}):null]},`${Et.path||"file"}:${Et.startLine||ys}:${ys}`))})]}):null,se.job?.steps&&se.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:se.job.steps.map((Et,ys)=>{const ie=(Et.conclusion||"").toLowerCase(),Je=ie&&!["success","neutral","skipped"].includes(ie),yt=`${se.id??"run"}:${se.job?.jobId??"job"}:${Et.number??ys}:${Et.name}`,Vt=pt.has(yt);return Je?s.jsxs(Ri,{open:Vt,children:[s.jsxs("button",{type:"button",onClick:()=>{It(ws=>{const $s=new Set(ws);return $s.has(yt)?$s.delete(yt):$s.add(yt),$s})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Je?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Vt?s.jsx(B,{name:"arrow-down-s",className:"size-4"}):s.jsx(B,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:Et.name}),Et.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Et.conclusion}):null]}),s.jsx(Mi,{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 Et.number=="number"?s.jsxs("div",{children:[a("gitView.pr.checks.stepLabel"),": ",Et.number]}):null,Et.status?s.jsxs("div",{children:[a("gitView.pr.checks.statusLabel"),": ",Et.status]}):null,Et.conclusion?s.jsxs("div",{children:[a("gitView.pr.checks.conclusionLabel"),": ",Et.conclusion]}):null,Et.startedAt?s.jsxs("div",{children:[a("gitView.pr.checks.startedLabel"),": ",gt(Et.startedAt)]}):null,Et.completedAt?s.jsxs("div",{children:[a("gitView.pr.checks.completedLabel"),": ",gt(Et.completedAt)]}):null]})})]},yt):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:Et.name}),Et.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Et.conclusion}):null]},yt)})})]}):null]})},[pt,gt,a]),[Kt,Ht]=c.useState(!1),[Qt,Le]=c.useState(!1),qe=c.useCallback(async()=>{if(!d?.prContext){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!J)return;const se=Jt();if(se){Ht(!0);try{const Qe=await Ze(d,t,J.number,{includeCheckDetails:!0,sourceRepo:Be?.repo??null});if(!Qe){Fe.error(a("gitView.pr.toast.loadChecksFailed"));return}const Dt=(Qe.checkRuns??[]).filter(Ft=>mi(Ft.conclusion));if(Dt.length===0){Fe.message(a("gitView.pr.toast.noFailedChecks"));return}const zt=Ei.getState();for(const Ft of Dt){const Et=(Ft.annotations??[]).map(Je=>[[Je.level,Je.title].filter(Boolean).join(" "),Je.path?`${Je.path}${typeof Je.startLine=="number"?`:${Je.startLine}`:""}`:null,Je.message,Je.rawDetails].filter(Boolean).join(`
|
|
3
|
+
`)),ys=(Ft.job?.steps??[]).filter(Je=>mi(Je.conclusion)).map(Je=>`step ${Je.number??"?"}: ${Je.name} → ${Je.conclusion}`),ie=[`check: ${Ft.job?.workflowName?`${Ft.job.workflowName} / ${Ft.name}`:Ft.name}`,`status: ${Ft.status??"unknown"} / ${Ft.conclusion??"unknown"}`,Ft.detailsUrl?`url: ${Ft.detailsUrl}`:null,Ft.output?.title?`title: ${Ft.output.title}`:null,Ft.output?.summary?`summary:
|
|
4
|
+
${Ft.output.summary}`:null,ys.length>0?`failed steps:
|
|
5
|
+
${ys.join(`
|
|
6
|
+
`)}`:null,Et.length>0?`annotations:
|
|
7
|
+
${Et.join(`
|
|
8
|
+
---
|
|
9
|
+
`)}`:null].filter(Boolean).join(`
|
|
10
|
+
|
|
11
|
+
`);zt.addDraft(se,{source:"pr-check",fileLabel:`PR #${J.number} · ${Ft.name}`,startLine:0,endLine:0,code:ie,language:"text",text:""})}}catch(Qe){const ct=Qe instanceof Error?Qe.message:String(Qe);Fe.error(a("gitView.pr.toast.loadChecksFailed"),{description:ct})}finally{Ht(!1)}}},[t,Ze,d,J,Jt,Be?.repo,a]),ot=c.useCallback(async()=>{if(!d?.prContext){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!J)return;const se=Jt();if(se){Le(!0);try{if(!await Ze(d,t,J.number,{sourceRepo:Be?.repo??null})){Fe.error(a("gitView.pr.toast.loadPrCommentsFailed"));return}if(Tt.length===0){Fe.message(a("gitView.pr.toast.noPrComments"));return}for(const ct of Tt)Gt(se,ct)}catch(Qe){const ct=Qe instanceof Error?Qe.message:String(Qe);Fe.error(a("gitView.pr.toast.loadPrCommentsFailed"),{description:ct})}finally{Le(!1)}}},[Gt,t,Ze,d,J,Jt,Be?.repo,a,Tt]),it=c.useCallback(async se=>{const Qe=Jt();Qe&&Gt(Qe,se)},[Gt,Jt]),He=c.useCallback(async se=>{await O(z,se)},[z,O]),[Bt,ts]=c.useState(!1),es=c.useRef(!0);c.useEffect(()=>(es.current=!0,()=>{es.current=!1}),[]);const ss=c.useCallback(async()=>{if(Bt)return;ts(!0);const se=Date.now();try{await He({force:!0})}finally{const Qe=Sy-(Date.now()-se);Qe>0&&await new Promise(ct=>window.setTimeout(ct,Qe)),es.current&&ts(!1)}},[Bt,He]),ds=c.useCallback(()=>{V.current.forEach(se=>{window.clearTimeout(se)}),V.current=wy.map(se=>window.setTimeout(()=>{He({force:!0,silent:!0,markInitialResolved:!0})},se))},[He]);c.useEffect(()=>{if(!d?.prStatus||!Ve||i.length<=1||lt.current||Be?.pr)return;const se=`${k}::${$?.name??""}`;if(H.current.has(se))return;H.current.add(se);const Qe=Cy(i,r).filter(zt=>zt.name!==$?.name);if(Qe.length===0)return;let ct=!1;return(async()=>{for(const zt of Qe){if(ct)return;try{if(!(await d.prStatus(t,e,zt.name))?.pr)continue;if(ct)return;ne(Et=>Et?.name===zt.name?Et:zt);return}catch{}}})(),()=>{ct=!0}},[e,Ve,t,d,i,$?.name,k,Be?.pr,r]),c.useEffect(()=>{I(z),P(z,{directory:t,branch:e,remoteName:$?.name??null,canShow:Ve,github:d,githubAuthChecked:f,githubConnected:h?.connected??null})},[e,Ve,t,I,d,f,h?.connected,z,$?.name,P]),c.useEffect(()=>(T(z),()=>{E(z)}),[z,T,E]),c.useEffect(()=>{const se=Dr.get(k)??null;F(se?.title??tc(e)),j(se?.body??""),M(se?.draft??!1),le(se?.targetBaseBranch?On(se.targetBaseBranch):On(n));const Qe=fi(i,{selectedRemoteName:se?.selectedRemoteName,trackingBranch:r});ne(ct=>ct?.name===Qe?.name?ct:Qe)},[n,e,i,k,r]),c.useEffect(()=>{He({markInitialResolved:!0})},[z,He]),c.useEffect(()=>{!Ve||!$?.name||He({force:!0,silent:!0,markInitialResolved:!0})},[Ve,He,$?.name]),c.useEffect(()=>{const se=Be?.resolvedRemoteName?.trim();if(!se||lt.current)return;const Qe=i.find(ct=>ct.name===se);Qe&&ne(ct=>ct?.name===Qe.name?ct:Qe)},[i,Be?.resolvedRemoteName]),c.useEffect(()=>{const se=()=>{const ct=tn.getState().entries[z]?.lastRefreshAt??0;Date.now()-ct>6e4&&He({force:!0,silent:!0})},Qe=()=>{document.visibilityState==="visible"&&se()};return window.addEventListener("focus",se),document.addEventListener("visibilitychange",Qe),()=>{window.removeEventListener("focus",se),document.removeEventListener("visibilitychange",Qe)}},[z,He]),c.useEffect(()=>{f&&h?.connected===!1&&He({force:!0,silent:!0,markInitialResolved:!0})},[f,h,He]),c.useEffect(()=>{!t||!e||Dr.set(k,{title:L,body:D,draft:A,additionalContext:G,targetBaseBranch:Z,selectedRemoteName:$?.name,activeSegment:at})},[k,L,D,A,G,Z,$?.name,t,e,at]),c.useEffect(()=>{const se=V.current;return()=>{se.forEach(Qe=>{window.clearTimeout(Qe)}),V.current=[]}},[]);const Js=c.useCallback(async()=>{if(!re&&t){Se(!0);try{const Qe={base:U&&he?.defaultBranchSha?he.defaultBranchSha:Z,head:e};G&&(Qe.context=G);const ct=await Qh(t,Qe);ct.title?.trim()&&F(ct.title.trim()),ct.body?.trim()&&j(ct.body.trim()),l?.()}catch(se){const Qe=se instanceof Error?se.message:String(se);Fe.error(a("gitView.pr.toast.generateDescriptionFailed"),{description:Qe})}finally{Se(!1)}}},[G,e,he?.defaultBranchSha,t,re,l,Z,a,U]),us=c.useCallback(async()=>{if(!d?.prCreate){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}const se=L.trim();if(!se){Fe.error(a("gitView.pr.toast.titleRequired"));return}const Qe=Z.trim();if(!Qe){Fe.error(a("gitView.pr.toast.baseBranchRequired"));return}if(!U&&Qe===e){Fe.error(a("gitView.pr.toast.baseMustDifferFromHead"));return}ye(!0);try{const ct=Wa(r),Dt=U&&he,zt=await d.prCreate({directory:t,title:se,head:e,base:Qe,...D.trim()?{body:D}:{},draft:A,...Dt?{targetRepo:{owner:he.owner,repo:he.repo},headRemote:"origin"}:{...$?{remote:$.name}:{},...ct&&ct!==$?.name?{headRemote:ct}:{}}});Fe.success(a("gitView.pr.toast.prCreated")),W(z,Ft=>Ft&&{...Ft,pr:zt}),await He({force:!0}),ds()}catch(ct){const Dt=ct instanceof Error?ct.message:String(ct);Fe.error(a("gitView.pr.toast.createPrFailed"),{description:Dt})}finally{ye(!1)}},[D,e,he,t,A,d,z,He,ds,$,Z,L,r,W,U,a]),Os=c.useCallback(async se=>{if(!d?.prMerge){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}oe(!0);try{const Qe=await d.prMerge({directory:t,number:se.number,method:X});Qe.merged?Fe.success(a("gitView.pr.toast.prMerged")):Fe.message(a("gitView.pr.toast.prNotMerged"),{description:Qe.message||a("gitView.pr.notMergeable")}),await He({force:!0}),ds()}catch(Qe){const ct=Qe instanceof Error?Qe.message:String(Qe);Fe.error(a("gitView.pr.toast.mergeFailed"),{description:ct}),se.url&&io(se.url)}finally{oe(!1)}},[t,d,X,He,ds,a]),ns=c.useCallback(async se=>{if(!d?.prReady){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}Q(!0);try{await d.prReady({directory:t,number:se.number}),Fe.success(a("gitView.pr.toast.markedReady")),await He({force:!0}),ds()}catch(Qe){const ct=Qe instanceof Error?Qe.message:String(Qe);Fe.error(a("gitView.pr.toast.markReadyFailed"),{description:ct}),se.url&&io(se.url)}finally{Q(!1)}},[t,d,He,ds,a]),Cs=c.useCallback(async se=>{if(!d?.prUpdate){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}const Qe=je.trim();if(!Qe){Fe.error(a("gitView.pr.toast.titleRequired"));return}be(!0);try{const ct=await d.prUpdate({directory:t,number:se.number,title:Qe,body:Re});W(z,Dt=>Dt&&{...Dt,pr:{...Dt.pr??se,...ct}}),ke(!1),Fe.success(a("gitView.pr.toast.prUpdated")),await He({force:!0}),ds()}catch(ct){const Dt=ct instanceof Error?ct.message:String(ct);Fe.error(a("gitView.pr.toast.updatePrFailed"),{description:Dt})}finally{be(!1)}},[t,Re,je,d,z,He,ds,W,a]);if(!Ve)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(Ql,{})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pullRequest.availableOnFeatureBranches")})]})});const Zs=Be?.repo?.url||null,Ns=U&&he?.url?he.url:Zs,Ts=!!Be?.canMerge,Lt=!!Be?.connected,Wt=f&&Be?.connected===!1,Xt=yy(Be),fs=Xt?`var(--pr-${Xt})`:"var(--status-info)",cs=Xt==="draft"?"git-pr-draft":Xt==="merged"?"git-merge":Xt==="closed"?"git-close-pull-request":"git-pull-request",Es=J?[`${J.state}${J.draft?" (draft)":""}`,J.mergeable===!1?a("gitView.pr.notMergeable"):null,J.state==="open"&&typeof J.mergeableState=="string"&&J.mergeableState&&J.mergeableState!=="unknown"?J.mergeableState:null].filter(Boolean).join(" · "):"",Ss=ze?ze.total>0?`${ze.success}/${ze.total} ${a("gitView.pr.checks.label")}`:`${ze.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:[J?s.jsxs(dt,{type:"button",variant:"outline",size:"xs",className:"shrink-0",onClick:()=>{io(J.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:[s.jsx(B,{name:cs,className:"size-4 shrink-0",style:{color:fs}}),a("gitView.pr.actions.openOnGitHub")]}):s.jsx(B,{name:cs,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")}),J?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",J.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[J&&C?s.jsxs(dt,{variant:"outline",size:"sm",className:Ie("pr-actions__walkthrough-button h-7 shrink-0 gap-1.5 px-2",fy),onClick:()=>{S(t,{kind:"pr",number:J.number,sourceRepo:Be?.repo?{owner:Be.repo.owner,repo:Be.repo.repo}:void 0}),b(t,"walkthrough")},"aria-label":a("walkthrough.action.open"),children:[s.jsx(B,{name:"route",className:"size-4"}),s.jsx("span",{className:"pr-actions__walkthrough-label typography-ui-label",children:a("walkthrough.action.open")})]}):null,s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx(dt,{variant:"ghost",size:"sm",className:"h-7 w-7 px-0",disabled:Ae||Bt,onClick:()=>{ss()},"aria-label":a("gitView.pr.actions.refreshAria"),children:Ae||Bt?s.jsx(B,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):s.jsx(B,{name:"refresh",className:"size-4 text-muted-foreground"})})}),s.jsx(At,{children:s.jsx("p",{children:a("gitView.pr.actions.refresh")})})]}),s.jsx(Ql,{className:"h-7 w-7"})]})]}),J?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:fs},children:Es}),ze?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${ec(ze.state)}`}),Ss]}):null,r&&$&&r.split("/")[0]!==$.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",$.name]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[Ts&&J.draft&&J.state==="open"?s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx(dt,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>ns(J),disabled:ce||_||ve||me,"aria-label":a("gitView.pr.actions.markReadyAria"),children:ce?s.jsx(B,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(B,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:a("gitView.pr.actions.markReady")})})]}):null,Ts?s.jsxs(s.Fragment,{children:[s.jsxs(Vs,{value:X,onValueChange:se=>te(se),disabled:_||J.state!=="open",children:[s.jsx(Us,{size:"sm",className:"h-7 w-auto min-w-0",children:s.jsx(Ms,{})}),s.jsxs(Ks,{children:[s.jsx(as,{value:"squash",children:a("gitView.pr.mergeMethod.squash")}),s.jsx(as,{value:"merge",children:a("gitView.pr.mergeMethod.merge")}),s.jsx(as,{value:"rebase",children:a("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx(dt,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>Os(J),disabled:_||ce||J.state!=="open"||J.draft||ve||me,"aria-label":a("gitView.pr.actions.mergePrAria"),children:_?s.jsx(B,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(B,{name:"git-merge",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:a("gitView.pr.actions.mergePr")})})]})]}):null]})]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Wt?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("gitView.pr.githubNotConnected")}),s.jsx(dt,{variant:"outline",size:"sm",onClick:N,className:"w-fit",children:a("gitView.pr.actions.openSettings")})]}):null,rt?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:rt}),Ns?s.jsx(dt,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:Ns,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(B,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!J&&!Ge&&!rt&&!Wt?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(B,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.pr.checkingStatus")]}):J&&!ge?s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("div",{className:"h-8 min-w-0",children:s.jsx(Pd,{className:"h-full",items:[{id:"overview",label:a("gitView.pr.segment.overview")},{id:"checks",label:ze&&ze.total>0?`${a("gitView.pr.segment.checks")} ${ze.success}/${ze.total}`:a("gitView.pr.segment.checks"),icon:ze?s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${ec(ze.state)}`}):void 0},{id:"comments",label:et?`${a("gitView.pr.segment.comments")} ${(et.issueComments?.length??0)+(et.reviewComments?.length??0)}`:a("gitView.pr.segment.comments")}],activeId:at,onSelect:se=>jt(se),layoutMode:"fit",variant:"active-pill",activePillButtonClassName:"h-7"})}),at==="overview"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Ts&&J.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.draftMustBeReady")}):null,Ts?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:me?s.jsx(An,{value:je,onChange:se=>Y(se.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:J.title})}),J.state==="open"?s.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:me?s.jsxs(s.Fragment,{children:[s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx(dt,{variant:"outline",size:"sm",className:"h-9 w-9 px-0",onClick:()=>{ke(!1),Y(J.title||""),Ce(J.body||"")},disabled:ve,"aria-label":a("gitView.pr.actions.cancelEditingAria"),children:s.jsx(B,{name:"close",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:a("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx(dt,{size:"sm",className:"h-9 w-9 px-0",onClick:()=>Cs(J),disabled:ve||!je.trim(),"aria-label":a("gitView.pr.actions.savePrAria"),children:ve?s.jsx(B,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(B,{name:"check",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:a("gitView.pr.actions.savePr")})})]})]}):s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx(dt,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>ke(!0),"aria-label":a("gitView.pr.actions.editPrAria"),children:s.jsx(B,{name:"edit",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:a("gitView.pr.actions.editPr")})})]})}):null]}),me?s.jsx(ur,{value:Re,onChange:se=>Ce(se.target.value),outerClassName:"min-h-[60vh]",placeholder:a("gitView.pr.placeholder.description"),autoCorrect:m?"on":"off",autoCapitalize:m?"sentences":"off",spellCheck:m}):null,me?null:J.body?.trim()?s.jsx(pl,{content:J.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(Ye?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}):null,at==="checks"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[ze&&ze.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:[ze.success>0?s.jsx("div",{className:"bg-[color:var(--status-success)]",style:{width:`${ze.success/ze.total*100}%`}}):null,ze.failure>0?s.jsx("div",{className:"bg-[color:var(--status-error)]",style:{width:`${ze.failure/ze.total*100}%`}}):null,ze.pending>0?s.jsx("div",{className:"bg-[color:var(--status-warning)]",style:{width:`${ze.pending/ze.total*100}%`}}):null]}),s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[ze.success,"/",ze.total," ",a("gitView.pr.checks.label")]}),(ze.inProgress??0)>0?s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 typography-micro text-[var(--status-warning)]",children:[s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}),ui(ze.startedAt,void 0,kt)]}):null]}):null,ze?.failure?s.jsxs(dt,{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:qe,disabled:Kt,"aria-label":a("gitView.pr.actions.resolveFailedChecksAria"),children:[Kt?s.jsx(B,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(B,{name:"ai-generate-2",className:"size-4"}),a("gitView.pr.actions.resolveFailedChecks")]}):null,(et?.checkRuns?.length??0)>0?s.jsx("div",{className:"flex flex-col gap-1.5",children:(et?.checkRuns??[]).map((se,Qe)=>{const ct=`${se.id??"run"}:${se.name}:${Qe}`,Dt=se.status==="in_progress",zt=se.status==="queued",Ft=mi(se.conclusion),Et=Pt.has(ct),ys=!!(se.output?.title||se.output?.summary||se.output?.text||(se.annotations?.length??0)>0||(se.job?.steps?.length??0)>0||se.detailsUrl),ie=se.job?.workflowName,Je=Dt?ui(se.startedAt,void 0,kt):ui(se.startedAt,se.completedAt);return s.jsxs("div",{className:Ie("rounded-md border border-border/40",Ft&&"border-[var(--status-error-border)]"),children:[s.jsxs("button",{type:"button",disabled:!ys,onClick:()=>{Rt(yt=>{const Vt=new Set(yt);return Vt.has(ct)?Vt.delete(ct):Vt.add(ct),Vt})},className:"flex w-full items-center gap-2 px-2.5 py-2 text-left disabled:cursor-default",children:[Dt?s.jsx(B,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-warning)]"}):zt?s.jsx(B,{name:"time",className:"size-4 shrink-0 text-muted-foreground"}):Ft?s.jsx(B,{name:"close-circle",className:"size-4 shrink-0 text-[var(--status-error)]"}):s.jsx(B,{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:ie&&ie!==se.name?`${ie} / ${se.name}`:se.name}),Je?s.jsx("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:Je}):null,ys?s.jsx(B,{name:"arrow-down-s",className:Ie("size-4 shrink-0 text-muted-foreground transition-transform",Et&&"rotate-180")}):null]}),Et&&ys?s.jsx("div",{className:"min-w-0 overflow-hidden border-t border-border/40 p-2.5",children:$t(se,{hideHeader:!0})}):null]},ct)})}):Ue?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(B,{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,at==="comments"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Tt.length>0?s.jsx("div",{className:"flex items-center justify-end",children:s.jsxs(dt,{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:ot,disabled:Qt,"aria-label":a("gitView.pr.actions.shareCommentsAria"),children:[Qt?s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(B,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.comments.addAll")]})}):null,Tt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Tt.map((se,Qe)=>{const ct=(se.authorName||"?").charAt(0).toUpperCase(),Dt=Qe===Tt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Dt?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:se.avatarUrl?s.jsx("img",{src:se.avatarUrl,alt:se.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:ct})}),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:[se.authorName,se.authorLogin&&se.authorLogin!==se.authorName?` · @${se.authorLogin}`:""]}),se.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:gt(se.createdAt)}):null,s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsxs(dt,{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:()=>{it(se)},"aria-label":a("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(B,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.actions.sendToAgent")]})}),s.jsx(At,{children:s.jsx("p",{children:a("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[se.context,se.path?` · ${se.path}`:"",se.line?`:${se.line}`:""]}),s.jsx(pl,{content:St(se.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",xt].filter(Boolean).join(" "),enableFileReferences:!1})]})]},se.id)})})}):Ue&&!et?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(B,{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:[J&&ge?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(B,{name:J.state==="merged"?"git-merge":"git-close-pull-request",className:"size-4 shrink-0",style:{color:fs}}),s.jsx("div",{className:"min-w-0 flex-1 typography-micro text-muted-foreground",children:J.state==="merged"?a("gitView.pr.history.merged",{number:J.number,base:J.base||Z}):a("gitView.pr.history.closed",{number:J.number})}),s.jsx(dt,{type:"button",variant:"ghost",size:"xs",className:"shrink-0",onClick:()=>{io(J.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(B,{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)"})," → ",Z," ",s.jsxs("span",{className:"opacity-60",children:["(",U&&he?"upstream":"remote",")"]})]})]}),Ns?s.jsx(dt,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:Ns,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(B,{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(An,{value:L,onChange:se=>F(se.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")}),ut.length>0?s.jsxs(Vs,{value:Z,onValueChange:le,children:[s.jsx(Us,{size:"lg",children:s.jsx(Ms,{placeholder:a("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(Ks,{children:ut.map(se=>s.jsx(as,{value:se,children:se},se))})]}):s.jsx(An,{value:Z,onChange:se=>le(se.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(ur,{value:D,onChange:se=>j(se.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":A,onClick:()=>M(se=>!se),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),M(Qe=>!Qe))},children:[s.jsx(hr,{size:"sm",checked:A,onChange:se=>M(se),ariaLabel:a("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:a("gitView.pr.field.draft")})]}),y?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(dt,{variant:"outline",size:"sm",onClick:()=>K(!0),children:G.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),G.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(Ri,{open:Me,onOpenChange:ae,children:[s.jsxs(tu,{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:Me?a("gitView.pr.actions.hide"):G.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),s.jsx(Mi,{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(ur,{value:G,onChange:se=>q(se.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(Xo,{open:ee,onClose:()=>K(!1),title:a("gitView.pr.additionalContext.title"),footer:s.jsx(dt,{size:"sm",onClick:()=>K(!1),className:"w-full",children:a("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(ur,{value:G,onChange:se=>q(se.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(dt,{variant:"outline",size:"sm",onClick:Js,disabled:re||ue,children:[re?s.jsx(B,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(B,{name:"ai-generate-2",className:"size-4 text-primary"}),a("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(dt,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:us,disabled:ue||!Lt||!Z.trim()||!U&&Z.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:ue?s.jsx(B,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(B,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:a("gitView.pr.actions.createPr")})]})]})]})]})]})},hi=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),ao=new Map,lo=new Map,Mn=t=>`${ls()}::${t}`,Py=()=>{const t=nt.c(115),{t:e}=vt(),{git:n}=jn(),r=rr(),{rootIsGitRepo:i,gitDirectory:o,nestedRepos:l}=Yh(r??null),a=Ca(o??null),u=su(o??null),d=nu(o??null),{ensureAll:h,ensureNestedRepos:f,selectNestedRepo:p}=In(sr(Dy)),g=tt(Iy),w=tt(Ty),v=tt(Ey),y=tt(Ry);let m;t[0]!==r?(m=hi(r),t[0]=r,t[1]=m):m=t[1];const x=m;let b;if(t[2]!==y||t[3]!==x||t[4]!==v){e:{if(!x){b=void 0;break e}let $;if(t[6]!==y||t[7]!==x){let U;t[9]!==x?(U=we=>hi(we.path)===x,t[9]=x,t[10]=U):U=t[10],$=y.find(U),t[6]=y,t[7]=x,t[8]=$}else $=t[8];const ne=$;if(ne){b=ne;break e}for(const U of v.values())if(hi(U.path)===x){b=U;break e}b=void 0}t[2]=y,t[3]=x,t[4]=v,t[5]=b}else b=t[5];const S=b;let C;t[11]!==g||t[12]!==S||t[13]!==w?.open||t[14]!==v?(C=()=>{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]=C):C=t[15],w?.open;let N;t[16]!==C?(N=C(),t[16]=C,t[17]=N):N=t[17];const k=N;let R;t[18]!==g?(R=$=>g?$.getAttachment(g):void 0,t[18]=g,t[19]=R):R=t[19];const I=Ud(R),P=I&&!I.degraded&&!I.legacy?I.worktreeRoot??void 0:void 0,T=sy(r,k,a?.current??void 0);let E,O;t[20]!==h||t[21]!==n||t[22]!==o?(E=()=>{!o||!n||h(o,n)},O=[o,h,n],t[20]=h,t[21]=n,t[22]=o,t[23]=E,t[24]=O):(E=t[23],O=t[24]),c.useEffect(E,O);const[W,L]=c.useState(null);let F;t[25]!==P||t[26]!==T?.projectDirectory?(F=()=>{const $=P||T?.projectDirectory;if(!$){L(null);return}let ne=!1;return Jo($).then(U=>{if(ne)return;const we=U.trim();L(we&&we!=="HEAD"?we:null)}).catch(()=>{ne||L(null)}),()=>{ne=!0}},t[25]=P,t[26]=T?.projectDirectory,t[27]=F):F=t[27];const D=T?.projectDirectory;let j;t[28]!==P||t[29]!==D?(j=[P,D],t[28]=P,t[29]=D,t[30]=j):j=t[30],c.useEffect(F,j);let A;t[31]!==o?(A=()=>(o?ao.get(Mn(o)):void 0)??[],t[31]=o,t[32]=A):A=t[32];const[M,G]=c.useState(A);let q;t[33]!==o?(q=()=>(o?lo.get(Mn(o)):void 0)??null,t[33]=o,t[34]=q):q=t[34];const[Z,le]=c.useState(q);let X,te;t[35]!==n||t[36]!==o?(X=()=>{if(!o||!n?.getRemotes){G([]);return}G(ao.get(Mn(o))??[]);let $=!1;return n.getRemotes(o).then(ne=>{$||(ao.set(Mn(o),ne??[]),G(ne??[]))}).catch(()=>{$||G(ao.get(Mn(o))??[])}),()=>{$=!0}},te=[o,n],t[35]=n,t[36]=o,t[37]=X,t[38]=te):(X=t[37],te=t[38]),c.useEffect(X,te);let re,Se;t[39]!==n||t[40]!==o?(re=()=>{if(!o||!n?.getRemoteUrl){le(null);return}le(lo.get(Mn(o))??null);let $=!1;return n.getRemoteUrl(o).then(ne=>{$||(lo.set(Mn(o),ne),le(ne))}).catch(()=>{$||le(lo.get(Mn(o))??null)}),()=>{$=!0}},Se=[o,n],t[39]=n,t[40]=o,t[41]=re,t[42]=Se):(re=t[41],Se=t[42]),c.useEffect(re,Se);let ue;e:{if(!u?.all){let ne;t[43]===Symbol.for("react.memo_cache_sentinel")?(ne=[],t[43]=ne):ne=t[43],ue=ne;break e}let $;t[44]!==u.all?($=u.all.filter(My).sort(),t[44]=u.all,t[45]=$):$=t[45],ue=$}const ye=ue;let ve;e:{if(!u?.all){let ne;t[46]===Symbol.for("react.memo_cache_sentinel")?(ne=[],t[46]=ne):ne=t[46],ve=ne;break e}let $;t[47]!==u.all?($=u.all.filter(Oy).map(By).sort(),t[47]=u.all,t[48]=$):$=t[48],ve=$}const be=ve;let _;t[49]!==be||t[50]!==Z||t[51]!==M||t[52]!==a?.tracking?(_=()=>{if(M.length>0)return M;const $=new Set,ne=a?.tracking?.trim();ne&&ne.includes("/")&&$.add(ne.split("/")[0]);for(const U of be){const we=U.indexOf("/");we>0&&$.add(U.slice(0,we))}return $.size===0&&Z&&$.add("origin"),Array.from($).map(U=>({name:U,fetchUrl:Z??"",pushUrl:Z??""}))},t[49]=be,t[50]=Z,t[51]=M,t[52]=a?.tracking,t[53]=_):_=t[53],a?.tracking;let oe;t[54]!==_?(oe=_(),t[54]=_,t[55]=oe):oe=t[55];const ce=oe,Q=a?.current??null;a?.tracking;let me;t[56]!==a?.tracking?(me=a?.tracking?.trim().split("/")[0],t[56]=a?.tracking,t[57]=me):me=t[57];const ke=me,fe=(ke&&u?.defaultBranches?.[ke])??u?.defaultBranches?.origin;let De;t[58]!==Q||t[59]!==fe||t[60]!==ce||t[61]!==ye||t[62]!==W||t[63]!==T?.createdFromBranch?(De=()=>eh({remoteNames:new Set(ce.map(Fy)),localBranches:ye,worktreeCreatedFromBranch:T?.createdFromBranch,rootBranchHint:W,defaultBranch:fe,headBranch:Q}),t[58]=Q,t[59]=fe,t[60]=ce,t[61]=ye,t[62]=W,t[63]=T?.createdFromBranch,t[64]=De):De=t[64],T?.createdFromBranch;let je;t[65]!==De?(je=De(),t[65]=De,t[66]=je):je=t[66];const Y=je;if(!r){let $;t[67]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(B,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[67]=$):$=t[67];let ne;t[68]!==e?(ne=e("gitView.pullRequest.title"),t[68]=e,t[69]=ne):ne=t[69];let U;t[70]!==ne?(U=s.jsx("div",{className:"typography-ui-header text-foreground",children:ne}),t[70]=ne,t[71]=U):U=t[71];let we;t[72]!==e?(we=e("gitView.pullRequest.createHint"),t[72]=e,t[73]=we):we=t[73];let he;t[74]!==we?(he=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:we}),t[74]=we,t[75]=he):he=t[75];let Te;return t[76]!==U||t[77]!==he?(Te=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[$,U,he]}),t[76]=U,t[77]=he,t[78]=Te):Te=t[78],Te}if(i===!1&&d!==!0){let $;t[79]!==r||t[80]!==f?($=()=>{f(r,{force:!0})},t[79]=r,t[80]=f,t[81]=$):$=t[81];let ne;return t[82]!==d||t[83]!==l||t[84]!==i||t[85]!==$?(ne=s.jsx(th,{rootIsGitRepo:i,resolvedIsGitRepo:d,nestedRepos:l,onRetryDiscovery:$}),t[82]=d,t[83]=l,t[84]=i,t[85]=$,t[86]=ne):ne=t[86],ne}if(!Q){let $;t[87]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(B,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[87]=$):$=t[87];let ne;t[88]!==e?(ne=e("gitView.pullRequest.title"),t[88]=e,t[89]=ne):ne=t[89];let U;t[90]!==ne?(U=s.jsx("div",{className:"typography-ui-header text-foreground",children:ne}),t[90]=ne,t[91]=U):U=t[91];let we;t[92]!==e?(we=e("gitView.pullRequest.createHint"),t[92]=e,t[93]=we):we=t[93];let he;t[94]!==we?(he=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:we}),t[94]=we,t[95]=he):he=t[95];let Te;return t[96]!==U||t[97]!==he?(Te=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[$,U,he]}),t[96]=U,t[97]=he,t[98]=Te):Te=t[98],Te}const Re=i===!1&&Array.isArray(l)&&l.length>0;let Ce;t[99]!==r||t[100]!==o||t[101]!==l||t[102]!==p||t[103]!==Re?(Ce=Re?s.jsx("div",{className:"flex shrink-0 items-center border-b border-border/60 px-4 py-2",children:s.jsx(sh,{repositories:l,selectedRepository:o??null,onSelectRepository:$=>{r&&p(r,$)},repositoryRoot:r??void 0})}):null,t[99]=r,t[100]=o,t[101]=l,t[102]=p,t[103]=Re,t[104]=Ce):Ce=t[104];const Me=o??r,ae=a?.tracking??void 0;let ee;t[105]!==Y||t[106]!==Q||t[107]!==be||t[108]!==M||t[109]!==Me||t[110]!==ae?(ee=s.jsx(Sn,{as:Na,outerClassName:"h-full min-h-0 flex-1",className:"px-4 py-3",disableHorizontal:!0,preventOverscroll:!0,children:s.jsx(Ay,{directory:Me,branch:Q,baseBranch:Y,trackingBranch:ae,remotes:M,remoteBranches:be})}),t[105]=Y,t[106]=Q,t[107]=be,t[108]=M,t[109]=Me,t[110]=ae,t[111]=ee):ee=t[111];let K;return t[112]!==Ce||t[113]!==ee?(K=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[Ce,ee]}),t[112]=Ce,t[113]=ee,t[114]=K):K=t[114],K};function Dy(t){return{ensureAll:t.ensureAll,ensureNestedRepos:t.ensureNestedRepos,selectNestedRepo:t.selectNestedRepo}}function Iy(t){return t.currentSessionId}function Ty(t){return t.newSessionDraft}function Ey(t){return t.worktreeMetadata}function Ry(t){return t.availableWorktrees}function My(t){return!t.startsWith("remotes/")}function Oy(t){return t.startsWith("remotes/")}function By(t){return t.replace(/^remotes\//,"")}function Fy(t){return t.name}const Zi=2e4,_y=(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},co=(t,e)=>tp(sp.getState().dictionary,t,e),Ly=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"},$y=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 bs(`/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()},nm=async(t,e,n)=>{if(Xh(e)||Jh(e)||Zh(e))return{ok:!0};try{const r=await $y(t,e,n);return ep(r)?{ok:!1,reason:"binary"}:_y(r,Zi)>Zi?{ok:!1,reason:"too-large"}:{ok:!0}}catch(r){return{ok:!1,reason:Ly(r)}}},rm=t=>{if(t==="too-large"){const e=Zi.toLocaleString(ru());return co("contextFileOpen.failure.tooLarge",{count:e})}return co(t==="missing"?"contextFileOpen.failure.missing":t==="binary"?"filesView.editor.cannotPreviewBinary":"contextFileOpen.failure.unreadable")},sc=8;let ea=null;const om=t=>{ea={x:t.clientX,y:t.clientY}},im=t=>{const e=ea;return ea=null,!e||t.dataTransfer&&t.dataTransfer.dropEffect!=="none"?!1:Math.abs(t.clientX-e.x)<=sc&&Math.abs(t.clientY-e.y)<=sc},nc=3,gr=t=>Array.from(t.types).includes("Files"),Wy=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]:[]})},rc=t=>{const e=t.name;return!e||e==="."||e===".."||e.includes("/")||e.includes("\\")?null:e},zy=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),ps=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},za=(t,e)=>{const n=ps(e),r=ps(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},Vy=(t,e)=>{const n=za(t,e);if(n!==".")return n;const r=ps(t);return r.split("/").filter(Boolean).pop()??r},Uy=t=>{const e=ps(t),n=e.lastIndexOf("/");return n<0?"":n===0?"/":e.slice(0,n)},Ky=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Hy=new Set(["node_modules"]),Gy=t=>Hy.has(t),qy=t=>{const e=ps(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Qy=8,gn=new Map,Va=t=>JSON.stringify([ls(),t]),Yy=t=>{const e=Va(t),n=gn.get(e);return n?(n.touchedAt=Date.now(),gn.delete(e),gn.set(e,n),n):null},pi=t=>{const e=Va(t),n=gn.get(e);if(n)return n.touchedAt=Date.now(),n;if(gn.size>=Qy){const i=gn.keys().next().value;i!==void 0&&gn.delete(i)}const r={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return gn.set(e,r),r},am=(t,e)=>s.jsx(Aa,{filePath:t,extension:e}),Xy=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},Jy=t=>{const e=nt.c(88),{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:y,onSetDropTarget:m,onDropFiles:x}=t,{t:b}=vt(),S=n.type==="directory";let C;e[0]!==S||e[1]!==n.path?(C=S?n.path:Uy(n.path),e[0]=S,e[1]=n.path,e[2]=C):C=e[2];const N=C,{canRename:k,canCreateFile:R,canCreateFolder:I,canDelete:P,canReveal:T}=f,E=!S&&!!p,O=T&&!l,W=k||R||I||P||E||O,[L,F]=c.useState(!1),[D,j]=c.useState(!1);let A;e[3]!==W?(A=ne=>{W&&(ne?.preventDefault(),j(!0))},e[3]=W,e[4]=A):A=e[4];const M=A;let G;e[5]!==S||e[6]!==n||e[7]!==g||e[8]!==w?(G=()=>{S?w(n.path):g(n)},e[5]=S,e[6]=n,e[7]=g,e[8]=w,e[9]=G):G=e[9];const q=G;let Z;e[10]===Symbol.for("react.memo_cache_sentinel")?(Z=ne=>{ne.stopPropagation(),j(!1),F(!0)},e[10]=Z):Z=e[10];const le=Z;let X;e[11]!==R||e[12]!==I||e[13]!==P||e[14]!==k||e[15]!==O||e[16]!==p||e[17]!==l||e[18]!==S||e[19]!==n||e[20]!==y||e[21]!==v||e[22]!==b?(X=ne=>{const{Item:U,Separator:we}=ne;return s.jsxs(s.Fragment,{children:[k&&s.jsxs(U,{onClick:he=>{he.stopPropagation(),y("rename",n)},children:[s.jsx(B,{name:"edit",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.rename")]}),s.jsxs(U,{onClick:he=>{he.stopPropagation(),xn(n.path).then(Te=>{if(Te.ok){Fe.success(b("sidebarFilesTree.toast.pathCopied"));return}Fe.error(b("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(B,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.copyPath")]}),!S&&p&&s.jsxs(U,{onClick:he=>{he.stopPropagation(),p(n.path).catch(Te=>{console.error("Download failed:",Te),Fe.error(b("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(B,{name:"download",className:"mr-2 h-4 w-4"})," ",b(l?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),O&&s.jsxs(U,{onClick:he=>{he.stopPropagation(),v(n.path)},children:[s.jsx(B,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",b(np())]}),S&&(R||I)&&s.jsxs(s.Fragment,{children:[s.jsx(we,{}),R&&s.jsxs(U,{onClick:he=>{he.stopPropagation(),y("createFile",n)},children:[s.jsx(B,{name:"file-add",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.newFile")]}),I&&s.jsxs(U,{onClick:he=>{he.stopPropagation(),y("createFolder",n)},children:[s.jsx(B,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.newFolder")]})]}),P&&s.jsxs(s.Fragment,{children:[s.jsx(we,{}),s.jsxs(U,{onClick:he=>{he.stopPropagation(),y("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",b("sidebarFilesTree.menu.delete")]})]})]})},e[11]=R,e[12]=I,e[13]=P,e[14]=k,e[15]=O,e[16]=p,e[17]=l,e[18]=S,e[19]=n,e[20]=y,e[21]=v,e[22]=b,e[23]=X):X=e[23];const te=X;let re;e[24]!==n.path||e[25]!==r?(re=ne=>{om(ne);const U=za(r,n.path);!U||U==="."||(ne.dataTransfer.setData("application/x-openchamber-file-path",U),ne.dataTransfer.effectAllowed="copy")},e[24]=n.path,e[25]=r,e[26]=re):re=e[26];const Se=re;let ue;e[27]!==q?(ue=ne=>{im(ne)&&q()},e[27]=q,e[28]=ue):ue=e[28];const ye=ue;let ve;e[29]!==h||e[30]!==m||e[31]!==N?(ve=ne=>{!h||!N||!gr(ne.dataTransfer)||(ne.preventDefault(),ne.stopPropagation(),ne.dataTransfer.dropEffect="copy",m(N))},e[29]=h,e[30]=m,e[31]=N,e[32]=ve):ve=e[32];const be=ve;let _;e[33]!==h||e[34]!==m||e[35]!==N?(_=ne=>{!h||!N||!gr(ne.dataTransfer)||ne.relatedTarget instanceof Node&&ne.currentTarget.contains(ne.relatedTarget)||(ne.stopPropagation(),m(null))},e[33]=h,e[34]=m,e[35]=N,e[36]=_):_=e[36];const oe=_;let ce;e[37]!==h||e[38]!==x||e[39]!==N?(ce=ne=>{!h||!N||!gr(ne.dataTransfer)||(ne.preventDefault(),ne.stopPropagation(),x(N,ne.dataTransfer))},e[37]=h,e[38]=x,e[39]=N,e[40]=ce):ce=e[40];const Q=ce;let me;e[41]===Symbol.for("react.memo_cache_sentinel")?(me={contentVisibility:"auto",blockSize:"calc(max(1lh, 1rem) + 0.5rem)"},e[41]=me):me=e[41];let ke;e[42]!==M||e[43]!==oe||e[44]!==be||e[45]!==Q?(ke=s.jsx("div",{className:"group relative flex items-center typography-meta",style:me,onContextMenu:M,onDragEnter:be,onDragOver:be,onDragLeave:oe,onDrop:Q}),e[42]=M,e[43]=oe,e[44]=be,e[45]=Q,e[46]=ke):ke=e[46];const fe=d?"bg-interactive-selection ring-2 ring-inset ring-primary":o?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let De;e[47]!==fe?(De=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",fe),e[47]=fe,e[48]=De):De=e[48];let je;e[49]!==S||e[50]!==i||e[51]!==n.extension||e[52]!==n.path?(je=S?i?s.jsx(B,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):s.jsx(B,{name:"folder-3",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):am(n.path,n.extension),e[49]=S,e[50]=i,e[51]=n.extension,e[52]=n.path,e[53]=je):je=e[53];let Y;e[54]!==n.name||e[55]!==n.path?(Y=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[54]=n.name,e[55]=n.path,e[56]=Y):Y=e[56];let Re;e[57]!==S||e[58]!==a?(Re=!S&&a&&s.jsx(Xy,{status:a}),e[57]=S,e[58]=a,e[59]=Re):Re=e[59];let Ce;e[60]!==u||e[61]!==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[60]=u,e[61]=S,e[62]=Ce):Ce=e[62];let Me;e[63]!==M||e[64]!==ye||e[65]!==Se||e[66]!==q||e[67]!==De||e[68]!==je||e[69]!==Y||e[70]!==Re||e[71]!==Ce?(Me=s.jsxs("button",{type:"button",onClick:q,onContextMenu:M,draggable:!0,onDragStart:Se,onDragEnd:ye,className:De,children:[je,Y,Re,Ce]}),e[63]=M,e[64]=ye,e[65]=Se,e[66]=q,e[67]=De,e[68]=je,e[69]=Y,e[70]=Re,e[71]=Ce,e[72]=Me):Me=e[72];let ae;e[73]!==L||e[74]!==W||e[75]!==te||e[76]!==b?(ae=W&&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(Ys,{open:L,onOpenChange:F,children:[s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(qs,{asChild:!0,children:s.jsx(dt,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:le,title:b("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":b("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(B,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:b("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(Qs,{align:"end",side:"bottom",onCloseAutoFocus:()=>F(!1),children:te({Item:Ut,Separator:zs})})]})}),e[73]=L,e[74]=W,e[75]=te,e[76]=b,e[77]=ae):ae=e[77];let ee;e[78]!==ke||e[79]!==Me||e[80]!==ae?(ee=s.jsxs(Id,{render:ke,children:[Me,ae]}),e[78]=ke,e[79]=Me,e[80]=ae,e[81]=ee):ee=e[81];let K;e[82]!==te?(K=s.jsx(Dd,{className:"min-w-[180px]",children:te({Item:Gn,Separator:Di})}),e[82]=te,e[83]=K):K=e[83];let $;return e[84]!==D||e[85]!==ee||e[86]!==K?($=s.jsxs(Td,{open:D,onOpenChange:j,children:[ee,K]}),e[84]=D,e[85]=ee,e[86]=K,e[87]=$):$=e[87],$},Zy=(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,e1=c.memo(Jy,Zy),t1=t=>{const e=nt.c(6),{visible:n}=t,r=n===void 0?!0:n,i=In(n1),o=rr();let l;e[0]!==o||e[1]!==i?(l=JSON.stringify([i,o]),e[0]=o,e[1]=i,e[2]=l):l=e[2];let a;return e[3]!==l||e[4]!==r?(a=s.jsx(s1,{visible:r},l),e[3]=l,e[4]=r,e[5]=a):a=e[5],a},s1=({visible:t})=>{const e=c.useRef(t);e.current=t;const{t:n}=vt(),{files:r,runtime:i}=jn(),o=yf(i.platform),l=rr()??"",a=ps(l.trim()),u=Va(a),d=wf(),h=Sf(),f=jd(de=>de.searchFiles),p=Ne(de=>de.openContextFile),g=Ca(t?l:null),[w,v]=c.useState(""),y=ou(w,200),m=c.useRef(null),[x,b]=c.useState([]),[S,C]=c.useState(!1),[N,k]=c.useState(null),[R,I]=c.useState(!1),[P,T]=c.useState(null),E=c.useRef(!1),O=c.useRef(a);O.current=a;const[W,L]=c.useState({}),[F,D]=c.useState({}),j=c.useRef(new Set),A=c.useMemo(()=>new gx,[]);c.useEffect(()=>()=>A.clear(),[A]);const M=c.useRef(null);c.useEffect(()=>{if(k(null),T(null),!a){L({}),D({}),j.current=new Set;return}const de=Yy(a);de?(L({...de.childrenByDir}),D({...de.loadErrorsByDir}),j.current=new Set(de.loadedDirs)):(L({}),D({}),j.current=new Set)},[a]),c.useEffect(()=>{if(!a)return;const de=pi(a);de.childrenByDir=W},[a,W]),c.useEffect(()=>{if(!a)return;const de=pi(a);de.loadErrorsByDir=F},[a,F]),c.useEffect(()=>{if(!a)return;const de=pi(a);de.loadedDirs=new Set(j.current)},[a,W,F]),c.useEffect(()=>()=>{if(!a)return;const de=gn.get(u);de&&de.loadedDirs.size===0&&Object.keys(de.childrenByDir).length===0&&gn.delete(u)},[u,a]);const G=c.useMemo(()=>[],[]),q=c.useMemo(()=>[],[]),Z=pn(de=>a?de.byRoot[a]?.expandedPaths??G:G),le=c.useMemo(()=>new Set(Z),[Z]),X=pn(de=>a?de.byRoot[a]?.selectedPath??null:null),te=pn(de=>de.setSelectedPath),re=pn(de=>de.addOpenPath),Se=pn(de=>de.removeOpenPathsByPrefix),ue=pn(de=>de.toggleExpandedPath),ye=pn(de=>de.collapseAllExpandedPaths),ve=Ne(de=>a?de.contextPanelByDirectory[a]?.tabs??q:q),be=c.useMemo(()=>new Set(ve.map(de=>de.mode==="file"?de.targetPath:null).filter(de=>typeof de=="string"&&de.length>0).map(de=>ps(de))),[ve]),[_,oe]=c.useState(null),[ce,Q]=c.useState(null),[me,ke]=c.useState(""),[fe,De]=c.useState(!1),je=!!r.writeFile,Y=!!r.createDirectory,Re=!!r.rename,Ce=!!r.delete,Me=!!r.revealPath,ae=!!r.uploadFile,ee=c.useMemo(()=>({canRename:Re,canCreateFile:je,canCreateFolder:Y,canDelete:Ce,canReveal:Me}),[Re,je,Y,Ce,Me]),K=c.useCallback(de=>{r.revealPath&&r.revealPath(de).catch(()=>{Fe.error(n("sidebarFilesTree.toast.revealFailed"))})},[r,n]),$=c.useCallback((de,We)=>{oe(de),Q(We),ke(de==="rename"&&We.name||""),De(!1)},[]),ne=c.useCallback((de,We)=>{const lt=We.filter(H=>H&&typeof H.name=="string"&&H.name.length>0).filter(H=>d||!H.name.startsWith(".")).filter(H=>h||!Gy(H.name)).map(H=>{const V=H.name,J=ps(H.path||""),ge=J?Ky(J)?J:ps(`${de}/${J}`):ps(`${de}/${V}`),Ee=H.isDirectory?"directory":"file",$e=Ee==="file"&&V.includes(".")?V.split(".").pop()?.toLowerCase():void 0;return{name:V,path:ge,type:Ee,extension:$e}});return zy(lt)},[h,d]),U=c.useCallback(async(de,We,lt=!1)=>{if(!e.current||We?.())return;const H=ps(de.trim());if(!H||!lt&&j.current.has(H))return;const V=ls();return A.run(H,async J=>{const ge=()=>!J()||ls()!==V;try{const Ee=r.listDirectory?(await r.listDirectory(H)).entries:await nn.listLocalDirectory(H);if(ge())return;const $e=ne(H,Ee);j.current=new Set(j.current),j.current.add(H),D(st=>{if(!st[H])return st;const Ze={...st};return delete Ze[H],Ze}),L(st=>st[H]&&xx(st[H],$e)?st:{...st,[H]:$e})}catch(Ee){if(ge())return;const $e=Ee instanceof Error?Ee.message:String(Ee??"");console.error("Failed to load sidebar directory:",Ee),D(st=>({...st,[H]:$e}))}},lt)},[A,r,ne]),we=c.useCallback(async()=>{if(!a)return;M.current?.abort();const de=new AbortController;M.current=de,A.clear();try{const lt=(pn.getState().byRoot[a]?.expandedPaths??[]).map(J=>ps(J)).filter(J=>!!J&&J!==a&&J.startsWith(`${a}/`)),H=[a,...lt];j.current=new Set(j.current);for(const J of H)j.current.delete(J);D(J=>{if(Object.keys(J).length===0)return J;const ge={...J};let Ee=!1;for(const $e of H)$e in ge&&(delete ge[$e],Ee=!0);return Ee?ge:J});const V=()=>de.signal.aborted;await U(a,V);for(let J=0;J<lt.length&&!de.signal.aborted;J+=3){const ge=lt.slice(J,J+3);await Promise.all(ge.map(Ee=>U(Ee,V)))}}catch(We){if(de.signal.aborted)return;console.error("Failed to refresh sidebar tree:",We)}finally{M.current===de&&(M.current=null)}},[A,U,a]),he=c.useCallback(async de=>{if(!de){await we();return}const We=ps(de);j.current=new Set(j.current),j.current.delete(We),await U(We,void 0,!0)},[U,we]);c.useEffect(()=>{a&&(M.current?.abort(),j.current=new Set,A.clear(),D({}),L(de=>Object.keys(de).length===0?de:{}),U(a))},[A,U,a,d,h]),c.useEffect(()=>{if(!t||!a||Z.length===0)return;const de=Z.map(H=>ps(H)).filter(H=>!!H&&H!==a&&H.startsWith(`${a}/`)&&!j.current.has(H)&&!A.has(H)).sort((H,V)=>H.split("/").length-V.split("/").length);if(de.length===0)return;let We=!1;const lt=()=>We;return(async()=>{for(let H=0;H<de.length&&!We;H+=3){const V=de.slice(H,H+3);await Promise.all(V.map(J=>U(J,lt)))}})(),()=>{We=!0}},[A,Z,U,a,t]);const Te=c.useRef(t);c.useEffect(()=>{const de=t&&!Te.current;Te.current=t,de&&we()},[we,t]),c.useEffect(()=>{if(!t)return;if(!l){b([]),C(!1);return}const de=y.trim();if(!de){b([]),C(!1);return}let We=!1;return C(!0),f(l,de,150,{includeHidden:d,respectGitignore:!h,type:"file"}).then(lt=>{if(We)return;const V=lt.filter(J=>h||!qy(J.path)).map(J=>({name:J.name,path:ps(J.path),type:"file",extension:J.extension,relativePath:J.relativePath}));b(V)}).catch(()=>{We||b([])}).finally(()=>{We||C(!1)}),()=>{We=!0}},[l,y,f,d,h,t]);const Oe=c.useMemo(()=>{const de=new Map;if(!g?.files)return de;for(const We of g.files)We.index==="A"||We.working_dir==="?"?de.set(We.path,"git-added"):We.index==="D"?de.set(We.path,"git-deleted"):(We.index==="M"||We.working_dir==="M")&&de.set(We.path,"git-modified");return de},[g]),_e=c.useMemo(()=>{const de=new Map;if(!g?.files||!a)return de;for(const We of g.files){const lt=We.index==="M"||We.working_dir==="M",H=We.index==="A"||We.working_dir==="?";if(!lt&&!H)continue;const V=We.path.split("/");if(V.length<=1)continue;let J=a;for(let ge=0;ge<V.length-1;ge++){J=`${J}/${V[ge]}`;let Ee=de.get(J);Ee||(Ee={modified:0,added:0},de.set(J,Ee)),lt&&Ee.modified++,H&&Ee.added++}}return de},[g,a]),Ve=c.useCallback(de=>{if(be.has(de))return"open";if(Oe.size===0)return null;const We=de.startsWith(a+"/")?de.slice(a.length+1):de;return Oe.get(We)??null},[be,Oe,a]),z=c.useCallback(de=>{if(_e.size===0)return null;const We=_e.get(de);return We&&We.modified+We.added>0?We:null},[_e]),pe=c.useCallback(async de=>{if(!a)return;const We=await nm(r,de.path,{directory:a});if(!We.ok){Fe.error(rm(We.reason));return}te(a,de.path),re(a,de.path),p(a,de.path)},[re,r,p,a,te]),Ae=c.useCallback(async de=>{const We=ps(de);a&&(ue(a,We),j.current.has(We)||await U(We))},[U,a,ue]),Be=c.useCallback(async(de,We,lt=!1)=>{const H=r.uploadFile;if(!H||We.length===0||E.current||!a)return;const V=a,J=ls();E.current=!0,I(!0),k(de),lt&&T(null);const ge=[];for(let Ue=0;Ue<We.length;Ue+=nc){const jt=We.slice(Ue,Ue+nc),ze=await Promise.all(jt.map(async xe=>{const bt=rc(xe);if(!bt||ls()!==J)return"failed";try{return(await H(ps(`${de}/${bt}`),xe,{directory:V,overwrite:lt})).success?"uploaded":"failed"}catch(ht){return!lt&&vf(ht)&&ht.reason==="already-exists"?"conflict":"failed"}}));ge.push(...ze)}const Ee=ge.filter(Ue=>Ue==="uploaded").length,$e=ge.filter(Ue=>Ue==="failed").length,st=We.filter((Ue,jt)=>ge[jt]==="conflict"),Ze=We.flatMap((Ue,jt)=>{const ze=rc(Ue);return ge[jt]==="uploaded"&&ze?[ps(`${de}/${ze}`)]:[]}),et=O.current===V&&ls()===J;try{Ze.length>0&&bx({runtimeKey:J,paths:Ze}),Ee>0&&et&&await he(de),Ee>0&&Fe.success(n(st.length>0?"sidebarFilesTree.toast.uploadedWithoutConflicts":"sidebarFilesTree.toast.uploaded")),$e>0&&Fe.error(n("sidebarFilesTree.toast.uploadFailed")),st.length>0&&et&&T({directory:de,files:st,runtimeKey:J,workspaceRoot:V})}finally{E.current=!1,I(!1),k(null)}},[r.uploadFile,he,a,n]),rt=c.useCallback((de,We)=>{const lt=Wy(We);lt.length!==0&&Be(de,lt)},[Be]),Ge=c.useCallback(de=>{!ae||E.current||!a||!gr(de.dataTransfer)||(de.preventDefault(),de.dataTransfer.dropEffect="copy",k(a))},[ae,a]),ut=c.useCallback(de=>{gr(de.dataTransfer)&&(de.relatedTarget instanceof Node&&de.currentTarget.contains(de.relatedTarget)||k(null))},[]),at=c.useCallback(de=>{!ae||E.current||!a||!gr(de.dataTransfer)||(de.preventDefault(),rt(a,de.dataTransfer))},[ae,rt,a]),wt=c.useCallback(async de=>{if(de?.preventDefault(),!ce||!_)return;De(!0);const We=()=>De(!1),lt=()=>oe(null);if(_==="createFile"){if(!me.trim()){Fe.error(n("sidebarFilesTree.toast.filenameRequired")),We();return}if(!r.writeFile){Fe.error(n("sidebarFilesTree.toast.writeNotSupported")),We();return}const H=ce.path,V=H?`${H}/`:"",J=ps(`${V}${me.trim()}`);await r.writeFile(J,"").then(async ge=>{ge.success&&(Fe.success(n("sidebarFilesTree.toast.fileCreated")),await he(H)),lt()}).catch(()=>Fe.error(n("sidebarFilesTree.toast.operationFailed"))).finally(We);return}if(_==="createFolder"){if(!me.trim()){Fe.error(n("sidebarFilesTree.toast.folderNameRequired")),We();return}const H=ce.path,V=H?`${H}/`:"",J=ps(`${V}${me.trim()}`);await r.createDirectory(J).then(async ge=>{ge.success&&(Fe.success(n("sidebarFilesTree.toast.folderCreated")),await he(H)),lt()}).catch(()=>Fe.error(n("sidebarFilesTree.toast.operationFailed"))).finally(We);return}if(_==="rename"){if(!me.trim()){Fe.error(n("sidebarFilesTree.toast.nameRequired")),We();return}if(!r.rename){Fe.error(n("sidebarFilesTree.toast.renameNotSupported")),We();return}const H=ce.path,V=H.split("/").slice(0,-1).join("/"),J=V?`${V}/`:"",ge=ps(`${J}${me.trim()}`);await r.rename(H,ge).then(async Ee=>{Ee.success&&(Fe.success(n("sidebarFilesTree.toast.renamedSuccessfully")),await he(V),a&&Se(a,H),(X===H||X&&X.startsWith(`${H}/`))&&te(a,null)),lt()}).catch(()=>Fe.error(n("sidebarFilesTree.toast.operationFailed"))).finally(We);return}if(_==="delete"){if(!r.delete){Fe.error(n("sidebarFilesTree.toast.deleteNotSupported")),We();return}const H=ce.path,V=H.split("/").slice(0,-1).join("/");await r.delete(H).then(async J=>{J.success&&(Fe.success(n("sidebarFilesTree.toast.deletedSuccessfully")),await he(V),a&&Se(a,H),(X===H||X&&X.startsWith(H+"/"))&&te(a,null)),lt()}).catch(()=>Fe.error(n("sidebarFilesTree.toast.operationFailed"))).finally(We);return}We()},[_,ce,me,r,he,Se,a,X,te,n]);function pt(de,We){const lt=W[de]??[];return lt.map((H,V)=>{const J=H.type==="directory",ge=J&&le.has(H.path),Ee=X===H.path,$e=V===lt.length-1;return s.jsxs("li",{className:"relative",children:[We>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),$e&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(e1,{node:H,root:a,isExpanded:ge,isActive:Ee,isBrowserClient:o,status:J?void 0:Ve(H.path),badge:J?z(H.path):void 0,isDropTarget:J&&N===H.path,canUpload:ae&&!R,permissions:ee,downloadFile:r.downloadFile,onSelect:pe,onToggle:Ae,onRevealPath:K,onOpenDialog:$,onSetDropTarget:k,onDropFiles:rt}),J&&ge&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[F[H.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:F[H.path],children:F[H.path]}),s.jsxs(dt,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{he(H.path)},children:[s.jsx(B,{name:"refresh",className:"h-3.5 w-3.5"}),n("sidebarFilesTree.actions.refreshTitle")]})]}):null,pt(H.path,We+1)]})]},H.path)})}const It=!!(a&&W[a]),Pt=a?F[a]:null,Rt=N?Vy(a,N):"";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:[je&&s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(dt,{variant:"ghost",size:"sm",onClick:()=>$("createFile",{path:l,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:n("sidebarFilesTree.actions.newFileTitle"),"aria-label":n("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(B,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:n("sidebarFilesTree.actions.newFileTitle")})]}),Y&&s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(dt,{variant:"ghost",size:"sm",onClick:()=>$("createFolder",{path:l,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:n("sidebarFilesTree.actions.newFolderTitle"),"aria-label":n("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(B,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:n("sidebarFilesTree.actions.newFolderTitle")})]}),s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(dt,{variant:"ghost",size:"sm",onClick:()=>{we()},className:"h-8 w-8 p-0 flex-shrink-0",title:n("sidebarFilesTree.actions.refreshTitle"),"aria-label":n("sidebarFilesTree.actions.refreshTitle"),children:s.jsx(B,{name:"refresh",className:"h-4 w-4"})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:n("sidebarFilesTree.actions.refreshTitle")})]}),s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(dt,{variant:"ghost",size:"sm",onClick:()=>{a&&ye(a)},className:"h-8 w-8 p-0 flex-shrink-0",title:n("sidebarFilesTree.actions.collapseAllTitle"),"aria-label":n("sidebarFilesTree.actions.collapseAllTitle"),children:s.jsx(B,{name:"collapse-vertical",className:"h-4 w-4"})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:n("sidebarFilesTree.actions.collapseAllTitle")})]})]}),s.jsxs("div",{className:"relative min-w-0",children:[s.jsx(B,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(An,{ref:m,value:w,onChange:de=>v(de.target.value),placeholder:n("sidebarFilesTree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),w.trim().length>0?s.jsx("button",{type:"button","aria-label":n("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:()=>{v(""),m.current?.focus()},children:s.jsx(B,{name:"close",className:"h-4 w-4"})}):null]})]}),s.jsxs("div",{className:"relative flex-1 min-h-0",children:[s.jsx(Sn,{outerClassName:"h-full min-h-0",className:Ie("p-2",N===a&&"bg-interactive-selection/10"),onDragEnter:Ge,onDragOver:Ge,onDragLeave:ut,onDrop:at,children:s.jsx("ul",{className:"flex flex-col",children:S?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(B,{name:"loader-4",className:"h-4 w-4 animate-spin"}),n("sidebarFilesTree.state.searching")]}):x.length>0?x.map(de=>{const We=X===de.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>pe(de),draggable:!0,onDragStart:lt=>{om(lt);const H=de.relativePath||za(a??"",de.path);!H||H==="."||(lt.dataTransfer.setData("application/x-openchamber-file-path",H),lt.dataTransfer.effectAllowed="copy")},onDragEnd:lt=>{im(lt)&&pe(de)},className:Ie("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",We?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:de.path,children:[am(de.path,de.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:de.relativePath??de.path})]})},de.path)}):Pt?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:Pt}),s.jsxs(dt,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{we()},children:[s.jsx(B,{name:"refresh",className:"h-3.5 w-3.5"}),n("sidebarFilesTree.actions.refreshTitle")]})]}):It&&a?pt(a,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:n("sidebarFilesTree.state.loading")})})}),N?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(B,{name:R?"loader-4":"folder-received",className:Ie("size-4 flex-shrink-0",R&&"animate-spin")}),s.jsx("span",{className:"min-w-0 truncate typography-meta",title:Rt,children:n(R?"sidebarFilesTree.drop.uploading":"sidebarFilesTree.drop.target",{path:Rt})})]}):null]}),s.jsx(Ds,{open:!!P,onOpenChange:de=>!de&&T(null),children:s.jsxs(Is,{children:[s.jsxs(Xs,{children:[s.jsx(_s,{children:n("sidebarFilesTree.dialog.uploadConflicts.title")}),s.jsx(Ls,{children:n("sidebarFilesTree.dialog.uploadConflicts.description",{path:P?.directory??""})})]}),s.jsx(Sn,{outerClassName:"max-h-52",className:"flex flex-col gap-1 pr-2",children:P?.files.map((de,We)=>s.jsx("div",{className:"truncate rounded-md bg-muted px-2 py-1 typography-meta",title:de.name,children:de.name},`${de.name}-${de.size}-${We}`))}),s.jsxs(wn,{children:[s.jsx(dt,{variant:"outline",onClick:()=>T(null),disabled:R,children:n("sidebarFilesTree.dialog.cancel")}),s.jsx(dt,{onClick:()=>{if(P){if(P.runtimeKey!==ls()||P.workspaceRoot!==a){T(null);return}Be(P.directory,P.files,!0)}},disabled:R,children:n("sidebarFilesTree.dialog.uploadConflicts.replace")})]})]})}),s.jsx(Ds,{open:!!_,onOpenChange:de=>!de&&oe(null),children:s.jsxs(Is,{children:[s.jsxs(Xs,{children:[s.jsxs(_s,{children:[_==="createFile"&&n("sidebarFilesTree.dialog.createFile.title"),_==="createFolder"&&n("sidebarFilesTree.dialog.createFolder.title"),_==="rename"&&n("sidebarFilesTree.dialog.rename.title"),_==="delete"&&n("sidebarFilesTree.dialog.delete.title")]}),s.jsxs(Ls,{children:[_==="createFile"&&n("sidebarFilesTree.dialog.createFile.description",{path:ce?.path??n("sidebarFilesTree.dialog.rootFallback")}),_==="createFolder"&&n("sidebarFilesTree.dialog.createFolder.description",{path:ce?.path??n("sidebarFilesTree.dialog.rootFallback")}),_==="rename"&&n("sidebarFilesTree.dialog.rename.description",{name:ce?.name??""}),_==="delete"&&n("sidebarFilesTree.dialog.delete.description",{name:ce?.name??""})]})]}),_!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(An,{value:me,onChange:de=>ke(de.target.value),placeholder:n(_==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:de=>{de.key==="Enter"&&wt()},autoFocus:!0})}),s.jsxs(wn,{children:[s.jsx(dt,{variant:"outline",onClick:()=>oe(null),disabled:fe,children:n("sidebarFilesTree.dialog.cancel")}),s.jsx(dt,{variant:_==="delete"?"destructive":"default",onClick:()=>{wt()},disabled:fe||_!=="delete"&&!me.trim(),children:fe?s.jsx(B,{name:"loader-4",className:"size-4 animate-spin"}):n(_==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})};function n1(t){return t.runtimeKey}const oc=60,r1=t=>{try{return new URL(t).origin}catch{return""}},gi=new Set,lm=or()((t,e)=>({byOrigin:{},resolve:(n,r)=>{const i=r1(n);!i||!r||e().byOrigin[i]||gi.has(i)||(gi.add(i),pr("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<=oc)return{byOrigin:u};for(const h of d.slice(0,d.length-oc))delete u[h];return{byOrigin:u}})}).catch(()=>{}).finally(()=>{gi.delete(i)}))}})),Ua=t=>t,ta=t=>{const e=Ua(t).type;return typeof e=="string"?e:""},o1=t=>{const e=Ua(t).tool;return typeof e=="string"?e:""},i1=t=>{const e=Ua(t).text;return typeof e=="string"?e:""},a1=t=>{const e=ta(t);return e==="tool"?o1(t).trim().toLowerCase()||"tool":e||"unknown"},l1=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=a1(n);e.includes(r)||e.push(r)}return e.join(" + ")},c1=t=>t.replace(/\s+/g," ").trim(),d1=t=>{for(const n of t)if(ta(n)==="text"){const r=c1(i1(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"}`},u1=(t,e,n)=>`${n(t)} / ${n(e)}`,m1=t=>{if(t==="12h")return!0;if(t==="24h")return!1},f1=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=m1(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},Bn=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,ic=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:Bn(n)};if(!n||typeof n!="object")return sa;const r=n,i=Bn(r.input),o=Bn(r.output),l=Bn(r.reasoning),a=Bn(r.cache?.read),u=Bn(r.cache?.write),d=Bn(r.total);return{input:i,output:o,reasoning:l,cacheRead:a,cacheWrite:u,total:d>0?d:i+o+l+a+u}},h1=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},en=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+en(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+en(n),0):0,p1=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...vo,assistant:en(n.text)+en(n.content)};const i=h1(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:en(n.input)+en(n.output)+en(n.error)+en(n.call?.input)+en(n.call?.output)+en(n.call?.error)+en(n.raw)+Math.round(en(n.metadata)*.25)+Math.round(en(n.state)*.1),other:0}:e==="user"?{user: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}},ac=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),g1=t=>{const e=eo(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},x1=(t,e)=>{if(t.length===0)return{...vo};const n=t.reduce((r,i)=>{const o=g1(i);let l={...vo};for(const a of i.parts)l=ac(l,p1(a,o));return ac(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)}},Hn=t=>t.toLocaleString(ru()),b1=(t,e)=>!t||!Number.isFinite(t)?"-":eu(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),y1=(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}},w1=()=>{const t=nt.c(209),{t:e}=vt(),n=Ne(S1);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=tt(v1),h=tt(j1),f=iu(h??void 0),p=rp(d??"",h??void 0),g=Yt(k1);let w;t[1]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null),o(C1),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 y,m;t[5]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},m=[],t[5]=y,t[6]=m):(y=t[5],m=t[6]),c.useEffect(y,m);let x;t[7]===Symbol.for("react.memo_cache_sentinel")?(x=async(Ke,Ye)=>{(await xn(Ye)).ok?(a(Ke),u.current!==null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{a(Mt=>Mt===Ke?null:Mt),u.current=null},2e3)):a(null)},t[7]=x):x=t[7];const b=x;let S;t[8]!==d||t[9]!==f?(S=d?f.find(Ke=>Ke.id===d)??null:null,t[8]=d,t[9]=f,t[10]=S):S=t[10];const C=S;let N,k,R,I,P,T,E;if(t[11]!==p){N=p.filter(N1),E=p.filter(A1);const Ke=op(p.map(P1));R=Ke?p[Ke.index]??null:null,I=Ke?.state==="compacted";let Ye;t[19]!==R?(T=R?ic(R):sa,Ye=ip({input:T.input,cache:{read:T.cacheRead,write:T.cacheWrite}}),t[19]=R,t[20]=Ye,t[21]=T):(Ye=t[20],T=t[21]),k=Ye,P=N.reduce(D1,0),t[11]=p,t[12]=N,t[13]=k,t[14]=R,t[15]=I,t[16]=P,t[17]=T,t[18]=E}else N=t[12],k=t[13],R=t[14],I=t[15],P=t[16],T=t[17],E=t[18];const O=P,W=R?.info??null,L=g,F=W?.providerID||"",D=W?.modelID||"";let j;t[22]!==D||t[23]!==L||t[24]!==F?(j=y1(L,F,D),t[22]=D,t[23]=L,t[24]=F,t[25]=j):j=t[25];const A=j,M=A.contextLimit,G=I?null:M&&M>0?Math.min(999,T.total/M*100):0;let q;if(t[26]!==p){const Ke=[...p].reverse().find(I1)?.info?.system||"";q=x1(p,Ke),t[26]=p,t[27]=q}else q=t[27];const Z=q,le=Z.user,X=Z.assistant,te=Z.tool,re=Math.max(0,T.input-le-X-te),Se=le+X+te+re,ue=p[0]?.info?.time?.created,ye=p.length>0?p[p.length-1]?.info?.time?.created:null;let ve;t[28]!==C?.title||t[29]!==e?(ve=C?.title||e("contextSidebar.session.untitled"),t[28]=C?.title,t[29]=e,t[30]=ve):ve=t[30];const be=C?.time?.created??ue??null,_=ye??C?.time?.created??null;let oe;t[31]!==X||t[32]!==re||t[33]!==te||t[34]!==le?(oe={user:le,assistant:X,tool:te,other:re},t[31]=X,t[32]=re,t[33]=te,t[34]=le,t[35]=oe):oe=t[35];let ce;t[36]!==N.length||t[37]!==Se||t[38]!==k||t[39]!==M||t[40]!==A||t[41]!==p.length||t[42]!==ve||t[43]!==be||t[44]!==_||t[45]!==oe||t[46]!==T||t[47]!==O||t[48]!==G||t[49]!==E.length?(ce={sessionTitle:ve,messagesCount:p.length,userMessagesCount:E.length,assistantMessagesCount:N.length,createdAt:be,lastActivityAt:_,providerModel:A,tokenBreakdown:T,usagePercent:G,cacheHitRate:k,totalAssistantCost:O,contextLimit:M,breakdown:oe,breakdownTotal:Se},t[36]=N.length,t[37]=Se,t[38]=k,t[39]=M,t[40]=A,t[41]=p.length,t[42]=ve,t[43]=be,t[44]=_,t[45]=oe,t[46]=T,t[47]=O,t[48]=G,t[49]=E.length,t[50]=ce):ce=t[50];const Q=ce;if(!d){let Ke;t[51]!==e?(Ke=e("contextSidebar.empty.openSession"),t[51]=e,t[52]=Ke):Ke=t[52];let Ye;return t[53]!==Ke?(Ye=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:Ke}),t[53]=Ke,t[54]=Ye):Ye=t[54],Ye}let me;t[55]!==e?(me=e("contextSidebar.breakdown.user"),t[55]=e,t[56]=me):me=t[56];let ke;t[57]!==me||t[58]!==Q.breakdown.user?(ke={key:"user",label:me,value:Q.breakdown.user,color:"var(--status-success)"},t[57]=me,t[58]=Q.breakdown.user,t[59]=ke):ke=t[59];let fe;t[60]!==e?(fe=e("contextSidebar.breakdown.assistant"),t[60]=e,t[61]=fe):fe=t[61];let De;t[62]!==fe||t[63]!==Q.breakdown.assistant?(De={key:"assistant",label:fe,value:Q.breakdown.assistant,color:"var(--primary-base)"},t[62]=fe,t[63]=Q.breakdown.assistant,t[64]=De):De=t[64];let je;t[65]!==e?(je=e("contextSidebar.breakdown.toolCalls"),t[65]=e,t[66]=je):je=t[66];let Y;t[67]!==je||t[68]!==Q.breakdown.tool?(Y={key:"tool",label:je,value:Q.breakdown.tool,color:"var(--status-warning)"},t[67]=je,t[68]=Q.breakdown.tool,t[69]=Y):Y=t[69];let Re;t[70]!==e?(Re=e("contextSidebar.breakdown.other"),t[70]=e,t[71]=Re):Re=t[71];let Ce;t[72]!==Re||t[73]!==Q.breakdown.other?(Ce={key:"other",label:Re,value:Q.breakdown.other,color:"var(--surface-muted-foreground)"},t[72]=Re,t[73]=Q.breakdown.other,t[74]=Ce):Ce=t[74];let Me;t[75]!==ke||t[76]!==De||t[77]!==Y||t[78]!==Ce?(Me=[ke,De,Y,Ce],t[75]=ke,t[76]=De,t[77]=Y,t[78]=Ce,t[79]=Me):Me=t[79];const ae=Me;let ee;t[80]!==Q.sessionTitle?(ee=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:Q.sessionTitle}),t[80]=Q.sessionTitle,t[81]=ee):ee=t[81];let K;t[82]!==Q.providerModel.modelName||t[83]!==Q.providerModel.providerName?(K=s.jsxs("span",{children:[Q.providerModel.providerName," / ",Q.providerModel.modelName]}),t[82]=Q.providerModel.modelName,t[83]=Q.providerModel.providerName,t[84]=K):K=t[84];let $;t[85]!==n||t[86]!==Q.createdAt?($=Q.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:b1(Q.createdAt,n)})]}),t[85]=n,t[86]=Q.createdAt,t[87]=$):$=t[87];let ne;t[88]!==K||t[89]!==$?(ne=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:[K,$]}),t[88]=K,t[89]=$,t[90]=ne):ne=t[90];let U;t[91]!==ee||t[92]!==ne?(U=s.jsxs("div",{className:"mb-6",children:[ee,ne]}),t[91]=ee,t[92]=ne,t[93]=U):U=t[93];let we;t[94]!==e?(we=e("contextSidebar.section.context"),t[94]=e,t[95]=we):we=t[95];let he;t[96]!==we?(he=s.jsx("span",{className:"typography-micro text-muted-foreground",children:we}),t[96]=we,t[97]=he):he=t[97];let Te;t[98]!==Q.tokenBreakdown.total||t[99]!==Q.usagePercent?(Te=Q.usagePercent===null?"—":Hn(Q.tokenBreakdown.total),t[98]=Q.tokenBreakdown.total,t[99]=Q.usagePercent,t[100]=Te):Te=t[100];let Oe;t[101]!==Q.contextLimit?(Oe=Q.contextLimit?` / ${Hn(Q.contextLimit)}`:"",t[101]=Q.contextLimit,t[102]=Oe):Oe=t[102];let _e;t[103]!==Te||t[104]!==Oe?(_e=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[Te,Oe]}),t[103]=Te,t[104]=Oe,t[105]=_e):_e=t[105];let Ve;t[106]!==he||t[107]!==_e?(Ve=s.jsxs("div",{className:"flex items-baseline justify-between",children:[he,_e]}),t[106]=he,t[107]=_e,t[108]=Ve):Ve=t[108];let z;t[109]!==Q.usagePercent?(z=Q.usagePercent!==null&&Q.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,Q.usagePercent)}%`,backgroundColor:Q.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[109]=Q.usagePercent,t[110]=z):z=t[110];let pe;t[111]!==z?(pe=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:z}),t[111]=z,t[112]=pe):pe=t[112];let Ae;t[113]!==e||t[114]!==Q.usagePercent?(Ae=Q.usagePercent===null?e("contextUsage.compacted.description"):e("contextSidebar.context.percentUsed",{percent:Q.usagePercent.toFixed(1)}),t[113]=e,t[114]=Q.usagePercent,t[115]=Ae):Ae=t[115];let Be;t[116]!==Ae?(Be=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Ae}),t[116]=Ae,t[117]=Be):Be=t[117];let rt;t[118]!==Ve||t[119]!==pe||t[120]!==Be?(rt=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Ve,pe,Be]}),t[118]=Ve,t[119]=pe,t[120]=Be,t[121]=rt):rt=t[121];let Ge;t[122]!==e?(Ge=e("contextSidebar.stats.messages"),t[122]=e,t[123]=Ge):Ge=t[123];let ut;t[124]!==Q.messagesCount?(ut=Hn(Q.messagesCount),t[124]=Q.messagesCount,t[125]=ut):ut=t[125];let at;t[126]!==Ge||t[127]!==ut?(at={label:Ge,value:ut},t[126]=Ge,t[127]=ut,t[128]=at):at=t[128];let wt;t[129]!==e?(wt=e("contextSidebar.stats.user"),t[129]=e,t[130]=wt):wt=t[130];let pt;t[131]!==Q.userMessagesCount?(pt=Hn(Q.userMessagesCount),t[131]=Q.userMessagesCount,t[132]=pt):pt=t[132];let It;t[133]!==wt||t[134]!==pt?(It={label:wt,value:pt},t[133]=wt,t[134]=pt,t[135]=It):It=t[135];let Pt;t[136]!==e?(Pt=e("contextSidebar.stats.assistant"),t[136]=e,t[137]=Pt):Pt=t[137];let Rt;t[138]!==Q.assistantMessagesCount?(Rt=Hn(Q.assistantMessagesCount),t[138]=Q.assistantMessagesCount,t[139]=Rt):Rt=t[139];let de;t[140]!==Pt||t[141]!==Rt?(de={label:Pt,value:Rt},t[140]=Pt,t[141]=Rt,t[142]=de):de=t[142];let We;t[143]!==e?(We=e("contextSidebar.stats.cost"),t[143]=e,t[144]=We):We=t[144];let lt;t[145]!==Q.totalAssistantCost?(lt=fx(Q.totalAssistantCost),t[145]=Q.totalAssistantCost,t[146]=lt):lt=t[146];let H;t[147]!==We||t[148]!==lt?(H={label:We,value:lt},t[147]=We,t[148]=lt,t[149]=H):H=t[149];let V;t[150]!==at||t[151]!==It||t[152]!==de||t[153]!==H?(V=[at,It,de,H],t[150]=at,t[151]=It,t[152]=de,t[153]=H,t[154]=V):V=t[154];const J=V;let ge;t[155]!==J?(ge=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:J.map(T1)}),t[155]=J,t[156]=ge):ge=t[156];let Ee;t[157]!==e?(Ee=e("contextSidebar.section.lastAssistantMessage"),t[157]=e,t[158]=Ee):Ee=t[158];let $e;t[159]!==Ee?($e=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:Ee}),t[159]=Ee,t[160]=$e):$e=t[160];let st;t[161]!==e||t[162]!==Q.cacheHitRate.hasInput||t[163]!==Q.cacheHitRate.percent||t[164]!==Q.tokenBreakdown.cacheRead||t[165]!==Q.tokenBreakdown.cacheWrite||t[166]!==Q.tokenBreakdown.input||t[167]!==Q.tokenBreakdown.output||t[168]!==Q.tokenBreakdown.reasoning?(st=s.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:Q.tokenBreakdown.input,format:"count"},{label:e("contextSidebar.tokens.output"),value:Q.tokenBreakdown.output,format:"count"},{label:e("contextSidebar.tokens.reasoning"),value:Q.tokenBreakdown.reasoning,format:"count"},{label:e("contextSidebar.tokens.cacheRead"),value:Q.tokenBreakdown.cacheRead,format:"count"},{label:e("contextSidebar.tokens.cacheWrite"),value:Q.tokenBreakdown.cacheWrite,format:"count"},{label:e("contextSidebar.tokens.cacheHit"),value:Q.cacheHitRate.hasInput?Q.cacheHitRate.percent:null,format:"percent"}].map(E1)}),t[161]=e,t[162]=Q.cacheHitRate.hasInput,t[163]=Q.cacheHitRate.percent,t[164]=Q.tokenBreakdown.cacheRead,t[165]=Q.tokenBreakdown.cacheWrite,t[166]=Q.tokenBreakdown.input,t[167]=Q.tokenBreakdown.output,t[168]=Q.tokenBreakdown.reasoning,t[169]=st):st=t[169];let Ze;t[170]!==$e||t[171]!==st?(Ze=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[$e,st]}),t[170]=$e,t[171]=st,t[172]=Ze):Ze=t[172];let et;t[173]!==ae||t[174]!==Q.breakdownTotal?(et=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ae.map(Ke=>Ke.value<=0||Q.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${Ke.value/Q.breakdownTotal*100}%`,backgroundColor:Ke.color}},Ke.key))}),t[173]=ae,t[174]=Q.breakdownTotal,t[175]=et):et=t[175];let Ue;t[176]!==ae||t[177]!==Q.breakdownTotal?(Ue=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:ae.map(Ke=>{const Ye=Q.breakdownTotal>0?Ke.value/Q.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:Ke.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[Ke.label," ",s.jsxs("span",{className:"tabular-nums",children:[Ye.toFixed(0),"%"]})]})]},Ke.key)})}),t[176]=ae,t[177]=Q.breakdownTotal,t[178]=Ue):Ue=t[178];let jt;t[179]!==et||t[180]!==Ue?(jt=s.jsxs("div",{className:"mb-6",children:[et,Ue]}),t[179]=et,t[180]=Ue,t[181]=jt):jt=t[181];let ze;t[182]!==e?(ze=e("contextSidebar.section.rawMessages"),t[182]=e,t[183]=ze):ze=t[183];let xe;t[184]!==ze?(xe=s.jsx("div",{className:"typography-micro text-muted-foreground",children:ze}),t[184]=ze,t[185]=xe):xe=t[185];let bt;if(t[186]!==l||t[187]!==i||t[188]!==p||t[189]!==e||t[190]!==n){let Ke;t[192]!==l||t[193]!==i||t[194]!==e||t[195]!==n?(Ke=Ye=>{const Mt=eo(Ye.info).role,xt=Mt==="assistant",St=Mt==="user",Tt=i[Ye.info.id]===!0,Jt=l===Ye.info.id,Gt=Ye.info.time?.created??null,$t=l1(Ye.parts),Kt=xt?ic({info:Ye.info,parts:Ye.parts}):null,Ht=St?d1(Ye.parts):"",Qt=f1(Gt,n),Le=$t||"—",qe=Kt?u1(Kt.input,Kt.output,Hn):"",ot=Mt||"unknown",it=$t?`${ot}: ${$t}`:ot,He=Tt?JSON.stringify({info:Ye.info,parts:Ye.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":Tt,onClick:()=>{o(Bt=>({...Bt,[Ye.info.id]:Bt[Ye.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:xt?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[St?s.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",Ht]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:xt?Le:it}),xt&&s.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:qe})]}),s.jsx("span",{className:"text-right text-muted-foreground",children:Qt})]})}),Tt&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:Bt=>{Bt.stopPropagation(),b(Ye.info.id,He)},"aria-label":e(Jt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Jt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Jt?s.jsx(B,{name:"check",className:"size-3.5"}):s.jsx(B,{name:"file-copy",className:"size-3.5"})})}),s.jsx(ap,{language:"json",code:He,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},Ye.info.id)},t[192]=l,t[193]=i,t[194]=e,t[195]=n,t[196]=Ke):Ke=t[196],bt=[...p].reverse().map(Ke),t[186]=l,t[187]=i,t[188]=p,t[189]=e,t[190]=n,t[191]=bt}else bt=t[191];let ht;t[197]!==bt?(ht=s.jsx("div",{className:"mt-2.5 space-y-1",children:bt}),t[197]=bt,t[198]=ht):ht=t[198];let kt;t[199]!==xe||t[200]!==ht?(kt=s.jsxs("div",{children:[xe,ht]}),t[199]=xe,t[200]=ht,t[201]=kt):kt=t[201];let Xe;return t[202]!==U||t[203]!==rt||t[204]!==ge||t[205]!==Ze||t[206]!==jt||t[207]!==kt?(Xe=s.jsx(Sn,{outerClassName:"h-full",className:"bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[U,rt,ge,Ze,jt,kt]})}),t[202]=U,t[203]=rt,t[204]=ge,t[205]=Ze,t[206]=jt,t[207]=kt,t[208]=Xe):Xe=t[208],Xe};function S1(t){return t.timeFormatPreference}function v1(t){return t.currentSessionId}function j1(t){return t.currentSessionDirectory}function k1(t){return t.providers}function C1(t){return Object.keys(t).length>0?{}:t}function N1(t){return eo(t.info).role==="assistant"}function A1(t){return eo(t.info).isUser}function P1(t){return t.info}function D1(t,e){const n=Bn(e.info.cost);return t+n}function I1(t){return eo(t.info).isUser&&typeof t.info.system=="string"}function T1(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 E1(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)}%`:Hn(t.value):"—"})]},t.label)}const cm=new Set(["localhost","127.0.0.1","0.0.0.0","::1","[::1]"]),R1=t=>{const e=t.split("/")[0]?.split("?")[0]??"",n=e.startsWith("[")?e.slice(0,e.indexOf("]")+1):e.split(":")[0]??"";return cm.has(n.toLowerCase())},dn="about:blank",xr=t=>{const e=t.trim();if(!e)return dn;const n=e.includes("://")?e:`${R1(e)?"http":"https"}://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?dn:r.toString()}catch{return dn}},vr=t=>{try{return cm.has(new URL(t).hostname.toLowerCase())}catch{return!1}},Ka=t=>{if(!t||t===dn)return"";try{return new URL(t).host||t}catch{return t}},M1=new Set([-2,-7,-101,-102,-104,-109,-118,-324]),O1=(t,e)=>M1.has(t)&&vr(e),B1=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"},F1=async t=>{try{const e=await bs("/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(B1)}:{kind:"unavailable"}}catch{return{kind:"unavailable"}}},_1=async t=>{try{const e=await bs("/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}},L1=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}},$1=({announced:t,discovered:e})=>{const n=new Map;for(const r of t){const i=L1(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",W1=`(() => {
|
|
12
|
+
try {
|
|
13
|
+
var host = document.querySelector('[data-openchamber-annotation]');
|
|
14
|
+
if (host && host.parentNode) host.parentNode.removeChild(host);
|
|
15
|
+
} catch (error) { /* page navigated away */ }
|
|
16
|
+
try {
|
|
17
|
+
var cursor = document.getElementById('openchamber-annotation-cursor');
|
|
18
|
+
if (cursor && cursor.parentNode) cursor.parentNode.removeChild(cursor);
|
|
19
|
+
} catch (error) { /* page navigated away */ }
|
|
20
|
+
try { delete window['${na}']; } catch (error) { /* non-configurable */ }
|
|
21
|
+
})();`,z1=(t,e)=>{const n=JSON.stringify({theme:t,labels:e});return String.raw`new Promise((resolve) => {
|
|
22
|
+
var CONFIG = ${n};
|
|
23
|
+
var THEME = CONFIG.theme;
|
|
24
|
+
var LABELS = CONFIG.labels;
|
|
25
|
+
var OVERLAY_ATTR = 'data-openchamber-annotation';
|
|
26
|
+
var Z_OVERLAY = 2147483646;
|
|
27
|
+
var MAX_TEXT = 400;
|
|
28
|
+
var MIN_RECT = 3;
|
|
29
|
+
var EDITOR_GAP = 10;
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
var stale = document.querySelector('[' + OVERLAY_ATTR + ']');
|
|
33
|
+
if (stale && stale.parentNode) stale.parentNode.removeChild(stale);
|
|
34
|
+
} catch (error) { /* nothing to clean */ }
|
|
35
|
+
|
|
36
|
+
window['${na}'] = true;
|
|
37
|
+
|
|
38
|
+
var counter = 0;
|
|
39
|
+
var nextId = function (prefix) { counter += 1; return prefix + '-' + counter; };
|
|
40
|
+
|
|
41
|
+
var selected = null;
|
|
42
|
+
var regions = [];
|
|
43
|
+
var strokes = [];
|
|
44
|
+
var tool = 'select';
|
|
45
|
+
var settled = false;
|
|
46
|
+
|
|
47
|
+
// ---------------------------------------------------------------- geometry
|
|
48
|
+
|
|
49
|
+
var rectFrom = function (domRect) {
|
|
50
|
+
return { x: domRect.left, y: domRect.top, width: domRect.width, height: domRect.height };
|
|
51
|
+
};
|
|
52
|
+
var normalizeRect = function (ax, ay, bx, by) {
|
|
53
|
+
return { x: Math.min(ax, bx), y: Math.min(ay, by), width: Math.abs(bx - ax), height: Math.abs(by - ay) };
|
|
54
|
+
};
|
|
55
|
+
var usableRect = function (rect) { return rect.width >= MIN_RECT && rect.height >= MIN_RECT; };
|
|
56
|
+
|
|
57
|
+
// ------------------------------------------------------------- description
|
|
58
|
+
|
|
59
|
+
var isOverlayNode = function (element) {
|
|
60
|
+
var node = element;
|
|
61
|
+
while (node) {
|
|
62
|
+
if (node.nodeType === 1 && node.hasAttribute && node.hasAttribute(OVERLAY_ATTR)) return true;
|
|
63
|
+
node = node.parentNode || (node.host || null);
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
var elementFromPoint = function (x, y) {
|
|
69
|
+
var found = document.elementFromPoint(x, y);
|
|
70
|
+
if (!found || isOverlayNode(found)) return null;
|
|
71
|
+
return found;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
var selectorPart = function (element) {
|
|
75
|
+
var part = element.tagName.toLowerCase();
|
|
76
|
+
if (element.id) return part + '#' + element.id;
|
|
77
|
+
var className = typeof element.className === 'string' ? element.className.trim() : '';
|
|
78
|
+
if (className) {
|
|
79
|
+
var first = className.split(/\s+/).filter(Boolean).slice(0, 2).join('.');
|
|
80
|
+
if (first) part += '.' + first;
|
|
81
|
+
}
|
|
82
|
+
return part;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
var buildSelector = function (element) {
|
|
86
|
+
if (element.id) return '#' + element.id;
|
|
87
|
+
var parts = [];
|
|
88
|
+
var node = element;
|
|
89
|
+
var depth = 0;
|
|
90
|
+
while (node && node.nodeType === 1 && depth < 5) {
|
|
91
|
+
var part = selectorPart(node);
|
|
92
|
+
var parent = node.parentElement;
|
|
93
|
+
if (parent) {
|
|
94
|
+
var siblings = Array.prototype.filter.call(parent.children, function (child) {
|
|
95
|
+
return child.tagName === node.tagName;
|
|
96
|
+
});
|
|
97
|
+
if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
|
|
98
|
+
}
|
|
99
|
+
parts.unshift(part);
|
|
100
|
+
if (node.id) break;
|
|
101
|
+
node = parent;
|
|
102
|
+
depth += 1;
|
|
103
|
+
}
|
|
104
|
+
return parts.join(' > ');
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
var INTERESTING_ATTRS = ['id', 'class', 'name', 'type', 'href', 'src', 'alt', 'title', 'role', 'placeholder', 'aria-label', 'data-testid'];
|
|
108
|
+
var STYLE_PROPS = [
|
|
109
|
+
'display', 'position', 'color', 'backgroundColor', 'fontSize', 'fontWeight', 'fontFamily',
|
|
110
|
+
'lineHeight', 'padding', 'margin', 'border', 'borderRadius', 'width', 'height', 'opacity',
|
|
111
|
+
'zIndex', 'flexDirection', 'justifyContent', 'alignItems', 'gap', 'textAlign'
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
var describe = function (element) {
|
|
115
|
+
var computed = window.getComputedStyle(element);
|
|
116
|
+
var attributes = {};
|
|
117
|
+
for (var i = 0; i < INTERESTING_ATTRS.length; i += 1) {
|
|
118
|
+
var name = INTERESTING_ATTRS[i];
|
|
119
|
+
var value = element.getAttribute(name);
|
|
120
|
+
if (value) attributes[name] = String(value).slice(0, 200);
|
|
121
|
+
}
|
|
122
|
+
var computedStyle = {};
|
|
123
|
+
for (var j = 0; j < STYLE_PROPS.length; j += 1) {
|
|
124
|
+
var prop = STYLE_PROPS[j];
|
|
125
|
+
computedStyle[prop] = String(computed[prop] == null ? '' : computed[prop]);
|
|
126
|
+
}
|
|
127
|
+
var ancestry = [];
|
|
128
|
+
var node = element.parentElement;
|
|
129
|
+
var depth = 0;
|
|
130
|
+
while (node && node.nodeType === 1 && depth < 4) {
|
|
131
|
+
var entry = { tag: node.tagName.toLowerCase(), selectorPart: selectorPart(node) };
|
|
132
|
+
if (node.id) entry.id = node.id;
|
|
133
|
+
var cls = typeof node.className === 'string' ? node.className.trim() : '';
|
|
134
|
+
if (cls) entry.className = cls.slice(0, 200);
|
|
135
|
+
ancestry.unshift(entry);
|
|
136
|
+
node = node.parentElement;
|
|
137
|
+
depth += 1;
|
|
138
|
+
}
|
|
139
|
+
var box = element.getBoundingClientRect();
|
|
140
|
+
var text = (element.textContent == null ? '' : String(element.textContent)).replace(/\s+/g, ' ').trim();
|
|
141
|
+
return {
|
|
142
|
+
tag: element.tagName.toLowerCase(),
|
|
143
|
+
text: text.slice(0, MAX_TEXT),
|
|
144
|
+
selector: buildSelector(element),
|
|
145
|
+
path: ancestry.map(function (e) { return e.selectorPart; }).concat([selectorPart(element)]).join(' > '),
|
|
146
|
+
bounds: rectFrom(box),
|
|
147
|
+
center: { x: box.left + box.width / 2, y: box.top + box.height / 2 },
|
|
148
|
+
attributes: attributes,
|
|
149
|
+
computedStyle: computedStyle,
|
|
150
|
+
ancestry: ancestry
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// ------------------------------------------------------------------ chrome
|
|
155
|
+
|
|
156
|
+
var host = document.createElement('div');
|
|
157
|
+
host.setAttribute(OVERLAY_ATTR, '');
|
|
158
|
+
host.style.cssText = 'position:fixed;inset:0;z-index:' + Z_OVERLAY + ';pointer-events:none';
|
|
159
|
+
var shadow = host.attachShadow({ mode: 'closed' });
|
|
160
|
+
|
|
161
|
+
var style = document.createElement('style');
|
|
162
|
+
style.textContent = [
|
|
163
|
+
':host{all:initial}',
|
|
164
|
+
'*{box-sizing:border-box;font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif}',
|
|
165
|
+
'.layer{position:fixed;inset:0;pointer-events:none}',
|
|
166
|
+
'.box{position:fixed;left:0;top:0;display:none;pointer-events:none;border:1.5px solid ' + THEME.primary + ';background:' + THEME.primarySoft + ';border-radius:2px}',
|
|
167
|
+
'.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}',
|
|
168
|
+
'.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}',
|
|
169
|
+
'.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}',
|
|
170
|
+
'.tools button:hover{background:' + THEME.primaryFaint + '}',
|
|
171
|
+
'.tools button[aria-pressed="true"]{background:' + THEME.primarySoft + ';color:' + THEME.primary + ';font-weight:600}',
|
|
172
|
+
'.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}',
|
|
173
|
+
'.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}',
|
|
174
|
+
'.editor textarea::placeholder{color:' + THEME.mutedText + '}',
|
|
175
|
+
'.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}',
|
|
176
|
+
'.editor button svg{width:16px;height:16px;display:block}',
|
|
177
|
+
'.editor button[disabled]{opacity:.5;cursor:default}'
|
|
178
|
+
].join('');
|
|
179
|
+
shadow.appendChild(style);
|
|
180
|
+
|
|
181
|
+
var cursorStyle = document.createElement('style');
|
|
182
|
+
cursorStyle.id = 'openchamber-annotation-cursor';
|
|
183
|
+
document.head.appendChild(cursorStyle);
|
|
184
|
+
var setCursor = function (value) {
|
|
185
|
+
cursorStyle.textContent = value ? '*{cursor:' + value + ' !important}' : '';
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
var svgNS = 'http://www.w3.org/2000/svg';
|
|
189
|
+
var svg = document.createElementNS(svgNS, 'svg');
|
|
190
|
+
svg.setAttribute('class', 'layer');
|
|
191
|
+
svg.style.overflow = 'visible';
|
|
192
|
+
shadow.appendChild(svg);
|
|
193
|
+
|
|
194
|
+
var hoverBox = document.createElement('div');
|
|
195
|
+
hoverBox.className = 'box';
|
|
196
|
+
var hoverLabel = document.createElement('div');
|
|
197
|
+
hoverLabel.className = 'label';
|
|
198
|
+
var marqueeBox = document.createElement('div');
|
|
199
|
+
marqueeBox.className = 'box';
|
|
200
|
+
shadow.append(hoverBox, hoverLabel, marqueeBox);
|
|
201
|
+
|
|
202
|
+
var positionBox = function (node, rect) {
|
|
203
|
+
node.style.display = 'block';
|
|
204
|
+
node.style.transform = 'translate(' + rect.x + 'px,' + rect.y + 'px)';
|
|
205
|
+
node.style.width = rect.width + 'px';
|
|
206
|
+
node.style.height = rect.height + 'px';
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
var tools = document.createElement('div');
|
|
210
|
+
tools.className = 'tools';
|
|
211
|
+
shadow.appendChild(tools);
|
|
212
|
+
|
|
213
|
+
var toolButtons = {};
|
|
214
|
+
[['select', LABELS.select], ['marquee', LABELS.marquee], ['draw', LABELS.draw]].forEach(function (entry) {
|
|
215
|
+
var button = document.createElement('button');
|
|
216
|
+
button.type = 'button';
|
|
217
|
+
button.textContent = entry[1];
|
|
218
|
+
button.addEventListener('click', function () { setTool(entry[0]); });
|
|
219
|
+
toolButtons[entry[0]] = button;
|
|
220
|
+
tools.appendChild(button);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
var editor = document.createElement('div');
|
|
224
|
+
editor.className = 'editor';
|
|
225
|
+
shadow.appendChild(editor);
|
|
226
|
+
|
|
227
|
+
var comment = document.createElement('textarea');
|
|
228
|
+
comment.rows = 1;
|
|
229
|
+
comment.placeholder = LABELS.commentPlaceholder;
|
|
230
|
+
var submit = document.createElement('button');
|
|
231
|
+
submit.type = 'button';
|
|
232
|
+
// Icon-only attach button (Remix attachment-2), matching the chat comment
|
|
233
|
+
// input; the localized label stays available to assistive tech.
|
|
234
|
+
submit.setAttribute('aria-label', LABELS.submit);
|
|
235
|
+
submit.title = LABELS.submit;
|
|
236
|
+
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>';
|
|
237
|
+
editor.append(comment, submit);
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Grows the box with its content.
|
|
241
|
+
*
|
|
242
|
+
* A hidden element reports scrollHeight 0, so measuring one collapses the
|
|
243
|
+
* field to nothing — which is what left a sliver of a click target and an
|
|
244
|
+
* invisible caret. Measuring only while visible, and never below the CSS
|
|
245
|
+
* min-height, keeps it usable.
|
|
246
|
+
*/
|
|
247
|
+
var resizeComment = function () {
|
|
248
|
+
if (editor.style.display === 'none') return;
|
|
249
|
+
comment.style.height = 'auto';
|
|
250
|
+
comment.style.height = Math.max(32, Math.min(comment.scrollHeight, 104)) + 'px';
|
|
251
|
+
};
|
|
252
|
+
comment.addEventListener('input', resizeComment);
|
|
253
|
+
|
|
254
|
+
// -------------------------------------------------------------- selection
|
|
255
|
+
|
|
256
|
+
var lastTargetRect = null;
|
|
257
|
+
|
|
258
|
+
/** Places the comment box under whatever was just marked, kept on screen. */
|
|
259
|
+
var positionEditor = function () {
|
|
260
|
+
if (!lastTargetRect) {
|
|
261
|
+
editor.style.display = 'none';
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
var wasHidden = editor.style.display === 'none';
|
|
265
|
+
editor.style.display = 'flex';
|
|
266
|
+
// Measured now that it is laid out, not while it was still hidden.
|
|
267
|
+
if (wasHidden) resizeComment();
|
|
268
|
+
var box = editor.getBoundingClientRect();
|
|
269
|
+
var left = lastTargetRect.x + lastTargetRect.width / 2 - box.width / 2;
|
|
270
|
+
var top = lastTargetRect.y + lastTargetRect.height + EDITOR_GAP;
|
|
271
|
+
// Above the target when there is no room below, so the box is never left
|
|
272
|
+
// half off the bottom of the page.
|
|
273
|
+
if (top + box.height > window.innerHeight - 8) {
|
|
274
|
+
top = Math.max(8, lastTargetRect.y - box.height - EDITOR_GAP);
|
|
275
|
+
}
|
|
276
|
+
left = Math.max(8, Math.min(left, window.innerWidth - box.width - 8));
|
|
277
|
+
editor.style.transform = 'translate(' + Math.round(left) + 'px,' + Math.round(top) + 'px)';
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/** Focus after layout: focusing a zero-height field puts the caret nowhere. */
|
|
281
|
+
var focusComment = function () {
|
|
282
|
+
requestAnimationFrame(function () {
|
|
283
|
+
try {
|
|
284
|
+
comment.focus({ preventScroll: true });
|
|
285
|
+
comment.setSelectionRange(comment.value.length, comment.value.length);
|
|
286
|
+
} catch (error) { /* field went away */ }
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
var hasTargets = function () {
|
|
291
|
+
return Boolean(selected) || regions.length > 0 || strokes.length > 0;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
var syncChrome = function () {
|
|
295
|
+
submit.disabled = !hasTargets();
|
|
296
|
+
if (!hasTargets()) {
|
|
297
|
+
lastTargetRect = null;
|
|
298
|
+
editor.style.display = 'none';
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
positionEditor();
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
var syncSelectionVisuals = function () {
|
|
305
|
+
if (!selected) return;
|
|
306
|
+
var rect = rectFrom(selected.element.getBoundingClientRect());
|
|
307
|
+
if (!usableRect(rect)) {
|
|
308
|
+
selected.outline.style.display = 'none';
|
|
309
|
+
selected.badge.style.display = 'none';
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
positionBox(selected.outline, rect);
|
|
313
|
+
selected.badge.style.display = 'block';
|
|
314
|
+
selected.badge.style.transform = 'translate(' + Math.max(2, rect.x) + 'px,' + Math.max(2, rect.y - 19) + 'px)';
|
|
315
|
+
lastTargetRect = rect;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
var dropSelection = function () {
|
|
319
|
+
if (!selected) return;
|
|
320
|
+
selected.outline.remove();
|
|
321
|
+
selected.badge.remove();
|
|
322
|
+
selected = null;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
var selectElement = function (element) {
|
|
326
|
+
var wasSelected = selected && selected.element === element;
|
|
327
|
+
dropSelection();
|
|
328
|
+
if (wasSelected) {
|
|
329
|
+
// Clicking the chosen element again clears it, so a misclick costs one
|
|
330
|
+
// click rather than starting over.
|
|
331
|
+
lastTargetRect = null;
|
|
332
|
+
syncChrome();
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
var outline = document.createElement('div');
|
|
336
|
+
outline.className = 'box';
|
|
337
|
+
var badge = document.createElement('div');
|
|
338
|
+
badge.className = 'label';
|
|
339
|
+
badge.textContent = selectorPart(element);
|
|
340
|
+
shadow.append(outline, badge);
|
|
341
|
+
selected = { id: nextId('element'), element: element, outline: outline, badge: badge };
|
|
342
|
+
syncSelectionVisuals();
|
|
343
|
+
syncChrome();
|
|
344
|
+
focusComment();
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
var setTool = function (next) {
|
|
348
|
+
tool = next;
|
|
349
|
+
hoverBox.style.display = 'none';
|
|
350
|
+
hoverLabel.style.display = 'none';
|
|
351
|
+
marqueeBox.style.display = 'none';
|
|
352
|
+
setCursor(next === 'select' ? '' : 'crosshair');
|
|
353
|
+
for (var key in toolButtons) {
|
|
354
|
+
if (Object.prototype.hasOwnProperty.call(toolButtons, key)) {
|
|
355
|
+
toolButtons[key].setAttribute('aria-pressed', key === next ? 'true' : 'false');
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// ------------------------------------------------------------- interaction
|
|
361
|
+
|
|
362
|
+
var drag = null;
|
|
363
|
+
|
|
364
|
+
var onPointerMove = function (event) {
|
|
365
|
+
if (drag) {
|
|
366
|
+
if (drag.kind === 'marquee') {
|
|
367
|
+
drag.rect = normalizeRect(drag.startX, drag.startY, event.clientX, event.clientY);
|
|
368
|
+
positionBox(marqueeBox, drag.rect);
|
|
369
|
+
} else if (drag.kind === 'draw') {
|
|
370
|
+
drag.points.push({ x: event.clientX, y: event.clientY });
|
|
371
|
+
drag.path.setAttribute('d', drag.points.map(function (point, index) {
|
|
372
|
+
return (index === 0 ? 'M' : 'L') + point.x + ' ' + point.y;
|
|
373
|
+
}).join(' '));
|
|
374
|
+
}
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (tool !== 'select') return;
|
|
379
|
+
var element = elementFromPoint(event.clientX, event.clientY);
|
|
380
|
+
if (!element) {
|
|
381
|
+
hoverBox.style.display = 'none';
|
|
382
|
+
hoverLabel.style.display = 'none';
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
var rect = rectFrom(element.getBoundingClientRect());
|
|
386
|
+
positionBox(hoverBox, rect);
|
|
387
|
+
hoverLabel.textContent = selectorPart(element);
|
|
388
|
+
hoverLabel.style.display = 'block';
|
|
389
|
+
hoverLabel.style.transform = 'translate(' + Math.max(2, rect.x) + 'px,' + Math.max(2, rect.y - 19) + 'px)';
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
var onPointerDown = function (event) {
|
|
393
|
+
if (event.button !== 0) return;
|
|
394
|
+
if (isOverlayNode(event.target)) return;
|
|
395
|
+
event.preventDefault();
|
|
396
|
+
event.stopPropagation();
|
|
397
|
+
|
|
398
|
+
if (tool === 'select') {
|
|
399
|
+
var element = elementFromPoint(event.clientX, event.clientY);
|
|
400
|
+
if (element) selectElement(element);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (tool === 'marquee') {
|
|
405
|
+
drag = { kind: 'marquee', startX: event.clientX, startY: event.clientY, rect: null };
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
var path = document.createElementNS(svgNS, 'path');
|
|
410
|
+
path.setAttribute('fill', 'none');
|
|
411
|
+
path.setAttribute('stroke', THEME.primary);
|
|
412
|
+
path.setAttribute('stroke-width', '2.5');
|
|
413
|
+
path.setAttribute('stroke-linecap', 'round');
|
|
414
|
+
path.setAttribute('stroke-linejoin', 'round');
|
|
415
|
+
svg.appendChild(path);
|
|
416
|
+
drag = { kind: 'draw', path: path, points: [{ x: event.clientX, y: event.clientY }] };
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
var onPointerUp = function () {
|
|
420
|
+
if (!drag) return;
|
|
421
|
+
var finished = drag;
|
|
422
|
+
drag = null;
|
|
423
|
+
|
|
424
|
+
if (finished.kind === 'marquee') {
|
|
425
|
+
marqueeBox.style.display = 'none';
|
|
426
|
+
var rect = finished.rect;
|
|
427
|
+
if (!rect || !usableRect(rect)) return;
|
|
428
|
+
// A region marks an area, not the elements inside it: expanding it into a
|
|
429
|
+
// selection made the result depend on the page's markup rather than on
|
|
430
|
+
// what was drawn.
|
|
431
|
+
regions.push({ id: nextId('region'), rect: rect });
|
|
432
|
+
var outline = document.createElementNS(svgNS, 'rect');
|
|
433
|
+
outline.setAttribute('x', String(rect.x));
|
|
434
|
+
outline.setAttribute('y', String(rect.y));
|
|
435
|
+
outline.setAttribute('width', String(rect.width));
|
|
436
|
+
outline.setAttribute('height', String(rect.height));
|
|
437
|
+
outline.style.fill = THEME.primarySoft;
|
|
438
|
+
outline.setAttribute('stroke', THEME.primary);
|
|
439
|
+
outline.setAttribute('stroke-width', '1.5');
|
|
440
|
+
outline.setAttribute('rx', '2');
|
|
441
|
+
svg.appendChild(outline);
|
|
442
|
+
lastTargetRect = rect;
|
|
443
|
+
syncChrome();
|
|
444
|
+
focusComment();
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
var points = finished.points;
|
|
449
|
+
if (points.length < 2) {
|
|
450
|
+
if (finished.path.parentNode) finished.path.parentNode.removeChild(finished.path);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
var minX = points[0].x, minY = points[0].y, maxX = points[0].x, maxY = points[0].y;
|
|
454
|
+
for (var p = 1; p < points.length; p += 1) {
|
|
455
|
+
minX = Math.min(minX, points[p].x);
|
|
456
|
+
minY = Math.min(minY, points[p].y);
|
|
457
|
+
maxX = Math.max(maxX, points[p].x);
|
|
458
|
+
maxY = Math.max(maxY, points[p].y);
|
|
459
|
+
}
|
|
460
|
+
var bounds = { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
461
|
+
strokes.push({ id: nextId('stroke'), points: points, bounds: bounds });
|
|
462
|
+
lastTargetRect = bounds;
|
|
463
|
+
syncChrome();
|
|
464
|
+
focusComment();
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Swallows the page's own mouse handling while annotating.
|
|
469
|
+
*
|
|
470
|
+
* Blocking pointerdown is not enough: a click still follows it, so marking a
|
|
471
|
+
* button pressed that button and marking a link navigated away from the page
|
|
472
|
+
* being annotated. These are the events that reach page code, so these are
|
|
473
|
+
* the ones that have to stop.
|
|
474
|
+
*/
|
|
475
|
+
var blockPageInteraction = function (event) {
|
|
476
|
+
if (isOverlayNode(event.target)) return;
|
|
477
|
+
event.preventDefault();
|
|
478
|
+
event.stopPropagation();
|
|
479
|
+
};
|
|
480
|
+
var BLOCKED_EVENTS = ['click', 'auxclick', 'dblclick', 'mousedown', 'mouseup', 'contextmenu'];
|
|
481
|
+
|
|
482
|
+
var onScrollOrResize = function () {
|
|
483
|
+
syncSelectionVisuals();
|
|
484
|
+
positionEditor();
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
var onKeyDown = function (event) {
|
|
488
|
+
if (event.isComposing || event.keyCode === 229) return;
|
|
489
|
+
if (event.key === 'Escape') {
|
|
490
|
+
event.preventDefault();
|
|
491
|
+
event.stopImmediatePropagation();
|
|
492
|
+
finish(null);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
var onCommentKeyDown = function (event) {
|
|
497
|
+
// Do not let the annotated page treat typed letters as its own shortcuts.
|
|
498
|
+
event.stopPropagation();
|
|
499
|
+
// WebKit can report the composition-confirming Enter as keyCode 229.
|
|
500
|
+
if (event.isComposing || event.keyCode === 229) return;
|
|
501
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
502
|
+
event.preventDefault();
|
|
503
|
+
attach();
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
document.addEventListener('pointermove', onPointerMove, true);
|
|
508
|
+
document.addEventListener('pointerdown', onPointerDown, true);
|
|
509
|
+
document.addEventListener('pointerup', onPointerUp, true);
|
|
510
|
+
BLOCKED_EVENTS.forEach(function (name) {
|
|
511
|
+
window.addEventListener(name, blockPageInteraction, { capture: true, passive: false });
|
|
512
|
+
});
|
|
513
|
+
window.addEventListener('scroll', onScrollOrResize, true);
|
|
514
|
+
window.addEventListener('resize', onScrollOrResize, true);
|
|
515
|
+
window.addEventListener('keydown', onKeyDown, true);
|
|
516
|
+
comment.addEventListener('keydown', onCommentKeyDown);
|
|
517
|
+
|
|
518
|
+
// ------------------------------------------------------------------ finish
|
|
519
|
+
|
|
520
|
+
var teardown = function () {
|
|
521
|
+
document.removeEventListener('pointermove', onPointerMove, true);
|
|
522
|
+
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
523
|
+
document.removeEventListener('pointerup', onPointerUp, true);
|
|
524
|
+
BLOCKED_EVENTS.forEach(function (name) {
|
|
525
|
+
window.removeEventListener(name, blockPageInteraction, true);
|
|
526
|
+
});
|
|
527
|
+
window.removeEventListener('scroll', onScrollOrResize, true);
|
|
528
|
+
window.removeEventListener('resize', onScrollOrResize, true);
|
|
529
|
+
window.removeEventListener('keydown', onKeyDown, true);
|
|
530
|
+
comment.removeEventListener('keydown', onCommentKeyDown);
|
|
531
|
+
setCursor('');
|
|
532
|
+
if (cursorStyle.parentNode) cursorStyle.parentNode.removeChild(cursorStyle);
|
|
533
|
+
if (host.parentNode) host.parentNode.removeChild(host);
|
|
534
|
+
try { delete window['${na}']; } catch (error) { /* non-configurable */ }
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
var finish = function (payload) {
|
|
538
|
+
if (settled) return;
|
|
539
|
+
settled = true;
|
|
540
|
+
teardown();
|
|
541
|
+
// Removing the chrome is not enough: the host screenshots this page right
|
|
542
|
+
// after we resolve, and the compositor can still hold a frame containing
|
|
543
|
+
// our outlines. Yield two frames so the page has actually repainted.
|
|
544
|
+
requestAnimationFrame(function () {
|
|
545
|
+
requestAnimationFrame(function () { resolve(payload); });
|
|
546
|
+
});
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
var attach = function () {
|
|
550
|
+
if (!hasTargets()) return;
|
|
551
|
+
finish({
|
|
552
|
+
id: 'annotation-' + Date.now(),
|
|
553
|
+
pageUrl: String(location.href),
|
|
554
|
+
pageTitle: String(document.title || ''),
|
|
555
|
+
viewport: { width: window.innerWidth, height: window.innerHeight },
|
|
556
|
+
devicePixelRatio: window.devicePixelRatio || 1,
|
|
557
|
+
comment: comment.value,
|
|
558
|
+
// Zero or one element, never more. Kept as a list so elements, regions
|
|
559
|
+
// and strokes stay one uniform shape for everything downstream.
|
|
560
|
+
elements: selected ? [{ id: selected.id, element: describe(selected.element) }] : [],
|
|
561
|
+
regions: regions.map(function (entry) { return { id: entry.id, rect: entry.rect }; }),
|
|
562
|
+
strokes: strokes.map(function (entry) {
|
|
563
|
+
return { id: entry.id, points: entry.points, bounds: entry.bounds };
|
|
564
|
+
})
|
|
565
|
+
});
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
submit.addEventListener('click', attach);
|
|
569
|
+
|
|
570
|
+
(document.body || document.documentElement).appendChild(host);
|
|
571
|
+
setTool('select');
|
|
572
|
+
syncChrome();
|
|
573
|
+
});`},V1={kind:"idle"},vn=t=>typeof t=="object"&&t!==null,Nn=t=>typeof t=="number"&&Number.isFinite(t),lc=t=>vn(t)&&Object.values(t).every(e=>typeof e=="string"),Ha=t=>vn(t)&&Nn(t.x)&&Nn(t.y)&&Nn(t.width)&&Nn(t.height),dm=t=>vn(t)&&Nn(t.x)&&Nn(t.y),U1=t=>vn(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"),K1=t=>vn(t)&&typeof t.tag=="string"&&typeof t.text=="string"&&typeof t.selector=="string"&&typeof t.path=="string"&&Ha(t.bounds)&&dm(t.center)&&lc(t.attributes)&&lc(t.computedStyle)&&Array.isArray(t.ancestry)&&t.ancestry.every(U1),H1=t=>vn(t)&&typeof t.id=="string"&&K1(t.element),G1=t=>vn(t)&&typeof t.id=="string"&&Ha(t.rect),q1=t=>vn(t)&&typeof t.id=="string"&&Ha(t.bounds)&&Array.isArray(t.points)&&t.points.every(dm),Q1=t=>vn(t)&&typeof t.id=="string"&&typeof t.pageUrl=="string"&&typeof t.pageTitle=="string"&&typeof t.comment=="string"&&vn(t.viewport)&&Nn(t.viewport.width)&&Nn(t.viewport.height)&&Nn(t.devicePixelRatio)&&Array.isArray(t.elements)&&t.elements.every(H1)&&Array.isArray(t.regions)&&t.regions.every(G1)&&Array.isArray(t.strokes)&&t.strokes.every(q1),Y1=1600,X1=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}),J1=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 X1(`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,Y1/h),v=document.createElement("canvas");v.width=Math.max(1,Math.floor(h*w)),v.height=Math.max(1,Math.floor(f*w));const y=v.getContext("2d");if(!y)return null;y.scale(w,w),y.drawImage(d,0,0,h,f);const m=C=>({x:C.x*p,y:C.y*g,width:C.width*p,height:C.height*g}),x=Math.max(2,2.5*p/Math.max(w,.2));y.strokeStyle=a,y.fillStyle=u;const b=C=>{const N=m(C);y.lineWidth=x,y.fillRect(N.x,N.y,N.width,N.height),y.strokeRect(N.x,N.y,N.width,N.height)};for(const C of l.elements)b(C.element.bounds);for(const C of l.regions)b(C.rect);for(const C of l.strokes)C.points.length<2||(y.beginPath(),C.points.forEach((N,k)=>{const R=N.x*p,I=N.y*g;k===0?y.moveTo(R,I):y.lineTo(R,I)}),y.lineCap="round",y.lineJoin="round",y.lineWidth=x*1.4,y.stroke());const S=await new Promise(C=>v.toBlob(C,"image/jpeg",.85));return S?new File([S],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Z1="({ width: window.innerWidth, height: window.innerHeight })",ew=async t=>{try{const e=await t.executeJavaScript(Z1,!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(W1,!1)}catch{}},tw=async({host:t,theme:e,labels:n})=>{const r=z1(e,n),i=await t.executeJavaScript(r,!0);if(i==null)return null;if(!Q1(i))return await jo(t),null;const o=i;try{const l=await ew(t)??o.viewport,a=await t.capturePage();if(!a||!a.base64)return{payload:o,screenshot:null};const u=await J1({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}}},ln={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)"},sw=()=>{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()}},nw=t=>{const e=sw();if(!e)return{...ln,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)`)||ln.glassSurface,glassFilter:`blur(${o}) saturate(${l})`,primary:n("--primary",ln.primary),primarySoft:r("--primary",16,ln.primarySoft),primaryFaint:r("--primary",10,ln.primaryFaint),primaryContrast:n("--primary-foreground",ln.primaryContrast),surface:n("--surface-background",ln.surface),surfaceElevated:n("--surface-elevated",ln.surfaceElevated),border:n("--border",ln.border),text:n("--foreground",ln.text),mutedText:n("--muted-foreground",ln.mutedText)}}catch{return{...ln,colorScheme:t}}finally{e.dispose()}},rw=2e3,ow=50;let Zn=null,br=null,Wr=null;const iw=async t=>{try{const e=await bs("/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}},ar=async(t,e)=>{try{const n=await bs("/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)}},aw=async(t=rw)=>{const e=Date.now()+t;for(;!Zn&&Date.now()<e;)await new Promise(n=>setTimeout(n,ow));return Zn},lw=async t=>{const e=t.action==="browser.open",n=Zn;if(!(!n&&!(e&&br))&&await iw(t.requestId))try{if(e&&!n){const i=typeof t.parameters.url=="string"?t.parameters.url:"";if(!i){await ar(t.requestId,{ok:!1,error:"url is required"});return}br?.(i);const o=typeof t.parameters.viewport=="string"?t.parameters.viewport:"";if(!o||o==="fill"){await ar(t.requestId,{ok:!0,data:{url:i,opened:!0}});return}const l=await aw();if(!l){await ar(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 ar(t.requestId,{ok:!0,data:{url:i,opened:!0,viewportApplied:!0,viewport:u}});return}const r=await n.run(t.action,t.parameters);await ar(t.requestId,{ok:!0,data:r})}catch(r){await ar(t.requestId,{ok:!1,error:r instanceof Error?r.message:String(r)})}},um=()=>{Wr||(Wr=to(t=>{t.type==="browser-control-request"&&lw({requestId:t.requestId,action:t.action,parameters:t.parameters})}))},mm=()=>{Zn||br||!Wr||(Wr(),Wr=null)},cw=t=>(Zn=t,um(),()=>{Zn===t&&(Zn=null),mm()}),dw=t=>(br=t,um(),()=>{br===t&&(br=null),mm()}),uw=50,mw=6,fw=2048,hw=200,fm=t=>{const e=xr(String(t??"").trim());if(!e||e.length>fw)return"";try{const n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?"":n.toString()}catch{return""}},pw=(t,e)=>{const n=fm(e.url);if(!n)return t;const r=t.find(l=>l.url===n),i=String(e.title??"").trim().slice(0,hw)||r?.title||"";return[{url:n,title:i,lastVisitedAt:e.at},...t.filter(l=>l.url!==n)].slice(0,uw)},gw=(t,e)=>{const n=fm(e);return t.filter(r=>r.url!==n)},xw=t=>`${t.url.replace(/^https?:\/\//,"")} ${t.title}`.toLowerCase(),hm=(t,e,n=mw)=>{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=xw(l);return l.url===r||a===o?!1:a.includes(o)}).slice(0,n)},cc=20,ko=t=>{const e=ft((t||"").trim());return e?JSON.stringify([ls(),e]):""},bw=t=>{const e=Object.keys(t);if(e.length<=cc)return t;const n=e.map(r=>[r,t[r]?.[0]?.lastVisitedAt??0]).sort((r,i)=>i[1]-r[1]).slice(0,cc);return Object.fromEntries(n.map(([r])=>[r,t[r]??[]]))},yr=or()(Tx(t=>({byProject:{},recordVisit:(e,n)=>{const r=ko(e);r&&t(i=>{const o=i.byProject[r]??[],l=pw(o,{...n,at:Date.now()});return l===o?i:{byProject:bw({...i.byProject,[r]:l})}})},forget:(e,n)=>{const r=ko(e);r&&t(i=>{const o=i.byProject[r];return o?{byProject:{...i.byProject,[r]:gw(o,n)}}:i})},clear:e=>{const n=ko(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:jf(),partialize:t=>({byProject:t.byProject})})),yw=[],pm=t=>e=>{const n=ko(t);return(n?e.byProject[n]:void 0)??yw},ra=new Map,ni=new Map,er=new Map,tr=new Set,ww=async(t,e)=>{if(!Za()){tr.delete(t),cr(t,{type:"close"});return}if(await kf(Pn()),!tr.has(t)||!Za())return;const n=ya().websocket(`/api/dev-tunnel?port=${e}`),r=Cf(n);er.set(t,r),r.binaryType="arraybuffer",r.onopen=()=>cr(t,{type:"ready"}),r.onmessage=i=>cr(t,{type:"data",data:i.data instanceof ArrayBuffer?i.data:new TextEncoder().encode(i.data)}),r.onerror=()=>cr(t,{type:"close"}),r.onclose=()=>{tr.delete(t),er.delete(t),cr(t,{type:"close"})}};lp(({connectionId:t,remotePort:e,message:n})=>{switch(n.type){case"data":{const r=er.get(t);r&&n.data&&r.send(n.data);return}case"close":tr.delete(t),er.get(t)?.close(),er.delete(t);return;case"connect":tr.add(t),ww(t,e).catch(()=>{tr.delete(t),cr(t,{type:"close"})})}});const gm=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,xm=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}},bm=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}},dc=(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}},uc=(t,e)=>{try{ni.set(e,new URL(t).origin)}catch{}};class zr extends Error{constructor(e){super(e),this.name="DevTunnelUnavailableError"}}const mc=async t=>{if(!t||!gm()||!vr(t))return t;const e=Pn();if(!xm(e))return t;const n=bm(t);if(!n)return t;const r=`${e}|${n}`,i=ra.get(r);if(i)return uc(t,i),dc(t,i);try{const o=await pr("desktop_dev_tunnel_open",{baseUrl:e,port:n,relay:Nf(),targetKey:ls(),clientToken:Kr(),requestHeaders:kd()});if(!o||!Number.isInteger(o.localPort)||o.localPort<=0)throw new zr(t);return ra.set(r,o.localPort),uc(t,o.localPort),dc(t,o.localPort)}catch(o){throw o instanceof zr?o:new zr(t)}},fc=t=>{if(!t||!gm()||!vr(t)||!xm(Pn()))return!1;const e=bm(t);return e>0&&!ni.has(e)},Ir=t=>{if(!t)return t;try{const e=new URL(t);if(e.hostname!=="127.0.0.1")return t;const n=ni.get(Number.parseInt(e.port||"0",10));return n?`${n}${e.pathname}${e.search}${e.hash}`:t}catch{return t}},Sw=()=>{ra.clear(),ni.clear(),tr.clear();for(const t of er.values())t.close();er.clear(),pr("desktop_relay_dev_tunnel_close_all").catch(()=>{})};typeof window<"u"&&Go(Sw);const hc=6e3,vw=120,jw=80,kw=`
|
|
574
|
+
var MAX_ELEMENTS = ${vw};
|
|
575
|
+
var MAX_LABEL_CHARS = ${jw};
|
|
576
|
+
var visible = function (element) {
|
|
577
|
+
var rect = element.getBoundingClientRect();
|
|
578
|
+
if (rect.width < 1 || rect.height < 1) return false;
|
|
579
|
+
var style = window.getComputedStyle(element);
|
|
580
|
+
return style.visibility !== 'hidden' && style.display !== 'none' && Number(style.opacity) !== 0;
|
|
581
|
+
};
|
|
582
|
+
var label = function (element) {
|
|
583
|
+
var aria = element.getAttribute('aria-label');
|
|
584
|
+
if (aria) return aria.trim();
|
|
585
|
+
var value = element.getAttribute('value');
|
|
586
|
+
var text = (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim();
|
|
587
|
+
if (text) return text.slice(0, MAX_LABEL_CHARS);
|
|
588
|
+
if (value) return String(value).slice(0, MAX_LABEL_CHARS);
|
|
589
|
+
var placeholder = element.getAttribute('placeholder');
|
|
590
|
+
return placeholder ? placeholder.trim().slice(0, MAX_LABEL_CHARS) : '';
|
|
591
|
+
};
|
|
592
|
+
var isUnique = function (selector) {
|
|
593
|
+
try {
|
|
594
|
+
return document.querySelectorAll(selector).length === 1;
|
|
595
|
+
} catch (error) {
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Names an element by what it is, falling back to where it sits.
|
|
602
|
+
*
|
|
603
|
+
* A positional chain like 'main > section:nth-of-type(3) > div > a' survives
|
|
604
|
+
* only until the markup shifts, and says nothing about what it points at.
|
|
605
|
+
* Anything the page states about identity — an id, a test id, an accessible
|
|
606
|
+
* name — outlives edits and reads as the thing it selects. The chain remains
|
|
607
|
+
* as the last resort, because something always has to work.
|
|
608
|
+
*/
|
|
609
|
+
var cssPath = function (element) {
|
|
610
|
+
var tag = element.tagName.toLowerCase();
|
|
611
|
+
|
|
612
|
+
if (element.id) {
|
|
613
|
+
var byId = '#' + CSS.escape(element.id);
|
|
614
|
+
if (isUnique(byId)) return byId;
|
|
615
|
+
}
|
|
616
|
+
var stableAttrs = ['data-testid', 'data-test-id', 'data-test', 'name', 'aria-label'];
|
|
617
|
+
for (var a = 0; a < stableAttrs.length; a += 1) {
|
|
618
|
+
var value = element.getAttribute(stableAttrs[a]);
|
|
619
|
+
if (!value) continue;
|
|
620
|
+
var raw = String(value);
|
|
621
|
+
// A value containing a quote would need escaping for no real gain: such
|
|
622
|
+
// attributes are rare, and the positional chain still covers them.
|
|
623
|
+
if (raw.indexOf('"') !== -1) continue;
|
|
624
|
+
var byAttr = tag + '[' + stableAttrs[a] + '="' + raw + '"]';
|
|
625
|
+
if (isUnique(byAttr)) return byAttr;
|
|
626
|
+
}
|
|
627
|
+
var className = typeof element.className === 'string' ? element.className.trim() : '';
|
|
628
|
+
if (className) {
|
|
629
|
+
var classes = className.split(/\\s+/).filter(Boolean);
|
|
630
|
+
for (var c = 0; c < classes.length; c += 1) {
|
|
631
|
+
var byClass = tag + '.' + CSS.escape(classes[c]);
|
|
632
|
+
if (isUnique(byClass)) return byClass;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
var parts = [];
|
|
637
|
+
var node = element;
|
|
638
|
+
var depth = 0;
|
|
639
|
+
while (node && node.nodeType === 1 && depth < 6) {
|
|
640
|
+
var part = node.tagName.toLowerCase();
|
|
641
|
+
var parent = node.parentElement;
|
|
642
|
+
if (!parent) { parts.unshift(part); break; }
|
|
643
|
+
var siblings = Array.prototype.filter.call(parent.children, function (child) {
|
|
644
|
+
return child.tagName === node.tagName;
|
|
645
|
+
});
|
|
646
|
+
if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
|
|
647
|
+
parts.unshift(part);
|
|
648
|
+
if (node.id) { parts[0] = '#' + CSS.escape(node.id); break; }
|
|
649
|
+
node = parent;
|
|
650
|
+
depth += 1;
|
|
651
|
+
}
|
|
652
|
+
return parts.join(' > ');
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
/** What a screen reader would announce, or '' when there is nothing to say. */
|
|
656
|
+
var accessibleName = function (element) {
|
|
657
|
+
var aria = element.getAttribute('aria-label');
|
|
658
|
+
if (aria && aria.trim()) return aria.trim();
|
|
659
|
+
var labelled = element.getAttribute('aria-labelledby');
|
|
660
|
+
if (labelled) {
|
|
661
|
+
var source = document.getElementById(labelled.split(/\\s+/)[0]);
|
|
662
|
+
if (source && (source.innerText || '').trim()) return source.innerText.trim();
|
|
663
|
+
}
|
|
664
|
+
var title = element.getAttribute('title');
|
|
665
|
+
if (title && title.trim()) return title.trim();
|
|
666
|
+
var alt = element.getAttribute('alt');
|
|
667
|
+
if (alt && alt.trim()) return alt.trim();
|
|
668
|
+
var text = (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim();
|
|
669
|
+
if (text) return text;
|
|
670
|
+
var value = element.getAttribute('value');
|
|
671
|
+
return value && String(value).trim() ? String(value).trim() : '';
|
|
672
|
+
};
|
|
673
|
+
var findByText = function (needle) {
|
|
674
|
+
var wanted = String(needle).replace(/\\s+/g, ' ').trim().toLowerCase();
|
|
675
|
+
var candidates = document.querySelectorAll('a, button, [role="button"], [role="link"], input[type="submit"], input[type="button"], summary, label');
|
|
676
|
+
var exact = null;
|
|
677
|
+
var partial = null;
|
|
678
|
+
for (var i = 0; i < candidates.length; i += 1) {
|
|
679
|
+
var element = candidates[i];
|
|
680
|
+
if (!visible(element)) continue;
|
|
681
|
+
var text = label(element).toLowerCase();
|
|
682
|
+
if (!text) continue;
|
|
683
|
+
if (text === wanted) { exact = element; break; }
|
|
684
|
+
if (!partial && text.indexOf(wanted) !== -1) partial = element;
|
|
685
|
+
}
|
|
686
|
+
return exact || partial;
|
|
687
|
+
};
|
|
688
|
+
`,so=t=>`(() => {
|
|
689
|
+
${kw}
|
|
690
|
+
${t}
|
|
691
|
+
})()`,Cw=({selector:t}={})=>so(`
|
|
692
|
+
var scopeSelector = ${JSON.stringify(t??"")};
|
|
693
|
+
var root = document;
|
|
694
|
+
if (scopeSelector) {
|
|
695
|
+
try { root = document.querySelector(scopeSelector); }
|
|
696
|
+
catch (error) { return { ok: false, error: 'Invalid selector: ' + scopeSelector }; }
|
|
697
|
+
if (!root) return { ok: false, error: 'No element matches ' + scopeSelector };
|
|
698
|
+
}
|
|
699
|
+
var interactive = root.querySelectorAll('a[href], button, input, select, textarea, [role="button"], [role="link"], [role="tab"], [contenteditable="true"]');
|
|
700
|
+
var elements = [];
|
|
701
|
+
var visibleTotal = 0;
|
|
702
|
+
for (var i = 0; i < interactive.length; i += 1) {
|
|
703
|
+
var element = interactive[i];
|
|
704
|
+
if (!visible(element)) continue;
|
|
705
|
+
visibleTotal += 1;
|
|
706
|
+
if (elements.length >= MAX_ELEMENTS) continue;
|
|
707
|
+
|
|
708
|
+
var rect = element.getBoundingClientRect();
|
|
709
|
+
// Empty and default-valued fields are left out rather than serialized as
|
|
710
|
+
// "" and false. Repeated across a hundred entries that overhead dwarfed
|
|
711
|
+
// the information it carried.
|
|
712
|
+
var entry = {
|
|
713
|
+
selector: cssPath(element),
|
|
714
|
+
tag: element.tagName.toLowerCase(),
|
|
715
|
+
bounds: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) }
|
|
716
|
+
};
|
|
717
|
+
// The list covers the whole document so anything can be clicked without
|
|
718
|
+
// scrolling to it first, which means bounds alone do not say what is on
|
|
719
|
+
// screen — a negative y reads as a bug otherwise.
|
|
720
|
+
if (rect.bottom > 0 && rect.top < window.innerHeight) entry.inViewport = true;
|
|
721
|
+
var type = element.getAttribute('type');
|
|
722
|
+
if (type) entry.type = type;
|
|
723
|
+
var role = element.getAttribute('role');
|
|
724
|
+
if (role) entry.role = role;
|
|
725
|
+
var labelText = label(element);
|
|
726
|
+
if (labelText) entry.label = labelText;
|
|
727
|
+
if (element.disabled === true) entry.disabled = true;
|
|
728
|
+
// Flagged rather than described: reporting the accessible name of every
|
|
729
|
+
// element would cost more than it tells, while its absence on something
|
|
730
|
+
// clickable is a defect worth naming.
|
|
731
|
+
if (!accessibleName(element)) entry.missingAccessibleName = true;
|
|
732
|
+
elements.push(entry);
|
|
733
|
+
}
|
|
734
|
+
var body = document.body ? (document.body.innerText || '') : '';
|
|
735
|
+
var text = body.replace(/\\n{3,}/g, '\\n\\n').trim();
|
|
736
|
+
var docEl = document.documentElement;
|
|
737
|
+
var result = {
|
|
738
|
+
ok: true,
|
|
739
|
+
url: String(location.href),
|
|
740
|
+
title: String(document.title || ''),
|
|
741
|
+
scope: scopeSelector || 'document',
|
|
742
|
+
scrollY: Math.round(window.scrollY),
|
|
743
|
+
maxScrollY: Math.max(0, Math.round(docEl.scrollHeight - window.innerHeight)),
|
|
744
|
+
text: text.slice(0, ${hc}),
|
|
745
|
+
elements: elements
|
|
746
|
+
};
|
|
747
|
+
// State what was dropped. A capped list that reports only its own length
|
|
748
|
+
// reads as the whole page, and the agent acts as if it had seen everything.
|
|
749
|
+
if (text.length > ${hc}) {
|
|
750
|
+
result.textTruncated = true;
|
|
751
|
+
result.textTotalChars = text.length;
|
|
752
|
+
}
|
|
753
|
+
if (visibleTotal > elements.length) {
|
|
754
|
+
result.elementsTruncated = true;
|
|
755
|
+
result.interactiveElementsOnPage = visibleTotal;
|
|
756
|
+
}
|
|
757
|
+
return result;
|
|
758
|
+
`),Nw=({selector:t,text:e})=>so(`
|
|
759
|
+
var selector = ${JSON.stringify(t??"")};
|
|
760
|
+
var text = ${JSON.stringify(e??"")};
|
|
761
|
+
var target = null;
|
|
762
|
+
if (selector) {
|
|
763
|
+
try { target = document.querySelector(selector); }
|
|
764
|
+
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
765
|
+
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
766
|
+
} else {
|
|
767
|
+
target = findByText(text);
|
|
768
|
+
if (!target) return { ok: false, error: 'No clickable element has the label ' + text };
|
|
769
|
+
}
|
|
770
|
+
if (target.disabled === true) return { ok: false, error: 'Element is disabled' };
|
|
771
|
+
target.scrollIntoView({ block: 'center', inline: 'center' });
|
|
772
|
+
target.click();
|
|
773
|
+
return { ok: true, clicked: cssPath(target), label: label(target), url: String(location.href) };
|
|
774
|
+
`),Aw=({selector:t,value:e,submit:n})=>so(`
|
|
775
|
+
var selector = ${JSON.stringify(t)};
|
|
776
|
+
var value = ${JSON.stringify(e)};
|
|
777
|
+
var target = null;
|
|
778
|
+
try { target = document.querySelector(selector); }
|
|
779
|
+
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
780
|
+
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
781
|
+
|
|
782
|
+
var editable = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;
|
|
783
|
+
if (!editable) return { ok: false, error: selector + ' is not a text field' };
|
|
784
|
+
if (target.disabled === true || target.readOnly === true) return { ok: false, error: 'Field is not editable' };
|
|
785
|
+
|
|
786
|
+
target.scrollIntoView({ block: 'center' });
|
|
787
|
+
target.focus();
|
|
788
|
+
if (target.isContentEditable) {
|
|
789
|
+
target.textContent = value;
|
|
790
|
+
} else {
|
|
791
|
+
// Frameworks track the value through the native setter; assigning the
|
|
792
|
+
// property directly leaves React and friends unaware of the change.
|
|
793
|
+
var prototype = target.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
794
|
+
var setter = Object.getOwnPropertyDescriptor(prototype, 'value');
|
|
795
|
+
if (setter && setter.set) setter.set.call(target, value);
|
|
796
|
+
else target.value = value;
|
|
797
|
+
}
|
|
798
|
+
target.dispatchEvent(new Event('input', { bubbles: true }));
|
|
799
|
+
target.dispatchEvent(new Event('change', { bubbles: true }));
|
|
800
|
+
|
|
801
|
+
if (${n?"true":"false"}) {
|
|
802
|
+
var enter = { key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true };
|
|
803
|
+
target.dispatchEvent(new KeyboardEvent('keydown', enter));
|
|
804
|
+
target.dispatchEvent(new KeyboardEvent('keyup', enter));
|
|
805
|
+
var form = target.form;
|
|
806
|
+
if (form && typeof form.requestSubmit === 'function') form.requestSubmit();
|
|
807
|
+
}
|
|
808
|
+
return { ok: true, selector: cssPath(target), url: String(location.href) };
|
|
809
|
+
`),Pw=({selector:t,direction:e})=>so(`
|
|
810
|
+
var selector = ${JSON.stringify(t??"")};
|
|
811
|
+
var direction = ${JSON.stringify(e??"")};
|
|
812
|
+
|
|
813
|
+
var settle = function (extra) {
|
|
814
|
+
return new Promise(function (resolve) {
|
|
815
|
+
requestAnimationFrame(function () {
|
|
816
|
+
requestAnimationFrame(function () {
|
|
817
|
+
var doc = document.documentElement;
|
|
818
|
+
var maxScrollY = Math.max(0, doc.scrollHeight - window.innerHeight);
|
|
819
|
+
var scrollY = Math.round(window.scrollY);
|
|
820
|
+
var result = { ok: true, scrollY: scrollY, maxScrollY: Math.round(maxScrollY) };
|
|
821
|
+
result.atTop = scrollY <= 1;
|
|
822
|
+
result.atBottom = scrollY >= maxScrollY - 1;
|
|
823
|
+
for (var key in extra) {
|
|
824
|
+
if (Object.prototype.hasOwnProperty.call(extra, key)) result[key] = extra[key];
|
|
825
|
+
}
|
|
826
|
+
resolve(result);
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
});
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
if (selector) {
|
|
833
|
+
var target = null;
|
|
834
|
+
try { target = document.querySelector(selector); }
|
|
835
|
+
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
836
|
+
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
837
|
+
// Instant on purpose: the page's own smooth scrolling would still be
|
|
838
|
+
// animating when the next action runs against it.
|
|
839
|
+
target.scrollIntoView({ block: 'center', behavior: 'instant' });
|
|
840
|
+
return settle({ scrolledTo: cssPath(target) });
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
var doc = document.documentElement;
|
|
844
|
+
var page = Math.round(window.innerHeight * 0.85);
|
|
845
|
+
var bottom = Math.max(0, doc.scrollHeight - window.innerHeight);
|
|
846
|
+
if (direction === 'down') window.scrollTo({ top: window.scrollY + page, behavior: 'instant' });
|
|
847
|
+
else if (direction === 'up') window.scrollTo({ top: window.scrollY - page, behavior: 'instant' });
|
|
848
|
+
else if (direction === 'top') window.scrollTo({ top: 0, behavior: 'instant' });
|
|
849
|
+
else if (direction === 'bottom') window.scrollTo({ top: bottom, behavior: 'instant' });
|
|
850
|
+
else return { ok: false, error: 'Unknown scroll direction: ' + direction };
|
|
851
|
+
return settle({ direction: direction });
|
|
852
|
+
`),Dw=["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"],Iw=({selector:t})=>so(`
|
|
853
|
+
var selector = ${JSON.stringify(t)};
|
|
854
|
+
var target = null;
|
|
855
|
+
try { target = document.querySelector(selector); }
|
|
856
|
+
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
857
|
+
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
858
|
+
|
|
859
|
+
var computed = window.getComputedStyle(target);
|
|
860
|
+
var styles = {};
|
|
861
|
+
var props = ${JSON.stringify(Dw)};
|
|
862
|
+
for (var i = 0; i < props.length; i += 1) {
|
|
863
|
+
var value = computed.getPropertyValue(props[i]);
|
|
864
|
+
if (value) styles[props[i]] = String(value).trim();
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
var rect = target.getBoundingClientRect();
|
|
868
|
+
return {
|
|
869
|
+
ok: true,
|
|
870
|
+
selector: cssPath(target),
|
|
871
|
+
tag: target.tagName.toLowerCase(),
|
|
872
|
+
label: label(target),
|
|
873
|
+
bounds: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) },
|
|
874
|
+
inViewport: rect.bottom > 0 && rect.top < window.innerHeight,
|
|
875
|
+
styles: styles
|
|
876
|
+
};
|
|
877
|
+
`),Tw=t=>{const e=nt.c(18),{entries:n,activeIndex:r,onSelect:i,onForget:o,onHighlight:l}=t,{t:a}=vt();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(B,{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||Ka(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(B,{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},cn=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(B,{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(Nt,{asChild:!0,children:s.jsx(dt,{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(At,{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(Ct,{children:[f,p]}),e[14]=f,e[15]=p,e[16]=g):g=e[16],g},ym=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:y,onHardReload:m,onZoomIn:x,onZoomOut:b,onZoomReset:S,zoomPercent:C,onClearCookies:N,onClearCache:k,onToggleDeviceBar:R,isDeviceBarOpen:I}=t;let P;e[0]!==r?(P=r===void 0?[]:r,e[0]=r,e[1]=P):P=e[1];const T=P,E=C===void 0?100:C,{t:O}=vt(),[W,L]=c.useState(!1),[F,D]=c.useState(-1);let j;e[2]!==W||e[3]!==T?(j=W?T:[],e[2]=W,e[3]=T,e[4]=j):j=e[4];const A=j;let M;e[5]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{D(-1)},e[5]=M):M=e[5];let G;e[6]!==n||e[7]!==W?(G=[n,W],e[6]=n,e[7]=W,e[8]=G):G=e[8],c.useEffect(M,G);let q;e[9]!==l?(q=Oe=>{L(!1),D(-1),l(Oe)},e[9]=l,e[10]=q):q=e[10];const Z=q;let le;e[11]!==F||e[12]!==Z||e[13]!==A?(le=Oe=>{if(A.length!==0){if(Oe.key==="ArrowDown"||Oe.key==="ArrowUp"){Oe.preventDefault();const _e=Oe.key==="ArrowDown"?1:-1,Ve=A.length;D(z=>{const pe=z+_e;return pe<-1?Ve-1:pe>=Ve?-1:pe});return}if(Oe.key==="Escape"&&F>=0){Oe.preventDefault(),D(-1);return}if(Oe.key==="Enter"&&F>=0){Oe.preventDefault();const _e=A[F];_e&&Z(_e.url)}}},e[11]=F,e[12]=Z,e[13]=A,e[14]=le):le=e[14];const X=le;let te;e[15]!==O?(te=O("contextPanel.browser.back"),e[15]=O,e[16]=te):te=e[16];const re=!f;let Se;e[17]!==a||e[18]!==re||e[19]!==te?(Se=s.jsx(cn,{icon:"arrow-left",label:te,onClick:a,disabled:re}),e[17]=a,e[18]=re,e[19]=te,e[20]=Se):Se=e[20];let ue;e[21]!==O?(ue=O("contextPanel.browser.forward"),e[21]=O,e[22]=ue):ue=e[22];const ye=!p;let ve;e[23]!==u||e[24]!==ue||e[25]!==ye?(ve=s.jsx(cn,{icon:"arrow-right",label:ue,onClick:u,disabled:ye}),e[23]=u,e[24]=ue,e[25]=ye,e[26]=ve):ve=e[26];let be;e[27]!==g||e[28]!==O?(be=O(g?"contextPanel.browser.stop":"contextPanel.browser.reload"),e[27]=g,e[28]=O,e[29]=be):be=e[29];let _;e[30]!==d||e[31]!==be?(_=s.jsx(cn,{icon:"refresh",label:be,onClick:d}),e[30]=d,e[31]=be,e[32]=_):_=e[32];let oe;e[33]!==m||e[34]!==O?(oe=m?s.jsx(cn,{icon:"restart",label:O("contextPanel.browser.hardReload"),onClick:m}):null,e[33]=m,e[34]=O,e[35]=oe):oe=e[35];let ce;e[36]!==n||e[37]!==Z?(ce=Oe=>{Oe.preventDefault(),Z(n)},e[36]=n,e[37]=Z,e[38]=ce):ce=e[38];let Q;e[39]!==o?(Q=Oe=>o(Oe.target.value),e[39]=o,e[40]=Q):Q=e[40];let me,ke;e[41]===Symbol.for("react.memo_cache_sentinel")?(me=()=>L(!0),ke=()=>L(!1),e[41]=me,e[42]=ke):(me=e[41],ke=e[42]);const fe=A.length>0;let De;e[43]===Symbol.for("react.memo_cache_sentinel")?(De=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]=De):De=e[43];let je;e[44]!==O?(je=O("contextPanel.browser.addressAria"),e[44]=O,e[45]=je):je=e[45];let Y;e[46]!==n||e[47]!==X||e[48]!==Q||e[49]!==fe||e[50]!==je?(Y=s.jsx("input",{value:n,onChange:Q,onFocus:me,onBlur:ke,onKeyDown:X,spellCheck:!1,autoComplete:"off",role:"combobox","aria-expanded":fe,"aria-controls":"openchamber-browser-address-suggestions",className:De,"aria-label":je}),e[46]=n,e[47]=X,e[48]=Q,e[49]=fe,e[50]=je,e[51]=Y):Y=e[51];let Re;e[52]!==i?(Re=Oe=>i?.(Oe),e[52]=i,e[53]=Re):Re=e[53];let Ce;e[54]!==F||e[55]!==Z||e[56]!==Re||e[57]!==A?(Ce=s.jsx("div",{id:"openchamber-browser-address-suggestions",children:s.jsx(Tw,{entries:A,activeIndex:F,onSelect:Z,onForget:Re,onHighlight:D})}),e[54]=F,e[55]=Z,e[56]=Re,e[57]=A,e[58]=Ce):Ce=e[58];let Me;e[59]!==ce||e[60]!==Y||e[61]!==Ce?(Me=s.jsxs("form",{className:"relative min-w-0 flex-1",onSubmit:ce,children:[Y,Ce]}),e[59]=ce,e[60]=Y,e[61]=Ce,e[62]=Me):Me=e[62];let ae;e[63]!==x||e[64]!==b||e[65]!==S||e[66]!==O||e[67]!==E?(ae=b&&x?s.jsxs("div",{className:"flex shrink-0 items-center",children:[s.jsx(cn,{icon:"subtract",label:O("contextPanel.browser.zoomOut"),onClick:b}),E!==100&&S?s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsxs(dt,{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":O("contextPanel.browser.zoomReset"),children:[E,"%"]})}),s.jsx(At,{sideOffset:6,children:O("contextPanel.browser.zoomReset")})]}):null,s.jsx(cn,{icon:"add",label:O("contextPanel.browser.zoomIn"),onClick:x})]}):null,e[63]=x,e[64]=b,e[65]=S,e[66]=O,e[67]=E,e[68]=ae):ae=e[68];let ee;e[69]!==N||e[70]!==O?(ee=N?s.jsx(cn,{icon:"delete-bin",label:O("contextPanel.browser.clearCookies"),onClick:N}):null,e[69]=N,e[70]=O,e[71]=ee):ee=e[71];let K;e[72]!==k||e[73]!==O?(K=k?s.jsx(cn,{icon:"database-2",label:O("contextPanel.browser.clearCache"),onClick:k}):null,e[72]=k,e[73]=O,e[74]=K):K=e[74];let $;e[75]!==I||e[76]!==R||e[77]!==O?($=R?s.jsx(cn,{icon:"smartphone",label:O("contextPanel.browser.deviceToolbar"),onClick:R,pressed:I}):null,e[75]=I,e[76]=R,e[77]=O,e[78]=$):$=e[78];let ne;e[79]!==y||e[80]!==w||e[81]!==O?(ne=w?s.jsx(cn,{icon:"markup",label:O("contextPanel.browser.annotate.toggle"),onClick:w,pressed:y}):null,e[79]=y,e[80]=w,e[81]=O,e[82]=ne):ne=e[82];let U;e[83]!==v||e[84]!==O?(U=v?s.jsx(cn,{icon:"terminal-box",label:O("contextPanel.browser.devTools"),onClick:v}):null,e[83]=v,e[84]=O,e[85]=U):U=e[85];let we;e[86]!==O?(we=O("contextPanel.browser.openExternal"),e[86]=O,e[87]=we):we=e[87];let he;e[88]!==h||e[89]!==we?(he=s.jsx(cn,{icon:"external-link",label:we,onClick:h}),e[88]=h,e[89]=we,e[90]=he):he=e[90];let Te;return e[91]!==Se||e[92]!==ve||e[93]!==_||e[94]!==oe||e[95]!==Me||e[96]!==ae||e[97]!==ee||e[98]!==K||e[99]!==$||e[100]!==ne||e[101]!==U||e[102]!==he?(Te=s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[Se,ve,_,oe,Me,ae,ee,K,$,ne,U,he]}),e[91]=Se,e[92]=ve,e[93]=_,e[94]=oe,e[95]=Me,e[96]=ae,e[97]=ee,e[98]=K,e[99]=$,e[100]=ne,e[101]=U,e[102]=he,e[103]=Te):Te=e[103],Te},_o={kind:"fill"},pc=240,Ew=3840,wm=[{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}],gc=t=>Number.isFinite(t)?Math.round(Math.min(Ew,Math.max(pc,t))):pc,Lo=t=>t.kind==="fill"?null:{width:t.width,height:t.height},Sm=t=>{const e=wm.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},Mw=(t,e)=>{const n=Lo(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}},Ow=["mobile","tablet","desktop","fill"],Bw={mobile:"iphone-14",tablet:"ipad-mini",desktop:"desktop"},xc=t=>typeof t=="string"&&Ow.includes(t),oa=t=>t==="fill"?_o:Sm(Bw[t])??_o,uo=t=>{const e=Lo(t);if(!e)return{mode:"fill",width:null,height:null};for(const n of["mobile","tablet","desktop"]){const r=oa(n),i=Lo(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}},Fw=t=>{const e=nt.c(70),{viewport:n,onViewportChange:r,colorScheme:i,onColorSchemeChange:o,scale:l}=t,{t:a}=vt();let u;e[0]!==n?(u=Lo(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=(re,Se)=>{const ue=Number.parseInt(Se,10);if(!Number.isFinite(ue))return;const ye=d??{width:1280,height:800};r({kind:"custom",width:gc(re==="width"?ue:ye.width),height:gc(re==="height"?ue:ye.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=re=>{const Se=Sm(re.target.value);r(Se??_o)},e[6]=r,e[7]=v):v=e[7];let y;e[8]!==a?(y=a("contextPanel.browser.device.preset"),e[8]=a,e[9]=y):y=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 x;e[11]!==a?(x=a("contextPanel.browser.device.responsive"),e[11]=a,e[12]=x):x=e[12];let b;e[13]!==x?(b=s.jsx("option",{value:"",children:x}),e[13]=x,e[14]=b):b=e[14];let S;e[15]===Symbol.for("react.memo_cache_sentinel")?(S=wm.map(_w),e[15]=S):S=e[15];let C;e[16]!==h||e[17]!==v||e[18]!==y||e[19]!==b?(C=s.jsxs("select",{value:h,onChange:v,"aria-label":y,className:m,children:[b,S]}),e[16]=h,e[17]=v,e[18]=y,e[19]=b,e[20]=C):C=e[20];const N=d?String(d.width):"";let k;e[21]!==p?(k=re=>p("width",re.target.value),e[21]=p,e[22]=k):k=e[22];let R;e[23]!==a?(R=a("contextPanel.browser.device.width"),e[23]=a,e[24]=R):R=e[24];let I;e[25]!==N||e[26]!==k||e[27]!==R?(I=s.jsx("input",{value:N,onChange:k,placeholder:"—",inputMode:"numeric","aria-label":R,className:w}),e[25]=N,e[26]=k,e[27]=R,e[28]=I):I=e[28];let P;e[29]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx("span",{className:"typography-micro text-muted-foreground",children:"×"}),e[29]=P):P=e[29];const T=d?String(d.height):"";let E;e[30]!==p?(E=re=>p("height",re.target.value),e[30]=p,e[31]=E):E=e[31];let O;e[32]!==a?(O=a("contextPanel.browser.device.height"),e[32]=a,e[33]=O):O=e[33];let W;e[34]!==T||e[35]!==E||e[36]!==O?(W=s.jsx("input",{value:T,onChange:E,placeholder:"—",inputMode:"numeric","aria-label":O,className:w}),e[34]=T,e[35]=E,e[36]=O,e[37]=W):W=e[37];let L;e[38]!==r||e[39]!==n?(L=()=>r(Rw(n)),e[38]=r,e[39]=n,e[40]=L):L=e[40];const F=!d;let D;e[41]!==a?(D=a("contextPanel.browser.device.rotate"),e[41]=a,e[42]=D):D=e[42];let j;e[43]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(B,{name:"refresh",className:"size-3.5","aria-hidden":"true"}),e[43]=j):j=e[43];let A;e[44]!==L||e[45]!==F||e[46]!==D?(A=s.jsx(Nt,{asChild:!0,children:s.jsx(dt,{type:"button",variant:"ghost",size:"xs",className:"w-6 shrink-0 rounded-full px-0 text-muted-foreground hover:text-foreground",onClick:L,disabled:F,"aria-label":D,children:j})}),e[44]=L,e[45]=F,e[46]=D,e[47]=A):A=e[47];let M;e[48]!==a?(M=a("contextPanel.browser.device.rotate"),e[48]=a,e[49]=M):M=e[49];let G;e[50]!==M?(G=s.jsx(At,{sideOffset:6,children:M}),e[50]=M,e[51]=G):G=e[51];let q;e[52]!==A||e[53]!==G?(q=s.jsxs(Ct,{children:[A,G]}),e[52]=A,e[53]=G,e[54]=q):q=e[54];let Z;e[55]!==l||e[56]!==d?(Z=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]=Z):Z=e[57];let le;e[58]===Symbol.for("react.memo_cache_sentinel")?(le=["system","light","dark"],e[58]=le):le=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:le.map(re=>s.jsx(dt,{type:"button",variant:i===re?"secondary":"ghost",size:"xs",className:Ie("shrink-0 rounded-full px-2.5 typography-micro",i===re?"text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>o(re),"aria-pressed":i===re,children:a(re==="system"?"contextPanel.browser.device.schemeSystem":re==="light"?"contextPanel.browser.device.schemeLight":"contextPanel.browser.device.schemeDark")},re))}),e[59]=i,e[60]=o,e[61]=a,e[62]=X):X=e[62];let te;return e[63]!==C||e[64]!==I||e[65]!==W||e[66]!==q||e[67]!==Z||e[68]!==X?(te=s.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[C,I,P,W,q,Z,X]}),e[63]=C,e[64]=I,e[65]=W,e[66]=q,e[67]=Z,e[68]=X,e[69]=te):te=e[69],te};function _w(t){return s.jsx("option",{value:t.id,children:t.label},t.id)}const Lw=t=>{try{const e=new URL(t).pathname;return e==="/"?"":e}catch{return""}},$w=2e3,Ww=()=>{if(typeof window>"u"||window.__OPENCHAMBER_ELECTRON__)return!1;const t=Pn();if(!t)return!1;try{return!vr(new URL(t,window.location.href).toString())}catch{return!1}},vm=t=>{const e=nt.c(33),{onOpen:n,directory:r}=t,i=r===void 0?"":r,{t:o}=vt();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=tb(i),[h]=c.useState(Ww);let f,p;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{let I=!0,P=null;const T=new AbortController,E=()=>{F1(T.signal).then(O=>{I&&(u(O),P=setTimeout(E,$w))})};return E(),()=>{I=!1,P&&clearTimeout(P),T.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=$1({announced:d,discovered:g}),e[3]=d,e[4]=g,e[5]=w):w=e[5];const v=w;let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(au,{width:110,height:110,className:"shrink-0 opacity-20"}),e[6]=y):y=e[6];let m;e[7]!==o?(m=o("contextPanel.browser.empty"),e[7]=o,e[8]=m):m=e[8];let x;e[9]!==m?(x=s.jsx("span",{className:"typography-ui-header text-foreground",children:m}),e[9]=m,e[10]=x):x=e[10];let b;e[11]!==o?(b=o("contextPanel.browser.emptyHint"),e[11]=o,e[12]=b):b=e[12];let S;e[13]!==b?(S=s.jsx("span",{className:"typography-micro text-muted-foreground",children:b}),e[13]=b,e[14]=S):S=e[14];let C;e[15]!==S||e[16]!==x?(C=s.jsxs("div",{className:"flex shrink-0 flex-col gap-1",children:[x,S]}),e[15]=S,e[16]=x,e[17]=C):C=e[17];let N;e[18]!==d||e[19]!==v||e[20]!==i||e[21]!==n||e[22]!==h||e[23]!==o?(N=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(I=>s.jsxs(dt,{type:"button",variant:"outline",size:"sm",className:"w-full shrink-0 justify-start gap-2",onClick:()=>{Jx(i),n(I.url)},children:[s.jsx(B,{name:"global",className:"size-3.5 shrink-0","aria-hidden":"true"}),s.jsx("span",{className:"truncate",children:Ka(I.url)||I.url}),s.jsx("span",{className:"ml-auto truncate typography-micro text-muted-foreground",children:Lw(I.url)})]},I.port))})]}):null,e[18]=d,e[19]=v,e[20]=i,e[21]=n,e[22]=h,e[23]=o,e[24]=N):N=e[24];let k;e[25]!==v.length||e[26]!==a.kind||e[27]!==o?(k=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]=k):k=e[28];let R;return e[29]!==C||e[30]!==N||e[31]!==k?(R=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:[y,C,N,k]}),e[29]=C,e[30]=N,e[31]=k,e[32]=R):R=e[32],R},Hs=t=>Math.round(t),zw=(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=${Hs(l.x)}, y=${Hs(l.y)}, width=${Hs(l.width)}, height=${Hs(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")},Vw=(t,e)=>{const n=t.rect;return`Region ${e+1}: x=${Hs(n.x)}, y=${Hs(n.y)}, width=${Hs(n.width)}, height=${Hs(n.height)}`},Uw=(t,e)=>{const n=t.bounds;return`Drawing ${e+1}: ${t.points.length} points over x=${Hs(n.x)}, y=${Hs(n.y)}, width=${Hs(n.width)}, height=${Hs(n.height)}`},Kw=({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: ${Hs(t.viewport.width)}x${Hs(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("",...zw(a.element,l));return t.regions.length>0&&(o.push(""),t.regions.forEach((l,a)=>o.push(Vw(l,a)))),t.strokes.length>0&&(o.push(""),t.strokes.forEach((l,a)=>o.push(Uw(l,a)))),o.filter(l=>typeof l=="string").join(`
|
|
878
|
+
`)},Hw=t=>{const e=nt.c(7),{t:n}=vt(),r=tt(qw),i=tt(Qw),o=Ei(Yw),l=cp(Xw);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){Fe.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:Kw({payload:u.payload,screenshotAttached:h,intro:n("contextPanel.browser.annotate.intro")}),language:"markdown",text:""}),Fe.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},Gw=()=>{const t=nt.c(16),{t:e}=vt();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 qw(t){return t.currentSessionId}function Qw(t){return t.newSessionDraft?.open}function Yw(t){return t.addDraft}function Xw(t){return t.addAttachedFile}const Jw=3e4,Zw=3,eS=250,tS={attempts:0,windowStartedAt:null},sS=(t,e)=>{const n=t.windowStartedAt===null||e-t.windowStartedAt>=Jw,r=n?0:t.attempts;return r>=Zw?null:{delayMs:eS*2**r,state:{attempts:r+1,windowStartedAt:n?e:t.windowStartedAt}}},nS=-3,mo=t=>typeof t=="string"&&t.length>0&&t!=="about:blank",fr=t=>{const e=t;return e.detail&&typeof e.detail=="object"?e.detail:t},rS=(t,{initialUrl:e,onUrlChange:n})=>{const[r,i]=c.useState(e?{kind:"loading",url:e}:V1),[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(tS);return c.useEffect(()=>{if(!t)return;const v=()=>{try{const P=t.getURL();return mo(P)?P:""}catch{return""}},y=()=>{try{h(t.canGoBack()),p(t.canGoForward())}catch{}},m=P=>{mo(P)&&(l(P),g.current(P))},x=()=>{const P=v();i({kind:"loading",url:P})},b=()=>{const P=v();let T="";try{T=t.getTitle()||""}catch{T=""}u(T),m(P),y(),i(E=>E.kind==="failed"&&E.url===P?E:{kind:"ready",url:P,title:T})},S=P=>{const T=fr(P);mo(T.url)&&(m(T.url),y())},C=P=>{const T=fr(P),E=Array.isArray(T.favicons)?T.favicons.find(Boolean):"",O=v();E&&O&&lm.getState().resolve(O,E)},N=P=>{const T=fr(P);typeof T.title=="string"&&u(T.title)},k=P=>{const T=fr(P);if(T.isMainFrame===!1)return;const E=typeof T.errorCode=="number"?T.errorCode:0;E!==nS&&i({kind:"failed",url:mo(T.validatedURL)?T.validatedURL:v(),code:E,description:typeof T.errorDescription=="string"?T.errorDescription:""})};let R=null;const I=()=>{const P=v(),T=sS(w.current,Date.now());if(!T){i({kind:"failed",url:P,code:0,description:"",crashed:!0});return}w.current=T.state,i({kind:"loading",url:P}),R=setTimeout(()=>{R=null;try{t.reload()}catch{i({kind:"failed",url:P,code:0,description:"",crashed:!0})}},T.delayMs)};t.addEventListener("did-start-loading",x),t.addEventListener("did-stop-loading",b),t.addEventListener("did-navigate",S),t.addEventListener("did-navigate-in-page",S),t.addEventListener("page-title-updated",N),t.addEventListener("page-favicon-updated",C),t.addEventListener("did-fail-load",k),t.addEventListener("render-process-gone",I),t.addEventListener("crashed",I);try{!t.isLoading()&&v()&&b()}catch{}return()=>{R!==null&&clearTimeout(R),t.removeEventListener("render-process-gone",I),t.removeEventListener("crashed",I),t.removeEventListener("did-start-loading",x),t.removeEventListener("did-stop-loading",b),t.removeEventListener("did-navigate",S),t.removeEventListener("did-navigate-in-page",S),t.removeEventListener("page-title-updated",N),t.removeEventListener("page-favicon-updated",C),t.removeEventListener("did-fail-load",k)}},[t]),{status:r,url:o,title:a,canGoBack:d,canGoForward:f}},oS=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,iS=4e4,fo=.5,aS=-3,lS=4,cS="persist:openchamber-browser",bc=20,dS=600,uS=2e4,mS=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=vt(),{currentTheme:i}=nr(),o=c.useRef(null),[l,a]=c.useState(null),u=c.useCallback(ae=>{o.current=ae,a(ae)},[]),d=Ne(ae=>ae.setContextPanelTabTargetPath),h=c.useRef(xr(t)),f=h.current!==dn?h.current:"",[p,g]=c.useState(f?null:dn),[w,v]=c.useState(f),[y,m]=c.useState(!1),[x,b]=c.useState(!1),[S,C]=c.useState(0),N=c.useRef(0),[k,R]=c.useState(!1),[I,P]=c.useState(_o),T=c.useRef(I);T.current=I;const E=c.useRef([]),[O,W]=c.useState("system"),[L,F]=c.useState({width:0,height:0}),D=c.useRef(null),j=c.useRef(null),A=c.useRef(!1),M=c.useRef(Date.now()),G=c.useCallback(ae=>{!ae||ae===dn||!e||!n||d(e,n,ae)},[e,n,d]),q=rS(l,{initialUrl:f,onUrlChange:c.useCallback(ae=>{const ee=Ir(ae);v(ee),G(ee)},[G])}),[Z,le]=c.useState(null),X=Hw(e),te=Gw(),re=q.status.kind==="loading",Se=yr(pm(e)),ue=yr(ae=>ae.recordVisit),ye=yr(ae=>ae.forget);c.useEffect(()=>{q.status.kind==="ready"&&ue(e,{url:Ir(q.status.url),title:q.status.title})},[e,q.status,ue]);const ve=c.useMemo(()=>hm(Se,w),[Se,w]),be=c.useCallback(ae=>{const ee=xr(ae);ee!==dn&&(v(ee),le(null),mc(ee).then(K=>{const $=o.current;if(!$){g(K);return}try{$.loadURL(K)}catch{g(K)}}).catch(K=>{K instanceof zr&&le(ee)}))},[]);c.useEffect(()=>{if(!f)return;let ae=!0;return mc(f).then(ee=>{ae&&g(ee)}).catch(ee=>{if(ae){if(ee instanceof zr){le(f),g(dn);return}g(f)}}),()=>{ae=!1}},[]);const _=c.useMemo(()=>({executeJavaScript:async(ae,ee)=>{const K=o.current;if(!K)throw new Error("Browser view is not available");return K.executeJavaScript(ae,ee)},capturePage:async()=>{const ae=o.current;if(!ae)return null;const ee=ae.getWebContentsId();return Number.isFinite(ee)?await pr("desktop_browser_capture_page",{webContentsId:ee}):null}}),[]),oe=c.useCallback(()=>{if(y){m(!1),jo(_);return}if(!q.url){Fe.error(r("contextPanel.browser.annotate.noPage"));return}const ae=nw(i.metadata.variant==="light"?"light":"dark");m(!0),tw({host:_,theme:ae,labels:te}).then(async ee=>{m(!1),ee&&await X(ee)}).catch(()=>{m(!1),Fe.error(r("contextPanel.browser.annotate.failed"))})},[_,X,i,y,q.url,te,r]);c.useEffect(()=>{if(!y)return;const ae=ee=>{dp(ee)||ee.key!=="Escape"||(ee.preventDefault(),ee.stopImmediatePropagation(),m(!1),jo(_))};return window.addEventListener("keydown",ae,!0),()=>window.removeEventListener("keydown",ae,!0)},[_,y]);const ce=c.useCallback(async(ae=8e3)=>{const ee=Date.now();for(;;){const K=o.current;if(!K)return!1;let $=!1;try{$=K.isLoading()}catch{return!1}if(!$)return!0;if(Date.now()-ee>ae)return!1;await new Promise(ne=>setTimeout(ne,120))}},[]),Q=c.useCallback(async(ae,ee)=>{const K=o.current;if(!K)throw new Error("The browser panel is not ready");const $=()=>{xc(ee.viewport)&&(P(oa(ee.viewport)),R(!0))};if(ae==="browser.back"||ae==="browser.forward"){const Oe=ae==="browser.back";if(!(Oe?K.canGoBack():K.canGoForward()))throw new Error(Oe?"There is nothing to go back to in this tab":"There is nothing to go forward to in this tab");Oe?K.goBack():K.goForward(),await new Promise(z=>setTimeout(z,150)),await ce();let Ve="";try{Ve=K.getTitle()||""}catch{Ve=""}return{url:Ir(K.getURL()),title:Ve}}if(ae==="browser.capture"){Ne.getState().openContextBrowser(e,K.getURL());const Oe=Date.now()+1200;let _e=0,Ve=0;for(;Ve<2&&Date.now()<Oe;){const Ae=K.getBoundingClientRect().width;Ve=Ae>=2&&Math.abs(Ae-_e)<.5?Ve+1:0,_e=Ae,await new Promise(Be=>setTimeout(Be,50))}await new Promise(Ae=>{requestAnimationFrame(()=>requestAnimationFrame(()=>Ae()))}),await ce();const z=await _.capturePage();if(!z)throw new Error("The page could not be captured");let pe="";try{pe=K.getTitle()||""}catch{pe=""}return{...z,url:Ir(K.getURL()),title:pe,viewport:uo(T.current)}}if(ae==="browser.resize"){if(!xc(ee.viewport))throw new Error("viewport is required");return $(),await new Promise(Oe=>setTimeout(Oe,200)),await ce(),{viewport:uo(oa(ee.viewport))}}if(ae==="browser.open"){const Oe=typeof ee.url=="string"?ee.url:"";if(!Oe)throw new Error("url is required");$(),be(Oe),await new Promise(z=>setTimeout(z,150));const _e=await ce(25e3);let Ve="";try{Ve=K.getTitle()||""}catch{Ve=""}return{url:xr(Oe),title:Ve,opened:!0,settled:_e,viewport:uo(T.current)}}await ce();const ne=Oe=>typeof Oe=="string"&&Oe?Oe:void 0,we=(()=>{switch(ae){case"browser.snapshot":return Cw({selector:ne(ee.selector)});case"browser.click":return Nw({selector:ne(ee.selector),text:ne(ee.text)});case"browser.type":return Aw({selector:String(ee.selector??""),value:String(ee.value??""),submit:ee.submit===!0});case"browser.inspect":return Iw({selector:String(ee.selector??"")});case"browser.scroll":return Pw({selector:ne(ee.selector),direction:ne(ee.direction)});default:return null}})();if(!we)throw new Error(`Unsupported browser action: ${ae}`);const he=await K.executeJavaScript(we,!0);if(!he||typeof he!="object")throw new Error("The page returned no result");const Te=he;if(Te.ok!==!0)throw new Error(typeof Te.error=="string"&&Te.error?Te.error:"Browser action failed");if(ae==="browser.snapshot"){const Oe=E.current;return{...Te,viewport:uo(T.current),...Oe.length>0?{consoleProblems:[...Oe]}:{}}}return(ae==="browser.click"||ae==="browser.type"&&ee.submit===!0)&&(await new Promise(Oe=>setTimeout(Oe,150)),await ce()),he},[_,e,be,ce]);c.useEffect(()=>cw({run:Q}),[Q]),c.useEffect(()=>{const ae=_;return()=>{jo(ae)}},[_]),c.useEffect(()=>{if(!l)return;const ae=K=>{const $=K;if(typeof $.level!="number"||$.level<2)return;const ne=$.sourceId?`${$.sourceId}${$.line?`:${$.line}`:""}`:"";E.current.push({level:$.level>=3?"error":"warning",message:String($.message??"").slice(0,400),source:ne}),E.current.length>bc&&E.current.splice(0,E.current.length-bc)},ee=()=>{E.current=[]};return l.addEventListener("console-message",ae),l.addEventListener("did-start-loading",ee),()=>{l.removeEventListener("console-message",ae),l.removeEventListener("did-start-loading",ee)}},[l]);const me=c.useRef(new Set),ke=c.useCallback(ae=>{me.current.clear(),be(ae)},[be]);c.useEffect(()=>{if(!l)return;const ae=K=>{const $=fr(K),ne=typeof $.url=="string"?$.url:"";!ne||!fc(ne)||(K.preventDefault(),be(ne))},ee=K=>{const $=fr(K);if($.isMainFrame===!1||$.errorCode===-3)return;const ne=typeof $.validatedURL=="string"?$.validatedURL:"";!ne||!fc(ne)||me.current.has(ne)||(me.current.add(ne),be(ne))};return l.addEventListener("will-navigate",ae),l.addEventListener("did-fail-load",ee),()=>{l.removeEventListener("will-navigate",ae),l.removeEventListener("did-fail-load",ee)}},[be,l]),c.useEffect(()=>{if(!l)return;const ae=ee=>{const K=ee.detail;ee.preventDefault(),K?.url&&be(K.url)};return l.addEventListener("new-window",ae),()=>l.removeEventListener("new-window",ae)},[be,l]);const fe=c.useCallback(ae=>{const ee=Math.min(lS,Math.max(aS,ae));N.current=ee,C(ee);try{o.current?.setZoomLevel(ee)}catch{}},[]);c.useEffect(()=>{const ae=ee=>{if(!(ee instanceof CustomEvent))return;const K=ee.detail,$=o.current;!$||document.activeElement!==$||(K==="zoom-in"?fe(N.current+fo):K==="zoom-out"?fe(N.current-fo):K==="zoom-reset"&&fe(0))};return window.addEventListener("openchamber:zoom",ae),()=>window.removeEventListener("openchamber:zoom",ae)},[fe]);const De=c.useCallback(ae=>{pr("desktop_browser_clear_data",{partition:cS,cookies:ae==="cookies",cache:ae==="cache"}).then(()=>{Fe.success(r(ae==="cookies"?"contextPanel.browser.clearedCookies":"contextPanel.browser.clearedCache"));try{o.current?.reloadIgnoringCache()}catch{}}).catch(()=>Fe.error(r("contextPanel.browser.clearFailed")))},[r]);c.useEffect(()=>{const ae=D.current;if(!ae||typeof ResizeObserver>"u")return;const ee=new ResizeObserver(K=>{const $=K[0]?.contentRect;$&&F({width:$.width,height:$.height})});return ee.observe(ae),()=>ee.disconnect()},[]);const je=c.useCallback(ae=>{W(ae);const ee=o.current;if(!ee)return;let K=-1;try{K=ee.getWebContentsId()}catch{return}pr("desktop_browser_set_color_scheme",{webContentsId:K,scheme:ae}).catch($=>{W("system"),Fe.error($ instanceof Error?$.message:r("contextPanel.browser.device.schemeFailed"))})},[r]),Y=c.useCallback(()=>{try{re?o.current?.stop():o.current?.reload()}catch{}},[re]),Re=q.status;c.useEffect(()=>{const ae=()=>{b(!0);const $=setTimeout(()=>{try{o.current?.reload()}catch{}},dS);return()=>clearTimeout($)};if(Re.kind==="failed"){if(!O1(Re.code,Re.url)){b(!1);return}const $=Date.now(),ne=j.current?.url===Re.url?j.current:{url:Re.url,startedAt:$};if(j.current=ne,$-ne.startedAt>iS){b(!1);return}return ae()}if(Re.kind==="loading")return;if(j.current=null,Re.kind!=="ready"||!Re.url||!vr(Re.url)){A.current=!0,b(!1);return}if(A.current||Date.now()-M.current>uS){A.current=!0,b(!1);return}let ee=!1,K=null;return _1(Ir(Re.url)).then($=>{if(!ee){if($===null||$<500){A.current=!0,b(!1);return}K=ae()}}),()=>{ee=!0,K?.()}},[Re]);const Ce=q.status.kind==="failed"&&!x?q.status:null,Me=Mw(I,L);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsx(ym,{address:w,onAddressChange:v,onSubmit:ke,suggestions:ve,onForgetSuggestion:ae=>ye(e,ae),onBack:()=>{try{o.current?.goBack()}catch{}},onForward:()=>{try{o.current?.goForward()}catch{}},onReload:Y,onOpenExternal:()=>{qo(q.url||w)},canGoBack:q.canGoBack,canGoForward:q.canGoForward,isLoading:re,onAnnotate:oe,isAnnotating:y,onOpenDevTools:()=>{try{o.current?.openDevTools()}catch{}},onHardReload:()=>{try{o.current?.reloadIgnoringCache()}catch{}},onZoomIn:()=>fe(S+fo),onZoomOut:()=>fe(S-fo),onZoomReset:()=>fe(0),zoomPercent:Math.round(Math.pow(1.2,S)*100),onClearCookies:()=>De("cookies"),onClearCache:()=>De("cache"),onToggleDeviceBar:()=>R(ae=>!ae),isDeviceBarOpen:k}),k?s.jsx(Fw,{viewport:I,onViewportChange:P,colorScheme:O,onColorSchemeChange:je,scale:Me?.scale??1}):null,s.jsxs("div",{ref:D,className:Ie("relative min-h-0 flex-1 bg-background",Me&&"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:Me?{width:`${Me.width}px`,height:`${Me.height}px`,transform:`scale(${Me.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&&!re?s.jsx(vm,{onOpen:ke,directory:e}):null,x?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,Z?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:Z})})]}):null,Ce&&!Z?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,re?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]})]})},fS=t=>{const e=nt.c(49),{initialUrl:n,directory:r,tabID:i}=t,{t:o}=vt(),l=Ne(pS);let a;e[0]!==n?(a=xr(n),e[0]=n,e[1]=a):a=e[1];const u=a,d=u!==dn?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,y]=c.useState(w),[m,x]=c.useState(d?0:-1),[b,S]=c.useReducer(gS,0);let C;e[4]!==r||e[5]!==l||e[6]!==i?(C=te=>{!te||te===dn||!r||!i||l(r,i,te)},e[4]=r,e[5]=l,e[6]=i,e[7]=C):C=e[7];const N=C;let k;e[8]!==r?(k=pm(r),e[8]=r,e[9]=k):k=e[9];const R=yr(k),I=yr(xS),P=yr(bS);let T;e[10]!==h||e[11]!==R?(T=hm(R,h),e[10]=h,e[11]=R,e[12]=T):T=e[12];const E=T;let O;e[13]!==r||e[14]!==m||e[15]!==N||e[16]!==I?(O=te=>{const re=xr(te);re!==dn&&(f(re),g(re),N(re),I(r,{url:re}),y(Se=>{const ue=m>=0?Se.slice(0,m+1):[];return ue[ue.length-1]===re?(x(ue.length-1),ue):(x(ue.length),[...ue,re])}))},e[13]=r,e[14]=m,e[15]=N,e[16]=I,e[17]=O):O=e[17];const W=O;let L;e[18]!==v||e[19]!==N?(L=te=>{const re=v[te];re&&(x(te),f(re),g(re),N(re))},e[18]=v,e[19]=N,e[20]=L):L=e[20];const F=L;let D;e[21]!==r||e[22]!==P?(D=te=>P(r,te),e[21]=r,e[22]=P,e[23]=D):D=e[23];let j,A;e[24]!==F||e[25]!==m?(A=()=>F(m-1),j=()=>F(m+1),e[24]=F,e[25]=m,e[26]=j,e[27]=A):(j=e[26],A=e[27]);let M;e[28]!==h||e[29]!==p?(M=()=>{qo(p||h)},e[28]=h,e[29]=p,e[30]=M):M=e[30];const G=m>0,q=m>=0&&m<v.length-1;let Z;e[31]!==h||e[32]!==W||e[33]!==E||e[34]!==j||e[35]!==M||e[36]!==G||e[37]!==q||e[38]!==D||e[39]!==A?(Z=s.jsx(ym,{address:h,onAddressChange:f,onSubmit:W,suggestions:E,onForgetSuggestion:D,onBack:A,onForward:j,onReload:S,onOpenExternal:M,canGoBack:G,canGoForward:q,isLoading:!1}),e[31]=h,e[32]=W,e[33]=E,e[34]=j,e[35]=M,e[36]=G,e[37]=q,e[38]=D,e[39]=A,e[40]=Z):Z=e[40];let le;e[41]!==p||e[42]!==W||e[43]!==b||e[44]!==o?(le=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}|${b}`):s.jsx(vm,{onOpen:W})}),e[41]=p,e[42]=W,e[43]=b,e[44]=o,e[45]=le):le=e[45];let X;return e[46]!==Z||e[47]!==le?(X=s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[Z,le]}),e[46]=Z,e[47]=le,e[48]=X):X=e[48],X},hS=t=>{const e=nt.c(3),[n]=c.useState(oS);let r;return e[0]!==n||e[1]!==t?(r=n?s.jsx(mS,{...t}):s.jsx(fS,{...t}),e[0]=n,e[1]=t,e[2]=r):r=e[2],r};function pS(t){return t.setContextPanelTabTargetPath}function gS(t){return t+1}function xS(t){return t.recordVisit}function bS(t){return t.forget}const yS=zn(()=>hn(()=>import("./WalkthroughView-CfIPvWWa.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,124])).then(t=>({default:t.WalkthroughView}))),wS=zn(()=>hn(()=>import("./DiffView-B7YkbY-u.js"),__vite__mapDeps([125,1,2,4,5,6,7,8,9,83,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,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,126,116,117,118,119,120,121,122,123,124])).then(t=>({default:t.DiffView}))),SS=zn(()=>hn(()=>import("./FilesView-vjJx7VaM.js"),__vite__mapDeps([127,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,84,85,128,129,130,131,132,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,133,134,119,120,117,122,135,118,136])).then(t=>({default:t.FilesView}))),vS=zn(()=>hn(()=>import("./GitView-BLhlMYEY.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,84,85,138,116,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,86,114,115,117,118,119,120,121,122,123,124])).then(t=>({default:t.GitView}))),jS=zn(()=>hn(()=>import("./LinearIssuesView-1uKhePfH.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])).then(t=>({default:t.LinearIssuesView}))),kS=zn(()=>hn(()=>import("./PlanView-BGAzxDwD.js"),__vite__mapDeps([140,1,2,4,5,6,7,8,9,128,57,58,59,60,61,62,79,55,56,63,129,130,131,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,118,136,119,120,105,106,90,91,92,93,94,95,96,97,98,99,100,101,102,103,84,85])).then(t=>({default:t.PlanView}))),CS=c.lazy(()=>hn(()=>import("./GuestAttachDialog-B-fwE8r3.js").then(t=>t.k),__vite__mapDeps([85,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.PluginPane}))),NS=320,AS=1400,jm=600,PS=100,DS=24,$o=new Map,IS=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},yc=t=>Number.isFinite(t)?Math.min(AS,Math.max(NS,Math.round(t))):jm,TS=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},ES=(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},km=(t,e)=>t==="chat"?e("contextPanel.mode.chat"):t==="file"?e("contextPanel.mode.files"):t==="diff"?e("contextPanel.mode.diff"):t==="walkthrough"?e("contextPanel.mode.walkthrough"):t==="plan"?e("contextPanel.mode.plan"):t==="browser"?e("contextPanel.mode.browser"):t==="git"?e("layout.rightSidebar.git"):t==="pr"?e("contextPanel.mode.pr"):t==="linear"?e("contextPanel.mode.linear"):t==="notes"?e("contextRail.surface.notes"):t==="terminal"?e("layout.mainTab.terminal"):Xn(t)?Zd.getState().guests.find(r=>r.id===Ci(t))?.name??e("contextRail.surface.plugin"):e("contextPanel.mode.context"),RS=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},MS=(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"?Ka(t.targetPath??"")||t.label||n("contextPanel.mode.browser"):t.label?t.label:t.mode==="file"?RS(t.targetPath)||n("contextPanel.mode.files"):t.mode==="diff"?n("contextPanel.mode.diff"):km(t.mode,n)},OS=t=>{const e=nt.c(8),{mode:n}=t,r=Pa();let i;if(e[0]!==n||e[1]!==r){let d;e[3]!==n?(d=h=>h.mode===n,e[3]=n,e[4]=d):d=e[4],i=r.find(d),e[0]=n,e[1]=r,e[2]=i}else i=e[2];const o=i,l=o?.icon??hp,a=o?.iconSrc;let u;return e[5]!==l||e[6]!==a?(u=s.jsx(Jr,{icon:l,iconSrc:a,className:"h-3.5 w-3.5"}),e[5]=l,e[6]=a,e[7]=u):u=e[7],u},wc=(t,e={})=>{if(t.mode==="file")return t.targetPath?s.jsx(Aa,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(Ju,{className:"h-3.5 w-3.5"});if(t.mode==="walkthrough")return s.jsx(B,{name:"route",className:"h-3.5 w-3.5"});if(t.mode==="git")return s.jsx(B,{name:"git-branch",className:"h-3.5 w-3.5"});if(t.mode==="pr")return s.jsx(B,{name:"github",className:"h-3.5 w-3.5"});if(t.mode==="linear")return s.jsx(B,{name:"linear",className:"h-3.5 w-3.5"});if(t.mode==="notes")return s.jsx(B,{name:"sticky-note",className:"h-3.5 w-3.5"});if(t.mode==="terminal")return s.jsx(B,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(B,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(B,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(B,{name:"chat-4",className:"h-3.5 w-3.5"});if(Xn(t.mode))return s.jsx(OS,{mode:t.mode});if(t.mode==="browser"){const n=BS(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(B,{name:"global",className:"h-3.5 w-3.5"})}},BS=(t,e)=>{try{return e[new URL(t).origin]??""}catch{return""}},FS=({visible:t,active:e,fill:n=!1})=>{const{t:r}=vt(),i=Ne(x=>x.contextEditorTreeWidth),o=Ne(x=>x.setContextEditorTreeWidth),[l,a]=c.useState(!1),u=c.useRef(0),d=c.useRef(i),h=c.useRef(null),f=c.useRef(null),p=c.useRef(null),g=c.useCallback(x=>{const b=p.current;b&&(b.style.width=`${x}px`,b.style.setProperty("--oc-editor-tree-width",`${x}px`))},[]),w=x=>{if(t){try{x.currentTarget.setPointerCapture(x.pointerId)}catch{}f.current=x.pointerId,a(!0),u.current=x.clientX,d.current=i,h.current=i,x.preventDefault()}},v=x=>{if(!l||f.current!==x.pointerId)return;const b=u.current-x.clientX,S=ki(d.current+b);h.current!==S&&(h.current=S,g(S))},y=x=>{if(f.current!==x.pointerId)return;try{x.currentTarget.releasePointerCapture(x.pointerId)}catch{}const b=ki(h.current??i);f.current=null,h.current=null,a(!1),o(b)},m=t?i:0;return s.jsxs("div",{ref:p,className:Ie("relative h-full flex-shrink-0 overflow-hidden bg-background will-change-[width] motion-reduce:transition-none",n&&"ml-auto"),style:{width:`${l?h.current??m:m}px`,maxWidth:n?"100%":void 0,"--oc-editor-tree-width":`${l?h.current??i:i}px`,overflowX:"clip",transitionProperty:l?"none":"width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t,children:[t&&!n&&s.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-y-0 left-0 z-20 w-px bg-border"}),t&&!n&&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",l&&"bg-[var(--interactive-border)]"),onPointerDown:w,onPointerMove:v,onPointerUp:y,onPointerCancel:y,role:"separator","aria-orientation":"vertical","aria-label":r("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",l&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-editor-tree-width)",maxWidth:n?"100%":void 0},"aria-hidden":!t,children:s.jsx(t1,{visible:t&&e})})]})},ia=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,_S=(t,e)=>{if(t.size!==e.size)return!1;for(const[n,r]of t)if(e.get(n)!==r)return!1;return!0},LS=(t,e)=>{if(e.length===0)return $o;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?$o:r},$S=(t,e)=>{const n=Kd(t),r=c.useRef($o),i=c.useRef(e);return i.current=e,c.useSyncExternalStore(n.subscribe,c.useCallback(()=>{const o=LS(n.getState().session,i.current);return _S(r.current,o)?r.current:(r.current=o,o)},[n]),()=>$o)},WS=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,zS=()=>{const{t}=vt(),e=rr()??"",n=c.useMemo(()=>IS(e),[e]),r=Ne(H=>n?H.contextPanelByDirectory[n]:void 0),i=Ne(H=>H.closeContextPanel),o=Ne(H=>H.closeContextPanelTab),l=Ne(H=>H.openContextPanelTab),a=Ne(H=>H.toggleContextPanelExpanded),u=Ne(H=>H.setContextPanelWidth),d=Ne(H=>H.setActiveContextPanelTab),h=Ne(H=>H.openContextBrowser);c.useEffect(()=>{if(e)return dw(H=>h(e,H))},[e,h]);const f=Ne(H=>H.reorderContextPanelTabs),p=pn(H=>H.setSelectedPath),g=Ne(H=>H.contextEditorTreeVisible),w=Ne(H=>H.contextEditorTreeWidth),v=Ne(H=>H.setContextEditorTreeWidth),y=Ne(H=>H.toggleContextEditorTree),m=Ne(H=>H.contextEditorVisible),x=Ne(H=>H.toggleContextEditor),b=Ne(H=>H.openNewContextBrowserTab),S=lm(H=>H.byOrigin),C=Ne(H=>H.allowPromptingSubagentSessions),{themeMode:N,setThemeMode:k,lightThemeId:R,darkThemeId:I,currentTheme:P}=nr(),T=c.useMemo(()=>r?.tabs??[],[r?.tabs]),E=T.find(H=>H.id===r?.activeTabId)??T[T.length-1]??null,O=!!(r?.isOpen&&E),[W,L]=c.useState(null),F=c.useMemo(()=>T.some(H=>H.mode==="file"&&H.targetPath),[T]),D=F&&(m||!g),j=E?.mode??null,A=j==="file"&&!D,M=!!(O&&r?.expanded&&!A),G=j?r?.widthByMode?.[j]:void 0,q=j?r?.widthFractionByMode?.[j]:void 0,Z=j?up(j):.5,le=W??(typeof window<"u"?window.innerWidth:jm*2),X=q!=null&&W!=null?Math.round(q*W):G,te=A?w:yc(X??Math.round(Z*le));c.useEffect(()=>{!n||!j||A||q!=null||G==null||W==null||u(n,j,G,W)},[j,W,n,A,G,q,u]);const re=c.useMemo(()=>{const H=[];for(const V of T){if(V.mode!=="chat")continue;const J=ia(V.dedupeKey);J&&!H.includes(J)&&H.push(J)}return H},[T]),Se=$S(n||void 0,re),[ue,ye]=c.useState(!1),ve=c.useRef(0),be=c.useRef(te),_=c.useRef(null),oe=c.useRef(null),ce=c.useRef(null),Q=c.useRef(new Map),me=c.useRef(new Map),ke=c.useRef(!1);c.useLayoutEffect(()=>{const H=ce.current?.parentElement;if(!H||typeof ResizeObserver>"u")return;const V=new ResizeObserver(()=>{L(H.clientWidth||null)});return V.observe(H),L(H.clientWidth||null),()=>V.disconnect()},[]),c.useEffect(()=>{if(!O||ke.current){ke.current=O;return}const H=window.requestAnimationFrame(()=>{ce.current?.focus({preventScroll:!0})});return ke.current=!0,()=>window.cancelAnimationFrame(H)},[O]);const fe=c.useRef(null),De=c.useRef(null),je=c.useCallback(()=>{De.current=null;const H=ce.current,V=_.current;!H||V===null||H.style.setProperty("--oc-context-panel-width",`${V}px`)},[]);c.useEffect(()=>()=>{De.current!==null&&clearTimeout(De.current)},[]);const Y=c.useCallback(H=>{const V=A?ki(H):yc(H),J=fe.current;return J===null?V:Math.min(V,Math.max(1,J))},[A]),Re=c.useCallback(H=>{!O||M||!n||(oe.current=H.pointerId,ye(!0),ve.current=H.clientX,be.current=te,_.current=te,fe.current=TS(ce.current),document.documentElement.style.cursor="col-resize",H.preventDefault())},[n,M,O,te]),Ce=c.useCallback(()=>{const H=Y(_.current??te),V=fe.current;_.current=null,fe.current=null,De.current!==null&&(clearTimeout(De.current),De.current=null),document.documentElement.style.cursor="",A?v(H):n&&j&&u(n,j,H,V??void 0),ye(!1),oe.current=null},[j,Y,n,A,v,u,te]);c.useEffect(()=>{if(!ue)return;const H=ge=>{if(oe.current!==ge.pointerId)return;const Ee=ve.current-ge.clientX,$e=Y(be.current+Ee);_.current!==$e&&(_.current=$e,De.current===null&&(De.current=setTimeout(je,PS)))},V=ge=>{oe.current===ge.pointerId&&Ce()},J=()=>{Ce()};return window.addEventListener("pointermove",H),window.addEventListener("pointerup",V),window.addEventListener("pointercancel",V),window.addEventListener("blur",J),()=>{window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",V),window.removeEventListener("pointercancel",V),window.removeEventListener("blur",J)}},[je,Y,Ce,ue]),c.useEffect(()=>{ue||(_.current=null,document.documentElement.style.cursor="")},[ue]);const Me=c.useCallback(()=>{n&&i(n)},[i,n]),ae=c.useCallback(()=>{n&&a(n)},[n,a]),ee=c.useCallback(H=>{H.key==="Escape"&&(H.target instanceof Node&&!H.currentTarget.contains(H.target)||mp(H.target)||fp(H.target)||(H.preventDefault(),H.stopPropagation(),Me()))},[Me]);c.useEffect(()=>{if(!(!n||!E)&&E.mode==="file"&&E.targetPath){p(n,E.targetPath,{allowOutsideRoot:!0});return}},[E,n,p]);const K=c.useMemo(()=>T.filter(H=>H.mode==="chat"),[T]),$=O&&E?.mode==="chat"?E.id:null,ne=O&&E?.mode==="chat"?ia(E.dedupeKey):null,U=Ex(K,$);c.useEffect(()=>{if(!O||!n||!ne||typeof window>"u")return;const H=()=>{if(document.visibilityState==="hidden"||!document.hasFocus()){ii(n,ne,!1);return}lu(ne),ii(n,ne,!0)};H();const V=window.setInterval(H,1e4);return window.addEventListener("focus",H),window.addEventListener("blur",H),document.addEventListener("visibilitychange",H),()=>{window.clearInterval(V),window.removeEventListener("focus",H),window.removeEventListener("blur",H),document.removeEventListener("visibilitychange",H),ii(n,ne,!1)}},[ne,n,O]);const we=c.useCallback((H,V,J)=>Rx(me.current,H,V,n||null,J,{mode:N,lightThemeId:R,darkThemeId:I,currentTheme:P},{allowPromptingSubagentSessions:C}),[C,P,I,n,R,N]),he=U&&ne?we(U.id,ne,U.readOnly):null;c.useEffect(()=>{const H=new Set(T.map(V=>V.id));for(const V of me.current.keys())H.has(V)||me.current.delete(V)},[T]);const Te=c.useCallback(H=>{!n||E?.mode!=="diff"||l(n,{mode:"diff",targetPath:E.targetPath,stagedDiff:H==="staged",diffScope:H})},[E,n,l]),Oe=c.useCallback(()=>{if(typeof window>"u")return;const H={themeMode:N,lightThemeId:R,darkThemeId:I,currentTheme:P};for(const V of Q.current.values()){const J=V.contentWindow;J&&J.postMessage({type:"openchamber:theme-sync",payload:H},window.location.origin)}},[P,I,R,N]),_e=c.useCallback(()=>{if(typeof window>"u")return;const H={allowPromptingSubagentSessions:C};for(const V of Q.current.values()){const J=V.contentWindow;J&&J.postMessage({type:"openchamber:chat-settings-sync",payload:H},window.location.origin)}},[C]),Ve=c.useCallback((H,V,J)=>{const ge=V.contentWindow;ge&&ge.postMessage({type:$u,payload:{visible:$===H}},J)},[$]),z=c.useCallback(()=>{if(!(typeof window>"u"))for(const[H,V]of Q.current.entries())Ve(H,V,window.location.origin)},[Ve]);c.useEffect(()=>{if(typeof window>"u")return;const H=V=>{if(V.origin!==window.location.origin)return;const J=Array.from(Q.current.entries()).find(([,Ze])=>Ze.contentWindow===V.source);if(!J)return;const ge=V.data;if(ge?.type===Mx){const[Ze,et]=J;Ve(Ze,et,V.origin);return}if(ge?.type===Ox){if(typeof ge.requestId!="string"||!ge.requestId)return;const Ze=ls(),et={apiBaseUrl:Pn(),clientToken:Kr(),localOrigin:typeof window.__OPENCHAMBER_LOCAL_ORIGIN__=="string"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"",runtimeHeaders:kd(),relayHostId:Ze.startsWith("host:")?Ze.slice(5):"",relay:Af()??void 0};V.source?.postMessage({type:Bx,requestId:ge.requestId,payload:et},V.origin);return}if(ge?.type==="openchamber:theme-sync-request"){Oe();return}if(ge?.type==="openchamber:chat-settings-request"){_e();return}if(ge?.type!=="openchamber:cycle-theme-request")return;const Ee=["light","dark","system"],st=(Ee.indexOf(N)+1)%Ee.length;k(Ee[st])};return window.addEventListener("message",H),()=>window.removeEventListener("message",H)},[_e,Ve,Oe,k,N]),c.useLayoutEffect(()=>{T.some(V=>V.mode==="chat")&&(Oe(),_e(),z())},[I,R,_e,z,Oe,T,N]);const pe=E?.mode==="file"||E?.mode==="chat"||E?.mode==="browser",Ae=c.useMemo(()=>E?T.filter(H=>H.mode===E.mode):[],[E,T]),Be=c.useMemo(()=>Ae.map(H=>{const V=MS(H,Se,t),J=WS(V,DS),ge=ES(H.targetPath,e);return{id:H.id,label:J,icon:wc(H,S),title:ge?`${V}: ${ge}`:V,closeLabel:t("contextPanel.tab.closeTabAria",{label:J})}}),[Ae,e,S,Se,t]),rt=E?.mode==="context"?s.jsx(w1,{}):E?.mode==="git"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(vS,{isActive:O})}):E?.mode==="pr"?s.jsx(Py,{}):E?.mode==="linear"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(jS,{})}):E?.mode==="notes"?s.jsx(nh,{}):E?.mode==="plan"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(kS,{targetPath:E.targetPath,savedProjectPlan:E.projectPlanId&&E.projectPlanRef?{projectRef:E.projectPlanRef,planId:E.projectPlanId}:null})}):null,Ge=c.useMemo(()=>T.filter(H=>H.mode==="browser"),[T]),ut=c.useMemo(()=>T.filter(H=>H.mode==="diff"),[T]),at=c.useMemo(()=>T.find(H=>H.mode==="terminal")??null,[T]),wt=c.useMemo(()=>T.some(H=>H.mode==="walkthrough"),[T]),pt=c.useMemo(()=>T.filter(H=>Xn(H.mode)),[T]),It=c.useMemo(()=>T.some(H=>H.mode==="file"),[T]),Pt=E?.mode==="file",Rt=Ne(H=>H.closeContextPanelTabs),de=c.useCallback(H=>{if(!n)return null;const{id:V,index:J,allIds:ge,close:Ee}=H,$e=()=>Rt(n,ge.filter(xe=>xe!==V)),st=()=>Rt(n,ge.slice(0,J)),Ze=()=>Rt(n,ge.slice(J+1)),et=()=>Rt(n,ge),Ue=ge.length>1,jt=J===0,ze=J===ge.length-1;return s.jsxs(s.Fragment,{children:[s.jsxs(Gn,{onClick:Ee,children:[s.jsx(B,{name:"close",className:"mr-2 size-4"}),t("contextPanel.tab.menu.close")]}),s.jsx(Di,{}),s.jsxs(Gn,{onClick:$e,disabled:!Ue,children:[s.jsx(B,{name:"expand-horizontal",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeOthers")]}),s.jsxs(Gn,{onClick:st,disabled:jt,children:[s.jsx(B,{name:"expand-left",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeToLeft")]}),s.jsxs(Gn,{onClick:Ze,disabled:ze,children:[s.jsx(B,{name:"expand-right",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeToRight")]}),s.jsx(Di,{}),s.jsxs(Gn,{onClick:et,disabled:!Ue,children:[s.jsx(B,{name:"close-circle",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeAll")]})]})},[Rt,n,t]),We=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[pe?s.jsx(Pd,{items:Be,activeId:E?.id??null,onSelect:H=>{n&&d(n,H)},onClose:H=>{n&&o(n,H)},onReorder:(H,V)=>{n&&f(n,H,V)},layoutMode:"scrollable",variant:"default",tabContextMenu:de}):s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[E?wc(E,S):null,s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:E?km(E.mode,t):null})]}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[E?.mode==="browser"?s.jsx(dt,{type:"button",variant:"ghost",size:"sm",onClick:()=>{n&&b(n)},className:"h-7 w-7 p-0",title:t("contextPanel.browser.newTab"),"aria-label":t("contextPanel.browser.newTab"),children:s.jsx(B,{name:"add",className:"h-3.5 w-3.5"})}):null,Pt&&F?s.jsx(dt,{type:"button",variant:"ghost",size:"sm",onClick:x,className:"h-7 w-7 p-0",title:t("contextRail.editor.toggle"),"aria-label":t("contextRail.editor.toggle"),"aria-pressed":D,children:s.jsx(B,{name:"layout-left",className:"h-3.5 w-3.5"})}):null,Pt?s.jsx(dt,{type:"button",variant:"ghost",size:"sm",onClick:y,className:"h-7 w-7 p-0",title:t("contextRail.editorTree.toggle"),"aria-label":t("contextRail.editorTree.toggle"),"aria-pressed":g,children:s.jsx(B,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,A?null:s.jsx(dt,{type:"button",variant:"ghost",size:"sm",onClick:ae,className:"h-7 w-7 p-0",title:t(M?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(M?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:M?s.jsx(B,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(dt,{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(B,{name:"close",className:"h-3.5 w-3.5"})})]})]}),lt=O?M?{"--oc-context-panel-width":W!==null?`${W}px`:"100%",width:W!==null?`${W}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${te}px`}:{"--oc-context-panel-width":`${te}px`,width:0,maxWidth:"100%",overflowX:"clip"};return s.jsxs("aside",{ref:ce,"data-context-panel":"true",tabIndex:-1,inert:!O||void 0,className:Ie("flex min-h-0 flex-col overflow-hidden bg-background",M?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!O&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:ee,style:lt,children:[O&&!M&&s.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),O&&s.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!M&&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",ue&&"bg-[var(--interactive-border)]"),onPointerDown:Re,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]",!O&&"pointer-events-none select-none opacity-0"),style:{width:M?W!==null?`${W}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!O,children:[We,s.jsxs("div",{className:Ie("relative min-h-0 flex-1 overflow-hidden",ue&&"pointer-events-none"),children:[It?s.jsxs("div",{className:Ie("absolute inset-0 flex",Pt?"flex":"hidden"),children:[F||!g?s.jsx("div",{className:Ie("h-full min-w-0 flex-1",F&&!D&&"hidden"),children:F?s.jsx(c.Suspense,{fallback:null,children:s.jsx(SS,{mode:"editor-only",visible:O&&Pt&&D})}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(B,{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")})]})}):null,s.jsx(FS,{visible:g,active:O&&Pt,fill:!D})]}):null,U&&ne&&he?s.jsx("iframe",{ref:H=>{if(!H){Q.current.delete(U.id);return}Q.current.set(U.id,H)},src:he,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ne}),className:"absolute inset-0 h-full w-full border-0 bg-background",onLoad:()=>{Oe(),_e(),z()}},U.id):null,Ge.map(H=>s.jsx("div",{className:Ie("absolute inset-0",E?.id!==H.id&&"hidden"),children:s.jsx(hS,{initialUrl:H.targetPath??"",directory:n,tabID:H.id})},H.id)),ut.map(H=>s.jsx("div",{className:Ie("absolute inset-0",E?.id!==H.id&&"hidden"),children:s.jsx(c.Suspense,{fallback:null,children:s.jsx(wS,{visible:O&&E?.id===H.id,hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:H.diffScope??(H.stagedDiff?"staged":"working"),onDiffScopeChange:Te,targetFilePath:H.targetPath,flushContent:!0})})},H.id)),at?s.jsx("div",{className:Ie("absolute inset-0",E?.mode==="terminal"?"block":"hidden"),children:s.jsx(rh,{visible:O&&E?.mode==="terminal",directory:at.targetDirectory})}):null,wt?s.jsx("div",{className:Ie("absolute inset-0",E?.mode==="walkthrough"?"block":"hidden"),children:s.jsx(c.Suspense,{fallback:null,children:s.jsx(yS,{directory:e,visible:O&&E?.mode==="walkthrough"})})}):null,pt.map(H=>Xn(H.mode)?s.jsx("div",{className:Ie("absolute inset-0",E?.id===H.id?"block":"hidden"),children:s.jsx(c.Suspense,{fallback:null,children:s.jsx(CS,{mode:H.mode})})},H.id):null),E?.mode!=="chat"&&!Pt&&E?.mode!=="browser"&&E?.mode!=="diff"&&E?.mode!=="terminal"&&E?.mode!=="walkthrough"&&!(E&&Xn(E.mode))?rt:null]})]})]})},VS=t=>{const e=nt.c(43),{open:n,onOpenChange:r}=t,{t:i}=vt(),o=Ne(US),l=Ne(KS),a=Ne(HS),u=Ne(GS),d=Pa();let h;e[0]!==o||e[1]!==d?(h=cu(o,d),e[0]=o,e[1]=d,e[2]=h):h=e[2];const f=h,p=l.length===0;let g;if(e[3]!==l||e[4]!==f){let I;e[6]!==l?(I=P=>l.includes(P.id),e[6]=l,e[7]=I):I=e[7],g=f.every(I),e[3]=l,e[4]=f,e[5]=g}else g=e[5];const w=g;let v;e[8]!==i?(v=i("contextRail.configure.dialogTitle"),e[8]=i,e[9]=v):v=e[9];let y;e[10]!==v?(y=s.jsx(_s,{children:v}),e[10]=v,e[11]=y):y=e[11];let m;e[12]!==i?(m=i("contextRail.configure.dialogDescription"),e[12]=i,e[13]=m):m=e[13];let x;e[14]!==m?(x=s.jsx(Ls,{children:m}),e[14]=m,e[15]=x):x=e[15];let b;e[16]!==y||e[17]!==x?(b=s.jsxs(Xs,{children:[y,x]}),e[16]=y,e[17]=x,e[18]=b):b=e[18];let S;if(e[19]!==l||e[20]!==a||e[21]!==f||e[22]!==i){let I;e[24]!==l||e[25]!==a||e[26]!==i?(I=P=>s.jsx(pp,{settingsItem:`layout.context-rail.surface.${P.id}`,checked:!l.includes(P.id),onChange:T=>a(P.id,T),label:P.label??i(P.labelKey),ariaLabel:P.label??i(P.labelKey)},P.id),e[24]=l,e[25]=a,e[26]=i,e[27]=I):I=e[27],S=f.map(I),e[19]=l,e[20]=a,e[21]=f,e[22]=i,e[23]=S}else S=e[23];let C;e[28]!==S?(C=s.jsx("div",{className:"flex flex-col",children:S}),e[28]=S,e[29]=C):C=e[29];let N;e[30]!==p||e[31]!==w||e[32]!==u||e[33]!==i?(N=p?null:s.jsxs("div",{className:"flex items-center justify-between border-t pt-3",children:[w?s.jsx("span",{className:"text-xs text-destructive",children:i("contextRail.configure.noneWarning")}):s.jsx("span",{}),s.jsx(dt,{variant:"link",size:"xs",onClick:()=>u([]),className:"normal-case text-muted-foreground hover:text-foreground",children:i("contextRail.configure.showAll")})]}),e[30]=p,e[31]=w,e[32]=u,e[33]=i,e[34]=N):N=e[34];let k;e[35]!==N||e[36]!==b||e[37]!==C?(k=s.jsxs(Is,{className:"max-w-md",children:[b,C,N]}),e[35]=N,e[36]=b,e[37]=C,e[38]=k):k=e[38];let R;return e[39]!==r||e[40]!==n||e[41]!==k?(R=s.jsx(Ds,{open:n,onOpenChange:r,children:k}),e[39]=r,e[40]=n,e[41]=k,e[42]=R):R=e[42],R};function US(t){return t.contextRailOrder}function KS(t){return t.contextRailHiddenSurfaces}function HS(t){return t.setContextRailSurfaceVisible}function GS(t){return t.setContextRailHiddenSurfaces}const Cm=150,qS=500,QS=[],YS=t=>t>99?"99+":String(t),XS=t=>{const e=nt.c(52),{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:y,transform:m,transition:x,isDragging:b}=Zo(g);let S;e[2]!==a?(S=a!=null&&a>0?YS(a):null,e[2]=a,e[3]=S):S=e[3];const C=S;let N;e[4]!==m?(N=ei.Translate.toString(m),e[4]=m,e[5]=N):N=e[5];let k;e[6]!==N||e[7]!==x?(k={transform:N,transition:x},e[6]=N,e[7]=x,e[8]=k):k=e[8];const R=b&&"z-10 opacity-70";let I;e[9]!==R?(I=Ie("relative",R),e[9]=R,e[10]=I):I=e[10];let P;e[11]!==p||e[12]!==n?(P=()=>p(n),e[11]=p,e[12]=n,e[13]=P):P=e[13];const T=u??o,E=r?"text-primary":"text-muted-foreground hover:text-foreground";let O;e[14]!==E?(O=Ie("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",E),e[14]=E,e[15]=O):O=e[15];let W;e[16]!==n.icon||e[17]!==n.iconSrc||e[18]!==n.id?(W=n.id==="diff"?s.jsx(Ju,{className:"h-[18px] w-[18px]"}):s.jsx(Jr,{icon:n.icon,iconSrc:n.iconSrc,className:"h-[18px] w-[18px]"}),e[16]=n.icon,e[17]=n.iconSrc,e[18]=n.id,e[19]=W):W=e[19];let L;e[20]!==C||e[21]!==h||e[22]!==i||e[23]!==f?(L=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}):C?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:C}):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[20]=C,e[21]=h,e[22]=i,e[23]=f,e[24]=L):L=e[24];let F;e[25]!==w||e[26]!==r||e[27]!==v||e[28]!==O||e[29]!==W||e[30]!==L||e[31]!==P||e[32]!==T?(F=s.jsx(Nt,{asChild:!0,children:s.jsxs("button",{type:"button",...w,...v,onClick:P,"aria-label":T,"aria-pressed":r,className:O,children:[W,L]})}),e[25]=w,e[26]=r,e[27]=v,e[28]=O,e[29]=W,e[30]=L,e[31]=P,e[32]=T,e[33]=F):F=e[33];let D;e[34]!==o?(D=s.jsx("span",{children:o}),e[34]=o,e[35]=D):D=e[35];let j;e[36]!==l?(j=s.jsx("span",{className:"typography-micro text-muted-foreground",children:l}),e[36]=l,e[37]=j):j=e[37];let A;e[38]!==d?(A=d?s.jsx("span",{className:"typography-micro text-muted-foreground",children:d}):null,e[38]=d,e[39]=A):A=e[39];let M;e[40]!==D||e[41]!==j||e[42]!==A?(M=s.jsx(At,{side:"left",sideOffset:8,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[D,j,A]})}),e[40]=D,e[41]=j,e[42]=A,e[43]=M):M=e[43];let G;e[44]!==F||e[45]!==M?(G=s.jsxs(Ct,{delayDuration:Cm,children:[F,M]}),e[44]=F,e[45]=M,e[46]=G):G=e[46];let q;return e[47]!==y||e[48]!==G||e[49]!==k||e[50]!==I?(q=s.jsx("div",{ref:y,style:k,className:I,children:G}),e[47]=y,e[48]=G,e[49]=k,e[50]=I,e[51]=q):q=e[51],q},JS=()=>{const t=nt.c(92),{t:e}=vt(),n=rr();let r;t[0]!==n?(r=n?lr(n):"",t[0]=n,t[1]=r):r=t[1];const i=r;let o;t[2]!==i?(o=ae=>i?ae.contextPanelByDirectory[i]:void 0,t[2]=i,t[3]=o):o=t[3];const l=Ne(o),a=Ne(ZS),u=Ne(ev),d=Ne(tv),h=Ne(sv),f=Ne(nv),p=Ne(rv),g=Ne(ov),w=ka(iv),v=Oi(av),y=Oi(lv),m=Dn(cv),x=Dn(dv),{screenWidth:b}=Wn(),S=Ca(i||null);let C;t[4]!==g?(C=Bi("switch_context_surface",g),t[4]=g,t[5]=C):C=t[5];const N=C,[k,R]=c.useState(!1);let I,P;t[6]!==N?(I=()=>{const ae=new Set;let ee=null,K=!1;const $=uv,ne=()=>{xl(N,ae)?!K&&ee===null&&(ee=setTimeout(()=>R(!0),qS)):(K=!1,ee!==null&&(clearTimeout(ee),ee=null),R(!1))},U=Te=>{if(ae.add(Te.key.toLowerCase()),$(Te.key)&&xl(N,ae)){K=!0,ee!==null&&(clearTimeout(ee),ee=null),R(!1);return}ne()},we=Te=>{ae.delete(Te.key.toLowerCase()),ne()},he=()=>{ae.clear(),K=!1,ee!==null&&(clearTimeout(ee),ee=null),R(!1)};return window.addEventListener("keydown",U,!0),window.addEventListener("keyup",we,!0),window.addEventListener("blur",he),()=>{window.removeEventListener("keydown",U,!0),window.removeEventListener("keyup",we,!0),window.removeEventListener("blur",he),ee!==null&&clearTimeout(ee)}},P=[N],t[6]=N,t[7]=I,t[8]=P):(I=t[7],P=t[8]),c.useEffect(I,P);let T;t[9]===Symbol.for("react.memo_cache_sentinel")?(T={activationConstraint:{distance:8}},t[9]=T):T=t[9];let E;t[10]===Symbol.for("react.memo_cache_sentinel")?(E={activationConstraint:{delay:200,tolerance:6}},t[10]=E):E=t[10];const O=qr(_n(Ru,T),_n(Eu,E)),W=Pa(),L=gl(mv),F=gl(fv),D=l?.tabs??QS;let j;t[11]!==l?.activeTabId||t[12]!==D?(j=D.find(ae=>ae.id===l?.activeTabId)??null,t[11]=l?.activeTabId,t[12]=D,t[13]=j):j=t[13];const A=j,M=l?.isOpen?A?.mode??null:null,G=S?.files.length??0;let q;t[14]!==d||t[15]!==u||t[16]!==x||t[17]!==W||t[18]!==y||t[19]!==w||t[20]!==b||t[21]!==D?(q=gp({railOrder:u,hiddenSurfaces:d,planModeEnabled:w,isVSCode:$n(),screenWidth:b,tabs:D,linearConnected:y,githubConnected:x,extras:W}),t[14]=d,t[15]=u,t[16]=x,t[17]=W,t[18]=y,t[19]=w,t[20]=b,t[21]=D,t[22]=q):q=t[22];const Z=q;let le,X;t[23]!==M||t[24]!==p||t[25]!==i||t[26]!==v||t[27]!==y?(X=()=>{!i||!v||y||M!=="linear"||p(i)},le=[M,p,i,v,y],t[23]=M,t[24]=p,t[25]=i,t[26]=v,t[27]=y,t[28]=le,t[29]=X):(le=t[28],X=t[29]),c.useEffect(X,le);let te,re;t[30]!==M||t[31]!==p||t[32]!==i||t[33]!==m||t[34]!==x?(te=()=>{!i||!m||x||M!=="pr"||p(i)},re=[M,p,i,m,x],t[30]=M,t[31]=p,t[32]=i,t[33]=m,t[34]=x,t[35]=te,t[36]=re):(te=t[35],re=t[36]),c.useEffect(te,re);const[Se,ue]=c.useState(!1);let ye;t[37]!==W||t[38]!==h?(ye=ae=>{const{active:ee,over:K}=ae;if(!K||ee.id===K.id)return;const $=cu(Ne.getState().contextRailOrder,W).map(hv),ne=$.indexOf(ee.id),U=$.indexOf(K.id);ne===-1||U===-1||h(Mu($,ne,U))},t[37]=W,t[38]=h,t[39]=ye):ye=t[39];const ve=ye;if(!i)return null;let be;t[40]!==e?(be=e("contextRail.aria.rail"),t[40]=e,t[41]=be):be=t[41];let _;t[42]!==Z?(_=Z.map(pv),t[42]=Z,t[43]=_):_=t[43];let oe;if(t[44]!==M||t[45]!==G||t[46]!==F||t[47]!==i||t[48]!==L||t[49]!==f||t[50]!==k||t[51]!==Z||t[52]!==e||t[53]!==a){let ae;t[55]!==M||t[56]!==G||t[57]!==F||t[58]!==i||t[59]!==L||t[60]!==f||t[61]!==k||t[62]!==e||t[63]!==a?(ae=(ee,K)=>{const $=ee.label??e(ee.labelKey),ne=ee.id==="git"&&!a?G:0,U=Xn(ee.mode)&&M!==ee.mode?L[Ci(ee.mode)]??0:0,we=ne>0?ne:U>0?U:null,he=we!==null&&ne===0;return s.jsx(XS,{surface:ee,isActive:M===ee.mode,showActivityDot:!1,label:$,description:e(ee.descriptionKey),badgeCount:we,badgeAriaLabel:we!==null?e(he?we===1?"contextRail.surface.plugin.badgeAriaSingle":"contextRail.surface.plugin.badgeAriaPlural":we===1?"contextRail.surface.git.changesCountAriaSingle":"contextRail.surface.git.changesCountAriaPlural",{label:$,count:we}):null,badgeDescription:we!==null?e(he?we===1?"contextRail.surface.plugin.badgeTooltipSingle":"contextRail.surface.plugin.badgeTooltipPlural":we===1?"contextRail.surface.git.changesCountTooltipSingle":"contextRail.surface.git.changesCountTooltipPlural",{count:we}):null,orderNumber:K+1,showOrderNumber:k,onSelect:Te=>{Xn(Te.mode)&&F(Ci(Te.mode)),f(i,Te.mode)}},ee.id)},t[55]=M,t[56]=G,t[57]=F,t[58]=i,t[59]=L,t[60]=f,t[61]=k,t[62]=e,t[63]=a,t[64]=ae):ae=t[64],oe=Z.map(ae),t[44]=M,t[45]=G,t[46]=F,t[47]=i,t[48]=L,t[49]=f,t[50]=k,t[51]=Z,t[52]=e,t[53]=a,t[54]=oe}else oe=t[54];let ce;t[65]!==_||t[66]!==oe?(ce=s.jsx(Mo,{items:_,strategy:Ui,children:oe}),t[65]=_,t[66]=oe,t[67]=ce):ce=t[67];let Q;t[68]!==ve||t[69]!==O||t[70]!==ce?(Q=s.jsx(Qr,{sensors:O,collisionDetection:Yr,onDragEnd:ve,children:ce}),t[68]=ve,t[69]=O,t[70]=ce,t[71]=Q):Q=t[71];let me;t[72]!==e?(me=e("contextRail.configure.open"),t[72]=e,t[73]=me):me=t[73];let ke;t[74]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>ue(!0),t[74]=ke):ke=t[74];let fe;t[75]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx(B,{name:"equalizer-2",className:"h-[18px] w-[18px]"}),t[75]=fe):fe=t[75];let De;t[76]!==me?(De=s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":me,onClick:ke,className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground",children:fe})}),t[76]=me,t[77]=De):De=t[77];let je;t[78]!==e?(je=e("contextRail.configure.open"),t[78]=e,t[79]=je):je=t[79];let Y;t[80]!==je?(Y=s.jsx(At,{side:"left",sideOffset:8,children:je}),t[80]=je,t[81]=Y):Y=t[81];let Re;t[82]!==De||t[83]!==Y?(Re=s.jsxs(Ct,{delayDuration:Cm,children:[De,Y]}),t[82]=De,t[83]=Y,t[84]=Re):Re=t[84];let Ce;t[85]!==Se?(Ce=s.jsx(VS,{open:Se,onOpenChange:ue}),t[85]=Se,t[86]=Ce):Ce=t[86];let Me;return t[87]!==be||t[88]!==Q||t[89]!==Re||t[90]!==Ce?(Me=s.jsxs("nav",{"aria-label":be,className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:[Q,Re,Ce]}),t[87]=be,t[88]=Q,t[89]=Re,t[90]=Ce,t[91]=Me):Me=t[91],Me};function ZS(t){return t.workStatusPanelVisible}function ev(t){return t.contextRailOrder}function tv(t){return t.contextRailHiddenSurfaces}function sv(t){return t.setContextRailOrder}function nv(t){return t.openContextSurface}function rv(t){return t.closeContextPanel}function ov(t){return t.shortcutOverrides}function iv(t){return t.planModeEnabled}function av(t){return t.hasChecked}function lv(t){return t.status?.connected===!0}function cv(t){return t.hasChecked}function dv(t){return t.status?.connected===!0}function uv(t){return t.length===1&&t>="0"&&t<="9"}function mv(t){return t.countByGuest}function fv(t){return t.clearBadge}function hv(t){return t.id}function pv(t){return t.id}const gv=c.lazy(()=>hn(()=>import("./GuestAttachDialog-B-fwE8r3.js").then(t=>t.l),__vite__mapDeps([85,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.GuestAttachDialog}))),xv=c.lazy(()=>hn(()=>import("./GuestAttachDialog-B-fwE8r3.js").then(t=>t.k),__vite__mapDeps([85,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.PluginPane}))),bv=()=>{const t=nt.c(8),e=bl(yv),n=bl(wv),r=xp(Sv);let i;t[0]!==n||t[1]!==e?(i=e?s.jsx(c.Suspense,{fallback:null,children:s.jsx(gv,{guestId:e.guestId,item:e.item,onOpenChange:a=>{a||n()}})}):null,t[0]=n,t[1]=e,t[2]=i):i=t[2];let o;t[3]!==r?(o=r?s.jsx("div",{"aria-hidden":"true",className:"pointer-events-none fixed top-0 -left-[9999px] h-px w-px overflow-hidden",children:s.jsx(c.Suspense,{fallback:null,children:s.jsx(xv,{mode:Pf(r),surface:"panel",headless:!0})})}):null,t[3]=r,t[4]=o):o=t[4];let l;return t[5]!==i||t[6]!==o?(l=s.jsxs(s.Fragment,{children:[i,o]}),t[5]=i,t[6]=o,t[7]=l):l=t[7],l};function yv(t){return t.request}function wv(t){return t.close}function Sv(t){return t.guestId}const vv=(t,e)=>!t||e.length===0?"":JSON.stringify([t,e]),jv=(t,e,n,r)=>!n||r!==n||t.length===0?[]:Fr(t,e,i=>i.relativePath||i.name,{limit:10,threshold:.4}),kv=new Set,Cv=[],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},Nv=()=>{const t=nt.c(182),{t:e}=vt(),n=Ne(Av),r=Ne(Pv),i=Ne(Dv),o=Ne(Iv),l=Ne(Tv),a=Ne(Ev),u=Ne(Rv),d=Ne(Mv),h=Ne(Ov),f=Ne(Bv),p=Ne(Fv),g=Ne(_v),w=Ne(Lv),v=tt($v),y=tt(Wv),m=tt(zv),x=Hr(Vv);let b;t[0]!==n?(b=Xe=>n?Xe.activeSessions:Cv,t[0]=n,t[1]=b):b=t[1];const S=Gs(b);let C;t[2]!==n?(C=Xe=>n?Xe.ids:kv,t[2]=n,t[3]=C):C=t[3];const N=Hr(C);let k;t[4]!==n?(k=Xe=>n?Xe.rankById:uu,t[4]=n,t[5]=k):k=t[5];const R=Da(k),I=is(Uv),P=qt(Kv),T=qt(Hv),E=rr(),O=jd(Gv),{files:W,git:L}=jn(),F=In(qv),{isMobile:D}=Wn();let j;t[6]!==E?(j=E?aa(E):null,t[6]=E,t[7]=j):j=t[7];const A=j,[M,G]=c.useState(""),Z=ou(M,200).trim();let le;t[8]!==M?(le=M.trim(),t[8]=M,t[9]=le):le=t[9];const X=le;let te,re;t[10]!==n?(te=()=>{n&&G("")},re=[n],t[10]=n,t[11]=te,t[12]=re):(te=t[11],re=t[12]),c.useEffect(te,re);let Se,ue;t[13]!==S||t[14]!==F||t[15]!==L||t[16]!==n?(Se=()=>{if(!n||!L)return;const Xe=setTimeout(()=>{const Ke=new Set;for(const Ye of S){const gt=Fs(Ye);!gt||Ke.has(gt)||(Ke.add(gt),F(gt,L))}},0);return()=>clearTimeout(Xe)},ue=[n,S,L,F],t[13]=S,t[14]=F,t[15]=L,t[16]=n,t[17]=Se,t[18]=ue):(Se=t[17],ue=t[18]),c.useEffect(Se,ue);let ye;t[19]!==r?(ye=()=>r(!1),t[19]=r,t[20]=ye):ye=t[20];const ve=ye;let be;t[21]!==ve?(be=Xe=>()=>{ve(),Xe()},t[21]=ve,t[22]=be):be=t[22];const _=be;let oe;t[23]!==P?.id||t[24]!==P?.path||t[25]!==I||t[26]!==m||t[27]!==D||t[28]!==u||t[29]!==d||t[30]!==p||t[31]!==v||t[32]!==_||t[33]!==g||t[34]!==w||t[35]!==l||t[36]!==i||t[37]!==e||t[38]!==x||t[39]!==a?(oe=()=>{const Xe=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(B,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:_(()=>{l(!1),v()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(B,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:_(Qv)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(B,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:_(Yv)},{id:"toggle-sidebar",title:e(D?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(B,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(D?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:_(()=>{if(D){const{isSessionSwitcherOpen:Ke}=Ne.getState();l(!Ke)}else a()})},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(B,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:_(()=>{I&&d(I,"terminal")})},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(B,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:_(()=>{I&&u(I)})},{id:"cycle-theme",secondary:!0,title:e("commandPalette.item.cycleTheme"),icon:s.jsx(B,{name:"palette",className:"mr-2 h-4 w-4"}),shortcutId:"cycle_theme",searchText:e("commandPalette.item.cycleTheme"),onSelect:_(Xv)},{id:"open-status",secondary:!0,title:e("commandPalette.item.showOpenCodeStatus"),icon:s.jsx(B,{name:"pulse",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showOpenCodeStatus"),onSelect:_(Jv)},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(B,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:_(()=>i(!0))}];return Xe.push({id:"pin-session",secondary:!0,title:e("commandPalette.item.pinSession"),icon:s.jsx(B,{name:"pushpin",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.pinSession"),onSelect:_(()=>{m&&I&&x({directory:I,sessionId:m})})},{id:"copy-session-id",secondary:!0,title:e("commandPalette.item.copySessionId"),icon:s.jsx(B,{name:"file-copy",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.copySessionId"),onSelect:_(()=>{m&&xn(m).then(Ke=>{if(Ke.ok){Fe.success(e("sessions.sidebar.session.copyId.success"));return}Fe.error(e("sessions.sidebar.session.copyId.error"))}).catch(()=>Fe.error(e("sessions.sidebar.session.copyId.error")))})},{id:"open-multi-run",secondary:!0,title:e("commandPalette.item.openMultiRun"),icon:s.jsx(B,{name:"checkbox-multiple",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openMultiRun"),onSelect:_(()=>{l(!1),p()})},{id:"open-archive",secondary:!0,title:e("commandPalette.item.openArchive"),icon:s.jsx(B,{name:"archive",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openArchive"),onSelect:_(()=>{l(!1),g(!0)})},{id:"open-notes",secondary:!0,title:e("commandPalette.item.openNotes"),icon:s.jsx(B,{name:"sticky-note",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openNotes"),onSelect:_(()=>{I&&(w("notes"),d(I,"notes"))})},{id:"open-todos",secondary:!0,title:e("commandPalette.item.openTodos"),icon:s.jsx(B,{name:"checkbox-circle",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openTodos"),onSelect:_(()=>{I&&(w("todos"),d(I,"notes"))})}),Xe.push({id:"toggle-memory-debug",secondary:!0,title:e("commandPalette.item.toggleMemoryDebug"),icon:s.jsx(B,{name:"bug",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.toggleMemoryDebug"),onSelect:_(Zv)}),Ur()&&Xe.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(B,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:_(()=>{Fn("desktop_open_draft_mini_chat_window",{directory:aa(I||P?.path||""),projectId:P?.id??null}).catch(e0)})}),Xe},t[23]=P?.id,t[24]=P?.path,t[25]=I,t[26]=m,t[27]=D,t[28]=u,t[29]=d,t[30]=p,t[31]=v,t[32]=_,t[33]=g,t[34]=w,t[35]=l,t[36]=i,t[37]=e,t[38]=x,t[39]=a,t[40]=oe):oe=t[40],P?.id,P?.path;let ce;t[41]!==oe?(ce=oe(),t[41]=oe,t[42]=ce):ce=t[42];const Q=ce;let me;t[43]===Symbol.for("react.memo_cache_sentinel")?(me=yn(),t[43]=me):me=t[43];const ke=me;let fe,De;t[44]===Symbol.for("react.memo_cache_sentinel")?(fe=$n(),De=!ke&&wa(),t[44]=fe,t[45]=De):(fe=t[44],De=t[45]);let je;t[46]!==D?(je={isVSCode:fe,isWeb:De,isDesktop:ke,isMobile:D},t[46]=D,t[47]=je):je=t[47];const Y=je;let Re;if(t[48]!==_||t[49]!==i||t[50]!==o||t[51]!==Y){let Xe;t[53]!==Y?(Xe=Ye=>Ye.isAvailable?Ye.isAvailable(Y):!0,t[53]=Y,t[54]=Xe):Xe=t[54];let Ke;t[55]!==_||t[56]!==i||t[57]!==o?(Ke=Ye=>{const gt=ih(Ye.slug)??"settings-3",Mt=(Ye.keywords??[]).join(" ");return{id:`settings:${Ye.slug}`,title:Ye.title,icon:Ye.slug==="mcp"?s.jsx(vp,{className:"mr-2 h-4 w-4"}):s.jsx(B,{name:gt,className:"mr-2 h-4 w-4"}),searchText:`${Ye.title} ${Ye.group} ${Mt}`,onSelect:_(()=>{o(Ye.slug),i(!0)})}},t[55]=_,t[56]=i,t[57]=o,t[58]=Ke):Ke=t[58],Re=oh.filter(t0).filter(Xe).map(Ke),t[48]=_,t[49]=i,t[50]=o,t[51]=Y,t[52]=Re}else Re=t[52];const Ce=Re;let Me;if(t[59]!==S||t[60]!==N||t[61]!==R){const Xe=S.filter(s0);Me=bp(Xe,N,R),t[59]=S,t[60]=N,t[61]=R,t[62]=Me}else Me=t[62];const ae=Me,ee=du(),K=tt(n0);let $;t[63]!==ee||t[64]!==K?($=(Xe,Ke)=>{const Ye=K.get(Xe);return Ye?.branch?Ye.branch.trim()||null:Ke&&ee.get(Ke)?.trim()||null},t[63]=ee,t[64]=K,t[65]=$):$=t[65];const ne=$;let U;t[66]===Symbol.for("react.memo_cache_sentinel")?(U=[],t[66]=U):U=t[66];const[we,he]=c.useState(U),[Te,Oe]=c.useState(""),_e=vv(A,Z);let Ve;t[67]!==A||t[68]!==_e||t[69]!==n||t[70]!==O||t[71]!==he||t[72]!==Oe||t[73]!==Z?(Ve=()=>{if(!n){he([]),Oe("");return}if(!_e){he([]),Oe("");return}if(!A){he([]),Oe("");return}let Xe=!1;return O(A,Z,40,{type:"file"}).then(Ke=>{Xe||(he(Ke.map(r0)),Oe(_e))}).catch(()=>{Xe||(he([]),Oe(_e))}),()=>{Xe=!0}},t[67]=A,t[68]=_e,t[69]=n,t[70]=O,t[71]=he,t[72]=Oe,t[73]=Z,t[74]=Ve):Ve=t[74];let z;t[75]!==A||t[76]!==_e||t[77]!==n||t[78]!==O||t[79]!==Z?(z=[n,A,Z,_e,O],t[75]=A,t[76]=_e,t[77]=n,t[78]=O,t[79]=Z,t[80]=z):z=t[80],c.useEffect(Ve,z);const pe=X.length>0;let Ae;e:{if(!pe){let Ke;t[81]!==Q?(Ke=Q.filter(o0).map(i0),t[81]=Q,t[82]=Ke):Ke=t[82],Ae=Ke;break e}let Xe;t[83]!==Q||t[84]!==X?(Xe=Fr(Q,X,a0,{limit:7,noFuzzy:!0}),t[83]=Q,t[84]=X,t[85]=Xe):Xe=t[85],Ae=Xe}const Be=Ae;let rt;e:{if(!pe){let Ke;t[86]===Symbol.for("react.memo_cache_sentinel")?(Ke=[],t[86]=Ke):Ke=t[86],rt=Ke;break e}let Xe;t[87]!==X||t[88]!==Ce?(Xe=Fr(Ce,X,l0,{limit:7,noFuzzy:!0}),t[87]=X,t[88]=Ce,t[89]=Xe):Xe=t[89],rt=Xe}const Ge=rt;let ut;e:{if(!pe){let Ke;t[90]!==ae?(Ke=ae.slice(0,5).map(c0),t[90]=ae,t[91]=Ke):Ke=t[91],ut=Ke;break e}let Xe;t[92]!==X||t[93]!==ae?(Xe=Fr(ae,X,d0,{limit:7,threshold:.2}),t[92]=X,t[93]=ae,t[94]=Xe):Xe=t[94],ut=Xe}const at=ut;let wt;e:{if(!n){let Ke;t[95]===Symbol.for("react.memo_cache_sentinel")?(Ke=[],t[95]=Ke):Ke=t[95],wt=Ke;break e}let Xe;t[96]!==we||t[97]!==Te||t[98]!==_e||t[99]!==Z?(Xe=jv(we,Z,_e,Te),t[96]=we,t[97]=Te,t[98]=_e,t[99]=Z,t[100]=Xe):Xe=t[100],wt=Xe}const pt=wt,It=n&&_e.length>0&&Te!==_e;let Pt;e:{if(!pe){let Ke;t[101]===Symbol.for("react.memo_cache_sentinel")?(Ke=[],t[101]=Ke):Ke=t[101],Pt=Ke;break e}let Xe;if(t[102]!==X||t[103]!==T){const Ke=T.map(u0);Xe=Fr(Ke,X,m0,{limit:7,threshold:.4}),t[102]=X,t[103]=T,t[104]=Xe}else Xe=t[104];Pt=Xe}const Rt=Pt;let de,We,lt,H,V,J,ge,Ee,$e,st,Ze,et,Ue,jt;if(t[105]!==ne||t[106]!==ve||t[107]!==A||t[108]!==W||t[109]!==pe||t[110]!==n||t[111]!==h||t[112]!==v||t[113]!==M||t[114]!==Be||t[115]!==pt||t[116]!==Rt||t[117]!==at||t[118]!==Ge||t[119]!==r||t[120]!==y||t[121]!==f||t[122]!==e){const Xe=Be.map(f0),Ke=Ge.map(h0),Ye=at.map(p0),gt=pe?pt.map(g0):[],Mt=pe?Rt.map(x0):[];let xt;e:{if(!pe){xt=["commands","sessions"];break e}const it=b0,He=[{key:"commands",score:it(Be)},{key:"settings",score:it(Ge)},{key:"sessions",score:it(at)},{key:"files",score:it(pt)},{key:"projects",score:it(Rt)}];He.sort(y0),xt=He.map(w0)}const St=xt,Tt=it=>{ve(),y(it.id,Fs(it))},Jt=async it=>{if(!A)return;const He=await nm(W,it,{directory:A});if(!He.ok){Fe.error(rm(He.reason));return}h(A,it),ve()},Gt=(it,He)=>{ve(),v({selectedProjectId:it,directoryOverride:He})},$t=it=>Jn(Zr(it,f));H=Ds,et=n,Ue=r;let Kt;t[137]!==e?(Kt=e("commandPalette.title"),t[137]=e,t[138]=Kt):Kt=t[138];let Ht;t[139]!==Kt?(Ht=s.jsx(_s,{children:Kt}),t[139]=Kt,t[140]=Ht):Ht=t[140];let Qt;t[141]!==e?(Qt=e("commandPalette.description"),t[141]=e,t[142]=Qt):Qt=t[142];let Le;t[143]!==Qt?(Le=s.jsx(Ls,{children:Qt}),t[143]=Qt,t[144]=Le):Le=t[144],t[145]!==Ht||t[146]!==Le?(jt=s.jsxs(Xs,{className:"sr-only",children:[Ht,Le]}),t[145]=Ht,t[146]=Le,t[147]=jt):jt=t[147],lt=Is,st="overflow-hidden p-0",Ze=!0,We=jp,ge=!1,Ee="[&_[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 qe;t[148]!==e?(qe=e("commandPalette.input.placeholder"),t[148]=e,t[149]=qe):qe=t[149],t[150]!==M||t[151]!==qe?($e=s.jsx(kp,{value:M,onValueChange:G,placeholder:qe}),t[150]=M,t[151]=qe,t[152]=$e):$e=t[152],de=Cp;let ot;t[153]!==e?(ot=e("commandPalette.empty.noResults"),t[153]=e,t[154]=ot):ot=t[154],t[155]!==ot?(V=s.jsx(Np,{children:ot}),t[155]=ot,t[156]=V):V=t[156],J=St.map(it=>it==="commands"&&Xe.length>0?s.jsx(Nr,{children:Xe.map(He=>s.jsxs(_r,{value:He.id,onSelect:He.onSelect,children:[He.icon,s.jsx("span",{children:He.title}),He.shortcutId?s.jsx(yp,{children:$t(He.shortcutId)}):null]},He.id))},"commands"):it==="settings"&&Ke.length>0?s.jsx(Nr,{children:Ke.map(S0)},"settings"):it==="sessions"&&Ye.length>0?s.jsx(Nr,{children:Ye.map(He=>{const Bt=He.title||e("commandPalette.session.untitled"),ts=Fs(He),es=ne(He.id,ts);return s.jsxs(_r,{value:`session:${He.id}`,onSelect:()=>Tt(He),children:[s.jsx(B,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Bt}),es?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(B,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:es})]}):null]},He.id)})},"sessions"):it==="files"&>.length>0?s.jsx(Nr,{children:gt.map(He=>{const Bt=wp(He.relativePath||He.name,{maxLength:80});return s.jsxs(_r,{value:`file:${He.path}`,onSelect:()=>{Jt(He.path)},children:[s.jsx(Aa,{filePath:He.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":He.relativePath,children:Bt})]},`file:${He.path}`)})},"files"):it==="projects"&&Mt.length>0?s.jsx(Nr,{children:Mt.map(He=>{const Bt=He.displayName;return s.jsxs(_r,{value:`project:${He.id}`,onSelect:()=>Gt(He.id,He.path),children:[s.jsx(B,{name:"folder",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Bt}),s.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:He.path})]},`project:${He.id}`)})},"projects"):null),t[105]=ne,t[106]=ve,t[107]=A,t[108]=W,t[109]=pe,t[110]=n,t[111]=h,t[112]=v,t[113]=M,t[114]=Be,t[115]=pt,t[116]=Rt,t[117]=at,t[118]=Ge,t[119]=r,t[120]=y,t[121]=f,t[122]=e,t[123]=de,t[124]=We,t[125]=lt,t[126]=H,t[127]=V,t[128]=J,t[129]=ge,t[130]=Ee,t[131]=$e,t[132]=st,t[133]=Ze,t[134]=et,t[135]=Ue,t[136]=jt}else de=t[123],We=t[124],lt=t[125],H=t[126],V=t[127],J=t[128],ge=t[129],Ee=t[130],$e=t[131],st=t[132],Ze=t[133],et=t[134],Ue=t[135],jt=t[136];let ze;t[157]!==It||t[158]!==e?(ze=It?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[157]=It,t[158]=e,t[159]=ze):ze=t[159];let xe;t[160]!==de||t[161]!==V||t[162]!==J||t[163]!==ze?(xe=s.jsxs(de,{children:[V,J,ze]}),t[160]=de,t[161]=V,t[162]=J,t[163]=ze,t[164]=xe):xe=t[164];let bt;t[165]!==We||t[166]!==ge||t[167]!==Ee||t[168]!==$e||t[169]!==xe?(bt=s.jsxs(We,{shouldFilter:ge,className:Ee,children:[$e,xe]}),t[165]=We,t[166]=ge,t[167]=Ee,t[168]=$e,t[169]=xe,t[170]=bt):bt=t[170];let ht;t[171]!==lt||t[172]!==st||t[173]!==Ze||t[174]!==bt?(ht=s.jsx(lt,{className:st,showCloseButton:Ze,children:bt}),t[171]=lt,t[172]=st,t[173]=Ze,t[174]=bt,t[175]=ht):ht=t[175];let kt;return t[176]!==H||t[177]!==et||t[178]!==Ue||t[179]!==jt||t[180]!==ht?(kt=s.jsxs(H,{open:et,onOpenChange:Ue,children:[jt,ht]}),t[176]=H,t[177]=et,t[178]=Ue,t[179]=jt,t[180]=ht,t[181]=kt):kt=t[181],kt};function Av(t){return t.isCommandPaletteOpen}function Pv(t){return t.setCommandPaletteOpen}function Dv(t){return t.setSettingsDialogOpen}function Iv(t){return t.setSettingsPage}function Tv(t){return t.setSessionSwitcherOpen}function Ev(t){return t.toggleSidebar}function Rv(t){return t.openContextOverview}function Mv(t){return t.openContextSurface}function Ov(t){return t.openContextFile}function Bv(t){return t.shortcutOverrides}function Fv(t){return t.openMultiRunLauncher}function _v(t){return t.setArchivePageOpen}function Lv(t){return t.setProjectContextTab}function $v(t){return t.openNewSessionDraft}function Wv(t){return t.setCurrentSession}function zv(t){return t.currentSessionId}function Vv(t){return t.toggle}function Uv(t){return t.currentDirectory}function Kv(t){return t.getActiveProject()}function Hv(t){return t.projects}function Gv(t){return t.searchFiles}function qv(t){return t.ensureStatus}function Qv(){mu()}function Yv(){bn.requestDirectoryDialog()}function Xv(){Ap.invoke("cycle_theme")}function Jv(){fu()}function Zv(){window.dispatchEvent(new CustomEvent("openchamber:memory-debug-toggle"))}function e0(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function t0(t){return t.slug!=="home"}function s0(t){return!Sp(t)}function n0(t){return t.worktreeMetadata}function r0(t){return{path:aa(t.path),name:t.name,relativePath:t.relativePath}}function o0(t){return!t.secondary}function i0(t){return{item:t,score:0}}function a0(t){return t.searchText}function l0(t){return t.searchText}function c0(t){return{item:t,score:0}}function d0(t){return t.title||""}function u0(t){return{...t,displayName:t.label||t.path.split("/").pop()||t.path,searchText:`${t.label||""} ${t.path}`}}function m0(t){return t.searchText}function f0(t){return t.item}function h0(t){return t.item}function p0(t){return t.item}function g0(t){return t.item}function x0(t){return t.item}function b0(t){return t.length?t[0].score:1/0}function y0(t,e){return t.score-e.score}function w0(t){return t.key}function S0(t){return s.jsxs(_r,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Sc=(t,e,n)=>Jn(Zr(t,e),n),v0=()=>{const t=nt.c(74),{t:e}=vt(),n=Ne(j0),r=Ne(k0),i=Ne(C0);let o;t[0]===Symbol.for("react.memo_cache_sentinel")?(o=$n(),t[0]=o):o=t[0];const l=o;let a,u,d,h,f,p,g,w,v,y,m,x;if(t[1]!==n||t[2]!==r||t[3]!==i||t[4]!==e){const j=[{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:[Jn("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:[`${Jn(Bi("switch_context_surface",i))} + 1...0`],descriptionKey:"helpDialog.item.switchContextSurface",icon:"layout-right"},{keys:[`${Jn(Bi("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:""}]}];d=Ds,m=n,x=r,u=Is,v="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let A;t[17]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(B,{name:"command",className:"h-5 w-5"}),t[17]=A):A=t[17];let M;t[18]!==e?(M=e("helpDialog.title"),t[18]=e,t[19]=M):M=t[19];let G;t[20]!==M?(G=s.jsxs(_s,{className:"flex items-center gap-2",children:[A,M]}),t[20]=M,t[21]=G):G=t[21];let q;t[22]!==e?(q=e("helpDialog.description"),t[22]=e,t[23]=q):q=t[23];let Z;t[24]!==q?(Z=s.jsx(Ls,{children:q}),t[24]=q,t[25]=Z):Z=t[25],t[26]!==G||t[27]!==Z?(y=s.jsxs(Xs,{children:[G,Z]}),t[26]=G,t[27]=Z,t[28]=y):y=t[28],a=Sn,p="flex-1 min-h-0 mt-3",g="pr-1",w=!0,h="space-y-4",f=j.map(le=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(le.categoryKey)}),s.jsx("div",{className:"space-y-1",children:le.items.filter(X=>!(l&&X.id==="toggle_prompt_navigator")).map(X=>{const te=X.id?Pp(X.id):void 0,re=X.descriptionKey??(te?.customizable?te.settingsLabelKey:void 0);if(!re||X.id&&!Zr(X.id,i))return null;const Se=X.id?Sc(X.id,i,e("settings.openchamber.keyboardShortcuts.unassigned")):Array.isArray(X.keys)?X.keys:X.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:[X.icon&&s.jsx(B,{name:X.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(re)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(Se)?Se:[Se]).map((ue,ye)=>s.jsxs(c.Fragment,{children:[ye>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:ue})]},`${ue}-${ye}`))})]},X.id||re)})})]},le.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,t[14]=y,t[15]=m,t[16]=x}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],y=t[14],m=t[15],x=t[16];let b;t[29]!==h||t[30]!==f?(b=s.jsx("div",{className:h,children:f}),t[29]=h,t[30]=f,t[31]=b):b=t[31];let S;t[32]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(B,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[32]=S):S=t[32];let C;t[33]!==e?(C=e("helpDialog.proTips.title"),t[33]=e,t[34]=C):C=t[34];let N;t[35]!==C?(N=s.jsx("p",{className:"font-medium mb-1",children:C}),t[35]=C,t[36]=N):N=t[36];let k;t[37]!==i||t[38]!==e?(k=e("helpDialog.proTips.commandPalette",{shortcut:Sc("open_command_palette",i,e("settings.openchamber.keyboardShortcuts.unassigned"))}),t[37]=i,t[38]=e,t[39]=k):k=t[39];let R;t[40]!==k?(R=s.jsxs("li",{children:["• ",k]}),t[40]=k,t[41]=R):R=t[41];let I;t[42]!==e?(I=e("helpDialog.proTips.recentSessions"),t[42]=e,t[43]=I):I=t[43];let P;t[44]!==I?(P=s.jsxs("li",{children:["• ",I]}),t[44]=I,t[45]=P):P=t[45];let T;t[46]!==e?(T=e("helpDialog.proTips.leaderSequences"),t[46]=e,t[47]=T):T=t[47];let E;t[48]!==T?(E=s.jsxs("li",{children:["• ",T]}),t[48]=T,t[49]=E):E=t[49];let O;t[50]!==R||t[51]!==P||t[52]!==E?(O=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[R,P,E]}),t[50]=R,t[51]=P,t[52]=E,t[53]=O):O=t[53];let W;t[54]!==N||t[55]!==O?(W=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[S,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[N,O]})]})}),t[54]=N,t[55]=O,t[56]=W):W=t[56];let L;t[57]!==a||t[58]!==b||t[59]!==W||t[60]!==p||t[61]!==g||t[62]!==w?(L=s.jsxs(a,{outerClassName:p,className:g,disableHorizontal:w,children:[b,W]}),t[57]=a,t[58]=b,t[59]=W,t[60]=p,t[61]=g,t[62]=w,t[63]=L):L=t[63];let F;t[64]!==u||t[65]!==L||t[66]!==v||t[67]!==y?(F=s.jsxs(u,{className:v,children:[y,L]}),t[64]=u,t[65]=L,t[66]=v,t[67]=y,t[68]=F):F=t[68];let D;return t[69]!==d||t[70]!==F||t[71]!==m||t[72]!==x?(D=s.jsx(d,{open:m,onOpenChange:x,children:F}),t[69]=d,t[70]=F,t[71]=m,t[72]=x,t[73]=D):D=t[73],D};function j0(t){return t.isHelpDialogOpen}function k0(t){return t.setHelpDialogOpen}function C0(t){return t.shortcutOverrides}const N0=()=>{const t=nt.c(32),{t:e}=vt(),n=Ne(A0),r=Ne(P0),i=Ne(D0);let o;t[0]!==i||t[1]!==e?(o=async()=>{if(!i)return;if((await xn(i)).ok){Fe.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}Fe.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(_s,{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(Ls,{children:d}),t[9]=d,t[10]=h):h=t[10];let f;t[11]!==u||t[12]!==h?(f=s.jsxs(Xs,{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-ring",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 y;t[24]!==f||t[25]!==g||t[26]!==v?(y=s.jsxs(Is,{className:"max-w-2xl",children:[f,g,v]}),t[24]=f,t[25]=g,t[26]=v,t[27]=y):y=t[27];let m;return t[28]!==n||t[29]!==r||t[30]!==y?(m=s.jsx(Ds,{open:n,onOpenChange:r,children:y}),t[28]=n,t[29]=r,t[30]=y,t[31]=m):m=t[31],m};function A0(t){return t.isOpenCodeStatusDialogOpen}function P0(t){return t.setOpenCodeStatusDialogOpen}function D0(t){return t.openCodeStatusText}const I0=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)},T0=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(E0)),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 E0(t){return[t.id,t]}const ho="oc.sessions.projectCollapse",vc="oc.sessions.groupOrder",jc="oc.sessions.groupCollapse",kc=t=>{if(!t)return new Set;try{const e=_a(Sr()).safeParse(JSON.parse(t));return new Set(e.success?e.data:[])}catch{return new Set}},R0=t=>{if(!t)return new Map;try{const e=Wu(Sr(),_a(Sr())).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}},M0=t=>{const e=nt.c(39),{isVSCode:n,projects:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=Io(),e[0]=i):i=e[0];const o=i;let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=()=>kc(o.getItem(ho)),e[1]=l):l=e[1];const[a,u]=c.useState(l);let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=()=>kc(o.getItem(jc)),e[2]=d):d=e[2];const[h,f]=c.useState(d);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=()=>R0(o.getItem(vc)),e[3]=p):p=e[3];const[g,w]=c.useState(p),v=c.useRef(0),y=c.useRef(!1),m=c.useRef(!1),x=c.useRef(null),b=c.useRef(null);let S;e[4]!==n?(S=()=>{if(n)return;const ye=b.current;if(b.current=null,x.current=null,!ye)return;const{projects:ve}=qt.getState(),be=ve.map(_=>({..._,sidebarCollapsed:ye.has(_.id)}));Or({projects:be}).catch(O0)},e[4]=n,e[5]=S):S=e[5];const C=S;let N;e[6]!==C||e[7]!==n?(N=ye=>{!globalThis.window||n||(b.current=ye,x.current!==null&&window.clearTimeout(x.current),x.current=window.setTimeout(()=>{C()},700))},e[6]=C,e[7]=n,e[8]=N):N=e[8];const k=N;let R,I;e[9]===Symbol.for("react.memo_cache_sentinel")?(R=()=>()=>{globalThis.window&&x.current!==null&&window.clearTimeout(x.current),x.current=null,b.current=null},I=[],e[9]=R,e[10]=I):(R=e[9],I=e[10]),c.useEffect(R,I);let P,T;e[11]!==g?(T=()=>{if(m.current)try{o.setItem(vc,JSON.stringify(Object.fromEntries(g.entries())))}catch{}},P=[g,o],e[11]=g,e[12]=P,e[13]=T):(P=e[12],T=e[13]),c.useEffect(T,P);let E,O;e[14]!==h?(E=()=>{if(y.current)try{o.setItem(jc,JSON.stringify(Array.from(h)))}catch{}},O=[h,o],e[14]=h,e[15]=E,e[16]=O):(E=e[15],O=e[16]),c.useEffect(E,O);let W;e[17]!==r||e[18]!==k?(W=()=>{v.current=Date.now()+150,y.current=!0,f(new Set),u(()=>{const ye=new Set(r.map(B0));try{o.setItem(ho,JSON.stringify(Array.from(ye)))}catch{}return k(ye),ye})},e[17]=r,e[18]=k,e[19]=W):W=e[19];const L=W;let F;e[20]!==k?(F=()=>{v.current=Date.now()+150,y.current=!0,f(new Set),u(()=>{const ye=new Set;try{o.setItem(ho,JSON.stringify([]))}catch{}return k(ye),ye})},e[20]=k,e[21]=F):F=e[21];const D=F;let j;e[22]!==k?(j=ye=>{v.current=Date.now()+150,u(ve=>{const be=new Set(ve);be.has(ye)?be.delete(ye):be.add(ye);try{o.setItem(ho,JSON.stringify(Array.from(be)))}catch{}return k(be),be})},e[22]=k,e[23]=j):j=e[23];const A=j;let M;e[24]===Symbol.for("react.memo_cache_sentinel")?(M=ye=>{y.current=!0,f(ve=>{const be=new Set(ve);return be.has(ye)?be.delete(ye):be.add(ye),be})},e[24]=M):M=e[24];const G=M;let q;e[25]===Symbol.for("react.memo_cache_sentinel")?(q=ye=>{m.current=!0,w(ye)},e[25]=q):q=e[25];const Z=q,{getOrderedGroups:le}=T0(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 te=X;let re;e[30]!==L||e[31]!==D||e[32]!==le||e[33]!==k||e[34]!==A?(re={setCollapsedProjects:u,toggleProject:A,collapseAllProjects:L,expandAllProjects:D,scheduleCollapsedProjectsPersist:k,setCollapsedGroups:f,toggleGroup:G,setGroupOrderByProject:Z,getOrderedGroups:le},e[30]=L,e[31]=D,e[32]=le,e[33]=k,e[34]=A,e[35]=re):re=e[35];const Se=re;let ue;return e[36]!==Se||e[37]!==te?(ue={state:te,actions:Se},e[36]=Se,e[37]=te,e[38]=ue):ue=e[38],ue};function O0(){}function B0(t){return t.id}const F0=5*6e4,_0=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}=jn(),d=In(L0);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(N=>{Fi(()=>d(N.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 N=new Map;n.forEach(k=>{N.set(k.id,i.get(k.normalizedPath)?.isGitRepo??null)}),o(N)},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 N;e[16]!==i?(N=k=>{const R=i.get(k.normalizedPath)?.branch??"";return`${k.id}:${R}`},e[16]=i,e[17]=N):N=e[17],w=n.map(N).join("|"),e[13]=i,e[14]=n,e[15]=w}else w=e[15];const v=w;let y;e[18]===Symbol.for("react.memo_cache_sentinel")?(y=new Map,e[18]=y):y=e[18];const m=c.useRef(y);let x;e[19]===Symbol.for("react.memo_cache_sentinel")?(x=new Map,e[19]=x):x=e[19];const b=c.useRef(x);let S;e[20]!==a||e[21]!==i||e[22]!==n||e[23]!==l?(S=()=>{if(!a)return;let N=!1;const k=setTimeout(()=>{(async()=>{const I=new Set(n.map($0));for(const L of m.current.keys())I.has(L)||(m.current.delete(L),b.current.delete(L));const P=Date.now(),T=n.filter(L=>{const F=i.get(L.normalizedPath);if(F?.isGitRepo===!1)return m.current.delete(L.id),b.current.delete(L.id),!1;if(F?.isGitRepo!==!0||F.branch===null)return!1;const D=F.branch.trim(),j=`${L.normalizedPath}\0${D}`,A=m.current.get(L.id);if(A===j){const M=b.current.get(L.id);return M&&(M.at=P),!1}return!(A!==void 0&&P-(b.current.get(L.id)?.at??0)<F0)});if(T.length===0)return;const E=await Dp(T,2,async L=>{const F=i.get(L.normalizedPath)?.branch?.trim()??"",D=`${L.normalizedPath}\0${F}`,j=await Fi(()=>Jo(L.normalizedPath,F?{knownBranch:F}:void 0)).catch(W0);return{id:L.id,inputKey:D,branch:j}});if(N)return;const O=E.filter(z0);if(O.length===0)return;const W=Date.now();l(L=>{const F=new Map(L);return O.forEach(D=>{const{id:j,branch:A}=D;A&&F.set(j,A)}),F}),O.forEach(L=>{const{id:F,inputKey:D,branch:j}=L;m.current.set(F,D),j&&b.current.set(F,{branch:j,at:W})})})()},150);return()=>{N=!0,clearTimeout(k)}},e[20]=a,e[21]=i,e[22]=n,e[23]=l,e[24]=S):S=e[24];let C;e[25]!==a||e[26]!==i||e[27]!==n||e[28]!==v||e[29]!==l?(C=[a,n,v,i,l],e[25]=a,e[26]=i,e[27]=n,e[28]=v,e[29]=l,e[30]=C):C=e[30],c.useEffect(S,C)};function L0(t){return t.ensureStatus}function $0(t){return t.id}function W0(){return null}function z0(t){return t.branch}const V0=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(ah,{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(Is,{className:"w-full max-w-2xl gap-0 overflow-hidden p-0",children:s.jsx(Sn,{outerClassName:"max-h-[min(90vh,48rem)]",className:"w-full bg-transparent",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(Ds,{open:n,onOpenChange:r,children:a}),e[6]=r,e[7]=n,e[8]=a,e[9]=u):u=e[9],u},U0=(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},ks=or()((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=U0(g,l),y=o!==null&&a.scopeKey!==null&&o!==a.scopeKey?new Set:new Set(a.selectedIds);for(const m of w)y.add(m);t({selectedIds:y,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 K0(t){const e=nt.c(218),{t:n}=vt(),r=hu(),{hideDirectoryControls:i,showProjectDisplayControls:o,showRecentControls:l,handleOpenDirectoryDialog:a,onOpenScheduled:u,onOpenMultiRun:d,canOpenMultiRun:h,onOpenArchive:f,headerActionIconClass:p,headerActionButtonClass:g,isSessionSearchOpen:w,setIsSessionSearchOpen:v,sessionSearchInputRef:y,sessionSearchQuery:m,setSessionSearchQuery:x,hasSessionSearchQuery:b,searchMatchCount:S,collapseAllProjects:C,expandAllProjects:N}=t,k=ks(oj),R=ks(rj),I=gs(nj),P=gs(sj),T=gs(tj),E=gs(ej),O=gs(Z0),W=gs(J0),L=gs(X0),F=gs(Y0),D=gs(Q0),j=gs(q0),A=o&&D==="single";if(i)return null;let M;e[0]!==g?(M=Ie(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[0]=g,e[1]=M):M=e[1];let G;e[2]!==n?(G=n("sessions.sidebar.header.actions.addProject"),e[2]=n,e[3]=G):G=e[3];let q;e[4]!==p?(q=s.jsx(B,{name:"folder-add",className:p}),e[4]=p,e[5]=q):q=e[5];let Z;e[6]!==a||e[7]!==M||e[8]!==G||e[9]!==q?(Z=s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:M,"aria-label":G,children:q})}),e[6]=a,e[7]=M,e[8]=G,e[9]=q,e[10]=Z):Z=e[10];let le;e[11]!==n?(le=n("sessions.sidebar.header.actions.addProject"),e[11]=n,e[12]=le):le=e[12];let X;e[13]!==le?(X=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:le})}),e[13]=le,e[14]=X):X=e[14];let te;e[15]!==Z||e[16]!==X?(te=s.jsxs(Ct,{children:[Z,X]}),e[15]=Z,e[16]=X,e[17]=te):te=e[17];let re;e[18]!==g?(re=Ie(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[18]=g,e[19]=re):re=e[19];let Se;e[20]!==n?(Se=n("sessions.sidebar.header.actions.scheduledTasks"),e[20]=n,e[21]=Se):Se=e[21];let ue;e[22]!==p?(ue=s.jsx(B,{name:"calendar-schedule",className:p}),e[22]=p,e[23]=ue):ue=e[23];let ye;e[24]!==u||e[25]!==re||e[26]!==Se||e[27]!==ue?(ye=s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:re,"aria-label":Se,children:ue})}),e[24]=u,e[25]=re,e[26]=Se,e[27]=ue,e[28]=ye):ye=e[28];let ve;e[29]!==n?(ve=n("sessions.sidebar.header.actions.scheduledTasks"),e[29]=n,e[30]=ve):ve=e[30];let be;e[31]!==ve?(be=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ve})}),e[31]=ve,e[32]=be):be=e[32];let _;e[33]!==ye||e[34]!==be?(_=s.jsxs(Ct,{children:[ye,be]}),e[33]=ye,e[34]=be,e[35]=_):_=e[35];let oe;e[36]!==g?(oe=Ie(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[36]=g,e[37]=oe):oe=e[37];let ce;e[38]!==n?(ce=n("sessions.sidebar.header.actions.newMultiRun"),e[38]=n,e[39]=ce):ce=e[39];const Q=!h;let me;e[40]!==p?(me=s.jsx(Ep,{className:p}),e[40]=p,e[41]=me):me=e[41];let ke;e[42]!==d||e[43]!==oe||e[44]!==ce||e[45]!==Q||e[46]!==me?(ke=s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:d,className:oe,"aria-label":ce,disabled:Q,children:me})}),e[42]=d,e[43]=oe,e[44]=ce,e[45]=Q,e[46]=me,e[47]=ke):ke=e[47];let fe;e[48]!==n?(fe=n("sessions.sidebar.header.actions.newMultiRun"),e[48]=n,e[49]=fe):fe=e[49];let De;e[50]!==fe?(De=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:fe})}),e[50]=fe,e[51]=De):De=e[51];let je;e[52]!==ke||e[53]!==De?(je=s.jsxs(Ct,{children:[ke,De]}),e[52]=ke,e[53]=De,e[54]=je):je=e[54];let Y;e[55]!==g?(Y=Ie(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[55]=g,e[56]=Y):Y=e[56];let Re;e[57]!==n?(Re=n("sessions.sidebar.nav.archive"),e[57]=n,e[58]=Re):Re=e[58];let Ce;e[59]!==p?(Ce=s.jsx(B,{name:"archive",className:p}),e[59]=p,e[60]=Ce):Ce=e[60];let Me;e[61]!==f||e[62]!==Y||e[63]!==Re||e[64]!==Ce?(Me=s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:Y,"aria-label":Re,children:Ce})}),e[61]=f,e[62]=Y,e[63]=Re,e[64]=Ce,e[65]=Me):Me=e[65];let ae;e[66]!==n?(ae=n("sessions.sidebar.nav.archive"),e[66]=n,e[67]=ae):ae=e[67];let ee;e[68]!==ae?(ee=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ae})}),e[68]=ae,e[69]=ee):ee=e[69];let K;e[70]!==Me||e[71]!==ee?(K=s.jsxs(Ct,{children:[Me,ee]}),e[70]=Me,e[71]=ee,e[72]=K):K=e[72];let $;e[73]!==r||e[74]!==p||e[75]!==n?($=r.length>0&&s.jsxs(Ys,{children:[s.jsx(qs,{asChild:!0,children:s.jsx(dt,{variant:"ghost",size:"xs",className:"w-6 text-muted-foreground","aria-label":n("sessions.sidebar.header.actions.extensionPages"),children:s.jsx(B,{name:"apps",className:p})})}),s.jsxs(Qs,{align:"start",children:[s.jsx(Br,{children:n("sessions.sidebar.header.actions.extensionPages")}),r.map(G0)]})]}),e[73]=r,e[74]=p,e[75]=n,e[76]=$):$=e[76];let ne;e[77]!==_||e[78]!==je||e[79]!==K||e[80]!==$||e[81]!==te?(ne=s.jsxs("div",{className:"ml-[3px] flex items-center gap-1.5",children:[te,_,je,K,$]}),e[77]=_,e[78]=je,e[79]=K,e[80]=$,e[81]=te,e[82]=ne):ne=e[82];let U;e[83]!==v?(U=()=>v(H0),e[83]=v,e[84]=U):U=e[84];let we;e[85]!==g?(we=Ie(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[85]=g,e[86]=we):we=e[86];let he;e[87]!==n?(he=n("sessions.sidebar.header.actions.searchSessions"),e[87]=n,e[88]=he):he=e[88];let Te;e[89]!==p?(Te=s.jsx(B,{name:"search",className:p}),e[89]=p,e[90]=Te):Te=e[90];let Oe;e[91]!==w||e[92]!==U||e[93]!==we||e[94]!==he||e[95]!==Te?(Oe=s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:U,className:we,"aria-label":he,"aria-expanded":w,children:Te})}),e[91]=w,e[92]=U,e[93]=we,e[94]=he,e[95]=Te,e[96]=Oe):Oe=e[96];let _e;e[97]!==n?(_e=n("sessions.sidebar.header.actions.searchSessions"),e[97]=n,e[98]=_e):_e=e[98];let Ve;e[99]!==_e?(Ve=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:_e})}),e[99]=_e,e[100]=Ve):Ve=e[100];let z;e[101]!==Oe||e[102]!==Ve?(z=s.jsxs(Ct,{children:[Oe,Ve]}),e[101]=Oe,e[102]=Ve,e[103]=z):z=e[103];const pe=k&&"bg-interactive-hover text-primary";let Ae;e[104]!==g||e[105]!==pe?(Ae=Ie(g,"text-muted-foreground hover:text-foreground hover:bg-transparent",pe),e[104]=g,e[105]=pe,e[106]=Ae):Ae=e[106];let Be;e[107]!==k||e[108]!==n?(Be=n(k?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[107]=k,e[108]=n,e[109]=Be):Be=e[109];let rt;e[110]!==p?(rt=s.jsx(B,{name:"checkbox-multiple",className:p}),e[110]=p,e[111]=rt):rt=e[111];let Ge;e[112]!==k||e[113]!==Ae||e[114]!==Be||e[115]!==rt||e[116]!==R?(Ge=s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:R,className:Ae,"aria-label":Be,"aria-pressed":k,children:rt})}),e[112]=k,e[113]=Ae,e[114]=Be,e[115]=rt,e[116]=R,e[117]=Ge):Ge=e[117];let ut;e[118]!==k||e[119]!==n?(ut=n(k?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[118]=k,e[119]=n,e[120]=ut):ut=e[120];let at;e[121]!==ut?(at=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ut})}),e[121]=ut,e[122]=at):at=e[122];let wt;e[123]!==Ge||e[124]!==at?(wt=s.jsxs(Ct,{children:[Ge,at]}),e[123]=Ge,e[124]=at,e[125]=wt):wt=e[125];let pt;e[126]!==g?(pt=Ie(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[126]=g,e[127]=pt):pt=e[127];let It;e[128]!==n?(It=n("sessions.sidebar.header.displayMode.label"),e[128]=n,e[129]=It):It=e[129];let Pt;e[130]!==p?(Pt=s.jsx(B,{name:"equalizer-2",className:p}),e[130]=p,e[131]=Pt):Pt=e[131];let Rt;e[132]!==pt||e[133]!==It||e[134]!==Pt?(Rt=s.jsx(Nt,{asChild:!0,children:s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:pt,"aria-label":It,children:Pt})})}),e[132]=pt,e[133]=It,e[134]=Pt,e[135]=Rt):Rt=e[135];let de;e[136]!==n?(de=n("sessions.sidebar.header.displayMode.label"),e[136]=n,e[137]=de):de=e[137];let We;e[138]!==de?(We=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:de})}),e[138]=de,e[139]=We):We=e[139];let lt;e[140]!==Rt||e[141]!==We?(lt=s.jsxs(Ct,{children:[Rt,We]}),e[140]=Rt,e[141]=We,e[142]=lt):lt=e[142];let H;e[143]!==n?(H=n("sessions.sidebar.header.actions.sortProjects"),e[143]=n,e[144]=H):H=e[144];let V;e[145]!==H?(V=s.jsx(Br,{children:H}),e[145]=H,e[146]=V):V=e[146];let J;e[147]!==T||e[148]!==E||e[149]!==n?(J=[["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(xt=>{const[St,Tt]=xt;return s.jsxs(Ut,{onClick:()=>{E(St),Or({sidebarProjectSortOrder:St})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Tt)}),T===St?s.jsx(B,{name:"check",className:"h-4 w-4 text-primary"}):null]},St)}),e[147]=T,e[148]=E,e[149]=n,e[150]=J):J=e[150];let ge;e[151]===Symbol.for("react.memo_cache_sentinel")?(ge=s.jsx(zs,{}),e[151]=ge):ge=e[151];let Ee;e[152]!==D||e[153]!==j||e[154]!==o||e[155]!==n?(Ee=o?s.jsxs(s.Fragment,{children:[s.jsx(Br,{children:n("sessions.sidebar.header.projectDisplay.label")}),[["all","sessions.sidebar.header.projectDisplay.all"],["single","sessions.sidebar.header.projectDisplay.single"]].map(xt=>{const[St,Tt]=xt;return s.jsxs(Ut,{onClick:()=>{j(St),Or({sidebarProjectDisplayMode:St})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Tt)}),D===St?s.jsx(B,{name:"check",className:"h-4 w-4 text-primary"}):null]},St)}),s.jsx(zs,{})]}):null,e[152]=D,e[153]=j,e[154]=o,e[155]=n,e[156]=Ee):Ee=e[156];let $e;e[157]!==n?($e=n("sessions.sidebar.header.grouping.label"),e[157]=n,e[158]=$e):$e=e[158];let st;e[159]!==$e?(st=s.jsx(Br,{children:$e}),e[159]=$e,e[160]=st):st=e[160];let Ze;e[161]!==O||e[162]!==W||e[163]!==n?(Ze=[["by-worktree","sessions.sidebar.header.grouping.byWorktree"],["flat","sessions.sidebar.header.grouping.flat"]].map(xt=>{const[St,Tt]=xt;return s.jsxs(Ut,{onClick:()=>{W(St),Or({sidebarSessionGroupingMode:St})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Tt)}),O===St?s.jsx(B,{name:"check",className:"h-4 w-4 text-primary"}):null]},St)}),e[161]=O,e[162]=W,e[163]=n,e[164]=Ze):Ze=e[164];let et;e[165]===Symbol.for("react.memo_cache_sentinel")?(et=s.jsx(zs,{}),e[165]=et):et=e[165];let Ue;e[166]!==A||e[167]!==l||e[168]!==I||e[169]!==n||e[170]!==P?(Ue=l&&!A?s.jsxs(Ut,{onClick:()=>{P(),Or({sidebarShowRecentSection:!I})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),I?s.jsx(B,{name:"check",className:"h-4 w-4 text-primary"}):null]}):null,e[166]=A,e[167]=l,e[168]=I,e[169]=n,e[170]=P,e[171]=Ue):Ue=e[171];let jt;e[172]!==n?(jt=n("sessions.sidebar.header.displayMode.stickyHeaders"),e[172]=n,e[173]=jt):jt=e[173];let ze;e[174]!==jt?(ze=s.jsx("span",{children:jt}),e[174]=jt,e[175]=ze):ze=e[175];let xe;e[176]!==L?(xe=L?s.jsx(B,{name:"check",className:"h-4 w-4 text-primary"}):null,e[176]=L,e[177]=xe):xe=e[177];let bt;e[178]!==ze||e[179]!==xe||e[180]!==F?(bt=s.jsxs(Ut,{onClick:F,className:"flex items-center justify-between",children:[ze,xe]}),e[178]=ze,e[179]=xe,e[180]=F,e[181]=bt):bt=e[181];let ht;e[182]!==C||e[183]!==N||e[184]!==A||e[185]!==n?(ht=A?null:s.jsxs(s.Fragment,{children:[s.jsx(zs,{}),s.jsxs(Ut,{onClick:C,className:"flex items-center gap-2",children:[s.jsx(B,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs(Ut,{onClick:N,className:"flex items-center gap-2",children:[s.jsx(B,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]}),e[182]=C,e[183]=N,e[184]=A,e[185]=n,e[186]=ht):ht=e[186];let kt;e[187]!==V||e[188]!==J||e[189]!==Ee||e[190]!==st||e[191]!==Ze||e[192]!==Ue||e[193]!==bt||e[194]!==ht?(kt=s.jsxs(Qs,{align:"end",className:"min-w-[180px]",children:[V,J,ge,Ee,st,Ze,et,Ue,bt,ht]}),e[187]=V,e[188]=J,e[189]=Ee,e[190]=st,e[191]=Ze,e[192]=Ue,e[193]=bt,e[194]=ht,e[195]=kt):kt=e[195];let Xe;e[196]!==lt||e[197]!==kt?(Xe=s.jsxs(Ys,{children:[lt,kt]}),e[196]=lt,e[197]=kt,e[198]=Xe):Xe=e[198];let Ke;e[199]!==z||e[200]!==wt||e[201]!==Xe?(Ke=s.jsxs("div",{className:"flex items-center gap-1.5",children:[z,wt,Xe]}),e[199]=z,e[200]=wt,e[201]=Xe,e[202]=Ke):Ke=e[202];let Ye;e[203]!==ne||e[204]!==Ke?(Ye=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[ne,Ke]}),e[203]=ne,e[204]=Ke,e[205]=Ye):Ye=e[205];let gt;e[206]!==b||e[207]!==w||e[208]!==S||e[209]!==y||e[210]!==m||e[211]!==v||e[212]!==x||e[213]!==n?(gt=w?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:S===1?n("sessions.sidebar.header.search.matchCountSingle",{count:S}):n("sessions.sidebar.header.search.matchCountPlural",{count:S})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsx(Ed,{inputRef:y,value:m,onSearch:x,onClose:()=>v(!1),placeholder:n("sessions.sidebar.header.search.placeholder"),clearLabel:n("sessions.sidebar.header.search.clear")})]}):null,e[206]=b,e[207]=w,e[208]=S,e[209]=y,e[210]=m,e[211]=v,e[212]=x,e[213]=n,e[214]=gt):gt=e[214];let Mt;return e[215]!==Ye||e[216]!==gt?(Mt=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:[Ye,gt]})}),e[215]=Ye,e[216]=gt,e[217]=Mt):Mt=e[217],Mt}function H0(t){return!t}function G0(t){return s.jsxs(Ut,{onSelect:()=>Ne.getState().setOpenGuestPage(t.id),children:[s.jsx(Jr,{icon:Tp(t.icon),iconSrc:Ip(t.id,t.icon,ya().authenticatedAsset),className:"size-4"}),s.jsx("span",{children:t.pageTitle??t.name})]},t.id)}function q0(t){return t.setProjectDisplayMode}function Q0(t){return t.projectDisplayMode}function Y0(t){return t.toggleStickyZoneHeaders}function X0(t){return t.stickyZoneHeaders}function J0(t){return t.setSessionGroupingMode}function Z0(t){return t.sessionGroupingMode}function ej(t){return t.setProjectSortOrder}function tj(t){return t.projectSortOrder}function sj(t){return t.toggleRecentSection}function nj(t){return t.showRecentSection}function rj(t){return t.toggleMode}function oj(t){return t.enabled}function ij(t){const e=nt.c(8),{t:n}=vt(),r=t.onNewSession;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(B,{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-ring",children:[i,l]})}),e[5]=t.onNewSession,e[6]=l,e[7]=a):a=e[7],a}const xi="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-ring";function aj(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}=vt();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(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:xi,"aria-label":h("sessions.sidebar.footer.actions.settings"),children:s.jsx(B,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:xi,"aria-label":h("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(B,{name:"command",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:xi,"aria-label":h("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(B,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=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(dt,{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 lj=t=>{for(const e of t.sessions.values())if(e.tabs.some(Cd))return!0;return!1},cj=()=>{const t=nt.c(4),{terminal:e}=jn(),n=Ot(lj);let r,i;return t[0]!==n||t[1]!==e?(r=()=>{const o=dj,l=uj;if(n)return Ai(e,"",l,o);let a=mj;return a=Ai(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 dj(t){const e=Ot.getState(),n=lh(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 uj(){return new Map(Ot.getState().actionMutationRevisions)}function mj(){}const fj=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 y=pu(v.normalizedPath),m=i.archivedSessionsByProject.get(v.id)??[],x=d[y]??[],b=new Map(x.map(hj));m.forEach(S=>{const C=Rp(S,v.normalizedPath),N=C.toLowerCase();let k=b.get(N);k||(k=h(y,C),b.set(N,k)),k.sessionIds.includes(S.id)||f(y,k.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 hj(t){return[t.name.toLowerCase(),t]}function pj({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 gj=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 N=(k,R,I,P)=>{w.has(k)||w.set(k,new Map);const T=w.get(k);P.forEach(E=>{const O=ft(E.worktree?.path??E.session.directory??I??R);T.set(E.session.id,{directory:O}),g.has(k)||g.set(k,{id:E.session.id,directory:O}),E.children.length>0&&N(k,R,O,E.children)})};n.forEach(k=>{k.groups.forEach(R=>{N(k.project.id,k.project.normalizedPath,R.directory,R.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 y=v,m=c.useRef(null);let x,b;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]!==y||e[16]!==o||e[17]!==p?(x=()=>{if(!r||d||Ne.getState().isNewWorktreeDialogOpen||m.current===r)return;const N=n.find(P=>P.project.id===r);if(!N)return;const k=y.metaByProject.get(r);if(l&&k&&k.has(l)){m.current=r,o(P=>{if(P.get(r)===l)return P;const T=new Map(P);return T.set(r,l),T});return}const R=pj({activeProjectId:r,currentSessionId:l,currentSessionOwnerProjectId:a,projectMap:k,metaByProject:y.metaByProject,rememberedSessionId:i.get(r),fallbackSessionId:y.firstSessionByProject.get(r)?.id??null});if(R.kind==="preserve-current"){a===r&&(m.current=r);return}if(m.current=r,R.kind==="open-draft"){h&&p(!1),f({selectedProjectId:N.project.id,directoryOverride:N.project.normalizedPath});return}if(R.kind!=="select-session")return;const I=k?.get(R.sessionId)?.directory??null;u(R.sessionId,I)},b=[r,i,l,a,u,d,h,f,n,y,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]=y,e[16]=o,e[17]=p,e[18]=x,e[19]=b):(x=e[18],b=e[19]),c.useLayoutEffect(x,b);let S,C;e[20]!==r||e[21]!==l||e[22]!==y||e[23]!==o?(S=()=>{if(!r||!l)return;const N=y.metaByProject.get(r);!N||!N.has(l)||o(k=>{if(k.get(r)===l)return k;const R=new Map(k);return R.set(r,l),R})},C=[r,l,y,o],e[20]=r,e[21]=l,e[22]=y,e[23]=o,e[24]=S,e[25]=C):(S=e[24],C=e[25]),c.useEffect(S,C)},xj=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=tt(bj),a=tt(yj);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],gj(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 bj(t){return t.currentSessionId}function yj(t){return!!t.newSessionDraft?.open}const Cc={selected:0,"active-project":1,expanded:2,visible:3,background:4};function Nm(t){const e=new Map,n=(r,i,o)=>{const l=ft(r??null);if(!l)return;const a=e.get(l);a&&Cc[a.priority]<=Cc[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 wj=(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,Nc=(t,e,n)=>{wj(t.get(e),n)&&t.set(e,n)},Sj=t=>{const e=t;return ft(e.directory)??ft(e.project?.worktree)},vj=(t,e,n,r,i=[])=>{const o=new Map,l=new Map;for(const w of e){const v=ft(w.normalizedPath);if(!v)continue;const y=l.get(v);(!y||w.id.localeCompare(y.id)<0)&&l.set(v,w),Nc(o,v,{projectId:w.id,projectRoot:v,scopeDirectory:v,kind:"project"})}if(!r)for(const[w,v]of n){const y=ft(w),m=y?l.get(y):void 0;if(!(!m||!y))for(const x of v){const b=ft(x.path);b&&Nc(o,b,{projectId:m.id,projectRoot:y,scopeDirectory:b,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 x=o.get(w)??null;return a.set(w,x),x}const v=[];let y=w,m=null;for(;y;){if(a.has(y)){m=a.get(y)??null;break}if(v.push(y),m=o.get(y)??null,m)break;y=Df(y)}for(const x of v)a.set(x,m);return m},g=(w,v,y)=>{for(const m of w){const x=p(Sj(m));if(!x)continue;u.set(m.id,x);const b=v.get(x.projectId);if(b?b.push(m):v.set(x.projectId,[m]),!y)continue;const S=y.get(x.scopeDirectory);S?S.add(m.id):y.set(x.scopeDirectory,new Set([m.id]))}};return g(t,d,f),g(i,h),{bySessionId:u,sessionsByProject:d,archivedSessionsByProject:h,sessionsByScope:f,directoryResolutions:a.size}},jj=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},kj=(t,e)=>t.map(n=>{const r=ft(n.path)??n.path;return`${r}=${e.get(r)??""}`}).join(`
|
|
879
|
+
`),Cj=[],Nj=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,y=c.useRef(new Map),m=c.useMemo(()=>{const I=y.current,P=new Map;let T=0,E=0;const O=(L,F)=>L.length===F.length&&L.every((D,j)=>D===F[j]),W=e.map(L=>{const F=n(L.id),D=r(L.id),j=i.get(L.normalizedPath)??Cj,A=o.has(L.id)?!!o.get(L.id):u,M=l.get(L.id)??null,G=kj(j,a),q=I.get(L.id);if(q&&q.project===L&&O(q.activeSessions,F)&&O(q.archivedSessions,D)&&q.availableWorktrees===j&&q.rootBranch===M&&q.worktreeBranchesKey===G&&q.isRepo===A&&q.buildGroupedSessions===d)return T+=1,P.set(L.id,q),q.section;if(E+=1,q){const te=q.project!==L?"project":O(q.activeSessions,F)?O(q.archivedSessions,D)?q.availableWorktrees!==j?"worktrees":q.rootBranch!==M?"branch":q.worktreeBranchesKey!==G?"worktreeBranches":q.isRepo!==A?"repo":"builder":"archived":"sessions";sn(`ui.sidebar.project_section.rebuilt_reason.${te}`)}const Z=gu([...F,...D]),le=d(Z,L.normalizedPath,j,M,A),X={project:L,groups:le};return P.set(L.id,{project:L,activeSessions:F,archivedSessions:D,availableWorktrees:j,rootBranch:M,worktreeBranchesKey:G,isRepo:A,buildGroupedSessions:d,section:X}),X});return y.current=P,T>0&&sn("ui.sidebar.project_section.reused",T),E>0&&sn("ui.sidebar.project_section.rebuilt",E),W},[e,n,r,i,o,u,d,l,a]),x=c.useMemo(()=>m,[m]),b=c.useMemo(()=>{const I=new WeakMap;if(!h)return I;const P=f.trim().toLowerCase(),T=P.startsWith("ses_"),E=W=>W.reduce((L,F)=>L+(!T||F.session.id.toLowerCase()===P?1:0)+E(F.children),0),O=W=>{const L=p(W.sessions,f),F=E(L),D=!T&&To([g(W)],f),j=ft(W.directory??null),A=j?w[j]??[]:[],M=T?0:A.filter(G=>To([G.name],f)).length;I.set(W,{filteredNodes:L,matchedSessionCount:F,folderNameMatchCount:M,groupMatches:D,hasMatch:D||F>0||M>0})};return x.forEach(W=>{W.groups.forEach(O)}),v.forEach(O),I},[h,x,v,p,f,g,w]),S=c.useMemo(()=>h?x.map(I=>({...I,groups:I.groups.filter(P=>b.get(P)?.hasMatch===!0)})).filter(I=>I.groups.length>0):x,[h,x,b]),C=h?S:x,N=c.useRef(new WeakMap),k=c.useMemo(()=>{const I=N.current;return C.map(P=>{const T=I.get(P);if(T&&T.query===f)return T.section;const E=P.groups.filter(A=>!A.isArchivedBucket),O=P.groups.filter(A=>A.isArchivedBucket),W=E.flatMap(A=>h?b.get(A)?.filteredNodes??[]:A.sessions),L=E.map(A=>({scopeKey:A.folderScopeKey??ft(A.directory??null),directory:A.directory??null})).filter(A=>!!A.scopeKey),F=E.find(A=>A.isMain)??null,D={id:"flat",label:F?.label??"",branch:F?.branch??null,description:F?.description??null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:F?.directory??P.project.normalizedPath,folderScopeKey:F?.folderScopeKey??P.project.normalizedPath,folderScopes:L,sessions:W};if(h){const A=E.map(M=>b.get(M)).filter(M=>!!M);b.set(D,{filteredNodes:W,matchedSessionCount:A.reduce((M,G)=>M+G.matchedSessionCount,0),folderNameMatchCount:A.reduce((M,G)=>M+G.folderNameMatchCount,0),groupMatches:A.some(M=>M.groupMatches),hasMatch:A.some(M=>M.hasMatch)})}const j={project:P.project,groups:[D,...O]};return I.set(P,{query:f,section:j}),j})},[b,h,f,C]),R=c.useMemo(()=>{if(!h)return 0;const I=(T,E)=>{const O=b.get(E);if(!O)return T;const W=O.folderNameMatchCount+(O.groupMatches?1:0);return T+O.matchedSessionCount+W},P=C.reduce((T,E)=>E.groups.reduce(I,T),0);return v.reduce(I,P)},[h,C,v,b]);return{projectSections:m,visibleProjectSections:x,groupSearchDataByGroup:b,searchableProjectSections:S,sectionsForRender:C,flatSectionsForRender:k,searchMatchCount:R}},Aj=180,Ac=150,Pj=2,Dj=8,Pc=[-1,1,-2,2],bi=t=>`${t.directory}
|
|
880
|
+
${t.sessionId}`,Ij=t=>t?.directory?.trim()||null,Tj=({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(()=>$n(),[]),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<Pj&&l.current.length>0;){const g=l.current.shift();if(!g)break;if(g.generation!==u.current||tt.getState().currentSessionId===g.sessionId||_i(g.sessionId,g.directory).renderable)continue;const v=bi(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=Ij(g);if(!t||d||!w||!v||w===e)return;const y={sessionId:w,directory:v,generation:u.current},m=bi(y);if(_i(w,v).renderable||a.current.has(m)||l.current.some(S=>bi(S)===m))return;const x=o.current.get(m);x!==void 0&&window.clearTimeout(x);const b=window.setTimeout(()=>{if(o.current.delete(m),y.generation!==u.current)return;const S=l.current;S.length>=Dj&&S.shift(),S.push(y),f()},Aj);o.current.set(m,b)},[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 Pc)p(n[w+v])},Ac);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 Pc)p(r[w+v])},Ac);return()=>window.clearTimeout(g)},[e,t,d,r,p]),c.useEffect(()=>h,[h])},Ej=t=>{const e=nt.c(3),n=tt(Rj);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],Tj(r),null};function Rj(t){return t.currentSessionId}const Wo=t=>{const e=nt.c(13),{directory:n,className:r}=t,{t:i}=vt();let o;e[0]!==n?(o=If(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],!Ot(a)?.tabs.some(Cd))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(B,{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},Am=c.createContext(null);function Dc(t){let e=0,n=t;for(;n;){e+=n.offsetTop;const r=n.offsetParent;n=r instanceof HTMLElement?r:null}return e}function Mj(t){const e=nt.c(14),{enabled:n,suspended:r,layoutKey:i,scrollRef:o,children:l}=t,a=r===void 0?!1:r,u=i===void 0?"":i;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[0]=d):d=e[0];const h=c.useRef(d),f=c.useRef(null);let p;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=x=>(h.current.add(x),f.current?.(),()=>{h.current.delete(x),f.current?.()}),e[1]=p):p=e[1];const g=p;let w;e[2]!==n||e[3]!==o||e[4]!==a?(w=()=>{const x=o.current;if(!n||a||!x)return;const b=document.createElement("div");b.dataset.sidebarCrossfadeLayer="true",b.className="pointer-events-none sticky top-0 z-30 h-0",b.style.marginBlock="0px",x.prepend(b);let S=null,C=null,N=null,k=0;const R=new Set;let I=[];const P=window.matchMedia("(prefers-reduced-motion: reduce)"),T=Bj,E=()=>{N?.cancel(),N=null,C?.remove(),C=null},O=()=>{let D=null,j=-1/0;for(const{entry:A,top:M}of I)M<=x.scrollTop&&M>=j&&(j=M,D=A);if(S!==D){if(E(),S&&D&&!P.matches){const A=S.host.cloneNode(!0);A instanceof HTMLElement&&(A.inert=!0,A.setAttribute("aria-hidden","true"),A.querySelectorAll("[id]").forEach(Oj),A.className="pointer-events-none absolute inset-x-0 top-0 z-30",C=A)}S&&(T(S,S.slot),S.slot.style.removeProperty("height")),S=D,b.hidden=!D,D&&(D.slot.style.height=`${D.host.getBoundingClientRect().height}px`,T(D,b),C&&(b.append(C),N=C.animate([{opacity:1},{opacity:0}],{duration:150,easing:"ease-out"}),N.onfinish=E))}},W=()=>{S&&(S.slot.style.height=`${S.host.getBoundingClientRect().height}px`);const D=Dc(x)+x.clientTop;I=Array.from(h.current,j=>({entry:j,top:Dc(j.slot)-D})),O()},L=new ResizeObserver(W);L.observe(x);const F=()=>{for(const D of R)h.current.has(D)||(L.unobserve(D.host),D.slot.parentElement&&L.unobserve(D.slot.parentElement),R.delete(D));for(const D of h.current)R.has(D)||(L.observe(D.host),D.slot.parentElement&&L.observe(D.slot.parentElement),R.add(D));cancelAnimationFrame(k),k=requestAnimationFrame(W)};return f.current=F,x.addEventListener("scroll",O,{passive:!0}),F(),W(),()=>{f.current=null,cancelAnimationFrame(k),x.removeEventListener("scroll",O),L.disconnect(),E(),b.hidden=!0,S&&(T(S,S.slot),S.slot.style.removeProperty("height")),b.remove()}},e[2]=n,e[3]=o,e[4]=a,e[5]=w):w=e[5];let v;e[6]!==n||e[7]!==u||e[8]!==o||e[9]!==a?(v=[n,a,u,o],e[6]=n,e[7]=u,e[8]=o,e[9]=a,e[10]=v):v=e[10],c.useLayoutEffect(w,v);const y=n?g:null;let m;return e[11]!==l||e[12]!==y?(m=s.jsx(Am.Provider,{value:y,children:l}),e[11]=l,e[12]=y,e[13]=m):m=e[13],m}function Oj(t){return t.removeAttribute("id")}function Bj(t,e){const n=document.activeElement,r=n instanceof HTMLElement&&t.host.contains(n);e.moveBefore&&e.isConnected&&t.host.isConnected?e.moveBefore(t.host,null):e.append(t.host),r&&n.focus({preventScroll:!0})}function Fj(t){const e=nt.c(15);let n,r;e[0]!==t?({register:r,...n}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);const i=c.useRef(null),[o]=c.useState(_j);let l,a;e[3]!==o||e[4]!==r?(l=()=>{const p=i.current;if(!p)return;p.append(o);const g=r({slot:p,host:o});return()=>{g(),o.remove()}},a=[o,r],e[3]=o,e[4]=r,e[5]=l,e[6]=a):(l=e[5],a=e[6]),c.useLayoutEffect(l,a);let u;e[7]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx("div",{ref:i}),e[7]=u):u=e[7];let d;e[8]!==n?(d=s.jsx("div",{...n}),e[8]=n,e[9]=d):d=e[9];let h;e[10]!==o||e[11]!==d?(h=df.createPortal(d,o),e[10]=o,e[11]=d,e[12]=h):h=e[12];let f;return e[13]!==h?(f=s.jsxs(s.Fragment,{children:[u,h]}),e[13]=h,e[14]=f):f=e[14],f}function _j(){const t=document.createElement("div");return t.className="pointer-events-auto flow-root",t}function Pm(t){const e=nt.c(3),n=c.useContext(Am);let r;return e[0]!==t||e[1]!==n?(r=n?s.jsx(Fj,{...t,register:n}):s.jsx("div",{...t}),e[0]=t,e[1]=n,e[2]=r):r=e[2],r}const yi=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}=nr(),p=i?Ia[i]:null,g=o?Ta[o]??null:null,w=u!==void 0,v=w?h?"hidden":"group-hover/project:hidden group-focus-within/project:hidden":void 0;let y;e[0]!==h||e[1]!==w||e[2]!==u?(y=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(B,{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]=y):y=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(Ea,{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(B,{name:p,className:"h-3.5 w-3.5",style:g?{color:g}:void 0}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:g?{color:g}:void 0})})}):p?s.jsx(B,{name:p,className:Ie("h-3.5 w-3.5",v),style:g?{color:g}:void 0}):s.jsx(B,{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 x;e[14]!==y||e[15]!==m?(x=s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[y,m]}),e[14]=y,e[15]=m,e[16]=x):x=e[16];let b;e[17]!==r?(b=s.jsx("span",{className:"truncate typography-ui-label font-semibold lowercase text-foreground",children:r}),e[17]=r,e[18]=b):b=e[18];let S;return e[19]!==x||e[20]!==b?(S=s.jsxs(s.Fragment,{children:[x,b]}),e[19]=x,e[20]=b,e[21]=S):S=e[21],S},Lj=t=>{const e=nt.c(61),{id:n,disabled:r,projectLabel:i,projectDescription:o,projectDirectory:l,projectIcon:a,projectColor:u,projectIconImage:d,projectIconBackground:h,isCollapsed:f,isRepo:p,hideDirectoryControls:g,alwaysShowActions:w,onToggle:v,onNewSession:y,onNewWorktreeSession:m,onManageWorktrees:x,onRenameStart:b,onClose:S,children:C,showCreateButtons:N,hideHeader:k,statusIndicator:R,openSidebarMenuKey:I,setOpenSidebarMenuKey:P,projectPickerOptions:T,onProjectSelect:E}=t,O=r===void 0?!1:r,W=N===void 0?!0:N,L=k===void 0?!1:k,F=R===void 0?null:R,{t:D}=vt(),j=gs(zj);let A;e[0]!==O||e[1]!==n?(A={id:n,disabled:O},e[0]=O,e[1]=n,e[2]=A):A=e[2];const{attributes:M,listeners:G,setNodeRef:q,transform:Z,transition:le,isDragging:X}=Zo(A),te=c.useRef(!1),re=`project:${n}`,Se=I===re,[ue,ye]=c.useState(!1),ve=!!(T&&E);let be;e[3]!==re||e[4]!==P?(be=$=>{$&&ye(!1),P($?re:null)},e[3]=re,e[4]=P,e[5]=be):be=e[5];const _=be;let oe;e[6]!==g||e[7]!==p||e[8]!==S||e[9]!==x||e[10]!==y||e[11]!==b||e[12]!==W||e[13]!==D?(oe=$=>s.jsxs(s.Fragment,{children:[W&&!p&&!g&&y&&s.jsxs($,{onClick:y,children:[s.jsx(B,{name:"add",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.newSession")]}),p&&!g&&x&&s.jsxs($,{onClick:x,children:[s.jsx(B,{name:"node-tree",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.manageWorktrees")]}),s.jsxs($,{onClick:b,children:[s.jsx(B,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.edit")]}),s.jsxs($,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"close",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.closeProject")]})]}),e[6]=g,e[7]=p,e[8]=S,e[9]=x,e[10]=y,e[11]=b,e[12]=W,e[13]=D,e[14]=oe):oe=e[14];const ce=oe,Q=Vj,me=Uj,ke=Kj;let fe;e[15]===Symbol.for("react.memo_cache_sentinel")?(fe=$=>{($.button===2||$.button===0&&$.ctrlKey)&&(te.current=!0)},e[15]=fe):fe=e[15];const De=fe;let je;e[16]!==v?(je=$=>{if($.currentTarget.blur(),te.current){te.current=!1;return}v()},e[16]=v,e[17]=je):je=e[17];const Y=je;let Re;e[18]!==Z?(Re=ei.Transform.toString(Z),e[18]=Z,e[19]=Re):Re=e[19];let Ce;e[20]!==Re||e[21]!==le?(Ce={transform:Re,transition:le},e[20]=Re,e[21]=le,e[22]=Ce):Ce=e[22];const Me=X&&"opacity-30";let ae;e[23]!==Me?(ae=Ie("relative",Me),e[23]=Me,e[24]=ae):ae=e[24];let ee;e[25]!==w||e[26]!==M||e[27]!==_||e[28]!==Y||e[29]!==g||e[30]!==L||e[31]!==n||e[32]!==f||e[33]!==ue||e[34]!==Se||e[35]!==ve||e[36]!==p||e[37]!==G||e[38]!==y||e[39]!==m||e[40]!==E||e[41]!==u||e[42]!==o||e[43]!==l||e[44]!==a||e[45]!==h||e[46]!==d||e[47]!==i||e[48]!==T||e[49]!==ce||e[50]!==W||e[51]!==F||e[52]!==j||e[53]!==D?(ee=L?null:s.jsx(s.Fragment,{children:s.jsxs(Td,{open:ue,onOpenChange:ye,children:[s.jsx(Id,{render:s.jsx(Pm,{className:Ie("-ml-2.5 -mr-2 text-left group/project select-none",j&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":j?"true":void 0,onContextMenu:$=>{g||($.preventDefault(),ye(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 py-1 pl-4 pr-3.5",...M,children:[ve?s.jsxs(Ys,{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-ring transition-[padding]",p&&!g?w||Se?"pr-20":"pr-0 group-hover/project:pr-20 group-focus-within/project:pr-20":w||Se?"pr-14":"pr-0 group-hover/project:pr-14 group-focus-within/project:pr-14"),"aria-label":D("sessions.sidebar.project.selectAria",{project:i}),children:[s.jsx(yi,{id:n,projectLabel:i,projectIcon:a,projectColor:u,projectIconImage:d,projectIconBackground:h}),s.jsx(B,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}),l?s.jsx(Wo,{directory:l,className:"ml-auto"}):null]})}),s.jsx(Qs,{align:"start",className:"max-h-[70vh] min-w-[220px] overflow-y-auto",children:T?.map($=>s.jsxs(Ut,{onClick:()=>E?.($.id),className:"flex items-center justify-between gap-3",title:$.projectDescription,children:[s.jsx("span",{className:"flex min-w-0 items-center gap-1.5",children:s.jsx(yi,{...$})}),$.id===n?s.jsx(B,{name:"check",className:"h-4 w-4 flex-shrink-0 text-primary"}):null]},$.id))})]}):s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:De,onClick:Y,...G,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-ring rounded-md cursor-grab active:cursor-grabbing transition-[padding]",p&&!g?w||Se?"pr-20":"pr-0 group-hover/project:pr-20 group-focus-within/project:pr-20":w||Se?"pr-14":"pr-0 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsx(yi,{id:n,projectLabel:i,projectIcon:a,projectColor:u,projectIconImage:d,projectIconBackground:h,isCollapsed:f,alwaysShowActions:w}),F?s.jsx("span",{className:"ml-1 inline-flex flex-shrink-0 items-center",children:F}):null,l?s.jsx(Wo,{directory:l,className:"ml-auto"}):null]})}),s.jsx(At,{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",W?"right-7":"right-0.5"),children:[W&&p&&!g&&m?s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:$=>{$.stopPropagation(),m()},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-ring hover:text-foreground transition-opacity",w?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":D("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(B,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,g?null:s.jsxs(Ys,{open:Se,onOpenChange:_,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-ring hover:text-foreground",Se?"opacity-100 pointer-events-auto":w?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":D("sessions.sidebar.project.actions.projectMenu"),onPointerDown:me,onMouseDown:ke,onClick:Q,children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Qs,{align:"end",className:"min-w-[180px]",children:ce(Ut)})]})]}),W&&y?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:$=>{$.stopPropagation(),y()},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-ring transition-opacity",w?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":D(p?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(B,{name:"add",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D(p?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx(Dd,{className:"min-w-[180px]",children:ce(Gn)})]})}),e[25]=w,e[26]=M,e[27]=_,e[28]=Y,e[29]=g,e[30]=L,e[31]=n,e[32]=f,e[33]=ue,e[34]=Se,e[35]=ve,e[36]=p,e[37]=G,e[38]=y,e[39]=m,e[40]=E,e[41]=u,e[42]=o,e[43]=l,e[44]=a,e[45]=h,e[46]=d,e[47]=i,e[48]=T,e[49]=ce,e[50]=W,e[51]=F,e[52]=j,e[53]=D,e[54]=ee):ee=e[54];let K;return e[55]!==C||e[56]!==q||e[57]!==Ce||e[58]!==ae||e[59]!==ee?(K=s.jsxs("div",{ref:q,style:Ce,className:ae,children:[ee,C]}),e[55]=C,e[56]=q,e[57]=Ce,e[58]=ae,e[59]=ee,e[60]=K):K=e[60],K},$j=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}=Zo(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=ei.Transform.toString(h),e[6]=h,e[7]=v):v=e[7];let y;e[8]!==v||e[9]!==f?(y={transform:v,transition:f},e[8]=v,e[9]=f,e[10]=y):y=e[10];const m=p&&"opacity-50";let x;e[11]!==m?(x=Ie("space-y-0.5 rounded-md",m),e[11]=m,e[12]=x):x=e[12];let b;e[13]!==i||e[14]!==w?(b=i(w),e[13]=i,e[14]=w,e[15]=b):b=e[15];let S;return e[16]!==u||e[17]!==y||e[18]!==x||e[19]!==b?(S=s.jsx("div",{ref:u,style:y,className:x,children:b}),e[16]=u,e[17]=y,e[18]=x,e[19]=b,e[20]=S):S=e[20],S},Wj=c.memo($j);function zj(t){return t.stickyZoneHeaders}function Vj(t){t.stopPropagation()}function Uj(t){t.stopPropagation()}function Kj(t){t.stopPropagation()}const Hj=(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}},Dm=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=Hj(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=Ra(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=Ma(h);return d??f};function Im(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 Gj=t=>{const e=nt.c(11),{nodes:n,includeUnreadSubtasks:r}=t,{t:i}=vt();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=Dm(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(Im,{state:l,activeLabel:a,unreadLabel:u}),e[7]=l,e[8]=a,e[9]=u,e[10]=d):d=e[10],d},qj=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:y,onRenameSave:m,onRenameCancel:x,droppableRef:b,isDropTarget:S,onNewSession:C,depth:N,hideActions:k,archivedBucket:R}=t,I=a===void 0?null:a,T=g===void 0?p===void 0?!1:p:g,E=w===void 0?!1:w,O=v===void 0?"":v,W=S===void 0?!1:S,L=k===void 0?!1:k,F=R===void 0?!1:R,{t:D}=vt(),[j,A]=c.useState(!1),[M,G]=c.useState(""),q=c.useRef(null),Z=E||j,le=E?O:M;let X;e[0]!==n.name?(X=()=>{G(n.name),A(!0)},e[0]=n.name,e[1]=X):X=e[1];const te=X;let re;e[2]!==le||e[3]!==n.name||e[4]!==E||e[5]!==d||e[6]!==m?(re=()=>{const Te=le.trim();Te&&Te!==n.name&&d(Te),E&&m&&m(),A(!1),G("")},e[2]=le,e[3]=n.name,e[4]=E,e[5]=d,e[6]=m,e[7]=re):re=e[7];const Se=re;let ue;e[8]!==E||e[9]!==x?(ue=()=>{E&&x&&x(),A(!1),G("")},e[8]=E,e[9]=x,e[10]=ue):ue=e[10];const ye=ue;let ve;e[11]!==E||e[12]!==y?(ve=Te=>{E&&y?y(Te):G(Te)},e[11]=E,e[12]=y,e[13]=ve):ve=e[13];const be=ve;let _,oe;e[14]!==E?(_=()=>{if(!E)return;const Te=()=>{const Ve=q.current;Ve&&(Ve.focus(),Ve.select())},Oe=requestAnimationFrame(Te),_e=window.setTimeout(Te,0);return()=>{cancelAnimationFrame(Oe),window.clearTimeout(_e)}},oe=[E],e[14]=E,e[15]=_,e[16]=oe):(_=e[15],oe=e[16]),c.useEffect(_,oe);const ce=l?"folder":"folder-open",Q=W&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let me;e[17]!==Q?(me=Ie("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",Q),e[17]=Q,e[18]=me):me=e[18];let ke;e[19]!==u||e[20]!==Z?(ke=Z?void 0:Te=>{Te.currentTarget.blur(),u()},e[19]=u,e[20]=Z,e[21]=ke):ke=e[21];const fe=Z?void 0:"button",De=Z?void 0:0;let je;e[22]!==u||e[23]!==Z?(je=Z?void 0:Te=>{(Te.key==="Enter"||Te.key===" ")&&(Te.preventDefault(),u())},e[22]=u,e[23]=Z,e[24]=je):je=e[24];let Y;e[25]!==n.name||e[26]!==l||e[27]!==D?(Y=l?D("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):D("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[25]=n.name,e[26]=l,e[27]=D,e[28]=Y):Y=e[28];const Re=F?T?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":T?"pr-20":"group-hover/folder:pr-20 group-focus-within/folder:pr-20";let Ce;e[29]!==Re?(Ce=Ie("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",Re),e[29]=Re,e[30]=Ce):Ce=e[30];const Me=W?"text-primary":"text-muted-foreground";let ae;e[31]!==Me?(ae=Ie("h-3.5 w-3.5 flex-shrink-0",Me),e[31]=Me,e[32]=ae):ae=e[32];let ee;e[33]!==ce||e[34]!==ae?(ee=s.jsx(B,{name:ce,className:ae}),e[33]=ce,e[34]=ae,e[35]=ee):ee=e[35];let K;e[36]!==I||e[37]!==r||e[38]!==le||e[39]!==n.name||e[40]!==ye||e[41]!==be||e[42]!==Se||e[43]!==l||e[44]!==W||e[45]!==Z||e[46]!==i||e[47]!==D?(K=Z?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:Yj,onMouseDown:Xj,onSubmit:Te=>{Te.preventDefault(),Se()},children:[s.jsx("input",{ref:q,value:le,onChange:Te=>be(Te.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:D("sessions.sidebar.folderItem.namePlaceholder"),onClick:Jj,onPointerDown:Zj,onMouseDown:e2,onKeyDown:Te=>{if(Te.key==="Escape"){Te.stopPropagation(),ye();return}(Te.key===" "||Te.key==="Enter")&&Te.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:t2,onPointerDown:s2,onMouseDown:n2,children:s.jsx(B,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:Te=>{Te.stopPropagation(),ye()},onPointerDown:r2,onMouseDown:o2,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(B,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("span",{className:Ie("typography-ui-label font-semibold truncate",W?"text-primary":"text-muted-foreground"),children:r??n.name})}),s.jsx(At,{side:"right",sideOffset:8,className:"max-w-xs",children:r??n.name})]}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",i.length]}),I?s.jsx(Im,{state:I,activeLabel:D("sessions.sidebar.session.status.active"),unreadLabel:D("sessions.sidebar.session.status.unread")}):null,l?s.jsx(B,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(B,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[36]=I,e[37]=r,e[38]=le,e[39]=n.name,e[40]=ye,e[41]=be,e[42]=Se,e[43]=l,e[44]=W,e[45]=Z,e[46]=i,e[47]=D,e[48]=K):K=e[48];let $;e[49]!==Ce||e[50]!==ee||e[51]!==K?($=s.jsxs("div",{className:Ce,children:[ee,K]}),e[49]=Ce,e[50]=ee,e[51]=K,e[52]=$):$=e[52];let ne;e[53]!==T||e[54]!==F||e[55]!==n.name||e[56]!==te||e[57]!==L||e[58]!==h||e[59]!==C||e[60]!==Z||e[61]!==D?(ne=!Z&&(!L||F)?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",T?"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:[!F&&C?s.jsx("button",{type:"button",onClick:Te=>{Te.stopPropagation(),C()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":D("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:D("sessions.sidebar.project.actions.newSession"),children:s.jsx(B,{name:"add",className:"h-3.5 w-3.5"})}):null,F?null:s.jsx("button",{type:"button",onClick:Te=>{Te.stopPropagation(),te()},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-ring","aria-label":D("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(B,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:Te=>{Te.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-ring","aria-label":F?D("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):D("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[53]=T,e[54]=F,e[55]=n.name,e[56]=te,e[57]=L,e[58]=h,e[59]=C,e[60]=Z,e[61]=D,e[62]=ne):ne=e[62];let U;e[63]!==b||e[64]!==me||e[65]!==ke||e[66]!==fe||e[67]!==De||e[68]!==je||e[69]!==Y||e[70]!==$||e[71]!==ne?(U=s.jsxs("div",{ref:b,className:me,onClick:ke,role:fe,tabIndex:De,onKeyDown:je,"aria-label":Y,children:[$,ne]}),e[63]=b,e[64]=me,e[65]=ke,e[66]=fe,e[67]=De,e[68]=je,e[69]=Y,e[70]=$,e[71]=ne,e[72]=U):U=e[72];let we;e[73]!==f||e[74]!==l||e[75]!==i||e[76]!==o||e[77]!==D?(we=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:D("sessions.sidebar.folderItem.emptyFolder")})]}),e[73]=f,e[74]=l,e[75]=i,e[76]=o,e[77]=D,e[78]=we):we=e[78];let he;return e[79]!==U||e[80]!==we?(he=s.jsxs("div",{className:"oc-folder",children:[U,we]}),e[79]=U,e[80]=we,e[81]=he):he=e[81],he},Qj=c.memo(qj);function Yj(t){return t.stopPropagation()}function Xj(t){return t.stopPropagation()}function Jj(t){return t.stopPropagation()}function Zj(t){return t.stopPropagation()}function e2(t){return t.stopPropagation()}function t2(t){return t.stopPropagation()}function s2(t){return t.stopPropagation()}function n2(t){return t.stopPropagation()}function r2(t){return t.stopPropagation()}function o2(t){return t.stopPropagation()}const i2=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}=kx(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 y;return e[9]!==d||e[10]!==o||e[11]!==w||e[12]!==f||e[13]!==v?(y=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]=y):y=e[14],y},a2=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}=Cx(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},l2=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=qr(_n(zi,l)),[u,d]=c.useState(null),[h,f]=c.useState("Session"),[p,g]=c.useState(null),[w,v]=c.useState(null);if(!n){let k;return e[1]!==o?(k=s.jsx(s.Fragment,{children:o}),e[1]=o,e[2]=k):k=e[2],k}let y;e[3]!==i?(y=k=>{d(null),g(null),v(null);const{active:R,over:I}=k;if(!I)return;const P=R.data.current,T=I.data.current;P?.type==="session"&&P.sessionId&&T?.type==="folder"&&T.folderId&&i(P.sessionId,T.folderId)},e[3]=i,e[4]=y):y=e[4];const m=y;let x,b;e[5]===Symbol.for("react.memo_cache_sentinel")?(x=k=>{const R=k.active.data.current;if(R?.type==="session"&&R.sessionId){d(R.sessionId),f(R.sessionTitle??"Session");const I=k.active.rect.current.initial?.width,P=k.active.rect.current.initial?.height;g(typeof I=="number"?I:null),v(typeof P=="number"?P:null)}},b=()=>{d(null),g(null),v(null)},e[5]=x,e[6]=b):(x=e[5],b=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(B,{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 C;e[13]!==S?(C=s.jsx(Vi,{children:S}),e[13]=S,e[14]=C):C=e[14];let N;return e[15]!==o||e[16]!==m||e[17]!==a||e[18]!==C?(N=s.jsxs(Qr,{sensors:a,collisionDetection:Yr,onDragStart:x,onDragCancel:b,onDragEnd:m,children:[o,C]}),e[15]=o,e[16]=m,e[17]=a,e[18]=C,e[19]=N):N=e[19],N},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)},Qn=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Qn(n,e))return!0;return!1},c2=({isSubtaskSession:t,archivedBucket:e,isVSCode:n,sessionDirectory:r})=>!t&&!e&&!n&&!Mp(r),d2=({sessionDirectory:t,isStreaming:e,isMovingToWorktree:n})=>!t||e||n,u2=(t,e,n)=>{const r=new Map,i=o=>{const l=Fs(o.session)??ft(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}))},m2=(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})},f2=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},h2=(t,e)=>{const n=e.searchQuery.trim().toLowerCase().startsWith("ses_"),r=new Map(t.map(d=>[d.id,d])),i=new Map,o=new Set;for(const d of t){if(d.parentId&&!r.has(d.parentId)){o.add(d.id);continue}if(d.parentId){const p=i.get(d.parentId)??[];p.push(d.id),i.set(d.parentId,p)}const h=new Set;let f=d.id;for(;f;){if(h.has(f)){o.add(d.id);break}h.add(f),f=r.get(f)?.parentId}}const l=new Set,a=new Set,u=d=>{if(l.has(d))return!0;if(a.has(d))return!1;const h=r.get(d);if(!h)return!1;a.add(d);let f=o.has(d);return!f&&e.archivedBucket&&h.nodeCount===0?f=(i.get(d)??[]).some(u):(!f&&!e.searchQuery&&(f=!0),!f&&(h.nodeCount>0||!n&&To([h.name],e.searchQuery))&&(f=!0),f||(f=(i.get(d)??[]).some(u))),a.delete(d),f&&l.add(d),f};return t.forEach(d=>u(d.id)),new Set(t.filter(d=>l.has(d.id)).map(d=>d.id))},Ic=new WeakMap;let Tc=1;const p2=t=>{const e=Ic.get(t);if(e!==void 0)return e;const n=Tc;return Tc+=1,Ic.set(t,n),n},zo=t=>t.children.length===0?"":t.children.map(n=>{const r=p2(n.session);return n.children.length===0?`${n.session.id}@${r}`:`${n.session.id}@${r}:${zo(n)}`}).join("|"),Tm=(t,e,n,r,i,o)=>{const l=ls(),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=yl(l,h??"",u.session.id),g=yl(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)},g2=t=>t.actionsAlwaysVisible?"":`transition-opacity duration-150 ${t.menuOpen?"opacity-0":t.hideOnHoverClass}`,Xr=(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 Ec=!1;function x2(){for(const t of da)t()}function Ga(t){ca!==t&&(ca=t,x2())}function b2(t){t.key==="Shift"&&Ga(!0)}function y2(t){t.key==="Shift"&&Ga(!1)}function w2(){Ga(!1)}function S2(){Ec||typeof window>"u"||(Ec=!0,window.addEventListener("keydown",b2),window.addEventListener("keyup",y2),window.addEventListener("blur",w2))}function v2(t){return S2(),da.add(t),()=>{da.delete(t)}}function j2(){return ca}function k2(){return!1}function C2(){return mt.useSyncExternalStore(v2,j2,k2)}const N2=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,Em=/^g[1-9]\d*$/,Tr=(t,e,n,r,i)=>{if(!N2.test(t)||e!==void 0&&!Em.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}},Co=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 Tr(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,a,u,d]=e;return Em.test(a)?Tr(n,a,u,d,void 0):Tr(n,void 0,a,u,d)}const[,r,i,o,l]=e;return r===""?Tr(n,void 0,i,o,l):Tr(n,r,i,o,l)},A2=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("/")},P2=(t,e,n,r)=>{const i=[t];return r&&i.push(r),i.push(e,n,"fusion"),i.join("/")},Rm=t=>{const e=nt.c(36),{value:n,onChange:r,className:i,disabled:o,id:l,portalToBody:a}=t,{t:u}=vt(),d=Yt(D2),h=Yt(I2),f=Yt(T2);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(E2),e[2]=g,e[3]=w):w=e[3];const v=w;let y,m;e[4]!==g.length||e[5]!==h?(y=()=>{g.length===0&&h()},m=[g.length,h],e[4]=g.length,e[5]=h,e[6]=y,e[7]=m):(y=e[6],m=e[7]),c.useEffect(y,m);let x,b;e[8]!==f||e[9]!==o||e[10]!==r||e[11]!==v||e[12]!==n?(x=()=>{if(o)return;const E=n.trim();if(E.length>0&&v.some(L=>L.name===E))return;const O=typeof f=="string"&&f.trim().length>0?f.trim():null;if(O&&v.some(L=>L.name===O)){r(O);return}const W=v[0]?.name;W&&r(W)},b=[f,o,r,v,n],e[8]=f,e[9]=o,e[10]=r,e[11]=v,e[12]=n,e[13]=x,e[14]=b):(x=e[13],b=e[14]),c.useEffect(x,b);const S=n.trim().length>0?n:void 0;let C;e[15]!==i?(C=Ie("max-w-full",i),e[15]=i,e[16]=C):C=e[16];let N;e[17]!==u?(N=u("multirun.agentSelector.placeholder"),e[17]=u,e[18]=N):N=e[18];let k;e[19]!==N?(k=s.jsx(Ms,{placeholder:N}),e[19]=N,e[20]=k):k=e[20];let R;e[21]!==l||e[22]!==C||e[23]!==k?(R=s.jsx(Us,{id:l,size:"lg",className:C,children:k}),e[21]=l,e[22]=C,e[23]=k,e[24]=R):R=e[24];let I;e[25]!==v?(I=v.length>0&&s.jsx(Li,{children:v.map(R2)}),e[25]=v,e[26]=I):I=e[26];let P;e[27]!==a||e[28]!==I?(P=s.jsx(Ks,{fitContent:!0,portalToBody:a,children:I}),e[27]=a,e[28]=I,e[29]=P):P=e[29];let T;return e[30]!==o||e[31]!==r||e[32]!==S||e[33]!==R||e[34]!==P?(T=s.jsxs(Vs,{value:S,onValueChange:r,disabled:o,children:[R,P]}),e[30]=o,e[31]=r,e[32]=S,e[33]=R,e[34]=P,e[35]=T):T=e[35],T};function D2(t){return t.getVisibleAgents}function I2(t){return t.loadAgents}function T2(t){return t.currentAgentName}function E2(t){return xu(t.mode)}function R2(t){return s.jsx(as,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const M2="h-7",Vr=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,O2=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",M2),e[0]=u):u=e[0];let d;e[1]!==n.providerID?(d=s.jsx($i,{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(B,{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},Mm=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,y=f===void 0?"top":f,{t:m}=vt(),x=Yt(B2),b=Yt(F2),S=Ne(_2),C=Ne(L2),{favoriteModelsList:N,recentModelsList:k}=Op(),R=Ne($2),I=Ne(W2),[P,T]=c.useState(!1),[E,O]=c.useState(""),[W,L]=c.useState(null),F=c.useRef(null),D=c.useRef(null),j=d===1,A=d===void 0||n.length<d||j;let M;if(e[0]!==n){M=new Map;for(const Be of n){const rt=`${Be.providerID}:${Be.modelID}`;M.set(rt,(M.get(rt)||0)+1)}e[0]=n,e[1]=M}else M=e[1];const G=M;let q;e[2]!==n?(q=Be=>n.filter(Ge=>Ge.providerID===Be.providerID&&Ge.modelID===Be.modelID).findIndex(Ge=>Ge.instanceId===Be.instanceId)+1,e[2]=n,e[3]=q):q=e[3];const Z=q;let le,X;e[4]!==y||e[5]!==P?(le=()=>{if(!P||!D.current)return;const Be=D.current.getBoundingClientRect();if(y==="bottom"){const pt=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-Be.bottom-16-112;L(Math.max(160,Math.min(320,pt)));return}let rt=D.current.parentElement;for(;rt&&!rt.matches('[role="dialog"], [data-scroll-shadow-scroller]');){const at=getComputedStyle(rt);if(at.overflow==="auto"||at.overflow==="hidden"||at.overflowY==="auto"||at.overflowY==="hidden")break;rt=rt.parentElement}const Ge=rt?rt.getBoundingClientRect().top:0,ut=Be.top-Ge-16;L(Math.max(150,Math.min(300,ut)))},X=[y,P],e[4]=y,e[5]=P,e[6]=le,e[7]=X):(le=e[6],X=e[7]),c.useEffect(le,X);let te,re;e[8]!==A||e[9]!==P?(te=()=>{!A&&P&&(T(!1),O(""))},re=[A,P],e[8]=A,e[9]=P,e[10]=te,e[11]=re):(te=e[10],re=e[11]),c.useEffect(te,re);let Se,ue;e[12]!==P?(Se=()=>{if(!P)return;const Be=rt=>{F.current&&!F.current.contains(rt.target)&&(T(!1),O(""))};return document.addEventListener("mousedown",Be),()=>document.removeEventListener("mousedown",Be)},ue=[P],e[12]=P,e[13]=Se,e[14]=ue):(Se=e[13],ue=e[14]),c.useEffect(Se,ue);let ye;e[15]!==j||e[16]!==r||e[17]!==o||e[18]!==n.length?(ye=Be=>{const rt={providerID:Be.providerID,modelID:Be.modelID,displayName:Be.model.name||Be.modelID,instanceId:Vr()};j&&n.length>0&&o?o(0,rt):r(rt),j&&(T(!1),O(""))},e[15]=j,e[16]=r,e[17]=o,e[18]=n.length,e[19]=ye):ye=e[19];const ve=ye;let be;e[20]!==m?(be=m("multirun.modelMultiSelect.search.placeholder"),e[20]=m,e[21]=be):be=e[21];let _;e[22]!==m?(_=m("multirun.modelMultiSelect.search.noResults"),e[22]=m,e[23]=_):_=e[23];let oe;e[24]!==m?(oe=m("multirun.modelMultiSelect.sections.favorites"),e[24]=m,e[25]=oe):oe=e[25];let ce;e[26]!==m?(ce=m("multirun.modelMultiSelect.sections.recent"),e[26]=m,e[27]=ce):ce=e[27];let Q;e[28]!==m?(Q=m("multirun.modelMultiSelect.keyboard.hint"),e[28]=m,e[29]=Q):Q=e[29];let me;e[30]!==m?(me=m("settings.agents.modelSelector.actions.favorite"),e[30]=m,e[31]=me):me=e[31];let ke;e[32]!==m?(ke=m("settings.agents.modelSelector.actions.unfavorite"),e[32]=m,e[33]=ke):ke=e[33];let fe;e[34]!==m?(fe=m("chat.modelControls.capabilities"),e[34]=m,e[35]=fe):fe=e[35];let De;e[36]!==m?(De=m("chat.modelControls.capability.toolCalling"),e[36]=m,e[37]=De):De=e[37];let je;e[38]!==m?(je=m("chat.modelControls.capability.reasoning"),e[38]=m,e[39]=je):je=e[39];let Y;e[40]!==m?(Y=m("chat.modelControls.input"),e[40]=m,e[41]=Y):Y=e[41];let Re;e[42]!==m?(Re=m("chat.modelControls.output"),e[42]=m,e[43]=Re):Re=e[43];let Ce;e[44]!==m?(Ce=m("chat.modelControls.costPerMillion"),e[44]=m,e[45]=Ce):Ce=e[45];let Me;e[46]!==be||e[47]!==_||e[48]!==oe||e[49]!==ce||e[50]!==Q||e[51]!==me||e[52]!==ke||e[53]!==fe||e[54]!==De||e[55]!==je||e[56]!==Y||e[57]!==Re||e[58]!==Ce?(Me={searchPlaceholder:be,noResults:_,favorites:oe,recent:ce,keyboardHint:Q,favorite:me,unfavorite:ke,capabilities:fe,capabilityToolCalling:De,capabilityReasoning:je,input:Y,output:Re,costPerMillion:Ce},e[46]=be,e[47]=_,e[48]=oe,e[49]=ce,e[50]=Q,e[51]=me,e[52]=ke,e[53]=fe,e[54]=De,e[55]=je,e[56]=Y,e[57]=Re,e[58]=Ce,e[59]=Me):Me=e[59];const ae=Me;let ee;e[60]!==g?(ee=Ie("relative",g),e[60]=g,e[61]=ee):ee=e[61];const K=P?"":void 0;let $;e[62]!==h?($=Ie(bu({size:"default"}),"w-fit",h),e[62]=h,e[63]=$):$=e[63];const ne=!A;let U;e[64]!==P?(U=()=>{T(!P)},e[64]=P,e[65]=U):U=e[65];let we;e[66]!==w?(we=w??s.jsx(B,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=w,e[67]=we):we=e[67];let he;e[68]!==a||e[69]!==m?(he=a??m("multirun.modelMultiSelect.actions.addModel"),e[68]=a,e[69]=m,e[70]=he):he=e[70];let Te;e[71]!==K||e[72]!==$||e[73]!==ne||e[74]!==U||e[75]!==we||e[76]!==he?(Te=s.jsxs("button",{ref:D,type:"button","data-popup-open":K,className:$,disabled:ne,onClick:U,children:[we,he]}),e[71]=K,e[72]=$,e[73]=ne,e[74]=U,e[75]=we,e[76]=he,e[77]=Te):Te=e[77];let Oe;e[78]!==W||e[79]!==A||e[80]!==p||e[81]!==y||e[82]!==N||e[83]!==ve||e[84]!==R||e[85]!==C||e[86]!==P||e[87]!==ae||e[88]!==G||e[89]!==b||e[90]!==I||e[91]!==x||e[92]!==k||e[93]!==E||e[94]!==S?(Oe=P?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",y==="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(Bp,{providers:x,providerOrder:I,favoriteModels:N,recentModels:k,modelsMetadata:b,hiddenModels:R,searchQuery:E,onSearchQueryChange:O,onSelect:ve,labels:ae,selectionCount:Be=>G.get(`${Be.providerID}:${Be.modelID}`)||0,disabled:!A,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:W?`${W}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:P,isFavorite:Be=>C(Be.providerID,Be.modelID),onToggleFavorite:Be=>S(Be.providerID,Be.modelID),onEscape:()=>{T(!1),O("")}})}):null,e[78]=W,e[79]=A,e[80]=p,e[81]=y,e[82]=N,e[83]=ve,e[84]=R,e[85]=C,e[86]=P,e[87]=ae,e[88]=G,e[89]=b,e[90]=I,e[91]=x,e[92]=k,e[93]=E,e[94]=S,e[95]=Oe):Oe=e[95];let _e;e[96]!==ee||e[97]!==Te||e[98]!==Oe?(_e=s.jsxs("div",{className:ee,ref:F,children:[Te,Oe]}),e[96]=ee,e[97]=Te,e[98]=Oe,e[99]=_e):_e=e[99];let Ve;e[100]!==Z||e[101]!==G||e[102]!==i||e[103]!==o||e[104]!==x||e[105]!==n||e[106]!==v||e[107]!==m?(Ve=v&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((Be,rt)=>{const Ge=`${Be.providerID}:${Be.modelID}`,ut=G.get(Ge)||1,at=Z(Be),pt=x.find(de=>de.id===Be.providerID)?.models?.find(de=>de.id===Be.modelID),It=pt?.variants?Object.keys(pt.variants):[],Pt=It.length>0,Rt=Be.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(O2,{model:Be,instanceIndex:at,totalSameModel:ut,onRemove:()=>i(rt)}),Pt&&s.jsxs(Vs,{value:Rt,onValueChange:de=>{if(!o)return;o(rt,{...Be,variant:de==="__default__"?void 0:de})},children:[s.jsxs(Us,{size:"sm",className:"gap-1.5",children:[s.jsx(B,{name:"brain-ai-3",className:Ie("h-3.5 w-3.5 flex-shrink-0",Rt==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(Ms,{placeholder:m("multirun.modelMultiSelect.variant.placeholder"),children:de=>de==="__default__"?m("multirun.modelMultiSelect.variant.default"):de})]}),s.jsxs(Ks,{fitContent:!0,children:[s.jsx(as,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:m("multirun.modelMultiSelect.variant.default")}),It.map(z2)]})]})]},Be.instanceId)})}),e[100]=Z,e[101]=G,e[102]=i,e[103]=o,e[104]=x,e[105]=n,e[106]=v,e[107]=m,e[108]=Ve):Ve=e[108];let z;e[109]!==_e||e[110]!==Ve?(z=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[_e,Ve]}),e[109]=_e,e[110]=Ve,e[111]=z):z=e[111];let pe;e[112]!==d||e[113]!==l||e[114]!==n.length||e[115]!==m?(pe=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]=pe):pe=e[116];let Ae;return e[117]!==z||e[118]!==pe?(Ae=s.jsxs("div",{className:"space-y-2",children:[z,pe]}),e[117]=z,e[118]=pe,e[119]=Ae):Ae=e[119],Ae};function B2(t){return t.providers}function F2(t){return t.modelsMetadata}function _2(t){return t.toggleFavoriteModel}function L2(t){return t.isFavoriteModel}function $2(t){return t.hiddenModels}function W2(t){return t.providerOrder}function z2(t){return s.jsx(as,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const V2=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
881
|
+
|
|
882
|
+
--- RESULT ${n+1}: ${r} ---
|
|
883
|
+
${e.trim()}
|
|
884
|
+
--- END RESULT ${n+1} ---`},Rc=(t,e)=>tt.getState().getWorktreeMetadata(t)?.projectDirectory??e,U2=async t=>{const e=t.directory??void 0,n=_p(t.session.id,e);if(n.length===0&&t.directory){const i=(await nn.withDirectory(t.directory,()=>nn.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 Sl(l.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const i=n[r];if(i.role==="assistant")return Sl(Lp(i.id,e)).trim()}return""};function K2({session:t,open:e,onOpenChange:n}){const{t:r}=vt(),i=Fp(),o=Gs(j=>j.activeSessions),l=Gs(j=>j.archivedSessions),a=Yt(j=>j.providers),u=Yt(j=>j.currentProviderId),d=Yt(j=>j.currentModelId),h=Yt(j=>j.currentAgentName),[f,p]=c.useState(u??""),[g,w]=c.useState(d??""),[v,y]=c.useState(()=>u&&d?[{providerID:u,modelID:d,instanceId:Vr()}]:[]),[m,x]=c.useState(""),[b,S]=c.useState(h??""),[C,N]=c.useState([]),[k,R]=c.useState(!1),I=c.useMemo(()=>Co(t.title),[t.title]),P=c.useMemo(()=>{const j=new Map;for(const A of i)j.set(A.id,A);for(const A of o)j.set(A.id,A);for(const A of l)j.set(A.id,A);return t.id&&j.set(t.id,t),Array.from(j.values())},[o,l,i,t]);c.useEffect(()=>{if(!e||!I)return;const j=tt.getState().getDirectoryForSession(t.id),A=Rc(t.id,j),M=P.map(G=>{const q=Co(G.title);if(!q||q.groupSlug!==I.groupSlug||q.fusion||(q.runGroup??null)!==(I.runGroup??null))return null;const Z=tt.getState().getDirectoryForSession(G.id)??Fs(G),le=Rc(G.id,Z);return A&&le&&A!==le?null:{session:G,directory:Z,projectDirectory:le}}).filter(G=>G!==null).sort((G,q)=>(G.session.time?.created??0)-(q.session.time?.created??0));N(M)},[P,e,I,t.id]);const E=a.find(j=>j.id===f)?.models.find(j=>j.id===g),O=E?.variants?Object.keys(E.variants):[],W=!!(I&&f&&g&&C.length>0&&!k),L=c.useCallback(j=>{y([j]),p(j.providerID),w(j.modelID),x("")},[]),F=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),D=async()=>{if(!(!I||!f||!g)){R(!0);try{const j=await Promise.all(C.map(X=>U2(X))),A=C.map((X,te)=>({source:X,text:j[te]??""})).filter(X=>X.text.trim().length>0);if(A.length===0){Fe.error(r("multirun.fusion.toast.noOutputs"));return}const M=C[0]?.projectDirectory??C[0]?.directory??null,G=P2(I.groupSlug,f,g,I.runGroup),[q,Z]=await Promise.all([wl("session.fusion.visible"),wl("session.fusion.instructions")]),le=await tt.getState().createSession(G,M,null);if(!le)throw new Error("Failed to create fusion session");tt.getState().setCurrentSession(le.id,M),n(!1),await nn.sendMessage({id:le.id,providerID:f,modelID:g,variant:m||void 0,agent:b||void 0,text:q,additionalParts:[{text:Z,synthetic:!0},...A.map((X,te)=>({text:V2(X.source,X.text,te),synthetic:!0})),{text:`
|
|
885
|
+
|
|
886
|
+
--- FUSION INPUTS END ---
|
|
887
|
+
Now write the final fused answer.`,synthetic:!0}],directory:M??nn.getDirectory()})}catch(j){console.error("[MultiRunFusion] Failed to start fusion",j),Fe.error(r("multirun.fusion.toast.failed"))}finally{R(!1)}}};return s.jsx(Ds,{open:e,onOpenChange:n,children:s.jsxs(Is,{className:"max-w-xl overflow-visible",children:[s.jsxs(Xs,{children:[s.jsx(_s,{children:r("multirun.fusion.title")}),s.jsx(Ls,{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(Mm,{selectedModels:v,onAdd:L,onUpdate:(j,A)=>L(A),onRemove:()=>{y([]),p(""),w(""),x("")},maxModels:1,addButtonLabel:F,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($i,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),O.length>0?s.jsxs(Vs,{value:m||"__default__",onValueChange:j=>x(j==="__default__"?"":j),children:[s.jsxs(Us,{size:"lg",className:"w-fit",children:[s.jsx(B,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Ms,{children:j=>j==="__default__"?r("multirun.modelMultiSelect.variant.default"):j})]}),s.jsxs(Ks,{fitContent:!0,portalToBody:!0,children:[s.jsx(as,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),O.map(j=>s.jsx(as,{value:j,children:j},j))]})]}):null,s.jsx(Rm,{value:b,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:C.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:C.map(j=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx($i,{providerId:Co(j.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:j.session.title||j.session.id}),s.jsx("button",{type:"button",onClick:()=>N(A=>A.filter(M=>M.session.id!==j.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(B,{name:"close",className:"h-4 w-4"})})]},j.session.id))})]}),s.jsxs(wn,{children:[s.jsx(dt,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(dt,{onClick:D,disabled:!W,children:r(k?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function H2(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 Om=async(t,e,n)=>{const r=n.getRuntimeKey(),i=ft(t.path);if(!i)throw new Error("Unable to resolve worktree project");const o=await n.listProjectWorktrees(t,{force:!0});if(n.getRuntimeKey()!==r)throw new Error("Runtime changed during worktree refresh");const l=n.getCurrentProjects(),a=l.find(w=>w.id===t.id)??null;if(!a||ft(a.path??null)!==i)throw new Error("Project removed during worktree refresh");const u=qa({rawWorktreesByProjectRef:n.rawWorktreesByProjectRef,publishedWorktreesByProject:n.getPublishedWorktreesByProject(),runtimeKey:r}),d=o.map(w=>Vo(w));d.sort((w,v)=>Bm({metadata:w},{metadata:v}));const h=$p(u.worktreesByProject,i,d,e?.projectDirectory);G2(n.rawWorktreesByProjectRef,r),n.rawWorktreesByProjectRef.current={runtimeKey:r,revision:n.rawWorktreesByProjectRef.current.revision,worktreesByProject:h};const f=n.getPublishedWorktreesByProject(),p=Wp(n.partitionWorktreesByRegisteredProject(l,h),f),g=[...p.values()].flat();return n.recordWorktreesSeen(g.map(w=>w.path),n.now()),n.worktreeMapsEqual(p,f)||n.publishTopology({availableWorktrees:g,availableWorktreesByProject:p}),d},G2=(t,e)=>(t.current.runtimeKey!==e||(t.current={...t.current,revision:t.current.revision+1}),t.current.revision),q2=t=>new Map([...t.entries()].map(([e,n])=>[e,n.map(r=>Vo(r))])),qa=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:q2(t.publishedWorktreesByProject)}),t.rawWorktreesByProjectRef.current),Bm=(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"})},Mc=t=>{const e=t.split("/").filter(Boolean);return e[e.length-1]??t},Vo=t=>({...t,path:ft(t.path)??t.path,projectDirectory:ft(t.projectDirectory)??t.projectDirectory,worktreeRoot:ft(t.worktreeRoot??t.path)??t.worktreeRoot}),Oc=t=>{const{currentWorktree:e,path:n,projectDirectory:r,projectRootBranch:i}=t,l=ft(e?.path??null)===n,a=l?e?.branch??"":i??"",u={path:n,projectDirectory:r,branch:a,label:l?e?.label||e?.branch||e?.name||Mc(n):i||Mc(n),name:l?e?.name:void 0,worktreeRoot:l?ft(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},Bc=t=>{const e=ft(t.projectPath??null),n=ft(t.sourceDirectory??null)??ft(t.currentWorktree?.path??null),r=ft(t.discoveredWorktrees.find(h=>ft(h.projectDirectory??null))?.projectDirectory??null),i=ft(t.currentWorktree?.projectDirectory??null),o=r??i??e,l=new Map,a=h=>{const f=ft(h.metadata.path??null);!f||l.has(f)||l.set(f,{...h,metadata:Vo({...h.metadata,path:f})})};for(const h of t.discoveredWorktrees){const f=ft(h.path??null);f&&a({metadata:Vo({...h,path:f,projectDirectory:ft(h.projectDirectory??null)??o??e??f}),isPrimary:o===f,isCurrent:n===f})}o&&!l.has(o)&&a({metadata:Oc({path:o,projectDirectory:o,currentWorktree:t.currentWorktree,projectRootBranch:t.projectRootBranch}),isPrimary:!0,isCurrent:n===o}),n&&!l.has(n)&&a({metadata:Oc({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(Bm),[...u,...d]},Q2=(t,e)=>{const n=e.getRuntimeKey(),r=e.getPublishedWorktreesByProject(),i=qa({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=ft(l?.path??null);return{cachedTargets:Bc({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 Om(l,t.currentWorktree,e);return Bc({projectPath:a,discoveredWorktrees:d,sourceDirectory:t.sourceDirectory,currentWorktree:t.currentWorktree,projectRootBranch:e.projectRootBranch})})()}},Y2=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},X2=t=>({refreshState:t.isRefreshing?"loading":t.loadFailed&&t.targets.length===0?"error":null,showNewWorktreeAction:!0}),J2=(t,e)=>ft(t.worktree?.path??null)===ft(e.worktree?.path??null)&&t.worktree?.branch===e.worktree?.branch,ua=6,po=14,Fc=ua+14+6,wi=new WeakMap,Z2=t=>{const e=t.closest("[data-session-row]"),n=e?.closest(".overlay-scrollbar-container");if(!e||!n)return;wi.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,wi.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,sn("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}),wi.set(n,a),l=window.requestAnimationFrame(u)},ek=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=C2(),p=f?i:r;let g;n[0]!==d||n[1]!==h||n[2]!==f?(g=N=>{if(f||N.shiftKey){h(N);return}d(N)},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 y;n[4]!==o||n[5]!==v?(y=Ie("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring transition-opacity",v,o),n[4]=o,n[5]=v,n[6]=y):y=n[6];const m=f?"delete-bin":"archive";let x;n[7]!==l||n[8]!==m?(x=s.jsx(B,{name:m,className:l}),n[7]=l,n[8]=m,n[9]=x):x=n[9];let b;n[10]!==w||n[11]!==p||n[12]!==u||n[13]!==a||n[14]!==y||n[15]!==x?(b=s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",className:y,"aria-label":p,onPointerDown:a,onMouseDown:u,onClick:w,onKeyDown:ck,children:x})}),n[10]=w,n[11]=p,n[12]=u,n[13]=a,n[14]=y,n[15]=x,n[16]=b):b=n[16];let S;n[17]!==p?(S=s.jsx(At,{side:"left",sideOffset:8,children:p}),n[17]=p,n[18]=S):S=n[18];let C;return n[19]!==b||n[20]!==S?(C=s.jsxs(Ct,{children:[b,S]}),n[19]=b,n[20]=S,n[21]=C):C=n[21],C});function tk(t){sn("ui.sidebar_session_node.render");const{t:e}=vt(),{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:y,handleCancelEdit:m,toggleParent:x,handleSessionSelect:b,handleSessionDoubleClick:S,handleShareSession:C,copiedSessionId:N,handleCopyShareUrl:k,handleCopySessionId:R,handleUnshareSession:I,openSidebarMenuKey:P,setOpenSidebarMenuKey:T,createFolderAndStartRename:E,handleDeleteSession:O,handleRestoreSession:W,startSessionWorktreeMenuLoad:L,mobileVariant:F,alwaysShowActions:D,secondaryMeta:j,renderContext:A="project",children:M}=t,G=Hr(Pe=>Pe.toggle),q=xs(Pe=>Pe.getFoldersForScope),Z=xs(Pe=>Pe.getSessionFolderId),le=xs(Pe=>Pe.removeSessionFromFolder),X=xs(Pe=>Pe.addSessionToFolder),te=Ne(Pe=>Pe.openContextPanelTab),re=c.useMemo(()=>$n(),[]),Se=c.useMemo(()=>Ur(),[]),ue=c.useContext(zp),ye=re?"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",ve=re?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",be=re,_=!l&&!F,oe=re?_&&be?"group-hover:pr-18":_||be?"group-hover:pr-14":"group-hover:pr-8":_?"group-hover:pr-7 group-focus-within:pr-7":"group-hover:pr-3 group-focus-within:pr-3",ce=_?"pr-13":"pr-7",Q=re?_?"pr-18":"pr-14":_?"pr-7":"pr-3",me=c.useRef(!1),[ke,fe]=c.useState(!1),De=c.useRef(p);De.current=p;const je=c.useRef(null),Y=c.useRef(!1),Re=c.useRef(y);Re.current=y;const[Ce,Me]=c.useState(w),ae=c.useRef(Ce);ae.current=Ce;const ee=c.useRef(null),K=c.useRef(!1),$=c.useRef(null),ne=c.useRef(null),U=n.session,we=U,he=qt(c.useCallback(Pe=>{if(j?.projectLabel||!o)return null;const _t=Pe.projects.find(Zt=>Zt.id===o);return _t?_t.label?.trim()||Ln(ft(_t.path)??_t.path,null)||_t.path:null},[o,j?.projectLabel])),Te=j?.projectLabel??(he?Oa(he):null),Oe=j?.branchLabel??n.worktree?.branch??null,_e=c.useMemo(()=>{if(re)return null;const Pe=n.worktree?.branch?.trim(),_t=ft(n.worktree?.path??null);return Pe&&_t?Yo(_t,Pe):null},[re,n.worktree]),Ve=yu(_e),z=Ve?`var(--pr-${Ve.visualState})`:void 0,pe=gs(Pe=>Pe.sessionGroupingMode),Ae=!!Oe&&(A==="recent"||pe==="flat"),Be=c.useMemo(()=>{if(!Ve)return null;switch(Ve.visualState){case"merged":return e("sessions.sidebar.group.pr.status.merged");case"open":return Ve.canMerge===!0||Ve.mergeableState==="clean"||Ve.checks?.state==="success"?e("sessions.sidebar.group.pr.status.readyToMerge"):e("sessions.sidebar.group.pr.status.open");case"blocked":return Ve.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}},[Ve,e]),rt=tt(Pe=>Pe.currentSessionId===U.id),Ge=ft(U.directory??null)??ft(i??null),ut=o??Ge??null,at=Vp(),wt=wu(),pt=re,It=ks(Pe=>Pe.enabled),Pt=ks(c.useCallback(Pe=>Pe.selectedIds.has(U.id),[U.id])),Rt=ks(Pe=>Pe.toggleSelected),de=ks(Pe=>Pe.setRange),We=c.useCallback(Pe=>{const _t=[],Zt=ms=>{ms.children.forEach(As=>{_t.push(As.session.id),Zt(As)})};return Zt(Pe),_t},[]),lt=c.useCallback(Pe=>{const _t=[],Zt=ms=>{ms.children.forEach(As=>{_t.push(As.session),Zt(As)})};return Zt(Pe),_t},[]),[H,V]=c.useState(!1),[J,ge]=c.useState(!0),Ee=`${A}:${l?"archived":"active"}:${U.id}`,$e=Su(c.useCallback(Pe=>!!Pe.sessionMemoryState.get(Up(U.id))?.isZombie,[U.id])),Ze=va(U.id)?.type??"idle",et=Ze==="busy"||Ze==="retry",Ue=Kp(U.id,et),jt=Hu(U.id),ze=Sa(U.id,Ge),xe=jt||ze,bt=n.worktree??tt.getState().getWorktreeMetadata(U.id)??null,[ht,kt]=c.useState([]),[Xe,Ke]=c.useState(!1),[Ye,gt]=c.useState(!1),Mt=c.useRef(!1),xt=c.useRef(0),St=Hp(U.id,Ge??void 0,{bootstrap:!1}),Tt=Gp(we),Jt=Tt?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center",title:e(vl[Tt.status]),"aria-label":e(vl[Tt.status]),children:s.jsx(B,{name:"target",className:"h-3 w-3",style:{color:qp[Tt.status]}})}):null,Gt=we.title||e("sessions.sidebar.session.untitled"),$t=n.children.length>0,Kt=Qp(a,Ge,U.id),Ht=Ee,Qt=d?!0:u.has(Ht),Le=c.useMemo(()=>u2(n,Qt,Ge),[Qt,n,Ge]),qe=Yp(Le),ot=!!we.parentID,He=Fd(U.id)>0&&(!ot||f),Bt=we.time?.updated||we.time?.created||Date.now(),ts=vu(Bt),es=Xp(Bt),ss=P===Ee,[ds,Js]=c.useState(!1),us=ss||ds,Os=c.useMemo(()=>Co(we.title)!==null,[we.title]),[ns,Cs]=c.useState(!1),Zs=c.useMemo(()=>We(n).length,[We,n]),Ns=c.useCallback(async Pe=>{const _t=[];let Zt=0;for(const ms of Pe)try{if(!Ge)throw new Error("Session directory is required for export");const As=await at({directory:Ge,sessionID:ms.session.id});if(!As)throw new Error("Session runtime changed during export");const rs=ms.session.title||e("sessions.sidebar.session.export.untitledSubagent"),rn=ms.session.agent,os=await Ns(ms.children);Zt+=os.skipped,_t.push({title:rs,agent:rn,records:As,children:os.children})}catch{Zt+=We(ms).length+1}return{children:_t,skipped:Zt}},[We,at,Ge,e]),Ts=c.useCallback(Pe=>{Pe<=0||Fe.warning(Pe===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:Pe}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:Pe}))},[e]),Lt=c.useCallback(async Pe=>{if(!Ge){Fe.error(e("sessions.sidebar.session.export.nothingToExport"));return}const _t=await at({directory:Ge,sessionID:U.id}).catch(()=>null);if(!_t){Fe.error(e("sessions.sidebar.session.export.failedLoadHistory"));return}if(_t.length===0){Fe.error(e("sessions.sidebar.session.export.nothingToExport"));return}let Zt,ms=0;if(Pe&&n.children.length>0){const os=await Ns(n.children);Zt=os.children,ms=os.skipped}const As=Gd(_t,we.title??null,Zt),rs=qd(we.title??null),rn=await Qd(As,rs);if(rn){Fe.success(e("sessions.sidebar.session.export.success"),{action:{label:e(Zp()),onClick:()=>{Jp(rn).then(os=>{os||Fe.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Ts(ms);return}Yd(As,rs),Fe.success(e("sessions.sidebar.session.export.success")),Ts(ms)},[Ns,at,n.children,we.title,U.id,Ge,Ts,e]),Wt=Xd(),Xt=c.useMemo(()=>Jd(Wt),[Wt]),fs=c.useCallback(Pe=>{Ku({entry:Pe,session:{id:U.id,title:we.title,directory:Ge},loadRecords:()=>Ge?at({directory:Ge,sessionID:U.id}).catch(()=>null):Promise.resolve(null),onLoadFailed:()=>Fe.error(e("sessions.sidebar.session.export.failedLoadHistory"))})},[at,we.title,U.id,Ge,e]),cs=c.useCallback(async()=>{if(n.children.length>0){ge(!0),V(!0);return}await Lt(!1)},[Lt,n.children.length]),Es=c.useCallback(()=>{Ge&&Fn("desktop_open_session_mini_chat_window",{sessionId:U.id,directory:Ge,apiBaseUrl:Pn(),clientToken:Kr()}).catch(Pe=>{console.warn("[session-sidebar] failed to open mini chat window",Pe)})},[U.id,Ge]);if(c.useEffect(()=>{if(p!==U.id)return;const Pe=_t=>{const ms=(_t.target instanceof HTMLElement?_t.target:null)?.closest?.(`[data-session-rename-form="${CSS.escape(U.id)}"]`);ne.current&&!ms&&Re.current(ae.current)};return document.addEventListener("mousedown",Pe),()=>document.removeEventListener("mousedown",Pe)},[p,U.id]),c.useLayoutEffect(()=>{if(p!==U.id){ee.current===U.id&&(ee.current=null);return}ee.current!==U.id&&(ee.current=U.id,K.current=!0,Me(w))},[p,w,U.id]),c.useLayoutEffect(()=>{if(p!==U.id||!K.current)return;const Pe=$.current;!Pe||Pe.value!==w||(K.current=!1,Pe.focus(),Pe.select())},[p,w,Ce,U.id]),p===U.id)return s.jsx("div",{style:{paddingLeft:Fc+r*po},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:ne,"data-session-rename-form":U.id,className:"flex w-full items-center gap-2",onSubmit:Pe=>{Pe.preventDefault(),y(Ce)},children:[s.jsx("input",{ref:$,value:Ce,onChange:Pe=>Me(Pe.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:Pe=>Pi(Pe,m)}),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(B,{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(B,{name:"close",className:"size-4"})})]})})},U.id);const Ss=St.length,hs=qe===1?e("sessions.sidebar.session.status.questionPendingSingle"):e("sessions.sidebar.session.status.questionPendingMany",{count:qe}),Tn=g2({actionsAlwaysVisible:D&&!re,menuOpen:us,hideOnHoverClass:ve}),En=!xe&&!et&&He&&!rt,se=et||En,Qe=e(et?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),ct=s.jsx("span",{className:Ie("h-1.5 w-1.5 rounded-full",et?"bg-primary":"bg-[var(--status-info)]"),"aria-label":Qe,title:Qe}),Dt=(et||En)&&Ue,zt=!D&&$t&&(xe||se||Kt),Ft=Kt&&!xe&&!se,Et=s.jsx(B,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}),ys=xe||se||Ft?s.jsx("span",{style:{left:ua+r*po},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",zt?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:xe?s.jsx(B,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":e(ze?"sessions.aiRename.generating":"sessions.sidebar.session.status.movingToWorktree")}):se?ct:Ft?Et:null}):null,ie=$t&&!D&&(xe||se||Kt),Je=$t?s.jsx("span",{role:"button",tabIndex:0,onClick:Pe=>{Pe.stopPropagation(),Pe.currentTarget.blur(),x(Ht)},onKeyDown:Pe=>{(Pe.key==="Enter"||Pe.key===" ")&&(Pe.preventDefault(),Pe.stopPropagation(),x(Ht))},style:{minWidth:14,minHeight:14,left:ua+r*po},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-ring transition-opacity",ie?"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(Qt?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Qt?s.jsx(B,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(B,{name:"arrow-right-s",className:"h-3 w-3"})}):null,yt=$e?s.jsx(B,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Vt=Pe=>{Pe&&Js(!1),T(Pe?Ee:null)},ws=Pe=>{if(!Pe&&je.current){const{id:_t,title:Zt}=je.current;je.current=null,g(_t),v(Zt)}},$s=Pe=>{Js(Pe)},vs=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),T(ss?null:Ee)},kr=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},no=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},ri=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},Xm=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},Jm=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),T(null),O(U,{archivedBucket:l})},Zm=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),T(null),O(U,{archivedBucket:l,hardDelete:!0,skipConfirm:!0})},ef=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},tf=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},sf=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),ue?.vscode?.executeCommand("openchamber.openSessionInEditor",U.id,Gt)},Qa=Pe=>{if(me.current){me.current=!1;return}if(It){if(Pe?.preventDefault(),Pe?.stopPropagation(),Pe?.shiftKey){const Zt=Array.from(document.querySelectorAll("[data-session-row]")).map(rs=>rs.getAttribute("data-session-row")).filter(rs=>rs!==null&&rs.length>0),ms=ks.getState().anchorId,As=new Map;As.set(U.id,We(n)),de(ms,U.id,Zt,ut,As);return}Rt(U.id,ut,We(n));return}Pe?.currentTarget&&Z2(Pe.currentTarget),b(U.id,Ge)},nf=Pe=>{Pe.defaultPrevented||(Pe.target instanceof HTMLElement?Pe.target:null)?.closest('button, a, input, [role="menuitem"], [role="menu"]')||Qa(Pe)},rf=Pe=>{(Pe.button===2||Pe.button===0&&Pe.ctrlKey&&!It)&&(me.current=!0)},of=Pe=>{F&&Pe.pointerType==="touch"&&fe(!0),Pe.button===0&&!rt&&!It&&!pt&&Ge&&!_i(U.id,Ge).renderable&&wt({directory:Ge,sessionID:U.id}).catch(()=>{})},Ya=Pe=>{F&&Pe.pointerType==="touch"&&fe(!1)},af=Pe=>{Mt.current=Pe,xt.current+=1;const _t=xt.current;if(!Pe){Ke(!1),gt(!1);return}const Zt=L({projectId:o??null,sourceDirectory:Ge,currentWorktree:bt});kt(Zt.cachedTargets),Ke(!0),gt(!1),Zt.refreshTargets.then(ms=>{!Mt.current||xt.current!==_t||(kt(ms),Ke(!1),gt(!1))}).catch(()=>{!Mt.current||xt.current!==_t||(Ke(!1),gt(!0))})},Xa=({Item:Pe,Separator:_t,Sub:Zt,SubTrigger:ms,SubContent:As})=>s.jsxs(s.Fragment,{children:[s.jsxs(Pe,{onClick:()=>{je.current={id:U.id,title:Gt}},className:"[&>svg]:mr-1",children:[s.jsx(B,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsx(Qi,{sessionID:U.id,directory:Ge,open:us,Item:Pe}),s.jsxs(Pe,{onClick:()=>R(U.id),className:"[&>svg]:mr-1",children:[s.jsx(B,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyId")]}),s.jsxs(Pe,{onClick:()=>Ge&&G({directory:Ge,sessionId:U.id}),className:"[&>svg]:mr-1",children:[Kt?s.jsx(B,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(B,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(Kt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),we.share?s.jsxs(s.Fragment,{children:[s.jsx(Pe,{onClick:()=>{we.share?.url&&k(we.share.url,U.id)},className:"[&>svg]:mr-1",children:N===U.id?s.jsxs(s.Fragment,{children:[s.jsx(B,{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(B,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(Pe,{onClick:()=>I(U.id),className:"[&>svg]:mr-1",children:[s.jsx(B,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Pe,{onClick:()=>C(we),className:"[&>svg]:mr-1",children:[s.jsx(B,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(Pe,{onClick:()=>{cs()},className:"[&>svg]:mr-1",children:[s.jsx(B,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),Xt.map(rs=>s.jsxs(Pe,{onClick:()=>fs(rs),className:"[&>svg]:mr-1",children:[s.jsx(Jr,{icon:rs.icon,iconSrc:rs.iconSrc,className:"mr-1 size-4"}),rs.action.label]},`${rs.guest.id}:${rs.action.id}`)),c2({isSubtaskSession:ot,archivedBucket:!!l,isVSCode:re,sessionDirectory:Ge})?(()=>{const rs=d2({sessionDirectory:Ge,isStreaming:et,isMovingToWorktree:jt}),rn=X2({targets:ht,isRefreshing:Xe,loadFailed:Ye});return s.jsxs(Zt,{onOpenChange:af,children:[s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsxs(ms,{disabled:rs,className:"w-full [&>svg]:mr-1","data-session-worktree-submenu-trigger":U.id,children:[s.jsx(B,{name:"folder-shared",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.moveToWorktreeTargets")]})}),s.jsx(At,{side:"right",className:"max-w-72",children:e(jt?"sessions.sidebar.session.moveToWorktree.tooltipMoving":et?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltipTargets")})]}),s.jsxs(As,{className:"min-w-[220px]","data-session-worktree-submenu":U.id,children:[ht.map(os=>{const on=ft(os.metadata.path??null)??os.metadata.path,Cr=os.isPrimary?e("sessions.sidebar.session.moveToWorktree.main"):os.metadata.label||os.metadata.branch||os.metadata.name||os.metadata.path,js=os.isCurrent||os.metadata.worktreeStatus!=="ready";return s.jsxs(Pe,{disabled:js,title:os.metadata.path,"data-session-worktree-target":on,onClick:()=>{js||!Ge||Ji({kind:"existing",root:we,descendants:lt(n),sourceDirectory:Ge,destination:os.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:Cr}),os.isCurrent?s.jsx("span",{className:"sr-only",children:e("sessions.sidebar.session.moveToWorktree.current")}):null]}),os.isCurrent?s.jsx(B,{name:"check",className:"ml-2 h-3.5 w-3.5 flex-shrink-0 text-primary","aria-hidden":"true"}):null]},on)}),rn.refreshState==="loading"?s.jsx(Pe,{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,rn.refreshState==="error"?s.jsx(Pe,{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(_t,{}),s.jsxs(Pe,{disabled:rs,"data-session-worktree-new-action":"true",onClick:()=>{rs||!Ge||Ji({kind:"quick",root:we,descendants:lt(n),sourceDirectory:Ge,messages:Yi(e,{success:"sessions.sidebar.session.moveToWorktree.success",failure:"sessions.sidebar.session.moveToWorktree.failed"})})},className:"[&>svg]:mr-1",children:[s.jsx(B,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.newWorktree")]})]})]})})():null,Os?s.jsxs(Pe,{onClick:()=>Cs(!0),className:"[&>svg]:mr-1",children:[s.jsx(H2,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Ge&&!l?(()=>{const rs=[],rn=js=>{const Rs=ft(js??null);Rs&&!rs.includes(Rs)&&rs.push(Rs)};if(o&&!re){const js=qt.getState().projects.find(ir=>ir.id===o),Rs=ft(js?.path??null);rn(Rs),Rs&&(tt.getState().availableWorktreesByProject.get(Rs)??[]).forEach(ir=>rn(ir.path))}rn(ju(Ge)),rn(Ge);const os=rs.flatMap(js=>q(js).map(Rs=>({scope:js,folder:Rs}))),on=os.find(({scope:js,folder:Rs})=>Z(js,U.id)===Rs.id)??null,Cr=rs[0]??Ge;return s.jsxs(s.Fragment,{children:[s.jsx(_t,{}),s.jsxs(Zt,{children:[s.jsxs(ms,{className:"[&>svg]:mr-1",children:[s.jsx(B,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(As,{className:"min-w-[180px]",children:[os.length===0?s.jsx(Pe,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):os.map(({scope:js,folder:Rs})=>{const ir=on?.folder.id===Rs.id;return s.jsxs(Pe,{onClick:()=>{if(ir){le(js,U.id);return}on&&on.scope!==js&&le(on.scope,U.id),X(js,Rs.id,U.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:Rs.name}),ir?s.jsx(B,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},Rs.id)}),s.jsx(_t,{}),s.jsxs(Pe,{onClick:()=>{const js=E(Cr);js&&(Y.current=!0,on&&on.scope!==Cr&&le(on.scope,U.id),X(Cr,js.id,U.id))},children:[s.jsx(B,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),on?s.jsxs(Pe,{onClick:()=>{le(on.scope,U.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,re?null:s.jsxs(Pe,{disabled:!Ge,onClick:()=>{Ge&&te(Ge,{mode:"chat",dedupeKey:`session:${U.id}`,label:Gt,sessionTitleFallback:Gt})},className:"[&>svg]:mr-1",children:[s.jsx(B,{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")})]}),Se?s.jsxs(Pe,{disabled:!Ge,onClick:Es,className:"[&>svg]:mr-1",children:[s.jsx(B,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(_t,{}),l?null:s.jsxs(Pe,{className:"[&>svg]:mr-1",onClick:()=>O(U,{archivedBucket:l}),children:[s.jsx(B,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),l?s.jsxs(Pe,{className:"[&>svg]:mr-1",onClick:()=>W(U),children:[s.jsx(B,{name:"inbox-unarchive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.restore")]}):null,s.jsxs(Pe,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>O(U,{archivedBucket:l,hardDelete:!0}),children:[s.jsx(B,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),lf=s.jsx(Qs,{align:"end",className:"min-w-[180px]",finalFocus:()=>Y.current?(Y.current=!1,!1):!De.current,children:Xa({Item:Ut,Separator:zs,Sub:tg,SubTrigger:sg,SubContent:ng})}),cf=s.jsx(Ki,{children:s.jsx(Hi,{className:"app-region-no-drag z-50",children:s.jsx(Gi,{"data-slot":"dropdown-menu-content",finalFocus:()=>Y.current?(Y.current=!1,!1):!De.current,style:{color:"var(--surface-elevated-foreground)"},className:Ie(Ii,"min-w-[180px]"),children:Xa({Item:({className:Pe,..._t})=>s.jsx(Bu,{className:Ie(Ld,Pe),..._t}),Separator:({className:Pe,..._t})=>s.jsx(Ou,{className:Ie(_d,Pe),..._t}),Sub:Dx,SubTrigger:({className:Pe,children:_t,...Zt})=>s.jsxs(Ix,{className:Ie(eg,Pe),...Zt,children:[_t,s.jsx(B,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:Pe,children:_t,...Zt})=>s.jsx(Ki,{children:s.jsx(Hi,{className:"app-region-no-drag z-50",children:s.jsx(Gi,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:Ie(Ii,Pe),...Zt,children:_t})})})})})})});return s.jsxs(c.Fragment,{children:[s.jsx(i2,{sessionId:U.id,sessionDirectory:Ge??null,sessionTitle:Gt,children:s.jsxs(_u,{open:ds,onOpenChange:$s,onOpenChangeComplete:ws,children:[s.jsxs(Fu,{render:s.jsx("div",{"data-session-row":U.id,"data-session-scope":ut??"","data-session-archived":l?"1":"0","aria-current":rt?"page":void 0,onClick:nf,style:{paddingLeft:Fc+r*po},className:Ie("group relative my-0.5 flex cursor-pointer items-center rounded-md py-1 pr-1.5",(rt||Pt)&&"bg-interactive-selection text-interactive-selection-foreground",Pt&&"ring-1 ring-inset ring-border")}),children:[ys,Je,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onPointerDown:of,onPointerUp:Ya,onPointerCancel:Ya,onMouseDown:rf,onClick:Pe=>Qa(Pe),onDoubleClick:Pe=>{Pe.stopPropagation(),S(U.id,Gt)},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-ring text-foreground select-none transition-[padding]",ke&&"bg-interactive-hover/70",D?re?oe:ce:us?Q:oe),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",rt||Pt?"text-interactive-selection-foreground":He?"text-foreground":"text-foreground/80"),children:wo(Gt,h)}),!l&&Ge&&(A==="recent"||pe==="flat"&&n.worktree&&ft(n.worktree.path)!==ft(n.worktree.projectDirectory))?s.jsx(Wo,{directory:Ge,className:D?void 0:us?"mr-1":re?"group-hover:mr-1":"group-hover:mr-1 group-focus-within:mr-1"}):null,D?s.jsx("span",{className:"ml-2 inline-flex flex-shrink-0 items-center gap-1 typography-micro text-muted-foreground/75",children:Dt?s.jsx(ll,{sessionId:U.id,running:et}):s.jsxs(s.Fragment,{children:[Jt,Ae?s.jsx(B,{name:"git-branch",className:Ie("h-3 w-3",!z&&"text-muted-foreground/60"),style:z?{color:z}:void 0}):null,es]})}):Dt||Jt||Ae||A==="recent"?s.jsx("div",{className:Ie("relative ml-1 flex h-4 flex-shrink-0 items-center justify-end",us?"hidden":re?"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:Dt?s.jsx(ll,{sessionId:U.id,running:et,className:"typography-micro"}):s.jsxs(s.Fragment,{children:[Jt,Ae?s.jsx(B,{name:"git-branch",className:Ie("h-3 w-3",!z&&"text-muted-foreground/60"),style:z?{color:z}:void 0}):null,A==="recent"?s.jsx("span",{className:"flex-shrink-0 typography-micro leading-none text-muted-foreground/75 tabular-nums",children:es}):null]})})}):null,Ss>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",Tn),title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(B,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Ss})]}):null,qe>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",Tn),title:hs,"aria-label":hs,children:[s.jsx(B,{name:"question",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:qe})]}):null]})})}),re?null:s.jsx(At,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex min-w-44 flex-col gap-1.5 text-left text-xs",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{className:"min-w-0 truncate font-medium text-foreground",children:Gt}),s.jsx("span",{className:"flex-shrink-0 text-muted-foreground",title:ts,children:es})]}),Te?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(B,{name:"folder",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 truncate",children:Te})]}):null,Oe?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(B,{name:"git-branch",className:"h-3 w-3 flex-shrink-0",style:z?{color:z}:void 0}),s.jsx("span",{className:"min-w-0 truncate",children:Oe})]}):null,Ve&&Be?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(B,{name:"git-pull-request",className:"h-3 w-3 flex-shrink-0",style:z?{color:z}:void 0}),s.jsxs("span",{className:"min-w-0 truncate",style:z?{color:z}:void 0,children:["#",Ve.number," · ",Be]})]}):null]})})]})}),yt&&!F?s.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 z-10",children:yt}):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",us||D&&!re?"opacity-100":Ie("opacity-0",ye)),children:[_?s.jsx(ek,{archiveLabel:e("sessions.sidebar.bulkActions.archive"),deleteLabel:e("sessions.sidebar.bulkActions.delete"),buttonSizeClass:D?"h-6 w-6":"h-4 w-4",iconSizeClass:D?"h-3.5 w-3.5":"h-2.5 w-2.5",onPointerDown:ri,onMouseDown:Xm,onArchive:Jm,onDelete:Zm}):null,be?s.jsxs(Ct,{children:[s.jsx(Nt,{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-ring transition-opacity",D?"h-6 w-6":"h-4 w-4"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:ef,onMouseDown:tf,onClick:sf,onKeyDown:Pe=>Pe.stopPropagation(),children:s.jsx(B,{name:"external-link",className:Ie(D?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),s.jsx(At,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(Ys,{open:ss,onOpenChange:Vt,onOpenChangeComplete:ws,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-ring transition-opacity",D?"h-6 w-6 opacity-100":us?"h-4 w-4 opacity-100":Ie("h-4 w-4 opacity-0",ye)),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:kr,onMouseDown:no,onClick:vs,onKeyDown:Pe=>Pe.stopPropagation(),children:s.jsx(B,{name:"more-2",className:Ie(D?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),lf]})]})]}),cf]})}),$t&&Qt?M:null,s.jsx(Ds,{open:H,onOpenChange:V,children:s.jsxs(Is,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Xs,{children:[s.jsx(_s,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ls,{children:Zs===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Zs}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Zs})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:J,onChange:Pe=>ge(Pe.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(wn,{children:[s.jsx(dt,{type:"button",onClick:()=>V(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(dt,{type:"button",onClick:()=>{V(!1),Lt(J)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),Os?s.jsx(K2,{session:we,open:ns,onOpenChange:Cs}):null]},U.id)}const _c=t=>ft(t.session.directory??null),sk=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),nk=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},Lc=t=>t.menuOpenSessionId??nk(t),go=(t,e,n)=>e?n.has(t.node.session.id)?!0:Qn(t.node,e):!1,ma=(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(ma(t.children[l],e.children[l],n,r,i))return!0;return!1},rk=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return ma(t.node,e.node,t.expandedParents,e.expandedParents,i=>`${t.renderContext??"project"}:${n}:${i.session.id}`)||ma(t.node,e.node,t.expandedParents,e.expandedParents,i=>`${e.renderContext??"project"}:${r}:${i.session.id}`)},ok=(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,ik=(t,e)=>{if(t.node.session.id!==e.node.session.id||!ok(t.node.session,e.node.session)||!J2(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(_c(t.node)!==_c(e.node))return"nodeDirectory";if(!sk(t.secondaryMeta,e.secondaryMeta))return"secondaryMeta";if(t.pinnedSessionIds!==e.pinnedSessionIds&&Tm(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,t.groupDirectory,e.groupDirectory))return"pinnedSessionIds";if(t.expandedParents!==e.expandedParents&&rk(t,e))return"expandedParents";if(t.editingId!==e.editingId&&(go(t,t.editingId,t.subtreeContainsEditing)||go(e,e.editingId,e.subtreeContainsEditing)))return"editingId";if(t.editTitle!==e.editTitle&&(go(t,t.editingId,t.subtreeContainsEditing)||go(e,e.editingId,e.subtreeContainsEditing)))return"editTitle";if(t.copiedSessionId!==e.copiedSessionId&&(Qn(t.node,t.copiedSessionId)||Qn(e.node,e.copiedSessionId)))return"copiedSessionId";if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const r=Lc(t),i=Lc(e);if(Qn(t.node,r)||Qn(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"},ak=(t,e)=>{const n=ik(t,e);return n===null?!0:(sn(`ui.sidebar_session_node.props_changed.${n}`),!1)},lk=c.memo(tk,ak);function ck(t){return t.stopPropagation()}const dk=t=>{const{t:e}=vt(),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=Ne(te=>te.setSessionSwitcherOpen),a=tt(te=>te.setCurrentSession),u=tt(te=>te.updateSessionTitle),d=tt(te=>te.shareSession),h=tt(te=>te.unshareSession),f=tt(te=>te.deleteSession),p=tt(te=>te.deleteSessions),g=tt(te=>te.archiveSession),w=tt(te=>te.archiveSessions),v=tt(te=>te.unarchiveSession),{mobileVariant:y,allowReselect:m,onSessionSelected:x,isSessionSearchOpen:b,sessionSearchQuery:S,setSessionSearchQuery:C,setIsSessionSearchOpen:N,descendantIds:k,showDeletionDialog:R,setDeleteSessionConfirm:I,setEditingId:P,setEditTitle:T,setCopiedSessionId:E}=t;c.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]);const O=c.useCallback((te,re)=>{Ni("navigation.session_select"),Ne.getState().closeMainSurfaces();const Se=()=>{!b&&S.length===0||(C(""),N(!1))};if(y&&l(!1),te===tt.getState().currentSessionId){m&&x?.(te),Se();return}Ni("navigation.session_state_set"),a(te,re??null),x?.(te),Se()},[m,b,y,x,S,a,N,C,l]),W=c.useCallback((te,re)=>{P(te),T(re)},[T,P]),L=c.useCallback(async te=>{const re=r.current;if(!re)return;const Se=(te??i.current).trim();Se&&await u(re,Se),P(null),T("")},[T,P,u]),F=c.useCallback(()=>{P(null),T("")},[T,P]),D=c.useCallback(async(te,re)=>{try{return(await xn(te)).ok?(E(re),n.current&&clearTimeout(n.current),n.current=window.setTimeout(()=>{E(null),n.current=null},2e3),!0):!1}catch{return!1}},[E]),j=c.useCallback(async te=>{const re=await d(te.id);if(!re?.share?.url){Fe.error(e("sessions.sidebar.session.share.error"));return}const Se=await D(re.share.url,te.id);Fe[Se?"success":"warning"](e("sessions.sidebar.session.share.successTitle"),{description:e(Se?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")})},[D,d,e]),A=c.useCallback((te,re)=>{D(te,re).then(Se=>{Se||Fe.error(e("sessions.sidebar.session.share.copyUrlError"))})},[D,e]),M=c.useCallback(te=>{xn(te).then(re=>{if(re.ok){Fe.success(e("sessions.sidebar.session.copyId.success"));return}Fe.error(e("sessions.sidebar.session.copyId.error"))}).catch(()=>Fe.error(e("sessions.sidebar.session.copyId.error")))},[e]),G=c.useCallback(async te=>{await h(te)?Fe.success(e("sessions.sidebar.session.unshare.success")):Fe.error(e("sessions.sidebar.session.unshare.error"))},[e,h]),q=c.useCallback(async(te,re,Se)=>{const ue=re?.archivedBucket===!0||re?.hardDelete===!0,ye=Se?.descendantIds??k;await ch(ue?"delete":"archive",te,ye,{archiveSession:g,archiveSessions:w,deleteSession:f,deleteSessions:p},e)},[g,w,f,p,k,e]),Z=c.useCallback((te,re)=>{const Se=re?.archivedBucket===!0||re?.hardDelete===!0,ue=Nd(te.id,k,Se);if(!R||re?.skipConfirm===!0){q(te,re,{descendantIds:ue});return}I({session:te,descendantCount:ue.length,descendantIds:ue,archivedBucket:Se})},[k,q,I,R]),le=c.useCallback(async()=>{const te=o.current;if(!te)return;const{session:re,archivedBucket:Se,descendantIds:ue}=te;I(null),await q(re,{archivedBucket:Se},{descendantIds:ue})},[q,I]),X=c.useCallback(async te=>{await v(te.id)?Fe.success(e("sessions.sidebar.session.restore.success")):Fe.error(e("sessions.sidebar.session.restore.error"))},[e,v]);return c.useMemo(()=>({handleSessionSelect:O,handleSessionDoubleClick:W,handleSaveEdit:L,handleCancelEdit:F,handleShareSession:j,handleCopyShareUrl:A,handleCopySessionId:M,handleUnshareSession:G,handleDeleteSession:Z,handleRestoreSession:X,confirmDeleteSession:le}),[F,M,A,Z,X,L,W,O,j,G,le])};function uk(t){const e=nt.c(71),{t:n}=vt(),{value:r,setValue:i,showDeletionDialog:o,setShowDeletionDialog:l,onConfirm:a}=t;let u,d,h,f,p,g,w,v,y,m;if(e[0]!==i||e[1]!==n||e[2]!==r){const A=n("sessions.sidebar.session.untitled");f=Ds,y=!!r,e[13]!==i?(m=G=>{G||i(null)},e[13]=i,e[14]=m):m=e[14],h=Is,w=!1,v="max-w-sm gap-5",d=Xs;let M;e[15]!==n||e[16]!==r?.archivedBucket?(M=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=M):M=e[17],e[18]!==M?(g=s.jsx(_s,{children:M}),e[18]=M,e[19]=g):g=e[19],u=Ls,p=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||A,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||A,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||A,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||A,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||A}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||A}),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]=y,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],y=e[11],m=e[12];let x;e[20]!==u||e[21]!==p?(x=s.jsx(u,{children:p}),e[20]=u,e[21]=p,e[22]=x):x=e[22];let b;e[23]!==d||e[24]!==g||e[25]!==x?(b=s.jsxs(d,{children:[g,x]}),e[23]=d,e[24]=g,e[25]=x,e[26]=b):b=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 C=!o;let N;e[30]!==o?(N=o?s.jsx(B,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(B,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=o,e[31]=N):N=e[31];let k;e[32]!==n?(k=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=k):k=e[33];let R;e[34]!==N||e[35]!==k||e[36]!==S||e[37]!==C?(R=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-ring","aria-pressed":C,children:[N,k]}),e[34]=N,e[35]=k,e[36]=S,e[37]=C,e[38]=R):R=e[38];let I;e[39]!==i?(I=()=>i(null),e[39]=i,e[40]=I):I=e[40];let P;e[41]!==n?(P=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=P):P=e[42];let T;e[43]!==I||e[44]!==P?(T=s.jsx("button",{type:"button",onClick:I,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-ring",children:P}),e[43]=I,e[44]=P,e[45]=T):T=e[45];let E;e[46]!==a?(E=()=>{a()},e[46]=a,e[47]=E):E=e[47];let O;e[48]!==n||e[49]!==r?.archivedBucket?(O=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=O):O=e[50];let W;e[51]!==E||e[52]!==O?(W=s.jsx("button",{type:"button",onClick:E,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:O}),e[51]=E,e[52]=O,e[53]=W):W=e[53];let L;e[54]!==T||e[55]!==W?(L=s.jsxs("div",{className:"flex items-center gap-2",children:[T,W]}),e[54]=T,e[55]=W,e[56]=L):L=e[56];let F;e[57]!==R||e[58]!==L?(F=s.jsxs(wn,{className:"w-full sm:items-center sm:justify-between",children:[R,L]}),e[57]=R,e[58]=L,e[59]=F):F=e[59];let D;e[60]!==h||e[61]!==w||e[62]!==F||e[63]!==v||e[64]!==b?(D=s.jsxs(h,{showCloseButton:w,className:v,children:[b,F]}),e[60]=h,e[61]=w,e[62]=F,e[63]=v,e[64]=b,e[65]=D):D=e[65];let j;return e[66]!==f||e[67]!==D||e[68]!==y||e[69]!==m?(j=s.jsx(f,{open:y,onOpenChange:m,children:D}),e[66]=f,e[67]=D,e[68]=y,e[69]=m,e[70]=j):j=e[70],j}function mk(t){const e=nt.c(57),{t:n}=vt(),{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=j=>{j||i(null)},e[8]=i,e[9]=v):v=e[9];let y;e[10]!==f?(y=s.jsx(_s,{children:f}),e[10]=f,e[11]=y):y=e[11];let m;e[12]!==g?(m=s.jsx(Ls,{children:g}),e[12]=g,e[13]=m):m=e[13];let x;e[14]!==y||e[15]!==m?(x=s.jsxs(Xs,{children:[y,m]}),e[14]=y,e[15]=m,e[16]=x):x=e[16];let b;e[17]!==l||e[18]!==o?(b=()=>l(!o),e[17]=l,e[18]=o,e[19]=b):b=e[19];const S=!o;let C;e[20]!==o?(C=o?s.jsx(B,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(B,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=o,e[21]=C):C=e[21];let N;e[22]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=N):N=e[23];let k;e[24]!==N||e[25]!==b||e[26]!==S||e[27]!==C?(k=s.jsxs("button",{type:"button",onClick:b,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-ring","aria-pressed":S,children:[C,N]}),e[24]=N,e[25]=b,e[26]=S,e[27]=C,e[28]=k):k=e[28];let R;e[29]!==i?(R=()=>i(null),e[29]=i,e[30]=R):R=e[30];let I;e[31]!==n?(I=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=I):I=e[32];let P;e[33]!==R||e[34]!==I?(P=s.jsx("button",{type:"button",onClick:R,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:I}),e[33]=R,e[34]=I,e[35]=P):P=e[35];let T;e[36]!==a?(T=()=>{a()},e[36]=a,e[37]=T):T=e[37];let E;e[38]!==u||e[39]!==n?(E=n(u?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=u,e[39]=n,e[40]=E):E=e[40];let O;e[41]!==T||e[42]!==E?(O=s.jsx("button",{type:"button",onClick:T,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[41]=T,e[42]=E,e[43]=O):O=e[43];let W;e[44]!==P||e[45]!==O?(W=s.jsxs("div",{className:"flex items-center gap-2",children:[P,O]}),e[44]=P,e[45]=O,e[46]=W):W=e[46];let L;e[47]!==k||e[48]!==W?(L=s.jsxs(wn,{className:"w-full sm:items-center sm:justify-between",children:[k,W]}),e[47]=k,e[48]=W,e[49]=L):L=e[49];let F;e[50]!==L||e[51]!==x?(F=s.jsxs(Is,{showCloseButton:!1,className:"max-w-sm gap-5",children:[x,L]}),e[50]=L,e[51]=x,e[52]=F):F=e[52];let D;return e[53]!==w||e[54]!==F||e[55]!==v?(D=s.jsx(Ds,{open:w,onOpenChange:v,children:F}),e[53]=w,e[54]=F,e[55]=v,e[56]=D):D=e[56],D}function fk(t){const e=nt.c(36),{t:n}=vt(),{value:r,setValue:i,onConfirm:o}=t,l=!!r;let a;e[0]!==i?(a=C=>{C||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(_s,{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(Ls,{children:h}),e[9]=h,e[10]=f):f=e[10];let p;e[11]!==d||e[12]!==f?(p=s.jsxs(Xs,{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-ring",children:w}),e[18]=g,e[19]=w,e[20]=v):v=e[20];let y;e[21]!==n?(y=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=y):y=e[22];let m;e[23]!==o||e[24]!==y?(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:y}),e[23]=o,e[24]=y,e[25]=m):m=e[25];let x;e[26]!==m||e[27]!==v?(x=s.jsxs(wn,{children:[v,m]}),e[26]=m,e[27]=v,e[28]=x):x=e[28];let b;e[29]!==x||e[30]!==p?(b=s.jsxs(Is,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,x]}),e[29]=x,e[30]=p,e[31]=b):b=e[31];let S;return e[32]!==l||e[33]!==a||e[34]!==b?(S=s.jsx(Ds,{open:l,onOpenChange:a,children:b}),e[32]=l,e[33]=a,e[34]=b,e[35]=S):S=e[35],S}const hk=new Set;function Uo(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:y,editTitle:m,setEditTitle:x,toggleParent:b,openSidebarMenuKey:S,setOpenSidebarMenuKey:C,allowReselect:N,onSessionSelected:k,isSessionSearchOpen:R,sessionSearchQuery:I,setSessionSearchQuery:P,setIsSessionSearchOpen:T,deleteSessionConfirm:E,setDeleteSessionConfirm:O,startFolderRename:W,copiedSessionId:L,setCopiedSessionId:F,startSessionWorktreeMenuLoad:D,mobileVariant:j,alwaysShowActions:A}=t,M=r===void 0?0:r,G=l===void 0?!1:l,q=u===void 0?"project":u,Z=xs(bk),le=xs(xk),X=Ne(gk),te=Ne(pk);let re;if(e[0]!==n){re=[];const Ve=z=>z.children.forEach(pe=>{re.push(pe.session.id),Ve(pe)});Ve(n),e[0]=n,e[1]=re}else re=e[1];const Se=re.join(`
|
|
888
|
+
`);let ue;e[2]!==Se?(ue=Se?Se.split(`
|
|
889
|
+
`):[],e[2]=Se,e[3]=ue):ue=e[3];const ye=ue;let ve;e[4]!==Z||e[5]!==W||e[6]!==le?(ve=(Ve,z)=>{if(!Ve)return null;z&&xs.getState().collapsedFolderIds.has(z)&&le(z);const pe=Z(Ve,"New folder",z);return W(Ve,pe),pe},e[4]=Z,e[5]=W,e[6]=le,e[7]=ve):ve=e[7];const be=ve;let _;e[8]!==N||e[9]!==L||e[10]!==E||e[11]!==ye||e[12]!==m||e[13]!==v||e[14]!==R||e[15]!==j||e[16]!==k||e[17]!==I||e[18]!==F||e[19]!==O||e[20]!==x||e[21]!==y||e[22]!==T||e[23]!==P||e[24]!==X?(_={mobileVariant:j,allowReselect:N,onSessionSelected:k,isSessionSearchOpen:R,sessionSearchQuery:I,setSessionSearchQuery:P,setIsSessionSearchOpen:T,descendantIds:ye,showDeletionDialog:X,setDeleteSessionConfirm:O,deleteSessionConfirm:E,editingId:v,setEditingId:y,editTitle:m,setEditTitle:x,copiedSessionId:L,setCopiedSessionId:F},e[8]=N,e[9]=L,e[10]=E,e[11]=ye,e[12]=m,e[13]=v,e[14]=R,e[15]=j,e[16]=k,e[17]=I,e[18]=F,e[19]=O,e[20]=x,e[21]=y,e[22]=T,e[23]=P,e[24]=X,e[25]=_):_=e[25];const oe=dk(_),ce=d?.childRenderExtrasFor,Q=n.session.directory??i;let me;e[26]!==G||e[27]!==o||e[28]!==q||e[29]!==Q?(me={groupDirectory:Q,projectId:o,archivedBucket:G,renderContext:q},e[26]=G,e[27]=o,e[28]=q,e[29]=Q,e[30]=me):me=e[30];const ke=me,fe=oe.handleSaveEdit,De=oe.handleCancelEdit,je=oe.handleSessionSelect,Y=oe.handleSessionDoubleClick,Re=oe.handleShareSession,Ce=oe.handleCopyShareUrl,Me=oe.handleCopySessionId,ae=oe.handleUnshareSession,ee=oe.handleDeleteSession,K=oe.handleRestoreSession,$=d?.subtreeContainsEditing??hk,ne=d?.menuOpenSessionId??null,U=d?.nodeStructureKey??"",we=d?.relativeTimeTick;let he;if(e[31]!==N||e[32]!==A||e[33]!==ke||e[34]!==ce||e[35]!==L||e[36]!==E||e[37]!==M||e[38]!==m||e[39]!==v||e[40]!==f||e[41]!==p||e[42]!==R||e[43]!==j||e[44]!==n.children||e[45]!==g||e[46]!==w||e[47]!==k||e[48]!==S||e[49]!==h||e[50]!==I||e[51]!==F||e[52]!==O||e[53]!==x||e[54]!==y||e[55]!==T||e[56]!==C||e[57]!==P||e[58]!==W||e[59]!==D||e[60]!==b){let Ve;e[62]!==N||e[63]!==A||e[64]!==ke||e[65]!==ce||e[66]!==L||e[67]!==E||e[68]!==M||e[69]!==m||e[70]!==v||e[71]!==f||e[72]!==p||e[73]!==R||e[74]!==j||e[75]!==g||e[76]!==w||e[77]!==k||e[78]!==S||e[79]!==h||e[80]!==I||e[81]!==F||e[82]!==O||e[83]!==x||e[84]!==y||e[85]!==T||e[86]!==C||e[87]!==P||e[88]!==W||e[89]!==D||e[90]!==b?(Ve=z=>s.jsx(Uo,{node:z,pinnedSessionIds:h,expandedParents:f,hasSessionSearchQuery:p,normalizedSessionSearchQuery:g,notifyOnSubtasks:w,editingId:v,setEditingId:y,editTitle:m,copiedSessionId:L,setEditTitle:x,toggleParent:b,openSidebarMenuKey:S,setOpenSidebarMenuKey:C,allowReselect:N,onSessionSelected:k,isSessionSearchOpen:R,sessionSearchQuery:I,setSessionSearchQuery:P,setIsSessionSearchOpen:T,deleteSessionConfirm:E,setDeleteSessionConfirm:O,startFolderRename:W,setCopiedSessionId:F,startSessionWorktreeMenuLoad:D,mobileVariant:j,alwaysShowActions:A,depth:M+1,...ke,renderExtras:ce?.(z)},z.session.id),e[62]=N,e[63]=A,e[64]=ke,e[65]=ce,e[66]=L,e[67]=E,e[68]=M,e[69]=m,e[70]=v,e[71]=f,e[72]=p,e[73]=R,e[74]=j,e[75]=g,e[76]=w,e[77]=k,e[78]=S,e[79]=h,e[80]=I,e[81]=F,e[82]=O,e[83]=x,e[84]=y,e[85]=T,e[86]=C,e[87]=P,e[88]=W,e[89]=D,e[90]=b,e[91]=Ve):Ve=e[91],he=n.children.map(Ve),e[31]=N,e[32]=A,e[33]=ke,e[34]=ce,e[35]=L,e[36]=E,e[37]=M,e[38]=m,e[39]=v,e[40]=f,e[41]=p,e[42]=R,e[43]=j,e[44]=n.children,e[45]=g,e[46]=w,e[47]=k,e[48]=S,e[49]=h,e[50]=I,e[51]=F,e[52]=O,e[53]=x,e[54]=y,e[55]=T,e[56]=C,e[57]=P,e[58]=W,e[59]=D,e[60]=b,e[61]=he}else he=e[61];let Te;e[92]!==A||e[93]!==G||e[94]!==L||e[95]!==be||e[96]!==M||e[97]!==m||e[98]!==v||e[99]!==f||e[100]!==i||e[101]!==p||e[102]!==j||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]!==oe.handleCancelEdit||e[112]!==oe.handleCopySessionId||e[113]!==oe.handleCopyShareUrl||e[114]!==oe.handleDeleteSession||e[115]!==oe.handleRestoreSession||e[116]!==oe.handleSaveEdit||e[117]!==oe.handleSessionDoubleClick||e[118]!==oe.handleSessionSelect||e[119]!==oe.handleShareSession||e[120]!==oe.handleUnshareSession||e[121]!==x||e[122]!==y||e[123]!==C||e[124]!==D||e[125]!==$||e[126]!==ne||e[127]!==U||e[128]!==we||e[129]!==he||e[130]!==b?(Te=s.jsx(lk,{expandedParents:f,hasSessionSearchQuery:p,normalizedSessionSearchQuery:g,notifyOnSubtasks:w,editingId:v,setEditingId:y,editTitle:m,setEditTitle:x,handleSaveEdit:fe,handleCancelEdit:De,toggleParent:b,handleSessionSelect:je,handleSessionDoubleClick:Y,handleShareSession:Re,copiedSessionId:L,handleCopyShareUrl:Ce,handleCopySessionId:Me,handleUnshareSession:ae,openSidebarMenuKey:S,setOpenSidebarMenuKey:C,createFolderAndStartRename:be,handleDeleteSession:ee,handleRestoreSession:K,startSessionWorktreeMenuLoad:D,mobileVariant:j,alwaysShowActions:A,pinnedSessionIds:h,node:n,depth:M,groupDirectory:i,projectId:o,archivedBucket:G,secondaryMeta:a,renderContext:q,subtreeContainsEditing:$,menuOpenSessionId:ne,nodeStructureKey:U,relativeTimeTick:we,children:he}),e[92]=A,e[93]=G,e[94]=L,e[95]=be,e[96]=M,e[97]=m,e[98]=v,e[99]=f,e[100]=i,e[101]=p,e[102]=j,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]=oe.handleCancelEdit,e[112]=oe.handleCopySessionId,e[113]=oe.handleCopyShareUrl,e[114]=oe.handleDeleteSession,e[115]=oe.handleRestoreSession,e[116]=oe.handleSaveEdit,e[117]=oe.handleSessionDoubleClick,e[118]=oe.handleSessionSelect,e[119]=oe.handleShareSession,e[120]=oe.handleUnshareSession,e[121]=x,e[122]=y,e[123]=C,e[124]=D,e[125]=$,e[126]=ne,e[127]=U,e[128]=we,e[129]=he,e[130]=b,e[131]=Te):Te=e[131];let Oe;e[132]!==E||e[133]!==n.session.id||e[134]!==oe.confirmDeleteSession||e[135]!==O||e[136]!==te||e[137]!==X?(Oe=E?.session.id===n.session.id?s.jsx(uk,{value:E,setValue:O,showDeletionDialog:X,setShowDeletionDialog:te,onConfirm:oe.confirmDeleteSession}):null,e[132]=E,e[133]=n.session.id,e[134]=oe.confirmDeleteSession,e[135]=O,e[136]=te,e[137]=X,e[138]=Oe):Oe=e[138];let _e;return e[139]!==Te||e[140]!==Oe?(_e=s.jsxs(s.Fragment,{children:[Te,Oe]}),e[139]=Te,e[140]=Oe,e[141]=_e):_e=e[141],_e}function pk(t){return t.setShowDeletionDialog}function gk(t){return t.showDeletionDialog}function xk(t){return t.toggleFolderCollapse}function bk(t){return t.createFolder}const yk=50,wk=28,$c=[],Sk=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=Dm(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},Er=(t,e)=>e?t.sessions.some(n=>Qn(n,e)):!1,vk=(t,e,n)=>t.sessions.some(r=>Tm(r,r,e,n,t.directory,t.directory)),jk=(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)},kk=(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)},Ck=(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&&vk(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.sessionOrderIndex!==e.sessionOrderIndex&&jk(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.expandedParents!==e.expandedParents&&kk(e.group,t.expandedParents,e.expandedParents)||t.editingId!==e.editingId&&(Er(e.group,t.editingId)||Er(e.group,e.editingId))||t.editTitle!==e.editTitle&&Er(e.group,e.editingId)||t.copiedSessionId!==e.copiedSessionId&&(Er(e.group,t.copiedSessionId)||Er(e.group,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=e.group.isArchivedBucket===!0,r=Xr(e.group.sessions,t.openSidebarMenuKey,"project",n),i=Xr(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??ft(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 Nk(t){const{t:e}=vt(),{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:y,activeProjectId:m,setActiveProjectIdOnly:x,setSessionSwitcherOpen:b,openNewSessionDraft:S,pinnedSessionIds:C,sessionOrderIndex:N,notifyOnSubtasks:k,onToggleCollapsedGroup:R,dragHandleProps:I,compactBodyPadding:P=!1,scrollContainerRef:T,expandedParents:E,editingId:O,openSidebarMenuKey:W,editTitle:L,copiedSessionId:F,folderRename:D,setFolderRenameDraft:j,clearFolderRename:A}=t,M=xs(Le=>Le.toggleFolderCollapse),G=xs(Le=>Le.renameFolder),q=xs(Le=>Le.deleteFolder),Z=xs(Le=>Le.addSessionToFolder),le=Ne(Le=>Le.showDeletionDialog),[X,te]=c.useState(null),re=c.useCallback((Le,qe)=>{const ot=N.get(Le.session.id),it=N.get(qe.session.id);if(ot!==void 0||it!==void 0){if(ot===void 0)return 1;if(it===void 0)return-1;if(ot!==it)return ot-it}return ku(Le.session,qe.session,C,uu)},[C,N]),Se=l?u.get(n):null,ue=l?!1:f.has(r),ye=c.useMemo(()=>{if(n.isMain||n.isArchivedBucket||o)return null;const Le=ft(n.directory??null),qe=n.branch?.trim();return Le&&qe?Yo(Le,qe):null},[n.branch,n.directory,n.isArchivedBucket,n.isMain,o]),ve=yu(ye),be=ve?`var(--pr-${ve.visualState})`:void 0,_=Ba(),oe=c.useMemo(()=>{const Le=n.folderScopes?.map(qe=>ft(qe.directory))??[ft(n.directory??null)];return[...new Set(Le.filter(qe=>!!qe))]},[n.directory,n.folderScopes]);c.useSyncExternalStore(c.useCallback(Le=>oe.length>0?_.subscribeBootstrap(Le):()=>{},[oe.length,_]),c.useCallback(()=>oe.map(Le=>`${Le}\0${_.getBootstrapState(Le)??""}\0${_.getBootstrapFailure(Le)??""}\0${_.getInitializationState(Le)??""}\0${_.getInitializationFailure(Le)??""}`).join(""),[oe,_]),c.useCallback(()=>"",[]));const ce=oe.some(Le=>{const qe=_.getBootstrapState(Le);return qe==="queued"||qe==="running"}),Q=oe.find(Le=>_.getBootstrapState(Le)==="failed"||_.getInitializationState(Le)==="failed")??null,me=Q!==null&&_.getBootstrapState(Q)==="failed",ke=Q?me?_.getBootstrapFailure(Q):_.getInitializationFailure(Q):void 0,fe=ke==="os-permission"&&Tf(),[De,je]=c.useState(!1),Y=c.useCallback(()=>{Q&&_.requestBootstrap({directory:Q,priority:ue?"visible":"expanded",reason:n.isMain?"project-expanded":"worktree-expanded",force:!0})},[_,Q,n.isMain,ue]),Re=c.useCallback(async()=>{if(!(!Q||!fe||De)){je(!0);try{(await Ef(Q)).success&&Y()}finally{je(!1)}}},[fe,Q,De,Y]),Ce=h??(p?10:5),Me=Math.max(Ce,d??Ce),ae=l?Se?.groupMatches===!0:!1,ee=l,K=c.useMemo(()=>[...ee?Se?.filteredNodes??[]:n.sessions].sort(re),[re,n.sessions,Se?.filteredNodes,ee]),$=n.folderScopeKey??ft(n.directory??null),ne=c.useMemo(()=>n.folderScopes&&n.folderScopes.length>0?n.folderScopes:$?[{scopeKey:$,directory:n.directory??null}]:[],[$,n.directory,n.folderScopes]),U=xs(sr(c.useCallback(Le=>ne.map(({scopeKey:qe})=>Le.foldersMap[qe]??$c),[ne]))),we=c.useMemo(()=>ne.flatMap(({scopeKey:Le,directory:qe},ot)=>(U[ot]??$c).map(He=>({folder:He,scopeKey:Le,scopeDirectory:qe}))),[U,ne]),he=xs(sr(c.useCallback(Le=>new Set(U.flatMap(qe=>qe.filter(ot=>Le.collapsedFolderIds.has(ot.id)).map(ot=>ot.id))),[U]))),Te=c.useMemo(()=>{const Le=new Map,qe=ot=>{ot.forEach(it=>{Le.set(it.session.id,it),it.children.length>0&&qe(it.children)})};return qe(K),Le},[K]),Oe=c.useMemo(()=>we.map(({folder:Le,scopeKey:qe,scopeDirectory:ot})=>{const it=m2(Le.sessionIds,Te).sort(re);return{folder:Le,scopeKey:qe,scopeDirectory:ot,nodes:it}}),[we,Te,re]),_e=c.useMemo(()=>{const Le=h2(Oe.map(({folder:qe,nodes:ot})=>({id:qe.id,name:qe.name,parentId:qe.parentId,nodeCount:ot.length})),{archivedBucket:n.isArchivedBucket===!0,searchQuery:l?a:""});return Oe.filter(({folder:qe})=>Le.has(qe.id))},[Oe,n.isArchivedBucket,l,a]),Ve=O,z=W,pe=E,Ae=c.useMemo(()=>new Set(_e.flatMap(Le=>Le.folder.sessionIds)),[_e]),Be=c.useMemo(()=>K.filter(Le=>!Ae.has(Le.session.id)),[K,Ae]),rt=c.useMemo(()=>{const Le=new Map(_e.map(qe=>[qe.folder.id,qe]));return f2(_e.map(qe=>qe.folder)).map(qe=>Le.get(qe.id)).filter(qe=>!!qe)},[_e]),Ge=c.useMemo(()=>{const Le=new Map;return _e.forEach(qe=>{if(!qe.folder.parentId)return;const ot=Le.get(qe.folder.parentId)??[];ot.push(qe),Le.set(qe.folder.parentId,ot)}),Le},[_e]),ut=c.useMemo(()=>{const Le=new Map(_e.map(it=>[it.folder.id,it])),qe=new Map,ot=(it,He)=>{const Bt=qe.get(it);if(Bt!==void 0)return Bt;if(He.has(it))return[];He.add(it);const ts=Le.get(it),es=ts?[...ts.nodes]:[];for(const ss of Ge.get(it)??[])es.push(...ot(ss.folder.id,He));return qe.set(it,es),es};return _e.forEach(({folder:it})=>ot(it.id,new Set)),qe},[_e,Ge]),at="project",wt=c.useMemo(()=>{const Le=new Set;return la(K,Ve,Le),_e.forEach(({nodes:qe})=>{la(qe,Ve,Le)}),Le},[K,_e,Ve]),pt=c.useMemo(()=>{if(!z)return null;const Le=Xr(K,z,at,!!n.isArchivedBucket);if(Le)return Le;for(const{nodes:qe}of _e){const ot=Xr(qe,z,at,!!n.isArchivedBucket);if(ot)return ot}return null},[z,K,_e,n.isArchivedBucket]),It=c.useCallback(Le=>{const qe=new WeakMap,ot=it=>{qe.set(it,zo(it));for(const He of it.children)ot(He)};return Le.forEach(ot),qe},[]),Pt=c.useMemo(()=>It(K),[It,K]),Rt=c.useMemo(()=>{const Le=new WeakMap;return _e.forEach(({nodes:qe})=>{qe.forEach(ot=>Le.set(ot,zo(ot)))}),Le},[_e]),de=c.useCallback(Le=>Pt.get(Le)??Rt.get(Le)??"",[Pt,Rt]),We=c.useCallback(Le=>({subtreeContainsEditing:wt,menuOpenSessionId:pt,nodeStructureKey:de(Le)}),[wt,pt,de]),lt=Be.length,H=n.isArchivedBucket||l?Be:Be.slice(0,Me),V=lt-H.length,J=!n.isArchivedBucket&&!l&<>Ce&&V===0,ge=n.isArchivedBucket===!0&&!l&&H.length>=yk,Ee=n.isArchivedBucket?"archived":"active",$e=ge&&H.some(Le=>{if(Le.children.length===0)return!1;const qe=`project:${Ee}:${Le.session.id}`;return pe.has(qe)}),st=c.useRef(null),[Ze,et]=c.useState(null),[Ue,jt]=c.useState(0),[,ze]=c.useState(0);c.useEffect(()=>{if(!ge)return;const Le=st.current;if(!Le||!globalThis.ResizeObserver)return;const qe=new ResizeObserver(()=>ze(ot=>ot+1));return qe.observe(Le),()=>qe.disconnect()},[ge]),c.useLayoutEffect(()=>{if(!ge){Ze!==null&&et(null),Ue!==0&&jt(0);return}const Le=st.current;if(!Le)return;let qe=Ze;const ot=T?.current??null;if(ot&&ot.contains(Le)){if(qe=ot,qe!==Ze){et(qe);return}}else if(!qe||!qe.contains(Le)){let He=Le.parentElement;for(;He;){const Bt=window.getComputedStyle(He);if(Bt.overflowY==="auto"||Bt.overflowY==="scroll"){qe=He;break}He=He.parentElement}if(qe!==Ze){et(qe);return}}if(!qe)return;const it=Le.getBoundingClientRect().top-qe.getBoundingClientRect().top+qe.scrollTop;jt(He=>Math.abs(He-it)<1?He:it)});const xe=ge&&Ze!==null,bt=$x({count:H.length,enabled:xe,getScrollElement:()=>Ze,initialOffset:()=>Ze?.scrollTop??0,estimateSize:()=>wk,overscan:$e?20:8,scrollMargin:Ue,getItemKey:Le=>H[Le]?.session.id??Le}),ht=c.useCallback(Le=>{const qe=[],ot=it=>{it.forEach(He=>{qe.push(He.session),He.children.length>0&&ot(He.children)})};return ot(Le),qe},[]),kt=c.useMemo(()=>ht(K),[ht,K]),Xe=c.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const Le=new Map,qe=new Map;for(const{folder:it}of _e){if(!it.parentId)continue;const He=qe.get(it.parentId)??[];He.push(it.id),qe.set(it.parentId,He)}const ot=(it,He)=>{if(He.has(it))return[];He.add(it);const Bt=_e.find(({folder:ss})=>ss.id===it),ts=Bt?ht(Bt.nodes):[],es=qe.get(it)??[];for(const ss of es)ts.push(...ot(ss,He));return ts};for(const{folder:it}of _e)Le.set(it.id,ot(it.id,new Set));return Le},[_e,ht,n.isArchivedBucket]);if(l&&!ae&&rt.length===0&&Be.length===0)return null;const Ke=!n.isMain&&!!n.branch,Ye=n.branch&&rg(n.branch,n.label)?{label:n.branch}:null,gt=ue?s.jsx(Gj,{nodes:K,includeUnreadSubtasks:k}):null,Mt=(Le,qe)=>{const{folder:ot,scopeKey:it,scopeDirectory:He,nodes:Bt}=Le,ts=Xe.get(ot.id)??[],es=D?.folderId===ot.id&&D?.scopeKey===it,ss=l?!1:he.has(ot.id),ds=Js=>s.jsx(a2,{folderId:ot.id,children:(us,Os)=>s.jsx(Qj,{folder:ot,displayName:qe,sessions:Bt,isCollapsed:ss,collapsedActivityState:Js,onToggle:()=>M(ot.id),onRename:ns=>{G(it,ot.id,ns)},onDelete:()=>{if(n.isArchivedBucket){bn.requestDelete({sessions:ts,mode:"session"});return}if(!le){q(it,ot.id);return}const ns=_e.filter(({folder:Zs})=>Zs.parentId===ot.id).length,Cs=Bt.length;te({scopeKey:it,folderId:ot.id,folderName:ot.name,subFolderCount:ns,sessionCount:Cs})},groupDirectory:He??n.directory,projectId:i,mobileVariant:v,alwaysShowActions:y,isRenaming:es,renameDraft:es?D?.draft:void 0,onRenameDraftChange:j,onRenameSave:()=>{const ns=D?.draft.trim()??"";ns&&G(it,ot.id,ns),A()},onRenameCancel:A,droppableRef:us,isDropTarget:Os,depth:0,onNewSession:()=>{i&&i!==m&&x(i),v&&b(!1),S({selectedProjectId:i,directoryOverride:He??n.directory,targetFolderId:ot.id,target:n.draftTarget})},hideActions:!1,archivedBucket:n.isArchivedBucket===!0,children:Bt.map(ns=>s.jsx(Uo,{node:ns,pinnedSessionIds:C,expandedParents:E,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,notifyOnSubtasks:k,editingId:O,editTitle:L,copiedSessionId:F,openSidebarMenuKey:W,mobileVariant:v,alwaysShowActions:y,groupDirectory:He??n.directory,projectId:i,archivedBucket:n.isArchivedBucket===!0,renderExtras:{subtreeContainsEditing:wt,menuOpenSessionId:pt,nodeStructureKey:de(ns),childRenderExtrasFor:We},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},ns.session.id))})},ot.id);return ss?s.jsx(Sk,{nodes:ut.get(ot.id)??Bt,includeUnreadSubtasks:k,children:ds},ot.id):ds(null)},xt=()=>{const Le=new Map;for(const He of _e){const Bt=He.folder.parentId;if(!Bt)continue;const ts=Le.get(Bt);ts?ts.push(He):Le.set(Bt,[He])}const qe=[],ot=new Set,it=(He,Bt)=>{if(ot.has(He.folder.id))return;ot.add(He.folder.id);const ts=Bt?`${Bt} / ${He.folder.name}`:He.folder.name;qe.push(Mt(He,ts)),!(!l&&he.has(He.folder.id))&&(Le.get(He.folder.id)??[]).forEach(ss=>it(ss,ts))};return rt.forEach(He=>it(He,"")),qe},St=!!(!n.isMain&&n.worktree),Tt=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(B,{name:"alert",className:"h-3 w-3"})}):null,Jt=y?St?"pr-14":"pr-7":St?"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",Gt=Q?s.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5",children:[e(ke==="os-permission"?"sessions.sidebar.group.empty.permissionDenied":me?"sessions.sidebar.group.empty.loadFailed":"sessions.sidebar.group.empty.initializationFailed"),fe?s.jsx(dt,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",disabled:De,onClick:()=>{Re()},children:e("sessions.sidebar.group.empty.grantAccess")}):null,s.jsx(dt,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",onClick:Y,children:e("sessions.sidebar.group.empty.retry")})]}):null,$t=Le=>s.jsx(Uo,{node:Le,pinnedSessionIds:C,expandedParents:E,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,notifyOnSubtasks:k,editingId:O,editTitle:L,copiedSessionId:F,openSidebarMenuKey:W,mobileVariant:v,alwaysShowActions:y,groupDirectory:n.directory,projectId:i,archivedBucket:n.isArchivedBucket===!0,renderExtras:{subtreeContainsEditing:wt,menuOpenSessionId:pt,nodeStructureKey:de(Le),childRenderExtrasFor:We},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},Le.session.id),Kt=s.jsxs(l2,{scopeKey:ne[0]?.scopeKey??$,hasFolders:_e.length>0,onSessionDroppedOnFolder:(Le,qe)=>{const ot=_e.find(({folder:He})=>He.id===qe);if(!ot)return;const it=xs.getState();for(const{scopeKey:He}of ne)He!==ot.scopeKey&&it.getSessionFolderId(He,Le)&&it.removeSessionFromFolder(He,Le);Z(ot.scopeKey,qe,Le)},children:[xt(),ge?s.jsx("div",{ref:st,children:xe?s.jsx("div",{style:{height:bt.getTotalSize(),position:"relative"},children:bt.getVirtualItems().map(Le=>{const qe=H[Le.index];return qe?s.jsx("div",{"data-index":Le.index,ref:bt.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Le.start-Ue}px)`},children:$t(qe)},qe.session.id):null})}):H.map($t)}):H.map($t),lt===0&&_e.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"):ce?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(B,{name:"loader-4",className:"size-3 animate-spin"}),e("sessions.sidebar.group.empty.loadingSessions")]}):Gt||(n.emptyMessage??e("sessions.sidebar.group.empty.noSessionsInWorkspace"))}):null,lt>0&&Gt?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-status-error",children:Gt}):null,V>0?s.jsx("button",{type:"button",onClick:()=>g(r,H.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,J?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]}),Ht="pb-2",Qt=s.jsx(fk,{value:X,setValue:te,onConfirm:()=>{const Le=X;Le&&(q(Le.scopeKey,Le.folderId),te(null))}});return o?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:Ie("oc-group-body",Ht),children:Kt})}),Qt]}):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:()=>R(r),role:"button",tabIndex:0,onKeyDown:Le=>{(Le.key==="Enter"||Le.key===" ")&&(Le.preventDefault(),R(r))},"aria-label":ue?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!ue,children:[s.jsxs("div",{ref:I?.setActivatorNodeRef,className:Ie("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-1.5 transition-[padding]",Jt),...I?.listeners??{},children:[s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"typography-ui-label font-normal truncate text-foreground/92",children: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(B,{name:"archive",className:Ie("h-3.5 w-3.5 shrink-0 text-muted-foreground",y?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:Ie("text-muted-foreground h-3.5 w-3.5 items-center justify-center",y?"inline-flex":"hidden group-hover/gh:inline-flex"),children:ue?s.jsx(B,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(B,{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)}),Tt,gt]}):!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(B,{name:"git-branch",className:Ie("h-3.5 w-3.5 shrink-0",!be&&"text-muted-foreground",y?"hidden":"group-hover/gh:hidden"),style:be?{color:be}:void 0}),s.jsx("span",{className:Ie("text-muted-foreground h-3.5 w-3.5 items-center justify-center",y?"inline-flex":"hidden group-hover/gh:inline-flex"),children:ue?s.jsx(B,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(B,{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)}),Tt,gt,ve?s.jsxs("span",{className:"ml-auto flex-shrink-0 text-[0.72rem] font-medium leading-none",style:be?{color:be}:void 0,children:["#",ve.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)}),gt]})}),Ke&&Ye?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(B,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(B,{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:Ye.label})]}):null]}),!n.isArchivedBucket&&n.directory?s.jsx(Wo,{directory:n.directory,className:"self-center"}):null]}),n.isArchivedBucket&&kt.length>0?s.jsx("div",{className:Ie("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",y?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Le=>{Le.stopPropagation(),bn.requestDelete({sessions:kt,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(B,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:Ie("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",y?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Le=>{Le.stopPropagation(),bn.requestDelete({sessions:kt,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(B,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:Ie("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",y?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Le=>{Le.stopPropagation(),i&&i!==m&&x(i),v&&b(!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-ring","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(B,{name:"add",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),ue?null:s.jsx("div",{className:Ie("oc-group-body",Ht),children:Kt})]}),Qt]})}const No=c.memo(Nk,Ck),Ak=(t,e,n)=>e?t.filter(r=>r.project.id===n):t,Pk=t=>t?"top-content":"empty-state",Dk=(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}))},Wc=(t,e)=>Oa(t.label?.trim()||Ln(t.normalizedPath,e)||t.normalizedPath);function Ik(t){const e=nt.c(49);sn("ui.sidebar_projects_list.render");const{t:n}=vt(),{model:r,view:i,actions:o}=t,l=r.state.editingId!==null,[a,u]=c.useState(!1);let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={activationConstraint:{distance:8}},e[0]=d):d=e[0];let h;e[1]===Symbol.for("react.memo_cache_sentinel")?(h={coordinateGetter:Px},e[1]=h):h=e[1];const f=qr(_n(zi,d),_n(Nx,h));let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p={activationConstraint:{distance:8}},e[2]=p):p=e[2];const g=qr(_n(zi,p)),w=c.useRef(null);let v,y,m,x,b,S,C,N,k,R,I,P,T,E;if(e[3]!==o||e[4]!==g||e[5]!==l||e[6]!==a||e[7]!==r||e[8]!==f||e[9]!==n||e[10]!==i){const F=Ak(r.sectionsForRender,r.singleProjectMode,r.singleProjectId);let D;if(e[25]!==r.projectSections||e[26]!==i.homeDirectory){let A;e[28]!==i.homeDirectory?(A=M=>({id:M.project.id,projectLabel:Wc(M.project,i.homeDirectory),projectDescription:Gr(M.project.normalizedPath,i.homeDirectory),projectIcon:M.project.icon,projectColor:M.project.color,projectIconImage:M.project.iconImage,projectIconBackground:M.project.iconBackground}),e[28]=i.homeDirectory,e[29]=A):A=e[29],D=r.projectSections.map(A),e[25]=r.projectSections,e[26]=i.homeDirectory,e[27]=D}else D=e[27];const j=D;C="relative flex min-h-0 flex-1",y=Mj,m=i.stickyZoneHeaders,x=a,b=F.map(Ok).join(":"),S=w,v=Sn,N=w,k=!0,R=!0,I=96,P="flex-1 min-h-0",T="oc-sidebar-scroller space-y-1.5 pb-1 pl-2.5 pr-2 [overflow-anchor:none]",E=r.projectSections.length===0?s.jsxs(s.Fragment,{children:[r.topContent,r.emptyState]}):r.sectionsForRender.length===0?Pk(r.topContentHasSearchMatches===!0)==="top-content"?r.topContent:r.searchEmptyState:s.jsxs(s.Fragment,{children:[r.topContent,i.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const A=F.find(G=>G.project.id===r.activeProjectId)??F[0];if(!A)return i.hasSessionSearchQuery?r.searchEmptyState:r.emptyState;const M=Dk(A);return M.length?M.map(G=>{const{group:q,groupKey:Z,projectId:le,hideGroupLabel:X}=G;return s.jsx(c.Fragment,{children:s.jsx(No,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:q,groupKey:Z,projectId:le,hideGroupLabel:X,visibleSessionCount:r.state.visibleSessionCountByGroup.get(Z),compactBodyPadding:!0,scrollContainerRef:w})},Z)}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})()}):s.jsxs(Qr,{sensors:f,collisionDetection:Yr,onDragStart:()=>u(!0),onDragCancel:()=>u(!1),onDragEnd:A=>{if(u(!1),l||i.projectSortOrder!=="manual")return;const{active:M,over:G}=A;if(!G||M.id===G.id)return;const q=r.sectionsForRender.findIndex(le=>le.project.id===M.id),Z=r.sectionsForRender.findIndex(le=>le.project.id===G.id);q===-1||Z===-1||q===Z||o.reorderProjects(q,Z)},children:[s.jsx(Mo,{items:F.map(Mk),strategy:Ui,children:F.map(A=>{const M=A.project,G=M.id,q=Wc(M,i.homeDirectory),Z=Gr(M.normalizedPath,i.homeDirectory),le=r.singleProjectMode?!1:i.collapsedProjects.has(G),X=r.projectRepoStatus.get(G);return s.jsx(Lj,{id:G,disabled:r.singleProjectMode||i.projectSortOrder!=="manual",projectLabel:q,projectDescription:Z,projectDirectory:M.normalizedPath,projectIcon:M.icon,projectColor:M.color,projectIconImage:M.iconImage,projectIconBackground:M.iconBackground,isCollapsed:le,isRepo:!!X,hideDirectoryControls:i.hideDirectoryControls,mobileVariant:i.mobileVariant,alwaysShowActions:i.alwaysShowActions,statusIndicator:le?o.renderProjectStatusIndicator?.(G,A.groups):null,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,projectPickerOptions:r.singleProjectMode?j:void 0,onProjectSelect:r.singleProjectMode?o.setSingleProjectId:void 0,onToggle:()=>{r.singleProjectMode||o.toggleProject(G)},onNewSession:()=>{G!==r.activeProjectId&&o.setActiveProjectIdOnly(G),i.mobileVariant&&o.setSessionSwitcherOpen(!1),o.openNewSessionDraft({selectedProjectId:G,directoryOverride:M.normalizedPath})},onNewWorktreeSession:()=>{G!==r.activeProjectId&&o.setActiveProjectIdOnly(G),o.openNewWorktreeDialog()},onManageWorktrees:()=>o.openWorktreesPage(G),onRenameStart:()=>o.openProjectEditDialog(G),onClose:()=>o.removeProject(G),showCreateButtons:!0,children:le?null:s.jsx("div",{className:"space-y-0 pt-0.5 pb-0.5",children:(()=>{const te=A.groups,re=te.find(Rk)??null,Se=re?te.filter(ue=>ue.id!==re.id):te;return s.jsxs(Qr,{sensors:g,collisionDetection:Yr,onDragEnd:ue=>{if(l)return;const{active:ye,over:ve}=ue;if(!ve||ye.id===ve.id)return;const be=Se.findIndex(Q=>Q.id===ye.id),_=Se.findIndex(Q=>Q.id===ve.id);if(be===-1||_===-1||be===_)return;const oe=Mu(Se,be,_).map(Ek),ce=re?[re.id,...oe]:oe;o.setGroupOrderByProject(Q=>{const me=new Map(Q);return me.set(G,ce),me})},children:[re?s.jsx(No,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:re,groupKey:`${G}:${re.id}`,projectId:G,hideGroupLabel:!0,visibleSessionCount:r.state.visibleSessionCountByGroup.get(`${G}:${re.id}`),scrollContainerRef:w}):null,s.jsx(Mo,{items:Se.map(Tk),strategy:Ui,children:Se.map(ue=>{const ye=`${G}:${ue.id}`;return s.jsx(Wj,{id:ue.id,disabled:l,children:ve=>s.jsx(No,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:ue,groupKey:ye,projectId:G,visibleSessionCount:r.state.visibleSessionCountByGroup.get(ye),dragHandleProps:ve,scrollContainerRef:w})},ue.id)})}),s.jsx(Vi,{dropAnimation:null})]})})()})},G)})}),s.jsx(Vi,{dropAnimation:null})]})]}),e[3]=o,e[4]=g,e[5]=l,e[6]=a,e[7]=r,e[8]=f,e[9]=n,e[10]=i,e[11]=v,e[12]=y,e[13]=m,e[14]=x,e[15]=b,e[16]=S,e[17]=C,e[18]=N,e[19]=k,e[20]=R,e[21]=I,e[22]=P,e[23]=T,e[24]=E}else v=e[11],y=e[12],m=e[13],x=e[14],b=e[15],S=e[16],C=e[17],N=e[18],k=e[19],R=e[20],I=e[21],P=e[22],T=e[23],E=e[24];let O;e[30]!==v||e[31]!==N||e[32]!==k||e[33]!==R||e[34]!==I||e[35]!==P||e[36]!==T||e[37]!==E?(O=s.jsx(v,{ref:N,useScrollShadow:k,hideTopScrollShadow:R,scrollShadowSize:I,outerClassName:P,className:T,children:E}),e[30]=v,e[31]=N,e[32]=k,e[33]=R,e[34]=I,e[35]=P,e[36]=T,e[37]=E,e[38]=O):O=e[38];let W;e[39]!==y||e[40]!==m||e[41]!==x||e[42]!==b||e[43]!==S||e[44]!==O?(W=s.jsx(y,{enabled:m,suspended:x,layoutKey:b,scrollRef:S,children:O}),e[39]=y,e[40]=m,e[41]=x,e[42]=b,e[43]=S,e[44]=O,e[45]=W):W=e[45];let L;return e[46]!==C||e[47]!==W?(L=s.jsx("div",{className:C,children:W}),e[46]=C,e[47]=W,e[48]=L):L=e[48],L}function Tk(t){return t.id}function Ek(t){return t.id}function Rk(t){return t.isMain}function Mk(t){return t.project.id}function Ok(t){return t.project.id}const Bk=c.memo(Ik),fa=new Map,zc=(t,e)=>{for(const n of t){const r=ft(n??null);r&&!fa.has(r)&&fa.set(r,e)}},Vc=t=>{const e=ft(t??null);return e?fa.get(e)??0:0},Rr=t=>!!t.time?.archived,Fk=t=>{const{t:e}=vt(),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=ft(a.directory??null)??"";return`${(a.title||e("sessions.sidebar.session.untitled")).trim()} ${u}`.toLowerCase()},[e]),o=c.useCallback((a,u)=>{if(!u)return a;const d=u.trim().toLowerCase(),h=d.startsWith("ses_");return a.flatMap(f=>{if(h&&Rr(f.session))return[];if(h?f.session.id.toLowerCase()===d:To([i(f.session)],u))return[f];const g=o(f.children,u);return g.length===0?[]:[{...f,children:g}]})},[i]),l=c.useCallback((a,u,d,h,f)=>{const p=ft(u??null),g=gu(a),w=new Map(g.map(F=>[F.id,F])),v=new Map;g.forEach(F=>{const D=F.parentID;if(!D)return;const j=w.get(D);if(!j||Rr(j)!==Rr(F))return;const A=v.get(D)??[];A.push(F),v.set(D,A)});const y=new Map;d.forEach(F=>{if(F.path){const D=ft(F.path)??F.path;y.set(D,F)}});const m=F=>{const D=ft(F.directory??null),j=t.worktreeMetadata.get(F.id)??null;if(j)return j;if(D){const A=y.get(D)??null;if(A&&D!==p)return A}return null},x=new Set,b=F=>{x.add(F.id);const D=v.get(F.id)??[],j=[];for(const A of D)x.has(A.id)||j.push(b(A));return{session:F,children:j,worktree:m(F)}},S=g.filter(F=>{const D=F.parentID;if(!D)return!0;const j=w.get(D);return j?Rr(j)!==Rr(F):!0}),C=[],N=F=>{x.has(F.id)||C.push(b(F))};S.forEach(N),g.forEach(N);const k=new Map,R="__archived__",I=F=>{if(F.time?.archived)return R;if(t.isVSCode)return p??"__project_root__";const j=ft(t.worktreeMetadata.get(F.id)?.path??null)??Fs(F);return j?j!==p&&y.has(j)?j:j===p?p??"__project_root__":R:R};C.forEach(F=>{const D=I(F.session);k.has(D)||k.set(D,[]),k.get(D)?.push(F)});const P=p??"__project_root__",T=[{id:"root",label:f&&h&&h!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:h}):e("sessions.sidebar.grouping.projectRoot"),branch:h??null,description:p?Gr(p,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:p,folderScopeKey:p,sessions:k.get(P)??[]}],E=new Map;d.forEach(F=>{const D=ft(F.path)??F.path,j=k.get(D)??[],A=j.length>0,M=j.reduce((G,q)=>{const Z=og(q.session,t.sessionOrderRanks);return Number.isFinite(Z)?Math.max(G,Z):G},0);E.set(D,{hasActiveSession:A,lastUpdatedAt:M})});const O=[...d].sort((F,D)=>{const j=ft(F.path)??F.path,A=ft(D.path)??D.path,M=E.get(j)??{hasActiveSession:!1,lastUpdatedAt:0},G=E.get(A)??{hasActiveSession:!1,lastUpdatedAt:0};if(M.hasActiveSession!==G.hasActiveSession)return M.hasActiveSession?-1:1;if(M.hasActiveSession&&G.hasActiveSession)return G.lastUpdatedAt-M.lastUpdatedAt;const q=Vc(F.path),Z=Vc(D.path);if(q!==Z)return Z-q;const le=(F.label||F.branch||F.name||F.path||"").toLowerCase(),X=(D.label||D.branch||D.name||D.path||"").toLowerCase();return le.localeCompare(X)});(t.isVSCode?[]:O).forEach(F=>{const D=ft(F.path)??F.path,j=n.current.get(D)?.trim()||null,A=F.branch?.trim()||null,G=!!(j&&A&&F.label&&jl(F.label)===jl(A))?j:F.label||F.name||Ln(D,t.homeDirectory)||D;T.push({id:`worktree:${D}`,label:G,branch:j||A,description:Gr(D,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:F,directory:D,folderScopeKey:D,sessions:k.get(D)??[]})});const L=k.get(R)??[];return L.length>0&&T.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?pu(p):null,sessions:L}),T},[t.homeDirectory,t.worktreeMetadata,t.sessionOrderRanks,t.isVSCode,e]);return{buildGroupSearchText:r,buildSessionSearchText:i,filterSessionNodesForSearch:o,buildGroupedSessions:l}},_k=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}=vt(),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 y=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 x;e[6]!==m?(x=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:m}),e[6]=m,e[7]=x):x=e[7];let b;e[8]!==w||e[9]!==d||e[10]!==a||e[11]!==l||e[12]!==u||e[13]!==i||e[14]!==g?(b=w?s.jsxs(Ys,{children:[s.jsxs(Ct,{children:[s.jsx(Nt,{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-ring","aria-label":g("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(B,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:g("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Qs,{align:"end",className:"min-w-[180px]",children:[i.length===0?s.jsx(Ut,{disabled:!0,className:"text-muted-foreground",children:g("sessions.sidebar.folders.none")}):i.map(j=>s.jsx(Ut,{onClick:()=>l(j.id),children:s.jsx("span",{className:"flex-1 truncate",children:j.name})},j.id)),s.jsx(zs,{}),s.jsxs(Ut,{onClick:a,children:[s.jsx(B,{name:"add",className:"mr-1 h-4 w-4"}),g("sessions.sidebar.folders.newFolderEllipsis")]}),d?s.jsxs(Ut,{onClick:u,className:"text-destructive focus:text-destructive",children:[s.jsx(B,{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]=b):b=e[15];let S;e[16]!==o||e[17]!==h||e[18]!==g?(S=o?s.jsxs(Ct,{children:[s.jsx(Nt,{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-ring","aria-label":g("sessions.sidebar.bulkActions.restore"),children:s.jsx(B,{name:"inbox-unarchive",className:"h-4 w-4"})})}),s.jsx(At,{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 C;e[20]===Symbol.for("react.memo_cache_sentinel")?(C=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]=C):C=e[20];let N;e[21]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(B,{name:"delete-bin",className:"h-4 w-4"}),e[21]=N):N=e[21];let k;e[22]!==y||e[23]!==f?(k=s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:C,"aria-label":y,children:N})}),e[22]=y,e[23]=f,e[24]=k):k=e[24];let R;e[25]!==y?(R=s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:y})}),e[25]=y,e[26]=R):R=e[26];let I;e[27]!==k||e[28]!==R?(I=s.jsxs(Ct,{children:[k,R]}),e[27]=k,e[28]=R,e[29]=I):I=e[29];let P;e[30]!==g?(P=g("sessions.sidebar.header.actions.exitSelection"),e[30]=g,e[31]=P):P=e[31];let T;e[32]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(B,{name:"close",className:"h-4 w-4"}),e[32]=T):T=e[32];let E;e[33]!==p||e[34]!==P?(E=s.jsx(Nt,{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-ring","aria-label":P,children:T})}),e[33]=p,e[34]=P,e[35]=E):E=e[35];let O;e[36]!==g?(O=g("sessions.sidebar.header.actions.exitSelection"),e[36]=g,e[37]=O):O=e[37];let W;e[38]!==O?(W=s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:O})}),e[38]=O,e[39]=W):W=e[39];let L;e[40]!==E||e[41]!==W?(L=s.jsxs(Ct,{children:[E,W]}),e[40]=E,e[41]=W,e[42]=L):L=e[42];let F;e[43]!==I||e[44]!==L||e[45]!==b||e[46]!==S?(F=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[b,S,I,L]}),e[43]=I,e[44]=L,e[45]=b,e[46]=S,e[47]=F):F=e[47];let D;return e[48]!==F||e[49]!==x?(D=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[x,F]}),e[48]=F,e[49]=x,e[50]=D):D=e[50],D},Lk=(t,e)=>{if(!t)return[];const n=e(t);return n.length>0?n.map(r=>r.scopeKey):[t]},$k=t=>{const{t:e}=vt(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:i,getFolderScopesForProject:o,addSessionsToFolder:l,removeSessionsFromFolders:a,createFolderAndStartRename:u,archiveSessions:d,unarchiveSessions:h,deleteSessions:f,setBulkDeleteConfirm:p}=t,g=ks(j=>j.enabled),w=ks(j=>j.selectedIds.size),v=w>0,y=ks(j=>j.selectedIds),m=ks(j=>j.scopeKey),x=c.useCallback(()=>{ks.getState().toggleMode()},[]),b=c.useCallback(()=>{ks.getState().disable()},[]),S=c.useMemo(()=>{if(!v||typeof document>"u")return!1;let j=!1,A=!1;for(const M of y){const G=document.querySelectorAll(`[data-session-row="${CSS.escape(M)}"]`);for(const q of G)q.getAttribute("data-session-archived")==="1"?A=!0:j=!0}return A&&!j},[v,y]),C=c.useMemo(()=>{if(m)return m;if(!v||typeof document>"u")return null;for(const j of y){const M=document.querySelector(`[data-session-row="${CSS.escape(j)}"]`)?.getAttribute("data-session-scope");if(M&&M.length>0)return M}return null},[v,y,m]),N=c.useMemo(()=>Lk(C,o),[C,o]),k=c.useMemo(()=>N.flatMap(j=>i[j]??[]),[i,N]),R=c.useCallback(j=>{for(const A of N)if((i[A]??[]).some(M=>M.id===j))return A;return null},[i,N]),I=c.useMemo(()=>{if(!v)return!1;for(const j of N)for(const A of i[j]??[])for(const M of A.sessionIds)if(y.has(M))return!0;return!1},[i,N,v,y]),P=c.useCallback((j,A)=>{const M=Array.from(y);for(const G of N)G!==j&&a(G,M);l(j,A,M)},[l,a,y,N]),T=c.useCallback(j=>{if(!v)return;const A=R(j);A&&P(A,j)},[v,P,R]),E=c.useCallback(()=>{const j=N[0];if(!j||!v)return;const A=u(j);A&&P(j,A.id)},[u,v,P,N]),O=c.useCallback(()=>{if(!v)return;const j=Array.from(y);for(const A of N)a(A,j)},[a,y,N,v]),W=c.useCallback(async()=>{const j=Array.from(y);if(j.length!==0){if(S){const{deletedIds:A,failedIds:M}=await f(j);A.length>0&&Fe.success(A.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:A.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:A.length})),M.length>0&&Fe.error(M.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:M.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:M.length}))}else{const{archivedIds:A,failedIds:M}=await d(j);A.length>0&&Fe.success(A.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:A.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:A.length})),M.length>0&&Fe.error(M.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:M.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:M.length}))}ks.getState().clear()}},[d,S,f,y,e]),L=c.useCallback(()=>{if(!v)return;const j=y.size;if(!r){W();return}p({sessionCount:j,archivedBucket:S})},[S,W,y,r,p,v]),F=c.useCallback(async()=>{if(!v||!S)return;const j=Array.from(y),{restoredIds:A,failedIds:M}=await h(j);A.length>0&&Fe.success(A.length===1?e("sessions.sidebar.bulkActions.restoredSingle",{count:A.length}):e("sessions.sidebar.bulkActions.restoredPlural",{count:A.length})),M.length>0&&Fe.error(M.length===1?e("sessions.sidebar.bulkActions.failedRestoreSingle",{count:M.length}):e("sessions.sidebar.bulkActions.failedRestorePlural",{count:M.length})),ks.getState().clear()},[S,v,y,e,h]),D=c.useCallback(async()=>{p(null),await W()},[W]);return c.useEffect(()=>{if(!g)return;const j=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),A=M=>{if(n)return;const G=M.target;if(G&&(G.tagName==="INPUT"||G.tagName==="TEXTAREA"||G.isContentEditable))return;const q=j?M.metaKey:M.ctrlKey;if(M.key==="Escape"){M.preventDefault(),ks.getState().disable();return}if(q&&M.key==="Backspace"){M.preventDefault(),L();return}if(q&&(M.key==="a"||M.key==="A")){const Z=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Z.length===0)return;M.preventDefault();const X=ks.getState().scopeKey??Z[0]?.getAttribute("data-session-scope")??null,te=Se=>X?Se.getAttribute("data-session-scope")===X:!0,re=Z.filter(te).map(Se=>Se.getAttribute("data-session-row")).filter(Se=>typeof Se=="string"&&Se.length>0);if(re.length===0)return;ks.getState().replaceAll(re,X||null)}};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[L,n,g]),{selectionModeEnabled:g,hasSelection:v,selectedIdsSize:w,bulkScopeIsArchived:S,derivedSelectionScope:C,bulkScopeFolders:k,bulkCanRemoveFromFolder:I,handleToggleSelectionMode:x,handleExitSelectionMode:b,handleBulkMoveToFolder:T,handleBulkCreateFolderAndMove:E,handleBulkRemoveFromFolder:O,handleBulkDelete:L,handleBulkRestore:F,confirmBulkDelete:D}};function Wk(t){const e=nt.c(36),{getFolderScopesForProject:n,isInlineEditing:r,startFolderRename:i}=t,[o,l]=c.useState(null),a=Ne(Yk),u=Ne(Qk),d=xs(qk),h=xs(Gk),f=xs(Hk),p=xs(Kk),g=tt(Uk),w=tt(Vk),v=tt(zk);let y;e[0]!==h||e[1]!==i?(y=N=>{const k=h(N,"New folder");return i(N,k),k},e[0]=h,e[1]=i,e[2]=y):y=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]!==y||e[12]!==w?(m={isInlineEditing:r,showDeletionDialog:a,foldersMap:d,getFolderScopesForProject:n,addSessionsToFolder:f,removeSessionsFromFolders:p,createFolderAndStartRename:y,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]=y,e[12]=w,e[13]=m):m=e[13];const x=$k(m);let b;e[14]!==x.bulkCanRemoveFromFolder||e[15]!==x.bulkScopeFolders||e[16]!==x.bulkScopeIsArchived||e[17]!==x.derivedSelectionScope||e[18]!==x.handleBulkCreateFolderAndMove||e[19]!==x.handleBulkDelete||e[20]!==x.handleBulkMoveToFolder||e[21]!==x.handleBulkRemoveFromFolder||e[22]!==x.handleBulkRestore||e[23]!==x.handleExitSelectionMode||e[24]!==x.hasSelection||e[25]!==x.selectedIdsSize||e[26]!==x.selectionModeEnabled?(b=x.selectionModeEnabled&&x.hasSelection?s.jsx(_k,{selectedCount:x.selectedIdsSize,scopeKey:x.derivedSelectionScope,scopeFolders:x.bulkScopeFolders,archivedBucket:x.bulkScopeIsArchived,onMoveToFolder:x.handleBulkMoveToFolder,onCreateFolderAndMove:x.handleBulkCreateFolderAndMove,onRemoveFromFolder:x.handleBulkRemoveFromFolder,canRemoveFromFolder:x.bulkCanRemoveFromFolder,onRestore:x.handleBulkRestore,onDelete:x.handleBulkDelete,onDone:x.handleExitSelectionMode}):null,e[14]=x.bulkCanRemoveFromFolder,e[15]=x.bulkScopeFolders,e[16]=x.bulkScopeIsArchived,e[17]=x.derivedSelectionScope,e[18]=x.handleBulkCreateFolderAndMove,e[19]=x.handleBulkDelete,e[20]=x.handleBulkMoveToFolder,e[21]=x.handleBulkRemoveFromFolder,e[22]=x.handleBulkRestore,e[23]=x.handleExitSelectionMode,e[24]=x.hasSelection,e[25]=x.selectedIdsSize,e[26]=x.selectionModeEnabled,e[27]=b):b=e[27];let S;e[28]!==x.confirmBulkDelete||e[29]!==o||e[30]!==u||e[31]!==a?(S=s.jsx(mk,{value:o,setValue:l,showDeletionDialog:a,setShowDeletionDialog:u,onConfirm:x.confirmBulkDelete}),e[28]=x.confirmBulkDelete,e[29]=o,e[30]=u,e[31]=a,e[32]=S):S=e[32];let C;return e[33]!==b||e[34]!==S?(C=s.jsxs(s.Fragment,{children:[b,S]}),e[33]=b,e[34]=S,e[35]=C):C=e[35],C}function zk(t){return t.deleteSessions}function Vk(t){return t.unarchiveSessions}function Uk(t){return t.archiveSessions}function Kk(t){return t.removeSessionsFromFolders}function Hk(t){return t.addSessionsToFolder}function Gk(t){return t.createFolder}function qk(t){return t.foldersMap}function Qk(t){return t.setShowDeletionDialog}function Yk(t){return t.showDeletionDialog}const Uc=7,Xk=6e4,Jk=()=>{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(e3)},Xk);return()=>clearInterval(o)},i=[],t[0]=r,t[1]=i):(r=t[0],i=t[1]),c.useEffect(r,i),e};function Zk(t){const{sections:e,variant:n="section",initialVisibleCount:r=Uc,batchSize:i=Uc}=t,{t:o}=vt(),{pinnedSessionIds:l}=t,a=gs(b=>b.stickyZoneHeaders),[u,d]=c.useState(new Set),[h,f]=c.useState(new Map),p=n==="flat",g=c.useCallback(b=>{f(S=>{if(!S.has(b))return S;const C=new Map(S);return C.delete(b),C})},[]),w=c.useCallback(b=>{g(b),d(S=>{const C=new Set(S);return C.has(b)?C.delete(b):C.add(b),C})},[g]),v=c.useCallback((b,S,C)=>{f(N=>{const k=Math.min(C,S+i),R=new Map(N);return R.set(b,k),R})},[i]),y=Jk(),m=c.useCallback(b=>{const S=new Set;la(b,t.editingId,S);const C=Xr(b,t.openSidebarMenuKey,"recent",!1),N=new WeakMap,k=I=>{N.set(I,zo(I)),I.children.forEach(k)};b.forEach(k);const R=I=>({subtreeContainsEditing:S,menuOpenSessionId:C,nodeStructureKey:N.get(I)??"",relativeTimeTick:y,childRenderExtrasFor:R});return I=>({subtreeContainsEditing:S,menuOpenSessionId:C,nodeStructureKey:N.get(I)??"",relativeTimeTick:y,childRenderExtrasFor:R})},[t.editingId,t.openSidebarMenuKey,y]),x=e.filter(b=>b.items.length>0||b.key==="chats");return x.length===0?null:s.jsx("div",{className:Ie(p?"space-y-0.5 pb-2":"space-y-2 pb-2"),children:x.map(b=>{const S=u.has(b.key),C=Math.max(r,h.get(b.key)??r),N=b.items.slice(0,C),k=b.items.length-N.length,R=b.key==="chats"&&!!t.renderChatsSection,I=!R&&!p&&b.items.length>r&&k===0,P=m(N.map(E=>E.node)),T=E=>s.jsx(Uo,{node:E.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:E.groupDirectory,projectId:E.projectId,secondaryMeta:E.secondaryMeta,renderContext:"recent",renderExtras:P(E.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},E.node.session.id);return p?s.jsxs("div",{className:"space-y-0.5",children:[N.map(T),k>0?s.jsx("button",{type:"button",onClick:()=>v(b.key,N.length,b.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]},b.key):s.jsxs("div",{className:"relative",children:[s.jsxs(Pm,{className:Ie("relative group/chats","-ml-2.5 -mr-2",!S&&"mb-1",a&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":a?"true":void 0,children:[s.jsxs("button",{type:"button",onClick:()=>w(b.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-ring",b.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(B,{name:b.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(B,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"typography-ui-label font-semibold lowercase text-foreground",children:b.title})]}),b.key==="chats"&&t.onNewChat?s.jsx("button",{type:"button",onClick:E=>{E.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-ring",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(B,{name:"add",className:"h-4 w-4"})}):null]}),S?null:s.jsxs("div",{className:Ie("space-y-0.5"),children:[R?t.renderChatsSection?.(b.items):N.map(T),!R&&k>0?s.jsx("button",{type:"button",onClick:()=>v(b.key,N.length,b.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,I?s.jsx("button",{type:"button",onClick:()=>g(b.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]})]},b.key)})})}function e3(t){return t+1}const t3=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}=vt();let y;if(e[0]!==r||e[1]!==i||e[2]!==o||e[3]!==n||e[4]!==d){y=new Map;for(const L of d){const F=ft(L.directory??null);if(!F)continue;let D=null,j=-1;for(const q of n){const Z=ft(q.normalizedPath);Z&&(F===Z||F.startsWith(`${Z}/`))&&Z.length>j&&(D=q,j=Z.length)}if(!D)continue;const A=r.get(D.normalizedPath)?.find(q=>ft(q.path)===F),M=Oa(D.label?.trim()||Ln(D.normalizedPath,o)||D.normalizedPath),G=A?.branch?.trim()||i.get(F)?.trim()||null;y.set(L.id,{projectId:D.id,groupDirectory:F,projectLabel:M,branchLabel:G&&G!=="HEAD"&&G!==M?G:null})}e[0]=r,e[1]=i,e[2]=o,e[3]=n,e[4]=d,e[5]=y}else y=e[5];const m=y;let x;e[6]!==m?(x=L=>m.get(L)??null,e[6]=m,e[7]=x):x=e[7];const b=x;let S;e[8]!==h?(S=L=>Rd(h,L),e[8]=h,e[9]=S):S=e[9];const C=S,N=l?a:"";let k;e[10]!==b||e[11]!==C||e[12]!==p||e[13]!==N?(k=dh({sessions:p,getSessionLocation:b,getSessionNode:C,query:N}),e[10]=b,e[11]=C,e[12]=p,e[13]=N,e[14]=k):k=e[14];const R=k;let I;e[15]!==v?(I=v("sessions.sidebar.activity.chatsTitle"),e[15]=v,e[16]=I):I=e[16];let P;if(e[17]!==g||e[18]!==C){let L;e[20]!==C?(L=F=>({node:C(F),projectId:null,groupDirectory:F.directory??null,secondaryMeta:null}),e[20]=C,e[21]=L):L=e[21],P=g.map(L),e[17]=g,e[18]=C,e[19]=P}else P=e[19];let T;e[22]!==I||e[23]!==P?(T={key:"chats",title:I,items:P},e[22]=I,e[23]=P,e[24]=T):T=e[24];let E;e[25]!==R||e[26]!==w||e[27]!==v||e[28]!==T?(E=[T,...w?R.map(L=>({...L,title:v("sessions.sidebar.activity.recentTitle")})):[]],e[25]=R,e[26]=w,e[27]=v,e[28]=T,e[29]=E):E=e[29];const O=E;let W;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]!==O?(W=s.jsx(Zk,{sections:O,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]=O,e[60]=W):W=e[60],W},Fm="oc.sessions.expandedParents.v3",s3=_a(Sr()),n3=()=>{try{const t=globalThis.localStorage.getItem(Fm);if(t===null)return new Set;const e=s3.safeParse(JSON.parse(t));return e.success?new Set(e.data):new Set}catch{return new Set}},r3=()=>{const[t,e]=c.useState(n3),n=c.useRef(t);n.current=t;const r=c.useCallback(i=>{const o=ig(n.current,i);n.current=o,e(o);try{globalThis.localStorage.setItem(Fm,JSON.stringify([...o]))}catch{}},[]);return{expandedParents:t,toggleParent:r}},o3=5*6e4,i3=[],a3=t=>!t.parentID,l3=t=>{const e=nt.c(286),{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=xs(d3),f=xs(u3),p=xs(m3),g=r.projectView,{getOrderedGroups:w,setGroupOrderByProject:v,toggleGroup:y,toggleProject:m}=a;let x;e[6]!==n.isVSCode||e[7]!==n.knownDirectories?(x={knownDirectories:n.knownDirectories,isVSCode:n.isVSCode,isVisible:!0},e[6]=n.isVSCode,e[7]=n.knownDirectories,e[8]=x):x=e[8];const b=uh(x);let S;e[9]===Symbol.for("react.memo_cache_sentinel")?(S=new Map,e[9]=S):S=e[9];const[C,N]=c.useState(S);let k;e[10]===Symbol.for("react.memo_cache_sentinel")?(k=(Lt,Wt,Xt)=>{const fs=Xt===void 0?7:Xt;N(cs=>new Map(cs).set(Lt,Wt+fs))},e[10]=k):k=e[10];const R=k;let I;e[11]===Symbol.for("react.memo_cache_sentinel")?(I=Lt=>{N(Wt=>{if(!Wt.has(Lt))return Wt;const Xt=new Map(Wt);return Xt.delete(Lt),Xt})},e[11]=I):I=e[11];const P=I,T=gs(f3),E=gs(h3),O=gs(p3),W=gs(g3);let L;e[12]!==n.isVSCode?(L=!n.isVSCode&&!Rf(),e[12]=n.isVSCode,e[13]=L):L=e[13];const D=L&&E==="single",j=T&&!D;let A;e[14]!==b.pinnedSessionIds||e[15]!==b.rootSessions||e[16]!==b.sessionOrderRanks||e[17]!==j||e[18]!==n.isVSCode?(A={enabled:j,isVSCode:n.isVSCode,pinnedSessionIds:b.pinnedSessionIds,sessionOrderRanks:b.sessionOrderRanks,sessions:b.rootSessions},e[14]=b.pinnedSessionIds,e[15]=b.rootSessions,e[16]=b.sessionOrderRanks,e[17]=j,e[18]=n.isVSCode,e[19]=A):A=e[19];const M=mh(A),[G,q]=c.useState(null),[Z,le]=c.useState(""),[X,te]=c.useState(null),[re,Se]=c.useState(null),[ue,ye]=c.useState(null),[ve,be]=c.useState(null);let _;e[20]===Symbol.for("react.memo_cache_sentinel")?(_=(Lt,Wt)=>{be({scopeKey:Lt,folderId:Wt.id,draft:Wt.name})},e[20]=_):_=e[20];const oe=_;let ce;e[21]===Symbol.for("react.memo_cache_sentinel")?(ce=Lt=>{be(Wt=>Wt?{...Wt,draft:Lt}:null)},e[21]=ce):ce=e[21];const Q=ce;let me;e[22]===Symbol.for("react.memo_cache_sentinel")?(me=()=>be(null),e[22]=me):me=e[22];const ke=me,{expandedParents:fe,toggleParent:De}=r3(),je=tt(x3);let Y;e[23]!==je?(Y=(Lt,Wt)=>{Lt!==tt.getState().currentSessionId&&je(Lt,Wt)},e[23]=je,e[24]=Y):Y=e[24];const Re=Y,Ce=wu();let Me;e[25]!==b.pinnedSessionIds||e[26]!==b.sessionOrderRanks||e[27]!==n.gitBranches||e[28]!==n.isVSCode||e[29]!==n.worktreeMetadata||e[30]!==r.homeDirectory?(Me={homeDirectory:r.homeDirectory,worktreeMetadata:n.worktreeMetadata,pinnedSessionIds:b.pinnedSessionIds,sessionOrderRanks:b.sessionOrderRanks,gitBranches:n.gitBranches,isVSCode:n.isVSCode},e[25]=b.pinnedSessionIds,e[26]=b.sessionOrderRanks,e[27]=n.gitBranches,e[28]=n.isVSCode,e[29]=n.worktreeMetadata,e[30]=r.homeDirectory,e[31]=Me):Me=e[31];const{buildGroupedSessions:ae,filterSessionNodesForSearch:ee,buildGroupSearchText:K}=Fk(Me);let $;e[32]!==b.archivedSessions||e[33]!==b.sessions||e[34]!==n.availableWorktreesByProject||e[35]!==n.isVSCode||e[36]!==n.projects?($=vj(b.sessions,n.projects,n.availableWorktreesByProject,n.isVSCode,b.archivedSessions),e[32]=b.archivedSessions,e[33]=b.sessions,e[34]=n.availableWorktreesByProject,e[35]=n.isVSCode,e[36]=n.projects,e[37]=$):$=e[37];const ne=$;let U;e[38]!==ne?(U={ownership:ne},e[38]=ne,e[39]=U):U=e[39];const{getSessionsForProject:we,getArchivedSessionsForProject:he}=jj(U);let Te;e:{if(n.isVSCode){Te=null;break e}let Lt;e[40]!==b.chatSessions||e[41]!==r.homeDirectory?(Lt=ag(r.homeDirectory)??b.chatSessions.map(b3).find(Boolean)??null,e[40]=b.chatSessions,e[41]=r.homeDirectory,e[42]=Lt):Lt=e[42];const Wt=Lt;if(!Wt){Te=null;break e}let Xt;if(e[43]!==Wt||e[44]!==b.chatSessions){const Ss=[Wt,...b.chatSessions.map(y3).filter(Boolean)];let hs;e[46]!==Ss?(hs=new Set(Ss),e[46]=Ss,e[47]=hs):hs=e[47],Xt=Array.from(hs).filter(w3).map(S3),e[43]=Wt,e[44]=b.chatSessions,e[45]=Xt}else Xt=e[45];const fs=Xt;let cs;if(e[48]!==b.chatSessions||e[49]!==b.childrenMap){let Ss;e[51]!==b.childrenMap?(Ss=hs=>Rd(b.childrenMap,hs),e[51]=b.childrenMap,e[52]=Ss):Ss=e[52],cs=b.chatSessions.filter(v3).map(Ss),e[48]=b.chatSessions,e[49]=b.childrenMap,e[50]=cs}else cs=e[50];let Es;e[53]!==Wt||e[54]!==fs||e[55]!==cs?(Es={id:"managed-chats",label:"",branch:null,description:null,isMain:!0,worktree:null,directory:Wt,folderScopeKey:Wt,folderScopes:fs,draftTarget:"chat",sessions:cs},e[53]=Wt,e[54]=fs,e[55]=cs,e[56]=Es):Es=e[56],Te=Es}const Oe=Te;let _e;e[57]!==Oe?(_e=Oe?[Oe]:i3,e[57]=Oe,e[58]=_e):_e=e[58];const Ve=_e;let z;e[59]!==K||e[60]!==ae||e[61]!==ee||e[62]!==h||e[63]!==he||e[64]!==we||e[65]!==Ve||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?(z={normalizedProjects:n.projects,getSessionsForProject:we,getArchivedSessionsForProject:he,availableWorktreesByProject:n.availableWorktreesByProject,projectRepoStatus:n.projectRepoStatus,projectRootBranches:n.projectRootBranches,gitBranches:n.gitBranches,lastRepoStatus:n.lastRepoStatus,buildGroupedSessions:ae,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,filterSessionNodesForSearch:ee,buildGroupSearchText:K,foldersMap:h,standaloneGroups:Ve},e[59]=K,e[60]=ae,e[61]=ee,e[62]=h,e[63]=he,e[64]=we,e[65]=Ve,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]=z):z=e[74];const{projectSections:pe,groupSearchDataByGroup:Ae,sectionsForRender:Be,flatSectionsForRender:rt,searchMatchCount:Ge}=Nj(z),ut=r.onSearchMatchCountChange;let at,wt;e[75]!==ut||e[76]!==Ge?(at=()=>{ut(Ge)},wt=[ut,Ge],e[75]=ut,e[76]=Ge,e[77]=at,e[78]=wt):(at=e[77],wt=e[78]),c.useEffect(at,wt);let pt,It;e[79]!==ut?(pt=()=>()=>ut(0),It=[ut],e[79]=ut,e[80]=pt,e[81]=It):(pt=e[80],It=e[81]),c.useEffect(pt,It);const Pt=Ba(),Rt=`session-collection-expansion:${c.useId()}`;let de,We;e[82]!==Pt||e[83]!==Rt||e[84]!==pe||e[85]!==g.collapsedGroups||e[86]!==g.collapsedProjects||e[87]!==r.activeProjectId?(de=()=>(Pt.setBootstrapDemand(Rt,Nm({projectSections:pe,activeProjectId:r.activeProjectId,collapsedProjects:g.collapsedProjects,collapsedGroups:g.collapsedGroups,currentDirectory:null,currentSessionDirectory:null})),()=>Pt.clearBootstrapDemand(Rt)),We=[Pt,Rt,pe,g.collapsedProjects,g.collapsedGroups,r.activeProjectId],e[82]=Pt,e[83]=Rt,e[84]=pe,e[85]=g.collapsedGroups,e[86]=g.collapsedProjects,e[87]=r.activeProjectId,e[88]=de,e[89]=We):(de=e[88],We=e[89]),c.useEffect(de,We);const lt=r.useGroupedSections?Be:rt;let H;e[90]!==lt||e[91]!==r.showInlineArchived?(H=r.showInlineArchived?lt:lt.map(C3),e[90]=lt,e[91]=r.showInlineArchived,e[92]=H):H=e[92];const V=H;let J;e[93]!==rt?(J=Lt=>rt.find(Xt=>Xt.project.id===Lt)?.groups.find(N3)?.folderScopes??[],e[93]=rt,e[94]=J):J=e[94];const ge=J;let Ee;e[95]!==p||e[96]!==b.hasAuthoritativeGlobalSessions||e[97]!==f||e[98]!==h||e[99]!==ne||e[100]!==n.projects||e[101]!==r.isSessionsLoading||e[102]!==r.isWorktreeTopologyLoading||e[103]!==r.unresolvedWorktreeProjectPaths?(Ee={enabled:!0,normalizedProjects:n.projects,ownership:ne,isSessionsLoading:r.isSessionsLoading,hasAuthoritativeGlobalSessions:b.hasAuthoritativeGlobalSessions,isWorktreeTopologyLoading:r.isWorktreeTopologyLoading,unresolvedWorktreeProjectPaths:r.unresolvedWorktreeProjectPaths,foldersMap:h,createFolder:f,addSessionToFolder:p},e[95]=p,e[96]=b.hasAuthoritativeGlobalSessions,e[97]=f,e[98]=h,e[99]=ne,e[100]=n.projects,e[101]=r.isSessionsLoading,e[102]=r.isWorktreeTopologyLoading,e[103]=r.unresolvedWorktreeProjectPaths,e[104]=Ee):Ee=e[104],fj(Ee);const{github:$e}=jn(),st=Dn(A3),Ze=Dn(P3),et=tn(D3),Ue=tn(I3),jt=tn(T3);let ze;e[105]===Symbol.for("react.memo_cache_sentinel")?(ze=new Set,e[105]=ze):ze=e[105];const xe=c.useRef(ze);let bt;e[106]!==et||e[107]!==$e||e[108]!==Ze||e[109]!==st||e[110]!==pe||e[111]!==g.collapsedProjects||e[112]!==jt||e[113]!==Ue||e[114]!==n.gitBranches?(bt=()=>{if(!$e||!Ze||!st?.connected)return;const Lt=new Map,Wt=Date.now();pe.forEach(Xt=>{g.collapsedProjects.has(Xt.project.id)||Xt.groups.forEach(fs=>{if(fs.isArchivedBucket||fs.isMain)return;const cs=ft(fs.directory??null),Es=fs.branch?.trim()||n.gitBranches.get(cs||"")?.trim();if(!cs||!Es)return;const Ss=Yo(cs,Es),hs=tn.getState().entries[Ss],Tn=hs?.status?.pr?.state==="closed"||hs?.status?.pr?.state==="merged",En=`${cs}::${Es}`,se=Math.max(hs?.lastRefreshAt??0,hs?.lastDiscoveryPollAt??0),Qe=!!(hs?.isInitialStatusResolved&&(!hs.status?.pr||Tn)&&(!xe.current.has(En)||Wt-se>=o3));(!hs||!hs.isInitialStatusResolved||Qe)&&(Qe&&xe.current.add(En),Lt.set(Ss,{directory:cs,branch:Es}))})}),Lt.forEach((Xt,fs)=>{et(fs),Ue(fs,{...Xt,remoteName:null,canShow:!0,github:$e,githubAuthChecked:Ze,githubConnected:st.connected})}),Lt.size&&jt([...Lt.values()],{silent:!0,markInitialResolved:!0})},e[106]=et,e[107]=$e,e[108]=Ze,e[109]=st,e[110]=pe,e[111]=g.collapsedProjects,e[112]=jt,e[113]=Ue,e[114]=n.gitBranches,e[115]=bt):bt=e[115];const ht=st?.connected;let kt;e[116]!==et||e[117]!==$e||e[118]!==Ze||e[119]!==pe||e[120]!==g.collapsedProjects||e[121]!==jt||e[122]!==Ue||e[123]!==ht||e[124]!==n.gitBranches?(kt=[et,$e,Ze,ht,pe,g.collapsedProjects,jt,Ue,n.gitBranches],e[116]=et,e[117]=$e,e[118]=Ze,e[119]=pe,e[120]=g.collapsedProjects,e[121]=jt,e[122]=Ue,e[123]=ht,e[124]=n.gitBranches,e[125]=kt):kt=e[125],c.useEffect(bt,kt);let Xe;e[126]!==b.orderedSessions?(Xe=new Map(b.orderedSessions.map(E3)),e[126]=b.orderedSessions,e[127]=Xe):Xe=e[127];const Ke=Xe;let Ye;if(e[128]!==w||e[129]!==V){let Lt;e[131]!==w?(Lt=Wt=>{const Xt=w(Wt.project.id,Wt.groups);return Xt===Wt.groups?Wt:{...Wt,groups:Xt}},e[131]=w,e[132]=Lt):Lt=e[132],Ye=V.map(Lt),e[128]=w,e[129]=V,e[130]=Ye}else Ye=e[130];const gt=Ye;let Mt;e[133]!==pe||e[134]!==O||e[135]!==D||e[136]!==r.activeProjectId?(Mt=null,D&&(pe.some(Lt=>Lt.project.id===O)?Mt=O:pe.some(Lt=>Lt.project.id===r.activeProjectId)?Mt=r.activeProjectId:Mt=pe[0]?.project.id??null),e[133]=pe,e[134]=O,e[135]=D,e[136]=r.activeProjectId,e[137]=Mt):Mt=e[137];const xt=D&&!r.useGroupedSections?20:void 0;let St;e[138]!==i.startSessionWorktreeMenuLoad||e[139]!==o||e[140]!==b.pinnedSessionIds||e[141]!==ue||e[142]!==re||e[143]!==Z||e[144]!==G||e[145]!==fe||e[146]!==ve||e[147]!==Ae||e[148]!==l||e[149]!==g.collapsedGroups||e[150]!==u.allowReselect||e[151]!==u.isSessionSearchOpen||e[152]!==u.onSessionSelected||e[153]!==u.sessionSearchQuery||e[154]!==u.setIsSessionSearchOpen||e[155]!==u.setSessionSearchQuery||e[156]!==Ke||e[157]!==xt||e[158]!==De||e[159]!==r.activeProjectId||e[160]!==r.hasSessionSearchQuery||e[161]!==r.hideDirectoryControls||e[162]!==r.mobileVariant||e[163]!==r.normalizedSessionSearchQuery?(St={hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,groupSearchDataByGroup:Ae,collapsedGroups:g.collapsedGroups,hideDirectoryControls:r.hideDirectoryControls,mobileVariant:r.mobileVariant,alwaysShowActions:o,activeProjectId:r.activeProjectId,notifyOnSubtasks:l,pinnedSessionIds:b.pinnedSessionIds,sessionOrderIndex:Ke,expandedParents:fe,editingId:G,editTitle:Z,copiedSessionId:ue,sessionBatchSize:xt,setEditingId:q,setEditTitle:le,toggleParent:De,allowReselect:u.allowReselect,onSessionSelected:u.onSessionSelected,isSessionSearchOpen:u.isSessionSearchOpen,sessionSearchQuery:u.sessionSearchQuery,setSessionSearchQuery:u.setSessionSearchQuery,setIsSessionSearchOpen:u.setIsSessionSearchOpen,deleteSessionConfirm:re,setDeleteSessionConfirm:Se,startFolderRename:oe,setCopiedSessionId:ye,startSessionWorktreeMenuLoad:i.startSessionWorktreeMenuLoad,folderRename:ve,setFolderRenameDraft:Q,clearFolderRename:ke},e[138]=i.startSessionWorktreeMenuLoad,e[139]=o,e[140]=b.pinnedSessionIds,e[141]=ue,e[142]=re,e[143]=Z,e[144]=G,e[145]=fe,e[146]=ve,e[147]=Ae,e[148]=l,e[149]=g.collapsedGroups,e[150]=u.allowReselect,e[151]=u.isSessionSearchOpen,e[152]=u.onSessionSelected,e[153]=u.sessionSearchQuery,e[154]=u.setIsSessionSearchOpen,e[155]=u.setSessionSearchQuery,e[156]=Ke,e[157]=xt,e[158]=De,e[159]=r.activeProjectId,e[160]=r.hasSessionSearchQuery,e[161]=r.hideDirectoryControls,e[162]=r.mobileVariant,e[163]=r.normalizedSessionSearchQuery,e[164]=St):St=e[164];const Tt=St;let Jt;e[165]!==d.openNewSessionDraft||e[166]!==d.setActiveProjectIdOnly||e[167]!==d.setSessionSwitcherOpen||e[168]!==y?(Jt={showMoreGroupSessions:R,resetGroupSessionLimit:P,setActiveProjectIdOnly:d.setActiveProjectIdOnly,setSessionSwitcherOpen:d.setSessionSwitcherOpen,openNewSessionDraft:d.openNewSessionDraft,onToggleCollapsedGroup:y},e[165]=d.openNewSessionDraft,e[166]=d.setActiveProjectIdOnly,e[167]=d.setSessionSwitcherOpen,e[168]=y,e[169]=Jt):Jt=e[169];const Gt=Jt;let $t;e[170]!==Oe||e[171]!==Gt||e[172]!==Tt||e[173]!==X||e[174]!==C?($t=()=>Oe?s.jsx(No,{...Tt,...Gt,group:Oe,groupKey:"managed-chats",projectId:null,hideGroupLabel:!0,sessionBatchSize:void 0,visibleSessionCount:C.get("managed-chats"),scrollContainerRef:void 0,openSidebarMenuKey:X,setOpenSidebarMenuKey:te}):null,e[170]=Oe,e[171]=Gt,e[172]=Tt,e[173]=X,e[174]=C,e[175]=$t):$t=e[175];const Kt=$t;let Ht;e[176]!==d||e[177]!==r.mobileVariant?(Ht=()=>{Ne.getState().closeMainSurfaces(),r.mobileVariant&&d.setSessionSwitcherOpen(!1),d.openNewSessionDraft({selectedProjectId:lg,directoryOverride:null})},e[176]=d,e[177]=r.mobileVariant,e[178]=Ht):Ht=e[178];const Qt=Ht;let Le;e[179]!==i.startSessionWorktreeMenuLoad||e[180]!==o||e[181]!==b.chatSessions||e[182]!==b.childrenMap||e[183]!==b.pinnedSessionIds||e[184]!==ue||e[185]!==re||e[186]!==Z||e[187]!==G||e[188]!==fe||e[189]!==Qt||e[190]!==l||e[191]!==X||e[192]!==M||e[193]!==Kt||e[194]!==u.allowReselect||e[195]!==u.isSessionSearchOpen||e[196]!==u.onSessionSelected||e[197]!==u.sessionSearchQuery||e[198]!==u.setIsSessionSearchOpen||e[199]!==u.setSessionSearchQuery||e[200]!==T||e[201]!==D||e[202]!==De||e[203]!==n.availableWorktreesByProject||e[204]!==n.gitBranches||e[205]!==n.isVSCode||e[206]!==n.projects||e[207]!==r.hasSessionSearchQuery||e[208]!==r.homeDirectory||e[209]!==r.isDesktopShellRuntime||e[210]!==r.mobileVariant||e[211]!==r.normalizedSessionSearchQuery?(Le=n.isVSCode?null:s.jsx(t3,{projects:n.projects,availableWorktreesByProject:n.availableWorktreesByProject,gitBranches:n.gitBranches,homeDirectory:r.homeDirectory,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,isDesktopShellRuntime:r.isDesktopShellRuntime,sessions:M,childrenMap:b.childrenMap,pinnedSessionIds:b.pinnedSessionIds,recentSessions:M,expandedParents:fe,notifyOnSubtasks:l,editingId:G,editTitle:Z,copiedSessionId:ue,openSidebarMenuKey:X,mobileVariant:r.mobileVariant,alwaysShowActions:o,setEditingId:q,setEditTitle:le,toggleParent:De,setOpenSidebarMenuKey:te,allowReselect:u.allowReselect,onSessionSelected:u.onSessionSelected,isSessionSearchOpen:u.isSessionSearchOpen,sessionSearchQuery:u.sessionSearchQuery,setSessionSearchQuery:u.setSessionSearchQuery,setIsSessionSearchOpen:u.setIsSessionSearchOpen,deleteSessionConfirm:re,setDeleteSessionConfirm:Se,startFolderRename:oe,setCopiedSessionId:ye,startSessionWorktreeMenuLoad:i.startSessionWorktreeMenuLoad,chatSessions:b.chatSessions,renderChatsSection:Kt,onNewChat:Qt,showRecentSection:T&&!D}),e[179]=i.startSessionWorktreeMenuLoad,e[180]=o,e[181]=b.chatSessions,e[182]=b.childrenMap,e[183]=b.pinnedSessionIds,e[184]=ue,e[185]=re,e[186]=Z,e[187]=G,e[188]=fe,e[189]=Qt,e[190]=l,e[191]=X,e[192]=M,e[193]=Kt,e[194]=u.allowReselect,e[195]=u.isSessionSearchOpen,e[196]=u.onSessionSelected,e[197]=u.sessionSearchQuery,e[198]=u.setIsSessionSearchOpen,e[199]=u.setSessionSearchQuery,e[200]=T,e[201]=D,e[202]=De,e[203]=n.availableWorktreesByProject,e[204]=n.gitBranches,e[205]=n.isVSCode,e[206]=n.projects,e[207]=r.hasSessionSearchQuery,e[208]=r.homeDirectory,e[209]=r.isDesktopShellRuntime,e[210]=r.mobileVariant,e[211]=r.normalizedSessionSearchQuery,e[212]=Le):Le=e[212];const qe=Le;let ot;e[213]!==Ae||e[214]!==Ve||e[215]!==r.hasSessionSearchQuery?(ot=r.hasSessionSearchQuery&&Ve.some(Lt=>Ae.get(Lt)?.hasMatch===!0),e[213]=Ae,e[214]=Ve,e[215]=r.hasSessionSearchQuery,e[216]=ot):ot=e[216];const it=ot;let He;e[217]!==G||e[218]!==X||e[219]!==C?(He={editingId:G,openSidebarMenuKey:X,setOpenSidebarMenuKey:te,visibleSessionCountByGroup:C},e[217]=G,e[218]=X,e[219]=C,e[220]=He):He=e[220];let Bt;e[221]!==Tt||e[222]!==gt||e[223]!==pe||e[224]!==qe||e[225]!==Mt||e[226]!==D||e[227]!==He||e[228]!==it||e[229]!==n.projectRepoStatus||e[230]!==r.activeProjectId||e[231]!==r.emptyState||e[232]!==r.searchEmptyState?(Bt={topContent:qe,topContentHasSearchMatches:it,sectionsForRender:gt,projectSections:pe,activeProjectId:r.activeProjectId,singleProjectMode:D,singleProjectId:Mt,emptyState:r.emptyState,searchEmptyState:r.searchEmptyState,projectRepoStatus:n.projectRepoStatus,state:He,groupProps:Tt},e[221]=Tt,e[222]=gt,e[223]=pe,e[224]=qe,e[225]=Mt,e[226]=D,e[227]=He,e[228]=it,e[229]=n.projectRepoStatus,e[230]=r.activeProjectId,e[231]=r.emptyState,e[232]=r.searchEmptyState,e[233]=Bt):Bt=e[233];const ts=Bt;let es;e[234]!==o||e[235]!==g.collapsedProjects||e[236]!==r.hasSessionSearchQuery||e[237]!==r.hideDirectoryControls||e[238]!==r.homeDirectory||e[239]!==r.mobileVariant||e[240]!==r.normalizedSessionSearchQuery||e[241]!==r.projectSortOrder||e[242]!==r.showOnlyMainWorkspace||e[243]!==r.stickyZoneHeaders?(es={homeDirectory:r.homeDirectory,collapsedProjects:g.collapsedProjects,showOnlyMainWorkspace:r.showOnlyMainWorkspace,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,hideDirectoryControls:r.hideDirectoryControls,stickyZoneHeaders:r.stickyZoneHeaders,mobileVariant:r.mobileVariant,alwaysShowActions:o,projectSortOrder:r.projectSortOrder},e[234]=o,e[235]=g.collapsedProjects,e[236]=r.hasSessionSearchQuery,e[237]=r.hideDirectoryControls,e[238]=r.homeDirectory,e[239]=r.mobileVariant,e[240]=r.normalizedSessionSearchQuery,e[241]=r.projectSortOrder,e[242]=r.showOnlyMainWorkspace,e[243]=r.stickyZoneHeaders,e[244]=es):es=e[244];const ss=es;let ds;e[245]!==Gt||e[246]!==d.openNewSessionDraft||e[247]!==d.openNewWorktreeDialog||e[248]!==d.openProjectEditDialog||e[249]!==d.openWorktreesPage||e[250]!==d.removeProject||e[251]!==d.renderProjectStatusIndicator||e[252]!==d.reorderProjects||e[253]!==d.setActiveProjectIdOnly||e[254]!==d.setSessionSwitcherOpen||e[255]!==v||e[256]!==W||e[257]!==m?(ds={group:Gt,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:W},e[245]=Gt,e[246]=d.openNewSessionDraft,e[247]=d.openNewWorktreeDialog,e[248]=d.openProjectEditDialog,e[249]=d.openWorktreesPage,e[250]=d.removeProject,e[251]=d.renderProjectStatusIndicator,e[252]=d.reorderProjects,e[253]=d.setActiveProjectIdOnly,e[254]=d.setSessionSwitcherOpen,e[255]=v,e[256]=W,e[257]=m,e[258]=ds):ds=e[258];const Js=ds;let us;e[259]===Symbol.for("react.memo_cache_sentinel")?(us=s.jsx(cj,{}),e[259]=us):us=e[259];let Os;e[260]!==i.initialActiveSessionByProject||e[261]!==i.openNewSessionDraft||e[262]!==i.persistActiveSessionByProject||e[263]!==i.setSessionSwitcherOpen||e[264]!==ne.bySessionId||e[265]!==pe||e[266]!==Re||e[267]!==r.activeProjectId||e[268]!==r.mobileVariant?(Os=s.jsx(xj,{projectSections:pe,activeProjectId:r.activeProjectId,initialActiveSessionByProject:i.initialActiveSessionByProject,persistActiveSessionByProject:i.persistActiveSessionByProject,mobileVariant:r.mobileVariant,openNewSessionDraft:i.openNewSessionDraft,setSessionSwitcherOpen:i.setSessionSwitcherOpen,sessionOwnerBySessionId:ne.bySessionId,handleSessionSelect:Re}),e[260]=i.initialActiveSessionByProject,e[261]=i.openNewSessionDraft,e[262]=i.persistActiveSessionByProject,e[263]=i.setSessionSwitcherOpen,e[264]=ne.bySessionId,e[265]=pe,e[266]=Re,e[267]=r.activeProjectId,e[268]=r.mobileVariant,e[269]=Os):Os=e[269];let ns;e[270]!==b.orderedSessions||e[271]!==Ce||e[272]!==M?(ns=s.jsx(Ej,{sortedSessions:b.orderedSessions,recentSessions:M,prefetchSession:Ce}),e[270]=b.orderedSessions,e[271]=Ce,e[272]=M,e[273]=ns):ns=e[273];let Cs;e[274]!==Js||e[275]!==ts||e[276]!==ss?(Cs=s.jsx(Bk,{model:ts,view:ss,actions:Js}),e[274]=Js,e[275]=ts,e[276]=ss,e[277]=Cs):Cs=e[277];const Zs=G!==null;let Ns;e[278]!==ge||e[279]!==Zs?(Ns=s.jsx(Wk,{getFolderScopesForProject:ge,isInlineEditing:Zs,startFolderRename:oe}),e[278]=ge,e[279]=Zs,e[280]=Ns):Ns=e[280];let Ts;return e[281]!==Os||e[282]!==ns||e[283]!==Cs||e[284]!==Ns?(Ts=s.jsxs(s.Fragment,{children:[us,Os,ns,Cs,Ns]}),e[281]=Os,e[282]=ns,e[283]=Cs,e[284]=Ns,e[285]=Ts):Ts=e[285],Ts},c3=t=>{const e=nt.c(2);let n;return e[0]!==t?(n=t.view.isVisible?s.jsx(l3,{...t}):null,e[0]=t,e[1]=n):n=e[1],n};function d3(t){return t.foldersMap}function u3(t){return t.createFolder}function m3(t){return t.addSessionToFolder}function f3(t){return t.showRecentSection}function h3(t){return t.projectDisplayMode}function p3(t){return t.singleProjectId}function g3(t){return t.setSingleProjectId}function x3(t){return t.setCurrentSession}function b3(t){return ju(t.directory)}function y3(t){return ft(t.directory??null)}function w3(t){return!!t}function S3(t){return{scopeKey:t,directory:t}}function v3(t){return!t.time?.archived&&a3(t)}function j3(t){return t.isArchivedBucket}function k3(t){return!t.isArchivedBucket}function C3(t){return t.groups.some(j3)?{...t,groups:t.groups.filter(k3)}:t}function N3(t){return!t.isArchivedBucket}function A3(t){return t.status}function P3(t){return t.hasChecked}function D3(t){return t.ensureEntry}function I3(t){return t.setParams}function T3(t){return t.refreshTargets}function E3(t,e){return[t.id,e]}const _m=(t,e,n)=>{const r=new Set;for(const i of t){const o=ft(i.path);o&&r.add(o)}if(n?.includeWorktrees===!1)return r;for(const i of e.values())for(const o of i){const l=ft(o.path);l&&r.add(l)}return r},Kc="oc.sessions.activeSessionByProject",R3=[],M3=Wu(Sr(),Sr().min(1).catch("")),O3=({isVisible:t=!0,mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:i=!1,showOnlyMainWorkspace:o=!1})=>{Ni("react.session_sidebar_render"),sn("ui.session_sidebar.render"),sn(`ui.session_sidebar.render.${e?"mobile":"desktop"}`),sn(`ui.session_sidebar.render.${t?"visible":"hidden"}`);const{t:l}=vt(),[a,u]=c.useState(!1),[d,h]=c.useState(""),[f,p]=c.useState(0),g=c.useRef(null),w=c.useRef(null),[v,y]=c.useState(null),m=c.useMemo(()=>Io(),[]),[x,b]=c.useState(new Map),S=Ne(xe=>xe.isNewWorktreeDialogOpen),C=Ne(xe=>xe.setNewWorktreeDialogOpen),[N,k]=c.useState(!1),R=c.useMemo(()=>{try{const xe=m.getItem(Kc);if(!xe)return new Map;const bt=M3.safeParse(JSON.parse(xe));if(!bt.success)return new Map;const ht=new Map;return Object.entries(bt.data).forEach(([kt,Xe])=>{Xe&&ht.set(kt,Xe)}),ht}catch{return new Map}},[m]),I=c.useCallback(xe=>{try{m.setItem(Kc,JSON.stringify(Object.fromEntries(xe.entries())))}catch{}},[m]),[P,T]=c.useState(new Map),E=is(xe=>xe.homeDirectory),O=qt(xe=>xe.projects),W=qt(xe=>xe.activeProjectId),L=qt(xe=>xe.removeProject),F=qt(xe=>xe.setActiveProjectIdOnly),D=qt(xe=>xe.updateProjectMeta),j=qt(xe=>xe.reorderProjects),A=Ne(xe=>xe.setSettingsDialogOpen),M=Ne(xe=>xe.toggleHelpDialog),G=Ne(xe=>xe.setAboutDialogOpen),q=Ne(xe=>xe.setSessionSwitcherOpen),Z=Ne(xe=>xe.setScheduledTasksDialogOpen),le=Ne(xe=>xe.setArchivePageOpen),X=Ne(xe=>xe.setWorktreesPageProjectId),te=Ne(xe=>xe.openMultiRunLauncher),re=Ne(xe=>xe.notifyOnSubtasks),Se=c.useMemo(()=>d.trim().toLowerCase(),[d]),ue=Se.length>0;I0({enabled:t,isSessionSearchOpen:a,setIsSessionSearchOpen:u,sessionSearchInputRef:w,sessionSearchContainerRef:g});const ye=du(t),ve=c.useMemo(()=>$n(),[]),be=tt(xe=>xe.setCurrentSession),_=tt(xe=>xe.worktreeMetadata),oe=tt(xe=>xe.availableWorktreesByProject),ce=tt(xe=>xe.openNewSessionDraft),Q=c.useMemo(()=>_m(O,oe,{includeWorktrees:!ve}),[oe,ve,O]),me=c.useCallback(xe=>{Ne.getState().closeMainSurfaces(),ce(xe),ve&&window.dispatchEvent(new CustomEvent("openchamber:navigate",{detail:{view:"chat"}}))},[ve,ce]),ke=$r(sr(xe=>({checkForUpdates:xe.checkForUpdates,available:xe.available,runtimeType:xe.runtimeType,info:xe.info,downloading:xe.downloading,downloaded:xe.downloaded,progress:xe.progress,error:xe.error,downloadUpdate:xe.downloadUpdate,restartToUpdate:xe.restartToUpdate}))),fe=ls(),De=c.useMemo(()=>`${fe}|${O.map(xe=>`${xe.id}:${ft(xe.path)??""}`).join("|")}`,[O,fe]),[je,Y]=c.useState(ve?De:null),[Re,Ce]=c.useReducer(xe=>xe+1,0),Me=!ve&&je!==De,[ae,ee]=c.useState(new Set),K=c.useRef({runtimeKey:null,revision:0,worktreesByProject:new Map});c.useEffect(()=>{let xe=!1;return(async()=>{const ht=fe,kt=qt.getState().projects;if(tt.setState({worktreeDiscoveryByProject:new Map(kt.map($t=>[ft($t.path)??$t.path,"loading"]))}),kt.length===0||ve){xe||(K.current={runtimeKey:null,revision:0,worktreesByProject:new Map},ee(new Set),Y(De));return}const Xe=tt.getState().availableWorktreesByProject,Ke=qa({rawWorktreesByProjectRef:K,publishedWorktreesByProject:Xe,runtimeKey:ht}),Ye=Ke.revision,gt=new Map(Ke.worktreesByProject),Mt=new Set,xt=3;let St=0;const Tt=Array.from({length:xt},async()=>{for(;;){const $t=St;if(St+=1,$t>=kt.length)return;const Kt=kt[$t],Ht=ft(Kt.path);if(Ht)try{const Qt=await Fi(async()=>In.getState().directories.get(Ht)?.isGitRepo??await Qo(Ht)?Nl({id:Kt.id,path:Ht}):null);if(Qt===null){gt.delete(Ht);continue}if(xe)return;Qt.length===0?gt.delete(Ht):gt.set(Ht,Qt)}catch{Mt.add(Ht)}}});if(await Promise.all(Tt),xe||ls()!==ht)return;const Jt=new Set(kt.map($t=>ft($t.path)).filter(Boolean));for(const $t of gt.keys())Jt.has($t)||gt.delete($t);Y2({rawWorktreesByProjectRef:K,runtimeKey:ht,capturedRevision:Ye,nextRawWorktreesByProject:gt,publishedWorktreesByProject:Xe,partitionWorktreesByRegisteredProject:Cl,projects:kt,worktreeMapsEqual:kl,recordWorktreesSeen:zc,publishTopology:$t=>{tt.setState($t)},requestRediscovery:()=>{Ce()},now:()=>Date.now()})&&(ee(Mt),tt.setState({worktreeDiscoveryByProject:new Map(kt.map($t=>{const Kt=ft($t.path)??$t.path;return[Kt,Mt.has(Kt)?"error":"ready"]}))}),Y(De))})(),()=>{xe=!0}},[ve,De,fe,Re]);const $=c.useMemo(()=>yn(),[]),{isTablet:ne}=Wn(),U=e||ne,we=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]),he=c.useMemo(()=>O.find(xe=>xe.id===v)??null,[O,v]),Te=c.useCallback(xe=>{v&&D(v,{label:xe.label,icon:xe.icon,color:xe.color,iconBackground:xe.iconBackground,defaultAgent:xe.defaultAgent??null,defaultModel:xe.defaultModel??null,defaultVariant:xe.defaultVariant??null})},[v,D]),Oe=c.useCallback(()=>{C(!0)},[C]),_e=c.useCallback(()=>{const xe=$r.getState();if(xe.available&&xe.info){k(!0);return}ke.checkForUpdates().then(()=>{const{available:bt,error:ht}=$r.getState();if(ht){Fe.error(l("sessions.sidebar.updateCheck.errorTitle"),{description:ht});return}if(!bt){Fe.success(l("sessions.sidebar.updateCheck.latestVersion"));return}k(!0)})},[l,ke]),Ve=c.useCallback(()=>{e&&q(!1),A(!0)},[e,q,A]),z=ke.available&&(ke.runtimeType==="desktop"||ke.runtimeType==="web"),pe=c.useCallback(()=>{bn.requestDirectoryDialog()},[]),Ae=c.useMemo(()=>O.flatMap(xe=>{const bt=ft(xe.path);return bt?[{id:xe.id,path:xe.path,label:xe.label,normalizedPath:bt,icon:xe.icon??void 0,color:xe.color??void 0,iconImage:xe.iconImage??void 0,iconBackground:xe.iconBackground??void 0,addedAt:xe.addedAt,lastOpenedAt:xe.lastOpenedAt,sidebarCollapsed:xe.sidebarCollapsed}]:[]}),[O]),Be=c.useMemo(()=>Ae.map(xe=>xe.normalizedPath),[Ae]),rt=cg(t?Be:R3);_0({enabled:t,normalizedProjects:Ae,gitRepoStatus:rt,setProjectRepoStatus:b,setProjectRootBranches:T});const Ge=tt(xe=>xe.isLoading),ut=c.useRef(!1);W&&x.has(W)&&(ut.current=!!x.get(W));const at=gs(xe=>xe.showArchivedSessions),wt=gs(xe=>xe.projectSortOrder),pt=gs(xe=>xe.stickyZoneHeaders),It=qt(xe=>xe.manualProjectOrder),Pt={isVisible:t,mobileVariant:e,onSessionSelected:n,allowReselect:r,hideDirectoryControls:i,showOnlyMainWorkspace:o,t:l,isTablet:ne,projects:O,activeProjectId:W,manualProjectOrder:It,worktreeMetadata:_,availableWorktreesByProject:oe,gitBranches:ye,gitRepoStatus:rt,updateStore:ke,showArchivedSessions:at,projectSortOrder:wt,projectRepoStatus:x,projectRootBranches:P,resolvedWorktreeTopologyKey:je,unresolvedWorktreeProjectPaths:ae,isSessionSearchOpen:a,sessionSearchQuery:d,editingProjectDialogId:v,updateDialogOpen:N},Rt=c.useRef(null),de=Rt.current;if(de){let xe=!1;for(const bt of Object.keys(Pt))Object.is(de[bt],Pt[bt])||(sn(`ui.session_sidebar.source.${bt}`),xe=!0);xe||sn("ui.session_sidebar.source.parent_or_context")}Rt.current=Pt;const We=c.useMemo(()=>fh(Ae,wt,It),[Ae,wt,It]),lt=M0({isVSCode:ve,projects:We}),H=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]),V=ve&&at,ge=gs(xe=>xe.sessionGroupingMode)==="by-worktree"&&!ve,st=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-ring 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-ring disabled:cursor-not-allowed",Ze="h-4.5 w-4.5",et=c.useCallback(()=>{e&&q(!1),te()},[e,te,q]),Ue=c.useMemo(()=>({projects:O,getCurrentProjects:()=>qt.getState().projects,rawWorktreesByProjectRef:K,getPublishedWorktreesByProject:()=>tt.getState().availableWorktreesByProject,resolveProject:xe=>Ti(xe),listProjectWorktrees:Nl,partitionWorktreesByRegisteredProject:Cl,worktreeMapsEqual:kl,recordWorktreesSeen:zc,publishTopology:xe=>{tt.setState(xe)},getRuntimeKey:ls,now:()=>Date.now()}),[O]),jt=c.useCallback(xe=>{const bt=xe.projectId?O.find(ht=>ht.id===xe.projectId)??null:xe.sourceDirectory?Ti(xe.sourceDirectory):null;return Q2(xe,{...Ue,projectRootBranch:bt?P.get(bt.id)??null:null})},[P,O,Ue]);c.useEffect(()=>{if(!ve)return to(xe=>{if(xe.type==="session-created"){Ce();return}if(xe.type==="worktree-changed")for(const bt of dg(xe.directories)){const ht=ft(bt.path),kt=ls(),Xe=Ke=>{!ht||ls()!==kt||tt.setState(Ye=>({worktreeDiscoveryByProject:new Map(Ye.worktreeDiscoveryByProject).set(ht,Ke)}))};Xe("loading"),Om(bt,null,Ue).then(()=>{!ht||ls()!==kt||(Xe("ready"),ee(Ke=>{if(!Ke.has(ht))return Ke;const Ye=new Set(Ke);return Ye.delete(ht),Ye}))}).catch(()=>{!ht||ls()!==kt||(Xe("error"),ee(Ke=>new Set(Ke).add(ht)))})}})},[ve,Ue]);const ze=c.useCallback(()=>{Ne.getState().closeMainSurfaces(),e&&q(!1),ce()},[e,ce,q]);return s.jsx(Wi,{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&&!ve?s.jsx(ij,{onNewSession:ze}):null,s.jsx(K0,{hideDirectoryControls:i,showProjectDisplayControls:!ve,showRecentControls:!ve,handleOpenDirectoryDialog:pe,onOpenScheduled:()=>{e&&q(!1),Z(!0)},onOpenMultiRun:et,canOpenMultiRun:O.length>0,onOpenArchive:()=>{e&&q(!1),le(!0)},headerActionIconClass:Ze,headerActionButtonClass:st,isSessionSearchOpen:a,setIsSessionSearchOpen:u,sessionSearchInputRef:w,sessionSearchQuery:d,setSessionSearchQuery:h,hasSessionSearchQuery:ue,searchMatchCount:f,collapseAllProjects:lt.actions.collapseAllProjects,expandAllProjects:lt.actions.expandAllProjects}),s.jsx(c3,{topology:{projects:We,availableWorktreesByProject:oe,knownDirectories:Q,isVSCode:ve,worktreeMetadata:_,gitBranches:ye,projectRepoStatus:x,projectRootBranches:P,lastRepoStatus:ut.current},view:{isVisible:t,hasSessionSearchQuery:ue,normalizedSessionSearchQuery:Se,activeProjectId:W,showInlineArchived:V,useGroupedSections:ge,homeDirectory:E,mobileVariant:e,hideDirectoryControls:i,showOnlyMainWorkspace:o,isDesktopShellRuntime:$,stickyZoneHeaders:pt,projectSortOrder:wt,emptyState:we,searchEmptyState:H,isSessionsLoading:Ge,isWorktreeTopologyLoading:Me,unresolvedWorktreeProjectPaths:ae,projectView:lt.state,onSearchMatchCountChange:p},actions:{rowActions:{allowReselect:r,onSessionSelected:n,isSessionSearchOpen:a,sessionSearchQuery:d,setSessionSearchQuery:h,setIsSessionSearchOpen:u},alwaysShowActions:U,notifyOnSubtasks:re,setActiveProjectIdOnly:F,setSessionSwitcherOpen:q,openNewSessionDraft:me,openNewWorktreeDialog:Oe,openWorktreesPage:xe=>{e&&q(!1),X(xe)},openProjectEditDialog:y,removeProject:L,reorderProjects:j,startSessionWorktreeMenuLoad:jt,initialActiveSessionByProject:R,persistActiveSessionByProject:I,projectViewActions:lt.actions}}),s.jsx(aj,{onOpenSettings:Ve,onOpenShortcuts:M,onOpenAbout:()=>G(!0),onOpenUpdate:_e,showRuntimeButtons:!ve,showUpdateButton:z}),s.jsx(Ad,{open:N,onOpenChange:k,info:ke.info,downloading:ke.downloading,downloaded:ke.downloaded,progress:ke.progress,error:ke.error,onDownload:ke.downloadUpdate,onRestart:ke.restartToUpdate,runtimeType:ke.runtimeType}),s.jsx(V0,{open:!!he,onOpenChange:xe=>{xe||y(null)},project:he,onSave:Te}),s.jsx(hh,{open:S,onOpenChange:C,onWorktreeCreated:(xe,bt)=>{if(Ne.getState().closeMainSurfaces(),e&&q(!1),bt?.sessionId){be(bt.sessionId,xe);return}ce({directoryOverride:xe,preserveDirectoryOverride:!0})}})]})})},B3=c.memo(O3),Cn=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,mn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},F3=()=>{const{t}=vt(),[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,y]=c.useState(!1),[m,x]=c.useState(new Set),b=tt(Y=>Y.getWorktreeMetadata),S=tt(Y=>Y.newSessionDraft),C=tt(Y=>Y.setNewSessionDraftTarget),N=tt(Y=>Y.setDraftBootstrapPendingDirectory),k=ug,R=tt(Y=>Y.deleteSessions),I=tt(Y=>Y.archiveSessions),P=Ne(Y=>Y.showDeletionDialog),T=Ne(Y=>Y.setShowDeletionDialog),E=is(Y=>Y.currentDirectory),O=is(Y=>Y.homeDirectory),W=is(Y=>Y.isHomeReady),L=qt(Y=>Y.projects),F=qt(Y=>Y.activeProjectId),{isMobile:D,isTablet:j,hasTouchInput:A}=Wn(),M=D||j||A,G=c.useMemo(()=>{const Re=(F?L.find(Ce=>Ce.id===F)??null:null)?.path??E;return mn(Re)},[F,E,L]),q=c.useCallback(Y=>{const Ce=mn(Y.projectDirectory)||G;return{id:(L.find(ae=>mn(ae.path)===Ce)??null)?.id??`path:${Ce}`,path:Ce}},[G,L]),Z=v&&m.size>0,le=c.useMemo(()=>{const Y=o?.worktree;return Y&&typeof Y.branch=="string"&&Y.branch.trim().length>0?!0:a.length>0&&a.every(({metadata:Re})=>typeof Re.branch=="string"&&Re.branch.trim().length>0)},[o?.worktree,a]),X=o?.mode==="worktree",te=X,re=g||!X||!le,Se=g||!X;c.useEffect(()=>{r||!W||L.length>0||(i(!0),n(!0))},[r,W,L.length]);const ue=c.useCallback(Y=>{l({sessions:Y.sessions,dateLabel:Y.dateLabel,mode:Y.mode??"session",worktree:Y.worktree??null})},[]),ye=c.useCallback(()=>{l(null),u([]),h(!1),p(!1),w(!1),y(!1),x(new Set)},[]),ve=c.useCallback(async Y=>{if(Y.sessions.length===0)return;if(Y.sessions.length===1){const ae=Y.sessions[0];await k(ae.id)?Fe.success(t("sessions.sidebar.session.delete.success")):Fe.error(t("sessions.sidebar.session.delete.error"));return}const Re=Y.sessions.map(ae=>ae.id),{deletedIds:Ce,failedIds:Me}=await R(Re);if(Ce.length>0){const ae=Me.length>0?Me.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Me.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Me.length}):Y.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:Y.dateLabel}):void 0;Fe.success(Ce.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ce.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ce.length}),{description:Cn(ae)})}Me.length>0&&Fe.error(Me.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Me.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Me.length}),{description:Cn(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[k,R,t]);c.useEffect(()=>bn.onDeleteRequest(Y=>{if(!P&&(Y.mode??"session")==="session"){ve(Y);return}ue(Y)}),[ue,P,ve]),c.useEffect(()=>bn.onDirectoryRequest(()=>{n(!0)}),[]),c.useEffect(()=>{if(!o){u([]),h(!1),p(!1),y(!1),x(new Set);return}const Y=o.sessions.map(Me=>{const ae=b(Me.id);return ae?{session:Me,metadata:ae}:null}).filter(Me=>!!Me);u(Y),h(!1),y(!1),x(new Set);const Re=new Map;if(o.worktree?.path&&Re.set(mn(o.worktree.path),o.worktree),Y.forEach(({metadata:Me})=>{Me.path&&Re.set(mn(Me.path),Me)}),Re.size===0){y(!0);return}let Ce=!1;return(async()=>{const Me=new Map,ae=new Set;await Promise.all(Array.from(Re.entries()).map(async([ee,K])=>{try{const $=await mg(K.path);Me.set(ee,$),$?.isDirty&&ae.add(ee)}catch{K.status&&(Me.set(ee,K.status),K.status.isDirty&&ae.add(ee))}})).catch(ee=>{console.warn("Failed to inspect worktree status before deletion:",ee)}),!Ce&&(x(ae),y(!0),l(ee=>{if(!ee?.worktree?.path)return ee;const K=mn(ee.worktree.path),$=Me.get(K);if(!$)return ee;const ne=ee.worktree.status;return ne?.isDirty===$.isDirty&&ne?.ahead===$.ahead&&ne?.behind===$.behind&&ne?.upstream===$.upstream?ee:{...ee,worktree:{...ee.worktree,status:$}}}),u(ee=>ee.map(K=>{const $=mn(K.metadata.path),ne=Me.get($);return ne?{session:K.session,metadata:{...K.metadata,status:ne}}:K})))})(),()=>{Ce=!0}},[o,b]),c.useEffect(()=>{le||h(!1)},[le]);const be=c.useCallback(async(Y,Re,Ce)=>{const Me=d&&le,ae=q(Y),ee=mn(Y.path),K=mn(ae.path);try{await zd(ae,Y,{deleteRemoteBranch:Me,deleteLocalBranch:Re});const $=mn(S?.directoryOverride);return S?.open&&ee&&$===ee&&K&&(N(null),C({projectId:ae.id,directoryOverride:K},{force:!0})),mn(E)===ee&&K&&is.getState().setDirectory(K,{showOverlay:!1}),!0}catch($){return Fe.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle",{name:ai(Y)}),{id:Ce,description:Cn($ instanceof Error?$.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[le,E,d,q,S?.directoryOverride,S?.open,N,C,t]),_=c.useCallback((Y,Re,Ce)=>{const Me=d&&le,ae=Fe.loading(t("sessions.sidebar.sessionDialogs.worktree.removingTitle",{name:ai(Y)}));(async()=>{try{if(Re.length>0){const{failedIds:$}=await I(Re);if($.length>0){Fe.error($.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:$.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:$.length}),{id:ae,description:Cn(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))});return}}if(!await be(Y,Ce,ae))return;const K=t(Me?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");Fe.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle",{name:ai(Y)}),{id:ae,description:Cn(K)})}catch(ee){Fe.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{id:ae,description:Cn(ee instanceof Error?ee.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})}})()},[I,le,d,be,t]),oe=c.useCallback(async()=>{if(o){w(!0);try{const Y=te,Re=Y&&d,Ce=Y&&f;if(X&&o.worktree){_(o.worktree,o.sessions.map(Me=>Me.id),Ce),ye();return}if(o.sessions.length===1){const Me=o.sessions[0];if(!await k(Me.id)){Fe.error(t("sessions.sidebar.session.delete.error")),w(!1);return}const ee=!X&&Y?t(Re?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;Fe.success(t("sessions.sidebar.session.delete.success"),{description:Cn(ee),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const Me=o.sessions.map($=>$.id);let ae=[],ee=[];const K=await R(Me);if(ae=K.deletedIds,ee=K.failedIds,ae.length>0){const $=!X&&Y?t(Re?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,U=[ee.length>0?ee.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ee.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ee.length}):o.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:o.dateLabel}):void 0,$].filter(Boolean).join(" ");Fe.success(ae.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ae.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ae.length}),{description:Cn(U||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(ee.length>0&&(Fe.error(ee.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ee.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ee.length}),{description:Cn(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),ae.length===0)){w(!1);return}}ye()}finally{w(!1)}}},[o,d,f,k,R,ye,te,X,_,t]),ce=o?.worktree??a[0]?.metadata??null,Q=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}):"",me=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(Y=>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:Y.title||t("sessions.sidebar.session.untitled")})]},Y.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(B,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),ce?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ce.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ce?Gr(ce.path,O):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),Z&&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,ke=X?le?s.jsxs("button",{type:"button",onClick:()=>{re||h(Y=>!Y)},disabled:re,className:Ie("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",re?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"),children:[d?s.jsx(B,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(B,{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,fe=X?s.jsxs("button",{type:"button",onClick:()=>{Se||p(Y=>!Y)},disabled:Se,className:Ie("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",Se?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"),children:[f?s.jsx(B,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(B,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,De=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:[fe,ke]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(dt,{variant:"ghost",onClick:ye,disabled:g,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(dt,{variant:"destructive",onClick:oe,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:()=>T(!P),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-ring","aria-pressed":!P,children:[P?s.jsx(B,{name:"checkbox-blank",className:"size-4"}):s.jsx(B,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(dt,{variant:"ghost",onClick:ye,disabled:g,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(dt,{variant:"destructive",onClick:oe,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")})]})]}),je=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:[M?s.jsx(Xo,{open:!!o,onClose:()=>{g||ye()},title:je,footer:s.jsx("div",{className:"flex justify-end gap-2",children:De}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[Q&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:Q}),me]})}):s.jsx(Ds,{open:!!o,onOpenChange:Y=>{if(!Y){if(g)return;ye()}},children:s.jsxs(Is,{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(Xs,{children:[s.jsxs(_s,{className:Ie(X&&"flex items-center gap-2"),children:[X&&s.jsx(B,{name:"delete-bin",className:"h-5 w-5"}),je]}),Q&&s.jsx(Ls,{children:Q})]}),s.jsx("div",{className:Ie(X&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:me}),s.jsx(wn,{className:"mt-2 gap-2 pt-1 pb-1",children:De})]})}),s.jsx(ph,{open:e,onOpenChange:n})]})};function _3(t){const e=nt.c(64),{t:n}=vt(),{value:r,onMoveSessionOnly:i,onMoveAllChanges:o,onCancel:l}=t,a=!!r;let u;e[0]!==l?(u=D=>{D||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(_s,{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(Ls,{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(Xs,{children:[h,w]}),e[14]=h,e[15]=w,e[16]=v):v=e[16];let y;e[17]!==n?(y=n("sessions.sidebar.session.moveToWorktree.confirm.sessionOnlyHelp"),e[17]=n,e[18]=y):y=e[18];let m;e[19]!==y?(m=s.jsx("p",{children:y}),e[19]=y,e[20]=m):m=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.session.moveToWorktree.confirm.allChangesHelp"),e[21]=n,e[22]=x):x=e[22];let b;e[23]!==x?(b=s.jsx("p",{children:x}),e[23]=x,e[24]=b):b=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 C;e[28]!==n?(C=n("sessions.sidebar.session.moveToWorktree.confirm.baseWarning"),e[28]=n,e[29]=C):C=e[29];let N;e[30]!==C?(N=s.jsx("p",{children:C}),e[30]=C,e[31]=N):N=e[31];let k;e[32]!==m||e[33]!==b||e[34]!==S||e[35]!==N?(k=s.jsxs("div",{className:"space-y-2 typography-ui-label text-muted-foreground",children:[m,b,S,N]}),e[32]=m,e[33]=b,e[34]=S,e[35]=N,e[36]=k):k=e[36];let R;e[37]!==n?(R=n("sessions.sidebar.session.moveToWorktree.confirm.cancel"),e[37]=n,e[38]=R):R=e[38];let I;e[39]!==l||e[40]!==R?(I=s.jsx(dt,{type:"button",variant:"neutral","data-session-worktree-move-action":"cancel",onClick:l,children:R}),e[39]=l,e[40]=R,e[41]=I):I=e[41];let P;e[42]!==n?(P=n("sessions.sidebar.session.moveToWorktree.confirm.allChanges"),e[42]=n,e[43]=P):P=e[43];let T;e[44]!==o||e[45]!==P?(T=s.jsx(dt,{type:"button",variant:"outline","data-session-worktree-move-action":"all-changes",onClick:o,children:P}),e[44]=o,e[45]=P,e[46]=T):T=e[46];let E;e[47]!==n?(E=n("sessions.sidebar.session.moveToWorktree.confirm.sessionOnly"),e[47]=n,e[48]=E):E=e[48];let O;e[49]!==i||e[50]!==E?(O=s.jsx(dt,{type:"button",autoFocus:!0,"data-session-worktree-move-action":"session-only",onClick:i,children:E}),e[49]=i,e[50]=E,e[51]=O):O=e[51];let W;e[52]!==I||e[53]!==T||e[54]!==O?(W=s.jsxs(wn,{className:"gap-2 sm:justify-end",children:[I,T,O]}),e[52]=I,e[53]=T,e[54]=O,e[55]=W):W=e[55];let L;e[56]!==k||e[57]!==W||e[58]!==v?(L=s.jsxs(Is,{id:"session-worktree-move-confirm-dialog",showCloseButton:!1,className:"max-w-md gap-5",children:[v,k,W]}),e[56]=k,e[57]=W,e[58]=v,e[59]=L):L=e[59];let F;return e[60]!==a||e[61]!==u||e[62]!==L?(F=s.jsx(Ds,{open:a,onOpenChange:u,children:L}),e[60]=a,e[61]=u,e[62]=L,e[63]=F):F=e[63],F}function Lm(t){if(!t||!t.trim())return{valid:!1,error:"required"};try{return zu.CronExpressionParser.parse(t),{valid:!0}}catch(e){return{valid:!1,error:e instanceof Error?e.message:"Invalid cron expression"}}}function L3(t,e,n=4){try{const r=e?{tz:e,currentDate:new Date}:{currentDate:new Date},i=zu.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 $3=[{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"}],W3={"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"},Yn=t=>W3[t]??t,$m=[0,1,2,3,4,5,6],Hc="flex h-6 w-6 cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0",ha=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?[...new Set(Intl.supportedValuesOf("timeZone").map(Yn))]:["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],Gc=()=>{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}`},Ao=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},qc=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},z3=(t,e,n)=>{const r=Ao(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},Qc=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),V3=(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},U3=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}},Kn=(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"},Yc=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:jr(t,{min:1,max:12}),xo=t=>/^[0-5][0-9]$/.test(t)?t:jr(t,{max:59}),K3=(t,e)=>jr(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),Xc=(t,e)=>jr(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),H3=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}},G3=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}},q3=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return $m.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},Q3=(t,e)=>[...t.slice(e),...t.slice(0,e)],Ws=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},Jc=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=U3(n),e[0]=n,e[1]=h):h=e[1];const f=h,p=mt.useRef(null),g=mt.useRef(null),[w,v]=mt.useState(null),[y,m]=mt.useState(null),x=mt.useRef(null),b=mt.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=Y=>{x.current=Y,v(Y)},e[2]=S):S=e[2];const C=S;let N;e[3]===Symbol.for("react.memo_cache_sentinel")?(N=Y=>{b.current=Y,m(Y)},e[3]=N):N=e[3];const k=N,R=s4,I=n4,P=r4;let T;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==i?(T=Y=>{const Re=Y.replace(/\D/g,"").slice(0,2);C(Re),Re.length===2&&(r(i?P(R(Re),f.minute):Kn(Yc(Re),f.minute,f.meridiem)),C(null),g.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=i,e[8]=T):T=e[8];const E=T;let O;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==i?(O=()=>{const Y=x.current;if(Y!==null&&(C(null),Y.length!==0)){if(i){r(P(R(Y.padStart(2,"0")),f.minute));return}r(Kn(Yc(Y.padStart(2,"0")),f.minute,f.meridiem))}},e[9]=r,e[10]=f.meridiem,e[11]=f.minute,e[12]=i,e[13]=O):O=e[13];const W=O;let L;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==i?(L=Y=>{const Re=Y.replace(/\D/g,"").slice(0,2);k(Re),Re.length===2&&(r(i?P(f.hour24,xo(Re)):Kn(f.hour12,xo(Re),f.meridiem)),k(null))},e[14]=r,e[15]=f.hour12,e[16]=f.hour24,e[17]=f.meridiem,e[18]=i,e[19]=L):L=e[19];const F=L;let D;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==i?(D=()=>{const Y=b.current;Y!==null&&(k(null),Y.length!==0&&r(i?P(f.hour24,xo(Y.padStart(2,"0"))):Kn(f.hour12,xo(Y.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]=D):D=e[25];const j=D;let A;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==i?(A=Y=>r(i?P(I(f.hour24,Y),f.minute):Kn(K3(f.hour12,Y),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]=A):A=e[32];const M=A;let G;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==i?(G=Y=>r(i?P(f.hour24,Xc(f.minute,Y)):Kn(f.hour12,Xc(f.minute,Y),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]=G):G=e[39];const q=G;let Z;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(Z=Y=>{Y!==f.meridiem&&r(Kn(f.hour12,f.minute,Y))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=Z):Z=e[44];const le=Z;let X;e[45]!==W||e[46]!==M?(X=Y=>{if(Y.key==="ArrowRight"){Y.preventDefault(),W(),g.current?.focus();return}(Y.key==="ArrowUp"||Y.key==="ArrowDown")&&(Y.preventDefault(),C(null),M(Y.key==="ArrowUp"?1:-1))},e[45]=W,e[46]=M,e[47]=X):X=e[47];const te=X;let re;e[48]!==j||e[49]!==q?(re=Y=>{if(Y.key==="ArrowLeft"&&(Y.currentTarget.selectionStart??0)===0){Y.preventDefault(),j(),p.current?.focus();return}(Y.key==="ArrowUp"||Y.key==="ArrowDown")&&(Y.preventDefault(),k(null),q(Y.key==="ArrowUp"?1:-1))},e[48]=j,e[49]=q,e[50]=re):re=e[50];const Se=re,ue=i?"px-2":"pl-2 pr-1";let ye;e[51]!==ue?(ye=Ie("oc-surface-elevated inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-surface-elevated focus-within:ring-1 focus-within:ring-ring focus-within:border-ring",ue),e[51]=ue,e[52]=ye):ye=e[52];const ve=w??(i?f.hour24:f.hour12);let be;e[53]!==E?(be=Y=>E(Y.target.value),e[53]=E,e[54]=be):be=e[54];let _;e[55]===Symbol.for("react.memo_cache_sentinel")?(_=()=>C(""),e[55]=_):_=e[55];let oe;e[56]!==W||e[57]!==o||e[58]!==te||e[59]!==ve||e[60]!==be?(oe=s.jsx("input",{ref:p,inputMode:"numeric",value:ve,onChange:be,onKeyDown:te,onFocus:_,onBlur:W,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]=W,e[57]=o,e[58]=te,e[59]=ve,e[60]=be,e[61]=oe):oe=e[61];let ce;e[62]===Symbol.for("react.memo_cache_sentinel")?(ce=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=ce):ce=e[62];const Q=y??f.minute;let me;e[63]!==F?(me=Y=>F(Y.target.value),e[63]=F,e[64]=me):me=e[64];let ke;e[65]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>k(""),e[65]=ke):ke=e[65];let fe;e[66]!==j||e[67]!==l||e[68]!==Se||e[69]!==Q||e[70]!==me?(fe=s.jsx("input",{ref:g,inputMode:"numeric",value:Q,onChange:me,onKeyDown:Se,onFocus:ke,onBlur:j,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]=j,e[67]=l,e[68]=Se,e[69]=Q,e[70]=me,e[71]=fe):fe=e[71];let De;e[72]!==u||e[73]!==f.meridiem||e[74]!==a||e[75]!==d||e[76]!==le||e[77]!==i?(De=i?null:s.jsxs(Vs,{value:f.meridiem,onValueChange:Y=>le(Y),children:[s.jsx(Us,{"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(Ms,{})}),s.jsxs(Ks,{children:[s.jsx(as,{value:"AM",children:u}),s.jsx(as,{value:"PM",children:d})]})]}),e[72]=u,e[73]=f.meridiem,e[74]=a,e[75]=d,e[76]=le,e[77]=i,e[78]=De):De=e[78];let je;return e[79]!==ye||e[80]!==oe||e[81]!==fe||e[82]!==De?(je=s.jsxs("div",{className:ye,children:[oe,ce,fe,De]}),e[79]=ye,e[80]=oe,e[81]=fe,e[82]=De,e[83]=je):je=e[83],je},Zc=t=>new Date(t.getFullYear(),t.getMonth(),1),Y3=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},ed=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),X3=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"]},td=(t,e)=>{const n=Yn(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:X3(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Gc(),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:Yn(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:Gc(),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}}},J3=(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(!Lm(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")},Z3=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))},e4=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()?Lm(l):null,e[0]=l,e[1]=a):a=e[1];const u=a;let d;e:{if(!u?.valid||!l.trim()){let A;e[2]===Symbol.for("react.memo_cache_sentinel")?(A=[],e[2]=A):A=e[2],d=A;break e}let j;e[3]!==l||e[4]!==n.schedule.timezone?(j=L3(l,n.schedule.timezone),e[3]=l,e[4]=n.schedule.timezone,e[5]=j):j=e[5],d=j}const h=d;let f;e[6]!==n.schedule.timezone||e[7]!==i?(f=j=>new Intl.DateTimeFormat(i,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(j),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(Ws,{htmlFor:"sched-cron",required:!0,children:g}),e[11]=g,e[12]=w):w=e[12];let v;e[13]!==r?(v=j=>r(A=>({...A,schedule:{...A.schedule,cronExpression:j.target.value}})),e[13]=r,e[14]=v):v=e[14];let y;e[15]!==o?(y=o("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=o,e[16]=y):y=e[16];let m;e[17]!==l||e[18]!==v||e[19]!==y?(m=s.jsx(An,{id:"sched-cron",value:l,onChange:v,placeholder:y,className:"w-full max-w-xs font-mono"}),e[17]=l,e[18]=v,e[19]=y,e[20]=m):m=e[20];let x;e[21]!==l||e[22]!==u||e[23]!==o?(x=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]=x):x=e[24];let b;e[25]!==w||e[26]!==m||e[27]!==x?(b=s.jsxs("div",{className:"flex flex-col gap-1",children:[w,m,x]}),e[25]=w,e[26]=m,e[27]=x,e[28]=b):b=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 C;e[33]!==o?(C=o("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=o,e[34]=C):C=e[34];let N;e[35]!==C?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:C}),e[35]=C,e[36]=N):N=e[36];let k;e[37]!==r||e[38]!==o?(k=$3.map(j=>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(A=>({...A,schedule:{...A.schedule,cronExpression:j.expression}})),children:[s.jsx("span",{className:"font-mono",children:j.expression}),s.jsx("span",{className:"text-muted-foreground",children:o(j.labelKey)})]},j.expression)),e[37]=r,e[38]=o,e[39]=k):k=e[39];let R;e[40]!==k?(R=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:k}),e[40]=k,e[41]=R):R=e[41];let I;e[42]!==N||e[43]!==R?(I=s.jsxs("div",{className:"flex flex-col gap-1",children:[N,R]}),e[42]=N,e[43]=R,e[44]=I):I=e[44];let P;e[45]!==o?(P=o("sessions.scheduledTasks.editor.timezone.label"),e[45]=o,e[46]=P):P=e[46];let T;e[47]!==P?(T=s.jsx(Ws,{children:P}),e[47]=P,e[48]=T):T=e[48];let E;e[49]!==r?(E=j=>{r(A=>({...A,schedule:{...A.schedule,timezone:j}}))},e[49]=r,e[50]=E):E=e[50];let O;e[51]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(Us,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Ms,{})}),e[51]=O):O=e[51];let W;e[52]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(Ks,{children:ha.map(o4)}),e[52]=W):W=e[52];let L;e[53]!==n.schedule.timezone||e[54]!==E?(L=s.jsxs(Vs,{value:n.schedule.timezone,onValueChange:E,children:[O,W]}),e[53]=n.schedule.timezone,e[54]=E,e[55]=L):L=e[55];let F;e[56]!==T||e[57]!==L?(F=s.jsxs("div",{className:"flex flex-col gap-1",children:[T,L]}),e[56]=T,e[57]=L,e[58]=F):F=e[58];let D;return e[59]!==b||e[60]!==S||e[61]!==I||e[62]!==F?(D=s.jsxs("div",{className:"flex flex-col gap-3",children:[b,S,I,F]}),e[59]=b,e[60]=S,e[61]=I,e[62]=F,e[63]=D):D=e[63],D};function t4(t){const{open:e,task:n,onOpenChange:r,onSave:i}=t,{t:o,locale:l}=vt(),a=Yt(z=>z.loadProviders),u=Yt(z=>z.loadAgents),d=Yt(z=>z.providers),h=Yt(z=>z.currentProviderId),f=Yt(z=>z.currentModelId),p=Yt(z=>z.currentVariant||""),g=Yt(z=>z.currentAgentName||""),w=Ne(z=>z.timeFormatPreference),v=Ne(z=>z.weekStartPreference),y=Ne(z=>z.isMobile),[m,x]=mt.useState(()=>td(n,{providerID:h,modelID:f,variant:p,agent:g})),[b,S]=mt.useState(!1),[C,N]=mt.useState(!1),[k,R]=mt.useState(!1),[I,P]=mt.useState(""),[T,E]=mt.useState(!1),[O,W]=mt.useState(""),[L,F]=mt.useState(!1),[D,j]=mt.useState(""),[A,M]=mt.useState(()=>{const z=Ao(n?.schedule?.date||"")||new Date;return new Date(z.getFullYear(),z.getMonth(),1)}),G=mt.useRef(null),q=mt.useRef(null),Z=mt.useRef(null),le=mt.useRef(null),X=mt.useRef(null),te=mt.useMemo(()=>G3(l),[l]),re=mt.useMemo(()=>H3(l),[l]),Se=mt.useMemo(()=>w==="24h"?!0:w==="12h"?!1:te,[w,te]),ue=mt.useMemo(()=>v==="sunday"?0:v==="monday"?1:re,[v,re]),ye=mt.useMemo(()=>{const z=q3(l);return Q3($m.map(pe=>({value:pe,label:z[pe]||""})),ue)},[l,ue]);mt.useEffect(()=>{e&&(a({source:"scheduledTaskEditor"}),u({source:"scheduledTaskEditor"}))},[e,a,u]),mt.useEffect(()=>{if(!e)return;x(td(n,{providerID:h,modelID:f,variant:p,agent:g}));const z=Ao(n?.schedule?.date||"")||new Date;M(new Date(z.getFullYear(),z.getMonth(),1)),N(!1),E(!1),R(!1),W(""),P("")},[e,n,h,f,p,g]),mt.useEffect(()=>{if(!C)return;const z=pe=>{G.current&&!G.current.contains(pe.target)&&N(!1)};return document.addEventListener("mousedown",z),()=>{document.removeEventListener("mousedown",z)}},[C]);const ve=mt.useMemo(()=>{const pe=d.find(Ae=>Ae.id===m.execution.providerID)?.models?.find(Ae=>Ae.id===m.execution.modelID);return pe?.variants?Object.keys(pe.variants):[]},[d,m.execution.providerID,m.execution.modelID]),be=ve.length>0,_=mt.useMemo(()=>!be||!m.execution.variant?"__default":ve.includes(m.execution.variant)?m.execution.variant:"__default",[m.execution.variant,be,ve]);mt.useEffect(()=>{be||!m.execution.variant||x(z=>({...z,execution:{...z.execution,variant:""}}))},[be,m.execution.variant]);const oe=mt.useCallback((z,pe)=>{x(Ae=>{const Be=new Set(Ae.schedule.weekdays);return pe?Be.add(z):Be.delete(z),{...Ae,schedule:{...Ae.schedule,weekdays:Array.from(Be).sort((rt,Ge)=>rt-Ge)}}})},[]),ce=mt.useCallback((z,pe)=>{x(Ae=>{const Be=Ae.schedule.times.slice();return Be[z]=pe,{...Ae,schedule:{...Ae.schedule,times:Be}}})},[]),Q=mt.useCallback(z=>{x(pe=>{const Ae=pe.schedule.times.filter((Be,rt)=>rt!==z);return{...pe,schedule:{...pe.schedule,times:Ae.length>0?Ae:["09:00"]}}})},[]),me=mt.useCallback(()=>{x(z=>({...z,schedule:{...z.schedule,times:[...z.schedule.times,"12:00"]}}))},[]),ke=mt.useMemo(()=>Y3(),[]),fe=mt.useMemo(()=>Zc(ke),[ke]),De=mt.useMemo(()=>{const z=Ao(m.schedule.onceDate);return z?ed(z,ke)?o("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(l,{weekday:"short"}).format(z):null},[m.schedule.onceDate,l,o,ke]),je=mt.useMemo(()=>Zc(A).getTime()<=fe.getTime(),[A,fe]),Y=mt.useMemo(()=>ye.map(z=>z.label),[ye]),Re=mt.useCallback(z=>{x(pe=>({...pe,schedule:{...pe.schedule,onceDate:z}}))},[]),Ce=mt.useCallback((z,pe)=>{if(z.startsWith("/")){const Ge=z.indexOf(" "),ut=z.indexOf(`
|
|
890
|
+
`),at=Math.min(Ge===-1?z.length:Ge,ut===-1?z.length:ut);if(pe<=at&&Ge===-1){W(z.substring(1,at)),E(!0),R(!1),F(!1);return}}E(!1);const Ae=z.substring(0,pe),Be=Ae.lastIndexOf("#");if(Be!==-1){const Ge=Be>0?Ae[Be-1]:null,ut=Ae.substring(Be+1);if((!Ge||/\s/.test(Ge))&&!ut.includes(" ")&&!ut.includes(`
|
|
891
|
+
`)){j(ut),F(!0),R(!1);return}}F(!1);const rt=Ae.lastIndexOf("@");if(rt!==-1){const Ge=rt>0?Ae[rt-1]:null,ut=Ae.substring(rt+1);(!Ge||/\s/.test(Ge))&&!ut.includes(" ")&&!ut.includes(`
|
|
892
|
+
`)?(P(ut),R(!0)):R(!1);return}R(!1)},[]),Me=mt.useCallback(z=>{x(pe=>({...pe,execution:{...pe.execution,prompt:z}}))},[]),ae=mt.useCallback(z=>{const pe=m.execution.prompt,Be=q.current?.selectionStart??pe.length,Ge=pe.substring(0,Be).lastIndexOf("@"),ut=z.relativePath&&z.relativePath.trim().length>0?z.relativePath.trim():z.path||z.name,at=Ge!==-1?Ge:Be,wt=`${pe.substring(0,at)}@${ut} ${pe.substring(Be)}`,pt=at+ut.length+2;Me(wt),R(!1),P(""),requestAnimationFrame(()=>{const It=q.current;It&&(It.selectionStart=pt,It.selectionEnd=pt,It.focus()),Ce(wt,pt)})},[m.execution.prompt,Me,Ce]),ee=mt.useCallback(z=>{const pe=m.execution.prompt,Be=q.current?.selectionStart??pe.length,Ge=pe.substring(0,Be).lastIndexOf("@"),ut=Ge!==-1?Ge:Be,at=`${pe.substring(0,ut)}@${z} ${pe.substring(Be)}`,wt=ut+z.length+2;Me(at),R(!1),P(""),requestAnimationFrame(()=>{const pt=q.current;pt&&(pt.selectionStart=wt,pt.selectionEnd=wt,pt.focus()),Ce(at,wt)})},[m.execution.prompt,Me,Ce]),K=mt.useCallback(z=>{const pe=`/${z.name} `;Me(pe),E(!1),W(""),F(!1),requestAnimationFrame(()=>{const Ae=q.current;Ae&&(Ae.focus(),Ae.selectionStart=Ae.value.length,Ae.selectionEnd=Ae.value.length),Ce(pe,pe.length)})},[Me,Ce]),$=mt.useCallback((z,pe)=>{const Ae=m.execution.prompt,rt=q.current?.selectionStart??Ae.length,ut=Ae.substring(0,rt).lastIndexOf("#"),at=ut!==-1?ut:rt,wt=`${Ae.substring(0,at)}#${pe} ${Ae.substring(rt)}`,pt=at+pe.length+2;Me(wt),F(!1),j(""),requestAnimationFrame(()=>{const It=q.current;It&&(It.selectionStart=pt,It.selectionEnd=pt,It.focus()),Ce(wt,pt)})},[m.execution.prompt,Me,Ce]),ne=mt.useCallback(z=>{if(T&&le.current&&(z.key==="Enter"||z.key==="ArrowUp"||z.key==="ArrowDown"||z.key==="Escape"||z.key==="Tab")){z.preventDefault(),le.current.handleKeyDown(z.key);return}k&&Z.current&&(z.key==="Enter"||z.key==="ArrowUp"||z.key==="ArrowDown"||z.key==="Escape"||z.key==="Tab")&&(z.preventDefault(),Z.current.handleKeyDown(z.key)),L&&X.current&&(z.key==="Enter"||z.key==="ArrowUp"||z.key==="ArrowDown"||z.key==="Escape"||z.key==="Tab")&&(z.preventDefault(),X.current.handleKeyDown(z.key))},[T,k,L]),U=mt.useCallback(async()=>{const z=J3(m,o);if(z){Fe.error(z);return}const pe={...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:Z3(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(pe),r(!1)}catch(Ae){Fe.error(Ae instanceof Error?Ae.message:o("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[m,r,i,o]),we=mt.useId(),he=mt.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]'),[]),Te=o(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),Oe=o("sessions.scheduledTasks.editor.description"),_e=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(Ws,{htmlFor:"sched-name",required:!0,children:o("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(An,{id:"sched-name",value:m.name,onChange:z=>x(pe=>({...pe,name:z.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(Ws,{children:o("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(Vs,{value:m.schedule.kind,onValueChange:z=>{x(pe=>({...pe,schedule:{...pe.schedule,kind:z,...z==="cron"&&!pe.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx(Us,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Ms,{children:z=>o(z==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":z==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":z==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(Ks,{children:[s.jsx(as,{value:"daily",children:o("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(as,{value:"weekly",children:o("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(as,{value:"once",children:o("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(as,{value:"cron",children:o("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),m.schedule.kind==="cron"?s.jsx(e4,{draft:m,setDraft:x,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:G,children:[s.jsx(Ws,{children:o("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:Ie(bu({size:"default"}),"w-fit max-w-full"),onClick:()=>N(z=>!z),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(B,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:z3(m.schedule.onceDate,o("sessions.scheduledTasks.editor.date.placeholder"),l)})]}),s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),C?s.jsxs("div",{className:"oc-surface-elevated absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-surface-elevated 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:()=>M(z=>Qc(z,-1)),"aria-label":o("sessions.scheduledTasks.editor.date.previousMonth"),disabled:je,children:s.jsx(B,{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(A)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>M(z=>Qc(z,1)),"aria-label":o("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(B,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:Y.map((z,pe)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:z},`${z}-${pe}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:V3(A,ue).map(({date:z,inCurrentMonth:pe})=>{const Ae=qc(z),Be=Ae===m.schedule.onceDate,rt=ed(z,ke),Ge=z.getTime()<ke.getTime(),ut=Be?"bg-interactive-selection text-interactive-selection-foreground":Ge?"text-muted-foreground/40":pe?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{Ge||(Re(Ae),N(!1))},disabled:Ge,className:["h-8 rounded-md typography-ui-label",ut,rt&&!Be?"ring-1 ring-inset ring-ring bg-interactive-selection text-interactive-selection-foreground":"",Ge?"cursor-not-allowed opacity-45":""].join(" "),children:z.getDate()},Ae)})}),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:De||""}),s.jsx(dt,{type:"button",size:"xs",variant:"ghost",onClick:()=>{Re(qc(ke)),M(new Date(ke.getFullYear(),ke.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(Ws,{children:o("sessions.scheduledTasks.editor.time.label")}),s.jsx(Jc,{value:m.schedule.onceTime,use24Hour:Se,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:z=>x(pe=>({...pe,schedule:{...pe.schedule,onceTime:z}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Ws,{children:o("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Vs,{value:m.schedule.timezone,onValueChange:z=>{x(pe=>({...pe,schedule:{...pe.schedule,timezone:z}}))},children:[s.jsx(Us,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Ms,{})}),s.jsx(Ks,{children:ha.map(z=>s.jsx(as,{value:z,children:z},z))})]})]})]})]}):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(Ws,{children:o("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:ye.map(z=>{const pe=m.schedule.weekdays.includes(z.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",pe?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(hr,{checked:pe,onChange:Ae=>oe(z.value,Ae),ariaLabel:z.label}),s.jsx("button",{type:"button",onClick:()=>oe(z.value,!pe),className:"group-hover:text-foreground",children:z.label})]},z.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Ws,{children:o("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:m.schedule.times.map((z,pe)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Jc,{value:z,use24Hour:Se,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:Ae=>ce(pe,Ae)}),m.schedule.times.length>1?s.jsx(dt,{type:"button",size:"icon",variant:"ghost",onClick:()=>Q(pe),"aria-label":o("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(B,{name:"close",className:"h-4 w-4"})}):null]},pe))}),s.jsx("div",{children:s.jsxs(dt,{type:"button",size:"sm",variant:"outline",onClick:me,children:[s.jsx(B,{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(Ws,{children:o("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Vs,{value:m.schedule.timezone,onValueChange:z=>{x(pe=>({...pe,schedule:{...pe.schedule,timezone:z}}))},children:[s.jsx(Us,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Ms,{})}),s.jsx(Ks,{children:ha.map(z=>s.jsx(as,{value:z,children:z},z))})]})]})]}),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(Ws,{required:!0,children:o("sessions.scheduledTasks.editor.model.label")}),s.jsx(fg,{providerId:m.execution.providerID,modelId:m.execution.modelID,onChange:(z,pe)=>{x(Ae=>({...Ae,execution:{...Ae.execution,providerID:z,modelID:pe,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ws,{children:o("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(Vs,{value:_,disabled:!be,onValueChange:z=>{x(pe=>({...pe,execution:{...pe.execution,variant:z==="__default"?"":z}}))},children:[s.jsx(Us,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Ms,{children:z=>z==="__default"?o("sessions.scheduledTasks.editor.thinkingLevel.default"):z})}),s.jsxs(Ks,{children:[s.jsx(as,{value:"__default",children:o("sessions.scheduledTasks.editor.thinkingLevel.default")}),ve.map(z=>s.jsx(as,{value:z,children:z},z))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ws,{children:o("sessions.scheduledTasks.editor.agent.label")}),s.jsx(hg,{agentName:m.execution.agent,filter:z=>xu(z.mode),onChange:z=>x(pe=>({...pe,execution:{...pe.execution,agent:z}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ws,{htmlFor:"sched-prompt",required:!0,children:o("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(ur,{id:"sched-prompt",ref:q,value:m.execution.prompt,onChange:z=>{const pe=z.target.value;Me(pe);const Ae=z.target.selectionStart??pe.length;Ce(pe,Ae)},onKeyDown:ne,rows:8,placeholder:o("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),T?s.jsx(Cu,{ref:le,searchQuery:O,onCommandSelect:K,onClose:()=>E(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,k?s.jsx(Nu,{ref:Z,searchQuery:I,onFileSelect:ae,onAgentSelect:ee,onClose:()=>R(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,L?s.jsx(Au,{ref:X,searchQuery:D,onSnippetSelect:$,onClose:()=>F(!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(hr,{checked:m.execution.goalTokenBudget!==null,onChange:z=>x(pe=>({...pe,execution:{...pe.execution,goalTokenBudget:z?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(pg,{value:m.execution.goalTokenBudget,onValueChange:z=>{typeof z=="number"&&Number.isFinite(z)&&z>0&&x(pe=>({...pe,execution:{...pe.execution,goalTokenBudget:Math.floor(z)}}))},min:1e3,max:1e8,step:5e4}):null]}):null]}),Ve=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(hr,{checked:m.enabled,onChange:z=>x(pe=>({...pe,enabled:z})),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(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie(Hc),onClick:()=>x(z=>({...z,execution:{...z.execution,permissionAutoAccept:!z.execution.permissionAutoAccept}})),"aria-pressed":m.execution.permissionAutoAccept,"aria-label":o("sessions.scheduledTasks.editor.permissionAutoAccept.aria"),children:m.execution.permissionAutoAccept?s.jsx(B,{name:"shield-check",className:"h-[18px] w-[18px]",style:{color:"var(--status-info)"},"aria-hidden":"true"}):s.jsx(B,{name:"shield-user",className:"h-[18px] w-[18px]","aria-hidden":"true"})})}),s.jsx(At,{side:"top",sideOffset:6,children:o("sessions.scheduledTasks.editor.permissionAutoAccept.label")})]}),s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie(Hc,m.execution.goalEnabled&&"text-[var(--status-info)]"),onClick:()=>x(z=>({...z,execution:{...z.execution,goalEnabled:!z.execution.goalEnabled}})),"aria-pressed":m.execution.goalEnabled,"aria-label":o("sessions.scheduledTasks.editor.goal.aria"),children:m.execution.goalEnabled?s.jsx(B,{name:"target-fill",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"}):s.jsx(B,{name:"target",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"})})}),s.jsx(At,{side:"top",sideOffset:6,children:o("sessions.scheduledTasks.editor.goal.label")})]}),s.jsx(dt,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:b,children:o("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(dt,{type:"button",size:"sm",onClick:U,disabled:b,children:o(b?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return y?s.jsx(Xo,{open:e,title:Te,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:z=>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:Te}),z]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:Oe})]}),footer:Ve,children:_e}):s.jsx(Ds,{open:e,onOpenChange:z=>{!z&&he()||r(z)},children:s.jsxs(Is,{"aria-describedby":we,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ls,{id:we,className:"sr-only",children:Oe}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(_s,{className:"typography-ui-label font-medium text-foreground",children:Te}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:Oe})]})}),s.jsx(Na,{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:_e})}),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:Ve})})]})})}function s4(t){return jr(t,{min:0,max:23})}function n4(t,e){return jr(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function r4(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 o4(t){return s.jsx(as,{value:t,children:t},t)}const i4=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=i4(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:Yn(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:Yn(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:Yn(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:Yn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},l4=(t,e)=>!t||!Number.isFinite(t)?"":gg(t,e),sd=(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})},c4={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"}},d4=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function u4(){const{t}=vt(),e=Ne(j=>j.isScheduledTasksDialogOpen),n=Ne(j=>j.setScheduledTasksDialogOpen),r=Ne(j=>j.isMobile),i=Ne(j=>j.timeFormatPreference),o=qt(j=>j.projects),l=qt(j=>j.getActiveProject()),a=is(j=>j.homeDirectory),{currentTheme:u}=nr(),[d,h]=mt.useState(""),[f,p]=mt.useState([]),[g,w]=mt.useState(!0),[v,y]=mt.useState(!1),[m,x]=mt.useState(null),[b,S]=mt.useState(null),C=mt.useMemo(()=>o.find(j=>j.id===d)||null,[o,d]),N=mt.useCallback(j=>{const A=j.label?.trim()||Ln(j.path,a||void 0),M=j.icon?Ia[j.icon]:null,G=j.color?Ta[j.color]:void 0,q=M?s.jsx(B,{name:M,className:"h-3.5 w-3.5 shrink-0",style:G?{color:G}:void 0}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:G?{color:G}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[j.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:j.iconBackground?{backgroundColor:j.iconBackground}:void 0,children:s.jsx(Ea,{project:{id:j.id,iconImage:j.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:A})]})},[a,u.metadata.variant,u.colors.surface.foreground]),k=mt.useCallback(async(j,A)=>{if(!j){p([]);return}A?.silent||w(!0);try{const M=await yx(j);M.sort((G,q)=>{if(G.enabled!==q.enabled)return G.enabled?-1:1;const Z=G.name.localeCompare(q.name);return Z!==0?Z:(G.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(q.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),p(M)}catch(M){Fe.error(M instanceof Error?M.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),A?.silent||p([])}finally{A?.silent||w(!1)}},[t]);mt.useEffect(()=>{if(!e)return;const j=l?.id||o[0]?.id||"";h(j),j?k(j):(p([]),w(!1))},[e,l,o,k]),mt.useEffect(()=>{if(!e)return;let j=null;const A=to(M=>{M.type==="scheduled-task-ran"&&M.projectId===d&&(j&&clearTimeout(j),j=setTimeout(()=>{k(d,{silent:!0})},400))});return()=>{j&&clearTimeout(j),A()}},[e,d,k]);const R=mt.useCallback(async j=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Bl(d,j),await k(d),Fe.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,k,t]),I=mt.useCallback(async(j,A)=>{if(d){S(j.id),p(M=>M.map(G=>G.id===j.id?{...G,enabled:A}:G));try{j.loopFile?await wx(d,j.id,A):await Bl(d,{...j,enabled:A}),await k(d,{silent:!0})}catch(M){Fe.error(M instanceof Error?M.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await k(d,{silent:!0})}finally{S(null)}}},[d,k,t]),P=mt.useCallback(async j=>{if(!(!d||!window.confirm(j.loopFile?t("sessions.scheduledTasks.dialog.confirm.deleteLoopFile",{taskName:j.name}):t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:j.name})))){S(j.id);try{j.loopFile?await Sx(d,j.id):await vx(d,j.id),await k(d,{silent:!0}),Fe.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(M){Fe.error(M instanceof Error?M.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{S(null)}}},[d,k,t]),T=mt.useCallback(j=>{if(!j.loopFile){x(j),y(!0);return}C?.path&&(n(!1),pn.getState().setSelectedPath(C.path,j.loopFile,{allowOutsideRoot:!0}),Ne.getState().openContextFile(C.path,j.loopFile))},[C?.path,n]),E=mt.useCallback(async j=>{if(d){S(j.id);try{const{sessionId:A,persistError:M}=await jx(d,j.id);if(await Promise.all([k(d,{silent:!0}),Fa()]),M?Fe.warning(t("sessions.scheduledTasks.dialog.toast.startedPersistWarning")):Fe.success(t("sessions.scheduledTasks.dialog.toast.started")),A){const G=o.find(q=>q.id===d);tt.getState().setCurrentSession(A,G?.path??null)}}catch(A){Fe.error(A instanceof Error?A.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{S(null)}}},[d,o,k,t]),O=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(Vs,{value:d||"__none",onValueChange:j=>{const A=j==="__none"?"":j;h(A),A?k(A):p([])},children:[s.jsx(Us,{size:"lg",className:r?"w-full":void 0,children:C?s.jsx(Ms,{children:N(C)}):s.jsx(Ms,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(Ks,{children:[o.length===0?s.jsx(as,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,o.map(j=>s.jsx(as,{value:j.id,children:N(j)},j.id))]})]})]}),W=()=>{x(null),y(!0)},L=j=>{h(j),j?k(j):p([])},F=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(B,{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(j=>{const A=b===j.id,M=j.state?.lastStatus||"idle",G=c4[M],q=t(M==="success"?"sessions.scheduledTasks.dialog.status.success":M==="error"?"sessions.scheduledTasks.dialog.status.error":M==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),Z=j.state?.nextRunAt,le=j.state?.lastRunAt;return s.jsxs("div",{className:Ie("rounded-lg border border-border p-4 transition-opacity"),children:[s.jsxs("div",{className:Ie("min-w-0",!j.enabled&&"opacity-60"),children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:j.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:a4(j,t)}),j.loopFile?s.jsx("div",{className:"typography-micro truncate text-muted-foreground/70",title:j.loopFile,children:t("sessions.scheduledTasks.dialog.loopFile.note",{file:j.loopFile})}):null]}),s.jsxs("div",{className:Ie("mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",!j.enabled&&"opacity-60"),children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(B,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),Z?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:sd(Z,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:l4(Z,i)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(B,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),M==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(B,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):le?s.jsxs(s.Fragment,{children:[G.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${G.tone})`},children:[s.jsx(B,{name:G.Icon,className:"h-3.5 w-3.5"}),q]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:sd(le,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),j.state?.lastError?s.jsxs("div",{className:Ie("mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",!j.enabled&&"opacity-60"),style:d4("error"),children:[s.jsx(B,{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:j.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",j.enabled?"text-foreground":"text-muted-foreground",A&&"cursor-not-allowed opacity-50"),children:[s.jsx(hr,{checked:j.enabled,onChange:X=>{I(j,X)},ariaLabel:j.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:j.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:j.name}),disabled:A}),j.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(dt,{variant:"outline",size:"sm",onClick:()=>{E(j)},disabled:A,children:[s.jsx(B,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(dt,{variant:"outline",size:"sm",onClick:()=>T(j),disabled:A,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:j.name}),children:[s.jsx(B,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(dt,{variant:"destructive",size:"sm",onClick:()=>{P(j)},disabled:A,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:j.name}),children:s.jsx(B,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},j.id)})})}),D=s.jsxs("div",{className:"space-y-4",children:[O,F]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Xo,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:j=>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")}),j]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(dt,{className:"w-full",onClick:W,disabled:!d,children:[s.jsx(B,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:D}):e?s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-surface-elevated",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(j=>s.jsx("button",{type:"button",onClick:()=>L(j.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-ring",d===j.id?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:N(j)},j.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(dt,{size:"sm",onClick:W,disabled:!d,children:[s.jsx(B,{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:F})})]})]})}):null,s.jsx(t4,{open:v,task:m,onOpenChange:y,onSave:R})]})}const Po=100;function m4(){const t=nt.c(108),{t:e}=vt(),n=Ne(S4),r=Ne(w4),i=tt(y4),o=tt(b4),l=is(x4);let a;t[0]!==n?(a=Z=>n?Z.archivedSessions:[],t[0]=n,t[1]=a):a=t[1];const u=Gs(sr(a)),[d,h]=c.useState(""),[f,p]=c.useState(null),[g,w]=c.useState(Po);let v;t[2]!==d?(v=d.trim().toLowerCase(),t[2]=d,t[3]=v):v=t[3];const y=v;let m;e:{if(!n){let le;t[4]===Symbol.for("react.memo_cache_sentinel")?(le=[],t[4]=le):le=t[4],m=le;break e}let Z;t[5]!==u?(Z=[...u].sort(g4),t[5]=u,t[6]=Z):Z=t[6],m=Z}const x=m;let b;if(t[7]!==l||t[8]!==x||t[9]!==e){const Z=new Map;for(const le of x){const X=ft(Fs(le))??"",te=Z.get(X);if(te){te.sessions.push(le);continue}Z.set(X,{directory:X,label:X?Ln(X,l)||X:e("sessions.archivePage.otherProjects"),sessions:[le]})}b=[...Z.values()].sort(p4),t[7]=l,t[8]=x,t[9]=e,t[10]=b}else b=t[10];const S=b;let C;e:{if(y){if(y.startsWith("ses_")){let X;if(t[11]!==y||t[12]!==x){let te;t[14]!==y?(te=re=>re.id.toLowerCase()===y,t[14]=y,t[15]=te):te=t[15],X=x.filter(te),t[11]=y,t[12]=x,t[13]=X}else X=t[13];C=X;break e}let le;t[16]!==y||t[17]!==x?(le=xg(x,y,h4),t[16]=y,t[17]=x,t[18]=le):le=t[18],C=le;break e}if(f===null){C=x;break e}let Z;t[19]!==S||t[20]!==f?(Z=S.find(le=>le.directory===f)?.sessions??[],t[19]=S,t[20]=f,t[21]=Z):Z=t[21],C=Z}const N=C;let k,R,I,P,T,E,O,W,L,F;if(t[22]!==u.length||t[23]!==S||t[24]!==N||t[25]!==l||t[26]!==y||t[27]!==n||t[28]!==d||t[29]!==f||t[30]!==i||t[31]!==r||t[32]!==e||t[33]!==o||t[34]!==g){T=Symbol.for("react.early_return_sentinel");e:{const Z=N.slice(0,g);k=N.length-Z.length;const le=u.length;let X;t[45]===Symbol.for("react.memo_cache_sentinel")?(X=je=>{p(je),w(Po)},t[45]=X):X=t[45];const te=X;let re;t[46]!==i||t[47]!==r?(re=je=>{const Y=ft(Fs(je));i(je.id,Y??void 0),r(!1)},t[46]=i,t[47]=r,t[48]=re):re=t[48];const Se=re;let ue;t[49]!==e||t[50]!==o?(ue=je=>{o(je.id).then(Y=>{Y?Fe.success(e("sessions.sidebar.session.restore.success")):Fe.error(e("sessions.sidebar.session.restore.error"))})},t[49]=e,t[50]=o,t[51]=ue):ue=t[51];const ye=ue;if(!n){T=null;break e}let ve;t[52]!==e?(ve=(je,Y,Re,Ce,Me,ae,ee)=>s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:Me,title:ae,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-ring",ee?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",Ce?"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:Y}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:Re})]}),ee?s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>bn.requestDelete({sessions:ee,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-ring","aria-label":e("sessions.archivePage.deleteProjectAria",{label:Y}),children:s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:e("sessions.archivePage.deleteProject")})]}):null]},je),t[52]=e,t[53]=ve):ve=t[53];const be=ve;P="absolute inset-0 z-10 flex flex-col bg-background",R="flex min-h-0 flex-1";let _;if(t[54]!==be||t[55]!==f||t[56]!==e||t[57]!==le){let je;t[59]===Symbol.for("react.memo_cache_sentinel")?(je=()=>te(null),t[59]=je):je=t[59],_=be("__all__",e("sessions.archivePage.allDirectories"),le,f===null,je),t[54]=be,t[55]=f,t[56]=e,t[57]=le,t[58]=_}else _=t[58];let oe;if(t[60]!==S||t[61]!==be||t[62]!==f){let je;t[64]!==be||t[65]!==f?(je=Y=>be(Y.directory||"__none__",Y.label,Y.sessions.length,f===Y.directory,()=>te(Y.directory),Y.directory||void 0,Y.sessions),t[64]=be,t[65]=f,t[66]=je):je=t[66],oe=S.map(je),t[60]=S,t[61]=be,t[62]=f,t[63]=oe}else oe=t[63];t[67]!==_||t[68]!==oe?(I=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:[_,oe]})}),t[67]=_,t[68]=oe,t[69]=I):I=t[69],L="flex min-w-0 flex-1 flex-col";let ce;t[70]===Symbol.for("react.memo_cache_sentinel")?(ce=je=>{h(je),w(Po)},t[70]=ce):ce=t[70];let Q;t[71]!==e?(Q=e("sessions.archivePage.searchPlaceholder"),t[71]=e,t[72]=Q):Q=t[72];let me;t[73]!==e?(me=e("sessions.sidebar.header.search.clear"),t[73]=e,t[74]=me):me=t[74];let ke;t[75]!==d||t[76]!==Q||t[77]!==me?(ke=s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(Ed,{value:d,onSearch:ce,placeholder:Q,clearLabel:me})}),t[75]=d,t[76]=Q,t[77]=me,t[78]=ke):ke=t[78];let fe;t[79]!==N.length||t[80]!==e?(fe=N.length===1?e("sessions.archivePage.countSingle",{count:N.length}):e("sessions.archivePage.countPlural",{count:N.length}),t[79]=N.length,t[80]=e,t[81]=fe):fe=t[81];let De;t[82]!==fe?(De=s.jsx("span",{className:"flex h-8 flex-shrink-0 items-center self-start typography-micro text-muted-foreground",children:fe}),t[82]=fe,t[83]=De):De=t[83],t[84]!==ke||t[85]!==De?(F=s.jsxs("div",{className:"flex items-center gap-3 px-6 pt-3",children:[ke,De]}),t[84]=ke,t[85]=De,t[86]=F):F=t[86],W="min-h-0 flex-1 overflow-y-auto px-6 py-3",E="mx-auto w-full max-w-3xl space-y-0.5",O=Z.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(y?"sessions.archivePage.empty.noMatches":"sessions.archivePage.empty.noArchived")})}):Z.map(je=>{const Y=ft(Fs(je))??"",Re=Y?Ln(Y,l)||Y: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:()=>Se(je),role:"button",tabIndex:0,onKeyDown:Ce=>{(Ce.key==="Enter"||Ce.key===" ")&&(Ce.preventDefault(),Se(je))},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:je.title||e("sessions.sidebar.session.untitled")}),y&&Re?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:Y,children:Re}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:vu(je.time?.archived??je.time?.updated??je.time?.created??Date.now())}),s.jsx("button",{type:"button",onClick:Ce=>{Ce.stopPropagation(),ye(je)},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-ring","aria-label":e("sessions.archivePage.restoreSessionAria",{title:je.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(B,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:Ce=>{Ce.stopPropagation(),bn.requestDelete({sessions:[je],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-ring","aria-label":e("sessions.archivePage.deleteSessionAria",{title:je.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},je.id)})}t[22]=u.length,t[23]=S,t[24]=N,t[25]=l,t[26]=y,t[27]=n,t[28]=d,t[29]=f,t[30]=i,t[31]=r,t[32]=e,t[33]=o,t[34]=g,t[35]=k,t[36]=R,t[37]=I,t[38]=P,t[39]=T,t[40]=E,t[41]=O,t[42]=W,t[43]=L,t[44]=F}else k=t[35],R=t[36],I=t[37],P=t[38],T=t[39],E=t[40],O=t[41],W=t[42],L=t[43],F=t[44];if(T!==Symbol.for("react.early_return_sentinel"))return T;let D;t[87]!==k||t[88]!==e?(D=k>0?s.jsx("button",{type:"button",onClick:()=>w(f4),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[87]=k,t[88]=e,t[89]=D):D=t[89];let j;t[90]!==D||t[91]!==E||t[92]!==O?(j=s.jsxs("div",{className:E,children:[O,D]}),t[90]=D,t[91]=E,t[92]=O,t[93]=j):j=t[93];let A;t[94]!==j||t[95]!==W?(A=s.jsx("div",{className:W,children:j}),t[94]=j,t[95]=W,t[96]=A):A=t[96];let M;t[97]!==A||t[98]!==L||t[99]!==F?(M=s.jsxs("div",{className:L,children:[F,A]}),t[97]=A,t[98]=L,t[99]=F,t[100]=M):M=t[100];let G;t[101]!==R||t[102]!==I||t[103]!==M?(G=s.jsxs("div",{className:R,children:[I,M]}),t[101]=R,t[102]=I,t[103]=M,t[104]=G):G=t[104];let q;return t[105]!==P||t[106]!==G?(q=s.jsx("div",{className:P,children:G}),t[105]=P,t[106]=G,t[107]=q):q=t[107],q}function f4(t){return t+Po}function h4(t){return[t.title]}function p4(t,e){return e.sessions.length-t.sessions.length}function g4(t,e){return(e.time?.archived??0)-(t.time?.archived??0)}function x4(t){return t.homeDirectory}function b4(t){return t.unarchiveSession}function y4(t){return t.setCurrentSession}function w4(t){return t.setArchivePageOpen}function S4(t){return t.isArchivePageOpen}function v4(){const t=nt.c(18),{t:e}=vt(),n=Ne(C4),r=Ne(k4),i=qt(j4);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=qt(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(B,{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(dt,{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(gh,{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 j4(t){return t.setActiveProjectIdOnly}function k4(t){return t.setNewWorktreeDialogOpen}function C4(t){return t.worktreesPageProjectId}const pa=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),N4=(t,e)=>{const n=pa(t),r=pa(e);return`${n}-${r}`.substring(0,60)},nd=(t,e)=>`${t}/${e}`,A4=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},rd=(t,e)=>{const n=A4(e),r=t.directory,i=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};Cg(t.id,n),tt.getState().markSessionAsOpenChamberCreated(t.id),Gs.getState().upsertSession(i);try{Eo().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},P4=()=>{const t=qt.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=is.getState().currentDirectory??null;if(r&&r.trim().length>0){const i=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${i}`,path:i}}return null},Si=or()(Lu(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=P4();if(!a)return t({error:"Select a project",isLoading:!1}),null;const u=a.path,h=await Qo(u)&&e.isolateRuns!==!1,f=pa(n),p=h?await Jo(u):void 0,g=h?await bg(u):null,w=[],v=l?.filter(S=>S.trim().length>0)??[];for(let S=0;S<r.length;S++){const C=r[S],N=C.prompt,k=new Map;for(const I of C.models){const P=`${I.providerID}:${I.modelID}`;k.set(P,(k.get(P)||0)+1)}const R=new Map;for(const I of C.models){const P=`${I.providerID}:${I.modelID}`,T=k.get(P)||1,E=(R.get(P)||0)+1;R.set(P,E);const O=N4(I.providerID,I.modelID),W=r.length>1?`g${S+1}`:void 0,L=T>1?nd(f,`${O}/${E}`):nd(f,O),F=W?`${W}/${L}`:L,D=A2({groupSlug:f,runGroup:W,providerID:I.providerID,modelID:I.modelID,index:T>1?E:void 0});try{if(!h){const G=await nn.withDirectory(u,()=>nn.createSession({title:D}));rd(G,u),w.push({sessionId:G.id,worktreePath:u,providerID:I.providerID,modelID:I.modelID,variant:I.variant,prompt:N});continue}const j=await yg(a,{preferredName:F,mode:"new",branchName:F,worktreeName:F,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:v,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:g}),A={...j,createdFromBranch:p,kind:"standard"};await wg(a)&&await Sg(j.path);const M=await nn.withDirectory(j.path,()=>nn.createSession({title:D}));rd(M,j.path),tt.getState().setWorktreeMetadata(M.id,A),w.push({sessionId:M.id,worktreePath:j.path,providerID:I.providerID,modelID:I.modelID,variant:I.variant,prompt:N})}catch(j){console.warn("[MultiRun] Failed to create session:",j)}}}const y=l?.filter(S=>S.trim().length>0)??[];y.length>0&&vg(a,y).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const m=w.map(S=>S.sessionId),x=w[0]?.sessionId??null;if(m.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const b=o?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{const S=jg.getState().expandText;await Promise.allSettled(w.map(async C=>{try{const N=await S(C.prompt).catch(()=>C.prompt);await kg({sessionId:C.sessionId,directory:C.worktreePath,content:N,providerID:C.providerID,modelID:C.modelID,variant:C.variant,agent:i,files:b})}catch(N){console.warn("[MultiRun] Failed to start run:",N)}}))}catch(S){console.warn("[MultiRun] Failed to start runs:",S)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:m,firstSessionId:x}}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 Wm(t){const e=nt.c(30),{git:n}=jn(),r=su(t),i=nu(t),o=Ng(t),l=Ag(t),a=In(R4),u=In(E4);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 k;e[19]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[19]=k):k=e[19],v=k;break e}let N;e[20]!==r.all?(N=r.all.filter(T4).sort(),e[20]=r.all,e[21]=N):N=e[21],v=N}const y=v;let m;e:{if(!r?.all){let k;e[22]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[22]=k):k=e[22],m=k;break e}let N;e[23]!==r.all?(N=r.all.filter(I4).map(D4).sort(),e[23]=r.all,e[24]=N):N=e[24],m=N}const x=m;let b;e:{if(!t){b=null;break e}if(i!==null){b=i;break e}if(w){b=null;break e}b=r?.all?!0:null}const S=b;let C;return e[25]!==S||e[26]!==w||e[27]!==y||e[28]!==x?(C={localBranches:y,remoteBranches:x,isLoading:w,isGitRepository:S},e[25]=S,e[26]=w,e[27]=y,e[28]=x,e[29]=C):C=e[29],C}function D4(t){return t.replace(/^remotes\//,"")}function I4(t){return t.startsWith("remotes/")}function T4(t){return!t.startsWith("remotes/")}function E4(t){return t.fetchStatus}function R4(t){return t.fetchBranches}const M4=({directory:t,value:e,onChange:n,className:r,disabled:i,id:o})=>{const{t:l}=vt(),{localBranches:a,remoteBranches:u,isLoading:d,isGitRepository:h}=Wm(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 y=t?await Jo(t).catch(()=>null):null;if(w)return;const m=localStorage.getItem(cl),{sourceBranch:x,shouldClearSavedSourceBranch:b}=xh({branches:f,savedSourceBranch:m,rootBranch:y});if(b&&localStorage.removeItem(cl),w||g&&f.includes(g))return;x&&n(x)}catch{}})(),()=>{w=!0}},[f,t,i,d,n,e]);const p=i||!h||d;return s.jsxs("div",{children:[s.jsxs(Vs,{value:e,onValueChange:n,disabled:p,children:[s.jsx(Us,{id:o,size:"lg",className:Ie("min-w-0 max-w-full *:data-[slot=select-value]:truncate",r??"w-fit"),children:s.jsx(Ms,{placeholder:l(d?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(Ks,{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(Li,{children:[s.jsx(Al,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.localBranches")}),a.map(g=>s.jsx(as,{value:g,className:"whitespace-normal break-all",children:g},g))]}),a.length>0&&u.length>0&&s.jsx(Pg,{}),u.length>0&&s.jsxs(Li,{children:[s.jsx(Al,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.remoteBranches")}),u.map(g=>s.jsx(as,{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")})]})},O4=10*1024*1024,Do=t=>{const e=nt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Nt,{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(B,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let i;return e[1]!==n?(i=s.jsxs(Ct,{children:[r,s.jsx(At,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=i):i=e[2],i},qn=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},B4=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:i}=vt(),[o,l]=c.useState(""),[a,u]=c.useState(()=>[{id:Vr(),prompt:"",models:[]}]),[d,h]=c.useState(""),[f,p]=c.useState([]),[g,w]=c.useState(!1),[v,y]=c.useState([]),[m,x]=c.useState(!1),[b,S]=c.useState(!1),[C,N]=c.useState(!0),k=c.useRef(null),R=is(K=>K.currentDirectory??null),I=is(K=>K.homeDirectory??null),P=c.useMemo(()=>{if(typeof window>"u")return null;const K=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof K=="string"&&K.trim().length>0?K.trim():null},[]),T=qt(K=>K.activeProjectId),E=qt(K=>K.setActiveProjectIdOnly),O=qt(K=>K.projects),[W,L]=c.useState(()=>T??null);c.useEffect(()=>{if(T){L(T);return}!W&&O.length>0&&L(O[0].id)},[T,O,W]);const F=c.useMemo(()=>W?O.find(K=>K.id===W)??null:null,[O,W]),D=F?.path??R,j=c.useCallback(K=>{L(K),K!==T&&E(K)},[T,E]),{currentTheme:A}=nr(),M=c.useCallback(K=>{const $=K.label?.trim()||Ln(K.path,I),ne=K.icon?Ia[K.icon]:null,U=K.color?Ta[K.color]:void 0,we=ne?s.jsx(B,{name:ne,className:"h-3.5 w-3.5 shrink-0",style:U?{color:U}:void 0}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:U?{color:U}: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(Ea,{project:{id:K.id,iconImage:K.iconImage??null},options:{themeVariant:A.metadata.variant,iconColor:A.colors.surface.foreground},className:"h-full w-full object-contain",fallback:we})}):we,s.jsx("span",{className:"truncate",children:$})]})},[I,A.metadata.variant,A.colors.surface.foreground]),G=c.useMemo(()=>{if(F?.path)return{id:F.id,path:F.path};const K=R??P;return K?{id:`path:${K}`,path:K}:null},[F,R,P]),[q]=c.useState(()=>typeof window<"u"?yn():!1),Z=c.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),le=Vd(),X=c.useMemo(()=>{if(typeof window>"u")return null;const K=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof K=="number"&&Number.isFinite(K)&&K>0)return K;if(typeof navigator>"u")return null;const $=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!$)return null;const ne=Number.parseInt($[1],10),U=Number.parseInt($[2],10);return Number.isNaN(ne)?null:ne===10?U:ne},[]),te=c.useMemo(()=>q&&Z||le?"pl-[88px]":"pl-3",[q,Z,le]),re=c.useMemo(()=>!q||!Z||X===null?"":X>=26?"h-12":X<=15?"h-14":"",[q,Z,X]),Se=c.useCallback(async K=>{K.target.closest("button, a, input, select, textarea")||K.button===0&&q&&await Dg()},[q]);c.useEffect(()=>{if(!n)return;const K=$=>{$.key==="Escape"&&($.preventDefault(),$.stopPropagation(),n())};return window.addEventListener("keydown",K,!0),()=>window.removeEventListener("keydown",K,!0)},[n]);const[ue,ye]=c.useState(""),{isLoading:ve,isGitRepository:be}=Wm(D),_=c.useRef(!1),oe=be===!0,ce=oe&&C;c.useEffect(()=>{if(be===!1){_.current=!0,N(!1);return}be===!0&&_.current&&(_.current=!1,N(!0))},[be]);const Q=Si(K=>K.createMultiRun),me=Si(K=>K.error),ke=Si(K=>K.clearError);c.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&u(K=>{const $=[...K];return $.length>0&&!$[0].prompt.trim()&&($[0]={...$[0],prompt:t}),$})},[t]),c.useEffect(()=>{if(!G)return;let K=!1;return S(!0),(async()=>{try{const $=await Ig(G);K||y($)}catch{}finally{K||S(!1)}})(),()=>{K=!0}},[G]);const fe=c.useCallback((K,$)=>{u(ne=>ne.map(U=>U.id===K?{...U,...$}:U))},[]),De=c.useCallback(K=>{u($=>$.filter(ne=>ne.id!==K))},[]),je=c.useCallback(()=>{u(K=>[...K,{id:Vr(),prompt:"",models:[]}])},[]),Y=async K=>{const $=K.target.files;if(!$)return;let ne=0;for(let U=0;U<$.length;U++){const we=$[U];if(we.size>O4){Fe.error(i("multirun.launcher.toast.fileTooLarge",{fileName:we.name}));continue}try{const he=await new Promise((Te,Oe)=>{const _e=new FileReader;_e.onload=()=>Te(_e.result),_e.onerror=Oe,_e.readAsDataURL(we)});p(Te=>[...Te,{id:Vr(),filename:we.name,mimeType:we.type||"application/octet-stream",size:we.size,dataUrl:he}]),ne++}catch(he){console.error("File attach failed",he),Fe.error(i("multirun.launcher.toast.attachFailed",{fileName:we.name}))}}ne>0&&Fe.success(ne===1?i("multirun.launcher.toast.attachedSingle",{count:ne}):i("multirun.launcher.toast.attachedPlural",{count:ne})),k.current&&(k.current.value="")},Re=K=>{p($=>$.filter(ne=>ne.id!==K))},Ce=c.useMemo(()=>a.reduce((K,$)=>K+$.models.length,0),[a]),Me=async K=>{K.preventDefault();const $=a.filter(ne=>ne.prompt.trim()&&ne.models.length>=1);if($.length!==0&&!(Ce<1)){w(!0),ke();try{W&&W!==T&&E(W);const ne=f.map(Oe=>({mime:Oe.mimeType,filename:Oe.filename,url:Oe.dataUrl})),U=v.filter(Oe=>Oe.trim().length>0),we=$.map(Oe=>({prompt:Oe.prompt.trim(),models:Oe.models.map(_e=>({providerID:_e.providerID,modelID:_e.modelID,displayName:_e.displayName,variant:_e.variant}))})),he={name:o.trim(),groups:we,agent:d||void 0,worktreeBaseBranch:ce?ue:void 0,isolateRuns:ce,files:ne.length>0?ne:void 0,setupCommands:U.length>0?U:void 0},Te=await Q(he);Te&&(Te.firstSessionId&&tt.getState().setCurrentSession(Te.firstSessionId),e?.())}finally{w(!1)}}},ae=!!(o.trim()&&a.some(K=>K.prompt.trim()&&K.models.length>=1)&&Ce>=1&&D&&!ve&&(be===!1||!ce||ue)),ee=v.filter(K=>K.trim()).length;return s.jsxs("form",{onSubmit:Me,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:Se,className:Ie("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",te,re),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(Ct,{children:[s.jsx(Nt,{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-ring app-region-no-drag",children:s.jsx(B,{name:"close",className:"h-5 w-5"})})}),s.jsx(At,{children:s.jsx("p",{children:i("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Na,{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(qn,{htmlFor:"multirun-project",required:!0,children:i("multirun.launcher.project.label")}),O.length>0?s.jsxs(Vs,{value:W??void 0,onValueChange:j,children:[s.jsx(Us,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:F?s.jsx(Ms,{children:M(F)}):s.jsx(Ms,{placeholder:i("multirun.launcher.project.placeholder")})}),s.jsx(Ks,{fitContent:!0,children:O.map(K=>s.jsx(as,{value:K.id,className:"max-w-[24rem]",children:M(K)},K.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(qn,{htmlFor:"group-name",required:!0,info:s.jsx(Do,{children:i("multirun.launcher.groupName.info")}),children:i("multirun.launcher.groupName.label")}),s.jsx(An,{id:"group-name",value:o,onChange:K=>l(K.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(qn,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Do,{children:i("multirun.launcher.baseBranch.info")}),children:i("multirun.launcher.baseBranch.label")}),s.jsx(M4,{directory:D,value:ue,onChange:ye,disabled:!ce,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(hr,{checked:C,onChange:N,disabled:!oe,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(qn,{htmlFor:"multirun-agent",info:s.jsx(Do,{children:i("multirun.launcher.agent.info")}),children:i("multirun.launcher.agent.label")}),s.jsx(Rm,{value:d,onChange:h,id:"multirun-agent"})]})]}),s.jsxs(Ri,{open:m,onOpenChange:x,children:[s.jsxs(tu,{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(B,{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")}),ee>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:ee}),s.jsx(B,{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(Mi,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:b?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((K,$)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(An,{value:K,onChange:ne=>{const U=[...v];U[$]=ne.target.value,y(U)},placeholder:i("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>y(v.filter((ne,U)=>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-ring","aria-label":i("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]},`${K}-${$}`)),s.jsxs("button",{type:"button",onClick:()=>y([...v,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(B,{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(qn,{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:k,type:"file",multiple:!0,className:"hidden",onChange:Y,accept:"*/*"}),s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>k.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(B,{name:"attachment-2",className:"h-3 w-3"}),i("multirun.launcher.attachments.attach")]})}),s.jsx(At,{children:i("multirun.launcher.attachments.tooltip")})]}),f.map(K=>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:[K.mimeType.startsWith("image/")?s.jsx(B,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(B,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:K.filename,children:K.filename}),s.jsx("button",{type:"button",onClick:()=>Re(K.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(B,{name:"close",className:"h-3 w-3"})})]},K.id))]})]}),a.map((K,$)=>s.jsx(F4,{group:K,groupIndex:$,canRemove:a.length>1,onUpdate:fe,onRemove:De},K.id)),s.jsxs("button",{type:"button",onClick:je,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(B,{name:"add",className:"h-3.5 w-3.5"}),i("multirun.launcher.groups.addGroup")]}),me&&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:me})]})})}),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:[!ce&&be!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(B,{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(dt,{type:"button",variant:"ghost",size:"sm",onClick:n,children:i("multirun.launcher.actions.cancel")}):null,s.jsx(dt,{type:"submit",size:"sm",disabled:!ae||g,children:g?i("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:i("multirun.launcher.actions.startWithRunCount",{count:Ce})})})]})})]})},F4=t=>{const e=nt.c(99),{group:n,groupIndex:r,canRemove:i,onUpdate:o,onRemove:l}=t,{t:a}=vt(),[u,d]=c.useState(!1),[h,f]=c.useState(""),[p,g]=c.useState(!1),[w,v]=c.useState(""),[y,m]=c.useState(!1),[x,b]=c.useState(""),S=c.useRef(null),C=c.useRef(null),N=c.useRef(null),k=c.useRef(null);let R;e[0]!==n.id||e[1]!==n.models||e[2]!==o?(R=U=>{o(n.id,{models:[...n.models,U]})},e[0]=n.id,e[1]=n.models,e[2]=o,e[3]=R):R=e[3];const I=R;let P;e[4]!==n.id||e[5]!==n.models||e[6]!==o?(P=U=>{o(n.id,{models:n.models.filter((we,he)=>he!==U)})},e[4]=n.id,e[5]=n.models,e[6]=o,e[7]=P):P=e[7];const T=P;let E;e[8]!==n.id||e[9]!==n.models||e[10]!==o?(E=(U,we)=>{o(n.id,{models:n.models.map((he,Te)=>Te===U?we:he)})},e[8]=n.id,e[9]=n.models,e[10]=o,e[11]=E):E=e[11];const O=E;let W;e[12]===Symbol.for("react.memo_cache_sentinel")?(W=(U,we)=>{if(U.startsWith("/")){const _e=U.indexOf(" "),Ve=U.indexOf(`
|
|
893
|
+
`),z=Math.min(_e===-1?U.length:_e,Ve===-1?U.length:Ve);if(we<=z&&_e===-1){v(U.substring(1,z)),g(!0),d(!1),m(!1);return}}g(!1);const he=U.substring(0,we),Te=he.lastIndexOf("#");if(Te!==-1){const _e=Te>0?he[Te-1]:null,Ve=he.substring(Te+1);if((!_e||/\s/.test(_e))&&!Ve.includes(" ")&&!Ve.includes(`
|
|
894
|
+
`)){b(Ve),m(!0),d(!1);return}}m(!1);const Oe=he.lastIndexOf("@");if(Oe!==-1){const _e=Oe>0?he[Oe-1]:null,Ve=he.substring(Oe+1);(!_e||/\s/.test(_e))&&!Ve.includes(" ")&&!Ve.includes(`
|
|
895
|
+
`)?(f(Ve),d(!0)):d(!1);return}d(!1)},e[12]=W):W=e[12];const L=W;let F;e[13]!==n.id||e[14]!==o?(F=U=>{o(n.id,{prompt:U})},e[13]=n.id,e[14]=o,e[15]=F):F=e[15];const D=F;let j;e[16]!==n.prompt||e[17]!==D?(j=U=>{const we=n.prompt,Te=S.current?.selectionStart??we.length,_e=we.substring(0,Te).lastIndexOf("@"),Ve=U.relativePath&&U.relativePath.trim().length>0?U.relativePath.trim():U.path||U.name,z=_e!==-1?_e:Te,pe=`${we.substring(0,z)}@${Ve} ${we.substring(Te)}`,Ae=z+Ve.length+2;D(pe),d(!1),f(""),requestAnimationFrame(()=>{const Be=S.current;Be&&(Be.selectionStart=Ae,Be.selectionEnd=Ae,Be.focus()),L(pe,Ae)})},e[16]=n.prompt,e[17]=D,e[18]=j):j=e[18];const A=j;let M;e[19]!==n.prompt||e[20]!==D?(M=U=>{const we=n.prompt,Te=S.current?.selectionStart??we.length,_e=we.substring(0,Te).lastIndexOf("@"),Ve=_e!==-1?_e:Te,z=`${we.substring(0,Ve)}@${U} ${we.substring(Te)}`,pe=Ve+U.length+2;D(z),d(!1),f(""),requestAnimationFrame(()=>{const Ae=S.current;Ae&&(Ae.selectionStart=pe,Ae.selectionEnd=pe,Ae.focus()),L(z,pe)})},e[19]=n.prompt,e[20]=D,e[21]=M):M=e[21];const G=M;let q;e[22]!==D?(q=U=>{const we=`/${U.name} `;D(we),g(!1),v(""),m(!1),requestAnimationFrame(()=>{const he=S.current;he&&(he.focus(),he.selectionStart=he.value.length,he.selectionEnd=he.value.length),L(we,we.length)})},e[22]=D,e[23]=q):q=e[23];const Z=q;let le;e[24]!==n.prompt||e[25]!==D?(le=(U,we)=>{const he=n.prompt,Oe=S.current?.selectionStart??he.length,Ve=he.substring(0,Oe).lastIndexOf("#"),z=Ve!==-1?Ve:Oe,pe=`${he.substring(0,z)}#${we} ${he.substring(Oe)}`,Ae=z+we.length+2;D(pe),m(!1),b(""),requestAnimationFrame(()=>{const Be=S.current;Be&&(Be.selectionStart=Ae,Be.selectionEnd=Ae,Be.focus()),L(pe,Ae)})},e[24]=n.prompt,e[25]=D,e[26]=le):le=e[26];const X=le;let te;e[27]!==p||e[28]!==u||e[29]!==y?(te=U=>{if(p&&N.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")){U.preventDefault(),N.current.handleKeyDown(U.key);return}u&&C.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")&&(U.preventDefault(),C.current.handleKeyDown(U.key)),y&&k.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")&&(U.preventDefault(),k.current.handleKeyDown(U.key))},e[27]=p,e[28]=u,e[29]=y,e[30]=te):te=e[30];const re=te,Se=r+1;let ue;e[31]!==a||e[32]!==Se?(ue=a("multirun.launcher.groups.groupLabel",{index:Se}),e[31]=a,e[32]=Se,e[33]=ue):ue=e[33];let ye;e[34]!==ue?(ye=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:ue}),e[34]=ue,e[35]=ye):ye=e[35];let ve;e[36]!==i||e[37]!==n.id||e[38]!==l||e[39]!==a?(ve=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(B,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=i,e[37]=n.id,e[38]=l,e[39]=a,e[40]=ve):ve=e[40];let be;e[41]!==ye||e[42]!==ve?(be=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ye,ve]}),e[41]=ye,e[42]=ve,e[43]=be):be=e[43];let _;e[44]!==a?(_=a("multirun.launcher.groups.prompt.label"),e[44]=a,e[45]=_):_=e[45];let oe;e[46]!==_?(oe=s.jsx(qn,{required:!0,children:_}),e[46]=_,e[47]=oe):oe=e[47];const ce=n.prompt;let Q;e[48]!==D?(Q=U=>{const we=U.target.value;D(we);const he=U.target.selectionStart??we.length;L(we,he)},e[48]=D,e[49]=Q):Q=e[49];let me;e[50]!==a?(me=a("multirun.launcher.groups.prompt.placeholder"),e[50]=a,e[51]=me):me=e[51];let ke;e[52]!==n.prompt||e[53]!==re||e[54]!==Q||e[55]!==me?(ke=s.jsx(ur,{ref:S,value:ce,onChange:Q,onKeyDown:re,placeholder:me,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]=re,e[54]=Q,e[55]=me,e[56]=ke):ke=e[56];let fe;e[57]!==w||e[58]!==Z||e[59]!==p?(fe=p?s.jsx(Cu,{ref:N,searchQuery:w,onCommandSelect:Z,onClose:()=>g(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=w,e[58]=Z,e[59]=p,e[60]=fe):fe=e[60];let De;e[61]!==G||e[62]!==A||e[63]!==h||e[64]!==u?(De=u?s.jsx(Nu,{ref:C,searchQuery:h,onFileSelect:A,onAgentSelect:G,onClose:()=>d(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=G,e[62]=A,e[63]=h,e[64]=u,e[65]=De):De=e[65];let je;e[66]!==X||e[67]!==y||e[68]!==x?(je=y?s.jsx(Au,{ref:k,searchQuery:x,onSnippetSelect:X,onClose:()=>m(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=X,e[67]=y,e[68]=x,e[69]=je):je=e[69];let Y;e[70]!==ke||e[71]!==fe||e[72]!==De||e[73]!==je?(Y=s.jsxs("div",{className:"relative",children:[ke,fe,De,je]}),e[70]=ke,e[71]=fe,e[72]=De,e[73]=je,e[74]=Y):Y=e[74];let Re;e[75]!==oe||e[76]!==Y?(Re=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[oe,Y]}),e[75]=oe,e[76]=Y,e[77]=Re):Re=e[77];let Ce;e[78]!==a?(Ce=a("multirun.launcher.models.info"),e[78]=a,e[79]=Ce):Ce=e[79];let Me;e[80]!==Ce?(Me=s.jsx(Do,{children:Ce}),e[80]=Ce,e[81]=Me):Me=e[81];let ae;e[82]!==a?(ae=a("multirun.launcher.models.label"),e[82]=a,e[83]=ae):ae=e[83];let ee;e[84]!==Me||e[85]!==ae?(ee=s.jsx(qn,{required:!0,info:Me,children:ae}),e[84]=Me,e[85]=ae,e[86]=ee):ee=e[86];let K;e[87]!==n.models||e[88]!==I||e[89]!==T||e[90]!==O?(K=s.jsx(Mm,{selectedModels:n.models,onAdd:I,onRemove:T,onUpdate:O,minModels:1}),e[87]=n.models,e[88]=I,e[89]=T,e[90]=O,e[91]=K):K=e[91];let $;e[92]!==ee||e[93]!==K?($=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ee,K]}),e[92]=ee,e[93]=K,e[94]=$):$=e[94];let ne;return e[95]!==be||e[96]!==Re||e[97]!==$?(ne=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[be,Re,$]}),e[95]=be,e[96]=Re,e[97]=$,e[98]=ne):ne=e[98],ne},_4=t=>{const e=new Map;for(const n of t){const r=Fs(n);r&&e.set(n.id,{directory:r,sessionId:n.id})}return e},L4=(t,e)=>{if(!t)return[];const n=[];return t.forEach((r,i)=>{e.has(i)||n.push(r)}),n},$4=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=ls(),h=_4(i),f=l.current?.runtimeKey===d?l.current.identities:null;for(const p of L4(f,h))Tg({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)},W4=new Map,z4=t=>{const e=nt.c(26),{isVSCode:n}=t,r=Ba(),i=qt(V4),o=qt(U4),l=is(K4),a=tt(H4);let u;e[0]!==n?(u=P=>n?W4:P.availableWorktreesByProject,e[0]=n,e[1]=u):u=e[1];const d=tt(u),h=!n;let f;e[2]!==d||e[3]!==i||e[4]!==h?(f=_m(i,d,{includeWorktrees:h}),e[2]=d,e[3]=i,e[4]=h,e[5]=f):f=e[5];const p=f,g=Gs(G4),w=Gs(q4),v=Gs(Q4),y=`session-list-sync:${c.useId()}`;let m,x;e[6]!==o||e[7]!==y||e[8]!==r||e[9]!==l||e[10]!==a||e[11]!==p||e[12]!==i?(m=()=>(r.setBootstrapDemand(y,Nm({knownDirectories:p,activeProjectDirectory:ft(i.find(P=>P.id===o)?.path??null),activeProjectId:o,collapsedProjects:new Set,collapsedGroups:new Set,currentDirectory:l,currentSessionDirectory:a})),()=>r.clearBootstrapDemand(y)),x=[o,y,r,l,a,p,i],e[6]=o,e[7]=y,e[8]=r,e[9]=l,e[10]=a,e[11]=p,e[12]=i,e[13]=m,e[14]=x):(m=e[13],x=e[14]),c.useEffect(m,x);const b=c.useRef(null);let S,C;e[15]!==n||e[16]!==p?(S=()=>{const P=new Set(p),T=b.current;b.current=P;const E=T?[...P].filter(O=>!T.has(O)):n?[...P]:[];E.length&&ja(E,Ro())},C=[n,p],e[15]=n,e[16]=p,e[17]=S,e[18]=C):(S=e[17],C=e[18]),c.useEffect(S,C);let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[19]=N):N=e[19],c.useEffect(Y4,N);let k;e[20]!==w||e[21]!==g?(k=[...g,...w],e[20]=w,e[21]=g,e[22]=k):k=e[22];const R=k;let I;e[23]!==R||e[24]!==v?(I={enabled:!0,hasAuthoritativeGlobalSessions:v,sessions:R},e[23]=R,e[24]=v,e[25]=I):I=e[25],$4(I)};function V4(t){return t.projects}function U4(t){return t.activeProjectId}function K4(t){return t.currentDirectory}function H4(t){return t.currentSessionDirectory}function G4(t){return t.activeSessions}function q4(t){return t.archivedSessions}function Q4(t){return t.status==="ready"}function Y4(){let t=null,e=!1;const n=new Set,r=to(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(),Fa(Ro());return}const o=[...n];n.clear(),o.length&&ja(o,Ro())},500)});return()=>{t&&clearTimeout(t),r()}}const X4=zn(()=>hn(()=>import("./SettingsWindow-Bi8LE9XI.js"),__vite__mapDeps([141,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,142,84,85,143,128,129,130,131,119,120,105,106,90,91,92,93,94,95,96,97,98,99,100,101,102,103,144,145,146])).then(t=>({default:t.SettingsWindow}))),J4=()=>{const t=nt.c(72);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={isVSCode:!1},t[0]=e):e=t[0],z4(e),bh();const n=Ne(Z4),r=Ne(eC),i=Ne(tC),o=Ne(sC),[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=Ne(nC),f=Ne(rC),p=Ne(oC),g=Ne(iC),w=Ne(aC),v=Ne(lC),y=Ne(cC),m=hu();let x;if(t[4]!==m||t[5]!==y){let Y;t[7]!==y?(Y=Re=>Re.id===y,t[7]=y,t[8]=Y):Y=t[8],x=m.find(Y),t[4]=m,t[5]=y,t[6]=x}else x=t[6];const b=x;let S,C;t[9]!==b||t[10]!==y?(S=()=>{y&&!b&&Ne.getState().setOpenGuestPage(null)},C=[y,b],t[9]=b,t[10]=y,t[11]=S,t[12]=C):(S=t[11],C=t[12]),c.useEffect(S,C);let N;t[13]===Symbol.for("react.memo_cache_sentinel")?(N=[],t[13]=N):N=t[13],c.useEffect(uC,N);const k=g||w||!!v||h||!!b;let R;t[14]===Symbol.for("react.memo_cache_sentinel")?(R=[],t[14]=R):R=t[14],c.useEffect(fC,R);const{isMobile:I}=Wn();yh();const P=Mb();let T,E;t[15]!==I||t[16]!==r?(T=()=>{Ne.getState().isMobile!==I&&r(I)},E=[I,r],t[15]=I,t[16]=r,t[17]=T,t[18]=E):(T=t[17],E=t[18]),c.useEffect(T,E);let O,W,L,F;t[19]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(Nv,{}),W=s.jsx(v0,{}),L=s.jsx(N0,{}),F=s.jsx(F3,{}),t[19]=O,t[20]=W,t[21]=L,t[22]=F):(O=t[19],W=t[20],L=t[21],F=t[22]);let D;t[23]!==P?(D=s.jsx(_3,{value:P,onMoveSessionOnly:hC,onMoveAllChanges:pC,onCancel:Vb}),t[23]=P,t[24]=D):D=t[24];let j;t[25]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Xb,{}),t[25]=j):j=t[25];let A;t[26]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(Yb,{}),t[26]=A):A=t[26];let M;t[27]!==n?(M=s.jsx(B3,{isVisible:n}),t[27]=n,t[28]=M):M=t[28];let G;t[29]!==I||t[30]!==n||t[31]!==M?(G=s.jsx(Qb,{isOpen:n,isMobile:I,className:"border-border",topBar:A,children:M}),t[29]=I,t[30]=n,t[31]=M,t[32]=G):G=t[32];let q;t[33]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx(Gb,{}),t[33]=q):q=t[33];const Z=k&&"invisible";let le;t[34]!==Z?(le=Ie("absolute inset-0",Z),t[34]=Z,t[35]=le):le=t[35];const X=!i&&!k;let te;t[36]!==X?(te=s.jsx(Bs,{children:s.jsx(Md,{active:X})}),t[36]=X,t[37]=te):te=t[37];let re;t[38]!==le||t[39]!==te?(re=s.jsx("div",{className:le,children:te}),t[38]=le,t[39]=te,t[40]=re):re=t[40];let Se;t[41]!==h||t[42]!==p||t[43]!==f?(Se=h&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Bs,{children:s.jsx(B4,{isWindowed:!0,initialPrompt:p,onCreated:()=>f(!1),onCancel:()=>f(!1)})})}),t[41]=h,t[42]=p,t[43]=f,t[44]=Se):Se=t[44];let ue;t[45]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx(Bs,{children:s.jsx(u4,{})}),t[45]=ue):ue=t[45];let ye;t[46]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx(Bs,{children:s.jsx(m4,{})}),t[46]=ye):ye=t[46];let ve;t[47]===Symbol.for("react.memo_cache_sentinel")?(ve=s.jsx(Bs,{children:s.jsx(v4,{})}),t[47]=ve):ve=t[47];let be;t[48]!==b?(be=b&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Bs,{children:s.jsx(Lx,{mode:`plugin:${b.id}`,surface:"page",item:null,onDismiss:gC})})}),t[48]=b,t[49]=be):be=t[49];let _;t[50]!==re||t[51]!==Se||t[52]!==be?(_=s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[re,Se,ue,ye,ve,be]}),t[50]=re,t[51]=Se,t[52]=be,t[53]=_):_=t[53];let oe;t[54]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx(zS,{}),t[54]=oe):oe=t[54];let ce;t[55]!==_?(ce=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:[_,oe]})})}),t[55]=_,t[56]=ce):ce=t[56];let Q;t[57]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:s.jsx(Bs,{children:s.jsx(JS,{})})}),t[57]=Q):Q=t[57];let me;t[58]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx(Bs,{children:s.jsx(bv,{})}),t[58]=me):me=t[58];let ke;t[59]!==ce?(ke=s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[q,s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[ce,Q,me]})]}),t[59]=ce,t[60]=ke):ke=t[60];let fe;t[61]!==G||t[62]!==ke?(fe=s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[G,ke]}),t[61]=G,t[62]=ke,t[63]=fe):fe=t[63];let De;t[64]!==i||t[65]!==o||t[66]!==l?(De=l?s.jsx(c.Suspense,{fallback:null,children:s.jsx(X4,{open:i,onOpenChange:o})}):null,t[64]=i,t[65]=o,t[66]=l,t[67]=De):De=t[67];let je;return t[68]!==D||t[69]!==fe||t[70]!==De?(je=s.jsx(wh,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:"main-content-safe-area relative flex h-[100dvh] bg-background",children:[O,W,L,F,D,j,fe,De]})}),t[68]=D,t[69]=fe,t[70]=De,t[71]=je):je=t[71],je};function Z4(t){return t.isSidebarOpen}function eC(t){return t.setIsMobile}function tC(t){return t.isSettingsDialogOpen}function sC(t){return t.setSettingsDialogOpen}function nC(t){return t.isMultiRunLauncherOpen}function rC(t){return t.setMultiRunLauncherOpen}function oC(t){return t.multiRunLauncherPrefillPrompt}function iC(t){return t.isScheduledTasksDialogOpen}function aC(t){return t.isArchivePageOpen}function lC(t){return t.worktreesPageProjectId}function cC(t){return t.openGuestPageId}function dC(){return Ne.getState().setOpenGuestPage(null)}function uC(){return Go(dC)}function mC(){return Ne.getState().closeMainSurfaces()}function fC(){const t=mC,e=tt.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 hC(){return Xu(!1)}function pC(){return Xu(!0)}function gC(){return Ne.getState().setOpenGuestPage(null)}const zm=12,xC=[{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"}],bC=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?xC:l,f=mt.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]),mt.useEffect(p,g);let w;e[4]===Symbol.for("react.memo_cache_sentinel")?(w=Array.from({length:zm},yC),e[4]=w):w=e[4];const v=w;if(!n)return null;let y;e[5]!==i?(y=Ie("fireworks-overlay pointer-events-none",i),e[5]=i,e[6]=y):y=e[6];let m;if(e[7]!==u||e[8]!==h||e[9]!==d){let b;e[11]!==u||e[12]!==d?(b=S=>{const C={"--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:C,children:v.map((N,k)=>{const R=N.x*S.radius,I=N.y*S.radius,P={"--translate-x":`${R}px`,"--translate-y":`${I}px`,"--particle-delay":`${N.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:P},`${S.id}-${k}-${u}`)})},`${S.id}-${u}`)},e[11]=u,e[12]=d,e[13]=b):b=e[13],m=h.map(b),e[7]=u,e[8]=h,e[9]=d,e[10]=m}else m=e[10];let x;return e[14]!==u||e[15]!==y||e[16]!==m?(x=s.jsx("div",{className:y,"aria-hidden":"true","data-burst-key":u,children:m}),e[14]=u,e[15]=y,e[16]=m,e[17]=x):x=e[17],x};function yC(t,e){const n=Math.PI*2*e/zm;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const wC=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]=mt.useState(o),u=mt.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(SC)},e[4]=f):f=e[4];const p=f;let g;e[5]!==i?(g=()=>{h(),a(vC),u.current=window.setTimeout(()=>{a(jC),u.current=null},i)},e[5]=i,e[6]=g):g=e[6];const w=g;let v,y;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>h(),y=[h],e[7]=v,e[8]=y):(v=e[7],y=e[8]),mt.useEffect(v,y);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 SC(t){return t.isActive?{...t,isActive:!1}:t}function vC(t){return{isActive:!0,cycle:t.cycle+1}}function jC(t){return t.isActive?{...t,isActive:!1}:t}const Vm=c.createContext(void 0),kC=t=>{const e=nt.c(10),{children:n}=t,{isActive:r,burstKey:i,triggerFireworks:o,dismissFireworks:l}=wC();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(bC,{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(Vm.Provider,{value:u,children:[n,d]}),e[6]=n,e[7]=d,e[8]=u,e[9]=h):h=e[9],h},lN=()=>{const t=c.useContext(Vm);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},ga="openchamber_requests_in_flight",Um=1e3,CC=300*1e3,Ko=Math.ceil(CC/Um),NC=()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(ga)==="1"}catch{return!1}},Km=()=>({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 AC=1;const PC=(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))},DC=t=>{const e=window.__openchamberRequestsInFlight__;!e||!e.enabled||(e.inFlight=Math.max(0,e.inFlight-1),e.totalSettled+=1,e.inFlightStarts.delete(t))},Hm=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},wr=(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)},IC=()=>{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=AC++;PC(o,Date.now());try{return await e(r,i)}finally{DC(o)}};window.fetch=n},od=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;!t||!t.fetchWrapped||!t.originalFetch||(window.fetch=t.originalFetch,t.fetchWrapped=!1,t.originalFetch=null)},Mr=t=>{t.length>Ko&&t.splice(0,t.length-Ko)},TC=()=>{const t=window.__openchamberRequestsInFlight__;if(!t||!t.enabled)return;t.samples.push(t.inFlight);const e=Hm(t),n=e.length>0?e[e.length-1]:0;t.p50Samples.push(wr(e,50)),t.p90Samples.push(wr(e,90)),t.p99Samples.push(wr(e,99)),t.maxSamples.push(n),n>t.peakAgeMs&&(t.peakAgeMs=n),t.sampleCount+=1,Mr(t.samples),Mr(t.p50Samples),Mr(t.p90Samples),Mr(t.p99Samples),Mr(t.maxSamples),t.lastSampleAt=Date.now()},EC=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;!t||t.sampleTimer!=null||(t.sampleTimer=window.setInterval(TC,Um))},id=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;!t||t.sampleTimer==null||(window.clearInterval(t.sampleTimer),t.sampleTimer=null)},ad=t=>{if(!(typeof window>"u"))try{if(t){id(),od(),window.localStorage.setItem(ga,"1"),window.__openchamberRequestsInFlight__=Km(),IC(),EC();return}window.localStorage.removeItem(ga),id(),od(),delete window.__openchamberRequestsInFlight__}catch{}},RC=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;if(!t)return;const e=Km();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},xa=()=>{if(typeof window>"u")return ld();const t=window.__openchamberRequestsInFlight__;if(!NC()||!t)return ld();const e=Hm(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:wr(e,50),ageP90:wr(e,90),ageP99:wr(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:Ko}},ld=()=>({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:Ko});function MC(t){switch(t){case"memory":return"database-2";case"streaming":return"bar-chart-box";case"requests":return"pulse"}}const Gm=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`},ba=t=>`${(t/1e3).toFixed(2)} s`,Ps=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},cd=t=>{const e=nt.c(43),{title:n,snapshot:r,emptyLabel:i}=t,{t:o}=vt();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(FC,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?Gm(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(Ps,{label:w,value:r.entries.length}),e[23]=r.entries.length,e[24]=w,e[25]=v):v=e[25];let y;e[26]!==o?(y=o("memoryDebugPanel.metric.samples"),e[26]=o,e[27]=y):y=e[27];let m;e[28]!==y||e[29]!==d?(m=s.jsx(Ps,{label:y,value:d}),e[28]=y,e[29]=d,e[30]=m):m=e[30];let x;e[31]!==o?(x=o("memoryDebugPanel.metric.lastUpdate"),e[31]=o,e[32]=x):x=e[32];let b;e[33]!==r.lastUpdatedAt||e[34]!==o?(b=r.lastUpdatedAt?o("memoryDebugPanel.common.live"):o("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=o,e[35]=b):b=e[35];let S;e[36]!==x||e[37]!==b?(S=s.jsx(Ps,{label:x,value:b}),e[36]=x,e[37]=b,e[38]=S):S=e[38];let C;e[39]!==m||e[40]!==S||e[41]!==v?(C=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]=C):C=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,C,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(Sn,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:a.map(N=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:N.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:o("memoryDebugPanel.metric.countValue",{value:N.count})}),s.jsx("span",{children:o("memoryDebugPanel.metric.avgValue",{value:N.avg})}),s.jsx("span",{children:o("memoryDebugPanel.metric.maxValue",{value:N.max})}),s.jsx("span",{children:o("memoryDebugPanel.metric.totalValue",{value:N.total})})]})]},N.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},dd=t=>{const e=nt.c(24),{series:n,peak:r,windowSeconds:i,ariaLabel:o,maxLabel:l}=t,a=i,u=n.reduce(_C,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 y;e[7]!==a?(y=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]=y):y=e[8];let m;if(e[9]!==n||e[10]!==f||e[11]!==g){let S;e[13]!==f||e[14]!==g?(S=(C,N)=>{const k=C.samples.length;if(k===0)return null;const R=C.samples.map((P,T)=>`${f(T)},${g(P).toFixed(2)}`),I=`M ${R.join(" L ")}`;return s.jsxs(c.Fragment,{children:[C.filled?s.jsx("path",{d:`M ${f(0)},56 L ${R.join(" L ")} L ${f(k-1)},56 Z`,fill:`color-mix(in srgb, ${C.color} 18%, transparent)`,stroke:"none"}):null,s.jsx("path",{d:I,fill:"none",stroke:C.color,strokeWidth:1.5,strokeLinejoin:"round",strokeLinecap:"round",vectorEffect:"non-scaling-stroke"})]},N)},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 x;e[16]!==o||e[17]!==v||e[18]!==y||e[19]!==m?(x=s.jsxs("svg",{viewBox:v,preserveAspectRatio:"none",className:"h-14 w-full",role:"img","aria-label":o,children:[y,m]}),e[16]=o,e[17]=v,e[18]=y,e[19]=m,e[20]=x):x=e[20];let b;return e[21]!==w||e[22]!==x?(b=s.jsxs("div",{className:"relative w-full",children:[w,x]}),e[21]=w,e[22]=x,e[23]=b):b=e[23],b},OC=t=>{const e=nt.c(100),{onClose:n}=t,{t:r}=vt(),[i,o]=c.useState("memory"),[l,a]=c.useState("idle"),u=tt(LC),d=Su($C),h=iu(),f=Eg(WC),p=tn(zC),[g,w]=c.useState(VC),[v,y]=c.useState(UC),[m,x]=c.useState(KC),b=[{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(HC,0),e[0]=m.samples,e[1]=S):S=e[1];const C=S,N=b.reduce(qC,0);let k;e[2]!==g.entries?(k=new Map,g.entries.forEach(Ae=>{k.set(Ae.metric,Ae.count)}),e[2]=g.entries,e[3]=k):k=e[3];let R;e[4]!==k?(R=k.get("ui.message_list.render")??0,e[4]=k,e[5]=R):R=e[5];let I;e[6]!==k?(I=k.get("ui.message_list.render.streaming")??0,e[6]=k,e[7]=I):I=e[7];let P;e[8]!==k?(P=k.get("ui.chat_message.render")??0,e[8]=k,e[9]=P):P=e[9];let T;e[10]!==k?(T=k.get("ui.chat_message.render.streaming")??0,e[10]=k,e[11]=T):T=e[11];let E;e[12]!==k?(E=k.get("ui.chat_message.render.static_during_stream")??0,e[12]=k,e[13]=E):E=e[13];let O;e[14]!==k?(O=k.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[14]=k,e[15]=O):O=e[15];let W;e[16]!==R||e[17]!==I||e[18]!==P||e[19]!==T||e[20]!==E||e[21]!==O?(W={messageListRender:R,messageListRenderStreaming:I,chatMessageRender:P,chatMessageRenderStreaming:T,chatMessageRenderStaticDuringStream:E,chatMessageRenderStaticOutsideActiveTurnDuringStream:O},e[16]=R,e[17]=I,e[18]=P,e[19]=T,e[20]=E,e[21]=O,e[22]=W):W=e[22];const L=W;let F,D;e[23]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{const Ae=()=>{w(bo()),y(yo()),x(xa())};Ae();const Be=window.setInterval(Ae,500);return()=>window.clearInterval(Be)},F=[],e[23]=F,e[24]=D):(F=e[23],D=e[24]),c.useEffect(D,F);let j,A;e[25]!==l?(j=()=>{if(l==="idle")return;const Ae=window.setTimeout(()=>{a("idle")},1500);return()=>window.clearTimeout(Ae)},A=[l],e[25]=l,e[26]=j,e[27]=A):(j=e[26],A=e[27]),c.useEffect(j,A);let M=0,G=0,q=0;for(const Ae of Object.keys(f)){const Be=f[Ae]??[];G=G+Be.length;for(const rt of Be)rt.role==="user"?q=q+1:rt.role==="assistant"&&(M=M+1)}let Z;e[28]!==M||e[29]!==G||e[30]!==q?(Z={assistant:M,total:G,user:q},e[28]=M,e[29]=G,e[30]=q,e[31]=Z):Z=e[31];const le=Z;let X;if(e[32]!==u||e[33]!==f||e[34]!==d||e[35]!==h||e[36]!==r){let Ae;e[38]!==u||e[39]!==f||e[40]!==d||e[41]!==r?(Ae=Be=>{const rt=f[Be.id]??[];let Ge=0,ut=0;for(const wt of rt)wt.role==="user"?ut=ut+1:wt.role==="assistant"&&(Ge=Ge+1);const at=d.get(Be.id);return{id:Be.id,title:Be.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:Ge,messageCount:rt.length,userMessageCount:ut,isStreaming:at?.isStreaming||!1,isZombie:at?.isZombie||!1,backgroundCount:at?.backgroundMessageCount||0,lastAccessed:at?.lastAccessedAt||0,isCurrent:Be.id===u}},e[38]=u,e[39]=f,e[40]=d,e[41]=r,e[42]=Ae):Ae=e[42],X=h.map(Ae).sort(QC),e[32]=u,e[33]=f,e[34]=d,e[35]=h,e[36]=r,e[37]=X}else X=e[37];const te=X;let re;e[43]!==f?(re=Object.keys(f),e[43]=f,e[44]=re):re=e[44];const Se=re.length;let ue;e[45]===Symbol.for("react.memo_cache_sentinel")?(ue=async()=>{try{const Ae={generatedAt:new Date().toISOString(),ui:bo(),vscode:yo()};await navigator.clipboard.writeText(JSON.stringify(Ae,null,2)),a("copied")}catch{a("error")}},e[45]=ue):ue=e[45];const ye=ue,ve=Mg,be="fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area";let _;e[46]===Symbol.for("react.memo_cache_sentinel")?(_={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=_):_=e[46];let oe;e[47]!==i?(oe=MC(i),e[47]=i,e[48]=oe):oe=e[48];let ce;e[49]!==oe?(ce=s.jsx(B,{name:oe,className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[49]=oe,e[50]=ce):ce=e[50];let Q;e[51]!==r?(Q=r("memoryDebugPanel.title"),e[51]=r,e[52]=Q):Q=e[52];let me;e[53]!==Q?(me=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:Q}),e[53]=Q,e[54]=me):me=e[54];let ke;e[55]!==ce||e[56]!==me?(ke=s.jsxs("div",{className:"flex items-center gap-2",children:[ce,me]}),e[55]=ce,e[56]=me,e[57]=ke):ke=e[57];let fe;e[58]!==i?(fe=i==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(dt,{size:"xs",variant:"ghost",onClick:ye,children:s.jsx(B,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(dt,{size:"xs",variant:"ghost",onClick:()=>{Mf(),w(bo()),y(yo())},children:s.jsx(B,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[58]=i,e[59]=fe):fe=e[59];let De;e[60]!==i?(De=i==="requests"?s.jsx(dt,{size:"xs",variant:"ghost",onClick:()=>{RC(),x(xa())},children:s.jsx(B,{name:"refresh",className:"h-3.5 w-3.5"})}):null,e[60]=i,e[61]=De):De=e[61];let je;e[62]!==n?(je=n?s.jsx(dt,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(B,{name:"close",className:"h-4 w-4"})}):null,e[62]=n,e[63]=je):je=e[63];let Y;e[64]!==fe||e[65]!==De||e[66]!==je?(Y=s.jsxs("div",{className:"flex items-center gap-1",children:[fe,De,je]}),e[64]=fe,e[65]=De,e[66]=je,e[67]=Y):Y=e[67];let Re;e[68]!==ke||e[69]!==Y?(Re=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[ke,Y]}),e[68]=ke,e[69]=Y,e[70]=Re):Re=e[70];let Ce;e[71]===Symbol.for("react.memo_cache_sentinel")?(Ce={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[71]=Ce):Ce=e[71];const Me=i==="memory"?"secondary":"ghost";let ae;e[72]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>o("memory"),e[72]=ae):ae=e[72];let ee;e[73]!==r?(ee=r("memoryDebugPanel.tabs.memory"),e[73]=r,e[74]=ee):ee=e[74];let K;e[75]!==Me||e[76]!==ee?(K=s.jsx(dt,{size:"sm",variant:Me,className:"flex-1",onClick:ae,children:ee}),e[75]=Me,e[76]=ee,e[77]=K):K=e[77];const $=i==="streaming"?"secondary":"ghost";let ne;e[78]===Symbol.for("react.memo_cache_sentinel")?(ne=()=>o("streaming"),e[78]=ne):ne=e[78];let U;e[79]!==r?(U=r("memoryDebugPanel.tabs.streaming"),e[79]=r,e[80]=U):U=e[80];let we;e[81]!==$||e[82]!==U?(we=s.jsx(dt,{size:"sm",variant:$,className:"flex-1",onClick:ne,children:U}),e[81]=$,e[82]=U,e[83]=we):we=e[83];const he=i==="requests"?"secondary":"ghost";let Te;e[84]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>o("requests"),e[84]=Te):Te=e[84];let Oe;e[85]!==r?(Oe=r("memoryDebugPanel.tabs.requests"),e[85]=r,e[86]=Oe):Oe=e[86];let _e;e[87]!==he||e[88]!==Oe?(_e=s.jsx(dt,{size:"sm",variant:he,className:"flex-1",onClick:Te,children:Oe}),e[87]=he,e[88]=Oe,e[89]=_e):_e=e[89];let Ve;e[90]!==K||e[91]!==we||e[92]!==_e?(Ve=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:Ce,children:[K,we,_e]}),e[90]=K,e[91]=we,e[92]=_e,e[93]=Ve):Ve=e[93];const z=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(Ps,{label:r("memoryDebugPanel.metric.totalMessages"),value:le.total}),s.jsx(Ps,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${Se} / ${Pl.MAX_SESSIONS}`}),s.jsx(Ps,{label:r("memoryDebugPanel.metric.userMessages"),value:le.user}),s.jsx(Ps,{label:r("memoryDebugPanel.metric.assistantMessages"),value:le.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:Rg()})})]}),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:Pl.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(Sn,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:te.map(Ae=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Ae.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:Ae.title}),Ae.isStreaming?s.jsx(B,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Ae.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:Ae.assistantMessageCount,user:Ae.userMessageCount})}),s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Ae.messageCount})}),Ae.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Ae.backgroundCount]}):null]})]},Ae.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Ct,{children:[s.jsx(Nt,{asChild:!0,children:s.jsx(dt,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:h.map(YC),currentSessionId:u,cachedSessions:Object.keys(f),messageRoleCounts:le,sessionMessageRoleCounts:te.map(XC),memoryStates:Object.fromEntries(d)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(At,{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(dt,{size:"xs",variant:"outline",onClick:ye,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(Ps,{label:r("memoryDebugPanel.metric.uiMetrics"),value:g.entries.length}),s.jsx(Ps,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(Ps,{label:r("memoryDebugPanel.metric.messageListRenders"),value:L.messageListRender}),s.jsx(Ps,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:L.messageListRenderStreaming}),s.jsx(Ps,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:L.chatMessageRender}),s.jsx(Ps,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:L.chatMessageRenderStreaming}),s.jsx(Ps,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:L.chatMessageRenderStaticDuringStream}),s.jsx(Ps,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:L.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(cd,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:g,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(cd,{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(Ps,{label:r("memoryDebugPanel.requests.totalRequests"),value:`${m.totalSettled} / ${m.totalStarted}`}),s.jsx(Ps,{label:r("memoryDebugPanel.requests.tracking"),value:m.startedAt?Gm(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(dd,{series:[{samples:m.samples,color:"var(--status-info)",filled:!0}],peak:C,windowSeconds:m.windowSeconds,ariaLabel:r("memoryDebugPanel.requests.chartLabel",{peak:m.peak}),maxLabel:`${C}`}),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:ba(m.peakAgeMs)})]}),s.jsx(dd,{series:b.map(JC),peak:N,windowSeconds:m.windowSeconds,ariaLabel:r("memoryDebugPanel.requests.percentileChartLabel"),maxLabel:ba(N)}),s.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-meta",children:b.map(ZC)}),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 pe;return e[94]!==ve||e[95]!==_||e[96]!==Re||e[97]!==Ve||e[98]!==z?(pe=s.jsxs(ve,{className:be,style:_,children:[Re,Ve,z]}),e[94]=ve,e[95]=_,e[96]=Re,e[97]=Ve,e[98]=z,e[99]=pe):pe=e[99],pe},BC=OC;function FC(t,e){return t+e.count}function _C(t,e){return Math.max(t,e.samples.length)}function LC(t){return t.currentSessionId}function $C(t){return t.sessionMemoryState}function WC(t){return t.message}function zC(t){return t.totalRequestCount}function VC(){return bo()}function UC(){return yo()}function KC(){return xa()}function HC(t,e){return Math.max(t,e)}function GC(t,e){return Math.max(t,e)}function qC(t,e){return e.samples.reduce(GC,t)}function QC(t,e){return e.lastAccessed-t.lastAccessed}function YC(t){return{id:t.id,title:t.title}}function XC(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}function JC(t){return{samples:t.samples,color:t.color}}function ZC(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:ba(t.current)})]},t.label)}const e5=()=>{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()??"":""},t5=async()=>{const t=e5()||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")},ud="openchamber:menu-action",vi="openchamber:check-for-updates",s5=t=>{const e=tt(m=>m.openNewSessionDraft),n=Ne(m=>m.toggleCommandPalette),r=Ne(m=>m.setCommandPaletteOpen),i=Ne(m=>m.toggleHelpDialog),o=Ne(m=>m.toggleSidebar),l=Ne(m=>m.setSessionSwitcherOpen),a=Ne(m=>m.setSettingsDialogOpen),u=Ne(m=>m.setAboutDialogOpen),d=$r(m=>m.checkForUpdates),{setThemeMode:h}=nr(),f=c.useRef(!1),p=c.useCallback(()=>{f.current||(f.current=!0,d().then(()=>{const{available:m,error:x}=$r.getState();if(x){Fe.error("Failed to check for updates",{description:x});return}m||Fe.success("You are on the latest version")}).finally(()=>{f.current=!1}))},[d]),g=c.useCallback(()=>{bn.requestDirectoryDialog()},[]),w=c.useCallback(m=>{const x=Og();if(x.length===0)return;const b=tt.getState().currentSessionId,S=x.findIndex(k=>k.id===b);let C=m>0?0:x.length-1;S>=0&&(C=(S+m+x.length)%x.length);const N=x[C];N&&(l(!1),tt.getState().setCurrentSession(N.id))},[l]),v=c.useCallback(m=>{const{activeProjectId:x,projects:b,setActiveProject:S}=qt.getState();if(b.length===0)return;const C=b.findIndex(R=>R.id===x);let N=m>0?0:b.length-1;C>=0&&(N=(C+m+b.length)%b.length);const k=b[N];k&&S(k.id)},[]),y=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 x=tt.getState(),b=is.getState().currentDirectory;e(x.currentSessionId&&b?{directoryOverride:b}:void 0)}break;case"new-worktree-session":l(!1),mu();break;case"change-workspace":g();break;case"toggle-right-sidebar":{const x=is.getState().currentDirectory;if(!x)break;const b=Ne.getState(),S=lr(x),C=b.contextPanelByDirectory[S];C?.isOpen?b.closeContextPanel(S):C?.activeTabId?b.setActiveContextPanelTab(S,C.activeTabId):b.openContextSurface(S,"git");break}case"open-right-sidebar-git":{const x=is.getState().currentDirectory;if(!x)break;Ne.getState().openContextSurface(lr(x),"git");break}case"open-right-sidebar-files":{const x=is.getState().currentDirectory;if(!x)break;Ne.getState().openContextSurface(lr(x),"file");break}case"toggle-terminal":{const x=is.getState().currentDirectory;if(!x)break;Ne.getState().openContextSurface(lr(x),"terminal");break}case"toggle-terminal-expanded":{const x=is.getState().currentDirectory;if(!x)break;const b=lr(x),S=Ne.getState(),C=S.contextPanelByDirectory[b];(C?.isOpen?C.tabs.find(k=>k.id===C.activeTabId)?.mode:null)!=="terminal"&&S.openContextSurface(b,"terminal"),S.toggleContextPanelExpanded(b);break}case"copy":{const x=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(x)||t5();break}case"theme-light":h("light");break;case"theme-dark":h("dark");break;case"theme-system":h("system");break;case"add-selection-to-chat":Bg();break;case"toggle-sidebar":o();break;case"toggle-memory-debug":t?.();break;case"go-back":is.getState().goBack();break;case"go-forward":is.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":{fu().catch(()=>{Fe.error("Failed to collect OpenCode status")});break}}},[g,v,w,t,e,u,l,r,a,h,n,i,o]);c.useEffect(()=>{const m=b=>{const S=b.detail;S&&y(S)},x=()=>{p()};return window.addEventListener(ud,m),window.addEventListener(vi,x),()=>{window.removeEventListener(ud,m),window.removeEventListener(vi,x)}},[y,p]),c.useEffect(()=>{if(typeof window>"u")return;const x=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof x!="function")return;let b=null,S=null;return x("openchamber:menu-action",C=>{const N=C?.payload;typeof N=="string"&&y(N)}).then(C=>{b=C}).catch(()=>{}),x("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(vi))}).then(C=>{S=C}).catch(()=>{}),()=>{(async()=>{try{const N=b?.();N instanceof Promise&&await N}catch{}try{const N=S?.();N instanceof Promise&&await N}catch{}})()}},[y])},n5="openchamber:tray-action",md=5e3,r5=500,qm=20,fd=()=>{if(typeof window>"u")return!1;const t=window.__OPENCHAMBER_PLATFORM__;return t==="darwin"||t==="win32"||t==="linux"},hd=()=>typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.trayEnabled!==!1,o5=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},i5=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},Qm=(t,e)=>ku(t,e,Hr.getState().ids,Da.getState().rankById),a5=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},l5=(t,e,n,r,i)=>{if(!t)return"";const o=Bd(n,r,t),l=e.project?.name,a=o?.label?.trim()||l?.trim()||a5(t),u=So(t);let d=u&&i.get(u)||"";if(!d){for(const[h,f]of In.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},c5=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=dr.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 Lg){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:Wg(h),value:$g(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}},d5=async()=>{try{if(Ho())return"Local OpenChamber";const t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,e=Pn();if(e&&el(e,t))return"Local OpenChamber";const r=(await Sd()).hosts.find(i=>e?el(e,Of(i)):!1);return r?.label?.trim()?vd(r.label.trim()):"Instance"}catch{return""}},u5=()=>{const t=new Map,e=new Map,n=[],r=new Map;let i;try{i=Eo()}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:o5(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:i5(h),directory:o})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},m5=()=>{const t=Gs.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort(Qm).slice(0,qm).forEach(r=>{const i=Fs(r);i&&e.add(i)});const n=new Map;for(const r of t){if(!r?.id)continue;const i=Fs(r);if(!i||!e.has(i))continue;const o=n.get(i)??[];o.push(r.id),n.set(i,o)}return n},f5=(t,e)=>{const n=Ma.getState().index.session,r=Gs.getState().activeSessions,i=new Map;for(const m of r)if(m?.id&&m.parentID){const x=i.get(m.parentID)??[];x.push(m.id),i.set(m.parentID,x)}const o=m=>{const x=[],b=[...i.get(m)??[]],S=new Set;for(;b.length;){const C=b.pop();S.has(C)||(S.add(C),x.push(C),b.push(...i.get(C)??[]))}return x},l=Ne.getState();let a=0;if(l.dockBadgeEnabled)for(const m of r){if(!m?.id||m.parentID)continue;let x=n.unseenCount[m.id]??0;x===0&&l.notifyOnSubtasks&&(x=o(m.id).reduce((b,S)=>b+(n.unseenCount[S]??0),0)),x>0&&(a+=1)}if(!e)return{sessions:[],approvals:[],instanceName:t,usage:{mode:"usage",groups:[]},dockBadgeCount:a};const u=u5(),d=new Map(u.titleById);for(const m of r)m?.id&&m.title&&d.set(m.id,m.title);const h=Ra.getState().statusById,f=m=>{const x=u.statusById.get(m);return x&&x!=="idle"?x:h.get(m)?.status.type??x??"idle"},p=m=>{const x=m.map(b=>f(b));return x.includes("busy")?"busy":x.includes("retry")?"retry":"idle"},g=qt.getState().projects,w=tt.getState().availableWorktreesByProject,v=r.filter(m=>m?.id&&!m.parentID).slice().sort(Qm).slice(0,qm).map(m=>{const x=[m.id,...o(m.id)],b=Fs(m)??"";return{id:m.id,title:m.title||"Untitled session",status:p(x),branch:b?u.branchByDirectory.get(b)??"":"",unseen:x.reduce((S,C)=>S+(n.unseenCount[C]??0),0),hasError:x.some(S=>n.unseenHasError[S]??!1),directory:b,subtitle:l5(b,m,g,w,u.branchByDirectory)}}),y=u.approvals.map(m=>({...m,sessionTitle:d.get(m.sessionId)||""}));return{sessions:v,approvals:y,instanceName:t,usage:c5(),dockBadgeCount:a}},h5=()=>{c.useEffect(()=>{if(!fd()||!Ur())return;const t=hd();let e=!1,n="",r=null,i="";const o=()=>{if(e)return;const R=f5(i,t),I=JSON.stringify(R);I!==n&&(n=I,Fn("desktop_tray_update",R))},l=async()=>{const R=m5();await Promise.all([...R.entries()].map(async([I,P])=>{const T=await nn.getSessionStatusForDirectory(I).catch(()=>null);e||T===null||Fg(I,T,P)}))},a=()=>{e||r!==null||(r=window.setTimeout(()=>{r=null,o()},r5))},u=Ma.subscribe(()=>a()),d=Gs.subscribe(()=>a()),h=Ne.subscribe((R,I)=>{(R.dockBadgeEnabled!==I.dockBadgeEnabled||R.notifyOnSubtasks!==I.notifyOnSubtasks)&&a()}),f=()=>{e=!0,r!==null&&window.clearTimeout(r),u(),d(),h()};if(!t)return o(),f;d5().then(R=>{e||(i=R,o())});const p=new Map,g=()=>{if(e)return;let R;try{R=Eo()}catch{return}const I=new Set;for(const[P,T]of R.children.entries())I.add(P),p.has(P)||p.set(P,T.subscribe(()=>a()));for(const[P,T]of p)I.has(P)||(T(),p.delete(P))};let w=null;try{w=Eo().subscribeRegistry(()=>{g(),a()})}catch{}g();const v=qt.subscribe(()=>a()),y=tt.subscribe(()=>a()),m=In.subscribe(()=>a()),x=Ra.subscribe(()=>a()),b=Da.subscribe(()=>a()),S=Hr.subscribe(()=>a());l();const C=window.setInterval(()=>{l()},md),N=dr.subscribe(()=>a());dr.getState().loadSettings().then(()=>{if(e)return;const{dropdownProviderIds:R,results:I}=dr.getState();R.length>0&&R.some(T=>!I.some(E=>E.providerId===T))&&dr.getState().fetchQuotas(R)});const k=window.setInterval(()=>{g(),o()},md);return o(),()=>{f(),window.clearInterval(k),window.clearInterval(C),v(),y(),m(),x(),b(),S(),N(),w?.();for(const R of p.values())R();p.clear()}},[]),c.useEffect(()=>{if(!fd()||!hd()||!Ur())return;const e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!="function")return;const n=i=>{i.type==="respond-permission"&&_g(i.sessionId,i.id,i.response).catch(()=>{Fe.error("Failed to respond to permission request")})};let r=null;return e(n5,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{}}},[])},p5=45e3,g5=(t,e,n=window.setInterval.bind(window),r=window.clearInterval.bind(window))=>{t();const i=n(e,p5);return()=>r(i)},x5=t=>{const e=nt.c(3);let n,r;e[0]!==t?(n=()=>{if(t)return g5(b5,y5)},r=[t],e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),c.useEffect(n,r)};function b5(){zg(Ro())}function y5(){Fa()}const w5="/api/notifications/stream",S5=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),v5=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}},j5=t=>{const e=nt.c(3),n=t?.enabled??!0;let r,i;e[0]!==n?(r=()=>{if(!n||yn()||!wa()||typeof window>"u"||typeof EventSource>"u")return;const o=new EventSource(ya().sse(w5));return o.onmessage=k5,()=>{o.close()}},i=[n],e[0]=n,e[1]=r,e[2]=i):(r=e[1],i=e[2]),c.useEffect(r,i)};function k5(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Ne.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&S5())return;const r=v5(e);if(!r)return;wd()?.notifications?.notifyAgentCompletion(r)}const C5=6e4,N5=t=>{const e=nt.c(10),n=Ne(A5),r=Vg(P5),o=Sh(t)?.path??null;let l,a;e[0]!==n||e[1]!==r||e[2]!==o?(l=()=>{n&&r(o,{maxAgeMs:C5})},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 to(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 A5(t){return t.agentMemoryFeatureAvailable&&t.agentMemoryToolEnabled}function P5(t){return t.load}const pd="pwa-install-toast-shown",gd="pwa-install-toast-dismissed",D5=()=>{const t=nt.c(6),{browserTab:e}=vh(),{t:n}=vt(),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"||!wa()||!e)return;let u=null,d=null;const h=()=>{d!==null&&(Fe.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"&&Fe.success(r.current("pwa.installPrompt.started"))},p=w=>{const v=w;if(typeof v.prompt!="function")return;v.preventDefault(),u=v;const y=Io(),m=Bf();jh({dismissed:y.getItem(gd),sessionShown:m.getItem(pd),hasActiveToast:d!==null})&&(m.setItem(pd,"true"),d=Fe.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{f()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{Io().setItem(gd,"true"),h()}}}))},g=()=>{u=null,h(),Fe.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)},I5=({open:t,onOpenChange:e})=>{const{t:n}=vt(),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 x=await bs("/api/system/info");if(x.ok){const b=await x.json();if(typeof b.openchamberVersion=="string"&&b.openchamberVersion.trim()){o(b.openchamberVersion);return}}}catch{}o(await Ug())})()},[t]),c.useEffect(()=>{if(!t)return;let m=!1;return(async()=>{try{const b=await bs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!b.ok)return;const S=await b.json().catch(()=>null),C=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!m&&C&&a(C)}catch{}})(),()=>{m=!0}},[t]),c.useEffect(()=>{{g(null),v(!1);return}},[t,r]);const y=i;return s.jsx(Ds,{open:t,onOpenChange:e,children:s.jsx(Is,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(au,{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:[y&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:y})}),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(B,{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(B,{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(B,{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")})]})})})},xd=t=>{if(!(typeof window>"u")){if(t){window.location.href="openchamber://focus/mcp-auth";return}window.location.replace("/")}},ji=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},T5=(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},E5=()=>{const t=Kg(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=ji(a,"code"),d=Hg(a),h=Gg(a),f=ji(a,"error"),p=ji(a,"error_description");if(f){h&&bs(`/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 bs(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`);if(v.ok){const y=await v.json().catch(()=>null);w=y?.origin===qg,i(w),!g&&y?.name?.trim()&&(g={name:y.name.trim(),directory:typeof y.directory=="string"&&y.directory.trim()?y.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 bs(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`,{method:"DELETE"}).catch(()=>{}),n("success"),w&&xd(!0),l("Authorization completed. You can close this tab and return to OpenChamber.")}catch(g){h&&await bs(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`,{method:"DELETE"}).catch(()=>{}),n("error"),l(T5(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:Qg,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(dt,{type:"button",onClick:()=>xd(r),children:"Return to OpenChamber"})})]})})},bd=zn(()=>hn(()=>import("./OnboardingScreen-ToIakxb_.js"),__vite__mapDeps([147,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}))),R5=()=>{const t=nt.c(3),e=Ne(L5),n=Ne($5);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(I5,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},M5=t=>{const e=nt.c(21),{onRetry:n,isRetrying:r}=t,{t:i}=vt();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(dt,{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},yd=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",O5=()=>{if(typeof window>"u"||!_x())return null;const t=new URLSearchParams(window.location.search),e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),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}},B5=()=>typeof window>"u"?!1:window.location.pathname===ex,F5=t=>{const e=nt.c(25),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=t,o=is(W5),l=tt(z5),a=tt(V5),u=Hd(),d=c.useRef(null);let h;e[0]!==n.directory?(h=yd(n.directory),e[0]=n.directory,e[1]=h):h=e[1];const f=h;let p;e[2]!==o?(p=yd(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 C=`${f}
|
|
896
|
+
${n.sessionId}`;d.current===C&&l||(d.current=C,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 y;e[14]!==i?(y=s.jsx(Pu,{embeddedBackgroundWorkEnabled:i}),e[14]=i,e[15]=y):y=e[15];let m;e[16]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Od,{}),e[16]=m):m=e[16];let x;e[17]!==i||e[18]!==n.allowPromptingSubagentSessions||e[19]!==n.readOnly?(x=s.jsx(Md,{active:i,messagesEnabled:!0,readOnly:n.readOnly,initialAllowPromptingSubagentSessions:n.allowPromptingSubagentSessions}),e[17]=i,e[18]=n.allowPromptingSubagentSessions,e[19]=n.readOnly,e[20]=x):x=e[20];let b;e[21]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(Du,{}),e[21]=b):b=e[21];let S;return e[22]!==y||e[23]!==x?(S=s.jsxs(s.Fragment,{children:[y,m,x,b]}),e[22]=y,e[23]=x,e[24]=S):S=e[24],S};function _5({apis:t}){c.useEffect(()=>{Ff("App:mounted"),_f()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=Yt(_=>_.initializeApp),n=Yt(_=>_.isInitialized),r=Yt(_=>_.isConnected),i=Yt(_=>_.providers.length),o=Yt(_=>_.agents.length),l=Yt(_=>_.loadProviders),a=Yt(_=>_.loadAgents),u=tt(_=>_.error),d=tt(_=>_.clearError),h=is(_=>_.currentDirectory),f=is(_=>_.setDirectory),p=is(_=>_.isSwitchingDirectory),[g,w]=c.useState(!1),v=Dn(_=>_.refreshStatus),y=Oi(_=>_.refreshStatus),[m,x]=c.useState(()=>t.runtime.isVSCode),[b,S]=c.useState(!1),[C,N]=c.useState(!1),[k,R]=c.useState(0),[I,P]=c.useState(0),[T,E]=c.useState(!1),O=Ne(_=>_.wideChatLayoutEnabled),W=Ne(_=>_.mobileKeyboardMode),L=c.useMemo(()=>yn(),[]),F=ka(_=>_.setPlanModeEnabled),[D,j]=c.useState(()=>tl()),[A,M]=c.useState(()=>{const _=sl();return _!==null?nl({isDesktopShell:!0,bootOutcome:_}):null}),G=c.useRef(!1),q=c.useMemo(()=>O5(),[]),Z=!q||b,le=c.useMemo(()=>B5(),[]);c.useEffect(()=>(rl(g),()=>{rl(!1)}),[g]),c.useEffect(()=>(ad(g),()=>{ad(!1)}),[g]),c.useEffect(()=>{Lf(W)},[W]),c.useEffect(()=>{x(t.runtime.isVSCode)},[t.runtime.isVSCode]),c.useEffect(()=>Go(_=>{kh(_),P(oe=>oe+1),N(!1),R(oe=>oe+1)}),[]);const X=Dl(_=>{const oe=ls();return Object.values(_.runsByOriginalSessionID).filter(ce=>ce.status==="running"&&ce.runtimeKey===oe).map(ce=>`${ce.originalSessionID}:${ce.phase}:${ce.lastForwardedMessageID??""}:${ce.expectedAssistantParentID??""}`).sort().join("|")});c.useEffect(()=>{if(q)return;const _=ls(),oe=Object.values(Dl.getState().runsByOriginalSessionID).filter(ce=>ce.status==="running"&&ce.runtimeKey===_);for(const ce of oe)Yg(ce.originalSessionID)},[X,q,I]),c.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",O),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[O]),c.useEffect(()=>(ol(t),()=>ol(null)),[t]),c.useEffect(()=>{q||(v(t.github,{force:!0}),y(t.linear,{force:!0}))},[t.github,t.linear,q,r,v,y,I]),Xg();const te=D==="valid",re=A?.screen==="main";c.useEffect(()=>{if(!$f({isDesktopShell:L,isInitialized:n,bootOutcomeKnown:te,bootViewIsMain:re}))return;const _=setTimeout(()=>{const oe=document.getElementById("initial-loading");oe&&(oe.classList.add("fade-out"),setTimeout(()=>{oe.remove()},300))},150);return()=>clearTimeout(_)},[L,n,te,re]),c.useEffect(()=>{if(!L||D!=="malformed")return;const _=document.getElementById("initial-loading");_&&(_.textContent="Desktop startup failed — please restart the app.")},[L,D]),c.useEffect(()=>{if(L)return;const _=setTimeout(()=>{const oe=document.getElementById("initial-loading");oe&&!n&&(oe.classList.add("fade-out"),setTimeout(()=>{oe.remove()},300))},5e3);return()=>clearTimeout(_)},[L,n]),c.useEffect(()=>{let _=!1;return(async()=>{const ce=await bs("/health",{method:"GET"}).catch(()=>null);if(!ce||!ce.ok||_)return;const Q=await ce.json().catch(()=>null);if(!Q||_)return;const me=Q.planModeExperimentalEnabled;F(me===!0||me===1||me==="1"||me==="true")})(),()=>{_=!0}},[F]),c.useEffect(()=>{m||e()},[e,m]),c.useEffect(()=>{if(m||n)return;let _=!0,oe,ce=0;const Q=10,me=1e3,ke=async()=>{if(!_)return;if(ce>=Q){N(!0);return}const fe=Yt.getState();if(fe.isInitialized){N(!1);return}ce+=1,await fe.initializeApp();const De=Yt.getState();if(!_)return;if(De.isInitialized){N(!1);return}if(ce>=Q){N(!0);return}const je=Math.min(me*Math.pow(2,ce-1),16e3);oe=setTimeout(ke,je)};return oe=setTimeout(ke,me),()=>{_=!1,oe&&clearTimeout(oe)}},[k,n,m]),c.useEffect(()=>{n&&N(!1)},[n]),c.useEffect(()=>{if(!C)return;const _=document.getElementById("initial-loading");_&&(_.classList.add("fade-out"),setTimeout(()=>{_.remove()},300))},[C]),c.useEffect(()=>{if(m||!r||i>0&&o>0)return;let _=!0,oe=0;const ce=15,Q=async()=>{const ke=Yt.getState();if(!(ke.providers.length>0&&ke.agents.length>0))try{ke.providers.length===0&&await l({source:"startupRecovery"}),Yt.getState().agents.length===0&&await a({source:"startupRecovery"})}catch{}};Q();const me=setInterval(()=>{if(_){if(++oe>=ce){clearInterval(me);return}Q()}},2e3);return()=>{_=!1,clearInterval(me)}},[r,m,a,l,i,o]),c.useEffect(()=>{p||m||r&&nn.setDirectory(h)},[h,p,r,m]),c.useEffect(()=>{if(!q||typeof window>"u")return;const _=Q=>{S(Q?.visible===!0)},oe=Q=>{if(Q.origin!==window.location.origin||Q.source!==window.parent)return;const me=Q.data;me?.type===$u&&_(me.payload)},ce=window;return ce.__openchamberSetEmbeddedVisibility=_,window.addEventListener("message",oe),Fx(),()=>{window.removeEventListener("message",oe),ce.__openchamberSetEmbeddedVisibility===_&&delete ce.__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 _=oe=>{oe.storageArea===window.localStorage&&oe.key==="ui-store"&&Ne.persist.rehydrate()};return window.addEventListener("storage",_),()=>{window.removeEventListener("storage",_)}},[q]),c.useEffect(()=>{if(typeof window>"u")return;const _=oe=>{const ce=oe.detail,Q=typeof ce?.sessionId=="string"?ce.sessionId.trim():"";if(!Q)return;const me=typeof ce?.directory=="string"&&ce.directory.trim().length>0?ce.directory.trim():null;tt.getState().setCurrentSession(Q,me)};return window.addEventListener("openchamber:open-session",_),()=>window.removeEventListener("openchamber:open-session",_)},[]),c.useEffect(()=>{if(typeof window>"u")return;const _=()=>{Fn("desktop_open_draft_mini_chat_window",{directory:"",projectId:null})};return window.addEventListener("openchamber:open-mini-chat",_),()=>window.removeEventListener("openchamber:open-mini-chat",_)},[]),c.useEffect(()=>{if(typeof window>"u")return;const _=()=>{const oe=tt.getState().currentSessionId;oe&&lu(oe)};return window.addEventListener("focus",_),()=>window.removeEventListener("focus",_)},[]),c.useEffect(()=>{if(typeof window>"u")return;const _=oe=>{const ce=oe.detail,Q=typeof ce?.directory=="string"&&ce.directory.trim().length>0?ce.directory.trim():null,me=typeof ce?.projectId=="string"&&ce.projectId.trim().length>0?ce.projectId.trim():null,ke=!!(Q||me);Ne.getState().setSessionSwitcherOpen(!1),tt.getState().openNewSessionDraft({target:ke?"project":"chat",selectedProjectId:ke?me:null,directoryOverride:ke?Q:null,preserveDirectoryOverride:!!Q})};return window.addEventListener("openchamber:open-draft-session",_),()=>window.removeEventListener("openchamber:open-draft-session",_)},[]),c.useEffect(()=>{typeof window>"u"||!n||p||G.current||(G.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,p]),Jg({enabled:Z}),j5({enabled:Z}),N5(h||null),D5(),Zg(),hx(),Ch();const Se=c.useCallback(()=>{w(_=>!_)},[]);s5(Se),h5(),x5(!q),c.useEffect(()=>{if(q)return;const _=()=>w(oe=>!oe);return window.addEventListener("openchamber:memory-debug-toggle",_),()=>window.removeEventListener("openchamber:memory-debug-toggle",_)},[q]),c.useEffect(()=>{q||u&&setTimeout(()=>d(),5e3)},[d,q,u]),c.useEffect(()=>{if(!L||D!=="not-injected")return;let _=!1,oe=0;const ce=200,Q=2e3,me=50,ke=()=>{if(_)return;oe++;const fe=tl();if(fe!=="not-injected"){if(_=!0,j(fe),fe==="valid"){const je=sl();je&&M(nl({isDesktopShell:!0,bootOutcome:je}))}return}const De=Math.min(ce*Math.pow(1.1,oe),Q);if(oe>=me){const je=document.getElementById("initial-loading");je&&!je.textContent?.includes("taking longer")&&(je.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(ke,De)};return window.setTimeout(ke,ce),()=>{_=!0}},[L,D]);const ue=c.useCallback(async()=>{if(Wf({isDesktopShell:yn(),isDesktopLocalOriginActive:Ho()})){await zf();return}window.location.reload()},[]),ye=c.useCallback(async()=>{if(!T){N(!1),E(!0);try{await Yt.getState().initializeApp()}finally{E(!1)}Yt.getState().isInitialized||R(_=>_+1)}},[T]),ve=_=>{if(_.screen==="recovery")return _.variant};if(L&&A&&A.screen!=="main"){if(A.screen==="chooser")return s.jsx(Bs,{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(bd,{mode:"first-launch",localAvailable:A.localAvailable!==!1,onCliAvailable:ue,onChooseRemote:()=>{}})})})});const _=ve(A),oe=A.screen==="recovery"&&"url"in A?A.url:void 0;return s.jsx(Bs,{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(bd,{mode:"recovery",recoveryVariant:_,recoveryHostUrl:oe,recoveryHostLabel:void 0,localAvailable:A.localAvailable!==!1,onCliAvailable:ue})})})})}if(q)return s.jsx(Bs,{children:s.jsx(Il,{sdk:nn.getSdkClient(),directory:h||"",children:s.jsx(Tl,{apis:t,children:s.jsx(Wi,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(F5,{embeddedSessionChat:q,isVSCodeRuntime:m,embeddedBackgroundWorkEnabled:Z}),s.jsx(El,{}),s.jsx(Rl,{})]})})})},I)});if(le)return s.jsx(Bs,{children:s.jsx(E5,{})});if(C&&!n&&!m&&!q)return s.jsx(Bs,{children:s.jsx(M5,{onRetry:()=>{ye()},isRetrying:T})});const be=!n&&!L;return s.jsx(Bs,{children:s.jsx(Il,{sdk:nn.getSdkClient(),directory:h||"",children:s.jsx(Tl,{apis:t,children:s.jsx(kC,{children:s.jsx(Wi,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:L?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(Pu,{embeddedBackgroundWorkEnabled:Z}),s.jsx(Od,{}),s.jsx(J4,{}),s.jsx(Nh,{ready:n&&(!L||te&&re)}),s.jsx(Du,{}),s.jsx(El,{}),s.jsx(Rl,{}),!be&&s.jsxs(s.Fragment,{children:[s.jsx(Ah,{}),s.jsx(R5,{}),g&&s.jsx(BC,{onClose:()=>w(!1)})]})]})})})})},I)})}function L5(t){return t.isAboutDialogOpen}function $5(t){return t.setAboutDialogOpen}function W5(t){return t.currentDirectory}function z5(t){return t.currentSessionId}function V5(t){return t.setCurrentSession}const U5=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();tx();Vf().then(()=>{Promise.all([Uf(),sx()]).catch(t=>{console.error("[main] settings init failed:",t)}),nx(),rx(),ox()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Ym=document.getElementById("root");if(!Ym)throw new Error("Root element not found");ix();uf.createRoot(Ym).render(s.jsx(mt.StrictMode,{children:s.jsx(ax,{children:s.jsx(lx,{children:s.jsx(cx,{children:s.jsx(dx,{children:s.jsx(_5,{apis:U5})})})})})}));const cN=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{fy as W,sy as a,lN as b,rm as g,cN as m,my as u,nm as v};
|