@yuriai/web 0.3.8-beta.2 → 0.3.8-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentAvatar-CzUo20cq.js → AgentAvatar-DN2h46UB.js} +1 -1
- package/dist/assets/{AgentSelector-BYe6JxpS.js → AgentSelector-VZpFxBH7.js} +1 -1
- package/dist/assets/ArchivedSessionsDialog-D7K1Z5JI.js +1 -0
- package/dist/assets/{AssistantConversationSurface-D9pxE0LL.js → AssistantConversationSurface-EqP5FB7k.js} +3 -3
- package/dist/assets/{AssistantSessionCard-UpViUHNh.js → AssistantSessionCard-C2p8COCi.js} +2 -2
- package/dist/assets/{AssistantUnreadBadge-Cu11SA54.js → AssistantUnreadBadge-BvTKd5sA.js} +1 -1
- package/dist/assets/AssistantView-D43teN1N.js +1 -0
- package/dist/assets/{AssistantWorkingAvatar-DXpA53IL.js → AssistantWorkingAvatar-DOrQbxXG.js} +1 -1
- package/dist/assets/{AssistantsSettingsPage-DgB1NmO5.js → AssistantsSettingsPage-Dqt3YxgP.js} +1 -1
- package/dist/assets/{BinaryFileFallback-DXA8nGbU.js → BinaryFileFallback-D4F_a4x6.js} +1 -1
- package/dist/assets/{BtwPanel-DkoRSk96.js → BtwPanel-NFzBgkq4.js} +2 -2
- package/dist/assets/{BusyDots-BJ7g-GAZ.js → BusyDots-BKnqBO3c.js} +2 -2
- package/dist/assets/ChatContainer-FcYVT-8C.js +65 -0
- package/dist/assets/{ChatView-Dg7Q_Wwt.js → ChatView-BzbEnpmC.js} +3 -3
- package/dist/assets/{DiagramView-eNKpLrSw.js → DiagramView-x9cCLpoQ.js} +1 -1
- package/dist/assets/{DiffView-B-Y0Knyh.js → DiffView-B5kteUBL.js} +2 -2
- package/dist/assets/{DiffViewToggle-BmJbap6o.js → DiffViewToggle-BWRB6tX0.js} +1 -1
- package/dist/assets/{ErrorBoundary-DGeC8hrR.js → ErrorBoundary-DFqo_Obv.js} +1 -1
- package/dist/assets/{FadeInOnReveal-D6FCXnEi.js → FadeInOnReveal-Cu3lf-bj.js} +1 -1
- package/dist/assets/{GuiPluginMount-CYYTSXpA.js → GuiPluginMount-BbxIxrdn.js} +1 -1
- package/dist/assets/{GuiPluginPage-B7UFo1YT.js → GuiPluginPage-DuL5L6gw.js} +1 -1
- package/dist/assets/{GuiPluginSurface-DFOsSAf1.js → GuiPluginSurface-BMGxd2e-.js} +1 -1
- package/dist/assets/{GuiPluginTitlebarItems-Cr4QSCKu.js → GuiPluginTitlebarItems-C7GY1ukp.js} +1 -1
- package/dist/assets/{GuiPluginWindow-DzXnwUM0.js → GuiPluginWindow-OqE882lG.js} +1 -1
- package/dist/assets/{Icon-Bj9hTMjF.js → Icon-BWc3icuX.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-Ugc-GANq.js → ImageLoadingPlaceholder-m4EUQ28B.js} +1 -1
- package/dist/assets/{LoadingImage-uYHHT_VX.js → LoadingImage-PnDPgkUI.js} +1 -1
- package/dist/assets/{MarkdownRenderer-1X8XlOwN.js → MarkdownRenderer-BFiNn3mD.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-CIX7kNlF.js → MarkdownRendererImpl-D3kANU0h.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-hHcz8MiN.js → MarkstreamRendererImpl-Ck0jOf70.js} +1 -1
- package/dist/assets/{MobileAssistantSettingsPage-CHcRJtXv.js → MobileAssistantSettingsPage-Bd-zo6fz.js} +1 -1
- package/dist/assets/{MobileAssistantTab-BO5SDNo5.js → MobileAssistantTab-YgKv3VxU.js} +1 -1
- package/dist/assets/{MobileBtwPage-CBAt4xS7.js → MobileBtwPage-BGExzEbM.js} +1 -1
- package/dist/assets/{MobileChangesSurface-DSryfzt8.js → MobileChangesSurface-CUB_wwOP.js} +1 -1
- package/dist/assets/{MobileChatScreen-CGk04i3r.js → MobileChatScreen-CsqyikJv.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-CIqxaASf.js → MobileDetailNavigation-DWZMp7wx.js} +1 -1
- package/dist/assets/{MobileFilesSurface-k1QgAZSz.js → MobileFilesSurface-BNKtecMx.js} +2 -2
- package/dist/assets/{MobileHtmlNetworkBoundary-wYqNGLbr.js → MobileHtmlNetworkBoundary-BO1iXjaf.js} +2 -2
- package/dist/assets/{MobileOverlayPanel-DH89DhXZ.js → MobileOverlayPanel-CY0YwEKs.js} +1 -1
- package/dist/assets/{MobileResizableSheet-BFNJaq9p.js → MobileResizableSheet-bd8BfSwf.js} +1 -1
- package/dist/assets/{MobileSettingsTab-Bs9qRYqM.js → MobileSettingsTab-D9SHNRwh.js} +1 -1
- package/dist/assets/{MobileShareBridge-DY3Lzf8x.js → MobileShareBridge-Plah5Nlx.js} +2 -2
- package/dist/assets/{MobileSurface-CCGzDCA8.js → MobileSurface-BqBct2gx.js} +1 -1
- package/dist/assets/{MobileTabPageHeader-CFaFn4mL.js → MobileTabPageHeader-D0PSwgh4.js} +1 -1
- package/dist/assets/{ModelLogo-Clc0TbVa.js → ModelLogo-ByJxd2UP.js} +1 -1
- package/dist/assets/{ModelSelector-Bzdl6__F.js → ModelSelector-DEMvpId-.js} +1 -1
- package/dist/assets/{MultiRunWindow-BI8M6MMJ.js → MultiRunWindow-BrnUHkhT.js} +1 -1
- package/dist/assets/{OnboardingScreen-CnQxeBTb.js → OnboardingScreen-BPbf-vae.js} +1 -1
- package/dist/assets/{OverlayScrollbar-DxWbQtPi.js → OverlayScrollbar-AzYrDKck.js} +1 -1
- package/dist/assets/{PierreDiffViewer-eVvrzbhm.js → PierreDiffViewer-DE4xQXlS.js} +1 -1
- package/dist/assets/{ProviderLogo-2q99kcs0.js → ProviderLogo-B6heKBib.js} +1 -1
- package/dist/assets/{RemoteAssistantSessionCard-DQzIrlZD.js → RemoteAssistantSessionCard-DOBS9ue2.js} +1 -1
- package/dist/assets/{RemoteDesktopPanel-5Hy1Vul9.js → RemoteDesktopPanel-8KGBizsD.js} +1 -1
- package/dist/assets/{ScheduledTasksDialog-CU-96_KI.js → ScheduledTasksDialog-cMix32JO.js} +1 -1
- package/dist/assets/{ScrollableOverlay-B6nm-QHe.js → ScrollableOverlay-Db594s2Q.js} +1 -1
- package/dist/assets/{SettingsGroup-VX5EIcdB.js → SettingsGroup-Bx1ZKyzt.js} +1 -1
- package/dist/assets/SettingsView-CXp4ystw.js +29 -0
- package/dist/assets/{SettingsWindow-CjVC__o_.js → SettingsWindow-CS3JHQa9.js} +1 -1
- package/dist/assets/{SetupTourDialog-Cd4anq2F.js → SetupTourDialog-DRe6I66o.js} +1 -1
- package/dist/assets/{SyncActions-CA80mSXn.js → SyncActions-CN9DLTjg.js} +1 -1
- package/dist/assets/{TerminalView-Cy3tfVjh.js → TerminalView-YI_IFeOt.js} +2 -2
- package/dist/assets/{TextSelectionMenu-C3G3QdRe.js → TextSelectionMenu-UsTzG0r3.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BUGnb_Yu.js → ToolOutputDialog-C5RTJaQw.js} +1 -1
- package/dist/assets/{YuriLogo-1yVZFnVN.js → YuriLogo-C7P98W3m.js} +1 -1
- package/dist/assets/YuriWordmark-CqWOXOaU.js +1 -0
- package/dist/assets/{assistantMessagePreview-DMQN3Gwb.js → assistantMessagePreview-L6eUvu3u.js} +1 -1
- package/dist/assets/{assistantQueries-3TdsxIwK.js → assistantQueries-CPYvIYND.js} +1 -1
- package/dist/assets/{auto-read-context-BFDDD6Nm.js → auto-read-context-DTwWW3zG.js} +1 -1
- package/dist/assets/{capgoAdapter-Bw37IoVM.js → capgoAdapter-D_vHi-sB.js} +1 -1
- package/dist/assets/{card-ZDEmL6t1.js → card-Cq6UwwN7.js} +1 -1
- package/dist/assets/{chatUpwardIntent-BB-rCDpI.js → chatUpwardIntent-C_n-X11y.js} +1 -1
- package/dist/assets/{checkbox-B0zYfEMl.js → checkbox-OdKCedfo.js} +1 -1
- package/dist/assets/client-A12QacVZ.js +7 -0
- package/dist/assets/{collapsible-BOWyQRZn.js → collapsible-Dh-IbYbQ.js} +1 -1
- package/dist/assets/connection-hint-B1Ya7Hgo.js +2 -0
- package/dist/assets/{context-menu-BK6NbucI.js → context-menu-BtIkrnj2.js} +1 -1
- package/dist/assets/desktopRelayRestore-DtGRUKC-.js +1 -0
- package/dist/assets/{diagram-DYl1ElOP.js → diagram-BA_hzsDn.js} +1 -1
- package/dist/assets/{dialog-kKHr6l0I.js → dialog-y7FwO2zG.js} +1 -1
- package/dist/assets/{dropdown-menu-NxiXa_EI.js → dropdown-menu-hX2yxn_J.js} +1 -1
- package/dist/assets/es-BP-mxEdS.js +15 -0
- package/dist/assets/{fileMentionTouchSelection-DWX5kpzC.js → fileMentionTouchSelection-F8RWr9zY.js} +1 -1
- package/dist/assets/fr-DBPFf_Ut.js +13 -0
- package/dist/assets/{gitApi-OVA3TAy3.js → gitApi-Czkb5T4C.js} +4 -4
- package/dist/assets/gitApiHttp-BLNjaxGv.js +3 -0
- package/dist/assets/{i18n-Sh2Qk9nD.js → i18n-DVQ9uTj5.js} +1 -1
- package/dist/assets/{icons-BpK9iAgA.js → icons-DYqQRods.js} +1 -1
- package/dist/assets/{input-CoI-IWJg.js → input-LFbBkZKd.js} +1 -1
- package/dist/assets/{insertionBoundaries-Bw6mz-QZ.js → insertionBoundaries-BZCe_D61.js} +1 -1
- package/dist/assets/ja-DfRNowd3.js +15 -0
- package/dist/assets/{kbd-Cvn5LQY3.js → kbd-VGSm8i9A.js} +1 -1
- package/dist/assets/ko-BWjwsiJd.js +15 -0
- package/dist/assets/main-C5ruSn_v.css +1 -0
- package/dist/assets/main-DdVb62t7.js +169 -0
- package/dist/assets/main-HUM5oaky.js +2 -0
- package/dist/assets/{markdownHeightCache-CknUtMlX.js → markdownHeightCache-0rdQ-3rh.js} +1 -1
- package/dist/assets/{mcpQueries-B3bAYBwV.js → mcpQueries-DV3-sWaq.js} +1 -1
- package/dist/assets/miniChat-DKFz8eoy.js +2 -0
- package/dist/assets/mobile-CWgivYEi.js +2 -0
- package/dist/assets/{mobileBackNavigation-oDcLGmHp.js → mobileBackNavigation-NOTJBxWS.js} +1 -1
- package/dist/assets/{mobileConnections-CBqRp-3T.js → mobileConnections-BsUCpYHe.js} +2 -2
- package/dist/assets/{multirun-CS8jFKDn.js → multirun-MALnx6yM.js} +1 -1
- package/dist/assets/{native-config-zrhK__rU.js → native-config-BSqhW0M6.js} +1 -1
- package/dist/assets/{nativeComposerCover-MPlMSBBX.js → nativeComposerCover-CD89B9_e.js} +1 -1
- package/dist/assets/{navigation-CkCH8e3H.js → navigation-CbioEJJj.js} +1 -1
- package/dist/assets/{openRemoteProjectSession-BbAkznDS.js → openRemoteProjectSession-Bo1j0WuT.js} +1 -1
- package/dist/assets/{openSessionFromDeepLink-qg52CXP9.js → openSessionFromDeepLink-Cjor8Gff.js} +2 -2
- package/dist/assets/pl-CToREN9u.js +15 -0
- package/dist/assets/{pluginPresentation-DkI5wY0D.js → pluginPresentation-DXlGcBhp.js} +1 -1
- package/dist/assets/pt-BR-CFbLdTxz.js +15 -0
- package/dist/assets/pwa-C_uxO0ld.js +2 -0
- package/dist/assets/queue-abort-optimistic-hktBb53r.js +1 -0
- package/dist/assets/{quota-jMPnmJTS.js → quota-CJictN-Z.js} +1 -1
- package/dist/assets/{reference-history-BJ9mAdW1.js → reference-history-B9IC2ofg.js} +1 -1
- package/dist/assets/remoteProjectQueries-Dq2vrCZs.js +1 -0
- package/dist/assets/{remoteSessionReference-DICMQab5.js → remoteSessionReference-Cqadrc7j.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-D_crcFe0.js → renderElectronMiniChatApp-C7MdxVFm.js} +2 -2
- package/dist/assets/{renderMobileApp-DYGufF-U.js → renderMobileApp-BCtmTuHR.js} +5 -5
- package/dist/assets/{runtimeConfig-AnrhVRkF.js → runtimeConfig-Cna7GNw_.js} +1 -1
- package/dist/assets/runtimeEndpointReset-BvxTzvn2.js +4 -0
- package/dist/assets/{select-COAwWxv-.js → select-B76OY5V2.js} +1 -1
- package/dist/assets/{sessionLookup-BtXyFcKe.js → sessionLookup-BLGieisF.js} +1 -1
- package/dist/assets/{sessionOwnership-Ck4bRAGZ.js → sessionOwnership-CBvrg1yB.js} +1 -1
- package/dist/assets/shortcuts-Db6EAojs.js +1 -0
- package/dist/assets/{sortable-tabs-strip-Duxo9Ip3.js → sortable-tabs-strip-74dWtnXq.js} +1 -1
- package/dist/assets/{speechSettingsQueries-CqamPgA0.js → speechSettingsQueries-Ca8URC1I.js} +1 -1
- package/dist/assets/src-7dXqzKwf.css +2 -0
- package/dist/assets/store-BmXGGNvt.js +17 -0
- package/dist/assets/{switch-CjaNqGBY.js → switch-DwtpxW8C.js} +1 -1
- package/dist/assets/{terminalApi-wdwb9MVG.js → terminalApi-DpnhkNX3.js} +1 -1
- package/dist/assets/{textarea-B0VZhgml.js → textarea-PTl0FSdz.js} +1 -1
- package/dist/assets/{timeFormat-BaiPCZgf.js → timeFormat-DXqVWLO8.js} +1 -1
- package/dist/assets/{tooltip-vDrp4bzq.js → tooltip-Chw-EXbL.js} +1 -1
- package/dist/assets/{truncated-path-CrzP3UBz.js → truncated-path-CueIHITN.js} +1 -1
- package/dist/assets/{types-D4sSimuj.js → types-BsJ5ofX_.js} +1 -1
- package/dist/assets/ui-Cvgk-VfB.js +13 -0
- package/dist/assets/uk-B-pZbaGp.js +15 -0
- package/dist/assets/useAppFontEffects-BYlC53hw.js +7 -0
- package/dist/assets/{useDesktopWindowControlsLayout-C9oYWUK2.js → useDesktopWindowControlsLayout-CToUoXe1.js} +1 -1
- package/dist/assets/{useDictation-83-qDgkn.js → useDictation-CsFtaf0U.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-DoR6gkPG.js → useEffectiveDirectory-sTPCrg3E.js} +1 -1
- package/dist/assets/{useGitStore-Tb4ovphQ.js → useGitStore-D8EHlPG5.js} +1 -1
- package/dist/assets/{useInlineCommentDraftStore-4A4nJ3nE.js → useInlineCommentDraftStore-7Q2pyuSV.js} +1 -1
- package/dist/assets/{useMcpConfigStore-DzP-AJLe.js → useMcpConfigStore-MUpLRoix.js} +1 -1
- package/dist/assets/{useMobileSwipeActions-BoaPQqab.js → useMobileSwipeActions-3fE3ZDIW.js} +1 -1
- package/dist/assets/{useMobileTranscriptSyncHint-B3mZDzht.js → useMobileTranscriptSyncHint-WvWB8Qzh.js} +2 -2
- package/dist/assets/{useModelLists-QXDxo5Ac.js → useModelLists-B0WY2vxY.js} +1 -1
- package/dist/assets/{useOpenCodeReadiness-CPwbuznT.js → useOpenCodeReadiness-DHd_J4Qt.js} +1 -1
- package/dist/assets/usePluginsStore-D6JIxDEW.js +1 -0
- package/dist/assets/{useProjectGitActions-7id8Rqeg.js → useProjectGitActions-C80i-0SJ.js} +1 -1
- package/dist/assets/{useProjectGitStore-8GteDOkw.js → useProjectGitStore-B-fG3PyR.js} +1 -1
- package/dist/assets/{useProjectRuntimeAPIs-BjRL5EMv.js → useProjectRuntimeAPIs-DA53IKrj.js} +1 -1
- package/dist/assets/{useQuotaStore-CHxR2ZkD.js → useQuotaStore-DHND_ctw.js} +1 -1
- package/dist/assets/{useSessionBtwStore-DDZStXhl.js → useSessionBtwStore-Dqz8innY.js} +2 -2
- package/dist/assets/{useStreamingTextThrottle-B4yaNsPw.js → useStreamingTextThrottle-Caaje_V5.js} +1 -1
- package/dist/assets/{useTerminalStore-C_QzSEgP.js → useTerminalStore-ax8bDQrp.js} +1 -1
- package/dist/assets/{worktreeManager-DmdHIgOn.js → worktreeManager-oPk1TFpI.js} +1 -1
- package/dist/assets/{worktreeSourceBranchPreference-Buq7Vnm1.js → worktreeSourceBranchPreference-D_i6GD56.js} +1 -1
- package/dist/assets/zh-CN-C4Fe2ywz.js +15 -0
- package/dist/assets/zh-TW-DYVOGHAF.js +15 -0
- package/dist/index.html +12 -13
- package/dist/mini-chat.html +12 -13
- package/dist/mobile.html +2 -2
- package/package.json +1 -1
- package/dist/assets/ArchivedSessionsDialog-CfidThGZ.js +0 -1
- package/dist/assets/AssistantView-Cn8EHVTJ.js +0 -1
- package/dist/assets/ChatContainer-Br3bKIVW.js +0 -65
- package/dist/assets/SettingsView-8FgFGfhK.js +0 -29
- package/dist/assets/YuriWordmark-CqkcfAJl.js +0 -1
- package/dist/assets/client-CmtAKi5B.js +0 -7
- package/dist/assets/connection-hint-By7s_PpE.js +0 -2
- package/dist/assets/desktopHosts-COI-czjF.js +0 -1
- package/dist/assets/desktopRelayRestore-BEPNc7qb.js +0 -1
- package/dist/assets/es-C1spVk4O.js +0 -15
- package/dist/assets/fr-yyP7Hlty.js +0 -13
- package/dist/assets/gitApiHttp-ZjM4HkSo.js +0 -3
- package/dist/assets/ja-ChftrfCh.js +0 -15
- package/dist/assets/ko-BrLgX_6B.js +0 -15
- package/dist/assets/main-CAX_GxTi.js +0 -169
- package/dist/assets/main-CFSCPKQq.js +0 -2
- package/dist/assets/main-qSeeJRW1.css +0 -1
- package/dist/assets/miniChat-DCPNrx-v.js +0 -2
- package/dist/assets/mobile-Ck9hV98N.js +0 -2
- package/dist/assets/pl-DlKDQDhl.js +0 -15
- package/dist/assets/pt-BR-BldJPFQ5.js +0 -15
- package/dist/assets/pwa-oKMat1GX.js +0 -2
- package/dist/assets/queue-abort-optimistic-CDuhpG2v.js +0 -1
- package/dist/assets/remoteProjectQueries-BQzoY_Y9.js +0 -1
- package/dist/assets/runtimeEndpointReset-BDoCO-tc.js +0 -4
- package/dist/assets/shortcuts-BFw2eop1.js +0 -1
- package/dist/assets/src-B7qham90.css +0 -2
- package/dist/assets/store-BGuutgkJ.js +0 -17
- package/dist/assets/ui-Pjq_Ygzo.js +0 -13
- package/dist/assets/uk-Cw2L_unr.js +0 -15
- package/dist/assets/useAppFontEffects-CzJ2wyOQ.js +0 -7
- package/dist/assets/usePluginsStore-Cw2anjTl.js +0 -1
- package/dist/assets/zh-CN-BQXjCmNe.js +0 -15
- package/dist/assets/zh-TW-Y0lErpEY.js +0 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/remote-input-store-DPw_n0MZ.js","assets/rolldown-runtime-hePW80VL.js","assets/runtime-switch-DEPKHgdL.js","assets/runtime-auth-DA-qfGHk.js","assets/platform-B2ylz14u.js","assets/runtimeAPIRegistry-C2VogTny.js","assets/pathNormalization-ewtPqJWn.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-zustand-CTekDqaS.js","assets/vendor-base-ui-wXsskyKm.js","assets/prompt-attachment-upload-BzYqZdzd.js","assets/runtime-fetch-V-iMWR8t.js","assets/reasoning-projection-client-BEhVknv9.js","assets/runtime-file-resource-BGZ4tGr5.js","assets/vendor-react-BkccXcWz.js","assets/vendor-tanstack-query-core-BSjXNgF_.js","assets/vendor-tanstack-react-query-DIb_ItL-.js","assets/path-utils-jGozTg9d.js","assets/vendor-reactuses-core-DjKFMfz7.js","assets/vendor-lodash-es-BS45jPoZ.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/summaries-BQMyJaaw.js","assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/runtime-file-store-BVRgEtI-.js","assets/brand-storage-migration-Bhz6UOBJ.js","assets/input-store-CzG_3qFv.js","assets/brand-storage-bootstrap-D4BW3w-M.js","assets/uuid-D-SDZijH.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n}from"./runtime-switch-DEPKHgdL.js";import{a as r}from"./vendor-zustand-CTekDqaS.js";import{ot as i,st as a}from"./vendor-base-ui-wXsskyKm.js";import{St as o}from"./gitApiHttp-ZjM4HkSo.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{Jt as s,R as c,Wt as l,Xt as u,at as d,dr as f,en as p,it as m,n as h,nr as g,on as _,rt as v,tn as y,tr as b}from"./client-CmtAKi5B.js";import{t as x}from"./pathNormalization-ewtPqJWn.js";import{n as S}from"./vendor-react-BkccXcWz.js";import{o as C,s as w}from"./vendor-tanstack-react-query-DIb_ItL-.js";import{A as T,E,I as D,R as O,W as k,k as A}from"./runtime-file-resource-BGZ4tGr5.js";import{r as ee}from"./vendor-reactuses-core-DjKFMfz7.js";import{o as j}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{r as M}from"./useUIStore-68ZPpgYA.js";import{s as N}from"./spacedFileMention-Ds4GtgiF.js";import{An as P,Bn as F,Et as te,Fr as I,Ga as L,Ha as R,Hn as z,Ji as ne,La as re,Lr as ie,Rr as ae,St as B,U as oe,V,Vn as se,W as H,Xi as ce,Xn as U,Xt as le,Zi as ue,_i as de,_t as fe,ar as pe,dr as me,dt as he,f as W,fn as ge,gi as _e,gt as ve,hi as ye,hn as be,ht as xe,ii as Se,io as G,j as Ce,jn as we,mt as Te,ni as Ee,pt as De,qi as Oe,ra as ke,ri as Ae,si as je,t as K,vi as Me,vt as Ne,yi as q,yr as J,zn as Pe,zr as Fe}from"./ui-Pjq_Ygzo.js";import{n as Y}from"./Icon-Bj9hTMjF.js";import{i as Ie,m as Le,n as Re}from"./remoteProjectQueries-BQzoY_Y9.js";import{t as ze}from"./i18n-Sh2Qk9nD.js";import{t as Be}from"./toolHelpers-iEHVHQ9p.js";import{t as Ve}from"./ScrollableOverlay-B6nm-QHe.js";import{t as He}from"./MobileResizableSheet-BFNJaq9p.js";import{a as Ue,i as We,n as Ge,o as Ke,t as qe}from"./dialog-kKHr6l0I.js";import{i as Je,n as Ye,t as Xe}from"./tooltip-vDrp4bzq.js";import{c as Ze,n as Qe,t as $e}from"./dropdown-menu-NxiXa_EI.js";import{n as et}from"./useProjectRuntimeAPIs-BjRL5EMv.js";import{b as tt,p as nt,t as rt,v as it}from"./gitApi-OVA3TAy3.js";import{o as at,t as ot}from"./useProjectGitStore-8GteDOkw.js";import{t as st}from"./input-CoI-IWJg.js";import{t as ct}from"./useDebouncedValue-BHlMPqY8.js";import{t as lt}from"./checkbox-B0zYfEMl.js";import{t as ut}from"./MobileOverlayPanel-DH89DhXZ.js";import{t as dt}from"./githubAuthQueries-3AJp5LD5.js";import{a as ft,i as pt,s as mt,t as ht}from"./worktreeManager-DmdHIgOn.js";import{a as gt,i as _t,n as vt,o as yt,r as bt,t as xt}from"./worktreeSourceBranchPreference-Buq7Vnm1.js";import{s as St}from"./remote-input-store-DPw_n0MZ.js";import{t as Ct}from"./vendor-cmdk-BDWoZLve.js";import{t as wt}from"./sortable-tabs-strip-Duxo9Ip3.js";import{f as Tt,m as Et}from"./auto-read-context-BFDDD6Nm.js";var Dt=2e3,Ot=r((e,t)=>({pending:!1,expiresAt:null,arm:(t=Dt)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),X=e(a(),1),kt=new class{inFlightByScope=new WeakMap;generationByScope=new WeakMap;run(e){let t=this.inFlightByScope.get(e.scope);t||(t=new Map,this.inFlightByScope.set(e.scope,t));let n=t.get(e.key);if(n)return n;let r=this.generationByScope.get(e.scope);r||(r=new Map,this.generationByScope.set(e.scope,r));let i=(r.get(e.key)??0)+1;r.set(e.key,i);let a=e.request(()=>r?.get(e.key)!==i);return t.set(e.key,a),a.finally(()=>{t?.get(e.key)===a&&t.delete(e.key)}).catch(()=>{}),a}},At=e=>C({queryKey:[e.transport,`sessionChildren`,e.generation,x(e.directory),e.sessionID],queryFn:({signal:t})=>e.request(t),staleTime:0,gcTime:6e4,retry:!1}),jt=e=>k.fetchQuery(At(e)),Mt=(e,t)=>e.id<t.id?-1:+(e.id>t.id),Nt=(e,t,n)=>{let r=new Set(e.map(e=>e.id)),i=t.filter(e=>!e?.id||r.has(e.id)||e.parentID!==n?!1:(r.add(e.id),!0));return i.length===0?e:[...e,...i].sort(Mt)},Pt=30,Ft=new Map;function It(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function Lt(e,t){let n=u();if(!n)return!1;let r=n.getTranscript(_(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>Fe()}function Rt(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function zt(e,t,n){let r=[...e.getState().session],i=z.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function Bt(){let e=B(),r=oe(),i=V(),a=(0,X.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),o=(0,X.useCallback)((t,n=e)=>{let r=u();if(!r||!t)return It({kind:`unknown`,loadedTurns:0},!1);let i=_(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return It(a.boundary,o?.status===`loading`)},[e]),c=(0,X.useCallback)((e,t)=>{if(t.length===0)return;let n=i.getChild(e);if(!n)return;let r=n.getState(),a={session_status:{...r.session_status},session_status_observed_at:{...r.session_status_observed_at},session_error_at:{...r.session_error_at},session_diff:{...r.session_diff},todo:{...r.todo},permission:{...r.permission},question:{...r.question}};Pe(a,t),Ce(n,t),n.setState(a);for(let n of t)p(e,n)},[i]),d=(0,X.useCallback)((t=e)=>{let n=Ft.get(t);if(n)return Ft.delete(t),Ft.set(t,n),n;let r=new Set;for(Ft.set(t,r);Ft.size>Pt;){let e=Ft.keys().next().value;if(!e)break;let t=[...Ft.get(e)??[]];Ft.delete(e),c(e,t)}return r},[e,c]),m=(0,X.useCallback)((t,n=e)=>{let a=n===e?r:i.ensureChild(n,{bootstrap:!1}),o=d(n),s=F(a.getState()),l=ie(),f=se({seen:o,keep:t,limit:l,preserve:s});if(c(n,f),ae()){let e=new Set([t,...o,...s]),r=(u()?.getCacheBudget?.().listCanonical({directory:n})??[]).map(e=>e.scope.sessionID),i=(r.length>0?r:Array.from(o)).filter(r=>r===t||e.has(r)?!1:Lt(n,r));if(i.length>0){for(let e of i)o.delete(e);c(n,i)}}},[i,e,d,c,r]),g=(0,X.useCallback)(async(t,n)=>{let a=n?.directory??e;if(!t||!a||a===`global`)return;let o=a===e?r:i.ensureChild(a,{bootstrap:!1}),c=o.getState(),l=c.session_status?.[t],d=c.session_status_observed_at?.[t];try{n?.purpose===`prepend`||n?.before?await s(a,t):await y(a,t,{background:!0})}catch{return}if(n?.isStale?.())return;let f=u()?.getTranscript(_(a,t));be({directory:a,sessionID:t,store:o,transcript:f,isStale:n?.isStale}),await J({directory:a,sessionID:t,store:o,statusBeforePull:l,statusObservedAtBeforePull:d,hasMessages:(f?.messageOrder.length??0)>0,isTailPage:!n?.before,isStale:n?.isStale})},[i,r,e]),v=(0,X.useCallback)(async(t,n)=>{await te();let r=typeof n==`boolean`?n:n?.force,o=typeof n==`object`?n.directory??e:e,s=i.ensureChild(o,{bootstrap:!1}),c=h.getScopedSdkClient(o);m(t,o);let l=a(t,o);return kt.run({scope:s,key:l,request:async e=>{let n=s.getState(),i=u(),a=_(o,t),l=i?.hasSession?.(a)??(i?.getTranscript(a).messageOrder.length??0)>0,d=i?.getPagination(a)?.boundary??{kind:`unknown`,loadedTurns:0},p=z.search(n.session,t,e=>e.id).found,m=i?.getRequestState?.(a);if(!r&&l&&d.kind!==`unknown`&&m?.status!==`error`&&p&&I(o,t)){be({directory:o,sessionID:t,store:s,isStale:e});return}let h=!!(r||!l||p),v=Rt({hasSession:p,shouldLoadMessages:h,force:!!r});await Promise.all([v?(async()=>{try{let n=await ne(async()=>c.session.get({sessionID:t}));if(n&&!e()){let r=Oe(f(n));e()||zt(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),h?g(t,{isStale:e,directory:o}):Promise.resolve()])}})},[i,a,m,g,e]),b=ee(async(r,a)=>{let o=a||e;if(!r||!o)return;let s=i.ensureChild(o,{bootstrap:!1}),c=h.getScopedSdkClient(o),l=n(),u=t(),d=()=>l!==n()||u!==t()||i.getChild(o)!==s,p=await jt({transport:u,generation:l,directory:o,sessionID:r,request:async e=>{let i=[],a=new Set,s;do{if(e.throwIfAborted(),l!==n()||u!==t())throw new DOMException(`Session children runtime changed`,`AbortError`);let d=await c.session.list(s?{cursor:s,limit:50}:{directory:o,parentID:r,limit:50},{signal:e});if(!Array.isArray(d?.data))throw Error(`session.list children returned no data`);if(i.push(...d.data.map(f)),d.data.length<50)break;if(s=d.cursor?.next??void 0,!s||a.has(s))throw Error(`session.list children pagination did not advance`);a.add(s)}while(s);return i}}).catch(e=>{if(d())return null;throw e});!p||d()||s.setState(e=>{let t=Nt(e.session,p,r);return t===e.session?e:{session:t,limit:Math.max(e.limit,t.length)}})}),x=(0,X.useCallback)((t,n)=>{let r=o(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,o]),S=(0,X.useCallback)((t,n)=>o(t,n?.directory??e).loading,[e,o]),C=(0,X.useCallback)((t,n)=>o(t,n?.directory??e).complete,[e,o]),w=(0,X.useCallback)(t=>{let n=t.directory||e;l(_(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),T=(0,X.useCallback)(t=>{let n=t.directory||e;l(_(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),E=(0,X.useCallback)(t=>{let n=t.directory||e;l(_(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),D=ee(async(r,a)=>{if(!r)return;await te();let o=a?.directory??e;if(!o||o===`global`)return;let s=i.ensureChild(o,{bootstrap:!1}),c=n(),l=t(),d=()=>c!==n()||l!==t()||i.ensureChild(o,{bootstrap:!1})!==s,f=s.getState();try{if(await y(o,r),d())return;be({directory:o,sessionID:r,store:s}),await J({directory:o,sessionID:r,store:s,statusBeforePull:f.session_status?.[r],statusObservedAtBeforePull:f.session_status_observed_at?.[r],hasMessages:(u()?.getTranscript(_(o,r)).messageOrder.length??0)>0,isStale:d})}catch{throw Error(`refresh transcript failed`)}});return(0,X.useMemo)(()=>({ensureSessionRenderable:v,syncSession:v,loadChildren:b,hasMore:x,isLoading:S,isComplete:C,refreshSessionTranscript:D,optimistic:{add:w,remove:T,confirm:E}}),[v,b,x,S,C,D,w,T,E])}var Z=S(),Q=i(),Vt=(e,t)=>{if(!e)return t;let n=e.ready&&!e.loading;return{modelsReady:!e.error&&(e.modelsReady??n),agentsReady:!e.error&&(e.agentsReady??n)}},Ht=e=>{let t=e?.variants;if(!t)return[];if(Array.isArray(t)){let e=[],n=new Set;for(let r of t){let t=typeof r==`string`?r:r&&typeof r==`object`&&!Array.isArray(r)&&typeof r.id==`string`?r.id:``;!t||n.has(t)||(n.add(t),e.push(t))}return e}return typeof t==`object`?Object.keys(t):[]},Ut=(e,t,n,r)=>{if(e.providerID!==n||e.modelID!==r||t?.variantsReady===!1)return[];if(t?.variants)return[...t.variants];let i=(t?.providers?.find(e=>e.id===n))?.models?.find(e=>e.id===r);return Ht(i)},Wt=()=>!0,Gt=(e,t)=>(e.commandPolicy??Wt)(t),Kt=X.createContext(null),qt=()=>X.useContext(Kt),Jt=e=>e,Yt=(e,t)=>t??e,Xt=e=>{if(e.kind!==`primary`&&(!e.sessionID||!e.directory||!e.draftKey||!e.transportIdentity||!Number.isSafeInteger(e.runtimeGeneration)||!e.resources||typeof e.resources.busy!=`boolean`||!e.activity||!e.commands||!e.shortcuts))throw Error(`chat-input-secondary-surface-incomplete`)},Zt=(e,t)=>e.kind===`secondary`?e.resources?.busy??!1:t,Qt=e=>!e.sessionID||!e.directory?null:{deliveryTarget:e.deliveryTarget,sessionID:e.queueSessionID??e.sessionID,directory:e.directory,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration},$t=(e,t,n)=>{if(e.kind===`secondary`){if(!e.commands)throw Error(`chat-input-secondary-commands-incomplete`);return e.commands}return e.commands?e.commands:{sessionID:e.sessionID,hasMessages:t,hasNewDraft:n}},en={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},tn=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function nn(e,t){let n=(0,Z.c)(6),r=ve(e??``,t),i=fe(e??``,t),a=he(e??``,t),o=Te(e??``,t),s=xe(e??``,t),c=Ne(t),l;bb0:{if(!e){l=en;break bb0}if(o.length>0||s.length>0){l=en;break bb0}let t=r?.type??`idle`,u=a[a.length-1],d=!!(u&&u.role===`assistant`&&typeof u.time?.completed!=`number`),f=a,p;n[0]!==d||n[1]!==f?(p=tn({messages:f,hasPendingAssistant:d}),n[0]=d,n[1]=f,n[2]=p):p=n[2];let m=p,h=u?.time?.created,g=!!(m&&typeof c==`number`&&typeof h==`number`&&h<=c),_=r!==void 0,v=_&&t!==`idle`,y=v||m&&!g;if(_&&!v&&(!m||_&&!v&&typeof i==`number`&&typeof h==`number`&&h<=i)){l=en;break bb0}if(!y){l=en;break bb0}let b=v?t:`busy`,x=t===`busy`||!v&&m,S;n[3]!==b||n[4]!==x?(S={phase:b,isWorking:!0,isBusy:x,isCooldown:!1},n[3]=b,n[4]=x,n[5]=S):S=n[5],l=S}return l}var rn=`data-mobile-overlay-active`,an=e=>Array.from(e).some(e=>e.getAttribute(rn)!==`false`),on=`artful.bionic.cosmic.disco.focal.groovy.jammy.kinetic.lunar.noble.bold.brave.calm.eager.gentle.happy.keen.lively.merry.swift.warm.wise.bright.clever.daring.agile.crisp.fresh.lucid.quick.sharp.vivid.zealous`.split(`.`),sn=`aardvark.beaver.chipmunk.dolphin.falcon.gopher.hedgehog.jackal.koala.lemur.mongoose.narwhal.otter.pangolin.quokka.raccoon.salamander.toucan.walrus.yak.zebra.badger.condor.dingo.egret.ferret.gecko.heron.iguana`.split(`.`);function cn(){return`${on[Math.floor(Math.random()*on.length)]}-${sn[Math.floor(Math.random()*sn.length)]}`}function ln(e){let t=cn();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}async function un(e,t,n){if(!e.hostId||!e.hubId)throw Error(`Remote Project Host scope is unavailable`);let r=L.getState().remoteSession,i=D(),a=await Re();if(i.assertCurrent(),!a.supported||a.hubId!==e.hubId||!a.projects.some(t=>t.id===e.id&&t.hostId===e.hostId&&t.path===e.path))throw Error(`Remote Project is not referenced by the current Hub`);let o=Ie(a);await o.connectHost(e.hostId);let s=o.resolve({hubId:e.hubId,hostId:e.hostId,directory:e.path}),c=D(s),l=pe(s);if(!await l.checkIsGitRepository(e.path))throw Error(`Worktrees can only be created in Git repositories`);let u=await Ae(e,s),f=u.commands,p=Array.isArray(f)?f.filter(e=>typeof e==`string`&&!!e.trim()).map(t=>je(t.trim(),{rootWorktreePath:e.path})).join(` && `):void 0,h=await l.getGitStatus(e.path),g=await l.getGitBranches(e.path),_=await l.listGitWorktrees(e.path),y=x(e.path),b=_.map(e=>x(e.path)).filter(e=>y===e||y.startsWith(`${e}/`)).sort((e,t)=>t.length-e.length)[0],S=b?y.slice(b.length):``,C=(g.branches?.[h.current]?.tracking||h.tracking)?.replace(/^remotes\//,``).split(`/`)[0],w=t.branchName||t.existingBranch?.replace(/^remotes\//,``),T={...t,...p?{startCommand:p}:{},...C&&w?{setUpstream:t.setUpstream??!0,upstreamRemote:t.upstreamRemote||C,upstreamBranch:t.upstreamBranch||w}:{},returnAfterDirectoryCreated:!1},E=await l.previewGitWorktree(e.path,T);if(!E.path)throw Error(`Remote worktree preview missing path`);let O=_e();q(O).catch(()=>void 0);let k=S?`${E.path.replace(/[\\/]+$/,``)}${S}`:E.path,A={...s.location,directory:k},ee={title:n.title,initialPrompt:n.initialPrompt,bootstrapWaitEnabled:u.wait,defaultModel:e.defaultModel??void 0,pendingWorktreeRequestId:O,bootstrapPendingDirectory:k,preserveDirectoryOverride:!0,bootstrapStatus:{status:`pending`,error:null,updatedAt:Date.now()}};try{n.initialPrompt&&await St(A,n.initialPrompt),c.assertCurrent()}catch(e){throw de(O,e instanceof Error?e:Error(String(e))),e}n.isSelected()&&L.getState().remoteSession===r&&L.getState().openRemoteSession(e,A,null,ee);let M=L.getState().remoteSession,N=M?.draft?.pendingWorktreeRequestId===O,P=()=>{if(!n.isSelected()||!N)return!1;let t=L.getState().remoteSession;return t?.sessionId===null&&t.projectId===e.id&&t.location.hubId===e.hubId&&t.location.hostId===e.hostId&&t.draft?.pendingWorktreeRequestId===O?(M=t,!0):t===M};try{let r=await l.createGitWorktree(e.path,T);if(!r.path||!r.name)throw Error(`Remote worktree create missing name/path`);let i=r.bootstrapStatus,a=Date.now()+12e4;for(;i?.status===`pending`&&u.wait;){if(Date.now()>=a)throw Error(`Remote worktree setup timed out; the existing draft was retained`);await new Promise(e=>setTimeout(e,500)),c.assertCurrent(),i=await l.getGitWorktreeBootstrapStatus(r.path)}if(i?.status===`failed`)throw Error(i.error||`Remote worktree setup failed`);c.assertCurrent();let f=S?`${r.path.replace(/[\\/]+$/,``)}${S}`:r.path,p={...s.location,directory:f},g={pendingWorktreeRequestId:null,bootstrapPendingDirectory:null,worktreeMetadata:{name:r.name,path:f,worktreeRoot:r.path,projectDirectory:e.path,relativePath:S.replace(/^\//,``)||void 0,branch:r.branch,label:r.branch||r.name,source:`sdk`,worktreeSource:`created-for-session`,headState:r.branch?`branch`:`unborn`,worktreeStatus:i?.status===`pending`?`pending`:`ready`,createdFromBranch:n.createdFromBranch||h.current||t.startRef,kind:n.kind??`standard`},bootstrapStatus:u.wait?i??{status:`ready`,error:null,updatedAt:Date.now()}:void 0};if(f!==k){let{getRemoteInputStore:e,remoteSessionDraftKey:t}=await j(async()=>{let{getRemoteInputStore:e,remoteSessionDraftKey:t}=await import(`./remote-input-store-DPw_n0MZ.js`).then(e=>e.a);return{getRemoteInputStore:e,remoteSessionDraftKey:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27])),n=e(p),r=t(A,null),i=n.getState().getDraft(r),a=await n.getState().moveDraftWithAttachments(r,t(p,null),i?.revision);if(i&&!a)throw Error(`Remote draft changed while the worktree target was being finalized; the original draft was retained`);c.assertCurrent()}!n.createSession&&P()&&M&&(L.getState().updateRemoteDraft(M,g,p),M=L.getState().remoteSession),n.createSession||Me(O,f);let _;if(n.createSession)try{let t=o.resolve(p).service(),r=P()?M?.draft?.title??n.title:n.title,i=await t.createSession({title:r},f);_=i.id,c.assertCurrent();let a=await t.getConfig(f).catch(()=>void 0);c.assertCurrent();let s=e.defaultModel||a?.model,l=typeof s==`string`?s:void 0,u=l?.indexOf(`/`)??-1,h=u>0?l.slice(0,u):m(i),g=u>0?l.slice(u+1):v(i),y=a?.default_agent||i.agent,b=typeof y==`string`?y:void 0,x=ke.getState();h&&g&&x.saveSessionModelSelection(i.id,h,g,p),b&&x.saveSessionAgentSelection(i.id,b,p),b&&h&&g&&(x.saveAgentModelForSession(i.id,b,h,g,p),x.saveAgentModelVariantForSession(i.id,b,h,g,d(i),p))}catch(t){throw await l.deleteGitWorktree(e.path,{directory:r.path,deleteLocalBranch:!0}).catch(()=>void 0),t}return c.assertCurrent(),n.createSession&&P()&&L.getState().openRemoteSession(e,p,_??null,{...M?.draft,...g}),n.createSession&&Me(O,f),{path:f,branch:r.branch,..._?{id:_}:{}}}catch(e){let t=e instanceof Error?e:Error(String(e));throw P()&&M&&L.getState().updateRemoteDraft(M,{pendingWorktreeRequestId:null,bootstrapPendingDirectory:null,bootstrapStatus:{status:`failed`,error:t.message,updatedAt:Date.now()}}),de(O,t),e}}var dn=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,fn=e=>()=>{let t=R.getState().getActiveProject();return t?.id===e.id&&t?.hostId===e.hostId&&t?.hubId===e.hubId&&t?.path===e.path},pn=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),mn=(e,t,n)=>{let r=t.agentName?.trim()||void 0,i=t.providerId?.trim()||void 0,a=t.modelId?.trim()||void 0;!r||!i||!a||(n.saveSessionAgentSelection(e,r),n.saveSessionModelSelection(e,i,a),n.saveAgentModelForSession(e,r,i,a),n.saveAgentModelVariantForSession(e,r,i,a,t.variant))},hn=async(e,t)=>{await Se(e)&&await ye(t)},gn=e=>{let t=dn(e),n=R.getState().projects;if(n.length===0)return null;let r=n.filter(e=>{if(e.hostId)return!1;let n=dn(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>dn(t.path).length-dn(e.path).length)[0];return r?{id:r.id,path:r.path}:null},_n=!1,vn=async(e,t)=>{try{let n=R.getState().projects.find(e=>e.id===t.id)??R.getState().projects.find(e=>dn(e.path)===dn(t.path)),r=ce(t.path);await ue.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=ue.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),mn(e,pn(ue.getState()),ke.getState())}catch{}},yn=async(e,t,n)=>{let r=W.getState(),i=ue.getState();r.initializeNewYuriSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await vn(e,n),o.getState().setDirectory(t.path,{showOverlay:!1})},bn=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,xn=async e=>{if(_n)return null;let t=R.getState().getActiveProject();if(t?.hostId){_n=!0;let n=fn(t);try{let r=e?.existingBranch?.trim().replace(/^remotes\//,``),i=r?bn(r):ln();return(await un(t,{mode:r?`existing`:`new`,worktreeName:i,...r?{existingBranch:r}:{branchName:i}},{...e,isSelected:n})).path}catch(e){return K.error(`Failed to create worktree`,{description:e instanceof Error?e.message:String(e)}),null}finally{_n=!1}}let n=e?.projectDirectory?.trim()||t?.path;if(!n)return K.error(`No active project`,{description:`Please select a project first.`}),null;let r=gn(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return K.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await rt(r.path)}catch{}if(!i)return K.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;_n=!0;try{let t=_e(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?bn(n):ln(),a=n?`existing`:`new`,s=W.getState();s.newSessionDraft?.open?s.overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.newSessionDraft.directoryOverride??r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}):s.openNewSessionDraft({selectedProjectId:r.id,directoryOverride:r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt});let c=await nt(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);c?.path&&(W.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:c.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:c.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),o.getState().setDirectory(c.path,{showOverlay:!1}));let l=await Ee(r),u=await _t(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:l,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return Me(t,u.path),W.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:u.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:u.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),o.getState().setDirectory(u.path,{showOverlay:!1}),u.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=W.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(de(n,e instanceof Error?e:Error(t)),W.getState().resolvePendingDraftWorktreeTarget(n,null)),W.getState().setDraftBootstrapPendingDirectory(null),K.error(`Failed to create worktree`,{description:t}),null}finally{_n=!1}};async function Sn(){return xn()}async function Cn(e){let t=e.branch?.trim();return t?xn({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function wn(e,t,n,r){if(_n)return null;_n=!0;try{let i=R.getState().getActiveProject();if(i?.hostId){let e=fn(i);try{if(!t.trim())throw Error(`Branch name is required`);let a=await un(i,{mode:`new`,branchName:t.trim(),worktreeName:r?.worktreeName||t.trim(),startRef:n?.trim()||`HEAD`,setUpstream:r?.setUpstream,upstreamRemote:r?.upstreamRemote,upstreamBranch:r?.upstreamBranch,ensureRemoteName:r?.ensureRemoteName,ensureRemoteUrl:r?.ensureRemoteUrl},{createSession:!0,isSelected:e,kind:r?.kind,createdFromBranch:r?.createdFromBranch});if(!a.id)throw Error(`Could not create a remote session for the worktree`);return{id:a.id,branch:a.branch,path:a.path}}catch(e){return K.error(`Failed to create worktree`,{description:e instanceof Error?e.message:String(e)}),null}}let a=n?.trim()||`HEAD`,o=t?.trim();if(!o)throw Error(`Branch name is required`);let s=r?.kind??`standard`,c=gn(e);if(!c)throw Error(`Project is not registered in Yuri`);let l=!1;try{l=await rt(c.path)}catch{}if(!l)return K.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let u=await Ee(c),d=await mt(c.path);try{let e=await _t(c,{preferredName:o,mode:`new`,branchName:o,worktreeName:r?.worktreeName||o,startRef:a,setUpstream:r?.setUpstream,upstreamRemote:r?.upstreamRemote,upstreamBranch:r?.upstreamBranch,ensureRemoteName:r?.ensureRemoteName,ensureRemoteUrl:r?.ensureRemoteUrl,setupCommands:u,returnAfterDirectoryCreated:r?.returnAfterDirectoryCreated}),t={...e,createdFromBranch:r?.createdFromBranch||d||a,kind:s};await hn(c,e.worktreeRoot??e.path);let n=await W.getState().createSession(void 0,e.path);if(!n)throw await pt(c,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await yn(n.id,t,c),{id:n.id,branch:e.branch||o,path:e.path}}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree session`;return K.error(`Failed to create worktree`,{description:t}),null}}finally{_n=!1}}function Tn(e){let t=(0,Z.c)(12),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,style:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===i?a=t[5]:(a={color:`var(--surface-elevated-foreground)`,...i},t[4]=i,t[5]=a);let o;t[6]===n?o=t[7]:(o=G(`flex h-full w-full flex-col overflow-hidden rounded-xl`,n),t[6]=n,t[7]=o);let s;return t[8]!==r||t[9]!==a||t[10]!==o?(s=(0,Q.jsx)(Ct,{"data-slot":`command`,style:a,className:o,...r}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s}var En=X.forwardRef((e,t)=>{let n=(0,Z.c)(16),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,variant:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=(a===void 0?`default`:a)===`mobileGlass`?`yuri-mobile-glass-control rounded-full`:`bg-[var(--surface-elevated)] ring-1 ring-inset ring-border/60 transition duration-200 ease-out hover:[&:not(:focus-within)]:bg-[var(--surface-subtle)] hover:[&:not(:focus-within)]:ring-transparent focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]`,s;n[4]===o?s=n[5]:(s=G(`flex h-8 items-center gap-2 rounded-lg px-3`,o),n[4]=o,n[5]=s);let c;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(Y,{name:`search`,className:`size-4 shrink-0 opacity-50`}),n[6]=c):c=n[6];let l;n[7]===r?l=n[8]:(l=G(`placeholder:text-muted-foreground flex h-8 w-full bg-transparent typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50`,r),n[7]=r,n[8]=l);let u;n[9]!==i||n[10]!==t||n[11]!==l?(u=(0,Q.jsx)(Ct.Input,{ref:t,"data-slot":`command-input`,className:l,...i}),n[9]=i,n[10]=t,n[11]=l,n[12]=u):u=n[12];let d;return n[13]!==s||n[14]!==u?(d=(0,Q.jsx)(`div`,{"data-slot":`command-input-wrapper`,className:`p-1.5 pb-1`,children:(0,Q.jsxs)(`div`,{"data-slot":`command-input-field`,className:s,children:[c,u]})}),n[13]=s,n[14]=u,n[15]=d):d=n[15],d});En.displayName=`CommandInput`;function Dn(e){let t=(0,Z.c)(14),n,r,i,a,o;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({className:r,children:n,scrollbarClassName:o,disableHorizontal:i,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o);let s;t[6]===r?s=t[7]:(s=G(`scroll-py-1 overflow-x-hidden h-full min-h-0`,r),t[6]=r,t[7]=s);let c=o??`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,l=i??!0,u;return t[8]!==n||t[9]!==a||t[10]!==s||t[11]!==c||t[12]!==l?(u=(0,Q.jsx)(Ve,{as:Ct.List,"data-slot":`command-list`,outerClassName:`max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0`,className:s,scrollbarClassName:c,disableHorizontal:l,...a,children:n}),t[8]=n,t[9]=a,t[10]=s,t[11]=c,t[12]=l,t[13]=u):u=t[13],u}function On(e){let t=(0,Z.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Q.jsx)(Ct.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function kn(e){let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=G(`text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Q.jsx)(Ct.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function An(e){let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=G(`bg-border -mx-1 h-px`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Q.jsx)(Ct.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function jn(e){let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=G(`data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Q.jsx)(Ct.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Mn(e){let t=(0,Z.c)(27),{branches:n,search:r,local:i,currentBranch:a,branchInfo:o,onCheckout:s}=e,{t:c}=ze(),l;if(t[0]!==n||t[1]!==r){let e=r.trim();l=e?N(n,e,Pn).map(Nn):n,t[0]=n,t[1]=r,t[2]=l}else l=t[2];let u=l,d=i?`gitView.branch.localBranches`:`gitView.branch.remoteBranches`,f;t[3]!==c||t[4]!==d?(f=c(d),t[3]=c,t[4]=d,t[5]=f):f=t[5];let p;if(t[6]!==o||t[7]!==a||t[8]!==u||t[9]!==i||t[10]!==s||t[11]!==c){let e;t[13]!==o||t[14]!==a||t[15]!==i||t[16]!==s||t[17]!==c?(e=e=>(0,Q.jsxs)(jn,{onSelect:()=>s(e),children:[i?(0,Q.jsxs)(`span`,{className:`flex flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e}),(o?.[e]?.ahead||o?.[e]?.behind)&&(0,Q.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[o[e].ahead||0,` ahead ·`,` `,o[e].behind||0,` behind`]})]}):(0,Q.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e}),i&&a===e&&(0,Q.jsx)(`span`,{className:`typography-micro text-primary`,children:c(`gitView.branch.currentBadge`)})]},`${i?`local`:`remote`}-${e}`),t[13]=o,t[14]=a,t[15]=i,t[16]=s,t[17]=c,t[18]=e):e=t[18],p=u.map(e),t[6]=o,t[7]=a,t[8]=u,t[9]=i,t[10]=s,t[11]=c,t[12]=p}else p=t[12];let m;t[19]!==u.length||t[20]!==i||t[21]!==c?(m=u.length===0&&(0,Q.jsx)(jn,{disabled:!0,className:`justify-center`,children:(0,Q.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:c(i?`gitView.branch.noLocalBranches`:`gitView.branch.noRemoteBranches`)})}),t[19]=u.length,t[20]=i,t[21]=c,t[22]=m):m=t[22];let h;return t[23]!==f||t[24]!==p||t[25]!==m?(h=(0,Q.jsxs)(kn,{heading:f,children:[p,m]}),t[23]=f,t[24]=p,t[25]=m,t[26]=h):h=t[26],h}function Nn(e){return e.item}function Pn(e){return e}function Fn(e){let t=(0,Z.c)(9),{options:n,selectedDirectory:r,onSelect:i}=e,{t:a}=ze(),o;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a){let e;t[5]!==i||t[6]!==r||t[7]!==a?(e=e=>(0,Q.jsxs)(jn,{onSelect:()=>i(e.value),children:[(0,Q.jsxs)(`span`,{className:`truncate typography-ui-label text-foreground`,children:[e.pending?`⏳ `:``,e.label]}),r===e.value?(0,Q.jsx)(`span`,{className:`typography-micro text-primary`,children:a(`gitView.branch.currentBadge`)}):null]},`worktree-${e.value}`),t[5]=i,t[6]=r,t[7]=a,t[8]=e):e=t[8],o=n.map(e),t[0]=i,t[1]=n,t[2]=r,t[3]=a,t[4]=o}else o=t[4];return o}var In=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),Ln=({currentBranch:e,localBranches:t,remoteBranches:n,branchInfo:r,onCheckout:i,onCreate:a,remotes:o=[],disabled:s=!1,iconOnly:c=!1,trigger:l,triggerLabel:u,contentAlign:d,hideTooltip:f=!1,projectRootOption:p=null,worktreeOptions:m=[],selectedDirectory:h=null,onSelectDirectory:g,onCreateWorktree:_,worktreesLabel:v,worktreeNewLabel:y,projectRootLabel:b,onOpenChange:x,open:S,presentation:C=`dropdown`})=>{let{t:w}=ze(),[T,E]=X.useState(!1),[D,O]=X.useState(``),[k,A]=X.useState(!1),[ee,j]=X.useState(!1),[M,P]=X.useState(``),[F,te]=X.useState(!1),I=X.useRef(null),L=X.useId(),R=S??T,z=e=>{S===void 0&&E(e),x?.(e)},ne=X.useCallback(e=>{e.stopPropagation()},[]),re=o.length>1,ie=!!(g||_),ae=X.useMemo(()=>In(M),[M]),B=X.useMemo(()=>{let e=D.trim();return e?N(m,e,e=>e.label).map(e=>e.item):m},[D,m]),oe=X.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||N([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),V=t=>{if(t===e){z(!1);return}i(t),z(!1),O(``)},se=e=>{g?.(e),z(!1),O(``)},H=()=>{A(!0),setTimeout(()=>I.current?.focus(),50)},ce=async()=>{if(!(!ae||F)){if(re){j(!0);return}te(!0);try{await a(ae,o[0]),P(``),A(!1),z(!1)}finally{te(!1)}}},le=async e=>{if(!(!ae||F)){te(!0);try{await a(ae,e),P(``),A(!1),j(!1),z(!1)}finally{te(!1)}}},ue=()=>{j(!1)},de=()=>{P(``),A(!1),j(!1)};X.useEffect(()=>{R||(O(``),A(!1),j(!1),P(``))},[R]);let fe=u||e||w(`gitView.branch.detachedHead`),pe=d??(c?`end`:`start`),me=v??w(`chat.chatInput.worktrees`),he=y??w(`chat.chatInput.worktreeNew`),W=b??w(`chat.chatInput.projectRoot`),ge=c?(0,Q.jsx)(`button`,{type:`button`,className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50`,disabled:s,"aria-label":fe,children:(0,Q.jsx)(Y,{name:`git-branch`,className:`size-3.5`})}):(0,Q.jsxs)(U,{variant:`ghost`,size:`xs`,className:`h-6 min-w-0 max-w-full justify-start gap-1 px-0 hover:bg-transparent`,disabled:s,"aria-label":fe,children:[(0,Q.jsx)(Y,{name:`git-branch`,className:`size-3.5 text-primary`}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate typography-ui-label font-semibold text-left text-foreground`,children:fe}),(0,Q.jsx)(Y,{name:`arrow-down-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),_e=(0,Q.jsx)(Ze,{asChild:!0,disabled:s,children:l??ge}),ve=(0,Q.jsxs)(Tn,{className:`h-full min-h-0`,children:[(0,Q.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,Q.jsx)(En,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:ne})}),(0,Q.jsxs)(Dn,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,Q.jsx)(On,{children:w(`gitView.branch.empty`)}),(0,Q.jsx)(kn,{children:ee?(0,Q.jsxs)(`div`,{className:`px-2 py-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:ue,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,Q.jsx)(Y,{name:`arrow-left`,className:`size-4`})}),(0,Q.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[w(`gitView.branch.pushToPrefix`),` `,(0,Q.jsx)(`span`,{className:`text-foreground font-medium`,children:ae}),` `,w(`gitView.branch.pushToSuffix`)]})]}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>le(e),disabled:F,className:`flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50`,children:[(0,Q.jsxs)(`span`,{className:`typography-ui-label text-foreground`,children:[F?(0,Q.jsx)(Y,{name:`loader-4`,className:`inline size-3 mr-1.5 animate-spin`}):null,e.name]}),(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground truncate max-w-full`,children:e.pushUrl})]},e.name))})]}):k?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-lg`,children:[(0,Q.jsx)(`input`,{ref:I,placeholder:w(`gitView.branch.newBranchPlaceholder`),value:M,onChange:e=>P(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{ne(e),e.key===`Enter`?(e.preventDefault(),ce()):e.key===`Escape`&&(e.preventDefault(),de())},className:`flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground`}),(0,Q.jsx)(`button`,{type:`button`,onClick:ce,disabled:!ae||F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:F?(0,Q.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):(0,Q.jsx)(Y,{name:`add`,className:`size-4`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:de,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,Q.jsx)(Y,{name:`close`,className:`size-4`})})]}):(0,Q.jsxs)(jn,{onSelect:H,children:[(0,Q.jsx)(Y,{name:`add`,className:`size-4`}),(0,Q.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,Q.jsx)(An,{}),(0,Q.jsx)(Mn,{branches:t,search:D,local:!0,currentBranch:e,branchInfo:r,onCheckout:V}),(0,Q.jsx)(An,{}),(0,Q.jsx)(Mn,{branches:n,search:D,onCheckout:V}),ie?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(An,{}),(0,Q.jsxs)(kn,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground typography-meta`,children:me}),_?(0,Q.jsx)(`button`,{type:`button`,className:`cursor-pointer text-muted-foreground typography-meta hover:text-foreground`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),z(!1),_()},children:he}):null]}),p&&oe?(0,Q.jsxs)(jn,{onSelect:()=>se(p.value),children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:W}),(0,Q.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:p.label})]}),h===p.value?(0,Q.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]}):null,(0,Q.jsx)(Fn,{options:B,selectedDirectory:h,onSelect:se})]})]}):null]})]});if(C===`mobile-sheet`){let e=X.cloneElement(l??ge,{onClick:()=>z(!0),"data-popup-open":R?``:void 0});return(0,Q.jsxs)(Q.Fragment,{children:[e,(0,Q.jsx)(He,{id:`mobile-draft-branch-picker-sheet-${L}`,open:R,onOpenChange:z,ariaLabel:w(`gitView.branch.selectBranch`),closeAriaLabel:w(`mobile.surface.closeAria`),resizeAriaLabel:w(`mobile.sessions.sheet.resizeAria`),children:ve})]})}return(0,Q.jsxs)($e,{open:R,onOpenChange:z,children:[f||l?_e:(0,Q.jsxs)(Xe,{children:[(0,Q.jsx)(Je,{asChild:!0,children:_e}),(0,Q.jsx)(Ye,{sideOffset:8,children:c?fe:w(`gitView.branch.currentBranchTooltip`)})]}),(0,Q.jsx)(Qe,{align:pe,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:ve})]})};function Rn(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=N(t,i,e=>e),o=N(n,i,e=>e),s=new Set(a.map(e=>e.item)),c=new Set(o.map(e=>e.item));return{matching:[...a.map(e=>({label:e.item,value:e.item,source:`local`,score:e.score})),...o.map(e=>({label:e.item,value:`remotes/${e.item}`,source:`remote`,score:e.score}))].sort((e,t)=>e.score===t.score?e.source===t.source?e.label.length===t.label.length?e.label.localeCompare(t.label,void 0,{sensitivity:`accent`}):e.label.length-t.label.length:e.source===`local`?-1:1:e.score-t.score).map(({label:e,value:t,source:n})=>({label:e,value:t,source:n})),otherLocal:t.filter(e=>!s.has(e)),otherRemote:n.filter(e=>!c.has(e))}}function zn(e){let t=D(e),n=(e,n={})=>t.json(`/api/github/${e}`,{query:n}),r=e=>e?{owner:e.owner,repo:e.repo}:{};return{authStatus:()=>n(`auth/status`),issuesList:(e,t)=>n(`issues/list`,{directory:e,page:t?.page,query:t?.query}),prsList:(e,t)=>n(`pulls/list`,{directory:e,page:t?.page,query:t?.query}),issueGet:(e,t,i)=>n(`issues/get`,{directory:e,number:t,...r(i?.sourceRepo)}),issueComments:(e,t,i)=>n(`issues/comments`,{directory:e,number:t,...r(i?.sourceRepo)}),prContext:(e,t,i)=>n(`pulls/context`,{directory:e,number:t,...r(i?.sourceRepo),diff:i?.includeDiff?`1`:void 0,checkDetails:i?.includeCheckDetails?`1`:void 0})}}var Bn=e=>({queryKey:[...e.queryScope,`worktree-dialog`,`github-auth`],queryFn:({signal:t})=>D(e).json(`/api/github/auth/status`,{signal:t}),staleTime:3e4,gcTime:1/0});function Vn(e,t){let n=(0,Z.c)(12),r=O(),i=e?void 0:r.github,a;n[0]!==e||n[1]!==i?(a=e?zn(e):i,n[0]=e,n[1]=i,n[2]=a):a=n[2];let o=a,s;n[3]!==e||n[4]!==r?(s=e?Bn(e):dt(r.github),n[3]=e,n[4]=r,n[5]=s):s=n[5];let c;n[6]!==t||n[7]!==s?(c={...s,enabled:t},n[6]=t,n[7]=s,n[8]=c):c=n[8];let l=w(c,k),u;return n[9]!==l||n[10]!==o?(u={github:o,auth:l},n[9]=l,n[10]=o,n[11]=u):u=n[11],u}async function Hn(e,t,n={}){let r=await D(e).json(`/api/magic-prompts`);return(typeof r.overrides?.[t]==`string`?r.overrides[t]:it(t)).replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g,(e,t)=>Object.prototype.hasOwnProperty.call(n,t)?n[t]??``:``)}async function Un(e,t,n,r,i,a){let o=zn(t),s=i.issue,l=i.pr;if(!s&&!l)return;let u=s?`issue`:`pr`,d=s?.number??l.number,f=await Hn(t,`github.${u}.review.visible`,{[`${u}_number`]:String(d)}),p=await Hn(t,`github.${u}.review.instructions`),m;if(s){let e=await o.issueGet(t.location.directory,d,{sourceRepo:s.sourceRepo}),n=await o.issueComments(t.location.directory,d,{sourceRepo:s.sourceRepo});if(e.connected===!1||!e.issue||n.connected===!1)throw Error(a);m=`GitHub issue context (JSON)\n${JSON.stringify({repo:e.repo??null,issue:e.issue,comments:n.comments??[]},null,2)}`}else{let e=await o.prContext(t.location.directory,d,{sourceRepo:l.sourceRepo,includeDiff:i.includeDiff,includeCheckDetails:!1});if(e.connected===!1||!e.pr)throw Error(a);m=`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`}t.sdk();let h=e.resolve({...t.location,directory:n});await me(e,h).state.send({sessionID:r,messageID:c(`msg`),text:[f,p,m].join(`
|
|
2
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n}from"./runtime-switch-DEPKHgdL.js";import{Jt as r,R as i,Wt as a,Xt as o,at as s,dr as c,en as l,it as u,n as d,nr as f,on as p,rt as m,tn as h,tr as g}from"./client-A12QacVZ.js";import{a as _}from"./vendor-zustand-CTekDqaS.js";import{ot as v,st as y}from"./vendor-base-ui-wXsskyKm.js";import{St as b}from"./gitApiHttp-BLNjaxGv.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{t as x}from"./pathNormalization-ewtPqJWn.js";import{n as S}from"./vendor-react-BkccXcWz.js";import{o as C,s as w}from"./vendor-tanstack-react-query-DIb_ItL-.js";import{A as T,E,I as D,R as O,W as k,k as A}from"./runtime-file-resource-BGZ4tGr5.js";import{r as ee}from"./vendor-reactuses-core-DjKFMfz7.js";import{o as j}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{r as M}from"./useUIStore-68ZPpgYA.js";import{s as N}from"./spacedFileMention-Ds4GtgiF.js";import{An as P,Bn as F,Et as te,Fr as I,Ga as L,Ha as R,Hn as z,Ji as ne,La as re,Lr as ie,Rr as ae,St as B,U as oe,V,Vn as se,W as H,Xi as ce,Xn as U,Xt as le,Zi as ue,_i as de,_t as fe,ar as pe,dr as me,dt as he,f as W,fn as ge,gi as _e,gt as ve,hi as ye,hn as be,ht as xe,ii as Se,io as G,j as Ce,jn as we,mt as Te,ni as Ee,pt as De,qi as Oe,ra as ke,ri as Ae,si as je,t as K,vi as Me,vt as Ne,yi as q,yr as J,zn as Pe,zr as Fe}from"./ui-Cvgk-VfB.js";import{n as Y}from"./Icon-BWc3icuX.js";import{i as Ie,m as Le,n as Re}from"./remoteProjectQueries-Dq2vrCZs.js";import{t as ze}from"./i18n-DVQ9uTj5.js";import{t as Be}from"./toolHelpers-iEHVHQ9p.js";import{t as Ve}from"./ScrollableOverlay-Db594s2Q.js";import{t as He}from"./MobileResizableSheet-bd8BfSwf.js";import{a as Ue,i as We,n as Ge,o as Ke,t as qe}from"./dialog-y7FwO2zG.js";import{i as Je,n as Ye,t as Xe}from"./tooltip-Chw-EXbL.js";import{c as Ze,n as Qe,t as $e}from"./dropdown-menu-hX2yxn_J.js";import{n as et}from"./useProjectRuntimeAPIs-DA53IKrj.js";import{b as tt,p as nt,t as rt,v as it}from"./gitApi-Czkb5T4C.js";import{o as at,t as ot}from"./useProjectGitStore-B-fG3PyR.js";import{t as st}from"./input-LFbBkZKd.js";import{t as ct}from"./useDebouncedValue-BHlMPqY8.js";import{t as lt}from"./checkbox-OdKCedfo.js";import{t as ut}from"./MobileOverlayPanel-CY0YwEKs.js";import{t as dt}from"./githubAuthQueries-3AJp5LD5.js";import{a as ft,i as pt,s as mt,t as ht}from"./worktreeManager-oPk1TFpI.js";import{a as gt,i as _t,n as vt,o as yt,r as bt,t as xt}from"./worktreeSourceBranchPreference-D_i6GD56.js";import{s as St}from"./remote-input-store-DPw_n0MZ.js";import{t as Ct}from"./vendor-cmdk-BDWoZLve.js";import{t as wt}from"./sortable-tabs-strip-74dWtnXq.js";import{f as Tt,m as Et}from"./auto-read-context-DTwWW3zG.js";var Dt=2e3,Ot=_((e,t)=>({pending:!1,expiresAt:null,arm:(t=Dt)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),X=e(y(),1),kt=new class{inFlightByScope=new WeakMap;generationByScope=new WeakMap;run(e){let t=this.inFlightByScope.get(e.scope);t||(t=new Map,this.inFlightByScope.set(e.scope,t));let n=t.get(e.key);if(n)return n;let r=this.generationByScope.get(e.scope);r||(r=new Map,this.generationByScope.set(e.scope,r));let i=(r.get(e.key)??0)+1;r.set(e.key,i);let a=e.request(()=>r?.get(e.key)!==i);return t.set(e.key,a),a.finally(()=>{t?.get(e.key)===a&&t.delete(e.key)}).catch(()=>{}),a}},At=e=>C({queryKey:[e.transport,`sessionChildren`,e.generation,x(e.directory),e.sessionID],queryFn:({signal:t})=>e.request(t),staleTime:0,gcTime:6e4,retry:!1}),jt=e=>k.fetchQuery(At(e)),Mt=(e,t)=>e.id<t.id?-1:+(e.id>t.id),Nt=(e,t,n)=>{let r=new Set(e.map(e=>e.id)),i=t.filter(e=>!e?.id||r.has(e.id)||e.parentID!==n?!1:(r.add(e.id),!0));return i.length===0?e:[...e,...i].sort(Mt)},Pt=30,Ft=new Map;function It(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function Lt(e,t){let n=o();if(!n)return!1;let r=n.getTranscript(p(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>Fe()}function Rt(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function zt(e,t,n){let r=[...e.getState().session],i=z.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function Bt(){let e=B(),i=oe(),s=V(),u=(0,X.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),f=(0,X.useCallback)((t,n=e)=>{let r=o();if(!r||!t)return It({kind:`unknown`,loadedTurns:0},!1);let i=p(n,t),a=r.getPagination(i),s=r.getRequestState?.(i);return It(a.boundary,s?.status===`loading`)},[e]),m=(0,X.useCallback)((e,t)=>{if(t.length===0)return;let n=s.getChild(e);if(!n)return;let r=n.getState(),i={session_status:{...r.session_status},session_status_observed_at:{...r.session_status_observed_at},session_error_at:{...r.session_error_at},session_diff:{...r.session_diff},todo:{...r.todo},permission:{...r.permission},question:{...r.question}};Pe(i,t),Ce(n,t),n.setState(i);for(let n of t)l(e,n)},[s]),g=(0,X.useCallback)((t=e)=>{let n=Ft.get(t);if(n)return Ft.delete(t),Ft.set(t,n),n;let r=new Set;for(Ft.set(t,r);Ft.size>Pt;){let e=Ft.keys().next().value;if(!e)break;let t=[...Ft.get(e)??[]];Ft.delete(e),m(e,t)}return r},[e,m]),_=(0,X.useCallback)((t,n=e)=>{let r=n===e?i:s.ensureChild(n,{bootstrap:!1}),a=g(n),c=F(r.getState()),l=ie(),u=se({seen:a,keep:t,limit:l,preserve:c});if(m(n,u),ae()){let e=new Set([t,...a,...c]),r=(o()?.getCacheBudget?.().listCanonical({directory:n})??[]).map(e=>e.scope.sessionID),i=(r.length>0?r:Array.from(a)).filter(r=>r===t||e.has(r)?!1:Lt(n,r));if(i.length>0){for(let e of i)a.delete(e);m(n,i)}}},[s,e,g,m,i]),v=(0,X.useCallback)(async(t,n)=>{let a=n?.directory??e;if(!t||!a||a===`global`)return;let c=a===e?i:s.ensureChild(a,{bootstrap:!1}),l=c.getState(),u=l.session_status?.[t],d=l.session_status_observed_at?.[t];try{n?.purpose===`prepend`||n?.before?await r(a,t):await h(a,t,{background:!0})}catch{return}if(n?.isStale?.())return;let f=o()?.getTranscript(p(a,t));be({directory:a,sessionID:t,store:c,transcript:f,isStale:n?.isStale}),await J({directory:a,sessionID:t,store:c,statusBeforePull:u,statusObservedAtBeforePull:d,hasMessages:(f?.messageOrder.length??0)>0,isTailPage:!n?.before,isStale:n?.isStale})},[s,i,e]),y=(0,X.useCallback)(async(t,n)=>{await te();let r=typeof n==`boolean`?n:n?.force,i=typeof n==`object`?n.directory??e:e,a=s.ensureChild(i,{bootstrap:!1}),l=d.getScopedSdkClient(i);_(t,i);let f=u(t,i);return kt.run({scope:a,key:f,request:async e=>{let n=a.getState(),s=o(),u=p(i,t),d=s?.hasSession?.(u)??(s?.getTranscript(u).messageOrder.length??0)>0,f=s?.getPagination(u)?.boundary??{kind:`unknown`,loadedTurns:0},m=z.search(n.session,t,e=>e.id).found,h=s?.getRequestState?.(u);if(!r&&d&&f.kind!==`unknown`&&h?.status!==`error`&&m&&I(i,t)){be({directory:i,sessionID:t,store:a,isStale:e});return}let g=!!(r||!d||m),_=Rt({hasSession:m,shouldLoadMessages:g,force:!!r});await Promise.all([_?(async()=>{try{let n=await ne(async()=>l.session.get({sessionID:t}));if(n&&!e()){let r=Oe(c(n));e()||zt(a,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),g?v(t,{isStale:e,directory:i}):Promise.resolve()])}})},[s,u,_,v,e]),b=ee(async(r,i)=>{let a=i||e;if(!r||!a)return;let o=s.ensureChild(a,{bootstrap:!1}),l=d.getScopedSdkClient(a),u=n(),f=t(),p=()=>u!==n()||f!==t()||s.getChild(a)!==o,m=await jt({transport:f,generation:u,directory:a,sessionID:r,request:async e=>{let i=[],o=new Set,s;do{if(e.throwIfAborted(),u!==n()||f!==t())throw new DOMException(`Session children runtime changed`,`AbortError`);let d=await l.session.list(s?{cursor:s,limit:50}:{directory:a,parentID:r,limit:50},{signal:e});if(!Array.isArray(d?.data))throw Error(`session.list children returned no data`);if(i.push(...d.data.map(c)),d.data.length<50)break;if(s=d.cursor?.next??void 0,!s||o.has(s))throw Error(`session.list children pagination did not advance`);o.add(s)}while(s);return i}}).catch(e=>{if(p())return null;throw e});!m||p()||o.setState(e=>{let t=Nt(e.session,m,r);return t===e.session?e:{session:t,limit:Math.max(e.limit,t.length)}})}),x=(0,X.useCallback)((t,n)=>{let r=f(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,f]),S=(0,X.useCallback)((t,n)=>f(t,n?.directory??e).loading,[e,f]),C=(0,X.useCallback)((t,n)=>f(t,n?.directory??e).complete,[e,f]),w=(0,X.useCallback)(t=>{let n=t.directory||e;a(p(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),T=(0,X.useCallback)(t=>{let n=t.directory||e;a(p(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),E=(0,X.useCallback)(t=>{let n=t.directory||e;a(p(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),D=ee(async(r,i)=>{if(!r)return;await te();let a=i?.directory??e;if(!a||a===`global`)return;let c=s.ensureChild(a,{bootstrap:!1}),l=n(),u=t(),d=()=>l!==n()||u!==t()||s.ensureChild(a,{bootstrap:!1})!==c,f=c.getState();try{if(await h(a,r),d())return;be({directory:a,sessionID:r,store:c}),await J({directory:a,sessionID:r,store:c,statusBeforePull:f.session_status?.[r],statusObservedAtBeforePull:f.session_status_observed_at?.[r],hasMessages:(o()?.getTranscript(p(a,r)).messageOrder.length??0)>0,isStale:d})}catch{throw Error(`refresh transcript failed`)}});return(0,X.useMemo)(()=>({ensureSessionRenderable:y,syncSession:y,loadChildren:b,hasMore:x,isLoading:S,isComplete:C,refreshSessionTranscript:D,optimistic:{add:w,remove:T,confirm:E}}),[y,b,x,S,C,D,w,T,E])}var Z=S(),Q=v(),Vt=(e,t)=>{if(!e)return t;let n=e.ready&&!e.loading;return{modelsReady:!e.error&&(e.modelsReady??n),agentsReady:!e.error&&(e.agentsReady??n)}},Ht=e=>{let t=e?.variants;if(!t)return[];if(Array.isArray(t)){let e=[],n=new Set;for(let r of t){let t=typeof r==`string`?r:r&&typeof r==`object`&&!Array.isArray(r)&&typeof r.id==`string`?r.id:``;!t||n.has(t)||(n.add(t),e.push(t))}return e}return typeof t==`object`?Object.keys(t):[]},Ut=(e,t,n,r)=>{if(e.providerID!==n||e.modelID!==r||t?.variantsReady===!1)return[];if(t?.variants)return[...t.variants];let i=(t?.providers?.find(e=>e.id===n))?.models?.find(e=>e.id===r);return Ht(i)},Wt=()=>!0,Gt=(e,t)=>(e.commandPolicy??Wt)(t),Kt=X.createContext(null),qt=()=>X.useContext(Kt),Jt=e=>e,Yt=(e,t)=>t??e,Xt=e=>{if(e.kind!==`primary`&&(!e.sessionID||!e.directory||!e.draftKey||!e.transportIdentity||!Number.isSafeInteger(e.runtimeGeneration)||!e.resources||typeof e.resources.busy!=`boolean`||!e.activity||!e.commands||!e.shortcuts))throw Error(`chat-input-secondary-surface-incomplete`)},Zt=(e,t)=>e.kind===`secondary`?e.resources?.busy??!1:t,Qt=e=>!e.sessionID||!e.directory?null:{deliveryTarget:e.deliveryTarget,sessionID:e.queueSessionID??e.sessionID,directory:e.directory,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration},$t=(e,t,n)=>{if(e.kind===`secondary`){if(!e.commands)throw Error(`chat-input-secondary-commands-incomplete`);return e.commands}return e.commands?e.commands:{sessionID:e.sessionID,hasMessages:t,hasNewDraft:n}},en={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},tn=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function nn(e,t){let n=(0,Z.c)(6),r=ve(e??``,t),i=fe(e??``,t),a=he(e??``,t),o=Te(e??``,t),s=xe(e??``,t),c=Ne(t),l;bb0:{if(!e){l=en;break bb0}if(o.length>0||s.length>0){l=en;break bb0}let t=r?.type??`idle`,u=a[a.length-1],d=!!(u&&u.role===`assistant`&&typeof u.time?.completed!=`number`),f=a,p;n[0]!==d||n[1]!==f?(p=tn({messages:f,hasPendingAssistant:d}),n[0]=d,n[1]=f,n[2]=p):p=n[2];let m=p,h=u?.time?.created,g=!!(m&&typeof c==`number`&&typeof h==`number`&&h<=c),_=r!==void 0,v=_&&t!==`idle`,y=v||m&&!g;if(_&&!v&&(!m||_&&!v&&typeof i==`number`&&typeof h==`number`&&h<=i)){l=en;break bb0}if(!y){l=en;break bb0}let b=v?t:`busy`,x=t===`busy`||!v&&m,S;n[3]!==b||n[4]!==x?(S={phase:b,isWorking:!0,isBusy:x,isCooldown:!1},n[3]=b,n[4]=x,n[5]=S):S=n[5],l=S}return l}var rn=`data-mobile-overlay-active`,an=e=>Array.from(e).some(e=>e.getAttribute(rn)!==`false`),on=`artful.bionic.cosmic.disco.focal.groovy.jammy.kinetic.lunar.noble.bold.brave.calm.eager.gentle.happy.keen.lively.merry.swift.warm.wise.bright.clever.daring.agile.crisp.fresh.lucid.quick.sharp.vivid.zealous`.split(`.`),sn=`aardvark.beaver.chipmunk.dolphin.falcon.gopher.hedgehog.jackal.koala.lemur.mongoose.narwhal.otter.pangolin.quokka.raccoon.salamander.toucan.walrus.yak.zebra.badger.condor.dingo.egret.ferret.gecko.heron.iguana`.split(`.`);function cn(){return`${on[Math.floor(Math.random()*on.length)]}-${sn[Math.floor(Math.random()*sn.length)]}`}function ln(e){let t=cn();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}async function un(e,t,n){if(!e.hostId||!e.hubId)throw Error(`Remote Project Host scope is unavailable`);let r=L.getState().remoteSession,i=D(),a=await Re();if(i.assertCurrent(),!a.supported||a.hubId!==e.hubId||!a.projects.some(t=>t.id===e.id&&t.hostId===e.hostId&&t.path===e.path))throw Error(`Remote Project is not referenced by the current Hub`);let o=Ie(a);await o.connectHost(e.hostId);let c=o.resolve({hubId:e.hubId,hostId:e.hostId,directory:e.path}),l=D(c),d=pe(c);if(!await d.checkIsGitRepository(e.path))throw Error(`Worktrees can only be created in Git repositories`);let f=await Ae(e,c),p=f.commands,h=Array.isArray(p)?p.filter(e=>typeof e==`string`&&!!e.trim()).map(t=>je(t.trim(),{rootWorktreePath:e.path})).join(` && `):void 0,g=await d.getGitStatus(e.path),_=await d.getGitBranches(e.path),v=await d.listGitWorktrees(e.path),y=x(e.path),b=v.map(e=>x(e.path)).filter(e=>y===e||y.startsWith(`${e}/`)).sort((e,t)=>t.length-e.length)[0],S=b?y.slice(b.length):``,C=(_.branches?.[g.current]?.tracking||g.tracking)?.replace(/^remotes\//,``).split(`/`)[0],w=t.branchName||t.existingBranch?.replace(/^remotes\//,``),T={...t,...h?{startCommand:h}:{},...C&&w?{setUpstream:t.setUpstream??!0,upstreamRemote:t.upstreamRemote||C,upstreamBranch:t.upstreamBranch||w}:{},returnAfterDirectoryCreated:!1},E=await d.previewGitWorktree(e.path,T);if(!E.path)throw Error(`Remote worktree preview missing path`);let O=_e();q(O).catch(()=>void 0);let k=S?`${E.path.replace(/[\\/]+$/,``)}${S}`:E.path,A={...c.location,directory:k},ee={title:n.title,initialPrompt:n.initialPrompt,bootstrapWaitEnabled:f.wait,defaultModel:e.defaultModel??void 0,pendingWorktreeRequestId:O,bootstrapPendingDirectory:k,preserveDirectoryOverride:!0,bootstrapStatus:{status:`pending`,error:null,updatedAt:Date.now()}};try{n.initialPrompt&&await St(A,n.initialPrompt),l.assertCurrent()}catch(e){throw de(O,e instanceof Error?e:Error(String(e))),e}n.isSelected()&&L.getState().remoteSession===r&&L.getState().openRemoteSession(e,A,null,ee);let M=L.getState().remoteSession,N=M?.draft?.pendingWorktreeRequestId===O,P=()=>{if(!n.isSelected()||!N)return!1;let t=L.getState().remoteSession;return t?.sessionId===null&&t.projectId===e.id&&t.location.hubId===e.hubId&&t.location.hostId===e.hostId&&t.draft?.pendingWorktreeRequestId===O?(M=t,!0):t===M};try{let r=await d.createGitWorktree(e.path,T);if(!r.path||!r.name)throw Error(`Remote worktree create missing name/path`);let i=r.bootstrapStatus,a=Date.now()+12e4;for(;i?.status===`pending`&&f.wait;){if(Date.now()>=a)throw Error(`Remote worktree setup timed out; the existing draft was retained`);await new Promise(e=>setTimeout(e,500)),l.assertCurrent(),i=await d.getGitWorktreeBootstrapStatus(r.path)}if(i?.status===`failed`)throw Error(i.error||`Remote worktree setup failed`);l.assertCurrent();let p=S?`${r.path.replace(/[\\/]+$/,``)}${S}`:r.path,h={...c.location,directory:p},_={pendingWorktreeRequestId:null,bootstrapPendingDirectory:null,worktreeMetadata:{name:r.name,path:p,worktreeRoot:r.path,projectDirectory:e.path,relativePath:S.replace(/^\//,``)||void 0,branch:r.branch,label:r.branch||r.name,source:`sdk`,worktreeSource:`created-for-session`,headState:r.branch?`branch`:`unborn`,worktreeStatus:i?.status===`pending`?`pending`:`ready`,createdFromBranch:n.createdFromBranch||g.current||t.startRef,kind:n.kind??`standard`},bootstrapStatus:f.wait?i??{status:`ready`,error:null,updatedAt:Date.now()}:void 0};if(p!==k){let{getRemoteInputStore:e,remoteSessionDraftKey:t}=await j(async()=>{let{getRemoteInputStore:e,remoteSessionDraftKey:t}=await import(`./remote-input-store-DPw_n0MZ.js`).then(e=>e.a);return{getRemoteInputStore:e,remoteSessionDraftKey:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27])),n=e(h),r=t(A,null),i=n.getState().getDraft(r),a=await n.getState().moveDraftWithAttachments(r,t(h,null),i?.revision);if(i&&!a)throw Error(`Remote draft changed while the worktree target was being finalized; the original draft was retained`);l.assertCurrent()}!n.createSession&&P()&&M&&(L.getState().updateRemoteDraft(M,_,h),M=L.getState().remoteSession),n.createSession||Me(O,p);let v;if(n.createSession)try{let t=o.resolve(h).service(),r=P()?M?.draft?.title??n.title:n.title,i=await t.createSession({title:r},p);v=i.id,l.assertCurrent();let a=await t.getConfig(p).catch(()=>void 0);l.assertCurrent();let c=e.defaultModel||a?.model,d=typeof c==`string`?c:void 0,f=d?.indexOf(`/`)??-1,g=f>0?d.slice(0,f):u(i),_=f>0?d.slice(f+1):m(i),y=a?.default_agent||i.agent,b=typeof y==`string`?y:void 0,x=ke.getState();g&&_&&x.saveSessionModelSelection(i.id,g,_,h),b&&x.saveSessionAgentSelection(i.id,b,h),b&&g&&_&&(x.saveAgentModelForSession(i.id,b,g,_,h),x.saveAgentModelVariantForSession(i.id,b,g,_,s(i),h))}catch(t){throw await d.deleteGitWorktree(e.path,{directory:r.path,deleteLocalBranch:!0}).catch(()=>void 0),t}return l.assertCurrent(),n.createSession&&P()&&L.getState().openRemoteSession(e,h,v??null,{...M?.draft,..._}),n.createSession&&Me(O,p),{path:p,branch:r.branch,...v?{id:v}:{}}}catch(e){let t=e instanceof Error?e:Error(String(e));throw P()&&M&&L.getState().updateRemoteDraft(M,{pendingWorktreeRequestId:null,bootstrapPendingDirectory:null,bootstrapStatus:{status:`failed`,error:t.message,updatedAt:Date.now()}}),de(O,t),e}}var dn=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,fn=e=>()=>{let t=R.getState().getActiveProject();return t?.id===e.id&&t?.hostId===e.hostId&&t?.hubId===e.hubId&&t?.path===e.path},pn=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),mn=(e,t,n)=>{let r=t.agentName?.trim()||void 0,i=t.providerId?.trim()||void 0,a=t.modelId?.trim()||void 0;!r||!i||!a||(n.saveSessionAgentSelection(e,r),n.saveSessionModelSelection(e,i,a),n.saveAgentModelForSession(e,r,i,a),n.saveAgentModelVariantForSession(e,r,i,a,t.variant))},hn=async(e,t)=>{await Se(e)&&await ye(t)},gn=e=>{let t=dn(e),n=R.getState().projects;if(n.length===0)return null;let r=n.filter(e=>{if(e.hostId)return!1;let n=dn(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>dn(t.path).length-dn(e.path).length)[0];return r?{id:r.id,path:r.path}:null},_n=!1,vn=async(e,t)=>{try{let n=R.getState().projects.find(e=>e.id===t.id)??R.getState().projects.find(e=>dn(e.path)===dn(t.path)),r=ce(t.path);await ue.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=ue.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),mn(e,pn(ue.getState()),ke.getState())}catch{}},yn=async(e,t,n)=>{let r=W.getState(),i=ue.getState();r.initializeNewYuriSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await vn(e,n),b.getState().setDirectory(t.path,{showOverlay:!1})},bn=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,xn=async e=>{if(_n)return null;let t=R.getState().getActiveProject();if(t?.hostId){_n=!0;let n=fn(t);try{let r=e?.existingBranch?.trim().replace(/^remotes\//,``),i=r?bn(r):ln();return(await un(t,{mode:r?`existing`:`new`,worktreeName:i,...r?{existingBranch:r}:{branchName:i}},{...e,isSelected:n})).path}catch(e){return K.error(`Failed to create worktree`,{description:e instanceof Error?e.message:String(e)}),null}finally{_n=!1}}let n=e?.projectDirectory?.trim()||t?.path;if(!n)return K.error(`No active project`,{description:`Please select a project first.`}),null;let r=gn(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return K.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await rt(r.path)}catch{}if(!i)return K.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;_n=!0;try{let t=_e(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?bn(n):ln(),a=n?`existing`:`new`,o=W.getState();o.newSessionDraft?.open?o.overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:o.newSessionDraft.directoryOverride??r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}):o.openNewSessionDraft({selectedProjectId:r.id,directoryOverride:r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt});let s=await nt(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(W.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),b.getState().setDirectory(s.path,{showOverlay:!1}));let c=await Ee(r),l=await _t(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return Me(t,l.path),W.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),b.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=W.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(de(n,e instanceof Error?e:Error(t)),W.getState().resolvePendingDraftWorktreeTarget(n,null)),W.getState().setDraftBootstrapPendingDirectory(null),K.error(`Failed to create worktree`,{description:t}),null}finally{_n=!1}};async function Sn(){return xn()}async function Cn(e){let t=e.branch?.trim();return t?xn({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function wn(e,t,n,r){if(_n)return null;_n=!0;try{let i=R.getState().getActiveProject();if(i?.hostId){let e=fn(i);try{if(!t.trim())throw Error(`Branch name is required`);let a=await un(i,{mode:`new`,branchName:t.trim(),worktreeName:r?.worktreeName||t.trim(),startRef:n?.trim()||`HEAD`,setUpstream:r?.setUpstream,upstreamRemote:r?.upstreamRemote,upstreamBranch:r?.upstreamBranch,ensureRemoteName:r?.ensureRemoteName,ensureRemoteUrl:r?.ensureRemoteUrl},{createSession:!0,isSelected:e,kind:r?.kind,createdFromBranch:r?.createdFromBranch});if(!a.id)throw Error(`Could not create a remote session for the worktree`);return{id:a.id,branch:a.branch,path:a.path}}catch(e){return K.error(`Failed to create worktree`,{description:e instanceof Error?e.message:String(e)}),null}}let a=n?.trim()||`HEAD`,o=t?.trim();if(!o)throw Error(`Branch name is required`);let s=r?.kind??`standard`,c=gn(e);if(!c)throw Error(`Project is not registered in Yuri`);let l=!1;try{l=await rt(c.path)}catch{}if(!l)return K.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let u=await Ee(c),d=await mt(c.path);try{let e=await _t(c,{preferredName:o,mode:`new`,branchName:o,worktreeName:r?.worktreeName||o,startRef:a,setUpstream:r?.setUpstream,upstreamRemote:r?.upstreamRemote,upstreamBranch:r?.upstreamBranch,ensureRemoteName:r?.ensureRemoteName,ensureRemoteUrl:r?.ensureRemoteUrl,setupCommands:u,returnAfterDirectoryCreated:r?.returnAfterDirectoryCreated}),t={...e,createdFromBranch:r?.createdFromBranch||d||a,kind:s};await hn(c,e.worktreeRoot??e.path);let n=await W.getState().createSession(void 0,e.path);if(!n)throw await pt(c,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await yn(n.id,t,c),{id:n.id,branch:e.branch||o,path:e.path}}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree session`;return K.error(`Failed to create worktree`,{description:t}),null}}finally{_n=!1}}function Tn(e){let t=(0,Z.c)(12),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,style:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===i?a=t[5]:(a={color:`var(--surface-elevated-foreground)`,...i},t[4]=i,t[5]=a);let o;t[6]===n?o=t[7]:(o=G(`flex h-full w-full flex-col overflow-hidden rounded-xl`,n),t[6]=n,t[7]=o);let s;return t[8]!==r||t[9]!==a||t[10]!==o?(s=(0,Q.jsx)(Ct,{"data-slot":`command`,style:a,className:o,...r}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s}var En=X.forwardRef((e,t)=>{let n=(0,Z.c)(16),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,variant:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=(a===void 0?`default`:a)===`mobileGlass`?`yuri-mobile-glass-control rounded-full`:`bg-[var(--surface-elevated)] ring-1 ring-inset ring-border/60 transition duration-200 ease-out hover:[&:not(:focus-within)]:bg-[var(--surface-subtle)] hover:[&:not(:focus-within)]:ring-transparent focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]`,s;n[4]===o?s=n[5]:(s=G(`flex h-8 items-center gap-2 rounded-lg px-3`,o),n[4]=o,n[5]=s);let c;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(Y,{name:`search`,className:`size-4 shrink-0 opacity-50`}),n[6]=c):c=n[6];let l;n[7]===r?l=n[8]:(l=G(`placeholder:text-muted-foreground flex h-8 w-full bg-transparent typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50`,r),n[7]=r,n[8]=l);let u;n[9]!==i||n[10]!==t||n[11]!==l?(u=(0,Q.jsx)(Ct.Input,{ref:t,"data-slot":`command-input`,className:l,...i}),n[9]=i,n[10]=t,n[11]=l,n[12]=u):u=n[12];let d;return n[13]!==s||n[14]!==u?(d=(0,Q.jsx)(`div`,{"data-slot":`command-input-wrapper`,className:`p-1.5 pb-1`,children:(0,Q.jsxs)(`div`,{"data-slot":`command-input-field`,className:s,children:[c,u]})}),n[13]=s,n[14]=u,n[15]=d):d=n[15],d});En.displayName=`CommandInput`;function Dn(e){let t=(0,Z.c)(14),n,r,i,a,o;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({className:r,children:n,scrollbarClassName:o,disableHorizontal:i,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o);let s;t[6]===r?s=t[7]:(s=G(`scroll-py-1 overflow-x-hidden h-full min-h-0`,r),t[6]=r,t[7]=s);let c=o??`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,l=i??!0,u;return t[8]!==n||t[9]!==a||t[10]!==s||t[11]!==c||t[12]!==l?(u=(0,Q.jsx)(Ve,{as:Ct.List,"data-slot":`command-list`,outerClassName:`max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0`,className:s,scrollbarClassName:c,disableHorizontal:l,...a,children:n}),t[8]=n,t[9]=a,t[10]=s,t[11]=c,t[12]=l,t[13]=u):u=t[13],u}function On(e){let t=(0,Z.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Q.jsx)(Ct.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function kn(e){let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=G(`text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Q.jsx)(Ct.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function An(e){let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=G(`bg-border -mx-1 h-px`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Q.jsx)(Ct.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function jn(e){let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=G(`data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Q.jsx)(Ct.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Mn(e){let t=(0,Z.c)(27),{branches:n,search:r,local:i,currentBranch:a,branchInfo:o,onCheckout:s}=e,{t:c}=ze(),l;if(t[0]!==n||t[1]!==r){let e=r.trim();l=e?N(n,e,Pn).map(Nn):n,t[0]=n,t[1]=r,t[2]=l}else l=t[2];let u=l,d=i?`gitView.branch.localBranches`:`gitView.branch.remoteBranches`,f;t[3]!==c||t[4]!==d?(f=c(d),t[3]=c,t[4]=d,t[5]=f):f=t[5];let p;if(t[6]!==o||t[7]!==a||t[8]!==u||t[9]!==i||t[10]!==s||t[11]!==c){let e;t[13]!==o||t[14]!==a||t[15]!==i||t[16]!==s||t[17]!==c?(e=e=>(0,Q.jsxs)(jn,{onSelect:()=>s(e),children:[i?(0,Q.jsxs)(`span`,{className:`flex flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e}),(o?.[e]?.ahead||o?.[e]?.behind)&&(0,Q.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[o[e].ahead||0,` ahead ·`,` `,o[e].behind||0,` behind`]})]}):(0,Q.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e}),i&&a===e&&(0,Q.jsx)(`span`,{className:`typography-micro text-primary`,children:c(`gitView.branch.currentBadge`)})]},`${i?`local`:`remote`}-${e}`),t[13]=o,t[14]=a,t[15]=i,t[16]=s,t[17]=c,t[18]=e):e=t[18],p=u.map(e),t[6]=o,t[7]=a,t[8]=u,t[9]=i,t[10]=s,t[11]=c,t[12]=p}else p=t[12];let m;t[19]!==u.length||t[20]!==i||t[21]!==c?(m=u.length===0&&(0,Q.jsx)(jn,{disabled:!0,className:`justify-center`,children:(0,Q.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:c(i?`gitView.branch.noLocalBranches`:`gitView.branch.noRemoteBranches`)})}),t[19]=u.length,t[20]=i,t[21]=c,t[22]=m):m=t[22];let h;return t[23]!==f||t[24]!==p||t[25]!==m?(h=(0,Q.jsxs)(kn,{heading:f,children:[p,m]}),t[23]=f,t[24]=p,t[25]=m,t[26]=h):h=t[26],h}function Nn(e){return e.item}function Pn(e){return e}function Fn(e){let t=(0,Z.c)(9),{options:n,selectedDirectory:r,onSelect:i}=e,{t:a}=ze(),o;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a){let e;t[5]!==i||t[6]!==r||t[7]!==a?(e=e=>(0,Q.jsxs)(jn,{onSelect:()=>i(e.value),children:[(0,Q.jsxs)(`span`,{className:`truncate typography-ui-label text-foreground`,children:[e.pending?`⏳ `:``,e.label]}),r===e.value?(0,Q.jsx)(`span`,{className:`typography-micro text-primary`,children:a(`gitView.branch.currentBadge`)}):null]},`worktree-${e.value}`),t[5]=i,t[6]=r,t[7]=a,t[8]=e):e=t[8],o=n.map(e),t[0]=i,t[1]=n,t[2]=r,t[3]=a,t[4]=o}else o=t[4];return o}var In=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),Ln=({currentBranch:e,localBranches:t,remoteBranches:n,branchInfo:r,onCheckout:i,onCreate:a,remotes:o=[],disabled:s=!1,iconOnly:c=!1,trigger:l,triggerLabel:u,contentAlign:d,hideTooltip:f=!1,projectRootOption:p=null,worktreeOptions:m=[],selectedDirectory:h=null,onSelectDirectory:g,onCreateWorktree:_,worktreesLabel:v,worktreeNewLabel:y,projectRootLabel:b,onOpenChange:x,open:S,presentation:C=`dropdown`})=>{let{t:w}=ze(),[T,E]=X.useState(!1),[D,O]=X.useState(``),[k,A]=X.useState(!1),[ee,j]=X.useState(!1),[M,P]=X.useState(``),[F,te]=X.useState(!1),I=X.useRef(null),L=X.useId(),R=S??T,z=e=>{S===void 0&&E(e),x?.(e)},ne=X.useCallback(e=>{e.stopPropagation()},[]),re=o.length>1,ie=!!(g||_),ae=X.useMemo(()=>In(M),[M]),B=X.useMemo(()=>{let e=D.trim();return e?N(m,e,e=>e.label).map(e=>e.item):m},[D,m]),oe=X.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||N([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),V=t=>{if(t===e){z(!1);return}i(t),z(!1),O(``)},se=e=>{g?.(e),z(!1),O(``)},H=()=>{A(!0),setTimeout(()=>I.current?.focus(),50)},ce=async()=>{if(!(!ae||F)){if(re){j(!0);return}te(!0);try{await a(ae,o[0]),P(``),A(!1),z(!1)}finally{te(!1)}}},le=async e=>{if(!(!ae||F)){te(!0);try{await a(ae,e),P(``),A(!1),j(!1),z(!1)}finally{te(!1)}}},ue=()=>{j(!1)},de=()=>{P(``),A(!1),j(!1)};X.useEffect(()=>{R||(O(``),A(!1),j(!1),P(``))},[R]);let fe=u||e||w(`gitView.branch.detachedHead`),pe=d??(c?`end`:`start`),me=v??w(`chat.chatInput.worktrees`),he=y??w(`chat.chatInput.worktreeNew`),W=b??w(`chat.chatInput.projectRoot`),ge=c?(0,Q.jsx)(`button`,{type:`button`,className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50`,disabled:s,"aria-label":fe,children:(0,Q.jsx)(Y,{name:`git-branch`,className:`size-3.5`})}):(0,Q.jsxs)(U,{variant:`ghost`,size:`xs`,className:`h-6 min-w-0 max-w-full justify-start gap-1 px-0 hover:bg-transparent`,disabled:s,"aria-label":fe,children:[(0,Q.jsx)(Y,{name:`git-branch`,className:`size-3.5 text-primary`}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate typography-ui-label font-semibold text-left text-foreground`,children:fe}),(0,Q.jsx)(Y,{name:`arrow-down-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),_e=(0,Q.jsx)(Ze,{asChild:!0,disabled:s,children:l??ge}),ve=(0,Q.jsxs)(Tn,{className:`h-full min-h-0`,children:[(0,Q.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,Q.jsx)(En,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:ne})}),(0,Q.jsxs)(Dn,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,Q.jsx)(On,{children:w(`gitView.branch.empty`)}),(0,Q.jsx)(kn,{children:ee?(0,Q.jsxs)(`div`,{className:`px-2 py-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:ue,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,Q.jsx)(Y,{name:`arrow-left`,className:`size-4`})}),(0,Q.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[w(`gitView.branch.pushToPrefix`),` `,(0,Q.jsx)(`span`,{className:`text-foreground font-medium`,children:ae}),` `,w(`gitView.branch.pushToSuffix`)]})]}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>le(e),disabled:F,className:`flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50`,children:[(0,Q.jsxs)(`span`,{className:`typography-ui-label text-foreground`,children:[F?(0,Q.jsx)(Y,{name:`loader-4`,className:`inline size-3 mr-1.5 animate-spin`}):null,e.name]}),(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground truncate max-w-full`,children:e.pushUrl})]},e.name))})]}):k?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-lg`,children:[(0,Q.jsx)(`input`,{ref:I,placeholder:w(`gitView.branch.newBranchPlaceholder`),value:M,onChange:e=>P(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{ne(e),e.key===`Enter`?(e.preventDefault(),ce()):e.key===`Escape`&&(e.preventDefault(),de())},className:`flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground`}),(0,Q.jsx)(`button`,{type:`button`,onClick:ce,disabled:!ae||F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:F?(0,Q.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):(0,Q.jsx)(Y,{name:`add`,className:`size-4`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:de,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,Q.jsx)(Y,{name:`close`,className:`size-4`})})]}):(0,Q.jsxs)(jn,{onSelect:H,children:[(0,Q.jsx)(Y,{name:`add`,className:`size-4`}),(0,Q.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,Q.jsx)(An,{}),(0,Q.jsx)(Mn,{branches:t,search:D,local:!0,currentBranch:e,branchInfo:r,onCheckout:V}),(0,Q.jsx)(An,{}),(0,Q.jsx)(Mn,{branches:n,search:D,onCheckout:V}),ie?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(An,{}),(0,Q.jsxs)(kn,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground typography-meta`,children:me}),_?(0,Q.jsx)(`button`,{type:`button`,className:`cursor-pointer text-muted-foreground typography-meta hover:text-foreground`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),z(!1),_()},children:he}):null]}),p&&oe?(0,Q.jsxs)(jn,{onSelect:()=>se(p.value),children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:W}),(0,Q.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:p.label})]}),h===p.value?(0,Q.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]}):null,(0,Q.jsx)(Fn,{options:B,selectedDirectory:h,onSelect:se})]})]}):null]})]});if(C===`mobile-sheet`){let e=X.cloneElement(l??ge,{onClick:()=>z(!0),"data-popup-open":R?``:void 0});return(0,Q.jsxs)(Q.Fragment,{children:[e,(0,Q.jsx)(He,{id:`mobile-draft-branch-picker-sheet-${L}`,open:R,onOpenChange:z,ariaLabel:w(`gitView.branch.selectBranch`),closeAriaLabel:w(`mobile.surface.closeAria`),resizeAriaLabel:w(`mobile.sessions.sheet.resizeAria`),children:ve})]})}return(0,Q.jsxs)($e,{open:R,onOpenChange:z,children:[f||l?_e:(0,Q.jsxs)(Xe,{children:[(0,Q.jsx)(Je,{asChild:!0,children:_e}),(0,Q.jsx)(Ye,{sideOffset:8,children:c?fe:w(`gitView.branch.currentBranchTooltip`)})]}),(0,Q.jsx)(Qe,{align:pe,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:ve})]})};function Rn(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=N(t,i,e=>e),o=N(n,i,e=>e),s=new Set(a.map(e=>e.item)),c=new Set(o.map(e=>e.item));return{matching:[...a.map(e=>({label:e.item,value:e.item,source:`local`,score:e.score})),...o.map(e=>({label:e.item,value:`remotes/${e.item}`,source:`remote`,score:e.score}))].sort((e,t)=>e.score===t.score?e.source===t.source?e.label.length===t.label.length?e.label.localeCompare(t.label,void 0,{sensitivity:`accent`}):e.label.length-t.label.length:e.source===`local`?-1:1:e.score-t.score).map(({label:e,value:t,source:n})=>({label:e,value:t,source:n})),otherLocal:t.filter(e=>!s.has(e)),otherRemote:n.filter(e=>!c.has(e))}}function zn(e){let t=D(e),n=(e,n={})=>t.json(`/api/github/${e}`,{query:n}),r=e=>e?{owner:e.owner,repo:e.repo}:{};return{authStatus:()=>n(`auth/status`),issuesList:(e,t)=>n(`issues/list`,{directory:e,page:t?.page,query:t?.query}),prsList:(e,t)=>n(`pulls/list`,{directory:e,page:t?.page,query:t?.query}),issueGet:(e,t,i)=>n(`issues/get`,{directory:e,number:t,...r(i?.sourceRepo)}),issueComments:(e,t,i)=>n(`issues/comments`,{directory:e,number:t,...r(i?.sourceRepo)}),prContext:(e,t,i)=>n(`pulls/context`,{directory:e,number:t,...r(i?.sourceRepo),diff:i?.includeDiff?`1`:void 0,checkDetails:i?.includeCheckDetails?`1`:void 0})}}var Bn=e=>({queryKey:[...e.queryScope,`worktree-dialog`,`github-auth`],queryFn:({signal:t})=>D(e).json(`/api/github/auth/status`,{signal:t}),staleTime:3e4,gcTime:1/0});function Vn(e,t){let n=(0,Z.c)(12),r=O(),i=e?void 0:r.github,a;n[0]!==e||n[1]!==i?(a=e?zn(e):i,n[0]=e,n[1]=i,n[2]=a):a=n[2];let o=a,s;n[3]!==e||n[4]!==r?(s=e?Bn(e):dt(r.github),n[3]=e,n[4]=r,n[5]=s):s=n[5];let c;n[6]!==t||n[7]!==s?(c={...s,enabled:t},n[6]=t,n[7]=s,n[8]=c):c=n[8];let l=w(c,k),u;return n[9]!==l||n[10]!==o?(u={github:o,auth:l},n[9]=l,n[10]=o,n[11]=u):u=n[11],u}async function Hn(e,t,n={}){let r=await D(e).json(`/api/magic-prompts`);return(typeof r.overrides?.[t]==`string`?r.overrides[t]:it(t)).replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g,(e,t)=>Object.prototype.hasOwnProperty.call(n,t)?n[t]??``:``)}async function Un(e,t,n,r,a,o){let s=zn(t),c=a.issue,l=a.pr;if(!c&&!l)return;let u=c?`issue`:`pr`,d=c?.number??l.number,f=await Hn(t,`github.${u}.review.visible`,{[`${u}_number`]:String(d)}),p=await Hn(t,`github.${u}.review.instructions`),m;if(c){let e=await s.issueGet(t.location.directory,d,{sourceRepo:c.sourceRepo}),n=await s.issueComments(t.location.directory,d,{sourceRepo:c.sourceRepo});if(e.connected===!1||!e.issue||n.connected===!1)throw Error(o);m=`GitHub issue context (JSON)\n${JSON.stringify({repo:e.repo??null,issue:e.issue,comments:n.comments??[]},null,2)}`}else{let e=await s.prContext(t.location.directory,d,{sourceRepo:l.sourceRepo,includeDiff:a.includeDiff,includeCheckDetails:!1});if(e.connected===!1||!e.pr)throw Error(o);m=`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`}t.sdk();let h=e.resolve({...t.location,directory:n});await me(e,h).state.send({sessionID:r,messageID:i(`msg`),text:[f,p,m].join(`
|
|
3
3
|
|
|
4
|
-
`)})}function Wn(e){let t=(0,Z.c)(41),{project:n,open:r,onClose:i,children:a}=e,o=E(),s=n?.hostId&&o&&o.entry.location.hubId===n.hubId&&o.entry.location.hostId===n.hostId&&o.entry.location.directory===n.path,c=Le(!!(r&&n?.hostId&&!s)),{t:l}=ze();if(!n?.hostId){let e;return t[0]===a?e=t[1]:(e=(0,Q.jsx)(T.Provider,{value:null,children:a}),t[0]=a,t[1]=e),e}if(s)return a;if(!r)return null;if(!c.registry||c.registry.hubId!==n.hubId){let e;t[2]===i?e=t[3]:(e=e=>{e||i()},t[2]=i,t[3]=e);let n;t[4]===l?n=t[5]:(n=l(`session.newWorktree.title`),t[4]=l,t[5]=n);let r;t[6]===n?r=t[7]:(r=(0,Q.jsx)(Ue,{children:(0,Q.jsx)(Ke,{children:n})}),t[6]=n,t[7]=r);let a=c.isPending?`status`:`alert`,o;t[8]!==c.error?.message||t[9]!==c.isPending||t[10]!==l?(o=c.isPending?l(`remoteProjects.running`):c.error?.message||l(`remoteProjects.host-unavailable`),t[8]=c.error?.message,t[9]=c.isPending,t[10]=l,t[11]=o):o=t[11];let s;t[12]!==a||t[13]!==o?(s=(0,Q.jsx)(`p`,{role:a,children:o}),t[12]=a,t[13]=o,t[14]=s):s=t[14];let u;t[15]===l?u=t[16]:(u=l(`session.newWorktree.actions.cancel`),t[15]=l,t[16]=u);let d;t[17]!==i||t[18]!==u?(d=(0,Q.jsx)(U,{onClick:i,children:u}),t[17]=i,t[18]=u,t[19]=d):d=t[19];let f;t[20]!==c.isPending||t[21]!==l?(f=c.isPending?null:(0,Q.jsx)(U,{onClick:Gn,children:l(`remoteProjects.retry`)}),t[20]=c.isPending,t[21]=l,t[22]=f):f=t[22];let p;t[23]!==d||t[24]!==f?(p=(0,Q.jsxs)(We,{children:[d,f]}),t[23]=d,t[24]=f,t[25]=p):p=t[25];let m;t[26]!==p||t[27]!==r||t[28]!==s?(m=(0,Q.jsxs)(Ge,{children:[r,s,p]}),t[26]=p,t[27]=r,t[28]=s,t[29]=m):m=t[29];let h;return t[30]!==e||t[31]!==m?(h=(0,Q.jsx)(qe,{open:!0,onOpenChange:e,children:m}),t[30]=e,t[31]=m,t[32]=h):h=t[32],h}let u;t[33]!==n.hostId||t[34]!==n.hubId||t[35]!==n.path?(u={hubId:n.hubId,hostId:n.hostId,directory:n.path},t[33]=n.hostId,t[34]=n.hubId,t[35]=n.path,t[36]=u):u=t[36];let d;return t[37]!==a||t[38]!==c.registry||t[39]!==u?(d=(0,Q.jsx)(A,{registry:c.registry,location:u,children:a}),t[37]=a,t[38]=c.registry,t[39]=u,t[40]=d):d=t[40],d}function Gn(){Re().catch(Kn)}function Kn(){}var qn=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null};function Jn(e,t){return`${e}\0${t}`}function Yn(e){let t=(0,Z.c)(12),n;t[0]===e.projectId?n=t[1]:(n=t=>qn(t.projects,t.activeProjectId,e.projectId),t[0]=e.projectId,t[1]=n);let r=R(n),i;t[2]===e?i=t[3]:(i=()=>e.onOpenChange(!1),t[2]=e,t[3]=i);let a=r?.id,o;t[4]!==e||t[5]!==a?(o=(0,Q.jsx)(Xn,{...e},a),t[4]=e,t[5]=a,t[6]=o):o=t[6];let s;return t[7]!==r||t[8]!==e.open||t[9]!==i||t[10]!==o?(s=(0,Q.jsx)(Wn,{project:r,open:e.open,onClose:i,children:o}),t[7]=r,t[8]=e.open,t[9]=i,t[10]=o,t[11]=s):s=t[11],s}function Xn({open:e,onOpenChange:t,onSelect:n,projectId:r}){let{t:i}=ze(),a=M(e=>e.isMobile),o=E(),s=o?.entry.location.hostId?o.entry:void 0,{git:c}=et(),{github:l,auth:u}=Vn(s,e),d=u.data??null,f=u.isFetched,p=M(e=>e.setSettingsDialogOpen),m=M(e=>e.setSettingsPage),h=R(e=>qn(e.projects,e.activeProjectId,r)),g=h?.id??null,_=h?.path??null,v=X.useMemo(()=>_&&g?{id:g,path:_,hostId:h?.hostId,hubId:h?.hubId}:null,[g,_,h?.hostId,h?.hubId]),[y,b]=X.useState(`issues`),[x,S]=X.useState(``),[C,w]=X.useState([]),[T,D]=X.useState([]),[O,k]=X.useState(!1),[A,j]=X.useState(!1),[N,P]=X.useState(null),[F,te]=X.useState(null),[I,L]=X.useState(null),[z,ne]=X.useState(!1),[re,ie]=X.useState(new Map),[ae,B]=X.useState(1),[oe,V]=X.useState(!1),se=X.useRef(0),H=ct(x,350),ce=ee(async e=>{if(!(!_||!l)&&!(f&&d?.connected===!1)){k(!0),P(null),B(1),V(!1);try{if(y===`issues`&&l.issuesList){let t=await l.issuesList(_,{page:1,query:e});t.connected===!1?(P(i(`session.githubIntegration.error.notConnected`)),w([])):(w(t.issues??[]),B(t.page??1),V(!!t.hasMore))}else if(y===`prs`&&l.prsList){let t=await l.prsList(_,{page:1,query:e});t.connected===!1?(P(i(`session.githubIntegration.error.notConnected`)),D([])):(D(t.prs??[]),B(t.page??1),V(!!t.hasMore))}}catch(e){P(e instanceof Error?e.message:i(`session.githubIntegration.error.loadDataFailed`))}finally{k(!1)}}});X.useEffect(()=>{if(!e||!_||f&&d?.connected===!1||!l)return;if(!H.trim()){ce();return}let t=new AbortController;k(!0),P(null),B(1),V(!1);let n=y===`issues`&&l.issuesList?l.issuesList(_,{page:1,query:H.trim()}):y===`prs`&&l.prsList?l.prsList(_,{page:1,query:H.trim()}):null;if(!n){k(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(P(i(`session.githubIntegration.error.notConnected`)),w([])):(w(e.issues??[]),B(e.page??1),V(!!e.hasMore)):`prs`in e&&(e.connected===!1?(P(i(`session.githubIntegration.error.notConnected`)),D([])):(D(e.prs??[]),B(e.page??1),V(!!e.hasMore))))}).catch(e=>{t.signal.aborted||P(e instanceof Error?e.message:i(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||k(!1)}),()=>t.abort()},[e,_,l,f,d,y,H,ce,i]);let le=ee(async()=>{if(!(!_||!l)&&!(O||A)&&oe){j(!0);try{let e=ae+1;if(y===`issues`&&l.issuesList){let t=H.trim()?await l.issuesList(_,{page:e,query:H.trim()}):await l.issuesList(_,{page:e});t.connected!==!1&&(w(e=>[...e,...t.issues??[]]),B(t.page??e),V(!!t.hasMore))}else if(y===`prs`&&l.prsList){let t=H.trim()?await l.prsList(_,{page:e,query:H.trim()}):await l.prsList(_,{page:e});t.connected!==!1&&(D(e=>[...e,...t.prs??[]]),B(t.page??e),V(!!t.hasMore))}}catch{}finally{j(!1)}}});X.useEffect(()=>{if(!e){b(`issues`),S(``),w([]),D([]),te(null),L(null),ne(!1),P(null),ie(new Map),B(1),V(!1);return}ce()},[e,ce]),X.useEffect(()=>{se.current+=1,ie(new Map)},[_,v]);let ue=ee(async e=>{if(!v||!e)return;let t=Jn(v.path,e);if(re.has(t))return;let n=se.current;try{let r={mode:`new`,branchName:e,worktreeName:e},a=s?await c.validateGitWorktree(v.path,r):await ft(v,r);if(n!==se.current)return;let o=a.errors.find(e=>e.code===`branch_in_use`);ie(e=>new Map(e).set(t,{isValid:!o,error:o?i(o.code===`branch_exists`?`session.githubIntegration.validation.branchAlreadyExists`:`session.githubIntegration.validation.branchAlreadyCheckedOut`):null}))}catch{if(n!==se.current)return;ie(e=>new Map(e).set(t,{isValid:!1,error:i(`session.githubIntegration.validation.failed`)}))}});X.useEffect(()=>{!e||y!==`prs`||T.forEach(e=>{e.head&&ue(e.head)})},[e,y,T,_,v,ue]);let de=f&&d?.connected===!0,fe=()=>{if(s){K.info(i(`remoteProjects.configurationReadOnly`));return}m(`github`),p(!0)},pe=e=>{te(e),L(null)},me=e=>{L(e),te(null)},he=()=>{F?n({type:`issue`,item:F}):I&&n({type:`pr`,item:I,includeDiff:z}),t(!1)},W=()=>{te(null),L(null),ne(!1)},ge=F||(I?.head&&_?re.get(Jn(_,I.head))?.isValid!==!1:!1),_e=e=>!e.head||(_?re.get(Jn(_,e.head)):void 0)?.isValid===!1,ve=(0,Q.jsxs)(Q.Fragment,{children:[s&&u.error?(0,Q.jsxs)(`div`,{role:`alert`,className:`typography-small text-destructive`,children:[u.error.message,(0,Q.jsx)(U,{variant:`ghost`,size:`xs`,onClick:()=>{u.refetch()},children:i(`remoteProjects.retry`)})]}):null,de?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`yuri-picker-search relative mt-2`,children:[(0,Q.jsx)(Y,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,Q.jsx)(st,{value:x,onChange:e=>S(e.target.value),placeholder:i(y===`issues`?`session.githubIntegration.search.issuesPlaceholder`:`session.githubIntegration.search.prsPlaceholder`),className:`h-8 pl-9`})]}),(0,Q.jsx)(`div`,{className:`yuri-picker-list mt-2 h-[300px] overflow-hidden`,children:(0,Q.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[O&&(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsx)(Y,{name:`loader-4`,className:`h-5 w-5 animate-spin text-muted-foreground`})}),N&&(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive`,children:[(0,Q.jsx)(Y,{name:`error-warning`,className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`typography-small`,children:N})]})}),!O&&!N&&y===`issues`&&(0,Q.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[C.length>0?C.map(e=>(0,Q.jsx)(`button`,{onClick:()=>pe(e),className:G(`yuri-picker-row w-full text-left px-2 py-1.5 rounded transition-colors`,F?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`yuri-picker-label typography-small line-clamp-2`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,Q.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)):(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:i(`session.githubIntegration.empty.noIssuesFound`)}),oe&&!A&&(0,Q.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,Q.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>void le(),className:`h-7 text-xs`,children:i(`session.githubIntegration.actions.loadMore`)})}),A&&(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,Q.jsx)(Y,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]}),!O&&!N&&y===`prs`&&(0,Q.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[T.length>0?T.map(e=>{let t=_e(e),n=e.head&&_?re.get(Jn(_,e.head)):void 0;return(0,Q.jsx)(`button`,{onClick:()=>!t&&me(e),disabled:t,className:G(`yuri-picker-row w-full text-left px-2 py-1.5 rounded transition-colors`,I?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:t?`opacity-50 cursor-not-allowed`:`hover:bg-interactive-hover`),children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`yuri-picker-label typography-small line-clamp-1`,children:e.title}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,Q.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[e.head,` → `,e.base]}),e.sourceRepo?.source===`upstream`?(0,Q.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,t&&n?.error&&(0,Q.jsx)(`span`,{className:`typography-micro text-destructive`,children:n.error})]})]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)}):(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:i(`session.githubIntegration.empty.noPullRequestsFound`)}),oe&&!A&&(0,Q.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,Q.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>void le(),className:`h-7 text-xs`,children:i(`session.githubIntegration.actions.loadMore`)})}),A&&(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,Q.jsx)(Y,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]})]})})]}):(0,Q.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 gap-4`,children:[(0,Q.jsx)(Y,{name:`github`,className:`h-12 w-12 text-muted-foreground`}),(0,Q.jsxs)(`div`,{className:`text-center`,children:[(0,Q.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:i(`session.githubIntegration.connect.title`)}),(0,Q.jsx)(`p`,{className:`typography-small text-muted-foreground mt-1`,children:i(`session.githubIntegration.connect.description`)})]}),(0,Q.jsx)(U,{onClick:fe,size:`sm`,children:i(`session.githubIntegration.connect.action`)})]})]}),ye=(0,Q.jsxs)(`div`,{className:G(`w-full`,a?`flex flex-col gap-2`:`flex flex-row items-center`),children:[(0,Q.jsxs)(`div`,{className:G(`flex items-center gap-4`,a?`w-full justify-center order-1`:`flex-1`),children:[!a&&(F||I)&&(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,Q.jsx)(`span`,{className:`typography-small truncate max-w-[150px]`,children:F?i(`session.githubIntegration.selected.issueNumber`,{number:F.number}):i(`session.githubIntegration.selected.prNumber`,{number:I?.number??``})}),(0,Q.jsx)(`button`,{onClick:W,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,Q.jsx)(Y,{name:`close`,className:`h-3.5 w-3.5`})})]}),y===`prs`&&I&&(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,Q.jsx)(lt,{checked:z,onChange:e=>ne(e),ariaLabel:i(`session.githubIntegration.includeDiffAria`)}),(0,Q.jsx)(`span`,{className:`typography-small text-foreground`,children:i(`session.githubIntegration.includeDiff`)})]})]}),(0,Q.jsxs)(`div`,{className:G(`flex gap-2`,a?`w-full order-2`:`justify-end`),children:[(0,Q.jsx)(U,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:G(a&&`flex-1`),children:i(`session.githubIntegration.actions.cancel`)}),(0,Q.jsx)(U,{size:`sm`,onClick:he,disabled:!ge,className:G(a&&`flex-1`),children:i(`session.githubIntegration.actions.select`)})]})]});return(0,Q.jsx)(Q.Fragment,{children:a?(0,Q.jsx)(ut,{open:e,title:i(`session.githubIntegration.title`),onClose:()=>t(!1),footer:de?ye:void 0,renderHeader:e=>(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 px-3 py-2 border-b border-border/40`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:i(`session.githubIntegration.title`)}),e]}),(0,Q.jsx)(`div`,{className:`w-full`,children:(0,Q.jsx)(wt,{items:[{id:`issues`,label:i(`session.githubIntegration.tabs.issues`),icon:(0,Q.jsx)(Y,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:i(`session.githubIntegration.tabs.pullRequests`),icon:(0,Q.jsx)(Y,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:y,onSelect:e=>{b(e),S(``)},variant:`active-pill`,layoutMode:`fit`})}),(F||I)&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,Q.jsx)(`span`,{className:`typography-small truncate flex-1`,children:F?i(`session.githubIntegration.selected.issueNumber`,{number:F.number}):i(`session.githubIntegration.selected.prNumber`,{number:I?.number??``})}),(0,Q.jsx)(`button`,{onClick:W,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,Q.jsx)(Y,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),children:ve}):(0,Q.jsx)(qe,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ge,{presentation:`picker`,children:[(0,Q.jsx)(Ue,{className:`yuri-picker-header`,children:(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-3`,children:[(0,Q.jsx)(Ke,{className:`yuri-picker-title`,children:i(`session.githubIntegration.title`)}),(0,Q.jsx)(`div`,{className:`w-[220px]`,children:(0,Q.jsx)(wt,{items:[{id:`issues`,label:i(`session.githubIntegration.tabs.issues`),icon:(0,Q.jsx)(Y,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:i(`session.githubIntegration.tabs.pullRequests`),icon:(0,Q.jsx)(Y,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:y,onSelect:e=>{b(e),S(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),ve,(0,Q.jsx)(We,{className:`yuri-picker-footer`,children:ye})]})})})}var Zn=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),$=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``).split(`/`).join(`-`).replace(/[^A-Za-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``).slice(0,80),Qn=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,$n=(e,t,n)=>{let r=Zn(e.head||``);if(!r)throw Error(`PR head branch is missing`);if(t.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};let i=n.find(e=>{let t=e.indexOf(`/`);return t<=0||t>=e.length-1?!1:e.slice(t+1)===r});if(i){let e=i.indexOf(`/`),t=i.slice(0,e);return{existingBranch:`remotes/${i}`,setUpstream:!0,upstreamRemote:t,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${t}/${r}`}}let a=String(e.headLabel||``).split(`:`)[0]?.trim(),o=`pr-${Qn(e.headRepo?.owner||a||`pr-head`)}`,s=e.headRepo?.sshUrl||e.headRepo?.cloneUrl||``;if(!s)throw Error(`PR head repository URL is unavailable`);return{existingBranch:`remotes/${o}/${r}`,setUpstream:!0,upstreamRemote:o,upstreamBranch:r,ensureRemoteName:o,ensureRemoteUrl:s,sourceLabel:`${o}/${r}`}},er=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},tr=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function nr(e){let t=(0,Z.c)(12),n;t[0]===e.projectId?n=t[1]:(n=t=>qn(t.projects,t.activeProjectId,e.projectId),t[0]=e.projectId,t[1]=n);let r=R(n),i;t[2]===e?i=t[3]:(i=()=>e.onOpenChange(!1),t[2]=e,t[3]=i);let a=r?.id,o;t[4]!==e||t[5]!==a?(o=(0,Q.jsx)(rr,{...e},a),t[4]=e,t[5]=a,t[6]=o):o=t[6];let s;return t[7]!==r||t[8]!==e.open||t[9]!==i||t[10]!==o?(s=(0,Q.jsx)(Wn,{project:r,open:e.open,onClose:i,children:o}),t[7]=r,t[8]=e.open,t[9]=i,t[10]=o,t[11]=s):s=t[11],s}function rr({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=ze(),{git:a}=et(),o=E(),s=o?.entry.location.hostId?o.entry:void 0,{github:c,auth:l}=Vn(s,e),u=M(e=>e.isMobile),d=X.useId(),f=l.data??null,p=l.isFetched,m=R(e=>qn(e.projects,e.activeProjectId,r)),h=m?.path??null,g=X.useMemo(()=>h&&m?{id:m.id,path:h,hostId:m.hostId,hubId:m.hubId}:null,[m,h]),[_,v]=X.useState(`new-branch`),[y,b]=X.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,S]=X.useState({selectedBranch:``,worktreeName:``}),C=ot(h),T=at(e=>h?e.directories.get(h)?.isLoadingBranches??!1:!1),D=at(e=>e.fetchBranches),O=X.useMemo(()=>C?.all?C.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[C]),A=X.useMemo(()=>C?.all?C.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[C]),ee=W(e=>e.availableWorktreesByProject),j=w({queryKey:[...s?.queryScope??[`local`],`worktree-dialog`,`worktrees`],enabled:!!(s&&e&&h),queryFn:()=>a.listGitWorktrees(h),staleTime:3e4,gcTime:1/0},k),N=X.useMemo(()=>{if(!h)return new Set;let e=s?j.data??[]:ee.get(h)??[];return new Set(e.map(e=>e.name))},[ee,h,s,j.data]),P=X.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=cn();if(!N.has(e))return e}return`${cn()}-${Date.now().toString(36).slice(-4)}`},[N]),[F,te]=X.useState(!1),[I,z]=X.useState(!1),[ne,ie]=X.useState(!1),[ae,B]=X.useState(!1),[oe,V]=X.useState(!1),[se,H]=X.useState(``),[ce,de]=X.useState(``),fe=X.useRef(null),pe=X.useRef(null),me=X.useRef(null),he=X.useRef(null),_e=X.useCallback(e=>{e.stopPropagation()},[]),ve=X.useCallback(e=>{let t=e;for(;t&&t!==document.body;){let{overflowY:e}=window.getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null},[]),be=X.useCallback(e=>{e&&(e.scrollTop=0)},[]),xe=X.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;be(t)},[be]),Ce=X.useCallback(e=>{let t=ve(e.current);be(t)},[ve,be]),we=X.useMemo(()=>Rn({localBranches:O,remoteBranches:A,query:se}),[O,A,se]),Te=X.useMemo(()=>Rn({localBranches:O,remoteBranches:A,query:ce}),[O,A,ce]),De=se.trim().length>0,Oe=ce.trim().length>0,Ae=we.matching.length>0,je=Te.matching.length>0,Me=!!(h&&a),Ne=X.useCallback(()=>{!h||!a||D(h,a)},[h,a,D]);X.useEffect(()=>{!e||!h||!a||C?.all||D(h,a)},[e,h,a,C?.all,D]),X.useEffect(()=>{!I&&!ae&&H(``)},[I,ae]),X.useEffect(()=>{!ne&&!oe&&de(``)},[ne,oe]),X.useEffect(()=>{I&&xe(fe),ae&&Ce(me)},[I,ae,se,xe,Ce]),X.useEffect(()=>{ne&&xe(pe),oe&&Ce(he)},[ne,oe,ce,xe,Ce]);let[q,J]=X.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[Pe,Fe]=X.useState(!1),[Ie,Le]=X.useState(null),Re=X.useCallback(()=>{let e=ue.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),Be=X.useCallback(()=>{let e=ue.getState(),t=e.settingsDefaultModel??(e.currentModelId?void 0:e.opencodeDefaultModel);if(!t)return null;let n=re(t);if(!n)return null;let{providerId:r,modelId:i}=n;return{providerID:r,modelID:i}},[]),Je=X.useCallback((e,t)=>{let n=ue.getState(),r=re(n.settingsDefaultModel??n.opencodeDefaultModel),i=r?.providerId===e&&r.modelId===t?r.variant??n.settingsDefaultVariant:void 0,a=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0;return i??a},[]),Ye=X.useCallback(async e=>{if(!h||!c)return;let t=ue.getState(),n=ke.getState().lastUsedProvider,r=Be(),a=r?.providerID||t.currentProviderId||n?.providerID,o=r?.modelID||t.currentModelId||n?.modelID,s=Re()||t.currentAgentName||void 0;if(!a||!o){K.error(i(`session.newWorktree.error.noModelSelected`));return}let l=Je(a,o);if(e.issue){if(!c.issueGet||!c.issueComments)return;let t=await c.issueGet(h,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(t.connected===!1||!t.repo||!t.issue)throw Error(`Failed to load issue context`);let n=await c.issueComments(h,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await tt(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await tt(`github.issue.review.instructions`),d=er({repo:t.repo,issue:t.issue,comments:n.comments??[]});await W.getState().sendMessage(r,a,o,s,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),K.success(i(`session.newWorktree.toast.sessionFromIssue`));return}if(e.pr){if(!c.prContext)return;let t=await c.prContext(h,e.pr.number,{sourceRepo:e.pr.sourceRepo??null,includeDiff:e.includeDiff,includeCheckDetails:!1});if(t.connected===!1||!t.repo||!t.pr)throw Error(`Failed to load PR context`);let n=await tt(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await tt(`github.pr.review.instructions`),u=tr(t);await W.getState().sendMessage(n,a,o,s,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),K.success(i(`session.newWorktree.toast.sessionFromPr`))}},[c,h,Re,Be,Je,i]),Xe=_===`new-branch`?y:x;X.useEffect(()=>{if(!e||!C?.all||!h||y.sourceBranch)return;let t=y.sourceBranch,n=!1;return(async()=>{try{let e=s?(await a.getGitStatus(h)).current:await mt(h).catch(()=>null);if(n)return;let r=localStorage.getItem(xt),{sourceBranch:i,shouldClearSavedSourceBranch:o}=vt({branches:C.all,savedSourceBranch:r,rootBranch:e});if(o&&localStorage.removeItem(xt),n||t)return;i&&b(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,C?.all,h,y.sourceBranch,s,a]),X.useLayoutEffect(()=>{if(!e)return;v(`new-branch`),S({selectedBranch:``,worktreeName:``}),z(!1),ie(!1),B(!1),V(!1),H(``),de(``),J({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=P();b({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,P]),X.useEffect(()=>{if(_!==`new-branch`||!y.isSyncingWorktreeName)return;let e=$(Zn(y.branchName));b(t=>({...t,worktreeName:e}))},[_,y.branchName,y.isSyncingWorktreeName]);let nt=X.useCallback(async()=>{if(!g||!q.touched||Pe)return;Ie&&Ie.abort();let e=new AbortController;Le(e),J(e=>({...e,isValidating:!0}));try{let t=_===`new-branch`?y.branchName:x.selectedBranch,n=Xe.worktreeName,r=Zn(t),o=$(n),c=null,l=null;if(r||(c=i(`session.newWorktree.error.branchNameRequired`)),o||(l=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&o){let t=_===`new-branch`?y.linkedPr:null,n=t?$n(t,O,A):null,i={mode:_===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:o,existingBranch:n?.existingBranch??(_===`existing-branch`?r:void 0),...n?.ensureRemoteName?{ensureRemoteName:n.ensureRemoteName}:{},...n?.ensureRemoteUrl?{ensureRemoteUrl:n.ensureRemoteUrl}:{}},u=s?await a.validateGitWorktree(h,i):await ft(g,i);if(e.signal.aborted)return;u.ok||u.errors.forEach(e=>{if(e.code===`worktree_exists`){l??=e.message;return}e.code.startsWith(`branch_`)&&(c??=e.message)})}e.signal.aborted||J(e=>({...e,isValidating:!1,branchError:c,worktreeError:l}))}catch{e.signal.aborted||J(e=>({...e,isValidating:!1}))}},[s,a,h,g,_,y.branchName,y.linkedPr,x.selectedBranch,Xe.worktreeName,O,A,q.touched,Ie,Pe,i]),rt=_===`new-branch`?y.branchName:x.selectedBranch;X.useEffect(()=>{if(!e||!g||!q.touched||Pe)return;let t=setTimeout(()=>{nt()},300);return()=>clearTimeout(t)},[Xe.worktreeName,rt,e,g,nt,q.touched,Pe]);let it=async()=>{if(!g||!h){K.error(i(`session.newWorktree.error.noActiveProject`));return}J(e=>({...e,touched:!0}));let e=_===`new-branch`?y.branchName:x.selectedBranch,r=Xe.worktreeName,a=Zn(e),c=$(r);if(!a){K.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!c){K.error(i(`session.newWorktree.error.worktreeDirectoryRequired`));return}Ie&&(Ie.abort(),Le(null)),J(e=>({...e,isValidating:!1,branchError:null,worktreeError:null})),Fe(!0);try{let e=_===`new-branch`?y.linkedPr:null,r=_===`new-branch`?y.linkedIssue:null,l=_===`new-branch`?y.linkedPr:null,u=_===`new-branch`&&y.includePrDiff,d=!!(r||l);if(s&&o&&m?.hostId){let l=m;R.getState().setActiveProjectIdOnly(l.id);let f=e?$n(e,O,A):null,p=r?`#${r.number} ${r.title}`.trim():e?`#${e.number} ${e.title}`.trim():void 0,h=await un(l,{mode:f||_===`existing-branch`?`existing`:`new`,worktreeName:c,branchName:_===`new-branch`?a:void 0,existingBranch:f?.existingBranch??(_===`existing-branch`?a:void 0),..._===`new-branch`&&!f&&y.sourceBranch?{startRef:y.sourceBranch}:{},...f?{setUpstream:f.setUpstream,upstreamRemote:f.upstreamRemote,upstreamBranch:f.upstreamBranch,...f.ensureRemoteName?{ensureRemoteName:f.ensureRemoteName}:{},...f.ensureRemoteUrl?{ensureRemoteUrl:f.ensureRemoteUrl}:{}}:{}},{title:p,createSession:d,kind:e?`pr`:`standard`,createdFromBranch:f?.sourceLabel??y.sourceBranch,isSelected:()=>R.getState().activeProjectId===l.id});s.sdk();let g=L.getState().remoteSession;g?.projectId===l.id&&g.location.hubId===s.location.hubId&&g.location.hostId===s.location.hostId&&g.location.directory===h.path&&g.sessionId===(h.id??null)&&n?.(h.path,{...h.id?{sessionId:h.id}:{},remote:!0}),t(!1),K.success(i(`session.newWorktree.toast.worktreeCreated`)),h.id&&d&&Un(o.registry,s,h.path,h.id,{issue:r,pr:e,includeDiff:u},i(`session.newWorktree.error.sendGitHubContextFailed`)).catch(e=>{K.error(i(`session.newWorktree.error.sendGitHubContextFailed`),{description:e instanceof Error?e.message:String(e)})});return}let[f,p]=await Promise.all([Ee(g),gt(h)]),v=y.sourceBranch,b=``,S=(()=>{if(e){let t=$n(e,O,A);return b=t.sourceLabel,{preferredName:a||c,mode:`existing`,branchName:a,worktreeName:c,existingBranch:t.existingBranch,setupCommands:f,setUpstream:t.setUpstream,upstreamRemote:t.upstreamRemote,upstreamBranch:t.upstreamBranch,returnAfterDirectoryCreated:!0,...t.ensureRemoteName?{ensureRemoteName:t.ensureRemoteName}:{},...t.ensureRemoteUrl?{ensureRemoteUrl:t.ensureRemoteUrl}:{}}}return b=_===`new-branch`?v:``,{preferredName:a||c,mode:_===`existing-branch`?`existing`:`new`,branchName:_===`existing-branch`?void 0:a,worktreeName:c,existingBranch:_===`existing-branch`?a:void 0,setupCommands:f,returnAfterDirectoryCreated:!0,...v&&_===`new-branch`?{startRef:v}:{}}})(),C=await yt(h,S,{resolvedRootTrackingRemote:p}),w=await ht(g,C),T=null;if(d){await Se(g)&&await ye(w.worktreeRoot??w.path);let e=r?`#${r.number} ${r.title}`.trim():l?`#${l.number} ${l.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await le(e,w.path,null);if(!a?.id)throw Error(`Failed to create session`);T=a.id,n?.(w.path,{sessionId:T}),t(!1),Fe(!1),ge(a.id,e).catch(()=>void 0);try{W.getState().initializeNewYuriSession(a.id,ue.getState().agents)}catch{}}else t(!1),Fe(!1);let E=bt({mode:_,sourceBranch:y.sourceBranch,linkedPr:!!y.linkedPr,selectedBranch:x.selectedBranch});E&&localStorage.setItem(xt,E),K.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${w.branch||w.name}${b?` ${i(`session.newWorktree.fromSource`,{source:b})}`:``}`})}),T?Ye({sessionId:T,directory:w.path,issue:r,pr:l,includeDiff:u}).catch(e=>{let t=e instanceof Error?e.message:i(`session.newWorktree.error.sendGitHubContextFailed`);K.error(i(`session.newWorktree.error.sendGitHubContextFailed`),{description:t})}):n?.(w.path)}catch(e){let t=e instanceof Error?e.message:i(`session.newWorktree.error.createWorktreeFailed`);K.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{Fe(!1)}},ct=e=>{v(e),J(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},lt=e=>{if(!e){b(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${cn()}`;b(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:$(n),isSyncingWorktreeName:!0}))}else if(e.type===`pr`){let t=e.item;b(n=>({...n,linkedPr:t,linkedIssue:null,includePrDiff:e.includeDiff??!1,branchName:t.head,worktreeName:$(t.head),isSyncingWorktreeName:!0}))}},dt=p&&f?.connected===!0,pt=(_===`existing-branch`?!!x.selectedBranch&&!!x.worktreeName&&!q.branchError&&!q.worktreeError:!!Zn(y.branchName)&&!!y.worktreeName&&!q.branchError&&!q.worktreeError)&&!Pe,_t=()=>{b(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},St=s&&(j.error||l.error)?(0,Q.jsxs)(`div`,{role:`alert`,className:`typography-micro text-destructive`,children:[(j.error||l.error)?.message,(0,Q.jsx)(U,{size:`xs`,variant:`ghost`,onClick:()=>{j.refetch(),l.refetch()},children:i(`remoteProjects.retry`)})]}):null,Ct=(0,Q.jsxs)(`div`,{className:G(`flex gap-2`,u?`flex-col w-full`:`flex-row items-center`),children:[St,(0,Q.jsx)(`div`,{className:G(`flex items-center gap-1.5 text-destructive`,u?`w-full justify-center order-first`:`mr-auto`),children:q.touched&&(q.branchError||q.worktreeError)&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Y,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:q.branchError||q.worktreeError})]})}),(0,Q.jsxs)(`div`,{className:G(`flex gap-2`,u&&`w-full`),children:[(0,Q.jsx)(U,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:Pe,className:G(u&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,Q.jsxs)(U,{size:`sm`,onClick:it,disabled:!pt||Pe,className:G(`gap-1.5`,u&&`flex-1`),children:[Pe&&(0,Q.jsx)(Y,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(Pe?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,Q.jsxs)(Q.Fragment,{children:[u?(0,Q.jsx)(He,{id:`new-worktree-sheet-${d}`,open:e,onOpenChange:t,title:(0,Q.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold text-foreground`,children:i(`session.newWorktree.title`)}),ariaLabel:i(`session.newWorktree.title`),closeAriaLabel:i(`mobile.surface.closeAria`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),children:(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,Q.jsxs)(Ve,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`overscroll-contain px-4 pb-4 pt-2`,children:[(0,Q.jsx)(`div`,{className:`w-full mb-4`,children:(0,Q.jsx)(wt,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,Q.jsx)(Y,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,Q.jsx)(Y,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:_,onSelect:e=>ct(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[_===`existing-branch`?(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>B(!0),className:`flex-1 justify-between h-9`,children:[(0,Q.jsx)(`span`,{className:x.selectedBranch?`text-foreground`:`text-muted-foreground`,children:x.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,Q.jsx)(Y,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,Q.jsx)(U,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:Ne,disabled:!Me||T,title:i(`session.newWorktree.fetchBranches`),children:T?(0,Q.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):(0,Q.jsx)(Y,{name:`refresh`,className:`size-4`})})]}),(0,Q.jsx)(ut,{open:ae,title:i(`session.newWorktree.selectBranch`),onClose:()=>B(!1),children:(0,Q.jsxs)(`div`,{className:`space-y-4`,ref:me,children:[(0,Q.jsx)(st,{value:se,onChange:e=>H(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),T?(0,Q.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):O.length===0&&A.length===0?(0,Q.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[De&&Ae&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:we.matching.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{S(t=>({...t,selectedBranch:e.value,worktreeName:$(e.label)})),J(e=>({...e,touched:!0})),B(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,x.selectedBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),De&&!Ae&&(0,Q.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),we.otherLocal.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(De?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:we.otherLocal.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{S(t=>({...t,selectedBranch:e,worktreeName:$(e)})),J(e=>({...e,touched:!0})),B(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,x.selectedBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),we.otherRemote.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(De?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:we.otherRemote.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{S(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:$(e)})),J(e=>({...e,touched:!0})),B(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,x.selectedBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}):(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),_===`new-branch`&&dt&&(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>te(!0),className:`gap-1.5 h-7`,children:[(0,Q.jsx)(Y,{name:`github`,className:`size-4 text-status-success`}),y.linkedIssue||y.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,Q.jsx)(st,{value:y.branchName,onChange:e=>{b(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>J(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!y.linkedPr,className:G(`h-8`,q.touched&&q.branchError&&`border-destructive`,y.linkedPr&&`bg-muted text-muted-foreground`)}),y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:y.linkedPr.head})})]}),y.linkedIssue&&!y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:y.linkedIssue.number,title:y.linkedIssue.title})})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),_!==`existing-branch`&&(0,Q.jsxs)(`button`,{onClick:()=>{let e=$(_===`new-branch`?y.branchName:``);b(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!y.branchName||y.worktreeName===$(y.branchName),className:G(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,y.worktreeName===$(y.branchName)||!y.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,Q.jsx)(Y,{name:`refresh`,className:`h-3 w-3`}),(0,Q.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,Q.jsx)(st,{value:Xe.worktreeName,onChange:e=>{_===`new-branch`?b(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):S(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>J(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:G(`h-8`,q.touched&&q.worktreeError&&`border-destructive`)})]}),_===`new-branch`&&!y.linkedPr&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>V(!0),className:`w-full justify-between h-9`,children:[(0,Q.jsx)(`span`,{className:y.sourceBranch?`text-foreground`:`text-muted-foreground`,children:y.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,Q.jsx)(Y,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),y.sourceBranch&&(0,Q.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:y.sourceBranch})}),(0,Q.jsx)(ut,{open:oe,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>V(!1),children:(0,Q.jsxs)(`div`,{className:`space-y-4`,ref:he,children:[(0,Q.jsx)(st,{value:ce,onChange:e=>de(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),T?(0,Q.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):O.length===0&&A.length===0?(0,Q.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[Oe&&je&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:Te.matching.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{b(t=>({...t,sourceBranch:e.value})),V(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.sourceBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),Oe&&!je&&(0,Q.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),Te.otherLocal.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(Oe?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:Te.otherLocal.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{b(t=>({...t,sourceBranch:e})),V(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.sourceBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),Te.otherRemote.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(Oe?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:Te.otherRemote.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{b(t=>({...t,sourceBranch:`remotes/${e}`})),V(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.sourceBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}),(y.linkedIssue||y.linkedPr)&&_===`new-branch`&&(0,Q.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Y,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),y.linkedIssue&&(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:y.linkedIssue.number})}),y.linkedPr&&(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:y.linkedPr.number})}),(0,Q.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:y.linkedIssue?.title||y.linkedPr?.title}),(0,Q.jsx)(`a`,{href:y.linkedIssue?.url||y.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(Y,{name:`external-link`,className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:_t,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,Q.jsx)(Y,{name:`close`,className:`h-3.5 w-3.5`})})]}),y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,Q.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[y.linkedPr.head,` → `,y.linkedPr.base]}),y.includePrDiff&&(0,Q.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]})]}),(0,Q.jsx)(`div`,{className:`shrink-0 border-t border-border/50 px-4 pb-3 pt-2`,children:Ct})]})}):(0,Q.jsx)(qe,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ge,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,Q.jsx)(Ue,{className:`flex flex-row items-center justify-between`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(Ke,{className:`flex items-center gap-2 shrink-0`,children:[(0,Q.jsx)(Y,{name:`git-branch`,className:`h-5 w-5`}),i(`session.newWorktree.title`)]}),(0,Q.jsx)(`div`,{className:`w-[280px] shrink-0`,children:(0,Q.jsx)(wt,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,Q.jsx)(Y,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,Q.jsx)(Y,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:_,onSelect:e=>ct(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})})]})}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto mt-2 space-y-6`,children:[_===`existing-branch`?(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)($e,{open:I,onOpenChange:z,children:[(0,Q.jsx)(Ze,{asChild:!0,children:(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:G(`truncate`,x.selectedBranch?`text-foreground`:`text-muted-foreground`),children:x.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,Q.jsx)(Y,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(Qe,{align:`start`,sideOffset:6,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:fe,children:(0,Q.jsxs)(Tn,{shouldFilter:!1,children:[(0,Q.jsx)(En,{placeholder:i(`session.newWorktree.searchBranches`),value:se,onValueChange:H,onKeyDown:_e}),(0,Q.jsx)(Dn,{disableHorizontal:!0,children:T?(0,Q.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):O.length===0&&A.length===0?(0,Q.jsx)(On,{children:i(`session.newWorktree.noBranchesFound`)}):(0,Q.jsxs)(Q.Fragment,{children:[De&&Ae&&(0,Q.jsx)(kn,{heading:i(`session.newWorktree.matchingBranches`),children:we.matching.map(e=>(0,Q.jsx)(jn,{value:e.value,onSelect:()=>{S(t=>({...t,selectedBranch:e.value,worktreeName:$(e.label)})),J(e=>({...e,touched:!0})),z(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),De&&!Ae&&(0,Q.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),we.otherLocal.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[De&&(0,Q.jsx)(An,{}),(0,Q.jsx)(kn,{heading:i(De?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:we.otherLocal.map(e=>(0,Q.jsx)(jn,{value:e,onSelect:()=>{S(t=>({...t,selectedBranch:e,worktreeName:$(e)})),J(e=>({...e,touched:!0})),z(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),we.otherRemote.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(we.otherLocal.length>0||De)&&(0,Q.jsx)(An,{}),(0,Q.jsx)(kn,{heading:i(De?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:we.otherRemote.map(e=>(0,Q.jsx)(jn,{value:`remotes/${e}`,onSelect:()=>{S(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:$(e)})),J(e=>({...e,touched:!0})),z(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,Q.jsx)(U,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:Ne,disabled:!Me||T,title:i(`session.newWorktree.fetchBranches`),children:T?(0,Q.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):(0,Q.jsx)(Y,{name:`refresh`,className:`size-4`})})]})]}):(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),_===`new-branch`&&dt&&(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>te(!0),className:`gap-1.5 h-7`,children:[(0,Q.jsx)(Y,{name:`github`,className:`size-4 text-status-success`}),y.linkedIssue||y.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,Q.jsx)(st,{value:y.branchName,onChange:e=>{b(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>J(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!y.linkedPr,className:G(`h-8`,q.touched&&q.branchError&&`border-destructive`,y.linkedPr&&`bg-muted text-muted-foreground`)}),y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:y.linkedPr.head})})]}),y.linkedIssue&&!y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:y.linkedIssue.number,title:y.linkedIssue.title})})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),_!==`existing-branch`&&(0,Q.jsxs)(`button`,{onClick:()=>{let e=$(_===`new-branch`?y.branchName:``);b(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!y.branchName||y.worktreeName===$(y.branchName),className:G(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,y.worktreeName===$(y.branchName)||!y.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,Q.jsx)(Y,{name:`refresh`,className:`h-3 w-3`}),(0,Q.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,Q.jsx)(st,{value:Xe.worktreeName,onChange:e=>{_===`new-branch`?b(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):S(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>J(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:G(`h-8`,q.touched&&q.worktreeError&&`border-destructive`)})]}),_===`new-branch`&&!y.linkedPr&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,Q.jsxs)($e,{open:ne,onOpenChange:ie,children:[(0,Q.jsx)(Ze,{asChild:!0,children:(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:G(`truncate`,y.sourceBranch?`text-foreground`:`text-muted-foreground`),children:y.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,Q.jsx)(Y,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(Qe,{align:`start`,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:pe,children:(0,Q.jsxs)(Tn,{shouldFilter:!1,children:[(0,Q.jsx)(En,{placeholder:i(`session.newWorktree.searchBranches`),value:ce,onValueChange:de,onKeyDown:_e}),(0,Q.jsx)(Dn,{disableHorizontal:!0,children:T?(0,Q.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):O.length===0&&A.length===0?(0,Q.jsx)(On,{children:i(`session.newWorktree.noBranchesFound`)}):(0,Q.jsxs)(Q.Fragment,{children:[Oe&&je&&(0,Q.jsx)(kn,{heading:i(`session.newWorktree.matchingBranches`),children:Te.matching.map(e=>(0,Q.jsx)(jn,{value:e.value,onSelect:()=>{b(t=>({...t,sourceBranch:e.value})),ie(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),Oe&&!je&&(0,Q.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),Te.otherLocal.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[Oe&&(0,Q.jsx)(An,{}),(0,Q.jsx)(kn,{heading:i(Oe?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:Te.otherLocal.map(e=>(0,Q.jsx)(jn,{value:e,onSelect:()=>{b(t=>({...t,sourceBranch:e})),ie(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),Te.otherRemote.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(Te.otherLocal.length>0||Oe)&&(0,Q.jsx)(An,{}),(0,Q.jsx)(kn,{heading:i(Oe?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:Te.otherRemote.map(e=>(0,Q.jsx)(jn,{value:`remotes/${e}`,onSelect:()=>{b(t=>({...t,sourceBranch:`remotes/${e}`})),ie(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),y.sourceBranch&&(0,Q.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:y.sourceBranch})})]}),(y.linkedIssue||y.linkedPr)&&_===`new-branch`&&(0,Q.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Y,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),y.linkedIssue&&(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:y.linkedIssue.number})}),y.linkedPr&&(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:y.linkedPr.number})}),(0,Q.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:y.linkedIssue?.title||y.linkedPr?.title}),(0,Q.jsx)(`a`,{href:y.linkedIssue?.url||y.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(Y,{name:`external-link`,className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:_t,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,Q.jsx)(Y,{name:`close`,className:`h-3.5 w-3.5`})})]}),y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,Q.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[y.linkedPr.head,` → `,y.linkedPr.base]}),y.includePrDiff&&(0,Q.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]}),(0,Q.jsxs)(We,{className:`mt-1 flex items-center justify-between`,children:[St,(0,Q.jsx)(`div`,{className:`flex items-center gap-1.5 text-destructive`,children:q.touched&&(q.branchError||q.worktreeError)&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Y,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:q.branchError||q.worktreeError})]})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(U,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:Pe,children:i(`session.newWorktree.actions.cancel`)}),(0,Q.jsxs)(U,{size:`sm`,onClick:it,disabled:!pt||Pe,className:`gap-1.5`,children:[Pe&&(0,Q.jsx)(Y,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(Pe?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]})]})}),(0,Q.jsx)(Yn,{projectId:m?.id,open:F,onOpenChange:te,onSelect:lt})]})}var ir=null,ar=new Set,or=()=>{for(let e of ar)e()},sr=e=>e===`chat`||e===`assistant`,cr=()=>ir,lr=e=>{ir!==e&&(ir=e,or())},ur=e=>{ir&&(e&&ir.surfaceID!==e||(ir=null,or()))},dr=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},fr=e=>{let t=e.options?.delivery===`steer`?`steer`:e.options?.delivery===`queue`?`queue`:void 0,n={...t?{delivery:t}:{},...e.options?.commitStagedMessageEdit===void 0?{}:{commitStagedMessageEdit:e.options.commitStagedMessageEdit},...e.options?.messageID?{messageID:e.options.messageID}:{},...e.options?.ticket?{ticket:e.options.ticket}:{}},r=e.options?.sessionId??e.sessionID??void 0;if(!r)return n;let i=e.options?.directoryHint===void 0?e.directory||null:e.options.directoryHint;return{...n,sessionId:r,directoryHint:i}},pr=(e,t,n={})=>({operation:t,surfaceID:e.surfaceID,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration,sessionID:e.sessionID,directory:e.directory??``,draftKey:e.draftKey,deliveryTarget:e.deliveryTarget,...n}),mr=e=>{if(!e.active||!e.draftKey||!e.directory)return null;let t=e.activity?.phase??`idle`,n=e.activity?.canAbort??(t===`busy`||t===`retry`);return{send:async t=>{let n=pr(e,`send`,t);return await e.selection.flush(),e.kind===`secondary`&&await e.shortcuts.submit(),e.backend.send(n)},sendQueued:async(t,n={})=>{let{manual:r,...i}=n,a=pr(e,`send`,i),o=Qt(e);if(await e.selection.flush(),!o)throw Error(`chat-input-queue-scope-incomplete`);return e.backend.sendQueued({...a,queueItemID:t,manual:r,queueScope:o})},create:async()=>{let t=pr(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=pr(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=pr(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Qt(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Gt(e,{name:t,source:`yuri`}),shortcut:async(t,n=1)=>{if(e.kind===`secondary`){t===`cycle`?await e.shortcuts.cycle(n):t===`new`?await e.shortcuts.new():t===`abort`?await e.shortcuts.abort():await e.shortcuts.submit();return}if(t===`abort`){let t=pr(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=pr(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},hr=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,gr=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},_r=e=>e.type!==`tool`||hr(e)?!1:!gr(e),vr=e=>{let t=0;for(let n of e)_r(n)&&(t+=1);return t},yr=(e,t)=>e===`stop`&&vr(t)===0,br=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&Tt(t)},xr=e=>{if(vr(e)!==0)return-1;for(let t=e.length-1;t>=0;--t){let n=e[t];if(br(n))return t;if(n.type===`tool`||n.type===`reasoning`||n.type===`file`||n.type===`agent`||n.type===`subtask`)break}return-1},Sr=(e,t,n)=>{if(n||!yr(e,t))return!1;for(let e of t)if(br(e))return!0;return!1},Cr=e=>e===`streaming`||e===`cooldown`,wr=e=>e.parts.some(br),Tr=e=>Cr(e.streamPhase)?wr(e):!1,Er=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},Dr=e=>{let t=e?.type;return t===`compaction`?!g(e):t===`text`&&Er(e).trim()===`/compact`},Or=e=>e?e.some(e=>Dr(e)):!1,kr=e=>Or(e.parts),Ar=e=>e?Or(e.sourceParts)||Or(e.parts):!1,jr=e=>{if(!kr(e))return e;let t=!1,n=e.parts.map(e=>e?.type!==`compaction`||g(e)?e:(t=!0,{type:`text`,text:`/compact`})),r=e.info.clientRole!==`user`;return!t&&!r?e:{...e,info:r?{...e.info,clientRole:`user`}:e.info,parts:t?n:e.parts}},Mr=e=>{let t=Et(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},Nr=new WeakMap,Pr=e=>{let t=Nr.get(e);if(t)return t;let n=jr(Mr(e)),r=n.parts,i=P(r),a=i===r?n:{...n,parts:i,sourceParts:r};return Nr.set(e,a),a},Fr={activity:`idle`,hasWorkingContext:!1,hasActiveTools:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,lifecyclePhase:null,statusText:null,isGenericStatus:!0,isWaitingForPermission:!1,canAbort:!1,compactionDeadline:null,activePartType:void 0,activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:null,turnStartedAt:void 0},Ir=[],Lr=`\0`,Rr=new Set([`edit`,`write`,`apply_patch`]),zr={read:`chat.assistantStatus.readingFile`,write:`chat.assistantStatus.writingFile`,edit:`chat.assistantStatus.editingFile`,apply_patch:`chat.assistantStatus.applyingPatch`,bash:`chat.assistantStatus.runningCommand`,grep:`chat.assistantStatus.searchingContent`,glob:`chat.assistantStatus.findingFiles`,list:`chat.assistantStatus.listingDirectory`,task:`chat.assistantStatus.delegatingTask`,webfetch:`chat.assistantStatus.fetchingUrl`,websearch:`chat.assistantStatus.searchingWeb`,codesearch:`chat.assistantStatus.webCodeSearch`,todowrite:`chat.assistantStatus.updatingTodos`,todoread:`chat.assistantStatus.readingTodos`,skill:`chat.assistantStatus.learningSkill`,question:`chat.assistantStatus.askingQuestion`,execute:`chat.assistantStatus.executing`,session_rename:`chat.assistantStatus.renamingSession`,session_move:`chat.assistantStatus.movingSession`,browser:`chat.assistantStatus.usingBrowser`},Br=[`chat.assistantStatus.working`,`chat.assistantStatus.processing`,`chat.assistantStatus.preparing`,`chat.assistantStatus.warmingUp`,`chat.assistantStatus.gearsTurning`,`chat.assistantStatus.computing`,`chat.assistantStatus.calculating`,`chat.assistantStatus.analyzing`,`chat.assistantStatus.wheelsSpinning`,`chat.assistantStatus.calibrating`,`chat.assistantStatus.synthesizing`,`chat.assistantStatus.connectingDots`,`chat.assistantStatus.inspectingLogic`,`chat.assistantStatus.weighingOptions`],Vr=(e,t)=>{let n=zr[Be(e)];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},Hr=e=>{let t=0;for(let n=0;n<e.length;n+=1)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t)},Ur=(e,t)=>t(Br[Hr(e)%Br.length]??`chat.assistantStatus.working`),Wr=(e,t,n)=>{let r,i;if(!we(e))for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)switch(n.type){case`reasoning`:{let e=n.time??Xr(n);(!e||e.end===void 0)&&!r&&(r=`reasoning`);break}case`tool`:{let e=n.state?.status;if((e===`running`||e===`pending`)&&!r){let e=Be(Zr(n));Rr.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=Yr(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=Xr(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?n(`chat.assistantStatus.editingFile`):r===`tool`&&i?Vr(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):Ur(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},Gr=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(Lr),Kr=e=>{let[t,n,r=`working`,i]=e.split(Lr);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},qr=e=>e.type===`reasoning`,Jr=e=>e.type===`text`,Yr=e=>{if(Jr(e))return e.text;let t=e;if(typeof t.text==`string`)return t.text;if(typeof t.content==`string`)return t.content;if(typeof t.value==`string`)return t.value},Xr=e=>(Jr(e)||qr(e),e.time),Zr=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function Qr(e,t){let{t:n}=ze(),r=W(e=>e.currentSessionId),i=W(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=H(e=>!!(a&&e.session_execution_recovery[a]),o??void 0),c=X.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),l=W(c),u=he(a??``,o??void 0),d=X.useMemo(()=>{for(let e=u.length-1;e>=0;e--){let t=u[e];if(t.role===`assistant`)return{id:t.id,index:e,finish:t.finish,error:t.error,isCompaction:t.clientRole===`compaction`,startedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,index:-1,finish:void 0,error:void 0,isCompaction:!1,startedAt:void 0}},[u]),f=d.id,p=X.useMemo(()=>{for(let e=u.length-1;e>=0;e--){let t=u[e];if(t.role===`user`&&!b(t))return{id:t.id,index:e,turnStartedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,index:-1,turnStartedAt:void 0}},[u]),m=p.id,h=De(f??``,o??void 0,a??void 0),g=De(m??``,o??void 0,a??void 0),_=!!m&&Or(g),v=d.isCompaction&&d.index>p.index?h.find(e=>e.type===`compaction`):void 0,y=v?.reason===`manual`?d.startedAt:p.turnStartedAt,x=!!(f&&d.index>p.index&&(v?v.status===`failed`||v.reason===`manual`&&v.status===`completed`:Sr(d.finish,h,d.error))),S=X.useMemo(()=>{let e=`${a??``}:${f??``}`;return Gr(Wr(f&&!d.error&&d.index>p.index?h:Ir,e,n))},[a,f,d.error,d.index,p.index,h,n]),C=Te(a??``,o??void 0),w=xe(a??``,o??void 0),T=X.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),E=W(T),{phase:D,isWorking:O}=nn(a,o??void 0),k=!!(d.error&&d.index>p.index),A=ve(a??``,o??void 0),ee=A?.type===`retry`?A.attempt:void 0,j=A?.type===`retry`?A.next:void 0,M=X.useMemo(()=>Kr(S),[S]),N=X.useMemo(()=>{let e=!!(E&&!E.acknowledged);return{wasAborted:e,abortActive:e}},[E]),P=X.useMemo(()=>{if(s)return{...Fr,isRecovering:!0,canAbort:O};if(k&&D!==`retry`)return{...Fr,isTurnSettled:!0,canAbort:O};if(N.wasAborted)return{...Fr,wasAborted:!0,abortActive:N.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};if(x)return{...Fr,isComplete:v?.status!==`failed`,isTurnSettled:!0,turnStartedAt:y};let e=O,t=D===`busy`,r=D===`retry`,i=e&&(_||v?.status===`running`),a=`idle`;e&&(a=!i&&(M.activePartType===`tool`||M.activePartType===`editing`)?`tooling`:`streaming`);let o=r?{attempt:ee,next:j,message:A?.type===`retry`?A.message:void 0}:null;return{activity:a,hasWorkingContext:e,hasActiveTools:!i&&(M.activePartType===`tool`||M.activePartType===`editing`),isWorking:e,isStreaming:t,isCooldown:!1,lifecyclePhase:t?`streaming`:null,statusText:e?i?n(`chat.assistantStatus.compacting`):M.statusText:null,isGenericStatus:!e||!i&&M.isGenericStatus,isWaitingForPermission:!1,canAbort:e,compactionDeadline:null,activePartType:e&&!i?M.activePartType:void 0,activeToolName:e&&!i?M.activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:o,turnStartedAt:y}},[s,k,D,O,x,_,v?.status,y,M,N,ee,j,A,n]);return{forming:X.useMemo(()=>({isActive:!s&&!k&&O&&M.activePartType===`text`,characterCount:0}),[s,k,O,M.activePartType]),working:X.useMemo(()=>{if(s||P.wasAborted||P.abortActive)return P;if(l)return{...P,activity:`streaming`,hasWorkingContext:!0,isWorking:!0,isStreaming:!0,isCooldown:!1,lifecyclePhase:`streaming`,statusText:n(`chat.assistantStatus.sendingMessage`),isGenericStatus:!1,isWaitingForPermission:!1,canAbort:!0,activePartType:void 0,activeToolName:void 0,isComplete:!1,isTurnSettled:!1,retryInfo:null};let e=C.length>0,t=w.length>0;return!e&&!t?P:t?{...P,statusText:null,isWorking:!1,hasWorkingContext:!1,hasActiveTools:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null}:{...P,statusText:n(`chat.assistantStatus.waitingForPermission`),isWaitingForPermission:!0,canAbort:!1,retryInfo:null}},[s,P,l,C,w,n])}}var $r=`--yuri-mobile-header-collapse`,ei=e=>e.closest(`.mobile-chat-screen`)?.querySelector(`:scope > [data-yuri-collapsible-header="true"]`)??null,ti=e=>{e.style.removeProperty($r),delete e.dataset.yuriHeaderCollapsePhase,delete e.dataset.yuriHeaderCollapseRest},ni=(e,t,n)=>{let r=String(t.progress),i=t.phase,a=t.rest===`compact`?`collapsed`:`expanded`;return n?.phase!==i&&(e.dataset.yuriHeaderCollapsePhase=i,i===`snapping`&&n&&n.phase!==`snapping`&&e.offsetWidth),n?.progress!==r&&e.style.setProperty($r,r),n?.rest!==a&&(e.dataset.yuriHeaderCollapseRest=a),{progress:r,phase:i,rest:a}},ri=e=>{let t=e.startsWith(`#`)?e.slice(1):e;if(!t)return null;let n=t.match(/^turn-(.+)$/);if(n?.[1])return{kind:`turn`,id:n[1]};let r=t.match(/^message-(.+)$/);return r?.[1]?{kind:`message`,id:r[1]}:null},ii=(e,t,n)=>{if(n===0||e.length===0)return{kind:`noop`};let r=t?e.indexOf(t):e.length-1,i=(r>=0?r:e.length-1)+n;if(i>=e.length)return{kind:`resume`};let a=e[Math.max(0,i)];return a?{kind:`turn`,turnId:a}:{kind:`noop`}},ai=e=>{if(typeof window>`u`)return;let t=e?`#${e}`:``,n=`${window.location.pathname}${window.location.search}${t}`;window.history.replaceState(window.history.state,``,n),e&&window.dispatchEvent(new HashChangeEvent(`hashchange`))},oi=e=>{e&&ai(`message-${e}`)},si=e=>{let t=(0,Z.c)(29),{sessionId:n,turnIds:r,activeTurnId:i,scrollToTurn:a,scrollToMessage:o,resumeToBottom:s}=e,c=X.useRef(r),l=X.useRef(i),u,d;t[0]===r?(u=t[1],d=t[2]):(u=()=>{c.current=r},d=[r],t[0]=r,t[1]=u,t[2]=d),X.useEffect(u,d);let f,p;t[3]===i?(f=t[4],p=t[5]):(f=()=>{l.current=i},p=[i],t[3]=i,t[4]=f,t[5]=p),X.useEffect(f,p);let m;t[6]===a?m=t[7]:(m=async(e,t)=>e?(t?.updateHash!==!1&&ai(`turn-${e}`),a(e,{behavior:t?.behavior})):!1,t[6]=a,t[7]=m);let h=m,g;t[8]===o?g=t[9]:(g=async(e,t)=>e?(t?.updateHash!==!1&&ai(`message-${e}`),o(e,{behavior:t?.behavior})):!1,t[8]=o,t[9]=g);let _=g,v;t[10]!==s||t[11]!==h?(v=async(e,t)=>{let n=c.current,r=ii(n,l.current,e);if(r.kind===`noop`)return e===0;if(r.kind===`resume`){if(t?.resumePastEnd===!1){let e=n[n.length-1];return e?h(e,{behavior:`auto`}):!1}return ai(null),s(),!0}return h(r.turnId,{behavior:`auto`})},t[10]=s,t[11]=h,t[12]=v):v=t[12];let y=v,b;t[13]===s?b=t[14]:(b=()=>{ai(null),s()},t[13]=s,t[14]=b);let x=b,S;t[15]!==_||t[16]!==h||t[17]!==n?(S=()=>{if(!n||typeof window>`u`)return;let e=()=>{let e=ri(window.location.hash);if(e){if(e.kind===`turn`){h(e.id,{behavior:`auto`,updateHash:!1});return}_(e.id,{behavior:`auto`,updateHash:!1})}};return e(),window.addEventListener(`hashchange`,e),()=>{window.removeEventListener(`hashchange`,e)}},t[15]=_,t[16]=h,t[17]=n,t[18]=S):S=t[18];let C;t[19]!==_||t[20]!==h||t[21]!==n||t[22]!==r.length?(C=[n,_,h,r.length],t[19]=_,t[20]=h,t[21]=n,t[22]=r.length,t[23]=C):C=t[23],X.useEffect(S,C);let w;return t[24]!==x||t[25]!==y||t[26]!==_||t[27]!==h?(w={scrollToTurnId:h,scrollToMessageId:_,scrollByTurnOffset:y,resumeToLatest:x},t[24]=x,t[25]=y,t[26]=_,t[27]=h,t[28]=w):w=t[28],w},ci=[0,200,400],li=e=>{let t=(0,Z.c)(5),{className:n}=e,r;t[0]===n?r=t[1]:(r=G(`inline-flex`,n),t[0]=n,t[1]=r);let i;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(i=ci.map(ui),t[2]=i):i=t[2];let a;return t[3]===r?a=t[4]:(a=(0,Q.jsxs)(Q.Fragment,{children:[`\xA0`,(0,Q.jsx)(`span`,{className:r,"aria-hidden":`true`,children:i})]}),t[3]=r,t[4]=a),a};function ui(e){return(0,Q.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}export{En as A,Xt as B,sr as C,Tn as D,Ln as E,wn as F,Ut as G,Vt as H,cn as I,qt as J,Yt as K,rn as L,Dn as M,Cn as N,On as O,Sn as P,Ot as Q,an as R,cr as S,nr as T,$t as U,Gt as V,Zt as W,Bt as X,Jt as Y,Dt as Z,Tr as _,ti as a,fr as b,Qr as c,wr as d,vr as f,br as g,yr as h,$r as i,jn as j,kn as k,Pr as l,Sr as m,oi as n,ni as o,xr as p,Ht as q,si as r,ei as s,li as t,Ar as u,dr as v,lr as w,ur as x,mr as y,nn as z};
|
|
4
|
+
`)})}function Wn(e){let t=(0,Z.c)(41),{project:n,open:r,onClose:i,children:a}=e,o=E(),s=n?.hostId&&o&&o.entry.location.hubId===n.hubId&&o.entry.location.hostId===n.hostId&&o.entry.location.directory===n.path,c=Le(!!(r&&n?.hostId&&!s)),{t:l}=ze();if(!n?.hostId){let e;return t[0]===a?e=t[1]:(e=(0,Q.jsx)(T.Provider,{value:null,children:a}),t[0]=a,t[1]=e),e}if(s)return a;if(!r)return null;if(!c.registry||c.registry.hubId!==n.hubId){let e;t[2]===i?e=t[3]:(e=e=>{e||i()},t[2]=i,t[3]=e);let n;t[4]===l?n=t[5]:(n=l(`session.newWorktree.title`),t[4]=l,t[5]=n);let r;t[6]===n?r=t[7]:(r=(0,Q.jsx)(Ue,{children:(0,Q.jsx)(Ke,{children:n})}),t[6]=n,t[7]=r);let a=c.isPending?`status`:`alert`,o;t[8]!==c.error?.message||t[9]!==c.isPending||t[10]!==l?(o=c.isPending?l(`remoteProjects.running`):c.error?.message||l(`remoteProjects.host-unavailable`),t[8]=c.error?.message,t[9]=c.isPending,t[10]=l,t[11]=o):o=t[11];let s;t[12]!==a||t[13]!==o?(s=(0,Q.jsx)(`p`,{role:a,children:o}),t[12]=a,t[13]=o,t[14]=s):s=t[14];let u;t[15]===l?u=t[16]:(u=l(`session.newWorktree.actions.cancel`),t[15]=l,t[16]=u);let d;t[17]!==i||t[18]!==u?(d=(0,Q.jsx)(U,{onClick:i,children:u}),t[17]=i,t[18]=u,t[19]=d):d=t[19];let f;t[20]!==c.isPending||t[21]!==l?(f=c.isPending?null:(0,Q.jsx)(U,{onClick:Gn,children:l(`remoteProjects.retry`)}),t[20]=c.isPending,t[21]=l,t[22]=f):f=t[22];let p;t[23]!==d||t[24]!==f?(p=(0,Q.jsxs)(We,{children:[d,f]}),t[23]=d,t[24]=f,t[25]=p):p=t[25];let m;t[26]!==p||t[27]!==r||t[28]!==s?(m=(0,Q.jsxs)(Ge,{children:[r,s,p]}),t[26]=p,t[27]=r,t[28]=s,t[29]=m):m=t[29];let h;return t[30]!==e||t[31]!==m?(h=(0,Q.jsx)(qe,{open:!0,onOpenChange:e,children:m}),t[30]=e,t[31]=m,t[32]=h):h=t[32],h}let u;t[33]!==n.hostId||t[34]!==n.hubId||t[35]!==n.path?(u={hubId:n.hubId,hostId:n.hostId,directory:n.path},t[33]=n.hostId,t[34]=n.hubId,t[35]=n.path,t[36]=u):u=t[36];let d;return t[37]!==a||t[38]!==c.registry||t[39]!==u?(d=(0,Q.jsx)(A,{registry:c.registry,location:u,children:a}),t[37]=a,t[38]=c.registry,t[39]=u,t[40]=d):d=t[40],d}function Gn(){Re().catch(Kn)}function Kn(){}var qn=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null};function Jn(e,t){return`${e}\0${t}`}function Yn(e){let t=(0,Z.c)(12),n;t[0]===e.projectId?n=t[1]:(n=t=>qn(t.projects,t.activeProjectId,e.projectId),t[0]=e.projectId,t[1]=n);let r=R(n),i;t[2]===e?i=t[3]:(i=()=>e.onOpenChange(!1),t[2]=e,t[3]=i);let a=r?.id,o;t[4]!==e||t[5]!==a?(o=(0,Q.jsx)(Xn,{...e},a),t[4]=e,t[5]=a,t[6]=o):o=t[6];let s;return t[7]!==r||t[8]!==e.open||t[9]!==i||t[10]!==o?(s=(0,Q.jsx)(Wn,{project:r,open:e.open,onClose:i,children:o}),t[7]=r,t[8]=e.open,t[9]=i,t[10]=o,t[11]=s):s=t[11],s}function Xn({open:e,onOpenChange:t,onSelect:n,projectId:r}){let{t:i}=ze(),a=M(e=>e.isMobile),o=E(),s=o?.entry.location.hostId?o.entry:void 0,{git:c}=et(),{github:l,auth:u}=Vn(s,e),d=u.data??null,f=u.isFetched,p=M(e=>e.setSettingsDialogOpen),m=M(e=>e.setSettingsPage),h=R(e=>qn(e.projects,e.activeProjectId,r)),g=h?.id??null,_=h?.path??null,v=X.useMemo(()=>_&&g?{id:g,path:_,hostId:h?.hostId,hubId:h?.hubId}:null,[g,_,h?.hostId,h?.hubId]),[y,b]=X.useState(`issues`),[x,S]=X.useState(``),[C,w]=X.useState([]),[T,D]=X.useState([]),[O,k]=X.useState(!1),[A,j]=X.useState(!1),[N,P]=X.useState(null),[F,te]=X.useState(null),[I,L]=X.useState(null),[z,ne]=X.useState(!1),[re,ie]=X.useState(new Map),[ae,B]=X.useState(1),[oe,V]=X.useState(!1),se=X.useRef(0),H=ct(x,350),ce=ee(async e=>{if(!(!_||!l)&&!(f&&d?.connected===!1)){k(!0),P(null),B(1),V(!1);try{if(y===`issues`&&l.issuesList){let t=await l.issuesList(_,{page:1,query:e});t.connected===!1?(P(i(`session.githubIntegration.error.notConnected`)),w([])):(w(t.issues??[]),B(t.page??1),V(!!t.hasMore))}else if(y===`prs`&&l.prsList){let t=await l.prsList(_,{page:1,query:e});t.connected===!1?(P(i(`session.githubIntegration.error.notConnected`)),D([])):(D(t.prs??[]),B(t.page??1),V(!!t.hasMore))}}catch(e){P(e instanceof Error?e.message:i(`session.githubIntegration.error.loadDataFailed`))}finally{k(!1)}}});X.useEffect(()=>{if(!e||!_||f&&d?.connected===!1||!l)return;if(!H.trim()){ce();return}let t=new AbortController;k(!0),P(null),B(1),V(!1);let n=y===`issues`&&l.issuesList?l.issuesList(_,{page:1,query:H.trim()}):y===`prs`&&l.prsList?l.prsList(_,{page:1,query:H.trim()}):null;if(!n){k(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(P(i(`session.githubIntegration.error.notConnected`)),w([])):(w(e.issues??[]),B(e.page??1),V(!!e.hasMore)):`prs`in e&&(e.connected===!1?(P(i(`session.githubIntegration.error.notConnected`)),D([])):(D(e.prs??[]),B(e.page??1),V(!!e.hasMore))))}).catch(e=>{t.signal.aborted||P(e instanceof Error?e.message:i(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||k(!1)}),()=>t.abort()},[e,_,l,f,d,y,H,ce,i]);let le=ee(async()=>{if(!(!_||!l)&&!(O||A)&&oe){j(!0);try{let e=ae+1;if(y===`issues`&&l.issuesList){let t=H.trim()?await l.issuesList(_,{page:e,query:H.trim()}):await l.issuesList(_,{page:e});t.connected!==!1&&(w(e=>[...e,...t.issues??[]]),B(t.page??e),V(!!t.hasMore))}else if(y===`prs`&&l.prsList){let t=H.trim()?await l.prsList(_,{page:e,query:H.trim()}):await l.prsList(_,{page:e});t.connected!==!1&&(D(e=>[...e,...t.prs??[]]),B(t.page??e),V(!!t.hasMore))}}catch{}finally{j(!1)}}});X.useEffect(()=>{if(!e){b(`issues`),S(``),w([]),D([]),te(null),L(null),ne(!1),P(null),ie(new Map),B(1),V(!1);return}ce()},[e,ce]),X.useEffect(()=>{se.current+=1,ie(new Map)},[_,v]);let ue=ee(async e=>{if(!v||!e)return;let t=Jn(v.path,e);if(re.has(t))return;let n=se.current;try{let r={mode:`new`,branchName:e,worktreeName:e},a=s?await c.validateGitWorktree(v.path,r):await ft(v,r);if(n!==se.current)return;let o=a.errors.find(e=>e.code===`branch_in_use`);ie(e=>new Map(e).set(t,{isValid:!o,error:o?i(o.code===`branch_exists`?`session.githubIntegration.validation.branchAlreadyExists`:`session.githubIntegration.validation.branchAlreadyCheckedOut`):null}))}catch{if(n!==se.current)return;ie(e=>new Map(e).set(t,{isValid:!1,error:i(`session.githubIntegration.validation.failed`)}))}});X.useEffect(()=>{!e||y!==`prs`||T.forEach(e=>{e.head&&ue(e.head)})},[e,y,T,_,v,ue]);let de=f&&d?.connected===!0,fe=()=>{if(s){K.info(i(`remoteProjects.configurationReadOnly`));return}m(`github`),p(!0)},pe=e=>{te(e),L(null)},me=e=>{L(e),te(null)},he=()=>{F?n({type:`issue`,item:F}):I&&n({type:`pr`,item:I,includeDiff:z}),t(!1)},W=()=>{te(null),L(null),ne(!1)},ge=F||(I?.head&&_?re.get(Jn(_,I.head))?.isValid!==!1:!1),_e=e=>!e.head||(_?re.get(Jn(_,e.head)):void 0)?.isValid===!1,ve=(0,Q.jsxs)(Q.Fragment,{children:[s&&u.error?(0,Q.jsxs)(`div`,{role:`alert`,className:`typography-small text-destructive`,children:[u.error.message,(0,Q.jsx)(U,{variant:`ghost`,size:`xs`,onClick:()=>{u.refetch()},children:i(`remoteProjects.retry`)})]}):null,de?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`yuri-picker-search relative mt-2`,children:[(0,Q.jsx)(Y,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,Q.jsx)(st,{value:x,onChange:e=>S(e.target.value),placeholder:i(y===`issues`?`session.githubIntegration.search.issuesPlaceholder`:`session.githubIntegration.search.prsPlaceholder`),className:`h-8 pl-9`})]}),(0,Q.jsx)(`div`,{className:`yuri-picker-list mt-2 h-[300px] overflow-hidden`,children:(0,Q.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[O&&(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsx)(Y,{name:`loader-4`,className:`h-5 w-5 animate-spin text-muted-foreground`})}),N&&(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive`,children:[(0,Q.jsx)(Y,{name:`error-warning`,className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`typography-small`,children:N})]})}),!O&&!N&&y===`issues`&&(0,Q.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[C.length>0?C.map(e=>(0,Q.jsx)(`button`,{onClick:()=>pe(e),className:G(`yuri-picker-row w-full text-left px-2 py-1.5 rounded transition-colors`,F?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`yuri-picker-label typography-small line-clamp-2`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,Q.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)):(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:i(`session.githubIntegration.empty.noIssuesFound`)}),oe&&!A&&(0,Q.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,Q.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>void le(),className:`h-7 text-xs`,children:i(`session.githubIntegration.actions.loadMore`)})}),A&&(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,Q.jsx)(Y,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]}),!O&&!N&&y===`prs`&&(0,Q.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[T.length>0?T.map(e=>{let t=_e(e),n=e.head&&_?re.get(Jn(_,e.head)):void 0;return(0,Q.jsx)(`button`,{onClick:()=>!t&&me(e),disabled:t,className:G(`yuri-picker-row w-full text-left px-2 py-1.5 rounded transition-colors`,I?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:t?`opacity-50 cursor-not-allowed`:`hover:bg-interactive-hover`),children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`yuri-picker-label typography-small line-clamp-1`,children:e.title}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,Q.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[e.head,` → `,e.base]}),e.sourceRepo?.source===`upstream`?(0,Q.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,t&&n?.error&&(0,Q.jsx)(`span`,{className:`typography-micro text-destructive`,children:n.error})]})]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)}):(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:i(`session.githubIntegration.empty.noPullRequestsFound`)}),oe&&!A&&(0,Q.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,Q.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>void le(),className:`h-7 text-xs`,children:i(`session.githubIntegration.actions.loadMore`)})}),A&&(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,Q.jsx)(Y,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]})]})})]}):(0,Q.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 gap-4`,children:[(0,Q.jsx)(Y,{name:`github`,className:`h-12 w-12 text-muted-foreground`}),(0,Q.jsxs)(`div`,{className:`text-center`,children:[(0,Q.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:i(`session.githubIntegration.connect.title`)}),(0,Q.jsx)(`p`,{className:`typography-small text-muted-foreground mt-1`,children:i(`session.githubIntegration.connect.description`)})]}),(0,Q.jsx)(U,{onClick:fe,size:`sm`,children:i(`session.githubIntegration.connect.action`)})]})]}),ye=(0,Q.jsxs)(`div`,{className:G(`w-full`,a?`flex flex-col gap-2`:`flex flex-row items-center`),children:[(0,Q.jsxs)(`div`,{className:G(`flex items-center gap-4`,a?`w-full justify-center order-1`:`flex-1`),children:[!a&&(F||I)&&(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,Q.jsx)(`span`,{className:`typography-small truncate max-w-[150px]`,children:F?i(`session.githubIntegration.selected.issueNumber`,{number:F.number}):i(`session.githubIntegration.selected.prNumber`,{number:I?.number??``})}),(0,Q.jsx)(`button`,{onClick:W,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,Q.jsx)(Y,{name:`close`,className:`h-3.5 w-3.5`})})]}),y===`prs`&&I&&(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,Q.jsx)(lt,{checked:z,onChange:e=>ne(e),ariaLabel:i(`session.githubIntegration.includeDiffAria`)}),(0,Q.jsx)(`span`,{className:`typography-small text-foreground`,children:i(`session.githubIntegration.includeDiff`)})]})]}),(0,Q.jsxs)(`div`,{className:G(`flex gap-2`,a?`w-full order-2`:`justify-end`),children:[(0,Q.jsx)(U,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:G(a&&`flex-1`),children:i(`session.githubIntegration.actions.cancel`)}),(0,Q.jsx)(U,{size:`sm`,onClick:he,disabled:!ge,className:G(a&&`flex-1`),children:i(`session.githubIntegration.actions.select`)})]})]});return(0,Q.jsx)(Q.Fragment,{children:a?(0,Q.jsx)(ut,{open:e,title:i(`session.githubIntegration.title`),onClose:()=>t(!1),footer:de?ye:void 0,renderHeader:e=>(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 px-3 py-2 border-b border-border/40`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:i(`session.githubIntegration.title`)}),e]}),(0,Q.jsx)(`div`,{className:`w-full`,children:(0,Q.jsx)(wt,{items:[{id:`issues`,label:i(`session.githubIntegration.tabs.issues`),icon:(0,Q.jsx)(Y,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:i(`session.githubIntegration.tabs.pullRequests`),icon:(0,Q.jsx)(Y,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:y,onSelect:e=>{b(e),S(``)},variant:`active-pill`,layoutMode:`fit`})}),(F||I)&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,Q.jsx)(`span`,{className:`typography-small truncate flex-1`,children:F?i(`session.githubIntegration.selected.issueNumber`,{number:F.number}):i(`session.githubIntegration.selected.prNumber`,{number:I?.number??``})}),(0,Q.jsx)(`button`,{onClick:W,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,Q.jsx)(Y,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),children:ve}):(0,Q.jsx)(qe,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ge,{presentation:`picker`,children:[(0,Q.jsx)(Ue,{className:`yuri-picker-header`,children:(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-3`,children:[(0,Q.jsx)(Ke,{className:`yuri-picker-title`,children:i(`session.githubIntegration.title`)}),(0,Q.jsx)(`div`,{className:`w-[220px]`,children:(0,Q.jsx)(wt,{items:[{id:`issues`,label:i(`session.githubIntegration.tabs.issues`),icon:(0,Q.jsx)(Y,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:i(`session.githubIntegration.tabs.pullRequests`),icon:(0,Q.jsx)(Y,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:y,onSelect:e=>{b(e),S(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),ve,(0,Q.jsx)(We,{className:`yuri-picker-footer`,children:ye})]})})})}var Zn=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),$=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``).split(`/`).join(`-`).replace(/[^A-Za-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``).slice(0,80),Qn=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,$n=(e,t,n)=>{let r=Zn(e.head||``);if(!r)throw Error(`PR head branch is missing`);if(t.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};let i=n.find(e=>{let t=e.indexOf(`/`);return t<=0||t>=e.length-1?!1:e.slice(t+1)===r});if(i){let e=i.indexOf(`/`),t=i.slice(0,e);return{existingBranch:`remotes/${i}`,setUpstream:!0,upstreamRemote:t,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${t}/${r}`}}let a=String(e.headLabel||``).split(`:`)[0]?.trim(),o=`pr-${Qn(e.headRepo?.owner||a||`pr-head`)}`,s=e.headRepo?.sshUrl||e.headRepo?.cloneUrl||``;if(!s)throw Error(`PR head repository URL is unavailable`);return{existingBranch:`remotes/${o}/${r}`,setUpstream:!0,upstreamRemote:o,upstreamBranch:r,ensureRemoteName:o,ensureRemoteUrl:s,sourceLabel:`${o}/${r}`}},er=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},tr=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function nr(e){let t=(0,Z.c)(12),n;t[0]===e.projectId?n=t[1]:(n=t=>qn(t.projects,t.activeProjectId,e.projectId),t[0]=e.projectId,t[1]=n);let r=R(n),i;t[2]===e?i=t[3]:(i=()=>e.onOpenChange(!1),t[2]=e,t[3]=i);let a=r?.id,o;t[4]!==e||t[5]!==a?(o=(0,Q.jsx)(rr,{...e},a),t[4]=e,t[5]=a,t[6]=o):o=t[6];let s;return t[7]!==r||t[8]!==e.open||t[9]!==i||t[10]!==o?(s=(0,Q.jsx)(Wn,{project:r,open:e.open,onClose:i,children:o}),t[7]=r,t[8]=e.open,t[9]=i,t[10]=o,t[11]=s):s=t[11],s}function rr({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=ze(),{git:a}=et(),o=E(),s=o?.entry.location.hostId?o.entry:void 0,{github:c,auth:l}=Vn(s,e),u=M(e=>e.isMobile),d=X.useId(),f=l.data??null,p=l.isFetched,m=R(e=>qn(e.projects,e.activeProjectId,r)),h=m?.path??null,g=X.useMemo(()=>h&&m?{id:m.id,path:h,hostId:m.hostId,hubId:m.hubId}:null,[m,h]),[_,v]=X.useState(`new-branch`),[y,b]=X.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,S]=X.useState({selectedBranch:``,worktreeName:``}),C=ot(h),T=at(e=>h?e.directories.get(h)?.isLoadingBranches??!1:!1),D=at(e=>e.fetchBranches),O=X.useMemo(()=>C?.all?C.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[C]),A=X.useMemo(()=>C?.all?C.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[C]),ee=W(e=>e.availableWorktreesByProject),j=w({queryKey:[...s?.queryScope??[`local`],`worktree-dialog`,`worktrees`],enabled:!!(s&&e&&h),queryFn:()=>a.listGitWorktrees(h),staleTime:3e4,gcTime:1/0},k),N=X.useMemo(()=>{if(!h)return new Set;let e=s?j.data??[]:ee.get(h)??[];return new Set(e.map(e=>e.name))},[ee,h,s,j.data]),P=X.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=cn();if(!N.has(e))return e}return`${cn()}-${Date.now().toString(36).slice(-4)}`},[N]),[F,te]=X.useState(!1),[I,z]=X.useState(!1),[ne,ie]=X.useState(!1),[ae,B]=X.useState(!1),[oe,V]=X.useState(!1),[se,H]=X.useState(``),[ce,de]=X.useState(``),fe=X.useRef(null),pe=X.useRef(null),me=X.useRef(null),he=X.useRef(null),_e=X.useCallback(e=>{e.stopPropagation()},[]),ve=X.useCallback(e=>{let t=e;for(;t&&t!==document.body;){let{overflowY:e}=window.getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null},[]),be=X.useCallback(e=>{e&&(e.scrollTop=0)},[]),xe=X.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;be(t)},[be]),Ce=X.useCallback(e=>{let t=ve(e.current);be(t)},[ve,be]),we=X.useMemo(()=>Rn({localBranches:O,remoteBranches:A,query:se}),[O,A,se]),Te=X.useMemo(()=>Rn({localBranches:O,remoteBranches:A,query:ce}),[O,A,ce]),De=se.trim().length>0,Oe=ce.trim().length>0,Ae=we.matching.length>0,je=Te.matching.length>0,Me=!!(h&&a),Ne=X.useCallback(()=>{!h||!a||D(h,a)},[h,a,D]);X.useEffect(()=>{!e||!h||!a||C?.all||D(h,a)},[e,h,a,C?.all,D]),X.useEffect(()=>{!I&&!ae&&H(``)},[I,ae]),X.useEffect(()=>{!ne&&!oe&&de(``)},[ne,oe]),X.useEffect(()=>{I&&xe(fe),ae&&Ce(me)},[I,ae,se,xe,Ce]),X.useEffect(()=>{ne&&xe(pe),oe&&Ce(he)},[ne,oe,ce,xe,Ce]);let[q,J]=X.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[Pe,Fe]=X.useState(!1),[Ie,Le]=X.useState(null),Re=X.useCallback(()=>{let e=ue.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),Be=X.useCallback(()=>{let e=ue.getState(),t=e.settingsDefaultModel??(e.currentModelId?void 0:e.opencodeDefaultModel);if(!t)return null;let n=re(t);if(!n)return null;let{providerId:r,modelId:i}=n;return{providerID:r,modelID:i}},[]),Je=X.useCallback((e,t)=>{let n=ue.getState(),r=re(n.settingsDefaultModel??n.opencodeDefaultModel),i=r?.providerId===e&&r.modelId===t?r.variant??n.settingsDefaultVariant:void 0,a=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0;return i??a},[]),Ye=X.useCallback(async e=>{if(!h||!c)return;let t=ue.getState(),n=ke.getState().lastUsedProvider,r=Be(),a=r?.providerID||t.currentProviderId||n?.providerID,o=r?.modelID||t.currentModelId||n?.modelID,s=Re()||t.currentAgentName||void 0;if(!a||!o){K.error(i(`session.newWorktree.error.noModelSelected`));return}let l=Je(a,o);if(e.issue){if(!c.issueGet||!c.issueComments)return;let t=await c.issueGet(h,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(t.connected===!1||!t.repo||!t.issue)throw Error(`Failed to load issue context`);let n=await c.issueComments(h,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await tt(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await tt(`github.issue.review.instructions`),d=er({repo:t.repo,issue:t.issue,comments:n.comments??[]});await W.getState().sendMessage(r,a,o,s,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),K.success(i(`session.newWorktree.toast.sessionFromIssue`));return}if(e.pr){if(!c.prContext)return;let t=await c.prContext(h,e.pr.number,{sourceRepo:e.pr.sourceRepo??null,includeDiff:e.includeDiff,includeCheckDetails:!1});if(t.connected===!1||!t.repo||!t.pr)throw Error(`Failed to load PR context`);let n=await tt(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await tt(`github.pr.review.instructions`),u=tr(t);await W.getState().sendMessage(n,a,o,s,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),K.success(i(`session.newWorktree.toast.sessionFromPr`))}},[c,h,Re,Be,Je,i]),Xe=_===`new-branch`?y:x;X.useEffect(()=>{if(!e||!C?.all||!h||y.sourceBranch)return;let t=y.sourceBranch,n=!1;return(async()=>{try{let e=s?(await a.getGitStatus(h)).current:await mt(h).catch(()=>null);if(n)return;let r=localStorage.getItem(xt),{sourceBranch:i,shouldClearSavedSourceBranch:o}=vt({branches:C.all,savedSourceBranch:r,rootBranch:e});if(o&&localStorage.removeItem(xt),n||t)return;i&&b(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,C?.all,h,y.sourceBranch,s,a]),X.useLayoutEffect(()=>{if(!e)return;v(`new-branch`),S({selectedBranch:``,worktreeName:``}),z(!1),ie(!1),B(!1),V(!1),H(``),de(``),J({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=P();b({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,P]),X.useEffect(()=>{if(_!==`new-branch`||!y.isSyncingWorktreeName)return;let e=$(Zn(y.branchName));b(t=>({...t,worktreeName:e}))},[_,y.branchName,y.isSyncingWorktreeName]);let nt=X.useCallback(async()=>{if(!g||!q.touched||Pe)return;Ie&&Ie.abort();let e=new AbortController;Le(e),J(e=>({...e,isValidating:!0}));try{let t=_===`new-branch`?y.branchName:x.selectedBranch,n=Xe.worktreeName,r=Zn(t),o=$(n),c=null,l=null;if(r||(c=i(`session.newWorktree.error.branchNameRequired`)),o||(l=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&o){let t=_===`new-branch`?y.linkedPr:null,n=t?$n(t,O,A):null,i={mode:_===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:o,existingBranch:n?.existingBranch??(_===`existing-branch`?r:void 0),...n?.ensureRemoteName?{ensureRemoteName:n.ensureRemoteName}:{},...n?.ensureRemoteUrl?{ensureRemoteUrl:n.ensureRemoteUrl}:{}},u=s?await a.validateGitWorktree(h,i):await ft(g,i);if(e.signal.aborted)return;u.ok||u.errors.forEach(e=>{if(e.code===`worktree_exists`){l??=e.message;return}e.code.startsWith(`branch_`)&&(c??=e.message)})}e.signal.aborted||J(e=>({...e,isValidating:!1,branchError:c,worktreeError:l}))}catch{e.signal.aborted||J(e=>({...e,isValidating:!1}))}},[s,a,h,g,_,y.branchName,y.linkedPr,x.selectedBranch,Xe.worktreeName,O,A,q.touched,Ie,Pe,i]),rt=_===`new-branch`?y.branchName:x.selectedBranch;X.useEffect(()=>{if(!e||!g||!q.touched||Pe)return;let t=setTimeout(()=>{nt()},300);return()=>clearTimeout(t)},[Xe.worktreeName,rt,e,g,nt,q.touched,Pe]);let it=async()=>{if(!g||!h){K.error(i(`session.newWorktree.error.noActiveProject`));return}J(e=>({...e,touched:!0}));let e=_===`new-branch`?y.branchName:x.selectedBranch,r=Xe.worktreeName,a=Zn(e),c=$(r);if(!a){K.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!c){K.error(i(`session.newWorktree.error.worktreeDirectoryRequired`));return}Ie&&(Ie.abort(),Le(null)),J(e=>({...e,isValidating:!1,branchError:null,worktreeError:null})),Fe(!0);try{let e=_===`new-branch`?y.linkedPr:null,r=_===`new-branch`?y.linkedIssue:null,l=_===`new-branch`?y.linkedPr:null,u=_===`new-branch`&&y.includePrDiff,d=!!(r||l);if(s&&o&&m?.hostId){let l=m;R.getState().setActiveProjectIdOnly(l.id);let f=e?$n(e,O,A):null,p=r?`#${r.number} ${r.title}`.trim():e?`#${e.number} ${e.title}`.trim():void 0,h=await un(l,{mode:f||_===`existing-branch`?`existing`:`new`,worktreeName:c,branchName:_===`new-branch`?a:void 0,existingBranch:f?.existingBranch??(_===`existing-branch`?a:void 0),..._===`new-branch`&&!f&&y.sourceBranch?{startRef:y.sourceBranch}:{},...f?{setUpstream:f.setUpstream,upstreamRemote:f.upstreamRemote,upstreamBranch:f.upstreamBranch,...f.ensureRemoteName?{ensureRemoteName:f.ensureRemoteName}:{},...f.ensureRemoteUrl?{ensureRemoteUrl:f.ensureRemoteUrl}:{}}:{}},{title:p,createSession:d,kind:e?`pr`:`standard`,createdFromBranch:f?.sourceLabel??y.sourceBranch,isSelected:()=>R.getState().activeProjectId===l.id});s.sdk();let g=L.getState().remoteSession;g?.projectId===l.id&&g.location.hubId===s.location.hubId&&g.location.hostId===s.location.hostId&&g.location.directory===h.path&&g.sessionId===(h.id??null)&&n?.(h.path,{...h.id?{sessionId:h.id}:{},remote:!0}),t(!1),K.success(i(`session.newWorktree.toast.worktreeCreated`)),h.id&&d&&Un(o.registry,s,h.path,h.id,{issue:r,pr:e,includeDiff:u},i(`session.newWorktree.error.sendGitHubContextFailed`)).catch(e=>{K.error(i(`session.newWorktree.error.sendGitHubContextFailed`),{description:e instanceof Error?e.message:String(e)})});return}let[f,p]=await Promise.all([Ee(g),gt(h)]),v=y.sourceBranch,b=``,S=(()=>{if(e){let t=$n(e,O,A);return b=t.sourceLabel,{preferredName:a||c,mode:`existing`,branchName:a,worktreeName:c,existingBranch:t.existingBranch,setupCommands:f,setUpstream:t.setUpstream,upstreamRemote:t.upstreamRemote,upstreamBranch:t.upstreamBranch,returnAfterDirectoryCreated:!0,...t.ensureRemoteName?{ensureRemoteName:t.ensureRemoteName}:{},...t.ensureRemoteUrl?{ensureRemoteUrl:t.ensureRemoteUrl}:{}}}return b=_===`new-branch`?v:``,{preferredName:a||c,mode:_===`existing-branch`?`existing`:`new`,branchName:_===`existing-branch`?void 0:a,worktreeName:c,existingBranch:_===`existing-branch`?a:void 0,setupCommands:f,returnAfterDirectoryCreated:!0,...v&&_===`new-branch`?{startRef:v}:{}}})(),C=await yt(h,S,{resolvedRootTrackingRemote:p}),w=await ht(g,C),T=null;if(d){await Se(g)&&await ye(w.worktreeRoot??w.path);let e=r?`#${r.number} ${r.title}`.trim():l?`#${l.number} ${l.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await le(e,w.path,null);if(!a?.id)throw Error(`Failed to create session`);T=a.id,n?.(w.path,{sessionId:T}),t(!1),Fe(!1),ge(a.id,e).catch(()=>void 0);try{W.getState().initializeNewYuriSession(a.id,ue.getState().agents)}catch{}}else t(!1),Fe(!1);let E=bt({mode:_,sourceBranch:y.sourceBranch,linkedPr:!!y.linkedPr,selectedBranch:x.selectedBranch});E&&localStorage.setItem(xt,E),K.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${w.branch||w.name}${b?` ${i(`session.newWorktree.fromSource`,{source:b})}`:``}`})}),T?Ye({sessionId:T,directory:w.path,issue:r,pr:l,includeDiff:u}).catch(e=>{let t=e instanceof Error?e.message:i(`session.newWorktree.error.sendGitHubContextFailed`);K.error(i(`session.newWorktree.error.sendGitHubContextFailed`),{description:t})}):n?.(w.path)}catch(e){let t=e instanceof Error?e.message:i(`session.newWorktree.error.createWorktreeFailed`);K.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{Fe(!1)}},ct=e=>{v(e),J(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},lt=e=>{if(!e){b(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${cn()}`;b(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:$(n),isSyncingWorktreeName:!0}))}else if(e.type===`pr`){let t=e.item;b(n=>({...n,linkedPr:t,linkedIssue:null,includePrDiff:e.includeDiff??!1,branchName:t.head,worktreeName:$(t.head),isSyncingWorktreeName:!0}))}},dt=p&&f?.connected===!0,pt=(_===`existing-branch`?!!x.selectedBranch&&!!x.worktreeName&&!q.branchError&&!q.worktreeError:!!Zn(y.branchName)&&!!y.worktreeName&&!q.branchError&&!q.worktreeError)&&!Pe,_t=()=>{b(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},St=s&&(j.error||l.error)?(0,Q.jsxs)(`div`,{role:`alert`,className:`typography-micro text-destructive`,children:[(j.error||l.error)?.message,(0,Q.jsx)(U,{size:`xs`,variant:`ghost`,onClick:()=>{j.refetch(),l.refetch()},children:i(`remoteProjects.retry`)})]}):null,Ct=(0,Q.jsxs)(`div`,{className:G(`flex gap-2`,u?`flex-col w-full`:`flex-row items-center`),children:[St,(0,Q.jsx)(`div`,{className:G(`flex items-center gap-1.5 text-destructive`,u?`w-full justify-center order-first`:`mr-auto`),children:q.touched&&(q.branchError||q.worktreeError)&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Y,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:q.branchError||q.worktreeError})]})}),(0,Q.jsxs)(`div`,{className:G(`flex gap-2`,u&&`w-full`),children:[(0,Q.jsx)(U,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:Pe,className:G(u&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,Q.jsxs)(U,{size:`sm`,onClick:it,disabled:!pt||Pe,className:G(`gap-1.5`,u&&`flex-1`),children:[Pe&&(0,Q.jsx)(Y,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(Pe?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,Q.jsxs)(Q.Fragment,{children:[u?(0,Q.jsx)(He,{id:`new-worktree-sheet-${d}`,open:e,onOpenChange:t,title:(0,Q.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold text-foreground`,children:i(`session.newWorktree.title`)}),ariaLabel:i(`session.newWorktree.title`),closeAriaLabel:i(`mobile.surface.closeAria`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),children:(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,Q.jsxs)(Ve,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`overscroll-contain px-4 pb-4 pt-2`,children:[(0,Q.jsx)(`div`,{className:`w-full mb-4`,children:(0,Q.jsx)(wt,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,Q.jsx)(Y,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,Q.jsx)(Y,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:_,onSelect:e=>ct(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[_===`existing-branch`?(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>B(!0),className:`flex-1 justify-between h-9`,children:[(0,Q.jsx)(`span`,{className:x.selectedBranch?`text-foreground`:`text-muted-foreground`,children:x.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,Q.jsx)(Y,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,Q.jsx)(U,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:Ne,disabled:!Me||T,title:i(`session.newWorktree.fetchBranches`),children:T?(0,Q.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):(0,Q.jsx)(Y,{name:`refresh`,className:`size-4`})})]}),(0,Q.jsx)(ut,{open:ae,title:i(`session.newWorktree.selectBranch`),onClose:()=>B(!1),children:(0,Q.jsxs)(`div`,{className:`space-y-4`,ref:me,children:[(0,Q.jsx)(st,{value:se,onChange:e=>H(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),T?(0,Q.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):O.length===0&&A.length===0?(0,Q.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[De&&Ae&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:we.matching.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{S(t=>({...t,selectedBranch:e.value,worktreeName:$(e.label)})),J(e=>({...e,touched:!0})),B(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,x.selectedBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),De&&!Ae&&(0,Q.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),we.otherLocal.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(De?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:we.otherLocal.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{S(t=>({...t,selectedBranch:e,worktreeName:$(e)})),J(e=>({...e,touched:!0})),B(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,x.selectedBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),we.otherRemote.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(De?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:we.otherRemote.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{S(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:$(e)})),J(e=>({...e,touched:!0})),B(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,x.selectedBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}):(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),_===`new-branch`&&dt&&(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>te(!0),className:`gap-1.5 h-7`,children:[(0,Q.jsx)(Y,{name:`github`,className:`size-4 text-status-success`}),y.linkedIssue||y.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,Q.jsx)(st,{value:y.branchName,onChange:e=>{b(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>J(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!y.linkedPr,className:G(`h-8`,q.touched&&q.branchError&&`border-destructive`,y.linkedPr&&`bg-muted text-muted-foreground`)}),y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:y.linkedPr.head})})]}),y.linkedIssue&&!y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:y.linkedIssue.number,title:y.linkedIssue.title})})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),_!==`existing-branch`&&(0,Q.jsxs)(`button`,{onClick:()=>{let e=$(_===`new-branch`?y.branchName:``);b(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!y.branchName||y.worktreeName===$(y.branchName),className:G(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,y.worktreeName===$(y.branchName)||!y.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,Q.jsx)(Y,{name:`refresh`,className:`h-3 w-3`}),(0,Q.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,Q.jsx)(st,{value:Xe.worktreeName,onChange:e=>{_===`new-branch`?b(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):S(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>J(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:G(`h-8`,q.touched&&q.worktreeError&&`border-destructive`)})]}),_===`new-branch`&&!y.linkedPr&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>V(!0),className:`w-full justify-between h-9`,children:[(0,Q.jsx)(`span`,{className:y.sourceBranch?`text-foreground`:`text-muted-foreground`,children:y.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,Q.jsx)(Y,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),y.sourceBranch&&(0,Q.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:y.sourceBranch})}),(0,Q.jsx)(ut,{open:oe,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>V(!1),children:(0,Q.jsxs)(`div`,{className:`space-y-4`,ref:he,children:[(0,Q.jsx)(st,{value:ce,onChange:e=>de(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),T?(0,Q.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):O.length===0&&A.length===0?(0,Q.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[Oe&&je&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:Te.matching.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{b(t=>({...t,sourceBranch:e.value})),V(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.sourceBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),Oe&&!je&&(0,Q.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),Te.otherLocal.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(Oe?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:Te.otherLocal.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{b(t=>({...t,sourceBranch:e})),V(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.sourceBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),Te.otherRemote.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(Oe?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:Te.otherRemote.map(e=>(0,Q.jsx)(`button`,{onClick:()=>{b(t=>({...t,sourceBranch:`remotes/${e}`})),V(!1)},className:G(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.sourceBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}),(y.linkedIssue||y.linkedPr)&&_===`new-branch`&&(0,Q.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Y,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),y.linkedIssue&&(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:y.linkedIssue.number})}),y.linkedPr&&(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:y.linkedPr.number})}),(0,Q.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:y.linkedIssue?.title||y.linkedPr?.title}),(0,Q.jsx)(`a`,{href:y.linkedIssue?.url||y.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(Y,{name:`external-link`,className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:_t,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,Q.jsx)(Y,{name:`close`,className:`h-3.5 w-3.5`})})]}),y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,Q.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[y.linkedPr.head,` → `,y.linkedPr.base]}),y.includePrDiff&&(0,Q.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]})]}),(0,Q.jsx)(`div`,{className:`shrink-0 border-t border-border/50 px-4 pb-3 pt-2`,children:Ct})]})}):(0,Q.jsx)(qe,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ge,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,Q.jsx)(Ue,{className:`flex flex-row items-center justify-between`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(Ke,{className:`flex items-center gap-2 shrink-0`,children:[(0,Q.jsx)(Y,{name:`git-branch`,className:`h-5 w-5`}),i(`session.newWorktree.title`)]}),(0,Q.jsx)(`div`,{className:`w-[280px] shrink-0`,children:(0,Q.jsx)(wt,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,Q.jsx)(Y,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,Q.jsx)(Y,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:_,onSelect:e=>ct(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})})]})}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto mt-2 space-y-6`,children:[_===`existing-branch`?(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)($e,{open:I,onOpenChange:z,children:[(0,Q.jsx)(Ze,{asChild:!0,children:(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:G(`truncate`,x.selectedBranch?`text-foreground`:`text-muted-foreground`),children:x.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,Q.jsx)(Y,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(Qe,{align:`start`,sideOffset:6,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:fe,children:(0,Q.jsxs)(Tn,{shouldFilter:!1,children:[(0,Q.jsx)(En,{placeholder:i(`session.newWorktree.searchBranches`),value:se,onValueChange:H,onKeyDown:_e}),(0,Q.jsx)(Dn,{disableHorizontal:!0,children:T?(0,Q.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):O.length===0&&A.length===0?(0,Q.jsx)(On,{children:i(`session.newWorktree.noBranchesFound`)}):(0,Q.jsxs)(Q.Fragment,{children:[De&&Ae&&(0,Q.jsx)(kn,{heading:i(`session.newWorktree.matchingBranches`),children:we.matching.map(e=>(0,Q.jsx)(jn,{value:e.value,onSelect:()=>{S(t=>({...t,selectedBranch:e.value,worktreeName:$(e.label)})),J(e=>({...e,touched:!0})),z(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),De&&!Ae&&(0,Q.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),we.otherLocal.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[De&&(0,Q.jsx)(An,{}),(0,Q.jsx)(kn,{heading:i(De?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:we.otherLocal.map(e=>(0,Q.jsx)(jn,{value:e,onSelect:()=>{S(t=>({...t,selectedBranch:e,worktreeName:$(e)})),J(e=>({...e,touched:!0})),z(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),we.otherRemote.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(we.otherLocal.length>0||De)&&(0,Q.jsx)(An,{}),(0,Q.jsx)(kn,{heading:i(De?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:we.otherRemote.map(e=>(0,Q.jsx)(jn,{value:`remotes/${e}`,onSelect:()=>{S(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:$(e)})),J(e=>({...e,touched:!0})),z(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,Q.jsx)(U,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:Ne,disabled:!Me||T,title:i(`session.newWorktree.fetchBranches`),children:T?(0,Q.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):(0,Q.jsx)(Y,{name:`refresh`,className:`size-4`})})]})]}):(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),_===`new-branch`&&dt&&(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>te(!0),className:`gap-1.5 h-7`,children:[(0,Q.jsx)(Y,{name:`github`,className:`size-4 text-status-success`}),y.linkedIssue||y.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,Q.jsx)(st,{value:y.branchName,onChange:e=>{b(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>J(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!y.linkedPr,className:G(`h-8`,q.touched&&q.branchError&&`border-destructive`,y.linkedPr&&`bg-muted text-muted-foreground`)}),y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:y.linkedPr.head})})]}),y.linkedIssue&&!y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Q.jsx)(Y,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:y.linkedIssue.number,title:y.linkedIssue.title})})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),_!==`existing-branch`&&(0,Q.jsxs)(`button`,{onClick:()=>{let e=$(_===`new-branch`?y.branchName:``);b(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!y.branchName||y.worktreeName===$(y.branchName),className:G(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,y.worktreeName===$(y.branchName)||!y.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,Q.jsx)(Y,{name:`refresh`,className:`h-3 w-3`}),(0,Q.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,Q.jsx)(st,{value:Xe.worktreeName,onChange:e=>{_===`new-branch`?b(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):S(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>J(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:G(`h-8`,q.touched&&q.worktreeError&&`border-destructive`)})]}),_===`new-branch`&&!y.linkedPr&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,Q.jsxs)($e,{open:ne,onOpenChange:ie,children:[(0,Q.jsx)(Ze,{asChild:!0,children:(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:G(`truncate`,y.sourceBranch?`text-foreground`:`text-muted-foreground`),children:y.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,Q.jsx)(Y,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(Qe,{align:`start`,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:pe,children:(0,Q.jsxs)(Tn,{shouldFilter:!1,children:[(0,Q.jsx)(En,{placeholder:i(`session.newWorktree.searchBranches`),value:ce,onValueChange:de,onKeyDown:_e}),(0,Q.jsx)(Dn,{disableHorizontal:!0,children:T?(0,Q.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):O.length===0&&A.length===0?(0,Q.jsx)(On,{children:i(`session.newWorktree.noBranchesFound`)}):(0,Q.jsxs)(Q.Fragment,{children:[Oe&&je&&(0,Q.jsx)(kn,{heading:i(`session.newWorktree.matchingBranches`),children:Te.matching.map(e=>(0,Q.jsx)(jn,{value:e.value,onSelect:()=>{b(t=>({...t,sourceBranch:e.value})),ie(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),Oe&&!je&&(0,Q.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),Te.otherLocal.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[Oe&&(0,Q.jsx)(An,{}),(0,Q.jsx)(kn,{heading:i(Oe?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:Te.otherLocal.map(e=>(0,Q.jsx)(jn,{value:e,onSelect:()=>{b(t=>({...t,sourceBranch:e})),ie(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),Te.otherRemote.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(Te.otherLocal.length>0||Oe)&&(0,Q.jsx)(An,{}),(0,Q.jsx)(kn,{heading:i(Oe?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:Te.otherRemote.map(e=>(0,Q.jsx)(jn,{value:`remotes/${e}`,onSelect:()=>{b(t=>({...t,sourceBranch:`remotes/${e}`})),ie(!1)},children:(0,Q.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),y.sourceBranch&&(0,Q.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:y.sourceBranch})})]}),(y.linkedIssue||y.linkedPr)&&_===`new-branch`&&(0,Q.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Y,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),y.linkedIssue&&(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:y.linkedIssue.number})}),y.linkedPr&&(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:y.linkedPr.number})}),(0,Q.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:y.linkedIssue?.title||y.linkedPr?.title}),(0,Q.jsx)(`a`,{href:y.linkedIssue?.url||y.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(Y,{name:`external-link`,className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:_t,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,Q.jsx)(Y,{name:`close`,className:`h-3.5 w-3.5`})})]}),y.linkedPr&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,Q.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[y.linkedPr.head,` → `,y.linkedPr.base]}),y.includePrDiff&&(0,Q.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]}),(0,Q.jsxs)(We,{className:`mt-1 flex items-center justify-between`,children:[St,(0,Q.jsx)(`div`,{className:`flex items-center gap-1.5 text-destructive`,children:q.touched&&(q.branchError||q.worktreeError)&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Y,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`typography-micro`,children:q.branchError||q.worktreeError})]})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(U,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:Pe,children:i(`session.newWorktree.actions.cancel`)}),(0,Q.jsxs)(U,{size:`sm`,onClick:it,disabled:!pt||Pe,className:`gap-1.5`,children:[Pe&&(0,Q.jsx)(Y,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(Pe?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]})]})}),(0,Q.jsx)(Yn,{projectId:m?.id,open:F,onOpenChange:te,onSelect:lt})]})}var ir=null,ar=new Set,or=()=>{for(let e of ar)e()},sr=e=>e===`chat`||e===`assistant`,cr=()=>ir,lr=e=>{ir!==e&&(ir=e,or())},ur=e=>{ir&&(e&&ir.surfaceID!==e||(ir=null,or()))},dr=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},fr=e=>{let t=e.options?.delivery===`steer`?`steer`:e.options?.delivery===`queue`?`queue`:void 0,n={...t?{delivery:t}:{},...e.options?.commitStagedMessageEdit===void 0?{}:{commitStagedMessageEdit:e.options.commitStagedMessageEdit},...e.options?.messageID?{messageID:e.options.messageID}:{},...e.options?.ticket?{ticket:e.options.ticket}:{}},r=e.options?.sessionId??e.sessionID??void 0;if(!r)return n;let i=e.options?.directoryHint===void 0?e.directory||null:e.options.directoryHint;return{...n,sessionId:r,directoryHint:i}},pr=(e,t,n={})=>({operation:t,surfaceID:e.surfaceID,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration,sessionID:e.sessionID,directory:e.directory??``,draftKey:e.draftKey,deliveryTarget:e.deliveryTarget,...n}),mr=e=>{if(!e.active||!e.draftKey||!e.directory)return null;let t=e.activity?.phase??`idle`,n=e.activity?.canAbort??(t===`busy`||t===`retry`);return{send:async t=>{let n=pr(e,`send`,t);return await e.selection.flush(),e.kind===`secondary`&&await e.shortcuts.submit(),e.backend.send(n)},sendQueued:async(t,n={})=>{let{manual:r,...i}=n,a=pr(e,`send`,i),o=Qt(e);if(await e.selection.flush(),!o)throw Error(`chat-input-queue-scope-incomplete`);return e.backend.sendQueued({...a,queueItemID:t,manual:r,queueScope:o})},create:async()=>{let t=pr(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=pr(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=pr(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Qt(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Gt(e,{name:t,source:`yuri`}),shortcut:async(t,n=1)=>{if(e.kind===`secondary`){t===`cycle`?await e.shortcuts.cycle(n):t===`new`?await e.shortcuts.new():t===`abort`?await e.shortcuts.abort():await e.shortcuts.submit();return}if(t===`abort`){let t=pr(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=pr(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},hr=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,gr=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},_r=e=>e.type!==`tool`||hr(e)?!1:!gr(e),vr=e=>{let t=0;for(let n of e)_r(n)&&(t+=1);return t},yr=(e,t)=>e===`stop`&&vr(t)===0,br=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&Tt(t)},xr=e=>{if(vr(e)!==0)return-1;for(let t=e.length-1;t>=0;--t){let n=e[t];if(br(n))return t;if(n.type===`tool`||n.type===`reasoning`||n.type===`file`||n.type===`agent`||n.type===`subtask`)break}return-1},Sr=(e,t,n)=>{if(n||!yr(e,t))return!1;for(let e of t)if(br(e))return!0;return!1},Cr=e=>e===`streaming`||e===`cooldown`,wr=e=>e.parts.some(br),Tr=e=>Cr(e.streamPhase)?wr(e):!1,Er=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},Dr=e=>{let t=e?.type;return t===`compaction`?!f(e):t===`text`&&Er(e).trim()===`/compact`},Or=e=>e?e.some(e=>Dr(e)):!1,kr=e=>Or(e.parts),Ar=e=>e?Or(e.sourceParts)||Or(e.parts):!1,jr=e=>{if(!kr(e))return e;let t=!1,n=e.parts.map(e=>e?.type!==`compaction`||f(e)?e:(t=!0,{type:`text`,text:`/compact`})),r=e.info.clientRole!==`user`;return!t&&!r?e:{...e,info:r?{...e.info,clientRole:`user`}:e.info,parts:t?n:e.parts}},Mr=e=>{let t=Et(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},Nr=new WeakMap,Pr=e=>{let t=Nr.get(e);if(t)return t;let n=jr(Mr(e)),r=n.parts,i=P(r),a=i===r?n:{...n,parts:i,sourceParts:r};return Nr.set(e,a),a},Fr={activity:`idle`,hasWorkingContext:!1,hasActiveTools:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,lifecyclePhase:null,statusText:null,isGenericStatus:!0,isWaitingForPermission:!1,canAbort:!1,compactionDeadline:null,activePartType:void 0,activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:null,turnStartedAt:void 0},Ir=[],Lr=`\0`,Rr=new Set([`edit`,`write`,`apply_patch`]),zr={read:`chat.assistantStatus.readingFile`,write:`chat.assistantStatus.writingFile`,edit:`chat.assistantStatus.editingFile`,apply_patch:`chat.assistantStatus.applyingPatch`,bash:`chat.assistantStatus.runningCommand`,grep:`chat.assistantStatus.searchingContent`,glob:`chat.assistantStatus.findingFiles`,list:`chat.assistantStatus.listingDirectory`,task:`chat.assistantStatus.delegatingTask`,webfetch:`chat.assistantStatus.fetchingUrl`,websearch:`chat.assistantStatus.searchingWeb`,codesearch:`chat.assistantStatus.webCodeSearch`,todowrite:`chat.assistantStatus.updatingTodos`,todoread:`chat.assistantStatus.readingTodos`,skill:`chat.assistantStatus.learningSkill`,question:`chat.assistantStatus.askingQuestion`,execute:`chat.assistantStatus.executing`,session_rename:`chat.assistantStatus.renamingSession`,session_move:`chat.assistantStatus.movingSession`,browser:`chat.assistantStatus.usingBrowser`},Br=[`chat.assistantStatus.working`,`chat.assistantStatus.processing`,`chat.assistantStatus.preparing`,`chat.assistantStatus.warmingUp`,`chat.assistantStatus.gearsTurning`,`chat.assistantStatus.computing`,`chat.assistantStatus.calculating`,`chat.assistantStatus.analyzing`,`chat.assistantStatus.wheelsSpinning`,`chat.assistantStatus.calibrating`,`chat.assistantStatus.synthesizing`,`chat.assistantStatus.connectingDots`,`chat.assistantStatus.inspectingLogic`,`chat.assistantStatus.weighingOptions`],Vr=(e,t)=>{let n=zr[Be(e)];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},Hr=e=>{let t=0;for(let n=0;n<e.length;n+=1)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t)},Ur=(e,t)=>t(Br[Hr(e)%Br.length]??`chat.assistantStatus.working`),Wr=(e,t,n)=>{let r,i;if(!we(e))for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)switch(n.type){case`reasoning`:{let e=n.time??Xr(n);(!e||e.end===void 0)&&!r&&(r=`reasoning`);break}case`tool`:{let e=n.state?.status;if((e===`running`||e===`pending`)&&!r){let e=Be(Zr(n));Rr.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=Yr(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=Xr(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?n(`chat.assistantStatus.editingFile`):r===`tool`&&i?Vr(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):Ur(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},Gr=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(Lr),Kr=e=>{let[t,n,r=`working`,i]=e.split(Lr);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},qr=e=>e.type===`reasoning`,Jr=e=>e.type===`text`,Yr=e=>{if(Jr(e))return e.text;let t=e;if(typeof t.text==`string`)return t.text;if(typeof t.content==`string`)return t.content;if(typeof t.value==`string`)return t.value},Xr=e=>(Jr(e)||qr(e),e.time),Zr=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function Qr(e,t){let{t:n}=ze(),r=W(e=>e.currentSessionId),i=W(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=H(e=>!!(a&&e.session_execution_recovery[a]),o??void 0),c=X.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),l=W(c),u=he(a??``,o??void 0),d=X.useMemo(()=>{for(let e=u.length-1;e>=0;e--){let t=u[e];if(t.role===`assistant`)return{id:t.id,index:e,finish:t.finish,error:t.error,isCompaction:t.clientRole===`compaction`,startedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,index:-1,finish:void 0,error:void 0,isCompaction:!1,startedAt:void 0}},[u]),f=d.id,p=X.useMemo(()=>{for(let e=u.length-1;e>=0;e--){let t=u[e];if(t.role===`user`&&!g(t))return{id:t.id,index:e,turnStartedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,index:-1,turnStartedAt:void 0}},[u]),m=p.id,h=De(f??``,o??void 0,a??void 0),_=De(m??``,o??void 0,a??void 0),v=!!m&&Or(_),y=d.isCompaction&&d.index>p.index?h.find(e=>e.type===`compaction`):void 0,b=y?.reason===`manual`?d.startedAt:p.turnStartedAt,x=!!(f&&d.index>p.index&&(y?y.status===`failed`||y.reason===`manual`&&y.status===`completed`:Sr(d.finish,h,d.error))),S=X.useMemo(()=>{let e=`${a??``}:${f??``}`;return Gr(Wr(f&&!d.error&&d.index>p.index?h:Ir,e,n))},[a,f,d.error,d.index,p.index,h,n]),C=Te(a??``,o??void 0),w=xe(a??``,o??void 0),T=X.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),E=W(T),{phase:D,isWorking:O}=nn(a,o??void 0),k=!!(d.error&&d.index>p.index),A=ve(a??``,o??void 0),ee=A?.type===`retry`?A.attempt:void 0,j=A?.type===`retry`?A.next:void 0,M=X.useMemo(()=>Kr(S),[S]),N=X.useMemo(()=>{let e=!!(E&&!E.acknowledged);return{wasAborted:e,abortActive:e}},[E]),P=X.useMemo(()=>{if(s)return{...Fr,isRecovering:!0,canAbort:O};if(k&&D!==`retry`)return{...Fr,isTurnSettled:!0,canAbort:O};if(N.wasAborted)return{...Fr,wasAborted:!0,abortActive:N.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};if(x)return{...Fr,isComplete:y?.status!==`failed`,isTurnSettled:!0,turnStartedAt:b};let e=O,t=D===`busy`,r=D===`retry`,i=e&&(v||y?.status===`running`),a=`idle`;e&&(a=!i&&(M.activePartType===`tool`||M.activePartType===`editing`)?`tooling`:`streaming`);let o=r?{attempt:ee,next:j,message:A?.type===`retry`?A.message:void 0}:null;return{activity:a,hasWorkingContext:e,hasActiveTools:!i&&(M.activePartType===`tool`||M.activePartType===`editing`),isWorking:e,isStreaming:t,isCooldown:!1,lifecyclePhase:t?`streaming`:null,statusText:e?i?n(`chat.assistantStatus.compacting`):M.statusText:null,isGenericStatus:!e||!i&&M.isGenericStatus,isWaitingForPermission:!1,canAbort:e,compactionDeadline:null,activePartType:e&&!i?M.activePartType:void 0,activeToolName:e&&!i?M.activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:o,turnStartedAt:b}},[s,k,D,O,x,v,y?.status,b,M,N,ee,j,A,n]);return{forming:X.useMemo(()=>({isActive:!s&&!k&&O&&M.activePartType===`text`,characterCount:0}),[s,k,O,M.activePartType]),working:X.useMemo(()=>{if(s||P.wasAborted||P.abortActive)return P;if(l)return{...P,activity:`streaming`,hasWorkingContext:!0,isWorking:!0,isStreaming:!0,isCooldown:!1,lifecyclePhase:`streaming`,statusText:n(`chat.assistantStatus.sendingMessage`),isGenericStatus:!1,isWaitingForPermission:!1,canAbort:!0,activePartType:void 0,activeToolName:void 0,isComplete:!1,isTurnSettled:!1,retryInfo:null};let e=C.length>0,t=w.length>0;return!e&&!t?P:t?{...P,statusText:null,isWorking:!1,hasWorkingContext:!1,hasActiveTools:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null}:{...P,statusText:n(`chat.assistantStatus.waitingForPermission`),isWaitingForPermission:!0,canAbort:!1,retryInfo:null}},[s,P,l,C,w,n])}}var $r=`--yuri-mobile-header-collapse`,ei=e=>e.closest(`.mobile-chat-screen`)?.querySelector(`:scope > [data-yuri-collapsible-header="true"]`)??null,ti=e=>{e.style.removeProperty($r),delete e.dataset.yuriHeaderCollapsePhase,delete e.dataset.yuriHeaderCollapseRest},ni=(e,t,n)=>{let r=String(t.progress),i=t.phase,a=t.rest===`compact`?`collapsed`:`expanded`;return n?.phase!==i&&(e.dataset.yuriHeaderCollapsePhase=i,i===`snapping`&&n&&n.phase!==`snapping`&&e.offsetWidth),n?.progress!==r&&e.style.setProperty($r,r),n?.rest!==a&&(e.dataset.yuriHeaderCollapseRest=a),{progress:r,phase:i,rest:a}},ri=e=>{let t=e.startsWith(`#`)?e.slice(1):e;if(!t)return null;let n=t.match(/^turn-(.+)$/);if(n?.[1])return{kind:`turn`,id:n[1]};let r=t.match(/^message-(.+)$/);return r?.[1]?{kind:`message`,id:r[1]}:null},ii=(e,t,n)=>{if(n===0||e.length===0)return{kind:`noop`};let r=t?e.indexOf(t):e.length-1,i=(r>=0?r:e.length-1)+n;if(i>=e.length)return{kind:`resume`};let a=e[Math.max(0,i)];return a?{kind:`turn`,turnId:a}:{kind:`noop`}},ai=e=>{if(typeof window>`u`)return;let t=e?`#${e}`:``,n=`${window.location.pathname}${window.location.search}${t}`;window.history.replaceState(window.history.state,``,n),e&&window.dispatchEvent(new HashChangeEvent(`hashchange`))},oi=e=>{e&&ai(`message-${e}`)},si=e=>{let t=(0,Z.c)(29),{sessionId:n,turnIds:r,activeTurnId:i,scrollToTurn:a,scrollToMessage:o,resumeToBottom:s}=e,c=X.useRef(r),l=X.useRef(i),u,d;t[0]===r?(u=t[1],d=t[2]):(u=()=>{c.current=r},d=[r],t[0]=r,t[1]=u,t[2]=d),X.useEffect(u,d);let f,p;t[3]===i?(f=t[4],p=t[5]):(f=()=>{l.current=i},p=[i],t[3]=i,t[4]=f,t[5]=p),X.useEffect(f,p);let m;t[6]===a?m=t[7]:(m=async(e,t)=>e?(t?.updateHash!==!1&&ai(`turn-${e}`),a(e,{behavior:t?.behavior})):!1,t[6]=a,t[7]=m);let h=m,g;t[8]===o?g=t[9]:(g=async(e,t)=>e?(t?.updateHash!==!1&&ai(`message-${e}`),o(e,{behavior:t?.behavior})):!1,t[8]=o,t[9]=g);let _=g,v;t[10]!==s||t[11]!==h?(v=async(e,t)=>{let n=c.current,r=ii(n,l.current,e);if(r.kind===`noop`)return e===0;if(r.kind===`resume`){if(t?.resumePastEnd===!1){let e=n[n.length-1];return e?h(e,{behavior:`auto`}):!1}return ai(null),s(),!0}return h(r.turnId,{behavior:`auto`})},t[10]=s,t[11]=h,t[12]=v):v=t[12];let y=v,b;t[13]===s?b=t[14]:(b=()=>{ai(null),s()},t[13]=s,t[14]=b);let x=b,S;t[15]!==_||t[16]!==h||t[17]!==n?(S=()=>{if(!n||typeof window>`u`)return;let e=()=>{let e=ri(window.location.hash);if(e){if(e.kind===`turn`){h(e.id,{behavior:`auto`,updateHash:!1});return}_(e.id,{behavior:`auto`,updateHash:!1})}};return e(),window.addEventListener(`hashchange`,e),()=>{window.removeEventListener(`hashchange`,e)}},t[15]=_,t[16]=h,t[17]=n,t[18]=S):S=t[18];let C;t[19]!==_||t[20]!==h||t[21]!==n||t[22]!==r.length?(C=[n,_,h,r.length],t[19]=_,t[20]=h,t[21]=n,t[22]=r.length,t[23]=C):C=t[23],X.useEffect(S,C);let w;return t[24]!==x||t[25]!==y||t[26]!==_||t[27]!==h?(w={scrollToTurnId:h,scrollToMessageId:_,scrollByTurnOffset:y,resumeToLatest:x},t[24]=x,t[25]=y,t[26]=_,t[27]=h,t[28]=w):w=t[28],w},ci=[0,200,400],li=e=>{let t=(0,Z.c)(5),{className:n}=e,r;t[0]===n?r=t[1]:(r=G(`inline-flex`,n),t[0]=n,t[1]=r);let i;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(i=ci.map(ui),t[2]=i):i=t[2];let a;return t[3]===r?a=t[4]:(a=(0,Q.jsxs)(Q.Fragment,{children:[`\xA0`,(0,Q.jsx)(`span`,{className:r,"aria-hidden":`true`,children:i})]}),t[3]=r,t[4]=a),a};function ui(e){return(0,Q.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}export{En as A,Xt as B,sr as C,Tn as D,Ln as E,wn as F,Ut as G,Vt as H,cn as I,qt as J,Yt as K,rn as L,Dn as M,Cn as N,On as O,Sn as P,Ot as Q,an as R,cr as S,nr as T,$t as U,Gt as V,Zt as W,Bt as X,Jt as Y,Dt as Z,Tr as _,ti as a,fr as b,Qr as c,wr as d,vr as f,br as g,yr as h,$r as i,jn as j,kn as k,Pr as l,Sr as m,oi as n,ni as o,xr as p,Ht as q,si as r,ei as s,li as t,Ar as u,dr as v,lr as w,ur as x,mr as y,nn as z};
|