@angular-modernizer/adapter-mcp 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +662 -0
- package/README.md +86 -445
- package/dist/cli.js +9 -1
- package/dist/core/project-analyzer.js +2 -2
- package/dist/index.d.ts +10 -1
- 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 +9 -6
- package/dist/tools/analyze-build-impact.js +14 -7
- 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 +35 -6
- package/dist/tools/analyze-project.js +141 -36
- 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/extract-libraries.js +42 -27
- package/dist/tools/find-angular-symbol.d.ts +2 -2
- package/dist/tools/find-angular-symbol.js +6 -5
- package/dist/tools/find-component-hosts.d.ts +2 -2
- package/dist/tools/find-component-hosts.js +6 -5
- package/dist/tools/find-usages.d.ts +2 -2
- package/dist/tools/find-usages.js +24 -15
- package/dist/tools/get-bootstrap-execution.d.ts +2 -2
- package/dist/tools/get-bootstrap-execution.js +3 -3
- package/dist/tools/get-call-graph.d.ts +2 -2
- package/dist/tools/get-call-graph.js +18 -5
- 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 +22 -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/output-contract.d.ts +42 -0
- package/dist/tools/helpers/output-contract.js +54 -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 +78 -6
- package/dist/tools/helpers/project-cache.js +205 -15
- 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 +610 -0
- package/dist/tools/helpers/rule-runner.js +3 -1
- package/dist/tools/helpers/scan-cache.d.ts +74 -5
- package/dist/tools/helpers/scan-cache.js +134 -6
- package/dist/tools/helpers/scan-engine.d.ts +30 -6
- package/dist/tools/helpers/scan-engine.js +131 -22
- package/dist/tools/helpers/scan-plan.d.ts +1 -1
- 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.d.ts +2 -2
- package/dist/tools/inspect-form-group.js +8 -3
- package/dist/tools/inspect-i18n.d.ts +2 -2
- package/dist/tools/inspect-i18n.js +3 -3
- package/dist/tools/inspect-template.d.ts +2 -2
- package/dist/tools/inspect-template.js +11 -5
- package/dist/tools/learn-patterns.d.ts +43 -28
- package/dist/tools/learn-patterns.js +83 -161
- package/dist/tools/list-imports.d.ts +2 -2
- package/dist/tools/list-imports.js +3 -3
- 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.d.ts +2 -2
- package/dist/tools/plan-migration.js +25 -12
- package/dist/tools/refresh-state.d.ts +378 -0
- package/dist/tools/refresh-state.js +370 -0
- package/dist/tools/resolve-type.d.ts +2 -2
- package/dist/tools/resolve-type.js +13 -6
- 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 +31 -15
- package/dist/tools/scan-all.js +75 -109
- package/dist/tools/scan-angular.d.ts +27 -14
- package/dist/tools/scan-angular.js +70 -92
- package/dist/tools/scan-architecture.d.ts +29 -12
- package/dist/tools/scan-architecture.js +205 -135
- package/dist/tools/scan-solid.d.ts +27 -14
- package/dist/tools/scan-solid.js +73 -89
- package/dist/tools/search-codebase.d.ts +8 -3
- package/dist/tools/search-codebase.js +16 -10
- package/dist/tools/suggest-improvements.d.ts +34 -3
- package/dist/tools/suggest-improvements.js +34 -9
- package/dist/tools/trace-output-flow.d.ts +2 -2
- package/dist/tools/trace-output-flow.js +6 -5
- 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 +782 -197
- 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
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* result into an output validation error. `required` lists only fields every
|
|
11
11
|
* variant of the result carries (`summaryOnly` drops the lists).
|
|
12
12
|
*/
|
|
13
|
+
import { type ConfigWarning } from '@angular-modernizer/core';
|
|
13
14
|
/** `warnings` entry of an output schema. */
|
|
14
15
|
export declare const WARNINGS_OUTPUT_SCHEMA: {
|
|
15
16
|
readonly warnings: {
|
|
@@ -29,4 +30,45 @@ export declare function withWarnings<T extends {
|
|
|
29
30
|
}>(result: T, warnings: readonly string[]): T & {
|
|
30
31
|
warnings?: string[];
|
|
31
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* `configWarnings` entry of an output schema. sdk-server adds it to every
|
|
35
|
+
* registered output schema (`withConfigWarningsSchema`); its own field because
|
|
36
|
+
* `warnings` means something different per tool.
|
|
37
|
+
*/
|
|
38
|
+
export declare const CONFIG_WARNINGS_OUTPUT_SCHEMA: {
|
|
39
|
+
readonly configWarnings: {
|
|
40
|
+
readonly type: "array";
|
|
41
|
+
readonly description: "Warnings about the project configuration (.angular-modernizer.json) the call loaded: deprecated keys without effect, layers / layersSource drift, a failed layersSource import. Absent when there are none.";
|
|
42
|
+
readonly items: {
|
|
43
|
+
readonly type: "object";
|
|
44
|
+
readonly properties: {
|
|
45
|
+
readonly code: {
|
|
46
|
+
readonly type: "string";
|
|
47
|
+
readonly enum: readonly ["deprecated-key", "layers-drift", "layers-source-failed"];
|
|
48
|
+
};
|
|
49
|
+
readonly message: {
|
|
50
|
+
readonly type: "string";
|
|
51
|
+
};
|
|
52
|
+
readonly key: {
|
|
53
|
+
readonly type: "string";
|
|
54
|
+
readonly description: "The config key the warning is about.";
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
readonly required: readonly ["code", "message"];
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/** An output schema with `configWarnings` added to its properties. */
|
|
62
|
+
export declare function withConfigWarningsSchema(schema: object): Record<string, unknown>;
|
|
63
|
+
/**
|
|
64
|
+
* Adds `configWarnings` to a tool result and one `Config:` line to its
|
|
65
|
+
* summary; returns the result unchanged when there are none or when the result
|
|
66
|
+
* is no object.
|
|
67
|
+
*/
|
|
68
|
+
export declare function withConfigWarnings(result: unknown, warnings: readonly ConfigWarning[]): unknown;
|
|
69
|
+
/**
|
|
70
|
+
* The summary line of config warnings: their count and the first message;
|
|
71
|
+
* `inField` points to `configWarnings`, which an error answer does not carry.
|
|
72
|
+
*/
|
|
73
|
+
export declare function configWarningsLine(warnings: readonly ConfigWarning[], inField: boolean): string;
|
|
32
74
|
//# sourceMappingURL=output-contract.d.ts.map
|
|
@@ -29,4 +29,58 @@ export function withWarnings(result, warnings) {
|
|
|
29
29
|
const lines = warnings.map((w) => `Warning: ${w}`).join('\n');
|
|
30
30
|
return { ...result, summary: `${result.summary}\n${lines}`, warnings: [...warnings] };
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* `configWarnings` entry of an output schema. sdk-server adds it to every
|
|
34
|
+
* registered output schema (`withConfigWarningsSchema`); its own field because
|
|
35
|
+
* `warnings` means something different per tool.
|
|
36
|
+
*/
|
|
37
|
+
export const CONFIG_WARNINGS_OUTPUT_SCHEMA = {
|
|
38
|
+
configWarnings: {
|
|
39
|
+
type: 'array',
|
|
40
|
+
description: 'Warnings about the project configuration (.angular-modernizer.json) the call loaded: deprecated keys without effect, layers / layersSource drift, a failed layersSource import. Absent when there are none.',
|
|
41
|
+
items: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
code: { type: 'string', enum: ['deprecated-key', 'layers-drift', 'layers-source-failed'] },
|
|
45
|
+
message: { type: 'string' },
|
|
46
|
+
key: { type: 'string', description: 'The config key the warning is about.' },
|
|
47
|
+
},
|
|
48
|
+
required: ['code', 'message'],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
/** An output schema with `configWarnings` added to its properties. */
|
|
53
|
+
export function withConfigWarningsSchema(schema) {
|
|
54
|
+
const own = schema;
|
|
55
|
+
return {
|
|
56
|
+
...schema,
|
|
57
|
+
properties: { ...own.properties, ...CONFIG_WARNINGS_OUTPUT_SCHEMA },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Adds `configWarnings` to a tool result and one `Config:` line to its
|
|
62
|
+
* summary; returns the result unchanged when there are none or when the result
|
|
63
|
+
* is no object.
|
|
64
|
+
*/
|
|
65
|
+
export function withConfigWarnings(result, warnings) {
|
|
66
|
+
if (warnings.length === 0 || typeof result !== 'object' || result === null || Array.isArray(result)) {
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
const record = result;
|
|
70
|
+
const summary = record['summary'];
|
|
71
|
+
const line = configWarningsLine(warnings, true);
|
|
72
|
+
return {
|
|
73
|
+
...record,
|
|
74
|
+
...(typeof summary === 'string' ? { summary: `${summary}\n${line}` } : {}),
|
|
75
|
+
configWarnings: warnings.map((w) => ({ ...w })),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The summary line of config warnings: their count and the first message;
|
|
80
|
+
* `inField` points to `configWarnings`, which an error answer does not carry.
|
|
81
|
+
*/
|
|
82
|
+
export function configWarningsLine(warnings, inField) {
|
|
83
|
+
const where = inField ? ', see configWarnings' : '';
|
|
84
|
+
return `Config: ${warnings.length} warning(s)${where}: ${warnings[0]?.message ?? ''}`;
|
|
85
|
+
}
|
|
32
86
|
//# sourceMappingURL=output-contract.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anonymization of learn-patterns examples: file paths and code.
|
|
3
|
+
*
|
|
4
|
+
* `strict` hashes file paths and renames every identifier, string literal
|
|
5
|
+
* and template text in code deterministically (same name, same alias in
|
|
6
|
+
* every example and run) and drops comments; framework names stay.
|
|
7
|
+
* `moderate` makes file paths project-relative and keeps the code.
|
|
8
|
+
* `minimal` keeps both as they are.
|
|
9
|
+
*/
|
|
10
|
+
/** Anonymization level of learn-patterns. */
|
|
11
|
+
export type AnonymizationLevel = 'strict' | 'moderate' | 'minimal';
|
|
12
|
+
/**
|
|
13
|
+
* File path of an example: hashed (`strict`), project-relative (`moderate`)
|
|
14
|
+
* or unchanged (`minimal`).
|
|
15
|
+
*/
|
|
16
|
+
export declare function anonymizeFilePath(filePath: string, projectRoot: string, level: AnonymizationLevel): string;
|
|
17
|
+
/**
|
|
18
|
+
* Code of an example. `strict` renames identifiers, string literals and
|
|
19
|
+
* template text and drops comments; the other levels keep the code.
|
|
20
|
+
*/
|
|
21
|
+
export declare function anonymizeCode(code: string, level: AnonymizationLevel): string;
|
|
22
|
+
/**
|
|
23
|
+
* Metadata of an example. `strict` anonymizes string values like code
|
|
24
|
+
* (class and property names get the same alias as in the code).
|
|
25
|
+
*/
|
|
26
|
+
export declare function anonymizeMetadata(metadata: Record<string, unknown>, level: AnonymizationLevel): Record<string, unknown>;
|
|
27
|
+
//# sourceMappingURL=pattern-anonymizer.d.ts.map
|