@openchamber/web 1.21.0 → 1.21.1

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.
Files changed (135) hide show
  1. package/bin/cli.test.js +35 -0
  2. package/bin/lib/DOCUMENTATION.md +12 -0
  3. package/bin/lib/cli-settings-accessors.js +111 -0
  4. package/bin/lib/cli-settings-accessors.test.js +189 -0
  5. package/bin/lib/cli-startup.js +29 -9
  6. package/bin/lib/commands-connect-url.js +12 -14
  7. package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-BGj8TJxW.js} +1 -1
  8. package/dist/assets/CommitSection-DwGiXyjf.js +1 -0
  9. package/dist/assets/{DiffView-D5cvbEPb.js → DiffView-Db6bjVv1.js} +3 -3
  10. package/dist/assets/FilesView-DQOa7Lgz.js +17 -0
  11. package/dist/assets/GitView-CHzJxTi0.js +6 -0
  12. package/dist/assets/{JsonTreeView-osju7J70.js → JsonTreeView-CggOsLot.js} +1 -1
  13. package/dist/assets/MarkdownImageGallery-DoZpaHev.js +1 -0
  14. package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +12 -0
  15. package/dist/assets/{OnboardingScreen-w2VG4fWY.js → OnboardingScreen-C98d69Fp.js} +1 -1
  16. package/dist/assets/{PatchDiff-Dan3mADn.js → PatchDiff-DJYMUiXA.js} +1 -1
  17. package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-CY2bx_SB.js} +3 -3
  18. package/dist/assets/PlanView-PkiOY_9H.js +5 -0
  19. package/dist/assets/SettingsView-D-K3ELCM.js +28 -0
  20. package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-oyOm2fHR.js} +1 -1
  21. package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-lKyeQTPL.js} +6 -6
  22. package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-C7kBQNAA.js} +2 -2
  23. package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-BP7ebDFF.js} +1 -1
  24. package/dist/assets/{WalkthroughView-D9Q4lr5x.js → WalkthroughView-MuJodAHD.js} +2 -2
  25. package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-CZ0xPeaT.js} +1 -1
  26. package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-C9abMBTb.js} +1 -1
  27. package/dist/assets/de-CEoCz3j6.js +9 -0
  28. package/dist/assets/es-DwyXCqaL.js +15 -0
  29. package/dist/assets/{fr-5qJM0nFS.js → fr-CS7Csln9.js} +5 -5
  30. package/dist/assets/index-CUKcHnUA.css +1 -0
  31. package/dist/assets/{index-Brm3X9rs.js → index-CaPAjwXQ.js} +1 -1
  32. package/dist/assets/index-DIvDEKE-.js +7 -0
  33. package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-ZBvDxhVB.js} +1 -1
  34. package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-DiLRrkJr.js} +1 -1
  35. package/dist/assets/ja-vnwqLcx6.js +15 -0
  36. package/dist/assets/ko-CXuSfZv5.js +15 -0
  37. package/dist/assets/{main-vUCh0VB0.js → main-D5RWr6sJ.js} +2 -2
  38. package/dist/assets/main-DLlfDjQ_.js +926 -0
  39. package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
  40. package/dist/assets/markdownCore-CcTcLsQF.js +3 -0
  41. package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-CqR3icsk.js} +2 -2
  42. package/dist/assets/{mobile-CkX6H-IT.js → mobile-RN_UTTlB.js} +2 -2
  43. package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-CjRR5ESs.js} +3 -3
  44. package/dist/assets/pl-BJxry0Mi.js +15 -0
  45. package/dist/assets/pt-BR-DxLmkhdv.js +15 -0
  46. package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.js → renderElectronMiniChatApp-1wC94fQK.js} +2 -2
  47. package/dist/assets/renderMobileApp-ltva2Plg.js +25 -0
  48. package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +15 -0
  49. package/dist/assets/{scheduledTasksApi-CAGPh_gZ.js → scheduledTasksApi-mjMDet_H.js} +1 -1
  50. package/dist/assets/{shikiHighlight-BgTPSITe.js → shikiHighlight-fGmFkxAM.js} +1 -1
  51. package/dist/assets/tr-5Mk_hQ2Q.js +6 -0
  52. package/dist/assets/uk-ClgQjmlw.js +15 -0
  53. package/dist/assets/{useAppFontEffects-Cll4gnsh.js → useAppFontEffects-KP8_yiGW.js} +143 -141
  54. package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-HIjtuhxD.js} +2 -2
  55. package/dist/assets/useRootScrollLock-BSiQ5F75.js +1 -0
  56. package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-DrTPkHl4.js} +2 -2
  58. package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
  59. package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
  60. package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
  61. package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
  62. package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
  63. package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
  64. package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
  65. package/dist/assets/{web-components-DLnGY4fs.js → web-components-DOXvU-tB.js} +1 -1
  66. package/dist/assets/zh-CN-Ba6y8H-i.js +15 -0
  67. package/dist/assets/zh-TW-Dv8yyhN1.js +15 -0
  68. package/dist/index.html +5 -5
  69. package/dist/mini-chat.html +3 -3
  70. package/dist/mobile.html +3 -3
  71. package/dist/site.webmanifest +1 -1
  72. package/dist/sw.js +1 -1
  73. package/package.json +2 -2
  74. package/public/site.webmanifest +1 -1
  75. package/server/index.js +2 -2
  76. package/server/lib/cloudflare-tunnel.js +1 -1
  77. package/server/lib/fs/DOCUMENTATION.md +1 -0
  78. package/server/lib/fs/routes.js +21 -0
  79. package/server/lib/fs/routes.test.js +89 -3
  80. package/server/lib/git/DOCUMENTATION.md +4 -3
  81. package/server/lib/git/service.js +128 -6
  82. package/server/lib/git/service.test.js +191 -1
  83. package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
  84. package/server/lib/markdown-image-grants/routes.js +3 -1
  85. package/server/lib/markdown-image-grants/routes.test.js +14 -0
  86. package/server/lib/openchamber-sessions/routes.js +4 -1
  87. package/server/lib/openchamber-sessions/routes.test.js +23 -0
  88. package/server/lib/opencode/env-runtime.js +17 -1
  89. package/server/lib/opencode/env-runtime.test.js +56 -0
  90. package/server/lib/opencode/lifecycle.js +48 -9
  91. package/server/lib/opencode/lifecycle.test.js +125 -1
  92. package/server/lib/opencode/managed-process-registry.d.ts +13 -0
  93. package/server/lib/opencode/managed-process-registry.js +213 -163
  94. package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
  95. package/server/lib/opencode/project-directory-runtime.js +16 -11
  96. package/server/lib/opencode/project-directory-runtime.test.js +32 -12
  97. package/server/lib/opencode/pwa-manifest-routes.js +1 -1
  98. package/server/lib/opencode/routes-upgrade.test.js +96 -12
  99. package/server/lib/opencode/routes.js +53 -5
  100. package/server/lib/opencode/settings-helpers.js +3 -0
  101. package/server/lib/opencode/settings-helpers.test.js +10 -0
  102. package/server/lib/opencode/theme-runtime.js +1 -1
  103. package/server/lib/opencode/theme-runtime.test.js +129 -0
  104. package/server/lib/quota/DOCUMENTATION.md +19 -0
  105. package/server/lib/quota/providers/copilot.js +26 -10
  106. package/server/lib/quota/providers/copilot.test.js +78 -0
  107. package/server/lib/small-model/DOCUMENTATION.md +11 -5
  108. package/server/lib/small-model/call.js +64 -20
  109. package/server/lib/small-model/call.test.js +184 -2
  110. package/server/lib/tunnels/install-help.js +2 -2
  111. package/server/lib/tunnels/install-help.test.js +9 -0
  112. package/server/lib/walkthrough/languages.js +1 -0
  113. package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
  114. package/dist/assets/FilesView-DPU8aNPL.js +0 -17
  115. package/dist/assets/GitView-Ct6xWrVH.js +0 -6
  116. package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
  117. package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
  118. package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
  119. package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
  120. package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
  121. package/dist/assets/de-B_LdJwEM.js +0 -9
  122. package/dist/assets/es-CubfsAYV.js +0 -15
  123. package/dist/assets/index-BW82eK5v.css +0 -1
  124. package/dist/assets/index-rlLjZUM5.js +0 -7
  125. package/dist/assets/ja-DJYIBUlH.js +0 -15
  126. package/dist/assets/ko-DcUBkB7y.js +0 -15
  127. package/dist/assets/main-DLBxKIoX.js +0 -926
  128. package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
  129. package/dist/assets/pl-rB6BLcio.js +0 -15
  130. package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
  131. package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
  132. package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
  133. package/dist/assets/uk-INZlFD9A.js +0 -15
  134. package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
  135. package/dist/assets/zh-TW-Cwn3rNYZ.js +0 -15
@@ -1,6 +0,0 @@
1
- import{R as l,r as be,j as t,f as Ct}from"./vendor-react-BUCujlKS.js";import{f as et,y as Ze,_ as Rt,hG as Pn,cP as Kt,c8 as Jt,t as b,I as T,b0 as Ps,aZ as Fs,cN as br,a$ as Rs,cr as Bs,cs as Ds,ct as Ms,cu as Es,cm as qt,cn as Yt,B as W,hH as Fn,hI as Rn,bz as ht,bA as gt,bB as ft,bC as pt,bD as yt,S as ir,a4 as Qt,a5 as Xt,a6 as Zt,hJ as Bn,h as Ve,hK as Dn,hL as Mn,hM as En,hN as Tn,aY as An,aj as Ln,bK as On,hO as zn,hP as Gn,hQ as _n,hR as $n,hS as Hn,hT as Wn,hU as Un,bX as jr,bN as Kn,bO as Jn,bP as qn,bQ as Yn,bR as Qn,hV as Xn,bU as Zn,bE as Is,eI as ea,V as ta,a9 as sa,ab as ra,aa as na,bp as aa,hW as ia,bV as oa,hX as la,hY as ca,ac as da,hZ as ua,ad as ma,bI as ha,hz as ga,l as fa,bW as pa,g as xa,cw as wa,ai as ya,$ as ba,h_ as ja,h$ as Ss}from"./useAppFontEffects-Cll4gnsh.js";import{a as va,b as Ca,d as Na}from"./main-DLBxKIoX.js";import{s as Sa,q as ka,p as Va,I as Ia,R as Pa}from"./runtimeEndpointReset-BDh7r8BL.js";import{u as or}from"./vendor-zustand-BAGL70zf.js";import{r as Fa,u as Pt}from"./index-rlLjZUM5.js";import{C as Ra,a as Ba}from"./CommitSection-HJeMUAWb.js";import{P as Da}from"./PierreDiffViewer-CGoI2v0q.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-base-ui-_6j2xOWl.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CpzVNWAv.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DkQX2EBa.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-zod-BLfBSgBh.js";import"./SessionSwitcherDropdown-CJTrc8K7.js";import"./scheduledTasksApi-CAGPh_gZ.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./web-components-DLnGY4fs.js";import"./computeVirtualFileMetrics-Gi1d5eU1.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-CN_BctrR.js";import"./isDiffPlainText-pH9kAJQH.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-DFFv0hae.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";const vr="gitmojiCache",Ma=1e3*60*60*24*7,Cr="1",Ea="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Nr=i=>{if(!i||typeof i!="object")return!1;const e=i;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},ks=()=>{if(typeof window>"u")return null;try{const i=window.localStorage.getItem(vr);if(!i)return null;const e=JSON.parse(i);return!e||e.version!==Cr||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Nr),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Ta=i=>{if(!(typeof window>"u"))try{const e={gitmojis:i,fetchedAt:Date.now(),version:Cr};window.localStorage.setItem(vr,JSON.stringify(e))}catch{return}},lr=i=>Date.now()-i.fetchedAt<Ma;let Wt=null;const Ft=new Set,cr=async()=>{if(Wt)return Wt;const i=(async()=>{try{const e=await fetch(Ea);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),r=Array.isArray(n.gitmojis)?n.gitmojis.filter(Nr):[];return Ta(r),Ft.forEach(j=>j(r)),r}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return Ft.forEach(r=>r(n)),n}finally{Wt=null}})();return Wt=i,i},Aa=i=>{const[e,n]=l.useState(()=>i?ks()?.gitmojis??[]:[]),[r,j]=l.useState(!1),h=l.useRef(i);h.current=i,l.useEffect(()=>{if(!i){Ft.delete(n),n([]),j(!1);return}const f=ks();if(f&&(n(f.gitmojis),lr(f)))return;Ft.add(n),j(!0);let m=!1;return cr().finally(()=>{!m&&h.current&&j(!1)}),()=>{m=!0,Ft.delete(n)}},[i]);const p=l.useCallback(async()=>{if(!h.current)return[];if(e.length>0)return e;const f=ks();return f&&lr(f)?f.gitmojis:cr()},[e]);return{gitmojis:e,isLoading:r,ensureLoaded:p}},Nt=async(i,e)=>{const n=await Fa(`/api/git/integrate/${i}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>null);throw new Error(r?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function It(i){return Nt("plan",i)}async function La(i){return Nt("conflict-details",{tempWorktreePath:i})}async function Oa(i){return(await Nt("cherry-pick-status",{tempWorktreePath:i})).inProgress}async function za(i){return Nt("run",{plan:i})}async function Ga(i){await Nt("abort",{state:i})}async function _a(i){return Nt("continue",{state:i})}const $a=({repoRoot:i,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:j,refreshKey:h,onRefresh:p,showHeader:f=!0})=>{const{t:m}=et(),x=Ze(u=>u.currentSessionId),[E,y]=be.useState(!1),[C,I]=be.useState(""),D=be.useRef(null),O=be.useMemo(()=>Rt(r,C,u=>[u]),[r,C]),[v,w]=be.useState(j);be.useEffect(()=>{w(j)},[j]),be.useEffect(()=>{if(E){const u=setTimeout(()=>{D.current?.focus()},0);return()=>clearTimeout(u)}},[E]);const B=!!(i&&e&&v&&v!=="HEAD"&&e!==v),[S,R]=be.useState({kind:"idle"}),[V,P]=be.useState(!1),[g,H]=be.useState([]),A=be.useMemo(()=>x?`openchamber.integrate.conflict:${x}`:null,[x]);be.useEffect(()=>{if(!A||typeof window>"u")return;const u=window.localStorage.getItem(A);if(!u)return;let d=!1;try{const F=JSON.parse(u);if(!F?.tempWorktreePath||F.repoRoot!==i){window.localStorage.removeItem(A);return}(async()=>{const L=await Oa(F.tempWorktreePath).catch(()=>!1);if(d)return;if(!L){window.localStorage.removeItem(A);return}const q=await La(F.tempWorktreePath).catch(()=>null);d||q&&R({kind:"conflict",state:F,details:q})})()}catch{window.localStorage.removeItem(A)}return()=>{d=!0}},[A,i]),be.useEffect(()=>{if(!B){R({kind:"idle"});return}let u=!1;return R({kind:"loading"}),(async()=>{try{const d=await It({repoRoot:i,sourceBranch:e,targetBranch:v});if(u)return;if(R({kind:"ready",plan:d}),d.commits.length>0){const L=d.commits.slice(-50).reverse(),q=await Pn(i,L);u||(H(q),P(!1))}else u||(H([]),P(!1))}catch{u||R({kind:"idle"})}})(),()=>{u=!0}},[B,i,e,v,h]);const k=be.useCallback(u=>{x&&Ze.getState().setWorktreeMetadata(x,{...n,createdFromBranch:u})},[x,n]),M=Ze(u=>u.openNewSessionDraft),U=be.useCallback(async u=>{const d=await Kt("git.integrate.cherrypick.resolve.visible",{current_commit:u.state.currentCommit,target_branch:u.state.targetBranch}),F=await Kt("git.integrate.cherrypick.resolve.instructions",{repo_root:u.state.repoRoot,temp_worktree_path:u.state.tempWorktreePath,source_branch:u.state.sourceBranch,target_branch:u.state.targetBranch,current_commit:u.state.currentCommit}),L=`Cherry-pick conflict context (JSON)
2
- ${JSON.stringify({repoRoot:u.state.repoRoot,tempWorktreePath:u.state.tempWorktreePath,sourceBranch:u.state.sourceBranch,targetBranch:u.state.targetBranch,currentCommit:u.state.currentCommit,remainingCommits:u.state.remainingCommits,statusPorcelain:u.details.statusPorcelain,unmergedFiles:u.details.unmergedFiles,currentPatchMeta:u.details.currentPatchMeta,currentPatch:u.details.currentPatch,diff:u.details.diff},null,2)}`;return{visibleText:d,instructionsText:F,payloadText:L}},[]),$=Jt(u=>u.setPendingInputText),_=Jt(u=>u.setPendingSyntheticParts),Y=be.useCallback(async(u,d)=>{const F=await U(u);if(d){M({directoryOverride:u.state.tempWorktreePath,initialPrompt:F.visibleText,syntheticParts:[{text:F.instructionsText,synthetic:!0},{text:F.payloadText,synthetic:!0}]});return}if(!x){b.error(m("gitView.integrate.noActiveSession"),{description:m("gitView.integrate.noActiveSessionDescription")});return}$(F.visibleText,"replace"),_([{text:F.instructionsText,synthetic:!0},{text:F.payloadText,synthetic:!0}])},[x,U,M,$,_,m]),ee=be.useCallback(async()=>{if(S.kind==="ready"){if(S.plan.commits.length===0){b.message(m("gitView.integrate.noCommitsToMoveToast"));return}R({kind:"running",plan:S.plan});try{const u=await za(S.plan);if(u.kind==="success"){b.success(m("gitView.integrate.commitsMovedToast"),{description:u.moved===1?m("gitView.integrate.commitsMovedDescriptionSingle",{count:u.moved,branch:S.plan.targetBranch}):m("gitView.integrate.commitsMovedDescriptionPlural",{count:u.moved,branch:S.plan.targetBranch})});const d=await It(S.plan);R({kind:"ready",plan:d}),p?.();return}u.kind==="conflict"&&(b.error(m("gitView.integrate.cherryPickConflictToast"),{description:m("gitView.integrate.cherryPickConflictDescription")}),R({kind:"conflict",state:u.state,details:u.details}),A&&typeof window<"u"&&window.localStorage.setItem(A,JSON.stringify(u.state)))}catch(u){const d=u instanceof Error?u.message:String(u);b.error(m("gitView.integrate.failedToMoveToast"),{description:d});const F=await It({repoRoot:i,sourceBranch:e,targetBranch:v}).catch(()=>null);R(F?{kind:"ready",plan:F}:{kind:"idle"})}}},[S,p,i,e,v,A,m]),Z=be.useCallback(async()=>{if(S.kind==="conflict")try{await Ga(S.state),b.message(m("gitView.integrate.cherryPickAbortedToast")),A&&typeof window<"u"&&window.localStorage.removeItem(A)}finally{const u=await It({repoRoot:i,sourceBranch:e,targetBranch:v}).catch(()=>null);R(u?{kind:"ready",plan:u}:{kind:"idle"})}},[S,i,e,v,A,m]),oe=be.useCallback(async()=>{if(S.kind==="conflict")try{const u=await _a(S.state);if(u.kind==="success"){b.success(m("gitView.integrate.cherryPickFinishedToast"));const d=await It({repoRoot:i,sourceBranch:e,targetBranch:v}).catch(()=>null);R(d?{kind:"ready",plan:d}:{kind:"idle"}),A&&typeof window<"u"&&window.localStorage.removeItem(A),p?.();return}u.kind==="conflict"&&(R({kind:"conflict",state:u.state,details:u.details}),A&&typeof window<"u"&&window.localStorage.setItem(A,JSON.stringify(u.state)))}catch(u){const d=u instanceof Error?u.message:String(u);b.error(m("gitView.integrate.cherryPickContinueFailedToast"),{description:d})}},[S,i,e,v,p,A,m]);return!i||!e?null:t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[f?t.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(T,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:m("gitView.integrate.title")}),S.kind==="ready"&&S.plan.commits.length>0?t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:m("gitView.integrate.toMoveCount",{count:S.plan.commits.length})}):null]}),t.jsx("div",{className:"flex items-center gap-2",children:S.kind==="loading"||S.kind==="running"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}):null,t.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:m("gitView.integrate.moveCommits")}),t.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",v]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs(Ps,{open:E,onOpenChange:y,children:[t.jsx(Fs,{asChild:!0,children:t.jsxs("button",{type:"button",className:br({size:"default"}),children:[m("gitView.integrate.target"),t.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:v}),t.jsx(T,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),t.jsx(Rs,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:t.jsxs(Bs,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(Ds,{ref:D,placeholder:m("gitView.branch.searchPlaceholder"),value:C,onValueChange:I,onKeyDown:u=>u.stopPropagation()}),t.jsxs(Ms,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(Es,{children:m("gitView.branch.empty")}),t.jsx(qt,{heading:m("gitView.branch.localBranches"),children:O.map(u=>t.jsx(Yt,{value:u,onSelect:()=>{w(u),k(u),y(!1),I("")},children:u},u))})]})]})})]}),S.kind==="ready"?t.jsx(W,{size:"sm",onClick:()=>{ee()},disabled:!B||S.plan.commits.length===0,children:m("gitView.integrate.move")}):S.kind==="loading"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:m("gitView.integrate.checking")}):S.kind==="running"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:m("gitView.integrate.moving")}):null]}),S.kind==="ready"&&S.plan.commits.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:m("gitView.integrate.noCommitsToMove")}),S.kind==="ready"&&S.plan.commits.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"typography-meta text-foreground",children:[m("gitView.integrate.commitsToMove"),t.jsxs("span",{className:"text-muted-foreground",children:[" (",S.plan.commits.length,")"]})]}),g.length>0&&S.plan.commits.length>5&&t.jsx("button",{type:"button",onClick:()=>P(u=>!u),className:"typography-micro text-muted-foreground hover:text-foreground",children:m(V?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(V?g:g.slice(0,5)).map(u=>t.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[t.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:u.short}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:u.subject||u.sha})]},u.sha)),g.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:m("gitView.integrate.previewUnavailable")}),S.plan.commits.length>g.length&&t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:m("gitView.integrate.showingFirstCommits",{count:g.length})})]})]}),S.kind==="conflict"&&t.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[t.jsx("div",{className:"typography-meta text-foreground",children:m("gitView.integrate.conflictsInFiles",{count:S.details.unmergedFiles.length})}),t.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[m("gitView.integrate.currentCommit"),": ",t.jsx("span",{className:"font-mono",children:S.state.currentCommit.slice(0,7)})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[S.details.unmergedFiles.slice(0,6).map(u=>t.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:u},u)),S.details.unmergedFiles.length>6&&t.jsx("span",{className:"text-xs text-muted-foreground",children:m("gitView.integrate.moreFiles",{count:S.details.unmergedFiles.length-6})})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(W,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{Z()},children:m("gitView.operation.abort")}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!x,onClick:()=>{Y({state:S.state,details:S.details},!1)},children:[t.jsx(T,{name:"sparkling",className:"size-3.5"}),m("gitView.integrate.currentSession")]}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{Y({state:S.state,details:S.details},!0)},children:[t.jsx(T,{name:"sparkling",className:"size-3.5"}),m("gitView.integrate.newSession")]}),t.jsx(W,{size:"sm",className:"typography-meta",onClick:()=>{oe()},children:m("gitView.operation.continue")})]})]})]})]})},Ha=({open:i,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:j=!1,uncommittedFileCount:h,onChanged:p})=>{const{t:f}=et(),[m,x]=l.useState([]),[E,y]=l.useState(!1),[C,I]=l.useState(""),[D,O]=l.useState(""),[v,w]=l.useState(null),[B,S]=l.useState({}),R=l.useCallback(async()=>{if(n){y(!0);try{const k=await Fn(n);x(k.stashes),S({})}catch(k){b.error(k instanceof Error?k.message:f("gitView.stashes.toast.loadFailed"))}finally{y(!1)}}},[n,f]);l.useEffect(()=>{i&&R()},[R,i]),l.useEffect(()=>{if(!i||!n||m.length===0)return;let k=!1;const M=m.map(U=>U.ref);return Rn(n,M).then(U=>{k||S(U.counts)}).catch(()=>{}),()=>{k=!0}},[n,i,m]);const V=l.useMemo(()=>Rt(m,C,k=>[k.message,k.ref,k.relativeTime]),[C,m]),P=l.useCallback(async k=>{await R(),await p?.(k)},[R,p]),g=async()=>{if(!(!n||v)){w("create");try{const k=await Bn(n,{message:D.trim()||void 0});k.created?(b.success(f("gitView.stashes.toast.created")),O("")):b.info(f("gitView.stashes.toast.noChanges")),await P({affectsIndex:!!(k.created&&j)})}catch(k){b.error(k instanceof Error?k.message:f("gitView.stashes.toast.createFailed"))}finally{w(null)}}},H=async(k,M)=>{if(!(!n||v)&&!(M==="drop"&&!window.confirm(f("gitView.stashes.confirm.drop",{ref:k.ref})))){w(`${M}:${k.ref}`);try{M==="apply"&&await Dn(n,{ref:k.ref}),M==="pop"&&await Mn(n,{ref:k.ref}),M==="drop"&&await En(n,{ref:k.ref});const U=M==="apply"?"gitView.stashes.toast.applySuccess":M==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";b.success(f(U)),await P({affectsIndex:M!=="drop"})}catch(U){const $=M==="apply"?"gitView.stashes.toast.applyFailed":M==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";b.error(U instanceof Error?U.message:f($)),await P({affectsIndex:M!=="drop"})}finally{w(null)}}},A=v!==null;return t.jsx(ht,{open:i,onOpenChange:e,children:t.jsxs(gt,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsxs(ft,{children:[t.jsxs(pt,{className:"flex items-center gap-2",children:[t.jsx(T,{name:"archive-stack",className:"h-5 w-5"}),f("gitView.stashes.title")]}),t.jsx(yt,{children:f("gitView.stashes.description")})]}),t.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[t.jsx(ir,{value:D,onChange:k=>O(k.target.value),placeholder:f("gitView.stashes.messagePlaceholder"),disabled:A||!r,className:"flex-1"}),t.jsxs(W,{onClick:g,disabled:!r||A||!n,children:[v==="create"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"inbox-archive",className:"size-4"}),f("gitView.stashes.actions.stashCurrentWithCount",{count:h})]})]}),t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:f("gitView.stashes.includeUntrackedHint")})]}),t.jsxs("div",{className:"relative mt-2",children:[t.jsx(T,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ir,{value:C,onChange:k=>I(k.target.value),placeholder:f("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:E?t.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:t.jsx(T,{name:"loader-4",className:"size-5 animate-spin"})}):V.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:f(C?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):V.map((k,M)=>t.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[t.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[t.jsx("p",{className:"typography-small truncate text-foreground",children:k.message||f("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[t.jsxs(Qt,{children:[t.jsx(Xt,{asChild:!0,children:t.jsx("span",{children:M===0&&!C.trim()?f("gitView.stashes.latestLabel"):f("gitView.stashes.itemNumber",{number:M+1})})}),t.jsx(Zt,{sideOffset:6,children:k.ref})]})," · ",k.relativeTime," · ",typeof B[k.ref]=="number"?f("gitView.stashes.fileCount",{count:B[k.ref]}):f("gitView.stashes.fileCountLoading")]})]}),t.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[t.jsx(Vs,{label:f("gitView.stashes.actions.apply"),loading:v===`apply:${k.ref}`,onClick:()=>H(k,"apply"),disabled:A,children:t.jsx(T,{name:"inbox-unarchive",className:"size-4"})}),t.jsx(Vs,{label:f("gitView.stashes.actions.pop"),loading:v===`pop:${k.ref}`,onClick:()=>H(k,"pop"),disabled:A,children:t.jsx(T,{name:"inbox-unarchive-fill",className:"size-4"})}),t.jsx(Vs,{label:f("gitView.stashes.actions.drop"),loading:v===`drop:${k.ref}`,onClick:()=>H(k,"drop"),disabled:A,destructive:!0,children:t.jsx(T,{name:"delete-bin",className:"size-4"})})]})]},k.ref))})]})})},Vs=i=>{const e=Ct.c(17),{label:n,loading:r,disabled:j,destructive:h,onClick:p,children:f}=i,m=r||void 0,x=h?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let E;e[0]!==x?(E=Ve("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",x),e[0]=x,e[1]=E):E=e[1];let y;e[2]!==f||e[3]!==r?(y=r?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):f,e[2]=f,e[3]=r,e[4]=y):y=e[4];let C;e[5]!==j||e[6]!==n||e[7]!==p||e[8]!==m||e[9]!==E||e[10]!==y?(C=t.jsx(Xt,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":n,"aria-busy":m,className:E,onClick:p,disabled:j,children:y})}),e[5]=j,e[6]=n,e[7]=p,e[8]=m,e[9]=E,e[10]=y,e[11]=C):C=e[11];let I;e[12]!==n?(I=t.jsx(Zt,{sideOffset:6,children:n}),e[12]=n,e[13]=I):I=e[13];let D;return e[14]!==C||e[15]!==I?(D=t.jsxs(Qt,{children:[C,I]}),e[14]=C,e[15]=I,e[16]=D):D=e[16],D},Wa=i=>{const e=Ct.c(16),{onOpenStashes:n}=i,{t:r}=et();let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j=t.jsx(T,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=j):j=e[0];let h;e[1]!==r?(h=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=h):h=e[2];let p;e[3]!==h?(p=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:h}),e[3]=h,e[4]=p):p=e[4];let f;e[5]!==r?(f=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=f):f=e[6];let m;e[7]!==f?(m=t.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:f}),e[7]=f,e[8]=m):m=e[8];let x;e[9]!==n||e[10]!==r?(x=n?t.jsxs(W,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[t.jsx(T,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=x):x=e[11];let E;return e[12]!==p||e[13]!==m||e[14]!==x?(E=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[j,p,m,x]}),e[12]=p,e[13]=m,e[14]=x,e[15]=E):E=e[15],E},mt=8,Ua=i=>{const e=Ct.c(18),{laned:n,totalLanes:r,isExpanded:j}=i,{lane:h,color:p,connectors:f}=n,x=Math.max(r,h+1)*mt+mt/2,E=l.useRef(null),y=l.useRef(null);let C;e[0]!==p||e[1]!==f||e[2]!==h||e[3]!==x?(C=()=>{const w=E.current,B=y.current;if(!w||!B)return;const S=w.offsetHeight;if(S===0)return;const R=window.devicePixelRatio||1;B.width=x*R,B.height=S*R;const V=B.getContext("2d");if(!V)return;V.scale(R,R),V.clearRect(0,0,x,S);const P=S/2,g=h*mt+mt/2,H=getComputedStyle(B),A=H.getPropertyValue("--surface-muted-foreground").trim()||H.color,k=$=>{if(!$.startsWith("var("))return $;const _=$.slice(4,-1).trim();return H.getPropertyValue(_).trim()||A},M=[...f].sort(Ja);for(const $ of M){const _=$.fromLane*mt+mt/2,Y=$.toLane*mt+mt/2,ee=$.type==="passing"?.72:$.type==="branch-out"||$.type==="merge-in"?.95:1;V.beginPath(),V.strokeStyle=k($.color),V.globalAlpha=ee,V.lineWidth=1.25,V.lineCap="round";e:switch($.type){case"passing":case"commit-lane":{V.moveTo(_,0),V.lineTo(_,S);break e}case"top-stub":{V.moveTo(_,0),V.lineTo(_,P);break e}case"bottom-stub":{V.moveTo(_,P),V.lineTo(_,S);break e}case"branch-out":{const Z=(P+S)/2;V.moveTo(g,P),V.bezierCurveTo(g,Z,Y,Z,Y,S);break e}case"merge-in":{const Z=P/2;V.moveTo(_,0),V.bezierCurveTo(_,Z,g,Z,g,P);break e}default:continue}V.stroke(),V.globalAlpha=1}const U=H.getPropertyValue("--background").trim()||H.getPropertyValue("--surface-background").trim();V.beginPath(),V.arc(g,P,4,0,Math.PI*2),V.fillStyle=k(p),V.fill(),V.beginPath(),V.arc(g,P,5,0,Math.PI*2),V.strokeStyle=U||A,V.lineWidth=2,V.stroke()},e[0]=p,e[1]=f,e[2]=h,e[3]=x,e[4]=C):C=e[4];let I;e[5]!==p||e[6]!==f||e[7]!==j||e[8]!==h||e[9]!==n||e[10]!==r||e[11]!==x?(I=[n,h,p,f,r,j,x],e[5]=p,e[6]=f,e[7]=j,e[8]=h,e[9]=n,e[10]=r,e[11]=x,e[12]=I):I=e[12],l.useLayoutEffect(C,I);let D;e[13]!==x?(D={width:x,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=x,e[14]=D):D=e[14];let O;e[15]===Symbol.for("react.memo_cache_sentinel")?(O=t.jsx("canvas",{ref:y,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=O):O=e[15];let v;return e[16]!==D?(v=t.jsx("div",{ref:E,style:D,children:O}),e[16]=D,e[17]=v):v=e[17],v};function Ka(i){return i==="branch-out"||i==="merge-in"}function Ja(i,e){const n=Ka;return(n(i.type)?1:0)-(n(e.type)?1:0)}const dr=15e3,ur=500,mr=12,hr=8*1024*1024,gr=i=>typeof i=="string"?0:(i.original?.length??0)+(i.modified?.length??0),fr=i=>{if(i.size<=mr){let j=0;for(const h of i.values())j+=gr(h);if(j<=hr)return i}const e=Array.from(i.entries()).reverse(),n=new Map;let r=0;for(const[j,h]of e){if(n.size>=mr)continue;const p=gr(h);r+p>hr&&n.size>0||(n.set(j,h),r+=p)}return new Map(Array.from(n.entries()).reverse())};function pr(i,e){const n=new Date(i);return Number.isNaN(n.getTime())?i:On(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function qa(i){switch(i){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}function Ya(i){return i?i.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const Qa=l.memo(({entry:i,mode:e="history",laned:n,totalLanes:r,isExpanded:j,onToggle:h,files:p,isLoadingFiles:f,onCopyHash:m,directory:x,onConflict:E,onActionSuccess:y})=>{const{t:C}=et(),I=Pt(d=>d.timeFormatPreference),D=e==="graph",[O,v]=l.useState(null),[w,B]=l.useState(!1),[S,R]=l.useState(""),[V,P]=l.useState(null),[g,H]=l.useState(new Set),[A,k]=l.useState(new Map),[M,U]=l.useState(new Set),$=async()=>{if(x){v("checkout");try{await Un(x,i.hash),b.success(C("gitView.history.actions.detachedHead")),y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},_=async()=>{if(!(!x||!S.trim())){v("createBranch");try{await zn(x,S.trim(),i.hash),B(!1),R(""),y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},Y=async()=>{if(x){v("cherryPick");try{const d=await Wn(x,i.hash);d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"cherry-pick"}):y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},ee=async()=>{if(x){v("revert");try{const d=await Hn(x,i.hash);d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"revert"}):y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},Z=async(d,F=!1)=>{if(!(!x||O!==null)){v("reset");try{await Gn(x,i.hash,d,F),y?.()}catch(L){b.error(String(L.message))}finally{v(null)}}},oe=async()=>{if(!V)return;const d=V;switch(P(null),d){case"checkout":return $();case"cherryPick":return Y();case"revert":return ee();case"merge":return de();case"rebase":return Q();case"resetSoft":return Z("soft");case"resetMixed":return Z("mixed");case"resetHard":return Z("hard",!0)}},de=async()=>{if(x){v("merge");try{const d=await $n(x,{branch:i.hash});d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"merge"}):y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},Q=async()=>{if(x){v("rebase");try{const d=await _n(x,{onto:i.hash});d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"rebase"}):y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},te=l.useCallback(async d=>{const F=d.path;if(!x){k(L=>new Map(L).set(F,"error"));return}k(L=>fr(new Map(L).set(F,"loading")));try{const L=Tn(x,i.hash,d.path,!1),q=new Promise((se,G)=>{setTimeout(()=>G(new Error(`Timed out after ${dr}ms`)),dr)}),ie=await Promise.race([L,q]);k(se=>fr(new Map(se).set(F,ie)))}catch{k(L=>new Map(L).set(F,"error"))}},[x,i.hash]),u=l.useCallback(async d=>{const F=d.path;if(d.changeType==="R"||d.isBinary){H(se=>{const G=new Set(se);return G.has(F)?G.delete(F):G.add(F),G});return}const L=A.get(F);if(g.has(F)&&L&&L!=="error"){H(se=>{const G=new Set(se);return G.delete(F),G});return}H(se=>{const G=new Set(se);return G.add(F),G}),!(L&&L!=="error"||d.insertions+d.deletions>ur&&!M.has(F))&&await te(d)},[A,M,te,g]);return t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:h,className:Ve("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",D?"hover:bg-[var(--interactive-hover)]/40":j?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[D&&n&&r!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(Ua,{laned:n,totalLanes:r,isExpanded:j})}):t.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),t.jsxs("div",{className:"min-w-0 flex-1",children:[D?(()=>{const d=Ya(i.refs);return d.length>0?t.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:d.map(F=>t.jsx("span",{className:Ve("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",F.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":F.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:F.label},F.label))}):null})():null,t.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:i.message}),t.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[t.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[t.jsx("span",{className:"truncate min-w-[3ch]",title:i.author_name,children:i.author_name}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("span",{className:"truncate min-w-0",title:pr(i.date,I),children:pr(i.date,I)})]}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("code",{className:"shrink-0 font-mono",children:i.hash.slice(0,8)}),t.jsxs(Qt,{children:[t.jsx(Xt,{asChild:!0,children:t.jsx(W,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:d=>{d.stopPropagation(),m(i.hash)},children:t.jsx(T,{name:"file-copy",className:"size-3"})})}),t.jsx(Zt,{sideOffset:8,children:C("gitView.history.copySha")})]})]})]})]}),j&&t.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[D&&V?t.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:C(`gitView.history.actions.${V}Confirm`)}),t.jsxs(W,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:O!==null,onClick:d=>{d.stopPropagation(),oe()},children:[O!==null?t.jsx(T,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,C("gitView.history.actions.confirmButton")]}),t.jsx(W,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:O!==null,onClick:d=>{d.stopPropagation(),P(null)},children:C("gitView.history.actions.cancelButton")})]}):D?t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("checkout")},children:C("gitView.history.actions.checkout")}),w?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{autoFocus:!0,value:S,onChange:d=>R(d.target.value),onKeyDown:d=>{d.key==="Enter"&&_(),d.key==="Escape"&&(B(!1),R(""))},placeholder:C("gitView.history.actions.createBranchPlaceholder"),className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),t.jsxs(W,{variant:"outline",size:"xs",className:"h-6",disabled:!S.trim()||O!==null,onClick:d=>{d.stopPropagation(),_()},children:[O==="createBranch"?t.jsx(T,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,C("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(W,{variant:"outline",size:"xs",className:"h-6",onClick:d=>{d.stopPropagation(),B(!0)},children:C("gitView.history.actions.createBranch")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("cherryPick")},children:C("gitView.history.actions.cherryPick")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("revert")},children:C("gitView.history.actions.revert")}),t.jsxs(Ps,{children:[t.jsx(Fs,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>d.stopPropagation(),children:[O==="reset"?t.jsx(T,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,C("gitView.history.actions.reset")]})}),t.jsx(Rs,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(d=>t.jsx(An,{disabled:O!==null,onSelect:F=>{F.stopPropagation(),P(`reset${d.charAt(0).toUpperCase()+d.slice(1)}`)},children:C(`gitView.history.actions.reset${d.charAt(0).toUpperCase()+d.slice(1)}`)},d))})]}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("merge")},children:C("gitView.history.actions.merge")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("rebase")},children:C("gitView.history.actions.rebase")})]}):null,f?t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:C("gitView.history.loadingFiles")})]}):p.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:C("gitView.history.noFiles")}):t.jsx("ul",{className:"space-y-0.5 py-2",children:p.map(d=>t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:()=>u(d),className:Ve("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",g.has(d.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[t.jsx("span",{className:Ve("font-semibold w-3 text-center shrink-0",qa(d.changeType)),children:d.changeType}),t.jsx("span",{className:"truncate text-foreground min-w-0",title:d.path,children:d.path}),!d.isBinary&&t.jsxs("span",{className:"shrink-0",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",d.insertions]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",d.deletions]})]}),d.isBinary&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:C("gitView.history.binary")}),t.jsx(T,{name:g.has(d.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),g.has(d.path)&&t.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:d.changeType==="R"?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.renamedNoDiff")}):d.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.binaryNoDiff")}):(()=>{const F=d.insertions+d.deletions;if(!M.has(d.path)&&F>ur)return t.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:C("gitView.history.largeDiffTitle",{count:F})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:C("gitView.history.largeDiffDescription")}),t.jsx(W,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{U(q=>new Set(q).add(d.path)),te(d)},children:C("gitView.history.renderDiffAnyway")})]});const L=A.get(d.path);return L==="loading"||L===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.loadingDiff")}):L==="error"?t.jsx("button",{type:"button",onClick:()=>u(d),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:C("gitView.history.diffError")}):t.jsx(Da,{original:L.original,modified:L.modified,language:Ln(d.path)||"",fileName:d.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},d.path))})]})]})}),xr=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--syntax-keyword)","var(--syntax-string)","var(--status-info)"];function Ut(i){return xr[i%xr.length]}function Xa(i){if(i.length===0)return[];const e=[],n=[];for(let r=0;r<i.length;r++){const j=i[r],h=[];for(let I=0;I<e.length;I++)e[I]===j.hash&&h.push(I);let p=h.length>0?h[0]:-1;if(p===-1){const I=e.indexOf(null);I!==-1?p=I:(p=e.length,e.push(null))}const f=h.slice(1),m=Ut(p),x=e[p]===j.hash,E=j.parents.length>0;E?e[p]=j.parents[0]:e[p]=null;const y=[];for(let I=1;I<j.parents.length;I++){const D=j.parents[I],O=e.indexOf(D);if(O!==-1)y.push(O);else{const v=e.indexOf(null),w=v!==-1?v:e.length;e[w]=D,w===e.length&&e.push(D),y.push(w)}}const C=[];x&&E?C.push({fromLane:p,toLane:p,color:m,type:"commit-lane"}):x&&!E?C.push({fromLane:p,toLane:p,color:m,type:"top-stub"}):!x&&E&&C.push({fromLane:p,toLane:p,color:m,type:"bottom-stub"});for(const I of f)C.push({fromLane:I,toLane:p,color:Ut(I),type:"merge-in"}),e[I]=null;for(const I of y)C.push({fromLane:p,toLane:I,color:Ut(I),type:"branch-out"});for(let I=0;I<e.length;I++)e[I]!==null&&I!==p&&(y.includes(I)||C.push({fromLane:I,toLane:I,color:Ut(I),type:"passing"}));n.push({commit:j,lane:p,color:m,connectors:C})}return n}const Za=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],ei=i=>{const e=Ct.c(84),{mode:n,log:r,isLogLoading:j,logMaxCount:h,onLogMaxCountChange:p,expandedCommitHashes:f,onToggleCommit:m,commitFilesMap:x,loadingCommitHashes:E,onCopyHash:y,directory:C,showHeader:I,contentMaxHeightClassName:D,branchDivider:O,onConflict:v,onActionSuccess:w}=i,B=n===void 0?"history":n,S=I===void 0?!0:I,R=D===void 0?"max-h-[50vh]":D,V=O===void 0?null:O,{t:P}=et(),[g,H]=l.useState(!0),A=B==="graph";let k;e[0]!==A||e[1]!==r?(k=A&&r?Xa(r.all):[],e[0]=A,e[1]=r,e[2]=k):k=e[2];const M=k;let U;e[3]!==M?(U=Math.max(1,...M.map(ti)),e[3]=M,e[4]=U):U=e[4];const $=U;let _;e[5]!==M?(_=new Map(M.map(si)),e[5]=M,e[6]=_):_=e[6];const Y=_;if(!r)return null;const ee=V!==null&&V.insertBeforeIndex>0&&V.insertBeforeIndex<r.all.length,Z=V!==null&&V.insertBeforeIndex===r.all.length,oe=ee||Z;let de;e[7]!==V||e[8]!==ee||e[9]!==Z||e[10]!==r.all?(de=ee?r.all.slice(0,V.insertBeforeIndex):Z?r.all:[],e[7]=V,e[8]=ee,e[9]=Z,e[10]=r.all,e[11]=de):de=e[11];const Q=de;let te;if(e[12]!==V||e[13]!==x||e[14]!==R||e[15]!==C||e[16]!==f||e[17]!==ee||e[18]!==oe||e[19]!==A||e[20]!==j||e[21]!==Y||e[22]!==E||e[23]!==r.all||e[24]!==h||e[25]!==$||e[26]!==B||e[27]!==w||e[28]!==v||e[29]!==y||e[30]!==p||e[31]!==m||e[32]!==P||e[33]!==Q){const re=ee?r.all.slice(V.insertBeforeIndex):[];let le;e[35]!==V?.direction?(le=V?.direction==="down"?t.jsx(T,{name:"arrow-down-s",className:"size-3.5"}):t.jsx(T,{name:"arrow-up",className:"size-3.5"}),e[35]=V?.direction,e[36]=le):le=e[36];const je=le;let pe;e[37]!==x||e[38]!==C||e[39]!==f||e[40]!==A||e[41]!==Y||e[42]!==E||e[43]!==$||e[44]!==B||e[45]!==w||e[46]!==v||e[47]!==y||e[48]!==m?(pe=ge=>t.jsx("ul",{className:"divide-y divide-border/60",children:ge.map(ce=>t.jsx(Qa,{entry:ce,mode:B,laned:A?Y.get(ce.hash):void 0,totalLanes:A?$:void 0,isExpanded:f.has(ce.hash),onToggle:()=>m(ce.hash),files:x.get(ce.hash)??[],isLoadingFiles:E.has(ce.hash),onCopyHash:y,directory:C,onConflict:v,onActionSuccess:w},ce.hash))}),e[37]=x,e[38]=C,e[39]=f,e[40]=A,e[41]=Y,e[42]=E,e[43]=$,e[44]=B,e[45]=w,e[46]=v,e[47]=y,e[48]=m,e[49]=pe):pe=e[49];const ue=pe;let me;e[50]!==j||e[51]!==r.all.length||e[52]!==h||e[53]!==p||e[54]!==P?(me=r.all.length>=h?t.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:t.jsx(W,{type:"button",variant:"ghost",size:"xs",onClick:()=>p(h+25),disabled:j,className:"px-3 text-muted-foreground hover:text-foreground",children:j?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(T,{name:"loader-4",className:"size-3 animate-spin"}),P("gitView.history.loadingMore")]}):P("gitView.history.loadMore")})}):null,e[50]=j,e[51]=r.all.length,e[52]=h,e[53]=p,e[54]=P,e[55]=me):me=e[55];const he=me;te=t.jsx(jr,{outerClassName:`min-h-0 ${R}`,className:"h-full w-full",children:r.all.length===0?t.jsx("div",{className:"flex h-full items-center justify-center p-4",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:P("gitView.history.noCommits")})}):oe&&V?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col gap-0",children:[Q.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ue(Q)}):null,t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[t.jsx("span",{className:"h-px flex-1 bg-border/60"}),t.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[t.jsx("span",{className:"truncate",title:V.branchName,children:V.branchName}),je]}),t.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),re.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ue(re)}):null]}),he]}):t.jsxs(t.Fragment,{children:[ue(r.all),he]})}),e[12]=V,e[13]=x,e[14]=R,e[15]=C,e[16]=f,e[17]=ee,e[18]=oe,e[19]=A,e[20]=j,e[21]=Y,e[22]=E,e[23]=r.all,e[24]=h,e[25]=$,e[26]=B,e[27]=w,e[28]=v,e[29]=y,e[30]=p,e[31]=m,e[32]=P,e[33]=Q,e[34]=te}else te=e[34];const u=te;if(!S){if(oe){let le;return e[56]!==u?(le=t.jsx("section",{className:"h-full min-h-0",children:u}),e[56]=u,e[57]=le):le=e[57],le}let re;return e[58]!==u?(re=t.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:u}),e[58]=u,e[59]=re):re=e[59],re}let d;e[60]!==P?(d=P("gitView.history.title"),e[60]=P,e[61]=d):d=e[61];let F;e[62]!==d?(F=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:d}),e[62]=d,e[63]=F):F=e[63];let L;e[64]!==j||e[65]!==g||e[66]!==h||e[67]!==p||e[68]!==P?(L=g&&t.jsx("div",{onClick:ri,onPointerDown:ni,children:t.jsxs(Kn,{value:String(h),onValueChange:re=>p(Number(re)),disabled:j,children:[t.jsx(Jn,{size:"sm",className:"w-auto",disabled:j,children:t.jsx(qn,{placeholder:P("gitView.history.commitsPlaceholder")})}),t.jsx(Yn,{children:Za.map(re=>t.jsx(Qn,{value:String(re.value),children:P(re.labelKey)},re.value))})]})}),e[64]=j,e[65]=g,e[66]=h,e[67]=p,e[68]=P,e[69]=L):L=e[69];let q;e[70]!==g?(q=g?t.jsx(T,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):t.jsx(T,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=g,e[71]=q):q=e[71];let ie;e[72]!==L||e[73]!==q?(ie=t.jsxs("div",{className:"flex items-center gap-2",children:[L,q]}),e[72]=L,e[73]=q,e[74]=ie):ie=e[74];let se;e[75]!==F||e[76]!==ie?(se=t.jsxs(Sa,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[F,ie]}),e[75]=F,e[76]=ie,e[77]=se):se=e[77];let G;e[78]!==u?(G=t.jsx(ka,{children:u}),e[78]=u,e[79]=G):G=e[79];let fe;return e[80]!==g||e[81]!==se||e[82]!==G?(fe=t.jsxs(Va,{open:g,onOpenChange:H,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[se,G]}),e[80]=g,e[81]=se,e[82]=G,e[83]=fe):fe=e[83],fe};function ti(i){return i.lane+1}function si(i){return[i.commit.hash,i]}function ri(i){return i.stopPropagation()}function ni(i){return i.stopPropagation()}const ai=i=>{const e=Ct.c(148),{open:n,onOpenChange:r,conflictFiles:j,directory:h,operation:p,onAbort:f,onClearState:m}=i;let x;e[0]!==j?(x=j===void 0?[]:j,e[0]=j,e[1]=x):x=e[1];const E=x,{t:y}=et(),C=Ze(ii),I=Ze(oi),D=Jt(li),O=Jt(ci),[v,w]=l.useState(!1),[B,S]=l.useState(null),[R,V]=l.useState(null);let P,g;e[2]!==h||e[3]!==n||e[4]!==y?(P=()=>{!n||!h||(w(!0),V(null),S(null),Xn(h).then(J=>{S(J)}).catch(J=>{const xe=J instanceof Error?J.message:y("gitView.conflict.loadFailed");V(xe)}).finally(()=>{w(!1)}))},g=[n,h,y],e[2]=h,e[3]=n,e[4]=y,e[5]=P,e[6]=g):(P=e[5],g=e[6]),l.useEffect(P,g);let H;e[7]!==B||e[8]!==h||e[9]!==p?(H=async()=>{if(!B)return null;const J=p==="merge"?"merge":"rebase",xe=B.headInfo||(p==="merge"?"MERGE_HEAD":"REBASE_HEAD"),Ee=p==="merge"?"git commit --no-edit":"git rebase --continue",Ge=await Kt("git.conflict.resolve.visible",{operation_label:J,head_ref:xe}),Ie=await Kt("git.conflict.resolve.instructions",{operation_label:J,directory:h,operation:p,head_info:B.headInfo||"N/A",continue_cmd:Ee}),Ne=`${J} conflict context (JSON)
3
- ${JSON.stringify({directory:h,operation:B.operation,headInfo:B.headInfo,statusPorcelain:B.statusPorcelain,unmergedFiles:B.unmergedFiles,diff:B.diff},null,2)}`;return{visibleText:Ge,instructionsText:Ie,payloadText:Ne}},e[7]=B,e[8]=h,e[9]=p,e[10]=H):H=e[10];const A=H;let k;e[11]!==f||e[12]!==r?(k=()=>{f(),r(!1)},e[11]=f,e[12]=r,e[13]=k):k=e[13];const M=k;let U;e[14]!==m||e[15]!==r?(U=()=>{m?.(),r(!1)},e[14]=m,e[15]=r,e[16]=U):U=e[16];const $=U;let _;e[17]!==A||e[18]!==I||e[19]!==m||e[20]!==r||e[21]!==D||e[22]!==O||e[23]!==y?(_=async()=>{const J=await A();if(!J){b.error(y("gitView.conflict.noDetailsAvailable"));return}if(!I){b.error(y("gitView.conflict.noActiveSession"),{description:y("gitView.conflict.noActiveSessionDescription")});return}D(J.visibleText,"replace"),O([{text:J.instructionsText,synthetic:!0},{text:J.payloadText,synthetic:!0}]),m?.(),r(!1)},e[17]=A,e[18]=I,e[19]=m,e[20]=r,e[21]=D,e[22]=O,e[23]=y,e[24]=_):_=e[24];const Y=_;let ee;e[25]!==A||e[26]!==h||e[27]!==m||e[28]!==r||e[29]!==C||e[30]!==y?(ee=async()=>{const J=await A();if(!J){b.error(y("gitView.conflict.noDetailsAvailable"));return}C({directoryOverride:h,initialPrompt:J.visibleText,syntheticParts:[{text:J.instructionsText,synthetic:!0},{text:J.payloadText,synthetic:!0}]}),m?.(),r(!1)},e[25]=A,e[26]=h,e[27]=m,e[28]=r,e[29]=C,e[30]=y,e[31]=ee):ee=e[31];const Z=ee;let oe,de,Q,te,u,d,F,L,q,ie,se,G,fe,re,le,je,pe,ue,me,he,ge,ce;if(e[32]!==B||e[33]!==E||e[34]!==I||e[35]!==M||e[36]!==$||e[37]!==Y||e[38]!==Z||e[39]!==v||e[40]!==R||e[41]!==r||e[42]!==n||e[43]!==p||e[44]!==y){const J=y(p==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),xe=B?.unmergedFiles||E;Q=ht,ge=n,ce=r,de=gt,he="max-w-md w-[calc(100vw-2rem)]",re="flex flex-col gap-4 overflow-hidden";let Ee;e[67]===Symbol.for("react.memo_cache_sentinel")?(Ee=t.jsx(T,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[67]=Ee):Ee=e[67];const Ge=t.jsxs("div",{className:"flex items-center gap-2",children:[Ee,t.jsx(pt,{children:y("gitView.conflict.detectedTitle",{operation:J})})]});let Ie;e[68]!==p||e[69]!==y?(Ie=y("gitView.conflict.detectedDescription",{operation:p}),e[68]=p,e[69]=y,e[70]=Ie):Ie=e[70];let Ne;e[71]!==Ie?(Ne=t.jsx(yt,{children:Ie}),e[71]=Ie,e[72]=Ne):Ne=e[72],e[73]!==Ge||e[74]!==Ne?(le=t.jsxs(ft,{children:[Ge,Ne]}),e[73]=Ge,e[74]=Ne,e[75]=le):le=e[75],e[76]!==v||e[77]!==y?(je=v&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:y("gitView.conflict.loading")})]}),e[76]=v,e[77]=y,e[78]=je):je=e[78],e[79]!==R||e[80]!==y?(pe=R&&t.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:y("gitView.conflict.errorLoadingDetails",{message:R})}),e[79]=R,e[80]=y,e[81]=pe):pe=e[81],e[82]!==xe||e[83]!==y?(ue=xe.length>0&&t.jsxs("div",{className:"space-y-2 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:y("gitView.conflict.conflictedFiles")}),t.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:xe.length})]}),t.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:t.jsx("ul",{className:"space-y-1",children:xe.map(di)})})]}),e[82]=xe,e[83]=y,e[84]=ue):ue=e[84],e[85]!==B||e[86]!==y?(me=B?.headInfo&&t.jsxs("div",{className:"space-y-1 overflow-hidden",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:y("gitView.conflict.headInfo")}),t.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:B.headInfo})]}),e[85]=B,e[86]=y,e[87]=me):me=e[87],se="flex flex-col gap-2 pt-2";let Se;e[88]!==Z?(Se=()=>{Z()},e[88]=Z,e[89]=Se):Se=e[89];const Be=v||!B;let Pe;e[90]!==v?(Pe=v?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"add",className:"size-4"}),e[90]=v,e[91]=Pe):Pe=e[91];let ke;e[92]!==y?(ke=y("gitView.conflict.resolveNewSession"),e[92]=y,e[93]=ke):ke=e[93],e[94]!==Se||e[95]!==Be||e[96]!==Pe||e[97]!==ke?(G=t.jsxs(W,{variant:"default",onClick:Se,disabled:Be,className:"w-full gap-2",children:[Pe,ke]}),e[94]=Se,e[95]=Be,e[96]=Pe,e[97]=ke,e[98]=G):G=e[98];let we;e[99]!==Y?(we=()=>{Y()},e[99]=Y,e[100]=we):we=e[100];const De=v||!B||!I;let Ae;e[101]!==v?(Ae=v?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"chat-1",className:"size-4"}),e[101]=v,e[102]=Ae):Ae=e[102];let X;e[103]!==y?(X=y("gitView.conflict.resolveCurrentSession"),e[103]=y,e[104]=X):X=e[104],e[105]!==we||e[106]!==De||e[107]!==Ae||e[108]!==X?(fe=t.jsxs(W,{variant:"outline",onClick:we,disabled:De,className:"w-full gap-2",children:[Ae,X]}),e[105]=we,e[106]=De,e[107]=Ae,e[108]=X,e[109]=fe):fe=e[109],q="flex gap-2 pt-1";let Fe;e[110]!==y?(Fe=y("gitView.conflict.continueLater"),e[110]=y,e[111]=Fe):Fe=e[111],e[112]!==$||e[113]!==Fe?(ie=t.jsx(W,{variant:"ghost",size:"sm",onClick:$,className:"flex-1",children:Fe}),e[112]=$,e[113]=Fe,e[114]=ie):ie=e[114],oe=W,te="destructive",u="sm",d=M,F="flex-1",L=y("gitView.conflict.abortOperation",{operation:J}),e[32]=B,e[33]=E,e[34]=I,e[35]=M,e[36]=$,e[37]=Y,e[38]=Z,e[39]=v,e[40]=R,e[41]=r,e[42]=n,e[43]=p,e[44]=y,e[45]=oe,e[46]=de,e[47]=Q,e[48]=te,e[49]=u,e[50]=d,e[51]=F,e[52]=L,e[53]=q,e[54]=ie,e[55]=se,e[56]=G,e[57]=fe,e[58]=re,e[59]=le,e[60]=je,e[61]=pe,e[62]=ue,e[63]=me,e[64]=he,e[65]=ge,e[66]=ce}else oe=e[45],de=e[46],Q=e[47],te=e[48],u=e[49],d=e[50],F=e[51],L=e[52],q=e[53],ie=e[54],se=e[55],G=e[56],fe=e[57],re=e[58],le=e[59],je=e[60],pe=e[61],ue=e[62],me=e[63],he=e[64],ge=e[65],ce=e[66];let ze;e[115]!==oe||e[116]!==te||e[117]!==u||e[118]!==d||e[119]!==F||e[120]!==L?(ze=t.jsx(oe,{variant:te,size:u,onClick:d,className:F,children:L}),e[115]=oe,e[116]=te,e[117]=u,e[118]=d,e[119]=F,e[120]=L,e[121]=ze):ze=e[121];let $e;e[122]!==q||e[123]!==ie||e[124]!==ze?($e=t.jsxs("div",{className:q,children:[ie,ze]}),e[122]=q,e[123]=ie,e[124]=ze,e[125]=$e):$e=e[125];let ve;e[126]!==se||e[127]!==G||e[128]!==fe||e[129]!==$e?(ve=t.jsxs("div",{className:se,children:[G,fe,$e]}),e[126]=se,e[127]=G,e[128]=fe,e[129]=$e,e[130]=ve):ve=e[130];let Re;e[131]!==re||e[132]!==le||e[133]!==je||e[134]!==pe||e[135]!==ue||e[136]!==me||e[137]!==ve?(Re=t.jsxs("div",{className:re,children:[le,je,pe,ue,me,ve]}),e[131]=re,e[132]=le,e[133]=je,e[134]=pe,e[135]=ue,e[136]=me,e[137]=ve,e[138]=Re):Re=e[138];let Ce;e[139]!==de||e[140]!==he||e[141]!==Re?(Ce=t.jsx(de,{className:he,children:Re}),e[139]=de,e[140]=he,e[141]=Re,e[142]=Ce):Ce=e[142];let Te;return e[143]!==Q||e[144]!==ge||e[145]!==ce||e[146]!==Ce?(Te=t.jsx(Q,{open:ge,onOpenChange:ce,children:Ce}),e[143]=Q,e[144]=ge,e[145]=ce,e[146]=Ce,e[147]=Te):Te=e[147],Te};function ii(i){return i.openNewSessionDraft}function oi(i){return i.currentSessionId}function li(i){return i.setPendingInputText}function ci(i){return i.setPendingSyntheticParts}function di(i){return t.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:i,children:i},i)}const ui=({open:i,onOpenChange:e,operation:n,targetBranch:r,onConfirm:j})=>{const{t:h}=et(),[p,f]=l.useState(!0),[m,x]=l.useState(!1),E=h(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),y=async()=>{x(!0);try{await j(p),e(!1)}catch(I){const D=I instanceof Error?I.message:`Failed to ${n}`;b.error(D)}finally{x(!1)}},C=()=>{m||e(!1)};return t.jsx(ht,{open:i,onOpenChange:m?void 0:e,children:t.jsxs(gt,{className:"max-w-md",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),t.jsx(pt,{children:h("gitView.stash.title")})]}),t.jsx(yt,{children:h("gitView.stash.description",{operation:n})})]}),t.jsxs("div",{className:"py-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:h("gitView.stash.thisWill")}),t.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[t.jsx("li",{children:h("gitView.stash.stepStash")}),t.jsxs("li",{children:[h(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",h(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",t.jsx("span",{className:"font-mono text-primary",children:r})]}),p&&t.jsx("li",{children:h("gitView.stash.stepRestore")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(Zn,{checked:p,onChange:f,disabled:m,ariaLabel:h("gitView.stash.restoreAria")}),t.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!m&&f(!p),children:h("gitView.stash.restoreAfterOperation",{operation:n})})]}),t.jsxs(Is,{className:"gap-2",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:C,disabled:m,children:h("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:y,disabled:m,className:"gap-1.5",children:m?t.jsxs(t.Fragment,{children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),h("gitView.common.processing")]}):h("gitView.stash.confirmButton",{operation:E})})]})]})})},mi=({mergeInProgress:i,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:j,conflictCount:h=0,isLoading:p=!1})=>{const{t:f}=et(),[m,x]=l.useState(null),E=i&&i.head,y=e&&(e.headName||e.onto),C=E?"merge":y?"rebase":null;if(!C)return null;const I=async()=>{x("continue");try{await n()}finally{x(null)}},D=async()=>{x("abort");try{await r()}finally{x(null)}},O=m!==null,v=h>0,w=f(C==="merge"?"gitView.operation.merge":"gitView.operation.rebase");let B="";i?B=i.message?f("gitView.operation.mergingMessage",{message:i.message}):f("gitView.operation.mergeInProgressWithHead",{head:i.head}):e&&(B=e.headName?f("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):f("gitView.operation.rebaseInProgress"));const S=v?h===1?f("gitView.operation.inProgressTitleOneConflict",{operation:w,count:h}):f("gitView.operation.inProgressTitleManyConflicts",{operation:w,count:h}):f("gitView.operation.inProgressTitle",{operation:w}),R=f(v?"gitView.operation.resolveConflictsHint":"gitView.operation.readyToContinueHint");return t.jsx("div",{className:"mx-4 mt-3 overflow-hidden rounded-lg border border-[var(--status-warning-border)]",children:t.jsxs("div",{className:"flex flex-col gap-3 p-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:S}),B&&t.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:B})]}),t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("p",{className:"typography-micro min-w-0 flex-1 text-muted-foreground",children:R}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[t.jsxs(W,{variant:"ghost",size:"sm",onClick:D,disabled:O||p,className:"gap-1.5",children:[m==="abort"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"close",className:"size-4"}),f("gitView.operation.abort")]}),v?j&&t.jsx(W,{variant:"default",size:"sm",onClick:j,disabled:O||p,children:f("gitView.operation.resolveWithAi")}):t.jsxs(W,{variant:"default",size:"sm",onClick:I,disabled:O||p,className:"gap-1.5",children:[m==="continue"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"check",className:"size-4"}),f("gitView.operation.continue")]})]})]})]})})},hi=i=>{const e=Ct.c(104),{currentBranch:n,localBranches:r,remoteBranches:j,onMerge:h,onRebase:p,disabled:f,isOperating:m,operationLogs:x,onOperationComplete:E,mode:y,defaultTargetBranch:C}=i,I=f===void 0?!1:f,D=m===void 0?!1:m,O=x===void 0?[]:x,v=y===void 0?"dialog":y,{t:w}=et(),[B,S]=l.useState(!1),[R,V]=l.useState("merge"),[P,g]=l.useState(null),[H,A]=l.useState(!1),[k,M]=l.useState(""),U=l.useRef(null),$=l.useRef(null),_=I||D,Y=n||w("gitView.branch.currentBranchFallback"),ee=O.length>0&&O.every(gi),Z=O.some(fi);let oe;e[0]===Symbol.for("react.memo_cache_sentinel")?(oe=()=>{$.current&&($.current.scrollTop=$.current.scrollHeight)},e[0]=oe):oe=e[0],l.useEffect(oe,[O]);let de;e[1]!==j?(de=new Set(j.map(pi).filter(Boolean)),e[1]=j,e[2]=de):de=e[2];const Q=de;let te;if(e[3]!==k||e[4]!==n||e[5]!==r||e[6]!==Q){let X;e[8]!==n||e[9]!==Q?(X=_e=>_e!==n&&!Q.has(_e),e[8]=n,e[9]=Q,e[10]=X):X=e[10];const Fe=r.filter(X);te=Rt(Fe,k,xi),e[3]=k,e[4]=n,e[5]=r,e[6]=Q,e[7]=te}else te=e[7];const u=te;let d;e[11]!==k||e[12]!==j?(d=Rt(j,k,wi),e[11]=k,e[12]=j,e[13]=d):d=e[13];const F=d;let L;e[14]!==C||e[15]!==r||e[16]!==j?(L=()=>C&&(j.includes(C)||r.includes(C))?C:null,e[14]=C,e[15]=r,e[16]=j,e[17]=L):L=e[17];const q=L;let ie;e[18]!==q||e[19]!==S?(ie=()=>{S(!0),g(q()),V("merge"),M("")},e[18]=q,e[19]=S,e[20]=ie):ie=e[20];const se=ie;let G;e[21]===Symbol.for("react.memo_cache_sentinel")?(G=X=>{g(X),A(!1),M("")},e[21]=G):G=e[21];const fe=G;let re;e[22]!==h||e[23]!==p||e[24]!==R||e[25]!==P?(re=()=>{P&&(R==="merge"?h(P):p(P))},e[22]=h,e[23]=p,e[24]=R,e[25]=P,e[26]=re):re=e[26];const le=re;let je;e[27]!==D||e[28]!==S?(je=()=>{D||(g(null),V("merge"),M(""),S(!1))},e[27]=D,e[28]=S,e[29]=je):je=e[29];const pe=je,ue=()=>{D&&!ee||(ee&&E?.(),g(null),V("merge"),M(""),S(!1))};let me,he;e[30]!==H?(me=()=>{H||M("")},he=[H],e[30]=H,e[31]=me,e[32]=he):(me=e[31],he=e[32]),l.useEffect(me,he);let ge,ce;e[33]!==v||e[34]!==q||e[35]!==P?(ge=()=>{v==="dialog"||P||g(q())},ce=[v,q,P],e[33]=v,e[34]=q,e[35]=P,e[36]=ge,e[37]=ce):(ge=e[36],ce=e[37]),l.useEffect(ge,ce);const ve=D?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{ref:$,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:t.jsx("div",{className:"space-y-2",children:O.map(yi)})}),ee?v==="dialog"?t.jsx(Is,{children:t.jsx(W,{variant:"default",size:"sm",onClick:ue,children:w(Z?"gitView.common.close":"gitView.common.done")})}):t.jsx("div",{className:"flex justify-end",children:t.jsx(W,{variant:"default",size:"sm",onClick:ue,children:w(Z?"gitView.common.close":"gitView.common.done")})}):null]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:w("gitView.branch.operation")}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>V("merge"),className:Ve("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",R==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"git-merge",className:Ve("size-4",R==="merge"?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Ve("typography-ui-label",R==="merge"?"text-foreground":"text-muted-foreground"),children:w("gitView.operation.merge")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:w("gitView.branch.mergeDescription")})]}),t.jsxs("button",{type:"button",onClick:()=>V("rebase"),className:Ve("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",R==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"git-branch",className:Ve("size-4",R==="rebase"?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Ve("typography-ui-label",R==="rebase"?"text-foreground":"text-muted-foreground"),children:w("gitView.operation.rebase")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:w("gitView.branch.rebaseDescription")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:R==="merge"?w("gitView.branch.branchToMergeInto",{branch:Y}):w("gitView.branch.branchToRebaseOnto")}),t.jsxs(Ps,{open:H,onOpenChange:A,modal:!1,children:[t.jsx(Fs,{asChild:!0,children:t.jsxs("button",{type:"button",className:Ve(br({size:"default"}),"w-full"),children:[t.jsx("span",{className:Ve("truncate",!P&&"text-muted-foreground"),children:P||w("gitView.branch.selectBranch")}),t.jsx(T,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),t.jsx(Rs,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:t.jsxs(Bs,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(Ds,{ref:U,placeholder:w("gitView.branch.searchPlaceholder"),value:k,onValueChange:M,onKeyDown:bi}),t.jsxs(Ms,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(Es,{children:w("gitView.branch.empty")}),u.length>0&&t.jsx(qt,{heading:w("gitView.branch.localBranches"),children:u.map(X=>t.jsx(Yt,{onSelect:()=>fe(X),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:X})},`local-${X}`))}),u.length>0&&F.length>0?t.jsx(ea,{}):null,F.length>0&&t.jsx(qt,{heading:w("gitView.branch.remoteBranches"),children:F.map(X=>t.jsx(Yt,{onSelect:()=>fe(X),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:X})},`remote-${X}`))})]})]})})]})]}),P?t.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:R==="merge"?t.jsxs(t.Fragment,{children:[w("gitView.branch.summaryMergePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P})," ",w("gitView.branch.summaryMergeInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Y})]}):t.jsxs(t.Fragment,{children:[w("gitView.branch.summaryRebasePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Y})," ",w("gitView.branch.summaryRebaseInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P})]})})}):null,v==="dialog"?t.jsxs(Is,{className:"gap-2 pt-1",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:pe,children:w("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:le,disabled:!P,className:"gap-1.5",children:R==="merge"?t.jsxs(t.Fragment,{children:[t.jsx(T,{name:"git-merge",className:"size-4"}),w("gitView.operation.merge")]}):t.jsxs(t.Fragment,{children:[t.jsx(T,{name:"git-branch",className:"size-4"}),w("gitView.operation.rebase")]})})]}):t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(W,{variant:"destructive",size:"sm",onClick:pe,disabled:_,children:w("gitView.common.reset")}),t.jsx("div",{className:"flex-1"}),t.jsx(W,{variant:"default",size:"sm",onClick:le,disabled:_||!P,children:w(R==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(v==="bare")return ve;if(v==="inline"){let X;e[38]!==w?(X=w("gitView.branch.updateTitle"),e[38]=w,e[39]=X):X=e[39];let Fe;e[40]!==X?(Fe=t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:X}),e[40]=X,e[41]=Fe):Fe=e[41];let _e;e[42]!==w?(_e=w("gitView.branch.updateDescriptionPrefix"),e[42]=w,e[43]=_e):_e=e[43];let tt;e[44]!==Y?(tt=t.jsx("span",{className:"font-mono text-foreground",children:Y}),e[44]=Y,e[45]=tt):tt=e[45];let st;e[46]!==_e||e[47]!==tt?(st=t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[_e," ",tt,"."]}),e[46]=_e,e[47]=tt,e[48]=st):st=e[48];let Ke;e[49]!==Fe||e[50]!==st?(Ke=t.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:t.jsxs("div",{className:"space-y-1",children:[Fe,st]})}),e[49]=Fe,e[50]=st,e[51]=Ke):Ke=e[51];let at;e[52]!==ve?(at=t.jsx("div",{className:"pt-3",children:ve}),e[52]=ve,e[53]=at):at=e[53];let it;return e[54]!==Ke||e[55]!==at?(it=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Ke,at]}),e[54]=Ke,e[55]=at,e[56]=it):it=e[56],it}let Re;e[57]!==D?(Re=D?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"git-merge",className:"size-4"}),e[57]=D,e[58]=Re):Re=e[58];let Ce;e[59]!==w?(Ce=w("gitView.branch.mergeRebase"),e[59]=w,e[60]=Ce):Ce=e[60];let Te;e[61]!==Ce?(Te=t.jsx("span",{children:Ce}),e[61]=Ce,e[62]=Te):Te=e[62];let J;e[63]!==se||e[64]!==_||e[65]!==Re||e[66]!==Te?(J=t.jsx(Xt,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"sm",className:"gap-1.5",onClick:se,disabled:_,children:[Re,Te]})}),e[63]=se,e[64]=_,e[65]=Re,e[66]=Te,e[67]=J):J=e[67];let xe;e[68]!==w?(xe=w("gitView.branch.mergeRebaseTooltip"),e[68]=w,e[69]=xe):xe=e[69];let Ee;e[70]!==xe?(Ee=t.jsx(Zt,{sideOffset:8,children:xe}),e[70]=xe,e[71]=Ee):Ee=e[71];let Ge;e[72]!==J||e[73]!==Ee?(Ge=t.jsxs(Qt,{children:[J,Ee]}),e[72]=J,e[73]=Ee,e[74]=Ge):Ge=e[74];let Ie;e[75]!==ue||e[76]!==S?(Ie=X=>{X?S(!0):ue()},e[75]=ue,e[76]=S,e[77]=Ie):Ie=e[77];let Ne;e[78]!==w?(Ne=w("gitView.branch.updateTitle"),e[78]=w,e[79]=Ne):Ne=e[79];let Se;e[80]!==Ne?(Se=t.jsx(pt,{children:Ne}),e[80]=Ne,e[81]=Se):Se=e[81];let Be;e[82]!==Z||e[83]!==D||e[84]!==R||e[85]!==ee||e[86]!==w||e[87]!==Y?(Be=D?w(ee?Z?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":R==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):t.jsxs(t.Fragment,{children:[w("gitView.branch.dialogDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Y}),"."]}),e[82]=Z,e[83]=D,e[84]=R,e[85]=ee,e[86]=w,e[87]=Y,e[88]=Be):Be=e[88];let Pe;e[89]!==Be?(Pe=t.jsx(yt,{children:Be}),e[89]=Be,e[90]=Pe):Pe=e[90];let ke;e[91]!==Se||e[92]!==Pe?(ke=t.jsxs(ft,{children:[Se,Pe]}),e[91]=Se,e[92]=Pe,e[93]=ke):ke=e[93];let we;e[94]!==ve||e[95]!==ke?(we=t.jsxs(gt,{className:"max-w-md",children:[ke,ve]}),e[94]=ve,e[95]=ke,e[96]=we):we=e[96];let De;e[97]!==B||e[98]!==Ie||e[99]!==we?(De=t.jsx(ht,{open:B,onOpenChange:Ie,children:we}),e[97]=B,e[98]=Ie,e[99]=we,e[100]=De):De=e[100];let Ae;return e[101]!==Ge||e[102]!==De?(Ae=t.jsxs(t.Fragment,{children:[Ge,De]}),e[101]=Ge,e[102]=De,e[103]=Ae):Ae=e[103],Ae};function gi(i){return i.status==="done"||i.status==="error"}function fi(i){return i.status==="error"}function pi(i){return i.slice(i.indexOf("/")+1)}function xi(i){return[i]}function wi(i){return[i]}function yi(i,e){return t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("div",{className:"mt-0.5 shrink-0",children:[i.status==="running"&&t.jsx(T,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),i.status==="done"&&t.jsx(T,{name:"check",className:"size-3.5 text-success"}),i.status==="error"&&t.jsx(T,{name:"close",className:"size-3.5 text-destructive"}),i.status==="pending"&&t.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),t.jsx("span",{className:Ve("typography-micro",i.status==="error"&&"text-destructive",i.status==="done"&&"text-muted-foreground",i.status==="running"&&"text-foreground",i.status==="pending"&&"text-muted-foreground/60"),children:i.message})]},e)}function bi(i){return i.stopPropagation()}const ji=({runMutation:i,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:j})=>{const h=[];let p=!1;return{enqueue:m=>{const x=h[h.length-1];if(x?.directory===m.directory&&x.direction===m.direction){m.paths.forEach(E=>x.paths.add(E));return}h.push(m)},flush:()=>{if(p)return;const m=h.shift();if(!m)return;p=!0;const x={directory:m.directory,direction:m.direction,paths:Array.from(m.paths),rollback:m.rollback};(async()=>{try{await i(x),e(x)}catch(E){n(x,E)}finally{r(x.paths),p=!1,h.length>0&&j()}})()},clear:()=>{h.length=0},size:()=>h.length,isRunning:()=>p}},vi=15e3,Ci=40,Ni=20,wr={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Si=(i,e)=>{const n=i.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,j=n.match(r);if(j){const f=j[1],m=wr[f];if(m)return e.find(x=>x.code===m)||null}const h=n.split(" ")[0],p=wr[h];return p&&e.find(f=>f.code===p)||null},ki=20,vt=new Map,Vi=(i,e)=>{if(vt.delete(i),vt.set(i,e),vt.size>ki){const n=vt.keys().next().value;n!==void 0&&vt.delete(n)}},nt=i=>(i||"").replace(/\\/g,"/").replace(/\/+$/,""),yr=i=>{const e=i.index?.trim();return!!(e&&e!=="?")},Ii=i=>{const e=i.working_dir?.trim(),n=i.index?.trim();return!!(e||n==="?")},Wl=({isActive:i})=>{const{t:e}=et(),{git:n}=ta(),r=sa(),[j,h]=l.useState(null),[p,f]=l.useState(!1),m=Ze(s=>s.currentSessionId),x=Ze(s=>s.newSessionDraft),E=Ze(s=>s.setDraftBootstrapPendingDirectory),y=Ze(s=>s.worktreeMetadata),C=Ze(s=>s.availableWorktrees),I=nt(r),D=l.useMemo(()=>{if(!I)return;const s=C.find(a=>nt(a.path)===I);if(s)return s;for(const a of y.values())if(nt(a.path)===I)return a},[C,I,y]),O=l.useMemo(()=>{if(m)return y.get(m)??D;if(x?.open)return D},[m,D,x?.open,y]),{profiles:v,globalIdentity:w,defaultGitIdentityId:B,loadProfiles:S,loadGlobalIdentity:R,loadDefaultGitIdentityId:V}=Ia(or(s=>({profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId}))),P=ra(r??null),g=na(r??null),H=aa(s=>m?s.getAttachment(m):void 0),A=H?ia(H):[],k=H&&!H.degraded&&!H.legacy?H.worktreeRoot??void 0:void 0,M=va(r,O,g?.current??void 0),U=oa(r??null),$=la(r??null),_=ca(r??null),Y=da(r??null),ee=ua(r??null),{setActiveDirectory:Z,fetchAll:oe,ensureAll:de,fetchStatus:Q,fetchBranches:te,fetchLog:u,setLogMaxCount:d,fetchIdentity:F,prefetchDiffs:L,clearDiffCache:q,moveStatusPathsOptimistically:ie,restoreStatus:se,bumpIndexRevision:G}=ma(or(s=>({setActiveDirectory:s.setActiveDirectory,fetchAll:s.fetchAll,ensureAll:s.ensureAll,fetchStatus:s.fetchStatus,fetchBranches:s.fetchBranches,fetchLog:s.fetchLog,setLogMaxCount:s.setLogMaxCount,fetchIdentity:s.fetchIdentity,prefetchDiffs:s.prefetchDiffs,clearDiffCache:s.clearDiffCache,moveStatusPathsOptimistically:s.moveStatusPathsOptimistically,restoreStatus:s.restoreStatus,bumpIndexRevision:s.bumpIndexRevision}))),fe=Pt(s=>s.isMobile),re=Pt(s=>s.openContextDiff),le=Pt(s=>s.openContextSurface),je=g?.current??null,pe=ha(s=>!r||!je?null:ga(s.entries,r,je)),ue=Pt(s=>s.navigateToDiff),me=l.useRef(null),he=l.useRef(null),ge=l.useRef(null),ce=l.useRef(null),ze=l.useRef(!0);l.useEffect(()=>()=>{ze.current=!1},[]);const $e=l.useCallback(()=>{he.current!==null&&(window.clearTimeout(he.current),he.current=null)},[]),ve=l.useCallback(s=>{$e(),he.current=window.setTimeout(()=>{he.current=null,nt(s)===nt(r)&&Q(s,n,{silent:!0})},vi)},[$e,r,Q,n]);l.useEffect(()=>$e,[$e]);const Re=l.useCallback(()=>{ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null)},[]),Ce=l.useCallback(()=>{ge.current===null&&(ge.current=window.setTimeout(()=>{ge.current=null,ce.current?.()},0))},[]),Te=l.useCallback(async(s,a,o)=>{if(a==="stage"){if(n.stageGitFiles){await n.stageGitFiles(s,o);return}await Promise.all(o.map(c=>n.stageGitFile(s,c)));return}if(n.unstageGitFiles){await n.unstageGitFiles(s,o);return}await Promise.all(o.map(c=>n.unstageGitFile(s,c)))},[n]),J=l.useMemo(()=>ji({runMutation:({directory:s,direction:a,paths:o})=>Te(s,a,o),onMutationComplete:({directory:s})=>{G(s),ve(s)},onMutationError:({directory:s,direction:a,rollback:o},c)=>{o?.(),G(s),ve(s);const N=e(a==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");b.error(c instanceof Error?c.message:N)},onPathsComplete:s=>{zs(a=>{const o=new Set(a);return s.forEach(c=>o.delete(c)),o})},scheduleFlush:Ce}),[G,Te,Ce,ve,e]);l.useEffect(()=>(ce.current=J.flush,()=>{ce.current=null}),[J]),l.useEffect(()=>()=>J.clear(),[J]),l.useEffect(()=>Re,[Re]),l.useEffect(()=>{if(!i)return;if(!r){h(null),f(!1);return}let s=!1,a=null;const o=async()=>{try{const c=await ja(r);if(s)return;h(c.status),c.status==="pending"&&(a=window.setTimeout(()=>{o()},500))}catch{s||h(null)}};return o(),()=>{s=!0,a!==null&&window.clearTimeout(a)}},[i,r]),l.useEffect(()=>{const s=me.current;me.current=j,!(!r||!n)&&(s==="pending"&&j==="ready"&&(f(!0),oe(r,n).finally(()=>{window.setTimeout(()=>{f(!1)},1200)})),j==="failed"&&(E(null),f(!1)))},[r,oe,n,E,j]);const xe=nt(x?.bootstrapPendingDirectory??null),Ee=!!(r&&xe&&xe===nt(r)),Ie=!!(r&&(j==="pending"||Ee))||p,Ne=l.useMemo(()=>r?vt.get(r)??null:null,[r]),Se=fa(s=>s.settingsGitmojiEnabled),[Be,Pe]=l.useState(null),{gitmojis:ke}=Aa(Se);l.useEffect(()=>{const s=k||M?.projectDirectory;if(!s){Pe(null);return}let a=!1;return pa(s).then(o=>{if(a)return;const c=o.trim();Pe(c&&c!=="HEAD"?c:null)}).catch(()=>{a||Pe(null)}),()=>{a=!0}},[k,M?.projectDirectory]);const[we,De]=l.useState(Ne?.commitMessage??""),[Ae,X]=l.useState([]),[Fe,_e]=l.useState(!1),tt=l.useRef(null),[st,Ke]=l.useState(null),[at,it]=l.useState(!1),[Ts,As]=l.useState(null),[Je,Sr]=l.useState(25),[kr,Ls]=l.useState(!1),{triggerFireworks:Vr}=Ca(),Os=l.useRef(new Map),Bt=l.useRef(0),es=l.useCallback(()=>{Bt.current+=1,ze.current&&Ls(!0)},[]),ts=l.useCallback(()=>{Bt.current=Math.max(0,Bt.current-1),ze.current&&Bt.current===0&&Ls(!1)},[]),[ss,Dt]=l.useState(new Set),[Ir,zs]=l.useState(new Set),[rs,Gs]=l.useState(!1),[Pr,Fr]=l.useState(0),[Rr,_s]=l.useState(!1),[ns,$s]=l.useState(Ne?.generatedHighlights??[]),Br=Ir.size>0||J.size()>0||J.isRunning(),Hs=l.useCallback(()=>{const s=tt.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),as=k||M?.projectDirectory||null,is=g?.current||null,Dr=l.useMemo(()=>{const s=g?.tracking;return s?s.startsWith("origin/"):!0},[g?.tracking]),Ws=l.useMemo(()=>{const s=M?.createdFromBranch,a=typeof s=="string"?s.trim():"",o=typeof g?.current=="string"?g.current.trim():"",c=typeof Be=="string"?Be.trim():"";return a?a===o&&a.startsWith("opencode/")&&c.length>0&&c!==a?c:a:c||o||"HEAD"},[M?.createdFromBranch,g,Be]),Mt=l.useCallback(()=>{$s([])},[]),[os,Mr]=l.useState(new Set),[Et,Er]=l.useState(new Map),[Tt,ls]=l.useState(new Set),cs=l.useRef(Et),St=l.useRef(Tt),[Tr,bt]=l.useState(null),[xt,ds]=l.useState(null),[Us,Ks]=l.useState(""),[Me,At]=l.useState(null),[Ar,Js]=l.useState(!1),[Lr,qs]=l.useState(!1),[us,ms]=l.useState([]),[Or,Ys]=l.useState(null),[Qs,hs]=l.useState(null),[zr,Lt]=l.useState([]),[Gr,qe]=l.useState(!1),[_r,Qe]=l.useState([]),[Ot,Xe]=l.useState("merge"),[$r,gs]=l.useState(null),[fs,Xs]=l.useState(!1),[ps,Hr]=l.useState(100),[Wr,Ur]=l.useState(0),Ye=l.useMemo(()=>m?`openchamber.conflict:${m}`:null,[m]),rt=l.useCallback((s,a,o)=>{if(!Ye||typeof window>"u")return;const c={directory:s,conflictFiles:a,operation:o};window.localStorage.setItem(Ye,JSON.stringify(c))},[Ye]),He=l.useCallback(()=>{!Ye||typeof window>"u"||window.localStorage.removeItem(Ye)},[Ye]);l.useEffect(()=>{if(!Ye||typeof window>"u"||!r)return;const s=window.localStorage.getItem(Ye);if(s)try{const a=JSON.parse(s);if(a.directory!==r){window.localStorage.removeItem(Ye);return}Qe(a.conflictFiles??[]),Xe(a.operation??"merge"),qe(!0)}catch{window.localStorage.removeItem(Ye)}},[Ye,r]);const[Kr,xs]=l.useState(!1),[ws,Zs]=l.useState("merge"),[ys,er]=l.useState(""),Jr=l.useCallback(s=>{xa(s).then(a=>{if(a.ok){b.success(e("gitView.toast.commitHashCopied"));return}b.error(e("gitView.toast.copyFailed"))})},[e]),qr=l.useCallback(s=>{Mr(a=>{const o=new Set(a);return o.has(s)?o.delete(s):o.add(s),o})},[]);l.useEffect(()=>{cs.current=Et},[Et]),l.useEffect(()=>{St.current=Tt},[Tt]),l.useEffect(()=>{if(!r||!n)return;const s=Array.from(os).filter(o=>!cs.current.has(o)&&!St.current.has(o));if(s.length===0)return;let a=!1;return ls(o=>{const c=new Set(o);for(const N of s)c.add(N);return St.current=c,c}),Promise.all(s.map(o=>n.getCommitFiles(r,o).then(c=>({hash:o,files:c.files})).catch(c=>(console.error("Failed to fetch commit files:",c),{hash:o,files:[]})))).then(o=>{a||(Er(c=>{const N=new Map(c);for(const{hash:z,files:ae}of o)N.set(z,ae);return cs.current=N,N}),ls(c=>{const N=new Set(c);for(const{hash:z}of o)N.delete(z);return St.current=N,N}))}),()=>{a=!0,ls(o=>{let c=!1;const N=new Set(o);for(const z of s)N.delete(z)&&(c=!0);return c?(St.current=N,N):o})}},[os,r,n]),l.useEffect(()=>{r&&Vi(r,{directory:r,commitMessage:we,generatedHighlights:ns})},[we,r,ns]),l.useEffect(()=>{i&&(S(),R(),V())},[i,S,R,V]),l.useEffect(()=>{if(!i)return;if(!r||!n?.getRemoteUrl){ds(null);return}let s=!1;return n.getRemoteUrl(r).then(a=>{s||ds(a)}).catch(()=>{s||ds(null)}),()=>{s=!0}},[i,r,n]);const zt=l.useCallback(async()=>{if(!r||!n?.getRemotes){ms([]);return}try{const s=await n.getRemotes(r);ze.current&&ms(s)}catch{ze.current&&ms([])}},[r,n]);l.useEffect(()=>{i&&zt()},[i,zt]),l.useEffect(()=>{i&&r&&(Z(r),de(r,n))},[i,r,Z,de,n]),l.useEffect(()=>{if(i&&r)return wa.onGitRefreshHint(s=>{nt(s.directory)===nt(r)&&(s.paths?.length&&q(r,s.paths),Q(r,n,{silent:!0}))})},[i,q,r,Q,n]);const ne=l.useCallback(async(s=!0)=>{if(r)try{await Promise.all([Q(r,n),te(r,n)])}catch(a){if(s){const o=a instanceof Error?a.message:e("gitView.toast.refreshRepositoryFailed");b.error(o)}}},[r,n,Q,te,e]),ye=l.useCallback(async()=>{r&&await u(r,n,Je)},[r,n,u,Je]),bs=l.useCallback(async()=>{r&&await F(r,n)},[r,n,F]);l.useEffect(()=>{if(!i||!r||!n?.hasLocalIdentity||P!==!0)return;const s=typeof B=="string"?B.trim():"";if(!s||s==="global"||Os.current.get(r)===s)return;let o=!1;return(async()=>{try{const N=await n.hasLocalIdentity?.(r);if(o||N===!0)return;es(),await n.setGitIdentity(r,s),Os.current.set(r,s),await bs()}catch(N){console.warn("Failed to auto-apply default git identity:",N)}finally{o||ts()}})(),()=>{o=!0}},[i,es,r,B,ts,n,P,bs]);const ot=l.useMemo(()=>g?[...g.files??[]].sort((a,o)=>a.path.localeCompare(o.path)):[],[g]),We=l.useMemo(()=>ot.filter(yr),[ot]),js=l.useMemo(()=>ot.filter(Ii),[ot]);l.useEffect(()=>{if(!r||ot.length===0)return;const s=[],a=new Set,o=N=>{!N||a.has(N)||(a.add(N),s.push(N))};if(We.forEach(N=>o(N.path)),Ae.forEach(o),ot.slice(0,Ni).forEach(N=>o(N.path)),s.length===0)return;const c=window.setTimeout(()=>{L(r,n,s,{maxFiles:Ci})},120);return()=>{window.clearTimeout(c)}},[ot,r,n,L,We,Ae]);const tr=s=>s?.pushed[0]?.remote||g?.tracking?.split("/")[0]||Ue.find(a=>a.name==="origin")?.name||Ue[0]?.name||"origin",sr=async(s,a)=>{if(r){Ke(s);try{const o=c=>{const N=`${c.name}/`,z=g?.tracking?.startsWith(N)?g.tracking.slice(N.length):void 0;return{remote:c.name,branch:z,rebase:!0}};if(s==="fetch"){if(!a)throw new Error("No remote available for fetch");await n.gitFetch(r,{remote:a.name}),b.success(e("gitView.toast.fetchedFromRemote",{name:a.name}))}else if(s==="pull"){if(!a)throw new Error("No remote available for pull");const c=await n.gitPull(r,o(a));b.success(c.files.length===1?e("gitView.toast.pulledFilesSingle",{count:c.files.length,name:a.name}):e("gitView.toast.pulledFilesPlural",{count:c.files.length,name:a.name}))}else if(s==="push"){const c=await n.gitPush(r);b.success(e("gitView.toast.pushedToUpstream",{name:tr(c)}))}else if(s==="sync"){if(!a)throw new Error("No remote available for sync");let c=0,N=!1;await n.gitFetch(r,{remote:a.name});const z=await n.getGitStatus(r);if((z.behind??0)>0){if((z.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync"));return}c=(await n.gitPull(r,o(a))).files.length}((await n.getGitStatus(r)).ahead??0)>0&&(await n.gitPush(r),N=!0),c>0&&N?b.success(c===1?e("gitView.toast.syncedPulledSingleAndPushed",{count:c,name:a.name}):e("gitView.toast.syncedPulledPluralAndPushed",{count:c,name:a.name})):c>0?b.success(c===1?e("gitView.toast.pulledFilesSingle",{count:c,name:a.name}):e("gitView.toast.pulledFilesPlural",{count:c,name:a.name})):N?b.success(e("gitView.toast.pushedToUpstream",{name:a.name})):b.success(e("gitView.toast.alreadyUpToDate"))}await ne(!1),await ye()}catch(o){const c=o instanceof Error?o.message:e("gitView.toast.syncActionFailed",{action:s==="sync"?e("gitView.sync.syncChanges"):s==="pull"?e("gitView.sync.pull"):s});b.error(c)}finally{Ke(null)}}},Yr=l.useCallback(async s=>{if(!r)return;const a=s.name.trim();if(!a){b.error(e("gitView.toast.remoteNameRequired"));return}if(a==="origin"){b.error(e("gitView.toast.cannotRemoveOriginRemote"));return}Ys(a);try{await n.removeRemote(r,{remote:a}),b.success(e("gitView.toast.removedRemote",{name:a})),await Promise.all([ne(!1),zt()])}catch(o){const c=o instanceof Error?o.message:`Failed to remove ${a}`;b.error(c)}finally{Ys(null)}},[r,n,zt,ne,e]),rr=async(s={})=>{if(!r)return;if(!we.trim()){b.error(e("gitView.toast.enterCommitMessage"));return}const a=We.map(c=>c.path).sort();if(a.length===0){b.error(e("gitView.toast.stageFileToCommit"));return}const o=s.pushAfter?"commitAndPush":"commit";As(o);try{if(await n.createGitCommit(r,we.trim(),{files:a,stageFiles:[]}),G(r),b.success(e("gitView.toast.commitCreated")),De(""),Mt(),await ne(),s.pushAfter){const c=g?.tracking?.split("/")[0],N=Ue.find(In=>In.name===c)??Ue[0];if(!N)throw new Error(e("mobile.changes.noRemote"));Ke("sync");const z=`${N.name}/`,ae=g?.tracking?.startsWith(z)?g.tracking.slice(z.length):void 0;await n.gitFetch(r,{remote:N.name});const K=await n.getGitStatus(r);if((K.behind??0)>0){if((K.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync")),await ne(!1);return}await n.gitPull(r,{remote:N.name,branch:ae,rebase:!0})}const Oe=await n.getGitStatus(r);let jt;(Oe.ahead??0)>0&&(jt=await n.gitPush(r)),b.success(e("gitView.toast.pushedToUpstream",{name:tr(jt)})),Vr(),await ne(!1)}else await ne(!1);await ye(),Fr(c=>c+1)}catch(c){const N=c instanceof Error?c.message:e("gitView.toast.createCommitFailed");b.error(N)}finally{As(null),s.pushAfter&&Ke(null)}},Qr=l.useCallback(async()=>{if(!r)return;const s=We.map(a=>a.path).sort();if(s.length===0){b.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:s.length}),_s(!0);try{const{message:a}=await ya(r,s),o=a.subject?.trim()??"",c=Array.isArray(a.highlights)?a.highlights:[];if(o){let N=o;if(Se&&ke.length>0){const z=Si(o,ke);if(z){const{code:ae,emoji:K}=z;!o.startsWith(ae)&&!o.startsWith(K)&&(N=`${ae} ${o}`)}}De(N)}$s(c),Hs()}catch(a){console.error("[git-generation][browser] GitView generate handler failed",{message:a instanceof Error?a.message:String(a),error:a});const o=a instanceof Error?a.message:e("gitView.toast.generateCommitMessageFailed");b.error(o)}finally{_s(!1)}},[r,We,Se,ke,Hs,e]),vs=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",Xr=async(s,a)=>{if(!r||!g)return;const o=Ss(H);if(o.length>0){b.error(e("gitView.toast.cannotCreateBranch",{reason:vs(o[0])}));return}const c=g.current??null,N=a?.name??"origin";try{await n.createBranch(r,s,c??"HEAD"),b.success(e("gitView.toast.createdBranch",{name:s})),await n.checkoutBranch(r,s);let z=!1;try{await n.gitPush(r,{remote:N,branch:s,options:["--set-upstream"]}),z=!0}catch(ae){const K=ae instanceof Error?ae.message:`Unable to push new branch to ${N}.`;b.warning(e("gitView.toast.branchCreatedLocally"),{description:t.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",K]})})}await ne(),await ye(),z&&b.success(e("gitView.toast.upstreamSet",{branch:s,remote:N}))}catch(z){const ae=z instanceof Error?z.message:e("gitView.toast.createBranchFailed");throw b.error(ae),z}},Zr=async(s,a)=>{if(!r)return;const o=Ss(H);if(o.length>0){b.error(e("gitView.toast.cannotRenameBranch",{reason:vs(o[0])}));return}try{await n.renameBranch(r,s,a),b.success(e("gitView.toast.renamedBranch",{oldName:s,newName:a})),await ne(),await ye()}catch(c){const N=c instanceof Error?c.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:a});b.error(N)}},en=async s=>{if(!r)return;const a=Ss(H);if(a.length>0){b.error(e("gitView.toast.cannotCheckout",{reason:vs(a[0])}));return}const o=s.replace(/^remotes\//,"");if(g?.current!==o)try{await n.checkoutBranch(r,o),b.success(e("gitView.toast.checkedOut",{name:o})),await ne(),await ye()}catch(c){const N=c instanceof Error?c.message:e("gitView.toast.checkoutFailed",{name:o});b.error(N)}},tn=async s=>{if(r){es();try{await n.setGitIdentity(r,s.id),b.success(e("gitView.toast.appliedIdentity",{name:s.name})),await bs()}catch(a){const o=a instanceof Error?a.message:e("gitView.toast.applyIdentityFailed");b.error(o)}finally{ts()}}},kt=l.useMemo(()=>U?.all?U.all.filter(s=>!s.startsWith("remotes/")).sort():[],[U]),lt=l.useMemo(()=>U?.all?U.all.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],[U]),Ue=l.useMemo(()=>{if(us.length>0)return us;const s=new Set,a=g?.tracking?.trim();a&&a.includes("/")&&s.add(a.split("/")[0]);for(const o of lt){const c=o.indexOf("/");c>0&&s.add(o.slice(0,c))}return s.size===0&&xt&&s.add("origin"),Array.from(s).map(o=>({name:o,fetchUrl:xt??"",pushUrl:xt??""}))},[us,lt,xt,g?.tracking]),ct=g?.current??null,nr=l.useMemo(()=>{const s=g?.tracking?.trim().split("/")[0];return(s&&U?.defaultBranches?.[s])??U?.defaultBranches?.origin},[U,g?.tracking]),wt=l.useMemo(()=>Na({remoteNames:new Set(Ue.map(s=>s.name)),localBranches:kt,worktreeCreatedFromBranch:M?.createdFromBranch,rootBranchHint:Be,defaultBranch:nr,headBranch:ct}),[ct,nr,Ue,kt,Be,M?.createdFromBranch]),sn=l.useMemo(()=>Ue.map(o=>o.name).map(o=>`${o}/${wt}`).find(o=>lt.includes(o))??wt,[wt,Ue,lt]),rn=l.useMemo(()=>{const s=new Map;w&&s.set(w.id,w);let a=null;if(xt)try{let o=xt.trim();o.startsWith("git@")&&(o=`https://${o.slice(4).replace(":","/")}`),o.endsWith(".git")&&(o=o.slice(0,-4));const c=new URL(o);a=c.hostname+c.pathname}catch{}for(const o of v){if(o.authType!=="token"){s.set(o.id,o);continue}const c=o.host;if(!c){s.set(o.id,o);continue}if(!c.includes("/")){s.set(o.id,o);continue}a&&a===c&&s.set(o.id,o)}return Array.from(s.values())},[v,w,xt]),nn=l.useMemo(()=>{if(_?.userName&&_?.userEmail){const s=v.find(a=>a.userName===_.userName&&a.userEmail===_.userEmail);return s||(w&&w.userName===_.userName&&w.userEmail===_.userEmail?w:{id:"local-config",name:_.userName,userName:_.userName,userEmail:_.userEmail,sshKey:_.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return w??null},[_,v,w]),an=We.length,on=Y||st!==null||Ts!==null,ln=!!(M&&as&&is&&Dr),ar=!!ct,dt=ln&&as&&is&&M?{repoRoot:as,sourceBranch:is,worktreeMetadata:M}:null;l.useEffect(()=>{if(!r||!n||!$?.all?.length||!ct||!wt||ct===wt){bt(null);return}let s=!1;return(async()=>{try{const o=await n.getGitLog(r,{from:wt,to:"HEAD",maxCount:Je});if(s)return;const c=new Set((o?.all??[]).map(z=>z.hash).filter(z=>typeof z=="string"&&z.length>0));if(c.size===0){bt(null);return}const N=$.all.findIndex(z=>!c.has(z.hash));if(N===0){bt(null);return}if(N===-1){bt({insertBeforeIndex:$.all.length,branchName:ct,direction:"up"});return}bt({insertBeforeIndex:N,branchName:ct,direction:"up"})}catch{s||bt(null)}})(),()=>{s=!0}},[wt,ct,r,n,$,Je]),l.useEffect(()=>{gs(null)},[r]),l.useEffect(()=>{if(Me!=="graph"||!r){Me!=="graph"&&gs(null);return}let s=!1;return Xs(!0),n.getGitLog(r,{maxCount:ps,all:!0}).then(a=>{s||gs(a)}).catch(a=>{console.error("Failed to fetch graph log:",a)}).finally(()=>{s||Xs(!1)}),()=>{s=!0}},[Me,r,ps,Wr,n]);const Vt=l.useCallback((s,a)=>{if(!r||s.length===0)return;const o=Array.from(new Set(s));zs(N=>{const z=new Set(N);return o.forEach(ae=>z.add(ae)),z});const c=ie(r,o,a);J.enqueue({directory:r,direction:a,paths:new Set(o),rollback:()=>se(r,c)}),Ce()},[r,J,ie,se,Ce]),Cs=l.useCallback(async s=>{if(r){Dt(a=>{const o=new Set(a);return o.add(s),o});try{await n.revertGitFile(r,s,{scope:"working"}),b.success(e("gitView.toast.revertedFile",{path:s})),await ne(!1)}catch(a){const o=a instanceof Error?a.message:e("gitView.toast.revertFailed");b.error(o)}finally{Dt(a=>{const o=new Set(a);return o.delete(s),o})}}},[r,ne,n,e]),Gt=l.useCallback(async(s,a,o="all")=>{if(!r||s.length===0)return;const c=Array.from(new Set(s));if(rs||c.some(K=>ss.has(K)))return;const N=new Set(We.map(K=>K.path)),z=o==="all"&&c.some(K=>N.has(K));a&&Gs(!0),Dt(K=>{const Oe=new Set(K);return c.forEach(jt=>Oe.add(jt)),Oe});const ae=[];try{if(await Promise.all(c.map(async K=>{try{await n.revertGitFile(r,K,{scope:o})}catch(Oe){ae.push({path:K,message:Oe instanceof Error?Oe.message:e("gitView.toast.revertFailed")})}})),z&&ae.length<c.length&&G(r),await ne(!1),ae.length===0)b.success(c.length===1?e("gitView.toast.revertedFilesSingle",{count:c.length}):e("gitView.toast.revertedFilesPlural",{count:c.length}));else if(ae.length===c.length)b.error(ae[0]?.message||e("gitView.toast.revertFailed"));else{const K=c.length-ae.length;b.warning(K===1?e("gitView.toast.revertedSomeSingle",{success:K,failed:ae.length}):e("gitView.toast.revertedSomePlural",{success:K,failed:ae.length}))}}finally{Dt(K=>{const Oe=new Set(K);return c.forEach(jt=>Oe.delete(jt)),Oe}),a&&Gs(!1)}},[G,r,n,rs,ne,ss,We,e]),cn=l.useCallback(async s=>{await Gt(s,!0)},[Gt]),dn=l.useCallback(async s=>{await Gt(s,!1,"working")},[Gt]),Ns=l.useCallback((s,a)=>{if(r&&!fe){re(r,s,a);return}ue(s,a)},[r,fe,ue,re]),un=l.useCallback(()=>it(!0),[]),mn=l.useMemo(()=>{const s=[];return We.length>0&&s.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:We,actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:a=>e("gitView.changes.unstageFileAria",{path:a}),onActionFile:a=>{Vt([a],"unstage")},onActionAll:a=>{Vt(a,"unstage")},onViewDiff:a=>Ns(a,!0),onRevertFile:Cs,showRevertActions:!1,accent:!0}),js.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:js,actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:a=>e("gitView.changes.stageFileAria",{path:a}),onActionFile:a=>{Vt([a],"stage")},onActionAll:a=>{Vt(a,"stage")},onViewDiff:a=>Ns(a,!1),onRevertFile:Cs}),s},[Cs,Ns,Vt,We,e,js]),hn=l.useCallback(s=>{if(s.length===0)return;const a=s.map(o=>o.trim()).filter(Boolean);if(a.length===0){Mt();return}De(o=>{const c=o.trim(),N=c.length>0?`
4
-
5
- `:"";return`${c}${N}${a.join(`
6
- `)}`.trim()}),Mt()},[Mt]),gn=l.useCallback((s,a)=>{const o=a||s;De(c=>{const N=c.trimStart();return N.startsWith(s)||a&&N.startsWith(a)?c:`${o.endsWith(" ")?o:`${o} `}${c}`.trimStart()}),Ks(""),_e(!1)},[]),_t=l.useCallback(s=>{const a=s instanceof Error?s.message.toLowerCase():"";return a.includes("uncommitted changes")||a.includes("local changes")||a.includes("your local changes would be overwritten")||a.includes("please commit your changes or stash them")||a.includes("cannot rebase: you have unstaged changes")||a.includes("error: cannot pull with rebase")},[]),ut=l.useCallback((s,a)=>{Lt(o=>[...o,{message:s,status:a,timestamp:Date.now()}])},[]),Le=l.useCallback((s,a)=>{Lt(o=>{if(o.length===0)return o;const c=[...o];return c[c.length-1]={...c[c.length-1],status:s,...a?{message:a}:{}},c})},[]),$t=l.useCallback(()=>{Lt([])},[]),fn=l.useCallback(()=>{Lt([]),hs(null)},[]),Ht=l.useCallback(s=>{const a=s.trim(),o=new Set(Ue.map(N=>N.name)),c=a.indexOf("/");if(c>0){const N=a.slice(0,c),z=a.slice(c+1);if(o.has(N)&&z)return{branch:a,remote:N,remoteBranch:z}}for(const N of Ue){const z=`${N.name}/${a}`;if(lt.includes(z))return{branch:z,remote:N.name,remoteBranch:a}}return{branch:a,remote:null,remoteBranch:null}},[Ue,lt]),pn=l.useCallback(async s=>{if(!r)return;hs("merge"),$t();const a=g?.current,o=Ht(s);try{o.remote&&o.remoteBranch&&(ut(`Fetching ${o.remote}/${o.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:o.remote,branch:o.remoteBranch}),Le("done",`Fetched ${o.remote}/${o.remoteBranch}`)),ut(`Merging ${o.branch} into ${a}...`,"running");const c=await n.merge(r,{branch:o.branch});c.conflict?(Le("error","Merge conflicts detected"),Qe(c.conflictFiles??[]),Xe("merge"),qe(!0),rt(r,c.conflictFiles??[],"merge")):(Le("done",`Merged ${o.branch} into ${a}`),He(),ut("Refreshing repository status...","running"),await ne(),await ye(),Le("done","Repository status updated"))}catch(c){if(_t(c))Le("error","Uncommitted changes detected"),Zs("merge"),er(o.branch),xs(!0);else{const N=c instanceof Error?c.message:`Failed to merge ${o.branch}`;Le("error",N)}}},[r,n,g,Ht,ne,ye,_t,rt,He,ut,Le,$t]),xn=l.useCallback(async s=>{if(!r)return;hs("rebase"),$t();const a=g?.current,o=Ht(s);try{o.remote&&o.remoteBranch&&(ut(`Fetching ${o.remote}/${o.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:o.remote,branch:o.remoteBranch}),Le("done",`Fetched ${o.remote}/${o.remoteBranch}`)),ut(`Rebasing ${a} onto ${o.branch}...`,"running");const c=await n.rebase(r,{onto:o.branch});c.conflict?(Le("error","Rebase conflicts detected"),Qe(c.conflictFiles??[]),Xe("rebase"),qe(!0),rt(r,c.conflictFiles??[],"rebase")):(Le("done",`Rebased ${a} onto ${o.branch}`),He(),ut("Refreshing repository status...","running"),await ne(),await ye(),Le("done","Repository status updated"))}catch(c){if(_t(c))Le("error","Uncommitted changes detected"),Zs("rebase"),er(o.branch),xs(!0);else{const N=c instanceof Error?c.message:`Failed to rebase onto ${o.branch}`;Le("error",N)}}},[r,n,g,Ht,ne,ye,_t,rt,He,ut,Le,$t]),wn=l.useCallback(async()=>{if(r)try{Ot==="merge"?(await n.abortMerge(r),b.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),b.success(e("gitView.toast.rebaseAborted"))),He(),await ne(),await ye()}catch(s){const a=s instanceof Error?s.message:`Failed to abort ${Ot}`;b.error(a)}},[r,n,Ot,ne,ye,He,e]),yn=l.useMemo(()=>g?.files?g.files.filter(s=>s.index==="U"||s.working_dir==="U"||s.index==="A"&&s.working_dir==="A"||s.index==="D"&&s.working_dir==="D").length:0,[g?.files]),bn=l.useCallback(async()=>{if(r)try{const s=!!g?.mergeInProgress?.head,a=!!(g?.rebaseInProgress?.headName||g?.rebaseInProgress?.onto);if(s){const o=await n.continueMerge(r);o.conflict?(Qe(o.conflictFiles??[]),Xe("merge"),qe(!0),rt(r,o.conflictFiles??[],"merge"),b.error(e("gitView.toast.mergeConflictsDetected"))):(He(),b.success(e("gitView.toast.mergeCompleted")),await ne(),await ye())}else if(a){const o=await n.continueRebase(r);o.conflict?(Qe(o.conflictFiles??[]),Xe("rebase"),qe(!0),rt(r,o.conflictFiles??[],"rebase"),b.error(e("gitView.toast.rebaseConflictsDetected"))):(He(),b.success(e("gitView.toast.rebaseStepCompleted")),await ne(),await ye())}}catch(s){const a=s instanceof Error?s.message:e("gitView.toast.continueOperationFailed");b.error(a)}},[r,n,g,ne,ye,rt,He,e]),jn=l.useCallback(async()=>{if(r)try{!!g?.mergeInProgress?.head?(await n.abortMerge(r),b.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),b.success(e("gitView.toast.rebaseAborted"))),He(),await ne(),await ye()}catch(s){const a=s instanceof Error?s.message:e("gitView.toast.abortOperationFailed");b.error(a)}},[r,n,g,ne,ye,He,e]),vn=l.useCallback(()=>{if(!r)return;const a=!!g?.mergeInProgress?.head?"merge":"rebase",o=g?.files?.filter(c=>c.index==="U"||c.working_dir==="U").map(c=>c.path)??[];o.length>0&&Qe(o),Xe(a),qe(!0)},[r,g]),Cn=l.useCallback(async s=>{if(!r)return;const a=g?.current,o=ws,c=ys,N=(g?.files??[]).some(yr);try{await n.stash(r,{message:`Auto-stash before ${o} with ${c}`,includeUntracked:!0}),N&&G(r)}catch(K){const Oe=K instanceof Error?K.message:"Failed to stash changes";b.error(Oe);return}let z=!1,ae=!1;try{if(o==="merge"){const K=await n.merge(r,{branch:c});K.conflict?(ae=!0,Qe(K.conflictFiles??[]),Xe("merge"),qe(!0)):(z=!0,b.success(e("gitView.toast.mergedIntoBranch",{branch:c,currentBranch:a||""})))}else{const K=await n.rebase(r,{onto:c});K.conflict?(ae=!0,Qe(K.conflictFiles??[]),Xe("rebase"),qe(!0)):(z=!0,b.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:a||"",branch:c})))}if(s&&z)try{await n.stashPop(r),G(r),b.success(e("gitView.toast.stashedRestored"))}catch(K){const Oe=K instanceof Error?K.message:e("gitView.toast.restoreStashFailed");b.error(Oe)}else s&&ae&&b.info(e("gitView.toast.restoreStashManually"));await ne(),await ye()}catch(K){if(s)try{await n.stashPop(r),G(r)}catch{}throw K}},[G,r,n,g,ws,ys,ne,ye,e]),Nn=l.useCallback(s=>{Sr(s),r&&(d(r,s),u(r,n,s))},[r,u,n,d]),Sn=l.useCallback(s=>{Hr(s)},[]),kn=l.useCallback(()=>{At(null),r&&(Q(r,n),te(r,n),u(r,n,Je))},[r,Q,te,u,Je,n]),Vn=l.useCallback(s=>{if(s.conflict){if(s.operation==="cherry-pick"||s.operation==="revert"){b.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:s.conflictFiles?.join(", ")??"unknown files"})}),r&&(Q(r,n),te(r,n),u(r,n,Je));return}Qe(s.conflictFiles??[]),Xe(s.operation),qe(!0),r&&rt(r,s.conflictFiles??[],s.operation)}},[e,Qe,Xe,qe,rt,r,Q,te,u,Je,n]);return r?P===null||P===!0&&!g?t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):P===!1?Ie?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[t.jsx(T,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.worktreeSetupInProgress")}),t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):t.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[t.jsx(T,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.notGitRepository")}),t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.notGitRepositoryDescription")}),A.includes("open-without-worktree-features")?t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:e("gitView.empty.worktreeFeaturesUnavailable")}):null]}):t.jsxs("div",{className:Ve("flex h-full flex-col overflow-hidden"),children:[t.jsx(Pa,{status:g,localBranches:kt,remoteBranches:lt,branchInfo:U?.branches,syncAction:st,remotes:Ue,onFetch:s=>sr("fetch",s),onSync:s=>sr("sync",s),onRemoveRemote:Yr,removingRemoteName:Or,onCheckoutBranch:en,onCreateBranch:Xr,onRenameBranch:Zr,activeIdentityProfile:nn,availableIdentities:rn,onSelectIdentity:tn,isApplyingIdentity:kr,isWorktreeMode:!!M,onOpenHistory:()=>At("history"),onOpenGraph:()=>At("graph"),onOpenStashes:un,onOpenUpdateBranch:ar?()=>Js(!0):void 0,onOpenReintegrateCommits:dt?()=>qs(!0):void 0,pullRequest:pe?.pr??null,prChecks:pe?.checks??null,onOpenPullRequest:r?()=>le(r,"pr"):void 0}),r&&(g?.mergeInProgress?.head||g?.rebaseInProgress?.headName||g?.rebaseInProgress?.onto)&&t.jsx(mi,{mergeInProgress:g?.mergeInProgress,rebaseInProgress:g?.rebaseInProgress,onContinue:bn,onAbort:jn,onResolveWithAI:vn,conflictCount:yn,isLoading:Y}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:t.jsx("div",{className:"h-full min-h-0 flex flex-col",children:t.jsx("div",{className:Ve("min-w-0 min-h-0 h-full flex flex-col"),children:t.jsx(jr,{as:ba,ref:tt,outerClassName:"flex-1 min-h-0",className:Ve("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:t.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(ot?.length??0)>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Ra,{groups:mn,diffStats:g?.diffStats,revertingPaths:ss,isRevertingAll:rs,onVisiblePathsChange:X,onRevertAll:cn,onRevertDirectory:dn,headerBackgroundClassName:"bg-background"})}),t.jsx(Ba,{stagedCount:an,commitMessage:we,onCommitMessageChange:De,generatedHighlights:ns,onInsertHighlights:hn,onGenerateMessage:Qr,isGeneratingMessage:Rr,onCommit:()=>rr({pushAfter:!1}),onCommitAndPush:()=>rr({pushAfter:!0}),commitAction:Ts,hasPendingIndexMutation:Br,gitmojiEnabled:Se,onOpenGitmojiPicker:()=>_e(!0)})]}):t.jsx(Wa,{onOpenStashes:()=>it(!0)})})})})})}),t.jsx(ht,{open:Ar,onOpenChange:s=>{!s&&Qs!==null||Js(s)},children:t.jsxs(gt,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(pt,{children:e("gitView.branch.updateTitle")}),t.jsxs(yt,{children:[e("gitView.branch.updateDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:g?.current??""}),"."]})]}),ar?t.jsx(hi,{mode:"bare",currentBranch:g?.current,localBranches:kt,remoteBranches:lt,defaultTargetBranch:sn,onMerge:pn,onRebase:xn,disabled:on,isOperating:Qs!==null,operationLogs:zr,onOperationComplete:fn}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})]})}),t.jsx(ht,{open:Lr,onOpenChange:qs,children:t.jsxs(gt,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(pt,{children:e("gitView.integrate.title")}),t.jsx(yt,{children:dt?t.jsxs("span",{className:"font-mono text-foreground",children:[dt.sourceBranch," → ",Ws]}):null})]}),dt?t.jsx($a,{repoRoot:dt.repoRoot,sourceBranch:dt.sourceBranch,worktreeMetadata:dt.worktreeMetadata,localBranches:kt,defaultTargetBranch:Ws,refreshKey:Pr,showHeader:!1,onRefresh:()=>{r&&(Q(r,n),te(r,n),u(r,n,Je))}},dt.worktreeMetadata.path):null]})}),t.jsx(ht,{open:Me!==null,onOpenChange:s=>{s||At(null)},children:t.jsxs(gt,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx(pt,{children:e(Me==="graph"?"gitView.graph.title":"gitView.history.title")}),t.jsxs(W,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:()=>{if(Me==="graph"){Ur(s=>s+1);return}r&&u(r,n,Je)},disabled:Me==="graph"?fs:ee,title:e("gitView.history.refresh"),"aria-label":e("gitView.history.refresh"),children:[t.jsx(T,{name:"refresh",className:Ve("size-4",(Me==="graph"?fs:ee)&&"animate-spin")}),e("gitView.history.refresh")]})]}),t.jsx(yt,{children:e("gitView.history.dialogDescription")})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(ei,{mode:Me==="graph"?"graph":"history",log:Me==="graph"?$r??$:$,isLogLoading:Me==="graph"&&fs||ee,logMaxCount:Me==="graph"?ps:Je,onLogMaxCountChange:Me==="graph"?Sn:Nn,expandedCommitHashes:os,onToggleCommit:qr,commitFilesMap:Et,loadingCommitHashes:Tt,onCopyHash:Jr,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Me==="graph"?null:Tr,onConflict:Me==="graph"?Vn:void 0,onActionSuccess:Me==="graph"?kn:void 0})})]})}),t.jsx(Ha,{open:at,onOpenChange:it,directory:r,hasUncommittedChanges:(g?.files?.length??0)>0,hasStagedChanges:We.length>0,uncommittedFileCount:g?.files?.length??0,onChanged:async s=>{r&&s?.affectsIndex&&G(r),await ne(!1),await ye()}}),t.jsx(ht,{open:Fe,onOpenChange:_e,children:t.jsxs(gt,{className:"max-w-md p-0 overflow-hidden",children:[t.jsx(ft,{className:"px-4 pt-4",children:t.jsx(pt,{children:e("gitView.gitmoji.title")})}),t.jsxs(Bs,{className:"h-[420px]",shouldFilter:!1,children:[t.jsx(Ds,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:Us,onValueChange:Ks}),t.jsxs(Ms,{children:[t.jsx(Es,{children:e("gitView.gitmoji.empty")}),t.jsx(qt,{children:Rt(ke,Us,s=>[s.code,s.description,s.emoji]).map(s=>t.jsxs(Yt,{onSelect:()=>gn(s.emoji,s.code),children:[t.jsx("span",{className:"text-lg",children:s.emoji}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s.code}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s.description})]},s.code))})]})]})]})}),r&&t.jsx(ai,{open:Gr,onOpenChange:qe,conflictFiles:_r,directory:r,operation:Ot,onAbort:wn,onClearState:He}),t.jsx(ui,{open:Kr,onOpenChange:xs,operation:ws,targetBranch:ys,onConfirm:Cn})]}):t.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:e("gitView.empty.selectSessionOrDirectory")})})};export{Wl as GitView};
@@ -1 +0,0 @@
1
- import{f as W,R as h,j as P}from"./vendor-react-BUCujlKS.js";import{toast as K}from"./vendor-sonner-DFyL3AvE.js";import{fp as H,fm as J,a9 as Z,f as Q,I as B}from"./useAppFontEffects-Cll4gnsh.js";import{r as G,V,F as ee,e as te,cW as re,cX as oe,aK as ae}from"./index-rlLjZUM5.js";import{extractMarkdownImageCandidates as se,MAX_MARKDOWN_IMAGE_COUNT as ne}from"./markdownCore-DG6GHLF4.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-_6j2xOWl.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CpzVNWAv.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DkQX2EBa.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-zod-BLfBSgBh.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";const L=10*1024*1024,ie=1024,le=3e4,ce=new Set(["image/png","image/jpeg","image/gif","image/webp"]),z=new WeakMap,$=r=>{if(r.aborted)throw new DOMException("Image load aborted","AbortError")},me=r=>{let e=r;if(/^file:\/\//i.test(e))try{const o=new URL(e);if(o.protocol!=="file:")return"";e=o.host&&o.host!=="localhost"?`//${o.host}${o.pathname}`:o.pathname,/^\/[A-Za-z]:\//.test(e)&&(e=e.slice(1))}catch{return""}const t=e.split(/[?#]/,1)[0]??"";try{return decodeURIComponent(t)}catch{return t}},ue=r=>new Promise((e,t)=>{const o=new FileReader;o.onload=()=>{typeof o.result=="string"?e(o.result):t(new Error("Unable to encode image"))},o.onerror=()=>t(o.error??new Error("Unable to encode image")),o.readAsDataURL(r)}),pe=async(r,e)=>{const t=new Uint8Array(await r.slice(0,12).arrayBuffer()),o=(n,u)=>String.fromCharCode(...t.slice(n,u));switch(e){case"image/png":return t[0]===137&&o(1,4)==="PNG"&&t[4]===13&&t[5]===10&&t[6]===26&&t[7]===10;case"image/jpeg":return t[0]===255&&t[1]===216&&t[2]===255;case"image/gif":{const n=o(0,6);return n==="GIF87a"||n==="GIF89a"}case"image/webp":return o(0,4)==="RIFF"&&o(8,12)==="WEBP";default:return!1}},Y=async(r,e)=>{if(!ce.has(e))throw new Error("Unsupported image type");if(r.size>L)throw new Error("Image is too large");if(!await pe(r,e))throw new Error("Unsupported image data")},fe=async r=>{const e=/^data:(image\/(?:png|jpeg|gif|webp));base64,([\s\S]*)$/i.exec(r);if(!e?.[1]||e[2]===void 0)throw new Error("Invalid image data URL");if(e[2].length>Math.ceil(L*4/3)+4)throw new Error("Image is too large");let t;try{t=atob(e[2])}catch{throw new Error("Invalid image data URL")}const o=Uint8Array.from(t,n=>n.charCodeAt(0));await Y(new Blob([o]),e[1].toLowerCase())},X=r=>!/^(?:https?:)?\/\//i.test(r)&&!/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r),de=async({sources:r,directory:e,sessionId:t,messageId:o,signal:n})=>{const u=V();let s=z.get(u);s||(s=new Map,z.set(u,s));const c=`${t}\0${o}\0${e}\0${r.join("\0")}`,i=s.get(c);if(i&&i.expiresAt>Date.now())return s.delete(c),s.set(c,i),i.result;i&&s.delete(c);const p=await G(`/api/openchamber/sessions/${encodeURIComponent(t)}/markdown-image-grants`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({directory:e,messageId:o,sources:r}),signal:n});if(!p.ok)throw new Error(`Unable to prepare images (${p.status})`);const m=await p.json(),l=new Map;for(const a of m.results??[])a.source&&(a.status==="ready"&&a.path?l.set(a.source,{status:"ready",path:a.path,outsideFileGrant:a.outsideFileGrant,expiresAt:a.expiresAt}):a.status==="missing"?l.set(a.source,{status:"missing"}):l.set(a.source,{status:"error"}));for(const a of r)l.has(a)||l.set(a,{status:"error"});for(;s.size>=ie;)s.delete(s.keys().next().value);const w=[...l.values()].every(a=>a.status==="ready"),y=Math.min(...[...l.values()].filter(a=>a.status==="ready").map(a=>a.expiresAt??Number.POSITIVE_INFINITY));return s.set(c,{result:l,expiresAt:w?y:Date.now()+le}),l},ge=async(r,e)=>{if($(e),/^(?:https?:)?\/\//i.test(r))return r;if(/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r))return await fe(r),$(e),r;throw new Error("Local image has not been prepared")},he=async(r,e,t)=>{$(t);const o=me(r),n=H(e,o);if(!e||!o||!J(n,e))throw new Error("Image path is outside the active workspace");const u=await G("/api/fs/stat",{query:{path:n,directory:e,optional:"true"},signal:t});if(!u.ok)throw new Error(`Unable to inspect image (${u.status})`);const s=await u.json();if(!s.isFile)throw new Error("Image path is not a file");if(typeof s.size=="number"&&s.size>L)throw new Error("Image is too large");const c=await G("/api/fs/raw",{query:{path:n,directory:e},signal:t});if(!c.ok)throw new Error(`Unable to load image (${c.status})`);const i=(c.headers.get("content-type")??"").split(";",1)[0]?.toLowerCase()??"",p=Number(c.headers.get("content-length"));if(Number.isFinite(p)&&p>L)throw new Error("Image is too large");const m=await c.blob();return await Y(m,i),$(t),ue(m)},we=(r,e)=>V().authenticatedAsset("/api/fs/raw",{path:r.path,directory:e,allowOutsideWorkspace:r.outsideFileGrant?"true":void 0,outsideFileGrant:r.outsideFileGrant}),be=r=>{const e=W.c(7),[t,o]=h.useState(!1),[n,u]=h.useState(0);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=te(),e[0]=s):s=e[0];const c=s;let i,p;e[1]!==r?(i=()=>{if(!r){o(!1);return}let w=!1,y;const a=re(c),g=oe(()=>{w||u(Ie)}),I=()=>{ae(c).then(()=>{w||o(!0)}).catch(()=>{w||(y=setTimeout(I,1e3))})};return I(),()=>{w=!0,y&&clearTimeout(y),a(),g()}},p=[c,r],e[1]=r,e[2]=i,e[3]=p):(i=e[2],p=e[3]),h.useEffect(i,p);const m=!r||t;let l;return e[4]!==n||e[5]!==m?(l={ready:m,nonce:n},e[4]=n,e[5]=m,e[6]=l):l=e[6],l},ye=r=>{const e=W.c(46),{candidate:t,preparation:o,directory:n,assetAuthReady:u,assetAuthNonce:s,useWorkspaceFsBridge:c,onShowPopup:i}=r,{t:p}=Q(),m=h.useRef(null),[l,w]=h.useState(!1);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y={url:"",status:"loading"},e[0]=y):y=e[0];const[a,g]=h.useState(y);let I;e[1]!==t.source?(I=X(t.source),e[1]=t.source,e[2]=I):I=e[2];const b=I;let x,f;e[3]!==l?(x=()=>{const N=m.current;if(!N||l)return;if(typeof IntersectionObserver>"u"){w(!0);return}const E=new IntersectionObserver(C=>{C.some(Ee)&&(w(!0),E.disconnect())},{rootMargin:"200px"});return E.observe(N),()=>E.disconnect()},f=[l],e[3]=l,e[4]=x,e[5]=f):(x=e[4],f=e[5]),h.useEffect(x,f);let v;e[6]!==u||e[7]!==t.source||e[8]!==n||e[9]!==b||e[10]!==o||e[11]!==l||e[12]!==c?(v=()=>{if(!l||b&&!c&&!o)return;if(b&&c){const E=new AbortController;return g({url:"",status:"loading"}),he(t.source,n,E.signal).then(C=>{E.signal.aborted||g({url:C,status:"loading"})}).catch(()=>{E.signal.aborted||g({url:"",status:"error"})}),()=>E.abort()}if(b){if(o?.status!=="ready"){g({url:"",status:"error"});return}if(!u)return;g({url:we(o,n),status:"loading"});return}const N=new AbortController;return g({url:"",status:"loading"}),ge(t.source,N.signal).then(E=>{N.signal.aborted||g({url:E,status:"loading"})}).catch(()=>{N.signal.aborted||g({url:"",status:"error"})}),()=>N.abort()},e[6]=u,e[7]=t.source,e[8]=n,e[9]=b,e[10]=o,e[11]=l,e[12]=c,e[13]=v):v=e[13];let k;e[14]!==s||e[15]!==u||e[16]!==t.source||e[17]!==n||e[18]!==b||e[19]!==o||e[20]!==l||e[21]!==c?(k=[s,u,t.source,n,b,o,l,c],e[14]=s,e[15]=u,e[16]=t.source,e[17]=n,e[18]=b,e[19]=o,e[20]=l,e[21]=c,e[22]=k):k=e[22],h.useEffect(v,k);let R;e[23]!==t.filename||e[24]!==a.status||e[25]!==a.url||e[26]!==i||e[27]!==p?(R=()=>{if(a.status==="error"){K.error(p("filesView.error.previewUnavailable"));return}a.status!=="ready"||!i||i({open:!0,title:t.filename,content:"",metadata:{tool:"markdown-image-preview",filename:t.filename},image:{url:a.url,filename:t.filename}})},e[23]=t.filename,e[24]=a.status,e[25]=a.url,e[26]=i,e[27]=p,e[28]=R):R=e[28];const U=R,j=a.status==="loading";let A;e[29]!==t.filename||e[30]!==a.status||e[31]!==a.url?(A=P.jsx("span",{className:"flex h-[72px] w-[100px] items-center justify-center overflow-hidden rounded-lg border border-border/40 bg-muted/10",children:a.url&&a.status!=="error"?P.jsx("img",{src:a.url,alt:t.filename,className:"h-full w-full object-contain",loading:"lazy",decoding:"async",referrerPolicy:"no-referrer",onLoad:()=>g(Ae),onError:()=>g({url:"",status:"error"}),"data-openchamber-markdown-image":"true","data-openchamber-markdown-image-thumbnail":"true","data-openchamber-markdown-image-state":a.status}):P.jsx(B,{name:"file-image",className:"h-5 w-5 text-muted-foreground"})}),e[29]=t.filename,e[30]=a.status,e[31]=a.url,e[32]=A):A=e[32];let _;e[33]===Symbol.for("react.memo_cache_sentinel")?(_=P.jsx(B,{name:"file-image",className:"h-3 w-3 shrink-0"}),e[33]=_):_=e[33];let S;e[34]!==t.filename?(S=P.jsx("span",{className:"min-w-0 truncate typography-meta",children:t.filename}),e[34]=t.filename,e[35]=S):S=e[35];let F;e[36]!==t.filename||e[37]!==S?(F=P.jsxs("span",{className:"mt-1 flex w-[100px] items-center justify-center gap-1 text-muted-foreground",title:t.filename,"data-openchamber-markdown-image-caption":"true",children:[_,S]}),e[36]=t.filename,e[37]=S,e[38]=F):F=e[38];let M;return e[39]!==t.filename||e[40]!==t.source||e[41]!==U||e[42]!==F||e[43]!==j||e[44]!==A?(M=P.jsxs("button",{ref:m,type:"button",className:"w-[100px] shrink-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t.filename,disabled:j,onClick:U,"data-openchamber-markdown-image-action":"true","data-openchamber-markdown-image-source":t.source,"data-openchamber-markdown-image-filename":t.filename,children:[A,F]}),e[39]=t.filename,e[40]=t.source,e[41]=U,e[42]=F,e[43]=j,e[44]=A,e[45]=M):M=e[45],M},cr=r=>{const e=W.c(34),{sessionId:t,messageId:o,contents:n,onShowPopup:u}=r,s=Z()??"",c=h.useRef(null),[i,p]=h.useState(!1),[m,l]=h.useState(null),[w,y]=h.useState(0);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=ee(),e[0]=a):a=e[0];const g=a;let I;e[1]!==n?(I=se(n,ne),e[1]=n,e[2]=I):I=e[2];const b=I;let x;e[3]!==b?(x=g?[]:b.filter(xe).map(ve),e[3]=b,e[4]=x):x=e[4];const f=x;let v,k;e[5]!==f.length||e[6]!==i?(v=()=>{if(f.length===0||i)return;const d=c.current;if(!d||typeof IntersectionObserver>"u"){p(!0);return}const T=new IntersectionObserver(q=>{q.some(ke)&&(p(!0),T.disconnect())},{rootMargin:"200px"});return T.observe(d),()=>T.disconnect()},k=[f.length,i],e[5]=f.length,e[6]=i,e[7]=v,e[8]=k):(v=e[7],k=e[8]),h.useEffect(v,k);let R;e[9]!==s||e[10]!==o||e[11]!==f||e[12]!==t||e[13]!==i?(R=()=>{if(!i||!t||f.length===0)return;const d=new AbortController;return de({sources:f,directory:s,sessionId:t,messageId:o,signal:d.signal}).then(T=>{d.signal.aborted||l(T)}).catch(()=>{d.signal.aborted||l(new Map(f.map(Re)))}),()=>d.abort()},e[9]=s,e[10]=o,e[11]=f,e[12]=t,e[13]=i,e[14]=R):R=e[14];let U;e[15]!==s||e[16]!==o||e[17]!==w||e[18]!==f||e[19]!==t||e[20]!==i?(U=[s,o,w,f,t,i],e[15]=s,e[16]=o,e[17]=w,e[18]=f,e[19]=t,e[20]=i,e[21]=U):U=e[21],h.useEffect(R,U);let j,A;e[22]!==m?(j=()=>{const d=Math.min(...[...m?.values()??[]].filter(_e).map(Se));if(!Number.isFinite(d))return;const T=setTimeout(()=>y(Me),Math.max(0,d-Date.now()));return()=>clearTimeout(T)},A=[m],e[22]=m,e[23]=j,e[24]=A):(j=e[23],A=e[24]),h.useEffect(j,A);let _;e[25]!==m?(_=d=>m?.get(d.source)?.status!=="missing",e[25]=m,e[26]=_):_=e[26];const S=b.filter(_),F=[...m?.values()??[]].some(Ne),M=be(F);if(S.length===0)return null;const N="mt-3 flex max-w-full gap-2 overflow-x-auto pb-1",E="true";let C;e[27]!==M||e[28]!==s||e[29]!==u||e[30]!==m?(C=d=>P.jsx(ye,{candidate:d,preparation:m?.get(d.source),directory:s,assetAuthReady:M.ready,assetAuthNonce:M.nonce,useWorkspaceFsBridge:g,onShowPopup:u},d.source),e[27]=M,e[28]=s,e[29]=u,e[30]=m,e[31]=C):C=e[31];const D=S.map(C);let O;return e[32]!==D?(O=P.jsx("div",{ref:c,className:N,"data-openchamber-markdown-image-gallery":E,children:D}),e[32]=D,e[33]=O):O=e[33],O};function Ie(r){return r+1}function Ee(r){return r.isIntersecting}function Ae(r){return{...r,status:"ready"}}function xe(r){return X(r.source)}function ve(r){return r.source}function ke(r){return r.isIntersecting}function Re(r){return[r,{status:"error"}]}function _e(r){return r.status==="ready"}function Se(r){return r.expiresAt??Number.POSITIVE_INFINITY}function Me(r){return r+1}function Ne(r){return r.status==="ready"}export{cr as MarkdownImageGallery};
@@ -1,12 +0,0 @@
1
- import{R as C,f as oe,j as ee}from"./vendor-react-BUCujlKS.js";import{m as Dt}from"./vendor-morphdom-B7dS_VPB.js";import{r as Wt,a as qt}from"./vendor-beautiful-mermaid-DztCUpLZ.js";import{ff as nt,fg as $t,fh as zt,fi as Bt,g as Ce,b2 as Ht,b5 as Vt,fj as Kt,fk as jt,V as rt,a9 as ot,fl as it,f as st,h as at,e6 as Ut,fm as Fe,fn as Zt,fo as Xt,fp as Gt,fq as Yt,fr as Jt,o as Qt}from"./useAppFontEffects-Cll4gnsh.js";import{r as en,F as lt,I as he,cc as tn,u as X,a as nn,ak as Oe,z as rn,A as on}from"./index-rlLjZUM5.js";import{h as sn}from"./contextPanelEmbeddedChat-CpzVNWAv.js";import{getCachedMarkdownBlocks as an,renderMarkdownSync as ln,renderMarkdownBlocks as cn}from"./markdownCore-DG6GHLF4.js";import{r as dn}from"./registerCustomTheme-BBXUCRnG.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-elkjs-BRwcR927.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-_6j2xOWl.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DkQX2EBa.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-zod-BLfBSgBh.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const ct=t=>{const e=t.target;if(!(e instanceof Element))return null;const n=e.closest("a[href]");return!(n instanceof HTMLAnchorElement)||n.getAttribute("data-openchamber-file-link")==="true"?null:n},Se=(t,e)=>{if(t.defaultPrevented)return!1;const r=ct(t)?.getAttribute("href")??"";return $t(r)?(t.preventDefault(),t.stopPropagation(),e?.(r),!0):!1},mn=t=>t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey,un=(t,e)=>{const n=o=>{if(Se(o,e.openAppLink)||!e.allowExternalHttp||o.defaultPrevented||!mn(o))return;const s=ct(o)?.getAttribute("href")??"";nt(s)&&(o.preventDefault(),o.stopPropagation(),e.openExternalHttp(s))},r=o=>{o.button===1&&Se(o,e.openAppLink)},i=o=>{Se(o)};return t.addEventListener("click",n),t.addEventListener("auxclick",r),t.addEventListener("dragstart",i),()=>{t.removeEventListener("click",n),t.removeEventListener("auxclick",r),t.removeEventListener("dragstart",i)}},dt="openchamber-md",pn={name:dt,colors:{"editor.background":"transparent","editor.foreground":"var(--md-syntax-foreground)"},tokenColors:[{scope:["comment","punctuation.definition.comment","string.comment"],settings:{foreground:"var(--md-syntax-comment)",fontStyle:"italic"}},{scope:["string","punctuation.definition.string","string.template"],settings:{foreground:"var(--md-syntax-string)"}},{scope:["constant.numeric","constant.language","constant.character","constant"],settings:{foreground:"var(--md-syntax-number)"}},{scope:["keyword","storage","storage.type","storage.modifier","keyword.control"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["keyword.operator","punctuation.separator","punctuation.terminator"],settings:{foreground:"var(--md-syntax-operator)"}},{scope:["entity.name.function","support.function","meta.function-call"],settings:{foreground:"var(--md-syntax-function)"}},{scope:["entity.name.type","entity.name.class","support.type","support.class","entity.other.inherited-class"],settings:{foreground:"var(--md-syntax-type)"}},{scope:["variable","variable.other","variable.parameter","meta.definition.variable"],settings:{foreground:"var(--md-syntax-variable)"}},{scope:["variable.other.property","meta.property-name","support.type.property-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["entity.name.tag","punctuation.definition.tag"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["entity.other.attribute-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["markup.bold","punctuation.definition.bold"],settings:{fontStyle:"bold"}},{scope:["markup.italic","punctuation.definition.italic"],settings:{fontStyle:"italic"}},{scope:["markup.heading","markup.heading entity.name"],settings:{foreground:"var(--md-syntax-keyword)",fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted"],settings:{foreground:"var(--md-syntax-deleted)"}},{scope:["invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let De=!1;const fn=()=>{De||(De=!0,dn(dt,()=>Promise.resolve(pn)))},N=t=>Number.isFinite(t)&&t>0,We=t=>{if(t==null)return null;const e=String(t).trim().match(/^([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?)(?:px)?$/);if(!e)return null;const n=Number(e[1]);return N(n)?n:null},Le=(t,e,n)=>Math.min(n,Math.max(e,t)),hn=6,qe=1.25,gn=1.0015,bn=.5,wn=12,$e=3,yn=400,te='[data-markdown="mermaid-block"]',T=t=>t.querySelector(te)!==null,An=t=>[t.x,t.y,t.width,t.height].map(e=>{const n=Number(e.toFixed(hn));return Object.is(n,-0)?"0":String(n)}).join(" "),vn=t=>{const e=t.viewBox?.trim().split(/[\s,]+/).map(i=>Number.parseFloat(i));if(e?.length===4){const[i,o,s,a]=e;if(Number.isFinite(i)&&Number.isFinite(o)&&N(s)&&N(a))return{x:i,y:o,width:s,height:a}}const n=We(t.width),r=We(t.height);return n===null||r===null?null:{x:0,y:0,width:n,height:r}},kn=t=>{let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0).toString(36)},En=t=>{const e=t.renderMode||"unknown",n=t.svgMarkup??"";if(!n){const r=[t.viewBox??"",t.width??"",t.height??""];return r.some(i=>i!=="")?`${e}:bounds:${r.join(":")}`:`${e}:no-svg`}return[e,kn(n)].join(":")},mt=(t,e)=>{if(!N(e.width)||!N(e.height))return t;const n=t.width/t.height,r=e.width/e.height;if(n>r){const o=t.width/r;return{x:t.x,y:t.y-(o-t.height)/2,width:t.width,height:o}}const i=t.height*r;return{x:t.x-(i-t.width)/2,y:t.y,width:i,height:t.height}},Cn=({currentBox:t,viewport:e,delta:n})=>!N(e.width)||!N(e.height)||!N(t.width)||!N(t.height)?t:{x:t.x-n.x/e.width*t.width,y:t.y-n.y/e.height*t.height,width:t.width,height:t.height},Sn=(t,e)=>{const n=e.x-t.x,r=e.y-t.y;return n*n+r*r>$e*$e},Ln=({currentBox:t,contentBox:e,viewport:n,pointer:r,zoomFactor:i,minScale:o,maxScale:s})=>{if(!N(n.width)||!N(n.height)||!N(i)||!N(t.width)||!N(t.height)||!N(e.width)||!N(e.height)||!N(o)||!N(s))return t;const a=Math.min(o,s),l=Math.max(o,s),d=mt(e,n),u=d.width/t.width,p=Le(u*i,a,l),c=d.width/p,f=c/(t.width/t.height),h=Le(r.x/n.width,0,1),b=Le(r.y/n.height,0,1),v=t.x+h*t.width,y=t.y+b*t.height;return{x:v-h*c,y:y-b*f,width:c,height:f}},ge=new WeakMap,Te=new WeakMap,H=new Set,ne=new Set;let B=null,Q=null,Y=null;const Mn=t=>t.querySelector('[data-markdown="mermaid-viewport"]')??t.querySelector('[data-markdown="mermaid"]'),ut=t=>{const e=t.querySelector('[data-markdown="mermaid"] svg'),n=t.querySelector('[data-markdown="mermaid"]');return En({renderMode:t.getAttribute("data-mermaid-render"),svgMarkup:n?.getAttribute("data-md-original-svg")??e?.outerHTML??null,viewBox:e?.getAttribute("viewBox"),width:e?.getAttribute("width"),height:e?.getAttribute("height")})},Z=t=>{const e=t.getBoundingClientRect();return{width:e.width,height:e.height}},Nn=(t,e)=>{const n=e.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}},Rn=t=>t instanceof Element&&!!t.closest('button, a, [role="button"]'),pt=t=>{const e=t.map(n=>Z(n.viewport));t.forEach((n,r)=>{const i=e[r];i&&n.fitToViewport(i)})},ft=()=>{Y!==null||H.size===0||(Y=window.requestAnimationFrame(()=>{Y=null,pt(Array.from(H))}))},_n=()=>{if(B)return B;const t=globalThis.ResizeObserver;return t?(B=new t(e=>{for(const n of e)n.target instanceof HTMLElement&&Te.get(n.target)?.fitToViewport({width:n.contentRect.width,height:n.contentRect.height})}),B):null},Tn=t=>{if(H.has(t))return;const e=H.size===0;H.add(t),Te.set(t.viewport,t),_n()?.observe(t.viewport),e&&window.addEventListener("resize",ft)},Pn=t=>{H.delete(t)&&(B?.unobserve(t.viewport),Te.delete(t.viewport),!(H.size>0)&&(B?.disconnect(),B=null,window.removeEventListener("resize",ft),Y!==null&&(window.cancelAnimationFrame(Y),Y=null)))},xn=t=>{const e=Mn(t),n=t.querySelector('[data-markdown="mermaid"] svg');if(!e||!n)return null;const r=vn({viewBox:n.getAttribute("viewBox"),width:n.getAttribute("width"),height:n.getAttribute("height")});if(!r)return null;let i=r,o=null,s=null,a=null,l=null;const d=m=>{i=m,n.setAttribute("viewBox",An(m)),n.removeAttribute("width"),n.removeAttribute("height")},u=m=>{d(mt(r,m))},p=()=>{u(Z(e))},c=(m,w)=>{d(Ln({currentBox:i,contentBox:r,viewport:Z(e),pointer:m,zoomFactor:w,minScale:bn,maxScale:wn}))},f=()=>{const m=Z(e);c({x:m.width/2,y:m.height/2},qe)},h=()=>{const m=Z(e);c({x:m.width/2,y:m.height/2},1/qe)},b=m=>{!m.ctrlKey&&!m.metaKey||(m.preventDefault(),m.stopPropagation(),c(Nn(m,e),Math.pow(gn,-m.deltaY)))},v=m=>{m.button!==0||Rn(m.target)||(o=m.pointerId,s={x:m.clientX,y:m.clientY},a=s,l!==null&&(window.clearTimeout(l),l=null),t.removeAttribute("data-mermaid-suppress-click"),e.setPointerCapture?.(m.pointerId),t.setAttribute("data-mermaid-panning","true"),m.preventDefault())},y=m=>{if(o!==m.pointerId||!a)return;const w={x:m.clientX,y:m.clientY};d(Cn({currentBox:i,viewport:Z(e),delta:{x:w.x-a.x,y:w.y-a.y}})),a=w,s&&Sn(s,w)&&t.setAttribute("data-mermaid-suppress-click","true"),m.preventDefault()},k=m=>{o===m.pointerId&&(e.releasePointerCapture?.(m.pointerId),o=null,s=null,a=null,t.removeAttribute("data-mermaid-panning"),t.hasAttribute("data-mermaid-suppress-click")&&(l=window.setTimeout(()=>{t.removeAttribute("data-mermaid-suppress-click"),l=null},yn)))};e.addEventListener("wheel",b,{passive:!1}),e.addEventListener("pointerdown",v),e.addEventListener("pointermove",y),e.addEventListener("pointerup",k),e.addEventListener("pointercancel",k);const M={viewport:e,zoomIn:f,zoomOut:h,fit:p,fitToViewport:u,cleanup:()=>{Pn(M),e.removeEventListener("wheel",b),e.removeEventListener("pointerdown",v),e.removeEventListener("pointermove",y),e.removeEventListener("pointerup",k),e.removeEventListener("pointercancel",k),l!==null&&window.clearTimeout(l),t.removeAttribute("data-mermaid-panning"),t.removeAttribute("data-mermaid-suppress-click"),ge.delete(t)}};return M},ht=t=>{for(const[e,n]of t.controllers){const r=ut(e);(!t.container.contains(e)||r!==t.signatures.get(e))&&(n.cleanup(),t.controllers.delete(e),t.signatures.delete(e))}},In=t=>{if(t.disposed)return[];const e=[];for(const n of Array.from(t.container.querySelectorAll(te))){if(t.controllers.has(n)||n.querySelector('[data-markdown="mermaid"] svg')===null)continue;const r=xn(n);r&&(t.controllers.set(n,r),t.signatures.set(n,ut(n)),ge.set(n,r),e.push(r))}return e},gt=()=>{const t=Array.from(ne);ne.clear();const e=[];for(const n of t)n.disposed||(ht(n),e.push(...In(n)));pt(e);for(const n of e)Tn(n)},Fn=()=>{Q===null&&(Q=window.requestAnimationFrame(()=>{Q=null,Q=window.requestAnimationFrame(()=>{Q=null,gt()})}))},On=t=>{t.disposed||(ht(t),ne.add(t),Fn())},Dn=t=>{if(!(t instanceof HTMLElement))return null;const e=ge.get(t);if(e)return e;for(const n of ne)if(n.container.contains(t))return gt(),ge.get(t)??null;return null},Wn=t=>{const e={container:t,controllers:new Map,signatures:new Map,disposed:!1},n=()=>On(e),r=()=>{e.disposed=!0,ne.delete(e);for(const i of e.controllers.values())i.cleanup();e.controllers.clear(),e.signatures.clear()};return n(),{refresh:n,cleanup:r}},qn={copy:"file-copy",check:"check",download:"download",zoomIn:"add",zoomOut:"subtract",fit:"refresh",textWrap:"text-wrap",image:"file-image"},bt="p-1 rounded hover:bg-interactive-hover/60 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--interactive-focus-ring)]",re=(t,e)=>{const n=qn[e],r=t.ownerDocument.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("class","remixicon size-3.5"),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("aria-hidden","true");const i=t.ownerDocument.createElementNS("http://www.w3.org/2000/svg","use");i.setAttribute("href",`#oc-${n}`),r.appendChild(i),t.replaceChildren(r)},$n=t=>{for(const e of Array.from(t.querySelectorAll('[data-openchamber-markdown-image-label="true"]'))){if(e.querySelector("[data-openchamber-markdown-image-label-icon]"))continue;const n=document.createElement("span");n.className="inline-flex shrink-0",n.setAttribute("aria-hidden","true"),n.setAttribute("data-openchamber-markdown-image-label-icon","true"),re(n,"image"),e.prepend(n)}},O=(t,e,n)=>{const r=document.createElement("button");return r.type="button",r.className=bt,r.setAttribute("data-md-action",n),r.setAttribute("title",e),r.setAttribute("aria-label",e),re(r,t),r},wt=(t,e,n)=>{const r=t.querySelector("[data-md-code-body]"),i=t.querySelector("pre"),o=t.querySelector("pre code"),s=t.querySelectorAll("[data-md-code-line-content]"),a=t.querySelector('[data-md-action="toggle-code-wrap"]');t.setAttribute("data-code-wrap",e?"true":"false"),r?.classList.toggle("overflow-x-auto",!e),r?.classList.toggle("overflow-x-hidden",e),i?.classList.toggle("whitespace-pre-wrap",e),i?.classList.toggle("break-words",e),o?.classList.toggle("whitespace-pre-wrap",e),o?.classList.toggle("break-words",e),i&&(i.style.whiteSpace=e?"pre-wrap":"pre",i.style.overflowWrap=e?"anywhere":"normal"),o&&(o.style.whiteSpace=e?"pre-wrap":"pre",o.style.overflowWrap=e?"anywhere":"normal");for(const l of Array.from(s))l.style.whiteSpace=e?"pre-wrap":"pre",l.style.overflowWrap=e?"anywhere":"normal";if(a){const l=e?n.disableCodeWrap:n.enableCodeWrap;a.setAttribute("title",l),a.setAttribute("aria-label",l),a.classList.toggle("text-foreground",e),a.classList.toggle("opacity-100",e),a.classList.toggle("text-muted-foreground",!e),a.classList.toggle("opacity-65",!e),a.setAttribute("aria-pressed",e?"true":"false")}},yt=t=>{const e=t.querySelector(":scope > code");if(!e||e.hasAttribute("data-md-code-lines"))return;t.removeAttribute("data-md-gutter-reserved");const n=e.textContent??"",r=n.endsWith(`
2
- `),i=r?n.slice(0,-1).split(`
3
- `):n.split(`
4
- `),o=i.length>0?i:[""],s=Array.from(e.children).filter(d=>d.classList.contains("line"));r&&s.length===o.length+1&&s.at(-1)?.textContent===""&&s.pop();const a=s.length===o.length,l=document.createDocumentFragment();o.forEach((d,u)=>{const p=document.createElement("span");p.setAttribute("data-md-code-line","");const c=document.createElement("span");c.setAttribute("data-md-code-line-number",""),c.setAttribute("aria-hidden","true"),c.textContent=String(u+1);const f=document.createElement("span");if(f.setAttribute("data-md-code-line-content",""),a){const h=s[u];h&&f.append(...Array.from(h.childNodes))}else f.textContent=d;if(p.append(c,f),l.appendChild(p),u<o.length-1||r){const h=document.createElement("span");h.setAttribute("data-md-code-line-break",""),h.textContent=`
5
- `,l.appendChild(h)}}),e.replaceChildren(l),e.setAttribute("data-md-code-lines",""),e.toggleAttribute("data-md-code-trailing-newline",r)},At=t=>{const e=Array.from(t.querySelectorAll("[data-md-code-line-content]"));if(e.length===0)return t.textContent??"";const n=e.map(r=>r.textContent??"").join(`
6
- `);return t.hasAttribute("data-md-code-trailing-newline")?`${n}
7
- `:n},ze=(t,e,n)=>{const r=t.querySelectorAll('[data-component="markdown-code"]');for(const i of Array.from(r)){const o=i.querySelector("pre");o&&yt(o),wt(i,e,n)}},Be=(t,e,n,r)=>{re(t,"check"),t.setAttribute("title",e),t.setAttribute("aria-label",e),window.setTimeout(()=>{re(t,n),t.setAttribute("title",r),t.setAttribute("aria-label",r)},2e3)},zn=t=>{const e=t.querySelectorAll(":not(pre) > code");for(const n of Array.from(e))n.getAttribute("data-markdown")!=="inline-code"&&n.setAttribute("data-markdown","inline-code")},Bn=(t,e)=>{const n=t.querySelectorAll("pre");for(const r of Array.from(n)){if(r.querySelector("code.language-mermaid"))continue;const i=r.parentElement;if(!i||i.closest('[data-component="markdown-code"]'))continue;const o=r.querySelector("code")?.className.match(/language-([\w+#.-]+)/)?.[1],s=r.getAttribute("data-md-lang")??o??"text",a=document.createElement("div");a.setAttribute("data-component","markdown-code"),a.className="my-4 group overflow-hidden rounded-2xl border border-border/80 bg-[var(--surface-elevated)]";const l=document.createElement("div");l.className="flex items-center justify-between border-b border-border/70 px-3 py-1.5";const d=document.createElement("span");d.className="font-mono text-[13px] text-muted-foreground",d.textContent=s;const u=O("copy",e.labels.copy,"copy-code"),p=O("textWrap",e.codeBlockLineWrap?e.labels.disableCodeWrap:e.labels.enableCodeWrap,"toggle-code-wrap");l.appendChild(d);const c=document.createElement("div");c.className="flex items-center gap-1",c.setAttribute("data-md-code-actions",""),c.appendChild(p),c.appendChild(u),l.appendChild(c);const f=document.createElement("div");f.setAttribute("data-md-code-body",""),f.className="px-3 py-2.5 overflow-x-auto",i.replaceChild(a,r),r.style.margin="0",r.style.background="transparent",r.classList.add("min-w-0","w-full","flex-1"),e.deferCodeLineNumberSync?r.setAttribute("data-md-gutter-reserved",""):yt(r),f.appendChild(r),a.appendChild(l),a.appendChild(f),wt(a,e.codeBlockLineWrap,e.labels)}},He=t=>{const e=[],n=[],r=t.querySelectorAll("thead th");for(const o of Array.from(r))e.push((o.textContent??"").trim());const i=t.querySelectorAll("tbody tr");for(const o of Array.from(i)){const s=Array.from(o.querySelectorAll("td")).map(a=>(a.textContent??"").trim());s.length>0&&n.push(s)}return{headers:e,rows:n}},Hn=t=>/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t,Ve=({headers:t,rows:e})=>[t,...e].map(n=>n.map(Hn).join(",")).join(`
8
- `),Vn=({headers:t,rows:e})=>[t,...e].map(n=>n.join(" ")).join(`
9
- `),Ke=({headers:t,rows:e})=>{const n=`| ${t.join(" | ")} |`,r=`| ${t.map(()=>"---").join(" | ")} |`,i=e.map(o=>`| ${o.join(" | ")} |`).join(`
10
- `);return`${n}
11
- ${r}
12
- ${i}`},je=(t,e)=>{const n=document.createElement("div");n.className=`absolute top-full right-0 mt-1 hidden ${Ht}`,n.style.backgroundColor="var(--surface-elevated)",n.style.color="var(--surface-elevated-foreground)",n.setAttribute("data-md-menu",t);for(const r of e){const i=document.createElement("button");i.type="button",i.className=`w-full text-left ${Vt}`,i.setAttribute("data-md-action",`${t}-${r.key}`),i.textContent=r.label,n.appendChild(i)}return n},Kn=(t,e)=>{const n=t.querySelectorAll("table");for(const r of Array.from(n)){if(r.closest('[data-markdown="table-wrapper"]'))continue;const o=document.createElement("div");o.className="group my-4 flex flex-col space-y-2",o.setAttribute("data-markdown","table-wrapper");const s=document.createElement("div");s.className="flex items-center justify-end gap-1";const a=document.createElement("div");a.className="relative",a.appendChild(O("copy",e.copyTable,"table-copy-toggle")),a.appendChild(je("table-copy",[{key:"csv",label:"CSV"},{key:"tsv",label:"TSV"},{key:"markdown",label:"Markdown"}]));const l=document.createElement("div");l.className="relative",l.appendChild(O("download",e.downloadTable,"table-download-toggle")),l.appendChild(je("table-download",[{key:"csv",label:"CSV"},{key:"markdown",label:"Markdown"}])),s.appendChild(a),s.appendChild(l);const d=document.createElement("div");d.className="overflow-x-auto rounded-lg border border-border/80 bg-[var(--surface-elevated)]";const u=r.parentElement;if(!u)continue;u.replaceChild(o,r),r.setAttribute("data-markdown","table"),r.classList.add("w-full","border-collapse","text-sm");for(const c of Array.from(r.querySelectorAll("tr")))c.classList.add("border-b","border-border/60");const p=r.querySelector("tbody tr:last-child");p?.classList.remove("border-b"),p?.classList.add("border-0");for(const c of Array.from(r.querySelectorAll("th")))c.classList.add("border-r","border-border/60","px-4","py-2.5","text-left","align-middle","font-semibold","text-foreground","last:border-r-0");for(const c of Array.from(r.querySelectorAll("td")))c.classList.add("border-r","border-border/60","px-4","py-2.5","align-middle","text-foreground/90","last:border-r-0");d.appendChild(r),o.appendChild(s),o.appendChild(d)}},jn=(t,e)=>{const n=t.querySelectorAll("pre > code.language-mermaid");for(const r of Array.from(n)){const i=r.parentElement;if(!i)continue;const o=(r.textContent??"").replace(/\s+$/,""),s=e.renderMermaid(o),a=document.createElement("div");a.setAttribute("data-markdown","mermaid-block"),a.setAttribute("data-md-source",o),a.className="group relative";const l=document.createElement("div");l.setAttribute("data-markdown","mermaid-scroll");const d=document.createElement("div");if(d.setAttribute("data-markdown","mermaid-toolbar"),d.className="absolute top-1 right-2 flex items-center gap-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity",s.svg){a.setAttribute("data-mermaid-render","svg");const p=document.createElement("div");p.setAttribute("data-markdown","mermaid-viewport");const c=document.createElement("div");if(c.setAttribute("data-markdown","mermaid"),c.setAttribute("data-md-original-svg",s.svg),c.innerHTML=s.svg,p.appendChild(c),l.appendChild(p),e.mermaidControls.showPanZoomControls&&(d.appendChild(O("zoomIn",e.labels.zoomInDiagram,"mermaid-zoom-in")),d.appendChild(O("zoomOut",e.labels.zoomOutDiagram,"mermaid-zoom-out")),d.appendChild(O("fit",e.labels.resetDiagramView,"mermaid-fit"))),e.mermaidControls.copy){const f=O("copy",e.labels.copyDiagram,"mermaid-copy");f.setAttribute("data-md-source",o),d.appendChild(f)}if(e.mermaidControls.download){const f=O("download",e.labels.downloadDiagram,"mermaid-download");f.setAttribute("data-md-svg","1"),d.appendChild(f)}}else{a.setAttribute("data-mermaid-render","ascii");const p=document.createElement("pre");if(p.setAttribute("data-markdown","mermaid-ascii"),p.textContent=s.ascii||o,l.appendChild(p),e.mermaidControls.copy){const c=O("copy",e.labels.copyDiagram,"mermaid-copy");c.setAttribute("data-md-source",s.ascii||o),d.appendChild(c)}}a.appendChild(l),a.appendChild(d);const u=i.parentElement;u&&u.replaceChild(a,i)}},Un=(t,e)=>{const n=t.querySelectorAll("a[href]");for(const r of Array.from(n)){if(r.getAttribute("data-md-link-decorated")==="true"||r.getAttribute("data-openchamber-file-link")==="true")continue;const i=r.getAttribute("href")??"";if(!nt(i))continue;r.setAttribute("data-md-link-decorated","true");const o=zt(i);if(o){const s=document.createElement("span");s.className="mr-1 inline-flex size-[18px] items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)] align-middle";const a=document.createElement("img");a.src=o,a.alt="",a.setAttribute("aria-hidden","true"),a.loading="lazy",a.decoding="async",a.className="size-3.5 rounded-sm",a.addEventListener("error",()=>s.remove(),{once:!0}),s.appendChild(a),r.parentNode?.insertBefore(s,r)}if(e.onPreviewLoopback&&Bt(i)){const s=document.createElement("button");s.type="button",s.className=`ml-1 align-middle ${bt}`,s.setAttribute("data-md-action","preview-loopback"),s.setAttribute("data-md-url",i),s.setAttribute("title",e.labels.previewTitle),s.setAttribute("aria-label",e.labels.previewLabel),re(s,"download"),r.parentNode?.insertBefore(s,r.nextSibling)}}},me=(t,e)=>{$n(t),zn(t),jn(t,e),Bn(t,e),Kn(t,e.labels),Un(t,e)},Ue=(t,e,n)=>{const r=new Blob([e],{type:n}),i=URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download=t,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i)},ue=t=>{for(const e of Array.from(t.querySelectorAll("[data-md-menu]")))e.classList.add("hidden")},Zn=(t,e)=>{const n=r=>{const i=r.target;if(!(i instanceof Element))return;const o=i.closest("[data-md-action]");if(!o){ue(t);return}const s=o.getAttribute("data-md-action")??"";if(s==="copy-code"){const a=o.closest('[data-component="markdown-code"]')?.querySelector("code"),l=a?At(a):"";l&&(o.setAttribute("data-md-copy-pending",""),Ce(l).then(()=>Be(o,e.labels.copied,"copy",e.labels.copy)).finally(()=>o.removeAttribute("data-md-copy-pending")));return}if(s==="toggle-code-wrap"){r.preventDefault(),e.onToggleCodeBlockLineWrap?.();return}if(s==="table-copy-toggle"||s==="table-download-toggle"){r.preventDefault();const a=o.parentElement?.querySelector("[data-md-menu]")??null,l=a?.classList.contains("hidden")??!1;ue(t),a&&l&&a.classList.remove("hidden");return}if(s.startsWith("table-copy-")){const a=s.replace("table-copy-",""),l=o.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(l instanceof HTMLTableElement){const d=He(l),u=a==="csv"?Ve(d):a==="tsv"?Vn(d):Ke(d);Ce(u)}ue(t);return}if(s.startsWith("table-download-")){const a=s.replace("table-download-",""),l=o.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(l instanceof HTMLTableElement){const d=He(l),u=a==="csv"?Ve(d):Ke(d);Ue(a==="csv"?"table.csv":"table.md",u,a==="csv"?"text/csv":"text/markdown")}ue(t);return}if(s==="mermaid-copy"){const a=o.getAttribute("data-md-source")??"";a&&Ce(a).then(()=>Be(o,e.labels.copied,"copy",e.labels.copyDiagram));return}if(s==="mermaid-zoom-in"||s==="mermaid-zoom-out"||s==="mermaid-fit"){r.preventDefault();const a=o.closest('[data-markdown="mermaid-block"]'),l=Dn(a);s==="mermaid-zoom-in"?l?.zoomIn():s==="mermaid-zoom-out"?l?.zoomOut():l?.fit();return}if(s==="mermaid-download"){const a=o.closest('[data-markdown="mermaid-block"]')?.querySelector('[data-markdown="mermaid"]'),l=a?.getAttribute("data-md-original-svg")??a?.innerHTML??"";l&&Ue("diagram.svg",l,"image/svg+xml;charset=utf-8");return}if(s==="preview-loopback"){r.preventDefault();const a=o.getAttribute("data-md-url")??"";a&&e.onPreviewLoopback?.(a);return}};return t.addEventListener("click",n),()=>t.removeEventListener("click",n)},Ze=(t,e,n)=>{let r=0;for(const o of t){const s=r+o.data.length;if(e<s||e===s&&n==="left")return{node:o,offset:Math.max(0,e-r)};r=s}const i=t.at(-1);return i?{node:i,offset:i.data.length}:null},Xn=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Xe=Array.from(Xn).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),vt=t=>Kt(t),Gn=t=>jt(t),Yn=t=>{let e;try{e=new URL(t.trim())}catch{return null}if(e.protocol!=="file:"||e.hostname&&e.hostname!=="localhost")return null;try{const n=decodeURIComponent(e.pathname);return/^\/[A-Za-z]:\//.test(n)?n.slice(1):n.startsWith("/")?n:null}catch{return null}},be=t=>{let e=(t||"").trim();return e?((e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e=e.replace(/[.,;!?]+$/g,""),e.endsWith(")")&&!e.includes("(")&&(e=e.slice(0,-1)),e.endsWith("]")&&!e.includes("[")&&(e=e.slice(0,-1)),e):""},pe=t=>{let e=be(t);if(!e)return"";const n=e.indexOf(";");n>=0&&(e=e.slice(0,n)),e=e.replace(/#.*$/,"");const r=e.match(/^(.*\.[A-Za-z0-9_-]{1,16}):.*$/);r&&(e=r[1]??e);const i=Xe.length>0?e.match(new RegExp(`^(.*(?:/|^)(${Xe})):.*$`,"i")):null;return i&&(e=i[1]??e),be(e)},kt=t=>{const e=be(t);if(!e)return null;const n=e.indexOf(";"),r=n>=0?be(e.slice(0,n)):e;if(!r)return null;const i=r.match(/^(.*?):(\d+)-(\d+)$/);if(i){const l=pe(i[1]??""),d=Number.parseInt(i[2]??"",10),u=Number.parseInt(i[3]??"",10);return!l||!Number.isFinite(d)||!Number.isFinite(u)||u<d?null:{path:l,line:d,endLine:u}}const o=r.match(/^(.*)#L(\d+)(?:C(\d+))?$/i);if(o){const l=pe(o[1]??""),d=Number.parseInt(o[2]??"",10),u=o[3]?Number.parseInt(o[3],10):void 0;return!l||!Number.isFinite(d)?null:{path:l,line:d,column:Number.isFinite(u??Number.NaN)?u:void 0}}const s=r.match(/^(.*?):(\d+)(?::(\d+))?$/);if(s){const l=pe(s[1]??""),d=Number.parseInt(s[2]??"",10),u=s[3]?Number.parseInt(s[3],10):void 0;return!l||!Number.isFinite(d)?null:{path:l,line:d,column:Number.isFinite(u??Number.NaN)?u:void 0}}const a=pe(r);return a?{path:a}:null},Me=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,Jn=4,Qn=1e3,er=200,$=new Map;let fe=0;const Ge=[],tr=()=>lt()?er:Qn,nr=(t,e)=>`${t}\0${e}`,rr=(t,e)=>{const n=vt(t);if(!n)return Promise.resolve(!1);const r=nr(e,n),i=$.get(r);if(i)return $.delete(r),$.set(r,i),i;const o=new Promise(a=>{const l=()=>{fe+=1,en(`/api/fs/stat?path=${encodeURIComponent(n)}&optional=true`,{method:"GET",cache:"no-store",headers:e?{"x-opencode-directory":e}:void 0}).then(async d=>{if(!d.ok){a(!1);return}const u=await d.json().catch(()=>null);a(u?.exists!==!1)}).catch(()=>a(!1)).finally(()=>{fe=Math.max(0,fe-1),Ge.shift()?.()})};if(fe<Jn){l();return}Ge.push(l)}),s=tr();for(;$.size>=s;){const a=$.keys().next().value;if(typeof a!="string")break;$.delete(a)}return $.set(r,o),o},or={maxSessions:8,maxEntriesPerSession:4};class ir{maxSessions;maxEntriesPerSession;sessions=new Map;constructor(e=or){this.maxSessions=Math.max(1,e.maxSessions),this.maxEntriesPerSession=Math.max(1,e.maxEntriesPerSession)}store(e){const n=e.scope,r=e.id;let i=this.sessions.get(n);for(i===void 0?(i=new Map,this.sessions.set(n,i)):this.refreshSession(n,i),i.delete(r),i.set(r,e);i.size>this.maxEntriesPerSession;)this.removeOldestEntry(i);for(;this.sessions.size>this.maxSessions;)this.removeOldestSession()}take(e){const n=e.scope,r=this.sessions.get(n);if(!r)return null;const i=e.id;this.refreshSession(n,r);const o=r.get(i);return o===void 0||o.locale!==e.locale||o.directory!==e.directory?null:(r.delete(i),r.size===0&&this.sessions.delete(n),o.fragment)}clear(){this.sessions.clear()}stats(){let e=0;for(const n of this.sessions.values())e+=n.size;return{sessions:this.sessions.size,entries:e}}refreshSession(e,n){this.sessions.delete(e),this.sessions.set(e,n)}removeOldestEntry(e){const n=e.keys().next().value;n!==void 0&&e.delete(n)}removeOldestSession(){const e=this.sessions.keys().next().value;e!==void 0&&this.sessions.delete(e)}}const Ye=new ir,Et=()=>{const t=oe.c(4),e=Ut();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=Oe(!1),t[0]=n):n=t[0];const r=n;let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=Oe(!0),t[1]=i):i=t[1];const o=i;let s;return t[2]!==e?.currentTheme?(s=e?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?o:r),t[2]=e?.currentTheme,t[3]=s):s=t[3],s},Ct=t=>{const e=oe.c(4),{containerRef:n,enabled:r}=t;let i,o;e[0]!==n||e[1]!==r?(i=()=>{const s=n.current;if(s)return un(s,{allowExternalHttp:r!==!1,openAppLink:Cr,openExternalHttp:Sr})},o=[n,r],e[0]=n,e[1]=r,e[2]=i,e[3]=o):(i=e[2],o=e[3]),C.useEffect(i,o)},J={download:!0,copy:!0,showPanZoomControls:!0},St=!0,sr=t=>{const e=t.match(/^(?:\uFEFF)?(---|\+\+\+)[^\S\r\n]*\r?\n[\s\S]*?\r?\n\1[^\S\r\n]*(?:\r?\n|$)/);return e?t.slice(e[0].length):t},Je='[data-openchamber-file-link="true"]',Lt="data-openchamber-block-path-token",Mt=`[${Lt}]`,G="data-openchamber-block-paths-scanned",ar=2e5,lr=80,cr=40,Qe=160,dr=()=>lt()?cr:lr,mr=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Nt=t=>vt(t),ur=t=>Gn(t),pr=(t,e)=>Gt(t,e),fr=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},Rt=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=Nt(t),n=e.split("/").filter(Boolean).pop()??e;if(!n||n==="."||n==="..")return!1;const r=n.toLowerCase();return mr.has(r)||r.startsWith(".")&&r.length>1?!0:fr(e)},_t=t=>{const e=kt(t);return e?Rt(e.path):!1},hr=t=>{const e=t.querySelectorAll(Mt);for(const r of Array.from(e))r.replaceWith(t.ownerDocument.createTextNode(r.textContent??""));const n=t.querySelectorAll(`code[${G}]`);for(const r of Array.from(n))r.removeAttribute(G),r.normalize()},Ne=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim(),n=e?Yn(e):null;if(n)return n;if(e&&_t(e))return e}return(t.textContent||"").trim()},gr=t=>{const e=t.querySelectorAll("pre code");if(e.length===0)return;const n=t.ownerDocument;if(n)for(const r of Array.from(e)){if(r.getAttribute(G)==="true")continue;if((r.textContent??"").length>ar){r.setAttribute(G,"true");continue}const i=n.createTreeWalker(r,NodeFilter.SHOW_TEXT),o=[];let s=i.nextNode();for(;s;){const u=s;u.parentElement?.closest("[data-md-code-line-number]")||o.push(u),s=i.nextNode()}const a=At(r);if(!a.includes(".")){r.setAttribute(G,"true");continue}Me.lastIndex=0;const l=[];let d=Me.exec(a);for(;d;){const u=d[0];u&&_t(u)&&l.push({start:d.index,end:d.index+u.length,raw:u}),d=Me.exec(a)}for(const{start:u,end:p,raw:c}of l.reverse()){const f=Ze(o,u,"right"),h=Ze(o,p,"left");if(!f||!h)continue;const b=n.createRange();b.setStart(f.node,f.offset),b.setEnd(h.node,h.offset);const v=n.createElement("span");v.setAttribute(Lt,"true"),v.textContent=c,b.deleteContents(),b.insertNode(v)}r.setAttribute(G,"true")}},Re=(t,e)=>{const n=kt(t);if(!n||!Rt(n.path))return null;const r=ur(n.path)?Nt(n.path):pr(e,n.path);return r?{...n,resolvedPath:r}:null},br=(t,e)=>t||Xt(t,e),Tt=({containerRef:t,effectiveDirectory:e,editor:n,preferRuntimeEditor:r,enabled:i})=>{const o=C.useRef(null);C.useEffect(()=>{const s=t.current;if(!s||i&&!e)return;let a=!1;const l=dr(),d=i&&!sn(),u=m=>{m.removeAttribute("data-openchamber-file-link"),m.removeAttribute("data-openchamber-file-ref"),m.removeAttribute("data-openchamber-file-path"),m.getAttribute("title")==="Open file"&&m.removeAttribute("title"),m.tagName.toLowerCase()!=="a"&&(m.removeAttribute("role"),m.removeAttribute("tabindex"))},p=()=>{const m=s.querySelectorAll(Je);for(const w of Array.from(m))u(w);hr(s)};if(!d){p();return}const c=(m=0)=>{if(o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),typeof window>"u"){f();return}o.current=window.setTimeout(()=>{o.current=null,window.requestAnimationFrame(()=>{a||f()})},m)},f=()=>{k+=1;try{h()}finally{queueMicrotask(()=>{k-=1})}},h=()=>{d&&gr(s);const m=s.querySelectorAll(`[data-markdown="inline-code"], a, ${Mt}`);let w=0;for(const g of Array.from(m)){const A=Ne(g),S=Re(A,e);if(u(g),!S||w>=l)continue;w+=1,(rn()&&on()&&!Fe(S.resolvedPath,e)?Promise.resolve(!0):rr(S.resolvedPath,e)).then(_=>{if(a||!_||!s.contains(g))return;const L=Ne(g),E=Re(L,e);!E||E.resolvedPath!==S.resolvedPath||(g.setAttribute("data-openchamber-file-link","true"),g.setAttribute("data-openchamber-file-ref",L),g.setAttribute("data-openchamber-file-path",E.resolvedPath),g.setAttribute("title","Open file"),g.tagName.toLowerCase()!=="a"&&(g.setAttribute("role","button"),g.setAttribute("tabindex","0")))})}},b=async m=>{const w=m.getAttribute("data-openchamber-file-ref")||Ne(m),g=Re(w,e);if(!g)return;const A=br(e,g.resolvedPath);if(r&&n){n.openFile(g.resolvedPath,Number.isFinite(g.line??Number.NaN)?Math.max(1,Math.trunc(g.line)):void 0,Number.isFinite(g.column??Number.NaN)?Math.max(1,Math.trunc(g.column)):void 0);return}Fe(g.resolvedPath,e)||await Zt(g.resolvedPath,e);const S=X.getState();Number.isFinite(g.line??Number.NaN)?S.openContextFileAtLine(A,g.resolvedPath,Math.max(1,Math.trunc(g.line)),Number.isFinite(g.column??Number.NaN)?Math.max(1,Math.trunc(g.column)):1):S.openContextFile(A,g.resolvedPath)},v=m=>{const w=m.target;if(!(w instanceof Element))return;const g=w.closest(Je);g instanceof HTMLElement&&(m.preventDefault(),m.stopPropagation(),b(g))},y=m=>{if(m.key!=="Enter"&&m.key!==" ")return;const w=m.target;!(w instanceof HTMLElement)||w.getAttribute("data-openchamber-file-link")!=="true"||(m.preventDefault(),m.stopPropagation(),b(w))};c(Qe);let k=0;const M=new MutationObserver(()=>{k>0||c(Qe)});return M.observe(s,{childList:!0,subtree:!0}),s.addEventListener("click",v),s.addEventListener("keydown",y),()=>{a=!0,o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),o.current=null,M.disconnect(),s.removeEventListener("click",v),s.removeEventListener("keydown",y)}},[t,n,e,r,i])},Pt=t=>{const e=oe.c(7),{containerRef:n,onShowPopup:r,enableFullscreen:i,enablePanZoom:o,allowMermaidWheelEvents:s}=t;let a,l;e[0]!==s||e[1]!==n||e[2]!==i||e[3]!==o||e[4]!==r?(a=()=>{const d=n.current;if(!d)return;const u=c=>{if(!i||!r)return;const f=c.target;if(!(f instanceof Element)||f.closest('button, a, [role="button"]'))return;const h=f.closest(te);if(!h)return;if(h instanceof HTMLElement&&h.hasAttribute("data-mermaid-suppress-click")){h.removeAttribute("data-mermaid-suppress-click");return}const v=Array.from(d.querySelectorAll(te)).indexOf(h);if(v<0)return;const y=h instanceof HTMLElement?h.getAttribute("data-md-source"):null;if(!y||y.trim().length===0)return;const k=`Diagram ${v+1}`;r({open:!0,title:k,content:"",metadata:{tool:"mermaid-preview",filename:k},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(y)}`,source:y,filename:k}})},p=c=>{if(s||(c.ctrlKey||c.metaKey)&&o)return;const f=c.target;!(f instanceof Element)||!f.closest(te)||c.stopPropagation()};return d.addEventListener("click",u),d.addEventListener("wheel",p,{capture:!0,passive:!0}),()=>{d.removeEventListener("click",u),d.removeEventListener("wheel",p,!0)}},l=[s,n,i,o,r],e[0]=s,e[1]=n,e[2]=i,e[3]=o,e[4]=r,e[5]=a,e[6]=l):(a=e[5],l=e[6]),C.useEffect(a,l)},z=new Map,wr=100,U="data-md-decoration-id",et=new WeakMap;let tt=0;const yr=2e5,_e=t=>{const e=et.get(t);if(e)return e;const n=`decoration-${tt}`;return tt+=1,et.set(t,n),n},Ar=(t,e)=>{const n=z.get(t);if(n)return z.delete(t),z.set(t,n),n;const r=e();if(z.set(t,r),z.size>wr){const i=z.keys().next().value;i&&z.delete(i)}return r},vr=t=>({bg:t.colors.surface.elevated,fg:t.colors.surface.foreground,line:t.colors.interactive.border,accent:t.colors.primary.base,muted:t.colors.surface.mutedForeground,surface:t.colors.surface.muted,border:t.colors.interactive.border,transparent:!0,font:"system-ui, sans-serif"}),xt=(t,e,n,r=J)=>{const{t:i}=st(),o=C.useMemo(()=>({copy:i("markdownRenderer.code.actions.copyTitle"),copied:i("markdownRenderer.code.actions.copiedTitle"),enableCodeWrap:i("markdownRenderer.code.actions.enableWrapTitle"),disableCodeWrap:i("markdownRenderer.code.actions.disableWrapTitle"),copyTable:i("markdownRenderer.table.actions.copyTitle"),downloadTable:i("markdownRenderer.table.actions.downloadTitle"),copyDiagram:i("markdownRenderer.mermaid.actions.copySourceTitle"),downloadDiagram:i("markdownRenderer.mermaid.actions.downloadSvgTitle"),zoomInDiagram:i("markdownRenderer.mermaid.actions.zoomInTitle"),zoomOutDiagram:i("markdownRenderer.mermaid.actions.zoomOutTitle"),resetDiagramView:i("markdownRenderer.mermaid.actions.resetViewTitle"),previewLabel:i("terminalView.preview.open"),previewTitle:i("terminalView.preview.openTitle")}),[i]),s=X(d=>d.codeBlockLineWrap),a=X(d=>d.setCodeBlockLineWrap),l=C.useCallback(()=>{a(!X.getState().codeBlockLineWrap)},[a]);return C.useMemo(()=>{const d=vr(t),u=X.getState().mermaidRenderingMode,p=t.metadata?.id??"theme";return{labels:o,mermaidControls:r,codeBlockLineWrap:s,deferCodeLineNumberSync:e,onToggleCodeBlockLineWrap:l,renderMermaid:f=>Ar(`${p}:${u}:${f}`,()=>{try{return u==="ascii"?{ascii:Wt(f)}:{svg:qt(f,d)}}catch{return{}}}),onPreviewLoopback:n}},[t,o,r,s,e,l,n])},It=({containerRef:t,text:e,streaming:n,imageMode:r="inline",syntaxVars:i,ctx:o,domCacheKey:s})=>{C.useEffect(()=>{fn()},[]);const a=C.useRef(null),l=C.useRef(0),d=C.useRef(null),u=C.useCallback(()=>{const p=t.current;if(p){if(!a.current){if(!T(p))return;a.current=Wn(p);return}a.current.refresh()}},[t]);C.useLayoutEffect(()=>{l.current+=1,d.current=null},[o,r,n,e]),C.useLayoutEffect(()=>{if(!s)return;const p=t.current,c=p?.querySelector("[data-markdown-content]")??p;if(!c||c.childNodes.length>0)return;const f=Ye.take(s);if(f){c.appendChild(f);const h=_e(o);for(const b of Array.from(c.children))b.setAttribute(U,h);for(const[b,v]of Object.entries(i))c.style.setProperty(b,v);ze(c,o.codeBlockLineWrap,o.labels),d.current={key:s,copiedLabel:o.labels.copied},he("ui.markdown_renderer.dom_cache.hit")}},[t,o,s,i,e.length]),C.useLayoutEffect(()=>{const p=t.current,c=p?.querySelector("[data-markdown-content]")??p;if(c)return()=>{const f=d.current;if(!f||c.childNodes.length===0||T(c)||Array.from(c.children).some(k=>!k.hasAttribute("data-md-id"))||c.querySelector("[data-md-copy-pending]"))return;const h=window.getSelection();if(h?.rangeCount&&!h.isCollapsed&&h.getRangeAt(0).intersectsNode(c))return;const b=c.querySelector("[data-md-menu]:not(.hidden)"),v=Array.from(c.querySelectorAll("[data-md-action]")).some(k=>k.getAttribute("title")===f.copiedLabel);if(b||v)return;const y=document.createDocumentFragment();y.append(...Array.from(c.childNodes)),Ye.store({...f.key,fragment:y}),he("ui.markdown_renderer.dom_cache.capture")}},[t]),C.useLayoutEffect(()=>{const p=t.current,c=p?.querySelector("[data-markdown-content]")??p;if(!c)return;const f=_e(o);if(e&&c.childNodes.length===0){const h=n?null:an(e,r);if(h){let b=!1;for(const v of h){const y=document.createElement("div");y.setAttribute("data-md-block",""),y.style.display="contents",y.innerHTML=v.html,me(y,o),y.setAttribute("data-md-id",v.id),y.setAttribute(U,f),b||=T(y),c.appendChild(y)}b&&u()}else{const b=document.createElement("div");b.setAttribute("data-md-block",""),b.style.display="contents",b.innerHTML=ln(e,r),me(b,o),b.setAttribute(U,f),c.appendChild(b),T(b)&&u()}}else!a.current&&T(c)&&u()},[t,e,n,r,o,u]),C.useEffect(()=>()=>{a.current?.cleanup(),a.current=null},[]),C.useEffect(()=>{const p=t.current;if(!p)return;const c=p.querySelector("[data-markdown-content]")??p;let f=!0;const h=l.current,b=_e(o);return cn(e,n,r).then(v=>{if(!f||l.current!==h)return;const y=Array.from(c.children);let k=0;v.forEach((w,g)=>{let A=y[g],S=!1;if(A||(A=document.createElement("div"),A.setAttribute("data-md-block",""),A.style.display="contents",c.appendChild(A),S=!0),A.getAttribute("data-md-id")===w.id){if(A.getAttribute(U)!==b){const L=T(A);L&&(a.current?.cleanup(),a.current=null);const E=document.createElement("div");E.setAttribute("data-md-block",""),E.style.display="contents",E.innerHTML=w.html,me(E,o),E.setAttribute("data-md-id",w.id),E.setAttribute(U,b),A.replaceWith(E),(L||T(E))&&u()}!a.current&&T(A)&&u();return}const R=document.createElement("div");if(R.innerHTML=w.html,me(R,o),S&&n&&g>0){const L=Math.min(k,4)*55;k+=1;for(const E of Array.from(R.children))E.classList.add("oc-md-block-enter"),L>0&&E instanceof HTMLElement&&E.style.setProperty("--oc-md-enter-delay",`${L}ms`)}const D=T(A),_=T(R);Dt(A,R,{childrenOnly:!0,onBeforeElUpdated:(L,E)=>!L.isEqualNode(E)}),A.setAttribute("data-md-id",w.id),A.setAttribute(U,b),(D||_||T(A))&&u()});const M=T(c);let m=!1;for(let w=y.length-1;w>=v.length;w-=1){const g=y[w];g&&T(g)&&(m=!0),g?.remove()}(m||y.length>v.length&&M)&&u(),d.current=s?{key:s,copiedLabel:o.labels.copied}:null}),()=>{f=!1}},[t,o,s,r,u,n,e]),C.useEffect(()=>{const p=t.current;if(p)return Zn(p,o)},[t,o]),C.useEffect(()=>{const p=t.current,c=p?.querySelector("[data-markdown-content]")??p;if(c)for(const[f,h]of Object.entries(i))c.style.setProperty(f,h)},[t,i]),C.useEffect(()=>{const p=t.current,c=p?.querySelector("[data-markdown-content]")??p;c&&(o.deferCodeLineNumberSync||ze(c,o.codeBlockLineWrap,o.labels))},[t,o.codeBlockLineWrap,o.deferCodeLineNumberSync,o.labels])},Ft=t=>t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",kr=t=>{const e=oe.c(39),{content:n,part:r,messageId:i,isAnimated:o,skipFadeIn:s,className:a,isStreaming:l,disableStreamAnimation:d,variant:u,onShowPopup:p,enableFileReferences:c}=t,f=o===void 0?!0:o,h=s===void 0?!1:s,b=l===void 0?!1:l,v=d===void 0?!1:d,y=u===void 0?"assistant":u,k=c===void 0?!0:c;he("ui.markdown_renderer.render"),b&&he("ui.markdown_renderer.render.streaming"),tn("ui.markdown_renderer.content_len",n.length);const M=Et(),{editor:m,runtime:w}=rt(),g=C.useRef(null),A=ot()??"",S=X(Lr);let R;e[0]!==A||e[1]!==S?(R=F=>{A&&S(A,F)},e[0]=A,e[1]=S,e[2]=R):R=e[2];const D=R,_=b&&!v;let L;e[3]!==p?(L={containerRef:g,onShowPopup:p,enableFullscreen:St,enablePanZoom:J.showPanZoomControls},e[3]=p,e[4]=L):L=e[4],Pt(L);const E=k&&!b;let W;e[5]!==m||e[6]!==A||e[7]!==w.isVSCode||e[8]!==E?(W={containerRef:g,effectiveDirectory:A,editor:m,preferRuntimeEditor:w.isVSCode,enabled:E},e[5]=m,e[6]=A,e[7]=w.isVSCode,e[8]=E,e[9]=W):W=e[9],Tt(W);let P;e[10]===Symbol.for("react.memo_cache_sentinel")?(P={containerRef:g},e[10]=P):P=e[10],Ct(P);let x;e[11]!==M?(x=it(M),e[11]=M,e[12]=x):x=e[12];const I=x,q=xt(M,_,A?D:void 0,J),{locale:we}=st(),ie=y==="assistant"?"label":"inline",ye=r&&(r.type==="text"||r.type==="reasoning")&&r.time?.end!==void 0?r:null;let se;e[13]===Symbol.for("react.memo_cache_sentinel")?(se=nn(),e[13]=se):se=e[13];const Ot=se,Pe=ye?.sessionID,xe=ye?.messageID,Ie=ye?.id;let Ae;e:{if(b||!Pe||!xe||!Ie||n.length===0||n.length>yr){Ae=null;break e}const F=`${Ot}\0${Pe}`,Ee=`${xe}\0${Ie}\0${ie}\0${n.length}`;let de;e[14]!==A||e[15]!==we||e[16]!==F||e[17]!==Ee?(de={scope:F,id:Ee,locale:we,directory:A},e[14]=A,e[15]=we,e[16]=F,e[17]=Ee,e[18]=de):de=e[18],Ae=de}const ve=Ae,ke=`markdown-${r?.id?`part-${r.id}`:`message-${i}`}`;let ae;e[19]!==n||e[20]!==q||e[21]!==ve||e[22]!==ie||e[23]!==_||e[24]!==I?(ae={containerRef:g,text:n,streaming:_,imageMode:ie,syntaxVars:I,ctx:q,domCacheKey:ve},e[19]=n,e[20]=q,e[21]=ve,e[22]=ie,e[23]=_,e[24]=I,e[25]=ae):ae=e[25],It(ae);let V;e[26]!==a?(V=at("break-words w-full min-w-0",a),e[26]=a,e[27]=V):V=e[27];let K;e[28]!==y?(K=Ft(y),e[28]=y,e[29]=K):K=e[29];let j;e[30]!==K?(j=ee.jsx("div",{className:K,"data-markdown-content":!0}),e[30]=K,e[31]=j):j=e[31];let le;e[32]!==V||e[33]!==j?(le=ee.jsx("div",{className:V,ref:g,children:j}),e[32]=V,e[33]=j,e[34]=le):le=e[34];const ce=le;if(f){let F;return e[35]!==ke||e[36]!==ce||e[37]!==h?(F=ee.jsx(Yt,{skipAnimation:h,children:ce},ke),e[35]=ke,e[36]=ce,e[37]=h,e[38]=F):F=e[38],F}return ce},Mi=C.memo(kr,(t,e)=>t.content===e.content&&t.isStreaming===e.isStreaming&&t.disableStreamAnimation===e.disableStreamAnimation&&t.variant===e.variant&&t.isAnimated===e.isAnimated&&t.skipFadeIn===e.skipFadeIn&&t.className===e.className&&t.messageId===e.messageId&&t.onShowPopup===e.onShowPopup&&t.enableFileReferences===e.enableFileReferences&&t.part?.id===e.part?.id),Er=t=>{const e=oe.c(29),{content:n,className:r,variant:i,disableLinkSafety:o,stripFrontmatter:s,onShowPopup:a,mermaidControls:l,allowMermaidWheelEvents:d,enableFileReferences:u}=t,p=i===void 0?"assistant":i,c=s===void 0?!1:s,f=l===void 0?J:l,h=d===void 0?!1:d,b=u===void 0?!0:u,{editor:v,runtime:y}=rt(),k=Et(),M=C.useRef(null),m=ot()??"";let w;e[0]!==n||e[1]!==c?(w=c?sr(n):n,e[0]=n,e[1]=c,e[2]=w):w=e[2];const g=w;let A;e[3]!==h||e[4]!==f.showPanZoomControls||e[5]!==a?(A={containerRef:M,onShowPopup:a,enableFullscreen:St,enablePanZoom:f.showPanZoomControls,allowMermaidWheelEvents:h},e[3]=h,e[4]=f.showPanZoomControls,e[5]=a,e[6]=A):A=e[6],Pt(A);let S;e[7]!==v||e[8]!==m||e[9]!==b||e[10]!==y.isVSCode?(S={containerRef:M,effectiveDirectory:m,editor:v,preferRuntimeEditor:y.isVSCode,enabled:b},e[7]=v,e[8]=m,e[9]=b,e[10]=y.isVSCode,e[11]=S):S=e[11],Tt(S);const R=!o;let D;e[12]!==R?(D={containerRef:M,enabled:R},e[12]=R,e[13]=D):D=e[13],Ct(D);let _;e[14]!==k?(_=it(k),e[14]=k,e[15]=_):_=e[15];const L=_,E=xt(k,!1,void 0,f);let W;e[16]!==E||e[17]!==g||e[18]!==L?(W={containerRef:M,text:g,streaming:!1,syntaxVars:L,ctx:E},e[16]=E,e[17]=g,e[18]=L,e[19]=W):W=e[19],It(W);let P;e[20]!==r?(P=at("break-words w-full min-w-0",r),e[20]=r,e[21]=P):P=e[21];let x;e[22]!==p?(x=Ft(p),e[22]=p,e[23]=x):x=e[23];let I;e[24]!==x?(I=ee.jsx("div",{className:x,"data-markdown-content":!0}),e[24]=x,e[25]=I):I=e[25];let q;return e[26]!==P||e[27]!==I?(q=ee.jsx("div",{className:P,ref:M,children:I}),e[26]=P,e[27]=I,e[28]=q):q=e[28],q},Ni=C.memo(Er,(t,e)=>{const n=t.mermaidControls??J,r=e.mermaidControls??J;return t.content===e.content&&t.variant===e.variant&&t.className===e.className&&t.disableLinkSafety===e.disableLinkSafety&&t.stripFrontmatter===e.stripFrontmatter&&t.onShowPopup===e.onShowPopup&&n.download===r.download&&n.copy===r.copy&&n.showPanZoomControls===r.showPanZoomControls&&t.allowMermaidWheelEvents===e.allowMermaidWheelEvents&&t.enableFileReferences===e.enableFileReferences});function Cr(t){Jt(t)}function Sr(t){Qt(t)}function Lr(t){return t.openContextPreview}export{Mi as MarkdownRenderer,Ni as SimpleMarkdownRenderer};
@@ -1,4 +0,0 @@
1
- import{R as s,j as r}from"./vendor-react-BUCujlKS.js";import{m as st,u as Ie,r as Le,o as it}from"./index-rlLjZUM5.js";import{c as ot,s as at,P as lt,C as ct}from"./shikiHighlight-BgTPSITe.js";import{f as ut,y as _,c3 as mt,ar as dt,b as $e,ad as pt,a9 as ft,V as ht,bj as wt,L as gt,eT as vt,gL as St,l as ze,eV as xt,aj as Ae,f_ as yt,cP as We,eX as bt,eY as jt,m as Ct,gM as Mt,b0 as _e,a4 as re,a5 as ne,aZ as Oe,B as J,I,a6 as se,a$ as Be,aY as Y,g as Tt,bX as Nt,al as kt,bT as Et,gN as Pt}from"./useAppFontEffects-Cll4gnsh.js";import{u as Vt,n as Dt}from"./useInlineCommentController-DFFv0hae.js";import{b as Rt}from"./CodeMirrorCommentWidgets-C2BopIs3.js";import{getResolvedShikiTheme as Ft}from"./appThemeRegistry-BK0dHKa6.js";import{E as It}from"./vendor-codemirror-view-CiLROUVV.js";import{M as Lt}from"./runtimeEndpointReset-BDh7r8BL.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-BLfBSgBh.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-_6j2xOWl.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CpzVNWAv.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DkQX2EBa.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./registerCustomTheme-BBXUCRnG.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const y=m=>{if(!m)return"";const l=m.replace(/\\/g,"/");return l==="/"?"/":l.replace(/\/+$/,"")},ie=(m,l)=>{const a=y(m),t=l.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!a||a==="/"?`/${t}`:`${a}/${t}`},$t=(m,l,a)=>ie(ie(ie(m,".opencode"),"plans"),`${l}-${a}.md`),zt=(m,l)=>`~/.opencode/plans/${m}-${l}.md`,At=(m,l)=>{const a=m.trim();return a.startsWith("~")?a==="~"?l||a:(a.startsWith("~/")||a.startsWith("~\\"))&&l?`${l}${a.slice(1)}`:a:a},Wt=(m,l)=>{const a=y(l.currentDirectory),t=y(l.homeDirectory),w=y(m);return a&&w.startsWith(a+"/")?w.slice(a.length+1):t&&w===t?"~":t&&w.startsWith(t+"/")?`~${w.slice(t.length)}`:w},_t=(m,l,a)=>{const t=y(m.trim());if(!t)return null;const w=a?l.find(g=>g.id===a)??null:null;if(w?.path){const g=y(w.path);if(t===g||t.startsWith(`${g}/`))return{id:w.id,path:w.path}}const P=l.filter(g=>{const N=y(g.path);return t===N||t.startsWith(`${N}/`)}).sort((g,N)=>y(N.path).length-y(g.path).length)[0];return P?{id:P.id,path:P.path}:null},_n=({targetPath:m=null,projectPlanId:l=null,onNavigatedToChat:a})=>{const{t}=ut(),w=_(e=>e.currentSessionId),P=_(e=>e.createSession),g=_(e=>e.initializeNewOpenChamberSession),N=_(e=>e.sendMessage),oe=_(e=>e.setCurrentSession),ae=mt(),L=st(e=>e.homeDirectory),le=dt(e=>e.planModeEnabled),ce=$e(e=>e.projects),ue=$e(e=>e.activeProjectId),me=pt(e=>e.directories),de=ft()??"",pe=Ie(e=>e.setSessionSwitcherOpen),V=ht(),{isMobile:fe}=wt(),{currentTheme:O}=gt(),v=s.useMemo(()=>w?ae.find(e=>e.id===w)??null:null,[w,ae]),j=s.useMemo(()=>{const e=typeof v?.directory=="string"?v.directory:"";return y(e||"")},[v?.directory]),he=s.useMemo(()=>y(de||j),[de,j]),h=s.useMemo(()=>_t(he,ce,ue),[ue,he,ce]),B=s.useMemo(()=>h?me.get(h.path)?.isGitRepo===!0:!1,[h,me]),[k,D]=s.useState(null),[we,ge]=s.useState(!1),[d,C]=s.useState(null),[$,X]=s.useState(null),ve=vt(e=>e.savePlan),Ge=!!d||!!$,Z=s.useMemo(()=>!d||!j||!L?d:Wt(d,{currentDirectory:j,homeDirectory:L}),[d,j,L]),[f,b]=s.useState(""),{isPlaying:G,play:Ue,stop:He}=St(),Ke=ze(e=>e.showMessageTTSButtons),[Se,z]=s.useState(null),q=s.useMemo(()=>Z&&Z.split("/").pop()||t("planView.file.defaultName"),[Z,t]),Q=s.useMemo(()=>f.trim()?xt(f,t("planView.title.default")).title:t("planView.title.default"),[f,t]),U=s.useMemo(()=>Q.trim()||t("planView.title.default"),[Q,t]),[Je,E]=s.useState(!1),[Ye,xe]=s.useState(!1),[H,ye]=s.useState("edit"),A=s.useRef(null),[o,S]=s.useState(null),be=s.useRef(null),Xe=s.useRef(null),je="openchamber:plan:md-viewer-mode";s.useEffect(()=>{try{const e=localStorage.getItem(je);if(!e)return;const i=JSON.parse(e);(i==="preview"||i==="edit")&&ye(i)}catch{}},[]);const Ze=s.useCallback(e=>{ye(e);try{localStorage.setItem(je,JSON.stringify(e))}catch{}},[]),R=s.useRef(!1),M=s.useRef(null),[Ce,F]=s.useState(!1);s.useEffect(()=>{const e=()=>{R.current=!1,M.current=null,F(!1)};return document.addEventListener("mouseup",e),()=>document.removeEventListener("mouseup",e)},[]);const qe=s.useCallback((e,i)=>{const u=e.split(`
2
- `),n=Math.max(1,i.start),c=Math.min(u.length,i.end);return n>c?"":u.slice(n-1,c).join(`
3
- `)},[]),Qe=Vt({source:"plan",fileLabel:q,language:d&&Ae(d)||"markdown",getCodeForRange:e=>qe(f,Dt(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})}),{drafts:Me,commentText:K,setCommentText:Te,editingDraftId:ee,setSelection:Ne,saveComment:ke,cancel:W,reset:Ee,startEdit:Pe,deleteDraft:Ve}=Qe;s.useEffect(()=>{S(null),Ee()},[f,Ee]),s.useEffect(()=>{Ne(o)},[o,Ne]);const De=s.useCallback(()=>{S(null),W()},[W]),Re=s.useCallback((e,i)=>{i&&S(i),ke(e,i??o??void 0),S(null)},[o,ke]);s.useEffect(()=>{if(!o)return;const e=u=>{const n=u.target;n.closest('[data-comment-card="true"]')||n.closest('[data-comment-input="true"]')||n.closest(".oc-block-widget")||n.closest(".cm-gutterElement")||n.closest("[data-sonner-toast]")||n.closest("[data-sonner-toaster]")||K.trim()||(S(null),W())},i=window.setTimeout(()=>{document.addEventListener("click",e)},100);return()=>{window.clearTimeout(i),document.removeEventListener("click",e)}},[W,K,ee,fe,o]);const te=Ie(e=>e.editorFontSize),et=s.useMemo(()=>{const e=d?Ae(d):null,i=!!e&&e!=="markdown",u=[ot(O,i?{syntaxColors:!1,fontSize:te}:{fontSize:te})],n=yt(d||"plan.md");return n&&u.push(n),i&&e&&u.push(at({language:e,themeName:O.metadata.id,theme:Ft(O)})),u.push(It.lineWrapping),u},[O,d,te]);s.useEffect(()=>{if(!le&&!m&&!l){C(null),X(null),b(""),E(!1);return}let e=!1;const i=async n=>{if(V.files?.readFile)return(await V.files.readFile(n))?.content??"";const c=it()?.files;if(c?.readFile)return(await c.readFile(n,{optional:!0}))?.content??"";const p=await Le(`/api/fs/read?path=${encodeURIComponent(n)}&optional=true`,{cache:"no-store"});if(!p.ok)throw new Error(`Failed to read plan file (${p.status})`);return p.text()};return(async()=>{if(C(null),X(null),b(""),z(null),l){if(!h)return;E(!0);try{const n=await Pt(h,l);if(e)return;if(!n){z(t("planView.error.loadFailed"));return}b(n.raw),X(l)}catch(n){if(e)return;z(n instanceof Error?n.message:t("planView.error.loadFailed"))}finally{e||E(!1)}return}if(m){E(!0);try{const n=await i(m);if(e)return;C(m),b(n)}catch{if(e)return;C(null),b("")}finally{e||E(!1)}return}if(!v?.slug||!v?.time?.created||!j){C(null),b("");return}E(!0);try{const n=$t(j,v.time.created,v.slug),c=At(zt(v.time.created,v.slug),L||null);let p=null,x=null;try{x=await i(n),p=n}catch{}if(!p)try{x=await i(c),p=c}catch{}if(e)return;if(!p||x===null){C(null),b("");return}C(p),b(x)}catch{if(e)return;C(null),b("")}finally{e||E(!1)}})(),()=>{e=!0}},[h,L,le,l,V.files,j,v?.slug,v?.time?.created,t,m]),s.useEffect(()=>{if(!d&&!$)return;const e=window.setTimeout(async()=>{z(null);try{if($){if(!h)throw new Error(t("planView.error.writeFailed"));if(!await ve(h,$,f))throw new Error(t("planView.error.writeFailed"));return}if(!d)return;if(V.files?.writeFile){if(!(await V.files.writeFile(d,f))?.success)throw new Error(t("planView.error.writeFailed"))}else{const i=await Le("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:d,content:f})});if(!i.ok)throw new Error(t("planView.error.writePlanFileFailed",{status:i.status}))}}catch(i){z(i instanceof Error?i.message:t("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(e)}},[f,h,$,d,V.files,ve,t]),s.useEffect(()=>()=>{A.current!==null&&window.clearTimeout(A.current)},[]);const Fe=s.useCallback(()=>{pe(!1),a?.()},[a,pe]),tt=s.useCallback(async e=>{if(!h||!k)return;const i=await We(k.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:U}),n=[{synthetic:!0,text:await We(k.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:U,plan_path:d??""})}];ge(!0);try{Fe();let c=null,p=h.path;if(k.target==="worktree"){if(!B)return;const T=await bt(h.path,jt());if(!T?.id)return;c=T.id,p=T.path}else{const T=await P(void 0,h.path,null);if(!T?.id)return;c=T.id,p=T.directory??h.path,g(T.id,ze.getState().agents??[])}if(!c)return;const x=Ct.getState();x.saveSessionModelSelection(c,e.providerID,e.modelID),e.agent.trim()&&(x.saveSessionAgentSelection(c,e.agent),x.saveAgentModelForSession(c,e.agent,e.providerID,e.modelID),x.saveAgentModelVariantForSession(c,e.agent,e.providerID,e.modelID,e.variant||void 0)),oe(c,p);const nt=e.runAsGoal===!0?[`Implement the plan "${U}" end-to-end${d?` (plan file: ${d})`:""}.`,"Re-read that file for full details — it is the source of truth.","",f].join(`
4
- `):null;Mt.getState().setArmed(e.runAsGoal===!0,nt),await N(i,e.providerID,e.modelID,e.agent.trim()||void 0,void 0,void 0,n,e.variant||void 0),D(null)}finally{ge(!1)}},[B,f,P,h,g,k,d,Fe,N,U,oe]),rt=s.useMemo(()=>Rt({drafts:Me,editingDraftId:ee,commentText:K,onTextChange:Te,selection:o,isDragging:Ce,fileLabel:q,newWidgetId:"plan-new-comment-input",mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:Re,onCancel:De,onEdit:e=>{Pe(e),S({start:e.startLine,end:e.endLine})},onDelete:Ve}),[K,Ve,ee,De,Re,Ce,o,Me,q,Te,Pe]);return r.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[r.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("div",{className:"typography-ui-label font-medium truncate",children:Q}),Se?r.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:Se,children:t("planView.error.saveFailed")}):null]}),Ge?r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsxs(_e,{children:[r.jsxs(re,{children:[r.jsx(ne,{asChild:!0,children:r.jsx(Oe,{asChild:!0,children:r.jsx(J,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":t("planView.actions.improvePlanAria"),disabled:!f.trim(),children:r.jsx(I,{name:"loop-right-ai",className:"size-4"})})})}),r.jsx(se,{sideOffset:8,children:t("planView.actions.improve")})]}),r.jsxs(Be,{align:"end",children:[r.jsx(Y,{onClick:()=>D({action:"improve",target:"session"}),children:t("planView.actions.sendToNewSession")}),r.jsx(Y,{onClick:()=>D({action:"improve",target:"worktree"}),disabled:!B,children:t("planView.actions.sendToNewWorktreeSession")})]})]}),r.jsxs(_e,{children:[r.jsxs(re,{children:[r.jsx(ne,{asChild:!0,children:r.jsx(Oe,{asChild:!0,children:r.jsx(J,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":t("planView.actions.implementPlanAria"),disabled:!f.trim(),children:r.jsx(I,{name:"code-ai",className:"size-4"})})})}),r.jsx(se,{sideOffset:8,children:t("planView.actions.implement")})]}),r.jsxs(Be,{align:"end",children:[r.jsx(Y,{onClick:()=>D({action:"implement",target:"session"}),children:t("planView.actions.sendToNewSession")}),r.jsx(Y,{onClick:()=>D({action:"implement",target:"worktree"}),disabled:!B,children:t("planView.actions.sendToNewWorktreeSession")})]})]}),r.jsx(lt,{currentMode:H,onToggle:()=>Ze(H==="preview"?"edit":"preview")}),H==="preview"&&Ke&&r.jsxs(re,{children:[r.jsx(ne,{asChild:!0,children:r.jsx(J,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":t(G?"planView.tts.stopSpeaking":"planView.tts.readAloud"),onClick:()=>{G?He():f.trim()&&Ue(f)},children:G?r.jsx(I,{name:"stop",className:"h-4 w-4 text-[color:var(--status-success)]"}):r.jsx(I,{name:"volume-up",className:"h-4 w-4"})})}),r.jsx(se,{sideOffset:8,children:t(G?"planView.tts.stopSpeaking":"planView.tts.readAloud")})]}),r.jsx(J,{variant:"ghost",size:"sm",onClick:async()=>{(await Tt(f)).ok&&(xe(!0),A.current!==null&&window.clearTimeout(A.current),A.current=window.setTimeout(()=>{xe(!1)},1200))},className:"h-5 w-5 p-0",title:t("planView.actions.copyPlanContents"),"aria-label":t("planView.actions.copyPlanContents"),children:Ye?r.jsx(I,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):r.jsx(I,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),r.jsx(Lt,{open:k!==null,onOpenChange:e=>{!e&&!we&&D(null)},target:k?.target??"session",projectDirectory:h?.path??null,submitting:we,allowRunAsGoal:!0,onConfirm:tt}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:r.jsx(Nt,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Je?r.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:t("planView.state.loading")}):r.jsx("div",{className:"relative h-full",children:r.jsx("div",{className:"h-full",children:H==="preview"?r.jsx("div",{className:"h-full overflow-auto p-3",children:r.jsx(kt,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:t("planView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:t("planView.error.switchToEditMode")})]}),children:r.jsx(Et,{content:f,className:"typography-markdown-body",enableFileReferences:!1})})}):r.jsx("div",{className:"relative h-full",ref:Xe,children:r.jsx(ct,{value:f,onChange:b,readOnly:!1,className:"h-full",extensions:et,onViewReady:e=>{be.current=e},onViewDestroy:()=>{be.current=null},blockWidgets:rt,highlightLines:o?{start:Math.min(o.start,o.end),end:Math.max(o.start,o.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(e,i,u)=>{if(!(u instanceof MouseEvent)||u.button!==0)return!1;u.preventDefault();const n=e.state.doc.lineAt(i.from).number;if(o&&!u.shiftKey&&Math.min(o.start,o.end)===n&&Math.max(o.start,o.end)===n)return S(null),W(),R.current=!1,M.current=null,F(!1),!0;if(fe&&o&&!u.shiftKey){const c=Math.min(o.start,o.end,n),p=Math.max(o.start,o.end,n);return S({start:c,end:p}),R.current=!1,M.current=null,F(!1),!0}if(R.current=!0,M.current=n,F(!0),o&&u.shiftKey){const c=Math.min(o.start,n),p=Math.max(o.end,n);S({start:c,end:p})}else S({start:n,end:n});return!0},mouseover:(e,i,u)=>{if(!(u instanceof MouseEvent)||u.buttons!==1||!R.current||M.current===null)return!1;const n=e.state.doc.lineAt(i.from).number,c=Math.min(M.current,n),p=Math.max(M.current,n);return S({start:c,end:p}),F(!0),!1},mouseup:()=>(R.current=!1,M.current=null,F(!1),!1)}}})})})})})})]})};export{_n as PlanView};