@mrclrchtr/supi-code-intelligence 1.16.1 → 2.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 (344) hide show
  1. package/README.md +373 -63
  2. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +6 -1
  3. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/abort-utils.ts +31 -0
  4. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/api.ts +8 -0
  5. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +10 -4
  6. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config.ts +1 -0
  7. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +1 -1
  8. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/index.ts +6 -0
  9. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/model-selection.ts +134 -0
  10. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +9 -2
  11. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +109 -4
  12. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +5 -1
  13. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/spinner-frames.ts +11 -0
  14. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/status-spinner.ts +68 -0
  15. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +3 -2
  16. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +7 -0
  17. package/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +56 -2
  18. package/node_modules/@mrclrchtr/supi-code-runtime/src/evidence-badge.ts +40 -0
  19. package/node_modules/@mrclrchtr/supi-code-runtime/src/index.ts +5 -0
  20. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +76 -3
  21. package/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/runtime.ts +37 -2
  22. package/node_modules/@mrclrchtr/supi-core/package.json +6 -1
  23. package/node_modules/@mrclrchtr/supi-core/src/abort-utils.ts +31 -0
  24. package/node_modules/@mrclrchtr/supi-core/src/api.ts +8 -0
  25. package/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +10 -4
  26. package/node_modules/@mrclrchtr/supi-core/src/config.ts +1 -0
  27. package/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +1 -1
  28. package/node_modules/@mrclrchtr/supi-core/src/index.ts +6 -0
  29. package/node_modules/@mrclrchtr/supi-core/src/model-selection.ts +134 -0
  30. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +9 -2
  31. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +109 -4
  32. package/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +5 -1
  33. package/node_modules/@mrclrchtr/supi-core/src/spinner-frames.ts +11 -0
  34. package/node_modules/@mrclrchtr/supi-core/src/status-spinner.ts +68 -0
  35. package/node_modules/@mrclrchtr/supi-lsp/README.md +44 -56
  36. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +6 -1
  37. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/abort-utils.ts +31 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/api.ts +8 -0
  39. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +10 -4
  40. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config.ts +1 -0
  41. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +1 -1
  42. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/index.ts +6 -0
  43. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/model-selection.ts +134 -0
  44. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +9 -2
  45. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +109 -4
  46. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +5 -1
  47. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/spinner-frames.ts +11 -0
  48. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/status-spinner.ts +68 -0
  49. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +3 -2
  50. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +7 -0
  51. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +56 -2
  52. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/evidence-badge.ts +40 -0
  53. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/index.ts +5 -0
  54. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +76 -3
  55. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/runtime.ts +37 -2
  56. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +6 -1
  57. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/abort-utils.ts +31 -0
  58. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/api.ts +8 -0
  59. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +10 -4
  60. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config.ts +1 -0
  61. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +1 -1
  62. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/index.ts +6 -0
  63. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/model-selection.ts +134 -0
  64. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +9 -2
  65. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +109 -4
  66. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +5 -1
  67. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/spinner-frames.ts +11 -0
  68. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/status-spinner.ts +68 -0
  69. package/node_modules/@mrclrchtr/supi-lsp/package.json +4 -31
  70. package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +27 -0
  71. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-refresh.ts +5 -0
  72. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +246 -1
  73. package/node_modules/@mrclrchtr/supi-lsp/src/client/transport.ts +4 -0
  74. package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +3 -0
  75. package/node_modules/@mrclrchtr/supi-lsp/src/config/config.ts +4 -2
  76. package/node_modules/@mrclrchtr/supi-lsp/src/config/lsp-settings.ts +102 -0
  77. package/node_modules/@mrclrchtr/supi-lsp/src/config/server-actions.ts +59 -0
  78. package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +4 -0
  79. package/node_modules/@mrclrchtr/supi-lsp/src/index.ts +11 -0
  80. package/node_modules/@mrclrchtr/supi-lsp/src/manager/capability-index.ts +1 -1
  81. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-project-info.ts +2 -1
  82. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +115 -26
  83. package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-semantic-provider.ts +177 -134
  84. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +214 -0
  85. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +320 -0
  86. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registration.ts +26 -5
  87. package/node_modules/@mrclrchtr/supi-lsp/src/session/service-registry.ts +81 -4
  88. package/node_modules/@mrclrchtr/supi-lsp/src/summary.ts +2 -0
  89. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +18 -37
  90. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +6 -1
  91. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/abort-utils.ts +31 -0
  92. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/api.ts +8 -0
  93. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +10 -4
  94. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config.ts +1 -0
  95. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +1 -1
  96. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/index.ts +6 -0
  97. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/model-selection.ts +134 -0
  98. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +9 -2
  99. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +109 -4
  100. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +5 -1
  101. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/spinner-frames.ts +11 -0
  102. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/status-spinner.ts +68 -0
  103. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +3 -2
  104. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +7 -0
  105. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +56 -2
  106. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/evidence-badge.ts +40 -0
  107. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/index.ts +5 -0
  108. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +76 -3
  109. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/runtime.ts +37 -2
  110. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +6 -1
  111. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/abort-utils.ts +31 -0
  112. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/api.ts +8 -0
  113. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +10 -4
  114. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config.ts +1 -0
  115. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +1 -1
  116. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/index.ts +6 -0
  117. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/model-selection.ts +134 -0
  118. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +9 -2
  119. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +109 -4
  120. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +5 -1
  121. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/spinner-frames.ts +11 -0
  122. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/status-spinner.ts +68 -0
  123. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/LICENSE +21 -0
  124. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/README.md +265 -0
  125. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.cjs +4661 -0
  126. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.cjs.map +7 -0
  127. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.js +4605 -0
  128. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.js.map +7 -0
  129. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.wasm +0 -0
  130. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.wasm.map +57 -0
  131. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/package.json +100 -0
  132. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.cjs +4063 -0
  133. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.cjs.map +7 -0
  134. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.cts +1025 -0
  135. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.cts.map +58 -0
  136. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.ts +1025 -0
  137. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.ts.map +58 -0
  138. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.js +4007 -0
  139. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.js.map +7 -0
  140. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.wasm +0 -0
  141. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.wasm.map +55 -0
  142. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +6 -12
  143. package/node_modules/@mrclrchtr/supi-tree-sitter/src/api.ts +29 -0
  144. package/node_modules/@mrclrchtr/supi-tree-sitter/src/index.ts +28 -0
  145. package/node_modules/@mrclrchtr/supi-tree-sitter/src/language.ts +5 -0
  146. package/node_modules/@mrclrchtr/supi-tree-sitter/src/provider/tree-sitter-provider.ts +14 -2
  147. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/runtime-controller.ts +157 -0
  148. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/session.ts +8 -1
  149. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +86 -0
  150. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +35 -16
  151. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/structure.ts +1 -0
  152. package/node_modules/@mrclrchtr/supi-tree-sitter/src/types.ts +10 -0
  153. package/package.json +14 -9
  154. package/src/{model.ts → analysis/architecture/discovery.ts} +15 -72
  155. package/src/analysis/architecture/model.ts +76 -0
  156. package/src/analysis/brief/directory.ts +324 -0
  157. package/src/analysis/brief/enrich.ts +157 -0
  158. package/src/analysis/brief/file.ts +84 -0
  159. package/src/analysis/brief/inventory.ts +177 -0
  160. package/src/analysis/brief/main.ts +176 -0
  161. package/src/analysis/brief/models.ts +75 -0
  162. package/src/{brief.ts → analysis/brief/public-brief.ts} +21 -26
  163. package/src/analysis/brief/summarize.ts +208 -0
  164. package/src/analysis/brief/types.ts +27 -0
  165. package/src/{use-case/generate-brief.ts → analysis/brief/use-case.ts} +67 -144
  166. package/src/analysis/coverage/coverage-warnings.ts +224 -0
  167. package/src/analysis/evidence.ts +91 -0
  168. package/src/{semantic-action-helpers.ts → analysis/helpers.ts} +4 -4
  169. package/src/analysis/provider.ts +186 -0
  170. package/src/analysis/read-next.ts +126 -0
  171. package/src/analysis/readiness.ts +73 -0
  172. package/src/{refactor → analysis/refactor}/safety.ts +1 -1
  173. package/src/{use-case/support/semantic-references.ts → analysis/references/semantic-refs.ts} +58 -26
  174. package/src/analysis/search/pattern.ts +345 -0
  175. package/src/analysis/search/ripgrep.ts +473 -0
  176. package/src/{git-context.ts → analysis/signals/git.ts} +20 -7
  177. package/src/{prioritization-signals.ts → analysis/signals/project.ts} +33 -19
  178. package/src/analysis/target/anchored.ts +349 -0
  179. package/src/analysis/target/bridge.ts +152 -0
  180. package/src/analysis/target/file-resolution.ts +125 -0
  181. package/src/{targeting/resolve-file.ts → analysis/target/file.ts} +40 -20
  182. package/src/{planner → analysis/target}/planner.ts +30 -20
  183. package/src/{targeting → analysis/target}/query.ts +17 -3
  184. package/src/analysis/target/resolve-common.ts +115 -0
  185. package/src/analysis/target/service.ts +229 -0
  186. package/src/analysis/target/symbol.ts +196 -0
  187. package/src/{targeting → analysis/target}/types.ts +17 -1
  188. package/src/analysis/tests/likely-tests.ts +174 -0
  189. package/src/analysis/tests/test-discovery.ts +540 -0
  190. package/src/analysis/tests/vitest.ts +87 -0
  191. package/src/api.ts +34 -41
  192. package/src/app/app.ts +125 -0
  193. package/src/app/manager.ts +65 -0
  194. package/src/extension.ts +132 -1
  195. package/src/index.ts +1 -57
  196. package/src/session/refactor-plans.ts +82 -0
  197. package/src/session/session.ts +300 -0
  198. package/src/session/target-store.ts +293 -0
  199. package/src/substrate/lsp/diagnostic-injection.ts +218 -0
  200. package/src/substrate/lsp/lifecycle.ts +66 -0
  201. package/src/substrate/lsp/overrides.ts +132 -0
  202. package/src/substrate/lsp/recovery.ts +55 -0
  203. package/src/substrate/lsp/settings.ts +286 -0
  204. package/src/substrate/lsp/state.ts +46 -0
  205. package/src/substrate/lsp/utils.ts +17 -0
  206. package/src/substrate/tree-sitter/lifecycle.ts +52 -0
  207. package/src/tool/find/execute.ts +118 -0
  208. package/src/{presentation/markdown/pattern.ts → tool/find/markdown.ts} +102 -53
  209. package/src/{use-case/generate-pattern.ts → tool/find/orchestrate.ts} +67 -33
  210. package/src/tool/find/semantic-search.ts +114 -0
  211. package/src/tool/find/tui.ts +39 -0
  212. package/src/tool/graph/callees.ts +87 -0
  213. package/src/tool/graph/calls-md.ts +54 -0
  214. package/src/tool/graph/collect-relation.ts +371 -0
  215. package/src/tool/graph/execute.ts +95 -0
  216. package/src/tool/graph/implementations-md.ts +79 -0
  217. package/src/tool/graph/implementations.ts +76 -0
  218. package/src/tool/graph/markdown-base.ts +243 -0
  219. package/src/tool/graph/orchestrate.ts +285 -0
  220. package/src/tool/graph/references-md.ts +34 -0
  221. package/src/tool/graph/references.ts +81 -0
  222. package/src/tool/graph/tui.ts +120 -0
  223. package/src/tool/graph/types.ts +97 -0
  224. package/src/tool/guidance.ts +96 -49
  225. package/src/tool/health/execute.ts +76 -0
  226. package/src/tool/health/markdown.ts +280 -0
  227. package/src/tool/health/orchestrate.ts +159 -0
  228. package/src/tool/health/sections/diagnostics.ts +182 -0
  229. package/src/tool/health/sections/recovery.ts +89 -0
  230. package/src/tool/health/sections/signals.ts +89 -0
  231. package/src/tool/health/tui.ts +137 -0
  232. package/src/tool/impact/analysis.ts +247 -0
  233. package/src/tool/impact/change-set-impact.ts +151 -0
  234. package/src/tool/impact/execute.ts +98 -0
  235. package/src/tool/impact/file-level-impact.ts +81 -0
  236. package/src/tool/impact/markdown.ts +283 -0
  237. package/src/tool/impact/orchestrate.ts +97 -0
  238. package/src/tool/impact/result.ts +21 -0
  239. package/src/tool/impact/single-impact.ts +89 -0
  240. package/src/tool/impact/tui.ts +39 -0
  241. package/src/tool/impact/types.ts +34 -0
  242. package/src/tool/infra/cross-field.ts +335 -0
  243. package/src/tool/infra/error-results.ts +199 -0
  244. package/src/tool/infra/pipeline.ts +311 -0
  245. package/src/tool/infra/progress.ts +21 -0
  246. package/src/tool/infra/readiness-message.ts +5 -0
  247. package/src/tool/infra/truncate.ts +49 -0
  248. package/src/tool/inspect/execute.ts +76 -0
  249. package/src/tool/inspect/markdown.ts +169 -0
  250. package/src/tool/inspect/orchestrate.ts +156 -0
  251. package/src/tool/inspect/tui.ts +36 -0
  252. package/src/tool/orientation/deps.ts +63 -0
  253. package/src/tool/orientation/execute.ts +50 -0
  254. package/src/tool/orientation/markdown.ts +35 -0
  255. package/src/tool/orientation/mode.ts +88 -0
  256. package/src/tool/orientation/orchestrate.ts +478 -0
  257. package/src/tool/orientation/precise-target.ts +257 -0
  258. package/src/tool/orientation/tui.ts +131 -0
  259. package/src/{refactor/apply-workspace-edit.ts → tool/refactor-apply/apply.ts} +39 -16
  260. package/src/tool/refactor-apply/execute.ts +20 -0
  261. package/src/tool/refactor-apply/markdown.ts +118 -0
  262. package/src/tool/refactor-apply/orchestrate.ts +89 -0
  263. package/src/tool/refactor-apply/tui.ts +51 -0
  264. package/src/tool/refactor-plan/execute.ts +73 -0
  265. package/src/tool/refactor-plan/markdown.ts +118 -0
  266. package/src/tool/refactor-plan/orchestrate.ts +363 -0
  267. package/src/tool/refactor-plan/tui.ts +42 -0
  268. package/src/tool/register.ts +123 -0
  269. package/src/tool/resolve/execute.ts +82 -0
  270. package/src/tool/resolve/markdown.ts +150 -0
  271. package/src/tool/resolve/orchestrate.ts +134 -0
  272. package/src/tool/resolve/tui.ts +40 -0
  273. package/src/tool/schemas.ts +337 -0
  274. package/src/tool/specs.ts +257 -0
  275. package/src/types/details.ts +188 -0
  276. package/src/types/execution.ts +60 -0
  277. package/src/types/index.ts +28 -0
  278. package/src/{intent/types.ts → types/tool-names.ts} +15 -14
  279. package/src/ui/footer.ts +52 -0
  280. package/src/ui/markdown/brief.ts +218 -0
  281. package/src/ui/markdown/gather.ts +177 -0
  282. package/src/{use-case/build-overview.ts → ui/markdown/overview-data.ts} +2 -2
  283. package/src/{presentation → ui}/markdown/overview.ts +2 -2
  284. package/src/ui/markdown/types.ts +80 -0
  285. package/{node_modules/@mrclrchtr/supi-lsp/src/ui/renderer.ts → src/ui/message-renderer.ts} +11 -10
  286. package/src/ui/status-command.ts +260 -0
  287. package/src/ui/status-overlay.ts +500 -0
  288. package/src/ui/tui/common.ts +220 -0
  289. package/src/ui/tui/index.ts +37 -0
  290. package/node_modules/@mrclrchtr/supi-lsp/src/extension.ts +0 -1
  291. package/node_modules/@mrclrchtr/supi-lsp/src/format.ts +0 -373
  292. package/node_modules/@mrclrchtr/supi-lsp/src/handlers/diagnostic-injection.ts +0 -182
  293. package/node_modules/@mrclrchtr/supi-lsp/src/handlers/session-lifecycle.ts +0 -149
  294. package/node_modules/@mrclrchtr/supi-lsp/src/handlers/status-command.ts +0 -38
  295. package/node_modules/@mrclrchtr/supi-lsp/src/handlers/workspace-recovery.ts +0 -92
  296. package/node_modules/@mrclrchtr/supi-lsp/src/lsp.ts +0 -37
  297. package/node_modules/@mrclrchtr/supi-lsp/src/session/lsp-state.ts +0 -93
  298. package/node_modules/@mrclrchtr/supi-lsp/src/session/settings-registration.ts +0 -296
  299. package/node_modules/@mrclrchtr/supi-lsp/src/session/tree-persist.ts +0 -75
  300. package/node_modules/@mrclrchtr/supi-lsp/src/tool/guidance.ts +0 -69
  301. package/node_modules/@mrclrchtr/supi-lsp/src/tool/names.ts +0 -27
  302. package/node_modules/@mrclrchtr/supi-lsp/src/tool/overrides.ts +0 -204
  303. package/node_modules/@mrclrchtr/supi-lsp/src/tool/register-tools.ts +0 -69
  304. package/node_modules/@mrclrchtr/supi-lsp/src/tool/service-actions.ts +0 -399
  305. package/node_modules/@mrclrchtr/supi-lsp/src/tool/tool-specs.ts +0 -248
  306. package/node_modules/@mrclrchtr/supi-lsp/src/ui/ui.ts +0 -360
  307. package/node_modules/@mrclrchtr/supi-lsp/src/workspace-change.ts +0 -40
  308. package/node_modules/@mrclrchtr/supi-tree-sitter/src/extension.ts +0 -1
  309. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/formatting.ts +0 -104
  310. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/guidance.ts +0 -35
  311. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/handlers.ts +0 -196
  312. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/register-tools.ts +0 -107
  313. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/tool-specs.ts +0 -117
  314. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tree-sitter.ts +0 -47
  315. package/src/brief-focused.ts +0 -563
  316. package/src/code-intelligence.ts +0 -70
  317. package/src/pattern-structured.ts +0 -194
  318. package/src/presentation/markdown/affected.ts +0 -170
  319. package/src/presentation/markdown/brief.ts +0 -174
  320. package/src/presentation/markdown/map.ts +0 -54
  321. package/src/presentation/markdown/refactor.ts +0 -27
  322. package/src/presentation/markdown/relations.ts +0 -121
  323. package/src/resolve-target.ts +0 -130
  324. package/src/search-helpers.ts +0 -303
  325. package/src/substrates/types.ts +0 -30
  326. package/src/target-resolution.ts +0 -122
  327. package/src/targeting/resolve-anchored.ts +0 -80
  328. package/src/targeting/resolve-symbol.ts +0 -110
  329. package/src/tool/execute-affected.ts +0 -71
  330. package/src/tool/execute-brief.ts +0 -59
  331. package/src/tool/execute-map.ts +0 -35
  332. package/src/tool/execute-pattern.ts +0 -29
  333. package/src/tool/execute-refactor.ts +0 -101
  334. package/src/tool/execute-relations.ts +0 -79
  335. package/src/tool/register-tools.ts +0 -32
  336. package/src/tool/tool-specs.ts +0 -190
  337. package/src/tool/validation.ts +0 -43
  338. package/src/types.ts +0 -169
  339. package/src/use-case/generate-affected.ts +0 -297
  340. package/src/use-case/generate-map.ts +0 -176
  341. package/src/use-case/generate-relations.ts +0 -438
  342. package/src/use-case/types.ts +0 -43
  343. package/src/workspace/request-context.ts +0 -139
  344. /package/src/{query-params.ts → tool/params.ts} +0 -0
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Workspace code-intelligence session facade.
3
+ *
4
+ * Per-workspace facade that owns session-scoped state (targets, plans,
5
+ * coverage warnings) and provides typed workflow methods for all
6
+ * public code_* tools. Tool executors receive this session explicitly
7
+ * through their execution context; the session centralizes provider
8
+ * access, target resolution, plan management, and readiness policy.
9
+ *
10
+ * The session does NOT own the shared capability broker in
11
+ * @mrclrchtr/supi-code-runtime — it reads from it. It does NOT
12
+ * render markdown or manage TUI state — executors and rendering
13
+ * modules keep that.
14
+ *
15
+ * @mrclrchtr/supi-code-intelligence — internal, not exported via api.ts
16
+ */
17
+
18
+ import {
19
+ getDefaultWorkspaceRuntime,
20
+ type SemanticProvider,
21
+ type StructuralProvider,
22
+ } from "@mrclrchtr/supi-code-runtime/api";
23
+ import type { LspRuntimeController } from "@mrclrchtr/supi-lsp/api";
24
+ import { CoverageWarningState } from "../analysis/coverage/coverage-warnings.ts";
25
+ import type { CodeProvider } from "../analysis/provider.ts";
26
+ import { getCodeProvider } from "../analysis/provider.ts";
27
+ import { getPlan, type RefactorPlan, removePlan, storePlan } from "./refactor-plans.ts";
28
+ import {
29
+ getWorkflowTarget,
30
+ registerWorkflowTarget,
31
+ type TargetLookupResult,
32
+ type TargetRegistrationInput,
33
+ type TargetRegistrationOutput,
34
+ type TargetStoreEntry,
35
+ } from "./target-store.ts";
36
+
37
+ // ── Re-export types consumed by callers ───────────────────────────────
38
+
39
+ export type { CoverageWarningState } from "../analysis/coverage/coverage-warnings.ts";
40
+ export type { CodeProvider, CodeProviderState } from "../analysis/provider.ts";
41
+ export type { RefactorPlan } from "./refactor-plans.ts";
42
+ export type {
43
+ TargetLookupResult,
44
+ TargetRegistrationInput,
45
+ TargetRegistrationOutput,
46
+ TargetStoreEntry,
47
+ } from "./target-store.ts";
48
+
49
+ // ── Target ID expansion result ────────────────────────────────────────
50
+
51
+ export type TargetIdExpansionResult =
52
+ | {
53
+ kind: "ok";
54
+ file: string;
55
+ line: number;
56
+ character: number;
57
+ targetName: string | null;
58
+ targetKind: string | null;
59
+ entry: TargetStoreEntry;
60
+ }
61
+ | { kind: "not-provided" }
62
+ | { kind: "error"; message: string };
63
+
64
+ // ── Session class ─────────────────────────────────────────────────────
65
+
66
+ /**
67
+ * Per-cwd workspace code-intelligence session.
68
+ *
69
+ * Owns session-scoped state and provides centralized methods for
70
+ * provider access, target resolution, plan management, and readiness
71
+ * policy. Lifecycle modules attach controller references.
72
+ */
73
+ export class WorkspaceCodeIntelligenceSession {
74
+ /** Canonical workspace directory for this session. */
75
+ readonly cwd: string;
76
+
77
+ /** Whether the hidden architecture overview has been injected. */
78
+ hasInjectedOverview = false;
79
+
80
+ /** Session-scoped workflow target storage (targetId → entry). */
81
+ readonly #workflowTargets = new Map<string, TargetStoreEntry>();
82
+
83
+ /** Session-scoped refactor plan storage (planId → plan). */
84
+ readonly #refactorPlans = new Map<string, RefactorPlan>();
85
+
86
+ /**
87
+ * Coverage warning state for deduplication and grace-period timing.
88
+ */
89
+ readonly coverageWarningState = new CoverageWarningState();
90
+
91
+ /**
92
+ * Optional LSP controller reference — attached by LSP lifecycle module
93
+ * for coverage evaluation and server management.
94
+ */
95
+ lspController: LspRuntimeController | null = null;
96
+
97
+ /**
98
+ * Optional Tree-sitter controller reference — attached by TS lifecycle
99
+ * module for structural provider lifecycle management.
100
+ */
101
+ tsController: import("@mrclrchtr/supi-tree-sitter/api").TreeSitterRuntimeController | null = null;
102
+
103
+ constructor(cwd: string) {
104
+ this.cwd = cwd;
105
+ }
106
+
107
+ // ── Provider access ───────────────────────────────────────────────
108
+
109
+ /**
110
+ * Get the composite code provider state for this workspace.
111
+ * Combines semantic (LSP) and structural (tree-sitter) capabilities
112
+ * along with LSP service state.
113
+ */
114
+ getProviders(): import("../analysis/provider.ts").CodeProviderState {
115
+ return getCodeProvider(this.cwd);
116
+ }
117
+
118
+ /**
119
+ * Get the ready composite code provider, or null if unavailable.
120
+ */
121
+ getProvider(): CodeProvider | null {
122
+ const state = this.getProviders();
123
+ return state.kind === "ready" ? state.provider : null;
124
+ }
125
+
126
+ /**
127
+ * Get the semantic provider from the shared runtime.
128
+ */
129
+ getSemanticProvider(): SemanticProvider | null {
130
+ const ws = getDefaultWorkspaceRuntime().getWorkspace(this.cwd);
131
+ if (
132
+ (ws.semantic.state.kind === "ready" || ws.semantic.state.kind === "pending") &&
133
+ ws.semantic.provider !== null
134
+ ) {
135
+ return ws.semantic.provider as SemanticProvider;
136
+ }
137
+ return null;
138
+ }
139
+
140
+ /**
141
+ * Get the structural provider from the shared runtime.
142
+ */
143
+ getStructuralProvider(): StructuralProvider | null {
144
+ const ws = getDefaultWorkspaceRuntime().getWorkspace(this.cwd);
145
+ if (ws.structural.state.kind === "ready" && ws.structural.provider !== null) {
146
+ return ws.structural.provider as StructuralProvider;
147
+ }
148
+ return null;
149
+ }
150
+
151
+ /**
152
+ * Get the raw workspace state from the shared runtime.
153
+ *
154
+ * Exposes semantic/structural state and provider refs for tools
155
+ * that need detailed status (e.g. code_health). Prefer higher-level
156
+ * methods (`getProvider()`, `getSemanticProvider()`) when you only
157
+ * need a ready provider reference.
158
+ */
159
+ getWorkspaceState() {
160
+ return getDefaultWorkspaceRuntime().getWorkspace(this.cwd);
161
+ }
162
+
163
+ // ── Target resolution ─────────────────────────────────────────────
164
+
165
+ /**
166
+ * Look up a stored target by targetId in this session's store.
167
+ */
168
+ lookupTargetId(targetId: string): TargetLookupResult {
169
+ return getWorkflowTarget(this.#workflowTargets, targetId);
170
+ }
171
+
172
+ /**
173
+ * Register a resolved target in this session's store and return
174
+ * stable session-scoped handles.
175
+ */
176
+ registerTarget(input: TargetRegistrationInput): TargetRegistrationOutput {
177
+ return registerWorkflowTarget(this.#workflowTargets, this.cwd, input);
178
+ }
179
+
180
+ /**
181
+ * Expand an optional targetId from tool params into anchored
182
+ * file/line/character.
183
+ *
184
+ * Usage at the top of each target-oriented executor:
185
+ *
186
+ * ```ts
187
+ * const expansion = session.expandTargetId(params);
188
+ * if (expansion.kind === "error") return errorResult(expansion.message);
189
+ * if (expansion.kind === "ok") {
190
+ * params.file = expansion.file;
191
+ * params.line = expansion.line;
192
+ * params.character = expansion.character;
193
+ * }
194
+ * ```
195
+ */
196
+ expandTargetId(params: {
197
+ targetId?: string;
198
+ file?: string;
199
+ line?: number;
200
+ character?: number;
201
+ symbol?: string;
202
+ }): TargetIdExpansionResult {
203
+ return expandSessionTargetId(this, params);
204
+ }
205
+
206
+ /**
207
+ * Look up a targetId without expanding into file/line/character.
208
+ * Returns the raw store entry or an error.
209
+ */
210
+ lookupTargetEntry(targetId: string): TargetLookupResult {
211
+ return getWorkflowTarget(this.#workflowTargets, targetId);
212
+ }
213
+
214
+ // ── Plan store ────────────────────────────────────────────────────
215
+
216
+ /**
217
+ * Store a refactor plan and return its planId.
218
+ */
219
+ storePlan(plan: RefactorPlan): string {
220
+ return storePlan(this.#refactorPlans, plan);
221
+ }
222
+
223
+ /**
224
+ * Retrieve a plan by id, or undefined.
225
+ */
226
+ getPlan(id: string): RefactorPlan | undefined {
227
+ return getPlan(this.#refactorPlans, id);
228
+ }
229
+
230
+ /**
231
+ * Remove a plan after successful apply.
232
+ */
233
+ removePlan(id: string): void {
234
+ removePlan(this.#refactorPlans, id);
235
+ }
236
+
237
+ // ── Introspection (for tests / debugging) ───────────────────────
238
+
239
+ /** Number of stored targets (for test isolation checks). */
240
+ get targetCount(): number {
241
+ return this.#workflowTargets.size;
242
+ }
243
+
244
+ /** Number of stored refactor plans (for test isolation checks). */
245
+ get planCount(): number {
246
+ return this.#refactorPlans.size;
247
+ }
248
+
249
+ // ── Cleanup ───────────────────────────────────────────────────────
250
+
251
+ /** Clear all session-scoped stores. */
252
+ clearStores(): void {
253
+ this.#refactorPlans.clear();
254
+ this.#workflowTargets.clear();
255
+ }
256
+ }
257
+
258
+ // ── Standalone target-id expansion helper ─────────────────────────────
259
+
260
+ /**
261
+ * Expand an optional targetId into anchored file/line/character params
262
+ * using the given session's store.
263
+ *
264
+ * Exported separately so executors that already hold a session ref
265
+ * can call it directly, without going through an ad-hoc session factory.
266
+ */
267
+ export function expandSessionTargetId(
268
+ session: WorkspaceCodeIntelligenceSession,
269
+ params: {
270
+ targetId?: string;
271
+ file?: string;
272
+ line?: number;
273
+ character?: number;
274
+ symbol?: string;
275
+ },
276
+ ): TargetIdExpansionResult {
277
+ const targetId = params.targetId;
278
+ if (targetId === undefined || targetId === null) {
279
+ return { kind: "not-provided" };
280
+ }
281
+
282
+ const result = session.lookupTargetEntry(targetId);
283
+ if (result.kind === "unavailable") {
284
+ return {
285
+ kind: "error",
286
+ message: `**Error:** ${result.reason}`,
287
+ };
288
+ }
289
+
290
+ const { entry } = result;
291
+ return {
292
+ kind: "ok",
293
+ file: entry.file,
294
+ line: entry.displayLine,
295
+ character: entry.displayCharacter,
296
+ targetName: entry.name,
297
+ targetKind: entry.kind,
298
+ entry,
299
+ };
300
+ }
@@ -0,0 +1,293 @@
1
+ /**
2
+ * Workflow target store — per-session target and span handle registry.
3
+ *
4
+ * Provides deterministic opaque IDs derived from cwd, file, position,
5
+ * metadata, and file fingerprint. Re-resolving the same target with
6
+ * unchanged file contents reuses the same IDs.
7
+ *
8
+ * The store map is passed in from the caller; this module provides pure
9
+ * functions without module-level state.
10
+ */
11
+
12
+ import { createHash } from "node:crypto";
13
+ import { existsSync, readFileSync } from "node:fs";
14
+ import { resolve } from "node:path";
15
+ import type { ConfidenceMode } from "@mrclrchtr/supi-code-runtime/api";
16
+
17
+ // ── Public types ──────────────────────────────────────────────────────
18
+
19
+ /**
20
+ * Which anchor a resolved target carries, per ADR 0003.
21
+ * - `name` — the identifier token (preferred by position-strict substrates).
22
+ * - `declaration` — the defining node start (export/modifiers); a fallback
23
+ * when the name anchor could not be derived. Position-strict consumers
24
+ * (rename, callees) must refuse rather than silently use it.
25
+ */
26
+ export type AnchorKind = "name" | "declaration";
27
+
28
+ /**
29
+ * A stored resolved target entry with handles and metadata.
30
+ *
31
+ * This is the canonical post-registration target type — all tool layers
32
+ * (executors, renderers, details) use it directly. Computed fields like
33
+ * relative paths are derived at the rendering boundary.
34
+ */
35
+ export interface TargetStoreEntry {
36
+ targetId: string;
37
+ spanId: string;
38
+ /** Absolute filesystem path. Compute relative paths at render time with `path.relative(cwd, file)`. */
39
+ file: string;
40
+ /** 0-based position for LSP calls. */
41
+ position: { line: number; character: number };
42
+ /** 1-based position for user display. */
43
+ displayLine: number;
44
+ displayCharacter: number;
45
+ name: string | null;
46
+ kind: string | null;
47
+ confidence: ConfidenceMode;
48
+ provenance: string;
49
+ /** Which anchor this target carries — drives strict-consumer enforcement (ADR 0003). */
50
+ anchorKind: AnchorKind;
51
+ fileFingerprint: string;
52
+ /** Symbolic container (class/namespace/module name), or null for top-level. */
53
+ container: string | null;
54
+ /**
55
+ * Resolution provenance — present when the target was resolved from
56
+ * anchored coordinates. Carries requested/resolved coordinates, whether
57
+ * the anchor was snapped, and the provider-backed evidence source.
58
+ */
59
+ resolution?: import("../types/index.ts").AnchoredResolutionMetadata;
60
+ }
61
+
62
+ /** Input shape for registering a resolved target. */
63
+ export interface TargetRegistrationInput {
64
+ file: string;
65
+ position: { line: number; character: number };
66
+ displayLine: number;
67
+ displayCharacter: number;
68
+ name: string | null;
69
+ kind: string | null;
70
+ confidence: ConfidenceMode;
71
+ provenance: string;
72
+ /** Which anchor this target carries — drives strict-consumer enforcement (ADR 0003). */
73
+ anchorKind: AnchorKind;
74
+ /** Symbolic container (class/namespace/module name), or null for top-level (ADR 0003 — disambiguates same-file collisions in the identity hash). */
75
+ container: string | null;
76
+ /**
77
+ * Resolution provenance — present when the target was resolved from
78
+ * anchored coordinates. Carries requested/resolved coordinates, whether
79
+ * the anchor was snapped, and the provider-backed evidence source.
80
+ */
81
+ resolution?: import("../types/index.ts").AnchoredResolutionMetadata;
82
+ }
83
+
84
+ /** Output from registering a target: stable session-scoped handles and the full stored entry. */
85
+ export interface TargetRegistrationOutput {
86
+ targetId: string;
87
+ spanId: string;
88
+ entry: TargetStoreEntry;
89
+ }
90
+
91
+ /** Lookup result for a target ID query. */
92
+ export type TargetLookupResult =
93
+ | { kind: "available"; entry: TargetStoreEntry }
94
+ | { kind: "unavailable"; reason: string };
95
+
96
+ // ── Helpers ───────────────────────────────────────────────────────────
97
+
98
+ function normalizeCwd(cwd: string): string {
99
+ return cwd.replace(/\\/g, "/").replace(/\/$/, "");
100
+ }
101
+
102
+ // ── File fingerprinting ───────────────────────────────────────────────
103
+
104
+ /**
105
+ * Compute a full-file SHA-256 fingerprint for staleness detection.
106
+ * Returns an error result when the file is missing or unreadable.
107
+ */
108
+ export function computeFileFingerprint(
109
+ file: string,
110
+ ): { kind: "ok"; fingerprint: string } | { kind: "error"; message: string } {
111
+ try {
112
+ if (!existsSync(file)) {
113
+ return { kind: "error", message: `File not found: \`${file}\`` };
114
+ }
115
+ const content = readFileSync(file, { flag: "r" });
116
+ const hash = createHash("sha256").update(content).digest("hex");
117
+ return { kind: "ok", fingerprint: hash };
118
+ } catch {
119
+ return { kind: "error", message: `Cannot read file: \`${file}\`` };
120
+ }
121
+ }
122
+
123
+ // ── ID generation ─────────────────────────────────────────────────────
124
+
125
+ /**
126
+ * Build a deterministic target handle from target identity fields.
127
+ *
128
+ * Per ADR 0003, position is intentionally excluded from symbol identity:
129
+ * nameAnchor is best-effort, so the same symbol can resolve to a name
130
+ * anchor or fall back to the declaration anchor across calls; including
131
+ * position would break the "re-resolve reuses the same IDs" invariant.
132
+ * Identity is cwd, file path, name, kind, container, and fingerprint.
133
+ */
134
+ function computeTargetId(opts: {
135
+ cwd: string;
136
+ file: string;
137
+ position: { line: number; character: number };
138
+ name: string | null;
139
+ kind: string | null;
140
+ container: string | null;
141
+ fingerprint: string;
142
+ }): string {
143
+ const hash = createHash("sha256");
144
+ hash.update(normalizeCwd(opts.cwd));
145
+ hash.update("\0");
146
+ hash.update(resolve(opts.cwd, opts.file));
147
+ hash.update("\0");
148
+ hash.update(opts.name ?? "");
149
+ hash.update("\0");
150
+ hash.update(opts.kind ?? "");
151
+ hash.update("\0");
152
+ hash.update(opts.container ?? "");
153
+ hash.update("\0");
154
+ hash.update(opts.fingerprint);
155
+ return `tg-${hash.digest("hex").slice(0, 28)}`;
156
+ }
157
+
158
+ /**
159
+ * Build a deterministic span handle from the file and 0-based range.
160
+ */
161
+ function computeSpanId(
162
+ cwd: string,
163
+ file: string,
164
+ position: { line: number; character: number },
165
+ fingerprint: string,
166
+ ): string {
167
+ const hash = createHash("sha256");
168
+ hash.update(normalizeCwd(cwd));
169
+ hash.update("\0");
170
+ hash.update(resolve(cwd, file));
171
+ hash.update("\0");
172
+ hash.update(`${position.line}:${position.character}`);
173
+ hash.update("\0");
174
+ hash.update(fingerprint);
175
+ return `sp-${hash.digest("hex").slice(0, 24)}`;
176
+ }
177
+
178
+ // ── Public API ────────────────────────────────────────────────────────
179
+
180
+ /**
181
+ * Register a resolved target in the given session-scoped store and return
182
+ * stable session-scoped handles.
183
+ *
184
+ * If the same target (same file, position, name, kind) is registered
185
+ * and the file fingerprint matches, the same IDs are returned.
186
+ *
187
+ * Returns an error when the backing file cannot be read for fingerprinting.
188
+ */
189
+ export function registerWorkflowTarget(
190
+ store: Map<string, TargetStoreEntry>,
191
+ cwd: string,
192
+ input: TargetRegistrationInput,
193
+ ): TargetRegistrationOutput {
194
+ const key = normalizeCwd(cwd);
195
+ const absFile = resolve(cwd, input.file);
196
+
197
+ // Compute fingerprint; if unavailable, still allow registration but
198
+ // mark as unfingerprinted so stale checks know the fingerprint is absent
199
+ const fingerprintResult = computeFileFingerprint(absFile);
200
+ const fingerprint =
201
+ fingerprintResult.kind === "ok" ? fingerprintResult.fingerprint : "unfingerprinted";
202
+
203
+ const targetId = computeTargetId({
204
+ cwd: key,
205
+ file: input.file,
206
+ position: input.position,
207
+ name: input.name,
208
+ kind: input.kind,
209
+ container: input.container,
210
+ fingerprint,
211
+ });
212
+ const spanId = computeSpanId(key, input.file, input.position, fingerprint);
213
+
214
+ // Check for existing entry with same targetId
215
+ const existing = store.get(targetId);
216
+ if (existing) {
217
+ return { targetId: existing.targetId, spanId: existing.spanId, entry: existing };
218
+ }
219
+
220
+ const entry: TargetStoreEntry = {
221
+ targetId,
222
+ spanId,
223
+ file: absFile,
224
+ position: { line: input.position.line, character: input.position.character },
225
+ displayLine: input.displayLine,
226
+ displayCharacter: input.displayCharacter,
227
+ name: input.name,
228
+ kind: input.kind,
229
+ confidence: input.confidence,
230
+ provenance: input.provenance,
231
+ anchorKind: input.anchorKind,
232
+ fileFingerprint: fingerprint,
233
+ container: input.container,
234
+ resolution: input.resolution,
235
+ };
236
+
237
+ store.set(targetId, entry);
238
+
239
+ return { targetId, spanId, entry };
240
+ }
241
+
242
+ /**
243
+ * Look up a stored target by targetId in the given session-scoped store.
244
+ *
245
+ * Returns `{ kind: "available", entry }` when found.
246
+ * Returns `{ kind: "unavailable", reason }` when unknown or stale.
247
+ *
248
+ * Staleness is detected by comparing the stored fileFingerprint
249
+ * against the current file contents. If the fingerprint was
250
+ * "unfingerprinted" (file was unreadable at registration time),
251
+ * staleness cannot be confirmed and the entry is returned as-is.
252
+ */
253
+ export function getWorkflowTarget(
254
+ store: Map<string, TargetStoreEntry>,
255
+ targetId: string,
256
+ ): TargetLookupResult {
257
+ const entry = store.get(targetId);
258
+ if (!entry) {
259
+ return {
260
+ kind: "unavailable",
261
+ reason: `Target \`${targetId}\` not found. It may have been cleared or never registered.`,
262
+ };
263
+ }
264
+
265
+ // Check staleness: re-fingerprint unfingerprinted entries and
266
+ // compare fingerprints for entries with known fingerprints.
267
+ const current = computeFileFingerprint(entry.file);
268
+ if (current.kind === "error") {
269
+ // File is gone or unreadable — remove and report unavailable
270
+ store.delete(targetId);
271
+ return {
272
+ kind: "unavailable",
273
+ reason: `${current.message} — target \`${targetId}\` is no longer available.`,
274
+ };
275
+ }
276
+
277
+ if (entry.fileFingerprint === "unfingerprinted") {
278
+ // Entry was registered without a fingerprint — update it now
279
+ entry.fileFingerprint = current.fingerprint;
280
+ return { kind: "available", entry };
281
+ }
282
+
283
+ if (current.fingerprint !== entry.fileFingerprint) {
284
+ // Stale — remove and report unavailable
285
+ store.delete(targetId);
286
+ return {
287
+ kind: "unavailable",
288
+ reason: `Target \`${targetId}\` (\`${entry.name ?? entry.file}\`) is stale — the backing file has been modified since resolution. Re-resolve with \`code_resolve\`.`,
289
+ };
290
+ }
291
+
292
+ return { kind: "available", entry };
293
+ }