@angular-modernizer/adapter-mcp 0.3.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/README.md +181 -282
  2. package/dist/cli.js +21 -13
  3. package/dist/core/project-analyzer.d.ts +3 -12
  4. package/dist/core/project-analyzer.js +3 -12
  5. package/dist/index.d.ts +122 -6
  6. package/dist/index.js +49 -5
  7. package/dist/mcp-watcher.d.ts +32 -7
  8. package/dist/mcp-watcher.js +16 -15
  9. package/dist/scan-host/scan-host.d.ts +119 -0
  10. package/dist/scan-host/scan-host.js +376 -0
  11. package/dist/scan-host/scan-protocol.d.ts +35 -0
  12. package/dist/scan-host/scan-protocol.js +6 -0
  13. package/dist/scan-host/scan-worker.d.ts +14 -0
  14. package/dist/scan-host/scan-worker.js +48 -0
  15. package/dist/server/limited-stdio-transport.d.ts +75 -0
  16. package/dist/server/limited-stdio-transport.js +115 -0
  17. package/dist/server/mcp-server.d.ts +20 -18
  18. package/dist/server/mcp-server.js +42 -79
  19. package/dist/server/package-version.d.ts +16 -0
  20. package/dist/server/package-version.js +37 -0
  21. package/dist/server/sdk-server.d.ts +71 -0
  22. package/dist/server/sdk-server.js +113 -0
  23. package/dist/server/tool-registry.d.ts +6 -9
  24. package/dist/server/tool-registry.js +6 -12
  25. package/dist/streaming/progress-store.d.ts +22 -5
  26. package/dist/streaming/progress-store.js +9 -5
  27. package/dist/tools/analyze-build-impact.d.ts +276 -35
  28. package/dist/tools/analyze-build-impact.js +175 -28
  29. package/dist/tools/analyze-core-to-shared.d.ts +176 -16
  30. package/dist/tools/analyze-core-to-shared.js +124 -19
  31. package/dist/tools/analyze-parser-performance.d.ts +209 -15
  32. package/dist/tools/analyze-parser-performance.js +119 -56
  33. package/dist/tools/analyze-project.d.ts +349 -17
  34. package/dist/tools/analyze-project.js +282 -97
  35. package/dist/tools/check-incremental-compatibility.d.ts +74 -12
  36. package/dist/tools/check-incremental-compatibility.js +69 -10
  37. package/dist/tools/collect-feedback.d.ts +225 -21
  38. package/dist/tools/collect-feedback.js +199 -118
  39. package/dist/tools/compare-health.d.ts +413 -0
  40. package/dist/tools/compare-health.js +479 -0
  41. package/dist/tools/extract-libraries.d.ts +200 -24
  42. package/dist/tools/extract-libraries.js +131 -27
  43. package/dist/tools/find-angular-symbol.d.ts +92 -24
  44. package/dist/tools/find-angular-symbol.js +70 -20
  45. package/dist/tools/find-component-hosts.d.ts +603 -27
  46. package/dist/tools/find-component-hosts.js +223 -19
  47. package/dist/tools/find-usages.d.ts +102 -22
  48. package/dist/tools/find-usages.js +81 -21
  49. package/dist/tools/get-bootstrap-execution.d.ts +183 -25
  50. package/dist/tools/get-bootstrap-execution.js +109 -25
  51. package/dist/tools/get-call-graph.d.ts +127 -12
  52. package/dist/tools/get-call-graph.js +84 -19
  53. package/dist/tools/get-operation-progress-tool.d.ts +126 -8
  54. package/dist/tools/get-operation-progress-tool.js +124 -12
  55. package/dist/tools/get-operation-progress.d.ts +27 -1
  56. package/dist/tools/get-operation-progress.js +5 -5
  57. package/dist/tools/helpers/analysis-output.d.ts +182 -0
  58. package/dist/tools/helpers/analysis-output.js +165 -0
  59. package/dist/tools/helpers/batch-kernel.d.ts +14 -0
  60. package/dist/tools/helpers/batch-kernel.js +12 -0
  61. package/dist/tools/helpers/build-schemas.d.ts +36 -0
  62. package/dist/tools/helpers/build-schemas.js +23 -0
  63. package/dist/tools/helpers/citation-file-source.d.ts +10 -0
  64. package/dist/tools/helpers/citation-file-source.js +82 -0
  65. package/dist/tools/helpers/compact-output.d.ts +2 -1
  66. package/dist/tools/helpers/compact-output.js +2 -1
  67. package/dist/tools/helpers/finding-window.d.ts +43 -0
  68. package/dist/tools/helpers/finding-window.js +64 -0
  69. package/dist/tools/helpers/health-delta.d.ts +99 -0
  70. package/dist/tools/helpers/health-delta.js +236 -0
  71. package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
  72. package/dist/tools/helpers/investigation-schemas.js +48 -0
  73. package/dist/tools/helpers/library-imports.d.ts +57 -0
  74. package/dist/tools/helpers/library-imports.js +151 -0
  75. package/dist/tools/helpers/load-source-files.d.ts +30 -0
  76. package/dist/tools/helpers/load-source-files.js +34 -0
  77. package/dist/tools/helpers/output-contract.d.ts +32 -0
  78. package/dist/tools/helpers/output-contract.js +32 -0
  79. package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
  80. package/dist/tools/helpers/platform-root-resolver.js +75 -48
  81. package/dist/tools/helpers/process-output.d.ts +19 -0
  82. package/dist/tools/helpers/process-output.js +31 -0
  83. package/dist/tools/helpers/project-cache.d.ts +60 -37
  84. package/dist/tools/helpers/project-cache.js +54 -37
  85. package/dist/tools/helpers/project-decorators.d.ts +14 -0
  86. package/dist/tools/helpers/project-decorators.js +22 -0
  87. package/dist/tools/helpers/rule-matcher.js +5 -0
  88. package/dist/tools/helpers/rule-runner.d.ts +25 -13
  89. package/dist/tools/helpers/rule-runner.js +45 -24
  90. package/dist/tools/helpers/scan-cache.d.ts +22 -0
  91. package/dist/tools/helpers/scan-cache.js +34 -0
  92. package/dist/tools/helpers/scan-engine.d.ts +107 -0
  93. package/dist/tools/helpers/scan-engine.js +197 -0
  94. package/dist/tools/helpers/scan-plan.d.ts +5 -2
  95. package/dist/tools/helpers/scan-plan.js +18 -3
  96. package/dist/tools/helpers/scope-paths.d.ts +17 -0
  97. package/dist/tools/helpers/scope-paths.js +32 -0
  98. package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
  99. package/dist/tools/helpers/suggestion-generator.js +0 -12
  100. package/dist/tools/helpers/tool-cache.d.ts +11 -0
  101. package/dist/tools/helpers/tool-cache.js +15 -0
  102. package/dist/tools/helpers/tool-context.d.ts +63 -0
  103. package/dist/tools/helpers/tool-context.js +79 -0
  104. package/dist/tools/helpers/transform-safety.d.ts +40 -0
  105. package/dist/tools/helpers/transform-safety.js +87 -0
  106. package/dist/tools/helpers/validation-output.d.ts +53 -0
  107. package/dist/tools/helpers/validation-output.js +48 -0
  108. package/dist/tools/inspect-form-group.d.ts +262 -24
  109. package/dist/tools/inspect-form-group.js +134 -13
  110. package/dist/tools/inspect-i18n.d.ts +410 -23
  111. package/dist/tools/inspect-i18n.js +213 -13
  112. package/dist/tools/inspect-template.d.ts +260 -22
  113. package/dist/tools/inspect-template.js +174 -13
  114. package/dist/tools/learn-patterns.d.ts +210 -13
  115. package/dist/tools/learn-patterns.js +113 -12
  116. package/dist/tools/list-imports.d.ts +152 -34
  117. package/dist/tools/list-imports.js +124 -18
  118. package/dist/tools/orchestrate-migration.d.ts +159 -14
  119. package/dist/tools/orchestrate-migration.js +147 -20
  120. package/dist/tools/parse-stack-trace.d.ts +78 -21
  121. package/dist/tools/parse-stack-trace.js +44 -7
  122. package/dist/tools/plan-migration.d.ts +395 -26
  123. package/dist/tools/plan-migration.js +173 -22
  124. package/dist/tools/resolve-type.d.ts +57 -9
  125. package/dist/tools/resolve-type.js +49 -12
  126. package/dist/tools/review-feedback.d.ts +214 -16
  127. package/dist/tools/review-feedback.js +142 -57
  128. package/dist/tools/rollback-changes.d.ts +88 -7
  129. package/dist/tools/rollback-changes.js +74 -19
  130. package/dist/tools/run-angular-cli.d.ts +57 -12
  131. package/dist/tools/run-angular-cli.js +76 -13
  132. package/dist/tools/run-build.d.ts +127 -13
  133. package/dist/tools/run-build.js +128 -16
  134. package/dist/tools/run-schematic.d.ts +82 -12
  135. package/dist/tools/run-schematic.js +115 -18
  136. package/dist/tools/scan-all.d.ts +88 -23
  137. package/dist/tools/scan-all.js +161 -220
  138. package/dist/tools/scan-angular.d.ts +60 -19
  139. package/dist/tools/scan-angular.js +100 -141
  140. package/dist/tools/scan-architecture.d.ts +92 -24
  141. package/dist/tools/scan-architecture.js +268 -211
  142. package/dist/tools/scan-solid.d.ts +59 -19
  143. package/dist/tools/scan-solid.js +98 -139
  144. package/dist/tools/search-codebase.d.ts +110 -23
  145. package/dist/tools/search-codebase.js +67 -11
  146. package/dist/tools/server-status.d.ts +392 -26
  147. package/dist/tools/server-status.js +260 -27
  148. package/dist/tools/suggest-improvements.d.ts +105 -10
  149. package/dist/tools/suggest-improvements.js +91 -51
  150. package/dist/tools/trace-output-flow.d.ts +713 -26
  151. package/dist/tools/trace-output-flow.js +396 -33
  152. package/dist/tools/transform-code-batch.d.ts +3 -0
  153. package/dist/tools/transform-code-batch.js +10 -5
  154. package/dist/tools/transform-code.d.ts +402 -18
  155. package/dist/tools/transform-code.js +708 -649
  156. package/dist/tools/validate-before-transform.d.ts +136 -7
  157. package/dist/tools/validate-before-transform.js +65 -9
  158. package/dist/tools/validate-project-compatibility.d.ts +82 -15
  159. package/dist/tools/validate-project-compatibility.js +84 -15
  160. package/dist/tools/validate-transformation.d.ts +243 -8
  161. package/dist/tools/validate-transformation.js +127 -23
  162. package/dist/tools/verify-citations.d.ts +202 -0
  163. package/dist/tools/verify-citations.js +221 -0
  164. package/dist/types.d.ts +78 -11
  165. package/dist/types.js +0 -5
  166. package/dist/utils/format-tool-response.d.ts +22 -59
  167. package/dist/utils/format-tool-response.js +25 -134
  168. package/package.json +31 -20
  169. package/dist/cli.d.ts.map +0 -1
  170. package/dist/cli.js.map +0 -1
  171. package/dist/core/project-analyzer.d.ts.map +0 -1
  172. package/dist/core/project-analyzer.js.map +0 -1
  173. package/dist/index.d.ts.map +0 -1
  174. package/dist/index.js.map +0 -1
  175. package/dist/mcp-watcher.d.ts.map +0 -1
  176. package/dist/mcp-watcher.js.map +0 -1
  177. package/dist/server/json-rpc-handler.d.ts +0 -98
  178. package/dist/server/json-rpc-handler.d.ts.map +0 -1
  179. package/dist/server/json-rpc-handler.js +0 -301
  180. package/dist/server/json-rpc-handler.js.map +0 -1
  181. package/dist/server/mcp-server.d.ts.map +0 -1
  182. package/dist/server/mcp-server.js.map +0 -1
  183. package/dist/server/stdio-guard.d.ts.map +0 -1
  184. package/dist/server/stdio-guard.js.map +0 -1
  185. package/dist/server/tool-registry.d.ts.map +0 -1
  186. package/dist/server/tool-registry.js.map +0 -1
  187. package/dist/streaming/progress-store.d.ts.map +0 -1
  188. package/dist/streaming/progress-store.js.map +0 -1
  189. package/dist/tools/analyze-build-impact.d.ts.map +0 -1
  190. package/dist/tools/analyze-build-impact.js.map +0 -1
  191. package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
  192. package/dist/tools/analyze-core-to-shared.js.map +0 -1
  193. package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
  194. package/dist/tools/analyze-parser-performance.js.map +0 -1
  195. package/dist/tools/analyze-project.d.ts.map +0 -1
  196. package/dist/tools/analyze-project.js.map +0 -1
  197. package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
  198. package/dist/tools/check-incremental-compatibility.js.map +0 -1
  199. package/dist/tools/collect-feedback.d.ts.map +0 -1
  200. package/dist/tools/collect-feedback.js.map +0 -1
  201. package/dist/tools/extract-libraries.d.ts.map +0 -1
  202. package/dist/tools/extract-libraries.js.map +0 -1
  203. package/dist/tools/find-angular-symbol.d.ts.map +0 -1
  204. package/dist/tools/find-angular-symbol.js.map +0 -1
  205. package/dist/tools/find-component-hosts.d.ts.map +0 -1
  206. package/dist/tools/find-component-hosts.js.map +0 -1
  207. package/dist/tools/find-usages.d.ts.map +0 -1
  208. package/dist/tools/find-usages.js.map +0 -1
  209. package/dist/tools/get-bootstrap-execution.d.ts.map +0 -1
  210. package/dist/tools/get-bootstrap-execution.js.map +0 -1
  211. package/dist/tools/get-call-graph.d.ts.map +0 -1
  212. package/dist/tools/get-call-graph.js.map +0 -1
  213. package/dist/tools/get-operation-progress-tool.d.ts.map +0 -1
  214. package/dist/tools/get-operation-progress-tool.js.map +0 -1
  215. package/dist/tools/get-operation-progress.d.ts.map +0 -1
  216. package/dist/tools/get-operation-progress.js.map +0 -1
  217. package/dist/tools/helpers/compact-output.d.ts.map +0 -1
  218. package/dist/tools/helpers/compact-output.js.map +0 -1
  219. package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
  220. package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
  221. package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
  222. package/dist/tools/helpers/find-ts-config.js.map +0 -1
  223. package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
  224. package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
  225. package/dist/tools/helpers/project-cache.d.ts.map +0 -1
  226. package/dist/tools/helpers/project-cache.js.map +0 -1
  227. package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
  228. package/dist/tools/helpers/rule-matcher.js.map +0 -1
  229. package/dist/tools/helpers/rule-runner.d.ts.map +0 -1
  230. package/dist/tools/helpers/rule-runner.js.map +0 -1
  231. package/dist/tools/helpers/scan-plan.d.ts.map +0 -1
  232. package/dist/tools/helpers/scan-plan.js.map +0 -1
  233. package/dist/tools/helpers/stack-frame-file-index.d.ts.map +0 -1
  234. package/dist/tools/helpers/stack-frame-file-index.js.map +0 -1
  235. package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
  236. package/dist/tools/helpers/suggestion-generator.js.map +0 -1
  237. package/dist/tools/inspect-form-group.d.ts.map +0 -1
  238. package/dist/tools/inspect-form-group.js.map +0 -1
  239. package/dist/tools/inspect-i18n.d.ts.map +0 -1
  240. package/dist/tools/inspect-i18n.js.map +0 -1
  241. package/dist/tools/inspect-template.d.ts.map +0 -1
  242. package/dist/tools/inspect-template.js.map +0 -1
  243. package/dist/tools/learn-patterns.d.ts.map +0 -1
  244. package/dist/tools/learn-patterns.js.map +0 -1
  245. package/dist/tools/list-imports.d.ts.map +0 -1
  246. package/dist/tools/list-imports.js.map +0 -1
  247. package/dist/tools/orchestrate-migration.d.ts.map +0 -1
  248. package/dist/tools/orchestrate-migration.js.map +0 -1
  249. package/dist/tools/parse-stack-trace.d.ts.map +0 -1
  250. package/dist/tools/parse-stack-trace.js.map +0 -1
  251. package/dist/tools/plan-migration.d.ts.map +0 -1
  252. package/dist/tools/plan-migration.js.map +0 -1
  253. package/dist/tools/resolve-type.d.ts.map +0 -1
  254. package/dist/tools/resolve-type.js.map +0 -1
  255. package/dist/tools/review-feedback.d.ts.map +0 -1
  256. package/dist/tools/review-feedback.js.map +0 -1
  257. package/dist/tools/rollback-changes.d.ts.map +0 -1
  258. package/dist/tools/rollback-changes.js.map +0 -1
  259. package/dist/tools/run-angular-cli.d.ts.map +0 -1
  260. package/dist/tools/run-angular-cli.js.map +0 -1
  261. package/dist/tools/run-build.d.ts.map +0 -1
  262. package/dist/tools/run-build.js.map +0 -1
  263. package/dist/tools/run-schematic.d.ts.map +0 -1
  264. package/dist/tools/run-schematic.js.map +0 -1
  265. package/dist/tools/scan-all.d.ts.map +0 -1
  266. package/dist/tools/scan-all.js.map +0 -1
  267. package/dist/tools/scan-angular.d.ts.map +0 -1
  268. package/dist/tools/scan-angular.js.map +0 -1
  269. package/dist/tools/scan-architecture.d.ts.map +0 -1
  270. package/dist/tools/scan-architecture.js.map +0 -1
  271. package/dist/tools/scan-solid.d.ts.map +0 -1
  272. package/dist/tools/scan-solid.js.map +0 -1
  273. package/dist/tools/search-codebase.d.ts.map +0 -1
  274. package/dist/tools/search-codebase.js.map +0 -1
  275. package/dist/tools/server-status.d.ts.map +0 -1
  276. package/dist/tools/server-status.js.map +0 -1
  277. package/dist/tools/shared/scan-types.d.ts +0 -200
  278. package/dist/tools/shared/scan-types.d.ts.map +0 -1
  279. package/dist/tools/shared/scan-types.js +0 -7
  280. package/dist/tools/shared/scan-types.js.map +0 -1
  281. package/dist/tools/suggest-improvements.d.ts.map +0 -1
  282. package/dist/tools/suggest-improvements.js.map +0 -1
  283. package/dist/tools/trace-output-flow.d.ts.map +0 -1
  284. package/dist/tools/trace-output-flow.js.map +0 -1
  285. package/dist/tools/transform-code-batch.d.ts.map +0 -1
  286. package/dist/tools/transform-code-batch.js.map +0 -1
  287. package/dist/tools/transform-code.d.ts.map +0 -1
  288. package/dist/tools/transform-code.js.map +0 -1
  289. package/dist/tools/validate-before-transform.d.ts.map +0 -1
  290. package/dist/tools/validate-before-transform.js.map +0 -1
  291. package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
  292. package/dist/tools/validate-project-compatibility.js.map +0 -1
  293. package/dist/tools/validate-transformation.d.ts.map +0 -1
  294. package/dist/tools/validate-transformation.js.map +0 -1
  295. package/dist/types.d.ts.map +0 -1
  296. package/dist/types.js.map +0 -1
  297. package/dist/utils/format-tool-response.d.ts.map +0 -1
  298. package/dist/utils/format-tool-response.js.map +0 -1
@@ -1,44 +1,12 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Project Cache
3
- *
4
- * Keeps ts-morph `Project` instances alive across tool calls, keyed by the
5
- * tsconfig path, so repeated investigation calls on the same workspace do not
6
- * re-parse the whole program each time (seconds on a large Angular app).
7
- *
8
- * @remarks
9
- * Same idea as `SharedProjectManager` in core (one long-lived Project instead
10
- * of one per call), but keyed per tsconfig because the MCP server can serve
11
- * several workspaces in one session. An entry is rebuilt when the tsconfig
12
- * mtime changes. Source files are kept current file by file: the mtime of
13
- * every program file is recorded at load and compared on each `get()` (about
14
- * 6 ms for ngUWI's 3939 files); changed files are re-read, deleted ones
15
- * removed. The type checker then rebuilds lazily on the next query. Files
16
- * that were not in the program at load (new files) need a tsconfig touch or a
17
- * server restart.
18
- *
19
- * Two limits bound the cache: `maxEntries` projects, and `maxHeapMb` of V8
20
- * heap, checked on every `get()` because a project keeps growing after the
21
- * load as the type checker resolves more of it, and on a miss also before
22
- * the load. Over either limit the least recently used project is evicted;
23
- * the project being requested never is.
24
- * The heap is the signal, not the RSS: dropping a Project frees its heap
25
- * (the TypeScript program, checker and ts-morph wrappers hang off it and
26
- * nothing else keeps them), but V8 does not reliably unmap the pages, so the
27
- * RSS can stay at its peak after an eviction and an RSS limit would then
28
- * evict everything on every call. Freed pages are reused by the next load.
29
- * When node runs with `--expose-gc` the cache collects once the raw heap
30
- * reading passes the limit and after each eviction, so garbage does not count
31
- * against the cache; otherwise it subtracts the heap growth recorded when the
32
- * evicted project was loaded, and garbage makes it evict earlier.
33
- */
34
1
  import { statSync } from 'node:fs';
35
2
  import { Project } from 'ts-morph';
3
+ import { findUnresolvedLibraryImports, libraryImportWarning, } from './library-imports.js';
36
4
  /** Default number of workspaces kept in memory at once. */
37
5
  export const DEFAULT_MAX_ENTRIES = 3;
38
6
  /**
39
- * Default heap limit. ngUWI (3939 files) takes 1.0 to 1.3 GB of heap once
40
- * loaded and queried; V8's heap limit on the dev machines is about 4.1 GB.
41
- * 2048 MB keeps ngUWI together with small workspaces, and evicts it before a
7
+ * Default heap limit. A workspace of 3939 files takes 1.0 to 1.3 GB of heap
8
+ * once loaded and queried; V8's heap limit on the dev machines is about 4.1 GB.
9
+ * 2048 MB keeps such a workspace together with small ones, and evicts it before a
42
10
  * second workspace of its size drives the process towards the V8 limit.
43
11
  */
44
12
  export const DEFAULT_MAX_HEAP_MB = 2048;
@@ -61,7 +29,39 @@ const processMemory = {
61
29
  ? { collect: globalThis.gc.bind(globalThis) }
62
30
  : {}),
63
31
  };
64
- /** LRU cache of ts-morph Projects keyed by tsconfig path. */
32
+ /**
33
+ * LRU cache of ts-morph Projects keyed by tsconfig path. Keeps `Project`
34
+ * instances alive across tool calls, so repeated investigation calls on the
35
+ * same workspace do not re-parse the whole program each time (seconds on a
36
+ * large Angular app).
37
+ *
38
+ * @remarks
39
+ * Same idea as `SharedProjectManager` in core (one long-lived Project instead
40
+ * of one per call), but keyed per tsconfig because the MCP server can serve
41
+ * several workspaces in one session. An entry is rebuilt when the tsconfig
42
+ * mtime changes. Source files are kept current file by file: the mtime of
43
+ * every program file is recorded at load and compared on each `get()` (about
44
+ * 6 ms for 3939 files); changed files are re-read, deleted ones
45
+ * removed. The type checker then rebuilds lazily on the next query. Files
46
+ * that were not in the program at load (new files) need a tsconfig touch or a
47
+ * server restart.
48
+ *
49
+ * Two limits bound the cache: `maxEntries` projects, and `maxHeapMb` of V8
50
+ * heap, checked on every `get()` because a project keeps growing after the
51
+ * load as the type checker resolves more of it, and on a miss also before
52
+ * the load. Over either limit the least recently used project is evicted;
53
+ * the project being requested never is.
54
+ *
55
+ * The heap is the signal, not the RSS: dropping a Project frees its heap
56
+ * (the TypeScript program, checker and ts-morph wrappers hang off it and
57
+ * nothing else keeps them), but V8 does not reliably unmap the pages, so the
58
+ * RSS can stay at its peak after an eviction and an RSS limit would then
59
+ * evict everything on every call. Freed pages are reused by the next load.
60
+ * When node runs with `--expose-gc` the cache collects once the raw heap
61
+ * reading passes the limit and after each eviction, so garbage does not count
62
+ * against the cache; otherwise it subtracts the heap growth recorded when the
63
+ * evicted project was loaded, and garbage makes it evict earlier.
64
+ */
65
65
  export class ProjectCache {
66
66
  entries = new Map();
67
67
  maxEntries;
@@ -116,6 +116,23 @@ export class ProjectCache {
116
116
  ? { count: this.evictionCount }
117
117
  : { count: this.evictionCount, last: this.lastEviction };
118
118
  }
119
+ /**
120
+ * Warnings about the loaded project for `tsConfigPath`: today the library
121
+ * imports that do not resolve (missing or incomplete node_modules). Checked
122
+ * once per load, on the first call, and kept until the project is reloaded;
123
+ * empty when the project is not cached.
124
+ */
125
+ warnings(tsConfigPath) {
126
+ const entry = this.entries.get(tsConfigPath);
127
+ if (entry === undefined) {
128
+ return [];
129
+ }
130
+ if (entry.warnings === undefined) {
131
+ const warning = libraryImportWarning(findUnresolvedLibraryImports(entry.project, tsConfigPath));
132
+ entry.warnings = warning === undefined ? [] : [warning];
133
+ }
134
+ return [...entry.warnings];
135
+ }
119
136
  /** Cached projects, least recently used first. */
120
137
  describe() {
121
138
  return [...this.entries].map(([tsConfigPath, entry]) => ({
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Project component decorators for the investigation tools.
3
+ *
4
+ * Reads `parser.componentDecorators` from `.angular-modernizer.json` in the
5
+ * project root. The list adds to `Component`; the api classes treat a missing
6
+ * and an empty list the same (Component only).
7
+ */
8
+ /**
9
+ * `parser.componentDecorators` of the project, or `undefined` when the project
10
+ * has no config file or the config does not load. A broken config must not
11
+ * break investigation; the tools then fall back to `Component` only.
12
+ */
13
+ export declare function configuredComponentDecorators(projectRoot: string): readonly string[] | undefined;
14
+ //# sourceMappingURL=project-decorators.d.ts.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Project component decorators for the investigation tools.
3
+ *
4
+ * Reads `parser.componentDecorators` from `.angular-modernizer.json` in the
5
+ * project root. The list adds to `Component`; the api classes treat a missing
6
+ * and an empty list the same (Component only).
7
+ */
8
+ import { loadConfig } from '@angular-modernizer/core';
9
+ /**
10
+ * `parser.componentDecorators` of the project, or `undefined` when the project
11
+ * has no config file or the config does not load. A broken config must not
12
+ * break investigation; the tools then fall back to `Component` only.
13
+ */
14
+ export function configuredComponentDecorators(projectRoot) {
15
+ try {
16
+ return loadConfig(projectRoot).parser?.componentDecorators;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ //# sourceMappingURL=project-decorators.js.map
@@ -199,6 +199,11 @@ export function getAvailableRules(inputSchema) {
199
199
  name: 'Subscription Transform',
200
200
  description: 'Add takeUntilDestroyed() to raw .subscribe() calls in lifecycle hooks',
201
201
  },
202
+ 'service-bag-transform': {
203
+ id: 'refactor:service-bag-split',
204
+ name: 'Service Bag Split',
205
+ description: 'Split a service bag into focused services by concern and backend area',
206
+ },
202
207
  };
203
208
  return transformationEnum.map((transformationType) => {
204
209
  const mapping = ruleMapping[transformationType];
@@ -1,15 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Rule runner for scan tools
3
- *
4
- * Runs analysis rules over a file list with a time budget:
5
- * - all files are added to the project first, so project-wide rules
6
- * (library extraction, circular dependencies, type resolution) see the same,
7
- * complete project for every file instead of a prefix that grows per file
8
- * - the budget is checked between files; a rule that is running cannot be
9
- * interrupted (analysis is synchronous CPU work), so the overrun is at most
10
- * one file
11
- * - time per rule is recorded so slow rules show up in the result
12
- */
13
1
  import type { Project } from 'ts-morph';
14
2
  import { type AnalysisRule } from '@angular-modernizer/plugin-system';
15
3
  /** Default scan time budget: 5 minutes. */
@@ -26,8 +14,11 @@ export interface RuleRunnerViolation {
26
14
  suggestedFix?: string;
27
15
  metadata?: Record<string, unknown>;
28
16
  }
17
+ /** Total analysis time of one rule over all files of a scan. */
29
18
  export interface RuleTiming {
19
+ /** Rule id. */
30
20
  ruleId: string;
21
+ /** Time spent in the rule in milliseconds, summed over all files. */
31
22
  ms: number;
32
23
  }
33
24
  export interface RuleRunResult {
@@ -52,16 +43,37 @@ export interface RuleRunOptions {
52
43
  maxDurationMs?: number;
53
44
  /** Start of the budget (defaults to now), e.g. the tool's start time. */
54
45
  startTime?: number;
46
+ /** Aborts the run between files (MCP `notifications/cancelled`). */
47
+ signal?: AbortSignal;
55
48
  isCancelled?: () => boolean;
56
49
  onFileAnalyzed?: (analyzed: number, total: number, violations: number) => void;
50
+ /** Findings of each analyzed file, in analysis order. */
51
+ onFileResults?: (filePath: string, violations: RuleRunnerViolation[]) => void;
52
+ /** Keep the findings in `violations` (default); `false` leaves it empty. */
53
+ collect?: boolean;
57
54
  }
58
55
  /**
59
56
  * Parse the `maxDurationMs` tool parameter.
60
57
  */
61
58
  export declare function parseMaxDurationMs(value: unknown): number;
59
+ /**
60
+ * Runs analysis rules over a file list with a time budget.
61
+ *
62
+ * @remarks
63
+ * - All files are added to the project first, so project-wide rules
64
+ * (library extraction, circular dependencies, type resolution) see the same,
65
+ * complete project for every file instead of a prefix that grows per file;
66
+ * the load yields and checks the signal per file as well.
67
+ * - The budget and the abort signal are checked between files; a rule that
68
+ * is running cannot be interrupted (analysis is synchronous CPU work), so
69
+ * the overrun is at most one file. With a signal the loop yields to the
70
+ * event loop once per file, otherwise `notifications/cancelled` is not read
71
+ * before the scan ends.
72
+ * - Time per rule is recorded so slow rules show up in the result.
73
+ */
62
74
  export declare function runRulesOverFiles(options: RuleRunOptions): Promise<RuleRunResult>;
63
75
  /**
64
76
  * Human-readable note for an incomplete run.
65
77
  */
66
- export declare function incompleteNote(result: RuleRunResult, budgetMs: number): string | undefined;
78
+ export declare function incompleteNote(result: Omit<RuleRunResult, 'violations'>, budgetMs: number): string | undefined;
67
79
  //# sourceMappingURL=rule-runner.d.ts.map
@@ -1,16 +1,6 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Rule runner for scan tools
3
- *
4
- * Runs analysis rules over a file list with a time budget:
5
- * - all files are added to the project first, so project-wide rules
6
- * (library extraction, circular dependencies, type resolution) see the same,
7
- * complete project for every file instead of a prefix that grows per file
8
- * - the budget is checked between files; a rule that is running cannot be
9
- * interrupted (analysis is synchronous CPU work), so the overrun is at most
10
- * one file
11
- * - time per rule is recorded so slow rules show up in the result
12
- */
13
1
  import { ContextFactory, } from '@angular-modernizer/plugin-system';
2
+ import { yieldIfCancellable } from './tool-context.js';
3
+ import { loadSourceFiles } from './load-source-files.js';
14
4
  /** Default scan time budget: 5 minutes. */
15
5
  export const DEFAULT_MAX_DURATION_MS = 300_000;
16
6
  /**
@@ -25,26 +15,51 @@ export function parseMaxDurationMs(value) {
25
15
  }
26
16
  return value;
27
17
  }
18
+ /**
19
+ * Runs analysis rules over a file list with a time budget.
20
+ *
21
+ * @remarks
22
+ * - All files are added to the project first, so project-wide rules
23
+ * (library extraction, circular dependencies, type resolution) see the same,
24
+ * complete project for every file instead of a prefix that grows per file;
25
+ * the load yields and checks the signal per file as well.
26
+ * - The budget and the abort signal are checked between files; a rule that
27
+ * is running cannot be interrupted (analysis is synchronous CPU work), so
28
+ * the overrun is at most one file. With a signal the loop yields to the
29
+ * event loop once per file, otherwise `notifications/cancelled` is not read
30
+ * before the scan ends.
31
+ * - Time per rule is recorded so slow rules show up in the result.
32
+ */
28
33
  export async function runRulesOverFiles(options) {
29
34
  const startTime = options.startTime ?? Date.now();
30
35
  const budget = options.maxDurationMs ?? DEFAULT_MAX_DURATION_MS;
31
36
  const deadline = budget > 0 ? startTime + budget : Number.POSITIVE_INFINITY;
32
37
  const { project, rules } = options;
33
- const sourceFiles = [];
34
- for (const filePath of options.files) {
35
- try {
36
- sourceFiles.push(project.getSourceFile(filePath) ?? project.addSourceFileAtPath(filePath));
37
- }
38
- catch (error) {
39
- console.warn(`Error loading ${filePath}:`, error);
40
- }
38
+ const loaded = await loadSourceFiles(project, options.files, {
39
+ signal: options.signal,
40
+ isCancelled: options.isCancelled,
41
+ reuseExisting: true,
42
+ });
43
+ if (loaded.cancelled) {
44
+ return {
45
+ violations: [],
46
+ filesAnalyzed: 0,
47
+ incomplete: true,
48
+ stopReason: 'cancelled',
49
+ skippedFiles: options.files.length,
50
+ ruleTimings: [],
51
+ durationMs: Date.now() - startTime,
52
+ };
41
53
  }
54
+ const sourceFiles = loaded.sourceFiles;
42
55
  const violations = [];
43
56
  const timings = new Map();
44
57
  let filesAnalyzed = 0;
58
+ let violationCount = 0;
45
59
  let stopReason;
46
60
  for (const sourceFile of sourceFiles) {
47
- if (options.isCancelled?.()) {
61
+ await yieldIfCancellable(options.signal);
62
+ if (options.signal?.aborted === true || options.isCancelled?.() === true) {
48
63
  stopReason = 'cancelled';
49
64
  break;
50
65
  }
@@ -52,6 +67,7 @@ export async function runRulesOverFiles(options) {
52
67
  stopReason = 'time-budget';
53
68
  break;
54
69
  }
70
+ const fileViolations = [];
55
71
  try {
56
72
  for (const rule of rules) {
57
73
  const ruleStart = Date.now();
@@ -63,15 +79,20 @@ export async function runRulesOverFiles(options) {
63
79
  }));
64
80
  timings.set(rule.id, (timings.get(rule.id) ?? 0) + Date.now() - ruleStart);
65
81
  for (const result of results) {
66
- violations.push(toViolation(rule, result));
82
+ fileViolations.push(toViolation(rule, result));
67
83
  }
68
84
  }
69
85
  }
70
86
  catch (error) {
71
87
  console.warn(`Error analyzing ${sourceFile.getFilePath()}:`, error);
72
88
  }
89
+ if (options.collect !== false) {
90
+ violations.push(...fileViolations);
91
+ }
92
+ violationCount += fileViolations.length;
73
93
  filesAnalyzed++;
74
- options.onFileAnalyzed?.(filesAnalyzed, sourceFiles.length, violations.length);
94
+ options.onFileResults?.(sourceFile.getFilePath(), fileViolations);
95
+ options.onFileAnalyzed?.(filesAnalyzed, sourceFiles.length, violationCount);
75
96
  }
76
97
  return {
77
98
  violations,
@@ -87,7 +108,7 @@ function toViolation(rule, result) {
87
108
  return {
88
109
  id: `${result.ruleId}-${result.filePath}-${result.line ?? 0}-${result.column ?? 0}`,
89
110
  ruleId: result.ruleId,
90
- severity: rule.severity,
111
+ severity: result.severity ?? rule.severity,
91
112
  message: result.message,
92
113
  filePath: result.filePath,
93
114
  line: result.line,
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - scan-all cache entries
3
+ *
4
+ * scan-all caches the findings of each analyzed `.ts` file under that file,
5
+ * including findings reported on its template (`.html`) and files without any
6
+ * finding. Template files are stored as dependencies so an edit to the
7
+ * template alone invalidates the entry.
8
+ */
9
+ /**
10
+ * Template files a cache entry depends on: `templateUrl` targets in the
11
+ * source text and every other file a finding of this source points at.
12
+ *
13
+ * @param exists - filters out paths that do not exist; the cache treats a
14
+ * missing dependency as invalidation, so it would never hit.
15
+ */
16
+ export declare function templateDependencies(sourcePath: string, sourceText: string, findingPaths: readonly string[], exists: (path: string) => boolean): string[];
17
+ /**
18
+ * Whether a cache entry is still current for its dependencies: none of them
19
+ * was modified after the entry was written.
20
+ */
21
+ export declare function dependenciesUnchanged(dependencies: readonly string[], cachedAt: number, modifiedAt: (path: string) => number | undefined): boolean;
22
+ //# sourceMappingURL=scan-cache.d.ts.map
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - scan-all cache entries
3
+ *
4
+ * scan-all caches the findings of each analyzed `.ts` file under that file,
5
+ * including findings reported on its template (`.html`) and files without any
6
+ * finding. Template files are stored as dependencies so an edit to the
7
+ * template alone invalidates the entry.
8
+ */
9
+ import { dirname, resolve } from 'node:path';
10
+ const TEMPLATE_URL = /templateUrl\s*:\s*['"`]([^'"`]+)['"`]/g;
11
+ /**
12
+ * Template files a cache entry depends on: `templateUrl` targets in the
13
+ * source text and every other file a finding of this source points at.
14
+ *
15
+ * @param exists - filters out paths that do not exist; the cache treats a
16
+ * missing dependency as invalidation, so it would never hit.
17
+ */
18
+ export function templateDependencies(sourcePath, sourceText, findingPaths, exists) {
19
+ const fromTemplateUrl = [...sourceText.matchAll(TEMPLATE_URL)].map((m) => resolve(dirname(sourcePath), m[1] ?? ''));
20
+ const candidates = new Set([...fromTemplateUrl, ...findingPaths]);
21
+ candidates.delete(sourcePath);
22
+ return [...candidates].filter(exists).sort();
23
+ }
24
+ /**
25
+ * Whether a cache entry is still current for its dependencies: none of them
26
+ * was modified after the entry was written.
27
+ */
28
+ export function dependenciesUnchanged(dependencies, cachedAt, modifiedAt) {
29
+ return dependencies.every((dep) => {
30
+ const mtime = modifiedAt(dep);
31
+ return mtime !== undefined && mtime <= cachedAt;
32
+ });
33
+ }
34
+ //# sourceMappingURL=scan-cache.js.map
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Analysis part of the scan tools
3
+ *
4
+ * The part of a scan between "build the kernel" and "all files analyzed":
5
+ * kernel, project, rules, file loading and rule runs. It runs in a scan worker
6
+ * (`scan-host/`) or, as fallback and under Jest, in the calling thread; both
7
+ * paths run this function, so they produce the same findings in the same
8
+ * order. Glob, scan cache, result window, progress and the MCP protocol stay
9
+ * with the tool on the main thread.
10
+ *
11
+ * The engine does not write to disk (the kernel gets no cache config), so a
12
+ * worker killed in the middle leaves nothing half written.
13
+ */
14
+ import { type RuleRunResult, type RuleRunnerViolation } from './rule-runner.js';
15
+ /** Plugins a scan runs. */
16
+ export type ScanPluginSet = 'all' | 'solid' | 'angular' | 'architecture' | 'analyzer';
17
+ /**
18
+ * What to analyze and how. Plain data: it is the `workerData` of a scan
19
+ * worker.
20
+ */
21
+ export interface ScanSpec {
22
+ /** Tool name, for logs and server-status. */
23
+ tool: string;
24
+ plugins: ScanPluginSet;
25
+ tsConfigPath: string;
26
+ /** Root whose `.angular-modernizer.json` supplies the rule configuration. */
27
+ rootPath: string;
28
+ /** Files to analyze, absolute, in analysis order. */
29
+ files: string[];
30
+ /**
31
+ * - `batches`: per batch remove all files, add the batch, analyze it
32
+ * (scan-all, scan-solid, scan-angular).
33
+ * - `runner`: add all files, then run the rules with the time budget
34
+ * (scan-architecture).
35
+ * - `sequential`: project from the tsconfig, files added one by one
36
+ * (analyze-project).
37
+ */
38
+ mode: 'batches' | 'runner' | 'sequential';
39
+ /** Batch size of `batches`. */
40
+ batchSize?: number;
41
+ /**
42
+ * `batches`: analyze every file the project holds after the load
43
+ * (scan-solid, scan-angular) instead of the loaded ones (scan-all).
44
+ */
45
+ analyzeProjectFiles?: boolean;
46
+ /** Record the template dependencies of each analyzed file (scan-all cache). */
47
+ templateDependencies?: boolean;
48
+ /** `runner`: run only these rules; none left is an error. */
49
+ ruleIds?: string[];
50
+ /** `runner`: time budget in ms, `0` disables it. */
51
+ maxDurationMs?: number;
52
+ /** `runner`: start of the budget (epoch ms). */
53
+ startTime?: number;
54
+ }
55
+ /** A finding as the scans collect it. */
56
+ export interface ScanFinding {
57
+ /** Set by the `runner` mode only. */
58
+ id?: string;
59
+ ruleId: string;
60
+ severity: RuleRunnerViolation['severity'];
61
+ message: string;
62
+ filePath: string;
63
+ line?: number;
64
+ column?: number;
65
+ category: string;
66
+ suggestedFix?: string;
67
+ metadata?: Record<string, unknown>;
68
+ }
69
+ /** Findings of one analyzed file. */
70
+ export interface ScanFileEvent {
71
+ /** The analyzed file. */
72
+ filePath: string;
73
+ /** Its findings, in rule order; they may point at other files (templates). */
74
+ findings: ScanFinding[];
75
+ /** Template dependencies, only with {@link ScanSpec.templateDependencies}. */
76
+ dependencies?: string[];
77
+ }
78
+ /** Receives the engine's output as it is produced. */
79
+ export interface ScanSink {
80
+ /** Rules are known (after `kernel.initialize()`). */
81
+ ready?(ruleIds: string[]): void;
82
+ /** One file is analyzed. */
83
+ file(event: ScanFileEvent): void;
84
+ /** `batches`: a batch of `files` files is done, failed loads included. */
85
+ batchDone?(files: number): void;
86
+ }
87
+ /** How the `runner` mode ended: the rule runner result without findings. */
88
+ export type ScanRunSummary = Omit<RuleRunResult, 'violations'>;
89
+ /** End of a scan run. */
90
+ export interface ScanEngineResult {
91
+ /** `true` when a cancel stopped the run. */
92
+ cancelled: boolean;
93
+ /** Ids of the rules that ran; empty when the run stopped before they were known. */
94
+ ruleIds: string[];
95
+ /** `runner` mode only. */
96
+ run?: ScanRunSummary;
97
+ }
98
+ /** Cancellation of an in-thread run; a worker is terminated instead. */
99
+ export interface ScanControl {
100
+ /** Yields once per file and stops when aborted. */
101
+ signal?: AbortSignal;
102
+ }
103
+ /**
104
+ * Runs the analysis part of a scan and reports each analyzed file to `sink`.
105
+ */
106
+ export declare function runScanEngine(spec: ScanSpec, sink: ScanSink, control?: ScanControl): Promise<ScanEngineResult>;
107
+ //# sourceMappingURL=scan-engine.d.ts.map