@angular-modernizer/adapter-mcp 0.2.0 → 1.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 (255) hide show
  1. package/README.md +188 -235
  2. package/dist/cli.js +77 -27
  3. package/dist/index.d.ts +11 -3
  4. package/dist/index.js +10 -2
  5. package/dist/mcp-watcher.d.ts +6 -1
  6. package/dist/mcp-watcher.js +14 -10
  7. package/dist/server/limited-stdio-transport.d.ts +68 -0
  8. package/dist/server/limited-stdio-transport.js +115 -0
  9. package/dist/server/mcp-server.d.ts +41 -12
  10. package/dist/server/mcp-server.js +113 -94
  11. package/dist/server/package-version.d.ts +16 -0
  12. package/dist/server/package-version.js +37 -0
  13. package/dist/server/sdk-server.d.ts +70 -0
  14. package/dist/server/sdk-server.js +113 -0
  15. package/dist/server/stdio-guard.d.ts +20 -0
  16. package/dist/server/stdio-guard.js +48 -0
  17. package/dist/server/tool-registry.d.ts +3 -2
  18. package/dist/server/tool-registry.js +5 -5
  19. package/dist/tools/analyze-build-impact.d.ts +346 -14
  20. package/dist/tools/analyze-build-impact.js +315 -31
  21. package/dist/tools/analyze-core-to-shared.d.ts +134 -4
  22. package/dist/tools/analyze-core-to-shared.js +113 -9
  23. package/dist/tools/analyze-parser-performance.d.ts +200 -7
  24. package/dist/tools/analyze-parser-performance.js +108 -47
  25. package/dist/tools/analyze-project.d.ts +267 -5
  26. package/dist/tools/analyze-project.js +196 -8
  27. package/dist/tools/check-incremental-compatibility.d.ts +61 -1
  28. package/dist/tools/check-incremental-compatibility.js +58 -2
  29. package/dist/tools/collect-feedback.d.ts +199 -10
  30. package/dist/tools/collect-feedback.js +171 -99
  31. package/dist/tools/compare-health.d.ts +356 -0
  32. package/dist/tools/compare-health.js +472 -0
  33. package/dist/tools/extract-libraries.d.ts +156 -4
  34. package/dist/tools/extract-libraries.js +115 -10
  35. package/dist/tools/find-angular-symbol.d.ts +98 -9
  36. package/dist/tools/find-angular-symbol.js +104 -12
  37. package/dist/tools/find-component-hosts.d.ts +684 -0
  38. package/dist/tools/find-component-hosts.js +441 -0
  39. package/dist/tools/find-usages.d.ts +99 -4
  40. package/dist/tools/find-usages.js +131 -11
  41. package/dist/tools/get-bootstrap-execution.d.ts +258 -0
  42. package/dist/tools/get-bootstrap-execution.js +324 -0
  43. package/dist/tools/get-call-graph.d.ts +139 -4
  44. package/dist/tools/get-call-graph.js +123 -13
  45. package/dist/tools/get-operation-progress-tool.d.ts +114 -2
  46. package/dist/tools/get-operation-progress-tool.js +114 -7
  47. package/dist/tools/get-operation-progress.d.ts +1 -1
  48. package/dist/tools/get-operation-progress.js +5 -5
  49. package/dist/tools/helpers/analysis-output.d.ts +177 -0
  50. package/dist/tools/helpers/analysis-output.js +165 -0
  51. package/dist/tools/helpers/build-schemas.d.ts +36 -0
  52. package/dist/tools/helpers/build-schemas.js +23 -0
  53. package/dist/tools/helpers/citation-file-source.d.ts +10 -0
  54. package/dist/tools/helpers/citation-file-source.js +82 -0
  55. package/dist/tools/helpers/compact-output.d.ts +61 -0
  56. package/dist/tools/helpers/compact-output.js +83 -0
  57. package/dist/tools/helpers/finding-window.d.ts +43 -0
  58. package/dist/tools/helpers/finding-window.js +64 -0
  59. package/dist/tools/helpers/health-delta.d.ts +86 -0
  60. package/dist/tools/helpers/health-delta.js +239 -0
  61. package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
  62. package/dist/tools/helpers/investigation-schemas.js +48 -0
  63. package/dist/tools/helpers/library-imports.d.ts +57 -0
  64. package/dist/tools/helpers/library-imports.js +151 -0
  65. package/dist/tools/helpers/load-source-files.d.ts +30 -0
  66. package/dist/tools/helpers/load-source-files.js +34 -0
  67. package/dist/tools/helpers/output-contract.d.ts +32 -0
  68. package/dist/tools/helpers/output-contract.js +32 -0
  69. package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
  70. package/dist/tools/helpers/platform-root-resolver.js +75 -48
  71. package/dist/tools/helpers/process-output.d.ts +19 -0
  72. package/dist/tools/helpers/process-output.js +31 -0
  73. package/dist/tools/helpers/project-cache.d.ts +184 -0
  74. package/dist/tools/helpers/project-cache.js +331 -0
  75. package/dist/tools/helpers/project-decorators.d.ts +14 -0
  76. package/dist/tools/helpers/project-decorators.js +22 -0
  77. package/dist/tools/helpers/rule-matcher.js +5 -0
  78. package/dist/tools/helpers/rule-runner.d.ts +72 -0
  79. package/dist/tools/helpers/rule-runner.js +131 -0
  80. package/dist/tools/helpers/scan-cache.d.ts +22 -0
  81. package/dist/tools/helpers/scan-cache.js +34 -0
  82. package/dist/tools/helpers/scan-plan.d.ts +48 -0
  83. package/dist/tools/helpers/scan-plan.js +166 -0
  84. package/dist/tools/helpers/scope-paths.d.ts +17 -0
  85. package/dist/tools/helpers/scope-paths.js +32 -0
  86. package/dist/tools/helpers/stack-frame-file-index.d.ts +10 -0
  87. package/dist/tools/helpers/stack-frame-file-index.js +71 -0
  88. package/dist/tools/helpers/tool-context.d.ts +60 -0
  89. package/dist/tools/helpers/tool-context.js +82 -0
  90. package/dist/tools/helpers/transform-safety.d.ts +40 -0
  91. package/dist/tools/helpers/transform-safety.js +87 -0
  92. package/dist/tools/helpers/validation-output.d.ts +53 -0
  93. package/dist/tools/helpers/validation-output.js +48 -0
  94. package/dist/tools/inspect-form-group.d.ts +324 -0
  95. package/dist/tools/inspect-form-group.js +279 -0
  96. package/dist/tools/inspect-i18n.d.ts +466 -0
  97. package/dist/tools/inspect-i18n.js +400 -0
  98. package/dist/tools/inspect-template.d.ts +320 -0
  99. package/dist/tools/inspect-template.js +324 -0
  100. package/dist/tools/learn-patterns.d.ts +122 -1
  101. package/dist/tools/learn-patterns.js +97 -2
  102. package/dist/tools/list-imports.d.ts +128 -11
  103. package/dist/tools/list-imports.js +128 -8
  104. package/dist/tools/orchestrate-migration.d.ts +129 -5
  105. package/dist/tools/orchestrate-migration.js +166 -12
  106. package/dist/tools/parse-stack-trace.d.ts +59 -2
  107. package/dist/tools/parse-stack-trace.js +52 -4
  108. package/dist/tools/plan-migration.d.ts +418 -1
  109. package/dist/tools/plan-migration.js +355 -8
  110. package/dist/tools/resolve-type.d.ts +42 -1
  111. package/dist/tools/resolve-type.js +37 -4
  112. package/dist/tools/review-feedback.d.ts +206 -11
  113. package/dist/tools/review-feedback.js +132 -51
  114. package/dist/tools/rollback-changes.d.ts +79 -2
  115. package/dist/tools/rollback-changes.js +66 -14
  116. package/dist/tools/run-angular-cli.d.ts +45 -2
  117. package/dist/tools/run-angular-cli.js +67 -7
  118. package/dist/tools/run-build.d.ts +114 -2
  119. package/dist/tools/run-build.js +117 -8
  120. package/dist/tools/run-schematic.d.ts +70 -2
  121. package/dist/tools/run-schematic.js +104 -10
  122. package/dist/tools/scan-all.d.ts +24 -16
  123. package/dist/tools/scan-all.js +145 -137
  124. package/dist/tools/scan-angular.d.ts +20 -11
  125. package/dist/tools/scan-angular.js +52 -24
  126. package/dist/tools/scan-architecture.d.ts +42 -14
  127. package/dist/tools/scan-architecture.js +206 -163
  128. package/dist/tools/scan-solid.d.ts +20 -11
  129. package/dist/tools/scan-solid.js +52 -24
  130. package/dist/tools/search-codebase.d.ts +85 -1
  131. package/dist/tools/search-codebase.js +61 -4
  132. package/dist/tools/server-status.d.ts +370 -0
  133. package/dist/tools/server-status.js +369 -0
  134. package/dist/tools/suggest-improvements.d.ts +97 -5
  135. package/dist/tools/suggest-improvements.js +80 -44
  136. package/dist/tools/trace-output-flow.d.ts +791 -0
  137. package/dist/tools/trace-output-flow.js +668 -0
  138. package/dist/tools/transform-code-batch.d.ts +3 -0
  139. package/dist/tools/transform-code-batch.js +10 -5
  140. package/dist/tools/transform-code.d.ts +335 -12
  141. package/dist/tools/transform-code.js +649 -608
  142. package/dist/tools/validate-before-transform.d.ts +116 -2
  143. package/dist/tools/validate-before-transform.js +55 -2
  144. package/dist/tools/validate-project-compatibility.d.ts +64 -2
  145. package/dist/tools/validate-project-compatibility.js +67 -4
  146. package/dist/tools/validate-transformation.d.ts +220 -2
  147. package/dist/tools/validate-transformation.js +113 -15
  148. package/dist/tools/verify-citations.d.ts +181 -0
  149. package/dist/tools/verify-citations.js +218 -0
  150. package/dist/types.d.ts +45 -1
  151. package/dist/utils/format-tool-response.d.ts +22 -59
  152. package/dist/utils/format-tool-response.js +25 -134
  153. package/package.json +30 -13
  154. package/dist/cli.d.ts.map +0 -1
  155. package/dist/cli.js.map +0 -1
  156. package/dist/core/project-analyzer.d.ts.map +0 -1
  157. package/dist/core/project-analyzer.js.map +0 -1
  158. package/dist/index.d.ts.map +0 -1
  159. package/dist/index.js.map +0 -1
  160. package/dist/mcp-watcher.d.ts.map +0 -1
  161. package/dist/mcp-watcher.js.map +0 -1
  162. package/dist/server/json-rpc-handler.d.ts +0 -57
  163. package/dist/server/json-rpc-handler.d.ts.map +0 -1
  164. package/dist/server/json-rpc-handler.js +0 -222
  165. package/dist/server/json-rpc-handler.js.map +0 -1
  166. package/dist/server/mcp-server.d.ts.map +0 -1
  167. package/dist/server/mcp-server.js.map +0 -1
  168. package/dist/server/tool-registry.d.ts.map +0 -1
  169. package/dist/server/tool-registry.js.map +0 -1
  170. package/dist/streaming/progress-store.d.ts.map +0 -1
  171. package/dist/streaming/progress-store.js.map +0 -1
  172. package/dist/tools/analyze-build-impact.d.ts.map +0 -1
  173. package/dist/tools/analyze-build-impact.js.map +0 -1
  174. package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
  175. package/dist/tools/analyze-core-to-shared.js.map +0 -1
  176. package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
  177. package/dist/tools/analyze-parser-performance.js.map +0 -1
  178. package/dist/tools/analyze-project.d.ts.map +0 -1
  179. package/dist/tools/analyze-project.js.map +0 -1
  180. package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
  181. package/dist/tools/check-incremental-compatibility.js.map +0 -1
  182. package/dist/tools/collect-feedback.d.ts.map +0 -1
  183. package/dist/tools/collect-feedback.js.map +0 -1
  184. package/dist/tools/extract-libraries.d.ts.map +0 -1
  185. package/dist/tools/extract-libraries.js.map +0 -1
  186. package/dist/tools/find-angular-symbol.d.ts.map +0 -1
  187. package/dist/tools/find-angular-symbol.js.map +0 -1
  188. package/dist/tools/find-usages.d.ts.map +0 -1
  189. package/dist/tools/find-usages.js.map +0 -1
  190. package/dist/tools/get-call-graph.d.ts.map +0 -1
  191. package/dist/tools/get-call-graph.js.map +0 -1
  192. package/dist/tools/get-operation-progress-tool.d.ts.map +0 -1
  193. package/dist/tools/get-operation-progress-tool.js.map +0 -1
  194. package/dist/tools/get-operation-progress.d.ts.map +0 -1
  195. package/dist/tools/get-operation-progress.js.map +0 -1
  196. package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
  197. package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
  198. package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
  199. package/dist/tools/helpers/find-ts-config.js.map +0 -1
  200. package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
  201. package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
  202. package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
  203. package/dist/tools/helpers/rule-matcher.js.map +0 -1
  204. package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
  205. package/dist/tools/helpers/suggestion-generator.js.map +0 -1
  206. package/dist/tools/learn-patterns.d.ts.map +0 -1
  207. package/dist/tools/learn-patterns.js.map +0 -1
  208. package/dist/tools/list-imports.d.ts.map +0 -1
  209. package/dist/tools/list-imports.js.map +0 -1
  210. package/dist/tools/orchestrate-migration.d.ts.map +0 -1
  211. package/dist/tools/orchestrate-migration.js.map +0 -1
  212. package/dist/tools/parse-stack-trace.d.ts.map +0 -1
  213. package/dist/tools/parse-stack-trace.js.map +0 -1
  214. package/dist/tools/plan-migration.d.ts.map +0 -1
  215. package/dist/tools/plan-migration.js.map +0 -1
  216. package/dist/tools/resolve-type.d.ts.map +0 -1
  217. package/dist/tools/resolve-type.js.map +0 -1
  218. package/dist/tools/review-feedback.d.ts.map +0 -1
  219. package/dist/tools/review-feedback.js.map +0 -1
  220. package/dist/tools/rollback-changes.d.ts.map +0 -1
  221. package/dist/tools/rollback-changes.js.map +0 -1
  222. package/dist/tools/run-angular-cli.d.ts.map +0 -1
  223. package/dist/tools/run-angular-cli.js.map +0 -1
  224. package/dist/tools/run-build.d.ts.map +0 -1
  225. package/dist/tools/run-build.js.map +0 -1
  226. package/dist/tools/run-schematic.d.ts.map +0 -1
  227. package/dist/tools/run-schematic.js.map +0 -1
  228. package/dist/tools/scan-all.d.ts.map +0 -1
  229. package/dist/tools/scan-all.js.map +0 -1
  230. package/dist/tools/scan-angular.d.ts.map +0 -1
  231. package/dist/tools/scan-angular.js.map +0 -1
  232. package/dist/tools/scan-architecture.d.ts.map +0 -1
  233. package/dist/tools/scan-architecture.js.map +0 -1
  234. package/dist/tools/scan-solid.d.ts.map +0 -1
  235. package/dist/tools/scan-solid.js.map +0 -1
  236. package/dist/tools/search-codebase.d.ts.map +0 -1
  237. package/dist/tools/search-codebase.js.map +0 -1
  238. package/dist/tools/shared/scan-types.d.ts.map +0 -1
  239. package/dist/tools/shared/scan-types.js.map +0 -1
  240. package/dist/tools/suggest-improvements.d.ts.map +0 -1
  241. package/dist/tools/suggest-improvements.js.map +0 -1
  242. package/dist/tools/transform-code-batch.d.ts.map +0 -1
  243. package/dist/tools/transform-code-batch.js.map +0 -1
  244. package/dist/tools/transform-code.d.ts.map +0 -1
  245. package/dist/tools/transform-code.js.map +0 -1
  246. package/dist/tools/validate-before-transform.d.ts.map +0 -1
  247. package/dist/tools/validate-before-transform.js.map +0 -1
  248. package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
  249. package/dist/tools/validate-project-compatibility.js.map +0 -1
  250. package/dist/tools/validate-transformation.d.ts.map +0 -1
  251. package/dist/tools/validate-transformation.js.map +0 -1
  252. package/dist/types.d.ts.map +0 -1
  253. package/dist/types.js.map +0 -1
  254. package/dist/utils/format-tool-response.d.ts.map +0 -1
  255. package/dist/utils/format-tool-response.js.map +0 -1
@@ -0,0 +1,441 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Find Component Hosts Tool
3
+ *
4
+ * MCP tool that lists every template using a component or directive and,
5
+ * per host, which inputs and outputs are bound, unbound or missing, plus
6
+ * the places creating a component in code (dialogs, `createComponent`,
7
+ * wrappers) as `dynamicHosts`.
8
+ *
9
+ * @remarks
10
+ * Logic lives in `ComponentHostFinder` (`@angular-modernizer/api`); this tool
11
+ * resolves the project, validates arguments and applies the compact output
12
+ * contract (`maxResults` caps the host list and the dynamic host list each).
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Via MCP:
17
+ * // tool: find-component-hosts
18
+ * // args: { className: 'ItemComponent', projectRoot: '/project' }
19
+ * ```
20
+ */
21
+ import { ComponentHostFinder, } from '@angular-modernizer/api';
22
+ import { existsSync } from 'node:fs';
23
+ import { isAbsolute, resolve } from 'node:path';
24
+ import { findTsConfig } from './helpers/find-ts-config.js';
25
+ import { ProjectCache } from './helpers/project-cache.js';
26
+ import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, truncationNote, } from './helpers/compact-output.js';
27
+ import { configuredComponentDecorators } from './helpers/project-decorators.js';
28
+ import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
29
+ import { ALTERNATIVES_SCHEMA, DYNAMIC_RESULT_USE_SCHEMA, DYNAMIC_ROUTE_SCHEMA, STRING_ARRAY, } from './helpers/investigation-schemas.js';
30
+ /** Host names listed per input/output in the text summary. */
31
+ const SUMMARY_MAX_NAMES = 5;
32
+ const IO_MEMBER_SCHEMA = {
33
+ type: 'object',
34
+ properties: {
35
+ name: { type: 'string' },
36
+ property: { type: 'string' },
37
+ required: { type: 'boolean' },
38
+ source: { type: 'string' },
39
+ inheritedFrom: { type: 'string' },
40
+ },
41
+ required: ['name', 'property', 'source'],
42
+ };
43
+ const COVERAGE_MAP_SCHEMA = {
44
+ type: 'object',
45
+ additionalProperties: {
46
+ type: 'object',
47
+ properties: {
48
+ bound: { type: 'integer' },
49
+ unbound: { type: 'integer' },
50
+ boundIn: STRING_ARRAY,
51
+ unboundIn: STRING_ARRAY,
52
+ },
53
+ required: ['bound', 'unbound'],
54
+ },
55
+ };
56
+ const BINDING_LISTS = {
57
+ boundInputs: STRING_ARRAY,
58
+ boundOutputs: STRING_ARRAY,
59
+ unboundInputs: STRING_ARRAY,
60
+ unboundOutputs: STRING_ARRAY,
61
+ };
62
+ const TEMPLATE_HOST_SCHEMA = {
63
+ type: 'object',
64
+ properties: {
65
+ kind: { type: 'string' },
66
+ component: { type: 'string' },
67
+ componentFile: { type: 'string' },
68
+ templateFile: { type: 'string' },
69
+ occurrences: {
70
+ type: 'array',
71
+ items: {
72
+ type: 'object',
73
+ properties: {
74
+ templateFile: { type: 'string' },
75
+ line: { type: 'integer' },
76
+ col: { type: 'integer' },
77
+ tag: { type: 'string' },
78
+ ...BINDING_LISTS,
79
+ missingRequiredInputs: STRING_ARRAY,
80
+ otherBindings: STRING_ARRAY,
81
+ structural: { type: 'string' },
82
+ },
83
+ required: [
84
+ 'templateFile',
85
+ 'line',
86
+ 'col',
87
+ 'tag',
88
+ 'boundInputs',
89
+ 'boundOutputs',
90
+ 'unboundInputs',
91
+ 'unboundOutputs',
92
+ 'missingRequiredInputs',
93
+ 'otherBindings',
94
+ ],
95
+ },
96
+ },
97
+ ...BINDING_LISTS,
98
+ },
99
+ required: [
100
+ 'kind',
101
+ 'component',
102
+ 'componentFile',
103
+ 'templateFile',
104
+ 'boundInputs',
105
+ 'boundOutputs',
106
+ 'unboundInputs',
107
+ 'unboundOutputs',
108
+ ],
109
+ };
110
+ const DYNAMIC_HOST_SCHEMA = {
111
+ type: 'object',
112
+ properties: {
113
+ kind: { type: 'string' },
114
+ component: { type: 'string' },
115
+ componentFile: { type: 'string' },
116
+ file: { type: 'string' },
117
+ line: { type: 'integer' },
118
+ col: { type: 'integer' },
119
+ in: { type: 'string' },
120
+ sink: { type: 'string' },
121
+ via: STRING_ARRAY,
122
+ resolution: STRING_ARRAY,
123
+ componentArgument: { type: 'integer' },
124
+ arguments: {
125
+ type: 'array',
126
+ items: {
127
+ type: 'object',
128
+ properties: {
129
+ index: { type: 'integer' },
130
+ parameter: { type: 'string' },
131
+ text: { type: 'string' },
132
+ data: { type: 'string' },
133
+ },
134
+ required: ['index', 'text'],
135
+ },
136
+ },
137
+ result: DYNAMIC_RESULT_USE_SCHEMA,
138
+ route: DYNAMIC_ROUTE_SCHEMA,
139
+ certainty: { type: 'string' },
140
+ selectorExpression: { type: 'string' },
141
+ selectorLiterals: STRING_ARRAY,
142
+ },
143
+ required: [
144
+ 'kind',
145
+ 'component',
146
+ 'componentFile',
147
+ 'file',
148
+ 'line',
149
+ 'col',
150
+ 'in',
151
+ 'sink',
152
+ 'via',
153
+ 'resolution',
154
+ 'arguments',
155
+ 'result',
156
+ ],
157
+ };
158
+ /**
159
+ * MCP tool that finds the template hosts of a component or directive.
160
+ */
161
+ export class FindComponentHostsTool {
162
+ projects;
163
+ name = 'find-component-hosts';
164
+ title = 'Find Component Hosts';
165
+ annotations = {
166
+ readOnlyHint: true,
167
+ destructiveHint: false,
168
+ idempotentHint: true,
169
+ openWorldHint: false,
170
+ };
171
+ constructor(projects = new ProjectCache()) {
172
+ this.projects = projects;
173
+ }
174
+ description = 'Find every component template that uses a component or directive (by className or selector) ' +
175
+ 'and report per host: template file, element occurrences with line, which of the target\'s ' +
176
+ 'inputs and outputs are bound or unbound, required inputs that are missing, and bindings no ' +
177
+ 'matched project directive declares (native events, library directives, typos). coverage ' +
178
+ 'lists per input/output which hosts bind it and which do not (e.g. "which hosts ignore ' +
179
+ '(formError)?"). Inputs/outputs come from @Input/@Output (aliases, required), signal input(), ' +
180
+ 'input.required(), model(), output(), decorator inputs/outputs arrays and base classes. Test ' +
181
+ 'hosts in spec files are skipped unless includeTestHosts. dynamicHosts lists places creating a ' +
182
+ 'component in code: any call or new whose parameter takes a component type (MatDialog.open, ' +
183
+ 'createComponent, ComponentPortal, project dialog wrappers), with sink, via (wrapper chain down ' +
184
+ 'to the library call), resolution (literal, variable, field, di-token, method-return, callback, ' +
185
+ 'selector, lazy-import, registry, promise), the other arguments (data) and what the caller does ' +
186
+ 'with the result (e.g. afterClosed.subscribe; a stored result shows the use that subscribes to it). Route entries (component, loadComponent) are ' +
187
+ 'dynamic hosts with route: path joined over children, guards, data, resolve, lazy. candidateHosts ' +
188
+ 'lists places that may create it: lookups in a component registry (e.g. dynamicComponents) whose ' +
189
+ 'selector comes from data (selectorExpression, selectorLiterals); a selector fixed by literals, a ' +
190
+ 'switch mapping or an equality guard is decided (dynamicHosts or nothing). includeDynamic: false ' +
191
+ 'skips both. ' +
192
+ 'For result and data flow of a dialog use trace-output-flow. For widely used components start with ' +
193
+ 'summaryOnly (counts per input/output only). summaryOnly drops the host list, ' +
194
+ 'maxResults caps it and the host names in coverage; counts (incl. coverage bound/unbound) always ' +
195
+ 'cover all hosts.';
196
+ inputSchema = {
197
+ type: 'object',
198
+ additionalProperties: false,
199
+ properties: {
200
+ className: {
201
+ type: 'string',
202
+ description: 'Class name of the component or directive. Give className or selector.',
203
+ },
204
+ selector: {
205
+ type: 'string',
206
+ description: 'Selector of the component or directive, e.g. "app-item" or "[appTooltip]". Give className or selector.',
207
+ },
208
+ file: {
209
+ type: 'string',
210
+ description: 'File declaring the class (absolute, or relative to projectRoot). Picks one of several same-name classes. Optional.',
211
+ },
212
+ projectRoot: {
213
+ type: 'string',
214
+ description: 'Absolute path to the project root. Must contain a tsconfig.json.',
215
+ },
216
+ includeOccurrences: {
217
+ type: 'boolean',
218
+ description: 'Include per-element occurrences with line and bindings. Default: true.',
219
+ default: true,
220
+ },
221
+ includeTestHosts: {
222
+ type: 'boolean',
223
+ description: 'Also report test host components declared in *.spec.ts / *.test.ts. Default: false.',
224
+ default: false,
225
+ },
226
+ includeDynamic: {
227
+ type: 'boolean',
228
+ description: 'Also find places creating the component in code (dialogs, createComponent, wrappers) as dynamicHosts. Default: true.',
229
+ default: true,
230
+ },
231
+ ...COMPACT_OUTPUT_SCHEMA,
232
+ },
233
+ required: ['projectRoot'],
234
+ };
235
+ outputSchema = {
236
+ type: 'object',
237
+ properties: {
238
+ target: {
239
+ type: 'object',
240
+ properties: {
241
+ className: { type: 'string' },
242
+ kind: { type: 'string' },
243
+ selector: { type: 'string' },
244
+ file: { type: 'string' },
245
+ inputs: { type: 'array', items: IO_MEMBER_SCHEMA },
246
+ outputs: { type: 'array', items: IO_MEMBER_SCHEMA },
247
+ },
248
+ required: ['className', 'kind', 'selector', 'file', 'inputs', 'outputs'],
249
+ },
250
+ alternatives: ALTERNATIVES_SCHEMA,
251
+ counts: {
252
+ type: 'object',
253
+ properties: {
254
+ hosts: { type: 'integer' },
255
+ occurrences: { type: 'integer' },
256
+ templatesScanned: { type: 'integer' },
257
+ occurrencesMissingRequired: { type: 'integer' },
258
+ dynamicHosts: { type: 'integer' },
259
+ candidateHosts: { type: 'integer' },
260
+ },
261
+ required: [
262
+ 'hosts',
263
+ 'occurrences',
264
+ 'templatesScanned',
265
+ 'occurrencesMissingRequired',
266
+ 'dynamicHosts',
267
+ 'candidateHosts',
268
+ ],
269
+ },
270
+ coverage: {
271
+ type: 'object',
272
+ properties: { inputs: COVERAGE_MAP_SCHEMA, outputs: COVERAGE_MAP_SCHEMA },
273
+ required: ['inputs', 'outputs'],
274
+ },
275
+ hosts: { type: 'array', items: TEMPLATE_HOST_SCHEMA },
276
+ truncated: { type: 'boolean' },
277
+ dynamicHosts: { type: 'array', items: DYNAMIC_HOST_SCHEMA },
278
+ dynamicTruncated: { type: 'boolean' },
279
+ candidateHosts: { type: 'array', items: DYNAMIC_HOST_SCHEMA },
280
+ candidateTruncated: { type: 'boolean' },
281
+ summary: { type: 'string' },
282
+ tsConfigPath: { type: 'string' },
283
+ ...WARNINGS_OUTPUT_SCHEMA,
284
+ },
285
+ required: [
286
+ 'alternatives',
287
+ 'counts',
288
+ 'coverage',
289
+ 'truncated',
290
+ 'dynamicTruncated',
291
+ 'candidateTruncated',
292
+ 'summary',
293
+ 'tsConfigPath',
294
+ ],
295
+ };
296
+ async execute(args) {
297
+ const params = args;
298
+ if (!params.className && !params.selector) {
299
+ throw new Error('className or selector is required');
300
+ }
301
+ if (!params.projectRoot) {
302
+ throw new Error('projectRoot is required');
303
+ }
304
+ const compact = parseCompactOptions(args);
305
+ if (!existsSync(params.projectRoot)) {
306
+ throw new Error(`projectRoot does not exist: ${params.projectRoot}`);
307
+ }
308
+ const tsConfigPath = findTsConfig(params.projectRoot);
309
+ if (!tsConfigPath) {
310
+ throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
311
+ }
312
+ const file = params.file === undefined || isAbsolute(params.file)
313
+ ? params.file
314
+ : resolve(params.projectRoot, params.file);
315
+ const finder = new ComponentHostFinder(this.projects.get(tsConfigPath), {
316
+ componentDecorators: configuredComponentDecorators(params.projectRoot),
317
+ includeTestHosts: params.includeTestHosts === true,
318
+ includeDynamic: params.includeDynamic !== false,
319
+ });
320
+ const result = finder.findHosts({
321
+ ...(params.className ? { className: params.className } : {}),
322
+ ...(params.selector ? { selector: params.selector } : {}),
323
+ ...(file === undefined ? {} : { file }),
324
+ });
325
+ const { hosts, coverage, dynamicHosts, candidateHosts, ...rest } = result;
326
+ const summary = this.buildSummary(params, result);
327
+ const warnings = this.projects.warnings(tsConfigPath);
328
+ if (compact.summaryOnly) {
329
+ return withWarnings({
330
+ ...rest,
331
+ coverage: this.shapeCoverage(coverage, (c) => ({ bound: c.bound, unbound: c.unbound })),
332
+ truncated: false,
333
+ dynamicTruncated: false,
334
+ candidateTruncated: false,
335
+ summary,
336
+ tsConfigPath,
337
+ }, warnings);
338
+ }
339
+ const includeOccurrences = params.includeOccurrences !== false;
340
+ const shown = limitList(hosts, compact.maxResults);
341
+ const shownDynamic = limitList(dynamicHosts, compact.maxResults);
342
+ const shownCandidates = limitList(candidateHosts, compact.maxResults);
343
+ const note = [
344
+ truncationNote(shown.items.length, hosts.length, 'hosts'),
345
+ truncationNote(shownDynamic.items.length, dynamicHosts.length, 'dynamic hosts'),
346
+ truncationNote(shownCandidates.items.length, candidateHosts.length, 'candidate hosts'),
347
+ ]
348
+ .filter((n) => n !== undefined)
349
+ .join('\n');
350
+ const cappedCoverage = this.shapeCoverage(coverage, (c) => ({
351
+ ...c,
352
+ boundIn: limitList(c.boundIn, compact.maxResults).items,
353
+ unboundIn: limitList(c.unboundIn, compact.maxResults).items,
354
+ }));
355
+ return withWarnings({
356
+ ...rest,
357
+ coverage: cappedCoverage,
358
+ hosts: shown.items.map((h) => {
359
+ if (includeOccurrences) {
360
+ return h;
361
+ }
362
+ const { occurrences: _dropped, ...host } = h;
363
+ return host;
364
+ }),
365
+ truncated: shown.truncated,
366
+ dynamicHosts: shownDynamic.items,
367
+ dynamicTruncated: shownDynamic.truncated,
368
+ candidateHosts: shownCandidates.items,
369
+ candidateTruncated: shownCandidates.truncated,
370
+ summary: note ? `${note}\n${summary}` : summary,
371
+ tsConfigPath,
372
+ }, warnings);
373
+ }
374
+ buildSummary(params, result) {
375
+ const target = result.target;
376
+ if (target === undefined) {
377
+ const wanted = params.className ?? params.selector ?? '';
378
+ return (`No project component or directive matches '${wanted}'. Only classes with @Component, ` +
379
+ 'a decorator from parser.componentDecorators or @Directive and a selector in the tsconfig ' +
380
+ 'program are known; library ' +
381
+ 'components are not. Check the name with find-angular-symbol.');
382
+ }
383
+ const lines = [
384
+ `${target.className} (${target.selector}): ${result.counts.hosts} host(s), ` +
385
+ `${result.counts.occurrences} occurrence(s) in ${result.counts.templatesScanned} candidate template(s).`,
386
+ ];
387
+ if (result.alternatives.length > 0) {
388
+ lines.push(` Also matched: ${result.alternatives.map((a) => `${a.className} (${a.file})`).join(', ')}. ` +
389
+ 'Pass file to pick one.');
390
+ }
391
+ for (const [kind, coverage] of [
392
+ ['input', result.coverage.inputs],
393
+ ['output', result.coverage.outputs],
394
+ ]) {
395
+ for (const [name, c] of Object.entries(coverage)) {
396
+ const unbound = c.unbound > 0 ? `, not in ${c.unbound} (${this.nameList(c.unboundIn)})` : '';
397
+ lines.push(` ${kind} ${name}: bound in ${c.bound}${unbound}`);
398
+ }
399
+ }
400
+ if (result.counts.occurrencesMissingRequired > 0) {
401
+ lines.push(` ${result.counts.occurrencesMissingRequired} occurrence(s) miss a required input.`);
402
+ }
403
+ if (result.counts.dynamicHosts > 0) {
404
+ lines.push(` Created in code at ${result.counts.dynamicHosts} place(s): ${this.sinkList(result.dynamicHosts)}.`);
405
+ }
406
+ const routes = result.dynamicHosts.filter((h) => h.route !== undefined);
407
+ if (routes.length > 0) {
408
+ lines.push(` Routes: ${this.nameList(routes.map((h) => `/${h.route?.path ?? ''}${h.route?.lazy === true ? ' (lazy)' : ''}`))}.`);
409
+ }
410
+ if (result.counts.candidateHosts > 0) {
411
+ const expressions = [...new Set(result.candidateHosts.map((h) => h.selectorExpression ?? '?'))];
412
+ lines.push(` May be created at ${result.counts.candidateHosts} more place(s) through a component registry with a ` +
413
+ `selector from data (${this.nameList(expressions)}).`);
414
+ }
415
+ if (result.counts.hosts === 0 && result.counts.dynamicHosts === 0 && result.counts.candidateHosts === 0) {
416
+ lines.push(params.includeDynamic === false
417
+ ? ' No template uses it. It may be created in code; run again without includeDynamic: false.'
418
+ : ' No template uses it and no creation in code, route or registry lookup was found; ' +
419
+ 'check with find-usages.');
420
+ }
421
+ return lines.join('\n');
422
+ }
423
+ shapeCoverage(coverage, shape) {
424
+ const map = (entries) => Object.fromEntries(Object.entries(entries).map(([name, c]) => [name, shape(c)]));
425
+ return { inputs: map(coverage.inputs), outputs: map(coverage.outputs) };
426
+ }
427
+ /** `AppDialog.open 24, new AppDialogRef 2` */
428
+ sinkList(hosts) {
429
+ const counts = new Map();
430
+ for (const h of hosts) {
431
+ counts.set(h.sink, (counts.get(h.sink) ?? 0) + 1);
432
+ }
433
+ const sorted = [...counts.entries()].sort((a, b) => b[1] - a[1]).map(([sink, n]) => `${sink} ${n}`);
434
+ return this.nameList(sorted);
435
+ }
436
+ nameList(names) {
437
+ const shown = names.slice(0, SUMMARY_MAX_NAMES).join(', ');
438
+ return names.length > SUMMARY_MAX_NAMES ? `${shown}, +${names.length - SUMMARY_MAX_NAMES} more` : shown;
439
+ }
440
+ }
441
+ //# sourceMappingURL=find-component-hosts.js.map
@@ -16,32 +16,53 @@
16
16
  * // args: { symbol: 'UserService', projectRoot: '/my/project', file: '/my/project/src/app/user.component.ts' }
17
17
  * ```
18
18
  */
19
- import { type MCPTool } from '../types.js';
19
+ import { type MCPTool, type ToolAnnotations } from '../types.js';
20
20
  import { type SymbolUsage, type UsageType } from '@angular-modernizer/api';
21
+ import { ProjectCache } from './helpers/project-cache.js';
21
22
  /**
22
23
  * Output of the find-usages tool.
23
24
  */
24
25
  interface FindUsagesOutput {
25
- /** All matching usages. */
26
- usages: SymbolUsage[];
27
- /** Total number of usages found. */
26
+ /** Matching usages, cut to `maxResults`; omitted with `summaryOnly`. */
27
+ usages?: SymbolUsage[];
28
+ /** Total number of usages found (before `maxResults`). */
28
29
  totalCount: number;
30
+ /** `true` when `maxResults` cut the usage list. */
31
+ truncated: boolean;
29
32
  /** Human-readable summary for LLM consumption. */
30
33
  summary: string;
31
34
  /** Usage counts per usage type. */
32
35
  countsByType: Partial<Record<UsageType, number>>;
36
+ /** Usage counts per directory (up to 3 levels below projectRoot), largest first. */
37
+ countsByDirectory: Record<string, number>;
33
38
  /** The tsconfig whose program was searched. */
34
39
  tsConfigPath: string;
40
+ /** Conditions that can make the result incomplete (unresolved library imports). */
41
+ warnings?: string[];
35
42
  }
36
43
  /**
37
44
  * MCP tool that finds all references to a named symbol across a TypeScript project.
38
45
  */
39
46
  export declare class FindUsagesTool implements MCPTool {
47
+ private readonly projects;
40
48
  readonly name = "find-usages";
49
+ readonly title = "Find Usages";
50
+ readonly annotations: ToolAnnotations;
51
+ constructor(projects?: ProjectCache);
41
52
  readonly description: string;
42
53
  readonly inputSchema: {
43
54
  type: string;
55
+ additionalProperties: boolean;
44
56
  properties: {
57
+ summaryOnly: {
58
+ readonly type: "boolean";
59
+ readonly description: "Return counts and the text summary only, without the result list. Default: false.";
60
+ readonly default: false;
61
+ };
62
+ maxResults: {
63
+ readonly type: "number";
64
+ readonly description: string;
65
+ };
45
66
  symbol: {
46
67
  type: string;
47
68
  description: string;
@@ -70,7 +91,81 @@ export declare class FindUsagesTool implements MCPTool {
70
91
  };
71
92
  required: string[];
72
93
  };
94
+ readonly outputSchema: {
95
+ type: string;
96
+ properties: {
97
+ warnings: {
98
+ readonly type: "array";
99
+ readonly items: {
100
+ readonly type: "string";
101
+ };
102
+ readonly description: "Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.";
103
+ };
104
+ usages: {
105
+ type: string;
106
+ items: {
107
+ type: string;
108
+ properties: {
109
+ file: {
110
+ type: string;
111
+ };
112
+ line: {
113
+ type: string;
114
+ };
115
+ col: {
116
+ type: string;
117
+ };
118
+ snippet: {
119
+ type: string;
120
+ };
121
+ usageType: {
122
+ type: string;
123
+ };
124
+ note: {
125
+ type: string;
126
+ };
127
+ templateKind: {
128
+ type: string;
129
+ };
130
+ templateMatch: {
131
+ type: string;
132
+ };
133
+ component: {
134
+ type: string;
135
+ };
136
+ };
137
+ required: string[];
138
+ };
139
+ };
140
+ totalCount: {
141
+ type: string;
142
+ };
143
+ truncated: {
144
+ type: string;
145
+ };
146
+ summary: {
147
+ type: string;
148
+ };
149
+ countsByType: {
150
+ type: string;
151
+ additionalProperties: {
152
+ type: string;
153
+ };
154
+ };
155
+ countsByDirectory: {
156
+ type: string;
157
+ additionalProperties: {
158
+ type: string;
159
+ };
160
+ };
161
+ tsConfigPath: {
162
+ type: string;
163
+ };
164
+ };
165
+ required: string[];
166
+ };
73
167
  execute(args: Record<string, unknown>): Promise<FindUsagesOutput>;
168
+ private buildCompactSummary;
74
169
  private buildSummary;
75
170
  }
76
171
  export {};