@animastor/installer 0.1.0

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.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -0
  3. package/ai/install-manifests/audio/qwen-tts.json +445 -0
  4. package/ai/install-manifests/image/qwen-image.json +465 -0
  5. package/ai/install-manifests/video/ltx-2.3.json +892 -0
  6. package/package.json +42 -0
  7. package/src/installer/cli.js +1067 -0
  8. package/src/installer/compatibility-resolver.js +1287 -0
  9. package/src/installer/download-planner.js +172 -0
  10. package/src/installer/engine/comfyui.js +508 -0
  11. package/src/installer/engine/downloader.js +514 -0
  12. package/src/installer/engine/engine.js +1180 -0
  13. package/src/installer/engine/io.js +437 -0
  14. package/src/installer/engine/logger.js +75 -0
  15. package/src/installer/engine/nodes.js +146 -0
  16. package/src/installer/engine/prereq.js +399 -0
  17. package/src/installer/engine/probe.js +349 -0
  18. package/src/installer/engine/progress.js +350 -0
  19. package/src/installer/engine/state.js +170 -0
  20. package/src/installer/engine/term.js +298 -0
  21. package/src/installer/engine/worker.js +430 -0
  22. package/src/installer/engine/workflows.js +153 -0
  23. package/src/installer/index.js +40 -0
  24. package/src/installer/install-manifest.js +376 -0
  25. package/src/installer/install-plan.js +741 -0
  26. package/src/installer/management.js +489 -0
  27. package/src/installer/platform/deployment/docker.js +78 -0
  28. package/src/installer/platform/deployment/native.js +36 -0
  29. package/src/installer/platform/index.js +165 -0
  30. package/src/installer/platform/linux.js +341 -0
  31. package/src/installer/platform/windows.js +360 -0
  32. package/src/installer/safety-rules.js +156 -0
  33. package/src/installer/setup-contract.js +1401 -0
  34. package/src/installer/uninstaller.js +572 -0
  35. package/src/installer/verification-report.js +220 -0
  36. package/src/installer/worker-bundle-source.js +64 -0
  37. package/src/installer/workflow-artifacts.js +152 -0
@@ -0,0 +1,489 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Management Tools runtime — shared logic for the installer and the
5
+ * command-line management tools installed next to the worker
6
+ * (tools/status.sh, tools/reboot-worker.sh, tools/reboot-comfyui.sh,
7
+ * tools/comfyui-monitor.sh).
8
+ *
9
+ * The tools are thin CLI entry points; ALL runtime behaviour lives here and
10
+ * reuses the installer engine primitives — there is exactly ONE
11
+ * implementation of managed ComfyUI discovery (engine/comfyui.js
12
+ * findManagedComfyUIPids / restartManagedComfyUI), managed worker discovery
13
+ * (engine/worker.js findRunningWorkerPid / restartManagedWorker), port
14
+ * handling (installer_options / comfyui_runtime state) and terminal UX
15
+ * (engine/term.js createTermRenderer + busy spinner).
16
+ *
17
+ * Safety invariants (mirrors the installer):
18
+ * - no global pkill/killall: only cwd-verified managed processes are
19
+ * signaled, and only ones owned by the current account (uid guard);
20
+ * - cross-tenant safety: paths and the install state's owner_uid go through
21
+ * the same ownership guard as the installer (prereq.checkOwnership);
22
+ * - tools never create root-owned files: the ownership guard blocks a sudo
23
+ * run against a user-owned installation;
24
+ * - read-only tools (status/monitor) never write state; reboot tools write
25
+ * only the runtime log files the engine's spawnDaemon already manages.
26
+ *
27
+ * ComfyUI API usage (v0.11.x, graceful fallback everywhere):
28
+ * GET /system_stats — API reachability (comfyui.systemStats)
29
+ * GET /queue — queue_running / queue_pending
30
+ * GET /history?max_items=N (fallback: /history) — recent errors
31
+ * The monitor NEVER invents data it could not retrieve: unknown values are
32
+ * rendered as "—" and unavailable blocks are omitted.
33
+ */
34
+
35
+ const path = require('path');
36
+ const platforms = require('./platform');
37
+ const comfyui = require('./engine/comfyui');
38
+ const workerMod = require('./engine/worker');
39
+ const stateMod = require('./engine/state');
40
+ const prereq = require('./engine/prereq');
41
+
42
+ /** Adapter for one call (explicit override wins over auto-detect). */
43
+ function adapterOf(opts = {}) {
44
+ return (opts && opts.platformAdapter) || platforms.getPlatformAdapter();
45
+ }
46
+
47
+ /**
48
+ * The installed command-line tools (wrapper script → CLI subcommand).
49
+ * `file` is the canonical (historical, Linux) file name; the platform
50
+ * adapter maps it to the platform-appropriate script name (.sh → .cmd).
51
+ */
52
+ const TOOL_SCRIPTS = Object.freeze([
53
+ { file: 'status.sh', command: 'status' },
54
+ { file: 'reboot-worker.sh', command: 'reboot-worker' },
55
+ { file: 'reboot-comfyui.sh', command: 'reboot-comfyui' },
56
+ { file: 'comfyui-monitor.sh', command: 'monitor' },
57
+ ]);
58
+
59
+ // ---------------------------------------------------------------------------
60
+ // Runtime target resolution (one installation = one state file + roots)
61
+ // ---------------------------------------------------------------------------
62
+
63
+ /**
64
+ * Resolve the runtime targets of THIS installation.
65
+ * Precedence: explicit CLI flags > install state > defaults.
66
+ * @returns {{ state, comfyuiRoot, workerDir, port, device, statePath, found: boolean }}
67
+ */
68
+ function resolveTargets(io, { statePath, root = null, workerDir = null, port = null } = {}) {
69
+ const st = statePath ? stateMod.loadState(io, statePath) : null;
70
+ const comfyuiRoot = root || (st && st.root) || null;
71
+ const resolvedWorker = workerDir
72
+ || (st && st.components && st.components.worker && st.components.worker.dir)
73
+ || null;
74
+ const resolvedPort = port
75
+ || (st && st.comfyui_runtime && st.comfyui_runtime.port)
76
+ || null;
77
+ const found = !!(comfyuiRoot || resolvedWorker || st);
78
+ return {
79
+ state: st,
80
+ comfyuiRoot,
81
+ workerDir: resolvedWorker,
82
+ port: resolvedPort,
83
+ device: st ? st.device : null,
84
+ statePath,
85
+ found,
86
+ };
87
+ }
88
+
89
+ /**
90
+ * Ownership guard for every tool invocation: blocks running as root against
91
+ * a user-owned installation (sudo mixing) and operating on another uid's
92
+ * installation. Same rules, same messages as the installer gates.
93
+ * `currentUid`/`home` overrides exist for deterministic tests; production
94
+ * passes nothing and the real uid/home are used.
95
+ * @returns {{ ok: boolean, violations: object[] }}
96
+ */
97
+ function checkAccess(io, targets, { currentUid = null, home = null } = {}) {
98
+ return prereq.checkOwnership(io, {
99
+ paths: [targets.comfyuiRoot, targets.workerDir, targets.statePath].filter(Boolean),
100
+ home: home !== null ? home : prereq.currentHome(),
101
+ currentUid: currentUid !== null ? currentUid : prereq.currentUid(),
102
+ stateUid: targets.state && targets.state.owner_uid != null ? targets.state.owner_uid : null,
103
+ });
104
+ }
105
+
106
+ /** Extract the --port value from a process cmdline (platform adapter). */
107
+ function readPidPort(io, pid, opts = {}) {
108
+ const parts = adapterOf(opts).readProcessCmdline(io, pid);
109
+ if (parts && Array.isArray(parts)) {
110
+ const i = parts.indexOf('--port');
111
+ if (i !== -1 && parts[i + 1]) return Number(parts[i + 1]);
112
+ }
113
+ return null;
114
+ }
115
+
116
+ // ---------------------------------------------------------------------------
117
+ // status
118
+ // ---------------------------------------------------------------------------
119
+
120
+ /**
121
+ * Snapshot of the managed runtime. Reuses the managed discovery primitives:
122
+ * - Worker: engine/worker.findRunningWorkerPid (cwd-verified)
123
+ * - ComfyUI: engine/comfyui.findManagedComfyUIPids (cwd-verified — a
124
+ * foreign ComfyUI on the same port is NEVER reported as ours)
125
+ * - API: engine/comfyui.systemStats (GET /system_stats)
126
+ * - Queue: GET /queue
127
+ * Never throws on unreachable components — unreachable IS the status.
128
+ */
129
+ async function collectStatus(io, targets, opts = {}) {
130
+ const adapter = adapterOf(opts);
131
+ const workerPid = targets.workerDir
132
+ ? workerMod.findRunningWorkerPid(io, targets.workerDir, { platformAdapter: adapter })
133
+ : null;
134
+ const comfyRootPresent = !!(targets.comfyuiRoot && io.fs.existsSync(targets.comfyuiRoot));
135
+ const comfyPids = comfyRootPresent
136
+ ? comfyui.findManagedComfyUIPids(io, { root: targets.comfyuiRoot, platformAdapter: adapter })
137
+ : [];
138
+ let port = targets.port || null;
139
+ if (comfyPids.length > 0) {
140
+ port = readPidPort(io, comfyPids[0], { platformAdapter: adapter }) || port;
141
+ }
142
+ const baseUrl = port ? `http://127.0.0.1:${port}` : null;
143
+ const stats = baseUrl ? await comfyui.systemStats(io, baseUrl) : null;
144
+ let queue = null;
145
+ if (stats && baseUrl) {
146
+ try {
147
+ const r = await io.http.fetchJson(`${baseUrl}/queue`);
148
+ if (r.status === 200 && r.json && Array.isArray(r.json.queue_running)) {
149
+ queue = {
150
+ running: r.json.queue_running.length,
151
+ pending: (r.json.queue_pending || []).length,
152
+ };
153
+ }
154
+ } catch (_) { /* queue is optional */ }
155
+ }
156
+ return {
157
+ worker: { running: !!workerPid, pid: workerPid || null },
158
+ comfyui: { running: comfyPids.length > 0, root_present: comfyRootPresent, port, pids: comfyPids },
159
+ api: { ok: !!stats },
160
+ queue,
161
+ };
162
+ }
163
+
164
+ /** Render the `Animastor status` block. */
165
+ function renderStatus(snapshot) {
166
+ const ok = '✓';
167
+ const bad = '✗';
168
+ const lines = [];
169
+ lines.push('Animastor status');
170
+ lines.push('');
171
+ lines.push(`Worker: ${snapshot.worker.running ? `${ok} RUNNING` : `${bad} STOPPED`}`);
172
+ lines.push(`ComfyUI: ${snapshot.comfyui.running
173
+ ? `${ok} RUNNING${snapshot.comfyui.port ? ` :${snapshot.comfyui.port}` : ''}`
174
+ : `${bad} STOPPED`}`);
175
+ lines.push(`API: ${snapshot.api.ok ? `${ok} OK` : `${bad} UNREACHABLE`}`);
176
+ if (snapshot.queue) {
177
+ lines.push(`Queue: ${snapshot.queue.running} running / ${snapshot.queue.pending} pending`);
178
+ } else {
179
+ lines.push('Queue: — (API unreachable)');
180
+ }
181
+ return lines.join('\n');
182
+ }
183
+
184
+ /** Exit code for a status snapshot: 0 healthy, 1 degraded. */
185
+ function statusExitCode(snapshot) {
186
+ return snapshot.worker.running && snapshot.comfyui.running && snapshot.api.ok ? 0 : 1;
187
+ }
188
+
189
+ // ---------------------------------------------------------------------------
190
+ // reboot-worker / reboot-comfyui
191
+ // ---------------------------------------------------------------------------
192
+
193
+ /**
194
+ * Restart THIS installation's worker. Managed-only and uid-guarded via
195
+ * engine/worker.restartManagedWorker (no global pkill/killall). Correctly
196
+ * handles the already-stopped case (skips the stop step and just starts).
197
+ * @returns {{ ok: boolean, healthy: boolean, detail: string|null }}
198
+ */
199
+ async function restartWorker(io, targets, { term = null, log = null, stopTimeoutMs = 15000, platformAdapter = null } = {}) {
200
+ const withBusy = (label, fn) => (term ? term.withBusy(label, fn) : fn());
201
+ const withBusySync = (label, fn) => (term ? term.withBusySync(label, fn) : fn());
202
+ const wasRunning = !!workerMod.findRunningWorkerPid(io, targets.workerDir, { platformAdapter });
203
+
204
+ if (wasRunning) {
205
+ await withBusy('Stopping Worker', async () => {
206
+ const stop = await workerMod.stopManagedWorker(io, { workerDir: targets.workerDir, stopTimeoutMs, log, platformAdapter });
207
+ if (!stop.stopped) throw new Error(stop.reason || 'worker could not be stopped');
208
+ return stop;
209
+ });
210
+ }
211
+ const start = withBusySync(wasRunning ? 'Starting Worker' : 'Starting Worker (was stopped)', () =>
212
+ workerMod.startWorker(io, { workerDir: targets.workerDir, log, platformAdapter }));
213
+ if (!start.started) {
214
+ return { ok: false, healthy: false, detail: start.reason || 'worker could not be started' };
215
+ }
216
+ // startWorker already waited the grace period and verified the process is
217
+ // alive (ps args check) — that IS the runtime's worker health check.
218
+ if (!start.alive) {
219
+ return { ok: false, healthy: false, detail: start.reason || 'worker exited immediately — see the worker log' };
220
+ }
221
+ return { ok: true, healthy: true, detail: start.already_running ? 'already running' : null };
222
+ }
223
+
224
+ /**
225
+ * Restart THIS installation's managed ComfyUI. REUSES the installer engine:
226
+ * - running → engine/comfyui.restartManagedComfyUI (managed discovery,
227
+ * uid-guarded via allowedUids, API wait built in);
228
+ * - stopped → engine/comfyui.startComfyUI + waitForApi (the same
229
+ * primitives the installer's verification step uses).
230
+ * @returns {{ ok: boolean, port: number|null, detail: string|null }}
231
+ */
232
+ async function restartComfyUI(io, targets, { term = null, log = null, verifyTimeoutMs = 120000, pollIntervalMs = 2000, platformAdapter = null } = {}) {
233
+ const adapter = adapterOf({ platformAdapter });
234
+ const withBusy = (label, fn) => (term ? term.withBusy(label, fn, { minShowMs: 200 }) : fn());
235
+ if (!targets.comfyuiRoot || !io.fs.existsSync(targets.comfyuiRoot)) {
236
+ return { ok: false, port: null, detail: `ComfyUI root not found${targets.comfyuiRoot ? ` (${targets.comfyuiRoot})` : ''}` };
237
+ }
238
+ const me = prereq.currentUid();
239
+ const allowedUids = me != null ? [me] : null;
240
+ const pids = comfyui.findManagedComfyUIPids(io, { root: targets.comfyuiRoot, platformAdapter: adapter });
241
+ let port = targets.port || null;
242
+ if (pids.length > 0) port = readPidPort(io, pids[0], { platformAdapter: adapter }) || port;
243
+
244
+ if (pids.length > 0) {
245
+ const res = await withBusy('Restarting ComfyUI', () => comfyui.restartManagedComfyUI(io, {
246
+ root: targets.comfyuiRoot,
247
+ port: port || 8188,
248
+ device: targets.device || null,
249
+ log,
250
+ verifyTimeoutMs,
251
+ pollIntervalMs,
252
+ allowedUids,
253
+ platformAdapter: adapter,
254
+ }));
255
+ if (!res.restarted) {
256
+ return { ok: false, port, detail: res.reason || 'managed ComfyUI was not restarted' };
257
+ }
258
+ if (!res.up) {
259
+ return { ok: true, port, detail: res.reason || 'ComfyUI restarted but the API did not come up — see the ComfyUI log', up: false };
260
+ }
261
+ return { ok: true, port, detail: null };
262
+ }
263
+ // stopped → start (same primitives as the installer's start step)
264
+ const res = await withBusy('Starting ComfyUI (was stopped)', async () => {
265
+ const started = comfyui.startComfyUI(io, {
266
+ root: targets.comfyuiRoot,
267
+ port: port || 8188,
268
+ device: targets.device || null,
269
+ platformAdapter: adapter,
270
+ });
271
+ const up = await comfyui.waitForApi(io, `http://127.0.0.1:${started.port}`, { timeoutMs: verifyTimeoutMs, intervalMs: pollIntervalMs });
272
+ return { started, up };
273
+ });
274
+ if (!res.up.ok) {
275
+ return { ok: true, port: res.started.port, detail: res.up.reason, up: false };
276
+ }
277
+ return { ok: true, port: res.started.port, detail: null };
278
+ }
279
+
280
+ // ---------------------------------------------------------------------------
281
+ // comfyui-monitor
282
+ // ---------------------------------------------------------------------------
283
+
284
+ /** Best-effort job kind from a queue entry's prompt graph (never throws). */
285
+ function guessJobKind(queueEntry) {
286
+ try {
287
+ const prompt = queueEntry && queueEntry[2];
288
+ const classes = [];
289
+ if (prompt && typeof prompt === 'object') {
290
+ if (Array.isArray(prompt.nodes)) {
291
+ for (const n of prompt.nodes) if (n && (n.class_type || n.type)) classes.push(String(n.class_type || n.type));
292
+ } else {
293
+ for (const n of Object.values(prompt)) {
294
+ if (n && typeof n === 'object' && n.class_type) classes.push(String(n.class_type));
295
+ }
296
+ }
297
+ }
298
+ const joined = classes.join(' ');
299
+ if (/tts|audio|voice|speech/i.test(joined)) return 'audio generation';
300
+ if (/video|svd|vhs|animate|framepack/i.test(joined)) return 'video generation';
301
+ if (/upscale/i.test(joined)) return 'upscale';
302
+ if (/ksampler|checkpoint|clip|vae|latent|diffusion/i.test(joined)) return 'image generation';
303
+ if (classes.length > 0) return classes[0];
304
+ } catch (_) { /* never */ }
305
+ return 'workflow';
306
+ }
307
+
308
+ function fmtClock(tsMs) {
309
+ try {
310
+ const d = new Date(Number(tsMs));
311
+ if (Number.isNaN(d.getTime())) return null;
312
+ const p = (n) => String(n).padStart(2, '0');
313
+ return `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
314
+ } catch (_) {
315
+ return null;
316
+ }
317
+ }
318
+
319
+ /**
320
+ * Collect monitor data from the ComfyUI API with graceful fallback:
321
+ * - /system_stats down → api.ok=false (monitor still renders, exit 1);
322
+ * - /queue unavailable → queue section omitted;
323
+ * - /history?max_items unavailable → retries plain /history;
324
+ * - running-job duration/progress are not exposed by the supported
325
+ * ComfyUI REST API → rendered as "—", never invented.
326
+ */
327
+ async function collectMonitor(io, targets, { historyMax = 24 } = {}) {
328
+ const port = targets.port || 8188;
329
+ const base = `http://127.0.0.1:${port}`;
330
+ const stats = await comfyui.systemStats(io, base);
331
+
332
+ let queue = null;
333
+ try {
334
+ const r = await io.http.fetchJson(`${base}/queue`);
335
+ if (r.status === 200 && r.json && Array.isArray(r.json.queue_running)) {
336
+ queue = { running: r.json.queue_running || [], pending: r.json.queue_pending || [] };
337
+ }
338
+ } catch (_) { /* optional */ }
339
+
340
+ let history = null;
341
+ try {
342
+ let r = await io.http.fetchJson(`${base}/history?max_items=${historyMax}`);
343
+ if (!(r.status === 200 && r.json)) r = await io.http.fetchJson(`${base}/history`);
344
+ if (r.status === 200 && r.json) history = r.json;
345
+ } catch (_) { /* optional */ }
346
+
347
+ const errors = [];
348
+ if (history && typeof history === 'object') {
349
+ for (const [promptId, entry] of Object.entries(history)) {
350
+ const status = entry && entry.status;
351
+ if (!status || status.status_str !== 'error') continue;
352
+ for (const msg of status.messages || []) {
353
+ const [event, data] = Array.isArray(msg) ? msg : [null, null];
354
+ if (event !== 'execution_error' || !data || typeof data !== 'object') continue;
355
+ errors.push({
356
+ prompt_id: promptId,
357
+ node_type: data.node_type || null,
358
+ message: String(data.exception_message || data.exception_type || 'execution error'),
359
+ timestamp: data.timestamp || null,
360
+ });
361
+ }
362
+ }
363
+ }
364
+ errors.sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0));
365
+
366
+ return {
367
+ port,
368
+ api: { ok: !!stats },
369
+ stats,
370
+ queue,
371
+ errors: errors.slice(0, 5),
372
+ };
373
+ }
374
+
375
+ /** Render the `Animastor ComfyUI Monitor` block. */
376
+ function renderMonitor(data) {
377
+ const ok = '✓';
378
+ const bad = '✗';
379
+ const lines = [];
380
+ lines.push('Animastor ComfyUI Monitor');
381
+ lines.push('────────────────────────────────────');
382
+ lines.push('');
383
+ lines.push(`ComfyUI: ${data.api.ok ? `${ok} RUNNING` : `${bad} NOT RESPONDING`}`);
384
+ lines.push(`API: ${data.api.ok ? `${ok} OK` : `${bad} UNREACHABLE`}`);
385
+ lines.push(`Port: ${data.port}`);
386
+ if (data.stats && data.stats.system && data.stats.system.comfyui_version) {
387
+ lines.push(`Version: ${data.stats.system.comfyui_version}`);
388
+ }
389
+
390
+ if (!data.queue) {
391
+ lines.push('');
392
+ lines.push('Queue — (unavailable)');
393
+ } else {
394
+ const running = data.queue.running || [];
395
+ const pending = data.queue.pending || [];
396
+ lines.push('');
397
+ lines.push('Queue');
398
+ lines.push(` Running: ${running.length}`);
399
+ lines.push(` Pending: ${pending.length}`);
400
+ if (running.length === 0 && pending.length === 0) {
401
+ lines.push(' Status: empty');
402
+ }
403
+
404
+ if (running.length > 0) {
405
+ lines.push('');
406
+ lines.push('Running');
407
+ for (const entry of running.slice(0, 5)) {
408
+ const id = entry && entry[1] ? String(entry[1]) : '?';
409
+ // duration/progress are not exposed by the REST API — shown as "—"
410
+ lines.push(` #${id} ${guessJobKind(entry)} —`);
411
+ }
412
+ }
413
+ if (pending.length > 0) {
414
+ lines.push('');
415
+ lines.push('Pending');
416
+ for (const entry of pending.slice(0, 8)) {
417
+ const id = entry && entry[1] ? String(entry[1]) : '?';
418
+ lines.push(` #${id} ${guessJobKind(entry)} waiting`);
419
+ }
420
+ if (pending.length > 8) lines.push(` … ${pending.length - 8} more`);
421
+ }
422
+ }
423
+
424
+ if (data.errors.length > 0) {
425
+ lines.push('');
426
+ lines.push('Recent errors');
427
+ for (const e of data.errors) {
428
+ const when = e.timestamp ? fmtClock(e.timestamp) : null;
429
+ const head = String(e.message).split('\n')[0].slice(0, 120);
430
+ lines.push(` [${when || '—'}] ${e.node_type || 'node'}: ${head}`);
431
+ }
432
+ }
433
+ return lines.join('\n');
434
+ }
435
+
436
+ // ---------------------------------------------------------------------------
437
+ // Tools installation (installer component)
438
+ // ---------------------------------------------------------------------------
439
+
440
+ /**
441
+ * Render one tool wrapper. The wrapper is a THIN shim: all runtime behaviour
442
+ * lives in the installer CLI (`management.js`), so there is exactly one
443
+ * implementation of discovery/restart logic for installer and tools.
444
+ * Delegates to the platform adapter (#!/bin/sh on Linux, .cmd on Windows).
445
+ */
446
+ function renderToolScript({ command, nodePath, cliPath, statePath, root, workerDir, platformAdapter = null }) {
447
+ return adapterOf({ platformAdapter }).renderToolScript({ command, nodePath, cliPath, statePath, root, workerDir });
448
+ }
449
+
450
+ /**
451
+ * Install (or idempotently refresh) the command-line management tools next
452
+ * to the worker. Re-running the installer overwrites the same files —
453
+ * no duplicates, no broken state. Script filenames/extensions and content
454
+ * are platform-specific (platform adapter).
455
+ * @returns {{ toolsDir, files: string[] }}
456
+ */
457
+ function installManagementTools(io, { toolsDir, nodePath, cliPath, statePath, root, workerDir, log = null, platformAdapter = null }) {
458
+ const adapter = adapterOf({ platformAdapter });
459
+ io.fs.mkdirSync(toolsDir, { recursive: true });
460
+ const files = [];
461
+ for (const t of TOOL_SCRIPTS) {
462
+ const p = path.join(toolsDir, adapter.toolScriptName(t.file));
463
+ io.fs.writeFileSync(p, renderToolScript({
464
+ command: t.command, nodePath, cliPath, statePath, root, workerDir,
465
+ platformAdapter: adapter,
466
+ }));
467
+ io.fs.chmodSync(p, adapter.TOOL_SCRIPT_MODE);
468
+ files.push(p);
469
+ }
470
+ if (log && log.info) log.info(`management tools installed at ${toolsDir} (${files.length} commands)`);
471
+ return { toolsDir, files };
472
+ }
473
+
474
+ module.exports = {
475
+ TOOL_SCRIPTS,
476
+ resolveTargets,
477
+ checkAccess,
478
+ readPidPort,
479
+ collectStatus,
480
+ renderStatus,
481
+ statusExitCode,
482
+ restartWorker,
483
+ restartComfyUI,
484
+ collectMonitor,
485
+ renderMonitor,
486
+ guessJobKind,
487
+ renderToolScript,
488
+ installManagementTools,
489
+ };
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Docker deployment adapter — ARCHITECTURAL PREPARATION ONLY.
5
+ *
6
+ * Docker is a DEPLOYMENT of a platform (linux), never an OS platform: the
7
+ * installer still runs under the linux platform adapter inside the
8
+ * container. This module prepares the deployment-specific touchpoints
9
+ * (container paths, volume mapping, GPU runtime flags, connectivity,
10
+ * lifecycle semantics) WITHOUT declaring docker production-supported.
11
+ *
12
+ * Status: experimental. The setup contract advertises it as Experimental
13
+ * (availability derived from these flags); the VPS E2E passed on CPU
14
+ * (2026-08-31) — the productionReady flag may flip only after the GPU path
15
+ * passes hardware validation.
16
+ */
17
+
18
+ const NAME = 'docker';
19
+
20
+ // In-container layout: everything under a single volume mount so the whole
21
+ // installation survives container replacement.
22
+ const CONTAINER_ROOT = '/data/animastor';
23
+
24
+ module.exports = {
25
+ name: NAME,
26
+ displayName: 'Docker (experimental)',
27
+ productionReady: false, // NOT production-supported until VPS-validated
28
+ experimental: true,
29
+ requiresPlatform: 'linux',
30
+
31
+ /** Container paths (inside the container, all under one volume). */
32
+ paths: {
33
+ root: `${CONTAINER_ROOT}/comfyui`,
34
+ workerDir: `${CONTAINER_ROOT}/worker`,
35
+ toolsDir: `${CONTAINER_ROOT}/tools`,
36
+ stateDir: `${CONTAINER_ROOT}/state`,
37
+ data: CONTAINER_ROOT,
38
+ },
39
+
40
+ /**
41
+ * Suggested volume mapping (host → container) for the reference image.
42
+ * The engine never invents host paths; this is documentation for the
43
+ * future docker integration test / compose file.
44
+ */
45
+ volumeMap() {
46
+ return [
47
+ { host: '~/animastor/data', container: CONTAINER_ROOT },
48
+ ];
49
+ },
50
+
51
+ /** GPU runtime requirements for the container runtime. */
52
+ gpuRuntime: {
53
+ flag: '--gpus all',
54
+ note: 'NVIDIA Container Toolkit must be installed on the host; the container sees the GPU through nvidia-smi as usual.',
55
+ },
56
+
57
+ /**
58
+ * Lifecycle: processes are owned by the CONTAINER, not by the installer.
59
+ * stop/restart of the installation inside the container stays valid
60
+ * (uid-guarded process management), but container start/stop/restart is
61
+ * the orchestrator's job (docker stop/restart), never the installer's.
62
+ */
63
+ lifecycle: 'container',
64
+
65
+ /** Connectivity: worker↔ComfyUI on loopback inside the container. */
66
+ connectivity: {
67
+ comfyuiBase: (port) => `http://127.0.0.1:${port}`,
68
+ note: 'The worker only makes OUTBOUND calls to the hub — no inbound ports are required (publish nothing).',
69
+ },
70
+
71
+ /**
72
+ * Path mapping for the engine: roots inside the container follow the
73
+ * container layout when the caller did not pin explicit paths.
74
+ */
75
+ mapPath(p) {
76
+ return p;
77
+ },
78
+ };
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Native deployment adapter — the default: components run directly on the
5
+ * host OS (detached daemons, files under the user's home). This is what the
6
+ * installer has always done on Linux; the module exists so the engine can
7
+ * ask for deployment behaviour explicitly instead of assuming it.
8
+ */
9
+
10
+ const NAME = 'native';
11
+
12
+ module.exports = {
13
+ name: NAME,
14
+ displayName: 'Native',
15
+ productionReady: true,
16
+
17
+ /**
18
+ * Paths used as-is: the roots the user/CLI chose are the real roots.
19
+ * (A container deployment would remap these to volume targets.)
20
+ */
21
+ mapPath(p) {
22
+ return p;
23
+ },
24
+
25
+ /**
26
+ * Service start/stop/restart are plain detached processes owned by the
27
+ * installer (see engine/comfyui.js and engine/worker.js) — no container
28
+ * lifecycle layer involved.
29
+ */
30
+ lifecycle: 'process',
31
+
32
+ /** Connectivity assumptions: everything on loopback of the same host. */
33
+ connectivity: {
34
+ comfyuiBase: (port) => `http://127.0.0.1:${port}`,
35
+ },
36
+ };