@mrclrchtr/supi-code-intelligence 4.10.0 → 6.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 (269) hide show
  1. package/README.md +4 -3
  2. package/node_modules/@mrclrchtr/supi-code-runtime/README.md +2 -0
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +9 -0
  5. package/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +53 -13
  6. package/node_modules/@mrclrchtr/supi-code-runtime/src/request-control.ts +47 -0
  7. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -1
  8. package/node_modules/@mrclrchtr/supi-core/README.md +2 -0
  9. package/node_modules/@mrclrchtr/supi-core/package.json +2 -2
  10. package/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
  11. package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +31 -0
  12. package/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -0
  13. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +19 -6
  14. package/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
  15. package/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
  16. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +3 -0
  17. package/node_modules/@mrclrchtr/supi-lsp/README.md +111 -5
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/README.md +2 -0
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  20. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +9 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +53 -13
  22. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/request-control.ts +47 -0
  23. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -1
  24. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/README.md +2 -0
  25. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +2 -2
  26. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
  27. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config/config.ts +31 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -0
  29. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +19 -6
  30. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
  32. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +3 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/package.json +7 -6
  34. package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +22 -1
  35. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-cache.ts +245 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +78 -0
  37. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-collection.ts +171 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-evidence.ts +413 -0
  39. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-host.ts +15 -0
  40. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-publication.ts +214 -0
  41. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-pull.ts +62 -0
  42. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-refresh.ts +690 -0
  43. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-request.ts +9 -0
  44. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-timing.ts +97 -16
  45. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-waiters.ts +206 -0
  46. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +448 -298
  47. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-state.ts +70 -0
  48. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +231 -0
  49. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-file-state.ts +25 -0
  50. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +529 -119
  51. package/node_modules/@mrclrchtr/supi-lsp/src/client/transport.ts +161 -33
  52. package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +12 -3
  53. package/node_modules/@mrclrchtr/supi-lsp/src/config/config.ts +5 -5
  54. package/node_modules/@mrclrchtr/supi-lsp/src/config/defaults.json +1 -1
  55. package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +3 -0
  56. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-extends.ts +68 -0
  57. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-path.ts +8 -0
  58. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +176 -24
  59. package/node_modules/@mrclrchtr/supi-lsp/src/debug-telemetry.ts +45 -0
  60. package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/evidence.ts +42 -0
  61. package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/workspace-sentinels.ts +46 -10
  62. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-client-state.ts +79 -9
  63. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-diagnostics.ts +17 -7
  64. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-recovery.ts +350 -26
  65. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-symbol.ts +5 -2
  66. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +586 -96
  67. package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-refactor-provider.ts +130 -0
  68. package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-semantic-provider.ts +45 -329
  69. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +57 -120
  70. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-edit-normalizer.ts +320 -0
  71. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +207 -0
  72. package/node_modules/@mrclrchtr/supi-lsp/src/session/readiness.ts +72 -2
  73. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +151 -26
  74. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostic-surface.ts +42 -0
  75. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostics.ts +92 -0
  76. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +165 -118
  77. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-transition-debug.ts +49 -0
  78. package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +102 -0
  79. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +17 -7
  80. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/README.md +2 -0
  81. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  82. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +9 -0
  83. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +53 -13
  84. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/request-control.ts +47 -0
  85. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -1
  86. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/README.md +2 -0
  87. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +2 -2
  88. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
  89. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config/config.ts +31 -0
  90. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -0
  91. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +19 -6
  92. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
  93. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
  94. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +3 -0
  95. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/LICENSE +21 -0
  96. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/README.md +258 -0
  97. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/dist/babel.cjs +257 -0
  98. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/dist/jiti.cjs +1 -0
  99. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-cli.mjs +34 -0
  100. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-hooks.mjs +124 -0
  101. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-native.mjs +121 -0
  102. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-register.d.mts +1 -0
  103. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-register.mjs +4 -0
  104. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-static.mjs +23 -0
  105. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.cjs +30 -0
  106. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.d.cts +8 -0
  107. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.d.mts +8 -0
  108. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.mjs +29 -0
  109. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/types.d.ts +420 -0
  110. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/package.json +146 -0
  111. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +6 -3
  112. package/node_modules/@mrclrchtr/supi-tree-sitter/src/api.ts +0 -9
  113. package/node_modules/@mrclrchtr/supi-tree-sitter/src/index.ts +0 -8
  114. package/node_modules/@mrclrchtr/supi-tree-sitter/src/provider/tree-sitter-provider.ts +16 -12
  115. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/runtime-controller.ts +65 -87
  116. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/session.ts +47 -95
  117. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-timing.ts +147 -0
  118. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client-lifecycle.ts +39 -0
  119. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +561 -0
  120. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-message-size.ts +24 -0
  121. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-protocol.ts +452 -0
  122. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +4 -2
  123. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +12 -4
  124. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +4 -2
  125. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/imports.ts +4 -2
  126. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/node-at.ts +5 -3
  127. package/node_modules/@mrclrchtr/supi-tree-sitter/src/types.ts +33 -12
  128. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/blocking-test-bootstrap.mjs +34 -0
  129. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/bootstrap.mjs +8 -0
  130. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/parsed-file-store-helpers.ts +23 -0
  131. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/parsed-file-store.ts +400 -0
  132. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/request-control.ts +48 -0
  133. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime-parser-helpers.ts +24 -0
  134. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime-query-helpers.ts +43 -0
  135. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +421 -0
  136. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/service.ts +116 -0
  137. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/worker-main.ts +201 -0
  138. package/package.json +5 -5
  139. package/src/analysis/health/diagnostics.ts +221 -77
  140. package/src/analysis/health/file-scope.ts +184 -0
  141. package/src/analysis/health/recovery.ts +14 -3
  142. package/src/analysis/provider.ts +58 -0
  143. package/src/analysis/readiness.ts +34 -9
  144. package/src/analysis/refactor/apply.ts +45 -1
  145. package/src/analysis/refactor/mutation-authority.ts +143 -0
  146. package/src/analysis/relations/callees.ts +9 -1
  147. package/src/analysis/relations/types.ts +5 -2
  148. package/src/analysis/search/ast-scan-timing.ts +9 -2
  149. package/src/analysis/search/ast-scan.ts +5 -2
  150. package/src/analysis/search/deadline.ts +2 -2
  151. package/src/analysis/search/pattern-analysis.ts +54 -33
  152. package/src/analysis/search/pattern.ts +18 -3
  153. package/src/analysis/target/anchored.ts +20 -11
  154. package/src/analysis/target/file.ts +18 -11
  155. package/src/analysis/target/identity.ts +19 -3
  156. package/src/analysis/target/symbol.ts +36 -15
  157. package/src/api.ts +4 -0
  158. package/src/config.ts +35 -1
  159. package/src/diagnostics/evidence.ts +51 -0
  160. package/src/extension.ts +57 -14
  161. package/src/overview/overview-data.ts +9 -2
  162. package/src/overview/overview.ts +49 -30
  163. package/src/overview/types.ts +2 -0
  164. package/src/session/capability-adapter.ts +12 -3
  165. package/src/session/find-types.ts +2 -2
  166. package/src/session/find-workflow.ts +20 -9
  167. package/src/session/graph/collect.ts +18 -2
  168. package/src/session/graph-workflow.ts +19 -12
  169. package/src/session/health-refresh.ts +175 -0
  170. package/src/session/health-types.ts +43 -15
  171. package/src/session/health-workflow.ts +69 -54
  172. package/src/session/input/workflows.ts +2 -2
  173. package/src/session/inspect/collect.ts +20 -3
  174. package/src/session/inspect-workflow.ts +12 -6
  175. package/src/session/orientation/collect.ts +12 -3
  176. package/src/session/orientation/context-facts.ts +3 -1
  177. package/src/session/orientation/context-sections.ts +20 -7
  178. package/src/session/orientation/gather.ts +17 -11
  179. package/src/session/orientation-types.ts +4 -1
  180. package/src/session/orientation-workflow.ts +23 -10
  181. package/src/session/refactor-plans.ts +2 -0
  182. package/src/session/refactor-workflow.ts +61 -15
  183. package/src/session/session.ts +29 -2
  184. package/src/session/target-workflow.ts +54 -23
  185. package/src/session/workflow-control.ts +7 -3
  186. package/src/substrate/lsp/lifecycle.ts +26 -46
  187. package/src/substrate/lsp/maintenance.ts +284 -28
  188. package/src/substrate/lsp/recovery.ts +11 -5
  189. package/src/substrate/lsp/state.ts +2 -2
  190. package/src/substrate/workspace-provider-host.ts +25 -3
  191. package/src/tool/{find → code_find}/execute.ts +2 -16
  192. package/src/tool/code_find/guidance.ts +8 -0
  193. package/src/tool/{find → code_find}/render.ts +21 -4
  194. package/src/tool/{result/find.ts → code_find/result.ts} +78 -9
  195. package/src/tool/code_find/spec.ts +37 -0
  196. package/src/tool/code_find/tui.ts +41 -0
  197. package/src/tool/code_graph/execute.ts +24 -0
  198. package/src/tool/code_graph/guidance.ts +6 -0
  199. package/src/tool/{graph → code_graph}/markdown.ts +1 -1
  200. package/src/tool/{result/graph.ts → code_graph/result.ts} +111 -3
  201. package/src/tool/code_graph/spec.ts +39 -0
  202. package/src/tool/code_graph/tui.ts +117 -0
  203. package/src/tool/{health → code_health}/execute.ts +2 -13
  204. package/src/tool/code_health/guidance.ts +8 -0
  205. package/src/tool/{health → code_health}/markdown.ts +119 -27
  206. package/src/tool/code_health/refresh-status.ts +105 -0
  207. package/src/tool/{result/health.ts → code_health/result.ts} +80 -3
  208. package/src/tool/code_health/spec.ts +41 -0
  209. package/src/tool/{health → code_health}/tui.ts +95 -98
  210. package/src/tool/{inspect → code_inspect}/execute.ts +2 -16
  211. package/src/tool/code_inspect/guidance.ts +6 -0
  212. package/src/tool/{inspect → code_inspect}/markdown.ts +1 -1
  213. package/src/tool/{result/inspect.ts → code_inspect/result.ts} +143 -2
  214. package/src/tool/code_inspect/spec.ts +25 -0
  215. package/src/tool/code_inspect/tui.ts +44 -0
  216. package/src/tool/code_orientation/execute.ts +25 -0
  217. package/src/tool/code_orientation/guidance.ts +9 -0
  218. package/src/tool/{orientation → code_orientation}/markdown.ts +1 -1
  219. package/src/tool/code_orientation/result.ts +248 -0
  220. package/src/tool/code_orientation/spec.ts +25 -0
  221. package/src/tool/{orientation → code_orientation}/tui.ts +51 -35
  222. package/src/tool/code_refactor_apply/execute.ts +17 -0
  223. package/src/tool/code_refactor_apply/guidance.ts +5 -0
  224. package/src/tool/{refactor-apply/execute.ts → code_refactor_apply/result.ts} +8 -11
  225. package/src/tool/code_refactor_apply/spec.ts +26 -0
  226. package/src/tool/code_refactor_apply/tui.ts +73 -0
  227. package/src/tool/code_refactor_plan/execute.ts +27 -0
  228. package/src/tool/code_refactor_plan/guidance.ts +8 -0
  229. package/src/tool/{refactor-plan/execute.ts → code_refactor_plan/result.ts} +13 -22
  230. package/src/tool/code_refactor_plan/spec.ts +25 -0
  231. package/src/tool/code_refactor_plan/tui.ts +54 -0
  232. package/src/tool/code_resolve/execute.ts +19 -0
  233. package/src/tool/code_resolve/guidance.ts +8 -0
  234. package/src/tool/{resolve → code_resolve}/markdown.ts +1 -1
  235. package/src/tool/{result/resolve.ts → code_resolve/result.ts} +79 -29
  236. package/src/tool/code_resolve/spec.ts +25 -0
  237. package/src/tool/code_resolve/tui.ts +60 -0
  238. package/src/tool/guidance.ts +71 -52
  239. package/src/tool/infra/truncate.ts +40 -0
  240. package/src/tool/infra/workflow-control.ts +8 -0
  241. package/src/tool/{refactor-plan/markdown.ts → refactor-markdown.ts} +4 -7
  242. package/src/tool/register.ts +105 -88
  243. package/src/tool/result/display.ts +107 -0
  244. package/src/tool/result/errors.ts +20 -17
  245. package/src/tool/result/refactor.ts +37 -8
  246. package/src/tool/result/types.ts +20 -0
  247. package/src/tool/schemas.ts +26 -157
  248. package/src/tool/specs.ts +40 -126
  249. package/src/types/execution.ts +18 -5
  250. package/src/types/index.ts +8 -1
  251. package/src/ui/status-command.ts +5 -3
  252. package/src/ui/status-overlay.ts +4 -0
  253. package/src/ui/tui/common.ts +108 -10
  254. package/src/ui/tui/display.ts +48 -0
  255. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/runtime.ts +0 -351
  256. package/src/tool/find/tui.ts +0 -39
  257. package/src/tool/graph/execute.ts +0 -62
  258. package/src/tool/graph/tui.ts +0 -104
  259. package/src/tool/inspect/tui.ts +0 -36
  260. package/src/tool/orientation/execute.ts +0 -62
  261. package/src/tool/refactor-apply/tui.ts +0 -55
  262. package/src/tool/refactor-plan/tui.ts +0 -41
  263. package/src/tool/resolve/execute.ts +0 -36
  264. package/src/tool/resolve/tui.ts +0 -42
  265. package/src/tool/result/orientation.ts +0 -132
  266. /package/src/tool/{find → code_find}/ast-kinds.ts +0 -0
  267. /package/src/tool/{find → code_find}/markdown.ts +0 -0
  268. /package/src/tool/{find → code_find}/modes.ts +0 -0
  269. /package/src/tool/{health → code_health}/semantic-state.ts +0 -0
@@ -6,19 +6,47 @@
6
6
  * partial/error guards, and the shared simple-result pattern.
7
7
  */
8
8
 
9
- import { getMarkdownTheme, type Theme } from "@earendil-works/pi-coding-agent";
9
+ import {
10
+ getMarkdownTheme,
11
+ type Theme,
12
+ type ToolRenderResultOptions,
13
+ } from "@earendil-works/pi-coding-agent";
10
14
  import { Container, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
11
15
  import { formatEvidenceBadge } from "@mrclrchtr/supi-core/evidence-badge";
16
+ import { truncateDisplayText } from "../../tool/result/display.ts";
17
+ import { renderToolDisplaySections } from "./display.ts";
18
+
19
+ export { formatCallPath, formatCallValue, renderToolDisplaySections } from "./display.ts";
20
+
21
+ import type {
22
+ ToolDisplaySection,
23
+ ToolOutputTruncationDetails,
24
+ ToolResultStatus,
25
+ } from "../../tool/result/types.ts";
12
26
 
13
27
  // ── Result type ──────────────────────────────────────────────────
14
28
 
15
29
  /** Shape of a pi tool result consumed by renderResult functions. */
16
30
  export interface ToolResult {
17
31
  content: Array<{ type: string; text?: string }>;
18
- details?: { type: string; data: Record<string, unknown> };
19
- isError?: boolean;
32
+ details?: {
33
+ type: string;
34
+ data: Record<string, unknown>;
35
+ status?: ToolResultStatus;
36
+ message?: string;
37
+ displaySections?: readonly ToolDisplaySection[];
38
+ truncation?: ToolOutputTruncationDetails;
39
+ };
40
+ }
41
+
42
+ /** PI render context used by Code Intelligence result renderers. */
43
+ export interface ToolRendererContext {
44
+ isError: boolean;
20
45
  }
21
46
 
47
+ /** PI render options used by Code Intelligence result renderers. */
48
+ export type ResultOptios = ToolRenderResultOptions;
49
+
22
50
  // ── Evidence key labels ──────────────────────────────────────────
23
51
 
24
52
  export const EVIDENCE_KEY_LABELS: Record<string, string> = {
@@ -142,7 +170,7 @@ export function renderMarkdownDetail(
142
170
  const markdownText = source.content?.find((c) => c.type === "text")?.text ?? "";
143
171
  if (!markdownText) return;
144
172
  container.addChild(new Spacer(1));
145
- const divider = `${theme.fg("border", "────")} ${theme.fg("dim", "raw markdown")} ${theme.fg("border", "".repeat(100))}`;
173
+ const divider = `${theme.fg("border", "────")} ${theme.fg("dim", "raw markdown")} ${theme.fg("border", "────")}`;
146
174
  container.addChild(new Text(divider, 0, 0));
147
175
  container.addChild(new Markdown(markdownText, 0, 0, getMarkdownTheme()));
148
176
  }
@@ -157,13 +185,62 @@ export function renderError(label: string, theme: Theme): Text {
157
185
  return new Text(theme.fg("error", label), 0, 0);
158
186
  }
159
187
 
160
- // ── Result options ───────────────────────────────────────────────
188
+ /** Render an execution failure from PI's renderer context. */
189
+ export function renderExecutionError(
190
+ context: ToolRendererContext | undefined,
191
+ label: string,
192
+ theme: Theme,
193
+ ): Text | null {
194
+ return context?.isError ? renderError(label, theme) : null;
195
+ }
196
+
197
+ /** Render a domain error encoded in structured result details. */
198
+ export function renderDomainError(result: ToolResult, theme: Theme): Text | null {
199
+ const status = result.details?.status;
200
+ if (status !== "invalid-input" && status !== "disambiguation" && status !== "unavailable") {
201
+ return null;
202
+ }
203
+
204
+ const label =
205
+ status === "invalid-input"
206
+ ? "Invalid input"
207
+ : status === "disambiguation"
208
+ ? "Choose a target"
209
+ : "Unavailable";
210
+ const message = result.details?.message
211
+ ? `: ${truncateDisplayText(result.details.message, 160)}`
212
+ : "";
213
+ return renderError(`${label}${message}`, theme);
214
+ }
215
+
216
+ /** Render an invalid-input or unavailable result with its structured body. */
217
+ export function renderDomainResult(
218
+ result: ToolResult,
219
+ options: ResultOptios,
220
+ theme: Theme,
221
+ error: Text,
222
+ ): Container | Text {
223
+ if (!options.expanded) return error;
224
+ const container = new Container();
225
+ container.addChild(error);
226
+ renderToolDisplaySections(container, result.details?.displaySections, theme);
227
+ renderMarkdownDetail(container, result, theme);
228
+ return container;
229
+ }
161
230
 
162
- export interface ResultOptios {
163
- expanded: boolean;
164
- isPartial: boolean;
231
+ /** Render the structured output-truncation disclosure. */
232
+ export function renderTruncationDisclosure(result: ToolResult, theme: Theme): Text | null {
233
+ const truncation = result.details?.truncation;
234
+ if (!truncation?.truncated) return null;
235
+
236
+ const path = truncation.fullOutputPath
237
+ ? `; full output: ${truncateDisplayText(truncation.fullOutputPath, 160)}`
238
+ : "";
239
+ return new Text(theme.fg("warning", `Output truncated${path}`), 0, 0);
165
240
  }
166
241
 
242
+ // ── Result options ───────────────────────────────────────────────
243
+
167
244
  // ── Shared simple-result renderer ─────────────────────────────────
168
245
 
169
246
  /**
@@ -172,19 +249,34 @@ export interface ResultOptios {
172
249
  *
173
250
  * Handles partial, error, compact, and expanded states uniformly.
174
251
  */
252
+ // biome-ignore lint/complexity/useMaxParams: renderer signature keeps the shared helper convenient for each tool
175
253
  export function renderSimpleResult(
176
254
  result: ToolResult,
177
255
  options: ResultOptios,
178
256
  theme: Theme,
179
257
  partialLabel: string,
258
+ context?: ToolRendererContext,
180
259
  ): Container | Text {
181
260
  if (options.isPartial) return renderPartial(partialLabel, theme);
182
- if (result.isError) return renderError("Tool failed", theme);
261
+
262
+ const executionError = renderExecutionError(context, "Tool failed", theme);
263
+ if (executionError) return executionError;
264
+
265
+ const domainError = renderDomainError(result, theme);
266
+ if (domainError) return renderDomainResult(result, options, theme, domainError);
183
267
 
184
268
  const data = result.details?.data as Record<string, unknown> | undefined;
185
269
  if (options.expanded) return buildExpandedView(result, data, theme);
186
270
 
187
- return buildSimpleCompact(data, theme);
271
+ const compact = buildSimpleCompact(data, theme);
272
+ const truncation = renderTruncationDisclosure(result, theme);
273
+ if (!truncation) return compact;
274
+
275
+ const container = new Container();
276
+ container.addChild(compact);
277
+ container.addChild(new Spacer(1));
278
+ container.addChild(truncation);
279
+ return container;
188
280
  }
189
281
 
190
282
  function buildExpandedView(
@@ -197,7 +289,13 @@ function buildExpandedView(
197
289
  const header = buildSimpleHeader(data, theme);
198
290
  if (header) container.addChild(header);
199
291
 
292
+ renderToolDisplaySections(container, result.details?.displaySections, theme);
200
293
  renderStructuredDetailBody(container, data, theme);
294
+ const truncation = renderTruncationDisclosure(result, theme);
295
+ if (truncation) {
296
+ container.addChild(new Spacer(1));
297
+ container.addChild(truncation);
298
+ }
201
299
  renderMarkdownDetail(container, result, theme);
202
300
 
203
301
  return container;
@@ -0,0 +1,48 @@
1
+ import type { Theme } from "@earendil-works/pi-coding-agent";
2
+ import { type Container, Text } from "@earendil-works/pi-tui";
3
+ import { readToolDisplaySections, truncateDisplayText } from "../../tool/result/display.ts";
4
+ import type { ToolDisplaySection } from "../../tool/result/types.ts";
5
+
6
+ /** Render bounded structured rows for an expanded TUI body. */
7
+ export function renderToolDisplaySections(
8
+ container: Container,
9
+ value: unknown,
10
+ theme: Theme,
11
+ ): void {
12
+ for (const section of readToolDisplaySections(value)) {
13
+ container.addChild(
14
+ new Text(theme.fg("dim", `${section.title}${formatDisplayBounds(section)}`), 0, 0),
15
+ );
16
+ for (const line of section.lines) {
17
+ container.addChild(new Text(theme.fg("muted", line), 0, 0));
18
+ }
19
+ }
20
+ }
21
+
22
+ function formatDisplayBounds(section: ToolDisplaySection): string {
23
+ if (section.totalCount === null) {
24
+ const omitted = section.omittedCount ? `; ${section.omittedCount} collected omitted` : "";
25
+ const reason = section.partialReason
26
+ ? `; more may exist — ${section.partialReason}`
27
+ : "; partial";
28
+ return ` (${section.shownCount}${omitted}${reason})`;
29
+ }
30
+ if (section.omittedCount && section.omittedCount > 0) {
31
+ return ` (${section.shownCount} of ${section.totalCount}; ${section.omittedCount} omitted)`;
32
+ }
33
+ return ` (${section.totalCount})`;
34
+ }
35
+
36
+ /** Format one call argument for a compact human transcript row. */
37
+ export function formatCallValue(value: unknown, maxLength = 60): string | null {
38
+ if (typeof value !== "string" || value.length === 0) return null;
39
+ const normalized = value.replace(/\s+/g, " ").trim();
40
+ return truncateDisplayText(normalized, maxLength);
41
+ }
42
+
43
+ /** Show the final path segment while accepting both POSIX and Windows paths. */
44
+ export function formatCallPath(value: unknown, maxLength = 60): string | null {
45
+ const formatted = formatCallValue(value, Number.MAX_SAFE_INTEGER);
46
+ if (!formatted) return null;
47
+ return formatCallValue(formatted.split(/[\\/]/).pop() ?? formatted, maxLength);
48
+ }
@@ -1,351 +0,0 @@
1
- // Tree-sitter runtime — parser management, parse, and query services.
2
-
3
- import { createHash } from "node:crypto";
4
- import * as fs from "node:fs";
5
- import * as path from "node:path";
6
- import { startDebugTimer } from "@mrclrchtr/supi-core/debug";
7
- import { resolveToolPath } from "@mrclrchtr/supi-core/path";
8
- import type { Language, Parser, Tree } from "web-tree-sitter";
9
- import { nodeToRange } from "../coordinates.ts";
10
- import { detectGrammar, resolveGrammarWasmPath } from "../language.ts";
11
- import type { GrammarId, QueryCapture, TreeSitterResult } from "../types.ts";
12
-
13
- interface ParserEntry {
14
- parser: Parser;
15
- language: Language;
16
- }
17
-
18
- /**
19
- * Session-scoped Tree-sitter runtime.
20
- *
21
- * A runtime owns the expensive `web-tree-sitter` initialization and parser
22
- * instances for one pi working directory. Call `dispose()` when the session is
23
- * torn down so WASM parser resources are released.
24
- */
25
- export class TreeSitterRuntime {
26
- private parserModule: typeof import("web-tree-sitter") | undefined;
27
- private parsers = new Map<GrammarId, ParserEntry>();
28
- private parserPromises = new Map<GrammarId, Promise<ParserEntry>>();
29
- private initPromise: Promise<typeof import("web-tree-sitter")> | undefined;
30
- private initializing = false;
31
- private disposed = false;
32
-
33
- /** Create a runtime that resolves relative file paths from `cwd`. */
34
- constructor(private cwd: string) {}
35
-
36
- /** Ensure web-tree-sitter Parser is initialized. */
37
- private async ensureParserInit(): Promise<typeof import("web-tree-sitter")> {
38
- this.assertActive();
39
- if (this.parserModule) return this.parserModule;
40
- if (this.initializing && this.initPromise) return this.initPromise;
41
-
42
- this.initializing = true;
43
- this.initPromise = (async () => {
44
- const mod = await import("web-tree-sitter");
45
- await mod.Parser.init();
46
- this.assertActive();
47
- this.parserModule = mod;
48
- return mod;
49
- })();
50
-
51
- try {
52
- return await this.initPromise;
53
- } catch (err: unknown) {
54
- // Allow retry on next call
55
- this.initPromise = undefined;
56
- this.initializing = false;
57
- throw new Error("Failed to initialize web-tree-sitter", { cause: err });
58
- }
59
- }
60
-
61
- /**
62
- * Get or create a parser entry for a grammar.
63
- *
64
- * Concurrent first-use calls for the same grammar share one initialization
65
- * promise. Failed initialization is not cached, so a later request can retry.
66
- */
67
- async ensureGrammarParser(grammarId: GrammarId): Promise<ParserEntry> {
68
- this.assertActive();
69
- const existing = this.parsers.get(grammarId);
70
- if (existing) return existing;
71
-
72
- const pending = this.parserPromises.get(grammarId);
73
- if (pending) return pending;
74
-
75
- const promise = this.createGrammarParser(grammarId);
76
- this.parserPromises.set(grammarId, promise);
77
-
78
- try {
79
- return await promise;
80
- } finally {
81
- if (this.parserPromises.get(grammarId) === promise) {
82
- this.parserPromises.delete(grammarId);
83
- }
84
- }
85
- }
86
-
87
- private async createGrammarParser(grammarId: GrammarId): Promise<ParserEntry> {
88
- const mod = await this.ensureParserInit();
89
- const wasmPath = resolveGrammarWasmPath(grammarId);
90
-
91
- const language = await mod.Language.load(wasmPath);
92
- const parser = new mod.Parser();
93
- try {
94
- parser.setLanguage(language);
95
- } catch (err) {
96
- parser.delete();
97
- throw err;
98
- }
99
-
100
- if (this.disposed) {
101
- parser.delete();
102
- throw new Error("Tree-sitter runtime has been disposed");
103
- }
104
-
105
- const entry = { parser, language };
106
- this.parsers.set(grammarId, entry);
107
- return entry;
108
- }
109
-
110
- /** Read and parse a file. Returns structured result. */
111
- async parseFile(filePath: string): Promise<
112
- TreeSitterResult<{
113
- tree: Tree;
114
- source: string;
115
- resolvedPath: string;
116
- grammarId: GrammarId;
117
- }>
118
- > {
119
- const resolvedPath = resolveToolPath(this.cwd, filePath);
120
-
121
- // Check language support first
122
- const grammarId = detectGrammar(filePath);
123
- if (!grammarId) {
124
- return {
125
- kind: "unsupported-language",
126
- file: filePath,
127
- message: `No Tree-sitter grammar configured for ${path.extname(filePath) || "this file type"}`,
128
- };
129
- }
130
-
131
- const timer = startDebugTimer();
132
- const parserState = this.parsers.has(grammarId)
133
- ? "reused"
134
- : this.parserPromises.has(grammarId)
135
- ? "initializing"
136
- : "cold";
137
-
138
- // Read the file
139
- let source: string;
140
- try {
141
- source = fs.readFileSync(resolvedPath, "utf-8");
142
- } catch (err: unknown) {
143
- finishStructuralTiming(timer, {
144
- operation: "parse",
145
- grammar: grammarId,
146
- parserState,
147
- outcome: "file-access-error",
148
- finalPhase: "file-read",
149
- });
150
- const message = err instanceof Error ? err.message : "File could not be read";
151
- return {
152
- kind: "file-access-error",
153
- file: filePath,
154
- message,
155
- };
156
- }
157
- timer.mark("file-read");
158
-
159
- if (timer.enabled) {
160
- try {
161
- createHash("sha256").update(source).digest();
162
- } catch {
163
- // Timing-only hashing must not change structural behavior.
164
- }
165
- }
166
- timer.mark("content-hash");
167
-
168
- let parserReady = false;
169
- try {
170
- const entry = await this.ensureGrammarParser(grammarId);
171
- timer.mark("parser-setup");
172
- parserReady = true;
173
- const tree = entry.parser.parse(source);
174
- finishStructuralTiming(timer, {
175
- operation: "parse",
176
- grammar: grammarId,
177
- parserState,
178
- outcome: "completed",
179
- finalPhase: "parse",
180
- });
181
- return {
182
- kind: "success",
183
- data: { tree: tree as Tree, source, resolvedPath, grammarId },
184
- };
185
- } catch (err: unknown) {
186
- finishStructuralTiming(timer, {
187
- operation: "parse",
188
- grammar: grammarId,
189
- parserState,
190
- outcome: "runtime-error",
191
- finalPhase: parserReady ? "parse" : "parser-setup",
192
- });
193
- return { kind: "runtime-error", message: formatError(err, "Parser initialization failed") };
194
- }
195
- }
196
-
197
- /** Execute a Tree-sitter query against a file. */
198
- async queryFile(
199
- filePath: string,
200
- queryString: string,
201
- ): Promise<TreeSitterResult<QueryCapture[]>> {
202
- if (!queryString || queryString.trim().length === 0) {
203
- return { kind: "validation-error", message: "query is required and must be non-empty" };
204
- }
205
- if (queryString.length > MAX_QUERY_LENGTH) {
206
- return {
207
- kind: "validation-error",
208
- message: `query exceeds maximum length of ${MAX_QUERY_LENGTH} characters`,
209
- };
210
- }
211
-
212
- const parseResult = await this.parseFile(filePath);
213
- if (parseResult.kind !== "success") return parseResult;
214
-
215
- const { grammarId, tree, source } = parseResult.data;
216
- const timer = startDebugTimer();
217
- let compiled = false;
218
-
219
- try {
220
- const entry = await this.ensureGrammarParser(grammarId);
221
- const mod = await this.ensureParserInit();
222
- let query: InstanceType<typeof mod.Query>;
223
-
224
- try {
225
- query = new mod.Query(entry.language, queryString);
226
- compiled = true;
227
- timer.mark("query-compilation");
228
- } catch (err: unknown) {
229
- finishStructuralTiming(timer, {
230
- operation: "query",
231
- grammar: grammarId,
232
- outcome: "validation-error",
233
- captureCount: 0,
234
- finalPhase: "query-compilation",
235
- });
236
- return { kind: "validation-error", message: `Invalid query: ${formatError(err)}` };
237
- }
238
-
239
- try {
240
- const matches = query.matches(tree.rootNode);
241
- const captures: QueryCapture[] = [];
242
- for (const match of matches) {
243
- for (const { name, node } of match.captures) {
244
- captures.push({
245
- name,
246
- nodeType: node.type,
247
- range: nodeToRange(node, source),
248
- text: node.text,
249
- });
250
- }
251
- }
252
- finishStructuralTiming(timer, {
253
- operation: "query",
254
- grammar: grammarId,
255
- outcome: "completed",
256
- captureCount: captures.length,
257
- finalPhase: "query-execution",
258
- });
259
- return { kind: "success", data: captures };
260
- } finally {
261
- query.delete();
262
- }
263
- } catch (err: unknown) {
264
- finishStructuralTiming(timer, {
265
- operation: "query",
266
- grammar: grammarId,
267
- outcome: "runtime-error",
268
- captureCount: 0,
269
- finalPhase: compiled ? "query-execution" : "query-compilation",
270
- });
271
- return { kind: "runtime-error", message: formatError(err, "Query execution failed") };
272
- } finally {
273
- tree.delete();
274
- }
275
- }
276
-
277
- /** Get the grammar ID for a file, or undefined if unsupported. */
278
- getGrammarId(filePath: string): GrammarId | undefined {
279
- return detectGrammar(filePath);
280
- }
281
-
282
- /** Resolve a file path from cwd. */
283
- resolvePath(filePath: string): string {
284
- return resolveToolPath(this.cwd, filePath);
285
- }
286
-
287
- /** Dispose all held parser resources. */
288
- dispose(): void {
289
- this.disposed = true;
290
- for (const [, entry] of this.parsers) {
291
- entry.parser.delete();
292
- }
293
- this.parsers.clear();
294
- this.parserPromises.clear();
295
- this.parserModule = undefined;
296
- this.initPromise = undefined;
297
- this.initializing = false;
298
- }
299
-
300
- private assertActive(): void {
301
- if (this.disposed) {
302
- throw new Error("Tree-sitter runtime has been disposed");
303
- }
304
- }
305
- }
306
-
307
- /** Max query string length to prevent ReDoS via overly complex Tree-sitter patterns. */
308
- const MAX_QUERY_LENGTH = 10_000;
309
-
310
- type StructuralTimer = ReturnType<typeof startDebugTimer>;
311
- type ParserState = "cold" | "initializing" | "reused";
312
-
313
- type StructuralTimingObservation =
314
- | {
315
- readonly operation: "parse";
316
- readonly grammar: GrammarId;
317
- readonly parserState: ParserState;
318
- readonly outcome: "completed" | "file-access-error" | "runtime-error";
319
- readonly finalPhase: "file-read" | "parse" | "parser-setup";
320
- }
321
- | {
322
- readonly operation: "query";
323
- readonly grammar: GrammarId;
324
- readonly outcome: "completed" | "runtime-error" | "validation-error";
325
- readonly captureCount: number;
326
- readonly finalPhase: "query-compilation" | "query-execution";
327
- };
328
-
329
- function finishStructuralTiming(
330
- timer: StructuralTimer,
331
- observation: StructuralTimingObservation,
332
- ): void {
333
- const { finalPhase, ...data } = observation;
334
- timer.finish(
335
- () => ({
336
- source: "tree-sitter",
337
- level: "debug",
338
- category: `structural.${data.operation}.timing`,
339
- message: `Tree-sitter ${data.operation} ${data.outcome}`,
340
- data: { ...data },
341
- }),
342
- finalPhase,
343
- );
344
- }
345
-
346
- /** Format errors with their cause chain's first message for user-facing tool output. */
347
- function formatError(err: unknown, fallback = "Operation failed"): string {
348
- if (!(err instanceof Error)) return String(err || fallback);
349
- if (err.cause instanceof Error) return `${err.message}: ${err.cause.message}`;
350
- return err.message || fallback;
351
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * TUI renderer for code_find — renderCall + renderResult.
3
- */
4
- import type { Theme } from "@earendil-works/pi-coding-agent";
5
- import { Text } from "@earendil-works/pi-tui";
6
- import { type ResultOptios, renderSimpleResult, type ToolResult } from "../../ui/tui/common.ts";
7
- import type { CodeFindToolParams } from "./execute.ts";
8
-
9
- /** ── renderCall ────────────────────────────────────────────────── */
10
-
11
- export function renderFindCall(args: unknown, theme: Theme, _context: unknown): Text {
12
- const params = (args ?? {}) as CodeFindToolParams;
13
- const mode = params.mode ?? "mode?";
14
-
15
- let content = theme.fg("toolTitle", "code_find");
16
-
17
- if (params.query) {
18
- content += ` ${theme.fg("accent", JSON.stringify(params.query))}`;
19
- }
20
-
21
- content += ` ${theme.fg("muted", mode)}`;
22
-
23
- if (params.kind) {
24
- content += theme.fg("dim", ` [${params.kind}]`);
25
- }
26
-
27
- return new Text(content, 0, 0);
28
- }
29
-
30
- /** ── renderResult ──────────────────────────────────────────────── */
31
-
32
- export function renderFindResult(
33
- result: ToolResult,
34
- options: ResultOptios,
35
- theme: Theme,
36
- _context: unknown,
37
- ): ReturnType<typeof renderSimpleResult> {
38
- return renderSimpleResult(result, options, theme, "Searching…");
39
- }
@@ -1,62 +0,0 @@
1
- /** Thin Pi adapter for the session-owned code_graph workflow. */
2
-
3
- import type { GraphWorkflowInput, RequestedGraphRelation } from "../../session/graph-types.ts";
4
- import type { GraphTargetInput } from "../../session/target-input.ts";
5
- import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
6
- import { toWorkflowControl } from "../infra/workflow-control.ts";
7
- import { searchErrorResult } from "../result/errors.ts";
8
- import { assembleGraphResult } from "../result/graph.ts";
9
- import { renderGraphResult } from "./markdown.ts";
10
-
11
- export type GraphRelation = RequestedGraphRelation;
12
-
13
- export interface CodeGraphToolParams {
14
- target: GraphTargetInput;
15
- relations?: GraphRelation[];
16
- calleeDepth?: "direct" | "deep";
17
- maxResults?: number;
18
- }
19
-
20
- export async function executeGraphTool(
21
- params: CodeGraphToolParams,
22
- ctx: CodeIntelToolExecCtx,
23
- ): Promise<CodeIntelResult> {
24
- const outcome = await ctx.session.graph(params as GraphWorkflowInput, toWorkflowControl(ctx));
25
-
26
- if (outcome.kind === "unavailable") throw new Error(outcome.reason);
27
- if (outcome.kind === "invalid-input") {
28
- return searchErrorResult(`**Error:** ${outcome.message}`);
29
- }
30
- if (outcome.kind === "disambiguation" || outcome.kind === "kind-mismatch") {
31
- const lines = [
32
- outcome.kind === "kind-mismatch"
33
- ? `**No target matched provider kind \`${outcome.requestedKind}\`. Near matches:**`
34
- : "**Target is ambiguous. Choose one candidate handle:**",
35
- "",
36
- ];
37
- for (const candidate of outcome.candidates) {
38
- lines.push(
39
- `- \`${candidate.targetId}\` — ${candidate.name} (\`${candidate.kind ?? "unknown"}\`) at ${candidate.file}:${candidate.line}:${candidate.character}`,
40
- );
41
- }
42
- if (outcome.kind === "kind-mismatch") {
43
- lines.push(
44
- "",
45
- "Retry without `symbolKind`, use an observed provider kind, or choose a handle.",
46
- );
47
- }
48
- return searchErrorResult(lines.join("\n"));
49
- }
50
-
51
- const assembly = assembleGraphResult({
52
- displayName: outcome.displayName,
53
- sections: outcome.sections,
54
- resolvedDisplayFile: outcome.resolvedDisplayFile,
55
- maxResults: outcome.maxResults,
56
- cwd: ctx.cwd,
57
- });
58
- return {
59
- content: renderGraphResult(assembly),
60
- details: { type: "search", data: assembly.details },
61
- };
62
- }