@sanurb/ringi 0.2.0 → 0.3.0

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 (423) hide show
  1. package/dist/cli.mjs +2132 -0
  2. package/dist/cli.mjs.map +1 -0
  3. package/dist/mcp.mjs +1057 -0
  4. package/dist/mcp.mjs.map +1 -0
  5. package/dist/runtime.mjs +3116 -0
  6. package/dist/runtime.mjs.map +1 -0
  7. package/package.json +15 -14
  8. package/server/nitro.json +17 -0
  9. package/server/public/assets/ClientOnly-QdfAxyFs.js +1 -0
  10. package/server/public/assets/_reviewId-CmXHvWLn.js +1 -0
  11. package/server/public/assets/_reviewId-DdOpDx4U.js +1 -0
  12. package/server/public/assets/abap-B1dkBSPn.js +1 -0
  13. package/server/public/assets/action-bar-DLRNvLjj.js +45 -0
  14. package/server/public/assets/actionscript-3-BT4ibYlP.js +1 -0
  15. package/server/public/assets/ada-CD92zeps.js +1 -0
  16. package/server/public/assets/andromeeda-DqSmgxi0.js +1 -0
  17. package/server/public/assets/angular-html-BDC0PfKr.js +1 -0
  18. package/server/public/assets/angular-ts-B9yoQMtj.js +1 -0
  19. package/server/public/assets/apache-D5suuoa_.js +1 -0
  20. package/server/public/assets/apex-BL-m4VHy.js +1 -0
  21. package/server/public/assets/apl-CldhY0Pn.js +1 -0
  22. package/server/public/assets/applescript-CLiBqvKT.js +1 -0
  23. package/server/public/assets/ara-LdDF8cmv.js +1 -0
  24. package/server/public/assets/asciidoc-2DZ9hC2N.js +1 -0
  25. package/server/public/assets/asm-0ZPGRSUy.js +1 -0
  26. package/server/public/assets/astro-DR6labZJ.js +1 -0
  27. package/server/public/assets/aurora-x-Da7Zfvbg.js +1 -0
  28. package/server/public/assets/awk-Bn0gn_B_.js +1 -0
  29. package/server/public/assets/ayu-dark-bqYKoqpM.js +1 -0
  30. package/server/public/assets/ayu-light-C45jTIzZ.js +1 -0
  31. package/server/public/assets/ayu-mirage-BV_FCTQi.js +1 -0
  32. package/server/public/assets/ballerina-D2nw_w8Q.js +1 -0
  33. package/server/public/assets/bat-ByUBN5gS.js +1 -0
  34. package/server/public/assets/beancount-BTb2W6Mp.js +1 -0
  35. package/server/public/assets/berry-5SO2uITG.js +1 -0
  36. package/server/public/assets/bibtex-CDBTNfUI.js +1 -0
  37. package/server/public/assets/bicep-fgxG_4rP.js +1 -0
  38. package/server/public/assets/bird2-BCwzDhwX.js +1 -0
  39. package/server/public/assets/blade-BBTRu2-g.js +1 -0
  40. package/server/public/assets/bsl-CG-fq4sc.js +1 -0
  41. package/server/public/assets/c-CEvNj7xl.js +1 -0
  42. package/server/public/assets/c3-Dlaci63_.js +1 -0
  43. package/server/public/assets/cadence-DHbRuEmm.js +1 -0
  44. package/server/public/assets/cairo-Ds0kTeYT.js +1 -0
  45. package/server/public/assets/catppuccin-frappe-DrL1fUuH.js +1 -0
  46. package/server/public/assets/catppuccin-latte-C0REgVjl.js +1 -0
  47. package/server/public/assets/catppuccin-macchiato-ChQpylWO.js +1 -0
  48. package/server/public/assets/catppuccin-mocha-Dd0JU1T0.js +1 -0
  49. package/server/public/assets/clarity-DMoTOm4G.js +1 -0
  50. package/server/public/assets/clojure-DBhE3PpS.js +1 -0
  51. package/server/public/assets/cmake-DwMc40Or.js +1 -0
  52. package/server/public/assets/cobol-BdNJSMRt.js +1 -0
  53. package/server/public/assets/codeowners-1lVr8wqV.js +1 -0
  54. package/server/public/assets/codeql-DWflolvo.js +1 -0
  55. package/server/public/assets/coffee-RA4xA24H.js +1 -0
  56. package/server/public/assets/common-lisp-CrVQ5xT-.js +1 -0
  57. package/server/public/assets/compiler-runtime-DZXZ41-q.js +1 -0
  58. package/server/public/assets/coq-CjfoyYSh.js +1 -0
  59. package/server/public/assets/cpp-BoW7e2Ow.js +1 -0
  60. package/server/public/assets/createServerFn-DTk395iP.js +9 -0
  61. package/server/public/assets/crystal-CYKRo3F9.js +1 -0
  62. package/server/public/assets/csharp-C7bIWP5y.js +1 -0
  63. package/server/public/assets/css-Ck2tii2d.js +1 -0
  64. package/server/public/assets/csv-DsAkDVtA.js +1 -0
  65. package/server/public/assets/cue-BWmQgbOB.js +1 -0
  66. package/server/public/assets/cypher-D-jVC50Q.js +1 -0
  67. package/server/public/assets/d-CaviyOrm.js +1 -0
  68. package/server/public/assets/dark-plus-DIrnwZt9.js +1 -0
  69. package/server/public/assets/dart-CZEi7JgC.js +1 -0
  70. package/server/public/assets/dax-BK-8zffy.js +1 -0
  71. package/server/public/assets/desktop-D3cjbL4D.js +1 -0
  72. package/server/public/assets/diff-sHAzLvlp.js +1 -0
  73. package/server/public/assets/docker--xs2Ng3w.js +1 -0
  74. package/server/public/assets/dotenv-Cm4nwcJ7.js +1 -0
  75. package/server/public/assets/dracula-CAUSusef.js +1 -0
  76. package/server/public/assets/dracula-soft-cjNkMFza.js +1 -0
  77. package/server/public/assets/dream-maker-fjmWTFCO.js +1 -0
  78. package/server/public/assets/edge-DxycC9wl.js +1 -0
  79. package/server/public/assets/elixir-B-50Er3p.js +1 -0
  80. package/server/public/assets/elm-B4-ygIVo.js +1 -0
  81. package/server/public/assets/emacs-lisp-CJzqStIa.js +1 -0
  82. package/server/public/assets/erb-DJvYE1L1.js +1 -0
  83. package/server/public/assets/erlang-C-m_88FN.js +1 -0
  84. package/server/public/assets/everforest-dark-DBpaSMx1.js +1 -0
  85. package/server/public/assets/everforest-light-CiGrXwia.js +1 -0
  86. package/server/public/assets/fennel-DRaXF7k8.js +1 -0
  87. package/server/public/assets/file-tree-CI3Xwwid.js +1907 -0
  88. package/server/public/assets/fish-Bn-Yh3Jj.js +1 -0
  89. package/server/public/assets/fluent-DF5F8Ks_.js +1 -0
  90. package/server/public/assets/fortran-fixed-form-Cx1lv7HN.js +1 -0
  91. package/server/public/assets/fortran-free-form-hCQHRqew.js +1 -0
  92. package/server/public/assets/fsharp-DC5k9sy2.js +1 -0
  93. package/server/public/assets/gdresource-D0EsKdgH.js +1 -0
  94. package/server/public/assets/gdscript-_C9_Hi_w.js +1 -0
  95. package/server/public/assets/gdshader-BW7b1X1Y.js +1 -0
  96. package/server/public/assets/geist-cyrillic-wght-normal-CHSlOQsW.woff2 +0 -0
  97. package/server/public/assets/geist-latin-ext-wght-normal-DMtmJ5ZE.woff2 +0 -0
  98. package/server/public/assets/geist-latin-wght-normal-Dm3htQBi.woff2 +0 -0
  99. package/server/public/assets/genie-Ch_6TCHd.js +1 -0
  100. package/server/public/assets/gherkin-CaNUsmTq.js +1 -0
  101. package/server/public/assets/git-commit-BcFsuO5E.js +1 -0
  102. package/server/public/assets/git-rebase-ChGA-z50.js +1 -0
  103. package/server/public/assets/github-dark-B9ygjgg6.js +1 -0
  104. package/server/public/assets/github-dark-default-Br2bgYSx.js +1 -0
  105. package/server/public/assets/github-dark-dimmed-CmtqpPJ-.js +1 -0
  106. package/server/public/assets/github-dark-high-contrast-fSfmrZcC.js +1 -0
  107. package/server/public/assets/github-light-BZjUqfZl.js +1 -0
  108. package/server/public/assets/github-light-default-lIytXXhR.js +1 -0
  109. package/server/public/assets/github-light-high-contrast-BRrjFb7n.js +1 -0
  110. package/server/public/assets/gleam-DALMDpNs.js +1 -0
  111. package/server/public/assets/glimmer-js-maLb6ysA.js +1 -0
  112. package/server/public/assets/glimmer-ts-DGNr-OBA.js +1 -0
  113. package/server/public/assets/glsl-CmplqyQ1.js +1 -0
  114. package/server/public/assets/gn-DGjqrYN9.js +1 -0
  115. package/server/public/assets/gnuplot-BYckvgQI.js +1 -0
  116. package/server/public/assets/go-JycvP538.js +1 -0
  117. package/server/public/assets/graphql-VhP7n4--.js +1 -0
  118. package/server/public/assets/groovy-D5qMRONT.js +1 -0
  119. package/server/public/assets/gruvbox-dark-hard-M1dj1e6V.js +1 -0
  120. package/server/public/assets/gruvbox-dark-medium-cqq_ncQu.js +1 -0
  121. package/server/public/assets/gruvbox-dark-soft-B4QwL2a9.js +1 -0
  122. package/server/public/assets/gruvbox-light-hard-DLayMKOQ.js +1 -0
  123. package/server/public/assets/gruvbox-light-medium-D52XgPKf.js +1 -0
  124. package/server/public/assets/gruvbox-light-soft-Dola3KdD.js +1 -0
  125. package/server/public/assets/hack-BVSQ2bxM.js +1 -0
  126. package/server/public/assets/haml-CwTtRHoj.js +1 -0
  127. package/server/public/assets/handlebars-CcO01SVo.js +1 -0
  128. package/server/public/assets/haskell-ys7wPPEd.js +1 -0
  129. package/server/public/assets/haxe-94kiChn7.js +1 -0
  130. package/server/public/assets/hcl-DmHt_-wq.js +1 -0
  131. package/server/public/assets/hjson-xMmoJ0Gx.js +1 -0
  132. package/server/public/assets/hlsl-b-Pskdze.js +1 -0
  133. package/server/public/assets/horizon-BKMqttiR.js +1 -0
  134. package/server/public/assets/horizon-bright-HNkBlnm5.js +1 -0
  135. package/server/public/assets/houston-BkBSBSOQ.js +1 -0
  136. package/server/public/assets/html-derivative-Cz-cKMi2.js +1 -0
  137. package/server/public/assets/html-zQbUS8Is.js +1 -0
  138. package/server/public/assets/http-CaGQ9BgA.js +1 -0
  139. package/server/public/assets/hurl-BBoki9bg.js +1 -0
  140. package/server/public/assets/hxml-iQTOTWpM.js +1 -0
  141. package/server/public/assets/hy-DKl1XhBq.js +1 -0
  142. package/server/public/assets/imba-DPxkOTAg.js +1 -0
  143. package/server/public/assets/ini-lkLGq_1x.js +1 -0
  144. package/server/public/assets/java-LAx6oszV.js +1 -0
  145. package/server/public/assets/javascript-COqx-gKX.js +1 -0
  146. package/server/public/assets/jinja-x-G_qSCP.js +1 -0
  147. package/server/public/assets/jison-7oSeVkKJ.js +1 -0
  148. package/server/public/assets/json-sTLOVXhc.js +1 -0
  149. package/server/public/assets/json5-Cy6ypJuJ.js +1 -0
  150. package/server/public/assets/jsonc-Cw2ugYAK.js +1 -0
  151. package/server/public/assets/jsonl-Dp5_qBVH.js +1 -0
  152. package/server/public/assets/jsonnet-BTbmg_-u.js +1 -0
  153. package/server/public/assets/jssm-CnT7nPea.js +1 -0
  154. package/server/public/assets/jsx-zXeIBQLI.js +1 -0
  155. package/server/public/assets/julia-E-6Xm9nd.js +1 -0
  156. package/server/public/assets/just-D9n74gZy.js +1 -0
  157. package/server/public/assets/kanagawa-dragon-CxsBnuhV.js +1 -0
  158. package/server/public/assets/kanagawa-lotus-vHdxDDOS.js +1 -0
  159. package/server/public/assets/kanagawa-wave-CIkfTKWk.js +1 -0
  160. package/server/public/assets/kdl-BwK60g80.js +1 -0
  161. package/server/public/assets/kotlin-Dbd9Vi-v.js +1 -0
  162. package/server/public/assets/kusto-BuTk9usc.js +1 -0
  163. package/server/public/assets/laserwave-C0wf_d3o.js +1 -0
  164. package/server/public/assets/latex-D0t4RtEU.js +1 -0
  165. package/server/public/assets/lean-CYAW8bRN.js +1 -0
  166. package/server/public/assets/less-D4uen21c.js +1 -0
  167. package/server/public/assets/light-plus-oqYyWKEE.js +1 -0
  168. package/server/public/assets/liquid-BzXN12F6.js +1 -0
  169. package/server/public/assets/llvm-Z1xJzteV.js +1 -0
  170. package/server/public/assets/log-BGUxlsk3.js +1 -0
  171. package/server/public/assets/logo-wVUhvQ1b.js +1 -0
  172. package/server/public/assets/lua-B0Cg8RP4.js +1 -0
  173. package/server/public/assets/luau-rPFZzCmq.js +1 -0
  174. package/server/public/assets/main-FvxVz-kD.js +15 -0
  175. package/server/public/assets/make-BmPf6m0P.js +1 -0
  176. package/server/public/assets/markdown-AseU6zcW.js +1 -0
  177. package/server/public/assets/marko-BlRPXWOe.js +1 -0
  178. package/server/public/assets/material-theme-6_W6rQhR.js +1 -0
  179. package/server/public/assets/material-theme-darker-VPEo3Sem.js +1 -0
  180. package/server/public/assets/material-theme-lighter-CUhzCcZ9.js +1 -0
  181. package/server/public/assets/material-theme-ocean-B2JdsaGb.js +1 -0
  182. package/server/public/assets/material-theme-palenight-DhY-sklA.js +1 -0
  183. package/server/public/assets/matlab-BOj_BDQv.js +1 -0
  184. package/server/public/assets/mdc-FiVDZSZ4.js +1 -0
  185. package/server/public/assets/mdx-Cm6cDkDI.js +1 -0
  186. package/server/public/assets/mermaid-DLO-R4hv.js +1 -0
  187. package/server/public/assets/min-dark-D34a_pX7.js +1 -0
  188. package/server/public/assets/min-light-Cdd4KORE.js +1 -0
  189. package/server/public/assets/mipsasm-DYpHF-GA.js +1 -0
  190. package/server/public/assets/mojo-DqYVFv_G.js +1 -0
  191. package/server/public/assets/monokai-CDR4sQ2n.js +1 -0
  192. package/server/public/assets/moonbit-DRKee9wk.js +1 -0
  193. package/server/public/assets/move-DbRk6Vn9.js +1 -0
  194. package/server/public/assets/narrat-IOfmaXfb.js +1 -0
  195. package/server/public/assets/new-DOyplRwM.js +1 -0
  196. package/server/public/assets/nextflow-D-Ec_bsY.js +1 -0
  197. package/server/public/assets/nextflow-groovy-EYl0c2BQ.js +1 -0
  198. package/server/public/assets/nginx-3JLAqmJa.js +1 -0
  199. package/server/public/assets/night-owl-light-Bedht9b4.js +1 -0
  200. package/server/public/assets/night-owl-yQJ3-I0I.js +1 -0
  201. package/server/public/assets/nim-DyjFVMzT.js +1 -0
  202. package/server/public/assets/nix-C2IovEl2.js +1 -0
  203. package/server/public/assets/nord-BjZ63GNL.js +1 -0
  204. package/server/public/assets/nushell-BflTrRB5.js +1 -0
  205. package/server/public/assets/objective-c-GRClK1S7.js +1 -0
  206. package/server/public/assets/objective-cpp-l3qYw-v5.js +1 -0
  207. package/server/public/assets/ocaml-BBDyhyMH.js +1 -0
  208. package/server/public/assets/odin-jCJ7Js99.js +1 -0
  209. package/server/public/assets/one-dark-pro-PIx2Diul.js +1 -0
  210. package/server/public/assets/one-light-BFMEz49S.js +1 -0
  211. package/server/public/assets/openscad-Drf0LgCX.js +1 -0
  212. package/server/public/assets/pascal-BT2XAUTl.js +1 -0
  213. package/server/public/assets/perl-Dr47G_2Q.js +1 -0
  214. package/server/public/assets/php-BhBDWTJe.js +1 -0
  215. package/server/public/assets/pierre-dark-CTXzTLfO.js +1 -0
  216. package/server/public/assets/pierre-light-C_5rlJRo.js +1 -0
  217. package/server/public/assets/pkl-ML-dWShO.js +1 -0
  218. package/server/public/assets/plastic-BFI-Z5Z2.js +1 -0
  219. package/server/public/assets/plsql-0vd5cLro.js +1 -0
  220. package/server/public/assets/po-CbZ_uqQA.js +1 -0
  221. package/server/public/assets/poimandres-Cayhd01L.js +1 -0
  222. package/server/public/assets/polar-C4hfV8Nc.js +1 -0
  223. package/server/public/assets/postcss-osFUbTLw.js +1 -0
  224. package/server/public/assets/powerquery-CTlGUQPj.js +1 -0
  225. package/server/public/assets/powershell-DyZsOmuq.js +1 -0
  226. package/server/public/assets/preload-helper-D7oT-Xwl.js +20 -0
  227. package/server/public/assets/prisma-SS92PO_I.js +1 -0
  228. package/server/public/assets/prolog-B1O1NNVC.js +1 -0
  229. package/server/public/assets/proto-BWu3eZTs.js +1 -0
  230. package/server/public/assets/pug-Dij_IK5w.js +1 -0
  231. package/server/public/assets/puppet-tvtRVdr6.js +1 -0
  232. package/server/public/assets/purescript-Dtbpb7D-.js +1 -0
  233. package/server/public/assets/python-Dlk0Acio.js +1 -0
  234. package/server/public/assets/qml-qUwk3nhh.js +1 -0
  235. package/server/public/assets/qmldir-B-iEOngH.js +1 -0
  236. package/server/public/assets/qss-Ba0p-aHw.js +1 -0
  237. package/server/public/assets/r-WmtNicKM.js +1 -0
  238. package/server/public/assets/racket-BXDsxf2U.js +1 -0
  239. package/server/public/assets/raku-Dw1WWFXK.js +1 -0
  240. package/server/public/assets/razor-DaqiVx3Q.js +1 -0
  241. package/server/public/assets/red-BC3Ds49b.js +1 -0
  242. package/server/public/assets/reg-DXFHGaM4.js +1 -0
  243. package/server/public/assets/regexp-CiSWN5Ne.js +1 -0
  244. package/server/public/assets/rel-Dc5_Ytx2.js +1 -0
  245. package/server/public/assets/reviews-CJvVXRLH.js +1 -0
  246. package/server/public/assets/reviews-CfbuF6ib.js +1 -0
  247. package/server/public/assets/riscv-ZgswiWij.js +1 -0
  248. package/server/public/assets/ron-YghabWAH.js +1 -0
  249. package/server/public/assets/rose-pine-ByWLnVr3.js +1 -0
  250. package/server/public/assets/rose-pine-dawn-DBmeySrz.js +1 -0
  251. package/server/public/assets/rose-pine-moon-B9J-N3nK.js +1 -0
  252. package/server/public/assets/rosmsg-DTKmAsVH.js +1 -0
  253. package/server/public/assets/routes-DNxq1Fba.js +1 -0
  254. package/server/public/assets/routes-Dp0ODZ55.js +2 -0
  255. package/server/public/assets/rst-CP6xOYlY.js +1 -0
  256. package/server/public/assets/ruby-BXYLc1CM.js +1 -0
  257. package/server/public/assets/rust-nfXwuE6F.js +1 -0
  258. package/server/public/assets/sas-CFdtZutF.js +1 -0
  259. package/server/public/assets/sass-CbRjkld3.js +1 -0
  260. package/server/public/assets/scala-BzD3eypx.js +1 -0
  261. package/server/public/assets/scheme-D4d1PV1y.js +1 -0
  262. package/server/public/assets/scss-D8KhdObH.js +1 -0
  263. package/server/public/assets/sdbl-Cf-Ydnvx.js +1 -0
  264. package/server/public/assets/shaderlab-DGohHMiF.js +1 -0
  265. package/server/public/assets/shellscript-BHdEbumI.js +1 -0
  266. package/server/public/assets/shellsession-Dh-bxrap.js +1 -0
  267. package/server/public/assets/slack-dark-MszIyPZ2.js +1 -0
  268. package/server/public/assets/slack-ochin-tQ3Q0gE9.js +1 -0
  269. package/server/public/assets/smalltalk-_uWoArwn.js +1 -0
  270. package/server/public/assets/snazzy-light-9sniMEk5.js +1 -0
  271. package/server/public/assets/solarized-dark-CdD0Hxzv.js +1 -0
  272. package/server/public/assets/solarized-light-C-nsEdqF.js +1 -0
  273. package/server/public/assets/solidity-D6uC-xwP.js +1 -0
  274. package/server/public/assets/soy-cDuODfbT.js +1 -0
  275. package/server/public/assets/sparql-BgU2QITA.js +1 -0
  276. package/server/public/assets/splunk-LQYHRu14.js +1 -0
  277. package/server/public/assets/sql-CKZpK620.js +1 -0
  278. package/server/public/assets/ssh-config-B7BUl8Rd.js +1 -0
  279. package/server/public/assets/stata-BLJTbKOO.js +1 -0
  280. package/server/public/assets/styles-UDowwF7S.css +2 -0
  281. package/server/public/assets/stylus-Byjxdx_q.js +1 -0
  282. package/server/public/assets/surrealql-C96KvYaj.js +1 -0
  283. package/server/public/assets/svelte-Qnbj2GWx.js +1 -0
  284. package/server/public/assets/swift-BexLlMrU.js +1 -0
  285. package/server/public/assets/synthwave-84-BxMBwQMS.js +1 -0
  286. package/server/public/assets/system-verilog-DVGwm0mw.js +1 -0
  287. package/server/public/assets/systemd-H2IT3-p5.js +1 -0
  288. package/server/public/assets/talonscript-mKZIGM8n.js +1 -0
  289. package/server/public/assets/tasl-B7he_Ugr.js +1 -0
  290. package/server/public/assets/tcl-5mT3RxHH.js +1 -0
  291. package/server/public/assets/templ-CQPDll3D.js +1 -0
  292. package/server/public/assets/terraform-BZP0GLsT.js +1 -0
  293. package/server/public/assets/test-D7JRfog1.js +1 -0
  294. package/server/public/assets/tex-97QNLoBJ.js +1 -0
  295. package/server/public/assets/tokyo-night-CTPVdZt9.js +1 -0
  296. package/server/public/assets/toml-CTFA98he.js +1 -0
  297. package/server/public/assets/ts-tags-B8zlXe2n.js +1 -0
  298. package/server/public/assets/tsv-BayJtYdY.js +1 -0
  299. package/server/public/assets/tsx-VqRU8NCz.js +1 -0
  300. package/server/public/assets/turtle-TVCBh_kY.js +1 -0
  301. package/server/public/assets/twig-FTTF8rVk.js +1 -0
  302. package/server/public/assets/typescript-CuX0hIVY.js +1 -0
  303. package/server/public/assets/typespec-BUvaJDLF.js +1 -0
  304. package/server/public/assets/typst-8NBaY7Ec.js +1 -0
  305. package/server/public/assets/useStore-M3H8PB1v.js +1 -0
  306. package/server/public/assets/utils-DElCu2hq.js +1 -0
  307. package/server/public/assets/v-VihyTigi.js +1 -0
  308. package/server/public/assets/vala-DyFAPyX6.js +1 -0
  309. package/server/public/assets/vb-Dg1Iqi4J.js +1 -0
  310. package/server/public/assets/verilog-D2Xc-vhD.js +1 -0
  311. package/server/public/assets/vesper-DJbtqYNr.js +1 -0
  312. package/server/public/assets/vhdl-CU3BVeE7.js +1 -0
  313. package/server/public/assets/viml-hG2shuOW.js +1 -0
  314. package/server/public/assets/vitesse-black-DbG2gsc0.js +1 -0
  315. package/server/public/assets/vitesse-dark-B6WV4xXH.js +1 -0
  316. package/server/public/assets/vitesse-light-DC1pdD02.js +1 -0
  317. package/server/public/assets/vue-DXwaEU0U.js +1 -0
  318. package/server/public/assets/vue-html-QD7AJ6JJ.js +1 -0
  319. package/server/public/assets/vue-vine-Bh2m1D2Z.js +1 -0
  320. package/server/public/assets/vyper-C1wojIuk.js +1 -0
  321. package/server/public/assets/wasm-C6Y0s02M.js +1 -0
  322. package/server/public/assets/wasm-qTvCOSHz.js +1 -0
  323. package/server/public/assets/wenyan-BG5vPQF0.js +1 -0
  324. package/server/public/assets/wgsl-DrVb-Cub.js +1 -0
  325. package/server/public/assets/wikitext-PRC4s8sH.js +1 -0
  326. package/server/public/assets/wit-ChW5qvg_.js +1 -0
  327. package/server/public/assets/wolfram-B8mKuZSQ.js +1 -0
  328. package/server/public/assets/xml-BK-rcb5a.js +1 -0
  329. package/server/public/assets/xsl-dt-d2R7p.js +1 -0
  330. package/server/public/assets/yaml-UiXU3hGj.js +1 -0
  331. package/server/public/assets/zenscript-C-jEPC9j.js +1 -0
  332. package/server/public/assets/zig-EbnRGjcz.js +1 -0
  333. package/server/public/favicon.ico +0 -0
  334. package/server/public/logo192.png +0 -0
  335. package/server/public/logo512.png +0 -0
  336. package/server/public/manifest.json +25 -0
  337. package/server/public/robots.txt +3 -0
  338. package/server/public/tanstack-circle-logo.png +0 -0
  339. package/server/public/tanstack-word-logo-white.svg +1 -0
  340. package/server/server/_chunks/ssr-renderer.mjs +15 -0
  341. package/server/server/_libs/@floating-ui/core+[...].mjs +698 -0
  342. package/server/server/_libs/@floating-ui/dom+[...].mjs +644 -0
  343. package/server/server/_libs/@floating-ui/react-dom+[...].mjs +839 -0
  344. package/server/server/_libs/@pierre/diffs+[...].mjs +18578 -0
  345. package/server/server/_libs/@radix-ui/react-arrow+[...].mjs +174 -0
  346. package/server/server/_libs/@radix-ui/react-collection+[...].mjs +162 -0
  347. package/server/server/_libs/@radix-ui/react-dialog+[...].mjs +1666 -0
  348. package/server/server/_libs/@radix-ui/react-popper+[...].mjs +289 -0
  349. package/server/server/_libs/@radix-ui/react-radio-group+[...].mjs +420 -0
  350. package/server/server/_libs/@radix-ui/react-select+[...].mjs +990 -0
  351. package/server/server/_libs/@tanstack/react-router+[...].mjs +14113 -0
  352. package/server/server/_libs/_.mjs +2 -0
  353. package/server/server/_libs/chokidar+readdirp.mjs +1599 -0
  354. package/server/server/_libs/class-variance-authority+clsx.mjs +69 -0
  355. package/server/server/_libs/effect+[...].mjs +34047 -0
  356. package/server/server/_libs/h3+rou3+srvx.mjs +1195 -0
  357. package/server/server/_libs/hookable.mjs +41 -0
  358. package/server/server/_libs/lucide-react.mjs +298 -0
  359. package/server/server/_libs/pierre__theme.mjs +2668 -0
  360. package/server/server/_libs/radix-ui__number.mjs +6 -0
  361. package/server/server/_libs/radix-ui__primitive.mjs +9 -0
  362. package/server/server/_libs/radix-ui__react-direction.mjs +11 -0
  363. package/server/server/_libs/shiki.mjs +16 -0
  364. package/server/server/_libs/shikijs__langs.mjs +1355 -0
  365. package/server/server/_libs/shikijs__themes.mjs +262 -0
  366. package/server/server/_libs/tailwind-merge.mjs +1962 -0
  367. package/server/server/_libs/tanstack__history.mjs +342 -0
  368. package/server/server/_libs/tanstack__router-core.mjs +6 -0
  369. package/server/server/_libs/ufo.mjs +64 -0
  370. package/server/server/_reviewId-AWnOGz5k.mjs +33 -0
  371. package/server/server/_reviewId-Com4yOlc.mjs +29 -0
  372. package/server/server/_reviewId-DAhmekJ2.mjs +277 -0
  373. package/server/server/_reviewId-p9mhYVwa.mjs +18 -0
  374. package/server/server/_runtime.mjs +35 -0
  375. package/server/server/_ssr/action-bar-C68xGnWW.mjs +592 -0
  376. package/server/server/_ssr/api-handler-CstW2n82.mjs +189 -0
  377. package/server/server/_ssr/client-runtime-BoPuAEoA.mjs +245 -0
  378. package/server/server/_ssr/createServerRpc--0mcGlWK.mjs +12 -0
  379. package/server/server/_ssr/createSsrRpc-AwdiLXmF.mjs +16 -0
  380. package/server/server/_ssr/domain-rpc-3Ds9DPr0.mjs +287 -0
  381. package/server/server/_ssr/file-tree-CQ5w2GHh.mjs +1951 -0
  382. package/server/server/_ssr/load-scoped-diff-NL2XAcdz.mjs +45 -0
  383. package/server/server/_ssr/new-BKl_G2Ks.mjs +37 -0
  384. package/server/server/_ssr/new-BREdMFAM.mjs +12 -0
  385. package/server/server/_ssr/new-DCz5eHkb.mjs +137 -0
  386. package/server/server/_ssr/reviews-BL5Nsgst.mjs +7 -0
  387. package/server/server/_ssr/reviews-BoaEgGKs.mjs +100 -0
  388. package/server/server/_ssr/reviews-C7_NIhY8.mjs +19 -0
  389. package/server/server/_ssr/reviews-Dd69YBDa.mjs +12 -0
  390. package/server/server/_ssr/router-DLxN8FOm.mjs +415 -0
  391. package/server/server/_ssr/routes-D25G8OuS.mjs +80 -0
  392. package/server/server/_ssr/routes-lz0AN75A.mjs +929 -0
  393. package/server/server/_ssr/runtime-D9IbnMlF.mjs +1401 -0
  394. package/server/server/_ssr/server-runtime-D99qpmma.mjs +12 -0
  395. package/server/server/_ssr/ssr.mjs +5318 -0
  396. package/server/server/_ssr/start-BIQfOZtj.mjs +4 -0
  397. package/server/server/_ssr/test-CQdMYlqa.mjs +6 -0
  398. package/server/server/_ssr/todo-m_uUvxca.mjs +88 -0
  399. package/server/server/_ssr/use-keyboard-shortcuts-D5b1Mxpq.mjs +25 -0
  400. package/server/server/_ssr/utils-BuOt9_LA.mjs +8 -0
  401. package/server/server/_tanstack-start-manifest_v-CnL10NRH.mjs +71 -0
  402. package/server/server/index.mjs +2615 -0
  403. package/server/server/node_modules/detect-libc/lib/detect-libc.js +313 -0
  404. package/server/server/node_modules/detect-libc/lib/elf.js +39 -0
  405. package/server/server/node_modules/detect-libc/lib/filesystem.js +51 -0
  406. package/server/server/node_modules/detect-libc/lib/process.js +24 -0
  407. package/server/server/node_modules/detect-libc/package.json +44 -0
  408. package/server/server/node_modules/msgpackr-extract/index.js +1 -0
  409. package/server/server/node_modules/msgpackr-extract/package.json +50 -0
  410. package/server/server/node_modules/node-gyp-build-optional-packages/index.js +6 -0
  411. package/server/server/node_modules/node-gyp-build-optional-packages/node-gyp-build.js +236 -0
  412. package/server/server/node_modules/node-gyp-build-optional-packages/package.json +32 -0
  413. package/server/server/node_modules/tslib/modules/index.js +70 -0
  414. package/server/server/node_modules/tslib/modules/package.json +3 -0
  415. package/server/server/node_modules/tslib/package.json +47 -0
  416. package/server/server/node_modules/tslib/tslib.js +484 -0
  417. package/server/server/package.json +12 -0
  418. package/dist/chunk-KMYSGMD3.js +0 -3526
  419. package/dist/chunk-KMYSGMD3.js.map +0 -1
  420. package/dist/cli.js +0 -1839
  421. package/dist/cli.js.map +0 -1
  422. package/dist/mcp.js +0 -1228
  423. package/dist/mcp.js.map +0 -1
@@ -0,0 +1,3116 @@
1
+ import { execFile, spawn } from "node:child_process";
2
+ import { mkdirSync, stat, unwatchFile, watch, watchFile } from "node:fs";
3
+ import * as sp from "node:path";
4
+ import { dirname, join, relative, resolve, sep } from "node:path";
5
+ import * as Schema from "effect/Schema";
6
+ import { lstat, open, readFile, readdir, realpath, stat as stat$1 } from "node:fs/promises";
7
+ import { randomUUID } from "node:crypto";
8
+ import { ServiceMap } from "effect";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Layer from "effect/Layer";
11
+ import * as Option from "effect/Option";
12
+ import { DatabaseSync } from "node:sqlite";
13
+ import * as Config from "effect/Config";
14
+ import * as Exit from "effect/Exit";
15
+ import "effect/ManagedRuntime";
16
+ import { platform, type } from "node:os";
17
+ import { EventEmitter } from "node:events";
18
+ import { Readable } from "node:stream";
19
+ import * as Queue from "effect/Queue";
20
+ import * as Stream from "effect/Stream";
21
+ //#region ../../packages/core/src/schemas/review.ts
22
+ const ReviewId = Schema.String.pipe(Schema.brand("ReviewId"));
23
+ const ReviewStatus = Schema.Literals([
24
+ "in_progress",
25
+ "approved",
26
+ "changes_requested"
27
+ ]);
28
+ const ReviewSourceType = Schema.Literals([
29
+ "staged",
30
+ "branch",
31
+ "commits",
32
+ "pull_request"
33
+ ]);
34
+ Schema.Struct({
35
+ baseRef: Schema.NullOr(Schema.String),
36
+ createdAt: Schema.String,
37
+ id: ReviewId,
38
+ repositoryPath: Schema.String,
39
+ snapshotData: Schema.String,
40
+ sourceRef: Schema.NullOr(Schema.String),
41
+ sourceType: ReviewSourceType,
42
+ status: ReviewStatus,
43
+ updatedAt: Schema.String
44
+ });
45
+ Schema.Struct({
46
+ sourceRef: Schema.NullOr(Schema.String).pipe(Schema.optionalKey, Schema.withDecodingDefaultKey(() => null)),
47
+ sourceType: ReviewSourceType.pipe(Schema.optionalKey, Schema.withDecodingDefaultKey(() => "staged"))
48
+ });
49
+ Schema.Struct({ status: Schema.OptionFromNullOr(ReviewStatus).pipe(Schema.optionalKey) });
50
+ var ReviewNotFound = class extends Schema.TaggedErrorClass()("ReviewNotFound", { id: ReviewId }) {};
51
+ //#endregion
52
+ //#region ../../packages/core/src/schemas/todo.ts
53
+ const TodoId = Schema.String.pipe(Schema.brand("TodoId"));
54
+ Schema.Struct({
55
+ completed: Schema.Boolean,
56
+ content: Schema.String,
57
+ createdAt: Schema.String,
58
+ id: TodoId,
59
+ position: Schema.Number,
60
+ reviewId: Schema.NullOr(ReviewId),
61
+ updatedAt: Schema.String
62
+ });
63
+ Schema.Struct({
64
+ content: Schema.String.pipe(Schema.check(Schema.isMinLength(1))),
65
+ reviewId: Schema.NullOr(ReviewId).pipe(Schema.optionalKey, Schema.withDecodingDefaultKey(() => null))
66
+ });
67
+ Schema.Struct({
68
+ completed: Schema.OptionFromNullOr(Schema.Boolean).pipe(Schema.optionalKey),
69
+ content: Schema.OptionFromNullOr(Schema.String.pipe(Schema.check(Schema.isMinLength(1)))).pipe(Schema.optionalKey)
70
+ });
71
+ var TodoNotFound = class extends Schema.TaggedErrorClass()("TodoNotFound", { id: TodoId }) {};
72
+ //#endregion
73
+ //#region ../../packages/core/src/db/migrations.ts
74
+ const migrations = [
75
+ `CREATE TABLE IF NOT EXISTS reviews (
76
+ id TEXT PRIMARY KEY,
77
+ repository_path TEXT NOT NULL,
78
+ base_ref TEXT,
79
+ snapshot_data TEXT NOT NULL,
80
+ status TEXT DEFAULT 'in_progress',
81
+ created_at TEXT DEFAULT (datetime('now')),
82
+ updated_at TEXT DEFAULT (datetime('now'))
83
+ ) STRICT`,
84
+ `CREATE TABLE IF NOT EXISTS comments (
85
+ id TEXT PRIMARY KEY,
86
+ review_id TEXT NOT NULL REFERENCES reviews(id) ON DELETE CASCADE,
87
+ file_path TEXT NOT NULL,
88
+ line_number INTEGER,
89
+ line_type TEXT,
90
+ content TEXT NOT NULL,
91
+ suggestion TEXT,
92
+ resolved INTEGER DEFAULT 0,
93
+ created_at TEXT DEFAULT (datetime('now')),
94
+ updated_at TEXT DEFAULT (datetime('now'))
95
+ ) STRICT`,
96
+ `ALTER TABLE reviews ADD COLUMN source_type TEXT DEFAULT 'staged';
97
+ ALTER TABLE reviews ADD COLUMN source_ref TEXT`,
98
+ `CREATE TABLE IF NOT EXISTS todos (
99
+ id TEXT PRIMARY KEY,
100
+ content TEXT NOT NULL,
101
+ completed INTEGER DEFAULT 0,
102
+ review_id TEXT REFERENCES reviews(id) ON DELETE CASCADE,
103
+ created_at TEXT DEFAULT (datetime('now')),
104
+ updated_at TEXT DEFAULT (datetime('now'))
105
+ ) STRICT`,
106
+ `ALTER TABLE todos ADD COLUMN position INTEGER DEFAULT 0`,
107
+ `CREATE TABLE IF NOT EXISTS review_files (
108
+ id TEXT PRIMARY KEY,
109
+ review_id TEXT NOT NULL REFERENCES reviews(id) ON DELETE CASCADE,
110
+ file_path TEXT NOT NULL,
111
+ old_path TEXT,
112
+ status TEXT NOT NULL,
113
+ additions INTEGER NOT NULL DEFAULT 0,
114
+ deletions INTEGER NOT NULL DEFAULT 0,
115
+ hunks_data TEXT,
116
+ created_at TEXT DEFAULT (datetime('now'))
117
+ ) STRICT`
118
+ ];
119
+ /** Apply pending migrations using PRAGMA user_version as the version tracker. */
120
+ const runMigrations = (db) => {
121
+ const currentVersion = db.prepare("PRAGMA user_version").get().user_version;
122
+ for (let i = currentVersion; i < migrations.length; i++) {
123
+ const statements = migrations[i].split(";").map((s) => s.trim()).filter(Boolean);
124
+ for (const sql of statements) db.exec(sql);
125
+ db.exec(`PRAGMA user_version = ${i + 1}`);
126
+ }
127
+ };
128
+ //#endregion
129
+ //#region ../../packages/core/src/db/database.ts
130
+ /**
131
+ * Wraps `body` in a SQLite transaction: BEGIN before, COMMIT on success,
132
+ * ROLLBACK on any failure or interruption.
133
+ */
134
+ const withTransaction = (db, body) => Effect.acquireUseRelease(Effect.sync(() => db.exec("BEGIN")), () => body, (_, exit) => Effect.sync(() => {
135
+ if (Exit.isSuccess(exit)) db.exec("COMMIT");
136
+ else db.exec("ROLLBACK");
137
+ }));
138
+ var SqliteService = class SqliteService extends ServiceMap.Service()("@ringi/SqliteService") {
139
+ static Default = Layer.effect(SqliteService, Effect.gen(function* () {
140
+ const dbPath = yield* Config.string("DB_PATH").pipe(Config.withDefault(".ringi/reviews.db"));
141
+ mkdirSync(dirname(dbPath), { recursive: true });
142
+ const db = new DatabaseSync(dbPath);
143
+ db.exec("PRAGMA journal_mode=WAL");
144
+ db.exec("PRAGMA foreign_keys=ON");
145
+ runMigrations(db);
146
+ return SqliteService.of({ db });
147
+ }));
148
+ };
149
+ //#endregion
150
+ //#region ../../packages/core/src/repos/comment.repo.ts
151
+ const rowToComment = (row) => ({
152
+ content: row.content,
153
+ createdAt: row.created_at,
154
+ filePath: row.file_path,
155
+ id: row.id,
156
+ lineNumber: row.line_number,
157
+ lineType: row.line_type,
158
+ resolved: row.resolved === 1,
159
+ reviewId: row.review_id,
160
+ suggestion: row.suggestion,
161
+ updatedAt: row.updated_at
162
+ });
163
+ var CommentRepo = class CommentRepo extends ServiceMap.Service()("@ringi/CommentRepo") {
164
+ static Default = Layer.effect(CommentRepo, Effect.gen(function* () {
165
+ const { db } = yield* SqliteService;
166
+ const stmtFindById = db.prepare("SELECT * FROM comments WHERE id = ?");
167
+ const stmtFindByReview = db.prepare("SELECT * FROM comments WHERE review_id = ? ORDER BY created_at ASC");
168
+ const stmtFindByFile = db.prepare("SELECT * FROM comments WHERE review_id = ? AND file_path = ? ORDER BY line_number ASC, created_at ASC");
169
+ const stmtInsert = db.prepare(`INSERT INTO comments (id, review_id, file_path, line_number, line_type, content, suggestion, resolved, created_at, updated_at)
170
+ VALUES (?, ?, ?, ?, ?, ?, ?, 0, datetime('now'), datetime('now'))`);
171
+ const stmtDelete = db.prepare("DELETE FROM comments WHERE id = ?");
172
+ const stmtDeleteByReview = db.prepare("DELETE FROM comments WHERE review_id = ?");
173
+ const stmtSetResolved = db.prepare("UPDATE comments SET resolved = ?, updated_at = datetime('now') WHERE id = ?");
174
+ const stmtCountByReview = db.prepare(`SELECT
175
+ COUNT(*) as total,
176
+ SUM(CASE WHEN resolved = 1 THEN 1 ELSE 0 END) as resolved,
177
+ SUM(CASE WHEN resolved = 0 THEN 1 ELSE 0 END) as unresolved,
178
+ SUM(CASE WHEN suggestion IS NOT NULL THEN 1 ELSE 0 END) as with_suggestions
179
+ FROM comments WHERE review_id = ?`);
180
+ const findById = (id) => Effect.sync(() => {
181
+ const row = stmtFindById.get(id);
182
+ return row ? rowToComment(row) : null;
183
+ });
184
+ const findByReview = (reviewId) => Effect.sync(() => {
185
+ return stmtFindByReview.all(reviewId).map(rowToComment);
186
+ });
187
+ const findByFile = (reviewId, filePath) => Effect.sync(() => {
188
+ return stmtFindByFile.all(reviewId, filePath).map(rowToComment);
189
+ });
190
+ const create = (input) => Effect.sync(() => {
191
+ stmtInsert.run(input.id, input.reviewId, input.filePath, input.lineNumber, input.lineType, input.content, input.suggestion);
192
+ return rowToComment(stmtFindById.get(input.id));
193
+ });
194
+ const update = (id, updates) => Effect.sync(() => {
195
+ const setClauses = [];
196
+ const params = [];
197
+ if (updates.content !== void 0) {
198
+ setClauses.push("content = ?");
199
+ params.push(updates.content);
200
+ }
201
+ if (updates.suggestion !== void 0) {
202
+ setClauses.push("suggestion = ?");
203
+ params.push(updates.suggestion);
204
+ }
205
+ if (setClauses.length === 0) {
206
+ const row = stmtFindById.get(id);
207
+ return row ? rowToComment(row) : null;
208
+ }
209
+ setClauses.push("updated_at = datetime('now')");
210
+ params.push(id);
211
+ db.prepare(`UPDATE comments SET ${setClauses.join(", ")} WHERE id = ?`).run(...params);
212
+ const row = stmtFindById.get(id);
213
+ return row ? rowToComment(row) : null;
214
+ });
215
+ const setResolved = (id, resolved) => Effect.sync(() => {
216
+ stmtSetResolved.run(resolved ? 1 : 0, id);
217
+ const row = stmtFindById.get(id);
218
+ return row ? rowToComment(row) : null;
219
+ });
220
+ const remove = (id) => Effect.sync(() => {
221
+ const result = stmtDelete.run(id);
222
+ return Number(result.changes) > 0;
223
+ });
224
+ const removeByReview = (reviewId) => Effect.sync(() => {
225
+ const result = stmtDeleteByReview.run(reviewId);
226
+ return Number(result.changes);
227
+ });
228
+ const countByReview = (reviewId) => Effect.sync(() => {
229
+ const row = stmtCountByReview.get(reviewId);
230
+ return {
231
+ resolved: row.resolved,
232
+ total: row.total,
233
+ unresolved: row.unresolved,
234
+ withSuggestions: row.with_suggestions
235
+ };
236
+ });
237
+ return CommentRepo.of({
238
+ countByReview,
239
+ create,
240
+ findByFile,
241
+ findById,
242
+ findByReview,
243
+ remove,
244
+ removeByReview,
245
+ setResolved,
246
+ update
247
+ });
248
+ }));
249
+ };
250
+ //#endregion
251
+ //#region ../../packages/core/src/schemas/comment.ts
252
+ const CommentId = Schema.String.pipe(Schema.brand("CommentId"));
253
+ const LineType = Schema.Literals([
254
+ "added",
255
+ "removed",
256
+ "context"
257
+ ]);
258
+ Schema.Struct({
259
+ content: Schema.String,
260
+ createdAt: Schema.String,
261
+ filePath: Schema.String,
262
+ id: CommentId,
263
+ lineNumber: Schema.NullOr(Schema.Number),
264
+ lineType: Schema.NullOr(LineType),
265
+ resolved: Schema.Boolean,
266
+ reviewId: ReviewId,
267
+ suggestion: Schema.NullOr(Schema.String),
268
+ updatedAt: Schema.String
269
+ });
270
+ Schema.Struct({
271
+ content: Schema.String.pipe(Schema.check(Schema.isMinLength(1))),
272
+ filePath: Schema.String.pipe(Schema.check(Schema.isMinLength(1))),
273
+ lineNumber: Schema.NullOr(Schema.Number).pipe(Schema.optionalKey, Schema.withDecodingDefaultKey(() => null)),
274
+ lineType: Schema.NullOr(LineType).pipe(Schema.optionalKey, Schema.withDecodingDefaultKey(() => null)),
275
+ suggestion: Schema.NullOr(Schema.String).pipe(Schema.optionalKey, Schema.withDecodingDefaultKey(() => null))
276
+ });
277
+ Schema.Struct({
278
+ content: Schema.OptionFromNullOr(Schema.String.pipe(Schema.check(Schema.isMinLength(1)))).pipe(Schema.optionalKey),
279
+ suggestion: Schema.OptionFromNullOr(Schema.NullOr(Schema.String)).pipe(Schema.optionalKey)
280
+ });
281
+ var CommentNotFound = class extends Schema.TaggedErrorClass()("CommentNotFound", { id: CommentId }) {};
282
+ //#endregion
283
+ //#region ../../packages/core/src/services/comment.service.ts
284
+ var CommentService = class CommentService extends ServiceMap.Service()("@ringi/CommentService") {
285
+ static Default = Layer.effect(CommentService, Effect.gen(function* () {
286
+ const repo = yield* CommentRepo;
287
+ const create = (reviewId, input) => {
288
+ const id = randomUUID();
289
+ return repo.create({
290
+ content: input.content,
291
+ filePath: input.filePath,
292
+ id,
293
+ lineNumber: input.lineNumber ?? null,
294
+ lineType: input.lineType ?? null,
295
+ reviewId,
296
+ suggestion: input.suggestion ?? null
297
+ });
298
+ };
299
+ const getById = (id) => Effect.gen(function* () {
300
+ const comment = yield* repo.findById(id);
301
+ if (!comment) return yield* new CommentNotFound({ id });
302
+ return comment;
303
+ });
304
+ const getByReview = (reviewId) => repo.findByReview(reviewId);
305
+ const getByFile = (reviewId, filePath) => repo.findByFile(reviewId, filePath);
306
+ const update = (id, input) => Effect.gen(function* () {
307
+ const updates = {};
308
+ if (input.content && Option.isSome(input.content)) updates.content = input.content.value;
309
+ if (input.suggestion && Option.isSome(input.suggestion)) updates.suggestion = input.suggestion.value;
310
+ const comment = yield* repo.update(id, updates);
311
+ if (!comment) return yield* new CommentNotFound({ id });
312
+ return comment;
313
+ });
314
+ const resolve = (id) => Effect.gen(function* () {
315
+ const comment = yield* repo.setResolved(id, true);
316
+ if (!comment) return yield* new CommentNotFound({ id });
317
+ return comment;
318
+ });
319
+ const unresolve = (id) => Effect.gen(function* () {
320
+ const comment = yield* repo.setResolved(id, false);
321
+ if (!comment) return yield* new CommentNotFound({ id });
322
+ return comment;
323
+ });
324
+ const remove = (id) => Effect.gen(function* () {
325
+ if (!(yield* repo.remove(id))) return yield* new CommentNotFound({ id });
326
+ return { success: true };
327
+ });
328
+ const getStats = (reviewId) => repo.countByReview(reviewId);
329
+ return CommentService.of({
330
+ create,
331
+ getByFile,
332
+ getById,
333
+ getByReview,
334
+ getStats,
335
+ remove,
336
+ resolve,
337
+ unresolve,
338
+ update
339
+ });
340
+ }));
341
+ };
342
+ //#endregion
343
+ //#region ../../packages/core/src/services/diff.service.ts
344
+ const HUNK_HEADER = /@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
345
+ const splitIntoFiles = (diffText) => {
346
+ const files = [];
347
+ const lines = diffText.split("\n");
348
+ let current = [];
349
+ for (const line of lines) if (line.startsWith("diff --git")) {
350
+ if (current.length > 0) files.push(current.join("\n"));
351
+ current = [line];
352
+ } else current.push(line);
353
+ if (current.length > 0) files.push(current.join("\n"));
354
+ return files;
355
+ };
356
+ const parseHunks$1 = (lines) => {
357
+ const hunks = [];
358
+ let currentHunk = null;
359
+ let oldLineNum = 0;
360
+ let newLineNum = 0;
361
+ for (const line of lines) {
362
+ const match = line.match(HUNK_HEADER);
363
+ if (match) {
364
+ if (currentHunk) hunks.push(currentHunk);
365
+ const oldStart = Number.parseInt(match[1], 10);
366
+ const oldLines = Number.parseInt(match[2] ?? "1", 10);
367
+ const newStart = Number.parseInt(match[3], 10);
368
+ currentHunk = {
369
+ lines: [],
370
+ newLines: Number.parseInt(match[4] ?? "1", 10),
371
+ newStart,
372
+ oldLines,
373
+ oldStart
374
+ };
375
+ oldLineNum = oldStart;
376
+ newLineNum = newStart;
377
+ continue;
378
+ }
379
+ if (!currentHunk) continue;
380
+ if (line.startsWith("+") && !line.startsWith("+++")) currentHunk.lines.push({
381
+ content: line.slice(1),
382
+ newLineNumber: newLineNum++,
383
+ oldLineNumber: null,
384
+ type: "added"
385
+ });
386
+ else if (line.startsWith("-") && !line.startsWith("---")) currentHunk.lines.push({
387
+ content: line.slice(1),
388
+ newLineNumber: null,
389
+ oldLineNumber: oldLineNum++,
390
+ type: "removed"
391
+ });
392
+ else if (line.startsWith(" ")) currentHunk.lines.push({
393
+ content: line.slice(1),
394
+ newLineNumber: newLineNum++,
395
+ oldLineNumber: oldLineNum++,
396
+ type: "context"
397
+ });
398
+ }
399
+ if (currentHunk) hunks.push(currentHunk);
400
+ return hunks;
401
+ };
402
+ const parseFileDiff = (fileDiff) => {
403
+ const lines = fileDiff.split("\n");
404
+ const diffLine = lines.find((l) => l.startsWith("diff --git"));
405
+ if (!diffLine) return null;
406
+ const pathMatch = diffLine.match(/diff --git a\/(.+) b\/(.+)/);
407
+ if (!pathMatch) return null;
408
+ const oldPath = pathMatch[1];
409
+ const newPath = pathMatch[2];
410
+ let status = "modified";
411
+ if (lines.some((l) => l.startsWith("deleted file mode"))) status = "deleted";
412
+ else if (lines.some((l) => l.startsWith("new file mode"))) status = "added";
413
+ else if (lines.some((l) => l.startsWith("rename from")) || oldPath !== newPath) status = "renamed";
414
+ const hunks = parseHunks$1(lines);
415
+ let additions = 0;
416
+ let deletions = 0;
417
+ for (const hunk of hunks) for (const line of hunk.lines) if (line.type === "added") additions++;
418
+ else if (line.type === "removed") deletions++;
419
+ return {
420
+ additions,
421
+ deletions,
422
+ hunks,
423
+ newPath,
424
+ oldPath,
425
+ status
426
+ };
427
+ };
428
+ /** Parse a full multi-file unified diff into structured DiffFile objects. */
429
+ const parseDiff = (diffText) => {
430
+ if (!diffText.trim()) return [];
431
+ const blocks = splitIntoFiles(diffText);
432
+ const files = [];
433
+ for (const block of blocks) {
434
+ const parsed = parseFileDiff(block);
435
+ if (parsed) files.push(parsed);
436
+ }
437
+ return files;
438
+ };
439
+ /** Aggregate stats from already-parsed files. */
440
+ const getDiffSummary = (files) => {
441
+ let totalAdditions = 0;
442
+ let totalDeletions = 0;
443
+ for (const file of files) {
444
+ totalAdditions += file.additions;
445
+ totalDeletions += file.deletions;
446
+ }
447
+ return {
448
+ filesAdded: files.filter((f) => f.status === "added").length,
449
+ filesDeleted: files.filter((f) => f.status === "deleted").length,
450
+ filesModified: files.filter((f) => f.status === "modified").length,
451
+ filesRenamed: files.filter((f) => f.status === "renamed").length,
452
+ totalAdditions,
453
+ totalDeletions,
454
+ totalFiles: files.length
455
+ };
456
+ };
457
+ //#endregion
458
+ //#region ../../packages/core/src/repos/review-file.repo.ts
459
+ const parseHunks = (hunksData) => hunksData == null ? Effect.succeed([]) : Effect.try({
460
+ try: () => JSON.parse(hunksData),
461
+ catch: () => []
462
+ }).pipe(Effect.orElseSucceed(() => []));
463
+ const serializeHunks = (hunks) => JSON.stringify(hunks);
464
+ var ReviewFileRepo = class ReviewFileRepo extends ServiceMap.Service()("@ringi/ReviewFileRepo") {
465
+ static Default = Layer.effect(ReviewFileRepo, Effect.gen(function* () {
466
+ const { db } = yield* SqliteService;
467
+ const stmtFindByReview = db.prepare(`SELECT id, review_id, file_path, old_path, status, additions, deletions, created_at
468
+ FROM review_files WHERE review_id = ? ORDER BY file_path`);
469
+ const stmtFindByReviewAndPath = db.prepare("SELECT * FROM review_files WHERE review_id = ? AND file_path = ?");
470
+ const stmtInsert = db.prepare(`INSERT INTO review_files (id, review_id, file_path, old_path, status, additions, deletions, hunks_data, created_at)
471
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))`);
472
+ const stmtDeleteByReview = db.prepare("DELETE FROM review_files WHERE review_id = ?");
473
+ const stmtCountByReview = db.prepare("SELECT COUNT(*) as count FROM review_files WHERE review_id = ?");
474
+ const findByReview = (reviewId) => Effect.sync(() => stmtFindByReview.all(reviewId));
475
+ const findByReviewAndPath = (reviewId, filePath) => Effect.sync(() => {
476
+ return stmtFindByReviewAndPath.get(reviewId, filePath) ?? null;
477
+ });
478
+ const createBulk = (files) => withTransaction(db, Effect.sync(() => {
479
+ for (const f of files) stmtInsert.run(randomUUID(), f.reviewId, f.filePath, f.oldPath, f.status, f.additions, f.deletions, f.hunksData);
480
+ }));
481
+ const deleteByReview = (reviewId) => Effect.sync(() => {
482
+ const result = stmtDeleteByReview.run(reviewId);
483
+ return Number(result.changes);
484
+ });
485
+ const countByReview = (reviewId) => Effect.sync(() => {
486
+ return stmtCountByReview.get(reviewId).count;
487
+ });
488
+ return ReviewFileRepo.of({
489
+ countByReview,
490
+ createBulk,
491
+ deleteByReview,
492
+ findByReview,
493
+ findByReviewAndPath
494
+ });
495
+ }));
496
+ };
497
+ //#endregion
498
+ //#region ../../packages/core/src/repos/review.repo.ts
499
+ const rowToReview = (row) => ({
500
+ baseRef: row.base_ref,
501
+ createdAt: row.created_at,
502
+ id: row.id,
503
+ repositoryPath: row.repository_path,
504
+ snapshotData: row.snapshot_data,
505
+ sourceRef: row.source_ref,
506
+ sourceType: row.source_type,
507
+ status: row.status,
508
+ updatedAt: row.updated_at
509
+ });
510
+ var ReviewRepo = class ReviewRepo extends ServiceMap.Service()("@ringi/ReviewRepo") {
511
+ static Default = Layer.effect(ReviewRepo, Effect.gen(function* () {
512
+ const { db } = yield* SqliteService;
513
+ const stmtFindById = db.prepare("SELECT * FROM reviews WHERE id = ?");
514
+ const stmtInsert = db.prepare(`INSERT INTO reviews (id, repository_path, base_ref, source_type, source_ref, snapshot_data, status, created_at, updated_at)
515
+ VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))`);
516
+ const stmtUpdate = db.prepare(`UPDATE reviews SET status = COALESCE(?, status), updated_at = datetime('now') WHERE id = ?`);
517
+ const stmtUpdateSnapshot = db.prepare(`UPDATE reviews SET snapshot_data = ?, updated_at = datetime('now') WHERE id = ?`);
518
+ const stmtDelete = db.prepare("DELETE FROM reviews WHERE id = ?");
519
+ const stmtCountAll = db.prepare("SELECT COUNT(*) as count FROM reviews");
520
+ const stmtCountByStatus = db.prepare("SELECT COUNT(*) as count FROM reviews WHERE status = ?");
521
+ const findById = (id) => Effect.sync(() => {
522
+ const row = stmtFindById.get(id);
523
+ return row ? rowToReview(row) : null;
524
+ });
525
+ const findAll = (opts = {}) => Effect.sync(() => {
526
+ const conditions = [];
527
+ const params = [];
528
+ if (opts.status != null) {
529
+ conditions.push("status = ?");
530
+ params.push(opts.status);
531
+ }
532
+ if (opts.repositoryPath != null) {
533
+ conditions.push("repository_path = ?");
534
+ params.push(opts.repositoryPath);
535
+ }
536
+ if (opts.sourceType != null) {
537
+ conditions.push("source_type = ?");
538
+ params.push(opts.sourceType);
539
+ }
540
+ const where = conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : "";
541
+ const page = opts.page ?? 1;
542
+ const pageSize = opts.pageSize ?? 20;
543
+ const offset = (page - 1) * pageSize;
544
+ const totalRow = db.prepare(`SELECT COUNT(*) as count FROM reviews${where}`).get(...params);
545
+ return {
546
+ data: db.prepare(`SELECT * FROM reviews${where} ORDER BY created_at DESC LIMIT ? OFFSET ?`).all(...params, pageSize, offset).map(rowToReview),
547
+ total: totalRow.count
548
+ };
549
+ });
550
+ const create = (input) => Effect.sync(() => {
551
+ stmtInsert.run(input.id, input.repositoryPath, input.baseRef, input.sourceType, input.sourceRef, input.snapshotData, input.status);
552
+ return rowToReview(stmtFindById.get(input.id));
553
+ });
554
+ const update = (id, status) => Effect.sync(() => {
555
+ stmtUpdate.run(status, id);
556
+ const row = stmtFindById.get(id);
557
+ return row ? rowToReview(row) : null;
558
+ });
559
+ const updateSnapshotData = (id, snapshotData) => Effect.sync(() => {
560
+ stmtUpdateSnapshot.run(snapshotData, id);
561
+ const row = stmtFindById.get(id);
562
+ return row ? rowToReview(row) : null;
563
+ });
564
+ const remove = (id) => Effect.sync(() => {
565
+ const result = stmtDelete.run(id);
566
+ return Number(result.changes) > 0;
567
+ });
568
+ const countAll = () => Effect.sync(() => {
569
+ return stmtCountAll.get().count;
570
+ });
571
+ const countByStatus = (status) => Effect.sync(() => {
572
+ return stmtCountByStatus.get(status).count;
573
+ });
574
+ return ReviewRepo.of({
575
+ countAll,
576
+ countByStatus,
577
+ create,
578
+ findAll,
579
+ findById,
580
+ remove,
581
+ update,
582
+ updateSnapshotData
583
+ });
584
+ }));
585
+ };
586
+ //#endregion
587
+ //#region ../../packages/core/src/services/git.service.ts
588
+ var GitError = class extends Schema.TaggedErrorClass()("GitError", { message: Schema.String }) {};
589
+ /** Max bytes to collect from a git command before truncating (200 MB). */
590
+ const MAX_STDOUT_BYTES$1 = 200 * 1024 * 1024;
591
+ const execGit = (args, repoPath) => Effect.tryPromise({
592
+ catch: (error) => new GitError({ message: String(error) }),
593
+ try: () => new Promise((resolve, reject) => {
594
+ const child = spawn("git", [...args], { cwd: repoPath });
595
+ const chunks = [];
596
+ let bytes = 0;
597
+ let truncated = false;
598
+ child.stdout.on("data", (chunk) => {
599
+ if (truncated) return;
600
+ bytes += chunk.length;
601
+ if (bytes > MAX_STDOUT_BYTES$1) {
602
+ truncated = true;
603
+ child.kill();
604
+ return;
605
+ }
606
+ chunks.push(chunk);
607
+ });
608
+ let stderr = "";
609
+ child.stderr.on("data", (chunk) => {
610
+ stderr += chunk.toString();
611
+ });
612
+ child.on("error", reject);
613
+ child.on("close", (code) => {
614
+ if (truncated) {
615
+ resolve(Buffer.concat(chunks).toString("utf8"));
616
+ return;
617
+ }
618
+ if (code !== 0) reject(/* @__PURE__ */ new Error(`git ${args[0]} exited with code ${code}: ${stderr}`));
619
+ else resolve(Buffer.concat(chunks).toString("utf8"));
620
+ });
621
+ })
622
+ });
623
+ /** Split git output into non-empty lines. */
624
+ const lines = (output) => output.trim().split("\n").filter(Boolean);
625
+ /** Parse name-status output (e.g. `M\tfile.ts`). */
626
+ const parseNameStatus = (output) => lines(output).map((line) => {
627
+ const [status, ...rest] = line.split(" ");
628
+ return {
629
+ path: rest.join(" "),
630
+ status
631
+ };
632
+ });
633
+ var GitService = class GitService extends ServiceMap.Service()("@ringi/GitService") {
634
+ static Default = Layer.effect(GitService, Effect.gen(function* () {
635
+ const repoPath = yield* Config.string("REPOSITORY_PATH").pipe(Config.withDefault(process.cwd()));
636
+ const hasCommits = execGit(["rev-parse", "HEAD"], repoPath).pipe(Effect.as(true), Effect.catchTag("GitError", () => Effect.succeed(false)), Effect.withSpan("GitService.hasCommits"));
637
+ const getRepositoryInfo = Effect.gen(function* () {
638
+ const name = yield* execGit(["rev-parse", "--show-toplevel"], repoPath).pipe(Effect.map((s) => s.trim().split("/").pop() ?? "unknown"));
639
+ return {
640
+ branch: yield* execGit([
641
+ "rev-parse",
642
+ "--abbrev-ref",
643
+ "HEAD"
644
+ ], repoPath).pipe(Effect.map((s) => s.trim())),
645
+ name,
646
+ path: repoPath,
647
+ remote: yield* execGit([
648
+ "config",
649
+ "--get",
650
+ "remote.origin.url"
651
+ ], repoPath).pipe(Effect.map((s) => s.trim() || null), Effect.catchTag("GitError", () => Effect.succeed(null)))
652
+ };
653
+ }).pipe(Effect.withSpan("GitService.getRepositoryInfo"));
654
+ const getStagedDiff = execGit([
655
+ "diff",
656
+ "--cached",
657
+ "--no-color",
658
+ "--unified=3"
659
+ ], repoPath).pipe(Effect.withSpan("GitService.getStagedDiff"));
660
+ const getUncommittedDiff = hasCommits.pipe(Effect.flatMap((has) => has ? execGit([
661
+ "diff",
662
+ "HEAD",
663
+ "--no-color",
664
+ "--unified=3"
665
+ ], repoPath) : Effect.succeed("")), Effect.withSpan("GitService.getUncommittedDiff"));
666
+ const getUnstagedDiff = execGit([
667
+ "diff",
668
+ "--no-color",
669
+ "--unified=3"
670
+ ], repoPath).pipe(Effect.withSpan("GitService.getUnstagedDiff"));
671
+ const getLastCommitDiff = hasCommits.pipe(Effect.flatMap((has) => has ? execGit([
672
+ "show",
673
+ "HEAD",
674
+ "--format=",
675
+ "--no-color",
676
+ "--unified=3"
677
+ ], repoPath) : Effect.succeed("")), Effect.withSpan("GitService.getLastCommitDiff"));
678
+ const getBranchDiff = Effect.fn("GitService.getBranchDiff")(function* (branch) {
679
+ return yield* execGit([
680
+ "diff",
681
+ `${branch}...HEAD`,
682
+ "--no-color",
683
+ "--unified=3"
684
+ ], repoPath);
685
+ });
686
+ const getCommitDiff = Effect.fn("GitService.getCommitDiff")(function* (shas) {
687
+ if (shas.length === 1) return yield* execGit([
688
+ "show",
689
+ shas[0],
690
+ "--format=",
691
+ "--no-color",
692
+ "--unified=3"
693
+ ], repoPath);
694
+ const first = shas.at(-1);
695
+ const last = shas[0];
696
+ return yield* execGit([
697
+ "diff",
698
+ `${first}~1..${last}`,
699
+ "--no-color",
700
+ "--unified=3"
701
+ ], repoPath);
702
+ });
703
+ const getStagedFiles = execGit([
704
+ "diff",
705
+ "--cached",
706
+ "--name-status"
707
+ ], repoPath).pipe(Effect.map(parseNameStatus), Effect.withSpan("GitService.getStagedFiles"));
708
+ const getUncommittedFiles = hasCommits.pipe(Effect.flatMap((has) => has ? execGit([
709
+ "diff",
710
+ "HEAD",
711
+ "--name-status"
712
+ ], repoPath).pipe(Effect.map(parseNameStatus)) : Effect.succeed([])), Effect.withSpan("GitService.getUncommittedFiles"));
713
+ const getUnstagedFiles = execGit(["diff", "--name-status"], repoPath).pipe(Effect.map(parseNameStatus), Effect.withSpan("GitService.getUnstagedFiles"));
714
+ const getLastCommitFiles = hasCommits.pipe(Effect.flatMap((has) => has ? execGit([
715
+ "show",
716
+ "HEAD",
717
+ "--format=",
718
+ "--name-status"
719
+ ], repoPath).pipe(Effect.map(parseNameStatus)) : Effect.succeed([])), Effect.withSpan("GitService.getLastCommitFiles"));
720
+ const getFileContent = Effect.fn("GitService.getFileContent")(function* (filePath, version) {
721
+ switch (version) {
722
+ case "staged": return yield* execGit(["show", `:${filePath}`], repoPath);
723
+ case "head": return yield* execGit(["show", `HEAD:${filePath}`], repoPath);
724
+ default: return yield* Effect.tryPromise({
725
+ catch: (error) => new GitError({ message: `Failed to read ${filePath}: ${String(error)}` }),
726
+ try: () => readFile(join(repoPath, filePath), "utf8")
727
+ });
728
+ }
729
+ });
730
+ const getFileTree = Effect.fn("GitService.getFileTree")(function* (ref) {
731
+ return yield* execGit([
732
+ "ls-tree",
733
+ "-r",
734
+ "--name-only",
735
+ ref
736
+ ], repoPath).pipe(Effect.map(lines));
737
+ });
738
+ const getBranches = execGit(["branch", "--format=%(refname:short) %(HEAD)"], repoPath).pipe(Effect.map((output) => lines(output).map((line) => {
739
+ const [name, head] = line.split(" ");
740
+ return {
741
+ current: head === "*",
742
+ name
743
+ };
744
+ })), Effect.withSpan("GitService.getBranches"));
745
+ const getCommits = Effect.fn("GitService.getCommits")(function* (opts) {
746
+ const limit = (opts.limit ?? 20) + 1;
747
+ const args = [
748
+ "log",
749
+ `--max-count=${limit}`,
750
+ `--skip=${opts.offset ?? 0}`,
751
+ "--format=%H %s %an %aI"
752
+ ];
753
+ if (opts.search) args.push(`--grep=${opts.search}`, "-i");
754
+ const rows = lines(yield* execGit(args, repoPath));
755
+ const hasMore = rows.length === limit;
756
+ return {
757
+ commits: (hasMore ? rows.slice(0, -1) : rows).map((line) => {
758
+ const [hash, message, author, date] = line.split(" ");
759
+ return {
760
+ author,
761
+ date,
762
+ hash,
763
+ message
764
+ };
765
+ }),
766
+ hasMore
767
+ };
768
+ });
769
+ const stageFiles = Effect.fn("GitService.stageFiles")(function* (files) {
770
+ return yield* execGit([
771
+ "add",
772
+ "--",
773
+ ...files
774
+ ], repoPath).pipe(Effect.as(files));
775
+ });
776
+ const stageAll = execGit(["add", "-A"], repoPath).pipe(Effect.flatMap(() => getStagedFiles), Effect.map((files) => files.map((f) => f.path)), Effect.withSpan("GitService.stageAll"));
777
+ const unstageFiles = Effect.fn("GitService.unstageFiles")(function* (files) {
778
+ return yield* execGit([
779
+ "reset",
780
+ "HEAD",
781
+ "--",
782
+ ...files
783
+ ], repoPath).pipe(Effect.as(files));
784
+ });
785
+ const getRepositoryPath = execGit(["rev-parse", "--show-toplevel"], repoPath).pipe(Effect.map((s) => s.trim()), Effect.withSpan("GitService.getRepositoryPath"));
786
+ return GitService.of({
787
+ getBranchDiff,
788
+ getBranches,
789
+ getCommitDiff,
790
+ getCommits,
791
+ getFileContent,
792
+ getFileTree,
793
+ getLastCommitDiff,
794
+ getLastCommitFiles,
795
+ getRepositoryInfo,
796
+ getRepositoryPath,
797
+ getStagedDiff,
798
+ getStagedFiles,
799
+ getUncommittedDiff,
800
+ getUncommittedFiles,
801
+ getUnstagedDiff,
802
+ getUnstagedFiles,
803
+ hasCommits,
804
+ stageAll,
805
+ stageFiles,
806
+ unstageFiles
807
+ });
808
+ }));
809
+ };
810
+ //#endregion
811
+ //#region ../../packages/core/src/services/review.service.ts
812
+ var ReviewError = class extends Schema.TaggedErrorClass()("ReviewError", {
813
+ code: Schema.String,
814
+ message: Schema.String
815
+ }) {};
816
+ const getHeadSha = (repoPath) => Effect.tryPromise({
817
+ catch: () => new ReviewError({
818
+ code: "GIT_ERROR",
819
+ message: "Failed to get HEAD"
820
+ }),
821
+ try: () => new Promise((resolve, reject) => {
822
+ execFile("git", ["rev-parse", "HEAD"], { cwd: repoPath }, (err, stdout) => {
823
+ if (err) reject(err);
824
+ else resolve(stdout.trim());
825
+ });
826
+ })
827
+ });
828
+ const parseSnapshotData = (s) => Effect.try({
829
+ try: () => JSON.parse(s),
830
+ catch: () => ({})
831
+ }).pipe(Effect.orElseSucceed(() => ({})));
832
+ var ReviewService = class ReviewService extends ServiceMap.Service()("@ringi/ReviewService") {
833
+ static Default = Layer.effect(ReviewService, Effect.gen(function* () {
834
+ const git = yield* GitService;
835
+ const repo = yield* ReviewRepo;
836
+ const fileRepo = yield* ReviewFileRepo;
837
+ const create = (input) => Effect.gen(function* () {
838
+ const repoPath = yield* git.getRepositoryPath;
839
+ if (!(yield* git.hasCommits)) return yield* new ReviewError({
840
+ code: "NO_COMMITS",
841
+ message: "Repository has no commits"
842
+ });
843
+ let diffText;
844
+ let baseRef = null;
845
+ const { sourceType, sourceRef } = input;
846
+ switch (sourceType) {
847
+ case "staged":
848
+ diffText = yield* git.getStagedDiff;
849
+ if (!diffText.trim()) return yield* new ReviewError({
850
+ code: "NO_STAGED_CHANGES",
851
+ message: "No staged changes"
852
+ });
853
+ baseRef = yield* getHeadSha(repoPath);
854
+ break;
855
+ case "branch":
856
+ if (!sourceRef) return yield* new ReviewError({
857
+ code: "INVALID_SOURCE",
858
+ message: "Branch name required"
859
+ });
860
+ diffText = yield* git.getBranchDiff(sourceRef);
861
+ baseRef = sourceRef;
862
+ break;
863
+ case "commits": {
864
+ if (!sourceRef) return yield* new ReviewError({
865
+ code: "INVALID_SOURCE",
866
+ message: "Commit SHAs required"
867
+ });
868
+ const shas = sourceRef.split(",").map((s) => s.trim()).filter(Boolean);
869
+ if (shas.length === 0) return yield* new ReviewError({
870
+ code: "INVALID_SOURCE",
871
+ message: "No valid commit SHAs"
872
+ });
873
+ diffText = yield* git.getCommitDiff(shas);
874
+ baseRef = shas.at(-1) ?? null;
875
+ break;
876
+ }
877
+ default: return yield* new ReviewError({
878
+ code: "INVALID_SOURCE",
879
+ message: "Unsupported review source"
880
+ });
881
+ }
882
+ const files = parseDiff(diffText);
883
+ if (files.length === 0) return yield* new ReviewError({
884
+ code: "NO_CHANGES",
885
+ message: "No changes found"
886
+ });
887
+ const repoInfo = yield* git.getRepositoryInfo;
888
+ const reviewId = crypto.randomUUID();
889
+ const storeHunks = sourceType === "staged";
890
+ const fileInputs = files.map((f) => ({
891
+ additions: f.additions,
892
+ deletions: f.deletions,
893
+ filePath: f.newPath,
894
+ hunksData: storeHunks ? serializeHunks(f.hunks) : null,
895
+ oldPath: f.oldPath !== f.newPath ? f.oldPath : null,
896
+ reviewId,
897
+ status: f.status
898
+ }));
899
+ const snapshotData = JSON.stringify({
900
+ repository: repoInfo,
901
+ version: 2
902
+ });
903
+ const review = yield* repo.create({
904
+ baseRef,
905
+ id: reviewId,
906
+ repositoryPath: repoPath,
907
+ snapshotData,
908
+ sourceRef: sourceRef ?? null,
909
+ sourceType,
910
+ status: "in_progress"
911
+ });
912
+ yield* fileRepo.createBulk(fileInputs);
913
+ return review;
914
+ });
915
+ const list = (opts) => Effect.gen(function* () {
916
+ const page = opts.page ?? 1;
917
+ const pageSize = opts.pageSize ?? 20;
918
+ const result = yield* repo.findAll({
919
+ page,
920
+ pageSize,
921
+ repositoryPath: opts.repositoryPath,
922
+ sourceType: opts.sourceType,
923
+ status: opts.status
924
+ });
925
+ const reviews = [];
926
+ for (const review of result.data) {
927
+ const fileCount = yield* fileRepo.countByReview(review.id);
928
+ const snapshot = yield* parseSnapshotData(review.snapshotData);
929
+ reviews.push({
930
+ ...review,
931
+ fileCount,
932
+ repository: snapshot.repository ?? null
933
+ });
934
+ }
935
+ return {
936
+ hasMore: page * pageSize < result.total,
937
+ page,
938
+ pageSize,
939
+ reviews,
940
+ total: result.total
941
+ };
942
+ });
943
+ const getById = (id) => Effect.gen(function* () {
944
+ const review = yield* repo.findById(id);
945
+ if (!review) return yield* new ReviewNotFound({ id });
946
+ const files = (yield* fileRepo.findByReview(id)).map((r) => ({
947
+ additions: r.additions,
948
+ deletions: r.deletions,
949
+ filePath: r.file_path,
950
+ id: r.id,
951
+ oldPath: r.old_path,
952
+ status: r.status
953
+ }));
954
+ const snapshot = yield* parseSnapshotData(review.snapshotData);
955
+ const summary = getDiffSummary(files.map((f) => ({
956
+ additions: f.additions,
957
+ deletions: f.deletions,
958
+ hunks: [],
959
+ newPath: f.filePath,
960
+ oldPath: f.oldPath ?? f.filePath,
961
+ status: f.status
962
+ })));
963
+ return {
964
+ ...review,
965
+ files,
966
+ repository: snapshot.repository ?? null,
967
+ summary
968
+ };
969
+ });
970
+ const getFileHunks = (reviewId, filePath) => Effect.gen(function* () {
971
+ const review = yield* repo.findById(reviewId);
972
+ if (!review) return yield* new ReviewNotFound({ id: reviewId });
973
+ const fileRecord = yield* fileRepo.findByReviewAndPath(reviewId, filePath);
974
+ if (fileRecord?.hunks_data) return yield* parseHunks(fileRecord.hunks_data);
975
+ if (review.sourceType === "branch" && review.sourceRef) return parseDiff(yield* git.getBranchDiff(review.sourceRef)).find((f) => f.newPath === filePath)?.hunks ?? [];
976
+ if (review.sourceType === "commits" && review.sourceRef) {
977
+ const shas = review.sourceRef.split(",").map((s) => s.trim());
978
+ return parseDiff(yield* git.getCommitDiff(shas)).find((f) => f.newPath === filePath)?.hunks ?? [];
979
+ }
980
+ const snapshot = yield* parseSnapshotData(review.snapshotData);
981
+ if (snapshot.files) return snapshot.files.find((f) => f.newPath === filePath)?.hunks ?? [];
982
+ return [];
983
+ });
984
+ const update = (id, input) => Effect.gen(function* () {
985
+ if (!(yield* repo.findById(id))) return yield* new ReviewNotFound({ id });
986
+ const status = input.status ? Option.getOrNull(input.status) : null;
987
+ const review = yield* repo.update(id, status);
988
+ if (!review) return yield* new ReviewNotFound({ id });
989
+ return review;
990
+ });
991
+ const remove = (id) => Effect.gen(function* () {
992
+ if (!(yield* repo.findById(id))) return yield* new ReviewNotFound({ id });
993
+ yield* fileRepo.deleteByReview(id);
994
+ yield* repo.remove(id);
995
+ return { success: true };
996
+ });
997
+ const getStats = () => Effect.gen(function* () {
998
+ const total = yield* repo.countAll();
999
+ const inProgress = yield* repo.countByStatus("in_progress");
1000
+ return {
1001
+ approved: yield* repo.countByStatus("approved"),
1002
+ changesRequested: yield* repo.countByStatus("changes_requested"),
1003
+ inProgress,
1004
+ total
1005
+ };
1006
+ });
1007
+ return ReviewService.of({
1008
+ create,
1009
+ getById,
1010
+ getFileHunks,
1011
+ getStats,
1012
+ list,
1013
+ remove,
1014
+ update
1015
+ });
1016
+ }));
1017
+ };
1018
+ //#endregion
1019
+ //#region ../../packages/core/src/repos/todo.repo.ts
1020
+ const rowToTodo = (row) => ({
1021
+ completed: row.completed === 1,
1022
+ content: row.content,
1023
+ createdAt: row.created_at,
1024
+ id: row.id,
1025
+ position: row.position,
1026
+ reviewId: row.review_id,
1027
+ updatedAt: row.updated_at
1028
+ });
1029
+ var TodoRepo = class TodoRepo extends ServiceMap.Service()("@ringi/TodoRepo") {
1030
+ static Default = Layer.effect(TodoRepo, Effect.gen(function* () {
1031
+ const { db } = yield* SqliteService;
1032
+ const stmtFindById = db.prepare("SELECT * FROM todos WHERE id = ?");
1033
+ const stmtInsert = db.prepare(`INSERT INTO todos (id, content, completed, review_id, position, created_at, updated_at)
1034
+ VALUES (?, ?, 0, ?, ?, datetime('now'), datetime('now'))`);
1035
+ const stmtDelete = db.prepare("DELETE FROM todos WHERE id = ?");
1036
+ const stmtDeleteCompleted = db.prepare("DELETE FROM todos WHERE completed = 1");
1037
+ const stmtNextPosition = db.prepare("SELECT COALESCE(MAX(position), -1) + 1 AS next_pos FROM todos");
1038
+ const stmtCountAll = db.prepare("SELECT COUNT(*) as count FROM todos");
1039
+ const stmtCountCompleted = db.prepare("SELECT COUNT(*) as count FROM todos WHERE completed = 1");
1040
+ const stmtCountPending = db.prepare("SELECT COUNT(*) as count FROM todos WHERE completed = 0");
1041
+ const findById = (id) => Effect.sync(() => {
1042
+ const row = stmtFindById.get(id);
1043
+ return row ? rowToTodo(row) : null;
1044
+ });
1045
+ const findAll = (opts = {}) => Effect.sync(() => {
1046
+ const conditions = [];
1047
+ const params = [];
1048
+ if (opts.reviewId != null) {
1049
+ conditions.push("review_id = ?");
1050
+ params.push(opts.reviewId);
1051
+ }
1052
+ if (opts.completed != null) {
1053
+ conditions.push("completed = ?");
1054
+ params.push(opts.completed ? 1 : 0);
1055
+ }
1056
+ const where = conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : "";
1057
+ const totalRow = db.prepare(`SELECT COUNT(*) as count FROM todos${where}`).get(...params);
1058
+ const limitClause = opts.limit != null ? ` LIMIT ? OFFSET ?` : "";
1059
+ const queryParams = opts.limit != null ? [
1060
+ ...params,
1061
+ opts.limit,
1062
+ opts.offset ?? 0
1063
+ ] : params;
1064
+ return {
1065
+ data: db.prepare(`SELECT * FROM todos${where} ORDER BY position ASC${limitClause}`).all(...queryParams).map(rowToTodo),
1066
+ total: totalRow.count
1067
+ };
1068
+ });
1069
+ const create = (input) => Effect.sync(() => {
1070
+ const { next_pos } = stmtNextPosition.get();
1071
+ stmtInsert.run(input.id, input.content, input.reviewId, next_pos);
1072
+ return rowToTodo(stmtFindById.get(input.id));
1073
+ });
1074
+ const update = (id, updates) => Effect.sync(() => {
1075
+ const sets = [];
1076
+ const params = [];
1077
+ if (updates.content != null) {
1078
+ sets.push("content = ?");
1079
+ params.push(updates.content);
1080
+ }
1081
+ if (updates.completed != null) {
1082
+ sets.push("completed = ?");
1083
+ params.push(updates.completed ? 1 : 0);
1084
+ }
1085
+ if (sets.length === 0) {
1086
+ const row = stmtFindById.get(id);
1087
+ return row ? rowToTodo(row) : null;
1088
+ }
1089
+ sets.push("updated_at = datetime('now')");
1090
+ params.push(id);
1091
+ db.prepare(`UPDATE todos SET ${sets.join(", ")} WHERE id = ?`).run(...params);
1092
+ const row = stmtFindById.get(id);
1093
+ return row ? rowToTodo(row) : null;
1094
+ });
1095
+ const toggle = (id) => Effect.sync(() => {
1096
+ const row = stmtFindById.get(id);
1097
+ if (!row) return null;
1098
+ const newCompleted = row.completed === 1 ? 0 : 1;
1099
+ db.prepare("UPDATE todos SET completed = ?, updated_at = datetime('now') WHERE id = ?").run(newCompleted, id);
1100
+ return rowToTodo(stmtFindById.get(id));
1101
+ });
1102
+ const remove = (id) => Effect.sync(() => {
1103
+ const result = stmtDelete.run(id);
1104
+ return Number(result.changes) > 0;
1105
+ });
1106
+ const removeCompleted = () => Effect.sync(() => {
1107
+ const result = stmtDeleteCompleted.run();
1108
+ return Number(result.changes);
1109
+ });
1110
+ const reorder = (orderedIds) => withTransaction(db, Effect.sync(() => {
1111
+ const stmt = db.prepare("UPDATE todos SET position = ?, updated_at = datetime('now') WHERE id = ?");
1112
+ let updated = 0;
1113
+ for (let i = 0; i < orderedIds.length; i++) {
1114
+ const result = stmt.run(i, orderedIds[i]);
1115
+ updated += Number(result.changes);
1116
+ }
1117
+ return updated;
1118
+ }));
1119
+ const move = (id, newPosition) => Effect.gen(function* () {
1120
+ const row = stmtFindById.get(id);
1121
+ if (!row) return null;
1122
+ const oldPosition = row.position;
1123
+ yield* withTransaction(db, Effect.sync(() => {
1124
+ if (newPosition < oldPosition) db.prepare("UPDATE todos SET position = position + 1, updated_at = datetime('now') WHERE position >= ? AND position < ? AND id != ?").run(newPosition, oldPosition, id);
1125
+ else if (newPosition > oldPosition) db.prepare("UPDATE todos SET position = position - 1, updated_at = datetime('now') WHERE position > ? AND position <= ? AND id != ?").run(oldPosition, newPosition, id);
1126
+ db.prepare("UPDATE todos SET position = ?, updated_at = datetime('now') WHERE id = ?").run(newPosition, id);
1127
+ }));
1128
+ return rowToTodo(stmtFindById.get(id));
1129
+ });
1130
+ const countAll = () => Effect.sync(() => {
1131
+ return stmtCountAll.get().count;
1132
+ });
1133
+ const countCompleted = () => Effect.sync(() => {
1134
+ return stmtCountCompleted.get().count;
1135
+ });
1136
+ const countPending = () => Effect.sync(() => {
1137
+ return stmtCountPending.get().count;
1138
+ });
1139
+ return TodoRepo.of({
1140
+ countAll,
1141
+ countCompleted,
1142
+ countPending,
1143
+ create,
1144
+ findAll,
1145
+ findById,
1146
+ move,
1147
+ remove,
1148
+ removeCompleted,
1149
+ reorder,
1150
+ toggle,
1151
+ update
1152
+ });
1153
+ }));
1154
+ };
1155
+ //#endregion
1156
+ //#region ../../packages/core/src/services/todo.service.ts
1157
+ var TodoService = class TodoService extends ServiceMap.Service()("@ringi/TodoService") {
1158
+ static Default = Layer.effect(TodoService, Effect.gen(function* () {
1159
+ const repo = yield* TodoRepo;
1160
+ const create = (input) => {
1161
+ const id = randomUUID();
1162
+ return repo.create({
1163
+ content: input.content,
1164
+ id,
1165
+ reviewId: input.reviewId ?? null
1166
+ });
1167
+ };
1168
+ const getById = (id) => Effect.gen(function* () {
1169
+ const todo = yield* repo.findById(id);
1170
+ if (!todo) return yield* new TodoNotFound({ id });
1171
+ return todo;
1172
+ });
1173
+ const list = (opts = {}) => Effect.gen(function* () {
1174
+ const result = yield* repo.findAll(opts);
1175
+ return {
1176
+ data: result.data,
1177
+ limit: opts.limit ?? null,
1178
+ offset: opts.offset ?? 0,
1179
+ total: result.total
1180
+ };
1181
+ });
1182
+ const update = (id, input) => Effect.gen(function* () {
1183
+ if (!(yield* repo.findById(id))) return yield* new TodoNotFound({ id });
1184
+ const updates = {};
1185
+ if (input.content && Option.isSome(input.content)) updates.content = input.content.value;
1186
+ if (input.completed && Option.isSome(input.completed)) updates.completed = input.completed.value;
1187
+ const todo = yield* repo.update(id, updates);
1188
+ if (!todo) return yield* new TodoNotFound({ id });
1189
+ return todo;
1190
+ });
1191
+ const toggle = (id) => Effect.gen(function* () {
1192
+ const todo = yield* repo.toggle(id);
1193
+ if (!todo) return yield* new TodoNotFound({ id });
1194
+ return todo;
1195
+ });
1196
+ const remove = (id) => Effect.gen(function* () {
1197
+ if (!(yield* repo.findById(id))) return yield* new TodoNotFound({ id });
1198
+ yield* repo.remove(id);
1199
+ return { success: true };
1200
+ });
1201
+ const removeCompleted = () => Effect.gen(function* () {
1202
+ return { deleted: yield* repo.removeCompleted() };
1203
+ });
1204
+ const reorder = (orderedIds) => Effect.gen(function* () {
1205
+ return { updated: yield* repo.reorder(orderedIds) };
1206
+ });
1207
+ const move = (id, position) => Effect.gen(function* () {
1208
+ const todo = yield* repo.move(id, position);
1209
+ if (!todo) return yield* new TodoNotFound({ id });
1210
+ return todo;
1211
+ });
1212
+ const getStats = () => Effect.gen(function* () {
1213
+ const total = yield* repo.countAll();
1214
+ return {
1215
+ completed: yield* repo.countCompleted(),
1216
+ pending: yield* repo.countPending(),
1217
+ total
1218
+ };
1219
+ });
1220
+ return TodoService.of({
1221
+ create,
1222
+ getById,
1223
+ getStats,
1224
+ list,
1225
+ move,
1226
+ remove,
1227
+ removeCompleted,
1228
+ reorder,
1229
+ toggle,
1230
+ update
1231
+ });
1232
+ }));
1233
+ };
1234
+ //#endregion
1235
+ //#region ../../packages/core/src/services/export.service.ts
1236
+ var ExportService = class ExportService extends ServiceMap.Service()("@ringi/ExportService") {
1237
+ static Default = Layer.effect(ExportService, Effect.gen(function* () {
1238
+ const reviewSvc = yield* ReviewService;
1239
+ const commentSvc = yield* CommentService;
1240
+ const todoSvc = yield* TodoService;
1241
+ const exportReview = (reviewId) => Effect.gen(function* () {
1242
+ const review = yield* reviewSvc.getById(reviewId);
1243
+ const repo = review.repository;
1244
+ const repoName = repo?.name ?? "Unknown";
1245
+ const branch = repo?.branch ?? "unknown";
1246
+ const comments = yield* commentSvc.getByReview(reviewId);
1247
+ const commentStats = yield* commentSvc.getStats(reviewId);
1248
+ const todos = yield* todoSvc.list({ reviewId });
1249
+ const lines = [];
1250
+ lines.push(`# Code Review: ${repoName}`);
1251
+ lines.push("");
1252
+ lines.push(`**Status:** ${review.status}`);
1253
+ lines.push(`**Branch:** ${branch}`);
1254
+ lines.push(`**Created:** ${review.createdAt}`);
1255
+ if (review.files && review.files.length > 0) {
1256
+ lines.push("");
1257
+ lines.push("## Files Changed");
1258
+ lines.push("");
1259
+ lines.push("| File | Status | Additions | Deletions |");
1260
+ lines.push("|------|--------|-----------|-----------|");
1261
+ for (const f of review.files) {
1262
+ const statusLabel = f.status === "modified" ? "M" : f.status === "added" ? "A" : f.status === "deleted" ? "D" : f.status;
1263
+ lines.push(`| ${f.filePath} | ${statusLabel} | +${f.additions} | -${f.deletions} |`);
1264
+ }
1265
+ }
1266
+ if (comments.length > 0) {
1267
+ lines.push("");
1268
+ lines.push(`## Comments (${commentStats.total} total, ${commentStats.resolved} resolved)`);
1269
+ const byFile = /* @__PURE__ */ new Map();
1270
+ for (const c of comments) {
1271
+ const key = c.filePath ?? "(general)";
1272
+ const arr = byFile.get(key) ?? [];
1273
+ arr.push(c);
1274
+ byFile.set(key, arr);
1275
+ }
1276
+ for (const [filePath, fileComments] of byFile) {
1277
+ lines.push("");
1278
+ lines.push(`### ${filePath}`);
1279
+ for (const c of fileComments) {
1280
+ lines.push("");
1281
+ lines.push(`**Line ${c.lineNumber ?? "–"}** (${c.lineType ?? "context"})`);
1282
+ lines.push(`> ${c.content}`);
1283
+ if (c.suggestion) {
1284
+ lines.push("");
1285
+ lines.push("```suggestion");
1286
+ lines.push(c.suggestion);
1287
+ lines.push("```");
1288
+ }
1289
+ }
1290
+ }
1291
+ }
1292
+ if (todos.data.length > 0) {
1293
+ const completed = todos.data.filter((t) => t.completed).length;
1294
+ lines.push("");
1295
+ lines.push("---");
1296
+ lines.push("");
1297
+ lines.push(`## Todos (${todos.total} total, ${completed} completed)`);
1298
+ lines.push("");
1299
+ for (const t of todos.data) {
1300
+ const check = t.completed ? "x" : " ";
1301
+ lines.push(`- [${check}] ${t.content}`);
1302
+ }
1303
+ }
1304
+ lines.push("");
1305
+ return lines.join("\n");
1306
+ });
1307
+ return ExportService.of({ exportReview });
1308
+ }));
1309
+ };
1310
+ //#endregion
1311
+ //#region ../../packages/core/src/services/gh.service.ts
1312
+ var GhNotInstalled = class extends Schema.TaggedErrorClass()("GhNotInstalled", { message: Schema.String }) {};
1313
+ var GhAuthError = class extends Schema.TaggedErrorClass()("GhAuthError", {
1314
+ host: Schema.String,
1315
+ message: Schema.String
1316
+ }) {};
1317
+ var GhApiError = class extends Schema.TaggedErrorClass()("GhApiError", {
1318
+ message: Schema.String,
1319
+ statusCode: Schema.NullOr(Schema.Number)
1320
+ }) {};
1321
+ /** Max bytes to collect from gh output (50 MB — PR diffs can be large). */
1322
+ const MAX_STDOUT_BYTES = 50 * 1024 * 1024;
1323
+ const execGh = (args) => Effect.tryPromise({
1324
+ catch: (error) => new GhApiError({
1325
+ message: String(error),
1326
+ statusCode: null
1327
+ }),
1328
+ try: () => new Promise((resolve, reject) => {
1329
+ const child = spawn("gh", [...args], { stdio: [
1330
+ "ignore",
1331
+ "pipe",
1332
+ "pipe"
1333
+ ] });
1334
+ const chunks = [];
1335
+ let bytes = 0;
1336
+ let truncated = false;
1337
+ child.stdout.on("data", (chunk) => {
1338
+ if (truncated) return;
1339
+ bytes += chunk.length;
1340
+ if (bytes > MAX_STDOUT_BYTES) {
1341
+ truncated = true;
1342
+ child.kill();
1343
+ return;
1344
+ }
1345
+ chunks.push(chunk);
1346
+ });
1347
+ let stderr = "";
1348
+ child.stderr.on("data", (chunk) => {
1349
+ stderr += chunk.toString();
1350
+ });
1351
+ child.on("error", (err) => {
1352
+ reject(/* @__PURE__ */ new Error(`Failed to spawn gh: ${err.message}`));
1353
+ });
1354
+ child.on("close", (code) => {
1355
+ if (truncated) {
1356
+ resolve(Buffer.concat(chunks).toString("utf8"));
1357
+ return;
1358
+ }
1359
+ if (code !== 0) reject(/* @__PURE__ */ new Error(`gh ${args[0]} exited with code ${code}: ${stderr}`));
1360
+ else resolve(Buffer.concat(chunks).toString("utf8"));
1361
+ });
1362
+ })
1363
+ });
1364
+ /** PR metadata fields requested from gh in a single JSON call. */
1365
+ const PR_JSON_FIELDS = [
1366
+ "additions",
1367
+ "author",
1368
+ "baseRefName",
1369
+ "baseRefOid",
1370
+ "body",
1371
+ "changedFiles",
1372
+ "createdAt",
1373
+ "deletions",
1374
+ "headRefName",
1375
+ "headRefOid",
1376
+ "headRepository",
1377
+ "isDraft",
1378
+ "mergeable",
1379
+ "number",
1380
+ "reviewDecision",
1381
+ "state",
1382
+ "title",
1383
+ "updatedAt",
1384
+ "url"
1385
+ ].join(",");
1386
+ var GhService = class GhService extends ServiceMap.Service()("@ringi/GhService") {
1387
+ static Default = Layer.effect(GhService, Effect.gen(function* () {
1388
+ const ensureInstalled = execGh(["version"]).pipe(Effect.asVoid, Effect.mapError(() => new GhNotInstalled({ message: "GitHub CLI (gh) not found. Install: https://cli.github.com" })), Effect.withSpan("GhService.ensureInstalled"));
1389
+ const ensureAuthenticated = Effect.fn("GhService.ensureAuthenticated")(function* (host) {
1390
+ yield* execGh([
1391
+ "auth",
1392
+ "status",
1393
+ "--hostname",
1394
+ host
1395
+ ]).pipe(Effect.asVoid, Effect.mapError(() => new GhAuthError({
1396
+ host,
1397
+ message: `Not authenticated to ${host}. Run: gh auth login --hostname ${host}`
1398
+ })));
1399
+ });
1400
+ const fetchPrMetadata = Effect.fn("GhService.fetchPrMetadata")(function* (target) {
1401
+ const json = yield* execGh([
1402
+ "pr",
1403
+ "view",
1404
+ String(target.prNumber),
1405
+ "--repo",
1406
+ target.nwoRef,
1407
+ "--json",
1408
+ PR_JSON_FIELDS
1409
+ ]);
1410
+ return yield* Effect.try({
1411
+ catch: () => new GhApiError({
1412
+ message: "Failed to parse PR metadata JSON from gh output",
1413
+ statusCode: null
1414
+ }),
1415
+ try: () => JSON.parse(json)
1416
+ });
1417
+ });
1418
+ const fetchPrDiff = Effect.fn("GhService.fetchPrDiff")(function* (target) {
1419
+ return yield* execGh([
1420
+ "pr",
1421
+ "diff",
1422
+ String(target.prNumber),
1423
+ "--repo",
1424
+ target.nwoRef
1425
+ ]);
1426
+ });
1427
+ const fetchPrHeadOid = Effect.fn("GhService.fetchPrHeadOid")(function* (target) {
1428
+ const json = yield* execGh([
1429
+ "pr",
1430
+ "view",
1431
+ String(target.prNumber),
1432
+ "--repo",
1433
+ target.nwoRef,
1434
+ "--json",
1435
+ "headRefOid"
1436
+ ]);
1437
+ return yield* Effect.try({
1438
+ catch: () => new GhApiError({
1439
+ message: "Failed to parse head OID from gh output",
1440
+ statusCode: null
1441
+ }),
1442
+ try: () => JSON.parse(json).headRefOid
1443
+ });
1444
+ });
1445
+ return GhService.of({
1446
+ ensureAuthenticated,
1447
+ ensureInstalled,
1448
+ fetchPrDiff,
1449
+ fetchPrHeadOid,
1450
+ fetchPrMetadata
1451
+ });
1452
+ }));
1453
+ };
1454
+ //#endregion
1455
+ //#region ../../node_modules/.pnpm/readdirp@5.0.0/node_modules/readdirp/index.js
1456
+ const EntryTypes = {
1457
+ FILE_TYPE: "files",
1458
+ DIR_TYPE: "directories",
1459
+ FILE_DIR_TYPE: "files_directories",
1460
+ EVERYTHING_TYPE: "all"
1461
+ };
1462
+ const defaultOptions = {
1463
+ root: ".",
1464
+ fileFilter: (_entryInfo) => true,
1465
+ directoryFilter: (_entryInfo) => true,
1466
+ type: EntryTypes.FILE_TYPE,
1467
+ lstat: false,
1468
+ depth: 2147483648,
1469
+ alwaysStat: false,
1470
+ highWaterMark: 4096
1471
+ };
1472
+ Object.freeze(defaultOptions);
1473
+ const RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
1474
+ const NORMAL_FLOW_ERRORS = new Set([
1475
+ "ENOENT",
1476
+ "EPERM",
1477
+ "EACCES",
1478
+ "ELOOP",
1479
+ RECURSIVE_ERROR_CODE
1480
+ ]);
1481
+ const ALL_TYPES = [
1482
+ EntryTypes.DIR_TYPE,
1483
+ EntryTypes.EVERYTHING_TYPE,
1484
+ EntryTypes.FILE_DIR_TYPE,
1485
+ EntryTypes.FILE_TYPE
1486
+ ];
1487
+ const DIR_TYPES = new Set([
1488
+ EntryTypes.DIR_TYPE,
1489
+ EntryTypes.EVERYTHING_TYPE,
1490
+ EntryTypes.FILE_DIR_TYPE
1491
+ ]);
1492
+ const FILE_TYPES = new Set([
1493
+ EntryTypes.EVERYTHING_TYPE,
1494
+ EntryTypes.FILE_DIR_TYPE,
1495
+ EntryTypes.FILE_TYPE
1496
+ ]);
1497
+ const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
1498
+ const wantBigintFsStats = process.platform === "win32";
1499
+ const emptyFn = (_entryInfo) => true;
1500
+ const normalizeFilter = (filter) => {
1501
+ if (filter === void 0) return emptyFn;
1502
+ if (typeof filter === "function") return filter;
1503
+ if (typeof filter === "string") {
1504
+ const fl = filter.trim();
1505
+ return (entry) => entry.basename === fl;
1506
+ }
1507
+ if (Array.isArray(filter)) {
1508
+ const trItems = filter.map((item) => item.trim());
1509
+ return (entry) => trItems.some((f) => entry.basename === f);
1510
+ }
1511
+ return emptyFn;
1512
+ };
1513
+ /** Readable readdir stream, emitting new files as they're being listed. */
1514
+ var ReaddirpStream = class extends Readable {
1515
+ parents;
1516
+ reading;
1517
+ parent;
1518
+ _stat;
1519
+ _maxDepth;
1520
+ _wantsDir;
1521
+ _wantsFile;
1522
+ _wantsEverything;
1523
+ _root;
1524
+ _isDirent;
1525
+ _statsProp;
1526
+ _rdOptions;
1527
+ _fileFilter;
1528
+ _directoryFilter;
1529
+ constructor(options = {}) {
1530
+ super({
1531
+ objectMode: true,
1532
+ autoDestroy: true,
1533
+ highWaterMark: options.highWaterMark
1534
+ });
1535
+ const opts = {
1536
+ ...defaultOptions,
1537
+ ...options
1538
+ };
1539
+ const { root, type } = opts;
1540
+ this._fileFilter = normalizeFilter(opts.fileFilter);
1541
+ this._directoryFilter = normalizeFilter(opts.directoryFilter);
1542
+ const statMethod = opts.lstat ? lstat : stat$1;
1543
+ if (wantBigintFsStats) this._stat = (path) => statMethod(path, { bigint: true });
1544
+ else this._stat = statMethod;
1545
+ this._maxDepth = opts.depth != null && Number.isSafeInteger(opts.depth) ? opts.depth : defaultOptions.depth;
1546
+ this._wantsDir = type ? DIR_TYPES.has(type) : false;
1547
+ this._wantsFile = type ? FILE_TYPES.has(type) : false;
1548
+ this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
1549
+ this._root = resolve(root);
1550
+ this._isDirent = !opts.alwaysStat;
1551
+ this._statsProp = this._isDirent ? "dirent" : "stats";
1552
+ this._rdOptions = {
1553
+ encoding: "utf8",
1554
+ withFileTypes: this._isDirent
1555
+ };
1556
+ this.parents = [this._exploreDir(root, 1)];
1557
+ this.reading = false;
1558
+ this.parent = void 0;
1559
+ }
1560
+ async _read(batch) {
1561
+ if (this.reading) return;
1562
+ this.reading = true;
1563
+ try {
1564
+ while (!this.destroyed && batch > 0) {
1565
+ const par = this.parent;
1566
+ const fil = par && par.files;
1567
+ if (fil && fil.length > 0) {
1568
+ const { path, depth } = par;
1569
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
1570
+ const awaited = await Promise.all(slice);
1571
+ for (const entry of awaited) {
1572
+ if (!entry) continue;
1573
+ if (this.destroyed) return;
1574
+ const entryType = await this._getEntryType(entry);
1575
+ if (entryType === "directory" && this._directoryFilter(entry)) {
1576
+ if (depth <= this._maxDepth) this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
1577
+ if (this._wantsDir) {
1578
+ this.push(entry);
1579
+ batch--;
1580
+ }
1581
+ } else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
1582
+ if (this._wantsFile) {
1583
+ this.push(entry);
1584
+ batch--;
1585
+ }
1586
+ }
1587
+ }
1588
+ } else {
1589
+ const parent = this.parents.pop();
1590
+ if (!parent) {
1591
+ this.push(null);
1592
+ break;
1593
+ }
1594
+ this.parent = await parent;
1595
+ if (this.destroyed) return;
1596
+ }
1597
+ }
1598
+ } catch (error) {
1599
+ this.destroy(error);
1600
+ } finally {
1601
+ this.reading = false;
1602
+ }
1603
+ }
1604
+ async _exploreDir(path, depth) {
1605
+ let files;
1606
+ try {
1607
+ files = await readdir(path, this._rdOptions);
1608
+ } catch (error) {
1609
+ this._onError(error);
1610
+ }
1611
+ return {
1612
+ files,
1613
+ depth,
1614
+ path
1615
+ };
1616
+ }
1617
+ async _formatEntry(dirent, path) {
1618
+ let entry;
1619
+ const basename = this._isDirent ? dirent.name : dirent;
1620
+ try {
1621
+ const fullPath = resolve(join(path, basename));
1622
+ entry = {
1623
+ path: relative(this._root, fullPath),
1624
+ fullPath,
1625
+ basename
1626
+ };
1627
+ entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
1628
+ } catch (err) {
1629
+ this._onError(err);
1630
+ return;
1631
+ }
1632
+ return entry;
1633
+ }
1634
+ _onError(err) {
1635
+ if (isNormalFlowError(err) && !this.destroyed) this.emit("warn", err);
1636
+ else this.destroy(err);
1637
+ }
1638
+ async _getEntryType(entry) {
1639
+ if (!entry && this._statsProp in entry) return "";
1640
+ const stats = entry[this._statsProp];
1641
+ if (stats.isFile()) return "file";
1642
+ if (stats.isDirectory()) return "directory";
1643
+ if (stats && stats.isSymbolicLink()) {
1644
+ const full = entry.fullPath;
1645
+ try {
1646
+ const entryRealPath = await realpath(full);
1647
+ const entryRealPathStats = await lstat(entryRealPath);
1648
+ if (entryRealPathStats.isFile()) return "file";
1649
+ if (entryRealPathStats.isDirectory()) {
1650
+ const len = entryRealPath.length;
1651
+ if (full.startsWith(entryRealPath) && full.substr(len, 1) === sep) {
1652
+ const recursiveError = /* @__PURE__ */ new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
1653
+ recursiveError.code = RECURSIVE_ERROR_CODE;
1654
+ return this._onError(recursiveError);
1655
+ }
1656
+ return "directory";
1657
+ }
1658
+ } catch (error) {
1659
+ this._onError(error);
1660
+ return "";
1661
+ }
1662
+ }
1663
+ }
1664
+ _includeAsFile(entry) {
1665
+ const stats = entry && entry[this._statsProp];
1666
+ return stats && this._wantsEverything && !stats.isDirectory();
1667
+ }
1668
+ };
1669
+ /**
1670
+ * Streaming version: Reads all files and directories in given root recursively.
1671
+ * Consumes ~constant small amount of RAM.
1672
+ * @param root Root directory
1673
+ * @param options Options to specify root (start directory), filters and recursion depth
1674
+ */
1675
+ function readdirp(root, options = {}) {
1676
+ let type = options.entryType || options.type;
1677
+ if (type === "both") type = EntryTypes.FILE_DIR_TYPE;
1678
+ if (type) options.type = type;
1679
+ if (!root) throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
1680
+ else if (typeof root !== "string") throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
1681
+ else if (type && !ALL_TYPES.includes(type)) throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
1682
+ options.root = root;
1683
+ return new ReaddirpStream(options);
1684
+ }
1685
+ //#endregion
1686
+ //#region ../../node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/handler.js
1687
+ const STR_DATA = "data";
1688
+ const STR_CLOSE = "close";
1689
+ const EMPTY_FN = () => {};
1690
+ const pl = process.platform;
1691
+ const isWindows = pl === "win32";
1692
+ const isMacos = pl === "darwin";
1693
+ const isLinux = pl === "linux";
1694
+ const isFreeBSD = pl === "freebsd";
1695
+ const isIBMi = type() === "OS400";
1696
+ const EVENTS = {
1697
+ ALL: "all",
1698
+ READY: "ready",
1699
+ ADD: "add",
1700
+ CHANGE: "change",
1701
+ ADD_DIR: "addDir",
1702
+ UNLINK: "unlink",
1703
+ UNLINK_DIR: "unlinkDir",
1704
+ RAW: "raw",
1705
+ ERROR: "error"
1706
+ };
1707
+ const EV = EVENTS;
1708
+ const THROTTLE_MODE_WATCH = "watch";
1709
+ const statMethods = {
1710
+ lstat,
1711
+ stat: stat$1
1712
+ };
1713
+ const KEY_LISTENERS = "listeners";
1714
+ const KEY_ERR = "errHandlers";
1715
+ const KEY_RAW = "rawEmitters";
1716
+ const HANDLER_KEYS = [
1717
+ KEY_LISTENERS,
1718
+ KEY_ERR,
1719
+ KEY_RAW
1720
+ ];
1721
+ const binaryExtensions = new Set([
1722
+ "3dm",
1723
+ "3ds",
1724
+ "3g2",
1725
+ "3gp",
1726
+ "7z",
1727
+ "a",
1728
+ "aac",
1729
+ "adp",
1730
+ "afdesign",
1731
+ "afphoto",
1732
+ "afpub",
1733
+ "ai",
1734
+ "aif",
1735
+ "aiff",
1736
+ "alz",
1737
+ "ape",
1738
+ "apk",
1739
+ "appimage",
1740
+ "ar",
1741
+ "arj",
1742
+ "asf",
1743
+ "au",
1744
+ "avi",
1745
+ "bak",
1746
+ "baml",
1747
+ "bh",
1748
+ "bin",
1749
+ "bk",
1750
+ "bmp",
1751
+ "btif",
1752
+ "bz2",
1753
+ "bzip2",
1754
+ "cab",
1755
+ "caf",
1756
+ "cgm",
1757
+ "class",
1758
+ "cmx",
1759
+ "cpio",
1760
+ "cr2",
1761
+ "cur",
1762
+ "dat",
1763
+ "dcm",
1764
+ "deb",
1765
+ "dex",
1766
+ "djvu",
1767
+ "dll",
1768
+ "dmg",
1769
+ "dng",
1770
+ "doc",
1771
+ "docm",
1772
+ "docx",
1773
+ "dot",
1774
+ "dotm",
1775
+ "dra",
1776
+ "DS_Store",
1777
+ "dsk",
1778
+ "dts",
1779
+ "dtshd",
1780
+ "dvb",
1781
+ "dwg",
1782
+ "dxf",
1783
+ "ecelp4800",
1784
+ "ecelp7470",
1785
+ "ecelp9600",
1786
+ "egg",
1787
+ "eol",
1788
+ "eot",
1789
+ "epub",
1790
+ "exe",
1791
+ "f4v",
1792
+ "fbs",
1793
+ "fh",
1794
+ "fla",
1795
+ "flac",
1796
+ "flatpak",
1797
+ "fli",
1798
+ "flv",
1799
+ "fpx",
1800
+ "fst",
1801
+ "fvt",
1802
+ "g3",
1803
+ "gh",
1804
+ "gif",
1805
+ "graffle",
1806
+ "gz",
1807
+ "gzip",
1808
+ "h261",
1809
+ "h263",
1810
+ "h264",
1811
+ "icns",
1812
+ "ico",
1813
+ "ief",
1814
+ "img",
1815
+ "ipa",
1816
+ "iso",
1817
+ "jar",
1818
+ "jpeg",
1819
+ "jpg",
1820
+ "jpgv",
1821
+ "jpm",
1822
+ "jxr",
1823
+ "key",
1824
+ "ktx",
1825
+ "lha",
1826
+ "lib",
1827
+ "lvp",
1828
+ "lz",
1829
+ "lzh",
1830
+ "lzma",
1831
+ "lzo",
1832
+ "m3u",
1833
+ "m4a",
1834
+ "m4v",
1835
+ "mar",
1836
+ "mdi",
1837
+ "mht",
1838
+ "mid",
1839
+ "midi",
1840
+ "mj2",
1841
+ "mka",
1842
+ "mkv",
1843
+ "mmr",
1844
+ "mng",
1845
+ "mobi",
1846
+ "mov",
1847
+ "movie",
1848
+ "mp3",
1849
+ "mp4",
1850
+ "mp4a",
1851
+ "mpeg",
1852
+ "mpg",
1853
+ "mpga",
1854
+ "mxu",
1855
+ "nef",
1856
+ "npx",
1857
+ "numbers",
1858
+ "nupkg",
1859
+ "o",
1860
+ "odp",
1861
+ "ods",
1862
+ "odt",
1863
+ "oga",
1864
+ "ogg",
1865
+ "ogv",
1866
+ "otf",
1867
+ "ott",
1868
+ "pages",
1869
+ "pbm",
1870
+ "pcx",
1871
+ "pdb",
1872
+ "pdf",
1873
+ "pea",
1874
+ "pgm",
1875
+ "pic",
1876
+ "png",
1877
+ "pnm",
1878
+ "pot",
1879
+ "potm",
1880
+ "potx",
1881
+ "ppa",
1882
+ "ppam",
1883
+ "ppm",
1884
+ "pps",
1885
+ "ppsm",
1886
+ "ppsx",
1887
+ "ppt",
1888
+ "pptm",
1889
+ "pptx",
1890
+ "psd",
1891
+ "pya",
1892
+ "pyc",
1893
+ "pyo",
1894
+ "pyv",
1895
+ "qt",
1896
+ "rar",
1897
+ "ras",
1898
+ "raw",
1899
+ "resources",
1900
+ "rgb",
1901
+ "rip",
1902
+ "rlc",
1903
+ "rmf",
1904
+ "rmvb",
1905
+ "rpm",
1906
+ "rtf",
1907
+ "rz",
1908
+ "s3m",
1909
+ "s7z",
1910
+ "scpt",
1911
+ "sgi",
1912
+ "shar",
1913
+ "snap",
1914
+ "sil",
1915
+ "sketch",
1916
+ "slk",
1917
+ "smv",
1918
+ "snk",
1919
+ "so",
1920
+ "stl",
1921
+ "suo",
1922
+ "sub",
1923
+ "swf",
1924
+ "tar",
1925
+ "tbz",
1926
+ "tbz2",
1927
+ "tga",
1928
+ "tgz",
1929
+ "thmx",
1930
+ "tif",
1931
+ "tiff",
1932
+ "tlz",
1933
+ "ttc",
1934
+ "ttf",
1935
+ "txz",
1936
+ "udf",
1937
+ "uvh",
1938
+ "uvi",
1939
+ "uvm",
1940
+ "uvp",
1941
+ "uvs",
1942
+ "uvu",
1943
+ "viv",
1944
+ "vob",
1945
+ "war",
1946
+ "wav",
1947
+ "wax",
1948
+ "wbmp",
1949
+ "wdp",
1950
+ "weba",
1951
+ "webm",
1952
+ "webp",
1953
+ "whl",
1954
+ "wim",
1955
+ "wm",
1956
+ "wma",
1957
+ "wmv",
1958
+ "wmx",
1959
+ "woff",
1960
+ "woff2",
1961
+ "wrm",
1962
+ "wvx",
1963
+ "xbm",
1964
+ "xif",
1965
+ "xla",
1966
+ "xlam",
1967
+ "xls",
1968
+ "xlsb",
1969
+ "xlsm",
1970
+ "xlsx",
1971
+ "xlt",
1972
+ "xltm",
1973
+ "xltx",
1974
+ "xm",
1975
+ "xmind",
1976
+ "xpi",
1977
+ "xpm",
1978
+ "xwd",
1979
+ "xz",
1980
+ "z",
1981
+ "zip",
1982
+ "zipx"
1983
+ ]);
1984
+ const isBinaryPath = (filePath) => binaryExtensions.has(sp.extname(filePath).slice(1).toLowerCase());
1985
+ const foreach = (val, fn) => {
1986
+ if (val instanceof Set) val.forEach(fn);
1987
+ else fn(val);
1988
+ };
1989
+ const addAndConvert = (main, prop, item) => {
1990
+ let container = main[prop];
1991
+ if (!(container instanceof Set)) main[prop] = container = new Set([container]);
1992
+ container.add(item);
1993
+ };
1994
+ const clearItem = (cont) => (key) => {
1995
+ const set = cont[key];
1996
+ if (set instanceof Set) set.clear();
1997
+ else delete cont[key];
1998
+ };
1999
+ const delFromSet = (main, prop, item) => {
2000
+ const container = main[prop];
2001
+ if (container instanceof Set) container.delete(item);
2002
+ else if (container === item) delete main[prop];
2003
+ };
2004
+ const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
2005
+ const FsWatchInstances = /* @__PURE__ */ new Map();
2006
+ /**
2007
+ * Instantiates the fs_watch interface
2008
+ * @param path to be watched
2009
+ * @param options to be passed to fs_watch
2010
+ * @param listener main event handler
2011
+ * @param errHandler emits info about errors
2012
+ * @param emitRaw emits raw event data
2013
+ * @returns {NativeFsWatcher}
2014
+ */
2015
+ function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
2016
+ const handleEvent = (rawEvent, evPath) => {
2017
+ listener(path);
2018
+ emitRaw(rawEvent, evPath, { watchedPath: path });
2019
+ if (evPath && path !== evPath) fsWatchBroadcast(sp.resolve(path, evPath), KEY_LISTENERS, sp.join(path, evPath));
2020
+ };
2021
+ try {
2022
+ return watch(path, { persistent: options.persistent }, handleEvent);
2023
+ } catch (error) {
2024
+ errHandler(error);
2025
+ return;
2026
+ }
2027
+ }
2028
+ /**
2029
+ * Helper for passing fs_watch event data to a collection of listeners
2030
+ * @param fullPath absolute path bound to fs_watch instance
2031
+ */
2032
+ const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
2033
+ const cont = FsWatchInstances.get(fullPath);
2034
+ if (!cont) return;
2035
+ foreach(cont[listenerType], (listener) => {
2036
+ listener(val1, val2, val3);
2037
+ });
2038
+ };
2039
+ /**
2040
+ * Instantiates the fs_watch interface or binds listeners
2041
+ * to an existing one covering the same file system entry
2042
+ * @param path
2043
+ * @param fullPath absolute path
2044
+ * @param options to be passed to fs_watch
2045
+ * @param handlers container for event listener functions
2046
+ */
2047
+ const setFsWatchListener = (path, fullPath, options, handlers) => {
2048
+ const { listener, errHandler, rawEmitter } = handlers;
2049
+ let cont = FsWatchInstances.get(fullPath);
2050
+ let watcher;
2051
+ if (!options.persistent) {
2052
+ watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
2053
+ if (!watcher) return;
2054
+ return watcher.close.bind(watcher);
2055
+ }
2056
+ if (cont) {
2057
+ addAndConvert(cont, KEY_LISTENERS, listener);
2058
+ addAndConvert(cont, KEY_ERR, errHandler);
2059
+ addAndConvert(cont, KEY_RAW, rawEmitter);
2060
+ } else {
2061
+ watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
2062
+ if (!watcher) return;
2063
+ watcher.on(EV.ERROR, async (error) => {
2064
+ const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
2065
+ if (cont) cont.watcherUnusable = true;
2066
+ if (isWindows && error.code === "EPERM") try {
2067
+ await (await open(path, "r")).close();
2068
+ broadcastErr(error);
2069
+ } catch (err) {}
2070
+ else broadcastErr(error);
2071
+ });
2072
+ cont = {
2073
+ listeners: listener,
2074
+ errHandlers: errHandler,
2075
+ rawEmitters: rawEmitter,
2076
+ watcher
2077
+ };
2078
+ FsWatchInstances.set(fullPath, cont);
2079
+ }
2080
+ return () => {
2081
+ delFromSet(cont, KEY_LISTENERS, listener);
2082
+ delFromSet(cont, KEY_ERR, errHandler);
2083
+ delFromSet(cont, KEY_RAW, rawEmitter);
2084
+ if (isEmptySet(cont.listeners)) {
2085
+ cont.watcher.close();
2086
+ FsWatchInstances.delete(fullPath);
2087
+ HANDLER_KEYS.forEach(clearItem(cont));
2088
+ cont.watcher = void 0;
2089
+ Object.freeze(cont);
2090
+ }
2091
+ };
2092
+ };
2093
+ const FsWatchFileInstances = /* @__PURE__ */ new Map();
2094
+ /**
2095
+ * Instantiates the fs_watchFile interface or binds listeners
2096
+ * to an existing one covering the same file system entry
2097
+ * @param path to be watched
2098
+ * @param fullPath absolute path
2099
+ * @param options options to be passed to fs_watchFile
2100
+ * @param handlers container for event listener functions
2101
+ * @returns closer
2102
+ */
2103
+ const setFsWatchFileListener = (path, fullPath, options, handlers) => {
2104
+ const { listener, rawEmitter } = handlers;
2105
+ let cont = FsWatchFileInstances.get(fullPath);
2106
+ const copts = cont && cont.options;
2107
+ if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
2108
+ unwatchFile(fullPath);
2109
+ cont = void 0;
2110
+ }
2111
+ if (cont) {
2112
+ addAndConvert(cont, KEY_LISTENERS, listener);
2113
+ addAndConvert(cont, KEY_RAW, rawEmitter);
2114
+ } else {
2115
+ cont = {
2116
+ listeners: listener,
2117
+ rawEmitters: rawEmitter,
2118
+ options,
2119
+ watcher: watchFile(fullPath, options, (curr, prev) => {
2120
+ foreach(cont.rawEmitters, (rawEmitter) => {
2121
+ rawEmitter(EV.CHANGE, fullPath, {
2122
+ curr,
2123
+ prev
2124
+ });
2125
+ });
2126
+ const currmtime = curr.mtimeMs;
2127
+ if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) foreach(cont.listeners, (listener) => listener(path, curr));
2128
+ })
2129
+ };
2130
+ FsWatchFileInstances.set(fullPath, cont);
2131
+ }
2132
+ return () => {
2133
+ delFromSet(cont, KEY_LISTENERS, listener);
2134
+ delFromSet(cont, KEY_RAW, rawEmitter);
2135
+ if (isEmptySet(cont.listeners)) {
2136
+ FsWatchFileInstances.delete(fullPath);
2137
+ unwatchFile(fullPath);
2138
+ cont.options = cont.watcher = void 0;
2139
+ Object.freeze(cont);
2140
+ }
2141
+ };
2142
+ };
2143
+ /**
2144
+ * @mixin
2145
+ */
2146
+ var NodeFsHandler = class {
2147
+ fsw;
2148
+ _boundHandleError;
2149
+ constructor(fsW) {
2150
+ this.fsw = fsW;
2151
+ this._boundHandleError = (error) => fsW._handleError(error);
2152
+ }
2153
+ /**
2154
+ * Watch file for changes with fs_watchFile or fs_watch.
2155
+ * @param path to file or dir
2156
+ * @param listener on fs change
2157
+ * @returns closer for the watcher instance
2158
+ */
2159
+ _watchWithNodeFs(path, listener) {
2160
+ const opts = this.fsw.options;
2161
+ const directory = sp.dirname(path);
2162
+ const basename = sp.basename(path);
2163
+ this.fsw._getWatchedDir(directory).add(basename);
2164
+ const absolutePath = sp.resolve(path);
2165
+ const options = { persistent: opts.persistent };
2166
+ if (!listener) listener = EMPTY_FN;
2167
+ let closer;
2168
+ if (opts.usePolling) {
2169
+ options.interval = opts.interval !== opts.binaryInterval && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
2170
+ closer = setFsWatchFileListener(path, absolutePath, options, {
2171
+ listener,
2172
+ rawEmitter: this.fsw._emitRaw
2173
+ });
2174
+ } else closer = setFsWatchListener(path, absolutePath, options, {
2175
+ listener,
2176
+ errHandler: this._boundHandleError,
2177
+ rawEmitter: this.fsw._emitRaw
2178
+ });
2179
+ return closer;
2180
+ }
2181
+ /**
2182
+ * Watch a file and emit add event if warranted.
2183
+ * @returns closer for the watcher instance
2184
+ */
2185
+ _handleFile(file, stats, initialAdd) {
2186
+ if (this.fsw.closed) return;
2187
+ const dirname = sp.dirname(file);
2188
+ const basename = sp.basename(file);
2189
+ const parent = this.fsw._getWatchedDir(dirname);
2190
+ let prevStats = stats;
2191
+ if (parent.has(basename)) return;
2192
+ const listener = async (path, newStats) => {
2193
+ if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
2194
+ if (!newStats || newStats.mtimeMs === 0) try {
2195
+ const newStats = await stat$1(file);
2196
+ if (this.fsw.closed) return;
2197
+ const at = newStats.atimeMs;
2198
+ const mt = newStats.mtimeMs;
2199
+ if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats);
2200
+ if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
2201
+ this.fsw._closeFile(path);
2202
+ prevStats = newStats;
2203
+ const closer = this._watchWithNodeFs(file, listener);
2204
+ if (closer) this.fsw._addPathCloser(path, closer);
2205
+ } else prevStats = newStats;
2206
+ } catch (error) {
2207
+ this.fsw._remove(dirname, basename);
2208
+ }
2209
+ else if (parent.has(basename)) {
2210
+ const at = newStats.atimeMs;
2211
+ const mt = newStats.mtimeMs;
2212
+ if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats);
2213
+ prevStats = newStats;
2214
+ }
2215
+ };
2216
+ const closer = this._watchWithNodeFs(file, listener);
2217
+ if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
2218
+ if (!this.fsw._throttle(EV.ADD, file, 0)) return;
2219
+ this.fsw._emit(EV.ADD, file, stats);
2220
+ }
2221
+ return closer;
2222
+ }
2223
+ /**
2224
+ * Handle symlinks encountered while reading a dir.
2225
+ * @param entry returned by readdirp
2226
+ * @param directory path of dir being read
2227
+ * @param path of this item
2228
+ * @param item basename of this item
2229
+ * @returns true if no more processing is needed for this entry.
2230
+ */
2231
+ async _handleSymlink(entry, directory, path, item) {
2232
+ if (this.fsw.closed) return;
2233
+ const full = entry.fullPath;
2234
+ const dir = this.fsw._getWatchedDir(directory);
2235
+ if (!this.fsw.options.followSymlinks) {
2236
+ this.fsw._incrReadyCount();
2237
+ let linkPath;
2238
+ try {
2239
+ linkPath = await realpath(path);
2240
+ } catch (e) {
2241
+ this.fsw._emitReady();
2242
+ return true;
2243
+ }
2244
+ if (this.fsw.closed) return;
2245
+ if (dir.has(item)) {
2246
+ if (this.fsw._symlinkPaths.get(full) !== linkPath) {
2247
+ this.fsw._symlinkPaths.set(full, linkPath);
2248
+ this.fsw._emit(EV.CHANGE, path, entry.stats);
2249
+ }
2250
+ } else {
2251
+ dir.add(item);
2252
+ this.fsw._symlinkPaths.set(full, linkPath);
2253
+ this.fsw._emit(EV.ADD, path, entry.stats);
2254
+ }
2255
+ this.fsw._emitReady();
2256
+ return true;
2257
+ }
2258
+ if (this.fsw._symlinkPaths.has(full)) return true;
2259
+ this.fsw._symlinkPaths.set(full, true);
2260
+ }
2261
+ _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
2262
+ directory = sp.join(directory, "");
2263
+ const throttleKey = target ? `${directory}:${target}` : directory;
2264
+ throttler = this.fsw._throttle("readdir", throttleKey, 1e3);
2265
+ if (!throttler) return;
2266
+ const previous = this.fsw._getWatchedDir(wh.path);
2267
+ const current = /* @__PURE__ */ new Set();
2268
+ let stream = this.fsw._readdirp(directory, {
2269
+ fileFilter: (entry) => wh.filterPath(entry),
2270
+ directoryFilter: (entry) => wh.filterDir(entry)
2271
+ });
2272
+ if (!stream) return;
2273
+ stream.on(STR_DATA, async (entry) => {
2274
+ if (this.fsw.closed) {
2275
+ stream = void 0;
2276
+ return;
2277
+ }
2278
+ const item = entry.path;
2279
+ let path = sp.join(directory, item);
2280
+ current.add(item);
2281
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) return;
2282
+ if (this.fsw.closed) {
2283
+ stream = void 0;
2284
+ return;
2285
+ }
2286
+ if (item === target || !target && !previous.has(item)) {
2287
+ this.fsw._incrReadyCount();
2288
+ path = sp.join(dir, sp.relative(dir, path));
2289
+ this._addToNodeFs(path, initialAdd, wh, depth + 1);
2290
+ }
2291
+ }).on(EV.ERROR, this._boundHandleError);
2292
+ return new Promise((resolve, reject) => {
2293
+ if (!stream) return reject();
2294
+ stream.once("end", () => {
2295
+ if (this.fsw.closed) {
2296
+ stream = void 0;
2297
+ return;
2298
+ }
2299
+ const wasThrottled = throttler ? throttler.clear() : false;
2300
+ resolve(void 0);
2301
+ previous.getChildren().filter((item) => {
2302
+ return item !== directory && !current.has(item);
2303
+ }).forEach((item) => {
2304
+ this.fsw._remove(directory, item);
2305
+ });
2306
+ stream = void 0;
2307
+ if (wasThrottled) this._handleRead(directory, false, wh, target, dir, depth, throttler);
2308
+ });
2309
+ });
2310
+ }
2311
+ /**
2312
+ * Read directory to add / remove files from `@watched` list and re-read it on change.
2313
+ * @param dir fs path
2314
+ * @param stats
2315
+ * @param initialAdd
2316
+ * @param depth relative to user-supplied path
2317
+ * @param target child path targeted for watch
2318
+ * @param wh Common watch helpers for this path
2319
+ * @param realpath
2320
+ * @returns closer for the watcher instance.
2321
+ */
2322
+ async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
2323
+ const parentDir = this.fsw._getWatchedDir(sp.dirname(dir));
2324
+ const tracked = parentDir.has(sp.basename(dir));
2325
+ if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) this.fsw._emit(EV.ADD_DIR, dir, stats);
2326
+ parentDir.add(sp.basename(dir));
2327
+ this.fsw._getWatchedDir(dir);
2328
+ let throttler;
2329
+ let closer;
2330
+ const oDepth = this.fsw.options.depth;
2331
+ if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
2332
+ if (!target) {
2333
+ await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
2334
+ if (this.fsw.closed) return;
2335
+ }
2336
+ closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
2337
+ if (stats && stats.mtimeMs === 0) return;
2338
+ this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
2339
+ });
2340
+ }
2341
+ return closer;
2342
+ }
2343
+ /**
2344
+ * Handle added file, directory, or glob pattern.
2345
+ * Delegates call to _handleFile / _handleDir after checks.
2346
+ * @param path to file or ir
2347
+ * @param initialAdd was the file added at watch instantiation?
2348
+ * @param priorWh depth relative to user-supplied path
2349
+ * @param depth Child path actually targeted for watch
2350
+ * @param target Child path actually targeted for watch
2351
+ */
2352
+ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
2353
+ const ready = this.fsw._emitReady;
2354
+ if (this.fsw._isIgnored(path) || this.fsw.closed) {
2355
+ ready();
2356
+ return false;
2357
+ }
2358
+ const wh = this.fsw._getWatchHelpers(path);
2359
+ if (priorWh) {
2360
+ wh.filterPath = (entry) => priorWh.filterPath(entry);
2361
+ wh.filterDir = (entry) => priorWh.filterDir(entry);
2362
+ }
2363
+ try {
2364
+ const stats = await statMethods[wh.statMethod](wh.watchPath);
2365
+ if (this.fsw.closed) return;
2366
+ if (this.fsw._isIgnored(wh.watchPath, stats)) {
2367
+ ready();
2368
+ return false;
2369
+ }
2370
+ const follow = this.fsw.options.followSymlinks;
2371
+ let closer;
2372
+ if (stats.isDirectory()) {
2373
+ const absPath = sp.resolve(path);
2374
+ const targetPath = follow ? await realpath(path) : path;
2375
+ if (this.fsw.closed) return;
2376
+ closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
2377
+ if (this.fsw.closed) return;
2378
+ if (absPath !== targetPath && targetPath !== void 0) this.fsw._symlinkPaths.set(absPath, targetPath);
2379
+ } else if (stats.isSymbolicLink()) {
2380
+ const targetPath = follow ? await realpath(path) : path;
2381
+ if (this.fsw.closed) return;
2382
+ const parent = sp.dirname(wh.watchPath);
2383
+ this.fsw._getWatchedDir(parent).add(wh.watchPath);
2384
+ this.fsw._emit(EV.ADD, wh.watchPath, stats);
2385
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
2386
+ if (this.fsw.closed) return;
2387
+ if (targetPath !== void 0) this.fsw._symlinkPaths.set(sp.resolve(path), targetPath);
2388
+ } else closer = this._handleFile(wh.watchPath, stats, initialAdd);
2389
+ ready();
2390
+ if (closer) this.fsw._addPathCloser(path, closer);
2391
+ return false;
2392
+ } catch (error) {
2393
+ if (this.fsw._handleError(error)) {
2394
+ ready();
2395
+ return path;
2396
+ }
2397
+ }
2398
+ }
2399
+ };
2400
+ //#endregion
2401
+ //#region ../../node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/index.js
2402
+ /*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
2403
+ const SLASH = "/";
2404
+ const SLASH_SLASH = "//";
2405
+ const ONE_DOT = ".";
2406
+ const TWO_DOTS = "..";
2407
+ const STRING_TYPE = "string";
2408
+ const BACK_SLASH_RE = /\\/g;
2409
+ const DOUBLE_SLASH_RE = /\/\//g;
2410
+ const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
2411
+ const REPLACER_RE = /^\.[/\\]/;
2412
+ function arrify(item) {
2413
+ return Array.isArray(item) ? item : [item];
2414
+ }
2415
+ const isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
2416
+ function createPattern(matcher) {
2417
+ if (typeof matcher === "function") return matcher;
2418
+ if (typeof matcher === "string") return (string) => matcher === string;
2419
+ if (matcher instanceof RegExp) return (string) => matcher.test(string);
2420
+ if (typeof matcher === "object" && matcher !== null) return (string) => {
2421
+ if (matcher.path === string) return true;
2422
+ if (matcher.recursive) {
2423
+ const relative = sp.relative(matcher.path, string);
2424
+ if (!relative) return false;
2425
+ return !relative.startsWith("..") && !sp.isAbsolute(relative);
2426
+ }
2427
+ return false;
2428
+ };
2429
+ return () => false;
2430
+ }
2431
+ function normalizePath(path) {
2432
+ if (typeof path !== "string") throw new Error("string expected");
2433
+ path = sp.normalize(path);
2434
+ path = path.replace(/\\/g, "/");
2435
+ let prepend = false;
2436
+ if (path.startsWith("//")) prepend = true;
2437
+ path = path.replace(DOUBLE_SLASH_RE, "/");
2438
+ if (prepend) path = "/" + path;
2439
+ return path;
2440
+ }
2441
+ function matchPatterns(patterns, testString, stats) {
2442
+ const path = normalizePath(testString);
2443
+ for (let index = 0; index < patterns.length; index++) {
2444
+ const pattern = patterns[index];
2445
+ if (pattern(path, stats)) return true;
2446
+ }
2447
+ return false;
2448
+ }
2449
+ function anymatch(matchers, testString) {
2450
+ if (matchers == null) throw new TypeError("anymatch: specify first argument");
2451
+ const patterns = arrify(matchers).map((matcher) => createPattern(matcher));
2452
+ if (testString == null) return (testString, stats) => {
2453
+ return matchPatterns(patterns, testString, stats);
2454
+ };
2455
+ return matchPatterns(patterns, testString);
2456
+ }
2457
+ const unifyPaths = (paths_) => {
2458
+ const paths = arrify(paths_).flat();
2459
+ if (!paths.every((p) => typeof p === STRING_TYPE)) throw new TypeError(`Non-string provided as watch path: ${paths}`);
2460
+ return paths.map(normalizePathToUnix);
2461
+ };
2462
+ const toUnix = (string) => {
2463
+ let str = string.replace(BACK_SLASH_RE, SLASH);
2464
+ let prepend = false;
2465
+ if (str.startsWith(SLASH_SLASH)) prepend = true;
2466
+ str = str.replace(DOUBLE_SLASH_RE, SLASH);
2467
+ if (prepend) str = SLASH + str;
2468
+ return str;
2469
+ };
2470
+ const normalizePathToUnix = (path) => toUnix(sp.normalize(toUnix(path)));
2471
+ const normalizeIgnored = (cwd = "") => (path) => {
2472
+ if (typeof path === "string") return normalizePathToUnix(sp.isAbsolute(path) ? path : sp.join(cwd, path));
2473
+ else return path;
2474
+ };
2475
+ const getAbsolutePath = (path, cwd) => {
2476
+ if (sp.isAbsolute(path)) return path;
2477
+ return sp.join(cwd, path);
2478
+ };
2479
+ const EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
2480
+ /**
2481
+ * Directory entry.
2482
+ */
2483
+ var DirEntry = class {
2484
+ path;
2485
+ _removeWatcher;
2486
+ items;
2487
+ constructor(dir, removeWatcher) {
2488
+ this.path = dir;
2489
+ this._removeWatcher = removeWatcher;
2490
+ this.items = /* @__PURE__ */ new Set();
2491
+ }
2492
+ add(item) {
2493
+ const { items } = this;
2494
+ if (!items) return;
2495
+ if (item !== ONE_DOT && item !== TWO_DOTS) items.add(item);
2496
+ }
2497
+ async remove(item) {
2498
+ const { items } = this;
2499
+ if (!items) return;
2500
+ items.delete(item);
2501
+ if (items.size > 0) return;
2502
+ const dir = this.path;
2503
+ try {
2504
+ await readdir(dir);
2505
+ } catch (err) {
2506
+ if (this._removeWatcher) this._removeWatcher(sp.dirname(dir), sp.basename(dir));
2507
+ }
2508
+ }
2509
+ has(item) {
2510
+ const { items } = this;
2511
+ if (!items) return;
2512
+ return items.has(item);
2513
+ }
2514
+ getChildren() {
2515
+ const { items } = this;
2516
+ if (!items) return [];
2517
+ return [...items.values()];
2518
+ }
2519
+ dispose() {
2520
+ this.items.clear();
2521
+ this.path = "";
2522
+ this._removeWatcher = EMPTY_FN;
2523
+ this.items = EMPTY_SET;
2524
+ Object.freeze(this);
2525
+ }
2526
+ };
2527
+ const STAT_METHOD_F = "stat";
2528
+ const STAT_METHOD_L = "lstat";
2529
+ var WatchHelper = class {
2530
+ fsw;
2531
+ path;
2532
+ watchPath;
2533
+ fullWatchPath;
2534
+ dirParts;
2535
+ followSymlinks;
2536
+ statMethod;
2537
+ constructor(path, follow, fsw) {
2538
+ this.fsw = fsw;
2539
+ const watchPath = path;
2540
+ this.path = path = path.replace(REPLACER_RE, "");
2541
+ this.watchPath = watchPath;
2542
+ this.fullWatchPath = sp.resolve(watchPath);
2543
+ this.dirParts = [];
2544
+ this.dirParts.forEach((parts) => {
2545
+ if (parts.length > 1) parts.pop();
2546
+ });
2547
+ this.followSymlinks = follow;
2548
+ this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
2549
+ }
2550
+ entryPath(entry) {
2551
+ return sp.join(this.watchPath, sp.relative(this.watchPath, entry.fullPath));
2552
+ }
2553
+ filterPath(entry) {
2554
+ const { stats } = entry;
2555
+ if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
2556
+ const resolvedPath = this.entryPath(entry);
2557
+ return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
2558
+ }
2559
+ filterDir(entry) {
2560
+ return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
2561
+ }
2562
+ };
2563
+ /**
2564
+ * Watches files & directories for changes. Emitted events:
2565
+ * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
2566
+ *
2567
+ * new FSWatcher()
2568
+ * .add(directories)
2569
+ * .on('add', path => log('File', path, 'was added'))
2570
+ */
2571
+ var FSWatcher = class extends EventEmitter {
2572
+ closed;
2573
+ options;
2574
+ _closers;
2575
+ _ignoredPaths;
2576
+ _throttled;
2577
+ _streams;
2578
+ _symlinkPaths;
2579
+ _watched;
2580
+ _pendingWrites;
2581
+ _pendingUnlinks;
2582
+ _readyCount;
2583
+ _emitReady;
2584
+ _closePromise;
2585
+ _userIgnored;
2586
+ _readyEmitted;
2587
+ _emitRaw;
2588
+ _boundRemove;
2589
+ _nodeFsHandler;
2590
+ constructor(_opts = {}) {
2591
+ super();
2592
+ this.closed = false;
2593
+ this._closers = /* @__PURE__ */ new Map();
2594
+ this._ignoredPaths = /* @__PURE__ */ new Set();
2595
+ this._throttled = /* @__PURE__ */ new Map();
2596
+ this._streams = /* @__PURE__ */ new Set();
2597
+ this._symlinkPaths = /* @__PURE__ */ new Map();
2598
+ this._watched = /* @__PURE__ */ new Map();
2599
+ this._pendingWrites = /* @__PURE__ */ new Map();
2600
+ this._pendingUnlinks = /* @__PURE__ */ new Map();
2601
+ this._readyCount = 0;
2602
+ this._readyEmitted = false;
2603
+ const awf = _opts.awaitWriteFinish;
2604
+ const DEF_AWF = {
2605
+ stabilityThreshold: 2e3,
2606
+ pollInterval: 100
2607
+ };
2608
+ const opts = {
2609
+ persistent: true,
2610
+ ignoreInitial: false,
2611
+ ignorePermissionErrors: false,
2612
+ interval: 100,
2613
+ binaryInterval: 300,
2614
+ followSymlinks: true,
2615
+ usePolling: false,
2616
+ atomic: true,
2617
+ ..._opts,
2618
+ ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
2619
+ awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? {
2620
+ ...DEF_AWF,
2621
+ ...awf
2622
+ } : false
2623
+ };
2624
+ if (isIBMi) opts.usePolling = true;
2625
+ if (opts.atomic === void 0) opts.atomic = !opts.usePolling;
2626
+ const envPoll = process.env.CHOKIDAR_USEPOLLING;
2627
+ if (envPoll !== void 0) {
2628
+ const envLower = envPoll.toLowerCase();
2629
+ if (envLower === "false" || envLower === "0") opts.usePolling = false;
2630
+ else if (envLower === "true" || envLower === "1") opts.usePolling = true;
2631
+ else opts.usePolling = !!envLower;
2632
+ }
2633
+ const envInterval = process.env.CHOKIDAR_INTERVAL;
2634
+ if (envInterval) opts.interval = Number.parseInt(envInterval, 10);
2635
+ let readyCalls = 0;
2636
+ this._emitReady = () => {
2637
+ readyCalls++;
2638
+ if (readyCalls >= this._readyCount) {
2639
+ this._emitReady = EMPTY_FN;
2640
+ this._readyEmitted = true;
2641
+ process.nextTick(() => this.emit(EVENTS.READY));
2642
+ }
2643
+ };
2644
+ this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
2645
+ this._boundRemove = this._remove.bind(this);
2646
+ this.options = opts;
2647
+ this._nodeFsHandler = new NodeFsHandler(this);
2648
+ Object.freeze(opts);
2649
+ }
2650
+ _addIgnoredPath(matcher) {
2651
+ if (isMatcherObject(matcher)) {
2652
+ for (const ignored of this._ignoredPaths) if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) return;
2653
+ }
2654
+ this._ignoredPaths.add(matcher);
2655
+ }
2656
+ _removeIgnoredPath(matcher) {
2657
+ this._ignoredPaths.delete(matcher);
2658
+ if (typeof matcher === "string") {
2659
+ for (const ignored of this._ignoredPaths) if (isMatcherObject(ignored) && ignored.path === matcher) this._ignoredPaths.delete(ignored);
2660
+ }
2661
+ }
2662
+ /**
2663
+ * Adds paths to be watched on an existing FSWatcher instance.
2664
+ * @param paths_ file or file list. Other arguments are unused
2665
+ */
2666
+ add(paths_, _origAdd, _internal) {
2667
+ const { cwd } = this.options;
2668
+ this.closed = false;
2669
+ this._closePromise = void 0;
2670
+ let paths = unifyPaths(paths_);
2671
+ if (cwd) paths = paths.map((path) => {
2672
+ return getAbsolutePath(path, cwd);
2673
+ });
2674
+ paths.forEach((path) => {
2675
+ this._removeIgnoredPath(path);
2676
+ });
2677
+ this._userIgnored = void 0;
2678
+ if (!this._readyCount) this._readyCount = 0;
2679
+ this._readyCount += paths.length;
2680
+ Promise.all(paths.map(async (path) => {
2681
+ const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
2682
+ if (res) this._emitReady();
2683
+ return res;
2684
+ })).then((results) => {
2685
+ if (this.closed) return;
2686
+ results.forEach((item) => {
2687
+ if (item) this.add(sp.dirname(item), sp.basename(_origAdd || item));
2688
+ });
2689
+ });
2690
+ return this;
2691
+ }
2692
+ /**
2693
+ * Close watchers or start ignoring events from specified paths.
2694
+ */
2695
+ unwatch(paths_) {
2696
+ if (this.closed) return this;
2697
+ const paths = unifyPaths(paths_);
2698
+ const { cwd } = this.options;
2699
+ paths.forEach((path) => {
2700
+ if (!sp.isAbsolute(path) && !this._closers.has(path)) {
2701
+ if (cwd) path = sp.join(cwd, path);
2702
+ path = sp.resolve(path);
2703
+ }
2704
+ this._closePath(path);
2705
+ this._addIgnoredPath(path);
2706
+ if (this._watched.has(path)) this._addIgnoredPath({
2707
+ path,
2708
+ recursive: true
2709
+ });
2710
+ this._userIgnored = void 0;
2711
+ });
2712
+ return this;
2713
+ }
2714
+ /**
2715
+ * Close watchers and remove all listeners from watched paths.
2716
+ */
2717
+ close() {
2718
+ if (this._closePromise) return this._closePromise;
2719
+ this.closed = true;
2720
+ this.removeAllListeners();
2721
+ const closers = [];
2722
+ this._closers.forEach((closerList) => closerList.forEach((closer) => {
2723
+ const promise = closer();
2724
+ if (promise instanceof Promise) closers.push(promise);
2725
+ }));
2726
+ this._streams.forEach((stream) => stream.destroy());
2727
+ this._userIgnored = void 0;
2728
+ this._readyCount = 0;
2729
+ this._readyEmitted = false;
2730
+ this._watched.forEach((dirent) => dirent.dispose());
2731
+ this._closers.clear();
2732
+ this._watched.clear();
2733
+ this._streams.clear();
2734
+ this._symlinkPaths.clear();
2735
+ this._throttled.clear();
2736
+ this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
2737
+ return this._closePromise;
2738
+ }
2739
+ /**
2740
+ * Expose list of watched paths
2741
+ * @returns for chaining
2742
+ */
2743
+ getWatched() {
2744
+ const watchList = {};
2745
+ this._watched.forEach((entry, dir) => {
2746
+ const index = (this.options.cwd ? sp.relative(this.options.cwd, dir) : dir) || ONE_DOT;
2747
+ watchList[index] = entry.getChildren().sort();
2748
+ });
2749
+ return watchList;
2750
+ }
2751
+ emitWithAll(event, args) {
2752
+ this.emit(event, ...args);
2753
+ if (event !== EVENTS.ERROR) this.emit(EVENTS.ALL, event, ...args);
2754
+ }
2755
+ /**
2756
+ * Normalize and emit events.
2757
+ * Calling _emit DOES NOT MEAN emit() would be called!
2758
+ * @param event Type of event
2759
+ * @param path File or directory path
2760
+ * @param stats arguments to be passed with event
2761
+ * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
2762
+ */
2763
+ async _emit(event, path, stats) {
2764
+ if (this.closed) return;
2765
+ const opts = this.options;
2766
+ if (isWindows) path = sp.normalize(path);
2767
+ if (opts.cwd) path = sp.relative(opts.cwd, path);
2768
+ const args = [path];
2769
+ if (stats != null) args.push(stats);
2770
+ const awf = opts.awaitWriteFinish;
2771
+ let pw;
2772
+ if (awf && (pw = this._pendingWrites.get(path))) {
2773
+ pw.lastChange = /* @__PURE__ */ new Date();
2774
+ return this;
2775
+ }
2776
+ if (opts.atomic) {
2777
+ if (event === EVENTS.UNLINK) {
2778
+ this._pendingUnlinks.set(path, [event, ...args]);
2779
+ setTimeout(() => {
2780
+ this._pendingUnlinks.forEach((entry, path) => {
2781
+ this.emit(...entry);
2782
+ this.emit(EVENTS.ALL, ...entry);
2783
+ this._pendingUnlinks.delete(path);
2784
+ });
2785
+ }, typeof opts.atomic === "number" ? opts.atomic : 100);
2786
+ return this;
2787
+ }
2788
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
2789
+ event = EVENTS.CHANGE;
2790
+ this._pendingUnlinks.delete(path);
2791
+ }
2792
+ }
2793
+ if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
2794
+ const awfEmit = (err, stats) => {
2795
+ if (err) {
2796
+ event = EVENTS.ERROR;
2797
+ args[0] = err;
2798
+ this.emitWithAll(event, args);
2799
+ } else if (stats) {
2800
+ if (args.length > 1) args[1] = stats;
2801
+ else args.push(stats);
2802
+ this.emitWithAll(event, args);
2803
+ }
2804
+ };
2805
+ this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
2806
+ return this;
2807
+ }
2808
+ if (event === EVENTS.CHANGE) {
2809
+ if (!this._throttle(EVENTS.CHANGE, path, 50)) return this;
2810
+ }
2811
+ if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
2812
+ const fullPath = opts.cwd ? sp.join(opts.cwd, path) : path;
2813
+ let stats;
2814
+ try {
2815
+ stats = await stat$1(fullPath);
2816
+ } catch (err) {}
2817
+ if (!stats || this.closed) return;
2818
+ args.push(stats);
2819
+ }
2820
+ this.emitWithAll(event, args);
2821
+ return this;
2822
+ }
2823
+ /**
2824
+ * Common handler for errors
2825
+ * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
2826
+ */
2827
+ _handleError(error) {
2828
+ const code = error && error.code;
2829
+ if (error && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) this.emit(EVENTS.ERROR, error);
2830
+ return error || this.closed;
2831
+ }
2832
+ /**
2833
+ * Helper utility for throttling
2834
+ * @param actionType type being throttled
2835
+ * @param path being acted upon
2836
+ * @param timeout duration of time to suppress duplicate actions
2837
+ * @returns tracking object or false if action should be suppressed
2838
+ */
2839
+ _throttle(actionType, path, timeout) {
2840
+ if (!this._throttled.has(actionType)) this._throttled.set(actionType, /* @__PURE__ */ new Map());
2841
+ const action = this._throttled.get(actionType);
2842
+ if (!action) throw new Error("invalid throttle");
2843
+ const actionPath = action.get(path);
2844
+ if (actionPath) {
2845
+ actionPath.count++;
2846
+ return false;
2847
+ }
2848
+ let timeoutObject;
2849
+ const clear = () => {
2850
+ const item = action.get(path);
2851
+ const count = item ? item.count : 0;
2852
+ action.delete(path);
2853
+ clearTimeout(timeoutObject);
2854
+ if (item) clearTimeout(item.timeoutObject);
2855
+ return count;
2856
+ };
2857
+ timeoutObject = setTimeout(clear, timeout);
2858
+ const thr = {
2859
+ timeoutObject,
2860
+ clear,
2861
+ count: 0
2862
+ };
2863
+ action.set(path, thr);
2864
+ return thr;
2865
+ }
2866
+ _incrReadyCount() {
2867
+ return this._readyCount++;
2868
+ }
2869
+ /**
2870
+ * Awaits write operation to finish.
2871
+ * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
2872
+ * @param path being acted upon
2873
+ * @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
2874
+ * @param event
2875
+ * @param awfEmit Callback to be called when ready for event to be emitted.
2876
+ */
2877
+ _awaitWriteFinish(path, threshold, event, awfEmit) {
2878
+ const awf = this.options.awaitWriteFinish;
2879
+ if (typeof awf !== "object") return;
2880
+ const pollInterval = awf.pollInterval;
2881
+ let timeoutHandler;
2882
+ let fullPath = path;
2883
+ if (this.options.cwd && !sp.isAbsolute(path)) fullPath = sp.join(this.options.cwd, path);
2884
+ const now = /* @__PURE__ */ new Date();
2885
+ const writes = this._pendingWrites;
2886
+ function awaitWriteFinishFn(prevStat) {
2887
+ stat(fullPath, (err, curStat) => {
2888
+ if (err || !writes.has(path)) {
2889
+ if (err && err.code !== "ENOENT") awfEmit(err);
2890
+ return;
2891
+ }
2892
+ const now = Number(/* @__PURE__ */ new Date());
2893
+ if (prevStat && curStat.size !== prevStat.size) writes.get(path).lastChange = now;
2894
+ if (now - writes.get(path).lastChange >= threshold) {
2895
+ writes.delete(path);
2896
+ awfEmit(void 0, curStat);
2897
+ } else timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
2898
+ });
2899
+ }
2900
+ if (!writes.has(path)) {
2901
+ writes.set(path, {
2902
+ lastChange: now,
2903
+ cancelWait: () => {
2904
+ writes.delete(path);
2905
+ clearTimeout(timeoutHandler);
2906
+ return event;
2907
+ }
2908
+ });
2909
+ timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
2910
+ }
2911
+ }
2912
+ /**
2913
+ * Determines whether user has asked to ignore this path.
2914
+ */
2915
+ _isIgnored(path, stats) {
2916
+ if (this.options.atomic && DOT_RE.test(path)) return true;
2917
+ if (!this._userIgnored) {
2918
+ const { cwd } = this.options;
2919
+ const ignored = (this.options.ignored || []).map(normalizeIgnored(cwd));
2920
+ this._userIgnored = anymatch([...[...this._ignoredPaths].map(normalizeIgnored(cwd)), ...ignored], void 0);
2921
+ }
2922
+ return this._userIgnored(path, stats);
2923
+ }
2924
+ _isntIgnored(path, stat) {
2925
+ return !this._isIgnored(path, stat);
2926
+ }
2927
+ /**
2928
+ * Provides a set of common helpers and properties relating to symlink handling.
2929
+ * @param path file or directory pattern being watched
2930
+ */
2931
+ _getWatchHelpers(path) {
2932
+ return new WatchHelper(path, this.options.followSymlinks, this);
2933
+ }
2934
+ /**
2935
+ * Provides directory tracking objects
2936
+ * @param directory path of the directory
2937
+ */
2938
+ _getWatchedDir(directory) {
2939
+ const dir = sp.resolve(directory);
2940
+ if (!this._watched.has(dir)) this._watched.set(dir, new DirEntry(dir, this._boundRemove));
2941
+ return this._watched.get(dir);
2942
+ }
2943
+ /**
2944
+ * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
2945
+ */
2946
+ _hasReadPermissions(stats) {
2947
+ if (this.options.ignorePermissionErrors) return true;
2948
+ return Boolean(Number(stats.mode) & 256);
2949
+ }
2950
+ /**
2951
+ * Handles emitting unlink events for
2952
+ * files and directories, and via recursion, for
2953
+ * files and directories within directories that are unlinked
2954
+ * @param directory within which the following item is located
2955
+ * @param item base path of item/directory
2956
+ */
2957
+ _remove(directory, item, isDirectory) {
2958
+ const path = sp.join(directory, item);
2959
+ const fullPath = sp.resolve(path);
2960
+ isDirectory = isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
2961
+ if (!this._throttle("remove", path, 100)) return;
2962
+ if (!isDirectory && this._watched.size === 1) this.add(directory, item, true);
2963
+ this._getWatchedDir(path).getChildren().forEach((nested) => this._remove(path, nested));
2964
+ const parent = this._getWatchedDir(directory);
2965
+ const wasTracked = parent.has(item);
2966
+ parent.remove(item);
2967
+ if (this._symlinkPaths.has(fullPath)) this._symlinkPaths.delete(fullPath);
2968
+ let relPath = path;
2969
+ if (this.options.cwd) relPath = sp.relative(this.options.cwd, path);
2970
+ if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
2971
+ if (this._pendingWrites.get(relPath).cancelWait() === EVENTS.ADD) return;
2972
+ }
2973
+ this._watched.delete(path);
2974
+ this._watched.delete(fullPath);
2975
+ const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
2976
+ if (wasTracked && !this._isIgnored(path)) this._emit(eventName, path);
2977
+ this._closePath(path);
2978
+ }
2979
+ /**
2980
+ * Closes all watchers for a path
2981
+ */
2982
+ _closePath(path) {
2983
+ this._closeFile(path);
2984
+ const dir = sp.dirname(path);
2985
+ this._getWatchedDir(dir).remove(sp.basename(path));
2986
+ }
2987
+ /**
2988
+ * Closes only file-specific watchers
2989
+ */
2990
+ _closeFile(path) {
2991
+ const closers = this._closers.get(path);
2992
+ if (!closers) return;
2993
+ closers.forEach((closer) => closer());
2994
+ this._closers.delete(path);
2995
+ }
2996
+ _addPathCloser(path, closer) {
2997
+ if (!closer) return;
2998
+ let list = this._closers.get(path);
2999
+ if (!list) {
3000
+ list = [];
3001
+ this._closers.set(path, list);
3002
+ }
3003
+ list.push(closer);
3004
+ }
3005
+ _readdirp(root, opts) {
3006
+ if (this.closed) return;
3007
+ let stream = readdirp(root, {
3008
+ type: EVENTS.ALL,
3009
+ alwaysStat: true,
3010
+ lstat: true,
3011
+ ...opts,
3012
+ depth: 0
3013
+ });
3014
+ this._streams.add(stream);
3015
+ stream.once(STR_CLOSE, () => {
3016
+ stream = void 0;
3017
+ });
3018
+ stream.once("end", () => {
3019
+ if (stream) {
3020
+ this._streams.delete(stream);
3021
+ stream = void 0;
3022
+ }
3023
+ });
3024
+ return stream;
3025
+ }
3026
+ };
3027
+ /**
3028
+ * Instantiates watcher with paths to be tracked.
3029
+ * @param paths file / directory paths
3030
+ * @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
3031
+ * @returns an instance of FSWatcher for chaining.
3032
+ * @example
3033
+ * const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
3034
+ * watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
3035
+ */
3036
+ function watch$1(paths, options = {}) {
3037
+ const watcher = new FSWatcher(options);
3038
+ watcher.add(paths);
3039
+ return watcher;
3040
+ }
3041
+ var chokidar_default = {
3042
+ watch: watch$1,
3043
+ FSWatcher
3044
+ };
3045
+ //#endregion
3046
+ //#region ../../packages/core/src/services/event.service.ts
3047
+ var EventService = class EventService extends ServiceMap.Service()("@ringi/EventService") {
3048
+ static Default = Layer.effect(EventService, Effect.sync(() => {
3049
+ const subscribers = /* @__PURE__ */ new Set();
3050
+ const broadcast = (type, data) => Effect.gen(function* () {
3051
+ const event = {
3052
+ data,
3053
+ timestamp: Date.now(),
3054
+ type
3055
+ };
3056
+ for (const queue of subscribers) yield* Queue.offer(queue, event);
3057
+ });
3058
+ const subscribe = () => Effect.gen(function* () {
3059
+ const queue = yield* Queue.sliding(100);
3060
+ subscribers.add(queue);
3061
+ return {
3062
+ stream: Stream.fromQueue(queue),
3063
+ unsubscribe: Effect.sync(() => {
3064
+ subscribers.delete(queue);
3065
+ }).pipe(Effect.andThen(Queue.shutdown(queue)))
3066
+ };
3067
+ });
3068
+ const startFileWatcher = (repoPath) => Effect.acquireRelease(Effect.sync(() => {
3069
+ let debounceTimer = null;
3070
+ const watcher = chokidar_default.watch(repoPath, {
3071
+ ignoreInitial: true,
3072
+ ignored: [
3073
+ "**/node_modules/**",
3074
+ "**/.git/**",
3075
+ "**/.ringi/**",
3076
+ "**/dist/**"
3077
+ ],
3078
+ persistent: true,
3079
+ ...platform() === "darwin" ? {
3080
+ interval: 1e3,
3081
+ usePolling: true
3082
+ } : {}
3083
+ });
3084
+ const debouncedBroadcast = (filePath) => {
3085
+ if (debounceTimer) clearTimeout(debounceTimer);
3086
+ debounceTimer = setTimeout(() => {
3087
+ const rel = relative(repoPath, filePath);
3088
+ Effect.runFork(broadcast("files", { path: rel }));
3089
+ }, 300);
3090
+ };
3091
+ watcher.on("add", debouncedBroadcast);
3092
+ watcher.on("change", debouncedBroadcast);
3093
+ watcher.on("unlink", debouncedBroadcast);
3094
+ return watcher;
3095
+ }), (watcher) => Effect.promise(() => watcher.close()));
3096
+ const getClientCount = () => Effect.sync(() => subscribers.size);
3097
+ return EventService.of({
3098
+ broadcast,
3099
+ getClientCount,
3100
+ startFileWatcher,
3101
+ subscribe
3102
+ });
3103
+ }));
3104
+ };
3105
+ //#endregion
3106
+ //#region ../../packages/core/src/runtime.ts
3107
+ const RepoLive = Layer.mergeAll(ReviewRepo.Default, ReviewFileRepo.Default, CommentRepo.Default, TodoRepo.Default).pipe(Layer.provide(SqliteService.Default));
3108
+ const CommentServiceLive = CommentService.Default.pipe(Layer.provide(CommentRepo.Default), Layer.provide(SqliteService.Default));
3109
+ const TodoServiceLive = TodoService.Default.pipe(Layer.provide(TodoRepo.Default), Layer.provide(SqliteService.Default));
3110
+ const ReviewServiceLive = ReviewService.Default.pipe(Layer.provide(ReviewRepo.Default), Layer.provide(ReviewFileRepo.Default), Layer.provide(GitService.Default), Layer.provide(SqliteService.Default));
3111
+ const ExportServiceLive = ExportService.Default.pipe(Layer.provide(ReviewServiceLive), Layer.provide(CommentServiceLive), Layer.provide(TodoServiceLive));
3112
+ const CoreLive = Layer.mergeAll(ReviewServiceLive, CommentServiceLive, TodoServiceLive, GitService.Default, GhService.Default, EventService.Default, ExportServiceLive, RepoLive, SqliteService.Default);
3113
+ //#endregion
3114
+ export { ReviewSourceType as _, ReviewService as a, ReviewFileRepo as c, parseDiff as d, CommentService as f, ReviewNotFound as g, ReviewId as h, TodoService as i, serializeHunks as l, TodoNotFound as m, GhService as n, GitService as o, TodoId as p, ExportService as r, ReviewRepo as s, CoreLive as t, getDiffSummary as u };
3115
+
3116
+ //# sourceMappingURL=runtime.mjs.map