@openchamber/web 1.18.2 → 1.18.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/commands-models.js +1 -1
- package/dist/assets/{CodeMirrorCommentWidgets-CxcJ5x9h.js → CodeMirrorCommentWidgets-4qZbrEXU.js} +1 -1
- package/dist/assets/{CommitSection-C9sBBYAJ.js → CommitSection-MJmntVPJ.js} +1 -1
- package/dist/assets/{DiagramEditor-C7nUw7p3.js → DiagramEditor-jnG3Hbxg.js} +1 -1
- package/dist/assets/{DiagramView-cYxZP-HS.js → DiagramView-CFXxgg_a.js} +1 -1
- package/dist/assets/{DiffView-1zd0slLu.js → DiffView-DZIoOnV7.js} +2 -2
- package/dist/assets/FilesView-BKL6YlKG.js +14 -0
- package/dist/assets/{GitView-OSVIn5V1.js → GitView-DBFrDDBv.js} +1 -1
- package/dist/assets/{JsonTreeView-Kgepz4pR.js → JsonTreeView-DLW2Wy1g.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DKIylIK7.js +1 -0
- package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +12 -0
- package/dist/assets/OnboardingScreen-D2Y6djMw.js +1 -0
- package/dist/assets/{PatchDiff-Cddz02Ya.js → PatchDiff-BuLPx7AN.js} +1 -1
- package/dist/assets/{PierreDiffViewer-B5k0KvPW.js → PierreDiffViewer-BHm4Yr0X.js} +2 -2
- package/dist/assets/{PlanView-BYgHBHDt.js → PlanView-ZYEJn8A_.js} +3 -3
- package/dist/assets/{SessionSwitcherDropdown-ig2OT22Z.js → SessionSwitcherDropdown-rro-SsaO.js} +1 -1
- package/dist/assets/SettingsView-5RmswFZe.js +28 -0
- package/dist/assets/{SettingsWindow-CNHM8ifT.js → SettingsWindow-BZhAYFdS.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DrGeYq2p.js → ToolOutputDialog-Za6V4VMJ.js} +7 -7
- package/dist/assets/{ToolPartDiffPreview-BRmPpe94.js → ToolPartDiffPreview-BL-9ixyC.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-Dcu8Q-5P.js → VirtualizedFileDiff-CwGocYQd.js} +1 -1
- package/dist/assets/{WalkthroughView-HStEYdD2.js → WalkthroughView-5DyvN03T.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-DQE7R9IY.js → computeVirtualFileMetrics-Da00Jg7M.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +1 -0
- package/dist/assets/de-u7gSnqWs.js +9 -0
- package/dist/assets/es-T9O7aAOr.js +15 -0
- package/dist/assets/fr-Oor7ewbE.js +13 -0
- package/dist/assets/index-BzIpNlNE.css +1 -0
- package/dist/assets/{index-BgQEgA2a.js → index-C0yNhuZw.js} +1 -1
- package/dist/assets/index-DRpChWux.js +7 -0
- package/dist/assets/{isDiffPlainText-XyBCe4eD.js → isDiffPlainText-D9YpoLrV.js} +1 -1
- package/dist/assets/{isFilePlainText-JbqDfa3n.js → isFilePlainText-gTibdNIe.js} +1 -1
- package/dist/assets/ja-DHpqbVmr.js +15 -0
- package/dist/assets/ko-CwLkS3nx.js +15 -0
- package/dist/assets/{main-LfcbGv7C.js → main-D7UcL3VQ.js} +2 -2
- package/dist/assets/main-DPMd2iKS.js +915 -0
- package/dist/assets/markdownCore-DDrHVneM.js +2 -0
- package/dist/assets/{miniChat-CUp_elRz.js → miniChat-O_GVoEbc.js} +2 -2
- package/dist/assets/{mobile-CBSN7BsH.js → mobile-Br4TtAqc.js} +2 -2
- package/dist/assets/{patchFileDiff-DCIXUHRJ.js → patchFileDiff-KNkxM1C1.js} +2 -2
- package/dist/assets/{pl-tHTP6XQx.js → pl-CcZILN8q.js} +4 -4
- package/dist/assets/pt-BR-DYHhVK6o.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-eZl-5STF.js → renderElectronMiniChatApp-CJpdxTT1.js} +2 -2
- package/dist/assets/renderMobileApp-toj9cXoh.js +25 -0
- package/dist/assets/runtimeEndpointReset-BVmispdD.js +13 -0
- package/dist/assets/scheduledTasksApi-ByKya3Un.js +1 -0
- package/dist/assets/{shikiHighlight-eU8abJ3T.js → shikiHighlight-C7LTbwFx.js} +1 -1
- package/dist/assets/uk-BA2kZR38.js +15 -0
- package/dist/assets/{useAppFontEffects-Bbpz77To.js → useAppFontEffects-BikB6enL.js} +138 -138
- package/dist/assets/useInlineCommentController-CYPvYJDt.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-Dzt9rWZZ.js → vendor-codemirror-language-data-CLHw8NWn.js} +2 -2
- package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
- package/dist/assets/{web-components-DGvnI0zx.js → web-components-GMc3oR3i.js} +1 -1
- package/dist/assets/zh-CN-dlOQK6v9.js +15 -0
- package/dist/assets/zh-TW-BnqQ-WL5.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/index.js +65 -19
- package/server/lib/agent-tool/DOCUMENTATION.md +21 -6
- package/server/lib/agent-tool/runtime.js +90 -16
- package/server/lib/agent-tool/runtime.test.js +86 -0
- package/server/lib/browser-control/DOCUMENTATION.md +50 -0
- package/server/lib/browser-control/broker.js +154 -0
- package/server/lib/browser-control/broker.test.js +191 -0
- package/server/lib/browser-control/routes.js +48 -0
- package/server/lib/browser-control/routes.test.js +108 -0
- package/server/lib/dev-servers/parse.js +203 -0
- package/server/lib/dev-servers/parse.test.js +174 -0
- package/server/lib/dev-servers/routes.js +135 -0
- package/server/lib/dev-tunnel/DOCUMENTATION.md +57 -0
- package/server/lib/dev-tunnel/client.js +193 -0
- package/server/lib/dev-tunnel/runtime.js +189 -0
- package/server/lib/dev-tunnel/tunnel.test.js +291 -0
- package/server/lib/git/credentials.js +0 -33
- package/server/lib/github/DOCUMENTATION.md +1 -1
- package/server/lib/markdown-image-grants/DOCUMENTATION.md +36 -0
- package/server/lib/markdown-image-grants/routes.js +340 -0
- package/server/lib/markdown-image-grants/routes.test.js +221 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +9 -0
- package/server/lib/openchamber-control/actions.js +33 -1
- package/server/lib/openchamber-control/screenshots.js +83 -0
- package/server/lib/openchamber-control/screenshots.test.js +84 -0
- package/server/lib/openchamber-control/service.js +141 -2
- package/server/lib/openchamber-control/service.test.js +55 -0
- package/server/lib/opencode/core-routes.js +31 -52
- package/server/lib/opencode/core-routes.test.js +37 -9
- package/server/lib/opencode/feature-routes-runtime.js +15 -0
- package/server/lib/opencode/server-startup-runtime.js +22 -1
- package/server/lib/opencode/server-startup-runtime.test.js +44 -0
- package/server/lib/opencode/settings-helpers.js +3 -9
- package/server/lib/projects/project-config.js +181 -2
- package/server/lib/projects/project-config.test.js +295 -0
- package/server/lib/quota/DOCUMENTATION.md +4 -2
- package/server/lib/quota/credentials/providers.js +0 -7
- package/server/lib/quota/credentials/store.js +11 -1
- package/server/lib/quota/credentials/store.test.js +9 -1
- package/server/lib/quota/providers/opencode-go.js +35 -35
- package/server/lib/quota/providers/opencode-go.test.js +52 -7
- package/server/lib/quota/routes.js +0 -2
- package/server/lib/relay/DOCUMENTATION.md +2 -0
- package/server/lib/relay/tunnel-host.js +157 -33
- package/server/lib/relay/tunnel-host.test.js +147 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +49 -0
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +488 -0
- package/server/lib/scheduled-tasks/routes.js +6 -0
- package/server/lib/scheduled-tasks/runtime.js +369 -108
- package/server/lib/scheduled-tasks/service.js +7 -1
- package/server/lib/scheduled-tasks/service.test.js +20 -0
- package/server/lib/walkthrough/index.js +0 -2
- package/server/sse-routes.test.js +3 -0
- package/dist/assets/FilesView-WkxsWHBE.js +0 -14
- package/dist/assets/MarkdownRendererImpl-CKAsRfIk.js +0 -12
- package/dist/assets/OnboardingScreen-BCgYA7J5.js +0 -1
- package/dist/assets/SettingsView-e7Fmxnz8.js +0 -28
- package/dist/assets/contextPanelEmbeddedChat-5VGWIT_J.js +0 -1
- package/dist/assets/de-B6t6T54h.js +0 -9
- package/dist/assets/es-DH9NUKge.js +0 -15
- package/dist/assets/fr-Do4t2KmA.js +0 -13
- package/dist/assets/index-B45s9aAX.css +0 -1
- package/dist/assets/index-CNrN5qDs.js +0 -7
- package/dist/assets/ja-DJT9EM80.js +0 -15
- package/dist/assets/ko-CfWRq2p4.js +0 -15
- package/dist/assets/main-B4oBRI9u.js +0 -193
- package/dist/assets/markdownCore-A3_L34oS.js +0 -2
- package/dist/assets/pt-BR-BDEzzltP.js +0 -15
- package/dist/assets/renderMobileApp-DA7wpIBi.js +0 -23
- package/dist/assets/runtimeEndpointReset-D5izT-u5.js +0 -13
- package/dist/assets/scheduledTasksApi-CTJdfSWc.js +0 -1
- package/dist/assets/uk-B6Q32nyk.js +0 -15
- package/dist/assets/useInlineCommentController-D7zs7-BQ.js +0 -2
- package/dist/assets/vendor-zumer-snapdom-Btyu_Xi2.js +0 -8
- package/dist/assets/zh-CN-7MGcwGaC.js +0 -15
- package/dist/assets/zh-TW-CFPfqxlL.js +0 -15
- package/server/lib/preview/proxy-runtime.js +0 -1604
- package/server/lib/preview/proxy-runtime.test.js +0 -528
- package/server/lib/quota/opencode-go-credentials.js +0 -11
- package/server/lib/quota/opencode-go-credentials.test.js +0 -32
- package/server/lib/quota/routes.test.js +0 -40
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-C0yNhuZw.js","assets/useAppFontEffects-BikB6enL.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-DRpChWux.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/vendor-zustand-BAGL70zf.js","assets/index-BzIpNlNE.css","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-D_V6hAcE.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-floating-ui-react-dom-DKpLs02S.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-B-bSg3P5.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-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-DUOssd4j.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-DSzLbZiS.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-Bbw3D7r0.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-BjbBRsUA.js","assets/vendor-codemirror-lang-json-ryCw7nab.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-VgNqFSH-.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-B3Qe3OpS.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-FGQydhTc.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-CLHw8NWn.js","assets/vendor-codemirror-lang-python-N414WYK-.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-ARAOgp1x.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CRSgBxjL.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/computeVirtualFileMetrics-Da00Jg7M.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/isFilePlainText-gTibdNIe.js","assets/isDiffPlainText-D9YpoLrV.js","assets/vendor-diff-C3JhlQdm.js","assets/vendor-lru_map-Tstukz9J.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/vendor-ghostty-web-CrxinGGH.js","assets/vendor-capacitor-keyboard-CYccoJjr.js","assets/vendor-capacitor-core-B4EWRrHz.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as Vt}from"./vendor-vite-runtime-DD1OZmLC.js";import{f as Ye,r as J,j as t,R as l}from"./vendor-react-BUCujlKS.js";import{dZ as Pr,aG as Dr,f as rt,o as Er,bs as Zt,bt as es,bv as ts,I as C,bU as Rr,bQ as Js,h as q,B as Ne,a$ as Un,g as Ar,t as ve,d_ as Br,d$ as Mr,e0 as Lr,O as Fr,dH as Or,e1 as Ur,e2 as Wr,e3 as zr,y as nt,e4 as $r,d3 as Vr,d4 as _r,d5 as Gr,l as pt,e5 as Hr,dj as Wn,e6 as Kr,dk as qr,bR as ss,cN as Yr,bu as gs,aV as xs,e7 as Jr,e8 as Qr,e9 as Xr,ea as Zr,eb as eo,ec as to,ed as so,ee as no,b as gt,c0 as ro,_ as Qs,dg as oo,dD as zn,ds as $n,du as ao,ef as io,u as As,cq as lo,eg as Bs,S as ht,cx as co,eh as Xs,ei as uo,ej as mo,ek as Zs,el as fo,em as ho,en as po,eo as go,aW as xo,ep as bo,aU as Pt,aR as Dt,aT as Et,bP as Vn,bK as yo,bL as wo,eq as vo,bM as ko,bN as jo,bO as en,L as _n,N as No,T as So,U as Co,R as Io,er as Gn,w as To,x as Po,es as Do,et as Eo,eu as Ro,ev as Ao,aX as Mt,aY as Lt,aZ as Ft,cl as Ms,cm as Ls,cn as Fs,co as Os,ch as Ct,ci as yt,ew as zt,aQ as jt,M as Yt,bw as Bo,bx as Gs,ex as tn,V as Hs,aj as hs,b_ as Mo,ey as Hn,bS as Lo,dz as Fo,a4 as Ks,ez as ys,m as Kn,cR as $t,eA as sn,eB as nn,cP as rn,bT as Oo,eC as Uo,eD as Wo,dt as zo,eE as $o,eF as Vo,af as os,ag as on,eG as _o,eH as Go,c5 as Ho,eI as Ko,eJ as qo,eK as as,eL as Yo,eM as Jo,eN as Qo,eO as an,eP as ln,eQ as Xo,cA as Zo,ah as ea,a0 as ta,bI as sa,eR as qn,dW as na,da as ra,eS as oa,eT as aa,eU as ia,bF as la,cF as ca}from"./useAppFontEffects-BikB6enL.js";import{ag as cn,ah as da,ai as dn,aj as ua,i as ma,ak as fa,C as Yn,Y as ha,r as Nt,u as Ae,y as pa,b as ga,q as xa,a as ws,d as un,K as Jn,U as ba,al as St,n as ya,l as ns,x as Qn,_ as wa,$ as va,am as ka,an as ja,t as _t,ao as Na,ap as Sa,a5 as Ca,aq as Ht,ar as vs,as as Xn,S as Ia,m as Ta,w as Pa}from"./index-DRpChWux.js";import{C as Da,c as Ea,b as Ra,d as Aa,S as Ba,M as Ma,a as La,g as Fa,h as Oa,i as Ua}from"./vendor-base-ui-D_V6hAcE.js";import{c as bs,d as Zn,p as er,a as Wa}from"./vendor-zustand-BAGL70zf.js";import{i as tr}from"./contextPanelEmbeddedChat-B-bSg3P5.js";import{toast as mn}from"./vendor-sonner-DFyL3AvE.js";import{f as sr,h as nr,P as rr,k as za,D as or,j as ar}from"./vendor-dnd-kit-core-BZknOX2w.js";import{u as ir,S as lr,h as $a,a as Va,v as _a}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as cr}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";const Ga=["typescript","javascript","tsx","jsx","json","markdown"],dr={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let fn=null;const ur=()=>(fn??=Promise.all([Vt(()=>import("./index-C0yNhuZw.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])),Vt(()=>import("./workerFactory-tw7cIdmV.js"),[]),Vt(()=>import("./appThemeRegistry-BK0dHKa6.js"),__vite__mapDeps([111,112,98,99,5,83,84,85,86,87,88,89,90,91,92,93,94,95,96]))]).then(([s,e,n])=>({WorkerPoolManager:s.WorkerPoolManager,workerFactory:e.workerFactory,ensurePierreThemeRegistered:n.ensurePierreThemeRegistered})),fn),Jt={},hn=new Set,Us=new Set;let us={light:"pierre-light",dark:"pierre-dark"};const Ha=()=>{for(const s of Us)s()},mr=(s,e)=>{e.setRenderOptions({theme:us,lineDiffType:dr[s].lineDiffType})},Ws=s=>{typeof window>"u"||hn.has(s)||(hn.add(s),ur().then(e=>{if(Jt[s])return;const n=dr[s],r=new e.WorkerPoolManager({workerFactory:e.workerFactory,poolSize:n.poolSize,totalASTLRUCacheSize:n.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:Ga,lineDiffType:n.lineDiffType,preferredHighlighter:"shiki-wasm"});r.initialize(),Jt[s]=r,mr(s,r),Ha()}))},Ka=s=>(Us.add(s),()=>Us.delete(s)),qa=s=>{if(!(us.light===s.light&&us.dark===s.dark)){us=s;for(const e of Object.keys(Jt)){const n=Jt[e];n&&mr(e,n)}}},Zc=s=>{const e=Ye.c(15),{children:n}=s,r=Pr();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=cn(!1),e[0]=o):o=e[0];const a=o;let i;e[1]===Symbol.for("react.memo_cache_sentinel")?(i=cn(!0),e[1]=i):i=e[1];const u=i,f=r?.lightThemeId??a.metadata.id,h=r?.darkThemeId??u.metadata.id;let c;e[2]!==f||e[3]!==r?.availableThemes?(c=r?.availableThemes.find(R=>R.metadata.id===f)??a,e[2]=f,e[3]=r?.availableThemes,e[4]=c):c=e[4];const g=c;let p;e[5]!==h||e[6]!==r?.availableThemes?(p=r?.availableThemes.find(R=>R.metadata.id===h)??u,e[5]=h,e[6]=r?.availableThemes,e[7]=p):p=e[7];const x=p;let d,y;e[8]!==x||e[9]!==g?(d=()=>{let R=!1;return ur().then(M=>{R||(M.ensurePierreThemeRegistered(g),M.ensurePierreThemeRegistered(x),qa({light:g.metadata.id,dark:x.metadata.id}))}),()=>{R=!0}},y=[x,g],e[8]=x,e[9]=g,e[10]=d,e[11]=y):(d=e[10],y=e[11]),J.useEffect(d,y);let j;e[12]===Symbol.for("react.memo_cache_sentinel")?(j=[],e[12]=j):j=e[12],J.useEffect(Ja,j);let T;return e[13]!==n?(T=t.jsx(t.Fragment,{children:n}),e[13]=n,e[14]=T):T=e[14],T},ed=s=>{const e=Ye.c(5),n=s===void 0?"unified":s;let r;e[0]!==n?(r=()=>Jt[n],e[0]=n,e[1]=r):r=e[1];const o=J.useSyncExternalStore(Ka,r,Qa);let a,i;return e[2]!==n?(a=()=>{Ws(n)},i=[n],e[2]=n,e[3]=a,e[4]=i):(a=e[3],i=e[4]),J.useEffect(a,i),o};function Ya(){Ws("unified"),Ws("split")}function Ja(){if(typeof window>"u")return;const s=Ya;if(typeof window.requestIdleCallback=="function"){const n=window.requestIdleCallback(s,{timeout:5e3});return()=>window.cancelIdleCallback(n)}const e=window.setTimeout(s,2e3);return()=>window.clearTimeout(e)}function Qa(){}const pn="openchamber.update-install-id";function Xa(){if(!(typeof window>"u"||typeof crypto.randomUUID!="function"))try{const s=window.localStorage.getItem(pn)?.trim();if(s)return s;const e=crypto.randomUUID();return window.localStorage.setItem(pn,e),e}catch{return}}function Za(){if(typeof window>"u")return"unknown";try{const{deviceType:s}=Dr();return s}catch{return"unknown"}}function ei(){const s=typeof window<"u"?window.__OPENCHAMBER_ELECTRON__?.arch?.toLowerCase?.():void 0;if(s==="arm64"||s==="aarch64")return"arm64";if(s==="x64"||s==="amd64"||s==="x86_64")return"x64";const e=typeof window<"u"?window.__VSCODE_CONFIG__?.arch?.toLowerCase?.():void 0;if(e==="arm64"||e==="aarch64")return"arm64";if(e==="x64"||e==="amd64"||e==="x86_64")return"x64";const r=(typeof navigator<"u"?navigator.userAgentData:void 0)?.architecture?.toLowerCase?.();if(r==="arm"||r==="arm64"||r==="aarch64")return"arm64";if(r==="x86"||r==="x64"||r==="amd64")return"x64";const o=typeof navigator<"u"?navigator.userAgent.toLowerCase():"";return o.includes("aarch64")||o.includes("arm64")||o.includes("armv")?"arm64":o.includes("x86_64")||o.includes("x64")||o.includes("amd64")||o.includes("win64")?"x64":"unknown"}function ti(){const s=ga();if(s==="android"||s==="ios")return s;if(typeof navigator>"u")return"web";const e=(navigator.platform||"").toLowerCase();return e.includes("mac")?"macos":e.includes("win")?"windows":e.includes("linux")?"linux":"web"}function si(s){const e=Ae.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});if(n.set("deviceClass",Za()),n.set("arch",ei()),n.set("platform",ti()),e&&(s==="desktop"||s==="mobile")){const r=Xa();r&&n.set("installId",r)}return s==="desktop"?(n.set("appType","desktop-electron"),n.set("instanceMode",pa()?"local":"remote"),n):s==="vscode"?(n.set("appType","vscode"),n.set("instanceMode","local"),n):s==="mobile"?(n.set("appType","mobile-capacitor"),n.set("instanceMode","remote"),n):(n.set("appType","web"),n.set("instanceMode","unknown"),n)}async function is(s,e){try{const n=si(s),r=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e?n.set("currentVersion",e):s==="vscode"&&r&&n.set("currentVersion",r);const o=await Nt(`/api/openchamber/update-check?${n.toString()}`,{method:"GET",headers:{Accept:"application/json"},priority:"low"});if(!o.ok)throw new Error(`Server responded with ${o.status}`);const a=await o.json();return{available:a.available??!1,version:a.version,currentVersion:a.currentVersion??"unknown",body:a.body,releaseUrl:a.releaseUrl,downloadUrl:a.downloadUrl,nextSuggestedCheckInSec:typeof a.nextSuggestedCheckInSec=="number"&&Number.isFinite(a.nextSuggestedCheckInSec)?a.nextSuggestedCheckInSec:void 0,packageManager:a.packageManager,updateCommand:a.updateCommand}}catch(n){return console.warn("Failed to check for updates:",n),null}}function ni(){return ma()?"mobile":fa()?"desktop":Yn()?"vscode":ha()?"web":null}const gn={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},ri=bs()((s,e)=>({...gn,checkForUpdates:async()=>{const n=ni();if(!n)return null;s({checking:!0,error:null,runtimeType:n});try{let r=null,o=null;if(n==="desktop"){const a="1.18.4",[i,u]=await Promise.allSettled([dn(),is("desktop",a)]),f=i.status==="fulfilled"?i.value:null;return o=u.status==="fulfilled"?u.value?.nextSuggestedCheckInSec??null:null,s({checking:!1,available:f?.available??!1,info:f,lastChecked:Date.now(),nextCheckInSec:o}),o}else n==="web"?(r=await is("web"),o=r?.nextSuggestedCheckInSec??null):n==="vscode"?o=(await is("vscode"))?.nextSuggestedCheckInSec??null:n==="mobile"&&(r=await is("mobile","1.18.4"),o=r?.nextSuggestedCheckInSec??null);return s({checking:!1,available:n==="vscode"?!1:r?.available??!1,info:n==="vscode"?null:r,lastChecked:Date.now(),nextCheckInSec:o}),o}catch(r){return s({checking:!1,error:r instanceof Error?r.message:"Failed to check for updates"}),null}},downloadUpdate:async()=>{const{available:n,runtimeType:r}=e();if(!(r!=="desktop"||!n)){s({downloading:!0,error:null,progress:null});try{const o=await dn();if(!o?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(s(i=>({info:i.info?{...i.info,...o,body:i.info.body||o.body,available:i.info.available}:o})),!await ua(i=>{s({progress:i})}))throw new Error("Desktop update only works on Local instance");s({downloading:!1,downloaded:!0})}catch(o){s({downloading:!1,error:o instanceof Error?o.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:r}=e();if(!(r!=="desktop"||!n))try{if(!await da())throw new Error("Desktop restart only works on Local instance")}catch(o){s({error:o instanceof Error?o.message:"Failed to restart"})}},dismiss:()=>{s({available:!1,downloaded:!1,info:null})},reset:()=>{s(gn)}})),xn="https://github.com/openchamber/openchamber/releases";function oi(s){const e=new Date(`${s}T00:00:00`);return Number.isNaN(e.getTime())?s:new Intl.DateTimeFormat(Un(),{year:"numeric",month:"short",day:"numeric"}).format(e)}function ai(s){return s.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function bn(s){return s.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function ii(s,e){const n=s.split(".").map(o=>Number.parseInt(o,10)),r=e.split(".").map(o=>Number.parseInt(o,10));for(let o=0;o<3;o+=1){const a=Number.isFinite(n[o])?n[o]:0,i=Number.isFinite(r[o])?r[o]:0;if(a!==i)return i-a}return 0}function li(s){const e=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let r;for(;(r=e.exec(s))!==null;)n.push({version:r[1]??"",date:r[2]??"",start:r.index});return n.length===0?[]:n.map((o,a)=>{const i=n[a+1]?.start??s.length,u=s.slice(o.start,i).trim();return{version:o.version,date:o.date,start:o.start,end:i,raw:u}})}const yn=2e3,ci=600*1e3;async function di(){try{const s=await Nt("/api/openchamber/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});return s.ok?{success:!0,autoRestart:(await s.json().catch(()=>({}))).autoRestart!==!1}:{success:!1,error:(await s.json().catch(()=>({}))).error||`Server error: ${s.status}`}}catch(s){return{success:!1,error:s instanceof Error?s.message:void 0}}}async function ui(){try{return(await Nt("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function mi(s,e=Math.ceil(ci/yn),n=yn){for(let r=0;r<e;r++){try{const o=await Nt("/api/openchamber/update-check?reportUsage=false",{method:"GET",headers:{Accept:"application/json"}});if(o.ok){const a=await o.json().catch(()=>null);if(a&&a.available===!1||a&&typeof a.currentVersion=="string"&&typeof s=="string"&&a.currentVersion!==s)return!0}else if((o.status===401||o.status===403)&&await ui())return!0}catch{}await new Promise(o=>setTimeout(o,n))}return!1}const td=({open:s,onOpenChange:e,info:n,downloading:r,downloaded:o,progress:a,error:i,onDownload:u,onRestart:f,runtimeType:h="desktop"})=>{const{t:c}=rt(),[g,p]=J.useState(!1),[x,d]=J.useState("idle"),[y,j]=J.useState(null),T=n?.version?n.releaseUrl||`${xn}/tag/v${n.version}`:xn,R=n?.downloadUrl||T,M=a?.total?Math.round(a.downloaded/a.total*100):0,G=h==="web",w=h==="mobile",k=n?.updateCommand||"openchamber update";J.useEffect(()=>{s||(d("idle"),j(null))},[s]);const I=async()=>{(await Ar(k)).ok&&(p(!0),setTimeout(()=>p(!1),2e3))},F=J.useCallback(async z=>{await Er(z)},[]),re=J.useCallback(async()=>{d("updating"),j(null);const z=await di();if(!z.success){d("error"),j(z.error||c("updateDialog.error.updateFailed"));return}z.autoRestart&&(d("restarting"),await new Promise(W=>setTimeout(W,2e3))),d("reconnecting"),await mi(n?.currentVersion)?window.location.reload():(d("error"),j(c("updateDialog.error.takingLonger")))},[n?.currentVersion,c]),te=J.useCallback(()=>{F(R)},[F,R]),L=x!=="idle"&&x!=="error",V=J.useMemo(()=>{if(!n?.body)return null;const z=n.body.trim();if(!z)return null;const ne=li(z);if(ne.length===0)return{kind:"raw",title:c("updateDialog.changelog.title"),content:bn(z)};const W=[...ne].sort((de,_)=>ii(de.version,_.version));return{kind:"sections",title:c("updateDialog.changelog.title"),sections:W.map(de=>({version:de.version,dateLabel:oi(de.date),content:bn(ai(de.raw)||z)}))}},[n?.body,c]);return t.jsx(Zt,{open:s,onOpenChange:L?void 0:e,children:t.jsxs(es,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[t.jsxs("div",{className:"flex items-center mb-1",children:[t.jsxs(ts,{className:"flex items-center gap-2.5",children:[t.jsx(C,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),t.jsx("span",{className:"text-lg font-semibold text-foreground",children:c(x==="restarting"||x==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&t.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&t.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&t.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&t.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),t.jsxs("div",{className:"space-y-2",children:[G&&L&&t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(C,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),t.jsxs("div",{className:"typography-ui-label text-foreground",children:[x==="updating"&&c("updateDialog.status.installingUpdate"),x==="restarting"&&c("updateDialog.status.serverRestarting"),x==="reconnecting"&&c("updateDialog.status.waitingForServer")]})]}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:c("updateDialog.status.autoReloadHint")})]}),V&&!L&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(Rr,{className:"max-h-[400px] p-0",fillContainer:!1,children:V.kind==="raw"?t.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:z=>{const W=z.target.closest("a");W&&W.href&&(z.preventDefault(),z.stopPropagation(),F(W.href))},children:t.jsx(Js,{content:V.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:V.sections.map(z=>t.jsxs("div",{className:"p-4",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",z.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:z.dateLabel})]}),t.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:ne=>{const de=ne.target.closest("a");de&&de.href&&(ne.preventDefault(),ne.stopPropagation(),F(de.href))},children:t.jsx(Js,{content:z.content,disableLinkSafety:!0,enableFileReferences:!1})})]},z.version))})})}),G&&x==="error"&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx(C,{name:"terminal",className:"h-4 w-4"}),t.jsx("span",{children:c("updateDialog.fallback.updateViaTerminal")})]}),t.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[t.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:k}),t.jsx("button",{onClick:I,className:q("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",g&&"text-[var(--status-success)]"),title:c(g?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:g?t.jsx(C,{name:"check",className:"h-4 w-4"}):t.jsx(C,{name:"clipboard",className:"h-4 w-4"})})]})]}),!G&&!w&&r&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:c("updateDialog.status.downloadingPayload")}),t.jsxs("span",{className:"font-mono text-foreground",children:[M,"%"]})]}),t.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${M}%`}})})]}),(i||y)&&t.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:t.jsx("p",{className:"text-sm text-[var(--status-error)]",children:i||y})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:T,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[t.jsx(C,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!G&&!w&&!o&&!r&&t.jsxs("button",{onClick:u,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(C,{name:"download",className:"h-4 w-4"}),c("updateDialog.actions.downloadUpdate")]}),!G&&!w&&r&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(C,{name:"loader",className:"h-4 w-4 animate-spin"}),c("updateDialog.status.downloading")]}),!G&&!w&&o&&t.jsxs("button",{onClick:f,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[t.jsx(C,{name:"restart",className:"h-4 w-4"}),c("updateDialog.actions.restartToUpdate")]}),w&&t.jsxs(Ne,{onClick:te,size:"default",children:[t.jsx(C,{name:"external-link",className:"h-4 w-4"}),c("updateDialog.actions.openMobileUpdate")]}),G&&!L&&t.jsxs("button",{onClick:re,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(C,{name:"download",className:"h-4 w-4"}),c("updateDialog.actions.updateNow")]}),G&&L&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(C,{name:"loader",className:"h-4 w-4 animate-spin"}),c("updateDialog.status.updating")]})]})]})]})})},sd=s=>!(s.dismissed==="true"||s.sessionShown==="true"||s.hasActiveToast),fi=s=>!(!s.version||s.seenVersions.has(s.version)||s.dismissedVersion!==null&&s.dismissedVersion===s.version),hi=s=>{if(s===null||typeof s!="object")return"";const e=s.version;return typeof e!="string"?"":e.trim()},pi=s=>!s||s.upgrade?.supported!==!0||s.available!==!0||typeof s.latestVersion!="string"?"":s.latestVersion.trim(),Ut="opencode-update-available",ls="opencode-upgrade-progress",gi=5e3,xi=[1e4,6e4],wn="opencode-update-toast-dismissed-version",nd=()=>{const{t:s}=rt(),e=Ae(i=>i.showOpenCodeUpdateNotifications),n=J.useRef(new Set),r=J.useRef(!1);J.useEffect(()=>{e||ve.dismiss(Ut)},[e]);const o=J.useCallback(()=>{ve.dismiss(ls),Br({message:s("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]}).catch(()=>{})},[s]),a=J.useCallback(async()=>{if(!r.current){r.current=!0,ve.dismiss(Ut),ve.message(s("opencodeUpdate.toast.upgrading.title"),{id:ls,description:s("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:t.jsx(C,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const i=await Nt("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),u=await i.json().catch(()=>null);if(!i.ok||u?.success===!1)throw new Error(u?.error||i.statusText||s("opencodeUpdate.toast.failed.description"));ve.success(s("opencodeUpdate.toast.updated.title"),{id:ls,description:u?.version?s("opencodeUpdate.toast.updated.descriptionWithVersion",{version:u.version}):s("opencodeUpdate.toast.updated.description"),duration:1/0,icon:t.jsx(C,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:s("opencodeUpdate.toast.actions.reload"),onClick:o}})}catch(i){ve.error(s("opencodeUpdate.toast.failed.title"),{id:ls,description:i instanceof Error?i.message:s("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[o,s]);return J.useEffect(()=>{const i=p=>{if(!Ae.getState().showOpenCodeUpdateNotifications){ve.dismiss(Ut);return}fi({version:p,dismissedVersion:un().getItem(wn),seenVersions:n.current})&&(n.current.add(p),ve.info(s("opencodeUpdate.toast.available.title"),{id:Ut,description:s("opencodeUpdate.toast.available.description",{version:p}),duration:1/0,action:{label:s("opencodeUpdate.toast.actions.update"),onClick:a},cancel:{label:s("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{un().setItem(wn,p),Jn({openCodeUpdateToastDismissedVersion:p}),ve.dismiss(Ut)}}}))};let u=!1;const f=[],h=async(p,x=ws())=>{try{const d=await Nt("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!d.ok)throw new Error(d.statusText||"OpenCode upgrade status check failed");const y=await d.json().catch(()=>null),j=pi(y);!u&&x===ws()&&j&&i(j)}catch{const d=xi[p];!u&&x===ws()&&d!==void 0&&f.push(setTimeout(()=>{h(p+1,x)},d))}},c=p=>{hi(p.detail)&&h(0)};e&&f.push(setTimeout(()=>{h(0)},gi));const g=xa(({runtimeKey:p})=>{n.current.clear(),ve.dismiss(Ut),Ae.getState().showOpenCodeUpdateNotifications&&h(0,p)});return window.addEventListener("openchamber:opencode-update-available",c),()=>{u=!0;for(const p of f)clearTimeout(p);g(),window.removeEventListener("openchamber:opencode-update-available",c)}},[a,e,s]),null},rd=()=>{const s=Ye.c(3),[e,n]=l.useState(bi),{isUpdating:r}=e;let o,a;if(s[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>Lr(n),a=[],s[0]=o,s[1]=a):(o=s[0],a=s[1]),l.useEffect(o,a),!r)return null;let i;return s[2]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:t.jsx(Fr,{width:80,height:80,isAnimated:!0})}),s[2]=i):i=s[2],i};function bi(){return Mr()}class yi extends l.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?t.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:t.jsxs(Or,{className:"w-full max-w-md",children:[t.jsx(Ur,{className:"text-center",children:t.jsxs(Wr,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(C,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(zr,{className:"space-y-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&t.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[t.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),t.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),t.jsx("div",{className:"flex gap-2",children:t.jsxs(Ne,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(C,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),t.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function wi(s){const e=Ye.c(22),{t:n}=rt();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let o;e[2]!==n?(o=n("chat.errorBoundary.description"),e[2]=n,e[3]=o):o=e[3];let a;e[4]!==n?(a=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=a):a=e[5];let i;e[6]!==n?(i=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=i):i=e[7];let u;e[8]!==n?(u=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=u):u=e[9];let f;e[10]!==n?(f=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=f):f=e[11];let h;e[12]!==r||e[13]!==o||e[14]!==a||e[15]!==i||e[16]!==u||e[17]!==f?(h={title:r,description:o,sessionLabel:a,detailsSummary:i,resetAction:u,persistentHint:f},e[12]=r,e[13]=o,e[14]=a,e[15]=i,e[16]=u,e[17]=f,e[18]=h):h=e[18];let c;return e[19]!==s||e[20]!==h?(c=t.jsx(yi,{...s,texts:h}),e[19]=s,e[20]=h,e[21]=c):c=e[21],c}const od=s=>{const e=Ye.c(7),{active:n,readOnly:r,initialAllowPromptingSubagentSessions:o}=s,a=n===void 0?!0:n,i=r===void 0?!1:r,f=nt(vi)||void 0;let h;e[0]!==a||e[1]!==o||e[2]!==i?(h=t.jsx($r,{active:a,readOnly:i,initialAllowPromptingSubagentSessions:o}),e[0]=a,e[1]=o,e[2]=i,e[3]=h):h=e[3];let c;return e[4]!==f||e[5]!==h?(c=t.jsx(wi,{sessionId:f,children:h}),e[4]=f,e[5]=h,e[6]=c):c=e[6],c};function vi(s){return s.currentSessionId}function ad(s){const e=Ye.c(4);let n;e[0]!==s?({...n}=s,e[0]=s,e[1]=n):n=e[1];let r;return e[2]!==n?(r=t.jsx(Da,{...n}),e[2]=n,e[3]=r):r=e[3],r}function id(s){const e=Ye.c(4);let n;e[0]!==s?({...n}=s,e[0]=s,e[1]=n):n=e[1];let r;return e[2]!==n?(r=t.jsx(Ea,{...n}),e[2]=n,e[3]=r):r=e[3],r}function ld(s){const e=Ye.c(20);let n,r,o,a,i;e[0]!==s?({className:r,positionerClassName:o,children:n,style:i,...a}=s,e[0]=s,e[1]=n,e[2]=r,e[3]=o,e[4]=a,e[5]=i):(n=e[1],r=e[2],o=e[3],a=e[4],i=e[5]);let u;e[6]!==o?(u=q("app-region-no-drag z-50",o),e[6]=o,e[7]=u):u=e[7];let f;e[8]!==i?(f={color:"var(--surface-elevated-foreground)",...i},e[8]=i,e[9]=f):f=e[9];let h;e[10]!==r?(h=q(Vr,r),e[10]=r,e[11]=h):h=e[11];let c;e[12]!==n||e[13]!==a||e[14]!==f||e[15]!==h?(c=t.jsx(Ra,{"data-slot":"dropdown-menu-content",style:f,className:h,...a,children:n}),e[12]=n,e[13]=a,e[14]=f,e[15]=h,e[16]=c):c=e[16];let g;return e[17]!==u||e[18]!==c?(g=t.jsx(Ma,{children:t.jsx(La,{className:u,children:c})}),e[17]=u,e[18]=c,e[19]=g):g=e[19],g}function cd(s){const e=Ye.c(8);let n,r;e[0]!==s?({className:n,...r}=s,e[0]=s,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=q(_r,n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=t.jsx(Aa,{className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}function dd(s){const e=Ye.c(8);let n,r;e[0]!==s?({className:n,...r}=s,e[0]=s,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=q(Gr,n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=t.jsx(Ba,{className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a}const ki=Oa,ji=s=>{const e=Ye.c(14);let n,r,o,a;e[0]!==s?({className:o,asChild:n,children:r,...a}=s,e[0]=s,e[1]=n,e[2]=r,e[3]=o,e[4]=a):(n=e[1],r=e[2],o=e[3],a=e[4]);let i;e[5]!==n||e[6]!==r?(i=n&&J.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=i):i=e[7];const u=i;let f;e[8]!==o?(f=q("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",o),e[8]=o,e[9]=f):f=e[9];let h;return e[10]!==a||e[11]!==u||e[12]!==f?(h=t.jsx(Fa,{className:f,...a,...u}),e[10]=a,e[11]=u,e[12]=f,e[13]=h):h=e[13],h},Ni=s=>{const e=Ye.c(8);let n,r;e[0]!==s?({className:n,...r}=s,e[0]=s,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let o;e[3]!==n?(o=q("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=o):o=e[4];let a;return e[5]!==r||e[6]!==o?(a=t.jsx(Ua,{className:o,...r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a},vn=s=>({providerID:s.providerID,modelID:s.modelID,variant:s.variant,agent:s.agent});function Si(s){const e=Ye.c(131),{t:n}=rt(),{open:r,onOpenChange:o,target:a,projectDirectory:i,submitting:u,allowRunAsGoal:f,onConfirm:h}=s,c=u===void 0?!1:u,g=f===void 0?!1:f;let p;e[0]!==g?(p=g&&!Yn(),e[0]=g,e[1]=p):p=e[1];const x=p,d=pt(Li),y=pt(Mi),j=Hr(Bi),T=pt(Ai),R=pt(Ri),M=pt(Ei),G=pt(Di),w=pt(Pi);let k;e[2]!==w||e[3]!==M||e[4]!==R||e[5]!==G?(k=()=>vn({providerID:R,modelID:M,variant:G,agent:w}),e[2]=w,e[3]=M,e[4]=R,e[5]=G,e[6]=k):k=e[6];const[I,F]=l.useState(k);let re,te;e[7]!==j||e[8]!==y||e[9]!==d||e[10]!==r||e[11]!==i?(re=()=>{r&&(d({directory:i,source:"todoSendDialog"}),y({directory:i}),j())},te=[r,d,y,j,i],e[7]=j,e[8]=y,e[9]=d,e[10]=r,e[11]=i,e[12]=re,e[13]=te):(re=e[12],te=e[13]),l.useEffect(re,te);let L,V;e[14]!==w||e[15]!==M||e[16]!==R||e[17]!==G||e[18]!==r?(L=()=>{r&&F(vn({providerID:R,modelID:M,variant:G,agent:w}))},V=[r,R,M,G,w],e[14]=w,e[15]=M,e[16]=R,e[17]=G,e[18]=r,e[19]=L,e[20]=V):(L=e[19],V=e[20]),l.useEffect(L,V);let z,ne;e[21]!==I.modelID||e[22]!==I.providerID||e[23]!==r||e[24]!==T?(z=()=>{if(!r||T.length===0)return;const m=T.find(xe=>xe.id===I.providerID)??T[0],v=Array.isArray(m?.models)?m.models:[],Z=v.some(xe=>xe.id===I.modelID),ye=v[0]?.id??"";m?.id===I.providerID&&Z||F(xe=>({...xe,providerID:m?.id??"",modelID:Z?xe.modelID:ye,variant:""}))},ne=[r,T,I.providerID,I.modelID],e[21]=I.modelID,e[22]=I.providerID,e[23]=r,e[24]=T,e[25]=z,e[26]=ne):(z=e[25],ne=e[26]),l.useEffect(z,ne);const W=Ti;let de;if(e[27]!==I.modelID||e[28]!==I.providerID||e[29]!==T){let m;e[31]!==I.providerID?(m=Z=>Z.id===I.providerID,e[31]=I.providerID,e[32]=m):m=e[32],de=T.find(m)?.models?.find(Z=>Z.id===I.modelID),e[27]=I.modelID,e[28]=I.providerID,e[29]=T,e[30]=de}else de=e[30];const _=de;let O;e[33]!==_?(O=_?.variants?Object.keys(_.variants):[],e[33]=_,e[34]=O):O=e[34];const E=O,A=E.length>0;let U,H;e[35]!==I.variant||e[36]!==A?(U=()=>{A||!I.variant||F(Ii)},H=[A,I.variant],e[35]=I.variant,e[36]=A,e[37]=U,e[38]=H):(U=e[37],H=e[38]),l.useEffect(U,H);let D;e[39]!==I.modelID||e[40]!==I.providerID?(D=I.providerID.trim().length>0&&I.modelID.trim().length>0,e[39]=I.modelID,e[40]=I.providerID,e[41]=D):D=e[41];const se=D;let ue;e[42]!==se||e[43]!==I||e[44]!==h||e[45]!==c?(ue=()=>{!se||c||h(I)},e[42]=se,e[43]=I,e[44]=h,e[45]=c,e[46]=ue):ue=e[46];const he=ue;let Ce,ke;e[47]!==he||e[48]!==r?(Ce=()=>{if(!r)return;const m=v=>{(v.metaKey||v.ctrlKey)&&v.key==="Enter"&&(v.preventDefault(),he())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},ke=[r,he],e[47]=he,e[48]=r,e[49]=Ce,e[50]=ke):(Ce=e[49],ke=e[50]),l.useEffect(Ce,ke);let Y;e[51]!==n||e[52]!==a?(Y=n(a==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[51]=n,e[52]=a,e[53]=Y):Y=e[53];const be=Y;let $;e[54]!==o||e[55]!==c?($=m=>{c||o(m)},e[54]=o,e[55]=c,e[56]=$):$=e[56];let le;e[57]!==be?(le=t.jsx(gs,{children:t.jsx(ts,{children:be})}),e[57]=be,e[58]=le):le=e[58];let K;e[59]!==n?(K=n("chat.modelControls.model"),e[59]=n,e[60]=K):K=e[60];let oe;e[61]!==K?(oe=t.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:K}),e[61]=K,e[62]=oe):oe=e[62];let ce;e[63]===Symbol.for("react.memo_cache_sentinel")?(ce=(m,v)=>{F(Z=>({...Z,providerID:m,modelID:v,variant:""}))},e[63]=ce):ce=e[63];let pe;e[64]!==I.modelID||e[65]!==I.providerID?(pe=t.jsx(Wn,{providerId:I.providerID,modelId:I.modelID,className:"max-w-[320px] justify-between",dropdownPortalToBody:!0,onChange:ce}),e[64]=I.modelID,e[65]=I.providerID,e[66]=pe):pe=e[66];let P;e[67]!==oe||e[68]!==pe?(P=t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[oe,pe]}),e[67]=oe,e[68]=pe,e[69]=P):P=e[69];let B;e[70]!==n?(B=n("sessions.scheduledTasks.editor.thinkingLevel.label"),e[70]=n,e[71]=B):B=e[71];let Q;e[72]!==B?(Q=t.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:B}),e[72]=B,e[73]=Q):Q=e[73];const me=!A;let ee;e[74]===Symbol.for("react.memo_cache_sentinel")?(ee=m=>F(v=>({...v,variant:m})),e[74]=ee):ee=e[74];let Se;e[75]!==I.variant||e[76]!==me||e[77]!==E?(Se=t.jsx(Kr,{value:I.variant,options:E,disabled:me,onChange:ee}),e[75]=I.variant,e[76]=me,e[77]=E,e[78]=Se):Se=e[78];let Te;e[79]!==Q||e[80]!==Se?(Te=t.jsxs("div",{className:"flex flex-col gap-1.5",children:[Q,Se]}),e[79]=Q,e[80]=Se,e[81]=Te):Te=e[81];let De;e[82]!==n?(De=n("sessions.scheduledTasks.editor.agent.label"),e[82]=n,e[83]=De):De=e[83];let Ue;e[84]!==De?(Ue=t.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:De}),e[84]=De,e[85]=Ue):Ue=e[85];let Ve;e[86]===Symbol.for("react.memo_cache_sentinel")?(Ve=m=>F(v=>({...v,agent:m})),e[86]=Ve):Ve=e[86];let Me;e[87]!==I.agent?(Me=t.jsx(qr,{agentName:I.agent,filter:W,dropdownPortalToBody:!0,onChange:Ve}),e[87]=I.agent,e[88]=Me):Me=e[88];let Ze;e[89]!==Ue||e[90]!==Me?(Ze=t.jsxs("div",{className:"flex flex-col gap-1.5",children:[Ue,Me]}),e[89]=Ue,e[90]=Me,e[91]=Ze):Ze=e[91];let Ee;e[92]!==P||e[93]!==Te||e[94]!==Ze?(Ee=t.jsxs("div",{className:"flex flex-col gap-4",children:[P,Te,Ze]}),e[92]=P,e[93]=Te,e[94]=Ze,e[95]=Ee):Ee=e[95];const Ge=`flex items-center gap-3 ${x?"justify-between":"justify-end"}`;let Le;e[96]!==I.runAsGoal||e[97]!==x||e[98]!==c||e[99]!==n?(Le=x?t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(ss,{checked:I.runAsGoal===!0,onChange:m=>F(v=>({...v,runAsGoal:m})),disabled:c,ariaLabel:n("sessions.scheduledTasks.editor.goal.aria")}),t.jsx("button",{type:"button",className:"truncate typography-ui-label text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c,onClick:()=>F(Ci),children:n("sessions.scheduledTasks.editor.goal.label")})]}):null,e[96]=I.runAsGoal,e[97]=x,e[98]=c,e[99]=n,e[100]=Le):Le=e[100];let $e;e[101]!==o?($e=()=>o(!1),e[101]=o,e[102]=$e):$e=e[102];let Je;e[103]!==n?(Je=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[103]=n,e[104]=Je):Je=e[104];let Be;e[105]!==c||e[106]!==$e||e[107]!==Je?(Be=t.jsx(Ne,{variant:"ghost",size:"sm",onClick:$e,disabled:c,children:Je}),e[105]=c,e[106]=$e,e[107]=Je,e[108]=Be):Be=e[108];const Qe=!se||c;let He;e[109]!==c||e[110]!==n?(He=n(c?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[109]=c,e[110]=n,e[111]=He):He=e[111];let Pe;e[112]!==he||e[113]!==Qe||e[114]!==He?(Pe=t.jsx(Ne,{size:"sm",onClick:he,disabled:Qe,children:He}),e[112]=he,e[113]=Qe,e[114]=He,e[115]=Pe):Pe=e[115];let et;e[116]!==Be||e[117]!==Pe?(et=t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[Be,Pe]}),e[116]=Be,e[117]=Pe,e[118]=et):et=e[118];let ze;e[119]!==Ge||e[120]!==Le||e[121]!==et?(ze=t.jsxs("div",{className:Ge,children:[Le,et]}),e[119]=Ge,e[120]=Le,e[121]=et,e[122]=ze):ze=e[122];let b;e[123]!==le||e[124]!==Ee||e[125]!==ze?(b=t.jsxs(es,{className:"max-w-md overflow-visible",children:[le,Ee,ze]}),e[123]=le,e[124]=Ee,e[125]=ze,e[126]=b):b=e[126];let X;return e[127]!==r||e[128]!==$||e[129]!==b?(X=t.jsx(Zt,{open:r,onOpenChange:$,children:b}),e[127]=r,e[128]=$,e[129]=b,e[130]=X):X=e[130],X}function Ci(s){return{...s,runAsGoal:s.runAsGoal!==!0}}function Ii(s){return{...s,variant:""}}function Ti(s){return Yr(s.mode)}function Pi(s){return s.currentAgentName||""}function Di(s){return s.currentVariant||""}function Ei(s){return s.currentModelId}function Ri(s){return s.currentProviderId}function Ai(s){return s.providers}function Bi(s){return s.loadAgents}function Mi(s){return s.loadAgents}function Li(s){return s.loadProviders}const Fi=280,kn=4,Oi=({transform:s})=>({...s,y:0}),Ui=s=>{const e=Ye.c(18),{id:n,children:r,className:o}=s;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:i,listeners:u,setNodeRef:f,transform:h,transition:c,isDragging:g}=ir(a);let p;e[2]!==h?(p=cr.Transform.toString(h),e[2]=h,e[3]=p):p=e[3];let x;e[4]!==p||e[5]!==c?(x={transform:p,transition:c},e[4]=p,e[5]=c,e[6]=x):x=e[6];const d=g&&"opacity-50";let y;e[7]!==o||e[8]!==d?(y=q("h-full rounded-md",o,d),e[7]=o,e[8]=d,e[9]=y):y=e[9];let j;return e[10]!==i||e[11]!==r||e[12]!==n||e[13]!==u||e[14]!==f||e[15]!==x||e[16]!==y?(j=t.jsx("div",{ref:f,"data-sortable-tab-id":n,style:x,className:y,...i,...u,children:r}),e[10]=i,e[11]=r,e[12]=n,e[13]=u,e[14]=f,e[15]=x,e[16]=y,e[17]=j):j=e[17],j},Wi=s=>{const e=Ye.c(6),{id:n,children:r,className:o}=s;let a;e[0]!==o?(a=q("h-full",o),e[0]=o,e[1]=a):a=e[1];let i;return e[2]!==r||e[3]!==n||e[4]!==a?(i=t.jsx("div",{className:a,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=a,e[5]=i):i=e[5],i},Qt=s=>{const e=Ye.c(133),{items:n,activeId:r,onSelect:o,onClose:a,onReorder:i,layoutMode:u,variant:f,activePillInsetClassName:h,activePillButtonClassName:c,inactiveTabsIconOnly:g,animateActivePill:p,activePillLowercase:x,nonCompositedIndicator:d,className:y}=s,j=u===void 0?"scrollable":u,T=f===void 0?"default":f,R=g===void 0?!1:g,M=x===void 0?!0:x,G=d===void 0?!1:d,{t:w}=rt(),k=Ae(zi),{isTablet:I}=xs(),F=k||I,re=l.useRef(null);let te;e[0]===Symbol.for("react.memo_cache_sentinel")?(te={left:!1,right:!1},e[0]=te):te=e[0];const[L,V]=l.useState(te);let z;e[1]!==n?(z=n.map($i),e[1]=n,e[2]=z):z=e[2];const ne=z,W=j==="scrollable",de=T==="default",_=T==="active-pill",E=_||T==="animated",A=de,U=E||A,H=_&&W,D=E,se=p??E,ue=typeof i=="function",he=ue?Ui:Wi;let Ce;e[3]===Symbol.for("react.memo_cache_sentinel")?(Ce=new Map,e[3]=Ce):Ce=e[3];const ke=l.useRef(Ce),[Y,be]=l.useState(null),[$,le]=l.useState(!1),[K,oe]=l.useState(null),ce=l.useRef(!1),pe=l.useRef(0),P=l.useRef(r),B=l.useRef(null);let Q;e:{if(!U||!K||!r||K===r){Q=0;break e}const fe=n.findIndex(We=>We.id===K),ie=n.findIndex(We=>We.id===r);if(fe<0||ie<0){Q=0;break e}Q=fe>ie?kn:-kn}const me=Q;let ee;e[4]===Symbol.for("react.memo_cache_sentinel")?(ee={activationConstraint:{distance:8}},e[4]=ee):ee=e[4];const Se=sr(nr(rr,ee)),Te=Vi;let De;e[5]===Symbol.for("react.memo_cache_sentinel")?(De=(fe,ie)=>{if(ie){ke.current.set(fe,ie);return}ke.current.delete(fe)},e[5]=De):De=e[5];const Ue=De;let Ve;e[6]!==r||e[7]!==U?(Ve=()=>{if(!U||!r){be(_i);return}const fe=re.current,ie=ke.current.get(r);if(!fe||!ie){be(Gi);return}let We=0,it=0,ut=ie;for(;ut&&ut!==fe;)We=We+ut.offsetLeft,it=it+ut.offsetTop,ut=ut.offsetParent;const wt={left:We,top:it,width:ie.offsetWidth,height:ie.offsetHeight};be(Rt=>Te(Rt,wt)?Rt:wt)},e[6]=r,e[7]=U,e[8]=Ve):Ve=e[8];const Me=Ve;let Ze;e[9]!==W?(Ze=()=>{if(!W){V({left:!1,right:!1});return}const fe=re.current;if(!fe){V({left:!1,right:!1});return}V({left:fe.scrollLeft>2,right:fe.scrollLeft+fe.clientWidth<fe.scrollWidth-2})},e[9]=W,e[10]=Ze):Ze=e[10];const Ee=Ze;let Ge;e[11]!==W||e[12]!==Ee?(Ge=()=>{if(!W){V({left:!1,right:!1});return}const fe=re.current;if(!fe)return;Ee(),fe.addEventListener("scroll",Ee,{passive:!0});const ie=new ResizeObserver(Ee);return ie.observe(fe),()=>{fe.removeEventListener("scroll",Ee),ie.disconnect()}},e[11]=W,e[12]=Ee,e[13]=Ge):Ge=e[13];let Le;e[14]!==W||e[15]!==n.length||e[16]!==Ee?(Le=[W,n.length,Ee],e[14]=W,e[15]=n.length,e[16]=Ee,e[17]=Le):Le=e[17],l.useEffect(Ge,Le);let $e;e[18]!==r||e[19]!==Me||e[20]!==U?($e=()=>{if(!U){be(null);return}Me();const fe=re.current;if(!fe)return;const ie=new ResizeObserver(()=>{performance.now()-pe.current>Fi&&le(!1),Me()});if(ie.observe(fe),r){const We=ke.current.get(r);We&&ie.observe(We)}return()=>{ie.disconnect()}},e[18]=r,e[19]=Me,e[20]=U,e[21]=$e):$e=e[21];let Je;e[22]!==r||e[23]!==n.length||e[24]!==Me||e[25]!==U?(Je=[r,n.length,Me,U],e[22]=r,e[23]=n.length,e[24]=Me,e[25]=U,e[26]=Je):Je=e[26],l.useEffect($e,Je);let Be;e[27]!==Me?(Be=()=>{Me()},e[27]=Me,e[28]=Be):Be=e[28],l.useLayoutEffect(Be);let Qe;e[29]!==ne?(Qe=ne.join("\0"),e[29]=ne,e[30]=Qe):Qe=e[30];const He=Qe;let Pe,et;e[31]!==r||e[32]!==He||e[33]!==U?(Pe=()=>{if(!U){ce.current=!1,le(!1);return}const fe=B.current!==He;if(B.current=He,!ce.current){ce.current=!0,P.current=r;return}const ie=P.current!==r;if(P.current=r,!ie||fe){le(!1);return}pe.current=performance.now(),le(!0)},et=[r,He,U],e[31]=r,e[32]=He,e[33]=U,e[34]=Pe,e[35]=et):(Pe=e[34],et=e[35]),l.useLayoutEffect(Pe,et);let ze;e[36]!==r||e[37]!==W||e[38]!==Ee?(ze=()=>{if(!W||!r)return;const fe=re.current;if(!fe)return;const ie=window.requestAnimationFrame(()=>{const We=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),it=fe.querySelector(`[data-sortable-tab-id="${We}"]`);it&&(it.scrollIntoView({block:"nearest",inline:"nearest"}),Ee())});return()=>{window.cancelAnimationFrame(ie)}},e[36]=r,e[37]=W,e[38]=Ee,e[39]=ze):ze=e[39];let b;e[40]!==r||e[41]!==W||e[42]!==n.length||e[43]!==Ee?(b=[r,W,n.length,Ee],e[40]=r,e[41]=W,e[42]=n.length,e[43]=Ee,e[44]=b):b=e[44],l.useEffect(ze,b);let X;e[45]!==i?(X=fe=>{if(!i)return;const{active:ie,over:We}=fe;!We||ie.id===We.id||i(String(ie.id),String(We.id))},e[45]=i,e[46]=X):X=e[46];const m=X;let v;e[47]!==y?(v=q("relative flex h-full min-w-0 flex-1",y),e[47]=y,e[48]=v):v=e[48];let Z;e[49]!==W||e[50]!==L||e[51]!==E?(Z=W&&L.left?t.jsx("div",{className:q("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",E?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[49]=W,e[50]=L,e[51]=E,e[52]=Z):Z=e[52];let ye;e[53]!==W||e[54]!==L||e[55]!==E?(ye=W&&L.right?t.jsx("div",{className:q("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",E?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[53]=W,e[54]=L,e[55]=E,e[56]=ye):ye=e[56];const xe=E?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Oe=E&&"@container/pill-tabs",tt=E&&"pill-tabs__track",Ke=E&&(h??"gap-0.5 py-0.5"),Re=A&&"items-center overflow-y-hidden",N=D&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_4%,transparent)] p-0.5 gap-0.5",we=W?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Ie;e[57]!==xe||e[58]!==Oe||e[59]!==tt||e[60]!==Ke||e[61]!==Re||e[62]!==N||e[63]!==we?(Ie=q("relative flex h-full min-w-0 flex-1",xe,Oe,tt,Ke,Re,N,we),e[57]=xe,e[58]=Oe,e[59]=tt,e[60]=Ke,e[61]=Re,e[62]=N,e[63]=we,e[64]=Ie):Ie=e[64];let Fe;e[65]!==W?(Fe=W?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[65]=W,e[66]=Fe):Fe=e[66];let st;e[67]!==w?(st=w("sortableTabsStrip.aria.tabs"),e[67]=w,e[68]=st):st=e[68];let at;e[69]!==G||e[70]!==me||e[71]!==Y||e[72]!==$||e[73]!==se||e[74]!==E?(at=E&&Y?t.jsx("div",{className:q("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-[color-mix(in_srgb,var(--foreground)_7%,transparent)]","shadow-[0_1px_2px_color-mix(in_srgb,var(--foreground)_10%,transparent),0_2px_6px_color-mix(in_srgb,var(--foreground)_6%,transparent)]",se&&$&&(G?"pill-tabs__indicator--is-animated-layout":"pill-tabs__indicator--is-animated")),style:G?{left:`${Y.left+me}px`,top:`${Y.top}px`,width:`${Y.width}px`,height:`${Y.height}px`}:{transform:`translate3d(${Y.left+me}px, ${Y.top}px, 0)`,width:`${Y.width}px`,height:`${Y.height}px`}}):null,e[69]=G,e[70]=me,e[71]=Y,e[72]=$,e[73]=se,e[74]=E,e[75]=at):at=e[75];let ot;e[76]!==me||e[77]!==Y||e[78]!==$||e[79]!==A?(ot=A&&Y?t.jsx("div",{className:q("pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",$&&"underline-tabs__indicator--is-animated"),style:{transform:`translate3d(${Y.left+me}px, 0, 0)`,width:`${Y.width}px`},"aria-hidden":!0}):null,e[76]=me,e[77]=Y,e[78]=$,e[79]=A,e[80]=ot):ot=e[80];let dt;if(e[81]!==he||e[82]!==r||e[83]!==c||e[84]!==M||e[85]!==F||e[86]!==R||e[87]!==_||e[88]!==k||e[89]!==W||e[90]!==n||e[91]!==a||e[92]!==o||e[93]!==H||e[94]!==E||e[95]!==U){let fe;e[97]!==he||e[98]!==r||e[99]!==c||e[100]!==M||e[101]!==F||e[102]!==R||e[103]!==_||e[104]!==k||e[105]!==W||e[106]!==a||e[107]!==o||e[108]!==H||e[109]!==E||e[110]!==U?(fe=ie=>{const We=ie.id===r,it=R&&E&&!We&&!!ie.icon,ut=!it,wt=!!ie.icon,Rt=R&&E&&We&&!W&&!H,vt=ie.closable!==!1&&!!a,kt=vt&&!!ie.icon,Tt=W||H?void 0:E?Rt?"flex-none basis-auto":k?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",Ot=vt?mt=>{mt.button===1&&(mt.preventDefault(),mt.stopPropagation(),a?.(ie.id))}:void 0,rs=vt?Hi:void 0;return t.jsx(he,{id:ie.id,className:Tt,children:t.jsxs("div",{ref:mt=>Ue(ie.id,mt),onAuxClick:Ot,onMouseDown:rs,className:q("group flex h-full min-w-0 flex-nowrap items-center",W||H?"shrink-0":E?"w-full":"w-full min-w-0",E?"relative z-10 bg-transparent":We?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[t.jsx("button",{type:"button",role:"tab","aria-selected":We,"aria-label":it?ie.title??ie.label:void 0,onClick:()=>o(ie.id),onPointerDown:U?()=>{le(!0),oe(ie.id)}:void 0,onPointerUp:U?()=>oe(null):void 0,onPointerLeave:U?()=>oe(null):void 0,onPointerCancel:U?()=>oe(null):void 0,className:q(E?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",E&&M?"lowercase":null,E&&(it?"gap-0":"gap-1.5"),E?H?"shrink-0 whitespace-nowrap px-3 text-center":W?"max-w-56 shrink-0 px-3 text-center":it?"px-2 !min-w-0 text-center":Rt?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":W?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",E?c??(_?k?"h-[38px]":"h-[31px]":"h-7"):null,E?We?"text-foreground":"text-muted-foreground hover:text-foreground":null,E?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:ie.title??ie.label,children:E?t.jsxs(t.Fragment,{children:[wt?t.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[t.jsx("span",{className:q("flex items-center justify-center transition-opacity",kt&&(F?"opacity-0":"group-hover:opacity-0")),children:ie.icon}),kt?t.jsx("span",{role:"button",tabIndex:-1,className:q("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",F?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Ki,onClick:mt=>{mt.stopPropagation(),a?.(ie.id)},"aria-label":ie.closeLabel??`Close ${ie.label} tab`,title:ie.closeLabel??`Close ${ie.label} tab`,children:t.jsx(C,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,ut?t.jsx("span",{className:"animated-tabs__label truncate",children:ie.label}):null]}):t.jsxs("span",{className:q("flex min-w-0 flex-nowrap items-center gap-1.5",!W&&"justify-center"),children:[wt?t.jsxs("span",{className:q("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",We?"text-[var(--primary-base)]":"text-muted-foreground"),children:[t.jsx("span",{className:q("flex items-center justify-center transition-opacity",kt&&(F?"opacity-0":"group-hover:opacity-0")),children:ie.icon}),kt?t.jsx("span",{role:"button",tabIndex:-1,className:q("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",F?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:qi,onClick:mt=>{mt.stopPropagation(),a?.(ie.id)},"aria-label":ie.closeLabel??`Close ${ie.label} tab`,title:ie.closeLabel??`Close ${ie.label} tab`,children:t.jsx(C,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,t.jsx("span",{className:"truncate leading-[1.2]",children:ie.label})]})}),vt&&!kt?t.jsx("button",{type:"button",onPointerDown:Yi,onClick:mt=>{mt.stopPropagation(),a?.(ie.id)},className:q("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",E?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",E?We?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":We?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":ie.closeLabel??`Close ${ie.label} tab`,title:ie.closeLabel??`Close ${ie.label} tab`,children:t.jsx(C,{name:"close",className:"h-3 w-3"})}):null]})},ie.id)},e[97]=he,e[98]=r,e[99]=c,e[100]=M,e[101]=F,e[102]=R,e[103]=_,e[104]=k,e[105]=W,e[106]=a,e[107]=o,e[108]=H,e[109]=E,e[110]=U,e[111]=fe):fe=e[111],dt=n.map(fe),e[81]=he,e[82]=r,e[83]=c,e[84]=M,e[85]=F,e[86]=R,e[87]=_,e[88]=k,e[89]=W,e[90]=n,e[91]=a,e[92]=o,e[93]=H,e[94]=E,e[95]=U,e[96]=dt}else dt=e[96];let _e;e[112]!==Ie||e[113]!==Fe||e[114]!==st||e[115]!==at||e[116]!==ot||e[117]!==dt?(_e=t.jsxs("div",{ref:re,className:Ie,style:Fe,role:"tablist","aria-label":st,children:[at,ot,dt]}),e[112]=Ie,e[113]=Fe,e[114]=st,e[115]=at,e[116]=ot,e[117]=dt,e[118]=_e):_e=e[118];let ft;e[119]!==v||e[120]!==Z||e[121]!==ye||e[122]!==_e?(ft=t.jsxs("div",{className:v,children:[Z,ye,_e]}),e[119]=v,e[120]=Z,e[121]=ye,e[122]=_e,e[123]=ft):ft=e[123];const S=ft;if(!ue)return S;let ae;e[124]===Symbol.for("react.memo_cache_sentinel")?(ae=[Oi],e[124]=ae):ae=e[124];let ge;e[125]!==ne||e[126]!==S?(ge=t.jsx(lr,{items:ne,strategy:$a,children:S}),e[125]=ne,e[126]=S,e[127]=ge):ge=e[127];let qe;e[128]===Symbol.for("react.memo_cache_sentinel")?(qe=t.jsx(za,{dropAnimation:null}),e[128]=qe):qe=e[128];let je;return e[129]!==m||e[130]!==Se||e[131]!==ge?(je=t.jsxs(or,{sensors:Se,collisionDetection:ar,onDragEnd:m,modifiers:ae,children:[ge,qe]}),e[129]=m,e[130]=Se,e[131]=ge,e[132]=je):je=e[132],je};function zi(s){return s.isMobile}function $i(s){return s.id}function Vi(s,e){return!s||!e?s===e:Math.abs(s.left-e.left)<.5&&Math.abs(s.top-e.top)<.5&&Math.abs(s.width-e.width)<.5&&Math.abs(s.height-e.height)<.5}function _i(s){return s===null?s:null}function Gi(s){return s===null?s:null}function Hi(s){s.button===1&&s.preventDefault()}function Ki(s){s.stopPropagation()}function qi(s){s.stopPropagation()}function Yi(s){s.stopPropagation()}const Bt=bs()(Zn(er((s,e)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{s({selectedProfileId:n})},loadProfiles:async()=>{s({isLoading:!0});const n=e().profiles;try{const r=await to();return s({profiles:r,isLoading:!1}),!0}catch(r){return console.error("Failed to load git identity profiles:",r),s({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{const n=await eo();if(n&&n.userName&&n.userEmail){const r={id:"global",name:"Global Identity",userName:n.userName,userEmail:n.userEmail,authType:n.sshCommand?"ssh":void 0,sshKey:n.sshCommand?n.sshCommand.replace("ssh -i ",""):null,color:"info",icon:"fingerprint"};s({globalIdentity:r})}else s({globalIdentity:null});return!0}catch(n){return console.error("Failed to load global git identity:",n),s({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{const n=await Zr();return s({discoveredCredentials:n}),!0}catch(n){return console.error("Failed to discover git credentials:",n),s({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=r=>{if(typeof r!="string")return null;const o=r.trim();return o.length>0?o:null};try{let r=null;if(r===null){const o=ya()?.settings;if(o)try{const i=(await o.load())?.settings||{};r=n(i.defaultGitIdentityId)}catch{}}if(r===null)try{const o=await Nt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(o.ok){const a=await o.json().catch(()=>null);r=n(a?.defaultGitIdentityId)}}catch{}return s({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",o=r.length>0?r:"";return await Jn({defaultGitIdentityId:o}),s({defaultGitIdentityId:o.length>0?o:null}),!0}catch(r){return console.error("Failed to save default git identity setting:",r),!1}},createProfile:async n=>{try{const r={...n,id:n.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:n.color||"keyword",icon:n.icon||"branch"};return St("saving"),await Xr(r),St("saved"),await e().loadProfiles(),!0}catch(r){return St("error"),console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const o=e().profiles.find(i=>i.id===n);if(!o)throw new Error("Profile not found");const a={...o,...r};return St("saving"),await Qr(n,a),St("saved"),await e().loadProfiles(),!0}catch(o){return St("error"),console.error("Failed to update git identity profile:",o),!1}},deleteProfile:async n=>{try{return St("saving"),await Jr(n),St("saved"),e().selectedProfileId===n&&s({selectedProfileId:null}),await e().loadProfiles(),!0}catch(r){return St("error"),console.error("Failed to delete git identity profile:",r),!1}},getProfileById:n=>{const{profiles:r,globalIdentity:o}=e();return n==="global"?o||void 0:r.find(a=>a.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:r}=e();return r.filter(o=>!n.some(a=>a.authType==="token"&&a.host===o.host))}}),{name:"git-identities-store",storage:ba(),partialize:s=>({selectedProfileId:s.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Bt);const Xt=so,It=s=>{const e=Ye.c(11),{title:n,description:r,info:o,settingsItem:a,titleAccessory:i,headerAction:u,children:f,className:h,contentClassName:c,divider:g}=s,p=g===void 0?!0:g;let x;return e[0]!==f||e[1]!==h||e[2]!==c||e[3]!==r||e[4]!==p||e[5]!==u||e[6]!==o||e[7]!==a||e[8]!==n||e[9]!==i?(x=t.jsx(no,{title:n,description:r,info:o,settingsItem:a,titleAccessory:i,headerAction:u,divider:p,className:h,contentClassName:c,children:f}),e[0]=f,e[1]=h,e[2]=c,e[3]=r,e[4]=p,e[5]=u,e[6]=o,e[7]=a,e[8]=n,e[9]=i,e[10]=x):x=e[10],x},Ji=450,Qi=({projectRef:s=null,sections:e="all"})=>{const{t:n}=rt(),{isMobile:r,isTablet:o}=xs(),a=r||o,i=gt(D=>D.getActiveProject()),u=s?.path??i?.path??null,f=nt(D=>D.getWorktreeMetadata),h=ro(),c=ns(D=>D.homeDirectory),[g,p]=l.useState([]),[x,d]=l.useState(!1),[y,j]=l.useState(!1),[T,R]=l.useState(null),[M,G]=l.useState(null),[w,k]=l.useState([]),[I,F]=l.useState(!1),re=l.useRef(!1),te=l.useMemo(()=>s?.id&&s?.path?{id:s.id,path:s.path}:!i?.id||!u?null:{id:i.id,path:u},[i?.id,u,s?.id,s?.path]),L=l.useCallback(async()=>{if(!(!te||M===!1))try{const D=await Qs(te);k(D)}catch{}},[te,M]);l.useEffect(()=>{if(!u)return;let D=!1;return G(null),(async()=>{try{const se=await oo(u);if(D)return;G(se)}catch{}})(),()=>{D=!0}},[u]),l.useEffect(()=>{if(!te){k([]),F(!1);return}if(M===!1){k([]),F(!1);return}let D=!1;return F(!0),k([]),(async()=>{try{const se=await Qs(te);if(D)return;k(se)}catch{}finally{D||F(!1)}})(),()=>{D=!0}},[te,M]),l.useEffect(()=>{if(!te)return;let D=!1;return j(!0),(async()=>{try{const[se,ue]=await Promise.all([zn(te),$n(te)]);if(!D){const he=se.length>0?se:[""];p(he),R(JSON.stringify(he)),d(ue)}}catch{D||(p([""]),R(JSON.stringify([""])),d(!1))}finally{D||j(!1)}})(),()=>{D=!0}},[te]);const V=l.useCallback(async D=>{if(!te)return!1;const se=D.filter(ue=>ue.trim().length>0);try{return await ao(te,se)?(R(JSON.stringify(D)),!0):(ve.error(n("settings.openchamber.worktrees.setup.toast.saveFailed")),!1)}catch{return ve.error(n("settings.openchamber.worktrees.setup.toast.saveFailed")),!1}},[te,n]),z=l.useMemo(()=>T===null?!1:T!==JSON.stringify(g),[T,g]);l.useEffect(()=>{if(!z||y||re.current)return;const D=window.setTimeout(()=>{re.current||(re.current=!0,(async()=>{try{await V(g)}finally{re.current=!1}})())},Ji);return()=>{window.clearTimeout(D)}},[z,y,V,g]);const ne=l.useCallback((D,se)=>{p(ue=>{const he=[...ue];return he[D]=se,he})},[]),W=l.useCallback(()=>{p(D=>[...D,""])},[]),de=l.useCallback(D=>{p(se=>{const ue=se.filter((he,Ce)=>Ce!==D);return ue.length>0?ue:[""]})},[]),_=l.useCallback(()=>{!z||re.current||(re.current=!0,(async()=>{try{await V(g)}finally{re.current=!1}})())},[z,V,g]),O=l.useCallback(D=>{d(D),te&&io(te,D)},[te]),E=l.useCallback(D=>{const se=K=>K.replace(/\\/g,"/").replace(/\/+$/,""),ue=se(D.path),he=h.filter(K=>{const oe=f(K.id);if(oe?.path&&se(oe.path)===ue)return!0;const ce=K.directory;return!!(ce&&se(ce)===ue)}),Ce=new Set(he.map(K=>K.id)),ke=[...As.getState().activeSessions,...As.getState().archivedSessions],Y=K=>{const oe=ke.filter(pe=>{const P=pe.parentID;return P&&K.has(P)});if(oe.length===0)return[];const ce=new Set(oe.map(pe=>pe.id));return[...oe,...Y(ce)]},be=Y(Ce),$=new Set,le=[...he,...be].filter(K=>$.has(K.id)?!1:($.add(K.id),!0));lo.requestDelete({sessions:le,mode:"worktree",worktree:D})},[h,f]),A=l.useMemo(()=>h.map(D=>D.id).join(","),[h]);l.useEffect(()=>{M&&u&&L()},[A,M,u,L]);const U=t.jsxs(Bs,{children:[n("settings.openchamber.worktrees.setup.tooltipPrefix")," ",t.jsx("code",{className:"font-mono text-xs bg-sidebar-accent/50 px-1 rounded",children:"$ROOT_PROJECT_PATH"})," ",n("settings.openchamber.worktrees.setup.tooltipSuffix")]}),H=t.jsx(Bs,{children:n("settings.openchamber.worktrees.list.tooltip")});return u?M===!1?t.jsx(It,{title:n("settings.projects.page.section.worktree"),settingsItem:"projects.worktree",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.openchamber.worktrees.state.gitOnly")})}):t.jsxs(t.Fragment,{children:[e==="all"?t.jsx(It,{title:n("settings.projects.page.section.worktree"),settingsItem:"projects.worktree",titleAccessory:U,children:y?t.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.openchamber.worktrees.setup.loading")}):t.jsxs("div",{className:q("space-y-2",Xt),children:[g.map((D,se)=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(ht,{value:D,onChange:ue=>ne(se,ue.target.value),onBlur:_,placeholder:n("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 min-w-0 flex-1 font-mono text-xs"}),t.jsx(Ne,{type:"button",variant:"ghost",size:"icon",onClick:()=>de(se),className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive","aria-label":n("settings.openchamber.worktrees.setup.removeCommandAria"),children:t.jsx(C,{name:"close",className:"h-4 w-4"})})]},se)),t.jsxs(Ne,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:W,children:[t.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),n("settings.openchamber.worktrees.setup.addCommand")]}),t.jsxs("label",{"data-settings-item":"projects.worktree.setup.wait",className:"flex cursor-pointer items-center gap-2 py-1",children:[t.jsx(ss,{checked:x,onChange:O,ariaLabel:n("settings.openchamber.worktrees.setup.waitForCommandsAria")}),t.jsx("span",{className:q("typography-ui-label font-normal",x?"text-foreground":"text-foreground/60"),children:n("settings.openchamber.worktrees.setup.waitForCommands")})]})]})}):null,t.jsx(It,{title:n("settings.openchamber.worktrees.list.title"),titleAccessory:H,children:I?t.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.openchamber.worktrees.list.loading")}):w.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:n("settings.openchamber.worktrees.list.empty")}):t.jsx("div",{className:q("space-y-1",e==="all"&&Xt),children:w.map(D=>t.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"flex min-w-0 items-center gap-2",children:t.jsx("p",{className:"typography-meta min-w-0 truncate text-foreground",children:D.label||D.branch||n("settings.openchamber.worktrees.list.detachedHead")})}),t.jsx("p",{className:"typography-micro truncate text-muted-foreground/60",children:co(D.path,c)})]}),t.jsx("button",{type:"button",onClick:()=>E(D),className:q("flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground/50 transition-opacity hover:bg-destructive/10 hover:text-destructive focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",a?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":n("settings.openchamber.worktrees.list.deleteWorktreeAria",{name:D.branch||D.label||D.path}),children:t.jsx(C,{name:"delete-bin",className:"h-4 w-4"})})]},D.path))})})]}):t.jsx(It,{title:n("settings.projects.page.section.worktree"),settingsItem:"projects.worktree",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.openchamber.worktrees.state.selectProject")})})},jn=(s,e)=>e.updatedAtMs-s.updatedAtMs,Nn=bs((s,e)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!e().isLoading){s({isLoading:!0,error:null});try{const[n,r]=await Promise.all([ho(),Zs()]),o={};for(const a of r.sort(jn))o[a.id]=a;e().listenerReady||await po(a=>{s(i=>({statusesById:{...i.statusesById,[a.id]:a}}))}),s({instances:n.instances,statusesById:o,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){s({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){s({isImportsLoading:!0,error:null});try{const n=await fo();s({importCandidates:n,isImportsLoading:!1})}catch(n){s({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await Zs(),r={};for(const o of n.sort(jn))r[o.id]=o;s({statusesById:r})}catch(n){s({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{s({isSaving:!0,error:null});try{await mo({instances:n}),s({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(r){throw s({isSaving:!1,error:r instanceof Error?r.message:String(r)}),r}},upsertInstance:async n=>{const r=e().instances,o=r.some(a=>a.id===n.id)?r.map(a=>a.id===n.id?n:a):[n,...r];await e().setInstances(o)},createFromCommand:async(n,r,o)=>{const a=go(n,r);o&&o.trim()&&(a.nickname=o.trim()),await e().upsertInstance(a)},removeInstance:async n=>{await Xs(n).catch(()=>{});const r=e().instances.filter(o=>o.id!==n);await e().setInstances(r),s(o=>{const a={...o.statusesById};return delete a[n],{statusesById:a}})},connect:async n=>{s({error:null});try{await uo(n),await e().refreshStatuses()}catch(r){throw s({error:r instanceof Error?r.message:String(r)}),r}},disconnect:async n=>{s({error:null});try{await Xs(n),await e().refreshStatuses()}catch(r){throw s({error:r instanceof Error?r.message:String(r)}),r}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>s({error:null})})),fr=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],hr=Object.fromEntries(fr.map(s=>[s.key,s.Icon])),Xi="openchamber:project-actions-updated",Zi=s=>{const e=(s||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},ud=(s,e)=>`${Zi(s)}::${e}`,el=s=>{const e=s.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Sn=s=>{if(typeof s!="number"||!Number.isFinite(s))return null;const e=Math.round(s);return e<1||e>65535?null:e},tl=(s,e)=>{if(!e.enabled||e.type!=="local")return null;const n=Sn(e.localPort),r=Sn(e.remotePort);if(!n||!r)return null;const o=el(e.localHost||s.localForward.bindHost||"127.0.0.1"),a=(e.remoteHost||"127.0.0.1").trim(),i=(s.nickname||s.id||"instance").trim();return{id:`${s.id}::${e.id}`,label:`${i} - ${o}:${n} -> ${a}:${r}`,url:`http://${o}:${n}`}},pr=s=>{const e=[];for(const n of s)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const o=tl(n,r);o&&e.push(o)}return e},md=(s,e)=>{const n=(s||"").trim();return n&&pr(e).find(a=>a.id===n)?.url||null},sl=450,nl=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,rl=()=>({id:nl(),name:"",command:"",icon:"play"}),ol=({projectRef:s})=>{const{t:e}=rt(),n=l.useMemo(()=>Qn(),[]),r=Nn(k=>k.instances),o=Nn(k=>k.load),[a,i]=l.useState([]),[u,f]=l.useState(!1),[h,c]=l.useState(null),[g,p]=l.useState({}),x=l.useRef(!1),d=l.useRef(null);l.useEffect(()=>{n&&o().catch(()=>{})},[n,o]),l.useEffect(()=>{let k=!1;return f(!0),(async()=>{try{const I=await xo(s);if(k)return;i(I.actions),c(JSON.stringify({actions:I.actions}))}catch{if(k)return;i([]),c(JSON.stringify({actions:[]}))}finally{k||f(!1)}})(),()=>{k=!0}},[s]);const y=l.useMemo(()=>n?pr(r):[],[r,n]),j=l.useMemo(()=>a.some(I=>I.name.trim().length===0||I.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[a,e]),T=l.useMemo(()=>h===null?!1:h!==JSON.stringify({actions:a}),[a,h]),R=l.useCallback(async k=>await bo(s,{actions:k,primaryActionId:null})?(c(JSON.stringify({actions:k})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Xi,{detail:{projectId:s.id}})),!0):(ve.error(e("settings.projects.actions.toast.saveFailed")),!1),[s,e]);l.useEffect(()=>{if(!T||u||j||x.current)return;const k=window.setTimeout(()=>{x.current||(x.current=!0,(async()=>{try{await R(a)}finally{x.current=!1}})())},sl);return()=>{window.clearTimeout(k)}},[a,T,u,R,j]),l.useEffect(()=>{if(!T||!j||u){j||(d.current=null);return}const k=window.setTimeout(()=>{d.current!==j&&(d.current=j,ve.error(j))},1e3);return()=>{window.clearTimeout(k)}},[T,u,j]);const M=l.useCallback(()=>{const k=rl();i(I=>[...I,k]),p(I=>({...I,[k.id]:!0}))},[]),G=l.useCallback(k=>{i(I=>I.filter(F=>F.id!==k)),p(I=>{const F={...I};return delete F[k],F})},[]),w=l.useCallback((k,I)=>{i(F=>F.map(re=>re.id===k?I(re):re))},[]);return t.jsxs(It,{title:e("settings.projects.actions.title"),info:e("settings.projects.actions.description"),settingsItem:"projects.actions",headerAction:t.jsxs(Ne,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:M,children:[t.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]}),contentClassName:"space-y-0",children:[u?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):a.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")}):t.jsx("div",{className:q("space-y-0",Xt),children:a.map(k=>{const I=k.icon||"play",F=hr[I]||"play",re=g[k.id]??!1,te=k.name.trim()||e("settings.projects.actions.state.untitled");return t.jsxs(ki,{open:re,onOpenChange:L=>{p(V=>({...V,[k.id]:L}))},className:"py-1.5",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs(ji,{className:"group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[re?t.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):t.jsx(C,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),t.jsx(C,{name:F,className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:te})})]}),t.jsx(Ne,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>G(k.id),children:t.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(Ni,{className:"pt-1.5",children:t.jsxs("div",{className:"space-y-2 pb-4 pl-3 pr-1",children:[t.jsxs("div",{className:"flex items-center gap-2 py-1",children:[t.jsxs(Pt,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":e("settings.projects.actions.field.selectIconAria"),children:t.jsx(C,{name:F,className:"h-4 w-4"})})}),t.jsx(Et,{align:"start",className:"w-56 p-2",children:t.jsx("div",{className:"grid grid-cols-6 gap-1",children:fr.map(L=>{const V=L.Icon,z=(k.icon||"play")===L.key;return t.jsx("button",{type:"button",onClick:()=>w(k.id,ne=>({...ne,icon:L.key})),className:q("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",z&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:L.label}),children:t.jsx(C,{name:V,className:"h-4 w-4"})},L.key)})})})]}),t.jsx(ht,{value:k.name,onChange:L=>w(k.id,V=>({...V,name:L.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 flex-1 min-w-0"})]}),t.jsxs("div",{className:"py-1",children:[t.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),t.jsx(Vn,{value:k.command,onChange:L=>w(k.id,V=>({...V,command:L.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] w-full font-mono text-xs"})]}),t.jsxs("div",{className:"py-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":k.autoOpenUrl===!0,onClick:()=>w(k.id,L=>({...L,...L.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),w(k.id,V=>({...V,...V.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[t.jsx(ss,{checked:k.autoOpenUrl===!0,onChange:L=>w(k.id,V=>({...V,...L?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:te})}),t.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),k.autoOpenUrl===!0?t.jsxs("div",{className:"mt-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ht,{value:k.openUrl||"",onChange:L=>w(k.id,V=>({...V,openUrl:L.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),t.jsx(Bs,{contentClassName:"max-w-xs",children:e("settings.projects.actions.field.overrideUrlTooltip")})]}),n?t.jsxs("div",{className:"mt-2",children:[t.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.desktopSshForward")}),y.length>0?t.jsxs(yo,{value:k.desktopOpenSshForward&&y.some(L=>L.id===k.desktopOpenSshForward)?k.desktopOpenSshForward:"__none__",onValueChange:L=>{w(k.id,V=>({...V,...L==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:L}}))},children:[t.jsx(wo,{size:vo,className:"w-full",children:t.jsx(ko,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),t.jsxs(jo,{children:[t.jsx(en,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),y.map(L=>t.jsx(en,{value:L.id,children:L.label},L.id))]})]}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},k.id)})}),j&&a.length>0?t.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:j}):null]})},al=s=>{const e=Ye.c(123),{form:n}=s,{t:r}=rt(),{currentTheme:o}=_n(),{name:a,setName:i,icon:u,setIcon:f,color:h,setColor:c,iconBackground:g,setIconBackground:p,parsedDefaultModel:x,handleDefaultModelChange:d,isUploadingIcon:y,isRemovingCustomIcon:j,isDiscoveringIcon:T,pendingRemoveImageIcon:R,setPendingRemoveImageIcon:M,pendingUploadIconPreviewUrl:G,setPreviewImageFailed:w,hasPendingUploadImageIcon:k,hasCustomIcon:I,effectiveHasImageIcon:F,hasRemovableImageIcon:re,showImagePreview:te,fileInputRef:L,handleUploadIcon:V,handleRemoveImageIcon:z,handleDiscoverIcon:ne,currentIconImage:W,project:de}=n;if(!de)return null;const _=h?No[h]??null:null;let O;e[0]!==r?(O=r("settings.projects.page.field.projectName"),e[0]=r,e[1]=O):O=e[1];let E;e[2]!==i?(E=b=>i(b.target.value),e[2]=i,e[3]=E):E=e[3];let A;e[4]!==r?(A=r("settings.projects.page.field.projectNamePlaceholder"),e[4]=r,e[5]=A):A=e[5];let U;e[6]===Symbol.for("react.memo_cache_sentinel")?(U=q("h-8 rounded-md px-3",Xt),e[6]=U):U=e[6];let H;e[7]!==a||e[8]!==E||e[9]!==A?(H=t.jsx(ht,{value:a,onChange:E,placeholder:A,className:U}),e[7]=a,e[8]=E,e[9]=A,e[10]=H):H=e[10];let D;e[11]!==O||e[12]!==H?(D=t.jsx(It,{title:O,settingsItem:"projects.name",divider:!1,children:H}),e[11]=O,e[12]=H,e[13]=D):D=e[13];let se;e[14]!==r?(se=r("settings.projects.page.field.defaultModel"),e[14]=r,e[15]=se):se=e[15];let ue;e[16]!==r?(ue=r("settings.projects.page.field.defaultModelDescription"),e[16]=r,e[17]=ue):ue=e[17];const he=x.providerId,Ce=x.modelId;let ke;e[18]===Symbol.for("react.memo_cache_sentinel")?(ke=q("h-8 min-h-8 rounded-md px-3 max-w-48",Xt),e[18]=ke):ke=e[18];let Y;e[19]!==d||e[20]!==x.modelId||e[21]!==x.providerId?(Y=t.jsx(Wn,{providerId:he,modelId:Ce,onChange:d,className:ke}),e[19]=d,e[20]=x.modelId,e[21]=x.providerId,e[22]=Y):Y=e[22];let be;e[23]!==Y||e[24]!==se||e[25]!==ue?(be=t.jsx(It,{title:se,info:ue,settingsItem:"projects.default-model",children:Y}),e[23]=Y,e[24]=se,e[25]=ue,e[26]=be):be=e[26];let $;e[27]!==r?($=r("settings.projects.page.field.accentColor"),e[27]=r,e[28]=$):$=e[28];let le;e[29]!==c?(le=()=>c(null),e[29]=c,e[30]=le):le=e[30];const K=h===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let oe;e[31]!==K?(oe=q("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",K),e[31]=K,e[32]=oe):oe=e[32];let ce;e[33]!==r?(ce=r("settings.projects.page.field.none"),e[33]=r,e[34]=ce):ce=e[34];let pe;e[35]===Symbol.for("react.memo_cache_sentinel")?(pe=t.jsx(C,{name:"close",className:"h-4 w-4 text-muted-foreground"}),e[35]=pe):pe=e[35];let P;e[36]!==le||e[37]!==oe||e[38]!==ce?(P=t.jsx("button",{type:"button",onClick:le,className:oe,title:ce,children:pe}),e[36]=le,e[37]=oe,e[38]=ce,e[39]=P):P=e[39];let B;e[40]!==h||e[41]!==c?(B=So.map(b=>t.jsx("button",{type:"button",onClick:()=>c(b.key),className:q("h-7 w-7 rounded-md border transition-colors",h===b.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:b.cssVar},title:b.label},b.key)),e[40]=h,e[41]=c,e[42]=B):B=e[42];let Q;e[43]!==P||e[44]!==B?(Q=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[P,B]}),e[43]=P,e[44]=B,e[45]=Q):Q=e[45];let me;e[46]!==$||e[47]!==Q?(me=t.jsx(It,{title:$,settingsItem:"projects.accent-color",children:Q}),e[46]=$,e[47]=Q,e[48]=me):me=e[48];let ee;e[49]!==r?(ee=r("settings.projects.page.field.projectIcon"),e[49]=r,e[50]=ee):ee=e[50];let Se;e[51]!==V?(Se=b=>{const X=b.target.files?.[0]??null;V(X),b.currentTarget.value=""},e[51]=V,e[52]=Se):Se=e[52];let Te;e[53]!==L||e[54]!==Se?(Te=t.jsx("input",{ref:L,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:Se}),e[53]=L,e[54]=Se,e[55]=Te):Te=e[55];let De;e[56]!==f?(De=()=>f(null),e[56]=f,e[57]=De):De=e[57];const Ue=u===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let Ve;e[58]!==Ue?(Ve=q("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Ue),e[58]=Ue,e[59]=Ve):Ve=e[59];let Me;e[60]!==r?(Me=r("settings.projects.page.field.none"),e[60]=r,e[61]=Me):Me=e[61];let Ze;e[62]===Symbol.for("react.memo_cache_sentinel")?(Ze=t.jsx(C,{name:"close",className:"h-4 w-4 text-muted-foreground"}),e[62]=Ze):Ze=e[62];let Ee;e[63]!==De||e[64]!==Ve||e[65]!==Me?(Ee=t.jsx("button",{type:"button",onClick:De,className:Ve,title:Me,children:Ze}),e[63]=De,e[64]=Ve,e[65]=Me,e[66]=Ee):Ee=e[66];let Ge;e[67]!==_||e[68]!==u||e[69]!==f?(Ge=Co.map(b=>{const X=b.Icon;return t.jsx("button",{type:"button",onClick:()=>f(b.key),className:q("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",u===b.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:b.label,children:t.jsx(C,{name:X,className:"w-4 h-4",style:_&&u===b.key?{color:_}:void 0})},b.key)}),e[67]=_,e[68]=u,e[69]=f,e[70]=Ge):Ge=e[70];let Le;e[71]!==Ee||e[72]!==Ge?(Le=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Ee,Ge]}),e[71]=Ee,e[72]=Ge,e[73]=Le):Le=e[73];let $e;e[74]!==W||e[75]!==o||e[76]!==F||e[77]!==k||e[78]!==g||e[79]!==G||e[80]!==de||e[81]!==w||e[82]!==te||e[83]!==r?($e=F&&te&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.projects.page.field.preview")}),t.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/60 bg-[var(--surface-elevated)] p-1",children:t.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:g?{backgroundColor:g}:void 0,children:k&&G?t.jsx("img",{src:G,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>w(!0)}):t.jsx(Io,{project:{...de,iconImage:W??de.iconImage},options:{themeVariant:o.metadata.variant,iconColor:o.colors.surface.foreground},className:"h-full w-full object-contain",onError:()=>w(!0)})})})]}),e[74]=W,e[75]=o,e[76]=F,e[77]=k,e[78]=g,e[79]=G,e[80]=de,e[81]=w,e[82]=te,e[83]=r,e[84]=$e):$e=e[84];let Je;e[85]!==F||e[86]!==g||e[87]!==p||e[88]!==r?(Je=F&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("input",{type:"color",value:g??"#000000",onChange:b=>p(b.target.value),className:"h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":r("settings.projects.page.field.projectIconBackgroundAria")}),t.jsx(ht,{value:g??"",onChange:b=>p(b.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),t.jsx(Ne,{type:"button",size:"xs",variant:"outline",onClick:()=>p(null),className:"h-7 w-7 p-0","aria-label":r("settings.projects.page.field.clearIconBackgroundAria"),title:r("settings.projects.page.field.clearBackground"),disabled:!g,children:t.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]}),e[85]=F,e[86]=g,e[87]=p,e[88]=r,e[89]=Je):Je=e[89];let Be;e[90]!==L||e[91]!==ne||e[92]!==I||e[93]!==T||e[94]!==y||e[95]!==r?(Be=!I&&t.jsxs(t.Fragment,{children:[t.jsx(Ne,{size:"xs",className:"h-6 !font-normal",onClick:()=>L.current?.click(),disabled:y,children:r(y?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),t.jsx(Ne,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{ne()},disabled:T,children:r(T?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),e[90]=L,e[91]=ne,e[92]=I,e[93]=T,e[94]=y,e[95]=r,e[96]=Be):Be=e[96];let Qe;e[97]!==z||e[98]!==re||e[99]!==j||e[100]!==r?(Qe=re&&t.jsx(Ne,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{z()},disabled:j,children:r(j?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),e[97]=z,e[98]=re,e[99]=j,e[100]=r,e[101]=Qe):Qe=e[101];let He;e[102]!==j||e[103]!==R||e[104]!==M||e[105]!==r?(He=R&&t.jsx(Ne,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>M(!1),disabled:j,children:r("settings.projects.page.actions.undoRemove")}),e[102]=j,e[103]=R,e[104]=M,e[105]=r,e[106]=He):He=e[106];let Pe;e[107]!==Be||e[108]!==Qe||e[109]!==He?(Pe=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Be,Qe,He]}),e[107]=Be,e[108]=Qe,e[109]=He,e[110]=Pe):Pe=e[110];let et;e[111]!==ee||e[112]!==Te||e[113]!==Le||e[114]!==$e||e[115]!==Je||e[116]!==Pe?(et=t.jsxs(It,{title:ee,settingsItem:"projects.icon",contentClassName:"space-y-3",children:[Te,Le,$e,Je,Pe]}),e[111]=ee,e[112]=Te,e[113]=Le,e[114]=$e,e[115]=Je,e[116]=Pe,e[117]=et):et=e[117];let ze;return e[118]!==be||e[119]!==me||e[120]!==et||e[121]!==D?(ze=t.jsxs(t.Fragment,{children:[D,be,me,et]}),e[118]=be,e[119]=me,e[120]=et,e[121]=D,e[122]=ze):ze=e[122],ze},il=/^#(?:[\da-fA-F]{3}|[\da-fA-F]{6})$/,ll=s=>{if(!s)return null;const e=s.trim();return e&&il.test(e)?e.toLowerCase():null},cl=s=>{const{t:e}=rt(),n=gt($=>$.uploadProjectIcon),r=gt($=>$.removeProjectIcon),o=gt($=>$.discoverProjectIcon),a=gt($=>s?$.projects.find(le=>le.id===s.id)?.iconImage??null:null),[i,u]=l.useState(""),[f,h]=l.useState(null),[c,g]=l.useState(null),[p,x]=l.useState(null),[d,y]=l.useState(void 0),[j,T]=l.useState(!1),[R,M]=l.useState(!1),[G,w]=l.useState(!1),[k,I]=l.useState(!1),[F,re]=l.useState(null),[te,L]=l.useState(null),[V,z]=l.useState(!1),ne=l.useRef(null),W=l.useCallback(()=>{re(null),L($=>($&&URL.revokeObjectURL($),null))},[]),de=s?.id??null;l.useEffect(()=>{if(!s){u(""),h(null),g(null),x(null),y(void 0);return}u(s.label??""),h(s.icon??null),g(s.color??null),x(s.iconBackground??null),y(s.defaultModel),I(!1),W(),z(!1)},[s,W]),l.useEffect(()=>()=>{W()},[W]);const _=l.useMemo(()=>Gn(d)??{providerId:"",modelId:""},[d]),O=!!s?.iconImage,E=!!(F&&te),A=s?.iconImage?.source==="custom",U=O&&!k||E,H=U,D=!!(s&&O&&!k),se=!V&&(E||D),ue=!!s&&(i.trim()!==(s?.label??"").trim()||f!==(s?.icon??null)||c!==(s?.color??null)||p!==(s?.iconBackground??null)||(d??void 0)!==(s?.defaultModel??void 0)||k||!!F),he=l.useCallback(($,le)=>{y($&&le?`${$}/${le}`:void 0)},[]),Ce=l.useCallback($=>{!s||!$||j||(I(!1),z(!1),re($),L(le=>(le&&URL.revokeObjectURL(le),URL.createObjectURL($))))},[j,s]),ke=l.useCallback(()=>{!s||!H||R||(E&&W(),I(!!O),z(!1))},[W,E,H,O,R,s]),Y=l.useCallback(async()=>{if(!(!s||G)){W(),I(!1),z(!1),w(!0);try{const $=await o(s.id);if(!$.ok){ve.error($.error||e("settings.projects.page.toast.discoverIconFailed"));return}if($.skipped){ve.success(e("settings.projects.page.toast.customIconAlreadySet"));return}ve.success(e("settings.projects.page.toast.iconDiscovered"))}finally{w(!1)}}},[W,o,G,s,e]),be=l.useCallback(async $=>{const le=$?.silent===!0;if(!s)return null;const K=i.trim();if(!K)return null;if(F){T(!0);const ce=await n(s.id,F);if(T(!1),!ce.ok)return ve.error(ce.error||e("settings.projects.page.toast.uploadIconFailed")),null;le||ve.success(e("settings.projects.page.toast.iconUpdated")),W(),I(!1)}const oe=k&&!!s.iconImage;if(oe){M(!0);const ce=await r(s.id);if(M(!1),!ce.ok)return ve.error(ce.error||e("settings.projects.page.toast.removeIconFailed")),null;le||ve.success(e("settings.projects.page.toast.iconRemoved")),I(!1),x(null)}return{label:K,icon:f,color:c,iconBackground:ll(oe?null:p),defaultModel:d??null}},[W,c,d,f,p,i,k,F,s,r,e,n]);return l.useEffect(()=>{z(!1)},[de,a?.updatedAt]),{name:i,setName:u,icon:f,setIcon:h,color:c,setColor:g,iconBackground:p,setIconBackground:x,defaultModel:d,parsedDefaultModel:_,handleDefaultModelChange:he,isUploadingIcon:j,isRemovingCustomIcon:R,isDiscoveringIcon:G,pendingRemoveImageIcon:k,setPendingRemoveImageIcon:I,pendingUploadIconFile:F,pendingUploadIconPreviewUrl:te,previewImageFailed:V,setPreviewImageFailed:z,hasStoredImageIcon:O,hasPendingUploadImageIcon:E,hasCustomIcon:A,effectiveHasImageIcon:U,hasRemovableImageIcon:H,showStoredImagePreview:D,showImagePreview:se,fileInputRef:ne,clearPendingUploadIcon:W,handleUploadIcon:Ce,handleRemoveImageIcon:ke,handleDiscoverIcon:Y,hasChanges:ue,prepareSaveData:be,currentIconImage:a,project:s}},dl=450,ul=(s,e)=>{const{t:n}=rt(),{hasChanges:r,name:o,icon:a,color:i,iconBackground:u,defaultModel:f,pendingRemoveImageIcon:h,pendingUploadIconFile:c,isUploadingIcon:g,isRemovingCustomIcon:p,prepareSaveData:x}=s,d=l.useRef(!1);l.useEffect(()=>{if(!r||!o.trim()||g||p||d.current)return;const y=window.setTimeout(()=>{d.current||(d.current=!0,(async()=>{try{const j=await x({silent:!0});if(j)try{await e(j)}catch{ve.error(n("settings.projects.page.toast.saveFailed"))}}finally{d.current=!1}})())},dl);return()=>{window.clearTimeout(y)}},[i,f,r,a,u,p,g,o,e,h,c,x,n])},fd=s=>{const e=Ye.c(16),{project:n,onIdentitySave:r,showWorktrees:o}=s,a=o===void 0?!0:o,i=cl(n);let u;e:{if(!n){u=null;break e}let y;e[0]!==n.id||e[1]!==n.path?(y={id:n.id,path:n.path},e[0]=n.id,e[1]=n.path,e[2]=y):y=e[2],u=y}const f=u;let h;if(e[3]!==r?(h=async y=>{await r(y)},e[3]=r,e[4]=h):h=e[4],ul(i,h),!n||!f)return null;let g;e[5]!==i?(g=t.jsx(al,{form:i}),e[5]=i,e[6]=g):g=e[6];let p;e[7]!==f?(p=t.jsx(ol,{projectRef:f}),e[7]=f,e[8]=p):p=e[8];let x;e[9]!==f||e[10]!==a?(x=a?t.jsx(Qi,{projectRef:f}):null,e[9]=f,e[10]=a,e[11]=x):x=e[11];let d;return e[12]!==g||e[13]!==p||e[14]!==x?(d=t.jsxs("div",{className:"space-y-0",children:[g,p,x]}),e[12]=g,e[13]=p,e[14]=x,e[15]=d):d=e[15],d},hd=s=>{const e=Ye.c(17),{percent:n,tonePercent:r,className:o}=s;let a;e[0]!==n?(a=To(n)??0,e[0]=n,e[1]=a):a=e[1];const i=a,u=r??n;let f;e[2]!==u?(f=Po(u),e[2]=u,e[3]=f):f=e[3];const h=f;let c;e[4]!==h?(c=h==="critical"?{backgroundColor:"var(--status-error)"}:h==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=h,e[5]=c):c=e[5];const g=c;let p;e[6]!==o?(p=q("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",o),e[6]=o,e[7]=p):p=e[7];const x=`${i}%`;let d;e[8]!==g||e[9]!==x?(d={...g,width:x},e[8]=g,e[9]=x,e[10]=d):d=e[10];let y;e[11]!==i||e[12]!==d?(y=t.jsx("div",{className:"h-full transition-all duration-300",style:d,role:"progressbar","aria-valuenow":i,"aria-valuemin":0,"aria-valuemax":100}),e[11]=i,e[12]=d,e[13]=y):y=e[13];let j;return e[14]!==p||e[15]!==y?(j=t.jsx("div",{className:p,children:y}),e[14]=p,e[15]=y,e[16]=j):j=e[16],j},gr=()=>{const s=Do();return{displayMode:s,installed:s!=="browser",browserTab:s==="browser"}},pd=()=>{const s=Ye.c(2),[e,n]=l.useState(ml);let r,o;return s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const a=[window.matchMedia("(display-mode: standalone)"),window.matchMedia("(display-mode: minimal-ui)"),window.matchMedia("(display-mode: fullscreen)"),window.matchMedia("(display-mode: window-controls-overlay)")],i=()=>{n(gr())};i();for(const u of a)typeof u.addEventListener=="function"?u.addEventListener("change",i):typeof u.addListener=="function"&&u.addListener(i);return window.addEventListener("appinstalled",i),window.addEventListener("focus",i),()=>{for(const u of a)typeof u.removeEventListener=="function"?u.removeEventListener("change",i):typeof u.removeListener=="function"&&u.removeListener(i);window.removeEventListener("appinstalled",i),window.removeEventListener("focus",i)}},o=[],s[0]=r,s[1]=o):(r=s[0],o=s[1]),l.useEffect(r,o),e};function ml(){return gr()}const fl=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"general",title:"General",group:"general",kind:"single",keywords:["general","startup","launch at login","autostart","tray","password","passkey","security","privacy","telemetry","transport","network","lan","binary","cli"]},{slug:"projects",title:"Projects",group:"projects",kind:"split",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"single",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:s=>!s.isVSCode},{slug:"providers",title:"Providers",group:"opencode",kind:"split",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"usage",title:"Usage",group:"general",kind:"split",keywords:["quota","billing","tokens","usage","limits"]},{slug:"agents",title:"Agents",group:"opencode",kind:"split",keywords:["agent","agents","prompts","tools","permissions"]},{slug:"behavior",title:"Behavior",group:"opencode",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"commands",title:"Commands",group:"opencode",kind:"split",keywords:["command","commands","slash","macros","automation"]},{slug:"mcp",title:"MCP",group:"opencode",kind:"split",keywords:["mcp","model context protocol","servers","tools","remote","stdio"]},{slug:"plugins",title:"Plugins",group:"opencode",kind:"split",keywords:["plugin","plugins","extensions","addons","npm","opencode-wakatime"]},{slug:"skills.installed",title:"Skills",group:"content",kind:"split",keywords:["skill","skills","instructions","install","catalog"]},{slug:"skills.catalog",title:"Skills Catalog",group:"content",kind:"single",keywords:["install","catalog","external","repository","skills catalog"]},{slug:"git",title:"Git",group:"projects",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","gitmoji","oauth","prs","issues"],isAvailable:s=>!s.isVSCode},{slug:"appearance",title:"Appearance",group:"general",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"],isAvailable:s=>!s.isVSCode},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"magic-prompts",title:"Magic Prompts",group:"content",kind:"split",keywords:["prompts","templates","git","github","review","commit","pull request"],isAvailable:s=>!s.isVSCode},{slug:"snippets",title:"Snippets",group:"content",kind:"split",keywords:["prompt","templates","multi-run","strategy","approach"]},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"voice",title:"Voice",group:"general",kind:"single",keywords:["tts","speech","voice"],isAvailable:s=>!s.isVSCode},{slug:"tunnel",title:"External Tunnel",group:"projects",kind:"single",keywords:["tunnel","external","cloudflare","qr","remote","mobile","share"],isAvailable:s=>!s.isVSCode},{slug:"about",title:"About",group:"general",kind:"single",keywords:["about","version","updates","release","changelog"],isAvailable:s=>s.isMobile&&!s.isVSCode}],hl={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function pl(s){const e=s.trim().toLowerCase();return fl.find(n=>n.slug===e)??null}function gl(s){const e=(s??"").trim().toLowerCase();if(!e)return"home";const n=hl[e];if(n)return n;const r=pl(e);return r?r.slug:"home"}function gd(s){switch(s){case"general":return"settings-3";case"projects":return"folders";case"remote-instances":return"computer";case"appearance":return"palette";case"chat":return"chat-ai-3";case"magic-prompts":return"ai-generate-2";case"snippets":return"chat-thread";case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"chat-history";case"providers":return"cloud";case"agents":return"ai-agent";case"behavior":return"brain";case"commands":return"slash-commands-2";case"mcp":return null;case"plugins":return"plug-2";case"skills.installed":return"book-open";case"skills.catalog":return"book";case"git":return"git-branch";case"usage":return"bar-chart-2";case"voice":return"mic";case"tunnel":return"home-office";case"about":return"information";case"home":return null;default:return"robot-2"}}const xl=["chat","git","diff","terminal","files","diagram"],bl=["settings","agents","commands","skills","providers","usage","git-identities"],xt={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Cn(s){const e=yl();return{sessionId:wl(e),tab:vl(e),settingsPath:kl(e),diffFile:jl(e)}}function yl(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function wl(s){const e=s.get(xt.SESSION);return!e||e.trim().length===0?null:e.trim()}function vl(s){const e=s.get(xt.TAB);if(!e)return null;const n=e.toLowerCase().trim();return xl.includes(n)?n:null}function kl(s){const e=s.get(xt.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(bl.includes(n),n)}function jl(s){const e=s.get(xt.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function In(){if(typeof window>"u")return!1;try{const s=new URLSearchParams(window.location.search);return s.has(xt.SESSION)||s.has(xt.TAB)||s.has(xt.SETTINGS)||s.has(xt.FILE)}catch{return!1}}const Nl="chat";function xr(s){const e=new URLSearchParams;if(s.sessionId&&s.sessionId.trim().length>0&&e.set(xt.SESSION,s.sessionId),s.isSettingsOpen){const n=s.settingsPath.trim().length>0?s.settingsPath:"home";return e.set(xt.SETTINGS,n),e}return s.tab!==Nl&&e.set(xt.TAB,s.tab),s.tab==="diff"&&s.diffFile&&s.diffFile.trim().length>0&&e.set(xt.FILE,s.diffFile),e}function Sl(s,e){const n=typeof window<"u"?window.location.pathname:"/",r=s.toString();return r?`${n}?${r}`:n}function Cl(s){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=xr(s),r=[...e.entries()].sort((a,i)=>a[0].localeCompare(i[0])),o=[...n.entries()].sort((a,i)=>a[0].localeCompare(i[0]));if(r.length!==o.length)return!1;for(let a=0;a<r.length;a++)if(r[a][0]!==o[a][0]||r[a][1]!==o[a][1])return!1;return!0}catch{return!0}}function Tn(s,e={}){if(!(typeof window>"u")&&!(Il()||tr())&&!(!e.force&&Cl(s)))try{const n=xr(s),r=Sl(n);e.replace?window.history.replaceState({...window.history.state,route:s},"",r):window.history.pushState({route:s},"",r)}catch{}}function Il(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function Tl(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function xd(){const s=l.useMemo(()=>Tl(),[]),e=l.useMemo(()=>tr(),[]),n=l.useRef(!1),r=l.useRef(!1),o=nt(p=>p.setCurrentSession),a=Ae(p=>p.setActiveMainTab),i=Ae(p=>p.setSettingsDialogOpen),u=Ae(p=>p.setSettingsPage),f=Ae(p=>p.navigateToDiff),h=l.useCallback(async p=>{if(!r.current){r.current=!0;try{if(p.sessionId){const x=nt.getState().currentSessionId;if(p.sessionId!==x){const d=nt.getState().getDirectoryForSession(p.sessionId);o(p.sessionId,d)}}if(p.settingsPath){u(gl(p.settingsPath)),i(!0);return}Ae.getState().isSettingsDialogOpen&&i(!1),p.tab&&a(p.tab),p.diffFile&&(p.tab==="diff"||!p.tab)&&f(p.diffFile)}finally{r.current=!1}}},[o,a,i,u,f]),c=l.useCallback(()=>{const p=nt.getState(),x=Ae.getState();return{sessionId:p.currentSessionId,tab:x.activeMainTab,isSettingsOpen:x.isSettingsDialogOpen,settingsPath:x.settingsPage,diffFile:x.pendingDiffFile}},[]),g=l.useCallback((p={})=>{if(s||e||r.current)return;const x=c();Tn(x,p)},[s,e,c]);l.useEffect(()=>{if(n.current||(n.current=!0,!In()))return;const p=Cn();(async()=>(await h(p),!s&&!e&&Tn({...c(),sessionId:p.sessionId??nt.getState().currentSessionId,tab:p.tab??Ae.getState().activeMainTab,settingsPath:p.settingsPath??Ae.getState().settingsPage,diffFile:p.diffFile??Ae.getState().pendingDiffFile},{replace:!0,force:!0})))()},[h,c,s,e]),l.useEffect(()=>{if(s||e)return;let p=nt.getState().currentSessionId;return nt.subscribe(d=>{const y=d.currentSessionId;y===p||r.current||(p=y,g())})},[s,e,g]),l.useEffect(()=>{if(s||e)return;let p=Ae.getState().activeMainTab,x=Ae.getState().isSettingsDialogOpen,d=Ae.getState().settingsPage,y=Ae.getState().pendingDiffFile;return Ae.subscribe(T=>{if(r.current)return;const R=T.activeMainTab!==p,M=T.isSettingsDialogOpen!==x,G=T.settingsPage!==d,w=T.pendingDiffFile!==y&&T.activeMainTab==="diff";p=T.activeMainTab,x=T.isSettingsDialogOpen,d=T.settingsPage,y=T.pendingDiffFile,(R||M||G||w)&&g()})},[s,e,g]),l.useEffect(()=>{if(typeof window>"u"||s||e)return;const p=()=>{const x=Cn();if(In())h(x);else{const d=Ae.getState();d.isSettingsDialogOpen&&i(!1),d.activeMainTab!=="chat"&&a("chat")}};return window.addEventListener("popstate",p),()=>{window.removeEventListener("popstate",p)}},[h,s,e,a,i])}function bd(){const s=Ye.c(5),e=ri(Dl),n=l.useRef(e);let r,o;s[0]!==e?(r=()=>{n.current=e},o=[e],s[0]=e,s[1]=r,s[2]=o):(r=s[1],o=s[2]),l.useEffect(r,o);let a,i;s[3]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{let u=!1,f=null;const h=Pl,c=g=>{u||(f=window.setTimeout(async()=>{const p=await n.current(),x=typeof p=="number"&&Number.isFinite(p)?h(p):36e5;c(x)},g))};return c(3e3),()=>{u=!0,f!==null&&window.clearTimeout(f)}},i=[],s[3]=a,s[4]=i):(a=s[3],i=s[4]),l.useEffect(a,i)}function Pl(s){const e=Math.round(s*1e3);return Math.max(3e5,Math.min(864e5,e))}function Dl(s){return s.checkForUpdates}const zs=1e3,Kt=60*zs,ks=60*Kt,El=(s,e)=>{const n=Math.max(0,s);return n<Kt?e("common.duration.secondsCompact",{seconds:Math.floor(n/zs)}):n<ks?e("common.duration.minutesSecondsCompact",{minutes:Math.floor(n/Kt),seconds:Math.floor(n%Kt/zs)}):e("common.duration.hoursMinutesCompact",{hours:Math.floor(n/ks),minutes:Math.floor(n%ks/Kt)})},Rl=1e3,yd=s=>{const e=Ye.c(12),{sessionId:n,running:r,className:o}=s,{t:a}=rt(),i=Eo(n),u=Ro(n),f=Ao(r,Rl),h=r?Math.max(0,f-(i??f)):u;if(h===void 0)return null;let c,g;e[0]!==h||e[1]!==r||e[2]!==a?(c=El(h,a),g=r?a("sessions.sidebar.session.status.activeFor",{duration:c}):a("sessions.sidebar.session.status.lastTurnDuration",{duration:c}),e[0]=h,e[1]=r,e[2]=a,e[3]=c,e[4]=g):(c=e[3],g=e[4]);const p=g,x=r?"text-primary":"text-[var(--status-info)]";let d;e[5]!==o||e[6]!==x?(d=q("shrink-0 tabular-nums",x,o),e[5]=o,e[6]=x,e[7]=d):d=e[7];let y;return e[8]!==p||e[9]!==c||e[10]!==d?(y=t.jsx("span",{className:d,"aria-label":p,title:p,children:c}),e[8]=p,e[9]=c,e[10]=d,e[11]=y):y=e[11],y},Al=()=>{const s=Ye.c(14),[e,n]=J.useState(!1),[r,o]=J.useState(!1);let a,i;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{n(Qn()),o(wa())},i=[],s[0]=a,s[1]=i):(a=s[0],i=s[1]),J.useEffect(a,i);let u;s[2]!==e?(u=async d=>e?await va(d):{success:!0,path:d},s[2]=e,s[3]=u):u=s[3];const f=u;let h;s[4]!==e?(h=async d=>e?await ka():{success:!0},s[4]=e,s[5]=h):h=s[5];const c=h;let g;s[6]!==e?(g=async d=>e?await ja():{success:!0},s[6]=e,s[7]=g):g=s[7];const p=g;let x;return s[8]!==r||s[9]!==e||s[10]!==f||s[11]!==c||s[12]!==p?(x={isDesktop:e,canRequestAccess:r,requestAccess:f,startAccessing:c,stopAccessing:p},s[8]=r,s[9]=e,s[10]=f,s[11]=c,s[12]=p,s[13]=x):x=s[13],x},Bl=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Ml=({currentBranch:s,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:o,onCreate:a,remotes:i=[],disabled:u=!1})=>{const{t:f}=rt(),[h,c]=l.useState(!1),[g,p]=l.useState(""),[x,d]=l.useState(!1),[y,j]=l.useState(!1),[T,R]=l.useState(""),[M,G]=l.useState(!1),w=l.useRef(null),k=l.useCallback(_=>{_.stopPropagation()},[]),I=i.length>1,F=l.useMemo(()=>Bl(T),[T]),re=l.useMemo(()=>{const _=g.toLowerCase();return _?e.filter(O=>O.toLowerCase().includes(_)):e},[g,e]),te=l.useMemo(()=>{const _=g.toLowerCase();return _?n.filter(O=>O.toLowerCase().includes(_)):n},[g,n]),L=_=>{if(_===s){c(!1);return}o(_),c(!1),p("")},V=()=>{d(!0),setTimeout(()=>w.current?.focus(),50)},z=async()=>{if(!(!F||M)){if(I){j(!0);return}G(!0);try{await a(F,i[0]),R(""),d(!1),c(!1)}finally{G(!1)}}},ne=async _=>{if(!(!F||M)){G(!0);try{await a(F,_),R(""),d(!1),j(!1),c(!1)}finally{G(!1)}}},W=()=>{j(!1)},de=()=>{R(""),d(!1),j(!1)};return l.useEffect(()=>{h||(p(""),d(!1),j(!1),R(""))},[h]),t.jsxs(Pt,{open:h,onOpenChange:c,children:[t.jsxs(Mt,{children:[t.jsx(Lt,{asChild:!0,children:t.jsx(Dt,{asChild:!0,children:t.jsxs(Ne,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:u,children:[t.jsx(C,{name:"git-branch",className:"size-4 text-primary"}),t.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:s||f("gitView.branch.detachedHead")}),t.jsx(C,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),t.jsx(Ft,{sideOffset:8,children:f("gitView.branch.currentBranchTooltip")})]}),t.jsx(Et,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:t.jsxs(Ms,{className:"h-full min-h-0",children:[t.jsx(Ls,{placeholder:f("gitView.branch.searchPlaceholder"),value:g,onValueChange:p,onKeyDown:k}),t.jsxs(Fs,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(Os,{children:f("gitView.branch.empty")}),t.jsx(Ct,{children:y?t.jsxs("div",{className:"px-2 py-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("button",{type:"button",onClick:W,disabled:M,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(C,{name:"arrow-left",className:"size-4"})}),t.jsxs("span",{className:"typography-meta text-muted-foreground",children:[f("gitView.branch.pushToPrefix")," ",t.jsx("span",{className:"text-foreground font-medium",children:F})," ",f("gitView.branch.pushToSuffix")]})]}),t.jsx("div",{className:"flex flex-col gap-1",children:i.map(_=>t.jsxs("button",{type:"button",onClick:()=>ne(_),disabled:M,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[t.jsxs("span",{className:"typography-ui-label text-foreground",children:[M?t.jsx(C,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,_.name]}),t.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:_.pushUrl})]},_.name))})]}):x?t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[t.jsx("input",{ref:w,placeholder:f("gitView.branch.newBranchPlaceholder"),value:T,onChange:_=>R(_.target.value),onClick:_=>_.stopPropagation(),onKeyDown:_=>{k(_),_.key==="Enter"?(_.preventDefault(),z()):_.key==="Escape"&&(_.preventDefault(),de())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),t.jsx("button",{type:"button",onClick:z,disabled:!F||M,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:M?t.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(C,{name:"add",className:"size-4"})}),t.jsx("button",{type:"button",onClick:de,disabled:M,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(C,{name:"close",className:"size-4"})})]}):t.jsxs(yt,{onSelect:V,children:[t.jsx(C,{name:"add",className:"size-4"}),t.jsx("span",{children:f("gitView.branch.create")})]})}),t.jsx(zt,{}),t.jsxs(Ct,{heading:f("gitView.branch.localBranches"),children:[re.map(_=>t.jsxs(yt,{onSelect:()=>L(_),children:[t.jsxs("span",{className:"flex flex-1 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:_}),(r?.[_]?.ahead||r?.[_]?.behind)&&t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[r[_].ahead||0," ahead ·"," ",r[_].behind||0," behind"]})]}),s===_&&t.jsx("span",{className:"typography-micro text-primary",children:f("gitView.branch.currentBadge")})]},`local-${_}`)),re.length===0&&t.jsx(yt,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:f("gitView.branch.noLocalBranches")})})]}),t.jsx(zt,{}),t.jsxs(Ct,{heading:f("gitView.branch.remoteBranches"),children:[te.map(_=>t.jsx(yt,{onSelect:()=>L(_),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:_})},`remote-${_}`)),te.length===0&&t.jsx(yt,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:f("gitView.branch.noRemoteBranches")})})]})]})]})})]})},Ll=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Fl=({currentBranch:s,onRename:e,showEditButton:n=!0})=>{const{t:r}=rt(),[o,a]=l.useState(!1),[i,u]=l.useState(s||""),[f,h]=l.useState(!1),c=l.useRef(null),g=()=>{!s||!e||(u(s),a(!0),setTimeout(()=>c.current?.focus(),0))},p=async()=>{if(!s||!e||!i.trim())return;const y=Ll(i);if(y===s){a(!1);return}h(!0);try{await e(s,y),a(!1),u("")}finally{h(!1)}},x=()=>{a(!1),u("")},d=y=>{y.key==="Enter"?(y.preventDefault(),p()):y.key==="Escape"&&(y.preventDefault(),x())};return o?t.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:t.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:y=>{y.preventDefault(),p()},children:[t.jsx(C,{name:"git-branch",className:"size-4 text-primary"}),t.jsx("input",{ref:c,value:i,onChange:y=>u(y.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:d,autoFocus:!0}),t.jsx("button",{type:"submit",disabled:f,"aria-label":r(f?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:r(f?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:f?t.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(C,{name:"check",className:"size-4"})}),t.jsx("button",{type:"button",onClick:x,disabled:f,"aria-label":r("gitView.branch.renameCancel"),title:r("gitView.branch.renameCancel"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(C,{name:"close",className:"size-4"})})]})}):t.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[t.jsx(C,{name:"git-branch",className:"size-4 text-primary shrink-0"}),t.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[t.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:s||r("gitView.branch.detachedHead")}),n&&e&&s&&t.jsx(Ne,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:g,title:r("gitView.branch.renameTitle"),children:t.jsx(C,{name:"edit",className:"size-4"})})]})]})},Ol=s=>{const e=Ye.c(44),{syncAction:n,remotes:r,onFetch:o,onSync:a,onRemoveRemote:i,disabled:u,removingRemoteName:f,aheadCount:h,behindCount:c,trackingRemoteName:g,hasUncommittedChanges:p}=s,x=r===void 0?[]:r,d=f===void 0?null:f,y=h===void 0?0:h,j=c===void 0?0:c,T=p===void 0?!1:p,{t:R}=rt(),M=l.useRef(!1),G=!!d,w=x.find(me=>me.name===g)??x[0],k=j>0&&T,I=u||n!==null||G||!w||k,F=u||n!==null||G||x.length===0,re=y>0||j>0;let te;e[0]!==R?(te=R("gitView.sync.sync"),e[0]=R,e[1]=te):te=e[1];const L=j>0?`↓${j}`:null,V=y>0?`↑${y}`:null;let z;e[2]!==te||e[3]!==L||e[4]!==V?(z=[te,L,V].filter(Boolean),e[2]=te,e[3]=L,e[4]=V,e[5]=z):z=e[5];const ne=z.join(" "),W=k?R("gitView.sync.commitOrStashTooltip"):w?re?R("gitView.sync.syncChangesTooltip",{ahead:y,behind:j}):R("gitView.sync.syncChanges"):R("gitView.sync.noRemoteTooltip"),de=()=>{w&&a(w)},_="inline-flex items-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] border border-border/60 bg-[var(--surface-elevated)] overflow-hidden",O=k?0:void 0;let E;e[6]===Symbol.for("react.memo_cache_sentinel")?(E=q("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[6]=E):E=e[6];let A;e[7]!==R?(A=R("gitView.sync.syncChanges"),e[7]=R,e[8]=A):A=e[8];let U;e[9]!==n?(U=n==="sync"?t.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(C,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=U):U=e[10];let H;e[11]!==ne?(H=t.jsx("span",{className:"whitespace-nowrap tabular-nums",children:ne}),e[11]=ne,e[12]=H):H=e[12];let D;e[13]!==de||e[14]!==I||e[15]!==A||e[16]!==U||e[17]!==H?(D=t.jsxs("button",{type:"button",onClick:de,disabled:I,className:E,"aria-label":A,children:[U,H]}),e[13]=de,e[14]=I,e[15]=A,e[16]=U,e[17]=H,e[18]=D):D=e[18];let se;e[19]!==O||e[20]!==D?(se=t.jsx(Lt,{asChild:!0,children:t.jsx("span",{className:"inline-flex",tabIndex:O,children:D})}),e[19]=O,e[20]=D,e[21]=se):se=e[21];let ue;e[22]!==W?(ue=t.jsx(Ft,{sideOffset:8,children:W}),e[22]=W,e[23]=ue):ue=e[23];let he;e[24]!==se||e[25]!==ue?(he=t.jsxs(Mt,{children:[se,ue]}),e[24]=se,e[25]=ue,e[26]=he):he=e[26];const Ce=Pt;let ke;e[27]===Symbol.for("react.memo_cache_sentinel")?(ke=q("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[27]=ke):ke=e[27];let Y;e[28]!==R?(Y=R("gitView.sync.moreActionsAria"),e[28]=R,e[29]=Y):Y=e[29];let be;e[30]===Symbol.for("react.memo_cache_sentinel")?(be=t.jsx(C,{name:"arrow-down-s",className:"size-4"}),e[30]=be):be=e[30];let $;e[31]!==F||e[32]!==Y?($=t.jsx(Dt,{asChild:!0,children:t.jsx("button",{type:"button",className:ke,disabled:F,"aria-label":Y,children:be})}),e[31]=F,e[32]=Y,e[33]=$):$=e[33];const le=Et,K="start",oe=-40,ce="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",pe=x.map(me=>t.jsx(jt,{onSelect:ee=>{if(M.current){ee.preventDefault(),M.current=!1;return}o(me)},children:t.jsxs("div",{className:"flex w-full items-center gap-2",children:[t.jsx(C,{name:"refresh",className:"size-4 text-muted-foreground"}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:R("gitView.sync.fetchFromRemote",{name:me.name})}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:me.fetchUrl})]})}),i&&me.name!==g?t.jsx(Ne,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||G,onPointerDown:ee=>{M.current=!0,ee.preventDefault(),ee.stopPropagation()},onClick:ee=>{M.current=!0,ee.preventDefault(),ee.stopPropagation(),i(me)},"aria-label":R("gitView.header.removeRemoteAria",{name:me.name}),title:R("gitView.header.removeRemoteTitle",{name:me.name}),children:d===me.name?t.jsx(C,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(C,{name:"close",className:"size-3.5"})}):null]})},me.name));let P;e[34]!==le||e[35]!==pe?(P=t.jsx(le,{align:K,alignOffset:oe,className:ce,children:pe}),e[34]=le,e[35]=pe,e[36]=P):P=e[36];let B;e[37]!==Ce||e[38]!==$||e[39]!==P?(B=t.jsxs(Ce,{children:[$,P]}),e[37]=Ce,e[38]=$,e[39]=P,e[40]=B):B=e[40];let Q;return e[41]!==he||e[42]!==B?(Q=t.jsxs("div",{className:_,children:[he,B]}),e[41]=he,e[42]=B,e[43]=Q):Q=e[43],Q},Ul={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3",fingerprint:"fingerprint"},Wl={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)",success:"var(--status-success)",info:"var(--status-info)",warning:"var(--status-warning)"};function br(s){return s&&Wl[s]||"var(--primary)"}const Pn=s=>{const e=Ye.c(8),{icon:n,className:r,colorToken:o}=s,a=Ul[n??"branch"]??"user-3";let i;e[0]!==o?(i=br(o),e[0]=o,e[1]=i):i=e[1];let u;e[2]!==i?(u={color:i},e[2]=i,e[3]=u):u=e[3];let f;return e[4]!==r||e[5]!==a||e[6]!==u?(f=t.jsx(C,{name:a,className:r,style:u}),e[4]=r,e[5]=a,e[6]=u,e[7]=f):f=e[7],f},yr=s=>{const e=Ye.c(35),{activeProfile:n,identities:r,onSelect:o,isApplying:a,iconOnly:i}=s,u=i===void 0?!1:i,{t:f}=rt(),h=a||r.length===0,c=n?.color;let g;e[0]!==c?(g=br(c),e[0]=c,e[1]=g):g=e[1];let p;e[2]!==g?(p={color:g},e[2]=g,e[3]=p):p=e[3];let x;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==a?(x=a?t.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(Pn,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=a,e[7]=x):x=e[7];let d;e[8]!==n?.name||e[9]!==u||e[10]!==f?(d=!u&&t.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||f("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=u,e[10]=f,e[11]=d):d=e[11];let y;e[12]===Symbol.for("react.memo_cache_sentinel")?(y=t.jsx(C,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=y):y=e[12];let j;e[13]!==h||e[14]!==p||e[15]!==x||e[16]!==d?(j=t.jsx(Lt,{asChild:!0,children:t.jsx(Dt,{asChild:!0,children:t.jsxs(Ne,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:p,disabled:h,children:[x,d,y]})})}),e[13]=h,e[14]=p,e[15]=x,e[16]=d,e[17]=j):j=e[17];let T;e[18]!==f?(T=f("gitView.header.identityTooltip"),e[18]=f,e[19]=T):T=e[19];let R;e[20]!==T?(R=t.jsx(Ft,{sideOffset:8,children:T}),e[20]=T,e[21]=R):R=e[21];let M;e[22]!==R||e[23]!==j?(M=t.jsxs(Mt,{children:[j,R]}),e[22]=R,e[23]=j,e[24]=M):M=e[24];let G;e[25]!==n?.id||e[26]!==r||e[27]!==o||e[28]!==f?(G=r.length===0?t.jsx("div",{className:"px-2 py-1.5",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.header.noProfiles")})}):r.map(I=>{const F=n?.id===I.id;return t.jsx(jt,{onSelect:()=>o(I),children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(Pn,{icon:I.icon,colorToken:I.color,className:"size-4"}),t.jsxs("span",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:I.name}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:I.userEmail})]}),F?t.jsx(C,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},I.id)}),e[25]=n?.id,e[26]=r,e[27]=o,e[28]=f,e[29]=G):G=e[29];let w;e[30]!==G?(w=t.jsx(Et,{align:"end",className:"w-64",children:G}),e[30]=G,e[31]=w):w=e[31];let k;return e[32]!==M||e[33]!==w?(k=t.jsxs(Pt,{children:[M,w]}),e[32]=M,e[33]=w,e[34]=k):k=e[34],k},zl=s=>{const e=Ye.c(21),{comparison:n,trackingBranch:r,tooltipDelayMs:o}=s,a=o===void 0?1e3:o,{t:i}=rt(),u=`${n.remote}/${n.branch}`,f=n.ahead===0&&n.behind===0;let h;e[0]!==i||e[1]!==u||e[2]!==r?(h=r?i("gitView.header.upstreamTooltipTracking",{target:u,tracking:r}):i("gitView.header.upstreamTooltip",{target:u}),e[0]=i,e[1]=u,e[2]=r,e[3]=h):h=e[3];const c=h;let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=t.jsx(C,{name:"git-branch",className:"size-3.5 shrink-0"}),e[4]=g):g=e[4];let p;e[5]!==u?(p=t.jsx("span",{className:"min-w-0 truncate text-foreground/80",children:u}),e[5]=u,e[6]=p):p=e[6];let x;e[7]!==n.ahead||e[8]!==n.behind||e[9]!==f||e[10]!==i?(x=f?t.jsx("span",{className:"tabular-nums text-muted-foreground",children:i("gitView.header.upstreamSynced")}):t.jsxs("span",{className:"inline-flex items-center gap-1 tabular-nums",children:[n.ahead>0?t.jsxs("span",{className:"text-[var(--status-info)]",children:["↑",n.ahead]}):null,n.behind>0?t.jsxs("span",{className:"text-[var(--status-warning)]",children:["↓",n.behind]}):null]}),e[7]=n.ahead,e[8]=n.behind,e[9]=f,e[10]=i,e[11]=x):x=e[11];let d;e[12]!==p||e[13]!==x?(d=t.jsx(Lt,{asChild:!0,children:t.jsxs("div",{className:"inline-flex h-8 max-w-full items-center gap-1.5 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2 typography-micro text-muted-foreground",children:[g,p,x]})}),e[12]=p,e[13]=x,e[14]=d):d=e[14];let y;e[15]!==c?(y=t.jsx(Ft,{sideOffset:8,children:c}),e[15]=c,e[16]=y):y=e[16];let j;return e[17]!==d||e[18]!==y||e[19]!==a?(j=t.jsxs(Mt,{delayDuration:a,children:[d,y]}),e[17]=d,e[18]=y,e[19]=a,e[20]=j):j=e[20],j},wd=s=>{const e=Ye.c(67),{status:n,localBranches:r,remoteBranches:o,branchInfo:a,syncAction:i,remotes:u,onFetch:f,onSync:h,onRemoveRemote:c,removingRemoteName:g,onCheckoutBranch:p,onCreateBranch:x,onRenameBranch:d,activeIdentityProfile:y,availableIdentities:j,onSelectIdentity:T,isApplyingIdentity:R,isWorktreeMode:M,onOpenHistory:G,onOpenGraph:w,onOpenStashes:k,onOpenUpdateBranch:I,onOpenReintegrateCommits:F,pullRequest:re,prChecks:te,onOpenPullRequest:L}=s,{t:V}=rt();if(!n)return null;let z;e[0]!==w||e[1]!==G||e[2]!==F||e[3]!==k||e[4]!==I||e[5]!==V?(z=G||w||k||I?t.jsxs(Pt,{children:[t.jsxs(Mt,{children:[t.jsx(Lt,{asChild:!0,children:t.jsx(Dt,{asChild:!0,children:t.jsx(Ne,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0","aria-label":V("gitView.header.repositoryViews"),children:t.jsx(C,{name:"more-fill",className:"size-4"})})})}),t.jsx(Ft,{sideOffset:8,children:V("gitView.header.repositoryViews")})]}),t.jsxs(Et,{align:"end",children:[G?t.jsxs(jt,{onSelect:G,children:[t.jsx(C,{name:"history",className:"size-4"}),V("gitView.history.title")]}):null,w?t.jsxs(jt,{onSelect:w,children:[t.jsx(C,{name:"git-branch",className:"size-4"}),V("gitView.graph.title")]}):null,k?t.jsxs(jt,{onSelect:k,children:[t.jsx(C,{name:"archive-stack",className:"size-4"}),V("gitView.stashes.title")]}):null,I?t.jsxs(jt,{onSelect:I,children:[t.jsx(C,{name:"git-merge",className:"size-4"}),V("gitView.header.updateBranch")]}):null,F?t.jsxs(jt,{onSelect:F,children:[t.jsx(C,{name:"split-cells-horizontal",className:"size-4"}),V("gitView.integrate.title")]}):null]})]}):null,e[0]=w,e[1]=G,e[2]=F,e[3]=k,e[4]=I,e[5]=V,e[6]=z):z=e[6];let ne;e[7]!==z?(ne=t.jsx("div",{className:"flex items-center gap-1 shrink-0",children:z}),e[7]=z,e[8]=ne):ne=e[8];const W=ne,de=te?te.state==="success"?"var(--status-success)":te.state==="failure"?"var(--status-error)":"var(--status-warning)":null,_=re?re.state==="merged"?"merged":re.state==="closed"?"closed":re.draft?"draft":te?.state==="failure"||re.mergeable===!1||re.mergeableState==="blocked"||re.mergeableState==="dirty"?"blocked":"open":null;let O;e[9]!==L||e[10]!==de||e[11]!==_||e[12]!==re||e[13]!==V?(O=re&&L?t.jsxs(Mt,{children:[t.jsx(Lt,{asChild:!0,children:t.jsxs(Ne,{variant:"ghost",size:"sm",onClick:L,className:"h-8 gap-1.5 px-2 typography-micro",children:[t.jsx(C,{name:"git-pull-request",className:"size-3.5",style:{color:`var(--pr-${_})`}}),t.jsx("span",{className:"tabular-nums text-foreground/80",children:V("gitView.pr.numberLabel",{number:re.number})}),de?t.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:de}}):null]})}),t.jsx(Ft,{sideOffset:8,children:V("gitView.header.openPullRequest")})]}):null,e[9]=L,e[10]=de,e[11]=_,e[12]=re,e[13]=V,e[14]=O):O=e[14];const E=O,A=!n;let U;e[15]!==n.tracking?(U=n.tracking?.split("/")[0],e[15]=n.tracking,e[16]=U):U=e[16];const H=(n.files?.length??0)>0;let D;e[17]!==f||e[18]!==c||e[19]!==h||e[20]!==u||e[21]!==g||e[22]!==n.ahead||e[23]!==n.behind||e[24]!==i||e[25]!==A||e[26]!==U||e[27]!==H?(D=t.jsx(Ol,{syncAction:i,remotes:u,onFetch:f,onSync:h,onRemoveRemote:c,removingRemoteName:g,disabled:A,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:U,hasUncommittedChanges:H}),e[17]=f,e[18]=c,e[19]=h,e[20]=u,e[21]=g,e[22]=n.ahead,e[23]=n.behind,e[24]=i,e[25]=A,e[26]=U,e[27]=H,e[28]=D):D=e[28];const se=D;let ue;e[29]!==n.tracking||e[30]!==n.upstreamComparison?(ue=n.upstreamComparison?t.jsx(zl,{comparison:n.upstreamComparison,trackingBranch:n.tracking,tooltipDelayMs:1e3}):null,e[29]=n.tracking,e[30]=n.upstreamComparison,e[31]=ue):ue=e[31];const he=ue;let Ce;e[32]!==y||e[33]!==j||e[34]!==R||e[35]!==T?(Ce=t.jsx(yr,{activeProfile:y,identities:j,onSelect:T,isApplying:R,iconOnly:!0}),e[32]=y,e[33]=j,e[34]=R,e[35]=T,e[36]=Ce):Ce=e[36];const ke=Ce;let Y;e[37]!==a||e[38]!==M||e[39]!==r||e[40]!==p||e[41]!==x||e[42]!==d||e[43]!==o||e[44]!==u||e[45]!==n.current?(Y=t.jsx("div",{className:"min-w-0 flex-1",children:M?t.jsx(Fl,{currentBranch:n.current,onRename:d}):t.jsx(Ml,{currentBranch:n.current,localBranches:r,remoteBranches:o,branchInfo:a,onCheckout:p,onCreate:x,remotes:u})}),e[37]=a,e[38]=M,e[39]=r,e[40]=p,e[41]=x,e[42]=d,e[43]=o,e[44]=u,e[45]=n.current,e[46]=Y):Y=e[46];let be;e[47]!==ke?(be=t.jsx("div",{className:"flex shrink-0 items-center gap-1",children:ke}),e[47]=ke,e[48]=be):be=e[48];let $;e[49]!==Y||e[50]!==be?($=t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[Y,be]}),e[49]=Y,e[50]=be,e[51]=$):$=e[51];let le;e[52]!==E?(le=E?t.jsx("div",{className:"shrink-0",children:E}):null,e[52]=E,e[53]=le):le=e[53];let K;e[54]===Symbol.for("react.memo_cache_sentinel")?(K=t.jsx("div",{className:"min-w-0 flex-1"}),e[54]=K):K=e[54];let oe;e[55]!==he?(oe=he?t.jsx("div",{className:"min-w-0 shrink",children:he}):null,e[55]=he,e[56]=oe):oe=e[56];let ce;e[57]!==se?(ce=t.jsx("div",{className:"shrink-0",children:se}),e[57]=se,e[58]=ce):ce=e[58];let pe;e[59]!==W||e[60]!==le||e[61]!==oe||e[62]!==ce?(pe=t.jsxs("div",{className:"mt-3 flex h-8 min-w-0 items-center gap-2",children:[le,K,oe,W,ce]}),e[59]=W,e[60]=le,e[61]=oe,e[62]=ce,e[63]=pe):pe=e[63];let P;return e[64]!==$||e[65]!==pe?(P=t.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[$,pe]}),e[64]=$,e[65]=pe,e[66]=P):P=e[66],P},$l=s=>s==="/",ps=s=>s.replace(/\\/g,"/"),qs=s=>{if(!s||$l(s))return s;let e=s;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},Gt=s=>s.endsWith("/"),Vl=s=>{const e=s.trim();return!e||Gt(e)?e:`${e}/`},Ys=s=>s.lastIndexOf("/"),wr=s=>{if(Gt(s))return s;const e=Ys(s);return e<0?s:s.slice(0,e+1)},_l=s=>{const e=Ys(s);return s.slice(e+1)},vr=s=>{const e=qs(s.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=Ys(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},Gl=s=>Gt(s)&&vr(s)!==null,Hl=(s,e)=>`${wr(s)}${e}/`,At=s=>{if(!s)return null;const e=qs(ps(s.trim()));return e?e.toLowerCase():null},Dn=(s,e)=>{const n=s.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},Kl=s=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey,js=s=>{if(!s)return;s.focus({preventScroll:!0});const e=s.value.length;s.setSelectionRange(e,e),s.scrollLeft=s.scrollWidth},ql=async()=>{try{const s=await Nt("/api/fs/home",{method:"GET",headers:{Accept:"application/json"}});if(s.ok){const e=await s.json();if(typeof e.home=="string"&&e.home.trim().length>0)return ps(e.home.trim())}}catch{}return _t.getFilesystemHome().catch(()=>null)},vd=({open:s,onOpenChange:e})=>{const{t:n}=rt(),r=ns(N=>N.homeDirectory),o=gt(N=>N.projects),a=gt(N=>N.addProject),i=Ae(N=>N.setActiveMainTab),u=Ae(N=>N.setSessionSwitcherOpen),f=nt(N=>N.openNewSessionDraft),h=Bt(N=>N.profiles),c=Bt(N=>N.globalIdentity),g=Bt(N=>N.defaultGitIdentityId),p=Bt(N=>N.loadProfiles),x=Bt(N=>N.loadGlobalIdentity),d=Bt(N=>N.loadDefaultGitIdentityId),{canRequestAccess:y,requestAccess:j,startAccessing:T}=Al(),{isMobile:R}=xs(),M=l.useRef(null),G=l.useRef(null),w=l.useRef(new Map),[k,I]=l.useState(""),[F,re]=l.useState("~/"),[te,L]=l.useState([]),[V,z]=l.useState(!1),[ne,W]=l.useState(!1),[de,_]=l.useState(null),[O,E]=l.useState(0),[A,U]=l.useState(0),[H,D]=l.useState(!1),[se,ue]=l.useState(!1),[he,Ce]=l.useState(0),[ke,Y]=l.useState(!1),[be,$]=l.useState(""),[le,K]=l.useState(null),[oe,ce]=l.useState(!1),pe=k||r,P=l.useMemo(()=>new Set(o.map(N=>At(N.path)).filter(N=>!!N)),[o]);l.useEffect(()=>{if(!s)return;re("~/"),L([]),U(0),D(!1),ue(!1),Y(!1),$(""),K(null),ce(!1),requestAnimationFrame(()=>js(M.current));let N=!1;return(async()=>{const Ie=await ql();N||(I(Ie||r||""),requestAnimationFrame(()=>js(M.current)))})(),()=>{N=!0}},[r,s]),l.useEffect(()=>{s&&(p(),x(),d())},[d,p,x,s]);const B=l.useMemo(()=>{const N=new Map;c&&N.set(c.id,c);for(const we of h)N.set(we.id,we);return Array.from(N.values())},[h,c]);l.useEffect(()=>{if(!s||!ke||le!==null)return;const N=typeof g=="string"?g.trim():"";if(N&&B.some(Ie=>Ie.id===N)){K(N);return}const we=B.find(Ie=>Ie.authType==="ssh"||Ie.sshKey);we&&K(we.id)},[B,g,ke,s,le]);const Q=l.useMemo(()=>B.find(N=>N.id===le)??null,[B,le]),me=l.useMemo(()=>wr(F),[F]),ee=l.useMemo(()=>Gt(F)?"":_l(F),[F]),Se=l.useMemo(()=>pe?Dn(me,pe):"",[me,pe]);l.useEffect(()=>{if(!s||!Se){L([]),_(null);return}let N=!1;return z(!0),W(!1),_(null),_t.listLocalDirectory(Se).then(we=>{if(N)return;W(!1),_(null);const Ie=we.filter(Fe=>Fe.isDirectory).map(Fe=>({name:Fe.name,path:ps(Fe.path)})).sort((Fe,st)=>Fe.name.localeCompare(st.name));L(Ie)}).catch(we=>{if(!N){L([]);const Ie=Na(we)?we.reason:"unknown";_(Ie),W(Ie==="not-found")}}).finally(()=>{N||z(!1)}),()=>{N=!0}},[Se,O,s]);const Te=l.useMemo(()=>{const N=ee.toLowerCase(),we=oe||ee.startsWith(".");return te.filter(Ie=>Ie.name.toLowerCase().startsWith(N)&&(we||!Ie.name.startsWith(".")))},[ee,te,oe]),De=l.useMemo(()=>{const N=[];Gl(F)&&N.push({type:"up",value:"browse:up",name:"..",path:vr(F)});for(const we of Te){const Ie=At(we.path);N.push({type:"directory",value:`browse:${we.path}`,name:we.name,path:we.path,disabled:!!(Ie&&P.has(Ie))})}return N},[P,Te,F]);l.useEffect(()=>{U(0)},[F,De.length]);const Ue=l.useMemo(()=>pe?qs(Dn(F,pe)):"",[pe,F]),Ve=At(Ue),Me=!!(Ve&&P.has(Ve)),Ze=l.useMemo(()=>ee?Te.find(N=>N.name===ee)??null:null,[ee,Te]),Ee=!!(Ue&&!Me&&(de===null||de==="not-found")&&(Gt(F)&&ne||!Gt(F)&&ee.trim().length>0&&Ze===null)),Ge=!H&&!se&&!Me&&de!=="os-permission"&&de!=="invalid-response"&&de!=="unknown"&&!!Ue,Le=Ge&&be.trim().length>0,$e=De[A]??null,Je=!!($e&&($e.type==="up"||$e.type==="directory"&&!$e.disabled)),Be=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Qe=n(Me?"directoryExplorerDialog.actions.alreadyAdded":ke?H?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":H?"directoryExplorerDialog.actions.adding":Ee?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const N=G.current;if(!N)return;const we=()=>Ce(Math.ceil(N.getBoundingClientRect().width));if(we(),typeof ResizeObserver>"u")return;const Ie=new ResizeObserver(we);return Ie.observe(N),()=>Ie.disconnect()},[Qe]),l.useLayoutEffect(()=>{const N=M.current;N&&(N.scrollLeft=N.scrollWidth)},[he,F]),l.useLayoutEffect(()=>{s&&js(M.current)},[s]),l.useLayoutEffect(()=>{const N=De[A];N&&w.current.get(N.value)?.scrollIntoView({block:"nearest"})},[A,De]);const He=l.useCallback(()=>{e(!1)},[e]),Pe=l.useCallback((N,we)=>{i("chat"),R&&u(!1),f({selectedProjectId:N,directoryOverride:we}),He()},[He,R,f,i,u]),et=l.useCallback((N,we)=>{N.stopPropagation();const Ie=At(we);if(Ie&&P.has(Ie))return;const Fe=a(we);if(!Fe){ve.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}Pe(Fe.id,Fe.path)},[a,P,Pe,n]),ze=l.useCallback(async N=>{if(!N||H)return;const we=At(N);if(we&&P.has(we))return;let Ie=N;D(!0);try{const Fe=!ke&&Ee&&At(N)===At(Ue);if(ke){const at=be.trim();if(!at){ve.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Ie=(await _t.cloneRepository({remoteUrl:at,destinationPath:N,gitIdentityId:Q?.id??null})).path}else Fe&&await _t.createDirectory(N,{asProject:!0});const st=a(Ie);if(!st){ve.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}Pe(st.id,st.path)}catch(Fe){ve.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Fe instanceof Error?Fe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{D(!1)}},[a,P,be,ke,H,Pe,Q?.id,Ee,Ue,n]),b=l.useCallback(N=>{re(Vl(N))},[]),X=l.useCallback(N=>{re(Hl(F,N.name))},[F]),m=l.useCallback(N=>{if(N){if(N.type==="up"){N.path&&b(N.path);return}N.disabled||X(N)}},[b,X]),v=l.useCallback(async()=>{if(!(!y||se)){ue(!0);try{const N=await j(Ue);if(!N.success||!N.path){N.error&&N.error!=="Directory selection cancelled"&&ve.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:N.error});return}const we=await T(N.path);if(!we.success){ve.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:we.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await ze(N.path)}catch(N){ve.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:N instanceof Error?N.message:n("directoryExplorerDialog.toast.unknownError")})}finally{ue(!1)}}},[y,ze,se,j,T,n,Ue]),Z=l.useCallback(N=>{if(N.key==="ArrowDown"){N.preventDefault(),U(we=>Math.min(De.length-1,we+1));return}if(N.key==="ArrowUp"){N.preventDefault(),U(we=>Math.max(0,we-1));return}if(N.key==="Enter"){if(N.preventDefault(),Kl(N)){ze(Ue);return}Je&&m($e);return}N.key==="Backspace"&&F===""&&(N.preventDefault(),He())},[m,ze,He,Je,$e,F,De.length,Ue]),ye=t.jsxs("button",{type:"button",onClick:()=>ce(N=>!N),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[oe?t.jsx(C,{name:"checkbox",className:"h-4 w-4 text-primary"}):t.jsx(C,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),xe=t.jsxs("div",{className:"px-2.5 py-1.5",children:[ke?t.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[t.jsx(ht,{value:be,onChange:N=>$(N.target.value),placeholder:n("directoryExplorerDialog.clone.remoteUrlPlaceholder"),className:"min-w-0 flex-1 border-border/60 bg-[var(--surface-elevated)] font-mono typography-ui-label shadow-none",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),t.jsx(yr,{activeProfile:Q,identities:B,onSelect:N=>K(N.id),isApplying:H,iconOnly:!0})]}):null,t.jsxs("div",{className:"relative",children:[t.jsx(C,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),t.jsx(ht,{ref:M,value:F,onChange:N=>re(ps(N.target.value)),onKeyDown:Z,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!R&&he>0?{paddingRight:`${he+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),R?null:t.jsx(Ne,{ref:G,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:ke?!Le:!Ge,onMouseDown:N=>N.preventDefault(),onClick:()=>{ze(Ue)},title:Qe,children:Qe})]})]}),Oe=t.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:t.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[t.jsx("div",{className:"px-2 pb-1 pt-0.5 typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),V?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):de&&de!=="not-found"?t.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-10 text-center",children:[t.jsx("div",{className:"typography-ui-label text-status-error",children:n(de==="os-permission"?"directoryExplorerDialog.browse.permissionDenied":"directoryExplorerDialog.browse.loadFailed")}),t.jsxs("div",{className:"flex items-center gap-2",children:[de==="os-permission"&&y?t.jsx(Ne,{size:"xs",onClick:()=>{v()},disabled:se,children:n("directoryExplorerDialog.browse.grantAccess")}):null,t.jsx(Ne,{variant:"outline",size:"xs",onClick:()=>E(N=>N+1),children:n("directoryExplorerDialog.browse.retry")})]})]}):De.length===0?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.empty")}):t.jsx("div",{className:"space-y-0.5",children:De.map((N,we)=>{const Ie=we===A;return t.jsxs("button",{ref:Fe=>{Fe?w.current.set(N.value,Fe):w.current.delete(N.value)},type:"button",disabled:N.type==="directory"&&N.disabled,onMouseEnter:()=>U(we),onMouseDown:Fe=>Fe.preventDefault(),onClick:()=>m(N),className:q("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ie&&"bg-interactive-selection text-interactive-selection-foreground",!Ie&&"hover:bg-interactive-hover/50",N.type==="directory"&&N.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[N.type==="up"?t.jsx(C,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):t.jsx(C,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),t.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:t.jsx("span",{className:"truncate typography-ui-label text-foreground",children:N.name})}),N.type==="directory"&&N.disabled?t.jsx("span",{className:"rounded-full border border-border/60 px-2 py-0.5 typography-meta text-muted-foreground",children:n("directoryExplorerDialog.browse.addedBadge")}):N.type==="directory"?t.jsx("button",{type:"button",onMouseDown:Fe=>Fe.stopPropagation(),onClick:Fe=>et(Fe,N.path),className:"flex-shrink-0 rounded-full p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",title:n("directoryExplorerDialog.browse.quickAdd"),children:t.jsx(C,{name:"add",className:"h-3.5 w-3.5"})}):null]},N.value)})})]})}),tt=t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[xe,Oe]}),Ke=t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(C,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),t.jsx(C,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(C,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx("span",{children:Be}),t.jsx(C,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),Re=()=>t.jsxs(t.Fragment,{children:[R?null:Ke,t.jsxs("div",{className:q("flex w-full flex-row justify-end gap-2 sm:w-auto",R&&"justify-stretch"),children:[y?t.jsx(Ne,{variant:"ghost",size:"xs",onClick:v,disabled:H||se||ke,children:n(se?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,t.jsx(Ne,{variant:"ghost",size:"xs",onClick:()=>Y(N=>!N),disabled:H||se,className:q(R&&"flex-1"),children:n(ke?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),R?t.jsx(Ne,{size:"xs",onClick:()=>{ze(Ue)},disabled:ke?!Le:!Ge,className:"flex-1",children:Qe}):null]})]});return R?t.jsx(Yt,{open:s,onClose:He,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px]",contentMaxHeightClassName:"flex-1",footer:t.jsx("div",{className:"flex flex-col gap-2",children:Re()}),children:t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[t.jsx("div",{className:"flex justify-end",children:ye}),tt]})}):t.jsx(Zt,{open:s,onOpenChange:e,children:t.jsxs(es,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[t.jsx(gs,{className:"px-5 pb-2 pt-5",children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{children:[t.jsx(ts,{children:n("directoryExplorerDialog.title")}),t.jsx(Bo,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),ye]})}),t.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:tt}),t.jsx(Gs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:Re()})]})})};function En(s){const{localBranches:e,remoteBranches:n,query:r}=s,o=r.trim();if(!o)return{matching:[],otherLocal:e,otherRemote:n};const a=tn(e,o,c=>c),i=tn(n,o,c=>c),u=[],f=a.other,h=i.other;for(const c of a.matching)u.push({label:c,value:c,source:"local"});for(const c of i.matching)u.push({label:c,value:`remotes/${c}`,source:"remote"});return u.sort((c,g)=>{const p=c.label.localeCompare(g.label,void 0,{sensitivity:"accent"});return p!==0?p:c.source!==g.source?c.source.localeCompare(g.source):c.value.localeCompare(g.value)}),{matching:u,otherLocal:f,otherRemote:h}}const Ns="oc:lastWorktreeSourceBranch",Yl=({mode:s,sourceBranch:e,linkedPr:n,selectedBranch:r})=>s==="existing-branch"?r||null:n?null:e||null,Jl=({branches:s,savedSourceBranch:e,rootBranch:n})=>!!(e&&s.includes(e))&&e?{sourceBranch:e,shouldClearSavedSourceBranch:!1}:{sourceBranch:n&&s.includes(n)?n:s.includes("main")?"main":s.includes("master")?"master":s[0]??"",shouldClearSavedSourceBranch:!!e};function Ql({open:s,onOpenChange:e,onSelect:n}){const{t:r}=rt(),o=Ae(P=>P.isMobile),{github:a}=Hs(),i=hs(P=>P.status),u=hs(P=>P.hasChecked),f=Ae(P=>P.setSettingsDialogOpen),h=Ae(P=>P.setSettingsPage),c=gt(P=>P.getActiveProject()),g=c?.path??null,p=J.useMemo(()=>g&&c?{id:c.id,path:g}:null,[c,g]),[x,d]=J.useState("issues"),[y,j]=J.useState(""),[T,R]=J.useState([]),[M,G]=J.useState([]),[w,k]=J.useState(!1),[I,F]=J.useState(!1),[re,te]=J.useState(null),[L,V]=J.useState(null),[z,ne]=J.useState(null),[W,de]=J.useState(!1),[_,O]=J.useState(new Map),[E,A]=J.useState(1),[U,H]=J.useState(!1),D=Mo(y,350),se=J.useCallback(async P=>{if(!(!g||!a)&&!(u&&i?.connected===!1)){k(!0),te(null),A(1),H(!1);try{if(x==="issues"&&a.issuesList){const B=await a.issuesList(g,{page:1,query:P});B.connected===!1?(te(r("session.githubIntegration.error.notConnected")),R([])):(R(B.issues??[]),A(B.page??1),H(!!B.hasMore))}else if(x==="prs"&&a.prsList){const B=await a.prsList(g,{page:1,query:P});B.connected===!1?(te(r("session.githubIntegration.error.notConnected")),G([])):(G(B.prs??[]),A(B.page??1),H(!!B.hasMore))}}catch(B){te(B instanceof Error?B.message:r("session.githubIntegration.error.loadDataFailed"))}finally{k(!1)}}},[g,a,u,i,x,r]);J.useEffect(()=>{if(!s||!g||u&&i?.connected===!1||!a)return;if(!D.trim()){se();return}const P=new AbortController;k(!0),te(null),A(1),H(!1);const B=x==="issues"&&a.issuesList?a.issuesList(g,{page:1,query:D.trim()}):x==="prs"&&a.prsList?a.prsList(g,{page:1,query:D.trim()}):null;if(!B){k(!1);return}return B.then(Q=>{P.signal.aborted||("issues"in Q?Q.connected===!1?(te(r("session.githubIntegration.error.notConnected")),R([])):(R(Q.issues??[]),A(Q.page??1),H(!!Q.hasMore)):"prs"in Q&&(Q.connected===!1?(te(r("session.githubIntegration.error.notConnected")),G([])):(G(Q.prs??[]),A(Q.page??1),H(!!Q.hasMore))))}).catch(Q=>{P.signal.aborted||te(Q instanceof Error?Q.message:r("session.githubIntegration.error.loadDataFailed"))}).finally(()=>{P.signal.aborted||k(!1)}),()=>P.abort()},[s,g,a,u,i,x,D,se,r]);const ue=J.useCallback(async()=>{if(!(!g||!a)&&!(w||I)&&U){F(!0);try{const P=E+1;if(x==="issues"&&a.issuesList){const B=D.trim()?await a.issuesList(g,{page:P,query:D.trim()}):await a.issuesList(g,{page:P});B.connected!==!1&&(R(Q=>[...Q,...B.issues??[]]),A(B.page??P),H(!!B.hasMore))}else if(x==="prs"&&a.prsList){const B=D.trim()?await a.prsList(g,{page:P,query:D.trim()}):await a.prsList(g,{page:P});B.connected!==!1&&(G(Q=>[...Q,...B.prs??[]]),A(B.page??P),H(!!B.hasMore))}}catch{}finally{F(!1)}}},[g,a,x,E,U,w,I,D]);J.useEffect(()=>{if(!s){d("issues"),j(""),R([]),G([]),V(null),ne(null),de(!1),te(null),O(new Map),A(1),H(!1);return}se()},[s,se]);const he=J.useCallback(async P=>{if(!(!p||!P)&&!_.has(P))try{const Q=(await Hn(p,{mode:"new",branchName:P,worktreeName:P})).errors.find(me=>me.code==="branch_in_use");O(me=>new Map(me).set(P,{isValid:!Q,error:Q?r(Q.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{O(B=>new Map(B).set(P,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[p,_,r]);J.useEffect(()=>{!s||x!=="prs"||M.forEach(P=>{P.head&&he(P.head)})},[s,x,M,he]);const Ce=u&&i?.connected===!0,ke=()=>{h("github"),f(!0)},Y=P=>{V(P),ne(null)},be=P=>{ne(P),V(null)},$=()=>{L?n({type:"issue",item:L}):z&&n({type:"pr",item:z,includeDiff:W}),e(!1)},le=()=>{V(null),ne(null),de(!1)},K=L||z&&_.get(z.head??"")?.isValid!==!1,oe=P=>P.head?_.get(P.head)?.isValid===!1:!0,ce=t.jsx(t.Fragment,{children:Ce?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative mt-2",children:[t.jsx(C,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),t.jsx(ht,{value:y,onChange:P=>j(P.target.value),placeholder:r(x==="issues"?"session.githubIntegration.search.issuesPlaceholder":"session.githubIntegration.search.prsPlaceholder"),className:"h-8 pl-9"})]}),t.jsx("div",{className:"mt-2 h-[300px] overflow-hidden",children:t.jsxs("div",{className:"h-full overflow-y-auto",children:[w&&t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsx(C,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}),re&&t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive",children:[t.jsx(C,{name:"error-warning",className:"h-4 w-4"}),t.jsx("span",{className:"typography-small",children:re})]})}),!w&&!re&&x==="issues"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[T.length>0?T.map(P=>t.jsx("button",{onClick:()=>Y(P),className:q("w-full text-left px-2 py-1.5 rounded transition-colors",L?.number===P.number?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",P.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-2",children:P.title}),P.sourceRepo?.source==="upstream"?t.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block",children:[P.sourceRepo.owner,"/",P.sourceRepo.repo]}):null]})]})},`${P.sourceRepo?.owner??""}-${P.sourceRepo?.repo??""}-${P.number}`)):t.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noIssuesFound")}),U&&!I&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(Ne,{variant:"ghost",size:"sm",onClick:()=>{ue()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),I&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!w&&!re&&x==="prs"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[M.length>0?M.map(P=>{const B=oe(P),Q=P.head?_.get(P.head):void 0;return t.jsx("button",{onClick:()=>!B&&be(P),disabled:B,className:q("w-full text-left px-2 py-1.5 rounded transition-colors",z?.number===P.number?"bg-interactive-selection text-interactive-selection-foreground":B?"opacity-50 cursor-not-allowed":"hover:bg-interactive-hover"),children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",P.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-1",children:P.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[P.head," → ",P.base]}),P.sourceRepo?.source==="upstream"?t.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[P.sourceRepo.owner,"/",P.sourceRepo.repo]}):null,B&&Q?.error&&t.jsx("span",{className:"typography-micro text-destructive",children:Q.error})]})]})]})},`${P.sourceRepo?.owner??""}-${P.sourceRepo?.repo??""}-${P.number}`)}):t.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noPullRequestsFound")}),U&&!I&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(Ne,{variant:"ghost",size:"sm",onClick:()=>{ue()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),I&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]})]})})]}):t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 gap-4",children:[t.jsx(C,{name:"github",className:"h-12 w-12 text-muted-foreground"}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:r("session.githubIntegration.connect.title")}),t.jsx("p",{className:"typography-small text-muted-foreground mt-1",children:r("session.githubIntegration.connect.description")})]}),t.jsx(Ne,{onClick:ke,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),pe=t.jsxs("div",{className:q("w-full",o?"flex flex-col gap-2":"flex flex-row items-center"),children:[t.jsxs("div",{className:q("flex items-center gap-4",o?"w-full justify-center order-1":"flex-1"),children:[!o&&(L||z)&&t.jsxs("div",{className:"flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50",children:[t.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),t.jsx("span",{className:"typography-small truncate max-w-[150px]",children:L?r("session.githubIntegration.selected.issueNumber",{number:L.number}):r("session.githubIntegration.selected.prNumber",{number:z?.number??""})}),t.jsx("button",{onClick:le,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]}),x==="prs"&&z&&t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[t.jsx(ss,{checked:W,onChange:P=>de(P),ariaLabel:r("session.githubIntegration.includeDiffAria")}),t.jsx("span",{className:"typography-small text-foreground",children:r("session.githubIntegration.includeDiff")})]})]}),t.jsxs("div",{className:q("flex gap-2",o?"w-full order-2":"justify-end"),children:[t.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e(!1),className:q(o&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),t.jsx(Ne,{size:"sm",onClick:$,disabled:!K,className:q(o&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return t.jsx(t.Fragment,{children:o?t.jsx(Yt,{open:s,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:Ce?pe:void 0,renderHeader:P=>t.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2 border-b border-border/40",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:r("session.githubIntegration.title")}),P]}),t.jsx("div",{className:"w-full",children:t.jsx(Qt,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:t.jsx(C,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:t.jsx(C,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:x,onSelect:B=>{d(B),j("")},variant:"active-pill",layoutMode:"fit"})}),(L||z)&&t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50",children:[t.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),t.jsx("span",{className:"typography-small truncate flex-1",children:L?r("session.githubIntegration.selected.issueNumber",{number:L.number}):r("session.githubIntegration.selected.prNumber",{number:z?.number??""})}),t.jsx("button",{onClick:le,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:ce}):t.jsx(Zt,{open:s,onOpenChange:e,children:t.jsxs(es,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsx(gs,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(ts,{className:"flex items-center gap-2 shrink-0",children:[t.jsx(C,{name:"github",className:"h-5 w-5"}),r("session.githubIntegration.title")]}),t.jsx("div",{className:"w-[220px]",children:t.jsx(Qt,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:t.jsx(C,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:t.jsx(C,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:x,onSelect:P=>{d(P),j("")},variant:"active-pill",layoutMode:"fit"})})]})}),ce,t.jsx(Gs,{className:"mt-1",children:pe})]})})})}const qt=s=>s.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),lt=s=>s.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,"").split("/").join("-").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"").slice(0,80),Xl=s=>String(s).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",Rn=(s,e,n)=>{const r=qt(s.head||"");if(!r)throw new Error("PR head branch is missing");if(e.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};const o=n.find(h=>{const c=h.indexOf("/");return c<=0||c>=h.length-1?!1:h.slice(c+1)===r});if(o){const h=o.indexOf("/"),c=o.slice(0,h);return{existingBranch:`remotes/${o}`,setUpstream:!0,upstreamRemote:c,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${c}/${r}`}}const a=String(s.headLabel||"").split(":")[0]?.trim(),i=s.headRepo?.owner||a||"pr-head",u=`pr-${Xl(i)}`,f=s.headRepo?.sshUrl||s.headRepo?.cloneUrl||"";if(!f)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${u}/${r}`,setUpstream:!0,upstreamRemote:u,upstreamBranch:r,ensureRemoteName:u,ensureRemoteUrl:f,sourceLabel:`${u}/${r}`}},Zl=s=>{const e={repo:s.repo??null,issue:s.issue,comments:s.comments};return`GitHub issue context (JSON)
|
|
3
|
+
${JSON.stringify(e,null,2)}`},ec=s=>`GitHub pull request context (JSON)
|
|
4
|
+
${JSON.stringify(s,null,2)}`;function kd({open:s,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=rt(),{github:o,git:a}=Hs(),i=Ae(m=>m.isMobile),u=hs(m=>m.status),f=hs(m=>m.hasChecked),h=gt(m=>m.getActiveProject()),c=h?.path??null,g=J.useMemo(()=>c&&h?{id:h.id,path:c}:null,[h,c]),[p,x]=J.useState("new-branch"),[d,y]=J.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[j,T]=J.useState({selectedBranch:"",worktreeName:""}),R=Lo(c),M=Fo(c),G=Ks(m=>m.fetchBranches),w=J.useMemo(()=>R?.all?R.all.filter(m=>!m.startsWith("remotes/")).sort():[],[R]),k=J.useMemo(()=>R?.all?R.all.filter(m=>m.startsWith("remotes/")).map(m=>m.replace(/^remotes\//,"")).sort():[],[R]),I=nt(m=>m.availableWorktreesByProject),F=J.useMemo(()=>{if(!c)return new Set;const m=I.get(c)??[];return new Set(m.map(v=>v.name))},[I,c]),re=J.useCallback((m=10)=>{for(let v=0;v<m;v++){const Z=ys();if(!F.has(Z))return Z}return`${ys()}-${Date.now().toString(36).slice(-4)}`},[F]),[te,L]=J.useState(!1),[V,z]=J.useState(!1),[ne,W]=J.useState(!1),[de,_]=J.useState(!1),[O,E]=J.useState(!1),[A,U]=J.useState(""),[H,D]=J.useState(""),se=J.useRef(null),ue=J.useRef(null),he=J.useRef(null),Ce=J.useRef(null),ke=J.useCallback(m=>{m.stopPropagation()},[]),Y=J.useCallback(m=>{let v=m;for(;v&&v!==document.body;){const{overflowY:Z}=window.getComputedStyle(v);if((Z==="auto"||Z==="scroll")&&v.scrollHeight>v.clientHeight)return v;v=v.parentElement}return null},[]),be=J.useCallback(m=>{m&&(m.scrollTop=0)},[]),$=J.useCallback(m=>{const v=m.current?.querySelector('[data-slot="command-list"]')??null;be(v)},[be]),le=J.useCallback(m=>{const v=Y(m.current);be(v)},[Y,be]),K=J.useMemo(()=>En({localBranches:w,remoteBranches:k,query:A}),[w,k,A]),oe=J.useMemo(()=>En({localBranches:w,remoteBranches:k,query:H}),[w,k,H]),ce=A.trim().length>0,pe=H.trim().length>0,P=K.matching.length>0,B=oe.matching.length>0,Q=!!(c&&a),me=J.useCallback(()=>{!c||!a||G(c,a)},[c,a,G]);J.useEffect(()=>{!s||!c||!a||R?.all||G(c,a)},[s,c,a,R?.all,G]),J.useEffect(()=>{!V&&!de&&U("")},[V,de]),J.useEffect(()=>{!ne&&!O&&D("")},[ne,O]),J.useEffect(()=>{V&&$(se),de&&le(he)},[V,de,A,$,le]),J.useEffect(()=>{ne&&$(ue),O&&le(Ce)},[ne,O,H,$,le]);const[ee,Se]=J.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[Te,De]=J.useState(!1),[Ue,Ve]=J.useState(null),Me=J.useCallback(()=>{const m=pt.getState(),v=m.getVisibleAgents();if(m.settingsDefaultAgent){const Z=v.find(ye=>ye.name===m.settingsDefaultAgent);if(Z)return Z.name}return v.find(Z=>Z.name==="build")?.name||v[0]?.name},[]),Ze=J.useCallback(()=>{const m=pt.getState(),v=m.settingsDefaultModel;if(!v)return null;const Z=Gn(v);if(!Z)return null;const{providerId:ye,modelId:xe}=Z;return m.getModelMetadata(ye,xe)?{providerID:ye,modelID:xe}:null},[]),Ee=J.useCallback((m,v)=>{const Z=pt.getState(),ye=Z.settingsDefaultVariant,xe=Z.currentProviderId===m&&Z.currentModelId===v?Z.currentVariant:void 0,Ke=Z.providers.find(Re=>Re.id===m)?.models.find(Re=>Re.id===v)?.variants;if(!Ke)return ye||xe||void 0;if(ye&&Object.prototype.hasOwnProperty.call(Ke,ye))return ye;if(xe&&Object.prototype.hasOwnProperty.call(Ke,xe))return xe},[]),Ge=J.useCallback(async m=>{if(!c||!o)return;const v=pt.getState(),Z=Kn.getState().lastUsedProvider,ye=Ze(),xe=ye?.providerID||v.currentProviderId||Z?.providerID,Oe=ye?.modelID||v.currentModelId||Z?.modelID,tt=Me()||v.currentAgentName||void 0;if(!xe||!Oe){ve.error(r("session.newWorktree.error.noModelSelected"));return}const Ke=Ee(xe,Oe);if(m.issue){if(!o.issueGet||!o.issueComments)return;const Re=await o.issueGet(c,m.issue.number,{sourceRepo:m.issue.sourceRepo??null});if(Re.connected===!1||!Re.repo||!Re.issue)throw new Error("Failed to load issue context");const N=await o.issueComments(c,m.issue.number,{sourceRepo:m.issue.sourceRepo??null});if(N.connected===!1)throw new Error("Failed to load issue comments");const we=await $t("github.issue.review.visible",{issue_number:String(m.issue.number)}),Ie=await $t("github.issue.review.instructions"),Fe=Zl({repo:Re.repo,issue:Re.issue,comments:N.comments??[]});await nt.getState().sendMessage(we,xe,Oe,tt,void 0,void 0,[{text:Ie,synthetic:!0},{text:Fe,synthetic:!0}],Ke,void 0,{sessionId:m.sessionId}),sn(m.sessionId,m.directory,nn({url:Re.issue.url,number:Re.issue.number,title:Re.issue.title,kind:"issue",author:Re.issue.author,linkedAt:Date.now()}),!0).catch(()=>{}),ve.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(m.pr){if(!o.prContext)return;const Re=await o.prContext(c,m.pr.number,{sourceRepo:m.pr.sourceRepo??null,includeDiff:m.includeDiff,includeCheckDetails:!1});if(Re.connected===!1||!Re.repo||!Re.pr)throw new Error("Failed to load PR context");const N=await $t("github.pr.review.visible",{pr_number:String(m.pr.number)}),we=await $t("github.pr.review.instructions"),Ie=ec(Re);await nt.getState().sendMessage(N,xe,Oe,tt,void 0,void 0,[{text:we,synthetic:!0},{text:Ie,synthetic:!0}],Ke,void 0,{sessionId:m.sessionId}),sn(m.sessionId,m.directory,nn({url:Re.pr.url,number:Re.pr.number,title:Re.pr.title,kind:"pull",author:Re.pr.author,linkedAt:Date.now()}),!0).catch(()=>{}),ve.success(r("session.newWorktree.toast.sessionFromPr"))}},[o,c,Me,Ze,Ee,r]),Le=p==="new-branch"?d:j;J.useEffect(()=>{if(!s||!R?.all||!c||d.sourceBranch)return;const m=d.sourceBranch;let v=!1;return(async()=>{try{const ye=await Oo(c).catch(()=>null);if(v)return;const xe=localStorage.getItem(Ns),{sourceBranch:Oe,shouldClearSavedSourceBranch:tt}=Jl({branches:R.all,savedSourceBranch:xe,rootBranch:ye});if(tt&&localStorage.removeItem(Ns),v||m)return;Oe&&y(Ke=>({...Ke,sourceBranch:Oe}))}catch{}})(),()=>{v=!0}},[s,R?.all,c,d.sourceBranch]),J.useLayoutEffect(()=>{if(!s)return;x("new-branch"),T({selectedBranch:"",worktreeName:""}),z(!1),W(!1),_(!1),E(!1),U(""),D(""),Se({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const m=re();y({branchName:m,worktreeName:m,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[s,re]),J.useEffect(()=>{if(p!=="new-branch"||!d.isSyncingWorktreeName)return;const m=qt(d.branchName),v=lt(m);y(Z=>({...Z,worktreeName:v}))},[p,d.branchName,d.isSyncingWorktreeName]);const $e=J.useCallback(async()=>{if(!g||!ee.touched||Te)return;Ue&&Ue.abort();const m=new AbortController;Ve(m),Se(v=>({...v,isValidating:!0}));try{const v=p==="new-branch"?d.branchName:j.selectedBranch,Z=Le.worktreeName,ye=qt(v),xe=lt(Z);let Oe=null,tt=null;if(ye||(Oe=r("session.newWorktree.error.branchNameRequired")),xe||(tt=r("session.newWorktree.error.worktreeDirectoryRequired")),ye&&xe){const Ke=p==="new-branch"?d.linkedPr:null,Re=Ke?Rn(Ke,w,k):null,N=await Hn(g,{mode:p==="existing-branch"||Re?"existing":"new",branchName:ye,worktreeName:xe,existingBranch:Re?.existingBranch??(p==="existing-branch"?ye:void 0),...Re?.ensureRemoteName?{ensureRemoteName:Re.ensureRemoteName}:{},...Re?.ensureRemoteUrl?{ensureRemoteUrl:Re.ensureRemoteUrl}:{}});if(m.signal.aborted)return;N.ok||N.errors.forEach(we=>{if(we.code==="worktree_exists"){tt=tt??we.message;return}we.code.startsWith("branch_")&&(Oe=Oe??we.message)})}m.signal.aborted||Se(Ke=>({...Ke,isValidating:!1,branchError:Oe,worktreeError:tt}))}catch{m.signal.aborted||Se(v=>({...v,isValidating:!1}))}},[g,p,d.branchName,d.linkedPr,j.selectedBranch,Le.worktreeName,w,k,ee.touched,Ue,Te,r]),Je=p==="new-branch"?d.branchName:j.selectedBranch;J.useEffect(()=>{if(!s||!g||!ee.touched||Te)return;const m=setTimeout(()=>{$e()},300);return()=>clearTimeout(m)},[Le.worktreeName,Je,s,g,$e,ee.touched,Te]);const Be=async()=>{if(!g||!c){ve.error(r("session.newWorktree.error.noActiveProject"));return}Se(xe=>({...xe,touched:!0}));const m=p==="new-branch"?d.branchName:j.selectedBranch,v=Le.worktreeName,Z=qt(m),ye=lt(v);if(!Z){ve.error(r("session.newWorktree.error.branchNameRequired"));return}if(!ye){ve.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}Ue&&(Ue.abort(),Ve(null)),Se(xe=>({...xe,isValidating:!1,branchError:null,worktreeError:null})),De(!0);try{const xe=p==="new-branch"?d.linkedPr:null,Oe=p==="new-branch"?d.linkedIssue:null,tt=p==="new-branch"?d.linkedPr:null,Ke=p==="new-branch"?d.includePrDiff:!1,Re=!!(Oe||tt),N=await zn(g),we=d.sourceBranch;let Ie="";const Fe=(()=>{if(xe){const _e=Rn(xe,w,k);return Ie=_e.sourceLabel,{preferredName:Z||ye,mode:"existing",branchName:Z,worktreeName:ye,existingBranch:_e.existingBranch,setupCommands:N,setUpstream:_e.setUpstream,upstreamRemote:_e.upstreamRemote,upstreamBranch:_e.upstreamBranch,returnAfterDirectoryCreated:!0,..._e.ensureRemoteName?{ensureRemoteName:_e.ensureRemoteName}:{},..._e.ensureRemoteUrl?{ensureRemoteUrl:_e.ensureRemoteUrl}:{}}}return Ie=p==="new-branch"?we:"",{preferredName:Z||ye,mode:p==="existing-branch"?"existing":"new",branchName:p==="existing-branch"?void 0:Z,worktreeName:ye,existingBranch:p==="existing-branch"?Z:void 0,setupCommands:N,returnAfterDirectoryCreated:!0,...we&&p==="new-branch"?{startRef:we}:{}}})(),st=await Uo(c,Fe),at=await Wo(g,st);let ot=null;if(Re){await $n(g)&&await zo(at.path);const _e=Oe?`#${Oe.number} ${Oe.title}`.trim():tt?`#${tt.number} ${tt.title}`.trim():r("session.newWorktree.newSessionTitle"),ft=await $o(_e,at.path,null);if(!ft?.id)throw new Error("Failed to create session");ot=ft.id,n?.(at.path,{sessionId:ot}),e(!1),De(!1),Vo(ft.id,_e).catch(()=>{});try{nt.getState().initializeNewOpenChamberSession(ft.id,pt.getState().agents)}catch{}}else e(!1),De(!1);const dt=Yl({mode:p,sourceBranch:d.sourceBranch,linkedPr:!!d.linkedPr,selectedBranch:j.selectedBranch});dt&&localStorage.setItem(Ns,dt),ve.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${at.branch||at.name}${Ie?` ${r("session.newWorktree.fromSource",{source:Ie})}`:""}`})}),ot?Ge({sessionId:ot,directory:at.path,issue:Oe,pr:tt,includeDiff:Ke}).catch(_e=>{const ft=_e instanceof Error?_e.message:r("session.newWorktree.error.sendGitHubContextFailed");ve.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:ft})}):n?.(at.path)}catch(xe){const Oe=xe instanceof Error?xe.message:r("session.newWorktree.error.createWorktreeFailed");ve.error(r("session.newWorktree.error.createWorktreeFailed"),{description:Oe})}finally{De(!1)}},Qe=m=>{x(m),Se(v=>({...v,touched:!1,branchError:null,worktreeError:null}))},He=m=>{if(!m){y(v=>({...v,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(m.type==="issue"){const v=m.item,Z=`issue-${v.number}-${ys()}`;y(ye=>({...ye,linkedIssue:v,linkedPr:null,includePrDiff:!1,branchName:Z,worktreeName:lt(Z),isSyncingWorktreeName:!0}))}else if(m.type==="pr"){const v=m.item;y(Z=>({...Z,linkedPr:v,linkedIssue:null,includePrDiff:m.includeDiff??!1,branchName:v.head,worktreeName:lt(v.head),isSyncingWorktreeName:!0}))}},Pe=f&&u?.connected===!0,ze=(p==="existing-branch"?!!j.selectedBranch&&!!j.worktreeName&&!ee.branchError&&!ee.worktreeError:!!qt(d.branchName)&&!!d.worktreeName&&!ee.branchError&&!ee.worktreeError)&&!Te,b=()=>{y(m=>({...m,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},X=t.jsxs("div",{className:q("flex gap-2",i?"flex-col w-full":"flex-row items-center"),children:[t.jsx("div",{className:q("flex items-center gap-1.5 text-destructive",i?"w-full justify-center order-first":"mr-auto"),children:ee.touched&&(ee.branchError||ee.worktreeError)&&t.jsxs(t.Fragment,{children:[t.jsx(C,{name:"error-warning",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"typography-micro",children:ee.branchError||ee.worktreeError})]})}),t.jsxs("div",{className:q("flex gap-2",i&&"w-full"),children:[t.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Te,className:q(i&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),t.jsxs(Ne,{size:"sm",onClick:Be,disabled:!ze||Te,className:q("gap-1.5",i&&"flex-1"),children:[Te&&t.jsx(C,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(Te?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return t.jsxs(t.Fragment,{children:[i?t.jsxs(Yt,{open:s,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:X,children:[t.jsx("div",{className:"w-full mb-4",children:t.jsx(Qt,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:t.jsx(C,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:t.jsx(C,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:p,onSelect:m=>Qe(m),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),t.jsxs("div",{className:"space-y-6",children:[p==="existing-branch"?t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(Ne,{variant:"outline",size:"sm",onClick:()=>_(!0),className:"flex-1 justify-between h-9",children:[t.jsx("span",{className:j.selectedBranch?"text-foreground":"text-muted-foreground",children:j.selectedBranch||r("session.newWorktree.chooseBranch")}),t.jsx(C,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),t.jsx(Ne,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:me,disabled:!Q||M,title:r("session.newWorktree.fetchBranches"),children:M?t.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(C,{name:"refresh",className:"size-4"})})]}),t.jsx(Yt,{open:de,title:r("session.newWorktree.selectBranch"),onClose:()=>_(!1),children:t.jsxs("div",{className:"space-y-4",ref:he,children:[t.jsx(ht,{value:A,onChange:m=>U(m.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),M?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):w.length===0&&k.length===0?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):t.jsxs("div",{className:"space-y-4",children:[ce&&P&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),t.jsx("div",{className:"space-y-1",children:K.matching.map(m=>t.jsx("button",{onClick:()=>{T(v=>({...v,selectedBranch:m.value,worktreeName:lt(m.label)})),Se(v=>({...v,touched:!0})),_(!1)},className:q("w-full text-left px-3 py-2.5 rounded-md transition-colors",j.selectedBranch===m.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:m.label})},`${m.source}-${m.value}`))})]}),ce&&!P&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),K.otherLocal.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ce?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:K.otherLocal.map(m=>t.jsx("button",{onClick:()=>{T(v=>({...v,selectedBranch:m,worktreeName:lt(m)})),Se(v=>({...v,touched:!0})),_(!1)},className:q("w-full text-left px-3 py-2.5 rounded-md transition-colors",j.selectedBranch===m?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:m})},m))})]}),K.otherRemote.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ce?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:K.otherRemote.map(m=>t.jsx("button",{onClick:()=>{T(v=>({...v,selectedBranch:`remotes/${m}`,worktreeName:lt(m)})),Se(v=>({...v,touched:!0})),_(!1)},className:q("w-full text-left px-3 py-2.5 rounded-md transition-colors",j.selectedBranch===`remotes/${m}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:m})},`remotes/${m}`))})]})]})]})})]}):t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),p==="new-branch"&&Pe&&t.jsxs(Ne,{variant:"outline",size:"sm",onClick:()=>L(!0),className:"gap-1.5 h-7",children:[t.jsx(C,{name:"github",className:"size-4 text-status-success"}),d.linkedIssue||d.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(ht,{value:d.branchName,onChange:m=>{y(v=>({...v,branchName:m.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>Se(m=>({...m,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!d.linkedPr,className:q("h-8",ee.touched&&ee.branchError&&"border-destructive",d.linkedPr&&"bg-muted text-muted-foreground")}),d.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:d.linkedPr.head})})]}),d.linkedIssue&&!d.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:d.linkedIssue.number,title:d.linkedIssue.title})})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),p!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const m=lt(p==="new-branch"?d.branchName:"");y(v=>({...v,worktreeName:m,isSyncingWorktreeName:!0}))},disabled:!d.branchName||d.worktreeName===lt(d.branchName),className:q("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",d.worktreeName===lt(d.branchName)||!d.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[t.jsx(C,{name:"refresh",className:"h-3 w-3"}),t.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),t.jsx(ht,{value:Le.worktreeName,onChange:m=>{p==="new-branch"?y(v=>({...v,worktreeName:m.target.value,isSyncingWorktreeName:!1})):T(v=>({...v,worktreeName:m.target.value}))},onBlur:()=>Se(m=>({...m,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:q("h-8",ee.touched&&ee.worktreeError&&"border-destructive")})]}),p==="new-branch"&&!d.linkedPr&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),t.jsxs(Ne,{variant:"outline",size:"sm",onClick:()=>E(!0),className:"w-full justify-between h-9",children:[t.jsx("span",{className:d.sourceBranch?"text-foreground":"text-muted-foreground",children:d.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),t.jsx(C,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),d.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:d.sourceBranch})}),t.jsx(Yt,{open:O,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>E(!1),children:t.jsxs("div",{className:"space-y-4",ref:Ce,children:[t.jsx(ht,{value:H,onChange:m=>D(m.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),M?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):w.length===0&&k.length===0?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):t.jsxs("div",{className:"space-y-4",children:[pe&&B&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),t.jsx("div",{className:"space-y-1",children:oe.matching.map(m=>t.jsx("button",{onClick:()=>{y(v=>({...v,sourceBranch:m.value})),E(!1)},className:q("w-full text-left px-3 py-2.5 rounded-md transition-colors",d.sourceBranch===m.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:m.label})},`${m.source}-${m.value}`))})]}),pe&&!B&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),oe.otherLocal.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(pe?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:oe.otherLocal.map(m=>t.jsx("button",{onClick:()=>{y(v=>({...v,sourceBranch:m})),E(!1)},className:q("w-full text-left px-3 py-2.5 rounded-md transition-colors",d.sourceBranch===m?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:m})},m))})]}),oe.otherRemote.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(pe?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:oe.otherRemote.map(m=>t.jsx("button",{onClick:()=>{y(v=>({...v,sourceBranch:`remotes/${m}`})),E(!1)},className:q("w-full text-left px-3 py-2.5 rounded-md transition-colors",d.sourceBranch===`remotes/${m}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:m})},`remotes/${m}`))})]})]})]})})]}),(d.linkedIssue||d.linkedPr)&&p==="new-branch"&&t.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(C,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),d.linkedIssue&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:d.linkedIssue.number})}),d.linkedPr&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:d.linkedPr.number})}),t.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:d.linkedIssue?.title||d.linkedPr?.title}),t.jsx("a",{href:d.linkedIssue?.url||d.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:m=>m.stopPropagation(),children:t.jsx(C,{name:"external-link",className:"h-3 w-3"})}),t.jsx("button",{onClick:b,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]}),d.linkedPr&&t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[d.linkedPr.head," → ",d.linkedPr.base]}),d.includePrDiff&&t.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]})]}):t.jsx(Zt,{open:s,onOpenChange:e,children:t.jsxs(es,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[t.jsx(gs,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(ts,{className:"flex items-center gap-2 shrink-0",children:[t.jsx(C,{name:"git-branch",className:"h-5 w-5"}),r("session.newWorktree.title")]}),t.jsx("div",{className:"w-[280px] shrink-0",children:t.jsx(Qt,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:t.jsx(C,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:t.jsx(C,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:p,onSelect:m=>Qe(m),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),t.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[p==="existing-branch"?t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(Pt,{open:V,onOpenChange:z,children:[t.jsx(Dt,{asChild:!0,children:t.jsxs("button",{type:"button",className:q(rn({size:"default"}),"min-w-[220px] max-w-full"),children:[t.jsx("span",{className:q("truncate",j.selectedBranch?"text-foreground":"text-muted-foreground"),children:j.selectedBranch||r("session.newWorktree.chooseBranch")}),t.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),t.jsx(Et,{align:"start",sideOffset:6,portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:se,children:t.jsxs(Ms,{shouldFilter:!1,children:[t.jsx(Ls,{placeholder:r("session.newWorktree.searchBranches"),value:A,onValueChange:U,onKeyDown:ke}),t.jsx(Fs,{disableHorizontal:!0,children:M?t.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):w.length===0&&k.length===0?t.jsx(Os,{children:r("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[ce&&P&&t.jsx(Ct,{heading:r("session.newWorktree.matchingBranches"),children:K.matching.map(m=>t.jsx(yt,{value:m.value,onSelect:()=>{T(v=>({...v,selectedBranch:m.value,worktreeName:lt(m.label)})),Se(v=>({...v,touched:!0})),z(!1)},children:t.jsx("span",{className:"typography-small break-all",children:m.label})},`${m.source}-${m.value}`))}),ce&&!P&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),K.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[ce&&t.jsx(zt,{}),t.jsx(Ct,{heading:r(ce?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:K.otherLocal.map(m=>t.jsx(yt,{value:m,onSelect:()=>{T(v=>({...v,selectedBranch:m,worktreeName:lt(m)})),Se(v=>({...v,touched:!0})),z(!1)},children:t.jsx("span",{className:"typography-small break-all",children:m})},`local-${m}`))})]}),K.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(K.otherLocal.length>0||ce)&&t.jsx(zt,{}),t.jsx(Ct,{heading:r(ce?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:K.otherRemote.map(m=>t.jsx(yt,{value:`remotes/${m}`,onSelect:()=>{T(v=>({...v,selectedBranch:`remotes/${m}`,worktreeName:lt(m)})),Se(v=>({...v,touched:!0})),z(!1)},children:t.jsx("span",{className:"typography-small break-all",children:m})},`remote-${m}`))})]})]})})]})})]}),t.jsx(Ne,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:me,disabled:!Q||M,title:r("session.newWorktree.fetchBranches"),children:M?t.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(C,{name:"refresh",className:"size-4"})})]})]}):t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),p==="new-branch"&&Pe&&t.jsxs(Ne,{variant:"outline",size:"sm",onClick:()=>L(!0),className:"gap-1.5 h-7",children:[t.jsx(C,{name:"github",className:"size-4 text-status-success"}),d.linkedIssue||d.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(ht,{value:d.branchName,onChange:m=>{y(v=>({...v,branchName:m.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>Se(m=>({...m,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!d.linkedPr,className:q("h-8",ee.touched&&ee.branchError&&"border-destructive",d.linkedPr&&"bg-muted text-muted-foreground")}),d.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:d.linkedPr.head})})]}),d.linkedIssue&&!d.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:d.linkedIssue.number,title:d.linkedIssue.title})})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),p!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const m=lt(p==="new-branch"?d.branchName:"");y(v=>({...v,worktreeName:m,isSyncingWorktreeName:!0}))},disabled:!d.branchName||d.worktreeName===lt(d.branchName),className:q("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",d.worktreeName===lt(d.branchName)||!d.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[t.jsx(C,{name:"refresh",className:"h-3 w-3"}),t.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),t.jsx(ht,{value:Le.worktreeName,onChange:m=>{p==="new-branch"?y(v=>({...v,worktreeName:m.target.value,isSyncingWorktreeName:!1})):T(v=>({...v,worktreeName:m.target.value}))},onBlur:()=>Se(m=>({...m,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:q("h-8",ee.touched&&ee.worktreeError&&"border-destructive")})]}),p==="new-branch"&&!d.linkedPr&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),t.jsxs(Pt,{open:ne,onOpenChange:W,children:[t.jsx(Dt,{asChild:!0,children:t.jsxs("button",{type:"button",className:q(rn({size:"default"}),"min-w-[220px] max-w-full"),children:[t.jsx("span",{className:q("truncate",d.sourceBranch?"text-foreground":"text-muted-foreground"),children:d.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),t.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),t.jsx(Et,{align:"start",portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:ue,children:t.jsxs(Ms,{shouldFilter:!1,children:[t.jsx(Ls,{placeholder:r("session.newWorktree.searchBranches"),value:H,onValueChange:D,onKeyDown:ke}),t.jsx(Fs,{disableHorizontal:!0,children:M?t.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):w.length===0&&k.length===0?t.jsx(Os,{children:r("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[pe&&B&&t.jsx(Ct,{heading:r("session.newWorktree.matchingBranches"),children:oe.matching.map(m=>t.jsx(yt,{value:m.value,onSelect:()=>{y(v=>({...v,sourceBranch:m.value})),W(!1)},children:t.jsx("span",{className:"typography-small break-all",children:m.label})},`${m.source}-${m.value}`))}),pe&&!B&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),oe.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[pe&&t.jsx(zt,{}),t.jsx(Ct,{heading:r(pe?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:oe.otherLocal.map(m=>t.jsx(yt,{value:m,onSelect:()=>{y(v=>({...v,sourceBranch:m})),W(!1)},children:t.jsx("span",{className:"typography-small break-all",children:m})},`local-${m}`))})]}),oe.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(oe.otherLocal.length>0||pe)&&t.jsx(zt,{}),t.jsx(Ct,{heading:r(pe?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:oe.otherRemote.map(m=>t.jsx(yt,{value:`remotes/${m}`,onSelect:()=>{y(v=>({...v,sourceBranch:`remotes/${m}`})),W(!1)},children:t.jsx("span",{className:"typography-small break-all",children:m})},`remote-${m}`))})]})]})})]})})]}),d.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:d.sourceBranch})})]}),(d.linkedIssue||d.linkedPr)&&p==="new-branch"&&t.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(C,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),d.linkedIssue&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:d.linkedIssue.number})}),d.linkedPr&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:d.linkedPr.number})}),t.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:d.linkedIssue?.title||d.linkedPr?.title}),t.jsx("a",{href:d.linkedIssue?.url||d.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:m=>m.stopPropagation(),children:t.jsx(C,{name:"external-link",className:"h-3 w-3"})}),t.jsx("button",{onClick:b,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]}),d.linkedPr&&t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[d.linkedPr.head," → ",d.linkedPr.base]}),d.includePrDiff&&t.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]}),t.jsxs(Gs,{className:"mt-1 flex items-center justify-between",children:[t.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:ee.touched&&(ee.branchError||ee.worktreeError)&&t.jsxs(t.Fragment,{children:[t.jsx(C,{name:"error-warning",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"typography-micro",children:ee.branchError||ee.worktreeError})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Te,children:r("session.newWorktree.actions.cancel")}),t.jsxs(Ne,{size:"sm",onClick:Be,disabled:!ze||Te,className:"gap-1.5",children:[Te&&t.jsx(C,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(Te?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),t.jsx(Ql,{open:te,onOpenChange:L,onSelect:He})]})}const tc=(s,e)=>{if(!s)return e("mcpDropdown.status.unknown");switch(s.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:s.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:s.error||""});default:return s.status}},sc=s=>{switch(s?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},jd=({active:s,className:e,headerAction:n,listClassName:r,hideHeader:o=!1,mobileListDensity:a=!1})=>{const{t:i}=rt(),f=ns(w=>w.currentDirectory)??null,h=os(w=>w.getStatusForDirectory(f)),c=os(w=>w.refresh),g=os(w=>w.connect),p=os(w=>w.disconnect),x=on(w=>w.mcpServers),d=on(w=>w.loadMcpConfigs),[y,j]=l.useState(!1),[T,R]=l.useState(null);l.useEffect(()=>{c({directory:f,silent:!0})},[c,f]),l.useEffect(()=>{d({force:!0})},[d]),l.useEffect(()=>{s&&Promise.all([c({directory:f,silent:!0}),d({force:!0})])},[s,c,f,d]);const M=l.useMemo(()=>{const w=new Set(Object.keys(h));for(const k of x)k?.name&&w.add(k.name);return Array.from(w).sort((k,I)=>k.localeCompare(I))},[x,h]),G=l.useCallback(w=>{if(w?.preventDefault(),y)return;j(!0);const k=new Promise(I=>setTimeout(I,500));Promise.all([c({directory:f}),k]).finally(()=>{j(!1)})},[y,c,f]);return t.jsxs("div",{className:q("w-full",e),children:[o?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:t.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[t.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:i("mcpDropdown.title")}),f&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:f.split("/").pop()||f})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n,t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:y,onClick:G,"aria-label":i("mcpDropdown.actions.refreshAria"),children:t.jsx(C,{name:"refresh",className:q("h-4 w-4",y&&"animate-spin")})})]})]})}),t.jsx("div",{className:q("max-h-64 overflow-y-auto",a?"space-y-1 py-3":"px-3 py-2.5",r),children:t.jsxs("div",{className:q(!a&&M.length>0&&"rounded-xl bg-[var(--surface-muted)] p-1.5"),children:[M.map(w=>{const k=h[w],I=sc(k),F=k?.status==="connected",re=T===w,te=tc(k,i);return t.jsxs("div",{className:q("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",a?"gap-3 px-4 py-3":"gap-2 px-2.5 py-2"),children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs(Mt,{children:[t.jsx(Lt,{asChild:!0,children:t.jsx("span",{className:q("rounded-full flex-shrink-0",a?"h-2.5 w-2.5":"h-2 w-2",I==="success"&&"bg-status-success",I==="error"&&"bg-status-error",I==="warning"&&"bg-status-warning",I==="default"&&"bg-muted-foreground/40"),"aria-label":te})}),t.jsx(Ft,{side:"left",children:t.jsx("p",{children:te})})]}),t.jsx("span",{className:q("truncate",a?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:w})]})}),t.jsx(_o,{checked:F,disabled:re,className:"data-[checked]:bg-status-info",onCheckedChange:async L=>{R(w);try{if(!L){await p(w,f);return}const V=h?.[w]?.status;if(V==="needs_auth"||V==="needs_client_registration"){const{opened:z}=await Go({name:w,directory:f});z||mn.error(i("mcpDropdown.toast.authorizeOpenFailed"));return}await g(w,f)}catch(V){mn.error(V instanceof Error?V.message:i("mcpDropdown.toast.authorizeFailed"))}finally{R(null)}}})]},w)}),M.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:i("mcpDropdown.empty.configureInConfig")})]})})]})},$s=5,kr=15,cs=new Map,ms=s=>{const e=Math.sqrt(s/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},nc=(s,e)=>{const n=ms(e);return Math.max(n*$s,Math.min(n*kr,n*s))},rc=async(s,e)=>{const n=await Xo(s.path);return{...s,title:n?.title||s.path.split("/").pop()||e}},oc=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,An=s=>[...s.filter(e=>!e.completed),...s.filter(e=>e.completed)],Bn=(s,e)=>{const n=s.findIndex(r=>r.completed);return n===-1?[...s,e]:[...s.slice(0,n),e,...s.slice(n)]},ac=s=>{const e=Ye.c(20),{id:n,children:r}=s;let o;e[0]!==n?(o={id:n},e[0]=n,e[1]=o):o=e[1];const{attributes:a,listeners:i,setNodeRef:u,setActivatorNodeRef:f,transform:h,transition:c,isDragging:g}=ir(o);let p;e[2]!==h?(p=cr.Transform.toString(h),e[2]=h,e[3]=p):p=e[3];let x;e[4]!==p||e[5]!==c?(x={transform:p,transition:c},e[4]=p,e[5]=c,e[6]=x):x=e[6];const d=g&&"opacity-60";let y;e[7]!==d?(y=q(d),e[7]=d,e[8]=y):y=e[8];let j;e[9]!==a||e[10]!==r||e[11]!==g||e[12]!==i||e[13]!==f?(j=r({attributes:a,listeners:i,setActivatorNodeRef:f,isDragging:g}),e[9]=a,e[10]=r,e[11]=g,e[12]=i,e[13]=f,e[14]=j):j=e[14];let T;return e[15]!==u||e[16]!==x||e[17]!==y||e[18]!==j?(T=t.jsx("li",{ref:u,style:x,className:y,children:j}),e[15]=u,e[16]=x,e[17]=y,e[18]=j,e[19]=T):T=e[19],T},ic=({projectRef:s,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,onOpenPlan:o,className:a})=>{const{t:i}=rt(),[u,f]=l.useState(!1),[h,c]=l.useState(""),[g,p]=l.useState([]),[x,d]=l.useState(""),[y,j]=l.useState(null),[T,R]=l.useState(()=>new Set),[M,G]=l.useState([]),[w,k]=l.useState(null),[I,F]=l.useState(!1),[re,te]=l.useState(0),L=l.useRef(!1),V=l.useRef(""),z=l.useRef(null),ne=Ae(b=>b.todoPanelHeight),W=Ae(b=>b.setTodoPanelHeight),de=Ae(b=>b.notesPanelHeight),_=Ae(b=>b.setNotesPanelHeight),[O,E]=l.useState(!1),A=l.useRef(0),U=l.useRef(ne),H=nt(b=>b.currentSessionId),D=nt(b=>b.createSession),se=nt(b=>b.initializeNewOpenChamberSession),ue=nt(b=>b.sendMessage),he=nt(b=>b.setCurrentSession),Ce=Ho(b=>b.setPendingInputText),ke=ns(b=>b.currentDirectory),Y=Ae(b=>b.openContextPanelTab),be=Ae(b=>b.setActiveMainTab),$=Ae(b=>b.setSessionSwitcherOpen),le=Ae(b=>b.padding),K=l.useCallback(async(b,X)=>{if(!s)return!1;const m=s.id,Z=(cs.get(m)??Promise.resolve()).catch(()=>{}).then(()=>Ko(s,{notes:b,todos:X}));cs.set(m,Z);try{const ye=await Z;return ye||ve.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),ye}finally{cs.get(m)===Z&&cs.delete(m)}},[s,i]);l.useEffect(()=>{if(!s){c(""),p([]),G([]),d(""),R(new Set);return}let b=!1;return f(!0),(async()=>{try{const X=await qo(s),m=await Promise.all(X.plans.map(v=>rc(v,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(b)return;c(X.notes),p(An(X.todos)),G(m),V.current=X.notes,L.current=!0,d(""),R(new Set)}catch{b||(ve.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),c(""),p([]),G([]),V.current="",L.current=!0)}finally{b||f(!1)}})(),()=>{b=!0}},[re,s,i]),l.useEffect(()=>{if(!s)return;const b=X=>{const m=X.detail;m?.projectId&&m.projectId!==s.id||te(v=>v+1)};return window.addEventListener("openchamber:project-plan-saved",b),window.addEventListener("openchamber:project-notes-updated",b),()=>{window.removeEventListener("openchamber:project-plan-saved",b),window.removeEventListener("openchamber:project-notes-updated",b)}},[s]),l.useEffect(()=>{if(g.length<7)return;const b=nc(g.length,le),X=ms(le)*$s;ne!==b&&(ne<X||ne>b)&&W(b)},[g.length,le,ne,W]),l.useEffect(()=>{if(!O)return;const b=m=>{const v=m.clientY-A.current,Z=Math.min(ms(le)*kr,Math.max(ms(le)*$s,U.current+v));W(Z)},X=()=>{E(!1)};return window.addEventListener("pointermove",b),window.addEventListener("pointerup",X,{once:!0}),window.addEventListener("pointercancel",X,{once:!0}),()=>{window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",X),window.removeEventListener("pointercancel",X)}},[O,le,W]);const oe=l.useCallback(b=>{E(!0),A.current=b.clientY,U.current=ne,b.preventDefault()},[ne]),ce=l.useCallback(()=>{z.current!==null&&(window.clearTimeout(z.current),z.current=null)},[]),pe=l.useCallback(()=>{ce(),V.current=h,K(h,g)},[ce,h,K,g]);l.useEffect(()=>{if(!(!s||!L.current)&&h!==V.current)return z.current=window.setTimeout(()=>{z.current=null,V.current=h,K(h,g)},400),()=>{ce()}},[ce,h,K,s,g]),l.useEffect(()=>()=>ce(),[ce]);const P=l.useCallback(()=>{const b=x.trim();if(!b)return;const X=Bn(g,{id:oc(),text:b.slice(0,as),completed:!1,createdAt:Date.now()});p(X),d(""),K(h,X)},[x,h,K,g]),B=l.useCallback(b=>{R(X=>{const m=new Set(X);return m.has(b)?m.delete(b):m.add(b),m})},[]),Q=l.useCallback((b,X)=>{const m=g.find(xe=>xe.id===b);if(!m||m.completed===X)return;const v=g.filter(xe=>xe.id!==b),Z={...m,completed:X},ye=X?[...v,Z]:Bn(v,Z);p(ye),K(h,ye)},[h,K,g]),me=l.useCallback(b=>{const X=g.filter(m=>m.id!==b);p(X),K(h,X)},[h,K,g]),ee=l.useCallback(()=>{const b=g.filter(X=>!X.completed);b.length!==g.length&&(p(b),K(h,b))},[h,K,g]),Se=l.useCallback(b=>{const{active:X,over:m}=b;if(!m||X.id===m.id)return;const v=g.findIndex(xe=>xe.id===X.id),Z=g.findIndex(xe=>xe.id===m.id);if(v===-1||Z===-1)return;const ye=An(Va(g,v,Z));p(ye),K(h,ye)},[h,K,g]),Te=sr(nr(rr,{activationConstraint:{distance:8}})),De=x.slice(0,as),Ue=g.reduce((b,X)=>b+(X.completed?1:0),0),Ve=l.useCallback(()=>{be("chat"),$(!1)},[be,$]),Me=l.useCallback((b,X)=>{!s||y||k({kind:"session",todoId:b,todoText:X})},[s,y]),Ze=l.useCallback(b=>{if(!H){ve.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}Ve();const X=`\`\`\`md
|
|
5
|
+
${b}
|
|
6
|
+
\`\`\``;Ce(X,"append"),ve.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[H,r,Ve,Ce,i]),Ee=l.useCallback((b,X)=>{if(!(!s||y)){if(!n){ve.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}k({kind:"worktree",todoId:b,todoText:X})}},[n,s,y,i]),Ge=l.useCallback(async b=>{if(!s||!w)return;const X=await $t("plan.todo.visible",{todo_text:w.todoText}),v=[{synthetic:!0,text:await $t("plan.todo.instructions",{todo_text:w.todoText})}];F(!0),j(w.todoId);try{Ve();let Z=null,ye=s.path;if(w.kind==="worktree"){if(!n){ve.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const Oe=await Yo(s.path,Jo());if(!Oe?.id)return;Z=Oe.id,ye=Oe.path}else{const Oe=await D(void 0,s.path,null);if(!Oe?.id){ve.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}Z=Oe.id,ye=Oe.directory??s.path,se(Oe.id,pt.getState().agents??[])}if(!Z)return;const xe=Kn.getState();xe.saveSessionModelSelection(Z,b.providerID,b.modelID),b.agent.trim()&&(xe.saveSessionAgentSelection(Z,b.agent),xe.saveAgentModelForSession(Z,b.agent,b.providerID,b.modelID),xe.saveAgentModelVariantForSession(Z,b.agent,b.providerID,b.modelID,b.variant||void 0)),he(Z,ye),await ue(X,b.providerID,b.modelID,b.agent.trim()||void 0,void 0,void 0,v,b.variant||void 0),ve.success(w.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),k(null),r?.()}catch(Z){const ye=Z instanceof Error?Z.message:void 0;ve.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),ye?{description:ye}:void 0)}finally{F(!1),j(null)}},[n,D,se,r,w,s,Ve,ue,he,i]),Le=l.useRef(null),[$e,Je]=l.useState(!1),[Be,Qe]=l.useState(null),He=l.useCallback(async b=>{if(!(!s||Be)){Qe(b);try{if(!await Qo(s,b)){ve.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}G(m=>m.filter(v=>v.id!==b)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:s.id}}))}finally{Qe(null)}}},[Be,s,i]),Pe=l.useCallback(async()=>{if(!s||$e)return;const b=await Sa({defaultPath:s.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(b.success&&b.path){Je(!0);try{const X=new URLSearchParams({path:b.path,allowOutsideWorkspace:"true"});b.outsideFileGrant&&X.set("outsideFileGrant",b.outsideFileGrant);const m=await Nt(`/api/fs/read?${X.toString()}`,{cache:"no-store"});if(!m.ok){ve.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const v=await m.text();if(!v.trim()){ve.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Z=b.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await an(s,v,Z)){ve.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:s.id}})),ve.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(X){const m=X instanceof Error?X.message:void 0;ve.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),m?{description:m}:void 0)}finally{Je(!1)}}else b.error==="Native file picker not available"&&Le.current?.click()},[$e,s,i]),et=l.useCallback(async b=>{if(!(!s||!b)){Je(!0);try{const X=await b.text();if(!X.trim()){ve.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const m=b.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await an(s,X,m)){ve.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:s.id}})),ve.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(X){const m=X instanceof Error?X.message:void 0;ve.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),m?{description:m}:void 0)}finally{Je(!1)}}},[s,i]),ze=l.useCallback(b=>{if(o){o({path:b.path,title:b.title});return}const X=s?.path?.trim(),m=ke?.trim()||X;m&&Y(m,{mode:"plan",targetPath:b.path,dedupeKey:b.path,label:b.title})},[ke,o,Y,s]);return s?t.jsxs("div",{className:q("w-full min-w-0 space-y-3 p-3",a),children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:s.path,children:i("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||s.path.split("/").filter(Boolean).pop()||s.path})}),t.jsxs("span",{className:"typography-meta text-muted-foreground",children:[h.length,"/",ln]})]}),t.jsx(Vn,{value:h,onChange:b=>c(b.target.value.slice(0,ln)),onBlur:pe,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:de,onResizeHeightChange:_,useScrollShadow:!0,scrollShadowSize:56,disabled:u})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:g.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:g.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:g.length})}),t.jsx("button",{type:"button",onClick:ee,disabled:u||Ue===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:i("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),t.jsxs("span",{className:"typography-meta text-muted-foreground",children:[De.length,"/",as]})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ht,{value:De,onChange:b=>d(b.target.value.slice(0,as)),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),P())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:u,className:"h-8"}),t.jsx("button",{type:"button",onClick:P,disabled:u||De.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.addAria"),title:i("rightSidebar.contextNotesTodo.todo.addAria"),children:t.jsx(C,{name:"add",className:"h-4 w-4"})})]}),t.jsx("div",{className:q("overflow-y-auto rounded-lg border border-border/60 bg-background/40",O&&"transition-none"),style:g.length<7?void 0:{height:`${ne}px`,maxHeight:`${ne}px`},children:g.length===0?t.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.todo.empty")}):t.jsx(or,{sensors:Te,collisionDetection:ar,onDragEnd:Se,children:t.jsx(lr,{items:g.map(b=>b.id),strategy:_a,children:t.jsx("ul",{className:"divide-y divide-border/50",children:g.map(b=>{const X=T.has(b.id);return t.jsx(ac,{id:b.id,children:m=>t.jsxs("div",{className:q("flex gap-1.5 px-2.5 py-1.5",X?"items-start":"items-center"),children:[t.jsx("button",{type:"button",ref:m.setActivatorNodeRef,...m.attributes,...m.listeners,onClick:v=>{v.preventDefault(),v.stopPropagation()},className:"flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:b.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:b.text}),children:t.jsx(C,{name:"draggable",className:"h-3.5 w-3.5"})}),t.jsx("div",{className:"flex h-6 items-center",children:t.jsx(ss,{checked:b.completed,onChange:v=>Q(b.id,v),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:b.text})})}),t.jsx("button",{type:"button",onClick:()=>B(b.id),className:q("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-normal text-foreground",X?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",b.completed&&"text-muted-foreground line-through"),title:X?void 0:b.text,"aria-label":X?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:b.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:b.text}),children:b.text}),t.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[t.jsx("button",{type:"button",onClick:()=>me(b.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:b.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:b.text}),children:t.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})}),t.jsxs(Pt,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx("button",{type:"button",disabled:y===b.id,className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.send",{text:b.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:b.text}),children:t.jsx(C,{name:"send-plane",className:"h-3.5 w-3.5"})})}),t.jsxs(Et,{align:"end",className:"w-56",children:[t.jsx(jt,{onClick:()=>Ze(b.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),t.jsx(jt,{onClick:()=>Me(b.id,b.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),t.jsx(jt,{onClick:()=>{Ee(b.id,b.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},b.id)})})})})}),g.length>=7&&t.jsx("div",{className:q("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",O&&"bg-[var(--interactive-border)]"),onPointerDown:oe,role:"separator","aria-orientation":"horizontal","aria-label":i("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.plans.title")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:M.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:M.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:M.length})})]}),t.jsx("input",{ref:Le,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:b=>{const X=b.target.files?.[0]??null;et(X),b.currentTarget.value=""}}),t.jsx("button",{type:"button",onClick:Pe,disabled:!s||$e,className:"inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.plans.importFromFile"),title:i("rightSidebar.contextNotesTodo.plans.importFromFile"),children:t.jsx(C,{name:"add",className:"h-3.5 w-3.5"})})]}),t.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:M.length===0?t.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.plans.empty")}):t.jsx("ul",{className:"divide-y divide-border/50",children:M.map(b=>t.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>ze(b),className:"flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[t.jsx("span",{className:"min-w-0 truncate typography-ui-label text-foreground",children:b.title}),t.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(b.createdAt).toLocaleDateString(Un())})]}),t.jsx("button",{type:"button",onClick:()=>{He(b.id)},disabled:Be===b.id,className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",title:i("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":i("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:b.title}),children:t.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},b.id))})})]}),t.jsx(Si,{open:w!==null,onOpenChange:b=>{!b&&!I&&k(null)},target:w?.kind??"session",projectDirectory:s?.path??null,submitting:I,onConfirm:Ge})]}):t.jsx("div",{className:q("w-full min-w-0 p-3",a),children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},Nd=s=>{const e=Ye.c(19),{onActionComplete:n,onOpenPlan:r}=s,o=gt(lc),a=gt(cc),i=ns(dc),u=Ks(uc);let f;e:{if(o){let T;e[0]!==o||e[1]!==a?(T=a.find(R=>R.id===o)??a[0]??null,e[0]=o,e[1]=a,e[2]=T):T=e[2],f=T;break e}f=a[0]??null}const h=f;let c;e:{if(!h){c=null;break e}let T;e[3]!==h.id||e[4]!==h.path?(T={id:h.id,path:h.path},e[3]=h.id,e[4]=h.path,e[5]=T):T=e[5],c=T}const g=c;let p;e:{if(!h){p=null;break e}let T;e[6]!==h.label||e[7]!==h.path||e[8]!==i?(T=h.label?.trim()||Zo(h.path,i)||h.path,e[6]=h.label,e[7]=h.path,e[8]=i,e[9]=T):T=e[9],p=T}const x=p;let d;e:{if(!h){d=!1;break e}let T;e[10]!==h.path||e[11]!==u?(T=u.get(h.path)?.isGitRepo,e[10]=h.path,e[11]=u,e[12]=T):T=e[12],d=T===!0}const y=d;let j;return e[13]!==y||e[14]!==n||e[15]!==r||e[16]!==x||e[17]!==g?(j=t.jsx("div",{className:"h-full min-h-0 overflow-auto bg-background",children:t.jsx(ic,{projectRef:g,projectLabel:x,canCreateWorktree:y,onActionComplete:n,onOpenPlan:r})}),e[13]=y,e[14]=n,e[15]=r,e[16]=x,e[17]=g,e[18]=j):j=e[18],j};function lc(s){return s.activeProjectId}function cc(s){return s.projects}function dc(s){return s.homeDirectory}function uc(s){return s.directories}const fs=Object.freeze({chunks:Object.freeze([]),byteLength:0,lastSequence:-1}),Vs=512*1024,mc=new TextEncoder,fc=new TextDecoder,Ss=s=>{const e=mc.encode(s);if(e.byteLength<=Vs)return{text:s,byteLength:e.byteLength};let n=e.byteLength-Vs;for(;n<e.byteLength&&(e[n]&192)===128;)n+=1;const r=e.subarray(n);return{text:fc.decode(r),byteLength:r.byteLength}},Wt=(s,e)=>`${s}\0${e}`,Cs=(s,e)=>{let n=null;for(const r of s.keys())e(r)&&(n??=new Map(s),n.delete(r));return n},hc="terminal-store";let Mn=!1,Ln=0;const ds=()=>typeof globalThis.crypto?.randomUUID=="function"?`tab-${globalThis.crypto.randomUUID()}`:(Ln+=1,`tab-${Date.now().toString(36)}-${Ln.toString(36)}`),Is=s=>typeof s=="object"&&s!==null,pc=s=>{const e=/^tab-(\d+)$/.exec(s);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function ct(s){let e=s.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const gc=/^Terminal(?: (\d+))?$/,xc=s=>{let e=0;for(const n of s){const r=gc.exec(n.label);if(!r)continue;const o=r[1]?Number.parseInt(r[1],10):1;Number.isSafeInteger(o)&&(e=Math.max(e,o))}return e===0?"Terminal":`Terminal ${e+1}`},Ts=(s,e)=>({id:s,terminalSessionId:null,lifecycle:"idle",label:e,iconKey:null,isConnecting:!1,createdAt:Date.now(),previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1}),Ps=s=>({tabs:[s],activeTabId:s.id}),bt=(s,e)=>s.tabs.findIndex(n=>n.id===e);let Ds=null,Es=null;const bc=s=>{if(Es&&Ds?.sessions===s.sessions&&Ds.nextTabId===s.nextTabId)return Es;const e={sessions:Array.from(s.sessions.entries()).map(([n,r])=>[n,{activeTabId:r.activeTabId,tabs:r.tabs.map(o=>({id:o.id,label:o.label,iconKey:o.iconKey,createdAt:o.createdAt}))}]),nextTabId:s.nextTabId};return Ds={sessions:s.sessions,nextTabId:s.nextTabId},Es=e,e},yc=()=>{const s=Wa(()=>Ca());if(!s)return;let e=null;return{getItem:n=>s.getItem(n),setItem:(n,r)=>{if(r.state!==e)return e=r.state,s.setItem(n,r)},removeItem:n=>(e=null,s.removeItem(n))}},Xe=bs()(Zn(er((s,e)=>({sessions:new Map,buffers:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=ct(n);r&&s(o=>{if(o.sessions.has(r))return o;const a=new Map(o.sessions),i=ds(),u=Ts(i,"Terminal");return a.set(r,Ps(u)),{sessions:a,nextTabId:o.nextTabId+1}})},getDirectoryState:n=>{const r=ct(n);return e().sessions.get(r)},getActiveTab:n=>{const r=ct(n),o=e().sessions.get(r);if(!o)return;const a=o.activeTabId;return a?o.tabs.find(i=>i.id===a)??o.tabs[0]:o.tabs[0]},getBuffer:(n,r)=>e().buffers.get(Wt(ct(n),r))??fs,createTab:n=>{const r=ct(n);if(!r)return"tab-invalid";const o=ds();return s(a=>{const i=new Map(a.sessions),u=i.get(r),f=a.nextTabId+1,h=xc(u?.tabs??[]),c=Ts(o,h);return u?i.set(r,{...u,tabs:[...u.tabs,c]}):i.set(r,Ps(c)),{sessions:i,nextTabId:f}}),o},setActiveTab:(n,r)=>{const o=ct(n);s(a=>{const i=new Map(a.sessions),u=i.get(o);return!u||u.activeTabId===r||bt(u,r)<0?a:(i.set(o,{...u,activeTabId:r}),{sessions:i})})},setTabLabel:(n,r,o)=>{const a=ct(n),i=o.trim();i&&s(u=>{const f=new Map(u.sessions),h=f.get(a);if(!h)return u;const c=bt(h,r);if(c<0||h.tabs[c]?.label===i)return u;const g=[...h.tabs];return g[c]={...g[c],label:i},f.set(a,{...h,tabs:g}),{sessions:f}})},setTabIconKey:(n,r,o)=>{const a=ct(n);s(i=>{const u=new Map(i.sessions),f=u.get(a);if(!f)return i;const h=bt(f,r);if(h<0)return i;const c=o?.trim()||null;if(f.tabs[h]?.iconKey===c)return i;const g=[...f.tabs];return g[h]={...g[h],iconKey:c},u.set(a,{...f,tabs:g}),{sessions:u}})},closeTab:(n,r)=>{const o=ct(n);s(a=>{const i=new Map(a.sessions),u=i.get(o);if(!u)return a;const f=bt(u,r);if(f<0)return a;const h=u.tabs.filter(y=>y.id!==r),c=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,y])=>!(y.directory===o&&y.tabId===r))),g=Object.keys(c).length!==Object.keys(a.projectActionRuns).length,p=Wt(o,r),x=a.buffers.has(p)?Cs(a.buffers,y=>y===p):null;if(h.length===0){const y=ds(),j=Ts(y,"Terminal");return i.set(o,Ps(j)),{sessions:i,nextTabId:a.nextTabId+1,...x?{buffers:x}:{},...g?{projectActionRuns:c}:{}}}let d=u.activeTabId;return u.activeTabId===r&&(d=h[Math.min(f,h.length-1)]?.id??h[0]?.id??null),i.set(o,{...u,tabs:h,activeTabId:d}),{sessions:i,...x?{buffers:x}:{},...g?{projectActionRuns:c}:{}}})},setTabSessionId:(n,r,o)=>{const a=ct(n);s(i=>{const u=new Map(i.sessions),f=u.get(a);if(!f)return i;const h=bt(f,r);if(h<0)return i;const c=f.tabs[h],g=o!==null&&c.terminalSessionId!==o,p=o?"running":c.terminalSessionId?"exited":c.lifecycle,x={...c,terminalSessionId:o,lifecycle:p,isConnecting:!1},d=Wt(a,r),y=g&&i.buffers.has(d)?Cs(i.buffers,T=>T===d):null,j=[...f.tabs];return j[h]=x,u.set(a,{...f,tabs:j}),{sessions:u,...y?{buffers:y}:{}}})},setTabLifecycle:(n,r,o)=>{const a=ct(n);s(i=>{const u=new Map(i.sessions),f=u.get(a);if(!f)return i;const h=bt(f,r);if(h<0)return i;const c=[...f.tabs];return c[h]={...c[h],lifecycle:o,isConnecting:!1},u.set(a,{...f,tabs:c}),{sessions:u}})},setConnecting:(n,r,o)=>{const a=ct(n);s(i=>{const u=new Map(i.sessions),f=u.get(a);if(!f)return i;const h=bt(f,r);if(h<0)return i;const c=[...f.tabs];return c[h]={...c[h],isConnecting:o},u.set(a,{...f,tabs:c}),{sessions:u}})},replaceBuffer:(n,r,o,a)=>{const i=ct(n);s(u=>{const f=u.sessions.get(i);if(!f||bt(f,r)<0)return u;const h=Wt(i,r),c=u.buffers.get(h)??fs;if(c.lastSequence>a)return u;const g=Ss(o);if(c.lastSequence===a&&c.byteLength===g.byteLength&&c.chunks.map(d=>d.data).join("")===g.text)return u;const p=u.nextChunkId,x=new Map(u.buffers);return x.set(h,{chunks:g.text?[{id:p,data:g.text,byteLength:g.byteLength}]:[],byteLength:g.byteLength,lastSequence:a}),{buffers:x,nextChunkId:g.text?p+1:p}})},appendToBuffer:(n,r,o,a,i)=>{if(!o)return;const u=ct(n);s(f=>{const h=f.sessions.get(u);if(!h||bt(h,r)<0)return f;const c=Wt(u,r),g=f.buffers.get(c)??fs;if(a!==void 0&&a<=g.lastSequence)return f;const p=f.nextChunkId,x=Ss(o),d=i!==void 0&&i!==o?Ss(i).text:void 0,y={id:p,data:x.text,...d!==void 0?{replayData:d}:{},byteLength:x.byteLength},j=[...g.chunks,y];let T=g.byteLength+y.byteLength;for(;T>Vs&&j.length>1;){const M=j.shift();if(!M)break;T-=M.byteLength}const R=new Map(f.buffers);return R.set(c,{chunks:j,byteLength:T,lastSequence:a??g.lastSequence}),{buffers:R,nextChunkId:p+1}})},setTabPreviewUrl:(n,r,o,a={})=>{const i=ct(n);s(u=>{const f=new Map(u.sessions),h=f.get(i);if(!h)return u;const c=bt(h,r);if(c<0)return u;const g=h.tabs[c],p=a.autoOpened??g.previewAutoOpened,x=a.locked??g.previewUrlLocked;if(g.previewUrl===o&&g.previewAutoOpened===p&&g.previewUrlLocked===x)return u;const d=[...h.tabs];return d[c]={...g,previewUrl:o,previewAutoOpened:p,previewUrlLocked:x},f.set(i,{...h,tabs:d}),{sessions:f}})},markPreviewAutoOpened:(n,r)=>{const o=ct(n);s(a=>{const i=new Map(a.sessions),u=i.get(o);if(!u)return a;const f=bt(u,r);if(f<0)return a;const h=u.tabs[f];if(!h.previewUrl||h.previewAutoOpened)return a;const c=[...u.tabs];return c[f]={...h,previewAutoOpened:!0},i.set(o,{...u,tabs:c}),{sessions:i}})},setProjectActionRun:n=>{s(r=>{const o=r.projectActionRuns[n.key];return o&&o.directory===n.directory&&o.actionId===n.actionId&&o.tabId===n.tabId&&o.sessionId===n.sessionId&&o.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{s(o=>{const a=o.projectActionRuns[n];return!a||a.status===r?o:{projectActionRuns:{...o.projectActionRuns,[n]:{...a,status:r}}}})},removeProjectActionRun:n=>{s(r=>{if(!r.projectActionRuns[n])return r;const o={...r.projectActionRuns};return delete o[n],{projectActionRuns:o}})},removeDirectory:n=>{const r=ct(n);s(o=>{const a=new Map(o.sessions);a.delete(r);const i=Wt(r,""),u=Cs(o.buffers,h=>h.startsWith(i)),f=Object.fromEntries(Object.entries(o.projectActionRuns).filter(([,h])=>h.directory!==r));return{sessions:a,...u?{buffers:u}:{},projectActionRuns:f}})},clearAll:()=>{s({sessions:new Map,buffers:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:hc,storage:yc(),partialize:bc,merge:(s,e)=>{if(!Is(s))return e;const n=Array.isArray(s.sessions)?s.sessions:[],r=new Map;let o=0;for(const u of n){if(!Array.isArray(u)||u.length!==2)continue;const[f,h]=u;if(typeof f!="string"||!Is(h))continue;const c=Array.isArray(h.tabs)?h.tabs:[],g=[],p=new Map;for(const j of c){if(!Is(j))continue;const T=typeof j.id=="string"?j.id:null;if(!T)continue;const R=pc(T);R!==null&&(o=Math.max(o,R));const M=R===null?T:ds();p.set(T,M),g.push({id:M,label:typeof j.label=="string"?j.label:"Terminal",iconKey:typeof j.iconKey=="string"?j.iconKey:null,terminalSessionId:null,lifecycle:"idle",createdAt:typeof j.createdAt=="number"?j.createdAt:Date.now(),isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(g.length===0)continue;const x=typeof h.activeTabId=="string"?h.activeTabId:null,d=x?p.get(x)??x:null,y=d?g.some(j=>j.id===d):!1;r.set(f,{tabs:g,activeTabId:y?d:g[0].id})}const a=typeof s.nextTabId=="number"&&Number.isFinite(s.nextTabId)?s.nextTabId:1,i=Math.max(e.nextTabId,a,o+1);return{...e,sessions:r,buffers:new Map,nextChunkId:1,nextTabId:i,hasHydrated:!0}}})));if(typeof window<"u"&&!Mn){Mn=!0;const s=Xe.persist,e=()=>{Xe.getState().hasHydrated||Xe.setState({hasHydrated:!0})};s?.hasHydrated?.()?e():s?.onFinishHydration?s.onFinishHydration(e):e()}function wc(s){const{colors:e}=s,n=e.syntax.base;return{background:e.surface.background,foreground:n.foreground,cursor:e.interactive.cursor,cursorAccent:e.surface.background,selectionBackground:e.interactive.selection,selectionForeground:e.interactive.selectionForeground,selectionInactiveBackground:e.interactive.selection+"50",black:e.surface.muted,red:e.status.error,green:e.status.success,yellow:e.status.warning,blue:n.function,magenta:n.keyword,cyan:n.type,white:n.foreground,brightBlack:n.comment,brightRed:e.status.error,brightGreen:e.status.success,brightYellow:e.status.warning,brightBlue:n.function,brightMagenta:n.keyword,brightCyan:n.type,brightWhite:e.surface.elevatedForeground}}function vc(s,e,n,r,o=!1){const i=`${s}, "JetBrainsMonoNL Nerd Font", "FiraCode Nerd Font", "Cascadia Code PL", "Fira Code", "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", "Courier New", monospace`;return{cursorBlink:!1,cursorStyle:"bar",fontSize:e,fontFamily:i,allowTransparency:!1,theme:{background:n.background,foreground:n.foreground,cursor:n.cursor,cursorAccent:n.cursorAccent,selectionBackground:n.selectionBackground,selectionForeground:n.selectionForeground,black:n.black,red:n.red,green:n.green,yellow:n.yellow,blue:n.blue,magenta:n.magenta,cyan:n.cyan,white:n.white,brightBlack:n.brightBlack,brightRed:n.brightRed,brightGreen:n.brightGreen,brightYellow:n.brightYellow,brightBlue:n.brightBlue,brightMagenta:n.brightMagenta,brightCyan:n.brightCyan,brightWhite:n.brightWhite},scrollback:1e4,ghostty:r,disableStdin:o}}const Rs=["\x1B[0m","\x1B[m"],kc=s=>{const e=s.trim(),n=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e)?.[1];if(n){const a=n.length<=4?n.slice(0,3).split("").map(i=>i+i).join(""):n.slice(0,6);return[Number.parseInt(a.slice(0,2),16),Number.parseInt(a.slice(2,4),16),Number.parseInt(a.slice(4,6),16)]}const r=/^rgba?\(\s*(\d{1,3})\s*[, ]\s*(\d{1,3})\s*[, ]\s*(\d{1,3})(?:\s*[,/]\s*[\d.]+)?\s*\)$/i.exec(e);if(!r)return null;const o=r.slice(1,4).map(Number);return o.some(a=>a<0||a>255)?null:o},Fn=s=>{const e=kc(s);return e?`\x1B[0;48;2;${e[0]};${e[1]};${e[2]}m`:null},jc=(s,e,n)=>{const r=e+s;if(!n)return{data:r,carry:""};let o=0;const a=Math.max(...Rs.map(f=>f.length))-1;for(let f=1;f<=Math.min(a,r.length);f+=1){const h=r.slice(-f);Rs.some(c=>c.length>h.length&&c.startsWith(h))&&(o=f)}const i=o>0?r.slice(-o):"";let u=o>0?r.slice(0,-o):r;for(const f of Rs)u=u.replaceAll(f,n);return{data:u,carry:i}},Nc=(s,e,n,r,o)=>{if(n.width<=0||n.height<=0||r<=0||o<=0)return null;const a=Math.floor((s-n.left)/n.width*r),i=Math.floor((e-n.top)/n.height*o);return{column:Math.max(0,Math.min(r-1,a)),row:Math.max(0,Math.min(o-1,i))}},Sc=(s,e)=>{const n=Math.max(0,Math.min(s.length-1,e)),r=i=>!!(i&&!/^\s+$/u.test(i));if(!r(s[n]))return{startColumn:n,endColumn:n};let o=n,a=n;for(;o>0&&r(s[o-1]);)o-=1;for(;a<s.length-1&&r(s[a+1]);)a+=1;return{startColumn:o,endColumn:a}};let Cc=null;const Ic=()=>Cc??=Vt(()=>import("./vendor-ghostty-web-CrxinGGH.js"),__vite__mapDeps([113,5])).then(async s=>({module:s,ghostty:await s.Ghostty.load()})),Tc=2e3,Pc=()=>{if(typeof window>"u")return Promise.resolve();const s=window.__openchamberEnsureNerdFonts;return typeof s!="function"?Promise.resolve():Promise.race([Promise.resolve(s()).catch(()=>{}),new Promise(e=>setTimeout(e,Tc))]).then(()=>{})},Dc=(s,e,n)=>{if(typeof window>"u"||typeof document>"u")return null;const r=document.createElement("canvas").getContext("2d");if(!r||s.clientWidth<24||s.clientHeight<24)return null;r.font=`${n}px ${e}`;const o=r.measureText("M"),a=Math.ceil(o.width),i=Math.ceil((o.actualBoundingBoxAscent||n*.8)+(o.actualBoundingBoxDescent||n*.2))+2;if(a<1||i<1)return null;const u=window.getComputedStyle(s),f=(Number.parseInt(u.paddingLeft,10)||0)+(Number.parseInt(u.paddingRight,10)||0),h=(Number.parseInt(u.paddingTop,10)||0)+(Number.parseInt(u.paddingBottom,10)||0);return{cols:Math.max(2,Math.floor((s.clientWidth-f-15)/a)),rows:Math.max(1,Math.floor((s.clientHeight-h)/i))}},jr=l.forwardRef(({sessionKey:s,chunks:e,onInput:n,onResize:r,theme:o,fontFamily:a,fontSize:i,className:u,enableTouchScroll:f=!1,autoFocus:h=!0,isVisible:c=!0},g)=>{const p=l.useRef(null),x=l.useRef(null),d=l.useRef(null),y=l.useRef(n),j=l.useRef(r),T=l.useRef(null),R=l.useRef(null),M=l.useRef(null),G=l.useRef(""),w=l.useRef(""),k=l.useRef(Fn(o.background)),I=l.useRef(!1),F=l.useRef(0),re=l.useRef(c),te=l.useRef(!1),[L,V]=l.useState(0),[z,ne]=l.useState(0);y.current=n,j.current=r,re.current=c,k.current=Fn(o.background),l.useLayoutEffect(()=>{const O=p.current;if(!O)return;const E=Dc(O,a,i);R.current=E,E&&j.current(E.cols,E.rows)},[a,i]);const W=l.useCallback(()=>{const O=p.current,E=x.current;if(!O||!E||!d.current||!re.current)return;const A=O.getBoundingClientRect();if(!(A.width<24||A.height<24))try{d.current.fit();const U={cols:E.cols,rows:E.rows};(!T.current||T.current.cols!==U.cols||T.current.rows!==U.rows)&&(T.current=U,j.current(U.cols,U.rows)),te.current||(te.current=!0,V(H=>H+1))}catch{}},[]),de=l.useCallback(()=>{if(I.current||!G.current||!x.current)return;const O=x.current,E=G.current;G.current="";const A=jc(E,w.current,k.current);if(w.current=A.carry,!A.data){G.current&&de();return}I.current=!0;const U=F.current;O.write(A.data,()=>{x.current!==O||F.current!==U||(I.current=!1,G.current&&de())})},[]),_=l.useCallback(()=>{M.current=null,G.current="",w.current="",I.current=!1,F.current+=1;const O=x.current;if(!O){ne(E=>E+1);return}try{O.reset();const E=k.current;E&&O.write(`${E}\x1B[2J\x1B[H`)}catch{ne(E=>E+1)}},[]);return l.useEffect(()=>{const O=p.current;if(!O)return;let E=!1,A=null,U=null,H=null,D=null,se=[];const ue=()=>{A&&re.current&&(A.options.cursorBlink=!0)},he=Y=>{Y.relatedTarget instanceof Node&&O.contains(Y.relatedTarget)||A&&(A.options.cursorBlink=!1)},Ce=()=>{A&&re.current&&O.contains(document.activeElement)&&(A.options.cursorBlink=!0)},ke=()=>{A&&(A.options.cursorBlink=!1)};return O.addEventListener("focusin",ue),O.addEventListener("focusout",he),window.addEventListener("focus",Ce),window.addEventListener("blur",ke),Promise.all([Ic(),Pc()]).then(([{module:Y,ghostty:be}])=>{if(E)return;A=new Y.Terminal({...vc(a,i,o,be,!1),...R.current??{}});const $=new Y.FitAddon;A.loadAddon($),A.open(O),x.current=A,d.current=$,se=[A.onData(K=>y.current(K))],U=new ResizeObserver(()=>{H&&clearTimeout(H),H=setTimeout(W,80)}),U.observe(O),W();const le=k.current;le&&A.write(`${le}\x1B[2J\x1B[H`),D=requestAnimationFrame(W)}),()=>{E=!0;const Y=document.activeElement;Y instanceof HTMLElement&&O.contains(Y)&&(Y.blur(),window.Capacitor?.getPlatform?.()==="android"&&Vt(async()=>{const{Keyboard:$}=await import("./vendor-capacitor-keyboard-CYccoJjr.js");return{Keyboard:$}},__vite__mapDeps([114,115])).then(({Keyboard:$})=>$.hide()).catch(()=>{})),U?.disconnect(),H&&clearTimeout(H),D!==null&&cancelAnimationFrame(D),O.removeEventListener("focusin",ue),O.removeEventListener("focusout",he),window.removeEventListener("focus",Ce),window.removeEventListener("blur",ke),se.forEach(be=>be.dispose()),A?.dispose(),x.current=null,d.current=null,T.current=null,M.current=null,G.current="",w.current="",I.current=!1,F.current+=1,te.current=!1}},[W,a,i,z,o]),l.useEffect(()=>{const O=x.current,E=p.current;!O||!E||(O.options.cursorBlink=c&&document.hasFocus()&&E.contains(document.activeElement))},[c,L]),l.useEffect(()=>{if(!x.current)return;if(e.length===0){M.current!==null&&_();return}const E=M.current;let A=-1;if(E!==null){for(let D=e.length-1;D>=0;D-=1){const se=e[D].id;if(se===E){A=D;break}if(se<E)break}if(A<0){_();return}}const U=A<0,H=A>=0?e.slice(A+1):e;G.current+=H.map(D=>U?D.replayData??D.data:D.data).join(""),M.current=e.at(-1)?.id??null,de()},[e,de,L,_]),l.useEffect(()=>{if(!h||!c)return;const O=requestAnimationFrame(()=>x.current?.focus());return()=>cancelAnimationFrame(O)},[h,c,L,s]),l.useEffect(()=>{const O=p.current;if(!f||!O)return;const E=A=>{const U=A;if(!U.isComposing)switch(U.inputType){case"insertText":U.data&&y.current(U.data);break;case"insertLineBreak":case"insertParagraph":y.current("\r");break;case"deleteContentBackward":y.current("");break}};return O.addEventListener("beforeinput",E),()=>O.removeEventListener("beforeinput",E)},[f,L]),l.useEffect(()=>{const O=p.current,E=x.current;if(!f||!O||!E)return;let A=null,U=null,H="idle",D=0,se=0,ue=0,he=0,Ce=null;const ke=Math.max(12,i+2),Y=()=>{window.Capacitor?.getPlatform?.()==="android"&&Vt(async()=>{const{Keyboard:Q}=await import("./vendor-capacitor-keyboard-CYccoJjr.js");return{Keyboard:Q}},__vite__mapDeps([114,115])).then(({Keyboard:Q})=>Q.show()).catch(()=>{})},be=()=>{U&&(clearTimeout(U),U=null)},$=(B,Q)=>{const me=O.querySelector("canvas");return me?Nc(B,Q,me.getBoundingClientRect(),E.cols,E.rows):null},le=(B,Q)=>{const me=O.querySelector("canvas");if(!me)return;const ee=me.getBoundingClientRect(),Se=ee.left+(Q.column+.5)/E.cols*ee.width,Te=ee.top+(Q.row+.5)/E.rows*ee.height;me.dispatchEvent(new MouseEvent(B,{bubbles:!0,cancelable:!0,button:0,buttons:1,clientX:Se,clientY:Te}))},K=()=>{document.dispatchEvent(new MouseEvent("mouseup",{bubbles:!0,cancelable:!0,button:0,buttons:0}))},oe=B=>{B.pointerType!=="touch"||A!==null||(A=B.pointerId,H="pending",D=B.clientX,se=B.clientY,ue=B.clientY,he=0,Ce=null,O.setPointerCapture(B.pointerId),U=setTimeout(()=>{if(U=null,A!==B.pointerId||H!=="pending")return;const Q=$(D,se);if(!Q)return;const me=E.buffer.active,ee=Math.max(0,me.length-E.rows-me.viewportY+Q.row),Se=me.getLine(ee),Te=Array.from({length:E.cols},(Ve,Me)=>Se?.getCell(Me)?.getChars()??""),De=Sc(Te,Q.column),Ue={column:De.startColumn,row:Q.row};Ce={column:De.endColumn,row:Q.row},H="selecting",le("mousedown",Ue),le("mousemove",Ce)},350))},ce=B=>{if(A!==B.pointerId)return;if(H==="selecting"){const ee=$(B.clientX,B.clientY);ee&&(!Ce||ee.column!==Ce.column||ee.row!==Ce.row)&&(Ce=ee,le("mousemove",ee)),B.cancelable&&B.preventDefault();return}if(H==="pending"){if(Math.hypot(B.clientX-D,B.clientY-se)<8)return;be(),H="scrolling"}if(H!=="scrolling")return;const Q=ue-B.clientY;ue=B.clientY,he+=Q;const me=Math.trunc(he/ke);me&&(E.scrollLines(me),he-=me*ke),B.cancelable&&B.preventDefault()},pe=B=>{if(A!==B.pointerId)return;const Q=H==="pending",me=H==="selecting";be(),O.hasPointerCapture(B.pointerId)&&O.releasePointerCapture(B.pointerId),A=null,H="idle",me&&K(),Q&&(E.focus(),Y())},P=B=>{if(A!==B.pointerId)return;const Q=H==="selecting";be(),O.hasPointerCapture(B.pointerId)&&O.releasePointerCapture(B.pointerId),A=null,H="idle",Q&&K()};return O.addEventListener("pointerdown",oe),O.addEventListener("pointermove",ce,{passive:!1}),O.addEventListener("pointerup",pe),O.addEventListener("pointercancel",P),()=>{be(),O.removeEventListener("pointerdown",oe),O.removeEventListener("pointermove",ce),O.removeEventListener("pointerup",pe),O.removeEventListener("pointercancel",P)}},[f,i,L]),l.useImperativeHandle(g,()=>({focus:()=>x.current?.focus(),fit:W,getSelection:()=>{const O=x.current,E=O?.getSelectionPosition(),A=O?.getSelection()??"";return!E||!A.trim()?null:{text:A,startLine:E.start.y+1,endLine:E.end.y+1}}}),[W]),t.jsx("div",{ref:p,"data-terminal-owner":"main",className:q("terminal-viewport-container h-full w-full overflow-hidden touch-none",u)})});jr.displayName="TerminalViewport";const Ec="\x1B",Nr=new RegExp(`${Ec}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Rc=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[^\s<>'"`]*)?)/gi,Ac=/(?:➜\s*(?:Local|Network):)|\b(?:local|network|loopback|serving|listening|available|ready|started|running|server|vite|webpack|next\.js|astro|sveltekit|nuxt)\b/i,Bc=/Serving HTTP on .*? port (\d{2,5})/i,Mc=new Set([".",",",";",":","!","?"]),Sr=s=>{let e=s;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",o=e.slice(0,-1),a=(o.match(new RegExp(`\\${r}`,"g"))||[]).length,i=(o.match(new RegExp(`\\${n}`,"g"))||[]).length;if(a>i)break;e=o;continue}if(Mc.has(n)){e=e.slice(0,-1);continue}break}return e},_s=s=>{let e=Sr(s);return e=e.replace("0.0.0.0","127.0.0.1"),e=e.replace("[::1]","127.0.0.1"),e=e.replace("[::]","127.0.0.1"),e},Lc=s=>{if(!s)return[];const e=s.replace(Nr,""),n=[],r=new Set,o=i=>{r.has(i)||(r.add(i),n.push(i))},a=e.match(Bc);if(a?.[1]){const i=Number.parseInt(a[1],10);Number.isFinite(i)&&i>0&&i<=65535&&o(`http://127.0.0.1:${i}/`)}for(const i of e.split(`
|
|
7
|
+
`)){if(!Ac.test(i))continue;const u=Array.from(i.matchAll(Rc));if(u.length===0)continue;const f=u.find(h=>{try{return!!new URL(_s(h[1])).port}catch{return!1}});o(_s((f??u[0])[1]))}return n},Cr=s=>Lc(s)[0]??null,Fc=async(s,e=1500)=>{if(!s||typeof window>"u")return!1;let n;try{n=new URL(s)}catch{return!1}if(n.protocol!=="http:"&&n.protocol!=="https:")return!1;const r=n.hostname.toLowerCase();if(r!=="localhost"&&r!=="127.0.0.1"&&r!=="0.0.0.0"&&r!=="::1"&&r!=="::")return!1;const o=new AbortController,a=window.setTimeout(()=>o.abort(),e);try{const i=await Nt("/api/system/probe-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:n.toString()}),cache:"no-store",signal:o.signal});return i.ok?(await i.json().catch(()=>null))?.ok===!0:!1}catch{return!1}finally{window.clearTimeout(a)}},Oc=/https?:\/\/[^\s<>'"`]+/gi,Sd=(s,{requireAnnounced:e=!1}={})=>{const n=Cr(s);if(n)return n;if(e)return null;const r=String(s||"").replace(Nr,""),o=[];for(const u of r.match(Oc)??[])try{const f=new URL(Sr(u));f.port&&o.push(f)}catch{}if(o.length===0)return null;const a=u=>{const f=u.hostname.toLowerCase();return(f==="localhost"||f==="127.0.0.1"||f==="0.0.0.0"||f==="::1"?50:0)-(u.search||u.hash?10:0)};let i=o[0];for(const u of o.slice(1))a(u)>a(i)&&(i=u);return _s(i.toString())},Uc={esc:"\x1B",tab:" ",enter:"\r","arrow-up":"\x1B[A","arrow-down":"\x1B[B","arrow-left":"\x1B[D","arrow-right":"\x1B[C"},Wc=(s,e)=>{if(e&&s.startsWith("arrow-")){const n=e==="ctrl"?"5":"3",r={"arrow-up":"A","arrow-down":"B","arrow-right":"C","arrow-left":"D"}[s];return`\x1B[1;${n}${r}`}return Uc[s]},Ir=s=>{const e=s[0]?.toUpperCase();return!e||e<"A"||e>"Z"?null:String.fromCharCode(e.charCodeAt(0)&31)},zc=(s,e)=>s&&(e==="ctrl"?Ir(s)??s:s.length===1&&s!=="\x1B"?`\x1B${s}`:s),On={cols:80,rows:24},Cd=({visible:s})=>{const{t:e}=rt(),{terminal:n,runtime:r}=Hs(),{currentTheme:o}=_n(),a=l.useRef({themeMode:"dark",terminalBackground:"",terminalForeground:""});a.current={themeMode:o.metadata.variant==="light"?"light":"dark",terminalBackground:o.colors.surface.background,terminalForeground:o.colors.syntax.base.foreground};const{monoFont:i}=ea(),u=Ae(S=>S.terminalFontSize),f=Ae(S=>S.terminalShell),h=Ae(S=>S.terminalLoginShells.includes(S.terminalShell)),{isMobile:c,isTablet:g,hasTouchOnlyPointer:p}=xs(),x=c||g,d=(x||p)&&r.platform==="web",y=r.platform!=="vscode",j=Ae(S=>S.showTerminalQuickKeysOnDesktop),T=x||j,R=nt(S=>S.currentSessionId),M=nt(S=>S.newSessionDraft),G=R!==null||M?.open===!0,w=ta()??null,k=Xe(S=>w?S.sessions.get(w):void 0),I=Xe(S=>S.hasHydrated),F=Xe(S=>S.ensureDirectory),re=Xe(S=>S.createTab),te=Xe(S=>S.setActiveTab),L=Xe(S=>S.closeTab),V=Xe(S=>S.setTabSessionId),z=Xe(S=>S.setTabLifecycle),ne=Xe(S=>S.setConnecting),W=Xe(S=>S.appendToBuffer),de=Xe(S=>S.replaceBuffer),_=Xe(S=>S.setTabPreviewUrl),O=sa(S=>S.addDraft),E=Ae(S=>S.openContextPreview),A=l.useMemo(()=>k?y?k.activeTabId??k.tabs[0]?.id??null:k.tabs[0]?.id??null:null,[k,y]),U=l.useMemo(()=>{if(k)return A?k.tabs.find(S=>S.id===A)??k.tabs[0]:k.tabs[0]},[k,A]),H=l.useMemo(()=>(k?.tabs??[]).map(S=>({icon:(()=>{const ae=S.iconKey?hr[S.iconKey]??"terminal":"terminal";return t.jsx(C,{name:ae,className:"h-4 w-4"})})(),id:S.id,label:S.label,title:S.label,closeLabel:e("terminalView.tabs.closeTabTitle")})),[k?.tabs,e]),D=U?.terminalSessionId??null,se=U?.lifecycle??"idle",ue=Xe(S=>w&&A?S.getBuffer(w,A).chunks:fs.chunks),he=U?.isConnecting??!1,Ce=U?.previewUrl??null,[ke,Y]=l.useState(null),[be,$]=l.useState(!1),[le,K]=l.useState(!1),[oe,ce]=l.useState(null),[pe,P]=l.useState(!1),B=l.useRef(null),Q=l.useRef(null),me=l.useRef(A),ee=l.useRef(D),Se=l.useRef(w),Te=l.useRef(null),De=l.useRef(null),Ue=l.useRef(new Set),Ve=l.useRef(""),Me=l.useRef(new Set),Ze=l.useRef(0),Ee=l.useCallback(()=>{Ve.current="",Me.current.clear(),Ze.current+=1},[]),Ge=l.useCallback(()=>{d||typeof document<"u"&&!document.hasFocus()||Te.current?.focus()},[d]),Le=l.useCallback(()=>{d||Te.current?.focus()},[d]),Je=Ae(S=>S.activeMainTab)==="terminal",Be=s??Je,[Qe,He]=l.useState(Be);l.useEffect(()=>{Be&&He(!0)},[Be]),l.useEffect(()=>{ee.current=D},[D]),l.useEffect(()=>{!D||!n.updateAppearance||n.updateAppearance(D,a.current).catch(()=>{})},[o.colors.surface.background,o.colors.syntax.base.foreground,o.metadata.variant,n,D]),l.useEffect(()=>{me.current=A,Ee()},[A,Ee]),l.useEffect(()=>{Se.current=w},[w]),l.useEffect(()=>{!T&&oe!==null&&ce(null)},[T,oe,ce]),l.useEffect(()=>{!D&&oe!==null&&ce(null)},[D,oe,ce]);const Pe=l.useCallback(()=>{B.current?.(),B.current=null,Q.current=null,K(!1)},[]);l.useEffect(()=>()=>{Pe(),ee.current=null},[Pe]);const et=l.useCallback((S,ae,ge)=>{if(!ge)return;const qe=`${Ve.current}${ge}`.replace(/\r\n|\r/g,`
|
|
8
|
+
`),je=qe.split(`
|
|
9
|
+
`),fe=qe.endsWith(`
|
|
10
|
+
`)?je.join(`
|
|
11
|
+
`):je.slice(0,-1).join(`
|
|
12
|
+
`);if(Ve.current=qe.endsWith(`
|
|
13
|
+
`)?"":(je[je.length-1]??"").slice(-1024),!fe)return;const ie=Cr(fe);if(!ie||Me.current.has(ie))return;const We=Ze.current;Me.current.add(ie),Fc(ie).then(it=>{if(Me.current.delete(ie),!it||Ze.current!==We)return;const ut=Xe.getState().getDirectoryState(S)?.tabs.find(wt=>wt.id===ae);!ut||ut.previewUrlLocked||ut.previewUrl===ie||_(S,ae,ie,{locked:!1,autoOpened:!1})})},[_]),ze=l.useCallback((S,ae,ge)=>{if(Q.current===ge)return;Pe(),Q.current=ge;const qe=n.connect(ge,{onEvent:je=>{if(Q.current===ge)switch(je.type){case"snapshot":{ne(S,ae,!1),Y(null),$(!1),K(!1),Ge(),de(S,ae,je.data??"",je.sequence??0),et(S,ae,je.data??""),je.status==="exited"&&z(S,ae,"exited");break}case"reconnecting":{Y(null),$(!1),K(!0);break}case"data":{je.data&&(W(S,ae,je.data,je.sequence,je.replayData),et(S,ae,je.data));break}case"exit":{const fe=typeof je.exitCode=="number"?je.exitCode:null,ie=typeof je.signal=="number"?je.signal:null,it=!!Xe.getState().getDirectoryState(S)?.tabs.find(ut=>ut.id===ae)?.label?.startsWith("Action:");W(S,ae,e("terminalView.stream.processExitedMessage",{exitCodeSegment:fe!==null?e("terminalView.stream.processExitedWithCode",{exitCode:fe}):"",signalSegment:ie!==null?e("terminalView.stream.processExitedWithSignal",{signal:ie}):""})),z(S,ae,"exited"),ne(S,ae,!1),Y(it?null:e("terminalView.error.sessionEnded")),$(!1),K(!1),Pe();break}}},onError:(je,fe)=>{if(Q.current===ge){if(!fe){Y(null),$(!1);return}if(K(!1),je.code==="SESSION_NOT_FOUND"&&!Xe.getState().getDirectoryState(S)?.tabs.find(We=>We.id===ae)?.label?.startsWith("Action:")){Y(null),$(!1),ne(S,ae,!1),V(S,ae,null),z(S,ae,"idle"),Pe();return}Y(e("terminalView.error.connectionFailed",{message:je.message})),$(!0),ne(S,ae,!1),z(S,ae,"exited"),V(S,ae,null),Pe()}}});B.current=()=>{qe.close(),Q.current=null}},[W,de,Pe,Ge,et,ne,z,V,e,n]);l.useEffect(()=>{let S=!1;if(!I||!Qe)return;if(!w){Y(e(G?"terminalView.empty.noWorkingDirectory":"terminalView.empty.selectSession")),Pe();return}return(async()=>{const ge=w;if(!Se.current||Se.current!==ge)return;if(!Xe.getState().getDirectoryState(ge)){F(ge);return}const je=Xe.getState().getDirectoryState(ge);if(!je||je.tabs.length===0)return;const fe=y?je.activeTabId??je.tabs[0]?.id??null:je.tabs[0]?.id??null;if(!fe)return;const ie=je.tabs.find(vt=>vt.id===fe)??je.tabs[0],We=ie?.terminalSessionId??null,it=ie?.lifecycle??"idle",ut=!!ie?.label?.startsWith("Action:"),wt=Xe.getState().getBuffer(ge,fe),Rt=wt.byteLength>0||wt.chunks.length>0;if(!We){if(it==="exited"){ne(ge,fe,!1);return}if(ut&&Rt){ne(ge,fe,!1);return}const vt=`${ge}\0${fe}`;if(Ue.current.has(vt))return;const kt=De.current??On;Ue.current.add(vt),Y(null),$(!1),K(!1),ne(ge,fe,!0);try{const Tt=await n.createSession({cwd:ge,sessionId:fe,cols:kt.cols,rows:kt.rows,shell:f,loginShell:h,...a.current}),Ot=!S&&Se.current===ge&&me.current===fe;if(!Xe.getState().getDirectoryState(ge)?.tabs.find(Tr=>Tr.id===fe)){try{await n.close(Tt.sessionId)}catch{}return}if(V(ge,fe,Tt.sessionId),!Ot)return;const mt=De.current;mt&&(mt.cols!==kt.cols||mt.rows!==kt.rows)&&n.resize({sessionId:Tt.sessionId,...mt}).catch(()=>{});return}catch(Tt){const Ot=Xe.getState().getDirectoryState(ge)?.tabs.find(rs=>rs.id===fe);if(!Ot||Ot.terminalSessionId||(ne(ge,fe,!1),Se.current!==ge||me.current!==fe))return;Y(Tt instanceof Error?Tt.message:e("terminalView.error.startSessionFailed")),$(!0),K(!1);return}finally{Ue.current.delete(vt)}}!We||S||(ee.current=We,ze(ge,fe,We))})(),()=>{S=!0,ee.current=null,Pe()}},[G,w,D,se,A,Qe,y,I,F,ne,z,V,ze,Pe,e,n,h,f]),l.useEffect(()=>{if(!Be||d)return;if(typeof window>"u"){Ge();return}const S=window.requestAnimationFrame(()=>{Ge()});return()=>{window.cancelAnimationFrame(S)}},[A,Ge,Be,d]);const b=l.useCallback(async()=>{if(!w||pe)return;const S=Xe.getState().getDirectoryState(w),ae=y?A??S?.activeTabId??S?.tabs[0]?.id??null:S?.tabs[0]?.id??null;if(!ae)return;const ge=S?.tabs.find(qe=>qe.id===ae)?.terminalSessionId??null;if(!(!ge||!n.restartSession)){P(!0),Y(null),$(!1),K(!1),Pe(),Ee();try{const qe=De.current??On,je=await n.restartSession(ge,{cwd:w,shell:f,loginShell:h,...qe,...a.current});if(Xe.getState().getDirectoryState(w)?.tabs.find(ie=>ie.id===ae)?.terminalSessionId!==ge||(V(w,ae,je.sessionId),z(w,ae,"running"),Se.current!==w||me.current!==ae))return;ee.current=je.sessionId,ze(w,ae,je.sessionId)}catch(qe){if(Xe.getState().getDirectoryState(w)?.tabs.find(fe=>fe.id===ae)?.terminalSessionId!==ge||Se.current!==w||me.current!==ae)return;Y(qe instanceof Error?qe.message:e("terminalView.error.restartFailed")),$(!1),K(!1),ee.current=ge,ze(w,ae,ge)}finally{P(!1)}}},[A,Pe,w,y,pe,Ee,z,V,ze,e,n,h,f]),X=l.useCallback(async()=>{await b()},[b]),m=l.useCallback(()=>{if(!w)return;const S=re(w);te(w,S),Y(null),$(!1),K(!1),Pe()},[re,Pe,w,te]),v=l.useCallback(()=>{const S=Te.current?.getSelection(),ae=R??(M?.open?"draft":null);!S||!ae||!U||!w||O({directory:w,sessionKey:ae},{source:"terminal",fileLabel:U.label,startLine:S.startLine,endLine:S.endLine,code:S.text,language:U.terminalSessionId??U.id,text:""})},[U,O,R,w,M?.open]),Z=l.useCallback(S=>{w&&(te(w,S),Y(null),$(!1),K(!1),Pe())},[Pe,w,te]),ye=l.useCallback(S=>{if(!w)return;S===A&&Pe(),Y(null),$(!1),K(!1);const ae=Xe.getState().getDirectoryState(w)?.tabs.find(ge=>ge.id===S)?.terminalSessionId;(async()=>{ae&&await n.close(ae),L(w,S)})().catch(ge=>Y(ge instanceof Error?ge.message:e("terminalView.error.sessionEnded")))},[A,L,Pe,w,e,n]),xe=l.useCallback(S=>{if(!S||le)return;let ae=S,ge=!1;oe&&S.length>0&&(ae=zc(S,oe),ge=!0);const qe=ee.current;qe&&(n.sendInput(qe,ae).catch(je=>{le||Y(je instanceof Error?je.message:e("terminalView.error.sendInputFailed"))}),ge&&(ce(null),Le()))},[oe,Le,le,ce,e,n]),Oe=l.useCallback((S,ae)=>{const ge=De.current;if((!ge||ge.cols!==S||ge.rows!==ae)&&(De.current={cols:S,rows:ae}),!Be)return;const qe=ee.current;qe&&n.resize({sessionId:qe,cols:S,rows:ae}).catch(()=>{})},[Be,n]),tt=l.useCallback(S=>{ce(ae=>ae===S?null:S),Le()},[Le,ce]),Ke=l.useCallback(S=>{const ae=Wc(S,oe);ae&&(xe(ae),ce(null),Le())},[oe,Le,xe,ce]),Re=l.useMemo(()=>({Tab:"tab",Enter:"enter",ArrowUp:"arrow-up",ArrowDown:"arrow-down",ArrowLeft:"arrow-left",ArrowRight:"arrow-right",Escape:"esc"}),[]),N=l.useCallback(S=>{if(S.repeat)return;const ae=S.key;if(!ae||ae==="Control"||ae==="Meta"||ae==="Alt"||ae==="Shift")return;const ge=ae.length===1?ae.toLowerCase():ae;if(ge in Re){S.preventDefault(),S.stopPropagation(),Ke(Re[ge]);return}if(oe!=="ctrl")return;const qe=S.code??"",je=ae.length===1&&/[a-zA-Z]/.test(ae)?ae.toUpperCase():qe.startsWith("Key")&&qe.length===4?qe.slice(3).toUpperCase():null;if(je&&je.length===1&&je>="A"&&je<="Z"){const fe=Ir(je);if(!fe)return;S.preventDefault(),S.stopPropagation(),xe(fe),ce(null),Le()}},[oe,Le,Ke,xe,Re,ce]);l.useEffect(()=>{if(!(!T||!oe||!D))return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[oe,N,T,D]);const we=l.useMemo(()=>{const S=Ht[vs].stack;if(typeof window>"u")return(Ht[i]??Ht[vs]).stack;const ge=window.getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono");return ge&&ge.trim().length>0?ge.trim():(Ht[i]??Ht[vs]).stack??S},[i]),Ie=l.useMemo(()=>wc(o),[o]),Fe=`${w??"no-dir"}::${A??"no-tab"}`;if(l.useEffect(()=>{if(!Be||d)return;const S=Te.current;if(!S)return;const ae=()=>{S.fit()};if(typeof window<"u"){const ge=window.requestAnimationFrame(()=>{ae(),Ge()}),qe=[220,400].map(je=>window.setTimeout(ae,je));return()=>{window.cancelAnimationFrame(ge),qe.forEach(je=>window.clearTimeout(je))}}ae()},[Ge,Be,d,Fe,D]),l.useEffect(()=>{if(!Be||!d)return;let S=null;const ae=()=>{S!==null&&window.cancelAnimationFrame(S),S=window.requestAnimationFrame(()=>{S=null,Te.current?.fit()})};return window.addEventListener("oc:keyboard-settled",ae),()=>{window.removeEventListener("oc:keyboard-settled",ae),S!==null&&window.cancelAnimationFrame(S)}},[Be,Fe,d]),!G)return t.jsx("div",{className:"flex h-full items-center justify-center p-4 text-center text-sm text-muted-foreground",children:e("terminalView.empty.selectSession")});if(!w)return t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-sm text-muted-foreground",children:[t.jsx("p",{children:e("terminalView.empty.noWorkingDirectoryForSession")}),t.jsx("button",{onClick:b,className:"rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:e("terminalView.actions.retry")})]});const st=!D||he||pe||le,at=Qe,ot=x?"lg":"xs",dt=x?"w-10 p-0":"w-9 p-0",_e=S=>{x&&S.preventDefault()},ft=t.jsxs(t.Fragment,{children:[t.jsx(Ne,{type:"button",size:ot,variant:"outline",onPointerDown:_e,onClick:()=>Ke("esc"),disabled:st,children:e("terminalView.quickKeys.escape")}),t.jsxs(Ne,{type:"button",size:ot,variant:"outline",className:dt,onPointerDown:_e,onClick:()=>Ke("tab"),disabled:st,children:[t.jsx(C,{name:"arrow-right",className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:e("terminalView.quickKeys.tabAria")})]}),t.jsxs(Ne,{type:"button",size:ot,variant:"chip","aria-pressed":oe==="ctrl",className:x?"px-3":"px-2",onPointerDown:_e,onClick:()=>tt("ctrl"),disabled:st,children:[t.jsx("span",{className:"text-xs font-medium",children:e("terminalView.quickKeys.controlLabel")}),t.jsx("span",{className:"sr-only",children:e("terminalView.quickKeys.controlModifierAria")})]}),t.jsxs(Ne,{type:"button",size:ot,variant:"chip","aria-pressed":oe==="alt",className:x?"px-3":"px-2",onPointerDown:_e,onClick:()=>tt("alt"),disabled:st,children:[t.jsx("span",{className:"text-xs font-medium",children:e("terminalView.quickKeys.altLabel")}),t.jsx("span",{className:"sr-only",children:e("terminalView.quickKeys.altModifierAria")})]}),t.jsxs(Ne,{type:"button",size:ot,variant:"outline",className:dt,onPointerDown:_e,onClick:()=>Ke("arrow-up"),disabled:st,children:[t.jsx(C,{name:"arrow-up"}),t.jsx("span",{className:"sr-only",children:e("terminalView.quickKeys.arrowUpAria")})]}),t.jsxs(Ne,{type:"button",size:ot,variant:"outline",className:dt,onPointerDown:_e,onClick:()=>Ke("arrow-left"),disabled:st,children:[t.jsx(C,{name:"arrow-left"}),t.jsx("span",{className:"sr-only",children:e("terminalView.quickKeys.arrowLeftAria")})]}),t.jsxs(Ne,{type:"button",size:ot,variant:"outline",className:dt,onPointerDown:_e,onClick:()=>Ke("arrow-down"),disabled:st,children:[t.jsx(C,{name:"arrow-down"}),t.jsx("span",{className:"sr-only",children:e("terminalView.quickKeys.arrowDownAria")})]}),t.jsxs(Ne,{type:"button",size:ot,variant:"outline",className:dt,onPointerDown:_e,onClick:()=>Ke("arrow-right"),disabled:st,children:[t.jsx(C,{name:"arrow-right"}),t.jsx("span",{className:"sr-only",children:e("terminalView.quickKeys.arrowRightAria")})]}),t.jsxs(Ne,{type:"button",size:ot,variant:"outline",className:dt,onPointerDown:_e,onClick:()=>Ke("enter"),disabled:st,children:[t.jsx(C,{name:"arrow-go-back"}),t.jsx("span",{className:"sr-only",children:e("terminalView.quickKeys.enterAria")})]})]});return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-[var(--surface-background)]",children:[t.jsxs("div",{className:q("app-region-no-drag sticky top-0 z-20 shrink-0 bg-[var(--surface-background)] text-xs",x?"px-3 py-1.5":"pl-3 pr-1.5 py-1"),children:[y&&k?t.jsxs("div",{className:"flex items-center gap-2 pl-1 pr-1",children:[t.jsx("div",{className:q("min-w-0 flex-1",x?"h-8":"h-7"),children:t.jsx(Qt,{items:H,activeId:A,onSelect:Z,onClose:ye,layoutMode:"scrollable",variant:"default",className:"h-full bg-transparent"})}),t.jsx(Ne,{type:"button",size:"xs",variant:"ghost",className:q("shrink-0",x?"h-8 w-8 p-0":"h-7 w-7 p-0"),onClick:m,title:e("terminalView.tabs.newTabTitle"),children:t.jsx(C,{name:"add",className:`${x?"h-[18px] w-[18px]":"h-4 w-4"}`})}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1 overflow-visible",children:[t.jsx(Ne,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{b()},disabled:pe,title:e("terminalView.actions.restart"),"aria-label":e("terminalView.actions.restart"),children:t.jsx(C,{name:"restart",className:"h-4 w-4"})}),t.jsx(Ne,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 p-0",onClick:v,title:e("terminalView.actions.attachSelection"),"aria-label":e("terminalView.actions.attachSelection"),children:t.jsx(C,{name:"attachment-2",className:"h-4 w-4"})}),Ce?t.jsxs(Ne,{type:"button",size:"xs",variant:"outline",className:"h-6 shrink-0 gap-1 px-2",onClick:()=>{w&&E(w,Ce)},title:e("terminalView.preview.openTitle"),children:[t.jsx(C,{name:"global",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"whitespace-nowrap",children:e("terminalView.preview.open")})]}):null]})]}):null,!x&&T&&y&&k?t.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1 pl-1 pr-1",children:ft}):null,!x&&T&&(!y||!k)?t.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1",children:ft}):null]}),t.jsxs("div",{className:"relative flex-1 overflow-hidden",style:{backgroundColor:Ie.background},children:[t.jsx("div",{className:"h-full w-full box-border pl-4 pr-1.5 pt-3 pb-4",children:at?t.jsx(jr,{ref:S=>{Te.current=S},sessionKey:Fe,chunks:ue,onInput:xe,onResize:Oe,theme:Ie,fontFamily:we,fontSize:u,enableTouchScroll:d,autoFocus:Be,isVisible:Be},Fe):null}),!le&&ke&&t.jsxs("div",{className:"absolute inset-x-0 bottom-0 bg-[var(--status-error-background)] px-3 py-2 text-xs text-[var(--status-error-foreground)] flex items-center justify-between gap-2",children:[t.jsx("span",{children:ke}),be&&x&&t.jsx(Ne,{size:"sm",variant:"secondary",className:"h-6 px-2 py-0 text-xs",onClick:X,disabled:pe,title:e("terminalView.actions.hardRestartTitle"),type:"button",children:e("terminalView.actions.hardRestart")})]})]}),x&&T?t.jsx("div",{className:"shrink-0 overflow-x-auto border-t border-border/40 bg-[var(--surface-background)] px-2 pt-1.5 pb-[max(0.375rem,calc(var(--oc-app-bottom-safe,0px)-var(--oc-keyboard-inset,0px)))] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:t.jsx("div",{className:"flex min-w-max items-center gap-1.5",children:ft})}):null]})},Id=()=>{Xn(),_t.reconnectToRuntimeBaseUrl(),qn()},Td=s=>{nt.getState().prepareForRuntimeSwitch(s.previousRuntimeKey),Ae.getState().prepareForRuntimeSwitch(s.previousRuntimeKey),s.previousRuntimeKey&&na.getState().stopRunningRunsForRuntime(s.previousRuntimeKey),Xn(),Xe.getState().clearAll(),_t.reconnectToRuntimeBaseUrl(),pt.setState({providers:[],agents:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),gt.getState().resetForRuntimeSwitch(),As.getState().resetForRuntimeSwitch(),ra.setState({statusById:new Map}),oa(),aa(),ia.getState().reset(),Ia.getState().resetForRuntimeSwitch(),Ks.getState().resetForRuntimeSwitch(s.runtimeKey),la.getState().resetForRuntimeSwitch(),ca.getState().resetForRuntimeSwitch(s.runtimeKey),Ta.getState().resetForRuntimeSwitch(s.runtimeKey),nt.getState().restoreForRuntimeSwitch(s.runtimeKey),Ae.getState().restoreForRuntimeSwitch(s.runtimeKey),qn(),queueMicrotask(()=>{Pa()})};export{ad as A,fl as B,rd as C,vd as D,gd as E,fd as F,Jl as G,pd as H,sd as I,Bt as J,pl as K,Ns as L,jd as M,kd as N,nd as O,Nd as P,gl as Q,Si as R,yd as S,Cd as T,td as U,ed as V,Qi as W,wd as X,Ol as a,Qt as b,Td as c,bd as d,xd as e,od as f,Zc as g,Nn as h,Xe as i,Xi as j,md as k,hr as l,Lc as m,Zi as n,Sd as o,hd as p,ki as q,Id as r,ji as s,ud as t,ri as u,Ni as v,ld as w,dd as x,cd as y,id as z};
|