@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
@@ -10,14 +10,50 @@ import { Project } from 'ts-morph';
10
10
  import { existsSync } from 'node:fs';
11
11
  import { join, dirname } from 'node:path';
12
12
  import { execSync } from 'node:child_process';
13
+ import { INCOMPATIBILITY_ISSUES_SCHEMA } from './helpers/build-schemas.js';
14
+ import { VALIDATION_ISSUES_SCHEMA, issueCount, issueLines, } from './helpers/validation-output.js';
15
+ /** Text summary: verdict, checks, validation mode, counts per severity and the first issues. */
16
+ function describeTransformationValidation(result) {
17
+ const checks = [
18
+ result.metadata.buildValidation ? 'build' : undefined,
19
+ result.metadata.testValidation ? 'tests' : undefined,
20
+ result.metadata.lintValidation ? 'lint' : undefined,
21
+ ].filter((c) => c !== undefined);
22
+ const lines = [
23
+ `${result.valid ? 'Valid' : 'Not valid'}: ${result.metadata.filePath} ` +
24
+ `(${checks.length > 0 ? checks.join(', ') : 'no checks'}; ${result.duration} ms); ` +
25
+ `${issueCount(result.issues)}.`,
26
+ ];
27
+ const inc = result.incremental;
28
+ if (inc !== undefined) {
29
+ lines.push(inc.enabled
30
+ ? `Incremental (${inc.scope ?? 'unknown scope'}): ${inc.filesValidated ?? 0} file(s) validated, ` +
31
+ `${inc.filesSkipped ?? 0} skipped${inc.speedup === undefined ? '' : `; ${inc.speedup}`}.`
32
+ : `Full validation${inc.fallbackReason === undefined ? '' : `: ${inc.fallbackReason}`}.`);
33
+ }
34
+ if (result.metadata.buildCommand !== undefined) {
35
+ lines.push(`Build command: ${result.metadata.buildCommand} (${result.metadata.buildCommandSource ?? 'unknown source'}).`);
36
+ }
37
+ lines.push(...issueLines(result.issues));
38
+ return lines.join('\n');
39
+ }
13
40
  /**
14
41
  * MCP tool for post-transformation validation with incremental build support.
15
42
  */
16
43
  export class ValidateTransformationTool {
17
44
  name = 'validate-transformation';
18
- description = 'Validate code after transformation to ensure changes did not break anything. Supports incremental build mode for 2-4x faster validation by checking only transformed files and their dependencies. Automatically detects project compatibility and falls back to full validation when needed.';
45
+ title = 'Validate Transformation';
46
+ annotations = {
47
+ readOnlyHint: false,
48
+ destructiveHint: true,
49
+ idempotentHint: true,
50
+ openWorldHint: false,
51
+ };
52
+ description = 'Validate code after transformation to ensure changes did not break anything. Supports incremental build mode for 2-4x faster validation by checking only transformed files and their dependencies. Automatically detects project compatibility and falls back to full validation when needed. ' +
53
+ 'summary is a short text with the verdict, the validation mode, the issue counts and the first issues.';
19
54
  inputSchema = {
20
55
  type: 'object',
56
+ additionalProperties: false,
21
57
  properties: {
22
58
  filePath: {
23
59
  type: 'string',
@@ -86,7 +122,53 @@ export class ValidateTransformationTool {
86
122
  },
87
123
  required: ['filePath'],
88
124
  };
89
- async execute(args) {
125
+ outputSchema = {
126
+ type: 'object',
127
+ properties: {
128
+ valid: { type: 'boolean' },
129
+ issues: VALIDATION_ISSUES_SCHEMA,
130
+ duration: { type: 'number' },
131
+ metadata: {
132
+ type: 'object',
133
+ properties: {
134
+ filePath: { type: 'string' },
135
+ buildValidation: { type: 'boolean' },
136
+ testValidation: { type: 'boolean' },
137
+ lintValidation: { type: 'boolean' },
138
+ cwd: { type: 'string' },
139
+ buildCommand: { type: 'string' },
140
+ buildCommandSource: { type: 'string' },
141
+ },
142
+ required: [
143
+ 'filePath',
144
+ 'buildValidation',
145
+ 'testValidation',
146
+ 'lintValidation',
147
+ ],
148
+ },
149
+ incremental: {
150
+ type: 'object',
151
+ properties: {
152
+ enabled: { type: 'boolean' },
153
+ scope: { type: 'string' },
154
+ filesValidated: { type: 'integer' },
155
+ filesSkipped: { type: 'integer' },
156
+ cacheHit: { type: 'boolean' },
157
+ speedup: { type: 'string' },
158
+ fallbackReason: { type: 'string' },
159
+ incompatibilityIssues: INCOMPATIBILITY_ISSUES_SCHEMA,
160
+ },
161
+ required: ['enabled'],
162
+ },
163
+ summary: { type: 'string' },
164
+ },
165
+ required: ['valid', 'issues', 'duration', 'metadata', 'summary'],
166
+ };
167
+ async execute(args, ctx = {}) {
168
+ const result = await this.runValidation(args, ctx.signal);
169
+ return { ...result, summary: describeTransformationValidation(result) };
170
+ }
171
+ async runValidation(args, signal) {
90
172
  const typedArgs = args;
91
173
  // Determine project root
92
174
  const projectRoot = typedArgs.cwd ?? this.detectProjectRoot(typedArgs.filePath);
@@ -105,22 +187,30 @@ export class ValidateTransformationTool {
105
187
  mergedArgs.validateBuild !== false &&
106
188
  mergedArgs.incrementalMode !== false &&
107
189
  !typedArgs.forceFullBuild;
190
+ let fallbackReason = typedArgs.forceFullBuild
191
+ ? 'Full validation forced by user'
192
+ : `No angular.json in ${projectRoot}: incremental validation needs an Angular CLI project`;
108
193
  if (shouldUseIncremental) {
109
194
  try {
110
- return await this.executeIncrementalValidation(typedArgs.filePath, projectRoot, typedArgs);
195
+ return await this.executeIncrementalValidation(typedArgs.filePath, projectRoot, typedArgs, signal);
111
196
  }
112
197
  catch (error) {
113
- // Fallback to legacy validation on any error
114
- console.warn('Incremental validation failed, falling back to legacy validation:', error instanceof Error ? error.message : String(error));
198
+ // A cancelled build stops; any other error falls back to legacy validation
199
+ if (signal?.aborted === true) {
200
+ throw error;
201
+ }
202
+ const message = error instanceof Error ? error.message : String(error);
203
+ console.warn('Incremental validation failed, falling back to legacy validation:', message);
204
+ fallbackReason = `Incremental validation failed: ${message}`;
115
205
  }
116
206
  }
117
207
  // Use legacy PostTransformValidator
118
- return this.executeLegacyValidation(typedArgs.filePath, typedArgs);
208
+ return this.executeLegacyValidation(typedArgs.filePath, typedArgs, fallbackReason, signal);
119
209
  }
120
210
  /**
121
211
  * Executes incremental build validation using IncrementalBuildValidator
122
212
  */
123
- async executeIncrementalValidation(filePath, projectRoot, args) {
213
+ async executeIncrementalValidation(filePath, projectRoot, args, signal) {
124
214
  // Dynamic imports to avoid circular dependencies
125
215
  const { IncompatibilityDetector, IncrementalBuildValidator, IncrementalAnalyzer, CacheManager, RealFileSystemAdapter, } = await import('@angular-modernizer/core');
126
216
  const startTime = Date.now();
@@ -215,6 +305,7 @@ export class ValidateTransformationTool {
215
305
  baseBranch: 'HEAD',
216
306
  forceFiles: filesToValidate,
217
307
  includeDependents: true,
308
+ signal,
218
309
  });
219
310
  // Calculate speedup
220
311
  const fullBuildEstimate = validationResult.scope.estimatedBuildTime * 1000;
@@ -293,7 +384,7 @@ export class ValidateTransformationTool {
293
384
  /**
294
385
  * Executes legacy validation using PostTransformValidator
295
386
  */
296
- async executeLegacyValidation(filePath, args) {
387
+ async executeLegacyValidation(filePath, args, fallbackReason, signal) {
297
388
  const validator = new PostTransformValidator();
298
389
  const config = {
299
390
  validateBuild: args.validateBuild ?? true,
@@ -303,6 +394,7 @@ export class ValidateTransformationTool {
303
394
  testTimeout: args.testTimeout ?? 600000,
304
395
  lintTimeout: args.lintTimeout ?? 120000,
305
396
  cwd: args.cwd,
397
+ signal,
306
398
  };
307
399
  const result = await validator.validate(filePath, config);
308
400
  // Transform ValidationResult from core to MCP format
@@ -324,15 +416,12 @@ export class ValidateTransformationTool {
324
416
  testValidation: args.validateTests ?? false,
325
417
  lintValidation: args.validateLint ?? true,
326
418
  cwd: args.cwd,
419
+ ...buildCommandOf(result.metadata),
327
420
  },
328
- incremental: args.incrementalMode === false
421
+ // Only a build has an incremental mode to fall back from
422
+ incremental: args.incrementalMode === false || args.validateBuild === false
329
423
  ? undefined
330
- : {
331
- enabled: false,
332
- fallbackReason: args.forceFullBuild
333
- ? 'Full validation forced by user'
334
- : 'Incremental mode not available or compatible',
335
- },
424
+ : { enabled: false, fallbackReason },
336
425
  };
337
426
  return response;
338
427
  }
@@ -388,4 +477,13 @@ export class ValidateTransformationTool {
388
477
  }
389
478
  }
390
479
  }
480
+ /** Build command and its source from the validator's metadata. */
481
+ function buildCommandOf(metadata) {
482
+ const command = metadata?.['buildCommand'];
483
+ const source = metadata?.['buildCommandSource'];
484
+ return {
485
+ ...(typeof command === 'string' ? { buildCommand: command } : {}),
486
+ ...(typeof source === 'string' ? { buildCommandSource: source } : {}),
487
+ };
488
+ }
391
489
  //# sourceMappingURL=validate-transformation.js.map
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Verify Citations Tool
3
+ *
4
+ * MCP tool that checks the `path:line` citations of Markdown plans against the
5
+ * current code: does the cited file exist, is the line range still in the
6
+ * file, and does the symbol named next to the citation still sit in the range?
7
+ *
8
+ * @remarks
9
+ * Run it before executing a bug-fix or feature plan (stale line numbers make
10
+ * edits land in the wrong place) and after writing one. Logic lives in the api
11
+ * `CitationVerifier`; the claude-plugin script `verify-citations.mjs` is the
12
+ * same check for sessions without this server.
13
+ *
14
+ * First tool on the structured output contract: `outputSchema`, `title` and
15
+ * `annotations`, answered with `structuredContent`.
16
+ */
17
+ import { type CitationFileSource, type CitationStatus } from '@angular-modernizer/api';
18
+ import { type MCPTool, type ToolAnnotations } from '../types.js';
19
+ /** One checked citation in the tool output. */
20
+ export interface VerifiedCitation {
21
+ /** Plan file relative to `projectRoot`. */
22
+ plan: string;
23
+ planLine: number;
24
+ /** Citation as written, e.g. `x.ts:12-20`. */
25
+ text: string;
26
+ status: CitationStatus;
27
+ file?: string;
28
+ matched?: string;
29
+ foundAt?: number[];
30
+ current?: string;
31
+ fileLength?: number;
32
+ candidates?: string[];
33
+ }
34
+ /** Output of the verify-citations tool. */
35
+ export interface VerifyCitationsOutput {
36
+ projectRoot: string;
37
+ plans: {
38
+ plan: string;
39
+ citations: number;
40
+ needsAttention: number;
41
+ }[];
42
+ total: number;
43
+ needsAttention: number;
44
+ counts: Record<CitationStatus, number>;
45
+ /** Citations that need attention first, then the others, each in plan order. */
46
+ citations?: VerifiedCitation[];
47
+ truncated: boolean;
48
+ summary: string;
49
+ }
50
+ export declare class VerifyCitationsTool implements MCPTool {
51
+ private readonly createSource;
52
+ readonly name = "verify-citations";
53
+ readonly title = "Verify Plan Citations";
54
+ readonly description: string;
55
+ readonly annotations: ToolAnnotations;
56
+ readonly inputSchema: {
57
+ type: string;
58
+ additionalProperties: boolean;
59
+ properties: {
60
+ summaryOnly: {
61
+ readonly type: "boolean";
62
+ readonly description: "Return counts and the text summary only, without the result list. Default: false.";
63
+ readonly default: false;
64
+ };
65
+ maxResults: {
66
+ readonly type: "number";
67
+ readonly description: string;
68
+ };
69
+ planPaths: {
70
+ type: string;
71
+ items: {
72
+ type: string;
73
+ };
74
+ minItems: number;
75
+ description: string;
76
+ };
77
+ projectRoot: {
78
+ type: string;
79
+ description: string;
80
+ };
81
+ };
82
+ required: string[];
83
+ };
84
+ readonly outputSchema: {
85
+ type: string;
86
+ properties: {
87
+ projectRoot: {
88
+ type: string;
89
+ };
90
+ plans: {
91
+ type: string;
92
+ items: {
93
+ type: string;
94
+ properties: {
95
+ plan: {
96
+ type: string;
97
+ };
98
+ citations: {
99
+ type: string;
100
+ };
101
+ needsAttention: {
102
+ type: string;
103
+ };
104
+ };
105
+ required: string[];
106
+ };
107
+ };
108
+ total: {
109
+ type: string;
110
+ };
111
+ needsAttention: {
112
+ type: string;
113
+ };
114
+ counts: {
115
+ type: string;
116
+ properties: {
117
+ [k: string]: {
118
+ type: string;
119
+ };
120
+ };
121
+ required: CitationStatus[];
122
+ };
123
+ citations: {
124
+ type: string;
125
+ items: {
126
+ readonly type: "object";
127
+ readonly properties: {
128
+ readonly plan: {
129
+ readonly type: "string";
130
+ };
131
+ readonly planLine: {
132
+ readonly type: "integer";
133
+ };
134
+ readonly text: {
135
+ readonly type: "string";
136
+ };
137
+ readonly status: {
138
+ readonly type: "string";
139
+ readonly enum: readonly CitationStatus[];
140
+ };
141
+ readonly file: {
142
+ readonly type: "string";
143
+ };
144
+ readonly matched: {
145
+ readonly type: "string";
146
+ };
147
+ readonly foundAt: {
148
+ readonly type: "array";
149
+ readonly items: {
150
+ readonly type: "integer";
151
+ };
152
+ };
153
+ readonly current: {
154
+ readonly type: "string";
155
+ };
156
+ readonly fileLength: {
157
+ readonly type: "integer";
158
+ };
159
+ readonly candidates: {
160
+ readonly type: "array";
161
+ readonly items: {
162
+ readonly type: "string";
163
+ };
164
+ };
165
+ };
166
+ readonly required: readonly ["plan", "planLine", "text", "status"];
167
+ };
168
+ };
169
+ truncated: {
170
+ type: string;
171
+ };
172
+ summary: {
173
+ type: string;
174
+ };
175
+ };
176
+ required: string[];
177
+ };
178
+ constructor(createSource?: (projectRoot: string) => CitationFileSource);
179
+ execute(args: Record<string, unknown>): Promise<VerifyCitationsOutput>;
180
+ }
181
+ //# sourceMappingURL=verify-citations.d.ts.map
@@ -0,0 +1,218 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Verify Citations Tool
3
+ *
4
+ * MCP tool that checks the `path:line` citations of Markdown plans against the
5
+ * current code: does the cited file exist, is the line range still in the
6
+ * file, and does the symbol named next to the citation still sit in the range?
7
+ *
8
+ * @remarks
9
+ * Run it before executing a bug-fix or feature plan (stale line numbers make
10
+ * edits land in the wrong place) and after writing one. Logic lives in the api
11
+ * `CitationVerifier`; the claude-plugin script `verify-citations.mjs` is the
12
+ * same check for sessions without this server.
13
+ *
14
+ * First tool on the structured output contract: `outputSchema`, `title` and
15
+ * `annotations`, answered with `structuredContent`.
16
+ */
17
+ import { isAbsolute, relative, resolve } from 'node:path';
18
+ import { CITATION_ATTENTION_STATUSES, CitationVerifier, } from '@angular-modernizer/api';
19
+ import { createNodeCitationFileSource } from './helpers/citation-file-source.js';
20
+ import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, truncationNote, } from './helpers/compact-output.js';
21
+ const STATUSES = [
22
+ 'ok',
23
+ 'unverified',
24
+ 'moved',
25
+ 'anchor-missing',
26
+ 'out-of-range',
27
+ 'missing-file',
28
+ 'ambiguous',
29
+ ];
30
+ /** Attention entries spelled out in the summary; the rest is in `citations`. */
31
+ const SUMMARY_LINES = 20;
32
+ const CITATION_SCHEMA = {
33
+ type: 'object',
34
+ properties: {
35
+ plan: { type: 'string' },
36
+ planLine: { type: 'integer' },
37
+ text: { type: 'string' },
38
+ status: { type: 'string', enum: [...STATUSES] },
39
+ file: { type: 'string' },
40
+ matched: { type: 'string' },
41
+ foundAt: { type: 'array', items: { type: 'integer' } },
42
+ current: { type: 'string' },
43
+ fileLength: { type: 'integer' },
44
+ candidates: { type: 'array', items: { type: 'string' } },
45
+ },
46
+ required: ['plan', 'planLine', 'text', 'status'],
47
+ };
48
+ export class VerifyCitationsTool {
49
+ createSource;
50
+ name = 'verify-citations';
51
+ title = 'Verify Plan Citations';
52
+ description = 'Check the path:line citations of Markdown plans (bug-fix plans, feature plans, investigation reports) ' +
53
+ 'against the current code. Per citation: ok (the symbol named next to it is inside the cited range), ' +
54
+ 'unverified (range exists, no symbol to check; current line text shown), moved (symbol found at other ' +
55
+ 'lines: foundAt), anchor-missing (symbol nowhere in the file), out-of-range (file too short), ' +
56
+ 'missing-file (similar files listed as candidates), ambiguous (bare file name matches several files). ' +
57
+ 'Citations inside fenced code blocks are skipped. Run before executing a plan and after writing one. ' +
58
+ 'needsAttention counts moved, anchor-missing, out-of-range, missing-file and ambiguous; those come first ' +
59
+ 'in citations. Read-only.';
60
+ annotations = {
61
+ readOnlyHint: true,
62
+ destructiveHint: false,
63
+ idempotentHint: true,
64
+ openWorldHint: false,
65
+ };
66
+ inputSchema = {
67
+ type: 'object',
68
+ additionalProperties: false,
69
+ properties: {
70
+ planPaths: {
71
+ type: 'array',
72
+ items: { type: 'string' },
73
+ minItems: 1,
74
+ description: 'Markdown files to check, absolute or relative to projectRoot (e.g. plan.md and investigation.md of one plan folder).',
75
+ },
76
+ projectRoot: {
77
+ type: 'string',
78
+ description: 'Absolute path of the repository the plans cite. Cited paths resolve from here, then from the plan folder, then by path suffix.',
79
+ },
80
+ ...COMPACT_OUTPUT_SCHEMA,
81
+ },
82
+ required: ['planPaths', 'projectRoot'],
83
+ };
84
+ outputSchema = {
85
+ type: 'object',
86
+ properties: {
87
+ projectRoot: { type: 'string' },
88
+ plans: {
89
+ type: 'array',
90
+ items: {
91
+ type: 'object',
92
+ properties: {
93
+ plan: { type: 'string' },
94
+ citations: { type: 'integer' },
95
+ needsAttention: { type: 'integer' },
96
+ },
97
+ required: ['plan', 'citations', 'needsAttention'],
98
+ },
99
+ },
100
+ total: { type: 'integer' },
101
+ needsAttention: { type: 'integer' },
102
+ counts: {
103
+ type: 'object',
104
+ properties: Object.fromEntries(STATUSES.map((s) => [s, { type: 'integer' }])),
105
+ required: [...STATUSES],
106
+ },
107
+ citations: { type: 'array', items: CITATION_SCHEMA },
108
+ truncated: { type: 'boolean' },
109
+ summary: { type: 'string' },
110
+ },
111
+ required: ['projectRoot', 'plans', 'total', 'needsAttention', 'counts', 'truncated', 'summary'],
112
+ };
113
+ constructor(createSource = createNodeCitationFileSource) {
114
+ this.createSource = createSource;
115
+ }
116
+ async execute(args) {
117
+ const { planPaths, projectRoot } = args;
118
+ if (typeof projectRoot !== 'string' || projectRoot === '') {
119
+ throw new Error('projectRoot is required');
120
+ }
121
+ if (!Array.isArray(planPaths) ||
122
+ planPaths.length === 0 ||
123
+ !planPaths.every((p) => typeof p === 'string' && p !== '')) {
124
+ throw new Error('planPaths must be a non-empty array of file paths');
125
+ }
126
+ const compact = parseCompactOptions(args);
127
+ const root = resolve(projectRoot);
128
+ const plans = planPaths.map((p) => (isAbsolute(p) ? p : resolve(root, p)));
129
+ const source = this.createSource(root);
130
+ const missing = plans.filter((p) => !source.isFile(p));
131
+ if (missing.length > 0) {
132
+ throw new Error(`Plan file not found: ${missing.join(', ')}`);
133
+ }
134
+ const reports = new CitationVerifier(root, source).verifyPlans(plans);
135
+ const label = (plan) => relative(root, plan) || plan;
136
+ const all = reports.flatMap((r) => r.results.map((c) => toVerified(label(r.plan), c)));
137
+ const attention = all.filter((c) => CITATION_ATTENTION_STATUSES.has(c.status));
138
+ const counts = Object.fromEntries(STATUSES.map((s) => [s, all.filter((c) => c.status === s).length]));
139
+ const planSummaries = reports.map((r) => ({
140
+ plan: label(r.plan),
141
+ citations: r.results.length,
142
+ needsAttention: r.results.filter((c) => CITATION_ATTENTION_STATUSES.has(c.status)).length,
143
+ }));
144
+ const ordered = [...attention, ...all.filter((c) => !CITATION_ATTENTION_STATUSES.has(c.status))];
145
+ const shown = limitList(ordered, compact.summaryOnly ? undefined : compact.maxResults);
146
+ const summary = buildSummary(planSummaries, all.length, counts, attention, shown.items.length);
147
+ const base = {
148
+ projectRoot: root,
149
+ plans: planSummaries,
150
+ total: all.length,
151
+ needsAttention: attention.length,
152
+ counts,
153
+ };
154
+ if (compact.summaryOnly) {
155
+ return { ...base, truncated: false, summary };
156
+ }
157
+ return { ...base, citations: shown.items, truncated: shown.truncated, summary };
158
+ }
159
+ }
160
+ function toVerified(plan, c) {
161
+ return {
162
+ plan,
163
+ planLine: c.planLine,
164
+ text: c.text,
165
+ status: c.status,
166
+ ...(c.file === undefined ? {} : { file: c.file }),
167
+ ...(c.matched === undefined ? {} : { matched: c.matched }),
168
+ ...(c.foundAt === undefined ? {} : { foundAt: c.foundAt }),
169
+ ...(c.current === undefined ? {} : { current: c.current }),
170
+ ...(c.fileLength === undefined ? {} : { fileLength: c.fileLength }),
171
+ ...(c.candidates === undefined ? {} : { candidates: c.candidates }),
172
+ };
173
+ }
174
+ function describeCitation(c) {
175
+ const anchor = c.matched === undefined ? '' : ` [${c.matched}]`;
176
+ const where = `${c.plan}:${c.planLine} ${c.text}${anchor}`;
177
+ switch (c.status) {
178
+ case 'moved':
179
+ return `- moved: ${where} -> now at line ${(c.foundAt ?? []).join(', ')} of ${c.file ?? '?'}`;
180
+ case 'anchor-missing':
181
+ return `- anchor-missing: ${where} -> not found in ${c.file ?? '?'}; the line reads "${c.current ?? ''}"`;
182
+ case 'out-of-range':
183
+ return `- out-of-range: ${where} -> ${c.file ?? '?'} has ${c.fileLength ?? 0} lines`;
184
+ case 'missing-file': {
185
+ const similar = c.candidates ?? [];
186
+ return `- missing-file: ${where}${similar.length > 0 ? ` -> similar: ${similar.join(', ')}` : ''}`;
187
+ }
188
+ case 'ambiguous':
189
+ return `- ambiguous: ${where} -> ${(c.candidates ?? []).slice(0, 5).join(', ')}`;
190
+ case 'ok':
191
+ case 'unverified':
192
+ return `- ${c.status}: ${where}`;
193
+ }
194
+ }
195
+ function buildSummary(plans, total, counts, attention, shown) {
196
+ const byStatus = STATUSES.filter((s) => counts[s] > 0)
197
+ .map((s) => `${counts[s]} ${s}`)
198
+ .join(', ');
199
+ const lines = [
200
+ `${total} citation(s) in ${plans.length} plan(s)${byStatus === '' ? '.' : `: ${byStatus}.`}`,
201
+ ];
202
+ if (attention.length === 0) {
203
+ lines.push('No citation needs attention.');
204
+ }
205
+ else {
206
+ lines.push(`${attention.length} need attention:`);
207
+ lines.push(...attention.slice(0, SUMMARY_LINES).map(describeCitation));
208
+ if (attention.length > SUMMARY_LINES) {
209
+ lines.push(`... and ${attention.length - SUMMARY_LINES} more in citations.`);
210
+ }
211
+ }
212
+ const note = truncationNote(shown, total, 'citations');
213
+ if (note !== undefined && shown > 0) {
214
+ lines.push(note);
215
+ }
216
+ return lines.join('\n');
217
+ }
218
+ //# sourceMappingURL=verify-citations.js.map
package/dist/types.d.ts CHANGED
@@ -20,12 +20,49 @@ export interface MCPTool {
20
20
  * JSON Schema for tool input validation.
21
21
  */
22
22
  inputSchema: object;
23
+ /** Display name for clients (MCP 2025-06-18). */
24
+ title?: string;
25
+ /** Behavior hints for clients (MCP 2025-03-26); hints, not guarantees. */
26
+ annotations?: ToolAnnotations;
27
+ /**
28
+ * JSON Schema of the result object (MCP 2025-06-18). Every tool answers
29
+ * with `structuredContent` plus a text block with its `summary`; with a
30
+ * schema the SDK validates `structuredContent` against it. All tools of
31
+ * this package set one.
32
+ */
33
+ outputSchema?: object;
23
34
  /**
24
35
  * Execute the tool with given arguments.
25
36
  * @param args - Tool arguments validated against inputSchema
37
+ * @param ctx - Cancellation and progress of the MCP request (absent in direct calls)
26
38
  * @returns Tool execution result
27
39
  */
28
- execute(args: Record<string, unknown>): Promise<unknown>;
40
+ execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<unknown>;
41
+ }
42
+ /**
43
+ * Reports progress of a running tool call. `progress` grows with every call;
44
+ * `total` is the expected end value when known.
45
+ */
46
+ export type ProgressFn = (progress: number, total?: number, message?: string) => void;
47
+ /**
48
+ * Per-call context of an MCP request. `signal` aborts when the client sends
49
+ * `notifications/cancelled` (the SDK then sends no response); `progress` is
50
+ * set only when the client asked for progress with a `progressToken`.
51
+ */
52
+ export interface ToolContext {
53
+ signal?: AbortSignal;
54
+ progress?: ProgressFn;
55
+ }
56
+ /**
57
+ * MCP tool annotations. `readOnlyHint` means the tool does not change its
58
+ * environment (writing the analyzer's own cache does not count);
59
+ * `destructiveHint` and `idempotentHint` only matter when it is not read-only.
60
+ */
61
+ export interface ToolAnnotations {
62
+ readOnlyHint?: boolean;
63
+ destructiveHint?: boolean;
64
+ idempotentHint?: boolean;
65
+ openWorldHint?: boolean;
29
66
  }
30
67
  /**
31
68
  * JSON-RPC 2.0 request message.