@mrclrchtr/supi-code-intelligence 12.0.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +4 -2
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-core/package.json +3 -1
  5. package/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -0
  6. package/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +1 -1
  7. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +22 -3
  8. package/node_modules/@mrclrchtr/supi-core/src/retired-packages.ts +152 -0
  9. package/node_modules/@mrclrchtr/supi-core/src/session.ts +1 -0
  10. package/node_modules/@mrclrchtr/supi-core/src/shell-hints.ts +46 -0
  11. package/node_modules/@mrclrchtr/supi-core/src/spill.ts +93 -0
  12. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +3 -1
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -0
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +1 -1
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +22 -3
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/retired-packages.ts +152 -0
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/session.ts +1 -0
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/shell-hints.ts +46 -0
  20. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/spill.ts +93 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/package.json +8 -8
  22. package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +1 -0
  23. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-cache.ts +102 -47
  24. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-host.ts +8 -0
  25. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-refresh.ts +15 -1
  26. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-request.ts +1 -1
  27. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +46 -4
  28. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-disk-stamp.ts +60 -0
  29. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-state.ts +3 -0
  30. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +21 -1
  31. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-file-state.ts +17 -3
  32. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-semantic-input-barrier.ts +53 -4
  33. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +11 -3
  34. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-extends.ts +2 -1
  35. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-path.ts +2 -2
  36. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +14 -5
  37. package/node_modules/@mrclrchtr/supi-lsp/src/config/typescript-module.ts +17 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/evidence.ts +42 -0
  39. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-client-state.ts +2 -17
  40. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-removal-ledger.ts +52 -0
  41. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +40 -20
  42. package/node_modules/@mrclrchtr/supi-lsp/src/manager/typescript-file-local.ts +6 -1
  43. package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-semantic-provider.ts +6 -1
  44. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +13 -3
  45. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostic-surface.ts +11 -0
  46. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostics.ts +1 -0
  47. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +17 -2
  48. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-transition-debug.ts +11 -1
  49. package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +2 -0
  50. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  51. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +3 -1
  52. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -0
  53. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +1 -1
  54. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +22 -3
  55. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/retired-packages.ts +152 -0
  56. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/session.ts +1 -0
  57. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/shell-hints.ts +46 -0
  58. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/spill.ts +93 -0
  59. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.cjs +50 -75
  60. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.cjs.map +2 -2
  61. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.js +50 -75
  62. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.js.map +2 -2
  63. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.wasm +0 -0
  64. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.wasm.map +6 -6
  65. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/package.json +1 -1
  66. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.cjs +50 -75
  67. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.cjs.map +2 -2
  68. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.cts +7 -7
  69. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.cts.map +1 -1
  70. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.ts +7 -7
  71. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.ts.map +1 -1
  72. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.js +50 -75
  73. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.js.map +2 -2
  74. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.wasm +0 -0
  75. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.wasm.map +5 -5
  76. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +5 -5
  77. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/kotlin/tree-sitter-kotlin.wasm.json +1 -1
  78. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/latex/tree-sitter-latex.wasm.json +1 -1
  79. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/sql/tree-sitter-sql.wasm.json +1 -1
  80. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +1 -1
  81. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +1 -1
  82. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +1 -1
  83. package/node_modules/fast-xml-parser/CHANGELOG.md +886 -0
  84. package/node_modules/fast-xml-parser/LICENSE +21 -0
  85. package/node_modules/fast-xml-parser/README.md +204 -0
  86. package/node_modules/fast-xml-parser/lib/fxbuilder.min.js +2 -0
  87. package/node_modules/fast-xml-parser/lib/fxbuilder.min.js.map +1 -0
  88. package/node_modules/fast-xml-parser/lib/fxp.cjs +1 -0
  89. package/node_modules/fast-xml-parser/lib/fxp.d.cts +774 -0
  90. package/node_modules/fast-xml-parser/lib/fxp.min.js +2 -0
  91. package/node_modules/fast-xml-parser/lib/fxp.min.js.map +1 -0
  92. package/node_modules/fast-xml-parser/lib/fxparser.min.js +2 -0
  93. package/node_modules/fast-xml-parser/lib/fxparser.min.js.map +1 -0
  94. package/node_modules/fast-xml-parser/lib/fxvalidator.min.js +2 -0
  95. package/node_modules/fast-xml-parser/lib/fxvalidator.min.js.map +1 -0
  96. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/README.md +92 -0
  97. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/package.json +57 -0
  98. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/EntityDecoder.js +644 -0
  99. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/EntityEncoder.js +239 -0
  100. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/all-entities.js +53 -0
  101. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/entities.js +1139 -0
  102. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/entityTries.js +60 -0
  103. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/index.d.ts +358 -0
  104. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/index.js +29 -0
  105. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/CHANGELOG.md +52 -0
  106. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/LICENSE +21 -0
  107. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/README.md +77 -0
  108. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/lib/fxb.cjs +1 -0
  109. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/lib/fxb.d.cts +270 -0
  110. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/lib/fxb.min.js +2 -0
  111. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/lib/fxb.min.js.map +1 -0
  112. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/package.json +77 -0
  113. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/fxb.d.ts +270 -0
  114. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/fxb.js +609 -0
  115. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/ignoreAttributes.js +18 -0
  116. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/orderedJs2Xml.js +360 -0
  117. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/prettifyJs2Xml.js +0 -0
  118. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/util.js +23 -0
  119. package/node_modules/fast-xml-parser/node_modules/is-unsafe/LICENSE +21 -0
  120. package/node_modules/fast-xml-parser/node_modules/is-unsafe/README.md +632 -0
  121. package/node_modules/fast-xml-parser/node_modules/is-unsafe/package.json +56 -0
  122. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/html.js +102 -0
  123. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/log.js +98 -0
  124. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/nosql.js +114 -0
  125. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/redos.js +60 -0
  126. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/shell.js +105 -0
  127. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/sql-strict.js +47 -0
  128. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/sql.js +95 -0
  129. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/svg.js +81 -0
  130. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/xml.js +79 -0
  131. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/index.cjs +27 -0
  132. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/index.d.ts +103 -0
  133. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/index.js +292 -0
  134. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/util/decode-entities.js +48 -0
  135. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/LICENSE +21 -0
  136. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/README.md +947 -0
  137. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/lib/pem.cjs +1 -0
  138. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/lib/pem.d.cts +725 -0
  139. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/lib/pem.min.js +2 -0
  140. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/lib/pem.min.js.map +1 -0
  141. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/package.json +79 -0
  142. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/src/Expression.js +232 -0
  143. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/src/ExpressionSet.js +225 -0
  144. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/src/Matcher.js +663 -0
  145. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/src/index.d.ts +589 -0
  146. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/src/index.js +30 -0
  147. package/node_modules/fast-xml-parser/node_modules/strnum/CHANGELOG.md +63 -0
  148. package/node_modules/fast-xml-parser/node_modules/strnum/LICENSE +21 -0
  149. package/node_modules/fast-xml-parser/node_modules/strnum/README.md +113 -0
  150. package/node_modules/fast-xml-parser/node_modules/strnum/node_modules/anynum/LICENSE +21 -0
  151. package/node_modules/fast-xml-parser/node_modules/strnum/node_modules/anynum/README.md +142 -0
  152. package/node_modules/fast-xml-parser/node_modules/strnum/node_modules/anynum/anynum.js +135 -0
  153. package/node_modules/fast-xml-parser/node_modules/strnum/node_modules/anynum/digitTable.js +116 -0
  154. package/node_modules/fast-xml-parser/node_modules/strnum/node_modules/anynum/package.json +42 -0
  155. package/node_modules/fast-xml-parser/node_modules/strnum/package.json +36 -0
  156. package/node_modules/fast-xml-parser/node_modules/strnum/strnum.js +176 -0
  157. package/node_modules/fast-xml-parser/node_modules/xml-naming/LICENSE +21 -0
  158. package/node_modules/fast-xml-parser/node_modules/xml-naming/README.md +287 -0
  159. package/node_modules/fast-xml-parser/node_modules/xml-naming/package.json +56 -0
  160. package/node_modules/fast-xml-parser/node_modules/xml-naming/src/index.d.ts +108 -0
  161. package/node_modules/fast-xml-parser/node_modules/xml-naming/src/index.js +382 -0
  162. package/node_modules/fast-xml-parser/package.json +93 -0
  163. package/node_modules/fast-xml-parser/src/cli/cli.js +97 -0
  164. package/node_modules/fast-xml-parser/src/cli/man.js +17 -0
  165. package/node_modules/fast-xml-parser/src/cli/read.js +43 -0
  166. package/node_modules/fast-xml-parser/src/fxp.d.ts +754 -0
  167. package/node_modules/fast-xml-parser/src/fxp.js +14 -0
  168. package/node_modules/fast-xml-parser/src/ignoreAttributes.js +18 -0
  169. package/node_modules/fast-xml-parser/src/util.js +61 -0
  170. package/node_modules/fast-xml-parser/src/v6/CharsSymbol.js +16 -0
  171. package/node_modules/fast-xml-parser/src/v6/EntitiesParser.js +106 -0
  172. package/node_modules/fast-xml-parser/src/v6/OptionsBuilder.js +61 -0
  173. package/node_modules/fast-xml-parser/src/v6/OutputBuilders/BaseOutputBuilder.js +69 -0
  174. package/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsArrBuilder.js +103 -0
  175. package/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsMinArrBuilder.js +100 -0
  176. package/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsObjBuilder.js +154 -0
  177. package/node_modules/fast-xml-parser/src/v6/OutputBuilders/ParserOptionsBuilder.js +94 -0
  178. package/node_modules/fast-xml-parser/src/v6/Report.js +0 -0
  179. package/node_modules/fast-xml-parser/src/v6/TagPath.js +81 -0
  180. package/node_modules/fast-xml-parser/src/v6/TagPathMatcher.js +13 -0
  181. package/node_modules/fast-xml-parser/src/v6/XMLParser.js +83 -0
  182. package/node_modules/fast-xml-parser/src/v6/Xml2JsParser.js +235 -0
  183. package/node_modules/fast-xml-parser/src/v6/XmlPartReader.js +210 -0
  184. package/node_modules/fast-xml-parser/src/v6/XmlSpecialTagsReader.js +111 -0
  185. package/node_modules/fast-xml-parser/src/v6/inputSource/BufferSource.js +116 -0
  186. package/node_modules/fast-xml-parser/src/v6/inputSource/StringSource.js +121 -0
  187. package/node_modules/fast-xml-parser/src/v6/valueParsers/EntitiesParser.js +105 -0
  188. package/node_modules/fast-xml-parser/src/v6/valueParsers/booleanParser.js +22 -0
  189. package/node_modules/fast-xml-parser/src/v6/valueParsers/booleanParserExt.js +19 -0
  190. package/node_modules/fast-xml-parser/src/v6/valueParsers/currency.js +38 -0
  191. package/node_modules/fast-xml-parser/src/v6/valueParsers/join.js +13 -0
  192. package/node_modules/fast-xml-parser/src/v6/valueParsers/number.js +14 -0
  193. package/node_modules/fast-xml-parser/src/v6/valueParsers/trim.js +6 -0
  194. package/node_modules/fast-xml-parser/src/validator.js +518 -0
  195. package/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js +6 -0
  196. package/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +426 -0
  197. package/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js +164 -0
  198. package/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +907 -0
  199. package/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js +77 -0
  200. package/node_modules/fast-xml-parser/src/xmlparser/node2json.js +177 -0
  201. package/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js +54 -0
  202. package/package.json +10 -8
  203. package/src/analysis/evidence.ts +331 -73
  204. package/src/analysis/health/diagnostics.ts +66 -18
  205. package/src/analysis/health/evidence-reason.ts +44 -0
  206. package/src/analysis/search/pattern.ts +3 -3
  207. package/src/analysis/target/anchored.ts +3 -6
  208. package/src/analysis/target/symbol.ts +41 -47
  209. package/src/analysis/target/types.ts +4 -9
  210. package/src/analysis/workspace/cmake-parser.ts +207 -0
  211. package/src/analysis/workspace/cmake.ts +141 -0
  212. package/src/analysis/workspace/maven.ts +310 -0
  213. package/src/analysis/workspace/membership.ts +100 -26
  214. package/src/analysis/workspace/metadata.ts +6 -1
  215. package/src/analysis/workspace/observe.ts +6 -0
  216. package/src/analysis/workspace/types.ts +11 -3
  217. package/src/diagnostics/coverage.ts +49 -0
  218. package/src/diagnostics/evidence.ts +10 -2
  219. package/src/session/health-workflow.ts +6 -0
  220. package/src/session/input/common.ts +1 -1
  221. package/src/session/orientation/collect.ts +42 -7
  222. package/src/session/orientation/context-facts.ts +3 -3
  223. package/src/session/orientation/context-sections.ts +13 -15
  224. package/src/session/orientation/facts.ts +5 -8
  225. package/src/session/orientation-workflow.ts +4 -19
  226. package/src/session/target-workflow.ts +25 -18
  227. package/src/tool/code_find/result.ts +5 -7
  228. package/src/tool/code_graph/display.ts +5 -6
  229. package/src/tool/code_graph/format.ts +8 -24
  230. package/src/tool/code_graph/result.ts +16 -75
  231. package/src/tool/code_graph/section.ts +21 -33
  232. package/src/tool/code_graph/tui.ts +10 -5
  233. package/src/tool/code_health/diagnostic-tui.ts +49 -0
  234. package/src/tool/code_health/guidance.ts +27 -0
  235. package/src/tool/code_health/markdown.ts +60 -8
  236. package/src/tool/code_health/result.ts +20 -9
  237. package/src/tool/code_health/structured-schema.ts +14 -0
  238. package/src/tool/code_health/structured.ts +7 -1
  239. package/src/tool/code_health/tui.ts +33 -40
  240. package/src/tool/code_inspect/result.ts +23 -18
  241. package/src/tool/code_inspect/structured.ts +2 -19
  242. package/src/tool/code_orientation/result.ts +53 -100
  243. package/src/tool/code_orientation/structured-schema.ts +16 -12
  244. package/src/tool/code_orientation/structured-workspace.ts +13 -7
  245. package/src/tool/code_orientation/structured.ts +31 -39
  246. package/src/tool/code_orientation/workspace-format.ts +4 -10
  247. package/src/tool/code_orientation/workspace-instructions.ts +4 -5
  248. package/src/tool/code_orientation/workspace-observations.ts +2 -2
  249. package/src/tool/code_orientation/workspace-output.ts +16 -7
  250. package/src/tool/code_orientation/workspace-projects.ts +7 -10
  251. package/src/tool/code_orientation/workspace-sections.ts +13 -19
  252. package/src/tool/code_resolve/markdown.ts +4 -46
  253. package/src/tool/code_resolve/result.ts +43 -72
  254. package/src/tool/infra/truncate.ts +2 -16
  255. package/src/tool/result/candidate-selection.ts +141 -0
  256. package/src/tool/result/display.ts +41 -45
  257. package/src/tool/result/errors.ts +1 -0
  258. package/src/tool/result/model-budget.ts +26 -1
  259. package/src/tool/result/refactor.ts +11 -8
  260. package/src/tool/result/structured.ts +2 -1
  261. package/src/tool/result/types.ts +9 -8
  262. package/src/tool/schemas.ts +15 -20
  263. package/src/ui/footer.ts +2 -4
  264. package/src/ui/status-presentation.ts +4 -7
  265. package/src/ui/tui/candidate-selection.ts +40 -95
  266. package/src/ui/tui/common.ts +16 -70
  267. package/src/ui/tui/display.ts +6 -24
  268. package/src/tool/result/candidate-row.ts +0 -49
@@ -0,0 +1,81 @@
1
+ /**
2
+ * SVG context patterns.
3
+ *
4
+ * SVG is XML-based but renders in browsers, giving it a unique attack surface
5
+ * that combines XML parser behaviour with browser rendering and JavaScript execution.
6
+ *
7
+ * Many of these vectors bypass HTML sanitizers that don't understand SVG semantics
8
+ * (DOMPurify has documented bypass vulnerabilities specifically in SVG/XML context).
9
+ */
10
+
11
+ const SVG_PATTERNS = [
12
+ {
13
+ id: 'svg-script-element',
14
+ description: '<script element inside SVG executes JavaScript',
15
+ pattern: /<script[\s>/]/i,
16
+ },
17
+ {
18
+ id: 'svg-xlink-href-javascript',
19
+ description: 'xlink:href with javascript: — classic SVG XSS via <a> or <use>',
20
+ pattern: /xlink\s*:\s*href\s*=\s*["']?\s*javascript\s*:/i,
21
+ },
22
+ {
23
+ id: 'svg-href-javascript',
24
+ description: 'href= with javascript: in SVG context (<a>, <animate>, etc.)',
25
+ pattern: /href\s*=\s*["']?\s*javascript\s*:/i,
26
+ },
27
+ {
28
+ id: 'svg-foreignobject',
29
+ description: '<foreignObject embeds HTML inside SVG — can execute scripts',
30
+ pattern: /<foreignObject[\s>/]/i,
31
+ },
32
+ {
33
+ id: 'svg-use-external',
34
+ description: '<use xlink:href or href pointing to external resource (non-fragment URL)',
35
+ // Match <use with href= where the value starts with a non-# character (external URL)
36
+ // [\"'][^#] catches quoted values not starting with #; [^\"'#\s>] catches unquoted
37
+ pattern: /<use[\s\S]{0,60}(?:xlink\s*:\s*)?href\s*=\s*(?:["'][^#]|[^"'#\s>])/i,
38
+ },
39
+ {
40
+ id: 'svg-animate-href',
41
+ description: '<animate attributeName="href" — can dynamically change href to javascript:',
42
+ pattern: /<animate[\s\S]{0,80}attributeName\s*=\s*["'][\s]*href["']/i,
43
+ },
44
+ {
45
+ id: 'svg-animate-xlinkhref',
46
+ description: '<animate attributeName="xlink:href"',
47
+ pattern: /<animate[\s\S]{0,80}attributeName\s*=\s*["'][\s]*xlink\s*:\s*href["']/i,
48
+ },
49
+ {
50
+ id: 'svg-set-javascript',
51
+ description: '<set to="javascript:..." — sets an attribute to a javascript: URI',
52
+ pattern: /<set[\s\S]{0,80}to\s*=\s*["']?\s*javascript\s*:/i,
53
+ },
54
+ {
55
+ id: 'svg-event-handler',
56
+ description: 'SVG-specific event handler attributes: onload=, onerror=, onactivate=, etc.',
57
+ pattern: /\bon(?:load|error|activate|begin|end|repeat|focus|blur|click|mouse\w{1,20}|key\w{1,20})\s*=/i,
58
+ },
59
+ {
60
+ id: 'svg-handler-generic',
61
+ description: 'Generic on* handler catch-all for SVG attributes',
62
+ pattern: /\bon\w{1,30}\s*=/i,
63
+ },
64
+ {
65
+ id: 'svg-filter-feimage',
66
+ description: '<feImage href= — filter primitive that can load external resources',
67
+ pattern: /<feImage[\s\S]{0,80}(?:xlink\s*:\s*)?href\s*=/i,
68
+ },
69
+ {
70
+ id: 'svg-image-external',
71
+ description: '<image xlink:href with http/https or javascript protocol',
72
+ pattern: /<image[\s\S]{0,80}(?:xlink\s*:\s*)?href\s*=\s*["']?\s*(?:https?|javascript)\s*:/i,
73
+ },
74
+ {
75
+ id: 'svg-style-javascript',
76
+ description: 'style= attribute containing javascript: (e.g. background:url(javascript:...))',
77
+ pattern: /style\s*=[\s\S]{0,60}javascript\s*:/i,
78
+ },
79
+ ];
80
+
81
+ export default SVG_PATTERNS;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * XML context patterns.
3
+ *
4
+ * Detects injection vectors that are specifically dangerous when a string
5
+ * is inserted into an XML document (not HTML rendering context).
6
+ *
7
+ * Key distinction from HTML: these patterns target parser-level attacks —
8
+ * things that can confuse or subvert an XML parser, trigger external entity
9
+ * resolution, or inject DTD content. HTML rendering concerns (XSS) belong
10
+ * in the HTML context.
11
+ */
12
+
13
+ const XML_PATTERNS = [
14
+ {
15
+ id: 'xml-cdata-injection',
16
+ description: 'CDATA section injection: <![CDATA[ breaks out of text node context',
17
+ pattern: /<!\[CDATA\[/i,
18
+ },
19
+ {
20
+ id: 'xml-cdata-close',
21
+ description: 'CDATA close sequence: ]]> can terminate an enclosing CDATA section',
22
+ pattern: /\]\]>/,
23
+ },
24
+ {
25
+ id: 'xml-processing-instruction',
26
+ description: 'XML processing instruction: <?xml-stylesheet or <?php etc.',
27
+ pattern: /<\?(?:xml[\- ]|php|asp)/i,
28
+ },
29
+ {
30
+ id: 'xml-doctype-injection',
31
+ description: 'DOCTYPE declaration embedded in content — can define entities',
32
+ // Match <!DOCTYPE followed by end-of-string, whitespace, or [ (internal subset)
33
+ pattern: /<!DOCTYPE(?:[\s[]|$)/i,
34
+ },
35
+ {
36
+ id: 'xml-entity-system',
37
+ description: 'SYSTEM keyword — used in external entity declarations (XXE)',
38
+ pattern: /\bSYSTEM\s+["']/i,
39
+ },
40
+ {
41
+ id: 'xml-entity-public',
42
+ description: 'PUBLIC keyword — used in external entity declarations (XXE)',
43
+ pattern: /\bPUBLIC\s+["']/i,
44
+ },
45
+ {
46
+ id: 'xml-entity-declaration',
47
+ description: '<!ENTITY declaration — defines entities, potential XXE or entity expansion',
48
+ pattern: /<!ENTITY[\s%]/i,
49
+ },
50
+ {
51
+ id: 'xml-billion-laughs',
52
+ description: 'Entity reference chaining / billion laughs: repeated &eX; style references',
53
+ // Heuristic: 3+ consecutive entity refs suggests expansion attack
54
+ pattern: /(?:&\w{1,20};){3,}/,
55
+ },
56
+ {
57
+ id: 'xml-namespace-confusion',
58
+ description: 'xmlns: attribute injection — can redefine namespaces to confuse parsers',
59
+ // pattern: /\bxmlns\s*(?::\w{1,40})?\s*=/i,
60
+ pattern: /\bxmlns(?::\w{1,40})?\s*=/i,
61
+ },
62
+ {
63
+ id: 'xml-comment-injection',
64
+ description: '<!-- comment injection — can hide content from some parsers',
65
+ pattern: /<!--/,
66
+ },
67
+ {
68
+ id: 'xml-comment-close',
69
+ description: '--> closes an enclosing XML comment',
70
+ pattern: /-->/,
71
+ },
72
+ {
73
+ id: 'xml-pi-close',
74
+ description: '?> closes an enclosing processing instruction',
75
+ pattern: /\?>/,
76
+ },
77
+ ];
78
+
79
+ export default XML_PATTERNS;
@@ -0,0 +1,27 @@
1
+ // CommonJS shim — generated from src/index.js
2
+ // For bundlers and Node.js environments that require CJS interop.
3
+ // This file re-exports via dynamic import to bridge ESM → CJS.
4
+
5
+ let _mod;
6
+ async function _load() {
7
+ if (!_mod) _mod = await import('./index.js');
8
+ return _mod;
9
+ }
10
+
11
+ // Synchronous-style exports via module.exports proxy
12
+ // (Works for environments that await the module, e.g. Jest with transformIgnorePatterns)
13
+ module.exports = new Proxy(
14
+ {},
15
+ {
16
+ get(_, key) {
17
+ throw new Error(
18
+ `is-unsafe: CommonJS require() is not fully supported. ` +
19
+ `Use dynamic import(): const { isUnsafe } = await import('is-unsafe'). ` +
20
+ `Or set "type": "module" in your package.json.`
21
+ );
22
+ },
23
+ }
24
+ );
25
+
26
+ // Export the loader for async CJS callers
27
+ module.exports.load = _load;
@@ -0,0 +1,103 @@
1
+ /**
2
+ * is-unsafe v2 — TypeScript declarations
3
+ *
4
+ * Each context is a tree-shakeable named export. Import only what you need.
5
+ */
6
+
7
+ /** A single detection rule: a pattern plus metadata. */
8
+ export interface Rule {
9
+ id: string;
10
+ description: string;
11
+ pattern: RegExp;
12
+ }
13
+
14
+ /**
15
+ * An ordered list of Rules for a given injection context.
16
+ *
17
+ * Built-in contexts (HTML, XML, etc.) have `label` pre-set by the library.
18
+ * Custom lists default to `'CUSTOM'` in MatchResult unless you set `label`:
19
+ *
20
+ * ```js
21
+ * const MY_RULES = [{ id: 'my-rule', description: '...', pattern: /danger/ }];
22
+ * MY_RULES.label = 'MY_CONTEXT';
23
+ * whyUnsafe('danger', MY_RULES); // → { context: 'MY_CONTEXT', ... }
24
+ * ```
25
+ */
26
+ export type PatternList = Rule[] & {
27
+ label?: string;
28
+ /**
29
+ * When `true`, each rule is tested against the raw input AND a copy with
30
+ * HTML character references decoded (numeric, hex, &colon;, &Tab;, &NewLine;).
31
+ * Set on HTML, XML and SVG. Leave unset for non-markup contexts.
32
+ */
33
+ decodeEntities?: boolean;
34
+ };
35
+
36
+ /**
37
+ * Valid context argument:
38
+ * - A single PatternList (e.g. `HTML`)
39
+ * - An array of PatternLists (e.g. `[HTML, XML]`) — unsafe if matches ANY
40
+ * - A custom RegExp
41
+ */
42
+ export type ContextArg = PatternList | PatternList[] | RegExp;
43
+
44
+ /** Describes which rule matched and why. */
45
+ export interface MatchResult {
46
+ /** Context label ('HTML', 'XML', 'CUSTOM', etc.) */
47
+ context: string;
48
+ id: string;
49
+ description: string;
50
+ pattern: RegExp;
51
+ }
52
+
53
+ // ─── Named context exports (tree-shakeable) ────────────────────────────────
54
+
55
+ export const HTML: PatternList;
56
+ export const XML: PatternList;
57
+ export const SVG: PatternList;
58
+ export const SQL: PatternList;
59
+ export const SQL_STRICT: PatternList;
60
+ export const SHELL: PatternList;
61
+ export const REDOS: PatternList;
62
+ export const NOSQL: PatternList;
63
+ export const LOG: PatternList;
64
+
65
+ // ─── VALID_CONTEXTS (convenience — pulls in all contexts) ──────────────────
66
+
67
+ export const VALID_CONTEXTS: {
68
+ readonly HTML: PatternList;
69
+ readonly XML: PatternList;
70
+ readonly SVG: PatternList;
71
+ readonly SQL: PatternList;
72
+ readonly 'SQL-STRICT': PatternList;
73
+ readonly SHELL: PatternList;
74
+ readonly REDOS: PatternList;
75
+ readonly NOSQL: PatternList;
76
+ readonly LOG: PatternList;
77
+ };
78
+
79
+ // ─── Core functions ────────────────────────────────────────────────────────
80
+
81
+ /**
82
+ * Returns `true` if `value` is unsafe in the given context(s).
83
+ *
84
+ * @example
85
+ * import { isUnsafe, HTML, XML } from 'is-unsafe';
86
+ * isUnsafe('<script>alert(1)</script>', HTML) // true
87
+ * isUnsafe('hello', [HTML, XML]) // false
88
+ * isUnsafe('hello', /danger/) // false
89
+ */
90
+ export function isUnsafe(value: string, context: ContextArg): boolean;
91
+
92
+ /**
93
+ * Returns the first `MatchResult` explaining why `value` is unsafe, or `null` if safe.
94
+ */
95
+ export function whyUnsafe(value: string, context: ContextArg): MatchResult | null;
96
+
97
+ /**
98
+ * Returns all matching rules across the given context(s), or `[]` if safe.
99
+ */
100
+ export function allUnsafe(value: string, context: ContextArg): MatchResult[];
101
+
102
+ declare const isUnsafeDefault: typeof isUnsafe;
103
+ export default isUnsafeDefault;
@@ -0,0 +1,292 @@
1
+ /**
2
+ * is-unsafe v2
3
+ *
4
+ * Zero-dependency, DOM-free, pure predicate for detecting unsafe strings
5
+ * across HTML, XML, SVG, SQL, SQL-STRICT, SHELL, REDOS, NOSQL, and LOG contexts.
6
+ *
7
+ * v2 change: contexts are imported as named pattern arrays rather than resolved
8
+ * via a string-keyed registry. This makes each context independently
9
+ * tree-shakeable — bundlers can drop any context you never import.
10
+ *
11
+ * @module is-unsafe
12
+ */
13
+
14
+ // ─── Context pattern arrays (named exports) ────────────────────────────────
15
+ // Import only the ones you need. Each is independently tree-shakeable.
16
+
17
+ export { default as HTML } from './contexts/html.js';
18
+ export { default as XML } from './contexts/xml.js';
19
+ export { default as SVG } from './contexts/svg.js';
20
+ export { default as SQL } from './contexts/sql.js';
21
+ export { default as SHELL } from './contexts/shell.js';
22
+ export { default as REDOS } from './contexts/redos.js';
23
+ export { default as NOSQL } from './contexts/nosql.js';
24
+ export { default as LOG } from './contexts/log.js';
25
+
26
+ // SQL-STRICT needs a quoted identifier because of the hyphen
27
+ import SQL_STRICT from './contexts/sql-strict.js';
28
+ export { SQL_STRICT };
29
+
30
+ // Markup contexts are also matched against an entity-decoded copy of the input,
31
+ // because browsers decode HTML character references before interpreting a URL
32
+ // scheme (e.g. javascript&#58;… is a javascript: URL).
33
+ import decodeEntities from './util/decode-entities.js';
34
+
35
+ // ─── VALID_CONTEXTS convenience re-export ─────────────────────────────────
36
+ // Importing this pulls in ALL contexts. Use it only when you need all of them
37
+ // (e.g. for validation UI, tooling, or exhaustive audits).
38
+ // If you only need a subset, import the named contexts directly instead.
39
+
40
+ import HTML from './contexts/html.js';
41
+ import XML from './contexts/xml.js';
42
+ import SVG from './contexts/svg.js';
43
+ import SQL from './contexts/sql.js';
44
+ import SHELL from './contexts/shell.js';
45
+ import REDOS from './contexts/redos.js';
46
+ import NOSQL from './contexts/nosql.js';
47
+ import LOG from './contexts/log.js';
48
+
49
+ // ─── Attach labels to named contexts ──────────────────────────────────────
50
+ // Each built-in PatternList carries its canonical name so matchList can read
51
+ // list.label directly — no registry lookup needed at match time.
52
+ // Custom PatternLists default to 'CUSTOM' unless the caller sets list.label.
53
+
54
+ HTML.label = 'HTML';
55
+ XML.label = 'XML';
56
+ SVG.label = 'SVG';
57
+
58
+ // Markup contexts: also test an entity-decoded copy (see util/decode-entities.js).
59
+ // Non-markup contexts (SQL, SHELL, LOG, …) are matched byte-for-byte as supplied.
60
+ HTML.decodeEntities = true;
61
+ XML.decodeEntities = true;
62
+ SVG.decodeEntities = true;
63
+ SQL.label = 'SQL';
64
+ SQL_STRICT.label = 'SQL-STRICT';
65
+ SHELL.label = 'SHELL';
66
+ REDOS.label = 'REDOS';
67
+ NOSQL.label = 'NOSQL';
68
+ LOG.label = 'LOG';
69
+
70
+ export const VALID_CONTEXTS = Object.freeze({
71
+ HTML,
72
+ XML,
73
+ SVG,
74
+ SQL,
75
+ 'SQL-STRICT': SQL_STRICT,
76
+ SHELL,
77
+ REDOS,
78
+ NOSQL,
79
+ LOG,
80
+ });
81
+
82
+ // ─── Types ────────────────────────────────────────────────────────────────
83
+
84
+ /**
85
+ * @typedef {{ id: string, description: string, pattern: RegExp }} Rule
86
+ */
87
+
88
+ /**
89
+ * @typedef {Rule[]} PatternList
90
+ */
91
+
92
+ /**
93
+ * @typedef {Object} MatchResult
94
+ * @property {string} context - Label identifying which context matched ('HTML', 'CUSTOM', etc.)
95
+ * @property {string} id - Rule identifier
96
+ * @property {string} description - Human-readable description of what was matched
97
+ * @property {RegExp} pattern - The pattern that matched
98
+ */
99
+
100
+ // ─── Internal helpers ──────────────────────────────────────────────────────
101
+
102
+ /**
103
+ * @param {unknown} value
104
+ */
105
+ function assertString(value) {
106
+ if (typeof value !== 'string') {
107
+ throw new TypeError(
108
+ `is-unsafe: first argument must be a string, got ${typeof value}`
109
+ );
110
+ }
111
+ }
112
+
113
+ /**
114
+ * @param {unknown} context
115
+ */
116
+ function assertContext(context) {
117
+ if (context instanceof RegExp) return;
118
+
119
+ if (Array.isArray(context)) {
120
+ if (context.length === 0) {
121
+ throw new TypeError('is-unsafe: context must not be an empty array');
122
+ }
123
+ // Detect array-of-arrays vs flat pattern list
124
+ if (Array.isArray(context[0])) {
125
+ // Array of PatternLists
126
+ for (const list of context) {
127
+ if (!Array.isArray(list) || list.length === 0) {
128
+ throw new TypeError(
129
+ 'is-unsafe: each context in the array must be a non-empty pattern array (PatternList)'
130
+ );
131
+ }
132
+ }
133
+ }
134
+ // else: flat PatternList — trust it, no deep validation needed
135
+ return;
136
+ }
137
+
138
+ throw new TypeError(
139
+ `is-unsafe: second argument must be a PatternList (e.g. HTML), ` +
140
+ `an array of PatternLists (e.g. [HTML, XML]), or a RegExp. Got: ${typeof context}`
141
+ );
142
+ }
143
+
144
+ /**
145
+ * Normalise any valid context arg into an array of PatternLists.
146
+ *
147
+ * @param {Rule[]|Rule[][]|RegExp} context
148
+ * @returns {{ lists: Rule[][]|null, regex: RegExp|null }}
149
+ */
150
+ function normalise(context) {
151
+ if (context instanceof RegExp) return { lists: null, regex: context };
152
+ // Distinguish PatternList (array of rule objects) from array of PatternLists
153
+ if (Array.isArray(context[0])) return { lists: context, regex: null };
154
+ return { lists: [context], regex: null };
155
+ }
156
+
157
+ /**
158
+ * For markup contexts, return an entity-decoded copy of `value` to test
159
+ * alongside the raw input, or null when there is nothing extra to test.
160
+ *
161
+ * @param {string} value
162
+ * @param {Rule[]} list
163
+ * @returns {string|null}
164
+ */
165
+ function decodedCopy(value, list) {
166
+ if (!list.decodeEntities) return null;
167
+ const decoded = decodeEntities(value);
168
+ return decoded === value ? null : decoded;
169
+ }
170
+
171
+ /**
172
+ * Test value against a single PatternList. Returns the first MatchResult or null.
173
+ *
174
+ * @param {string} value
175
+ * @param {Rule[]} list
176
+ * @returns {MatchResult|null}
177
+ */
178
+ function matchList(value, list) {
179
+ const label = list.label ?? 'CUSTOM';
180
+ const decoded = decodedCopy(value, list);
181
+ for (const rule of list) {
182
+ if (rule.pattern.test(value) || (decoded !== null && rule.pattern.test(decoded))) {
183
+ return { context: label, id: rule.id, description: rule.description, pattern: rule.pattern };
184
+ }
185
+ }
186
+ return null;
187
+ }
188
+
189
+ // ─── Public API ───────────────────────────────────────────────────────────
190
+
191
+ /**
192
+ * Returns `true` if `value` is unsafe in the given context(s), `false` otherwise.
193
+ *
194
+ * @param {string} value - The string to test
195
+ * @param {PatternList | PatternList[] | RegExp} context
196
+ * - A PatternList imported from is-unsafe (e.g. `HTML`, `XML`)
197
+ * - An array of PatternLists — returns true if unsafe in **any** of them
198
+ * - A custom RegExp — returns true if the pattern matches
199
+ * @returns {boolean}
200
+ *
201
+ * @example
202
+ * import { isUnsafe, HTML, SQL } from 'is-unsafe';
203
+ *
204
+ * isUnsafe('<script>alert(1)</script>', HTML) // true
205
+ * isUnsafe('hello world', HTML) // false
206
+ * isUnsafe('value', [HTML, SQL]) // false
207
+ * isUnsafe('value', /my-pattern/i) // false
208
+ */
209
+ function isUnsafe(value, context) {
210
+ assertString(value);
211
+ assertContext(context);
212
+
213
+ const { lists, regex } = normalise(context);
214
+
215
+ if (regex) return regex.test(value);
216
+
217
+ for (const list of lists) {
218
+ if (matchList(value, list) !== null) return true;
219
+ }
220
+ return false;
221
+ }
222
+
223
+ /**
224
+ * Like `isUnsafe`, but returns the first `MatchResult` describing **why**
225
+ * the value was flagged, or `null` if it is safe.
226
+ *
227
+ * @param {string} value
228
+ * @param {PatternList | PatternList[] | RegExp} context
229
+ * @returns {MatchResult|null}
230
+ *
231
+ * @example
232
+ * import { whyUnsafe, HTML } from 'is-unsafe';
233
+ *
234
+ * whyUnsafe('<script>alert(1)</script>', HTML)
235
+ * // { context: 'HTML', id: 'html-script-open', description: '...', pattern: /.../ }
236
+ */
237
+ function whyUnsafe(value, context) {
238
+ assertString(value);
239
+ assertContext(context);
240
+
241
+ const { lists, regex } = normalise(context);
242
+
243
+ if (regex) {
244
+ return regex.test(value)
245
+ ? { context: 'CUSTOM', id: 'custom-regex', description: 'Matched caller-supplied pattern', pattern: regex }
246
+ : null;
247
+ }
248
+
249
+ for (const list of lists) {
250
+ const result = matchList(value, list);
251
+ if (result !== null) return result;
252
+ }
253
+ return null;
254
+ }
255
+
256
+ /**
257
+ * Returns **all** matching rules across the given context(s), or an empty
258
+ * array if the value is safe. Useful for comprehensive auditing.
259
+ *
260
+ * @param {string} value
261
+ * @param {PatternList | PatternList[] | RegExp} context
262
+ * @returns {MatchResult[]}
263
+ */
264
+ function allUnsafe(value, context) {
265
+ assertString(value);
266
+ assertContext(context);
267
+
268
+ const { lists, regex } = normalise(context);
269
+ const results = [];
270
+
271
+ if (regex) {
272
+ if (regex.test(value)) {
273
+ results.push({ context: 'CUSTOM', id: 'custom-regex', description: 'Matched caller-supplied pattern', pattern: regex });
274
+ }
275
+ return results;
276
+ }
277
+
278
+ for (const list of lists) {
279
+ const label = list.label ?? 'CUSTOM';
280
+ const decoded = decodedCopy(value, list);
281
+ for (const rule of list) {
282
+ if (rule.pattern.test(value) || (decoded !== null && rule.pattern.test(decoded))) {
283
+ results.push({ context: label, id: rule.id, description: rule.description, pattern: rule.pattern });
284
+ }
285
+ }
286
+ }
287
+
288
+ return results;
289
+ }
290
+
291
+ export { isUnsafe, whyUnsafe, allUnsafe };
292
+ export default isUnsafe;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Decode the HTML character references that matter for markup-context
3
+ * detection.
4
+ *
5
+ * Browsers decode character references in attribute values before they
6
+ * interpret a URL, so `javascript&#58;alert(1)` in an href is the
7
+ * `javascript:` scheme. The HTML/XML/SVG rules match literal characters, so
8
+ * without this step such payloads slip through.
9
+ *
10
+ * Deliberately NOT a full entity decoder. It decodes only:
11
+ * - decimal refs &#58; &#058; &#00000058; &#58 (any leading zeros,
12
+ * trailing ; optional — browsers accept both)
13
+ * - hex refs &#x3a; &#X3A; &#x0000003a; &#x3a (same)
14
+ * - named refs &colon; &Tab; &NewLine;
15
+ * Named refs are CASE-SENSITIVE and REQUIRE the trailing ';', exactly
16
+ * like a browser (so `&COLON;` and `&colon` are not decoded).
17
+ * &Tab; / &NewLine; matter because the URL parser strips tab/newline,
18
+ * so `java&Tab;script:` is still a javascript: URL.
19
+ *
20
+ * It does NOT decode &amp; (single pass only), so double-encoded text such as
21
+ * "&amp;lt;script&amp;gt;" stays literal — a browser renders that as text.
22
+ *
23
+ * All quantifiers are bounded; no ReDoS risk.
24
+ *
25
+ * @param {string} input
26
+ * @returns {string}
27
+ */
28
+ const NAMED = Object.freeze({
29
+ colon: ':',
30
+ Tab: '\t',
31
+ NewLine: '\n',
32
+ });
33
+
34
+ const ENTITY_RE =
35
+ /&(?:#[xX]0*([0-9a-fA-F]{1,6});?|#0*([0-9]{1,7});?|([a-zA-Z][a-zA-Z0-9]{1,15});)/g;
36
+
37
+ export default function decodeEntities(input) {
38
+ if (input.indexOf('&') === -1) return input;
39
+
40
+ return input.replace(ENTITY_RE, (match, hex, dec, name) => {
41
+ if (name !== undefined) {
42
+ return Object.prototype.hasOwnProperty.call(NAMED, name) ? NAMED[name] : match;
43
+ }
44
+ const cp = hex !== undefined ? parseInt(hex, 16) : parseInt(dec, 10);
45
+ if (!Number.isFinite(cp) || cp > 0x10ffff) return match;
46
+ return String.fromCodePoint(cp);
47
+ });
48
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.