@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
package/dist/cli.js CHANGED
@@ -8,12 +8,15 @@ import { realpathSync, appendFileSync } from 'node:fs';
8
8
  import { dirname, join } from 'node:path';
9
9
  import { fileURLToPath } from 'node:url';
10
10
  import { MCPServer } from './server/mcp-server.js';
11
+ import { isDebugEnabled } from './mcp-watcher.js';
11
12
  import { routeConsoleToStderr } from './server/stdio-guard.js';
13
+ import { configureScanHost, parseScanWorkerSetting } from './scan-host/scan-host.js';
12
14
  import { AnalyzeProjectTool } from './tools/analyze-project.js';
13
15
  import { ScanArchitectureTool } from './tools/scan-architecture.js';
14
16
  import { ScanSolidTool } from './tools/scan-solid.js';
15
17
  import { ScanAngularTool } from './tools/scan-angular.js';
16
18
  import { ScanAllTool } from './tools/scan-all.js';
19
+ import { CompareHealthTool } from './tools/compare-health.js';
17
20
  import { PlanMigrationTool } from './tools/plan-migration.js';
18
21
  import { TransformCodeTool } from './tools/transform-code.js';
19
22
  import { RunAngularCliTool } from './tools/run-angular-cli.js';
@@ -48,12 +51,17 @@ import { InspectI18nTool } from './tools/inspect-i18n.js';
48
51
  import { ProjectCache, parseProjectCacheLimits, } from './tools/helpers/project-cache.js';
49
52
  import { FindAngularSymbolTool } from './tools/find-angular-symbol.js';
50
53
  import { SearchCodebaseTool } from './tools/search-codebase.js';
54
+ import { VerifyCitationsTool } from './tools/verify-citations.js';
51
55
  import { ServerStatusTool } from './tools/server-status.js';
52
56
  /**
53
- * Write debug message to MCP log file (mcp-server.log)
54
- * This ensures debug output appears in the same log file that MCP Watcher uses
57
+ * Write debug message to MCP log file (mcp-server.log), the file the MCP
58
+ * Watcher uses. Only with ANGULAR_MODERNIZER_DEBUG set: the file lands in the
59
+ * client's working directory.
55
60
  */
56
61
  function debugLog(message) {
62
+ if (!isDebugEnabled()) {
63
+ return;
64
+ }
57
65
  const timestamp = new Date().toISOString();
58
66
  const line = `[${timestamp}] DEBUG ${message}\n`;
59
67
  appendFileSync('./mcp-server.log', line);
@@ -110,11 +118,19 @@ function main() {
110
118
  cacheLimits.warnings.forEach((w) => console.error(`Project cache: ${w}`));
111
119
  const projects = new ProjectCache(cacheLimits.options);
112
120
  debugLog(`CLI Project cache limits: ${JSON.stringify(projects.limits)}`);
121
+ // Scans analyze in a worker thread (default; --scan-worker 0 or
122
+ // ANGULAR_MODERNIZER_SCAN_WORKER=0 runs them on the main thread), its
123
+ // heap limited to the same --max-heap-mb as the project cache
124
+ const scanWorker = parseScanWorkerSetting(process.argv.slice(2), process.env);
125
+ scanWorker.warnings.forEach((w) => console.error(`Scan worker: ${w}`));
126
+ configureScanHost({ enabled: scanWorker.enabled, maxHeapMb: projects.limits.maxHeapMb });
127
+ debugLog(`CLI Scan worker: ${scanWorker.enabled ? 'on' : 'off'}`);
113
128
  server.registerTool(new AnalyzeProjectTool());
114
129
  server.registerTool(new ScanArchitectureTool());
115
130
  server.registerTool(new ScanSolidTool());
116
131
  server.registerTool(new ScanAngularTool());
117
132
  server.registerTool(new ScanAllTool());
133
+ server.registerTool(new CompareHealthTool());
118
134
  server.registerTool(new PlanMigrationTool(projects));
119
135
  server.registerTool(new TransformCodeTool());
120
136
  server.registerTool(new RunAngularCliTool());
@@ -148,6 +164,7 @@ function main() {
148
164
  server.registerTool(new InspectI18nTool(projects));
149
165
  server.registerTool(new FindAngularSymbolTool(projects));
150
166
  server.registerTool(new SearchCodebaseTool(projects));
167
+ server.registerTool(new VerifyCitationsTool());
151
168
  server.registerTool(new ServerStatusTool(projects, () => server.getRuntimeStats(), distDirectories()));
152
169
  debugLog(`CLI ${server.getToolsMap().size} tools registered successfully`);
153
170
  // Register orchestration tool with access to all other tools
@@ -159,17 +176,8 @@ function main() {
159
176
  // Start the server
160
177
  server.start();
161
178
  debugLog('CLI MCP server.start() completed, server should now be listening on stdin');
162
- // Keep the process running
163
- process.on('SIGINT', () => {
164
- console.error('Received SIGINT, shutting down gracefully...');
165
- server.stop();
166
- process.exit(0);
167
- });
168
- process.on('SIGTERM', () => {
169
- console.error('Received SIGTERM, shutting down gracefully...');
170
- server.stop();
171
- process.exit(0);
172
- });
179
+ // Signals, stdin end and a lost parent end the process through the
180
+ // server's shutdown(), which flushes stdout first
173
181
  }
174
182
  catch (error) {
175
183
  console.error('Failed to start MCP server:', error);
@@ -1,15 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Project Analyzer
3
- *
4
- * Core orchestration logic for analyzing Angular projects.
5
- * This module coordinates the Kernel, plugins, and analysis rules
6
- * to perform comprehensive project analysis.
7
- *
8
- * Design Philosophy: "Orchestrate, Don't Implement"
9
- * - This module doesn't contain analysis logic
10
- * - It coordinates existing components (Kernel, plugins, rules)
11
- * - All actual analysis happens in plugin rules
12
- */
13
1
  import { type AnalysisResult } from '@angular-modernizer/plugin-system';
14
2
  /**
15
3
  * Options for project analysis.
@@ -51,6 +39,9 @@ export interface AnalyzeProjectOptions {
51
39
  * 4. Executes all rules in parallel
52
40
  * 5. Collects and returns all analysis results
53
41
  *
42
+ * The function holds no analysis logic of its own; all findings come from
43
+ * the plugin rules.
44
+ *
54
45
  * @param options - Configuration for the analysis
55
46
  * @returns Promise resolving to array of all analysis results
56
47
  * @throws Error if project path is invalid or analysis fails
@@ -1,15 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Project Analyzer
3
- *
4
- * Core orchestration logic for analyzing Angular projects.
5
- * This module coordinates the Kernel, plugins, and analysis rules
6
- * to perform comprehensive project analysis.
7
- *
8
- * Design Philosophy: "Orchestrate, Don't Implement"
9
- * - This module doesn't contain analysis logic
10
- * - It coordinates existing components (Kernel, plugins, rules)
11
- * - All actual analysis happens in plugin rules
12
- */
13
1
  import { Kernel } from '@angular-modernizer/core';
14
2
  import { AnalyzerPlugin } from '@angular-modernizer/plugin-analyzer';
15
3
  import { createPublicApi } from '@angular-modernizer/api';
@@ -24,6 +12,9 @@ import { ContextFactory, } from '@angular-modernizer/plugin-system';
24
12
  * 4. Executes all rules in parallel
25
13
  * 5. Collects and returns all analysis results
26
14
  *
15
+ * The function holds no analysis logic of its own; all findings come from
16
+ * the plugin rules.
17
+ *
27
18
  * @param options - Configuration for the analysis
28
19
  * @returns Promise resolving to array of all analysis results
29
20
  * @throws Error if project path is invalid or analysis fails
package/dist/index.d.ts CHANGED
@@ -1,19 +1,62 @@
1
1
  /**
2
- * @angular-modernizer/adapter-mcp - MCP Server Entry Point
2
+ * MCP server of the Angular Modernizer: 41 tools for analysis, migration
3
+ * planning, transformation, build validation, rollback, feedback and bug
4
+ * investigation of Angular projects, served over stdio with the MCP
5
+ * TypeScript SDK.
3
6
  *
4
- * This module provides the Model Context Protocol (MCP) server
5
- * that exposes Angular Modernizer analysis capabilities to AI assistants.
7
+ * @remarks
8
+ * The server speaks both protocol eras on one stdio connection: clients that
9
+ * open with `initialize` get the revision they ask for (2025-06-18,
10
+ * 2025-11-25), clients that open with `server/discover` get 2026-07-28.
11
+ * Arguments are validated against each tool's input schema; every tool
12
+ * answers with `structuredContent` validated against its output schema and a
13
+ * text block with the result's `summary`.
14
+ *
15
+ * Run the server through the `angular-modernizer-mcp` bin (`dist/cli.js`):
16
+ *
17
+ * ```bash
18
+ * npx @angular-modernizer/adapter-mcp
19
+ * claude mcp add angular-modernizer npx @angular-modernizer/adapter-mcp
20
+ * ```
21
+ *
22
+ * `cli.js` takes `--max-projects N` and `--max-heap-mb N` for the shared
23
+ * ts-morph project cache (defaults 3 and 2048 MB, 0 = no heap limit).
24
+ *
25
+ * The package entry exports the building blocks for embedding the server or
26
+ * calling tools directly:
27
+ *
28
+ * - {@link MCPServer}: stdio server lifecycle; register tools, then `start()`.
29
+ * - {@link ToolRegistry}: tool registration and execution.
30
+ * - {@link MCPTool}: the tool contract every tool class implements, with
31
+ * {@link ToolContext} for cancellation and progress.
32
+ * - The tool classes, one per MCP tool, e.g. {@link ScanAllTool},
33
+ * {@link TransformCodeTool}, {@link FindUsagesTool}, {@link ServerStatusTool}.
34
+ * - {@link ProgressStore}: operation store of the deprecated streaming path.
35
+ * - {@link startMCPWatcher}: debug log and health check, enabled with
36
+ * `ANGULAR_MODERNIZER_DEBUG`.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { MCPServer, ScanAllTool, FindUsagesTool } from '@angular-modernizer/adapter-mcp';
41
+ *
42
+ * const server = new MCPServer();
43
+ * server.registerTool(new ScanAllTool());
44
+ * server.registerTool(new FindUsagesTool());
45
+ * server.start();
46
+ * ```
47
+ *
48
+ * @packageDocumentation
6
49
  */
7
50
  export { MCPServer } from './server/mcp-server.js';
8
51
  export { ToolRegistry } from './server/tool-registry.js';
9
- export { JsonRpcHandler } from './server/json-rpc-handler.js';
10
- export { startMCPWatcher, stopMCPWatcher, getMCPWatcher, } from './mcp-watcher.js';
52
+ export { startMCPWatcher, stopMCPWatcher, getMCPWatcher, isDebugEnabled, DEBUG_ENV, } from './mcp-watcher.js';
11
53
  export type { MCPWatcher, WatcherState, OperationInfo } from './mcp-watcher.js';
12
54
  export { AnalyzeProjectTool } from './tools/analyze-project.js';
13
55
  export { ScanArchitectureTool } from './tools/scan-architecture.js';
14
56
  export { ScanSolidTool } from './tools/scan-solid.js';
15
57
  export { ScanAngularTool } from './tools/scan-angular.js';
16
58
  export { ScanAllTool } from './tools/scan-all.js';
59
+ export { CompareHealthTool } from './tools/compare-health.js';
17
60
  export { PlanMigrationTool } from './tools/plan-migration.js';
18
61
  export { TransformCodeTool } from './tools/transform-code.js';
19
62
  export { RunAngularCliTool } from './tools/run-angular-cli.js';
@@ -48,7 +91,80 @@ export { InspectFormGroupTool } from './tools/inspect-form-group.js';
48
91
  export { InspectI18nTool } from './tools/inspect-i18n.js';
49
92
  export { FindAngularSymbolTool } from './tools/find-angular-symbol.js';
50
93
  export { SearchCodebaseTool } from './tools/search-codebase.js';
94
+ export { VerifyCitationsTool } from './tools/verify-citations.js';
51
95
  export { ProgressStore, type OperationMetadata, type OperationState, } from './streaming/progress-store.js';
52
- export type { MCPTool, MCPServerConfig, JsonRpcRequest, JsonRpcResponse, JsonRpcNotification, ToolExecutionContext, } from './types.js';
96
+ export type { MCPTool, ToolAnnotations, MCPServerConfig, JsonRpcRequest, JsonRpcResponse, JsonRpcNotification, ToolExecutionContext, ToolContext, ProgressFn, } from './types.js';
53
97
  export { analyzeProject } from './core/project-analyzer.js';
98
+ export type { AnalyzeProjectOptions } from './core/project-analyzer.js';
99
+ export type { JsonRpcError } from './types.js';
100
+ export type { MemorySnapshot } from './mcp-watcher.js';
101
+ export type { ServerRuntimeStats } from './server/mcp-server.js';
102
+ export type { ProjectCache } from './tools/helpers/project-cache.js';
103
+ export type { HealthScan, CompareHealthOutput } from './tools/compare-health.js';
104
+ export type { DistDirectory, ServerStatusOutput } from './tools/server-status.js';
105
+ export type { AnalyzeBuildImpactOutput } from './tools/analyze-build-impact.js';
106
+ export type { AnalyzeCoreToSharedResult } from './tools/analyze-core-to-shared.js';
107
+ export type { AnalyzeParserPerformanceOutput } from './tools/analyze-parser-performance.js';
108
+ export type { AnalyzeProjectResult } from './tools/analyze-project.js';
109
+ export type { CompatibilityCheckOutput } from './tools/check-incremental-compatibility.js';
110
+ export type { CollectFeedbackOutput, CollectAnalysisFeedbackOutput, } from './tools/collect-feedback.js';
111
+ export type { ExtractLibrariesResult } from './tools/extract-libraries.js';
112
+ export type { FindAngularSymbolOutput } from './tools/find-angular-symbol.js';
113
+ export type { FindComponentHostsOutput } from './tools/find-component-hosts.js';
114
+ export type { FindUsagesOutput } from './tools/find-usages.js';
115
+ export type { GetBootstrapExecutionOutput } from './tools/get-bootstrap-execution.js';
116
+ export type { GetCallGraphOutput } from './tools/get-call-graph.js';
117
+ export type { InspectFormGroupOutput } from './tools/inspect-form-group.js';
118
+ export type { InspectI18nOutput } from './tools/inspect-i18n.js';
119
+ export type { InspectTemplateOutput } from './tools/inspect-template.js';
120
+ export type { LearnPatternsResult } from './tools/learn-patterns.js';
121
+ export type { ListImportsOutput } from './tools/list-imports.js';
122
+ export type { OrchestrateMigrationResult } from './tools/orchestrate-migration.js';
123
+ export type { ParseStackTraceOutput } from './tools/parse-stack-trace.js';
124
+ export type { PlanMigrationResult } from './tools/plan-migration.js';
125
+ export type { ReviewFeedbackOutput } from './tools/review-feedback.js';
126
+ export type { RollbackResult } from './tools/rollback-changes.js';
127
+ export type { AngularCliResult } from './tools/run-angular-cli.js';
128
+ export type { BuildResult } from './tools/run-build.js';
129
+ export type { SchematicResult } from './tools/run-schematic.js';
130
+ export type { ScanAllResult } from './tools/scan-all.js';
131
+ export type { ScanAngularResult } from './tools/scan-angular.js';
132
+ export type { ScanArchitectureResult } from './tools/scan-architecture.js';
133
+ export type { ScanSolidResult } from './tools/scan-solid.js';
134
+ export type { SearchCodebaseOutput } from './tools/search-codebase.js';
135
+ export type { SuggestImprovementsOutput } from './tools/suggest-improvements.js';
136
+ export type { TraceOutputFlowOutput } from './tools/trace-output-flow.js';
137
+ export type { TransformationResult } from './tools/transform-code.js';
138
+ export type { ValidationResult as ValidateBeforeTransformResult } from './tools/validate-before-transform.js';
139
+ export type { ValidationResult as ValidateTransformationResult } from './tools/validate-transformation.js';
140
+ export type { ValidateProjectCompatibilityOutput } from './tools/validate-project-compatibility.js';
141
+ export type { VerifyCitationsOutput } from './tools/verify-citations.js';
142
+ export type { BuildImpactCounts, BuildScopeStrategy, DependencyInfo, EstimatedBuildScope, MappedFile, TemplateHost, UnresolvedFile, } from './tools/analyze-build-impact.js';
143
+ export type { AggregatedParserMetrics, SessionMetricsDetail, } from './tools/analyze-parser-performance.js';
144
+ export type { RecommendationType } from './tools/check-incremental-compatibility.js';
145
+ export type { CompareHealthStatus, HealthRunInfo, HealthScanResult, } from './tools/compare-health.js';
146
+ export type { ExtractionOpportunity } from './tools/extract-libraries.js';
147
+ export type { CoverageOutput, HostOutput } from './tools/find-component-hosts.js';
148
+ export type { RootOutput } from './tools/get-bootstrap-execution.js';
149
+ export type { ControlOutput, FormOutput } from './tools/inspect-form-group.js';
150
+ export type { DetailField, ListField as InspectI18nListField, SourceOutput, } from './tools/inspect-i18n.js';
151
+ export type { ListField as InspectTemplateListField, TemplateReportOutput, } from './tools/inspect-template.js';
152
+ export type { ImportCounts, ImportEntry, NamedImportEntry, } from './tools/list-imports.js';
153
+ export type { MigrationStep, MigrationStrategy, ScanPlanOutput, StyleAwareRiskAssessment, } from './tools/plan-migration.js';
154
+ export type { FeedbackInsight, QualityWarning } from './tools/review-feedback.js';
155
+ export type { IncrementalMetadata as RunBuildIncrementalMetadata } from './tools/run-build.js';
156
+ export type { ResolvedScope, ScanExecution } from './tools/scan-architecture.js';
157
+ export type { DistPackageState } from './tools/server-status.js';
158
+ export type { DynamicFlowOutput, OutputFlowOutput } from './tools/trace-output-flow.js';
159
+ export type { IncrementalMetadata as ValidateTransformationIncrementalMetadata } from './tools/validate-transformation.js';
160
+ export type { VerifiedCitation } from './tools/verify-citations.js';
161
+ export type { ScanCounts } from './tools/helpers/analysis-output.js';
162
+ export type { FileDelta, HealthViolation, RuleDelta, } from './tools/helpers/health-delta.js';
163
+ export type { CachedProjectInfo, EvictionReason, EvictionStats, ProjectCacheLimits, ProjectEviction, } from './tools/helpers/project-cache.js';
164
+ export type { RuleTiming } from './tools/helpers/rule-runner.js';
165
+ export type { Performance, Suggestion } from './tools/helpers/suggestion-generator.js';
166
+ export type { CancelledExecution } from './tools/helpers/tool-context.js';
167
+ export type { ResponseRecord, ResponseStats } from './server/limited-stdio-transport.js';
168
+ export type { ScanHostStatus, ScanWorkerInfo } from './scan-host/scan-host.js';
169
+ export type { ProtocolEra, ProtocolInfo } from './server/sdk-server.js';
54
170
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,21 +1,64 @@
1
1
  /**
2
- * @angular-modernizer/adapter-mcp - MCP Server Entry Point
2
+ * MCP server of the Angular Modernizer: 41 tools for analysis, migration
3
+ * planning, transformation, build validation, rollback, feedback and bug
4
+ * investigation of Angular projects, served over stdio with the MCP
5
+ * TypeScript SDK.
3
6
  *
4
- * This module provides the Model Context Protocol (MCP) server
5
- * that exposes Angular Modernizer analysis capabilities to AI assistants.
7
+ * @remarks
8
+ * The server speaks both protocol eras on one stdio connection: clients that
9
+ * open with `initialize` get the revision they ask for (2025-06-18,
10
+ * 2025-11-25), clients that open with `server/discover` get 2026-07-28.
11
+ * Arguments are validated against each tool's input schema; every tool
12
+ * answers with `structuredContent` validated against its output schema and a
13
+ * text block with the result's `summary`.
14
+ *
15
+ * Run the server through the `angular-modernizer-mcp` bin (`dist/cli.js`):
16
+ *
17
+ * ```bash
18
+ * npx @angular-modernizer/adapter-mcp
19
+ * claude mcp add angular-modernizer npx @angular-modernizer/adapter-mcp
20
+ * ```
21
+ *
22
+ * `cli.js` takes `--max-projects N` and `--max-heap-mb N` for the shared
23
+ * ts-morph project cache (defaults 3 and 2048 MB, 0 = no heap limit).
24
+ *
25
+ * The package entry exports the building blocks for embedding the server or
26
+ * calling tools directly:
27
+ *
28
+ * - {@link MCPServer}: stdio server lifecycle; register tools, then `start()`.
29
+ * - {@link ToolRegistry}: tool registration and execution.
30
+ * - {@link MCPTool}: the tool contract every tool class implements, with
31
+ * {@link ToolContext} for cancellation and progress.
32
+ * - The tool classes, one per MCP tool, e.g. {@link ScanAllTool},
33
+ * {@link TransformCodeTool}, {@link FindUsagesTool}, {@link ServerStatusTool}.
34
+ * - {@link ProgressStore}: operation store of the deprecated streaming path.
35
+ * - {@link startMCPWatcher}: debug log and health check, enabled with
36
+ * `ANGULAR_MODERNIZER_DEBUG`.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { MCPServer, ScanAllTool, FindUsagesTool } from '@angular-modernizer/adapter-mcp';
41
+ *
42
+ * const server = new MCPServer();
43
+ * server.registerTool(new ScanAllTool());
44
+ * server.registerTool(new FindUsagesTool());
45
+ * server.start();
46
+ * ```
47
+ *
48
+ * @packageDocumentation
6
49
  */
7
50
  // Export server infrastructure
8
51
  export { MCPServer } from './server/mcp-server.js';
9
52
  export { ToolRegistry } from './server/tool-registry.js';
10
- export { JsonRpcHandler } from './server/json-rpc-handler.js';
11
53
  // Export MCP Watcher for debugging and monitoring
12
- export { startMCPWatcher, stopMCPWatcher, getMCPWatcher, } from './mcp-watcher.js';
54
+ export { startMCPWatcher, stopMCPWatcher, getMCPWatcher, isDebugEnabled, DEBUG_ENV, } from './mcp-watcher.js';
13
55
  // Export MCP tools
14
56
  export { AnalyzeProjectTool } from './tools/analyze-project.js';
15
57
  export { ScanArchitectureTool } from './tools/scan-architecture.js';
16
58
  export { ScanSolidTool } from './tools/scan-solid.js';
17
59
  export { ScanAngularTool } from './tools/scan-angular.js';
18
60
  export { ScanAllTool } from './tools/scan-all.js';
61
+ export { CompareHealthTool } from './tools/compare-health.js';
19
62
  export { PlanMigrationTool } from './tools/plan-migration.js';
20
63
  export { TransformCodeTool } from './tools/transform-code.js';
21
64
  export { RunAngularCliTool } from './tools/run-angular-cli.js';
@@ -52,6 +95,7 @@ export { InspectFormGroupTool } from './tools/inspect-form-group.js';
52
95
  export { InspectI18nTool } from './tools/inspect-i18n.js';
53
96
  export { FindAngularSymbolTool } from './tools/find-angular-symbol.js';
54
97
  export { SearchCodebaseTool } from './tools/search-codebase.js';
98
+ export { VerifyCitationsTool } from './tools/verify-citations.js';
55
99
  // Export streaming utilities
56
100
  export { ProgressStore, } from './streaming/progress-store.js';
57
101
  // Re-export existing project analyzer for compatibility
@@ -1,32 +1,53 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - MCP Watcher
3
- *
4
- * Writes periodic status updates to mcp-server.log to help debug
5
- * hanging operations like analyze-project.
6
- */
1
+ /** Internal state of the {@link MCPWatcher}. */
7
2
  export interface WatcherState {
3
+ /** When the watcher started. */
8
4
  startTime: Date;
5
+ /** Time of the last heartbeat. */
9
6
  lastHeartbeat: Date;
7
+ /** Number of heartbeats since the start. */
10
8
  heartbeatCount: number;
9
+ /** Running operations by operation id. */
11
10
  activeOperations: Map<string, OperationInfo>;
11
+ /** Memory readings of the last 20 heartbeats, oldest first. */
12
12
  memorySnapshots: MemorySnapshot[];
13
+ /** Port of the health check HTTP server; unset when disabled. */
13
14
  healthCheckPort?: number;
14
15
  }
16
+ /** An operation tracked by the {@link MCPWatcher}. */
15
17
  export interface OperationInfo {
18
+ /** Operation id. */
16
19
  operationId: string;
20
+ /** Name of the tool running the operation. */
17
21
  toolName: string;
22
+ /** When the operation started. */
18
23
  startTime: Date;
24
+ /** Time of the last phase update. */
19
25
  lastUpdate: Date;
26
+ /** Current phase, `'starting'` at the start. */
20
27
  phase: string;
28
+ /** Details of the current phase. */
21
29
  details?: string;
22
30
  }
23
- interface MemorySnapshot {
31
+ /** Memory reading of one heartbeat, in bytes (`process.memoryUsage()`). */
32
+ export interface MemorySnapshot {
33
+ /** Time of the reading. */
24
34
  timestamp: Date;
35
+ /** V8 heap in use. */
25
36
  heapUsed: number;
37
+ /** V8 heap allocated. */
26
38
  heapTotal: number;
39
+ /** Memory of C++ objects bound to JavaScript objects. */
27
40
  external: number;
41
+ /** Resident set size of the process. */
28
42
  rss: number;
29
43
  }
44
+ /**
45
+ * Debug watcher: writes periodic status updates (heartbeat, memory, running
46
+ * operations) to `mcp-server.log` to help debug hanging operations, and
47
+ * optionally serves a health check over HTTP. The server starts it only when
48
+ * `ANGULAR_MODERNIZER_DEBUG` is set; its timer is `unref()`ed and never keeps
49
+ * the process alive.
50
+ */
30
51
  declare class MCPWatcher {
31
52
  private readonly state;
32
53
  private readonly logPath;
@@ -103,6 +124,10 @@ declare class MCPWatcher {
103
124
  */
104
125
  private formatDuration;
105
126
  }
127
+ /** Environment variable that switches on the debug log and the watcher. */
128
+ export declare const DEBUG_ENV = "ANGULAR_MODERNIZER_DEBUG";
129
+ /** True when `ANGULAR_MODERNIZER_DEBUG` is set to anything but '', '0' or 'false'. */
130
+ export declare function isDebugEnabled(env?: NodeJS.ProcessEnv): boolean;
106
131
  /**
107
132
  * Initialize and start the MCP watcher
108
133
  */
@@ -1,12 +1,13 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - MCP Watcher
3
- *
4
- * Writes periodic status updates to mcp-server.log to help debug
5
- * hanging operations like analyze-project.
6
- */
7
1
  import { appendFileSync, writeFileSync } from 'node:fs';
8
2
  import { resolve } from 'node:path';
9
3
  import * as http from 'node:http';
4
+ /**
5
+ * Debug watcher: writes periodic status updates (heartbeat, memory, running
6
+ * operations) to `mcp-server.log` to help debug hanging operations, and
7
+ * optionally serves a health check over HTTP. The server starts it only when
8
+ * `ANGULAR_MODERNIZER_DEBUG` is set; its timer is `unref()`ed and never keeps
9
+ * the process alive.
10
+ */
10
11
  class MCPWatcher {
11
12
  state;
12
13
  logPath;
@@ -62,16 +63,9 @@ Platform: ${process.platform}
62
63
  }, this.intervalMs);
63
64
  // Diagnostics must never keep the process alive after stdin closes
64
65
  this.heartbeatInterval.unref();
65
- // Ensure cleanup on exit
66
+ // Ensure cleanup on exit. Signals end the process through the server's
67
+ // shutdown(), which stops the watcher; a handler here would exit first.
66
68
  process.on('beforeExit', () => this.stop());
67
- process.on('SIGINT', () => {
68
- this.stop();
69
- process.exit(0);
70
- });
71
- process.on('SIGTERM', () => {
72
- this.stop();
73
- process.exit(0);
74
- });
75
69
  }
76
70
  /**
77
71
  * Stop the heartbeat loop
@@ -350,6 +344,13 @@ Platform: ${process.platform}
350
344
  return `${(ms / 3600000).toFixed(1)}h`;
351
345
  }
352
346
  }
347
+ /** Environment variable that switches on the debug log and the watcher. */
348
+ export const DEBUG_ENV = 'ANGULAR_MODERNIZER_DEBUG';
349
+ /** True when `ANGULAR_MODERNIZER_DEBUG` is set to anything but '', '0' or 'false'. */
350
+ export function isDebugEnabled(env = process.env) {
351
+ const value = env[DEBUG_ENV]?.trim().toLowerCase();
352
+ return value !== undefined && value !== '' && value !== '0' && value !== 'false';
353
+ }
353
354
  // Singleton instance
354
355
  let watcherInstance = null;
355
356
  /**
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Scan worker host
3
+ *
4
+ * Runs the analysis part of a scan ({@link runScanEngine}) in a worker
5
+ * thread. The first type query of a scan builds the TypeScript program and
6
+ * type checker synchronously (large app: 2784 program files, 1.6 s in one
7
+ * block); on the main thread the server reads no stdin meanwhile, so a
8
+ * `notifications/cancelled` and every other request wait. In a worker the
9
+ * main thread keeps serving, and a cancel ends the worker with `terminate()`,
10
+ * which stops synchronous JavaScript too, the checker build included.
11
+ *
12
+ * One scan worker serves the scans one after the other, each with a new
13
+ * kernel; further scans wait in a queue (heap). The worker stays alive after
14
+ * a finished scan: a new isolate loads ts-morph, core and api in about 400 ms
15
+ * and runs the TypeScript code unoptimized, which made each scan on a small
16
+ * scope 1.5 to 3 s slower than on the main thread (large app). A cancel, an
17
+ * error or the heap limit ends the worker; the host then starts the next one,
18
+ * which loads the modules while it waits. The worker heap is limited to
19
+ * `--max-heap-mb`; it is not part of the main thread's `heapUsed`, which the
20
+ * project cache checks.
21
+ */
22
+ import { type ScanEngineResult, type ScanSink, type ScanSpec } from '../tools/helpers/scan-engine.js';
23
+ /** Settings of the scan host. */
24
+ export interface ScanHostSettings {
25
+ /** Run scans in a worker; off means in the calling thread. */
26
+ enabled: boolean;
27
+ /** Old-generation heap limit of a scan worker in MB; 0 means no limit. */
28
+ maxHeapMb: number;
29
+ }
30
+ /** A running scan worker, as server-status shows it. */
31
+ export interface ScanWorkerInfo {
32
+ /** Thread id of the worker. */
33
+ threadId: number;
34
+ /** Tool that started it. */
35
+ tool: string;
36
+ /** Start time of the scan (ISO). */
37
+ startedAt: string;
38
+ /** Files the scan analyzes. */
39
+ files: number;
40
+ /** Files analyzed so far. */
41
+ filesDone: number;
42
+ /** Last heap the worker reported, in MB. */
43
+ heapUsedMB?: number;
44
+ }
45
+ /** State of the scan host for server-status. */
46
+ export interface ScanHostStatus {
47
+ /** Scans run in a worker. */
48
+ enabled: boolean;
49
+ /** Heap limit of a scan worker in MB; 0 means no limit. */
50
+ maxHeapMB: number;
51
+ /** A worker with loaded modules waits for the next scan (started ahead or from the last scan). */
52
+ standby: boolean;
53
+ /** Running workers (at most one). */
54
+ running: ScanWorkerInfo[];
55
+ /** Scans waiting for the running one. */
56
+ queued: number;
57
+ /** Scans started in a worker since the server started. */
58
+ started: number;
59
+ /** Workers terminated by a cancel. */
60
+ cancelled: number;
61
+ /** Workers that failed (error, crash, heap limit). */
62
+ failed: number;
63
+ }
64
+ /** Command-line flag and environment variable of the scan worker switch. */
65
+ export declare const SCAN_WORKER_FLAG: {
66
+ readonly flag: "--scan-worker";
67
+ readonly env: "ANGULAR_MODERNIZER_SCAN_WORKER";
68
+ };
69
+ /**
70
+ * Sets how scans run. The CLI turns the worker on, which also starts the
71
+ * waiting worker; without this call (Jest, library use) scans run in the
72
+ * calling thread.
73
+ */
74
+ export declare function configureScanHost(next: Partial<ScanHostSettings>): void;
75
+ /** Ends the waiting worker (tests; the server ends with the process). */
76
+ export declare function stopStandby(): void;
77
+ /** Current settings. */
78
+ export declare function scanHostSettings(): ScanHostSettings;
79
+ /** State for server-status. */
80
+ export declare function describeScanHost(): ScanHostStatus;
81
+ /**
82
+ * Reads the scan worker switch from `--scan-worker` (`--scan-worker=0`,
83
+ * `--scan-worker 0`) or `ANGULAR_MODERNIZER_SCAN_WORKER`; the flag wins.
84
+ * Default on; `0`, `false`, `off` switch it off. Other values keep the
85
+ * default with a warning.
86
+ */
87
+ export declare function parseScanWorkerSetting(argv: readonly string[], env: Readonly<Record<string, string | undefined>>): {
88
+ enabled: boolean;
89
+ warnings: string[];
90
+ };
91
+ /** Options of a scan run. */
92
+ export interface RunScanOptions {
93
+ /** Aborted by `notifications/cancelled`. */
94
+ signal?: AbortSignal;
95
+ }
96
+ /**
97
+ * Runs a scan in a worker when the host is enabled and there is something to
98
+ * analyze, otherwise in the calling thread. Both report through `sink`; a
99
+ * cancelled worker run resolves with `cancelled: true` and only the files the
100
+ * sink got before the cancel.
101
+ */
102
+ export declare function runScan(spec: ScanSpec, sink: ScanSink, options?: RunScanOptions): Promise<ScanEngineResult>;
103
+ /** Options of {@link runScanInWorker}. */
104
+ export interface WorkerRunOptions {
105
+ signal?: AbortSignal;
106
+ /** Old-generation heap limit in MB; 0 or unset means no limit. */
107
+ maxHeapMb?: number;
108
+ /** Worker script; default the scan worker next to this module (standby when ready). */
109
+ workerUrl?: URL;
110
+ }
111
+ /**
112
+ * Runs `spec` in a worker. Abort terminates the worker at once and resolves
113
+ * with `cancelled: true`; messages arriving after the abort are dropped. A
114
+ * worker that fails or exits without a result rejects. The call returns once
115
+ * the worker has exited, so the next queued scan never shares the memory
116
+ * with it.
117
+ */
118
+ export declare function runScanInWorker(spec: ScanSpec, sink: ScanSink, options?: WorkerRunOptions): Promise<ScanEngineResult>;
119
+ //# sourceMappingURL=scan-host.d.ts.map