@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
@@ -38,6 +38,7 @@ import {
38
38
  } from "./client-diagnostic-request.ts";
39
39
  import { DiagnosticObserver } from "./client-diagnostic-timing.ts";
40
40
  import { DiagnosticWaitRegistry } from "./client-diagnostic-waiters.ts";
41
+ import { type DiskStamp, statDiskStampSync } from "./client-disk-stamp.ts";
41
42
  import {
42
43
  type ClientDiagnosticSnapshot,
43
44
  type DiagnosticEntry,
@@ -136,18 +137,36 @@ export class ClientDiagnostics {
136
137
  return this.#inputAdmission.request(run, control, uri);
137
138
  }
138
139
 
139
- /** Read content only after admission; tracked-document changes never wait. */
140
- async openDocument(
140
+ /**
141
+ * Read content only after admission; tracked-document changes never wait.
142
+ *
143
+ * `readContent` reads the file from disk. The disk stamp taken directly
144
+ * before that read is recorded when the document then holds that content.
145
+ */
146
+ openDocument(
141
147
  filePath: string,
142
148
  readContent: () => string,
143
149
  control?: CodeRequestControl,
144
150
  protectInputs = false,
151
+ ): Promise<void> {
152
+ return this.#openDocument(filePath, readContent, control, { protectInputs, readsDisk: true });
153
+ }
154
+
155
+ async #openDocument(
156
+ filePath: string,
157
+ readContent: () => string,
158
+ control: CodeRequestControl | undefined,
159
+ { protectInputs, readsDisk }: { readonly protectInputs: boolean; readonly readsDisk: boolean },
145
160
  ): Promise<void> {
146
161
  throwIfCodeRequestInterrupted(control);
147
162
  const open = () => {
148
163
  throwIfCodeRequestInterrupted(control);
149
164
  if (!this.host.isOperational()) throw new Error("LSP client is not running.");
150
- this.didOpen(filePath, readContent());
165
+ // Stat inside the admitted closure, directly before the read.
166
+ const stamp = readsDisk ? statDiskStampSync(filePath) : undefined;
167
+ const content = readContent();
168
+ this.didOpen(filePath, content);
169
+ this.#recordDiskStampIfCurrent(fileToUri(filePath), content, stamp);
151
170
  };
152
171
  if (this.#openDocs.has(fileToUri(filePath))) {
153
172
  open();
@@ -237,22 +256,17 @@ export class ClientDiagnostics {
237
256
  for (const update of updates) {
238
257
  const document = this.#openDocs.get(update.document.uri);
239
258
  if (!document) throw new Error("Semantic input changed while synchronization was running.");
240
- this.#synchronizeTrackedDocument(
241
- update.document.uri,
242
- update.document.filePath,
243
- update.content,
244
- document,
245
- );
259
+ this.#synchronizeTrackedDocument(update.document, update.content, document);
246
260
  this.#failedUris.delete(update.document.uri);
247
261
  }
248
262
  }
249
263
 
250
264
  /** Apply one tracked-document change with the shared client state. */
251
265
  #synchronizeTrackedDocument(
252
- uri: string,
253
- filePath: string,
266
+ { uri, filePath }: { readonly uri: string; readonly filePath: string },
254
267
  content: string,
255
268
  document: OpenDocumentState,
269
+ options: { fullText?: boolean } = {},
256
270
  ): void {
257
271
  synchronizeTrackedDocument({
258
272
  uri,
@@ -267,6 +281,7 @@ export class ClientDiagnostics {
267
281
  markUnversionedSyncMoment: () => this.#unversionedPushSyncMoments.set(uri, Date.now()),
268
282
  clearFailedFile: () => this.#failedUris.delete(uri),
269
283
  open: () => this.didOpen(filePath, content),
284
+ ...(options.fullText ? { fullText: true } : {}),
270
285
  });
271
286
  }
272
287
 
@@ -278,6 +293,13 @@ export class ClientDiagnostics {
278
293
  this.#inputBarrier.forgetDocumentContent(uri);
279
294
  }
280
295
 
296
+ /** Record a pre-read stamp when the open document now holds exactly that read. */
297
+ #recordDiskStampIfCurrent(uri: string, content: string, stamp: DiskStamp | undefined): void {
298
+ if (!stamp) return;
299
+ if (this.#openDocs.get(uri)?.contentFingerprint !== fingerprintDocumentContent(content)) return;
300
+ this.#inputBarrier.recordDiskStamp(uri, stamp);
301
+ }
302
+
281
303
  async #ensureExplicitDocumentContent(
282
304
  filePath: string,
283
305
  content: string,
@@ -289,10 +311,12 @@ export class ClientDiagnostics {
289
311
  if (!document) {
290
312
  // A manager read can predate admission. Re-read disk after the wait;
291
313
  // explicit authoritative content retains its existing override semantics.
292
- await this.openDocument(
314
+ await this.#openDocument(
293
315
  filePath,
294
316
  () => (contentIsAuthoritative ? content : readFileSync(filePath, "utf-8")),
295
317
  control,
318
+ // Authoritative content is not a disk read and must not record a stamp.
319
+ { protectInputs: false, readsDisk: !contentIsAuthoritative },
296
320
  );
297
321
  return;
298
322
  }
@@ -394,7 +418,27 @@ export class ClientDiagnostics {
394
418
  const nextFingerprint = fingerprintDocumentContent(content);
395
419
  if (doc.contentFingerprint === nextFingerprint) return;
396
420
  this.#advanceInputRevision();
397
- this.#synchronizeTrackedDocument(uri, filePath, content, doc);
421
+ this.#synchronizeTrackedDocument({ uri, filePath }, content, doc);
422
+ }
423
+
424
+ /**
425
+ * Re-send an open document's tracked content under a new version, even when
426
+ * it is unchanged. The tracked content matches disk: semantic requests
427
+ * synchronize open documents with disk before they run. Used after a server ran a command whose pushed
428
+ * edit was refused, so the server's model matches the client again.
429
+ * Returns the versions before and after, or null when the document is not open.
430
+ */
431
+ resynchronizeOpenDocument(filePath: string): { from: number; to: number } | null {
432
+ if (!this.host.isOperational()) return null;
433
+ const uri = fileToUri(filePath);
434
+ const doc = this.#openDocs.get(uri);
435
+ if (!doc) return null;
436
+ const from = doc.version;
437
+ this.#advanceInputRevision();
438
+ // Full text: the server may have changed its own copy, so a range computed
439
+ // from the client's content could no longer cover the whole document.
440
+ this.#synchronizeTrackedDocument({ uri, filePath }, doc.content, doc, { fullText: true });
441
+ return { from, to: doc.version };
398
442
  }
399
443
 
400
444
  /** Send a save after a disk change that the input barrier observed. */
@@ -418,6 +462,7 @@ export class ClientDiagnostics {
418
462
  if (!document) return;
419
463
 
420
464
  let content: string;
465
+ const stamp = statDiskStampSync(filePath);
421
466
  try {
422
467
  content = readFileSync(filePath, "utf-8");
423
468
  } catch {
@@ -427,6 +472,7 @@ export class ClientDiagnostics {
427
472
  if (document.contentFingerprint !== fingerprintDocumentContent(content)) {
428
473
  this.didChange(filePath, content);
429
474
  }
475
+ this.#recordDiskStampIfCurrent(uri, content, stamp);
430
476
  if (diskChanged) this.#noteExternalDiskChange(filePath, content);
431
477
  }
432
478
 
@@ -450,6 +496,10 @@ export class ClientDiagnostics {
450
496
  if (wasOpen && this.host.isOperational()) {
451
497
  sendDidCloseNotification(this.host, uri);
452
498
  }
499
+ // An intentional close of an existing file is not a removal.
500
+ if (hadState && getDiagnosticFileState(filePath) === "removed") {
501
+ this.host.onTrackedFileRemoved?.(filePath);
502
+ }
453
503
  }
454
504
 
455
505
  pruneMissingFiles(): string[] {
@@ -474,6 +524,7 @@ export class ClientDiagnostics {
474
524
  clearTrackedDocumentState(this.#openDocs, this.#diagnosticStore, this.#waiters, uri);
475
525
  removedFiles.push(filePath);
476
526
  if (wasOpen && this.host.isOperational()) sendDidCloseNotification(this.host, uri);
527
+ this.host.onTrackedFileRemoved?.(filePath);
477
528
  }
478
529
 
479
530
  return removedFiles;
@@ -490,6 +541,9 @@ export class ClientDiagnostics {
490
541
  getOpenDocumentVersion(filePath: string): number | null {
491
542
  return this.#openDocs.get(fileToUri(filePath))?.version ?? null;
492
543
  }
544
+ getOpenDocumentContent(filePath: string): string | null {
545
+ return this.#openDocs.get(fileToUri(filePath))?.content ?? null;
546
+ }
493
547
  getDiagnostics(filePath: string): Diagnostic[] {
494
548
  return this.#diagnosticStore.get(fileToUri(filePath))?.diagnostics ?? [];
495
549
  }
@@ -499,6 +553,7 @@ export class ClientDiagnostics {
499
553
  openDocuments: this.#openDocs,
500
554
  failedDocuments: this.#failedUris,
501
555
  evidenceRevision: this.#evidenceRevision,
556
+ observedDiskStamp: (uri) => this.#inputBarrier.getObservedDiskStamp(uri),
502
557
  });
503
558
  }
504
559
  getAllDiagnostics(): DiagnosticEntry[] {
@@ -626,6 +681,7 @@ export class ClientDiagnostics {
626
681
  nextSynchronizationId: () => ++this.#nextSynchronizationId,
627
682
  noteInputContentChange: () => this.#noteInputContentChange(),
628
683
  observeDiskContent: (uri, content) => this.#inputBarrier.observeDiskContent(uri, content),
684
+ recordDiskStamp: (uri, content, stamp) => this.#recordDiskStampIfCurrent(uri, content, stamp),
629
685
  noteExternalDiskChange: (uri, content) =>
630
686
  this.#noteExternalDiskChange(uriToFile(uri), content),
631
687
  invalidateEvidence: (uri) => {
@@ -647,6 +703,8 @@ export class ClientDiagnostics {
647
703
  this.#unversionedPushSyncMoments.delete(uri);
648
704
  this.#closedVersionedBarrier.add(uri);
649
705
  clearTrackedDocumentState(this.#openDocs, this.#diagnosticStore, this.#waiters, uri);
706
+ // Resynchronization clears only documents whose files were removed.
707
+ this.host.onTrackedFileRemoved?.(uriToFile(uri));
650
708
  },
651
709
  markUnversionedSyncMoment: (uri) => {
652
710
  this.#cancelDiagnosticRequest(uri);
@@ -0,0 +1,60 @@
1
+ import { statSync } from "node:fs";
2
+
3
+ /**
4
+ * File metadata that identifies one observed on-disk state of a document.
5
+ *
6
+ * A stamp can only withdraw diagnostic confirmation: a different stamp means
7
+ * the file may have changed since its content was last read. Only a content
8
+ * read restores confirmation. `ctimeNs` catches tools that restore mtime
9
+ * (`cp -p`, `rsync -t`, `touch -r`, tar); `ino` catches atomic replace.
10
+ * A same-size rewrite within one timestamp tick is not detected.
11
+ */
12
+ export interface DiskStamp {
13
+ readonly dev: bigint;
14
+ readonly ino: bigint;
15
+ readonly size: bigint;
16
+ readonly mtimeNs: bigint;
17
+ readonly ctimeNs: bigint;
18
+ }
19
+
20
+ interface BigIntStatLike {
21
+ readonly dev: bigint;
22
+ readonly ino: bigint;
23
+ readonly size: bigint;
24
+ readonly mtimeNs: bigint;
25
+ readonly ctimeNs: bigint;
26
+ }
27
+
28
+ /** Convert a bigint stat result into a stamp. */
29
+ export function toDiskStamp(stats: BigIntStatLike): DiskStamp {
30
+ return {
31
+ dev: stats.dev,
32
+ ino: stats.ino,
33
+ size: stats.size,
34
+ mtimeNs: stats.mtimeNs,
35
+ ctimeNs: stats.ctimeNs,
36
+ };
37
+ }
38
+
39
+ /**
40
+ * Stat one file before its content is read. Returns undefined on any failure;
41
+ * the following read decides whether the file is missing or unreadable.
42
+ */
43
+ export function statDiskStampSync(filePath: string): DiskStamp | undefined {
44
+ try {
45
+ return toDiskStamp(statSync(filePath, { bigint: true }));
46
+ } catch {
47
+ return undefined;
48
+ }
49
+ }
50
+
51
+ /** Compare two stamps field by field. */
52
+ export function sameDiskStamp(a: DiskStamp, b: DiskStamp): boolean {
53
+ return (
54
+ a.dev === b.dev &&
55
+ a.ino === b.ino &&
56
+ a.size === b.size &&
57
+ a.mtimeNs === b.mtimeNs &&
58
+ a.ctimeNs === b.ctimeNs
59
+ );
60
+ }
@@ -1,5 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import type { Diagnostic } from "../config/types.ts";
3
+ import type { DiagnosticEvidenceReason } from "../diagnostics/evidence.ts";
3
4
  import { type DiagnosticCacheEntry, isTentativePushEntry } from "./client-diagnostic-evidence.ts";
4
5
 
5
6
  /** One file's stored diagnostics as consumed by manager-level collection. */
@@ -14,6 +15,8 @@ export interface ClientDiagnosticDocument {
14
15
  uri: string;
15
16
  current: boolean;
16
17
  status: "confirmed" | "unconfirmed" | "failed" | "removed";
18
+ /** Why an otherwise current document is unconfirmed. */
19
+ reason?: DiagnosticEvidenceReason;
17
20
  }
18
21
 
19
22
  /** One client's diagnostic snapshot, including empty cache freshness. */
@@ -5,6 +5,7 @@ import {
5
5
  } from "vscode-languageserver-protocol";
6
6
  import type { DiagnosticSynchronization } from "./client-diagnostic-evidence.ts";
7
7
  import type { DiagnosticWaitRegistry } from "./client-diagnostic-waiters.ts";
8
+ import { type DiskStamp, statDiskStampSync } from "./client-disk-stamp.ts";
8
9
  import { fingerprintDocumentContent, type OpenDocumentState } from "./client-document-state.ts";
9
10
  import { getDiagnosticFileState } from "./client-file-state.ts";
10
11
 
@@ -73,6 +74,8 @@ interface SynchronizeDocumentOptions {
73
74
  documentSync: NormalizedDocumentSync;
74
75
  waiters: DiagnosticWaitRegistry;
75
76
  sendNotification: NotificationSender;
77
+ /** Send the whole text without a range, even under incremental sync (LSP allows both). */
78
+ fullText?: boolean;
76
79
  }
77
80
 
78
81
  function endPosition(content: string): { line: number; character: number } {
@@ -117,11 +120,9 @@ export function synchronizeDocument(options: SynchronizeDocumentOptions): void {
117
120
  retainDocumentSynchronization(options);
118
121
  options.document.version = options.version;
119
122
  options.document.synchronizationId = options.synchronizationId;
120
- const changes = contentChanges(
121
- options.document.content,
122
- options.content,
123
- options.documentSync.change,
124
- );
123
+ const changes = options.fullText
124
+ ? [{ text: options.content }]
125
+ : contentChanges(options.document.content, options.content, options.documentSync.change);
125
126
  options.document.content = options.content;
126
127
  options.document.contentFingerprint = fingerprintDocumentContent(options.content);
127
128
  if (options.documentSync.change === TextDocumentSyncKind.None) return;
@@ -161,6 +162,7 @@ export function synchronizeTrackedDocument(options: {
161
162
  markUnversionedSyncMoment?(): void;
162
163
  clearFailedFile?(): void;
163
164
  open(): void;
165
+ fullText?: boolean;
164
166
  }): void {
165
167
  if (!options.document) {
166
168
  options.open();
@@ -177,6 +179,7 @@ export function synchronizeTrackedDocument(options: {
177
179
  documentSync: options.documentSync,
178
180
  waiters: options.waiters,
179
181
  sendNotification: options.sendNotification,
182
+ ...(options.fullText ? { fullText: true } : {}),
180
183
  });
181
184
  options.clearFailedFile?.();
182
185
  }
@@ -192,12 +195,16 @@ interface ResynchronizeDocumentsOptions {
192
195
  noteInputContentChange(): number;
193
196
  /** Record the verified disk content and report whether its baseline changed. */
194
197
  observeDiskContent(uri: string, content: string): boolean;
198
+ /** Record a pre-read disk stamp when the document now equals that read. */
199
+ recordDiskStamp(uri: string, content: string, stamp: DiskStamp | undefined): void;
195
200
  /** Send one save for an externally observed disk change. */
196
201
  noteExternalDiskChange(uri: string, content: string): void;
197
202
  sendNotification: NotificationSender;
198
203
  uriToFile(uri: string): string;
199
204
  /** Disk content already read by classification; avoids a second read. */
200
205
  preloadedContent?: ReadonlyMap<string, string>;
206
+ /** Stamps taken before the preloaded reads. */
207
+ preloadedStamps?: ReadonlyMap<string, DiskStamp>;
201
208
  clearFile(uri: string): void;
202
209
  invalidateEvidence(uri: string): void;
203
210
  markUnversionedSyncMoment(uri: string): void;
@@ -227,6 +234,20 @@ function noteObservedDiskChange(
227
234
  }
228
235
  }
229
236
 
237
+ /** Read one document, or reuse its preloaded read; the stamp precedes the read. */
238
+ function readDocumentForResynchronization(
239
+ options: Pick<ResynchronizeDocumentsOptions, "preloadedContent" | "preloadedStamps">,
240
+ uri: string,
241
+ filePath: string,
242
+ ): { content: string; stamp: DiskStamp | undefined } {
243
+ const preloaded = options.preloadedContent?.get(uri);
244
+ if (preloaded !== undefined) {
245
+ return { content: preloaded, stamp: options.preloadedStamps?.get(uri) };
246
+ }
247
+ const stamp = statDiskStampSync(filePath);
248
+ return { content: readFileSync(filePath, "utf-8"), stamp };
249
+ }
250
+
230
251
  /** Re-read and synchronize every existing open document. */
231
252
  export function resynchronizeOpenDocuments(
232
253
  options: ResynchronizeDocumentsOptions,
@@ -241,7 +262,7 @@ export function resynchronizeOpenDocuments(
241
262
  const filePath = options.uriToFile(uri);
242
263
  try {
243
264
  options.markUnversionedSyncMoment(uri);
244
- const content = options.preloadedContent?.get(uri) ?? readFileSync(filePath, "utf-8");
265
+ const { content, stamp } = readDocumentForResynchronization(options, uri, filePath);
245
266
  const contentChanged = fingerprintDocumentContent(content) !== document.contentFingerprint;
246
267
  if (contentChanged) {
247
268
  if (!inputChangeNoted) {
@@ -271,6 +292,7 @@ export function resynchronizeOpenDocuments(
271
292
  });
272
293
  }
273
294
  noteObservedDiskChange(options, uri, content);
295
+ options.recordDiskStamp(uri, content, stamp);
274
296
  options.clearFailedFile(uri);
275
297
  synchronizedUris.add(uri);
276
298
  if (contentChanged) resynchronizedUris.add(uri);
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Capture window for server-pushed `workspace/applyEdit` requests.
3
+ *
4
+ * SuPi never applies an edit that a server pushes. While one command runs for
5
+ * preview, each pushed edit is recorded and refused; outside that window every
6
+ * pushed edit is refused as unsolicited (LSP 3.17 `ApplyWorkspaceEditResult`).
7
+ */
8
+
9
+ import {
10
+ type CodeRequestControl,
11
+ isCodeRequestInterruption,
12
+ } from "@mrclrchtr/supi-code-runtime/api";
13
+ import { uriToFile } from "@mrclrchtr/supi-core/path";
14
+ import type { Command, WorkspaceEdit } from "../config/types.ts";
15
+ import { LSP_REQUEST_TIMEOUT_ERROR_CODE } from "../debug-telemetry.ts";
16
+ import { JsonRpcRequestError } from "./transport.ts";
17
+
18
+ /** Reply for an edit recorded for preview. */
19
+ export const CAPTURED_EDIT_REPLY = {
20
+ applied: false,
21
+ failureReason: "SuPi captured this edit for preview.",
22
+ } as const;
23
+
24
+ /** Reply for an edit that arrives outside a capture window. */
25
+ export const UNSOLICITED_EDIT_REPLY = {
26
+ applied: false,
27
+ failureReason: "SuPi does not accept unsolicited workspace edits.",
28
+ } as const;
29
+
30
+ /** Result of running one command inside a capture window. */
31
+ export type CommandEditCaptureResult =
32
+ | {
33
+ readonly kind: "captured";
34
+ /** The single edit the server pushed while the command ran. */
35
+ readonly edit: WorkspaceEdit;
36
+ /** Open documents re-sent afterwards, with their versions before and after. */
37
+ readonly resynced: readonly { file: string; from: number; to: number }[];
38
+ }
39
+ | { readonly kind: "unavailable"; readonly reason: string };
40
+
41
+ /** Reply for an edit from a command SuPi stopped waiting for. */
42
+ export const ABANDONED_EDIT_REPLY = {
43
+ applied: false,
44
+ failureReason: "SuPi stopped waiting for the command that produced this edit.",
45
+ } as const;
46
+
47
+ /**
48
+ * Records pushed edits for at most one capture per client. After a capture
49
+ * stops waiting (timeout, abort, deadline) the window keeps draining until the
50
+ * abandoned command settles, so its late edits are refused and can never be
51
+ * attributed to the next capture.
52
+ */
53
+ export class EditCaptureWindow {
54
+ #state: "idle" | "capturing" | "draining" = "idle";
55
+ #edits: unknown[] = [];
56
+ #onEdit: (() => void) | undefined;
57
+
58
+ /** Open the window. Returns false while another capture runs or drains. */
59
+ open(): boolean {
60
+ if (this.#state !== "idle") return false;
61
+ this.#state = "capturing";
62
+ this.#edits = [];
63
+ return true;
64
+ }
65
+
66
+ /** Stop capturing and return the edits pushed so far. */
67
+ close(): unknown[] {
68
+ const edits = this.#edits;
69
+ this.#edits = [];
70
+ this.#onEdit = undefined;
71
+ if (this.#state === "capturing") this.#state = "idle";
72
+ return edits;
73
+ }
74
+
75
+ /** Stop capturing but refuse new captures until `settled` resolves. */
76
+ drain(settled: Promise<void>): unknown[] {
77
+ const edits = this.close();
78
+ this.#state = "draining";
79
+ void settled.then(() => {
80
+ if (this.#state === "draining") this.#state = "idle";
81
+ });
82
+ return edits;
83
+ }
84
+
85
+ /** Wait up to `ms` for the first edit when none has arrived yet. */
86
+ async waitForEdit(ms: number): Promise<void> {
87
+ if (this.#edits.length > 0 || ms <= 0) return;
88
+ await new Promise<void>((resolve) => {
89
+ const timer = setTimeout(resolve, ms);
90
+ this.#onEdit = () => {
91
+ clearTimeout(timer);
92
+ resolve();
93
+ };
94
+ });
95
+ }
96
+
97
+ /** Answer one `workspace/applyEdit` request; the edit is never applied. */
98
+ handleApplyEdit(
99
+ params: unknown,
100
+ ): typeof CAPTURED_EDIT_REPLY | typeof UNSOLICITED_EDIT_REPLY | typeof ABANDONED_EDIT_REPLY {
101
+ if (this.#state === "draining") return ABANDONED_EDIT_REPLY;
102
+ if (this.#state === "idle") return UNSOLICITED_EDIT_REPLY;
103
+ const edit =
104
+ typeof params === "object" && params !== null
105
+ ? (params as { edit?: unknown }).edit
106
+ : undefined;
107
+ this.#edits.push(edit);
108
+ this.#onEdit?.();
109
+ return CAPTURED_EDIT_REPLY;
110
+ }
111
+ }
112
+
113
+ /** Collect the file URIs a captured edit touches, for resynchronization. */
114
+ export function editedDocumentUris(edit: unknown): string[] {
115
+ if (typeof edit !== "object" || edit === null) return [];
116
+ const uris = new Set<string>();
117
+ const { changes, documentChanges } = edit as {
118
+ changes?: unknown;
119
+ documentChanges?: unknown;
120
+ };
121
+ if (typeof changes === "object" && changes !== null) {
122
+ for (const uri of Object.keys(changes)) uris.add(uri);
123
+ }
124
+ if (Array.isArray(documentChanges)) {
125
+ for (const change of documentChanges) {
126
+ const uri = (change as { textDocument?: { uri?: unknown } } | null)?.textDocument?.uri;
127
+ if (typeof uri === "string") uris.add(uri);
128
+ }
129
+ }
130
+ return [...uris];
131
+ }
132
+
133
+ /** Default wait for an edit a server pushes just after answering the command. */
134
+ const DEFAULT_GRACE_MS = 250;
135
+
136
+ /** Collaborators for one command capture on one client. */
137
+ export interface CommandEditCaptureOptions {
138
+ readonly command: Command;
139
+ /** Upper bound for the command to finish. */
140
+ readonly timeoutMs: number;
141
+ /** Wait for an edit pushed after the command answers; LSP allows that order. */
142
+ readonly graceMs?: number;
143
+ /** Upper bound for refusing late edits from an abandoned command. */
144
+ readonly drainMs?: number;
145
+ readonly control?: CodeRequestControl;
146
+ readonly window: EditCaptureWindow;
147
+ /** Send one request and expose when its transport lifetime ends. */
148
+ sendRequestOwned(
149
+ method: string,
150
+ params: unknown,
151
+ options: { timeoutMs: number } & CodeRequestControl,
152
+ ): { result: Promise<unknown>; settled: Promise<void> };
153
+ /** Re-send one open document; null when it is not open. */
154
+ resynchronize(file: string): { from: number; to: number } | null;
155
+ }
156
+
157
+ /**
158
+ * Run one command inside a capture window. Exactly one pushed edit becomes the
159
+ * result; none, several, a timeout, or a server error are unavailable.
160
+ * Cancellation and deadline expiry propagate. Every touched open document is
161
+ * resynced, and an abandoned command keeps the window draining.
162
+ */
163
+ export async function runCommandEditCapture(
164
+ options: CommandEditCaptureOptions,
165
+ ): Promise<CommandEditCaptureResult> {
166
+ const { command, timeoutMs, control, window } = options;
167
+ if (!window.open()) {
168
+ return {
169
+ kind: "unavailable",
170
+ reason: "Another server command capture is running on this client; retry shortly.",
171
+ };
172
+ }
173
+ const request = options.sendRequestOwned(
174
+ "workspace/executeCommand",
175
+ { command: command.command, ...(command.arguments ? { arguments: command.arguments } : {}) },
176
+ { ...control, timeoutMs },
177
+ );
178
+ let serverError: string | undefined;
179
+ try {
180
+ await request.result;
181
+ } catch (error) {
182
+ if (!(error instanceof JsonRpcRequestError) || isCodeRequestInterruption(error, control)) {
183
+ return abandonCapture(options, request.settled, error);
184
+ }
185
+ // The server answered with an error, so the command is over. clangd
186
+ // reports that the refused edit "was not applied"; the edit still counts.
187
+ serverError = error.message;
188
+ }
189
+ if (serverError === undefined) await window.waitForEdit(options.graceMs ?? DEFAULT_GRACE_MS);
190
+ const edits = window.close();
191
+ const resynced = resynchronizeEdits(edits, options.resynchronize);
192
+ if (edits.length === 0) {
193
+ return {
194
+ kind: "unavailable",
195
+ reason:
196
+ serverError === undefined
197
+ ? "The server command produced no edit; there may be nothing to change."
198
+ : `The server command failed: ${serverError}`,
199
+ };
200
+ }
201
+ if (edits.length > 1) {
202
+ return {
203
+ kind: "unavailable",
204
+ reason: `The server command produced ${edits.length} edits; only one can be previewed.`,
205
+ };
206
+ }
207
+ return { kind: "captured", edit: edits[0] as WorkspaceEdit, resynced };
208
+ }
209
+
210
+ /** Close or drain the window after SuPi stopped waiting for the command, then report or rethrow. */
211
+ function abandonCapture(
212
+ options: CommandEditCaptureOptions,
213
+ settled: Promise<void>,
214
+ error: unknown,
215
+ ): CommandEditCaptureResult {
216
+ const { window, timeoutMs, control } = options;
217
+ const drainMs = options.drainMs ?? timeoutMs;
218
+ const edits = drainMs > 0 ? window.drain(boundedSettle(settled, drainMs)) : window.close();
219
+ resynchronizeEdits(edits, options.resynchronize);
220
+ if (isCodeRequestInterruption(error, control)) throw error;
221
+ return {
222
+ kind: "unavailable",
223
+ reason: isTimeout(error)
224
+ ? `The server command did not finish within ${timeoutMs} ms.`
225
+ : `The server command could not run: ${error instanceof Error ? error.message : String(error)}`,
226
+ };
227
+ }
228
+
229
+ function boundedSettle(settled: Promise<void>, ms: number): Promise<void> {
230
+ return Promise.race([settled, new Promise<void>((resolve) => setTimeout(resolve, ms))]);
231
+ }
232
+
233
+ function resynchronizeEdits(
234
+ edits: readonly unknown[],
235
+ resynchronize: CommandEditCaptureOptions["resynchronize"],
236
+ ): { file: string; from: number; to: number }[] {
237
+ const uris = new Set(edits.flatMap((edit) => editedDocumentUris(edit)));
238
+ const resynced: { file: string; from: number; to: number }[] = [];
239
+ for (const uri of uris) {
240
+ let file: string;
241
+ try {
242
+ file = uriToFile(uri);
243
+ } catch {
244
+ continue;
245
+ }
246
+ const versions = resynchronize(file);
247
+ if (versions) resynced.push({ file, ...versions });
248
+ }
249
+ return resynced;
250
+ }
251
+
252
+ function isTimeout(error: unknown): boolean {
253
+ return (
254
+ typeof error === "object" &&
255
+ error !== null &&
256
+ (error as { code?: unknown }).code === LSP_REQUEST_TIMEOUT_ERROR_CODE
257
+ );
258
+ }
@@ -1,16 +1,30 @@
1
1
  import { accessSync, constants, statSync } from "node:fs";
2
+ import { type DiskStamp, toDiskStamp } from "./client-disk-stamp.ts";
2
3
 
3
4
  /** State used to distinguish deleted files from files that cannot be read. */
4
5
  export type DiagnosticFileState = "present" | "removed" | "unreadable";
5
6
 
7
+ /** File-system state plus the disk stamp of a present file. */
8
+ export interface DiagnosticFileStatus {
9
+ readonly state: DiagnosticFileState;
10
+ /** Set only for a present file. */
11
+ readonly stamp?: DiskStamp;
12
+ }
13
+
6
14
  /** Read the file-system state without treating access errors as deletion. */
7
15
  export function getDiagnosticFileState(filePath: string): DiagnosticFileState {
16
+ return getDiagnosticFileStatus(filePath).state;
17
+ }
18
+
19
+ /** Read the file-system state and, for a present file, its disk stamp. */
20
+ export function getDiagnosticFileStatus(filePath: string): DiagnosticFileStatus {
8
21
  try {
9
- if (!statSync(filePath).isFile()) return "unreadable";
22
+ const stats = statSync(filePath, { bigint: true });
23
+ if (!stats.isFile()) return { state: "unreadable" };
10
24
  accessSync(filePath, constants.R_OK);
11
- return "present";
25
+ return { state: "present", stamp: toDiskStamp(stats) };
12
26
  } catch (error) {
13
- return isMissingFileError(error) ? "removed" : "unreadable";
27
+ return { state: isMissingFileError(error) ? "removed" : "unreadable" };
14
28
  }
15
29
  }
16
30