@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.
@@ -13,7 +13,7 @@
13
13
  * animastor-installer verify [--profile P[,P2]] [--root PATH] [--worker-dir PATH] [--hub-url URL]
14
14
  * animastor-installer resume
15
15
  * animastor-installer uninstall [--all] [--yes] [--dry-run] [--state PATH] [--home PATH]
16
- * animastor-installer start | stop | status | logs [-f] [--lines N] | doctor [--new-key]
16
+ * animastor-installer start | stop | status | logs [-f] [--lines N] | doctor [--new-key] [--wait-job-ms N] [--force]
17
17
  * animastor-installer boot (node startup script: detaches `doctor --yes`, exits 0 at once)
18
18
  * (what the `animastor` command in PATH runs)
19
19
  *
@@ -29,6 +29,11 @@
29
29
  * --yes Auto-confirm all prompts
30
30
  * --dry-run Show plan only; never perform real changes
31
31
  * --all uninstall: full uninstall (everything recorded in the manifest)
32
+ * --wait-job-ms N install/doctor: when the worker must be restarted (its .env or bundle
33
+ * changed) but is busy with a task, wait up to N ms for the task to
34
+ * finish (default 600000); still busy → FAILED, exit 1
35
+ * --force install/doctor: restart the worker for a changed configuration even
36
+ * when it is busy (the task's result is lost)
32
37
  */
33
38
 
34
39
  const fs = require('fs');
@@ -55,6 +60,8 @@ const workerMod = require('./engine/worker');
55
60
  const comfyuiMod = require('./engine/comfyui');
56
61
  const comfyOwner = require('./engine/comfy-owner');
57
62
  const nodeDeps = require('./engine/node-deps');
63
+ const pydepsMod = require('./engine/pydeps');
64
+ const overridesMod = require('./engine/overrides');
58
65
  const downloader = require('./engine/downloader');
59
66
  const { resolveRepoBundleDir } = require('./worker-bundle-source');
60
67
  const engineMod = require('./engine/engine');
@@ -106,31 +113,74 @@ const DEFAULT_HUB_URL = 'https://animastor.org/gpu';
106
113
  // Argument parsing
107
114
  // ---------------------------------------------------------------------------
108
115
 
109
- const BOOLEAN_FLAGS = ['yes', 'dry-run', 'resume', 'start-comfy', 'start-worker', 'no-start-comfy', 'no-start-worker', 'all', 'accept-reference-runtime', 'accept-runtime-change', 'install-tools', 'no-tools', 'new-key', 'follow', 'no-fix', 'restart-platform-comfy', 'no-restart-platform-comfy'];
116
+ const BOOLEAN_FLAGS = ['yes', 'dry-run', 'resume', 'start-comfy', 'start-worker', 'no-start-comfy', 'no-start-worker', 'all', 'accept-reference-runtime', 'accept-runtime-change', 'install-tools', 'no-tools', 'new-key', 'follow', 'no-fix', 'restart-platform-comfy', 'no-restart-platform-comfy', 'accept-node-deps-overrides', 'force', 'help'];
117
+
118
+ /**
119
+ * Every option that takes a value. Installer 0.2.5: an option that is in
120
+ * neither list is an ERROR (exit 2) — installer 0.2.3 silently swallowed
121
+ * `doctor --restart-platform-comfy` (a flag it did not know) and ran a plain
122
+ * doctor, which printed the same fix again (live E2E 02.11).
123
+ */
124
+ const VALUE_FLAGS = ['profile', 'mode', 'root', 'worker-dir', 'hub-url', 'repo-root', 'state', 'tools-dir',
125
+ 'comfy-port', 'comfy-wait-ms', 'verify-timeout-ms', 'port', 'lines', 'history-max', 'home', 'boot-log', 'wait-job-ms'];
126
+
127
+ /** Commands main() dispatches. */
128
+ const COMMANDS = ['detect', 'plan', 'install', 'verify', 'validate', 'resume', 'uninstall', 'start', 'stop', 'status',
129
+ 'logs', 'doctor', 'boot', 'monitor', 'reboot-worker', 'reboot-comfyui'];
130
+
131
+ /** Exit code of a command line the CLI does not understand. */
132
+ const USAGE_EXIT = 2;
110
133
 
111
134
  function parseArgs(argv) {
112
135
  const args = argv.slice(2);
113
- const parsed = { command: null, profiles: [], flags: {} };
136
+ const parsed = { command: null, profiles: [], flags: {}, errors: [] };
114
137
  const positional = [];
115
138
  for (let i = 0; i < args.length; i++) {
116
139
  const a = args[i];
117
140
  if (a.startsWith('--')) {
118
- const key = a.slice(2);
141
+ let key = a.slice(2);
142
+ let inline = null;
143
+ const eq = key.indexOf('=');
144
+ if (eq > 0) { inline = key.slice(eq + 1); key = key.slice(0, eq); }
119
145
  if (BOOLEAN_FLAGS.includes(key)) {
146
+ if (inline !== null) parsed.errors.push(`option --${key} takes no value (got --${key}=${inline})`);
120
147
  parsed.flags[key] = true;
148
+ } else if (VALUE_FLAGS.includes(key)) {
149
+ let val = inline;
150
+ if (val === null) {
151
+ const next = args[i + 1];
152
+ if (next === undefined || (next.startsWith('--') && next.length > 2)) {
153
+ parsed.errors.push(`option --${key} needs a value`);
154
+ val = '';
155
+ } else {
156
+ val = next;
157
+ i += 1;
158
+ }
159
+ }
160
+ parsed.flags[key] = val;
121
161
  } else {
122
- const val = args[++i];
123
- parsed.flags[key] = val || '';
162
+ parsed.errors.push(`unknown option --${key}`);
124
163
  }
125
164
  } else if (a === '-f') {
126
165
  parsed.flags.follow = true;
127
166
  } else if (a === '-y') {
128
167
  parsed.flags.yes = true;
168
+ } else if (a === '-h') {
169
+ parsed.flags.help = true;
170
+ } else if (a.startsWith('-') && a.length > 1) {
171
+ parsed.errors.push(`unknown option ${a}`);
129
172
  } else {
130
173
  positional.push(a);
131
174
  }
132
175
  }
176
+ const wj = parsed.flags['wait-job-ms'];
177
+ if (wj !== undefined && wj !== '' && !(/^\d+$/.test(String(wj)))) {
178
+ parsed.errors.push(`option --wait-job-ms needs a number of milliseconds >= 0 (got ${wj})`);
179
+ }
133
180
  parsed.command = positional[0] || null;
181
+ if (positional.length > 1) parsed.errors.push(`unexpected argument(s): ${positional.slice(1).join(' ')}`);
182
+ // An unknown COMMAND keeps its old behaviour: usage + exit 1 (main()).
183
+ parsed.unknownCommand = parsed.command !== null && !COMMANDS.includes(parsed.command);
134
184
  const profileFlag = parsed.flags.profile || '';
135
185
  if (profileFlag) {
136
186
  parsed.profiles = profileFlag.split(',').map((s) => s.trim()).filter(Boolean);
@@ -475,7 +525,10 @@ function platformComfyMissingResult({ waited, tool, mode }) {
475
525
  * explicit flag wins, then the recorded answer (install-state
476
526
  * installer_options.restartPlatformComfy), then the boot default: yes on
477
527
  * type A — the node is unattended and nothing else brings the node classes
478
- * back. An interactive run without a record asks (askRestartPlatformComfy).
528
+ * back. An interactive run without a record asks (default Yes) and records
529
+ * the answer. A plain `--yes` is NOT consent to stop a process the installer
530
+ * does not own (installer 0.2.5 ADR): it needs the flag, a recorded yes, or
531
+ * the boot run.
479
532
  * @returns {{ allowed: boolean|null, source: 'flag'|'state'|'boot'|'unset' }}
480
533
  */
481
534
  function restartPlatformComfyDecision(flags, state, { boot = false } = {}) {
@@ -487,106 +540,324 @@ function restartPlatformComfyDecision(flags, state, { boot = false } = {}) {
487
540
  return { allowed: null, source: 'unset' };
488
541
  }
489
542
 
490
- const RESTART_PLATFORM_QUESTION = 'After a node restart the pip packages of custom nodes can disappear. May `animastor boot` reinstall them and restart the platform\'s ComfyUI so the nodes load?';
543
+ const RESTART_PLATFORM_QUESTION = 'When the custom-node dependencies have to be (re)installed, may animastor (also `animastor boot`) restart the platform\'s ComfyUI with the same command line so the nodes load?';
491
544
 
492
545
  /**
493
- * The custom-node dependency gate (installer 0.2.4) for a ComfyUI that the
494
- * PLATFORM runs (type A): check the pip requirements of every required
495
- * profile node in the Python of the running main.py; install the missing
496
- * ones (boot / --yes: no question; interactive: one question, which also
497
- * records the restart option); then — only when restarting the platform's
498
- * ComfyUI is allowed — stop exactly that pid and wait until the platform
499
- * started a new one with the node classes. Never starts a ComfyUI itself.
500
- * @returns {Promise<{ instance, checked: boolean, installed: string[], restarted: boolean, pid_changed: boolean, failed: boolean, reason: string|null, record: object }>}
546
+ * The custom-node dependency gate for a ComfyUI that the PLATFORM runs
547
+ * (type A; installer 0.2.4, persistence + restart reworked in 0.2.5):
548
+ *
549
+ * 1. the pip requirements of every required profile node are checked in
550
+ * the Python of the running main.py — with the persistent overlay
551
+ * (~/animastor/pydeps, engine/pydeps.js) in front of sys.path, exactly
552
+ * as ComfyUI sees it after the generated prestartup script;
553
+ * 2. missing ones are installed (boot / --yes / --restart-platform-comfy:
554
+ * no question; interactive: one question that also records the restart
555
+ * option) INTO THE OVERLAY — it lives in /home and survives a node
556
+ * restart; only when the overlay is impossible (old ComfyUI without
557
+ * prestartup scripts, no venv module) into the platform Python as in
558
+ * 0.2.4 (lost with a restart — boot reinstalls them);
559
+ * 3. the running ComfyUI loads new packages only on a restart: when the
560
+ * node classes are not in its /object_info and restarting the
561
+ * platform's ComfyUI is allowed, it is restarted with the same command
562
+ * line, cwd and environment (node-deps restartForeignComfyUI).
563
+ * @returns {Promise<{ instance, checked: boolean, installed: string[], restarted: boolean, pid_changed: boolean, failed: boolean, reason: string|null, fix?: string, record: object, persistence: object|null, prestartup: object|null }>}
564
+ */
565
+ /**
566
+ * Compare the overlay with the platform Python and log every replacement
567
+ * (installer 0.2.6): "[i] <pkg> platform X → overlay Y (needed by <node>)",
568
+ * a major change as a warning. Null when the comparison itself failed.
569
+ * @returns {{ overrides: object[], conflicts: object[] }|null}
501
570
  */
571
+ function overridesStep(io, { python, sitePackages, root, manifests = [], otherManifests = [], info, warn }) {
572
+ const all = [...(manifests || []), ...(otherManifests || [])];
573
+ const nodes = overridesMod.nodesOfProfiles(io, { root, manifests: all });
574
+ const raw = overridesMod.inspectOverlay(io, { python, sitePackages, root, nodes });
575
+ if (!raw.ok) {
576
+ warn(`overlay version comparison failed: ${raw.error}`);
577
+ return null;
578
+ }
579
+ const res = overridesMod.analyzeOverrides(raw, nodes, { profileCount: overridesMod.profileIds(all).length });
580
+ for (const o of res.overrides) {
581
+ const line = `node-deps overlay replaces a platform package: ${overridesMod.describeOverride(o)}`;
582
+ if (o.major) warn(`${line}${overridesMod.majorNote(o)}`);
583
+ else info(line);
584
+ }
585
+ return res;
586
+ }
587
+
588
+ /** Manifests of the profiles recorded on this ComfyUI that this run does not install (unknown ids are skipped). */
589
+ function otherProfileManifests(priorState, profiles, { load = manifest.loadManifest, logger = null } = {}) {
590
+ const ids = new Set();
591
+ for (const p of (priorState && Array.isArray(priorState.profiles) ? priorState.profiles : [])) ids.add(p);
592
+ const nd = priorState && priorState.installer_options && priorState.installer_options.nodeDeps;
593
+ for (const o of (nd && Array.isArray(nd.overrides) ? nd.overrides : [])) for (const p of o.profiles || []) ids.add(p);
594
+ const out = [];
595
+ for (const id of ids) {
596
+ if ((profiles || []).includes(id)) continue;
597
+ try { out.push(load(id)); } catch (err) {
598
+ if (logger) logger.warn(`profile ${id} recorded on this ComfyUI is unknown to this installer — not checked for version replacements (${err.message})`);
599
+ }
600
+ }
601
+ return out;
602
+ }
603
+
502
604
  async function platformNodeDepsGate(io, {
503
605
  instance, state = null, root, manifests, flags = {}, boot = false, yes = false, prompt = null,
504
606
  waitMs = 600000, logger = null, statePath = null, sleep = null, intervalMs = 3000, progressMs = 30000,
607
+ workerDir = null, platformGraceMs = 30000, otherManifests = [], command = 'doctor',
505
608
  } = {}) {
506
- const out = { instance, checked: false, installed: [], restarted: false, pid_changed: false, failed: false, reason: null, record: {} };
609
+ const out = {
610
+ instance, checked: false, installed: [], restarted: false, pid_changed: false, failed: false, reason: null, record: {},
611
+ persistence: null, prestartup: null, overrides: [], conflicts: [],
612
+ };
507
613
  if (!instance || instance.owner !== 'foreign' || !instance.pid) return out;
508
614
  const info = (line) => { if (logger) logger.info(line); };
509
615
  const warn = (line) => { if (logger) logger.warn(line); };
510
616
  const decision = restartPlatformComfyDecision(flags, state, { boot });
511
617
  let restartAllowed = decision.allowed;
512
618
  const interactive = !boot && !yes && !!(prompt && prompt.available);
619
+ const tool = toolCommandPath(flags);
513
620
 
514
621
  const py = nodeDeps.pythonOfProcess(io, instance.pid);
515
622
  if (!py.python) {
516
623
  warn(`custom-node dependencies not checked: the Python of the ComfyUI process (pid ${instance.pid}) is unknown (${py.source})`);
517
624
  return out;
518
625
  }
519
- const check = nodeDeps.checkNodeDeps(io, { python: py.python, root, manifests });
626
+ const base = workerDir ? pydepsMod.overlayBase(workerDir) : null;
627
+ let persist = pydepsMod.planPersistence(io, { python: py.python, root, base, create: false });
628
+ const overlayReady = () => persist.kind === 'overlay' && persist.paths && io.fs.existsSync(persist.paths.cfg);
629
+ const extraPaths = () => (overlayReady() ? [persist.sitePackages] : []);
630
+ const ensurePrestartup = () => {
631
+ if (!overlayReady()) return null;
632
+ const r = pydepsMod.ensurePrestartupNode(io, { root, base });
633
+ if (r.status === 'created' || r.status === 'updated') info(`prestartup node ${r.dir}: ${r.status} — ComfyUI adds ${persist.sitePackages} before it imports the custom nodes`);
634
+ else if (r.status === 'foreign' || r.status === 'failed') warn(`prestartup node not written: ${r.reason}`);
635
+ return r;
636
+ };
637
+ out.prestartup = ensurePrestartup();
638
+
639
+ const check = nodeDeps.checkNodeDeps(io, { python: py.python, root, manifests, extraPaths: extraPaths() });
520
640
  out.checked = true;
521
641
  for (const e of check.errors) warn(`custom-node dependency check: ${e}`);
642
+ let needRestart = !!(out.prestartup && (out.prestartup.status === 'created' || out.prestartup.status === 'updated'));
643
+ let snapshotOf = null;
644
+ const dropSnap = () => { if (snapshotOf) overridesMod.dropSnapshot(io, snapshotOf); snapshotOf = null; };
522
645
  if (check.nodes.length === 0) {
523
- info(`custom-node dependencies satisfied in ${py.python} (ComfyUI pid ${instance.pid})`);
646
+ info(`custom-node dependencies satisfied in ${py.python}${overlayReady() ? ` (+ overlay ${persist.sitePackages})` : ''} (ComfyUI pid ${instance.pid})`);
524
647
  if (interactive && restartAllowed === null) {
648
+ // Asked once and recorded: the unattended boot run must know it.
525
649
  restartAllowed = await prompt.confirm(RESTART_PLATFORM_QUESTION, { defaultYes: true });
526
650
  out.record.restartPlatformComfy = restartAllowed;
527
651
  }
528
- return out;
529
- }
530
- const what = nodeDeps.describeUnsatisfied(check.nodes);
531
- info(`custom-node dependencies missing in ${py.python} (ComfyUI pid ${instance.pid}): ${what}`);
532
- let install = boot || yes;
533
- if (interactive) {
534
- const restartPart = restartAllowed === false ? '' : ` and restart the platform's ComfyUI (pid ${instance.pid}) so it loads them`;
535
- install = await prompt.confirm(`Install the missing Python packages — ${what} — into ${py.python}${restartPart}?`, { defaultYes: true });
536
- if (restartAllowed === null) {
537
- restartAllowed = install;
538
- out.record.restartPlatformComfy = install;
652
+ } else {
653
+ const what = nodeDeps.describeUnsatisfied(check.nodes);
654
+ info(`custom-node dependencies missing in ${py.python} (ComfyUI pid ${instance.pid}): ${what}`);
655
+ let install = boot || yes || !!flags['restart-platform-comfy'];
656
+ if (interactive && !install) {
657
+ const restartPart = restartAllowed === false ? '' : ` and restart the platform's ComfyUI (pid ${instance.pid}) so it loads them`;
658
+ install = await prompt.confirm(`Install the missing Python packages — ${what} — for ${py.python}${restartPart}?`, { defaultYes: true });
659
+ if (restartAllowed === null) {
660
+ restartAllowed = install;
661
+ out.record.restartPlatformComfy = install;
662
+ }
663
+ }
664
+ if (!install) {
665
+ out.failed = true;
666
+ out.reason = `custom-node dependencies missing in the ComfyUI Python ${py.python}: ${what}`;
667
+ out.fix = `${tool} doctor --yes --restart-platform-comfy`;
668
+ return out;
669
+ }
670
+ if (persist.kind === 'overlay') {
671
+ persist = pydepsMod.planPersistence(io, { python: py.python, root, base, create: true });
672
+ if (persist.kind === 'overlay') {
673
+ const pr = ensurePrestartup();
674
+ if (pr && (pr.status === 'foreign' || pr.status === 'failed')) {
675
+ persist = { ...persist, kind: 'system', reason: pr.reason };
676
+ } else if (pr && !out.prestartup) out.prestartup = pr;
677
+ }
678
+ }
679
+ if (persist.kind !== 'overlay') {
680
+ warn(`node dependencies go into ${py.python} itself (${persist.reason}) — they are lost with a node restart; \`${tool} boot\` reinstalls them`);
681
+ }
682
+ // Another profile on this ComfyUI (installer 0.2.6): a replacement it
683
+ // refuses must be undone — the overlay venv is copied aside first.
684
+ if (persist.kind === 'overlay' && overridesMod.profileIds([...(manifests || []), ...(otherManifests || [])]).length > 1) {
685
+ const snap = overridesMod.snapshotOverlay(io, persist.paths.dir);
686
+ if (snap.ok) snapshotOf = persist.paths.dir;
687
+ else warn(`overlay snapshot not taken (${snap.reason}) — a refused version replacement cannot be undone`);
688
+ }
689
+ const constraintsPath = statePath ? path.join(path.dirname(statePath), 'node-deps-constraints.txt') : null;
690
+ const inst = nodeDeps.installNodeDeps(io, {
691
+ python: py.python, nodes: check.nodes, torch: check.torch, constraintsPath, log: logger,
692
+ pipPython: persist.kind === 'overlay' ? persist.paths.python : null,
693
+ });
694
+ out.installed = inst.installed;
695
+ if (!inst.ok) {
696
+ dropSnap();
697
+ out.failed = true;
698
+ out.reason = inst.failed.map((f) => `${f.directory}: ${f.reason}`).join('; ');
699
+ out.fix = `fix the pip error above (network, disk space, a package conflict), then run: ${tool} doctor --yes --restart-platform-comfy`;
700
+ return out;
701
+ }
702
+ const again = nodeDeps.checkNodeDeps(io, { python: py.python, root, manifests, extraPaths: extraPaths() });
703
+ if (again.nodes.length > 0) {
704
+ dropSnap();
705
+ out.failed = true;
706
+ out.reason = `pip finished, but the requirements are still not satisfied in ${py.python}: ${nodeDeps.describeUnsatisfied(again.nodes)}`;
707
+ out.fix = `install them by hand: ${persist.kind === 'overlay' ? persist.paths.python : py.python} -m pip install -r <requirements.txt>, then run: ${tool} doctor --restart-platform-comfy`;
708
+ return out;
709
+ }
710
+ info(`custom-node dependencies installed: ${inst.installed.join(', ')} → ${persist.kind === 'overlay' ? persist.sitePackages : py.python}`);
711
+ needRestart = true;
712
+ }
713
+ out.persistence = { kind: persist.kind, base: persist.base, site_packages: persist.sitePackages || null, reason: persist.reason || null, python: py.python };
714
+ const prevDeps = (state && state.installer_options && state.installer_options.nodeDeps) || {};
715
+ let accepted = Array.isArray(prevDeps.accepted) ? prevDeps.accepted.slice() : [];
716
+ out.record.nodeDeps = { target: persist.kind, overlay: persist.sitePackages || null, python: py.python, overrides: [], accepted };
717
+ // Version replacements by the overlay (installer 0.2.6): logged, shown in
718
+ // RESULT, recorded; a replacement that touches another profile or the
719
+ // ComfyUI core needs consent.
720
+ if (overlayReady()) {
721
+ const ov = overridesStep(io, {
722
+ python: py.python, sitePackages: persist.sitePackages, root, manifests, otherManifests, info, warn,
723
+ });
724
+ if (ov) {
725
+ out.overrides = ov.overrides;
726
+ out.conflicts = ov.conflicts;
727
+ out.record.nodeDeps.overrides = ov.overrides.map(overridesMod.recordOf);
728
+ const pending = overridesMod.pendingConflicts(ov.conflicts, accepted);
729
+ if (pending.length > 0) {
730
+ const lines = pending.map(overridesMod.describeConflict);
731
+ for (const l of lines) warn(`version replacement affects another profile: ${l}`);
732
+ let consent = !!flags['accept-node-deps-overrides'];
733
+ if (!consent && interactive) {
734
+ consent = await prompt.confirm(`The node-deps overlay is first in sys.path of the whole ComfyUI. It replaces packages that another profile or ComfyUI itself uses:\n - ${lines.join('\n - ')}\nKeep these replacements (the other profile may stop working)?`, { defaultYes: false });
735
+ }
736
+ if (consent) {
737
+ const at = new Date(typeof io.now === 'function' ? io.now() : Date.now()).toISOString();
738
+ accepted = [...accepted, ...pending.map((c) => overridesMod.acceptedEntry(c, at))];
739
+ out.record.nodeDeps.accepted = accepted;
740
+ info(`version replacements accepted (${flags['accept-node-deps-overrides'] ? '--accept-node-deps-overrides' : 'answer'}): ${pending.map(overridesMod.conflictKey).join(', ')}`);
741
+ dropSnap();
742
+ } else {
743
+ let undone = '';
744
+ if (snapshotOf) {
745
+ const rs = overridesMod.restoreOverlay(io, snapshotOf);
746
+ snapshotOf = null;
747
+ if (rs.ok) {
748
+ undone = '; the overlay was restored to its state before this run';
749
+ info(`overlay ${persist.paths.dir} restored from the snapshot — the replacements were not kept`);
750
+ const back = overridesStep(io, { python: py.python, sitePackages: persist.sitePackages, root, manifests, otherManifests, info: () => {}, warn: () => {} });
751
+ out.record.nodeDeps.overrides = back ? back.overrides.map(overridesMod.recordOf) : [];
752
+ out.overrides = back ? back.overrides : [];
753
+ } else {
754
+ undone = `; restoring the overlay failed: ${rs.reason}`;
755
+ warn(rs.reason);
756
+ }
757
+ }
758
+ out.failed = true;
759
+ const why = boot ? 'boot never consents' : (interactive ? 'not accepted' : 'no consent (--yes is not consent; use --accept-node-deps-overrides)');
760
+ out.reason = `the node-deps overlay would replace packages another profile on this ComfyUI uses (${why}): ${lines.join('; ')}${undone}. One GPU node — one profile`;
761
+ const profileArg = command === 'install' && Array.isArray(flags.profiles) && flags.profiles.length > 0 ? ` --profile ${flags.profiles.join(',')}` : '';
762
+ out.fix = `install this profile on a separate GPU node, or accept the replacements: ${tool} ${command === 'install' ? 'install' : 'doctor'}${profileArg} --accept-node-deps-overrides`;
763
+ return out;
764
+ }
765
+ }
539
766
  }
540
767
  }
541
- const tool = toolCommandPath(flags);
542
- if (!install) {
543
- out.failed = true;
544
- out.reason = `custom-node dependencies missing in the ComfyUI Python ${py.python}: ${what}`;
545
- out.fix = `${tool} doctor --yes`;
768
+ dropSnap();
769
+ // The running process imported the custom nodes at its start: the
770
+ // remedy for missing classes with the packages in place is a restart —
771
+ // decided by FACT (/object_info), not only by "installed just now":
772
+ // `doctor --restart-platform-comfy` must restart even when nothing was
773
+ // installed in this run (otherwise the printed fix loops).
774
+ const expectClasses = nodeDeps.profileNodeRequirements(io, { root, manifests }).flatMap((n) => n.classes);
775
+ if (expectClasses.length === 0) return out;
776
+ const have = instance.url ? await comfyuiMod.objectInfoClasses(io, instance.url) : null;
777
+ if (!have && !needRestart) return out; // not answering — the platform gate/verification reports it
778
+ const missingNow = have ? expectClasses.filter((c) => !have.has(c)) : expectClasses;
779
+ if (missingNow.length === 0) {
780
+ if (needRestart) info(`the running ComfyUI (pid ${instance.pid}) already has the node classes — no restart needed`);
546
781
  return out;
547
782
  }
548
- const constraintsPath = statePath ? path.join(path.dirname(statePath), 'node-deps-constraints.txt') : null;
549
- const inst = nodeDeps.installNodeDeps(io, { python: py.python, nodes: check.nodes, torch: check.torch, constraintsPath, log: logger });
550
- out.installed = inst.installed;
551
- if (!inst.ok) {
552
- out.failed = true;
553
- out.reason = inst.failed.map((f) => `${f.directory}: ${f.reason}`).join('; ');
554
- out.fix = `${tool} doctor`;
555
- return out;
783
+ if (!needRestart && decision.source !== 'flag') {
784
+ // A node that fails for another reason (syntax error, CUDA, …) is
785
+ // not fixed by restarting it on every boot: report the cause.
786
+ const diag = await nodeDeps.diagnoseMissingClasses(io, {
787
+ missingClasses: missingNow, manifests, root, url: instance.url, pid: instance.pid, python: py.python,
788
+ extraPaths: extraPaths(), logFiles: workerDir ? [path.join(path.dirname(path.resolve(workerDir)), 'logs', 'comfyui-restart.log')] : [],
789
+ });
790
+ if (diag.kind === 'import-failed') {
791
+ out.failed = true;
792
+ out.reason = `node classes missing: ${missingNow.join(', ')} — ${diag.detail}`;
793
+ out.fix = `fix the import error of the custom node (ComfyUI log: ${diag.log_source}), then run: ${tool} doctor --restart-platform-comfy`;
794
+ return out;
795
+ }
796
+ info(`node classes missing in the running ComfyUI (pid ${instance.pid}): ${missingNow.join(', ')} — ${diag.detail}`);
556
797
  }
557
- const again = nodeDeps.checkNodeDeps(io, { python: py.python, root, manifests });
558
- if (again.nodes.length > 0) {
559
- out.failed = true;
560
- out.reason = `pip finished, but the requirements are still not satisfied in ${py.python}: ${nodeDeps.describeUnsatisfied(again.nodes)}`;
561
- out.fix = `${tool} doctor`;
562
- return out;
798
+ if (restartAllowed === null && interactive) {
799
+ restartAllowed = await prompt.confirm(`The running ComfyUI (pid ${instance.pid}) loaded the custom nodes before their dependencies were in place. Restart it now (same command line, working directory and environment)?`, { defaultYes: true });
800
+ out.record.restartPlatformComfy = restartAllowed;
563
801
  }
564
- info(`custom-node dependencies installed: ${inst.installed.join(', ')}`);
565
802
  if (restartAllowed !== true) {
566
803
  // A ComfyUI that is not ours is never stopped without the option.
567
804
  out.failed = true;
568
- out.reason = `custom-node dependencies were installed, but the platform's ComfyUI (pid ${instance.pid}) imported the nodes before that and was not restarted (restart of the platform's ComfyUI is off)`;
805
+ out.reason = `custom-node dependencies are in place, but the platform's ComfyUI (pid ${instance.pid}) imported the nodes before that and was not restarted (restart of the platform's ComfyUI is off): ${missingNow.join(', ')} missing`;
569
806
  out.fix = `restart the ComfyUI from the platform console, or run: ${tool} doctor --restart-platform-comfy`;
570
807
  return out;
571
808
  }
572
- const expectClasses = check.nodes.flatMap((n) => n.classes);
573
- const rr = await nodeDeps.restartPlatformComfyUI(io, {
574
- pid: instance.pid, timeoutMs: waitMs, intervalMs, expectClasses, sleep, log: logger, onProgress: info, progressMs,
809
+ const restartLog = workerDir ? path.join(path.dirname(path.resolve(workerDir)), 'logs', 'comfyui-restart.log') : null;
810
+ const rr = await nodeDeps.restartForeignComfyUI(io, {
811
+ pid: instance.pid, timeoutMs: waitMs, intervalMs, expectClasses: missingNow, sleep, log: logger, onProgress: info, progressMs,
812
+ platformGraceMs, logFile: restartLog,
575
813
  });
576
814
  out.restarted = rr.stopped;
815
+ out.restart = { started_by: rr.started_by, log_file: rr.log_file };
577
816
  if (!rr.ok) {
578
817
  out.failed = true;
579
818
  out.reason = rr.reason;
580
- out.fix = `when the platform's ComfyUI is up again, run: ${tool} doctor`;
819
+ out.fix = rr.stopped
820
+ ? `${rr.log_file ? `see ${rr.log_file}; ` : ''}when ComfyUI answers again, run: ${tool} doctor`
821
+ : `restart the ComfyUI from the platform console, then run: ${tool} doctor`;
581
822
  if (rr.stopped) out.pid_changed = rr.pid != null;
823
+ if (rr.missing_classes && rr.missing_classes.length > 0 && rr.pid) {
824
+ const diag = await nodeDeps.diagnoseMissingClasses(io, {
825
+ missingClasses: rr.missing_classes, manifests, root, url: rr.url, pid: rr.pid, python: py.python,
826
+ extraPaths: extraPaths(), logFiles: [restartLog].filter(Boolean),
827
+ });
828
+ out.reason = `${rr.reason} — ${diag.detail}`;
829
+ if (diag.kind === 'import-failed') out.fix = `fix the import error of the custom node (log: ${diag.log_source}), then run: ${tool} doctor --restart-platform-comfy`;
830
+ }
582
831
  return out;
583
832
  }
584
- info(`the platform started ComfyUI again: pid ${rr.old_pid} → ${rr.pid} at ${rr.url} (after ${Math.round(rr.waited_ms / 1000)} s), node classes present`);
833
+ const who = rr.started_by === 'installer' ? 'the installer started ComfyUI again (same command line, cwd and environment)' : 'the platform started ComfyUI again';
834
+ info(`${who}: pid ${rr.old_pid} → ${rr.pid} at ${rr.url} (after ${Math.round(rr.waited_ms / 1000)} s), node classes present`);
585
835
  out.pid_changed = true;
586
836
  out.instance = await comfyOwner.resolveComfyOwner(io, { state, root });
587
837
  return out;
588
838
  }
589
839
 
840
+ /** Owned paths created by the dependency gate (overlay venv base, prestartup node). */
841
+ function nodeDepsOwnedServices(gate) {
842
+ const out = [];
843
+ if (!gate || !gate.persistence || gate.persistence.kind !== 'overlay') return out;
844
+ if (gate.persistence.base) out.push({ id: 'node-deps-overlay', path: gate.persistence.base });
845
+ if (gate.prestartup && gate.prestartup.dir && gate.prestartup.status !== 'foreign' && gate.prestartup.status !== 'failed') {
846
+ out.push({ id: 'node-deps-prestartup-node', path: gate.prestartup.dir });
847
+ }
848
+ return out;
849
+ }
850
+
851
+ /** Register owned service paths in an existing install-state.json (no-op without one). */
852
+ function recordOwnedServices(io, statePath, entries) {
853
+ if (!entries || entries.length === 0) return false;
854
+ const st = stateStore.loadState(io, statePath);
855
+ if (!st) return false;
856
+ for (const e of entries) stateStore.addOwnedComponent(st, 'services', e);
857
+ stateStore.saveState(io, statePath, st, io.now);
858
+ return true;
859
+ }
860
+
590
861
  /** FAILED result of the dependency gate (the engine — worker start — does not run). */
591
862
  function nodeDepsFailedResult({ gate, mode }) {
592
863
  return {
@@ -603,6 +874,46 @@ function nodeDepsFailedResult({ gate, mode }) {
603
874
  };
604
875
  }
605
876
 
877
+ /** installer 0.2.10: install-state worker.bundle_files (fallback files_installed) of THIS dir, or null. */
878
+ function previousBundleFilesFromState(io, statePath, workerDir) {
879
+ try {
880
+ const st = stateStore.loadState(io, statePath);
881
+ return engineMod.previousBundleFilesOf(st && st.components && st.components.worker, workerDir);
882
+ } catch (_) { return null; }
883
+ }
884
+
885
+ /** After a bundle update: record the new bundle file list and the copied files; drop removed ones. */
886
+ function recordWorkerBundle(io, statePath, workerDir, res) {
887
+ try {
888
+ const st = stateStore.loadState(io, statePath);
889
+ const w = st && st.components && st.components.worker;
890
+ if (!w || !w.dir || path.resolve(w.dir) !== path.resolve(workerDir)) return false;
891
+ const removed = new Set(res.files_removed || []);
892
+ w.files_installed = [...new Set([...(w.files_installed || []), ...(res.files_installed || [])])].filter((f) => !removed.has(f));
893
+ if (Array.isArray(res.bundle_files)) w.bundle_files = res.bundle_files.slice();
894
+ stateStore.saveState(io, statePath, st, io.now);
895
+ return true;
896
+ } catch (_) { return false; }
897
+ }
898
+
899
+ /**
900
+ * Register a file the installer wrote into the worker dir (uninstall removes
901
+ * it). Only for the recorded worker of THIS dir; no-op without a state.
902
+ */
903
+ function recordWorkerFile(io, statePath, workerDir, file) {
904
+ try {
905
+ const st = stateStore.loadState(io, statePath);
906
+ const w = st && st.components && st.components.worker;
907
+ if (!w || !w.dir || path.resolve(w.dir) !== path.resolve(workerDir)) return false;
908
+ const files = new Set(w.files_installed || []);
909
+ if (files.has(file)) return false;
910
+ files.add(file);
911
+ w.files_installed = Array.from(files);
912
+ stateStore.saveState(io, statePath, st, io.now);
913
+ return true;
914
+ } catch (_) { return false; }
915
+ }
916
+
606
917
  /** Store one installer option in install-state.json (a recorded answer). */
607
918
  function recordInstallerOption(io, statePath, key, value) {
608
919
  const st = stateStore.loadState(io, statePath);
@@ -680,6 +991,121 @@ function cmdBoot(flags, { io = createRealIo(), spawn = require('child_process').
680
991
  }
681
992
  }
682
993
 
994
+ /** This installer's version (package.json next to src/). */
995
+ function ownVersion() {
996
+ try { return require('../../package.json').version; } catch (_) { return null; }
997
+ }
998
+
999
+ /** Version of the persistent installer copy behind the `animastor` command (<base>/installer), or null. */
1000
+ function installedToolsVersion(io, flags) {
1001
+ const dir = path.join(path.dirname(resolveToolsDir(flags)), 'installer');
1002
+ try { return JSON.parse(String(io.fs.readFileSync(path.join(dir, 'package.json'), 'utf8'))).version || null; } catch (_) { return null; }
1003
+ }
1004
+
1005
+ /**
1006
+ * Installer 0.2.5 — FIRST change of every install/doctor run, before any
1007
+ * check that can end the run with ✗: the management tools (the `animastor`
1008
+ * command and the persistent installer copy it runs) and an installed worker
1009
+ * bundle are brought to THIS installer's version. Live E2E 02.11: 0.2.4
1010
+ * stopped at the node-deps gate before its "install management tools" step,
1011
+ * so ~/.local/bin/animastor stayed 0.2.3 (bundle 2.2.0) and the printed fix
1012
+ * `animastor doctor --restart-platform-comfy` ran a version that did not
1013
+ * know the flag. Every fix command printed afterwards names a command of
1014
+ * THIS version — or the result says why it could not be updated.
1015
+ * @returns {Promise<{ tools: object|null, tools_error: string|null, tools_skipped: string|null, bundle: object|null, version: string|null, tools_version: string|null }>}
1016
+ */
1017
+ async function preflightSelfUpdate(io, {
1018
+ flags, statePath, root, workerDir, hubUrl, repoRoot, manifests = [], logger = null, dryRun = false,
1019
+ nodeBin = null, home = homeDir(), linkDir = undefined, cliPath = __filename,
1020
+ installerSrcRoot = path.resolve(__dirname, '..', '..'),
1021
+ } = {}) {
1022
+ const out = { tools: null, tools_error: null, tools_skipped: null, bundle: null, version: ownVersion(), tools_version: null };
1023
+ if (dryRun) { out.tools_skipped = 'dry-run'; return out; }
1024
+ const toolsDirEarly = resolveToolsDir(flags);
1025
+ // Never write as the wrong user (sudo vs. normal user): the host gate
1026
+ // later stops such a run with the full explanation.
1027
+ const own = prereq.checkOwnership(io, {
1028
+ paths: [root, workerDir, statePath, toolsDirEarly].filter(Boolean), home: prereq.currentHome(), currentUid: prereq.currentUid(),
1029
+ });
1030
+ if (!own.ok) { out.tools_skipped = 'ownership mismatch'; return out; }
1031
+ const wantTools = await resolveToolsDecision({ flags, prompt: null, prior: priorToolsDecision(io, statePath) });
1032
+ const toolsDir = toolsDirEarly;
1033
+ if (!wantTools) {
1034
+ out.tools_skipped = 'management tools declined (--no-tools)';
1035
+ } else {
1036
+ try {
1037
+ out.tools = management.installManagementTools(io, {
1038
+ toolsDir,
1039
+ nodePath: nodeBin || process.execPath,
1040
+ cliPath,
1041
+ installerSrcRoot,
1042
+ installerDestRoot: path.join(path.dirname(toolsDir), 'installer'),
1043
+ linkDir: linkDir !== undefined ? linkDir : management.defaultLinkDir(),
1044
+ home,
1045
+ statePath,
1046
+ root,
1047
+ workerDir,
1048
+ hubUrl,
1049
+ log: logger,
1050
+ platformAdapter: PLATFORM_ADAPTER,
1051
+ });
1052
+ } catch (err) {
1053
+ out.tools_error = err.message;
1054
+ if (logger) logger.warn(`management tools could not be updated: ${err.message}`);
1055
+ }
1056
+ }
1057
+ out.tools_version = installedToolsVersion(io, flags);
1058
+ if (manifests.length > 0) {
1059
+ try {
1060
+ out.bundle = await engineMod.refreshInstalledWorkerBundle(io, {
1061
+ workerDir, manifest: manifests[0], repoRoot, hubUrl, log: logger, nodeBin,
1062
+ previousBundleFiles: previousBundleFilesFromState(io, statePath, workerDir),
1063
+ });
1064
+ if (out.bundle && out.bundle.status === 'updated') recordWorkerBundle(io, statePath, workerDir, out.bundle);
1065
+ } catch (err) {
1066
+ out.bundle = { status: 'failed', reason: err.message };
1067
+ }
1068
+ if (out.bundle && out.bundle.status === 'failed' && logger) logger.warn(`worker bundle ${out.bundle.have || '?'} could not be updated to ${out.bundle.want || '?'}: ${out.bundle.reason}`);
1069
+ // Installer 0.2.7: node-classes.json for the worker's readiness gate
1070
+ // — on install, bundle update, doctor and boot alike, so a node
1071
+ // installed by an older installer gets it on its next doctor/boot.
1072
+ try {
1073
+ out.node_classes = engineMod.writeNodeClasses(io, { workerDir, manifests, log: logger, version: ownVersion() });
1074
+ if (out.node_classes.status === 'written') recordWorkerFile(io, statePath, workerDir, 'node-classes.json');
1075
+ } catch (err) {
1076
+ out.node_classes = { status: 'failed', reason: err.message };
1077
+ }
1078
+ }
1079
+ return out;
1080
+ }
1081
+
1082
+ /**
1083
+ * Result lines for a preflight that could not bring the tools/bundle to
1084
+ * this version — the fix commands of the result would otherwise run an
1085
+ * older `animastor` (or the worker an older bundle) without saying so.
1086
+ */
1087
+ function preflightExtras(pre) {
1088
+ if (!pre) return [];
1089
+ const extra = [];
1090
+ if (!pre.tools_skipped && pre.version && pre.tools_version !== pre.version) {
1091
+ extra.push({
1092
+ ok: false,
1093
+ label: 'Management tools',
1094
+ detail: `the animastor command runs installer ${pre.tools_version || 'unknown'}, this installer is ${pre.version}${pre.tools_error ? ` — update failed: ${pre.tools_error}` : ''}; the fix commands of this result need ${pre.version}`,
1095
+ fix: 'run the install command from the Animastor setup page again',
1096
+ });
1097
+ }
1098
+ if (pre.bundle && pre.bundle.status === 'failed') {
1099
+ extra.push({
1100
+ ok: false,
1101
+ label: 'Worker bundle',
1102
+ detail: `installed ${pre.bundle.have || 'unknown'}, this installer ships ${pre.bundle.want || 'unknown'} — update failed: ${pre.bundle.reason}`,
1103
+ fix: 'run the install command from the Animastor setup page again',
1104
+ });
1105
+ }
1106
+ return extra;
1107
+ }
1108
+
683
1109
  /** The one line for the node startup script (printed at the end of an install). */
684
1110
  function startupScriptLine(flags) {
685
1111
  const tool = toolCommandPath(flags);
@@ -806,6 +1232,13 @@ async function cmdInstall(flags, { doctor = false } = {}) {
806
1232
  const pathEntry = management.restoreCommandPath(realIo, { linkDir: management.defaultLinkDir(), home: homeDir() });
807
1233
  if (!boot && pathEntry.updated.length > 0) console.log(`PATH block restored: ${pathEntry.updated.join(', ')}`);
808
1234
 
1235
+ // Tools + bundle of THIS version before anything can stop the run (0.2.5).
1236
+ const preflight = await preflightSelfUpdate(realIo, {
1237
+ flags, statePath, root, workerDir, hubUrl, repoRoot, manifests: loadedManifests, logger, dryRun,
1238
+ nodeBin: (probeMod.pickNodeBinary(realIo) || {}).bin || null,
1239
+ });
1240
+ const withPre = (res) => ({ ...res, preflight });
1241
+
809
1242
  // Host packages that disappeared with the image restart (boot path).
810
1243
  if (doctor) {
811
1244
  const missingPkgs = missingRequiredHostPackages(realIo);
@@ -834,7 +1267,7 @@ async function cmdInstall(flags, { doctor = false } = {}) {
834
1267
  instance = gate.instance;
835
1268
  if (gate.waited && gate.waited.ok) runningComfy = probeMod.detectRunningComfyUI(realIo);
836
1269
  if (gate.failed) {
837
- printResult(platformComfyMissingResult({ waited: gate.waited, tool: toolCommandPath(flags), mode: 'existing' }), { flags, mode: 'existing', boot });
1270
+ printResult(withPre(platformComfyMissingResult({ waited: gate.waited, tool: toolCommandPath(flags), mode: 'existing' })), { flags, mode: 'existing', boot });
838
1271
  process.exitCode = 1;
839
1272
  prompt.close();
840
1273
  return;
@@ -845,9 +1278,11 @@ async function cmdInstall(flags, { doctor = false } = {}) {
845
1278
  // of the platform's main.py, reinstall, and (when allowed) let the
846
1279
  // platform start its ComfyUI again so the node classes load.
847
1280
  const recordedPid = priorState && priorState.comfy_owner ? priorState.comfy_owner.pid : null;
1281
+ const ownedServices = [];
848
1282
  const depsGate = dryRun ? null : await platformNodeDepsGate(realIo, {
849
1283
  instance, state: priorState, root, manifests: loadedManifests, flags, boot, yes, prompt,
850
- waitMs: Math.max(60000, comfyWaitMs - (realIo.now() - windowStart)), logger, statePath,
1284
+ waitMs: Math.max(180000, comfyWaitMs - (realIo.now() - windowStart)), logger, statePath, workerDir,
1285
+ otherManifests: otherProfileManifests(priorState, flags.profiles, { logger }), command: doctor ? 'doctor' : 'install',
851
1286
  });
852
1287
  if (depsGate) {
853
1288
  instance = depsGate.instance;
@@ -855,8 +1290,11 @@ async function cmdInstall(flags, { doctor = false } = {}) {
855
1290
  if (depsGate.record.restartPlatformComfy !== undefined) {
856
1291
  recordInstallerOption(realIo, statePath, 'restartPlatformComfy', depsGate.record.restartPlatformComfy);
857
1292
  }
1293
+ if (depsGate.record.nodeDeps) recordInstallerOption(realIo, statePath, 'nodeDeps', depsGate.record.nodeDeps);
1294
+ ownedServices.push(...nodeDepsOwnedServices(depsGate));
1295
+ recordOwnedServices(realIo, statePath, ownedServices);
858
1296
  if (depsGate.failed) {
859
- printResult(nodeDepsFailedResult({ gate: depsGate, mode: instance.mode }), { flags, mode: instance.mode, boot });
1297
+ printResult(withPre({ ...nodeDepsFailedResult({ gate: depsGate, mode: instance.mode }), node_deps_overrides: depsGate.overrides }), { flags, mode: instance.mode, boot });
860
1298
  process.exitCode = 1;
861
1299
  prompt.close();
862
1300
  return;
@@ -971,7 +1409,7 @@ async function cmdInstall(flags, { doctor = false } = {}) {
971
1409
  }
972
1410
 
973
1411
  if (plan.blocked.length > 0) {
974
- printFinal({ blocked: plan.blocked, tool: toolCommand(flags), mode });
1412
+ printFinal({ blocked: plan.blocked, tool: toolCommand(flags), mode, preflight });
975
1413
  process.exitCode = 1;
976
1414
  return;
977
1415
  }
@@ -1116,7 +1554,7 @@ async function cmdInstall(flags, { doctor = false } = {}) {
1116
1554
  process.exit(1);
1117
1555
  }
1118
1556
  if (plan2.blocked.length > 0) {
1119
- printFinal({ blocked: plan2.blocked, tool: toolCommand(flags), mode });
1557
+ printFinal({ blocked: plan2.blocked, tool: toolCommand(flags), mode, preflight });
1120
1558
  process.exitCode = 1;
1121
1559
  return;
1122
1560
  }
@@ -1135,13 +1573,15 @@ async function cmdInstall(flags, { doctor = false } = {}) {
1135
1573
  comfyOwner: instance,
1136
1574
  comfyWaitMs,
1137
1575
  nodeClassesDeadline,
1576
+ ownedServices,
1577
+ bundleRefreshedEarly: !!(preflight.bundle && preflight.bundle.status === 'updated'),
1138
1578
  restartPlatformComfy: restartPlatformComfyDecision(flags, priorState, { boot }).source === 'flag'
1139
1579
  ? !!flags['restart-platform-comfy']
1140
1580
  : (depsGate && depsGate.record.restartPlatformComfy !== undefined ? depsGate.record.restartPlatformComfy : undefined),
1141
1581
  hubVersion,
1142
1582
  },
1143
1583
  });
1144
- printResult(result, { flags, mode, boot, hubVersion });
1584
+ printResult(withPre({ ...result, node_deps_overrides: depsGate ? depsGate.overrides : [] }), { flags, mode, boot, hubVersion });
1145
1585
  } catch (err) {
1146
1586
  if (err instanceof NoTerminalError) {
1147
1587
  console.error('');
@@ -1169,6 +1609,12 @@ function installOptions(flags, { doctor = false } = {}) {
1169
1609
  startWorker: flags['start-worker'] === true ? true
1170
1610
  : flags['no-start-worker'] === true ? false
1171
1611
  : (doctor ? true : undefined),
1612
+ // Installer 0.2.8: a running worker is restarted only for a changed
1613
+ // .env/bundle and never in the middle of a task (engine/worker
1614
+ // ensureWorker); the boot path only starts a stopped worker.
1615
+ waitJobMs: flags['wait-job-ms'] !== undefined && flags['wait-job-ms'] !== '' ? Number(flags['wait-job-ms']) : undefined,
1616
+ forceWorkerRestart: !!flags.force,
1617
+ boot: isBootRun(flags, doctor),
1172
1618
  };
1173
1619
  }
1174
1620
 
@@ -1396,7 +1842,9 @@ async function cmdVerify(flags) {
1396
1842
  */
1397
1843
  /** Blocked steps + host remediation as summary items (shared by both outputs). */
1398
1844
  function resultExtras(result, tool) {
1399
- const extra = [];
1845
+ const extra = preflightExtras(result.preflight);
1846
+ // Version replacements of the node-deps overlay (installer 0.2.6).
1847
+ extra.push(...overridesMod.resultItems(result.node_deps_overrides));
1400
1848
  for (const b of result.blocked || []) {
1401
1849
  let fix = result.remediation && result.remediation.command ? `${result.remediation.command} && ${tool} doctor` : `${tool} doctor`;
1402
1850
  if (/accept_runtime_change/.test(b.reason || '')) fix = `if ComfyUI already works, this can be ignored; to let the installer replace the runtime run: ${tool} doctor --accept-runtime-change`;
@@ -1430,7 +1878,8 @@ function printOneLineSummary(result, { flags = {}, mode = null } = {}) {
1430
1878
  const what = [
1431
1879
  `mode ${mode || result.mode}`,
1432
1880
  owner && owner.url ? `ComfyUI ${owner.url}` : 'ComfyUI not reachable',
1433
- worker && worker.started ? `worker pid ${worker.pid}` : 'worker not started',
1881
+ worker && worker.started ? `worker pid ${worker.pid}${worker.action === 'left' ? ' (left as is)' : ''}` : 'worker not started',
1882
+ `current job: ${currentJobOf(result, flags)}`,
1434
1883
  ].join(', ');
1435
1884
  const head = summary.ok ? 'OK' : `FAILED — ${summary.failures.length} problem(s)`;
1436
1885
  console.log(`animastor doctor: ${head} — ${what} (${tool})`);
@@ -1440,6 +1889,19 @@ function printOneLineSummary(result, { flags = {}, mode = null } = {}) {
1440
1889
  }
1441
1890
  }
1442
1891
 
1892
+ /** "none" | "<job_id>" | "unknown" — the worker's task at the end of the run (installer 0.2.8). */
1893
+ function currentJobOf(result, flags = {}) {
1894
+ const known = result && result.results && result.results.current_job;
1895
+ if (known) return known;
1896
+ // The engine did not run (e.g. the platform's ComfyUI never came up):
1897
+ // read the running worker's log directly.
1898
+ try {
1899
+ return workerMod.currentJobLabel(createRealIo(), { workerDir: resolveWorkerDir(flags), platformAdapter: PLATFORM_ADAPTER });
1900
+ } catch (_) {
1901
+ return 'unknown';
1902
+ }
1903
+ }
1904
+
1443
1905
  function printResult(result, { flags = {}, mode = null, boot = false } = {}) {
1444
1906
  if (boot) {
1445
1907
  printOneLineSummary(result, { flags, mode });
@@ -1453,6 +1915,7 @@ function printResult(result, { flags = {}, mode = null, boot = false } = {}) {
1453
1915
  const extra = resultExtras(result, tool);
1454
1916
  const summary = renderFinalSummary({ verification: result.verification, e2e: result.e2e || [], extra, tool, mode: mode || result.mode });
1455
1917
  console.log(summary.text);
1918
+ console.log(`current job: ${currentJobOf(result, flags)}`);
1456
1919
  // The full path is printed even when ~/.local/bin is already in PATH:
1457
1920
  // after a node reboot the PATH block is gone, and a copy-pasted relative
1458
1921
  // `animastor` must not be the only way to run the command.
@@ -1465,8 +1928,8 @@ function printResult(result, { flags = {}, mode = null, boot = false } = {}) {
1465
1928
  }
1466
1929
 
1467
1930
  /** Result block for a plan that is blocked before anything ran. */
1468
- function printFinal({ blocked = [], tool = 'animastor', mode = null }) {
1469
- const extra = blocked.map((b) => ({ ok: false, label: `Step "${b.step || b.id || 'plan'}"`, detail: b.reason, fix: `${tool} doctor` }));
1931
+ function printFinal({ blocked = [], tool = 'animastor', mode = null, preflight = null }) {
1932
+ const extra = [...preflightExtras(preflight), ...blocked.map((b) => ({ ok: false, label: `Step "${b.step || b.id || 'plan'}"`, detail: b.reason, fix: `${tool} doctor` }))];
1470
1933
  console.log(renderFinalSummary({ extra, tool, mode }).text);
1471
1934
  }
1472
1935
 
@@ -1725,7 +2188,11 @@ async function cmdStart(flags) {
1725
2188
  if (stats) {
1726
2189
  start = workerMod.startWorker(io, { workerDir: targets.workerDir });
1727
2190
  if (start.started && start.alive) {
1728
- if (start.already_running) screen.print(`worker already running (pid ${start.pid})`);
2191
+ if (start.already_running) {
2192
+ screen.print(start.busy_job
2193
+ ? `worker already running (pid ${start.pid}), busy with ${start.busy_job} — its .env changed, restart deferred until the task finishes (run \`${toolCommand(flags)} doctor\`)`
2194
+ : `worker already running (pid ${start.pid})`);
2195
+ }
1729
2196
  ready = await screen.withBusy('Waiting for the worker (ComfyUI ready → hub heartbeat)', () => workerMod.waitForWorkerReady(io, {
1730
2197
  workerDir: targets.workerDir, pid: start.pid, logFile: start.logFile, logOffset: start.logOffset || 0,
1731
2198
  }));
@@ -1792,6 +2259,14 @@ async function cmdDoctor(flags) {
1792
2259
  async function main() {
1793
2260
  const args = parseArgs(process.argv);
1794
2261
  const pkg = require('../../package.json');
2262
+ // A command line this version does not understand is never "best
2263
+ // effort": an ignored option silently changes what the run does.
2264
+ if (args.errors.length > 0) {
2265
+ for (const e of args.errors) console.error(`animastor-installer ${pkg.version}: ${e}`);
2266
+ console.error(`Run with --help for the list of commands and options (this is installer ${pkg.version}).`);
2267
+ process.exit(USAGE_EXIT);
2268
+ }
2269
+ if (args.flags.help) args.command = null;
1795
2270
  // install/doctor print the full banner; the everyday tool commands stay quiet.
1796
2271
  if (!['install', 'doctor', 'start', 'stop', 'logs', 'status', 'boot'].includes(args.command)) {
1797
2272
  console.log(`animastor-installer v${pkg.version} (platform: ${PLATFORM_RUNTIME.platform}, deployment: ${PLATFORM_RUNTIME.deployment})`);
@@ -1859,16 +2334,17 @@ async function main() {
1859
2334
  console.error(' a free port when 8188 is taken; opt out:');
1860
2335
  console.error(' --no-start-comfy --no-start-worker --comfy-port N');
1861
2336
  console.error(' management (the `animastor` command in PATH):');
1862
- console.error(' animastor start | stop | status | logs [-f] | doctor [--new-key] | boot');
2337
+ console.error(' animastor start | stop | status | logs [-f] | doctor [--new-key] [--wait-job-ms N] [--force] | boot');
1863
2338
  console.error(' boot: node startup script — detaches `doctor --yes` (log ~/animastor/logs/bootstrap.log), exits 0');
1864
2339
  console.error(' --restart-platform-comfy / --no-restart-platform-comfy restart the platform ComfyUI after node deps');
2340
+ console.error(' --accept-node-deps-overrides consent: the node-deps overlay may replace a package another profile / ComfyUI core uses');
1865
2341
  console.error(' (also: monitor | reboot-worker | reboot-comfyui)');
1866
2342
  console.error(' (--state/--root/--worker-dir/--port override discovery)');
1867
2343
  console.error(' installer flags: --install-tools / --no-tools / --tools-dir PATH');
1868
2344
  console.error(' uninstall flags:');
1869
2345
  console.error(' --all Full uninstall (remove everything recorded as installed by Animastor)');
1870
2346
  console.error(' --state PATH Install state file path');
1871
- process.exit(1);
2347
+ process.exit(args.flags.help ? 0 : 1);
1872
2348
  }
1873
2349
  }
1874
2350
 
@@ -1880,7 +2356,7 @@ if (require.main === module) {
1880
2356
  }
1881
2357
 
1882
2358
  module.exports = {
1883
- stepQuestion, parseArgs, cmdDetect, cmdPlan, cmdInstall, cmdStart, cmdStop, cmdLogs, cmdDoctor,
2359
+ stepQuestion, parseArgs, BOOLEAN_FLAGS, VALUE_FLAGS, COMMANDS, USAGE_EXIT, cmdDetect, cmdPlan, cmdInstall, cmdStart, cmdStop, cmdLogs, cmdDoctor,
1884
2360
  printResult, printOneLineSummary, resultExtras, cmdVerify, cmdValidateManifests, cmdResume,
1885
2361
  cmdUninstall, cmdStatus, cmdMonitor, cmdRebootWorker, cmdRebootComfyUI, resolveAndPlan,
1886
2362
  makeSecretProvider, resolveToolsDecision, resolveToolsDir, installOptions, runHostGates,
@@ -1889,4 +2365,6 @@ module.exports = {
1889
2365
  missingRequiredHostPackages, shouldWaitForPlatformComfy, platformComfyGate, platformComfyMissingResult,
1890
2366
  restartPlatformComfyDecision, platformNodeDepsGate, nodeDepsFailedResult, recordInstallerOption,
1891
2367
  cmdBoot, bootChildArgs, bootLogPath, startupScriptLine,
2368
+ preflightSelfUpdate, preflightExtras, installedToolsVersion, ownVersion,
2369
+ nodeDepsOwnedServices, recordOwnedServices, otherProfileManifests, overridesStep,
1892
2370
  };