@angular-modernizer/adapter-mcp 0.3.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 (275) hide show
  1. package/README.md +103 -218
  2. package/dist/cli.js +13 -13
  3. package/dist/index.d.ts +4 -3
  4. package/dist/index.js +3 -2
  5. package/dist/mcp-watcher.d.ts +6 -1
  6. package/dist/mcp-watcher.js +11 -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 +12 -14
  10. package/dist/server/mcp-server.js +41 -75
  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/tool-registry.d.ts +3 -2
  16. package/dist/server/tool-registry.js +5 -5
  17. package/dist/tools/analyze-build-impact.d.ts +220 -1
  18. package/dist/tools/analyze-build-impact.js +145 -3
  19. package/dist/tools/analyze-core-to-shared.d.ts +134 -4
  20. package/dist/tools/analyze-core-to-shared.js +113 -9
  21. package/dist/tools/analyze-parser-performance.d.ts +200 -7
  22. package/dist/tools/analyze-parser-performance.js +108 -47
  23. package/dist/tools/analyze-project.d.ts +267 -5
  24. package/dist/tools/analyze-project.js +196 -8
  25. package/dist/tools/check-incremental-compatibility.d.ts +61 -1
  26. package/dist/tools/check-incremental-compatibility.js +58 -2
  27. package/dist/tools/collect-feedback.d.ts +199 -10
  28. package/dist/tools/collect-feedback.js +171 -99
  29. package/dist/tools/compare-health.d.ts +356 -0
  30. package/dist/tools/compare-health.js +472 -0
  31. package/dist/tools/extract-libraries.d.ts +156 -4
  32. package/dist/tools/extract-libraries.js +115 -10
  33. package/dist/tools/find-angular-symbol.d.ts +69 -3
  34. package/dist/tools/find-angular-symbol.js +55 -8
  35. package/dist/tools/find-component-hosts.d.ts +572 -2
  36. package/dist/tools/find-component-hosts.js +207 -6
  37. package/dist/tools/find-usages.d.ts +79 -1
  38. package/dist/tools/find-usages.js +64 -7
  39. package/dist/tools/get-bootstrap-execution.d.ts +151 -1
  40. package/dist/tools/get-bootstrap-execution.js +84 -3
  41. package/dist/tools/get-call-graph.d.ts +111 -1
  42. package/dist/tools/get-call-graph.js +72 -10
  43. package/dist/tools/get-operation-progress-tool.d.ts +114 -2
  44. package/dist/tools/get-operation-progress-tool.js +114 -7
  45. package/dist/tools/get-operation-progress.d.ts +1 -1
  46. package/dist/tools/get-operation-progress.js +5 -5
  47. package/dist/tools/helpers/analysis-output.d.ts +177 -0
  48. package/dist/tools/helpers/analysis-output.js +165 -0
  49. package/dist/tools/helpers/build-schemas.d.ts +36 -0
  50. package/dist/tools/helpers/build-schemas.js +23 -0
  51. package/dist/tools/helpers/citation-file-source.d.ts +10 -0
  52. package/dist/tools/helpers/citation-file-source.js +82 -0
  53. package/dist/tools/helpers/finding-window.d.ts +43 -0
  54. package/dist/tools/helpers/finding-window.js +64 -0
  55. package/dist/tools/helpers/health-delta.d.ts +86 -0
  56. package/dist/tools/helpers/health-delta.js +239 -0
  57. package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
  58. package/dist/tools/helpers/investigation-schemas.js +48 -0
  59. package/dist/tools/helpers/library-imports.d.ts +57 -0
  60. package/dist/tools/helpers/library-imports.js +151 -0
  61. package/dist/tools/helpers/load-source-files.d.ts +30 -0
  62. package/dist/tools/helpers/load-source-files.js +34 -0
  63. package/dist/tools/helpers/output-contract.d.ts +32 -0
  64. package/dist/tools/helpers/output-contract.js +32 -0
  65. package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
  66. package/dist/tools/helpers/platform-root-resolver.js +75 -48
  67. package/dist/tools/helpers/process-output.d.ts +19 -0
  68. package/dist/tools/helpers/process-output.js +31 -0
  69. package/dist/tools/helpers/project-cache.d.ts +11 -4
  70. package/dist/tools/helpers/project-cache.js +22 -4
  71. package/dist/tools/helpers/project-decorators.d.ts +14 -0
  72. package/dist/tools/helpers/project-decorators.js +22 -0
  73. package/dist/tools/helpers/rule-matcher.js +5 -0
  74. package/dist/tools/helpers/rule-runner.d.ts +9 -4
  75. package/dist/tools/helpers/rule-runner.js +28 -14
  76. package/dist/tools/helpers/scan-cache.d.ts +22 -0
  77. package/dist/tools/helpers/scan-cache.js +34 -0
  78. package/dist/tools/helpers/scan-plan.d.ts +5 -2
  79. package/dist/tools/helpers/scan-plan.js +18 -3
  80. package/dist/tools/helpers/scope-paths.d.ts +17 -0
  81. package/dist/tools/helpers/scope-paths.js +32 -0
  82. package/dist/tools/helpers/tool-context.d.ts +60 -0
  83. package/dist/tools/helpers/tool-context.js +82 -0
  84. package/dist/tools/helpers/transform-safety.d.ts +40 -0
  85. package/dist/tools/helpers/transform-safety.js +87 -0
  86. package/dist/tools/helpers/validation-output.d.ts +53 -0
  87. package/dist/tools/helpers/validation-output.js +48 -0
  88. package/dist/tools/inspect-form-group.d.ts +232 -1
  89. package/dist/tools/inspect-form-group.js +120 -2
  90. package/dist/tools/inspect-i18n.d.ts +382 -1
  91. package/dist/tools/inspect-i18n.js +199 -2
  92. package/dist/tools/inspect-template.d.ts +232 -1
  93. package/dist/tools/inspect-template.js +160 -2
  94. package/dist/tools/learn-patterns.d.ts +122 -1
  95. package/dist/tools/learn-patterns.js +97 -2
  96. package/dist/tools/list-imports.d.ts +111 -10
  97. package/dist/tools/list-imports.js +110 -7
  98. package/dist/tools/orchestrate-migration.d.ts +128 -5
  99. package/dist/tools/orchestrate-migration.js +135 -13
  100. package/dist/tools/parse-stack-trace.d.ts +56 -1
  101. package/dist/tools/parse-stack-trace.js +34 -0
  102. package/dist/tools/plan-migration.d.ts +330 -1
  103. package/dist/tools/plan-migration.js +154 -3
  104. package/dist/tools/resolve-type.d.ts +39 -1
  105. package/dist/tools/resolve-type.js +31 -2
  106. package/dist/tools/review-feedback.d.ts +206 -11
  107. package/dist/tools/review-feedback.js +132 -51
  108. package/dist/tools/rollback-changes.d.ts +79 -2
  109. package/dist/tools/rollback-changes.js +66 -14
  110. package/dist/tools/run-angular-cli.d.ts +45 -2
  111. package/dist/tools/run-angular-cli.js +67 -7
  112. package/dist/tools/run-build.d.ts +114 -2
  113. package/dist/tools/run-build.js +117 -8
  114. package/dist/tools/run-schematic.d.ts +70 -2
  115. package/dist/tools/run-schematic.js +104 -10
  116. package/dist/tools/scan-all.d.ts +19 -11
  117. package/dist/tools/scan-all.js +139 -131
  118. package/dist/tools/scan-angular.d.ts +19 -10
  119. package/dist/tools/scan-angular.js +51 -23
  120. package/dist/tools/scan-architecture.d.ts +17 -10
  121. package/dist/tools/scan-architecture.js +93 -31
  122. package/dist/tools/scan-solid.d.ts +19 -10
  123. package/dist/tools/scan-solid.js +51 -23
  124. package/dist/tools/search-codebase.d.ts +82 -1
  125. package/dist/tools/search-codebase.js +55 -2
  126. package/dist/tools/server-status.d.ts +279 -5
  127. package/dist/tools/server-status.js +179 -5
  128. package/dist/tools/suggest-improvements.d.ts +97 -5
  129. package/dist/tools/suggest-improvements.js +80 -44
  130. package/dist/tools/trace-output-flow.d.ts +682 -2
  131. package/dist/tools/trace-output-flow.js +375 -15
  132. package/dist/tools/transform-code-batch.d.ts +3 -0
  133. package/dist/tools/transform-code-batch.js +10 -5
  134. package/dist/tools/transform-code.d.ts +335 -12
  135. package/dist/tools/transform-code.js +649 -608
  136. package/dist/tools/validate-before-transform.d.ts +116 -2
  137. package/dist/tools/validate-before-transform.js +55 -2
  138. package/dist/tools/validate-project-compatibility.d.ts +64 -2
  139. package/dist/tools/validate-project-compatibility.js +67 -4
  140. package/dist/tools/validate-transformation.d.ts +220 -2
  141. package/dist/tools/validate-transformation.js +113 -15
  142. package/dist/tools/verify-citations.d.ts +181 -0
  143. package/dist/tools/verify-citations.js +218 -0
  144. package/dist/types.d.ts +38 -1
  145. package/dist/utils/format-tool-response.d.ts +22 -59
  146. package/dist/utils/format-tool-response.js +25 -134
  147. package/package.json +30 -13
  148. package/dist/cli.d.ts.map +0 -1
  149. package/dist/cli.js.map +0 -1
  150. package/dist/core/project-analyzer.d.ts.map +0 -1
  151. package/dist/core/project-analyzer.js.map +0 -1
  152. package/dist/index.d.ts.map +0 -1
  153. package/dist/index.js.map +0 -1
  154. package/dist/mcp-watcher.d.ts.map +0 -1
  155. package/dist/mcp-watcher.js.map +0 -1
  156. package/dist/server/json-rpc-handler.d.ts +0 -98
  157. package/dist/server/json-rpc-handler.d.ts.map +0 -1
  158. package/dist/server/json-rpc-handler.js +0 -301
  159. package/dist/server/json-rpc-handler.js.map +0 -1
  160. package/dist/server/mcp-server.d.ts.map +0 -1
  161. package/dist/server/mcp-server.js.map +0 -1
  162. package/dist/server/stdio-guard.d.ts.map +0 -1
  163. package/dist/server/stdio-guard.js.map +0 -1
  164. package/dist/server/tool-registry.d.ts.map +0 -1
  165. package/dist/server/tool-registry.js.map +0 -1
  166. package/dist/streaming/progress-store.d.ts.map +0 -1
  167. package/dist/streaming/progress-store.js.map +0 -1
  168. package/dist/tools/analyze-build-impact.d.ts.map +0 -1
  169. package/dist/tools/analyze-build-impact.js.map +0 -1
  170. package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
  171. package/dist/tools/analyze-core-to-shared.js.map +0 -1
  172. package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
  173. package/dist/tools/analyze-parser-performance.js.map +0 -1
  174. package/dist/tools/analyze-project.d.ts.map +0 -1
  175. package/dist/tools/analyze-project.js.map +0 -1
  176. package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
  177. package/dist/tools/check-incremental-compatibility.js.map +0 -1
  178. package/dist/tools/collect-feedback.d.ts.map +0 -1
  179. package/dist/tools/collect-feedback.js.map +0 -1
  180. package/dist/tools/extract-libraries.d.ts.map +0 -1
  181. package/dist/tools/extract-libraries.js.map +0 -1
  182. package/dist/tools/find-angular-symbol.d.ts.map +0 -1
  183. package/dist/tools/find-angular-symbol.js.map +0 -1
  184. package/dist/tools/find-component-hosts.d.ts.map +0 -1
  185. package/dist/tools/find-component-hosts.js.map +0 -1
  186. package/dist/tools/find-usages.d.ts.map +0 -1
  187. package/dist/tools/find-usages.js.map +0 -1
  188. package/dist/tools/get-bootstrap-execution.d.ts.map +0 -1
  189. package/dist/tools/get-bootstrap-execution.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/compact-output.d.ts.map +0 -1
  197. package/dist/tools/helpers/compact-output.js.map +0 -1
  198. package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
  199. package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
  200. package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
  201. package/dist/tools/helpers/find-ts-config.js.map +0 -1
  202. package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
  203. package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
  204. package/dist/tools/helpers/project-cache.d.ts.map +0 -1
  205. package/dist/tools/helpers/project-cache.js.map +0 -1
  206. package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
  207. package/dist/tools/helpers/rule-matcher.js.map +0 -1
  208. package/dist/tools/helpers/rule-runner.d.ts.map +0 -1
  209. package/dist/tools/helpers/rule-runner.js.map +0 -1
  210. package/dist/tools/helpers/scan-plan.d.ts.map +0 -1
  211. package/dist/tools/helpers/scan-plan.js.map +0 -1
  212. package/dist/tools/helpers/stack-frame-file-index.d.ts.map +0 -1
  213. package/dist/tools/helpers/stack-frame-file-index.js.map +0 -1
  214. package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
  215. package/dist/tools/helpers/suggestion-generator.js.map +0 -1
  216. package/dist/tools/inspect-form-group.d.ts.map +0 -1
  217. package/dist/tools/inspect-form-group.js.map +0 -1
  218. package/dist/tools/inspect-i18n.d.ts.map +0 -1
  219. package/dist/tools/inspect-i18n.js.map +0 -1
  220. package/dist/tools/inspect-template.d.ts.map +0 -1
  221. package/dist/tools/inspect-template.js.map +0 -1
  222. package/dist/tools/learn-patterns.d.ts.map +0 -1
  223. package/dist/tools/learn-patterns.js.map +0 -1
  224. package/dist/tools/list-imports.d.ts.map +0 -1
  225. package/dist/tools/list-imports.js.map +0 -1
  226. package/dist/tools/orchestrate-migration.d.ts.map +0 -1
  227. package/dist/tools/orchestrate-migration.js.map +0 -1
  228. package/dist/tools/parse-stack-trace.d.ts.map +0 -1
  229. package/dist/tools/parse-stack-trace.js.map +0 -1
  230. package/dist/tools/plan-migration.d.ts.map +0 -1
  231. package/dist/tools/plan-migration.js.map +0 -1
  232. package/dist/tools/resolve-type.d.ts.map +0 -1
  233. package/dist/tools/resolve-type.js.map +0 -1
  234. package/dist/tools/review-feedback.d.ts.map +0 -1
  235. package/dist/tools/review-feedback.js.map +0 -1
  236. package/dist/tools/rollback-changes.d.ts.map +0 -1
  237. package/dist/tools/rollback-changes.js.map +0 -1
  238. package/dist/tools/run-angular-cli.d.ts.map +0 -1
  239. package/dist/tools/run-angular-cli.js.map +0 -1
  240. package/dist/tools/run-build.d.ts.map +0 -1
  241. package/dist/tools/run-build.js.map +0 -1
  242. package/dist/tools/run-schematic.d.ts.map +0 -1
  243. package/dist/tools/run-schematic.js.map +0 -1
  244. package/dist/tools/scan-all.d.ts.map +0 -1
  245. package/dist/tools/scan-all.js.map +0 -1
  246. package/dist/tools/scan-angular.d.ts.map +0 -1
  247. package/dist/tools/scan-angular.js.map +0 -1
  248. package/dist/tools/scan-architecture.d.ts.map +0 -1
  249. package/dist/tools/scan-architecture.js.map +0 -1
  250. package/dist/tools/scan-solid.d.ts.map +0 -1
  251. package/dist/tools/scan-solid.js.map +0 -1
  252. package/dist/tools/search-codebase.d.ts.map +0 -1
  253. package/dist/tools/search-codebase.js.map +0 -1
  254. package/dist/tools/server-status.d.ts.map +0 -1
  255. package/dist/tools/server-status.js.map +0 -1
  256. package/dist/tools/shared/scan-types.d.ts.map +0 -1
  257. package/dist/tools/shared/scan-types.js.map +0 -1
  258. package/dist/tools/suggest-improvements.d.ts.map +0 -1
  259. package/dist/tools/suggest-improvements.js.map +0 -1
  260. package/dist/tools/trace-output-flow.d.ts.map +0 -1
  261. package/dist/tools/trace-output-flow.js.map +0 -1
  262. package/dist/tools/transform-code-batch.d.ts.map +0 -1
  263. package/dist/tools/transform-code-batch.js.map +0 -1
  264. package/dist/tools/transform-code.d.ts.map +0 -1
  265. package/dist/tools/transform-code.js.map +0 -1
  266. package/dist/tools/validate-before-transform.d.ts.map +0 -1
  267. package/dist/tools/validate-before-transform.js.map +0 -1
  268. package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
  269. package/dist/tools/validate-project-compatibility.js.map +0 -1
  270. package/dist/tools/validate-transformation.d.ts.map +0 -1
  271. package/dist/tools/validate-transformation.js.map +0 -1
  272. package/dist/types.d.ts.map +0 -1
  273. package/dist/types.js.map +0 -1
  274. package/dist/utils/format-tool-response.d.ts.map +0 -1
  275. package/dist/utils/format-tool-response.js.map +0 -1
@@ -0,0 +1,472 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Compare Health Tool
3
+ *
4
+ * MCP tool that runs the scan-all scan and compares it with the previous run:
5
+ * which violations are new, fixed or unchanged, per rule and per file.
6
+ *
7
+ * @remarks
8
+ * scan-all returns a window of `maxResults` violations and sums only that
9
+ * window, so a comparison of two scan-all answers would compare two windows.
10
+ * This tool takes the complete result, stores it as a snapshot in the target
11
+ * project (default `.angular-modernizer-cache/health/last-run.json`, ignored
12
+ * like the cache) and compares the next run against it. Matching and snapshot
13
+ * format live in `helpers/health-delta.ts`.
14
+ *
15
+ * The snapshot is replaced after every comparison unless `updateSnapshot` is
16
+ * false. When the stored run used another scope (rules, include or exclude
17
+ * patterns) or the file cannot be read, nothing is compared and the file is
18
+ * kept unless `updateSnapshot` is explicitly true.
19
+ */
20
+ import { isAbsolute, relative, resolve } from 'node:path';
21
+ import { RealFileSystemAdapter, } from '@angular-modernizer/core';
22
+ import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
23
+ import { DEFAULT_HEALTH_SNAPSHOT_PATH, HEALTH_SNAPSHOT_VERSION, compareHealth, compareViolations, parseHealthSnapshot, scopeDifferences, serializeHealthSnapshot, } from './helpers/health-delta.js';
24
+ import { ScanAllTool } from './scan-all.js';
25
+ /** Violations spelled out per list in the summary; the rest is in the lists. */
26
+ const SUMMARY_LINES = 15;
27
+ const STRING_LIST = { type: 'array', items: { type: 'string' } };
28
+ const VIOLATION_SCHEMA = {
29
+ type: 'object',
30
+ properties: {
31
+ ruleId: { type: 'string' },
32
+ filePath: { type: 'string' },
33
+ message: { type: 'string' },
34
+ severity: { type: 'string' },
35
+ category: { type: 'string' },
36
+ line: { type: 'integer' },
37
+ },
38
+ required: ['ruleId', 'filePath', 'message', 'severity', 'category'],
39
+ };
40
+ const RUN_SCHEMA = {
41
+ type: 'object',
42
+ properties: {
43
+ createdAt: { type: 'string' },
44
+ analyzedFiles: { type: 'integer' },
45
+ totalViolations: { type: 'integer' },
46
+ },
47
+ required: ['createdAt', 'analyzedFiles', 'totalViolations'],
48
+ };
49
+ const COUNTS_SCHEMA = {
50
+ type: 'object',
51
+ additionalProperties: { type: 'integer' },
52
+ };
53
+ export class CompareHealthTool {
54
+ scan;
55
+ fileSystem;
56
+ now;
57
+ name = 'compare-health';
58
+ title = 'Compare Health With Last Run';
59
+ description = 'Run the full scan-all scan (all violations, no result window) and compare it with the previous run ' +
60
+ 'stored in the project: new, fixed and unchanged violations, per rule (byRule) and per changed file ' +
61
+ '(byFile), plus the lists newViolations and fixedViolations. Violations match by rule, file and message ' +
62
+ 'with digits ignored, not by line, so code moving up or down stays unchanged. The first run writes the ' +
63
+ 'baseline (status baseline-created). After a comparison the snapshot is replaced by the current run ' +
64
+ 'unless updateSnapshot is false. A snapshot taken with other rules or include/exclude patterns is not ' +
65
+ 'compared (status scope-mismatch) and is only replaced with updateSnapshot: true. currentRun.bySeverity ' +
66
+ 'and byCategory count all violations. Writes only the snapshot file.';
67
+ annotations = {
68
+ readOnlyHint: false,
69
+ destructiveHint: false,
70
+ idempotentHint: false,
71
+ openWorldHint: false,
72
+ };
73
+ inputSchema = {
74
+ type: 'object',
75
+ additionalProperties: false,
76
+ properties: {
77
+ rootPath: {
78
+ type: 'string',
79
+ description: 'Root path of the project to scan',
80
+ },
81
+ rules: {
82
+ ...STRING_LIST,
83
+ description: 'Rule IDs to compare (optional, all 52 if not specified). Part of the snapshot scope.',
84
+ },
85
+ includePatterns: {
86
+ ...STRING_LIST,
87
+ description: 'File patterns to include, as in scan-all. Part of the snapshot scope.',
88
+ },
89
+ excludePatterns: {
90
+ ...STRING_LIST,
91
+ description: 'File patterns to exclude, as in scan-all. Part of the snapshot scope.',
92
+ },
93
+ maxFiles: {
94
+ type: 'number',
95
+ description: 'Batch size for processing files, as in scan-all.',
96
+ },
97
+ snapshotPath: {
98
+ type: 'string',
99
+ description: `Snapshot file, absolute or relative to rootPath. Default: ${DEFAULT_HEALTH_SNAPSHOT_PATH}.`,
100
+ },
101
+ updateSnapshot: {
102
+ type: 'boolean',
103
+ description: 'false: compare only, keep the stored snapshot. true: also replace a snapshot with another scope or ' +
104
+ 'an unreadable one. Default: replace after a comparison and write the first baseline.',
105
+ },
106
+ ...COMPACT_OUTPUT_SCHEMA,
107
+ },
108
+ required: ['rootPath'],
109
+ };
110
+ outputSchema = {
111
+ type: 'object',
112
+ properties: {
113
+ status: {
114
+ type: 'string',
115
+ enum: [
116
+ 'compared',
117
+ 'baseline-created',
118
+ 'no-baseline',
119
+ 'scope-mismatch',
120
+ 'invalid-snapshot',
121
+ ],
122
+ },
123
+ projectRoot: { type: 'string' },
124
+ snapshotPath: { type: 'string' },
125
+ snapshotWritten: { type: 'boolean' },
126
+ previousRun: RUN_SCHEMA,
127
+ currentRun: {
128
+ type: 'object',
129
+ properties: {
130
+ ...RUN_SCHEMA.properties,
131
+ bySeverity: COUNTS_SCHEMA,
132
+ byCategory: COUNTS_SCHEMA,
133
+ },
134
+ required: [...RUN_SCHEMA.required, 'bySeverity', 'byCategory'],
135
+ },
136
+ totals: {
137
+ type: 'object',
138
+ properties: {
139
+ new: { type: 'integer' },
140
+ fixed: { type: 'integer' },
141
+ unchanged: { type: 'integer' },
142
+ },
143
+ required: ['new', 'fixed', 'unchanged'],
144
+ },
145
+ byRule: {
146
+ type: 'array',
147
+ items: {
148
+ type: 'object',
149
+ properties: {
150
+ ruleId: { type: 'string' },
151
+ previous: { type: 'integer' },
152
+ current: { type: 'integer' },
153
+ new: { type: 'integer' },
154
+ fixed: { type: 'integer' },
155
+ unchanged: { type: 'integer' },
156
+ },
157
+ required: [
158
+ 'ruleId',
159
+ 'previous',
160
+ 'current',
161
+ 'new',
162
+ 'fixed',
163
+ 'unchanged',
164
+ ],
165
+ },
166
+ },
167
+ byFile: {
168
+ type: 'array',
169
+ items: {
170
+ type: 'object',
171
+ properties: {
172
+ filePath: { type: 'string' },
173
+ previous: { type: 'integer' },
174
+ current: { type: 'integer' },
175
+ new: { type: 'integer' },
176
+ fixed: { type: 'integer' },
177
+ },
178
+ required: ['filePath', 'previous', 'current', 'new', 'fixed'],
179
+ },
180
+ },
181
+ newViolations: { type: 'array', items: VIOLATION_SCHEMA },
182
+ fixedViolations: { type: 'array', items: VIOLATION_SCHEMA },
183
+ rulesAdded: STRING_LIST,
184
+ rulesRemoved: STRING_LIST,
185
+ scopeDifferences: STRING_LIST,
186
+ truncated: { type: 'boolean' },
187
+ summary: { type: 'string' },
188
+ },
189
+ required: [
190
+ 'status',
191
+ 'projectRoot',
192
+ 'snapshotPath',
193
+ 'snapshotWritten',
194
+ 'currentRun',
195
+ 'byRule',
196
+ 'rulesAdded',
197
+ 'rulesRemoved',
198
+ 'scopeDifferences',
199
+ 'truncated',
200
+ 'summary',
201
+ ],
202
+ };
203
+ constructor(scan = (args, ctx) => new ScanAllTool().execute(args, ctx), fileSystem = new RealFileSystemAdapter(), now = () => new Date()) {
204
+ this.scan = scan;
205
+ this.fileSystem = fileSystem;
206
+ this.now = now;
207
+ }
208
+ async execute(args, ctx = {}) {
209
+ const input = parseInput(args);
210
+ const compact = parseCompactOptions(args);
211
+ const root = resolve(input.rootPath);
212
+ const snapshotFile = isAbsolute(input.snapshotPath)
213
+ ? input.snapshotPath
214
+ : resolve(root, input.snapshotPath);
215
+ const snapshotLabel = relative(root, snapshotFile).startsWith('..')
216
+ ? snapshotFile
217
+ : relative(root, snapshotFile);
218
+ const scanResult = await this.scan(scanArguments(root, input), ctx);
219
+ // A cancelled scan covers only part of the project: comparing it would
220
+ // report the rest as fixed, and writing it would replace the baseline
221
+ if (scanResult.execution?.stopReason === 'cancelled') {
222
+ throw new Error('Scan cancelled; snapshot not compared or written.');
223
+ }
224
+ const current = {
225
+ version: HEALTH_SNAPSHOT_VERSION,
226
+ createdAt: this.now().toISOString(),
227
+ scope: input.scope,
228
+ rulesExecuted: [...scanResult.metadata.rulesExecuted].sort(),
229
+ analyzedFiles: scanResult.counts.analyzedFiles,
230
+ violations: scanResult.violations
231
+ .map(toHealthViolation)
232
+ .sort(compareViolations),
233
+ };
234
+ const stored = await this.readSnapshot(snapshotFile);
235
+ const previous = stored.snapshot;
236
+ const differences = previous === undefined
237
+ ? []
238
+ : scopeDifferences(previous.scope, current.scope);
239
+ const status = decideStatus(stored, differences);
240
+ const write = input.updateSnapshot === true ||
241
+ (input.updateSnapshot === undefined &&
242
+ (status === 'compared' || status === 'baseline-created'));
243
+ if (write) {
244
+ await this.fileSystem.writeFile(snapshotFile, serializeHealthSnapshot(current));
245
+ }
246
+ const output = buildOutput({
247
+ status,
248
+ root,
249
+ snapshotLabel,
250
+ written: write,
251
+ previous,
252
+ current,
253
+ differences,
254
+ compact,
255
+ });
256
+ return output;
257
+ }
258
+ async readSnapshot(path) {
259
+ if (!(await this.fileSystem.exists(path))) {
260
+ return { exists: false, snapshot: undefined };
261
+ }
262
+ const text = await this.fileSystem.readFile(path);
263
+ return { exists: true, snapshot: parseHealthSnapshot(text) };
264
+ }
265
+ }
266
+ function parseInput(args) {
267
+ const { rootPath, maxFiles, snapshotPath, updateSnapshot } = args;
268
+ if (typeof rootPath !== 'string' || rootPath === '') {
269
+ throw new Error('rootPath is required');
270
+ }
271
+ if (maxFiles !== undefined &&
272
+ (typeof maxFiles !== 'number' ||
273
+ !Number.isInteger(maxFiles) ||
274
+ maxFiles < 1)) {
275
+ throw new Error('maxFiles must be a positive integer');
276
+ }
277
+ if (snapshotPath !== undefined &&
278
+ (typeof snapshotPath !== 'string' || snapshotPath === '')) {
279
+ throw new Error('snapshotPath must be a non-empty string');
280
+ }
281
+ if (updateSnapshot !== undefined && typeof updateSnapshot !== 'boolean') {
282
+ throw new Error('updateSnapshot must be a boolean');
283
+ }
284
+ return {
285
+ rootPath,
286
+ scope: {
287
+ rules: stringList(args, 'rules'),
288
+ includePatterns: stringList(args, 'includePatterns'),
289
+ excludePatterns: stringList(args, 'excludePatterns'),
290
+ },
291
+ maxFiles,
292
+ snapshotPath: snapshotPath ?? DEFAULT_HEALTH_SNAPSHOT_PATH,
293
+ updateSnapshot,
294
+ };
295
+ }
296
+ function stringList(args, key) {
297
+ const value = args[key];
298
+ if (value === undefined) {
299
+ return null;
300
+ }
301
+ if (!Array.isArray(value) || !value.every((x) => typeof x === 'string')) {
302
+ throw new Error(`${key} must be an array of strings`);
303
+ }
304
+ return [...value].sort();
305
+ }
306
+ /** scan-all arguments for the complete result; unset keys stay unset so the project config applies. */
307
+ function scanArguments(root, input) {
308
+ const { rules, includePatterns, excludePatterns } = input.scope;
309
+ return {
310
+ rootPath: root,
311
+ includeAutoFixes: false,
312
+ maxResults: Number.MAX_SAFE_INTEGER,
313
+ resultOffset: 0,
314
+ ...(rules === null ? {} : { rules }),
315
+ ...(includePatterns === null ? {} : { includePatterns }),
316
+ ...(excludePatterns === null ? {} : { excludePatterns }),
317
+ ...(input.maxFiles === undefined ? {} : { maxFiles: input.maxFiles }),
318
+ };
319
+ }
320
+ function toHealthViolation(v) {
321
+ return {
322
+ ruleId: v.ruleId,
323
+ filePath: v.filePath,
324
+ message: v.message,
325
+ severity: v.severity,
326
+ category: v.category,
327
+ ...(v.line === undefined ? {} : { line: v.line }),
328
+ };
329
+ }
330
+ function decideStatus(stored, differences) {
331
+ if (!stored.exists) {
332
+ return 'baseline-created';
333
+ }
334
+ if (stored.snapshot === undefined) {
335
+ return 'invalid-snapshot';
336
+ }
337
+ return differences.length > 0 ? 'scope-mismatch' : 'compared';
338
+ }
339
+ function buildOutput(parts) {
340
+ const { root, snapshotLabel, written, previous, current, differences, compact, } = parts;
341
+ const status = parts.status === 'baseline-created' && !written
342
+ ? 'no-baseline'
343
+ : parts.status;
344
+ const previousRules = new Set(previous?.rulesExecuted ?? []);
345
+ const currentRules = new Set(current.rulesExecuted);
346
+ const base = {
347
+ status,
348
+ projectRoot: root,
349
+ snapshotPath: snapshotLabel,
350
+ snapshotWritten: written,
351
+ ...(previous === undefined ? {} : { previousRun: runInfo(previous) }),
352
+ currentRun: {
353
+ ...runInfo(current),
354
+ bySeverity: countBy(current.violations, (v) => v.severity),
355
+ byCategory: countBy(current.violations, (v) => v.category),
356
+ },
357
+ rulesAdded: previous === undefined
358
+ ? []
359
+ : current.rulesExecuted.filter((r) => !previousRules.has(r)),
360
+ rulesRemoved: previous === undefined
361
+ ? []
362
+ : previous.rulesExecuted.filter((r) => !currentRules.has(r)),
363
+ scopeDifferences: differences,
364
+ };
365
+ if (status !== 'compared' || previous === undefined) {
366
+ const byRule = compareHealth([], current.violations).byRule.map((r) => ({
367
+ ...r,
368
+ new: 0,
369
+ }));
370
+ return {
371
+ ...base,
372
+ byRule,
373
+ truncated: false,
374
+ summary: describeOther(status, snapshotLabel, previous, current, differences, written),
375
+ };
376
+ }
377
+ const delta = compareHealth(previous.violations, current.violations);
378
+ const totals = {
379
+ new: delta.newViolations.length,
380
+ fixed: delta.fixedViolations.length,
381
+ unchanged: delta.unchanged,
382
+ };
383
+ const summary = describeComparison(previous, current, totals, delta.byRule, delta.newViolations, delta.fixedViolations, base.rulesAdded, snapshotLabel, written);
384
+ if (compact.summaryOnly) {
385
+ return { ...base, totals, byRule: delta.byRule, truncated: false, summary };
386
+ }
387
+ const byFile = limitList(delta.byFile, compact.maxResults);
388
+ const added = limitList(delta.newViolations, compact.maxResults);
389
+ const fixed = limitList(delta.fixedViolations, compact.maxResults);
390
+ return {
391
+ ...base,
392
+ totals,
393
+ byRule: delta.byRule,
394
+ byFile: byFile.items,
395
+ newViolations: added.items,
396
+ fixedViolations: fixed.items,
397
+ truncated: byFile.truncated || added.truncated || fixed.truncated,
398
+ summary,
399
+ };
400
+ }
401
+ function runInfo(snapshot) {
402
+ return {
403
+ createdAt: snapshot.createdAt,
404
+ analyzedFiles: snapshot.analyzedFiles,
405
+ totalViolations: snapshot.violations.length,
406
+ };
407
+ }
408
+ function countBy(violations, key) {
409
+ const counts = {};
410
+ for (const v of violations) {
411
+ counts[key(v)] = (counts[key(v)] ?? 0) + 1;
412
+ }
413
+ return counts;
414
+ }
415
+ function describeViolation(v) {
416
+ const where = v.line === undefined ? v.filePath : `${v.filePath}:${v.line}`;
417
+ return `${where} ${v.ruleId}: ${v.message}`;
418
+ }
419
+ function listLines(label, violations) {
420
+ if (violations.length === 0) {
421
+ return [];
422
+ }
423
+ const lines = [
424
+ `${label}:`,
425
+ ...violations
426
+ .slice(0, SUMMARY_LINES)
427
+ .map((v) => `- ${describeViolation(v)}`),
428
+ ];
429
+ if (violations.length > SUMMARY_LINES) {
430
+ lines.push(`... and ${violations.length - SUMMARY_LINES} more.`);
431
+ }
432
+ return lines;
433
+ }
434
+ function describeComparison(previous, current, totals, byRule, added, fixed, rulesAdded, snapshotLabel, written) {
435
+ const lines = [
436
+ `Compared with the run of ${previous.createdAt}: ${totals.new} new, ${totals.fixed} fixed, ` +
437
+ `${totals.unchanged} unchanged (${previous.violations.length} -> ${current.violations.length} ` +
438
+ `violations, ${current.analyzedFiles} files).`,
439
+ ];
440
+ const changedRules = byRule.filter((r) => r.new + r.fixed > 0);
441
+ if (changedRules.length > 0) {
442
+ lines.push('By rule:', ...changedRules.map((r) => `- ${r.ruleId}: +${r.new} / -${r.fixed} (${r.previous} -> ${r.current})`));
443
+ }
444
+ if (rulesAdded.length > 0) {
445
+ lines.push(`Rules new since the previous run (their findings count as new): ${rulesAdded.join(', ')}.`);
446
+ }
447
+ lines.push(...listLines('New', added), ...listLines('Fixed', fixed));
448
+ lines.push(written
449
+ ? `Snapshot ${snapshotLabel} now holds this run.`
450
+ : `Snapshot ${snapshotLabel} kept (updateSnapshot: false).`);
451
+ return lines.join('\n');
452
+ }
453
+ function describeOther(status, snapshotLabel, previous, current, differences, written) {
454
+ const run = `${current.violations.length} violations in ${current.analyzedFiles} files`;
455
+ const replaced = written
456
+ ? ` Replaced by this run (updateSnapshot: true): ${run}.`
457
+ : ' Kept; pass updateSnapshot: true to replace it with this run, or another snapshotPath to keep both.';
458
+ switch (status) {
459
+ case 'baseline-created':
460
+ return `No previous run at ${snapshotLabel}. Baseline written: ${run}. The next run reports new, fixed and unchanged violations.`;
461
+ case 'no-baseline':
462
+ return `No previous run at ${snapshotLabel}; updateSnapshot is false, so no baseline was written. Current run: ${run}.`;
463
+ case 'scope-mismatch':
464
+ return (`The previous run (${previous?.createdAt ?? '?'}) used another scope, so nothing was compared: ` +
465
+ `${differences.join('; ')}.${replaced}`);
466
+ case 'invalid-snapshot':
467
+ return `${snapshotLabel} is not a readable health snapshot (version ${HEALTH_SNAPSHOT_VERSION}); nothing was compared.${replaced}`;
468
+ case 'compared':
469
+ return `Current run: ${run}.`;
470
+ }
471
+ }
472
+ //# sourceMappingURL=compare-health.js.map
@@ -9,7 +9,7 @@
9
9
  * 2. Extraction: pass an opportunity's artifacts to transform-code with
10
10
  * transformation: 'library-extraction' to execute the actual migration
11
11
  */
12
- import type { MCPTool } from '../types.js';
12
+ import type { MCPTool, ToolAnnotations } from '../types.js';
13
13
  /**
14
14
  * A single library extraction opportunity.
15
15
  */
@@ -40,8 +40,8 @@ interface ExtractionOpportunity {
40
40
  interface ExtractLibrariesResult {
41
41
  /** Detected extraction opportunities. */
42
42
  opportunities: ExtractionOpportunity[];
43
- /** Summary statistics. */
44
- summary: {
43
+ /** Counts over all opportunities, independent of the page. */
44
+ counts: {
45
45
  totalOpportunities: number;
46
46
  analyzedFiles: number;
47
47
  byCategory: Record<string, number>;
@@ -50,6 +50,8 @@ interface ExtractLibrariesResult {
50
50
  byKind: Record<string, number>;
51
51
  totalArtifacts: number;
52
52
  };
53
+ /** Human-readable summary for LLM consumption. */
54
+ summary: string;
53
55
  /** Suggested next step instructions for the LLM. */
54
56
  nextSteps: string[];
55
57
  /** Analysis metadata. */
@@ -72,9 +74,12 @@ interface ExtractLibrariesResult {
72
74
  */
73
75
  export declare class ExtractLibrariesTool implements MCPTool {
74
76
  readonly name = "extract-libraries";
75
- readonly description = "Detect Angular artifacts in shared folders that qualify for extraction into dedicated libraries with secondary entry points. Returns opportunities with cohesion/reusability scores and suggested library names.";
77
+ readonly title = "Detect Library Candidates";
78
+ readonly annotations: ToolAnnotations;
79
+ readonly description = "Detect Angular artifacts in shared folders that qualify for extraction into dedicated libraries with secondary entry points. Returns opportunities with cohesion/reusability scores and suggested library names; counts cover all of them, summary is a short text.";
76
80
  readonly inputSchema: {
77
81
  type: string;
82
+ additionalProperties: boolean;
78
83
  properties: {
79
84
  rootPath: {
80
85
  type: string;
@@ -117,6 +122,153 @@ export declare class ExtractLibrariesTool implements MCPTool {
117
122
  };
118
123
  required: string[];
119
124
  };
125
+ readonly outputSchema: {
126
+ type: string;
127
+ properties: {
128
+ opportunities: {
129
+ type: string;
130
+ items: {
131
+ type: string;
132
+ properties: {
133
+ ruleId: {
134
+ type: string;
135
+ };
136
+ message: {
137
+ type: string;
138
+ };
139
+ filePath: {
140
+ type: string;
141
+ };
142
+ suggestedLibraryName: {
143
+ type: string;
144
+ };
145
+ category: {
146
+ type: string;
147
+ };
148
+ artifacts: {
149
+ readonly type: "array";
150
+ readonly items: {
151
+ readonly type: "string";
152
+ };
153
+ };
154
+ secondaryEntryPoints: {
155
+ readonly type: "array";
156
+ readonly items: {
157
+ readonly type: "string";
158
+ };
159
+ };
160
+ cohesionScore: {
161
+ type: string;
162
+ };
163
+ reusabilityScore: {
164
+ type: string;
165
+ };
166
+ migrationComplexity: {
167
+ type: string;
168
+ };
169
+ estimatedEffort: {
170
+ type: string;
171
+ properties: {
172
+ value: {
173
+ type: string;
174
+ };
175
+ unit: {
176
+ type: string;
177
+ };
178
+ };
179
+ required: string[];
180
+ };
181
+ dependencies: {
182
+ readonly type: "array";
183
+ readonly items: {
184
+ readonly type: "string";
185
+ };
186
+ };
187
+ circularDependencies: {
188
+ readonly type: "array";
189
+ readonly items: {
190
+ readonly type: "string";
191
+ };
192
+ };
193
+ candidateKind: {
194
+ type: string;
195
+ };
196
+ metadata: {
197
+ type: string;
198
+ };
199
+ };
200
+ required: string[];
201
+ };
202
+ };
203
+ counts: {
204
+ type: string;
205
+ properties: {
206
+ totalOpportunities: {
207
+ type: string;
208
+ };
209
+ analyzedFiles: {
210
+ type: string;
211
+ };
212
+ byCategory: {
213
+ readonly type: "object";
214
+ readonly additionalProperties: {
215
+ readonly type: "integer";
216
+ };
217
+ };
218
+ byComplexity: {
219
+ readonly type: "object";
220
+ readonly additionalProperties: {
221
+ readonly type: "integer";
222
+ };
223
+ };
224
+ byKind: {
225
+ readonly type: "object";
226
+ readonly additionalProperties: {
227
+ readonly type: "integer";
228
+ };
229
+ };
230
+ totalArtifacts: {
231
+ type: string;
232
+ };
233
+ };
234
+ required: string[];
235
+ };
236
+ summary: {
237
+ type: string;
238
+ };
239
+ nextSteps: {
240
+ readonly type: "array";
241
+ readonly items: {
242
+ readonly type: "string";
243
+ };
244
+ };
245
+ metadata: {
246
+ type: string;
247
+ properties: {
248
+ duration: {
249
+ type: string;
250
+ };
251
+ projectRoot: {
252
+ type: string;
253
+ };
254
+ targetFolders: {
255
+ readonly type: "array";
256
+ readonly items: {
257
+ readonly type: "string";
258
+ };
259
+ };
260
+ minReusabilityScore: {
261
+ type: string;
262
+ };
263
+ minCohesionScore: {
264
+ type: string;
265
+ };
266
+ };
267
+ required: string[];
268
+ };
269
+ };
270
+ required: string[];
271
+ };
120
272
  execute(args: Record<string, unknown>): Promise<ExtractLibrariesResult>;
121
273
  private emptyResult;
122
274
  private buildNextSteps;