@animastor/installer 0.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/LICENSE +21 -0
- package/README.md +66 -0
- package/ai/install-manifests/audio/qwen-tts.json +445 -0
- package/ai/install-manifests/image/qwen-image.json +465 -0
- package/ai/install-manifests/video/ltx-2.3.json +892 -0
- package/package.json +42 -0
- package/src/installer/cli.js +1067 -0
- package/src/installer/compatibility-resolver.js +1287 -0
- package/src/installer/download-planner.js +172 -0
- package/src/installer/engine/comfyui.js +508 -0
- package/src/installer/engine/downloader.js +514 -0
- package/src/installer/engine/engine.js +1180 -0
- package/src/installer/engine/io.js +437 -0
- package/src/installer/engine/logger.js +75 -0
- package/src/installer/engine/nodes.js +146 -0
- package/src/installer/engine/prereq.js +399 -0
- package/src/installer/engine/probe.js +349 -0
- package/src/installer/engine/progress.js +350 -0
- package/src/installer/engine/state.js +170 -0
- package/src/installer/engine/term.js +298 -0
- package/src/installer/engine/worker.js +430 -0
- package/src/installer/engine/workflows.js +153 -0
- package/src/installer/index.js +40 -0
- package/src/installer/install-manifest.js +376 -0
- package/src/installer/install-plan.js +741 -0
- package/src/installer/management.js +489 -0
- package/src/installer/platform/deployment/docker.js +78 -0
- package/src/installer/platform/deployment/native.js +36 -0
- package/src/installer/platform/index.js +165 -0
- package/src/installer/platform/linux.js +341 -0
- package/src/installer/platform/windows.js +360 -0
- package/src/installer/safety-rules.js +156 -0
- package/src/installer/setup-contract.js +1401 -0
- package/src/installer/uninstaller.js +572 -0
- package/src/installer/verification-report.js +220 -0
- package/src/installer/worker-bundle-source.js +64 -0
- package/src/installer/workflow-artifacts.js +152 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Verification Report — Private Worker Installer Phase 1.5.
|
|
5
|
+
*
|
|
6
|
+
* Renders the final post-install verification result from a resolution
|
|
7
|
+
* report plus optional live checks (ComfyUI API, worker health, GPU Hub
|
|
8
|
+
* registration). Output is the user-facing verdict:
|
|
9
|
+
*
|
|
10
|
+
* INSTALLATION COMPLETE
|
|
11
|
+
* ✓ GPU
|
|
12
|
+
* ✓ ComfyUI
|
|
13
|
+
* ...
|
|
14
|
+
*
|
|
15
|
+
* or precise FAIL/WARN lines. Live checks that were not performed are
|
|
16
|
+
* reported as WARN "not checked" — never silently assumed passed.
|
|
17
|
+
*
|
|
18
|
+
* EXCEPTION — profile workflows: they are OPTIONAL demo/test artifacts
|
|
19
|
+
* (Animastor sends workflow JSON with each task via the API), so their
|
|
20
|
+
* absence is reported as a neutral [i] info line and never as a FAIL/WARN,
|
|
21
|
+
* and workflow problems never fail the whole installation verdict.
|
|
22
|
+
*
|
|
23
|
+
* Secret safety: this module only ever receives key NAMES and boolean
|
|
24
|
+
* flags; a Worker Key value must never be passed in or rendered.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const OK = '\u2713';
|
|
28
|
+
const FAIL = '\u2717';
|
|
29
|
+
const WARN = '!';
|
|
30
|
+
const INFO = 'i';
|
|
31
|
+
|
|
32
|
+
function line(ok, label, detail) {
|
|
33
|
+
const mark = ok === true ? OK : ok === false ? FAIL : WARN;
|
|
34
|
+
return detail ? `${mark} ${label} — ${detail}` : `${mark} ${label}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Neutral, non-scored line: neither a fail nor a warning (severity-free). */
|
|
38
|
+
function infoLine(label, detail) {
|
|
39
|
+
return detail ? `[${INFO}] ${label} — ${detail}` : `[${INFO}] ${label}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** tri-state normalizer: true | false | null(unknown) */
|
|
43
|
+
function tri(v) {
|
|
44
|
+
if (v === true) return true;
|
|
45
|
+
if (v === false) return false;
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function verdictOf(entries) {
|
|
50
|
+
if (entries.some((e) => e.status === 'missing' && e.requirement === 'required')) return false;
|
|
51
|
+
if (entries.some((e) => e.status === 'incompatible')) return false;
|
|
52
|
+
if (entries.some((e) => e.status === 'required' || e.status === 'unknown')) return null;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function detailOf(entries) {
|
|
57
|
+
const problems = entries
|
|
58
|
+
.filter((e) => e.status === 'missing' || e.status === 'incompatible')
|
|
59
|
+
.map((e) => `${e.name || e.id}: ${e.status}${e.reason ? ` (${e.reason})` : ''}`);
|
|
60
|
+
return problems.length > 0 ? problems.join('; ') : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function summarizeRuntime(entries) {
|
|
64
|
+
return entries
|
|
65
|
+
.filter((e) => e.status === 'installed')
|
|
66
|
+
.map((e) => `${e.component}${e.found && e.found.version ? ` ${e.found.version}` : ''}`)
|
|
67
|
+
.join(', ') || null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {object} args
|
|
72
|
+
* @param {object} args.report - resolver report
|
|
73
|
+
* @param {object} [args.live] - optional live check results:
|
|
74
|
+
* {
|
|
75
|
+
* comfyui: { running, api_reachable, version, missing_node_classes[] },
|
|
76
|
+
* workflow: { accepted, missing_node_classes[] },
|
|
77
|
+
* worker: { process_alive, registered, health },
|
|
78
|
+
* hub: { connection, registration },
|
|
79
|
+
* }
|
|
80
|
+
* Each sub-object/field may be omitted (= not checked → WARN).
|
|
81
|
+
*/
|
|
82
|
+
function buildVerificationReport({ report, live = {} }) {
|
|
83
|
+
if (!report || !Array.isArray(report.entries)) {
|
|
84
|
+
throw new Error('buildVerificationReport requires a resolution report');
|
|
85
|
+
}
|
|
86
|
+
const lines = [];
|
|
87
|
+
let fails = 0;
|
|
88
|
+
let warns = 0;
|
|
89
|
+
|
|
90
|
+
const push = (verdict, label, detail) => {
|
|
91
|
+
lines.push(line(verdict, label, detail));
|
|
92
|
+
if (verdict === false) fails += 1;
|
|
93
|
+
else if (verdict === null) warns += 1;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const byKind = (kind) => report.entries.filter((e) => e.kind === kind);
|
|
97
|
+
|
|
98
|
+
// --- Machine -----------------------------------------------------------
|
|
99
|
+
const hw = report.hardware || {};
|
|
100
|
+
if (hw.device === 'cpu') {
|
|
101
|
+
push(null, 'GPU', 'not detected — CPU-only mode (ComfyUI runs with --cpu; performance significantly lower; intended for the TTS/audio profile)');
|
|
102
|
+
} else if (hw.gpu && hw.gpu.name) {
|
|
103
|
+
push(true, 'GPU', `${hw.gpu.name}${typeof hw.gpu.vram_mib === 'number' ? `, ${Math.round(hw.gpu.vram_mib / 1024)} GB VRAM` : ''}`);
|
|
104
|
+
} else {
|
|
105
|
+
push(false, 'GPU', 'no GPU detected');
|
|
106
|
+
}
|
|
107
|
+
if (hw.device !== 'cpu' && hw.sufficient_vram === false) {
|
|
108
|
+
push(false, 'VRAM', (hw.notes || []).join('; ') || 'below manifest minimum');
|
|
109
|
+
} else if (hw.device !== 'cpu' && hw.sufficient_vram === null) {
|
|
110
|
+
push(null, 'VRAM', 'minimum unknown — not verified');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const runtimeEntries = byKind('runtime');
|
|
114
|
+
push(verdictOf(runtimeEntries), 'Runtime', detailOf(runtimeEntries) || summarizeRuntime(runtimeEntries));
|
|
115
|
+
|
|
116
|
+
// --- ComfyUI -----------------------------------------------------------
|
|
117
|
+
const comfy = report.entries.find((e) => e.id === 'runtime:comfyui');
|
|
118
|
+
const comfyVerdict = comfy
|
|
119
|
+
? (comfy.status === 'installed' ? true : (comfy.status === 'missing' || comfy.status === 'incompatible') ? false : null)
|
|
120
|
+
: null;
|
|
121
|
+
push(comfyVerdict, 'ComfyUI', comfy && comfy.found && comfy.found.version ? `version ${comfy.found.version}` : detailOf(comfy ? [comfy] : []));
|
|
122
|
+
|
|
123
|
+
if (live.comfyui) {
|
|
124
|
+
const c = live.comfyui;
|
|
125
|
+
push(tri(c.running), 'ComfyUI running');
|
|
126
|
+
push(tri(c.api_reachable), 'ComfyUI API');
|
|
127
|
+
if (Array.isArray(c.missing_node_classes) && c.missing_node_classes.length > 0) {
|
|
128
|
+
// When the providing custom node files ARE on disk (resolver says
|
|
129
|
+
// installed) but the live registry lacks the classes, the running
|
|
130
|
+
// instance is stale or the node import failed — say so precisely
|
|
131
|
+
// instead of implying the node is absent.
|
|
132
|
+
const nodeEntriesAll = byKind('custom_node');
|
|
133
|
+
const presentButUnregistered = nodeEntriesAll.length > 0
|
|
134
|
+
&& nodeEntriesAll.every((e) => e.status === 'installed');
|
|
135
|
+
push(false, 'ComfyUI node classes', `missing: ${c.missing_node_classes.join(', ')}${presentButUnregistered
|
|
136
|
+
? ' — the node files are present, but the running ComfyUI did not register them (import failed — see <ComfyUI>/comfyui-installer.log — or the instance predates the install); restart ComfyUI and re-run verify'
|
|
137
|
+
: ''}`);
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
push(null, 'ComfyUI API', 'not checked (start ComfyUI and re-run verification)');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// --- Custom nodes ------------------------------------------------------
|
|
144
|
+
const nodeEntries = byKind('custom_node').filter((e) => e.requirement === 'required' || e.status === 'incompatible');
|
|
145
|
+
push(verdictOf(nodeEntries), 'Custom Nodes', detailOf(nodeEntries));
|
|
146
|
+
|
|
147
|
+
// --- Models ------------------------------------------------------------
|
|
148
|
+
const modelEntries = byKind('model').concat(byKind('model_repo')).filter((e) => e.requirement === 'required' || e.status === 'incompatible');
|
|
149
|
+
push(verdictOf(modelEntries), 'Models', detailOf(modelEntries));
|
|
150
|
+
|
|
151
|
+
// --- Workflows (OPTIONAL demo/test artifacts — never scored) -----------
|
|
152
|
+
// Missing profile workflows are NOT a failure, incomplete state, or
|
|
153
|
+
// warning: the runtime sends workflow JSON with each task via the API.
|
|
154
|
+
// They are only reported neutrally so the user knows what was skipped.
|
|
155
|
+
const wfEntries = byKind('workflow');
|
|
156
|
+
const wfMissing = wfEntries.filter((e) => e.status === 'missing');
|
|
157
|
+
const customized = wfEntries.filter((e) => e.grade === 'customized');
|
|
158
|
+
const wfInstalled = wfEntries.filter((e) => e.status === 'installed');
|
|
159
|
+
if (wfEntries.length > 0) {
|
|
160
|
+
lines.push(infoLine('Profile workflows', wfInstalled.length > 0
|
|
161
|
+
? `${wfInstalled.length} installed${customized.length > 0 ? `, ${customized.length} customized by user (allowed)` : ''}${wfMissing.length > 0 ? `, ${wfMissing.length} not installed` : ''} — optional; needed only to test ComfyUI locally or as a starting point for your own workflows`
|
|
162
|
+
: wfMissing.length > 0
|
|
163
|
+
? `${wfMissing.length} not installed — optional; they are only needed to test ComfyUI locally or as a starting point for your own workflows`
|
|
164
|
+
: 'optional; none declared by the selected profile(s)'));
|
|
165
|
+
lines.push(infoLine('Profile workflows', 'not required for API-based generation (workflow JSON is delivered with each task)'));
|
|
166
|
+
}
|
|
167
|
+
if (live.workflow) {
|
|
168
|
+
const w = live.workflow;
|
|
169
|
+
if (Array.isArray(w.problems) && w.problems.length > 0) {
|
|
170
|
+
lines.push(infoLine('Workflow accepted by ComfyUI', `installed workflow copies have problems: ${w.problems.join('; ')} — optional local copies; replace or re-download them if you want to test in the ComfyUI Web UI`));
|
|
171
|
+
} else if (w.accepted === false) {
|
|
172
|
+
lines.push(infoLine('Workflow accepted by ComfyUI', 'not verified — optional local copies; generation via the API is unaffected'));
|
|
173
|
+
} else {
|
|
174
|
+
lines.push(infoLine('Workflow accepted by ComfyUI', 'installed copies are valid JSON (optional local copies)'));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// --- Worker --------------------------------------------------------------
|
|
179
|
+
const workerEntries = byKind('worker');
|
|
180
|
+
push(verdictOf(workerEntries), 'Worker', detailOf(workerEntries));
|
|
181
|
+
|
|
182
|
+
const unconfigured = workerEntries.filter((e) => e.action === 'configure');
|
|
183
|
+
if (unconfigured.length > 0) {
|
|
184
|
+
const missingKeys = unconfigured
|
|
185
|
+
.map((e) => ((e.env && e.env.missing_required) || []).join(', '))
|
|
186
|
+
.filter(Boolean)
|
|
187
|
+
.join('; ');
|
|
188
|
+
push(false, 'Worker .env / Worker Key', missingKeys ? `configuration incomplete: ${missingKeys}` : 'interactive setup required');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (live.worker) {
|
|
192
|
+
const wk = live.worker;
|
|
193
|
+
push(tri(wk.process_alive), 'Worker process');
|
|
194
|
+
push(tri(wk.registered), 'Worker registration');
|
|
195
|
+
if (wk.health !== undefined) push(tri(wk.health), 'Worker health');
|
|
196
|
+
} else {
|
|
197
|
+
push(null, 'Worker process / registration', 'not checked');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (live.hub) {
|
|
201
|
+
push(tri(live.hub.connection), 'GPU Hub connection');
|
|
202
|
+
push(tri(live.hub.registration), 'GPU Hub registration');
|
|
203
|
+
} else {
|
|
204
|
+
push(null, 'GPU Hub registration', 'not checked');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const status = fails > 0 ? 'FAIL' : warns > 0 ? 'WARN' : 'PASS';
|
|
208
|
+
const header = status === 'PASS'
|
|
209
|
+
? 'INSTALLATION COMPLETE'
|
|
210
|
+
: status === 'WARN'
|
|
211
|
+
? 'INSTALLATION COMPLETE WITH WARNINGS'
|
|
212
|
+
: 'INSTALLATION INCOMPLETE';
|
|
213
|
+
|
|
214
|
+
const text = [header, '', ...lines].join('\n');
|
|
215
|
+
return { status, fails, warns, lines, text };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
module.exports = {
|
|
219
|
+
buildVerificationReport,
|
|
220
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Repo-checkout location of the Animastor Worker bundle source.
|
|
5
|
+
*
|
|
6
|
+
* Canonical location: packages/animastor-worker/worker — the worker package
|
|
7
|
+
* boundary is being relocated there (see
|
|
8
|
+
* docs/architecture/WORKER_PACKAGE_RELOCATION_AUDIT.md and
|
|
9
|
+
* docs/architecture/WORKER_PACKAGE_RELOCATION_CHECKLIST.md). The legacy repo
|
|
10
|
+
* path `worker/worker` is kept as an existsSync/isDirectory-guarded fallback
|
|
11
|
+
* so repo checkouts from BEFORE the physical relocation commit keep
|
|
12
|
+
* installing; the fallback becomes inert (never matches) once the physical
|
|
13
|
+
* `git mv worker/worker packages/animastor-worker` lands and may be pruned
|
|
14
|
+
* in a later cleanup.
|
|
15
|
+
*
|
|
16
|
+
* Two-sided contract: the GPU Hub installer-package tar entries
|
|
17
|
+
* (`animastor-installer/packages/animastor-worker/worker/*` in
|
|
18
|
+
* packages/animastor-gpu-hub/gpu-hub.js) mirror the canonical layout, so the
|
|
19
|
+
* engine inside an extracted installer package resolves its bundled copy
|
|
20
|
+
* through the same canonical branch. Both sides ship from the same repo
|
|
21
|
+
* build — never change one without the other.
|
|
22
|
+
*
|
|
23
|
+
* The resolver takes an injectable fs (io.fs adapter or node fs) so tests
|
|
24
|
+
* can emulate repo layouts with mock filesystems.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const path = require('path');
|
|
28
|
+
|
|
29
|
+
/** Repo-relative bundle dir segments — canonical first, legacy fallback. */
|
|
30
|
+
const REPO_BUNDLE_DIRS = [
|
|
31
|
+
['packages', 'animastor-worker', 'worker'],
|
|
32
|
+
['worker', 'worker'],
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
/** Tolerate both io.fs adapters (isDirectory helper) and node fs. */
|
|
36
|
+
function isDir(fsLike, dir) {
|
|
37
|
+
try {
|
|
38
|
+
if (typeof fsLike.isDirectory === 'function') return fsLike.isDirectory(dir);
|
|
39
|
+
return fsLike.statSync(dir).isDirectory();
|
|
40
|
+
} catch (_) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* First existing repo-checkout bundle dir (canonical first), or null when
|
|
47
|
+
* the checkout carries neither layout. Never returns a non-existent path.
|
|
48
|
+
* @param {object} fsLike - io.fs adapter or node fs (statSync/isDirectory)
|
|
49
|
+
* @param {string|null} repoRoot
|
|
50
|
+
* @returns {string|null}
|
|
51
|
+
*/
|
|
52
|
+
function resolveRepoBundleDir(fsLike, repoRoot) {
|
|
53
|
+
if (!repoRoot || !fsLike) return null;
|
|
54
|
+
for (const segments of REPO_BUNDLE_DIRS) {
|
|
55
|
+
const dir = path.join(repoRoot, ...segments);
|
|
56
|
+
if (isDir(fsLike, dir)) return dir;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = {
|
|
62
|
+
REPO_BUNDLE_DIRS,
|
|
63
|
+
resolveRepoBundleDir,
|
|
64
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Workflow Artifacts — Private Worker Installer Phase 1.5.
|
|
5
|
+
*
|
|
6
|
+
* Baseline workflows are FIRST-CLASS install artifacts. A Generation Profile
|
|
7
|
+
* defines its production (baseline) workflows; the installer can list them,
|
|
8
|
+
* download selected ones into a user-visible location, and leave them alone
|
|
9
|
+
* afterwards.
|
|
10
|
+
*
|
|
11
|
+
* Core principle: "a baseline workflow is an editable starting point, not an
|
|
12
|
+
* immutable configuration". Consequences:
|
|
13
|
+
* - the installer writes a baseline file once and never modifies it;
|
|
14
|
+
* - a user copy that differs from the baseline is NOT an error;
|
|
15
|
+
* - the installer never overwrites or deletes a user's workflow;
|
|
16
|
+
* - restoring the official baseline = downloading a FRESH copy under a
|
|
17
|
+
* distinct name (freshCopyPath), so "Animastor baseline" and
|
|
18
|
+
* "My customized workflow" coexist without conflict.
|
|
19
|
+
*
|
|
20
|
+
* This module is pure (no fs/network) — it only computes paths and download
|
|
21
|
+
* intents. The future installer engine executes them.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function normPath(p) {
|
|
25
|
+
return String(p || '').replace(/\\/g, '/').replace(/^\/+/, '').replace(/\/+$/, '');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** All baseline workflow artifacts declared by a manifest. */
|
|
29
|
+
function listProfileWorkflows(manifest) {
|
|
30
|
+
const section = manifest && manifest.workflows;
|
|
31
|
+
if (!section || !Array.isArray(section.artifacts)) return [];
|
|
32
|
+
return section.artifacts.slice();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Baseline target path (relative to the ComfyUI root). */
|
|
36
|
+
function baselineTargetPath(wf) {
|
|
37
|
+
return `${normPath(wf.target_dir)}/${wf.filename}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Path for a FRESH official copy when the baseline path already holds a
|
|
42
|
+
* user-customized file: same directory, suffixed name, e.g.
|
|
43
|
+
* img-qwen-image.json → img-qwen-image.animastor-baseline.json
|
|
44
|
+
* Guarantees the user's customized copy is never touched.
|
|
45
|
+
*/
|
|
46
|
+
function freshCopyPath(wf) {
|
|
47
|
+
const dir = normPath(wf.target_dir);
|
|
48
|
+
const file = wf.filename;
|
|
49
|
+
const dot = file.lastIndexOf('.');
|
|
50
|
+
const renamed = dot > 0 ? `${file.slice(0, dot)}.animastor-baseline${file.slice(dot)}` : `${file}.animastor-baseline`;
|
|
51
|
+
return `${dir}/${renamed}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Plan baseline workflow downloads for one manifest against an environment
|
|
56
|
+
* probe. Pure function; returns an array of download intents:
|
|
57
|
+
* { id, name, target_path, reason, overwrite: false, fresh_copy }
|
|
58
|
+
*
|
|
59
|
+
* Selection semantics:
|
|
60
|
+
* selection = 'all' | 'none' | array of workflow ids.
|
|
61
|
+
* - missing baselines are proposed for download (only if selected);
|
|
62
|
+
* - present baselines are skipped (never re-downloaded silently);
|
|
63
|
+
* - customized baselines are skipped; a fresh copy is proposed ONLY when
|
|
64
|
+
* the caller explicitly passes { restoreBaseline: true }.
|
|
65
|
+
*
|
|
66
|
+
* `overwrite` is always false — a hard invariant of Phase 1.5.
|
|
67
|
+
*/
|
|
68
|
+
function planWorkflowDownloads(manifest, env, selection = 'all', opts = {}) {
|
|
69
|
+
const artifacts = listProfileWorkflows(manifest);
|
|
70
|
+
const selected = (id) => selection === 'all' || (Array.isArray(selection) && selection.includes(id));
|
|
71
|
+
const plans = [];
|
|
72
|
+
|
|
73
|
+
for (const wf of artifacts) {
|
|
74
|
+
if (!selected(wf.id)) continue;
|
|
75
|
+
const target = baselineTargetPath(wf);
|
|
76
|
+
const found = env && Array.isArray(env.workflows)
|
|
77
|
+
? env.workflows.find((w) => normPath(w.path) === target)
|
|
78
|
+
: null;
|
|
79
|
+
|
|
80
|
+
if (!found) {
|
|
81
|
+
plans.push({
|
|
82
|
+
id: wf.id,
|
|
83
|
+
name: wf.name,
|
|
84
|
+
target_path: target,
|
|
85
|
+
source: wf.source,
|
|
86
|
+
reason: 'missing',
|
|
87
|
+
overwrite: false,
|
|
88
|
+
fresh_copy: false,
|
|
89
|
+
});
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const customized = wf.baseline_sha256 && found.sha256
|
|
94
|
+
&& String(found.sha256).toLowerCase() !== String(wf.baseline_sha256).toLowerCase();
|
|
95
|
+
|
|
96
|
+
if (customized && opts.restoreBaseline === true) {
|
|
97
|
+
plans.push({
|
|
98
|
+
id: wf.id,
|
|
99
|
+
name: wf.name,
|
|
100
|
+
target_path: freshCopyPath(wf),
|
|
101
|
+
source: wf.source,
|
|
102
|
+
reason: 'restore-fresh-copy',
|
|
103
|
+
overwrite: false,
|
|
104
|
+
fresh_copy: true,
|
|
105
|
+
note: 'user copy differs from the Animastor baseline; fresh copy goes to a distinct path, the user copy is untouched',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// present (canonical or customized) → no download; never overwritten
|
|
109
|
+
}
|
|
110
|
+
return plans;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Summarize workflow state for plan rendering:
|
|
115
|
+
* { baselines_total, installed, missing, customized, user_extras }
|
|
116
|
+
*/
|
|
117
|
+
function summarizeWorkflowState(manifest, env) {
|
|
118
|
+
const artifacts = listProfileWorkflows(manifest);
|
|
119
|
+
const summary = { baselines_total: artifacts.length, installed: 0, missing: 0, customized: 0, user_extras: 0 };
|
|
120
|
+
const baselinePaths = new Set();
|
|
121
|
+
|
|
122
|
+
for (const wf of artifacts) {
|
|
123
|
+
const target = baselineTargetPath(wf);
|
|
124
|
+
baselinePaths.add(target);
|
|
125
|
+
const found = env && Array.isArray(env.workflows)
|
|
126
|
+
? env.workflows.find((w) => normPath(w.path) === target)
|
|
127
|
+
: null;
|
|
128
|
+
if (!found) {
|
|
129
|
+
summary.missing += 1;
|
|
130
|
+
} else if (wf.baseline_sha256 && found.sha256
|
|
131
|
+
&& String(found.sha256).toLowerCase() !== String(wf.baseline_sha256).toLowerCase()) {
|
|
132
|
+
summary.customized += 1;
|
|
133
|
+
} else {
|
|
134
|
+
summary.installed += 1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (env && Array.isArray(env.workflows)) {
|
|
139
|
+
for (const w of env.workflows) {
|
|
140
|
+
if (!baselinePaths.has(normPath(w.path))) summary.user_extras += 1;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return summary;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = {
|
|
147
|
+
listProfileWorkflows,
|
|
148
|
+
baselineTargetPath,
|
|
149
|
+
freshCopyPath,
|
|
150
|
+
planWorkflowDownloads,
|
|
151
|
+
summarizeWorkflowState,
|
|
152
|
+
};
|