@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.
- package/CHANGELOG.md +688 -0
- package/README.md +84 -445
- package/dist/cli.js +9 -1
- package/dist/core/project-analyzer.js +2 -2
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1 -0
- package/dist/scan-host/scan-host.d.ts +7 -0
- package/dist/scan-host/scan-host.js +73 -10
- package/dist/scan-host/scan-protocol.d.ts +2 -0
- package/dist/scan-host/scan-worker.js +14 -8
- package/dist/server/limited-stdio-transport.d.ts +6 -3
- package/dist/server/limited-stdio-transport.js +26 -9
- package/dist/server/mcp-server.js +1 -1
- package/dist/server/sdk-server.d.ts +14 -3
- package/dist/server/sdk-server.js +54 -6
- package/dist/server/tool-registry.d.ts +3 -1
- package/dist/server/tool-registry.js +8 -3
- package/dist/streaming/progress-store.d.ts +19 -7
- package/dist/streaming/progress-store.js +19 -8
- package/dist/tools/analyze-build-impact.d.ts +7 -4
- package/dist/tools/analyze-build-impact.js +8 -3
- package/dist/tools/analyze-core-to-shared.d.ts +10 -6
- package/dist/tools/analyze-core-to-shared.js +63 -60
- package/dist/tools/analyze-parser-performance.d.ts +57 -13
- package/dist/tools/analyze-parser-performance.js +67 -6
- package/dist/tools/analyze-project.d.ts +55 -4
- package/dist/tools/analyze-project.js +104 -15
- package/dist/tools/check-incremental-compatibility.d.ts +30 -41
- package/dist/tools/check-incremental-compatibility.js +32 -264
- package/dist/tools/collect-feedback.js +15 -2
- package/dist/tools/compare-health.d.ts +40 -4
- package/dist/tools/compare-health.js +22 -5
- package/dist/tools/extract-libraries.js +42 -27
- package/dist/tools/find-angular-symbol.js +3 -2
- package/dist/tools/find-component-hosts.js +3 -2
- package/dist/tools/find-usages.js +21 -12
- package/dist/tools/get-call-graph.js +15 -2
- package/dist/tools/get-operation-progress-tool.d.ts +1 -1
- package/dist/tools/get-operation-progress-tool.js +2 -2
- package/dist/tools/get-operation-progress.d.ts +4 -1
- package/dist/tools/get-operation-progress.js +6 -2
- package/dist/tools/helpers/analysis-output.d.ts +32 -1
- package/dist/tools/helpers/analysis-output.js +25 -1
- package/dist/tools/helpers/build-cache.d.ts +27 -0
- package/dist/tools/helpers/build-cache.js +86 -0
- package/dist/tools/helpers/class-filter.d.ts +18 -0
- package/dist/tools/helpers/class-filter.js +30 -0
- package/dist/tools/helpers/cli-arguments.d.ts +23 -0
- package/dist/tools/helpers/cli-arguments.js +35 -0
- package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
- package/dist/tools/helpers/feedback-catalog.js +196 -0
- package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
- package/dist/tools/helpers/feedback-sidecar.js +381 -0
- package/dist/tools/helpers/file-type-check.d.ts +34 -0
- package/dist/tools/helpers/file-type-check.js +56 -0
- package/dist/tools/helpers/health-delta.d.ts +6 -0
- package/dist/tools/helpers/health-delta.js +4 -1
- package/dist/tools/helpers/library-import-warning.d.ts +33 -0
- package/dist/tools/helpers/library-import-warning.js +38 -0
- package/dist/tools/helpers/library-imports.d.ts +38 -14
- package/dist/tools/helpers/library-imports.js +128 -23
- package/dist/tools/helpers/output-contract.d.ts +64 -0
- package/dist/tools/helpers/output-contract.js +67 -0
- package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
- package/dist/tools/helpers/pattern-anonymizer.js +159 -0
- package/dist/tools/helpers/project-cache.d.ts +5 -4
- package/dist/tools/helpers/project-cache.js +21 -16
- package/dist/tools/helpers/project-decorators.d.ts +11 -4
- package/dist/tools/helpers/project-decorators.js +13 -6
- package/dist/tools/helpers/refresh-apply.d.ts +94 -0
- package/dist/tools/helpers/refresh-apply.js +460 -0
- package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
- package/dist/tools/helpers/refresh-inventory.js +631 -0
- package/dist/tools/helpers/rule-runner.js +3 -1
- package/dist/tools/helpers/scan-cache.d.ts +117 -5
- package/dist/tools/helpers/scan-cache.js +179 -6
- package/dist/tools/helpers/scan-engine.d.ts +43 -6
- package/dist/tools/helpers/scan-engine.js +141 -22
- package/dist/tools/helpers/scan-plan.js +16 -2
- package/dist/tools/helpers/source-map-loader.d.ts +55 -0
- package/dist/tools/helpers/source-map-loader.js +226 -0
- package/dist/tools/helpers/template-check.d.ts +76 -0
- package/dist/tools/helpers/template-check.js +158 -0
- package/dist/tools/helpers/tool-cache.d.ts +7 -2
- package/dist/tools/helpers/tool-cache.js +9 -3
- package/dist/tools/helpers/tool-context.d.ts +18 -0
- package/dist/tools/helpers/tool-context.js +29 -0
- package/dist/tools/helpers/transform-safety.d.ts +151 -1
- package/dist/tools/helpers/transform-safety.js +357 -4
- package/dist/tools/inspect-form-group.js +5 -0
- package/dist/tools/inspect-i18n.d.ts +1 -1
- package/dist/tools/inspect-template.js +8 -2
- package/dist/tools/learn-patterns.d.ts +43 -28
- package/dist/tools/learn-patterns.js +83 -161
- package/dist/tools/list-imports.d.ts +1 -1
- package/dist/tools/orchestrate-migration.d.ts +19 -1
- package/dist/tools/orchestrate-migration.js +52 -10
- package/dist/tools/parse-stack-trace.d.ts +48 -1
- package/dist/tools/parse-stack-trace.js +108 -9
- package/dist/tools/plan-migration.js +22 -10
- package/dist/tools/refresh-state.d.ts +378 -0
- package/dist/tools/refresh-state.js +370 -0
- package/dist/tools/resolve-type.js +10 -3
- package/dist/tools/review-feedback.d.ts +42 -7
- package/dist/tools/review-feedback.js +24 -17
- package/dist/tools/rollback-changes.d.ts +5 -0
- package/dist/tools/rollback-changes.js +7 -2
- package/dist/tools/run-angular-cli.js +36 -22
- package/dist/tools/run-build.d.ts +33 -28
- package/dist/tools/run-build.js +136 -438
- package/dist/tools/run-schematic.d.ts +8 -2
- package/dist/tools/run-schematic.js +80 -50
- package/dist/tools/scan-all.d.ts +37 -15
- package/dist/tools/scan-all.js +76 -115
- package/dist/tools/scan-angular.d.ts +33 -14
- package/dist/tools/scan-angular.js +77 -94
- package/dist/tools/scan-architecture.d.ts +37 -12
- package/dist/tools/scan-architecture.js +220 -139
- package/dist/tools/scan-solid.d.ts +33 -14
- package/dist/tools/scan-solid.js +80 -91
- package/dist/tools/search-codebase.d.ts +6 -1
- package/dist/tools/search-codebase.js +13 -7
- package/dist/tools/suggest-improvements.d.ts +34 -3
- package/dist/tools/suggest-improvements.js +34 -9
- package/dist/tools/trace-output-flow.js +3 -2
- package/dist/tools/transform-code-batch.d.ts +9 -9
- package/dist/tools/transform-code.d.ts +161 -12
- package/dist/tools/transform-code.js +715 -206
- package/dist/tools/validate-before-transform.js +2 -1
- package/dist/tools/validate-project-compatibility.d.ts +28 -55
- package/dist/tools/validate-project-compatibility.js +33 -225
- package/dist/tools/validate-transformation.d.ts +40 -26
- package/dist/tools/validate-transformation.js +115 -294
- package/dist/tools/verify-citations.js +8 -2
- package/dist/types.d.ts +9 -9
- package/dist/utils/format-tool-response.d.ts +3 -1
- package/dist/utils/format-tool-response.js +8 -3
- package/package.json +14 -13
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inventory of the state the platform keeps in a target project (refresh-state, report mode): scan and kernel
|
|
3
|
+
* caches, legacy cache layouts, health snapshot, pattern knowledge, transform backups, git snapshot refs, feedback
|
|
4
|
+
* sessions and the NGM-CACHE block. Reads only; never follows a symbolic link.
|
|
5
|
+
*/
|
|
6
|
+
import { execFileSync } from 'node:child_process';
|
|
7
|
+
import { closeSync, existsSync, lstatSync, openSync, readFileSync, readSync, readdirSync, realpathSync, } from 'node:fs';
|
|
8
|
+
import { basename, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
9
|
+
import { gunzipSync } from 'node:zlib';
|
|
10
|
+
import { readSidecar, sameMarks, scanFeedbackSessions } from './feedback-sidecar.js';
|
|
11
|
+
import { SCAN_CACHE_LAYOUTS } from './scan-cache.js';
|
|
12
|
+
/** Platform cache folder in the project root. */
|
|
13
|
+
export const CACHE_DIR = '.angular-modernizer-cache';
|
|
14
|
+
/** Transform backup folder in the project root. */
|
|
15
|
+
export const BACKUP_DIR = '.angular-modernizer-backups';
|
|
16
|
+
/** Feedback session folder in the project root. */
|
|
17
|
+
export const FEEDBACK_DIR = join('.claude-feedback', 'sessions');
|
|
18
|
+
/** Folder of the deprecated CacheCoordinator (no writer left). */
|
|
19
|
+
export const LEGACY_STORE_DIR = join('.angular-modernizer', 'cache');
|
|
20
|
+
/** Ref namespace of the git snapshots transform-code keeps (core `SNAPSHOT_REF_PREFIX`). */
|
|
21
|
+
export const SNAPSHOT_REFS = 'refs/angular-modernizer/snapshots/';
|
|
22
|
+
/** Age after which a scan cache entry is no longer used (core CacheManager `maxAge`). */
|
|
23
|
+
export const CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
24
|
+
/** Default retention of backup groups and snapshot refs in days. */
|
|
25
|
+
export const DEFAULT_RETENTION_DAYS = 30;
|
|
26
|
+
/** Default number of newest backup groups that are never proposed. */
|
|
27
|
+
export const DEFAULT_KEEP_NEWEST = 5;
|
|
28
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
29
|
+
/** {@link GitRunner} on the real git binary; `undefined` when git fails or is missing. */
|
|
30
|
+
export const runGit = (cwd, args) => {
|
|
31
|
+
try {
|
|
32
|
+
return execFileSync('git', args, {
|
|
33
|
+
cwd,
|
|
34
|
+
encoding: 'utf8',
|
|
35
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
36
|
+
windowsHide: true,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/** Collects the platform state of `projectRoot`; changes nothing. */
|
|
44
|
+
export function inventoryPlatformState(projectRoot, options = {}) {
|
|
45
|
+
const root = realpathSync(projectRoot);
|
|
46
|
+
const now = (options.now ?? Date.now)();
|
|
47
|
+
const ctx = {
|
|
48
|
+
root,
|
|
49
|
+
now,
|
|
50
|
+
retentionDays: options.retentionDays ?? DEFAULT_RETENTION_DAYS,
|
|
51
|
+
// The newest group is what rollback-changes restores: never listed
|
|
52
|
+
keepNewest: Math.max(1, options.keepNewest ?? DEFAULT_KEEP_NEWEST),
|
|
53
|
+
git: options.git ?? runGit,
|
|
54
|
+
tools: options.tools,
|
|
55
|
+
};
|
|
56
|
+
const scan = scanCaches(ctx);
|
|
57
|
+
const backups = backupGroups(ctx);
|
|
58
|
+
const parts = [
|
|
59
|
+
scan.cache,
|
|
60
|
+
scan.legacy,
|
|
61
|
+
singleFile(ctx, 'health-snapshot', join(CACHE_DIR, 'health', 'last-run.json'), healthCreatedAt),
|
|
62
|
+
singleFile(ctx, 'pattern-knowledge', join(CACHE_DIR, 'pattern-knowledge.json')),
|
|
63
|
+
backups.part,
|
|
64
|
+
snapshotRefs(ctx, backups.groups),
|
|
65
|
+
feedbackSessions(ctx),
|
|
66
|
+
ngmCache(ctx),
|
|
67
|
+
];
|
|
68
|
+
return {
|
|
69
|
+
projectRoot: root,
|
|
70
|
+
generatedAt: new Date(now).toISOString(),
|
|
71
|
+
retention: { days: ctx.retentionDays, keepNewest: ctx.keepNewest },
|
|
72
|
+
stores: parts.map((p) => p.report),
|
|
73
|
+
items: parts.flatMap((p) => [...p.items].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0)),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function rel(ctx, absolute) {
|
|
77
|
+
return relative(ctx.root, absolute).split(sep).join('/');
|
|
78
|
+
}
|
|
79
|
+
function ageDays(ctx, timeMs) {
|
|
80
|
+
return Math.max(0, Math.floor((ctx.now - timeMs) / DAY_MS));
|
|
81
|
+
}
|
|
82
|
+
/** lstat that never throws; symbolic links are reported as such and not followed. */
|
|
83
|
+
function stat(path) {
|
|
84
|
+
try {
|
|
85
|
+
return lstatSync(path);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function list(dir) {
|
|
92
|
+
try {
|
|
93
|
+
return readdirSync(dir).sort();
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** Size and newest mtime of a folder tree, without following links. */
|
|
100
|
+
function treeSize(dir) {
|
|
101
|
+
let bytes = 0;
|
|
102
|
+
let newest = 0;
|
|
103
|
+
let links = 0;
|
|
104
|
+
for (const name of list(dir)) {
|
|
105
|
+
const path = join(dir, name);
|
|
106
|
+
const s = stat(path);
|
|
107
|
+
if (s === undefined) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (s.isSymbolicLink()) {
|
|
111
|
+
links++;
|
|
112
|
+
}
|
|
113
|
+
else if (s.isDirectory()) {
|
|
114
|
+
const sub = treeSize(path);
|
|
115
|
+
bytes += sub.bytes;
|
|
116
|
+
newest = Math.max(newest, sub.newest);
|
|
117
|
+
links += sub.links;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
bytes += s.size;
|
|
121
|
+
newest = Math.max(newest, s.mtimeMs);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { bytes, newest, links };
|
|
125
|
+
}
|
|
126
|
+
function report(store, items, extra = {}) {
|
|
127
|
+
return {
|
|
128
|
+
store,
|
|
129
|
+
present: false,
|
|
130
|
+
entries: 0,
|
|
131
|
+
bytes: 0,
|
|
132
|
+
listed: items.length,
|
|
133
|
+
listedBytes: items.reduce((sum, i) => sum + i.bytes, 0),
|
|
134
|
+
...extra,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function withAges(r, ages) {
|
|
138
|
+
if (ages.length === 0) {
|
|
139
|
+
return r;
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
...r,
|
|
143
|
+
newestAgeDays: Math.min(...ages),
|
|
144
|
+
oldestAgeDays: Math.max(...ages),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Reads the metadata of a CacheManager entry (base64 gzip JSON, or plain JSON without compression). */
|
|
148
|
+
function readCacheMetadata(path) {
|
|
149
|
+
try {
|
|
150
|
+
const text = readFileSync(path, 'utf8');
|
|
151
|
+
let json;
|
|
152
|
+
try {
|
|
153
|
+
json = gunzipSync(Buffer.from(text, 'base64')).toString('utf8');
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
json = text;
|
|
157
|
+
}
|
|
158
|
+
const parsed = JSON.parse(json);
|
|
159
|
+
return parsed.metadata;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** Scan, kernel and other CacheManager caches under `.angular-modernizer-cache/<tool>/(ast|analysis)`. */
|
|
166
|
+
function scanCaches(ctx) {
|
|
167
|
+
const base = join(ctx.root, CACHE_DIR);
|
|
168
|
+
const cacheItems = [];
|
|
169
|
+
const legacyItems = [];
|
|
170
|
+
const ages = [];
|
|
171
|
+
let entries = 0;
|
|
172
|
+
let bytes = 0;
|
|
173
|
+
let links = 0;
|
|
174
|
+
const typeDirs = ['ast', 'analysis'];
|
|
175
|
+
const toolDirs = [
|
|
176
|
+
base,
|
|
177
|
+
...list(base)
|
|
178
|
+
.map((n) => join(base, n))
|
|
179
|
+
.filter((p) => stat(p)?.isDirectory() === true),
|
|
180
|
+
];
|
|
181
|
+
for (const toolDir of toolDirs) {
|
|
182
|
+
// Scan cache folders have a layout version; kernel caches (the base folder) do not
|
|
183
|
+
const layout = toolDir === base ? undefined : SCAN_CACHE_LAYOUTS[basename(toolDir)];
|
|
184
|
+
// Former layout <cacheDir>/YYYY/MM/DD/(ast|analysis)/ (replaced 2026-10, bfd5f91c): looked up by the current
|
|
185
|
+
// date only, so nothing reads these folders any more
|
|
186
|
+
for (const name of list(toolDir)) {
|
|
187
|
+
const path = join(toolDir, name);
|
|
188
|
+
if (!/^\d{4}$/.test(name) || stat(path)?.isDirectory() !== true) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const tree = treeSize(path);
|
|
192
|
+
legacyItems.push({
|
|
193
|
+
store: 'legacy-cache',
|
|
194
|
+
reason: 'legacy-layout',
|
|
195
|
+
action: 'remove',
|
|
196
|
+
path: rel(ctx, path),
|
|
197
|
+
bytes: tree.bytes,
|
|
198
|
+
ageDays: tree.newest > 0 ? ageDays(ctx, tree.newest) : undefined,
|
|
199
|
+
detail: 'date folder of the former YYYY/MM/DD cache layout, never read',
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
for (const type of typeDirs) {
|
|
203
|
+
const dir = join(toolDir, type);
|
|
204
|
+
if (stat(dir)?.isDirectory() !== true) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
for (const name of list(dir)) {
|
|
208
|
+
const path = join(dir, name);
|
|
209
|
+
const s = stat(path);
|
|
210
|
+
if (s === undefined) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (s.isSymbolicLink()) {
|
|
214
|
+
links++;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (s.isDirectory()) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (!name.endsWith('.json')) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
entries++;
|
|
224
|
+
bytes += s.size;
|
|
225
|
+
const item = cacheEntryItem(ctx, path, s, type === 'analysis' ? layout : undefined);
|
|
226
|
+
ages.push(item.age);
|
|
227
|
+
if (item.listed !== undefined) {
|
|
228
|
+
cacheItems.push(item.listed);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const legacyStore = join(ctx.root, LEGACY_STORE_DIR);
|
|
234
|
+
if (stat(legacyStore)?.isDirectory() === true) {
|
|
235
|
+
const tree = treeSize(legacyStore);
|
|
236
|
+
legacyItems.push({
|
|
237
|
+
store: 'legacy-cache',
|
|
238
|
+
reason: 'legacy-store',
|
|
239
|
+
action: 'remove',
|
|
240
|
+
path: rel(ctx, legacyStore),
|
|
241
|
+
bytes: tree.bytes,
|
|
242
|
+
ageDays: tree.newest > 0 ? ageDays(ctx, tree.newest) : undefined,
|
|
243
|
+
detail: 'CacheCoordinator folder, no writer left',
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
const cache = withAges(report('scan-cache', cacheItems, {
|
|
247
|
+
present: entries > 0,
|
|
248
|
+
entries,
|
|
249
|
+
bytes,
|
|
250
|
+
note: links > 0 ? `${links} symbolic link(s) skipped` : undefined,
|
|
251
|
+
}), ages);
|
|
252
|
+
const legacy = report('legacy-cache', legacyItems, {
|
|
253
|
+
present: legacyItems.length > 0,
|
|
254
|
+
entries: legacyItems.length,
|
|
255
|
+
bytes: legacyItems.reduce((sum, i) => sum + i.bytes, 0),
|
|
256
|
+
});
|
|
257
|
+
return {
|
|
258
|
+
cache: { report: cache, items: cacheItems },
|
|
259
|
+
legacy: { report: legacy, items: legacyItems },
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* @param layout - Current layout version of the scan cache folder the entry
|
|
264
|
+
* is in; an entry of another layout is never read again (`outdated-layout`).
|
|
265
|
+
* Unset for kernel caches.
|
|
266
|
+
*/
|
|
267
|
+
function cacheEntryItem(ctx, path, s, layout) {
|
|
268
|
+
const metadata = readCacheMetadata(path);
|
|
269
|
+
const cachedAt = typeof metadata?.cachedAt === 'number' ? metadata.cachedAt : s.mtimeMs;
|
|
270
|
+
const age = ageDays(ctx, cachedAt);
|
|
271
|
+
const base = {
|
|
272
|
+
store: 'scan-cache',
|
|
273
|
+
action: 'remove',
|
|
274
|
+
path: rel(ctx, path),
|
|
275
|
+
bytes: s.size,
|
|
276
|
+
ageDays: age,
|
|
277
|
+
};
|
|
278
|
+
if (metadata === undefined || typeof metadata.filePath !== 'string') {
|
|
279
|
+
return {
|
|
280
|
+
age,
|
|
281
|
+
listed: {
|
|
282
|
+
...base,
|
|
283
|
+
reason: 'unreadable',
|
|
284
|
+
detail: 'no readable cache metadata',
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const source = isAbsolute(metadata.filePath)
|
|
289
|
+
? metadata.filePath
|
|
290
|
+
: resolve(ctx.root, metadata.filePath);
|
|
291
|
+
const shown = source.startsWith(ctx.root + sep) ? rel(ctx, source) : source;
|
|
292
|
+
if (!existsSync(source)) {
|
|
293
|
+
return {
|
|
294
|
+
age,
|
|
295
|
+
listed: {
|
|
296
|
+
...base,
|
|
297
|
+
reason: 'orphan',
|
|
298
|
+
detail: `${shown} no longer exists`,
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
// The version is `<layout>+<hash>`; the hash part (config, rules, scope,
|
|
303
|
+
// unresolved packages) belongs to the scan call and is not checked here
|
|
304
|
+
const entryLayout = typeof metadata.version === 'string' ? metadata.version.split('+')[0] : undefined;
|
|
305
|
+
if (layout !== undefined && entryLayout !== layout) {
|
|
306
|
+
return {
|
|
307
|
+
age,
|
|
308
|
+
listed: {
|
|
309
|
+
...base,
|
|
310
|
+
reason: 'outdated-layout',
|
|
311
|
+
detail: `${shown}; written with cache layout ${entryLayout ?? 'unknown'}, the scan reads ${layout}`,
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (ctx.now - cachedAt > CACHE_MAX_AGE_MS) {
|
|
316
|
+
return {
|
|
317
|
+
age,
|
|
318
|
+
listed: {
|
|
319
|
+
...base,
|
|
320
|
+
reason: 'expired',
|
|
321
|
+
detail: `${shown}; older than the 24 h cache limit, never read again`,
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return { age };
|
|
326
|
+
}
|
|
327
|
+
/** Reads `createdAt` from the first line of a health snapshot without loading the whole file. */
|
|
328
|
+
function healthCreatedAt(path) {
|
|
329
|
+
try {
|
|
330
|
+
const fd = openSync(path, 'r');
|
|
331
|
+
try {
|
|
332
|
+
const buffer = Buffer.alloc(64 * 1024);
|
|
333
|
+
const read = readSync(fd, buffer, 0, buffer.length, 0);
|
|
334
|
+
const match = /"createdAt"\s*:\s*"([^"]+)"/.exec(buffer.subarray(0, read).toString('utf8'));
|
|
335
|
+
const time = match?.[1] === undefined ? NaN : Date.parse(match[1]);
|
|
336
|
+
return Number.isNaN(time) ? undefined : time;
|
|
337
|
+
}
|
|
338
|
+
finally {
|
|
339
|
+
closeSync(fd);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/** A single-file store: reported, never listed. */
|
|
347
|
+
function singleFile(ctx, store, relativePath, createdAt) {
|
|
348
|
+
const path = join(ctx.root, relativePath);
|
|
349
|
+
const s = stat(path);
|
|
350
|
+
if (!s?.isFile()) {
|
|
351
|
+
return {
|
|
352
|
+
report: report(store, [], {
|
|
353
|
+
note: s?.isSymbolicLink() === true ? 'symbolic link skipped' : undefined,
|
|
354
|
+
}),
|
|
355
|
+
items: [],
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
const time = createdAt?.(path) ?? s.mtimeMs;
|
|
359
|
+
return {
|
|
360
|
+
report: withAges(report(store, [], { present: true, entries: 1, bytes: s.size }), [ageDays(ctx, time)]),
|
|
361
|
+
items: [],
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Files of each backup group in `.angular-modernizer-backups` of `projectRoot`, by group id (`group`, else
|
|
366
|
+
* `backupId`, of the metadata), as names in that folder. Grouped exactly like the inventory groups them.
|
|
367
|
+
*/
|
|
368
|
+
export function backupGroupMembers(projectRoot) {
|
|
369
|
+
const groups = readBackupGroups(join(projectRoot, BACKUP_DIR), list(join(projectRoot, BACKUP_DIR)));
|
|
370
|
+
return new Map([...groups.values()].map((g) => [g.id, g.members]));
|
|
371
|
+
}
|
|
372
|
+
/** Groups of the `.backup.json` files in `dir`; symbolic links and unreadable metadata are skipped. */
|
|
373
|
+
function readBackupGroups(dir, names) {
|
|
374
|
+
const groups = new Map();
|
|
375
|
+
for (const name of names) {
|
|
376
|
+
if (!name.endsWith('.backup.json')) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
const path = join(dir, name);
|
|
380
|
+
const s = stat(path);
|
|
381
|
+
if (s?.isFile() !== true) {
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
let metadata;
|
|
385
|
+
try {
|
|
386
|
+
metadata = JSON.parse(readFileSync(path, 'utf8'));
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const backupName = name.slice(0, -'.json'.length);
|
|
392
|
+
const id = typeof metadata.group === 'string'
|
|
393
|
+
? metadata.group
|
|
394
|
+
: typeof metadata.backupId === 'string'
|
|
395
|
+
? metadata.backupId
|
|
396
|
+
: backupName;
|
|
397
|
+
const time = typeof metadata.timestamp === 'string'
|
|
398
|
+
? Date.parse(metadata.timestamp)
|
|
399
|
+
: s.mtimeMs;
|
|
400
|
+
const backupStat = stat(join(dir, backupName));
|
|
401
|
+
const group = groups.get(id) ?? {
|
|
402
|
+
id,
|
|
403
|
+
newest: 0,
|
|
404
|
+
files: 0,
|
|
405
|
+
bytes: 0,
|
|
406
|
+
members: [],
|
|
407
|
+
};
|
|
408
|
+
group.newest = Math.max(group.newest, Number.isNaN(time) ? s.mtimeMs : time);
|
|
409
|
+
group.files++;
|
|
410
|
+
group.bytes += s.size + (backupStat?.size ?? 0);
|
|
411
|
+
group.members.push(name);
|
|
412
|
+
if (backupStat !== undefined) {
|
|
413
|
+
group.members.push(backupName);
|
|
414
|
+
}
|
|
415
|
+
groups.set(id, group);
|
|
416
|
+
}
|
|
417
|
+
return groups;
|
|
418
|
+
}
|
|
419
|
+
/** Backup groups in `.angular-modernizer-backups`, newest first. */
|
|
420
|
+
function backupGroups(ctx) {
|
|
421
|
+
const dir = join(ctx.root, BACKUP_DIR);
|
|
422
|
+
const items = [];
|
|
423
|
+
const names = list(dir);
|
|
424
|
+
const groups = readBackupGroups(dir, names);
|
|
425
|
+
for (const name of names) {
|
|
426
|
+
// Metadata in any form (also unreadable or a link) keeps the backup out of the list
|
|
427
|
+
if (!name.endsWith('.backup') ||
|
|
428
|
+
stat(join(dir, `${name}.json`)) !== undefined) {
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
const s = stat(join(dir, name));
|
|
432
|
+
if (s?.isFile() !== true) {
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
items.push({
|
|
436
|
+
store: 'backups',
|
|
437
|
+
reason: 'missing-metadata',
|
|
438
|
+
action: 'remove',
|
|
439
|
+
path: `${BACKUP_DIR}/${name}`,
|
|
440
|
+
bytes: s.size,
|
|
441
|
+
ageDays: ageDays(ctx, s.mtimeMs),
|
|
442
|
+
detail: 'backup file without its .json metadata; rollback-changes cannot use it',
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
const ordered = [...groups.values()].sort((a, b) => b.newest - a.newest);
|
|
446
|
+
const result = new Map();
|
|
447
|
+
ordered.forEach((group, index) => {
|
|
448
|
+
const age = ageDays(ctx, group.newest);
|
|
449
|
+
const listed = index >= ctx.keepNewest && age > ctx.retentionDays;
|
|
450
|
+
result.set(group.id, { listed, group });
|
|
451
|
+
if (listed) {
|
|
452
|
+
items.push({
|
|
453
|
+
store: 'backups',
|
|
454
|
+
reason: 'retention',
|
|
455
|
+
action: 'remove',
|
|
456
|
+
path: group.id,
|
|
457
|
+
bytes: group.bytes,
|
|
458
|
+
ageDays: age,
|
|
459
|
+
detail: `${group.files} backup(s), older than ${ctx.retentionDays} days and not among the newest ${ctx.keepNewest} groups`,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
const reportOf = withAges(report('backups', items, {
|
|
464
|
+
present: groups.size > 0 || items.length > 0,
|
|
465
|
+
entries: groups.size,
|
|
466
|
+
bytes: ordered.reduce((sum, g) => sum + g.bytes, 0),
|
|
467
|
+
}), ordered.map((g) => ageDays(ctx, g.newest)));
|
|
468
|
+
return { part: { report: reportOf, items }, groups: result };
|
|
469
|
+
}
|
|
470
|
+
/** Snapshot refs of transform-code, matched to their backup groups. */
|
|
471
|
+
function snapshotRefs(ctx, groups) {
|
|
472
|
+
if (ctx.git(ctx.root, ['rev-parse', '--is-inside-work-tree'])?.trim() !== 'true') {
|
|
473
|
+
return {
|
|
474
|
+
report: report('snapshot-refs', [], { note: 'no git repository' }),
|
|
475
|
+
items: [],
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
const out = ctx.git(ctx.root, [
|
|
479
|
+
'for-each-ref',
|
|
480
|
+
'--format=%(refname) %(creatordate:unix)',
|
|
481
|
+
SNAPSHOT_REFS,
|
|
482
|
+
]) ?? '';
|
|
483
|
+
const items = [];
|
|
484
|
+
const ages = [];
|
|
485
|
+
let entries = 0;
|
|
486
|
+
for (const line of out.split('\n')) {
|
|
487
|
+
const [ref, unix] = line.trim().split(' ');
|
|
488
|
+
if (ref === undefined || ref === '' || !ref.startsWith(SNAPSHOT_REFS)) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
entries++;
|
|
492
|
+
const age = ageDays(ctx, Number(unix) * 1000);
|
|
493
|
+
ages.push(age);
|
|
494
|
+
const group = groups.get(ref.slice(SNAPSHOT_REFS.length));
|
|
495
|
+
if (group?.listed === true) {
|
|
496
|
+
items.push({
|
|
497
|
+
store: 'snapshot-refs',
|
|
498
|
+
reason: 'retention',
|
|
499
|
+
action: 'remove',
|
|
500
|
+
path: ref,
|
|
501
|
+
bytes: 0,
|
|
502
|
+
ageDays: age,
|
|
503
|
+
detail: 'its backup group is listed for removal',
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
else if (group === undefined && age > ctx.retentionDays) {
|
|
507
|
+
items.push({
|
|
508
|
+
store: 'snapshot-refs',
|
|
509
|
+
reason: 'ref-without-backup',
|
|
510
|
+
action: 'remove',
|
|
511
|
+
path: ref,
|
|
512
|
+
bytes: 0,
|
|
513
|
+
ageDays: age,
|
|
514
|
+
detail: `no backup group left and older than ${ctx.retentionDays} days`,
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
report: withAges(report('snapshot-refs', items, { present: entries > 0, entries }), ages),
|
|
520
|
+
items,
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Feedback sessions: record counts, records that repeat an earlier one (same transformationId or feedbackId) and
|
|
525
|
+
* outdated records (feedback-catalog). A session file is listed only while the sidecar does not already hold
|
|
526
|
+
* exactly these marks for its current content.
|
|
527
|
+
*/
|
|
528
|
+
function feedbackSessions(ctx) {
|
|
529
|
+
const scans = scanFeedbackSessions(join(ctx.root, FEEDBACK_DIR), ctx.tools);
|
|
530
|
+
const { sidecar, problem } = readSidecar(ctx.root);
|
|
531
|
+
const items = [];
|
|
532
|
+
let records = 0;
|
|
533
|
+
let bytes = 0;
|
|
534
|
+
let marked = 0;
|
|
535
|
+
for (const scan of scans) {
|
|
536
|
+
records += scan.records;
|
|
537
|
+
bytes += scan.size;
|
|
538
|
+
const entry = sidecar?.sessions[scan.file];
|
|
539
|
+
if (entry !== undefined && entry.sha256 === scan.sha256 && sameMarks(entry.marks, scan.marks)) {
|
|
540
|
+
marked += Object.keys(scan.marks).length;
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
const path = rel(ctx, join(ctx.root, FEEDBACK_DIR, scan.file));
|
|
544
|
+
const age = ageDays(ctx, scan.mtimeMs);
|
|
545
|
+
if (scan.duplicates > 0) {
|
|
546
|
+
items.push({
|
|
547
|
+
store: 'feedback',
|
|
548
|
+
reason: 'duplicate-records',
|
|
549
|
+
action: 'mark',
|
|
550
|
+
path,
|
|
551
|
+
bytes: 0,
|
|
552
|
+
ageDays: age,
|
|
553
|
+
detail: `${scan.duplicates} of ${scan.records} record(s) repeat an earlier record`,
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
if (scan.outdated > 0) {
|
|
557
|
+
const reasons = new Map();
|
|
558
|
+
for (const mark of Object.values(scan.marks)) {
|
|
559
|
+
if (mark.reason !== 'duplicate') {
|
|
560
|
+
reasons.set(mark.reason, (reasons.get(mark.reason) ?? 0) + 1);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
items.push({
|
|
564
|
+
store: 'feedback',
|
|
565
|
+
reason: 'outdated-records',
|
|
566
|
+
action: 'mark',
|
|
567
|
+
path,
|
|
568
|
+
bytes: 0,
|
|
569
|
+
ageDays: age,
|
|
570
|
+
detail: `${scan.outdated} of ${scan.records} record(s) outdated (${[...reasons].map(([r, n]) => `${n} ${r}`).join(', ')})`,
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const notes = [];
|
|
575
|
+
if (marked > 0) {
|
|
576
|
+
notes.push(`${marked} record(s) already marked in the sidecar`);
|
|
577
|
+
}
|
|
578
|
+
if (problem !== undefined) {
|
|
579
|
+
notes.push(`sidecar unusable: ${problem}`);
|
|
580
|
+
}
|
|
581
|
+
if (ctx.tools === undefined && scans.length > 0) {
|
|
582
|
+
notes.push('tools not checked');
|
|
583
|
+
}
|
|
584
|
+
return {
|
|
585
|
+
report: withAges(report('feedback', items, {
|
|
586
|
+
present: scans.length > 0,
|
|
587
|
+
entries: records,
|
|
588
|
+
bytes,
|
|
589
|
+
...(notes.length === 0 ? {} : { note: notes.join('; ') }),
|
|
590
|
+
}), scans.map((scan) => ageDays(ctx, scan.mtimeMs))),
|
|
591
|
+
items,
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
/** NGM-CACHE block in `<root>/.claude/CLAUDE.md`, written by the health-check and init agents. */
|
|
595
|
+
function ngmCache(ctx) {
|
|
596
|
+
const path = join(ctx.root, '.claude', 'CLAUDE.md');
|
|
597
|
+
const s = stat(path);
|
|
598
|
+
if (s?.isFile() !== true) {
|
|
599
|
+
return { report: report('ngm-cache', []), items: [] };
|
|
600
|
+
}
|
|
601
|
+
const text = readFileSync(path, 'utf8');
|
|
602
|
+
if (!text.includes('<!-- NGM-CACHE -->')) {
|
|
603
|
+
return {
|
|
604
|
+
report: report('ngm-cache', [], {
|
|
605
|
+
note: '.claude/CLAUDE.md has no NGM-CACHE block',
|
|
606
|
+
}),
|
|
607
|
+
items: [],
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
const match = /<!-- Last updated: (\d{4}-\d{2}-\d{2}) -->/.exec(text);
|
|
611
|
+
const time = match?.[1] === undefined ? NaN : Date.parse(`${match[1]}T00:00:00Z`);
|
|
612
|
+
const age = Number.isNaN(time) ? undefined : ageDays(ctx, time);
|
|
613
|
+
const items = age === 0
|
|
614
|
+
? []
|
|
615
|
+
: [
|
|
616
|
+
{
|
|
617
|
+
store: 'ngm-cache',
|
|
618
|
+
reason: 'stale-date',
|
|
619
|
+
action: 'regenerate',
|
|
620
|
+
path: '.claude/CLAUDE.md',
|
|
621
|
+
bytes: 0,
|
|
622
|
+
ageDays: age,
|
|
623
|
+
detail: age === undefined
|
|
624
|
+
? 'NGM-CACHE block without a readable date'
|
|
625
|
+
: `NGM-CACHE last updated ${match?.[1]}; agents treat it as fresh only on the same day`,
|
|
626
|
+
},
|
|
627
|
+
];
|
|
628
|
+
const r = report('ngm-cache', items, { present: true, entries: 1 });
|
|
629
|
+
return { report: age === undefined ? r : withAges(r, [age]), items };
|
|
630
|
+
}
|
|
631
|
+
//# sourceMappingURL=refresh-inventory.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { applySuppressionComments } from '@angular-modernizer/core';
|
|
1
2
|
import { ContextFactory, } from '@angular-modernizer/plugin-system';
|
|
2
3
|
import { yieldIfCancellable } from './tool-context.js';
|
|
3
4
|
import { loadSourceFiles } from './load-source-files.js';
|
|
@@ -78,7 +79,8 @@ export async function runRulesOverFiles(options) {
|
|
|
78
79
|
config: options.config,
|
|
79
80
|
}));
|
|
80
81
|
timings.set(rule.id, (timings.get(rule.id) ?? 0) + Date.now() - ruleStart);
|
|
81
|
-
|
|
82
|
+
const kept = applySuppressionComments(results, rule.id, options.config, project);
|
|
83
|
+
for (const result of kept) {
|
|
82
84
|
fileViolations.push(toViolation(rule, result));
|
|
83
85
|
}
|
|
84
86
|
}
|