@angular-modernizer/adapter-mcp 1.2.0 → 2.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 (138) hide show
  1. package/CHANGELOG.md +688 -0
  2. package/README.md +84 -445
  3. package/dist/cli.js +9 -1
  4. package/dist/core/project-analyzer.js +2 -2
  5. package/dist/index.d.ts +10 -0
  6. package/dist/index.js +1 -0
  7. package/dist/scan-host/scan-host.d.ts +7 -0
  8. package/dist/scan-host/scan-host.js +73 -10
  9. package/dist/scan-host/scan-protocol.d.ts +2 -0
  10. package/dist/scan-host/scan-worker.js +14 -8
  11. package/dist/server/limited-stdio-transport.d.ts +6 -3
  12. package/dist/server/limited-stdio-transport.js +26 -9
  13. package/dist/server/mcp-server.js +1 -1
  14. package/dist/server/sdk-server.d.ts +14 -3
  15. package/dist/server/sdk-server.js +54 -6
  16. package/dist/server/tool-registry.d.ts +3 -1
  17. package/dist/server/tool-registry.js +8 -3
  18. package/dist/streaming/progress-store.d.ts +19 -7
  19. package/dist/streaming/progress-store.js +19 -8
  20. package/dist/tools/analyze-build-impact.d.ts +7 -4
  21. package/dist/tools/analyze-build-impact.js +8 -3
  22. package/dist/tools/analyze-core-to-shared.d.ts +10 -6
  23. package/dist/tools/analyze-core-to-shared.js +63 -60
  24. package/dist/tools/analyze-parser-performance.d.ts +57 -13
  25. package/dist/tools/analyze-parser-performance.js +67 -6
  26. package/dist/tools/analyze-project.d.ts +55 -4
  27. package/dist/tools/analyze-project.js +104 -15
  28. package/dist/tools/check-incremental-compatibility.d.ts +30 -41
  29. package/dist/tools/check-incremental-compatibility.js +32 -264
  30. package/dist/tools/collect-feedback.js +15 -2
  31. package/dist/tools/compare-health.d.ts +40 -4
  32. package/dist/tools/compare-health.js +22 -5
  33. package/dist/tools/extract-libraries.js +42 -27
  34. package/dist/tools/find-angular-symbol.js +3 -2
  35. package/dist/tools/find-component-hosts.js +3 -2
  36. package/dist/tools/find-usages.js +21 -12
  37. package/dist/tools/get-call-graph.js +15 -2
  38. package/dist/tools/get-operation-progress-tool.d.ts +1 -1
  39. package/dist/tools/get-operation-progress-tool.js +2 -2
  40. package/dist/tools/get-operation-progress.d.ts +4 -1
  41. package/dist/tools/get-operation-progress.js +6 -2
  42. package/dist/tools/helpers/analysis-output.d.ts +32 -1
  43. package/dist/tools/helpers/analysis-output.js +25 -1
  44. package/dist/tools/helpers/build-cache.d.ts +27 -0
  45. package/dist/tools/helpers/build-cache.js +86 -0
  46. package/dist/tools/helpers/class-filter.d.ts +18 -0
  47. package/dist/tools/helpers/class-filter.js +30 -0
  48. package/dist/tools/helpers/cli-arguments.d.ts +23 -0
  49. package/dist/tools/helpers/cli-arguments.js +35 -0
  50. package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
  51. package/dist/tools/helpers/feedback-catalog.js +196 -0
  52. package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
  53. package/dist/tools/helpers/feedback-sidecar.js +381 -0
  54. package/dist/tools/helpers/file-type-check.d.ts +34 -0
  55. package/dist/tools/helpers/file-type-check.js +56 -0
  56. package/dist/tools/helpers/health-delta.d.ts +6 -0
  57. package/dist/tools/helpers/health-delta.js +4 -1
  58. package/dist/tools/helpers/library-import-warning.d.ts +33 -0
  59. package/dist/tools/helpers/library-import-warning.js +38 -0
  60. package/dist/tools/helpers/library-imports.d.ts +38 -14
  61. package/dist/tools/helpers/library-imports.js +128 -23
  62. package/dist/tools/helpers/output-contract.d.ts +64 -0
  63. package/dist/tools/helpers/output-contract.js +67 -0
  64. package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
  65. package/dist/tools/helpers/pattern-anonymizer.js +159 -0
  66. package/dist/tools/helpers/project-cache.d.ts +5 -4
  67. package/dist/tools/helpers/project-cache.js +21 -16
  68. package/dist/tools/helpers/project-decorators.d.ts +11 -4
  69. package/dist/tools/helpers/project-decorators.js +13 -6
  70. package/dist/tools/helpers/refresh-apply.d.ts +94 -0
  71. package/dist/tools/helpers/refresh-apply.js +460 -0
  72. package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
  73. package/dist/tools/helpers/refresh-inventory.js +631 -0
  74. package/dist/tools/helpers/rule-runner.js +3 -1
  75. package/dist/tools/helpers/scan-cache.d.ts +117 -5
  76. package/dist/tools/helpers/scan-cache.js +179 -6
  77. package/dist/tools/helpers/scan-engine.d.ts +43 -6
  78. package/dist/tools/helpers/scan-engine.js +141 -22
  79. package/dist/tools/helpers/scan-plan.js +16 -2
  80. package/dist/tools/helpers/source-map-loader.d.ts +55 -0
  81. package/dist/tools/helpers/source-map-loader.js +226 -0
  82. package/dist/tools/helpers/template-check.d.ts +76 -0
  83. package/dist/tools/helpers/template-check.js +158 -0
  84. package/dist/tools/helpers/tool-cache.d.ts +7 -2
  85. package/dist/tools/helpers/tool-cache.js +9 -3
  86. package/dist/tools/helpers/tool-context.d.ts +18 -0
  87. package/dist/tools/helpers/tool-context.js +29 -0
  88. package/dist/tools/helpers/transform-safety.d.ts +151 -1
  89. package/dist/tools/helpers/transform-safety.js +357 -4
  90. package/dist/tools/inspect-form-group.js +5 -0
  91. package/dist/tools/inspect-i18n.d.ts +1 -1
  92. package/dist/tools/inspect-template.js +8 -2
  93. package/dist/tools/learn-patterns.d.ts +43 -28
  94. package/dist/tools/learn-patterns.js +83 -161
  95. package/dist/tools/list-imports.d.ts +1 -1
  96. package/dist/tools/orchestrate-migration.d.ts +19 -1
  97. package/dist/tools/orchestrate-migration.js +52 -10
  98. package/dist/tools/parse-stack-trace.d.ts +48 -1
  99. package/dist/tools/parse-stack-trace.js +108 -9
  100. package/dist/tools/plan-migration.js +22 -10
  101. package/dist/tools/refresh-state.d.ts +378 -0
  102. package/dist/tools/refresh-state.js +370 -0
  103. package/dist/tools/resolve-type.js +10 -3
  104. package/dist/tools/review-feedback.d.ts +42 -7
  105. package/dist/tools/review-feedback.js +24 -17
  106. package/dist/tools/rollback-changes.d.ts +5 -0
  107. package/dist/tools/rollback-changes.js +7 -2
  108. package/dist/tools/run-angular-cli.js +36 -22
  109. package/dist/tools/run-build.d.ts +33 -28
  110. package/dist/tools/run-build.js +136 -438
  111. package/dist/tools/run-schematic.d.ts +8 -2
  112. package/dist/tools/run-schematic.js +80 -50
  113. package/dist/tools/scan-all.d.ts +37 -15
  114. package/dist/tools/scan-all.js +76 -115
  115. package/dist/tools/scan-angular.d.ts +33 -14
  116. package/dist/tools/scan-angular.js +77 -94
  117. package/dist/tools/scan-architecture.d.ts +37 -12
  118. package/dist/tools/scan-architecture.js +220 -139
  119. package/dist/tools/scan-solid.d.ts +33 -14
  120. package/dist/tools/scan-solid.js +80 -91
  121. package/dist/tools/search-codebase.d.ts +6 -1
  122. package/dist/tools/search-codebase.js +13 -7
  123. package/dist/tools/suggest-improvements.d.ts +34 -3
  124. package/dist/tools/suggest-improvements.js +34 -9
  125. package/dist/tools/trace-output-flow.js +3 -2
  126. package/dist/tools/transform-code-batch.d.ts +9 -9
  127. package/dist/tools/transform-code.d.ts +161 -12
  128. package/dist/tools/transform-code.js +715 -206
  129. package/dist/tools/validate-before-transform.js +2 -1
  130. package/dist/tools/validate-project-compatibility.d.ts +28 -55
  131. package/dist/tools/validate-project-compatibility.js +33 -225
  132. package/dist/tools/validate-transformation.d.ts +40 -26
  133. package/dist/tools/validate-transformation.js +115 -294
  134. package/dist/tools/verify-citations.js +8 -2
  135. package/dist/types.d.ts +9 -9
  136. package/dist/utils/format-tool-response.d.ts +3 -1
  137. package/dist/utils/format-tool-response.js +8 -3
  138. package/package.json +14 -13
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Build cache clearing (`cacheStrategy: 'clear'`)
3
+ *
4
+ * run-build and validate-transformation remove the build caches of the project
5
+ * before an incremental build. Each cache is resolved through symlinks first and
6
+ * removed only when it lies inside the project root and not under `node_modules`:
7
+ * a linked or shared `node_modules` (pnpm, monorepos, project copies) leads out
8
+ * of the project, and `rm -rf` used to delete there.
9
+ */
10
+ import { existsSync, realpathSync, rmSync } from 'node:fs';
11
+ import { isAbsolute, join, relative, sep } from 'node:path';
12
+ /** Angular CLI build cache, relative to the project root. */
13
+ const ANGULAR_CACHE = '.angular/cache';
14
+ /** Nx cache of Nx 17 and later, relative to the project root. */
15
+ const NX_CACHE = '.nx/cache';
16
+ /** Nx cache of older Nx versions; under node_modules, so it is never removed. */
17
+ const LEGACY_NX_CACHE = 'node_modules/.cache/nx';
18
+ /**
19
+ * Remove the Angular CLI cache and, in an Nx workspace, the Nx cache of a project.
20
+ *
21
+ * Missing caches are skipped silently; a cache that resolves outside the project
22
+ * root or under `node_modules`, or that cannot be removed, is left in place and
23
+ * reported in `warnings`.
24
+ *
25
+ * @param projectRoot - Root folder of the project
26
+ */
27
+ export function clearBuildCaches(projectRoot) {
28
+ const result = { cleared: [], warnings: [] };
29
+ let root;
30
+ try {
31
+ root = realpathSync(projectRoot);
32
+ }
33
+ catch (error) {
34
+ result.warnings.push(`Build caches not cleared: ${errorMessage(error)}`);
35
+ return result;
36
+ }
37
+ const isNx = existsSync(join(root, 'nx.json'));
38
+ const targets = isNx ? [ANGULAR_CACHE, NX_CACHE] : [ANGULAR_CACHE];
39
+ for (const target of targets) {
40
+ clearCache(root, target, result);
41
+ }
42
+ if (isNx && existsSync(join(root, LEGACY_NX_CACHE))) {
43
+ result.warnings.push(`${LEGACY_NX_CACHE} left in place: caches under node_modules are never removed; run \`nx reset\` to clear it`);
44
+ }
45
+ return result;
46
+ }
47
+ function clearCache(root, target, result) {
48
+ let resolved;
49
+ try {
50
+ resolved = realpathSync(join(root, target));
51
+ }
52
+ catch (error) {
53
+ if (isMissing(error)) {
54
+ return;
55
+ }
56
+ result.warnings.push(`${target} not cleared: ${errorMessage(error)}`);
57
+ return;
58
+ }
59
+ if (!isInsideProject(root, resolved)) {
60
+ result.warnings.push(`${target} not cleared: it resolves to ${resolved}, outside the project root or under node_modules`);
61
+ return;
62
+ }
63
+ try {
64
+ rmSync(resolved, { recursive: true, force: true });
65
+ result.cleared.push(target);
66
+ }
67
+ catch (error) {
68
+ result.warnings.push(`${target} could not be removed: ${errorMessage(error)}`);
69
+ }
70
+ }
71
+ function isInsideProject(root, resolved) {
72
+ const path = relative(root, resolved);
73
+ const outside = path === '' || path === '..' || path.startsWith(`..${sep}`) || isAbsolute(path);
74
+ return !outside && !path.split(sep).includes('node_modules');
75
+ }
76
+ // Structural checks: fs errors from another realm (Jest's vm) fail `instanceof Error`
77
+ function isMissing(error) {
78
+ return typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT';
79
+ }
80
+ function errorMessage(error) {
81
+ if (typeof error === 'object' && error !== null && 'message' in error) {
82
+ return String(error.message);
83
+ }
84
+ return String(error);
85
+ }
86
+ //# sourceMappingURL=build-cache.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Class filter
3
+ *
4
+ * Explains an empty result of a tool that takes `className` for a file
5
+ * (inspect-template, inspect-form-group) when no class of the file has that
6
+ * name, instead of the generic "nothing found" message.
7
+ */
8
+ import { type SourceFile } from 'ts-morph';
9
+ /**
10
+ * Message for a `className` that matches no class of `sourceFile`.
11
+ *
12
+ * @param sourceFile - The inspected file; `undefined` (an `.html` file) never matches.
13
+ * @param className - The requested class, if any.
14
+ * @param filePath - Path shown in the message.
15
+ * @returns The message, or `undefined` when no class was requested or the file declares it.
16
+ */
17
+ export declare function missingClassMessage(sourceFile: SourceFile | undefined, className: string | undefined, filePath: string): string | undefined;
18
+ //# sourceMappingURL=class-filter.d.ts.map
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Class filter
3
+ *
4
+ * Explains an empty result of a tool that takes `className` for a file
5
+ * (inspect-template, inspect-form-group) when no class of the file has that
6
+ * name, instead of the generic "nothing found" message.
7
+ */
8
+ /**
9
+ * Message for a `className` that matches no class of `sourceFile`.
10
+ *
11
+ * @param sourceFile - The inspected file; `undefined` (an `.html` file) never matches.
12
+ * @param className - The requested class, if any.
13
+ * @param filePath - Path shown in the message.
14
+ * @returns The message, or `undefined` when no class was requested or the file declares it.
15
+ */
16
+ export function missingClassMessage(sourceFile, className, filePath) {
17
+ if (className === undefined || sourceFile === undefined) {
18
+ return undefined;
19
+ }
20
+ const names = sourceFile
21
+ .getClasses()
22
+ .map((cls) => cls.getName())
23
+ .filter((name) => name !== undefined);
24
+ if (names.includes(className)) {
25
+ return undefined;
26
+ }
27
+ const found = names.length === 0 ? 'the file declares no class' : `classes in the file: ${names.join(', ')}`;
28
+ return `No class named ${className} in ${filePath}; ${found}.`;
29
+ }
30
+ //# sourceMappingURL=class-filter.js.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Spawn settings for the Angular CLI tools (run-angular-cli, run-schematic).
3
+ *
4
+ * On POSIX the arguments go to `npx` as argv without a shell, so `;`, `$( )`,
5
+ * backticks or quotes in a value stay part of that value. Windows needs the
6
+ * shell to start `npx.cmd`; there cmd.exe would interpret the line, so values
7
+ * with its metacharacters are rejected before anything runs.
8
+ */
9
+ /**
10
+ * Whether the CLI process needs a shell: only on Windows, for `npx.cmd`.
11
+ *
12
+ * @returns `true` on win32
13
+ */
14
+ export declare function cliNeedsShell(): boolean;
15
+ /**
16
+ * Throws when a value would be interpreted by the shell the CLI runs in. Does
17
+ * nothing where the CLI runs without a shell.
18
+ *
19
+ * @param values - Every value that becomes part of the command line
20
+ * @throws Error naming the first value with a shell metacharacter
21
+ */
22
+ export declare function assertShellSafeArguments(values: readonly string[]): void;
23
+ //# sourceMappingURL=cli-arguments.d.ts.map
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Spawn settings for the Angular CLI tools (run-angular-cli, run-schematic).
3
+ *
4
+ * On POSIX the arguments go to `npx` as argv without a shell, so `;`, `$( )`,
5
+ * backticks or quotes in a value stay part of that value. Windows needs the
6
+ * shell to start `npx.cmd`; there cmd.exe would interpret the line, so values
7
+ * with its metacharacters are rejected before anything runs.
8
+ */
9
+ /** Characters cmd.exe interprets in a command line. */
10
+ const CMD_METACHARACTERS = /[&|<>^%!"`\r\n]/;
11
+ /**
12
+ * Whether the CLI process needs a shell: only on Windows, for `npx.cmd`.
13
+ *
14
+ * @returns `true` on win32
15
+ */
16
+ export function cliNeedsShell() {
17
+ return process.platform === 'win32';
18
+ }
19
+ /**
20
+ * Throws when a value would be interpreted by the shell the CLI runs in. Does
21
+ * nothing where the CLI runs without a shell.
22
+ *
23
+ * @param values - Every value that becomes part of the command line
24
+ * @throws Error naming the first value with a shell metacharacter
25
+ */
26
+ export function assertShellSafeArguments(values) {
27
+ if (!cliNeedsShell()) {
28
+ return;
29
+ }
30
+ const unsafe = values.find((value) => CMD_METACHARACTERS.test(value));
31
+ if (unsafe !== undefined) {
32
+ throw new Error(`Argument contains a shell metacharacter (one of & | < > ^ % ! " \` or a line break), rejected on Windows: ${unsafe}`);
33
+ }
34
+ }
35
+ //# sourceMappingURL=cli-arguments.js.map
@@ -0,0 +1,38 @@
1
+ /** Values of transform-code's `transformation` argument. */
2
+ export declare const TRANSFORMATION_TYPES: readonly ["constructor-to-inject", "interface-extraction", "standalone-migration", "dependency-injection-migration", "facade-pattern", "form-modernization", "constructor-injection-transform", "component-inputs-interface-extraction", "service-injection-cleanup", "container-presentational", "core-shared-modules", "inheritance-to-composition", "promise-service-to-observable", "promise-component-to-reactive", "promise-cleanup", "sequential-await-to-forkjoin", "missing-output-transform", "subscription-transform", "library-extraction", "service-bag-transform", "any-to-interface", "dto-object-literal", "interface-duplication", "static-class-to-functions", "extract-static-from-stateful", "type-safety"];
3
+ /** Ids of the analysis and transform rules of plugin-angular, plugin-architecture, plugin-solid, plugin-standalone and plugin-analyzer. */
4
+ export declare const REGISTERED_RULE_IDS: readonly string[];
5
+ /** A tool the server registers. */
6
+ export interface CatalogTool {
7
+ /** Tool name. */
8
+ name: string;
9
+ /** Whether its description marks it as deprecated. */
10
+ deprecated: boolean;
11
+ }
12
+ /** Tools the server registers, read on each call (the server registers some after the others). */
13
+ export type ToolCatalogProvider = () => readonly CatalogTool[];
14
+ /** Why a feedback record counts as outdated. */
15
+ export type OutdatedReason = 'unknown-rule' | 'unknown-transformation' | 'unknown-tool' | 'deprecated-tool';
16
+ /** Tool entry of a registered tool, from its name and description. */
17
+ export declare function catalogTool(tool: {
18
+ name: string;
19
+ description: string;
20
+ }): CatalogTool;
21
+ /**
22
+ * Why a raw session record is outdated, or `undefined` when it is current or not checked. A transformation record
23
+ * names its rule in `rule.ruleId`: with a `:` it must be a registered rule id, without one a transformation type or
24
+ * a rule name (collect-feedback documents `'constructor-to-inject'`). Analysis records name a tool; only a single
25
+ * tool name is checked (free text like `find-usages/get-call-graph (manual synthesis)` never named a removed tool).
26
+ * Old analysis records stored as transformation records are checked by tool only when their rule id names one; a
27
+ * plugin rule id (`solid:circular-dependency`) is checked as a rule, a free slug (`platform:mcp-registration`) not
28
+ * at all. Tools are checked only with a catalog.
29
+ */
30
+ export declare function outdatedReason(record: {
31
+ kind?: unknown;
32
+ tool?: unknown;
33
+ rule?: unknown;
34
+ }, tools: readonly CatalogTool[] | undefined): {
35
+ reason: OutdatedReason;
36
+ detail: string;
37
+ } | undefined;
38
+ //# sourceMappingURL=feedback-catalog.d.ts.map
@@ -0,0 +1,196 @@
1
+ /**
2
+ * What feedback records are checked against (refresh-state, feedback part): the rule ids of the plugins, the
3
+ * transformation types of transform-code and the tools the server registers. Rule ids and transformation types are
4
+ * constants, so no plugin is loaded for the check (plugin-angular brings `@angular/compiler`); a test compares the
5
+ * rule ids with the plugins. The tools come from the server at run time.
6
+ */
7
+ import { fromLegacyAnalysisRecord } from '@angular-modernizer/core';
8
+ /** Values of transform-code's `transformation` argument. */
9
+ export const TRANSFORMATION_TYPES = [
10
+ 'constructor-to-inject',
11
+ 'interface-extraction',
12
+ 'standalone-migration',
13
+ 'dependency-injection-migration',
14
+ 'facade-pattern',
15
+ 'form-modernization',
16
+ 'constructor-injection-transform',
17
+ 'component-inputs-interface-extraction',
18
+ 'service-injection-cleanup',
19
+ 'container-presentational',
20
+ 'core-shared-modules',
21
+ 'inheritance-to-composition',
22
+ 'promise-service-to-observable',
23
+ 'promise-component-to-reactive',
24
+ 'promise-cleanup',
25
+ 'sequential-await-to-forkjoin',
26
+ 'missing-output-transform',
27
+ 'subscription-transform',
28
+ 'library-extraction',
29
+ 'service-bag-transform',
30
+ 'any-to-interface',
31
+ 'dto-object-literal',
32
+ 'interface-duplication',
33
+ 'static-class-to-functions',
34
+ 'extract-static-from-stateful',
35
+ 'type-safety',
36
+ ];
37
+ /** Ids of the analysis and transform rules of plugin-angular, plugin-architecture, plugin-solid, plugin-standalone and plugin-analyzer. */
38
+ export const REGISTERED_RULE_IDS = [
39
+ 'analyzer:framework-detector',
40
+ 'angular:any-to-interface',
41
+ 'angular:any-to-interface-transform',
42
+ 'angular:async-pipe-misuse',
43
+ 'angular:component-inputs-interface-extraction',
44
+ 'angular:component-without-selector',
45
+ 'angular:component-wrapper-instantiation',
46
+ 'angular:constructor-injection-transform',
47
+ 'angular:constructor-to-inject',
48
+ 'angular:container-presentational',
49
+ 'angular:core-shared-modules',
50
+ 'angular:dependency-injection-migration',
51
+ 'angular:directive-without-selector',
52
+ 'angular:dto-direct-instantiation',
53
+ 'angular:dto-object-literal-transform',
54
+ 'angular:extract-static-from-stateful',
55
+ 'angular:facade-pattern',
56
+ 'angular:form-modernization',
57
+ 'angular:immutable-input-violation',
58
+ 'angular:interface-duplication',
59
+ 'angular:interface-duplication-transform',
60
+ 'angular:interface-extraction',
61
+ 'angular:lifecycle-hook-violation',
62
+ 'angular:magic-string-selector',
63
+ 'angular:missing-onpush-change-detection',
64
+ 'angular:missing-output-transform',
65
+ 'angular:missing-return-type',
66
+ 'angular:missing-trackby',
67
+ 'angular:performance-violation',
68
+ 'angular:pipe-without-name',
69
+ 'angular:presentational-component-violation',
70
+ 'angular:promise-cleanup',
71
+ 'angular:promise-component-to-reactive',
72
+ 'angular:promise-service-to-observable',
73
+ 'angular:promise-vs-observable-anti-pattern',
74
+ 'angular:sequential-await-to-forkjoin',
75
+ 'angular:service-mutable-state',
76
+ 'angular:service-without-injectable',
77
+ 'angular:static-class-detection',
78
+ 'angular:static-class-to-functions',
79
+ 'angular:subscription-transform',
80
+ 'angular:template-complexity',
81
+ 'angular:too-many-inputs',
82
+ 'angular:transform:inheritance-to-composition',
83
+ 'angular:transform:service-injection-cleanup',
84
+ 'angular:type-safety',
85
+ 'angular:type-safety-transform',
86
+ 'angular:unnecessary-change-detection',
87
+ 'angular:untyped-dynamic-component',
88
+ 'architecture:advanced-content-placement',
89
+ 'architecture:component-complexity',
90
+ 'architecture:content-placement',
91
+ 'architecture:cross-file-architecture',
92
+ 'architecture:error-handling-pattern',
93
+ 'architecture:inheritance-analysis',
94
+ 'architecture:layer-boundary-violation',
95
+ 'architecture:library-extraction-opportunity',
96
+ 'architecture:model-separation',
97
+ 'architecture:performance-pattern',
98
+ 'architecture:rxjs-memory-leak',
99
+ 'architecture:service-architecture',
100
+ 'architecture:service-bag',
101
+ 'architecture:static-in-stateful-class',
102
+ 'plugin-angular:bundle-size-optimization',
103
+ 'plugin-angular:data-handling-strategy',
104
+ 'plugin-angular:rxjs-optimization',
105
+ 'refactor:library-extraction',
106
+ 'refactor:service-bag-split',
107
+ 'solid:circular-dependency',
108
+ 'solid:dip-violation-direct-instantiation',
109
+ 'solid:god-object-violation',
110
+ 'solid:god-switch',
111
+ 'solid:god-switch-transform',
112
+ 'solid:import-direction-violation',
113
+ 'solid:isp-violation',
114
+ 'solid:lsp-violation',
115
+ 'solid:ocp-violation',
116
+ 'solid:service-dip-violation',
117
+ 'solid:service-dip-violation-transform',
118
+ 'solid:srp-single-responsibility-violation',
119
+ 'standalone:migrate-to-standalone',
120
+ ];
121
+ /** Tool entry of a registered tool, from its name and description. */
122
+ export function catalogTool(tool) {
123
+ return { name: tool.name, deprecated: /^deprecated\b/i.test(tool.description) };
124
+ }
125
+ const RULE_IDS = new Set(REGISTERED_RULE_IDS);
126
+ /** Rule ids without the plugin prefix (`angular:constructor-to-inject` -> `constructor-to-inject`). */
127
+ const RULE_NAMES = new Set(REGISTERED_RULE_IDS.map((id) => id.slice(id.lastIndexOf(':') + 1)));
128
+ const TYPES = new Set(TRANSFORMATION_TYPES);
129
+ /** Plugin prefixes of the registered rule ids (`solid`, `architecture`, ...). */
130
+ const RULE_PREFIXES = new Set(REGISTERED_RULE_IDS.map((id) => id.slice(0, id.indexOf(':'))));
131
+ /** A single tool name; anything else in `tool` is free text. */
132
+ const TOOL_NAME = /^[a-z][a-z0-9-]*$/;
133
+ /**
134
+ * Why a raw session record is outdated, or `undefined` when it is current or not checked. A transformation record
135
+ * names its rule in `rule.ruleId`: with a `:` it must be a registered rule id, without one a transformation type or
136
+ * a rule name (collect-feedback documents `'constructor-to-inject'`). Analysis records name a tool; only a single
137
+ * tool name is checked (free text like `find-usages/get-call-graph (manual synthesis)` never named a removed tool).
138
+ * Old analysis records stored as transformation records are checked by tool only when their rule id names one; a
139
+ * plugin rule id (`solid:circular-dependency`) is checked as a rule, a free slug (`platform:mcp-registration`) not
140
+ * at all. Tools are checked only with a catalog.
141
+ */
142
+ export function outdatedReason(record, tools) {
143
+ if (record.kind === 'analysis') {
144
+ return typeof record.tool === 'string' && TOOL_NAME.test(record.tool)
145
+ ? toolReason(record.tool, tools)
146
+ : undefined;
147
+ }
148
+ const rule = record.rule;
149
+ if (rule?.ruleType === 'analysis') {
150
+ const legacy = fromLegacyAnalysisRecord(record);
151
+ return legacy === null ? undefined : legacyReason(legacy.tool, rule.ruleId, tools);
152
+ }
153
+ const ruleId = rule?.ruleId;
154
+ if (typeof ruleId !== 'string' || ruleId === '') {
155
+ return undefined;
156
+ }
157
+ if (ruleId.includes(':')) {
158
+ return RULE_IDS.has(ruleId)
159
+ ? undefined
160
+ : { reason: 'unknown-rule', detail: `rule ${ruleId} is not registered` };
161
+ }
162
+ return TYPES.has(ruleId) || RULE_NAMES.has(ruleId)
163
+ ? undefined
164
+ : {
165
+ reason: 'unknown-transformation',
166
+ detail: `${ruleId} is neither a transformation type of transform-code nor a rule name`,
167
+ };
168
+ }
169
+ /**
170
+ * Old analysis records derive their tool from the rule id: a known tool name at its start, or else the whole rule
171
+ * id. Only the first names a tool. A derived name that is the rule id itself and no registered tool is the fallback:
172
+ * then a plugin rule id is checked as a rule, anything else is a free slug and not checked.
173
+ */
174
+ function legacyReason(tool, ruleId, tools) {
175
+ const id = typeof ruleId === 'string' ? ruleId : '';
176
+ const fallback = tool === id.replace(/^analysis:/, '') && !tools?.some((t) => t.name === tool);
177
+ if (!fallback) {
178
+ return toolReason(tool, tools);
179
+ }
180
+ const prefix = id.includes(':') ? id.slice(0, id.indexOf(':')) : '';
181
+ if (!RULE_PREFIXES.has(prefix) || RULE_IDS.has(id)) {
182
+ return undefined;
183
+ }
184
+ return { reason: 'unknown-rule', detail: `rule ${id} is not registered` };
185
+ }
186
+ function toolReason(name, tools) {
187
+ if (tools === undefined) {
188
+ return undefined;
189
+ }
190
+ const tool = tools.find((t) => t.name === name);
191
+ if (tool === undefined) {
192
+ return { reason: 'unknown-tool', detail: `tool ${name} is not registered` };
193
+ }
194
+ return tool.deprecated ? { reason: 'deprecated-tool', detail: `tool ${name} is deprecated` } : undefined;
195
+ }
196
+ //# sourceMappingURL=feedback-catalog.js.map
@@ -0,0 +1,201 @@
1
+ import { type CatalogTool, type OutdatedReason } from './feedback-catalog.js';
2
+ /** Format of the sidecar file. */
3
+ export declare const SIDECAR_FORMAT = "ngm-feedback-consolidated-v1";
4
+ /** Feedback folder in the project root. */
5
+ export declare const FEEDBACK_ROOT_DIR = ".claude-feedback";
6
+ /** Sidecar folder below the feedback folder. */
7
+ export declare const FEEDBACK_INDEX_DIR = "index";
8
+ /** Sidecar file name. */
9
+ export declare const SIDECAR_FILE = "consolidated.json";
10
+ /** The sidecar before the last apply. */
11
+ export declare const PREVIOUS_SIDECAR_FILE = "consolidated.prev.json";
12
+ /** Why a record is marked. */
13
+ export type FeedbackMarkReason = 'duplicate' | OutdatedReason;
14
+ /** Mark of one record. */
15
+ export interface FeedbackMark {
16
+ /** Why it is marked. */
17
+ reason: FeedbackMarkReason;
18
+ /** What was found. */
19
+ detail?: string;
20
+ }
21
+ /** Marks of one session file. */
22
+ export interface SidecarSession {
23
+ /** SHA-256 of the session file when it was marked. */
24
+ sha256: string;
25
+ /** Marks by record key (`t:<transformationId>`, `f:<feedbackId>`). */
26
+ marks: Record<string, FeedbackMark>;
27
+ }
28
+ /** Content of `consolidated.json`. */
29
+ export interface FeedbackSidecar {
30
+ /** Always {@link SIDECAR_FORMAT}. */
31
+ format: typeof SIDECAR_FORMAT;
32
+ /** When it was written (ISO). */
33
+ writtenAt: string;
34
+ /** Plan of the refresh-state report the marks were confirmed with. */
35
+ planId: string;
36
+ /** adapter-mcp version that wrote it. */
37
+ version: string;
38
+ /** Marks per session file name. */
39
+ sessions: Record<string, SidecarSession>;
40
+ }
41
+ /** One session file and what it holds. */
42
+ export interface SessionScan {
43
+ /** File name in the sessions folder. */
44
+ file: string;
45
+ /** SHA-256 of the file. */
46
+ sha256: string;
47
+ /** Bytes. */
48
+ size: number;
49
+ /** mtime. */
50
+ mtimeMs: number;
51
+ /** Records with a key. */
52
+ records: number;
53
+ /** Marks this file's records get now. */
54
+ marks: Record<string, FeedbackMark>;
55
+ /** Records that repeat an earlier one. */
56
+ duplicates: number;
57
+ /** Outdated records. */
58
+ outdated: number;
59
+ }
60
+ /** Key of a raw session record: `t:<transformationId>`, `f:<feedbackId>`, or `undefined` (header). */
61
+ export declare function recordKey(record: {
62
+ transformationId?: unknown;
63
+ feedbackId?: unknown;
64
+ }): string | undefined;
65
+ /**
66
+ * Reads every `.jsonl` file of a sessions folder in name order and marks each record that repeats a key of an
67
+ * earlier one (file order, then line order: the first stays) and each outdated record. Symbolic links are skipped.
68
+ * `tools` undefined leaves the tools unchecked.
69
+ */
70
+ export declare function scanFeedbackSessions(sessionsDir: string, tools: readonly CatalogTool[] | undefined): SessionScan[];
71
+ /** Result of reading the sidecar. */
72
+ export interface SidecarRead {
73
+ /** The sidecar, `undefined` when there is none or it is unusable. */
74
+ sidecar?: FeedbackSidecar;
75
+ /** Why it is unusable. */
76
+ problem?: string;
77
+ }
78
+ /** Reads `consolidated.json` of a project; never throws. */
79
+ export declare function readSidecar(projectRoot: string): SidecarRead;
80
+ /** Whether the marks of a sidecar entry equal `marks` (key order ignored). */
81
+ export declare function sameMarks(a: Record<string, FeedbackMark>, b: Record<string, FeedbackMark>): boolean;
82
+ /** Outcome of {@link writeFeedbackMarks}. */
83
+ export type MarkWriteResult = {
84
+ /** Records marked per session file that was written. */
85
+ marked: {
86
+ file: string;
87
+ records: number;
88
+ }[];
89
+ /** Planned files whose content changed since the report. */
90
+ changed: string[];
91
+ /** Planned files that are gone. */
92
+ missing: string[];
93
+ } | {
94
+ error: string;
95
+ outsideFolder: boolean;
96
+ };
97
+ /**
98
+ * Writes the marks of the session files in `planned` (file name -> SHA-256 at report time) into the sidecar. A file
99
+ * is marked only while it still has that hash; entries of other files stay while their file is unchanged and are
100
+ * dropped otherwise. The previous sidecar is kept as {@link PREVIOUS_SIDECAR_FILE}; the new one replaces it through
101
+ * a rename. Session files are only read.
102
+ */
103
+ export declare function writeFeedbackMarks(projectRoot: string, sessionsDir: string, planned: ReadonlyMap<string, string>, tools: readonly CatalogTool[] | undefined, planId: string, now: number): MarkWriteResult;
104
+ /** Marks the readers apply, from the sidecar of the project. */
105
+ export interface MarkView {
106
+ /** Outdated record keys with their reason. */
107
+ outdated: ReadonlyMap<string, FeedbackMarkReason>;
108
+ /** Keys with a duplicate mark: the first record of such a key stays, every later one is skipped. */
109
+ duplicateKeys: ReadonlySet<string>;
110
+ /** Unusable sidecar, or session files changed since they were marked. */
111
+ warnings: string[];
112
+ }
113
+ /** Reads the marks of the project's sidecar for the readers; an unusable sidecar marks nothing. */
114
+ export declare function loadMarkView(projectRoot: string): MarkView;
115
+ /** Records the readers skipped. */
116
+ export interface SkippedRecords {
117
+ /** Skipped records. */
118
+ total: number;
119
+ /** Skipped records per reason. */
120
+ byReason: Record<string, number>;
121
+ }
122
+ /**
123
+ * Decides per record whether a reader skips it. Feed the records session by session in the order of
124
+ * {@link sessionFileOrder} and in file order within a session, so the first record of a duplicate key is the one the
125
+ * sidecar keeps.
126
+ */
127
+ export declare class MarkFilter {
128
+ private readonly view;
129
+ private readonly includeOutdated;
130
+ private readonly seen;
131
+ /** What was skipped so far. */
132
+ readonly skipped: SkippedRecords;
133
+ /**
134
+ * @param view marks of the sidecar
135
+ * @param includeOutdated true skips nothing (the view before the sidecar)
136
+ */
137
+ constructor(view: MarkView, includeOutdated: boolean);
138
+ /** Whether to keep the record with this key; counts it when not. */
139
+ keep(key: string | undefined): boolean;
140
+ }
141
+ /** Session ids in the order the sidecar reads their files (by file name). */
142
+ export declare function sessionFileOrder(sessionIds: readonly string[]): string[];
143
+ /** Sessions after the sidecar marks, for the readers. */
144
+ export interface MarkedSessions<S> {
145
+ /** Sessions in file name order, without the skipped records. */
146
+ sessions: S[];
147
+ /** The same sessions by session id. */
148
+ byId: Map<string, S>;
149
+ /** What was skipped. */
150
+ skipped: SkippedRecords;
151
+ /** Unusable sidecar, or session files changed since they were marked. */
152
+ warnings: string[];
153
+ }
154
+ /**
155
+ * Drops the records the project's sidecar marks from loaded sessions (nothing with `includeOutdated`). Keys come
156
+ * from the stored ids (`transformationId`, `feedbackId`), so old analysis records stored as transformation records
157
+ * keep their `t:` key.
158
+ */
159
+ export declare function skipMarkedRecords<S extends {
160
+ transformations: {
161
+ transformationId: string;
162
+ }[];
163
+ analyses?: {
164
+ feedbackId: string;
165
+ }[];
166
+ }>(projectRoot: string, sessions: ReadonlyMap<string, S>, includeOutdated: boolean): MarkedSessions<S>;
167
+ /** Input property `includeOutdated` of the readers. */
168
+ export declare const INCLUDE_OUTDATED_SCHEMA: {
169
+ readonly includeOutdated: {
170
+ readonly type: "boolean";
171
+ readonly default: false;
172
+ readonly description: "Also read the records that .claude-feedback/index/consolidated.json marks as duplicate or outdated (written by refresh-state apply, part 'feedback'); default false skips them and counts them in skippedRecords";
173
+ };
174
+ };
175
+ /** Output properties `skippedRecords` and `sidecarWarnings` of the readers. */
176
+ export declare const SKIPPED_RECORDS_OUTPUT_SCHEMA: {
177
+ readonly skippedRecords: {
178
+ readonly type: "object";
179
+ readonly properties: {
180
+ readonly total: {
181
+ readonly type: "integer";
182
+ };
183
+ readonly byReason: {
184
+ readonly type: "object";
185
+ readonly additionalProperties: {
186
+ readonly type: "integer";
187
+ };
188
+ };
189
+ };
190
+ readonly required: readonly ["total", "byReason"];
191
+ };
192
+ readonly sidecarWarnings: {
193
+ readonly type: "array";
194
+ readonly items: {
195
+ readonly type: "string";
196
+ };
197
+ };
198
+ };
199
+ /** Summary lines about skipped records and sidecar warnings (none when nothing to say). */
200
+ export declare function describeSkipped(skipped: SkippedRecords, warnings: readonly string[]): string[];
201
+ //# sourceMappingURL=feedback-sidecar.d.ts.map