@animastor/installer 0.2.13 → 0.2.14

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 CHANGED
@@ -14,7 +14,7 @@ published to npm as `@animastor/installer`.
14
14
 
15
15
  ```
16
16
  packages/animastor-installer/
17
- ├── package.json @animastor/installer 0.2.13, Node >=20, zero runtime deps
17
+ ├── package.json @animastor/installer 0.2.14, Node >=20, zero runtime deps
18
18
  ├── src/installer/
19
19
  │ ├── cli.js CLI entry (detect/plan/install/verify/resume/uninstall)
20
20
  │ ├── index.js Public API entry (10 exports, incl. setupContract)
@@ -213,6 +213,15 @@ recomputed on every run because the platform's port and notebook prefix change
213
213
  between boots. Answers already given (a declined optional workflow, a declined
214
214
  model download) are remembered and not asked again, also under `--yes`.
215
215
 
216
+ Model check and download log (0.2.14): besides the standard ComfyUI folders the
217
+ check scans the top folder (`models/<folder>`) of every `target_dir` in the
218
+ loaded manifests, plus `extra_model_paths.yaml` — a file the installer
219
+ downloads is always visible to the check. Present files up to 1 GiB that match
220
+ the manifest size are compared by sha256, larger ones by size. Every model file
221
+ is logged with name, size and outcome (`downloaded`, `present, verified sha256
222
+ — skipped`, `failed: <reason>`). `install`, `doctor` and `resume` append their
223
+ log to `~/animastor/logs/bootstrap.log`, not only `animastor boot`.
224
+
216
225
  ## Manifest resolution (MANIFEST_ROOT contract)
217
226
 
218
227
  1. `/app/artifacts/install-manifests` (baked container layout)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@animastor/installer",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Animastor Private GPU Worker installer — self-contained CLI and library for GPU worker setup, verification, and management.",
5
5
  "main": "src/installer/index.js",
6
6
  "exports": {
@@ -945,6 +945,30 @@ function bootLogPath(flags) {
945
945
  return flags['boot-log'] || path.join(path.dirname(resolveWorkerDir(flags)), 'logs', 'bootstrap.log');
946
946
  }
947
947
 
948
+ /**
949
+ * Copy the log of an install/doctor/resume run to bootstrap.log (0.2.14) —
950
+ * before, only `animastor boot` wrote there and an interactive install left no
951
+ * trace. Not when stdout already IS that file (the boot run). Called after the
952
+ * ownership gates, so nothing is created as the wrong user. Never fatal.
953
+ */
954
+ function teeToBootLog(logger, { io, flags, command, stdoutFd = 1 }) {
955
+ const logFile = bootLogPath(flags);
956
+ try {
957
+ const out = fs.fstatSync(stdoutFd);
958
+ const log = fs.statSync(logFile);
959
+ if (out.ino === log.ino && out.dev === log.dev) return false;
960
+ } catch (_) { /* no log file yet */ }
961
+ try {
962
+ io.fs.mkdirSync(path.dirname(logFile), { recursive: true });
963
+ io.fs.appendFileSync(logFile, `\n===== animastor ${command} ${new Date(io.now()).toISOString()} (installer ${ownVersion()}) =====\n`);
964
+ } catch (err) {
965
+ logger.warn(`${logFile} is not writable: ${err.message}`);
966
+ return false;
967
+ }
968
+ logger.teeTo((line) => { try { io.fs.appendFileSync(logFile, `${line}\n`); } catch (_) { /* the run goes on */ } });
969
+ return true;
970
+ }
971
+
948
972
  /** System boot time from /proc/stat (btime) as ISO, or null. */
949
973
  function systemBootTime(io) {
950
974
  try {
@@ -1162,9 +1186,8 @@ async function cmdPlan(flags) {
1162
1186
  const repoRoot = resolveRepoRoot(flags);
1163
1187
  const io = createRealIo();
1164
1188
  const crypto = require('crypto');
1165
- const env = probeEnvironment(io, { root, workerDir, crypto, workerType: null });
1166
-
1167
1189
  const loadedManifests = flags.profiles.map((p) => manifest.loadManifest(p));
1190
+ const env = await probeMod.hashProbedModels(io, probeEnvironment(io, { root, workerDir, crypto, workerType: null, manifests: loadedManifests }), loadedManifests);
1168
1191
  const mode = flags.mode || (env.comfyui && env.comfyui.present ? 'existing' : 'managed');
1169
1192
  const { plan } = resolveAndPlan({ manifests: loadedManifests, env, mode, decisions: {} });
1170
1193
  console.log(plan.plan_text);
@@ -1357,7 +1380,9 @@ async function cmdInstall(flags, { doctor = false } = {}) {
1357
1380
  const env = probeEnvironment(realIo, {
1358
1381
  root, workerDir, crypto,
1359
1382
  workerType: loadedManifests.length === 1 ? (loadedManifests[0].worker_bundle || {}).worker_type : null,
1383
+ manifests: loadedManifests,
1360
1384
  });
1385
+ await probeMod.hashProbedModels(realIo, env, loadedManifests);
1361
1386
 
1362
1387
  // The dry-run guard wraps everything handed to the engine so any
1363
1388
  // accidental mutation throws "dry-run violation" instead of executing.
@@ -1575,6 +1600,7 @@ async function cmdInstall(flags, { doctor = false } = {}) {
1575
1600
  return;
1576
1601
  }
1577
1602
 
1603
+ teeToBootLog(logger, { io: realIo, flags, command: doctor ? 'doctor' : 'install' });
1578
1604
  const result = await runInstallation({
1579
1605
  manifests: loadedManifests, mode, io,
1580
1606
  roots: { comfyuiRoot: root, workerDir, statePath, repoRoot, hubUrl, toolsDir: resolveToolsDir(flags) },
@@ -1703,6 +1729,7 @@ async function cmdResume(flags) {
1703
1729
  const env = probeEnvironment(io, {
1704
1730
  root, workerDir, crypto,
1705
1731
  workerType: loadedManifests.length === 1 ? (loadedManifests[0].worker_bundle || {}).worker_type : null,
1732
+ manifests: loadedManifests,
1706
1733
  });
1707
1734
 
1708
1735
  // restored non-secret decisions from state; CLI --yes can still widen them.
@@ -1717,6 +1744,7 @@ async function cmdResume(flags) {
1717
1744
  flags, prompt: null, prior: priorToolsDecision(io, statePath),
1718
1745
  });
1719
1746
 
1747
+ teeToBootLog(logger, { io, flags, command: 'resume' });
1720
1748
  const result = await runInstallation({
1721
1749
  manifests: loadedManifests, mode, io,
1722
1750
  roots: { comfyuiRoot: root, workerDir, statePath, repoRoot, hubUrl, toolsDir: resolveToolsDir(flags) },
@@ -1857,7 +1885,9 @@ async function cmdVerify(flags) {
1857
1885
  ? flags.profiles.map((p) => manifest.loadManifest(p))
1858
1886
  : [manifest.loadManifest('image/qwen-image')]; // default
1859
1887
 
1860
- const env = probeEnvironment(io, { root, workerDir, crypto, workerType: loadedManifests[0].worker_bundle.worker_type });
1888
+ const env = await probeMod.hashProbedModels(io, probeEnvironment(io, {
1889
+ root, workerDir, crypto, workerType: loadedManifests[0].worker_bundle.worker_type, manifests: loadedManifests,
1890
+ }), loadedManifests);
1861
1891
  const report = resolver.resolveInstallation({ manifests: loadedManifests, environment: env, mode: 'existing' });
1862
1892
  const { buildVerificationReport } = require('./verification-report');
1863
1893
  const ver = buildVerificationReport({ report, live: {} });
@@ -2397,7 +2427,7 @@ module.exports = {
2397
2427
  toolCommand, toolCommandPath, detectHubVersion, priorReusableDecisions, applicableDecisions, isBootRun,
2398
2428
  missingRequiredHostPackages, shouldWaitForPlatformComfy, platformComfyGate, platformComfyMissingResult,
2399
2429
  restartPlatformComfyDecision, platformNodeDepsGate, nodeDepsFailedResult, recordInstallerOption,
2400
- cmdBoot, bootChildArgs, bootLogPath, startupScriptLine,
2430
+ cmdBoot, bootChildArgs, bootLogPath, teeToBootLog, startupScriptLine,
2401
2431
  preflightSelfUpdate, preflightExtras, installedToolsVersion, ownVersion,
2402
2432
  nodeDepsOwnedServices, recordOwnedServices, otherProfileManifests, overridesStep,
2403
2433
  };
@@ -168,6 +168,28 @@ async function downloadArtifact(io, spec, opts = {}) {
168
168
  };
169
169
  }
170
170
 
171
+ /** What a verification grade proved, in log words. */
172
+ const GRADE_TEXT = {
173
+ 'checksum-verified': 'verified sha256',
174
+ 'checksum-prefix-verified': 'verified sha256 prefix',
175
+ 'size-verified': 'verified size',
176
+ 'files-verified': 'verified file list',
177
+ };
178
+
179
+ /**
180
+ * One log line per model file (0.2.14): name, size, outcome —
181
+ * model models/x/a.bin (123 bytes): downloaded, verified sha256
182
+ * model models/x/a.bin (123 bytes): present, verified sha256 — skipped
183
+ * model models/x/a.bin: failed: HTTP 404 from source
184
+ */
185
+ function modelFileLine({ file, size = null, status, grade = null, reason = null }) {
186
+ const name = `model ${file}${typeof size === 'number' ? ` (${size} bytes)` : ''}`;
187
+ const proof = GRADE_TEXT[grade] || 'not verified (no checksum or size in the manifest)';
188
+ if (status === 'downloaded' || status === 'resumed') return `${name}: downloaded${status === 'resumed' ? ' (resumed)' : ''}, ${proof}`;
189
+ if (status === 'skipped') return `${name}: present, ${proof} — skipped`;
190
+ return `${name}: ${status || 'failed'}: ${reason || grade || 'unknown reason'}`;
191
+ }
192
+
171
193
  // ---------------------------------------------------------------------------
172
194
  // Platform adapters — manifest source → request headers
173
195
  // ---------------------------------------------------------------------------
@@ -531,6 +553,7 @@ module.exports = {
531
553
  SIZE_TOLERANCE,
532
554
  verifyFile,
533
555
  downloadArtifact,
556
+ modelFileLine,
534
557
  makeHeaderProvider,
535
558
  modelscopeStrategy,
536
559
  listModelScopeFiles,
@@ -273,8 +273,10 @@ async function runInstallation(args) {
273
273
  : probe.probeEnvironment(io, {
274
274
  root: comfyuiRoot, workerDir, crypto,
275
275
  workerType: manifests.length === 1 ? (manifests[0].worker_bundle || {}).worker_type : null,
276
+ manifests,
276
277
  })
277
278
  );
279
+ if (!dryRun) await probe.hashProbedModels(io, env, manifests);
278
280
  const device = env.device || (env.gpu ? 'cuda' : 'cpu');
279
281
  if (device === 'cpu') {
280
282
  result.warnings.push(CPU_MODE_WARNING);
@@ -797,6 +799,10 @@ async function runInstallation(args) {
797
799
  if (!runtimeFatal && modelsStep && modelsStep.skipped_by_user) {
798
800
  log.warn(`model downloads skipped — declined (${modelsStep.missing.length} missing: ${modelsStep.missing.map((x) => x.label).join(', ')})`);
799
801
  }
802
+ // Every model file is logged with its outcome (0.2.14) — also the ones
803
+ // the plan found in place, so the plan, this log and the final check
804
+ // speak about the same files.
805
+ logPresentModels(io, { env, report, manifests, log });
800
806
  if (!runtimeFatal && modelsStep && modelsStep.action && modelsStep.decision === 'yes') {
801
807
  const getHeader = downloader.makeHeaderProvider(process.env);
802
808
  const missingIds = (modelsStep.missing || []).map((x) => x.id);
@@ -823,6 +829,7 @@ async function runInstallation(args) {
823
829
  const strategy = downloader.modelscopeStrategy(dep);
824
830
  if (strategy.mechanism === 'node_auto_download') {
825
831
  result.results.models.push({ id: spec.id, status: 'deferred-to-node', reason: strategy.note });
832
+ logModelResult(io, { log, res: { status: 'deferred-to-node', reason: strategy.note }, target: spec.target_path, absTarget });
826
833
  state.setArtifact(st, spec.id, 'missing', { note: strategy.note });
827
834
  } else if (strategy.mechanism === 'installer_preload') {
828
835
  // D2 closed: installer pre-downloads ModelScope repos
@@ -853,6 +860,9 @@ async function runInstallation(args) {
853
860
  const res = r.ok ? r.value : { status: 'failed', reason: String(r.error && r.error.message) };
854
861
  const status = res.status === 'failed' ? 'failed' : res.status === 'skipped' ? 'verified' : 'installed';
855
862
  result.results.models.push({ id: spec.id, ...res });
863
+ logModelResult(io, {
864
+ log, res, target: spec.target_path, absTarget: path.join(loc ? loc.base : comfyuiRoot, dlSpec.target_path),
865
+ });
856
866
  if (status === 'installed') {
857
867
  state.addOwnedComponent(st, 'models', {
858
868
  id: spec.id,
@@ -866,6 +876,7 @@ async function runInstallation(args) {
866
876
  continue; // skip the generic downloadArtifact below
867
877
  } else {
868
878
  result.results.models.push({ id: spec.id, status: 'blocked', reason: strategy.note });
879
+ logModelResult(io, { log, res: { status: 'blocked', reason: strategy.note }, target: spec.target_path, absTarget });
869
880
  state.setArtifact(st, spec.id, 'missing', { note: strategy.note });
870
881
  }
871
882
  if (strategy.mechanism !== 'installer_preload') continue;
@@ -883,6 +894,7 @@ async function runInstallation(args) {
883
894
  if (progress && progress.endFile) progress.endFile({ status: r.ok ? r.value.status : 'failed' });
884
895
  const res = r.ok ? r.value : { status: 'failed', reason: String(r.error && r.error.message) };
885
896
  result.results.models.push({ id: spec.id, ...res });
897
+ logModelResult(io, { log, res, target: spec.target_path, absTarget });
886
898
  if (res.status === 'downloaded' || res.status === 'resumed') {
887
899
  state.addOwnedComponent(st, 'models', {
888
900
  id: spec.id,
@@ -1438,6 +1450,41 @@ function pickUpdateTarget(manifest) {
1438
1450
  throw new Error('no update target in manifest');
1439
1451
  }
1440
1452
 
1453
+ /** Log the outcome of one download: a single file, or every file of a repo. */
1454
+ function logModelResult(io, { log, res, target, absTarget }) {
1455
+ const files = res.files && res.files.length > 0 ? res.files : [{ ...res, path: null }];
1456
+ for (const f of files) {
1457
+ let size = null;
1458
+ try {
1459
+ const st = io.fs.statSync(f.path ? path.join(absTarget, f.path) : absTarget);
1460
+ if (st.isFile) size = st.size;
1461
+ } catch (_) { /* not on disk */ }
1462
+ const line = downloader.modelFileLine({ ...f, file: f.path ? `${target}/${f.path}` : target, size });
1463
+ if (f.status === 'failed' || f.status === 'blocked') log.error(line);
1464
+ else log.info(line);
1465
+ }
1466
+ }
1467
+
1468
+ /** Log the model files the resolver found on disk (they are not downloaded). */
1469
+ function logPresentModels(io, { env, report, manifests, log }) {
1470
+ const sizes = new Map((env.models || []).map((m) => [m.path, m.size_bytes]));
1471
+ for (const e of report.entries) {
1472
+ const dep = findModelDep(manifests, e.id);
1473
+ if (!dep || !e.found || (e.kind !== 'model' && e.kind !== 'model_repo')) continue;
1474
+ const dir = path.posix.normalize(String(dep.target_dir));
1475
+ // a repo lists its files with the full path or relative to its folder
1476
+ const files = e.found.path ? [e.found.path] : (e.found.files || []).map((f) => (sizes.has(f) ? f : `${dir}/${f}`));
1477
+ for (const file of files.filter((f) => !f.endsWith('.part'))) {
1478
+ const size = sizes.get(file);
1479
+ if (e.status === 'incompatible') {
1480
+ log.warn(`${downloader.modelFileLine({ file, size, status: 'left as is', reason: e.reason })} — to download it again, delete the file and repeat the run`);
1481
+ } else {
1482
+ log.info(downloader.modelFileLine({ file, size, status: 'skipped', grade: e.grade }));
1483
+ }
1484
+ }
1485
+ }
1486
+ }
1487
+
1441
1488
  function findModelDep(manifests, id) {
1442
1489
  for (const m of manifests) {
1443
1490
  const dep = (m.dependencies || []).find((d) => d.id === id);
@@ -1754,7 +1801,9 @@ async function runVerification({ io, manifests, roots, options, log, crypto, tok
1754
1801
  }
1755
1802
 
1756
1803
  // Re-probe disk state for the final report
1757
- const envAfter = probe.probeEnvironment(io, { root: comfyuiRoot, workerDir, crypto, workerType: expectedType });
1804
+ const envAfter = await probe.hashProbedModels(io, probe.probeEnvironment(io, {
1805
+ root: comfyuiRoot, workerDir, crypto, workerType: expectedType, manifests,
1806
+ }), manifests);
1758
1807
  const reportAfter = require('../compatibility-resolver').resolveInstallation({
1759
1808
  manifests, environment: envAfter, mode: manifests.length > 1 ? 'shared' : 'existing',
1760
1809
  });
@@ -16,12 +16,14 @@ const { redactSecrets, isSecretName } = require('../safety-rules');
16
16
  function createLogger({ io, sink = null, quiet = false } = {}) {
17
17
  const secrets = new Set();
18
18
  const lines = [];
19
+ let tee = null;
19
20
 
20
21
  function emit(level, msg) {
21
22
  const safe = redact(String(msg), secrets);
22
23
  const ts = new Date(io.now()).toISOString();
23
24
  const line = `[${ts}] [${level}] ${safe}`;
24
25
  lines.push(line);
26
+ if (tee) tee(line);
25
27
  if (!quiet) {
26
28
  if (sink) sink(line);
27
29
  else console.log(line); // eslint-disable-line no-console
@@ -67,6 +69,11 @@ function createLogger({ io, sink = null, quiet = false } = {}) {
67
69
  return { ok: false, error: err, ms: io.now() - t0 };
68
70
  }
69
71
  },
72
+ /** Copy the log to fn: the lines so far, then every new one (redacted). */
73
+ teeTo(fn) {
74
+ lines.forEach((line) => fn(line));
75
+ tee = fn;
76
+ },
70
77
  lines,
71
78
  isSecretName,
72
79
  };
@@ -417,10 +417,29 @@ function extraModelFolders(io, root) {
417
417
  }
418
418
  }
419
419
 
420
- function probeModels(io, root) {
420
+ /**
421
+ * Folders scanned for models: MODEL_DIRS plus the top folder (models/<folder>)
422
+ * of every target_dir the manifests install models into — a file the
423
+ * downloader can write is always a file the check can see (0.2.14).
424
+ */
425
+ function modelScanDirs(manifests = []) {
426
+ const dirs = new Set(MODEL_DIRS);
427
+ for (const m of manifests || []) {
428
+ for (const dep of m.dependencies || []) {
429
+ if (dep.kind !== 'model' && dep.kind !== 'model_repo') continue;
430
+ const parts = String(dep.target_dir || '').split(/[\\/]+/).filter((p) => p && p !== '.');
431
+ if (parts.length < 2 || parts.includes('..')) continue;
432
+ dirs.add(parts.slice(0, 2).join('/'));
433
+ }
434
+ }
435
+ return [...dirs];
436
+ }
437
+
438
+ function probeModels(io, root, manifests = []) {
421
439
  const out = [];
422
- for (const dir of MODEL_DIRS) walkModelDir(io, path.join(root, dir), dir, out);
423
- const seen = new Set(MODEL_DIRS.map((d) => path.normalize(path.join(root, d))));
440
+ const scanDirs = modelScanDirs(manifests);
441
+ for (const dir of scanDirs) walkModelDir(io, path.join(root, dir), dir, out);
442
+ const seen = new Set(scanDirs.map((d) => path.normalize(path.join(root, d))));
424
443
  for (const extra of extraModelFolders(io, root)) {
425
444
  const abs = extra.path.replace(/[\\/]+$/, '');
426
445
  if (seen.has(path.normalize(abs))) continue; // same as the default layout
@@ -430,6 +449,34 @@ function probeModels(io, root) {
430
449
  return out;
431
450
  }
432
451
 
452
+ /** Larger files are checked by size only: hashing 20+ GB on every doctor run takes minutes. */
453
+ const HASH_LIMIT_BYTES = 1024 ** 3;
454
+
455
+ /**
456
+ * Add sha256 to the probed models the manifests carry a checksum for, so the
457
+ * resolver can say "checksum-verified" (0.2.14). Only files of exactly the
458
+ * manifest size are hashed: another size is another file (quant) and stays a
459
+ * matter of the size check. An unreadable file stays without sha256.
460
+ */
461
+ async function hashProbedModels(io, env, manifests = []) {
462
+ if (!env || !env.root || !Array.isArray(env.models) || !io.hashFile) return env;
463
+ const byPath = new Map(env.models.map((m) => [m.path, m]));
464
+ for (const dep of (manifests || []).flatMap((m) => m.dependencies || [])) {
465
+ if (dep.kind !== 'model' || !dep.checksum || !dep.checksum.value) continue;
466
+ const found = byPath.get(path.posix.join(dep.target_dir, dep.filename));
467
+ if (!found || found.sha256 || found.size_bytes !== dep.size_bytes_approx || found.size_bytes > HASH_LIMIT_BYTES) continue;
468
+ try { found.sha256 = await io.hashFile(modelAbsPath(env.root, found), 'sha256'); } catch (_) { /* size check only */ }
469
+ }
470
+ return env;
471
+ }
472
+
473
+ /** Absolute path of a probed model (`location` = a folder of extra_model_paths.yaml). */
474
+ function modelAbsPath(root, model) {
475
+ return model.location
476
+ ? path.join(model.location, model.path.split('/').slice(2).join('/'))
477
+ : path.join(root, model.path);
478
+ }
479
+
433
480
  function sha256OfFile(io, crypto, absPath) {
434
481
  const data = io.fs.readFileSync(absPath); // workflows are small; fine
435
482
  return crypto.createHash('sha256').update(Buffer.from(data)).digest('hex');
@@ -490,10 +537,10 @@ function probeWorker(io, workerDir) {
490
537
  /**
491
538
  * Probe the full environment.
492
539
  * @param {object} io
493
- * @param {object} opts { root: ComfyUI root, workerDir, crypto }
540
+ * @param {object} opts { root: ComfyUI root, workerDir, crypto, manifests: loaded manifests (model folders) }
494
541
  * @returns resolver-compatible environment object
495
542
  */
496
- function probeEnvironment(io, { root = null, workerDir = null, crypto = null, workerType = null } = {}) {
543
+ function probeEnvironment(io, { root = null, workerDir = null, crypto = null, workerType = null, manifests = [] } = {}) {
497
544
  const env = {
498
545
  root,
499
546
  comfyui: undefined,
@@ -526,7 +573,7 @@ function probeEnvironment(io, { root = null, workerDir = null, crypto = null, wo
526
573
 
527
574
  if (env.comfyui) {
528
575
  env.custom_nodes = probeCustomNodes(io, root);
529
- env.models = probeModels(io, root);
576
+ env.models = probeModels(io, root, manifests);
530
577
  env.python_packages = [];
531
578
  if (crypto) env.workflows = probeWorkflows(io, crypto, root);
532
579
  } else {
@@ -595,6 +642,9 @@ module.exports = {
595
642
  MODEL_DIRS,
596
643
  parseExtraModelPaths,
597
644
  probeModels,
645
+ modelScanDirs,
646
+ hashProbedModels,
647
+ modelAbsPath,
598
648
  pickNodeBinary,
599
649
  nodeBinaryVersion,
600
650
  nodeMajor,