@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,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sidecar of the feedback sessions: `<projectRoot>/.claude-feedback/index/consolidated.json` marks records that
|
|
3
|
+
* repeat an earlier one (same `transformationId` / `feedbackId`) or are outdated (see `feedback-catalog.ts`). The
|
|
4
|
+
* session files are never changed; only refresh-state apply (part `feedback`) writes the sidecar, and
|
|
5
|
+
* review-feedback, suggest-improvements and analyze-parser-performance skip what it marks.
|
|
6
|
+
*/
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import { copyFileSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import { PACKAGE_VERSION } from '../../server/package-version.js';
|
|
11
|
+
import { outdatedReason, } from './feedback-catalog.js';
|
|
12
|
+
/** Format of the sidecar file. */
|
|
13
|
+
export const SIDECAR_FORMAT = 'ngm-feedback-consolidated-v1';
|
|
14
|
+
/** Feedback folder in the project root. */
|
|
15
|
+
export const FEEDBACK_ROOT_DIR = '.claude-feedback';
|
|
16
|
+
/** Sidecar folder below the feedback folder. */
|
|
17
|
+
export const FEEDBACK_INDEX_DIR = 'index';
|
|
18
|
+
/** Sidecar file name. */
|
|
19
|
+
export const SIDECAR_FILE = 'consolidated.json';
|
|
20
|
+
/** The sidecar before the last apply. */
|
|
21
|
+
export const PREVIOUS_SIDECAR_FILE = 'consolidated.prev.json';
|
|
22
|
+
/** Key of a raw session record: `t:<transformationId>`, `f:<feedbackId>`, or `undefined` (header). */
|
|
23
|
+
export function recordKey(record) {
|
|
24
|
+
if (typeof record.transformationId === 'string') {
|
|
25
|
+
return `t:${record.transformationId}`;
|
|
26
|
+
}
|
|
27
|
+
return typeof record.feedbackId === 'string' ? `f:${record.feedbackId}` : undefined;
|
|
28
|
+
}
|
|
29
|
+
function lstat(path) {
|
|
30
|
+
try {
|
|
31
|
+
return lstatSync(path);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function sha256(text) {
|
|
38
|
+
return createHash('sha256').update(text).digest('hex');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Reads every `.jsonl` file of a sessions folder in name order and marks each record that repeats a key of an
|
|
42
|
+
* earlier one (file order, then line order: the first stays) and each outdated record. Symbolic links are skipped.
|
|
43
|
+
* `tools` undefined leaves the tools unchecked.
|
|
44
|
+
*/
|
|
45
|
+
export function scanFeedbackSessions(sessionsDir, tools) {
|
|
46
|
+
let names;
|
|
47
|
+
try {
|
|
48
|
+
names = readdirSync(sessionsDir).sort();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
const seen = new Set();
|
|
54
|
+
const scans = [];
|
|
55
|
+
for (const file of names) {
|
|
56
|
+
if (!file.endsWith('.jsonl')) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const path = join(sessionsDir, file);
|
|
60
|
+
const s = lstat(path);
|
|
61
|
+
if (s?.isFile() !== true) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const bytes = readFileSync(path);
|
|
65
|
+
const scan = {
|
|
66
|
+
file,
|
|
67
|
+
sha256: sha256(bytes),
|
|
68
|
+
size: s.size,
|
|
69
|
+
mtimeMs: s.mtimeMs,
|
|
70
|
+
records: 0,
|
|
71
|
+
marks: {},
|
|
72
|
+
duplicates: 0,
|
|
73
|
+
outdated: 0,
|
|
74
|
+
};
|
|
75
|
+
for (const line of bytes.toString('utf8').split('\n')) {
|
|
76
|
+
if (line.trim() === '') {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
let record;
|
|
80
|
+
try {
|
|
81
|
+
record = JSON.parse(line);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const key = recordKey(record);
|
|
87
|
+
if (key === undefined) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
scan.records++;
|
|
91
|
+
const outdated = outdatedReason(record, tools);
|
|
92
|
+
if (outdated !== undefined) {
|
|
93
|
+
scan.outdated++;
|
|
94
|
+
scan.marks[key] = outdated;
|
|
95
|
+
}
|
|
96
|
+
if (seen.has(key)) {
|
|
97
|
+
scan.duplicates++;
|
|
98
|
+
scan.marks[key] ??= {
|
|
99
|
+
reason: 'duplicate',
|
|
100
|
+
detail: `repeats record ${key}`,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
seen.add(key);
|
|
104
|
+
}
|
|
105
|
+
scans.push(scan);
|
|
106
|
+
}
|
|
107
|
+
return scans;
|
|
108
|
+
}
|
|
109
|
+
/** Reads `consolidated.json` of a project; never throws. */
|
|
110
|
+
export function readSidecar(projectRoot) {
|
|
111
|
+
const path = join(projectRoot, FEEDBACK_ROOT_DIR, FEEDBACK_INDEX_DIR, SIDECAR_FILE);
|
|
112
|
+
const s = lstat(path);
|
|
113
|
+
if (s === undefined) {
|
|
114
|
+
return {};
|
|
115
|
+
}
|
|
116
|
+
if (!s.isFile()) {
|
|
117
|
+
return { problem: `${SIDECAR_FILE} is not a regular file` };
|
|
118
|
+
}
|
|
119
|
+
let data;
|
|
120
|
+
try {
|
|
121
|
+
data = JSON.parse(readFileSync(path, 'utf8'));
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return {
|
|
125
|
+
problem: `${SIDECAR_FILE} is not valid JSON (${error instanceof Error ? error.message : String(error)})`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (!isObject(data) || data['format'] !== SIDECAR_FORMAT || !isObject(data['sessions'])) {
|
|
129
|
+
return { problem: `${SIDECAR_FILE} has no ${SIDECAR_FORMAT} content` };
|
|
130
|
+
}
|
|
131
|
+
for (const session of Object.values(data['sessions'])) {
|
|
132
|
+
if (!isObject(session) || typeof session['sha256'] !== 'string' || !isObject(session['marks'])) {
|
|
133
|
+
return { problem: `${SIDECAR_FILE} has a malformed session entry` };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return { sidecar: data };
|
|
137
|
+
}
|
|
138
|
+
function isObject(value) {
|
|
139
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
140
|
+
}
|
|
141
|
+
/** Whether the marks of a sidecar entry equal `marks` (key order ignored). */
|
|
142
|
+
export function sameMarks(a, b) {
|
|
143
|
+
const keys = Object.keys(a);
|
|
144
|
+
if (keys.length !== Object.keys(b).length) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return keys.every((key) => a[key]?.reason === b[key]?.reason && a[key]?.detail === b[key]?.detail);
|
|
148
|
+
}
|
|
149
|
+
/** Why the sidecar cannot be written, or `undefined`. Folders on the way must be real folders at their own path. */
|
|
150
|
+
function sidecarFolderProblem(projectRoot) {
|
|
151
|
+
const feedback = join(projectRoot, FEEDBACK_ROOT_DIR);
|
|
152
|
+
const index = join(feedback, FEEDBACK_INDEX_DIR);
|
|
153
|
+
for (const dir of [feedback, index]) {
|
|
154
|
+
const s = lstat(dir);
|
|
155
|
+
if (s === undefined) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (!s.isDirectory()) {
|
|
159
|
+
return `${dir} is not a real folder`;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
if (realpathSync(dir) !== dir) {
|
|
163
|
+
return `${dir} lies behind a symbolic link`;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return `${dir} cannot be resolved`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const name of [SIDECAR_FILE, PREVIOUS_SIDECAR_FILE]) {
|
|
171
|
+
const s = lstat(join(index, name));
|
|
172
|
+
if (s !== undefined && !s.isFile()) {
|
|
173
|
+
return `${join(index, name)} is not a regular file`;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Writes the marks of the session files in `planned` (file name -> SHA-256 at report time) into the sidecar. A file
|
|
180
|
+
* is marked only while it still has that hash; entries of other files stay while their file is unchanged and are
|
|
181
|
+
* dropped otherwise. The previous sidecar is kept as {@link PREVIOUS_SIDECAR_FILE}; the new one replaces it through
|
|
182
|
+
* a rename. Session files are only read.
|
|
183
|
+
*/
|
|
184
|
+
export function writeFeedbackMarks(projectRoot, sessionsDir, planned, tools, planId, now) {
|
|
185
|
+
const problem = sidecarFolderProblem(projectRoot);
|
|
186
|
+
if (problem !== undefined) {
|
|
187
|
+
return { error: problem, outsideFolder: true };
|
|
188
|
+
}
|
|
189
|
+
const scans = new Map(scanFeedbackSessions(sessionsDir, tools).map((scan) => [scan.file, scan]));
|
|
190
|
+
const previous = readSidecar(projectRoot).sidecar;
|
|
191
|
+
const sessions = {};
|
|
192
|
+
for (const [file, entry] of Object.entries(previous?.sessions ?? {})) {
|
|
193
|
+
if (!planned.has(file) && scans.get(file)?.sha256 === entry.sha256) {
|
|
194
|
+
sessions[file] = entry;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const result = { marked: [], changed: [], missing: [] };
|
|
198
|
+
for (const [file, hash] of planned) {
|
|
199
|
+
const scan = scans.get(file);
|
|
200
|
+
if (scan === undefined) {
|
|
201
|
+
result.missing.push(file);
|
|
202
|
+
}
|
|
203
|
+
else if (scan.sha256 !== hash) {
|
|
204
|
+
result.changed.push(file);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
sessions[file] = { sha256: scan.sha256, marks: scan.marks };
|
|
208
|
+
result.marked.push({ file, records: Object.keys(scan.marks).length });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (result.marked.length === 0) {
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
const sidecar = {
|
|
215
|
+
format: SIDECAR_FORMAT,
|
|
216
|
+
writtenAt: new Date(now).toISOString(),
|
|
217
|
+
planId,
|
|
218
|
+
version: PACKAGE_VERSION,
|
|
219
|
+
sessions,
|
|
220
|
+
};
|
|
221
|
+
const index = join(projectRoot, FEEDBACK_ROOT_DIR, FEEDBACK_INDEX_DIR);
|
|
222
|
+
const target = join(index, SIDECAR_FILE);
|
|
223
|
+
const temp = join(index, `${SIDECAR_FILE}.${process.pid}.tmp`);
|
|
224
|
+
try {
|
|
225
|
+
mkdirSync(index, { recursive: true });
|
|
226
|
+
writeFileSync(temp, JSON.stringify(sidecar, null, 2) + '\n', { encoding: 'utf8', flag: 'wx' });
|
|
227
|
+
if (lstat(target) !== undefined) {
|
|
228
|
+
copyFileSync(target, join(index, PREVIOUS_SIDECAR_FILE));
|
|
229
|
+
}
|
|
230
|
+
renameSync(temp, target);
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
// Only the temp file this call created goes; the sidecar stays as it was
|
|
234
|
+
if (lstat(temp)?.isFile() === true) {
|
|
235
|
+
rmSync(temp);
|
|
236
|
+
}
|
|
237
|
+
return { error: error instanceof Error ? error.message : String(error), outsideFolder: false };
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
/** Reads the marks of the project's sidecar for the readers; an unusable sidecar marks nothing. */
|
|
242
|
+
export function loadMarkView(projectRoot) {
|
|
243
|
+
const { sidecar, problem } = readSidecar(projectRoot);
|
|
244
|
+
const view = { outdated: new Map(), duplicateKeys: new Set(), warnings: [] };
|
|
245
|
+
if (problem !== undefined) {
|
|
246
|
+
view.warnings.push(`Feedback sidecar ignored, nothing skipped: ${problem}. Run refresh-state (report, then apply with part 'feedback') to write it again.`);
|
|
247
|
+
return view;
|
|
248
|
+
}
|
|
249
|
+
if (sidecar === undefined) {
|
|
250
|
+
return view;
|
|
251
|
+
}
|
|
252
|
+
const sessionsDir = join(projectRoot, FEEDBACK_ROOT_DIR, 'sessions');
|
|
253
|
+
const changed = [];
|
|
254
|
+
for (const [file, entry] of Object.entries(sidecar.sessions)) {
|
|
255
|
+
for (const [key, mark] of Object.entries(entry.marks)) {
|
|
256
|
+
if (mark.reason === 'duplicate') {
|
|
257
|
+
view.duplicateKeys.add(key);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
view.outdated.set(key, mark.reason);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
let current;
|
|
264
|
+
try {
|
|
265
|
+
current = sha256(readFileSync(join(sessionsDir, file)));
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
current = undefined;
|
|
269
|
+
}
|
|
270
|
+
if (current !== entry.sha256) {
|
|
271
|
+
changed.push(file);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (changed.length > 0) {
|
|
275
|
+
view.warnings.push(`Feedback sidecar is older than ${changed.length} session file(s) (${changed.slice(0, 5).join(', ')}${changed.length > 5 ? ', ...' : ''}): their marks still apply by record id; run refresh-state to mark the records added since.`);
|
|
276
|
+
}
|
|
277
|
+
return view;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Decides per record whether a reader skips it. Feed the records session by session in the order of
|
|
281
|
+
* {@link sessionFileOrder} and in file order within a session, so the first record of a duplicate key is the one the
|
|
282
|
+
* sidecar keeps.
|
|
283
|
+
*/
|
|
284
|
+
export class MarkFilter {
|
|
285
|
+
view;
|
|
286
|
+
includeOutdated;
|
|
287
|
+
seen = new Set();
|
|
288
|
+
/** What was skipped so far. */
|
|
289
|
+
skipped = { total: 0, byReason: {} };
|
|
290
|
+
/**
|
|
291
|
+
* @param view marks of the sidecar
|
|
292
|
+
* @param includeOutdated true skips nothing (the view before the sidecar)
|
|
293
|
+
*/
|
|
294
|
+
constructor(view, includeOutdated) {
|
|
295
|
+
this.view = view;
|
|
296
|
+
this.includeOutdated = includeOutdated;
|
|
297
|
+
}
|
|
298
|
+
/** Whether to keep the record with this key; counts it when not. */
|
|
299
|
+
keep(key) {
|
|
300
|
+
if (this.includeOutdated || key === undefined) {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
let reason = this.view.outdated.get(key);
|
|
304
|
+
if (reason === undefined && this.view.duplicateKeys.has(key)) {
|
|
305
|
+
reason = this.seen.has(key) ? 'duplicate' : undefined;
|
|
306
|
+
this.seen.add(key);
|
|
307
|
+
}
|
|
308
|
+
if (reason === undefined) {
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
this.skipped.total++;
|
|
312
|
+
this.skipped.byReason[reason] = (this.skipped.byReason[reason] ?? 0) + 1;
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/** Session ids in the order the sidecar reads their files (by file name). */
|
|
317
|
+
export function sessionFileOrder(sessionIds) {
|
|
318
|
+
return [...sessionIds].sort((a, b) => {
|
|
319
|
+
const fa = `${a}.jsonl`;
|
|
320
|
+
const fb = `${b}.jsonl`;
|
|
321
|
+
return fa < fb ? -1 : fa > fb ? 1 : 0;
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Drops the records the project's sidecar marks from loaded sessions (nothing with `includeOutdated`). Keys come
|
|
326
|
+
* from the stored ids (`transformationId`, `feedbackId`), so old analysis records stored as transformation records
|
|
327
|
+
* keep their `t:` key.
|
|
328
|
+
*/
|
|
329
|
+
export function skipMarkedRecords(projectRoot, sessions, includeOutdated) {
|
|
330
|
+
const view = includeOutdated
|
|
331
|
+
? { outdated: new Map(), duplicateKeys: new Set(), warnings: [] }
|
|
332
|
+
: loadMarkView(projectRoot);
|
|
333
|
+
const filter = new MarkFilter(view, includeOutdated);
|
|
334
|
+
const byId = new Map();
|
|
335
|
+
for (const id of sessionFileOrder([...sessions.keys()])) {
|
|
336
|
+
const session = sessions.get(id);
|
|
337
|
+
byId.set(id, {
|
|
338
|
+
...session,
|
|
339
|
+
transformations: session.transformations.filter((t) => filter.keep(`t:${t.transformationId}`)),
|
|
340
|
+
...(session.analyses === undefined
|
|
341
|
+
? {}
|
|
342
|
+
: { analyses: session.analyses.filter((a) => filter.keep(`f:${a.feedbackId}`)) }),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
return { sessions: [...byId.values()], byId, skipped: filter.skipped, warnings: view.warnings };
|
|
346
|
+
}
|
|
347
|
+
/** Input property `includeOutdated` of the readers. */
|
|
348
|
+
export const INCLUDE_OUTDATED_SCHEMA = {
|
|
349
|
+
includeOutdated: {
|
|
350
|
+
type: 'boolean',
|
|
351
|
+
default: false,
|
|
352
|
+
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",
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
/** Output properties `skippedRecords` and `sidecarWarnings` of the readers. */
|
|
356
|
+
export const SKIPPED_RECORDS_OUTPUT_SCHEMA = {
|
|
357
|
+
skippedRecords: {
|
|
358
|
+
type: 'object',
|
|
359
|
+
properties: {
|
|
360
|
+
total: { type: 'integer' },
|
|
361
|
+
byReason: { type: 'object', additionalProperties: { type: 'integer' } },
|
|
362
|
+
},
|
|
363
|
+
required: ['total', 'byReason'],
|
|
364
|
+
},
|
|
365
|
+
sidecarWarnings: { type: 'array', items: { type: 'string' } },
|
|
366
|
+
};
|
|
367
|
+
/** Summary lines about skipped records and sidecar warnings (none when nothing to say). */
|
|
368
|
+
export function describeSkipped(skipped, warnings) {
|
|
369
|
+
const lines = [];
|
|
370
|
+
if (skipped.total > 0) {
|
|
371
|
+
const reasons = Object.entries(skipped.byReason)
|
|
372
|
+
.map(([reason, n]) => `${n} ${reason}`)
|
|
373
|
+
.join(', ');
|
|
374
|
+
lines.push(`Skipped ${skipped.total} record(s) marked in the feedback sidecar (${reasons}); includeOutdated: true reads them.`);
|
|
375
|
+
}
|
|
376
|
+
for (const warning of warnings) {
|
|
377
|
+
lines.push(`Warning: ${warning}`);
|
|
378
|
+
}
|
|
379
|
+
return lines;
|
|
380
|
+
}
|
|
381
|
+
//# sourceMappingURL=feedback-sidecar.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** A TypeScript diagnostic of the checked file. */
|
|
2
|
+
export interface FileTypeIssue {
|
|
3
|
+
/** `error` or `warning` (diagnostic category). */
|
|
4
|
+
severity: 'error' | 'warning';
|
|
5
|
+
/** Flattened diagnostic message. */
|
|
6
|
+
message: string;
|
|
7
|
+
/** 1-based line. */
|
|
8
|
+
line?: number;
|
|
9
|
+
/** 1-based column. */
|
|
10
|
+
column?: number;
|
|
11
|
+
/** Diagnostic code, e.g. `TS2322`. */
|
|
12
|
+
code: string;
|
|
13
|
+
}
|
|
14
|
+
/** Result of {@link typeCheckFile}. */
|
|
15
|
+
export interface FileTypeCheck {
|
|
16
|
+
/** Whether a type check ran. */
|
|
17
|
+
checked: boolean;
|
|
18
|
+
/** Diagnostics of the file. */
|
|
19
|
+
issues: FileTypeIssue[];
|
|
20
|
+
/** tsconfig whose compiler options were used. */
|
|
21
|
+
tsConfigPath?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Type-checks one file with the compiler options of its project: the file and
|
|
25
|
+
* the files it imports are loaded, not the whole program, and only the file's
|
|
26
|
+
* own diagnostics are reported. Test files use `tsconfig.spec.json` when the
|
|
27
|
+
* project has one.
|
|
28
|
+
*
|
|
29
|
+
* @param filePath - Absolute path of an existing file
|
|
30
|
+
* @param projectRoot - Project root to find the tsconfig in
|
|
31
|
+
* @returns The diagnostics, or `checked: false` without a tsconfig
|
|
32
|
+
*/
|
|
33
|
+
export declare function typeCheckFile(filePath: string, projectRoot: string): FileTypeCheck;
|
|
34
|
+
//# sourceMappingURL=file-type-check.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { Project, ts } from 'ts-morph';
|
|
4
|
+
import { findTsConfig } from './find-ts-config.js';
|
|
5
|
+
/** Test files compile with the spec tsconfig (test framework types). */
|
|
6
|
+
function isTestFile(filePath) {
|
|
7
|
+
return /\.(?:spec|test)\.[cm]?tsx?$/.test(filePath);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Type-checks one file with the compiler options of its project: the file and
|
|
11
|
+
* the files it imports are loaded, not the whole program, and only the file's
|
|
12
|
+
* own diagnostics are reported. Test files use `tsconfig.spec.json` when the
|
|
13
|
+
* project has one.
|
|
14
|
+
*
|
|
15
|
+
* @param filePath - Absolute path of an existing file
|
|
16
|
+
* @param projectRoot - Project root to find the tsconfig in
|
|
17
|
+
* @returns The diagnostics, or `checked: false` without a tsconfig
|
|
18
|
+
*/
|
|
19
|
+
export function typeCheckFile(filePath, projectRoot) {
|
|
20
|
+
const specConfig = join(projectRoot, 'tsconfig.spec.json');
|
|
21
|
+
const tsConfigPath = isTestFile(filePath) && existsSync(specConfig)
|
|
22
|
+
? specConfig
|
|
23
|
+
: findTsConfig(projectRoot);
|
|
24
|
+
if (tsConfigPath === null) {
|
|
25
|
+
return { checked: false, issues: [] };
|
|
26
|
+
}
|
|
27
|
+
const project = new Project({
|
|
28
|
+
tsConfigFilePath: tsConfigPath,
|
|
29
|
+
skipAddingFilesFromTsConfig: true,
|
|
30
|
+
});
|
|
31
|
+
const sourceFile = project.addSourceFileAtPath(filePath);
|
|
32
|
+
project.resolveSourceFileDependencies();
|
|
33
|
+
const issues = sourceFile
|
|
34
|
+
.getPreEmitDiagnostics()
|
|
35
|
+
// Only the file's own diagnostics: config diagnostics (an empty `files`
|
|
36
|
+
// list of a solution-style tsconfig) have no file and say nothing about it
|
|
37
|
+
.filter((diagnostic) => diagnostic.getSourceFile()?.getFilePath() === sourceFile.getFilePath() &&
|
|
38
|
+
(diagnostic.getCategory() === ts.DiagnosticCategory.Error ||
|
|
39
|
+
diagnostic.getCategory() === ts.DiagnosticCategory.Warning))
|
|
40
|
+
.map((diagnostic) => {
|
|
41
|
+
const start = diagnostic.getStart();
|
|
42
|
+
const position = start === undefined ? undefined : sourceFile.getLineAndColumnAtPos(start);
|
|
43
|
+
return {
|
|
44
|
+
severity: diagnostic.getCategory() === ts.DiagnosticCategory.Error
|
|
45
|
+
? 'error'
|
|
46
|
+
: 'warning',
|
|
47
|
+
message: ts.flattenDiagnosticMessageText(diagnostic.compilerObject.messageText, '\n'),
|
|
48
|
+
...(position === undefined
|
|
49
|
+
? {}
|
|
50
|
+
: { line: position.line, column: position.column }),
|
|
51
|
+
code: `TS${diagnostic.getCode()}`,
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
return { checked: true, issues, tsConfigPath };
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=file-type-check.js.map
|
|
@@ -26,6 +26,12 @@ export interface HealthSnapshot {
|
|
|
26
26
|
scope: HealthScope;
|
|
27
27
|
rulesExecuted: string[];
|
|
28
28
|
analyzedFiles: number;
|
|
29
|
+
/**
|
|
30
|
+
* Whether every library import of the scan resolved (node_modules
|
|
31
|
+
* complete); rules that need library types report differently without
|
|
32
|
+
* them. Absent in snapshots written before the flag: read as `true`.
|
|
33
|
+
*/
|
|
34
|
+
libraryTypesResolved: boolean;
|
|
29
35
|
violations: HealthViolation[];
|
|
30
36
|
}
|
|
31
37
|
/** Counts of one rule in the previous and the current run. */
|
|
@@ -30,6 +30,7 @@ export function serializeHealthSnapshot(snapshot) {
|
|
|
30
30
|
scope: snapshot.scope,
|
|
31
31
|
rulesExecuted: snapshot.rulesExecuted,
|
|
32
32
|
analyzedFiles: snapshot.analyzedFiles,
|
|
33
|
+
libraryTypesResolved: snapshot.libraryTypesResolved,
|
|
33
34
|
totalViolations: snapshot.violations.length,
|
|
34
35
|
});
|
|
35
36
|
const lines = [...files].map(([file, list]) => `${JSON.stringify(file)}:${JSON.stringify(list)}`);
|
|
@@ -52,11 +53,12 @@ export function parseHealthSnapshot(text) {
|
|
|
52
53
|
if (!isRecord(data) || data['version'] !== HEALTH_SNAPSHOT_VERSION) {
|
|
53
54
|
return undefined;
|
|
54
55
|
}
|
|
55
|
-
const { createdAt, scope, rulesExecuted, analyzedFiles, files } = data;
|
|
56
|
+
const { createdAt, scope, rulesExecuted, analyzedFiles, libraryTypesResolved, files } = data;
|
|
56
57
|
const valid = typeof createdAt === 'string' &&
|
|
57
58
|
isScope(scope) &&
|
|
58
59
|
isStringArray(rulesExecuted) &&
|
|
59
60
|
typeof analyzedFiles === 'number' &&
|
|
61
|
+
(libraryTypesResolved === undefined || typeof libraryTypesResolved === 'boolean') &&
|
|
60
62
|
isRecord(files);
|
|
61
63
|
if (!valid) {
|
|
62
64
|
return undefined;
|
|
@@ -83,6 +85,7 @@ export function parseHealthSnapshot(text) {
|
|
|
83
85
|
scope,
|
|
84
86
|
rulesExecuted,
|
|
85
87
|
analyzedFiles,
|
|
88
|
+
libraryTypesResolved: libraryTypesResolved ?? true,
|
|
86
89
|
violations,
|
|
87
90
|
};
|
|
88
91
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Warning about unresolved library imports
|
|
3
|
+
*
|
|
4
|
+
* Counts, warning text and the result helper of the library import check
|
|
5
|
+
* (`library-imports.ts`). Kept apart from the check so the scan tools can
|
|
6
|
+
* add the warning without loading ts-morph (their unit tests mock `node:fs`).
|
|
7
|
+
*/
|
|
8
|
+
/** Library imports of a project that do not resolve. */
|
|
9
|
+
export interface UnresolvedLibraryImports {
|
|
10
|
+
/** Import and `export ... from` declarations with an unresolved library specifier. */
|
|
11
|
+
imports: number;
|
|
12
|
+
/** Distinct packages among them (`@scope/name` or `name`). */
|
|
13
|
+
packages: number;
|
|
14
|
+
/** Up to {@link EXAMPLE_PACKAGES} package names, most imported first. */
|
|
15
|
+
examples: string[];
|
|
16
|
+
}
|
|
17
|
+
/** Package names listed in the warning. */
|
|
18
|
+
export declare const EXAMPLE_PACKAGES = 5;
|
|
19
|
+
/** Warning text for `warnings` and the summary, or `undefined` when all resolve. */
|
|
20
|
+
export declare function libraryImportWarning(found: UnresolvedLibraryImports): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Adds the library import warning of a scan to its result: one entry in
|
|
23
|
+
* `warnings` (after the existing ones), `unresolvedLibraryImports` and one
|
|
24
|
+
* `Warning:` line in the summary. Returns the result unchanged when every
|
|
25
|
+
* library import resolved or nothing was checked (a cancelled worker run).
|
|
26
|
+
*/
|
|
27
|
+
export declare function withLibraryImportWarning<T extends {
|
|
28
|
+
summary: string;
|
|
29
|
+
warnings?: string[];
|
|
30
|
+
}>(result: T, found: UnresolvedLibraryImports | undefined): T & {
|
|
31
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=library-import-warning.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Warning about unresolved library imports
|
|
3
|
+
*
|
|
4
|
+
* Counts, warning text and the result helper of the library import check
|
|
5
|
+
* (`library-imports.ts`). Kept apart from the check so the scan tools can
|
|
6
|
+
* add the warning without loading ts-morph (their unit tests mock `node:fs`).
|
|
7
|
+
*/
|
|
8
|
+
/** Package names listed in the warning. */
|
|
9
|
+
export const EXAMPLE_PACKAGES = 5;
|
|
10
|
+
/** Warning text for `warnings` and the summary, or `undefined` when all resolve. */
|
|
11
|
+
export function libraryImportWarning(found) {
|
|
12
|
+
if (found.imports === 0) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const more = found.packages > found.examples.length ? ', ...' : '';
|
|
16
|
+
return (`${found.imports} library import(s) from ${found.packages} package(s) do not resolve ` +
|
|
17
|
+
`(${found.examples.join(', ')}${more}); is node_modules missing or incomplete? ` +
|
|
18
|
+
'Results that depend on library types (dialogs, subscriptions, injected services) can be incomplete.');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Adds the library import warning of a scan to its result: one entry in
|
|
22
|
+
* `warnings` (after the existing ones), `unresolvedLibraryImports` and one
|
|
23
|
+
* `Warning:` line in the summary. Returns the result unchanged when every
|
|
24
|
+
* library import resolved or nothing was checked (a cancelled worker run).
|
|
25
|
+
*/
|
|
26
|
+
export function withLibraryImportWarning(result, found) {
|
|
27
|
+
const warning = found === undefined ? undefined : libraryImportWarning(found);
|
|
28
|
+
if (found === undefined || warning === undefined) {
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
...result,
|
|
33
|
+
warnings: [...(result.warnings ?? []), warning],
|
|
34
|
+
unresolvedLibraryImports: found,
|
|
35
|
+
summary: `${result.summary}\nWarning: ${warning}`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=library-import-warning.js.map
|
|
@@ -25,18 +25,9 @@
|
|
|
25
25
|
* JavaScript such as `moment/locale/de-at` have no types to resolve). No
|
|
26
26
|
* program is created.
|
|
27
27
|
*/
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
export
|
|
31
|
-
/** Import and `export ... from` declarations with an unresolved library specifier. */
|
|
32
|
-
imports: number;
|
|
33
|
-
/** Distinct packages among them (`@scope/name` or `name`). */
|
|
34
|
-
packages: number;
|
|
35
|
-
/** Up to {@link EXAMPLE_PACKAGES} package names, most imported first. */
|
|
36
|
-
examples: string[];
|
|
37
|
-
}
|
|
38
|
-
/** Package names listed in the warning. */
|
|
39
|
-
export declare const EXAMPLE_PACKAGES = 5;
|
|
28
|
+
import { Project, type FileSystemHost } from 'ts-morph';
|
|
29
|
+
import { type UnresolvedLibraryImports } from './library-import-warning.js';
|
|
30
|
+
export { EXAMPLE_PACKAGES, libraryImportWarning, withLibraryImportWarning, type UnresolvedLibraryImports, } from './library-import-warning.js';
|
|
40
31
|
/** `@scope/name/sub` -> `@scope/name`, `name/sub` -> `name`. */
|
|
41
32
|
export declare function packageName(specifier: string): string;
|
|
42
33
|
/**
|
|
@@ -52,6 +43,39 @@ export declare function declaredPackages(fs: FileSystemHost, dir: string): Set<s
|
|
|
52
43
|
* declared packages is looked up from its directory upwards.
|
|
53
44
|
*/
|
|
54
45
|
export declare function findUnresolvedLibraryImports(project: Project, tsConfigPath: string): UnresolvedLibraryImports;
|
|
55
|
-
/**
|
|
56
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Like {@link findUnresolvedLibraryImports}, for files that are not (all)
|
|
48
|
+
* in the project: the scans hold only a batch of their scope at a time and
|
|
49
|
+
* none on a warm run. Each file is read and scanned for its imports without
|
|
50
|
+
* a parse; besides import and `export ... from` declarations this also
|
|
51
|
+
* counts `import x = require(...)` and dynamic `import(...)` of a library.
|
|
52
|
+
* Files that cannot be read are skipped; the specifiers of a file are
|
|
53
|
+
* remembered per process until its mtime or size changes.
|
|
54
|
+
*
|
|
55
|
+
* @param project - Gives compiler options, module resolution host and file
|
|
56
|
+
* system of the tsconfig; its source files are not read.
|
|
57
|
+
* @param tsConfigPath - As in {@link findUnresolvedLibraryImports}.
|
|
58
|
+
* @param filePaths - Absolute paths of the files to check.
|
|
59
|
+
*/
|
|
60
|
+
export declare function findUnresolvedLibraryImportsInFiles(project: Project, tsConfigPath: string, filePaths: Iterable<string>): UnresolvedLibraryImports;
|
|
61
|
+
/** Library imports of a scan scope, see {@link checkScanScope}. */
|
|
62
|
+
export interface ScanScopeLibraryImports {
|
|
63
|
+
/** Counts and examples for the warning. */
|
|
64
|
+
unresolved: UnresolvedLibraryImports;
|
|
65
|
+
/** Every package with an unresolved import, sorted; empty when all resolve. */
|
|
66
|
+
packages: string[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Library imports of a scan scope that do not resolve, checked before the
|
|
70
|
+
* scan reads its cache: the packages go into the cache version, so entries
|
|
71
|
+
* written while node_modules was missing or incomplete are not served once
|
|
72
|
+
* it is complete (and the other way round). Runs on the calling thread and
|
|
73
|
+
* yields to the event loop every {@link FILES_PER_TURN} files; repeated
|
|
74
|
+
* calls only stat unchanged files (see {@link findUnresolvedLibraryImportsInFiles}).
|
|
75
|
+
*
|
|
76
|
+
* @param tsConfigPath - tsconfig of the scan; gives compiler options and
|
|
77
|
+
* the `package.json` with the declared packages.
|
|
78
|
+
* @param filePaths - Absolute paths of the scan scope.
|
|
79
|
+
*/
|
|
80
|
+
export declare function checkScanScope(tsConfigPath: string, filePaths: readonly string[]): Promise<ScanScopeLibraryImports>;
|
|
57
81
|
//# sourceMappingURL=library-imports.d.ts.map
|