@animastor/installer 0.2.4 → 0.2.10

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.
@@ -0,0 +1,375 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Version replacements made by the persistent node-deps overlay
5
+ * (installer 0.2.6, ADR in animastor-docs INSTALLER_ARCHITECTURE
6
+ * §node deps → "One GPU node — one profile").
7
+ *
8
+ * E2E 02.11 (TIR, audio/qwen-tts): qwen-tts pins transformers==4.57.3, so pip
9
+ * put into ~/animastor/pydeps not only the missing packages but also
10
+ * transformers 4.57.3 (platform 5.0.0), huggingface_hub 0.36.2 (platform
11
+ * 1.3.5) and cryptography 50.0.2 (platform 3.4.8). The overlay is FIRST in
12
+ * sys.path of the whole ComfyUI (prestartup script), so these versions apply
13
+ * to ComfyUI itself and to every other custom node — silently.
14
+ *
15
+ * 1. after the deps are in place the overlay is compared with the platform
16
+ * Python (`python -I`, importlib.metadata, the overlay NOT on sys.path):
17
+ * every package present in both with different versions is a
18
+ * replacement; it is attributed to the node(s) that forced it — a node
19
+ * whose requirement closure (requirements.txt + Requires-Dist, as
20
+ * ComfyUI sees the packages: overlay first) excludes the platform
21
+ * version;
22
+ * 2. a replacement touching a package that ANOTHER profile on this ComfyUI
23
+ * uses (a node of that profile that did not force it), or — with more
24
+ * than one profile — a ComfyUI core requirement (<root>/requirements.txt)
25
+ * whose range excludes the overlay version, is a conflict: it needs
26
+ * consent (interactive question or --accept-node-deps-overrides); boot
27
+ * and --yes never consent.
28
+ */
29
+
30
+ const path = require('path');
31
+
32
+ /**
33
+ * Python run with `-I -c` in the PLATFORM interpreter:
34
+ * argv[1] overlay site-packages, argv[2] ComfyUI requirements.txt ('' = none),
35
+ * argv[3] JSON [{ key, req }] — requirements.txt of the custom nodes.
36
+ * Prints ONE JSON line:
37
+ * { overrides: [{ name, key, platform, overlay }],
38
+ * nodes: [{ key, uses: { <pkg key>: { specs, accepts_platform, accepts_overlay } } }],
39
+ * core: { <pkg key>: { spec, accepts_overlay } } }
40
+ */
41
+ const OVERRIDES_SCRIPT = [
42
+ 'import json, re, sys',
43
+ 'try:',
44
+ ' from packaging.requirements import Requirement',
45
+ ' from packaging.specifiers import SpecifierSet',
46
+ 'except Exception:',
47
+ ' from pip._vendor.packaging.requirements import Requirement',
48
+ ' from pip._vendor.packaging.specifiers import SpecifierSet',
49
+ 'try:',
50
+ ' from importlib import metadata as md',
51
+ 'except Exception:',
52
+ ' import importlib_metadata as md',
53
+ 'def canon(n):',
54
+ ' return re.sub(r"[-_.]+", "-", n).lower()',
55
+ 'overlay_sp = sys.argv[1]',
56
+ 'core_req = sys.argv[2]',
57
+ 'nodes = json.loads(sys.argv[3])',
58
+ 'platform_path = list(sys.path)',
59
+ 'def dists(paths):',
60
+ ' out = {}',
61
+ ' for d in md.distributions(path=paths):',
62
+ ' try:',
63
+ ' n = d.metadata["Name"]',
64
+ ' except Exception:',
65
+ ' n = None',
66
+ ' if n and canon(n) not in out:',
67
+ ' out[canon(n)] = d',
68
+ ' return out',
69
+ 'overlay = dists([overlay_sp])',
70
+ 'platform = dists(platform_path)',
71
+ 'both = dists([overlay_sp] + platform_path)',
72
+ 'overrides = []',
73
+ 'for k, d in sorted(overlay.items()):',
74
+ ' p = platform.get(k)',
75
+ ' if p is None or p.version == d.version:',
76
+ ' continue',
77
+ ' overrides.append({"name": d.metadata["Name"], "key": k, "platform": p.version, "overlay": d.version})',
78
+ 'ov = {o["key"]: o for o in overrides}',
79
+ 'def parse(path):',
80
+ ' out = []',
81
+ ' try:',
82
+ ' f = open(path, encoding="utf-8", errors="replace")',
83
+ ' except Exception:',
84
+ ' return out',
85
+ ' for raw in f:',
86
+ ' line = raw.split(" #")[0].strip()',
87
+ ' if not line or line.startswith("#") or line.startswith("-"):',
88
+ ' continue',
89
+ ' if "://" in line and "@" not in line:',
90
+ ' continue',
91
+ ' try:',
92
+ ' r = Requirement(line)',
93
+ ' except Exception:',
94
+ ' continue',
95
+ ' if r.marker is not None and not r.marker.evaluate():',
96
+ ' continue',
97
+ ' out.append(r)',
98
+ ' return out',
99
+ 'def marker_ok(r, extras):',
100
+ ' if r.marker is None:',
101
+ ' return True',
102
+ ' for e in ("",) + extras:',
103
+ ' try:',
104
+ ' if r.marker.evaluate({"extra": e}):',
105
+ ' return True',
106
+ ' except Exception:',
107
+ ' pass',
108
+ ' return False',
109
+ 'def closure(reqs):',
110
+ ' specs = {}',
111
+ ' seen = set()',
112
+ ' queue = list(reqs)',
113
+ ' while queue:',
114
+ ' r = queue.pop(0)',
115
+ ' k = canon(r.name)',
116
+ ' specs.setdefault(k, []).append(str(r.specifier))',
117
+ ' extras = tuple(sorted(r.extras))',
118
+ ' if (k, extras) in seen:',
119
+ ' continue',
120
+ ' seen.add((k, extras))',
121
+ ' d = both.get(k)',
122
+ ' if d is None:',
123
+ ' continue',
124
+ ' for s in (d.requires or []):',
125
+ ' try:',
126
+ ' rr = Requirement(s)',
127
+ ' except Exception:',
128
+ ' continue',
129
+ ' if marker_ok(rr, extras):',
130
+ ' queue.append(rr)',
131
+ ' return specs',
132
+ 'def accepts(specs, v):',
133
+ ' for s in specs:',
134
+ ' if s and not SpecifierSet(s).contains(v, prereleases=True):',
135
+ ' return False',
136
+ ' return True',
137
+ 'out_nodes = []',
138
+ 'for n in nodes:',
139
+ ' specs = closure(parse(n["req"])) if ov else {}',
140
+ ' uses = {}',
141
+ ' for k, o in ov.items():',
142
+ ' if k in specs:',
143
+ ' s = [x for x in specs[k] if x]',
144
+ ' uses[k] = {"specs": s, "accepts_platform": accepts(s, o["platform"]), "accepts_overlay": accepts(s, o["overlay"])}',
145
+ ' out_nodes.append({"key": n["key"], "uses": uses})',
146
+ 'core = {}',
147
+ 'if core_req and ov:',
148
+ ' for r in parse(core_req):',
149
+ ' k = canon(r.name)',
150
+ ' if k in ov:',
151
+ ' core[k] = {"spec": str(r.specifier), "accepts_overlay": accepts([str(r.specifier)], ov[k]["overlay"])}',
152
+ 'print(json.dumps({"overrides": overrides, "nodes": out_nodes, "core": core}))',
153
+ ].join('\n');
154
+
155
+ /**
156
+ * Required custom nodes with a requirements.txt of ALL profiles on this
157
+ * ComfyUI, one entry per directory with every profile that uses it.
158
+ * @returns {Array<{ directory, reqPath, profiles: string[] }>}
159
+ */
160
+ function nodesOfProfiles(io, { root, manifests }) {
161
+ const byDir = new Map();
162
+ for (const m of manifests || []) {
163
+ const profile = (m && m.profile && m.profile.id) || null;
164
+ for (const dep of (m && m.dependencies) || []) {
165
+ if (dep.kind !== 'custom_node' || dep.requirement !== 'required') continue;
166
+ const dir = (dep.install && dep.install.directory) || dep.name;
167
+ const reqPath = path.join(root, 'custom_nodes', dir, 'requirements.txt');
168
+ if (!io.fs.existsSync(reqPath)) continue;
169
+ const e = byDir.get(dir) || { directory: dir, reqPath, profiles: [] };
170
+ if (profile && !e.profiles.includes(profile)) e.profiles.push(profile);
171
+ byDir.set(dir, e);
172
+ }
173
+ }
174
+ return Array.from(byDir.values());
175
+ }
176
+
177
+ /** Distinct profile ids of the manifests. */
178
+ function profileIds(manifests) {
179
+ return Array.from(new Set((manifests || []).map((m) => m && m.profile && m.profile.id).filter(Boolean)));
180
+ }
181
+
182
+ function majorOf(v) {
183
+ const m = /^\s*v?(\d+)/.exec(String(v || ''));
184
+ return m ? Number(m[1]) : null;
185
+ }
186
+
187
+ /** 'up' | 'down' | null — change of the MAJOR version platform → overlay. */
188
+ function majorChange(platform, overlay) {
189
+ const a = majorOf(platform);
190
+ const b = majorOf(overlay);
191
+ if (a === null || b === null || a === b) return null;
192
+ return b > a ? 'up' : 'down';
193
+ }
194
+
195
+ /**
196
+ * Run the comparison in the platform Python.
197
+ * @returns {{ ok: boolean, error?: string, overrides: object[], nodes: object[], core: object }}
198
+ */
199
+ function inspectOverlay(io, { python, sitePackages, root, nodes }) {
200
+ const coreReq = root ? path.join(root, 'requirements.txt') : '';
201
+ const arg = JSON.stringify((nodes || []).map((n) => ({ key: n.directory, req: n.reqPath })));
202
+ let r = null;
203
+ try {
204
+ r = io.exec(python, ['-I', '-c', OVERRIDES_SCRIPT, sitePackages, coreReq && io.fs.existsSync(coreReq) ? coreReq : '', arg], { timeout: 120000 });
205
+ } catch (err) { r = { code: 1, stderr: err.message }; }
206
+ const empty = { overrides: [], nodes: [], core: {} };
207
+ if (!r || r.code !== 0) return { ok: false, error: String((r && (r.stderr || r.error)) || 'overlay comparison failed').trim().slice(-300), ...empty };
208
+ let parsed = null;
209
+ try { parsed = JSON.parse(String(r.stdout || '').trim().split('\n').pop()); } catch (_) { parsed = null; }
210
+ if (!parsed || !Array.isArray(parsed.overrides)) return { ok: false, error: 'unexpected output of the overlay comparison', ...empty };
211
+ return { ok: true, overrides: parsed.overrides, nodes: Array.isArray(parsed.nodes) ? parsed.nodes : [], core: parsed.core || {} };
212
+ }
213
+
214
+ /**
215
+ * Attribute the replacements and find the conflicts.
216
+ * @param {object} raw inspectOverlay() result
217
+ * @param {Array} nodes nodesOfProfiles() result
218
+ * @param {{ profileCount: number }} opts
219
+ * @returns {{ overrides: object[], conflicts: object[] }}
220
+ */
221
+ function analyzeOverrides(raw, nodes, { profileCount = 1 } = {}) {
222
+ const usesOf = new Map((raw.nodes || []).map((n) => [n.key, n.uses || {}]));
223
+ const overrides = [];
224
+ const conflicts = [];
225
+ for (const o of raw.overrides || []) {
226
+ const users = nodes.filter((n) => (usesOf.get(n.directory) || {})[o.key]);
227
+ const causes = users.filter((n) => usesOf.get(n.directory)[o.key].accepts_platform === false);
228
+ const neededBy = causes.length > 0 ? causes : users;
229
+ const causeProfiles = new Set(neededBy.flatMap((n) => n.profiles));
230
+ const entry = {
231
+ package: o.name,
232
+ key: o.key,
233
+ platform: o.platform,
234
+ overlay: o.overlay,
235
+ major: majorChange(o.platform, o.overlay),
236
+ needed_by: neededBy.map((n) => n.directory),
237
+ profiles: Array.from(causeProfiles),
238
+ };
239
+ overrides.push(entry);
240
+ if (causes.length > 0) {
241
+ for (const n of users) {
242
+ if (causes.includes(n)) continue;
243
+ const u = usesOf.get(n.directory)[o.key];
244
+ for (const p of n.profiles) {
245
+ if (causeProfiles.has(p)) continue;
246
+ conflicts.push({
247
+ kind: 'profile', package: o.name, key: o.key, platform: o.platform, overlay: o.overlay,
248
+ needed_by: entry.needed_by, cause_profiles: entry.profiles,
249
+ profile: p, node: n.directory, specs: u.specs || [], accepts_overlay: u.accepts_overlay !== false,
250
+ });
251
+ }
252
+ }
253
+ }
254
+ const core = (raw.core || {})[o.key];
255
+ if (profileCount > 1 && core && core.accepts_overlay === false) {
256
+ conflicts.push({
257
+ kind: 'core', package: o.name, key: o.key, platform: o.platform, overlay: o.overlay,
258
+ needed_by: entry.needed_by, cause_profiles: entry.profiles,
259
+ profile: null, node: 'ComfyUI', specs: core.spec ? [core.spec] : [], accepts_overlay: false,
260
+ });
261
+ }
262
+ }
263
+ return { overrides, conflicts };
264
+ }
265
+
266
+ /** "transformers platform 5.0.0 → overlay 4.57.3 (needed by qwen3-tts)" */
267
+ function describeOverride(o) {
268
+ const by = o.needed_by && o.needed_by.length > 0 ? o.needed_by.join(', ') : 'no node of the installed profiles';
269
+ return `${o.package} platform ${o.platform} → overlay ${o.overlay} (needed by ${by})`;
270
+ }
271
+
272
+ /** The warning part for a major change, or ''. */
273
+ function majorNote(o) {
274
+ if (!o.major) return '';
275
+ return ` — major version ${o.major === 'up' ? 'UP' : 'DOWN'} (${majorOf(o.platform)} → ${majorOf(o.overlay)}): ComfyUI and every other custom node import this version`;
276
+ }
277
+
278
+ /** One line for a conflict. */
279
+ function describeConflict(c) {
280
+ const head = `${c.package} platform ${c.platform} → overlay ${c.overlay} (needed by ${c.needed_by.join(', ') || '?'}${c.cause_profiles.length ? `, profile ${c.cause_profiles.join(', ')}` : ''})`;
281
+ if (c.kind === 'core') {
282
+ return `${head} is outside the range of the ComfyUI core requirement ${c.package}${c.specs[0] || ''} (<ComfyUI>/requirements.txt)`;
283
+ }
284
+ const range = c.specs.length > 0 ? `requires ${c.specs.join(', ')}; the overlay version is ${c.accepts_overlay ? 'inside' : 'OUTSIDE'} that range` : 'any version';
285
+ return `${head} also changes it for profile ${c.profile} (node ${c.node}, ${range})`;
286
+ }
287
+
288
+ /** Key of an accepted conflict in install-state (package@overlay-version:profile). */
289
+ function conflictKey(c) {
290
+ return `${c.key || String(c.package).toLowerCase()}@${c.overlay}:${c.profile || 'comfyui-core'}`;
291
+ }
292
+
293
+ /** Conflicts that are not in the recorded consent list. */
294
+ function pendingConflicts(conflicts, accepted = []) {
295
+ const ok = new Set((accepted || []).map((a) => (typeof a === 'string' ? a : a && a.key)).filter(Boolean));
296
+ return (conflicts || []).filter((c) => !ok.has(conflictKey(c)));
297
+ }
298
+
299
+ /** Record entry for an accepted conflict. */
300
+ function acceptedEntry(c, at) {
301
+ return { key: conflictKey(c), package: c.package, overlay: c.overlay, profile: c.profile || 'comfyui-core', at };
302
+ }
303
+
304
+ /** The install-state record of a replacement (installer_options.nodeDeps.overrides[]). */
305
+ function recordOf(o) {
306
+ return { package: o.package, platform: o.platform, overlay: o.overlay, major: o.major, needed_by: o.needed_by, profiles: o.profiles };
307
+ }
308
+
309
+ /** RESULT items: [i] for a replacement, ! for a major change. */
310
+ function resultItems(overrides) {
311
+ return (overrides || []).map((o) => ({ ok: o.major ? 'warn' : 'info', label: `${describeOverride(o)}${majorNote(o)}` }));
312
+ }
313
+
314
+ // ---------------------------------------------------------------------------
315
+ // Snapshot of the overlay venv (rollback of a refused replacement)
316
+ // ---------------------------------------------------------------------------
317
+
318
+ function snapshotDir(venvDir) {
319
+ return `${venvDir}.pre-install`;
320
+ }
321
+
322
+ /**
323
+ * Copy the overlay venv aside (`cp -a`) before pip changes it. A stale
324
+ * snapshot of an interrupted run is replaced.
325
+ * @returns {{ ok: boolean, dir: string, reason: string|null }}
326
+ */
327
+ function snapshotOverlay(io, venvDir) {
328
+ const dir = snapshotDir(venvDir);
329
+ try { if (io.fs.existsSync(dir)) io.fs.rmSync(dir, { recursive: true, force: true }); } catch (err) {
330
+ return { ok: false, dir, reason: `cannot remove the stale snapshot ${dir}: ${err.message}` };
331
+ }
332
+ let r = null;
333
+ try { r = io.exec('cp', ['-a', venvDir, dir], { timeout: 30 * 60 * 1000 }); } catch (err) { r = { code: 1, stderr: err.message }; }
334
+ if (!r || r.code !== 0) return { ok: false, dir, reason: `cp -a ${venvDir} ${dir} failed: ${String((r && (r.stderr || r.error)) || '').trim().slice(-200)}` };
335
+ return { ok: true, dir, reason: null };
336
+ }
337
+
338
+ /** Put the snapshot back in place of the overlay venv. */
339
+ function restoreOverlay(io, venvDir) {
340
+ const dir = snapshotDir(venvDir);
341
+ if (!io.fs.existsSync(dir)) return { ok: false, reason: `no snapshot ${dir}` };
342
+ try {
343
+ io.fs.rmSync(venvDir, { recursive: true, force: true });
344
+ io.fs.renameSync(dir, venvDir);
345
+ } catch (err) {
346
+ return { ok: false, reason: `restoring ${venvDir} from ${dir} failed: ${err.message}` };
347
+ }
348
+ return { ok: true, reason: null };
349
+ }
350
+
351
+ /** Remove the snapshot (the change was kept). */
352
+ function dropSnapshot(io, venvDir) {
353
+ try { io.fs.rmSync(snapshotDir(venvDir), { recursive: true, force: true }); } catch (_) { /* best effort */ }
354
+ }
355
+
356
+ module.exports = {
357
+ OVERRIDES_SCRIPT,
358
+ nodesOfProfiles,
359
+ profileIds,
360
+ majorChange,
361
+ inspectOverlay,
362
+ analyzeOverrides,
363
+ describeOverride,
364
+ majorNote,
365
+ describeConflict,
366
+ conflictKey,
367
+ pendingConflicts,
368
+ acceptedEntry,
369
+ recordOf,
370
+ resultItems,
371
+ snapshotDir,
372
+ snapshotOverlay,
373
+ restoreOverlay,
374
+ dropSnapshot,
375
+ };
@@ -0,0 +1,204 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Persistent custom-node Python dependencies for a PLATFORM ComfyUI
5
+ * (installer 0.2.5, ADR in animastor-docs INSTALLER_ARCHITECTURE §node deps).
6
+ *
7
+ * E2E 02.11 (TIR, type A): the platform runs ComfyUI as root with
8
+ * /usr/bin/python3; `pip install` as root writes to
9
+ * /usr/local/lib/python3.10/dist-packages (Debian `posix_local` scheme), and
10
+ * only /home survives a node restart — so the packages of qwen3-tts were gone
11
+ * after every restart, and every boot needed a reinstall plus a restart of
12
+ * the platform's ComfyUI.
13
+ *
14
+ * Instead the packages go into an OVERLAY venv under the installation:
15
+ *
16
+ * ~/animastor/pydeps/py3.10/ python -m venv --without-pip --system-site-packages
17
+ * ~/animastor/pydeps/py3.10/lib/python3.10/site-packages ← only what is MISSING
18
+ *
19
+ * `--system-site-packages` makes pip (the platform's own pip module, run by
20
+ * the overlay interpreter) see everything the platform already has: torch &
21
+ * co. are "already satisfied" and never copied. `--without-pip` needs no
22
+ * ensurepip / python3.X-venv.
23
+ *
24
+ * The platform's ComfyUI sees the overlay through a generated custom node
25
+ * whose `prestartup_script.py` runs inside main.py BEFORE any custom node is
26
+ * imported (ComfyUI execute_prestartup_script). It prepends the overlay
27
+ * site-packages (site.addsitedir → .pth files honoured). Everything lives in
28
+ * /home: after a node restart the platform starts its ComfyUI and the node
29
+ * classes load — no reinstall, no restart.
30
+ */
31
+
32
+ const path = require('path');
33
+
34
+ /** Directory of the generated custom node (custom_nodes/<this>). */
35
+ const PYDEPS_NODE_DIR = 'animastor-pydeps';
36
+ const PRESTARTUP_MARKER = '# animastor: generated prestartup — persistent node dependencies';
37
+
38
+ /** ~/animastor/pydeps for <workerDir> = ~/animastor/worker. */
39
+ function overlayBase(workerDir) {
40
+ return path.join(path.dirname(path.resolve(workerDir)), 'pydeps');
41
+ }
42
+
43
+ /** "3.10" — major.minor of `python`, or null. */
44
+ function pythonTag(io, python) {
45
+ let r = null;
46
+ try { r = io.exec(python, ['-I', '-c', 'import sys; print("%d.%d" % sys.version_info[:2])'], { timeout: 30000 }); } catch (_) { r = null; }
47
+ const m = r && r.code === 0 ? /^(\d+\.\d+)\s*$/.exec(String(r.stdout || '').trim()) : null;
48
+ return m ? m[1] : null;
49
+ }
50
+
51
+ /** Layout of the overlay for one Python X.Y. */
52
+ function overlayPaths(base, tag) {
53
+ const dir = path.join(base, `py${tag}`);
54
+ return {
55
+ dir,
56
+ python: path.join(dir, 'bin', 'python'),
57
+ sitePackages: path.join(dir, 'lib', `python${tag}`, 'site-packages'),
58
+ cfg: path.join(dir, 'pyvenv.cfg'),
59
+ };
60
+ }
61
+
62
+ /**
63
+ * Does this ComfyUI run custom_nodes/<node>/prestartup_script.py before the
64
+ * node imports? (main.py execute_prestartup_script, ComfyUI since 2023.)
65
+ */
66
+ function supportsPrestartup(io, root) {
67
+ try {
68
+ return /prestartup_script/.test(String(io.fs.readFileSync(path.join(root, 'main.py'), 'utf8')));
69
+ } catch (_) { return false; }
70
+ }
71
+
72
+ /** The generated prestartup script (Python), with the overlay base baked in. */
73
+ function renderPrestartupScript(base) {
74
+ return [
75
+ PRESTARTUP_MARKER,
76
+ '# (animastor installer 0.2.5). Do not edit: `animastor doctor` rewrites this file.',
77
+ '# Puts the overlay site-packages of the Animastor installation in front of',
78
+ '# sys.path before ComfyUI imports the custom nodes. The overlay holds ONLY',
79
+ '# the packages the platform Python lacks; it lives in /home and survives',
80
+ '# a node restart. A missing overlay (other Python X.Y) is a no-op.',
81
+ 'import os',
82
+ 'import site',
83
+ 'import sys',
84
+ '',
85
+ `_ANIMASTOR_PYDEPS = ${JSON.stringify(base)}`,
86
+ '',
87
+ '',
88
+ 'def _animastor_pydeps():',
89
+ ' tag = "%d.%d" % sys.version_info[:2]',
90
+ ' sp = os.path.join(_ANIMASTOR_PYDEPS, "py" + tag, "lib", "python" + tag, "site-packages")',
91
+ ' if not os.path.isdir(sp) or sp in sys.path:',
92
+ ' return',
93
+ ' before = list(sys.path)',
94
+ ' site.addsitedir(sp)',
95
+ ' added = [p for p in sys.path if p not in before]',
96
+ ' sys.path[:] = added + [p for p in sys.path if p not in added]',
97
+ ' print("[animastor] node dependencies: %s" % sp)',
98
+ '',
99
+ '',
100
+ 'try:',
101
+ ' _animastor_pydeps()',
102
+ 'except Exception as e: # never break the ComfyUI start',
103
+ ' print("[animastor] node dependencies not added: %s" % e)',
104
+ '',
105
+ ].join('\n');
106
+ }
107
+
108
+ const INIT_PY = [
109
+ '# animastor: generated — see prestartup_script.py. No nodes of its own.',
110
+ 'NODE_CLASS_MAPPINGS = {}',
111
+ 'NODE_DISPLAY_NAME_MAPPINGS = {}',
112
+ '',
113
+ ].join('\n');
114
+
115
+ /**
116
+ * Write custom_nodes/animastor-pydeps/{prestartup_script.py,__init__.py}.
117
+ * Idempotent: unchanged bytes → 'unchanged' (a running ComfyUI needs no
118
+ * restart for it); a foreign directory of the same name is never touched.
119
+ * @returns {{ status: 'created'|'updated'|'unchanged'|'foreign'|'failed', dir: string, reason?: string }}
120
+ */
121
+ function ensurePrestartupNode(io, { root, base }) {
122
+ const dir = path.join(root, 'custom_nodes', PYDEPS_NODE_DIR);
123
+ const script = path.join(dir, 'prestartup_script.py');
124
+ const init = path.join(dir, '__init__.py');
125
+ const wanted = renderPrestartupScript(base);
126
+ let current = null;
127
+ try { current = io.fs.existsSync(script) ? String(io.fs.readFileSync(script, 'utf8')) : null; } catch (_) { current = null; }
128
+ if (current !== null && !current.startsWith(PRESTARTUP_MARKER)) {
129
+ return { status: 'foreign', dir, reason: `${script} was not generated by the installer — left untouched` };
130
+ }
131
+ let initCurrent = null;
132
+ try { initCurrent = io.fs.existsSync(init) ? String(io.fs.readFileSync(init, 'utf8')) : null; } catch (_) { initCurrent = null; }
133
+ if (current === wanted && initCurrent === INIT_PY) return { status: 'unchanged', dir };
134
+ try {
135
+ io.fs.mkdirSync(dir, { recursive: true });
136
+ io.fs.writeFileSync(init, INIT_PY);
137
+ io.fs.writeFileSync(script, wanted);
138
+ } catch (err) {
139
+ return { status: 'failed', dir, reason: err.message };
140
+ }
141
+ return { status: current === null ? 'created' : 'updated', dir };
142
+ }
143
+
144
+ /**
145
+ * Create the overlay venv for `python` (idempotent).
146
+ * @returns {{ ok: boolean, created: boolean, paths: object|null, tag: string|null, reason: string|null }}
147
+ */
148
+ function ensureOverlayVenv(io, { python, base }) {
149
+ const tag = pythonTag(io, python);
150
+ if (!tag) return { ok: false, created: false, paths: null, tag: null, reason: `cannot read the version of ${python}` };
151
+ const p = overlayPaths(base, tag);
152
+ if (io.fs.existsSync(p.cfg) && io.fs.existsSync(p.python)) return { ok: true, created: false, paths: p, tag, reason: null };
153
+ try { io.fs.mkdirSync(base, { recursive: true }); } catch (err) {
154
+ return { ok: false, created: false, paths: p, tag, reason: `cannot create ${base}: ${err.message}` };
155
+ }
156
+ let r = null;
157
+ try { r = io.exec(python, ['-m', 'venv', '--without-pip', '--system-site-packages', p.dir], { timeout: 120000 }); } catch (err) { r = { code: 1, stderr: err.message }; }
158
+ if (!r || r.code !== 0) {
159
+ return { ok: false, created: false, paths: p, tag, reason: `${python} -m venv failed: ${String((r && (r.stderr || r.error)) || '').trim().slice(-300)}` };
160
+ }
161
+ // pip itself comes from the platform's site-packages (system-site-packages).
162
+ let pip = null;
163
+ try { pip = io.exec(p.python, ['-m', 'pip', '--version'], { timeout: 60000 }); } catch (err) { pip = { code: 1, stderr: err.message }; }
164
+ if (!pip || pip.code !== 0) {
165
+ return { ok: false, created: true, paths: p, tag, reason: `pip is not available to ${python} (${String((pip && pip.stderr) || '').trim().slice(-200)})` };
166
+ }
167
+ return { ok: true, created: true, paths: p, tag, reason: null };
168
+ }
169
+
170
+ /**
171
+ * Decide where the node dependencies of a platform ComfyUI go.
172
+ * overlay — the ComfyUI runs prestartup scripts and the overlay venv works;
173
+ * system — fallback (old ComfyUI / no venv module): the 0.2.4 behaviour,
174
+ * packages vanish with a node restart, boot reinstalls them.
175
+ * Nothing is created when `create` is false (read-only check).
176
+ * @returns {{ kind: 'overlay'|'system', base, paths: object|null, sitePackages: string|null, reason: string|null, venv?: object }}
177
+ */
178
+ function planPersistence(io, { python, root, base, create = true }) {
179
+ if (!base) return { kind: 'system', base: null, paths: null, sitePackages: null, reason: 'no installation directory for the overlay' };
180
+ if (!supportsPrestartup(io, root)) {
181
+ return { kind: 'system', base, paths: null, sitePackages: null, reason: `${path.join(root, 'main.py')} has no prestartup_script support (ComfyUI too old)` };
182
+ }
183
+ if (!create) {
184
+ const tag = pythonTag(io, python);
185
+ const p = tag ? overlayPaths(base, tag) : null;
186
+ return { kind: 'overlay', base, paths: p, sitePackages: p ? p.sitePackages : null, reason: null };
187
+ }
188
+ const venv = ensureOverlayVenv(io, { python, base });
189
+ if (!venv.ok) return { kind: 'system', base, paths: null, sitePackages: null, reason: venv.reason, venv };
190
+ return { kind: 'overlay', base, paths: venv.paths, sitePackages: venv.paths.sitePackages, reason: null, venv };
191
+ }
192
+
193
+ module.exports = {
194
+ PYDEPS_NODE_DIR,
195
+ PRESTARTUP_MARKER,
196
+ overlayBase,
197
+ pythonTag,
198
+ overlayPaths,
199
+ supportsPrestartup,
200
+ renderPrestartupScript,
201
+ ensurePrestartupNode,
202
+ ensureOverlayVenv,
203
+ planPersistence,
204
+ };
@@ -53,6 +53,20 @@ function fixForCheck(check, { tool = 'animastor', mode = null } = {}) {
53
53
  return `create a new Worker Key in Animastor → Settings → Workers, then run: ${tool} doctor --new-key`;
54
54
  case 'Worker process':
55
55
  return `${tool} start`;
56
+ case 'ComfyUI node classes': {
57
+ // Installer 0.2.5: one fix per CAUSE; never a bare `doctor` that
58
+ // repeats the same check (live loop E2E 02.11).
59
+ const cause = check.cause || {};
60
+ const foreign = cause.owner === 'foreign' || (cause.owner == null && mode !== 'managed');
61
+ if (cause.kind === 'deps-missing') return `${tool} doctor --yes${foreign ? ' --restart-platform-comfy' : ''}`;
62
+ if (cause.kind === 'restart-needed') return foreign ? `${tool} doctor --restart-platform-comfy` : `${tool} reboot-comfyui`;
63
+ if (cause.kind === 'import-failed') {
64
+ return `fix the import error of the custom node shown above${cause.log_source ? ` (ComfyUI log: ${cause.log_source})` : ''}, then run: ${foreign ? `${tool} doctor --restart-platform-comfy` : `${tool} reboot-comfyui`}`;
65
+ }
66
+ return foreign
67
+ ? `restart ComfyUI from the platform console (or: ${tool} doctor --restart-platform-comfy) and check its log for "IMPORT FAILED"`
68
+ : `${tool} reboot-comfyui, then check <ComfyUI>/comfyui-installer.log for "IMPORT FAILED"`;
69
+ }
56
70
  case 'Runtime':
57
71
  return /incompatible|version_mismatch/.test(String(check.detail || ''))
58
72
  ? `if ComfyUI already works, this can be ignored; to let the installer replace the torch/python runtime run: ${tool} doctor --accept-runtime-change`
@@ -88,7 +102,9 @@ function renderFinalSummary({ verification = null, e2e = [], extra = [], tool =
88
102
  const failures = items.filter((c) => c.ok === false);
89
103
  const lines = ['', '==================== RESULT ===================='];
90
104
  for (const c of items) {
91
- const mark = c.ok === true ? '✓' : c.ok === false ? '✗' : '·';
105
+ // ok: 'info' → [i], 'warn' → ! (installer 0.2.6: node-deps overlay
106
+ // version replacements) — shown, never counted as a failure.
107
+ const mark = c.ok === true ? '✓' : c.ok === false ? '✗' : c.ok === 'info' ? '[i]' : c.ok === 'warn' ? '!' : '·';
92
108
  lines.push(`${mark} ${c.label}${c.detail ? `: ${oneLine(c.detail)}` : ''}`);
93
109
  if (c.ok === false && c.fix) lines.push(` fix: ${c.fix}`);
94
110
  }