@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.
@@ -39,6 +39,7 @@ const prereq = require('./prereq');
39
39
  const management = require('../management');
40
40
  const comfyOwnerMod = require('./comfy-owner');
41
41
  const nodeDeps = require('./node-deps');
42
+ const pydeps = require('./pydeps');
42
43
  const { createProgressReporter } = require('./progress');
43
44
  const { buildVerificationReport } = require('../verification-report');
44
45
 
@@ -401,6 +402,10 @@ async function runInstallation(args) {
401
402
  // a recorded answer survives every run; an explicit flag replaces it.
402
403
  const restartPlatform = options.restartPlatformComfy !== undefined ? options.restartPlatformComfy : saved.restartPlatformComfy;
403
404
  if (restartPlatform === true || restartPlatform === false) st.installer_options.restartPlatformComfy = restartPlatform;
405
+ // Node-deps record of the dependency gate (overlay, version
406
+ // replacements, accepted conflicts — installer 0.2.6) is written by
407
+ // the CLI before the engine runs: kept, not dropped.
408
+ if (saved.nodeDeps) st.installer_options.nodeDeps = saved.nodeDeps;
404
409
  // Hub version seen by this run (bootstrap env) — `animastor doctor`
405
410
  // prints it instead of "hub unknown" on later runs.
406
411
  // Who runs the ComfyUI, as seen by THIS run (installer 0.2.3): the
@@ -416,6 +421,11 @@ async function runInstallation(args) {
416
421
  if (options.hubVersion) st.hub_version = String(options.hubVersion);
417
422
  else if (process.env.ANIMASTOR_HUB_VERSION) st.hub_version = process.env.ANIMASTOR_HUB_VERSION;
418
423
  }
424
+ // Installer 0.2.5: what the CLI created before the engine ran (node-deps
425
+ // overlay, prestartup custom node) is owned → removed by `uninstall`.
426
+ for (const e of options.ownedServices || []) {
427
+ if (e && e.path && !dryRun) state.addOwnedComponent(st, 'services', e);
428
+ }
419
429
  const save = () => state.saveState(io, statePath, st, io.now);
420
430
  if (initialState) {
421
431
  for (const line of renderResumeSummary(st)) log.info(line);
@@ -968,6 +978,7 @@ async function runInstallation(args) {
968
978
  httpFetchText: null, log,
969
979
  update: decisions.apply_fixes !== false,
970
980
  nodeBin,
981
+ previousBundleFiles: previousBundleFilesOf(st.components.worker, workerDir),
971
982
  }));
972
983
  } finally {
973
984
  if (bundleTmp) {
@@ -979,12 +990,19 @@ async function runInstallation(args) {
979
990
  if (bundleRes.ok && bundleRes.value.status === 'installed') {
980
991
  // Ownership is per-file: a pre-existing worker dir keeps its
981
992
  // own files; only what the installer copied is registered.
993
+ const prevW = st.components.worker && st.components.worker.dir
994
+ && path.resolve(st.components.worker.dir) === path.resolve(workerDir) ? st.components.worker : null;
995
+ const removedSet = new Set(bundleRes.value.files_removed || []);
982
996
  st.components.worker = {
983
- owned: bundleRes.value.dir_created === true,
997
+ // a re-run over the installer's own dir keeps its ownership and earlier files
998
+ owned: bundleRes.value.dir_created === true || (prevW ? prevW.owned === true : false),
984
999
  dir: workerDir,
985
- files_installed: bundleRes.value.files_installed || [],
1000
+ files_installed: [...new Set([...(prevW ? prevW.files_installed || [] : []), ...(bundleRes.value.files_installed || [])])]
1001
+ .filter((f) => !removedSet.has(f)),
986
1002
  files_kept: bundleRes.value.files_kept || [],
987
- env_created: null, // finalized by the .env step below
1003
+ // installer 0.2.10: the deployed bundle's file list — the next update removes what it no longer ships
1004
+ bundle_files: bundleRes.value.bundle_files || [],
1005
+ env_created: prevW ? (prevW.env_created ?? null) : null, // finalized by the .env step below
988
1006
  };
989
1007
  }
990
1008
  state.setArtifact(st, w.id, bundleRes.ok && bundleRes.value.status === 'installed' ? 'installed' : 'failed');
@@ -992,6 +1010,21 @@ async function runInstallation(args) {
992
1010
  }
993
1011
  }
994
1012
 
1013
+ // 4.6a node-classes.json (installer 0.2.7) — the profile's node
1014
+ // classes for the worker's readiness gate (bundle >= 2.2.2). Written
1015
+ // on every run where a bundle is installed (fresh install, update,
1016
+ // re-run); never fatal.
1017
+ if (workerDir && io.fs.existsSync(path.join(workerDir, 'worker.cjs'))) {
1018
+ const nc = worker.writeNodeClasses(io, { workerDir, manifests, log });
1019
+ result.results.worker.push({ id: 'node-classes', node_classes: nc });
1020
+ if (nc.status === 'written' && st.components.worker) {
1021
+ const owned = new Set(st.components.worker.files_installed || []);
1022
+ owned.add(worker.NODE_CLASSES_FILE);
1023
+ st.components.worker.files_installed = Array.from(owned);
1024
+ save();
1025
+ }
1026
+ }
1027
+
995
1028
  // 4.7 Worker Key + .env configuration ----------------------------------------
996
1029
  // Runs on EVERY install where the worker is wanted — even full re-runs
997
1030
  // whose plan has no worker-key step (nothing left to ask). configureEnv
@@ -1139,9 +1172,26 @@ async function runInstallation(args) {
1139
1172
  let workerStart = null;
1140
1173
  if (options.startWorker && workerDir && !runtimeFatal) {
1141
1174
  const r = await log.step('start worker', async () => {
1142
- const bundleChanged = result.results.worker.some((x) => x.bundle && (x.bundle.files_installed || []).length > 0);
1143
- const res = worker.startWorker(io, { workerDir, nodeBin, graceMs: options.workerGraceMs || 3000, forceRestart: workerConfigChanged || bundleChanged });
1175
+ const bundleChanged = !!options.bundleRefreshedEarly || result.results.worker.some((x) => x.bundle && (x.bundle.files_installed || []).length > 0);
1176
+ // Installer 0.2.8: a running worker is restarted only when its
1177
+ // configuration changed, and never in the middle of a task
1178
+ // (worker.ensureWorker: wait up to --wait-job-ms, else deferred).
1179
+ const configChanged = [];
1180
+ if (workerConfigChanged) configChanged.push('.env changed by this run');
1181
+ if (bundleChanged) configChanged.push('worker bundle updated by this run');
1182
+ const res = await worker.ensureWorker(io, {
1183
+ workerDir, nodeBin, graceMs: options.workerGraceMs || 3000,
1184
+ configChanged,
1185
+ force: !!options.forceWorkerRestart,
1186
+ boot: !!options.boot,
1187
+ waitJobMs: options.waitJobMs !== undefined ? options.waitJobMs : worker.DEFAULT_WAIT_JOB_MS,
1188
+ pollMs: options.jobPollMs || 5000,
1189
+ sleep: options.sleep || null,
1190
+ log,
1191
+ tool: options.toolCommand || toolCommandFrom(result.results.management_tools),
1192
+ });
1144
1193
  workerStart = res;
1194
+ if (res.deferred) throw new Error(res.reason);
1145
1195
  if (!res.started || !res.alive) {
1146
1196
  // An immediate exit is usually the fail-closed credential
1147
1197
  // gate — say so (the fix is a new key, not a re-run).
@@ -1154,7 +1204,7 @@ async function runInstallation(args) {
1154
1204
  }
1155
1205
  throw new Error(res.reason || 'worker did not start');
1156
1206
  }
1157
- if (res.already_running) log.info(`worker already running (pid ${res.pid}) — not spawning a second instance`);
1207
+
1158
1208
  // The 90 s "worker → ComfyUI ready" window opens only once
1159
1209
  // ComfyUI itself answers (installer 0.2.3) — a ComfyUI that is
1160
1210
  // still loading must not eat the worker's time.
@@ -1172,7 +1222,13 @@ async function runInstallation(args) {
1172
1222
  return { ...res, ...ready };
1173
1223
  });
1174
1224
  const res = r.ok ? r.value : { ...(workerStart || {}), started: !!(workerStart && workerStart.started), alive: false, reason: String(r.error && r.error.message) };
1175
- result.results.worker.push({ id: 'worker-process', pid: res.pid || null, started: !!res.started, comfy_ready: !!(workerReady && workerReady.comfy_ready), reason: r.ok ? null : res.reason, log_file: res.logFile || null });
1225
+ result.results.worker.push({
1226
+ id: 'worker-process', pid: res.pid || null, started: !!res.started, comfy_ready: !!(workerReady && workerReady.comfy_ready), reason: r.ok ? null : res.reason, log_file: res.logFile || null,
1227
+ action: workerStart ? workerStart.action || null : null,
1228
+ restart_reasons: workerStart ? workerStart.restart_reasons || [] : [],
1229
+ restart_pending: workerStart && workerStart.restart_pending ? workerStart.restart_pending : null,
1230
+ deferred: !!(workerStart && workerStart.deferred),
1231
+ });
1176
1232
  if (r.ok) {
1177
1233
  startedWorkerPid = res.pid;
1178
1234
  state.setArtifact(st, 'worker-process', 'installed', { pid: res.pid });
@@ -1193,6 +1249,12 @@ async function runInstallation(args) {
1193
1249
  }
1194
1250
  }
1195
1251
 
1252
+ // "current job: none|<id>" of the doctor result (installer 0.2.8) —
1253
+ // read at the end of the step, from the running worker's own log.
1254
+ if (workerDir && !dryRun) {
1255
+ try { result.results.current_job = worker.currentJobLabel(io, { workerDir }); } catch (_) { result.results.current_job = 'unknown'; }
1256
+ }
1257
+
1196
1258
  // 4.9 Verification --------------------------------------------------------------
1197
1259
  // A fatal runtime failure means ComfyUI cannot start — skip the live
1198
1260
  // start step entirely (it would only spawn a doomed process).
@@ -1253,6 +1315,64 @@ async function runInstallation(args) {
1253
1315
  }
1254
1316
  }
1255
1317
 
1318
+ /**
1319
+ * Installer 0.2.5: bring an INSTALLED worker bundle to the version this
1320
+ * installer ships (its bundled copy, else the hub's published bundle) —
1321
+ * called by the CLI BEFORE any check that can end the run early (live E2E
1322
+ * 02.11: installer 0.2.4 stopped at the node-deps gate and left bundle 2.2.0
1323
+ * behind). A missing installation is left to the regular install step.
1324
+ * @returns {Promise<{ status: 'absent'|'current'|'unknown'|'updated'|'failed', have: string|null, want: string|null, files_installed?: string[], reason?: string }>}
1325
+ */
1326
+ /**
1327
+ * installer 0.2.10: the file list of the bundle version on disk, as recorded in
1328
+ * install-state (worker.bundle_files). Installs by 0.2.9 and older recorded only
1329
+ * files_installed (manifest files they copied) — that list is the fallback.
1330
+ * null when the state does not describe THIS worker dir.
1331
+ */
1332
+ function previousBundleFilesOf(w, workerDir) {
1333
+ if (!w || !w.dir || !workerDir || path.resolve(w.dir) !== path.resolve(workerDir)) return null;
1334
+ if (Array.isArray(w.bundle_files)) return w.bundle_files.slice();
1335
+ if (Array.isArray(w.files_installed)) return w.files_installed.filter((f) => f !== worker.NODE_CLASSES_FILE);
1336
+ return null;
1337
+ }
1338
+
1339
+ async function refreshInstalledWorkerBundle(io, { workerDir, manifest, repoRoot = null, hubUrl = null, log = null, nodeBin = null, previousBundleFiles = null }) {
1340
+ if (!workerDir || !manifest || !io.fs.existsSync(path.join(workerDir, 'worker.cjs'))) return { status: 'absent', have: null, want: null };
1341
+ const srcDir = repoBundleSource.resolveRepoBundleDir(io.fs, repoRoot);
1342
+ const have = worker.readPkgVersion(io, workerDir);
1343
+ let want = srcDir ? worker.readPkgVersion(io, srcDir) : null;
1344
+ if (!want && hubUrl && io.http && io.http.fetchJson) {
1345
+ try {
1346
+ const meta = await io.http.fetchJson(`${hubUrl.replace(/\/$/, '')}/worker-bundle/sha256`);
1347
+ if (meta && meta.status === 200 && meta.json && typeof meta.json.version === 'string') want = meta.json.version;
1348
+ } catch (_) { /* hub unreachable */ }
1349
+ }
1350
+ if (!have || !want) return { status: 'unknown', have, want };
1351
+ if (have === want) return { status: 'current', have, want };
1352
+ const wbFiles = ((manifest.worker_bundle || {}).files) || [];
1353
+ const missingFromRepo = wbFiles.filter((f) => !(srcDir && io.fs.existsSync(path.join(srcDir, f))));
1354
+ let bundleDir = null;
1355
+ let bundleTmp = null;
1356
+ try {
1357
+ if (missingFromRepo.length > 0 && hubUrl) {
1358
+ const fetched = await worker.fetchHubWorkerBundle(io, { hubUrl });
1359
+ if (fetched.bundleDir) { bundleDir = fetched.bundleDir; bundleTmp = fetched.tmpDir; }
1360
+ else return { status: 'failed', have, want, reason: `worker bundle fetch failed: ${fetched.reason}` };
1361
+ }
1362
+ const r = worker.installWorkerBundle(io, { workerDir, manifest, repoRoot, bundleDir, hubUrl, httpFetchText: null, log, update: true, nodeBin, previousBundleFiles });
1363
+ if (r.status !== 'installed') return { status: 'failed', have, want, reason: r.reason || r.status };
1364
+ const now = worker.readPkgVersion(io, workerDir);
1365
+ if (now !== want) return { status: 'failed', have, want, reason: `bundle is ${now} after the update, expected ${want}` };
1366
+ return { status: 'updated', have, want, files_installed: r.files_installed || [], bundle_files: r.bundle_files || [], files_removed: r.files_removed || [] };
1367
+ } catch (err) {
1368
+ return { status: 'failed', have, want, reason: err.message };
1369
+ } finally {
1370
+ if (bundleTmp) {
1371
+ try { io.fs.rmSync(bundleTmp, { recursive: true, force: true }); } catch (_) { /* best effort */ }
1372
+ }
1373
+ }
1374
+ }
1375
+
1256
1376
  function pickUpdateTarget(manifest) {
1257
1377
  const spec = (manifest.runtime_requirements || {}).comfyui || {};
1258
1378
  if (spec.pin && (spec.pin.commit || spec.pin.tag)) return spec.pin;
@@ -1342,25 +1462,41 @@ async function endToEndChecks(io, { mode, comfyUrl, comfyPort, hubUrl, workerWan
1342
1462
  return checks;
1343
1463
  }
1344
1464
  const newKeyFix = `create a new Worker Key in Animastor → Settings → Workers, then run: ${tool} doctor --new-key`;
1465
+ if (workerStart && workerStart.deferred) {
1466
+ // Installer 0.2.8: the worker keeps running (and serving) on its old
1467
+ // configuration; the needed restart was not done — FAILED, exit ≠ 0.
1468
+ checks.push({
1469
+ id: 'worker', ok: false, label: 'Worker restart',
1470
+ detail: String(workerStart.reason || 'restart deferred').replace(/\s+/g, ' '),
1471
+ fix: workerStart.busy_job
1472
+ ? `re-run \`${tool} doctor\` when the task finishes (or \`${tool} doctor --wait-job-ms <ms>\` to wait longer); \`${tool} doctor --force\` restarts now and loses the task's result`
1473
+ : `${tool} doctor --force (restarts the worker even if it is busy)`,
1474
+ });
1475
+ checks.push({ id: 'heartbeat', ok: null, label: 'Hub heartbeat (Online)', detail: `not re-checked — the worker (pid ${workerStart.pid}) keeps running on its previous configuration`, fix: null });
1476
+ return checks;
1477
+ }
1345
1478
  const r = workerReady || {};
1479
+ // A running worker left as is (installer 0.2.8) is not restarted by
1480
+ // another doctor run — the fix that restarts it is reboot-worker.
1481
+ const rerun = workerStart && workerStart.action === 'left' ? `${tool} reboot-worker` : `${tool} doctor`;
1346
1482
  if (r.comfy_ready) {
1347
1483
  checks.push({ id: 'worker', ok: true, label: 'Worker → ComfyUI', detail: '"ComfyUI ready" in the worker log', fix: null });
1348
1484
  } else {
1349
1485
  const reason = (r.reason || (workerStart && workerStart.reason) || 'worker did not start').replace(/\s+/g, ' ');
1350
1486
  checks.push({
1351
1487
  id: 'worker', ok: false, label: 'Worker → ComfyUI', detail: reason,
1352
- fix: r.auth_failed ? newKeyFix : `${tool} doctor`,
1488
+ fix: r.auth_failed ? newKeyFix : rerun,
1353
1489
  });
1354
1490
  }
1355
1491
  if (r.heartbeat) {
1356
1492
  checks.push({ id: 'heartbeat', ok: true, label: 'Hub heartbeat (Online)', detail: hubUrl || null, fix: null });
1357
1493
  } else if (!r.comfy_ready) {
1358
- checks.push({ id: 'heartbeat', ok: false, label: 'Hub heartbeat (Online)', detail: 'not reached — the worker sends heartbeats only after it reached ComfyUI', fix: r.auth_failed ? newKeyFix : `${tool} doctor` });
1494
+ checks.push({ id: 'heartbeat', ok: false, label: 'Hub heartbeat (Online)', detail: 'not reached — the worker sends heartbeats only after it reached ComfyUI', fix: r.auth_failed ? newKeyFix : rerun });
1359
1495
  } else {
1360
1496
  checks.push({
1361
1497
  id: 'heartbeat', ok: false, label: 'Hub heartbeat (Online)',
1362
1498
  detail: (r.reason || 'no heartbeat confirmed').replace(/\s+/g, ' '),
1363
- fix: r.auth_failed ? newKeyFix : `check that this machine reaches ${hubUrl} (curl -fsS ${hubUrl}/health), then run: ${tool} doctor`,
1499
+ fix: r.auth_failed ? newKeyFix : `check that this machine reaches ${hubUrl} (curl -fsS ${hubUrl}/health), then run: ${rerun}`,
1364
1500
  });
1365
1501
  }
1366
1502
  return checks;
@@ -1426,7 +1562,35 @@ async function runVerification({ io, manifests, roots, options, log, crypto, tok
1426
1562
  }
1427
1563
  if (missingClasses.length === 0) log.info('node classes registered');
1428
1564
  }
1429
- if (missingClasses.length > 0) live.comfyui.missing_node_classes = missingClasses;
1565
+ if (missingClasses.length > 0) {
1566
+ live.comfyui.missing_node_classes = missingClasses;
1567
+ // Installer 0.2.5: say WHY (missing packages / IMPORT FAILED /
1568
+ // restart needed) — "run doctor" alone looped on the live node.
1569
+ try {
1570
+ const ownerInfo = options.comfyOwner || null;
1571
+ const pid = ownerInfo && ownerInfo.pid ? ownerInfo.pid : null;
1572
+ const py = pid ? nodeDeps.pythonOfProcess(io, pid).python : null;
1573
+ let extraPaths = [];
1574
+ if (py && workerDir && ownerInfo && ownerInfo.owner === 'foreign') {
1575
+ const plan = pydeps.planPersistence(io, { python: py, root: comfyuiRoot, base: pydeps.overlayBase(workerDir), create: false });
1576
+ if (plan.kind === 'overlay' && plan.sitePackages && io.fs.existsSync(plan.sitePackages)) extraPaths = [plan.sitePackages];
1577
+ }
1578
+ const logFiles = [
1579
+ workerDir ? path.join(path.dirname(path.resolve(workerDir)), 'logs', 'comfyui-restart.log') : null,
1580
+ comfyuiRoot ? path.join(comfyuiRoot, 'comfyui-installer.log') : null,
1581
+ ].filter(Boolean);
1582
+ const diag = await nodeDeps.diagnoseMissingClasses(io, {
1583
+ missingClasses, manifests, root: comfyuiRoot, url: baseUrl, pid, python: py, extraPaths, logFiles,
1584
+ });
1585
+ live.comfyui.missing_node_classes_cause = {
1586
+ kind: diag.kind, detail: diag.detail, log_source: diag.log_source,
1587
+ owner: ownerInfo && ownerInfo.owner === 'foreign' ? 'foreign' : 'managed',
1588
+ };
1589
+ log.info(`node classes missing — cause: ${diag.kind}: ${diag.detail}`);
1590
+ } catch (err) {
1591
+ log.warn(`node classes missing — cause not determined: ${err.message}`);
1592
+ }
1593
+ }
1430
1594
  }
1431
1595
  // workflow static validation (no generation) — only meaningful when
1432
1596
  // at least one OPTIONAL profile workflow copy is actually installed;
@@ -1568,6 +1732,9 @@ module.exports = {
1568
1732
  comfyPortState,
1569
1733
  autoPickComfyPort,
1570
1734
  platformComfyMissingChecks,
1735
+ refreshInstalledWorkerBundle,
1736
+ previousBundleFilesOf,
1737
+ writeNodeClasses: worker.writeNodeClasses,
1571
1738
  desiredEnvWiring,
1572
1739
  endToEndChecks,
1573
1740
  CPU_MODE_WARNING,