@openchamber/web 1.23.1 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-DL0imnlI.js → CodeMirrorCommentWidgets-C9kV-n7r.js} +1 -1
- package/dist/assets/DiffView-B7YkbY-u.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +1 -0
- package/dist/assets/FilesView-vjJx7VaM.js +13 -0
- package/dist/assets/GitView-BLhlMYEY.js +6 -0
- package/dist/assets/GuestAttachDialog-B-fwE8r3.js +3 -0
- package/dist/assets/{JsonTreeView-BPBDPY9B.js → JsonTreeView-D_4G5X6-.js} +1 -1
- package/dist/assets/LinearIssuesView-1uKhePfH.js +1 -0
- package/dist/assets/{MarkdownImageGallery-BNjimjiI.js → MarkdownImageGallery-Ix7N_2wp.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-Deel_y5S.js +12 -0
- package/dist/assets/{OnboardingScreen-CWXxIIAH.js → OnboardingScreen-ToIakxb_.js} +1 -1
- package/dist/assets/{PatchDiff-B6J3p3br.js → PatchDiff-BjMgezr1.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BjTRJJ1D.js → PierreDiffViewer-53Ghfnlr.js} +5 -5
- package/dist/assets/PlanView-BGAzxDwD.js +5 -0
- package/dist/assets/SettingsView-n2X-jfBB.js +29 -0
- package/dist/assets/SettingsWindow-Bi8LE9XI.js +1 -0
- package/dist/assets/SubmoduleDiffSummary--YFqK6Ih.js +1 -0
- package/dist/assets/ToolOutputDialog-DRWBvdaJ.js +15 -0
- package/dist/assets/{ToolPartDiffPreview-DRifZ2YH.js → ToolPartDiffPreview-BxZJCU28.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BOeQtAWV.js → VirtualizedFileDiff-DCXjBGRf.js} +3 -3
- package/dist/assets/{WalkthroughView-BD4p0vhD.js → WalkthroughView-CfIPvWWa.js} +2 -2
- package/dist/assets/appThemeRegistry-DDROzcUO.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-FZI1j1rE.js → computeVirtualFileMetrics-DHgQIkUq.js} +1 -1
- package/dist/assets/de-CX_f-T5U.js +10 -0
- package/dist/assets/es-BERmWNn_.js +16 -0
- package/dist/assets/fr-BjYYE_-z.js +14 -0
- package/dist/assets/index-DpzTz2UH.css +1 -0
- package/dist/assets/index-Dy8xgawx.js +40 -0
- package/dist/assets/{index-DddhnFNK.js → index-WjufPkIV.js} +1 -1
- package/dist/assets/{isDiffPlainText-D4ld2G-2.js → isDiffPlainText-D9faP70y.js} +1 -1
- package/dist/assets/{isFilePlainText-BW1Xfw0F.js → isFilePlainText-6qOcz5Ky.js} +1 -1
- package/dist/assets/ja-DxqeAk9N.js +16 -0
- package/dist/assets/ko-Dty1aUod.js +16 -0
- package/dist/assets/main-BOYSXfYn.js +896 -0
- package/dist/assets/{main-BBqRX3Po.js → main-Bjcre_GE.js} +2 -2
- package/dist/assets/{markdown-shiki.worker-D5fBU-lw.js → markdown-shiki.worker-CahLvHIq.js} +5 -5
- package/dist/assets/markdownCore-DPrwM1rU.js +5 -0
- package/dist/assets/{miniChat-CygpKLC_.js → miniChat-Dz_bPgMc.js} +2 -2
- package/dist/assets/{mobile-CSmUm4vb.js → mobile-BbZPBJrK.js} +2 -2
- package/dist/assets/{patchFileDiff-u4JuidC_.js → patchFileDiff-BvU6KOQC.js} +3 -3
- package/dist/assets/pl-CX-_ROkr.js +16 -0
- package/dist/assets/pt-BR-DhRR1arx.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +2 -0
- package/dist/assets/renderMobileApp-BK1kFlcJ.js +25 -0
- package/dist/assets/runtimeEndpointReset-BULHvOwb.js +25 -0
- package/dist/assets/{scheduledTasksApi-Og3jfb4K.js → scheduledTasksApi-DW3xqMQ8.js} +1 -1
- package/dist/assets/shikiHighlight-DsxD9QEa.js +1 -0
- package/dist/assets/textMateThemeFromAppTheme-Da7ed8qM.js +1 -0
- package/dist/assets/tr-cIQtYBpg.js +7 -0
- package/dist/assets/uk-CD21CXFV.js +16 -0
- package/dist/assets/useAppFontEffects-hfv2s6mZ.js +7333 -0
- package/dist/assets/useInlineCommentController-BmtfVbo8.js +2 -0
- package/dist/assets/useRootScrollLock-Cwc4kSl2.js +1 -0
- package/dist/assets/{vendor-base-ui-BY_5qla_.js → vendor-base-ui-CsXYnR5c.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-D5hG1bL9.js → vendor-codemirror-language-data-BPMJpOpT.js} +2 -2
- package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +1 -0
- package/dist/assets/{vendor-motion-dom-D_o3BTI3.js → vendor-motion-dom-DcCgeG69.js} +1 -1
- package/dist/assets/{vendor-remixicon-react-Dil0zKKT.js → vendor-remixicon-react-BDmGmFCA.js} +1 -1
- package/dist/assets/vendor-strip-json-comments-5dJlOkP1.js +4 -0
- package/dist/assets/{vendor-zod-B6551dwG.js → vendor-zod-fZppILAM.js} +4 -4
- package/dist/assets/{web-components-DCyJti1c.js → web-components-U-hWbgJo.js} +2 -2
- package/dist/assets/zh-CN-BWvlPHY-.js +16 -0
- package/dist/assets/zh-TW-CRp5dJU2.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +8 -6
- package/server/built-in-extensions/registry.json +4 -0
- package/server/index.d.ts +2 -0
- package/server/index.js +15 -3
- package/server/lib/fs/DOCUMENTATION.md +8 -0
- package/server/lib/fs/git-process.test.js +77 -0
- package/server/lib/fs/routes.js +2 -1
- package/server/lib/fs/search.js +2 -1
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/routes.js +16 -3
- package/server/lib/git/service.js +112 -8
- package/server/lib/git/service.test.js +127 -0
- package/server/lib/guests/DOCUMENTATION.md +66 -0
- package/server/lib/guests/auth-store.js +184 -0
- package/server/lib/guests/auth-store.test.js +112 -0
- package/server/lib/guests/builtins.js +34 -0
- package/server/lib/guests/builtins.test.js +174 -0
- package/server/lib/guests/catalog.js +466 -0
- package/server/lib/guests/catalog.test.js +390 -0
- package/server/lib/guests/clone.js +297 -0
- package/server/lib/guests/extract-zip.js +136 -0
- package/server/lib/guests/extract-zip.test.js +109 -0
- package/server/lib/guests/files.js +308 -0
- package/server/lib/guests/files.test.js +262 -0
- package/server/lib/guests/grant-scope.js +81 -0
- package/server/lib/guests/grant-scope.test.js +75 -0
- package/server/lib/guests/host-session.js +73 -0
- package/server/lib/guests/host-session.test.js +30 -0
- package/server/lib/guests/html-styles.js +6 -0
- package/server/lib/guests/html-styles.test.js +45 -0
- package/server/lib/guests/html-tokens.js +73 -0
- package/server/lib/guests/html-tokens.test.js +53 -0
- package/server/lib/guests/install.js +406 -0
- package/server/lib/guests/install.test.js +338 -0
- package/server/lib/guests/oauth.js +501 -0
- package/server/lib/guests/oauth.test.js +481 -0
- package/server/lib/guests/persist.js +336 -0
- package/server/lib/guests/persist.test.js +288 -0
- package/server/lib/guests/request.js +112 -0
- package/server/lib/guests/request.test.js +206 -0
- package/server/lib/guests/routes.js +838 -0
- package/server/lib/guests/service.js +538 -0
- package/server/lib/guests/service.test.js +277 -0
- package/server/lib/guests/sockets.js +129 -0
- package/server/lib/guests/sockets.test.js +110 -0
- package/server/lib/guests/ssh-install.test.js +188 -0
- package/server/lib/guests/storage.js +68 -0
- package/server/lib/guests/storage.test.js +59 -0
- package/server/lib/guests/updates.js +294 -0
- package/server/lib/guests/updates.test.js +334 -0
- package/server/lib/guests/upload.js +50 -0
- package/server/lib/guests/upload.test.js +131 -0
- package/server/lib/linear/DOCUMENTATION.md +1 -1
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -0
- package/server/lib/openchamber-sessions/routes.js +44 -11
- package/server/lib/openchamber-sessions/routes.test.js +47 -0
- package/server/lib/opencode/DOCUMENTATION.md +54 -0
- package/server/lib/opencode/core-routes.js +39 -1
- package/server/lib/opencode/feature-routes-runtime.js +10 -0
- package/server/lib/opencode/lifecycle-process.test.js +84 -0
- package/server/lib/opencode/lifecycle.js +54 -67
- package/server/lib/opencode/openchamber-routes.js +72 -14
- package/server/lib/opencode/openchamber-routes.test.js +71 -3
- package/server/lib/opencode/settings-helpers.js +5 -0
- package/server/lib/opencode/settings-helpers.test.js +13 -1
- package/server/lib/opencode/settings-normalization-runtime.js +2 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +13 -0
- package/server/lib/opencode/settings-registry.json +7 -0
- package/server/lib/opencode/shutdown-runtime.js +3 -0
- package/server/lib/opencode/shutdown-runtime.test.js +24 -0
- package/server/lib/opencode/theme-archive.js +53 -0
- package/server/lib/opencode/theme-catalog.js +171 -0
- package/server/lib/opencode/theme-catalog.test.js +125 -0
- package/server/lib/opencode/theme-import.test.js +144 -0
- package/server/lib/opencode/theme-runtime.js +100 -28
- package/server/lib/opencode/theme-runtime.test.js +15 -0
- package/server/lib/quota/DOCUMENTATION.md +0 -1
- package/server/lib/quota/providers/index.js +0 -7
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +17 -2
- package/server/lib/terminal/runtime.test.js +45 -0
- package/server/lib/ui-auth/ui-auth.js +43 -8
- package/server/lib/ui-auth/ui-auth.test.js +40 -0
- package/dist/assets/DiffView-q6z6MFdZ.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-to6K1rXL.js +0 -1
- package/dist/assets/FilesView-uwvKGOeu.js +0 -13
- package/dist/assets/GitView-CAqrkFYg.js +0 -6
- package/dist/assets/LinearIssuesView-Dq4Nz_DL.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BIYG3j5A.js +0 -12
- package/dist/assets/PlanView-Cs7Aa22g.js +0 -5
- package/dist/assets/SettingsView-DROvkdyX.js +0 -28
- package/dist/assets/SettingsWindow-AtPQGcRJ.js +0 -1
- package/dist/assets/ToolOutputDialog-DmAZDzlT.js +0 -15
- package/dist/assets/appThemeRegistry-BK0dHKa6.js +0 -1
- package/dist/assets/de-Byg3syd1.js +0 -10
- package/dist/assets/es-B-FGkjnQ.js +0 -16
- package/dist/assets/fr-Dvzik_Jj.js +0 -14
- package/dist/assets/index-zhgg-SDz.css +0 -1
- package/dist/assets/index-zzfsbdBe.js +0 -40
- package/dist/assets/ja-CFnftYdc.js +0 -16
- package/dist/assets/ko-CgZ13aWV.js +0 -16
- package/dist/assets/main-BX3ip8Oc.js +0 -930
- package/dist/assets/markdownCore-TRGNObm0.js +0 -5
- package/dist/assets/pl-BDk6AWIE.js +0 -16
- package/dist/assets/pt-BR-DV5hPNsk.js +0 -16
- package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-Bfh77YcY.js +0 -2
- package/dist/assets/renderMobileApp-DsYwHQBL.js +0 -25
- package/dist/assets/runtimeEndpointReset-MtnTGkZz.js +0 -41
- package/dist/assets/shikiHighlight-CVE7qsu3.js +0 -1
- package/dist/assets/tr-BwS5J324.js +0 -7
- package/dist/assets/uk-Dp60Q7VN.js +0 -16
- package/dist/assets/useAppFontEffects-DQXEYu1N.js +0 -7282
- package/dist/assets/useGitComparison-DjFXbxbu.js +0 -1
- package/dist/assets/useInlineCommentController-B4Vhtx-T.js +0 -2
- package/dist/assets/useRootScrollLock-B32nj08w.js +0 -1
- package/dist/assets/vendor-framer-motion-livSKyyV.js +0 -1
- package/dist/assets/zh-CN-D1MXOnJ7.js +0 -16
- package/dist/assets/zh-TW-MqRc5ECP.js +0 -16
- package/server/lib/quota/providers/crof.js +0 -96
- package/server/lib/quota/providers/crof.test.js +0 -98
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{R as l,r as ve,j as t,f as Ct}from"./vendor-react-BUCujlKS.js";import{f as nt,z as rt,a4 as Dt,kd as _n,dr as Yt,cF as Qt,t as b,I as T,ap as Ts,aq as Ls,ar as Fr,as as Os,d1 as As,d2 as zs,d3 as Gs,d4 as _s,cY as Zt,cZ as Xt,B as W,ke as $n,kf as Hn,b_ as mt,b$ as ht,c0 as gt,c1 as ft,c2 as bt,W as gr,aa as es,ab as ts,ac as ss,kg as Wn,h as Se,kh as Un,ki as Kn,kj as qn,kk as Jn,bd as Yn,av as Qn,ca as Zn,kl as Xn,km as ea,kn as ta,ko as sa,kp as ra,kq as na,kr as aa,c4 as Rr,cf as ia,cg as oa,ch as la,ci as ca,cj as da,cn as ua,cd as ma,cc as ha,ks as ga,cm as fa,c3 as Es,fq as pa,Z as xa,af as wa,ag as ya,J as ba,ah as va,bI as ja,kt as Ca,ai as Na,ku as Sa,kv as ka,aj as Va,kw as Ia,K as Pa,c8 as Fa,jn as Ra,kx as Ba,l as Da,co as Ma,g as Ea,d6 as Ta,ao as fr,a5 as La,ky as Oa,kz as Bs}from"./useAppFontEffects-hfv2s6mZ.js";import{a as Aa,b as za}from"./main-BOYSXfYn.js";import{ab as Ga,Q as _a,i as $a,ah as Ha}from"./runtimeEndpointReset-BULHvOwb.js";import{u as pr}from"./vendor-zustand-BAGL70zf.js";import{h as Wa,u as Rt}from"./index-Dy8xgawx.js";import{C as Ua,a as Ka,D as qa}from"./DirtyBranchSwitchDialog-CU0A93Zx.js";import{P as Ja}from"./PierreDiffViewer-53Ghfnlr.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-fZppILAM.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-base-ui-CsXYnR5c.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.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-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./contextPanelEmbeddedChat-CirXEPJq.js";import"./vendor-sonner-DFyL3AvE.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-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.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-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BPMJpOpT.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./useRootScrollLock-Cwc4kSl2.js";import"./scheduledTasksApi-DW3xqMQ8.js";import"./GuestAttachDialog-B-fwE8r3.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./web-components-U-hWbgJo.js";import"./computeVirtualFileMetrics-DHgQIkUq.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-DCXjBGRf.js";import"./isDiffPlainText-D9faP70y.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-BmtfVbo8.js";import"./appThemeRegistry-DDROzcUO.js";import"./textMateThemeFromAppTheme-Da7ed8qM.js";const Br="gitmojiCache",Ya=1e3*60*60*24*7,Dr="1",Qa="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Mr=o=>{if(!o||typeof o!="object")return!1;const e=o;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Ds=()=>{if(typeof window>"u")return null;try{const o=window.localStorage.getItem(Br);if(!o)return null;const e=JSON.parse(o);return!e||e.version!==Dr||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Mr),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Za=o=>{if(!(typeof window>"u"))try{const e={gitmojis:o,fetchedAt:Date.now(),version:Dr};window.localStorage.setItem(Br,JSON.stringify(e))}catch{return}},xr=o=>Date.now()-o.fetchedAt<Ya;let qt=null;const Bt=new Set,wr=async()=>{if(qt)return qt;const o=(async()=>{try{const e=await fetch(Qa);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const a=await e.json(),m=Array.isArray(a.gitmojis)?a.gitmojis.filter(Mr):[];return Za(m),Bt.forEach(N=>N(m)),m}catch(e){console.warn("Failed to load gitmoji list:",e);const a=[];return Bt.forEach(m=>m(a)),a}finally{qt=null}})();return qt=o,o},Xa=o=>{const[e,a]=l.useState(()=>o?Ds()?.gitmojis??[]:[]),[m,N]=l.useState(!1),f=l.useRef(o);f.current=o,l.useEffect(()=>{if(!o){Bt.delete(a),a([]),N(!1);return}const x=Ds();if(x&&(a(x.gitmojis),xr(x)))return;Bt.add(a),N(!0);let g=!1;return wr().finally(()=>{!g&&f.current&&N(!1)}),()=>{g=!0,Bt.delete(a)}},[o]);const p=l.useCallback(async()=>{if(!f.current)return[];if(e.length>0)return e;const x=Ds();return x&&xr(x)?x.gitmojis:wr()},[e]);return{gitmojis:e,isLoading:m,ensureLoaded:p}},Nt=async(o,e)=>{const a=await Wa(`/api/git/integrate/${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!a.ok){const m=await a.json().catch(()=>null);throw new Error(m?.error||`Git integrate request failed: ${a.statusText}`)}return a.json()};async function Ft(o){return Nt("plan",o)}async function ei(o){return Nt("conflict-details",{tempWorktreePath:o})}async function ti(o){return(await Nt("cherry-pick-status",{tempWorktreePath:o})).inProgress}async function si(o){return Nt("run",{plan:o})}async function ri(o){await Nt("abort",{state:o})}async function ni(o){return Nt("continue",{state:o})}const ai=({repoRoot:o,sourceBranch:e,worktreeMetadata:a,localBranches:m,defaultTargetBranch:N,refreshKey:f,onRefresh:p,showHeader:x=!0})=>{const{t:g}=nt(),w=rt(h=>h.currentSessionId),[M,v]=ve.useState(!1),[V,L]=ve.useState(""),S=ve.useRef(null),z=ve.useMemo(()=>Dt(m,V,h=>[h]),[m,V]),[C,y]=ve.useState(N);ve.useEffect(()=>{y(N)},[N]),ve.useEffect(()=>{if(M){const h=setTimeout(()=>{S.current?.focus()},0);return()=>clearTimeout(h)}},[M]);const D=!!(o&&e&&C&&C!=="HEAD"&&e!==C),[k,R]=ve.useState({kind:"idle"}),[P,F]=ve.useState(!1),[r,Y]=ve.useState([]),B=ve.useMemo(()=>w?`openchamber.integrate.conflict:${w}`:null,[w]);ve.useEffect(()=>{if(!B||typeof window>"u")return;const h=window.localStorage.getItem(B);if(!h)return;let d=!1;try{const I=JSON.parse(h);if(!I?.tempWorktreePath||I.repoRoot!==o){window.localStorage.removeItem(B);return}(async()=>{const O=await ti(I.tempWorktreePath).catch(()=>!1);if(d)return;if(!O){window.localStorage.removeItem(B);return}const J=await ei(I.tempWorktreePath).catch(()=>null);d||J&&R({kind:"conflict",state:I,details:J})})()}catch{window.localStorage.removeItem(B)}return()=>{d=!0}},[B,o]),ve.useEffect(()=>{if(!D){R({kind:"idle"});return}let h=!1;return R({kind:"loading"}),(async()=>{try{const d=await Ft({repoRoot:o,sourceBranch:e,targetBranch:C});if(h)return;if(R({kind:"ready",plan:d}),d.commits.length>0){const O=d.commits.slice(-50).reverse(),J=await _n(o,O);h||(Y(J),F(!1))}else h||(Y([]),F(!1))}catch{h||R({kind:"idle"})}})(),()=>{h=!0}},[D,o,e,C,f]);const u=ve.useCallback(h=>{w&&rt.getState().setWorktreeMetadata(w,{...a,createdFromBranch:h})},[w,a]),E=rt(h=>h.openNewSessionDraft),se=ve.useCallback(async h=>{const d=await Yt("git.integrate.cherrypick.resolve.visible",{current_commit:h.state.currentCommit,target_branch:h.state.targetBranch}),I=await Yt("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}),O=`Cherry-pick conflict context (JSON)
|
|
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:d,instructionsText:I,payloadText:O}},[]),U=Qt(h=>h.setPendingInputText),G=Qt(h=>h.setPendingSyntheticParts),$=ve.useCallback(async(h,d)=>{const I=await se(h);if(d){E({directoryOverride:h.state.tempWorktreePath,initialPrompt:I.visibleText,syntheticParts:[{text:I.instructionsText,synthetic:!0},{text:I.payloadText,synthetic:!0}]});return}if(!w){b.error(g("gitView.integrate.noActiveSession"),{description:g("gitView.integrate.noActiveSessionDescription")});return}U(I.visibleText,"replace"),G([{text:I.instructionsText,synthetic:!0},{text:I.payloadText,synthetic:!0}])},[w,se,E,U,G,g]),Z=ve.useCallback(async()=>{if(k.kind==="ready"){if(k.plan.commits.length===0){b.message(g("gitView.integrate.noCommitsToMoveToast"));return}R({kind:"running",plan:k.plan});try{const h=await si(k.plan);if(h.kind==="success"){b.success(g("gitView.integrate.commitsMovedToast"),{description:h.moved===1?g("gitView.integrate.commitsMovedDescriptionSingle",{count:h.moved,branch:k.plan.targetBranch}):g("gitView.integrate.commitsMovedDescriptionPlural",{count:h.moved,branch:k.plan.targetBranch})});const d=await Ft(k.plan);R({kind:"ready",plan:d}),p?.();return}h.kind==="conflict"&&(b.error(g("gitView.integrate.cherryPickConflictToast"),{description:g("gitView.integrate.cherryPickConflictDescription")}),R({kind:"conflict",state:h.state,details:h.details}),B&&typeof window<"u"&&window.localStorage.setItem(B,JSON.stringify(h.state)))}catch(h){const d=h instanceof Error?h.message:String(h);b.error(g("gitView.integrate.failedToMoveToast"),{description:d});const I=await Ft({repoRoot:o,sourceBranch:e,targetBranch:C}).catch(()=>null);R(I?{kind:"ready",plan:I}:{kind:"idle"})}}},[k,p,o,e,C,B,g]),H=ve.useCallback(async()=>{if(k.kind==="conflict")try{await ri(k.state),b.message(g("gitView.integrate.cherryPickAbortedToast")),B&&typeof window<"u"&&window.localStorage.removeItem(B)}finally{const h=await Ft({repoRoot:o,sourceBranch:e,targetBranch:C}).catch(()=>null);R(h?{kind:"ready",plan:h}:{kind:"idle"})}},[k,o,e,C,B,g]),le=ve.useCallback(async()=>{if(k.kind==="conflict")try{const h=await ni(k.state);if(h.kind==="success"){b.success(g("gitView.integrate.cherryPickFinishedToast"));const d=await Ft({repoRoot:o,sourceBranch:e,targetBranch:C}).catch(()=>null);R(d?{kind:"ready",plan:d}:{kind:"idle"}),B&&typeof window<"u"&&window.localStorage.removeItem(B),p?.();return}h.kind==="conflict"&&(R({kind:"conflict",state:h.state,details:h.details}),B&&typeof window<"u"&&window.localStorage.setItem(B,JSON.stringify(h.state)))}catch(h){const d=h instanceof Error?h.message:String(h);b.error(g("gitView.integrate.cherryPickContinueFailedToast"),{description:d})}},[k,o,e,C,p,B,g]);return!o||!e?null:t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[x?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(T,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:g("gitView.integrate.title")}),k.kind==="ready"&&k.plan.commits.length>0?t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:g("gitView.integrate.toMoveCount",{count:k.plan.commits.length})}):null]}),t.jsx("div",{className:"flex items-center gap-2",children:k.kind==="loading"||k.kind==="running"?t.jsx(T,{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:g("gitView.integrate.moveCommits")}),t.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",C]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs(Ts,{open:M,onOpenChange:v,children:[t.jsx(Ls,{asChild:!0,children:t.jsxs("button",{type:"button",className:Fr({size:"default"}),children:[g("gitView.integrate.target"),t.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:C}),t.jsx(T,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),t.jsx(Os,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:t.jsxs(As,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(zs,{ref:S,placeholder:g("gitView.branch.searchPlaceholder"),value:V,onValueChange:L,onKeyDown:h=>h.stopPropagation()}),t.jsxs(Gs,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(_s,{children:g("gitView.branch.empty")}),t.jsx(Zt,{heading:g("gitView.branch.localBranches"),children:z.map(h=>t.jsx(Xt,{value:h,onSelect:()=>{y(h),u(h),v(!1),L("")},children:h},h))})]})]})})]}),k.kind==="ready"?t.jsx(W,{size:"sm",onClick:()=>{Z()},disabled:!D||k.plan.commits.length===0,children:g("gitView.integrate.move")}):k.kind==="loading"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:g("gitView.integrate.checking")}):k.kind==="running"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:g("gitView.integrate.moving")}):null]}),k.kind==="ready"&&k.plan.commits.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:g("gitView.integrate.noCommitsToMove")}),k.kind==="ready"&&k.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:[g("gitView.integrate.commitsToMove"),t.jsxs("span",{className:"text-muted-foreground",children:[" (",k.plan.commits.length,")"]})]}),r.length>0&&k.plan.commits.length>5&&t.jsx("button",{type:"button",onClick:()=>F(h=>!h),className:"typography-micro text-muted-foreground hover:text-foreground",children:g(P?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(P?r:r.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)),r.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:g("gitView.integrate.previewUnavailable")}),k.plan.commits.length>r.length&&t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:g("gitView.integrate.showingFirstCommits",{count:r.length})})]})]}),k.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:g("gitView.integrate.conflictsInFiles",{count:k.details.unmergedFiles.length})}),t.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[g("gitView.integrate.currentCommit"),": ",t.jsx("span",{className:"font-mono",children:k.state.currentCommit.slice(0,7)})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[k.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)),k.details.unmergedFiles.length>6&&t.jsx("span",{className:"text-xs text-muted-foreground",children:g("gitView.integrate.moreFiles",{count:k.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:()=>{H()},children:g("gitView.operation.abort")}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!w,onClick:()=>{$({state:k.state,details:k.details},!1)},children:[t.jsx(T,{name:"sparkling",className:"size-3.5"}),g("gitView.integrate.currentSession")]}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{$({state:k.state,details:k.details},!0)},children:[t.jsx(T,{name:"sparkling",className:"size-3.5"}),g("gitView.integrate.newSession")]}),t.jsx(W,{size:"sm",className:"typography-meta",onClick:()=>{le()},children:g("gitView.operation.continue")})]})]})]})]})},ii=({open:o,onOpenChange:e,directory:a,hasUncommittedChanges:m,hasStagedChanges:N=!1,uncommittedFileCount:f,onChanged:p})=>{const{t:x}=nt(),[g,w]=l.useState([]),[M,v]=l.useState(!1),[V,L]=l.useState(""),[S,z]=l.useState(""),[C,y]=l.useState(null),[D,k]=l.useState({}),R=l.useCallback(async()=>{if(a){v(!0);try{const u=await $n(a);w(u.stashes),k({})}catch(u){b.error(u instanceof Error?u.message:x("gitView.stashes.toast.loadFailed"))}finally{v(!1)}}},[a,x]);l.useEffect(()=>{o&&R()},[R,o]),l.useEffect(()=>{if(!o||!a||g.length===0)return;let u=!1;const E=g.map(se=>se.ref);return Hn(a,E).then(se=>{u||k(se.counts)}).catch(()=>{}),()=>{u=!0}},[a,o,g]);const P=l.useMemo(()=>Dt(g,V,u=>[u.message,u.ref,u.relativeTime]),[V,g]),F=l.useCallback(async u=>{await R(),await p?.(u)},[R,p]),r=async()=>{if(!(!a||C)){y("create");try{const u=await Wn(a,{message:S.trim()||void 0});u.created?(b.success(x("gitView.stashes.toast.created")),z("")):b.info(x("gitView.stashes.toast.noChanges")),await F({affectsIndex:!!(u.created&&N)})}catch(u){b.error(u instanceof Error?u.message:x("gitView.stashes.toast.createFailed"))}finally{y(null)}}},Y=async(u,E)=>{if(!(!a||C)&&!(E==="drop"&&!window.confirm(x("gitView.stashes.confirm.drop",{ref:u.ref})))){y(`${E}:${u.ref}`);try{E==="apply"&&await Un(a,{ref:u.ref}),E==="pop"&&await Kn(a,{ref:u.ref}),E==="drop"&&await qn(a,{ref:u.ref});const se=E==="apply"?"gitView.stashes.toast.applySuccess":E==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";b.success(x(se)),await F({affectsIndex:E!=="drop"})}catch(se){const U=E==="apply"?"gitView.stashes.toast.applyFailed":E==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";b.error(se instanceof Error?se.message:x(U)),await F({affectsIndex:E!=="drop"})}finally{y(null)}}},B=C!==null;return t.jsx(mt,{open:o,onOpenChange:e,children:t.jsxs(ht,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsxs(gt,{children:[t.jsxs(ft,{className:"flex items-center gap-2",children:[t.jsx(T,{name:"archive-stack",className:"h-5 w-5"}),x("gitView.stashes.title")]}),t.jsx(bt,{children:x("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(gr,{value:S,onChange:u=>z(u.target.value),placeholder:x("gitView.stashes.messagePlaceholder"),disabled:B||!m,className:"flex-1"}),t.jsxs(W,{onClick:r,disabled:!m||B||!a,children:[C==="create"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"inbox-archive",className:"size-4"}),x("gitView.stashes.actions.stashCurrentWithCount",{count:f})]})]}),t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:x("gitView.stashes.includeUntrackedHint")})]}),t.jsxs("div",{className:"relative mt-2",children:[t.jsx(T,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(gr,{value:V,onChange:u=>L(u.target.value),placeholder:x("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:M?t.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:t.jsx(T,{name:"loader-4",className:"size-5 animate-spin"})}):P.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:x(V?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):P.map((u,E)=>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:u.message||x("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[t.jsxs(es,{children:[t.jsx(ts,{asChild:!0,children:t.jsx("span",{children:E===0&&!V.trim()?x("gitView.stashes.latestLabel"):x("gitView.stashes.itemNumber",{number:E+1})})}),t.jsx(ss,{sideOffset:6,children:u.ref})]})," · ",u.relativeTime," · ",typeof D[u.ref]=="number"?x("gitView.stashes.fileCount",{count:D[u.ref]}):x("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(Ms,{label:x("gitView.stashes.actions.apply"),loading:C===`apply:${u.ref}`,onClick:()=>Y(u,"apply"),disabled:B,children:t.jsx(T,{name:"inbox-unarchive",className:"size-4"})}),t.jsx(Ms,{label:x("gitView.stashes.actions.pop"),loading:C===`pop:${u.ref}`,onClick:()=>Y(u,"pop"),disabled:B,children:t.jsx(T,{name:"inbox-unarchive-fill",className:"size-4"})}),t.jsx(Ms,{label:x("gitView.stashes.actions.drop"),loading:C===`drop:${u.ref}`,onClick:()=>Y(u,"drop"),disabled:B,destructive:!0,children:t.jsx(T,{name:"delete-bin",className:"size-4"})})]})]},u.ref))})]})})},Ms=o=>{const e=Ct.c(17),{label:a,loading:m,disabled:N,destructive:f,onClick:p,children:x}=o,g=m||void 0,w=f?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let M;e[0]!==w?(M=Se("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",w),e[0]=w,e[1]=M):M=e[1];let v;e[2]!==x||e[3]!==m?(v=m?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):x,e[2]=x,e[3]=m,e[4]=v):v=e[4];let V;e[5]!==N||e[6]!==a||e[7]!==p||e[8]!==g||e[9]!==M||e[10]!==v?(V=t.jsx(ts,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":a,"aria-busy":g,className:M,onClick:p,disabled:N,children:v})}),e[5]=N,e[6]=a,e[7]=p,e[8]=g,e[9]=M,e[10]=v,e[11]=V):V=e[11];let L;e[12]!==a?(L=t.jsx(ss,{sideOffset:6,children:a}),e[12]=a,e[13]=L):L=e[13];let S;return e[14]!==V||e[15]!==L?(S=t.jsxs(es,{children:[V,L]}),e[14]=V,e[15]=L,e[16]=S):S=e[16],S},oi=o=>{const e=Ct.c(16),{onOpenStashes:a}=o,{t:m}=nt();let N;e[0]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(T,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=N):N=e[0];let f;e[1]!==m?(f=m("gitView.empty.cleanTitle"),e[1]=m,e[2]=f):f=e[2];let p;e[3]!==f?(p=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:f}),e[3]=f,e[4]=p):p=e[4];let x;e[5]!==m?(x=m("gitView.empty.cleanDescription"),e[5]=m,e[6]=x):x=e[6];let g;e[7]!==x?(g=t.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:x}),e[7]=x,e[8]=g):g=e[8];let w;e[9]!==a||e[10]!==m?(w=a?t.jsxs(W,{type:"button",variant:"outline",size:"sm",onClick:a,className:"gap-1.5",children:[t.jsx(T,{name:"archive-stack",className:"size-4"}),m("gitView.stashes.title")]}):null,e[9]=a,e[10]=m,e[11]=w):w=e[11];let M;return e[12]!==p||e[13]!==g||e[14]!==w?(M=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[N,p,g,w]}),e[12]=p,e[13]=g,e[14]=w,e[15]=M):M=e[15],M},ut=8,li=o=>{const e=Ct.c(18),{laned:a,totalLanes:m,isExpanded:N}=o,{lane:f,color:p,connectors:x}=a,w=Math.max(m,f+1)*ut+ut/2,M=l.useRef(null),v=l.useRef(null);let V;e[0]!==p||e[1]!==x||e[2]!==f||e[3]!==w?(V=()=>{const y=M.current,D=v.current;if(!y||!D)return;const k=y.offsetHeight;if(k===0)return;const R=window.devicePixelRatio||1;D.width=w*R,D.height=k*R;const P=D.getContext("2d");if(!P)return;P.scale(R,R),P.clearRect(0,0,w,k);const F=k/2,r=f*ut+ut/2,Y=getComputedStyle(D),B=Y.getPropertyValue("--surface-muted-foreground").trim()||Y.color,u=U=>{if(!U.startsWith("var("))return U;const G=U.slice(4,-1).trim();return Y.getPropertyValue(G).trim()||B},E=[...x].sort(di);for(const U of E){const G=U.fromLane*ut+ut/2,$=U.toLane*ut+ut/2,Z=U.type==="passing"?.72:U.type==="branch-out"||U.type==="merge-in"?.95:1;P.beginPath(),P.strokeStyle=u(U.color),P.globalAlpha=Z,P.lineWidth=1.25,P.lineCap="round";e:switch(U.type){case"passing":case"commit-lane":{P.moveTo(G,0),P.lineTo(G,k);break e}case"top-stub":{P.moveTo(G,0),P.lineTo(G,F);break e}case"bottom-stub":{P.moveTo(G,F),P.lineTo(G,k);break e}case"branch-out":{const H=(F+k)/2;P.moveTo(r,F),P.bezierCurveTo(r,H,$,H,$,k);break e}case"merge-in":{const H=F/2;P.moveTo(G,0),P.bezierCurveTo(G,H,r,H,r,F);break e}default:continue}P.stroke(),P.globalAlpha=1}const se=Y.getPropertyValue("--background").trim()||Y.getPropertyValue("--surface-background").trim();P.beginPath(),P.arc(r,F,4,0,Math.PI*2),P.fillStyle=u(p),P.fill(),P.beginPath(),P.arc(r,F,5,0,Math.PI*2),P.strokeStyle=se||B,P.lineWidth=2,P.stroke()},e[0]=p,e[1]=x,e[2]=f,e[3]=w,e[4]=V):V=e[4];let L;e[5]!==p||e[6]!==x||e[7]!==N||e[8]!==f||e[9]!==a||e[10]!==m||e[11]!==w?(L=[a,f,p,x,m,N,w],e[5]=p,e[6]=x,e[7]=N,e[8]=f,e[9]=a,e[10]=m,e[11]=w,e[12]=L):L=e[12],l.useLayoutEffect(V,L);let S;e[13]!==w?(S={width:w,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=w,e[14]=S):S=e[14];let z;e[15]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx("canvas",{ref:v,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=z):z=e[15];let C;return e[16]!==S?(C=t.jsx("div",{ref:M,style:S,children:z}),e[16]=S,e[17]=C):C=e[17],C};function ci(o){return o==="branch-out"||o==="merge-in"}function di(o,e){const a=ci;return(a(o.type)?1:0)-(a(e.type)?1:0)}const yr=15e3,br=500,vr=12,jr=8*1024*1024,Cr=o=>typeof o=="string"?0:(o.original?.length??0)+(o.modified?.length??0),Nr=o=>{if(o.size<=vr){let N=0;for(const f of o.values())N+=Cr(f);if(N<=jr)return o}const e=Array.from(o.entries()).reverse(),a=new Map;let m=0;for(const[N,f]of e){if(a.size>=vr)continue;const p=Cr(f);m+p>jr&&a.size>0||(a.set(N,f),m+=p)}return new Map(Array.from(a.entries()).reverse())};function Sr(o,e){const a=new Date(o);return Number.isNaN(a.getTime())?o:Zn(a,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function ui(o){switch(o){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 mi(o){return o?o.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const a=e.startsWith("HEAD ->");return{label:a?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:a,isTag:e.startsWith("tag: ")}}):[]}const hi=l.memo(({entry:o,mode:e="history",laned:a,totalLanes:m,isExpanded:N,onToggle:f,files:p,isLoadingFiles:x,onCopyHash:g,directory:w,onConflict:M,onActionSuccess:v})=>{const{t:V}=nt(),L=Rt(d=>d.timeFormatPreference),S=e==="graph",[z,C]=l.useState(null),[y,D]=l.useState(!1),[k,R]=l.useState(""),[P,F]=l.useState(null),[r,Y]=l.useState(new Set),[B,u]=l.useState(new Map),[E,se]=l.useState(new Set),U=async()=>{if(w){C("checkout");try{await aa(w,o.hash),b.success(V("gitView.history.actions.detachedHead")),v?.()}catch(d){b.error(String(d.message))}finally{C(null)}}},G=async()=>{if(!(!w||!k.trim())){C("createBranch");try{await Xn(w,k.trim(),o.hash),D(!1),R(""),v?.()}catch(d){b.error(String(d.message))}finally{C(null)}}},$=async()=>{if(w){C("cherryPick");try{const d=await na(w,o.hash);d.conflict?M?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"cherry-pick"}):v?.()}catch(d){b.error(String(d.message))}finally{C(null)}}},Z=async()=>{if(w){C("revert");try{const d=await ra(w,o.hash);d.conflict?M?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"revert"}):v?.()}catch(d){b.error(String(d.message))}finally{C(null)}}},H=async(d,I=!1)=>{if(!(!w||z!==null)){C("reset");try{await ea(w,o.hash,d,I),v?.()}catch(O){b.error(String(O.message))}finally{C(null)}}},le=async()=>{if(!P)return;const d=P;switch(F(null),d){case"checkout":return U();case"cherryPick":return $();case"revert":return Z();case"merge":return ae();case"rebase":return ce();case"resetSoft":return H("soft");case"resetMixed":return H("mixed");case"resetHard":return H("hard",!0)}},ae=async()=>{if(w){C("merge");try{const d=await sa(w,{branch:o.hash});d.conflict?M?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"merge"}):v?.()}catch(d){b.error(String(d.message))}finally{C(null)}}},ce=async()=>{if(w){C("rebase");try{const d=await ta(w,{onto:o.hash});d.conflict?M?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"rebase"}):v?.()}catch(d){b.error(String(d.message))}finally{C(null)}}},ie=l.useCallback(async d=>{const I=d.path;if(!w){u(O=>new Map(O).set(I,"error"));return}u(O=>Nr(new Map(O).set(I,"loading")));try{const O=Jn(w,o.hash,d.path,!1),J=new Promise((re,q)=>{setTimeout(()=>q(new Error(`Timed out after ${yr}ms`)),yr)}),ne=await Promise.race([O,J]);u(re=>Nr(new Map(re).set(I,ne)))}catch{u(O=>new Map(O).set(I,"error"))}},[w,o.hash]),h=l.useCallback(async d=>{const I=d.path;if(d.changeType==="R"||d.isBinary){Y(re=>{const q=new Set(re);return q.has(I)?q.delete(I):q.add(I),q});return}const O=B.get(I);if(r.has(I)&&O&&O!=="error"){Y(re=>{const q=new Set(re);return q.delete(I),q});return}Y(re=>{const q=new Set(re);return q.add(I),q}),!(O&&O!=="error"||d.insertions+d.deletions>br&&!E.has(I))&&await ie(d)},[B,E,ie,r]);return t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:f,className:Se("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",S?"hover:bg-[var(--interactive-hover)]/40":N?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[S&&a&&m!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(li,{laned:a,totalLanes:m,isExpanded:N})}):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:[S?(()=>{const d=mi(o.refs);return d.length>0?t.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:d.map(I=>t.jsx("span",{className:Se("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",I.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":I.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:I.label},I.label))}):null})():null,t.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:o.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:o.author_name,children:o.author_name}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("span",{className:"truncate min-w-0",title:Sr(o.date,L),children:Sr(o.date,L)})]}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("code",{className:"shrink-0 font-mono",children:o.hash.slice(0,8)}),t.jsxs(es,{children:[t.jsx(ts,{asChild:!0,children:t.jsx(W,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:d=>{d.stopPropagation(),g(o.hash)},children:t.jsx(T,{name:"file-copy",className:"size-3"})})}),t.jsx(ss,{sideOffset:8,children:V("gitView.history.copySha")})]})]})]})]}),N&&t.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[S&&P?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:V(`gitView.history.actions.${P}Confirm`)}),t.jsxs(W,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:z!==null,onClick:d=>{d.stopPropagation(),le()},children:[z!==null?t.jsx(T,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,V("gitView.history.actions.confirmButton")]}),t.jsx(W,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:z!==null,onClick:d=>{d.stopPropagation(),F(null)},children:V("gitView.history.actions.cancelButton")})]}):S?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:z!==null,onClick:d=>{d.stopPropagation(),F("checkout")},children:V("gitView.history.actions.checkout")}),y?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{autoFocus:!0,value:k,onChange:d=>R(d.target.value),onKeyDown:d=>{d.key==="Enter"&&G(),d.key==="Escape"&&(D(!1),R(""))},placeholder:V("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:!k.trim()||z!==null,onClick:d=>{d.stopPropagation(),G()},children:[z==="createBranch"?t.jsx(T,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,V("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(W,{variant:"outline",size:"xs",className:"h-6",onClick:d=>{d.stopPropagation(),D(!0)},children:V("gitView.history.actions.createBranch")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:z!==null,onClick:d=>{d.stopPropagation(),F("cherryPick")},children:V("gitView.history.actions.cherryPick")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:z!==null,onClick:d=>{d.stopPropagation(),F("revert")},children:V("gitView.history.actions.revert")}),t.jsxs(Ts,{children:[t.jsx(Ls,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"xs",className:"h-6",disabled:z!==null,onClick:d=>d.stopPropagation(),children:[z==="reset"?t.jsx(T,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,V("gitView.history.actions.reset")]})}),t.jsx(Os,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(d=>t.jsx(Yn,{disabled:z!==null,onSelect:I=>{I.stopPropagation(),F(`reset${d.charAt(0).toUpperCase()+d.slice(1)}`)},children:V(`gitView.history.actions.reset${d.charAt(0).toUpperCase()+d.slice(1)}`)},d))})]}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:z!==null,onClick:d=>{d.stopPropagation(),F("merge")},children:V("gitView.history.actions.merge")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:z!==null,onClick:d=>{d.stopPropagation(),F("rebase")},children:V("gitView.history.actions.rebase")})]}):null,x?t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:V("gitView.history.loadingFiles")})]}):p.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:V("gitView.history.noFiles")}):t.jsx("ul",{className:"space-y-0.5 py-2",children:p.map(d=>t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:()=>h(d),className:Se("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",r.has(d.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[t.jsx("span",{className:Se("font-semibold w-3 text-center shrink-0",ui(d.changeType)),children:d.changeType}),t.jsx("span",{className:"truncate text-foreground min-w-0",title:d.path,children:d.path}),!d.isBinary&&t.jsxs("span",{className:"shrink-0",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",d.insertions]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",d.deletions]})]}),d.isBinary&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:V("gitView.history.binary")}),t.jsx(T,{name:r.has(d.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),r.has(d.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:d.changeType==="R"?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:V("gitView.history.renamedNoDiff")}):d.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:V("gitView.history.binaryNoDiff")}):(()=>{const I=d.insertions+d.deletions;if(!E.has(d.path)&&I>br)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:V("gitView.history.largeDiffTitle",{count:I})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:V("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:()=>{se(J=>new Set(J).add(d.path)),ie(d)},children:V("gitView.history.renderDiffAnyway")})]});const O=B.get(d.path);return O==="loading"||O===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:V("gitView.history.loadingDiff")}):O==="error"?t.jsx("button",{type:"button",onClick:()=>h(d),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:V("gitView.history.diffError")}):t.jsx(Ja,{original:O.original,modified:O.modified,language:Qn(d.path)||"",fileName:d.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},d.path))})]})]})}),kr=["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 Jt(o){return kr[o%kr.length]}function gi(o){if(o.length===0)return[];const e=[],a=[];for(let m=0;m<o.length;m++){const N=o[m],f=[];for(let S=0;S<e.length;S++)e[S]===N.hash&&f.push(S);let p=f.length>0?f[0]:-1;if(p===-1){const S=e.indexOf(null);S!==-1?p=S:(p=e.length,e.push(null))}const x=f.slice(1),g=Jt(p),w=e[p]===N.hash,M=N.parents.length>0;M?e[p]=N.parents[0]:e[p]=null;const v=[],V=new Set;for(let S=1;S<N.parents.length;S++){const z=N.parents[S],C=e.indexOf(z);if(C!==-1)v.push(C);else{const y=e.indexOf(null);if(y!==-1)e[y]=z,v.push(y),V.add(y);else{const D=e.length;e.push(z),v.push(D),V.add(D)}}}const L=[];w&&M?L.push({fromLane:p,toLane:p,color:g,type:"commit-lane"}):w&&!M?L.push({fromLane:p,toLane:p,color:g,type:"top-stub"}):!w&&M&&L.push({fromLane:p,toLane:p,color:g,type:"bottom-stub"});for(const S of x)L.push({fromLane:S,toLane:p,color:Jt(S),type:"merge-in"}),e[S]=null;for(const S of v)L.push({fromLane:p,toLane:S,color:Jt(S),type:"branch-out"});for(let S=0;S<e.length;S++)e[S]!==null&&S!==p&&(V.has(S)||L.push({fromLane:S,toLane:S,color:Jt(S),type:"passing"}));a.push({commit:N,lane:p,color:g,connectors:L})}return a}const fi=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],pi=o=>{const e=Ct.c(84),{mode:a,log:m,isLogLoading:N,logMaxCount:f,onLogMaxCountChange:p,expandedCommitHashes:x,onToggleCommit:g,commitFilesMap:w,loadingCommitHashes:M,onCopyHash:v,directory:V,showHeader:L,contentMaxHeightClassName:S,branchDivider:z,onConflict:C,onActionSuccess:y}=o,D=a===void 0?"history":a,k=L===void 0?!0:L,R=S===void 0?"max-h-[50vh]":S,P=z===void 0?null:z,{t:F}=nt(),[r,Y]=l.useState(!0),B=D==="graph";let u;e[0]!==B||e[1]!==m?(u=B&&m?gi(m.all):[],e[0]=B,e[1]=m,e[2]=u):u=e[2];const E=u;let se;e[3]!==E?(se=Math.max(1,...E.map(xi)),e[3]=E,e[4]=se):se=e[4];const U=se;let G;e[5]!==E?(G=new Map(E.map(wi)),e[5]=E,e[6]=G):G=e[6];const $=G;if(!m)return null;const Z=P!==null&&P.insertBeforeIndex>0&&P.insertBeforeIndex<m.all.length,H=P!==null&&P.insertBeforeIndex===m.all.length,le=Z||H;let ae;e[7]!==P||e[8]!==Z||e[9]!==H||e[10]!==m.all?(ae=Z?m.all.slice(0,P.insertBeforeIndex):H?m.all:[],e[7]=P,e[8]=Z,e[9]=H,e[10]=m.all,e[11]=ae):ae=e[11];const ce=ae;let ie;if(e[12]!==P||e[13]!==w||e[14]!==R||e[15]!==V||e[16]!==x||e[17]!==Z||e[18]!==le||e[19]!==B||e[20]!==N||e[21]!==$||e[22]!==M||e[23]!==m.all||e[24]!==f||e[25]!==U||e[26]!==D||e[27]!==y||e[28]!==C||e[29]!==v||e[30]!==p||e[31]!==g||e[32]!==F||e[33]!==ce){const K=Z?m.all.slice(P.insertBeforeIndex):[];let de;e[35]!==P?.direction?(de=P?.direction==="down"?t.jsx(T,{name:"arrow-down-s",className:"size-3.5"}):t.jsx(T,{name:"arrow-up",className:"size-3.5"}),e[35]=P?.direction,e[36]=de):de=e[36];const ke=de;let ye;e[37]!==w||e[38]!==V||e[39]!==x||e[40]!==B||e[41]!==$||e[42]!==M||e[43]!==U||e[44]!==D||e[45]!==y||e[46]!==C||e[47]!==v||e[48]!==g?(ye=Re=>t.jsx("ul",{className:"divide-y divide-border/60",children:Re.map(ue=>t.jsx(hi,{entry:ue,mode:D,laned:B?$.get(ue.hash):void 0,totalLanes:B?U:void 0,isExpanded:x.has(ue.hash),onToggle:()=>g(ue.hash),files:w.get(ue.hash)??[],isLoadingFiles:M.has(ue.hash),onCopyHash:v,directory:V,onConflict:C,onActionSuccess:y},ue.hash))}),e[37]=w,e[38]=V,e[39]=x,e[40]=B,e[41]=$,e[42]=M,e[43]=U,e[44]=D,e[45]=y,e[46]=C,e[47]=v,e[48]=g,e[49]=ye):ye=e[49];const me=ye;let xe;e[50]!==N||e[51]!==m.all.length||e[52]!==f||e[53]!==p||e[54]!==F?(xe=m.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:()=>p(f+25),disabled:N,className:"px-3 text-muted-foreground hover:text-foreground",children:N?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(T,{name:"loader-4",className:"size-3 animate-spin"}),F("gitView.history.loadingMore")]}):F("gitView.history.loadMore")})}):null,e[50]=N,e[51]=m.all.length,e[52]=f,e[53]=p,e[54]=F,e[55]=xe):xe=e[55];const Ve=xe;ie=t.jsx(Rr,{outerClassName:`min-h-0 ${R}`,className:"h-full w-full",children:m.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:F("gitView.history.noCommits")})}):le&&P?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col gap-0",children:[ce.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:me(ce)}):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:P.branchName,children:P.branchName}),ke]}),t.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),K.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:me(K)}):null]}),Ve]}):t.jsxs(t.Fragment,{children:[me(m.all),Ve]})}),e[12]=P,e[13]=w,e[14]=R,e[15]=V,e[16]=x,e[17]=Z,e[18]=le,e[19]=B,e[20]=N,e[21]=$,e[22]=M,e[23]=m.all,e[24]=f,e[25]=U,e[26]=D,e[27]=y,e[28]=C,e[29]=v,e[30]=p,e[31]=g,e[32]=F,e[33]=ce,e[34]=ie}else ie=e[34];const h=ie;if(!k){if(le){let de;return e[56]!==h?(de=t.jsx("section",{className:"h-full min-h-0",children:h}),e[56]=h,e[57]=de):de=e[57],de}let K;return e[58]!==h?(K=t.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:h}),e[58]=h,e[59]=K):K=e[59],K}let d;e[60]!==F?(d=F("gitView.history.title"),e[60]=F,e[61]=d):d=e[61];let I;e[62]!==d?(I=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:d}),e[62]=d,e[63]=I):I=e[63];let O;e[64]!==N||e[65]!==r||e[66]!==f||e[67]!==p||e[68]!==F?(O=r&&t.jsx("div",{onClick:yi,onPointerDown:bi,children:t.jsxs(ia,{value:String(f),onValueChange:K=>p(Number(K)),disabled:N,children:[t.jsx(oa,{size:"sm",className:"w-auto",disabled:N,children:t.jsx(la,{placeholder:F("gitView.history.commitsPlaceholder")})}),t.jsx(ca,{children:fi.map(K=>t.jsx(da,{value:String(K.value),children:F(K.labelKey)},K.value))})]})}),e[64]=N,e[65]=r,e[66]=f,e[67]=p,e[68]=F,e[69]=O):O=e[69];let J;e[70]!==r?(J=r?t.jsx(T,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):t.jsx(T,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=r,e[71]=J):J=e[71];let ne;e[72]!==O||e[73]!==J?(ne=t.jsxs("div",{className:"flex items-center gap-2",children:[O,J]}),e[72]=O,e[73]=J,e[74]=ne):ne=e[74];let re;e[75]!==I||e[76]!==ne?(re=t.jsxs(ua,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[I,ne]}),e[75]=I,e[76]=ne,e[77]=re):re=e[77];let q;e[78]!==h?(q=t.jsx(ma,{children:h}),e[78]=h,e[79]=q):q=e[79];let we;return e[80]!==r||e[81]!==re||e[82]!==q?(we=t.jsxs(ha,{open:r,onOpenChange:Y,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[re,q]}),e[80]=r,e[81]=re,e[82]=q,e[83]=we):we=e[83],we};function xi(o){return o.lane+1}function wi(o){return[o.commit.hash,o]}function yi(o){return o.stopPropagation()}function bi(o){return o.stopPropagation()}const vi=o=>{const e=Ct.c(148),{open:a,onOpenChange:m,conflictFiles:N,directory:f,operation:p,onAbort:x,onClearState:g}=o;let w;e[0]!==N?(w=N===void 0?[]:N,e[0]=N,e[1]=w):w=e[1];const M=w,{t:v}=nt(),V=rt(ji),L=rt(Ci),S=Qt(Ni),z=Qt(Si),[C,y]=l.useState(!1),[D,k]=l.useState(null),[R,P]=l.useState(null);let F,r;e[2]!==f||e[3]!==a||e[4]!==v?(F=()=>{!a||!f||(y(!0),P(null),k(null),ga(f).then(ee=>{k(ee)}).catch(ee=>{const he=ee instanceof Error?ee.message:v("gitView.conflict.loadFailed");P(he)}).finally(()=>{y(!1)}))},r=[a,f,v],e[2]=f,e[3]=a,e[4]=v,e[5]=F,e[6]=r):(F=e[5],r=e[6]),l.useEffect(F,r);let Y;e[7]!==D||e[8]!==f||e[9]!==p?(Y=async()=>{if(!D)return null;const ee=p==="merge"?"merge":"rebase",he=D.headInfo||(p==="merge"?"MERGE_HEAD":"REBASE_HEAD"),Be=p==="merge"?"git commit --no-edit":"git rebase --continue",ge=await Yt("git.conflict.resolve.visible",{operation_label:ee,head_ref:he}),Ne=await Yt("git.conflict.resolve.instructions",{operation_label:ee,directory:f,operation:p,head_info:D.headInfo||"N/A",continue_cmd:Be}),Ie=`${ee} conflict context (JSON)
|
|
3
|
+
${JSON.stringify({directory:f,operation:D.operation,headInfo:D.headInfo,statusPorcelain:D.statusPorcelain,unmergedFiles:D.unmergedFiles,diff:D.diff},null,2)}`;return{visibleText:ge,instructionsText:Ne,payloadText:Ie}},e[7]=D,e[8]=f,e[9]=p,e[10]=Y):Y=e[10];const B=Y;let u;e[11]!==x||e[12]!==m?(u=()=>{x(),m(!1)},e[11]=x,e[12]=m,e[13]=u):u=e[13];const E=u;let se;e[14]!==g||e[15]!==m?(se=()=>{g?.(),m(!1)},e[14]=g,e[15]=m,e[16]=se):se=e[16];const U=se;let G;e[17]!==B||e[18]!==L||e[19]!==g||e[20]!==m||e[21]!==S||e[22]!==z||e[23]!==v?(G=async()=>{const ee=await B();if(!ee){b.error(v("gitView.conflict.noDetailsAvailable"));return}if(!L){b.error(v("gitView.conflict.noActiveSession"),{description:v("gitView.conflict.noActiveSessionDescription")});return}S(ee.visibleText,"replace"),z([{text:ee.instructionsText,synthetic:!0},{text:ee.payloadText,synthetic:!0}]),g?.(),m(!1)},e[17]=B,e[18]=L,e[19]=g,e[20]=m,e[21]=S,e[22]=z,e[23]=v,e[24]=G):G=e[24];const $=G;let Z;e[25]!==B||e[26]!==f||e[27]!==g||e[28]!==m||e[29]!==V||e[30]!==v?(Z=async()=>{const ee=await B();if(!ee){b.error(v("gitView.conflict.noDetailsAvailable"));return}V({directoryOverride:f,initialPrompt:ee.visibleText,syntheticParts:[{text:ee.instructionsText,synthetic:!0},{text:ee.payloadText,synthetic:!0}]}),g?.(),m(!1)},e[25]=B,e[26]=f,e[27]=g,e[28]=m,e[29]=V,e[30]=v,e[31]=Z):Z=e[31];const H=Z;let le,ae,ce,ie,h,d,I,O,J,ne,re,q,we,K,de,ke,ye,me,xe,Ve,Re,ue;if(e[32]!==D||e[33]!==M||e[34]!==L||e[35]!==E||e[36]!==U||e[37]!==$||e[38]!==H||e[39]!==C||e[40]!==R||e[41]!==m||e[42]!==a||e[43]!==p||e[44]!==v){const ee=v(p==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),he=D?.unmergedFiles||M;ce=mt,Re=a,ue=m,ae=ht,Ve="max-w-md w-[calc(100vw-2rem)]",K="flex flex-col gap-4 overflow-hidden";let Be;e[67]===Symbol.for("react.memo_cache_sentinel")?(Be=t.jsx(T,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[67]=Be):Be=e[67];const ge=t.jsxs("div",{className:"flex items-center gap-2",children:[Be,t.jsx(ft,{children:v("gitView.conflict.detectedTitle",{operation:ee})})]});let Ne;e[68]!==p||e[69]!==v?(Ne=v("gitView.conflict.detectedDescription",{operation:p}),e[68]=p,e[69]=v,e[70]=Ne):Ne=e[70];let Ie;e[71]!==Ne?(Ie=t.jsx(bt,{children:Ne}),e[71]=Ne,e[72]=Ie):Ie=e[72],e[73]!==ge||e[74]!==Ie?(de=t.jsxs(gt,{children:[ge,Ie]}),e[73]=ge,e[74]=Ie,e[75]=de):de=e[75],e[76]!==C||e[77]!==v?(ke=C&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:v("gitView.conflict.loading")})]}),e[76]=C,e[77]=v,e[78]=ke):ke=e[78],e[79]!==R||e[80]!==v?(ye=R&&t.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:v("gitView.conflict.errorLoadingDetails",{message:R})}),e[79]=R,e[80]=v,e[81]=ye):ye=e[81],e[82]!==he||e[83]!==v?(me=he.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:v("gitView.conflict.conflictedFiles")}),t.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:he.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:he.map(ki)})})]}),e[82]=he,e[83]=v,e[84]=me):me=e[84],e[85]!==D||e[86]!==v?(xe=D?.headInfo&&t.jsxs("div",{className:"space-y-1 overflow-hidden",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:v("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:D.headInfo})]}),e[85]=D,e[86]=v,e[87]=xe):xe=e[87],re="flex flex-col gap-2 pt-2";let Te;e[88]!==H?(Te=()=>{H()},e[88]=H,e[89]=Te):Te=e[89];const oe=C||!D;let Pe;e[90]!==C?(Pe=C?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"add",className:"size-4"}),e[90]=C,e[91]=Pe):Pe=e[91];let Fe;e[92]!==v?(Fe=v("gitView.conflict.resolveNewSession"),e[92]=v,e[93]=Fe):Fe=e[93],e[94]!==Te||e[95]!==oe||e[96]!==Pe||e[97]!==Fe?(q=t.jsxs(W,{variant:"default",onClick:Te,disabled:oe,className:"w-full gap-2",children:[Pe,Fe]}),e[94]=Te,e[95]=oe,e[96]=Pe,e[97]=Fe,e[98]=q):q=e[98];let De;e[99]!==$?(De=()=>{$()},e[99]=$,e[100]=De):De=e[100];const Ue=C||!D||!L;let Le;e[101]!==C?(Le=C?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"chat-1",className:"size-4"}),e[101]=C,e[102]=Le):Le=e[102];let Q;e[103]!==v?(Q=v("gitView.conflict.resolveCurrentSession"),e[103]=v,e[104]=Q):Q=e[104],e[105]!==De||e[106]!==Ue||e[107]!==Le||e[108]!==Q?(we=t.jsxs(W,{variant:"outline",onClick:De,disabled:Ue,className:"w-full gap-2",children:[Le,Q]}),e[105]=De,e[106]=Ue,e[107]=Le,e[108]=Q,e[109]=we):we=e[109],J="flex gap-2 pt-1";let fe;e[110]!==v?(fe=v("gitView.conflict.continueLater"),e[110]=v,e[111]=fe):fe=e[111],e[112]!==U||e[113]!==fe?(ne=t.jsx(W,{variant:"ghost",size:"sm",onClick:U,className:"flex-1",children:fe}),e[112]=U,e[113]=fe,e[114]=ne):ne=e[114],le=W,ie="destructive",h="sm",d=E,I="flex-1",O=v("gitView.conflict.abortOperation",{operation:ee}),e[32]=D,e[33]=M,e[34]=L,e[35]=E,e[36]=U,e[37]=$,e[38]=H,e[39]=C,e[40]=R,e[41]=m,e[42]=a,e[43]=p,e[44]=v,e[45]=le,e[46]=ae,e[47]=ce,e[48]=ie,e[49]=h,e[50]=d,e[51]=I,e[52]=O,e[53]=J,e[54]=ne,e[55]=re,e[56]=q,e[57]=we,e[58]=K,e[59]=de,e[60]=ke,e[61]=ye,e[62]=me,e[63]=xe,e[64]=Ve,e[65]=Re,e[66]=ue}else le=e[45],ae=e[46],ce=e[47],ie=e[48],h=e[49],d=e[50],I=e[51],O=e[52],J=e[53],ne=e[54],re=e[55],q=e[56],we=e[57],K=e[58],de=e[59],ke=e[60],ye=e[61],me=e[62],xe=e[63],Ve=e[64],Re=e[65],ue=e[66];let $e;e[115]!==le||e[116]!==ie||e[117]!==h||e[118]!==d||e[119]!==I||e[120]!==O?($e=t.jsx(le,{variant:ie,size:h,onClick:d,className:I,children:O}),e[115]=le,e[116]=ie,e[117]=h,e[118]=d,e[119]=I,e[120]=O,e[121]=$e):$e=e[121];let Ae;e[122]!==J||e[123]!==ne||e[124]!==$e?(Ae=t.jsxs("div",{className:J,children:[ne,$e]}),e[122]=J,e[123]=ne,e[124]=$e,e[125]=Ae):Ae=e[125];let je;e[126]!==re||e[127]!==q||e[128]!==we||e[129]!==Ae?(je=t.jsxs("div",{className:re,children:[q,we,Ae]}),e[126]=re,e[127]=q,e[128]=we,e[129]=Ae,e[130]=je):je=e[130];let be;e[131]!==K||e[132]!==de||e[133]!==ke||e[134]!==ye||e[135]!==me||e[136]!==xe||e[137]!==je?(be=t.jsxs("div",{className:K,children:[de,ke,ye,me,xe,je]}),e[131]=K,e[132]=de,e[133]=ke,e[134]=ye,e[135]=me,e[136]=xe,e[137]=je,e[138]=be):be=e[138];let Ce;e[139]!==ae||e[140]!==Ve||e[141]!==be?(Ce=t.jsx(ae,{className:Ve,children:be}),e[139]=ae,e[140]=Ve,e[141]=be,e[142]=Ce):Ce=e[142];let Ee;return e[143]!==ce||e[144]!==Re||e[145]!==ue||e[146]!==Ce?(Ee=t.jsx(ce,{open:Re,onOpenChange:ue,children:Ce}),e[143]=ce,e[144]=Re,e[145]=ue,e[146]=Ce,e[147]=Ee):Ee=e[147],Ee};function ji(o){return o.openNewSessionDraft}function Ci(o){return o.currentSessionId}function Ni(o){return o.setPendingInputText}function Si(o){return o.setPendingSyntheticParts}function ki(o){return t.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:o,children:o},o)}const Vi=({open:o,onOpenChange:e,operation:a,targetBranch:m,onConfirm:N})=>{const{t:f}=nt(),[p,x]=l.useState(!0),[g,w]=l.useState(!1),M=f(a==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),v=async()=>{w(!0);try{await N(p),e(!1)}catch(L){const S=L instanceof Error?L.message:`Failed to ${a}`;b.error(S)}finally{w(!1)}},V=()=>{g||e(!1)};return t.jsx(mt,{open:o,onOpenChange:g?void 0:e,children:t.jsxs(ht,{className:"max-w-md",children:[t.jsxs(gt,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),t.jsx(ft,{children:f("gitView.stash.title")})]}),t.jsx(bt,{children:f("gitView.stash.description",{operation:a})})]}),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(a==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",f(a==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",t.jsx("span",{className:"font-mono text-primary",children:m})]}),p&&t.jsx("li",{children:f("gitView.stash.stepRestore")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(fa,{checked:p,onChange:x,disabled:g,ariaLabel:f("gitView.stash.restoreAria")}),t.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!g&&x(!p),children:f("gitView.stash.restoreAfterOperation",{operation:a})})]}),t.jsxs(Es,{className:"gap-2",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:V,disabled:g,children:f("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:v,disabled:g,className:"gap-1.5",children:g?t.jsxs(t.Fragment,{children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),f("gitView.common.processing")]}):f("gitView.stash.confirmButton",{operation:M})})]})]})})},Ii=({mergeInProgress:o,rebaseInProgress:e,onContinue:a,onAbort:m,onResolveWithAI:N,conflictCount:f=0,isLoading:p=!1})=>{const{t:x}=nt(),[g,w]=l.useState(null),M=o&&o.head,v=e&&(e.headName||e.onto),V=M?"merge":v?"rebase":null;if(!V)return null;const L=async()=>{w("continue");try{await a()}finally{w(null)}},S=async()=>{w("abort");try{await m()}finally{w(null)}},z=g!==null,C=f>0,y=x(V==="merge"?"gitView.operation.merge":"gitView.operation.rebase");let D="";o?D=o.message?x("gitView.operation.mergingMessage",{message:o.message}):x("gitView.operation.mergeInProgressWithHead",{head:o.head}):e&&(D=e.headName?x("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):x("gitView.operation.rebaseInProgress"));const k=C?f===1?x("gitView.operation.inProgressTitleOneConflict",{operation:y,count:f}):x("gitView.operation.inProgressTitleManyConflicts",{operation:y,count:f}):x("gitView.operation.inProgressTitle",{operation:y}),R=x(C?"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:k}),D&&t.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:D})]}),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:R}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[t.jsxs(W,{variant:"ghost",size:"sm",onClick:S,disabled:z||p,className:"gap-1.5",children:[g==="abort"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"close",className:"size-4"}),x("gitView.operation.abort")]}),C?N&&t.jsx(W,{variant:"default",size:"sm",onClick:N,disabled:z||p,children:x("gitView.operation.resolveWithAi")}):t.jsxs(W,{variant:"default",size:"sm",onClick:L,disabled:z||p,className:"gap-1.5",children:[g==="continue"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"check",className:"size-4"}),x("gitView.operation.continue")]})]})]})]})})},Pi=o=>{const e=Ct.c(104),{currentBranch:a,localBranches:m,remoteBranches:N,onMerge:f,onRebase:p,disabled:x,isOperating:g,operationLogs:w,onOperationComplete:M,mode:v,defaultTargetBranch:V}=o,L=x===void 0?!1:x,S=g===void 0?!1:g,z=w===void 0?[]:w,C=v===void 0?"dialog":v,{t:y}=nt(),[D,k]=l.useState(!1),[R,P]=l.useState("merge"),[F,r]=l.useState(null),[Y,B]=l.useState(!1),[u,E]=l.useState(""),se=l.useRef(null),U=l.useRef(null),G=L||S,$=a||y("gitView.branch.currentBranchFallback"),Z=z.length>0&&z.every(Fi),H=z.some(Ri);let le;e[0]===Symbol.for("react.memo_cache_sentinel")?(le=()=>{U.current&&(U.current.scrollTop=U.current.scrollHeight)},e[0]=le):le=e[0],l.useEffect(le,[z]);let ae;e[1]!==N?(ae=new Set(N.map(Bi).filter(Boolean)),e[1]=N,e[2]=ae):ae=e[2];const ce=ae;let ie;if(e[3]!==u||e[4]!==a||e[5]!==m||e[6]!==ce){let Q;e[8]!==a||e[9]!==ce?(Q=Oe=>Oe!==a&&!ce.has(Oe),e[8]=a,e[9]=ce,e[10]=Q):Q=e[10];const fe=m.filter(Q);ie=Dt(fe,u,Di),e[3]=u,e[4]=a,e[5]=m,e[6]=ce,e[7]=ie}else ie=e[7];const h=ie;let d;e[11]!==u||e[12]!==N?(d=Dt(N,u,Mi),e[11]=u,e[12]=N,e[13]=d):d=e[13];const I=d;let O;e[14]!==V||e[15]!==m||e[16]!==N?(O=()=>V&&(N.includes(V)||m.includes(V))?V:null,e[14]=V,e[15]=m,e[16]=N,e[17]=O):O=e[17];const J=O;let ne;e[18]!==J||e[19]!==k?(ne=()=>{k(!0),r(J()),P("merge"),E("")},e[18]=J,e[19]=k,e[20]=ne):ne=e[20];const re=ne;let q;e[21]===Symbol.for("react.memo_cache_sentinel")?(q=Q=>{r(Q),B(!1),E("")},e[21]=q):q=e[21];const we=q;let K;e[22]!==f||e[23]!==p||e[24]!==R||e[25]!==F?(K=()=>{F&&(R==="merge"?f(F):p(F))},e[22]=f,e[23]=p,e[24]=R,e[25]=F,e[26]=K):K=e[26];const de=K;let ke;e[27]!==S||e[28]!==k?(ke=()=>{S||(r(null),P("merge"),E(""),k(!1))},e[27]=S,e[28]=k,e[29]=ke):ke=e[29];const ye=ke,me=()=>{S&&!Z||(Z&&M?.(),r(null),P("merge"),E(""),k(!1))};let xe,Ve;e[30]!==Y?(xe=()=>{Y||E("")},Ve=[Y],e[30]=Y,e[31]=xe,e[32]=Ve):(xe=e[31],Ve=e[32]),l.useEffect(xe,Ve);let Re,ue;e[33]!==C||e[34]!==J||e[35]!==F?(Re=()=>{C==="dialog"||F||r(J())},ue=[C,J,F],e[33]=C,e[34]=J,e[35]=F,e[36]=Re,e[37]=ue):(Re=e[36],ue=e[37]),l.useEffect(Re,ue);const je=S?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{ref:U,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:z.map(Ei)})}),Z?C==="dialog"?t.jsx(Es,{children:t.jsx(W,{variant:"default",size:"sm",onClick:me,children:y(H?"gitView.common.close":"gitView.common.done")})}):t.jsx("div",{className:"flex justify-end",children:t.jsx(W,{variant:"default",size:"sm",onClick:me,children:y(H?"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:y("gitView.branch.operation")}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>P("merge"),className:Se("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",R==="merge"?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-border/80 hover:bg-interactive-hover"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"git-merge",className:Se("size-4",R==="merge"?"text-inherit":"text-muted-foreground")}),t.jsx("span",{className:Se("typography-ui-label",R==="merge"?"text-foreground":"text-muted-foreground"),children:y("gitView.operation.merge")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:y("gitView.branch.mergeDescription")})]}),t.jsxs("button",{type:"button",onClick:()=>P("rebase"),className:Se("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",R==="rebase"?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-border/80 hover:bg-interactive-hover"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"git-branch",className:Se("size-4",R==="rebase"?"text-inherit":"text-muted-foreground")}),t.jsx("span",{className:Se("typography-ui-label",R==="rebase"?"text-foreground":"text-muted-foreground"),children:y("gitView.operation.rebase")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:y("gitView.branch.rebaseDescription")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:R==="merge"?y("gitView.branch.branchToMergeInto",{branch:$}):y("gitView.branch.branchToRebaseOnto")}),t.jsxs(Ts,{open:Y,onOpenChange:B,modal:!1,children:[t.jsx(Ls,{asChild:!0,children:t.jsxs("button",{type:"button",className:Se(Fr({size:"default"}),"w-full"),children:[t.jsx("span",{className:Se("truncate",!F&&"text-muted-foreground"),children:F||y("gitView.branch.selectBranch")}),t.jsx(T,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),t.jsx(Os,{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(As,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(zs,{ref:se,placeholder:y("gitView.branch.searchPlaceholder"),value:u,onValueChange:E,onKeyDown:Ti}),t.jsxs(Gs,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(_s,{children:y("gitView.branch.empty")}),h.length>0&&t.jsx(Zt,{heading:y("gitView.branch.localBranches"),children:h.map(Q=>t.jsx(Xt,{onSelect:()=>we(Q),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Q})},`local-${Q}`))}),h.length>0&&I.length>0?t.jsx(pa,{}):null,I.length>0&&t.jsx(Zt,{heading:y("gitView.branch.remoteBranches"),children:I.map(Q=>t.jsx(Xt,{onSelect:()=>we(Q),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Q})},`remote-${Q}`))})]})]})})]})]}),F?t.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:R==="merge"?t.jsxs(t.Fragment,{children:[y("gitView.branch.summaryMergePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:F})," ",y("gitView.branch.summaryMergeInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:$})]}):t.jsxs(t.Fragment,{children:[y("gitView.branch.summaryRebasePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:$})," ",y("gitView.branch.summaryRebaseInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:F})]})})}):null,C==="dialog"?t.jsxs(Es,{className:"gap-2 pt-1",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:ye,children:y("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:de,disabled:!F,className:"gap-1.5",children:R==="merge"?t.jsxs(t.Fragment,{children:[t.jsx(T,{name:"git-merge",className:"size-4"}),y("gitView.operation.merge")]}):t.jsxs(t.Fragment,{children:[t.jsx(T,{name:"git-branch",className:"size-4"}),y("gitView.operation.rebase")]})})]}):t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(W,{variant:"destructive",size:"sm",onClick:ye,disabled:G,children:y("gitView.common.reset")}),t.jsx("div",{className:"flex-1"}),t.jsx(W,{variant:"default",size:"sm",onClick:de,disabled:G||!F,children:y(R==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(C==="bare")return je;if(C==="inline"){let Q;e[38]!==y?(Q=y("gitView.branch.updateTitle"),e[38]=y,e[39]=Q):Q=e[39];let fe;e[40]!==Q?(fe=t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:Q}),e[40]=Q,e[41]=fe):fe=e[41];let Oe;e[42]!==y?(Oe=y("gitView.branch.updateDescriptionPrefix"),e[42]=y,e[43]=Oe):Oe=e[43];let et;e[44]!==$?(et=t.jsx("span",{className:"font-mono text-foreground",children:$}),e[44]=$,e[45]=et):et=e[45];let He;e[46]!==Oe||e[47]!==et?(He=t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Oe," ",et,"."]}),e[46]=Oe,e[47]=et,e[48]=He):He=e[48];let Ke;e[49]!==fe||e[50]!==He?(Ke=t.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:t.jsxs("div",{className:"space-y-1",children:[fe,He]})}),e[49]=fe,e[50]=He,e[51]=Ke):Ke=e[51];let We;e[52]!==je?(We=t.jsx("div",{className:"pt-3",children:je}),e[52]=je,e[53]=We):We=e[53];let pt;return e[54]!==Ke||e[55]!==We?(pt=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Ke,We]}),e[54]=Ke,e[55]=We,e[56]=pt):pt=e[56],pt}let be;e[57]!==S?(be=S?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"git-merge",className:"size-4"}),e[57]=S,e[58]=be):be=e[58];let Ce;e[59]!==y?(Ce=y("gitView.branch.mergeRebase"),e[59]=y,e[60]=Ce):Ce=e[60];let Ee;e[61]!==Ce?(Ee=t.jsx("span",{children:Ce}),e[61]=Ce,e[62]=Ee):Ee=e[62];let ee;e[63]!==re||e[64]!==G||e[65]!==be||e[66]!==Ee?(ee=t.jsx(ts,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"sm",className:"gap-1.5",onClick:re,disabled:G,children:[be,Ee]})}),e[63]=re,e[64]=G,e[65]=be,e[66]=Ee,e[67]=ee):ee=e[67];let he;e[68]!==y?(he=y("gitView.branch.mergeRebaseTooltip"),e[68]=y,e[69]=he):he=e[69];let Be;e[70]!==he?(Be=t.jsx(ss,{sideOffset:8,children:he}),e[70]=he,e[71]=Be):Be=e[71];let ge;e[72]!==ee||e[73]!==Be?(ge=t.jsxs(es,{children:[ee,Be]}),e[72]=ee,e[73]=Be,e[74]=ge):ge=e[74];let Ne;e[75]!==me||e[76]!==k?(Ne=Q=>{Q?k(!0):me()},e[75]=me,e[76]=k,e[77]=Ne):Ne=e[77];let Ie;e[78]!==y?(Ie=y("gitView.branch.updateTitle"),e[78]=y,e[79]=Ie):Ie=e[79];let Te;e[80]!==Ie?(Te=t.jsx(ft,{children:Ie}),e[80]=Ie,e[81]=Te):Te=e[81];let oe;e[82]!==H||e[83]!==S||e[84]!==R||e[85]!==Z||e[86]!==y||e[87]!==$?(oe=S?y(Z?H?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":R==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):t.jsxs(t.Fragment,{children:[y("gitView.branch.dialogDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:$}),"."]}),e[82]=H,e[83]=S,e[84]=R,e[85]=Z,e[86]=y,e[87]=$,e[88]=oe):oe=e[88];let Pe;e[89]!==oe?(Pe=t.jsx(bt,{children:oe}),e[89]=oe,e[90]=Pe):Pe=e[90];let Fe;e[91]!==Te||e[92]!==Pe?(Fe=t.jsxs(gt,{children:[Te,Pe]}),e[91]=Te,e[92]=Pe,e[93]=Fe):Fe=e[93];let De;e[94]!==je||e[95]!==Fe?(De=t.jsxs(ht,{className:"max-w-md",children:[Fe,je]}),e[94]=je,e[95]=Fe,e[96]=De):De=e[96];let Ue;e[97]!==D||e[98]!==Ne||e[99]!==De?(Ue=t.jsx(mt,{open:D,onOpenChange:Ne,children:De}),e[97]=D,e[98]=Ne,e[99]=De,e[100]=Ue):Ue=e[100];let Le;return e[101]!==ge||e[102]!==Ue?(Le=t.jsxs(t.Fragment,{children:[ge,Ue]}),e[101]=ge,e[102]=Ue,e[103]=Le):Le=e[103],Le};function Fi(o){return o.status==="done"||o.status==="error"}function Ri(o){return o.status==="error"}function Bi(o){return o.slice(o.indexOf("/")+1)}function Di(o){return[o]}function Mi(o){return[o]}function Ei(o,e){return t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("div",{className:"mt-0.5 shrink-0",children:[o.status==="running"&&t.jsx(T,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),o.status==="done"&&t.jsx(T,{name:"check",className:"size-3.5 text-success"}),o.status==="error"&&t.jsx(T,{name:"close",className:"size-3.5 text-destructive"}),o.status==="pending"&&t.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),t.jsx("span",{className:Se("typography-micro",o.status==="error"&&"text-destructive",o.status==="done"&&"text-muted-foreground",o.status==="running"&&"text-foreground",o.status==="pending"&&"text-muted-foreground/60"),children:o.message})]},e)}function Ti(o){return o.stopPropagation()}const Li=({runMutation:o,onMutationComplete:e,onMutationError:a,onPathsComplete:m,scheduleFlush:N})=>{const f=[];let p=!1;return{enqueue:g=>{const w=f[f.length-1];if(w?.directory===g.directory&&w.direction===g.direction){g.paths.forEach(M=>w.paths.add(M));return}f.push(g)},flush:()=>{if(p)return;const g=f.shift();if(!g)return;p=!0;const w={directory:g.directory,direction:g.direction,paths:Array.from(g.paths),rollback:g.rollback};(async()=>{try{await o(w),e(w)}catch(M){a(w,M)}finally{m(w.paths),p=!1,f.length>0&&N()}})()},clear:()=>{f.length=0},size:()=>f.length,isRunning:()=>p}},Oi=15e3,Ai=40,zi=20,Vr={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:"},Ir=(o,e)=>{const a=o.toLowerCase(),m=/^([a-z]+)(?:\(.*\))?!?:/,N=a.match(m);if(N){const x=N[1],g=Vr[x];if(g)return e.find(w=>w.code===g)||null}const f=a.split(" ")[0],p=Vr[f];return p&&e.find(x=>x.code===p)||null},Gi=20,yt=new Map,_i=(o,e)=>{if(yt.delete(o),yt.set(o,e),yt.size>Gi){const a=yt.keys().next().value;a!==void 0&&yt.delete(a)}},Xe=o=>(o||"").replace(/\\/g,"/").replace(/\/+$/,""),Pr=o=>{const e=o.index?.trim();return!!(e&&e!=="?")},$i=o=>{const e=o.working_dir?.trim(),a=o.index?.trim();return!!(e||a==="?")},oc=({isActive:o})=>{const{t:e}=nt(),{git:a}=xa(),m=wa(),[N,f]=l.useState(null),[p,x]=l.useState(null),g=rt(s=>s.currentSessionId),w=rt(s=>s.newSessionDraft),M=rt(s=>s.setDraftBootstrapPendingDirectory),v=rt(s=>s.worktreeMetadata),V=rt(s=>s.availableWorktrees),L=Xe(m),S=l.useMemo(()=>{if(!L)return;const s=V.find(n=>Xe(n.path)===L);if(s)return s;for(const n of v.values())if(Xe(n.path)===L)return n},[V,L,v]),z=l.useMemo(()=>{if(g)return v.get(g)??S;if(w?.open)return S},[g,S,w?.open,v]),{profiles:C,globalIdentity:y,defaultGitIdentityId:D,loadProfiles:k,loadGlobalIdentity:R,loadDefaultGitIdentityId:P}=Ga(pr(s=>({profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId}))),{rootIsGitRepo:F,gitDirectory:r,nestedRepos:Y}=ya(m??null,{enabled:o}),B=ba(r??null),u=va(r??null),E=ja(s=>g?s.getAttachment(g):void 0),se=E?Ca(E):[],U=E&&!E.degraded&&!E.legacy?E.worktreeRoot??void 0:void 0,G=Aa(m,z,u?.current??void 0),$=Na(r??null),Z=Sa(r??null),H=ka(r??null),le=Va(r??null),ae=Ia(r??null),{setActiveDirectory:ce,ensureAll:ie,fetchStatus:h,fetchBranches:d,fetchLog:I,setLogMaxCount:O,fetchIdentity:J,prefetchDiffs:ne,clearDiffCache:re,moveStatusPathsOptimistically:q,restoreStatus:we,bumpIndexRevision:K,ensureNestedRepos:de,selectNestedRepo:ke}=Pa(pr(s=>({setActiveDirectory:s.setActiveDirectory,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,ensureNestedRepos:s.ensureNestedRepos,selectNestedRepo:s.selectNestedRepo}))),ye=Rt(s=>s.isMobile),me=Rt(s=>s.openContextDiff),xe=Rt(s=>s.openContextSurface),Ve=u?.current??null,Re=Fa(s=>!r||!Ve?null:Ra(s.entries,r,Ve)),ue=Rt(s=>s.navigateToDiff),$e=l.useRef(null),Ae=l.useRef(null),je=l.useRef(null),be=l.useRef(!0);l.useEffect(()=>()=>{be.current=!1},[]);const Ce=l.useCallback(()=>{$e.current!==null&&(window.clearTimeout($e.current),$e.current=null)},[]),Ee=l.useCallback(s=>{Ce(),$e.current=window.setTimeout(()=>{$e.current=null,Xe(s)===Xe(r)&&h(s,a,{silent:!0})},Oi)},[Ce,r,h,a]);l.useEffect(()=>Ce,[Ce]);const ee=l.useCallback(()=>{Ae.current!==null&&(window.clearTimeout(Ae.current),Ae.current=null)},[]),he=l.useCallback(()=>{Ae.current===null&&(Ae.current=window.setTimeout(()=>{Ae.current=null,je.current?.()},0))},[]),Be=l.useCallback(async(s,n,i)=>{if(n==="stage"){if(a.stageGitFiles){await a.stageGitFiles(s,i);return}await Promise.all(i.map(c=>a.stageGitFile(s,c)));return}if(a.unstageGitFiles){await a.unstageGitFiles(s,i);return}await Promise.all(i.map(c=>a.unstageGitFile(s,c)))},[a]),ge=l.useMemo(()=>Li({runMutation:({directory:s,direction:n,paths:i})=>Be(s,n,i),onMutationComplete:({directory:s})=>{K(s),Ee(s)},onMutationError:({directory:s,direction:n,rollback:i},c)=>{i?.(),K(s),Ee(s);const j=e(n==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");b.error(c instanceof Error?c.message:j)},onPathsComplete:s=>{Js(n=>{const i=new Set(n);return s.forEach(c=>i.delete(c)),i})},scheduleFlush:he}),[K,Be,he,Ee,e]);l.useEffect(()=>(je.current=ge.flush,()=>{je.current=null}),[ge]),l.useEffect(()=>()=>ge.clear(),[ge]),l.useEffect(()=>ee,[ee]),l.useEffect(()=>{if(!o)return;if(!m){f(null);return}const s=Xe(m)??m;f({directory:s,status:null});let n=!1,i=null;const c=async()=>{try{const j=await Oa(m);if(n)return;f({directory:s,status:j.status}),j.status==="pending"&&(i=window.setTimeout(()=>{c()},500))}catch{n||f({directory:s,status:null})}};return c(),()=>{n=!0,i!==null&&window.clearTimeout(i)}},[o,m]);const Ne=Xe(w?.bootstrapPendingDirectory??null),Ie=!!(m&&Ne&&Ne===Xe(m)),Te=Ba(m??null),oe=Xe(m),Pe=N?.directory===oe?N.status:null,Fe=!!(m&&(Te||Pe==="pending"||Ie&&w?.pendingWorktreeRequestId)),De=!!(oe&&p?.directory===oe);l.useEffect(()=>{if(!oe)return;if(Pe==="failed"){M(null),x(n=>n?.directory===oe?null:n);return}if(Fe){x(n=>n?.directory===oe&&n.status==="refreshing"?n:{directory:oe,status:"refreshing"});return}if(p?.directory!==oe||p.status!=="refreshing"||!r||!a)return;let s=!1;return h(r,a,{force:!0,silent:!0,throwOnError:!0}).then(()=>{s||x(n=>n?.directory===oe?null:n)}).catch(()=>{s||x(n=>n?.directory===oe?{...n,status:"failed"}:n)}),()=>{s=!0}},[h,a,r,Fe,oe,Pe,p,M]);const Ue=Fe||De,Le=De&&p?.status==="failed",Q=l.useMemo(()=>r?yt.get(r)??null:null,[r]),fe=Da(s=>s.settingsGitmojiEnabled),[Oe,et]=l.useState(null),{gitmojis:He}=Xa(fe);l.useEffect(()=>{const s=U||G?.projectDirectory;if(!s){et(null);return}let n=!1;return Ma(s).then(i=>{if(n)return;const c=i.trim();et(c&&c!=="HEAD"?c:null)}).catch(()=>{n||et(null)}),()=>{n=!0}},[U,G?.projectDirectory]);const[Ke,We]=l.useState(Q?.commitMessage??""),[pt,Er]=l.useState([]),[Tr,rs]=l.useState(!1),$s=l.useRef(null),[Hs,Mt]=l.useState(null),[Lr,ns]=l.useState(!1),[Ws,Us]=l.useState(null),[Ye,Or]=l.useState(25),[Ar,Ks]=l.useState(!1),{triggerFireworks:zr}=za(),qs=l.useRef(new Map),Et=l.useRef(0),as=l.useCallback(()=>{Et.current+=1,be.current&&Ks(!0)},[]),is=l.useCallback(()=>{Et.current=Math.max(0,Et.current-1),be.current&&Et.current===0&&Ks(!1)},[]),[os,Tt]=l.useState(new Set),[Gr,Js]=l.useState(new Set),[ls,Ys]=l.useState(!1),[_r,$r]=l.useState(0),[Hr,Qs]=l.useState(!1),[cs,ds]=l.useState(Q?.generatedHighlights??[]),Wr=Gr.size>0||ge.size()>0||ge.isRunning(),Zs=l.useCallback(()=>{const s=$s.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),us=U||G?.projectDirectory||null,ms=u?.current||null,Ur=l.useMemo(()=>{const s=u?.tracking;return s?s.startsWith("origin/"):!0},[u?.tracking]),Xs=l.useMemo(()=>{const s=G?.createdFromBranch,n=typeof s=="string"?s.trim():"",i=typeof u?.current=="string"?u.current.trim():"",c=typeof Oe=="string"?Oe.trim():"";return n?n===i&&n.startsWith("opencode/")&&c.length>0&&c!==n?c:n:c||i||"HEAD"},[G?.createdFromBranch,u,Oe]),Lt=l.useCallback(()=>{ds([])},[]),[hs,Kr]=l.useState(new Set),[Ot,qr]=l.useState(new Map),[At,gs]=l.useState(new Set),fs=l.useRef(Ot),St=l.useRef(At),[Jr,vt]=l.useState(null),[xt,ps]=l.useState(null),[er,tr]=l.useState(""),[Me,zt]=l.useState(null),[Yr,sr]=l.useState(!1),[Qr,rr]=l.useState(!1),[xs,ws]=l.useState([]),[Zr,nr]=l.useState(null),[ar,ys]=l.useState(null),[Xr,Gt]=l.useState([]),[en,Qe]=l.useState(!1),[tn,tt]=l.useState([]),[_t,st]=l.useState("merge"),[sn,bs]=l.useState(null),[vs,ir]=l.useState(!1),[js,rn]=l.useState(100),[nn,an]=l.useState(0),Ze=l.useMemo(()=>g?`openchamber.conflict:${g}`:null,[g]),at=l.useCallback((s,n,i)=>{if(!Ze||typeof window>"u")return;const c={directory:s,conflictFiles:n,operation:i};window.localStorage.setItem(Ze,JSON.stringify(c))},[Ze]),qe=l.useCallback(()=>{!Ze||typeof window>"u"||window.localStorage.removeItem(Ze)},[Ze]);l.useEffect(()=>{if(!Ze||typeof window>"u"||!r)return;const s=window.localStorage.getItem(Ze);if(s)try{const n=JSON.parse(s);if(n.directory!==r){window.localStorage.removeItem(Ze);return}tt(n.conflictFiles??[]),st(n.operation??"merge"),Qe(!0)}catch{window.localStorage.removeItem(Ze)}},[Ze,r]);const[on,Cs]=l.useState(!1),[$t,kt]=l.useState(null),[Ns,or]=l.useState("merge"),[Ss,lr]=l.useState(""),ln=l.useCallback(s=>{Ea(s).then(n=>{if(n.ok){b.success(e("gitView.toast.commitHashCopied"));return}b.error(e("gitView.toast.copyFailed"))})},[e]),cn=l.useCallback(s=>{Kr(n=>{const i=new Set(n);return i.has(s)?i.delete(s):i.add(s),i})},[]);l.useEffect(()=>{fs.current=Ot},[Ot]),l.useEffect(()=>{St.current=At},[At]),l.useEffect(()=>{if(!r||!a)return;const s=Array.from(hs).filter(i=>!fs.current.has(i)&&!St.current.has(i));if(s.length===0)return;let n=!1;return gs(i=>{const c=new Set(i);for(const j of s)c.add(j);return St.current=c,c}),Promise.all(s.map(i=>a.getCommitFiles(r,i).then(c=>({hash:i,files:c.files})).catch(c=>(console.error("Failed to fetch commit files:",c),{hash:i,files:[]})))).then(i=>{n||(qr(c=>{const j=new Map(c);for(const{hash:A,files:X}of i)j.set(A,X);return fs.current=j,j}),gs(c=>{const j=new Set(c);for(const{hash:A}of i)j.delete(A);return St.current=j,j}))}),()=>{n=!0,gs(i=>{let c=!1;const j=new Set(i);for(const A of s)j.delete(A)&&(c=!0);return c?(St.current=j,j):i})}},[hs,r,a]),l.useEffect(()=>{if(!r)return;const s=yt.get(r)??null;We(s?.commitMessage??""),ds(s?.generatedHighlights??[])},[r]),l.useEffect(()=>{r&&_i(r,{directory:r,commitMessage:Ke,generatedHighlights:cs})},[Ke,r,cs]),l.useEffect(()=>{o&&(k(),R(),P())},[o,k,R,P]),l.useEffect(()=>{if(!o)return;if(!r||!a?.getRemoteUrl||B!==!0){ps(null);return}let s=!1;return a.getRemoteUrl(r).then(n=>{s||ps(n)}).catch(()=>{s||ps(null)}),()=>{s=!0}},[o,r,a,B]);const Ht=l.useCallback(async()=>{if(!r||!a?.getRemotes||B!==!0){ws([]);return}try{const s=await a.getRemotes(r);be.current&&ws(s)}catch{be.current&&ws([])}},[r,a,B]);l.useEffect(()=>{o&&Ht()},[o,Ht]),l.useEffect(()=>{o&&m&&r&&(ce(m),ie(r,a))},[o,m,r,ce,ie,a]),l.useEffect(()=>{if(o&&r)return Ta.onGitRefreshHint(s=>{Xe(s.directory)===Xe(r)&&(s.paths?.length&&re(r,s.paths),h(r,a,{silent:!0}))})},[o,re,r,h,a]);const te=l.useCallback(async(s=!0)=>{if(r)try{await Promise.all([h(r,a),d(r,a)])}catch(n){if(s){const i=n instanceof Error?n.message:e("gitView.toast.refreshRepositoryFailed");b.error(i)}}},[r,a,h,d,e]),pe=l.useCallback(async()=>{r&&await I(r,a,Ye)},[r,a,I,Ye]),ks=l.useCallback(async()=>{r&&await J(r,a)},[r,a,J]);l.useEffect(()=>{if(!o||!r||!a?.hasLocalIdentity||B!==!0)return;const s=typeof D=="string"?D.trim():"";if(!s||s==="global"||qs.current.get(r)===s)return;let i=!1;return(async()=>{try{const j=await a.hasLocalIdentity?.(r);if(i||j===!0)return;as(),await a.setGitIdentity(r,s),qs.current.set(r,s),await ks()}catch(j){console.warn("Failed to auto-apply default git identity:",j)}finally{i||is()}})(),()=>{i=!0}},[o,as,r,D,is,a,B,ks]);const it=l.useMemo(()=>u?[...u.files??[]].sort((n,i)=>n.path.localeCompare(i.path)):[],[u]),Je=l.useMemo(()=>it.filter(Pr),[it]),Vs=l.useMemo(()=>it.filter($i),[it]);l.useEffect(()=>{if(!o||!r||it.length===0)return;const s=[],n=new Set,i=j=>{!j||n.has(j)||(n.add(j),s.push(j))};if(Je.forEach(j=>i(j.path)),pt.forEach(i),it.slice(0,zi).forEach(j=>i(j.path)),s.length===0)return;const c=window.setTimeout(()=>{ne(r,a,s,{maxFiles:Ai})},120);return()=>{window.clearTimeout(c)}},[o,it,r,a,ne,Je,pt]);const cr=s=>s?.pushed[0]?.remote||u?.tracking?.split("/")[0]||ze.find(n=>n.name==="origin")?.name||ze[0]?.name||"origin",dr=async(s,n)=>{if(r){Mt(s);try{const i=c=>{const j=`${c.name}/`,A=u?.tracking?.startsWith(j)?u.tracking.slice(j.length):void 0;return{remote:c.name,branch:A,rebase:!0}};if(s==="fetch"){if(!n)throw new Error("No remote available for fetch");await a.gitFetch(r,{remote:n.name}),b.success(e("gitView.toast.fetchedFromRemote",{name:n.name}))}else if(s==="pull"){if(!n)throw new Error("No remote available for pull");const c=await a.gitPull(r,i(n));b.success(c.files.length===1?e("gitView.toast.pulledFilesSingle",{count:c.files.length,name:n.name}):e("gitView.toast.pulledFilesPlural",{count:c.files.length,name:n.name}))}else if(s==="push"){const c=await a.gitPush(r);b.success(e("gitView.toast.pushedToUpstream",{name:cr(c)}))}else if(s==="sync"){if(!n)throw new Error("No remote available for sync");let c=0,j=!1;await a.gitFetch(r,{remote:n.name});const A=await a.getGitStatus(r);if((A.behind??0)>0){if((A.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync"));return}c=(await a.gitPull(r,i(n))).files.length}((await a.getGitStatus(r)).ahead??0)>0&&(await a.gitPush(r),j=!0),c>0&&j?b.success(c===1?e("gitView.toast.syncedPulledSingleAndPushed",{count:c,name:n.name}):e("gitView.toast.syncedPulledPluralAndPushed",{count:c,name:n.name})):c>0?b.success(c===1?e("gitView.toast.pulledFilesSingle",{count:c,name:n.name}):e("gitView.toast.pulledFilesPlural",{count:c,name:n.name})):j?b.success(e("gitView.toast.pushedToUpstream",{name:n.name})):b.success(e("gitView.toast.alreadyUpToDate"))}await te(!1),await pe()}catch(i){const c=i instanceof Error?i.message:e("gitView.toast.syncActionFailed",{action:s==="sync"?e("gitView.sync.syncChanges"):s==="pull"?e("gitView.sync.pull"):s});b.error(c)}finally{Mt(null)}}},dn=l.useCallback(async s=>{if(!r)return;const n=s.name.trim();if(!n){b.error(e("gitView.toast.remoteNameRequired"));return}if(n==="origin"){b.error(e("gitView.toast.cannotRemoveOriginRemote"));return}nr(n);try{await a.removeRemote(r,{remote:n}),b.success(e("gitView.toast.removedRemote",{name:n})),await Promise.all([te(!1),Ht()])}catch(i){const c=i instanceof Error?i.message:`Failed to remove ${n}`;b.error(c)}finally{nr(null)}},[r,a,Ht,te,e]),ur=async(s={})=>{if(!r)return;if(!Ke.trim()){b.error(e("gitView.toast.enterCommitMessage"));return}const n=Je.map(c=>c.path).sort();if(n.length===0){b.error(e("gitView.toast.stageFileToCommit"));return}const i=s.pushAfter?"commitAndPush":"commit";Us(i);try{if(await a.createGitCommit(r,Ke.trim(),{files:n,stageFiles:[]}),K(r),b.success(e("gitView.toast.commitCreated")),We(""),Lt(),await te(),s.pushAfter){const c=u?.tracking?.split("/")[0],j=ze.find(Gn=>Gn.name===c)??ze[0];if(!j)throw new Error(e("mobile.changes.noRemote"));Mt("sync");const A=`${j.name}/`,X=u?.tracking?.startsWith(A)?u.tracking.slice(A.length):void 0;await a.gitFetch(r,{remote:j.name});const _=await a.getGitStatus(r);if((_.behind??0)>0){if((_.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync")),await te(!1);return}await a.gitPull(r,{remote:j.name,branch:X,rebase:!0})}const _e=await a.getGitStatus(r);let jt;(_e.ahead??0)>0&&(jt=await a.gitPush(r)),b.success(e("gitView.toast.pushedToUpstream",{name:cr(jt)})),zr(),await te(!1)}else await te(!1);await pe(),$r(c=>c+1)}catch(c){const j=c instanceof Error?c.message:e("gitView.toast.createCommitFailed");b.error(j)}finally{Us(null),s.pushAfter&&Mt(null)}},un=l.useCallback(async()=>{if(!r)return;const s=Je.map(n=>n.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}),Qs(!0);try{const{message:n}=await fr(r,s),i=n.subject?.trim()??"",c=Array.isArray(n.highlights)?n.highlights:[];if(i){let j=i;if(fe&&He.length>0){const A=Ir(i,He);if(A){const{code:X,emoji:_}=A;!i.startsWith(X)&&!i.startsWith(_)&&(j=`${X} ${i}`)}}We(j)}ds(c),Zs()}catch(n){console.error("[git-generation][browser] GitView generate handler failed",{message:n instanceof Error?n.message:String(n),error:n});const i=n instanceof Error?n.message:e("gitView.toast.generateCommitMessageFailed");b.error(i)}finally{Qs(!1)}},[r,Je,fe,He,Zs,e]),Is=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",mn=async(s,n)=>{if(!r||!u)return;const i=Bs(E);if(i.length>0){b.error(e("gitView.toast.cannotCreateBranch",{reason:Is(i[0])}));return}const c=u.current??null,j=n?.name??"origin";try{await a.createBranch(r,s,c??"HEAD"),b.success(e("gitView.toast.createdBranch",{name:s})),await a.checkoutBranch(r,s);let A=!1;try{await a.gitPush(r,{remote:j,branch:s,options:["--set-upstream"]}),A=!0}catch(X){const _=X instanceof Error?X.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: ",_]})})}await te(),await pe(),A&&b.success(e("gitView.toast.upstreamSet",{branch:s,remote:j}))}catch(A){const X=A instanceof Error?A.message:e("gitView.toast.createBranchFailed");throw b.error(X),A}},hn=async(s,n)=>{if(!r)return;const i=Bs(E);if(i.length>0){b.error(e("gitView.toast.cannotRenameBranch",{reason:Is(i[0])}));return}try{await a.renameBranch(r,s,n),b.success(e("gitView.toast.renamedBranch",{oldName:s,newName:n})),await te(),await pe()}catch(c){const j=c instanceof Error?c.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:n});b.error(j)}},gn=async s=>{if(!r)return;const n=Bs(E);if(n.length>0){b.error(e("gitView.toast.cannotCheckout",{reason:Is(n[0])}));return}const i=s.replace(/^remotes\//,"");if(u?.current!==i){if((u?.files?.length??0)>0){kt(i);return}await Ps(i)}},Ps=async s=>{if(!r)return;const n=s;try{const i=await a.checkoutBranch(r,n);b.success(e("gitView.toast.checkedOut",{name:i?.branch||n})),await te(),await pe()}catch(i){const c=i instanceof Error?i.message:e("gitView.toast.checkoutFailed",{name:n});b.error(c)}},fn=async s=>{if(r){as();try{await a.setGitIdentity(r,s.id),b.success(e("gitView.toast.appliedIdentity",{name:s.name})),await ks()}catch(n){const i=n instanceof Error?n.message:e("gitView.toast.applyIdentityFailed");b.error(i)}finally{is()}}},Vt=l.useMemo(()=>$?.all?$.all.filter(s=>!s.startsWith("remotes/")).sort():[],[$]),ot=l.useMemo(()=>$?.all?$.all.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],[$]),ze=l.useMemo(()=>{if(xs.length>0)return xs;const s=new Set,n=u?.tracking?.trim();n&&n.includes("/")&&s.add(n.split("/")[0]);for(const i of ot){const c=i.indexOf("/");c>0&&s.add(i.slice(0,c))}return s.size===0&&xt&&s.add("origin"),Array.from(s).map(i=>({name:i,fetchUrl:xt??"",pushUrl:xt??""}))},[xs,ot,xt,u?.tracking]),lt=u?.current??null,mr=l.useMemo(()=>{const s=u?.tracking?.trim().split("/")[0];return(s&&$?.defaultBranches?.[s])??$?.defaultBranches?.origin},[$,u?.tracking]),wt=l.useMemo(()=>_a({remoteNames:new Set(ze.map(s=>s.name)),localBranches:Vt,worktreeCreatedFromBranch:G?.createdFromBranch,rootBranchHint:Oe,defaultBranch:mr,headBranch:lt}),[lt,mr,ze,Vt,Oe,G?.createdFromBranch]),pn=l.useMemo(()=>ze.map(i=>i.name).map(i=>`${i}/${wt}`).find(i=>ot.includes(i))??wt,[wt,ze,ot]),xn=l.useMemo(()=>{const s=new Map;y&&s.set(y.id,y);let n=null;if(xt)try{let i=xt.trim();i.startsWith("git@")&&(i=`https://${i.slice(4).replace(":","/")}`),i.endsWith(".git")&&(i=i.slice(0,-4));const c=new URL(i);n=c.hostname+c.pathname}catch{}for(const i of C){if(i.authType!=="token"){s.set(i.id,i);continue}const c=i.host;if(!c){s.set(i.id,i);continue}if(!c.includes("/")){s.set(i.id,i);continue}n&&n===c&&s.set(i.id,i)}return Array.from(s.values())},[C,y,xt]),wn=l.useMemo(()=>{if(H?.userName&&H?.userEmail){const s=C.find(n=>n.userName===H.userName&&n.userEmail===H.userEmail);return s||(y&&y.userName===H.userName&&y.userEmail===H.userEmail?y:{id:"local-config",name:H.userName,userName:H.userName,userEmail:H.userEmail,sshKey:H.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return y??null},[H,C,y]),yn=Je.length,bn=le||Hs!==null||Ws!==null,vn=!!(G&&us&&ms&&Ur),hr=!!lt,ct=vn&&us&&ms&&G?{repoRoot:us,sourceBranch:ms,worktreeMetadata:G}:null;l.useEffect(()=>{if(!r||!a||!Z?.all?.length||!lt||!wt||lt===wt){vt(null);return}let s=!1;return(async()=>{try{const i=await a.getGitLog(r,{from:wt,to:"HEAD",maxCount:Ye});if(s)return;const c=new Set((i?.all??[]).map(A=>A.hash).filter(A=>typeof A=="string"&&A.length>0));if(c.size===0){vt(null);return}const j=Z.all.findIndex(A=>!c.has(A.hash));if(j===0){vt(null);return}if(j===-1){vt({insertBeforeIndex:Z.all.length,branchName:lt,direction:"up"});return}vt({insertBeforeIndex:j,branchName:lt,direction:"up"})}catch{s||vt(null)}})(),()=>{s=!0}},[wt,lt,r,a,Z,Ye]),l.useEffect(()=>{bs(null)},[r]),l.useEffect(()=>{if(Me!=="graph"||!r){Me!=="graph"&&bs(null);return}let s=!1;return ir(!0),a.getGitLog(r,{maxCount:js,all:!0}).then(n=>{s||bs(n)}).catch(n=>{console.error("Failed to fetch graph log:",n)}).finally(()=>{s||ir(!1)}),()=>{s=!0}},[Me,r,js,nn,a]);const It=l.useCallback((s,n)=>{if(!r||s.length===0)return;const i=Array.from(new Set(s));Js(j=>{const A=new Set(j);return i.forEach(X=>A.add(X)),A});const c=q(r,i,n);ge.enqueue({directory:r,direction:n,paths:new Set(i),rollback:()=>we(r,c)}),he()},[r,ge,q,we,he]),Fs=l.useCallback(async s=>{if(r){Tt(n=>{const i=new Set(n);return i.add(s),i});try{await a.revertGitFile(r,s,{scope:"working"}),b.success(e("gitView.toast.revertedFile",{path:s})),await te(!1)}catch(n){const i=n instanceof Error?n.message:e("gitView.toast.revertFailed");b.error(i)}finally{Tt(n=>{const i=new Set(n);return i.delete(s),i})}}},[r,te,a,e]),Pt=l.useCallback(async(s,n,i="all")=>{if(!r||s.length===0)return;const c=Array.from(new Set(s));if(ls||c.some(_=>os.has(_)))return;const j=new Set(Je.map(_=>_.path)),A=i==="all"&&c.some(_=>j.has(_));n&&Ys(!0),Tt(_=>{const _e=new Set(_);return c.forEach(jt=>_e.add(jt)),_e});const X=[];try{if(await Promise.all(c.map(async _=>{try{await a.revertGitFile(r,_,{scope:i})}catch(_e){X.push({path:_,message:_e instanceof Error?_e.message:e("gitView.toast.revertFailed")})}})),A&&X.length<c.length&&K(r),await te(!1),X.length===0)b.success(c.length===1?e("gitView.toast.revertedFilesSingle",{count:c.length}):e("gitView.toast.revertedFilesPlural",{count:c.length}));else if(X.length===c.length)b.error(X[0]?.message||e("gitView.toast.revertFailed"));else{const _=c.length-X.length;b.warning(_===1?e("gitView.toast.revertedSomeSingle",{success:_,failed:X.length}):e("gitView.toast.revertedSomePlural",{success:_,failed:X.length}))}}finally{Tt(_=>{const _e=new Set(_);return c.forEach(jt=>_e.delete(jt)),_e}),n&&Ys(!1)}},[K,r,a,ls,te,os,Je,e]),jn=l.useCallback(async s=>{await Pt(s,!0)},[Pt]),Cn=l.useCallback(async s=>{await Pt(s,!1,"working")},[Pt]),Rs=l.useCallback((s,n)=>{if(m&&!ye){me(m,s,n);return}ue(s,n)},[m,ye,ue,me]),Nn=l.useCallback(()=>ns(!0),[]),Sn=l.useMemo(()=>{const s=[];return Je.length>0&&s.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:Je,actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:n=>e("gitView.changes.unstageFileAria",{path:n}),onActionFile:n=>{It([n],"unstage")},onActionAll:n=>{It(n,"unstage")},onViewDiff:n=>Rs(n,!0),onRevertFile:Fs,showRevertActions:!1,accent:!0}),Vs.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:Vs,actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:n=>e("gitView.changes.stageFileAria",{path:n}),onActionFile:n=>{It([n],"stage")},onActionAll:n=>{It(n,"stage")},onViewDiff:n=>Rs(n,!1),onRevertFile:Fs}),s},[Fs,Rs,It,Je,e,Vs]),kn=l.useCallback(s=>{if(s.length===0)return;const n=s.map(i=>i.trim()).filter(Boolean);if(n.length===0){Lt();return}We(i=>{const c=i.trim(),j=c.length>0?`
|
|
4
|
+
|
|
5
|
+
`:"";return`${c}${j}${n.join(`
|
|
6
|
+
`)}`.trim()}),Lt()},[Lt]),Vn=l.useCallback((s,n)=>{const i=n||s;We(c=>{const j=c.trimStart();return j.startsWith(s)||n&&j.startsWith(n)?c:`${i.endsWith(" ")?i:`${i} `}${c}`.trimStart()}),tr(""),rs(!1)},[]),Wt=l.useCallback(s=>{const n=s instanceof Error?s.message.toLowerCase():"";return n.includes("uncommitted changes")||n.includes("local changes")||n.includes("your local changes would be overwritten")||n.includes("please commit your changes or stash them")||n.includes("cannot rebase: you have unstaged changes")||n.includes("error: cannot pull with rebase")},[]),dt=l.useCallback((s,n)=>{Gt(i=>[...i,{message:s,status:n,timestamp:Date.now()}])},[]),Ge=l.useCallback((s,n)=>{Gt(i=>{if(i.length===0)return i;const c=[...i];return c[c.length-1]={...c[c.length-1],status:s,...n?{message:n}:{}},c})},[]),Ut=l.useCallback(()=>{Gt([])},[]),In=l.useCallback(()=>{Gt([]),ys(null)},[]),Kt=l.useCallback(s=>{const n=s.trim(),i=new Set(ze.map(j=>j.name)),c=n.indexOf("/");if(c>0){const j=n.slice(0,c),A=n.slice(c+1);if(i.has(j)&&A)return{branch:n,remote:j,remoteBranch:A}}for(const j of ze){const A=`${j.name}/${n}`;if(ot.includes(A))return{branch:A,remote:j.name,remoteBranch:n}}return{branch:n,remote:null,remoteBranch:null}},[ze,ot]),Pn=l.useCallback(async s=>{if(!r)return;ys("merge"),Ut();const n=u?.current,i=Kt(s);try{i.remote&&i.remoteBranch&&(dt(`Fetching ${i.remote}/${i.remoteBranch}...`,"running"),await a.gitFetch(r,{remote:i.remote,branch:i.remoteBranch}),Ge("done",`Fetched ${i.remote}/${i.remoteBranch}`)),dt(`Merging ${i.branch} into ${n}...`,"running");const c=await a.merge(r,{branch:i.branch});c.conflict?(Ge("error","Merge conflicts detected"),tt(c.conflictFiles??[]),st("merge"),Qe(!0),at(r,c.conflictFiles??[],"merge")):(Ge("done",`Merged ${i.branch} into ${n}`),qe(),dt("Refreshing repository status...","running"),await te(),await pe(),Ge("done","Repository status updated"))}catch(c){if(Wt(c))Ge("error","Uncommitted changes detected"),or("merge"),lr(i.branch),Cs(!0);else{const j=c instanceof Error?c.message:`Failed to merge ${i.branch}`;Ge("error",j)}}},[r,a,u,Kt,te,pe,Wt,at,qe,dt,Ge,Ut]),Fn=l.useCallback(async s=>{if(!r)return;ys("rebase"),Ut();const n=u?.current,i=Kt(s);try{i.remote&&i.remoteBranch&&(dt(`Fetching ${i.remote}/${i.remoteBranch}...`,"running"),await a.gitFetch(r,{remote:i.remote,branch:i.remoteBranch}),Ge("done",`Fetched ${i.remote}/${i.remoteBranch}`)),dt(`Rebasing ${n} onto ${i.branch}...`,"running");const c=await a.rebase(r,{onto:i.branch});c.conflict?(Ge("error","Rebase conflicts detected"),tt(c.conflictFiles??[]),st("rebase"),Qe(!0),at(r,c.conflictFiles??[],"rebase")):(Ge("done",`Rebased ${n} onto ${i.branch}`),qe(),dt("Refreshing repository status...","running"),await te(),await pe(),Ge("done","Repository status updated"))}catch(c){if(Wt(c))Ge("error","Uncommitted changes detected"),or("rebase"),lr(i.branch),Cs(!0);else{const j=c instanceof Error?c.message:`Failed to rebase onto ${i.branch}`;Ge("error",j)}}},[r,a,u,Kt,te,pe,Wt,at,qe,dt,Ge,Ut]),Rn=l.useCallback(async()=>{if(r)try{_t==="merge"?(await a.abortMerge(r),b.success(e("gitView.toast.mergeAborted"))):(await a.abortRebase(r),b.success(e("gitView.toast.rebaseAborted"))),qe(),await te(),await pe()}catch(s){const n=s instanceof Error?s.message:`Failed to abort ${_t}`;b.error(n)}},[r,a,_t,te,pe,qe,e]),Bn=l.useMemo(()=>u?.files?u.files.filter(s=>s.index==="U"||s.working_dir==="U"||s.index==="A"&&s.working_dir==="A"||s.index==="D"&&s.working_dir==="D").length:0,[u?.files]),Dn=l.useCallback(async()=>{if(r)try{const s=!!u?.mergeInProgress?.head,n=!!(u?.rebaseInProgress?.headName||u?.rebaseInProgress?.onto);if(s){const i=await a.continueMerge(r);i.conflict?(tt(i.conflictFiles??[]),st("merge"),Qe(!0),at(r,i.conflictFiles??[],"merge"),b.error(e("gitView.toast.mergeConflictsDetected"))):(qe(),b.success(e("gitView.toast.mergeCompleted")),await te(),await pe())}else if(n){const i=await a.continueRebase(r);i.conflict?(tt(i.conflictFiles??[]),st("rebase"),Qe(!0),at(r,i.conflictFiles??[],"rebase"),b.error(e("gitView.toast.rebaseConflictsDetected"))):(qe(),b.success(e("gitView.toast.rebaseStepCompleted")),await te(),await pe())}}catch(s){const n=s instanceof Error?s.message:e("gitView.toast.continueOperationFailed");b.error(n)}},[r,a,u,te,pe,at,qe,e]),Mn=l.useCallback(async()=>{if(r)try{!!u?.mergeInProgress?.head?(await a.abortMerge(r),b.success(e("gitView.toast.mergeAborted"))):(await a.abortRebase(r),b.success(e("gitView.toast.rebaseAborted"))),qe(),await te(),await pe()}catch(s){const n=s instanceof Error?s.message:e("gitView.toast.abortOperationFailed");b.error(n)}},[r,a,u,te,pe,qe,e]),En=l.useCallback(()=>{if(!r)return;const n=!!u?.mergeInProgress?.head?"merge":"rebase",i=u?.files?.filter(c=>c.index==="U"||c.working_dir==="U").map(c=>c.path)??[];i.length>0&&tt(i),st(n),Qe(!0)},[r,u]),Tn=l.useCallback(async s=>{if(!r)return;const n=u?.current,i=Ns,c=Ss,j=(u?.files??[]).some(Pr);try{await a.stash(r,{message:`Auto-stash before ${i} with ${c}`,includeUntracked:!0}),j&&K(r)}catch(_){const _e=_ instanceof Error?_.message:"Failed to stash changes";b.error(_e);return}let A=!1,X=!1;try{if(i==="merge"){const _=await a.merge(r,{branch:c});_.conflict?(X=!0,tt(_.conflictFiles??[]),st("merge"),Qe(!0)):(A=!0,b.success(e("gitView.toast.mergedIntoBranch",{branch:c,currentBranch:n||""})))}else{const _=await a.rebase(r,{onto:c});_.conflict?(X=!0,tt(_.conflictFiles??[]),st("rebase"),Qe(!0)):(A=!0,b.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:n||"",branch:c})))}if(s&&A)try{await a.stashPop(r),K(r),b.success(e("gitView.toast.stashedRestored"))}catch(_){const _e=_ instanceof Error?_.message:e("gitView.toast.restoreStashFailed");b.error(_e)}else s&&X&&b.info(e("gitView.toast.restoreStashManually"));await te(),await pe()}catch(_){if(s)try{await a.stashPop(r),K(r)}catch{}throw _}},[K,r,a,u,Ns,Ss,te,pe,e]),Ln=l.useCallback(s=>{Or(s),r&&(O(r,s),I(r,a,s))},[r,I,a,O]),On=l.useCallback(s=>{rn(s)},[]),An=l.useCallback(()=>{zt(null),r&&(h(r,a),d(r,a),I(r,a,Ye))},[r,h,d,I,Ye,a]),zn=l.useCallback(s=>{if(s.conflict){if(s.operation==="cherry-pick"||s.operation==="revert"){b.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:s.conflictFiles?.join(", ")??"unknown files"})}),r&&(h(r,a),d(r,a),I(r,a,Ye));return}tt(s.conflictFiles??[]),st(s.operation),Qe(!0),r&&at(r,s.conflictFiles??[],s.operation)}},[e,tt,st,Qe,at,r,h,d,I,Ye,a]);return m?Ue?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[Le?null:t.jsx(T,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e(Le?"gitView.toast.refreshRepositoryFailed":"gitView.empty.worktreeSetupInProgress")}),Le?t.jsx(W,{type:"button",variant:"outline",size:"sm",className:"mt-3",onClick:()=>{oe&&x({directory:oe,status:"refreshing"})},children:e("gitView.empty.retryDiscovery")}):t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):B===null||B===!0&&!u?t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):B===!1?t.jsx($a,{rootIsGitRepo:F,resolvedIsGitRepo:B,nestedRepos:Y,onRetryDiscovery:()=>{m&&de(m,{force:!0})},emptyStateFooter:se.includes("open-without-worktree-features")?t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:e("gitView.empty.worktreeFeaturesUnavailable")}):void 0}):t.jsxs("div",{className:Se("flex h-full flex-col overflow-hidden"),children:[t.jsx(Ha,{directory:r??"",status:u,localBranches:Vt,remoteBranches:ot,branchInfo:$?.branches,syncAction:Hs,remotes:ze,onFetch:s=>dr("fetch",s),onSync:s=>dr("sync",s),onRemoveRemote:dn,removingRemoteName:Zr,onCheckoutBranch:gn,onCreateBranch:mn,onRenameBranch:hn,activeIdentityProfile:wn,availableIdentities:xn,onSelectIdentity:fn,isApplyingIdentity:Ar,isWorktreeMode:!!G,onOpenHistory:()=>zt("history"),onOpenGraph:()=>zt("graph"),onOpenStashes:Nn,onOpenUpdateBranch:hr?()=>sr(!0):void 0,onOpenReintegrateCommits:ct?()=>rr(!0):void 0,pullRequest:Re?.pr??null,prChecks:Re?.checks??null,onOpenPullRequest:r?()=>xe(r,"pr"):void 0,repositoryOptions:r!==m&&Array.isArray(Y)?Y:void 0,selectedRepository:r!==m?r:null,onSelectRepository:r!==m&&m?s=>ke(m,s):void 0,repositoryRoot:r!==m?m:void 0}),m&&(u?.mergeInProgress?.head||u?.rebaseInProgress?.headName||u?.rebaseInProgress?.onto)&&t.jsx(Ii,{mergeInProgress:u?.mergeInProgress,rebaseInProgress:u?.rebaseInProgress,onContinue:Dn,onAbort:Mn,onResolveWithAI:En,conflictCount:Bn,isLoading:le}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:t.jsx("div",{className:"h-full min-h-0 flex flex-col",children:t.jsx("div",{className:Se("min-w-0 min-h-0 h-full flex flex-col"),children:t.jsx(Rr,{as:La,ref:$s,outerClassName:"flex-1 min-h-0",className:Se("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:t.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(it?.length??0)>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Ua,{groups:Sn,diffStats:u?.diffStats,revertingPaths:os,isRevertingAll:ls,onVisiblePathsChange:Er,onRevertAll:jn,onRevertDirectory:Cn,headerBackgroundClassName:"bg-background"})}),t.jsx(Ka,{stagedCount:yn,commitMessage:Ke,onCommitMessageChange:We,generatedHighlights:cs,onInsertHighlights:kn,onGenerateMessage:un,isGeneratingMessage:Hr,onCommit:()=>ur({pushAfter:!1}),onCommitAndPush:()=>ur({pushAfter:!0}),commitAction:Ws,hasPendingIndexMutation:Wr,gitmojiEnabled:fe,onOpenGitmojiPicker:()=>rs(!0)})]}):t.jsx(oi,{onOpenStashes:()=>ns(!0)})})})})})}),t.jsx(mt,{open:Yr,onOpenChange:s=>{!s&&ar!==null||sr(s)},children:t.jsxs(ht,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(gt,{children:[t.jsx(ft,{children:e("gitView.branch.updateTitle")}),t.jsxs(bt,{children:[e("gitView.branch.updateDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:u?.current??""}),"."]})]}),hr?t.jsx(Pi,{mode:"bare",currentBranch:u?.current,localBranches:Vt,remoteBranches:ot,defaultTargetBranch:pn,onMerge:Pn,onRebase:Fn,disabled:bn,isOperating:ar!==null,operationLogs:Xr,onOperationComplete:In}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})]})}),t.jsx(mt,{open:Qr,onOpenChange:rr,children:t.jsxs(ht,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(gt,{children:[t.jsx(ft,{children:e("gitView.integrate.title")}),t.jsx(bt,{children:ct?t.jsxs("span",{className:"font-mono text-foreground",children:[ct.sourceBranch," → ",Xs]}):null})]}),ct?t.jsx(ai,{repoRoot:ct.repoRoot,sourceBranch:ct.sourceBranch,worktreeMetadata:ct.worktreeMetadata,localBranches:Vt,defaultTargetBranch:Xs,refreshKey:_r,showHeader:!1,onRefresh:()=>{r&&(h(r,a),d(r,a),I(r,a,Ye))}},ct.worktreeMetadata.path):null]})}),t.jsx(mt,{open:Me!==null,onOpenChange:s=>{s||zt(null)},children:t.jsxs(ht,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[t.jsxs(gt,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx(ft,{children:e(Me==="graph"?"gitView.graph.title":"gitView.history.title")}),t.jsxs(W,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:()=>{if(Me==="graph"){an(s=>s+1);return}r&&I(r,a,Ye)},disabled:Me==="graph"?vs:ae,title:e("gitView.history.refresh"),"aria-label":e("gitView.history.refresh"),children:[t.jsx(T,{name:"refresh",className:Se("size-4",(Me==="graph"?vs:ae)&&"animate-spin")}),e("gitView.history.refresh")]})]}),t.jsx(bt,{children:e("gitView.history.dialogDescription")})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(pi,{mode:Me==="graph"?"graph":"history",log:Me==="graph"?sn??Z:Z,isLogLoading:Me==="graph"&&vs||ae,logMaxCount:Me==="graph"?js:Ye,onLogMaxCountChange:Me==="graph"?On:Ln,expandedCommitHashes:hs,onToggleCommit:cn,commitFilesMap:Ot,loadingCommitHashes:At,onCopyHash:ln,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Me==="graph"?null:Jr,onConflict:Me==="graph"?zn:void 0,onActionSuccess:Me==="graph"?An:void 0})})]})}),t.jsx(ii,{open:Lr,onOpenChange:ns,directory:r,hasUncommittedChanges:(u?.files?.length??0)>0,hasStagedChanges:Je.length>0,uncommittedFileCount:u?.files?.length??0,onChanged:async s=>{r&&s?.affectsIndex&&K(r),await te(!1),await pe()}}),t.jsx(mt,{open:Tr,onOpenChange:rs,children:t.jsxs(ht,{className:"max-w-md p-0 overflow-hidden",children:[t.jsx(gt,{className:"px-4 pt-4",children:t.jsx(ft,{children:e("gitView.gitmoji.title")})}),t.jsxs(As,{className:"h-[420px]",shouldFilter:!1,children:[t.jsx(zs,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:er,onValueChange:tr}),t.jsxs(Gs,{children:[t.jsx(_s,{children:e("gitView.gitmoji.empty")}),t.jsx(Zt,{children:Dt(He,er,s=>[s.code,s.description,s.emoji]).map(s=>t.jsxs(Xt,{onSelect:()=>Vn(s.emoji,s.code),children:[t.jsx("span",{className:"text-lg",children:s.emoji}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s.code}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s.description})]},s.code))})]})]})]})}),r&&t.jsx(vi,{open:en,onOpenChange:Qe,conflictFiles:tn,directory:r,operation:_t,onAbort:Rn,onClearState:qe}),t.jsx(qa,{open:$t!==null,onOpenChange:s=>{s||kt(null)},targetBranch:$t??"",changedFileCount:u?.files?.length??0,onCommitAndSwitch:async(s,n)=>{const i=$t;if(!i||!r)return;const c=u?.current??null;await a.createGitCommit(r,s,{addAll:!0}),K(r);let j=null;if(n){const A=u?.tracking?.split("/")[0],X=ze.find(_=>_.name===A)??ze[0];try{if(!X)throw new Error(e("mobile.changes.noRemote"));await a.gitPush(r,u?.tracking?{remote:X.name}:{remote:X.name,branch:c??void 0,options:["--set-upstream"]}),j=X.name}catch(_){console.error("Push after commit failed:",_),b.error(e("gitView.dirtySwitch.pushFailed")),await te(),await pe(),kt(null);return}}b.success(j?e("gitView.toast.pushedToUpstream",{name:j}):c?e("gitView.dirtySwitch.committedNotPushed",{branch:c}):e("gitView.toast.commitCreated")),await te(),await pe(),kt(null),await Ps(i)},onGenerateMessage:async()=>{if(!r)return"";const s=(u?.files??[]).map(c=>c.path).sort(),{message:n}=await fr(r,s),i=n.subject?.trim()??"";if(i&&fe&&He.length>0){const c=Ir(i,He);if(c&&!i.startsWith(c.code)&&!i.startsWith(c.emoji))return`${c.code} ${i}`}return i},onRevertAndSwitch:async()=>{const s=$t;if(!s||!r)return;const n=(u?.files??[]).map(c=>c.path);await Pt(n,!0,"all");const i=await a.getGitStatus(r);if(!i.isClean&&(i.files?.length??0)>0){b.error(e("gitView.dirtySwitch.revertIncomplete"));return}kt(null),await Ps(s)}}),t.jsx(Vi,{open:on,onOpenChange:Cs,operation:Ns,targetBranch:Ss,onConfirm:Tn})]}):t.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:e("gitView.empty.selectSessionOrDirectory")})})};export{oc as GitView};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{f as Jt,R as T,j as te}from"./vendor-react-BUCujlKS.js";import{i8 as _e,i9 as Je,ia as ve,ib as Mn,ic as Nn,id as Un,ie as Dn,ig as jn,ih as Ln,ii as Hn,ij as Bn,ik as Fn,il as $n,im as Rt,io as qn,ip as Xn,iq as Jn,ir as zn,is as Wn,it as Kn,iu as Vn,iv as Yn,iw as Zn,ix as Qn,iy as zt,iz as Wt,iA as es,iB as ts,iC as ns,iD as ss,iE as Kt,iF as rs,iG as ht,iH as Vt,iI as Yt,iJ as Zt,iK as Qt,iL as os,iM as It,iN as as,iO as is,iP as en,iQ as cs,iR as ls,iS as us,iT as tn,iU as ds,iV as ps,iW as ms,iX as fs,iY as hs,iZ as ys,i_ as Ot,i$ as Pt,j0 as Ct,j1 as Gt,j2 as Ss,j3 as gs,j4 as Es,j5 as Ts,j6 as ws,j7 as ks,u as yt,z as ne,b as St,ei as nn,dk as sn,l as le,j8 as rn,j9 as bs,fy as on,bB as xs,fx as _s,en as vs,eb as As,ja as Rs,jb as Is,fz as Os,m as Ps,ec as Cs,ed as Gs,fE as Ms,fo as Ns,fj as Us,f as an,S as Ds,af as js,H as Ls,jc as Hs,bW as je,ho as Mt,jd as Nt,cR as Ut,je as Bs,jf as Dt,jg as Fs,h as $s,jh as qs,o as jt,bq as ce,ji as Xs,cF as at,g as Js,jj as zs,c1 as Ws,c2 as Ks,c0 as Vs,b$ as Ys,b_ as Zs}from"./useAppFontEffects-hfv2s6mZ.js";import{h as L,a as z,u as ze,ac as cn,dH as Qs,a2 as it,dI as er,a4 as tr,A as We,o as j,aa as nr}from"./index-Dy8xgawx.js";import{toast as F}from"./vendor-sonner-DFyL3AvE.js";import{o as r,s,r as Xe,b as Z,n as W,_ as R,a as V,c as G,l,e as ln,d as Ke,j as Ve,N as sr}from"./vendor-zod-fZppILAM.js";import{c as rr}from"./vendor-zustand-BAGL70zf.js";const q="openchamber.sdk",X=1,or=[1],ar=128,ir=65536,cr=2e3,lr=/^(>=)?\d+\.\d+\.\d+$/;class $ extends Error{code;constructor(t,n){super(n),this.name="HostRequestError",this.code=t}}const ur=/^[a-z][a-z0-9-]*$/,dr=r({connected:Z(),account:s(),hasClient:Z(),settings:Xe(s().regex(ur),s()),redirectUri:s().optional()}),pr=r({authorizationUrl:s().min(1)}),mr=r({status:W().int().min(100).max(599),body:s()}),fr=r({error:s().min(1),message:s().min(1).optional()}),Le=(e,t)=>({ok:!1,code:e,message:t}),hr=async e=>{const t=await e.json().catch(()=>null);if(!e.ok){const o=fr.safeParse(t);return o.success?Le(_e(o.data.error),o.data.message??o.data.error):Le("HOST_REJECTED","Request failed.")}const n=mr.safeParse(t);return n.success?{ok:!0,result:n.data}:Le("HOST_REJECTED","Request failed.")},yr=e=>({connection:{connected:e.connected,account:e.account},settings:e.settings,hasClient:e.hasClient,redirectUri:e.redirectUri??""}),Ae=async e=>{if(!e.ok)return null;const t=dr.safeParse(await e.json().catch(()=>null));return t.success?yr(t.data):null},Sr=async e=>{try{return await Ae(await L(`/api/guests/${e}/oauth/status`))}catch{return null}},va=async(e,t,n)=>{const o={clientId:t};n&&(o.clientSecret=n);try{return await Ae(await L(`/api/guests/${e}/oauth/client`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}))}catch{return null}},Aa=async(e,t,n)=>{try{return await Ae(await L(`/api/guests/${e}/token`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n?{token:t,username:n}:{token:t})}))}catch{return null}},Ra=async(e,t)=>{try{return await Ae(await L(`/api/guests/${e}/settings`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}))}catch{return null}},gr=async e=>{try{const t=await L(`/api/guests/${e}/oauth/start`,{method:"POST"});if(!t.ok)return null;const n=pr.safeParse(await t.json().catch(()=>null));return n.success?n.data.authorizationUrl:null}catch{return null}},Er=async e=>{try{return await Ae(await L(`/api/guests/${e}/oauth`,{method:"DELETE"}))}catch{return null}},Tr=3*6e4,wr=1500,kr=(e,t)=>t.connected?e.connected?t.account!==e.account:!0:!1,br=async(e,t)=>{try{const n=await L(`/api/guests/${e}/request`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return hr(n)}catch{return Le("HOST_REJECTED","Request failed.")}};let ct=0;const Ge=rr(e=>({byId:{},setStatus:(t,n)=>{e(o=>({byId:{...o.byId,[t]:n}}))},refresh:async t=>{const n=ct,o=z(),i=await Sr(t);return n!==ct||z()!==o?null:(i&&e(f=>({byId:{...f.byId,[t]:i}})),i)},resetForRuntimeSwitch:()=>{ct++,e({byId:{}})}})),xr=r({status:W().int().min(100).max(599),body:s()}),_r=r({error:s().min(1),message:s().min(1).optional()}),vr=r({status:R(["stopped","starting","ready","failed"])}),He=(e,t)=>({ok:!1,code:e,message:t}),Ar=async e=>{const t=await e.json().catch(()=>null);if(!e.ok){const o=_r.safeParse(t);return o.success?He(_e(o.data.error),o.data.message??o.data.error):He("HOST_REJECTED","Request failed.")}const n=xr.safeParse(t);return n.success?{ok:!0,result:n.data}:He("HOST_REJECTED","Request failed.")},Rr=async(e,t)=>{try{const n=await L(`/api/guests/${e}/service/request`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return Ar(n)}catch{return He("HOST_REJECTED","Request failed.")}},Ir=async e=>{try{const t=await L(`/api/guests/${e}/service/status`);if(!t.ok)return{ok:!1,code:"NO_SERVICE",message:"No service for this extension."};const n=vr.safeParse(await t.json().catch(()=>null));return n.success?{ok:!0,result:n.data}:{ok:!1,code:"HOST_REJECTED",message:"Service status was empty."}}catch{return{ok:!1,code:"HOST_REJECTED",message:"Could not read service status."}}},Or=r({guest:r({id:s().min(1)}).passthrough()}),Ia=async(e,t,n)=>{try{const o=await L(`/api/guests/${e}/service/sockets`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t,path:n})});return o.ok?Or.safeParse(await o.json().catch(()=>null)).success:!1}catch{return!1}},un=e=>{const t=ze.getState();for(const[n,o]of Object.entries(t.contextPanelByDirectory)){const i=o.tabs.filter(f=>f.mode===e).map(f=>f.id);i.length>0&&t.closeContextPanelTabs(n,i)}},Oa=e=>un(cn(e)),gt=e=>ve.test(e)||Qn(e),Lt=e=>{try{const t=new URL(e);return t.protocol==="https:"&&t.username===""&&t.password===""}catch{return!1}},dn=e=>{try{const t=new URL(e);return t.protocol==="https:"&&t.username===""&&t.password===""&&t.pathname==="/"&&t.search===""&&t.hash===""&&e===t.origin}catch{return!1}},pn=e=>!e.startsWith("/")||e.includes("\0")||e.includes("\\")||e.includes("://")?!1:!e.split("/").some(n=>n==="."||n===".."),mn=/^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)*$/,fn=R(["panel","dialog"]),Pr=r({mode:fn,entry:s().trim().refine(Je).optional()}).refine(e=>e.mode==="dialog"||e.entry===void 0,{path:["entry"]}),Cr=V([Z(),fn,Pr]),Gr=r({id:s().trim().regex(ve),name:s().trim().min(1),icon:s().trim().refine(gt),entry:s().trim().refine(Je).optional()}),Mr=r({id:s().trim().regex(ve),label:s().trim().min(1)}),Nr=r({authorizeUrl:s().trim().refine(Lt),tokenUrl:s().trim().refine(Lt),apiOrigin:s().trim().refine(dn),scopes:G(s().trim().min(1)).optional(),account:r({path:s().trim().refine(pn),name:s().trim().regex(mn)}).optional()}),Ur=r({apiOrigin:s().trim().refine(dn),account:r({path:s().trim().refine(pn),name:s().trim().regex(mn)}).optional(),scheme:R(["raw","bearer","basic"]).optional(),usernameLabel:s().trim().min(1).max(64).optional()}),Dr=r({provider:R(["linear"])}),jr=r({name:s().trim().min(1),description:s().trim().min(1),oauth:Nr.optional(),token:Ur.optional(),host:Dr.optional(),settings:G(Mr).optional()}).refine(e=>Mn(e)!==null,{path:["oauth"]}),Ht=["linux","darwin","win32"],xe=s().trim().min(1).max(512),Lr=r({linux:G(xe).max(16).optional(),darwin:G(xe).max(16).optional(),win32:G(xe).max(16).optional()}).strict(),Hr=r({id:s().trim().regex(ve).max(64),path:xe.optional(),candidates:Lr.optional()}).strict().refine(e=>!!e.path||!!e.candidates,{message:"socket binding needs path or candidates"}),Br=e=>{const t={};if(e.candidates)for(const n of Ht){const o=e.candidates[n];o&&o.length>0&&(t[n]=[...o])}else if(e.path)for(const n of Ht)t[n]=[e.path];return{id:e.id,candidatesByPlatform:t}},Fr=V([xe.transform(e=>({id:e,candidatesByPlatform:{linux:[e],darwin:[e],win32:[e]}})),Hr.transform(Br)]),$r=r({sockets:G(Fr).max(32).optional(),exec:G(s().trim().min(1).max(128)).max(32).optional()}).strict().transform(e=>{const t={};return e.sockets&&e.sockets.length>0&&(t.sockets=e.sockets),e.exec&&e.exec.length>0&&(t.exec=[...e.exec]),t}),qr=r({entry:s().trim().refine(Je),runtime:l("host"),permissions:$r.optional()}),hn=(e,t)=>new Set(e.map(t)).size===e.length,Xr=r({id:s().trim().regex(ve).max(64),label:s().trim().min(1).max(Nn),icon:s().trim().refine(gt).optional(),where:R(["message","session"]),roles:G(R(["user","assistant"])).min(1).max(2).optional(),payload:G(R(["messages"])).max(1).optional()}).refine(e=>e.where==="message"||e.roles===void 0,{path:["roles"]}).refine(e=>e.where==="session"||e.payload===void 0,{path:["payload"]}),Jr=G(Xr).min(1).max(Un).refine(e=>hn(e,t=>t.id),{message:"action ids must be unique"}),zr=r({name:s().trim().regex(jn),description:s().trim().min(1).max(Dn).optional()}),Wr=G(zr).min(1).max(Ln).refine(e=>hn(e,t=>t.name),{message:"command names must be unique"}),Kr=r({match:s().trim().min(1).max(Xn).regex(Jn),name:s().trim().min(1).max(qn).optional(),icon:s().trim().refine(gt).optional(),title:s().trim().min(1).max(Rt).optional(),subtitle:s().trim().min(1).max(Rt).optional(),output:R($n).optional(),language:s().trim().min(1).max(Fn).optional(),columns:G(s().trim().min(1).max(Hn)).min(1).max(Bn).optional()}).refine(e=>e.output==="code"||e.language===void 0,{path:["language"]}).refine(e=>e.output==="table"==(e.columns!==void 0),{path:["columns"]}),Vr=G(Kr).min(1).max(zn),Yr=r({panel:Gr,attach:Cr.optional(),page:V([l(!0),r({entry:s().trim().refine(Je),title:s().trim().min(1).max(200).optional()})]).optional(),capabilities:G(R(Yn)).max(8).optional(),integration:jr.optional(),service:qr.optional(),filesystem:G(s().max(Wn).refine(Kn)).min(1).max(Vn).optional(),actions:Jr.optional(),commands:Wr.optional(),tools:Vr.optional()}),Zr=e=>{const t=[];return e.page!==void 0&&t.push("page"),e.attach!==void 0&&e.attach!==!1&&t.push("attach"),e.capabilities&&e.capabilities.length>0&&t.push("capabilities"),e.integration!==void 0&&t.push("integration"),e.service!==void 0&&t.push("service"),e.filesystem!==void 0&&t.push("filesystem"),e.actions!==void 0&&t.push("actions"),e.commands!==void 0&&t.push("commands"),t},Qr=r({apiVersion:l(or[0]),engines:r({openchamber:s().trim().regex(lr)}).strict().optional(),contributes:Yr.superRefine((e,t)=>{if(Zn(e))return;const n=Zr(e);n.length!==0&&t.addIssue({code:"custom",path:["panel"],message:`${n.map(o=>`contributes.${o}`).join(", ")} needs panel.entry; an extension without a page may only declare tools.`})})}),eo=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/,to=s().trim().regex(eo).max(64);r({version:to.optional(),openchamber:Qr});V([r({openchamber:ln()}),r({openchamber:r({}).passthrough()})]);const B=s().trim().min(1).max(1024),Me=R(["loading","ready","error"]),Bt=r({directory:B,name:s(),branch:s(),status:R(["ready","pending","invalid","missing"])}),Ft=Ke("kind",[r({kind:l("projects")}).strict(),r({kind:l("worktrees"),projectId:B}).strict(),r({kind:l("sessions"),projectId:B}).strict()]),yn=Ke("kind",[r({kind:l("projects"),state:Me,projects:G(r({id:B,name:s(),directory:B}))}),r({kind:l("worktrees"),projectId:B,state:Me,worktrees:G(Bt)}),r({kind:l("sessions"),projectId:B,state:Me,coverage:G(r({directory:B,state:Me})),sessions:G(r({id:B,title:s(),projectId:B,directory:B,parentId:B.nullable(),createdAt:W(),updatedAt:W(),archivedAt:W().nullable(),worktree:Bt.nullable(),activity:R(["unknown","idle","running","retrying","waiting-permission","waiting-question"]),outcome:R(["completed","failed"]).nullable(),items:G(r({id:B,data:Ve().optional()}))}))})]),no=V([Z(),r({kind:l("existing"),directory:B}).strict(),r({kind:l("new"),name:s().trim().min(1).max(200).optional(),baseBranch:s().trim().min(1).max(200).optional()}).strict()]),Be=s().min(1).max(ar),so=Ke("op",[r({op:l("get"),key:Be}).strict(),r({op:l("delete"),key:Be}).strict(),r({op:l("set"),key:Be,value:Ve().refine(e=>new TextEncoder().encode(JSON.stringify(e)).length<=ir)}).strict(),r({op:l("keys")}).strict()]),Sn=V([r({storage:l(!0),op:l("get"),found:l(!1)}),r({storage:l(!0),op:l("get"),found:l(!0),value:Ve()}),r({storage:l(!0),op:R(["set","delete"])}),r({storage:l(!0),op:l("keys"),keys:G(Be).max(cr)})]),x={channel:l(q),v:l(X)},ro=r({background:s().min(1),elevated:s().min(1),foreground:s().min(1),muted:s().min(1),subtle:s().min(1),border:s().min(1),hover:s().min(1),selection:s().min(1),focus:s().min(1),primary:s().min(1),mutedSurface:s().min(1),elevatedForeground:s().min(1),active:s().min(1),selectionForeground:s().min(1),primaryForeground:s().min(1),primaryText:s().min(1),successText:s().min(1),warningText:s().min(1),errorText:s().min(1),infoText:s().min(1),success:s().min(1),warning:s().min(1),error:s().min(1),info:s().min(1),font:s().min(1),mono:s().min(1),radius:s().min(1)}),gn=r({id:s().min(1),title:s().min(1),busy:Z().optional().default(!1),model:s().min(1).max(Wt).optional(),agent:s().min(1).max(zt).optional()}).nullable(),En=r({connected:Z(),account:s().max(es)}),Tn=Xe(s().regex(ns),s().max(ts)),oo=r({status:W().int().min(100).max(599),body:s().max(ss)}),$t=r({directory:s(),name:s(),branch:s(),status:R(["ready","pending","invalid","missing"])}),ao=V([r({sessionId:s().min(1),sent:R(Kt),directory:s().optional(),worktree:$t.optional(),linked:Z().optional()}),r({sessionId:ln(),sent:l("skipped"),directory:s(),worktree:$t,failure:R(["bootstrap-failed","session-create-failed"])})]),io=r({sent:R(Kt)}),co=r({status:R(rs)}),lo=r({content:s().max(ht)}),uo=r({written:l(!0)}),po=r({entries:G(r({name:s().min(1),kind:R(Vt)})).max(Yt)}),mo=r({kind:R(Zt),size:W().int().min(0),mtime:W().int().min(0)}),fo=r({text:s().max(Qt)}),ho=V([Sn,yn,ao,oo,io,co,lo,uo,po,mo,fo]),be=r({providerId:s().trim().regex(us),id:s().trim().min(1).max(ls),title:s().trim().min(1).max(cs),url:s().trim().min(1).max(en),text:s().trim().min(1).max(is).optional(),kind:R(["issue","pull"]).optional(),author:s().trim().min(1).max(as).optional(),branches:r({head:s().trim().min(1).max(It),base:s().trim().min(1).max(It)}).optional(),data:Ve().refine(e=>JSON.stringify(e).length<=os).optional()}),wn=R(["user","assistant"]),yo=r({kind:l("message"),action:s().trim().min(1).max(64),sessionId:s().min(1),sessionTitle:s(),directory:s().nullable(),messageId:s().min(1),role:wn,text:s().max(tn)}),So=r({kind:l("session"),action:s().trim().min(1).max(64),sessionId:s().min(1),sessionTitle:s(),directory:s().nullable(),messages:G(r({id:s().min(1),role:wn,text:s().max(tn),createdAt:W().int().min(0)})).optional(),truncated:Z().optional()}).refine(e=>JSON.stringify(e).length<=ds),kn=V([yo,So,be]).nullable(),go=r({theme:r({mode:R(["light","dark"]),tokens:ro}),locale:s().min(1),directory:s().nullable(),session:gn,surface:R(["panel","dialog","page"]),connection:En,settings:Tn,item:kn}),Eo=r({...x,type:l("result"),id:s().min(1),ok:Z(),error:s().min(1).optional(),code:s().min(1).optional(),payload:ho.optional()}).transform((e,t)=>e.ok?e.payload?{channel:e.channel,v:e.v,type:"result",id:e.id,ok:!0,payload:e.payload}:{channel:e.channel,v:e.v,type:"result",id:e.id,ok:!0}:e.error?{channel:e.channel,v:e.v,type:"result",id:e.id,ok:!1,error:e.error,code:_e(e.code)}:(t.addIssue({code:"custom",message:"Failed result needs an error string."}),sr));V([r({...x,type:l("workspace"),payload:r({subscriptionId:s().min(1).max(128),snapshot:yn})}),r({...x,type:l("ready"),payload:go}),r({...x,type:l("directory"),payload:r({directory:s().nullable()})}),r({...x,type:l("session"),payload:r({session:gn})}),r({...x,type:l("connection"),payload:r({connection:En})}),r({...x,type:l("settings"),payload:r({settings:Tn})}),r({...x,type:l("session-lifecycle"),payload:r({sessionId:s().min(1),phase:R(ps)})}),r({...x,type:l("item"),payload:r({item:kn})}),r({...x,type:l("resolve"),id:s().min(1),payload:r({command:s().min(1),args:s()})}),Eo]);const Ne=s().min(1).max(ms).refine(fs),To=Ke("type",[r({...x,type:l("workspace-read"),id:s().min(1),payload:Ft}),r({...x,type:l("workspace-subscribe"),id:s().min(1),payload:r({subscriptionId:s().min(1).max(128),query:Ft})}),r({...x,type:l("workspace-unsubscribe"),id:s().min(1),payload:r({subscriptionId:s().min(1).max(128)})}),r({...x,type:l("storage"),id:s().min(1),payload:so}),r({...x,type:l("open-session"),id:s().min(1),payload:r({sessionId:s().min(1).max(1024)})}),r({...x,type:l("hello")}),r({...x,type:l("toast"),id:s().min(1),payload:r({kind:R(["info","success","error"]),message:s().trim().min(1).max(hs)})}),r({...x,type:l("open-url"),id:s().min(1),payload:r({url:s().trim().min(1).max(en)})}),r({...x,type:l("open-surface"),id:s().min(1),payload:r({surfaceId:s().trim().min(1).max(64)})}),r({...x,type:l("clipboard-write"),id:s().min(1),payload:r({text:s().min(1).max(ys)})}),r({...x,type:l("compose"),id:s().min(1),payload:r({text:s().trim().min(1).max(Ot),mode:R(["replace","append"]).optional()})}),r({...x,type:l("attach"),id:s().min(1),payload:be}),r({...x,type:l("start-session"),id:s().min(1),payload:be.extend({worktree:no.optional(),projectId:s().trim().min(1).max(1024).optional(),navigation:R(["preserve","open"]).optional()})}),r({...x,type:l("prompt"),id:s().min(1),payload:r({text:s().trim().min(1).max(Ot),send:Z().optional()})}),r({...x,type:l("session-link"),id:s().min(1),payload:be}),r({...x,type:l("close"),id:s().min(1)}),r({...x,type:l("oauth-start"),id:s().min(1)}),r({...x,type:l("oauth-disconnect"),id:s().min(1)}),r({...x,type:l("request"),id:s().min(1),payload:r({method:R(["GET","POST","PUT","PATCH","DELETE"]),path:s().trim().min(1).max(Ct).refine(Gt),query:Xe(s().min(1).max(128),s().max(2e3)).optional(),body:s().max(Pt).optional()})}),r({...x,type:l("service-request"),id:s().min(1),payload:r({method:R(["GET","POST","PUT","PATCH","DELETE"]),path:s().trim().min(1).max(Ct).refine(Gt),query:Xe(s().min(1).max(128),s().max(2e3)).optional(),body:s().max(Pt).optional()})}),r({...x,type:l("service-status"),id:s().min(1)}),r({...x,type:l("file-read"),id:s().min(1),payload:r({path:Ne})}),r({...x,type:l("file-write"),id:s().min(1),payload:r({path:Ne,content:s().max(ht)})}),r({...x,type:l("file-list"),id:s().min(1),payload:r({path:Ne})}),r({...x,type:l("file-stat"),id:s().min(1),payload:r({path:Ne})}),r({...x,type:l("generate"),id:s().min(1),payload:r({prompt:s().trim().min(1).max(Es),system:s().trim().min(1).max(gs).optional(),maxOutputTokens:W().int().min(1).max(Ss).optional()})}),r({...x,type:l("badge"),id:s().min(1),payload:r({count:W().int().min(0).max(Ts).nullable()})}),r({...x,type:l("resolve-result"),id:s().min(1),payload:V([r({item:be.nullable()}),r({error:s().trim().min(1).max(ws)})])})]),wo=e=>({channel:q,v:X,type:"ready",payload:e}),ko=e=>({channel:q,v:X,type:"directory",payload:{directory:e}}),bo=e=>({channel:q,v:X,type:"session",payload:{session:e}}),xo=e=>({channel:q,v:X,type:"connection",payload:{connection:e}}),_o=e=>({channel:q,v:X,type:"settings",payload:{settings:e}}),vo=e=>({channel:q,v:X,type:"item",payload:{item:e}}),Ao=(e,t,n)=>({channel:q,v:X,type:"resolve",id:e,payload:{command:t,args:n}}),Ro=e=>({channel:q,v:X,type:"session-lifecycle",payload:e}),Io=e=>e?.type==="busy"||e?.type==="retry"?"started":e?.type==="idle"?"completed":e?.type?"failure":null,Oo=e=>{const t=e?.providerID?.trim(),n=e?.id?.trim();if(!(!t||!n))return`${t}/${n}`},Po=e=>{if(!e?.id)return null;const t=e.title?.trim(),n={id:e.id,title:t||e.id,busy:!!e.busy},o=e.model?.trim().slice(0,Wt);o&&(n.model=o);const i=e.agent?.trim().slice(0,zt);return i&&(n.agent=i),n},M=(e,t)=>t?{channel:q,v:X,type:"result",id:e,ok:!0,payload:t}:{channel:q,v:X,type:"result",id:e,ok:!0},N=(e,t,n="HOST_REJECTED")=>({channel:q,v:X,type:"result",id:e,ok:!1,error:t,code:n}),Ue=(e,t)=>t.ok?M(e,t.result):N(e,t.message,t.code),De=e=>{try{const t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}},Co=async(e,t)=>{try{switch(e.type){case"workspace-read":return M(e.id,t.workspaceRead(e.payload));case"workspace-subscribe":return t.workspaceSubscribe(e.payload),M(e.id);case"workspace-unsubscribe":return t.workspaceUnsubscribe(e.payload.subscriptionId),M(e.id);case"storage":return M(e.id,await t.storage(e.payload));case"open-session":return t.openSession(e.payload.sessionId),M(e.id);case"hello":return null;case"toast":return t.toast(e.payload.kind,e.payload.message),M(e.id);case"open-url":return De(e.payload.url)?await t.openUrl(e.payload.url)?M(e.id):N(e.id,"Could not open URL."):N(e.id,"URL must be http or https.");case"open-surface":return Qs(e.payload.surfaceId)?(t.openSurface(e.payload.surfaceId),M(e.id)):N(e.id,"Unknown surface.");case"clipboard-write":return await t.writeClipboard(e.payload.text)?M(e.id):N(e.id,"Could not write clipboard.");case"compose":return t.compose(e.payload.text,e.payload.mode??"append"),M(e.id);case"attach":return De(e.payload.url)?(t.attach(e.payload),M(e.id)):N(e.id,"URL must be http or https.");case"start-session":{if(!De(e.payload.url))return N(e.id,"URL must be http or https.");const n=await t.startSession(e.payload);return n?"sessionId"in n?M(e.id,n):N(e.id,n.message,n.code):N(e.id,"Could not start that session.")}case"prompt":{const n=await t.prompt(e.payload);return n.ok?M(e.id,n.result):N(e.id,n.message,n.code)}case"session-link":{if(!De(e.payload.url))return N(e.id,"URL must be http or https.");const n=await t.sessionLink(e.payload);return n.ok?M(e.id):N(e.id,n.message,n.code)}case"close":return t.close(),M(e.id);case"oauth-start":return await t.oauthStart()?M(e.id):N(e.id,"Could not start OAuth.");case"oauth-disconnect":return await t.oauthDisconnect()?M(e.id):N(e.id,"Could not disconnect.");case"request":{const n=await t.request(e.payload);return n.ok?M(e.id,n.result):N(e.id,n.message,n.code)}case"service-request":{const n=await t.serviceRequest(e.payload);return n.ok?M(e.id,n.result):N(e.id,n.message,n.code)}case"service-status":{const n=await t.serviceStatus();return n.ok?M(e.id,n.result):N(e.id,n.message,n.code)}case"file-read":return Ue(e.id,await t.file({op:"read",path:e.payload.path}));case"file-write":return Ue(e.id,await t.file({op:"write",path:e.payload.path,content:e.payload.content}));case"file-list":return Ue(e.id,await t.file({op:"list",path:e.payload.path}));case"file-stat":return Ue(e.id,await t.file({op:"stat",path:e.payload.path}));case"generate":{const n=await t.generate(e.payload);return n.ok?M(e.id,n.result):N(e.id,n.message,n.code)}case"badge":return t.setBadge(e.payload.count),M(e.id);case"resolve-result":return t.resolveResult(e.id,e.payload),null}}catch(n){return e.type==="hello"?null:N(e.id,n instanceof $?n.message:"Extension operation failed.",n instanceof $?n.code:"HOST_REJECTED")}},Go=V([r({content:s().max(ht)}),r({written:l(!0)}),r({entries:G(r({name:s().min(1),kind:R(Vt)})).max(Yt)}),r({kind:R(Zt),size:W().int().min(0),mtime:W().int().min(0)})]),Mo=r({ok:l(!0),result:Go}),No=r({error:s().min(1),message:s().min(1).optional()}),Fe=(e,t)=>({ok:!1,code:e,message:t}),Uo=async e=>{const t=await e.json().catch(()=>null);if(!e.ok){const o=No.safeParse(t);return o.success?Fe(_e(o.data.error),o.data.message??o.data.error):Fe("HOST_REJECTED","File operation failed.")}const n=Mo.safeParse(t);return n.success?{ok:!0,result:n.data.result}:Fe("HOST_REJECTED","File operation failed.")},Do=async(e,t,n)=>{const o=new Headers({"Content-Type":"application/json"});n&&o.set("x-opencode-directory",n);try{const i=await L(`/api/guests/${e}/files`,{method:"POST",headers:o,body:JSON.stringify(t)});return Uo(i)}catch{return Fe("HOST_REJECTED","File operation failed.")}},jo=r({ok:l(!0),result:r({text:s().max(Qt)})}),Lo=r({error:s().min(1),message:s().min(1).optional()}),$e=(e,t)=>({ok:!1,code:e,message:t}),mt="Text generation failed.",Ho=async e=>{const t=await e.json().catch(()=>null);if(!e.ok){const o=Lo.safeParse(t);return o.success?$e(_e(o.data.error),o.data.message??o.data.error):$e("HOST_REJECTED",mt)}const n=jo.safeParse(t);return n.success?{ok:!0,result:n.data.result}:$e("HOST_REJECTED",mt)},Bo=async(e,t,n)=>{const o=new Headers({"Content-Type":"application/json"});n&&o.set("x-opencode-directory",n);try{const i=await L(`/api/guests/${e}/generate`,{method:"POST",headers:o,body:JSON.stringify(t)});return Ho(i)}catch{return $e("HOST_REJECTED",mt)}},lt="https://extension.invalid",Fo=500,$o=40*1024*1024,qt=64*1024*1024,ut=async e=>{const t=new Uint8Array(await e.arrayBuffer());let n="";for(let o=0;o<t.length;o+=8192)n+=String.fromCharCode(...t.subarray(o,o+8192));return`data:${e.type||"application/octet-stream"};base64,${btoa(n)}`},qo=e=>e.replace(/\\(?:([0-9a-f]{1,6})\s?|([\s\S]))/gi,(t,n,o)=>{if(n){const i=Number.parseInt(n,16);return i>0&&i<=1114111?String.fromCodePoint(i):"�"}return o===`
|
|
2
|
+
`||o==="\r"?"":o??""}),Xo=/\/\*[\s\S]*?\*\/|"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|\burl\(\s*(?:"((?:\\[\s\S]|[^"\\])*)"|'((?:\\[\s\S]|[^'\\])*)'|((?:\\[\s\S]|[^)\\])*?))\s*\)|@import\s+(?:"((?:\\[\s\S]|[^"\\])*)"|'((?:\\[\s\S]|[^'\\])*)')/gi,Jo=async(e,t,n)=>{const o=`/api/guests/${e}/`,i=new URL(t,`${lt}${o}`),f=new Map;let k=0,E=0;const _=async a=>{if(a.origin!==lt||!a.pathname.startsWith(o))throw new Error("Extension resource is outside its package");const d=await n(`${a.pathname}${a.search}`);if(!d.ok)throw new Error(`Could not load extension resource (HTTP ${d.status})`);const u=d.body?.getReader();if(!u)throw new Error("Extension resource has no response body");const p=[];try{for(;;){const{done:c,value:y}=await u.read();if(c)break;if(k+=y.byteLength,k>$o)throw new Error("Extension document exceeds the resource size limit");p.push(new Uint8Array(y))}}catch(c){throw await u.cancel().catch(()=>{}),c}finally{u.releaseLock()}return new Blob(p,{type:d.headers.get("content-type")?.split(";")[0]||"application/octet-stream"})},S=async(a,d,u)=>{const p=a.trim();if(!p||p.startsWith("#"))return a;const c=new URL(p,d);if(c.origin!==lt)return c.href;const y=c.hash;c.hash="";const w=c.href;if(u.includes(w))throw new Error("Circular extension resource reference");let b=f.get(w);if(!b){if(f.size>=Fo)throw new Error("Extension document has too many resources");const v=[...u,w];b=_(c).then(async H=>{const Q=H.type.split(";")[0];return Q==="text/css"||c.pathname.endsWith(".css")?ut(new Blob([await I(await H.text(),c,v)],{type:"text/css"})):ut(Q==="text/html"?new Blob([await O(await H.text(),c,v)],{type:"text/html"}):H)}),f.set(w,b)}const C=`${await b}${y}`;if(E+=C.length,E>qt)throw new Error("Extension document exceeds the embedded size limit");return C},I=async(a,d,u)=>{let p="",c=0;for(const y of a.matchAll(Xo)){const w=y[1]??y[2]??y[3]??y[4]??y[5];if(w===void 0)continue;p+=a.slice(c,y.index);const b=await S(qo(w.trim()),d,u),C=JSON.stringify(b);p+=y[4]!==void 0||y[5]!==void 0?`@import url(${C})`:`url(${C})`,c=y.index+y[0].length}return p+a.slice(c)},h=async(a,d,u)=>{const p=[];let c=a;for(;c.trim();){c=c.replace(/^[\s,]+/,"");const y=/^\S+/.exec(c);if(!y)break;const w=y[0];c=c.slice(w.length);let b="";if(!w.endsWith(",")){const v=c.indexOf(",");b=(v<0?c:c.slice(0,v)).trim(),c=v<0?"":c.slice(v+1)}const C=await S(w.replace(/,+$/,""),d,u);p.push(b?`${C} ${b}`:C)}return p.join(", ")},O=async(a,d,u)=>{const p=new DOMParser().parseFromString(a,"text/html"),c=p.querySelector("base[href]")?.getAttribute("href"),y=p.querySelector("base[target]")?.getAttribute("target"),w=c?new URL(c,d):d;for(const v of p.querySelectorAll("base"))v.remove();const b=p.createElement("base");b.href=w.href,y&&(b.target=y),p.head.prepend(b);for(const v of p.querySelectorAll("script[src], link[href], img[src], source[src], video[src], audio[src], iframe[src], embed[src], object[data], image[href], image[xlink\\:href], use[href], use[xlink\\:href]"))for(const H of["src","href","data","xlink:href"]){const Q=v.getAttribute(H);Q!==null&&v.setAttribute(H,await S(Q,w,u))}for(const v of p.querySelectorAll("[poster]"))v.setAttribute("poster",await S(v.getAttribute("poster")??"",w,u));for(const v of p.querySelectorAll("img[srcset], source[srcset]"))v.setAttribute("srcset",await h(v.getAttribute("srcset")??"",w,u));for(const v of p.querySelectorAll("style"))v.textContent=await I(v.textContent??"",w,u);for(const v of p.querySelectorAll("[style]"))v.setAttribute("style",await I(v.getAttribute("style")??"",w,u));const C=`<!doctype html>
|
|
3
|
+
${p.documentElement.outerHTML}`;if(C.length>qt)throw new Error("Extension document exceeds the size limit");return C},g=await _(i);if(g.type.split(";")[0]!=="text/html")throw new Error("Extension entry is not HTML");return O(await g.text(),i,[i.href])},zo=async(e,t,n)=>{const o=z(),i=it();if(i){const E=await Jo(e,t,_=>{if(z()!==o||it()!==i||n?.aborted)throw new DOMException("Extension frame owner changed","AbortError");return L(_,{signal:n})});if(z()!==o||it()!==i||n?.aborted)throw new DOMException("Extension frame owner changed","AbortError");return{kind:"document",html:E}}const{token:f,expiresAt:k}=await er(e);if(o!==z())throw new Error("Runtime changed while authorizing extension frame");return{kind:"url",url:tr().assetWithUrlToken(`/api/guests/${e}/${t}`,f,{oc_ui:"issue-page"}),expiresAt:k}},Wo=e=>{const t=Jt.c(31),{guestId:n,entry:o,instanceKey:i,enabled:f}=e,[k,E]=T.useState(null),[_,S]=T.useState(0),I=T.useRef(!1),[h,O]=T.useState(z);let g;t[0]!==f||t[1]!==o||t[2]!==n||t[3]!==i||t[4]!==h?(g=JSON.stringify([h,n,o,i,f]),t[0]=f,t[1]=o,t[2]=n,t[3]=i,t[4]=h,t[5]=g):g=t[5];const a=g;let d,u;t[6]===Symbol.for("react.memo_cache_sentinel")?(d=()=>We(oe=>{O(oe.runtimeKey)}),u=[],t[6]=d,t[7]=u):(d=t[6],u=t[7]),T.useEffect(d,u);let p;t[8]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{I.current=!1},t[8]=p):p=t[8];let c;t[9]!==a?(c=[a],t[9]=a,t[10]=c):c=t[10],T.useEffect(p,c);let y;t[11]!==f||t[12]!==o||t[13]!==n||t[14]!==a?(y=()=>{if(E({key:a,status:"loading"}),!o||!f)return;let oe=!1;const Y=new AbortController;return zo(n,o,Y.signal).then(ge=>{oe||E({key:a,status:"ready",source:ge})}).catch(()=>{oe||E({key:a,status:"error"})}),()=>{oe=!0,Y.abort()}},t[11]=f,t[12]=o,t[13]=n,t[14]=a,t[15]=y):y=t[15];let w;t[16]!==f||t[17]!==o||t[18]!==n||t[19]!==a||t[20]!==_?(w=[f,o,n,a,_],t[16]=f,t[17]=o,t[18]=n,t[19]=a,t[20]=_,t[21]=w):w=t[21],T.useEffect(y,w);const b=k?.key===a&&k.status==="ready"?k.source:null;let C;t[22]!==b||t[23]!==a?(C=()=>b?b.kind==="document"||Date.now()<b.expiresAt?!1:(I.current?E({key:a,status:"error"}):(E({key:a,status:"loading"}),I.current=!0,S(Ko)),!0):!0,t[22]=b,t[23]=a,t[24]=C):C=t[24];const v=C;let H;t[25]===Symbol.for("react.memo_cache_sentinel")?(H=()=>{I.current=!1},t[25]=H):H=t[25];const Q=H,pe=b?.kind==="url"?b.url:"",me=b?.kind==="document"?b.html:void 0,se=k?.key===a?k.status:"loading";let re;return t[26]!==v||t[27]!==pe||t[28]!==me||t[29]!==se?(re={src:pe,srcDoc:me,status:se,recoverExpiredNavigation:v,acknowledgeHandshake:Q},t[26]=v,t[27]=pe,t[28]=me,t[29]=se,t[30]=re):re=t[30],re};function Ko(e){return e+1}const bn="/api/linear/issues/get",Vo=(e,t)=>e==="host"&&t.method==="GET"&&t.path===bn,Yo=async(e,t)=>{if(Vo(e,t))try{const n=await L(bn,{query:t.query});return{status:n.status,body:await n.text()}}catch{return null}},Zo=e=>{const t=St.getState();if(!t.hasServerSnapshot)throw new $("HOST_UNAVAILABLE","The project registry has not loaded.");const n=t.projects.find(o=>o.id===e);if(!n)throw new $("NOT_FOUND","Project is not registered.");return n},qe=e=>ne.getState().availableWorktreesByProject.get(j(e)??e)??[],xn=e=>({directory:e.path,name:e.name??e.label,branch:e.branch,status:e.worktreeStatus==="not-a-repo"?"invalid":e.worktreeStatus??"ready"}),Qo=e=>e.includes("error")?"error":e.includes("loading")?"loading":"ready",ea=(e,t,n,o)=>{const i=e.directory,f=rn(i),k=sn.getState(),E=k.statusById.get(e.id),_=(E&&j(E.directory)===j(i)?E.status:void 0)??f?.session_status[e.id],S=k.observedById.get(e.id),I=S&&j(S.directory)===j(i)?S:void 0,h=ne.getState().worktreeMetadata.get(e.id),O=o.get(j(i)??i)??(h&&j(h.path)===j(i)?xn(h):null),g=le.getState().isConnected;let a="unknown";return g&&(_?.type==="busy"?a="running":_?.type==="retry"?a="retrying":(_?.type==="idle"||f?.sessionStatusReady||I)&&(a="idle"),f?.permission[e.id]?.length?a="waiting-permission":f?.question[e.id]?.length&&(a="waiting-question")),{id:e.id,title:e.title||e.id,projectId:t,directory:i,parentId:e.parentID??null,createdAt:e.time.created,updatedAt:e.time.updated,archivedAt:e.time.archived||null,worktree:O,activity:a,outcome:a==="idle"?I?.outcome??null:null,items:bs(e).flatMap(d=>{if(d.kind!=="guest"||d.providerId!==n)return[];const u={id:d.identifier};return d.data!==void 0&&(u.data=d.data),[u]})}},ft=(e,t)=>{const n=St.getState();if(e.kind==="projects")return{kind:"projects",state:n.serverSnapshotFailed?"error":n.hasServerSnapshot?"ready":"loading",projects:n.hasServerSnapshot?n.projects.map(a=>({id:a.id,name:a.label||a.path.split("/").pop()||a.path,directory:a.path})):[]};const o=n.projects.find(a=>a.id===e.projectId),i=ne.getState(),f=o?j(o.path)??o.path:"",k=o?i.worktreeDiscoveryByProject.get(f)??"loading":n.hasServerSnapshot?"error":"loading",E=o?qe(o.path).map(xn):[];if(e.kind==="worktrees")return{...e,state:k,worktrees:E};const _=new Set(o?[f,...E.map(a=>j(a.directory)??a.directory)]:[]),S=nn(),I=yt.getState(),h=[..._].map(a=>{const u=S.getBootstrapState(a)==="failed"||I.status==="error"?"error":I.status==="ready"?"ready":"loading";return{directory:a,state:u}}),O=new Map;for(const a of _)for(const d of I.structure.activeIdsByDirectory.get(a)??[]){const u=I.entityById.get(d);u&&O.set(d,u)}for(const a of I.archivedSessions)_.has(j(a.directory)??a.directory)&&O.set(a.id,a);for(const a of _)for(const d of rn(a)?.session??[])_.has(j(d.directory)??d.directory)&&(O.has(d.id)||O.set(d.id,d));const g=new Map(E.map(a=>[j(a.directory)??a.directory,a]));return{...e,state:Qo([k,...h.map(a=>a.state)]),coverage:h,sessions:[...O.values()].map(a=>ea(a,e.projectId,t,g))}},dt=new Map,ta=(e,t,n)=>{const o=JSON.stringify([z(),t,e]);let i=dt.get(o);if(!i){const k=new Set,E={listeners:k,snapshot:ft(e,t),dispose:()=>{}};let _=!1,S=!1,I=JSON.stringify(E.snapshot);const h=()=>{_||S||(_=!0,queueMicrotask(()=>{if(_=!1,S)return;const g=ft(e,t),a=JSON.stringify(g);if(a!==I){I=a,E.snapshot=g;for(const d of k)d(g)}}))},O=[St.subscribe((g,a)=>{(g.projects!==a.projects||g.hasServerSnapshot!==a.hasServerSnapshot||g.serverSnapshotFailed!==a.serverSnapshotFailed)&&h()})];if(e.kind!=="projects"&&O.push(ne.subscribe((g,a)=>{(g.availableWorktreesByProject!==a.availableWorktreesByProject||g.worktreeDiscoveryByProject!==a.worktreeDiscoveryByProject||g.worktreeMetadata!==a.worktreeMetadata)&&h()})),e.kind==="sessions"){const g=nn();O.push(yt.subscribe((a,d)=>{(a.activeSessions!==d.activeSessions||a.archivedSessions!==d.archivedSessions||a.status!==d.status)&&h()}),sn.subscribe(h),le.subscribe((a,d)=>{a.isConnected!==d.isConnected&&h()}),g.subscribeBootstrap(h),g.subscribeAllSelected(a=>a.session,h),g.subscribeAllSelected(a=>a.permission,h),g.subscribeAllSelected(a=>a.question,h),g.subscribeAllSelected(a=>a.sessionStatusReady,h))}E.dispose=()=>{S=!0;for(const g of O)g();dt.delete(o)},O.push(We(E.dispose)),dt.set(o,E),i=E}i.listeners.add(n),n(i.snapshot);const f=i;return()=>{f.listeners.delete(n),f.listeners.size===0&&f.dispose()}},na=e=>{const t=ks().get(e)??yt.getState().entityById.get(e);if(!t?.directory)throw new $("NO_SESSION","Session is not available.");ne.getState().setCurrentSession(e,t.directory),ze.getState().closeMainSurfaces()},sa=e=>`${e.id} ${e.title}`.trim(),ra=(e,t)=>{const n=e.replace(/[^a-zA-Z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase();return`${t==="pull"?"pr":"issue"}-${n||"guest"}`},_n=(e,t,n)=>{const o=t?.trim()??"";if(!o)return{ok:!1,reason:"no-directory"};const i=Is(e),f=i.kind==="pull"?"pull":"issue",k={ok:!0,directory:o,title:sa(i),worktree:!!i.worktree,branchName:ra(i.id,f),kind:f==="pull"?"pr":"standard",linked:Os({providerId:i.providerId,identifier:i.id,title:i.title,url:i.url,thread:f,author:i.author,head:i.branches?.head,base:i.branches?.base,data:i.data,linkedAt:n})};return i.text&&(k.text=i.text),k},oa=async(e,t)=>{const n=e.worktree?await t.createWorktree(e.directory,e.branchName,e.kind):await t.createSession(e.title,e.directory);if(!n)return{ok:!1,reason:e.worktree?"worktree-failed":"create-failed"};if(t.initializeSession(n.id),t.closeSurfaces(),await t.setLinkedIssue(n.id,n.directory,e.linked),!e.text)return{ok:!0,sessionId:n.id,sent:"skipped"};const o=await t.sendFirstMessage(n.id,n.directory,e.text);return{ok:!0,sessionId:n.id,sent:o}},aa=()=>{const e=le.getState();if(e.settingsDefaultAgent)return e.settingsDefaultAgent;const t=e.agents.filter(n=>!n.hidden);return e.currentAgentName||t.find(n=>n.mode==="primary"||!n.mode)?.name||t[0]?.name},ia=()=>{const e=Ns(le.getState().settingsDefaultModel);return!e||!le.getState().getModelMetadata(e.providerId,e.modelId)?null:{providerID:e.providerId,modelID:e.modelId}},ca=(e,t)=>{const n=le.getState(),o=n.settingsDefaultVariant,i=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0,k=n.providers.find(_=>_.id===e)?.models.find(_=>_.id===t),E=Us(k);if(E.length===0)return o||i||void 0;if(o&&E.includes(o))return o;if(i&&E.includes(i))return i},vn=()=>{const e=le.getState(),t=Ps.getState().lastUsedProvider,n=ia(),o=n?.providerID||e.currentProviderId||t?.providerID,i=n?.modelID||e.currentModelId||t?.modelID,f=aa()||e.currentAgentName||void 0;return!o||!i?null:{providerID:o,modelID:i,agentName:f,variant:ca(o,i)}},An=async(e,t,n,o=vn())=>{if(!o)return"no-model";try{return await ne.getState().sendMessage(n,o.providerID,o.modelID,o.agentName,void 0,void 0,void 0,o.variant,void 0,{sessionId:e,directory:t}),"sent"}catch{return"failed"}},la=(e,t,n,o)=>{const i=n?.trim()??"";if(!i)return{ok:!1,code:"HOST_REJECTED",message:"Open a project first.",toastKey:"contextPanel.plugin.startSession.noProject"};const f=t?.trim()??"";if(!f)return{ok:!1,code:"NO_SESSION",message:"No open session.",toastKey:"contextPanel.plugin.sessionLink.noSession"};const k=_n(e,i,o);return k.ok?{ok:!0,sessionId:f,directory:i,linked:k.linked}:{ok:!1,code:"HOST_REJECTED",message:"Open a project first.",toastKey:"contextPanel.plugin.startSession.noProject"}},ua=async e=>{const t=la(e.request,e.sessionId,e.directory,Date.now());if(!t.ok)return F.error(e.t(t.toastKey)),{ok:!1,code:t.code,message:t.message};try{return await on(t.sessionId,t.directory,t.linked,!0),F.success(e.t("contextPanel.plugin.sessionLink.linked")),{ok:!0}}catch{return F.error(e.t("contextPanel.plugin.sessionLink.failed")),{ok:!1,code:"HOST_REJECTED",message:"Could not link that item."}}},da=e=>{const t=Rs(e.request),n=e.sessionId?.trim()??"";if(!n)return{ok:!1,code:"NO_SESSION",message:"No open session.",toastKey:"contextPanel.plugin.prompt.noSession"};if(!t.send)return{ok:!0,action:"compose",text:t.text};if(e.busy)return{ok:!1,code:"SESSION_BUSY",message:"Session is busy.",toastKey:"contextPanel.plugin.prompt.busy"};const o=e.directory?.trim()??"";return o?{ok:!0,action:"send",text:t.text,sessionId:n,directory:o}:{ok:!1,code:"HOST_REJECTED",message:"Open a project first.",toastKey:"contextPanel.plugin.startSession.noProject"}},pa=async e=>{const t=da(e);if(!t.ok)return F.error(e.t(t.toastKey)),{ok:!1,code:t.code,message:t.message};if(t.action==="compose")return e.compose(t.text,"replace"),{ok:!0,result:{sent:"skipped"}};const n=await An(t.sessionId,t.directory,t.text);return n==="no-model"?F.error(e.t("contextPanel.plugin.prompt.noModel")):n==="failed"&&F.error(e.t("contextPanel.plugin.prompt.sendFailed")),{ok:!0,result:{sent:n}}},ma=async e=>{e.assertAuthorized();const t=e.request.projectId?Zo(e.request.projectId):e.directory?xs(e.directory):null,n=e.request.worktree;let o=e.request.projectId?t?.path??null:e.directory,i;if(n&&n!==!0&&n.kind==="existing"){if(!t)throw new $("NO_DIRECTORY","Project is not registered.");if(i=qe(t.path).find(p=>j(p.path)===j(n.directory)),!i)throw new $("NOT_FOUND","Worktree does not belong to this project or has not loaded yet.");if(i.worktreeStatus==="missing"||i.worktreeStatus==="invalid"||i.worktreeStatus==="not-a-repo")throw new $("HOST_REJECTED","Worktree is unavailable.");o=i.path}const f=n===!0||!!(n&&n.kind==="new"),k=_n({...e.request,worktree:f},o,Date.now());if(!k.ok)return F.error(e.t("contextPanel.plugin.startSession.noProject")),null;const E=e.request.navigation??"preserve",_=vn();let S=!1;const I=We(()=>{S=!0}),h=()=>{if(S)throw new $("DISCONNECTED","The connected server changed.");e.assertAuthorized()};let O="session-create-failed",g=!0,a=o??"";const d=()=>{if(!i)return;const p=t?qe(t.path).find(c=>c.path===i?.path)??i:i;return{directory:p.path,name:p.name??p.label,branch:p.branch,status:p.worktreeStatus==="not-a-repo"?"invalid":p.worktreeStatus??"ready"}},u=async(p,c)=>{if(i&&t){O="bootstrap-failed";const w=await Cs(t);h(),w&&await Gs(i.path)}h(),O="session-create-failed";const y=await Ms(p,c,null,void 0,void 0,E);if(h(),!y)return null;if(a=y.directory??c,i){const w=t?qe(t.path).find(b=>b.path===i?.path):void 0;i={...i,worktreeStatus:w?.worktreeStatus??i.worktreeStatus},ne.getState().setWorktreeMetadata(y.id,i)}return{id:y.id,directory:a}};try{const p=await oa(k,{createSession:u,createWorktree:async(c,y,w)=>{if(!t)throw new $("NO_DIRECTORY","Project is not registered.");const b=n&&n!==!0&&n.kind==="new"?n:void 0,C=b?.name??`${y}-${_s()}`,v=await vs(t);return h(),i=await As(t,{preferredName:C,mode:"new",branchName:C,worktreeName:C,startRef:b?.baseBranch,setupCommands:v,returnAfterDirectoryCreated:!0}),h(),i={...i,kind:w,createdFromBranch:b?.baseBranch},u(k.title,i.path)},initializeSession:c=>{ne.getState().initializeNewOpenChamberSession(c,le.getState().agents)},setLinkedIssue:async(c,y,w)=>{h(),await on(c,y,w,!0).catch(()=>{g=!1}),h()},sendFirstMessage:(c,y,w)=>(h(),An(c,y,w,_)),closeSurfaces:()=>{E==="open"&&ze.getState().closeMainSurfaces()}});if(h(),!p.ok){const c=d();return c?{sessionId:null,sent:"skipped",directory:c.directory,worktree:c,failure:O}:(F.error(e.t("contextPanel.plugin.startSession.failed")),null)}return p.sent==="no-model"?F.error(e.t("contextPanel.plugin.startSession.noModel")):p.sent==="failed"?F.error(e.t("contextPanel.plugin.startSession.sendFailed")):F.success(e.t("contextPanel.plugin.startSession.created")),{sessionId:p.sessionId,sent:p.sent,directory:a,worktree:d(),linked:g}}catch(p){h();const c=d();if(c)return{sessionId:null,sent:"skipped",directory:c.directory,worktree:c,failure:O};throw p}finally{I()}},fa=async(e,t)=>{const n=await L(`/api/guests/${encodeURIComponent(e)}/storage`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new $("HOST_REJECTED","Storage operation failed. Check extension approval and storage limits.");return Sn.parse(await n.json())},Xt="*",ha='"SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif',ya='ui-monospace, "SFMono-Regular", "Menlo", "Cascadia Mono", "Segoe UI Mono", monospace',Sa="0.5625rem",Se="The user has not allowed this capability for the extension.",ga=(e,t)=>e.type==="attach"||e.type==="start-session"||e.type==="session-link"?e.payload.providerId===t?e:{...e,payload:{...e.payload,providerId:t}}:e,pt=(e,t)=>getComputedStyle(document.documentElement).getPropertyValue(e).trim()||t,Rn=({mode:e,surface:t="panel",item:n,headless:o=!1,onDismiss:i,onAttach:f,onSessionStarted:k})=>{const{t:E,locale:_}=an(),{currentTheme:S}=Ds(),I=js(),h=ne(A=>A.currentSessionId),O=Ls(h,I||void 0),g=Hs(h??"",I||void 0),a=T.useRef(null),d=nr(e),u=je(A=>A.guests.find(K=>K.id===d)??null),p=je(A=>A.status),c=u?Mt(u):!0,y=Ge(A=>A.byId[d]),w=Ge(A=>A.setStatus),b=Ge(A=>A.refresh),C=Nt(A=>A.pendingItemByGuest[d]),v=Nt(A=>A.takePendingItem),[H,Q]=T.useState(null);T.useEffect(()=>{o||n!==void 0||!C||Q(v(d))},[d,o,n,C,v]);const pe=o?null:n!==void 0?n:H,me=Ut(A=>A.clearBadge);T.useEffect(()=>{t==="panel"&&!o&&me(d)},[me,d,o,t]);const se=g?.type==="busy"||g?.type==="retry",re=Io(g),oe=T.useMemo(()=>Po(h?{id:O?.id??h,title:O?.title,busy:se,model:Oo(O?.model),agent:O?.agent}:null),[h,O,se]),Y=T.useMemo(()=>Bs(S),[S]),ge=T.useMemo(()=>({theme:{mode:S.metadata.variant==="dark"?"dark":"light",tokens:{background:S.colors.surface.background,elevated:S.colors.surface.elevated,foreground:S.colors.surface.foreground,muted:S.colors.surface.mutedForeground,subtle:S.colors.surface.subtle,border:S.colors.interactive.border,hover:S.colors.interactive.hover,selection:S.colors.interactive.selection,focus:S.colors.interactive.focusRing,primary:S.colors.primary.base,mutedSurface:S.colors.surface.muted,elevatedForeground:S.colors.surface.elevatedForeground,active:S.colors.interactive.active,selectionForeground:Y.selectionForeground,primaryForeground:S.colors.primary.foreground??"#ffffff",primaryText:Y.tinted.primary,successText:Y.tinted.success,warningText:Y.tinted.warning,errorText:Y.tinted.error,infoText:Y.tinted.info,success:S.colors.status.success,warning:S.colors.status.warning,error:S.colors.status.error,info:S.colors.status.info,font:pt("--font-sans",ha),mono:pt("--font-mono",ya),radius:pt("--radius",Sa)}},locale:_,directory:I||null,session:oe,surface:t,connection:y?.connection??Dt,settings:y?.settings??{},item:pe}),[S,Y,I,pe,_,y,oe,t]),Ee=`${d}:${u?.version??""}:${c}:service-${u?.service?.granted?"1":"0"}`,In=u?t==="page"?u.pageEntry??null:t==="dialog"&&u.attachEntry?u.attachEntry:u.entry??null:null,{src:Ye,srcDoc:Ze,status:On,recoverExpiredNavigation:Pn,acknowledgeHandshake:Et}=Wo({guestId:d,entry:In,instanceKey:Ee,enabled:c}),fe=T.useRef(ge);fe.current=ge;const ae=T.useRef(I);ae.current=I;const Qe=T.useRef(h);Qe.current=h;const Tt=T.useRef(se);Tt.current=se;const D=T.useRef(d);D.current=d;const ie=T.useRef(c);ie.current=c;const ue=T.useRef(u);ue.current=u;const wt=T.useRef(u?.integration?.auth);wt.current=u?.integration?.auth;const Re=T.useRef(E);Re.current=E;const et=T.useRef(f);et.current=f;const tt=T.useRef(i);tt.current=i;const kt=T.useRef(k);kt.current=k;const Ie=T.useRef(null),he=T.useRef(new Map),bt=T.useRef(0),de=T.useCallback(()=>{Ie.current!=null&&(window.clearInterval(Ie.current),Ie.current=null)},[]),J=T.useCallback(A=>{a.current?.contentWindow?.postMessage(A,Xt)},[]),nt=T.useRef(!1),st=T.useRef(null),rt=T.useCallback(()=>{nt.current||t!=="panel"||(nt.current=!0,st.current=Fs(D.current,A=>new Promise(K=>{bt.current+=1;const ee=`resolve-${bt.current}`,we=window.setTimeout(()=>{he.current.delete(ee),K({ok:!1,reason:"timeout"})},qs);he.current.set(ee,ke=>{window.clearTimeout(we),he.current.delete(ee),K(ke)}),a.current?.contentWindow?.postMessage(Ao(ee,A.command,A.args),Xt)})))},[t]);T.useEffect(()=>()=>{st.current?.(),st.current=null,nt.current=!1;for(const A of he.current.values())A({ok:!1,reason:"unavailable"});he.current.clear()},[Ee]);const Te=T.useCallback(()=>{J(wo(fe.current)),J(ko(ae.current||null)),J(bo(fe.current.session)),J(xo(fe.current.connection)),J(_o(fe.current.settings)),J(vo(fe.current.item))},[J]);return T.useEffect(()=>{u?.integration&&b(u.id)},[u?.id,u?.integration,b]),T.useEffect(()=>{u&&!c&&i?.()},[u,c,i]),T.useEffect(()=>{const A=new Map;let K=!1;const ee=z(),we=D.current,ke=()=>je.getState().guests.find(ye=>ye.id===we)??null,Oe=()=>{for(const ye of A.values())ye();A.clear()},Cn=We(()=>{K=!0,Oe(),de()}),Pe=()=>{if(!ce(ke(),"sessions"))throw new $("NOT_GRANTED",Se)},xt=ye=>{const ot=a.current;if(!ot||ye.source!==ot.contentWindow)return;const _t=To.safeParse(ye.data);if(!_t.success||K||z()!==ee)return;const Ce=ga(_t.data,D.current),vt=ke();if(!vt||!Mt(vt)){Oe(),"id"in Ce&&J({channel:q,v:X,type:"result",id:Ce.id,ok:!1,error:"Extension is unavailable.",code:"DISABLED"});return}if(Ce.type==="hello"){Et(),Oe(),Te(),rt();return}Co(Ce,{workspaceRead:m=>(Pe(),ft(m,D.current)),workspaceSubscribe:({subscriptionId:m,query:P})=>{if(Pe(),A.get(m)?.(),A.delete(m),A.size>=32)throw new $("HOST_REJECTED","At most 32 workspace subscriptions per frame.");A.set(m,ta(P,D.current,U=>{!K&&ce(ue.current,"sessions")&&J({channel:q,v:X,type:"workspace",payload:{subscriptionId:m,snapshot:U}})}))},workspaceUnsubscribe:m=>{A.get(m)?.(),A.delete(m)},storage:m=>fa(D.current,m),openSession:m=>{Pe(),na(m)},toast:(m,P)=>{ie.current&&(m==="success"?F.success(P):m==="error"?F.error(P):F.info(P))},openUrl:jt,openSurface:m=>{const P=ae.current||"";P&&ze.getState().openContextSurface(P,m)},writeClipboard:async m=>(await Js(m)).ok,compose:(m,P)=>{at.getState().setPendingInputText(m,P)},attach:m=>{if(et.current){et.current(m);return}at.getState().setPendingGuestIssue(m)},startSession:async m=>{if(!ce(ue.current,"sessions")||m.text&&!ce(ue.current,"prompt"))return{ok:!1,code:"NOT_GRANTED",message:Se};const P=await ma({request:m,directory:ae.current||null,t:Re.current,assertAuthorized:()=>{if(Pe(),m.text&&!ce(ke(),"prompt"))throw new $("NOT_GRANTED",Se)}});return P?.sessionId&&m.navigation==="open"&&(kt.current?.(),tt.current?.()),P},prompt:m=>m.send&&!ce(ue.current,"prompt")?Promise.resolve({ok:!1,code:"NOT_GRANTED",message:Se}):pa({request:m,sessionId:Qe.current,directory:ae.current||null,busy:Tt.current,compose:(P,U)=>{at.getState().setPendingInputText(P,U)},t:Re.current}),sessionLink:m=>ua({request:m,sessionId:Qe.current,directory:ae.current||null,t:Re.current}),close:()=>{tt.current?.()},oauthStart:async()=>{if(!ie.current)return!1;const m=D.current,P=Ge.getState().byId[m]?.connection??Dt,U=await gr(m);if(!U||K||z()!==ee)return!1;jt(U),de();const Gn=Date.now()+Tr;return Ie.current=window.setInterval(()=>{(async()=>{if(Date.now()>Gn){de();return}const At=await b(m);At&&kr(P,At.connection)&&de()})()},wr),!0},oauthDisconnect:async()=>{const m=await Er(we);return!m||K||z()!==ee?!1:(w(we,m),!0)},request:async m=>{if(!ie.current)return{ok:!1,code:"DISABLED",message:"This extension is disabled in Settings → Extensions."};const P=await Yo(wt.current,m);if(P!==void 0)return P?{ok:!0,result:P}:{ok:!1,code:"HOST_REJECTED",message:"Request failed."};const U=await br(D.current,m);return U.ok||b(D.current),U},serviceRequest:m=>ie.current?Rr(D.current,m):Promise.resolve({ok:!1,code:"DISABLED",message:"This extension is disabled in Settings → Extensions."}),serviceStatus:()=>Ir(D.current),file:m=>{if(!ie.current)return Promise.resolve({ok:!1,code:"DISABLED",message:"This extension is disabled in Settings → Extensions."});const P=Xs(m.path);if(!ce(ue.current,P==="project"?"files":"filesystem"))return Promise.resolve({ok:!1,code:"NOT_GRANTED",message:Se});const U=ae.current||null;return P==="project"&&!U?Promise.resolve({ok:!1,code:"NO_DIRECTORY",message:"No project is open."}):Do(D.current,m,U)},generate:m=>ie.current?ce(ue.current,"model")?Bo(D.current,m,ae.current||null):Promise.resolve({ok:!1,code:"NOT_GRANTED",message:Se}):Promise.resolve({ok:!1,code:"DISABLED",message:"This extension is disabled in Settings → Extensions."}),setBadge:m=>{ie.current&&Ut.getState().setBadge(D.current,m)},resolveResult:(m,P)=>{const U=he.current.get(m);if(U){if("error"in P){U({ok:!1,reason:"error",message:P.error});return}U({ok:!0,item:P.item})}}}).then(m=>{m&&!K&&ot===a.current&&z()===ee&&J(m)})};return window.addEventListener("message",xt),()=>{K=!0,Oe(),Cn(),window.removeEventListener("message",xt)}},[Et,Ee,c,J,Te,b,rt,w,Ye,Ze,de]),T.useEffect(()=>()=>de(),[Ee,de]),T.useEffect(()=>{Te()},[Te,ge,I]),T.useEffect(()=>{p!=="ready"||u||un(e)},[p,u,e]),T.useEffect(()=>{!h||!re||J(Ro({sessionId:h,phase:re}))},[h,re,J]),!u&&p!=="ready"&&p!=="error"?null:!u||!Ye&&!Ze?te.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:E(u&&On==="loading"?"common.loading":"contextPanel.plugin.loadFailed")}):c?te.jsx("iframe",{ref:a,title:u.name,src:Ye||void 0,srcDoc:Ze,sandbox:"allow-scripts",className:$s("h-full w-full min-h-0 min-w-0 border-0 overflow-hidden",t==="dialog"?"bg-transparent":"bg-[var(--surface-background)]"),onLoad:()=>{Pn()||(Te(),rt())}},Ee):null},Pa=Object.freeze(Object.defineProperty({__proto__:null,PluginPane:Rn},Symbol.toStringTag,{value:"Module"})),Ea=e=>{const t=Jt.c(27),{guestId:n,item:o,onOpenChange:i,onAttach:f,onSessionStarted:k}=e,E=o===void 0?null:o,{t:_}=an();let S;t[0]!==n?(S=b=>n?b.guests.find(C=>C.id===n)??null:null,t[0]=n,t[1]=S):S=t[1];const I=je(S),h=!!n,O=I?.name??n;let g;t[2]!==O?(g=te.jsx(Ws,{children:O}),t[2]=O,t[3]=g):g=t[3];let a;t[4]!==E||t[5]!==_?(a=E===null||zs(E)?_("contextPanel.plugin.attachDialog.description"):_("contextPanel.plugin.actionDialog.description"),t[4]=E,t[5]=_,t[6]=a):a=t[6];let d;t[7]!==a?(d=te.jsx(Ks,{children:a}),t[7]=a,t[8]=d):d=t[8];let u;t[9]!==g||t[10]!==d?(u=te.jsxs(Vs,{className:"flex-shrink-0",children:[g,d]}),t[9]=g,t[10]=d,t[11]=u):u=t[11];let p;t[12]!==n||t[13]!==E||t[14]!==f||t[15]!==i||t[16]!==k?(p=n?te.jsx(Rn,{mode:cn(n),surface:"dialog",item:E,onDismiss:()=>i(!1),onAttach:f,onSessionStarted:k}):null,t[12]=n,t[13]=E,t[14]=f,t[15]=i,t[16]=k,t[17]=p):p=t[17];let c;t[18]!==p?(c=te.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden",children:p}),t[18]=p,t[19]=c):c=t[19];let y;t[20]!==c||t[21]!==u?(y=te.jsxs(Ys,{className:"flex h-[70vh] max-h-[70vh] max-w-2xl flex-col overflow-hidden",children:[u,c]}),t[20]=c,t[21]=u,t[22]=y):y=t[22];let w;return t[23]!==i||t[24]!==y||t[25]!==h?(w=te.jsx(Zs,{open:h,onOpenChange:i,children:y}),t[23]=i,t[24]=y,t[25]=h,t[26]=w):w=t[26],w},Ca=Object.freeze(Object.defineProperty({__proto__:null,GuestAttachDialog:Ea},Symbol.toStringTag,{value:"Module"}));export{Tr as A,Ea as G,Rn as P,ra as a,gr as b,kr as c,Er as d,wr as e,Aa as f,sa as g,va as h,Oa as i,Ia as j,Pa as k,Ca as l,Ra as s,Ge as u};
|