@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
@@ -11,7 +11,7 @@
11
11
  * several workspaces in one session. An entry is rebuilt when the tsconfig
12
12
  * mtime changes. Source files are kept current file by file: the mtime of
13
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
14
+ * 6 ms for 3939 files); changed files are re-read, deleted ones
15
15
  * removed. The type checker then rebuilds lazily on the next query. Files
16
16
  * that were not in the program at load (new files) need a tsconfig touch or a
17
17
  * server restart.
@@ -33,12 +33,13 @@
33
33
  */
34
34
  import { statSync } from 'node:fs';
35
35
  import { Project } from 'ts-morph';
36
+ import { findUnresolvedLibraryImports, libraryImportWarning, } from './library-imports.js';
36
37
  /** Default number of workspaces kept in memory at once. */
37
38
  export const DEFAULT_MAX_ENTRIES = 3;
38
39
  /**
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
40
+ * Default heap limit. A workspace of 3939 files takes 1.0 to 1.3 GB of heap
41
+ * once loaded and queried; V8's heap limit on the dev machines is about 4.1 GB.
42
+ * 2048 MB keeps such a workspace together with small ones, and evicts it before a
42
43
  * second workspace of its size drives the process towards the V8 limit.
43
44
  */
44
45
  export const DEFAULT_MAX_HEAP_MB = 2048;
@@ -116,6 +117,23 @@ export class ProjectCache {
116
117
  ? { count: this.evictionCount }
117
118
  : { count: this.evictionCount, last: this.lastEviction };
118
119
  }
120
+ /**
121
+ * Warnings about the loaded project for `tsConfigPath`: today the library
122
+ * imports that do not resolve (missing or incomplete node_modules). Checked
123
+ * once per load, on the first call, and kept until the project is reloaded;
124
+ * empty when the project is not cached.
125
+ */
126
+ warnings(tsConfigPath) {
127
+ const entry = this.entries.get(tsConfigPath);
128
+ if (entry === undefined) {
129
+ return [];
130
+ }
131
+ if (entry.warnings === undefined) {
132
+ const warning = libraryImportWarning(findUnresolvedLibraryImports(entry.project, tsConfigPath));
133
+ entry.warnings = warning === undefined ? [] : [warning];
134
+ }
135
+ return [...entry.warnings];
136
+ }
119
137
  /** Cached projects, least recently used first. */
120
138
  describe() {
121
139
  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];
@@ -4,10 +4,13 @@
4
4
  * Runs analysis rules over a file list with a time budget:
5
5
  * - all files are added to the project first, so project-wide rules
6
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
7
+ * complete project for every file instead of a prefix that grows per file;
8
+ * the load yields and checks the signal per file as well
9
+ * - the budget and the abort signal are checked between files; a rule that
10
+ * is running cannot be interrupted (analysis is synchronous CPU work), so
11
+ * the overrun is at most one file. With a signal the loop yields to the
12
+ * event loop once per file, otherwise `notifications/cancelled` is not read
13
+ * before the scan ends
11
14
  * - time per rule is recorded so slow rules show up in the result
12
15
  */
13
16
  import type { Project } from 'ts-morph';
@@ -52,6 +55,8 @@ export interface RuleRunOptions {
52
55
  maxDurationMs?: number;
53
56
  /** Start of the budget (defaults to now), e.g. the tool's start time. */
54
57
  startTime?: number;
58
+ /** Aborts the run between files (MCP `notifications/cancelled`). */
59
+ signal?: AbortSignal;
55
60
  isCancelled?: () => boolean;
56
61
  onFileAnalyzed?: (analyzed: number, total: number, violations: number) => void;
57
62
  }
@@ -4,13 +4,18 @@
4
4
  * Runs analysis rules over a file list with a time budget:
5
5
  * - all files are added to the project first, so project-wide rules
6
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
7
+ * complete project for every file instead of a prefix that grows per file;
8
+ * the load yields and checks the signal per file as well
9
+ * - the budget and the abort signal are checked between files; a rule that
10
+ * is running cannot be interrupted (analysis is synchronous CPU work), so
11
+ * the overrun is at most one file. With a signal the loop yields to the
12
+ * event loop once per file, otherwise `notifications/cancelled` is not read
13
+ * before the scan ends
11
14
  * - time per rule is recorded so slow rules show up in the result
12
15
  */
13
16
  import { ContextFactory, } from '@angular-modernizer/plugin-system';
17
+ import { yieldIfCancellable } from './tool-context.js';
18
+ import { loadSourceFiles } from './load-source-files.js';
14
19
  /** Default scan time budget: 5 minutes. */
15
20
  export const DEFAULT_MAX_DURATION_MS = 300_000;
16
21
  /**
@@ -30,21 +35,30 @@ export async function runRulesOverFiles(options) {
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;
45
58
  let stopReason;
46
59
  for (const sourceFile of sourceFiles) {
47
- if (options.isCancelled?.()) {
60
+ await yieldIfCancellable(options.signal);
61
+ if (options.signal?.aborted === true || options.isCancelled?.() === true) {
48
62
  stopReason = 'cancelled';
49
63
  break;
50
64
  }
@@ -87,7 +101,7 @@ function toViolation(rule, result) {
87
101
  return {
88
102
  id: `${result.ruleId}-${result.filePath}-${result.line ?? 0}-${result.column ?? 0}`,
89
103
  ruleId: result.ruleId,
90
- severity: rule.severity,
104
+ severity: result.severity ?? rule.severity,
91
105
  message: result.message,
92
106
  filePath: result.filePath,
93
107
  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
@@ -28,8 +28,11 @@ export interface ScanPlanResult {
28
28
  }
29
29
  /**
30
30
  * Read violations from a saved scan-architecture result. Accepts the tool
31
- * result object (`{ violations: [...] }`), a bare violation array, or an MCP
32
- * content array (`[{ type: 'text', text: '<json>' }]`) as clients persist it.
31
+ * result object (`{ violations: [...] }`), the MCP tool result with
32
+ * `structuredContent`, a bare violation array, or an MCP content array
33
+ * (`[{ type: 'text', text: '<json>' }]`) as clients persist it. A content
34
+ * array whose text is no JSON (the text summary of a structured result) is
35
+ * rejected like any other file without violations.
33
36
  */
34
37
  export declare function readScanResultFile(filePath: string): ScanViolationInput[];
35
38
  /**
@@ -18,8 +18,11 @@ function isRecord(value) {
18
18
  }
19
19
  /**
20
20
  * Read violations from a saved scan-architecture result. Accepts the tool
21
- * result object (`{ violations: [...] }`), a bare violation array, or an MCP
22
- * content array (`[{ type: 'text', text: '<json>' }]`) as clients persist it.
21
+ * result object (`{ violations: [...] }`), the MCP tool result with
22
+ * `structuredContent`, a bare violation array, or an MCP content array
23
+ * (`[{ type: 'text', text: '<json>' }]`) as clients persist it. A content
24
+ * array whose text is no JSON (the text summary of a structured result) is
25
+ * rejected like any other file without violations.
23
26
  */
24
27
  export function readScanResultFile(filePath) {
25
28
  if (!existsSync(filePath)) {
@@ -42,15 +45,27 @@ function extractViolations(value) {
42
45
  if (Array.isArray(value)) {
43
46
  const first = value[0];
44
47
  if (isRecord(first) && first['type'] === 'text' && typeof first['text'] === 'string') {
45
- return extractViolations(JSON.parse(first['text']));
48
+ return extractViolations(parseJson(first['text']));
46
49
  }
47
50
  return value.filter(isScanViolation);
48
51
  }
49
52
  if (isRecord(value) && Array.isArray(value['violations'])) {
50
53
  return value['violations'].filter(isScanViolation);
51
54
  }
55
+ if (isRecord(value) && isRecord(value['structuredContent'])) {
56
+ return extractViolations(value['structuredContent']);
57
+ }
52
58
  return undefined;
53
59
  }
60
+ /** Parsed JSON, or `undefined` for text that is no JSON. */
61
+ function parseJson(text) {
62
+ try {
63
+ return JSON.parse(text);
64
+ }
65
+ catch {
66
+ return undefined;
67
+ }
68
+ }
54
69
  function isScanViolation(value) {
55
70
  return (isRecord(value) &&
56
71
  typeof value['ruleId'] === 'string' &&
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Scope path matching
3
+ *
4
+ * A file belongs to a scope path when it is that path or lies below it. A
5
+ * bare `startsWith` also matched sibling folders sharing the prefix
6
+ * (`features/orders` took in `features/orders-shared`).
7
+ */
8
+ /**
9
+ * Whether `file` is `scopePath` itself or lies inside the folder
10
+ * `scopePath`. Both are compared with `/` separators.
11
+ */
12
+ export declare function isInScopePath(file: string, scopePath: string): boolean;
13
+ /**
14
+ * The files inside at least one of `scopePaths`.
15
+ */
16
+ export declare function filterFilesByScopePaths(files: readonly string[], scopePaths: readonly string[]): string[];
17
+ //# sourceMappingURL=scope-paths.d.ts.map
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Scope path matching
3
+ *
4
+ * A file belongs to a scope path when it is that path or lies below it. A
5
+ * bare `startsWith` also matched sibling folders sharing the prefix
6
+ * (`features/orders` took in `features/orders-shared`).
7
+ */
8
+ /** `/` separators and no trailing separator. */
9
+ function normalizePath(path) {
10
+ const slashes = path.replaceAll('\\', '/');
11
+ return slashes.length > 1 ? slashes.replace(/\/+$/, '') : slashes;
12
+ }
13
+ /**
14
+ * Whether `file` is `scopePath` itself or lies inside the folder
15
+ * `scopePath`. Both are compared with `/` separators.
16
+ */
17
+ export function isInScopePath(file, scopePath) {
18
+ const normalizedFile = normalizePath(file);
19
+ const normalizedScope = normalizePath(scopePath);
20
+ if (normalizedFile === normalizedScope) {
21
+ return true;
22
+ }
23
+ const folder = normalizedScope.endsWith('/') ? normalizedScope : `${normalizedScope}/`;
24
+ return normalizedFile.startsWith(folder);
25
+ }
26
+ /**
27
+ * The files inside at least one of `scopePaths`.
28
+ */
29
+ export function filterFilesByScopePaths(files, scopePaths) {
30
+ return files.filter((file) => scopePaths.some((scopePath) => isInScopePath(file, scopePath)));
31
+ }
32
+ //# sourceMappingURL=scope-paths.js.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Helpers for the per-call tool context
3
+ *
4
+ * Analysis is synchronous CPU work: while a loop runs, the server does not
5
+ * read stdin, so `notifications/cancelled` only arrives once the loop gives
6
+ * the event loop a turn. Long loops therefore yield once per file when the
7
+ * call can be cancelled ({@link yieldIfCancellable}).
8
+ */
9
+ import { type ProgressFn } from '../../types.js';
10
+ /** Minimum gap between two progress notifications. */
11
+ export declare const PROGRESS_INTERVAL_MS = 250;
12
+ /**
13
+ * Wraps `send` so it fires for the first value, for the last value
14
+ * (`progress >= total`) and otherwise at most once per `intervalMs`.
15
+ */
16
+ export declare function throttleProgress(send: ProgressFn, intervalMs?: number, now?: () => number): ProgressFn;
17
+ /**
18
+ * Gives the event loop one turn when the call can be cancelled, so a pending
19
+ * `notifications/cancelled` is read and `signal` aborts. Without a signal
20
+ * (direct calls, tests) it returns at once.
21
+ */
22
+ export declare function yieldIfCancellable(signal: AbortSignal | undefined): Promise<void>;
23
+ /** Progress message of a file loop: `12/40 files, 3 violations`. */
24
+ export declare function fileProgressMessage(analyzed: number, total: number, violations: number): string;
25
+ /**
26
+ * `onFileAnalyzed` callback of a file loop that reports to `progress`;
27
+ * `undefined` without progress, so the loop does no extra work.
28
+ */
29
+ export declare function fileProgress(progress: ProgressFn | undefined): ((analyzed: number, total: number, violations: number) => void) | undefined;
30
+ /** Execution details of a scan the client cancelled. */
31
+ export interface CancelledExecution {
32
+ maxDurationMs?: number;
33
+ incomplete: true;
34
+ stopReason: 'cancelled';
35
+ skippedFiles: number;
36
+ ruleTimings: [];
37
+ note: string;
38
+ }
39
+ /**
40
+ * Execution details of a scan the client cancelled after `analyzed` files.
41
+ * The SDK does not send the result of a cancelled request; it still has to
42
+ * be complete for direct callers (compare-health, tests).
43
+ */
44
+ export declare function cancelledExecution(analyzed: number, skippedFiles: number, maxDurationMs?: number): CancelledExecution;
45
+ /** The part of the kernel's `ProgressReporter` the forwarding needs. */
46
+ interface KernelProgressSource {
47
+ on(event: 'progress', listener: (event: {
48
+ current: number;
49
+ total: number;
50
+ message?: string;
51
+ }) => void): unknown;
52
+ }
53
+ /**
54
+ * Forwards the kernel's progress events (parallel and incremental analysis)
55
+ * to `progress`. The reporter belongs to the call's own kernel, so the
56
+ * listener goes away with it.
57
+ */
58
+ export declare function forwardKernelProgress(reporter: KernelProgressSource | undefined, progress: ProgressFn): void;
59
+ export {};
60
+ //# sourceMappingURL=tool-context.d.ts.map
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Helpers for the per-call tool context
3
+ *
4
+ * Analysis is synchronous CPU work: while a loop runs, the server does not
5
+ * read stdin, so `notifications/cancelled` only arrives once the loop gives
6
+ * the event loop a turn. Long loops therefore yield once per file when the
7
+ * call can be cancelled ({@link yieldIfCancellable}).
8
+ */
9
+ /** Minimum gap between two progress notifications. */
10
+ export const PROGRESS_INTERVAL_MS = 250;
11
+ /**
12
+ * Wraps `send` so it fires for the first value, for the last value
13
+ * (`progress >= total`) and otherwise at most once per `intervalMs`.
14
+ */
15
+ export function throttleProgress(send, intervalMs = PROGRESS_INTERVAL_MS, now = Date.now) {
16
+ let last;
17
+ return (progress, total, message) => {
18
+ const time = now();
19
+ const isLast = total !== undefined && progress >= total;
20
+ if (last !== undefined && !isLast && time - last < intervalMs) {
21
+ return;
22
+ }
23
+ last = time;
24
+ send(progress, total, message);
25
+ };
26
+ }
27
+ /**
28
+ * Gives the event loop one turn when the call can be cancelled, so a pending
29
+ * `notifications/cancelled` is read and `signal` aborts. Without a signal
30
+ * (direct calls, tests) it returns at once.
31
+ */
32
+ export async function yieldIfCancellable(signal) {
33
+ if (signal === undefined) {
34
+ return;
35
+ }
36
+ await new Promise((resolve) => setImmediate(resolve));
37
+ }
38
+ /** Progress message of a file loop: `12/40 files, 3 violations`. */
39
+ export function fileProgressMessage(analyzed, total, violations) {
40
+ return `${analyzed}/${total} files, ${violations} violation${violations === 1 ? '' : 's'}`;
41
+ }
42
+ /**
43
+ * `onFileAnalyzed` callback of a file loop that reports to `progress`;
44
+ * `undefined` without progress, so the loop does no extra work.
45
+ */
46
+ export function fileProgress(progress) {
47
+ if (progress === undefined) {
48
+ return undefined;
49
+ }
50
+ return (analyzed, total, violations) => {
51
+ progress(analyzed, total, fileProgressMessage(analyzed, total, violations));
52
+ };
53
+ }
54
+ /**
55
+ * Execution details of a scan the client cancelled after `analyzed` files.
56
+ * The SDK does not send the result of a cancelled request; it still has to
57
+ * be complete for direct callers (compare-health, tests).
58
+ */
59
+ export function cancelledExecution(analyzed, skippedFiles, maxDurationMs) {
60
+ return {
61
+ ...(maxDurationMs === undefined ? {} : { maxDurationMs }),
62
+ incomplete: true,
63
+ stopReason: 'cancelled',
64
+ skippedFiles,
65
+ ruleTimings: [],
66
+ note: `Scan cancelled after ${analyzed} file(s); ${skippedFiles} file(s) not analyzed.`,
67
+ };
68
+ }
69
+ /**
70
+ * Forwards the kernel's progress events (parallel and incremental analysis)
71
+ * to `progress`. The reporter belongs to the call's own kernel, so the
72
+ * listener goes away with it.
73
+ */
74
+ export function forwardKernelProgress(reporter, progress) {
75
+ if (reporter === undefined) {
76
+ return;
77
+ }
78
+ reporter.on('progress', (event) => {
79
+ progress(event.current, event.total, `${event.current}/${event.total} files`);
80
+ });
81
+ }
82
+ //# sourceMappingURL=tool-context.js.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Safety envelope shared by transform-code and rollback-changes: backups in
3
+ * the project (not in the server's working directory), one RollbackManager
4
+ * configuration for both tools, and the type check of a transformed file.
5
+ */
6
+ import { type SourceFile } from 'ts-morph';
7
+ import { RollbackManager, RollbackStrategy } from '@angular-modernizer/core';
8
+ /**
9
+ * Backup directory name inside the project root.
10
+ */
11
+ export declare const BACKUP_DIR_NAME = ".angular-modernizer-backups";
12
+ /**
13
+ * Backup directory of a project: the explicit one, else inside the project.
14
+ */
15
+ export declare function projectBackupDir(projectRoot: string, backupDir?: string): string;
16
+ /**
17
+ * RollbackManager writing to and reading from the project's backup
18
+ * directory; git snapshots run in the project root.
19
+ */
20
+ export declare function createProjectRollbackManager(projectRoot: string, options?: {
21
+ backupDir?: string;
22
+ strategy?: RollbackStrategy;
23
+ }): RollbackManager;
24
+ /**
25
+ * Nearest directory above a file that holds a tsconfig.json, package.json or
26
+ * .angular-modernizer.json; undefined when none exists up to the file system
27
+ * root.
28
+ */
29
+ export declare function findProjectRootOf(filePath: string): string | undefined;
30
+ /**
31
+ * Type errors of one file, as `TS<code>: <message>` without positions so the
32
+ * lists before and after a transformation can be compared.
33
+ */
34
+ export declare function fileTypeErrors(sourceFile: SourceFile): string[];
35
+ /**
36
+ * Errors in `after` that `before` did not have (multiset difference): errors
37
+ * the file already had do not fail the transformation.
38
+ */
39
+ export declare function introducedTypeErrors(before: readonly string[], after: readonly string[]): string[];
40
+ //# sourceMappingURL=transform-safety.d.ts.map
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Safety envelope shared by transform-code and rollback-changes: backups in
3
+ * the project (not in the server's working directory), one RollbackManager
4
+ * configuration for both tools, and the type check of a transformed file.
5
+ */
6
+ import { existsSync } from 'node:fs';
7
+ import { dirname, join, resolve } from 'node:path';
8
+ import { DiagnosticCategory } from 'ts-morph';
9
+ import { RollbackManager, RollbackStrategy } from '@angular-modernizer/core';
10
+ /**
11
+ * Backup directory name inside the project root.
12
+ */
13
+ export const BACKUP_DIR_NAME = '.angular-modernizer-backups';
14
+ /**
15
+ * Backup directory of a project: the explicit one, else inside the project.
16
+ */
17
+ export function projectBackupDir(projectRoot, backupDir) {
18
+ return backupDir ?? join(projectRoot, BACKUP_DIR_NAME);
19
+ }
20
+ /**
21
+ * RollbackManager writing to and reading from the project's backup
22
+ * directory; git snapshots run in the project root.
23
+ */
24
+ export function createProjectRollbackManager(projectRoot, options = {}) {
25
+ return new RollbackManager({
26
+ backupDir: projectBackupDir(projectRoot, options.backupDir),
27
+ gitRoot: projectRoot,
28
+ strategy: options.strategy ?? RollbackStrategy.AUTO,
29
+ });
30
+ }
31
+ /**
32
+ * Nearest directory above a file that holds a tsconfig.json, package.json or
33
+ * .angular-modernizer.json; undefined when none exists up to the file system
34
+ * root.
35
+ */
36
+ export function findProjectRootOf(filePath) {
37
+ let dir = dirname(resolve(filePath));
38
+ for (;;) {
39
+ const marker = ['tsconfig.json', 'package.json', '.angular-modernizer.json']
40
+ .map((name) => join(dir, name))
41
+ .some((path) => existsSync(path));
42
+ if (marker) {
43
+ return dir;
44
+ }
45
+ const parent = dirname(dir);
46
+ if (parent === dir) {
47
+ return undefined;
48
+ }
49
+ dir = parent;
50
+ }
51
+ }
52
+ /**
53
+ * Type errors of one file, as `TS<code>: <message>` without positions so the
54
+ * lists before and after a transformation can be compared.
55
+ */
56
+ export function fileTypeErrors(sourceFile) {
57
+ return sourceFile
58
+ .getPreEmitDiagnostics()
59
+ .filter((d) => d.getCategory() === DiagnosticCategory.Error)
60
+ .map((d) => {
61
+ const message = d.getMessageText();
62
+ const text = typeof message === 'string' ? message : message.getMessageText();
63
+ return `TS${d.getCode()}: ${text}`;
64
+ });
65
+ }
66
+ /**
67
+ * Errors in `after` that `before` did not have (multiset difference): errors
68
+ * the file already had do not fail the transformation.
69
+ */
70
+ export function introducedTypeErrors(before, after) {
71
+ const remaining = new Map();
72
+ for (const error of before) {
73
+ remaining.set(error, (remaining.get(error) ?? 0) + 1);
74
+ }
75
+ const introduced = [];
76
+ for (const error of after) {
77
+ const count = remaining.get(error) ?? 0;
78
+ if (count > 0) {
79
+ remaining.set(error, count - 1);
80
+ }
81
+ else {
82
+ introduced.push(error);
83
+ }
84
+ }
85
+ return introduced;
86
+ }
87
+ //# sourceMappingURL=transform-safety.js.map