@animastor/installer 0.1.1 → 0.2.4

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.
@@ -492,7 +492,11 @@ function checkModel(dep, env, profiles) {
492
492
  const expectedPath = `${normPath(dep.target_dir)}/${dep.filename}`;
493
493
  const found = (env.models || []).find((m) => normPath(m.path) === expectedPath);
494
494
  if (!found) {
495
- return { ...base, status: 'missing', action: missingAction(dep), expected: { path: expectedPath }, notes: [] };
495
+ return {
496
+ ...base, status: 'missing', action: missingAction(dep), expected: { path: expectedPath },
497
+ missing_bytes_approx: typeof dep.size_bytes_approx === 'number' ? dep.size_bytes_approx : null,
498
+ notes: [],
499
+ };
496
500
  }
497
501
  const checksum = dep.checksum || {};
498
502
  if (checksum.value && found.sha256) {
@@ -540,6 +544,14 @@ function checkModel(dep, env, profiles) {
540
544
  return { ...base, status: 'installed', grade: 'presence', action: 'skip', found: { path: found.path }, notes: ['presence only — no checksum/size evidence available'] };
541
545
  }
542
546
 
547
+ /**
548
+ * Files of a model repo that the loader never reads (repository metadata).
549
+ * Their absence must never make a present model "incomplete" — that is what
550
+ * made the installer offer to re-download complete, working models. The
551
+ * manifest may extend the list per dependency (`optional_files`).
552
+ */
553
+ const MODEL_REPO_METADATA_FILES = Object.freeze(['.gitattributes', 'README.md', 'configuration.json', 'LICENSE', 'LICENSE.txt']);
554
+
543
555
  function checkModelRepo(dep, env, profiles) {
544
556
  const base = { id: dep.id, kind: 'model_repo', name: dep.name, requirement: dep.requirement, basis: dep.basis, profiles };
545
557
  if (env.models === undefined) {
@@ -553,32 +565,51 @@ function checkModelRepo(dep, env, profiles) {
553
565
  status: 'missing',
554
566
  action: missingAction(dep),
555
567
  expected: { target_dir: prefix, repo: dep.repo },
568
+ missing_bytes_approx: typeof dep.size_bytes_approx === 'number' ? dep.size_bytes_approx : null,
556
569
  notes: dep.delivery && dep.delivery.mechanism === 'node_auto_download'
557
570
  ? ['the custom node can auto-download this repo on first run (decision D2: preinstall vs auto_download)']
558
571
  : [],
559
572
  };
560
573
  }
574
+ // Where the repo really lives: the default layout, or a folder declared
575
+ // in extra_model_paths.yaml (probe attaches `location`). Downloads of
576
+ // missing pieces go next to the found files — never into a second copy.
577
+ const location = matches.find((m) => m.location) ? matches.find((m) => m.location).location : null;
578
+ const found = location
579
+ ? { files: matches.map((m) => normPath(m.path)), location: { base: location, target_dir: prefix.split('/').slice(2).join('/') } }
580
+ : { files: matches.map((m) => normPath(m.path)) };
561
581
  if (Array.isArray(dep.expected_files) && dep.expected_files.length > 0) {
562
582
  const have = new Set(matches.map((m) => normPath(m.path)));
563
- const missingFiles = dep.expected_files.filter((f) => !have.has(`${prefix}/${normPath(f)}`));
583
+ // Metadata files are matched by NAME at any depth (ModelScope puts a
584
+ // configuration.json into sub-folders too); manifest optional_files
585
+ // by exact path.
586
+ const metadataNames = new Set(MODEL_REPO_METADATA_FILES);
587
+ const optional = new Set((Array.isArray(dep.optional_files) ? dep.optional_files : []).map(normPath));
588
+ const required = dep.expected_files.map(normPath).filter((f) => !optional.has(f) && !metadataNames.has(f.split('/').pop()));
589
+ const missingFiles = required.filter((f) => !have.has(`${prefix}/${f}`));
564
590
  if (missingFiles.length > 0) {
565
591
  // Partially present: status stays 'missing' (with reason
566
- // 'incomplete') so plan/engine treat it as installable — the
567
- // downloader is idempotent and resumes .part files, it never
568
- // re-downloads a verified file. 'incompatible' would park it as a
569
- // review item and an interrupted download could never resume.
592
+ // 'incomplete') so plan/engine treat it as installable — only the
593
+ // listed files are downloaded, files already on disk are never
594
+ // re-downloaded. 'incompatible' would park it as a review item and
595
+ // an interrupted download could never resume.
596
+ const interrupted = missingFiles.filter((f) => have.has(`${prefix}/${f}.part`));
597
+ const why = interrupted.length > 0
598
+ ? `download interrupted (${interrupted.join(', ')}: .part on disk)`
599
+ : `missing files: ${missingFiles.join(', ')}`;
570
600
  return {
571
601
  ...base,
572
602
  status: 'missing',
573
603
  reason: 'incomplete',
574
604
  action: 'install',
575
- found: { files: Array.from(have) },
576
- notes: [`present but incomplete; missing: ${missingFiles.join(', ')}`],
605
+ missing_files: missingFiles,
606
+ found,
607
+ notes: [`present but incomplete — ${why}`],
577
608
  };
578
609
  }
579
- return { ...base, status: 'installed', grade: 'files-verified', action: 'skip', found: { files: dep.expected_files }, notes: [] };
610
+ return { ...base, status: 'installed', grade: 'files-verified', action: 'skip', found: { ...found, files: required }, notes: [] };
580
611
  }
581
- return { ...base, status: 'installed', grade: 'presence', action: 'skip', found: { files: matches.map((m) => normPath(m.path)) }, notes: [] };
612
+ return { ...base, status: 'installed', grade: 'presence', action: 'skip', found, notes: [] };
582
613
  }
583
614
 
584
615
  function checkPythonPackage(dep, env, profiles) {
@@ -720,8 +751,22 @@ function checkWorker(manifest, env) {
720
751
  }
721
752
  const probes = Array.isArray(env.worker) ? env.worker : [env.worker];
722
753
  const probe = probes.find((p) => p && (p.worker_type === workerType || workerType === null));
754
+ const requiredEnvAll = (wb.env && wb.env.required) || [];
755
+ // The .env is independent of the BUNDLE files: a missing/incomplete bundle
756
+ // on a re-install must not report the existing Worker Key as missing (the
757
+ // installer would ask for it again). Report what the probe actually saw.
758
+ const envState = (p) => {
759
+ const present = !!(p && p.env && p.env.present !== false);
760
+ const setKeys = (p && p.env && p.env.set_keys) || [];
761
+ return {
762
+ present,
763
+ missing_required: present
764
+ ? requiredEnvAll.filter((k) => !setKeys.includes(k))
765
+ : requiredEnvAll.slice(),
766
+ };
767
+ };
723
768
  if (!probe || !probe.bundle || probe.bundle.present === false) {
724
- return { ...base, status: 'missing', action: 'install', expected: { files: wb.files || [] }, notes: [] };
769
+ return { ...base, status: 'missing', action: 'install', expected: { files: wb.files || [] }, env: envState(probe), notes: [] };
725
770
  }
726
771
  const haveFiles = probe.bundle.files || [];
727
772
  const filesMissing = (wb.files || []).filter((f) => !haveFiles.includes(f));
@@ -733,6 +778,7 @@ function checkWorker(manifest, env) {
733
778
  action: 'install',
734
779
  expected: { files: wb.files },
735
780
  found: { files: haveFiles },
781
+ env: envState(probe),
736
782
  notes: [`bundle incomplete; missing files: ${filesMissing.join(', ')}`],
737
783
  };
738
784
  }
@@ -1264,6 +1310,7 @@ function planIsolatedEnvironments(assignments) {
1264
1310
  }
1265
1311
 
1266
1312
  module.exports = {
1313
+ MODEL_REPO_METADATA_FILES,
1267
1314
  RUNTIME_MODES,
1268
1315
  ENTRY_STATUSES,
1269
1316
  ACTIONS,
@@ -0,0 +1,385 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * ComfyUI ownership BY FACT (installer 0.2.2).
5
+ *
6
+ * The install state is a record, not the truth: on TIR nodes the platform
7
+ * starts `python3 ~/ComfyUI/main.py --listen 0.0.0.0 --port 8888 --baseurl
8
+ * /notebook/p-…` with root privileges, and the port/prefix change between
9
+ * boots. The installer must therefore decide the mode from what RUNS:
10
+ *
11
+ * - a verified ComfyUI process that the installer did not start
12
+ * → owner 'foreign', mode 'existing': its address (from --port /
13
+ * --baseurl in the cmdline, confirmed by GET /system_stats returning
14
+ * a ComfyUI payload) is the one the worker gets; the installer never
15
+ * starts a second ComfyUI next to it.
16
+ * - the installer's OWN process (started by spawnDaemon: `--listen
17
+ * 127.0.0.1 --port N`, recorded in state.comfyui_runtime)
18
+ * → owner 'managed', mode 'managed'.
19
+ * - nothing running
20
+ * → 'managed' only when the installer created the ComfyUI
21
+ * (state.components.comfyui.owned); otherwise 'existing' (the
22
+ * user's ComfyUI is simply down — never silently take it over).
23
+ *
24
+ * A recorded state that contradicts the fact is reported as a CONFLICT with
25
+ * the exact correction (mode / startComfyui / comfyPort / ownership); the
26
+ * CLI shows it and applies the correction with one question.
27
+ */
28
+
29
+ const path = require('path');
30
+ const probe = require('./probe');
31
+
32
+ /** The listen address of every ComfyUI the installer starts itself. */
33
+ const INSTALLER_LISTEN = '127.0.0.1';
34
+
35
+ /** 'http://127.0.0.1:8888/notebook/p-1/n-2' → '/notebook/p-1/n-2'; '' → ''. */
36
+ function normalizePrefix(baseurl) {
37
+ const p = String(baseurl || '').trim();
38
+ if (!p || p === '/') return '';
39
+ const one = `/${p.replace(/^\/+|\/+$/g, '')}`;
40
+ return one === '/' ? '' : one;
41
+ }
42
+
43
+ /**
44
+ * The address a ComfyUI process is reachable at, taken from its OWN cmdline:
45
+ * --listen decides the host (0.0.0.0 / :: → loopback), --port the port,
46
+ * --baseurl the reverse-proxy prefix. Nothing is guessed.
47
+ */
48
+ function comfyUrlFor({ port = 8188, baseurl = null, listen = null } = {}) {
49
+ const l = String(listen || '').trim();
50
+ const host = !l || l === '0.0.0.0' || l === '::' || l === '[::]' ? INSTALLER_LISTEN : l;
51
+ const prefix = normalizePrefix(baseurl);
52
+ const base = `http://${host}:${Number(port)}`;
53
+ return { url: prefix ? `${base}${prefix}` : base, prefixed: prefix !== '', baseurl: prefix };
54
+ }
55
+
56
+ /**
57
+ * True when the process is THE instance this installation started: the
58
+ * installer always starts its own ComfyUI with `--listen 127.0.0.1`, no
59
+ * --baseurl, on the port recorded in state.comfyui_runtime. A platform
60
+ * process (`--listen 0.0.0.0 --baseurl …`) is never classified as ours, so
61
+ * it is never stopped, wired as a managed target or reported as managed.
62
+ */
63
+ function isInstallerInstance(proc, state) {
64
+ if (!proc || proc.listen !== INSTALLER_LISTEN) return false;
65
+ if (normalizePrefix(proc.baseurl)) return false;
66
+ const rt = (state && state.comfyui_runtime) || null;
67
+ if (!rt) return false;
68
+ if (rt.pid != null && Number(rt.pid) === Number(proc.pid)) return true;
69
+ return rt.port != null && Number(rt.port) === Number(proc.port);
70
+ }
71
+
72
+ /**
73
+ * GET <url>/system_stats and require a ComfyUI payload (system + devices) —
74
+ * a wrong reverse-proxy prefix answers 404/HTML, another service answers its
75
+ * own JSON, so a bare 200 is not proof.
76
+ * @returns {Promise<object|null>}
77
+ */
78
+ async function verifyComfyUrl(io, url, { timeoutMs = 3000 } = {}) {
79
+ try {
80
+ const opts = typeof AbortSignal !== 'undefined' && AbortSignal.timeout
81
+ ? { signal: AbortSignal.timeout(timeoutMs) }
82
+ : {};
83
+ const res = await io.http.fetchJson(`${url}/system_stats`, opts);
84
+ if (res && res.status === 200 && probe.isSystemStats(res.json)) return res.json;
85
+ } catch (_) { /* not this URL */ }
86
+ return null;
87
+ }
88
+
89
+ /** One-line description used by the mode line and the conflict list. */
90
+ function describeInstance(i) {
91
+ if (!i) return 'no ComfyUI process';
92
+ const who = i.ours ? 'started by the installer' : 'started outside the installer';
93
+ return `pid ${i.pid} on :${i.port}${i.baseurl || ''} (${who})`;
94
+ }
95
+
96
+ /**
97
+ * Every running ComfyUI of this account, each with its cmdline address and a
98
+ * verification flag. Processes whose address does not answer a ComfyUI
99
+ * payload are still listed (they explain a port conflict) but never chosen.
100
+ */
101
+ async function inspectComfyInstances(io, { state = null } = {}) {
102
+ const procs = typeof probe.listRunningComfyUI === 'function'
103
+ ? probe.listRunningComfyUI(io)
104
+ : [];
105
+ const out = [];
106
+ for (const p of procs) {
107
+ const u = comfyUrlFor(p);
108
+ const stats = await verifyComfyUrl(io, u.url);
109
+ out.push({
110
+ ...p,
111
+ url: u.url,
112
+ prefixed: u.prefixed,
113
+ baseurl: u.baseurl,
114
+ ours: isInstallerInstance(p, state),
115
+ verified: !!stats,
116
+ });
117
+ }
118
+ return out;
119
+ }
120
+
121
+ /**
122
+ * Contradictions between the recorded install-state and the machine.
123
+ * @returns {Array<{ key, recorded, actual, message }>}
124
+ */
125
+ function stateConflicts(state, resolved) {
126
+ const out = [];
127
+ if (!state) return out;
128
+ const mode = resolved.mode;
129
+ if (state.mode && state.mode !== mode) {
130
+ out.push({
131
+ key: 'mode',
132
+ recorded: state.mode,
133
+ actual: mode,
134
+ message: `mode: ${state.mode} (recorded) → ${mode} (${resolved.reason})`,
135
+ });
136
+ }
137
+ const opts = state.installer_options || {};
138
+ if (mode === 'existing' && opts.startComfyui === true) {
139
+ out.push({
140
+ key: 'startComfyui',
141
+ recorded: true,
142
+ actual: false,
143
+ message: `startComfyui: true (recorded) → false (${resolved.reason} — the installer must not start a second ComfyUI)`,
144
+ });
145
+ }
146
+ if (mode === 'existing' && resolved.port != null && opts.comfyPort != null
147
+ && Number(opts.comfyPort) !== Number(resolved.port)) {
148
+ out.push({
149
+ key: 'comfyPort',
150
+ recorded: Number(opts.comfyPort),
151
+ actual: Number(resolved.port),
152
+ message: `comfyPort: ${opts.comfyPort} (recorded) → ${resolved.port} (from the running process)`,
153
+ });
154
+ }
155
+ const owned = !!(state.components && state.components.comfyui && state.components.comfyui.owned);
156
+ if (mode === 'existing' && owned) {
157
+ out.push({
158
+ key: 'components.comfyui.owned',
159
+ recorded: true,
160
+ actual: false,
161
+ message: `the install state says the installer owns this ComfyUI, but the running instance was ${resolved.foreign ? describeInstance(resolved.foreign) : 'not started by it'}`,
162
+ });
163
+ }
164
+ if (resolved.ours && resolved.foreign) {
165
+ out.push({
166
+ key: 'installer-instance',
167
+ recorded: describeInstance(resolved.ours),
168
+ actual: describeInstance(resolved.foreign),
169
+ message: `two instances run: the installer's own (${describeInstance(resolved.ours)}) and the platform's (${describeInstance(resolved.foreign)}) — the platform's is the real one`,
170
+ });
171
+ }
172
+ return out;
173
+ }
174
+
175
+ /**
176
+ * Resolve the ComfyUI this installation must use — from facts only.
177
+ * @returns {Promise<{
178
+ * present: boolean, owner: 'foreign'|'managed'|'none', mode: 'existing'|'managed',
179
+ * url: string|null, port: number|null, baseurl: string|null, pid: number|null,
180
+ * root: string|null, reason: string, instances: object[],
181
+ * foreign: object|null, ours: object|null, conflicts: object[],
182
+ * stop_offer: { pid: number, port: number }|null
183
+ * }>}
184
+ */
185
+ async function resolveComfyOwner(io, { state = null, root = null, timeoutMs = 3000 } = {}) {
186
+ const instances = await inspectComfyInstances(io, { state });
187
+ const verified = instances.filter((i) => i.verified);
188
+ const foreign = verified.find((i) => !i.ours) || null;
189
+ const ours = instances.find((i) => i.ours) || null;
190
+
191
+ let mode;
192
+ let owner;
193
+ let chosen = null;
194
+ let reason;
195
+ if (foreign) {
196
+ owner = 'foreign';
197
+ mode = 'existing';
198
+ chosen = foreign;
199
+ reason = `a ComfyUI the installer did not start is running — ${describeInstance(foreign)}`;
200
+ } else if (ours) {
201
+ owner = 'managed';
202
+ mode = 'managed';
203
+ chosen = ours;
204
+ reason = `the installer's own ComfyUI is running — ${describeInstance(ours)}`;
205
+ } else {
206
+ // Nothing runs. Disk truth decides:
207
+ // - the installer created this ComfyUI → managed (start it);
208
+ // - a ComfyUI exists at the root but is down → existing (the user's
209
+ // instance is never taken over by starting our own);
210
+ // - no ComfyUI at the root → managed (a first install clones one).
211
+ const owned = !!(state && state.components && state.components.comfyui && state.components.comfyui.owned);
212
+ const onDisk = !!(root && io.fs.existsSync(path.join(root, 'main.py')));
213
+ owner = 'none';
214
+ if (owned) {
215
+ mode = 'managed';
216
+ reason = `no ComfyUI process is running; the installer created this ComfyUI (managed${root ? `: ${root}` : ''})`;
217
+ } else if (onDisk) {
218
+ mode = 'existing';
219
+ reason = `a ComfyUI exists at ${root} but does not run — the user starts it (existing)`;
220
+ } else {
221
+ mode = 'managed';
222
+ reason = `no ComfyUI ${root ? `at ${root} ` : ''}and none running — the installer sets one up (managed)`;
223
+ }
224
+ }
225
+
226
+ const resolved = {
227
+ present: !!chosen,
228
+ owner,
229
+ mode,
230
+ url: chosen ? chosen.url : null,
231
+ port: chosen ? chosen.port : null,
232
+ baseurl: chosen ? chosen.baseurl : null,
233
+ pid: chosen ? chosen.pid : null,
234
+ root: chosen && chosen.root ? chosen.root : null,
235
+ reason,
236
+ instances,
237
+ foreign,
238
+ ours,
239
+ conflicts: [],
240
+ stop_offer: (ours && foreign) ? { pid: ours.pid, port: ours.port } : null,
241
+ };
242
+ resolved.conflicts = stateConflicts(state, resolved);
243
+ return resolved;
244
+ }
245
+
246
+ /**
247
+ * Stop ONE process that was classified as the installer's own instance.
248
+ * Refuses anything else — a foreign ComfyUI is never signaled.
249
+ * @returns {{ stopped: boolean, reason?: string }}
250
+ */
251
+ function stopInstallerInstance(io, instance) {
252
+ if (!instance || !instance.ours) {
253
+ return { stopped: false, reason: 'refusing to stop a ComfyUI the installer did not start' };
254
+ }
255
+ try {
256
+ if (typeof io.kill === 'function') io.kill(instance.pid, 'SIGTERM');
257
+ else process.kill(instance.pid, 'SIGTERM');
258
+ return { stopped: true };
259
+ } catch (err) {
260
+ return { stopped: false, reason: err.message };
261
+ }
262
+ }
263
+
264
+ /**
265
+ * May this run start its OWN ComfyUI?
266
+ * - owner 'foreign' → never (a second instance next to the platform's is
267
+ * the bug this release fixes); an explicit --start-comfy is ignored and
268
+ * reported;
269
+ * - otherwise an explicit flag wins, then the remembered setting, then the
270
+ * mode (managed starts by default, existing does not).
271
+ * @returns {{ startComfyui: boolean, ignored_request: boolean, corrected: boolean, reason: string }}
272
+ */
273
+ function decideStartComfy({ owner = 'none', requested = undefined, remembered = undefined, mode = 'existing' } = {}) {
274
+ if (owner === 'foreign') {
275
+ return {
276
+ startComfyui: false,
277
+ ignored_request: requested === true,
278
+ corrected: requested === true || remembered === true,
279
+ reason: 'another ComfyUI already runs on this machine — the installer never starts a second one',
280
+ };
281
+ }
282
+ if (requested !== undefined) return { startComfyui: requested === true, ignored_request: false, corrected: false, reason: 'requested' };
283
+ if (remembered !== undefined) return { startComfyui: remembered === true, ignored_request: false, corrected: false, reason: 'remembered setting' };
284
+ return { startComfyui: mode === 'managed', ignored_request: false, corrected: false, reason: mode === 'managed' ? 'managed mode starts its own ComfyUI' : 'existing mode leaves the running ComfyUI alone' };
285
+ }
286
+
287
+ /**
288
+ * Wait until the platform's ComfyUI answers at `url` (boot script: the
289
+ * platform starts it after the installer). Polls GET /system_stats.
290
+ * @returns {Promise<{ ok: boolean, url: string|null, waited_ms: number }>}
291
+ */
292
+ async function waitForComfyUrl(io, { url = null, timeoutMs = 180000, intervalMs = 3000 } = {}) {
293
+ const deadline = io.now() + timeoutMs;
294
+ let last = null;
295
+ for (;;) {
296
+ const target = url || last;
297
+ if (target) {
298
+ const stats = await verifyComfyUrl(io, target, { timeoutMs: Math.min(3000, intervalMs) });
299
+ if (stats) return { ok: true, url: target, waited_ms: Math.max(0, io.now() - (deadline - timeoutMs)) };
300
+ }
301
+ if (io.now() > deadline) {
302
+ return { ok: false, url: target || url, waited_ms: timeoutMs };
303
+ }
304
+ await new Promise((r) => setTimeout(r, intervalMs));
305
+ }
306
+ }
307
+
308
+ /**
309
+ * True when the RECORDED installation says "this ComfyUI belongs to the
310
+ * platform" (installer 0.2.3, type A): a previous run saw a foreign
311
+ * instance (state.comfy_owner.owner === 'foreign'), or the installation is
312
+ * an `existing` one / never starts its own ComfyUI and did not create it.
313
+ * A managed install of a clean Ubuntu (type B: owned, startComfyui=true) is
314
+ * never platform-owned.
315
+ */
316
+ function platformOwnedByRecord(state) {
317
+ if (!state) return false;
318
+ if (state.comfy_owner && state.comfy_owner.owner === 'foreign') return true;
319
+ const owned = !!(state.components && state.components.comfyui && state.components.comfyui.owned);
320
+ if (owned) return false;
321
+ const opts = state.installer_options || {};
322
+ return state.mode === 'existing' || opts.startComfyui === false;
323
+ }
324
+
325
+ /** The platform message for type A when ComfyUI never came up. */
326
+ function platformComfyMissingReason(waitedMs, lastSeen = null) {
327
+ const secs = Math.round(Number(waitedMs || 0) / 1000);
328
+ const seen = lastSeen && lastSeen.pid
329
+ ? ` (process pid ${lastSeen.pid} at ${lastSeen.url} did not answer GET /system_stats)`
330
+ : ' (no ComfyUI main.py process appeared)';
331
+ return `ComfyUI is started by the platform; it did not come up in ${secs} s${seen}`;
332
+ }
333
+
334
+ /**
335
+ * Boot (type A): wait until the PLATFORM's ComfyUI runs AND answers. Every
336
+ * poll re-reads the processes (pgrep + /proc cmdline) and re-verifies GET
337
+ * /system_stats at the address built from THAT cmdline — the port and the
338
+ * notebook prefix of the previous boot are never reused. Progress goes to
339
+ * `onProgress` once per `progressMs` (the boot log).
340
+ * @returns {Promise<{ ok: boolean, instance: object, waited_ms: number, last_seen: { pid, url }|null }>}
341
+ */
342
+ async function waitForPlatformComfyUI(io, {
343
+ state = null, root = null, timeoutMs = 180000, intervalMs = 3000, progressMs = 30000,
344
+ onProgress = null, sleep = null,
345
+ } = {}) {
346
+ const now = () => (typeof io.now === 'function' ? io.now() : Date.now());
347
+ const pause = sleep || ((ms) => new Promise((r) => setTimeout(r, ms)));
348
+ const started = now();
349
+ let nextProgress = started + progressMs;
350
+ let lastSeen = null;
351
+ for (;;) {
352
+ const instance = await resolveComfyOwner(io, { state, root });
353
+ const waited = now() - started;
354
+ if (instance.owner === 'foreign') return { ok: true, instance, waited_ms: waited, last_seen: lastSeen };
355
+ const proc = (instance.instances || []).find((i) => !i.ours) || null;
356
+ lastSeen = proc ? { pid: proc.pid, url: proc.url } : lastSeen;
357
+ if (waited >= timeoutMs) return { ok: false, instance, waited_ms: waited, last_seen: lastSeen };
358
+ if (onProgress && now() >= nextProgress) {
359
+ const what = proc
360
+ ? `process pid ${proc.pid} at ${proc.url} does not answer GET /system_stats yet`
361
+ : 'no ComfyUI main.py process yet';
362
+ onProgress(`waiting for the platform's ComfyUI — ${what} (${Math.round(waited / 1000)} s of ${Math.round(timeoutMs / 1000)} s)`);
363
+ nextProgress += progressMs;
364
+ }
365
+ await pause(Math.min(intervalMs, Math.max(1, timeoutMs - waited)));
366
+ }
367
+ }
368
+
369
+ module.exports = {
370
+ INSTALLER_LISTEN,
371
+ normalizePrefix,
372
+ comfyUrlFor,
373
+ isInstallerInstance,
374
+ verifyComfyUrl,
375
+ inspectComfyInstances,
376
+ stateConflicts,
377
+ resolveComfyOwner,
378
+ decideStartComfy,
379
+ stopInstallerInstance,
380
+ waitForComfyUrl,
381
+ describeInstance,
382
+ platformOwnedByRecord,
383
+ platformComfyMissingReason,
384
+ waitForPlatformComfyUI,
385
+ };
@@ -331,6 +331,31 @@ async function listModelScopeFiles(io, repository, revision = 'master', token =
331
331
  * @param {object} opts { root, getHeader, retries, retryDelayMs, log, expectedFiles, checksums }
332
332
  * @returns {{ status, files?, reason?, attempts }}
333
333
  */
334
+ /**
335
+ * Fill `missing_bytes_approx` of incomplete ModelScope repos in a resolver
336
+ * report from the registry listing (real sizes of exactly the missing files)
337
+ * so the plan shows what will really be downloaded. Best effort: a failed
338
+ * listing leaves the size unknown — never invented.
339
+ */
340
+ async function annotateMissingModelSizes(io, report, manifests) {
341
+ const deps = new Map();
342
+ for (const m of manifests) for (const d of m.dependencies || []) deps.set(d.id, d);
343
+ for (const e of report.entries || []) {
344
+ if (e.kind !== 'model_repo' || e.reason !== 'incomplete' || !Array.isArray(e.missing_files)) continue;
345
+ const dep = deps.get(e.id);
346
+ const src = (dep && dep.source) || {};
347
+ if (src.kind !== 'modelscope' || !src.repository) continue;
348
+ try {
349
+ const listing = await listModelScopeFiles(io, src.repository, src.revision || 'master', process.env.MODELSCOPE_API_TOKEN || null);
350
+ if (!listing.ok) continue;
351
+ const want = new Set(e.missing_files.map(normPath));
352
+ const total = listing.files.filter((f) => want.has(normPath(f.Path))).reduce((a, f) => a + (f.Size > 0 ? f.Size : 0), 0);
353
+ if (total > 0) e.missing_bytes_approx = total;
354
+ } catch (_) { /* size stays unknown */ }
355
+ }
356
+ return report;
357
+ }
358
+
334
359
  async function downloadModelScopeRepo(io, spec, opts = {}) {
335
360
  const {
336
361
  root = '',
@@ -502,6 +527,7 @@ async function downloadModelScopeRepo(io, spec, opts = {}) {
502
527
  }
503
528
 
504
529
  module.exports = {
530
+ annotateMissingModelSizes,
505
531
  SIZE_TOLERANCE,
506
532
  verifyFile,
507
533
  downloadArtifact,