@pi-chamber/web 1.0.6-rc.3 → 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 (137) hide show
  1. package/dist/assets/{DiagramView-Dq5w8TCG.js → DiagramView--XO16VPB.js} +1 -1
  2. package/dist/assets/DiffView-Duy2_7Gp.js +18 -0
  3. package/dist/assets/{FileSaveConflictDialog-dFqLbFzT.js → FileSaveConflictDialog-B1DvL9zy.js} +2 -2
  4. package/dist/assets/FilesView-CjjPpE4c.js +6 -0
  5. package/dist/assets/{GitHubDetailScaffold-B2HRjT8V.js → GitHubDetailScaffold-DqxAKqCT.js} +4 -4
  6. package/dist/assets/{GitHubLinkPicker-D7I3J9_O.js → GitHubLinkPicker-ELF_chia.js} +1 -1
  7. package/dist/assets/GitHubListPrimitives-C2nGTntk.js +1 -0
  8. package/dist/assets/GitView-5fIq2nzM.js +9 -0
  9. package/dist/assets/IssuesSurface-Dq5A_bWq.js +7 -0
  10. package/dist/assets/{JsonTreeView-BJr5kBg4.js → JsonTreeView-BjFFSUwi.js} +1 -1
  11. package/dist/assets/MarkdownRendererImpl-B9Cu4TCh.js +12 -0
  12. package/dist/assets/{PatchDiff-B6RBZULC.js → PatchDiff-CTqTTcg7.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-YJJQkE7t.js → PierreDiffViewer-H2f4pJ1k.js} +15 -3
  14. package/dist/assets/PullRequestsSurface-DPpb2RW_.js +2 -0
  15. package/dist/assets/SessionSwitcherContent-B5DaBWZU.js +1 -0
  16. package/dist/assets/{SessionSwitcherDropdown-CEAid1Bd.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-5dK-buUn.js → SettingsWindow-Bw1dUoJ1.js} +1 -1
  20. package/dist/assets/{StickyHorizontalScrollbar-p7EbL2-E.js → StickyHorizontalScrollbar-DNsbTLS7.js} +1 -1
  21. package/dist/assets/{ToolOutputDialog-gITobhpo.js → ToolOutputDialog-aR4kcgKL.js} +5 -5
  22. package/dist/assets/{ToolPartDiffPreview-nOJxBl-Y.js → ToolPartDiffPreview-B_wWmhtE.js} +1 -1
  23. package/dist/assets/{VirtualizedFileDiff-BmJk6XJm.js → VirtualizedFileDiff-BYby097w.js} +4 -4
  24. package/dist/assets/{Virtualizer-DNJrJKVb.js → Virtualizer-okhy9Aq3.js} +1 -1
  25. package/dist/assets/{collapsible-0yfy07W2.js → collapsible-Dz0bPrJ_.js} +1 -1
  26. package/dist/assets/{computeVirtualFileMetrics-BCFpa-1q.js → computeVirtualFileMetrics-8MuwxSC6.js} +1 -1
  27. package/dist/assets/{contextFileOpenGuard-BCi5nTZp.js → contextFileOpenGuard-fZ2NIQMQ.js} +1 -1
  28. package/dist/assets/fileTreeStatus-BzhMMLA9.js +7 -0
  29. package/dist/assets/gitStatusPredicates-Cyh9UhYX.js +1 -0
  30. package/dist/assets/{githubLink-CCmFsyTF.js → githubLink-D2PznPcI.js} +2 -2
  31. package/dist/assets/{index-BaeFf5Q8.js → index-BX5pAOQX.js} +1 -1
  32. package/dist/assets/index-Cs2nBW_t.js +11 -0
  33. package/dist/assets/index-tmO0fZa4.css +1 -0
  34. package/dist/assets/main-7vBNPBMb.js +137 -0
  35. package/dist/assets/{main-CgXs2e27.js → main-BI6qe8pz.js} +2 -2
  36. package/dist/assets/{markdownCore-DTNVLpYS.js → markdownCore-D5jiabKe.js} +1 -1
  37. package/dist/assets/{miniChat-CrAin_em.js → miniChat-B3up4Bnz.js} +2 -2
  38. package/dist/assets/{mobile-EK9oTupb.js → mobile-B4vLFgBc.js} +2 -2
  39. package/dist/assets/{nativeFileSave-Bhafll_7.js → nativeFileSave-DpBH1Sa3.js} +1 -1
  40. package/dist/assets/{pi-session-focus-preference-BoN1cyoG.js → pi-session-focus-preference-BrB72skF.js} +3 -3
  41. package/dist/assets/{renderDiffWithHighlighter-DixZh5Zd.js → renderDiffWithHighlighter-B6T04JGG.js} +1 -1
  42. package/dist/assets/renderElectronMiniChatApp-CX10w321.js +2 -0
  43. package/dist/assets/{renderFileWithHighlighter-s6fQq9eg.js → renderFileWithHighlighter-DtAcGyJr.js} +1 -1
  44. package/dist/assets/renderMobileApp-C9n-BhPZ.js +11 -0
  45. package/dist/assets/runtimeEndpointReset-aGyXPXPs.js +62 -0
  46. package/dist/assets/{runtimeSurface-CJN1oo_1.js → runtimeSurface-DiP2a57a.js} +1 -1
  47. package/dist/assets/useAppFontEffects-Oyin3dgQ.js +215 -0
  48. package/dist/assets/useGitHubRemoteSearch-CZ9Hauw0.js +1 -0
  49. package/dist/assets/useSwitcherItems-BSqDA1IF.js +1 -0
  50. package/dist/assets/{vendor-aparajita-capacitor-secure-storage-BLsm9T1Y.js → vendor-aparajita-capacitor-secure-storage-DVZvgYu4.js} +1 -1
  51. package/dist/assets/{vendor-base-ui-C7vVMZTg.js → vendor-base-ui-BCqPBzDj.js} +1 -1
  52. package/dist/assets/{vendor-boot-CoTxysn6.js → vendor-boot-3SaHYVb1.js} +18 -18
  53. package/dist/assets/{vendor-capacitor-app-NX6DULfp.js → vendor-capacitor-app-NbQ-WiPS.js} +1 -1
  54. package/dist/assets/{vendor-capacitor-keyboard-DJD81I9f.js → vendor-capacitor-keyboard-CgrHt8iN.js} +1 -1
  55. package/dist/assets/{vendor-capacitor-status-bar-DV24OoQV.js → vendor-capacitor-status-bar-CWt0OF5t.js} +1 -1
  56. package/dist/assets/{vendor-codemirror-autocomplete-qsuH4Dh-.js → vendor-codemirror-autocomplete-WThuuUAz.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-angular-ZHWyBf7j.js → vendor-codemirror-lang-angular-BbLGCxF6.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-cpp-pCTOmv-k.js → vendor-codemirror-lang-cpp-Cceks-9O.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-css-2bFuyM70.js → vendor-codemirror-lang-css-D1wpUg3Z.js} +1 -1
  60. package/dist/assets/{vendor-codemirror-lang-go-DrG_c7D7.js → vendor-codemirror-lang-go-Cv0zXHHM.js} +1 -1
  61. package/dist/assets/{vendor-codemirror-lang-html-BV8lrR8v.js → vendor-codemirror-lang-html-DbL8oT9H.js} +1 -1
  62. package/dist/assets/{vendor-codemirror-lang-java-DrsvH6T2.js → vendor-codemirror-lang-java-CNugenuC.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-javascript-Dkzl3s07.js → vendor-codemirror-lang-javascript-Bx_FIyZF.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-jinja-8Nn3bnoP.js → vendor-codemirror-lang-jinja-DDGjB3Zq.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-json-CsdmtHhi.js → vendor-codemirror-lang-json-DIvqf9Pb.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-less-DJuZ4cZe.js → vendor-codemirror-lang-less-D8r9dGG1.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-liquid-D2RO-Pzr.js → vendor-codemirror-lang-liquid-B24mguYi.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-markdown-C0Zu3b3n.js → vendor-codemirror-lang-markdown-v3yG2sbf.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-php-CuDtt2Zj.js → vendor-codemirror-lang-php-BcZGalqy.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-python-Cv2exx_M.js → vendor-codemirror-lang-python-b-JqEwQy.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-rust-C4TxJ6Rg.js → vendor-codemirror-lang-rust-B1uZxDW-.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sass-BmtPz8kf.js → vendor-codemirror-lang-sass-DqPrngKp.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-sql-BF1ZaXqJ.js → vendor-codemirror-lang-sql-UyCnpt-k.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-vue-DZgXrP2k.js → vendor-codemirror-lang-vue-xDwYkovV.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-wast-DsnaGtL_.js → vendor-codemirror-lang-wast-CF3169p_.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-xml-D8DzzFat.js → vendor-codemirror-lang-xml-FCtVhuOb.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-yaml-D5hBv7m6.js → vendor-codemirror-lang-yaml-g0sPmAnv.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-language-data-vn2RyN9T.js → vendor-codemirror-language-data-B03xgzP2.js} +2 -2
  79. package/dist/assets/{vendor-codemirror-search-BVCYIV0D.js → vendor-codemirror-search-Dw3Wpu15.js} +1 -1
  80. package/dist/assets/{vendor-lezer-cpp-vqXSn3lv.js → vendor-lezer-cpp-Cu3E-KUI.js} +1 -1
  81. package/dist/assets/{vendor-lezer-css-JnEzSyZR.js → vendor-lezer-css-Cb8vp67u.js} +1 -1
  82. package/dist/assets/{vendor-lezer-go-dD2gQMIL.js → vendor-lezer-go-BTsIaOm7.js} +1 -1
  83. package/dist/assets/{vendor-lezer-html-Cr3U-1pu.js → vendor-lezer-html-UQMsUwj-.js} +1 -1
  84. package/dist/assets/{vendor-lezer-java-CRM0IMCo.js → vendor-lezer-java-BIWrFrAx.js} +1 -1
  85. package/dist/assets/{vendor-lezer-javascript-B3s21DIS.js → vendor-lezer-javascript-BH2Etgoy.js} +1 -1
  86. package/dist/assets/{vendor-lezer-json-DPFM6EBV.js → vendor-lezer-json-CE-QUCwM.js} +1 -1
  87. package/dist/assets/{vendor-lezer-lr-Bllrq8hY.js → vendor-lezer-lr-HY6Yc0Vr.js} +1 -1
  88. package/dist/assets/{vendor-lezer-markdown-6-3PLvXG.js → vendor-lezer-markdown-xFL3Evwf.js} +1 -1
  89. package/dist/assets/{vendor-lezer-php-DOyzfHRl.js → vendor-lezer-php-Cr_mQGrG.js} +1 -1
  90. package/dist/assets/{vendor-lezer-python-CdHdN5qt.js → vendor-lezer-python-BNRFWCb0.js} +1 -1
  91. package/dist/assets/{vendor-lezer-rust-CqnW8EMH.js → vendor-lezer-rust-BvfOK5cU.js} +1 -1
  92. package/dist/assets/{vendor-lezer-sass-BbcF4y6A.js → vendor-lezer-sass-qoxiLisk.js} +1 -1
  93. package/dist/assets/{vendor-lezer-xml-C31AyWoo.js → vendor-lezer-xml--x8SSpqU.js} +1 -1
  94. package/dist/assets/{vendor-lezer-yaml-Cv908yC2.js → vendor-lezer-yaml-BDo1JaEr.js} +1 -1
  95. package/dist/assets/{vendor-replit-codemirror-vim-Cwhyn_5f.js → vendor-replit-codemirror-vim-D1Fe7FiY.js} +1 -1
  96. package/dist/assets/{web-components-Bz5oGa3p.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/git/DOCUMENTATION.md +1 -0
  102. package/server/lib/git/routes.js +14 -0
  103. package/server/lib/git/routes.test.js +37 -0
  104. package/server/lib/git/service.js +27 -0
  105. package/server/lib/git/service.test.js +32 -0
  106. package/server/lib/pi/archive-store.js +38 -10
  107. package/server/lib/pi/archive-store.test.js +10 -0
  108. package/server/lib/pi/routes.js +107 -2
  109. package/server/lib/pi/routes.test.js +255 -0
  110. package/server/lib/pi/session-daemon/DOCUMENTATION.md +5 -1
  111. package/server/lib/pi/session-daemon/session-daemon-engines.test.js +18 -0
  112. package/server/lib/pi/session-daemon/session-daemon.js +24 -1
  113. package/server/lib/pi/session-shelf-store.js +252 -0
  114. package/server/lib/pi/session-shelf-store.test.js +174 -0
  115. package/server/lib/pi/ui-settings-store.js +60 -0
  116. package/server/lib/pi/ui-settings-store.test.js +105 -6
  117. package/dist/assets/DiffView-CFIjN2zy.js +0 -18
  118. package/dist/assets/FilesView-D0b2mEKA.js +0 -6
  119. package/dist/assets/GitHubListPrimitives-Dw5LAmzm.js +0 -1
  120. package/dist/assets/GitView-Dhr7qVeI.js +0 -9
  121. package/dist/assets/IssuesSurface-Bya7OsRl.js +0 -7
  122. package/dist/assets/MarkdownRendererImpl-DadkFPCz.js +0 -12
  123. package/dist/assets/PullRequestsSurface-D8JpzP5l.js +0 -2
  124. package/dist/assets/SessionSwitcherContent-CJ6C2ZKG.js +0 -1
  125. package/dist/assets/SessionUnreadDot-I1_tmqY9.js +0 -1
  126. package/dist/assets/SettingsView-B-b76XDV.js +0 -6
  127. package/dist/assets/gitStatusPredicates-BQOqDJU1.js +0 -1
  128. package/dist/assets/index-C2ISrmRR.js +0 -11
  129. package/dist/assets/index-DgwThEwf.css +0 -1
  130. package/dist/assets/main-DoVzQV56.js +0 -137
  131. package/dist/assets/renderElectronMiniChatApp-0MqKeGfI.js +0 -2
  132. package/dist/assets/renderMobileApp-BLoXL_J8.js +0 -11
  133. package/dist/assets/runtimeEndpointReset-Bv2Y1fMm.js +0 -62
  134. package/dist/assets/useAppFontEffects-D2xXdmYC.js +0 -215
  135. package/dist/assets/useFilesViewSearch-BKotcAUN.js +0 -7
  136. package/dist/assets/useGitHubRemoteSearch-CZ92xKSw.js +0 -1
  137. package/dist/assets/useSwitcherItems-BfA4omGb.js +0 -1
@@ -0,0 +1 @@
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-B2HRjT8V.js";import{bY as f}from"./useAppFontEffects-D2xXdmYC.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}})}`},Y=()=>({appendVisibleText:e=>{f.getState().setPendingInputText(e,"append")},appendSyntheticText:e=>{const t=f.getState(),s=t.pendingSyntheticParts??[];t.setPendingSyntheticParts([...s,{text:e,synthetic:!0}])}}),U=(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,U as e,Y 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{d9 as v}from"./useAppFontEffects-D2xXdmYC.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-BCFpa-1q.js";import{h as S,i as B,a as T,r as N}from"./renderFileWithHighlighter-s6fQq9eg.js";import{a as p,i as O,r as $,b as j}from"./renderDiffWithHighlighter-DixZh5Zd.js";import{t as D}from"./themeResolver-DrfmQi8i.js";import{L as b}from"./vendor-lru_map-BbiDqlyL.js";import"./index-C2ISrmRR.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-CoTxysn6.js";import"./runtimeSurface-CJN1oo_1.js";import"./nativeFileSave-Bhafll_7.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};