@angular-modernizer/adapter-mcp 0.3.0 → 1.1.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 (298) hide show
  1. package/README.md +181 -282
  2. package/dist/cli.js +21 -13
  3. package/dist/core/project-analyzer.d.ts +3 -12
  4. package/dist/core/project-analyzer.js +3 -12
  5. package/dist/index.d.ts +122 -6
  6. package/dist/index.js +49 -5
  7. package/dist/mcp-watcher.d.ts +32 -7
  8. package/dist/mcp-watcher.js +16 -15
  9. package/dist/scan-host/scan-host.d.ts +119 -0
  10. package/dist/scan-host/scan-host.js +376 -0
  11. package/dist/scan-host/scan-protocol.d.ts +35 -0
  12. package/dist/scan-host/scan-protocol.js +6 -0
  13. package/dist/scan-host/scan-worker.d.ts +14 -0
  14. package/dist/scan-host/scan-worker.js +48 -0
  15. package/dist/server/limited-stdio-transport.d.ts +75 -0
  16. package/dist/server/limited-stdio-transport.js +115 -0
  17. package/dist/server/mcp-server.d.ts +20 -18
  18. package/dist/server/mcp-server.js +42 -79
  19. package/dist/server/package-version.d.ts +16 -0
  20. package/dist/server/package-version.js +37 -0
  21. package/dist/server/sdk-server.d.ts +71 -0
  22. package/dist/server/sdk-server.js +113 -0
  23. package/dist/server/tool-registry.d.ts +6 -9
  24. package/dist/server/tool-registry.js +6 -12
  25. package/dist/streaming/progress-store.d.ts +22 -5
  26. package/dist/streaming/progress-store.js +9 -5
  27. package/dist/tools/analyze-build-impact.d.ts +276 -35
  28. package/dist/tools/analyze-build-impact.js +175 -28
  29. package/dist/tools/analyze-core-to-shared.d.ts +176 -16
  30. package/dist/tools/analyze-core-to-shared.js +124 -19
  31. package/dist/tools/analyze-parser-performance.d.ts +209 -15
  32. package/dist/tools/analyze-parser-performance.js +119 -56
  33. package/dist/tools/analyze-project.d.ts +349 -17
  34. package/dist/tools/analyze-project.js +282 -97
  35. package/dist/tools/check-incremental-compatibility.d.ts +74 -12
  36. package/dist/tools/check-incremental-compatibility.js +69 -10
  37. package/dist/tools/collect-feedback.d.ts +225 -21
  38. package/dist/tools/collect-feedback.js +199 -118
  39. package/dist/tools/compare-health.d.ts +413 -0
  40. package/dist/tools/compare-health.js +479 -0
  41. package/dist/tools/extract-libraries.d.ts +200 -24
  42. package/dist/tools/extract-libraries.js +131 -27
  43. package/dist/tools/find-angular-symbol.d.ts +92 -24
  44. package/dist/tools/find-angular-symbol.js +70 -20
  45. package/dist/tools/find-component-hosts.d.ts +603 -27
  46. package/dist/tools/find-component-hosts.js +223 -19
  47. package/dist/tools/find-usages.d.ts +102 -22
  48. package/dist/tools/find-usages.js +81 -21
  49. package/dist/tools/get-bootstrap-execution.d.ts +183 -25
  50. package/dist/tools/get-bootstrap-execution.js +109 -25
  51. package/dist/tools/get-call-graph.d.ts +127 -12
  52. package/dist/tools/get-call-graph.js +84 -19
  53. package/dist/tools/get-operation-progress-tool.d.ts +126 -8
  54. package/dist/tools/get-operation-progress-tool.js +124 -12
  55. package/dist/tools/get-operation-progress.d.ts +27 -1
  56. package/dist/tools/get-operation-progress.js +5 -5
  57. package/dist/tools/helpers/analysis-output.d.ts +182 -0
  58. package/dist/tools/helpers/analysis-output.js +165 -0
  59. package/dist/tools/helpers/batch-kernel.d.ts +14 -0
  60. package/dist/tools/helpers/batch-kernel.js +12 -0
  61. package/dist/tools/helpers/build-schemas.d.ts +36 -0
  62. package/dist/tools/helpers/build-schemas.js +23 -0
  63. package/dist/tools/helpers/citation-file-source.d.ts +10 -0
  64. package/dist/tools/helpers/citation-file-source.js +82 -0
  65. package/dist/tools/helpers/compact-output.d.ts +2 -1
  66. package/dist/tools/helpers/compact-output.js +2 -1
  67. package/dist/tools/helpers/finding-window.d.ts +43 -0
  68. package/dist/tools/helpers/finding-window.js +64 -0
  69. package/dist/tools/helpers/health-delta.d.ts +99 -0
  70. package/dist/tools/helpers/health-delta.js +236 -0
  71. package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
  72. package/dist/tools/helpers/investigation-schemas.js +48 -0
  73. package/dist/tools/helpers/library-imports.d.ts +57 -0
  74. package/dist/tools/helpers/library-imports.js +151 -0
  75. package/dist/tools/helpers/load-source-files.d.ts +30 -0
  76. package/dist/tools/helpers/load-source-files.js +34 -0
  77. package/dist/tools/helpers/output-contract.d.ts +32 -0
  78. package/dist/tools/helpers/output-contract.js +32 -0
  79. package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
  80. package/dist/tools/helpers/platform-root-resolver.js +75 -48
  81. package/dist/tools/helpers/process-output.d.ts +19 -0
  82. package/dist/tools/helpers/process-output.js +31 -0
  83. package/dist/tools/helpers/project-cache.d.ts +60 -37
  84. package/dist/tools/helpers/project-cache.js +54 -37
  85. package/dist/tools/helpers/project-decorators.d.ts +14 -0
  86. package/dist/tools/helpers/project-decorators.js +22 -0
  87. package/dist/tools/helpers/rule-matcher.js +5 -0
  88. package/dist/tools/helpers/rule-runner.d.ts +25 -13
  89. package/dist/tools/helpers/rule-runner.js +45 -24
  90. package/dist/tools/helpers/scan-cache.d.ts +22 -0
  91. package/dist/tools/helpers/scan-cache.js +34 -0
  92. package/dist/tools/helpers/scan-engine.d.ts +107 -0
  93. package/dist/tools/helpers/scan-engine.js +197 -0
  94. package/dist/tools/helpers/scan-plan.d.ts +5 -2
  95. package/dist/tools/helpers/scan-plan.js +18 -3
  96. package/dist/tools/helpers/scope-paths.d.ts +17 -0
  97. package/dist/tools/helpers/scope-paths.js +32 -0
  98. package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
  99. package/dist/tools/helpers/suggestion-generator.js +0 -12
  100. package/dist/tools/helpers/tool-cache.d.ts +11 -0
  101. package/dist/tools/helpers/tool-cache.js +15 -0
  102. package/dist/tools/helpers/tool-context.d.ts +63 -0
  103. package/dist/tools/helpers/tool-context.js +79 -0
  104. package/dist/tools/helpers/transform-safety.d.ts +40 -0
  105. package/dist/tools/helpers/transform-safety.js +87 -0
  106. package/dist/tools/helpers/validation-output.d.ts +53 -0
  107. package/dist/tools/helpers/validation-output.js +48 -0
  108. package/dist/tools/inspect-form-group.d.ts +262 -24
  109. package/dist/tools/inspect-form-group.js +134 -13
  110. package/dist/tools/inspect-i18n.d.ts +410 -23
  111. package/dist/tools/inspect-i18n.js +213 -13
  112. package/dist/tools/inspect-template.d.ts +260 -22
  113. package/dist/tools/inspect-template.js +174 -13
  114. package/dist/tools/learn-patterns.d.ts +210 -13
  115. package/dist/tools/learn-patterns.js +113 -12
  116. package/dist/tools/list-imports.d.ts +152 -34
  117. package/dist/tools/list-imports.js +124 -18
  118. package/dist/tools/orchestrate-migration.d.ts +159 -14
  119. package/dist/tools/orchestrate-migration.js +147 -20
  120. package/dist/tools/parse-stack-trace.d.ts +78 -21
  121. package/dist/tools/parse-stack-trace.js +44 -7
  122. package/dist/tools/plan-migration.d.ts +395 -26
  123. package/dist/tools/plan-migration.js +173 -22
  124. package/dist/tools/resolve-type.d.ts +57 -9
  125. package/dist/tools/resolve-type.js +49 -12
  126. package/dist/tools/review-feedback.d.ts +214 -16
  127. package/dist/tools/review-feedback.js +142 -57
  128. package/dist/tools/rollback-changes.d.ts +88 -7
  129. package/dist/tools/rollback-changes.js +74 -19
  130. package/dist/tools/run-angular-cli.d.ts +57 -12
  131. package/dist/tools/run-angular-cli.js +76 -13
  132. package/dist/tools/run-build.d.ts +127 -13
  133. package/dist/tools/run-build.js +128 -16
  134. package/dist/tools/run-schematic.d.ts +82 -12
  135. package/dist/tools/run-schematic.js +115 -18
  136. package/dist/tools/scan-all.d.ts +88 -23
  137. package/dist/tools/scan-all.js +161 -220
  138. package/dist/tools/scan-angular.d.ts +60 -19
  139. package/dist/tools/scan-angular.js +100 -141
  140. package/dist/tools/scan-architecture.d.ts +92 -24
  141. package/dist/tools/scan-architecture.js +268 -211
  142. package/dist/tools/scan-solid.d.ts +59 -19
  143. package/dist/tools/scan-solid.js +98 -139
  144. package/dist/tools/search-codebase.d.ts +110 -23
  145. package/dist/tools/search-codebase.js +67 -11
  146. package/dist/tools/server-status.d.ts +392 -26
  147. package/dist/tools/server-status.js +260 -27
  148. package/dist/tools/suggest-improvements.d.ts +105 -10
  149. package/dist/tools/suggest-improvements.js +91 -51
  150. package/dist/tools/trace-output-flow.d.ts +713 -26
  151. package/dist/tools/trace-output-flow.js +396 -33
  152. package/dist/tools/transform-code-batch.d.ts +3 -0
  153. package/dist/tools/transform-code-batch.js +10 -5
  154. package/dist/tools/transform-code.d.ts +402 -18
  155. package/dist/tools/transform-code.js +708 -649
  156. package/dist/tools/validate-before-transform.d.ts +136 -7
  157. package/dist/tools/validate-before-transform.js +65 -9
  158. package/dist/tools/validate-project-compatibility.d.ts +82 -15
  159. package/dist/tools/validate-project-compatibility.js +84 -15
  160. package/dist/tools/validate-transformation.d.ts +243 -8
  161. package/dist/tools/validate-transformation.js +127 -23
  162. package/dist/tools/verify-citations.d.ts +202 -0
  163. package/dist/tools/verify-citations.js +221 -0
  164. package/dist/types.d.ts +78 -11
  165. package/dist/types.js +0 -5
  166. package/dist/utils/format-tool-response.d.ts +22 -59
  167. package/dist/utils/format-tool-response.js +25 -134
  168. package/package.json +31 -20
  169. package/dist/cli.d.ts.map +0 -1
  170. package/dist/cli.js.map +0 -1
  171. package/dist/core/project-analyzer.d.ts.map +0 -1
  172. package/dist/core/project-analyzer.js.map +0 -1
  173. package/dist/index.d.ts.map +0 -1
  174. package/dist/index.js.map +0 -1
  175. package/dist/mcp-watcher.d.ts.map +0 -1
  176. package/dist/mcp-watcher.js.map +0 -1
  177. package/dist/server/json-rpc-handler.d.ts +0 -98
  178. package/dist/server/json-rpc-handler.d.ts.map +0 -1
  179. package/dist/server/json-rpc-handler.js +0 -301
  180. package/dist/server/json-rpc-handler.js.map +0 -1
  181. package/dist/server/mcp-server.d.ts.map +0 -1
  182. package/dist/server/mcp-server.js.map +0 -1
  183. package/dist/server/stdio-guard.d.ts.map +0 -1
  184. package/dist/server/stdio-guard.js.map +0 -1
  185. package/dist/server/tool-registry.d.ts.map +0 -1
  186. package/dist/server/tool-registry.js.map +0 -1
  187. package/dist/streaming/progress-store.d.ts.map +0 -1
  188. package/dist/streaming/progress-store.js.map +0 -1
  189. package/dist/tools/analyze-build-impact.d.ts.map +0 -1
  190. package/dist/tools/analyze-build-impact.js.map +0 -1
  191. package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
  192. package/dist/tools/analyze-core-to-shared.js.map +0 -1
  193. package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
  194. package/dist/tools/analyze-parser-performance.js.map +0 -1
  195. package/dist/tools/analyze-project.d.ts.map +0 -1
  196. package/dist/tools/analyze-project.js.map +0 -1
  197. package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
  198. package/dist/tools/check-incremental-compatibility.js.map +0 -1
  199. package/dist/tools/collect-feedback.d.ts.map +0 -1
  200. package/dist/tools/collect-feedback.js.map +0 -1
  201. package/dist/tools/extract-libraries.d.ts.map +0 -1
  202. package/dist/tools/extract-libraries.js.map +0 -1
  203. package/dist/tools/find-angular-symbol.d.ts.map +0 -1
  204. package/dist/tools/find-angular-symbol.js.map +0 -1
  205. package/dist/tools/find-component-hosts.d.ts.map +0 -1
  206. package/dist/tools/find-component-hosts.js.map +0 -1
  207. package/dist/tools/find-usages.d.ts.map +0 -1
  208. package/dist/tools/find-usages.js.map +0 -1
  209. package/dist/tools/get-bootstrap-execution.d.ts.map +0 -1
  210. package/dist/tools/get-bootstrap-execution.js.map +0 -1
  211. package/dist/tools/get-call-graph.d.ts.map +0 -1
  212. package/dist/tools/get-call-graph.js.map +0 -1
  213. package/dist/tools/get-operation-progress-tool.d.ts.map +0 -1
  214. package/dist/tools/get-operation-progress-tool.js.map +0 -1
  215. package/dist/tools/get-operation-progress.d.ts.map +0 -1
  216. package/dist/tools/get-operation-progress.js.map +0 -1
  217. package/dist/tools/helpers/compact-output.d.ts.map +0 -1
  218. package/dist/tools/helpers/compact-output.js.map +0 -1
  219. package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
  220. package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
  221. package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
  222. package/dist/tools/helpers/find-ts-config.js.map +0 -1
  223. package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
  224. package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
  225. package/dist/tools/helpers/project-cache.d.ts.map +0 -1
  226. package/dist/tools/helpers/project-cache.js.map +0 -1
  227. package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
  228. package/dist/tools/helpers/rule-matcher.js.map +0 -1
  229. package/dist/tools/helpers/rule-runner.d.ts.map +0 -1
  230. package/dist/tools/helpers/rule-runner.js.map +0 -1
  231. package/dist/tools/helpers/scan-plan.d.ts.map +0 -1
  232. package/dist/tools/helpers/scan-plan.js.map +0 -1
  233. package/dist/tools/helpers/stack-frame-file-index.d.ts.map +0 -1
  234. package/dist/tools/helpers/stack-frame-file-index.js.map +0 -1
  235. package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
  236. package/dist/tools/helpers/suggestion-generator.js.map +0 -1
  237. package/dist/tools/inspect-form-group.d.ts.map +0 -1
  238. package/dist/tools/inspect-form-group.js.map +0 -1
  239. package/dist/tools/inspect-i18n.d.ts.map +0 -1
  240. package/dist/tools/inspect-i18n.js.map +0 -1
  241. package/dist/tools/inspect-template.d.ts.map +0 -1
  242. package/dist/tools/inspect-template.js.map +0 -1
  243. package/dist/tools/learn-patterns.d.ts.map +0 -1
  244. package/dist/tools/learn-patterns.js.map +0 -1
  245. package/dist/tools/list-imports.d.ts.map +0 -1
  246. package/dist/tools/list-imports.js.map +0 -1
  247. package/dist/tools/orchestrate-migration.d.ts.map +0 -1
  248. package/dist/tools/orchestrate-migration.js.map +0 -1
  249. package/dist/tools/parse-stack-trace.d.ts.map +0 -1
  250. package/dist/tools/parse-stack-trace.js.map +0 -1
  251. package/dist/tools/plan-migration.d.ts.map +0 -1
  252. package/dist/tools/plan-migration.js.map +0 -1
  253. package/dist/tools/resolve-type.d.ts.map +0 -1
  254. package/dist/tools/resolve-type.js.map +0 -1
  255. package/dist/tools/review-feedback.d.ts.map +0 -1
  256. package/dist/tools/review-feedback.js.map +0 -1
  257. package/dist/tools/rollback-changes.d.ts.map +0 -1
  258. package/dist/tools/rollback-changes.js.map +0 -1
  259. package/dist/tools/run-angular-cli.d.ts.map +0 -1
  260. package/dist/tools/run-angular-cli.js.map +0 -1
  261. package/dist/tools/run-build.d.ts.map +0 -1
  262. package/dist/tools/run-build.js.map +0 -1
  263. package/dist/tools/run-schematic.d.ts.map +0 -1
  264. package/dist/tools/run-schematic.js.map +0 -1
  265. package/dist/tools/scan-all.d.ts.map +0 -1
  266. package/dist/tools/scan-all.js.map +0 -1
  267. package/dist/tools/scan-angular.d.ts.map +0 -1
  268. package/dist/tools/scan-angular.js.map +0 -1
  269. package/dist/tools/scan-architecture.d.ts.map +0 -1
  270. package/dist/tools/scan-architecture.js.map +0 -1
  271. package/dist/tools/scan-solid.d.ts.map +0 -1
  272. package/dist/tools/scan-solid.js.map +0 -1
  273. package/dist/tools/search-codebase.d.ts.map +0 -1
  274. package/dist/tools/search-codebase.js.map +0 -1
  275. package/dist/tools/server-status.d.ts.map +0 -1
  276. package/dist/tools/server-status.js.map +0 -1
  277. package/dist/tools/shared/scan-types.d.ts +0 -200
  278. package/dist/tools/shared/scan-types.d.ts.map +0 -1
  279. package/dist/tools/shared/scan-types.js +0 -7
  280. package/dist/tools/shared/scan-types.js.map +0 -1
  281. package/dist/tools/suggest-improvements.d.ts.map +0 -1
  282. package/dist/tools/suggest-improvements.js.map +0 -1
  283. package/dist/tools/trace-output-flow.d.ts.map +0 -1
  284. package/dist/tools/trace-output-flow.js.map +0 -1
  285. package/dist/tools/transform-code-batch.d.ts.map +0 -1
  286. package/dist/tools/transform-code-batch.js.map +0 -1
  287. package/dist/tools/transform-code.d.ts.map +0 -1
  288. package/dist/tools/transform-code.js.map +0 -1
  289. package/dist/tools/validate-before-transform.d.ts.map +0 -1
  290. package/dist/tools/validate-before-transform.js.map +0 -1
  291. package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
  292. package/dist/tools/validate-project-compatibility.js.map +0 -1
  293. package/dist/tools/validate-transformation.d.ts.map +0 -1
  294. package/dist/tools/validate-transformation.js.map +0 -1
  295. package/dist/types.d.ts.map +0 -1
  296. package/dist/types.js.map +0 -1
  297. package/dist/utils/format-tool-response.d.ts.map +0 -1
  298. package/dist/utils/format-tool-response.js.map +0 -1
@@ -1,6 +1,288 @@
1
+ import { OutputFlowTracer, } from '@angular-modernizer/api';
2
+ import { existsSync } from 'node:fs';
3
+ import { isAbsolute, resolve } from 'node:path';
4
+ import { findTsConfig } from './helpers/find-ts-config.js';
5
+ import { ProjectCache } from './helpers/project-cache.js';
6
+ import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
7
+ import { configuredComponentDecorators } from './helpers/project-decorators.js';
8
+ import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
9
+ import { ALTERNATIVES_SCHEMA, DYNAMIC_RESULT_USE_SCHEMA, DYNAMIC_ROUTE_SCHEMA, STRING_ARRAY, } from './helpers/investigation-schemas.js';
10
+ /** Callables walked per `$event` argument when `depth` is not given. */
11
+ const DEFAULT_DEPTH = 2;
12
+ const MAX_DEPTH = 5;
13
+ /** Bindings and effects spelled out per output in the text summary. */
14
+ const SUMMARY_MAX_BINDINGS = 5;
15
+ const SUMMARY_MAX_EFFECTS = 4;
16
+ const SUMMARY_MAX_NAMES = 5;
17
+ const EFFECTS = { type: 'array', items: { $ref: '#/$defs/effect' } };
18
+ const HANDLER = { $ref: '#/$defs/handler' };
19
+ const FORWARDS = { type: 'array', items: { $ref: '#/$defs/forward' } };
20
+ /** Recursive parts: payload effects, result handlers and forwards to callers. */
21
+ const OUTPUT_FLOW_DEFS = {
22
+ effect: {
23
+ type: 'object',
24
+ properties: {
25
+ kind: { type: 'string' },
26
+ file: { type: 'string' },
27
+ line: { type: 'integer' },
28
+ in: { type: 'string' },
29
+ expression: { type: 'string' },
30
+ text: { type: 'string' },
31
+ target: { type: 'string' },
32
+ argIndex: { type: 'integer' },
33
+ callee: {
34
+ type: 'object',
35
+ properties: {
36
+ name: { type: 'string' },
37
+ file: { type: 'string' },
38
+ line: { type: 'integer' },
39
+ parameter: { type: 'string' },
40
+ },
41
+ required: ['name', 'file', 'line'],
42
+ },
43
+ effects: EFFECTS,
44
+ },
45
+ required: ['kind', 'file', 'line', 'in', 'expression', 'text'],
46
+ },
47
+ handler: {
48
+ type: 'object',
49
+ properties: {
50
+ parameter: { type: 'string' },
51
+ effects: EFFECTS,
52
+ resultUnused: { type: 'boolean' },
53
+ via: STRING_ARRAY,
54
+ operators: {
55
+ type: 'array',
56
+ items: {
57
+ type: 'object',
58
+ properties: {
59
+ name: { type: 'string' },
60
+ parameter: { type: 'string' },
61
+ effects: EFFECTS,
62
+ },
63
+ required: ['name', 'parameter', 'effects'],
64
+ },
65
+ },
66
+ },
67
+ required: ['effects'],
68
+ },
69
+ forward: {
70
+ type: 'object',
71
+ properties: {
72
+ in: { type: 'string' },
73
+ file: { type: 'string' },
74
+ line: { type: 'integer' },
75
+ chain: STRING_ARRAY,
76
+ handler: HANDLER,
77
+ note: { type: 'string' },
78
+ },
79
+ required: ['in', 'file', 'line', 'chain'],
80
+ },
81
+ };
82
+ const HANDLER_STEP_SCHEMA = {
83
+ type: 'object',
84
+ properties: {
85
+ kind: { type: 'string' },
86
+ text: { type: 'string' },
87
+ target: { type: 'string' },
88
+ resolved: {
89
+ type: 'object',
90
+ properties: { name: { type: 'string' }, file: { type: 'string' }, line: { type: 'integer' } },
91
+ required: ['name', 'file', 'line'],
92
+ },
93
+ arguments: {
94
+ type: 'array',
95
+ items: {
96
+ type: 'object',
97
+ properties: {
98
+ index: { type: 'integer' },
99
+ text: { type: 'string' },
100
+ usesEvent: { type: 'boolean' },
101
+ parameter: { type: 'string' },
102
+ effects: EFFECTS,
103
+ },
104
+ required: ['index', 'text', 'usesEvent'],
105
+ },
106
+ },
107
+ valueUsesEvent: { type: 'boolean' },
108
+ effects: EFFECTS,
109
+ },
110
+ required: ['kind', 'text', 'target'],
111
+ };
112
+ const OUTPUT_FLOW_SCHEMA = {
113
+ type: 'object',
114
+ properties: {
115
+ name: { type: 'string' },
116
+ property: { type: 'string' },
117
+ source: { type: 'string' },
118
+ inheritedFrom: { type: 'string' },
119
+ emitterKind: { type: 'string' },
120
+ payloadType: { type: 'string' },
121
+ declaredAt: {
122
+ type: 'object',
123
+ properties: { file: { type: 'string' }, line: { type: 'integer' } },
124
+ required: ['file', 'line'],
125
+ },
126
+ emits: {
127
+ type: 'array',
128
+ items: {
129
+ type: 'object',
130
+ properties: {
131
+ file: { type: 'string' },
132
+ line: { type: 'integer' },
133
+ col: { type: 'integer' },
134
+ in: { type: 'string' },
135
+ via: { type: 'string' },
136
+ argument: { type: 'string' },
137
+ },
138
+ required: ['file', 'line', 'col', 'in', 'via'],
139
+ },
140
+ },
141
+ sourceExpression: { type: 'string' },
142
+ boundIn: {
143
+ type: 'array',
144
+ items: {
145
+ type: 'object',
146
+ properties: {
147
+ component: { type: 'string' },
148
+ componentFile: { type: 'string' },
149
+ templateFile: { type: 'string' },
150
+ bindings: {
151
+ type: 'array',
152
+ items: {
153
+ type: 'object',
154
+ properties: {
155
+ templateFile: { type: 'string' },
156
+ line: { type: 'integer' },
157
+ col: { type: 'integer' },
158
+ tag: { type: 'string' },
159
+ handler: { type: 'string' },
160
+ twoWay: { type: 'boolean' },
161
+ eventUnused: { type: 'boolean' },
162
+ steps: { type: 'array', items: HANDLER_STEP_SCHEMA },
163
+ },
164
+ required: ['templateFile', 'line', 'col', 'tag', 'handler', 'twoWay', 'eventUnused', 'steps'],
165
+ },
166
+ },
167
+ },
168
+ required: ['component', 'componentFile', 'templateFile', 'bindings'],
169
+ },
170
+ },
171
+ unboundIn: {
172
+ type: 'array',
173
+ items: {
174
+ type: 'object',
175
+ properties: {
176
+ component: { type: 'string' },
177
+ componentFile: { type: 'string' },
178
+ templateFile: { type: 'string' },
179
+ occurrences: { type: 'integer' },
180
+ },
181
+ required: ['component', 'componentFile', 'templateFile', 'occurrences'],
182
+ },
183
+ },
184
+ subscribedIn: {
185
+ type: 'array',
186
+ items: {
187
+ type: 'object',
188
+ properties: {
189
+ file: { type: 'string' },
190
+ line: { type: 'integer' },
191
+ col: { type: 'integer' },
192
+ in: { type: 'string' },
193
+ receiver: { type: 'string' },
194
+ chain: STRING_ARRAY,
195
+ handler: HANDLER,
196
+ forwardedTo: FORWARDS,
197
+ note: { type: 'string' },
198
+ },
199
+ required: ['file', 'line', 'col', 'in', 'receiver', 'chain'],
200
+ },
201
+ },
202
+ counts: {
203
+ type: 'object',
204
+ properties: {
205
+ emitSites: { type: 'integer' },
206
+ boundHosts: { type: 'integer' },
207
+ unboundHosts: { type: 'integer' },
208
+ bindings: { type: 'integer' },
209
+ effects: { type: 'integer' },
210
+ subscriptions: { type: 'integer' },
211
+ },
212
+ required: ['emitSites', 'boundHosts', 'unboundHosts', 'bindings', 'effects', 'subscriptions'],
213
+ },
214
+ truncated: { type: 'boolean' },
215
+ },
216
+ required: ['name', 'property', 'source', 'emitterKind', 'counts', 'truncated'],
217
+ };
218
+ const DYNAMIC_FLOW_SCHEMA = {
219
+ type: 'object',
220
+ properties: {
221
+ dataInjections: {
222
+ type: 'array',
223
+ items: {
224
+ type: 'object',
225
+ properties: {
226
+ member: { type: 'string' },
227
+ token: { type: 'string' },
228
+ file: { type: 'string' },
229
+ line: { type: 'integer' },
230
+ type: { type: 'string' },
231
+ },
232
+ required: ['member', 'token', 'file', 'line'],
233
+ },
234
+ },
235
+ closeSites: {
236
+ type: 'array',
237
+ items: {
238
+ type: 'object',
239
+ properties: {
240
+ file: { type: 'string' },
241
+ line: { type: 'integer' },
242
+ col: { type: 'integer' },
243
+ in: { type: 'string' },
244
+ method: { type: 'string' },
245
+ argument: { type: 'string' },
246
+ },
247
+ required: ['file', 'line', 'col', 'in', 'method'],
248
+ },
249
+ },
250
+ hosts: {
251
+ type: 'array',
252
+ items: {
253
+ type: 'object',
254
+ properties: {
255
+ component: { type: 'string' },
256
+ componentFile: { type: 'string' },
257
+ file: { type: 'string' },
258
+ line: { type: 'integer' },
259
+ in: { type: 'string' },
260
+ sink: { type: 'string' },
261
+ via: STRING_ARRAY,
262
+ result: DYNAMIC_RESULT_USE_SCHEMA,
263
+ route: DYNAMIC_ROUTE_SCHEMA,
264
+ handler: HANDLER,
265
+ forwardedTo: FORWARDS,
266
+ },
267
+ required: ['component', 'componentFile', 'file', 'line', 'in', 'sink', 'via', 'result'],
268
+ },
269
+ },
270
+ counts: {
271
+ type: 'object',
272
+ properties: {
273
+ hosts: { type: 'integer' },
274
+ closeSites: { type: 'integer' },
275
+ handlers: { type: 'integer' },
276
+ effects: { type: 'integer' },
277
+ resultUnused: { type: 'integer' },
278
+ },
279
+ required: ['hosts', 'closeSites', 'handlers', 'effects', 'resultUnused'],
280
+ },
281
+ truncated: { type: 'boolean' },
282
+ },
283
+ required: ['counts', 'truncated'],
284
+ };
1
285
  /**
2
- * @angular-modernizer/adapter-mcp - Trace Output Flow Tool
3
- *
4
286
  * MCP tool that follows the payload of a component's outputs across the
5
287
  * template boundary: emit sites, the host bindings and handlers that receive
6
288
  * the value, and what the handler methods do with `$event`.
@@ -18,25 +300,16 @@
18
300
  * // args: { className: 'ItemComponent', output: 'formError', projectRoot: '/project' }
19
301
  * ```
20
302
  */
21
- import { OutputFlowTracer, } 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, } from './helpers/compact-output.js';
27
- /** Callables walked per `$event` argument when `depth` is not given. */
28
- const DEFAULT_DEPTH = 2;
29
- const MAX_DEPTH = 5;
30
- /** Bindings and effects spelled out per output in the text summary. */
31
- const SUMMARY_MAX_BINDINGS = 5;
32
- const SUMMARY_MAX_EFFECTS = 4;
33
- const SUMMARY_MAX_NAMES = 5;
34
- /**
35
- * MCP tool that traces @Output payloads from emit to host handler.
36
- */
37
303
  export class TraceOutputFlowTool {
38
304
  projects;
39
305
  name = 'trace-output-flow';
306
+ title = 'Trace Output Flow';
307
+ annotations = {
308
+ readOnlyHint: true,
309
+ destructiveHint: false,
310
+ idempotentHint: true,
311
+ openWorldHint: false,
312
+ };
40
313
  constructor(projects = new ProjectCache()) {
41
314
  this.projects = projects;
42
315
  }
@@ -55,13 +328,19 @@ export class TraceOutputFlowTool {
55
328
  'firstValueFrom, the handler after a switchMap/concatMap/mergeMap/exhaustMap (handler.via); ' +
56
329
  'handler.resultUnused when it never reads the result; a returned result lists its callers (two ' +
57
330
  'levels) in forwardedTo; result.note says why a result is not followed (toSignal, portal attach, ' +
58
- 'no callers). Route entries are listed with path and guards; candidates from ' +
59
- 'registries with a data selector stay in find-component-hosts); includeDynamic: false skips it. Programmatic subscriptions ' +
60
- '(ref.instance.x.subscribe) are not traced (use find-usages). Give output to trace one output; for ' +
61
- 'widely used components start with summaryOnly. summaryOnly drops emit sites, host lists and the ' +
62
- 'dynamic lists, maxResults caps them per output and per dynamic list; counts always cover everything.';
331
+ 'no callers). Route entries are listed with path and guards. Subscriptions ' +
332
+ 'in code outside the target (ref.instance.x.subscribe, dialogRef.componentInstance.x.pipe(...).subscribe, ' +
333
+ 'a viewChild field) are listed per output as subscribedIn with the handler and its effects, like a ' +
334
+ 'dynamic result. For widely used components start with summaryOnly. summaryOnly drops emit sites, ' +
335
+ 'host and subscription lists and the dynamic lists, maxResults caps them per output and per dynamic ' +
336
+ 'list; counts always cover everything.';
337
+ /**
338
+ * JSON Schema of the tool arguments.
339
+ * @hidden
340
+ */
63
341
  inputSchema = {
64
342
  type: 'object',
343
+ additionalProperties: false,
65
344
  properties: {
66
345
  className: {
67
346
  type: 'string',
@@ -96,13 +375,68 @@ export class TraceOutputFlowTool {
96
375
  },
97
376
  includeDynamic: {
98
377
  type: 'boolean',
99
- description: 'Also trace creation in code (dialogs, createComponent, wrappers): data injected, close sites, result handlers. Default: true.',
378
+ description: 'Also trace creation in code (dialogs, createComponent, wrappers): data injected, close sites, result ' +
379
+ 'handlers, route entries (the dynamic section). Registry candidates with a data selector stay in ' +
380
+ 'find-component-hosts. Default: true.',
100
381
  default: true,
101
382
  },
102
383
  ...COMPACT_OUTPUT_SCHEMA,
103
384
  },
104
385
  required: ['projectRoot'],
105
386
  };
387
+ /**
388
+ * JSON Schema of the tool result (`structuredContent`).
389
+ * @hidden
390
+ */
391
+ outputSchema = {
392
+ type: 'object',
393
+ $defs: OUTPUT_FLOW_DEFS,
394
+ properties: {
395
+ target: {
396
+ type: 'object',
397
+ properties: {
398
+ className: { type: 'string' },
399
+ kind: { type: 'string' },
400
+ selector: { type: 'string' },
401
+ file: { type: 'string' },
402
+ },
403
+ required: ['className', 'kind', 'selector', 'file'],
404
+ },
405
+ alternatives: ALTERNATIVES_SCHEMA,
406
+ unknownOutput: { type: 'string' },
407
+ availableOutputs: STRING_ARRAY,
408
+ outputs: { type: 'array', items: OUTPUT_FLOW_SCHEMA },
409
+ dynamic: DYNAMIC_FLOW_SCHEMA,
410
+ counts: {
411
+ type: 'object',
412
+ properties: {
413
+ outputs: { type: 'integer' },
414
+ hosts: { type: 'integer' },
415
+ emitSites: { type: 'integer' },
416
+ bindings: { type: 'integer' },
417
+ effects: { type: 'integer' },
418
+ templatesScanned: { type: 'integer' },
419
+ dynamicHosts: { type: 'integer' },
420
+ subscriptions: { type: 'integer' },
421
+ },
422
+ required: [
423
+ 'outputs',
424
+ 'hosts',
425
+ 'emitSites',
426
+ 'bindings',
427
+ 'effects',
428
+ 'templatesScanned',
429
+ 'dynamicHosts',
430
+ 'subscriptions',
431
+ ],
432
+ },
433
+ truncated: { type: 'boolean' },
434
+ summary: { type: 'string' },
435
+ tsConfigPath: { type: 'string' },
436
+ ...WARNINGS_OUTPUT_SCHEMA,
437
+ },
438
+ required: ['alternatives', 'availableOutputs', 'outputs', 'counts', 'truncated', 'summary', 'tsConfigPath'],
439
+ };
106
440
  async execute(args) {
107
441
  const params = args;
108
442
  if (!params.className && !params.selector) {
@@ -127,6 +461,7 @@ export class TraceOutputFlowTool {
127
461
  ? params.file
128
462
  : resolve(params.projectRoot, params.file);
129
463
  const tracer = new OutputFlowTracer(this.projects.get(tsConfigPath), {
464
+ componentDecorators: configuredComponentDecorators(params.projectRoot),
130
465
  includeTestHosts: params.includeTestHosts === true,
131
466
  includeDynamic: params.includeDynamic !== false,
132
467
  depth,
@@ -138,36 +473,48 @@ export class TraceOutputFlowTool {
138
473
  ...(params.output ? { output: params.output } : {}),
139
474
  });
140
475
  const summary = this.buildSummary(params, result);
476
+ const warnings = this.projects.warnings(tsConfigPath);
141
477
  const { outputs, dynamic, ...rest } = result;
142
478
  if (compact.summaryOnly) {
143
- return {
479
+ return withWarnings({
144
480
  ...rest,
145
481
  ...(dynamic === undefined ? {} : { dynamic: { counts: dynamic.counts, truncated: false } }),
146
- outputs: outputs.map(({ emits: _e, boundIn: _b, unboundIn: _u, ...flow }) => ({ ...flow, truncated: false })),
482
+ outputs: outputs.map(({ emits: _e, boundIn: _b, unboundIn: _u, subscribedIn: _s, ...flow }) => ({
483
+ ...flow,
484
+ truncated: false,
485
+ })),
147
486
  summary,
148
487
  tsConfigPath,
149
- };
488
+ }, warnings);
150
489
  }
151
490
  const shaped = outputs.map((flow) => {
152
491
  const emits = limitList(flow.emits, compact.maxResults);
153
492
  const boundIn = limitList(flow.boundIn, compact.maxResults);
154
493
  const unboundIn = limitList(flow.unboundIn, compact.maxResults);
155
- const truncated = emits.truncated || boundIn.truncated || unboundIn.truncated;
156
- return { ...flow, emits: emits.items, boundIn: boundIn.items, unboundIn: unboundIn.items, truncated };
494
+ const subscribedIn = limitList(flow.subscribedIn, compact.maxResults);
495
+ const truncated = emits.truncated || boundIn.truncated || unboundIn.truncated || subscribedIn.truncated;
496
+ return {
497
+ ...flow,
498
+ emits: emits.items,
499
+ boundIn: boundIn.items,
500
+ unboundIn: unboundIn.items,
501
+ subscribedIn: subscribedIn.items,
502
+ truncated,
503
+ };
157
504
  });
158
505
  const shapedDynamic = dynamic === undefined ? undefined : this.shapeDynamic(dynamic, compact.maxResults);
159
506
  const cut = shaped.some((flow) => flow.truncated) || shapedDynamic?.truncated === true;
160
507
  const note = cut
161
508
  ? `Lists cut to ${compact.maxResults ?? 0} entries per output and dynamic list (maxResults). Counts cover everything.`
162
509
  : undefined;
163
- return {
510
+ return withWarnings({
164
511
  ...rest,
165
512
  ...(shapedDynamic === undefined ? {} : { dynamic: shapedDynamic }),
166
513
  outputs: shaped,
167
514
  truncated: rest.truncated || cut,
168
515
  summary: note === undefined ? summary : `${note}\n${summary}`,
169
516
  tsConfigPath,
170
- };
517
+ }, warnings);
171
518
  }
172
519
  shapeDynamic(dynamic, maxResults) {
173
520
  const dataInjections = limitList(dynamic.dataInjections, maxResults);
@@ -186,7 +533,8 @@ export class TraceOutputFlowTool {
186
533
  if (target === undefined) {
187
534
  const wanted = params.className ?? params.selector ?? '';
188
535
  return (`No project component or directive matches '${wanted}'. Only classes with @Component, ` +
189
- '@ExportComponent or @Directive and a selector in the tsconfig program are known. Check the name ' +
536
+ 'a decorator from parser.componentDecorators or @Directive and a selector in the tsconfig ' +
537
+ 'program are known. Check the name ' +
190
538
  'with find-angular-symbol.');
191
539
  }
192
540
  if (result.unknownOutput !== undefined) {
@@ -217,7 +565,8 @@ export class TraceOutputFlowTool {
217
565
  const type = flow.payloadType === undefined ? flow.emitterKind : `${flow.emitterKind}<${flow.payloadType}>`;
218
566
  const lines = [
219
567
  ` (${flow.name}) ${type}: ${flow.counts.emitSites} emit site(s), bound in ${flow.counts.boundHosts} ` +
220
- `of ${flow.counts.boundHosts + flow.counts.unboundHosts} host(s).`,
568
+ `of ${flow.counts.boundHosts + flow.counts.unboundHosts} host(s)` +
569
+ (flow.counts.subscriptions > 0 ? `, subscribed in code at ${flow.counts.subscriptions} place(s).` : '.'),
221
570
  ];
222
571
  for (const emit of flow.emits.slice(0, SUMMARY_MAX_BINDINGS)) {
223
572
  lines.push(` emit ${emit.in} line ${emit.line}: ${emit.via}(${emit.argument ?? ''})`);
@@ -240,6 +589,20 @@ export class TraceOutputFlowTool {
240
589
  if (bindings.length > SUMMARY_MAX_BINDINGS) {
241
590
  lines.push(` +${bindings.length - SUMMARY_MAX_BINDINGS} more binding(s)`);
242
591
  }
592
+ for (const sub of flow.subscribedIn.slice(0, SUMMARY_MAX_BINDINGS)) {
593
+ const handler = sub.handler;
594
+ const unread = handler?.resultUnused === true ? ' (payload unused)' : '';
595
+ lines.push(` subscribed in ${sub.in} line ${sub.line}: ${sub.receiver}.${flow.name}.${sub.chain.join('.')}${unread}`);
596
+ if (handler !== undefined && handler.effects.length > 0) {
597
+ lines.push(` -> ${handler.parameter ?? 'handler'}: ${this.effectList(handler.effects)}`);
598
+ }
599
+ else if (sub.note !== undefined) {
600
+ lines.push(` -> ${sub.note}`);
601
+ }
602
+ }
603
+ if (flow.subscribedIn.length > SUMMARY_MAX_BINDINGS) {
604
+ lines.push(` +${flow.subscribedIn.length - SUMMARY_MAX_BINDINGS} more subscription(s)`);
605
+ }
243
606
  if (flow.unboundIn.length > 0) {
244
607
  const names = flow.unboundIn.map((h) => h.component);
245
608
  const shown = names.slice(0, SUMMARY_MAX_NAMES).join(', ');
@@ -7,7 +7,10 @@ export interface BatchTransformOptions {
7
7
  options?: Record<string, unknown>;
8
8
  parallel?: boolean;
9
9
  enableProgress?: boolean;
10
+ /** Stops between files (sequential) or chunks (parallel). */
10
11
  signal?: AbortSignal;
12
+ /** Called after each file (sequential) or chunk (parallel) with the files done so far. */
13
+ onProgress?: (done: number, total: number) => void;
11
14
  resourceLimits?: {
12
15
  maxMemory?: number;
13
16
  maxWorkers?: number;
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @angular-modernizer/adapter-mcp - Batch transformation helper for transform-code tool.
3
3
  */
4
+ import { yieldIfCancellable } from './helpers/tool-context.js';
4
5
  /**
5
6
  * Helper to process a single transformation result.
6
7
  */
@@ -16,12 +17,13 @@ function processResult(result, results, succeeded, failed) {
16
17
  /**
17
18
  * Process files in chunks with parallel execution within each chunk.
18
19
  */
19
- async function processChunks(totalFiles, chunks, transformSingleFile, signal, enableProgress) {
20
+ async function processChunks(totalFiles, chunks, transformSingleFile, signal, enableProgress, onProgress) {
20
21
  const results = [];
21
22
  const succeeded = { value: 0 };
22
23
  const failed = { value: 0 };
23
24
  let processed = 0;
24
25
  for (const chunk of chunks) {
26
+ await yieldIfCancellable(signal);
25
27
  if (signal?.aborted) {
26
28
  break;
27
29
  }
@@ -30,8 +32,9 @@ async function processChunks(totalFiles, chunks, transformSingleFile, signal, en
30
32
  return { path: filePath, ...result };
31
33
  }));
32
34
  chunkResults.forEach((result) => processResult(result, results, succeeded, failed));
35
+ processed += chunk.length;
36
+ onProgress?.(processed, totalFiles);
33
37
  if (enableProgress) {
34
- processed += chunk.length;
35
38
  const percentage = (processed / totalFiles) * 100;
36
39
  console.info(`Progress: ${processed}/${totalFiles} (${percentage.toFixed(1)}%)`);
37
40
  }
@@ -41,12 +44,13 @@ async function processChunks(totalFiles, chunks, transformSingleFile, signal, en
41
44
  /**
42
45
  * Process files sequentially.
43
46
  */
44
- async function processSequentially(files, transformSingleFile, signal, enableProgress) {
47
+ async function processSequentially(files, transformSingleFile, signal, enableProgress, onProgress) {
45
48
  const results = [];
46
49
  const succeeded = { value: 0 };
47
50
  const failed = { value: 0 };
48
51
  for (let i = 0; i < files.length; i++) {
49
52
  const filePath = files[i];
53
+ await yieldIfCancellable(signal);
50
54
  if (signal?.aborted) {
51
55
  break;
52
56
  }
@@ -58,6 +62,7 @@ async function processSequentially(files, transformSingleFile, signal, enablePro
58
62
  }
59
63
  const result = await transformSingleFile(filePath);
60
64
  processResult({ path: filePath, ...result }, results, succeeded, failed);
65
+ onProgress?.(i + 1, files.length);
61
66
  }
62
67
  return { results, succeeded: succeeded.value, failed: failed.value };
63
68
  }
@@ -76,14 +81,14 @@ export async function executeBatchTransformation(options, transformSingleFile) {
76
81
  for (let i = 0; i < options.files.length; i += maxWorkers) {
77
82
  chunks.push(options.files.slice(i, i + maxWorkers));
78
83
  }
79
- const { results: chunkResults, succeeded, failed, } = await processChunks(options.files.length, chunks, transformSingleFile, options.signal, options.enableProgress);
84
+ const { results: chunkResults, succeeded, failed, } = await processChunks(options.files.length, chunks, transformSingleFile, options.signal, options.enableProgress, options.onProgress);
80
85
  results.push(...chunkResults);
81
86
  filesSucceeded += succeeded;
82
87
  filesFailed += failed;
83
88
  }
84
89
  else {
85
90
  // Sequential processing
86
- const { results: seqResults, succeeded, failed, } = await processSequentially(options.files, transformSingleFile, options.signal, options.enableProgress);
91
+ const { results: seqResults, succeeded, failed, } = await processSequentially(options.files, transformSingleFile, options.signal, options.enableProgress, options.onProgress);
87
92
  results.push(...seqResults);
88
93
  filesSucceeded += succeeded;
89
94
  filesFailed += failed;