@animastor/installer 0.1.1 → 0.2.9
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/README.md +153 -1
- package/ai/install-manifests/audio/qwen-tts.json +6 -7
- package/ai/install-manifests/image/qwen-image.json +3 -3
- package/ai/install-manifests/video/ltx-2.3.json +9 -9
- package/package.json +3 -3
- package/src/installer/cli.js +1493 -214
- package/src/installer/compatibility-resolver.js +58 -11
- package/src/installer/engine/comfy-owner.js +385 -0
- package/src/installer/engine/downloader.js +26 -0
- package/src/installer/engine/engine.js +600 -61
- package/src/installer/engine/fixes.js +96 -0
- package/src/installer/engine/io.js +33 -2
- package/src/installer/engine/node-deps.js +560 -0
- package/src/installer/engine/overrides.js +375 -0
- package/src/installer/engine/prereq.js +176 -0
- package/src/installer/engine/probe.js +265 -8
- package/src/installer/engine/pydeps.js +204 -0
- package/src/installer/engine/summary.js +124 -0
- package/src/installer/engine/tty.js +214 -0
- package/src/installer/engine/worker.js +736 -52
- package/src/installer/install-plan.js +99 -15
- package/src/installer/management.js +342 -13
- package/src/installer/platform/linux.js +17 -0
- package/src/installer/setup-contract.js +35 -23
- package/src/installer/verification-report.js +21 -5
|
@@ -145,6 +145,149 @@ function probeNodejs(io) {
|
|
|
145
145
|
return v ? { version: v } : null;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
function nodeMajor(version) {
|
|
149
|
+
const m = /^v?(\d+)/.exec(String(version || ''));
|
|
150
|
+
return m ? Number(m[1]) : 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The Node.js binary the worker must run with: the one running this
|
|
155
|
+
* installer when it is >= 20 (the bootstrap verified or provisioned it),
|
|
156
|
+
* otherwise the first `node`/`node22`/`node20` on PATH that is >= 20.
|
|
157
|
+
* Written to .env as NODE_BIN so start-worker.sh, the `animastor` tool and
|
|
158
|
+
* the installer start the SAME binary (no silent fallback to an old system
|
|
159
|
+
* Node 18).
|
|
160
|
+
* @returns {{ bin: string, version: string } | null}
|
|
161
|
+
*/
|
|
162
|
+
function pickNodeBinary(io, { execPath = process.execPath, execVersion = process.versions.node } = {}) {
|
|
163
|
+
if (execPath && nodeMajor(execVersion) >= 20) return { bin: execPath, version: execVersion };
|
|
164
|
+
for (const cand of ['node', 'node22', 'node20']) {
|
|
165
|
+
const r = io.exec(cand, ['-p', 'process.execPath + " " + process.versions.node']);
|
|
166
|
+
if (r.code !== 0) continue;
|
|
167
|
+
const [bin, version] = firstLine(r.stdout).split(' ');
|
|
168
|
+
if (bin && nodeMajor(version) >= 20) return { bin, version };
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Version of a node binary (e.g. NODE_BIN from .env) or null. */
|
|
174
|
+
function nodeBinaryVersion(io, bin) {
|
|
175
|
+
if (!bin) return null;
|
|
176
|
+
const r = io.exec(bin, ['--version']);
|
|
177
|
+
if (r.code !== 0) return null;
|
|
178
|
+
return firstLine(r.stdout).replace(/^v/, '') || null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* A ComfyUI process of the current user (python ... main.py): pid, cwd
|
|
183
|
+
* (the ComfyUI root), --port and --baseurl from its command line. Used to
|
|
184
|
+
* find the user's existing ComfyUI when it does not live in ~/ComfyUI and to
|
|
185
|
+
* learn the port/prefix instead of guessing. Linux only (/proc); null
|
|
186
|
+
* elsewhere or when none runs.
|
|
187
|
+
*/
|
|
188
|
+
function detectRunningComfyUI(io, { uid = (typeof process.getuid === 'function' ? process.getuid() : null) } = {}) {
|
|
189
|
+
const all = listRunningComfyUI(io, { uid });
|
|
190
|
+
if (all.length === 0) return null;
|
|
191
|
+
const { pid, root, port, baseurl } = all[0];
|
|
192
|
+
return { pid, root, port, baseurl };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Every ComfyUI process of the account: pid, cwd (the ComfyUI root) and the
|
|
197
|
+
* --listen / --port / --baseurl values from its own command line. Linux only
|
|
198
|
+
* (/proc); [] elsewhere or when none runs. Order = pgrep order (newest
|
|
199
|
+
* processes are not guaranteed first — callers must not rely on it).
|
|
200
|
+
*/
|
|
201
|
+
function listRunningComfyUI(io, { uid = (typeof process.getuid === 'function' ? process.getuid() : null) } = {}) {
|
|
202
|
+
if (uid == null) return [];
|
|
203
|
+
let r = null;
|
|
204
|
+
try { r = io.exec('pgrep', ['-u', String(uid), '-f', 'main\\.py']); } catch (_) { r = null; }
|
|
205
|
+
if (!r || r.code !== 0) return [];
|
|
206
|
+
const out = [];
|
|
207
|
+
for (const pidStr of String(r.stdout || '').split(/\s+/).filter(Boolean)) {
|
|
208
|
+
const pid = Number(pidStr);
|
|
209
|
+
if (!Number.isFinite(pid) || pid <= 0) continue;
|
|
210
|
+
let cwd = null;
|
|
211
|
+
let argv = [];
|
|
212
|
+
try { cwd = io.fs.readlinkSync(`/proc/${pid}/cwd`); } catch (_) { cwd = null; }
|
|
213
|
+
try { argv = String(io.fs.readFileSync(`/proc/${pid}/cmdline`, 'utf8')).split('\0').filter(Boolean); } catch (_) { argv = []; }
|
|
214
|
+
if (!argv.some((a) => /(^|\/)main\.py$/.test(a))) continue;
|
|
215
|
+
const flag = (name) => {
|
|
216
|
+
const i = argv.indexOf(name);
|
|
217
|
+
if (i !== -1 && argv[i + 1]) return argv[i + 1];
|
|
218
|
+
const eq = argv.find((a) => a.startsWith(`${name}=`));
|
|
219
|
+
return eq ? eq.slice(name.length + 1) : null;
|
|
220
|
+
};
|
|
221
|
+
const port = flag('--port');
|
|
222
|
+
out.push({
|
|
223
|
+
pid,
|
|
224
|
+
root: cwd && io.fs.existsSync(path.join(cwd, 'main.py')) ? cwd : null,
|
|
225
|
+
// ComfyUI defaults to 8188 when --port is absent
|
|
226
|
+
port: port ? Number(port) : 8188,
|
|
227
|
+
listen: flag('--listen'),
|
|
228
|
+
baseurl: flag('--baseurl'),
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Resolve the ComfyUI root: an explicit --root wins; then the default
|
|
236
|
+
* (~/ComfyUI) when it holds a ComfyUI; then the root of the user's running
|
|
237
|
+
* ComfyUI process; finally the default (a managed install creates it).
|
|
238
|
+
* @returns {{ root: string, source: 'flag'|'default'|'running-process' }}
|
|
239
|
+
*/
|
|
240
|
+
function resolveComfyRoot(io, { explicit = null, defaultRoot, running = undefined } = {}) {
|
|
241
|
+
if (explicit) return { root: explicit, source: 'flag' };
|
|
242
|
+
if (defaultRoot && io.fs.existsSync(path.join(defaultRoot, 'main.py'))) return { root: defaultRoot, source: 'default' };
|
|
243
|
+
const proc = running === undefined ? detectRunningComfyUI(io) : running;
|
|
244
|
+
if (proc && proc.root) return { root: proc.root, source: 'running-process' };
|
|
245
|
+
return { root: defaultRoot, source: 'default' };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* True for a REAL ComfyUI /system_stats answer (installer 0.2.2): the payload
|
|
250
|
+
* carries a `system` object (ComfyUI always sends `system` + `devices`; the
|
|
251
|
+
* system block alone is its signature). A wrong reverse-proxy prefix answers
|
|
252
|
+
* 404/HTML, another service answers its own JSON — a bare 200 JSON object is
|
|
253
|
+
* NOT proof (a notebook proxy or a coworker's app would otherwise be
|
|
254
|
+
* accepted as "our" ComfyUI and wired into COMFY_URL).
|
|
255
|
+
*/
|
|
256
|
+
function isSystemStats(json) {
|
|
257
|
+
return !!(json && typeof json === 'object' && !Array.isArray(json)
|
|
258
|
+
&& json.system && typeof json.system === 'object' && !Array.isArray(json.system));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Probe the ComfyUI API base the worker must use (COMFY_URL). The plain
|
|
263
|
+
* http://127.0.0.1:<port> is tried FIRST; a reverse-proxy prefix (notebook
|
|
264
|
+
* deployments) only when the plain URL does not answer. Never guessed: the
|
|
265
|
+
* returned URL answered GET /system_stats with a ComfyUI payload.
|
|
266
|
+
* @param {object} opts { port, prefixes: string[] (e.g. NOTEBOOK_PATH, --baseurl), timeoutMs }
|
|
267
|
+
* @returns {Promise<{ url: string, prefixed: boolean, tried: string[] } | { url: null, tried: string[] }>}
|
|
268
|
+
*/
|
|
269
|
+
async function probeComfyUrl(io, { port, prefixes = [], timeoutMs = 3000 } = {}) {
|
|
270
|
+
const base = `http://127.0.0.1:${port}`;
|
|
271
|
+
const candidates = [base];
|
|
272
|
+
for (const p of prefixes) {
|
|
273
|
+
if (!p) continue;
|
|
274
|
+
const norm = `/${String(p).replace(/^\/+|\/+$/g, '')}`;
|
|
275
|
+
if (norm === '/') continue;
|
|
276
|
+
const url = `${base}${norm}`;
|
|
277
|
+
if (!candidates.includes(url)) candidates.push(url);
|
|
278
|
+
}
|
|
279
|
+
for (const url of candidates) {
|
|
280
|
+
try {
|
|
281
|
+
const opts = typeof AbortSignal !== 'undefined' && AbortSignal.timeout ? { signal: AbortSignal.timeout(timeoutMs) } : {};
|
|
282
|
+
const res = await io.http.fetchJson(`${url}/system_stats`, opts);
|
|
283
|
+
if (res && res.status === 200 && isSystemStats(res.json)) {
|
|
284
|
+
return { url, prefixed: url !== base, tried: candidates };
|
|
285
|
+
}
|
|
286
|
+
} catch (_) { /* next candidate */ }
|
|
287
|
+
}
|
|
288
|
+
return { url: null, tried: candidates };
|
|
289
|
+
}
|
|
290
|
+
|
|
148
291
|
function probeCustomNodes(io, root) {
|
|
149
292
|
const dir = path.join(root, 'custom_nodes');
|
|
150
293
|
if (!io.fs.isDirectory(dir)) return [];
|
|
@@ -162,23 +305,118 @@ function probeCustomNodes(io, root) {
|
|
|
162
305
|
return out;
|
|
163
306
|
}
|
|
164
307
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
308
|
+
/**
|
|
309
|
+
* Walk one model folder. `relDir` is the CANONICAL ComfyUI-relative path the
|
|
310
|
+
* files are reported under (models/<folder>/...), `absDir` where they really
|
|
311
|
+
* live — the same for the default layout, different for a folder declared in
|
|
312
|
+
* extra_model_paths.yaml. `location` (absolute folder base) is attached to
|
|
313
|
+
* files found outside the default layout so the engine downloads missing
|
|
314
|
+
* pieces next to them, never into a second copy.
|
|
315
|
+
*/
|
|
316
|
+
function walkModelDir(io, absDir, relDir, out, { depth = 0, location = null } = {}) {
|
|
317
|
+
if (!io.fs.isDirectory(absDir)) return;
|
|
318
|
+
let names = [];
|
|
319
|
+
try { names = io.fs.readdirSync(absDir); } catch (_) { return; }
|
|
320
|
+
for (const name of names) {
|
|
169
321
|
const rel = `${relDir}/${name}`;
|
|
170
|
-
|
|
322
|
+
let st;
|
|
323
|
+
try { st = io.fs.statSync(path.join(absDir, name)); } catch (_) { continue; }
|
|
171
324
|
if (st.isDirectory) {
|
|
172
|
-
if (depth <
|
|
325
|
+
if (depth < 4) walkModelDir(io, path.join(absDir, name), rel, out, { depth: depth + 1, location });
|
|
173
326
|
} else if (st.isFile) {
|
|
174
|
-
out.push({ path: rel, size_bytes: st.size });
|
|
327
|
+
out.push(location ? { path: rel, size_bytes: st.size, location } : { path: rel, size_bytes: st.size });
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Minimal extra_model_paths.yaml reader (ComfyUI's own format):
|
|
334
|
+
*
|
|
335
|
+
* comfyui:
|
|
336
|
+
* base_path: /data/ComfyUI/
|
|
337
|
+
* checkpoints: models/checkpoints/
|
|
338
|
+
* TTS: models/TTS/
|
|
339
|
+
* loras: |
|
|
340
|
+
* models/loras/
|
|
341
|
+
* more_loras/
|
|
342
|
+
*
|
|
343
|
+
* Returns [{ folder, path }] with absolute paths (relative entries resolve
|
|
344
|
+
* against the section's base_path, else against the ComfyUI root). Unknown
|
|
345
|
+
* syntax is skipped — never guessed.
|
|
346
|
+
*/
|
|
347
|
+
function parseExtraModelPaths(text, root) {
|
|
348
|
+
const out = [];
|
|
349
|
+
const sections = [];
|
|
350
|
+
let cur = null;
|
|
351
|
+
let blockKey = null;
|
|
352
|
+
let blockIndent = 0;
|
|
353
|
+
for (const raw of String(text || '').split(/\r?\n/)) {
|
|
354
|
+
const noComment = raw.replace(/\s+#.*$/, '');
|
|
355
|
+
if (!noComment.trim() || noComment.trim().startsWith('#')) continue;
|
|
356
|
+
const indent = noComment.length - noComment.trimStart().length;
|
|
357
|
+
const line = noComment.trim();
|
|
358
|
+
if (blockKey && indent > blockIndent) {
|
|
359
|
+
cur.entries.push({ folder: blockKey, value: line });
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
blockKey = null;
|
|
363
|
+
if (indent === 0) {
|
|
364
|
+
const m = /^([^:]+):\s*$/.exec(line);
|
|
365
|
+
cur = m ? { name: m[1].trim(), base: null, entries: [] } : null;
|
|
366
|
+
if (cur) sections.push(cur);
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (!cur) continue;
|
|
370
|
+
const kv = /^([A-Za-z0-9_.-]+):\s*(.*)$/.exec(line);
|
|
371
|
+
if (!kv) continue;
|
|
372
|
+
const key = kv[1];
|
|
373
|
+
const value = kv[2].replace(/^['"]|['"]$/g, '').trim();
|
|
374
|
+
if (key === 'base_path') { cur.base = value; continue; }
|
|
375
|
+
if (key === 'is_default' || key === 'download_model_base') continue;
|
|
376
|
+
if (value === '|' || value === '>' || value === '|-' || value === '') {
|
|
377
|
+
blockKey = key;
|
|
378
|
+
blockIndent = indent;
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
cur.entries.push({ folder: key, value });
|
|
382
|
+
}
|
|
383
|
+
for (const sec of sections) {
|
|
384
|
+
const base = sec.base ? (path.isAbsolute(sec.base) ? sec.base : path.join(root, sec.base)) : root;
|
|
385
|
+
for (const e of sec.entries) {
|
|
386
|
+
const v = e.value.replace(/^['"]|['"]$/g, '');
|
|
387
|
+
if (!v) continue;
|
|
388
|
+
out.push({ folder: e.folder, path: path.normalize(path.isAbsolute(v) ? v : path.join(base, v)) });
|
|
175
389
|
}
|
|
176
390
|
}
|
|
391
|
+
return out;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Additional model folders: extra_model_paths.yaml next to the ComfyUI root
|
|
396
|
+
* (the file ComfyUI itself reads). Each entry maps a folder name (e.g. TTS,
|
|
397
|
+
* the folder the ComfyUI-Qwen3-TTS loader resolves via
|
|
398
|
+
* folder_paths.get_folder_paths("TTS")) to an absolute directory.
|
|
399
|
+
*/
|
|
400
|
+
function extraModelFolders(io, root) {
|
|
401
|
+
const yamlPath = path.join(root, 'extra_model_paths.yaml');
|
|
402
|
+
if (!io.fs.existsSync(yamlPath)) return [];
|
|
403
|
+
try {
|
|
404
|
+
return parseExtraModelPaths(io.fs.readFileSync(yamlPath, 'utf8'), root);
|
|
405
|
+
} catch (_) {
|
|
406
|
+
return [];
|
|
407
|
+
}
|
|
177
408
|
}
|
|
178
409
|
|
|
179
410
|
function probeModels(io, root) {
|
|
180
411
|
const out = [];
|
|
181
|
-
for (const dir of MODEL_DIRS)
|
|
412
|
+
for (const dir of MODEL_DIRS) walkModelDir(io, path.join(root, dir), dir, out);
|
|
413
|
+
const seen = new Set(MODEL_DIRS.map((d) => path.normalize(path.join(root, d))));
|
|
414
|
+
for (const extra of extraModelFolders(io, root)) {
|
|
415
|
+
const abs = extra.path.replace(/[\\/]+$/, '');
|
|
416
|
+
if (seen.has(path.normalize(abs))) continue; // same as the default layout
|
|
417
|
+
seen.add(path.normalize(abs));
|
|
418
|
+
walkModelDir(io, abs, `models/${extra.folder}`, out, { location: abs });
|
|
419
|
+
}
|
|
182
420
|
return out;
|
|
183
421
|
}
|
|
184
422
|
|
|
@@ -265,6 +503,13 @@ function probeEnvironment(io, { root = null, workerDir = null, crypto = null, wo
|
|
|
265
503
|
env.cuda = probeCuda(io);
|
|
266
504
|
env.device = env.gpu && env.gpu.vendor === 'nvidia' ? 'cuda' : 'cpu';
|
|
267
505
|
env.nodejs = probeNodejs(io);
|
|
506
|
+
// The worker runs with NODE_BIN (the installer's own Node >= 20), not with
|
|
507
|
+
// whatever `node` is first in PATH — judge the runtime by that binary and
|
|
508
|
+
// keep the PATH version for information only.
|
|
509
|
+
if (!env.nodejs || nodeMajor(env.nodejs.version) < 20) {
|
|
510
|
+
const pick = pickNodeBinary(io);
|
|
511
|
+
if (pick) env.nodejs = { version: pick.version, binary: pick.bin, path_version: env.nodejs ? env.nodejs.version : null };
|
|
512
|
+
}
|
|
268
513
|
env.comfyui = probeComfyui(io, root);
|
|
269
514
|
env.python = probePython(io, root);
|
|
270
515
|
env.torch = probeTorch(io, root);
|
|
@@ -335,7 +580,19 @@ function renderDetection(env) {
|
|
|
335
580
|
}
|
|
336
581
|
|
|
337
582
|
module.exports = {
|
|
583
|
+
detectRunningComfyUI,
|
|
584
|
+
resolveComfyRoot,
|
|
338
585
|
MODEL_DIRS,
|
|
586
|
+
parseExtraModelPaths,
|
|
587
|
+
probeModels,
|
|
588
|
+
pickNodeBinary,
|
|
589
|
+
nodeBinaryVersion,
|
|
590
|
+
nodeMajor,
|
|
591
|
+
detectRunningComfyUI,
|
|
592
|
+
resolveComfyRoot,
|
|
593
|
+
probeComfyUrl,
|
|
594
|
+
listRunningComfyUI,
|
|
595
|
+
isSystemStats,
|
|
339
596
|
DEVICE_KINDS,
|
|
340
597
|
probeEnvironment,
|
|
341
598
|
probeGpu,
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Installer banner and the final result block.
|
|
5
|
+
*
|
|
6
|
+
* The final block is the ONLY thing a user has to read after a run: either
|
|
7
|
+
* every check is ✓ and "Done — return to the Animastor page", or every ✗ is
|
|
8
|
+
* one line of cause plus one exact fix command. Nothing refers to output
|
|
9
|
+
* "above".
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const BANNER = [
|
|
13
|
+
' _ _ _ ___ __ __ _ ____ _____ ___ ____ ',
|
|
14
|
+
' / \\ | \\ | |_ _| \\/ | / \\ / ___|_ _/ _ \\| _ \\ ',
|
|
15
|
+
' / _ \\ | \\| || || |\\/| | / _ \\ \\___ \\ | || | | | |_) |',
|
|
16
|
+
' / ___ \\| |\\ || || | | |/ ___ \\ ___) || || |_| | _ < ',
|
|
17
|
+
'/_/ \\_\\_| \\_|___|_| |_/_/ \\_\\____/ |_| \\___/|_| \\_\\',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {object} v { installer, worker, profile, profileRevision, hub, bootstrap, platform }
|
|
22
|
+
* @returns {string}
|
|
23
|
+
*/
|
|
24
|
+
function renderBanner(v = {}) {
|
|
25
|
+
const val = (x) => (x ? String(x) : 'unknown');
|
|
26
|
+
const profile = v.profile ? `${v.profile}${v.profileRevision ? ` (${v.profileRevision})` : ''}` : '—';
|
|
27
|
+
return [
|
|
28
|
+
...BANNER,
|
|
29
|
+
'',
|
|
30
|
+
` GPU worker installer ${val(v.installer)}${v.platform ? ` · ${v.platform}` : ''}`,
|
|
31
|
+
` worker bundle ${val(v.worker)} · profile ${profile}`,
|
|
32
|
+
` hub ${val(v.hub)}${v.bootstrap ? ` · bootstrap ${v.bootstrap}` : ''}`,
|
|
33
|
+
'',
|
|
34
|
+
].join('\n');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Exact fix for a failed verification check (label from
|
|
39
|
+
* verification-report.js). `tool` is the `animastor` command (or its
|
|
40
|
+
* absolute path when not in PATH).
|
|
41
|
+
*/
|
|
42
|
+
function fixForCheck(check, { tool = 'animastor', mode = null } = {}) {
|
|
43
|
+
switch (check.label) {
|
|
44
|
+
case 'GPU':
|
|
45
|
+
return 'install the NVIDIA driver so that `nvidia-smi` works, then run: ' + `${tool} doctor`;
|
|
46
|
+
case 'VRAM':
|
|
47
|
+
return 'use a GPU with more VRAM (see the profile minimum on the Animastor setup page)';
|
|
48
|
+
case 'ComfyUI running':
|
|
49
|
+
case 'ComfyUI API':
|
|
50
|
+
return mode === 'managed' ? `${tool} start` : `start your ComfyUI, then run: ${tool} doctor`;
|
|
51
|
+
case 'Worker registration':
|
|
52
|
+
case 'GPU Hub registration':
|
|
53
|
+
return `create a new Worker Key in Animastor → Settings → Workers, then run: ${tool} doctor --new-key`;
|
|
54
|
+
case 'Worker process':
|
|
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
|
+
}
|
|
70
|
+
case 'Runtime':
|
|
71
|
+
return /incompatible|version_mismatch/.test(String(check.detail || ''))
|
|
72
|
+
? `if ComfyUI already works, this can be ignored; to let the installer replace the torch/python runtime run: ${tool} doctor --accept-runtime-change`
|
|
73
|
+
: `${tool} doctor`;
|
|
74
|
+
default:
|
|
75
|
+
return `${tool} doctor`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Verification labels already covered by the end-to-end checks. */
|
|
80
|
+
const COVERED_BY_E2E = new Set(['ComfyUI running', 'ComfyUI API', 'Worker process']);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Build the final block.
|
|
84
|
+
* @param {object} args
|
|
85
|
+
* @param {object|null} args.verification - buildVerificationReport() result
|
|
86
|
+
* @param {Array} [args.e2e] - engine endToEndChecks() result
|
|
87
|
+
* @param {Array} [args.extra] - additional { ok, label, detail, fix } items (blocked steps, remediation)
|
|
88
|
+
* @returns {{ ok: boolean, text: string, failures: Array }}
|
|
89
|
+
*/
|
|
90
|
+
function renderFinalSummary({ verification = null, e2e = [], extra = [], tool = 'animastor', mode = null } = {}) {
|
|
91
|
+
const items = [];
|
|
92
|
+
for (const c of extra || []) items.push(c);
|
|
93
|
+
const e2eIds = new Set((e2e || []).map((c) => c.label));
|
|
94
|
+
for (const c of (verification && verification.checks) || []) {
|
|
95
|
+
if (c.verdict !== false) continue;
|
|
96
|
+
if (COVERED_BY_E2E.has(c.label) && e2e && e2e.length > 0) continue;
|
|
97
|
+
if (e2eIds.has(c.label)) continue;
|
|
98
|
+
items.push({ ok: false, label: c.label, detail: c.detail, fix: fixForCheck(c, { tool, mode }) });
|
|
99
|
+
}
|
|
100
|
+
for (const c of e2e || []) items.push(c);
|
|
101
|
+
|
|
102
|
+
const failures = items.filter((c) => c.ok === false);
|
|
103
|
+
const lines = ['', '==================== RESULT ===================='];
|
|
104
|
+
for (const c of items) {
|
|
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' ? '!' : '·';
|
|
108
|
+
lines.push(`${mark} ${c.label}${c.detail ? `: ${oneLine(c.detail)}` : ''}`);
|
|
109
|
+
if (c.ok === false && c.fix) lines.push(` fix: ${c.fix}`);
|
|
110
|
+
}
|
|
111
|
+
lines.push('');
|
|
112
|
+
if (failures.length === 0) {
|
|
113
|
+
lines.push('Done — return to the Animastor page: the worker shows ONLINE.');
|
|
114
|
+
} else {
|
|
115
|
+
lines.push(`${failures.length} problem(s) left — run the fix command(s) above; \`${tool} doctor\` re-checks and fixes what it can.`);
|
|
116
|
+
}
|
|
117
|
+
return { ok: failures.length === 0, text: lines.join('\n'), failures };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function oneLine(s) {
|
|
121
|
+
return String(s).replace(/\s+/g, ' ').trim();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = { renderBanner, renderFinalSummary, fixForCheck, BANNER };
|