@feiyoug/skill-lab 0.0.0 → 0.0.2

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 (465) hide show
  1. package/README.md +73 -0
  2. package/esm/analyzer/astgrep/client.d.ts +20 -8
  3. package/esm/analyzer/astgrep/client.d.ts.map +1 -1
  4. package/esm/analyzer/astgrep/client.js +58 -31
  5. package/esm/analyzer/config/default.d.ts +8 -0
  6. package/esm/analyzer/config/default.d.ts.map +1 -0
  7. package/esm/analyzer/config/default.js +91 -0
  8. package/esm/analyzer/config/helpers.d.ts +8 -0
  9. package/esm/analyzer/config/helpers.d.ts.map +1 -0
  10. package/esm/analyzer/config/helpers.js +72 -0
  11. package/esm/analyzer/config/mod.d.ts +4 -0
  12. package/esm/analyzer/config/mod.d.ts.map +1 -0
  13. package/esm/analyzer/config/mod.js +3 -0
  14. package/esm/analyzer/config/types.d.ts +58 -0
  15. package/esm/analyzer/config/types.d.ts.map +1 -0
  16. package/esm/analyzer/{config.js → config/types.js} +0 -28
  17. package/esm/analyzer/logging.d.ts +3 -0
  18. package/esm/analyzer/logging.d.ts.map +1 -0
  19. package/esm/analyzer/logging.js +6 -0
  20. package/esm/analyzer/mod.d.ts +12 -5
  21. package/esm/analyzer/mod.d.ts.map +1 -1
  22. package/esm/analyzer/mod.js +25 -12
  23. package/esm/analyzer/result.d.ts +35 -0
  24. package/esm/analyzer/result.d.ts.map +1 -0
  25. package/esm/analyzer/result.js +311 -0
  26. package/esm/analyzer/rules/bash/commands/mod.d.ts +1 -0
  27. package/esm/analyzer/rules/bash/commands/mod.d.ts.map +1 -1
  28. package/esm/analyzer/rules/bash/commands/mod.js +3 -0
  29. package/esm/analyzer/rules/bash/commands/pip.d.ts +3 -0
  30. package/esm/analyzer/rules/bash/commands/pip.d.ts.map +1 -0
  31. package/esm/analyzer/rules/bash/commands/pip.js +14 -0
  32. package/esm/analyzer/rules/bash/extractFileRefs.d.ts +1 -1
  33. package/esm/analyzer/rules/bash/extractFileRefs.d.ts.map +1 -1
  34. package/esm/analyzer/rules/bash/extractFileRefs.js +2 -2
  35. package/esm/analyzer/rules/bash/inline-command-classifier.d.ts +1 -1
  36. package/esm/analyzer/rules/bash/inline-command-classifier.d.ts.map +1 -1
  37. package/esm/analyzer/rules/bash/inline-command-classifier.js +4 -4
  38. package/esm/analyzer/rules/javascript/extractFileRefs.d.ts +3 -4
  39. package/esm/analyzer/rules/javascript/extractFileRefs.d.ts.map +1 -1
  40. package/esm/analyzer/rules/javascript/extractFileRefs.js +3 -4
  41. package/esm/analyzer/rules/markdown/extractCodeBlocks.d.ts.map +1 -1
  42. package/esm/analyzer/rules/markdown/extractCodeBlocks.js +6 -3
  43. package/esm/analyzer/rules/markdown/extractFileRefs.d.ts.map +1 -1
  44. package/esm/analyzer/rules/markdown/extractFileRefs.js +2 -0
  45. package/esm/analyzer/rules/python/extractFileRefs.d.ts +1 -1
  46. package/esm/analyzer/rules/python/extractFileRefs.d.ts.map +1 -1
  47. package/esm/analyzer/rules/python/extractFileRefs.js +2 -2
  48. package/esm/analyzer/steps/001-discovery/discover-files.d.ts +4 -0
  49. package/esm/analyzer/steps/001-discovery/discover-files.d.ts.map +1 -1
  50. package/esm/analyzer/steps/001-discovery/discover-files.js +18 -2
  51. package/esm/analyzer/steps/001-discovery/mod.d.ts.map +1 -1
  52. package/esm/analyzer/steps/001-discovery/mod.js +39 -9
  53. package/esm/analyzer/steps/002-permissions/mod.d.ts.map +1 -1
  54. package/esm/analyzer/steps/002-permissions/mod.js +156 -73
  55. package/esm/analyzer/steps/002-permissions/scan-file.d.ts +1 -1
  56. package/esm/analyzer/steps/002-permissions/scan-file.d.ts.map +1 -1
  57. package/esm/analyzer/steps/002-permissions/scan-file.js +40 -5
  58. package/esm/analyzer/steps/002-permissions/seed-frontmatter.js +2 -2
  59. package/esm/analyzer/steps/003-risks/dep-risks.d.ts +3 -0
  60. package/esm/analyzer/steps/003-risks/dep-risks.d.ts.map +1 -0
  61. package/esm/analyzer/steps/003-risks/dep-risks.js +74 -0
  62. package/esm/analyzer/steps/003-risks/helpers.d.ts +1 -0
  63. package/esm/analyzer/steps/003-risks/helpers.d.ts.map +1 -1
  64. package/esm/analyzer/steps/003-risks/helpers.js +1 -0
  65. package/esm/analyzer/steps/003-risks/mod.d.ts +3 -2
  66. package/esm/analyzer/steps/003-risks/mod.d.ts.map +1 -1
  67. package/esm/analyzer/steps/003-risks/mod.js +41 -4
  68. package/esm/analyzer/steps/003-risks/policy.d.ts +7 -0
  69. package/esm/analyzer/steps/003-risks/policy.d.ts.map +1 -0
  70. package/esm/analyzer/steps/003-risks/policy.js +23 -0
  71. package/esm/analyzer/steps/003-risks/rule-mapped.d.ts +2 -2
  72. package/esm/analyzer/steps/003-risks/rule-mapped.d.ts.map +1 -1
  73. package/esm/analyzer/steps/003-risks/rule-mapped.js +83 -2
  74. package/esm/analyzer/steps/003-risks/scoring.d.ts +9 -1
  75. package/esm/analyzer/steps/003-risks/scoring.d.ts.map +1 -1
  76. package/esm/analyzer/steps/003-risks/scoring.js +55 -42
  77. package/esm/analyzer/treesitter/client.d.ts +31 -0
  78. package/esm/analyzer/treesitter/client.d.ts.map +1 -0
  79. package/esm/analyzer/{treesiter → treesitter}/client.js +43 -39
  80. package/esm/analyzer/treesitter/registry.d.ts +73 -0
  81. package/esm/analyzer/treesitter/registry.d.ts.map +1 -0
  82. package/esm/analyzer/treesitter/registry.js +165 -0
  83. package/esm/analyzer/types.d.ts +14 -28
  84. package/esm/analyzer/types.d.ts.map +1 -1
  85. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/deps.d.ts +3 -0
  86. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/deps.d.ts.map +1 -0
  87. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/deps.js +3 -0
  88. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/mod.d.ts +93 -0
  89. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/mod.d.ts.map +1 -0
  90. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/mod.js +297 -0
  91. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/multi.d.ts +84 -0
  92. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/multi.d.ts.map +1 -0
  93. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/multi.js +268 -0
  94. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/time.d.ts +18 -0
  95. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/time.d.ts.map +1 -0
  96. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/time.js +45 -0
  97. package/esm/deps/jsr.io/@std/fmt/1.0.3/colors.d.ts +700 -0
  98. package/esm/deps/jsr.io/@std/fmt/1.0.3/colors.d.ts.map +1 -0
  99. package/esm/deps/jsr.io/@std/fmt/1.0.3/colors.js +903 -0
  100. package/esm/deps/jsr.io/@std/io/0.225.0/types.d.ts +146 -0
  101. package/esm/deps/jsr.io/@std/io/0.225.0/types.d.ts.map +1 -0
  102. package/esm/deps/jsr.io/@std/io/0.225.0/types.js +15 -0
  103. package/esm/deps/jsr.io/@std/io/0.225.0/write_all.d.ts +51 -0
  104. package/esm/deps/jsr.io/@std/io/0.225.0/write_all.d.ts.map +1 -0
  105. package/esm/deps/jsr.io/@std/io/0.225.0/write_all.js +61 -0
  106. package/esm/shared/deep_merge.d.ts +12 -0
  107. package/esm/shared/deep_merge.d.ts.map +1 -0
  108. package/esm/shared/deep_merge.js +49 -0
  109. package/esm/shared/mod.d.ts +1 -0
  110. package/esm/shared/mod.d.ts.map +1 -1
  111. package/esm/shared/mod.js +1 -0
  112. package/esm/shared/types/filetypes.d.ts +2 -2
  113. package/esm/shared/types/filetypes.d.ts.map +1 -1
  114. package/esm/shared/types/permissions.d.ts +1 -1
  115. package/esm/shared/types/permissions.d.ts.map +1 -1
  116. package/esm/shared/types/risks.d.ts +4 -1
  117. package/esm/shared/types/risks.d.ts.map +1 -1
  118. package/esm/skillreader/types.d.ts +2 -2
  119. package/esm/skillreader/types.d.ts.map +1 -1
  120. package/esm/skillreader/types.js +2 -2
  121. package/package.json +1 -1
  122. package/script/analyzer/astgrep/client.d.ts +20 -8
  123. package/script/analyzer/astgrep/client.d.ts.map +1 -1
  124. package/script/analyzer/astgrep/client.js +58 -64
  125. package/script/analyzer/config/default.d.ts +8 -0
  126. package/script/analyzer/config/default.d.ts.map +1 -0
  127. package/script/analyzer/config/default.js +94 -0
  128. package/script/analyzer/config/helpers.d.ts +8 -0
  129. package/script/analyzer/config/helpers.d.ts.map +1 -0
  130. package/script/analyzer/config/helpers.js +76 -0
  131. package/script/analyzer/config/mod.d.ts +4 -0
  132. package/script/analyzer/config/mod.d.ts.map +1 -0
  133. package/script/analyzer/config/mod.js +21 -0
  134. package/script/analyzer/config/types.d.ts +58 -0
  135. package/script/analyzer/config/types.d.ts.map +1 -0
  136. package/script/analyzer/{config.js → config/types.js} +1 -29
  137. package/script/analyzer/logging.d.ts +3 -0
  138. package/script/analyzer/logging.d.ts.map +1 -0
  139. package/script/analyzer/logging.js +9 -0
  140. package/script/analyzer/mod.d.ts +12 -5
  141. package/script/analyzer/mod.d.ts.map +1 -1
  142. package/script/analyzer/mod.js +35 -20
  143. package/script/analyzer/result.d.ts +35 -0
  144. package/script/analyzer/result.d.ts.map +1 -0
  145. package/script/analyzer/result.js +315 -0
  146. package/script/analyzer/rules/bash/commands/mod.d.ts +1 -0
  147. package/script/analyzer/rules/bash/commands/mod.d.ts.map +1 -1
  148. package/script/analyzer/rules/bash/commands/mod.js +3 -0
  149. package/script/analyzer/rules/bash/commands/pip.d.ts +3 -0
  150. package/script/analyzer/rules/bash/commands/pip.d.ts.map +1 -0
  151. package/script/analyzer/rules/bash/commands/pip.js +17 -0
  152. package/script/analyzer/rules/bash/extractFileRefs.d.ts +1 -1
  153. package/script/analyzer/rules/bash/extractFileRefs.d.ts.map +1 -1
  154. package/script/analyzer/rules/bash/extractFileRefs.js +2 -2
  155. package/script/analyzer/rules/bash/inline-command-classifier.d.ts +1 -1
  156. package/script/analyzer/rules/bash/inline-command-classifier.d.ts.map +1 -1
  157. package/script/analyzer/rules/bash/inline-command-classifier.js +4 -4
  158. package/script/analyzer/rules/javascript/extractFileRefs.d.ts +3 -4
  159. package/script/analyzer/rules/javascript/extractFileRefs.d.ts.map +1 -1
  160. package/script/analyzer/rules/javascript/extractFileRefs.js +3 -4
  161. package/script/analyzer/rules/markdown/extractCodeBlocks.d.ts.map +1 -1
  162. package/script/analyzer/rules/markdown/extractCodeBlocks.js +6 -3
  163. package/script/analyzer/rules/markdown/extractFileRefs.d.ts.map +1 -1
  164. package/script/analyzer/rules/markdown/extractFileRefs.js +2 -0
  165. package/script/analyzer/rules/python/extractFileRefs.d.ts +1 -1
  166. package/script/analyzer/rules/python/extractFileRefs.d.ts.map +1 -1
  167. package/script/analyzer/rules/python/extractFileRefs.js +2 -2
  168. package/script/analyzer/steps/001-discovery/discover-files.d.ts +4 -0
  169. package/script/analyzer/steps/001-discovery/discover-files.d.ts.map +1 -1
  170. package/script/analyzer/steps/001-discovery/discover-files.js +18 -2
  171. package/script/analyzer/steps/001-discovery/mod.d.ts.map +1 -1
  172. package/script/analyzer/steps/001-discovery/mod.js +77 -11
  173. package/script/analyzer/steps/002-permissions/mod.d.ts.map +1 -1
  174. package/script/analyzer/steps/002-permissions/mod.js +194 -75
  175. package/script/analyzer/steps/002-permissions/scan-file.d.ts +1 -1
  176. package/script/analyzer/steps/002-permissions/scan-file.d.ts.map +1 -1
  177. package/script/analyzer/steps/002-permissions/scan-file.js +40 -5
  178. package/script/analyzer/steps/002-permissions/seed-frontmatter.js +3 -3
  179. package/script/analyzer/steps/003-risks/dep-risks.d.ts +3 -0
  180. package/script/analyzer/steps/003-risks/dep-risks.d.ts.map +1 -0
  181. package/script/analyzer/steps/003-risks/dep-risks.js +77 -0
  182. package/script/analyzer/steps/003-risks/helpers.d.ts +1 -0
  183. package/script/analyzer/steps/003-risks/helpers.d.ts.map +1 -1
  184. package/script/analyzer/steps/003-risks/helpers.js +1 -0
  185. package/script/analyzer/steps/003-risks/mod.d.ts +3 -2
  186. package/script/analyzer/steps/003-risks/mod.d.ts.map +1 -1
  187. package/script/analyzer/steps/003-risks/mod.js +77 -4
  188. package/script/analyzer/steps/003-risks/policy.d.ts +7 -0
  189. package/script/analyzer/steps/003-risks/policy.d.ts.map +1 -0
  190. package/script/analyzer/steps/003-risks/policy.js +29 -0
  191. package/script/analyzer/steps/003-risks/rule-mapped.d.ts +2 -2
  192. package/script/analyzer/steps/003-risks/rule-mapped.d.ts.map +1 -1
  193. package/script/analyzer/steps/003-risks/rule-mapped.js +83 -2
  194. package/script/analyzer/steps/003-risks/scoring.d.ts +9 -1
  195. package/script/analyzer/steps/003-risks/scoring.d.ts.map +1 -1
  196. package/script/analyzer/steps/003-risks/scoring.js +55 -42
  197. package/script/analyzer/treesitter/client.d.ts +31 -0
  198. package/script/analyzer/treesitter/client.d.ts.map +1 -0
  199. package/script/analyzer/treesitter/client.js +136 -0
  200. package/script/analyzer/treesitter/registry.d.ts +73 -0
  201. package/script/analyzer/treesitter/registry.d.ts.map +1 -0
  202. package/script/analyzer/treesitter/registry.js +206 -0
  203. package/script/analyzer/types.d.ts +14 -28
  204. package/script/analyzer/types.d.ts.map +1 -1
  205. package/script/deps/jsr.io/@deno-library/progress/1.5.1/deps.d.ts +3 -0
  206. package/script/deps/jsr.io/@deno-library/progress/1.5.1/deps.d.ts.map +1 -0
  207. package/script/deps/jsr.io/@deno-library/progress/1.5.1/deps.js +10 -0
  208. package/script/deps/jsr.io/@deno-library/progress/1.5.1/mod.d.ts +93 -0
  209. package/script/deps/jsr.io/@deno-library/progress/1.5.1/mod.d.ts.map +1 -0
  210. package/script/deps/jsr.io/@deno-library/progress/1.5.1/mod.js +334 -0
  211. package/script/deps/jsr.io/@deno-library/progress/1.5.1/multi.d.ts +84 -0
  212. package/script/deps/jsr.io/@deno-library/progress/1.5.1/multi.d.ts.map +1 -0
  213. package/script/deps/jsr.io/@deno-library/progress/1.5.1/multi.js +305 -0
  214. package/script/deps/jsr.io/@deno-library/progress/1.5.1/time.d.ts +18 -0
  215. package/script/deps/jsr.io/@deno-library/progress/1.5.1/time.d.ts.map +1 -0
  216. package/script/deps/jsr.io/@deno-library/progress/1.5.1/time.js +48 -0
  217. package/script/deps/jsr.io/@std/fmt/1.0.3/colors.d.ts +700 -0
  218. package/script/deps/jsr.io/@std/fmt/1.0.3/colors.d.ts.map +1 -0
  219. package/script/deps/jsr.io/@std/fmt/1.0.3/colors.js +986 -0
  220. package/script/deps/jsr.io/@std/io/0.225.0/types.d.ts +146 -0
  221. package/script/deps/jsr.io/@std/io/0.225.0/types.d.ts.map +1 -0
  222. package/script/deps/jsr.io/@std/io/0.225.0/types.js +18 -0
  223. package/script/deps/jsr.io/@std/io/0.225.0/write_all.d.ts +51 -0
  224. package/script/deps/jsr.io/@std/io/0.225.0/write_all.d.ts.map +1 -0
  225. package/script/deps/jsr.io/@std/io/0.225.0/write_all.js +65 -0
  226. package/script/shared/deep_merge.d.ts +12 -0
  227. package/script/shared/deep_merge.d.ts.map +1 -0
  228. package/script/shared/deep_merge.js +53 -0
  229. package/script/shared/mod.d.ts +1 -0
  230. package/script/shared/mod.d.ts.map +1 -1
  231. package/script/shared/mod.js +1 -0
  232. package/script/shared/types/filetypes.d.ts +2 -2
  233. package/script/shared/types/filetypes.d.ts.map +1 -1
  234. package/script/shared/types/permissions.d.ts +1 -1
  235. package/script/shared/types/permissions.d.ts.map +1 -1
  236. package/script/shared/types/risks.d.ts +4 -1
  237. package/script/shared/types/risks.d.ts.map +1 -1
  238. package/script/skillreader/types.d.ts +2 -2
  239. package/script/skillreader/types.d.ts.map +1 -1
  240. package/script/skillreader/types.js +2 -2
  241. package/src/_dnt.polyfills.ts +27 -0
  242. package/src/_dnt.shims.ts +64 -0
  243. package/src/analyzer/astgrep/client.ts +184 -0
  244. package/src/analyzer/astgrep/mod.ts +2 -0
  245. package/src/analyzer/config/default.ts +98 -0
  246. package/src/analyzer/config/helpers.ts +107 -0
  247. package/src/analyzer/config/mod.ts +3 -0
  248. package/src/analyzer/config/types.ts +103 -0
  249. package/src/analyzer/logging.ts +8 -0
  250. package/src/analyzer/mod.ts +118 -0
  251. package/src/analyzer/result.ts +393 -0
  252. package/src/analyzer/rules/bash/astTypes.ts +5 -0
  253. package/src/analyzer/rules/bash/commands/bd.ts +23 -0
  254. package/src/analyzer/rules/bash/commands/cron.ts +21 -0
  255. package/src/analyzer/rules/bash/commands/docker.ts +37 -0
  256. package/src/analyzer/rules/bash/commands/eval.ts +52 -0
  257. package/src/analyzer/rules/bash/commands/generic.ts +16 -0
  258. package/src/analyzer/rules/bash/commands/gh.ts +21 -0
  259. package/src/analyzer/rules/bash/commands/git.ts +28 -0
  260. package/src/analyzer/rules/bash/commands/mod.ts +38 -0
  261. package/src/analyzer/rules/bash/commands/node.ts +64 -0
  262. package/src/analyzer/rules/bash/commands/openspec.ts +16 -0
  263. package/src/analyzer/rules/bash/commands/pip.ts +16 -0
  264. package/src/analyzer/rules/bash/commands/sudo.ts +21 -0
  265. package/src/analyzer/rules/bash/destructive.ts +28 -0
  266. package/src/analyzer/rules/bash/extractFileRefs.ts +101 -0
  267. package/src/analyzer/rules/bash/filesystem.ts +50 -0
  268. package/src/analyzer/rules/bash/injection.ts +21 -0
  269. package/src/analyzer/rules/bash/inline-command-classifier.ts +94 -0
  270. package/src/analyzer/rules/bash/mod.ts +23 -0
  271. package/src/analyzer/rules/bash/network.ts +64 -0
  272. package/src/analyzer/rules/bash/secret-detection.ts +43 -0
  273. package/src/analyzer/rules/javascript/astTypes.ts +8 -0
  274. package/src/analyzer/rules/javascript/extractFileRefs.ts +131 -0
  275. package/src/analyzer/rules/javascript/filesystem.ts +28 -0
  276. package/src/analyzer/rules/javascript/injection.ts +21 -0
  277. package/src/analyzer/rules/javascript/mod.ts +26 -0
  278. package/src/analyzer/rules/javascript/network.ts +27 -0
  279. package/src/analyzer/rules/javascript/secret-detection.ts +68 -0
  280. package/src/analyzer/rules/javascript/subprocess.ts +16 -0
  281. package/src/analyzer/rules/markdown/astTypes.ts +35 -0
  282. package/src/analyzer/rules/markdown/extractCodeBlocks.ts +101 -0
  283. package/src/analyzer/rules/markdown/extractFileRefs.ts +179 -0
  284. package/src/analyzer/rules/markdown/mod.ts +12 -0
  285. package/src/analyzer/rules/mod.ts +77 -0
  286. package/src/analyzer/rules/python/astTypes.ts +9 -0
  287. package/src/analyzer/rules/python/extractFileRefs.ts +92 -0
  288. package/src/analyzer/rules/python/mod.ts +15 -0
  289. package/src/analyzer/rules/python/network.ts +26 -0
  290. package/src/analyzer/rules/python/secret-detection.ts +30 -0
  291. package/src/analyzer/rules/shared/file-refs.ts +38 -0
  292. package/src/analyzer/rules/shared/network-evaluators.ts +107 -0
  293. package/src/analyzer/rules/shared/prompt-injection.ts +48 -0
  294. package/src/analyzer/rules/shared/secret-evaluators.ts +13 -0
  295. package/src/analyzer/rules/text/mod.ts +12 -0
  296. package/src/analyzer/rules/typescript/mod.ts +7 -0
  297. package/src/analyzer/steps/001-discovery/discover-files.ts +211 -0
  298. package/src/analyzer/steps/001-discovery/filter-files.ts +72 -0
  299. package/src/analyzer/steps/001-discovery/mod.ts +103 -0
  300. package/src/analyzer/steps/002-permissions/mod.ts +329 -0
  301. package/src/analyzer/steps/002-permissions/scan-file.ts +258 -0
  302. package/src/analyzer/steps/002-permissions/seed-frontmatter.ts +66 -0
  303. package/src/analyzer/steps/002-permissions/synthesize.ts +42 -0
  304. package/src/analyzer/steps/003-risks/dep-risks.ts +89 -0
  305. package/src/analyzer/steps/003-risks/helpers.ts +41 -0
  306. package/src/analyzer/steps/003-risks/mod.ts +86 -0
  307. package/src/analyzer/steps/003-risks/policy.ts +38 -0
  308. package/src/analyzer/steps/003-risks/rule-mapped.ts +206 -0
  309. package/src/analyzer/steps/003-risks/scoring.ts +117 -0
  310. package/src/analyzer/steps/mod.ts +3 -0
  311. package/src/analyzer/treesitter/client.ts +120 -0
  312. package/src/analyzer/treesitter/registry.ts +198 -0
  313. package/src/analyzer/types.ts +78 -0
  314. package/src/analyzer/utils/code-block-path.ts +33 -0
  315. package/src/analyzer/utils/id-generator.ts +59 -0
  316. package/src/analyzer/utils/secret-validator.ts +29 -0
  317. package/src/analyzer/utils/url-parser.ts +25 -0
  318. package/src/deps/jsr.io/@deno-library/progress/1.5.1/deps.ts +3 -0
  319. package/src/deps/jsr.io/@deno-library/progress/1.5.1/mod.ts +265 -0
  320. package/src/deps/jsr.io/@deno-library/progress/1.5.1/multi.ts +250 -0
  321. package/src/deps/jsr.io/@deno-library/progress/1.5.1/time.ts +69 -0
  322. package/src/deps/jsr.io/@std/fmt/1.0.3/colors.ts +1004 -0
  323. package/src/deps/jsr.io/@std/internal/1.0.12/_os.ts +15 -0
  324. package/src/deps/jsr.io/@std/internal/1.0.12/os.ts +7 -0
  325. package/src/deps/jsr.io/@std/io/0.225.0/types.ts +157 -0
  326. package/src/deps/jsr.io/@std/io/0.225.0/write_all.ts +65 -0
  327. package/src/deps/jsr.io/@std/path/1.1.4/_common/assert_path.ts +10 -0
  328. package/src/deps/jsr.io/@std/path/1.1.4/_common/basename.ts +53 -0
  329. package/src/deps/jsr.io/@std/path/1.1.4/_common/common.ts +26 -0
  330. package/src/deps/jsr.io/@std/path/1.1.4/_common/constants.ts +49 -0
  331. package/src/deps/jsr.io/@std/path/1.1.4/_common/dirname.ts +9 -0
  332. package/src/deps/jsr.io/@std/path/1.1.4/_common/format.ts +25 -0
  333. package/src/deps/jsr.io/@std/path/1.1.4/_common/from_file_url.ts +12 -0
  334. package/src/deps/jsr.io/@std/path/1.1.4/_common/glob_to_reg_exp.ts +295 -0
  335. package/src/deps/jsr.io/@std/path/1.1.4/_common/normalize.ts +9 -0
  336. package/src/deps/jsr.io/@std/path/1.1.4/_common/normalize_string.ts +74 -0
  337. package/src/deps/jsr.io/@std/path/1.1.4/_common/relative.ts +10 -0
  338. package/src/deps/jsr.io/@std/path/1.1.4/_common/strip_trailing_separators.ts +25 -0
  339. package/src/deps/jsr.io/@std/path/1.1.4/_common/to_file_url.ts +17 -0
  340. package/src/deps/jsr.io/@std/path/1.1.4/basename.ts +37 -0
  341. package/src/deps/jsr.io/@std/path/1.1.4/common.ts +35 -0
  342. package/src/deps/jsr.io/@std/path/1.1.4/constants.ts +18 -0
  343. package/src/deps/jsr.io/@std/path/1.1.4/dirname.ts +30 -0
  344. package/src/deps/jsr.io/@std/path/1.1.4/extname.ts +29 -0
  345. package/src/deps/jsr.io/@std/path/1.1.4/format.ts +30 -0
  346. package/src/deps/jsr.io/@std/path/1.1.4/from_file_url.ts +30 -0
  347. package/src/deps/jsr.io/@std/path/1.1.4/glob_to_regexp.ts +94 -0
  348. package/src/deps/jsr.io/@std/path/1.1.4/is_absolute.ts +30 -0
  349. package/src/deps/jsr.io/@std/path/1.1.4/is_glob.ts +49 -0
  350. package/src/deps/jsr.io/@std/path/1.1.4/join.ts +31 -0
  351. package/src/deps/jsr.io/@std/path/1.1.4/join_globs.ts +42 -0
  352. package/src/deps/jsr.io/@std/path/1.1.4/mod.ts +217 -0
  353. package/src/deps/jsr.io/@std/path/1.1.4/normalize.ts +33 -0
  354. package/src/deps/jsr.io/@std/path/1.1.4/normalize_glob.ts +45 -0
  355. package/src/deps/jsr.io/@std/path/1.1.4/parse.ts +44 -0
  356. package/src/deps/jsr.io/@std/path/1.1.4/posix/_util.ts +10 -0
  357. package/src/deps/jsr.io/@std/path/1.1.4/posix/basename.ts +62 -0
  358. package/src/deps/jsr.io/@std/path/1.1.4/posix/constants.ts +15 -0
  359. package/src/deps/jsr.io/@std/path/1.1.4/posix/dirname.ts +72 -0
  360. package/src/deps/jsr.io/@std/path/1.1.4/posix/extname.ts +96 -0
  361. package/src/deps/jsr.io/@std/path/1.1.4/posix/format.ts +31 -0
  362. package/src/deps/jsr.io/@std/path/1.1.4/posix/from_file_url.ts +25 -0
  363. package/src/deps/jsr.io/@std/path/1.1.4/posix/glob_to_regexp.ts +94 -0
  364. package/src/deps/jsr.io/@std/path/1.1.4/posix/is_absolute.ts +25 -0
  365. package/src/deps/jsr.io/@std/path/1.1.4/posix/join.ts +46 -0
  366. package/src/deps/jsr.io/@std/path/1.1.4/posix/join_globs.ts +45 -0
  367. package/src/deps/jsr.io/@std/path/1.1.4/posix/normalize.ts +63 -0
  368. package/src/deps/jsr.io/@std/path/1.1.4/posix/normalize_glob.ts +43 -0
  369. package/src/deps/jsr.io/@std/path/1.1.4/posix/parse.ts +121 -0
  370. package/src/deps/jsr.io/@std/path/1.1.4/posix/relative.ts +103 -0
  371. package/src/deps/jsr.io/@std/path/1.1.4/posix/resolve.ts +71 -0
  372. package/src/deps/jsr.io/@std/path/1.1.4/posix/to_file_url.ts +32 -0
  373. package/src/deps/jsr.io/@std/path/1.1.4/posix/to_namespaced_path.ts +21 -0
  374. package/src/deps/jsr.io/@std/path/1.1.4/relative.ts +32 -0
  375. package/src/deps/jsr.io/@std/path/1.1.4/resolve.ts +32 -0
  376. package/src/deps/jsr.io/@std/path/1.1.4/to_file_url.ts +30 -0
  377. package/src/deps/jsr.io/@std/path/1.1.4/to_namespaced_path.ts +31 -0
  378. package/src/deps/jsr.io/@std/path/1.1.4/types.ts +40 -0
  379. package/src/deps/jsr.io/@std/path/1.1.4/windows/_util.ts +28 -0
  380. package/src/deps/jsr.io/@std/path/1.1.4/windows/basename.ts +54 -0
  381. package/src/deps/jsr.io/@std/path/1.1.4/windows/constants.ts +15 -0
  382. package/src/deps/jsr.io/@std/path/1.1.4/windows/dirname.ts +118 -0
  383. package/src/deps/jsr.io/@std/path/1.1.4/windows/extname.ts +90 -0
  384. package/src/deps/jsr.io/@std/path/1.1.4/windows/format.ts +31 -0
  385. package/src/deps/jsr.io/@std/path/1.1.4/windows/from_file_url.ts +34 -0
  386. package/src/deps/jsr.io/@std/path/1.1.4/windows/glob_to_regexp.ts +92 -0
  387. package/src/deps/jsr.io/@std/path/1.1.4/windows/is_absolute.ts +40 -0
  388. package/src/deps/jsr.io/@std/path/1.1.4/windows/join.ts +78 -0
  389. package/src/deps/jsr.io/@std/path/1.1.4/windows/join_globs.ts +46 -0
  390. package/src/deps/jsr.io/@std/path/1.1.4/windows/normalize.ts +136 -0
  391. package/src/deps/jsr.io/@std/path/1.1.4/windows/normalize_glob.ts +43 -0
  392. package/src/deps/jsr.io/@std/path/1.1.4/windows/parse.ts +184 -0
  393. package/src/deps/jsr.io/@std/path/1.1.4/windows/relative.ts +128 -0
  394. package/src/deps/jsr.io/@std/path/1.1.4/windows/resolve.ts +178 -0
  395. package/src/deps/jsr.io/@std/path/1.1.4/windows/to_file_url.ts +38 -0
  396. package/src/deps/jsr.io/@std/path/1.1.4/windows/to_namespaced_path.ts +60 -0
  397. package/src/deps/jsr.io/@std/yaml/1.0.11/_chars.ts +55 -0
  398. package/src/deps/jsr.io/@std/yaml/1.0.11/_dumper_state.ts +841 -0
  399. package/src/deps/jsr.io/@std/yaml/1.0.11/_loader_state.ts +1780 -0
  400. package/src/deps/jsr.io/@std/yaml/1.0.11/_schema.ts +183 -0
  401. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/binary.ts +127 -0
  402. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/bool.ts +37 -0
  403. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/float.ts +112 -0
  404. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/int.ts +174 -0
  405. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/map.ts +17 -0
  406. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/merge.ts +13 -0
  407. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/nil.ts +27 -0
  408. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/omap.ts +30 -0
  409. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/pairs.ts +22 -0
  410. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/regexp.ts +33 -0
  411. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/seq.ts +13 -0
  412. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/set.ts +17 -0
  413. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/str.ts +12 -0
  414. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/timestamp.ts +101 -0
  415. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/undefined.ts +23 -0
  416. package/src/deps/jsr.io/@std/yaml/1.0.11/_type.ts +49 -0
  417. package/src/deps/jsr.io/@std/yaml/1.0.11/_utils.ts +16 -0
  418. package/src/deps/jsr.io/@std/yaml/1.0.11/mod.ts +54 -0
  419. package/src/deps/jsr.io/@std/yaml/1.0.11/parse.ts +128 -0
  420. package/src/deps/jsr.io/@std/yaml/1.0.11/stringify.ts +118 -0
  421. package/src/shared/deep_merge.ts +73 -0
  422. package/src/shared/mod.ts +2 -0
  423. package/src/shared/types/filetypes.ts +101 -0
  424. package/src/shared/types/findings.ts +7 -0
  425. package/src/shared/types/mod.ts +6 -0
  426. package/src/shared/types/permissions.ts +17 -0
  427. package/src/shared/types/references.ts +62 -0
  428. package/src/shared/types/risks.ts +72 -0
  429. package/src/shared/types/syntaxNode.ts +7 -0
  430. package/src/skillreader/cloudStorage/mod.ts +170 -0
  431. package/src/skillreader/factory.ts +71 -0
  432. package/src/skillreader/fs/git.ts +153 -0
  433. package/src/skillreader/fs/mod.ts +84 -0
  434. package/src/skillreader/github/base.ts +162 -0
  435. package/src/skillreader/github/githubApi.ts +40 -0
  436. package/src/skillreader/github/githubRaw.ts +24 -0
  437. package/src/skillreader/github/mod.ts +45 -0
  438. package/src/skillreader/github/utils.ts +40 -0
  439. package/src/skillreader/manifest.ts +67 -0
  440. package/src/skillreader/mod.ts +26 -0
  441. package/src/skillreader/types.ts +150 -0
  442. package/src/skillreader/utils/frontmatter-parser.ts +72 -0
  443. package/src/skillreader/utils/http-range.ts +38 -0
  444. package/src/skillreader/utils/mod.ts +12 -0
  445. package/esm/analyzer/astgrep/registry.d.ts +0 -18
  446. package/esm/analyzer/astgrep/registry.d.ts.map +0 -1
  447. package/esm/analyzer/astgrep/registry.js +0 -71
  448. package/esm/analyzer/config.d.ts +0 -27
  449. package/esm/analyzer/config.d.ts.map +0 -1
  450. package/esm/analyzer/steps/003-risks/output.d.ts +0 -3
  451. package/esm/analyzer/steps/003-risks/output.d.ts.map +0 -1
  452. package/esm/analyzer/steps/003-risks/output.js +0 -16
  453. package/esm/analyzer/treesiter/client.d.ts +0 -26
  454. package/esm/analyzer/treesiter/client.d.ts.map +0 -1
  455. package/script/analyzer/astgrep/registry.d.ts +0 -18
  456. package/script/analyzer/astgrep/registry.d.ts.map +0 -1
  457. package/script/analyzer/astgrep/registry.js +0 -109
  458. package/script/analyzer/config.d.ts +0 -27
  459. package/script/analyzer/config.d.ts.map +0 -1
  460. package/script/analyzer/steps/003-risks/output.d.ts +0 -3
  461. package/script/analyzer/steps/003-risks/output.d.ts.map +0 -1
  462. package/script/analyzer/steps/003-risks/output.js +0 -19
  463. package/script/analyzer/treesiter/client.d.ts +0 -26
  464. package/script/analyzer/treesiter/client.d.ts.map +0 -1
  465. package/script/analyzer/treesiter/client.js +0 -165
@@ -0,0 +1,841 @@
1
+ // Ported from js-yaml v3.13.1:
2
+ // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da
3
+ // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
4
+ // Copyright 2018-2026 the Deno authors. MIT license.
5
+
6
+ import {
7
+ AMPERSAND,
8
+ ASTERISK,
9
+ BOM,
10
+ COLON,
11
+ COMMA,
12
+ COMMERCIAL_AT,
13
+ DOUBLE_QUOTE,
14
+ EXCLAMATION,
15
+ GRAVE_ACCENT,
16
+ GREATER_THAN,
17
+ isWhiteSpace,
18
+ LEFT_CURLY_BRACKET,
19
+ LEFT_SQUARE_BRACKET,
20
+ LINE_FEED,
21
+ MINUS,
22
+ PERCENT,
23
+ QUESTION,
24
+ RIGHT_CURLY_BRACKET,
25
+ RIGHT_SQUARE_BRACKET,
26
+ SHARP,
27
+ SINGLE_QUOTE,
28
+ VERTICAL_LINE,
29
+ } from "./_chars.js";
30
+ import { DEFAULT_SCHEMA, type Schema } from "./_schema.js";
31
+ import type { KindType, StyleVariant, Type } from "./_type.js";
32
+ import { isObject } from "./_utils.js";
33
+
34
+ const STYLE_PLAIN = 1;
35
+ const STYLE_SINGLE = 2;
36
+ const STYLE_LITERAL = 3;
37
+ const STYLE_FOLDED = 4;
38
+ const STYLE_DOUBLE = 5;
39
+
40
+ const LEADING_SPACE_REGEXP = /^\n* /;
41
+
42
+ const ESCAPE_SEQUENCES = new Map<number, string>([
43
+ [0x00, "\\0"],
44
+ [0x07, "\\a"],
45
+ [0x08, "\\b"],
46
+ [0x09, "\\t"],
47
+ [0x0a, "\\n"],
48
+ [0x0b, "\\v"],
49
+ [0x0c, "\\f"],
50
+ [0x0d, "\\r"],
51
+ [0x1b, "\\e"],
52
+ [0x22, '\\"'],
53
+ [0x5c, "\\\\"],
54
+ [0x85, "\\N"],
55
+ [0xa0, "\\_"],
56
+ [0x2028, "\\L"],
57
+ [0x2029, "\\P"],
58
+ ]);
59
+
60
+ const DEPRECATED_BOOLEANS_SYNTAX = new Set([
61
+ "y",
62
+ "Y",
63
+ "yes",
64
+ "Yes",
65
+ "YES",
66
+ "on",
67
+ "On",
68
+ "ON",
69
+ "n",
70
+ "N",
71
+ "no",
72
+ "No",
73
+ "NO",
74
+ "off",
75
+ "Off",
76
+ "OFF",
77
+ ]);
78
+
79
+ /**
80
+ * Encodes a Unicode character code point as a hexadecimal escape sequence.
81
+ */
82
+ function charCodeToHexString(charCode: number): string {
83
+ const hexString = charCode.toString(16).toUpperCase();
84
+ if (charCode <= 0xff) return `\\x${hexString.padStart(2, "0")}`;
85
+ if (charCode <= 0xffff) return `\\u${hexString.padStart(4, "0")}`;
86
+ if (charCode <= 0xffffffff) return `\\U${hexString.padStart(8, "0")}`;
87
+ throw new Error(
88
+ "Code point within a string may not be greater than 0xFFFFFFFF",
89
+ );
90
+ }
91
+
92
+ function createStyleMap(
93
+ map: Record<string, StyleVariant>,
94
+ ): Map<string, StyleVariant> {
95
+ const result = new Map();
96
+ for (let tag of Object.keys(map)) {
97
+ const style = String(map[tag]) as StyleVariant;
98
+ if (tag.slice(0, 2) === "!!") {
99
+ tag = `tag:yaml.org,2002:${tag.slice(2)}`;
100
+ }
101
+ result.set(tag, style);
102
+ }
103
+ return result;
104
+ }
105
+
106
+ // Indents every line in a string. Empty lines (\n only) are not indented.
107
+ function indentString(string: string, spaces: number): string {
108
+ const indent = " ".repeat(spaces);
109
+ return string
110
+ .split("\n")
111
+ .map((line) => line.length ? indent + line : line)
112
+ .join("\n");
113
+ }
114
+
115
+ function generateNextLine(indent: number, level: number): string {
116
+ return `\n${" ".repeat(indent * level)}`;
117
+ }
118
+
119
+ /**
120
+ * @link https://yaml.org/spec/1.2.2/ 5.1. Character Set
121
+ * @return `true` if the character is printable without escaping, `false` otherwise.
122
+ */
123
+ function isPrintable(c: number): boolean {
124
+ return (
125
+ (0x00020 <= c && c <= 0x00007e) ||
126
+ (0x000a1 <= c && c <= 0x00d7ff && c !== 0x2028 && c !== 0x2029) ||
127
+ (0x0e000 <= c && c <= 0x00fffd && c !== BOM) ||
128
+ (0x10000 <= c && c <= 0x10ffff)
129
+ );
130
+ }
131
+
132
+ /**
133
+ * @return `true` if value is allowed after the first character in plain style, `false` otherwise.
134
+ */
135
+ function isPlainSafe(c: number): boolean {
136
+ return (
137
+ isPrintable(c) &&
138
+ c !== BOM &&
139
+ c !== COMMA &&
140
+ c !== LEFT_SQUARE_BRACKET &&
141
+ c !== RIGHT_SQUARE_BRACKET &&
142
+ c !== LEFT_CURLY_BRACKET &&
143
+ c !== RIGHT_CURLY_BRACKET &&
144
+ c !== COLON &&
145
+ c !== SHARP
146
+ );
147
+ }
148
+
149
+ /**
150
+ * @return `true` if value is allowed as the first character in plain style, `false` otherwise.
151
+ */
152
+ function isPlainSafeFirst(c: number): boolean {
153
+ return (
154
+ isPlainSafe(c) &&
155
+ !isWhiteSpace(c) &&
156
+ c !== MINUS &&
157
+ c !== QUESTION &&
158
+ c !== AMPERSAND &&
159
+ c !== ASTERISK &&
160
+ c !== EXCLAMATION &&
161
+ c !== VERTICAL_LINE &&
162
+ c !== GREATER_THAN &&
163
+ c !== SINGLE_QUOTE &&
164
+ c !== DOUBLE_QUOTE &&
165
+ c !== PERCENT &&
166
+ c !== COMMERCIAL_AT &&
167
+ c !== GRAVE_ACCENT
168
+ );
169
+ }
170
+
171
+ // Determines whether block indentation indicator is required.
172
+ function needIndentIndicator(string: string): boolean {
173
+ return LEADING_SPACE_REGEXP.test(string);
174
+ }
175
+
176
+ // Determines which scalar styles are possible and returns the preferred style.
177
+ // lineWidth = -1 => no limit.
178
+ // Pre-conditions: str.length > 0.
179
+ // Post-conditions:
180
+ // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
181
+ // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
182
+ // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth !== -1).
183
+ function chooseScalarStyle(
184
+ string: string,
185
+ singleLineOnly: boolean,
186
+ indentPerLevel: number,
187
+ lineWidth: number,
188
+ implicitTypes: Type<"scalar", unknown>[],
189
+ quoteStyle: "'" | '"',
190
+ ): number {
191
+ const shouldTrackWidth = lineWidth !== -1;
192
+ let hasLineBreak = false;
193
+ let hasFoldableLine = false; // only checked if shouldTrackWidth
194
+ let previousLineBreak = -1; // count the first line correctly
195
+ let plain = isPlainSafeFirst(string.charCodeAt(0)) &&
196
+ !isWhiteSpace(string.charCodeAt(string.length - 1));
197
+
198
+ let char: number;
199
+ let i: number;
200
+ if (singleLineOnly) {
201
+ // Case: no block styles.
202
+ // Check for disallowed characters to rule out plain and single.
203
+ for (i = 0; i < string.length; i++) {
204
+ char = string.charCodeAt(i);
205
+ if (!isPrintable(char)) {
206
+ return STYLE_DOUBLE;
207
+ }
208
+ plain = plain && isPlainSafe(char);
209
+ }
210
+ } else {
211
+ // Case: block styles permitted.
212
+ for (i = 0; i < string.length; i++) {
213
+ char = string.charCodeAt(i);
214
+ if (char === LINE_FEED) {
215
+ hasLineBreak = true;
216
+ // Check if any line can be folded.
217
+ if (shouldTrackWidth) {
218
+ hasFoldableLine = hasFoldableLine ||
219
+ // Foldable line = too long, and not more-indented.
220
+ (i - previousLineBreak - 1 > lineWidth &&
221
+ string[previousLineBreak + 1] !== " ");
222
+ previousLineBreak = i;
223
+ }
224
+ } else if (!isPrintable(char)) {
225
+ return STYLE_DOUBLE;
226
+ }
227
+ plain = plain && isPlainSafe(char);
228
+ }
229
+ // in case the end is missing a \n
230
+ hasFoldableLine = hasFoldableLine ||
231
+ (shouldTrackWidth &&
232
+ i - previousLineBreak - 1 > lineWidth &&
233
+ string[previousLineBreak + 1] !== " ");
234
+ }
235
+ // Although every style can represent \n without escaping, prefer block styles
236
+ // for multiline, since they're more readable and they don't add empty lines.
237
+ // Also prefer folding a super-long line.
238
+ if (!hasLineBreak && !hasFoldableLine) {
239
+ // Strings interpretable as another type have to be quoted;
240
+ // e.g. the string 'true' vs. the boolean true.
241
+ return plain && !implicitTypes.some((type) => type.resolve(string))
242
+ ? STYLE_PLAIN
243
+ : quoteStyle === "'"
244
+ ? STYLE_SINGLE
245
+ : STYLE_DOUBLE;
246
+ }
247
+ // Edge case: block indentation indicator can only have one digit.
248
+ if (indentPerLevel > 9 && needIndentIndicator(string)) {
249
+ return STYLE_DOUBLE;
250
+ }
251
+ // At this point we know block styles are valid.
252
+ // Prefer literal style unless we want to fold.
253
+ return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
254
+ }
255
+
256
+ // Greedy line breaking.
257
+ // Picks the longest line under the limit each time,
258
+ // otherwise settles for the shortest line over the limit.
259
+ // NB. More-indented lines *cannot* be folded, as that would add an extra \n.
260
+ function foldLine(line: string, width: number): string {
261
+ if (line === "" || line[0] === " ") return line;
262
+
263
+ // Since a more-indented line adds a \n, breaks can't be followed by a space.
264
+ const breakRegExp = / [^ ]/g; // note: the match index will always be <= length-2.
265
+ // start is an inclusive index. end, curr, and next are exclusive.
266
+ let start = 0;
267
+ let end;
268
+ let curr = 0;
269
+ let next = 0;
270
+ const lines = [];
271
+
272
+ // Invariants: 0 <= start <= length-1.
273
+ // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
274
+ // Inside the loop:
275
+ // A match implies length >= 2, so curr and next are <= length-2.
276
+ for (const match of line.matchAll(breakRegExp)) {
277
+ next = match.index;
278
+ // maintain invariant: curr - start <= width
279
+ if (next - start > width) {
280
+ end = curr > start ? curr : next; // derive end <= length-2
281
+ lines.push(line.slice(start, end));
282
+ // skip the space that was output as \n
283
+ start = end + 1; // derive start <= length-1
284
+ }
285
+ curr = next;
286
+ }
287
+
288
+ // By the invariants, start <= length-1, so there is something left over.
289
+ // It is either the whole string or a part starting from non-whitespace.
290
+ // Insert a break if the remainder is too long and there is a break available.
291
+ if (line.length - start > width && curr > start) {
292
+ lines.push(line.slice(start, curr));
293
+ lines.push(line.slice(curr + 1));
294
+ } else {
295
+ lines.push(line.slice(start));
296
+ }
297
+
298
+ return lines.join("\n");
299
+ }
300
+
301
+ function trimTrailingNewline(string: string) {
302
+ return string.at(-1) === "\n" ? string.slice(0, -1) : string;
303
+ }
304
+
305
+ // Note: a long line without a suitable break point will exceed the width limit.
306
+ // Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
307
+ function foldString(string: string, width: number): string {
308
+ // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
309
+ // unless they're before or after a more-indented line, or at the very
310
+ // beginning or end, in which case $k$ maps to $k$.
311
+ // Therefore, parse each chunk as newline(s) followed by a content line.
312
+ const lineRe = /(\n+)([^\n]*)/g;
313
+
314
+ // first line (possibly an empty line)
315
+ let result = ((): string => {
316
+ let nextLF = string.indexOf("\n");
317
+ nextLF = nextLF !== -1 ? nextLF : string.length;
318
+ lineRe.lastIndex = nextLF;
319
+ return foldLine(string.slice(0, nextLF), width);
320
+ })();
321
+ // If we haven't reached the first content line yet, don't add an extra \n.
322
+ let prevMoreIndented = string[0] === "\n" || string[0] === " ";
323
+ let moreIndented;
324
+
325
+ // rest of the lines
326
+ let match;
327
+ // tslint:disable-next-line:no-conditional-assignment
328
+ while ((match = lineRe.exec(string))) {
329
+ const prefix = match[1];
330
+ const line = match[2] || "";
331
+ moreIndented = line[0] === " ";
332
+ result += prefix +
333
+ (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") +
334
+ foldLine(line, width);
335
+ prevMoreIndented = moreIndented;
336
+ }
337
+
338
+ return result;
339
+ }
340
+
341
+ // Escapes a double-quoted string.
342
+ function escapeString(string: string): string {
343
+ let result = "";
344
+ let char;
345
+ let nextChar;
346
+ let escapeSeq;
347
+
348
+ for (let i = 0; i < string.length; i++) {
349
+ char = string.charCodeAt(i);
350
+ // Check for surrogate pairs (reference Unicode 3.0 section "3.7 Surrogates").
351
+ if (char >= 0xd800 && char <= 0xdbff /* high surrogate */) {
352
+ nextChar = string.charCodeAt(i + 1);
353
+ if (nextChar >= 0xdc00 && nextChar <= 0xdfff /* low surrogate */) {
354
+ // Combine the surrogate pair and store it escaped.
355
+ result += charCodeToHexString(
356
+ (char - 0xd800) * 0x400 + nextChar - 0xdc00 + 0x10000,
357
+ );
358
+ // Advance index one extra since we already used that char here.
359
+ i++;
360
+ continue;
361
+ }
362
+ }
363
+ escapeSeq = ESCAPE_SEQUENCES.get(char);
364
+ result += !escapeSeq && isPrintable(char)
365
+ ? string[i]
366
+ : escapeSeq || charCodeToHexString(char);
367
+ }
368
+
369
+ return result;
370
+ }
371
+
372
+ // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
373
+ function blockHeader(string: string, indentPerLevel: number): string {
374
+ const indentIndicator = needIndentIndicator(string)
375
+ ? String(indentPerLevel)
376
+ : "";
377
+
378
+ // note the special case: the string '\n' counts as a "trailing" empty line.
379
+ const clip = string[string.length - 1] === "\n";
380
+ const keep = clip && (string[string.length - 2] === "\n" || string === "\n");
381
+ const chomp = keep ? "+" : clip ? "" : "-";
382
+
383
+ return `${indentIndicator}${chomp}\n`;
384
+ }
385
+
386
+ function getDuplicateObjects(root: unknown): unknown[] {
387
+ const seenObjects = new Set();
388
+ const duplicateObjects = new Set();
389
+ const queue = [root];
390
+
391
+ for (let i = 0; i < queue.length; i++) {
392
+ const value = queue[i];
393
+ if (!isObject(value)) continue;
394
+ if (seenObjects.has(value)) {
395
+ duplicateObjects.add(value);
396
+ continue;
397
+ }
398
+ seenObjects.add(value);
399
+ const children = Array.isArray(value) ? value : Object.values(value);
400
+ queue.push(...children);
401
+ }
402
+
403
+ return [...duplicateObjects];
404
+ }
405
+ function stringifyValue(value: unknown, tag: string | null) {
406
+ if (tag !== null && tag !== "?") return `!<${tag}> ${value}`;
407
+ return value as string;
408
+ }
409
+
410
+ export interface DumperStateOptions {
411
+ /** indentation width to use (in spaces). */
412
+ indent?: number;
413
+ /** when true, adds an indentation level to array elements */
414
+ arrayIndent?: boolean;
415
+ /**
416
+ * do not throw on invalid types (like function in the safe schema)
417
+ * and skip pairs and single values with such types.
418
+ */
419
+ skipInvalid?: boolean;
420
+ /**
421
+ * specifies level of nesting, when to switch from
422
+ * block to flow style for collections. -1 means block style everywhere
423
+ */
424
+ flowLevel?: number;
425
+ /** Each tag may have own set of styles. - "tag" => "style" map. */
426
+ styles?: Record<string, StyleVariant>;
427
+ /** specifies a schema to use. */
428
+ schema?: Schema;
429
+ /**
430
+ * If true, sort keys when dumping YAML in ascending, ASCII character order.
431
+ * If a function, use the function to sort the keys. (default: false)
432
+ * If a function is specified, the function must return a negative value
433
+ * if first argument is less than second argument, zero if they're equal
434
+ * and a positive value otherwise.
435
+ */
436
+ sortKeys?: boolean | ((a: string, b: string) => number);
437
+ /** set max line width. (default: 80) */
438
+ lineWidth?: number;
439
+ /**
440
+ * if false, don't convert duplicate objects
441
+ * into references (default: true)
442
+ */
443
+ useAnchors?: boolean;
444
+ /**
445
+ * if false don't try to be compatible with older yaml versions.
446
+ * Currently: don't quote "yes", "no" and so on,
447
+ * as required for YAML 1.1 (default: true)
448
+ */
449
+ compatMode?: boolean;
450
+ /**
451
+ * if true flow sequences will be condensed, omitting the
452
+ * space between `key: value` or `a, b`. Eg. `'[a,b]'` or `{a:{b:c}}`.
453
+ * Can be useful when using yaml for pretty URL query params
454
+ * as spaces are %-encoded. (default: false).
455
+ */
456
+ condenseFlow?: boolean;
457
+ /**
458
+ * Strings will be quoted using this quoting style.
459
+ * If you specify single quotes, double quotes will still be used
460
+ * for non-printable characters. (default: "'")
461
+ */
462
+ quoteStyle?: "'" | '"';
463
+ }
464
+
465
+ export class DumperState {
466
+ indent: number;
467
+ arrayIndent: boolean;
468
+ skipInvalid: boolean;
469
+ flowLevel: number;
470
+ sortKeys: boolean | ((a: string, b: string) => number);
471
+ lineWidth: number;
472
+ useAnchors: boolean;
473
+ compatMode: boolean;
474
+ condenseFlow: boolean;
475
+ implicitTypes: Type<"scalar">[];
476
+ explicitTypes: Type<KindType>[];
477
+ duplicates: unknown[] = [];
478
+ usedDuplicates: Set<unknown> = new Set();
479
+ styleMap: Map<string, StyleVariant> = new Map();
480
+ quoteStyle: "'" | '"';
481
+
482
+ constructor({
483
+ schema = DEFAULT_SCHEMA,
484
+ indent = 2,
485
+ arrayIndent = true,
486
+ skipInvalid = false,
487
+ flowLevel = -1,
488
+ styles = undefined,
489
+ sortKeys = false,
490
+ lineWidth = 80,
491
+ useAnchors = true,
492
+ compatMode = true,
493
+ condenseFlow = false,
494
+ quoteStyle = "'",
495
+ }: DumperStateOptions) {
496
+ this.indent = Math.max(1, indent);
497
+ this.arrayIndent = arrayIndent;
498
+ this.skipInvalid = skipInvalid;
499
+ this.flowLevel = flowLevel;
500
+ if (styles) this.styleMap = createStyleMap(styles);
501
+ this.sortKeys = sortKeys;
502
+ this.lineWidth = lineWidth;
503
+ this.useAnchors = useAnchors;
504
+ this.compatMode = compatMode;
505
+ this.condenseFlow = condenseFlow;
506
+ this.implicitTypes = schema.implicitTypes;
507
+ this.explicitTypes = schema.explicitTypes;
508
+ this.quoteStyle = quoteStyle;
509
+ }
510
+
511
+ // Note: line breaking/folding is implemented for only the folded style.
512
+ // NB. We drop the last trailing newline (if any) of a returned block scalar
513
+ // since the dumper adds its own newline. This always works:
514
+ // • No ending newline => unaffected; already using strip "-" chomping.
515
+ // • Ending newline => removed then restored.
516
+ // Importantly, this keeps the "+" chomp indicator from gaining an extra line.
517
+ stringifyScalar(
518
+ string: string,
519
+ { level, isKey }: { level: number; isKey: boolean },
520
+ ): string {
521
+ if (string.length === 0) {
522
+ return "''";
523
+ }
524
+ if (this.compatMode && DEPRECATED_BOOLEANS_SYNTAX.has(string)) {
525
+ return `'${string}'`;
526
+ }
527
+
528
+ const indent = this.indent * Math.max(1, level); // no 0-indent scalars
529
+ // As indentation gets deeper, let the width decrease monotonically
530
+ // to the lower bound min(this.lineWidth, 40).
531
+ // Note that this implies
532
+ // this.lineWidth ≤ 40 + this.indent: width is fixed at the lower bound.
533
+ // this.lineWidth > 40 + this.indent: width decreases until the lower
534
+ // bound.
535
+ // This behaves better than a constant minimum width which disallows
536
+ // narrower options, or an indent threshold which causes the width
537
+ // to suddenly increase.
538
+ const lineWidth = this.lineWidth === -1
539
+ ? -1
540
+ : Math.max(Math.min(this.lineWidth, 40), this.lineWidth - indent);
541
+
542
+ // Without knowing if keys are implicit/explicit,
543
+ // assume implicit for safety.
544
+ const singleLineOnly = isKey ||
545
+ // No block styles in flow mode.
546
+ (this.flowLevel > -1 && level >= this.flowLevel);
547
+
548
+ const scalarStyle = chooseScalarStyle(
549
+ string,
550
+ singleLineOnly,
551
+ this.indent,
552
+ lineWidth,
553
+ this.implicitTypes,
554
+ this.quoteStyle,
555
+ );
556
+ switch (scalarStyle) {
557
+ case STYLE_PLAIN:
558
+ return string;
559
+ case STYLE_SINGLE:
560
+ return `'${string.replace(/'/g, "''")}'`;
561
+ case STYLE_LITERAL:
562
+ return `|${blockHeader(string, this.indent)}${
563
+ trimTrailingNewline(indentString(string, indent))
564
+ }`;
565
+ case STYLE_FOLDED:
566
+ return `>${blockHeader(string, this.indent)}${
567
+ trimTrailingNewline(
568
+ indentString(foldString(string, lineWidth), indent),
569
+ )
570
+ }`;
571
+ case STYLE_DOUBLE:
572
+ return `"${escapeString(string)}"`;
573
+ default:
574
+ throw new TypeError(
575
+ "Invalid scalar style should be unreachable: please file a bug report against Deno at https://github.com/denoland/std/issues",
576
+ );
577
+ }
578
+ }
579
+
580
+ stringifyFlowSequence(
581
+ array: unknown[],
582
+ { level }: { level: number },
583
+ ): string {
584
+ const results = [];
585
+ for (const value of array) {
586
+ const string = this.stringifyNode(value, {
587
+ level,
588
+ block: false,
589
+ compact: false,
590
+ isKey: false,
591
+ });
592
+ if (string === null) continue;
593
+ results.push(string);
594
+ }
595
+ const separator = this.condenseFlow ? "," : ", ";
596
+ return `[${results.join(separator)}]`;
597
+ }
598
+
599
+ stringifyBlockSequence(
600
+ array: unknown[],
601
+ { level, compact }: { level: number; compact: boolean },
602
+ ): string {
603
+ const whitespace = generateNextLine(this.indent, level);
604
+ const prefix = compact ? "" : whitespace;
605
+ const results = [];
606
+ for (const value of array) {
607
+ const string = this.stringifyNode(value, {
608
+ level: level + 1,
609
+ block: true,
610
+ compact: true,
611
+ isKey: false,
612
+ });
613
+ if (string === null) continue;
614
+ const linePrefix = LINE_FEED === string.charCodeAt(0) ? "-" : "- ";
615
+ results.push(`${linePrefix}${string}`);
616
+ }
617
+ return results.length ? prefix + results.join(whitespace) : "[]";
618
+ }
619
+
620
+ stringifyFlowMapping(
621
+ object: Record<string, unknown>,
622
+ { level }: { level: number },
623
+ ): string {
624
+ const quote = this.condenseFlow ? '"' : "";
625
+ const separator = this.condenseFlow ? ":" : ": ";
626
+
627
+ const results = [];
628
+ for (const [key, value] of Object.entries(object)) {
629
+ const keyString = this.stringifyNode(key, {
630
+ level,
631
+ block: false,
632
+ compact: false,
633
+ isKey: false,
634
+ });
635
+ if (keyString === null) continue; // Skip this pair because of invalid key;
636
+
637
+ const valueString = this.stringifyNode(value, {
638
+ level,
639
+ block: false,
640
+ compact: false,
641
+ isKey: false,
642
+ });
643
+ if (valueString === null) continue; // Skip this pair because of invalid value.
644
+
645
+ const keyPrefix = keyString.length > 1024 ? "? " : "";
646
+ results.push(
647
+ quote + keyPrefix + keyString + quote + separator + valueString,
648
+ );
649
+ }
650
+
651
+ return `{${results.join(", ")}}`;
652
+ }
653
+
654
+ stringifyBlockMapping(
655
+ object: Record<string, unknown>,
656
+ { tag, level, compact }: {
657
+ tag: string | null;
658
+ level: number;
659
+ compact: boolean;
660
+ },
661
+ ): string {
662
+ const keys = Object.keys(object);
663
+
664
+ // Allow sorting keys so that the output file is deterministic
665
+ if (this.sortKeys === true) {
666
+ // Default sorting
667
+ keys.sort();
668
+ } else if (typeof this.sortKeys === "function") {
669
+ // Custom sort function
670
+ keys.sort(this.sortKeys);
671
+ } else if (this.sortKeys) {
672
+ // Something is wrong
673
+ throw new TypeError(
674
+ `"sortKeys" must be a boolean or a function: received ${typeof this
675
+ .sortKeys}`,
676
+ );
677
+ }
678
+
679
+ const separator = generateNextLine(this.indent, level);
680
+
681
+ const results = [];
682
+
683
+ for (const key of keys) {
684
+ const value = object[key];
685
+
686
+ const keyString = this.stringifyNode(key, {
687
+ level: level + 1,
688
+ block: true,
689
+ compact: true,
690
+ isKey: true,
691
+ });
692
+ if (keyString === null) continue; // Skip this pair because of invalid key.
693
+
694
+ const explicitPair = (tag !== null && tag !== "?") ||
695
+ (keyString.length > 1024);
696
+
697
+ const valueString = this.stringifyNode(value, {
698
+ level: level + 1,
699
+ block: true,
700
+ compact: explicitPair,
701
+ isKey: false,
702
+ });
703
+ if (valueString === null) continue; // Skip this pair because of invalid value.
704
+
705
+ let pairBuffer = "";
706
+ if (explicitPair) {
707
+ pairBuffer += keyString.charCodeAt(0) === LINE_FEED ? "?" : "? ";
708
+ }
709
+ pairBuffer += keyString;
710
+ if (explicitPair) pairBuffer += separator;
711
+ pairBuffer += valueString.charCodeAt(0) === LINE_FEED ? ":" : ": ";
712
+ pairBuffer += valueString;
713
+ results.push(pairBuffer);
714
+ }
715
+
716
+ const prefix = compact ? "" : separator;
717
+ return results.length ? prefix + results.join(separator) : "{}"; // Empty mapping if no valid pairs.
718
+ }
719
+
720
+ getTypeRepresentation(type: Type<KindType, unknown>, value: unknown) {
721
+ if (!type.represent) return value;
722
+ const style = this.styleMap.get(type.tag) ??
723
+ type.defaultStyle as StyleVariant;
724
+ if (typeof type.represent === "function") {
725
+ return type.represent(value, style);
726
+ }
727
+ const represent = type.represent[style];
728
+ if (!represent) {
729
+ throw new TypeError(
730
+ `!<${type.tag}> tag resolver accepts not "${style}" style`,
731
+ );
732
+ }
733
+ return represent(value, style);
734
+ }
735
+
736
+ detectType(value: unknown): { tag: string | null; value: unknown } {
737
+ for (const type of this.implicitTypes) {
738
+ if (type.predicate?.(value)) {
739
+ value = this.getTypeRepresentation(type, value);
740
+ return { tag: "?", value };
741
+ }
742
+ }
743
+ for (const type of this.explicitTypes) {
744
+ if (type.predicate?.(value)) {
745
+ value = this.getTypeRepresentation(type, value);
746
+ return { tag: type.tag, value };
747
+ }
748
+ }
749
+ return { tag: null, value };
750
+ }
751
+
752
+ // Serializes `object` and writes it to global `result`.
753
+ // Returns true on success, or false on invalid object.
754
+ stringifyNode(value: unknown, { level, block, compact, isKey }: {
755
+ level: number;
756
+ block: boolean;
757
+ compact: boolean;
758
+ isKey: boolean;
759
+ }): string | null {
760
+ const result = this.detectType(value);
761
+ const tag = result.tag;
762
+ value = result.value;
763
+
764
+ if (block) {
765
+ block = this.flowLevel < 0 || this.flowLevel > level;
766
+ }
767
+
768
+ if (typeof value === "string" || value instanceof String) {
769
+ value = value instanceof String ? value.valueOf() : value;
770
+ if (tag !== "?") {
771
+ value = this.stringifyScalar(value as string, { level, isKey });
772
+ }
773
+ return stringifyValue(value, tag);
774
+ }
775
+
776
+ if (isObject(value)) {
777
+ const duplicateIndex = this.duplicates.indexOf(value);
778
+ const duplicate = duplicateIndex !== -1;
779
+
780
+ if (duplicate) {
781
+ if (this.usedDuplicates.has(value)) return `*ref_${duplicateIndex}`;
782
+ this.usedDuplicates.add(value);
783
+ }
784
+
785
+ if (
786
+ (tag !== null && tag !== "?") ||
787
+ duplicate ||
788
+ (this.indent !== 2 && level > 0)
789
+ ) {
790
+ compact = false;
791
+ }
792
+
793
+ if (Array.isArray(value)) {
794
+ const arrayLevel = !this.arrayIndent && level > 0 ? level - 1 : level;
795
+ if (block && value.length !== 0) {
796
+ value = this.stringifyBlockSequence(value, {
797
+ level: arrayLevel,
798
+ compact,
799
+ });
800
+ if (duplicate) value = `&ref_${duplicateIndex}${value}`;
801
+ return stringifyValue(value, tag);
802
+ }
803
+
804
+ value = this.stringifyFlowSequence(value, { level: arrayLevel });
805
+ if (duplicate) value = `&ref_${duplicateIndex} ${value}`;
806
+ return stringifyValue(value, tag);
807
+ }
808
+
809
+ if (block && Object.keys(value).length !== 0) {
810
+ value = this.stringifyBlockMapping(value, { tag, level, compact });
811
+ if (duplicate) value = `&ref_${duplicateIndex}${value}`;
812
+ return stringifyValue(value, tag);
813
+ }
814
+
815
+ value = this.stringifyFlowMapping(value, { level });
816
+ if (duplicate) value = `&ref_${duplicateIndex} ${value}`;
817
+ return stringifyValue(value, tag);
818
+ }
819
+
820
+ if (this.skipInvalid) return null;
821
+ throw new TypeError(`Cannot stringify ${typeof value}`);
822
+ }
823
+
824
+ stringify(value: unknown): string {
825
+ if (this.useAnchors) {
826
+ this.duplicates = getDuplicateObjects(value);
827
+ this.usedDuplicates = new Set();
828
+ }
829
+
830
+ const string = this.stringifyNode(value, {
831
+ level: 0,
832
+ block: true,
833
+ compact: true,
834
+ isKey: false,
835
+ });
836
+ if (string !== null) {
837
+ return `${string}\n`;
838
+ }
839
+ return "";
840
+ }
841
+ }