@vantran-se/openchamber-web 2.1.1 → 2.2.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/README.md +32 -24
- package/bin/cli.js +1 -3
- package/bin/cli.test.js +40 -16
- package/bin/lib/DOCUMENTATION.md +6 -5
- package/bin/lib/cli-args.js +6 -1
- package/bin/lib/cli-args.test.js +34 -0
- package/bin/lib/cli-lifecycle.js +0 -1
- package/bin/lib/cli-network.js +8 -2
- package/bin/lib/cli-process.js +1 -1
- package/bin/lib/cli-settings-accessors.test.js +21 -13
- package/bin/lib/cli-startup.js +17 -11
- package/bin/lib/cli-startup.test.js +92 -2
- package/bin/lib/commands-connect-url.js +8 -1
- package/bin/lib/commands-schedule.js +8 -2
- package/bin/lib/commands-serve.js +15 -21
- package/bin/lib/commands-update.js +12 -24
- package/bin/lib/commands-update.test.js +14 -46
- package/dist/assets/DiffView-Cv9MSXl1.js +4 -0
- package/dist/assets/FilePreviewCommentMenu-D4kLseHj.js +4 -0
- package/dist/assets/FilesView-BVoD8I2x.js +14 -0
- package/dist/assets/{GitView-DzuzhIPx.js → GitView-Bzb8p-ew.js} +4 -4
- package/dist/assets/GuestSurfacePane-Crdbvsxo.js +1 -0
- package/dist/assets/InProgressOperationBanner-CwMjNQgk.js +2 -0
- package/dist/assets/{JsonTreeView-B_EPRjzy.js → JsonTreeView-DRKHZfsn.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DZtqT1Zn.js +1 -0
- package/dist/assets/MarkdownRendererImpl-CqG7HCNd.js +10 -0
- package/dist/assets/OnboardingScreen-DMIxwYK5.js +1 -0
- package/dist/assets/{PatchDiff-6yh1csza.js → PatchDiff-CUcCg1jk.js} +1 -1
- package/dist/assets/PierreDiffViewer-CnnR-dnD.js +228 -0
- package/dist/assets/PlanView-RCBadcY7.js +5 -0
- package/dist/assets/SettingsView-CjBjZFRO.js +30 -0
- package/dist/assets/SettingsWindow-DyM7QuhI.js +1 -0
- package/dist/assets/SubmoduleDiffSummary-BWIfgMED.js +1 -0
- package/dist/assets/ToolOutputDialog-Q0P3FuAi.js +15 -0
- package/dist/assets/ToolPartDiffPreview-p7qR9FpU.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-BTJVRkyo.js → VirtualizedFileDiff-CFpjL8Ns.js} +3 -3
- package/dist/assets/{Virtualizer-xCEYz34p.js → Virtualizer-C0IsclZn.js} +1 -1
- package/dist/assets/WalkthroughView-DI31zD02.js +4 -0
- package/dist/assets/appThemeRegistry-B9gkFq9i.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-CmPe29DM.js → computeVirtualFileMetrics-C2WM6JC2.js} +2 -2
- package/dist/assets/de-YKfk5MmC.js +14 -0
- package/dist/assets/es-_gwT0kr-.js +20 -0
- package/dist/assets/fileTreeStatus-D438yi8M.js +1 -0
- package/dist/assets/fr-DqzvXmIm.js +18 -0
- package/dist/assets/index-BLaHKdtx.js +1 -0
- package/dist/assets/index-BkMXRrVQ.css +1 -0
- package/dist/assets/index-DxNa7xYB.js +65 -0
- package/dist/assets/initializeSharedPreferences-Bck5EAWP.js +1 -0
- package/dist/assets/{isDiffPlainText-CQmDCnEv.js → isDiffPlainText-Dgbw8VKk.js} +1 -1
- package/dist/assets/{isFilePlainText-CYBUzW4I.js → isFilePlainText-_ZS5UYRj.js} +1 -1
- package/dist/assets/ja-B-GFYhQE.js +20 -0
- package/dist/assets/ko-mzksfqDC.js +20 -0
- package/dist/assets/main-C5Xx8dn_.js +2 -0
- package/dist/assets/main-CfBSQM1H.js +990 -0
- package/dist/assets/markdownCore-BmWwW1ll.js +7 -0
- package/dist/assets/miniChat-mnKwy4vQ.js +2 -0
- package/dist/assets/mobile-DeEQd0wZ.js +2 -0
- package/dist/assets/nl-CWQr6NSq.js +20 -0
- package/dist/assets/{parseDiffFromFile-Cy0PNxun.js → parseDiffFromFile-BUgn-T9p.js} +2 -2
- package/dist/assets/patchFileDiff-Dt8LhgBh.js +13 -0
- package/dist/assets/pl-UmRcDUX2.js +20 -0
- package/dist/assets/pt-BR-BSLybvVF.js +20 -0
- package/dist/assets/relocateRestoredSession-B5E9xb3T.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-C0a9A5_J.js +2 -0
- package/dist/assets/renderMobileApp-BNncg3Pk.js +25 -0
- package/dist/assets/runtimeEndpointReset-CZ5aafpl.js +62 -0
- package/dist/assets/{selectionMarkdown-TkYk5h9l.js → selectionMarkdown-CUN3wUld.js} +9 -9
- package/dist/assets/{sessionOwnership-Bs1xbRfB.js → sessionOwnership-BSuxCEhb.js} +1 -1
- package/dist/assets/shikiHighlight-DHDx-6eM.js +1 -0
- package/dist/assets/space-apply-DM_2pRW7.js +1 -0
- package/dist/assets/space-close-Bpomt8z0.js +1 -0
- package/dist/assets/{surface-B6n7wJtt.js → surface-C-jQaGnL.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-CDlKffWz.js → textMateThemeFromAppTheme-DlsTphbY.js} +1 -1
- package/dist/assets/tr-gaTrX_HK.js +11 -0
- package/dist/assets/uk-CnJF6ykl.js +20 -0
- package/dist/assets/{useAppFontEffects-DCqCVGlT.js → useAppFontEffects-DGlvOqP_.js} +194 -233
- package/dist/assets/useInlineCommentController-kMN4Wg_D.js +2 -0
- package/dist/assets/{useRootScrollLock-BowwS8kq.js → useRootScrollLock-DMPpvpNP.js} +2 -2
- package/dist/assets/{vendor-base-ui-DX96QhTP.js → vendor-base-ui-Det7U81h.js} +1 -1
- package/dist/assets/{vendor-codemirror-autocomplete-DW1FQz9_.js → vendor-codemirror-autocomplete-BSHQHbKu.js} +1 -1
- package/dist/assets/{vendor-codemirror-commands-DpmhalwN.js → vendor-codemirror-commands-C4G_dPWe.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-BqExbN1M.js → vendor-codemirror-lang-angular-B6LbBGHB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-DZA36HfS.js → vendor-codemirror-lang-cpp-BWWXBx7W.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-B07blnnZ.js → vendor-codemirror-lang-css-Cayfb29q.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-BM8K9D1-.js → vendor-codemirror-lang-go-BoKlCNKw.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-DaH9adfE.js → vendor-codemirror-lang-html-BQWerHsJ.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-CsdC0viz.js → vendor-codemirror-lang-java-DWX7Fq_K.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-CpGYXGuo.js → vendor-codemirror-lang-javascript-DbpEcZM0.js} +2 -2
- package/dist/assets/{vendor-codemirror-lang-jinja-BBeGzXw5.js → vendor-codemirror-lang-jinja-D1JIJRA7.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-58T70Hqs.js → vendor-codemirror-lang-json-BzgckzmB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-BI-xCA59.js → vendor-codemirror-lang-less-B9EpDXFi.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-zEcMa-zy.js → vendor-codemirror-lang-liquid-9U7kRbSf.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-BLKnlLP4.js → vendor-codemirror-lang-markdown-D2TEBIvZ.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-9f35M83-.js → vendor-codemirror-lang-php-BT6sDVzE.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-python-jAMtYiA9.js +3 -0
- package/dist/assets/{vendor-codemirror-lang-rust-MNDL_jZQ.js → vendor-codemirror-lang-rust-CVO56EiL.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-p9epsSNm.js → vendor-codemirror-lang-sass-DZlOoUWu.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-Bqzh0EXX.js → vendor-codemirror-lang-sql-fZ6t1DPw.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-BnNUWV-p.js → vendor-codemirror-lang-vue-DxbqrLiE.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-C2a-oLmk.js → vendor-codemirror-lang-wast-DyU1Gt-I.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-xml-C9a_K5_p.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-yaml-C0sjswB0.js → vendor-codemirror-lang-yaml-Cptq8l0e.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-ByBn5zIW.js → vendor-codemirror-language-DufXoQvE.js} +2 -2
- package/dist/assets/vendor-codemirror-language-data-CtwSWKtX.js +2 -0
- package/dist/assets/{vendor-codemirror-search-ib-sHD5W.js → vendor-codemirror-search-CvXM_pZg.js} +1 -1
- package/dist/assets/{vendor-codemirror-state-G3UuR-be.js → vendor-codemirror-state-Dek9sMtw.js} +1 -1
- package/dist/assets/{vendor-codemirror-view-Bniqp7p5.js → vendor-codemirror-view-1e0FQ6Wn.js} +1 -1
- package/dist/assets/vendor-framer-motion-DxDVhOLc.js +9 -0
- package/dist/assets/vendor-katex-CuQvj9-L.js +257 -0
- package/dist/assets/vendor-katex-DdZNUVNG.css +1 -0
- package/dist/assets/{vendor-motion-dom-DcCgeG69.js → vendor-motion-dom-HXPOMxb7.js} +1 -1
- package/dist/assets/{vendor-opencode-client-DHzhmLwV.js → vendor-opencode-client-BmFcUkbQ.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-DkzqxN2H.js → vendor-replit-codemirror-vim-BlJRn-cW.js} +2 -2
- package/dist/assets/{vendor-tanstack-react-virtual-H_JmXOFV.js → vendor-tanstack-react-virtual-CvuLsk7D.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-Dxc8hSTB.js → vendor-tanstack-virtual-core-DPaNcJcT.js} +1 -1
- package/dist/assets/zh-CN-t2vigSB1.js +20 -0
- package/dist/assets/zh-TW-jAgqBokB.js +20 -0
- package/dist/index.html +6 -6
- package/dist/mini-chat.html +6 -6
- package/dist/mobile.html +6 -6
- package/package.json +8 -5
- package/server/index.js +80 -36
- package/server/lib/agent-memory/actions.js +1 -6
- package/server/lib/agent-memory/routes.js +1 -2
- package/server/lib/agent-memory/runtime.js +1 -8
- package/server/lib/agent-tool/DOCUMENTATION.md +7 -3
- package/server/lib/agent-tool/runtime.js +3 -6
- package/server/lib/agent-tool/runtime.test.js +0 -2
- package/server/lib/browser-control/DOCUMENTATION.md +6 -0
- package/server/lib/changelog/update-notes.js +1 -1
- package/server/lib/context-obligatory/runtime.js +1 -2
- package/server/lib/dev-tunnel/DOCUMENTATION.md +8 -0
- package/server/lib/dev-tunnel/client.js +21 -10
- package/server/lib/dev-tunnel/tunnel.test.js +34 -0
- package/server/lib/dispatch-results/runtime.js +1 -1
- package/server/lib/enterprise-mode.d.ts +1 -0
- package/server/lib/enterprise-mode.js +13 -2
- package/server/lib/enterprise-mode.test.js +21 -0
- package/server/lib/event-stream/DOCUMENTATION.md +2 -2
- package/server/lib/event-stream/index.js +1 -3
- package/server/lib/event-stream/translate-v2.js +1 -9
- package/server/lib/event-stream/translate-v2.test.js +0 -11
- package/server/lib/fs/DOCUMENTATION.md +5 -2
- package/server/lib/fs/routes.js +62 -15
- package/server/lib/fs/routes.test.js +278 -48
- package/server/lib/fs/workspace-file-names.js +104 -0
- package/server/lib/fs/workspace-file-names.test.js +62 -0
- package/server/lib/git/DOCUMENTATION.md +17 -5
- package/server/lib/git/contributor-provenance-storage.js +9 -6
- package/server/lib/git/contributor-provenance-storage.test.js +29 -0
- package/server/lib/git/credential-broker.js +1 -1
- package/server/lib/git/credential-resolver.js +1 -4
- package/server/lib/git/credentials.js +1 -0
- package/server/lib/git/discovery-endpoint.js +1 -1
- package/server/lib/git/identity-provisioning.js +2 -1
- package/server/lib/git/identity-storage.js +3 -4
- package/server/lib/git/lfs-discovery.js +14 -14
- package/server/lib/git/lfs-discovery.test.js +16 -6
- package/server/lib/git/network-operation-plan.js +50 -62
- package/server/lib/git/network-operation-plan.test.js +103 -1
- package/server/lib/git/network-operation-registry.js +4 -6
- package/server/lib/git/network-operation-storage.js +4 -6
- package/server/lib/git/network-operations.js +12 -4
- package/server/lib/git/network-operations.test.js +19 -6
- package/server/lib/git/redaction.js +2 -1
- package/server/lib/git/repository-credential-runtime.js +5 -3
- package/server/lib/git/repository-credential-runtime.test.js +22 -0
- package/server/lib/git/routes.js +31 -137
- package/server/lib/git/routes.test.js +2 -2
- package/server/lib/git/service.js +143 -27
- package/server/lib/git/service.test.js +215 -1
- package/server/lib/git/ssh-credential-storage.js +1 -4
- package/server/lib/git/submodule-discovery.js +1 -1
- package/server/lib/git/worktree-bootstrap-storage.js +3 -4
- package/server/lib/git/worktree-bootstrap-storage.test.js +15 -0
- package/server/lib/git/worktree-creation.js +194 -0
- package/server/lib/git/worktree-creation.test.js +155 -0
- package/server/lib/github/DOCUMENTATION.md +11 -6
- package/server/lib/github/auth.js +2 -4
- package/server/lib/github/device-flow.js +2 -2
- package/server/lib/github/gh-cli-credential.js +1 -0
- package/server/lib/github/octokit.js +31 -0
- package/server/lib/github/pr-status.js +35 -18
- package/server/lib/github/pr-status.test.js +271 -3
- package/server/lib/github/reference-search.js +102 -13
- package/server/lib/github/reference-search.test.js +48 -7
- package/server/lib/github/routes.auth.test.js +18 -0
- package/server/lib/github/routes.js +360 -6
- package/server/lib/github/routes.mutations.test.js +239 -0
- package/server/lib/github/routes.test.js +134 -2
- package/server/lib/gitlab/DOCUMENTATION.md +5 -1
- package/server/lib/gitlab/auth-storage.test.js +1 -0
- package/server/lib/gitlab/mappers.js +30 -1
- package/server/lib/gitlab/resources.js +230 -6
- package/server/lib/gitlab/resources.test.js +179 -0
- package/server/lib/gitlab/routes.js +200 -6
- package/server/lib/gitlab/routes.test.js +186 -2
- package/server/lib/gitlab/validation.js +1 -5
- package/server/lib/guests/DOCUMENTATION.md +1 -1
- package/server/lib/guests/oauth.js +2 -2
- package/server/lib/guests/service.js +1 -1
- package/server/lib/guests/sockets.js +1 -1
- package/server/lib/injected-env.d.ts +8 -0
- package/server/lib/injected-env.js +50 -0
- package/server/lib/injected-env.test.js +56 -0
- package/server/lib/linear/DOCUMENTATION.md +5 -6
- package/server/lib/linear/issues.js +62 -4
- package/server/lib/linear/issues.test.js +68 -0
- package/server/lib/linear/oauth.js +5 -5
- package/server/lib/linear/parse.js +2 -9
- package/server/lib/message-queue/DOCUMENTATION.md +23 -1
- package/server/lib/message-queue/runtime.js +85 -12
- package/server/lib/message-queue/runtime.test.js +172 -2
- package/server/lib/notifications/apns-runtime.js +5 -6
- package/server/lib/notifications/apns-runtime.test.js +20 -4
- package/server/lib/openchamber-control/DOCUMENTATION.md +19 -1
- package/server/lib/openchamber-control/actions.js +2 -1
- package/server/lib/openchamber-control/service.js +119 -20
- package/server/lib/openchamber-control/service.test.js +166 -0
- package/server/lib/openchamber-sessions/archive-store.js +1 -6
- package/server/lib/openchamber-sessions/routes.js +47 -12
- package/server/lib/openchamber-sessions/routes.test.js +65 -2
- package/server/lib/openchamber-sessions/session-metadata-store.js +1 -6
- package/server/lib/opencode/DOCUMENTATION.md +22 -8
- package/server/lib/opencode/agents.js +62 -0
- package/server/lib/opencode/auth-state-runtime.js +3 -1
- package/server/lib/opencode/auth.d.ts +1 -1
- package/server/lib/opencode/auth.js +8 -0
- package/server/lib/opencode/auth.test.js +31 -0
- package/server/lib/opencode/config-entity-routes.js +16 -0
- package/server/lib/opencode/config-entity-v2.test.js +16 -1
- package/server/lib/opencode/config-paths.test.js +2 -2
- package/server/lib/opencode/config-v2.js +2 -4
- package/server/lib/opencode/feature-routes-runtime.js +89 -49
- package/server/lib/opencode/lifecycle.js +41 -21
- package/server/lib/opencode/lifecycle.test.js +50 -2
- package/server/lib/opencode/model-discovery.js +1 -1
- package/server/lib/opencode/model-discovery.test.js +17 -0
- package/server/lib/opencode/models-metadata.js +0 -2
- package/server/lib/opencode/openchamber-routes.test.js +3 -3
- package/server/lib/opencode/plugins.js +6 -9
- package/server/lib/opencode/provider-source-route.test.js +101 -3
- package/server/lib/opencode/providers-disabled.test.js +59 -0
- package/server/lib/opencode/providers.js +34 -0
- package/server/lib/opencode/proxy.js +11 -3
- package/server/lib/opencode/routes.js +40 -2
- package/server/lib/opencode/settings-helpers.js +27 -1
- package/server/lib/opencode/settings-helpers.test.js +19 -7
- package/server/lib/opencode/settings-registry.json +27 -16
- package/server/lib/opencode/settings-runtime.test.js +18 -0
- package/server/lib/opencode/shared-service-runtime.js +23 -104
- package/server/lib/opencode/shared.js +77 -46
- package/server/lib/opencode/shared.test.js +12 -12
- package/server/lib/opencode/shutdown-runtime.test.js +2 -3
- package/server/lib/opencode/skill-routes.js +123 -38
- package/server/lib/opencode/skill-routes.test.js +201 -0
- package/server/lib/opencode/skills.js +81 -34
- package/server/lib/opencode/skills.test.js +176 -21
- package/server/lib/opencode/startup-pipeline-runtime.js +6 -3
- package/server/lib/opencode/startup-pipeline-runtime.test.js +2 -1
- package/server/lib/opencode/watcher.test.js +0 -54
- package/server/lib/outbound-proxy.js +52 -0
- package/server/lib/outbound-proxy.test.js +55 -0
- package/server/lib/package-manager.js +23 -17
- package/server/lib/package-manager.test.js +5 -18
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +1 -1
- package/server/lib/permission-auto-accept/runtime.js +19 -47
- package/server/lib/permission-auto-accept/runtime.test.js +2 -2
- package/server/lib/project-context/DOCUMENTATION.md +7 -1
- package/server/lib/project-context/routes.js +1 -2
- package/server/lib/project-context/runtime.js +12 -14
- package/server/lib/project-context/runtime.test.js +78 -2
- package/server/lib/projects/project-config.js +30 -15
- package/server/lib/projects/project-config.test.js +30 -0
- package/server/lib/projects/project-setup.js +1 -2
- package/server/lib/projects/routes.js +1 -2
- package/server/lib/quota/DOCUMENTATION.md +35 -7
- package/server/lib/quota/index.js +1 -0
- package/server/lib/quota/providers/claude/index.js +1 -1
- package/server/lib/quota/providers/cline-pass.js +1 -1
- package/server/lib/quota/providers/exe-dev.js +1 -1
- package/server/lib/quota/providers/google/index.js +1 -1
- package/server/lib/quota/providers/hyper.js +1 -1
- package/server/lib/quota/providers/kimi.js +116 -36
- package/server/lib/quota/providers/kimi.test.js +128 -3
- package/server/lib/quota/providers/opencode-go.js +144 -21
- package/server/lib/quota/providers/opencode-go.test.js +229 -6
- package/server/lib/quota/providers/openrouter.js +1 -1
- package/server/lib/quota/providers/zenmux.js +1 -1
- package/server/lib/quota/utils/auth.js +1 -0
- package/server/lib/quota/utils/transformers.js +2 -6
- package/server/lib/relay/DOCUMENTATION.md +18 -3
- package/server/lib/relay/e2ee.js +7 -7
- package/server/lib/relay/host-client.js +84 -13
- package/server/lib/relay/host-client.test.js +201 -1
- package/server/lib/relay/identity.js +6 -29
- package/server/lib/relay/identity.test.js +18 -28
- package/server/lib/relay/key-store.js +141 -0
- package/server/lib/relay/key-store.test.js +138 -0
- package/server/lib/relay/service.js +8 -8
- package/server/lib/relay/service.test.js +10 -5
- package/server/lib/relay/signing-key.js +13 -36
- package/server/lib/relay/tunnel-codec.js +10 -10
- package/server/lib/route-module-exports.test.js +22 -0
- package/server/lib/routing/DOCUMENTATION.md +23 -3
- package/server/lib/routing/cache.js +87 -0
- package/server/lib/routing/defaults.js +11 -0
- package/server/lib/routing/history.js +12 -4
- package/server/lib/routing/runtime.js +39 -3
- package/server/lib/routing/runtime.test.js +81 -2
- package/server/lib/routing/store.js +12 -1
- package/server/lib/routing/store.test.js +13 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +59 -1
- package/server/lib/scheduled-tasks/existing-session.js +119 -0
- package/server/lib/scheduled-tasks/existing-session.test.js +350 -0
- package/server/lib/scheduled-tasks/loops.js +1 -8
- package/server/lib/scheduled-tasks/routes.js +8 -8
- package/server/lib/scheduled-tasks/runtime.js +103 -13
- package/server/lib/scheduled-tasks/runtime.test.js +48 -0
- package/server/lib/scheduled-tasks/service.js +33 -11
- package/server/lib/scheduled-tasks/service.test.js +128 -2
- package/server/lib/scheduled-tasks/session-defaults.js +27 -0
- package/server/lib/scheduled-tasks/session-defaults.test.js +19 -0
- package/server/lib/session-assist/context.js +1 -0
- package/server/lib/session-folders/routes.js +2 -2
- package/server/lib/session-goal/objectives.js +1 -1
- package/server/lib/session-knowledge/routes.js +2 -2
- package/server/lib/session-knowledge/runtime.js +1 -2
- package/server/lib/session-work/DOCUMENTATION.md +39 -14
- package/server/lib/session-work/questions.js +31 -2
- package/server/lib/session-work/runtime.js +22 -13
- package/server/lib/session-work/runtime.test.js +43 -26
- package/server/lib/session-work/state.js +10 -4
- package/server/lib/session-work/state.test.js +8 -1
- package/server/lib/shared/DOCUMENTATION.md +89 -0
- package/server/lib/shared/guards.js +53 -0
- package/server/lib/shared/guards.test.js +112 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +10 -8
- package/server/lib/skills-catalog/cache.js +3 -2
- package/server/lib/skills-catalog/curated-sources.js +5 -1
- package/server/lib/skills-catalog/git.js +107 -20
- package/server/lib/skills-catalog/git.test.js +78 -0
- package/server/lib/skills-catalog/install.js +21 -12
- package/server/lib/skills-catalog/scan.js +25 -15
- package/server/lib/skills-catalog/source.js +26 -1
- package/server/lib/skills-catalog/source.test.js +27 -0
- package/server/lib/source-control/DOCUMENTATION.md +2 -1
- package/server/lib/source-control/audit-storage.js +7 -6
- package/server/lib/source-control/audit-storage.test.js +11 -0
- package/server/lib/source-control/binding-service.js +2 -5
- package/server/lib/source-control/change-request-worktree.js +90 -0
- package/server/lib/source-control/change-request-worktree.test.js +121 -0
- package/server/lib/source-control/mutation-executor.js +1 -1
- package/server/lib/source-control/mutation-storage.js +11 -5
- package/server/lib/source-control/provider-instance.js +1 -2
- package/server/lib/source-control/repository-identity.js +1 -1
- package/server/lib/source-control/routes.js +14 -2
- package/server/lib/spaces/DOCUMENTATION.md +42 -17
- package/server/lib/spaces/command-stream.test.js +15 -0
- package/server/lib/spaces/dispatcher.js +7 -0
- package/server/lib/spaces/dispatcher.test.js +17 -0
- package/server/lib/spaces/hardening.js +2 -2
- package/server/lib/spaces/hardening.test.js +1 -1
- package/server/lib/spaces/host.js +2 -0
- package/server/lib/spaces/journey.js +66 -5
- package/server/lib/spaces/journey.test.js +95 -4
- package/server/lib/spaces/layout.js +1 -1
- package/server/lib/spaces/places/docker-disk.js +38 -14
- package/server/lib/spaces/places/docker-disk.test.js +80 -1
- package/server/lib/spaces/places/docker.js +35 -11
- package/server/lib/spaces/places/fake-docker.js +22 -3
- package/server/lib/spaces/places/memory-place.js +3 -0
- package/server/lib/spaces/places/packed.docker.live.test.js +1 -1
- package/server/lib/spaces/routes.js +5 -0
- package/server/lib/spaces/routes.test.js +4 -2
- package/server/lib/spaces/run-command.js +9 -2
- package/server/lib/spaces/tools.js +4 -5
- package/server/lib/spaces/tools.test.js +2 -2
- package/server/lib/terminal/runtime.js +18 -6
- package/server/lib/terminal/runtime.test.js +66 -0
- package/server/lib/tts/index.js +3 -0
- package/server/lib/tts/service.js +4 -2
- package/server/lib/walkthrough/DOCUMENTATION.md +3 -1
- package/server/lib/walkthrough/index.js +2 -3
- package/server/lib/walkthrough/pr-source.test.js +22 -0
- package/server/lib/walkthrough/sources.js +6 -1
- package/server/opencode-proxy.test.js +127 -0
- package/bin/lib/commands-startup.test.js +0 -15
- package/dist/assets/CodeMirrorCommentWidgets-CVDSjcrP.js +0 -1
- package/dist/assets/DiffView-Ct7vL3fD.js +0 -4
- package/dist/assets/FilesView-DT0uEYgT.js +0 -17
- package/dist/assets/GuestSurfacePane-DVvk1VPu.js +0 -1
- package/dist/assets/LinearIssuesView-C10MwA9h.js +0 -1
- package/dist/assets/MarkdownImageGallery-BbN_K_3d.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BLt2Tkk9.js +0 -10
- package/dist/assets/OnboardingScreen-Bgp5A3WB.js +0 -1
- package/dist/assets/PierreDiffViewer-CWJLj-S-.js +0 -210
- package/dist/assets/PlanView-DsRWnsOI.js +0 -5
- package/dist/assets/PublishDialog-CCeKloRu.js +0 -2
- package/dist/assets/SettingsView-BuPPsNPp.js +0 -30
- package/dist/assets/SettingsWindow-CM5fL8Ot.js +0 -1
- package/dist/assets/SubmoduleDiffSummary-CfsMcfiQ.js +0 -1
- package/dist/assets/ToolOutputDialog-mZrfSofz.js +0 -15
- package/dist/assets/ToolPartDiffPreview-BUGCRYEL.js +0 -8
- package/dist/assets/WalkthroughView-ClBo7PPd.js +0 -4
- package/dist/assets/appThemeRegistry-CxzMxR-H.js +0 -1
- package/dist/assets/de-CBla4hjd.js +0 -14
- package/dist/assets/es-BmnZtxTD.js +0 -20
- package/dist/assets/fileTreeStatus-BSHFIGEg.js +0 -1
- package/dist/assets/fr-OVKIBUZO.js +0 -18
- package/dist/assets/index-CKCFKmjF.js +0 -1
- package/dist/assets/index-Dbx4V4GN.css +0 -1
- package/dist/assets/index-vQ1Pg1cr.js +0 -61
- package/dist/assets/ja-6v-yr-gE.js +0 -20
- package/dist/assets/ko-I_ZLvgQ9.js +0 -20
- package/dist/assets/main-CmO4dRtR.js +0 -2
- package/dist/assets/main-b9vqhlYM.js +0 -999
- package/dist/assets/markdownCore-BPEZRQfP.js +0 -7
- package/dist/assets/miniChat-B5Oi7B-6.js +0 -2
- package/dist/assets/mobile-CVtShif9.js +0 -2
- package/dist/assets/nl-DcvIJf46.js +0 -20
- package/dist/assets/patchFileDiff-CW3wCH1O.js +0 -13
- package/dist/assets/pl-JxCUl0sd.js +0 -20
- package/dist/assets/pt-BR-L89mjja2.js +0 -20
- package/dist/assets/relocateRestoredSession-DYh_9oBa.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-BD-1JHSg.js +0 -2
- package/dist/assets/renderMobileApp-7s5InXt1.js +0 -25
- package/dist/assets/runtimeEndpointReset-DqLJC6L1.js +0 -53
- package/dist/assets/shikiHighlight-CXgZnvHh.js +0 -1
- package/dist/assets/space-apply-1trGVIl8.js +0 -1
- package/dist/assets/space-close-y7j-NuBv.js +0 -1
- package/dist/assets/tr-ka5J1flt.js +0 -11
- package/dist/assets/uk-PyGe6Q_u.js +0 -20
- package/dist/assets/useInlineCommentController-CrjSGCpi.js +0 -2
- package/dist/assets/vendor-codemirror-lang-python-B7ClrMIT.js +0 -3
- package/dist/assets/vendor-codemirror-lang-xml-C8tGnS64.js +0 -1
- package/dist/assets/vendor-codemirror-language-data-q2bKO1EM.js +0 -2
- package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +0 -1
- package/dist/assets/vendor-katex-CHD9BdDO.js +0 -257
- package/dist/assets/vendor-katex-Cp579UoJ.css +0 -1
- package/dist/assets/zh-CN-B0P2tybJ.js +0 -20
- package/dist/assets/zh-TW-Bs9C5cN8.js +0 -20
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{R as i,r as ue,j as t,f as Gt}from"./vendor-react-BUCujlKS.js";import{h as wa,u as Et,o as De,a as dt,A as ba}from"./index-vQ1Pg1cr.js";import{f as ot,z as it,al as Lt,lN as va,gI as Fr,ds as Dr,t as g,I as E,aT as $s,aU as Ws,aV as en,aW as Us,e0 as Ks,e1 as qs,e2 as Js,e3 as Ys,e4 as ns,dS as as,B as K,lO as ja,lP as Ca,cy as mt,cz as ht,cA as ft,cB as gt,cC as vt,a8 as Br,av as is,aw as os,ax as ls,lQ as Sa,h as me,lR as Na,lS as ka,lT as Va,lU as Ra,bN as Ia,a_ as Pa,cT as Fa,lV as Da,lW as Ba,lX as Ma,lY as Aa,lZ as Oa,l_ as Ea,l$ as Ta,cE as tn,cZ as La,c_ as Ga,c$ as za,d0 as _a,d1 as Ha,d4 as $a,cD as Hs,gk as Wa,X as we,N as Ua,aA as Ka,aB as qa,K as Ja,aC as Ya,ci as Qa,m0 as Za,aD as Xa,m1 as ei,aE as ti,aJ as si,m2 as ri,L as ni,aK as ai,aM as ii,aZ as oi,aG as Mr,cN as ts,cO as Ar,cP as Or,kI as li,m3 as ci,l as di,d8 as ui,g as mi,dU as hi,aR as Er,aF as fi,aH as gi,aI as pi,aL as xi,az as yi,b2 as Tr,an as wi,kz as bi,m4 as vi,b0 as ji,m5 as Ls,b1 as Ci,V as At,W as Lr}from"./useAppFontEffects-DCqCVGlT.js";import{u as Si,a as Ni}from"./main-b9vqhlYM.js";import{au as ki,at as Vi,as as Ri,m as Ii,n as Pi,t as Fi,av as Di,o as Gs,y as Bi,bf as Mi,G as Ai,x as Oi}from"./runtimeEndpointReset-DqLJC6L1.js";import{u as Gr}from"./vendor-zustand-BAGL70zf.js";import{u as Ei,a as Ti,R as Li,I as Gi,b as zi,c as _i,P as Hi,C as $i,d as Wi,D as Ui}from"./PublishDialog-CCeKloRu.js";import{P as Ki}from"./PierreDiffViewer-CWJLj-S-.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-CxRSdNoV.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-client-DHzhmLwV.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-base-ui-DX96QhTP.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.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-tanstack-react-virtual-H_JmXOFV.js";import"./vendor-tanstack-virtual-core-Dxc8hSTB.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.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-ByBn5zIW.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-G3UuR-be.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-Bniqp7p5.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-CpGYXGuo.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DW1FQz9_.js";import"./vendor-codemirror-lang-json-58T70Hqs.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-B07blnnZ.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-DaH9adfE.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BLKnlLP4.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-q2bKO1EM.js";import"./vendor-codemirror-lang-python-B7ClrMIT.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DpmhalwN.js";import"./vendor-legendapp-list-DViGR95I.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-katex-CHD9BdDO.js";import"./useRootScrollLock-BowwS8kq.js";import"./fileTreeStatus-BSHFIGEg.js";import"./space-apply-1trGVIl8.js";import"./sessionOwnership-Bs1xbRfB.js";import"./vendor-cron-parser-CjvYVigk.js";import"./vendor-luxon-BZ0puJYg.js";import"./changesTree-CePHbFcj.js";import"./parseDiffFromFile-Cy0PNxun.js";import"./computeVirtualFileMetrics-CmPe29DM.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"./vendor-diff-C3JhlQdm.js";import"./isDiffPlainText-CQmDCnEv.js";import"./VirtualizedFileDiff-BTJVRkyo.js";import"./Virtualizer-xCEYz34p.js";import"./useInlineCommentController-CrjSGCpi.js";import"./appThemeRegistry-CxzMxR-H.js";import"./textMateThemeFromAppTheme-CDlKffWz.js";const sn="gitmojiCache",qi=1e3*60*60*24*7,rn="1",Ji="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",nn=o=>{if(!o||typeof o!="object")return!1;const e=o;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},zs=()=>{if(typeof window>"u")return null;try{const o=window.localStorage.getItem(sn);if(!o)return null;const e=JSON.parse(o);return!e||e.version!==rn||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(nn),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Yi=o=>{if(!(typeof window>"u"))try{const e={gitmojis:o,fetchedAt:Date.now(),version:rn};window.localStorage.setItem(sn,JSON.stringify(e))}catch{return}},zr=o=>Date.now()-o.fetchedAt<qi;let ss=null;const Tt=new Set,_r=async()=>{if(ss)return ss;const o=(async()=>{try{const e=await fetch(Ji);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const a=await e.json(),f=Array.isArray(a.gitmojis)?a.gitmojis.filter(nn):[];return Yi(f),Tt.forEach(w=>w(f)),f}catch(e){console.warn("Failed to load gitmoji list:",e);const a=[];return Tt.forEach(f=>f(a)),a}finally{ss=null}})();return ss=o,o},Qi=o=>{const[e,a]=i.useState(()=>o?zs()?.gitmojis??[]:[]),[f,w]=i.useState(!1),u=i.useRef(o);u.current=o,i.useEffect(()=>{if(!o){Tt.delete(a),a([]),w(!1);return}const v=zs();if(v&&(a(v.gitmojis),zr(v)))return;Tt.add(a),w(!0);let h=!1;return _r().finally(()=>{!h&&u.current&&w(!1)}),()=>{h=!0,Tt.delete(a)}},[o]);const p=i.useCallback(async()=>{if(!u.current)return[];if(e.length>0)return e;const v=zs();return v&&zr(v)?v.gitmojis:_r()},[e]);return{gitmojis:e,isLoading:f,ensureLoaded:p}},jt=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 f=await a.json().catch(()=>null);throw new Error(f?.error||`Git integrate request failed: ${a.statusText}`)}return a.json()};async function Ot(o){return jt("plan",o)}async function Zi(o){return jt("conflict-details",{tempWorktreePath:o})}async function Xi(o){return(await jt("cherry-pick-status",{tempWorktreePath:o})).inProgress}async function eo(o){return jt("run",{plan:o})}async function to(o){await jt("abort",{state:o})}async function so(o){return jt("continue",{state:o})}const ro=({repoRoot:o,sourceBranch:e,worktreeMetadata:a,localBranches:f,defaultTargetBranch:w,refreshKey:u,onRefresh:p,showHeader:v=!0})=>{const{t:h}=ot(),x=it(m=>m.currentSessionId),[B,M]=ue.useState(!1),[k,z]=ue.useState(""),S=ue.useRef(null),L=ue.useMemo(()=>Lt(f,k,m=>[m]),[f,k]),[R,b]=ue.useState(w);ue.useEffect(()=>{b(w)},[w]),ue.useEffect(()=>{if(B){const m=setTimeout(()=>{S.current?.focus()},0);return()=>clearTimeout(m)}},[B]);const q=!!(o&&e&&R&&R!=="HEAD"&&e!==R),[j,F]=ue.useState({kind:"idle"}),[V,P]=ue.useState(!1),[G,ee]=ue.useState([]),A=ue.useMemo(()=>x?`openchamber.integrate.conflict:${x}`:null,[x]);ue.useEffect(()=>{if(!A||typeof window>"u")return;const m=window.localStorage.getItem(A);if(!m)return;let c=!1;try{const I=JSON.parse(m);if(!I?.tempWorktreePath||I.repoRoot!==o){window.localStorage.removeItem(A);return}(async()=>{const T=await Xi(I.tempWorktreePath).catch(()=>!1);if(c)return;if(!T){window.localStorage.removeItem(A);return}const ne=await Zi(I.tempWorktreePath).catch(()=>null);c||ne&&F({kind:"conflict",state:I,details:ne})})()}catch{window.localStorage.removeItem(A)}return()=>{c=!0}},[A,o]),ue.useEffect(()=>{if(!q){F({kind:"idle"});return}let m=!1;return F({kind:"loading"}),(async()=>{try{const c=await Ot({repoRoot:o,sourceBranch:e,targetBranch:R});if(m)return;if(F({kind:"ready",plan:c}),c.commits.length>0){const T=c.commits.slice(-50).reverse(),ne=await va(o,T);m||(ee(ne),P(!1))}else m||(ee([]),P(!1))}catch{m||F({kind:"idle"})}})(),()=>{m=!0}},[q,o,e,R,u]);const r=ue.useCallback(m=>{x&&it.getState().setWorktreeMetadata(x,{...a,createdFromBranch:m})},[x,a]),O=it(m=>m.openNewSessionDraft),J=ue.useCallback(async m=>{const c=await Fr("git.integrate.cherrypick.resolve.visible",{current_commit:m.state.currentCommit,target_branch:m.state.targetBranch}),I=await Fr("git.integrate.cherrypick.resolve.instructions",{repo_root:m.state.repoRoot,temp_worktree_path:m.state.tempWorktreePath,source_branch:m.state.sourceBranch,target_branch:m.state.targetBranch,current_commit:m.state.currentCommit}),T=`Cherry-pick conflict context (JSON)
|
|
2
|
-
${JSON.stringify({repoRoot:m.state.repoRoot,tempWorktreePath:m.state.tempWorktreePath,sourceBranch:m.state.sourceBranch,targetBranch:m.state.targetBranch,currentCommit:m.state.currentCommit,remainingCommits:m.state.remainingCommits,statusPorcelain:m.details.statusPorcelain,unmergedFiles:m.details.unmergedFiles,currentPatchMeta:m.details.currentPatchMeta,currentPatch:m.details.currentPatch,diff:m.details.diff},null,2)}`;return{visibleText:c,instructionsText:I,payloadText:T}},[]),y=Dr(m=>m.setPendingInputText),_=Dr(m=>m.setPendingSyntheticParts),H=ue.useCallback(async(m,c)=>{const I=await J(m);if(c){O({directoryOverride:m.state.tempWorktreePath,initialPrompt:I.visibleText,syntheticParts:[{text:I.instructionsText,synthetic:!0},{text:I.payloadText,synthetic:!0}]});return}if(!x){g.error(h("gitView.integrate.noActiveSession"),{description:h("gitView.integrate.noActiveSessionDescription")});return}y(I.visibleText,"replace"),_([{text:I.instructionsText,synthetic:!0},{text:I.payloadText,synthetic:!0}])},[x,J,O,y,_,h]),Y=ue.useCallback(async()=>{if(j.kind==="ready"){if(j.plan.commits.length===0){g.message(h("gitView.integrate.noCommitsToMoveToast"));return}F({kind:"running",plan:j.plan});try{const m=await eo(j.plan);if(m.kind==="success"){g.success(h("gitView.integrate.commitsMovedToast"),{description:m.moved===1?h("gitView.integrate.commitsMovedDescriptionSingle",{count:m.moved,branch:j.plan.targetBranch}):h("gitView.integrate.commitsMovedDescriptionPlural",{count:m.moved,branch:j.plan.targetBranch})});const c=await Ot(j.plan);F({kind:"ready",plan:c}),p?.();return}m.kind==="conflict"&&(g.error(h("gitView.integrate.cherryPickConflictToast"),{description:h("gitView.integrate.cherryPickConflictDescription")}),F({kind:"conflict",state:m.state,details:m.details}),A&&typeof window<"u"&&window.localStorage.setItem(A,JSON.stringify(m.state)))}catch(m){const c=m instanceof Error?m.message:String(m);g.error(h("gitView.integrate.failedToMoveToast"),{description:c});const I=await Ot({repoRoot:o,sourceBranch:e,targetBranch:R}).catch(()=>null);F(I?{kind:"ready",plan:I}:{kind:"idle"})}}},[j,p,o,e,R,A,h]),te=ue.useCallback(async()=>{if(j.kind==="conflict")try{await to(j.state),g.message(h("gitView.integrate.cherryPickAbortedToast")),A&&typeof window<"u"&&window.localStorage.removeItem(A)}finally{const m=await Ot({repoRoot:o,sourceBranch:e,targetBranch:R}).catch(()=>null);F(m?{kind:"ready",plan:m}:{kind:"idle"})}},[j,o,e,R,A,h]),he=ue.useCallback(async()=>{if(j.kind==="conflict")try{const m=await so(j.state);if(m.kind==="success"){g.success(h("gitView.integrate.cherryPickFinishedToast"));const c=await Ot({repoRoot:o,sourceBranch:e,targetBranch:R}).catch(()=>null);F(c?{kind:"ready",plan:c}:{kind:"idle"}),A&&typeof window<"u"&&window.localStorage.removeItem(A),p?.();return}m.kind==="conflict"&&(F({kind:"conflict",state:m.state,details:m.details}),A&&typeof window<"u"&&window.localStorage.setItem(A,JSON.stringify(m.state)))}catch(m){const c=m instanceof Error?m.message:String(m);g.error(h("gitView.integrate.cherryPickContinueFailedToast"),{description:c})}},[j,o,e,R,p,A,h]);return!o||!e?null:t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[v?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(E,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:h("gitView.integrate.title")}),j.kind==="ready"&&j.plan.commits.length>0?t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:h("gitView.integrate.toMoveCount",{count:j.plan.commits.length})}):null]}),t.jsx("div",{className:"flex items-center gap-2",children:j.kind==="loading"||j.kind==="running"?t.jsx(E,{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:h("gitView.integrate.moveCommits")}),t.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",R]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs($s,{open:B,onOpenChange:M,children:[t.jsx(Ws,{asChild:!0,children:t.jsxs("button",{type:"button",className:en({size:"default"}),children:[h("gitView.integrate.target"),t.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:R}),t.jsx(E,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),t.jsx(Us,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:t.jsxs(Ks,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(qs,{ref:S,placeholder:h("gitView.branch.searchPlaceholder"),value:k,onValueChange:z,onKeyDown:m=>m.stopPropagation()}),t.jsxs(Js,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(Ys,{children:h("gitView.branch.empty")}),t.jsx(ns,{heading:h("gitView.branch.localBranches"),children:L.map(m=>t.jsx(as,{value:m,onSelect:()=>{b(m),r(m),M(!1),z("")},children:m},m))})]})]})})]}),j.kind==="ready"?t.jsx(K,{size:"sm",onClick:()=>{Y()},disabled:!q||j.plan.commits.length===0,children:h("gitView.integrate.move")}):j.kind==="loading"?t.jsx(K,{size:"sm",variant:"outline",disabled:!0,children:h("gitView.integrate.checking")}):j.kind==="running"?t.jsx(K,{size:"sm",variant:"outline",disabled:!0,children:h("gitView.integrate.moving")}):null]}),j.kind==="ready"&&j.plan.commits.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:h("gitView.integrate.noCommitsToMove")}),j.kind==="ready"&&j.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:[h("gitView.integrate.commitsToMove"),t.jsxs("span",{className:"text-muted-foreground",children:[" (",j.plan.commits.length,")"]})]}),G.length>0&&j.plan.commits.length>5&&t.jsx("button",{type:"button",onClick:()=>P(m=>!m),className:"typography-micro text-muted-foreground hover:text-foreground",children:h(V?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(V?G:G.slice(0,5)).map(m=>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:m.short}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:m.subject||m.sha})]},m.sha)),G.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:h("gitView.integrate.previewUnavailable")}),j.plan.commits.length>G.length&&t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:h("gitView.integrate.showingFirstCommits",{count:G.length})})]})]}),j.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:h("gitView.integrate.conflictsInFiles",{count:j.details.unmergedFiles.length})}),t.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[h("gitView.integrate.currentCommit"),": ",t.jsx("span",{className:"font-mono",children:j.state.currentCommit.slice(0,7)})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[j.details.unmergedFiles.slice(0,6).map(m=>t.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:m},m)),j.details.unmergedFiles.length>6&&t.jsx("span",{className:"text-xs text-muted-foreground",children:h("gitView.integrate.moreFiles",{count:j.details.unmergedFiles.length-6})})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(K,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{te()},children:h("gitView.operation.abort")}),t.jsxs(K,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!x,onClick:()=>{H({state:j.state,details:j.details},!1)},children:[t.jsx(E,{name:"sparkling",className:"size-3.5"}),h("gitView.integrate.currentSession")]}),t.jsxs(K,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{H({state:j.state,details:j.details},!0)},children:[t.jsx(E,{name:"sparkling",className:"size-3.5"}),h("gitView.integrate.newSession")]}),t.jsx(K,{size:"sm",className:"typography-meta",onClick:()=>{he()},children:h("gitView.operation.continue")})]})]})]})]})},no=({open:o,onOpenChange:e,directory:a,hasUncommittedChanges:f,hasStagedChanges:w=!1,uncommittedFileCount:u,onChanged:p})=>{const{t:v}=ot(),[h,x]=i.useState([]),[B,M]=i.useState(!1),[k,z]=i.useState(""),[S,L]=i.useState(""),[R,b]=i.useState(null),[q,j]=i.useState({}),F=i.useCallback(async()=>{if(a){M(!0);try{const r=await ja(a);x(r.stashes),j({})}catch(r){g.error(r instanceof Error?r.message:v("gitView.stashes.toast.loadFailed"))}finally{M(!1)}}},[a,v]);i.useEffect(()=>{o&&F()},[F,o]),i.useEffect(()=>{if(!o||!a||h.length===0)return;let r=!1;const O=h.map(J=>J.ref);return Ca(a,O).then(J=>{r||j(J.counts)}).catch(()=>{}),()=>{r=!0}},[a,o,h]);const V=i.useMemo(()=>Lt(h,k,r=>[r.message,r.ref,r.relativeTime]),[k,h]),P=i.useCallback(async r=>{await F(),await p?.(r)},[F,p]),G=async()=>{if(!(!a||R)){b("create");try{const r=await Sa(a,{message:S.trim()||void 0});r.created?(g.success(v("gitView.stashes.toast.created")),L("")):g.info(v("gitView.stashes.toast.noChanges")),await P({affectsIndex:!!(r.created&&w)})}catch(r){g.error(r instanceof Error?r.message:v("gitView.stashes.toast.createFailed"))}finally{b(null)}}},ee=async(r,O)=>{if(!(!a||R)&&!(O==="drop"&&!window.confirm(v("gitView.stashes.confirm.drop",{ref:r.ref})))){b(`${O}:${r.ref}`);try{O==="apply"&&await Na(a,{ref:r.ref}),O==="pop"&&await ka(a,{ref:r.ref}),O==="drop"&&await Va(a,{ref:r.ref});const J=O==="apply"?"gitView.stashes.toast.applySuccess":O==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";g.success(v(J)),await P({affectsIndex:O!=="drop"})}catch(J){const y=O==="apply"?"gitView.stashes.toast.applyFailed":O==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";g.error(J instanceof Error?J.message:v(y)),await P({affectsIndex:O!=="drop"})}finally{b(null)}}},A=R!==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(ft,{children:[t.jsxs(gt,{className:"flex items-center gap-2",children:[t.jsx(E,{name:"archive-stack",className:"h-5 w-5"}),v("gitView.stashes.title")]}),t.jsx(vt,{children:v("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(Br,{value:S,onChange:r=>L(r.target.value),placeholder:v("gitView.stashes.messagePlaceholder"),disabled:A||!f,className:"flex-1"}),t.jsxs(K,{onClick:G,disabled:!f||A||!a,children:[R==="create"?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"inbox-archive",className:"size-4"}),v("gitView.stashes.actions.stashCurrentWithCount",{count:u})]})]}),t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:v("gitView.stashes.includeUntrackedHint")})]}),t.jsxs("div",{className:"relative mt-2",children:[t.jsx(E,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(Br,{value:k,onChange:r=>z(r.target.value),placeholder:v("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:B?t.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:t.jsx(E,{name:"loader-4",className:"size-5 animate-spin"})}):V.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:v(k?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):V.map((r,O)=>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:r.message||v("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[t.jsxs(is,{children:[t.jsx(os,{asChild:!0,children:t.jsx("span",{children:O===0&&!k.trim()?v("gitView.stashes.latestLabel"):v("gitView.stashes.itemNumber",{number:O+1})})}),t.jsx(ls,{sideOffset:6,children:r.ref})]})," · ",r.relativeTime," · ",typeof q[r.ref]=="number"?v("gitView.stashes.fileCount",{count:q[r.ref]}):v("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(_s,{label:v("gitView.stashes.actions.apply"),loading:R===`apply:${r.ref}`,onClick:()=>ee(r,"apply"),disabled:A,children:t.jsx(E,{name:"inbox-unarchive",className:"size-4"})}),t.jsx(_s,{label:v("gitView.stashes.actions.pop"),loading:R===`pop:${r.ref}`,onClick:()=>ee(r,"pop"),disabled:A,children:t.jsx(E,{name:"inbox-unarchive-fill",className:"size-4"})}),t.jsx(_s,{label:v("gitView.stashes.actions.drop"),loading:R===`drop:${r.ref}`,onClick:()=>ee(r,"drop"),disabled:A,destructive:!0,children:t.jsx(E,{name:"delete-bin",className:"size-4"})})]})]},r.ref))})]})})},_s=o=>{const e=Gt.c(17),{label:a,loading:f,disabled:w,destructive:u,onClick:p,children:v}=o,h=f||void 0,x=u?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let B;e[0]!==x?(B=me("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",x),e[0]=x,e[1]=B):B=e[1];let M;e[2]!==v||e[3]!==f?(M=f?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):v,e[2]=v,e[3]=f,e[4]=M):M=e[4];let k;e[5]!==w||e[6]!==a||e[7]!==p||e[8]!==h||e[9]!==B||e[10]!==M?(k=t.jsx(os,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":a,"aria-busy":h,className:B,onClick:p,disabled:w,children:M})}),e[5]=w,e[6]=a,e[7]=p,e[8]=h,e[9]=B,e[10]=M,e[11]=k):k=e[11];let z;e[12]!==a?(z=t.jsx(ls,{sideOffset:6,children:a}),e[12]=a,e[13]=z):z=e[13];let S;return e[14]!==k||e[15]!==z?(S=t.jsxs(is,{children:[k,z]}),e[14]=k,e[15]=z,e[16]=S):S=e[16],S},ao=o=>{const e=Gt.c(16),{onOpenStashes:a}=o,{t:f}=ot();let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=t.jsx(E,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=w):w=e[0];let u;e[1]!==f?(u=f("gitView.empty.cleanTitle"),e[1]=f,e[2]=u):u=e[2];let p;e[3]!==u?(p=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:u}),e[3]=u,e[4]=p):p=e[4];let v;e[5]!==f?(v=f("gitView.empty.cleanDescription"),e[5]=f,e[6]=v):v=e[6];let h;e[7]!==v?(h=t.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:v}),e[7]=v,e[8]=h):h=e[8];let x;e[9]!==a||e[10]!==f?(x=a?t.jsxs(K,{type:"button",variant:"outline",size:"sm",onClick:a,className:"gap-1.5",children:[t.jsx(E,{name:"archive-stack",className:"size-4"}),f("gitView.stashes.title")]}):null,e[9]=a,e[10]=f,e[11]=x):x=e[11];let B;return e[12]!==p||e[13]!==h||e[14]!==x?(B=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[w,p,h,x]}),e[12]=p,e[13]=h,e[14]=x,e[15]=B):B=e[15],B},at=8,io=o=>{const e=Gt.c(18),{laned:a,totalLanes:f,isExpanded:w}=o,{lane:u,color:p,connectors:v}=a,x=Math.max(f,u+1)*at+at/2,B=i.useRef(null),M=i.useRef(null);let k;e[0]!==p||e[1]!==v||e[2]!==u||e[3]!==x?(k=()=>{const b=B.current,q=M.current;if(!b||!q)return;const j=b.offsetHeight;if(j===0)return;const F=window.devicePixelRatio||1;q.width=x*F,q.height=j*F;const V=q.getContext("2d");if(!V)return;V.scale(F,F),V.clearRect(0,0,x,j);const P=j/2,G=u*at+at/2,ee=getComputedStyle(q),A=ee.getPropertyValue("--surface-muted-foreground").trim()||ee.color,r=y=>{if(!y.startsWith("var("))return y;const _=y.slice(4,-1).trim();return ee.getPropertyValue(_).trim()||A},O=[...v].sort(lo);for(const y of O){const _=y.fromLane*at+at/2,H=y.toLane*at+at/2,Y=y.type==="passing"?.72:y.type==="branch-out"||y.type==="merge-in"?.95:1;V.beginPath(),V.strokeStyle=r(y.color),V.globalAlpha=Y,V.lineWidth=1.25,V.lineCap="round";e:switch(y.type){case"passing":case"commit-lane":{V.moveTo(_,0),V.lineTo(_,j);break e}case"top-stub":{V.moveTo(_,0),V.lineTo(_,P);break e}case"bottom-stub":{V.moveTo(_,P),V.lineTo(_,j);break e}case"branch-out":{const te=(P+j)/2;V.moveTo(G,P),V.bezierCurveTo(G,te,H,te,H,j);break e}case"merge-in":{const te=P/2;V.moveTo(_,0),V.bezierCurveTo(_,te,G,te,G,P);break e}default:continue}V.stroke(),V.globalAlpha=1}const J=ee.getPropertyValue("--background").trim()||ee.getPropertyValue("--surface-background").trim();V.beginPath(),V.arc(G,P,4,0,Math.PI*2),V.fillStyle=r(p),V.fill(),V.beginPath(),V.arc(G,P,5,0,Math.PI*2),V.strokeStyle=J||A,V.lineWidth=2,V.stroke()},e[0]=p,e[1]=v,e[2]=u,e[3]=x,e[4]=k):k=e[4];let z;e[5]!==p||e[6]!==v||e[7]!==w||e[8]!==u||e[9]!==a||e[10]!==f||e[11]!==x?(z=[a,u,p,v,f,w,x],e[5]=p,e[6]=v,e[7]=w,e[8]=u,e[9]=a,e[10]=f,e[11]=x,e[12]=z):z=e[12],i.useLayoutEffect(k,z);let S;e[13]!==x?(S={width:x,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=x,e[14]=S):S=e[14];let L;e[15]===Symbol.for("react.memo_cache_sentinel")?(L=t.jsx("canvas",{ref:M,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=L):L=e[15];let R;return e[16]!==S?(R=t.jsx("div",{ref:B,style:S,children:L}),e[16]=S,e[17]=R):R=e[17],R};function oo(o){return o==="branch-out"||o==="merge-in"}function lo(o,e){const a=oo;return(a(o.type)?1:0)-(a(e.type)?1:0)}const Hr=15e3,$r=500,Wr=12,Ur=8*1024*1024,Kr=o=>typeof o=="string"?0:(o.original?.length??0)+(o.modified?.length??0),qr=o=>{if(o.size<=Wr){let w=0;for(const u of o.values())w+=Kr(u);if(w<=Ur)return o}const e=Array.from(o.entries()).reverse(),a=new Map;let f=0;for(const[w,u]of e){if(a.size>=Wr)continue;const p=Kr(u);f+p>Ur&&a.size>0||(a.set(w,u),f+=p)}return new Map(Array.from(a.entries()).reverse())};function Jr(o,e){const a=new Date(o);return Number.isNaN(a.getTime())?o:Fa(a,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function co(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 uo(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 mo=i.memo(({entry:o,mode:e="history",laned:a,totalLanes:f,isExpanded:w,onToggle:u,files:p,isLoadingFiles:v,onCopyHash:h,directory:x,onConflict:B,onActionSuccess:M})=>{const{t:k}=ot(),z=Et(c=>c.timeFormatPreference),S=e==="graph",[L,R]=i.useState(null),[b,q]=i.useState(!1),[j,F]=i.useState(""),[V,P]=i.useState(null),[G,ee]=i.useState(new Set),[A,r]=i.useState(new Map),[O,J]=i.useState(new Set),y=async()=>{if(x){R("checkout");try{await Ta(x,o.hash),g.success(k("gitView.history.actions.detachedHead")),M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},_=async()=>{if(!(!x||!j.trim())){R("createBranch");try{await Da(x,j.trim(),o.hash),q(!1),F(""),M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},H=async()=>{if(x){R("cherryPick");try{const c=await Ea(x,o.hash);c.conflict?B?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"cherry-pick"}):M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},Y=async()=>{if(x){R("revert");try{const c=await Oa(x,o.hash);c.conflict?B?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"revert"}):M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},te=async(c,I=!1)=>{if(!(!x||L!==null)){R("reset");try{await Ba(x,o.hash,c,I),M?.()}catch(T){g.error(String(T.message))}finally{R(null)}}},he=async()=>{if(!V)return;const c=V;switch(P(null),c){case"checkout":return y();case"cherryPick":return H();case"revert":return Y();case"merge":return se();case"rebase":return oe();case"resetSoft":return te("soft");case"resetMixed":return te("mixed");case"resetHard":return te("hard",!0)}},se=async()=>{if(x){R("merge");try{const c=await Aa(x,{branch:o.hash});c.conflict?B?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"merge"}):M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},oe=async()=>{if(x){R("rebase");try{const c=await Ma(x,{onto:o.hash});c.conflict?B?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"rebase"}):M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},le=i.useCallback(async c=>{const I=c.path;if(!x){r(T=>new Map(T).set(I,"error"));return}r(T=>qr(new Map(T).set(I,"loading")));try{const T=Ra(x,o.hash,c.path,!1),ne=new Promise((X,$)=>{setTimeout(()=>$(new Error(`Timed out after ${Hr}ms`)),Hr)}),Q=await Promise.race([T,ne]);r(X=>qr(new Map(X).set(I,Q)))}catch{r(T=>new Map(T).set(I,"error"))}},[x,o.hash]),m=i.useCallback(async c=>{const I=c.path;if(c.changeType==="R"||c.isBinary){ee(X=>{const $=new Set(X);return $.has(I)?$.delete(I):$.add(I),$});return}const T=A.get(I);if(G.has(I)&&T&&T!=="error"){ee(X=>{const $=new Set(X);return $.delete(I),$});return}ee(X=>{const $=new Set(X);return $.add(I),$}),!(T&&T!=="error"||c.insertions+c.deletions>$r&&!O.has(I))&&await le(c)},[A,O,le,G]);return t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:u,className:me("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",S?"hover:bg-[var(--interactive-hover)]/40":w?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[S&&a&&f!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(io,{laned:a,totalLanes:f,isExpanded:w})}):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 c=uo(o.refs);return c.length>0?t.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:c.map(I=>t.jsx("span",{className:me("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:Jr(o.date,z),children:Jr(o.date,z)})]}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("code",{className:"shrink-0 font-mono",children:o.hash.slice(0,8)}),t.jsxs(is,{children:[t.jsx(os,{asChild:!0,children:t.jsx(K,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:c=>{c.stopPropagation(),h(o.hash)},children:t.jsx(E,{name:"file-copy",className:"size-3"})})}),t.jsx(ls,{sideOffset:8,children:k("gitView.history.copySha")})]})]})]})]}),w&&t.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[S&&V?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:k(`gitView.history.actions.${V}Confirm`)}),t.jsxs(K,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:L!==null,onClick:c=>{c.stopPropagation(),he()},children:[L!==null?t.jsx(E,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,k("gitView.history.actions.confirmButton")]}),t.jsx(K,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:L!==null,onClick:c=>{c.stopPropagation(),P(null)},children:k("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(K,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>{c.stopPropagation(),P("checkout")},children:k("gitView.history.actions.checkout")}),b?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{autoFocus:!0,value:j,onChange:c=>F(c.target.value),onKeyDown:c=>{c.key==="Enter"&&_(),c.key==="Escape"&&(q(!1),F(""))},placeholder:k("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(K,{variant:"outline",size:"xs",className:"h-6",disabled:!j.trim()||L!==null,onClick:c=>{c.stopPropagation(),_()},children:[L==="createBranch"?t.jsx(E,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,k("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(K,{variant:"outline",size:"xs",className:"h-6",onClick:c=>{c.stopPropagation(),q(!0)},children:k("gitView.history.actions.createBranch")}),t.jsx(K,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>{c.stopPropagation(),P("cherryPick")},children:k("gitView.history.actions.cherryPick")}),t.jsx(K,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>{c.stopPropagation(),P("revert")},children:k("gitView.history.actions.revert")}),t.jsxs($s,{children:[t.jsx(Ws,{asChild:!0,children:t.jsxs(K,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>c.stopPropagation(),children:[L==="reset"?t.jsx(E,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,k("gitView.history.actions.reset")]})}),t.jsx(Us,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(c=>t.jsx(Ia,{disabled:L!==null,onSelect:I=>{I.stopPropagation(),P(`reset${c.charAt(0).toUpperCase()+c.slice(1)}`)},children:k(`gitView.history.actions.reset${c.charAt(0).toUpperCase()+c.slice(1)}`)},c))})]}),t.jsx(K,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>{c.stopPropagation(),P("merge")},children:k("gitView.history.actions.merge")}),t.jsx(K,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>{c.stopPropagation(),P("rebase")},children:k("gitView.history.actions.rebase")})]}):null,v?t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(E,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:k("gitView.history.loadingFiles")})]}):p.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:k("gitView.history.noFiles")}):t.jsx("ul",{className:"space-y-0.5 py-2",children:p.map(c=>t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:()=>m(c),className:me("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",G.has(c.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[t.jsx("span",{className:me("font-semibold w-3 text-center shrink-0",co(c.changeType)),children:c.changeType}),t.jsx("span",{className:"truncate text-foreground min-w-0",title:c.path,children:c.path}),!c.isBinary&&t.jsxs("span",{className:"shrink-0",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",c.insertions]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",c.deletions]})]}),c.isBinary&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:k("gitView.history.binary")}),t.jsx(E,{name:G.has(c.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),G.has(c.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:c.changeType==="R"?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.renamedNoDiff")}):c.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.binaryNoDiff")}):(()=>{const I=c.insertions+c.deletions;if(!O.has(c.path)&&I>$r)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:k("gitView.history.largeDiffTitle",{count:I})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:k("gitView.history.largeDiffDescription")}),t.jsx(K,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{J(ne=>new Set(ne).add(c.path)),le(c)},children:k("gitView.history.renderDiffAnyway")})]});const T=A.get(c.path);return T==="loading"||T===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.loadingDiff")}):T==="error"?t.jsx("button",{type:"button",onClick:()=>m(c),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:k("gitView.history.diffError")}):t.jsx(Ki,{original:T.original,modified:T.modified,language:Pa(c.path)||"",fileName:c.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},c.path))})]})]})}),Yr=["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 rs(o){return Yr[o%Yr.length]}function ho(o){if(o.length===0)return[];const e=[],a=[];for(let f=0;f<o.length;f++){const w=o[f],u=[];for(let S=0;S<e.length;S++)e[S]===w.hash&&u.push(S);let p=u.length>0?u[0]:-1;if(p===-1){const S=e.indexOf(null);S!==-1?p=S:(p=e.length,e.push(null))}const v=u.slice(1),h=rs(p),x=e[p]===w.hash,B=w.parents.length>0;B?e[p]=w.parents[0]:e[p]=null;const M=[],k=new Set;for(let S=1;S<w.parents.length;S++){const L=w.parents[S],R=e.indexOf(L);if(R!==-1)M.push(R);else{const b=e.indexOf(null);if(b!==-1)e[b]=L,M.push(b),k.add(b);else{const q=e.length;e.push(L),M.push(q),k.add(q)}}}const z=[];x&&B?z.push({fromLane:p,toLane:p,color:h,type:"commit-lane"}):x&&!B?z.push({fromLane:p,toLane:p,color:h,type:"top-stub"}):!x&&B&&z.push({fromLane:p,toLane:p,color:h,type:"bottom-stub"});for(const S of v)z.push({fromLane:S,toLane:p,color:rs(S),type:"merge-in"}),e[S]=null;for(const S of M)z.push({fromLane:p,toLane:S,color:rs(S),type:"branch-out"});for(let S=0;S<e.length;S++)e[S]!==null&&S!==p&&(k.has(S)||z.push({fromLane:S,toLane:S,color:rs(S),type:"passing"}));a.push({commit:w,lane:p,color:h,connectors:z})}return a}const fo=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],go=o=>{const e=Gt.c(84),{mode:a,log:f,isLogLoading:w,logMaxCount:u,onLogMaxCountChange:p,expandedCommitHashes:v,onToggleCommit:h,commitFilesMap:x,loadingCommitHashes:B,onCopyHash:M,directory:k,showHeader:z,contentMaxHeightClassName:S,branchDivider:L,onConflict:R,onActionSuccess:b}=o,q=a===void 0?"history":a,j=z===void 0?!0:z,F=S===void 0?"max-h-[50vh]":S,V=L===void 0?null:L,{t:P}=ot(),[G,ee]=i.useState(!0),A=q==="graph";let r;e[0]!==A||e[1]!==f?(r=A&&f?ho(f.all):[],e[0]=A,e[1]=f,e[2]=r):r=e[2];const O=r;let J;e[3]!==O?(J=Math.max(1,...O.map(po)),e[3]=O,e[4]=J):J=e[4];const y=J;let _;e[5]!==O?(_=new Map(O.map(xo)),e[5]=O,e[6]=_):_=e[6];const H=_;if(!f)return null;const Y=V!==null&&V.insertBeforeIndex>0&&V.insertBeforeIndex<f.all.length,te=V!==null&&V.insertBeforeIndex===f.all.length,he=Y||te;let se;e[7]!==V||e[8]!==Y||e[9]!==te||e[10]!==f.all?(se=Y?f.all.slice(0,V.insertBeforeIndex):te?f.all:[],e[7]=V,e[8]=Y,e[9]=te,e[10]=f.all,e[11]=se):se=e[11];const oe=se;let le;if(e[12]!==V||e[13]!==x||e[14]!==F||e[15]!==k||e[16]!==v||e[17]!==Y||e[18]!==he||e[19]!==A||e[20]!==w||e[21]!==H||e[22]!==B||e[23]!==f.all||e[24]!==u||e[25]!==y||e[26]!==q||e[27]!==b||e[28]!==R||e[29]!==M||e[30]!==p||e[31]!==h||e[32]!==P||e[33]!==oe){const ce=Y?f.all.slice(V.insertBeforeIndex):[];let pe;e[35]!==V?.direction?(pe=V?.direction==="down"?t.jsx(E,{name:"arrow-down-s",className:"size-3.5"}):t.jsx(E,{name:"arrow-up",className:"size-3.5"}),e[35]=V?.direction,e[36]=pe):pe=e[36];const Me=pe;let be;e[37]!==x||e[38]!==k||e[39]!==v||e[40]!==A||e[41]!==H||e[42]!==B||e[43]!==y||e[44]!==q||e[45]!==b||e[46]!==R||e[47]!==M||e[48]!==h?(be=zt=>t.jsx("ul",{className:"divide-y divide-border/60",children:zt.map(Ne=>t.jsx(mo,{entry:Ne,mode:q,laned:A?H.get(Ne.hash):void 0,totalLanes:A?y:void 0,isExpanded:v.has(Ne.hash),onToggle:()=>h(Ne.hash),files:x.get(Ne.hash)??[],isLoadingFiles:B.has(Ne.hash),onCopyHash:M,directory:k,onConflict:R,onActionSuccess:b},Ne.hash))}),e[37]=x,e[38]=k,e[39]=v,e[40]=A,e[41]=H,e[42]=B,e[43]=y,e[44]=q,e[45]=b,e[46]=R,e[47]=M,e[48]=h,e[49]=be):be=e[49];const Se=be;let ae;e[50]!==w||e[51]!==f.all.length||e[52]!==u||e[53]!==p||e[54]!==P?(ae=f.all.length>=u?t.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:t.jsx(K,{type:"button",variant:"ghost",size:"xs",onClick:()=>p(u+25),disabled:w,className:"px-3 text-muted-foreground hover:text-foreground",children:w?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(E,{name:"loader-4",className:"size-3 animate-spin"}),P("gitView.history.loadingMore")]}):P("gitView.history.loadMore")})}):null,e[50]=w,e[51]=f.all.length,e[52]=u,e[53]=p,e[54]=P,e[55]=ae):ae=e[55];const _e=ae;le=t.jsx(tn,{outerClassName:`min-h-0 ${F}`,className:"h-full w-full",children:f.all.length===0?t.jsx("div",{className:"flex h-full items-center justify-center p-4",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:P("gitView.history.noCommits")})}):he&&V?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col gap-0",children:[oe.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Se(oe)}):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:V.branchName,children:V.branchName}),Me]}),t.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),ce.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Se(ce)}):null]}),_e]}):t.jsxs(t.Fragment,{children:[Se(f.all),_e]})}),e[12]=V,e[13]=x,e[14]=F,e[15]=k,e[16]=v,e[17]=Y,e[18]=he,e[19]=A,e[20]=w,e[21]=H,e[22]=B,e[23]=f.all,e[24]=u,e[25]=y,e[26]=q,e[27]=b,e[28]=R,e[29]=M,e[30]=p,e[31]=h,e[32]=P,e[33]=oe,e[34]=le}else le=e[34];const m=le;if(!j){if(he){let pe;return e[56]!==m?(pe=t.jsx("section",{className:"h-full min-h-0",children:m}),e[56]=m,e[57]=pe):pe=e[57],pe}let ce;return e[58]!==m?(ce=t.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:m}),e[58]=m,e[59]=ce):ce=e[59],ce}let c;e[60]!==P?(c=P("gitView.history.title"),e[60]=P,e[61]=c):c=e[61];let I;e[62]!==c?(I=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:c}),e[62]=c,e[63]=I):I=e[63];let T;e[64]!==w||e[65]!==G||e[66]!==u||e[67]!==p||e[68]!==P?(T=G&&t.jsx("div",{onClick:yo,onPointerDown:wo,children:t.jsxs(La,{value:String(u),onValueChange:ce=>p(Number(ce)),disabled:w,children:[t.jsx(Ga,{size:"sm",className:"w-auto",disabled:w,children:t.jsx(za,{placeholder:P("gitView.history.commitsPlaceholder")})}),t.jsx(_a,{children:fo.map(ce=>t.jsx(Ha,{value:String(ce.value),children:P(ce.labelKey)},ce.value))})]})}),e[64]=w,e[65]=G,e[66]=u,e[67]=p,e[68]=P,e[69]=T):T=e[69];let ne;e[70]!==G?(ne=G?t.jsx(E,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):t.jsx(E,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=G,e[71]=ne):ne=e[71];let Q;e[72]!==T||e[73]!==ne?(Q=t.jsxs("div",{className:"flex items-center gap-2",children:[T,ne]}),e[72]=T,e[73]=ne,e[74]=Q):Q=e[74];let X;e[75]!==I||e[76]!==Q?(X=t.jsxs(ki,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[I,Q]}),e[75]=I,e[76]=Q,e[77]=X):X=e[77];let $;e[78]!==m?($=t.jsx(Vi,{children:m}),e[78]=m,e[79]=$):$=e[79];let Be;return e[80]!==G||e[81]!==X||e[82]!==$?(Be=t.jsxs(Ri,{open:G,onOpenChange:ee,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[X,$]}),e[80]=G,e[81]=X,e[82]=$,e[83]=Be):Be=e[83],Be};function po(o){return o.lane+1}function xo(o){return[o.commit.hash,o]}function yo(o){return o.stopPropagation()}function wo(o){return o.stopPropagation()}const bo=({open:o,onOpenChange:e,operation:a,targetBranch:f,onConfirm:w})=>{const{t:u}=ot(),[p,v]=i.useState(!0),[h,x]=i.useState(!1),B=u(a==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),M=async()=>{x(!0);try{await w(p),e(!1)}catch(z){const S=z instanceof Error?z.message:`Failed to ${a}`;g.error(S)}finally{x(!1)}},k=()=>{h||e(!1)};return t.jsx(mt,{open:o,onOpenChange:h?void 0:e,children:t.jsxs(ht,{className:"max-w-md",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),t.jsx(gt,{children:u("gitView.stash.title")})]}),t.jsx(vt,{children:u("gitView.stash.description",{operation:a})})]}),t.jsxs("div",{className:"py-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:u("gitView.stash.thisWill")}),t.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[t.jsx("li",{children:u("gitView.stash.stepStash")}),t.jsxs("li",{children:[u(a==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",u(a==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",t.jsx("span",{className:"font-mono text-primary",children:f})]}),p&&t.jsx("li",{children:u("gitView.stash.stepRestore")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx($a,{checked:p,onChange:v,disabled:h,ariaLabel:u("gitView.stash.restoreAria")}),t.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!h&&v(!p),children:u("gitView.stash.restoreAfterOperation",{operation:a})})]}),t.jsxs(Hs,{className:"gap-2",children:[t.jsx(K,{variant:"ghost",size:"sm",onClick:k,disabled:h,children:u("gitView.common.cancel")}),t.jsx(K,{variant:"default",size:"sm",onClick:M,disabled:h,className:"gap-1.5",children:h?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),u("gitView.common.processing")]}):u("gitView.stash.confirmButton",{operation:B})})]})]})})},vo=o=>{const e=Gt.c(100),{currentBranch:a,localBranches:f,remoteBranches:w,onMerge:u,onRebase:p,disabled:v,isOperating:h,operationLogs:x,onOperationComplete:B,mode:M,defaultTargetBranch:k}=o,z=v===void 0?!1:v,S=h===void 0?!1:h,L=x===void 0?[]:x,R=M===void 0?"dialog":M,{t:b}=ot(),[q,j]=i.useState(!1),[F,V]=i.useState("merge"),[P,G]=i.useState(null),[ee,A]=i.useState(!1),[r,O]=i.useState(""),J=i.useRef(null),y=i.useRef(null),_=z||S,H=a||b("gitView.branch.currentBranchFallback"),Y=L.length>0&&L.every(jo),te=L.some(Co);let he;e[0]===Symbol.for("react.memo_cache_sentinel")?(he=()=>{y.current&&(y.current.scrollTop=y.current.scrollHeight)},e[0]=he):he=e[0],i.useEffect(he,[L]);let se;if(e[1]!==r||e[2]!==a||e[3]!==f){let Z;e[5]!==a?(Z=Re=>Re!==a,e[5]=a,e[6]=Z):Z=e[6];const fe=f.filter(Z);se=Lt(fe,r,So),e[1]=r,e[2]=a,e[3]=f,e[4]=se}else se=e[4];const oe=se;let le;e[7]!==r||e[8]!==w?(le=Lt(w,r,No),e[7]=r,e[8]=w,e[9]=le):le=e[9];const m=le;let c;e[10]!==k||e[11]!==f||e[12]!==w?(c=()=>{if(!k)return null;const Z=w.find(fe=>fe.label===k);return Z||(f.includes(k)?{kind:"local",branch:k,label:k}:null)},e[10]=k,e[11]=f,e[12]=w,e[13]=c):c=e[13];const I=c;let T;e[14]!==I||e[15]!==j?(T=()=>{j(!0),G(I()),V("merge"),O("")},e[14]=I,e[15]=j,e[16]=T):T=e[16];const ne=T;let Q;e[17]===Symbol.for("react.memo_cache_sentinel")?(Q=Z=>{G(Z),A(!1),O("")},e[17]=Q):Q=e[17];const X=Q;let $;e[18]!==u||e[19]!==p||e[20]!==F||e[21]!==P?($=()=>{P&&(F==="merge"?u(P):p(P))},e[18]=u,e[19]=p,e[20]=F,e[21]=P,e[22]=$):$=e[22];const Be=$;let ce;e[23]!==S||e[24]!==j?(ce=()=>{S||(G(null),V("merge"),O(""),j(!1))},e[23]=S,e[24]=j,e[25]=ce):ce=e[25];const pe=ce,Me=()=>{S&&!Y||(Y&&B?.(),G(null),V("merge"),O(""),j(!1))};let be,Se;e[26]!==ee?(be=()=>{ee||O("")},Se=[ee],e[26]=ee,e[27]=be,e[28]=Se):(be=e[27],Se=e[28]),i.useEffect(be,Se);let ae,_e;e[29]!==R||e[30]!==I||e[31]!==P?(ae=()=>{R==="dialog"||P||G(I())},_e=[R,I,P],e[29]=R,e[30]=I,e[31]=P,e[32]=ae,e[33]=_e):(ae=e[32],_e=e[33]),i.useEffect(ae,_e);const Ae=S?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{ref:y,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:L.map(ko)})}),Y?R==="dialog"?t.jsx(Hs,{children:t.jsx(K,{variant:"default",size:"sm",onClick:Me,children:b(te?"gitView.common.close":"gitView.common.done")})}):t.jsx("div",{className:"flex justify-end",children:t.jsx(K,{variant:"default",size:"sm",onClick:Me,children:b(te?"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:b("gitView.branch.operation")}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>V("merge"),className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",F==="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(E,{name:"git-merge",className:me("size-4",F==="merge"?"text-inherit":"text-muted-foreground")}),t.jsx("span",{className:me("typography-ui-label",F==="merge"?"text-foreground":"text-muted-foreground"),children:b("gitView.operation.merge")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:b("gitView.branch.mergeDescription")})]}),t.jsxs("button",{type:"button",onClick:()=>V("rebase"),className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",F==="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(E,{name:"git-branch",className:me("size-4",F==="rebase"?"text-inherit":"text-muted-foreground")}),t.jsx("span",{className:me("typography-ui-label",F==="rebase"?"text-foreground":"text-muted-foreground"),children:b("gitView.operation.rebase")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:b("gitView.branch.rebaseDescription")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:F==="merge"?b("gitView.branch.branchToMergeInto",{branch:H}):b("gitView.branch.branchToRebaseOnto")}),t.jsxs($s,{open:ee,onOpenChange:A,modal:!1,children:[t.jsx(Ws,{asChild:!0,children:t.jsxs("button",{type:"button",className:me(en({size:"default"}),"w-full"),children:[t.jsx("span",{className:me("truncate",!P&&"text-muted-foreground"),children:P?.label||b("gitView.branch.selectBranch")}),t.jsx(E,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),t.jsx(Us,{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(Ks,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(qs,{ref:J,placeholder:b("gitView.branch.searchPlaceholder"),value:r,onValueChange:O,onKeyDown:Vo}),t.jsxs(Js,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(Ys,{children:b("gitView.branch.empty")}),oe.length>0&&t.jsx(ns,{heading:b("gitView.branch.localBranches"),children:oe.map(Z=>t.jsx(as,{onSelect:()=>X({kind:"local",branch:Z,label:Z}),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Z})},`local-${Z}`))}),oe.length>0&&m.length>0?t.jsx(Wa,{}):null,m.length>0&&t.jsx(ns,{heading:b("gitView.branch.remoteBranches"),children:m.map(Z=>t.jsx(as,{onSelect:()=>X(Z),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Z.label})},`remote-${Z.label}`))})]})]})})]})]}),P?t.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:F==="merge"?t.jsxs(t.Fragment,{children:[b("gitView.branch.summaryMergePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P.label})," ",b("gitView.branch.summaryMergeInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:H})]}):t.jsxs(t.Fragment,{children:[b("gitView.branch.summaryRebasePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:H})," ",b("gitView.branch.summaryRebaseInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P.label})]})})}):null,R==="dialog"?t.jsxs(Hs,{className:"gap-2 pt-1",children:[t.jsx(K,{variant:"ghost",size:"sm",onClick:pe,children:b("gitView.common.cancel")}),t.jsx(K,{variant:"default",size:"sm",onClick:Be,disabled:!P,className:"gap-1.5",children:F==="merge"?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"git-merge",className:"size-4"}),b("gitView.operation.merge")]}):t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"git-branch",className:"size-4"}),b("gitView.operation.rebase")]})})]}):t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(K,{variant:"destructive",size:"sm",onClick:pe,disabled:_,children:b("gitView.common.reset")}),t.jsx("div",{className:"flex-1"}),t.jsx(K,{variant:"default",size:"sm",onClick:Be,disabled:_||!P,children:b(F==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(R==="bare")return Ae;if(R==="inline"){let Z;e[34]!==b?(Z=b("gitView.branch.updateTitle"),e[34]=b,e[35]=Z):Z=e[35];let fe;e[36]!==Z?(fe=t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:Z}),e[36]=Z,e[37]=fe):fe=e[37];let Re;e[38]!==b?(Re=b("gitView.branch.updateDescriptionPrefix"),e[38]=b,e[39]=Re):Re=e[39];let ve;e[40]!==H?(ve=t.jsx("span",{className:"font-mono text-foreground",children:H}),e[40]=H,e[41]=ve):ve=e[41];let xe;e[42]!==Re||e[43]!==ve?(xe=t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Re," ",ve,"."]}),e[42]=Re,e[43]=ve,e[44]=xe):xe=e[44];let Le;e[45]!==fe||e[46]!==xe?(Le=t.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:t.jsxs("div",{className:"space-y-1",children:[fe,xe]})}),e[45]=fe,e[46]=xe,e[47]=Le):Le=e[47];let je;e[48]!==Ae?(je=t.jsx("div",{className:"pt-3",children:Ae}),e[48]=Ae,e[49]=je):je=e[49];let qe;return e[50]!==Le||e[51]!==je?(qe=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Le,je]}),e[50]=Le,e[51]=je,e[52]=qe):qe=e[52],qe}let Ye;e[53]!==S?(Ye=S?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"git-merge",className:"size-4"}),e[53]=S,e[54]=Ye):Ye=e[54];let ke;e[55]!==b?(ke=b("gitView.branch.mergeRebase"),e[55]=b,e[56]=ke):ke=e[56];let Oe;e[57]!==ke?(Oe=t.jsx("span",{children:ke}),e[57]=ke,e[58]=Oe):Oe=e[58];let W;e[59]!==ne||e[60]!==_||e[61]!==Ye||e[62]!==Oe?(W=t.jsx(os,{asChild:!0,children:t.jsxs(K,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ne,disabled:_,children:[Ye,Oe]})}),e[59]=ne,e[60]=_,e[61]=Ye,e[62]=Oe,e[63]=W):W=e[63];let Qe;e[64]!==b?(Qe=b("gitView.branch.mergeRebaseTooltip"),e[64]=b,e[65]=Qe):Qe=e[65];let He;e[66]!==Qe?(He=t.jsx(ls,{sideOffset:8,children:Qe}),e[66]=Qe,e[67]=He):He=e[67];let Ze;e[68]!==W||e[69]!==He?(Ze=t.jsxs(is,{children:[W,He]}),e[68]=W,e[69]=He,e[70]=Ze):Ze=e[70];let Ee;e[71]!==Me||e[72]!==j?(Ee=Z=>{Z?j(!0):Me()},e[71]=Me,e[72]=j,e[73]=Ee):Ee=e[73];let Xe;e[74]!==b?(Xe=b("gitView.branch.updateTitle"),e[74]=b,e[75]=Xe):Xe=e[75];let Te;e[76]!==Xe?(Te=t.jsx(gt,{children:Xe}),e[76]=Xe,e[77]=Te):Te=e[77];let et;e[78]!==te||e[79]!==S||e[80]!==F||e[81]!==Y||e[82]!==b||e[83]!==H?(et=S?b(Y?te?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":F==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):t.jsxs(t.Fragment,{children:[b("gitView.branch.dialogDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:H}),"."]}),e[78]=te,e[79]=S,e[80]=F,e[81]=Y,e[82]=b,e[83]=H,e[84]=et):et=e[84];let $e;e[85]!==et?($e=t.jsx(vt,{children:et}),e[85]=et,e[86]=$e):$e=e[86];let We;e[87]!==Te||e[88]!==$e?(We=t.jsxs(ft,{children:[Te,$e]}),e[87]=Te,e[88]=$e,e[89]=We):We=e[89];let Ue;e[90]!==Ae||e[91]!==We?(Ue=t.jsxs(ht,{className:"max-w-md",children:[We,Ae]}),e[90]=Ae,e[91]=We,e[92]=Ue):Ue=e[92];let Ve;e[93]!==q||e[94]!==Ee||e[95]!==Ue?(Ve=t.jsx(mt,{open:q,onOpenChange:Ee,children:Ue}),e[93]=q,e[94]=Ee,e[95]=Ue,e[96]=Ve):Ve=e[96];let Ke;return e[97]!==Ze||e[98]!==Ve?(Ke=t.jsxs(t.Fragment,{children:[Ze,Ve]}),e[97]=Ze,e[98]=Ve,e[99]=Ke):Ke=e[99],Ke};function jo(o){return o.status==="done"||o.status==="error"}function Co(o){return o.status==="error"}function So(o){return[o]}function No(o){return[o.label,o.branch,o.remote]}function ko(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(E,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),o.status==="done"&&t.jsx(E,{name:"check",className:"size-3.5 text-success"}),o.status==="error"&&t.jsx(E,{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:me("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 Vo(o){return o.stopPropagation()}const Ro=/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/i,Io=(o,e)=>{const a=[...o].sort((f,w)=>w.length-f.length);return e.flatMap(f=>{const w=a.find(p=>f.startsWith(`${p}/`));if(!w)return[];const u=f.slice(w.length+1);return u?[{kind:"remote",branch:u,destinationRef:`refs/remotes/${w}/${u}`,label:f,remote:w,sourceRef:`refs/heads/${u}`}]:[]})},Po=async({directory:o,git:e,runPlannedFetch:a,target:f})=>{if(f.kind==="local")return f.branch;await a(f);const u=(await e.getGitLog(o,{to:f.destinationRef,maxCount:1})).latest?.hash.trim();if(!u||!Ro.test(u))throw new we("invalid-terminal-state");return u},Fo=({runMutation:o,onMutationComplete:e,onMutationError:a,onPathsComplete:f,scheduleFlush:w})=>{const u=[];let p=!1;return{enqueue:h=>{const x=u[u.length-1];if(x?.directory===h.directory&&x.direction===h.direction){h.paths.forEach(B=>x.paths.add(B));return}u.push(h)},flush:()=>{if(p)return;const h=u.shift();if(!h)return;p=!0;const x={directory:h.directory,direction:h.direction,paths:Array.from(h.paths),rollback:h.rollback};(async()=>{try{await o(x),e(x)}catch(B){a(x,B)}finally{f(x.paths),p=!1,u.length>0&&w()}})()},clear:()=>{u.length=0},size:()=>u.length,isRunning:()=>p}},Do=15e3,Bo=40,Mo=20,Ao=2,Qr={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:"},Zr=(o,e)=>{const a=o.toLowerCase(),f=/^([a-z]+)(?:\(.*\))?!?:/,w=a.match(f);if(w){const v=w[1],h=Qr[v];if(h)return e.find(x=>x.code===h)||null}const u=a.split(" ")[0],p=Qr[u];return p&&e.find(v=>v.code===p)||null},Oo=20,ut=new Map,Eo=(o,e)=>{if(ut.delete(o),ut.set(o,e),ut.size>Oo){const a=ut.keys().next().value;a!==void 0&&ut.delete(a)}},Xr=o=>{const e=o.index?.trim();return!!(e&&e!=="?")},To=o=>{const e=o.working_dir?.trim(),a=o.index?.trim();return!!(e||a==="?")},Lo=(o,e,a,f)=>{if(e){const w=a.filter(u=>e.startsWith(`${u}/`)&&e.length>u.length+1).sort((u,p)=>p.length-u.length)[0];if(w)return{remoteName:w,destinationRef:`refs/heads/${e.slice(w.length+1)}`}}return f?{remoteName:f,destinationRef:`refs/heads/${o}`}:null},nd=({isActive:o})=>{const{t:e}=ot(),{git:a,sourceControl:f,runtime:w}=Ua(),u=Ka(),p=Ei(),[v,h]=i.useState(null),[x,B]=i.useState(null),M=it(s=>s.currentSessionId),k=it(s=>s.newSessionDraft),z=it(s=>s.setDraftBootstrapPendingDirectory),S=it(s=>s.worktreeMetadata),L=it(s=>s.availableWorktrees),R=De(u),b=i.useMemo(()=>{if(!R)return;const s=L.find(n=>De(n.path)===R);if(s)return s;for(const n of S.values())if(De(n.path)===R)return n},[L,R,S]),q=i.useMemo(()=>{if(M)return S.get(M)??b;if(k?.open)return b},[M,b,k?.open,S]),{profiles:j,globalIdentity:F,defaultGitIdentityId:V,loadProfiles:P,loadGlobalIdentity:G,loadDefaultGitIdentityId:ee}=Ii(Gr(s=>({profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId}))),{rootIsGitRepo:A,gitDirectory:r,nestedRepos:O}=qa(u??null,{enabled:o}),J=Ja(r??null),y=Ya(r??null),_=Ti({directory:r,branch:y?.current,chooseContributor:p.choose}),H=Pi(r,a,f),Y=Qa(s=>M?s.getAttachment(M):void 0),te=Y?Za(Y):[],he=Y&&!Y.degraded&&!Y.legacy?Y.worktreeRoot??void 0:void 0,se=Si(u,q,y?.current??void 0),oe=Xa(r??null),le=ei(r??null),m=ti(r??null),c=si(r??null),I=ri(r??null),{setActiveDirectory:T,ensureAll:ne,fetchStatus:Q,fetchBranches:X,fetchLog:$,setLogMaxCount:Be,fetchIdentity:ce,prefetchDiffs:pe,clearDiffCache:Me,moveStatusPathsOptimistically:be,restoreStatus:Se,bumpIndexRevision:ae,ensureNestedRepos:_e,selectNestedRepo:zt}=ni(Gr(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}))),Ne=Et(s=>s.isMobile),Ae=Et(s=>s.openContextDiff),Ye=Et(s=>s.openContextSurface),[ke,Oe]=i.useState([]),W=ai(r,f,o),[Qe,He]=i.useState(!1),Ze=i.useMemo(()=>{const s=W.read;return!s?.binding||W.status!=="ready"||s.binding.state==="bound"?null:ii(s.binding)?e("gitView.identity.configChanged"):e("gitView.context.needsAttention")},[W.read,W.status,e]),Ee=W.read?.binding?.remotes[0]?.name??W.read?.repository.remotes.find(s=>s.name==="origin")?.name??W.read?.repository.remotes[0]?.name??"",Xe=i.useCallback(s=>{const n=W.read?.repository.remotes.find(l=>l.name===Ee);return n?Fi(s,oi(n.fetch.displayUrl)):{applicable:!0}},[W.read,Ee]),Te=Mr(s=>s.entries),et=Mr(s=>s.refreshIdentityAccounts),$e=ts(s=>s.beginActiveContextsLoad),We=ts(s=>s.commitActiveContexts),Ue=ts(s=>s.releaseActiveContexts),Ve=i.useId();i.useEffect(()=>{if(!o||!u)return;const s=W.scope.runtimeKey,n=$e(s,u,Ve);return We(s,u,Ve,n,W.contexts.filter(l=>Ar(Te[Or(l)],l).connected)),()=>{Ue(s,u,Ve)}},[$e,W.contexts,W.scope.runtimeKey,We,u,o,Ue,Te,Ve]);const Ke=W.contexts[0]??null,Z=y?.current??null,fe=ts(s=>!Z||!Ke||!Ar(Te[Or(Ke)],Ke).connected?null:li(s.entries,Ke,Z)),Re=Et(s=>s.navigateToDiff),ve=i.useRef(null),xe=i.useRef(null),Le=i.useRef(null),je=i.useRef(!0);i.useEffect(()=>()=>{je.current=!1},[]);const qe=i.useCallback(()=>{ve.current!==null&&(window.clearTimeout(ve.current),ve.current=null)},[]),cs=i.useCallback(s=>{qe(),ve.current=window.setTimeout(()=>{ve.current=null,De(s)===De(r)&&Q(s,a,{silent:!0})},Do)},[qe,r,Q,a]);i.useEffect(()=>qe,[qe]);const Qs=i.useCallback(()=>{xe.current!==null&&(window.clearTimeout(xe.current),xe.current=null)},[]),_t=i.useCallback(()=>{xe.current===null&&(xe.current=window.setTimeout(()=>{xe.current=null,Le.current?.()},0))},[]),Zs=i.useCallback(async(s,n,l)=>{if(n==="stage"){if(a.stageGitFiles){await a.stageGitFiles(s,l);return}await Promise.all(l.map(d=>a.stageGitFile(s,d)));return}if(a.unstageGitFiles){await a.unstageGitFiles(s,l);return}await Promise.all(l.map(d=>a.unstageGitFile(s,d)))},[a]),tt=i.useMemo(()=>Fo({runMutation:({directory:s,direction:n,paths:l})=>Zs(s,n,l),onMutationComplete:({directory:s})=>{ae(s),cs(s)},onMutationError:({directory:s,direction:n,rollback:l},d)=>{l?.(),ae(s),cs(s);const N=e(n==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");g.error(d instanceof Error?d.message:N)},onPathsComplete:s=>{cr(n=>{const l=new Set(n);return s.forEach(d=>l.delete(d)),l})},scheduleFlush:_t}),[ae,Zs,_t,cs,e]);i.useEffect(()=>(Le.current=tt.flush,()=>{Le.current=null}),[tt]),i.useEffect(()=>()=>tt.clear(),[tt]),i.useEffect(()=>Qs,[Qs]),i.useEffect(()=>{if(!o)return;if(!u){h(null);return}const s=De(u)??u;h({directory:s,status:null});let n=!1,l=null;const d=async()=>{try{const N=await vi(u);if(n)return;h({directory:s,status:N.status}),N.status==="pending"&&(l=window.setTimeout(()=>{d()},500))}catch{n||h({directory:s,status:null})}};return d(),()=>{n=!0,l!==null&&window.clearTimeout(l)}},[o,u]);const Xs=De(k?.bootstrapPendingDirectory??null),an=!!(u&&Xs&&Xs===De(u)),on=ci(u??null),ye=De(u),ds=v?.directory===ye?v.status:null,us=!!(u&&(on||ds==="pending"||an&&k?.pendingWorktreeRequestId)),er=!!(ye&&x?.directory===ye);i.useEffect(()=>{if(!ye)return;if(ds==="failed"){z(null),B(n=>n?.directory===ye?null:n);return}if(us){B(n=>n?.directory===ye&&n.status==="refreshing"?n:{directory:ye,status:"refreshing"});return}if(x?.directory!==ye||x.status!=="refreshing"||!r||!a)return;let s=!1;return Q(r,a,{force:!0,silent:!0,throwOnError:!0}).then(()=>{s||B(n=>n?.directory===ye?null:n)}).catch(()=>{s||B(n=>n?.directory===ye?{...n,status:"failed"}:n)}),()=>{s=!0}},[Q,a,r,us,ye,ds,x,z]);const ln=us||er,ms=er&&x?.status==="failed",tr=i.useMemo(()=>r?ut.get(r)??null:null,[r]),Ct=di(s=>s.settingsGitmojiEnabled),[St,hs]=i.useState(null),{gitmojis:pt}=Qi(Ct);i.useEffect(()=>{const s=he||se?.projectDirectory;if(!s){hs(null);return}let n=!1;return ui(s).then(l=>{if(n)return;const d=l.trim();hs(d&&d!=="HEAD"?d:null)}).catch(()=>{n||hs(null)}),()=>{n=!0}},[he,se?.projectDirectory]);const[Nt,xt]=i.useState(tr?.commitMessage??""),[sr,cn]=i.useState([]),[dn,fs]=i.useState(!1),rr=i.useRef(null),[nr,Ht]=i.useState(null),[un,gs]=i.useState(!1),[ar,ir]=i.useState(null),[Ie,mn]=i.useState(25),[hn,or]=i.useState(!1),{triggerFireworks:fn}=Ni(),lr=i.useRef(new Map),$t=i.useRef(0),ps=i.useCallback(()=>{$t.current+=1,je.current&&or(!0)},[]),xs=i.useCallback(()=>{$t.current=Math.max(0,$t.current-1),je.current&&$t.current===0&&or(!1)},[]),[ys,Wt]=i.useState(new Set),[gn,cr]=i.useState(new Set),[ws,dr]=i.useState(!1),[pn,xn]=i.useState(0),[yn,ur]=i.useState(!1),[bs,vs]=i.useState(tr?.generatedHighlights??[]),wn=gn.size>0||tt.size()>0||tt.isRunning(),mr=i.useCallback(()=>{const s=rr.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),js=he||se?.projectDirectory||null,Cs=y?.current||null,bn=i.useMemo(()=>{const s=y?.tracking;return s?s.startsWith("origin/"):!0},[y?.tracking]),hr=i.useMemo(()=>{const s=se?.createdFromBranch,n=typeof s=="string"?s.trim():"",l=typeof y?.current=="string"?y.current.trim():"",d=typeof St=="string"?St.trim():"";return n?n===l&&n.startsWith("opencode/")&&d.length>0&&d!==n?d:n:d||l||"HEAD"},[se?.createdFromBranch,y,St]),Ut=i.useCallback(()=>{vs([])},[]),[Ss,vn]=i.useState(new Set),[Kt,jn]=i.useState(new Map),[qt,Ns]=i.useState(new Set),ks=i.useRef(Kt),kt=i.useRef(qt),[Cn,yt]=i.useState(null),[fr,gr]=i.useState(""),[ge,Jt]=i.useState(null),[Sn,pr]=i.useState(!1),[Nn,xr]=i.useState(!1),[kn,yr]=i.useState(null),[wr,br]=i.useState(null),[Vn,Yt]=i.useState([]),[Rn,wt]=i.useState(!1),[In,Vt]=i.useState([]),[Qt,Rt]=i.useState("merge"),[Pn,Vs]=i.useState(null),[Rs,vr]=i.useState(!1),[Is,Fn]=i.useState(100),[Dn,Bn]=i.useState(0),Pe=i.useMemo(()=>M?`openchamber.conflict:${M}`:null,[M]),jr=i.useCallback((s,n,l)=>{if(!Pe||typeof window>"u")return;const d={directory:s,conflictFiles:n,operation:l};window.localStorage.setItem(Pe,JSON.stringify(d))},[Pe]),Fe=i.useCallback(()=>{!Pe||typeof window>"u"||window.localStorage.removeItem(Pe)},[Pe]),Je=i.useCallback((s,n)=>{Vt(s),Rt(n),wt(!0),r&&jr(r,s,n)},[r,jr]);i.useEffect(()=>{if(!Pe||typeof window>"u"||!r)return;const s=window.localStorage.getItem(Pe);if(s)try{const n=JSON.parse(s);if(n.directory!==r){window.localStorage.removeItem(Pe);return}Vt(n.conflictFiles??[]),Rt(n.operation??"merge"),wt(!0)}catch{window.localStorage.removeItem(Pe)}},[Pe,r]);const[Mn,Cr]=i.useState(!1),[Zt,It]=i.useState(null),[Ps,An]=i.useState("merge"),[Fs,On]=i.useState(""),[Ds,En]=i.useState(""),Tn=i.useCallback(s=>{mi(s).then(n=>{if(n.ok){g.success(e("gitView.toast.commitHashCopied"));return}g.error(e("gitView.toast.copyFailed"))})},[e]),Ln=i.useCallback(s=>{vn(n=>{const l=new Set(n);return l.has(s)?l.delete(s):l.add(s),l})},[]);i.useEffect(()=>{ks.current=Kt},[Kt]),i.useEffect(()=>{kt.current=qt},[qt]),i.useEffect(()=>{if(!r||!a)return;const s=Array.from(Ss).filter(l=>!ks.current.has(l)&&!kt.current.has(l));if(s.length===0)return;let n=!1;return Ns(l=>{const d=new Set(l);for(const N of s)d.add(N);return kt.current=d,d}),Promise.all(s.map(l=>a.getCommitFiles(r,l).then(d=>({hash:l,files:d.files})).catch(d=>(console.error("Failed to fetch commit files:",d),{hash:l,files:[]})))).then(l=>{n||(jn(d=>{const N=new Map(d);for(const{hash:C,files:D}of l)N.set(C,D);return ks.current=N,N}),Ns(d=>{const N=new Set(d);for(const{hash:C}of l)N.delete(C);return kt.current=N,N}))}),()=>{n=!0,Ns(l=>{let d=!1;const N=new Set(l);for(const C of s)N.delete(C)&&(d=!0);return d?(kt.current=N,N):l})}},[Ss,r,a]),i.useEffect(()=>{if(!r)return;const s=ut.get(r)??null;xt(s?.commitMessage??""),vs(s?.generatedHighlights??[])},[r]),i.useEffect(()=>{r&&Eo(r,{directory:r,commitMessage:Nt,generatedHighlights:bs})},[Nt,r,bs]),i.useEffect(()=>{o&&(P(),G(),ee())},[o,P,G,ee]);const Xt=i.useCallback(async()=>{if(!r||!a?.getRemotes||J!==!0){Oe([]);return}try{const s=await a.getRemotes(r);je.current&&Oe(s)}catch{je.current&&Oe([])}},[r,a,J]);i.useEffect(()=>{o&&Xt()},[o,Xt]),i.useEffect(()=>{o&&u&&r&&(T(u),ne(r,a))},[o,u,r,T,ne,a]),i.useEffect(()=>{if(o&&r)return hi.onGitRefreshHint(s=>{De(s.directory)===De(r)&&(s.paths?.length&&Me(r,s.paths),Q(r,a,{silent:!0}))})},[o,Me,r,Q,a]);const re=i.useCallback(async(s=!0)=>{if(r)try{await Promise.all([Q(r,a),X(r,a)])}catch(n){if(s){const l=n instanceof Error?n.message:e("gitView.toast.refreshRepositoryFailed");g.error(l)}}},[r,a,Q,X,e]),de=i.useCallback(async()=>{r&&await $(r,a,Ie)},[r,a,$,Ie]),lt=i.useCallback(async s=>{if(!r)return;const n=Promise.allSettled([X(r,a),de()]);s&&n.then(s),await Q(r,a).catch(()=>{})},[r,a,X,Q,de]),Bs=i.useCallback(async()=>{r&&await ce(r,a)},[r,a,ce]);i.useEffect(()=>{if(!o||!r||!a?.hasLocalIdentity||J!==!0)return;const s=typeof V=="string"?V.trim():"";if(!s||s==="global")return;const n=dt(),l=JSON.stringify([n,r]);if(lr.current.get(l)===s)return;let N=!1,C=!1;return(async()=>{try{const U=await a.hasLocalIdentity?.(r);if(N||dt()!==n||U===!0||(ps(),C=!0,await a.setGitIdentity(r,s),N||dt()!==n))return;lr.current.set(l,s),await Bs()}catch(U){!N&&dt()===n&&console.warn("Failed to auto-apply default git identity:",U)}finally{C&&xs()}})(),()=>{N=!0}},[o,ps,r,V,xs,a,J,Bs]);const st=i.useMemo(()=>y?[...y.files??[]].sort((n,l)=>n.path.localeCompare(l.path)):[],[y]),Ce=i.useMemo(()=>st.filter(Xr),[st]),Ms=i.useMemo(()=>st.filter(To),[st]);i.useEffect(()=>{if(!o||!r||st.length===0)return;const s=[],n=new Set,l=N=>{!N||n.has(N)||(n.add(N),s.push(N))};if(Ce.forEach(N=>l(N.path)),sr.forEach(l),st.slice(0,Mo).forEach(N=>l(N.path)),s.length===0)return;const d=window.setTimeout(()=>{pe(r,a,s,{maxFiles:Bo})},120);return()=>{window.clearTimeout(d)}},[o,st,r,a,pe,Ce,sr]);const Pt=async(s,n,l=!1)=>{if(!r)return;const d=H.start();if(!d)return;Ht(s);const N=e(s==="fetch"?"gitView.sync.fetch":s==="pull"?"gitView.sync.pull":s==="publish"?"gitView.publish.title":"gitView.sync.syncChanges");let C=null;try{if(s==="sync"||s==="publish"){const D=await _.prepare(s==="publish"?"push":"sync",{forceChoose:l,onOperation:d.onOperation});C=Ci(await D())}else if(n&&y)await Tr({action:s,directory:r,remoteName:n.name,status:y,sourceControl:f,git:a,onOperation:d.onOperation});else throw new we("tracking-required");if(!d.isCurrent())return;s==="fetch"&&n?g.success(e("gitView.toast.fetchedFromRemote",{name:n.name})):s==="pull"&&n?g.success(e("gitView.toast.pulledFromRemote",{name:n.name})):s==="sync"?g.success(C?.kind==="up-to-date"?e("gitView.toast.alreadyUpToDate"):C?.kind==="pulled"?e("gitView.toast.pulledFromRemote",{name:C.remoteName}):C?.kind==="pushed"?e("gitView.toast.pushedToUpstream",{name:C.remoteName}):e("gitView.toast.syncedChanges")):s==="publish"&&g.success(e("gitView.publish.succeeded")),await lt()}catch(D){if(D instanceof At||D instanceof Lr){if(D instanceof At&&D.read.availability==="available"&&g.error(e("gitView.toast.syncActionFailed",{action:N}),{description:D.message||void 0}),d.isCurrent()&&await lt(),d.isCurrent()&&D instanceof At&&D.read.availability==="available"&&D.read.operation.state==="conflicted"&&D.read.operation.error.code==="CONFLICT"){const ze=((await a.getGitStatus(r).catch(()=>null))?.files??[]).filter(Gs).map(ya=>ya.path);ze.length>0&&Je(ze,"merge")}return}if(D instanceof we&&D.code==="stale-runtime")return;if(D instanceof we&&_.errorMessage(D)){g.info(_.errorMessage(D));return}await lt();const U=D instanceof we?D.code==="contributor-publish-cancelled-after-update"?e("gitView.toast.contributorPublishCancelledAfterUpdate"):D.code==="contributor-publish-cancelled"?e("gitView.toast.contributorPublishCancelled"):e("gitView.toast.syncActionFailed",{action:N}):D instanceof Error?D.message:e("gitView.toast.syncActionFailed",{action:N});g.error(U)}finally{d.finish(),d.isCurrent()&&Ht(null)}},Gn=i.useCallback(async s=>{if(!r)return;const n=s.name.trim();if(!n){g.error(e("gitView.toast.remoteNameRequired"));return}if(n==="origin"){g.error(e("gitView.toast.cannotRemoveOriginRemote"));return}yr(n);try{await a.removeRemote(r,{remote:n}),g.success(e("gitView.toast.removedRemote",{name:n})),await Promise.all([re(!1),Xt()])}catch(l){const d=l instanceof Error?l.message:`Failed to remove ${n}`;g.error(d)}finally{yr(null)}},[r,a,Xt,re,e]),Sr=async(s={})=>{if(!r)return;if(!Nt.trim()){g.error(e("gitView.toast.enterCommitMessage"));return}const n=Ce.map(C=>C.path).sort();if(n.length===0){g.error(e("gitView.toast.stageFileToCommit"));return}const l=s.pushAfter?"commitAndPush":"commit";ir(l);let d=null,N="pending";try{if(await a.createGitCommit(r,Nt.trim(),{files:n,stageFiles:[]}),N="local",ae(r),ae(r),g.success(e("gitView.toast.commitCreated")),xt(""),Ut(),s.pushAfter){if(d=H.start(),!d){g.warning(e("gitView.publish.commitKept")),await lt();return}const C=await _.prepare("push",{onOperation:d.onOperation});Ht("publish"),await C(),N="published",g.success(e("gitView.publish.succeeded")),fn()}await lt(()=>xn(C=>C+1))}catch(C){if(s.pushAfter&&N==="local"&&g.warning(e("gitView.publish.commitKept")),C instanceof At||C instanceof Lr){C instanceof At&&C.read.availability==="available"&&g.error(e("gitView.toast.pushFailed"),{description:C.message||void 0}),await lt();return}if(C instanceof we&&C.code==="stale-runtime")return;if(C instanceof we&&_.errorMessage(C)){g.info(_.errorMessage(C));return}s.pushAfter&&await lt();const D=C instanceof we?C.code==="contributor-publish-cancelled-after-update"?e("gitView.toast.contributorPublishCancelledAfterUpdate"):C.code==="contributor-publish-cancelled"?e("gitView.toast.contributorPublishCancelled"):e("gitView.toast.syncActionFailed",{action:e("gitView.sync.syncChanges")}):C instanceof Error?C.message:e("gitView.toast.createCommitFailed");g.error(D)}finally{d?.finish(),ir(null),s.pushAfter&&Ht(null)}},zn=i.useCallback(async()=>{if(!r)return;const s=Ce.map(n=>n.path).sort();if(s.length===0){g.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:s.length}),ur(!0);try{const{message:n}=await Er(r,s),l=n.subject?.trim()??"",d=Array.isArray(n.highlights)?n.highlights:[];if(l){let N=l;if(Ct&&pt.length>0){const C=Zr(l,pt);if(C){const{code:D,emoji:U}=C;!l.startsWith(D)&&!l.startsWith(U)&&(N=`${D} ${l}`)}}xt(N)}vs(d),mr()}catch(n){console.error("[git-generation][browser] GitView generate handler failed",{message:n instanceof Error?n.message:String(n),error:n});const l=n instanceof Error?n.message:e("gitView.toast.generateCommitMessageFailed");g.error(l)}finally{ur(!1)}},[r,Ce,Ct,pt,mr,e]),As=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",_n=async s=>{if(!r||!y)return;const n=Ls(Y);if(n.length>0){g.error(e("gitView.toast.cannotCreateBranch",{reason:As(n[0])}));return}const l=y.current??null;try{await a.createBranch(r,s,l??"HEAD"),g.success(e("gitView.toast.createdBranch",{name:s})),await a.checkoutBranch(r,s),await re(),await de()}catch(d){if(d instanceof we&&d.code==="stale-runtime")return;const N=d instanceof Error?d.message:e("gitView.toast.createBranchFailed");throw g.error(N),d}},Hn=async(s,n)=>{if(!r)return;const l=Ls(Y);if(l.length>0){g.error(e("gitView.toast.cannotRenameBranch",{reason:As(l[0])}));return}try{await a.renameBranch(r,s,n),g.success(e("gitView.toast.renamedBranch",{oldName:s,newName:n})),await re(),await de()}catch(d){const N=d instanceof Error?d.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:n});g.error(N)}},$n=async s=>{if(!r)return;const n=Ls(Y);if(n.length>0){g.error(e("gitView.toast.cannotCheckout",{reason:As(n[0])}));return}const l=s.replace(/^remotes\//,"");if(y?.current!==l){if((y?.files?.length??0)>0){It(l);return}await Os(l)}},Os=async s=>{if(!r)return;const n=s;try{const l=await a.checkoutBranch(r,n);g.success(e("gitView.toast.checkedOut",{name:l?.branch||n})),await re(),await de()}catch(l){const d=l instanceof Error?l.message:e("gitView.toast.checkoutFailed",{name:n});g.error(d)}},Wn=async s=>{if(!r)return;const n=dt();ps();try{const l=await Oi({directory:r,identity:s,remoteName:Ee||null},{git:a,sourceControl:f});if(dt()!==n)return;l.status==="failed"?g.error(e("gitView.toast.applyIdentityFailed")):g.success(e("gitView.toast.appliedIdentity",{name:ji(s,e)})),await Bs()}catch(l){if(dt()!==n)return;const d=l instanceof Error?l.message:e("gitView.toast.applyIdentityFailed");g.error(d)}finally{xs()}},Ft=i.useMemo(()=>oe?.all?oe.all.filter(s=>!s.startsWith("remotes/")).sort():[],[oe]),Dt=i.useMemo(()=>oe?.all?oe.all.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],[oe]),Un=i.useMemo(()=>Io(ke.map(s=>s.name),Dt),[ke,Dt]),rt=y?.current??null,Nr=i.useMemo(()=>{const s=W.contexts[0]?.primaryRemote;return s?oe?.defaultBranches?.[s]:void 0},[W.contexts,oe]),ct=i.useMemo(()=>Di({remoteNames:new Set(W.contexts[0]?.primaryRemote?[W.contexts[0].primaryRemote]:[]),knownRemoteNames:new Set(W.read?.repository.remotes.map(s=>s.name)??[]),localBranches:Ft,worktreeCreatedFromBranch:se?.createdFromBranch,rootBranchHint:St,defaultBranch:Nr,headBranch:rt,fallbackToConventional:!1}),[rt,Nr,W.contexts,Ft,W.read,St,se?.createdFromBranch]),Kn=i.useMemo(()=>{const s=W.contexts[0]?.primaryRemote,n=s?`${s}/${ct}`:null;return n&&Dt.includes(n)?n:ct},[ct,W.contexts,Dt]),kr=fi(),qn=i.useMemo(()=>gi(j,F,s=>ba(s)&&pi(s,kr)),[j,F,kr]),Vr=W.read?W.read.binding?.providers.find(s=>s.readiness==="ready")?.accountId??null:void 0,Jn=i.useMemo(()=>xi(j,F,m,s=>({id:"local-config",name:s.userName,...s,color:"info",icon:"user"}),Vr),[Vr,m,j,F]),Yn=Ce.length,Qn=c||nr!==null||ar!==null,Zn=!!(se&&js&&Cs&&bn),Rr=!!rt,nt=Zn&&js&&Cs&&se?{repoRoot:js,sourceBranch:Cs,worktreeMetadata:se}:null;i.useEffect(()=>{if(!r||!a||!le?.all?.length||!rt||!ct||rt===ct){yt(null);return}let s=!1;return(async()=>{try{const l=await a.getGitLog(r,{from:ct,to:"HEAD",maxCount:Ie});if(s)return;const d=new Set((l?.all??[]).map(C=>C.hash).filter(C=>typeof C=="string"&&C.length>0));if(d.size===0){yt(null);return}const N=le.all.findIndex(C=>!d.has(C.hash));if(N===0){yt(null);return}if(N===-1){yt({insertBeforeIndex:le.all.length,branchName:rt,direction:"up"});return}yt({insertBeforeIndex:N,branchName:rt,direction:"up"})}catch{s||yt(null)}})(),()=>{s=!0}},[ct,rt,r,a,le,Ie]),i.useEffect(()=>{Vs(null)},[r]),i.useEffect(()=>{if(ge!=="graph"||!r){ge!=="graph"&&Vs(null);return}let s=!1;return vr(!0),a.getGitLog(r,{maxCount:Is,all:!0}).then(n=>{s||Vs(n)}).catch(n=>{console.error("Failed to fetch graph log:",n)}).finally(()=>{s||vr(!1)}),()=>{s=!0}},[ge,r,Is,Dn,a]);const Bt=i.useCallback((s,n)=>{if(!r||s.length===0)return;const l=Array.from(new Set(s));cr(N=>{const C=new Set(N);return l.forEach(D=>C.add(D)),C});const d=be(r,l,n);tt.enqueue({directory:r,direction:n,paths:new Set(l),rollback:()=>Se(r,d)}),_t()},[r,tt,be,Se,_t]),Es=i.useCallback(async s=>{if(r){Wt(n=>{const l=new Set(n);return l.add(s),l});try{await a.revertGitFile(r,s,{scope:"working"}),g.success(e("gitView.toast.revertedFile",{path:s})),await re(!1)}catch(n){const l=n instanceof Error?n.message:e("gitView.toast.revertFailed");g.error(l)}finally{Wt(n=>{const l=new Set(n);return l.delete(s),l})}}},[r,re,a,e]),Mt=i.useCallback(async(s,n,l="all")=>{if(!r||s.length===0)return;const d=Array.from(new Set(s));if(ws||d.some(U=>ys.has(U)))return;const N=new Set(Ce.map(U=>U.path)),C=l==="all"&&d.some(U=>N.has(U));n&&dr(!0),Wt(U=>{const ie=new Set(U);return d.forEach(ze=>ie.add(ze)),ie});const D=[];try{if(await yi(d,Ao,async U=>{try{await a.revertGitFile(r,U,{scope:l})}catch(ie){D.push({path:U,message:ie instanceof Error?ie.message:e("gitView.toast.revertFailed")})}}),C&&D.length<d.length&&ae(r),await re(!1),D.length===0)g.success(d.length===1?e("gitView.toast.revertedFilesSingle",{count:d.length}):e("gitView.toast.revertedFilesPlural",{count:d.length}));else if(D.length===d.length)g.error(D[0]?.message||e("gitView.toast.revertFailed"));else{const U=d.length-D.length;g.warning(U===1?e("gitView.toast.revertedSomeSingle",{success:U,failed:D.length}):e("gitView.toast.revertedSomePlural",{success:U,failed:D.length}))}}finally{Wt(U=>{const ie=new Set(U);return d.forEach(ze=>ie.delete(ze)),ie}),n&&dr(!1)}},[ae,r,a,ws,re,ys,Ce,e]),Xn=i.useCallback(async s=>{await Mt(s,!0)},[Mt]),ea=i.useCallback(async s=>{await Mt(s,!1,"working")},[Mt]),Ts=i.useCallback((s,n)=>{if(u&&!Ne){Ae(u,s,n);return}Re(s,n)},[u,Ne,Re,Ae]),ta=i.useCallback(()=>gs(!0),[]),sa=i.useMemo(()=>{const s=[];return Ce.length>0&&s.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:Ce,statsScope:"staged",actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:n=>e("gitView.changes.unstageFileAria",{path:n}),onActionFile:n=>{Bt([n],"unstage")},onActionAll:n=>{Bt(n,"unstage")},onViewDiff:n=>Ts(n,!0),onRevertFile:Es,showRevertActions:!1,accent:!0}),Ms.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:Ms,statsScope:"working",actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:n=>e("gitView.changes.stageFileAria",{path:n}),onActionFile:n=>{Bt([n],"stage")},onActionAll:n=>{Bt(n,"stage")},onViewDiff:n=>Ts(n,!1),onRevertFile:Es}),s},[Es,Ts,Bt,Ce,e,Ms]),ra=i.useCallback(s=>{if(s.length===0)return;const n=s.map(l=>l.trim()).filter(Boolean);if(n.length===0){Ut();return}xt(l=>{const d=l.trim(),N=d.length>0?`
|
|
1
|
+
import{R as i,r as de,j as t,f as Gt}from"./vendor-react-BUCujlKS.js";import{h as wa,u as Et,t as De,a as ut,E as ba}from"./index-DxNa7xYB.js";import{f as ot,z as it,aj as Lt,mt as va,gS as Fr,dr as Dr,t as g,I as E,aR as $s,aS as Ws,aT as en,aU as Ks,d$ as Us,e0 as qs,e1 as Js,e2 as Ys,e3 as ns,dR as as,B as U,mu as ja,mv as Ca,b_ as mt,bZ as ht,bW as ft,bU as gt,bV as vt,a8 as Br,at as is,au as os,av as ls,mw as Sa,h as me,mx as Na,my as ka,mz as Va,mA as Ra,bH as Ia,aY as Pa,dm as Fa,mB as Da,mC as Ba,mD as Ma,mE as Aa,mF as Oa,mG as Ea,mH as Ta,cA as tn,cY as La,cZ as Ga,c_ as za,c$ as Ha,d0 as _a,fT as $a,cz as _s,gq as Wa,X as we,N as Ka,ay as Ua,az as qa,K as Ja,aA as Ya,ck as Qa,mI as Xa,aB as Za,mJ as ei,aC as ti,aH as si,mK as ri,L as ni,aI as ai,aK as ii,aX as oi,aE as Mr,cO as ts,cP as Ar,cQ as Or,lp as li,mL as ci,l as ui,d5 as di,g as mi,dT as hi,aP as Er,aD as fi,aF as gi,aG as pi,aJ as xi,ax as yi,b0 as Tr,al as wi,ix as bi,mM as vi,a_ as ji,mN as Ls,a$ as Ci,V as At,W as Lr}from"./useAppFontEffects-DGlvOqP_.js";import{u as Si,a as Ni}from"./main-CfBSQM1H.js";import{bf as ki,bg as Vi,be as Ri,o as Ii,n as Pi,q as Fi,t as Di,y as Bi,aC as Mi,v as Gs,F as Ai,bA as Oi,G as Ei,P as Ti,w as Li,E as Gi}from"./runtimeEndpointReset-CZ5aafpl.js";import{u as Gr}from"./vendor-zustand-BAGL70zf.js";import{R as zi,I as Hi,C as _i,a as $i,b as Wi,D as Ki}from"./InProgressOperationBanner-CwMjNQgk.js";import{P as Ui}from"./PierreDiffViewer-CnnR-dnD.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-CxRSdNoV.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-client-BmFcUkbQ.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-base-ui-Det7U81h.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.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-tanstack-react-virtual-CvuLsk7D.js";import"./vendor-tanstack-virtual-core-DPaNcJcT.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-C4G_dPWe.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-1e0FQ6Wn.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-DufXoQvE.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DbpEcZM0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BSHQHbKu.js";import"./vendor-codemirror-lang-json-BzgckzmB.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-Cayfb29q.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-BQWerHsJ.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-D2TEBIvZ.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CtwSWKtX.js";import"./vendor-codemirror-lang-python-jAMtYiA9.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-capacitor-core-B4EWRrHz.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-legendapp-list-DViGR95I.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-katex-CuQvj9-L.js";import"./useRootScrollLock-DMPpvpNP.js";import"./fileTreeStatus-D438yi8M.js";import"./sessionOwnership-BSuxCEhb.js";import"./space-apply-DM_2pRW7.js";import"./vendor-cron-parser-CjvYVigk.js";import"./vendor-luxon-BZ0puJYg.js";import"./changesTree-CePHbFcj.js";import"./parseDiffFromFile-BUgn-T9p.js";import"./computeVirtualFileMetrics-C2WM6JC2.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"./vendor-diff-C3JhlQdm.js";import"./isDiffPlainText-Dgbw8VKk.js";import"./VirtualizedFileDiff-CFpjL8Ns.js";import"./Virtualizer-C0IsclZn.js";import"./useInlineCommentController-kMN4Wg_D.js";import"./appThemeRegistry-B9gkFq9i.js";import"./textMateThemeFromAppTheme-DlsTphbY.js";const sn="gitmojiCache",qi=1e3*60*60*24*7,rn="1",Ji="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",nn=o=>{if(!o||typeof o!="object")return!1;const e=o;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},zs=()=>{if(typeof window>"u")return null;try{const o=window.localStorage.getItem(sn);if(!o)return null;const e=JSON.parse(o);return!e||e.version!==rn||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(nn),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Yi=o=>{if(!(typeof window>"u"))try{const e={gitmojis:o,fetchedAt:Date.now(),version:rn};window.localStorage.setItem(sn,JSON.stringify(e))}catch{return}},zr=o=>Date.now()-o.fetchedAt<qi;let ss=null;const Tt=new Set,Hr=async()=>{if(ss)return ss;const o=(async()=>{try{const e=await fetch(Ji);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const a=await e.json(),f=Array.isArray(a.gitmojis)?a.gitmojis.filter(nn):[];return Yi(f),Tt.forEach(w=>w(f)),f}catch(e){console.warn("Failed to load gitmoji list:",e);const a=[];return Tt.forEach(f=>f(a)),a}finally{ss=null}})();return ss=o,o},Qi=o=>{const[e,a]=i.useState(()=>o?zs()?.gitmojis??[]:[]),[f,w]=i.useState(!1),d=i.useRef(o);d.current=o,i.useEffect(()=>{if(!o){Tt.delete(a),a([]),w(!1);return}const v=zs();if(v&&(a(v.gitmojis),zr(v)))return;Tt.add(a),w(!0);let h=!1;return Hr().finally(()=>{!h&&d.current&&w(!1)}),()=>{h=!0,Tt.delete(a)}},[o]);const p=i.useCallback(async()=>{if(!d.current)return[];if(e.length>0)return e;const v=zs();return v&&zr(v)?v.gitmojis:Hr()},[e]);return{gitmojis:e,isLoading:f,ensureLoaded:p}},jt=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 f=await a.json().catch(()=>null);throw new Error(f?.error||`Git integrate request failed: ${a.statusText}`)}return a.json()};async function Ot(o){return jt("plan",o)}async function Xi(o){return jt("conflict-details",{tempWorktreePath:o})}async function Zi(o){return(await jt("cherry-pick-status",{tempWorktreePath:o})).inProgress}async function eo(o){return jt("run",{plan:o})}async function to(o){await jt("abort",{state:o})}async function so(o){return jt("continue",{state:o})}const ro=({repoRoot:o,sourceBranch:e,worktreeMetadata:a,localBranches:f,defaultTargetBranch:w,refreshKey:d,onRefresh:p,showHeader:v=!0})=>{const{t:h}=ot(),x=it(m=>m.currentSessionId),[B,M]=de.useState(!1),[k,z]=de.useState(""),S=de.useRef(null),L=de.useMemo(()=>Lt(f,k,m=>[m]),[f,k]),[R,b]=de.useState(w);de.useEffect(()=>{b(w)},[w]),de.useEffect(()=>{if(B){const m=setTimeout(()=>{S.current?.focus()},0);return()=>clearTimeout(m)}},[B]);const q=!!(o&&e&&R&&R!=="HEAD"&&e!==R),[j,F]=de.useState({kind:"idle"}),[V,P]=de.useState(!1),[G,ee]=de.useState([]),A=de.useMemo(()=>x?`openchamber.integrate.conflict:${x}`:null,[x]);de.useEffect(()=>{if(!A||typeof window>"u")return;const m=window.localStorage.getItem(A);if(!m)return;let c=!1;try{const I=JSON.parse(m);if(!I?.tempWorktreePath||I.repoRoot!==o){window.localStorage.removeItem(A);return}(async()=>{const T=await Zi(I.tempWorktreePath).catch(()=>!1);if(c)return;if(!T){window.localStorage.removeItem(A);return}const ne=await Xi(I.tempWorktreePath).catch(()=>null);c||ne&&F({kind:"conflict",state:I,details:ne})})()}catch{window.localStorage.removeItem(A)}return()=>{c=!0}},[A,o]),de.useEffect(()=>{if(!q){F({kind:"idle"});return}let m=!1;return F({kind:"loading"}),(async()=>{try{const c=await Ot({repoRoot:o,sourceBranch:e,targetBranch:R});if(m)return;if(F({kind:"ready",plan:c}),c.commits.length>0){const T=c.commits.slice(-50).reverse(),ne=await va(o,T);m||(ee(ne),P(!1))}else m||(ee([]),P(!1))}catch{m||F({kind:"idle"})}})(),()=>{m=!0}},[q,o,e,R,d]);const r=de.useCallback(m=>{x&&it.getState().setWorktreeMetadata(x,{...a,createdFromBranch:m})},[x,a]),O=it(m=>m.openNewSessionDraft),J=de.useCallback(async m=>{const c=await Fr("git.integrate.cherrypick.resolve.visible",{current_commit:m.state.currentCommit,target_branch:m.state.targetBranch}),I=await Fr("git.integrate.cherrypick.resolve.instructions",{repo_root:m.state.repoRoot,temp_worktree_path:m.state.tempWorktreePath,source_branch:m.state.sourceBranch,target_branch:m.state.targetBranch,current_commit:m.state.currentCommit}),T=`Cherry-pick conflict context (JSON)
|
|
2
|
+
${JSON.stringify({repoRoot:m.state.repoRoot,tempWorktreePath:m.state.tempWorktreePath,sourceBranch:m.state.sourceBranch,targetBranch:m.state.targetBranch,currentCommit:m.state.currentCommit,remainingCommits:m.state.remainingCommits,statusPorcelain:m.details.statusPorcelain,unmergedFiles:m.details.unmergedFiles,currentPatchMeta:m.details.currentPatchMeta,currentPatch:m.details.currentPatch,diff:m.details.diff},null,2)}`;return{visibleText:c,instructionsText:I,payloadText:T}},[]),y=Dr(m=>m.setPendingInputText),H=Dr(m=>m.setPendingSyntheticParts),_=de.useCallback(async(m,c)=>{const I=await J(m);if(c){O({directoryOverride:m.state.tempWorktreePath,initialPrompt:I.visibleText,syntheticParts:[{text:I.instructionsText,synthetic:!0},{text:I.payloadText,synthetic:!0}]});return}if(!x){g.error(h("gitView.integrate.noActiveSession"),{description:h("gitView.integrate.noActiveSessionDescription")});return}y(I.visibleText,"replace"),H([{text:I.instructionsText,synthetic:!0},{text:I.payloadText,synthetic:!0}])},[x,J,O,y,H,h]),Y=de.useCallback(async()=>{if(j.kind==="ready"){if(j.plan.commits.length===0){g.message(h("gitView.integrate.noCommitsToMoveToast"));return}F({kind:"running",plan:j.plan});try{const m=await eo(j.plan);if(m.kind==="success"){g.success(h("gitView.integrate.commitsMovedToast"),{description:m.moved===1?h("gitView.integrate.commitsMovedDescriptionSingle",{count:m.moved,branch:j.plan.targetBranch}):h("gitView.integrate.commitsMovedDescriptionPlural",{count:m.moved,branch:j.plan.targetBranch})});const c=await Ot(j.plan);F({kind:"ready",plan:c}),p?.();return}m.kind==="conflict"&&(g.error(h("gitView.integrate.cherryPickConflictToast"),{description:h("gitView.integrate.cherryPickConflictDescription")}),F({kind:"conflict",state:m.state,details:m.details}),A&&typeof window<"u"&&window.localStorage.setItem(A,JSON.stringify(m.state)))}catch(m){const c=m instanceof Error?m.message:String(m);g.error(h("gitView.integrate.failedToMoveToast"),{description:c});const I=await Ot({repoRoot:o,sourceBranch:e,targetBranch:R}).catch(()=>null);F(I?{kind:"ready",plan:I}:{kind:"idle"})}}},[j,p,o,e,R,A,h]),te=de.useCallback(async()=>{if(j.kind==="conflict")try{await to(j.state),g.message(h("gitView.integrate.cherryPickAbortedToast")),A&&typeof window<"u"&&window.localStorage.removeItem(A)}finally{const m=await Ot({repoRoot:o,sourceBranch:e,targetBranch:R}).catch(()=>null);F(m?{kind:"ready",plan:m}:{kind:"idle"})}},[j,o,e,R,A,h]),he=de.useCallback(async()=>{if(j.kind==="conflict")try{const m=await so(j.state);if(m.kind==="success"){g.success(h("gitView.integrate.cherryPickFinishedToast"));const c=await Ot({repoRoot:o,sourceBranch:e,targetBranch:R}).catch(()=>null);F(c?{kind:"ready",plan:c}:{kind:"idle"}),A&&typeof window<"u"&&window.localStorage.removeItem(A),p?.();return}m.kind==="conflict"&&(F({kind:"conflict",state:m.state,details:m.details}),A&&typeof window<"u"&&window.localStorage.setItem(A,JSON.stringify(m.state)))}catch(m){const c=m instanceof Error?m.message:String(m);g.error(h("gitView.integrate.cherryPickContinueFailedToast"),{description:c})}},[j,o,e,R,p,A,h]);return!o||!e?null:t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[v?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(E,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:h("gitView.integrate.title")}),j.kind==="ready"&&j.plan.commits.length>0?t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:h("gitView.integrate.toMoveCount",{count:j.plan.commits.length})}):null]}),t.jsx("div",{className:"flex items-center gap-2",children:j.kind==="loading"||j.kind==="running"?t.jsx(E,{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:h("gitView.integrate.moveCommits")}),t.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",R]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs($s,{open:B,onOpenChange:M,children:[t.jsx(Ws,{asChild:!0,children:t.jsxs("button",{type:"button",className:en({size:"default"}),children:[h("gitView.integrate.target"),t.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:R}),t.jsx(E,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),t.jsx(Ks,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:t.jsxs(Us,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(qs,{ref:S,placeholder:h("gitView.branch.searchPlaceholder"),value:k,onValueChange:z,onKeyDown:m=>m.stopPropagation()}),t.jsxs(Js,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(Ys,{children:h("gitView.branch.empty")}),t.jsx(ns,{heading:h("gitView.branch.localBranches"),children:L.map(m=>t.jsx(as,{value:m,onSelect:()=>{b(m),r(m),M(!1),z("")},children:m},m))})]})]})})]}),j.kind==="ready"?t.jsx(U,{size:"sm",onClick:()=>{Y()},disabled:!q||j.plan.commits.length===0,children:h("gitView.integrate.move")}):j.kind==="loading"?t.jsx(U,{size:"sm",variant:"outline",disabled:!0,children:h("gitView.integrate.checking")}):j.kind==="running"?t.jsx(U,{size:"sm",variant:"outline",disabled:!0,children:h("gitView.integrate.moving")}):null]}),j.kind==="ready"&&j.plan.commits.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:h("gitView.integrate.noCommitsToMove")}),j.kind==="ready"&&j.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:[h("gitView.integrate.commitsToMove"),t.jsxs("span",{className:"text-muted-foreground",children:[" (",j.plan.commits.length,")"]})]}),G.length>0&&j.plan.commits.length>5&&t.jsx("button",{type:"button",onClick:()=>P(m=>!m),className:"typography-micro text-muted-foreground hover:text-foreground",children:h(V?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(V?G:G.slice(0,5)).map(m=>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:m.short}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:m.subject||m.sha})]},m.sha)),G.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:h("gitView.integrate.previewUnavailable")}),j.plan.commits.length>G.length&&t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:h("gitView.integrate.showingFirstCommits",{count:G.length})})]})]}),j.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:h("gitView.integrate.conflictsInFiles",{count:j.details.unmergedFiles.length})}),t.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[h("gitView.integrate.currentCommit"),": ",t.jsx("span",{className:"font-mono",children:j.state.currentCommit.slice(0,7)})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[j.details.unmergedFiles.slice(0,6).map(m=>t.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:m},m)),j.details.unmergedFiles.length>6&&t.jsx("span",{className:"text-xs text-muted-foreground",children:h("gitView.integrate.moreFiles",{count:j.details.unmergedFiles.length-6})})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(U,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{te()},children:h("gitView.operation.abort")}),t.jsxs(U,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!x,onClick:()=>{_({state:j.state,details:j.details},!1)},children:[t.jsx(E,{name:"sparkling",className:"size-3.5"}),h("gitView.integrate.currentSession")]}),t.jsxs(U,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{_({state:j.state,details:j.details},!0)},children:[t.jsx(E,{name:"sparkling",className:"size-3.5"}),h("gitView.integrate.newSession")]}),t.jsx(U,{size:"sm",className:"typography-meta",onClick:()=>{he()},children:h("gitView.operation.continue")})]})]})]})]})},no=({open:o,onOpenChange:e,directory:a,hasUncommittedChanges:f,hasStagedChanges:w=!1,uncommittedFileCount:d,onChanged:p})=>{const{t:v}=ot(),[h,x]=i.useState([]),[B,M]=i.useState(!1),[k,z]=i.useState(""),[S,L]=i.useState(""),[R,b]=i.useState(null),[q,j]=i.useState({}),F=i.useCallback(async()=>{if(a){M(!0);try{const r=await ja(a);x(r.stashes),j({})}catch(r){g.error(r instanceof Error?r.message:v("gitView.stashes.toast.loadFailed"))}finally{M(!1)}}},[a,v]);i.useEffect(()=>{o&&F()},[F,o]),i.useEffect(()=>{if(!o||!a||h.length===0)return;let r=!1;const O=h.map(J=>J.ref);return Ca(a,O).then(J=>{r||j(J.counts)}).catch(()=>{}),()=>{r=!0}},[a,o,h]);const V=i.useMemo(()=>Lt(h,k,r=>[r.message,r.ref,r.relativeTime]),[k,h]),P=i.useCallback(async r=>{await F(),await p?.(r)},[F,p]),G=async()=>{if(!(!a||R)){b("create");try{const r=await Sa(a,{message:S.trim()||void 0});r.created?(g.success(v("gitView.stashes.toast.created")),L("")):g.info(v("gitView.stashes.toast.noChanges")),await P({affectsIndex:!!(r.created&&w)})}catch(r){g.error(r instanceof Error?r.message:v("gitView.stashes.toast.createFailed"))}finally{b(null)}}},ee=async(r,O)=>{if(!(!a||R)&&!(O==="drop"&&!window.confirm(v("gitView.stashes.confirm.drop",{ref:r.ref})))){b(`${O}:${r.ref}`);try{O==="apply"&&await Na(a,{ref:r.ref}),O==="pop"&&await ka(a,{ref:r.ref}),O==="drop"&&await Va(a,{ref:r.ref});const J=O==="apply"?"gitView.stashes.toast.applySuccess":O==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";g.success(v(J)),await P({affectsIndex:O!=="drop"})}catch(J){const y=O==="apply"?"gitView.stashes.toast.applyFailed":O==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";g.error(J instanceof Error?J.message:v(y)),await P({affectsIndex:O!=="drop"})}finally{b(null)}}},A=R!==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(ft,{children:[t.jsxs(gt,{className:"flex items-center gap-2",children:[t.jsx(E,{name:"archive-stack",className:"h-5 w-5"}),v("gitView.stashes.title")]}),t.jsx(vt,{children:v("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(Br,{value:S,onChange:r=>L(r.target.value),placeholder:v("gitView.stashes.messagePlaceholder"),disabled:A||!f,className:"flex-1"}),t.jsxs(U,{onClick:G,disabled:!f||A||!a,children:[R==="create"?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"inbox-archive",className:"size-4"}),v("gitView.stashes.actions.stashCurrentWithCount",{count:d})]})]}),t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:v("gitView.stashes.includeUntrackedHint")})]}),t.jsxs("div",{className:"relative mt-2",children:[t.jsx(E,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(Br,{value:k,onChange:r=>z(r.target.value),placeholder:v("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:B?t.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:t.jsx(E,{name:"loader-4",className:"size-5 animate-spin"})}):V.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:v(k?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):V.map((r,O)=>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:r.message||v("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[t.jsxs(is,{children:[t.jsx(os,{asChild:!0,children:t.jsx("span",{children:O===0&&!k.trim()?v("gitView.stashes.latestLabel"):v("gitView.stashes.itemNumber",{number:O+1})})}),t.jsx(ls,{sideOffset:6,children:r.ref})]})," · ",r.relativeTime," · ",typeof q[r.ref]=="number"?v("gitView.stashes.fileCount",{count:q[r.ref]}):v("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(Hs,{label:v("gitView.stashes.actions.apply"),loading:R===`apply:${r.ref}`,onClick:()=>ee(r,"apply"),disabled:A,children:t.jsx(E,{name:"inbox-unarchive",className:"size-4"})}),t.jsx(Hs,{label:v("gitView.stashes.actions.pop"),loading:R===`pop:${r.ref}`,onClick:()=>ee(r,"pop"),disabled:A,children:t.jsx(E,{name:"inbox-unarchive-fill",className:"size-4"})}),t.jsx(Hs,{label:v("gitView.stashes.actions.drop"),loading:R===`drop:${r.ref}`,onClick:()=>ee(r,"drop"),disabled:A,destructive:!0,children:t.jsx(E,{name:"delete-bin",className:"size-4"})})]})]},r.ref))})]})})},Hs=o=>{const e=Gt.c(17),{label:a,loading:f,disabled:w,destructive:d,onClick:p,children:v}=o,h=f||void 0,x=d?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let B;e[0]!==x?(B=me("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",x),e[0]=x,e[1]=B):B=e[1];let M;e[2]!==v||e[3]!==f?(M=f?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):v,e[2]=v,e[3]=f,e[4]=M):M=e[4];let k;e[5]!==w||e[6]!==a||e[7]!==p||e[8]!==h||e[9]!==B||e[10]!==M?(k=t.jsx(os,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":a,"aria-busy":h,className:B,onClick:p,disabled:w,children:M})}),e[5]=w,e[6]=a,e[7]=p,e[8]=h,e[9]=B,e[10]=M,e[11]=k):k=e[11];let z;e[12]!==a?(z=t.jsx(ls,{sideOffset:6,children:a}),e[12]=a,e[13]=z):z=e[13];let S;return e[14]!==k||e[15]!==z?(S=t.jsxs(is,{children:[k,z]}),e[14]=k,e[15]=z,e[16]=S):S=e[16],S},ao=o=>{const e=Gt.c(16),{onOpenStashes:a}=o,{t:f}=ot();let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=t.jsx(E,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=w):w=e[0];let d;e[1]!==f?(d=f("gitView.empty.cleanTitle"),e[1]=f,e[2]=d):d=e[2];let p;e[3]!==d?(p=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:d}),e[3]=d,e[4]=p):p=e[4];let v;e[5]!==f?(v=f("gitView.empty.cleanDescription"),e[5]=f,e[6]=v):v=e[6];let h;e[7]!==v?(h=t.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:v}),e[7]=v,e[8]=h):h=e[8];let x;e[9]!==a||e[10]!==f?(x=a?t.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:a,className:"gap-1.5",children:[t.jsx(E,{name:"archive-stack",className:"size-4"}),f("gitView.stashes.title")]}):null,e[9]=a,e[10]=f,e[11]=x):x=e[11];let B;return e[12]!==p||e[13]!==h||e[14]!==x?(B=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[w,p,h,x]}),e[12]=p,e[13]=h,e[14]=x,e[15]=B):B=e[15],B},at=8,io=o=>{const e=Gt.c(18),{laned:a,totalLanes:f,isExpanded:w}=o,{lane:d,color:p,connectors:v}=a,x=Math.max(f,d+1)*at+at/2,B=i.useRef(null),M=i.useRef(null);let k;e[0]!==p||e[1]!==v||e[2]!==d||e[3]!==x?(k=()=>{const b=B.current,q=M.current;if(!b||!q)return;const j=b.offsetHeight;if(j===0)return;const F=window.devicePixelRatio||1;q.width=x*F,q.height=j*F;const V=q.getContext("2d");if(!V)return;V.scale(F,F),V.clearRect(0,0,x,j);const P=j/2,G=d*at+at/2,ee=getComputedStyle(q),A=ee.getPropertyValue("--surface-muted-foreground").trim()||ee.color,r=y=>{if(!y.startsWith("var("))return y;const H=y.slice(4,-1).trim();return ee.getPropertyValue(H).trim()||A},O=[...v].sort(lo);for(const y of O){const H=y.fromLane*at+at/2,_=y.toLane*at+at/2,Y=y.type==="passing"?.72:y.type==="branch-out"||y.type==="merge-in"?.95:1;V.beginPath(),V.strokeStyle=r(y.color),V.globalAlpha=Y,V.lineWidth=1.25,V.lineCap="round";e:switch(y.type){case"passing":case"commit-lane":{V.moveTo(H,0),V.lineTo(H,j);break e}case"top-stub":{V.moveTo(H,0),V.lineTo(H,P);break e}case"bottom-stub":{V.moveTo(H,P),V.lineTo(H,j);break e}case"branch-out":{const te=(P+j)/2;V.moveTo(G,P),V.bezierCurveTo(G,te,_,te,_,j);break e}case"merge-in":{const te=P/2;V.moveTo(H,0),V.bezierCurveTo(H,te,G,te,G,P);break e}default:continue}V.stroke(),V.globalAlpha=1}const J=ee.getPropertyValue("--background").trim()||ee.getPropertyValue("--surface-background").trim();V.beginPath(),V.arc(G,P,4,0,Math.PI*2),V.fillStyle=r(p),V.fill(),V.beginPath(),V.arc(G,P,5,0,Math.PI*2),V.strokeStyle=J||A,V.lineWidth=2,V.stroke()},e[0]=p,e[1]=v,e[2]=d,e[3]=x,e[4]=k):k=e[4];let z;e[5]!==p||e[6]!==v||e[7]!==w||e[8]!==d||e[9]!==a||e[10]!==f||e[11]!==x?(z=[a,d,p,v,f,w,x],e[5]=p,e[6]=v,e[7]=w,e[8]=d,e[9]=a,e[10]=f,e[11]=x,e[12]=z):z=e[12],i.useLayoutEffect(k,z);let S;e[13]!==x?(S={width:x,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=x,e[14]=S):S=e[14];let L;e[15]===Symbol.for("react.memo_cache_sentinel")?(L=t.jsx("canvas",{ref:M,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=L):L=e[15];let R;return e[16]!==S?(R=t.jsx("div",{ref:B,style:S,children:L}),e[16]=S,e[17]=R):R=e[17],R};function oo(o){return o==="branch-out"||o==="merge-in"}function lo(o,e){const a=oo;return(a(o.type)?1:0)-(a(e.type)?1:0)}const _r=15e3,$r=500,Wr=12,Kr=8*1024*1024,Ur=o=>typeof o=="string"?0:(o.original?.length??0)+(o.modified?.length??0),qr=o=>{if(o.size<=Wr){let w=0;for(const d of o.values())w+=Ur(d);if(w<=Kr)return o}const e=Array.from(o.entries()).reverse(),a=new Map;let f=0;for(const[w,d]of e){if(a.size>=Wr)continue;const p=Ur(d);f+p>Kr&&a.size>0||(a.set(w,d),f+=p)}return new Map(Array.from(a.entries()).reverse())};function Jr(o,e){const a=new Date(o);return Number.isNaN(a.getTime())?o:Fa(a,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function co(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 uo(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 mo=i.memo(({entry:o,mode:e="history",laned:a,totalLanes:f,isExpanded:w,onToggle:d,files:p,isLoadingFiles:v,onCopyHash:h,directory:x,onConflict:B,onActionSuccess:M})=>{const{t:k}=ot(),z=Et(c=>c.timeFormatPreference),S=e==="graph",[L,R]=i.useState(null),[b,q]=i.useState(!1),[j,F]=i.useState(""),[V,P]=i.useState(null),[G,ee]=i.useState(new Set),[A,r]=i.useState(new Map),[O,J]=i.useState(new Set),y=async()=>{if(x){R("checkout");try{await Ta(x,o.hash),g.success(k("gitView.history.actions.detachedHead")),M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},H=async()=>{if(!(!x||!j.trim())){R("createBranch");try{await Da(x,j.trim(),o.hash),q(!1),F(""),M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},_=async()=>{if(x){R("cherryPick");try{const c=await Ea(x,o.hash);c.conflict?B?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"cherry-pick"}):M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},Y=async()=>{if(x){R("revert");try{const c=await Oa(x,o.hash);c.conflict?B?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"revert"}):M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},te=async(c,I=!1)=>{if(!(!x||L!==null)){R("reset");try{await Ba(x,o.hash,c,I),M?.()}catch(T){g.error(String(T.message))}finally{R(null)}}},he=async()=>{if(!V)return;const c=V;switch(P(null),c){case"checkout":return y();case"cherryPick":return _();case"revert":return Y();case"merge":return se();case"rebase":return oe();case"resetSoft":return te("soft");case"resetMixed":return te("mixed");case"resetHard":return te("hard",!0)}},se=async()=>{if(x){R("merge");try{const c=await Aa(x,{branch:o.hash});c.conflict?B?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"merge"}):M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},oe=async()=>{if(x){R("rebase");try{const c=await Ma(x,{onto:o.hash});c.conflict?B?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"rebase"}):M?.()}catch(c){g.error(String(c.message))}finally{R(null)}}},le=i.useCallback(async c=>{const I=c.path;if(!x){r(T=>new Map(T).set(I,"error"));return}r(T=>qr(new Map(T).set(I,"loading")));try{const T=Ra(x,o.hash,c.path,!1),ne=new Promise((Z,$)=>{setTimeout(()=>$(new Error(`Timed out after ${_r}ms`)),_r)}),Q=await Promise.race([T,ne]);r(Z=>qr(new Map(Z).set(I,Q)))}catch{r(T=>new Map(T).set(I,"error"))}},[x,o.hash]),m=i.useCallback(async c=>{const I=c.path;if(c.changeType==="R"||c.isBinary){ee(Z=>{const $=new Set(Z);return $.has(I)?$.delete(I):$.add(I),$});return}const T=A.get(I);if(G.has(I)&&T&&T!=="error"){ee(Z=>{const $=new Set(Z);return $.delete(I),$});return}ee(Z=>{const $=new Set(Z);return $.add(I),$}),!(T&&T!=="error"||c.insertions+c.deletions>$r&&!O.has(I))&&await le(c)},[A,O,le,G]);return t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:d,className:me("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",S?"hover:bg-[var(--interactive-hover)]/40":w?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[S&&a&&f!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(io,{laned:a,totalLanes:f,isExpanded:w})}):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 c=uo(o.refs);return c.length>0?t.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:c.map(I=>t.jsx("span",{className:me("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:Jr(o.date,z),children:Jr(o.date,z)})]}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("code",{className:"shrink-0 font-mono",children:o.hash.slice(0,8)}),t.jsxs(is,{children:[t.jsx(os,{asChild:!0,children:t.jsx(U,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:c=>{c.stopPropagation(),h(o.hash)},children:t.jsx(E,{name:"file-copy",className:"size-3"})})}),t.jsx(ls,{sideOffset:8,children:k("gitView.history.copySha")})]})]})]})]}),w&&t.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[S&&V?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:k(`gitView.history.actions.${V}Confirm`)}),t.jsxs(U,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:L!==null,onClick:c=>{c.stopPropagation(),he()},children:[L!==null?t.jsx(E,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,k("gitView.history.actions.confirmButton")]}),t.jsx(U,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:L!==null,onClick:c=>{c.stopPropagation(),P(null)},children:k("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(U,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>{c.stopPropagation(),P("checkout")},children:k("gitView.history.actions.checkout")}),b?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{autoFocus:!0,value:j,onChange:c=>F(c.target.value),onKeyDown:c=>{c.key==="Enter"&&H(),c.key==="Escape"&&(q(!1),F(""))},placeholder:k("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(U,{variant:"outline",size:"xs",className:"h-6",disabled:!j.trim()||L!==null,onClick:c=>{c.stopPropagation(),H()},children:[L==="createBranch"?t.jsx(E,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,k("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(U,{variant:"outline",size:"xs",className:"h-6",onClick:c=>{c.stopPropagation(),q(!0)},children:k("gitView.history.actions.createBranch")}),t.jsx(U,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>{c.stopPropagation(),P("cherryPick")},children:k("gitView.history.actions.cherryPick")}),t.jsx(U,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>{c.stopPropagation(),P("revert")},children:k("gitView.history.actions.revert")}),t.jsxs($s,{children:[t.jsx(Ws,{asChild:!0,children:t.jsxs(U,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>c.stopPropagation(),children:[L==="reset"?t.jsx(E,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,k("gitView.history.actions.reset")]})}),t.jsx(Ks,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(c=>t.jsx(Ia,{disabled:L!==null,onSelect:I=>{I.stopPropagation(),P(`reset${c.charAt(0).toUpperCase()+c.slice(1)}`)},children:k(`gitView.history.actions.reset${c.charAt(0).toUpperCase()+c.slice(1)}`)},c))})]}),t.jsx(U,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>{c.stopPropagation(),P("merge")},children:k("gitView.history.actions.merge")}),t.jsx(U,{variant:"outline",size:"xs",className:"h-6",disabled:L!==null,onClick:c=>{c.stopPropagation(),P("rebase")},children:k("gitView.history.actions.rebase")})]}):null,v?t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(E,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:k("gitView.history.loadingFiles")})]}):p.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:k("gitView.history.noFiles")}):t.jsx("ul",{className:"space-y-0.5 py-2",children:p.map(c=>t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:()=>m(c),className:me("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",G.has(c.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[t.jsx("span",{className:me("font-semibold w-3 text-center shrink-0",co(c.changeType)),children:c.changeType}),t.jsx("span",{className:"truncate text-foreground min-w-0",title:c.path,children:c.path}),!c.isBinary&&t.jsxs("span",{className:"shrink-0",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",c.insertions]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",c.deletions]})]}),c.isBinary&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:k("gitView.history.binary")}),t.jsx(E,{name:G.has(c.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),G.has(c.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:c.changeType==="R"?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.renamedNoDiff")}):c.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.binaryNoDiff")}):(()=>{const I=c.insertions+c.deletions;if(!O.has(c.path)&&I>$r)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:k("gitView.history.largeDiffTitle",{count:I})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:k("gitView.history.largeDiffDescription")}),t.jsx(U,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{J(ne=>new Set(ne).add(c.path)),le(c)},children:k("gitView.history.renderDiffAnyway")})]});const T=A.get(c.path);return T==="loading"||T===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.loadingDiff")}):T==="error"?t.jsx("button",{type:"button",onClick:()=>m(c),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:k("gitView.history.diffError")}):t.jsx(Ui,{original:T.original,modified:T.modified,language:Pa(c.path)||"",fileName:c.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},c.path))})]})]})}),Yr=["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 rs(o){return Yr[o%Yr.length]}function ho(o){if(o.length===0)return[];const e=[],a=[];for(let f=0;f<o.length;f++){const w=o[f],d=[];for(let S=0;S<e.length;S++)e[S]===w.hash&&d.push(S);let p=d.length>0?d[0]:-1;if(p===-1){const S=e.indexOf(null);S!==-1?p=S:(p=e.length,e.push(null))}const v=d.slice(1),h=rs(p),x=e[p]===w.hash,B=w.parents.length>0;B?e[p]=w.parents[0]:e[p]=null;const M=[],k=new Set;for(let S=1;S<w.parents.length;S++){const L=w.parents[S],R=e.indexOf(L);if(R!==-1)M.push(R);else{const b=e.indexOf(null);if(b!==-1)e[b]=L,M.push(b),k.add(b);else{const q=e.length;e.push(L),M.push(q),k.add(q)}}}const z=[];x&&B?z.push({fromLane:p,toLane:p,color:h,type:"commit-lane"}):x&&!B?z.push({fromLane:p,toLane:p,color:h,type:"top-stub"}):!x&&B&&z.push({fromLane:p,toLane:p,color:h,type:"bottom-stub"});for(const S of v)z.push({fromLane:S,toLane:p,color:rs(S),type:"merge-in"}),e[S]=null;for(const S of M)z.push({fromLane:p,toLane:S,color:rs(S),type:"branch-out"});for(let S=0;S<e.length;S++)e[S]!==null&&S!==p&&(k.has(S)||z.push({fromLane:S,toLane:S,color:rs(S),type:"passing"}));a.push({commit:w,lane:p,color:h,connectors:z})}return a}const fo=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],go=o=>{const e=Gt.c(84),{mode:a,log:f,isLogLoading:w,logMaxCount:d,onLogMaxCountChange:p,expandedCommitHashes:v,onToggleCommit:h,commitFilesMap:x,loadingCommitHashes:B,onCopyHash:M,directory:k,showHeader:z,contentMaxHeightClassName:S,branchDivider:L,onConflict:R,onActionSuccess:b}=o,q=a===void 0?"history":a,j=z===void 0?!0:z,F=S===void 0?"max-h-[50vh]":S,V=L===void 0?null:L,{t:P}=ot(),[G,ee]=i.useState(!0),A=q==="graph";let r;e[0]!==A||e[1]!==f?(r=A&&f?ho(f.all):[],e[0]=A,e[1]=f,e[2]=r):r=e[2];const O=r;let J;e[3]!==O?(J=Math.max(1,...O.map(po)),e[3]=O,e[4]=J):J=e[4];const y=J;let H;e[5]!==O?(H=new Map(O.map(xo)),e[5]=O,e[6]=H):H=e[6];const _=H;if(!f)return null;const Y=V!==null&&V.insertBeforeIndex>0&&V.insertBeforeIndex<f.all.length,te=V!==null&&V.insertBeforeIndex===f.all.length,he=Y||te;let se;e[7]!==V||e[8]!==Y||e[9]!==te||e[10]!==f.all?(se=Y?f.all.slice(0,V.insertBeforeIndex):te?f.all:[],e[7]=V,e[8]=Y,e[9]=te,e[10]=f.all,e[11]=se):se=e[11];const oe=se;let le;if(e[12]!==V||e[13]!==x||e[14]!==F||e[15]!==k||e[16]!==v||e[17]!==Y||e[18]!==he||e[19]!==A||e[20]!==w||e[21]!==_||e[22]!==B||e[23]!==f.all||e[24]!==d||e[25]!==y||e[26]!==q||e[27]!==b||e[28]!==R||e[29]!==M||e[30]!==p||e[31]!==h||e[32]!==P||e[33]!==oe){const ce=Y?f.all.slice(V.insertBeforeIndex):[];let pe;e[35]!==V?.direction?(pe=V?.direction==="down"?t.jsx(E,{name:"arrow-down-s",className:"size-3.5"}):t.jsx(E,{name:"arrow-up",className:"size-3.5"}),e[35]=V?.direction,e[36]=pe):pe=e[36];const Me=pe;let be;e[37]!==x||e[38]!==k||e[39]!==v||e[40]!==A||e[41]!==_||e[42]!==B||e[43]!==y||e[44]!==q||e[45]!==b||e[46]!==R||e[47]!==M||e[48]!==h?(be=zt=>t.jsx("ul",{className:"divide-y divide-border/60",children:zt.map(Ne=>t.jsx(mo,{entry:Ne,mode:q,laned:A?_.get(Ne.hash):void 0,totalLanes:A?y:void 0,isExpanded:v.has(Ne.hash),onToggle:()=>h(Ne.hash),files:x.get(Ne.hash)??[],isLoadingFiles:B.has(Ne.hash),onCopyHash:M,directory:k,onConflict:R,onActionSuccess:b},Ne.hash))}),e[37]=x,e[38]=k,e[39]=v,e[40]=A,e[41]=_,e[42]=B,e[43]=y,e[44]=q,e[45]=b,e[46]=R,e[47]=M,e[48]=h,e[49]=be):be=e[49];const Se=be;let ae;e[50]!==w||e[51]!==f.all.length||e[52]!==d||e[53]!==p||e[54]!==P?(ae=f.all.length>=d?t.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:t.jsx(U,{type:"button",variant:"ghost",size:"xs",onClick:()=>p(d+25),disabled:w,className:"px-3 text-muted-foreground hover:text-foreground",children:w?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(E,{name:"loader-4",className:"size-3 animate-spin"}),P("gitView.history.loadingMore")]}):P("gitView.history.loadMore")})}):null,e[50]=w,e[51]=f.all.length,e[52]=d,e[53]=p,e[54]=P,e[55]=ae):ae=e[55];const He=ae;le=t.jsx(tn,{outerClassName:`min-h-0 ${F}`,className:"h-full w-full",children:f.all.length===0?t.jsx("div",{className:"flex h-full items-center justify-center p-4",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:P("gitView.history.noCommits")})}):he&&V?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col gap-0",children:[oe.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Se(oe)}):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:V.branchName,children:V.branchName}),Me]}),t.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),ce.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Se(ce)}):null]}),He]}):t.jsxs(t.Fragment,{children:[Se(f.all),He]})}),e[12]=V,e[13]=x,e[14]=F,e[15]=k,e[16]=v,e[17]=Y,e[18]=he,e[19]=A,e[20]=w,e[21]=_,e[22]=B,e[23]=f.all,e[24]=d,e[25]=y,e[26]=q,e[27]=b,e[28]=R,e[29]=M,e[30]=p,e[31]=h,e[32]=P,e[33]=oe,e[34]=le}else le=e[34];const m=le;if(!j){if(he){let pe;return e[56]!==m?(pe=t.jsx("section",{className:"h-full min-h-0",children:m}),e[56]=m,e[57]=pe):pe=e[57],pe}let ce;return e[58]!==m?(ce=t.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:m}),e[58]=m,e[59]=ce):ce=e[59],ce}let c;e[60]!==P?(c=P("gitView.history.title"),e[60]=P,e[61]=c):c=e[61];let I;e[62]!==c?(I=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:c}),e[62]=c,e[63]=I):I=e[63];let T;e[64]!==w||e[65]!==G||e[66]!==d||e[67]!==p||e[68]!==P?(T=G&&t.jsx("div",{onClick:yo,onPointerDown:wo,children:t.jsxs(La,{value:String(d),onValueChange:ce=>p(Number(ce)),disabled:w,children:[t.jsx(Ga,{size:"sm",className:"w-auto",disabled:w,children:t.jsx(za,{placeholder:P("gitView.history.commitsPlaceholder")})}),t.jsx(Ha,{children:fo.map(ce=>t.jsx(_a,{value:String(ce.value),children:P(ce.labelKey)},ce.value))})]})}),e[64]=w,e[65]=G,e[66]=d,e[67]=p,e[68]=P,e[69]=T):T=e[69];let ne;e[70]!==G?(ne=G?t.jsx(E,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):t.jsx(E,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=G,e[71]=ne):ne=e[71];let Q;e[72]!==T||e[73]!==ne?(Q=t.jsxs("div",{className:"flex items-center gap-2",children:[T,ne]}),e[72]=T,e[73]=ne,e[74]=Q):Q=e[74];let Z;e[75]!==I||e[76]!==Q?(Z=t.jsxs(ki,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[I,Q]}),e[75]=I,e[76]=Q,e[77]=Z):Z=e[77];let $;e[78]!==m?($=t.jsx(Vi,{children:m}),e[78]=m,e[79]=$):$=e[79];let Be;return e[80]!==G||e[81]!==Z||e[82]!==$?(Be=t.jsxs(Ri,{open:G,onOpenChange:ee,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[Z,$]}),e[80]=G,e[81]=Z,e[82]=$,e[83]=Be):Be=e[83],Be};function po(o){return o.lane+1}function xo(o){return[o.commit.hash,o]}function yo(o){return o.stopPropagation()}function wo(o){return o.stopPropagation()}const bo=({open:o,onOpenChange:e,operation:a,targetBranch:f,onConfirm:w})=>{const{t:d}=ot(),[p,v]=i.useState(!0),[h,x]=i.useState(!1),B=d(a==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),M=async()=>{x(!0);try{await w(p),e(!1)}catch(z){const S=z instanceof Error?z.message:`Failed to ${a}`;g.error(S)}finally{x(!1)}},k=()=>{h||e(!1)};return t.jsx(mt,{open:o,onOpenChange:h?void 0:e,children:t.jsxs(ht,{className:"max-w-md",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),t.jsx(gt,{children:d("gitView.stash.title")})]}),t.jsx(vt,{children:d("gitView.stash.description",{operation:a})})]}),t.jsxs("div",{className:"py-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:d("gitView.stash.thisWill")}),t.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[t.jsx("li",{children:d("gitView.stash.stepStash")}),t.jsxs("li",{children:[d(a==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",d(a==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",t.jsx("span",{className:"font-mono text-primary",children:f})]}),p&&t.jsx("li",{children:d("gitView.stash.stepRestore")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx($a,{checked:p,onChange:v,disabled:h,ariaLabel:d("gitView.stash.restoreAria")}),t.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!h&&v(!p),children:d("gitView.stash.restoreAfterOperation",{operation:a})})]}),t.jsxs(_s,{className:"gap-2",children:[t.jsx(U,{variant:"ghost",size:"sm",onClick:k,disabled:h,children:d("gitView.common.cancel")}),t.jsx(U,{variant:"default",size:"sm",onClick:M,disabled:h,className:"gap-1.5",children:h?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),d("gitView.common.processing")]}):d("gitView.stash.confirmButton",{operation:B})})]})]})})},vo=o=>{const e=Gt.c(100),{currentBranch:a,localBranches:f,remoteBranches:w,onMerge:d,onRebase:p,disabled:v,isOperating:h,operationLogs:x,onOperationComplete:B,mode:M,defaultTargetBranch:k}=o,z=v===void 0?!1:v,S=h===void 0?!1:h,L=x===void 0?[]:x,R=M===void 0?"dialog":M,{t:b}=ot(),[q,j]=i.useState(!1),[F,V]=i.useState("merge"),[P,G]=i.useState(null),[ee,A]=i.useState(!1),[r,O]=i.useState(""),J=i.useRef(null),y=i.useRef(null),H=z||S,_=a||b("gitView.branch.currentBranchFallback"),Y=L.length>0&&L.every(jo),te=L.some(Co);let he;e[0]===Symbol.for("react.memo_cache_sentinel")?(he=()=>{y.current&&(y.current.scrollTop=y.current.scrollHeight)},e[0]=he):he=e[0],i.useEffect(he,[L]);let se;if(e[1]!==r||e[2]!==a||e[3]!==f){let X;e[5]!==a?(X=Re=>Re!==a,e[5]=a,e[6]=X):X=e[6];const fe=f.filter(X);se=Lt(fe,r,So),e[1]=r,e[2]=a,e[3]=f,e[4]=se}else se=e[4];const oe=se;let le;e[7]!==r||e[8]!==w?(le=Lt(w,r,No),e[7]=r,e[8]=w,e[9]=le):le=e[9];const m=le;let c;e[10]!==k||e[11]!==f||e[12]!==w?(c=()=>{if(!k)return null;const X=w.find(fe=>fe.label===k);return X||(f.includes(k)?{kind:"local",branch:k,label:k}:null)},e[10]=k,e[11]=f,e[12]=w,e[13]=c):c=e[13];const I=c;let T;e[14]!==I||e[15]!==j?(T=()=>{j(!0),G(I()),V("merge"),O("")},e[14]=I,e[15]=j,e[16]=T):T=e[16];const ne=T;let Q;e[17]===Symbol.for("react.memo_cache_sentinel")?(Q=X=>{G(X),A(!1),O("")},e[17]=Q):Q=e[17];const Z=Q;let $;e[18]!==d||e[19]!==p||e[20]!==F||e[21]!==P?($=()=>{P&&(F==="merge"?d(P):p(P))},e[18]=d,e[19]=p,e[20]=F,e[21]=P,e[22]=$):$=e[22];const Be=$;let ce;e[23]!==S||e[24]!==j?(ce=()=>{S||(G(null),V("merge"),O(""),j(!1))},e[23]=S,e[24]=j,e[25]=ce):ce=e[25];const pe=ce,Me=()=>{S&&!Y||(Y&&B?.(),G(null),V("merge"),O(""),j(!1))};let be,Se;e[26]!==ee?(be=()=>{ee||O("")},Se=[ee],e[26]=ee,e[27]=be,e[28]=Se):(be=e[27],Se=e[28]),i.useEffect(be,Se);let ae,He;e[29]!==R||e[30]!==I||e[31]!==P?(ae=()=>{R==="dialog"||P||G(I())},He=[R,I,P],e[29]=R,e[30]=I,e[31]=P,e[32]=ae,e[33]=He):(ae=e[32],He=e[33]),i.useEffect(ae,He);const Ae=S?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{ref:y,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:L.map(ko)})}),Y?R==="dialog"?t.jsx(_s,{children:t.jsx(U,{variant:"default",size:"sm",onClick:Me,children:b(te?"gitView.common.close":"gitView.common.done")})}):t.jsx("div",{className:"flex justify-end",children:t.jsx(U,{variant:"default",size:"sm",onClick:Me,children:b(te?"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:b("gitView.branch.operation")}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>V("merge"),className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",F==="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(E,{name:"git-merge",className:me("size-4",F==="merge"?"text-inherit":"text-muted-foreground")}),t.jsx("span",{className:me("typography-ui-label",F==="merge"?"text-foreground":"text-muted-foreground"),children:b("gitView.operation.merge")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:b("gitView.branch.mergeDescription")})]}),t.jsxs("button",{type:"button",onClick:()=>V("rebase"),className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",F==="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(E,{name:"git-branch",className:me("size-4",F==="rebase"?"text-inherit":"text-muted-foreground")}),t.jsx("span",{className:me("typography-ui-label",F==="rebase"?"text-foreground":"text-muted-foreground"),children:b("gitView.operation.rebase")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:b("gitView.branch.rebaseDescription")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:F==="merge"?b("gitView.branch.branchToMergeInto",{branch:_}):b("gitView.branch.branchToRebaseOnto")}),t.jsxs($s,{open:ee,onOpenChange:A,modal:!1,children:[t.jsx(Ws,{asChild:!0,children:t.jsxs("button",{type:"button",className:me(en({size:"default"}),"w-full"),children:[t.jsx("span",{className:me("truncate",!P&&"text-muted-foreground"),children:P?.label||b("gitView.branch.selectBranch")}),t.jsx(E,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),t.jsx(Ks,{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(Us,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(qs,{ref:J,placeholder:b("gitView.branch.searchPlaceholder"),value:r,onValueChange:O,onKeyDown:Vo}),t.jsxs(Js,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(Ys,{children:b("gitView.branch.empty")}),oe.length>0&&t.jsx(ns,{heading:b("gitView.branch.localBranches"),children:oe.map(X=>t.jsx(as,{onSelect:()=>Z({kind:"local",branch:X,label:X}),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:X})},`local-${X}`))}),oe.length>0&&m.length>0?t.jsx(Wa,{}):null,m.length>0&&t.jsx(ns,{heading:b("gitView.branch.remoteBranches"),children:m.map(X=>t.jsx(as,{onSelect:()=>Z(X),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:X.label})},`remote-${X.label}`))})]})]})})]})]}),P?t.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:F==="merge"?t.jsxs(t.Fragment,{children:[b("gitView.branch.summaryMergePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P.label})," ",b("gitView.branch.summaryMergeInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:_})]}):t.jsxs(t.Fragment,{children:[b("gitView.branch.summaryRebasePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:_})," ",b("gitView.branch.summaryRebaseInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P.label})]})})}):null,R==="dialog"?t.jsxs(_s,{className:"gap-2 pt-1",children:[t.jsx(U,{variant:"ghost",size:"sm",onClick:pe,children:b("gitView.common.cancel")}),t.jsx(U,{variant:"default",size:"sm",onClick:Be,disabled:!P,className:"gap-1.5",children:F==="merge"?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"git-merge",className:"size-4"}),b("gitView.operation.merge")]}):t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"git-branch",className:"size-4"}),b("gitView.operation.rebase")]})})]}):t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(U,{variant:"destructive",size:"sm",onClick:pe,disabled:H,children:b("gitView.common.reset")}),t.jsx("div",{className:"flex-1"}),t.jsx(U,{variant:"default",size:"sm",onClick:Be,disabled:H||!P,children:b(F==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(R==="bare")return Ae;if(R==="inline"){let X;e[34]!==b?(X=b("gitView.branch.updateTitle"),e[34]=b,e[35]=X):X=e[35];let fe;e[36]!==X?(fe=t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:X}),e[36]=X,e[37]=fe):fe=e[37];let Re;e[38]!==b?(Re=b("gitView.branch.updateDescriptionPrefix"),e[38]=b,e[39]=Re):Re=e[39];let ve;e[40]!==_?(ve=t.jsx("span",{className:"font-mono text-foreground",children:_}),e[40]=_,e[41]=ve):ve=e[41];let xe;e[42]!==Re||e[43]!==ve?(xe=t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Re," ",ve,"."]}),e[42]=Re,e[43]=ve,e[44]=xe):xe=e[44];let Le;e[45]!==fe||e[46]!==xe?(Le=t.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:t.jsxs("div",{className:"space-y-1",children:[fe,xe]})}),e[45]=fe,e[46]=xe,e[47]=Le):Le=e[47];let je;e[48]!==Ae?(je=t.jsx("div",{className:"pt-3",children:Ae}),e[48]=Ae,e[49]=je):je=e[49];let qe;return e[50]!==Le||e[51]!==je?(qe=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Le,je]}),e[50]=Le,e[51]=je,e[52]=qe):qe=e[52],qe}let Ye;e[53]!==S?(Ye=S?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"git-merge",className:"size-4"}),e[53]=S,e[54]=Ye):Ye=e[54];let ke;e[55]!==b?(ke=b("gitView.branch.mergeRebase"),e[55]=b,e[56]=ke):ke=e[56];let Oe;e[57]!==ke?(Oe=t.jsx("span",{children:ke}),e[57]=ke,e[58]=Oe):Oe=e[58];let W;e[59]!==ne||e[60]!==H||e[61]!==Ye||e[62]!==Oe?(W=t.jsx(os,{asChild:!0,children:t.jsxs(U,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ne,disabled:H,children:[Ye,Oe]})}),e[59]=ne,e[60]=H,e[61]=Ye,e[62]=Oe,e[63]=W):W=e[63];let Qe;e[64]!==b?(Qe=b("gitView.branch.mergeRebaseTooltip"),e[64]=b,e[65]=Qe):Qe=e[65];let _e;e[66]!==Qe?(_e=t.jsx(ls,{sideOffset:8,children:Qe}),e[66]=Qe,e[67]=_e):_e=e[67];let Xe;e[68]!==W||e[69]!==_e?(Xe=t.jsxs(is,{children:[W,_e]}),e[68]=W,e[69]=_e,e[70]=Xe):Xe=e[70];let Ee;e[71]!==Me||e[72]!==j?(Ee=X=>{X?j(!0):Me()},e[71]=Me,e[72]=j,e[73]=Ee):Ee=e[73];let Ze;e[74]!==b?(Ze=b("gitView.branch.updateTitle"),e[74]=b,e[75]=Ze):Ze=e[75];let Te;e[76]!==Ze?(Te=t.jsx(gt,{children:Ze}),e[76]=Ze,e[77]=Te):Te=e[77];let et;e[78]!==te||e[79]!==S||e[80]!==F||e[81]!==Y||e[82]!==b||e[83]!==_?(et=S?b(Y?te?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":F==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):t.jsxs(t.Fragment,{children:[b("gitView.branch.dialogDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:_}),"."]}),e[78]=te,e[79]=S,e[80]=F,e[81]=Y,e[82]=b,e[83]=_,e[84]=et):et=e[84];let $e;e[85]!==et?($e=t.jsx(vt,{children:et}),e[85]=et,e[86]=$e):$e=e[86];let We;e[87]!==Te||e[88]!==$e?(We=t.jsxs(ft,{children:[Te,$e]}),e[87]=Te,e[88]=$e,e[89]=We):We=e[89];let Ke;e[90]!==Ae||e[91]!==We?(Ke=t.jsxs(ht,{className:"max-w-md",children:[We,Ae]}),e[90]=Ae,e[91]=We,e[92]=Ke):Ke=e[92];let Ve;e[93]!==q||e[94]!==Ee||e[95]!==Ke?(Ve=t.jsx(mt,{open:q,onOpenChange:Ee,children:Ke}),e[93]=q,e[94]=Ee,e[95]=Ke,e[96]=Ve):Ve=e[96];let Ue;return e[97]!==Xe||e[98]!==Ve?(Ue=t.jsxs(t.Fragment,{children:[Xe,Ve]}),e[97]=Xe,e[98]=Ve,e[99]=Ue):Ue=e[99],Ue};function jo(o){return o.status==="done"||o.status==="error"}function Co(o){return o.status==="error"}function So(o){return[o]}function No(o){return[o.label,o.branch,o.remote]}function ko(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(E,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),o.status==="done"&&t.jsx(E,{name:"check",className:"size-3.5 text-success"}),o.status==="error"&&t.jsx(E,{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:me("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 Vo(o){return o.stopPropagation()}const Ro=/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/i,Io=(o,e)=>{const a=[...o].sort((f,w)=>w.length-f.length);return e.flatMap(f=>{const w=a.find(p=>f.startsWith(`${p}/`));if(!w)return[];const d=f.slice(w.length+1);return d?[{kind:"remote",branch:d,destinationRef:`refs/remotes/${w}/${d}`,label:f,remote:w,sourceRef:`refs/heads/${d}`}]:[]})},Po=async({directory:o,git:e,runPlannedFetch:a,target:f})=>{if(f.kind==="local")return f.branch;await a(f);const d=(await e.getGitLog(o,{to:f.destinationRef,maxCount:1})).latest?.hash.trim();if(!d||!Ro.test(d))throw new we("invalid-terminal-state");return d},Fo=({runMutation:o,onMutationComplete:e,onMutationError:a,onPathsComplete:f,scheduleFlush:w})=>{const d=[];let p=!1;return{enqueue:h=>{const x=d[d.length-1];if(x?.directory===h.directory&&x.direction===h.direction){h.paths.forEach(B=>x.paths.add(B));return}d.push(h)},flush:()=>{if(p)return;const h=d.shift();if(!h)return;p=!0;const x={directory:h.directory,direction:h.direction,paths:Array.from(h.paths),rollback:h.rollback};(async()=>{try{await o(x),e(x)}catch(B){a(x,B)}finally{f(x.paths),p=!1,d.length>0&&w()}})()},clear:()=>{d.length=0},size:()=>d.length,isRunning:()=>p}},Do=15e3,Bo=40,Mo=20,Ao=2,Qr={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:"},Xr=(o,e)=>{const a=o.toLowerCase(),f=/^([a-z]+)(?:\(.*\))?!?:/,w=a.match(f);if(w){const v=w[1],h=Qr[v];if(h)return e.find(x=>x.code===h)||null}const d=a.split(" ")[0],p=Qr[d];return p&&e.find(v=>v.code===p)||null},Oo=20,dt=new Map,Eo=(o,e)=>{if(dt.delete(o),dt.set(o,e),dt.size>Oo){const a=dt.keys().next().value;a!==void 0&&dt.delete(a)}},Zr=o=>{const e=o.index?.trim();return!!(e&&e!=="?")},To=o=>{const e=o.working_dir?.trim(),a=o.index?.trim();return!!(e||a==="?")},Lo=(o,e,a,f)=>{if(e){const w=a.filter(d=>e.startsWith(`${d}/`)&&e.length>d.length+1).sort((d,p)=>p.length-d.length)[0];if(w)return{remoteName:w,destinationRef:`refs/heads/${e.slice(w.length+1)}`}}return f?{remoteName:f,destinationRef:`refs/heads/${o}`}:null},au=({isActive:o})=>{const{t:e}=ot(),{git:a,sourceControl:f,runtime:w}=Ka(),d=Ua(),p=Ii(),[v,h]=i.useState(null),[x,B]=i.useState(null),M=it(s=>s.currentSessionId),k=it(s=>s.newSessionDraft),z=it(s=>s.setDraftBootstrapPendingDirectory),S=it(s=>s.worktreeMetadata),L=it(s=>s.availableWorktrees),R=De(d),b=i.useMemo(()=>{if(!R)return;const s=L.find(n=>De(n.path)===R);if(s)return s;for(const n of S.values())if(De(n.path)===R)return n},[L,R,S]),q=i.useMemo(()=>{if(M)return S.get(M)??b;if(k?.open)return b},[M,b,k?.open,S]),{profiles:j,globalIdentity:F,defaultGitIdentityId:V,loadProfiles:P,loadGlobalIdentity:G,loadDefaultGitIdentityId:ee}=Pi(Gr(s=>({profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId}))),{rootIsGitRepo:A,gitDirectory:r,nestedRepos:O}=qa(d??null,{enabled:o,recheckOnOpen:!0}),J=Ja(r??null),y=Ya(r??null),H=Fi({directory:r,branch:y?.current,chooseContributor:p.choose}),_=Di(r,a,f),Y=Qa(s=>M?s.getAttachment(M):void 0),te=Y?Xa(Y):[],he=Y&&!Y.degraded&&!Y.legacy?Y.worktreeRoot??void 0:void 0,se=Si(d,q,y?.current??void 0),oe=Za(r??null),le=ei(r??null),m=ti(r??null),c=si(r??null),I=ri(r??null),{setActiveDirectory:T,ensureAll:ne,fetchStatus:Q,fetchBranches:Z,fetchLog:$,setLogMaxCount:Be,fetchIdentity:ce,prefetchDiffs:pe,clearDiffCache:Me,moveStatusPathsOptimistically:be,restoreStatus:Se,bumpIndexRevision:ae,ensureNestedRepos:He,selectNestedRepo:zt}=ni(Gr(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}))),Ne=Et(s=>s.isMobile),Ae=Et(s=>s.openContextDiff),Ye=Et(s=>s.openContextSurface),[ke,Oe]=i.useState([]),W=ai(r,f,o),[Qe,_e]=i.useState(!1),Xe=i.useMemo(()=>{const s=W.read;return!s?.binding||W.status!=="ready"||s.binding.state==="bound"?null:ii(s.binding)?e("gitView.identity.configChanged"):e("gitView.context.needsAttention")},[W.read,W.status,e]),Ee=W.read?.binding?.remotes[0]?.name??W.read?.repository.remotes.find(s=>s.name==="origin")?.name??W.read?.repository.remotes[0]?.name??"",Ze=i.useCallback(s=>{const n=W.read?.repository.remotes.find(l=>l.name===Ee);return n?Bi(s,oi(n.fetch.displayUrl)):{applicable:!0}},[W.read,Ee]),Te=Mr(s=>s.entries),et=Mr(s=>s.refreshIdentityAccounts),$e=ts(s=>s.beginActiveContextsLoad),We=ts(s=>s.commitActiveContexts),Ke=ts(s=>s.releaseActiveContexts),Ve=i.useId();i.useEffect(()=>{if(!o||!d)return;const s=W.scope.runtimeKey,n=$e(s,d,Ve);return We(s,d,Ve,n,W.contexts.filter(l=>Ar(Te[Or(l)],l).connected)),()=>{Ke(s,d,Ve)}},[$e,W.contexts,W.scope.runtimeKey,We,d,o,Ke,Te,Ve]);const Ue=W.contexts[0]??null,X=y?.current??null,fe=ts(s=>!X||!Ue||!Ar(Te[Or(Ue)],Ue).connected?null:li(s.entries,Ue,X)),Re=Et(s=>s.navigateToDiff),ve=i.useRef(null),xe=i.useRef(null),Le=i.useRef(null),je=i.useRef(!0);i.useEffect(()=>()=>{je.current=!1},[]);const qe=i.useCallback(()=>{ve.current!==null&&(window.clearTimeout(ve.current),ve.current=null)},[]),cs=i.useCallback(s=>{qe(),ve.current=window.setTimeout(()=>{ve.current=null,De(s)===De(r)&&Q(s,a,{silent:!0})},Do)},[qe,r,Q,a]);i.useEffect(()=>qe,[qe]);const Qs=i.useCallback(()=>{xe.current!==null&&(window.clearTimeout(xe.current),xe.current=null)},[]),Ht=i.useCallback(()=>{xe.current===null&&(xe.current=window.setTimeout(()=>{xe.current=null,Le.current?.()},0))},[]),Xs=i.useCallback(async(s,n,l)=>{if(n==="stage"){if(a.stageGitFiles){await a.stageGitFiles(s,l);return}await Promise.all(l.map(u=>a.stageGitFile(s,u)));return}if(a.unstageGitFiles){await a.unstageGitFiles(s,l);return}await Promise.all(l.map(u=>a.unstageGitFile(s,u)))},[a]),tt=i.useMemo(()=>Fo({runMutation:({directory:s,direction:n,paths:l})=>Xs(s,n,l),onMutationComplete:({directory:s})=>{ae(s),cs(s)},onMutationError:({directory:s,direction:n,rollback:l},u)=>{l?.(),ae(s),cs(s);const N=e(n==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");g.error(u instanceof Error?u.message:N)},onPathsComplete:s=>{cr(n=>{const l=new Set(n);return s.forEach(u=>l.delete(u)),l})},scheduleFlush:Ht}),[ae,Xs,Ht,cs,e]);i.useEffect(()=>(Le.current=tt.flush,()=>{Le.current=null}),[tt]),i.useEffect(()=>()=>tt.clear(),[tt]),i.useEffect(()=>Qs,[Qs]),i.useEffect(()=>{if(!o)return;if(!d){h(null);return}const s=De(d)??d;h({directory:s,status:null});let n=!1,l=null;const u=async()=>{try{const N=await vi(d);if(n)return;h({directory:s,status:N.status}),N.status==="pending"&&(l=window.setTimeout(()=>{u()},500))}catch{n||h({directory:s,status:null})}};return u(),()=>{n=!0,l!==null&&window.clearTimeout(l)}},[o,d]);const Zs=De(k?.bootstrapPendingDirectory??null),an=!!(d&&Zs&&Zs===De(d)),on=ci(d??null),ye=De(d),us=v?.directory===ye?v.status:null,ds=!!(d&&(on||us==="pending"||an&&k?.pendingWorktreeRequestId)),er=!!(ye&&x?.directory===ye);i.useEffect(()=>{if(!ye)return;if(us==="failed"){z(null),B(n=>n?.directory===ye?null:n);return}if(ds){B(n=>n?.directory===ye&&n.status==="refreshing"?n:{directory:ye,status:"refreshing"});return}if(x?.directory!==ye||x.status!=="refreshing"||!r||!a)return;let s=!1;return Q(r,a,{force:!0,silent:!0,throwOnError:!0}).then(()=>{s||B(n=>n?.directory===ye?null:n)}).catch(()=>{s||B(n=>n?.directory===ye?{...n,status:"failed"}:n)}),()=>{s=!0}},[Q,a,r,ds,ye,us,x,z]);const ln=ds||er,ms=er&&x?.status==="failed",tr=i.useMemo(()=>r?dt.get(r)??null:null,[r]),Ct=ui(s=>s.settingsGitmojiEnabled),[St,hs]=i.useState(null),{gitmojis:pt}=Qi(Ct);i.useEffect(()=>{const s=he||se?.projectDirectory;if(!s){hs(null);return}let n=!1;return di(s).then(l=>{if(n)return;const u=l.trim();hs(u&&u!=="HEAD"?u:null)}).catch(()=>{n||hs(null)}),()=>{n=!0}},[he,se?.projectDirectory]);const[Nt,xt]=i.useState(tr?.commitMessage??""),[sr,cn]=i.useState([]),[un,fs]=i.useState(!1),rr=i.useRef(null),[nr,_t]=i.useState(null),[dn,gs]=i.useState(!1),[ar,ir]=i.useState(null),[Ie,mn]=i.useState(25),[hn,or]=i.useState(!1),{triggerFireworks:fn}=Ni(),lr=i.useRef(new Map),$t=i.useRef(0),ps=i.useCallback(()=>{$t.current+=1,je.current&&or(!0)},[]),xs=i.useCallback(()=>{$t.current=Math.max(0,$t.current-1),je.current&&$t.current===0&&or(!1)},[]),[ys,Wt]=i.useState(new Set),[gn,cr]=i.useState(new Set),[ws,ur]=i.useState(!1),[pn,xn]=i.useState(0),[yn,dr]=i.useState(!1),[bs,vs]=i.useState(tr?.generatedHighlights??[]),wn=gn.size>0||tt.size()>0||tt.isRunning(),mr=i.useCallback(()=>{const s=rr.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),js=he||se?.projectDirectory||null,Cs=y?.current||null,bn=i.useMemo(()=>{const s=y?.tracking;return s?s.startsWith("origin/"):!0},[y?.tracking]),hr=i.useMemo(()=>{const s=se?.createdFromBranch,n=typeof s=="string"?s.trim():"",l=typeof y?.current=="string"?y.current.trim():"",u=typeof St=="string"?St.trim():"";return n?n===l&&n.startsWith("opencode/")&&u.length>0&&u!==n?u:n:u||l||"HEAD"},[se?.createdFromBranch,y,St]),Kt=i.useCallback(()=>{vs([])},[]),[Ss,vn]=i.useState(new Set),[Ut,jn]=i.useState(new Map),[qt,Ns]=i.useState(new Set),ks=i.useRef(Ut),kt=i.useRef(qt),[Cn,yt]=i.useState(null),[fr,gr]=i.useState(""),[ge,Jt]=i.useState(null),[Sn,pr]=i.useState(!1),[Nn,xr]=i.useState(!1),[kn,yr]=i.useState(null),[wr,br]=i.useState(null),[Vn,Yt]=i.useState([]),[Rn,wt]=i.useState(!1),[In,Vt]=i.useState([]),[Qt,Rt]=i.useState("merge"),[Pn,Vs]=i.useState(null),[Rs,vr]=i.useState(!1),[Is,Fn]=i.useState(100),[Dn,Bn]=i.useState(0),Pe=i.useMemo(()=>M?`openchamber.conflict:${M}`:null,[M]),jr=i.useCallback((s,n,l)=>{if(!Pe||typeof window>"u")return;const u={directory:s,conflictFiles:n,operation:l};window.localStorage.setItem(Pe,JSON.stringify(u))},[Pe]),Fe=i.useCallback(()=>{!Pe||typeof window>"u"||window.localStorage.removeItem(Pe)},[Pe]),Je=i.useCallback((s,n)=>{Vt(s),Rt(n),wt(!0),r&&jr(r,s,n)},[r,jr]);i.useEffect(()=>{if(!Pe||typeof window>"u"||!r)return;const s=window.localStorage.getItem(Pe);if(s)try{const n=JSON.parse(s);if(n.directory!==r){window.localStorage.removeItem(Pe);return}Vt(n.conflictFiles??[]),Rt(n.operation??"merge"),wt(!0)}catch{window.localStorage.removeItem(Pe)}},[Pe,r]);const[Mn,Cr]=i.useState(!1),[Xt,It]=i.useState(null),[Ps,An]=i.useState("merge"),[Fs,On]=i.useState(""),[Ds,En]=i.useState(""),Tn=i.useCallback(s=>{mi(s).then(n=>{if(n.ok){g.success(e("gitView.toast.commitHashCopied"));return}g.error(e("gitView.toast.copyFailed"))})},[e]),Ln=i.useCallback(s=>{vn(n=>{const l=new Set(n);return l.has(s)?l.delete(s):l.add(s),l})},[]);i.useEffect(()=>{ks.current=Ut},[Ut]),i.useEffect(()=>{kt.current=qt},[qt]),i.useEffect(()=>{if(!r||!a)return;const s=Array.from(Ss).filter(l=>!ks.current.has(l)&&!kt.current.has(l));if(s.length===0)return;let n=!1;return Ns(l=>{const u=new Set(l);for(const N of s)u.add(N);return kt.current=u,u}),Promise.all(s.map(l=>a.getCommitFiles(r,l).then(u=>({hash:l,files:u.files})).catch(u=>(console.error("Failed to fetch commit files:",u),{hash:l,files:[]})))).then(l=>{n||(jn(u=>{const N=new Map(u);for(const{hash:C,files:D}of l)N.set(C,D);return ks.current=N,N}),Ns(u=>{const N=new Set(u);for(const{hash:C}of l)N.delete(C);return kt.current=N,N}))}),()=>{n=!0,Ns(l=>{let u=!1;const N=new Set(l);for(const C of s)N.delete(C)&&(u=!0);return u?(kt.current=N,N):l})}},[Ss,r,a]),i.useEffect(()=>{if(!r)return;const s=dt.get(r)??null;xt(s?.commitMessage??""),vs(s?.generatedHighlights??[])},[r]),i.useEffect(()=>{r&&Eo(r,{directory:r,commitMessage:Nt,generatedHighlights:bs})},[Nt,r,bs]),i.useEffect(()=>{o&&(P(),G(),ee())},[o,P,G,ee]);const Zt=i.useCallback(async()=>{if(!r||!a?.getRemotes||J!==!0){Oe([]);return}try{const s=await a.getRemotes(r);je.current&&Oe(s)}catch{je.current&&Oe([])}},[r,a,J]);i.useEffect(()=>{o&&Zt()},[o,Zt]),i.useEffect(()=>{o&&d&&r&&(T(d),ne(r,a))},[o,d,r,T,ne,a]),i.useEffect(()=>{if(o&&r)return hi.onGitRefreshHint(s=>{De(s.directory)===De(r)&&(s.paths?.length&&Me(r,s.paths),Q(r,a,{silent:!0}))})},[o,Me,r,Q,a]);const re=i.useCallback(async(s=!0)=>{if(r)try{await Promise.all([Q(r,a),Z(r,a)])}catch(n){if(s){const l=n instanceof Error?n.message:e("gitView.toast.refreshRepositoryFailed");g.error(l)}}},[r,a,Q,Z,e]),ue=i.useCallback(async()=>{r&&await $(r,a,Ie)},[r,a,$,Ie]),lt=i.useCallback(async s=>{if(!r)return;const n=Promise.allSettled([Z(r,a),ue()]);s&&n.then(s),await Q(r,a).catch(()=>{})},[r,a,Z,Q,ue]),Bs=i.useCallback(async()=>{r&&await ce(r,a)},[r,a,ce]);i.useEffect(()=>{if(!o||!r||!a?.hasLocalIdentity||J!==!0)return;const s=typeof V=="string"?V.trim():"";if(!s||s==="global")return;const n=ut(),l=JSON.stringify([n,r]);if(lr.current.get(l)===s)return;let N=!1,C=!1;return(async()=>{try{const K=await a.hasLocalIdentity?.(r);if(N||ut()!==n||K===!0||(ps(),C=!0,await a.setGitIdentity(r,s),N||ut()!==n))return;lr.current.set(l,s),await Bs()}catch(K){!N&&ut()===n&&console.warn("Failed to auto-apply default git identity:",K)}finally{C&&xs()}})(),()=>{N=!0}},[o,ps,r,V,xs,a,J,Bs]);const st=i.useMemo(()=>y?[...y.files??[]].sort((n,l)=>n.path.localeCompare(l.path)):[],[y]),Ce=i.useMemo(()=>st.filter(Zr),[st]),Ms=i.useMemo(()=>st.filter(To),[st]);i.useEffect(()=>{if(!o||!r||st.length===0)return;const s=[],n=new Set,l=N=>{!N||n.has(N)||(n.add(N),s.push(N))};if(Ce.forEach(N=>l(N.path)),sr.forEach(l),st.slice(0,Mo).forEach(N=>l(N.path)),s.length===0)return;const u=window.setTimeout(()=>{pe(r,a,s,{maxFiles:Bo})},120);return()=>{window.clearTimeout(u)}},[o,st,r,a,pe,Ce,sr]);const Pt=async(s,n,l=!1)=>{if(!r)return;const u=_.start();if(!u)return;_t(s);const N=e(s==="fetch"?"gitView.sync.fetch":s==="pull"?"gitView.sync.pull":s==="publish"?"gitView.publish.title":"gitView.sync.syncChanges");let C=null;try{if(s==="sync"||s==="publish"){const D=await H.prepare(s==="publish"?"push":"sync",{forceChoose:l,onOperation:u.onOperation});C=Ci(await D())}else if(n&&y)await Tr({action:s,directory:r,remoteName:n.name,status:y,sourceControl:f,git:a,onOperation:u.onOperation});else throw new we("tracking-required");if(!u.isCurrent())return;s==="fetch"&&n?g.success(e("gitView.toast.fetchedFromRemote",{name:n.name})):s==="pull"&&n?g.success(e("gitView.toast.pulledFromRemote",{name:n.name})):s==="sync"?g.success(C?.kind==="up-to-date"?e("gitView.toast.alreadyUpToDate"):C?.kind==="pulled"?e("gitView.toast.pulledFromRemote",{name:C.remoteName}):C?.kind==="pushed"?e("gitView.toast.pushedToUpstream",{name:C.remoteName}):e("gitView.toast.syncedChanges")):s==="publish"&&g.success(e("gitView.publish.succeeded")),await lt()}catch(D){if(D instanceof At||D instanceof Lr){if(D instanceof At&&D.read.availability==="available"&&g.error(e("gitView.toast.syncActionFailed",{action:N}),{description:D.message||void 0}),u.isCurrent()&&await lt(),u.isCurrent()&&D instanceof At&&D.read.availability==="available"&&D.read.operation.state==="conflicted"&&D.read.operation.error.code==="CONFLICT"){const ze=((await a.getGitStatus(r).catch(()=>null))?.files??[]).filter(Gs).map(ya=>ya.path);ze.length>0&&Je(ze,"merge")}return}if(D instanceof we&&D.code==="stale-runtime")return;if(D instanceof we&&H.errorMessage(D)){g.info(H.errorMessage(D));return}await lt();const K=D instanceof we?D.code==="contributor-publish-cancelled-after-update"?e("gitView.toast.contributorPublishCancelledAfterUpdate"):D.code==="contributor-publish-cancelled"?e("gitView.toast.contributorPublishCancelled"):e("gitView.toast.syncActionFailed",{action:N}):D instanceof Error?D.message:e("gitView.toast.syncActionFailed",{action:N});g.error(K)}finally{u.finish(),u.isCurrent()&&_t(null)}},Gn=i.useCallback(async s=>{if(!r)return;const n=s.name.trim();if(!n){g.error(e("gitView.toast.remoteNameRequired"));return}if(n==="origin"){g.error(e("gitView.toast.cannotRemoveOriginRemote"));return}yr(n);try{await a.removeRemote(r,{remote:n}),g.success(e("gitView.toast.removedRemote",{name:n})),await Promise.all([re(!1),Zt()])}catch(l){const u=l instanceof Error?l.message:`Failed to remove ${n}`;g.error(u)}finally{yr(null)}},[r,a,Zt,re,e]),Sr=async(s={})=>{if(!r)return;if(!Nt.trim()){g.error(e("gitView.toast.enterCommitMessage"));return}const n=Ce.map(C=>C.path).sort();if(n.length===0){g.error(e("gitView.toast.stageFileToCommit"));return}const l=s.pushAfter?"commitAndPush":"commit";ir(l);let u=null,N="pending";try{if(await a.createGitCommit(r,Nt.trim(),{files:n,stageFiles:[]}),N="local",ae(r),ae(r),g.success(e("gitView.toast.commitCreated")),xt(""),Kt(),s.pushAfter){if(u=_.start(),!u){g.warning(e("gitView.publish.commitKept")),await lt();return}const C=await H.prepare("push",{onOperation:u.onOperation});_t("publish"),await C(),N="published",g.success(e("gitView.publish.succeeded")),fn()}await lt(()=>xn(C=>C+1))}catch(C){if(s.pushAfter&&N==="local"&&g.warning(e("gitView.publish.commitKept")),C instanceof At||C instanceof Lr){C instanceof At&&C.read.availability==="available"&&g.error(e("gitView.toast.pushFailed"),{description:C.message||void 0}),await lt();return}if(C instanceof we&&C.code==="stale-runtime")return;if(C instanceof we&&H.errorMessage(C)){g.info(H.errorMessage(C));return}s.pushAfter&&await lt();const D=C instanceof we?C.code==="contributor-publish-cancelled-after-update"?e("gitView.toast.contributorPublishCancelledAfterUpdate"):C.code==="contributor-publish-cancelled"?e("gitView.toast.contributorPublishCancelled"):e("gitView.toast.syncActionFailed",{action:e("gitView.sync.syncChanges")}):C instanceof Error?C.message:e("gitView.toast.createCommitFailed");g.error(D)}finally{u?.finish(),ir(null),s.pushAfter&&_t(null)}},zn=i.useCallback(async()=>{if(!r)return;const s=Ce.map(n=>n.path).sort();if(s.length===0){g.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:s.length}),dr(!0);try{const{message:n}=await Er(r,s),l=n.subject?.trim()??"",u=Array.isArray(n.highlights)?n.highlights:[];if(l){let N=l;if(Ct&&pt.length>0){const C=Xr(l,pt);if(C){const{code:D,emoji:K}=C;!l.startsWith(D)&&!l.startsWith(K)&&(N=`${D} ${l}`)}}xt(N)}vs(u),mr()}catch(n){console.error("[git-generation][browser] GitView generate handler failed",{message:n instanceof Error?n.message:String(n),error:n});const l=n instanceof Error?n.message:e("gitView.toast.generateCommitMessageFailed");g.error(l)}finally{dr(!1)}},[r,Ce,Ct,pt,mr,e]),As=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",Hn=async s=>{if(!r||!y)return;const n=Ls(Y);if(n.length>0){g.error(e("gitView.toast.cannotCreateBranch",{reason:As(n[0])}));return}const l=y.current??null;try{await a.createBranch(r,s,l??"HEAD"),g.success(e("gitView.toast.createdBranch",{name:s})),await a.checkoutBranch(r,s),await re(),await ue()}catch(u){if(u instanceof we&&u.code==="stale-runtime")return;const N=u instanceof Error?u.message:e("gitView.toast.createBranchFailed");throw g.error(N),u}},_n=async(s,n)=>{if(!r)return;const l=Ls(Y);if(l.length>0){g.error(e("gitView.toast.cannotRenameBranch",{reason:As(l[0])}));return}try{await a.renameBranch(r,s,n),g.success(e("gitView.toast.renamedBranch",{oldName:s,newName:n})),await re(),await ue()}catch(u){const N=u instanceof Error?u.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:n});g.error(N)}},$n=async s=>{if(!r)return;const n=Ls(Y);if(n.length>0){g.error(e("gitView.toast.cannotCheckout",{reason:As(n[0])}));return}const l=s.replace(/^remotes\//,"");if(y?.current!==l){if((y?.files?.length??0)>0){It(l);return}await Os(l)}},Os=async s=>{if(!r)return;const n=s;try{const l=await a.checkoutBranch(r,n);g.success(e("gitView.toast.checkedOut",{name:l?.branch||n})),await re(),await ue()}catch(l){const u=l instanceof Error?l.message:e("gitView.toast.checkoutFailed",{name:n});g.error(u)}},Wn=async s=>{if(!r)return;const n=ut();ps();try{const l=await Gi({directory:r,identity:s,remoteName:Ee||null},{git:a,sourceControl:f});if(ut()!==n)return;l.status==="failed"?g.error(e("gitView.toast.applyIdentityFailed")):g.success(e("gitView.toast.appliedIdentity",{name:ji(s,e)})),await Bs()}catch(l){if(ut()!==n)return;const u=l instanceof Error?l.message:e("gitView.toast.applyIdentityFailed");g.error(u)}finally{xs()}},Ft=i.useMemo(()=>oe?.all?oe.all.filter(s=>!s.startsWith("remotes/")).sort():[],[oe]),Dt=i.useMemo(()=>oe?.all?oe.all.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],[oe]),Kn=i.useMemo(()=>Io(ke.map(s=>s.name),Dt),[ke,Dt]),rt=y?.current??null,Nr=i.useMemo(()=>{const s=W.contexts[0]?.primaryRemote;return s?oe?.defaultBranches?.[s]:void 0},[W.contexts,oe]),ct=i.useMemo(()=>Mi({remoteNames:new Set(W.contexts[0]?.primaryRemote?[W.contexts[0].primaryRemote]:[]),knownRemoteNames:new Set(W.read?.repository.remotes.map(s=>s.name)??[]),localBranches:Ft,worktreeCreatedFromBranch:se?.createdFromBranch,rootBranchHint:St,defaultBranch:Nr,headBranch:rt,fallbackToConventional:!1}),[rt,Nr,W.contexts,Ft,W.read,St,se?.createdFromBranch]),Un=i.useMemo(()=>{const s=W.contexts[0]?.primaryRemote,n=s?`${s}/${ct}`:null;return n&&Dt.includes(n)?n:ct},[ct,W.contexts,Dt]),kr=fi(),qn=i.useMemo(()=>gi(j,F,s=>ba(s)&&pi(s,kr)),[j,F,kr]),Vr=W.read?W.read.binding?.providers.find(s=>s.readiness==="ready")?.accountId??null:void 0,Jn=i.useMemo(()=>xi(j,F,m,s=>({id:"local-config",name:s.userName,...s,color:"info",icon:"user"}),Vr),[Vr,m,j,F]),Yn=Ce.length,Qn=c||nr!==null||ar!==null,Xn=!!(se&&js&&Cs&&bn),Rr=!!rt,nt=Xn&&js&&Cs&&se?{repoRoot:js,sourceBranch:Cs,worktreeMetadata:se}:null;i.useEffect(()=>{if(!r||!a||!le?.all?.length||!rt||!ct||rt===ct){yt(null);return}let s=!1;return(async()=>{try{const l=await a.getGitLog(r,{from:ct,to:"HEAD",maxCount:Ie});if(s)return;const u=new Set((l?.all??[]).map(C=>C.hash).filter(C=>typeof C=="string"&&C.length>0));if(u.size===0){yt(null);return}const N=le.all.findIndex(C=>!u.has(C.hash));if(N===0){yt(null);return}if(N===-1){yt({insertBeforeIndex:le.all.length,branchName:rt,direction:"up"});return}yt({insertBeforeIndex:N,branchName:rt,direction:"up"})}catch{s||yt(null)}})(),()=>{s=!0}},[ct,rt,r,a,le,Ie]),i.useEffect(()=>{Vs(null)},[r]),i.useEffect(()=>{if(ge!=="graph"||!r){ge!=="graph"&&Vs(null);return}let s=!1;return vr(!0),a.getGitLog(r,{maxCount:Is,all:!0}).then(n=>{s||Vs(n)}).catch(n=>{console.error("Failed to fetch graph log:",n)}).finally(()=>{s||vr(!1)}),()=>{s=!0}},[ge,r,Is,Dn,a]);const Bt=i.useCallback((s,n)=>{if(!r||s.length===0)return;const l=Array.from(new Set(s));cr(N=>{const C=new Set(N);return l.forEach(D=>C.add(D)),C});const u=be(r,l,n);tt.enqueue({directory:r,direction:n,paths:new Set(l),rollback:()=>Se(r,u)}),Ht()},[r,tt,be,Se,Ht]),Es=i.useCallback(async s=>{if(r){Wt(n=>{const l=new Set(n);return l.add(s),l});try{await a.revertGitFile(r,s,{scope:"working"}),g.success(e("gitView.toast.revertedFile",{path:s})),await re(!1)}catch(n){const l=n instanceof Error?n.message:e("gitView.toast.revertFailed");g.error(l)}finally{Wt(n=>{const l=new Set(n);return l.delete(s),l})}}},[r,re,a,e]),Mt=i.useCallback(async(s,n,l="all")=>{if(!r||s.length===0)return;const u=Array.from(new Set(s));if(ws||u.some(K=>ys.has(K)))return;const N=new Set(Ce.map(K=>K.path)),C=l==="all"&&u.some(K=>N.has(K));n&&ur(!0),Wt(K=>{const ie=new Set(K);return u.forEach(ze=>ie.add(ze)),ie});const D=[];try{if(await yi(u,Ao,async K=>{try{await a.revertGitFile(r,K,{scope:l})}catch(ie){D.push({path:K,message:ie instanceof Error?ie.message:e("gitView.toast.revertFailed")})}}),C&&D.length<u.length&&ae(r),await re(!1),D.length===0)g.success(u.length===1?e("gitView.toast.revertedFilesSingle",{count:u.length}):e("gitView.toast.revertedFilesPlural",{count:u.length}));else if(D.length===u.length)g.error(D[0]?.message||e("gitView.toast.revertFailed"));else{const K=u.length-D.length;g.warning(K===1?e("gitView.toast.revertedSomeSingle",{success:K,failed:D.length}):e("gitView.toast.revertedSomePlural",{success:K,failed:D.length}))}}finally{Wt(K=>{const ie=new Set(K);return u.forEach(ze=>ie.delete(ze)),ie}),n&&ur(!1)}},[ae,r,a,ws,re,ys,Ce,e]),Zn=i.useCallback(async s=>{await Mt(s,!0)},[Mt]),ea=i.useCallback(async s=>{await Mt(s,!1,"working")},[Mt]),Ts=i.useCallback((s,n)=>{if(d&&!Ne){Ae(d,s,n);return}Re(s,n)},[d,Ne,Re,Ae]),ta=i.useCallback(()=>gs(!0),[]),sa=i.useMemo(()=>{const s=[];return Ce.length>0&&s.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:Ce,statsScope:"staged",actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:n=>e("gitView.changes.unstageFileAria",{path:n}),onActionFile:n=>{Bt([n],"unstage")},onActionAll:n=>{Bt(n,"unstage")},onViewDiff:n=>Ts(n,!0),onRevertFile:Es,showRevertActions:!1,accent:!0}),Ms.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:Ms,statsScope:"working",actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:n=>e("gitView.changes.stageFileAria",{path:n}),onActionFile:n=>{Bt([n],"stage")},onActionAll:n=>{Bt(n,"stage")},onViewDiff:n=>Ts(n,!1),onRevertFile:Es}),s},[Es,Ts,Bt,Ce,e,Ms]),ra=i.useCallback(s=>{if(s.length===0)return;const n=s.map(l=>l.trim()).filter(Boolean);if(n.length===0){Kt();return}xt(l=>{const u=l.trim(),N=u.length>0?`
|
|
3
3
|
|
|
4
|
-
`:"";return`${
|
|
5
|
-
`)}`.trim()}),Ut()},[Ut]),na=i.useCallback((s,n)=>{const l=n||s;xt(d=>{const N=d.trimStart();return N.startsWith(s)||n&&N.startsWith(n)?d:`${l.endsWith(" ")?l:`${l} `}${d}`.trimStart()}),gr(""),fs(!1)},[]),Ir=i.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")},[]),bt=i.useCallback((s,n)=>{Yt(l=>[...l,{message:s,status:n,timestamp:Date.now()}])},[]),Ge=i.useCallback((s,n)=>{Yt(l=>{if(l.length===0)return l;const d=[...l];return d[d.length-1]={...d[d.length-1],status:s,...n?{message:n}:{}},d})},[]),Pr=i.useCallback(()=>{Yt([])},[]),aa=i.useCallback(()=>{Yt([]),br(null)},[]),es=i.useCallback(async(s,n)=>{if(!r)return;const l=n.kind==="remote"?H.start():null;if(n.kind==="remote"&&!l)return;br(s),Pr();const d=y?.current;let N=n.branch;try{if(N=await Po({directory:r,git:a,target:n,runPlannedFetch:async C=>{if(bt(`Fetching ${C.label}...`,"running"),!y||!l)throw new we("branch-required");if(await Tr({action:"fetch",directory:r,fetchTarget:{remoteName:C.remote,sourceRef:C.sourceRef,destinationRef:C.destinationRef},remoteName:C.remote,status:y,sourceControl:f,git:a,onOperation:l.onOperation}),!l.isCurrent())throw new we("stale-runtime");Ge("done",`Fetched ${C.label}`)}}),l&&!l.isCurrent())throw new we("stale-runtime");if(s==="merge"){bt(`Merging ${n.label} into ${d}...`,"running");const C=await a.merge(r,{branch:N});C.conflict?(Ge("error","Merge conflicts detected"),Je(C.conflictFiles??[],"merge")):(Ge("done",`Merged ${n.label} into ${d}`),Fe(),bt("Refreshing repository status...","running"),await re(),await de(),Ge("done","Repository status updated"))}else{bt(`Rebasing ${d} onto ${n.label}...`,"running");const C=await a.rebase(r,{onto:N});C.conflict?(Ge("error","Rebase conflicts detected"),Je(C.conflictFiles??[],"rebase")):(Ge("done",`Rebased ${d} onto ${n.label}`),Fe(),bt("Refreshing repository status...","running"),await re(),await de(),Ge("done","Repository status updated"))}}catch(C){if(Ir(C))Ge("error","Uncommitted changes detected"),An(s),On(N),En(n.label),Cr(!0);else{const D=C instanceof we?e("gitView.toast.syncActionFailed",{action:e("gitView.sync.fetch")}):C instanceof Error?C.message:s==="merge"?`Failed to merge ${n.label}`:`Failed to rebase onto ${n.label}`;Ge("error",D)}}finally{l?.finish()}},[r,a,f,y,H,re,de,Ir,Je,Fe,bt,Ge,Pr,e]),ia=i.useCallback(s=>{es("merge",s)},[es]),oa=i.useCallback(s=>{es("rebase",s)},[es]),la=i.useCallback(async()=>{if(r)try{Qt==="merge"?(await a.abortMerge(r),g.success(e("gitView.toast.mergeAborted"))):(await a.abortRebase(r),g.success(e("gitView.toast.rebaseAborted"))),Fe(),await re(),await de()}catch(s){const n=s instanceof Error?s.message:`Failed to abort ${Qt}`;g.error(n)}},[r,a,Qt,re,de,Fe,e]),ca=i.useMemo(()=>(y?.files??[]).filter(Gs).length,[y?.files]),da=i.useCallback(async()=>{if(r)try{const s=!!y?.mergeInProgress?.head,n=!!(y?.rebaseInProgress?.headName||y?.rebaseInProgress?.onto);if(s){const l=await a.continueMerge(r);l.conflict?(Je(l.conflictFiles??[],"merge"),g.error(e("gitView.toast.mergeConflictsDetected"))):(Fe(),g.success(e("gitView.toast.mergeCompleted")),await re(),await de())}else if(n){const l=await a.continueRebase(r);l.conflict?(Je(l.conflictFiles??[],"rebase"),g.error(e("gitView.toast.rebaseConflictsDetected"))):(Fe(),g.success(e("gitView.toast.rebaseStepCompleted")),await re(),await de())}}catch(s){const n=s instanceof Error?s.message:e("gitView.toast.continueOperationFailed");g.error(n)}},[r,a,y,re,de,Je,Fe,e]),ua=i.useCallback(async()=>{if(r)try{!!y?.mergeInProgress?.head?(await a.abortMerge(r),g.success(e("gitView.toast.mergeAborted"))):(await a.abortRebase(r),g.success(e("gitView.toast.rebaseAborted"))),Fe(),await re(),await de()}catch(s){const n=s instanceof Error?s.message:e("gitView.toast.abortOperationFailed");g.error(n)}},[r,a,y,re,de,Fe,e]),ma=i.useCallback(()=>{if(!r)return;const n=!!y?.mergeInProgress?.head?"merge":"rebase",l=(y?.files??[]).filter(Gs).map(d=>d.path);l.length>0&&Vt(l),Rt(n),wt(!0)},[r,y]),ha=i.useCallback(async s=>{if(!r)return;const n=y?.current,l=Ps,d=Fs,N=Ds||d,C=(y?.files??[]).some(Xr);try{await a.stash(r,{message:`Auto-stash before ${l} with ${N}`,includeUntracked:!0}),C&&ae(r)}catch(ie){const ze=ie instanceof Error?ie.message:"Failed to stash changes";g.error(ze);return}let D=!1,U=!1;try{if(l==="merge"){const ie=await a.merge(r,{branch:d});ie.conflict?(U=!0,Vt(ie.conflictFiles??[]),Rt("merge"),wt(!0)):(D=!0,g.success(e("gitView.toast.mergedIntoBranch",{branch:N,currentBranch:n||""})))}else{const ie=await a.rebase(r,{onto:d});ie.conflict?(U=!0,Vt(ie.conflictFiles??[]),Rt("rebase"),wt(!0)):(D=!0,g.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:n||"",branch:N})))}if(s&&D)try{await a.stashPop(r),ae(r),g.success(e("gitView.toast.stashedRestored"))}catch(ie){const ze=ie instanceof Error?ie.message:e("gitView.toast.restoreStashFailed");g.error(ze)}else s&&U&&g.info(e("gitView.toast.restoreStashManually"));await re(),await de()}catch(ie){if(s)try{await a.stashPop(r),ae(r)}catch{}throw ie}},[ae,r,a,y,Ps,Fs,Ds,re,de,e]),fa=i.useCallback(s=>{mn(s),r&&(Be(r,s),$(r,a,s))},[r,$,a,Be]),ga=i.useCallback(s=>{Fn(s)},[]),pa=i.useCallback(()=>{Jt(null),r&&(Q(r,a),X(r,a),$(r,a,Ie))},[r,Q,X,$,Ie,a]),xa=i.useCallback(s=>{if(s.conflict){if(s.operation==="cherry-pick"||s.operation==="revert"){g.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:s.conflictFiles?.join(", ")??"unknown files"})}),r&&(Q(r,a),X(r,a),$(r,a,Ie));return}Je(s.conflictFiles??[],s.operation)}},[e,Je,r,Q,X,$,Ie,a]);return u?ln?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[ms?null:t.jsx(E,{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(ms?"gitView.toast.refreshRepositoryFailed":"gitView.empty.worktreeSetupInProgress")}),ms?t.jsx(K,{type:"button",variant:"outline",size:"sm",className:"mt-3",onClick:()=>{ye&&B({directory:ye,status:"refreshing"})},children:e("gitView.empty.retryDiscovery")}):t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):J===null||J===!0&&!y?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(E,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):J===!1?t.jsx(Bi,{root:u,rootIsGitRepo:A,resolvedIsGitRepo:J,nestedRepos:O,onRetryDiscovery:()=>{u&&_e(u,{force:!0})},emptyStateFooter:te.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:me("flex h-full flex-col overflow-hidden"),children:[t.jsx(Mi,{directory:r??"",status:y,localBranches:Ft,remoteBranches:Dt,branchInfo:oe?.branches,syncAction:H.entry?.executing?nr:null,operationBlocked:H.blocked,remotes:ke,onFetch:s=>Pt("fetch",s),onPull:s=>Pt("pull",s),onSync:s=>Pt("sync",s),onPublish:()=>{Pt("publish")},onChooseSyncTargets:()=>{Pt("sync",void 0,!0)},onRemoveRemote:Gn,removingRemoteName:kn,onCheckoutBranch:$n,onCreateBranch:_n,onRenameBranch:Hn,activeIdentityProfile:Jn,availableIdentities:qn,onSelectIdentity:Wn,isApplyingIdentity:hn,identityAttention:Ze,identityApplicability:Xe,onConfigureRepository:w.isVSCode?void 0:()=>He(!0),onIdentityMenuOpen:()=>{et(f,j.map(s=>s.account))},isWorktreeMode:!!se,onOpenHistory:()=>Jt("history"),onOpenGraph:()=>Jt("graph"),onOpenStashes:ta,onOpenUpdateBranch:Rr?()=>pr(!0):void 0,onOpenReintegrateCommits:nt?()=>xr(!0):void 0,pullRequest:fe?.changeRequest??fe?.pr??null,pullRequestProvider:fe?.changeRequest?.provider??null,prChecks:fe?.ci?.summary??fe?.checks??null,onOpenPullRequest:r?()=>Ye(r,"pr"):void 0,repositoryOptions:r!==u&&Array.isArray(O)?O:void 0,selectedRepository:r!==u?r:null,onSelectRepository:r!==u&&u?s=>zt(u,s):void 0,repositoryRoot:r!==u?u:void 0}),w.isVSCode?null:t.jsx(Li,{open:Qe,onOpenChange:He,directory:o?r??"":""}),t.jsx(Ai,{className:"mx-4 mt-3",entry:H.entry,onRefresh:()=>{H.refresh()},onCancel:()=>{H.cancel()}}),u&&(y?.mergeInProgress?.head||y?.rebaseInProgress?.headName||y?.rebaseInProgress?.onto)&&t.jsx(Gi,{mergeInProgress:y?.mergeInProgress,rebaseInProgress:y?.rebaseInProgress,onContinue:da,onAbort:ua,onResolveWithAI:ma,conflictCount:ca,isLoading:c}),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:me("min-w-0 min-h-0 h-full flex flex-col"),children:t.jsx(tn,{as:wi,ref:rr,outerClassName:"flex-1 min-h-0",className:me("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:(st?.length??0)>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(zi,{groups:sa,diffStats:y?.diffStats,revertingPaths:ys,isRevertingAll:ws,onVisiblePathsChange:cn,onRevertAll:Xn,onRevertDirectory:ea,headerBackgroundClassName:"bg-background"})}),t.jsx(_i,{stagedCount:Yn,commitMessage:Nt,onCommitMessageChange:xt,generatedHighlights:bs,onInsertHighlights:ra,onGenerateMessage:zn,isGeneratingMessage:yn,onCommit:()=>Sr({pushAfter:!1}),onCommitAndPush:()=>Sr({pushAfter:!0}),commitAction:ar,networkOperationBlocked:H.blocked,hasPendingIndexMutation:wn,gitmojiEnabled:Ct,onOpenGitmojiPicker:()=>fs(!0)})]}):t.jsx(ao,{onOpenStashes:()=>gs(!0)})})})})})}),t.jsx(mt,{open:Sn,onOpenChange:s=>{!s&&wr!==null||pr(s)},children:t.jsxs(ht,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(gt,{children:e("gitView.branch.updateTitle")}),t.jsxs(vt,{children:[e("gitView.branch.updateDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:y?.current??""}),"."]})]}),Rr?t.jsx(vo,{mode:"bare",currentBranch:y?.current,localBranches:Ft,remoteBranches:Un,defaultTargetBranch:Kn,onMerge:ia,onRebase:oa,disabled:Qn||H.blocked,isOperating:wr!==null,operationLogs:Vn,onOperationComplete:aa}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})]})}),t.jsx(mt,{open:Nn,onOpenChange:xr,children:t.jsxs(ht,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(gt,{children:e("gitView.integrate.title")}),t.jsx(vt,{children:nt?t.jsxs("span",{className:"font-mono text-foreground",children:[nt.sourceBranch," → ",hr]}):null})]}),nt?t.jsx(ro,{repoRoot:nt.repoRoot,sourceBranch:nt.sourceBranch,worktreeMetadata:nt.worktreeMetadata,localBranches:Ft,defaultTargetBranch:hr,refreshKey:pn,showHeader:!1,onRefresh:()=>{r&&(Q(r,a),X(r,a),$(r,a,Ie))}},nt.worktreeMetadata.path):null]})}),t.jsx(mt,{open:ge!==null,onOpenChange:s=>{s||Jt(null)},children:t.jsxs(ht,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx(gt,{children:e(ge==="graph"?"gitView.graph.title":"gitView.history.title")}),t.jsxs(K,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:()=>{if(ge==="graph"){Bn(s=>s+1);return}r&&$(r,a,Ie)},disabled:ge==="graph"?Rs:I,title:e("gitView.history.refresh"),"aria-label":e("gitView.history.refresh"),children:[t.jsx(E,{name:"refresh",className:me("size-4",(ge==="graph"?Rs:I)&&"animate-spin")}),e("gitView.history.refresh")]})]}),t.jsx(vt,{children:e("gitView.history.dialogDescription")})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(go,{mode:ge==="graph"?"graph":"history",log:ge==="graph"?Pn??le:le,isLogLoading:ge==="graph"&&Rs||I,logMaxCount:ge==="graph"?Is:Ie,onLogMaxCountChange:ge==="graph"?ga:fa,expandedCommitHashes:Ss,onToggleCommit:Ln,commitFilesMap:Kt,loadingCommitHashes:qt,onCopyHash:Tn,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ge==="graph"?null:Cn,onConflict:ge==="graph"?xa:void 0,onActionSuccess:ge==="graph"?pa:void 0})})]})}),t.jsx(no,{open:un,onOpenChange:gs,directory:r,hasUncommittedChanges:(y?.files?.length??0)>0,hasStagedChanges:Ce.length>0,uncommittedFileCount:y?.files?.length??0,onChanged:async s=>{r&&s?.affectsIndex&&ae(r),await re(!1),await de()}}),t.jsx(mt,{open:dn,onOpenChange:fs,children:t.jsxs(ht,{className:"max-w-md p-0 overflow-hidden",children:[t.jsx(ft,{className:"px-4 pt-4",children:t.jsx(gt,{children:e("gitView.gitmoji.title")})}),t.jsxs(Ks,{className:"h-[420px]",shouldFilter:!1,children:[t.jsx(qs,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:fr,onValueChange:gr}),t.jsxs(Js,{children:[t.jsx(Ys,{children:e("gitView.gitmoji.empty")}),t.jsx(ns,{children:Lt(pt,fr,s=>[s.code,s.description,s.emoji]).map(s=>t.jsxs(as,{onSelect:()=>na(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))})]})]})]})}),_.context?t.jsx(Hi,{context:_.context,onSelect:_.settle}):null,_.confirmDialog,t.jsx($i,{candidates:p.candidates,onSelect:p.settle}),r&&t.jsx(Wi,{open:Rn,onOpenChange:wt,conflictFiles:In,directory:r,operation:Qt,onAbort:la,onClearState:Fe}),t.jsx(Ui,{open:Zt!==null,onOpenChange:s=>{s||It(null)},targetBranch:Zt??"",changedFileCount:y?.files?.length??0,onCommitAndSwitch:async(s,n)=>{const l=Zt;if(!l||!r)return;const d=y?.current??null;await a.createGitCommit(r,s,{addAll:!0}),ae(r);let N=null;if(n){const C=W.read?.repository.remotes.map(U=>U.name)??ke.map(U=>U.name),D=d?Lo(d,y?.tracking,C,W.contexts[0]?.primaryRemote??C[0]??null):null;try{if(!D||!d)throw new Error(e("mobile.changes.noRemote"));await bi({directory:r,branch:d,remoteName:D.remoteName,sourceControl:f,git:a,choose:p.choose,destinationRef:D.destinationRef}),N=D.remoteName}catch(U){console.error("Push after commit failed:",U),g.error(e("gitView.dirtySwitch.pushFailed")),await re(),await de(),It(null);return}}g.success(N?e("gitView.toast.pushedToUpstream",{name:N}):d?e("gitView.dirtySwitch.committedNotPushed",{branch:d}):e("gitView.toast.commitCreated")),await re(),await de(),It(null),await Os(l)},onGenerateMessage:async()=>{if(!r)return"";const s=(y?.files??[]).map(d=>d.path).sort(),{message:n}=await Er(r,s),l=n.subject?.trim()??"";if(l&&Ct&&pt.length>0){const d=Zr(l,pt);if(d&&!l.startsWith(d.code)&&!l.startsWith(d.emoji))return`${d.code} ${l}`}return l},onRevertAndSwitch:async()=>{const s=Zt;if(!s||!r)return;const n=(y?.files??[]).map(d=>d.path);await Mt(n,!0,"all");const l=await a.getGitStatus(r);if(!l.isClean&&(l.files?.length??0)>0){g.error(e("gitView.dirtySwitch.revertIncomplete"));return}It(null),await Os(s)}}),t.jsx(bo,{open:Mn,onOpenChange:Cr,operation:Ps,targetBranch:Ds||Fs,onConfirm:ha})]}):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{nd as GitView};
|
|
4
|
+
`:"";return`${u}${N}${n.join(`
|
|
5
|
+
`)}`.trim()}),Kt()},[Kt]),na=i.useCallback((s,n)=>{const l=n||s;xt(u=>{const N=u.trimStart();return N.startsWith(s)||n&&N.startsWith(n)?u:`${l.endsWith(" ")?l:`${l} `}${u}`.trimStart()}),gr(""),fs(!1)},[]),Ir=i.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")},[]),bt=i.useCallback((s,n)=>{Yt(l=>[...l,{message:s,status:n,timestamp:Date.now()}])},[]),Ge=i.useCallback((s,n)=>{Yt(l=>{if(l.length===0)return l;const u=[...l];return u[u.length-1]={...u[u.length-1],status:s,...n?{message:n}:{}},u})},[]),Pr=i.useCallback(()=>{Yt([])},[]),aa=i.useCallback(()=>{Yt([]),br(null)},[]),es=i.useCallback(async(s,n)=>{if(!r)return;const l=n.kind==="remote"?_.start():null;if(n.kind==="remote"&&!l)return;br(s),Pr();const u=y?.current;let N=n.branch;try{if(N=await Po({directory:r,git:a,target:n,runPlannedFetch:async C=>{if(bt(`Fetching ${C.label}...`,"running"),!y||!l)throw new we("branch-required");if(await Tr({action:"fetch",directory:r,fetchTarget:{remoteName:C.remote,sourceRef:C.sourceRef,destinationRef:C.destinationRef},remoteName:C.remote,status:y,sourceControl:f,git:a,onOperation:l.onOperation}),!l.isCurrent())throw new we("stale-runtime");Ge("done",`Fetched ${C.label}`)}}),l&&!l.isCurrent())throw new we("stale-runtime");if(s==="merge"){bt(`Merging ${n.label} into ${u}...`,"running");const C=await a.merge(r,{branch:N});C.conflict?(Ge("error","Merge conflicts detected"),Je(C.conflictFiles??[],"merge")):(Ge("done",`Merged ${n.label} into ${u}`),Fe(),bt("Refreshing repository status...","running"),await re(),await ue(),Ge("done","Repository status updated"))}else{bt(`Rebasing ${u} onto ${n.label}...`,"running");const C=await a.rebase(r,{onto:N});C.conflict?(Ge("error","Rebase conflicts detected"),Je(C.conflictFiles??[],"rebase")):(Ge("done",`Rebased ${u} onto ${n.label}`),Fe(),bt("Refreshing repository status...","running"),await re(),await ue(),Ge("done","Repository status updated"))}}catch(C){if(Ir(C))Ge("error","Uncommitted changes detected"),An(s),On(N),En(n.label),Cr(!0);else{const D=C instanceof we?e("gitView.toast.syncActionFailed",{action:e("gitView.sync.fetch")}):C instanceof Error?C.message:s==="merge"?`Failed to merge ${n.label}`:`Failed to rebase onto ${n.label}`;Ge("error",D)}}finally{l?.finish()}},[r,a,f,y,_,re,ue,Ir,Je,Fe,bt,Ge,Pr,e]),ia=i.useCallback(s=>{es("merge",s)},[es]),oa=i.useCallback(s=>{es("rebase",s)},[es]),la=i.useCallback(async()=>{if(r)try{Qt==="merge"?(await a.abortMerge(r),g.success(e("gitView.toast.mergeAborted"))):(await a.abortRebase(r),g.success(e("gitView.toast.rebaseAborted"))),Fe(),await re(),await ue()}catch(s){const n=s instanceof Error?s.message:`Failed to abort ${Qt}`;g.error(n)}},[r,a,Qt,re,ue,Fe,e]),ca=i.useMemo(()=>(y?.files??[]).filter(Gs).length,[y?.files]),ua=i.useCallback(async()=>{if(r)try{const s=!!y?.mergeInProgress?.head,n=!!(y?.rebaseInProgress?.headName||y?.rebaseInProgress?.onto);if(s){const l=await a.continueMerge(r);l.conflict?(Je(l.conflictFiles??[],"merge"),g.error(e("gitView.toast.mergeConflictsDetected"))):(Fe(),g.success(e("gitView.toast.mergeCompleted")),await re(),await ue())}else if(n){const l=await a.continueRebase(r);l.conflict?(Je(l.conflictFiles??[],"rebase"),g.error(e("gitView.toast.rebaseConflictsDetected"))):(Fe(),g.success(e("gitView.toast.rebaseStepCompleted")),await re(),await ue())}}catch(s){const n=s instanceof Error?s.message:e("gitView.toast.continueOperationFailed");g.error(n)}},[r,a,y,re,ue,Je,Fe,e]),da=i.useCallback(async()=>{if(r)try{!!y?.mergeInProgress?.head?(await a.abortMerge(r),g.success(e("gitView.toast.mergeAborted"))):(await a.abortRebase(r),g.success(e("gitView.toast.rebaseAborted"))),Fe(),await re(),await ue()}catch(s){const n=s instanceof Error?s.message:e("gitView.toast.abortOperationFailed");g.error(n)}},[r,a,y,re,ue,Fe,e]),ma=i.useCallback(()=>{if(!r)return;const n=!!y?.mergeInProgress?.head?"merge":"rebase",l=(y?.files??[]).filter(Gs).map(u=>u.path);l.length>0&&Vt(l),Rt(n),wt(!0)},[r,y]),ha=i.useCallback(async s=>{if(!r)return;const n=y?.current,l=Ps,u=Fs,N=Ds||u,C=(y?.files??[]).some(Zr);try{await a.stash(r,{message:`Auto-stash before ${l} with ${N}`,includeUntracked:!0}),C&&ae(r)}catch(ie){const ze=ie instanceof Error?ie.message:"Failed to stash changes";g.error(ze);return}let D=!1,K=!1;try{if(l==="merge"){const ie=await a.merge(r,{branch:u});ie.conflict?(K=!0,Vt(ie.conflictFiles??[]),Rt("merge"),wt(!0)):(D=!0,g.success(e("gitView.toast.mergedIntoBranch",{branch:N,currentBranch:n||""})))}else{const ie=await a.rebase(r,{onto:u});ie.conflict?(K=!0,Vt(ie.conflictFiles??[]),Rt("rebase"),wt(!0)):(D=!0,g.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:n||"",branch:N})))}if(s&&D)try{await a.stashPop(r),ae(r),g.success(e("gitView.toast.stashedRestored"))}catch(ie){const ze=ie instanceof Error?ie.message:e("gitView.toast.restoreStashFailed");g.error(ze)}else s&&K&&g.info(e("gitView.toast.restoreStashManually"));await re(),await ue()}catch(ie){if(s)try{await a.stashPop(r),ae(r)}catch{}throw ie}},[ae,r,a,y,Ps,Fs,Ds,re,ue,e]),fa=i.useCallback(s=>{mn(s),r&&(Be(r,s),$(r,a,s))},[r,$,a,Be]),ga=i.useCallback(s=>{Fn(s)},[]),pa=i.useCallback(()=>{Jt(null),r&&(Q(r,a),Z(r,a),$(r,a,Ie))},[r,Q,Z,$,Ie,a]),xa=i.useCallback(s=>{if(s.conflict){if(s.operation==="cherry-pick"||s.operation==="revert"){g.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:s.conflictFiles?.join(", ")??"unknown files"})}),r&&(Q(r,a),Z(r,a),$(r,a,Ie));return}Je(s.conflictFiles??[],s.operation)}},[e,Je,r,Q,Z,$,Ie,a]);return d?ln?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[ms?null:t.jsx(E,{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(ms?"gitView.toast.refreshRepositoryFailed":"gitView.empty.worktreeSetupInProgress")}),ms?t.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-3",onClick:()=>{ye&&B({directory:ye,status:"refreshing"})},children:e("gitView.empty.retryDiscovery")}):t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):J===null||J===!0&&!y?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(E,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):J===!1?t.jsx(Ai,{root:d,rootIsGitRepo:A,resolvedIsGitRepo:J,nestedRepos:O,onRetryDiscovery:()=>{d&&He(d,{force:!0})},emptyStateFooter:te.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:me("flex h-full flex-col overflow-hidden"),children:[t.jsx(Oi,{directory:r??"",status:y,localBranches:Ft,remoteBranches:Dt,branchInfo:oe?.branches,syncAction:_.entry?.executing?nr:null,operationBlocked:_.blocked,remotes:ke,onFetch:s=>Pt("fetch",s),onPull:s=>Pt("pull",s),onSync:s=>Pt("sync",s),onPublish:()=>{Pt("publish")},onChooseSyncTargets:()=>{Pt("sync",void 0,!0)},onRemoveRemote:Gn,removingRemoteName:kn,onCheckoutBranch:$n,onCreateBranch:Hn,onRenameBranch:_n,activeIdentityProfile:Jn,availableIdentities:qn,onSelectIdentity:Wn,isApplyingIdentity:hn,identityAttention:Xe,identityApplicability:Ze,onConfigureRepository:w.isVSCode?void 0:()=>_e(!0),onIdentityMenuOpen:()=>{et(f,j.map(s=>s.account))},isWorktreeMode:!!se,onOpenHistory:()=>Jt("history"),onOpenGraph:()=>Jt("graph"),onOpenStashes:ta,onOpenUpdateBranch:Rr?()=>pr(!0):void 0,onOpenReintegrateCommits:nt?()=>xr(!0):void 0,pullRequest:fe?.changeRequest??fe?.pr??null,pullRequestProvider:fe?.changeRequest?.provider??null,prChecks:fe?.ci?.summary??fe?.checks??null,onOpenPullRequest:r?()=>Ye(r,"pr"):void 0,repositoryOptions:r!==d&&Array.isArray(O)?O:void 0,selectedRepository:r!==d?r:null,onSelectRepository:r!==d&&d?s=>zt(d,s):void 0,repositoryRoot:r!==d?d:void 0}),w.isVSCode?null:t.jsx(zi,{open:Qe,onOpenChange:_e,directory:o?r??"":""}),t.jsx(Ei,{className:"mx-4 mt-3",entry:_.entry,onRefresh:()=>{_.refresh()},onCancel:()=>{_.cancel()}}),d&&(y?.mergeInProgress?.head||y?.rebaseInProgress?.headName||y?.rebaseInProgress?.onto)&&t.jsx(Hi,{mergeInProgress:y?.mergeInProgress,rebaseInProgress:y?.rebaseInProgress,onContinue:ua,onAbort:da,onResolveWithAI:ma,conflictCount:ca,isLoading:c}),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:me("min-w-0 min-h-0 h-full flex flex-col"),children:t.jsx(tn,{as:wi,ref:rr,outerClassName:"flex-1 min-h-0",className:me("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:(st?.length??0)>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(_i,{groups:sa,diffStats:y?.diffStats,revertingPaths:ys,isRevertingAll:ws,onVisiblePathsChange:cn,onRevertAll:Zn,onRevertDirectory:ea,headerBackgroundClassName:"bg-background"})}),t.jsx($i,{stagedCount:Yn,commitMessage:Nt,onCommitMessageChange:xt,generatedHighlights:bs,onInsertHighlights:ra,onGenerateMessage:zn,isGeneratingMessage:yn,onCommit:()=>Sr({pushAfter:!1}),onCommitAndPush:()=>Sr({pushAfter:!0}),commitAction:ar,networkOperationBlocked:_.blocked,hasPendingIndexMutation:wn,gitmojiEnabled:Ct,onOpenGitmojiPicker:()=>fs(!0)})]}):t.jsx(ao,{onOpenStashes:()=>gs(!0)})})})})})}),t.jsx(mt,{open:Sn,onOpenChange:s=>{!s&&wr!==null||pr(s)},children:t.jsxs(ht,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(gt,{children:e("gitView.branch.updateTitle")}),t.jsxs(vt,{children:[e("gitView.branch.updateDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:y?.current??""}),"."]})]}),Rr?t.jsx(vo,{mode:"bare",currentBranch:y?.current,localBranches:Ft,remoteBranches:Kn,defaultTargetBranch:Un,onMerge:ia,onRebase:oa,disabled:Qn||_.blocked,isOperating:wr!==null,operationLogs:Vn,onOperationComplete:aa}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})]})}),t.jsx(mt,{open:Nn,onOpenChange:xr,children:t.jsxs(ht,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(gt,{children:e("gitView.integrate.title")}),t.jsx(vt,{children:nt?t.jsxs("span",{className:"font-mono text-foreground",children:[nt.sourceBranch," → ",hr]}):null})]}),nt?t.jsx(ro,{repoRoot:nt.repoRoot,sourceBranch:nt.sourceBranch,worktreeMetadata:nt.worktreeMetadata,localBranches:Ft,defaultTargetBranch:hr,refreshKey:pn,showHeader:!1,onRefresh:()=>{r&&(Q(r,a),Z(r,a),$(r,a,Ie))}},nt.worktreeMetadata.path):null]})}),t.jsx(mt,{open:ge!==null,onOpenChange:s=>{s||Jt(null)},children:t.jsxs(ht,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx(gt,{children:e(ge==="graph"?"gitView.graph.title":"gitView.history.title")}),t.jsxs(U,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:()=>{if(ge==="graph"){Bn(s=>s+1);return}r&&$(r,a,Ie)},disabled:ge==="graph"?Rs:I,title:e("gitView.history.refresh"),"aria-label":e("gitView.history.refresh"),children:[t.jsx(E,{name:"refresh",className:me("size-4",(ge==="graph"?Rs:I)&&"animate-spin")}),e("gitView.history.refresh")]})]}),t.jsx(vt,{children:e("gitView.history.dialogDescription")})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(go,{mode:ge==="graph"?"graph":"history",log:ge==="graph"?Pn??le:le,isLogLoading:ge==="graph"&&Rs||I,logMaxCount:ge==="graph"?Is:Ie,onLogMaxCountChange:ge==="graph"?ga:fa,expandedCommitHashes:Ss,onToggleCommit:Ln,commitFilesMap:Ut,loadingCommitHashes:qt,onCopyHash:Tn,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ge==="graph"?null:Cn,onConflict:ge==="graph"?xa:void 0,onActionSuccess:ge==="graph"?pa:void 0})})]})}),t.jsx(no,{open:dn,onOpenChange:gs,directory:r,hasUncommittedChanges:(y?.files?.length??0)>0,hasStagedChanges:Ce.length>0,uncommittedFileCount:y?.files?.length??0,onChanged:async s=>{r&&s?.affectsIndex&&ae(r),await re(!1),await ue()}}),t.jsx(mt,{open:un,onOpenChange:fs,children:t.jsxs(ht,{className:"max-w-md p-0 overflow-hidden",children:[t.jsx(ft,{className:"px-4 pt-4",children:t.jsx(gt,{children:e("gitView.gitmoji.title")})}),t.jsxs(Us,{className:"h-[420px]",shouldFilter:!1,children:[t.jsx(qs,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:fr,onValueChange:gr}),t.jsxs(Js,{children:[t.jsx(Ys,{children:e("gitView.gitmoji.empty")}),t.jsx(ns,{children:Lt(pt,fr,s=>[s.code,s.description,s.emoji]).map(s=>t.jsxs(as,{onSelect:()=>na(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))})]})]})]})}),H.context?t.jsx(Ti,{context:H.context,onSelect:H.settle}):null,H.confirmDialog,t.jsx(Li,{candidates:p.candidates,onSelect:p.settle}),r&&t.jsx(Wi,{open:Rn,onOpenChange:wt,conflictFiles:In,directory:r,operation:Qt,onAbort:la,onClearState:Fe}),t.jsx(Ki,{open:Xt!==null,onOpenChange:s=>{s||It(null)},targetBranch:Xt??"",changedFileCount:y?.files?.length??0,onCommitAndSwitch:async(s,n)=>{const l=Xt;if(!l||!r)return;const u=y?.current??null;await a.createGitCommit(r,s,{addAll:!0}),ae(r);let N=null;if(n){const C=W.read?.repository.remotes.map(K=>K.name)??ke.map(K=>K.name),D=u?Lo(u,y?.tracking,C,W.contexts[0]?.primaryRemote??C[0]??null):null;try{if(!D||!u)throw new Error(e("mobile.changes.noRemote"));await bi({directory:r,branch:u,remoteName:D.remoteName,sourceControl:f,git:a,choose:p.choose,destinationRef:D.destinationRef}),N=D.remoteName}catch(K){console.error("Push after commit failed:",K),g.error(e("gitView.dirtySwitch.pushFailed")),await re(),await ue(),It(null);return}}g.success(N?e("gitView.toast.pushedToUpstream",{name:N}):u?e("gitView.dirtySwitch.committedNotPushed",{branch:u}):e("gitView.toast.commitCreated")),await re(),await ue(),It(null),await Os(l)},onGenerateMessage:async()=>{if(!r)return"";const s=(y?.files??[]).map(u=>u.path).sort(),{message:n}=await Er(r,s),l=n.subject?.trim()??"";if(l&&Ct&&pt.length>0){const u=Xr(l,pt);if(u&&!l.startsWith(u.code)&&!l.startsWith(u.emoji))return`${u.code} ${l}`}return l},onRevertAndSwitch:async()=>{const s=Xt;if(!s||!r)return;const n=(y?.files??[]).map(u=>u.path);await Mt(n,!0,"all");const l=await a.getGitStatus(r);if(!l.isClean&&(l.files?.length??0)>0){g.error(e("gitView.dirtySwitch.revertIncomplete"));return}It(null),await Os(s)}}),t.jsx(bo,{open:Mn,onOpenChange:Cr,operation:Ps,targetBranch:Ds||Fs,onConfirm:ha})]}):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{au as GitView};
|