@pi-chamber/web 0.9.0 → 0.9.3

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 (106) hide show
  1. package/README.md +24 -8
  2. package/bin/cli.js +11 -1
  3. package/bin/cli.test.js +18 -0
  4. package/bin/lib/DOCUMENTATION.md +3 -3
  5. package/bin/lib/cli-args.js +7 -3
  6. package/bin/lib/cli-lifecycle.js +3 -0
  7. package/bin/lib/cli-paths.js +28 -6
  8. package/bin/lib/cli-process.js +1 -0
  9. package/bin/lib/cli-tunnel-profiles.js +15 -10
  10. package/bin/lib/commands-connect-url.js +9 -1
  11. package/bin/lib/commands-logs.js +22 -4
  12. package/bin/lib/commands-serve.js +10 -2
  13. package/bin/lib/commands-tunnel.js +14 -0
  14. package/bin/lib/commands-update.js +18 -14
  15. package/bin/lib/commands-update.test.js +2 -1
  16. package/dist/assets/{DiagramEditor-CcbnMl1H.js → DiagramEditor-DuGmiPZ5.js} +1 -1
  17. package/dist/assets/{DiagramView-DTW5jwK3.js → DiagramView-CV-iReyY.js} +1 -1
  18. package/dist/assets/{DiffView-CZyHHAOB.js → DiffView-DVd1MLPB.js} +6 -6
  19. package/dist/assets/{FilesView-BJYLFR3H.js → FilesView-CPnW4I90.js} +1 -1
  20. package/dist/assets/{GitView-Cg_5UU7E.js → GitView-Dj_7hgX_.js} +3 -3
  21. package/dist/assets/JsonTreeView-Cyy0lEZR.js +1 -0
  22. package/dist/assets/{MarkdownRendererImpl-WqBwxlso.js → MarkdownRendererImpl-BXN78Wu_.js} +1 -1
  23. package/dist/assets/{PatchDiff-BRi23N1l.js → PatchDiff-C7dA3U29.js} +1 -1
  24. package/dist/assets/{SessionSwitcherContent-7VAU5pwZ.js → SessionSwitcherContent-dr3g9DR7.js} +1 -1
  25. package/dist/assets/{SessionSwitcherDropdown-BslRtccE.js → SessionSwitcherDropdown-C3zdd82V.js} +2 -2
  26. package/dist/assets/{SessionUnreadDot-1nV0Z2ZA.js → SessionUnreadDot-qeik5qtT.js} +1 -1
  27. package/dist/assets/SettingsView-C57uV1YS.js +2 -0
  28. package/dist/assets/{SettingsWindow-D4jZHl8X.js → SettingsWindow-Bbay2W76.js} +1 -1
  29. package/dist/assets/ToolOutputDialog-CRTiN1CH.js +8 -0
  30. package/dist/assets/{ToolPartDiffPreview-9FLv2fWD.js → ToolPartDiffPreview-CqnNcLPk.js} +1 -1
  31. package/dist/assets/{VirtualizedFileDiff-ywmPBXAG.js → VirtualizedFileDiff-iqwryMNU.js} +3 -3
  32. package/dist/assets/{collapsible-6mCYf7Ky.js → collapsible-szfZ0Syc.js} +1 -1
  33. package/dist/assets/computeVirtualFileMetrics-Bbugxxtp.js +3 -0
  34. package/dist/assets/{contextFileOpenGuard-CKyf-TZ7.js → contextFileOpenGuard-BC3ie230.js} +1 -1
  35. package/dist/assets/{gitStatusPredicates-UsytDMy_.js → gitStatusPredicates-DbThKVSf.js} +1 -1
  36. package/dist/assets/{index-C8NYcA8-.css → index-DNoEeZ2U.css} +1 -1
  37. package/dist/assets/{index-yWgKW2Fx.js → index-KIdiBFJs.js} +4 -4
  38. package/dist/assets/{index-D1IaU-Q7.js → index-v6K3L94m.js} +1 -1
  39. package/dist/assets/{isDiffPlainText-DPCilEx_.js → isDiffPlainText-Dl0RBjPZ.js} +1 -1
  40. package/dist/assets/{isFilePlainText-XdCAgm8R.js → isFilePlainText-CbrmvrM6.js} +1 -1
  41. package/dist/assets/{main-DcAMXRSi.js → main-4PkIvzf4.js} +7 -7
  42. package/dist/assets/{main-DhvLreEl.js → main-DMyWi0qs.js} +2 -2
  43. package/dist/assets/{markdownCore-BF0Dqwm4.js → markdownCore-BD5WkOKU.js} +1 -1
  44. package/dist/assets/{miniChat-DsCx0dsW.js → miniChat-CLMNhna4.js} +2 -2
  45. package/dist/assets/{mobile-C-IN49xX.js → mobile-rWMDwhtQ.js} +2 -2
  46. package/dist/assets/renderElectronMiniChatApp-BRhGNRJ8.js +2 -0
  47. package/dist/assets/{renderMobileApp-xCdVzvyf.js → renderMobileApp-DLy2YoQg.js} +3 -3
  48. package/dist/assets/{runtimeEndpointReset-CT3WShpj.js → runtimeEndpointReset-Z9YtcHxZ.js} +15 -15
  49. package/dist/assets/{runtimeSurface-C_3mcJ01.js → runtimeSurface-CySRuLbN.js} +1 -1
  50. package/dist/assets/{useAppFontEffects-BgK55NDM.js → useAppFontEffects-DfuJVB15.js} +102 -102
  51. package/dist/assets/{useFilesViewSearch-CWx24PZg.js → useFilesViewSearch-BZBHrZ90.js} +1 -1
  52. package/dist/assets/usePushVisibilityBeacon-BxTkEajM.js +10 -0
  53. package/dist/assets/{useSwitcherItems-CrS-F6DY.js → useSwitcherItems-jITqE8PV.js} +1 -1
  54. package/dist/assets/{vendor-codemirror-language-data-BzeePAPn.js → vendor-codemirror-language-data-CDdfwzlS.js} +2 -2
  55. package/dist/assets/{web-components-DAkBDXRk.js → web-components-C9wXMuCp.js} +2 -2
  56. package/dist/index.html +4 -4
  57. package/dist/mini-chat.html +3 -3
  58. package/dist/mobile.html +3 -3
  59. package/package.json +3 -3
  60. package/server/index.js +26 -7
  61. package/server/lib/client-auth/pairing.js +13 -2
  62. package/server/lib/client-auth/remote-clients.js +13 -2
  63. package/server/lib/fs/DOCUMENTATION.md +3 -1
  64. package/server/lib/fs/routes.test.js +74 -0
  65. package/server/lib/git/DOCUMENTATION.md +1 -1
  66. package/server/lib/git/identity-storage.js +10 -1
  67. package/server/lib/package-manager.js +1 -1
  68. package/server/lib/package-manager.test.js +11 -0
  69. package/server/lib/pi/archive-store.js +3 -2
  70. package/server/lib/pi/model-config-store.js +6 -2
  71. package/server/lib/pi/routes.js +46 -3
  72. package/server/lib/pi/routes.test.js +53 -0
  73. package/server/lib/pi/session-daemon/DOCUMENTATION.md +15 -9
  74. package/server/lib/pi/session-daemon/daemon-process.js +48 -13
  75. package/server/lib/pi/session-daemon/ipc-client.js +20 -9
  76. package/server/lib/pi/session-daemon/ipc-client.test.js +88 -0
  77. package/server/lib/pi/session-daemon/ipc-protocol.js +9 -0
  78. package/server/lib/pi/session-daemon/session-daemon.js +353 -66
  79. package/server/lib/pi/session-daemon/session-daemon.test.js +348 -0
  80. package/server/lib/pi/session-daemon/session-lease.js +151 -0
  81. package/server/lib/pi/session-daemon/session-lease.test.js +108 -0
  82. package/server/lib/pi/session-daemon/supervisor.js +244 -54
  83. package/server/lib/pi/session-daemon/supervisor.test.js +202 -6
  84. package/server/lib/pi/session-folders-store.js +20 -2
  85. package/server/lib/pi/session-folders-store.test.js +17 -0
  86. package/server/lib/pi/settings-store.js +3 -2
  87. package/server/lib/pi/snippets-store.js +4 -1
  88. package/server/lib/pi/ui-settings-store.js +130 -24
  89. package/server/lib/pi/ui-settings-store.test.js +58 -7
  90. package/server/lib/server/cross-process-lock.js +112 -0
  91. package/server/lib/server/cross-process-lock.test.js +70 -0
  92. package/server/lib/server/server-profile.js +110 -0
  93. package/server/lib/server/server-profile.test.js +58 -0
  94. package/server/lib/server/tunnel-service.DOCUMENTATION.md +7 -8
  95. package/server/lib/server/tunnel-service.js +8 -1
  96. package/server/lib/stt/config-store.js +3 -2
  97. package/server/lib/terminal/DOCUMENTATION.md +1 -1
  98. package/server/lib/tunnels/DOCUMENTATION.md +38 -18
  99. package/server/lib/ui-auth/ui-auth.js +9 -2
  100. package/server/lib/ui-auth/ui-passkeys.js +9 -1
  101. package/dist/assets/JsonTreeView-GTdKGEdy.js +0 -1
  102. package/dist/assets/SettingsView-UIaAyjTo.js +0 -2
  103. package/dist/assets/ToolOutputDialog-BoeJONiR.js +0 -8
  104. package/dist/assets/computeVirtualFileMetrics-3H6mg13G.js +0 -3
  105. package/dist/assets/renderElectronMiniChatApp-C13HXGZL.js +0 -2
  106. package/dist/assets/usePushVisibilityBeacon-swMQLm-i.js +0 -10
@@ -1,18 +1,18 @@
1
- import{j as n,R as r,b as St}from"./vendor-react-B5Z1Mdn3.js";import{c as te,u as Y,w as Ze,n as ze}from"./index-yWgKW2Fx.js";import{b1 as vt,b2 as Ct,aa as jt,aq as et,b3 as tt,aR as Nt,p as Ne,U as Le,I as q,j as nt,Q as re,t as st,aU as it,aC as Lt,b4 as Dt,b5 as kt,aD as Rt,b6 as Et,b7 as At,b8 as Tt,b9 as Mt,k as It,ba as $t,bb as Pt,E as _t,F as Wt,G as Bt}from"./useAppFontEffects-BgK55NDM.js";import{d as rt,P as Ot,i as Ge,a as He,b as zt,C as Gt}from"./gitStatusPredicates-UsytDMy_.js";import{p as Ht}from"./VirtualizedFileDiff-ywmPBXAG.js";import{v as Ut,g as Vt}from"./contextFileOpenGuard-CKyf-TZ7.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-base-ui-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./runtimeSurface-C_3mcJ01.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BzeePAPn.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./web-components-DAkBDXRk.js";import"./computeVirtualFileMetrics-3H6mg13G.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-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.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"./runtimeEndpointReset-CT3WShpj.js";import"./SessionUnreadDot-1nV0Z2ZA.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";import"./isDiffPlainText-DPCilEx_.js";import"./vendor-diff-C3JhlQdm.js";function Kt(t,s=10){const e=[];let i;for(const l of t.split(`
1
+ import{j as n,R as r,b as St}from"./vendor-react-B5Z1Mdn3.js";import{c as te,u as J,h as Ze,n as ze}from"./index-KIdiBFJs.js";import{b3 as vt,b4 as Ct,am as jt,as as et,b5 as tt,aT as Nt,p as Ne,a4 as Le,I as q,j as nt,a0 as re,t as st,aW as it,aE as Lt,b6 as Dt,b7 as kt,aF as Rt,b8 as Et,b9 as At,ba as Tt,bb as Mt,k as It,bc as $t,bd as Pt,S as _t,U as Wt,V as Bt}from"./useAppFontEffects-DfuJVB15.js";import{d as rt,P as Ot,i as Ge,a as He,b as zt,C as Gt}from"./gitStatusPredicates-DbThKVSf.js";import{p as Ht}from"./VirtualizedFileDiff-iqwryMNU.js";import{v as Ut,g as Vt}from"./contextFileOpenGuard-BC3ie230.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-base-ui-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./runtimeSurface-CySRuLbN.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CDdfwzlS.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./web-components-C9wXMuCp.js";import"./computeVirtualFileMetrics-Bbugxxtp.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-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.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"./runtimeEndpointReset-Z9YtcHxZ.js";import"./SessionUnreadDot-qeik5qtT.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";import"./isDiffPlainText-Dl0RBjPZ.js";import"./vendor-diff-C3JhlQdm.js";function Kt(t,s=10){const e=[];let i;for(const l of t.split(`
2
2
  `)){const p=l.match(vt);if(p!=null){i!=null&&(i.hunkLines.length>0&&(Re(i,s,"trailing"),Ie(i,e)),i=void 0);const u=parseInt(p[3]),b=parseInt(p[1]),h=parseInt(p[4]??"1"),c=parseInt(p[2]??"1");isNaN(u)||isNaN(b)||isNaN(h)||isNaN(c)?e.push(l):i={additionStart:u,deletionStart:b,additionCount:0,deletionCount:0,hunkLines:[],contextLines:[]};continue}if(i==null){e.push(l);continue}if(l.startsWith(" "))i.contextLines.push(l);else if(l!==""){if(i.hunkLines.length>0&&i.contextLines.length>s*2){const u=i.contextLines.length-s*2,b=i.contextLines.slice(-s);Re(i,s,"trailing");const{additionCount:h,deletionCount:c}=i;Ie(i,e),i={additionStart:i.additionStart+h+u,deletionStart:i.deletionStart+c+u,deletionCount:0,additionCount:0,contextLines:b,hunkLines:[]}}Re(i,s,i.hunkLines.length===0?"leading":"before-change"),i.hunkLines.push(l),l.startsWith("+")?i.additionCount+=1:l.startsWith("-")&&(i.deletionCount+=1)}}i!=null&&i.hunkLines.length>0&&(Re(i,s,"trailing"),Ie(i,e));const a=e.join(`
3
3
  `);return t.endsWith(`
4
4
  `)?`${a}
5
- `:a}function Re(t,s,e){if(e==="leading"&&t.contextLines.length>s){const i=t.contextLines.length-s;t.contextLines.splice(0,i),t.additionStart+=i,t.deletionStart+=i}return e==="trailing"&&t.contextLines.length>s&&(t.contextLines.length=s),t.contextLines.length>0&&(t.hunkLines.push(...t.contextLines),t.additionCount+=t.contextLines.length,t.deletionCount+=t.contextLines.length,t.contextLines.length=0),t}function Ie(t,s){s.push(`@@ -${Ue(t.deletionStart,t.deletionCount)} +${Ue(t.additionStart,t.additionCount)} @@`),s.push(...t.hunkLines)}function Ue(t,s){return s===1?`${t}`:`${t},${s}`}const qt=64,Xt=3,de=new Map,Qt=(t,s,e=Xt)=>{const i=`${t}\0${e}\0${s}`,a=de.get(i);if(a)return de.delete(i),de.set(i,a),a;const l=Jt(s),p=l?Ct(Kt(s,e),{oldFile:{name:t,contents:l.before},newFile:{name:t,contents:l.after}})??Ke(t):jt(Yt(t,s))[0]?.files[0]??Ke(t);for(de.set(i,p);de.size>qt;){const u=de.keys().next().value;if(!u)break;de.delete(u)}return p},Yt=(t,s)=>!s.trim()||s.startsWith("diff --git ")||/^--- [^\n]*\r?\n\+\+\+ /m.test(s)?s:`Index: ${t}
5
+ `:a}function Re(t,s,e){if(e==="leading"&&t.contextLines.length>s){const i=t.contextLines.length-s;t.contextLines.splice(0,i),t.additionStart+=i,t.deletionStart+=i}return e==="trailing"&&t.contextLines.length>s&&(t.contextLines.length=s),t.contextLines.length>0&&(t.hunkLines.push(...t.contextLines),t.additionCount+=t.contextLines.length,t.deletionCount+=t.contextLines.length,t.contextLines.length=0),t}function Ie(t,s){s.push(`@@ -${Ue(t.deletionStart,t.deletionCount)} +${Ue(t.additionStart,t.additionCount)} @@`),s.push(...t.hunkLines)}function Ue(t,s){return s===1?`${t}`:`${t},${s}`}const qt=64,Xt=3,de=new Map,Yt=(t,s,e=Xt)=>{const i=`${t}\0${e}\0${s}`,a=de.get(i);if(a)return de.delete(i),de.set(i,a),a;const l=Qt(s),p=l?Ct(Kt(s,e),{oldFile:{name:t,contents:l.before},newFile:{name:t,contents:l.after}})??Ke(t):jt(Jt(t,s))[0]?.files[0]??Ke(t);for(de.set(i,p);de.size>qt;){const u=de.keys().next().value;if(!u)break;de.delete(u)}return p},Jt=(t,s)=>!s.trim()||s.startsWith("diff --git ")||/^--- [^\n]*\r?\n\+\+\+ /m.test(s)?s:`Index: ${t}
6
6
  ===================================================================
7
7
  --- ${t}
8
8
  +++ ${t}
9
- ${s}`,Jt=t=>{if(!t.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(t))return;const s=[...t.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(s.length!==1)return;const e=s[0],i=Number.parseInt(e[1]??"",10),a=Number.parseInt(e[2]??"",10);if(i>1||a>1||!Number.isFinite(i)||!Number.isFinite(a))return;const l=(e.index??0)+e[0].length,p=t.slice(l),u=[],b=[];let h;for(const c of p.split(/\r?\n/)){if(c.startsWith("diff --git ")||c.startsWith("@@ "))break;if(c.startsWith("\\")){if(h==="-"||h===" "){const m=u.at(-1);m&&(m.newline=!1)}if(h==="+"||h===" "){const m=b.at(-1);m&&(m.newline=!1)}continue}if(c.startsWith("-")){u.push({text:c.slice(1),newline:!0}),h="-";continue}if(c.startsWith("+")){b.push({text:c.slice(1),newline:!0}),h="+";continue}c.startsWith(" ")&&(u.push({text:c.slice(1),newline:!0}),b.push({text:c.slice(1),newline:!0}),h=" ")}return{before:Ve(u),after:Ve(b)}},Ve=t=>t.map(s=>s.text+(s.newline?`
10
- `:"")).join(""),Ke=t=>Ht({name:t,contents:""},{name:t,contents:""}),Zt=t=>/^Binary files .+ differ$/m.test(t)||/^GIT binary patch$/m.test(t),Pe=(t,s,e)=>Zt(s)?{original:"",modified:"",isBinary:!0,patch:s,contextMode:e}:{original:"",modified:"",patch:s,fileDiff:Qt(t,s),contextMode:e},ot=(t,s,e)=>{const i=t??0,a=s??0;return!i&&!a?null:n.jsxs("span",{className:te("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",e?.className),children:[i?n.jsxs("span",{style:{color:"var(--status-success)"},children:["+",i]}):null,a?n.jsxs("span",{style:{color:"var(--status-error)"},children:["-",a]}):null]})},en=r.memo(function({changedFiles:s,selectedFile:e,onSelectFile:i}){return s.length===0?null:n.jsx(et,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:n.jsx("ul",{className:"flex flex-col gap-1",children:s.map(a=>{const l=rt(a),p=e===a.path;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>i(a.path),className:te("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",p?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(tt,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),n.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:l.color},title:l.description,"aria-label":l.description,children:l.code}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:a.path,children:a.path}),ot(a.insertions,a.deletions)]})},a.path)})})})}),tn=r.memo(function(){return n.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:n.jsx("div",{className:"typography-meta text-muted-foreground",children:"Content of this file cannot be viewed."})})}),nn=r.memo(function({filePath:s,diff:e,renderSideBySide:i}){const a=e.original.length>0,l=e.modified.length>0,p=i?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",u=i?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";return n.jsx("div",{className:"w-full overflow-auto p-4",style:{contain:"layout"},children:n.jsxs("div",{className:p,children:[a&&n.jsxs("div",{className:u,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:"Original"}),n.jsx("img",{src:e.original,alt:`Original: ${s}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),l&&n.jsxs("div",{className:u,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a?"Modified":"New"}),n.jsx("img",{src:e.modified,alt:`Modified: ${s}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]})]})})}),sn=r.memo(function({filePath:s,diff:e,renderSideBySide:i,wrapLines:a}){const l=r.useMemo(()=>Nt(s)||"text",[s]);return e.isBinary?n.jsx(tn,{}):Ne(s)?n.jsx(nn,{filePath:s,diff:e,renderSideBySide:i}):n.jsx("div",{className:"w-full",style:{contain:"layout"},children:n.jsx(Ot,{original:e.original,modified:e.modified,fileDiff:e.fileDiff,language:l,fileName:s,renderSideBySide:i,wrapLines:a,layout:"inline"})})}),$e=({label:t,icon:s,loading:e,disabled:i,tone:a,onClick:l})=>n.jsx(Le,{variant:"ghost",size:"sm",className:te("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",a==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",a==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]"),disabled:i,title:t,"aria-label":t,onClick:p=>{p.stopPropagation(),l()},children:e?n.jsx(q,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(q,{name:s,className:s==="add"?"size-4":"size-3.5"})}),rn=r.memo(function({filePath:s,staged:e,busyAction:i,disabled:a,onAction:l}){return n.jsx("div",{className:"flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-sm backdrop-blur-md",children:e?n.jsx($e,{label:`Unstage ${s}`,icon:"arrow-go-back",loading:i==="unstage",disabled:a,onClick:()=>l("unstage")}):n.jsxs(n.Fragment,{children:[n.jsx($e,{label:`Revert changes in ${s}`,icon:"arrow-go-back",loading:i==="discard",disabled:a,tone:"failure",onClick:()=>l("discard")}),n.jsx($e,{label:`Stage ${s}`,icon:"add",loading:i==="stage",disabled:a,tone:"success",onClick:()=>l("stage")})]})})}),at=3,on=1e6,an=15e3,qe=500,ln=r.memo(function({directory:s,file:e,layout:i,wrapLines:a,isSelected:l,isExpanded:p,isMounted:u,onSelect:b,onExpandedChange:h,registerSectionRef:c,showOpenInEditorAction:m=!1,isOpeningInEditor:F=!1,onOpenInEditor:k,staged:x=!1,showFileActions:C=!0,loadFullFiles:g=!1,initialDiffData:d=null}){const{git:_}=nt(),R=re(r.useCallback(f=>f.directories.get(s)?.diffCache.get(e.path)??null,[s,e.path])),X=re(f=>f.setDiff),S=re(f=>f.fetchStatus),y=Y(f=>f.setDiffFileLayout),[w,j]=r.useState(0),[A,E]=r.useState(null),[z,N]=r.useState(!1),[I,W]=r.useState(null),[ne,oe]=r.useState(!1),[se,fe]=r.useState(null),[T,$]=r.useState(null),G=r.useRef(null),pe=r.useRef(null),B=r.useMemo(()=>rt(e),[e]),ae=i==="side-by-side",K=g?"full":"patch",U=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,V=r.useMemo(()=>d||(x?T:se||(R?{original:R.original,modified:R.modified,isBinary:R.isBinary,contextMode:"full"}:null)),[R,d,se,x,T]),me=V?.contextMode===K,ve=r.useCallback(f=>{pe.current=f,c(e.path,f)},[e.path,c]),ie=r.useCallback(f=>{h(e.path,f)},[e.path,h]),he=r.useCallback(()=>{b(e.path)},[e.path,b]);r.useEffect(()=>{x?$(null):fe(null),E(null),G.current=null},[U,x]),r.useEffect(()=>{if(!p||!u)return;if(!s||d||V&&me){G.current=null,N(!1);return}const f=`${s}::${e.path}::${x?"staged":"unstaged"}::${U}::${K}::${w}`;if(G.current===f)return;G.current=f,E(null),N(!0);let P=!1;const J=Ze(),xe=g?on:at,ce=Ne(e.path)?_.getGitFileDiff(s,{path:e.path,staged:x}):_.getGitDiff(s,{path:e.path,staged:x,contextLines:xe}),Z=an,be=new Promise((H,O)=>{setTimeout(()=>O(new Error(`Timed out after ${Z}ms`)),Z)});return Promise.race([ce,be]).then(H=>{if(!P){if("diff"in H){const O=Pe(e.path,H.diff,K);x?$(O):fe(O)}else{const O={original:H.original??"",modified:H.modified??"",isBinary:H.isBinary,contextMode:"full"};x?$(O):X(s,e.path,O,J)}N(!1)}}).catch(H=>{if(P)return;const O=H instanceof Error?H.message:String(H);E(O),N(!1)}),()=>{P=!0,G.current===f&&(G.current=null)}},[K,V,me,w,s,e.path,U,_,d,p,u,g,X,x]);const ge=r.useCallback(()=>{ie(!p),he()},[ie,he,p]),le=r.useCallback(async f=>{if(!(!s||I!==null)){W(f);try{f==="stage"?await _.stageGitFile(s,e.path):f==="unstage"?await _.unstageGitFile(s,e.path):await _.revertGitFile(s,e.path,{scope:"working"}),j(P=>P+1),await S(s,_)}catch(P){const J=f==="unstage"?"Failed to unstage changes":f==="stage"?"Failed to stage changes":"Failed to revert changes";st.error(P instanceof Error?P.message:J)}finally{W(P=>P===f?null:P)}}},[s,S,e.path,I,_]);return n.jsxs("div",{ref:ve,className:te("scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0"),children:[n.jsx("div",{className:te("z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80","sticky top-0"),children:n.jsxs("div",{role:"button",tabIndex:0,onClick:ge,onKeyDown:f=>{f.target===f.currentTarget&&(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),ge())},className:te("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",l?"bg-[var(--interactive-selection)]/35":null),children:[n.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),n.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[n.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:p?n.jsx(q,{name:"arrow-down-s",className:"size-4"}):n.jsx(q,{name:"arrow-right-s",className:"size-4"})}),n.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:B.color},title:B.description,"aria-label":B.description,children:B.code}),n.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(tt,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const f=e.path.lastIndexOf("/");if(f===-1)return n.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const P=e.path.slice(0,f),J=e.path.slice(f+1);return n.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[n.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:P}),n.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[n.jsx("span",{className:"text-muted-foreground",children:"/"}),n.jsx("span",{className:"text-foreground",children:J})]})]})})()]})})]}),n.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[ot(e.insertions,e.deletions),m&&k?n.jsx(Le,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:"Open this file in editor at change",onClick:f=>{f.stopPropagation(),k(e.path,V)},disabled:F,children:F?n.jsx(q,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(q,{name:"edit",className:"size-3.5"})}):null,n.jsx(it,{mode:ae?"side-by-side":"unified",onModeChange:f=>{const P=f==="side-by-side"?"side-by-side":"inline";y(e.path,P)},className:"opacity-70"})]})]})}),p&&n.jsxs("div",{className:"relative overflow-hidden bg-background",children:[!u&&!A?n.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,A?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:A}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>j(f=>f+1),children:"Retry"})]}):null,u&&z&&!V&&!A?n.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx(q,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff..."]}):null,u&&V&&!ne&&e.insertions+e.deletions>qe?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:`Large diff (${e.insertions+e.deletions} changed lines)`}),n.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>oe(!0),children:"Render anyway"})]}):null,u&&V&&(ne||e.insertions+e.deletions<=qe)?n.jsxs(n.Fragment,{children:[n.jsx(sn,{filePath:e.path,diff:V,renderSideBySide:ae,wrapLines:a}),C?n.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:n.jsx("div",{className:"pointer-events-auto",children:n.jsx(rn,{filePath:e.path,staged:x,busyAction:I,disabled:I!==null,onAction:le})})}):null]}):null]})]})}),cn=1100,Xe=300,un=t=>t<=6?t:t<=12?6:t<=25?4:2,dn=(t,s)=>Lt(t,s),Qe=(t,s)=>{const e=t.split(`
9
+ ${s}`,Qt=t=>{if(!t.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(t))return;const s=[...t.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(s.length!==1)return;const e=s[0],i=Number.parseInt(e[1]??"",10),a=Number.parseInt(e[2]??"",10);if(i>1||a>1||!Number.isFinite(i)||!Number.isFinite(a))return;const l=(e.index??0)+e[0].length,p=t.slice(l),u=[],b=[];let h;for(const c of p.split(/\r?\n/)){if(c.startsWith("diff --git ")||c.startsWith("@@ "))break;if(c.startsWith("\\")){if(h==="-"||h===" "){const m=u.at(-1);m&&(m.newline=!1)}if(h==="+"||h===" "){const m=b.at(-1);m&&(m.newline=!1)}continue}if(c.startsWith("-")){u.push({text:c.slice(1),newline:!0}),h="-";continue}if(c.startsWith("+")){b.push({text:c.slice(1),newline:!0}),h="+";continue}c.startsWith(" ")&&(u.push({text:c.slice(1),newline:!0}),b.push({text:c.slice(1),newline:!0}),h=" ")}return{before:Ve(u),after:Ve(b)}},Ve=t=>t.map(s=>s.text+(s.newline?`
10
+ `:"")).join(""),Ke=t=>Ht({name:t,contents:""},{name:t,contents:""}),Zt=t=>/^Binary files .+ differ$/m.test(t)||/^GIT binary patch$/m.test(t),Pe=(t,s,e)=>Zt(s)?{original:"",modified:"",isBinary:!0,patch:s,contextMode:e}:{original:"",modified:"",patch:s,fileDiff:Yt(t,s),contextMode:e},ot=(t,s,e)=>{const i=t??0,a=s??0;return!i&&!a?null:n.jsxs("span",{className:te("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",e?.className),children:[i?n.jsxs("span",{style:{color:"var(--status-success)"},children:["+",i]}):null,a?n.jsxs("span",{style:{color:"var(--status-error)"},children:["-",a]}):null]})},en=r.memo(function({changedFiles:s,selectedFile:e,onSelectFile:i}){return s.length===0?null:n.jsx(et,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:n.jsx("ul",{className:"flex flex-col gap-1",children:s.map(a=>{const l=rt(a),p=e===a.path;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>i(a.path),className:te("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",p?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(tt,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),n.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:l.color},title:l.description,"aria-label":l.description,children:l.code}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:a.path,children:a.path}),ot(a.insertions,a.deletions)]})},a.path)})})})}),tn=r.memo(function(){return n.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:n.jsx("div",{className:"typography-meta text-muted-foreground",children:"Content of this file cannot be viewed."})})}),nn=r.memo(function({filePath:s,diff:e,renderSideBySide:i}){const a=e.original.length>0,l=e.modified.length>0,p=i?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",u=i?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";return n.jsx("div",{className:"w-full overflow-auto p-4",style:{contain:"layout"},children:n.jsxs("div",{className:p,children:[a&&n.jsxs("div",{className:u,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:"Original"}),n.jsx("img",{src:e.original,alt:`Original: ${s}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),l&&n.jsxs("div",{className:u,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a?"Modified":"New"}),n.jsx("img",{src:e.modified,alt:`Modified: ${s}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]})]})})}),sn=r.memo(function({filePath:s,diff:e,renderSideBySide:i,wrapLines:a}){const l=r.useMemo(()=>Nt(s)||"text",[s]);return e.isBinary?n.jsx(tn,{}):Ne(s)?n.jsx(nn,{filePath:s,diff:e,renderSideBySide:i}):n.jsx("div",{className:"w-full",style:{contain:"layout"},children:n.jsx(Ot,{original:e.original,modified:e.modified,fileDiff:e.fileDiff,language:l,fileName:s,renderSideBySide:i,wrapLines:a,layout:"inline"})})}),$e=({label:t,icon:s,loading:e,disabled:i,tone:a,onClick:l})=>n.jsx(Le,{variant:"ghost",size:"sm",className:te("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",a==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",a==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]"),disabled:i,title:t,"aria-label":t,onClick:p=>{p.stopPropagation(),l()},children:e?n.jsx(q,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(q,{name:s,className:s==="add"?"size-4":"size-3.5"})}),rn=r.memo(function({filePath:s,staged:e,busyAction:i,disabled:a,onAction:l}){return n.jsx("div",{className:"flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-sm backdrop-blur-md",children:e?n.jsx($e,{label:`Unstage ${s}`,icon:"arrow-go-back",loading:i==="unstage",disabled:a,onClick:()=>l("unstage")}):n.jsxs(n.Fragment,{children:[n.jsx($e,{label:`Revert changes in ${s}`,icon:"arrow-go-back",loading:i==="discard",disabled:a,tone:"failure",onClick:()=>l("discard")}),n.jsx($e,{label:`Stage ${s}`,icon:"add",loading:i==="stage",disabled:a,tone:"success",onClick:()=>l("stage")})]})})}),at=3,on=1e6,an=15e3,qe=500,ln=r.memo(function({directory:s,file:e,layout:i,wrapLines:a,isSelected:l,isExpanded:p,isMounted:u,onSelect:b,onExpandedChange:h,registerSectionRef:c,showOpenInEditorAction:m=!1,isOpeningInEditor:F=!1,onOpenInEditor:k,staged:x=!1,showFileActions:C=!0,loadFullFiles:g=!1,initialDiffData:d=null}){const{git:_}=nt(),R=re(r.useCallback(f=>f.directories.get(s)?.diffCache.get(e.path)??null,[s,e.path])),X=re(f=>f.setDiff),S=re(f=>f.fetchStatus),y=J(f=>f.setDiffFileLayout),[w,j]=r.useState(0),[A,E]=r.useState(null),[z,N]=r.useState(!1),[I,W]=r.useState(null),[ne,oe]=r.useState(!1),[se,fe]=r.useState(null),[T,$]=r.useState(null),G=r.useRef(null),pe=r.useRef(null),B=r.useMemo(()=>rt(e),[e]),ae=i==="side-by-side",K=g?"full":"patch",U=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,V=r.useMemo(()=>d||(x?T:se||(R?{original:R.original,modified:R.modified,isBinary:R.isBinary,contextMode:"full"}:null)),[R,d,se,x,T]),me=V?.contextMode===K,ve=r.useCallback(f=>{pe.current=f,c(e.path,f)},[e.path,c]),ie=r.useCallback(f=>{h(e.path,f)},[e.path,h]),he=r.useCallback(()=>{b(e.path)},[e.path,b]);r.useEffect(()=>{x?$(null):fe(null),E(null),G.current=null},[U,x]),r.useEffect(()=>{if(!p||!u)return;if(!s||d||V&&me){G.current=null,N(!1);return}const f=`${s}::${e.path}::${x?"staged":"unstaged"}::${U}::${K}::${w}`;if(G.current===f)return;G.current=f,E(null),N(!0);let P=!1;const Q=Ze(),xe=g?on:at,ce=Ne(e.path)?_.getGitFileDiff(s,{path:e.path,staged:x}):_.getGitDiff(s,{path:e.path,staged:x,contextLines:xe}),Z=an,be=new Promise((H,O)=>{setTimeout(()=>O(new Error(`Timed out after ${Z}ms`)),Z)});return Promise.race([ce,be]).then(H=>{if(!P){if("diff"in H){const O=Pe(e.path,H.diff,K);x?$(O):fe(O)}else{const O={original:H.original??"",modified:H.modified??"",isBinary:H.isBinary,contextMode:"full"};x?$(O):X(s,e.path,O,Q)}N(!1)}}).catch(H=>{if(P)return;const O=H instanceof Error?H.message:String(H);E(O),N(!1)}),()=>{P=!0,G.current===f&&(G.current=null)}},[K,V,me,w,s,e.path,U,_,d,p,u,g,X,x]);const ge=r.useCallback(()=>{ie(!p),he()},[ie,he,p]),le=r.useCallback(async f=>{if(!(!s||I!==null)){W(f);try{f==="stage"?await _.stageGitFile(s,e.path):f==="unstage"?await _.unstageGitFile(s,e.path):await _.revertGitFile(s,e.path,{scope:"working"}),j(P=>P+1),await S(s,_)}catch(P){const Q=f==="unstage"?"Failed to unstage changes":f==="stage"?"Failed to stage changes":"Failed to revert changes";st.error(P instanceof Error?P.message:Q)}finally{W(P=>P===f?null:P)}}},[s,S,e.path,I,_]);return n.jsxs("div",{ref:ve,className:te("scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0"),children:[n.jsx("div",{className:te("z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80","sticky top-0"),children:n.jsxs("div",{role:"button",tabIndex:0,onClick:ge,onKeyDown:f=>{f.target===f.currentTarget&&(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),ge())},className:te("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",l?"bg-[var(--interactive-selection)]/35":null),children:[n.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),n.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[n.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:p?n.jsx(q,{name:"arrow-down-s",className:"size-4"}):n.jsx(q,{name:"arrow-right-s",className:"size-4"})}),n.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:B.color},title:B.description,"aria-label":B.description,children:B.code}),n.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(tt,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const f=e.path.lastIndexOf("/");if(f===-1)return n.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const P=e.path.slice(0,f),Q=e.path.slice(f+1);return n.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[n.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:P}),n.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[n.jsx("span",{className:"text-muted-foreground",children:"/"}),n.jsx("span",{className:"text-foreground",children:Q})]})]})})()]})})]}),n.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[ot(e.insertions,e.deletions),m&&k?n.jsx(Le,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:"Open this file in editor at change",onClick:f=>{f.stopPropagation(),k(e.path,V)},disabled:F,children:F?n.jsx(q,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(q,{name:"edit",className:"size-3.5"})}):null,n.jsx(it,{mode:ae?"side-by-side":"unified",onModeChange:f=>{const P=f==="side-by-side"?"side-by-side":"inline";y(e.path,P)},className:"opacity-70"})]})]})}),p&&n.jsxs("div",{className:"relative overflow-hidden bg-background",children:[!u&&!A?n.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,A?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:A}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>j(f=>f+1),children:"Retry"})]}):null,u&&z&&!V&&!A?n.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx(q,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff..."]}):null,u&&V&&!ne&&e.insertions+e.deletions>qe?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:`Large diff (${e.insertions+e.deletions} changed lines)`}),n.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>oe(!0),children:"Render anyway"})]}):null,u&&V&&(ne||e.insertions+e.deletions<=qe)?n.jsxs(n.Fragment,{children:[n.jsx(sn,{filePath:e.path,diff:V,renderSideBySide:ae,wrapLines:a}),C?n.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:n.jsx("div",{className:"pointer-events-auto",children:n.jsx(rn,{filePath:e.path,staged:x,busyAction:I,disabled:I!==null,onAction:le})})}):null]}):null]})]})}),cn=1100,Xe=300,un=t=>t<=6?t:t<=12?6:t<=25?4:2,dn=(t,s)=>Lt(t,s),Ye=(t,s)=>{const e=t.split(`
11
11
  `),i=s.split(`
12
12
  `),a=Math.min(e.length,i.length);for(let l=0;l<a;l+=1)if(e[l]!==i[l])return l+1;return i.length>e.length?e.length+1:e.length>i.length?Math.max(1,i.length):1},fn=t=>Array.isArray(t)?t.filter(s=>!s||typeof s!="object"?!1:typeof s.file=="string"):[],pn=t=>t.split(/^diff --git /m).slice(1).flatMap(e=>{const[i=""]=e.split(`
13
13
  `,1),a=i.lastIndexOf(" b/");if(a<=2)return[];const l=i.slice(2,a),p=i.slice(a+3).trim(),u=`diff --git ${e}`,b=u.includes(`
14
14
  new file mode `)?"added":u.includes(`
15
15
  deleted file mode `)?"deleted":u.includes(`
16
16
  rename from `)?"renamed":"modified";let h=0,c=0;for(const m of u.split(`
17
- `))m.startsWith("+")&&!m.startsWith("+++")&&(h+=1),m.startsWith("-")&&!m.startsWith("---")&&(c+=1);return[{file:b==="deleted"?l:p,status:b,additions:h,deletions:c,patch:u}]}),mn=t=>t==="added"?"A":t==="deleted"?"D":"M";function hn({activeDiffScope:t,effectiveDirectory:s,branchBase:e,branchHead:i,git:a,sessionMessageRecords:l}){const[p,u]=r.useState([]),[b,h]=r.useState(null),[c,m]=r.useState(!1),F=r.useMemo(()=>{const C=Dt(l,{showTextJustificationActivity:!1,showTurnChangedFiles:!0,mergeHiddenUserTurns:!0});for(let g=C.turns.length-1;g>=0;g-=1){const d=C.turns[g];if(!d)continue;const _=d.activityParts.map(S=>S.part).filter(S=>S.type==="tool"),R=kt(_);if(R.length>0)return R.map(S=>({file:S.path,status:"modified",additions:S.additions,deletions:S.deletions,patch:S.patch}));const X=fn(d.userMessage.info?.summary?.diffs);if(X.length>0)return X}return[]},[l]);r.useEffect(()=>{if(t!=="branch"||!s||!e||!i||!a.getGitRangeDiff){u([]),h(null),m(!1);return}let C=!1;return m(!0),h(null),a.getGitRangeDiff(s,{base:e,head:i,contextLines:at}).then(g=>{C||(u(pn(g.diff??"")),m(!1))}).catch(g=>{C||(u([]),m(!1),h(g instanceof Error?g.message:String(g)))}),()=>{C=!0}},[t,e,i,s,a]);const k=r.useMemo(()=>{const C=new Map;for(const g of F)if(g.file){if(typeof g.patch=="string"){C.set(g.file,Pe(g.file,g.patch,"patch"));continue}C.set(g.file,{original:g.before??"",modified:g.after??"",contextMode:"full"})}return C},[F]),x=r.useMemo(()=>{const C=new Map;for(const g of p)!g.file||typeof g.patch!="string"||C.set(g.file,Pe(g.file,g.patch,"patch"));return C},[p]);return{branchDiffs:p,branchDiffError:b,branchDiffLoading:c,lastTurnDiffs:F,lastTurnDiffData:k,branchDiffData:x}}const Ye=(t,s)=>{if(s.length===0)return null;let e=null,i=null;for(const l of s)l.top<=t?(!e||l.top>e.top)&&(e=l):(!i||l.top<i.top)&&(i=l);const a=e??i;return a?{path:a.path,topOffset:a.top-t}:null},gn=(t,s,e,i)=>Math.min(Math.max(0,i),Math.max(0,t+e-s));function xn({pinSelectedFileHeaderToTopOnNavigate:t,scrollRequestNonce:s,changedFiles:e,expandedFiles:i,setMountedStackedFiles:a,fileDiffRefreshNonce:l}){const p=r.useRef(null),u=r.useRef(new Map),[b,h]=r.useState(null),c=r.useRef(null),m=r.useRef(null),F=r.useRef(!1),k=r.useRef(null),x=r.useRef(null),C=r.useRef(null),g=r.useCallback(()=>{const y=p.current;if(!y)return null;const w=y.getBoundingClientRect().top,j=[];for(const[A,E]of u.current)E&&j.push({path:A,top:E.getBoundingClientRect().top});return Ye(w,j)},[]),d=r.useCallback(()=>{c.current=null,F.current=!1,h(null),m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null)},[]),_=r.useCallback(()=>{k.current=null;const y=p.current;if(!y)return;const w=y.getBoundingClientRect(),j=w.top-Xe,A=w.bottom+Xe,E={},z=[];for(const[N,I]of u.current){if(!I)continue;const W=I.getBoundingClientRect();z.push({path:N,top:W.top}),i.has(N)&&(W.bottom<j||W.top>A||(E[N]=!0))}x.current=Ye(w.top,z),a(N=>{let I=!1;const W=new Set(N);for(const ne of Object.keys(E))W.has(ne)||(W.add(ne),I=!0);return I?W:N})},[i,a]),R=r.useCallback(()=>{typeof window>"u"||k.current===null&&(k.current=window.requestAnimationFrame(_))},[_]);r.useEffect(()=>{const y=p.current;if(y)return R(),y.addEventListener("scroll",R,{passive:!0}),window.addEventListener("resize",R),()=>{y.removeEventListener("scroll",R),window.removeEventListener("resize",R),k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null)}},[e,i,R]),r.useLayoutEffect(()=>{const y=C.current;if(!y)return;C.current=null;const w=p.current,j=u.current.get(y.path);if(!w||!j)return;const A=w.getBoundingClientRect().top,E=j.getBoundingClientRect().top-A;w.scrollTop=gn(w.scrollTop,y.topOffset,E,w.scrollHeight-w.clientHeight),x.current=y},[l]);const X=r.useCallback((y,w)=>{const j=u.current;w?j.set(y,w):j.delete(y),R()},[R]),S=r.useCallback(y=>{const w=u.current.get(y),j=p.current;if(!w||!j)return!1;const A=w.getBoundingClientRect().top-j.getBoundingClientRect().top;return j.scrollTo({top:j.scrollTop+A,behavior:"auto"}),!0},[]);return r.useEffect(()=>{if(!c.current)return;let w=0;const j=20;let A=!1;const E=(N=!0)=>{A||(A=!0,c.current=null,F.current=!1,N&&h(null),m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null))},z=()=>{if(A){m.current=null;return}const N=c.current;if(!N){E(),m.current=null;return}if(!S(N)){w+=1,w<j?m.current=window.requestAnimationFrame(z):(E(),m.current=null);return}if(t&&F.current){h(N),E(!1);return}E()};return m.current=window.requestAnimationFrame(z),()=>{A=!0,m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null)}},[t,s,S]),{diffScrollRef:p,fileSectionRefs:u,pinnedStackedTarget:b,pendingScrollTargetRef:c,shouldPinAfterAlignRef:F,pendingScrollAnchorRestoreRef:C,lastScrollAnchorRef:x,captureScrollAnchor:g,cancelPendingScrollAlignment:d,queueVisibleStackedFilesSync:R,registerSectionRef:X,scrollToFile:S}}const Je=t=>{if(!t)return null;const s=t.split(`
18
- `);let e=null;for(const i of s){const a=i.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(a){const l=Number.parseInt(a[1]??"",10);e=Number.isFinite(l)&&l>=1?l:null;continue}if(e!==null){if(i.startsWith(" ")){e+=1;continue}if(i.startsWith("+"))return e;if(i.startsWith("-"))return Math.max(1,e)}}return null};function bn({effectiveDirectory:t,activeDiffStaged:s,git:e,files:i,setDiff:a,openContextFileAtLine:l}){const[p,u]=r.useState(null),b=r.useCallback(async(h,c)=>{if(!t||!h)return;u(h);const m=Ze();try{let F=null;if(c?.patch&&!c.isBinary&&!Ne(h)?F=Je(c.patch):c&&c.contextMode==="full"&&!c.isBinary&&!Ne(h)&&(F=Qe(c.original,c.modified)),F===null)try{const d=await e.getGitDiff(t,{path:h,staged:s,contextLines:3});F=Je(d.diff)}catch{F=null}let k=c;if(F===null||!k){const d=await e.getGitFileDiff(t,{path:h,staged:s});k={original:d.original??"",modified:d.modified??"",isBinary:d.isBinary},s||a(t,h,k,m??void 0)}const x=F??(k.isBinary||Ne(h)?1:Qe(k.original,k.modified)),C=dn(t,h),g=await Ut(i,C,{directory:t});if(!g.ok){st.error(Vt(g.reason));return}l(t,C,x,1)}finally{u(F=>F===h?null:F)}},[s,t,i,e,l,a]);return{openingEditorFilePath:p,openFileInEditorAtChange:b}}function yn(t){const{hideStackedFileSidebar:s=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:i=!1,diffScope:a="all",branchBase:l=null,branchHead:p=null,targetFilePath:u=null}=t,{git:b,files:h}=nt(),c=Rt(),{screenWidth:m,isMobile:F}=Et(),k=At(c??null),x=Tt(c??null),C=Mt(c??null),g=re(o=>o.setActiveDirectory),d=re(o=>o.ensureStatus),_=re(o=>o.fetchStatus),R=re(o=>o.clearDiffCache),X=re(o=>o.setDiff),[S,y]=r.useState(null),[w,j]=r.useState(!1),[A,E]=r.useState(()=>new Set),[z,N]=r.useState(()=>new Set),[I,W]=r.useState(!1),[ne,oe]=r.useState(0),[se,fe]=r.useState(()=>new Map),[T,$]=r.useState(a);r.useEffect(()=>{$(a)},[a]);const G=Y(o=>o.pendingDiffFile),pe=Y(o=>o.pendingDiffStaged),B=Y(o=>o.pendingDiffScope),ae=Y(o=>o.setPendingDiffFile),K=Y(o=>o.diffLayoutPreference),U=Y(o=>o.diffFileLayout),V=Y(o=>o.setDiffFileLayout),me=Y(o=>o.diffWrapLines),ve=Y(o=>o.setDiffWrapLines),ie=Y(o=>o.openContextFileAtLine),he=It(o=>o.currentSessionId),ge=$t(he??""),le=me,f=T==="staged"?!0:T==="working"?!1:null,P=f??w,J=F||m<=768,xe=!s&&!J&&m>=1024,ce=r.useRef(null),{branchDiffs:Z,branchDiffError:be,branchDiffLoading:H,lastTurnDiffs:O,lastTurnDiffData:De,branchDiffData:ee}=hn({activeDiffScope:T,effectiveDirectory:c,branchBase:l,branchHead:p,git:b,sessionMessageRecords:ge}),L=r.useMemo(()=>{if(T==="turn"||T==="branch")return(T==="branch"?Z:O).map(M=>({path:M.file??"",index:"",working_dir:mn(M.status),insertions:M.additions??0,deletions:M.deletions??0,isNew:M.status==="added"})).filter(M=>M.path).sort((M,Q)=>M.path.localeCompare(Q.path));if(!x?.files)return[];const o=x.diffStats??{},D=T==="staged"?Ge:T==="working"?He:()=>!0;return x.files.filter(D).map(v=>({...v,insertions:o[v.path]?.insertions??0,deletions:o[v.path]?.deletions??0,isNew:zt(v)})).sort((v,M)=>v.path.localeCompare(M.path))},[T,Z,O,x]),Ee=r.useMemo(()=>x?.files?x.files.filter(He).length:0,[x]),Ae=r.useMemo(()=>x?.files?x.files.filter(Ge).length:0,[x]),lt=O.length,ct=x?.files?.length??0,ut=Z.length,{diffScrollRef:dt,pinnedStackedTarget:ft,pendingScrollTargetRef:ye,shouldPinAfterAlignRef:we,pendingScrollAnchorRestoreRef:_e,lastScrollAnchorRef:We,captureScrollAnchor:Be,cancelPendingScrollAlignment:Fe,queueVisibleStackedFilesSync:ke,registerSectionRef:pt,scrollToFile:Oe}=xn({pinSelectedFileHeaderToTopOnNavigate:i,scrollRequestNonce:ne,changedFiles:L,expandedFiles:A,setMountedStackedFiles:N,fileDiffRefreshNonce:se}),Se=r.useCallback(o=>{E(D=>{if(D.has(o))return D;const v=new Set(D);return v.add(o),v})},[]),Te=r.useMemo(()=>L.map(o=>o.path).join("\0"),[L]);r.useEffect(()=>{const o=Te?Te.split("\0"):[],D=new Set(o),v=`${c??""}:${T}:${e?"collapsed":"default"}`,M=ce.current!==v;ce.current=v,E(Q=>{if(M){const ue=e?0:un(o.length);return new Set(o.slice(0,ue))}let Ce=!1;const je=new Set;for(const ue of Q){if(!D.has(ue)){Ce=!0;continue}je.add(ue)}return Ce?je:Q}),N(Q=>{if(M)return new Set;let Ce=!1;const je=new Set;for(const ue of Q){if(!D.has(ue)){Ce=!0;continue}je.add(ue)}return Ce?je:Q})},[T,Te,c,N,e]);const Me=r.useCallback(o=>{const D=U[o.path];if(D)return D;if(K==="inline")return"inline";if(K==="side-by-side")return"side-by-side";const v=m<cn;return o.isNew||v?"inline":"side-by-side"},[U,K,m]),mt=r.useMemo(()=>L.length===0?null:L.every(o=>Me(o)==="side-by-side")?"side-by-side":"inline",[L,Me]);r.useEffect(()=>{c&&(g(c),d(c,b))},[c,g,d,b]),r.useEffect(()=>{if(c)return Pt.onGitRefreshHint(o=>{ze(o.directory)===ze(c)&&(o.paths?.length&&(_e.current=Be()??We.current,R(c,o.paths),fe(D=>{const v=new Map(D);for(const M of o.paths??[])v.set(M,(v.get(M)??0)+1);return v})),_(c,b,{silent:!0}))})},[Be,R,c,_,b,We,_e]),r.useEffect(()=>{T!=="all"&&!B||G&&(B&&$(B),y(G),j(B==="staged"||!B&&pe),ae(null),we.current=!0,ye.current=G,Se(G),oe(o=>o+1))},[T,Se,G,B,pe,ye,ae,we]),r.useEffect(()=>{if(T==="all")return;const o=u?.trim();o&&(y(o),j(T==="staged"),we.current=!0,ye.current=o,Se(o),oe(D=>D+1))},[T,Se,ye,we,u]),r.useEffect(()=>{if(!S)return;L.some(D=>D.path===S)||(y(null),j(!1))},[L,S]);const ht=r.useCallback((o,D)=>{Fe(),E(v=>{const M=v.has(o);if(D===M)return v;const Q=new Set(v);return D?Q.add(o):Q.delete(o),Q}),D||N(v=>{if(!v.has(o))return v;const M=new Set(v);return M.delete(o),M}),ke()},[Fe,ke,N]),gt=r.useCallback(()=>{Fe(),E(o=>o.size>0?new Set:new Set(L.map(D=>D.path))),N(new Set),ke()},[Fe,L,ke,N]),xt=r.useCallback(o=>{},[]),bt=r.useCallback(o=>{Fe(),y(o),j(!1),we.current=!0,ye.current=o,Se(o),oe(D=>D+1),Oe(o)},[Fe,Se,ye,Oe,we]),yt=r.useCallback(o=>{const D=o==="side-by-side"?"side-by-side":"inline";L.forEach(v=>{V(v.path,D)})},[L,V]),{openingEditorFilePath:wt,openFileInEditorAtChange:Ft}=bn({effectiveDirectory:c,activeDiffStaged:P,git:b,files:h,setDiff:X,openContextFileAtLine:ie});return{git:b,files:h,effectiveDirectory:c,screenWidth:m,isMobile:F,isGitRepo:k,status:x,isLoadingStatus:C,activeDiffScope:T,setActiveDiffScope:$,branchDiffs:Z,branchDiffError:be,branchDiffLoading:H,diffWrapLines:le,setDiffWrapLines:ve,forcedStaged:f,displayFileStaged:w,displayFile:S,pinnedStackedTarget:ft,expandedFiles:A,mountedStackedFiles:z,loadFullFiles:I,setLoadFullFiles:W,fileDiffRefreshNonce:se,showFileSidebar:xe,diffScrollRef:dt,lastTurnDiffData:De,branchDiffData:ee,changedFiles:L,workingFileCount:Ee,stagedFileCount:Ae,turnFileCount:lt,allFileCount:ct,branchFileCount:ut,currentLayoutForAllFiles:mt,openingEditorFilePath:wt,registerSectionRef:pt,handleStackedEntryExpandedChange:ht,handleExpandOrCollapseAll:gt,handleSelectFile:xt,handleSelectFileAndScroll:bt,handleHeaderLayoutChange:yt,openFileInEditorAtChange:Ft,getLayoutForFile:Me}}const Di=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:s=!1,pinSelectedFileHeaderToTopOnNavigate:e=!1,showOpenInEditorAction:i=!1,diffScope:a="all",onDiffScopeChange:l,branchBase:p=null,branchHead:u=null,targetFilePath:b=null,flushContent:h=!1,hideToolbar:c=!1,onHeaderControlsStateChange:m,toolbarSlot:F=null})=>{const{effectiveDirectory:k,isGitRepo:x,status:C,isLoadingStatus:g,activeDiffScope:d,setActiveDiffScope:_,branchDiffError:R,branchDiffLoading:X,diffWrapLines:S,setDiffWrapLines:y,forcedStaged:w,displayFileStaged:j,displayFile:A,pinnedStackedTarget:E,expandedFiles:z,mountedStackedFiles:N,loadFullFiles:I,setLoadFullFiles:W,fileDiffRefreshNonce:ne,showFileSidebar:oe,diffScrollRef:se,lastTurnDiffData:fe,branchDiffData:T,changedFiles:$,workingFileCount:G,stagedFileCount:pe,turnFileCount:B,allFileCount:ae,branchFileCount:K,currentLayoutForAllFiles:U,openingEditorFilePath:V,registerSectionRef:me,handleStackedEntryExpandedChange:ve,handleExpandOrCollapseAll:ie,handleSelectFile:he,handleSelectFileAndScroll:ge,handleHeaderLayoutChange:le,openFileInEditorAtChange:f,getLayoutForFile:P}=yn({hideStackedFileSidebar:t,stackedDefaultCollapsedAll:s,pinSelectedFileHeaderToTopOnNavigate:e,diffScope:a,branchBase:p,branchHead:u,targetFilePath:b});r.useEffect(()=>{c&&l?.(d)},[d,c,l]);const J=r.useCallback(()=>{W(ee=>!ee)},[W]),xe=r.useCallback(()=>{y(!S)},[S,y]),ce=r.useCallback(()=>{le(U==="side-by-side"?"unified":"side-by-side")},[U,le]),Z=z.size,be=r.useMemo(()=>({turnCount:B,branchCount:K,expandedCount:Z,totalCount:$.length,loadFullFiles:I,wrapLines:S,layoutMode:U,onExpandOrCollapseAll:ie,onToggleLoadFullFiles:J,onToggleWrapLines:xe,onToggleLayout:ce}),[B,K,Z,$.length,I,S,U,ie,J,xe,ce]);r.useEffect(()=>{c&&m?.(be)},[c,be,m]);const H=()=>{if(!k)return null;const ee=L=>w!==null?w:j&&L===A;return n.jsxs("div",{className:te("flex min-w-0 flex-1 min-h-0 h-full",h?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[oe&&n.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[n.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:"Files"}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:$.length})]}),n.jsx(en,{changedFiles:$,selectedFile:null,onSelectFile:ge})]}),n.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:n.jsx(et,{ref:se,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:n.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:$.map(L=>n.jsx(ln,{directory:k,file:L,layout:P(L),wrapLines:S,isSelected:!1,isExpanded:z.has(L.path),isMounted:N.has(L.path)||L.path===E,onSelect:he,onExpandedChange:ve,registerSectionRef:me,showOpenInEditorAction:i&&d!=="turn"&&d!=="branch",isOpeningInEditor:V===L.path,onOpenInEditor:(Ee,Ae)=>{f(Ee,Ae)},staged:ee(L.path),showFileActions:d!=="turn"&&d!=="branch",loadFullFiles:I,initialDiffData:d==="turn"?fe.get(L.path)??null:d==="branch"?T.get(L.path)??null:null},`${L.path}:${ne.get(L.path)??0}`))})})})]})},O=()=>k?d!=="turn"&&g&&!C?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(q,{name:"loader-4",className:"size-4 animate-spin"}),"Loading repository status..."]}):d!=="turn"&&d!=="branch"&&x===!1?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Not a git repository. Use the Git tab to initialize or change directories."}):d==="branch"&&X?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(q,{name:"loader-4",className:"size-4 animate-spin"}),"Loading branch changes..."]}):d==="branch"&&R?n.jsx("div",{className:"flex flex-1 items-center justify-center px-4 text-center text-sm text-muted-foreground",children:`Failed to load branch changes: ${R}`}):$.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d==="turn"?"No last turn changes to display":"Working tree clean, no changes to display"}):H():n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Select a session directory to view diffs"}),De=n.jsxs("div",{className:F?"flex min-w-0 flex-1 items-center gap-1.5":"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[(x!==!1||d==="turn")&&(d==="all"||d==="working"||d==="staged"||d==="turn"||d==="branch")?n.jsx(Gt,{scope:d,isGitRepo:x,branchAvailable:!!(p&&u),allCount:ae,workingCount:G,stagedCount:pe,turnCount:B,branchCount:K,onScopeChange:ee=>{_(ee),l?.(ee)}}):n.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:n.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:g&&!C?"Loading changes...":$.length===1?`${$.length} file changed`:`${$.length} files changed`})}),$.length>0&&n.jsxs(Le,{variant:"ghost",size:"sm",onClick:ie,className:te("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:z.size>0?"Collapse all":"Expand all",children:[n.jsx(q,{name:"expand-up-down",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:z.size>0?"Collapse all":"Expand all"})]}),$.length>0&&d!=="turn"&&d!=="branch"&&n.jsxs(_t,{children:[n.jsx(Wt,{asChild:!0,children:n.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>W(ee=>!ee),"aria-pressed":I,"aria-label":I?"Unload full files":"Load full files",className:te("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",I&&"bg-interactive-selection text-interactive-selection-foreground"),children:n.jsx(q,{name:"file-download",className:"size-4"})})}),n.jsx(Bt,{children:n.jsx("p",{children:I?"Unload full files":"Load full files"})})]}),$.length>0&&n.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>y(!S),className:te("h-5 w-5 p-0 transition-opacity",S?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:S?"Disable line wrap":"Enable line wrap",children:n.jsx(q,{name:"text-wrap",className:"size-4"})}),U&&n.jsx(it,{mode:U==="side-by-side"?"side-by-side":"unified",onModeChange:le})]});return n.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[F?St.createPortal(De,F):c?null:De,O()]})};export{Di as DiffView};
17
+ `))m.startsWith("+")&&!m.startsWith("+++")&&(h+=1),m.startsWith("-")&&!m.startsWith("---")&&(c+=1);return[{file:b==="deleted"?l:p,status:b,additions:h,deletions:c,patch:u}]}),mn=t=>t==="added"?"A":t==="deleted"?"D":"M";function hn({activeDiffScope:t,effectiveDirectory:s,branchBase:e,branchHead:i,git:a,sessionMessageRecords:l}){const[p,u]=r.useState([]),[b,h]=r.useState(null),[c,m]=r.useState(!1),F=r.useMemo(()=>{const C=Dt(l,{showTextJustificationActivity:!1,showTurnChangedFiles:!0,mergeHiddenUserTurns:!0});for(let g=C.turns.length-1;g>=0;g-=1){const d=C.turns[g];if(!d)continue;const _=d.activityParts.map(S=>S.part).filter(S=>S.type==="tool"),R=kt(_);if(R.length>0)return R.map(S=>({file:S.path,status:"modified",additions:S.additions,deletions:S.deletions,patch:S.patch}));const X=fn(d.userMessage.info?.summary?.diffs);if(X.length>0)return X}return[]},[l]);r.useEffect(()=>{if(t!=="branch"||!s||!e||!i||!a.getGitRangeDiff){u([]),h(null),m(!1);return}let C=!1;return m(!0),h(null),a.getGitRangeDiff(s,{base:e,head:i,contextLines:at}).then(g=>{C||(u(pn(g.diff??"")),m(!1))}).catch(g=>{C||(u([]),m(!1),h(g instanceof Error?g.message:String(g)))}),()=>{C=!0}},[t,e,i,s,a]);const k=r.useMemo(()=>{const C=new Map;for(const g of F)if(g.file){if(typeof g.patch=="string"){C.set(g.file,Pe(g.file,g.patch,"patch"));continue}C.set(g.file,{original:g.before??"",modified:g.after??"",contextMode:"full"})}return C},[F]),x=r.useMemo(()=>{const C=new Map;for(const g of p)!g.file||typeof g.patch!="string"||C.set(g.file,Pe(g.file,g.patch,"patch"));return C},[p]);return{branchDiffs:p,branchDiffError:b,branchDiffLoading:c,lastTurnDiffs:F,lastTurnDiffData:k,branchDiffData:x}}const Je=(t,s)=>{if(s.length===0)return null;let e=null,i=null;for(const l of s)l.top<=t?(!e||l.top>e.top)&&(e=l):(!i||l.top<i.top)&&(i=l);const a=e??i;return a?{path:a.path,topOffset:a.top-t}:null},gn=(t,s,e,i)=>Math.min(Math.max(0,i),Math.max(0,t+e-s));function xn({pinSelectedFileHeaderToTopOnNavigate:t,scrollRequestNonce:s,changedFiles:e,expandedFiles:i,setMountedStackedFiles:a,fileDiffRefreshNonce:l}){const p=r.useRef(null),u=r.useRef(new Map),[b,h]=r.useState(null),c=r.useRef(null),m=r.useRef(null),F=r.useRef(!1),k=r.useRef(null),x=r.useRef(null),C=r.useRef(null),g=r.useCallback(()=>{const y=p.current;if(!y)return null;const w=y.getBoundingClientRect().top,j=[];for(const[A,E]of u.current)E&&j.push({path:A,top:E.getBoundingClientRect().top});return Je(w,j)},[]),d=r.useCallback(()=>{c.current=null,F.current=!1,h(null),m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null)},[]),_=r.useCallback(()=>{k.current=null;const y=p.current;if(!y)return;const w=y.getBoundingClientRect(),j=w.top-Xe,A=w.bottom+Xe,E={},z=[];for(const[N,I]of u.current){if(!I)continue;const W=I.getBoundingClientRect();z.push({path:N,top:W.top}),i.has(N)&&(W.bottom<j||W.top>A||(E[N]=!0))}x.current=Je(w.top,z),a(N=>{let I=!1;const W=new Set(N);for(const ne of Object.keys(E))W.has(ne)||(W.add(ne),I=!0);return I?W:N})},[i,a]),R=r.useCallback(()=>{typeof window>"u"||k.current===null&&(k.current=window.requestAnimationFrame(_))},[_]);r.useEffect(()=>{const y=p.current;if(y)return R(),y.addEventListener("scroll",R,{passive:!0}),window.addEventListener("resize",R),()=>{y.removeEventListener("scroll",R),window.removeEventListener("resize",R),k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null)}},[e,i,R]),r.useLayoutEffect(()=>{const y=C.current;if(!y)return;C.current=null;const w=p.current,j=u.current.get(y.path);if(!w||!j)return;const A=w.getBoundingClientRect().top,E=j.getBoundingClientRect().top-A;w.scrollTop=gn(w.scrollTop,y.topOffset,E,w.scrollHeight-w.clientHeight),x.current=y},[l]);const X=r.useCallback((y,w)=>{const j=u.current;w?j.set(y,w):j.delete(y),R()},[R]),S=r.useCallback(y=>{const w=u.current.get(y),j=p.current;if(!w||!j)return!1;const A=w.getBoundingClientRect().top-j.getBoundingClientRect().top;return j.scrollTo({top:j.scrollTop+A,behavior:"auto"}),!0},[]);return r.useEffect(()=>{if(!c.current)return;let w=0;const j=20;let A=!1;const E=(N=!0)=>{A||(A=!0,c.current=null,F.current=!1,N&&h(null),m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null))},z=()=>{if(A){m.current=null;return}const N=c.current;if(!N){E(),m.current=null;return}if(!S(N)){w+=1,w<j?m.current=window.requestAnimationFrame(z):(E(),m.current=null);return}if(t&&F.current){h(N),E(!1);return}E()};return m.current=window.requestAnimationFrame(z),()=>{A=!0,m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null)}},[t,s,S]),{diffScrollRef:p,fileSectionRefs:u,pinnedStackedTarget:b,pendingScrollTargetRef:c,shouldPinAfterAlignRef:F,pendingScrollAnchorRestoreRef:C,lastScrollAnchorRef:x,captureScrollAnchor:g,cancelPendingScrollAlignment:d,queueVisibleStackedFilesSync:R,registerSectionRef:X,scrollToFile:S}}const Qe=t=>{if(!t)return null;const s=t.split(`
18
+ `);let e=null;for(const i of s){const a=i.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(a){const l=Number.parseInt(a[1]??"",10);e=Number.isFinite(l)&&l>=1?l:null;continue}if(e!==null){if(i.startsWith(" ")){e+=1;continue}if(i.startsWith("+"))return e;if(i.startsWith("-"))return Math.max(1,e)}}return null};function bn({effectiveDirectory:t,activeDiffStaged:s,git:e,files:i,setDiff:a,openContextFileAtLine:l}){const[p,u]=r.useState(null),b=r.useCallback(async(h,c)=>{if(!t||!h)return;u(h);const m=Ze();try{let F=null;if(c?.patch&&!c.isBinary&&!Ne(h)?F=Qe(c.patch):c&&c.contextMode==="full"&&!c.isBinary&&!Ne(h)&&(F=Ye(c.original,c.modified)),F===null)try{const d=await e.getGitDiff(t,{path:h,staged:s,contextLines:3});F=Qe(d.diff)}catch{F=null}let k=c;if(F===null||!k){const d=await e.getGitFileDiff(t,{path:h,staged:s});k={original:d.original??"",modified:d.modified??"",isBinary:d.isBinary},s||a(t,h,k,m??void 0)}const x=F??(k.isBinary||Ne(h)?1:Ye(k.original,k.modified)),C=dn(t,h),g=await Ut(i,C,{directory:t});if(!g.ok){st.error(Vt(g.reason));return}l(t,C,x,1)}finally{u(F=>F===h?null:F)}},[s,t,i,e,l,a]);return{openingEditorFilePath:p,openFileInEditorAtChange:b}}function yn(t){const{hideStackedFileSidebar:s=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:i=!1,diffScope:a="all",branchBase:l=null,branchHead:p=null,targetFilePath:u=null}=t,{git:b,files:h}=nt(),c=Rt(),{screenWidth:m,isMobile:F}=Et(),k=At(c??null),x=Tt(c??null),C=Mt(c??null),g=re(o=>o.setActiveDirectory),d=re(o=>o.ensureStatus),_=re(o=>o.fetchStatus),R=re(o=>o.clearDiffCache),X=re(o=>o.setDiff),[S,y]=r.useState(null),[w,j]=r.useState(!1),[A,E]=r.useState(()=>new Set),[z,N]=r.useState(()=>new Set),[I,W]=r.useState(!1),[ne,oe]=r.useState(0),[se,fe]=r.useState(()=>new Map),[T,$]=r.useState(a);r.useEffect(()=>{$(a)},[a]);const G=J(o=>o.pendingDiffFile),pe=J(o=>o.pendingDiffStaged),B=J(o=>o.pendingDiffScope),ae=J(o=>o.setPendingDiffFile),K=J(o=>o.diffLayoutPreference),U=J(o=>o.diffFileLayout),V=J(o=>o.setDiffFileLayout),me=J(o=>o.diffWrapLines),ve=J(o=>o.setDiffWrapLines),ie=J(o=>o.openContextFileAtLine),he=It(o=>o.currentSessionId),ge=$t(he??""),le=me,f=T==="staged"?!0:T==="working"?!1:null,P=f??w,Q=F||m<=768,xe=!s&&!Q&&m>=1024,ce=r.useRef(null),{branchDiffs:Z,branchDiffError:be,branchDiffLoading:H,lastTurnDiffs:O,lastTurnDiffData:De,branchDiffData:ee}=hn({activeDiffScope:T,effectiveDirectory:c,branchBase:l,branchHead:p,git:b,sessionMessageRecords:ge}),L=r.useMemo(()=>{if(T==="turn"||T==="branch")return(T==="branch"?Z:O).map(M=>({path:M.file??"",index:"",working_dir:mn(M.status),insertions:M.additions??0,deletions:M.deletions??0,isNew:M.status==="added"})).filter(M=>M.path).sort((M,Y)=>M.path.localeCompare(Y.path));if(!x?.files)return[];const o=x.diffStats??{},D=T==="staged"?Ge:T==="working"?He:()=>!0;return x.files.filter(D).map(v=>({...v,insertions:o[v.path]?.insertions??0,deletions:o[v.path]?.deletions??0,isNew:zt(v)})).sort((v,M)=>v.path.localeCompare(M.path))},[T,Z,O,x]),Ee=r.useMemo(()=>x?.files?x.files.filter(He).length:0,[x]),Ae=r.useMemo(()=>x?.files?x.files.filter(Ge).length:0,[x]),lt=O.length,ct=x?.files?.length??0,ut=Z.length,{diffScrollRef:dt,pinnedStackedTarget:ft,pendingScrollTargetRef:ye,shouldPinAfterAlignRef:we,pendingScrollAnchorRestoreRef:_e,lastScrollAnchorRef:We,captureScrollAnchor:Be,cancelPendingScrollAlignment:Fe,queueVisibleStackedFilesSync:ke,registerSectionRef:pt,scrollToFile:Oe}=xn({pinSelectedFileHeaderToTopOnNavigate:i,scrollRequestNonce:ne,changedFiles:L,expandedFiles:A,setMountedStackedFiles:N,fileDiffRefreshNonce:se}),Se=r.useCallback(o=>{E(D=>{if(D.has(o))return D;const v=new Set(D);return v.add(o),v})},[]),Te=r.useMemo(()=>L.map(o=>o.path).join("\0"),[L]);r.useEffect(()=>{const o=Te?Te.split("\0"):[],D=new Set(o),v=`${c??""}:${T}:${e?"collapsed":"default"}`,M=ce.current!==v;ce.current=v,E(Y=>{if(M){const ue=e?0:un(o.length);return new Set(o.slice(0,ue))}let Ce=!1;const je=new Set;for(const ue of Y){if(!D.has(ue)){Ce=!0;continue}je.add(ue)}return Ce?je:Y}),N(Y=>{if(M)return new Set;let Ce=!1;const je=new Set;for(const ue of Y){if(!D.has(ue)){Ce=!0;continue}je.add(ue)}return Ce?je:Y})},[T,Te,c,N,e]);const Me=r.useCallback(o=>{const D=U[o.path];if(D)return D;if(K==="inline")return"inline";if(K==="side-by-side")return"side-by-side";const v=m<cn;return o.isNew||v?"inline":"side-by-side"},[U,K,m]),mt=r.useMemo(()=>L.length===0?null:L.every(o=>Me(o)==="side-by-side")?"side-by-side":"inline",[L,Me]);r.useEffect(()=>{c&&(g(c),d(c,b))},[c,g,d,b]),r.useEffect(()=>{if(c)return Pt.onGitRefreshHint(o=>{ze(o.directory)===ze(c)&&(o.paths?.length&&(_e.current=Be()??We.current,R(c,o.paths),fe(D=>{const v=new Map(D);for(const M of o.paths??[])v.set(M,(v.get(M)??0)+1);return v})),_(c,b,{silent:!0}))})},[Be,R,c,_,b,We,_e]),r.useEffect(()=>{T!=="all"&&!B||G&&(B&&$(B),y(G),j(B==="staged"||!B&&pe),ae(null),we.current=!0,ye.current=G,Se(G),oe(o=>o+1))},[T,Se,G,B,pe,ye,ae,we]),r.useEffect(()=>{if(T==="all")return;const o=u?.trim();o&&(y(o),j(T==="staged"),we.current=!0,ye.current=o,Se(o),oe(D=>D+1))},[T,Se,ye,we,u]),r.useEffect(()=>{if(!S)return;L.some(D=>D.path===S)||(y(null),j(!1))},[L,S]);const ht=r.useCallback((o,D)=>{Fe(),E(v=>{const M=v.has(o);if(D===M)return v;const Y=new Set(v);return D?Y.add(o):Y.delete(o),Y}),D||N(v=>{if(!v.has(o))return v;const M=new Set(v);return M.delete(o),M}),ke()},[Fe,ke,N]),gt=r.useCallback(()=>{Fe(),E(o=>o.size>0?new Set:new Set(L.map(D=>D.path))),N(new Set),ke()},[Fe,L,ke,N]),xt=r.useCallback(o=>{},[]),bt=r.useCallback(o=>{Fe(),y(o),j(!1),we.current=!0,ye.current=o,Se(o),oe(D=>D+1),Oe(o)},[Fe,Se,ye,Oe,we]),yt=r.useCallback(o=>{const D=o==="side-by-side"?"side-by-side":"inline";L.forEach(v=>{V(v.path,D)})},[L,V]),{openingEditorFilePath:wt,openFileInEditorAtChange:Ft}=bn({effectiveDirectory:c,activeDiffStaged:P,git:b,files:h,setDiff:X,openContextFileAtLine:ie});return{git:b,files:h,effectiveDirectory:c,screenWidth:m,isMobile:F,isGitRepo:k,status:x,isLoadingStatus:C,activeDiffScope:T,setActiveDiffScope:$,branchDiffs:Z,branchDiffError:be,branchDiffLoading:H,diffWrapLines:le,setDiffWrapLines:ve,forcedStaged:f,displayFileStaged:w,displayFile:S,pinnedStackedTarget:ft,expandedFiles:A,mountedStackedFiles:z,loadFullFiles:I,setLoadFullFiles:W,fileDiffRefreshNonce:se,showFileSidebar:xe,diffScrollRef:dt,lastTurnDiffData:De,branchDiffData:ee,changedFiles:L,workingFileCount:Ee,stagedFileCount:Ae,turnFileCount:lt,allFileCount:ct,branchFileCount:ut,currentLayoutForAllFiles:mt,openingEditorFilePath:wt,registerSectionRef:pt,handleStackedEntryExpandedChange:ht,handleExpandOrCollapseAll:gt,handleSelectFile:xt,handleSelectFileAndScroll:bt,handleHeaderLayoutChange:yt,openFileInEditorAtChange:Ft,getLayoutForFile:Me}}const Di=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:s=!1,pinSelectedFileHeaderToTopOnNavigate:e=!1,showOpenInEditorAction:i=!1,diffScope:a="all",onDiffScopeChange:l,branchBase:p=null,branchHead:u=null,targetFilePath:b=null,flushContent:h=!1,hideToolbar:c=!1,onHeaderControlsStateChange:m,toolbarSlot:F=null})=>{const{effectiveDirectory:k,isGitRepo:x,status:C,isLoadingStatus:g,activeDiffScope:d,setActiveDiffScope:_,branchDiffError:R,branchDiffLoading:X,diffWrapLines:S,setDiffWrapLines:y,forcedStaged:w,displayFileStaged:j,displayFile:A,pinnedStackedTarget:E,expandedFiles:z,mountedStackedFiles:N,loadFullFiles:I,setLoadFullFiles:W,fileDiffRefreshNonce:ne,showFileSidebar:oe,diffScrollRef:se,lastTurnDiffData:fe,branchDiffData:T,changedFiles:$,workingFileCount:G,stagedFileCount:pe,turnFileCount:B,allFileCount:ae,branchFileCount:K,currentLayoutForAllFiles:U,openingEditorFilePath:V,registerSectionRef:me,handleStackedEntryExpandedChange:ve,handleExpandOrCollapseAll:ie,handleSelectFile:he,handleSelectFileAndScroll:ge,handleHeaderLayoutChange:le,openFileInEditorAtChange:f,getLayoutForFile:P}=yn({hideStackedFileSidebar:t,stackedDefaultCollapsedAll:s,pinSelectedFileHeaderToTopOnNavigate:e,diffScope:a,branchBase:p,branchHead:u,targetFilePath:b});r.useEffect(()=>{c&&l?.(d)},[d,c,l]);const Q=r.useCallback(()=>{W(ee=>!ee)},[W]),xe=r.useCallback(()=>{y(!S)},[S,y]),ce=r.useCallback(()=>{le(U==="side-by-side"?"unified":"side-by-side")},[U,le]),Z=z.size,be=r.useMemo(()=>({turnCount:B,branchCount:K,expandedCount:Z,totalCount:$.length,loadFullFiles:I,wrapLines:S,layoutMode:U,onExpandOrCollapseAll:ie,onToggleLoadFullFiles:Q,onToggleWrapLines:xe,onToggleLayout:ce}),[B,K,Z,$.length,I,S,U,ie,Q,xe,ce]);r.useEffect(()=>{c&&m?.(be)},[c,be,m]);const H=()=>{if(!k)return null;const ee=L=>w!==null?w:j&&L===A;return n.jsxs("div",{className:te("flex min-w-0 flex-1 min-h-0 h-full",h?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[oe&&n.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[n.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:"Files"}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:$.length})]}),n.jsx(en,{changedFiles:$,selectedFile:null,onSelectFile:ge})]}),n.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:n.jsx(et,{ref:se,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:n.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:$.map(L=>n.jsx(ln,{directory:k,file:L,layout:P(L),wrapLines:S,isSelected:!1,isExpanded:z.has(L.path),isMounted:N.has(L.path)||L.path===E,onSelect:he,onExpandedChange:ve,registerSectionRef:me,showOpenInEditorAction:i&&d!=="turn"&&d!=="branch",isOpeningInEditor:V===L.path,onOpenInEditor:(Ee,Ae)=>{f(Ee,Ae)},staged:ee(L.path),showFileActions:d!=="turn"&&d!=="branch",loadFullFiles:I,initialDiffData:d==="turn"?fe.get(L.path)??null:d==="branch"?T.get(L.path)??null:null},`${L.path}:${ne.get(L.path)??0}`))})})})]})},O=()=>k?d!=="turn"&&g&&!C?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(q,{name:"loader-4",className:"size-4 animate-spin"}),"Loading repository status..."]}):d!=="turn"&&d!=="branch"&&x===!1?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Not a git repository. Use the Git tab to initialize or change directories."}):d==="branch"&&X?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(q,{name:"loader-4",className:"size-4 animate-spin"}),"Loading branch changes..."]}):d==="branch"&&R?n.jsx("div",{className:"flex flex-1 items-center justify-center px-4 text-center text-sm text-muted-foreground",children:`Failed to load branch changes: ${R}`}):$.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d==="turn"?"No last turn changes to display":"Working tree clean, no changes to display"}):H():n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Select a session directory to view diffs"}),De=n.jsxs("div",{className:F?"flex min-w-0 flex-1 items-center gap-1.5":"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[(x!==!1||d==="turn")&&(d==="all"||d==="working"||d==="staged"||d==="turn"||d==="branch")?n.jsx(Gt,{scope:d,isGitRepo:x,branchAvailable:!!(p&&u),allCount:ae,workingCount:G,stagedCount:pe,turnCount:B,branchCount:K,onScopeChange:ee=>{_(ee),l?.(ee)}}):n.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:n.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:g&&!C?"Loading changes...":$.length===1?`${$.length} file changed`:`${$.length} files changed`})}),$.length>0&&n.jsxs(Le,{variant:"ghost",size:"sm",onClick:ie,className:te("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:z.size>0?"Collapse all":"Expand all",children:[n.jsx(q,{name:"expand-up-down",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:z.size>0?"Collapse all":"Expand all"})]}),$.length>0&&d!=="turn"&&d!=="branch"&&n.jsxs(_t,{children:[n.jsx(Wt,{asChild:!0,children:n.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>W(ee=>!ee),"aria-pressed":I,"aria-label":I?"Unload full files":"Load full files",className:te("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",I&&"bg-interactive-selection text-interactive-selection-foreground"),children:n.jsx(q,{name:"file-download",className:"size-4"})})}),n.jsx(Bt,{children:n.jsx("p",{children:I?"Unload full files":"Load full files"})})]}),$.length>0&&n.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>y(!S),className:te("h-5 w-5 p-0 transition-opacity",S?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:S?"Disable line wrap":"Enable line wrap",children:n.jsx(q,{name:"text-wrap",className:"size-4"})}),U&&n.jsx(it,{mode:U==="side-by-side"?"side-by-side":"unified",onModeChange:le})]});return n.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[F?St.createPortal(De,F):c?null:De,O()]})};export{Di as DiffView};