@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,1287 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Compatibility Resolver — Private Worker Installer Phase 1 / Phase 1.5.
|
|
5
|
+
*
|
|
6
|
+
* Pure, read-only resolution logic. It accepts:
|
|
7
|
+
* - profiles/manifests (canonical install manifests),
|
|
8
|
+
* - environment probe (= installed state: ComfyUI, python/torch, nodes,
|
|
9
|
+
* models, workflows, worker),
|
|
10
|
+
* - runtime mode,
|
|
11
|
+
* and produces a structured resolution report. It performs NO installation,
|
|
12
|
+
* NO deletion and NO mutation of any environment. The report is the input
|
|
13
|
+
* for a future installer; the installer must not decide "what is needed"
|
|
14
|
+
* on its own.
|
|
15
|
+
*
|
|
16
|
+
* Runtime modes (see docs/04-planning/private-worker-installer-phase15.md):
|
|
17
|
+
* managed — installer fully owns the environment (V1 target);
|
|
18
|
+
* existing — detect → compare → report → optionally install missing;
|
|
19
|
+
* never replace/downgrade the user's environment automatically;
|
|
20
|
+
* isolated — one GPU machine, several independent ComfyUI environments
|
|
21
|
+
* (data model + interface only; full implementation later);
|
|
22
|
+
* shared — one ComfyUI serving several profiles; resolver computes the
|
|
23
|
+
* union of dependencies and detects runtime conflicts.
|
|
24
|
+
*
|
|
25
|
+
* Entry kinds (Phase 1.5): runtime | custom_node | model | model_repo |
|
|
26
|
+
* python_package | workflow | worker.
|
|
27
|
+
*
|
|
28
|
+
* Entry statuses: required | installed | missing | incompatible | unused | unknown
|
|
29
|
+
* required — declared required by manifest; environment was not probed
|
|
30
|
+
* for this kind, so no installed/missing judgement is possible
|
|
31
|
+
* installed — required and found compatible (for workflow: present —
|
|
32
|
+
* possibly customized by the user, which is ALLOWED)
|
|
33
|
+
* missing — required and absent
|
|
34
|
+
* incompatible — found, but version/config conflicts with the manifest
|
|
35
|
+
* unused — present on the machine, not required by selected profiles
|
|
36
|
+
* (informational; NEVER auto-removed)
|
|
37
|
+
* unknown — present but cannot be matched/verified, or compatibility
|
|
38
|
+
* cannot be determined from available evidence
|
|
39
|
+
*
|
|
40
|
+
* Actions: install | skip | review | none | configure.
|
|
41
|
+
* configure — interactive worker/.env setup (Worker Key entered hidden;
|
|
42
|
+
* never logged, never passed via argv).
|
|
43
|
+
*
|
|
44
|
+
* Workflow semantics (Phase 1.5): a baseline workflow is an EDITABLE starting
|
|
45
|
+
* point. A copy whose hash differs from the manifest baseline_sha256 is
|
|
46
|
+
* "installed/customized" — NOT an error, never overwritten. A fresh official
|
|
47
|
+
* copy can be downloaded separately under a distinct name on request.
|
|
48
|
+
*
|
|
49
|
+
* Multi-profile (shared) verdicts:
|
|
50
|
+
* shared-compatible | shared-conflict | requires-isolation | unknown
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
const RUNTIME_MODES = Object.freeze(['managed', 'existing', 'isolated', 'shared']);
|
|
54
|
+
|
|
55
|
+
const ENTRY_STATUSES = Object.freeze([
|
|
56
|
+
'required', 'installed', 'missing', 'incompatible', 'unused', 'unknown',
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
const ACTIONS = Object.freeze(['install', 'skip', 'review', 'none', 'configure']);
|
|
60
|
+
|
|
61
|
+
const SHARING_VERDICTS = Object.freeze([
|
|
62
|
+
'shared-compatible', 'shared-conflict', 'requires-isolation', 'unknown',
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
// Upstream renames that must not be treated as different repositories.
|
|
66
|
+
const REPO_ALIASES = Object.freeze({
|
|
67
|
+
'comfyanonymous/comfyui': 'comfy-org/comfyui',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const SIZE_TOLERANCE = 0.05; // 5% — audit sizes are human-rounded (e.g. "16.54 GiB")
|
|
71
|
+
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// Version helpers
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
function parseVersion(v) {
|
|
77
|
+
if (typeof v !== 'string') return null;
|
|
78
|
+
const base = v.trim().replace(/^v/i, '').split('+')[0];
|
|
79
|
+
const parts = base.split('.').map((p) => {
|
|
80
|
+
const m = /^(\d+)/.exec(p);
|
|
81
|
+
return m ? parseInt(m[1], 10) : NaN;
|
|
82
|
+
});
|
|
83
|
+
if (parts.length === 0 || parts.some(Number.isNaN)) return null;
|
|
84
|
+
return parts;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** -1 if a<b, 0 if equal, 1 if a>b, null if either is unparseable. */
|
|
88
|
+
function compareVersions(a, b) {
|
|
89
|
+
const pa = parseVersion(a);
|
|
90
|
+
const pb = parseVersion(b);
|
|
91
|
+
if (!pa || !pb) return null;
|
|
92
|
+
const len = Math.max(pa.length, pb.length);
|
|
93
|
+
for (let i = 0; i < len; i += 1) {
|
|
94
|
+
const x = pa[i] || 0;
|
|
95
|
+
const y = pb[i] || 0;
|
|
96
|
+
if (x !== y) return x < y ? -1 : 1;
|
|
97
|
+
}
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Short/full sha match: case-insensitive prefix in either direction (min 7 chars). */
|
|
102
|
+
function shaMatch(a, b) {
|
|
103
|
+
if (!a || !b) return false;
|
|
104
|
+
const x = String(a).toLowerCase();
|
|
105
|
+
const y = String(b).toLowerCase();
|
|
106
|
+
if (x === y) return true;
|
|
107
|
+
const n = Math.min(x.length, y.length);
|
|
108
|
+
if (n < 7) return false;
|
|
109
|
+
return x.startsWith(y) || y.startsWith(x);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function repoKey(url) {
|
|
113
|
+
if (!url) return null;
|
|
114
|
+
let key = String(url).trim().toLowerCase().replace(/\.git$/, '');
|
|
115
|
+
key = key.replace(/^https?:\/\/github\.com\//, '').replace(/^github:/, '');
|
|
116
|
+
return REPO_ALIASES[key] || key;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function reposEqual(a, b) {
|
|
120
|
+
const ka = repoKey(a);
|
|
121
|
+
const kb = repoKey(b);
|
|
122
|
+
if (!ka || !kb) return true; // cannot compare — not a mismatch by itself
|
|
123
|
+
return ka === kb;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function normPath(p) {
|
|
127
|
+
return String(p || '').replace(/\\/g, '/').replace(/^\/+/, '').replace(/\/+$/, '');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// Environment model
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Environment probe result (= installed state).
|
|
136
|
+
* `null` means "probed, absent"; `undefined` means "not probed" — the
|
|
137
|
+
* resolver must distinguish the two (missing vs required/undetermined).
|
|
138
|
+
*/
|
|
139
|
+
function createEmptyEnvironment(root = null) {
|
|
140
|
+
return {
|
|
141
|
+
root,
|
|
142
|
+
comfyui: null,
|
|
143
|
+
python: null,
|
|
144
|
+
torch: null,
|
|
145
|
+
nodejs: null,
|
|
146
|
+
gpu: null,
|
|
147
|
+
custom_nodes: [],
|
|
148
|
+
models: [],
|
|
149
|
+
python_packages: [],
|
|
150
|
+
workflows: [],
|
|
151
|
+
worker: null,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
// Manifest union (multi-profile)
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
|
|
159
|
+
function unionDependencies(manifests) {
|
|
160
|
+
const byId = new Map();
|
|
161
|
+
const conflicts = [];
|
|
162
|
+
|
|
163
|
+
for (const manifest of manifests) {
|
|
164
|
+
const profileId = manifest.profile ? manifest.profile.id : '<unknown>';
|
|
165
|
+
for (const dep of manifest.dependencies || []) {
|
|
166
|
+
if (!byId.has(dep.id)) {
|
|
167
|
+
byId.set(dep.id, { dep: JSON.parse(JSON.stringify(dep)), profiles: [profileId] });
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const slot = byId.get(dep.id);
|
|
171
|
+
if (!slot.profiles.includes(profileId)) slot.profiles.push(profileId);
|
|
172
|
+
|
|
173
|
+
const have = slot.dep.install && slot.dep.install.source ? slot.dep.install.source.commit : null;
|
|
174
|
+
const other = dep.install && dep.install.source ? dep.install.source.commit : null;
|
|
175
|
+
if (have && other && !shaMatch(have, other)) {
|
|
176
|
+
conflicts.push({
|
|
177
|
+
component: 'dependency',
|
|
178
|
+
id: dep.id,
|
|
179
|
+
profiles: { [slot.profiles[0]]: have, [profileId]: other },
|
|
180
|
+
reason: 'same dependency id is pinned to different commits by different profiles',
|
|
181
|
+
});
|
|
182
|
+
} else if (!have && other) {
|
|
183
|
+
// adopt the only known pin, keep provenance of both profiles
|
|
184
|
+
slot.dep.install = JSON.parse(JSON.stringify(dep.install));
|
|
185
|
+
slot.dep.notes = (slot.dep.notes || []).concat(
|
|
186
|
+
[`commit pin adopted from ${profileId} manifest; the other profile has no pin (unverified)`]
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { byId, conflicts };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
// Runtime checks (single-manifest verdicts)
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
|
|
198
|
+
function checkComfyuiAgainst(spec, comfyEnv) {
|
|
199
|
+
if (comfyEnv === undefined) {
|
|
200
|
+
return { status: 'required', action: 'review', notes: ['environment not probed for ComfyUI'] };
|
|
201
|
+
}
|
|
202
|
+
if (!comfyEnv || comfyEnv.present === false) {
|
|
203
|
+
return { status: 'missing', action: 'install', notes: [] };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const pin = spec.pin;
|
|
207
|
+
if (pin) {
|
|
208
|
+
const commitOk = shaMatch(pin.commit, comfyEnv.commit);
|
|
209
|
+
const tagOk = pin.tag && (comfyEnv.tag === pin.tag || comfyEnv.version === pin.tag);
|
|
210
|
+
if (commitOk || tagOk) {
|
|
211
|
+
const notes = [];
|
|
212
|
+
if (pin.repository && comfyEnv.repository && !reposEqual(pin.repository, comfyEnv.repository)) {
|
|
213
|
+
notes.push(`git remote differs from manifest pin (${comfyEnv.repository} vs ${pin.repository}) — commit/tag matched, treat with care`);
|
|
214
|
+
}
|
|
215
|
+
return { status: 'installed', grade: 'canonical', action: 'skip', notes };
|
|
216
|
+
}
|
|
217
|
+
const v = comfyEnv.version || comfyEnv.tag;
|
|
218
|
+
if (v) {
|
|
219
|
+
if (spec.min_version && compareVersions(v, spec.min_version) === -1) {
|
|
220
|
+
return {
|
|
221
|
+
status: 'incompatible',
|
|
222
|
+
reason: 'below_minimum',
|
|
223
|
+
action: 'review',
|
|
224
|
+
notes: [`found ${v} < min ${spec.min_version}; suggest upgrade to the pinned version; abort if the user declines; never forced`],
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if (spec.max_tested_version && compareVersions(v, spec.max_tested_version) === 1) {
|
|
228
|
+
return {
|
|
229
|
+
status: 'incompatible',
|
|
230
|
+
reason: 'above_max_tested',
|
|
231
|
+
action: 'review',
|
|
232
|
+
notes: [`found ${v} > max tested ${spec.max_tested_version}; NEVER auto-downgrade; user decides: downgrade to pin or continue at own risk (recorded in install state)`],
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
status: 'installed',
|
|
237
|
+
grade: 'range',
|
|
238
|
+
action: 'skip',
|
|
239
|
+
notes: [`version ${v} is within [${spec.min_version}, ${spec.max_tested_version}] but is not the exact pin (range-if-approved)`],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
status: 'unknown',
|
|
244
|
+
action: 'review',
|
|
245
|
+
notes: ['ComfyUI present but version/commit cannot be determined (not a git repository?) — scenario D, ask the user'],
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const ref = spec.known_working_reference;
|
|
250
|
+
if (ref) {
|
|
251
|
+
const commitOk = shaMatch(ref.commit, comfyEnv.commit);
|
|
252
|
+
const repoOk = reposEqual(ref.repository, comfyEnv.repository);
|
|
253
|
+
if (commitOk && repoOk) {
|
|
254
|
+
return {
|
|
255
|
+
status: 'installed',
|
|
256
|
+
grade: 'reference',
|
|
257
|
+
action: 'skip',
|
|
258
|
+
notes: ['matches the known-working reference environment; canonical pin is still unknown (manifest basis=unknown) — no automatic changes to it'],
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
status: 'unknown',
|
|
263
|
+
action: 'review',
|
|
264
|
+
notes: ['canonical ComfyUI requirement is unknown for this profile; the installed version matches neither a canonical pin nor the known-working reference — compatibility cannot be determined (golden run required); NO automatic replacement/downgrade'],
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return { status: 'unknown', action: 'review', notes: ['manifest has neither a canonical pin nor a known-working reference'] };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Base version without the local build tag: "2.10.0+cu128" → "2.10.0". */
|
|
271
|
+
function torchBaseVersion(v) {
|
|
272
|
+
return String(v || '').trim().split('+')[0].toLowerCase();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Local build tag: "2.10.0+cpu" → "cpu"; "2.10.0" → "". */
|
|
276
|
+
function torchLocalTag(v) {
|
|
277
|
+
const parts = String(v || '').trim().split('+');
|
|
278
|
+
return parts.length > 1 ? parts[1].toLowerCase() : '';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function checkTorchAgainst(spec, torchEnv, device = null) {
|
|
282
|
+
if (torchEnv === undefined) {
|
|
283
|
+
return { status: 'required', action: 'review', notes: ['environment not probed for torch'] };
|
|
284
|
+
}
|
|
285
|
+
if (!torchEnv || !torchEnv.version) {
|
|
286
|
+
return { status: 'missing', action: 'install', notes: [] };
|
|
287
|
+
}
|
|
288
|
+
// CPU-only machine: the manifest may declare a dedicated CPU build (pin +
|
|
289
|
+
// CPU wheel index). "+cpu" local tags and the untagged pin are equivalent.
|
|
290
|
+
if (device === 'cpu' && spec.cpu && spec.cpu.pin) {
|
|
291
|
+
const found = String(torchEnv.version);
|
|
292
|
+
if (torchBaseVersion(found) === torchBaseVersion(spec.cpu.pin)
|
|
293
|
+
&& ['', 'cpu'].includes(torchLocalTag(found))) {
|
|
294
|
+
return { status: 'installed', grade: 'cpu-canonical', action: 'skip', notes: [`CPU build ${found} matches the manifest CPU pin ${spec.cpu.pin}`] };
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
status: 'incompatible',
|
|
298
|
+
reason: 'version_mismatch',
|
|
299
|
+
action: 'review',
|
|
300
|
+
notes: [`found ${torchEnv.version}, manifest pins CPU torch ${spec.cpu.pin}; CPU torch is NEVER auto-replaced — user decision required`],
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
const found = String(torchEnv.version).toLowerCase();
|
|
304
|
+
if (spec.pin) {
|
|
305
|
+
if (found === String(spec.pin).toLowerCase()) {
|
|
306
|
+
return { status: 'installed', grade: 'canonical', action: 'skip', notes: [] };
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
status: 'incompatible',
|
|
310
|
+
reason: 'version_mismatch',
|
|
311
|
+
action: 'review',
|
|
312
|
+
notes: [`found ${torchEnv.version}, manifest pins ${spec.pin}; in 'existing' mode torch is NEVER auto-replaced — user decision required`],
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
const ref = spec.known_working_reference;
|
|
316
|
+
if (ref && ref.version) {
|
|
317
|
+
if (found === String(ref.version).toLowerCase()) {
|
|
318
|
+
return {
|
|
319
|
+
status: 'installed',
|
|
320
|
+
grade: 'reference',
|
|
321
|
+
action: 'skip',
|
|
322
|
+
notes: ['matches the known-working reference; canonical torch pin is still unknown (manifest basis=unknown)'],
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
status: 'unknown',
|
|
327
|
+
action: 'review',
|
|
328
|
+
notes: [`found ${torchEnv.version}; canonical pin unknown and the version matches neither the pin nor the known-working reference (${ref.version}) — compatibility cannot be determined; NO automatic replacement`],
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
return { status: 'unknown', action: 'review', notes: ['manifest has neither a canonical torch pin nor a reference'] };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function checkMinimumAgainst(component, spec, envValue) {
|
|
335
|
+
if (envValue === undefined) {
|
|
336
|
+
return { status: 'required', action: 'review', notes: [`environment not probed for ${component}`] };
|
|
337
|
+
}
|
|
338
|
+
if (!envValue || !envValue.version) {
|
|
339
|
+
return { status: 'missing', action: 'install', notes: [] };
|
|
340
|
+
}
|
|
341
|
+
const cmp = compareVersions(envValue.version, spec.minimum);
|
|
342
|
+
if (cmp === null) {
|
|
343
|
+
return { status: 'unknown', action: 'review', notes: [`cannot parse ${component} version "${envValue.version}"`] };
|
|
344
|
+
}
|
|
345
|
+
if (cmp === -1) {
|
|
346
|
+
return {
|
|
347
|
+
status: 'incompatible',
|
|
348
|
+
reason: 'below_minimum',
|
|
349
|
+
action: 'review',
|
|
350
|
+
notes: [`found ${envValue.version} < minimum ${spec.minimum}`],
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
return { status: 'installed', grade: 'minimum-satisfied', action: 'skip', notes: [] };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const RUNTIME_ORDER = ['comfyui', 'torch', 'python', 'nodejs'];
|
|
357
|
+
|
|
358
|
+
function combineRuntimeVerdicts(perManifest) {
|
|
359
|
+
// perManifest: [{ verdict, profile }]
|
|
360
|
+
const statuses = perManifest.map((p) => p.verdict.status);
|
|
361
|
+
if (statuses.every((s) => s === 'installed')) {
|
|
362
|
+
const grades = perManifest.map((p) => p.verdict.grade || 'canonical');
|
|
363
|
+
const grade = grades.includes('reference') ? 'reference' : grades.find((g) => g !== 'canonical') || 'canonical';
|
|
364
|
+
return {
|
|
365
|
+
status: 'installed',
|
|
366
|
+
grade,
|
|
367
|
+
action: 'skip',
|
|
368
|
+
notes: perManifest.flatMap((p) => p.verdict.notes || []),
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
if (statuses.every((s) => s === 'missing')) {
|
|
372
|
+
return { status: 'missing', action: 'install', notes: [] };
|
|
373
|
+
}
|
|
374
|
+
const incompatible = perManifest.filter((p) => p.verdict.status === 'incompatible');
|
|
375
|
+
if (incompatible.length > 0) {
|
|
376
|
+
return {
|
|
377
|
+
status: 'incompatible',
|
|
378
|
+
reason: incompatible[0].verdict.reason || 'profiles_disagree',
|
|
379
|
+
action: 'review',
|
|
380
|
+
notes: perManifest.flatMap((p) => (p.verdict.notes || []).map((n) => `[${p.profile}] ${n}`)),
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
if (statuses.includes('installed') && statuses.includes('missing')) {
|
|
384
|
+
return {
|
|
385
|
+
status: 'incompatible',
|
|
386
|
+
reason: 'profiles_disagree',
|
|
387
|
+
action: 'review',
|
|
388
|
+
notes: ['installed state satisfies some profiles but not others — profiles cannot share this runtime as-is'],
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
status: 'unknown',
|
|
393
|
+
action: 'review',
|
|
394
|
+
notes: perManifest.flatMap((p) => (p.verdict.notes || []).map((n) => `[${p.profile}] ${n}`)),
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// ---------------------------------------------------------------------------
|
|
399
|
+
// Dependency checks
|
|
400
|
+
// ---------------------------------------------------------------------------
|
|
401
|
+
|
|
402
|
+
function missingAction(dep) {
|
|
403
|
+
if (dep.requirement === 'required') return 'install';
|
|
404
|
+
if (dep.requirement === 'unknown') return 'review';
|
|
405
|
+
return 'none';
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* 'installed' is reserved for REQUIRED dependencies found compatible.
|
|
410
|
+
* An optional dependency that is present is 'unused' (kept, never removed);
|
|
411
|
+
* a dependency whose requirement is still unresolved is 'unknown'.
|
|
412
|
+
*/
|
|
413
|
+
function remapByRequirement(entry, dep) {
|
|
414
|
+
if (entry.status !== 'installed') return entry;
|
|
415
|
+
if (dep.requirement === 'optional') {
|
|
416
|
+
return {
|
|
417
|
+
...entry,
|
|
418
|
+
status: 'unused',
|
|
419
|
+
action: 'none',
|
|
420
|
+
notes: (entry.notes || []).concat(['optional dependency — present but not required; kept as-is, never auto-removed']),
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
if (dep.requirement === 'unknown') {
|
|
424
|
+
return {
|
|
425
|
+
...entry,
|
|
426
|
+
status: 'unknown',
|
|
427
|
+
action: 'review',
|
|
428
|
+
notes: (entry.notes || []).concat(['requirement is unresolved in the manifest (needs verification) — presence noted, no automatic action']),
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
return entry;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function findInstalledNode(env, dep) {
|
|
435
|
+
if (!Array.isArray(env.custom_nodes)) return undefined;
|
|
436
|
+
const dir = dep.install && dep.install.directory ? String(dep.install.directory).toLowerCase() : null;
|
|
437
|
+
const name = dep.name ? String(dep.name).toLowerCase() : null;
|
|
438
|
+
const src = dep.install && dep.install.source ? dep.install.source : null;
|
|
439
|
+
return env.custom_nodes.find((n) => {
|
|
440
|
+
const nd = String(n.directory || '').toLowerCase();
|
|
441
|
+
if (dir && nd === dir) return true;
|
|
442
|
+
if (name && nd === name) return true;
|
|
443
|
+
if (src && src.repository && n.repository && reposEqual(src.repository, n.repository) && shaMatch(src.commit, n.commit)) return true;
|
|
444
|
+
return false;
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function checkCustomNode(dep, env, profiles) {
|
|
449
|
+
const base = { id: dep.id, kind: 'custom_node', name: dep.name, requirement: dep.requirement, basis: dep.basis, profiles };
|
|
450
|
+
if (env.custom_nodes === undefined) {
|
|
451
|
+
return { ...base, status: 'required', action: 'review', notes: ['environment not probed for custom nodes'] };
|
|
452
|
+
}
|
|
453
|
+
const found = findInstalledNode(env, dep);
|
|
454
|
+
if (!found) {
|
|
455
|
+
return { ...base, status: 'missing', action: missingAction(dep), expected: describeNodeExpectation(dep), notes: [] };
|
|
456
|
+
}
|
|
457
|
+
const wantCommit = dep.install && dep.install.source ? dep.install.source.commit : null;
|
|
458
|
+
const haveCommit = found.commit || null;
|
|
459
|
+
const notes = [];
|
|
460
|
+
if (dep.patches && dep.patches.length > 0) {
|
|
461
|
+
notes.push(`requires patch(es): ${dep.patches.map((p) => p.id).join(', ')} — patch state is not detectable by the resolver yet (documented, not declarative)`);
|
|
462
|
+
}
|
|
463
|
+
if (wantCommit && haveCommit) {
|
|
464
|
+
if (shaMatch(wantCommit, haveCommit)) {
|
|
465
|
+
return { ...base, status: 'installed', grade: 'canonical-version', action: 'skip', found: describeNodeFound(found), notes };
|
|
466
|
+
}
|
|
467
|
+
notes.push(`installed commit ${haveCommit} differs from manifest pin ${wantCommit}; in 'existing' mode a git-safe checkout is SUGGESTED, never applied automatically`);
|
|
468
|
+
return { ...base, status: 'incompatible', reason: 'version_mismatch', action: 'review', expected: wantCommit, found: describeNodeFound(found), notes };
|
|
469
|
+
}
|
|
470
|
+
if (wantCommit && !haveCommit) {
|
|
471
|
+
notes.push('present as a plain directory without git metadata — pinned version cannot be verified');
|
|
472
|
+
} else if (!wantCommit) {
|
|
473
|
+
notes.push('manifest has no pinned commit for this node yet (TODO) — presence verified only');
|
|
474
|
+
}
|
|
475
|
+
return { ...base, status: 'installed', grade: 'presence', action: 'skip', found: describeNodeFound(found), notes };
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function describeNodeExpectation(dep) {
|
|
479
|
+
const src = (dep.install && dep.install.source) || {};
|
|
480
|
+
return { directory: dep.install && dep.install.directory, repository: src.repository || null, commit: src.commit || null };
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function describeNodeFound(found) {
|
|
484
|
+
return { directory: found.directory, repository: found.repository || null, commit: found.commit || null, is_git: found.is_git !== false && Boolean(found.commit) };
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function checkModel(dep, env, profiles) {
|
|
488
|
+
const base = { id: dep.id, kind: 'model', name: dep.name, requirement: dep.requirement, basis: dep.basis, profiles };
|
|
489
|
+
if (env.models === undefined) {
|
|
490
|
+
return { ...base, status: 'required', action: 'review', notes: ['environment not probed for models'] };
|
|
491
|
+
}
|
|
492
|
+
const expectedPath = `${normPath(dep.target_dir)}/${dep.filename}`;
|
|
493
|
+
const found = (env.models || []).find((m) => normPath(m.path) === expectedPath);
|
|
494
|
+
if (!found) {
|
|
495
|
+
return { ...base, status: 'missing', action: missingAction(dep), expected: { path: expectedPath }, notes: [] };
|
|
496
|
+
}
|
|
497
|
+
const checksum = dep.checksum || {};
|
|
498
|
+
if (checksum.value && found.sha256) {
|
|
499
|
+
if (String(found.sha256).toLowerCase() === String(checksum.value).toLowerCase()) {
|
|
500
|
+
return { ...base, status: 'installed', grade: 'checksum-verified', action: 'skip', found: { path: found.path }, notes: [] };
|
|
501
|
+
}
|
|
502
|
+
return {
|
|
503
|
+
...base,
|
|
504
|
+
status: 'incompatible',
|
|
505
|
+
reason: 'checksum_mismatch',
|
|
506
|
+
action: 'review',
|
|
507
|
+
found: { path: found.path, sha256: found.sha256 },
|
|
508
|
+
notes: ['checksum mismatch — never continue with a possibly corrupted model; re-download after user confirmation'],
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
if (checksum.value_prefix && found.sha256) {
|
|
512
|
+
const ok = String(found.sha256).toLowerCase().startsWith(String(checksum.value_prefix).toLowerCase());
|
|
513
|
+
if (!ok) {
|
|
514
|
+
return {
|
|
515
|
+
...base,
|
|
516
|
+
status: 'incompatible',
|
|
517
|
+
reason: 'checksum_mismatch',
|
|
518
|
+
action: 'review',
|
|
519
|
+
found: { path: found.path, sha256: found.sha256 },
|
|
520
|
+
notes: [`sha256 prefix does not match audit-captured prefix ${checksum.value_prefix}`],
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
return { ...base, status: 'installed', grade: 'checksum-prefix-verified', action: 'skip', found: { path: found.path }, notes: [] };
|
|
524
|
+
}
|
|
525
|
+
if (dep.size_bytes_approx && found.size_bytes) {
|
|
526
|
+
const rel = Math.abs(found.size_bytes - dep.size_bytes_approx) / dep.size_bytes_approx;
|
|
527
|
+
if (rel > SIZE_TOLERANCE) {
|
|
528
|
+
return {
|
|
529
|
+
...base,
|
|
530
|
+
status: 'incompatible',
|
|
531
|
+
reason: 'size_mismatch',
|
|
532
|
+
action: 'review',
|
|
533
|
+
expected: { size_bytes_approx: dep.size_bytes_approx },
|
|
534
|
+
found: { path: found.path, size_bytes: found.size_bytes },
|
|
535
|
+
notes: ['size differs from the reference audit size by more than 5% — possibly a different file/quant; user review required'],
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
return { ...base, status: 'installed', grade: 'size-verified', action: 'skip', found: { path: found.path, size_bytes: found.size_bytes }, notes: [] };
|
|
539
|
+
}
|
|
540
|
+
return { ...base, status: 'installed', grade: 'presence', action: 'skip', found: { path: found.path }, notes: ['presence only — no checksum/size evidence available'] };
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function checkModelRepo(dep, env, profiles) {
|
|
544
|
+
const base = { id: dep.id, kind: 'model_repo', name: dep.name, requirement: dep.requirement, basis: dep.basis, profiles };
|
|
545
|
+
if (env.models === undefined) {
|
|
546
|
+
return { ...base, status: 'required', action: 'review', notes: ['environment not probed for models'] };
|
|
547
|
+
}
|
|
548
|
+
const prefix = normPath(dep.target_dir);
|
|
549
|
+
const matches = (env.models || []).filter((m) => normPath(m.path).startsWith(`${prefix}/`));
|
|
550
|
+
if (matches.length === 0) {
|
|
551
|
+
return {
|
|
552
|
+
...base,
|
|
553
|
+
status: 'missing',
|
|
554
|
+
action: missingAction(dep),
|
|
555
|
+
expected: { target_dir: prefix, repo: dep.repo },
|
|
556
|
+
notes: dep.delivery && dep.delivery.mechanism === 'node_auto_download'
|
|
557
|
+
? ['the custom node can auto-download this repo on first run (decision D2: preinstall vs auto_download)']
|
|
558
|
+
: [],
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
if (Array.isArray(dep.expected_files) && dep.expected_files.length > 0) {
|
|
562
|
+
const have = new Set(matches.map((m) => normPath(m.path)));
|
|
563
|
+
const missingFiles = dep.expected_files.filter((f) => !have.has(`${prefix}/${normPath(f)}`));
|
|
564
|
+
if (missingFiles.length > 0) {
|
|
565
|
+
// Partially present: status stays 'missing' (with reason
|
|
566
|
+
// 'incomplete') so plan/engine treat it as installable — the
|
|
567
|
+
// downloader is idempotent and resumes .part files, it never
|
|
568
|
+
// re-downloads a verified file. 'incompatible' would park it as a
|
|
569
|
+
// review item and an interrupted download could never resume.
|
|
570
|
+
return {
|
|
571
|
+
...base,
|
|
572
|
+
status: 'missing',
|
|
573
|
+
reason: 'incomplete',
|
|
574
|
+
action: 'install',
|
|
575
|
+
found: { files: Array.from(have) },
|
|
576
|
+
notes: [`present but incomplete; missing: ${missingFiles.join(', ')}`],
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
return { ...base, status: 'installed', grade: 'files-verified', action: 'skip', found: { files: dep.expected_files }, notes: [] };
|
|
580
|
+
}
|
|
581
|
+
return { ...base, status: 'installed', grade: 'presence', action: 'skip', found: { files: matches.map((m) => normPath(m.path)) }, notes: [] };
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function checkPythonPackage(dep, env, profiles) {
|
|
585
|
+
const base = { id: dep.id, kind: 'python_package', name: dep.name, requirement: dep.requirement, basis: dep.basis, profiles };
|
|
586
|
+
if (env.python_packages === undefined) {
|
|
587
|
+
return { ...base, status: 'required', action: 'review', notes: ['environment not probed for python packages'] };
|
|
588
|
+
}
|
|
589
|
+
const found = (env.python_packages || []).find((p) => String(p.name).toLowerCase() === String(dep.name).toLowerCase());
|
|
590
|
+
if (!found) {
|
|
591
|
+
return { ...base, status: 'missing', action: missingAction(dep), notes: [] };
|
|
592
|
+
}
|
|
593
|
+
if (dep.version && found.version && String(dep.version) !== String(found.version)) {
|
|
594
|
+
return {
|
|
595
|
+
...base,
|
|
596
|
+
status: 'incompatible',
|
|
597
|
+
reason: 'version_mismatch',
|
|
598
|
+
action: 'review',
|
|
599
|
+
expected: dep.version,
|
|
600
|
+
found: { version: found.version },
|
|
601
|
+
notes: [],
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
const notes = dep.version ? [] : ['manifest does not pin a version yet (TODO) — presence verified only'];
|
|
605
|
+
return { ...base, status: 'installed', grade: 'presence', action: 'skip', found: { version: found.version || null }, notes };
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function checkDependency(slot, env) {
|
|
609
|
+
const { dep, profiles } = slot;
|
|
610
|
+
let entry;
|
|
611
|
+
switch (dep.kind) {
|
|
612
|
+
case 'custom_node': entry = checkCustomNode(dep, env, profiles); break;
|
|
613
|
+
case 'model': entry = checkModel(dep, env, profiles); break;
|
|
614
|
+
case 'model_repo': entry = checkModelRepo(dep, env, profiles); break;
|
|
615
|
+
case 'python_package': entry = checkPythonPackage(dep, env, profiles); break;
|
|
616
|
+
default:
|
|
617
|
+
entry = { id: dep.id, kind: dep.kind, requirement: dep.requirement, basis: dep.basis, profiles, status: 'unknown', action: 'review', notes: [`unknown dependency kind: ${dep.kind}`] };
|
|
618
|
+
}
|
|
619
|
+
return remapByRequirement(entry, dep);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// ---------------------------------------------------------------------------
|
|
623
|
+
// Workflow checks (Phase 1.5 — first-class artifacts, editable baselines)
|
|
624
|
+
// ---------------------------------------------------------------------------
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* A baseline workflow is an OPTIONAL demo/test artifact and an EDITABLE
|
|
628
|
+
* starting point — never a runtime requirement: Animastor sends workflow JSON
|
|
629
|
+
* with each task via the API/GPU Hub, so a profile is fully usable for
|
|
630
|
+
* API-based generation without any locally installed copies. Local copies
|
|
631
|
+
* exist only to test ComfyUI in its Web UI or as a starting point for the
|
|
632
|
+
* user's own workflows. Consequences:
|
|
633
|
+
* - absent at the baseline path → missing (OFFERED for download,
|
|
634
|
+
* but optional: it is never counted as a missing required component and
|
|
635
|
+
* never blocks or fails the installation);
|
|
636
|
+
* - present, hash matches baseline_sha256 → installed / canonical-baseline;
|
|
637
|
+
* - present, hash differs → installed / customized —
|
|
638
|
+
* this is ALLOWED, never an error, and NEVER overwritten;
|
|
639
|
+
* - present, no baseline hash recorded → installed / presence.
|
|
640
|
+
* The installer may later download a FRESH official copy under a distinct
|
|
641
|
+
* name on explicit request; it never touches the user's copy.
|
|
642
|
+
*/
|
|
643
|
+
function checkWorkflow(wf, env, profiles) {
|
|
644
|
+
const base = {
|
|
645
|
+
id: wf.id,
|
|
646
|
+
kind: 'workflow',
|
|
647
|
+
name: wf.name,
|
|
648
|
+
// Workflows are ALWAYS optional regardless of what a manifest says:
|
|
649
|
+
// no locally installed workflow file is ever a runtime dependency.
|
|
650
|
+
requirement: 'optional',
|
|
651
|
+
basis: wf.basis || 'optional',
|
|
652
|
+
profiles,
|
|
653
|
+
};
|
|
654
|
+
if (env.workflows === undefined) {
|
|
655
|
+
return { ...base, status: 'unknown', action: 'none', notes: ['environment not probed for workflows (optional artifacts)'] };
|
|
656
|
+
}
|
|
657
|
+
const expectedPath = `${normPath(wf.target_dir)}/${wf.filename}`;
|
|
658
|
+
const found = (env.workflows || []).find((w) => normPath(w.path) === expectedPath);
|
|
659
|
+
if (!found) {
|
|
660
|
+
return {
|
|
661
|
+
...base,
|
|
662
|
+
status: 'missing',
|
|
663
|
+
// 'install' is an OFFER for the interactive plan (the user may
|
|
664
|
+
// download a copy), not a required install: requirement stays
|
|
665
|
+
// 'optional', so missing workflows never reach missing_required
|
|
666
|
+
// or blocking and never fail verification.
|
|
667
|
+
action: 'install',
|
|
668
|
+
expected: { path: expectedPath },
|
|
669
|
+
notes: ['optional demo workflow — download writes a NEW file only; it never touches existing user workflows'],
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
if (wf.baseline_sha256 && found.sha256) {
|
|
673
|
+
if (String(found.sha256).toLowerCase() === String(wf.baseline_sha256).toLowerCase()) {
|
|
674
|
+
return { ...base, status: 'installed', grade: 'canonical-baseline', action: 'skip', found: { path: found.path }, notes: [] };
|
|
675
|
+
}
|
|
676
|
+
return {
|
|
677
|
+
...base,
|
|
678
|
+
status: 'installed',
|
|
679
|
+
grade: 'customized',
|
|
680
|
+
action: 'skip',
|
|
681
|
+
found: { path: found.path, sha256: found.sha256 },
|
|
682
|
+
notes: ['user has customized this baseline workflow — ALLOWED (editable baseline); NEVER overwritten; a fresh official copy can be downloaded separately under a distinct name on request'],
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
...base,
|
|
687
|
+
status: 'installed',
|
|
688
|
+
grade: 'presence',
|
|
689
|
+
action: 'skip',
|
|
690
|
+
found: { path: found.path },
|
|
691
|
+
notes: ['presence only — no baseline sha256 and/or file hash available'],
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// ---------------------------------------------------------------------------
|
|
696
|
+
// Worker checks (Phase 1.5 — Animastor worker bundle + .env, secrets-safe)
|
|
697
|
+
// ---------------------------------------------------------------------------
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Worker probe shape (env.worker): a single probe object or an array of
|
|
701
|
+
* probes (shared mode — one per worker_type):
|
|
702
|
+
* { worker_type, bundle: { present, dir, files[] }, env: { present, set_keys[] } }
|
|
703
|
+
* SECURITY: probes record which env KEYS are set — never their VALUES.
|
|
704
|
+
* The resolver therefore can never leak a Worker Key into a report/log.
|
|
705
|
+
*/
|
|
706
|
+
function checkWorker(manifest, env) {
|
|
707
|
+
const wb = manifest.worker_bundle || {};
|
|
708
|
+
const profileId = manifest.profile ? manifest.profile.id : '<unknown>';
|
|
709
|
+
const workerType = wb.worker_type || (manifest.profile ? manifest.profile.type : null);
|
|
710
|
+
const base = {
|
|
711
|
+
id: `worker:${profileId}`,
|
|
712
|
+
kind: 'worker',
|
|
713
|
+
worker_type: workerType,
|
|
714
|
+
requirement: 'required',
|
|
715
|
+
basis: wb.basis || 'minimum_supported',
|
|
716
|
+
profiles: [profileId],
|
|
717
|
+
};
|
|
718
|
+
if (env.worker === undefined) {
|
|
719
|
+
return { ...base, status: 'required', action: 'review', notes: ['environment not probed for the Animastor worker'] };
|
|
720
|
+
}
|
|
721
|
+
const probes = Array.isArray(env.worker) ? env.worker : [env.worker];
|
|
722
|
+
const probe = probes.find((p) => p && (p.worker_type === workerType || workerType === null));
|
|
723
|
+
if (!probe || !probe.bundle || probe.bundle.present === false) {
|
|
724
|
+
return { ...base, status: 'missing', action: 'install', expected: { files: wb.files || [] }, notes: [] };
|
|
725
|
+
}
|
|
726
|
+
const haveFiles = probe.bundle.files || [];
|
|
727
|
+
const filesMissing = (wb.files || []).filter((f) => !haveFiles.includes(f));
|
|
728
|
+
if (filesMissing.length > 0) {
|
|
729
|
+
return {
|
|
730
|
+
...base,
|
|
731
|
+
status: 'incompatible',
|
|
732
|
+
reason: 'incomplete_bundle',
|
|
733
|
+
action: 'install',
|
|
734
|
+
expected: { files: wb.files },
|
|
735
|
+
found: { files: haveFiles },
|
|
736
|
+
notes: [`bundle incomplete; missing files: ${filesMissing.join(', ')}`],
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
const requiredEnv = (wb.env && wb.env.required) || [];
|
|
740
|
+
const secretKeys = (wb.env && wb.env.secrets) || [];
|
|
741
|
+
if (!probe.env || probe.env.present === false) {
|
|
742
|
+
return {
|
|
743
|
+
...base,
|
|
744
|
+
status: 'installed',
|
|
745
|
+
grade: 'bundle-only',
|
|
746
|
+
action: 'configure',
|
|
747
|
+
found: { files: haveFiles },
|
|
748
|
+
env: { present: false, missing_required: requiredEnv.slice() },
|
|
749
|
+
notes: ['.env not created yet — interactive configuration required (merge semantics; never overwrite an existing valid token)'],
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
const setKeys = probe.env.set_keys || [];
|
|
753
|
+
const envMissing = requiredEnv.filter((k) => !setKeys.includes(k));
|
|
754
|
+
if (envMissing.length > 0) {
|
|
755
|
+
const secretMissing = envMissing.filter((k) => secretKeys.includes(k));
|
|
756
|
+
return {
|
|
757
|
+
...base,
|
|
758
|
+
status: 'installed',
|
|
759
|
+
grade: 'bundle-only',
|
|
760
|
+
action: 'configure',
|
|
761
|
+
found: { files: haveFiles },
|
|
762
|
+
env: { present: true, missing_required: envMissing },
|
|
763
|
+
notes: secretMissing.length > 0
|
|
764
|
+
? [`missing secret key(s): ${secretMissing.join(', ')} — prompt interactively (hidden input); the VALUE is never logged, never stored in reports/state, never passed via argv`]
|
|
765
|
+
: [`missing env keys: ${envMissing.join(', ')}`],
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
return {
|
|
769
|
+
...base,
|
|
770
|
+
status: 'installed',
|
|
771
|
+
grade: 'configured',
|
|
772
|
+
action: 'skip',
|
|
773
|
+
found: { files: haveFiles },
|
|
774
|
+
env: { present: true, missing_required: [] },
|
|
775
|
+
notes: [],
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// ---------------------------------------------------------------------------
|
|
780
|
+
// Extras: unused / unknown detection (never destructive)
|
|
781
|
+
// ---------------------------------------------------------------------------
|
|
782
|
+
|
|
783
|
+
function collectKnownExtraNames(manifests) {
|
|
784
|
+
const names = new Set();
|
|
785
|
+
for (const m of manifests) {
|
|
786
|
+
for (const dep of m.dependencies || []) {
|
|
787
|
+
if (dep.requirement !== 'required') {
|
|
788
|
+
if (dep.install && dep.install.directory) names.add(String(dep.install.directory).toLowerCase());
|
|
789
|
+
if (dep.name) names.add(String(dep.name).toLowerCase());
|
|
790
|
+
if (dep.filename) names.add(String(dep.filename).toLowerCase());
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
for (const ref of m.environment_reference || []) {
|
|
794
|
+
for (const extra of ref.known_extras || []) {
|
|
795
|
+
if (extra.name) names.add(String(extra.name).toLowerCase());
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return names;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
function classifyExtras(manifests, env, matchedNodeDirs, matchedModelPaths, matchedWorkflowPaths) {
|
|
803
|
+
const entries = [];
|
|
804
|
+
const known = collectKnownExtraNames(manifests);
|
|
805
|
+
|
|
806
|
+
if (Array.isArray(env.custom_nodes)) {
|
|
807
|
+
for (const node of env.custom_nodes) {
|
|
808
|
+
const dir = String(node.directory || '');
|
|
809
|
+
if (matchedNodeDirs.has(dir.toLowerCase())) continue;
|
|
810
|
+
const isKnown = known.has(dir.toLowerCase());
|
|
811
|
+
entries.push({
|
|
812
|
+
id: `extra:custom-node:${dir}`,
|
|
813
|
+
kind: 'custom_node',
|
|
814
|
+
requirement: isKnown ? 'optional' : 'unknown',
|
|
815
|
+
basis: isKnown ? 'environment_reference' : 'unknown',
|
|
816
|
+
status: isKnown ? 'unused' : 'unknown',
|
|
817
|
+
action: 'none',
|
|
818
|
+
found: describeNodeFound(node),
|
|
819
|
+
notes: isKnown
|
|
820
|
+
? ['known component, not required by the selected profiles — kept as-is, NEVER auto-removed']
|
|
821
|
+
: ['cannot be matched to any manifest record (no git remote / plain dir / unrecognized) — left untouched, reported for the user'],
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
if (Array.isArray(env.models)) {
|
|
827
|
+
for (const model of env.models) {
|
|
828
|
+
const p = normPath(model.path);
|
|
829
|
+
if (matchedModelPaths.has(p)) continue;
|
|
830
|
+
const basename = p.split('/').pop().toLowerCase();
|
|
831
|
+
const isKnown = known.has(basename) || Array.from(known).some((name) => name.includes('/') && p.toLowerCase().includes(name));
|
|
832
|
+
entries.push({
|
|
833
|
+
id: `extra:model:${p}`,
|
|
834
|
+
kind: 'model',
|
|
835
|
+
requirement: isKnown ? 'optional' : 'unknown',
|
|
836
|
+
basis: isKnown ? 'environment_reference' : 'unknown',
|
|
837
|
+
status: isKnown ? 'unused' : 'unknown',
|
|
838
|
+
action: 'none',
|
|
839
|
+
found: { path: p, size_bytes: model.size_bytes || null },
|
|
840
|
+
notes: isKnown
|
|
841
|
+
? ['known component, not referenced by the selected profiles\' production workflows — kept as-is, NEVER auto-removed']
|
|
842
|
+
: ['cannot be matched to any manifest record — left untouched, reported for the user'],
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// Phase 1.5: any workflow file that is not a required baseline artifact is
|
|
848
|
+
// a USER workflow (editable by design) — reported, never touched.
|
|
849
|
+
if (Array.isArray(env.workflows)) {
|
|
850
|
+
for (const wf of env.workflows) {
|
|
851
|
+
const p = normPath(wf.path);
|
|
852
|
+
if (matchedWorkflowPaths.has(p)) continue;
|
|
853
|
+
const isUserArea = p.toLowerCase().startsWith('user/');
|
|
854
|
+
entries.push({
|
|
855
|
+
id: `extra:workflow:${p}`,
|
|
856
|
+
kind: 'workflow',
|
|
857
|
+
requirement: isUserArea ? 'optional' : 'unknown',
|
|
858
|
+
basis: isUserArea ? 'environment_reference' : 'unknown',
|
|
859
|
+
status: isUserArea ? 'unused' : 'unknown',
|
|
860
|
+
action: 'none',
|
|
861
|
+
found: { path: p, sha256: wf.sha256 || null },
|
|
862
|
+
notes: isUserArea
|
|
863
|
+
? ['user workflow — editable by design; NEVER modified, replaced or removed by the installer']
|
|
864
|
+
: ['workflow file outside the user area — left untouched, reported for the user'],
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
return entries;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// ---------------------------------------------------------------------------
|
|
873
|
+
// Shared-runtime resolution (multi-profile, manifest-level)
|
|
874
|
+
// ---------------------------------------------------------------------------
|
|
875
|
+
|
|
876
|
+
function effectiveRuntimeConstraint(manifest, component) {
|
|
877
|
+
const spec = (manifest.runtime_requirements || {})[component] || {};
|
|
878
|
+
if (component === 'comfyui') {
|
|
879
|
+
if (spec.pin && (spec.pin.commit || spec.pin.tag)) {
|
|
880
|
+
return { value: `${repoKey(spec.pin.repository) || '?'}@${spec.pin.commit || spec.pin.tag}`, grade: 'canonical', raw: spec.pin };
|
|
881
|
+
}
|
|
882
|
+
const ref = spec.known_working_reference;
|
|
883
|
+
if (ref && (ref.commit || ref.tag)) {
|
|
884
|
+
return { value: `${repoKey(ref.repository) || '?'}@${ref.commit || ref.tag}`, grade: 'reference', raw: ref };
|
|
885
|
+
}
|
|
886
|
+
return { value: null, grade: 'unknown' };
|
|
887
|
+
}
|
|
888
|
+
if (spec.pin) return { value: String(spec.pin).toLowerCase(), grade: 'canonical' };
|
|
889
|
+
if (spec.known_working_reference && spec.known_working_reference.version) {
|
|
890
|
+
return { value: String(spec.known_working_reference.version).toLowerCase(), grade: 'reference' };
|
|
891
|
+
}
|
|
892
|
+
return { value: null, grade: 'unknown' };
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function pairwiseConflicts(items, component, kind) {
|
|
896
|
+
const conflicts = [];
|
|
897
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
898
|
+
for (let j = i + 1; j < items.length; j += 1) {
|
|
899
|
+
const a = items[i];
|
|
900
|
+
const b = items[j];
|
|
901
|
+
if (a.c.value && b.c.value && a.c.value !== b.c.value) {
|
|
902
|
+
conflicts.push({
|
|
903
|
+
component,
|
|
904
|
+
kind,
|
|
905
|
+
profiles: [a.profile, b.profile],
|
|
906
|
+
detail: `${a.profile}: ${a.c.value} vs ${b.profile}: ${b.c.value}`,
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return conflicts;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Determine whether several profiles can share ONE ComfyUI runtime.
|
|
916
|
+
* Returns an explicit verdict — never silently merges incompatible versions.
|
|
917
|
+
*/
|
|
918
|
+
function resolveSharedRuntime(manifests) {
|
|
919
|
+
if (!Array.isArray(manifests) || manifests.length === 0) {
|
|
920
|
+
throw new Error('resolveSharedRuntime requires a non-empty array of manifests');
|
|
921
|
+
}
|
|
922
|
+
const profiles = manifests.map((m) => (m.profile ? m.profile.id : '<unknown>'));
|
|
923
|
+
const conflicts = [];
|
|
924
|
+
const unknowns = [];
|
|
925
|
+
|
|
926
|
+
const comfy = manifests.map((m) => ({ profile: m.profile.id, c: effectiveRuntimeConstraint(m, 'comfyui') }));
|
|
927
|
+
const torch = manifests.map((m) => ({ profile: m.profile.id, c: effectiveRuntimeConstraint(m, 'torch') }));
|
|
928
|
+
|
|
929
|
+
conflicts.push(...pairwiseConflicts(comfy, 'comfyui', 'requires-isolation'));
|
|
930
|
+
conflicts.push(...pairwiseConflicts(torch, 'torch', 'shared-conflict'));
|
|
931
|
+
|
|
932
|
+
if (manifests.length > 1 && comfy.every((x) => x.c.value === null)) {
|
|
933
|
+
unknowns.push('comfyui: no canonical or known-working constraint in any manifest');
|
|
934
|
+
}
|
|
935
|
+
if (manifests.length > 1 && torch.every((x) => x.c.value === null)) {
|
|
936
|
+
unknowns.push('torch: no canonical or known-working constraint in any manifest');
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
const union = unionDependencies(manifests);
|
|
940
|
+
for (const c of union.conflicts) {
|
|
941
|
+
conflicts.push({ ...c, kind: 'shared-conflict' });
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// combined minimums (minimum policies never conflict — take the strictest)
|
|
945
|
+
const combinedMinimums = {};
|
|
946
|
+
for (const component of ['python', 'nodejs']) {
|
|
947
|
+
let max = null;
|
|
948
|
+
for (const m of manifests) {
|
|
949
|
+
const spec = (m.runtime_requirements || {})[component] || {};
|
|
950
|
+
if (spec.minimum && (max === null || compareVersions(spec.minimum, max) === 1)) max = spec.minimum;
|
|
951
|
+
}
|
|
952
|
+
combinedMinimums[component] = max;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
const hasIsolationConflict = conflicts.some((c) => c.component === 'comfyui');
|
|
956
|
+
const hasSharedConflict = conflicts.some((c) => c.component !== 'comfyui');
|
|
957
|
+
|
|
958
|
+
let verdict;
|
|
959
|
+
if (hasIsolationConflict) verdict = 'requires-isolation';
|
|
960
|
+
else if (hasSharedConflict) verdict = 'shared-conflict';
|
|
961
|
+
else if (unknowns.length > 0) verdict = 'unknown';
|
|
962
|
+
else verdict = 'shared-compatible';
|
|
963
|
+
|
|
964
|
+
const grades = [...comfy, ...torch].filter((x) => x.c.value !== null).map((x) => x.c.grade);
|
|
965
|
+
const evidenceGrade = grades.length === 0 ? 'unknown' : (grades.includes('reference') ? 'reference' : 'canonical');
|
|
966
|
+
|
|
967
|
+
const canShare = verdict === 'shared-compatible';
|
|
968
|
+
const message = canShare
|
|
969
|
+
? `profiles can share one ComfyUI runtime (evidence grade: ${evidenceGrade}${evidenceGrade === 'reference' ? ' — established from known-working reference environments, canonical policy pending' : ''})`
|
|
970
|
+
: verdict === 'unknown'
|
|
971
|
+
? 'cannot determine whether profiles can share one ComfyUI runtime — insufficient evidence'
|
|
972
|
+
: 'profiles cannot safely share one ComfyUI runtime — use isolated environments (separate ComfyUI + venv per profile)';
|
|
973
|
+
|
|
974
|
+
const unionSummary = {
|
|
975
|
+
dependencies_total: union.byId.size,
|
|
976
|
+
custom_nodes: Array.from(union.byId.values()).filter((s) => s.dep.kind === 'custom_node').map((s) => s.dep.id),
|
|
977
|
+
models: Array.from(union.byId.values()).filter((s) => s.dep.kind === 'model' || s.dep.kind === 'model_repo').map((s) => s.dep.id),
|
|
978
|
+
shared_by_multiple_profiles: Array.from(union.byId.values())
|
|
979
|
+
.filter((s) => s.profiles.length > 1)
|
|
980
|
+
.map((s) => ({ id: s.dep.id, profiles: s.profiles })),
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
return {
|
|
984
|
+
verdict,
|
|
985
|
+
can_share: canShare,
|
|
986
|
+
evidence_grade: evidenceGrade,
|
|
987
|
+
profiles,
|
|
988
|
+
conflicts,
|
|
989
|
+
unknowns,
|
|
990
|
+
combined_minimums: combinedMinimums,
|
|
991
|
+
union: unionSummary,
|
|
992
|
+
message,
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// ---------------------------------------------------------------------------
|
|
997
|
+
// Main resolution entry point
|
|
998
|
+
// ---------------------------------------------------------------------------
|
|
999
|
+
|
|
1000
|
+
const CPU_ONLY_NOTE = 'CPU-only mode: no supported GPU runtime detected — CPU PyTorch will be installed and ComfyUI will run with --cpu. Performance will be SIGNIFICANTLY lower; this mode is intended for the TTS/audio profile, not for image/video generation.';
|
|
1001
|
+
const AMD_FALLBACK_NOTE = 'AMD GPU detected, but the installer provides no ROCm/accelerated runtime branch yet — falling back to CPU-only mode (explicit fallback, not a silent degradation).';
|
|
1002
|
+
|
|
1003
|
+
function summarizeHardware(env, manifests) {
|
|
1004
|
+
// env.device comes from the probe; the fallback covers legacy/synthetic
|
|
1005
|
+
// environments (a detected GPU without vendor info is treated as CUDA).
|
|
1006
|
+
const device = env.device || (env.gpu ? 'cuda' : 'cpu');
|
|
1007
|
+
const info = {
|
|
1008
|
+
gpu: env.gpu || null,
|
|
1009
|
+
device,
|
|
1010
|
+
notes: [],
|
|
1011
|
+
};
|
|
1012
|
+
if (device === 'cpu') {
|
|
1013
|
+
if (env.gpu && env.gpu.vendor === 'amd') info.notes.push(AMD_FALLBACK_NOTE);
|
|
1014
|
+
info.notes.push(CPU_ONLY_NOTE);
|
|
1015
|
+
info.sufficient_vram = null; // VRAM is irrelevant in CPU-only mode
|
|
1016
|
+
return info;
|
|
1017
|
+
}
|
|
1018
|
+
const mins = manifests.map((m) => (m.hardware || {}).gpu_min_vram_gb).filter((v) => typeof v === 'number');
|
|
1019
|
+
if (mins.length > 0 && env.gpu && typeof env.gpu.vram_mib === 'number') {
|
|
1020
|
+
const need = Math.max(...mins);
|
|
1021
|
+
const haveGb = env.gpu.vram_mib / 1024;
|
|
1022
|
+
if (haveGb < need) {
|
|
1023
|
+
info.notes.push(`VRAM ${haveGb.toFixed(1)} GB is below the manifest minimum ${need} GB`);
|
|
1024
|
+
info.sufficient_vram = false;
|
|
1025
|
+
} else {
|
|
1026
|
+
info.sufficient_vram = true;
|
|
1027
|
+
}
|
|
1028
|
+
} else {
|
|
1029
|
+
info.sufficient_vram = null;
|
|
1030
|
+
info.notes.push('minimum VRAM is unknown for the selected profiles (manifest hardware.gpu_min_vram_gb=null) — preflight must measure, no automatic judgement');
|
|
1031
|
+
}
|
|
1032
|
+
return info;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* Resolve installation state for one or more profiles against one environment.
|
|
1037
|
+
*
|
|
1038
|
+
* @param {object} args
|
|
1039
|
+
* @param {object|object[]} args.manifests - canonical manifest(s)
|
|
1040
|
+
* @param {object} [args.environment] - environment probe (installed state);
|
|
1041
|
+
* omitted/null = clean machine (empty environment)
|
|
1042
|
+
* @param {string} [args.mode='existing'] - one of RUNTIME_MODES
|
|
1043
|
+
* @param {string} [args.label] - optional environment label (isolation root, etc.)
|
|
1044
|
+
* @returns structured resolution report (see module header)
|
|
1045
|
+
*/
|
|
1046
|
+
function resolveInstallation({ manifests, environment = null, mode = 'existing', label = null }) {
|
|
1047
|
+
if (!RUNTIME_MODES.includes(mode)) {
|
|
1048
|
+
throw new Error(`unknown runtime mode "${mode}" (expected one of ${RUNTIME_MODES.join(', ')})`);
|
|
1049
|
+
}
|
|
1050
|
+
const list = Array.isArray(manifests) ? manifests : [manifests];
|
|
1051
|
+
if (list.length === 0 || list.some((m) => !m || !m.profile)) {
|
|
1052
|
+
throw new Error('resolveInstallation requires at least one valid manifest');
|
|
1053
|
+
}
|
|
1054
|
+
if (mode === 'shared' && list.length < 2) {
|
|
1055
|
+
throw new Error("mode 'shared' requires at least two manifests");
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
const env = environment || createEmptyEnvironment();
|
|
1059
|
+
const warnings = [];
|
|
1060
|
+
const entries = [];
|
|
1061
|
+
|
|
1062
|
+
if (mode === 'managed' && env.comfyui && env.comfyui.present !== false) {
|
|
1063
|
+
warnings.push('managed mode requested, but an existing ComfyUI was detected — fail-safe: it will be compared and reported, never automatically replaced or removed');
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
const sharing = list.length > 1 ? resolveSharedRuntime(list) : null;
|
|
1067
|
+
if (sharing && !sharing.can_share) {
|
|
1068
|
+
warnings.push(`shared runtime: ${sharing.message}`);
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
// --- runtime entries -------------------------------------------------
|
|
1072
|
+
for (const component of RUNTIME_ORDER) {
|
|
1073
|
+
const perManifest = list.map((m) => {
|
|
1074
|
+
const spec = (m.runtime_requirements || {})[component] || {};
|
|
1075
|
+
let verdict;
|
|
1076
|
+
if (component === 'comfyui') verdict = checkComfyuiAgainst(spec, env.comfyui);
|
|
1077
|
+
else if (component === 'torch') verdict = checkTorchAgainst(spec, env.torch, env.device || null);
|
|
1078
|
+
else verdict = checkMinimumAgainst(component, spec, env[component]);
|
|
1079
|
+
return { profile: m.profile.id, verdict, basis: spec.basis };
|
|
1080
|
+
});
|
|
1081
|
+
const combined = list.length === 1 ? perManifest[0].verdict : combineRuntimeVerdicts(perManifest);
|
|
1082
|
+
const basis = perManifest.find((p) => p.basis === 'known_working')
|
|
1083
|
+
? 'known_working'
|
|
1084
|
+
: (perManifest.find((p) => p.basis === 'minimum_supported') ? 'minimum_supported' : (perManifest[0].basis || 'unknown'));
|
|
1085
|
+
entries.push({
|
|
1086
|
+
id: `runtime:${component}`,
|
|
1087
|
+
kind: 'runtime',
|
|
1088
|
+
component,
|
|
1089
|
+
requirement: 'required',
|
|
1090
|
+
basis,
|
|
1091
|
+
profiles: list.map((m) => m.profile.id),
|
|
1092
|
+
expected: expectedRuntime(component, list),
|
|
1093
|
+
found: foundRuntime(component, env),
|
|
1094
|
+
...combined,
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// --- dependency entries ----------------------------------------------
|
|
1099
|
+
const union = unionDependencies(list);
|
|
1100
|
+
const matchedNodeDirs = new Set();
|
|
1101
|
+
const matchedModelPaths = new Set();
|
|
1102
|
+
|
|
1103
|
+
for (const slot of union.byId.values()) {
|
|
1104
|
+
const entry = checkDependency(slot, env);
|
|
1105
|
+
entries.push(entry);
|
|
1106
|
+
// Mark as matched whenever the probe actually found the dependency in
|
|
1107
|
+
// the environment (regardless of installed/incompatible/unused/unknown),
|
|
1108
|
+
// so classifyExtras does not report it a second time.
|
|
1109
|
+
if (entry.found) {
|
|
1110
|
+
if (slot.dep.kind === 'custom_node') {
|
|
1111
|
+
const dir = slot.dep.install && slot.dep.install.directory;
|
|
1112
|
+
if (dir) matchedNodeDirs.add(String(dir).toLowerCase());
|
|
1113
|
+
if (slot.dep.name) matchedNodeDirs.add(String(slot.dep.name).toLowerCase());
|
|
1114
|
+
// also mark whatever directory the probe actually matched on
|
|
1115
|
+
if (entry.found && entry.found.directory) matchedNodeDirs.add(String(entry.found.directory).toLowerCase());
|
|
1116
|
+
} else if (slot.dep.kind === 'model') {
|
|
1117
|
+
matchedModelPaths.add(`${normPath(slot.dep.target_dir)}/${slot.dep.filename}`);
|
|
1118
|
+
} else if (slot.dep.kind === 'model_repo') {
|
|
1119
|
+
const prefix = normPath(slot.dep.target_dir);
|
|
1120
|
+
for (const m of env.models || []) {
|
|
1121
|
+
if (normPath(m.path).startsWith(`${prefix}/`)) matchedModelPaths.add(normPath(m.path));
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// --- workflow entries (Phase 1.5: first-class artifacts) --------------
|
|
1128
|
+
const matchedWorkflowPaths = new Set();
|
|
1129
|
+
for (const m of list) {
|
|
1130
|
+
const wfSection = m.workflows;
|
|
1131
|
+
const artifacts = wfSection && Array.isArray(wfSection.artifacts) ? wfSection.artifacts : [];
|
|
1132
|
+
for (const wf of artifacts) {
|
|
1133
|
+
const entry = checkWorkflow(wf, env, [m.profile.id]);
|
|
1134
|
+
entries.push(entry);
|
|
1135
|
+
if (entry.found && entry.found.path) matchedWorkflowPaths.add(normPath(entry.found.path));
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
// --- worker entries (Phase 1.5: one per profile/worker_type) ----------
|
|
1140
|
+
for (const m of list) {
|
|
1141
|
+
entries.push(checkWorker(m, env));
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// --- extras: unused / unknown (never removed) -------------------------
|
|
1145
|
+
entries.push(...classifyExtras(list, env, matchedNodeDirs, matchedModelPaths, matchedWorkflowPaths));
|
|
1146
|
+
|
|
1147
|
+
// --- summary -----------------------------------------------------------
|
|
1148
|
+
const byStatus = {};
|
|
1149
|
+
for (const s of ENTRY_STATUSES) byStatus[s] = 0;
|
|
1150
|
+
for (const e of entries) byStatus[e.status] = (byStatus[e.status] || 0) + 1;
|
|
1151
|
+
|
|
1152
|
+
const byKind = {};
|
|
1153
|
+
for (const e of entries) byKind[e.kind] = (byKind[e.kind] || 0) + 1;
|
|
1154
|
+
|
|
1155
|
+
const missingRequired = entries.filter((e) => e.status === 'missing' && e.requirement === 'required').length;
|
|
1156
|
+
const incompatible = entries.filter((e) => e.status === 'incompatible').length;
|
|
1157
|
+
const installPlan = entries.filter((e) => e.action === 'install').map((e) => e.id);
|
|
1158
|
+
const configurePlan = entries.filter((e) => e.action === 'configure').map((e) => e.id);
|
|
1159
|
+
const customizedWorkflows = entries.filter((e) => e.kind === 'workflow' && e.grade === 'customized').map((e) => e.id);
|
|
1160
|
+
|
|
1161
|
+
// Hard invariant of Phase 1: resolver never plans destructive operations.
|
|
1162
|
+
for (const e of entries) {
|
|
1163
|
+
if (!ACTIONS.includes(e.action)) {
|
|
1164
|
+
throw new Error(`internal error: resolver produced a forbidden action "${e.action}"`);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
return {
|
|
1169
|
+
mode,
|
|
1170
|
+
label,
|
|
1171
|
+
profiles: list.map((m) => m.profile.id),
|
|
1172
|
+
environment_root: env.root || null,
|
|
1173
|
+
entries,
|
|
1174
|
+
sharing,
|
|
1175
|
+
hardware: summarizeHardware(env, list),
|
|
1176
|
+
summary: {
|
|
1177
|
+
by_status: byStatus,
|
|
1178
|
+
by_kind: byKind,
|
|
1179
|
+
missing_required: missingRequired,
|
|
1180
|
+
incompatible,
|
|
1181
|
+
blocking: missingRequired + incompatible,
|
|
1182
|
+
install_plan: installPlan,
|
|
1183
|
+
configure_plan: configurePlan,
|
|
1184
|
+
customized_workflows: customizedWorkflows,
|
|
1185
|
+
},
|
|
1186
|
+
warnings,
|
|
1187
|
+
safe_to_proceed: incompatible === 0 && (sharing ? sharing.can_share : true),
|
|
1188
|
+
destructive_operations: Object.freeze([]),
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
function expectedRuntime(component, manifests) {
|
|
1193
|
+
if (component === 'comfyui') {
|
|
1194
|
+
const pins = manifests.map((m) => effectiveRuntimeConstraint(m, 'comfyui')).filter((c) => c.value);
|
|
1195
|
+
return pins.length > 0 ? Array.from(new Set(pins.map((p) => p.value))) : ['unknown (manifest basis=unknown)'];
|
|
1196
|
+
}
|
|
1197
|
+
if (component === 'torch') {
|
|
1198
|
+
const pins = manifests.map((m) => effectiveRuntimeConstraint(m, 'torch')).filter((c) => c.value);
|
|
1199
|
+
return pins.length > 0 ? Array.from(new Set(pins.map((p) => p.value))) : ['unknown (manifest basis=unknown)'];
|
|
1200
|
+
}
|
|
1201
|
+
const mins = manifests
|
|
1202
|
+
.map((m) => ((m.runtime_requirements || {})[component] || {}).minimum)
|
|
1203
|
+
.filter(Boolean);
|
|
1204
|
+
return mins.length > 0 ? [`>= ${mins.join(', >= ')}`] : ['unknown'];
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
function foundRuntime(component, env) {
|
|
1208
|
+
const probe = env[component];
|
|
1209
|
+
if (probe === undefined) return 'not probed';
|
|
1210
|
+
if (!probe) return 'absent';
|
|
1211
|
+
if (component === 'comfyui') {
|
|
1212
|
+
return { version: probe.version || probe.tag || null, commit: probe.commit || null, repository: probe.repository || null };
|
|
1213
|
+
}
|
|
1214
|
+
return { version: probe.version || null };
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
// ---------------------------------------------------------------------------
|
|
1218
|
+
// Isolated mode (data model + interface; full implementation is later)
|
|
1219
|
+
// ---------------------------------------------------------------------------
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* Plan several isolated environments on one GPU machine.
|
|
1223
|
+
* Each assignment = one worker's own ComfyUI+venv root with its profile(s).
|
|
1224
|
+
* Phase 1: validates distinct roots and resolves each environment
|
|
1225
|
+
* independently; no cross-environment mutation is possible by design.
|
|
1226
|
+
*
|
|
1227
|
+
* @param {Array<{manifests: object|object[], environment: object, label?: string}>} assignments
|
|
1228
|
+
*/
|
|
1229
|
+
function planIsolatedEnvironments(assignments) {
|
|
1230
|
+
if (!Array.isArray(assignments) || assignments.length === 0) {
|
|
1231
|
+
throw new Error('planIsolatedEnvironments requires a non-empty assignments array');
|
|
1232
|
+
}
|
|
1233
|
+
const issues = [];
|
|
1234
|
+
const roots = new Set();
|
|
1235
|
+
assignments.forEach((a, i) => {
|
|
1236
|
+
const root = a.environment && a.environment.root;
|
|
1237
|
+
if (!root) {
|
|
1238
|
+
issues.push(`assignment[${i}] has no environment.root — isolated environments must have distinct roots`);
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
const key = normPath(root).toLowerCase();
|
|
1242
|
+
if (roots.has(key)) {
|
|
1243
|
+
issues.push(`assignment[${i}] reuses root "${root}" — isolated environments must not share a root`);
|
|
1244
|
+
}
|
|
1245
|
+
roots.add(key);
|
|
1246
|
+
});
|
|
1247
|
+
|
|
1248
|
+
const environments = assignments.map((a) => resolveInstallation({
|
|
1249
|
+
manifests: a.manifests,
|
|
1250
|
+
environment: a.environment,
|
|
1251
|
+
mode: 'isolated',
|
|
1252
|
+
label: a.label || (a.environment && a.environment.root) || null,
|
|
1253
|
+
}));
|
|
1254
|
+
|
|
1255
|
+
return {
|
|
1256
|
+
ok: issues.length === 0,
|
|
1257
|
+
issues,
|
|
1258
|
+
environments,
|
|
1259
|
+
machine_summary: {
|
|
1260
|
+
environments_total: environments.length,
|
|
1261
|
+
blocking_total: environments.reduce((s, r) => s + r.summary.blocking, 0),
|
|
1262
|
+
},
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
module.exports = {
|
|
1267
|
+
RUNTIME_MODES,
|
|
1268
|
+
ENTRY_STATUSES,
|
|
1269
|
+
ACTIONS,
|
|
1270
|
+
SHARING_VERDICTS,
|
|
1271
|
+
SIZE_TOLERANCE,
|
|
1272
|
+
parseVersion,
|
|
1273
|
+
compareVersions,
|
|
1274
|
+
shaMatch,
|
|
1275
|
+
reposEqual,
|
|
1276
|
+
createEmptyEnvironment,
|
|
1277
|
+
unionDependencies,
|
|
1278
|
+
effectiveRuntimeConstraint,
|
|
1279
|
+
resolveSharedRuntime,
|
|
1280
|
+
resolveInstallation,
|
|
1281
|
+
planIsolatedEnvironments,
|
|
1282
|
+
checkWorkflow,
|
|
1283
|
+
checkWorker,
|
|
1284
|
+
checkTorchAgainst,
|
|
1285
|
+
summarizeHardware,
|
|
1286
|
+
CPU_ONLY_NOTE,
|
|
1287
|
+
};
|