@mrclrchtr/supi-code-intelligence 11.4.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 (330) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +17 -9
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +1 -0
  5. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +51 -23
  6. package/node_modules/@mrclrchtr/supi-core/package.json +3 -1
  7. package/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -0
  8. package/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +1 -1
  9. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +22 -3
  10. package/node_modules/@mrclrchtr/supi-core/src/retired-packages.ts +152 -0
  11. package/node_modules/@mrclrchtr/supi-core/src/session.ts +1 -0
  12. package/node_modules/@mrclrchtr/supi-core/src/shell-hints.ts +46 -0
  13. package/node_modules/@mrclrchtr/supi-core/src/spill.ts +93 -0
  14. package/node_modules/@mrclrchtr/supi-lsp/README.md +21 -16
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +1 -0
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +51 -23
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +3 -1
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -0
  20. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +1 -1
  21. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +22 -3
  22. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/retired-packages.ts +152 -0
  23. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/session.ts +1 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/shell-hints.ts +46 -0
  25. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/spill.ts +93 -0
  26. package/node_modules/@mrclrchtr/supi-lsp/package.json +8 -8
  27. package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +3 -2
  28. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-cache.ts +102 -47
  29. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +13 -3
  30. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-host.ts +8 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-refresh.ts +15 -1
  32. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-request.ts +1 -1
  33. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +71 -13
  34. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-disk-stamp.ts +60 -0
  35. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-state.ts +3 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +28 -6
  37. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-edit-capture.ts +258 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-file-state.ts +17 -3
  39. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-semantic-input-barrier.ts +53 -4
  40. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +75 -14
  41. package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +8 -0
  42. package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +48 -79
  43. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-extends.ts +2 -1
  44. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-path.ts +2 -2
  45. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +14 -5
  46. package/node_modules/@mrclrchtr/supi-lsp/src/config/typescript-module.ts +17 -0
  47. package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/evidence.ts +42 -0
  48. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-client-state.ts +2 -17
  49. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-removal-ledger.ts +52 -0
  50. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +43 -21
  51. package/node_modules/@mrclrchtr/supi-lsp/src/manager/typescript-file-local.ts +6 -1
  52. package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-refactor-provider.ts +21 -35
  53. package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-semantic-provider.ts +6 -1
  54. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-command-capture.ts +139 -0
  55. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +202 -47
  56. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +13 -3
  57. package/node_modules/@mrclrchtr/supi-lsp/src/session/route-boundary.ts +26 -0
  58. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostic-surface.ts +11 -0
  59. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostics.ts +1 -0
  60. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +74 -14
  61. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +3 -0
  62. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-transition-debug.ts +11 -1
  63. package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +24 -1
  64. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  65. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +1 -0
  66. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +51 -23
  67. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +3 -1
  68. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -0
  69. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +1 -1
  70. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +22 -3
  71. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/retired-packages.ts +152 -0
  72. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/session.ts +1 -0
  73. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/shell-hints.ts +46 -0
  74. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/spill.ts +93 -0
  75. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.cjs +50 -75
  76. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.cjs.map +2 -2
  77. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.js +50 -75
  78. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.js.map +2 -2
  79. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.wasm +0 -0
  80. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.wasm.map +6 -6
  81. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/package.json +1 -1
  82. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.cjs +50 -75
  83. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.cjs.map +2 -2
  84. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.cts +7 -7
  85. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.cts.map +1 -1
  86. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.ts +7 -7
  87. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.ts.map +1 -1
  88. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.js +50 -75
  89. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.js.map +2 -2
  90. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.wasm +0 -0
  91. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.wasm.map +5 -5
  92. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +5 -5
  93. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/kotlin/tree-sitter-kotlin.wasm.json +1 -1
  94. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/latex/tree-sitter-latex.wasm.json +1 -1
  95. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/sql/tree-sitter-sql.wasm.json +1 -1
  96. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +1 -1
  97. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +1 -1
  98. package/node_modules/@mrclrchtr/supi-tree-sitter/src/coordinates.ts +16 -2
  99. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +4 -3
  100. package/node_modules/@mrclrchtr/supi-tree-sitter/src/syntax-errors.ts +2 -0
  101. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-range.ts +94 -0
  102. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +26 -6
  103. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +6 -3
  104. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +13 -4
  105. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +1 -9
  106. package/node_modules/fast-xml-parser/CHANGELOG.md +886 -0
  107. package/node_modules/fast-xml-parser/LICENSE +21 -0
  108. package/node_modules/fast-xml-parser/README.md +204 -0
  109. package/node_modules/fast-xml-parser/lib/fxbuilder.min.js +2 -0
  110. package/node_modules/fast-xml-parser/lib/fxbuilder.min.js.map +1 -0
  111. package/node_modules/fast-xml-parser/lib/fxp.cjs +1 -0
  112. package/node_modules/fast-xml-parser/lib/fxp.d.cts +774 -0
  113. package/node_modules/fast-xml-parser/lib/fxp.min.js +2 -0
  114. package/node_modules/fast-xml-parser/lib/fxp.min.js.map +1 -0
  115. package/node_modules/fast-xml-parser/lib/fxparser.min.js +2 -0
  116. package/node_modules/fast-xml-parser/lib/fxparser.min.js.map +1 -0
  117. package/node_modules/fast-xml-parser/lib/fxvalidator.min.js +2 -0
  118. package/node_modules/fast-xml-parser/lib/fxvalidator.min.js.map +1 -0
  119. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/README.md +92 -0
  120. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/package.json +57 -0
  121. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/EntityDecoder.js +644 -0
  122. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/EntityEncoder.js +239 -0
  123. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/all-entities.js +53 -0
  124. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/entities.js +1139 -0
  125. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/entityTries.js +60 -0
  126. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/index.d.ts +358 -0
  127. package/node_modules/fast-xml-parser/node_modules/@nodable/entities/src/index.js +29 -0
  128. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/CHANGELOG.md +52 -0
  129. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/LICENSE +21 -0
  130. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/README.md +77 -0
  131. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/lib/fxb.cjs +1 -0
  132. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/lib/fxb.d.cts +270 -0
  133. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/lib/fxb.min.js +2 -0
  134. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/lib/fxb.min.js.map +1 -0
  135. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/package.json +77 -0
  136. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/fxb.d.ts +270 -0
  137. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/fxb.js +609 -0
  138. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/ignoreAttributes.js +18 -0
  139. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/orderedJs2Xml.js +360 -0
  140. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/prettifyJs2Xml.js +0 -0
  141. package/node_modules/fast-xml-parser/node_modules/fast-xml-builder/src/util.js +23 -0
  142. package/node_modules/fast-xml-parser/node_modules/is-unsafe/LICENSE +21 -0
  143. package/node_modules/fast-xml-parser/node_modules/is-unsafe/README.md +632 -0
  144. package/node_modules/fast-xml-parser/node_modules/is-unsafe/package.json +56 -0
  145. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/html.js +102 -0
  146. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/log.js +98 -0
  147. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/nosql.js +114 -0
  148. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/redos.js +60 -0
  149. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/shell.js +105 -0
  150. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/sql-strict.js +47 -0
  151. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/sql.js +95 -0
  152. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/svg.js +81 -0
  153. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/contexts/xml.js +79 -0
  154. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/index.cjs +27 -0
  155. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/index.d.ts +103 -0
  156. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/index.js +292 -0
  157. package/node_modules/fast-xml-parser/node_modules/is-unsafe/src/util/decode-entities.js +48 -0
  158. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/LICENSE +21 -0
  159. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/README.md +947 -0
  160. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/lib/pem.cjs +1 -0
  161. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/lib/pem.d.cts +725 -0
  162. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/lib/pem.min.js +2 -0
  163. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/lib/pem.min.js.map +1 -0
  164. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/package.json +79 -0
  165. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/src/Expression.js +232 -0
  166. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/src/ExpressionSet.js +225 -0
  167. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/src/Matcher.js +663 -0
  168. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/src/index.d.ts +589 -0
  169. package/node_modules/fast-xml-parser/node_modules/path-expression-matcher/src/index.js +30 -0
  170. package/node_modules/fast-xml-parser/node_modules/strnum/CHANGELOG.md +63 -0
  171. package/node_modules/fast-xml-parser/node_modules/strnum/LICENSE +21 -0
  172. package/node_modules/fast-xml-parser/node_modules/strnum/README.md +113 -0
  173. package/node_modules/fast-xml-parser/node_modules/strnum/node_modules/anynum/LICENSE +21 -0
  174. package/node_modules/fast-xml-parser/node_modules/strnum/node_modules/anynum/README.md +142 -0
  175. package/node_modules/fast-xml-parser/node_modules/strnum/node_modules/anynum/anynum.js +135 -0
  176. package/node_modules/fast-xml-parser/node_modules/strnum/node_modules/anynum/digitTable.js +116 -0
  177. package/node_modules/fast-xml-parser/node_modules/strnum/node_modules/anynum/package.json +42 -0
  178. package/node_modules/fast-xml-parser/node_modules/strnum/package.json +36 -0
  179. package/node_modules/fast-xml-parser/node_modules/strnum/strnum.js +176 -0
  180. package/node_modules/fast-xml-parser/node_modules/xml-naming/LICENSE +21 -0
  181. package/node_modules/fast-xml-parser/node_modules/xml-naming/README.md +287 -0
  182. package/node_modules/fast-xml-parser/node_modules/xml-naming/package.json +56 -0
  183. package/node_modules/fast-xml-parser/node_modules/xml-naming/src/index.d.ts +108 -0
  184. package/node_modules/fast-xml-parser/node_modules/xml-naming/src/index.js +382 -0
  185. package/node_modules/fast-xml-parser/package.json +93 -0
  186. package/node_modules/fast-xml-parser/src/cli/cli.js +97 -0
  187. package/node_modules/fast-xml-parser/src/cli/man.js +17 -0
  188. package/node_modules/fast-xml-parser/src/cli/read.js +43 -0
  189. package/node_modules/fast-xml-parser/src/fxp.d.ts +754 -0
  190. package/node_modules/fast-xml-parser/src/fxp.js +14 -0
  191. package/node_modules/fast-xml-parser/src/ignoreAttributes.js +18 -0
  192. package/node_modules/fast-xml-parser/src/util.js +61 -0
  193. package/node_modules/fast-xml-parser/src/v6/CharsSymbol.js +16 -0
  194. package/node_modules/fast-xml-parser/src/v6/EntitiesParser.js +106 -0
  195. package/node_modules/fast-xml-parser/src/v6/OptionsBuilder.js +61 -0
  196. package/node_modules/fast-xml-parser/src/v6/OutputBuilders/BaseOutputBuilder.js +69 -0
  197. package/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsArrBuilder.js +103 -0
  198. package/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsMinArrBuilder.js +100 -0
  199. package/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsObjBuilder.js +154 -0
  200. package/node_modules/fast-xml-parser/src/v6/OutputBuilders/ParserOptionsBuilder.js +94 -0
  201. package/node_modules/fast-xml-parser/src/v6/Report.js +0 -0
  202. package/node_modules/fast-xml-parser/src/v6/TagPath.js +81 -0
  203. package/node_modules/fast-xml-parser/src/v6/TagPathMatcher.js +13 -0
  204. package/node_modules/fast-xml-parser/src/v6/XMLParser.js +83 -0
  205. package/node_modules/fast-xml-parser/src/v6/Xml2JsParser.js +235 -0
  206. package/node_modules/fast-xml-parser/src/v6/XmlPartReader.js +210 -0
  207. package/node_modules/fast-xml-parser/src/v6/XmlSpecialTagsReader.js +111 -0
  208. package/node_modules/fast-xml-parser/src/v6/inputSource/BufferSource.js +116 -0
  209. package/node_modules/fast-xml-parser/src/v6/inputSource/StringSource.js +121 -0
  210. package/node_modules/fast-xml-parser/src/v6/valueParsers/EntitiesParser.js +105 -0
  211. package/node_modules/fast-xml-parser/src/v6/valueParsers/booleanParser.js +22 -0
  212. package/node_modules/fast-xml-parser/src/v6/valueParsers/booleanParserExt.js +19 -0
  213. package/node_modules/fast-xml-parser/src/v6/valueParsers/currency.js +38 -0
  214. package/node_modules/fast-xml-parser/src/v6/valueParsers/join.js +13 -0
  215. package/node_modules/fast-xml-parser/src/v6/valueParsers/number.js +14 -0
  216. package/node_modules/fast-xml-parser/src/v6/valueParsers/trim.js +6 -0
  217. package/node_modules/fast-xml-parser/src/validator.js +518 -0
  218. package/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js +6 -0
  219. package/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +426 -0
  220. package/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js +164 -0
  221. package/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +907 -0
  222. package/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js +77 -0
  223. package/node_modules/fast-xml-parser/src/xmlparser/node2json.js +177 -0
  224. package/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js +54 -0
  225. package/package.json +10 -8
  226. package/src/analysis/evidence.ts +331 -73
  227. package/src/analysis/health/diagnostics.ts +66 -18
  228. package/src/analysis/health/evidence-reason.ts +44 -0
  229. package/src/analysis/health/server-status.ts +41 -12
  230. package/src/analysis/search/pattern.ts +3 -3
  231. package/src/analysis/target/anchored-structural.ts +4 -1
  232. package/src/analysis/target/anchored.ts +3 -6
  233. package/src/analysis/target/symbol.ts +42 -48
  234. package/src/analysis/target/types.ts +4 -9
  235. package/src/analysis/workspace/cmake-parser.ts +207 -0
  236. package/src/analysis/workspace/cmake.ts +141 -0
  237. package/src/analysis/workspace/maven.ts +310 -0
  238. package/src/analysis/workspace/membership.ts +100 -26
  239. package/src/analysis/workspace/metadata.ts +6 -1
  240. package/src/analysis/workspace/observe.ts +6 -0
  241. package/src/analysis/workspace/types.ts +11 -3
  242. package/src/diagnostics/coverage.ts +49 -0
  243. package/src/diagnostics/evidence.ts +10 -2
  244. package/src/session/find-types.ts +8 -4
  245. package/src/session/find-workflow.ts +11 -16
  246. package/src/session/health-workflow.ts +6 -0
  247. package/src/session/input/common.ts +1 -1
  248. package/src/session/input/health-refactor.ts +48 -34
  249. package/src/session/input/workflows.ts +45 -46
  250. package/src/session/inspect/file-point.ts +2 -2
  251. package/src/session/inspect-types.ts +1 -1
  252. package/src/session/inspect-workflow.ts +3 -3
  253. package/src/session/orientation/collect.ts +42 -7
  254. package/src/session/orientation/context-facts.ts +3 -3
  255. package/src/session/orientation/context-sections.ts +13 -15
  256. package/src/session/orientation/facts.ts +5 -8
  257. package/src/session/orientation-workflow.ts +4 -19
  258. package/src/session/refactor-file-actions.ts +122 -0
  259. package/src/session/refactor-plan-pipeline.ts +152 -0
  260. package/src/session/refactor-plans.ts +18 -15
  261. package/src/session/refactor-types.ts +24 -12
  262. package/src/session/refactor-workflow.ts +68 -243
  263. package/src/session/target-workflow.ts +25 -18
  264. package/src/tool/code_find/execute.ts +6 -7
  265. package/src/tool/code_find/result.ts +5 -7
  266. package/src/tool/code_find/spec.ts +9 -16
  267. package/src/tool/code_find/tui.ts +12 -6
  268. package/src/tool/code_graph/display.ts +5 -6
  269. package/src/tool/code_graph/format.ts +8 -24
  270. package/src/tool/code_graph/result.ts +16 -75
  271. package/src/tool/code_graph/section.ts +21 -33
  272. package/src/tool/code_graph/spec.ts +6 -0
  273. package/src/tool/code_graph/tui.ts +10 -5
  274. package/src/tool/code_health/diagnostic-tui.ts +49 -0
  275. package/src/tool/code_health/guidance.ts +27 -0
  276. package/src/tool/code_health/markdown.ts +60 -8
  277. package/src/tool/code_health/result.ts +20 -9
  278. package/src/tool/code_health/spec.ts +6 -0
  279. package/src/tool/code_health/structured-schema.ts +18 -4
  280. package/src/tool/code_health/structured.ts +22 -18
  281. package/src/tool/code_health/tui.ts +33 -40
  282. package/src/tool/code_inspect/execute.ts +1 -1
  283. package/src/tool/code_inspect/markdown.ts +33 -6
  284. package/src/tool/code_inspect/result.ts +24 -19
  285. package/src/tool/code_inspect/spec.ts +14 -6
  286. package/src/tool/code_inspect/structured.ts +4 -21
  287. package/src/tool/code_inspect/tui.ts +2 -2
  288. package/src/tool/code_orientation/result.ts +53 -100
  289. package/src/tool/code_orientation/spec.ts +8 -0
  290. package/src/tool/code_orientation/structured-schema.ts +16 -12
  291. package/src/tool/code_orientation/structured-workspace.ts +13 -7
  292. package/src/tool/code_orientation/structured.ts +31 -39
  293. package/src/tool/code_orientation/workspace-format.ts +4 -10
  294. package/src/tool/code_orientation/workspace-instructions.ts +4 -5
  295. package/src/tool/code_orientation/workspace-observations.ts +2 -2
  296. package/src/tool/code_orientation/workspace-output.ts +16 -7
  297. package/src/tool/code_orientation/workspace-projects.ts +7 -10
  298. package/src/tool/code_orientation/workspace-sections.ts +13 -19
  299. package/src/tool/code_refactor_apply/result.ts +2 -1
  300. package/src/tool/code_refactor_apply/spec.ts +7 -0
  301. package/src/tool/code_refactor_plan/execute.ts +0 -2
  302. package/src/tool/code_refactor_plan/result.ts +23 -13
  303. package/src/tool/code_refactor_plan/spec.ts +8 -2
  304. package/src/tool/code_refactor_plan/structured.ts +59 -12
  305. package/src/tool/code_refactor_plan/tui.ts +14 -17
  306. package/src/tool/code_resolve/markdown.ts +5 -47
  307. package/src/tool/code_resolve/result.ts +43 -72
  308. package/src/tool/code_resolve/spec.ts +6 -0
  309. package/src/tool/infra/truncate.ts +2 -16
  310. package/src/tool/namespace.ts +14 -0
  311. package/src/tool/refactor-markdown.ts +55 -15
  312. package/src/tool/register.ts +3 -0
  313. package/src/tool/result/candidate-selection.ts +141 -0
  314. package/src/tool/result/display.ts +41 -45
  315. package/src/tool/result/errors.ts +1 -0
  316. package/src/tool/result/model-budget.ts +26 -1
  317. package/src/tool/result/refactor-preview.ts +118 -0
  318. package/src/tool/result/refactor-unavailable.ts +16 -0
  319. package/src/tool/result/refactor.ts +19 -10
  320. package/src/tool/result/structured.ts +2 -1
  321. package/src/tool/result/types.ts +9 -8
  322. package/src/tool/schemas.ts +76 -38
  323. package/src/tool/specs.ts +3 -0
  324. package/src/ui/footer.ts +2 -4
  325. package/src/ui/status-overlay.ts +1 -1
  326. package/src/ui/status-presentation.ts +4 -7
  327. package/src/ui/tui/candidate-selection.ts +40 -95
  328. package/src/ui/tui/common.ts +16 -70
  329. package/src/ui/tui/display.ts +6 -24
  330. package/src/tool/result/candidate-row.ts +0 -49
@@ -0,0 +1,907 @@
1
+ 'use strict';
2
+ ///@ts-check
3
+
4
+ import { getAllMatches, isExist, DANGEROUS_PROPERTY_NAMES, criticalProperties } from '../util.js';
5
+ import xmlNode from './xmlNode.js';
6
+ import DocTypeReader from './DocTypeReader.js';
7
+ import toNumber from "strnum";
8
+ import getIgnoreAttributesFn from "../ignoreAttributes.js";
9
+ import { Expression, Matcher } from 'path-expression-matcher';
10
+ import { ExpressionSet } from 'path-expression-matcher';
11
+ import { EntityDecoder, XML, CURRENCY, COMMON_HTML, ENTITY_ACTION } from '@nodable/entities';
12
+ import { isUnsafe, HTML as HTML_CONTEXT, XML as XML_CONTEXT } from "is-unsafe"
13
+
14
+
15
+ // const regx =
16
+ // '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
17
+ // .replace(/NAME/g, util.nameRegexp);
18
+
19
+ //const tagsRegx = new RegExp("<(\\/?[\\w:\\-\._]+)([^>]*)>(\\s*"+cdataRegx+")*([^<]+)?","g");
20
+ //const tagsRegx = new RegExp("<(\\/?)((\\w*:)?([\\w:\\-\._]+))([^>]*)>([^<]*)("+cdataRegx+"([^<]*))*([^<]+)?","g");
21
+
22
+ // Helper functions for attribute and namespace handling
23
+
24
+ /**
25
+ * Extract raw attributes (without prefix) from prefixed attribute map
26
+ * @param {object} prefixedAttrs - Attributes with prefix from buildAttributesMap
27
+ * @param {object} options - Parser options containing attributeNamePrefix
28
+ * @returns {object} Raw attributes for matcher
29
+ */
30
+ function extractRawAttributes(prefixedAttrs, options) {
31
+ if (!prefixedAttrs) return {};
32
+
33
+ // Handle attributesGroupName option
34
+ const attrs = options.attributesGroupName
35
+ ? prefixedAttrs[options.attributesGroupName]
36
+ : prefixedAttrs;
37
+
38
+ if (!attrs) return {};
39
+
40
+ const rawAttrs = {};
41
+ for (const key in attrs) {
42
+ // Remove the attribute prefix to get raw name
43
+ if (key.startsWith(options.attributeNamePrefix)) {
44
+ const rawName = key.substring(options.attributeNamePrefix.length);
45
+ rawAttrs[rawName] = attrs[key];
46
+ } else {
47
+ // Attribute without prefix (shouldn't normally happen, but be safe)
48
+ rawAttrs[key] = attrs[key];
49
+ }
50
+ }
51
+ return rawAttrs;
52
+ }
53
+
54
+ /**
55
+ * Extract namespace from raw tag name
56
+ * @param {string} rawTagName - Tag name possibly with namespace (e.g., "soap:Envelope")
57
+ * @returns {string|undefined} Namespace or undefined
58
+ */
59
+ function extractNamespace(rawTagName) {
60
+ if (!rawTagName || typeof rawTagName !== 'string') return undefined;
61
+
62
+ const colonIndex = rawTagName.indexOf(':');
63
+ if (colonIndex !== -1 && colonIndex > 0) {
64
+ const ns = rawTagName.substring(0, colonIndex);
65
+ // Don't treat xmlns as a namespace
66
+ if (ns !== 'xmlns') {
67
+ return ns;
68
+ }
69
+ }
70
+ return undefined;
71
+ }
72
+
73
+ export default class OrderedObjParser {
74
+ constructor(options, externalEntities) {
75
+ this.options = options;
76
+ this.currentNode = null;
77
+ this.tagsNodeStack = [];
78
+ this.parseXml = parseXml;
79
+ this.parseTextData = parseTextData;
80
+ this.resolveNameSpace = resolveNameSpace;
81
+ this.buildAttributesMap = buildAttributesMap;
82
+ this.isItStopNode = isItStopNode;
83
+ this.replaceEntitiesValue = replaceEntitiesValue;
84
+ this.readStopNodeData = readStopNodeData;
85
+ this.saveTextToParentTag = saveTextToParentTag;
86
+ this.addChild = addChild;
87
+ this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
88
+ this.entityExpansionCount = 0;
89
+ this.currentExpandedLength = 0;
90
+ this.doctypefound = false;
91
+ let namedEntities = { ...XML };
92
+ if (this.options.entityDecoder) {
93
+ this.entityDecoder = this.options.entityDecoder
94
+ } else {
95
+ if (typeof this.options.htmlEntities === "object") namedEntities = this.options.htmlEntities;
96
+ else if (this.options.htmlEntities === true) namedEntities = { ...COMMON_HTML, ...CURRENCY };
97
+ this.entityDecoder = new EntityDecoder({
98
+ namedEntities: { ...namedEntities, ...externalEntities },
99
+ numericAllowed: this.options.htmlEntities,
100
+ limit: {
101
+ maxTotalExpansions: this.options.processEntities.maxTotalExpansions,
102
+ maxExpandedLength: this.options.processEntities.maxExpandedLength,
103
+ applyLimitsTo: this.options.processEntities.appliesTo,
104
+ },
105
+ // onExternalEntity: (name, value) => isUnsafe(value) ? 'block' : 'allow',
106
+ onInputEntity: (name, value) =>
107
+ //TODO: VALID_CONTEXTS.HTML should be set only if this.options.htmlEntities
108
+ isUnsafe(value, [HTML_CONTEXT, XML_CONTEXT]) ? ENTITY_ACTION.BLOCK : ENTITY_ACTION.ALLOW,
109
+
110
+ //postCheck: resolved => resolved
111
+ });
112
+ }
113
+
114
+ // Initialize path matcher for path-expression-matcher
115
+ this.matcher = new Matcher();
116
+ this.readonlyMatcher = this.matcher.readOnly();
117
+
118
+ // Flag to track if current node is a stop node (optimization)
119
+ this.isCurrentNodeStopNode = false;
120
+
121
+ // Pre-compile stopNodes expressions
122
+ this.stopNodeExpressionsSet = new ExpressionSet();
123
+ const stopNodesOpts = this.options.stopNodes;
124
+ if (stopNodesOpts && stopNodesOpts.length > 0) {
125
+ for (let i = 0; i < stopNodesOpts.length; i++) {
126
+ const stopNodeExp = stopNodesOpts[i];
127
+ if (typeof stopNodeExp === 'string') {
128
+ // Convert string to Expression object
129
+ this.stopNodeExpressionsSet.add(new Expression(stopNodeExp));
130
+ } else if (stopNodeExp instanceof Expression) {
131
+ // Already an Expression object
132
+ this.stopNodeExpressionsSet.add(stopNodeExp);
133
+ }
134
+ }
135
+ this.stopNodeExpressionsSet.seal();
136
+ }
137
+ }
138
+
139
+ }
140
+
141
+
142
+ /**
143
+ * @param {string} val
144
+ * @param {string} tagName
145
+ * @param {string|Matcher} jPath - jPath string or Matcher instance based on options.jPath
146
+ * @param {boolean} dontTrim
147
+ * @param {boolean} hasAttributes
148
+ * @param {boolean} isLeafNode
149
+ * @param {boolean} escapeEntities
150
+ */
151
+ function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
152
+ const options = this.options;
153
+ if (val !== undefined) {
154
+ if (options.trimValues && !dontTrim) {
155
+ val = val.trim();
156
+ }
157
+ if (val.length > 0) {
158
+ if (!escapeEntities) val = this.replaceEntitiesValue(val, tagName, jPath);
159
+
160
+ // Pass jPath string or matcher based on options.jPath setting
161
+ const jPathOrMatcher = options.jPath ? jPath.toString() : jPath;
162
+ const newval = options.tagValueProcessor(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode);
163
+ if (newval === null || newval === undefined) {
164
+ //don't parse
165
+ return val;
166
+ } else if (typeof newval !== typeof val || newval !== val) {
167
+ //overwrite
168
+ return newval;
169
+ } else if (options.trimValues) {
170
+ return parseValue(val, options.parseTagValue, options.numberParseOptions);
171
+ } else {
172
+ const trimmedVal = val.trim();
173
+ if (trimmedVal === val) {
174
+ return parseValue(val, options.parseTagValue, options.numberParseOptions);
175
+ } else {
176
+ return val;
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ function resolveNameSpace(tagname) {
184
+ if (this.options.removeNSPrefix) {
185
+ const tags = tagname.split(':');
186
+ const prefix = tagname.charAt(0) === '/' ? '/' : '';
187
+ if (tags[0] === 'xmlns') {
188
+ return '';
189
+ }
190
+ if (tags.length === 2) {
191
+ tagname = prefix + tags[1];
192
+ }
193
+ }
194
+ return tagname;
195
+ }
196
+
197
+ //TODO: change regex to capture NS
198
+ //const attrsRegx = new RegExp("([\\w\\-\\.\\:]+)\\s*=\\s*(['\"])((.|\n)*?)\\2","gm");
199
+ const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
200
+
201
+ function buildAttributesMap(attrStr, jPath, tagName, force = false) {
202
+ const options = this.options;
203
+ if (force === true || (options.ignoreAttributes !== true && typeof attrStr === 'string')) {
204
+ // attrStr = attrStr.replace(/\r?\n/g, ' ');
205
+ //attrStr = attrStr || attrStr.trim();
206
+
207
+ const matches = getAllMatches(attrStr, attrsRegx);
208
+ const len = matches.length; //don't make it inline
209
+ const attrs = {};
210
+
211
+ // Pre-process values once: trim + entity replacement
212
+ // Reused in both matcher update and second pass
213
+ const processedVals = new Array(len);
214
+ let hasRawAttrs = false;
215
+ const rawAttrsForMatcher = {};
216
+
217
+ for (let i = 0; i < len; i++) {
218
+ const attrName = this.resolveNameSpace(matches[i][1]);
219
+ const oldVal = matches[i][4];
220
+
221
+ if (attrName.length && oldVal !== undefined) {
222
+ let val = oldVal;
223
+ if (options.trimValues) val = val.trim();
224
+ val = this.replaceEntitiesValue(val, tagName, this.readonlyMatcher);
225
+ processedVals[i] = val;
226
+
227
+ rawAttrsForMatcher[attrName] = val;
228
+ hasRawAttrs = true;
229
+ }
230
+ }
231
+
232
+ // Update matcher ONCE before second pass, if applicable
233
+ if (hasRawAttrs && typeof jPath === 'object' && jPath.updateCurrent) {
234
+ jPath.updateCurrent(rawAttrsForMatcher);
235
+ }
236
+
237
+ // Hoist toString() once — path doesn't change during attribute processing
238
+ const jPathStr = options.jPath ? jPath.toString() : this.readonlyMatcher;
239
+
240
+ // Second pass: apply processors, build final attrs
241
+ let hasAttrs = false;
242
+ for (let i = 0; i < len; i++) {
243
+ const attrName = this.resolveNameSpace(matches[i][1]);
244
+
245
+ if (this.ignoreAttributesFn(attrName, jPathStr)) continue;
246
+
247
+ let aName = options.attributeNamePrefix + attrName;
248
+
249
+ if (attrName.length) {
250
+ if (options.transformAttributeName) {
251
+ aName = options.transformAttributeName(aName);
252
+ }
253
+ aName = sanitizeName(aName, options);
254
+
255
+ if (matches[i][4] !== undefined) {
256
+ // Reuse already-processed value — no double entity replacement
257
+ const oldVal = processedVals[i];
258
+
259
+ const newVal = options.attributeValueProcessor(attrName, oldVal, jPathStr);
260
+ if (newVal === null || newVal === undefined) {
261
+ attrs[aName] = oldVal;
262
+ } else if (typeof newVal !== typeof oldVal || newVal !== oldVal) {
263
+ attrs[aName] = newVal;
264
+ } else {
265
+ attrs[aName] = parseValue(oldVal, options.parseAttributeValue, options.numberParseOptions);
266
+ }
267
+ hasAttrs = true;
268
+ } else if (options.allowBooleanAttributes) {
269
+ attrs[aName] = true;
270
+ hasAttrs = true;
271
+ }
272
+ }
273
+ }
274
+
275
+ if (!hasAttrs) return;
276
+
277
+ if (options.attributesGroupName && !options.preserveOrder) {
278
+ const attrCollection = {};
279
+ attrCollection[options.attributesGroupName] = attrs;
280
+ return attrCollection;
281
+ }
282
+ return attrs;
283
+ }
284
+ }
285
+ const parseXml = function (xmlData) {
286
+ const options = this.options;
287
+ const crlfPositions = options.captureMetaData ? [] : undefined;
288
+ xmlData = xmlData.replace(/\r\n?/g, options.captureMetaData ? (newline, index) => {
289
+ if (newline.length === 2) {
290
+ // Store the position after earlier CRLF pairs have been normalized.
291
+ crlfPositions.push(index - crlfPositions.length);
292
+ }
293
+ return "\n";
294
+ } : "\n");
295
+ const xmlObj = new xmlNode('!xml');
296
+ let currentNode = xmlObj;
297
+ let textData = "";
298
+
299
+ // Reset matcher for new document
300
+ this.matcher.reset();
301
+ this.entityDecoder.reset();
302
+
303
+ // Reset entity expansion counters for this document
304
+ this.entityExpansionCount = 0;
305
+ this.currentExpandedLength = 0;
306
+ this.doctypefound = false;
307
+ const docTypeReader = new DocTypeReader(options.processEntities);
308
+ const xmlLen = xmlData.length;
309
+ for (let i = 0; i < xmlLen; i++) {//for each char in XML data
310
+ const ch = xmlData[i];
311
+ if (ch === '<') {
312
+ // const nextIndex = i+1;
313
+ // const _2ndChar = xmlData[nextIndex];
314
+ const c1 = xmlData.charCodeAt(i + 1);
315
+ if (c1 === 47) {//Closing Tag '/'
316
+ const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.")
317
+ let tagName = xmlData.substring(i + 2, closeIndex).trim();
318
+
319
+ if (options.removeNSPrefix) {
320
+ const colonIndex = tagName.indexOf(":");
321
+ if (colonIndex !== -1) {
322
+ tagName = tagName.substr(colonIndex + 1);
323
+ }
324
+ }
325
+
326
+ tagName = transformTagName(options.transformTagName, tagName, "", options).tagName;
327
+
328
+ if (currentNode) {
329
+ textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
330
+ }
331
+
332
+ //check if last tag of nested tag was unpaired tag
333
+ const lastTagName = this.matcher.getCurrentTag();
334
+ if (tagName && options.unpairedTagsSet.has(tagName)) {
335
+ throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
336
+ }
337
+ if (lastTagName && options.unpairedTagsSet.has(lastTagName)) {
338
+ // Pop the unpaired tag
339
+ this.matcher.pop();
340
+ this.tagsNodeStack.pop();
341
+ }
342
+ // Pop the closing tag
343
+ this.matcher.pop();
344
+ this.isCurrentNodeStopNode = false; // Reset flag when closing tag
345
+
346
+ //a closing tag with no matching opening tag leaves the stack empty
347
+ currentNode = this.tagsNodeStack.pop() || xmlObj;//avoid recursion, set the parent tag scope
348
+
349
+ if (options.captureMetaData && currentNode) {
350
+ currentNode.addEndIndex(getOriginalIndex(closeIndex + 1, crlfPositions));
351
+ }
352
+ textData = "";
353
+ i = closeIndex;
354
+ } else if (c1 === 63) { //'?'
355
+
356
+ let tagData = readTagExp(xmlData, i, false, "?>");
357
+ if (!tagData) throw new Error("Pi Tag is not closed.");
358
+
359
+ textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
360
+ const attsMap = this.buildAttributesMap(tagData.tagExp, this.matcher, tagData.tagName, true);
361
+ if (attsMap) {
362
+ const ver = attsMap[this.options.attributeNamePrefix + "version"];
363
+ this.entityDecoder.setXmlVersion(Number(ver) || 1.0);
364
+ docTypeReader.setXmlVersion(Number(ver) || 1.0);
365
+ }
366
+ if ((options.ignoreDeclaration && tagData.tagName === "?xml") || options.ignorePiTags) {
367
+ //do nothing
368
+ } else {
369
+
370
+ const childNode = new xmlNode(tagData.tagName);
371
+ childNode.add(options.textNodeName, "");
372
+
373
+ if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent && options.ignoreAttributes !== true) {
374
+ childNode[":@"] = attsMap
375
+ }
376
+ const startIndex = options.captureMetaData ? getOriginalIndex(i, crlfPositions) : i;
377
+ this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
378
+
379
+ if (options.captureMetaData) {
380
+ // closeIndex points at '?' of the closing '?>'
381
+ currentNode.addEndIndex(getOriginalIndex(tagData.closeIndex + 2, crlfPositions));
382
+ }
383
+ }
384
+
385
+
386
+ i = tagData.closeIndex + 1;
387
+ } else if (c1 === 33
388
+ && xmlData.charCodeAt(i + 2) === 45
389
+ && xmlData.charCodeAt(i + 3) === 45) { //'!--'
390
+ const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.")
391
+ if (options.commentPropName) {
392
+ const comment = xmlData.substring(i + 4, endIndex - 2);
393
+
394
+ textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
395
+
396
+ currentNode.add(options.commentPropName, [{ [options.textNodeName]: comment }]);
397
+ }
398
+ i = endIndex;
399
+ } else if (c1 === 33
400
+ && xmlData.charCodeAt(i + 2) === 68) { //'!D'
401
+ if (this.doctypefound) throw new Error("Multiple DOCTYPE declarations found.");
402
+ this.doctypefound = true;
403
+ const result = docTypeReader.readDocType(xmlData, i);
404
+ this.entityDecoder.addInputEntities(result.entities);
405
+ i = result.i;
406
+ } else if (c1 === 33
407
+ && xmlData.charCodeAt(i + 2) === 91) { // '!['
408
+ const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
409
+ const tagExp = xmlData.substring(i + 9, closeIndex);
410
+
411
+ textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
412
+
413
+ let val = this.parseTextData(tagExp, currentNode.tagname, this.readonlyMatcher, true, false, true, true);
414
+ if (val == undefined) val = "";
415
+
416
+ //cdata should be set even if it is 0 length string
417
+ if (options.cdataPropName) {
418
+ currentNode.add(options.cdataPropName, [{ [options.textNodeName]: tagExp }]);
419
+ } else {
420
+ currentNode.add(options.textNodeName, val);
421
+ }
422
+
423
+ i = closeIndex + 2;
424
+ } else {//Opening tag
425
+ let result = readTagExp(xmlData, i, options.removeNSPrefix);
426
+
427
+ // Safety check: readTagExp can return undefined
428
+ if (!result) {
429
+ // Log context for debugging
430
+ const context = xmlData.substring(Math.max(0, i - 50), Math.min(xmlLen, i + 50));
431
+ throw new Error(`readTagExp returned undefined at position ${i}. Context: "${context}"`);
432
+ }
433
+
434
+ let tagName = result.tagName;
435
+ const rawTagName = result.rawTagName;
436
+ let tagExp = result.tagExp;
437
+ let attrExpPresent = result.attrExpPresent;
438
+ let closeIndex = result.closeIndex;
439
+
440
+ ({ tagName, tagExp } = transformTagName(options.transformTagName, tagName, tagExp, options));
441
+
442
+ if (options.strictReservedNames &&
443
+ (tagName === options.commentPropName
444
+ || tagName === options.cdataPropName
445
+ || tagName === options.textNodeName
446
+ || tagName === options.attributesGroupName
447
+ )) {
448
+ throw new Error(`Invalid tag name: ${tagName}`);
449
+ }
450
+
451
+ //save text as child node
452
+ if (currentNode && textData) {
453
+ if (currentNode.tagname !== '!xml') {
454
+ //when nested tag is found
455
+ textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher, false);
456
+ }
457
+ }
458
+
459
+ //check if last tag was unpaired tag
460
+ const lastTag = currentNode;
461
+ if (lastTag && options.unpairedTagsSet.has(lastTag.tagname)) {
462
+ currentNode = this.tagsNodeStack.pop();
463
+ this.matcher.pop();
464
+ }
465
+
466
+ // Clean up self-closing syntax BEFORE processing attributes
467
+ // This is where tagExp gets the trailing / removed
468
+ let isSelfClosing = false;
469
+ if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
470
+ isSelfClosing = true;
471
+ if (tagName[tagName.length - 1] === "/") {
472
+ tagName = tagName.substr(0, tagName.length - 1);
473
+ tagExp = tagName;
474
+ } else {
475
+ tagExp = tagExp.substr(0, tagExp.length - 1);
476
+ }
477
+
478
+ // Re-check attrExpPresent after cleaning
479
+ attrExpPresent = (tagName !== tagExp);
480
+ }
481
+
482
+ // Now process attributes with CLEAN tagExp (no trailing /)
483
+ let prefixedAttrs = null;
484
+ let rawAttrs = {};
485
+ let namespace = undefined;
486
+
487
+ // Extract namespace from rawTagName
488
+ namespace = extractNamespace(rawTagName);
489
+
490
+ // Push tag to matcher FIRST (with empty attrs for now) so callbacks see correct path
491
+ if (tagName !== xmlObj.tagname) {
492
+ this.matcher.push(tagName, {}, namespace);
493
+ }
494
+
495
+ // Now build attributes - callbacks will see correct matcher state
496
+ if (tagName !== tagExp && attrExpPresent) {
497
+ // Build attributes (returns prefixed attributes for the tree)
498
+ // Note: buildAttributesMap now internally updates the matcher with raw attributes
499
+ prefixedAttrs = this.buildAttributesMap(tagExp, this.matcher, tagName);
500
+
501
+ if (prefixedAttrs) {
502
+ // Extract raw attributes (without prefix) for our use
503
+ //TODO: seems a performance overhead
504
+ rawAttrs = extractRawAttributes(prefixedAttrs, options);
505
+ }
506
+ }
507
+
508
+ // Now check if this is a stop node (after attributes are set)
509
+ if (tagName !== xmlObj.tagname) {
510
+ this.isCurrentNodeStopNode = this.isItStopNode();
511
+ }
512
+
513
+ const startIndex = options.captureMetaData ? getOriginalIndex(i, crlfPositions) : i;
514
+ if (this.isCurrentNodeStopNode) {
515
+ let tagContent = "";
516
+
517
+ // For self-closing tags, content is empty
518
+ if (isSelfClosing) {
519
+ i = result.closeIndex;
520
+ }
521
+ //unpaired tag
522
+ else if (options.unpairedTagsSet.has(tagName)) {
523
+ i = result.closeIndex;
524
+ }
525
+ //normal tag
526
+ else {
527
+ //read until closing tag is found
528
+ const result = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
529
+ if (!result) throw new Error(`Unexpected end of ${rawTagName}`);
530
+ i = result.i;
531
+ tagContent = result.tagContent;
532
+ }
533
+
534
+ const childNode = new xmlNode(tagName);
535
+
536
+ if (prefixedAttrs) {
537
+ childNode[":@"] = prefixedAttrs;
538
+ }
539
+
540
+ // For stop nodes, store raw content as-is without any processing
541
+ childNode.add(options.textNodeName, tagContent);
542
+
543
+ this.matcher.pop(); // Pop the stop node tag
544
+ this.isCurrentNodeStopNode = false; // Reset flag
545
+
546
+ this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
547
+
548
+ if (options.captureMetaData) {
549
+ currentNode.addEndIndex(getOriginalIndex(i + 1, crlfPositions));
550
+ }
551
+ } else {
552
+ //selfClosing tag
553
+ if (isSelfClosing) {
554
+ ({ tagName, tagExp } = transformTagName(options.transformTagName, tagName, tagExp, options));
555
+
556
+ const childNode = new xmlNode(tagName);
557
+ if (prefixedAttrs) {
558
+ childNode[":@"] = prefixedAttrs;
559
+ }
560
+ this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
561
+
562
+ if (options.captureMetaData) {
563
+ currentNode.addEndIndex(getOriginalIndex(closeIndex + 1, crlfPositions));
564
+ }
565
+ this.matcher.pop(); // Pop self-closing tag
566
+ this.isCurrentNodeStopNode = false; // Reset flag
567
+ }
568
+ else if (options.unpairedTagsSet.has(tagName)) {//unpaired tag
569
+ const childNode = new xmlNode(tagName);
570
+ if (prefixedAttrs) {
571
+ childNode[":@"] = prefixedAttrs;
572
+ }
573
+ this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
574
+
575
+ if (options.captureMetaData) {
576
+ currentNode.addEndIndex(getOriginalIndex(result.closeIndex + 1, crlfPositions));
577
+ }
578
+ this.matcher.pop(); // Pop unpaired tag
579
+ this.isCurrentNodeStopNode = false; // Reset flag
580
+ i = result.closeIndex;
581
+ // Continue to next iteration without changing currentNode
582
+ continue;
583
+ }
584
+ //opening tag
585
+ else {
586
+ const childNode = new xmlNode(tagName);
587
+ if (this.tagsNodeStack.length > options.maxNestedTags) {
588
+ throw new Error("Maximum nested tags exceeded");
589
+ }
590
+ this.tagsNodeStack.push(currentNode);
591
+
592
+ if (prefixedAttrs) {
593
+ childNode[":@"] = prefixedAttrs;
594
+ }
595
+ this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
596
+ currentNode = childNode;
597
+ }
598
+ textData = "";
599
+ i = closeIndex;
600
+ }
601
+ }
602
+ } else {
603
+ textData += xmlData[i];
604
+ }
605
+ }
606
+ return xmlObj.child;
607
+ }
608
+
609
+ function getOriginalIndex(index, crlfPositions) {
610
+ let low = 0;
611
+ let high = crlfPositions.length;
612
+ while (low < high) {
613
+ const middle = Math.floor((low + high) / 2);
614
+ if (crlfPositions[middle] < index) low = middle + 1;
615
+ else high = middle;
616
+ }
617
+ return index + low;
618
+ }
619
+
620
+ function addChild(currentNode, childNode, matcher, startIndex) {
621
+ // unset startIndex if not requested
622
+ if (!this.options.captureMetaData) startIndex = undefined;
623
+
624
+ // Pass jPath string or matcher based on options.jPath setting
625
+ const jPathOrMatcher = this.options.jPath ? matcher.toString() : matcher;
626
+ const result = this.options.updateTag(childNode.tagname, jPathOrMatcher, childNode[":@"])
627
+ if (result === false) {
628
+ //do nothing
629
+ } else if (typeof result === "string") {
630
+ childNode.tagname = result
631
+ currentNode.addChild(childNode, startIndex);
632
+ } else {
633
+ currentNode.addChild(childNode, startIndex);
634
+ }
635
+ }
636
+
637
+ /**
638
+ * @param {object} val - Entity object with regex and val properties
639
+ * @param {string} tagName - Tag name
640
+ * @param {string|Matcher} jPath - jPath string or Matcher instance based on options.jPath
641
+ */
642
+ function replaceEntitiesValue(val, tagName, jPath) {
643
+ const entityConfig = this.options.processEntities;
644
+
645
+ if (!entityConfig || !entityConfig.enabled) {
646
+ return val;
647
+ }
648
+
649
+ // Check if tag is allowed to contain entities
650
+ if (entityConfig.allowedTags) {
651
+ const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
652
+ const allowed = Array.isArray(entityConfig.allowedTags)
653
+ ? entityConfig.allowedTags.includes(tagName)
654
+ : entityConfig.allowedTags(tagName, jPathOrMatcher);
655
+
656
+ if (!allowed) {
657
+ return val;
658
+ }
659
+ }
660
+
661
+ // Apply custom tag filter if provided
662
+ if (entityConfig.tagFilter) {
663
+ const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
664
+ if (!entityConfig.tagFilter(tagName, jPathOrMatcher)) {
665
+ return val; // Skip based on custom filter
666
+ }
667
+ }
668
+
669
+ return this.entityDecoder.decode(val);
670
+ }
671
+
672
+
673
+ function saveTextToParentTag(textData, parentNode, matcher, isLeafNode) {
674
+ if (textData) { //store previously collected data as textNode
675
+ if (isLeafNode === undefined) isLeafNode = parentNode.child.length === 0
676
+
677
+ textData = this.parseTextData(textData,
678
+ parentNode.tagname,
679
+ matcher,
680
+ false,
681
+ parentNode[":@"] ? Object.keys(parentNode[":@"]).length !== 0 : false,
682
+ isLeafNode);
683
+
684
+ if (textData !== undefined && textData !== "")
685
+ parentNode.add(this.options.textNodeName, textData);
686
+ textData = "";
687
+ }
688
+ return textData;
689
+ }
690
+
691
+ /**
692
+ * @param {Array<Expression>} stopNodeExpressions - Array of compiled Expression objects
693
+ * @param {Matcher} matcher - Current path matcher
694
+ */
695
+ function isItStopNode() {
696
+ if (this.stopNodeExpressionsSet.size === 0) return false;
697
+
698
+ return this.matcher.matchesAny(this.stopNodeExpressionsSet);
699
+ }
700
+
701
+ /**
702
+ * Returns the tag Expression and where it is ending handling single-double quotes situation
703
+ * @param {string} xmlData
704
+ * @param {number} i starting index
705
+ * @returns
706
+ */
707
+ function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
708
+ //TODO: ignore boolean attributes in tag expression
709
+ //TODO: if ignore attributes, dont read full attribute expression but the end. But read for xml declaration
710
+ let attrBoundary = 0;
711
+ const len = xmlData.length;
712
+ const closeCode0 = closingChar.charCodeAt(0);
713
+ const closeCode1 = closingChar.length > 1 ? closingChar.charCodeAt(1) : -1;
714
+
715
+ let result = '';
716
+ let segmentStart = i;
717
+
718
+ for (let index = i; index < len; index++) {
719
+ const code = xmlData.charCodeAt(index);
720
+
721
+ if (attrBoundary) {
722
+ if (code === attrBoundary) attrBoundary = 0;
723
+ } else if (code === 34 || code === 39) { // " or '
724
+ attrBoundary = code;
725
+ } else if (code === closeCode0) {
726
+ if (closeCode1 !== -1) {
727
+ if (xmlData.charCodeAt(index + 1) === closeCode1) {
728
+ result += xmlData.substring(segmentStart, index);
729
+ return { data: result, index };
730
+ }
731
+ } else {
732
+ result += xmlData.substring(segmentStart, index);
733
+ return { data: result, index };
734
+ }
735
+ } else if (code === 9 && !attrBoundary) { // \t - only replace with space outside attribute values
736
+ // Flush accumulated segment, add space, start new segment
737
+ result += xmlData.substring(segmentStart, index) + ' ';
738
+ segmentStart = index + 1;
739
+ }
740
+ }
741
+ }
742
+
743
+ function findClosingIndex(xmlData, str, i, errMsg) {
744
+ const closingIndex = xmlData.indexOf(str, i);
745
+ if (closingIndex === -1) {
746
+ throw new Error(errMsg)
747
+ } else {
748
+ return closingIndex + str.length - 1;
749
+ }
750
+ }
751
+
752
+ function findClosingChar(xmlData, char, i, errMsg) {
753
+ const closingIndex = xmlData.indexOf(char, i);
754
+ if (closingIndex === -1) throw new Error(errMsg);
755
+ return closingIndex; // no offset needed
756
+ }
757
+
758
+ function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
759
+ const result = tagExpWithClosingIndex(xmlData, i + 1, closingChar);
760
+ if (!result) return;
761
+ let tagExp = result.data;
762
+ const closeIndex = result.index;
763
+ const separatorIndex = tagExp.search(/\s/);
764
+ let tagName = tagExp;
765
+ let attrExpPresent = true;
766
+ if (separatorIndex !== -1) {//separate tag name and attributes expression
767
+ tagName = tagExp.substring(0, separatorIndex);
768
+ tagExp = tagExp.substring(separatorIndex + 1).trimStart();
769
+ }
770
+
771
+ const rawTagName = tagName;
772
+ if (removeNSPrefix) {
773
+ const colonIndex = tagName.indexOf(":");
774
+ if (colonIndex !== -1) {
775
+ tagName = tagName.substr(colonIndex + 1);
776
+ attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
777
+ }
778
+ }
779
+
780
+ return {
781
+ tagName: tagName,
782
+ tagExp: tagExp,
783
+ closeIndex: closeIndex,
784
+ attrExpPresent: attrExpPresent,
785
+ rawTagName: rawTagName,
786
+ }
787
+ }
788
+ /**
789
+ * find paired tag for a stop node
790
+ * @param {string} xmlData
791
+ * @param {string} tagName
792
+ * @param {number} i
793
+ */
794
+ function readStopNodeData(xmlData, tagName, i) {
795
+ const startIndex = i;
796
+ // Starting at 1 since we already have an open tag
797
+ let openTagCount = 1;
798
+ let lenient = false; // set once a quote-aware tag scan fails
799
+ let nextGt = -1; // cached index of the next '>'
800
+
801
+ const xmllen = xmlData.length;
802
+ for (; i < xmllen; i++) {
803
+ if (xmlData[i] === "<") {
804
+ const c1 = xmlData.charCodeAt(i + 1);
805
+ if (c1 === 47) {//close tag '/'
806
+ const closeIndex = findClosingChar(xmlData, ">", i, `${tagName} is not closed`);
807
+ let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
808
+ if (closeTagName === tagName) {
809
+ openTagCount--;
810
+ if (openTagCount === 0) {
811
+ return {
812
+ tagContent: xmlData.substring(startIndex, i),
813
+ i: closeIndex
814
+ }
815
+ }
816
+ }
817
+ i = closeIndex;
818
+ } else if (c1 === 63) { //?
819
+ const closeIndex = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed.")
820
+ i = closeIndex;
821
+ } else if (c1 === 33
822
+ && xmlData.charCodeAt(i + 2) === 45
823
+ && xmlData.charCodeAt(i + 3) === 45) { // '!--'
824
+ const closeIndex = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed.")
825
+ i = closeIndex;
826
+ } else if (c1 === 33
827
+ && xmlData.charCodeAt(i + 2) === 91) { // '!['
828
+ const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
829
+ i = closeIndex;
830
+ } else {
831
+ const tagData = lenient ? undefined : readTagExp(xmlData, i, false);
832
+
833
+ if (tagData) {
834
+ const openTagName = tagData.tagName;
835
+ if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") {
836
+ openTagCount++;
837
+ }
838
+ i = tagData.closeIndex;
839
+ } else {
840
+ // no closing '>'. use lenient approach to find '<' instead of readTagExp, to avoid repeated rescans.
841
+ lenient = true;
842
+ if (nextGt < i) {
843
+ nextGt = xmlData.indexOf(">", i);
844
+ if (nextGt === -1) return; // no '>' left, so no closing tag can follow
845
+ }
846
+ const nextLt = xmlData.indexOf("<", i + 1);
847
+ if (nextLt === -1 || nextLt > nextGt) { // looks like a real tag
848
+ const exp = xmlData.substring(i + 1, nextGt);
849
+ const sep = exp.search(/\s/);
850
+ const name = sep === -1 ? exp : exp.substring(0, sep);
851
+ if (name === tagName && exp[exp.length - 1] !== "/") openTagCount++;
852
+ i = nextGt;
853
+ } // else: treat this '<' as plain text
854
+ }
855
+ }
856
+ }
857
+ }//end for loop
858
+ }
859
+
860
+ function parseValue(val, shouldParse, options) {
861
+ if (shouldParse && typeof val === 'string') {
862
+ //console.log(options)
863
+ const newval = val.trim();
864
+ if (newval === 'true') return true;
865
+ else if (newval === 'false') return false;
866
+ else return toNumber(val, options);
867
+ } else {
868
+ if (isExist(val)) {
869
+ return val;
870
+ } else {
871
+ return '';
872
+ }
873
+ }
874
+ }
875
+
876
+ function fromCodePoint(str, base, prefix) {
877
+ const codePoint = Number.parseInt(str, base);
878
+
879
+ if (codePoint >= 0 && codePoint <= 0x10FFFF) {
880
+ return String.fromCodePoint(codePoint);
881
+ } else {
882
+ return prefix + str + ";";
883
+ }
884
+ }
885
+
886
+ function transformTagName(fn, tagName, tagExp, options) {
887
+ if (fn) {
888
+ const newTagName = fn(tagName);
889
+ if (tagExp === tagName) {
890
+ tagExp = newTagName
891
+ }
892
+ tagName = newTagName;
893
+ }
894
+ tagName = sanitizeName(tagName, options);
895
+ return { tagName, tagExp };
896
+ }
897
+
898
+
899
+
900
+ function sanitizeName(name, options) {
901
+ if (criticalProperties.includes(name)) {
902
+ throw new Error(`[SECURITY] Invalid name: "${name}" is a reserved JavaScript keyword that could cause prototype pollution`);
903
+ } else if (DANGEROUS_PROPERTY_NAMES.includes(name)) {
904
+ return options.onDangerousProperty(name);
905
+ }
906
+ return name;
907
+ }