@poe-platform/safe-bash 0.1.788 → 0.1.790

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 (342) hide show
  1. package/README.md +1 -1
  2. package/dist/image-ast/index.browser.js +147 -80
  3. package/dist/image-ast/index.js +147 -80
  4. package/dist/mp4-ast/mp4.d.ts +2 -0
  5. package/dist/pdf-ast/cos/parser.d.ts +1 -0
  6. package/dist/pdf-ast/cos/security.d.ts +2 -0
  7. package/dist/pdf-ast/cos/writer.d.ts +1 -0
  8. package/dist/pdf-ast/document.d.ts +3 -0
  9. package/dist/pdf-ast/edit/forms.d.ts +1 -0
  10. package/dist/pdf-ast/index.js +171 -82
  11. package/dist/safe-bash/chunks/{chunk-L5QQLNTO.js → chunk-22PI65AH.js} +2 -2
  12. package/dist/safe-bash/chunks/{chunk-Q3E6C3DX.js → chunk-2TAGYMPK.js} +49 -34
  13. package/dist/safe-bash/chunks/{chunk-Z3HX3ZBA.js → chunk-2W4HTMEK.js} +52 -48
  14. package/dist/safe-bash/chunks/{chunk-FFZXP6ZC.js → chunk-3M7L7XU2.js} +2 -2
  15. package/dist/safe-bash/chunks/{chunk-XNODZRVD.js → chunk-3QAO6UYS.js} +2 -2
  16. package/dist/safe-bash/chunks/{chunk-YPETOVQU.js → chunk-3VKFK3NF.js} +2 -2
  17. package/dist/safe-bash/chunks/chunk-5OST7NOX.js +42 -0
  18. package/dist/safe-bash/chunks/{chunk-KEBSX2AX.js → chunk-6HLURHVU.js} +2 -2
  19. package/dist/safe-bash/chunks/chunk-DYEUZE6Z.js +19 -0
  20. package/dist/safe-bash/chunks/{chunk-T2TGCHKE.js → chunk-FM3WBSZT.js} +2 -2
  21. package/dist/safe-bash/chunks/chunk-GAYRKQM6.js +22 -0
  22. package/dist/safe-bash/chunks/{chunk-Q45QCA4J.js → chunk-I3KSESCR.js} +0 -7
  23. package/dist/safe-bash/chunks/{chunk-OSKDIBQS.js → chunk-JLIMK5TD.js} +1 -1
  24. package/dist/safe-bash/chunks/{chunk-2AYZCT5X.js → chunk-JQ2FAJJT.js} +27 -23
  25. package/dist/safe-bash/chunks/{chunk-QA3NVP43.js → chunk-JRE6Z3T7.js} +2 -2
  26. package/dist/safe-bash/chunks/{chunk-DC5EHLKS.js → chunk-NDIL6T7Y.js} +5 -5
  27. package/dist/safe-bash/chunks/{chunk-747G42FY.js → chunk-OPR4UAIT.js} +2 -2
  28. package/dist/safe-bash/chunks/chunk-OSMQCYSP.js +19 -0
  29. package/dist/safe-bash/chunks/chunk-OYB332PQ.js +17 -0
  30. package/dist/safe-bash/chunks/{chunk-ZMYVCRAF.js → chunk-QTIH2AFE.js} +77 -69
  31. package/dist/safe-bash/chunks/{chunk-PYTLIUST.js → chunk-SBESXWT2.js} +43 -44
  32. package/dist/safe-bash/chunks/{chunk-4FDQJUFW.js → chunk-SDEPGTOF.js} +1 -1
  33. package/dist/safe-bash/chunks/chunk-UZU5BIJI.js +32 -0
  34. package/dist/safe-bash/chunks/{chunk-BI6JV62X.js → chunk-VCCMROTL.js} +7 -10
  35. package/dist/safe-bash/chunks/chunk-W47GHRRF.js +13 -0
  36. package/dist/safe-bash/chunks/{chunk-NPMQWZUZ.js → chunk-WS7KZIUM.js} +2 -2
  37. package/dist/safe-bash/chunks/{chunk-3PZYHMGM.js → chunk-YYAERCWS.js} +7 -7
  38. package/dist/safe-bash/chunks/{chunk-5U7JECDB.js → chunk-ZPGVEUKF.js} +8 -7
  39. package/dist/safe-bash/chunks/{csvkit-K55OYAQC.js → csvkit-USUJG62I.js} +65 -11
  40. package/dist/safe-bash/chunks/{ffmpeg-BEFTQ6DZ.js → ffmpeg-KRGG5DLH.js} +21 -10
  41. package/dist/safe-bash/chunks/{gh-HQWOWLWE.js → gh-UCFDUZCX.js} +16 -8
  42. package/dist/safe-bash/chunks/{git-UFNPAOYZ.js → git-LPAF6KDG.js} +7 -9
  43. package/dist/safe-bash/chunks/{imagemagick-53BMHH6D.js → imagemagick-KGREKK4G.js} +38 -7
  44. package/dist/safe-bash/chunks/{implementation-QUTAAYMT.js → implementation-FXDRYS5A.js} +34 -8
  45. package/dist/safe-bash/chunks/{pdfimages-4OYI6FLG.js → pdfimages-UADCF4G4.js} +12 -8
  46. package/dist/safe-bash/chunks/{pdfinfo-I7U6TQPP.js → pdfinfo-O7UWPF4W.js} +38 -13
  47. package/dist/safe-bash/chunks/{pdftk-SUA6FMHI.js → pdftk-AERXIJTN.js} +13 -8
  48. package/dist/safe-bash/chunks/{pdftoppm-4C5DGEWX.js → pdftoppm-L466JQKI.js} +17 -10
  49. package/dist/safe-bash/chunks/{pdftotext-Y4WI225Y.js → pdftotext-SUSI4WXS.js} +19 -9
  50. package/dist/safe-bash/chunks/{qpdf-IORB4RV5.js → qpdf-YL24KVRH.js} +14 -8
  51. package/dist/safe-bash/chunks/{sips-WHAMJFEU.js → sips-QXEQZERX.js} +14 -7
  52. package/dist/safe-bash/chunks/{soffice-SYEK6WJS.js → soffice-TBITRML3.js} +16 -8
  53. package/dist/safe-bash/chunks/{wkhtmltopdf-ZIICWJLF.js → wkhtmltopdf-NJA2THRC.js} +27 -7
  54. package/dist/safe-bash/command-chunks/chunk-2C5BEBPY.js +1388 -0
  55. package/dist/safe-bash/command-chunks/{chunk-FXYWQ6S4.js → chunk-2EXV2ZLV.js} +2 -2
  56. package/dist/safe-bash/command-chunks/{chunk-PFBJR2PY.js → chunk-2KRKKW5S.js} +2 -2
  57. package/dist/safe-bash/command-chunks/{chunk-4DSJDVBM.js → chunk-32F3RBUW.js} +10 -749
  58. package/dist/safe-bash/command-chunks/{chunk-L3MLMXL4.js → chunk-3ZK5F23O.js} +1 -1
  59. package/dist/safe-bash/command-chunks/{chunk-4QX6XCDD.js → chunk-4RNIZ3RT.js} +79 -0
  60. package/dist/safe-bash/command-chunks/{chunk-D7TADAYG.js → chunk-64LG3EVJ.js} +17 -0
  61. package/dist/safe-bash/command-chunks/{chunk-TOSM3T3A.js → chunk-6EASC5EC.js} +20 -9
  62. package/dist/safe-bash/command-chunks/{chunk-ZF3ZVGQC.js → chunk-7JRITHKW.js} +150 -80
  63. package/dist/safe-bash/command-chunks/{chunk-IJ3FXP4Q.js → chunk-A3ZX6SCY.js} +1 -1
  64. package/dist/safe-bash/{chunks/chunk-LD76P7AG.js → command-chunks/chunk-AKDMCNX4.js} +74 -39
  65. package/dist/safe-bash/command-chunks/{chunk-KSIGF4AG.js → chunk-BK4CMEE6.js} +1 -1
  66. package/dist/safe-bash/command-chunks/{chunk-JUDOV5MJ.js → chunk-CBDVLMJB.js} +1 -1
  67. package/dist/safe-bash/command-chunks/{chunk-XGMWWUHV.js → chunk-CZ5DAK4K.js} +1 -1
  68. package/dist/safe-bash/command-chunks/{chunk-Z57TV6TC.js → chunk-EZ2DTOLI.js} +4 -2
  69. package/dist/safe-bash/command-chunks/{chunk-ADCGH6A7.js → chunk-FH3D75FC.js} +1 -1
  70. package/dist/safe-bash/command-chunks/{chunk-WYJTWJZ5.js → chunk-G3G6W5ZE.js} +1 -1
  71. package/dist/safe-bash/command-chunks/{chunk-3HDIDEUJ.js → chunk-GF54KE2M.js} +1 -1
  72. package/dist/safe-bash/command-chunks/chunk-H4LWTITX.js +169 -0
  73. package/dist/safe-bash/command-chunks/chunk-I2MQNBGR.js +145 -0
  74. package/dist/safe-bash/command-chunks/{chunk-Z7TYZG3A.js → chunk-IHHTTQX6.js} +5 -3
  75. package/dist/safe-bash/command-chunks/{chunk-5GRLAARV.js → chunk-IOXI5ZAJ.js} +1 -1
  76. package/dist/safe-bash/command-chunks/{chunk-INDIFLBW.js → chunk-JTAGNROA.js} +4 -0
  77. package/dist/safe-bash/command-chunks/{chunk-Y5IHIAY3.js → chunk-MDPIOQUD.js} +12 -8
  78. package/dist/safe-bash/command-chunks/chunk-PGEYORBZ.js +25 -0
  79. package/dist/safe-bash/command-chunks/chunk-QI4MGIN6.js +6 -0
  80. package/dist/safe-bash/command-chunks/chunk-QM4UZF3C.js +753 -0
  81. package/dist/safe-bash/command-chunks/chunk-QTYZAWSB.js +91 -0
  82. package/dist/safe-bash/command-chunks/chunk-SNK7K3XW.js +90 -0
  83. package/dist/safe-bash/command-chunks/chunk-T5OLGM43.js +314 -0
  84. package/dist/safe-bash/command-chunks/chunk-TB7IFMUZ.js +802 -0
  85. package/dist/safe-bash/command-chunks/{chunk-YNT4ZJHW.js → chunk-TPPBPIWL.js} +3 -3
  86. package/dist/safe-bash/command-chunks/chunk-VMK4XVKO.js +82 -0
  87. package/dist/safe-bash/command-chunks/chunk-VNSJKXDU.js +130 -0
  88. package/dist/safe-bash/command-chunks/{chunk-2LP3VMPA.js → chunk-WFDW4XXD.js} +1 -17
  89. package/dist/safe-bash/command-chunks/chunk-WR37IS4O.js +318 -0
  90. package/dist/safe-bash/command-chunks/chunk-YFNTMH6Z.js +6 -0
  91. package/dist/safe-bash/commands/basic.js +148 -48
  92. package/dist/safe-bash/commands/bytes/compression/index.js +5 -6
  93. package/dist/safe-bash/commands/cmp.d.ts +2 -3
  94. package/dist/safe-bash/commands/cmp.js +2 -689
  95. package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
  96. package/dist/safe-bash/commands/docx/index.browser.js +4 -47
  97. package/dist/safe-bash/commands/docx/index.d.ts +2 -24
  98. package/dist/safe-bash/commands/docx/index.js +2 -41
  99. package/dist/safe-bash/commands/docx/io.d.ts +1 -14
  100. package/dist/safe-bash/commands/docx/io.js +1 -15
  101. package/dist/safe-bash/commands/factor/index.browser.js +2 -2
  102. package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
  103. package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
  104. package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
  105. package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
  106. package/dist/safe-bash/commands/llm/command.d.ts +1 -4
  107. package/dist/safe-bash/commands/llm/command.js +1 -248
  108. package/dist/safe-bash/commands/llm/elevenlabs-stream.d.ts +1 -2
  109. package/dist/safe-bash/commands/llm/elevenlabs-stream.js +1 -117
  110. package/dist/safe-bash/commands/llm/elevenlabs.d.ts +1 -15
  111. package/dist/safe-bash/commands/llm/elevenlabs.js +1 -123
  112. package/dist/safe-bash/commands/llm/index.browser.js +20 -15
  113. package/dist/safe-bash/commands/llm/index.d.ts +1 -6
  114. package/dist/safe-bash/commands/llm/index.js +1 -4
  115. package/dist/safe-bash/commands/llm/mime.d.ts +1 -2
  116. package/dist/safe-bash/commands/llm/mime.js +1 -136
  117. package/dist/safe-bash/commands/llm/openai-http.d.ts +1 -8
  118. package/dist/safe-bash/commands/llm/openai-http.js +1 -143
  119. package/dist/safe-bash/commands/llm/openai-sse.d.ts +1 -3
  120. package/dist/safe-bash/commands/llm/openai-sse.js +1 -78
  121. package/dist/safe-bash/commands/llm/openai.d.ts +1 -14
  122. package/dist/safe-bash/commands/llm/openai.js +1 -288
  123. package/dist/safe-bash/commands/llm/providers/elevenlabs.d.ts +1 -1
  124. package/dist/safe-bash/commands/llm/providers/elevenlabs.js +1 -1
  125. package/dist/safe-bash/commands/llm/providers/index.browser.js +6 -6
  126. package/dist/safe-bash/commands/llm/providers/index.d.ts +1 -3
  127. package/dist/safe-bash/commands/llm/providers/index.js +1 -2
  128. package/dist/safe-bash/commands/llm/providers/openai.d.ts +1 -1
  129. package/dist/safe-bash/commands/llm/providers/openai.js +1 -1
  130. package/dist/safe-bash/commands/llm/providers/shared.d.ts +1 -23
  131. package/dist/safe-bash/commands/llm/providers/shared.js +1 -65
  132. package/dist/safe-bash/commands/llm/service.d.ts +1 -37
  133. package/dist/safe-bash/commands/llm/service.js +1 -151
  134. package/dist/safe-bash/commands/llm/types.d.ts +1 -52
  135. package/dist/safe-bash/commands/llm/types.js +1 -1
  136. package/dist/safe-bash/commands/mdq/index.browser.js +3 -3
  137. package/dist/safe-bash/commands/media/index.browser.js +1 -1
  138. package/dist/safe-bash/commands/network/index.browser.js +9 -9
  139. package/dist/safe-bash/commands/network/types.d.ts +2 -40
  140. package/dist/safe-bash/commands/node/index.browser.js +6 -8
  141. package/dist/safe-bash/commands/op/index.browser.js +3 -3
  142. package/dist/safe-bash/commands/op/index.js +12 -28
  143. package/dist/safe-bash/commands/pptx/index.d.ts +2 -28
  144. package/dist/safe-bash/commands/pptx/index.js +2 -152
  145. package/dist/safe-bash/commands/pr/index.browser.js +2 -2
  146. package/dist/safe-bash/commands/printf-float.d.ts +1 -0
  147. package/dist/safe-bash/commands/printf-float.js +48 -38
  148. package/dist/safe-bash/commands/printf-format.js +9 -6
  149. package/dist/safe-bash/commands/printf-quote.d.ts +3 -0
  150. package/dist/safe-bash/commands/printf-quote.js +62 -0
  151. package/dist/safe-bash/commands/printf-wide.d.ts +5 -0
  152. package/dist/safe-bash/commands/printf-wide.js +41 -0
  153. package/dist/safe-bash/commands/python/index.browser.js +8 -8
  154. package/dist/safe-bash/commands/python/worker.browser.js +2 -2
  155. package/dist/safe-bash/commands/truncate.d.ts +2 -3
  156. package/dist/safe-bash/commands/truncate.js +2 -686
  157. package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
  158. package/dist/safe-bash/commands/xml/index.browser.js +2 -2
  159. package/dist/safe-bash/commands/yq/index.browser.js +3 -3
  160. package/dist/safe-bash/contracts/diagnostics.d.ts +2 -0
  161. package/dist/safe-bash/contracts/diagnostics.js +2 -0
  162. package/dist/safe-bash/contracts/runtime-control.d.ts +2 -0
  163. package/dist/safe-bash/contracts/runtime-control.js +2 -0
  164. package/dist/safe-bash/core.browser.d.ts +1 -1
  165. package/dist/safe-bash/core.browser.js +10645 -14065
  166. package/dist/safe-bash/core.d.ts +10 -1
  167. package/dist/safe-bash/core.js +0 -1
  168. package/dist/safe-bash/jobs.browser.js +5 -4
  169. package/dist/safe-bash/opt-in/commands/cmp/index.d.ts +6 -2
  170. package/dist/safe-bash/opt-in/commands/cmp/index.js +776 -79
  171. package/dist/safe-bash/opt-in/commands/cmp/options.d.ts +0 -12
  172. package/dist/safe-bash/opt-in/commands/cmp/options.js +0 -153
  173. package/dist/safe-bash/opt-in/commands/truncate/index.d.ts +8 -3
  174. package/dist/safe-bash/opt-in/commands/truncate/index.js +790 -272
  175. package/dist/safe-bash/opt-in/commands/truncate/sync.d.ts +1 -0
  176. package/dist/safe-bash/opt-in/commands/truncate/sync.js +60 -0
  177. package/dist/safe-bash/optional-host.browser.js +61 -80
  178. package/dist/safe-bash/optional-host.d.ts +3 -1
  179. package/dist/safe-bash/optional-host.js +3 -1
  180. package/dist/safe-bash/shell/runtime.js +44 -18
  181. package/dist/safe-bash/yq-browser/index.js +1 -1
  182. package/dist/safe-bash-checksum-engine/index.d.ts +1 -1
  183. package/dist/safe-bash-checksum-engine/index.js +14 -2
  184. package/dist/safe-bash-command-bzip2/index.js +2 -1
  185. package/dist/safe-bash-command-cmp/index.d.ts +10 -0
  186. package/dist/safe-bash-command-cmp/index.js +796 -0
  187. package/dist/safe-bash-command-cmp/options.d.ts +12 -0
  188. package/dist/safe-bash-command-cmp/options.js +42 -0
  189. package/dist/safe-bash-command-csvcut/index.js +11 -8
  190. package/dist/safe-bash-command-csvgrep/index.js +35 -7
  191. package/dist/safe-bash-command-csvkit/codecs/python.js +4 -3
  192. package/dist/safe-bash-command-csvkit/codecs/utf8.js +3 -2
  193. package/dist/safe-bash-command-csvkit/index.js +80 -324
  194. package/dist/safe-bash-command-csvkit/python-regex.d.ts +5 -0
  195. package/dist/safe-bash-command-csvkit/python-regex.js +14 -0
  196. package/dist/safe-bash-command-csvkit/runtime.d.ts +1 -0
  197. package/dist/safe-bash-command-csvkit/sync-support.js +4 -2
  198. package/dist/safe-bash-command-diff3/index.js +3 -0
  199. package/dist/safe-bash-command-docx/LICENSE +21 -0
  200. package/dist/safe-bash-command-docx/index.d.ts +30 -0
  201. package/dist/safe-bash-command-docx/index.js +67 -0
  202. package/dist/safe-bash-command-docx/io.d.ts +14 -0
  203. package/dist/safe-bash-command-docx/io.js +26 -0
  204. package/dist/safe-bash-command-envsubst/index.js +34 -3
  205. package/dist/safe-bash-command-exiftool/index.js +3 -0
  206. package/dist/safe-bash-command-ffmpeg/index.js +8073 -7940
  207. package/dist/safe-bash-command-fold/family.js +1 -1
  208. package/dist/safe-bash-command-fold/index.js +1 -1
  209. package/dist/safe-bash-command-git/git_rust.wasm +0 -0
  210. package/dist/safe-bash-command-git/wasm.generated.js +1 -1
  211. package/dist/safe-bash-command-htmlq/index.js +5 -0
  212. package/dist/safe-bash-command-imagemagick/index.d.ts +25 -21
  213. package/dist/safe-bash-command-imagemagick/index.js +671 -273
  214. package/dist/safe-bash-command-llm/LICENSE +21 -0
  215. package/dist/safe-bash-command-llm/command.d.ts +5 -0
  216. package/dist/safe-bash-command-llm/command.js +14 -0
  217. package/dist/safe-bash-command-llm/configuration.d.ts +18 -0
  218. package/dist/safe-bash-command-llm/elevenlabs-stream.d.ts +2 -0
  219. package/dist/safe-bash-command-llm/elevenlabs-stream.js +7 -0
  220. package/dist/safe-bash-command-llm/elevenlabs.d.ts +15 -0
  221. package/dist/safe-bash-command-llm/elevenlabs.js +10 -0
  222. package/dist/safe-bash-command-llm/index.d.ts +10 -0
  223. package/dist/safe-bash-command-llm/index.js +46 -0
  224. package/dist/safe-bash-command-llm/mime.d.ts +2 -0
  225. package/dist/safe-bash-command-llm/mime.js +9 -0
  226. package/dist/safe-bash-command-llm/model-options.d.ts +3 -0
  227. package/dist/safe-bash-command-llm/openai-http.d.ts +8 -0
  228. package/dist/safe-bash-command-llm/openai-http.js +17 -0
  229. package/dist/safe-bash-command-llm/openai-sse.d.ts +3 -0
  230. package/dist/safe-bash-command-llm/openai-sse.js +8 -0
  231. package/dist/safe-bash-command-llm/openai.d.ts +14 -0
  232. package/dist/safe-bash-command-llm/openai.js +12 -0
  233. package/dist/safe-bash-command-llm/providers/elevenlabs.d.ts +1 -0
  234. package/dist/safe-bash-command-llm/providers/elevenlabs.js +11 -0
  235. package/dist/safe-bash-command-llm/providers/index.d.ts +3 -0
  236. package/dist/safe-bash-command-llm/providers/index.js +24 -0
  237. package/dist/safe-bash-command-llm/providers/openai.d.ts +1 -0
  238. package/dist/safe-bash-command-llm/providers/openai.js +13 -0
  239. package/dist/safe-bash-command-llm/providers/shared.d.ts +23 -0
  240. package/dist/safe-bash-command-llm/providers/shared.js +13 -0
  241. package/dist/safe-bash-command-llm/schemas.d.ts +2 -0
  242. package/dist/safe-bash-command-llm/service.d.ts +42 -0
  243. package/dist/safe-bash-command-llm/service.js +9 -0
  244. package/dist/safe-bash-command-llm/templates.d.ts +27 -0
  245. package/dist/safe-bash-command-llm/types.d.ts +87 -0
  246. package/dist/safe-bash-command-llm/types.js +6 -0
  247. package/dist/safe-bash-command-mmdc/command.d.ts +4 -0
  248. package/dist/safe-bash-command-mmdc/index.d.ts +1 -1
  249. package/dist/safe-bash-command-mmdc/index.js +7134 -6699
  250. package/dist/safe-bash-command-mmdc/layout.d.ts +1 -0
  251. package/dist/safe-bash-command-mmdc/parser.d.ts +1 -0
  252. package/dist/safe-bash-command-mmdc/png.d.ts +3 -0
  253. package/dist/safe-bash-command-mmdc/raster.d.ts +1 -0
  254. package/dist/safe-bash-command-mmdc/svg.d.ts +1 -0
  255. package/dist/safe-bash-command-op/index.js +19 -14
  256. package/dist/safe-bash-command-pandoc/command.js +3 -3
  257. package/dist/safe-bash-command-pandoc/index.js +3 -3
  258. package/dist/safe-bash-command-pdfimages/index.d.ts +7 -1
  259. package/dist/safe-bash-command-pdfimages/index.js +210 -113
  260. package/dist/safe-bash-command-pdfinfo/index.d.ts +24 -20
  261. package/dist/safe-bash-command-pdfinfo/index.js +517 -241
  262. package/dist/safe-bash-command-pdftk/index.d.ts +7 -3
  263. package/dist/safe-bash-command-pdftk/index.js +261 -125
  264. package/dist/safe-bash-command-pdftoppm/index.d.ts +15 -7
  265. package/dist/safe-bash-command-pdftoppm/index.js +326 -189
  266. package/dist/safe-bash-command-pdftotext/index.d.ts +9 -5
  267. package/dist/safe-bash-command-pdftotext/index.js +237 -107
  268. package/dist/safe-bash-command-pptx/LICENSE +21 -0
  269. package/dist/safe-bash-command-pptx/index.d.ts +33 -0
  270. package/dist/safe-bash-command-pptx/index.js +168 -0
  271. package/dist/safe-bash-command-qpdf/index.d.ts +9 -3
  272. package/dist/safe-bash-command-qpdf/index.js +254 -130
  273. package/dist/safe-bash-command-sha512sum/index.js +12 -475
  274. package/dist/safe-bash-command-sips/index.d.ts +9 -5
  275. package/dist/safe-bash-command-sips/index.js +65 -46
  276. package/dist/safe-bash-command-soffice/index.d.ts +9 -3
  277. package/dist/safe-bash-command-soffice/index.js +66 -25
  278. package/dist/safe-bash-command-sqlite3/engine.d.ts +9 -0
  279. package/dist/safe-bash-command-sqlite3/index.d.ts +1 -0
  280. package/dist/safe-bash-command-sqlite3/index.js +851 -352
  281. package/dist/safe-bash-command-ssconvert/formats/xls.js +3 -3
  282. package/dist/safe-bash-command-ssconvert/index.js +147 -80
  283. package/dist/safe-bash-command-timeout/index.js +3 -3
  284. package/dist/safe-bash-command-truncate/index.d.ts +8 -3
  285. package/dist/safe-bash-command-truncate/index.js +790 -272
  286. package/dist/safe-bash-command-truncate/sync.d.ts +1 -0
  287. package/dist/safe-bash-command-truncate/sync.js +60 -0
  288. package/dist/safe-bash-command-wkhtmltopdf/index.js +239 -118
  289. package/dist/safe-bash-command-wkhtmltopdf/pdf-renderer.d.ts +1 -1
  290. package/dist/safe-bash-command-xxd/index.js +78 -20
  291. package/dist/safe-bash-command-xz/command.d.ts +4 -0
  292. package/dist/safe-bash-command-xz/index.d.ts +1 -1
  293. package/dist/safe-bash-command-xz/index.js +1 -1
  294. package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
  295. package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
  296. package/dist/safe-bash-compression-engine/files.js +6 -6
  297. package/dist/safe-bash-compression-engine/index.js +5 -5
  298. package/dist/safe-bash-compression-engine/operand.js +6 -6
  299. package/dist/safe-bash-compression-engine/stream.js +5 -5
  300. package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
  301. package/dist/safe-bash-contracts/command.js +3 -3
  302. package/dist/safe-bash-contracts/default-executor.d.ts +5 -0
  303. package/dist/safe-bash-contracts/default-executor.js +37 -0
  304. package/dist/safe-bash-contracts/diagnostics.js +3 -3
  305. package/dist/safe-bash-contracts/escaping.js +9 -9
  306. package/dist/safe-bash-contracts/filesystem-descriptor.js +3 -3
  307. package/dist/safe-bash-contracts/filesystem-output.js +8 -8
  308. package/dist/safe-bash-contracts/http.d.ts +41 -0
  309. package/dist/safe-bash-contracts/http.js +6 -0
  310. package/dist/safe-bash-contracts/index.js +21 -19
  311. package/dist/safe-bash-contracts/io.d.ts +12 -0
  312. package/dist/safe-bash-contracts/io.js +4 -1
  313. package/dist/safe-bash-contracts/output.js +3 -2
  314. package/dist/safe-bash-contracts/runtime-control.js +2 -2
  315. package/dist/safe-bash-contracts/signals.js +1 -1
  316. package/dist/safe-bash-contracts/yield.d.ts +1 -0
  317. package/dist/safe-bash-contracts/yield.js +3 -1
  318. package/dist/safe-bash-csv-engine/index.d.ts +10 -1
  319. package/dist/safe-bash-csv-engine/index.js +78 -6
  320. package/dist/safe-bash-io-engine/commands/search/requirements.js +3 -3
  321. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +3 -3
  322. package/dist/safe-bash-io-engine/gnu-information.d.ts +1 -1
  323. package/dist/safe-bash-io-engine/gnu-information.js +1 -1
  324. package/dist/safe-bash-io-engine/internal.d.ts +1 -1
  325. package/dist/safe-bash-io-engine/internal.js +2 -2
  326. package/dist/safe-bash-query-engine/index.js +5 -5
  327. package/dist/safe-bash-query-engine/interpreter.js +3 -3
  328. package/dist/safe-bash-query-engine/query-core.js +5 -5
  329. package/package.json +2 -2
  330. package/dist/safe-bash/chunks/chunk-2G2T5MEM.js +0 -14
  331. package/dist/safe-bash/chunks/chunk-FJZNUUOQ.js +0 -81
  332. package/dist/safe-bash/chunks/chunk-GJWUEOT6.js +0 -14
  333. package/dist/safe-bash/chunks/chunk-LAPF2XE6.js +0 -14
  334. package/dist/safe-bash/chunks/chunk-O6356Z27.js +0 -37
  335. package/dist/safe-bash/chunks/chunk-S2LSZFZ6.js +0 -758
  336. package/dist/safe-bash/chunks/chunk-T3VDYWKZ.js +0 -21
  337. package/dist/safe-bash/chunks/chunk-VYW4Q6KF.js +0 -12
  338. package/dist/safe-bash/chunks/chunk-WHURJBET.js +0 -409
  339. package/dist/safe-bash/opt-in/commands/cmp/compare.js +0 -95
  340. package/dist/safe-bash/opt-in/commands/cmp/io.js +0 -218
  341. package/dist/safe-bash/command-chunks/{chunk-RTOJNFFL.js → chunk-KNI4GRXF.js} +7 -7
  342. package/dist/safe-bash/command-chunks/{chunk-DEH3CMGL.js → chunk-QJ3ONEBI.js} +3 -3
@@ -1,690 +1,3 @@
1
- import { FsError, getCommandArguments, isFsError } from "../contracts/index.js";
2
- import { yieldTurn } from "../contracts/yield.js";
3
- import { assertCommandRequirements } from "../contracts/command-requirements.js";
4
- import { PublicDiagnostic, publicDiagnosticMessage } from "../diagnostics.js";
5
- import { ByteInputBudget } from "./bytes/input-budget.js";
6
- import { bufferLimit, output, pathOf, UsageError } from "./internal.js";
7
- import { inputRequirements } from "./portable-requirements.js";
8
- import { compareCopyIdentity, compareObservedEntries } from "./copy-identity.js";
9
- const blockBytes = 4096;
10
- const maxCount = 18446744073709551616n;
11
- function byteCount(text, option = "bytes") {
12
- const invalid = () => { throw new UsageError(`invalid --${option} value '${text}'`); };
13
- let position = 0;
14
- while (text[position] === " " || text.charCodeAt(position) >= 9 && text.charCodeAt(position) <= 13)
15
- position++;
16
- if (text[position] === "+")
17
- position++;
18
- let base = 10;
19
- if (text[position] === "0") {
20
- base = 8;
21
- if (text[position + 1]?.toLowerCase() === "x") {
22
- base = 16;
23
- position += 2;
24
- }
25
- }
26
- const start = position;
27
- let count = 0n;
28
- const maximum = option === "bytes" ? 18446744073709551615n : 9223372036854775807n;
29
- while (position < text.length) {
30
- const digit = "0123456789abcdef".indexOf(text[position].toLowerCase());
31
- if (digit < 0 || digit >= base)
32
- break;
33
- count = count * BigInt(base) + BigInt(digit);
34
- if (count > maximum)
35
- invalid();
36
- position++;
37
- }
38
- const suffix = text.slice(position);
39
- if (position === start) {
40
- if (position !== 0 || !"kKMGTPEZY".includes(suffix[0] ?? " "))
41
- invalid();
42
- count = 1n;
43
- }
44
- if (suffix) {
45
- const power = "KMGTPEZY".indexOf(suffix[0] === "k" ? "K" : suffix[0]) + 1;
46
- if (!power || !["", "B", "D", "iB"].includes(suffix.slice(1)))
47
- invalid();
48
- count *= (suffix.endsWith("B") && !suffix.endsWith("iB") || suffix.endsWith("D") ? 1000n : 1024n) ** BigInt(power);
49
- }
50
- if (count > maximum)
51
- invalid();
52
- return count;
53
- }
54
- function parse(context) {
55
- const parsed = { names: [], skips: [0n, 0n], limit: maxCount, silent: false, verbose: false, printBytes: false };
56
- const long = { "print-bytes": "b", "print-chars": "c", "ignore-initial": "i", verbose: "l", bytes: "n", silent: "s", quiet: "s", version: "v", help: "help" };
57
- const operands = [];
58
- const argumentsWithBytes = getCommandArguments(context);
59
- const args = context.args.map((_argument, index) => {
60
- const bytes = argumentsWithBytes.bytes(index);
61
- return Array.from(bytes, byte => String.fromCharCode(byte)).join("");
62
- });
63
- let ended = false;
64
- const apply = (key, argument) => {
65
- if (key === "s" || key === "l") {
66
- if (key === "s" ? parsed.verbose : parsed.silent)
67
- throw new UsageError("options -l and -s are incompatible");
68
- if (key === "s")
69
- parsed.silent = true;
70
- else
71
- parsed.verbose = true;
72
- }
73
- else if (key === "b" || key === "c")
74
- parsed.printBytes = true;
75
- else if (key === "n") {
76
- const next = byteCount(argument);
77
- if (next < parsed.limit)
78
- parsed.limit = next;
79
- }
80
- else if (key === "i") {
81
- const delimiter = argument.indexOf(":");
82
- const first = delimiter < 0 ? argument : argument.slice(0, delimiter);
83
- let firstSkip;
84
- try {
85
- firstSkip = byteCount(first, "ignore-initial");
86
- }
87
- catch {
88
- throw new UsageError(`invalid --ignore-initial value '${argument}'`);
89
- }
90
- if (firstSkip > parsed.skips[0])
91
- parsed.skips[0] = firstSkip;
92
- const secondSkip = delimiter < 0 ? firstSkip : byteCount(argument.slice(delimiter + 1), "ignore-initial");
93
- if (secondSkip > parsed.skips[1])
94
- parsed.skips[1] = secondSkip;
95
- }
96
- else
97
- parsed.information = key === "v" ? "version" : "help";
98
- };
99
- for (let index = 0; index < args.length; index++) {
100
- const argument = args[index];
101
- if (ended || argument === "-" || !argument.startsWith("-")) {
102
- operands.push(argument);
103
- if (Object.hasOwn(context.env, "POSIXLY_CORRECT"))
104
- ended = true;
105
- }
106
- else if (argument === "--")
107
- ended = true;
108
- else if (argument.startsWith("--")) {
109
- const equals = argument.indexOf("=");
110
- const name = argument.slice(2, equals < 0 ? undefined : equals);
111
- const matches = Object.keys(long).filter(candidate => candidate.startsWith(name));
112
- const selected = Object.hasOwn(long, name) ? name : matches[0];
113
- if (!Object.hasOwn(long, name) && matches.length > 1 && new Set(matches.map(match => long[match])).size > 1) {
114
- throw new UsageError(`option '${argument}' is ambiguous; possibilities: ${matches.map(match => `'--${match}'`).join(" ")}`);
115
- }
116
- if (!selected)
117
- throw new UsageError(`unrecognized option '${argument}'`);
118
- const key = long[selected];
119
- let value;
120
- if (key === "i" || key === "n") {
121
- value = equals < 0 ? args[++index] : argument.slice(equals + 1);
122
- if (value === undefined)
123
- throw new UsageError(`option '--${selected}' requires an argument`);
124
- }
125
- else if (equals >= 0)
126
- throw new UsageError(`option '--${selected}' doesn't allow an argument`);
127
- apply(key, value);
128
- }
129
- else {
130
- for (let offset = 1; offset < argument.length; offset++) {
131
- const key = argument[offset];
132
- if (!"bcilnsv".includes(key))
133
- throw new UsageError(`invalid option -- '${key}'`);
134
- let value;
135
- if (key === "i" || key === "n") {
136
- value = argument.slice(offset + 1) || args[++index];
137
- if (value === undefined)
138
- throw new UsageError(`option requires an argument -- '${key}'`);
139
- offset = argument.length;
140
- }
141
- apply(key, value);
142
- if (parsed.information)
143
- return parsed;
144
- }
145
- }
146
- if (parsed.information)
147
- return parsed;
148
- }
149
- if (!operands.length)
150
- throw new UsageError(`missing operand after '${args.at(-1) ?? "cmp"}'`);
151
- parsed.names = [operands[0], operands[1] ?? "-"];
152
- for (const index of [0, 1]) {
153
- if (operands[index + 2] !== undefined) {
154
- const next = byteCount(operands[index + 2], "ignore-initial");
155
- if (next > parsed.skips[index])
156
- parsed.skips[index] = next;
157
- }
158
- }
159
- if (operands.length > 4)
160
- throw new UsageError(`extra operand '${operands[4]}'`);
161
- return parsed;
162
- }
163
- class InputError extends PublicDiagnostic {
164
- suppressInSilent;
165
- constructor(message, suppressInSilent) {
166
- super(message);
167
- this.suppressInSilent = suppressInSilent;
168
- }
169
- }
170
- function inputError(error, name, opening = false) {
171
- if (!(error instanceof FsError))
172
- return error;
173
- const messages = {
174
- EACCES: "Permission denied", EBADF: "Bad file descriptor", EIO: "Input/output error", EISDIR: "Is a directory",
175
- ELOOP: "Too many levels of symbolic links", ENAMETOOLONG: "File name too long", ENOENT: "No such file or directory",
176
- ENOTDIR: "Not a directory", ENOTSUP: "Operation not supported", EPERM: "Operation not permitted",
177
- };
178
- const detail = messages[error.code];
179
- return detail ? new InputError(`${name}: ${detail}`, opening) : error;
180
- }
181
- function printByte(byte) {
182
- const prefix = byte >= 128 ? "M-" : "";
183
- const character = byte & 127;
184
- return prefix + (character < 32 ? `^${String.fromCharCode(character + 64)}` : character === 127 ? "^?" : String.fromCharCode(character));
185
- }
186
- async function discardsOutput(context) {
187
- if (!context.stdoutFile)
188
- return false;
189
- const options = { signal: context.signal };
190
- try {
191
- const paths = [context.stdoutFile.path, "/dev/null"];
192
- for (const path of paths) {
193
- const capabilities = await context.fs.capabilitiesFor?.(path, options) ?? context.fs.capabilities;
194
- context.signal.throwIfAborted();
195
- if (capabilities.stat === false)
196
- return false;
197
- }
198
- const target = await context.fs.stat(paths[0], options);
199
- const empty = await context.fs.stat(paths[1], options);
200
- return await compareObservedEntries(context.fs, paths[0], target, context.fs, paths[1], empty, options) === "same";
201
- }
202
- catch (error) {
203
- context.signal.throwIfAborted();
204
- if (error instanceof FsError)
205
- return false;
206
- throw error;
207
- }
208
- }
209
- class Cursor {
210
- name;
211
- context;
212
- budget;
213
- signal;
214
- chargeChunk;
215
- bytes = new Uint8Array();
216
- offset = 0;
217
- size = Infinity;
218
- stat;
219
- position = 0n;
220
- skip = 0;
221
- requestBytes = blockBytes;
222
- reader;
223
- iterator;
224
- source;
225
- finished = false;
226
- retirement;
227
- handle;
228
- acquisition;
229
- handleClosing;
230
- operations = new Set();
231
- constructor(name, context, budget, signal, chargeChunk) {
232
- this.name = name;
233
- this.context = context;
234
- this.budget = budget;
235
- this.signal = signal;
236
- this.chargeChunk = chargeChunk;
237
- }
238
- async open(limit, skip) {
239
- this.signal.throwIfAborted();
240
- const numericSkip = skip > BigInt(Number.MAX_SAFE_INTEGER) ? Number.MAX_SAFE_INTEGER : Number(skip);
241
- this.skip = numericSkip;
242
- if (this.name === "-") {
243
- const input = this.context.stdinInput;
244
- this.stat = input?.stat;
245
- this.position = BigInt(input?.position ?? 0);
246
- if (this.stat?.type === "file" && Number.isSafeInteger(this.stat.size) && this.stat.size >= 0) {
247
- const remaining = BigInt(this.stat.size) - this.position - skip;
248
- this.size = remaining > 0n ? Number(remaining) : 0;
249
- }
250
- this.source = input ? () => ({ [Symbol.asyncIterator]: () => ({ next: () => input.read(this.requestBytes, this.signal) }) }) : () => this.context.stdin;
251
- }
252
- else {
253
- let name;
254
- try {
255
- name = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Uint8Array.from(this.name, unit => unit.charCodeAt(0)));
256
- }
257
- catch {
258
- throw new FsError("ENOENT");
259
- }
260
- const path = pathOf(this.context, name);
261
- const capabilities = await this.context.fs.capabilitiesFor?.(path, { signal: this.signal }) ?? this.context.fs.capabilities;
262
- this.signal.throwIfAborted();
263
- assertCommandRequirements({ ...this.context, signal: this.signal }, inputRequirements, ["file"], capabilities);
264
- let stat;
265
- if (capabilities.stat !== false) {
266
- try {
267
- stat = await this.context.fs.stat(path, { signal: this.signal });
268
- }
269
- catch (error) {
270
- this.signal.throwIfAborted();
271
- if (!isFsError(error, "ENOTSUP"))
272
- throw error;
273
- }
274
- }
275
- this.signal.throwIfAborted();
276
- if (stat?.type !== "directory" && capabilities.retainedRead === true && this.context.fs.openReadFile) {
277
- this.acquisition = this.context.fs.openReadFile(path, { signal: this.signal }).then(handle => { this.handle = handle; return handle; });
278
- try {
279
- const handle = await this.acquisition;
280
- this.signal.throwIfAborted();
281
- stat = await this.work(() => handle.stat({ signal: this.signal }));
282
- }
283
- catch (error) {
284
- this.signal.throwIfAborted();
285
- if (this.handle || !isFsError(error, "ENOTSUP"))
286
- throw error;
287
- }
288
- }
289
- if (!this.handle && capabilities.access !== false) {
290
- try {
291
- await this.context.fs.access(path, 4, { signal: this.signal });
292
- }
293
- catch (error) {
294
- this.signal.throwIfAborted();
295
- if (!isFsError(error, "ENOTSUP"))
296
- throw error;
297
- }
298
- }
299
- this.signal.throwIfAborted();
300
- if (!stat && limit === 0)
301
- throw new FsError("ENOTSUP", { path, message: "zero-byte comparison requires metadata admission" });
302
- this.stat = stat;
303
- this.position = skip;
304
- if (stat?.type === "file" && Number.isSafeInteger(stat.size) && stat.size >= 0) {
305
- const remaining = BigInt(stat.size) - skip;
306
- this.size = remaining > 0n ? Number(remaining) : 0;
307
- }
308
- if (limit === 0 && (this.handle || Number.isFinite(this.size) || this.skip === 0)) {
309
- this.skip = 0;
310
- return;
311
- }
312
- if (this.handle) {
313
- const handle = this.handle;
314
- let position = Number.isFinite(this.size) ? Math.min(numericSkip, stat.size) : numericSkip;
315
- this.skip = 0;
316
- this.source = () => ({ [Symbol.asyncIterator]: () => ({ next: async () => {
317
- const bytes = await this.work(() => handle.read(position, this.requestBytes, { signal: this.signal }));
318
- if (!(bytes instanceof Uint8Array) || bytes.length > this.requestBytes)
319
- throw new FsError("EIO", { path, message: "invalid retained read size" });
320
- position += bytes.length;
321
- return bytes.length ? { done: false, value: bytes } : { done: true, value: undefined };
322
- } }) });
323
- }
324
- else if (this.context.fs.readStream && capabilities.streamingRead !== false) {
325
- const start = Number.isFinite(this.size) ? Math.min(numericSkip, stat.size) : 0;
326
- if (Number.isFinite(this.size))
327
- this.skip = 0;
328
- this.source = () => this.context.fs.readStream(path, { signal: this.signal, chunkSize: Math.min(blockBytes, limit || this.skip),
329
- ...(start ? { start } : {}),
330
- ...(limit === Infinity || this.skip ? {} : { endExclusive: Math.min(Number.MAX_SAFE_INTEGER, start + limit) }) });
331
- }
332
- else {
333
- if (capabilities.read === false)
334
- throw new FsError("ENOTSUP", { syscall: "readFile", path });
335
- const context = this.context;
336
- const signal = this.signal;
337
- this.source = () => ({ async *[Symbol.asyncIterator]() {
338
- yield await context.fs.readFile(path, { signal });
339
- } });
340
- }
341
- }
342
- }
343
- async prepare() {
344
- const input = this.name === "-" ? this.context.stdinInput : undefined;
345
- if (input?.seek) {
346
- this.signal.throwIfAborted();
347
- const targetPosition = Math.min(Number.MAX_SAFE_INTEGER, input.position + this.skip);
348
- this.position = BigInt(input.position) + BigInt(this.skip);
349
- if (this.skip) {
350
- try {
351
- await input.seek(targetPosition, this.signal);
352
- }
353
- catch (error) {
354
- throw inputError(error, this.name);
355
- }
356
- }
357
- this.signal.throwIfAborted();
358
- this.skip = 0;
359
- if (this.stat?.type === "file") {
360
- const remaining = BigInt(this.stat.size) - this.position;
361
- this.size = remaining > 0n ? Number(remaining) : 0;
362
- }
363
- }
364
- }
365
- async fill(remaining) {
366
- this.signal.throwIfAborted();
367
- if (remaining === 0 && this.skip === 0)
368
- return false;
369
- if (!this.reader) {
370
- try {
371
- this.iterator = this.source()[Symbol.asyncIterator]();
372
- }
373
- catch (error) {
374
- throw inputError(error, this.name);
375
- }
376
- this.reader = this.budget.read({ [Symbol.asyncIterator]: () => ({
377
- next: async () => {
378
- let result;
379
- try {
380
- result = await this.iterator.next();
381
- }
382
- catch (error) {
383
- throw inputError(error, this.name);
384
- }
385
- if (result.done)
386
- this.finished = true;
387
- return result;
388
- },
389
- return: async () => { await this.retire(); return { done: true, value: undefined }; },
390
- }) }, this.signal)[Symbol.asyncIterator]();
391
- }
392
- while (this.offset === this.bytes.length) {
393
- this.signal.throwIfAborted();
394
- if (remaining === 0 && this.skip === 0)
395
- return false;
396
- this.requestBytes = Math.min(blockBytes, this.skip || remaining);
397
- const item = await this.reader.next();
398
- if (item.done)
399
- return false;
400
- await this.chargeChunk();
401
- this.bytes = new Uint8Array(item.value);
402
- this.offset = Math.min(this.skip, this.bytes.length);
403
- this.skip -= this.offset;
404
- }
405
- return true;
406
- }
407
- retire() {
408
- this.retirement ??= Promise.resolve().then(async () => {
409
- try {
410
- if (!this.finished)
411
- await this.iterator?.return?.();
412
- }
413
- catch (error) {
414
- throw inputError(error, this.name);
415
- }
416
- });
417
- return this.retirement;
418
- }
419
- work(operation) {
420
- this.signal.throwIfAborted();
421
- if (this.handleClosing)
422
- throw new FsError("EBADF", { path: this.name });
423
- const pending = Promise.resolve().then(() => {
424
- this.signal.throwIfAborted();
425
- return operation();
426
- });
427
- this.operations.add(pending);
428
- void pending.then(() => { this.operations.delete(pending); }, () => { this.operations.delete(pending); });
429
- return pending;
430
- }
431
- async close() {
432
- this.handleClosing ??= Promise.resolve().then(async () => {
433
- await this.acquisition?.catch(() => undefined);
434
- await Promise.allSettled(this.operations);
435
- try {
436
- await this.handle?.close();
437
- }
438
- catch (error) {
439
- throw inputError(error, this.name);
440
- }
441
- });
442
- const results = await Promise.allSettled([this.retire(), this.reader?.return?.(), this.handleClosing]);
443
- this.bytes = new Uint8Array();
444
- for (const result of results)
445
- if (result.status === "rejected")
446
- throw result.reason;
447
- }
448
- }
449
- async function compare(context, parsed) {
450
- const { names, skips, silent, verbose, printBytes } = parsed;
451
- const limit = parsed.limit >= maxCount ? Infinity : parsed.limit > BigInt(Number.MAX_SAFE_INTEGER) ? Number.MAX_SAFE_INTEGER : Number(parsed.limit);
452
- const controller = new AbortController();
453
- const signal = AbortSignal.any([context.signal, controller.signal]);
454
- const budget = new ByteInputBudget(bufferLimit);
455
- let chunks = 0;
456
- const chargeChunk = async () => {
457
- if (++chunks % 64 === 0)
458
- await yieldTurn(signal);
459
- };
460
- const cursors = names.map(name => new Cursor(name, context, budget, signal, chargeChunk));
461
- let closing;
462
- const cleanupErrors = [];
463
- const close = () => {
464
- if (!closing) {
465
- controller.abort(new FsError("EPIPE", { message: "cmp input closed" }));
466
- closing = Promise.allSettled(cursors.map(cursor => cursor.close())).then(results => {
467
- for (const result of results)
468
- if (result.status === "rejected")
469
- cleanupErrors.push(result.reason);
470
- });
471
- }
472
- return closing;
473
- };
474
- context.registerCleanup?.(close);
475
- let duplicateStdinClose = false;
476
- const run = async () => {
477
- assertCommandRequirements({ ...context, signal }, inputRequirements, [names.some(name => name !== "-") ? "file" : "stdin"]);
478
- const sharedStdin = names.every(name => name === "-");
479
- if (sharedStdin && (skips[0] === skips[1] || !context.stdinInput?.seek && context.stdinInput?.stat?.type !== "file"))
480
- return 0;
481
- for (const index of [0, 1]) {
482
- const cursor = cursors[index];
483
- try {
484
- await cursor.open(limit, skips[index]);
485
- }
486
- catch (error) {
487
- throw inputError(error, cursor.name, true);
488
- }
489
- if (index === 0 && names[0] === names[1] && skips[0] === skips[1] && cursor.stat)
490
- return 0;
491
- }
492
- const [left, right] = cursors;
493
- for (const cursor of cursors)
494
- await cursor.prepare();
495
- if (!sharedStdin && left.position === right.position && compareCopyIdentity(left.stat, right.stat) === "same")
496
- return 0;
497
- if (silent && Number.isFinite(left.size) && Number.isFinite(right.size) && left.size !== right.size && Math.min(left.size, right.size) < limit)
498
- return 1;
499
- for (const cursor of cursors)
500
- if (cursor.stat?.type === "directory")
501
- throw inputError(new FsError("EISDIR"), cursor.name);
502
- const noStdout = !silent && await discardsOutput(context);
503
- const known = Math.min(left.size, right.size, limit);
504
- const width = Number.isFinite(known) ? String(known).length : 19;
505
- duplicateStdinClose = sharedStdin;
506
- let compared = 0;
507
- let newlines = 0;
508
- let lastByte = -1;
509
- let different = false;
510
- let report = "";
511
- const flush = async () => {
512
- if (report) {
513
- await output(context, report);
514
- report = "";
515
- }
516
- };
517
- for (const cursor of cursors)
518
- await cursor.fill(0);
519
- while (compared < limit) {
520
- const hasLeft = await left.fill(limit - compared);
521
- const hasRight = await right.fill(limit - compared);
522
- if (!hasLeft || !hasRight) {
523
- await flush();
524
- if (hasLeft === hasRight)
525
- return different ? 1 : 0;
526
- if (!silent) {
527
- const shorter = hasLeft ? right.name : left.name;
528
- const detail = compared === 0 ? "which is empty" : `after byte ${compared}${verbose || noStdout ? "" : `, ${lastByte === 10 ? "" : "in "}line ${newlines + (lastByte === 10 ? 0 : 1)}`}`;
529
- await output({ ...context, stdout: context.stderr }, Uint8Array.from(`cmp: EOF on ${shorter} ${detail}\n`, unit => unit.charCodeAt(0)));
530
- }
531
- return 1;
532
- }
533
- const count = Math.min(left.bytes.length - left.offset, right.bytes.length - right.offset, limit - compared, blockBytes - compared % blockBytes);
534
- for (let index = 0; index < count; index++) {
535
- const leftByte = left.bytes[left.offset++];
536
- const rightByte = right.bytes[right.offset++];
537
- compared++;
538
- if (leftByte !== rightByte) {
539
- different = true;
540
- if (silent || noStdout)
541
- return 1;
542
- if (!verbose) {
543
- const locale = context.env.LC_ALL || context.env.LC_MESSAGES || context.env.LANG;
544
- const unit = !printBytes && (!locale || locale === "C" || locale === "POSIX") ? "char" : "byte";
545
- const detail = printBytes ? ` is ${leftByte.toString(8).padStart(3)} ${printByte(leftByte)} ${rightByte.toString(8).padStart(3)} ${printByte(rightByte)}` : "";
546
- await output(context, Uint8Array.from(`${left.name} ${right.name} differ: ${unit} ${compared}, line ${newlines + 1}${detail}\n`, character => character.charCodeAt(0)));
547
- return 1;
548
- }
549
- report += `${String(compared).padStart(width)} ${leftByte.toString(8).padStart(3)} ${printBytes ? `${printByte(leftByte).padEnd(4)} ` : ""}${rightByte.toString(8).padStart(3)}${printBytes ? ` ${printByte(rightByte)}` : ""}\n`;
550
- if (report.length >= 16384)
551
- await flush();
552
- }
553
- if (leftByte === 10)
554
- newlines++;
555
- lastByte = leftByte;
556
- }
557
- if (compared % blockBytes === 0)
558
- await yieldTurn(signal);
559
- }
560
- await flush();
561
- return different ? 1 : 0;
562
- };
563
- let result;
564
- try {
565
- result = await run();
566
- }
567
- catch (error) {
568
- await close();
569
- throw error;
570
- }
571
- await close();
572
- if (cleanupErrors.length)
573
- throw cleanupErrors[0];
574
- if (duplicateStdinClose)
575
- throw inputError(new FsError("EBADF"), "-");
576
- return result;
577
- }
578
- export function cmpCommand() {
579
- return { name: "cmp", filesystemRequirements: inputRequirements, async execute(context) {
580
- context.signal.throwIfAborted();
581
- let silent = false;
582
- try {
583
- const parsed = parse(context);
584
- if (parsed.information) {
585
- await output(context, parsed.information === "version" ? "cmp (virtual-bash)\n" : "Usage: cmp [OPTION]... FILE1 [FILE2 [SKIP1 [SKIP2]]]\nCompare bytes in the virtual filesystem; omitted FILE2 or '-' reads stdin.\n -s, --silent, --quiet report status only\n -l, --verbose list differing bytes in octal\n -b, -c, --print-bytes also display byte characters\n -i, --ignore-initial=SKIP[:SKIP2] skip initial bytes\n -n, --bytes=LIMIT compare at most LIMIT bytes\n --help, -v, --version show virtual-bash command information\n");
586
- return { exitCode: 0 };
587
- }
588
- silent = parsed.silent;
589
- return { exitCode: await compare(context, parsed) };
590
- }
591
- catch (error) {
592
- context.signal.throwIfAborted();
593
- if (!silent || !(error instanceof InputError) || !error.suppressInSilent) {
594
- const message = publicDiagnosticMessage(error, context.onInternalError);
595
- const diagnostic = `cmp: ${message}\n${error instanceof UsageError ? "cmp: Try 'cmp --help' for more information.\n" : ""}`;
596
- await output({ ...context, stdout: context.stderr }, error instanceof UsageError || error instanceof InputError ? Uint8Array.from(diagnostic, unit => unit.charCodeAt(0)) : diagnostic);
597
- }
598
- return { exitCode: 2 };
599
- }
600
- } };
601
- }
602
- export function evalSyncCmp(inBytes, opArgs, readFileSync) {
603
- try {
604
- const operands = [];
605
- const skips = [0n, 0n];
606
- let count = 9223372036854775807n;
607
- let stopped = false;
608
- const setSkip = (idx, text) => {
609
- const p = byteCount(text, "ignore-initial");
610
- if (p > skips[idx])
611
- skips[idx] = p;
612
- };
613
- for (let i = 0; i < opArgs.length; i++) {
614
- const a = opArgs[i];
615
- if (stopped || a === "-" || !a.startsWith("-")) {
616
- operands.push(a);
617
- continue;
618
- }
619
- if (a === "--") {
620
- stopped = true;
621
- continue;
622
- }
623
- if (a === "-s" || a === "--silent" || a === "--quiet" || a === "-b" || a === "-c" || a === "--print-bytes" || a === "-l" || a === "--verbose")
624
- continue;
625
- if (a === "-i" || a === "--ignore-initial" || a.startsWith("-i") || a.startsWith("--ignore-initial=")) {
626
- const v = (a === "-i" || a === "--ignore-initial") ? opArgs[++i] : (a.startsWith("--ignore-initial=") ? a.slice(17) : a.slice(2));
627
- if (v === undefined || v === "")
628
- return undefined;
629
- const d = v.indexOf(":");
630
- if (d < 0) {
631
- setSkip(0, v);
632
- if (skips[0] > skips[1])
633
- skips[1] = skips[0];
634
- }
635
- else {
636
- setSkip(0, v.slice(0, d));
637
- setSkip(1, v.slice(d + 1));
638
- }
639
- continue;
640
- }
641
- if (a === "-n" || a === "--bytes" || a.startsWith("-n") || a.startsWith("--bytes=")) {
642
- const v = (a === "-n" || a === "--bytes") ? opArgs[++i] : (a.startsWith("--bytes=") ? a.slice(8) : a.slice(2));
643
- if (v === undefined || v === "")
644
- return undefined;
645
- const p = byteCount(v, "bytes");
646
- if (p < count)
647
- count = p;
648
- continue;
649
- }
650
- return undefined;
651
- }
652
- if (operands.length < 1 || operands.length > 4)
653
- return undefined;
654
- if (operands[2] !== undefined)
655
- setSkip(0, operands[2]);
656
- if (operands[3] !== undefined)
657
- setSkip(1, operands[3]);
658
- const f0 = operands[0];
659
- const f1 = operands[1] ?? "-";
660
- if (f0 === "-" && f1 === "-") {
661
- if (skips[0] === skips[1])
662
- return "";
663
- return undefined;
664
- }
665
- const b0 = f0 === "-" ? inBytes : readFileSync?.(f0);
666
- const b1 = f1 === "-" ? inBytes : readFileSync?.(f1);
667
- if (!b0 || !b1 || b0.byteLength > 16384 || b1.byteLength > 16384)
668
- return undefined;
669
- if (skips[0] > BigInt(b0.byteLength) || skips[1] > BigInt(b1.byteLength))
670
- return undefined;
671
- const s0 = Number(skips[0]);
672
- const s1 = Number(skips[1]);
673
- const rem0 = b0.byteLength - s0;
674
- const rem1 = b1.byteLength - s1;
675
- const limit = count < BigInt(Math.max(rem0, rem1)) ? Number(count) : Math.max(rem0, rem1);
676
- const len0 = Math.min(rem0, limit);
677
- const len1 = Math.min(rem1, limit);
678
- if (len0 !== len1)
679
- return undefined;
680
- for (let i = 0; i < len0; i++) {
681
- if (b0[s0 + i] !== b1[s1 + i])
682
- return undefined;
683
- }
684
- return "";
685
- }
686
- catch {
687
- return undefined;
688
- }
689
- }
1
+ export * from "../../safe-bash-command-cmp/index.js";
2
+ export { createCmpCommand, createCmpCommands, cmpCommands, cmpCommand, evalSyncCmp } from "../../safe-bash-command-cmp/index.js";
690
3
  //# sourceMappingURL=cmp.js.map