@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
|
@@ -5,10 +5,17 @@
|
|
|
5
5
|
* project root. The list adds to `Component`; the api classes treat a missing
|
|
6
6
|
* and an empty list the same (Component only).
|
|
7
7
|
*/
|
|
8
|
+
/** Configured component decorators and why the config could not be used. */
|
|
9
|
+
export interface ProjectComponentDecorators {
|
|
10
|
+
/** `parser.componentDecorators`, `undefined` without a config or when it does not load. */
|
|
11
|
+
componentDecorators: readonly string[] | undefined;
|
|
12
|
+
/** One entry when the config does not load (invalid JSON or schema); empty otherwise. */
|
|
13
|
+
warnings: string[];
|
|
14
|
+
}
|
|
8
15
|
/**
|
|
9
|
-
* `parser.componentDecorators` of the project
|
|
10
|
-
*
|
|
11
|
-
*
|
|
16
|
+
* `parser.componentDecorators` of the project. A broken config must not break
|
|
17
|
+
* investigation: the tools then fall back to `Component` only, and the warning
|
|
18
|
+
* says so (with the loader's message, which names unknown keys).
|
|
12
19
|
*/
|
|
13
|
-
export declare function configuredComponentDecorators(projectRoot: string):
|
|
20
|
+
export declare function configuredComponentDecorators(projectRoot: string): ProjectComponentDecorators;
|
|
14
21
|
//# sourceMappingURL=project-decorators.d.ts.map
|
|
@@ -7,16 +7,23 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { loadConfig } from '@angular-modernizer/core';
|
|
9
9
|
/**
|
|
10
|
-
* `parser.componentDecorators` of the project
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* `parser.componentDecorators` of the project. A broken config must not break
|
|
11
|
+
* investigation: the tools then fall back to `Component` only, and the warning
|
|
12
|
+
* says so (with the loader's message, which names unknown keys).
|
|
13
13
|
*/
|
|
14
14
|
export function configuredComponentDecorators(projectRoot) {
|
|
15
15
|
try {
|
|
16
|
-
return
|
|
16
|
+
return {
|
|
17
|
+
componentDecorators: loadConfig(projectRoot).parser?.componentDecorators,
|
|
18
|
+
warnings: [],
|
|
19
|
+
};
|
|
17
20
|
}
|
|
18
|
-
catch {
|
|
19
|
-
|
|
21
|
+
catch (error) {
|
|
22
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
23
|
+
return {
|
|
24
|
+
componentDecorators: undefined,
|
|
25
|
+
warnings: [`.angular-modernizer.json not used (only @Component counts as a component): ${message}`],
|
|
26
|
+
};
|
|
20
27
|
}
|
|
21
28
|
}
|
|
22
29
|
//# sourceMappingURL=project-decorators.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type GitRunner, type RefreshItem, type RefreshReason, type RefreshRetention, type RefreshStore } from './refresh-inventory.js';
|
|
2
|
+
import { type CatalogTool } from './feedback-catalog.js';
|
|
3
|
+
/** Time a plan stays valid after its report. */
|
|
4
|
+
export declare const PLAN_TTL_MS: number;
|
|
5
|
+
/** Parts of the platform state an apply can act on. */
|
|
6
|
+
export type RefreshPart = 'caches' | 'backups' | 'refs' | 'feedback';
|
|
7
|
+
/** Every part apply accepts. */
|
|
8
|
+
export declare const REFRESH_PARTS: readonly RefreshPart[];
|
|
9
|
+
/** Why apply left a planned item in place. */
|
|
10
|
+
export type SkipCause = 'no-longer-listed' | 'missing' | 'changed' | 'symbolic-link' | 'outside-cache-folder' | 'outside-backup-folder' | 'outside-feedback-folder' | 'failed';
|
|
11
|
+
/** A planned item apply removed. */
|
|
12
|
+
export interface RemovedItem {
|
|
13
|
+
/** Store of the item. */
|
|
14
|
+
store: RefreshStore;
|
|
15
|
+
/** Reason it was listed. */
|
|
16
|
+
reason: RefreshReason;
|
|
17
|
+
/** Path relative to the project root, backup group id or ref name. */
|
|
18
|
+
path: string;
|
|
19
|
+
/** Bytes freed (0 for a ref). */
|
|
20
|
+
bytes: number;
|
|
21
|
+
}
|
|
22
|
+
/** A planned item apply left in place. */
|
|
23
|
+
export interface SkippedItem {
|
|
24
|
+
/** Store of the item. */
|
|
25
|
+
store: RefreshStore;
|
|
26
|
+
/** Reason it was listed. */
|
|
27
|
+
reason: RefreshReason;
|
|
28
|
+
/** Path relative to the project root, backup group id or ref name. */
|
|
29
|
+
path: string;
|
|
30
|
+
/** Why it stayed. */
|
|
31
|
+
cause: SkipCause;
|
|
32
|
+
/** Error message of a failed removal. */
|
|
33
|
+
detail?: string;
|
|
34
|
+
}
|
|
35
|
+
/** A planned feedback item whose session file apply marked in the sidecar. */
|
|
36
|
+
export interface MarkedItem {
|
|
37
|
+
/** Store of the item (`feedback`). */
|
|
38
|
+
store: RefreshStore;
|
|
39
|
+
/** Reason it was listed. */
|
|
40
|
+
reason: RefreshReason;
|
|
41
|
+
/** Session file relative to the project root. */
|
|
42
|
+
path: string;
|
|
43
|
+
/** Records of the file the sidecar marks now (all reasons). */
|
|
44
|
+
records: number;
|
|
45
|
+
}
|
|
46
|
+
/** Outcome of an apply. */
|
|
47
|
+
export interface ApplyOutcome {
|
|
48
|
+
/** Removed items, plan order. */
|
|
49
|
+
removed: RemovedItem[];
|
|
50
|
+
/** Feedback items marked in the sidecar, plan order. */
|
|
51
|
+
marked: MarkedItem[];
|
|
52
|
+
/** Planned items of the requested parts that stayed. */
|
|
53
|
+
skipped: SkippedItem[];
|
|
54
|
+
}
|
|
55
|
+
/** Lists the items a fresh inventory of the project finds with the given retention. */
|
|
56
|
+
export type InventoryLister = (retention: RefreshRetention) => readonly RefreshItem[];
|
|
57
|
+
/** Registered tools for the feedback marks, read at apply time. */
|
|
58
|
+
export type ApplyTools = readonly CatalogTool[] | undefined;
|
|
59
|
+
/** Plans of one tool instance, kept in memory only. */
|
|
60
|
+
export declare class RefreshPlans {
|
|
61
|
+
private readonly now;
|
|
62
|
+
private readonly git;
|
|
63
|
+
private readonly plans;
|
|
64
|
+
/**
|
|
65
|
+
* @param now clock
|
|
66
|
+
* @param git git runner (snapshot refs are read and deleted through it)
|
|
67
|
+
*/
|
|
68
|
+
constructor(now: () => number, git?: GitRunner);
|
|
69
|
+
/**
|
|
70
|
+
* Records the items of a report with their fingerprints and the retention the report used.
|
|
71
|
+
*
|
|
72
|
+
* @param projectRoot real path of the project root
|
|
73
|
+
* @returns the plan id and when it expires (ms)
|
|
74
|
+
*/
|
|
75
|
+
create(projectRoot: string, items: readonly RefreshItem[], retention: RefreshRetention): {
|
|
76
|
+
planId: string;
|
|
77
|
+
expiresAt: number;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Removes the planned items of `parts` that a fresh inventory still lists and that are unchanged. The inventory
|
|
81
|
+
* runs with the retention of the report. The plan is used up by the call, whatever the outcome.
|
|
82
|
+
*
|
|
83
|
+
* @param projectRoot real path of the project root
|
|
84
|
+
* @throws when the plan is unknown, expired or belongs to another project
|
|
85
|
+
*/
|
|
86
|
+
apply(planId: string, projectRoot: string, parts: readonly RefreshPart[], inventory: InventoryLister, tools?: ApplyTools): ApplyOutcome;
|
|
87
|
+
/** Writes the sidecar marks of the planned session files that are still unchanged. */
|
|
88
|
+
private mark;
|
|
89
|
+
/** Fingerprint of an item at report time, or why it can never be removed. */
|
|
90
|
+
private plan;
|
|
91
|
+
/** Removes one listed item when it is unchanged against its fingerprint. */
|
|
92
|
+
private remove;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=refresh-apply.d.ts.map
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply side of refresh-state: plans that a report hands out and the removal of planned items. An item is removed
|
|
3
|
+
* only while a fresh inventory (with the retention of the report) still lists it for the same reason and it is
|
|
4
|
+
* unchanged since the report: a cache entry or file keeps its size and mtime (a folder: bytes, file count, newest
|
|
5
|
+
* mtime) and its real path is itself below the folder of its store; a backup group keeps the same files with the
|
|
6
|
+
* same sizes and mtimes, and exactly those files go; a snapshot ref still points at the commit of the report, which
|
|
7
|
+
* git checks on deletion (`update-ref -d <ref> <old>`). Symbolic links are never followed and never removed. Feedback
|
|
8
|
+
* items are never removed: their session file keeps its SHA-256 of the report, and its marks go into the sidecar
|
|
9
|
+
* (`feedback-sidecar.ts`); session files are only read.
|
|
10
|
+
*/
|
|
11
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
12
|
+
import { lstatSync, readFileSync, readdirSync, realpathSync, rmSync, unlinkSync, } from 'node:fs';
|
|
13
|
+
import { dirname, join, sep } from 'node:path';
|
|
14
|
+
import { BACKUP_DIR, CACHE_DIR, FEEDBACK_DIR, LEGACY_STORE_DIR, backupGroupMembers, runGit, } from './refresh-inventory.js';
|
|
15
|
+
import { writeFeedbackMarks } from './feedback-sidecar.js';
|
|
16
|
+
/** Time a plan stays valid after its report. */
|
|
17
|
+
export const PLAN_TTL_MS = 10 * 60 * 1000;
|
|
18
|
+
/** Plans kept at a time; the oldest goes first. */
|
|
19
|
+
const MAX_PLANS = 20;
|
|
20
|
+
/** Every part apply accepts. */
|
|
21
|
+
export const REFRESH_PARTS = ['caches', 'backups', 'refs', 'feedback'];
|
|
22
|
+
/** Stores and reasons each part removes. */
|
|
23
|
+
const PART_SCOPE = {
|
|
24
|
+
caches: {
|
|
25
|
+
stores: ['scan-cache', 'legacy-cache'],
|
|
26
|
+
reasons: ['orphan', 'outdated-layout', 'expired', 'unreadable', 'legacy-layout', 'legacy-store'],
|
|
27
|
+
},
|
|
28
|
+
backups: {
|
|
29
|
+
stores: ['backups'],
|
|
30
|
+
reasons: ['retention', 'missing-metadata'],
|
|
31
|
+
},
|
|
32
|
+
refs: {
|
|
33
|
+
stores: ['snapshot-refs'],
|
|
34
|
+
reasons: ['retention', 'ref-without-backup'],
|
|
35
|
+
},
|
|
36
|
+
feedback: {
|
|
37
|
+
stores: ['feedback'],
|
|
38
|
+
reasons: ['duplicate-records', 'outdated-records'],
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
/** Folders below the project root that the caches part may remove from. */
|
|
42
|
+
const CACHE_ROOTS = [CACHE_DIR, LEGACY_STORE_DIR];
|
|
43
|
+
/** Plans of one tool instance, kept in memory only. */
|
|
44
|
+
export class RefreshPlans {
|
|
45
|
+
now;
|
|
46
|
+
git;
|
|
47
|
+
plans = new Map();
|
|
48
|
+
/**
|
|
49
|
+
* @param now clock
|
|
50
|
+
* @param git git runner (snapshot refs are read and deleted through it)
|
|
51
|
+
*/
|
|
52
|
+
constructor(now, git = runGit) {
|
|
53
|
+
this.now = now;
|
|
54
|
+
this.git = git;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Records the items of a report with their fingerprints and the retention the report used.
|
|
58
|
+
*
|
|
59
|
+
* @param projectRoot real path of the project root
|
|
60
|
+
* @returns the plan id and when it expires (ms)
|
|
61
|
+
*/
|
|
62
|
+
create(projectRoot, items, retention) {
|
|
63
|
+
const now = this.now();
|
|
64
|
+
for (const [id, plan] of this.plans) {
|
|
65
|
+
if (plan.expiresAt <= now) {
|
|
66
|
+
this.plans.delete(id);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
while (this.plans.size >= MAX_PLANS) {
|
|
70
|
+
const oldest = this.plans.keys().next().value;
|
|
71
|
+
if (oldest === undefined) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
this.plans.delete(oldest);
|
|
75
|
+
}
|
|
76
|
+
const planned = [];
|
|
77
|
+
for (const item of items) {
|
|
78
|
+
if (inAnyPart(item)) {
|
|
79
|
+
planned.push(this.plan(projectRoot, item));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const planId = randomUUID();
|
|
83
|
+
const expiresAt = now + PLAN_TTL_MS;
|
|
84
|
+
this.plans.set(planId, { projectRoot, retention: { ...retention }, expiresAt, items: planned });
|
|
85
|
+
return { planId, expiresAt };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Removes the planned items of `parts` that a fresh inventory still lists and that are unchanged. The inventory
|
|
89
|
+
* runs with the retention of the report. The plan is used up by the call, whatever the outcome.
|
|
90
|
+
*
|
|
91
|
+
* @param projectRoot real path of the project root
|
|
92
|
+
* @throws when the plan is unknown, expired or belongs to another project
|
|
93
|
+
*/
|
|
94
|
+
apply(planId, projectRoot, parts, inventory, tools) {
|
|
95
|
+
const plan = this.plans.get(planId);
|
|
96
|
+
if (plan === undefined) {
|
|
97
|
+
throw new Error(`Unknown planId ${planId}: run refresh-state with mode 'report' and pass the planId of that report`);
|
|
98
|
+
}
|
|
99
|
+
this.plans.delete(planId);
|
|
100
|
+
if (plan.expiresAt <= this.now()) {
|
|
101
|
+
throw new Error(`planId ${planId} expired (plans are valid for ${PLAN_TTL_MS / 60000} minutes): run a new report`);
|
|
102
|
+
}
|
|
103
|
+
if (plan.projectRoot !== projectRoot) {
|
|
104
|
+
throw new Error(`planId ${planId} belongs to ${plan.projectRoot}, not to ${projectRoot}`);
|
|
105
|
+
}
|
|
106
|
+
const listed = new Set(inventory(plan.retention).map(key));
|
|
107
|
+
const outcome = { removed: [], marked: [], skipped: [] };
|
|
108
|
+
// Feedback items are marked together at the end: one sidecar write for every session file
|
|
109
|
+
const toMark = [];
|
|
110
|
+
for (const planned of plan.items) {
|
|
111
|
+
const { item } = planned;
|
|
112
|
+
if (!parts.some((part) => inPart(item, part))) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
let result;
|
|
116
|
+
if (!listed.has(key(item))) {
|
|
117
|
+
result = { cause: 'no-longer-listed' };
|
|
118
|
+
}
|
|
119
|
+
else if (planned.fingerprint === undefined) {
|
|
120
|
+
result = { cause: planned.cause };
|
|
121
|
+
}
|
|
122
|
+
else if (planned.fingerprint.kind === 'hash') {
|
|
123
|
+
toMark.push({ item, sha256: planned.fingerprint.sha256 });
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
result = this.remove(projectRoot, item, planned.fingerprint);
|
|
128
|
+
}
|
|
129
|
+
if ('cause' in result) {
|
|
130
|
+
outcome.skipped.push({
|
|
131
|
+
store: item.store,
|
|
132
|
+
reason: item.reason,
|
|
133
|
+
path: item.path,
|
|
134
|
+
cause: result.cause,
|
|
135
|
+
...(result.detail === undefined ? {} : { detail: result.detail }),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
outcome.removed.push({
|
|
140
|
+
store: item.store,
|
|
141
|
+
reason: item.reason,
|
|
142
|
+
path: item.path,
|
|
143
|
+
bytes: result.bytes,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (toMark.length > 0) {
|
|
148
|
+
this.mark(projectRoot, planId, toMark, tools, outcome);
|
|
149
|
+
}
|
|
150
|
+
return outcome;
|
|
151
|
+
}
|
|
152
|
+
/** Writes the sidecar marks of the planned session files that are still unchanged. */
|
|
153
|
+
mark(projectRoot, planId, toMark, tools, outcome) {
|
|
154
|
+
const fileOf = (item) => item.path.slice(item.path.lastIndexOf('/') + 1);
|
|
155
|
+
const planned = new Map(toMark.map(({ item, sha256 }) => [fileOf(item), sha256]));
|
|
156
|
+
const result = writeFeedbackMarks(projectRoot, join(projectRoot, FEEDBACK_DIR), planned, tools, planId, this.now());
|
|
157
|
+
for (const { item } of toMark) {
|
|
158
|
+
const file = fileOf(item);
|
|
159
|
+
const skip = (cause, detail) => {
|
|
160
|
+
outcome.skipped.push({
|
|
161
|
+
store: item.store,
|
|
162
|
+
reason: item.reason,
|
|
163
|
+
path: item.path,
|
|
164
|
+
cause,
|
|
165
|
+
...(detail === undefined ? {} : { detail }),
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
if ('error' in result) {
|
|
169
|
+
skip(result.outsideFolder ? 'outside-feedback-folder' : 'failed', result.error);
|
|
170
|
+
}
|
|
171
|
+
else if (result.missing.includes(file)) {
|
|
172
|
+
skip('missing');
|
|
173
|
+
}
|
|
174
|
+
else if (result.changed.includes(file)) {
|
|
175
|
+
skip('changed');
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const records = result.marked.find((m) => m.file === file)?.records ?? 0;
|
|
179
|
+
outcome.marked.push({ store: item.store, reason: item.reason, path: item.path, records });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** Fingerprint of an item at report time, or why it can never be removed. */
|
|
184
|
+
plan(projectRoot, item) {
|
|
185
|
+
if (item.store === 'snapshot-refs') {
|
|
186
|
+
const sha = refTarget(this.git, projectRoot, item.path);
|
|
187
|
+
return sha === undefined
|
|
188
|
+
? { item, fingerprint: undefined, cause: 'missing' }
|
|
189
|
+
: { item, fingerprint: { kind: 'ref', sha } };
|
|
190
|
+
}
|
|
191
|
+
if (item.store === 'feedback') {
|
|
192
|
+
return feedbackFingerprint(projectRoot, item);
|
|
193
|
+
}
|
|
194
|
+
if (item.store === 'backups' && item.reason === 'retention') {
|
|
195
|
+
const members = groupStamps(projectRoot, item.path);
|
|
196
|
+
return 'cause' in members
|
|
197
|
+
? { item, fingerprint: undefined, cause: members.cause }
|
|
198
|
+
: { item, fingerprint: { kind: 'group', members } };
|
|
199
|
+
}
|
|
200
|
+
const path = join(projectRoot, item.path);
|
|
201
|
+
const fingerprint = fingerprintOf(path);
|
|
202
|
+
if (fingerprint !== undefined) {
|
|
203
|
+
return { item, fingerprint };
|
|
204
|
+
}
|
|
205
|
+
return { item, fingerprint: undefined, cause: lstat(path) === undefined ? 'missing' : 'symbolic-link' };
|
|
206
|
+
}
|
|
207
|
+
/** Removes one listed item when it is unchanged against its fingerprint. */
|
|
208
|
+
remove(projectRoot, item, planned) {
|
|
209
|
+
switch (planned.kind) {
|
|
210
|
+
case 'ref':
|
|
211
|
+
return removeRef(this.git, projectRoot, item.path, planned.sha);
|
|
212
|
+
case 'group':
|
|
213
|
+
return removeGroup(projectRoot, item.path, planned.members);
|
|
214
|
+
case 'path':
|
|
215
|
+
return removePath(projectRoot, item, planned);
|
|
216
|
+
case 'hash':
|
|
217
|
+
// Feedback items are marked in apply(), never removed
|
|
218
|
+
return { cause: 'failed', detail: 'feedback records are marked, not removed' };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/** SHA-256 of a session file at report time; a link or a file outside the sessions folder is never marked. */
|
|
223
|
+
function feedbackFingerprint(projectRoot, item) {
|
|
224
|
+
const path = join(projectRoot, item.path);
|
|
225
|
+
const s = lstat(path);
|
|
226
|
+
if (s === undefined) {
|
|
227
|
+
return { item, fingerprint: undefined, cause: 'missing' };
|
|
228
|
+
}
|
|
229
|
+
if (s.isSymbolicLink()) {
|
|
230
|
+
return { item, fingerprint: undefined, cause: 'symbolic-link' };
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
if (realpathSync(path) !== path || dirname(path) !== join(projectRoot, FEEDBACK_DIR)) {
|
|
234
|
+
return { item, fingerprint: undefined, cause: 'outside-feedback-folder' };
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
item,
|
|
238
|
+
fingerprint: { kind: 'hash', sha256: createHash('sha256').update(readFileSync(path)).digest('hex') },
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return { item, fingerprint: undefined, cause: 'missing' };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function key(item) {
|
|
246
|
+
return `${item.store}\0${item.reason}\0${item.path}`;
|
|
247
|
+
}
|
|
248
|
+
function inPart(item, part) {
|
|
249
|
+
const scope = PART_SCOPE[part];
|
|
250
|
+
return scope.stores.includes(item.store) && scope.reasons.includes(item.reason);
|
|
251
|
+
}
|
|
252
|
+
function inAnyPart(item) {
|
|
253
|
+
return REFRESH_PARTS.some((part) => inPart(item, part));
|
|
254
|
+
}
|
|
255
|
+
function lstat(path) {
|
|
256
|
+
try {
|
|
257
|
+
return lstatSync(path);
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function errorText(error) {
|
|
264
|
+
return error instanceof Error ? error.message : String(error);
|
|
265
|
+
}
|
|
266
|
+
/** Object a ref points at, `undefined` when the ref does not exist. */
|
|
267
|
+
function refTarget(git, projectRoot, ref) {
|
|
268
|
+
const sha = git(projectRoot, ['rev-parse', '--verify', '--quiet', ref])?.trim();
|
|
269
|
+
return sha === undefined || sha === '' ? undefined : sha;
|
|
270
|
+
}
|
|
271
|
+
/** Deletes `ref` only while it still points at `sha` (git compares and deletes in one step). */
|
|
272
|
+
function removeRef(git, projectRoot, ref, sha) {
|
|
273
|
+
if (git(projectRoot, ['update-ref', '-d', ref, sha]) !== undefined) {
|
|
274
|
+
return { bytes: 0 };
|
|
275
|
+
}
|
|
276
|
+
const now = refTarget(git, projectRoot, ref);
|
|
277
|
+
if (now === undefined) {
|
|
278
|
+
return { cause: 'missing' };
|
|
279
|
+
}
|
|
280
|
+
return { cause: now === sha ? 'failed' : 'changed' };
|
|
281
|
+
}
|
|
282
|
+
/** The backup folder, when it is a real folder at its own path. */
|
|
283
|
+
function backupFolder(projectRoot) {
|
|
284
|
+
const dir = join(projectRoot, BACKUP_DIR);
|
|
285
|
+
try {
|
|
286
|
+
return realpathSync(dir) === dir ? dir : undefined;
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/** Size and mtime of each file of a backup group, sorted by name, or why the group cannot be removed. */
|
|
293
|
+
function groupStamps(projectRoot, groupId) {
|
|
294
|
+
const dir = backupFolder(projectRoot);
|
|
295
|
+
if (dir === undefined) {
|
|
296
|
+
return { cause: lstat(join(projectRoot, BACKUP_DIR)) === undefined ? 'missing' : 'outside-backup-folder' };
|
|
297
|
+
}
|
|
298
|
+
const names = backupGroupMembers(projectRoot).get(groupId);
|
|
299
|
+
if (names === undefined) {
|
|
300
|
+
return { cause: 'missing' };
|
|
301
|
+
}
|
|
302
|
+
const stamps = [];
|
|
303
|
+
for (const name of [...names].sort()) {
|
|
304
|
+
const s = lstat(join(dir, name));
|
|
305
|
+
if (s === undefined) {
|
|
306
|
+
return { cause: 'changed' };
|
|
307
|
+
}
|
|
308
|
+
if (s.isSymbolicLink()) {
|
|
309
|
+
return { cause: 'symbolic-link' };
|
|
310
|
+
}
|
|
311
|
+
if (!s.isFile()) {
|
|
312
|
+
return { cause: 'changed' };
|
|
313
|
+
}
|
|
314
|
+
stamps.push({ name, size: s.size, mtimeMs: s.mtimeMs });
|
|
315
|
+
}
|
|
316
|
+
return stamps;
|
|
317
|
+
}
|
|
318
|
+
/** Removes exactly the files of the group the report saw, while the group still has exactly those files unchanged. */
|
|
319
|
+
function removeGroup(projectRoot, groupId, planned) {
|
|
320
|
+
const now = groupStamps(projectRoot, groupId);
|
|
321
|
+
if ('cause' in now) {
|
|
322
|
+
return now;
|
|
323
|
+
}
|
|
324
|
+
const stampKey = (stamps) => stamps.map((stamp) => `${stamp.name}\0${stamp.size}\0${stamp.mtimeMs}`).join('\n');
|
|
325
|
+
if (stampKey(now) !== stampKey(planned)) {
|
|
326
|
+
return { cause: 'changed' };
|
|
327
|
+
}
|
|
328
|
+
const dir = join(projectRoot, BACKUP_DIR);
|
|
329
|
+
let removed = 0;
|
|
330
|
+
for (const stamp of planned) {
|
|
331
|
+
try {
|
|
332
|
+
unlinkSync(join(dir, stamp.name));
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
return {
|
|
336
|
+
cause: 'failed',
|
|
337
|
+
detail: `${removed} of ${planned.length} files removed; ${stamp.name}: ${errorText(error)}`,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
removed++;
|
|
341
|
+
}
|
|
342
|
+
return { bytes: planned.reduce((sum, stamp) => sum + stamp.size, 0) };
|
|
343
|
+
}
|
|
344
|
+
/** Removes a cache entry, legacy cache folder or backup file without metadata. */
|
|
345
|
+
function removePath(projectRoot, item, planned) {
|
|
346
|
+
const path = join(projectRoot, item.path);
|
|
347
|
+
const check = checkRemovable(projectRoot, path, planned, item.store);
|
|
348
|
+
if (check !== undefined) {
|
|
349
|
+
return { cause: check };
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
if (planned.directory) {
|
|
353
|
+
rmSync(path, { recursive: true });
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
unlinkSync(path);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
return { cause: 'failed', detail: errorText(error) };
|
|
361
|
+
}
|
|
362
|
+
return { bytes: planned.bytes };
|
|
363
|
+
}
|
|
364
|
+
/** Fingerprint of a file or folder; `undefined` when missing or a link. */
|
|
365
|
+
function fingerprintOf(path) {
|
|
366
|
+
const s = lstat(path);
|
|
367
|
+
if (s === undefined || s.isSymbolicLink()) {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
if (!s.isDirectory()) {
|
|
371
|
+
return { kind: 'path', directory: false, bytes: s.size, files: 1, newestMtimeMs: s.mtimeMs };
|
|
372
|
+
}
|
|
373
|
+
const tree = walk(path);
|
|
374
|
+
return tree.links > 0
|
|
375
|
+
? undefined
|
|
376
|
+
: { kind: 'path', directory: true, bytes: tree.bytes, files: tree.files, newestMtimeMs: tree.newest };
|
|
377
|
+
}
|
|
378
|
+
function walk(dir) {
|
|
379
|
+
let bytes = 0;
|
|
380
|
+
let files = 0;
|
|
381
|
+
let newest = 0;
|
|
382
|
+
let links = 0;
|
|
383
|
+
let names;
|
|
384
|
+
try {
|
|
385
|
+
names = readdirSync(dir);
|
|
386
|
+
}
|
|
387
|
+
catch {
|
|
388
|
+
return { bytes, files, newest, links };
|
|
389
|
+
}
|
|
390
|
+
for (const name of names) {
|
|
391
|
+
const path = join(dir, name);
|
|
392
|
+
const s = lstat(path);
|
|
393
|
+
if (s === undefined) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (s.isSymbolicLink()) {
|
|
397
|
+
links++;
|
|
398
|
+
}
|
|
399
|
+
else if (s.isDirectory()) {
|
|
400
|
+
const sub = walk(path);
|
|
401
|
+
bytes += sub.bytes;
|
|
402
|
+
files += sub.files;
|
|
403
|
+
newest = Math.max(newest, sub.newest);
|
|
404
|
+
links += sub.links;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
bytes += s.size;
|
|
408
|
+
files++;
|
|
409
|
+
newest = Math.max(newest, s.mtimeMs);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return { bytes, files, newest, links };
|
|
413
|
+
}
|
|
414
|
+
/** Below a cache folder, or the legacy store folder itself; never the cache folder itself. */
|
|
415
|
+
function insideCacheFolder(projectRoot, real) {
|
|
416
|
+
return (real === join(projectRoot, LEGACY_STORE_DIR) ||
|
|
417
|
+
CACHE_ROOTS.some((dir) => real.startsWith(join(projectRoot, dir) + sep)));
|
|
418
|
+
}
|
|
419
|
+
/** Why `path` must stay, or `undefined` when it may be removed. */
|
|
420
|
+
function checkRemovable(projectRoot, path, planned, store) {
|
|
421
|
+
const s = lstat(path);
|
|
422
|
+
if (s === undefined) {
|
|
423
|
+
return 'missing';
|
|
424
|
+
}
|
|
425
|
+
if (s.isSymbolicLink()) {
|
|
426
|
+
return 'symbolic-link';
|
|
427
|
+
}
|
|
428
|
+
let real;
|
|
429
|
+
try {
|
|
430
|
+
real = realpathSync(path);
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
return 'missing';
|
|
434
|
+
}
|
|
435
|
+
// A real path other than the path itself means a linked folder on the way
|
|
436
|
+
if (store === 'backups') {
|
|
437
|
+
// A backup file without metadata lies directly in the backup folder
|
|
438
|
+
if (real !== path || dirname(real) !== join(projectRoot, BACKUP_DIR)) {
|
|
439
|
+
return 'outside-backup-folder';
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
else if (real !== path || !insideCacheFolder(projectRoot, real)) {
|
|
443
|
+
return 'outside-cache-folder';
|
|
444
|
+
}
|
|
445
|
+
if (s.isDirectory() !== planned.directory) {
|
|
446
|
+
return 'changed';
|
|
447
|
+
}
|
|
448
|
+
if (planned.directory && walk(path).links > 0) {
|
|
449
|
+
return 'symbolic-link';
|
|
450
|
+
}
|
|
451
|
+
const now = fingerprintOf(path);
|
|
452
|
+
if (now === undefined ||
|
|
453
|
+
now.bytes !== planned.bytes ||
|
|
454
|
+
now.files !== planned.files ||
|
|
455
|
+
now.newestMtimeMs !== planned.newestMtimeMs) {
|
|
456
|
+
return 'changed';
|
|
457
|
+
}
|
|
458
|
+
return undefined;
|
|
459
|
+
}
|
|
460
|
+
//# sourceMappingURL=refresh-apply.js.map
|