@pi-chamber/web 1.0.6-rc.4 → 1.0.6-rc.5

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 (119) hide show
  1. package/dist/assets/{DiagramView-BZ--w7Lh.js → DiagramView--XO16VPB.js} +1 -1
  2. package/dist/assets/{DiffView-Dtn6otnT.js → DiffView-Duy2_7Gp.js} +6 -6
  3. package/dist/assets/{FileSaveConflictDialog-p1ik30al.js → FileSaveConflictDialog-B1DvL9zy.js} +1 -1
  4. package/dist/assets/{FilesView-D0Z0VmQm.js → FilesView-CjjPpE4c.js} +4 -4
  5. package/dist/assets/{GitHubDetailScaffold-a27RksFo.js → GitHubDetailScaffold-DqxAKqCT.js} +2 -2
  6. package/dist/assets/{GitHubLinkPicker-B0CfzNfk.js → GitHubLinkPicker-ELF_chia.js} +1 -1
  7. package/dist/assets/GitHubListPrimitives-C2nGTntk.js +1 -0
  8. package/dist/assets/{GitView-BNkoaVYl.js → GitView-5fIq2nzM.js} +4 -4
  9. package/dist/assets/IssuesSurface-Dq5A_bWq.js +7 -0
  10. package/dist/assets/{JsonTreeView-CEiJsFnP.js → JsonTreeView-BjFFSUwi.js} +1 -1
  11. package/dist/assets/{MarkdownRendererImpl-418ChlsN.js → MarkdownRendererImpl-B9Cu4TCh.js} +2 -2
  12. package/dist/assets/{PatchDiff-BtOv_oLB.js → PatchDiff-CTqTTcg7.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-CkuyY9ne.js → PierreDiffViewer-H2f4pJ1k.js} +1 -1
  14. package/dist/assets/PullRequestsSurface-DPpb2RW_.js +2 -0
  15. package/dist/assets/{SessionSwitcherContent-DkfjRgwv.js → SessionSwitcherContent-B5DaBWZU.js} +1 -1
  16. package/dist/assets/{SessionSwitcherDropdown-CEw8BEs6.js → SessionSwitcherDropdown-D86FaZg_.js} +2 -2
  17. package/dist/assets/SessionUnreadDot-CY9-1iV2.js +1 -0
  18. package/dist/assets/SettingsView-CiIuOi_E.js +6 -0
  19. package/dist/assets/{SettingsWindow-D03Z9QyW.js → SettingsWindow-Bw1dUoJ1.js} +1 -1
  20. package/dist/assets/{StickyHorizontalScrollbar-CONTbZgX.js → StickyHorizontalScrollbar-DNsbTLS7.js} +1 -1
  21. package/dist/assets/{ToolOutputDialog-DibddNlz.js → ToolOutputDialog-aR4kcgKL.js} +5 -5
  22. package/dist/assets/{ToolPartDiffPreview-Bx7T1M2f.js → ToolPartDiffPreview-B_wWmhtE.js} +1 -1
  23. package/dist/assets/{VirtualizedFileDiff-BY-mDMT8.js → VirtualizedFileDiff-BYby097w.js} +4 -4
  24. package/dist/assets/{Virtualizer-cIf8dSOQ.js → Virtualizer-okhy9Aq3.js} +1 -1
  25. package/dist/assets/{collapsible-BhQdnj8G.js → collapsible-Dz0bPrJ_.js} +1 -1
  26. package/dist/assets/{computeVirtualFileMetrics-CzkFqhaU.js → computeVirtualFileMetrics-8MuwxSC6.js} +1 -1
  27. package/dist/assets/{contextFileOpenGuard-CjCOK8EB.js → contextFileOpenGuard-fZ2NIQMQ.js} +1 -1
  28. package/dist/assets/{fileTreeStatus-CPTpyKOV.js → fileTreeStatus-BzhMMLA9.js} +2 -2
  29. package/dist/assets/{gitStatusPredicates-_GNbGCCb.js → gitStatusPredicates-Cyh9UhYX.js} +1 -1
  30. package/dist/assets/{githubLink-CwIFogWd.js → githubLink-D2PznPcI.js} +2 -2
  31. package/dist/assets/{index-DjOKW10B.js → index-BX5pAOQX.js} +1 -1
  32. package/dist/assets/index-Cs2nBW_t.js +11 -0
  33. package/dist/assets/{index-D7k62S9M.css → index-tmO0fZa4.css} +1 -1
  34. package/dist/assets/{main-1wmEZ4Is.js → main-7vBNPBMb.js} +4 -4
  35. package/dist/assets/{main-C51a3z3b.js → main-BI6qe8pz.js} +2 -2
  36. package/dist/assets/{markdownCore-Dsr6dY5C.js → markdownCore-D5jiabKe.js} +1 -1
  37. package/dist/assets/{miniChat-DCxCx1fF.js → miniChat-B3up4Bnz.js} +2 -2
  38. package/dist/assets/{mobile-D6Ac2Mu3.js → mobile-B4vLFgBc.js} +2 -2
  39. package/dist/assets/{nativeFileSave-P_Eg5Dgb.js → nativeFileSave-DpBH1Sa3.js} +1 -1
  40. package/dist/assets/{pi-session-focus-preference-DjDyjZ1C.js → pi-session-focus-preference-BrB72skF.js} +3 -3
  41. package/dist/assets/{renderDiffWithHighlighter-CK_inhQE.js → renderDiffWithHighlighter-B6T04JGG.js} +1 -1
  42. package/dist/assets/{renderElectronMiniChatApp-wBNgFl0U.js → renderElectronMiniChatApp-CX10w321.js} +2 -2
  43. package/dist/assets/{renderFileWithHighlighter-B_PFeRW5.js → renderFileWithHighlighter-DtAcGyJr.js} +1 -1
  44. package/dist/assets/{renderMobileApp-B3mhxGnb.js → renderMobileApp-C9n-BhPZ.js} +3 -3
  45. package/dist/assets/runtimeEndpointReset-aGyXPXPs.js +62 -0
  46. package/dist/assets/{runtimeSurface-C3YPOBlg.js → runtimeSurface-DiP2a57a.js} +1 -1
  47. package/dist/assets/{useAppFontEffects-CoFst31H.js → useAppFontEffects-Oyin3dgQ.js} +92 -92
  48. package/dist/assets/useGitHubRemoteSearch-CZ9Hauw0.js +1 -0
  49. package/dist/assets/{useSwitcherItems-DHCCg4GF.js → useSwitcherItems-BSqDA1IF.js} +1 -1
  50. package/dist/assets/{vendor-aparajita-capacitor-secure-storage-B9_YeZyx.js → vendor-aparajita-capacitor-secure-storage-DVZvgYu4.js} +1 -1
  51. package/dist/assets/{vendor-base-ui-CKSCJw-4.js → vendor-base-ui-BCqPBzDj.js} +1 -1
  52. package/dist/assets/{vendor-boot-Ciu-Edvy.js → vendor-boot-3SaHYVb1.js} +1 -1
  53. package/dist/assets/{vendor-capacitor-app-Bpy_aPMq.js → vendor-capacitor-app-NbQ-WiPS.js} +1 -1
  54. package/dist/assets/{vendor-capacitor-keyboard-DO8AIjrZ.js → vendor-capacitor-keyboard-CgrHt8iN.js} +1 -1
  55. package/dist/assets/{vendor-capacitor-status-bar-SQkytwUW.js → vendor-capacitor-status-bar-CWt0OF5t.js} +1 -1
  56. package/dist/assets/{vendor-codemirror-autocomplete-CInQsE8a.js → vendor-codemirror-autocomplete-WThuuUAz.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-angular-QbsN3LGE.js → vendor-codemirror-lang-angular-BbLGCxF6.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-cpp-BT5U7lxV.js → vendor-codemirror-lang-cpp-Cceks-9O.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-css-dF-Dxbty.js → vendor-codemirror-lang-css-D1wpUg3Z.js} +1 -1
  60. package/dist/assets/{vendor-codemirror-lang-go-e4dp1bar.js → vendor-codemirror-lang-go-Cv0zXHHM.js} +1 -1
  61. package/dist/assets/{vendor-codemirror-lang-html-DKcbBVQ4.js → vendor-codemirror-lang-html-DbL8oT9H.js} +1 -1
  62. package/dist/assets/{vendor-codemirror-lang-java-CB2-FWv6.js → vendor-codemirror-lang-java-CNugenuC.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-javascript-B1zJk7xE.js → vendor-codemirror-lang-javascript-Bx_FIyZF.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-jinja-BsERjdSd.js → vendor-codemirror-lang-jinja-DDGjB3Zq.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-json-C0pZ0NhY.js → vendor-codemirror-lang-json-DIvqf9Pb.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-less-_N9HmR4h.js → vendor-codemirror-lang-less-D8r9dGG1.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-liquid-D02xJRCD.js → vendor-codemirror-lang-liquid-B24mguYi.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-markdown-_6ojeUuZ.js → vendor-codemirror-lang-markdown-v3yG2sbf.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-php-DguCnbJA.js → vendor-codemirror-lang-php-BcZGalqy.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-python-Byr5gw5f.js → vendor-codemirror-lang-python-b-JqEwQy.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-rust-DN6Wh0eK.js → vendor-codemirror-lang-rust-B1uZxDW-.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sass-DOlEW7q1.js → vendor-codemirror-lang-sass-DqPrngKp.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-sql-BJzE9Dby.js → vendor-codemirror-lang-sql-UyCnpt-k.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-vue-DR8E-2nr.js → vendor-codemirror-lang-vue-xDwYkovV.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-wast-n6lcDH5S.js → vendor-codemirror-lang-wast-CF3169p_.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-xml-Cf2lmlmY.js → vendor-codemirror-lang-xml-FCtVhuOb.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-yaml-DSR_E0yh.js → vendor-codemirror-lang-yaml-g0sPmAnv.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-language-data-CSid5JuX.js → vendor-codemirror-language-data-B03xgzP2.js} +2 -2
  79. package/dist/assets/{vendor-codemirror-search-8lY3lt6q.js → vendor-codemirror-search-Dw3Wpu15.js} +1 -1
  80. package/dist/assets/{vendor-lezer-cpp-DZYTDKiD.js → vendor-lezer-cpp-Cu3E-KUI.js} +1 -1
  81. package/dist/assets/{vendor-lezer-css-6qV4fYNQ.js → vendor-lezer-css-Cb8vp67u.js} +1 -1
  82. package/dist/assets/{vendor-lezer-go-BDi_Iblq.js → vendor-lezer-go-BTsIaOm7.js} +1 -1
  83. package/dist/assets/{vendor-lezer-html-BjqcY-oJ.js → vendor-lezer-html-UQMsUwj-.js} +1 -1
  84. package/dist/assets/{vendor-lezer-java-J2BXqz1h.js → vendor-lezer-java-BIWrFrAx.js} +1 -1
  85. package/dist/assets/{vendor-lezer-javascript-CiQ9F8yX.js → vendor-lezer-javascript-BH2Etgoy.js} +1 -1
  86. package/dist/assets/{vendor-lezer-json-BxN83KKR.js → vendor-lezer-json-CE-QUCwM.js} +1 -1
  87. package/dist/assets/{vendor-lezer-lr-BVsDua_K.js → vendor-lezer-lr-HY6Yc0Vr.js} +1 -1
  88. package/dist/assets/{vendor-lezer-markdown-BkMtRQ3X.js → vendor-lezer-markdown-xFL3Evwf.js} +1 -1
  89. package/dist/assets/{vendor-lezer-php-B3XqnXdP.js → vendor-lezer-php-Cr_mQGrG.js} +1 -1
  90. package/dist/assets/{vendor-lezer-python-D342CidI.js → vendor-lezer-python-BNRFWCb0.js} +1 -1
  91. package/dist/assets/{vendor-lezer-rust-Dbfg_4LA.js → vendor-lezer-rust-BvfOK5cU.js} +1 -1
  92. package/dist/assets/{vendor-lezer-sass-ClxPaFt1.js → vendor-lezer-sass-qoxiLisk.js} +1 -1
  93. package/dist/assets/{vendor-lezer-xml-I_S6FQ1u.js → vendor-lezer-xml--x8SSpqU.js} +1 -1
  94. package/dist/assets/{vendor-lezer-yaml-COA6HWLP.js → vendor-lezer-yaml-BDo1JaEr.js} +1 -1
  95. package/dist/assets/{vendor-replit-codemirror-vim-7IE2zVmx.js → vendor-replit-codemirror-vim-D1Fe7FiY.js} +1 -1
  96. package/dist/assets/{web-components-CzkvK_V5.js → web-components-CkTNGkJ2.js} +4 -4
  97. package/dist/index.html +4 -4
  98. package/dist/mini-chat.html +3 -3
  99. package/dist/mobile.html +3 -3
  100. package/package.json +1 -1
  101. package/server/lib/pi/archive-store.js +38 -10
  102. package/server/lib/pi/archive-store.test.js +10 -0
  103. package/server/lib/pi/routes.js +60 -17
  104. package/server/lib/pi/routes.test.js +186 -8
  105. package/server/lib/pi/session-daemon/DOCUMENTATION.md +5 -1
  106. package/server/lib/pi/session-daemon/session-daemon-engines.test.js +18 -0
  107. package/server/lib/pi/session-daemon/session-daemon.js +24 -1
  108. package/server/lib/pi/session-shelf-store.js +155 -84
  109. package/server/lib/pi/session-shelf-store.test.js +134 -33
  110. package/server/lib/pi/ui-settings-store.js +59 -0
  111. package/server/lib/pi/ui-settings-store.test.js +105 -6
  112. package/dist/assets/GitHubListPrimitives-LFdR70l6.js +0 -1
  113. package/dist/assets/IssuesSurface-D4kD7_VW.js +0 -7
  114. package/dist/assets/PullRequestsSurface-PML07zr-.js +0 -2
  115. package/dist/assets/SessionUnreadDot-DXUn8-ss.js +0 -1
  116. package/dist/assets/SettingsView-BvUeFUqw.js +0 -6
  117. package/dist/assets/index-Cfrwo5uQ.js +0 -11
  118. package/dist/assets/runtimeEndpointReset-D8lAOCUB.js +0 -62
  119. package/dist/assets/useGitHubRemoteSearch-C0-6hhMJ.js +0 -1
@@ -1,7 +1,7 @@
1
- import{R as g}from"./vendor-react-Bz1tRBxM.js";import{t as w,bE as P,cJ as M}from"./useAppFontEffects-CoFst31H.js";import{aA as _,f as R}from"./index-Cfrwo5uQ.js";import{j as u}from"./vendor-boot-Ciu-Edvy.js";const J=e=>{const t=h(e);if(!t)return"";if(t==="/"||/^[A-Za-z]:\/$/.test(t))return t;const s=t.lastIndexOf("/");if(s<0)return t;if(s===0)return"/";const n=t.slice(0,s);return/^[A-Za-z]:$/.test(n)?`${n}/`:n},Q=e=>e.slice().sort((t,s)=>t.type!==s.type?t.type==="directory"?-1:1:t.name.localeCompare(s.name)),h=e=>{if(!e)return"";const t=e.replace(/\\/g,"/"),s=t.startsWith("//");let n=t.replace(/\/+/g,"/");s&&!n.startsWith("//")&&(n=`/${n}`);const o=n==="/",i=/^[A-Za-z]:\/$/.test(n);return!o&&!i&&(n=n.replace(/\/+$/,"")),n},X=e=>e.startsWith("/")||e.startsWith("//")||/^[A-Za-z]:\//.test(e),A=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,z=(e,t)=>{const s=h(t),n=h(e);if(!s||!n)return!1;const o=A(s),i=A(n);return i===o||i.startsWith(`${o}/`)},Y=(e,t)=>{const s=h(t),n=h(e);if(!z(n,s))return[];const i=n.slice(s.length).replace(/^\//,"").split("/"),c=[];let r=s;for(let f=0;f<i.length-1;f++)r=r?`${r}/${i[f]}`:i[f],c.push(r);return c},K=(e,t)=>{if(!t)return"";const s=h(t);if(!e||!z(s,e))return s;const n=s.slice(e.length);return n.startsWith("/")?n.slice(1):n},D=new Set(["node_modules"]),ee=e=>D.has(e),te=e=>e===".git",W=/(^|\/)\.git(\/|$)/,L=e=>W.test(h(e)),I=e=>{const t=h(e);return t==="node_modules"||t.endsWith("/node_modules")||t.includes("/node_modules/")},se=e=>{const s=(e instanceof Error?e.message:String(e??"")).toLowerCase();return s.includes("is a directory")||s.includes("eisdir")},ne=e=>{const s=(e instanceof Error?e.message:String(e??"")).toLowerCase();return s.includes("file not found")||s.includes("enoent")||s.includes("no such file")||s.includes("does not exist")},re=2e5,ae=e=>{let t=0,s=0;for(let n=0;n<e.length;n+=1)e.charCodeAt(n)===10&&(n>0&&e.charCodeAt(n-1)===13?t+=1:s+=1);return t>s?`\r
1
+ import{R as g}from"./vendor-react-Bz1tRBxM.js";import{t as w,bL as P,cQ as M}from"./useAppFontEffects-Oyin3dgQ.js";import{as as _,f as R}from"./index-Cs2nBW_t.js";import{j as u}from"./vendor-boot-3SaHYVb1.js";const q=e=>{const t=h(e);if(!t)return"";if(t==="/"||/^[A-Za-z]:\/$/.test(t))return t;const s=t.lastIndexOf("/");if(s<0)return t;if(s===0)return"/";const n=t.slice(0,s);return/^[A-Za-z]:$/.test(n)?`${n}/`:n},J=e=>e.slice().sort((t,s)=>t.type!==s.type?t.type==="directory"?-1:1:t.name.localeCompare(s.name)),h=e=>{if(!e)return"";const t=e.replace(/\\/g,"/"),s=t.startsWith("//");let n=t.replace(/\/+/g,"/");s&&!n.startsWith("//")&&(n=`/${n}`);const o=n==="/",i=/^[A-Za-z]:\/$/.test(n);return!o&&!i&&(n=n.replace(/\/+$/,"")),n},X=e=>e.startsWith("/")||e.startsWith("//")||/^[A-Za-z]:\//.test(e),$=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,A=(e,t)=>{const s=h(t),n=h(e);if(!s||!n)return!1;const o=$(s),i=$(n);return i===o||i.startsWith(`${o}/`)},Y=(e,t)=>{const s=h(t),n=h(e);if(!A(n,s))return[];const i=n.slice(s.length).replace(/^\//,"").split("/"),c=[];let r=s;for(let f=0;f<i.length-1;f++)r=r?`${r}/${i[f]}`:i[f],c.push(r);return c},K=(e,t)=>{if(!t)return"";const s=h(t);if(!e||!A(s,e))return s;const n=s.slice(e.length);return n.startsWith("/")?n.slice(1):n},D=new Set(["node_modules"]),ee=e=>D.has(e),te=e=>e===".git",L=/(^|\/)\.git(\/|$)/,W=e=>L.test(h(e)),I=e=>{const t=h(e);return t==="node_modules"||t.endsWith("/node_modules")||t.includes("/node_modules/")},se=e=>{const s=(e instanceof Error?e.message:String(e??"")).toLowerCase();return s.includes("is a directory")||s.includes("eisdir")},ne=e=>{const s=(e instanceof Error?e.message:String(e??"")).toLowerCase();return s.includes("file not found")||s.includes("enoent")||s.includes("no such file")||s.includes("does not exist")},re=2e5,ae=e=>{let t=0,s=0;for(let n=0;n<e.length;n+=1)e.charCodeAt(n)===10&&(n>0&&e.charCodeAt(n-1)===13?t+=1:s+=1);return t>s?`\r
2
2
  `:`
3
3
  `},B=e=>e.replace(/\r\n/g,`
4
4
  `).replace(/\r/g,`
5
5
  `),ie=(e,t)=>{const s=B(e);return t===`\r
6
6
  `?s.replace(/\n/g,`\r
7
- `):s},oe=e=>{if(!e)return!1;const t=e.toLowerCase().split(".").pop();return t==="md"||t==="markdown"},le=e=>{if(!e)return!1;const t=e.toLowerCase().split(".").pop();return t==="json"||t==="jsonc"||t==="json5"||t==="geojson"},ce=e=>{if(!e)return!1;const t=e.toLowerCase().split(".").pop();return t==="html"||t==="htm"};function de({files:e,root:t,selectedPath:s,refreshDirectory:n,removeOpenPathsByPrefix:o,clearSelectedPath:i}){const c=g.useRef(null),[r,f]=g.useState(null),[a,m]=g.useState(null),[l,C]=g.useState(""),[F,p]=g.useState(!1),b=g.useCallback((v,y)=>{f(v),m(y),C(v==="rename"&&y.name||""),p(!1)},[]),x=g.useCallback(()=>f(null),[]),N=g.useCallback(async v=>{if(v?.preventDefault(),!r||!a)return;const y=l.trim();if(r==="createFile"&&!y){w.error("Filename is required");return}if(r==="createFolder"&&!y){w.error("Folder name is required");return}if(r==="rename"&&!y){w.error("Name is required");return}if(r==="createFile"&&!e.writeFile){w.error("Write not supported");return}if(r==="rename"&&!e.rename){w.error("Rename not supported");return}if(r==="delete"&&!e.delete){w.error("Delete not supported");return}p(!0);try{if(r==="createFile"){const d=a.path,S=h(`${d?`${d}/`:""}${y}`);try{(await e.writeFile(S,"",{expectedRevision:null})).success&&(w.success("File created"),await n(d))}catch(j){if(j?.reason==="file-revision-conflict"||j?.name==="FileRevisionConflictError")w.error("File already exists");else throw j}}else if(r==="createFolder"){const d=a.path,S=h(`${d?`${d}/`:""}${y}`);(await e.createDirectory(S)).success&&(w.success("Folder created"),await n(d))}else{const d=a.path,S=d.split("/").slice(0,-1).join("/"),j=s===d||s.startsWith(`${d}/`);(r==="rename"?await e.rename(d,h(`${S?`${S}/`:""}${y}`)):await e.delete(d)).success&&(w.success(r==="rename"?"Renamed successfully":"Deleted successfully"),await n(S),t&&o(t,d),j&&i())}f(null)}catch{w.error("Operation failed")}finally{p(!1)}},[i,e,l,r,n,o,t,s,a]);return{operation:r,target:a,inputValue:l,setInputValue:C,submitting:F,inputRef:c,open:b,close:x,submit:N,capabilities:{canCreateFile:!!e.writeFile,canCreateFolder:!!e.createDirectory,canRename:!!e.rename,canDelete:!!e.delete}}}function ue({directory:e,query:t,chrome:s,showGitignored:n}){const o=_(F=>F.searchFiles),i=P(t,200),[c,r]=g.useState([]),[f,a]=g.useState(!1),[m,l]=g.useState(!1);g.useEffect(()=>{const F=i.trim();if(!e||!F){r([]),a(!1),l(!1);return}let p=!1;return a(!0),l(!1),o(e,F,s==="mobile"?40:150,{includeHidden:!0,respectGitignore:s==="desktop"&&!n,type:"file"}).then(b=>{p||r(b.filter(x=>!L(x.relativePath??x.path)).filter(x=>n||!I(x.path)).map(x=>({name:x.name,path:h(x.path),type:"file",extension:x.extension,relativePath:x.relativePath})))}).catch(()=>{p||(r([]),l(!0))}).finally(()=>{p||a(!1)}),()=>{p=!0}},[s,i,e,o,n]);const C=t.trim()!==""&&t.trim()!==i.trim();return{results:c,searching:f||C,failed:m&&!C}}const E={"git-modified":{letter:"M",label:"Modified",textClass:"text-[var(--status-warning)]"},"git-added":{letter:"A",label:"New file",textClass:"text-[var(--status-success)]"},"git-deleted":{letter:"D",label:"Deleted",textClass:"text-[var(--status-error)]"}},H=e=>e in E,O=({status:e,className:t})=>{if(H(e)){const n=E[e];return u.jsx("span",{className:R("w-3 shrink-0 text-center font-mono typography-micro font-semibold",n.textClass,t),title:n.label,"aria-label":n.label,children:n.letter})}const s=e==="open"?"Open in a tab":"Unsaved changes";return u.jsx("span",{className:R("flex w-3 shrink-0 justify-center",t),title:s,"aria-label":s,children:u.jsx("span",{className:R("size-1.5 rounded-full",e==="open"?"bg-[var(--status-info)]":"bg-[var(--status-warning)]")})})},fe=({badge:e,className:t})=>{const s=[e.modified>0?`${e.modified} modified`:null,e.added>0?e.added===1?"1 new file":`${e.added} new files`:null].filter(Boolean);if(s.length===0)return null;const n=s.join(", ");return u.jsx("span",{className:R("flex w-3 shrink-0 justify-center",t),title:n,"aria-label":n,children:u.jsx("span",{className:R("size-1.5 rounded-full",e.modified>0?"bg-[var(--status-warning)]":"bg-[var(--status-success)]")})})},T=(e,t)=>{const s=t?.trim().toLowerCase();if(!s)return e;const n=e.toLowerCase().indexOf(s);return n<0?e:u.jsxs(u.Fragment,{children:[e.slice(0,n),u.jsx("mark",{className:"bg-transparent font-semibold text-foreground",children:e.slice(n,n+s.length)}),e.slice(n+s.length)]})},me=({path:e,status:t,active:s=!1,onClick:n,onDragStart:o,match:i})=>{const c=e.lastIndexOf("/"),r=e.slice(c+1),f=c>=0?e.slice(0,c):"";return u.jsxs("button",{type:"button",onClick:n,draggable:!!o,onDragStart:o,className:R("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left transition-colors",s?"bg-interactive-selection/70":"hover:bg-interactive-hover/40",o&&"cursor-grab active:cursor-grabbing"),title:e,children:[u.jsx(M,{filePath:e}),u.jsx("span",{className:"min-w-0 truncate typography-meta text-foreground",children:T(r,i)}),u.jsx("span",{className:"min-w-0 flex-1 truncate pl-1 typography-meta text-muted-foreground [direction:rtl] [text-align:left]",children:u.jsx("bdi",{children:f})}),t?u.jsx(O,{status:t}):null]})},$=(e,t)=>e.startsWith(`${t}/`)?e.slice(t.length+1):e,V=e=>e.index==="A"||e.working_dir==="?"?"git-added":e.index==="D"?"git-deleted":e.index==="M"||e.working_dir==="M"?"git-modified":null,pe=({root:e,openPaths:t,gitFiles:s})=>{const n=new Set(t),o=new Map,i=new Map,c={modified:0,added:0};for(const a of s??[]){o.has(a.path)||o.set(a.path,a);const m=+(a.index==="M"||a.working_dir==="M"),l=+(a.index==="A"||a.working_dir==="?");if(m===0&&l===0)continue;c.modified+=m,c.added+=l;const C=a.path.split("/");for(let F=1;F<C.length;F+=1){const p=C.slice(0,F).join("/");if(!p)continue;let b=i.get(p);b||(b={modified:0,added:0},i.set(p,b)),b.modified+=m,b.added+=l}}return{getFileStatus:a=>{const m=o.size>0?o.get($(a,e)):void 0,l=m?V(m):null;return l||(n.has(a)?"open":null)},getFolderBadge:a=>{if(!s)return null;const m=$(a,e);if(!m)return c.modified+c.added>0?{...c}:null;const l=i.get(m);return l?{...l}:null}}},ge=e=>new Set(e);export{O as F,re as M,fe as a,X as b,Q as c,de as d,Y as e,me as f,K as g,V as h,te as i,le as j,oe as k,ce as l,ae as m,B as n,h as o,ie as p,ge as q,z as r,ee as s,A as t,ue as u,J as v,ne as w,se as x,pe as y};
7
+ `):s},oe=e=>{if(!e)return!1;const t=e.toLowerCase().split(".").pop();return t==="md"||t==="markdown"},le=e=>{if(!e)return!1;const t=e.toLowerCase().split(".").pop();return t==="json"||t==="jsonc"||t==="json5"||t==="geojson"},ce=e=>{if(!e)return!1;const t=e.toLowerCase().split(".").pop();return t==="html"||t==="htm"};function de({files:e,root:t,selectedPath:s,refreshDirectory:n,removeOpenPathsByPrefix:o,clearSelectedPath:i}){const c=g.useRef(null),[r,f]=g.useState(null),[a,m]=g.useState(null),[l,C]=g.useState(""),[F,p]=g.useState(!1),b=g.useCallback((v,y)=>{f(v),m(y),C(v==="rename"&&y.name||""),p(!1)},[]),x=g.useCallback(()=>f(null),[]),N=g.useCallback(async v=>{if(v?.preventDefault(),!r||!a)return;const y=l.trim();if(r==="createFile"&&!y){w.error("Filename is required");return}if(r==="createFolder"&&!y){w.error("Folder name is required");return}if(r==="rename"&&!y){w.error("Name is required");return}if(r==="createFile"&&!e.writeFile){w.error("Write not supported");return}if(r==="rename"&&!e.rename){w.error("Rename not supported");return}if(r==="delete"&&!e.delete){w.error("Delete not supported");return}p(!0);try{if(r==="createFile"){const d=a.path,S=h(`${d?`${d}/`:""}${y}`);try{(await e.writeFile(S,"",{expectedRevision:null})).success&&(w.success("File created"),await n(d))}catch(j){if(j?.reason==="file-revision-conflict"||j?.name==="FileRevisionConflictError")w.error("File already exists");else throw j}}else if(r==="createFolder"){const d=a.path,S=h(`${d?`${d}/`:""}${y}`);(await e.createDirectory(S)).success&&(w.success("Folder created"),await n(d))}else{const d=a.path,S=d.split("/").slice(0,-1).join("/"),j=s===d||s.startsWith(`${d}/`);(r==="rename"?await e.rename(d,h(`${S?`${S}/`:""}${y}`)):await e.delete(d)).success&&(w.success(r==="rename"?"Renamed successfully":"Deleted successfully"),await n(S),t&&o(t,d),j&&i())}f(null)}catch{w.error("Operation failed")}finally{p(!1)}},[i,e,l,r,n,o,t,s,a]);return{operation:r,target:a,inputValue:l,setInputValue:C,submitting:F,inputRef:c,open:b,close:x,submit:N,capabilities:{canCreateFile:!!e.writeFile,canCreateFolder:!!e.createDirectory,canRename:!!e.rename,canDelete:!!e.delete}}}function ue({directory:e,query:t,chrome:s,showGitignored:n}){const o=_(F=>F.searchFiles),i=P(t,200),[c,r]=g.useState([]),[f,a]=g.useState(!1),[m,l]=g.useState(!1);g.useEffect(()=>{const F=i.trim();if(!e||!F){r([]),a(!1),l(!1);return}let p=!1;return a(!0),l(!1),o(e,F,s==="mobile"?40:150,{includeHidden:!0,respectGitignore:s==="desktop"&&!n,type:"file"}).then(b=>{p||r(b.filter(x=>!W(x.relativePath??x.path)).filter(x=>n||!I(x.path)).map(x=>({name:x.name,path:h(x.path),type:"file",extension:x.extension,relativePath:x.relativePath})))}).catch(()=>{p||(r([]),l(!0))}).finally(()=>{p||a(!1)}),()=>{p=!0}},[s,i,e,o,n]);const C=t.trim()!==""&&t.trim()!==i.trim();return{results:c,searching:f||C,failed:m&&!C}}const E={"git-modified":{letter:"M",label:"Modified",textClass:"text-[var(--status-warning)]"},"git-added":{letter:"A",label:"New file",textClass:"text-[var(--status-success)]"},"git-deleted":{letter:"D",label:"Deleted",textClass:"text-[var(--status-error)]"}},H=e=>e in E,O=({status:e,className:t})=>{if(H(e)){const n=E[e];return u.jsx("span",{className:R("w-3 shrink-0 text-center font-mono typography-micro font-semibold",n.textClass,t),title:n.label,"aria-label":n.label,children:n.letter})}const s=e==="open"?"Open in a tab":"Unsaved changes";return u.jsx("span",{className:R("flex w-3 shrink-0 justify-center",t),title:s,"aria-label":s,children:u.jsx("span",{className:R("size-1.5 rounded-full",e==="open"?"bg-[var(--status-info)]":"bg-[var(--status-warning)]")})})},fe=({badge:e,className:t})=>{const s=[e.modified>0?`${e.modified} modified`:null,e.added>0?e.added===1?"1 new file":`${e.added} new files`:null].filter(Boolean);if(s.length===0)return null;const n=s.join(", ");return u.jsx("span",{className:R("flex w-3 shrink-0 justify-center",t),title:n,"aria-label":n,children:u.jsx("span",{className:R("size-1.5 rounded-full",e.modified>0?"bg-[var(--status-warning)]":"bg-[var(--status-success)]")})})},T=(e,t)=>{const s=t?.trim().toLowerCase();if(!s)return e;const n=e.toLowerCase().indexOf(s);return n<0?e:u.jsxs(u.Fragment,{children:[e.slice(0,n),u.jsx("mark",{className:"bg-transparent font-semibold text-foreground",children:e.slice(n,n+s.length)}),e.slice(n+s.length)]})},me=({path:e,status:t,active:s=!1,onClick:n,onDragStart:o,match:i})=>{const c=e.lastIndexOf("/"),r=e.slice(c+1),f=c>=0?e.slice(0,c):"";return u.jsxs("button",{type:"button",onClick:n,draggable:!!o,onDragStart:o,className:R("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left transition-colors",s?"bg-interactive-selection/70":"hover:bg-interactive-hover/40",o&&"cursor-grab active:cursor-grabbing"),title:e,children:[u.jsx(M,{filePath:e}),u.jsx("span",{className:"min-w-0 truncate typography-meta text-foreground",children:T(r,i)}),u.jsx("span",{className:"min-w-0 flex-1 truncate pl-1 typography-meta text-muted-foreground [direction:rtl] [text-align:left]",children:u.jsx("bdi",{children:f})}),t?u.jsx(O,{status:t}):null]})},z=(e,t)=>e.startsWith(`${t}/`)?e.slice(t.length+1):e,V=e=>e.index==="A"||e.working_dir==="?"?"git-added":e.index==="D"?"git-deleted":e.index==="M"||e.working_dir==="M"?"git-modified":null,pe=({root:e,openPaths:t,gitFiles:s})=>{const n=new Set(t),o=new Map,i=new Map,c={modified:0,added:0};for(const a of s??[]){o.has(a.path)||o.set(a.path,a);const m=+(a.index==="M"||a.working_dir==="M"),l=+(a.index==="A"||a.working_dir==="?");if(m===0&&l===0)continue;c.modified+=m,c.added+=l;const C=a.path.split("/");for(let F=1;F<C.length;F+=1){const p=C.slice(0,F).join("/");if(!p)continue;let b=i.get(p);b||(b={modified:0,added:0},i.set(p,b)),b.modified+=m,b.added+=l}}return{getFileStatus:a=>{const m=o.size>0?o.get(z(a,e)):void 0,l=m?V(m):null;return l||(n.has(a)?"open":null)},getFolderBadge:a=>{if(!s)return null;const m=z(a,e);if(!m)return c.modified+c.added>0?{...c}:null;const l=i.get(m);return l?{...l}:null}}},ge=e=>new Set(e);export{O as F,re as M,fe as a,X as b,J as c,de as d,Y as e,me as f,K as g,V as h,te as i,le as j,oe as k,ce as l,ae as m,B as n,h as o,ie as p,ge as q,A as r,ee as s,$ as t,ue as u,q as v,ne as w,se as x,pe as y};
@@ -1 +1 @@
1
- import{j as e}from"./vendor-boot-Ciu-Edvy.js";import{R as h}from"./vendor-react-Bz1tRBxM.js";import{a$ as y,b0 as N,B as b,I as S,b1 as C,dT as k,dU as r}from"./useAppFontEffects-CoFst31H.js";const B=h.memo(function({scope:n,isGitRepo:a,branchAvailable:i,allCount:o,workingCount:c,stagedCount:d,turnCount:m,branchCount:u,focusedFilePath:l=null,onScopeChange:g}){const[j,x]=h.useState(!1),p=n==="all"?o:n==="staged"?d:n==="turn"?m:n==="branch"?u:c,w=n==="staged"?"Staged":n==="turn"?"Last turn":n==="branch"?"Branch":n==="all"?"All":"Changed";return e.jsxs(y,{open:j,onOpenChange:x,children:[e.jsx(N,{asChild:!0,children:e.jsxs(b,{type:"button",variant:"ghost",size:"sm",className:"h-8 flex-shrink-0 gap-1.5 px-2 py-1 normal-case","aria-label":"Select change mode",children:[e.jsxs("span",{className:"whitespace-nowrap font-medium",children:[w," ",e.jsx("span",{className:"diff-toolbar__scope-count font-normal text-muted-foreground",children:l?`· ${l.split("/").pop()??l}`:p===1?"1 file":`${p} files`})]}),e.jsx(S,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-70"})]})}),e.jsx(C,{align:"start",className:"w-40",children:e.jsxs(k,{value:n,onValueChange:t=>{(t==="all"||t==="working"||t==="staged"||t==="turn"||t==="branch")&&(g?.(t),x(!1))},children:[a!==!1?e.jsx(r,{value:"all",children:e.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[e.jsx("span",{children:"All"}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:o})]})}):null,a!==!1?e.jsx(r,{value:"working",children:e.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[e.jsx("span",{children:"Changed"}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:c})]})}):null,a!==!1?e.jsx(r,{value:"staged",children:e.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[e.jsx("span",{children:"Staged"}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:d})]})}):null,e.jsx(r,{value:"turn",children:e.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[e.jsx("span",{children:"Last turn"}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:m})]})}),i?e.jsx(r,{value:"branch",children:e.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[e.jsx("span",{children:"Branch"}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:u})]})}):null]})})]})}),f={"?":{code:"?",color:"var(--status-info)",description:"Untracked file"},A:{code:"A",color:"var(--status-success)",description:"New file"},D:{code:"D",color:"var(--status-error)",description:"Deleted file"},R:{code:"R",color:"var(--status-info)",description:"Renamed file"},C:{code:"C",color:"var(--status-info)",description:"Copied file"},M:{code:"M",color:"var(--status-warning)",description:"Modified file"}};function _(s){const n=s.index?.trim(),a=s.working_dir?.trim(),i=n&&n!=="?"?n.charAt(0):a?.charAt(0)||n?.charAt(0)||"M";return f[i]??f.M}function A(s){const n=s.index?.trim();return!!(n&&n!=="?")}function M(s){return!!s.working_dir?.trim()||s.index?.trim()==="?"}function I(s){return A(s)&&!M(s)}function O(s){const n=s.index?.trim(),a=s.working_dir?.trim();return n==="A"||a==="A"||n==="?"||a==="?"}export{B as C,M as a,I as b,O as c,_ as d,A as i};
1
+ import{j as e}from"./vendor-boot-3SaHYVb1.js";import{R as h}from"./vendor-react-Bz1tRBxM.js";import{a$ as y,b0 as N,B as b,I as S,b1 as C,d_ as k,d$ as r}from"./useAppFontEffects-Oyin3dgQ.js";const _=h.memo(function({scope:n,isGitRepo:a,branchAvailable:i,allCount:o,workingCount:c,stagedCount:d,turnCount:m,branchCount:u,focusedFilePath:l=null,onScopeChange:g}){const[j,x]=h.useState(!1),p=n==="all"?o:n==="staged"?d:n==="turn"?m:n==="branch"?u:c,w=n==="staged"?"Staged":n==="turn"?"Last turn":n==="branch"?"Branch":n==="all"?"All":"Changed";return e.jsxs(y,{open:j,onOpenChange:x,children:[e.jsx(N,{asChild:!0,children:e.jsxs(b,{type:"button",variant:"ghost",size:"sm",className:"h-8 flex-shrink-0 gap-1.5 px-2 py-1 normal-case","aria-label":"Select change mode",children:[e.jsxs("span",{className:"whitespace-nowrap font-medium",children:[w," ",e.jsx("span",{className:"diff-toolbar__scope-count font-normal text-muted-foreground",children:l?`· ${l.split("/").pop()??l}`:p===1?"1 file":`${p} files`})]}),e.jsx(S,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-70"})]})}),e.jsx(C,{align:"start",className:"w-40",children:e.jsxs(k,{value:n,onValueChange:t=>{(t==="all"||t==="working"||t==="staged"||t==="turn"||t==="branch")&&(g?.(t),x(!1))},children:[a!==!1?e.jsx(r,{value:"all",children:e.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[e.jsx("span",{children:"All"}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:o})]})}):null,a!==!1?e.jsx(r,{value:"working",children:e.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[e.jsx("span",{children:"Changed"}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:c})]})}):null,a!==!1?e.jsx(r,{value:"staged",children:e.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[e.jsx("span",{children:"Staged"}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:d})]})}):null,e.jsx(r,{value:"turn",children:e.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[e.jsx("span",{children:"Last turn"}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:m})]})}),i?e.jsx(r,{value:"branch",children:e.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[e.jsx("span",{children:"Branch"}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:u})]})}):null]})})]})}),f={"?":{code:"?",color:"var(--status-info)",description:"Untracked file"},A:{code:"A",color:"var(--status-success)",description:"New file"},D:{code:"D",color:"var(--status-error)",description:"Deleted file"},R:{code:"R",color:"var(--status-info)",description:"Renamed file"},C:{code:"C",color:"var(--status-info)",description:"Copied file"},M:{code:"M",color:"var(--status-warning)",description:"Modified file"}};function B(s){const n=s.index?.trim(),a=s.working_dir?.trim(),i=n&&n!=="?"?n.charAt(0):a?.charAt(0)||n?.charAt(0)||"M";return f[i]??f.M}function A(s){const n=s.index?.trim();return!!(n&&n!=="?")}function M(s){return!!s.working_dir?.trim()||s.index?.trim()==="?"}function I(s){return A(s)&&!M(s)}function O(s){const n=s.index?.trim(),a=s.working_dir?.trim();return n==="A"||a==="A"||n==="?"||a==="?"}export{_ as C,M as a,I as b,O as c,B as d,A as i};
@@ -1,4 +1,4 @@
1
- import{U as m,V as p,W as u,X as w}from"./GitHubDetailScaffold-a27RksFo.js";import{b$ as f}from"./useAppFontEffects-CoFst31H.js";const x=[{id:"open",label:"Open"},{id:"closed",label:"Closed"},{id:"all",label:"All"}],k=[{id:"all",label:"All"},{id:"mine",label:"Created by me"},{id:"assigned",label:"Assigned to me"},{id:"mentioned",label:"Mentioned"}],y=[{id:"updated",label:"Recently updated"},{id:"newest",label:"Newest"},{id:"oldest",label:"Oldest"}],N=[{id:"completed",label:"Completed"},{id:"not_planned",label:"Not planned"}],_=(e,t,s)=>{if(!t&&e!=="comment")return{allowed:!1,reason:"Issue is still loading"};switch(e){case"close":return t?.state==="closed"?{allowed:!1,reason:"Already closed"}:u(s)?{allowed:!1,reason:"You need write access or be the author to close"}:{allowed:!0,reason:null};case"reopen":return t?.state!=="closed"?{allowed:!1,reason:"Already open"}:u(s)?{allowed:!1,reason:"You need write access or be the author to reopen"}:{allowed:!0,reason:null};case"edit":return u(s)?{allowed:!1,reason:"You need write access or be the author to edit"}:{allowed:!0,reason:null};case"labels":return p(s)?{allowed:!1,reason:"You need write access to change labels"}:{allowed:!0,reason:null};case"assignees":return p(s)?{allowed:!1,reason:"You need write access to change assignees"}:{allowed:!0,reason:null};case"comment":return m(s);default:return{allowed:!0,reason:null}}},E=(e,t)=>{switch(e){case"close-not-planned":return{title:`Close issue #${t} as not planned?`,detail:"The issue will close without being completed. You can reopen it later.",confirm:"Close as not planned",progress:"Closing…"};case"reopen":return{title:`Reopen issue #${t}?`,detail:"The issue will return to its previous open state.",confirm:"Reopen issue",progress:"Reopening…"};default:return{title:`Close issue #${t} as completed?`,detail:"The issue will be recorded as completed. You can reopen it later.",confirm:"Close as completed",progress:"Closing…"}}},L=e=>e==="reopen"?{state:"open"}:{state:"closed",stateReason:e==="close-not-planned"?"not_planned":"completed"},P=e=>{const t={},s=w(e.title,300);return s&&(t.title=s),e.body!==void 0&&e.body.length>2e5&&(t.body="Body is too long"),{ok:Object.keys(t).length===0,errors:t}},A=(e,t)=>e.trim()?t.trim()?`${e.replace(/\s+$/,"")}
1
+ import{U as m,V as p,W as u,X as w}from"./GitHubDetailScaffold-DqxAKqCT.js";import{c6 as f}from"./useAppFontEffects-Oyin3dgQ.js";const x=[{id:"open",label:"Open"},{id:"closed",label:"Closed"},{id:"all",label:"All"}],k=[{id:"all",label:"All"},{id:"mine",label:"Created by me"},{id:"assigned",label:"Assigned to me"},{id:"mentioned",label:"Mentioned"}],y=[{id:"updated",label:"Recently updated"},{id:"newest",label:"Newest"},{id:"oldest",label:"Oldest"}],N=[{id:"completed",label:"Completed"},{id:"not_planned",label:"Not planned"}],_=(e,t,s)=>{if(!t&&e!=="comment")return{allowed:!1,reason:"Issue is still loading"};switch(e){case"close":return t?.state==="closed"?{allowed:!1,reason:"Already closed"}:u(s)?{allowed:!1,reason:"You need write access or be the author to close"}:{allowed:!0,reason:null};case"reopen":return t?.state!=="closed"?{allowed:!1,reason:"Already open"}:u(s)?{allowed:!1,reason:"You need write access or be the author to reopen"}:{allowed:!0,reason:null};case"edit":return u(s)?{allowed:!1,reason:"You need write access or be the author to edit"}:{allowed:!0,reason:null};case"labels":return p(s)?{allowed:!1,reason:"You need write access to change labels"}:{allowed:!0,reason:null};case"assignees":return p(s)?{allowed:!1,reason:"You need write access to change assignees"}:{allowed:!0,reason:null};case"comment":return m(s);default:return{allowed:!0,reason:null}}},E=(e,t)=>{switch(e){case"close-not-planned":return{title:`Close issue #${t} as not planned?`,detail:"The issue will close without being completed. You can reopen it later.",confirm:"Close as not planned",progress:"Closing…"};case"reopen":return{title:`Reopen issue #${t}?`,detail:"The issue will return to its previous open state.",confirm:"Reopen issue",progress:"Reopening…"};default:return{title:`Close issue #${t} as completed?`,detail:"The issue will be recorded as completed. You can reopen it later.",confirm:"Close as completed",progress:"Closing…"}}},L=e=>e==="reopen"?{state:"open"}:{state:"closed",stateReason:e==="close-not-planned"?"not_planned":"completed"},P=e=>{const t={},s=w(e.title,300);return s&&(t.title=s),e.body!==void 0&&e.body.length>2e5&&(t.body="Body is too long"),{ok:Object.keys(t).length===0,errors:t}},A=(e,t)=>e.trim()?t.trim()?`${e.replace(/\s+$/,"")}
2
2
 
3
3
  ${t}`:e:t,h=e=>e.toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40)||"issue",R=(e,t)=>`issue-${e}-${h(t)}`,G=(e,t)=>{const s=e.trim();if(!s)return{link:null,outOfScope:!1};const c=s.match(/^#(\d{1,7})$/);if(c)return{link:{kind:"issue",number:Number(c[1]),owner:"",repo:""},outOfScope:!1};const r=s.match(/^([\w.-]+)\/([\w.-]+)#(\d{1,7})$/);if(r){const l=r[1].toLowerCase(),n=r[2].toLowerCase(),a=Number(r[3]);return t.some(i=>i.owner?.toLowerCase()===l&&i.repo?.toLowerCase()===n)?{link:{kind:"issue",number:a,owner:l,repo:n},outOfScope:!1}:{link:null,outOfScope:!0}}const o=s.match(/^https?:\/\/([^/]+)\/([\w.-]+)\/([\w.-]+)\/(issues|pull)\/(\d{1,7})(?:[/?#].*)?$/i);if(o){const l=o[1].toLowerCase(),n=o[2].toLowerCase(),a=o[3].toLowerCase().replace(/\.git$/,""),d=o[4].toLowerCase()==="pull"?"pr":"issue",i=Number(o[5]);return t.some(b=>b.ref.toLowerCase()===`${l}/${n}/${a}`)?{link:{kind:d,number:i,owner:n,repo:a},outOfScope:!1}:{link:null,outOfScope:!0}}return{link:null,outOfScope:!1}},H=e=>`Work on this GitHub issue. Read the quoted context below, then propose a plan and wait for confirmation before changing code.
4
4
 
@@ -7,4 +7,4 @@ ${e.url}
7
7
 
8
8
  ${e.contextText}`,S="GitHub issue context (JSON)",g="GitHub pull request context (JSON)",C=e=>{const t=e.kind==="pr"?"PR":"Issue",s=e.title.trim()||"(untitled)";return`${t} #${e.number}: ${s}`},T=e=>{const t=e.title.trim()||"(untitled)";return e.kind==="pr"?`${g}
9
9
  ${JSON.stringify({pr:{number:e.number,title:t,url:e.url}})}`:`${S}
10
- ${JSON.stringify({issue:{number:e.number,title:t,url:e.url}})}`},U=()=>({appendVisibleText:e=>{f.getState().setPendingInputText(e,"append")},appendSyntheticText:e=>{const t=f.getState(),s=t.pendingSyntheticParts??[];t.setPendingSyntheticParts([...s,{text:e,synthetic:!0}])}}),V=(e,t)=>{t.appendVisibleText(C(e)),t.appendSyntheticText(T(e)),e.contextText.trim()&&t.appendSyntheticText(e.contextText)};export{N as C,x as I,y as a,k as b,H as c,T as d,V as e,U as f,_ as g,L as h,R as i,E as j,A as k,G as p,h as s,P as v};
10
+ ${JSON.stringify({issue:{number:e.number,title:t,url:e.url}})}`},U=()=>({appendVisibleText:e=>{f.getState().setPendingInputText(e,"append")},appendSyntheticText:e=>{const t=f.getState(),s=t.pendingSyntheticParts??[];t.setPendingSyntheticParts([...s,{text:e,synthetic:!0}])}}),V=(e,t)=>{t.appendVisibleText(C(e)),t.appendSyntheticText(T(e)),e.contextText.trim()&&t.appendSyntheticText(e.contextText)};export{N as C,y as I,k as a,x as b,H as c,T as d,V as e,U as f,_ as g,L as h,R as i,E as j,A as k,G as p,h as s,P as v};
@@ -1 +1 @@
1
- import{dc as v}from"./useAppFontEffects-CoFst31H.js";import{R as L,g as W,r as A,p as M,v as V,a as R,b as P,c as _,d as w,e as C,f as Q,h as I,i as k}from"./computeVirtualFileMetrics-CzkFqhaU.js";import{h as S,i as B,a as T,r as N}from"./renderFileWithHighlighter-B_PFeRW5.js";import{a as p,i as O,r as $,b as j}from"./renderDiffWithHighlighter-CK_inhQE.js";import{t as D}from"./themeResolver-DrfmQi8i.js";import{L as b}from"./vendor-lru_map-BbiDqlyL.js";import"./index-Cfrwo5uQ.js";import"./vendor-zustand-CXhN0IMY.js";import"./vendor-react-Bz1tRBxM.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-BKkUfl9q.js";import"./vendor-fuse.js-t_7AcMTv.js";import"./vendor-boot-Ciu-Edvy.js";import"./runtimeSurface-C3YPOBlg.js";import"./nativeFileSave-P_Eg5Dgb.js";import"./vendor-shiki-BEwTOAFg.js";import"./vendor-shikijs-core-Ck_OPM_T.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-DPFxvYtK.js";import"./vendor-hast-util-to-html-O3stl53j.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-C40bX6nM.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"./vendor-pierre-theming-BO6EPniU.js";import"./vendor-shikijs-engine-javascript-DL394yyj.js";import"./vendor-oniguruma-to-es-DgwFOwdE.js";import"./vendor-oniguruma-parser-BrbMHgHx.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./vendor-diff-C3JhlQdm.js";function z(e){const t=[];for(const i of e){const s=L.get(i);if(s==null)throw new Error(`getResolvedLanguages: ${i} is not resolved. Please resolve languages before calling getResolvedLanguages`);t.push(s)}return t}function E(e){for(const t of Array.isArray(e)?e:[e])if(!L.has(t))return!1;return!0}async function F(e){const t=[],i=[];for(const s of e){if(s==="text"||s==="ansi")continue;const r=W(s)??A(s);"then"in r?i.push(r):t.push(r)}return i.length>0&&await Promise.all(i).then(s=>{for(const r of s){if(r==null)throw new Error("resolvedLanguages: unable to resolve language");t.push(r)}}),t}function x(e){return D.getResolvedThemes(e)}async function K(e){for(const i of e)M(i);const t=await D.resolveThemes(e);for(let i=0;i<e.length;i++)V(e[i],t[i]);return t}const y=Symbol("IGNORE_RESPONSE");var q=class extends Error{constructor(){super("WorkerPoolManager: operation canceled because the pool terminated")}},G=class{options;highlighter;preferredHighlighter;renderOptions;renderOptionsRequestVersion=0;renderOptionsVersion=0;initialized=!1;workers=[];queuedTasks=[];queuedTaskByInstance=new Map;taskByHighlightKey=new Map;activeTaskById=new Map;activeRequestByInstance=new Map;nextRequestId=0;themeSubscribers=new Set;workersFailed=!1;statSubscribers=new Set;fileCache;diffCache;_queuedBroadcast;lifecycleGeneration=0;constructor(e,{langs:t,theme:i=v,useTokenTransformer:s=!1,lineDiffType:r="word-alt",maxLineDiffLength:n=1e3,tokenizeMaxLineLength:a=1e3,preferredHighlighter:o="shiki-js"}){this.options=e,this.preferredHighlighter=o,this.renderOptions={theme:i,useTokenTransformer:s,lineDiffType:r,maxLineDiffLength:n,tokenizeMaxLineLength:a},this.fileCache=new b.LRUMap(e.totalASTLRUCacheSize??100),this.diffCache=new b.LRUMap(e.totalASTLRUCacheSize??100),this.queueInitialization(t)}isWorkingPool(){return!this.workersFailed}getFileResultCache(e){return e.cacheKey!=null?this.fileCache.get(e.cacheKey):void 0}getDiffResultCache(e){return e.cacheKey!=null?this.diffCache.get(e.cacheKey):void 0}inspectCaches(){const{fileCache:e,diffCache:t}=this;return{fileCache:e,diffCache:t}}evictFileFromCache(e){try{return this.fileCache.delete(e)!==void 0}finally{this.queueBroadcastStateChanges()}}evictDiffFromCache(e){try{return this.diffCache.delete(e)!==void 0}finally{this.queueBroadcastStateChanges()}}async setRenderOptions({theme:e=this.renderOptions.theme??v,useTokenTransformer:t=this.renderOptions.useTokenTransformer??!1,lineDiffType:i=this.renderOptions.lineDiffType??"word-alt",maxLineDiffLength:s=this.renderOptions.maxLineDiffLength??1e3,tokenizeMaxLineLength:r=this.renderOptions.tokenizeMaxLineLength??1e3}){const{lifecycleGeneration:n}=this,a=++this.renderOptionsRequestVersion,o=()=>this.isCurrentLifecycle(n)&&this.renderOptionsRequestVersion===a;try{const h={theme:e,useTokenTransformer:t,lineDiffType:i,maxLineDiffLength:s,tokenizeMaxLineLength:r};if(this.isInitialized()||await this.initialize(),!o()||p(h,this.renderOptions))return;const c=R(e);let l=[];if(P(h.theme,this.renderOptions.theme)||(S(c)?l=x(c):l=await K(c)),!o())return;if(this.highlighter!=null)_(l,this.highlighter);else{const m=await w({themes:c,langs:["text"],preferredHighlighter:this.preferredHighlighter});if(!o())return;this.highlighter=m}const g=this.setRenderOptionsOnWorkers(h,l);this.renderOptions=h,this.renderOptionsVersion++,this.diffCache.clear(),this.fileCache.clear(),this.invalidateRenderTasks();for(const m of this.themeSubscribers)m.onThemeChange();await g}catch(h){if(h instanceof q||!o())return;throw h}}getFileRenderOptions(){const{tokenizeMaxLineLength:e,theme:t,useTokenTransformer:i}=this.renderOptions;return{theme:t,useTokenTransformer:i,tokenizeMaxLineLength:e}}getDiffRenderOptions(){return{...this.renderOptions}}async setRenderOptionsOnWorkers(e,t){if(this.workersFailed)return;this.isInitialized()||await this.initialize();const i=[];for(const s of this.workers){if(!s.initialized)throw console.log({managedWorker:s}),new Error("setRenderOptionsOnWorkers: Somehow we have an uninitialized worker");i.push(new Promise((r,n)=>{const a=this.generateRequestId(),o={type:"set-render-options",id:a,request:{type:"set-render-options",id:a,renderOptions:e,resolvedThemes:t},resolve:r,reject:n,requestStart:Date.now()};this.activeTaskById.set(a,o),s.pendingSetupRequestId=a,s.worker.postMessage(o.request)}))}await Promise.all(i)}subscribeToThemeChanges(e){return this.themeSubscribers.add(e),this.queueBroadcastStateChanges(),()=>{this.unsubscribeToThemeChanges(e),this.queueBroadcastStateChanges()}}unsubscribeToThemeChanges(e){this.themeSubscribers.delete(e),this.queueBroadcastStateChanges()}subscribeToStatChanges(e){return this.statSubscribers.add(e),e(this.getStats()),()=>{this.statSubscribers.delete(e)}}queueBroadcastStateChanges(){this._queuedBroadcast==null&&(this._queuedBroadcast=requestAnimationFrame(this._broadcastStateChanges))}_broadcastStateChanges=()=>{this._queuedBroadcast!=null&&(cancelAnimationFrame(this._queuedBroadcast),this._queuedBroadcast=void 0);const e=this.getStats();for(const t of this.statSubscribers)t(e)};cleanUpTasks(e){this.detachInstanceFromQueuedTasks(e);const t=this.activeRequestByInstance.get(e);if(t!=null){const i=this.activeTaskById.get(t);u(i)?(this.detachInstanceFromRenderTask(i,e),!i.primeCache&&i.instances.size===0&&this.removeActiveTask(i)):this.activeTaskById.delete(t)}this.activeRequestByInstance.delete(e),this.queueBroadcastStateChanges()}isInitialized(){return this.initialized===!0}async initialize(e=[]){if(this.initialized!==!0)if(this.initialized===!1){const{lifecycleGeneration:t}=this;this.initialized=new Promise((i,s)=>{(async()=>{try{const r=R(this.renderOptions.theme);let n=[];if(S(r)?n=x(r):n=await K(r),!this.isCurrentLifecycle(t)){i();return}let a=[];if(E(e)?a=z(e):a=await F(e),!this.isCurrentLifecycle(t)){i();return}const[o]=await Promise.all([w({themes:r,langs:["text",...e],preferredHighlighter:this.preferredHighlighter}),this.initializeWorkers(n,a)]);if(!this.isCurrentLifecycle(t)){this.terminateWorkers(),i();return}this.highlighter=o,this.initialized=!0,this.diffCache.clear(),this.fileCache.clear(),this.drainQueue(),this.queueBroadcastStateChanges(),i()}catch(r){if(r instanceof q||!this.isCurrentLifecycle(t)){i();return}this.initialized=!1,this.workersFailed=!0,this.queueBroadcastStateChanges(),s(r)}})()}),this.queueBroadcastStateChanges()}else return this.initialized}async initializeWorkers(e,t){this.workersFailed=!1;const i=[],s=I(),r=s>0?C():void 0;this.workers.length>0&&this.terminateWorkers();for(let n=0;n<(this.options.poolSize??8);n++){const a=this.options.workerFactory(),o={worker:a,requestId:void 0,pendingSetupRequestId:void 0,initialized:!1,langs:new Set(["text",...t.map(({name:h})=>h)]),customExtensionsVersion:0};a.addEventListener("message",h=>{this.handleWorkerMessage(o,h.data)}),a.addEventListener("error",h=>console.error("Worker error:",h,o)),this.workers.push(o),i.push(new Promise((h,c)=>{const l=this.generateRequestId(),g={type:"initialize",id:l,request:{type:"initialize",id:l,renderOptions:this.renderOptions,preferredHighlighter:this.preferredHighlighter,resolvedThemes:e,resolvedLanguages:t,customExtensionsVersion:r!=null?s:void 0,customExtensionMap:r},resolve(){o.initialized=!0,h()},reject:c,requestStart:Date.now()};this.activeTaskById.set(l,g),this.executeTask(o,g)}))}await Promise.all(i)}drainQueue=()=>{if(this._queuedDrain=void 0,!(this.initialized!==!0||this.queuedTasks.length===0)){for(let e=0;e<this.queuedTasks.length;){const t=this.queuedTasks[e];if(this.hasActiveRequest(t)){e++;continue}const i=H(t),s=this.getAvailableWorker(i);if(s==null)break;this.queuedTasks.splice(e,1),this.assignWorkerToTask(t,s),this.resolveLanguagesAndExecuteTask(s,t,i)}this.queueBroadcastStateChanges()}};highlightFileAST(e,t){const i=this.getFileResultCache(t);B(t)||i!=null&&T(i.options,this.getFileRenderOptions())||this.hasMatchingFileInstanceTask(e,t)||this.submitTask(e,{type:"file",file:t})}primeFileHighlightCache(e){if(e.cacheKey==null){console.warn(`WorkerPoolManager.primeFileHighlightCache: priming highlight cache requires file.cacheKey; skipping "${e.name}".`);return}const t=this.getFileResultCache(e),i=this.getFileHighlightKey(e);if(i==null||B(e)||t!=null&&T(t.options,this.getFileRenderOptions()))return;const s=this.getTaskByHighlightKey(i);s!=null?s.primeCache=!0:this.submitCacheTask({type:"file",file:e},i)}getPlainFileAST(e,t,i,s){if(this.highlighter==null){this.queueInitialization();return}return N(e,this.highlighter,this.renderOptions,{forcePlainText:!0,startingLine:t,totalLines:i,lines:s})}highlightDiffAST(e,t){const i=this.getDiffResultCache(t);O(t)||i!=null&&p(i.options,this.getDiffRenderOptions())||this.hasMatchingDiffInstanceTask(e,t)||this.submitTask(e,{type:"diff",diff:t})}primeDiffHighlightCache(e){if(e.cacheKey==null){console.warn(`WorkerPoolManager.primeDiffHighlightCache: priming highlight cache requires diff.cacheKey; skipping "${e.prevName??e.name}" -> "${e.name}".`);return}const t=this.getDiffResultCache(e),i=this.getDiffHighlightKey(e);if(i==null||O(e)||t!=null&&p(t.options,this.getDiffRenderOptions()))return;const s=this.getTaskByHighlightKey(i);s!=null?s.primeCache=!0:this.submitCacheTask({type:"diff",diff:e},i)}getPlainDiffAST(e,t,i,s,r){return this.highlighter!=null?$(e,this.highlighter,this.renderOptions,{forcePlainText:!0,startingLine:t,totalLines:i,expandedHunks:s,collapsedContextThreshold:r}):void 0}terminate(){this.lifecycleGeneration++,this.cancelActiveWorkerTasks(),this.terminateWorkers(),this.fileCache.clear(),this.diffCache.clear(),this.activeRequestByInstance.clear(),this.queuedTasks.length=0,this.queuedTaskByInstance.clear(),this.taskByHighlightKey.clear(),this.activeTaskById.clear(),this.highlighter=void 0,this.initialized=!1,this.workersFailed=!1,this.queueBroadcastStateChanges()}isCurrentLifecycle(e){return this.lifecycleGeneration===e}queueInitialization(e){this.initialize(e).catch(t=>{console.error(t)})}cancelActiveWorkerTasks(){const e=new q;for(const t of this.activeTaskById.values())"reject"in t&&t.reject(e)}terminateWorkers(){for(const e of this.workers)e.worker.terminate();this.workers.length=0}getStats(){return{managerState:this.initialized===!1?"waiting":this.initialized!==!0?"initializing":"initialized",totalWorkers:this.workers.length,workersFailed:this.workersFailed,busyWorkers:this.workers.filter(e=>e.requestId!=null||e.pendingSetupRequestId!=null).length,queuedTasks:this.queuedTasks.length,activeTasks:this.activeTaskById.size,themeSubscribers:this.themeSubscribers.size,fileCacheSize:this.fileCache.size,diffCacheSize:this.diffCache.size}}submitTask(e,t){this.initialized===!1&&this.queueInitialization();const i=this.getHighlightKeyForRequest(t),s=i!=null?this.getTaskByHighlightKey(i):void 0;if(s!=null){this.detachInstanceFromQueuedTasks(e,s),this.addInstanceToTask(s,e),this.queueBroadcastStateChanges();return}this.detachInstanceFromQueuedTasks(e);const r=this.generateRequestId(),n=Date.now(),{renderOptionsVersion:a}=this,o=(()=>{switch(t.type){case"file":return{type:"file",id:r,request:{...t,id:r},instances:new Set([e]),primeCache:!1,highlightKey:i,renderOptionsVersion:a,requestStart:n};case"diff":return{type:"diff",id:r,request:{...t,id:r},instances:new Set([e]),primeCache:!1,highlightKey:i,renderOptionsVersion:a,requestStart:n}}})();this.enqueueRenderTask(o,e)}submitCacheTask(e,t){this.initialized===!1&&this.queueInitialization();const i=this.generateRequestId(),s=Date.now(),{renderOptionsVersion:r}=this,n=(()=>{switch(e.type){case"file":return{type:"file",id:i,request:{...e,id:i},instances:new Set,primeCache:!0,highlightKey:t,renderOptionsVersion:r,requestStart:s};case"diff":return{type:"diff",id:i,request:{...e,id:i},instances:new Set,primeCache:!0,highlightKey:t,renderOptionsVersion:r,requestStart:s}}})();this.enqueueRenderTask(n)}enqueueRenderTask(e,t){this.queuedTasks.push(e),t!=null&&this.queuedTaskByInstance.set(t,e),e.highlightKey!=null&&this.taskByHighlightKey.set(e.highlightKey,e),this.queueDrain()}async resolveLanguagesAndExecuteTask(e,t,i){try{const s=i.filter(r=>!e.langs.has(r));if(s.length>0&&(E(s)?t.request.resolvedLanguages=z(s):t.request.resolvedLanguages=await F(s)),!this.activeTaskById.has(t.id)){e.requestId===t.id&&(this.cleanWorkerAndTask(e,t),this.queueBroadcastStateChanges(),this.queuedTasks.length>0&&this.queueDrain());return}this.executeTask(e,t)}catch{this.cleanWorkerAndTask(e,t),this.queueBroadcastStateChanges(),this.queuedTasks.length>0&&this.queueDrain()}}handleWorkerMessage(e,t){const i=this.activeTaskById.get(t.id);try{if(i==null)throw y;if(t.type==="error"){const s=new Error(t.error);if(t.stack&&(s.stack=t.stack),"reject"in i)i.reject(s);else if(u(i))this.notifyHighlightError(i,s);else throw new Error("handleWorkerMessage: unknown task type");throw s}else switch(t.requestType){case"initialize":if(i.type!=="initialize")throw new Error("handleWorkerMessage: task/response dont match");this.syncCustomExtensionVersion(e,i.request),i.resolve();break;case"set-render-options":if(i.type!=="set-render-options")throw new Error("handleWorkerMessage: task/response dont match");i.resolve();break;case"file":{if(i.type!=="file")throw new Error("handleWorkerMessage: task/response dont match");const{result:s,options:r}=t;if(!this.isCurrentRenderTask(i)||!T(r,this.getFileRenderOptions()))throw y;const{request:n}=i;this.syncCustomExtensionVersion(e,n),n.file.cacheKey!=null&&this.fileCache.set(n.file.cacheKey,{result:s,options:r}),this.notifyFileInstances(i,s,r);break}case"diff":{if(i.type!=="diff")throw new Error("handleWorkerMessage: task/response dont match");const{result:s,options:r}=t;if(!this.isCurrentRenderTask(i)||!p(r,this.getDiffRenderOptions()))throw y;const{request:n}=i;this.syncCustomExtensionVersion(e,n),n.diff.cacheKey!=null&&this.diffCache.set(n.diff.cacheKey,{result:s,options:r}),this.notifyDiffInstances(i,s,r);break}}}catch(s){s!==y&&console.error(s,i,t)}this.cleanWorkerAndTask(e,i,t.id),this.queueBroadcastStateChanges(),this.queuedTasks.length>0&&this.queueDrain()}_queuedDrain;queueDrain(){this._queuedDrain==null&&(this._queuedDrain=Promise.resolve().then(this.drainQueue),this.queueBroadcastStateChanges())}assignWorkerToTask(e,t){t.requestId=e.id,u(e)&&(this.clearQueuedInstanceRequests(e),this.trackInstanceRequests(e)),this.activeTaskById.set(e.id,e)}cleanWorkerAndTask(e,t,i=t?.id){e.requestId===i&&(e.requestId=void 0),e.pendingSetupRequestId===i&&(e.pendingSetupRequestId=void 0),t!=null&&(u(t)&&(this.clearInstanceRequests(t),this.clearHighlightKey(t)),this.activeTaskById.delete(t.id))}executeTask(e,t){U(t.request)&&this.maybeAttachCustomExtensions(e,t.request),this.activeTaskById.has(t.id)||this.assignWorkerToTask(t,e);for(const i of H(t))e.langs.add(i);try{e.worker.postMessage(t.request)}catch(i){console.error("Failed to post message to worker:",i),u(t)?this.notifyHighlightError(t,i):"reject"in t&&t.reject(i),this.cleanWorkerAndTask(e,t),this.queuedTasks.length>0&&this.queueDrain()}this.queueBroadcastStateChanges()}maybeAttachCustomExtensions(e,t){if(t.customExtensionsVersion!=null)return;const i=I();e.customExtensionsVersion>=i||(t.customExtensionsVersion=i,t.customExtensionMap=C())}syncCustomExtensionVersion(e,t){t.customExtensionsVersion!=null&&(e.customExtensionsVersion=t.customExtensionsVersion)}getAvailableWorker(e){let t;for(const i of this.workers){if(i.requestId!=null||i.pendingSetupRequestId!=null||!i.initialized)continue;if(t=i,e.length===0)break;let s=!0;for(const r of e)if(!i.langs.has(r)){s=!1;break}if(s)break}return t}getFileHighlightKey(e){if(e.cacheKey!=null)return`file:${e.cacheKey}:${this.renderOptionsVersion}`}getDiffHighlightKey(e){if(e.cacheKey!=null)return`diff:${e.cacheKey}:${this.renderOptionsVersion}`}getHighlightKeyForRequest(e){switch(e.type){case"file":return this.getFileHighlightKey(e.file);case"diff":return this.getDiffHighlightKey(e.diff)}}hasActiveRequest(e){for(const t of d(e))if(this.activeRequestByInstance.has(t))return!0;return!1}addInstanceToTask(e,t){e.type,e.instances.add(t),this.activeTaskById.has(e.id)?this.activeRequestByInstance.set(t,e.id):this.queuedTaskByInstance.set(t,e)}detachInstanceFromQueuedTasks(e,t){const i=this.queuedTaskByInstance.get(e);i==null||i===t||(this.queuedTaskByInstance.delete(e),this.detachInstanceFromRenderTask(i,e),!i.primeCache&&i.instances.size===0&&this.removeQueuedTask(i))}detachInstanceFromRenderTask(e,t){e.type,e.instances.delete(t)}removeQueuedTask(e){const t=this.queuedTasks.indexOf(e);t!==-1&&this.queuedTasks.splice(t,1),this.clearQueuedInstanceRequests(e),this.clearHighlightKey(e)}removeActiveTask(e){this.clearInstanceRequests(e),this.clearHighlightKey(e),this.activeTaskById.delete(e.id)}invalidateRenderTasks(){for(let e=this.queuedTasks.length-1;e>=0;e--){const t=this.queuedTasks[e];t.renderOptionsVersion!==this.renderOptionsVersion&&this.removeQueuedTask(t)}for(const e of Array.from(this.activeTaskById.values()))u(e)&&e.renderOptionsVersion!==this.renderOptionsVersion&&this.removeActiveTask(e)}clearQueuedInstanceRequests(e){for(const t of d(e))this.queuedTaskByInstance.get(t)===e&&this.queuedTaskByInstance.delete(t)}clearHighlightKey(e){e.highlightKey!=null&&this.taskByHighlightKey.get(e.highlightKey)===e&&this.taskByHighlightKey.delete(e.highlightKey)}trackInstanceRequests(e){for(const t of d(e))this.activeRequestByInstance.set(t,e.id)}clearInstanceRequests(e){for(const t of d(e))this.activeRequestByInstance.get(t)===e.id&&this.activeRequestByInstance.delete(t)}notifyFileInstances(e,t,i){for(const s of e.instances)this.activeRequestByInstance.get(s)===e.id&&s.onHighlightSuccess(e.request.file,t,i)}notifyDiffInstances(e,t,i){for(const s of e.instances)this.activeRequestByInstance.get(s)===e.id&&s.onHighlightSuccess(e.request.diff,t,i)}notifyHighlightError(e,t){for(const i of d(e))this.activeRequestByInstance.get(i)===e.id&&i.onHighlightError(t)}hasMatchingFileInstanceTask(e,t){for(const i of this.iterateRenderTasks())if(i.type==="file"&&this.isCurrentRenderTask(i)&&i.instances.has(e)&&Q(t,i.request.file))return!0;return!1}hasMatchingDiffInstanceTask(e,t){for(const i of this.iterateRenderTasks())if(i.type==="diff"&&this.isCurrentRenderTask(i)&&i.instances.has(e)&&j(i.request.diff,t))return!0;return!1}getTaskByHighlightKey(e){const t=this.taskByHighlightKey.get(e);return t!=null&&this.isCurrentRenderTask(t)?t:void 0}isCurrentRenderTask(e){return e.renderOptionsVersion===this.renderOptionsVersion}*iterateRenderTasks(){for(const e of this.queuedTasks)yield e;for(const e of this.activeTaskById.values())u(e)&&(yield e)}generateRequestId(){return`req_${++this.nextRequestId}`}};function U(e){return e.type==="initialize"||e.type==="file"||e.type==="diff"}function H(e){const t=new Set;if(e.type==="initialize"||e.type==="set-render-options")return[];switch(e.type){case"file":t.add(e.request.file.lang??k(e.request.file.name));break;case"diff":t.add(e.request.diff.lang??k(e.request.diff.name)),t.add(e.request.diff.lang??k(e.request.diff.prevName??"-"));break}return t.delete("text"),Array.from(t)}function u(e){return e?.type==="file"||e?.type==="diff"}function d(e){return e.instances}let f;function De({poolOptions:e,highlighterOptions:t}){return f??=new G(e,t),f}function We(){f!=null&&(f.terminate(),f=void 0)}export{G as WorkerPoolManager,De as getOrCreateWorkerPoolSingleton,We as terminateWorkerPoolSingleton};
1
+ import{dj as v}from"./useAppFontEffects-Oyin3dgQ.js";import{R as L,g as W,r as A,p as M,v as V,a as R,b as P,c as _,d as w,e as C,f as Q,h as I,i as k}from"./computeVirtualFileMetrics-8MuwxSC6.js";import{h as S,i as B,a as T,r as N}from"./renderFileWithHighlighter-DtAcGyJr.js";import{a as p,i as O,r as $,b as j}from"./renderDiffWithHighlighter-B6T04JGG.js";import{t as D}from"./themeResolver-DrfmQi8i.js";import{L as b}from"./vendor-lru_map-BbiDqlyL.js";import"./index-Cs2nBW_t.js";import"./vendor-zustand-CXhN0IMY.js";import"./vendor-react-Bz1tRBxM.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-BKkUfl9q.js";import"./vendor-fuse.js-t_7AcMTv.js";import"./vendor-boot-3SaHYVb1.js";import"./runtimeSurface-DiP2a57a.js";import"./nativeFileSave-DpBH1Sa3.js";import"./vendor-shiki-BEwTOAFg.js";import"./vendor-shikijs-core-Ck_OPM_T.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-DPFxvYtK.js";import"./vendor-hast-util-to-html-O3stl53j.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-C40bX6nM.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"./vendor-pierre-theming-BO6EPniU.js";import"./vendor-shikijs-engine-javascript-DL394yyj.js";import"./vendor-oniguruma-to-es-DgwFOwdE.js";import"./vendor-oniguruma-parser-BrbMHgHx.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./vendor-diff-C3JhlQdm.js";function z(e){const t=[];for(const i of e){const s=L.get(i);if(s==null)throw new Error(`getResolvedLanguages: ${i} is not resolved. Please resolve languages before calling getResolvedLanguages`);t.push(s)}return t}function E(e){for(const t of Array.isArray(e)?e:[e])if(!L.has(t))return!1;return!0}async function F(e){const t=[],i=[];for(const s of e){if(s==="text"||s==="ansi")continue;const r=W(s)??A(s);"then"in r?i.push(r):t.push(r)}return i.length>0&&await Promise.all(i).then(s=>{for(const r of s){if(r==null)throw new Error("resolvedLanguages: unable to resolve language");t.push(r)}}),t}function x(e){return D.getResolvedThemes(e)}async function K(e){for(const i of e)M(i);const t=await D.resolveThemes(e);for(let i=0;i<e.length;i++)V(e[i],t[i]);return t}const y=Symbol("IGNORE_RESPONSE");var q=class extends Error{constructor(){super("WorkerPoolManager: operation canceled because the pool terminated")}},G=class{options;highlighter;preferredHighlighter;renderOptions;renderOptionsRequestVersion=0;renderOptionsVersion=0;initialized=!1;workers=[];queuedTasks=[];queuedTaskByInstance=new Map;taskByHighlightKey=new Map;activeTaskById=new Map;activeRequestByInstance=new Map;nextRequestId=0;themeSubscribers=new Set;workersFailed=!1;statSubscribers=new Set;fileCache;diffCache;_queuedBroadcast;lifecycleGeneration=0;constructor(e,{langs:t,theme:i=v,useTokenTransformer:s=!1,lineDiffType:r="word-alt",maxLineDiffLength:n=1e3,tokenizeMaxLineLength:a=1e3,preferredHighlighter:o="shiki-js"}){this.options=e,this.preferredHighlighter=o,this.renderOptions={theme:i,useTokenTransformer:s,lineDiffType:r,maxLineDiffLength:n,tokenizeMaxLineLength:a},this.fileCache=new b.LRUMap(e.totalASTLRUCacheSize??100),this.diffCache=new b.LRUMap(e.totalASTLRUCacheSize??100),this.queueInitialization(t)}isWorkingPool(){return!this.workersFailed}getFileResultCache(e){return e.cacheKey!=null?this.fileCache.get(e.cacheKey):void 0}getDiffResultCache(e){return e.cacheKey!=null?this.diffCache.get(e.cacheKey):void 0}inspectCaches(){const{fileCache:e,diffCache:t}=this;return{fileCache:e,diffCache:t}}evictFileFromCache(e){try{return this.fileCache.delete(e)!==void 0}finally{this.queueBroadcastStateChanges()}}evictDiffFromCache(e){try{return this.diffCache.delete(e)!==void 0}finally{this.queueBroadcastStateChanges()}}async setRenderOptions({theme:e=this.renderOptions.theme??v,useTokenTransformer:t=this.renderOptions.useTokenTransformer??!1,lineDiffType:i=this.renderOptions.lineDiffType??"word-alt",maxLineDiffLength:s=this.renderOptions.maxLineDiffLength??1e3,tokenizeMaxLineLength:r=this.renderOptions.tokenizeMaxLineLength??1e3}){const{lifecycleGeneration:n}=this,a=++this.renderOptionsRequestVersion,o=()=>this.isCurrentLifecycle(n)&&this.renderOptionsRequestVersion===a;try{const h={theme:e,useTokenTransformer:t,lineDiffType:i,maxLineDiffLength:s,tokenizeMaxLineLength:r};if(this.isInitialized()||await this.initialize(),!o()||p(h,this.renderOptions))return;const c=R(e);let l=[];if(P(h.theme,this.renderOptions.theme)||(S(c)?l=x(c):l=await K(c)),!o())return;if(this.highlighter!=null)_(l,this.highlighter);else{const m=await w({themes:c,langs:["text"],preferredHighlighter:this.preferredHighlighter});if(!o())return;this.highlighter=m}const g=this.setRenderOptionsOnWorkers(h,l);this.renderOptions=h,this.renderOptionsVersion++,this.diffCache.clear(),this.fileCache.clear(),this.invalidateRenderTasks();for(const m of this.themeSubscribers)m.onThemeChange();await g}catch(h){if(h instanceof q||!o())return;throw h}}getFileRenderOptions(){const{tokenizeMaxLineLength:e,theme:t,useTokenTransformer:i}=this.renderOptions;return{theme:t,useTokenTransformer:i,tokenizeMaxLineLength:e}}getDiffRenderOptions(){return{...this.renderOptions}}async setRenderOptionsOnWorkers(e,t){if(this.workersFailed)return;this.isInitialized()||await this.initialize();const i=[];for(const s of this.workers){if(!s.initialized)throw console.log({managedWorker:s}),new Error("setRenderOptionsOnWorkers: Somehow we have an uninitialized worker");i.push(new Promise((r,n)=>{const a=this.generateRequestId(),o={type:"set-render-options",id:a,request:{type:"set-render-options",id:a,renderOptions:e,resolvedThemes:t},resolve:r,reject:n,requestStart:Date.now()};this.activeTaskById.set(a,o),s.pendingSetupRequestId=a,s.worker.postMessage(o.request)}))}await Promise.all(i)}subscribeToThemeChanges(e){return this.themeSubscribers.add(e),this.queueBroadcastStateChanges(),()=>{this.unsubscribeToThemeChanges(e),this.queueBroadcastStateChanges()}}unsubscribeToThemeChanges(e){this.themeSubscribers.delete(e),this.queueBroadcastStateChanges()}subscribeToStatChanges(e){return this.statSubscribers.add(e),e(this.getStats()),()=>{this.statSubscribers.delete(e)}}queueBroadcastStateChanges(){this._queuedBroadcast==null&&(this._queuedBroadcast=requestAnimationFrame(this._broadcastStateChanges))}_broadcastStateChanges=()=>{this._queuedBroadcast!=null&&(cancelAnimationFrame(this._queuedBroadcast),this._queuedBroadcast=void 0);const e=this.getStats();for(const t of this.statSubscribers)t(e)};cleanUpTasks(e){this.detachInstanceFromQueuedTasks(e);const t=this.activeRequestByInstance.get(e);if(t!=null){const i=this.activeTaskById.get(t);u(i)?(this.detachInstanceFromRenderTask(i,e),!i.primeCache&&i.instances.size===0&&this.removeActiveTask(i)):this.activeTaskById.delete(t)}this.activeRequestByInstance.delete(e),this.queueBroadcastStateChanges()}isInitialized(){return this.initialized===!0}async initialize(e=[]){if(this.initialized!==!0)if(this.initialized===!1){const{lifecycleGeneration:t}=this;this.initialized=new Promise((i,s)=>{(async()=>{try{const r=R(this.renderOptions.theme);let n=[];if(S(r)?n=x(r):n=await K(r),!this.isCurrentLifecycle(t)){i();return}let a=[];if(E(e)?a=z(e):a=await F(e),!this.isCurrentLifecycle(t)){i();return}const[o]=await Promise.all([w({themes:r,langs:["text",...e],preferredHighlighter:this.preferredHighlighter}),this.initializeWorkers(n,a)]);if(!this.isCurrentLifecycle(t)){this.terminateWorkers(),i();return}this.highlighter=o,this.initialized=!0,this.diffCache.clear(),this.fileCache.clear(),this.drainQueue(),this.queueBroadcastStateChanges(),i()}catch(r){if(r instanceof q||!this.isCurrentLifecycle(t)){i();return}this.initialized=!1,this.workersFailed=!0,this.queueBroadcastStateChanges(),s(r)}})()}),this.queueBroadcastStateChanges()}else return this.initialized}async initializeWorkers(e,t){this.workersFailed=!1;const i=[],s=I(),r=s>0?C():void 0;this.workers.length>0&&this.terminateWorkers();for(let n=0;n<(this.options.poolSize??8);n++){const a=this.options.workerFactory(),o={worker:a,requestId:void 0,pendingSetupRequestId:void 0,initialized:!1,langs:new Set(["text",...t.map(({name:h})=>h)]),customExtensionsVersion:0};a.addEventListener("message",h=>{this.handleWorkerMessage(o,h.data)}),a.addEventListener("error",h=>console.error("Worker error:",h,o)),this.workers.push(o),i.push(new Promise((h,c)=>{const l=this.generateRequestId(),g={type:"initialize",id:l,request:{type:"initialize",id:l,renderOptions:this.renderOptions,preferredHighlighter:this.preferredHighlighter,resolvedThemes:e,resolvedLanguages:t,customExtensionsVersion:r!=null?s:void 0,customExtensionMap:r},resolve(){o.initialized=!0,h()},reject:c,requestStart:Date.now()};this.activeTaskById.set(l,g),this.executeTask(o,g)}))}await Promise.all(i)}drainQueue=()=>{if(this._queuedDrain=void 0,!(this.initialized!==!0||this.queuedTasks.length===0)){for(let e=0;e<this.queuedTasks.length;){const t=this.queuedTasks[e];if(this.hasActiveRequest(t)){e++;continue}const i=H(t),s=this.getAvailableWorker(i);if(s==null)break;this.queuedTasks.splice(e,1),this.assignWorkerToTask(t,s),this.resolveLanguagesAndExecuteTask(s,t,i)}this.queueBroadcastStateChanges()}};highlightFileAST(e,t){const i=this.getFileResultCache(t);B(t)||i!=null&&T(i.options,this.getFileRenderOptions())||this.hasMatchingFileInstanceTask(e,t)||this.submitTask(e,{type:"file",file:t})}primeFileHighlightCache(e){if(e.cacheKey==null){console.warn(`WorkerPoolManager.primeFileHighlightCache: priming highlight cache requires file.cacheKey; skipping "${e.name}".`);return}const t=this.getFileResultCache(e),i=this.getFileHighlightKey(e);if(i==null||B(e)||t!=null&&T(t.options,this.getFileRenderOptions()))return;const s=this.getTaskByHighlightKey(i);s!=null?s.primeCache=!0:this.submitCacheTask({type:"file",file:e},i)}getPlainFileAST(e,t,i,s){if(this.highlighter==null){this.queueInitialization();return}return N(e,this.highlighter,this.renderOptions,{forcePlainText:!0,startingLine:t,totalLines:i,lines:s})}highlightDiffAST(e,t){const i=this.getDiffResultCache(t);O(t)||i!=null&&p(i.options,this.getDiffRenderOptions())||this.hasMatchingDiffInstanceTask(e,t)||this.submitTask(e,{type:"diff",diff:t})}primeDiffHighlightCache(e){if(e.cacheKey==null){console.warn(`WorkerPoolManager.primeDiffHighlightCache: priming highlight cache requires diff.cacheKey; skipping "${e.prevName??e.name}" -> "${e.name}".`);return}const t=this.getDiffResultCache(e),i=this.getDiffHighlightKey(e);if(i==null||O(e)||t!=null&&p(t.options,this.getDiffRenderOptions()))return;const s=this.getTaskByHighlightKey(i);s!=null?s.primeCache=!0:this.submitCacheTask({type:"diff",diff:e},i)}getPlainDiffAST(e,t,i,s,r){return this.highlighter!=null?$(e,this.highlighter,this.renderOptions,{forcePlainText:!0,startingLine:t,totalLines:i,expandedHunks:s,collapsedContextThreshold:r}):void 0}terminate(){this.lifecycleGeneration++,this.cancelActiveWorkerTasks(),this.terminateWorkers(),this.fileCache.clear(),this.diffCache.clear(),this.activeRequestByInstance.clear(),this.queuedTasks.length=0,this.queuedTaskByInstance.clear(),this.taskByHighlightKey.clear(),this.activeTaskById.clear(),this.highlighter=void 0,this.initialized=!1,this.workersFailed=!1,this.queueBroadcastStateChanges()}isCurrentLifecycle(e){return this.lifecycleGeneration===e}queueInitialization(e){this.initialize(e).catch(t=>{console.error(t)})}cancelActiveWorkerTasks(){const e=new q;for(const t of this.activeTaskById.values())"reject"in t&&t.reject(e)}terminateWorkers(){for(const e of this.workers)e.worker.terminate();this.workers.length=0}getStats(){return{managerState:this.initialized===!1?"waiting":this.initialized!==!0?"initializing":"initialized",totalWorkers:this.workers.length,workersFailed:this.workersFailed,busyWorkers:this.workers.filter(e=>e.requestId!=null||e.pendingSetupRequestId!=null).length,queuedTasks:this.queuedTasks.length,activeTasks:this.activeTaskById.size,themeSubscribers:this.themeSubscribers.size,fileCacheSize:this.fileCache.size,diffCacheSize:this.diffCache.size}}submitTask(e,t){this.initialized===!1&&this.queueInitialization();const i=this.getHighlightKeyForRequest(t),s=i!=null?this.getTaskByHighlightKey(i):void 0;if(s!=null){this.detachInstanceFromQueuedTasks(e,s),this.addInstanceToTask(s,e),this.queueBroadcastStateChanges();return}this.detachInstanceFromQueuedTasks(e);const r=this.generateRequestId(),n=Date.now(),{renderOptionsVersion:a}=this,o=(()=>{switch(t.type){case"file":return{type:"file",id:r,request:{...t,id:r},instances:new Set([e]),primeCache:!1,highlightKey:i,renderOptionsVersion:a,requestStart:n};case"diff":return{type:"diff",id:r,request:{...t,id:r},instances:new Set([e]),primeCache:!1,highlightKey:i,renderOptionsVersion:a,requestStart:n}}})();this.enqueueRenderTask(o,e)}submitCacheTask(e,t){this.initialized===!1&&this.queueInitialization();const i=this.generateRequestId(),s=Date.now(),{renderOptionsVersion:r}=this,n=(()=>{switch(e.type){case"file":return{type:"file",id:i,request:{...e,id:i},instances:new Set,primeCache:!0,highlightKey:t,renderOptionsVersion:r,requestStart:s};case"diff":return{type:"diff",id:i,request:{...e,id:i},instances:new Set,primeCache:!0,highlightKey:t,renderOptionsVersion:r,requestStart:s}}})();this.enqueueRenderTask(n)}enqueueRenderTask(e,t){this.queuedTasks.push(e),t!=null&&this.queuedTaskByInstance.set(t,e),e.highlightKey!=null&&this.taskByHighlightKey.set(e.highlightKey,e),this.queueDrain()}async resolveLanguagesAndExecuteTask(e,t,i){try{const s=i.filter(r=>!e.langs.has(r));if(s.length>0&&(E(s)?t.request.resolvedLanguages=z(s):t.request.resolvedLanguages=await F(s)),!this.activeTaskById.has(t.id)){e.requestId===t.id&&(this.cleanWorkerAndTask(e,t),this.queueBroadcastStateChanges(),this.queuedTasks.length>0&&this.queueDrain());return}this.executeTask(e,t)}catch{this.cleanWorkerAndTask(e,t),this.queueBroadcastStateChanges(),this.queuedTasks.length>0&&this.queueDrain()}}handleWorkerMessage(e,t){const i=this.activeTaskById.get(t.id);try{if(i==null)throw y;if(t.type==="error"){const s=new Error(t.error);if(t.stack&&(s.stack=t.stack),"reject"in i)i.reject(s);else if(u(i))this.notifyHighlightError(i,s);else throw new Error("handleWorkerMessage: unknown task type");throw s}else switch(t.requestType){case"initialize":if(i.type!=="initialize")throw new Error("handleWorkerMessage: task/response dont match");this.syncCustomExtensionVersion(e,i.request),i.resolve();break;case"set-render-options":if(i.type!=="set-render-options")throw new Error("handleWorkerMessage: task/response dont match");i.resolve();break;case"file":{if(i.type!=="file")throw new Error("handleWorkerMessage: task/response dont match");const{result:s,options:r}=t;if(!this.isCurrentRenderTask(i)||!T(r,this.getFileRenderOptions()))throw y;const{request:n}=i;this.syncCustomExtensionVersion(e,n),n.file.cacheKey!=null&&this.fileCache.set(n.file.cacheKey,{result:s,options:r}),this.notifyFileInstances(i,s,r);break}case"diff":{if(i.type!=="diff")throw new Error("handleWorkerMessage: task/response dont match");const{result:s,options:r}=t;if(!this.isCurrentRenderTask(i)||!p(r,this.getDiffRenderOptions()))throw y;const{request:n}=i;this.syncCustomExtensionVersion(e,n),n.diff.cacheKey!=null&&this.diffCache.set(n.diff.cacheKey,{result:s,options:r}),this.notifyDiffInstances(i,s,r);break}}}catch(s){s!==y&&console.error(s,i,t)}this.cleanWorkerAndTask(e,i,t.id),this.queueBroadcastStateChanges(),this.queuedTasks.length>0&&this.queueDrain()}_queuedDrain;queueDrain(){this._queuedDrain==null&&(this._queuedDrain=Promise.resolve().then(this.drainQueue),this.queueBroadcastStateChanges())}assignWorkerToTask(e,t){t.requestId=e.id,u(e)&&(this.clearQueuedInstanceRequests(e),this.trackInstanceRequests(e)),this.activeTaskById.set(e.id,e)}cleanWorkerAndTask(e,t,i=t?.id){e.requestId===i&&(e.requestId=void 0),e.pendingSetupRequestId===i&&(e.pendingSetupRequestId=void 0),t!=null&&(u(t)&&(this.clearInstanceRequests(t),this.clearHighlightKey(t)),this.activeTaskById.delete(t.id))}executeTask(e,t){U(t.request)&&this.maybeAttachCustomExtensions(e,t.request),this.activeTaskById.has(t.id)||this.assignWorkerToTask(t,e);for(const i of H(t))e.langs.add(i);try{e.worker.postMessage(t.request)}catch(i){console.error("Failed to post message to worker:",i),u(t)?this.notifyHighlightError(t,i):"reject"in t&&t.reject(i),this.cleanWorkerAndTask(e,t),this.queuedTasks.length>0&&this.queueDrain()}this.queueBroadcastStateChanges()}maybeAttachCustomExtensions(e,t){if(t.customExtensionsVersion!=null)return;const i=I();e.customExtensionsVersion>=i||(t.customExtensionsVersion=i,t.customExtensionMap=C())}syncCustomExtensionVersion(e,t){t.customExtensionsVersion!=null&&(e.customExtensionsVersion=t.customExtensionsVersion)}getAvailableWorker(e){let t;for(const i of this.workers){if(i.requestId!=null||i.pendingSetupRequestId!=null||!i.initialized)continue;if(t=i,e.length===0)break;let s=!0;for(const r of e)if(!i.langs.has(r)){s=!1;break}if(s)break}return t}getFileHighlightKey(e){if(e.cacheKey!=null)return`file:${e.cacheKey}:${this.renderOptionsVersion}`}getDiffHighlightKey(e){if(e.cacheKey!=null)return`diff:${e.cacheKey}:${this.renderOptionsVersion}`}getHighlightKeyForRequest(e){switch(e.type){case"file":return this.getFileHighlightKey(e.file);case"diff":return this.getDiffHighlightKey(e.diff)}}hasActiveRequest(e){for(const t of d(e))if(this.activeRequestByInstance.has(t))return!0;return!1}addInstanceToTask(e,t){e.type,e.instances.add(t),this.activeTaskById.has(e.id)?this.activeRequestByInstance.set(t,e.id):this.queuedTaskByInstance.set(t,e)}detachInstanceFromQueuedTasks(e,t){const i=this.queuedTaskByInstance.get(e);i==null||i===t||(this.queuedTaskByInstance.delete(e),this.detachInstanceFromRenderTask(i,e),!i.primeCache&&i.instances.size===0&&this.removeQueuedTask(i))}detachInstanceFromRenderTask(e,t){e.type,e.instances.delete(t)}removeQueuedTask(e){const t=this.queuedTasks.indexOf(e);t!==-1&&this.queuedTasks.splice(t,1),this.clearQueuedInstanceRequests(e),this.clearHighlightKey(e)}removeActiveTask(e){this.clearInstanceRequests(e),this.clearHighlightKey(e),this.activeTaskById.delete(e.id)}invalidateRenderTasks(){for(let e=this.queuedTasks.length-1;e>=0;e--){const t=this.queuedTasks[e];t.renderOptionsVersion!==this.renderOptionsVersion&&this.removeQueuedTask(t)}for(const e of Array.from(this.activeTaskById.values()))u(e)&&e.renderOptionsVersion!==this.renderOptionsVersion&&this.removeActiveTask(e)}clearQueuedInstanceRequests(e){for(const t of d(e))this.queuedTaskByInstance.get(t)===e&&this.queuedTaskByInstance.delete(t)}clearHighlightKey(e){e.highlightKey!=null&&this.taskByHighlightKey.get(e.highlightKey)===e&&this.taskByHighlightKey.delete(e.highlightKey)}trackInstanceRequests(e){for(const t of d(e))this.activeRequestByInstance.set(t,e.id)}clearInstanceRequests(e){for(const t of d(e))this.activeRequestByInstance.get(t)===e.id&&this.activeRequestByInstance.delete(t)}notifyFileInstances(e,t,i){for(const s of e.instances)this.activeRequestByInstance.get(s)===e.id&&s.onHighlightSuccess(e.request.file,t,i)}notifyDiffInstances(e,t,i){for(const s of e.instances)this.activeRequestByInstance.get(s)===e.id&&s.onHighlightSuccess(e.request.diff,t,i)}notifyHighlightError(e,t){for(const i of d(e))this.activeRequestByInstance.get(i)===e.id&&i.onHighlightError(t)}hasMatchingFileInstanceTask(e,t){for(const i of this.iterateRenderTasks())if(i.type==="file"&&this.isCurrentRenderTask(i)&&i.instances.has(e)&&Q(t,i.request.file))return!0;return!1}hasMatchingDiffInstanceTask(e,t){for(const i of this.iterateRenderTasks())if(i.type==="diff"&&this.isCurrentRenderTask(i)&&i.instances.has(e)&&j(i.request.diff,t))return!0;return!1}getTaskByHighlightKey(e){const t=this.taskByHighlightKey.get(e);return t!=null&&this.isCurrentRenderTask(t)?t:void 0}isCurrentRenderTask(e){return e.renderOptionsVersion===this.renderOptionsVersion}*iterateRenderTasks(){for(const e of this.queuedTasks)yield e;for(const e of this.activeTaskById.values())u(e)&&(yield e)}generateRequestId(){return`req_${++this.nextRequestId}`}};function U(e){return e.type==="initialize"||e.type==="file"||e.type==="diff"}function H(e){const t=new Set;if(e.type==="initialize"||e.type==="set-render-options")return[];switch(e.type){case"file":t.add(e.request.file.lang??k(e.request.file.name));break;case"diff":t.add(e.request.diff.lang??k(e.request.diff.name)),t.add(e.request.diff.lang??k(e.request.diff.prevName??"-"));break}return t.delete("text"),Array.from(t)}function u(e){return e?.type==="file"||e?.type==="diff"}function d(e){return e.instances}let f;function De({poolOptions:e,highlighterOptions:t}){return f??=new G(e,t),f}function We(){f!=null&&(f.terminate(),f=void 0)}export{G as WorkerPoolManager,De as getOrCreateWorkerPoolSingleton,We as terminateWorkerPoolSingleton};