@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,14 @@
|
|
|
1
|
+
import{R as n,j as s,f as Ut}from"./vendor-react-BUCujlKS.js";import{P as Un,Q as Gn,R as Kn,S as Hn,ag as xi,m as ze,u as he,cS as qn,A as vi,t as _n,r as wi,T as bi,e as Qn,cQ as Jn,aG as Xn,cR as Yn}from"./index-DRpChWux.js";import{f as Vs,S as ks,B as S,h as O,V as Zn,L as ea,aV as ta,a0 as sa,a1 as ra,b_ as ia,gO as yi,gm as na,t as I,l as ji,aa as er,bV as js,cq as aa,b as oa,gP as tr,ab as Fi,gQ as Ni,bW as Ci,bX as la,fI as ca,gR as da,br as ua,gS as fa,bs as Ai,bt as Ii,bu as Oi,bv as Bi,bw as $i,bx as Wi,I as g,aU as or,aR as lr,ad as Ns,aT as cr,aQ as Cs,aX as ht,aY as pt,aZ as gt,bU as sr,ac as rr,bQ as Si,by as ma,bz as ha,gk as ir,g as Ts,aS as pa,a_ as ga}from"./useAppFontEffects-BikB6enL.js";import{w as xa,x as va,y as wa,z as ba,A as ya}from"./runtimeEndpointReset-BVmispdD.js";import{c as ki,s as ja,C as Ti,P as nr}from"./shikiHighlight-C7LTbwFx.js";import{a as Fa}from"./vendor-codemirror-state-CNWM3Q8V.js";import{E as kt}from"./vendor-codemirror-view-DSzLbZiS.js";import{F as Na,J as Ca}from"./JsonTreeView-DLW2Wy1g.js";import{ensurePierreThemeRegistered as Vi,getResolvedShikiTheme as Sa}from"./appThemeRegistry-BK0dHKa6.js";import{D as ka}from"./DiagramEditor-jnG3Hbxg.js";import{u as Ta,n as Va}from"./useInlineCommentController-CYPvYJDt.js";import{b as Da}from"./CodeMirrorCommentWidgets-4qZbrEXU.js";import{u as Fs,c as Ea}from"./scheduledTasksApi-ByKya3Un.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-B-bSg3P5.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CLHw8NWn.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-codemirror-search-8kyQdB3f.js";import"./vendor-replit-codemirror-vim-B0Ecqnlh.js";import"./web-components-GMc3oR3i.js";import"./computeVirtualFileMetrics-Da00Jg7M.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./Virtualizer-X_7XPoTH.js";import"./isFilePlainText-gTibdNIe.js";import"./registerCustomTheme-BBXUCRnG.js";import"./vendor-react-drawio-Ct3Q0DsD.js";const Pa=(d,e)=>{if(!e)return null;const r=Number.parseInt(d.trim(),10);return!Number.isFinite(r)||r<1?null:Math.min(r,e.state.doc.lines)},Di=(d,e)=>{const r=d.state.doc.lineAt(e.main.head);return{lineNumber:r.number,character:e.main.head-r.from+1,selection:e}},Ei=(d,e,r)=>{const m=d.state.doc.line(e),x=Math.max(1,Math.min(r,m.length+1)),v=m.from+x-1;d.dispatch({selection:Fa.cursor(v),effects:kt.scrollIntoView(v,{y:"center"})})};function Ra({open:d,onOpenChange:e,view:r,variant:m="overlay"}){const{t:x}=Vs(),[v,y]=n.useState(""),b=n.useRef(null),h=n.useRef(!1),j=n.useRef(null),p=n.useRef(null),F=n.useMemo(()=>Pa(v,r),[v,r]);n.useEffect(()=>{!d||!r||(h.current=!1,b.current=Di(r,r.state.selection),y(""))},[d,r]),n.useEffect(()=>{d&&window.requestAnimationFrame(()=>{p.current?.focus(),p.current?.select()})},[d]),n.useEffect(()=>{if(!(!d||!r||!b.current)){if(F===null){const{selection:a}=b.current;r.dispatch({selection:a,effects:kt.scrollIntoView(a.main.from,{y:"center"})});return}Ei(r,F,b.current.character)}},[F,d,r]);const M=n.useCallback(()=>{if(!r||h.current||!b.current)return;const{selection:a}=b.current;r.dispatch({selection:a,effects:kt.scrollIntoView(a.main.from,{y:"center"})})},[r]),E=n.useCallback(a=>{a||M(),e(a)},[e,M]),N=n.useCallback(()=>{!r||F===null||!b.current||(h.current=!0,Ei(r,F,b.current.character),e(!1),r.focus())},[F,e,r]);n.useEffect(()=>{if(!d)return;const a=W=>{const _=j.current,L=W.target;!_||!(L instanceof Node)||_.contains(L)||E(!1)},q=W=>{W.key==="Escape"&&(W.preventDefault(),E(!1))};return document.addEventListener("pointerdown",a,!0),document.addEventListener("keydown",q,!0),()=>{document.removeEventListener("pointerdown",a,!0),document.removeEventListener("keydown",q,!0)}},[E,d,m]);const P=n.useMemo(()=>{if(!r)return x("goToLineDialog.helper.editorUnavailable");if(F===null){const a=b.current??Di(r,r.state.selection);return x("goToLineDialog.helper.currentLineRange",{current:a.lineNumber,max:r.state.doc.lines})}return x("goToLineDialog.helper.goToLine",{line:F})},[F,x,r]);return m==="inline"?d?s.jsxs("div",{ref:j,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(ks,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:v,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),N())},placeholder:x("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(S,{variant:"outline",size:"xs",onClick:N,disabled:!r||F===null,className:"h-6 px-2",children:x("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:j,className:O("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",d?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(ks,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:v,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),N())},placeholder:x("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:P})]})})}function Ma(d){return!(!d.autoSaveEnabled||!d.isDirty||!d.canWrite||d.isSaving||d.fileLoading||d.isNonEditableBinary||!d.selectedFilePath||d.loadedFilePath!==d.selectedFilePath)}function za(d){return d.selectedFilePath?d.isDirty?!(d.fileLoading||d.loadedFilePath!==d.selectedFilePath||d.isNonEditableBinary||d.draftContent===""&&d.fileContent!==""&&d.loadedFilePath!==d.selectedFilePath):!0:!1}const La=d=>{const e=z(d);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const r=e.lastIndexOf("/");if(r<0)return e;if(r===0)return"/";const m=e.slice(0,r);return/^[A-Za-z]:$/.test(m)?`${m}/`:m},Aa=d=>{const e=Ut.c(8),{label:r,iconDataUrl:m}=d,[x,v]=n.useState(!1);let y;e[0]!==r?(y=r.trim().slice(0,1).toUpperCase()||"?",e[0]=r,e[1]=y):y=e[1];const b=y;if(m&&!x){let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>v(!0),e[2]=p):p=e[2];let F;return e[3]!==m?(F=s.jsx("img",{src:m,alt:"",className:"size-4 rounded-sm",onError:p}),e[3]=m,e[4]=F):F=e[4],F}let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=O("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=h):h=e[5];let j;return e[6]!==b?(j=s.jsx("span",{className:h,children:b}),e[6]=b,e[7]=j):j=e[7],j},Ia=d=>d.slice().sort((e,r)=>e.type!==r.type?e.type==="directory"?-1:1:e.name.localeCompare(r.name)),z=d=>{if(!d)return"";const e=d.replace(/\\/g,"/"),r=e.startsWith("//");let m=e.replace(/\/+/g,"/");r&&!m.startsWith("//")&&(m=`/${m}`);const x=m==="/",v=/^[A-Za-z]:\/$/.test(m);return!x&&!v&&(m=m.replace(/\/+$/,"")),m},Oa=d=>d.startsWith("/")||d.startsWith("//")||/^[A-Za-z]:\//.test(d),Wt=d=>/^[A-Za-z]:\//.test(d)?d.toLowerCase():d,rs=(d,e)=>{const r=z(e),m=z(d);if(!r||!m)return!1;const x=Wt(r),v=Wt(m);return v===x||v.startsWith(`${x}/`)},Pi=(d,e)=>{const r=z(e),m=z(d);if(!rs(m,r))return[];const v=m.slice(r.length).replace(/^\//,"").split("/"),y=[];let b=r;for(let h=0;h<v.length-1;h++)b=b?`${b}/${v[h]}`:v[h],y.push(b);return y},Ss=(d,e)=>{if(!e)return"";const r=z(e);if(!d||!rs(r,d))return r;const m=r.slice(d.length);return m.startsWith("/")?m.slice(1):m},Ba=new Set(["node_modules"]),$a=d=>{const e=Ut.c(3),{status:r}=d;let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=m):m=e[0];const x=m[r];let v;return e[1]!==x?(v=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:x}}),e[1]=x,e[2]=v):v=e[2],v},Ri=d=>{const e=Ut.c(11),{name:r}=d,m=n.useRef(null),x=n.useRef(null),[v,y]=n.useState(!1);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const M=m.current,E=x.current;if(!M||!E)return;const N=()=>{y(E.scrollWidth>M.clientWidth+1)};N();const P=new ResizeObserver(N);return P.observe(M),P.observe(E),()=>{P.disconnect()}},e[0]=b):b=e[0];let h;e[1]!==r?(h=[r],e[1]=r,e[2]=h):h=e[2],n.useLayoutEffect(b,h);let j;e[3]!==r?(j=s.jsx("span",{ref:x,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:r}),e[3]=r,e[4]=j):j=e[4];let p;e[5]!==r||e[6]!==v?(p=v?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:r}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:r})]}):s.jsx("span",{className:"block min-w-0 truncate",children:r}),e[5]=r,e[6]=v,e[7]=p):p=e[7];let F;return e[8]!==j||e[9]!==p?(F=s.jsxs("span",{ref:m,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[j,p]}),e[8]=j,e[9]=p,e[10]=F):F=e[10],F},Wa=d=>Ba.has(d),Ua=d=>{const e=z(d);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ga=d=>{const r=(d instanceof Error?d.message:String(d??"")).toLowerCase();return r.includes("is a directory")||r.includes("eisdir")},Mi=d=>{const r=(d instanceof Error?d.message:String(d??"")).toLowerCase();return r.includes("file not found")||r.includes("enoent")||r.includes("no such file")||r.includes("does not exist")},ss=2e5,Ka=d=>{let e=0,r=0;for(let m=0;m<d.length;m+=1)d.charCodeAt(m)===10&&(m>0&&d.charCodeAt(m-1)===13?e+=1:r+=1);return e>r?`\r
|
|
2
|
+
`:`
|
|
3
|
+
`},Ui=d=>d.replace(/\r\n/g,`
|
|
4
|
+
`).replace(/\r/g,`
|
|
5
|
+
`),Ha=(d,e)=>{const r=Ui(d);return e===`\r
|
|
6
|
+
`?r.replace(/\n/g,`\r
|
|
7
|
+
`):r},Gi=(d,e)=>s.jsx(Ns,{filePath:d,extension:e}),zi=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},qa=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},ar=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="html"||e==="htm"},_a=d=>{const e=Ut.c(76),{node:r,root:m,isExpanded:x,isActive:v,isMobile:y,isBrowserClient:b,alwaysShowActions:h,status:j,badge:p,permissions:F,downloadFile:M,contextMenuPath:E,setContextMenuPath:N,rightClickMenuPath:P,setRightClickMenuPath:a,onSelect:q,onToggle:W,onRevealPath:_,onOpenDialog:L}=d,{t:T}=Vs(),V=r.type==="directory",{canRename:le,canCreateFile:X,canCreateFolder:Y,canDelete:A,canReveal:ce}=F,Le=!V&&!!M,U=ce&&!b,Q=le||X||Y||A||Le||U;let Z;e[0]!==Q||e[1]!==r.path||e[2]!==a?(Z=fe=>{Q&&(fe?.preventDefault(),a(r.path))},e[0]=Q,e[1]=r.path,e[2]=a,e[3]=Z):Z=e[3];const pe=Z;let ee;e[4]!==V||e[5]!==r||e[6]!==q||e[7]!==W?(ee=()=>{V?W(r.path):q(r)},e[4]=V,e[5]=r,e[6]=q,e[7]=W,e[8]=ee):ee=e[8];const ge=ee;let de;e[9]!==r.path||e[10]!==N||e[11]!==a?(de=fe=>{fe.stopPropagation(),a(null),N(r.path)},e[9]=r.path,e[10]=N,e[11]=a,e[12]=de):de=e[12];const rt=de;let Tt;e[13]!==X||e[14]!==Y||e[15]!==A||e[16]!==le||e[17]!==U||e[18]!==M||e[19]!==b||e[20]!==V||e[21]!==r||e[22]!==L||e[23]!==_||e[24]!==m||e[25]!==T?(Tt=fe=>{const{Item:ve,Separator:wt}=fe;return s.jsxs(s.Fragment,{children:[le&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("rename",r)},children:[s.jsx(g,{name:"edit",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.rename")]}),s.jsxs(ve,{onClick:C=>{C.stopPropagation(),Ts(r.path).then(we=>{if(we.ok){I.success(T("sidebarFilesTree.toast.pathCopied"));return}I.error(T("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.copyPath")]}),s.jsxs(ve,{onClick:C=>{C.stopPropagation();const we=Ss(m,r.path)||r.path;Ts(we).then(Qe=>{if(Qe.ok){I.success(T("filesView.toast.relativePathCopied"));return}I.error(T("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy-2",className:"mr-2 size-4"})," ",T("filesView.tree.menu.copyRelativePath")]}),!V&&M&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),M(r.path).catch(we=>{console.error("Download failed:",we),I.error(T("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"})," ",T(b?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),U&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),_(r.path)},children:[s.jsx(g,{name:"folder-received",className:"mr-2 size-4"})," ",T(ga())]}),V&&(X||Y)&&s.jsxs(s.Fragment,{children:[s.jsx(wt,{}),X&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("createFile",r)},children:[s.jsx(g,{name:"file-add",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.newFile")]}),Y&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("createFolder",r)},children:[s.jsx(g,{name:"folder-add",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.newFolder")]})]}),A&&s.jsxs(s.Fragment,{children:[s.jsx(wt,{}),s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("delete",r)},className:"text-destructive focus:text-destructive",children:[s.jsx(g,{name:"delete-bin",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.delete")]})]})]})},e[13]=X,e[14]=Y,e[15]=A,e[16]=le,e[17]=U,e[18]=M,e[19]=b,e[20]=V,e[21]=r,e[22]=L,e[23]=_,e[24]=m,e[25]=T,e[26]=Tt):Tt=e[26];const _e=Tt,G=P===r.path;let Fe;e[27]!==r.path||e[28]!==a?(Fe=fe=>a(fe?r.path:null),e[27]=r.path,e[28]=a,e[29]=Fe):Fe=e[29];const xt=y?void 0:pe;let Ae;e[30]!==xt?(Ae=s.jsx("div",{className:"group relative flex items-center",onContextMenu:xt}),e[30]=xt,e[31]=Ae):Ae=e[31];const Ie=y?void 0:pe,vt=v?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let xe;e[32]!==vt?(xe=O("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",vt),e[32]=vt,e[33]=xe):xe=e[33];let Oe;e[34]!==V||e[35]!==x||e[36]!==r.extension||e[37]!==r.path?(Oe=V?x?s.jsx(g,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(g,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):Gi(r.path,r.extension),e[34]=V,e[35]=x,e[36]=r.extension,e[37]=r.path,e[38]=Oe):Oe=e[38];let ue;e[39]!==r.name||e[40]!==r.path?(ue=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:r.path,children:r.name}),e[39]=r.name,e[40]=r.path,e[41]=ue):ue=e[41];let Ne;e[42]!==V||e[43]!==j?(Ne=!V&&j&&s.jsx($a,{status:j}),e[42]=V,e[43]=j,e[44]=Ne):Ne=e[44];let it;e[45]!==p||e[46]!==V?(it=V&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[45]=p,e[46]=V,e[47]=it):it=e[47];let nt;e[48]!==ge||e[49]!==xe||e[50]!==Oe||e[51]!==ue||e[52]!==Ne||e[53]!==it||e[54]!==Ie?(nt=s.jsxs("button",{type:"button",onClick:ge,onContextMenu:Ie,className:xe,children:[Oe,ue,Ne,it]}),e[48]=ge,e[49]=xe,e[50]=Oe,e[51]=ue,e[52]=Ne,e[53]=it,e[54]=Ie,e[55]=nt):nt=e[55];let Be;e[56]!==h||e[57]!==E||e[58]!==rt||e[59]!==Q||e[60]!==y||e[61]!==r.path||e[62]!==_e||e[63]!==N?(Be=Q&&s.jsx("div",{className:O("absolute right-1 top-1/2 -translate-y-1/2",h?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(or,{open:E===r.path,onOpenChange:fe=>N(fe?r.path:null),children:[s.jsx(lr,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"icon",className:"size-6",onClick:rt,children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})}),s.jsx(cr,{align:"end",side:"bottom",onCloseAutoFocus:()=>N(null),children:_e({Item:Cs,Separator:pa})})]})}),e[56]=h,e[57]=E,e[58]=rt,e[59]=Q,e[60]=y,e[61]=r.path,e[62]=_e,e[63]=N,e[64]=Be):Be=e[64];let $e;e[65]!==nt||e[66]!==Be||e[67]!==Ae?($e=s.jsxs(ba,{render:Ae,children:[nt,Be]}),e[65]=nt,e[66]=Be,e[67]=Ae,e[68]=$e):$e=e[68];let We;e[69]!==_e?(We=s.jsx(xa,{className:"min-w-[180px]",children:_e({Item:wa,Separator:va})}),e[69]=_e,e[70]=We):We=e[70];let at;return e[71]!==$e||e[72]!==We||e[73]!==G||e[74]!==Fe?(at=s.jsxs(ya,{open:G,onOpenChange:Fe,children:[$e,We]}),e[71]=$e,e[72]=We,e[73]=G,e[74]=Fe,e[75]=at):at=e[75],at},Qa=d=>{const e=Ut.c(83),{activeDialog:r,dialogData:m,dialogInputValue:x,onDialogInputChange:v,isDialogSubmitting:y,onDialogSubmit:b,onClose:h,inputRef:j}=d,{t:p}=Vs(),F=!!r;let M;e[0]!==h?(M=de=>!de&&h(),e[0]=h,e[1]=M):M=e[1];let E;e[2]!==r||e[3]!==p?(E=r==="createFile"&&p("filesView.dialog.createFile.title"),e[2]=r,e[3]=p,e[4]=E):E=e[4];let N;e[5]!==r||e[6]!==p?(N=r==="createFolder"&&p("filesView.dialog.createFolder.title"),e[5]=r,e[6]=p,e[7]=N):N=e[7];let P;e[8]!==r||e[9]!==p?(P=r==="rename"&&p("filesView.dialog.rename.title"),e[8]=r,e[9]=p,e[10]=P):P=e[10];let a;e[11]!==r||e[12]!==p?(a=r==="delete"&&p("filesView.dialog.delete.title"),e[11]=r,e[12]=p,e[13]=a):a=e[13];let q;e[14]!==E||e[15]!==N||e[16]!==P||e[17]!==a?(q=s.jsxs(Bi,{children:[E,N,P,a]}),e[14]=E,e[15]=N,e[16]=P,e[17]=a,e[18]=q):q=e[18];let W;e[19]!==r||e[20]!==m?.path||e[21]!==p?(W=r==="createFile"&&p("filesView.dialog.createFile.description",{path:m?.path??p("filesView.dialog.rootFallback")}),e[19]=r,e[20]=m?.path,e[21]=p,e[22]=W):W=e[22];let _;e[23]!==r||e[24]!==m?.path||e[25]!==p?(_=r==="createFolder"&&p("filesView.dialog.createFolder.description",{path:m?.path??p("filesView.dialog.rootFallback")}),e[23]=r,e[24]=m?.path,e[25]=p,e[26]=_):_=e[26];let L;e[27]!==r||e[28]!==m?.name||e[29]!==p?(L=r==="rename"&&p("filesView.dialog.rename.description",{name:m?.name??""}),e[27]=r,e[28]=m?.name,e[29]=p,e[30]=L):L=e[30];let T;e[31]!==r||e[32]!==m?.name||e[33]!==p?(T=r==="delete"&&p("filesView.dialog.delete.description",{name:m?.name??""}),e[31]=r,e[32]=m?.name,e[33]=p,e[34]=T):T=e[34];let V;e[35]!==L||e[36]!==T||e[37]!==W||e[38]!==_?(V=s.jsxs($i,{children:[W,_,L,T]}),e[35]=L,e[36]=T,e[37]=W,e[38]=_,e[39]=V):V=e[39];let le;e[40]!==V||e[41]!==q?(le=s.jsxs(Oi,{children:[q,V]}),e[40]=V,e[41]=q,e[42]=le):le=e[42];let X;e[43]!==r||e[44]!==x||e[45]!==j||e[46]!==v||e[47]!==b||e[48]!==p?(X=r!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(ks,{value:x,onChange:de=>v(de.target.value),placeholder:p(r==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:de=>{de.key==="Enter"&&b()},ref:j})}),e[43]=r,e[44]=x,e[45]=j,e[46]=v,e[47]=b,e[48]=p,e[49]=X):X=e[49];let Y;e[50]!==p?(Y=p("filesView.dialog.cancel"),e[50]=p,e[51]=Y):Y=e[51];let A;e[52]!==y||e[53]!==h||e[54]!==Y?(A=s.jsx(S,{variant:"outline",onClick:h,disabled:y,children:Y}),e[52]=y,e[53]=h,e[54]=Y,e[55]=A):A=e[55];const ce=r==="delete"?"destructive":"default";let Le;e[56]!==b?(Le=()=>{b()},e[56]=b,e[57]=Le):Le=e[57];let U;e[58]!==r||e[59]!==x||e[60]!==y?(U=y||r!=="delete"&&!x.trim(),e[58]=r,e[59]=x,e[60]=y,e[61]=U):U=e[61];let Q;e[62]!==r||e[63]!==y||e[64]!==p?(Q=y?s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}):p(r==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=r,e[63]=y,e[64]=p,e[65]=Q):Q=e[65];let Z;e[66]!==ce||e[67]!==Le||e[68]!==U||e[69]!==Q?(Z=s.jsx(S,{variant:ce,onClick:Le,disabled:U,children:Q}),e[66]=ce,e[67]=Le,e[68]=U,e[69]=Q,e[70]=Z):Z=e[70];let pe;e[71]!==A||e[72]!==Z?(pe=s.jsxs(Wi,{children:[A,Z]}),e[71]=A,e[72]=Z,e[73]=pe):pe=e[73];let ee;e[74]!==j||e[75]!==le||e[76]!==X||e[77]!==pe?(ee=s.jsxs(Ii,{initialFocus:j,children:[le,X,pe]}),e[74]=j,e[75]=le,e[76]=X,e[77]=pe,e[78]=ee):ee=e[78];let ge;return e[79]!==F||e[80]!==M||e[81]!==ee?(ge=s.jsx(Ai,{open:F,onOpenChange:M,children:ee}),e[79]=F,e[80]=M,e[81]=ee,e[82]=ge):ge=e[82],ge},Li=(d,e,r)=>{const m=Ut.c(8),[x,v]=n.useState(""),[y,b]=n.useState(0);let h,j;m[0]!==d||m[1]!==r||m[2]!==e?(h=()=>{if(!d){v("");return}let F=!1;v("");const M=Qn(),E=Jn(M);Xn(M).then(P=>{F||!P||(v(d),e(null))}).catch(P=>{F||(e(P instanceof Error?P.message:r),v(d))});const N=Yn(()=>{F||(v(d),b(Ja),e(null))});return()=>{F=!0,E(),N()}},j=[d,e,r],m[0]=d,m[1]=r,m[2]=e,m[3]=h,m[4]=j):(h=m[3],j=m[4]),n.useEffect(h,j);let p;return m[5]!==y||m[6]!==x?(p={readyKey:x,nonce:y},m[5]=y,m[6]=x,m[7]=p):p=m[7],p},mc=({mode:d="full"})=>{const{t:e}=Vs(),{files:r,runtime:m}=Zn(),{currentTheme:x,availableThemes:v,lightThemeId:y,darkThemeId:b}=ea(),{isMobile:h,isTablet:j,screenWidth:p}=ta(),F=Un(m.platform),M=h||j,E=Gn(),N=Kn(),P=sa()??"",a=z(P.trim()),q=d!=="editor-only",W=d==="editor-only"&&!h,_=Hn(t=>t.searchFiles),L=ra(P),[T,V]=n.useState(""),le=ia(T,200),X=n.useRef(null),[Y,A]=n.useState(!1),[ce,Le]=n.useState(!0),[U,Q]=n.useState(!1),[Z,pe]=n.useState(!1),[ee,ge]=n.useState(!1),de=n.useRef(null),rt=n.useRef(0),Tt=n.useCallback(t=>{rt.current=Math.max(0,rt.current+(t?1:-1))},[]),_e=n.useCallback(t=>t instanceof Element?t.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);n.useEffect(()=>{if(!ee)return;const t=i=>{rt.current>0||_e(i.target)||de.current&&!de.current.contains(i.target)&&ge(!1)};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[_e,ee]);const[G,Fe]=n.useState("edit"),[xt,Ae]=n.useState("edit"),[Ie,vt]=n.useState("tree"),[xe,Oe]=n.useState("edit"),[ue,Ne]=n.useState("preview"),[it,nt]=n.useState(0),Be=n.useRef({}),$e=n.useRef({}),We=n.useRef({}),at=n.useRef({}),fe=n.useMemo(()=>v.find(t=>t.metadata.id===y)??xi(!1),[v,y]),ve=n.useMemo(()=>v.find(t=>t.metadata.id===b)??xi(!0),[v,b]);n.useEffect(()=>{Vi(fe),Vi(ve)},[fe,ve]);const wt=n.useMemo(()=>[],[]),C=ze(t=>a?t.byRoot[a]?.openPaths??wt:wt),we=ze(t=>a?t.byRoot[a]?.selectedPath??null:null),Qe=ze(t=>a?t.byRoot[a]?.expandedPaths??wt:wt),Vt=ze(t=>t.removeOpenPath),ot=ze(t=>t.removeOpenPathsByPrefix),dr=ze(t=>t.removeExpandedPathsByPrefix),te=ze(t=>t.setSelectedPath),ur=ze(t=>t.toggleExpandedPath),is=ze(t=>t.expandPaths),Dt=n.useCallback(t=>{const i=z(t),o=i.split("/"),c=o[o.length-1]||i,u=c.includes(".")?c.split(".").pop()?.toLowerCase():void 0;return{name:c,path:i,type:"file",extension:u}},[]),Et=n.useMemo(()=>C.map(Dt),[C,Dt]),Ds=n.useMemo(()=>{if(we){const t=Wt(we);if(C.some(i=>Wt(i)===t))return we}return C[0]??null},[C,we]),l=n.useMemo(()=>Ds?Dt(Ds):null,[Ds,Dt]),Ue=l?.path??"";n.useEffect(()=>{if(!a||!we)return;const t=Wt(we);C.some(o=>Wt(o)===t)||te(a,C[0]??null)},[C,a,we,te]);const ns=!!(a&&Ue&&!rs(Ue,a)),fr=ns?yi(Ue):void 0,Ce=n.useMemo(()=>({allowOutsideWorkspace:d==="editor-only"&&ns,outsideFileGrant:fr,directory:a||void 0}),[d,ns,fr,a]),Es=n.useRef(null),[mr,Ki]=n.useState({left:!1,right:!1}),hr=n.useCallback(()=>{const t=Es.current;t&&Ki({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),pr=n.useRef(hr);pr.current=hr,n.useEffect(()=>{const t=Es.current;if(!t)return;const i=()=>pr.current();i(),t.addEventListener("scroll",i,{passive:!0});const o=new ResizeObserver(i);return o.observe(t),()=>{t.removeEventListener("scroll",i),o.disconnect()}},[Et.length]);const[gr,Ps]=n.useState({}),[as,Gt]=n.useState({}),Se=n.useRef(new Set),ke=n.useRef(new Set),Je=n.useRef(new Map),xr=n.useRef(0),[vr,os]=n.useState([]),[Hi,ls]=n.useState(!1),[k,K]=n.useState(""),{isPlaying:cs,play:qi,stop:_i}=na(),[Ee,Xe]=n.useState(!1),[Ye,se]=n.useState(null),[Qi,Pe]=n.useState(""),[be,H]=n.useState(null),[B,J]=n.useState(""),[Pt,Rs]=n.useState(!1),[wr,Ji]=n.useState(`
|
|
8
|
+
`),Xi=n.useRef(null),Ge=n.useRef(null),ye=n.useRef(null),lt=n.useRef(""),Kt=n.useRef(""),Ze=n.useRef(null),br=n.useRef(null),et=n.useRef(null),ds=n.useRef(0),Ht=n.useRef(null),[Yi,Rt]=n.useState("idle"),[Zi,us]=n.useState(!1),[qt,yr]=n.useState(!1),re=he(t=>t.autoSaveEnabled),en=he(t=>t.setAutoSaveEnabled),[Ms,Mt]=n.useState(!1),zt=n.useRef(null),_t=n.useRef(null),Qt=n.useRef(null),bt=n.useRef(!1),Jt=n.useRef(null),Xt=n.useRef(null),Re=n.useRef(null),tn=n.useRef(null),[sn,zs]=n.useState(0),Lt=n.useRef(null),yt=n.useRef({key:"",attempts:0});n.useEffect(()=>()=>{Lt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Lt.current),Lt.current=null)},[]);const[jt,Ls]=n.useState(null),[Ft,rn]=n.useState(null),[ct,jr]=n.useState(""),[nn,As]=n.useState(!1),[an,on]=n.useState(null),[ln,cn]=n.useState(null),[dn,Fr]=n.useState(!1),[un,Nr]=n.useState(!1),[fn,Is]=n.useState(!1),Cr=!!r.writeFile,Sr=!!r.createDirectory,kr=!!r.rename,Tr=!!r.delete,Vr=!!r.revealPath,mn=Fs(t=>t.availableApps),hn=Fs(t=>t.isCacheStale),Dr=Fs(t=>t.initialize),pn=Fs(t=>t.loadInstalledApps);n.useEffect(()=>{Dr()},[Dr]);const gn=n.useCallback(t=>{r.revealPath&&r.revealPath(t).catch(()=>{I.error(e("sidebarFilesTree.toast.revealFailed"))})},[r,e]),xn=n.useCallback(async t=>{if(!l?.path||await qn(l.path,t.id,t.appName)||await vi(l.path,t.appName))return;const c=La(l.path)||a;c&&await vi(c,t.appName)||I.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[a,l?.path,e]),Os=n.useCallback((t,i)=>{Ls(t),rn(i),jr(t==="rename"&&i.name||""),As(!1)},[]),[R,Me]=n.useState(null),At=n.useRef(!1),dt=n.useRef(null),[Er,It]=n.useState(!1),Ke=he(t=>t.setMainTabGuard),He=he(t=>t.pendingFileNavigation),fs=he(t=>t.setPendingFileNavigation),Bs=he(t=>t.pendingFileFocusPath),$s=he(t=>t.setPendingFileFocusPath),Pr=he(t=>t.shortcutOverrides),Rr=he(t=>t.fileEditorKeymap),Yt=ji(t=>t.settingsDefaultFileViewerPreview),vn=ji(t=>t.showMessageTTSButtons),Mr=he(t=>t.expandedEditorToolbar);n.useEffect(()=>{const t=()=>{At.current=!1,dt.current=null,It(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),n.useEffect(()=>()=>{Jt.current!==null&&window.clearTimeout(Jt.current),Xt.current!==null&&window.clearTimeout(Xt.current)},[]);const wn=n.useCallback((t,i)=>{const o=t.split(`
|
|
9
|
+
`),c=Math.max(1,i.start),u=Math.min(o.length,i.end);return c>u?"":o.slice(c-1,u).join(`
|
|
10
|
+
`)},[]),bn=Ta({source:"file",fileLabel:l?.path??null,language:l?.path&&er(l.path)||"text",getCodeForRange:t=>wn(k,Va(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:zr,commentText:ms,setCommentText:Lr,editingDraftId:hs,setSelection:Ar,saveComment:Ir,cancel:Zt,reset:Or,startEdit:Br,deleteDraft:$r}=bn;n.useEffect(()=>{Me(null),Or(),Ke(null),J(""),Rs(!1)},[l?.path,Or,Ke]),n.useEffect(()=>{Ar(R)},[R,Ar]),n.useEffect(()=>{if(!R&&!hs)return;const t=o=>{const c=o.target;c.closest('[data-comment-input="true"]')||c.closest('[data-comment-card="true"]')||c.closest(".cm-gutterElement")||c.closest("[data-sonner-toast]")||c.closest("[data-sonner-toaster]")||ms.trim()||(Me(null),Zt())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[Zt,ms,hs,R]);const Wr=n.useCallback((t,i)=>{const o=i??R??void 0;i&&Me(i),Ir(t,o),Me(null)},[R,Ir]),Ur=n.useCallback((t,i)=>{const o=[];for(const c of i){if(!(c&&typeof c.name=="string"&&c.name.length>0)||!E&&c.name.startsWith(".")||!N&&Wa(c.name))continue;const u=c.name,f=z(c.path||""),w=f?Oa(f)?f:z(`${t}/${f}`):z(`${t}/${u}`),D=c.isDirectory?"directory":"file",$=D==="file"&&u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;o.push({name:u,path:w,type:D,extension:$})}return Ia(o)},[N,E]),Te=n.useCallback(async t=>{const i=z(t.trim());if(!i||Se.current.has(i)||ke.current.has(i))return;ke.current=new Set(ke.current),ke.current.add(i);const o=xr.current+1;xr.current=o,Je.current=new Map(Je.current),Je.current.set(i,o);const c=()=>Je.current.get(i)===o;await(r.listDirectory?r.listDirectory(i).then(f=>f.entries.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory}))):_n.listLocalDirectory(i).then(f=>f.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory})))).then(f=>{if(!c())return;const w=Ur(i,f);Se.current=new Set(Se.current),Se.current.add(i),Gt(D=>{if(!D[i])return D;const $={...D};return delete $[i],$}),Ps(D=>({...D,[i]:w}))}).catch(f=>{if(!c())return;const w=f instanceof Error?f.message:String(f??"");if(w==="Directory not found"&&a&&i!==a){dr(a,i),Gt(D=>{if(!D[i])return D;const $={...D};return delete $[i],$});return}console.error("Failed to load files directory:",f),Gt(D=>({...D,[i]:w}))}).finally(()=>{c()&&(Je.current=new Map(Je.current),Je.current.delete(i),ke.current=new Set(ke.current),ke.current.delete(i))})},[r,Ur,dr,a]),ps=n.useCallback(async()=>{a&&(Se.current=new Set,ke.current=new Set,Je.current=new Map,Gt({}),Ps(t=>Object.keys(t).length===0?t:{}),await Te(a))},[Te,a]),qe=n.useCallback(async t=>{if(!t){await ps();return}const i=z(t);Se.current=new Set(Se.current),Se.current.delete(i),ke.current=new Set(ke.current),ke.current.delete(i),await Te(i)},[Te,ps]),Gr=n.useRef(""),Kr=n.useRef("");n.useEffect(()=>{if(!a)return;const t=`${a}|h${E?"1":"0"}|g${N?"1":"0"}`,i=Gr.current!==a,o=Kr.current!==t;!i&&!o||(i&&(Gr.current=a,K(""),se(null),Pe(""),H(null),A(!1)),o&&(Kr.current=t,Se.current=new Set,ke.current=new Set,Je.current=new Map,Gt({}),Ps(c=>Object.keys(c).length===0?c:{}),Te(a)))},[Te,a,N,E]),n.useEffect(()=>{if(!r.listDirectory)return;const t=()=>{if(!document.hidden&&Qe.length>0)for(const i of Qe)qe(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[Qe,r.listDirectory,qe]),n.useEffect(()=>{if(!r.listDirectory||Qe.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of Qe)qe(i)},8e3);return()=>clearInterval(t)},[Qe,r.listDirectory,qe]);const yn=n.useCallback(async t=>{if(t?.preventDefault(),!Ft||!jt)return;As(!0);const i=()=>{Ls(null)},o=u=>{I.error(u)},c=()=>{As(!1)};if(jt==="createFile"){if(!ct.trim()){o(e("sidebarFilesTree.toast.filenameRequired")),c();return}if(!r.writeFile){o(e("sidebarFilesTree.toast.writeNotSupported")),c();return}const u=Ft.path,f=u?`${u}/`:"",w=z(`${f}${ct.trim()}`);await r.writeFile(w,"").then(async D=>{D.success&&(I.success(e("sidebarFilesTree.toast.fileCreated")),await qe(u)),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}if(jt==="createFolder"){if(!ct.trim()){o(e("sidebarFilesTree.toast.folderNameRequired")),c();return}const u=Ft.path,f=u?`${u}/`:"",w=z(`${f}${ct.trim()}`);await r.createDirectory(w).then(async D=>{D.success&&(I.success(e("sidebarFilesTree.toast.folderCreated")),await qe(u)),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}if(jt==="rename"){if(!ct.trim()){o(e("sidebarFilesTree.toast.nameRequired")),c();return}if(!r.rename){o(e("sidebarFilesTree.toast.renameNotSupported")),c();return}const u=Ft.path,f=u.split("/").slice(0,-1).join("/"),w=f?`${f}/`:"",D=z(`${w}${ct.trim()}`);await r.rename(u,D).then(async $=>{$.success&&(I.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await qe(f),a&&ot(a,u),(l?.path===u||l?.path.startsWith(`${u}/`))&&(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1))),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}if(jt==="delete"){if(!r.delete){o(e("sidebarFilesTree.toast.deleteNotSupported")),c();return}const u=Ft.path,f=u.split("/").slice(0,-1).join("/");await r.delete(u).then(async w=>{w.success&&(I.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await qe(f),a&&ot(a,u),(l?.path===u||l?.path.startsWith(`${u}/`))&&(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1))),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}c()},[jt,Ft,ct,r,qe,h,ot,a,l?.path,te,e]);n.useEffect(()=>{if(!P){os([]),ls(!1);return}const t=le.trim();if(!t){os([]),ls(!1);return}let i=!1;return ls(!0),_(P,t,150,{includeHidden:E,respectGitignore:!N,type:"file"}).then(o=>{if(i)return;const u=o.filter(f=>N||!Ua(f.path)).map(f=>({name:f.name,path:z(f.path),type:"file",extension:f.extension,relativePath:f.relativePath}));os(u)}).catch(()=>{i||os([])}).finally(()=>{i||ls(!1)}),()=>{i=!0}},[P,le,_,E,N]);const Hr=n.useCallback(async(t,i)=>{if(r.readFile)return(await r.readFile(t,{...i??{},directory:a||void 0})).content??"";const o=new URLSearchParams({path:t});i?.allowOutsideWorkspace&&o.set("allowOutsideWorkspace","true"),i?.outsideFileGrant&&o.set("outsideFileGrant",i.outsideFileGrant),i?.optional&&o.set("optional","true"),a&&o.set("directory",a);const c=await wi(`/api/fs/read?${o.toString()}`,{cache:i?.optional?"no-store":"default"});if(!c.ok){const u=await c.json().catch(()=>({error:c.statusText}));throw new Error(u.error||e("filesView.error.readFileFailed"))}return c.text()},[r,a,e]),ut=n.useCallback(async(t,i)=>{if(r.statFile){const o=await r.statFile(t,{...i??{},directory:a||void 0});return{path:o.path,size:o.size,mtimeMs:o.mtimeMs}}return null},[r,a]);n.useEffect(()=>{if(!a||!r.statFile||C.length===0)return;let t=!1;const i=[...C];return Promise.all(i.map(async o=>{try{const c=await r.statFile?.(o,{directory:a||void 0});!t&&c&&!c.isFile&&ot(a,o)}catch(c){!t&&Mi(c)&&ot(a,o)}})),()=>{t=!0}},[r,C,ot,a]);const Ws=n.useMemo(()=>k.length>ss?`${k.slice(0,ss)}
|
|
11
|
+
|
|
12
|
+
… truncated …`:k,[k]),ie=B!==Ws,Nt=n.useCallback(async()=>{if(!l||!r.writeFile)return I.error(e("filesView.toast.savingNotSupported")),!1;const t=js(l.path)||qt;if(!za({selectedFilePath:l.path,loadedFilePath:be,fileLoading:Ee,isDirty:ie,draftContent:B,fileContent:k,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${l.path}".`):B===""&&k!==""&&be!==l.path&&console.warn(`[saveDraft] refusing to save empty draft for "${l.path}" (${k.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!ie)return!0;Rs(!0);try{const i=Ha(B,wr);if(!(await r.writeFile(l.path,i))?.success)return I.error(e("filesView.toast.writeFileFailed")),!1;if(K(B),a&&rs(l.path,a)){const c=Ss(a,l.path);c&&aa.requestGitRefresh({directory:a,paths:[c]})}if(a&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(z(l.path))){const c=oa.getState().projects.find(u=>z(u.path)===z(a));if(c)try{await Ea(c.id)}catch{I.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return l?.path&&tr(l.path)&&(lt.current=B,Kt.current=B),ut(l.path).then(c=>{c&&(et.current=c)}).catch(()=>{}),!0}catch(i){return I.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{Rs(!1)}},[qt,B,k,Ee,r,ie,wr,be,ut,a,l,e]);n.useEffect(()=>{if(!ie){Ke(null);return}const t=i=>bt.current?(bt.current=!1,!0):(Mt(!0),_t.current=i,!1);return Ke(t),()=>{he.getState().mainTabGuard===t&&Ke(null)}},[ie,Ke]),n.useEffect(()=>{re||(Rt("idle"),Ge.current&&(clearTimeout(Ge.current),Ge.current=null))},[re]);const qr=1500;n.useEffect(()=>{const t=!!(l&&r.writeFile),i=!!(l?.path&&(js(l.path)||qt));if(Ma({autoSaveEnabled:re,isDirty:ie,canWrite:t,isSaving:Pt,fileLoading:Ee,selectedFilePath:l?.path,loadedFilePath:be,isNonEditableBinary:i}))return Ge.current=setTimeout(()=>{Nt().then(o=>{o&&(Rt("saved"),setTimeout(()=>Rt("idle"),2e3))})},qr),()=>{Ge.current&&(clearTimeout(Ge.current),Ge.current=null)}},[re,qt,B,Ee,ie,be,l,r.writeFile,Pt,Nt]),n.useEffect(()=>{Rt("idle")},[l?.path]),n.useEffect(()=>{const t=i=>{ma(i)&&(i.key.toLowerCase()==="s"?(i.preventDefault(),Ge.current&&(clearTimeout(Ge.current),Ge.current=null),Pt||Nt().then(o=>{o&&(Rt("saved"),setTimeout(()=>Rt("idle"),2e3))})):i.key.toLowerCase()==="f"&&(i.preventDefault(),pe(!0)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[Pt,Nt]);const _r=n.useCallback(async t=>{const i=ds.current+1;ds.current=i;const o=()=>{if(!a)return!1;const je=ze.getState().byRoot[a],oe=je?.selectedPath??je?.openPaths[0]??null;return ds.current===i&&oe===t.path};se(null),Pe(""),H(null),yr(!1);const c=Fi(t.path),u=Ni(t.path),f=Ci(t.path),w=js(t.path);if(h&&A(!0),m.isDesktop&&c&&!u){K(""),J(""),Xe(!0);return}if(!m.isDesktop&&c&&!u){K(""),J(""),H(t.path),Xe(!1);return}if(f){K(""),J(""),H(t.path),Xe(!1);return}if(w){K(""),J(""),H(t.path),Xe(!1);return}Xe(!0);const D=yi(t.path),$={allowOutsideWorkspace:d==="editor-only"&&!!a&&!rs(t.path,a),outsideFileGrant:D};await Hr(t.path,$).then(je=>{if(!o())return;if(la(je)){yr(!0),K(""),J(""),H(t.path);return}const oe=Ui(je);Ji(Ka(je)),K(oe),lt.current=oe,Kt.current=oe,J(oe.length>ss?`${oe.slice(0,ss)}
|
|
13
|
+
|
|
14
|
+
… truncated …`:oe),H(t.path),ut(t.path,$).then(Ct=>{Ct&&o()&&(et.current=Ct)}).catch(()=>{})}).catch(je=>{if(o()){if(Ga(je)){if(Xe(!1),a&&te(a,null),se(null),K(""),J(""),H(null),et.current=null,T.trim().length>0&&V(""),h&&A(!1),a){const Ct=[...Pi(t.path,a),t.path];Ct.length>0&&is(a,Ct);for(const Ys of Ct)Se.current.has(Ys)||Te(Ys)}return}if(Mi(je)){a&&ot(a,t.path),K(""),J(""),se(null),et.current=null,h&&A(!1);return}K(""),J(""),se(je instanceof Error?je.message:e("filesView.error.readFileFailed")),et.current=null}}).finally(()=>{o()&&Xe(!1)})},[is,h,Te,d,Hr,ut,ot,a,m.isDesktop,T,te,e]),gs=n.useCallback(async(t,i)=>{if(!a)return;const o=Pi(t,a),c=i?[...o,t]:o;c.length>0&&is(a,c);const u=c.map(f=>{if(!Se.current.has(f))return Te(f)}).filter(Boolean);await Promise.all(u)},[is,Te,a]),Qr=n.useCallback((t,i)=>{const o=i.findIndex(c=>c.path===t);return o===-1||i.length<=1?null:i[o+1]??i[o-1]??null},[]),me=n.useCallback(async t=>{if(bt.current)bt.current=!1;else if(ie){Mt(!0),zt.current=t;return}a&&(te(a,t.path),gs(t.path,!1)),se(null),Pe(""),K(""),lt.current="",Kt.current="",J(""),H(null),h&&A(!0)},[gs,ie,h,a,te]);n.useEffect(()=>{l?.path&&gs(l.path,!1)},[gs,l?.path]),n.useEffect(()=>{if(!l){ds.current+=1,Ht.current=null,Xe(!1);return}if(be===l.path||Ht.current===l.path)return;const t=l.path;Ht.current=t,_r(l).finally(()=>{Ht.current===t&&(Ht.current=null)})},[_r,be,l]);const Jr=n.useRef(ie);Jr.current=ie,n.useEffect(()=>{if(!l?.path||be!==l.path)return;let t=!1;const i=window.setInterval(()=>{document.hidden||ut(l.path,Ce).then(o=>{if(t||!o)return;const c=et.current;if(!c||c.path!==l.path){et.current=o;return}const u=o.mtimeMs!==void 0&&c.mtimeMs!==void 0&&o.mtimeMs!==c.mtimeMs,f=o.size!==c.size;!u&&!f||Jr.current||(et.current=o,H(null))}).catch(()=>{})},2e3);return()=>{t=!0,window.clearInterval(i)}},[be,ut,l?.path,Ce]);const jn=n.useCallback(()=>{const t=zt.current,i=_t.current,o=Qt.current;if(zt.current=null,_t.current=null,Qt.current=null,bt.current=!0,Mt(!1),J(Ws),o){a&&Vt(a,o),l?.path===o&&(t?me(t):(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1)));return}if(t){me(t);return}i&&(Ke(null),he.getState().setActiveMainTab(i))},[Ws,me,h,Vt,a,l?.path,Ke,te]),Fn=n.useCallback(async()=>{const t=zt.current,i=_t.current,o=Qt.current;if(!await Nt()){bt.current=!1;return}if(zt.current=null,_t.current=null,Qt.current=null,bt.current=!0,Mt(!1),o){a&&Vt(a,o),l?.path===o&&(t?await me(t):(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1)));return}if(t){await me(t);return}i&&(Ke(null),he.getState().setActiveMainTab(i))},[me,h,Vt,a,Nt,l?.path,Ke,te]),Xr=n.useCallback(t=>{const i=l?.path===t,o=Qr(t,Et);if(i&&ie){Mt(!0),zt.current=o,Qt.current=t;return}if(a&&Vt(a,t),!!i){if(o){me(o);return}a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1)}},[Qr,me,ie,h,Et,Vt,a,l?.path,te]),Nn=n.useCallback(t=>{if(C.includes(t))return"open";if(L?.files){const i=t.startsWith(a+"/")?t.slice(a.length+1):t,o=L.files.find(c=>c.path===i);if(o){if(o.index==="A"||o.working_dir==="?")return"git-added";if(o.index==="D")return"git-deleted";if(o.index==="M"||o.working_dir==="M")return"git-modified"}}return null},[C,L,a]),Cn=n.useCallback(t=>{if(!L?.files)return null;const i=t.startsWith(a+"/")?t.slice(a.length+1):t,o=i?`${i}/`:"";let c=0,u=0;for(const f of L.files)f.path.startsWith(o)&&((f.index==="M"||f.working_dir==="M")&&c++,(f.index==="A"||f.working_dir==="?")&&u++);return c+u>0?{modified:c,added:u}:null},[L,a]),Sn=n.useCallback(async t=>{const i=z(t);a&&(ur(a,i),Se.current.has(i)||await Te(i))},[Te,a,ur]),kn=n.useMemo(()=>({canRename:kr,canCreateFile:Cr,canCreateFolder:Sr,canDelete:Tr,canReveal:Vr}),[kr,Cr,Sr,Tr,Vr]);function Yr(t,i){const o=gr[t]??[];return o.map((c,u)=>{const f=c.type==="directory",w=f&&Qe.includes(c.path),D=l?.path===c.path,$=u===o.length-1;return s.jsxs("li",{className:"relative",children:[i>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),$&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(_a,{node:c,root:a,isExpanded:w,isActive:D,isMobile:h,isBrowserClient:F,alwaysShowActions:M,status:f?void 0:Nn(c.path),badge:f?Cn(c.path):void 0,permissions:kn,downloadFile:r.downloadFile,contextMenuPath:an,setContextMenuPath:on,rightClickMenuPath:ln,setRightClickMenuPath:cn,onSelect:me,onToggle:Sn,onRevealPath:gn,onOpenDialog:Os}),f&&w&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[as[c.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:as[c.path],children:as[c.path]}),s.jsxs(S,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{qe(c.path)},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,Yr(c.path,i+1)]})]},c.path)})}const ne=!!(l?.path&&Fi(l.path)),xs=!!(l?.path&&Ni(l.path)),Ve=!!(l?.path&&Ci(l.path)),Us=!!(l?.path&&(js(l.path)||qt)),tt=Us&&!ne&&!Ve,Zr=n.useMemo(()=>z(He?.path??""),[He?.path]),Ot=!!(He&&Zr&&Ue&&Ue===Zr&&!Ee&&!Ye&&!ne&&!Ve&&!tt),ft=n.useMemo(()=>Ss(a,Ue),[Ue,a]),Tn=!!(l&&(!ne||xs)&&!Ve&&!tt&&k.length>0),Vn=!!(l&&ft.length>0),De=!!(l&&!ns&&!Us&&!ne&&r.writeFile&&k.length<=ss),mt=!!(l?.path&&zi(l.path)),es=!!(l?.path&&qa(l.path)),Bt=!!(l?.path&&ar(l.path)),ts=!!(l?.path&&tr(l.path)),Gs=!!(l&&!Us&&!ne)&&!mt&&!ts&&!(Bt&&xe==="preview"),Dn=mt&&xt==="edit"||Bt&&xe==="edit"||es&&Ie==="text"||!mt&&!Bt&&!es&&G==="edit",vs=n.useMemo(()=>Ue?ca(Ue):null,[Ue]),[ei,Ks]=n.useState(null);n.useEffect(()=>{let t=!1;const i=l?.path;if(!i||vs){Ks(null);return}return Ks(null),da(i).then(o=>{t||Ks(o)}),()=>{t=!0}},[l?.path,vs]),n.useEffect(()=>{!De&&G==="edit"&&Fe("view")},[De,G]);const Hs="openchamber:files:md-viewer-mode",qs="openchamber:files:html-viewer-mode",_s="openchamber:files:json-viewer-mode";n.useEffect(()=>{const t=l?.path;if(!t)return;Fe(Be.current[t]??"edit");let i=Yt?"preview":"edit";try{const u=localStorage.getItem(Hs);(u==="preview"||u==="edit")&&(i=u)}catch{}Ae($e.current[t]??i);let o=Yt?"preview":"edit";try{const u=localStorage.getItem(qs);(u==="preview"||u==="edit")&&(o=u)}catch{}Oe(We.current[t]??o),Ne(at.current[t]??(Yt?"preview":"edit"));let c=Yt?"tree":"text";try{const u=localStorage.getItem(_s);(u==="tree"||u==="text")&&(c=u)}catch{}vt(c)},[l?.path,Yt]);const En=n.useCallback(t=>{const i=l?.path;i&&(Be.current[i]=t),Fe(t)},[l?.path]),ti=n.useCallback(t=>{const i=l?.path;i&&($e.current[i]=t),Ae(t);try{localStorage.setItem(Hs,t)}catch{}},[l?.path]),ae=n.useCallback(()=>xt,[xt]),Pn=n.useCallback(t=>{vt(t);try{localStorage.setItem(_s,t)}catch{}},[]),Rn=n.useCallback(t=>{const i=l?.path;i&&(We.current[i]=t),Oe(t);try{localStorage.setItem(qs,t)}catch{}},[l?.path]),Mn=n.useCallback(t=>{const i=l?.path;if(i&&(at.current[i]=t),ye.current&&(clearTimeout(ye.current),ye.current=null),Ze.current!==null&&(cancelAnimationFrame(Ze.current),Ze.current=null),t==="edit")J(lt.current||k),Ne(t);else{lt.current=B;const o=i;Ne("edit"),Ze.current=requestAnimationFrame(()=>{Ze.current=requestAnimationFrame(()=>{Ze.current=null,!(a&&o&&ze.getState().byRoot[a]?.selectedPath!==o)&&(nt(c=>c+1),Ne("preview"))})});return}},[B,k,a,l?.path]),Qs=n.useCallback(async(t,i)=>{if(!r.writeFile||i===Kt.current)return!1;if(!(await r.writeFile(t,i))?.success)return I.error(e("filesView.toast.writeFileFailed")),!1;lt.current=i,Kt.current=i,J(i);const c=await ut(t,Ce).catch(()=>null);return c&&(et.current=c),!0},[r,ut,Ce,e]);n.useEffect(()=>()=>{ye.current&&(clearTimeout(ye.current),ye.current=null),Ze.current!==null&&(cancelAnimationFrame(Ze.current),Ze.current=null)},[ue,l?.path]);const zn=n.useCallback(t=>{if(lt.current=t,!re||!l?.path||ue!=="preview"||!r.writeFile)return;ye.current&&clearTimeout(ye.current);const i=l.path;ye.current=setTimeout(()=>{ye.current=null,Qs(i,t).then(o=>{o&&(us(!0),setTimeout(()=>us(!1),1500))}).catch(o=>{I.error(o instanceof Error?o.message:e("filesView.toast.saveFailed"))})},qr)},[re,ue,r.writeFile,Qs,l?.path,e]),Ln=n.useMemo(()=>ts&&(lt.current||B)||k,[B,k,ts]),si=n.useCallback(()=>xe,[xe]);n.useEffect(()=>{const t=o=>{const c=o?"preview":"edit",u=o?"tree":"text";for(const f of C)Be.current[f]="edit",zi(f)&&($e.current[f]=c),ar(f)&&(We.current[f]=c),tr(f)&&(at.current[f]=c);Fe("edit"),Ae(c),Oe(c),Ne(c),vt(u);try{localStorage.setItem(Hs,c),localStorage.setItem(qs,c),localStorage.setItem(_s,u)}catch{}},i=o=>{const c=!!o.detail?.enabled;t(c)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",i),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",i)}},[C]),n.useEffect(()=>{if(!He||!a)return;const t=()=>{typeof window>"u"||Lt.current===null&&(Lt.current=window.requestAnimationFrame(()=>{Lt.current=null,zs(st=>st+1)}))},i=(st,St)=>{if(st.state.doc.length!==St.length)return!1;if(St.length===0)return!0;const Zs=Math.min(128,St.length);if(st.state.sliceDoc(0,Zs)!==St.slice(0,Zs))return!1;const gi=Math.max(0,St.length-Zs);return st.state.sliceDoc(gi,St.length)===St.slice(gi)},o=z(He.path);if(!o){fs(null),yt.current={key:"",attempts:0};return}const c=`${o}:${He.line}:${He.column??1}`;if(yt.current.key!==c&&(yt.current={key:c,attempts:0}),l?.path!==o){if(Ms)return;me(Dt(o));return}if(Ee||be!==o)return;if(Ye||ne||Ve||tt){fs(null),yt.current={key:"",attempts:0};return}if(!De)return;if(G!=="edit"){Fe("edit");return}const u=Re.current;if(!u){t();return}if(!i(u,B)){t();return}const f=Math.max(1,Math.min(He.line,u.state.doc.lines)),w=u.state.doc.line(f),D=Math.max(1,He.column||1),$=Math.max(0,w.to-w.from),je=Math.min($,D-1),oe=w.from+je;if(!(u.state.selection.main.head===oe)||yt.current.attempts===0){yt.current.attempts+=1,u.dispatch({selection:{anchor:oe},effects:kt.scrollIntoView(oe,{y:"center"})}),u.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const st=Re.current;st&&(st.dispatch({selection:{anchor:oe},effects:kt.scrollIntoView(oe,{y:"center"})}),st.focus())}),fs(null),yt.current={key:"",attempts:0}},[De,Ms,B,sn,Ye,Ee,ne,Ve,tt,be,me,He,a,l?.path,fs,G,Dt]),n.useEffect(()=>{if(!Bs||!a)return;const t=z(Bs);if(!t){$s(null);return}l?.path===t&&(Ee||be!==t||(!Ye&&!ne&&!Ve&&!tt&&De&&G==="edit"&&Re.current?.focus(),$s(null)))},[De,Ye,Ee,ne,Ve,tt,be,Bs,a,l?.path,$s,G]);const $t=n.useCallback(t=>{if(!h||!t||!t.hasFocus||typeof window>"u")return;const i=window.visualViewport;if(!i)return;const o=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,o-(i.offsetTop+i.height))<=0)return;const u=t.state.selection.main.head,f=t.coordsAtPos(u);if(!f)return;const w=Math.round(i.offsetTop+i.height),$=f.bottom+20-w;$<=0||(t.scrollDOM.scrollTop+=$)},[h]);n.useEffect(()=>{if(!h||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{$t(Re.current)})},i=window.visualViewport;return i?.addEventListener("resize",t),i?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{i?.removeEventListener("resize",t),i?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[h,$t]),n.useEffect(()=>{if(!De||G!=="edit"||h)return;const t=ua("open_go_to_line",Pr),i=o=>{const c=o.target;if(c?.closest('[role="dialog"]'))return;const u=!!c?.closest(".cm-editor");c?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!u||!document.activeElement?.closest(".cm-editor")||ha(o,t)&&(o.preventDefault(),Is(!0))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[De,h,Pr,G]);const ws=he(t=>t.editorFontSize),ri=n.useMemo(()=>{if(!l?.path)return[ki(x,{fontSize:ws})];const t=er(l.path),i=[ki(x,t?{syntaxColors:!1,fontSize:ws}:{fontSize:ws})],o=vs??ei;return o&&i.push(o),t&&i.push(ja({language:t,themeName:x.metadata.id,theme:Sa(x)})),ce&&i.push(kt.lineWrapping),h&&i.push(kt.updateListener.of(c=>{c.view.hasFocus&&(c.selectionSet||c.focusChanged||c.viewportChanged||c.geometryChanged)&&window.requestAnimationFrame(()=>{$t(c.view)})})),i},[x,l?.path,vs,ei,ce,h,$t,ws]),ii=n.useMemo(()=>({light:fe.metadata.id,dark:ve.metadata.id}),[fe.metadata.id,ve.metadata.id]),bs=l?.path&&Ve?`${l.path}|${Ce.allowOutsideWorkspace?"outside":"workspace"}|${Ce.outsideFileGrant??""}`:"",ys=l?.path&&Bt&&xe==="preview"&&!m.isVSCode?l.path:"",ni=e("filesView.error.readFileFailed"),{readyKey:ai,nonce:An}=Li(ys,se,ni),{readyKey:oi,nonce:li}=Li(bs,se,ni),In=!!(ys&&ai!==ys),ci=!!(bs&&oi!==bs),di=l?.path&&ne?xs?`data:${fa(l.path)};utf8,${encodeURIComponent(k)}`:Qi:"",ui=l?.path&&Ve&&oi===bs?bi().authenticatedAsset("/api/fs/raw",{path:l.path,allowOutsideWorkspace:Ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:Ce.outsideFileGrant,directory:a||void 0}):"",fi=n.useCallback(t=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:ui,className:"h-full w-full border-0",title:t.name},li)}),[ui,li]);n.useEffect(()=>{let t=!1,i="";return(async()=>{if(!l?.path||!ne||xs){Pe("");return}se(null),await(r.readFileBinary?r.readFileBinary(l.path,Ce).then(u=>u.dataUrl):(async()=>{const u=await wi("/api/fs/raw",{query:{path:l.path,allowOutsideWorkspace:Ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:Ce.outsideFileGrant,directory:a||void 0}});if(!u.ok)throw new Error(e("filesView.error.readFileFailed"));const f=await u.blob();return i=URL.createObjectURL(f),t?(URL.revokeObjectURL(i),i="",""):i})()).then(u=>{t||(Pe(u),H(l.path))}).catch(u=>{t||(Pe(""),se(u instanceof Error?u.message:e("filesView.error.readFileFailed")),H(null))}).finally(()=>{t||Xe(!1)})})(),()=>{t=!0,i&&URL.revokeObjectURL(i)}},[r,ne,xs,a,l?.path,Ce,e]);const On=n.useCallback(()=>Ls(null),[]),Bn=n.useMemo(()=>Da({drafts:zr,editingDraftId:hs,commentText:ms,onTextChange:Lr,selection:R,isDragging:Er,fileLabel:l?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Wr,onCancel:()=>{Me(null),Zt()},onEdit:t=>{Br(t),Me({start:t.startLine,end:t.endLine})},onDelete:$r}),[Zt,ms,$r,hs,zr,Wr,Er,R,l?.path,Lr,Br]),mi=n.useCallback((t,i)=>s.jsx("div",{className:"h-full",children:s.jsx(Na,{file:{name:t.name,contents:i,lang:er(t.path)||void 0},options:{disableFileHeader:!0,overflow:ce?"wrap":"scroll",theme:ii,themeType:x.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[x.metadata.variant,ii,ce]),Js=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!l)return null;const c=i==="docked"?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",u=(f,w)=>s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:w})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:f})]});return s.jsxs("div",{className:c,children:[De&&Dn&&s.jsxs(s.Fragment,{children:[Pt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(g,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):re&&Yi==="saved"&&!ie?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(g,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):ie?u(e(re?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ir()}+S`}),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{Nt()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(re?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ir()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${ir()}+S`}),children:s.jsx(g,{name:"save-3",className:"size-4"})})):null,u(e(re?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>en(!re),className:O("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",re?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(re?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(re?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:re?s.jsx(g,{name:"file-check-fill",className:"size-4"}):s.jsx(g,{name:"file-check",className:"size-4"})}))]}),s.jsxs(or,{onOpenChange:Tt,children:[s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(lr,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(g,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(cr,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[mn.map(f=>s.jsxs(Cs,{className:"flex items-center gap-2",onClick:()=>{xn(f)},children:[s.jsx(Aa,{label:f.label,iconDataUrl:f.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:f.label})]},f.id)),hn?s.jsxs(Cs,{className:"flex items-center gap-2",onClick:()=>{pn(!0)},children:[s.jsx(g,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!ne&&!Ve&&!tt&&s.jsxs(s.Fragment,{children:[u(e(ce?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Le(!ce),className:O("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",ce?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(ce?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(g,{name:"text-wrap",className:"size-4"})})),G==="edit"&&s.jsxs(s.Fragment,{children:[u(e("filesView.editor.findInFile"),s.jsx(S,{variant:"ghost",size:"sm",onClick:f=>{pe(!Z),f.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(g,{name:"search",className:"size-4"})})),u(e("filesView.editor.goToLine"),s.jsx(S,{variant:"ghost",size:"sm",onClick:f=>{Is(w=>!w),f.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(g,{name:"menu-fold-2",className:"size-4"})})),s.jsx(Ra,{open:fn,onOpenChange:Is,view:Re.current,variant:"inline"})]})]}),Gs&&De&&!es&&!Bt&&s.jsx(nr,{currentMode:G==="view"?"preview":"edit",onToggle:()=>{En(G==="view"?"edit":"view")}}),mt&&u(e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ti(ae()==="preview"?"edit":"preview"),className:O("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",ae()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:ae()==="preview"?"eye":"eye-off",className:"size-4"})})),ar(l?.path??"")&&s.jsx(nr,{currentMode:si(),onToggle:()=>{Rn(si()==="preview"?"edit":"preview")}}),mt&&ae()==="preview"&&vn&&s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(cs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{cs?_i():k.trim()&&qi(k)},children:cs?s.jsx(g,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"volume-up",className:"size-4"})})}),s.jsx(gt,{sideOffset:8,children:e(cs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),ts&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{currentMode:ue,onToggle:()=>Mn(ue==="preview"?"edit":"preview")}),ue==="preview"&&s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{const f=br.current?.getXml();if(ye.current&&(clearTimeout(ye.current),ye.current=null),l?.path&&f){if(!await Qs(l.path,f))return;us(!0),setTimeout(()=>us(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:Zi?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"save-3",className:"size-4"})})]}),es&&u(e(Ie==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Pn(Ie==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(Ie==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:Ie==="tree"?s.jsx(g,{name:"code-sslash",className:"size-4"}):s.jsx(g,{name:"node-tree",className:"size-4"})})),Tn&&u(e("filesView.editor.copyFileContents"),s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{(await Ts(k)).ok?(Fr(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.current=window.setTimeout(()=>{Fr(!1)},1200)):I.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:dn?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"clipboard",className:"size-4"})})),Vn&&u(e("filesView.editor.copyFilePathTitle",{path:ft}),s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{(await Ts(ft)).ok?(Nr(!0),Xt.current!==null&&window.clearTimeout(Xt.current),Xt.current=window.setTimeout(()=>{Nr(!1)},1200)):I.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:ft}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:ft}),children:un?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"file-copy-2",className:"size-4"})})),r.downloadFile&&u(e("filesView.editor.saveFile"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{const f=r.downloadFile;f&&f(l.path).catch(w=>{console.error("Download failed:",w),I.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(g,{name:"download",className:"size-4"})})),t?u(e("filesView.editor.exitFullscreen"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Q(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(g,{name:"fullscreen-exit",className:"size-4"})})):!h&&d==="full"&&u(e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Q(!U),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:U?s.jsx(g,{name:"fullscreen-exit",className:"size-4"}):s.jsx(g,{name:"fullscreen",className:"size-4"})}))]})},Xs=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Ai,{open:Ms,onOpenChange:t=>{t||Mt(!0)},children:s.jsxs(Ii,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Oi,{children:[s.jsx(Bi,{children:e("filesView.unsaved.title")}),s.jsx($i,{children:e("filesView.unsaved.description")})]}),s.jsxs(Wi,{children:[s.jsx(S,{variant:"outline",onClick:()=>{Fn()},disabled:Pt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(S,{variant:"destructive",onClick:jn,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:O("flex flex-col flex-shrink-0",q&&"border-b border-border/40"),children:[q?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[h&&Y&&s.jsx("button",{type:"button",onClick:()=>A(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(g,{name:"arrow-left-s",className:"size-5"})}),h?l?s.jsxs(or,{children:[s.jsx(lr,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(Ns,{filePath:l.path,extension:l.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Ri,{name:l.name}),s.jsx(g,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(cr,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Et.map(t=>{const i=l?.path===t.path;return s.jsxs(Cs,{onSelect:o=>{if(o.target.closest("[data-close-open-file]")){o.preventDefault();return}i||me(t)},className:O("flex min-w-0 items-center justify-between gap-2 overflow-hidden",i&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(Ns,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Ri,{name:t.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:o=>{o.preventDefault(),o.stopPropagation()},onClick:o=>{o.preventDefault(),o.stopPropagation(),Xr(t.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Et.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[mr.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),mr.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:Es,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Et.map(t=>{const i=l?.path===t.path;return s.jsxs("div",{title:Ss(a,t.path),className:O("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",i?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(Ns,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{i||me(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),Xr(t.path)},className:O("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!M&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,(Mr||h)&&l?s.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[ft&&!h?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:ft,children:ft}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Js({layout:"docked"})})]}):null]}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[l&&!Z&&!(Mr||h)&&s.jsx("div",{ref:de,className:"absolute right-3 top-3 z-30",onMouseLeave:()=>{rt.current>0||ge(!1)},children:ee?Js():s.jsxs("div",{className:"flex items-center gap-1",children:[mt?s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ti(ae()==="preview"?"edit":"preview"),className:O("size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors",ae()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]":"text-muted-foreground hover:text-foreground"),"aria-label":e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),title:e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:ae()==="preview"?"eye":"eye-off",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode")})]}):null,s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",onMouseEnter:()=>ge(!0),children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ge(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})]})}),s.jsx(sr,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:l?Ee||ci?W?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):Ye?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Ye}):ne?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:di,alt:l?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},l.path)}):Ve?fi(l):tt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!l||t(l.path).catch(i=>{console.error("Download failed:",i),I.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):l&&ts&&ue==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(ka,{ref:br,xml:Ln,onChange:zn},`${l.path}:${it}`)}):l&&es&&Ie==="tree"?s.jsx(rr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Ca,{jsonString:k,maxHeight:"100%",initiallyExpandedDepth:2})})}):l&&mt&&ae()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[k.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(k.length/1024)})}),s.jsx(rr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Si,{content:k,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):l&&Bt&&xe==="preview"?In?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!m.isVSCode&&ai===ys?(()=>{const t=l.path.split("/").map(i=>encodeURIComponent(i)).join("/");return bi().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:m.isVSCode?(()=>{const t=l.path.substring(0,l.path.lastIndexOf("/")+1);return t?k.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):k})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},An)}):l&&Gs&&G==="view"?mi(l,B):s.jsxs("div",{className:O("relative h-full",Ot&&"overflow-hidden"),ref:tn,children:[s.jsx("div",{className:O("h-full",Ot&&"invisible"),children:s.jsx(Ti,{value:B,onChange:J,readOnly:!De,vimMode:Rr==="vim",extensions:ri,className:"h-full",blockWidgets:Bn,onViewReady:t=>{Re.current=t,zs(i=>i+1),window.requestAnimationFrame(()=>{$t(t)})},onViewDestroy:()=>{Re.current&&(Re.current=null),zs(t=>t+1)},enableSearch:!0,searchOpen:Z,onSearchOpenChange:pe,highlightLines:R?{start:Math.min(R.start,R.end),end:Math.max(R.start,R.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,i,o)=>{if(!(o instanceof MouseEvent)||o.button!==0)return!1;o.preventDefault();const c=t.state.doc.lineAt(i.from).number;if(R&&!o.shiftKey&&Math.min(R.start,R.end)===c&&Math.max(R.start,R.end)===c)return Me(null),Zt(),At.current=!1,dt.current=null,It(!1),!0;if(h&&R&&!o.shiftKey){const u=Math.min(R.start,R.end,c),f=Math.max(R.start,R.end,c);return Me({start:u,end:f}),At.current=!1,dt.current=null,It(!1),!0}if(At.current=!0,dt.current=c,It(!0),R&&o.shiftKey){const u=Math.min(R.start,c),f=Math.max(R.end,c);Me({start:u,end:f})}else Me({start:c,end:c});return!0},mouseover:(t,i,o)=>{if(!(o instanceof MouseEvent)||o.buttons!==1||!At.current||dt.current===null)return!1;const c=t.state.doc.lineAt(i.from).number,u=Math.min(dt.current,c),f=Math.max(dt.current,c);return Me({start:u,end:f}),It(!0),!1},mouseup:()=>(At.current=!1,dt.current=null,It(!1),!1)}}})}),Ot&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),$n=!!(a&&gr[a]),hi=a?as[a]:null,pi=s.jsxs("section",{className:O("flex min-h-0 flex-col overflow-hidden",h?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:O("flex flex-col gap-2 py-2",h?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(g,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(ks,{ref:X,value:T,onChange:t=>V(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),T.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{V(""),X.current?.focus()},children:s.jsx(g,{name:"close",className:"size-4"})})]}),s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Os("createFile",{path:P,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(g,{name:"file-add",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Os("createFolder",{path:P,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(g,{name:"folder-add",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{ps()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(g,{name:"refresh",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(sr,{outerClassName:"flex-1 min-h-0",className:O("py-2",h?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Hi?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):vr.length>0?vr.map(t=>{const i=l?.path===t.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{me(t)},className:O("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[Gi(t.path,t.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):hi?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:hi}),s.jsxs(S,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{ps()},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):$n?Yr(a,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Wn=d==="full"&&U&&l&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:Js({exitFullscreenOnly:!0})}),s.jsx(sr,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Ee||ci?W?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):Ye?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Ye}):ne?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:di,alt:l.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},l.path)}):Ve?fi(l):tt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!l||t(l.path).catch(i=>{console.error("Download failed:",i),I.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):mt&&ae()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[k.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(k.length/1024)})}),s.jsx(rr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Si,{content:k,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):Gs&&G==="view"?mi(l,B):s.jsxs("div",{className:O("relative h-full",Ot&&"overflow-hidden"),children:[s.jsx("div",{className:O("h-full",Ot&&"invisible"),children:s.jsx(Ti,{value:B,onChange:J,readOnly:!De,vimMode:Rr==="vim",extensions:ri,className:"h-full",onViewReady:t=>{Re.current=t,window.requestAnimationFrame(()=>{$t(t)})},onViewDestroy:()=>{Re.current&&(Re.current=null)}})}),Ot&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(Qa,{activeDialog:jt,dialogData:Ft,dialogInputValue:ct,onDialogInputChange:jr,isDialogSubmitting:nn,onDialogSubmit:yn,onClose:On,inputRef:Xi}),Wn,h?Y?Xs:pi:d==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:Xs})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[p>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:pi}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Xs})]})]})};function Ja(d){return d+1}export{mc as FilesView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{R as l,r as Te,j as t,f as jt}from"./vendor-react-BUCujlKS.js";import{f as et,x as Ze,h7 as In,cS as Ht,ca as Wt,t as b,I as D,aT as Vs,aQ as Is,cQ as wr,aS as Ps,cm as Fs,cn as Rs,co as Ms,cp as Bs,ci as Ut,cj as Kt,B as W,h8 as Pn,h9 as Fn,br as ut,bs as mt,bt as ht,bu as gt,bv as wt,R as nr,aW as Jt,aX as qt,aY as Yt,ha as Rn,g as Re,hb as Mn,hc as Bn,hd as Tn,he as Dn,aO as En,a9 as Ln,bI as An,hf as On,hg as zn,hh as Gn,hi as _n,hj as $n,hk as Hn,hl as Wn,bV as yr,bL as Un,bM as Kn,bN as Jn,bO as qn,bP as Yn,hm as Qn,bS as Xn,bw as ks,ez as Zn,U as ea,$ as ta,a1 as sa,a0 as ra,bj as na,hn as aa,bT as ia,ho as oa,hp as la,a2 as ca,hq as da,a3 as ua,bG as ma,hr as ha,k as ga,bU as fa,aP as pa,cr as xa,a8 as wa,Y as ya,hs as ba,ht as Cs}from"./useAppFontEffects-Bbpz77To.js";import{u as va,a as ja,d as Ca}from"./main-B4oBRI9u.js";import{q as Na,s as Sa,p as ka,I as Va,V as Ia}from"./runtimeEndpointReset-D5izT-u5.js";import{u as ar}from"./vendor-zustand-BAGL70zf.js";import{r as Pa,u as xt}from"./index-CNrN5qDs.js";import{C as Fa,a as Ra}from"./CommitSection-C9sBBYAJ.js";import{P as Ma}from"./PierreDiffViewer-B5k0KvPW.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-5VGWIT_J.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dzt9rWZZ.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./SessionSwitcherDropdown-ig2OT22Z.js";import"./scheduledTasksApi-CTJdfSWc.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./web-components-DGvnI0zx.js";import"./computeVirtualFileMetrics-DQE7R9IY.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-Dcu8Q-5P.js";import"./isDiffPlainText-XyBCe4eD.js";import"./vendor-diff-C3JhlQdm.js";import"./useInlineCommentController-D7zs7-BQ.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";const br="gitmojiCache",Ba=1e3*60*60*24*7,vr="1",Ta="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",jr=i=>{if(!i||typeof i!="object")return!1;const e=i;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Ns=()=>{if(typeof window>"u")return null;try{const i=window.localStorage.getItem(br);if(!i)return null;const e=JSON.parse(i);return!e||e.version!==vr||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(jr),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Da=i=>{if(!(typeof window>"u"))try{const e={gitmojis:i,fetchedAt:Date.now(),version:vr};window.localStorage.setItem(br,JSON.stringify(e))}catch{return}},ir=i=>Date.now()-i.fetchedAt<Ba;let _t=null;const It=new Set,or=async()=>{if(_t)return _t;const i=(async()=>{try{const e=await fetch(Ta);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),r=Array.isArray(n.gitmojis)?n.gitmojis.filter(jr):[];return Da(r),It.forEach(v=>v(r)),r}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return It.forEach(r=>r(n)),n}finally{_t=null}})();return _t=i,i},Ea=i=>{const[e,n]=l.useState(()=>i?Ns()?.gitmojis??[]:[]),[r,v]=l.useState(!1),f=l.useRef(i);f.current=i,l.useEffect(()=>{if(!i){It.delete(n),n([]),v(!1);return}const p=Ns();if(p&&(n(p.gitmojis),ir(p)))return;It.add(n),v(!0);let m=!1;return or().finally(()=>{!m&&f.current&&v(!1)}),()=>{m=!0,It.delete(n)}},[i]);const x=l.useCallback(async()=>{if(!f.current)return[];if(e.length>0)return e;const p=Ns();return p&&ir(p)?p.gitmojis:or()},[e]);return{gitmojis:e,isLoading:r,ensureLoaded:x}},Ct=async(i,e)=>{const n=await Pa(`/api/git/integrate/${i}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>null);throw new Error(r?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function Vt(i){return Ct("plan",i)}async function La(i){return Ct("conflict-details",{tempWorktreePath:i})}async function Aa(i){return(await Ct("cherry-pick-status",{tempWorktreePath:i})).inProgress}async function Oa(i){return Ct("run",{plan:i})}async function za(i){await Ct("abort",{state:i})}async function Ga(i){return Ct("continue",{state:i})}const _a=({repoRoot:i,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:v,refreshKey:f,onRefresh:x,showHeader:p=!0})=>{const{t:m}=et(),w=Ze(h=>h.currentSessionId),B=xt(h=>h.setActiveMainTab),[y,C]=Te.useState(!1),k=Te.useRef(null),[V,A]=Te.useState(v);Te.useEffect(()=>{A(v)},[v]),Te.useEffect(()=>{if(y){const h=setTimeout(()=>{k.current?.focus()},0);return()=>clearTimeout(h)}},[y]);const I=!!(i&&e&&V&&V!=="HEAD"&&e!==V),[d,E]=Te.useState({kind:"idle"}),[R,O]=Te.useState(!1),[N,P]=Te.useState([]),g=Te.useMemo(()=>w?`openchamber.integrate.conflict:${w}`:null,[w]);Te.useEffect(()=>{if(!g||typeof window>"u")return;const h=window.localStorage.getItem(g);if(!h)return;let L=!1;try{const T=JSON.parse(h);if(!T?.tempWorktreePath||T.repoRoot!==i){window.localStorage.removeItem(g);return}(async()=>{const u=await Aa(T.tempWorktreePath).catch(()=>!1);if(L)return;if(!u){window.localStorage.removeItem(g);return}const M=await La(T.tempWorktreePath).catch(()=>null);L||M&&E({kind:"conflict",state:T,details:M})})()}catch{window.localStorage.removeItem(g)}return()=>{L=!0}},[g,i]),Te.useEffect(()=>{if(!I){E({kind:"idle"});return}let h=!1;return E({kind:"loading"}),(async()=>{try{const L=await Vt({repoRoot:i,sourceBranch:e,targetBranch:V});if(h)return;if(E({kind:"ready",plan:L}),L.commits.length>0){const u=L.commits.slice(-50).reverse(),M=await In(i,u);h||(P(M),O(!1))}else h||(P([]),O(!1))}catch{h||E({kind:"idle"})}})(),()=>{h=!0}},[I,i,e,V,f]);const U=Te.useCallback(h=>{w&&Ze.getState().setWorktreeMetadata(w,{...n,createdFromBranch:h})},[w,n]),Y=Ze(h=>h.openNewSessionDraft),S=Te.useCallback(async h=>{const L=await Ht("git.integrate.cherrypick.resolve.visible",{current_commit:h.state.currentCommit,target_branch:h.state.targetBranch}),T=await Ht("git.integrate.cherrypick.resolve.instructions",{repo_root:h.state.repoRoot,temp_worktree_path:h.state.tempWorktreePath,source_branch:h.state.sourceBranch,target_branch:h.state.targetBranch,current_commit:h.state.currentCommit}),u=`Cherry-pick conflict context (JSON)
|
|
1
|
+
import{R as l,r as Te,j as t,f as jt}from"./vendor-react-BUCujlKS.js";import{f as et,y as Ze,h4 as In,cR as Ht,c5 as Wt,t as b,I as D,aU as Vs,aR as Is,cP as wr,aT as Ps,cl as Fs,cm as Rs,cn as Ms,co as Bs,ch as Ut,ci as Kt,B as W,h5 as Pn,h6 as Fn,bs as ut,bt as mt,bu as ht,bv as gt,bw as wt,S as nr,aX as Jt,aY as qt,aZ as Yt,h7 as Rn,h as Re,h8 as Mn,h9 as Bn,ha as Tn,hb as Dn,aQ as En,aa as Ln,bH as An,hc as On,hd as zn,he as Gn,hf as _n,hg as $n,hh as Hn,hi as Wn,bU as yr,bK as Un,bL as Kn,bM as Jn,bN as qn,bO as Yn,hj as Qn,bR as Xn,bx as ks,ew as Zn,V as ea,a0 as ta,a2 as sa,a1 as ra,bk as na,hk as aa,bS as ia,hl as oa,hm as la,a3 as ca,hn as da,a4 as ua,bF as ma,ho as ha,l as ga,bT as fa,g as pa,cq as xa,a9 as wa,Z as ya,hp as ba,hq as Cs}from"./useAppFontEffects-BikB6enL.js";import{u as va,a as ja,d as Ca}from"./main-DPMd2iKS.js";import{s as Na,v as Sa,q as ka,J as Va,X as Ia}from"./runtimeEndpointReset-BVmispdD.js";import{u as ar}from"./vendor-zustand-BAGL70zf.js";import{r as Pa,u as xt}from"./index-DRpChWux.js";import{C as Fa,a as Ra}from"./CommitSection-MJmntVPJ.js";import{P as Ma}from"./PierreDiffViewer-BHm4Yr0X.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-B-bSg3P5.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CLHw8NWn.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./SessionSwitcherDropdown-rro-SsaO.js";import"./scheduledTasksApi-ByKya3Un.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./web-components-GMc3oR3i.js";import"./computeVirtualFileMetrics-Da00Jg7M.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-CwGocYQd.js";import"./isDiffPlainText-D9YpoLrV.js";import"./vendor-diff-C3JhlQdm.js";import"./useInlineCommentController-CYPvYJDt.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";const br="gitmojiCache",Ba=1e3*60*60*24*7,vr="1",Ta="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",jr=i=>{if(!i||typeof i!="object")return!1;const e=i;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Ns=()=>{if(typeof window>"u")return null;try{const i=window.localStorage.getItem(br);if(!i)return null;const e=JSON.parse(i);return!e||e.version!==vr||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(jr),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Da=i=>{if(!(typeof window>"u"))try{const e={gitmojis:i,fetchedAt:Date.now(),version:vr};window.localStorage.setItem(br,JSON.stringify(e))}catch{return}},ir=i=>Date.now()-i.fetchedAt<Ba;let _t=null;const It=new Set,or=async()=>{if(_t)return _t;const i=(async()=>{try{const e=await fetch(Ta);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),r=Array.isArray(n.gitmojis)?n.gitmojis.filter(jr):[];return Da(r),It.forEach(v=>v(r)),r}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return It.forEach(r=>r(n)),n}finally{_t=null}})();return _t=i,i},Ea=i=>{const[e,n]=l.useState(()=>i?Ns()?.gitmojis??[]:[]),[r,v]=l.useState(!1),f=l.useRef(i);f.current=i,l.useEffect(()=>{if(!i){It.delete(n),n([]),v(!1);return}const p=Ns();if(p&&(n(p.gitmojis),ir(p)))return;It.add(n),v(!0);let m=!1;return or().finally(()=>{!m&&f.current&&v(!1)}),()=>{m=!0,It.delete(n)}},[i]);const x=l.useCallback(async()=>{if(!f.current)return[];if(e.length>0)return e;const p=Ns();return p&&ir(p)?p.gitmojis:or()},[e]);return{gitmojis:e,isLoading:r,ensureLoaded:x}},Ct=async(i,e)=>{const n=await Pa(`/api/git/integrate/${i}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>null);throw new Error(r?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function Vt(i){return Ct("plan",i)}async function La(i){return Ct("conflict-details",{tempWorktreePath:i})}async function Aa(i){return(await Ct("cherry-pick-status",{tempWorktreePath:i})).inProgress}async function Oa(i){return Ct("run",{plan:i})}async function za(i){await Ct("abort",{state:i})}async function Ga(i){return Ct("continue",{state:i})}const _a=({repoRoot:i,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:v,refreshKey:f,onRefresh:x,showHeader:p=!0})=>{const{t:m}=et(),w=Ze(h=>h.currentSessionId),B=xt(h=>h.setActiveMainTab),[y,C]=Te.useState(!1),k=Te.useRef(null),[V,A]=Te.useState(v);Te.useEffect(()=>{A(v)},[v]),Te.useEffect(()=>{if(y){const h=setTimeout(()=>{k.current?.focus()},0);return()=>clearTimeout(h)}},[y]);const I=!!(i&&e&&V&&V!=="HEAD"&&e!==V),[d,E]=Te.useState({kind:"idle"}),[R,O]=Te.useState(!1),[N,P]=Te.useState([]),g=Te.useMemo(()=>w?`openchamber.integrate.conflict:${w}`:null,[w]);Te.useEffect(()=>{if(!g||typeof window>"u")return;const h=window.localStorage.getItem(g);if(!h)return;let L=!1;try{const T=JSON.parse(h);if(!T?.tempWorktreePath||T.repoRoot!==i){window.localStorage.removeItem(g);return}(async()=>{const u=await Aa(T.tempWorktreePath).catch(()=>!1);if(L)return;if(!u){window.localStorage.removeItem(g);return}const M=await La(T.tempWorktreePath).catch(()=>null);L||M&&E({kind:"conflict",state:T,details:M})})()}catch{window.localStorage.removeItem(g)}return()=>{L=!0}},[g,i]),Te.useEffect(()=>{if(!I){E({kind:"idle"});return}let h=!1;return E({kind:"loading"}),(async()=>{try{const L=await Vt({repoRoot:i,sourceBranch:e,targetBranch:V});if(h)return;if(E({kind:"ready",plan:L}),L.commits.length>0){const u=L.commits.slice(-50).reverse(),M=await In(i,u);h||(P(M),O(!1))}else h||(P([]),O(!1))}catch{h||E({kind:"idle"})}})(),()=>{h=!0}},[I,i,e,V,f]);const U=Te.useCallback(h=>{w&&Ze.getState().setWorktreeMetadata(w,{...n,createdFromBranch:h})},[w,n]),Y=Ze(h=>h.openNewSessionDraft),S=Te.useCallback(async h=>{const L=await Ht("git.integrate.cherrypick.resolve.visible",{current_commit:h.state.currentCommit,target_branch:h.state.targetBranch}),T=await Ht("git.integrate.cherrypick.resolve.instructions",{repo_root:h.state.repoRoot,temp_worktree_path:h.state.tempWorktreePath,source_branch:h.state.sourceBranch,target_branch:h.state.targetBranch,current_commit:h.state.currentCommit}),u=`Cherry-pick conflict context (JSON)
|
|
2
2
|
${JSON.stringify({repoRoot:h.state.repoRoot,tempWorktreePath:h.state.tempWorktreePath,sourceBranch:h.state.sourceBranch,targetBranch:h.state.targetBranch,currentCommit:h.state.currentCommit,remainingCommits:h.state.remainingCommits,statusPorcelain:h.details.statusPorcelain,unmergedFiles:h.details.unmergedFiles,currentPatchMeta:h.details.currentPatchMeta,currentPatch:h.details.currentPatch,diff:h.details.diff},null,2)}`;return{visibleText:L,instructionsText:T,payloadText:u}},[]),F=Wt(h=>h.setPendingInputText),J=Wt(h=>h.setPendingSyntheticParts),H=Te.useCallback(async(h,L)=>{const T=await S(h);if(L){Y({directoryOverride:h.state.tempWorktreePath,initialPrompt:T.visibleText,syntheticParts:[{text:T.instructionsText,synthetic:!0},{text:T.payloadText,synthetic:!0}]}),B("chat");return}if(!w){b.error(m("gitView.integrate.noActiveSession"),{description:m("gitView.integrate.noActiveSessionDescription")});return}F(T.visibleText,"replace"),J([{text:T.instructionsText,synthetic:!0},{text:T.payloadText,synthetic:!0}]),B("chat")},[w,B,S,Y,F,J,m]),G=Te.useCallback(async()=>{if(d.kind==="ready"){if(d.plan.commits.length===0){b.message(m("gitView.integrate.noCommitsToMoveToast"));return}E({kind:"running",plan:d.plan});try{const h=await Oa(d.plan);if(h.kind==="success"){b.success(m("gitView.integrate.commitsMovedToast"),{description:h.moved===1?m("gitView.integrate.commitsMovedDescriptionSingle",{count:h.moved,branch:d.plan.targetBranch}):m("gitView.integrate.commitsMovedDescriptionPlural",{count:h.moved,branch:d.plan.targetBranch})});const L=await Vt(d.plan);E({kind:"ready",plan:L}),x?.();return}h.kind==="conflict"&&(b.error(m("gitView.integrate.cherryPickConflictToast"),{description:m("gitView.integrate.cherryPickConflictDescription")}),E({kind:"conflict",state:h.state,details:h.details}),g&&typeof window<"u"&&window.localStorage.setItem(g,JSON.stringify(h.state)))}catch(h){const L=h instanceof Error?h.message:String(h);b.error(m("gitView.integrate.failedToMoveToast"),{description:L});const T=await Vt({repoRoot:i,sourceBranch:e,targetBranch:V}).catch(()=>null);E(T?{kind:"ready",plan:T}:{kind:"idle"})}}},[d,x,i,e,V,g,m]),Z=Te.useCallback(async()=>{if(d.kind==="conflict")try{await za(d.state),b.message(m("gitView.integrate.cherryPickAbortedToast")),g&&typeof window<"u"&&window.localStorage.removeItem(g)}finally{const h=await Vt({repoRoot:i,sourceBranch:e,targetBranch:V}).catch(()=>null);E(h?{kind:"ready",plan:h}:{kind:"idle"})}},[d,i,e,V,g,m]),Q=Te.useCallback(async()=>{if(d.kind==="conflict")try{const h=await Ga(d.state);if(h.kind==="success"){b.success(m("gitView.integrate.cherryPickFinishedToast"));const L=await Vt({repoRoot:i,sourceBranch:e,targetBranch:V}).catch(()=>null);E(L?{kind:"ready",plan:L}:{kind:"idle"}),g&&typeof window<"u"&&window.localStorage.removeItem(g),x?.();return}h.kind==="conflict"&&(E({kind:"conflict",state:h.state,details:h.details}),g&&typeof window<"u"&&window.localStorage.setItem(g,JSON.stringify(h.state)))}catch(h){const L=h instanceof Error?h.message:String(h);b.error(m("gitView.integrate.cherryPickContinueFailedToast"),{description:L})}},[d,i,e,V,x,g,m]);return!i||!e?null:t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[p?t.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(D,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:m("gitView.integrate.title")}),d.kind==="ready"&&d.plan.commits.length>0?t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:m("gitView.integrate.toMoveCount",{count:d.plan.commits.length})}):null]}),t.jsx("div",{className:"flex items-center gap-2",children:d.kind==="loading"||d.kind==="running"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}):null,t.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:m("gitView.integrate.moveCommits")}),t.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",V]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs(Vs,{open:y,onOpenChange:C,children:[t.jsx(Is,{asChild:!0,children:t.jsxs("button",{type:"button",className:wr({size:"default"}),children:[m("gitView.integrate.target"),t.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:V}),t.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),t.jsx(Ps,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:t.jsxs(Fs,{className:"h-full min-h-0",children:[t.jsx(Rs,{ref:k,placeholder:m("gitView.branch.searchPlaceholder"),onKeyDown:h=>h.stopPropagation()}),t.jsxs(Ms,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(Bs,{children:m("gitView.branch.empty")}),t.jsx(Ut,{heading:m("gitView.branch.localBranches"),children:r.map(h=>t.jsx(Kt,{value:h,onSelect:()=>{A(h),U(h),C(!1)},children:h},h))})]})]})})]}),d.kind==="ready"?t.jsx(W,{size:"sm",onClick:()=>{G()},disabled:!I||d.plan.commits.length===0,children:m("gitView.integrate.move")}):d.kind==="loading"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:m("gitView.integrate.checking")}):d.kind==="running"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:m("gitView.integrate.moving")}):null]}),d.kind==="ready"&&d.plan.commits.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:m("gitView.integrate.noCommitsToMove")}),d.kind==="ready"&&d.plan.commits.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"typography-meta text-foreground",children:[m("gitView.integrate.commitsToMove"),t.jsxs("span",{className:"text-muted-foreground",children:[" (",d.plan.commits.length,")"]})]}),N.length>0&&d.plan.commits.length>5&&t.jsx("button",{type:"button",onClick:()=>O(h=>!h),className:"typography-micro text-muted-foreground hover:text-foreground",children:m(R?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(R?N:N.slice(0,5)).map(h=>t.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[t.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:h.short}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:h.subject||h.sha})]},h.sha)),N.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:m("gitView.integrate.previewUnavailable")}),d.plan.commits.length>N.length&&t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:m("gitView.integrate.showingFirstCommits",{count:N.length})})]})]}),d.kind==="conflict"&&t.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[t.jsx("div",{className:"typography-meta text-foreground",children:m("gitView.integrate.conflictsInFiles",{count:d.details.unmergedFiles.length})}),t.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[m("gitView.integrate.currentCommit"),": ",t.jsx("span",{className:"font-mono",children:d.state.currentCommit.slice(0,7)})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[d.details.unmergedFiles.slice(0,6).map(h=>t.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:h},h)),d.details.unmergedFiles.length>6&&t.jsx("span",{className:"text-xs text-muted-foreground",children:m("gitView.integrate.moreFiles",{count:d.details.unmergedFiles.length-6})})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(W,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{Z()},children:m("gitView.operation.abort")}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!w,onClick:()=>{H({state:d.state,details:d.details},!1)},children:[t.jsx(D,{name:"sparkling",className:"size-3.5"}),m("gitView.integrate.currentSession")]}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{H({state:d.state,details:d.details},!0)},children:[t.jsx(D,{name:"sparkling",className:"size-3.5"}),m("gitView.integrate.newSession")]}),t.jsx(W,{size:"sm",className:"typography-meta",onClick:()=>{Q()},children:m("gitView.operation.continue")})]})]})]})]})},$a=({open:i,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:v=!1,uncommittedFileCount:f,onChanged:x})=>{const{t:p}=et(),[m,w]=l.useState([]),[B,y]=l.useState(!1),[C,k]=l.useState(""),[V,A]=l.useState(""),[I,d]=l.useState(null),[E,R]=l.useState({}),O=l.useCallback(async()=>{if(n){y(!0);try{const S=await Pn(n);w(S.stashes),R({})}catch(S){b.error(S instanceof Error?S.message:p("gitView.stashes.toast.loadFailed"))}finally{y(!1)}}},[n,p]);l.useEffect(()=>{i&&O()},[O,i]),l.useEffect(()=>{if(!i||!n||m.length===0)return;let S=!1;const F=m.map(J=>J.ref);return Fn(n,F).then(J=>{S||R(J.counts)}).catch(()=>{}),()=>{S=!0}},[n,i,m]);const N=l.useMemo(()=>{const S=C.trim().toLowerCase();return S?m.filter(F=>`${F.ref} ${F.message} ${F.relativeTime}`.toLowerCase().includes(S)):m},[C,m]),P=l.useCallback(async S=>{await O(),await x?.(S)},[O,x]),g=async()=>{if(!(!n||I)){d("create");try{const S=await Rn(n,{message:V.trim()||void 0});S.created?(b.success(p("gitView.stashes.toast.created")),A("")):b.info(p("gitView.stashes.toast.noChanges")),await P({affectsIndex:!!(S.created&&v)})}catch(S){b.error(S instanceof Error?S.message:p("gitView.stashes.toast.createFailed"))}finally{d(null)}}},U=async(S,F)=>{if(!(!n||I)&&!(F==="drop"&&!window.confirm(p("gitView.stashes.confirm.drop",{ref:S.ref})))){d(`${F}:${S.ref}`);try{F==="apply"&&await Mn(n,{ref:S.ref}),F==="pop"&&await Bn(n,{ref:S.ref}),F==="drop"&&await Tn(n,{ref:S.ref});const J=F==="apply"?"gitView.stashes.toast.applySuccess":F==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";b.success(p(J)),await P({affectsIndex:F!=="drop"})}catch(J){const H=F==="apply"?"gitView.stashes.toast.applyFailed":F==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";b.error(J instanceof Error?J.message:p(H)),await P({affectsIndex:F!=="drop"})}finally{d(null)}}},Y=I!==null;return t.jsx(ut,{open:i,onOpenChange:e,children:t.jsxs(mt,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsxs(ht,{children:[t.jsxs(gt,{className:"flex items-center gap-2",children:[t.jsx(D,{name:"archive-stack",className:"h-5 w-5"}),p("gitView.stashes.title")]}),t.jsx(wt,{children:p("gitView.stashes.description")})]}),t.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[t.jsx(nr,{value:V,onChange:S=>A(S.target.value),placeholder:p("gitView.stashes.messagePlaceholder"),disabled:Y||!r,className:"flex-1"}),t.jsxs(W,{onClick:g,disabled:!r||Y||!n,children:[I==="create"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"inbox-archive",className:"size-4"}),p("gitView.stashes.actions.stashCurrentWithCount",{count:f})]})]}),t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:p("gitView.stashes.includeUntrackedHint")})]}),t.jsxs("div",{className:"relative mt-2",children:[t.jsx(D,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(nr,{value:C,onChange:S=>k(S.target.value),placeholder:p("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:B?t.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:t.jsx(D,{name:"loader-4",className:"size-5 animate-spin"})}):N.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:p(C?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):N.map((S,F)=>t.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[t.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[t.jsx("p",{className:"typography-small truncate text-foreground",children:S.message||p("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[t.jsxs(Jt,{children:[t.jsx(qt,{asChild:!0,children:t.jsx("span",{children:F===0&&!C.trim()?p("gitView.stashes.latestLabel"):p("gitView.stashes.itemNumber",{number:F+1})})}),t.jsx(Yt,{sideOffset:6,children:S.ref})]})," · ",S.relativeTime," · ",typeof E[S.ref]=="number"?p("gitView.stashes.fileCount",{count:E[S.ref]}):p("gitView.stashes.fileCountLoading")]})]}),t.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[t.jsx(Ss,{label:p("gitView.stashes.actions.apply"),loading:I===`apply:${S.ref}`,onClick:()=>U(S,"apply"),disabled:Y,children:t.jsx(D,{name:"inbox-unarchive",className:"size-4"})}),t.jsx(Ss,{label:p("gitView.stashes.actions.pop"),loading:I===`pop:${S.ref}`,onClick:()=>U(S,"pop"),disabled:Y,children:t.jsx(D,{name:"inbox-unarchive-fill",className:"size-4"})}),t.jsx(Ss,{label:p("gitView.stashes.actions.drop"),loading:I===`drop:${S.ref}`,onClick:()=>U(S,"drop"),disabled:Y,destructive:!0,children:t.jsx(D,{name:"delete-bin",className:"size-4"})})]})]},S.ref))})]})})},Ss=i=>{const e=jt.c(17),{label:n,loading:r,disabled:v,destructive:f,onClick:x,children:p}=i,m=r||void 0,w=f?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let B;e[0]!==w?(B=Re("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",w),e[0]=w,e[1]=B):B=e[1];let y;e[2]!==p||e[3]!==r?(y=r?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):p,e[2]=p,e[3]=r,e[4]=y):y=e[4];let C;e[5]!==v||e[6]!==n||e[7]!==x||e[8]!==m||e[9]!==B||e[10]!==y?(C=t.jsx(qt,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":n,"aria-busy":m,className:B,onClick:x,disabled:v,children:y})}),e[5]=v,e[6]=n,e[7]=x,e[8]=m,e[9]=B,e[10]=y,e[11]=C):C=e[11];let k;e[12]!==n?(k=t.jsx(Yt,{sideOffset:6,children:n}),e[12]=n,e[13]=k):k=e[13];let V;return e[14]!==C||e[15]!==k?(V=t.jsxs(Jt,{children:[C,k]}),e[14]=C,e[15]=k,e[16]=V):V=e[16],V},Ha=i=>{const e=jt.c(16),{onOpenStashes:n}=i,{t:r}=et();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(D,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=v):v=e[0];let f;e[1]!==r?(f=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=f):f=e[2];let x;e[3]!==f?(x=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:f}),e[3]=f,e[4]=x):x=e[4];let p;e[5]!==r?(p=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=p):p=e[6];let m;e[7]!==p?(m=t.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:p}),e[7]=p,e[8]=m):m=e[8];let w;e[9]!==n||e[10]!==r?(w=n?t.jsxs(W,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[t.jsx(D,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=w):w=e[11];let B;return e[12]!==x||e[13]!==m||e[14]!==w?(B=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[v,x,m,w]}),e[12]=x,e[13]=m,e[14]=w,e[15]=B):B=e[15],B},dt=8,Wa=i=>{const e=jt.c(18),{laned:n,totalLanes:r,isExpanded:v}=i,{lane:f,color:x,connectors:p}=n,w=Math.max(r,f+1)*dt+dt/2,B=l.useRef(null),y=l.useRef(null);let C;e[0]!==x||e[1]!==p||e[2]!==f||e[3]!==w?(C=()=>{const d=B.current,E=y.current;if(!d||!E)return;const R=d.offsetHeight;if(R===0)return;const O=window.devicePixelRatio||1;E.width=w*O,E.height=R*O;const N=E.getContext("2d");if(!N)return;N.scale(O,O),N.clearRect(0,0,w,R);const P=R/2,g=f*dt+dt/2,U=getComputedStyle(E),Y=U.getPropertyValue("--surface-muted-foreground").trim()||U.color,S=H=>{if(!H.startsWith("var("))return H;const G=H.slice(4,-1).trim();return U.getPropertyValue(G).trim()||Y},F=[...p].sort(Ka);for(const H of F){const G=H.fromLane*dt+dt/2,Z=H.toLane*dt+dt/2,Q=H.type==="passing"?.72:H.type==="branch-out"||H.type==="merge-in"?.95:1;N.beginPath(),N.strokeStyle=S(H.color),N.globalAlpha=Q,N.lineWidth=1.25,N.lineCap="round";e:switch(H.type){case"passing":case"commit-lane":{N.moveTo(G,0),N.lineTo(G,R);break e}case"top-stub":{N.moveTo(G,0),N.lineTo(G,P);break e}case"bottom-stub":{N.moveTo(G,P),N.lineTo(G,R);break e}case"branch-out":{const se=(P+R)/2;N.moveTo(g,P),N.bezierCurveTo(g,se,Z,se,Z,R);break e}case"merge-in":{const se=P/2;N.moveTo(G,0),N.bezierCurveTo(G,se,g,se,g,P);break e}default:continue}N.stroke(),N.globalAlpha=1}const J=U.getPropertyValue("--background").trim()||U.getPropertyValue("--surface-background").trim();N.beginPath(),N.arc(g,P,4,0,Math.PI*2),N.fillStyle=S(x),N.fill(),N.beginPath(),N.arc(g,P,5,0,Math.PI*2),N.strokeStyle=J||Y,N.lineWidth=2,N.stroke()},e[0]=x,e[1]=p,e[2]=f,e[3]=w,e[4]=C):C=e[4];let k;e[5]!==x||e[6]!==p||e[7]!==v||e[8]!==f||e[9]!==n||e[10]!==r||e[11]!==w?(k=[n,f,x,p,r,v,w],e[5]=x,e[6]=p,e[7]=v,e[8]=f,e[9]=n,e[10]=r,e[11]=w,e[12]=k):k=e[12],l.useLayoutEffect(C,k);let V;e[13]!==w?(V={width:w,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=w,e[14]=V):V=e[14];let A;e[15]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx("canvas",{ref:y,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=A):A=e[15];let I;return e[16]!==V?(I=t.jsx("div",{ref:B,style:V,children:A}),e[16]=V,e[17]=I):I=e[17],I};function Ua(i){return i==="branch-out"||i==="merge-in"}function Ka(i,e){const n=Ua;return(n(i.type)?1:0)-(n(e.type)?1:0)}const lr=15e3,cr=500,dr=12,ur=8*1024*1024,mr=i=>typeof i=="string"?0:(i.original?.length??0)+(i.modified?.length??0),hr=i=>{if(i.size<=dr){let v=0;for(const f of i.values())v+=mr(f);if(v<=ur)return i}const e=Array.from(i.entries()).reverse(),n=new Map;let r=0;for(const[v,f]of e){if(n.size>=dr)continue;const x=mr(f);r+x>ur&&n.size>0||(n.set(v,f),r+=x)}return new Map(Array.from(n.entries()).reverse())};function gr(i,e){const n=new Date(i);return Number.isNaN(n.getTime())?i:An(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Ja(i){switch(i){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}function qa(i){return i?i.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const Ya=l.memo(({entry:i,mode:e="history",laned:n,totalLanes:r,isExpanded:v,onToggle:f,files:x,isLoadingFiles:p,onCopyHash:m,directory:w,onConflict:B,onActionSuccess:y})=>{const{t:C}=et(),k=xt(u=>u.timeFormatPreference),V=e==="graph",[A,I]=l.useState(null),[d,E]=l.useState(!1),[R,O]=l.useState(""),[N,P]=l.useState(null),[g,U]=l.useState(new Set),[Y,S]=l.useState(new Map),[F,J]=l.useState(new Set),H=async()=>{if(w){I("checkout");try{await Wn(w,i.hash),b.success(C("gitView.history.actions.detachedHead")),y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},G=async()=>{if(!(!w||!R.trim())){I("createBranch");try{await On(w,R.trim(),i.hash),E(!1),O(""),y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},Z=async()=>{if(w){I("cherryPick");try{const u=await Hn(w,i.hash);u.conflict?B?.({conflict:!0,conflictFiles:u.conflictFiles,operation:"cherry-pick"}):y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},Q=async()=>{if(w){I("revert");try{const u=await $n(w,i.hash);u.conflict?B?.({conflict:!0,conflictFiles:u.conflictFiles,operation:"revert"}):y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},se=async(u,M=!1)=>{if(!(!w||A!==null)){I("reset");try{await zn(w,i.hash,u,M),y?.()}catch($){b.error(String($.message))}finally{I(null)}}},ce=async()=>{if(!N)return;const u=N;switch(P(null),u){case"checkout":return H();case"cherryPick":return Z();case"revert":return Q();case"merge":return oe();case"rebase":return h();case"resetSoft":return se("soft");case"resetMixed":return se("mixed");case"resetHard":return se("hard",!0)}},oe=async()=>{if(w){I("merge");try{const u=await _n(w,{branch:i.hash});u.conflict?B?.({conflict:!0,conflictFiles:u.conflictFiles,operation:"merge"}):y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},h=async()=>{if(w){I("rebase");try{const u=await Gn(w,{onto:i.hash});u.conflict?B?.({conflict:!0,conflictFiles:u.conflictFiles,operation:"rebase"}):y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},L=l.useCallback(async u=>{const M=u.path;if(!w){S($=>new Map($).set(M,"error"));return}S($=>hr(new Map($).set(M,"loading")));try{const $=Dn(w,i.hash,u.path,!1),ae=new Promise((ee,_)=>{setTimeout(()=>_(new Error(`Timed out after ${lr}ms`)),lr)}),ie=await Promise.race([$,ae]);S(ee=>hr(new Map(ee).set(M,ie)))}catch{S($=>new Map($).set(M,"error"))}},[w,i.hash]),T=l.useCallback(async u=>{const M=u.path;if(u.changeType==="R"||u.isBinary){U(ee=>{const _=new Set(ee);return _.has(M)?_.delete(M):_.add(M),_});return}const $=Y.get(M);if(g.has(M)&&$&&$!=="error"){U(ee=>{const _=new Set(ee);return _.delete(M),_});return}U(ee=>{const _=new Set(ee);return _.add(M),_}),!($&&$!=="error"||u.insertions+u.deletions>cr&&!F.has(M))&&await L(u)},[Y,F,L,g]);return t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:f,className:Re("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",V?"hover:bg-[var(--interactive-hover)]/40":v?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[V&&n&&r!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(Wa,{laned:n,totalLanes:r,isExpanded:v})}):t.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),t.jsxs("div",{className:"min-w-0 flex-1",children:[V?(()=>{const u=qa(i.refs);return u.length>0?t.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:u.map(M=>t.jsx("span",{className:Re("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",M.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":M.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:M.label},M.label))}):null})():null,t.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:i.message}),t.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[t.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[t.jsx("span",{className:"truncate min-w-[3ch]",title:i.author_name,children:i.author_name}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("span",{className:"truncate min-w-0",title:gr(i.date,k),children:gr(i.date,k)})]}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("code",{className:"shrink-0 font-mono",children:i.hash.slice(0,8)}),t.jsxs(Jt,{children:[t.jsx(qt,{asChild:!0,children:t.jsx(W,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:u=>{u.stopPropagation(),m(i.hash)},children:t.jsx(D,{name:"file-copy",className:"size-3"})})}),t.jsx(Yt,{sideOffset:8,children:C("gitView.history.copySha")})]})]})]})]}),v&&t.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[V&&N?t.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:C(`gitView.history.actions.${N}Confirm`)}),t.jsxs(W,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:A!==null,onClick:u=>{u.stopPropagation(),ce()},children:[A!==null?t.jsx(D,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,C("gitView.history.actions.confirmButton")]}),t.jsx(W,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:A!==null,onClick:u=>{u.stopPropagation(),P(null)},children:C("gitView.history.actions.cancelButton")})]}):V?t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>{u.stopPropagation(),P("checkout")},children:C("gitView.history.actions.checkout")}),d?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{autoFocus:!0,value:R,onChange:u=>O(u.target.value),onKeyDown:u=>{u.key==="Enter"&&G(),u.key==="Escape"&&(E(!1),O(""))},placeholder:C("gitView.history.actions.createBranchPlaceholder"),className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),t.jsxs(W,{variant:"outline",size:"xs",className:"h-6",disabled:!R.trim()||A!==null,onClick:u=>{u.stopPropagation(),G()},children:[A==="createBranch"?t.jsx(D,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,C("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(W,{variant:"outline",size:"xs",className:"h-6",onClick:u=>{u.stopPropagation(),E(!0)},children:C("gitView.history.actions.createBranch")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>{u.stopPropagation(),P("cherryPick")},children:C("gitView.history.actions.cherryPick")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>{u.stopPropagation(),P("revert")},children:C("gitView.history.actions.revert")}),t.jsxs(Vs,{children:[t.jsx(Is,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>u.stopPropagation(),children:[A==="reset"?t.jsx(D,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,C("gitView.history.actions.reset")]})}),t.jsx(Ps,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(u=>t.jsx(En,{disabled:A!==null,onSelect:M=>{M.stopPropagation(),P(`reset${u.charAt(0).toUpperCase()+u.slice(1)}`)},children:C(`gitView.history.actions.reset${u.charAt(0).toUpperCase()+u.slice(1)}`)},u))})]}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>{u.stopPropagation(),P("merge")},children:C("gitView.history.actions.merge")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>{u.stopPropagation(),P("rebase")},children:C("gitView.history.actions.rebase")})]}):null,p?t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(D,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:C("gitView.history.loadingFiles")})]}):x.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:C("gitView.history.noFiles")}):t.jsx("ul",{className:"space-y-0.5 py-2",children:x.map(u=>t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:()=>T(u),className:Re("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",g.has(u.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[t.jsx("span",{className:Re("font-semibold w-3 text-center shrink-0",Ja(u.changeType)),children:u.changeType}),t.jsx("span",{className:"truncate text-foreground min-w-0",title:u.path,children:u.path}),!u.isBinary&&t.jsxs("span",{className:"shrink-0",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",u.insertions]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",u.deletions]})]}),u.isBinary&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:C("gitView.history.binary")}),t.jsx(D,{name:g.has(u.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),g.has(u.path)&&t.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:u.changeType==="R"?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.renamedNoDiff")}):u.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.binaryNoDiff")}):(()=>{const M=u.insertions+u.deletions;if(!F.has(u.path)&&M>cr)return t.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:C("gitView.history.largeDiffTitle",{count:M})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:C("gitView.history.largeDiffDescription")}),t.jsx(W,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{J(ae=>new Set(ae).add(u.path)),L(u)},children:C("gitView.history.renderDiffAnyway")})]});const $=Y.get(u.path);return $==="loading"||$===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.loadingDiff")}):$==="error"?t.jsx("button",{type:"button",onClick:()=>T(u),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:C("gitView.history.diffError")}):t.jsx(Ma,{original:$.original,modified:$.modified,language:Ln(u.path)||"",fileName:u.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},u.path))})]})]})}),fr=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--syntax-keyword)","var(--syntax-string)","var(--status-info)"];function $t(i){return fr[i%fr.length]}function Qa(i){if(i.length===0)return[];const e=[],n=[];for(let r=0;r<i.length;r++){const v=i[r],f=[];for(let k=0;k<e.length;k++)e[k]===v.hash&&f.push(k);let x=f.length>0?f[0]:-1;if(x===-1){const k=e.indexOf(null);k!==-1?x=k:(x=e.length,e.push(null))}const p=f.slice(1),m=$t(x),w=e[x]===v.hash,B=v.parents.length>0;B?e[x]=v.parents[0]:e[x]=null;const y=[];for(let k=1;k<v.parents.length;k++){const V=v.parents[k],A=e.indexOf(V);if(A!==-1)y.push(A);else{const I=e.indexOf(null),d=I!==-1?I:e.length;e[d]=V,d===e.length&&e.push(V),y.push(d)}}const C=[];w&&B?C.push({fromLane:x,toLane:x,color:m,type:"commit-lane"}):w&&!B?C.push({fromLane:x,toLane:x,color:m,type:"top-stub"}):!w&&B&&C.push({fromLane:x,toLane:x,color:m,type:"bottom-stub"});for(const k of p)C.push({fromLane:k,toLane:x,color:$t(k),type:"merge-in"}),e[k]=null;for(const k of y)C.push({fromLane:x,toLane:k,color:$t(k),type:"branch-out"});for(let k=0;k<e.length;k++)e[k]!==null&&k!==x&&(y.includes(k)||C.push({fromLane:k,toLane:k,color:$t(k),type:"passing"}));n.push({commit:v,lane:x,color:m,connectors:C})}return n}const Xa=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],Za=i=>{const e=jt.c(84),{mode:n,log:r,isLogLoading:v,logMaxCount:f,onLogMaxCountChange:x,expandedCommitHashes:p,onToggleCommit:m,commitFilesMap:w,loadingCommitHashes:B,onCopyHash:y,directory:C,showHeader:k,contentMaxHeightClassName:V,branchDivider:A,onConflict:I,onActionSuccess:d}=i,E=n===void 0?"history":n,R=k===void 0?!0:k,O=V===void 0?"max-h-[50vh]":V,N=A===void 0?null:A,{t:P}=et(),[g,U]=l.useState(!0),Y=E==="graph";let S;e[0]!==Y||e[1]!==r?(S=Y&&r?Qa(r.all):[],e[0]=Y,e[1]=r,e[2]=S):S=e[2];const F=S;let J;e[3]!==F?(J=Math.max(1,...F.map(ei)),e[3]=F,e[4]=J):J=e[4];const H=J;let G;e[5]!==F?(G=new Map(F.map(ti)),e[5]=F,e[6]=G):G=e[6];const Z=G;if(!r)return null;const Q=N!==null&&N.insertBeforeIndex>0&&N.insertBeforeIndex<r.all.length,se=N!==null&&N.insertBeforeIndex===r.all.length,ce=Q||se;let oe;e[7]!==N||e[8]!==Q||e[9]!==se||e[10]!==r.all?(oe=Q?r.all.slice(0,N.insertBeforeIndex):se?r.all:[],e[7]=N,e[8]=Q,e[9]=se,e[10]=r.all,e[11]=oe):oe=e[11];const h=oe;let L;if(e[12]!==N||e[13]!==w||e[14]!==O||e[15]!==C||e[16]!==p||e[17]!==Q||e[18]!==ce||e[19]!==Y||e[20]!==v||e[21]!==Z||e[22]!==B||e[23]!==r.all||e[24]!==f||e[25]!==H||e[26]!==E||e[27]!==d||e[28]!==I||e[29]!==y||e[30]!==x||e[31]!==m||e[32]!==P||e[33]!==h){const te=Q?r.all.slice(N.insertBeforeIndex):[];let de;e[35]!==N?.direction?(de=N?.direction==="down"?t.jsx(D,{name:"arrow-down-s",className:"size-3.5"}):t.jsx(D,{name:"arrow-up",className:"size-3.5"}),e[35]=N?.direction,e[36]=de):de=e[36];const ve=de;let ue;e[37]!==w||e[38]!==C||e[39]!==p||e[40]!==Y||e[41]!==Z||e[42]!==B||e[43]!==H||e[44]!==E||e[45]!==d||e[46]!==I||e[47]!==y||e[48]!==m?(ue=De=>t.jsx("ul",{className:"divide-y divide-border/60",children:De.map(je=>t.jsx(Ya,{entry:je,mode:E,laned:Y?Z.get(je.hash):void 0,totalLanes:Y?H:void 0,isExpanded:p.has(je.hash),onToggle:()=>m(je.hash),files:w.get(je.hash)??[],isLoadingFiles:B.has(je.hash),onCopyHash:y,directory:C,onConflict:I,onActionSuccess:d},je.hash))}),e[37]=w,e[38]=C,e[39]=p,e[40]=Y,e[41]=Z,e[42]=B,e[43]=H,e[44]=E,e[45]=d,e[46]=I,e[47]=y,e[48]=m,e[49]=ue):ue=e[49];const he=ue;let me;e[50]!==v||e[51]!==r.all.length||e[52]!==f||e[53]!==x||e[54]!==P?(me=r.all.length>=f?t.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:t.jsx(W,{type:"button",variant:"ghost",size:"xs",onClick:()=>x(f+25),disabled:v,className:"px-3 text-muted-foreground hover:text-foreground",children:v?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(D,{name:"loader-4",className:"size-3 animate-spin"}),P("gitView.history.loadingMore")]}):P("gitView.history.loadMore")})}):null,e[50]=v,e[51]=r.all.length,e[52]=f,e[53]=x,e[54]=P,e[55]=me):me=e[55];const le=me;L=t.jsx(yr,{outerClassName:`min-h-0 ${O}`,className:"h-full w-full",children:r.all.length===0?t.jsx("div",{className:"flex h-full items-center justify-center p-4",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:P("gitView.history.noCommits")})}):ce&&N?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col gap-0",children:[h.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:he(h)}):null,t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[t.jsx("span",{className:"h-px flex-1 bg-border/60"}),t.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[t.jsx("span",{className:"truncate",title:N.branchName,children:N.branchName}),ve]}),t.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),te.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:he(te)}):null]}),le]}):t.jsxs(t.Fragment,{children:[he(r.all),le]})}),e[12]=N,e[13]=w,e[14]=O,e[15]=C,e[16]=p,e[17]=Q,e[18]=ce,e[19]=Y,e[20]=v,e[21]=Z,e[22]=B,e[23]=r.all,e[24]=f,e[25]=H,e[26]=E,e[27]=d,e[28]=I,e[29]=y,e[30]=x,e[31]=m,e[32]=P,e[33]=h,e[34]=L}else L=e[34];const T=L;if(!R){if(ce){let de;return e[56]!==T?(de=t.jsx("section",{className:"h-full min-h-0",children:T}),e[56]=T,e[57]=de):de=e[57],de}let te;return e[58]!==T?(te=t.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:T}),e[58]=T,e[59]=te):te=e[59],te}let u;e[60]!==P?(u=P("gitView.history.title"),e[60]=P,e[61]=u):u=e[61];let M;e[62]!==u?(M=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:u}),e[62]=u,e[63]=M):M=e[63];let $;e[64]!==v||e[65]!==g||e[66]!==f||e[67]!==x||e[68]!==P?($=g&&t.jsx("div",{onClick:si,onPointerDown:ri,children:t.jsxs(Un,{value:String(f),onValueChange:te=>x(Number(te)),disabled:v,children:[t.jsx(Kn,{size:"sm",className:"w-auto",disabled:v,children:t.jsx(Jn,{placeholder:P("gitView.history.commitsPlaceholder")})}),t.jsx(qn,{children:Xa.map(te=>t.jsx(Yn,{value:String(te.value),children:P(te.labelKey)},te.value))})]})}),e[64]=v,e[65]=g,e[66]=f,e[67]=x,e[68]=P,e[69]=$):$=e[69];let ae;e[70]!==g?(ae=g?t.jsx(D,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):t.jsx(D,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=g,e[71]=ae):ae=e[71];let ie;e[72]!==$||e[73]!==ae?(ie=t.jsxs("div",{className:"flex items-center gap-2",children:[$,ae]}),e[72]=$,e[73]=ae,e[74]=ie):ie=e[74];let ee;e[75]!==M||e[76]!==ie?(ee=t.jsxs(Na,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[M,ie]}),e[75]=M,e[76]=ie,e[77]=ee):ee=e[77];let _;e[78]!==T?(_=t.jsx(Sa,{children:T}),e[78]=T,e[79]=_):_=e[79];let be;return e[80]!==g||e[81]!==ee||e[82]!==_?(be=t.jsxs(ka,{open:g,onOpenChange:U,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[ee,_]}),e[80]=g,e[81]=ee,e[82]=_,e[83]=be):be=e[83],be};function ei(i){return i.lane+1}function ti(i){return[i.commit.hash,i]}function si(i){return i.stopPropagation()}function ri(i){return i.stopPropagation()}const ni=i=>{const e=jt.c(150),{open:n,onOpenChange:r,conflictFiles:v,directory:f,operation:x,onAbort:p,onClearState:m}=i;let w;e[0]!==v?(w=v===void 0?[]:v,e[0]=v,e[1]=w):w=e[1];const B=w,{t:y}=et(),C=Ze(ai),k=Ze(ii),V=Wt(oi),A=Wt(li),I=xt(ci),[d,E]=l.useState(!1),[R,O]=l.useState(null),[N,P]=l.useState(null);let g,U;e[2]!==f||e[3]!==n||e[4]!==y?(g=()=>{!n||!f||(E(!0),P(null),O(null),Qn(f).then(X=>{O(X)}).catch(X=>{const Pe=X instanceof Error?X.message:y("gitView.conflict.loadFailed");P(Pe)}).finally(()=>{E(!1)}))},U=[n,f,y],e[2]=f,e[3]=n,e[4]=y,e[5]=g,e[6]=U):(g=e[5],U=e[6]),l.useEffect(g,U);let Y;e[7]!==R||e[8]!==f||e[9]!==x?(Y=async()=>{if(!R)return null;const X=x==="merge"?"merge":"rebase",Pe=R.headInfo||(x==="merge"?"MERGE_HEAD":"REBASE_HEAD"),Oe=x==="merge"?"git commit --no-edit":"git rebase --continue",ze=await Ht("git.conflict.resolve.visible",{operation_label:X,head_ref:Pe}),Fe=await Ht("git.conflict.resolve.instructions",{operation_label:X,directory:f,operation:x,head_info:R.headInfo||"N/A",continue_cmd:Oe}),pe=`${X} conflict context (JSON)
|
|
3
3
|
${JSON.stringify({directory:f,operation:R.operation,headInfo:R.headInfo,statusPorcelain:R.statusPorcelain,unmergedFiles:R.unmergedFiles,diff:R.diff},null,2)}`;return{visibleText:ze,instructionsText:Fe,payloadText:pe}},e[7]=R,e[8]=f,e[9]=x,e[10]=Y):Y=e[10];const S=Y;let F;e[11]!==p||e[12]!==r?(F=()=>{p(),r(!1)},e[11]=p,e[12]=r,e[13]=F):F=e[13];const J=F;let H;e[14]!==m||e[15]!==r?(H=()=>{m?.(),r(!1)},e[14]=m,e[15]=r,e[16]=H):H=e[16];const G=H;let Z;e[17]!==S||e[18]!==k||e[19]!==m||e[20]!==r||e[21]!==I||e[22]!==V||e[23]!==A||e[24]!==y?(Z=async()=>{const X=await S();if(!X){b.error(y("gitView.conflict.noDetailsAvailable"));return}if(!k){b.error(y("gitView.conflict.noActiveSession"),{description:y("gitView.conflict.noActiveSessionDescription")});return}V(X.visibleText,"replace"),A([{text:X.instructionsText,synthetic:!0},{text:X.payloadText,synthetic:!0}]),I("chat"),m?.(),r(!1)},e[17]=S,e[18]=k,e[19]=m,e[20]=r,e[21]=I,e[22]=V,e[23]=A,e[24]=y,e[25]=Z):Z=e[25];const Q=Z;let se;e[26]!==S||e[27]!==f||e[28]!==m||e[29]!==r||e[30]!==C||e[31]!==I||e[32]!==y?(se=async()=>{const X=await S();if(!X){b.error(y("gitView.conflict.noDetailsAvailable"));return}C({directoryOverride:f,initialPrompt:X.visibleText,syntheticParts:[{text:X.instructionsText,synthetic:!0},{text:X.payloadText,synthetic:!0}]}),I("chat"),m?.(),r(!1)},e[26]=S,e[27]=f,e[28]=m,e[29]=r,e[30]=C,e[31]=I,e[32]=y,e[33]=se):se=e[33];const ce=se;let oe,h,L,T,u,M,$,ae,ie,ee,_,be,te,de,ve,ue,he,me,le,De,je,ge;if(e[34]!==R||e[35]!==B||e[36]!==k||e[37]!==J||e[38]!==G||e[39]!==Q||e[40]!==ce||e[41]!==d||e[42]!==N||e[43]!==r||e[44]!==n||e[45]!==x||e[46]!==y){const X=y(x==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),Pe=R?.unmergedFiles||B;L=ut,je=n,ge=r,h=mt,De="max-w-md w-[calc(100vw-2rem)]",de="flex flex-col gap-4 overflow-hidden";let Oe;e[69]===Symbol.for("react.memo_cache_sentinel")?(Oe=t.jsx(D,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=Oe):Oe=e[69];const ze=t.jsxs("div",{className:"flex items-center gap-2",children:[Oe,t.jsx(gt,{children:y("gitView.conflict.detectedTitle",{operation:X})})]});let Fe;e[70]!==x||e[71]!==y?(Fe=y("gitView.conflict.detectedDescription",{operation:x}),e[70]=x,e[71]=y,e[72]=Fe):Fe=e[72];let pe;e[73]!==Fe?(pe=t.jsx(wt,{children:Fe}),e[73]=Fe,e[74]=pe):pe=e[74],e[75]!==ze||e[76]!==pe?(ve=t.jsxs(ht,{children:[ze,pe]}),e[75]=ze,e[76]=pe,e[77]=ve):ve=e[77],e[78]!==d||e[79]!==y?(ue=d&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:y("gitView.conflict.loading")})]}),e[78]=d,e[79]=y,e[80]=ue):ue=e[80],e[81]!==N||e[82]!==y?(he=N&&t.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:y("gitView.conflict.errorLoadingDetails",{message:N})}),e[81]=N,e[82]=y,e[83]=he):he=e[83],e[84]!==Pe||e[85]!==y?(me=Pe.length>0&&t.jsxs("div",{className:"space-y-2 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:y("gitView.conflict.conflictedFiles")}),t.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:Pe.length})]}),t.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:t.jsx("ul",{className:"space-y-1",children:Pe.map(di)})})]}),e[84]=Pe,e[85]=y,e[86]=me):me=e[86],e[87]!==R||e[88]!==y?(le=R?.headInfo&&t.jsxs("div",{className:"space-y-1 overflow-hidden",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:y("gitView.conflict.headInfo")}),t.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:R.headInfo})]}),e[87]=R,e[88]=y,e[89]=le):le=e[89],_="flex flex-col gap-2 pt-2";let Ce;e[90]!==ce?(Ce=()=>{ce()},e[90]=ce,e[91]=Ce):Ce=e[91];const Ge=d||!R;let Ne;e[92]!==d?(Ne=d?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"add",className:"size-4"}),e[92]=d,e[93]=Ne):Ne=e[93];let Be;e[94]!==y?(Be=y("gitView.conflict.resolveNewSession"),e[94]=y,e[95]=Be):Be=e[95],e[96]!==Ce||e[97]!==Ge||e[98]!==Ne||e[99]!==Be?(be=t.jsxs(W,{variant:"default",onClick:Ce,disabled:Ge,className:"w-full gap-2",children:[Ne,Be]}),e[96]=Ce,e[97]=Ge,e[98]=Ne,e[99]=Be,e[100]=be):be=e[100];let q;e[101]!==Q?(q=()=>{Q()},e[101]=Q,e[102]=q):q=e[102];const xe=d||!R||!k;let Se;e[103]!==d?(Se=d?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"chat-1",className:"size-4"}),e[103]=d,e[104]=Se):Se=e[104];let we;e[105]!==y?(we=y("gitView.conflict.resolveCurrentSession"),e[105]=y,e[106]=we):we=e[106],e[107]!==q||e[108]!==xe||e[109]!==Se||e[110]!==we?(te=t.jsxs(W,{variant:"outline",onClick:q,disabled:xe,className:"w-full gap-2",children:[Se,we]}),e[107]=q,e[108]=xe,e[109]=Se,e[110]=we,e[111]=te):te=e[111],ie="flex gap-2 pt-1";let ye;e[112]!==y?(ye=y("gitView.conflict.continueLater"),e[112]=y,e[113]=ye):ye=e[113],e[114]!==G||e[115]!==ye?(ee=t.jsx(W,{variant:"ghost",size:"sm",onClick:G,className:"flex-1",children:ye}),e[114]=G,e[115]=ye,e[116]=ee):ee=e[116],oe=W,T="destructive",u="sm",M=J,$="flex-1",ae=y("gitView.conflict.abortOperation",{operation:X}),e[34]=R,e[35]=B,e[36]=k,e[37]=J,e[38]=G,e[39]=Q,e[40]=ce,e[41]=d,e[42]=N,e[43]=r,e[44]=n,e[45]=x,e[46]=y,e[47]=oe,e[48]=h,e[49]=L,e[50]=T,e[51]=u,e[52]=M,e[53]=$,e[54]=ae,e[55]=ie,e[56]=ee,e[57]=_,e[58]=be,e[59]=te,e[60]=de,e[61]=ve,e[62]=ue,e[63]=he,e[64]=me,e[65]=le,e[66]=De,e[67]=je,e[68]=ge}else oe=e[47],h=e[48],L=e[49],T=e[50],u=e[51],M=e[52],$=e[53],ae=e[54],ie=e[55],ee=e[56],_=e[57],be=e[58],te=e[59],de=e[60],ve=e[61],ue=e[62],he=e[63],me=e[64],le=e[65],De=e[66],je=e[67],ge=e[68];let Ve;e[117]!==oe||e[118]!==T||e[119]!==u||e[120]!==M||e[121]!==$||e[122]!==ae?(Ve=t.jsx(oe,{variant:T,size:u,onClick:M,className:$,children:ae}),e[117]=oe,e[118]=T,e[119]=u,e[120]=M,e[121]=$,e[122]=ae,e[123]=Ve):Ve=e[123];let Me;e[124]!==ie||e[125]!==ee||e[126]!==Ve?(Me=t.jsxs("div",{className:ie,children:[ee,Ve]}),e[124]=ie,e[125]=ee,e[126]=Ve,e[127]=Me):Me=e[127];let Ee;e[128]!==_||e[129]!==be||e[130]!==te||e[131]!==Me?(Ee=t.jsxs("div",{className:_,children:[be,te,Me]}),e[128]=_,e[129]=be,e[130]=te,e[131]=Me,e[132]=Ee):Ee=e[132];let Ie;e[133]!==de||e[134]!==ve||e[135]!==ue||e[136]!==he||e[137]!==me||e[138]!==le||e[139]!==Ee?(Ie=t.jsxs("div",{className:de,children:[ve,ue,he,me,le,Ee]}),e[133]=de,e[134]=ve,e[135]=ue,e[136]=he,e[137]=me,e[138]=le,e[139]=Ee,e[140]=Ie):Ie=e[140];let Le;e[141]!==h||e[142]!==De||e[143]!==Ie?(Le=t.jsx(h,{className:De,children:Ie}),e[141]=h,e[142]=De,e[143]=Ie,e[144]=Le):Le=e[144];let fe;return e[145]!==L||e[146]!==je||e[147]!==ge||e[148]!==Le?(fe=t.jsx(L,{open:je,onOpenChange:ge,children:Le}),e[145]=L,e[146]=je,e[147]=ge,e[148]=Le,e[149]=fe):fe=e[149],fe};function ai(i){return i.openNewSessionDraft}function ii(i){return i.currentSessionId}function oi(i){return i.setPendingInputText}function li(i){return i.setPendingSyntheticParts}function ci(i){return i.setActiveMainTab}function di(i){return t.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:i,children:i},i)}const ui=({open:i,onOpenChange:e,operation:n,targetBranch:r,onConfirm:v})=>{const{t:f}=et(),[x,p]=l.useState(!0),[m,w]=l.useState(!1),B=f(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),y=async()=>{w(!0);try{await v(x),e(!1)}catch(k){const V=k instanceof Error?k.message:`Failed to ${n}`;b.error(V)}finally{w(!1)}},C=()=>{m||e(!1)};return t.jsx(ut,{open:i,onOpenChange:m?void 0:e,children:t.jsxs(mt,{className:"max-w-md",children:[t.jsxs(ht,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),t.jsx(gt,{children:f("gitView.stash.title")})]}),t.jsx(wt,{children:f("gitView.stash.description",{operation:n})})]}),t.jsxs("div",{className:"py-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:f("gitView.stash.thisWill")}),t.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[t.jsx("li",{children:f("gitView.stash.stepStash")}),t.jsxs("li",{children:[f(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",f(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",t.jsx("span",{className:"font-mono text-primary",children:r})]}),x&&t.jsx("li",{children:f("gitView.stash.stepRestore")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(Xn,{checked:x,onChange:p,disabled:m,ariaLabel:f("gitView.stash.restoreAria")}),t.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!m&&p(!x),children:f("gitView.stash.restoreAfterOperation",{operation:n})})]}),t.jsxs(ks,{className:"gap-2",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:C,disabled:m,children:f("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:y,disabled:m,className:"gap-1.5",children:m?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),f("gitView.common.processing")]}):f("gitView.stash.confirmButton",{operation:B})})]})]})})},mi=({mergeInProgress:i,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:v,conflictCount:f=0,isLoading:x=!1})=>{const{t:p}=et(),[m,w]=l.useState(null),B=i&&i.head,y=e&&(e.headName||e.onto),C=B?"merge":y?"rebase":null;if(!C)return null;const k=async()=>{w("continue");try{await n()}finally{w(null)}},V=async()=>{w("abort");try{await r()}finally{w(null)}},A=m!==null,I=f>0,d=p(C==="merge"?"gitView.operation.merge":"gitView.operation.rebase");let E="";i?E=i.message?p("gitView.operation.mergingMessage",{message:i.message}):p("gitView.operation.mergeInProgressWithHead",{head:i.head}):e&&(E=e.headName?p("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):p("gitView.operation.rebaseInProgress"));const R=I?f===1?p("gitView.operation.inProgressTitleOneConflict",{operation:d,count:f}):p("gitView.operation.inProgressTitleManyConflicts",{operation:d,count:f}):p("gitView.operation.inProgressTitle",{operation:d}),O=p(I?"gitView.operation.resolveConflictsHint":"gitView.operation.readyToContinueHint");return t.jsx("div",{className:"mx-4 mt-3 overflow-hidden rounded-lg border border-[var(--status-warning-border)]",children:t.jsxs("div",{className:"flex flex-col gap-3 p-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:R}),E&&t.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:E})]}),t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("p",{className:"typography-micro min-w-0 flex-1 text-muted-foreground",children:O}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[t.jsxs(W,{variant:"ghost",size:"sm",onClick:V,disabled:A||x,className:"gap-1.5",children:[m==="abort"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"close",className:"size-4"}),p("gitView.operation.abort")]}),I?v&&t.jsx(W,{variant:"default",size:"sm",onClick:v,disabled:A||x,children:p("gitView.operation.resolveWithAi")}):t.jsxs(W,{variant:"default",size:"sm",onClick:k,disabled:A||x,className:"gap-1.5",children:[m==="continue"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"check",className:"size-4"}),p("gitView.operation.continue")]})]})]})]})})},hi=i=>{const e=jt.c(104),{currentBranch:n,localBranches:r,remoteBranches:v,onMerge:f,onRebase:x,disabled:p,isOperating:m,operationLogs:w,onOperationComplete:B,mode:y,defaultTargetBranch:C}=i,k=p===void 0?!1:p,V=m===void 0?!1:m,A=w===void 0?[]:w,I=y===void 0?"dialog":y,{t:d}=et(),[E,R]=l.useState(!1),[O,N]=l.useState("merge"),[P,g]=l.useState(null),[U,Y]=l.useState(!1),[S,F]=l.useState(""),J=l.useRef(null),H=l.useRef(null),G=k||V,Z=n||d("gitView.branch.currentBranchFallback"),Q=A.length>0&&A.every(gi),se=A.some(fi);let ce;e[0]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>{H.current&&(H.current.scrollTop=H.current.scrollHeight)},e[0]=ce):ce=e[0],l.useEffect(ce,[A]);let oe;if(e[1]!==S||e[2]!==n||e[3]!==r||e[4]!==v){e:{const q=S.toLowerCase();let xe;e[6]!==v?(xe=new Set(v.map(pi).filter(Boolean)),e[6]=v,e[7]=xe):xe=e[7];const Se=xe;let we;e[8]!==n||e[9]!==Se?(we=_e=>_e!==n&&!Se.has(_e),e[8]=n,e[9]=Se,e[10]=we):we=e[10];const ye=r.filter(we);if(!q){oe=ye;break e}oe=ye.filter(_e=>_e.toLowerCase().includes(q))}e[1]=S,e[2]=n,e[3]=r,e[4]=v,e[5]=oe}else oe=e[5];const h=oe;let L;if(e[11]!==S||e[12]!==v){e:{const q=S.toLowerCase();if(!q){L=v;break e}L=v.filter(xe=>xe.toLowerCase().includes(q))}e[11]=S,e[12]=v,e[13]=L}else L=e[13];const T=L;let u;e[14]!==C||e[15]!==r||e[16]!==v?(u=()=>C&&(v.includes(C)||r.includes(C))?C:null,e[14]=C,e[15]=r,e[16]=v,e[17]=u):u=e[17];const M=u;let $;e[18]!==M||e[19]!==R?($=()=>{R(!0),g(M()),N("merge"),F("")},e[18]=M,e[19]=R,e[20]=$):$=e[20];const ae=$;let ie;e[21]===Symbol.for("react.memo_cache_sentinel")?(ie=q=>{g(q),Y(!1),F("")},e[21]=ie):ie=e[21];const ee=ie;let _;e[22]!==f||e[23]!==x||e[24]!==O||e[25]!==P?(_=()=>{P&&(O==="merge"?f(P):x(P))},e[22]=f,e[23]=x,e[24]=O,e[25]=P,e[26]=_):_=e[26];const be=_;let te;e[27]!==V||e[28]!==R?(te=()=>{V||(g(null),N("merge"),F(""),R(!1))},e[27]=V,e[28]=R,e[29]=te):te=e[29];const de=te,ve=()=>{V&&!Q||(Q&&B?.(),g(null),N("merge"),F(""),R(!1))};let ue,he;e[30]!==U?(ue=()=>{U||F("")},he=[U],e[30]=U,e[31]=ue,e[32]=he):(ue=e[31],he=e[32]),l.useEffect(ue,he);let me,le;e[33]!==I||e[34]!==M||e[35]!==P?(me=()=>{I==="dialog"||P||g(M())},le=[I,M,P],e[33]=I,e[34]=M,e[35]=P,e[36]=me,e[37]=le):(me=e[36],le=e[37]),l.useEffect(me,le);const ge=V?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{ref:H,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:t.jsx("div",{className:"space-y-2",children:A.map(xi)})}),Q?I==="dialog"?t.jsx(ks,{children:t.jsx(W,{variant:"default",size:"sm",onClick:ve,children:d(se?"gitView.common.close":"gitView.common.done")})}):t.jsx("div",{className:"flex justify-end",children:t.jsx(W,{variant:"default",size:"sm",onClick:ve,children:d(se?"gitView.common.close":"gitView.common.done")})}):null]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.operation")}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>N("merge"),className:Re("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",O==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"git-merge",className:Re("size-4",O==="merge"?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Re("typography-ui-label",O==="merge"?"text-foreground":"text-muted-foreground"),children:d("gitView.operation.merge")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:d("gitView.branch.mergeDescription")})]}),t.jsxs("button",{type:"button",onClick:()=>N("rebase"),className:Re("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",O==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"git-branch",className:Re("size-4",O==="rebase"?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Re("typography-ui-label",O==="rebase"?"text-foreground":"text-muted-foreground"),children:d("gitView.operation.rebase")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:d("gitView.branch.rebaseDescription")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:O==="merge"?d("gitView.branch.branchToMergeInto",{branch:Z}):d("gitView.branch.branchToRebaseOnto")}),t.jsxs(Vs,{open:U,onOpenChange:Y,modal:!1,children:[t.jsx(Is,{asChild:!0,children:t.jsxs("button",{type:"button",className:Re(wr({size:"default"}),"w-full"),children:[t.jsx("span",{className:Re("truncate",!P&&"text-muted-foreground"),children:P||d("gitView.branch.selectBranch")}),t.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),t.jsx(Ps,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:t.jsxs(Fs,{className:"h-full min-h-0",children:[t.jsx(Rs,{ref:J,placeholder:d("gitView.branch.searchPlaceholder"),value:S,onValueChange:F,onKeyDown:wi}),t.jsxs(Ms,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(Bs,{children:d("gitView.branch.empty")}),h.length>0&&t.jsx(Ut,{heading:d("gitView.branch.localBranches"),children:h.map(q=>t.jsx(Kt,{onSelect:()=>ee(q),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q})},`local-${q}`))}),h.length>0&&T.length>0?t.jsx(Zn,{}):null,T.length>0&&t.jsx(Ut,{heading:d("gitView.branch.remoteBranches"),children:T.map(q=>t.jsx(Kt,{onSelect:()=>ee(q),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q})},`remote-${q}`))})]})]})})]})]}),P?t.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:O==="merge"?t.jsxs(t.Fragment,{children:[d("gitView.branch.summaryMergePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P})," ",d("gitView.branch.summaryMergeInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Z})]}):t.jsxs(t.Fragment,{children:[d("gitView.branch.summaryRebasePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Z})," ",d("gitView.branch.summaryRebaseInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P})]})})}):null,I==="dialog"?t.jsxs(ks,{className:"gap-2 pt-1",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:de,children:d("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:be,disabled:!P,className:"gap-1.5",children:O==="merge"?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"git-merge",className:"size-4"}),d("gitView.operation.merge")]}):t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"git-branch",className:"size-4"}),d("gitView.operation.rebase")]})})]}):t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(W,{variant:"destructive",size:"sm",onClick:de,disabled:G,children:d("gitView.common.reset")}),t.jsx("div",{className:"flex-1"}),t.jsx(W,{variant:"default",size:"sm",onClick:be,disabled:G||!P,children:d(O==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(I==="bare")return ge;if(I==="inline"){let q;e[38]!==d?(q=d("gitView.branch.updateTitle"),e[38]=d,e[39]=q):q=e[39];let xe;e[40]!==q?(xe=t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:q}),e[40]=q,e[41]=xe):xe=e[41];let Se;e[42]!==d?(Se=d("gitView.branch.updateDescriptionPrefix"),e[42]=d,e[43]=Se):Se=e[43];let we;e[44]!==Z?(we=t.jsx("span",{className:"font-mono text-foreground",children:Z}),e[44]=Z,e[45]=we):we=e[45];let ye;e[46]!==Se||e[47]!==we?(ye=t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Se," ",we,"."]}),e[46]=Se,e[47]=we,e[48]=ye):ye=e[48];let _e;e[49]!==xe||e[50]!==ye?(_e=t.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:t.jsxs("div",{className:"space-y-1",children:[xe,ye]})}),e[49]=xe,e[50]=ye,e[51]=_e):_e=e[51];let tt;e[52]!==ge?(tt=t.jsx("div",{className:"pt-3",children:ge}),e[52]=ge,e[53]=tt):tt=e[53];let st;return e[54]!==_e||e[55]!==tt?(st=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[_e,tt]}),e[54]=_e,e[55]=tt,e[56]=st):st=e[56],st}let Ve;e[57]!==V?(Ve=V?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"git-merge",className:"size-4"}),e[57]=V,e[58]=Ve):Ve=e[58];let Me;e[59]!==d?(Me=d("gitView.branch.mergeRebase"),e[59]=d,e[60]=Me):Me=e[60];let Ee;e[61]!==Me?(Ee=t.jsx("span",{children:Me}),e[61]=Me,e[62]=Ee):Ee=e[62];let Ie;e[63]!==ae||e[64]!==G||e[65]!==Ve||e[66]!==Ee?(Ie=t.jsx(qt,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ae,disabled:G,children:[Ve,Ee]})}),e[63]=ae,e[64]=G,e[65]=Ve,e[66]=Ee,e[67]=Ie):Ie=e[67];let Le;e[68]!==d?(Le=d("gitView.branch.mergeRebaseTooltip"),e[68]=d,e[69]=Le):Le=e[69];let fe;e[70]!==Le?(fe=t.jsx(Yt,{sideOffset:8,children:Le}),e[70]=Le,e[71]=fe):fe=e[71];let X;e[72]!==Ie||e[73]!==fe?(X=t.jsxs(Jt,{children:[Ie,fe]}),e[72]=Ie,e[73]=fe,e[74]=X):X=e[74];let Pe;e[75]!==ve||e[76]!==R?(Pe=q=>{q?R(!0):ve()},e[75]=ve,e[76]=R,e[77]=Pe):Pe=e[77];let Oe;e[78]!==d?(Oe=d("gitView.branch.updateTitle"),e[78]=d,e[79]=Oe):Oe=e[79];let ze;e[80]!==Oe?(ze=t.jsx(gt,{children:Oe}),e[80]=Oe,e[81]=ze):ze=e[81];let Fe;e[82]!==se||e[83]!==V||e[84]!==O||e[85]!==Q||e[86]!==d||e[87]!==Z?(Fe=V?d(Q?se?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":O==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):t.jsxs(t.Fragment,{children:[d("gitView.branch.dialogDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Z}),"."]}),e[82]=se,e[83]=V,e[84]=O,e[85]=Q,e[86]=d,e[87]=Z,e[88]=Fe):Fe=e[88];let pe;e[89]!==Fe?(pe=t.jsx(wt,{children:Fe}),e[89]=Fe,e[90]=pe):pe=e[90];let Ce;e[91]!==ze||e[92]!==pe?(Ce=t.jsxs(ht,{children:[ze,pe]}),e[91]=ze,e[92]=pe,e[93]=Ce):Ce=e[93];let Ge;e[94]!==ge||e[95]!==Ce?(Ge=t.jsxs(mt,{className:"max-w-md",children:[Ce,ge]}),e[94]=ge,e[95]=Ce,e[96]=Ge):Ge=e[96];let Ne;e[97]!==E||e[98]!==Pe||e[99]!==Ge?(Ne=t.jsx(ut,{open:E,onOpenChange:Pe,children:Ge}),e[97]=E,e[98]=Pe,e[99]=Ge,e[100]=Ne):Ne=e[100];let Be;return e[101]!==X||e[102]!==Ne?(Be=t.jsxs(t.Fragment,{children:[X,Ne]}),e[101]=X,e[102]=Ne,e[103]=Be):Be=e[103],Be};function gi(i){return i.status==="done"||i.status==="error"}function fi(i){return i.status==="error"}function pi(i){return i.slice(i.indexOf("/")+1)}function xi(i,e){return t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("div",{className:"mt-0.5 shrink-0",children:[i.status==="running"&&t.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),i.status==="done"&&t.jsx(D,{name:"check",className:"size-3.5 text-success"}),i.status==="error"&&t.jsx(D,{name:"close",className:"size-3.5 text-destructive"}),i.status==="pending"&&t.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),t.jsx("span",{className:Re("typography-micro",i.status==="error"&&"text-destructive",i.status==="done"&&"text-muted-foreground",i.status==="running"&&"text-foreground",i.status==="pending"&&"text-muted-foreground/60"),children:i.message})]},e)}function wi(i){return i.stopPropagation()}const yi=({runMutation:i,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:v})=>{const f=[];let x=!1;return{enqueue:m=>{const w=f[f.length-1];if(w?.directory===m.directory&&w.direction===m.direction){m.paths.forEach(B=>w.paths.add(B));return}f.push(m)},flush:()=>{if(x)return;const m=f.shift();if(!m)return;x=!0;const w={directory:m.directory,direction:m.direction,paths:Array.from(m.paths),rollback:m.rollback};(async()=>{try{await i(w),e(w)}catch(B){n(w,B)}finally{r(w.paths),x=!1,f.length>0&&v()}})()},clear:()=>{f.length=0},size:()=>f.length,isRunning:()=>x}},bi=15e3,vi=40,ji=20,pr={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Ci=(i,e)=>{const n=i.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,v=n.match(r);if(v){const p=v[1],m=pr[p];if(m)return e.find(w=>w.code===m)||null}const f=n.split(" ")[0],x=pr[f];return x&&e.find(p=>p.code===x)||null},Ni=20,vt=new Map,Si=(i,e)=>{if(vt.delete(i),vt.set(i,e),vt.size>Ni){const n=vt.keys().next().value;n!==void 0&&vt.delete(n)}},nt=i=>(i||"").replace(/\\/g,"/").replace(/\/+$/,""),xr=i=>{const e=i.index?.trim();return!!(e&&e!=="?")},ki=i=>{const e=i.working_dir?.trim(),n=i.index?.trim();return!!(e||n==="?")},zl=({isActive:i})=>{const{t:e}=et(),{git:n}=ea(),r=ta(),[v,f]=l.useState(null),[x,p]=l.useState(!1),m=Ze(s=>s.currentSessionId),w=Ze(s=>s.newSessionDraft),B=Ze(s=>s.setDraftBootstrapPendingDirectory),y=Ze(s=>s.worktreeMetadata),C=Ze(s=>s.availableWorktrees),k=nt(r),V=l.useMemo(()=>{if(!k)return;const s=C.find(a=>nt(a.path)===k);if(s)return s;for(const a of y.values())if(nt(a.path)===k)return a},[C,k,y]),A=l.useMemo(()=>{if(m)return y.get(m)??V;if(w?.open)return V},[m,V,w?.open,y]),{profiles:I,globalIdentity:d,defaultGitIdentityId:E,loadProfiles:R,loadGlobalIdentity:O,loadDefaultGitIdentityId:N}=Va(ar(s=>({profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId}))),P=sa(r??null),g=ra(r??null),U=na(s=>m?s.getAttachment(m):void 0),Y=U?aa(U):[],S=U&&!U.degraded&&!U.legacy?U.worktreeRoot??void 0:void 0,F=va(r,A,g?.current??void 0),J=ia(r??null),H=oa(r??null),G=la(r??null),Z=ca(r??null),Q=da(r??null),{setActiveDirectory:se,fetchAll:ce,ensureAll:oe,fetchStatus:h,fetchBranches:L,fetchLog:T,setLogMaxCount:u,fetchIdentity:M,prefetchDiffs:$,clearDiffCache:ae,moveStatusPathsOptimistically:ie,restoreStatus:ee,bumpIndexRevision:_}=ua(ar(s=>({setActiveDirectory:s.setActiveDirectory,fetchAll:s.fetchAll,ensureAll:s.ensureAll,fetchStatus:s.fetchStatus,fetchBranches:s.fetchBranches,fetchLog:s.fetchLog,setLogMaxCount:s.setLogMaxCount,fetchIdentity:s.fetchIdentity,prefetchDiffs:s.prefetchDiffs,clearDiffCache:s.clearDiffCache,moveStatusPathsOptimistically:s.moveStatusPathsOptimistically,restoreStatus:s.restoreStatus,bumpIndexRevision:s.bumpIndexRevision}))),be=xt(s=>s.isMobile),te=xt(s=>s.openContextDiff),de=xt(s=>s.openContextSurface),ve=g?.current??null,ue=ma(s=>!r||!ve?null:ha(s.entries,r,ve)),he=xt(s=>s.navigateToDiff),me=l.useRef(null),le=l.useRef(null),De=l.useRef(null),je=l.useRef(null),ge=l.useRef(!0);l.useEffect(()=>()=>{ge.current=!1},[]);const Ve=l.useCallback(()=>{le.current!==null&&(window.clearTimeout(le.current),le.current=null)},[]),Me=l.useCallback(s=>{Ve(),le.current=window.setTimeout(()=>{le.current=null,nt(s)===nt(r)&&h(s,n,{silent:!0})},bi)},[Ve,r,h,n]);l.useEffect(()=>Ve,[Ve]);const Ee=l.useCallback(()=>{De.current!==null&&(window.clearTimeout(De.current),De.current=null)},[]),Ie=l.useCallback(()=>{De.current===null&&(De.current=window.setTimeout(()=>{De.current=null,je.current?.()},0))},[]),Le=l.useCallback(async(s,a,o)=>{if(a==="stage"){if(n.stageGitFiles){await n.stageGitFiles(s,o);return}await Promise.all(o.map(c=>n.stageGitFile(s,c)));return}if(n.unstageGitFiles){await n.unstageGitFiles(s,o);return}await Promise.all(o.map(c=>n.unstageGitFile(s,c)))},[n]),fe=l.useMemo(()=>yi({runMutation:({directory:s,direction:a,paths:o})=>Le(s,a,o),onMutationComplete:({directory:s})=>{_(s),Me(s)},onMutationError:({directory:s,direction:a,rollback:o},c)=>{o?.(),_(s),Me(s);const j=e(a==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");b.error(c instanceof Error?c.message:j)},onPathsComplete:s=>{As(a=>{const o=new Set(a);return s.forEach(c=>o.delete(c)),o})},scheduleFlush:Ie}),[_,Le,Ie,Me,e]);l.useEffect(()=>(je.current=fe.flush,()=>{je.current=null}),[fe]),l.useEffect(()=>()=>fe.clear(),[fe]),l.useEffect(()=>Ee,[Ee]),l.useEffect(()=>{if(!i)return;if(!r){f(null),p(!1);return}let s=!1,a=null;const o=async()=>{try{const c=await ba(r);if(s)return;f(c.status),c.status==="pending"&&(a=window.setTimeout(()=>{o()},500))}catch{s||f(null)}};return o(),()=>{s=!0,a!==null&&window.clearTimeout(a)}},[i,r]),l.useEffect(()=>{const s=me.current;me.current=v,!(!r||!n)&&(s==="pending"&&v==="ready"&&(p(!0),ce(r,n).finally(()=>{window.setTimeout(()=>{p(!1)},1200)})),v==="failed"&&(B(null),p(!1)))},[r,ce,n,B,v]);const X=nt(w?.bootstrapPendingDirectory??null),Pe=!!(r&&X&&X===nt(r)),ze=!!(r&&(v==="pending"||Pe))||x,Fe=l.useMemo(()=>r?vt.get(r)??null:null,[r]),pe=ga(s=>s.settingsGitmojiEnabled),[Ce,Ge]=l.useState(null),{gitmojis:Ne}=Ea(pe);l.useEffect(()=>{const s=S||F?.projectDirectory;if(!s){Ge(null);return}let a=!1;return fa(s).then(o=>{if(a)return;const c=o.trim();Ge(c&&c!=="HEAD"?c:null)}).catch(()=>{a||Ge(null)}),()=>{a=!0}},[S,F?.projectDirectory]);const[Be,q]=l.useState(Fe?.commitMessage??""),[xe,Se]=l.useState([]),[we,ye]=l.useState(!1),_e=l.useRef(null),[tt,st]=l.useState(null),[Cr,Qt]=l.useState(!1),[Ts,Ds]=l.useState(null),[Je,Nr]=l.useState(25),[Sr,Es]=l.useState(!1),{triggerFireworks:kr}=ja(),Ls=l.useRef(new Map),Pt=l.useRef(0),Xt=l.useCallback(()=>{Pt.current+=1,ge.current&&Es(!0)},[]),Zt=l.useCallback(()=>{Pt.current=Math.max(0,Pt.current-1),ge.current&&Pt.current===0&&Es(!1)},[]),[es,Ft]=l.useState(new Set),[Vr,As]=l.useState(new Set),[ts,Os]=l.useState(!1),[Ir,Pr]=l.useState(0),[Fr,zs]=l.useState(!1),[ss,Gs]=l.useState(Fe?.generatedHighlights??[]),Rr=Vr.size>0||fe.size()>0||fe.isRunning(),_s=l.useCallback(()=>{const s=_e.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),rs=S||F?.projectDirectory||null,ns=g?.current||null,Mr=l.useMemo(()=>{const s=g?.tracking;return s?s.startsWith("origin/"):!0},[g?.tracking]),$s=l.useMemo(()=>{const s=F?.createdFromBranch,a=typeof s=="string"?s.trim():"",o=typeof g?.current=="string"?g.current.trim():"",c=typeof Ce=="string"?Ce.trim():"";return a?a===o&&a.startsWith("opencode/")&&c.length>0&&c!==a?c:a:c||o||"HEAD"},[F?.createdFromBranch,g,Ce]),Rt=l.useCallback(()=>{Gs([])},[]),[as,Br]=l.useState(new Set),[Mt,Tr]=l.useState(new Map),[Bt,is]=l.useState(new Set),os=l.useRef(Mt),Nt=l.useRef(Bt),[Dr,yt]=l.useState(null),[ft,ls]=l.useState(null),[Hs,Ws]=l.useState(""),[Ae,Tt]=l.useState(null),[Er,Us]=l.useState(!1),[Lr,Ks]=l.useState(!1),[cs,ds]=l.useState([]),[Ar,Js]=l.useState(null),[qs,us]=l.useState(null),[Or,Dt]=l.useState([]),[zr,qe]=l.useState(!1),[Gr,Qe]=l.useState([]),[Et,Xe]=l.useState("merge"),[_r,ms]=l.useState(null),[hs,Ys]=l.useState(!1),[gs,$r]=l.useState(100),[Hr,Wr]=l.useState(0),Ye=l.useMemo(()=>m?`openchamber.conflict:${m}`:null,[m]),rt=l.useCallback((s,a,o)=>{if(!Ye||typeof window>"u")return;const c={directory:s,conflictFiles:a,operation:o};window.localStorage.setItem(Ye,JSON.stringify(c))},[Ye]),We=l.useCallback(()=>{!Ye||typeof window>"u"||window.localStorage.removeItem(Ye)},[Ye]);l.useEffect(()=>{if(!Ye||typeof window>"u"||!r)return;const s=window.localStorage.getItem(Ye);if(s)try{const a=JSON.parse(s);if(a.directory!==r){window.localStorage.removeItem(Ye);return}Qe(a.conflictFiles??[]),Xe(a.operation??"merge"),qe(!0)}catch{window.localStorage.removeItem(Ye)}},[Ye,r]);const[Ur,fs]=l.useState(!1),[ps,Qs]=l.useState("merge"),[xs,Xs]=l.useState(""),Kr=l.useCallback(s=>{pa(s).then(a=>{if(a.ok){b.success(e("gitView.toast.commitHashCopied"));return}b.error(e("gitView.toast.copyFailed"))})},[e]),Jr=l.useCallback(s=>{Br(a=>{const o=new Set(a);return o.has(s)?o.delete(s):o.add(s),o})},[]);l.useEffect(()=>{os.current=Mt},[Mt]),l.useEffect(()=>{Nt.current=Bt},[Bt]),l.useEffect(()=>{if(!r||!n)return;const s=Array.from(as).filter(o=>!os.current.has(o)&&!Nt.current.has(o));if(s.length===0)return;let a=!1;return is(o=>{const c=new Set(o);for(const j of s)c.add(j);return Nt.current=c,c}),Promise.all(s.map(o=>n.getCommitFiles(r,o).then(c=>({hash:o,files:c.files})).catch(c=>(console.error("Failed to fetch commit files:",c),{hash:o,files:[]})))).then(o=>{a||(Tr(c=>{const j=new Map(c);for(const{hash:z,files:ne}of o)j.set(z,ne);return os.current=j,j}),is(c=>{const j=new Set(c);for(const{hash:z}of o)j.delete(z);return Nt.current=j,j}))}),()=>{a=!0,is(o=>{let c=!1;const j=new Set(o);for(const z of s)j.delete(z)&&(c=!0);return c?(Nt.current=j,j):o})}},[as,r,n]),l.useEffect(()=>{r&&Si(r,{directory:r,commitMessage:Be,generatedHighlights:ss})},[Be,r,ss]),l.useEffect(()=>{i&&(R(),O(),N())},[i,R,O,N]),l.useEffect(()=>{if(!i)return;if(!r||!n?.getRemoteUrl){ls(null);return}let s=!1;return n.getRemoteUrl(r).then(a=>{s||ls(a)}).catch(()=>{s||ls(null)}),()=>{s=!0}},[i,r,n]);const Lt=l.useCallback(async()=>{if(!r||!n?.getRemotes){ds([]);return}try{const s=await n.getRemotes(r);ge.current&&ds(s)}catch{ge.current&&ds([])}},[r,n]);l.useEffect(()=>{i&&Lt()},[i,Lt]),l.useEffect(()=>{i&&r&&(se(r),oe(r,n))},[i,r,se,oe,n]),l.useEffect(()=>{if(i&&r)return xa.onGitRefreshHint(s=>{nt(s.directory)===nt(r)&&(s.paths?.length&&ae(r,s.paths),h(r,n,{silent:!0}))})},[i,ae,r,h,n]);const re=l.useCallback(async(s=!0)=>{if(r)try{await Promise.all([h(r,n),L(r,n)])}catch(a){if(s){const o=a instanceof Error?a.message:e("gitView.toast.refreshRepositoryFailed");b.error(o)}}},[r,n,h,L,e]),ke=l.useCallback(async()=>{r&&await T(r,n,Je)},[r,n,T,Je]),ws=l.useCallback(async()=>{r&&await M(r,n)},[r,n,M]);l.useEffect(()=>{if(!i||!r||!n?.hasLocalIdentity||P!==!0)return;const s=typeof E=="string"?E.trim():"";if(!s||s==="global"||Ls.current.get(r)===s)return;let o=!1;return(async()=>{try{const j=await n.hasLocalIdentity?.(r);if(o||j===!0)return;Xt(),await n.setGitIdentity(r,s),Ls.current.set(r,s),await ws()}catch(j){console.warn("Failed to auto-apply default git identity:",j)}finally{o||Zt()}})(),()=>{o=!0}},[i,Xt,r,E,Zt,n,P,ws]);const at=l.useMemo(()=>g?[...g.files??[]].sort((a,o)=>a.path.localeCompare(o.path)):[],[g]),Ue=l.useMemo(()=>at.filter(xr),[at]),ys=l.useMemo(()=>at.filter(ki),[at]);l.useEffect(()=>{if(!r||at.length===0)return;const s=[],a=new Set,o=j=>{!j||a.has(j)||(a.add(j),s.push(j))};if(Ue.forEach(j=>o(j.path)),xe.forEach(o),at.slice(0,ji).forEach(j=>o(j.path)),s.length===0)return;const c=window.setTimeout(()=>{$(r,n,s,{maxFiles:vi})},120);return()=>{window.clearTimeout(c)}},[at,r,n,$,Ue,xe]);const Zs=s=>s?.pushed[0]?.remote||g?.tracking?.split("/")[0]||Ke.find(a=>a.name==="origin")?.name||Ke[0]?.name||"origin",er=async(s,a)=>{if(r){st(s);try{const o=c=>{const j=`${c.name}/`,z=g?.tracking?.startsWith(j)?g.tracking.slice(j.length):void 0;return{remote:c.name,branch:z,rebase:!0}};if(s==="fetch"){if(!a)throw new Error("No remote available for fetch");await n.gitFetch(r,{remote:a.name}),b.success(e("gitView.toast.fetchedFromRemote",{name:a.name}))}else if(s==="pull"){if(!a)throw new Error("No remote available for pull");const c=await n.gitPull(r,o(a));b.success(c.files.length===1?e("gitView.toast.pulledFilesSingle",{count:c.files.length,name:a.name}):e("gitView.toast.pulledFilesPlural",{count:c.files.length,name:a.name}))}else if(s==="push"){const c=await n.gitPush(r);b.success(e("gitView.toast.pushedToUpstream",{name:Zs(c)}))}else if(s==="sync"){if(!a)throw new Error("No remote available for sync");let c=0,j=!1;await n.gitFetch(r,{remote:a.name});const z=await n.getGitStatus(r);if((z.behind??0)>0){if((z.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync"));return}c=(await n.gitPull(r,o(a))).files.length}((await n.getGitStatus(r)).ahead??0)>0&&(await n.gitPush(r),j=!0),c>0&&j?b.success(c===1?e("gitView.toast.syncedPulledSingleAndPushed",{count:c,name:a.name}):e("gitView.toast.syncedPulledPluralAndPushed",{count:c,name:a.name})):c>0?b.success(c===1?e("gitView.toast.pulledFilesSingle",{count:c,name:a.name}):e("gitView.toast.pulledFilesPlural",{count:c,name:a.name})):j?b.success(e("gitView.toast.pushedToUpstream",{name:a.name})):b.success(e("gitView.toast.alreadyUpToDate"))}await re(!1),await ke()}catch(o){const c=o instanceof Error?o.message:e("gitView.toast.syncActionFailed",{action:s==="sync"?e("gitView.sync.syncChanges"):s==="pull"?e("gitView.sync.pull"):s});b.error(c)}finally{st(null)}}},qr=l.useCallback(async s=>{if(!r)return;const a=s.name.trim();if(!a){b.error(e("gitView.toast.remoteNameRequired"));return}if(a==="origin"){b.error(e("gitView.toast.cannotRemoveOriginRemote"));return}Js(a);try{await n.removeRemote(r,{remote:a}),b.success(e("gitView.toast.removedRemote",{name:a})),await Promise.all([re(!1),Lt()])}catch(o){const c=o instanceof Error?o.message:`Failed to remove ${a}`;b.error(c)}finally{Js(null)}},[r,n,Lt,re,e]),tr=async(s={})=>{if(!r)return;if(!Be.trim()){b.error(e("gitView.toast.enterCommitMessage"));return}const a=Ue.map(c=>c.path).sort();if(a.length===0){b.error(e("gitView.toast.stageFileToCommit"));return}const o=s.pushAfter?"commitAndPush":"commit";Ds(o);try{if(await n.createGitCommit(r,Be.trim(),{files:a,stageFiles:[]}),_(r),b.success(e("gitView.toast.commitCreated")),q(""),Rt(),await re(),s.pushAfter){const c=g?.tracking?.split("/")[0],j=Ke.find(Vn=>Vn.name===c)??Ke[0];if(!j)throw new Error(e("mobile.changes.noRemote"));st("sync");const z=`${j.name}/`,ne=g?.tracking?.startsWith(z)?g.tracking.slice(z.length):void 0;await n.gitFetch(r,{remote:j.name});const K=await n.getGitStatus(r);if((K.behind??0)>0){if((K.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync")),await re(!1);return}await n.gitPull(r,{remote:j.name,branch:ne,rebase:!0})}const He=await n.getGitStatus(r);let bt;(He.ahead??0)>0&&(bt=await n.gitPush(r)),b.success(e("gitView.toast.pushedToUpstream",{name:Zs(bt)})),kr(),await re(!1)}else await re(!1);await ke(),Pr(c=>c+1)}catch(c){const j=c instanceof Error?c.message:e("gitView.toast.createCommitFailed");b.error(j)}finally{Ds(null),s.pushAfter&&st(null)}},Yr=l.useCallback(async()=>{if(!r)return;const s=Ue.map(a=>a.path).sort();if(s.length===0){b.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:s.length}),zs(!0);try{const{message:a}=await wa(r,s),o=a.subject?.trim()??"",c=Array.isArray(a.highlights)?a.highlights:[];if(o){let j=o;if(pe&&Ne.length>0){const z=Ci(o,Ne);if(z){const{code:ne,emoji:K}=z;!o.startsWith(ne)&&!o.startsWith(K)&&(j=`${ne} ${o}`)}}q(j)}Gs(c),_s()}catch(a){console.error("[git-generation][browser] GitView generate handler failed",{message:a instanceof Error?a.message:String(a),error:a});const o=a instanceof Error?a.message:e("gitView.toast.generateCommitMessageFailed");b.error(o)}finally{zs(!1)}},[r,Ue,pe,Ne,_s,e]),bs=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",Qr=async(s,a)=>{if(!r||!g)return;const o=Cs(U);if(o.length>0){b.error(e("gitView.toast.cannotCreateBranch",{reason:bs(o[0])}));return}const c=g.current??null,j=a?.name??"origin";try{await n.createBranch(r,s,c??"HEAD"),b.success(e("gitView.toast.createdBranch",{name:s})),await n.checkoutBranch(r,s);let z=!1;try{await n.gitPush(r,{remote:j,branch:s,options:["--set-upstream"]}),z=!0}catch(ne){const K=ne instanceof Error?ne.message:`Unable to push new branch to ${j}.`;b.warning(e("gitView.toast.branchCreatedLocally"),{description:t.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",K]})})}await re(),await ke(),z&&b.success(e("gitView.toast.upstreamSet",{branch:s,remote:j}))}catch(z){const ne=z instanceof Error?z.message:e("gitView.toast.createBranchFailed");throw b.error(ne),z}},Xr=async(s,a)=>{if(!r)return;const o=Cs(U);if(o.length>0){b.error(e("gitView.toast.cannotRenameBranch",{reason:bs(o[0])}));return}try{await n.renameBranch(r,s,a),b.success(e("gitView.toast.renamedBranch",{oldName:s,newName:a})),await re(),await ke()}catch(c){const j=c instanceof Error?c.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:a});b.error(j)}},Zr=async s=>{if(!r)return;const a=Cs(U);if(a.length>0){b.error(e("gitView.toast.cannotCheckout",{reason:bs(a[0])}));return}const o=s.replace(/^remotes\//,"");if(g?.current!==o)try{await n.checkoutBranch(r,o),b.success(e("gitView.toast.checkedOut",{name:o})),await re(),await ke()}catch(c){const j=c instanceof Error?c.message:e("gitView.toast.checkoutFailed",{name:o});b.error(j)}},en=async s=>{if(r){Xt();try{await n.setGitIdentity(r,s.id),b.success(e("gitView.toast.appliedIdentity",{name:s.name})),await ws()}catch(a){const o=a instanceof Error?a.message:e("gitView.toast.applyIdentityFailed");b.error(o)}finally{Zt()}}},St=l.useMemo(()=>J?.all?J.all.filter(s=>!s.startsWith("remotes/")).sort():[],[J]),it=l.useMemo(()=>J?.all?J.all.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],[J]),Ke=l.useMemo(()=>{if(cs.length>0)return cs;const s=new Set,a=g?.tracking?.trim();a&&a.includes("/")&&s.add(a.split("/")[0]);for(const o of it){const c=o.indexOf("/");c>0&&s.add(o.slice(0,c))}return s.size===0&&ft&&s.add("origin"),Array.from(s).map(o=>({name:o,fetchUrl:ft??"",pushUrl:ft??""}))},[cs,it,ft,g?.tracking]),ot=g?.current??null,sr=l.useMemo(()=>{const s=g?.tracking?.trim().split("/")[0];return(s&&J?.defaultBranches?.[s])??J?.defaultBranches?.origin},[J,g?.tracking]),pt=l.useMemo(()=>Ca({remoteNames:new Set(Ke.map(s=>s.name)),localBranches:St,worktreeCreatedFromBranch:F?.createdFromBranch,rootBranchHint:Ce,defaultBranch:sr,headBranch:ot}),[ot,sr,Ke,St,Ce,F?.createdFromBranch]),tn=l.useMemo(()=>Ke.map(o=>o.name).map(o=>`${o}/${pt}`).find(o=>it.includes(o))??pt,[pt,Ke,it]),sn=l.useMemo(()=>{const s=new Map;d&&s.set(d.id,d);let a=null;if(ft)try{let o=ft.trim();o.startsWith("git@")&&(o=`https://${o.slice(4).replace(":","/")}`),o.endsWith(".git")&&(o=o.slice(0,-4));const c=new URL(o);a=c.hostname+c.pathname}catch{}for(const o of I){if(o.authType!=="token"){s.set(o.id,o);continue}const c=o.host;if(!c){s.set(o.id,o);continue}if(!c.includes("/")){s.set(o.id,o);continue}a&&a===c&&s.set(o.id,o)}return Array.from(s.values())},[I,d,ft]),rn=l.useMemo(()=>{if(G?.userName&&G?.userEmail){const s=I.find(a=>a.userName===G.userName&&a.userEmail===G.userEmail);return s||(d&&d.userName===G.userName&&d.userEmail===G.userEmail?d:{id:"local-config",name:G.userName,userName:G.userName,userEmail:G.userEmail,sshKey:G.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return d??null},[G,I,d]),nn=Ue.length,an=Z||tt!==null||Ts!==null,on=!!(F&&rs&&ns&&Mr),rr=!!ot,lt=on&&rs&&ns&&F?{repoRoot:rs,sourceBranch:ns,worktreeMetadata:F}:null;l.useEffect(()=>{if(!r||!n||!H?.all?.length||!ot||!pt||ot===pt){yt(null);return}let s=!1;return(async()=>{try{const o=await n.getGitLog(r,{from:pt,to:"HEAD",maxCount:Je});if(s)return;const c=new Set((o?.all??[]).map(z=>z.hash).filter(z=>typeof z=="string"&&z.length>0));if(c.size===0){yt(null);return}const j=H.all.findIndex(z=>!c.has(z.hash));if(j===0){yt(null);return}if(j===-1){yt({insertBeforeIndex:H.all.length,branchName:ot,direction:"up"});return}yt({insertBeforeIndex:j,branchName:ot,direction:"up"})}catch{s||yt(null)}})(),()=>{s=!0}},[pt,ot,r,n,H,Je]),l.useEffect(()=>{ms(null)},[r]),l.useEffect(()=>{if(Ae!=="graph"||!r){Ae!=="graph"&&ms(null);return}let s=!1;return Ys(!0),n.getGitLog(r,{maxCount:gs,all:!0}).then(a=>{s||ms(a)}).catch(a=>{console.error("Failed to fetch graph log:",a)}).finally(()=>{s||Ys(!1)}),()=>{s=!0}},[Ae,r,gs,Hr,n]);const kt=l.useCallback((s,a)=>{if(!r||s.length===0)return;const o=Array.from(new Set(s));As(j=>{const z=new Set(j);return o.forEach(ne=>z.add(ne)),z});const c=ie(r,o,a);fe.enqueue({directory:r,direction:a,paths:new Set(o),rollback:()=>ee(r,c)}),Ie()},[r,fe,ie,ee,Ie]),vs=l.useCallback(async s=>{if(r){Ft(a=>{const o=new Set(a);return o.add(s),o});try{await n.revertGitFile(r,s,{scope:"working"}),b.success(e("gitView.toast.revertedFile",{path:s})),await re(!1)}catch(a){const o=a instanceof Error?a.message:e("gitView.toast.revertFailed");b.error(o)}finally{Ft(a=>{const o=new Set(a);return o.delete(s),o})}}},[r,re,n,e]),At=l.useCallback(async(s,a,o="all")=>{if(!r||s.length===0)return;const c=Array.from(new Set(s));if(ts||c.some(K=>es.has(K)))return;const j=new Set(Ue.map(K=>K.path)),z=o==="all"&&c.some(K=>j.has(K));a&&Os(!0),Ft(K=>{const He=new Set(K);return c.forEach(bt=>He.add(bt)),He});const ne=[];try{if(await Promise.all(c.map(async K=>{try{await n.revertGitFile(r,K,{scope:o})}catch(He){ne.push({path:K,message:He instanceof Error?He.message:e("gitView.toast.revertFailed")})}})),z&&ne.length<c.length&&_(r),await re(!1),ne.length===0)b.success(c.length===1?e("gitView.toast.revertedFilesSingle",{count:c.length}):e("gitView.toast.revertedFilesPlural",{count:c.length}));else if(ne.length===c.length)b.error(ne[0]?.message||e("gitView.toast.revertFailed"));else{const K=c.length-ne.length;b.warning(K===1?e("gitView.toast.revertedSomeSingle",{success:K,failed:ne.length}):e("gitView.toast.revertedSomePlural",{success:K,failed:ne.length}))}}finally{Ft(K=>{const He=new Set(K);return c.forEach(bt=>He.delete(bt)),He}),a&&Os(!1)}},[_,r,n,ts,re,es,Ue,e]),ln=l.useCallback(async s=>{await At(s,!0)},[At]),cn=l.useCallback(async s=>{await At(s,!1,"working")},[At]),js=l.useCallback((s,a)=>{if(r&&!be){te(r,s,a);return}he(s,a)},[r,be,he,te]),dn=l.useCallback(()=>Qt(!0),[]),un=l.useMemo(()=>{const s=[];return Ue.length>0&&s.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:Ue,actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:a=>e("gitView.changes.unstageFileAria",{path:a}),onActionFile:a=>{kt([a],"unstage")},onActionAll:a=>{kt(a,"unstage")},onViewDiff:a=>js(a,!0),onRevertFile:vs,showRevertActions:!1,accent:!0}),ys.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:ys,actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:a=>e("gitView.changes.stageFileAria",{path:a}),onActionFile:a=>{kt([a],"stage")},onActionAll:a=>{kt(a,"stage")},onViewDiff:a=>js(a,!1),onRevertFile:vs}),s},[vs,js,kt,Ue,e,ys]),mn=l.useCallback(s=>{if(s.length===0)return;const a=s.map(o=>o.trim()).filter(Boolean);if(a.length===0){Rt();return}q(o=>{const c=o.trim(),j=c.length>0?`
|
|
4
4
|
|