@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.
- package/LICENSE +21 -0
- package/README.md +66 -0
- package/ai/install-manifests/audio/qwen-tts.json +445 -0
- package/ai/install-manifests/image/qwen-image.json +465 -0
- package/ai/install-manifests/video/ltx-2.3.json +892 -0
- package/package.json +42 -0
- package/src/installer/cli.js +1067 -0
- package/src/installer/compatibility-resolver.js +1287 -0
- package/src/installer/download-planner.js +172 -0
- package/src/installer/engine/comfyui.js +508 -0
- package/src/installer/engine/downloader.js +514 -0
- package/src/installer/engine/engine.js +1180 -0
- package/src/installer/engine/io.js +437 -0
- package/src/installer/engine/logger.js +75 -0
- package/src/installer/engine/nodes.js +146 -0
- package/src/installer/engine/prereq.js +399 -0
- package/src/installer/engine/probe.js +349 -0
- package/src/installer/engine/progress.js +350 -0
- package/src/installer/engine/state.js +170 -0
- package/src/installer/engine/term.js +298 -0
- package/src/installer/engine/worker.js +430 -0
- package/src/installer/engine/workflows.js +153 -0
- package/src/installer/index.js +40 -0
- package/src/installer/install-manifest.js +376 -0
- package/src/installer/install-plan.js +741 -0
- package/src/installer/management.js +489 -0
- package/src/installer/platform/deployment/docker.js +78 -0
- package/src/installer/platform/deployment/native.js +36 -0
- package/src/installer/platform/index.js +165 -0
- package/src/installer/platform/linux.js +341 -0
- package/src/installer/platform/windows.js +360 -0
- package/src/installer/safety-rules.js +156 -0
- package/src/installer/setup-contract.js +1401 -0
- package/src/installer/uninstaller.js +572 -0
- package/src/installer/verification-report.js +220 -0
- package/src/installer/worker-bundle-source.js +64 -0
- package/src/installer/workflow-artifacts.js +152 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* IO layer — Private Worker Installer Phase 2.
|
|
5
|
+
*
|
|
6
|
+
* Every side effect the installation engine performs goes through an `io`
|
|
7
|
+
* object. Production uses createRealIo(); tests inject a mock; --dry-run
|
|
8
|
+
* wraps the real io with a mutation guard that throws on any write.
|
|
9
|
+
*
|
|
10
|
+
* The engine itself is pure orchestration: given the same io behavior it is
|
|
11
|
+
* fully deterministic and testable without network, GPU, or real downloads.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const crypto = require('crypto');
|
|
17
|
+
const { spawnSync, spawn } = require('child_process');
|
|
18
|
+
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Real IO
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
function createRealIo() {
|
|
24
|
+
return {
|
|
25
|
+
fs: {
|
|
26
|
+
existsSync: (p) => fs.existsSync(p),
|
|
27
|
+
isDirectory: (p) => fs.existsSync(p) && fs.statSync(p).isDirectory(),
|
|
28
|
+
readFileSync: (p, enc) => fs.readFileSync(p, enc),
|
|
29
|
+
writeFileSync: (p, data, opts) => fs.writeFileSync(p, data, opts),
|
|
30
|
+
appendFileSync: (p, data) => fs.appendFileSync(p, data),
|
|
31
|
+
mkdirSync: (p, opts) => fs.mkdirSync(p, opts),
|
|
32
|
+
renameSync: (a, b) => fs.renameSync(a, b),
|
|
33
|
+
unlinkSync: (p) => fs.unlinkSync(p),
|
|
34
|
+
/** Recursive directory/file removal (uninstaller). */
|
|
35
|
+
rmSync: (p, opts = { recursive: true, force: true }) => fs.rmSync(p, opts),
|
|
36
|
+
rmdirSync: (p) => fs.rmdirSync(p),
|
|
37
|
+
copyFileSync: (a, b) => fs.copyFileSync(a, b),
|
|
38
|
+
chmodSync: (p, mode) => fs.chmodSync(p, mode),
|
|
39
|
+
statSync: (p) => {
|
|
40
|
+
const s = fs.statSync(p);
|
|
41
|
+
return { size: s.size, isFile: s.isFile(), isDirectory: s.isDirectory(), uid: s.uid, gid: s.gid };
|
|
42
|
+
},
|
|
43
|
+
readdirSync: (p) => fs.readdirSync(p),
|
|
44
|
+
readlinkSync: (p) => fs.readlinkSync(p),
|
|
45
|
+
},
|
|
46
|
+
/** Synchronous command execution (git, pip, npm, nvidia-smi…). */
|
|
47
|
+
exec(command, args = [], opts = {}) {
|
|
48
|
+
const r = spawnSync(command, args, {
|
|
49
|
+
cwd: opts.cwd,
|
|
50
|
+
env: opts.env || process.env,
|
|
51
|
+
encoding: 'utf8',
|
|
52
|
+
timeout: opts.timeout || 10 * 60 * 1000,
|
|
53
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
54
|
+
input: opts.input,
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
code: r.status === null ? -1 : r.status,
|
|
58
|
+
stdout: r.stdout || '',
|
|
59
|
+
stderr: r.stderr || '',
|
|
60
|
+
error: r.error ? String(r.error.message || r.error) : null,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Asynchronous command execution — same result shape as exec(), but
|
|
65
|
+
* the Node event loop stays free, so the terminal busy spinner keeps
|
|
66
|
+
* animating while a long pip/npm/git step runs. Used for the slow
|
|
67
|
+
* steps (pip install requirements/torch, …).
|
|
68
|
+
*
|
|
69
|
+
* Options: { cwd, env, timeout, onLine }.
|
|
70
|
+
* `onLine(line)` receives COMPLETE output lines as they are produced
|
|
71
|
+
* (both streams), with carriage-return progress-bar redraws filtered
|
|
72
|
+
* out — useful output (Collecting/Installing/Successfully…) can be
|
|
73
|
+
* surfaced through the terminal renderer while the full raw output is
|
|
74
|
+
* still captured for diagnostics and error messages.
|
|
75
|
+
*/
|
|
76
|
+
async execAsync(command, args = [], opts = {}) {
|
|
77
|
+
const { cwd, env, timeout = 10 * 60 * 1000, onLine = null } = opts;
|
|
78
|
+
return await new Promise((resolve) => {
|
|
79
|
+
let child;
|
|
80
|
+
try {
|
|
81
|
+
child = spawn(command, args, { cwd, env: env || process.env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
82
|
+
} catch (err) {
|
|
83
|
+
resolve({ code: -1, stdout: '', stderr: '', error: String(err.message || err) });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
let stdout = '';
|
|
87
|
+
let stderr = '';
|
|
88
|
+
let outBuf = '';
|
|
89
|
+
let errBuf = '';
|
|
90
|
+
let settled = false;
|
|
91
|
+
let timedOut = false;
|
|
92
|
+
|
|
93
|
+
const emitLines = (bufferKey, chunk) => {
|
|
94
|
+
let buf = bufferKey === 'out' ? outBuf : errBuf;
|
|
95
|
+
buf += chunk;
|
|
96
|
+
const parts = buf.split('\n');
|
|
97
|
+
buf = parts.pop(); // last (possibly incomplete) segment stays buffered
|
|
98
|
+
for (const line of parts) {
|
|
99
|
+
if (onLine && !line.includes('\r')) onLine(line);
|
|
100
|
+
}
|
|
101
|
+
if (bufferKey === 'out') outBuf = buf; else errBuf = buf;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const timer = setTimeout(() => {
|
|
105
|
+
timedOut = true;
|
|
106
|
+
try { child.kill('SIGTERM'); } catch (_) { /* already gone */ }
|
|
107
|
+
}, timeout);
|
|
108
|
+
|
|
109
|
+
const finish = (code, error = null) => {
|
|
110
|
+
if (settled) return;
|
|
111
|
+
settled = true;
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
resolve({
|
|
114
|
+
code,
|
|
115
|
+
stdout,
|
|
116
|
+
stderr,
|
|
117
|
+
error: timedOut ? `timed out after ${timeout} ms` : error,
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
child.stdout.setEncoding('utf8');
|
|
122
|
+
child.stdout.on('data', (chunk) => {
|
|
123
|
+
stdout += chunk;
|
|
124
|
+
emitLines('out', chunk);
|
|
125
|
+
});
|
|
126
|
+
child.stderr.setEncoding('utf8');
|
|
127
|
+
child.stderr.on('data', (chunk) => {
|
|
128
|
+
stderr += chunk;
|
|
129
|
+
emitLines('err', chunk);
|
|
130
|
+
});
|
|
131
|
+
child.on('error', (err) => finish(-1, String(err.message || err)));
|
|
132
|
+
child.on('close', (code) => {
|
|
133
|
+
// flush trailing lines that were not newline-terminated
|
|
134
|
+
if (onLine) {
|
|
135
|
+
if (outBuf !== '' && !outBuf.includes('\r')) onLine(outBuf);
|
|
136
|
+
if (errBuf !== '' && !errBuf.includes('\r')) onLine(errBuf);
|
|
137
|
+
outBuf = '';
|
|
138
|
+
errBuf = '';
|
|
139
|
+
}
|
|
140
|
+
finish(code === null ? -1 : code);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
/** Detached long-running process (ComfyUI server). Returns pid. */
|
|
145
|
+
spawnDaemon(command, args = [], opts = {}) {
|
|
146
|
+
const out = opts.logFile
|
|
147
|
+
? fs.openSync(opts.logFile, 'a')
|
|
148
|
+
: 'ignore';
|
|
149
|
+
const child = spawn(command, args, {
|
|
150
|
+
cwd: opts.cwd,
|
|
151
|
+
env: opts.env || process.env,
|
|
152
|
+
detached: true,
|
|
153
|
+
stdio: ['ignore', out, out],
|
|
154
|
+
});
|
|
155
|
+
child.unref();
|
|
156
|
+
return child.pid;
|
|
157
|
+
},
|
|
158
|
+
/** Signal a process by pid (used to restart the managed ComfyUI). */
|
|
159
|
+
kill(pid, signal = 'SIGTERM') {
|
|
160
|
+
process.kill(pid, signal);
|
|
161
|
+
},
|
|
162
|
+
/** Global fetch (Node 20+). */
|
|
163
|
+
fetch: (url, opts) => fetch(url, opts),
|
|
164
|
+
http: {
|
|
165
|
+
/**
|
|
166
|
+
* Stream-download a URL to dest. If appendFrom>0, request an HTTP
|
|
167
|
+
* Range and append (resumed=true when the server honors it with
|
|
168
|
+
* 206; otherwise the file is restarted from scratch).
|
|
169
|
+
* Returns { status, bytes, total, resumed, error? }.
|
|
170
|
+
*/
|
|
171
|
+
async download({ url, dest, appendFrom = 0, headers = {}, onProgress = null }) {
|
|
172
|
+
const h = { ...headers };
|
|
173
|
+
if (appendFrom > 0) h.Range = `bytes=${appendFrom}-`;
|
|
174
|
+
const res = await fetch(url, { headers: h, redirect: 'follow' });
|
|
175
|
+
if (!(res.status === 200 || res.status === 206 || res.status === 416)) {
|
|
176
|
+
let body = '';
|
|
177
|
+
try { body = (await res.text()).slice(0, 300); } catch (_) { /* ignore */ }
|
|
178
|
+
return { status: res.status, bytes: 0, total: null, resumed: false, error: body };
|
|
179
|
+
}
|
|
180
|
+
if (res.status === 416) {
|
|
181
|
+
return { status: 416, bytes: 0, total: null, resumed: false };
|
|
182
|
+
}
|
|
183
|
+
const resumed = res.status === 206 && appendFrom > 0;
|
|
184
|
+
const totalHeader = res.headers.get('content-range') || res.headers.get('content-length');
|
|
185
|
+
let total = null;
|
|
186
|
+
if (totalHeader) {
|
|
187
|
+
const m = /\/(\d+)$/.exec(String(totalHeader));
|
|
188
|
+
total = m ? Number(m[1]) : Number(totalHeader) + (resumed ? appendFrom : 0);
|
|
189
|
+
}
|
|
190
|
+
let received = resumed ? appendFrom : 0;
|
|
191
|
+
await new Promise((resolve, reject) => {
|
|
192
|
+
const out = fs.createWriteStream(dest, { flags: resumed ? 'a' : 'w' });
|
|
193
|
+
(async () => {
|
|
194
|
+
try {
|
|
195
|
+
const reader = res.body.getReader();
|
|
196
|
+
for (;;) {
|
|
197
|
+
const { done, value } = await reader.read();
|
|
198
|
+
if (done) break;
|
|
199
|
+
out.write(Buffer.from(value));
|
|
200
|
+
received += value.byteLength;
|
|
201
|
+
if (onProgress) onProgress({ received, total });
|
|
202
|
+
}
|
|
203
|
+
out.end();
|
|
204
|
+
out.on('finish', resolve);
|
|
205
|
+
out.on('error', reject);
|
|
206
|
+
} catch (err) {
|
|
207
|
+
out.destroy();
|
|
208
|
+
reject(err);
|
|
209
|
+
}
|
|
210
|
+
})();
|
|
211
|
+
});
|
|
212
|
+
return { status: res.status, bytes: received, total, resumed };
|
|
213
|
+
},
|
|
214
|
+
async fetchJson(url, opts = {}) {
|
|
215
|
+
const res = await fetch(url, opts);
|
|
216
|
+
let json = null;
|
|
217
|
+
try { json = await res.json(); } catch (_) { /* non-json body */ }
|
|
218
|
+
return { status: res.status, json };
|
|
219
|
+
},
|
|
220
|
+
async fetchText(url, opts = {}) {
|
|
221
|
+
const res = await fetch(url, opts);
|
|
222
|
+
return { status: res.status, text: await res.text().catch(() => '') };
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
/** Streaming sha256 of a file (never loads whole multi-GB files). */
|
|
226
|
+
async hashFile(filePath, algo = 'sha256') {
|
|
227
|
+
return new Promise((resolve, reject) => {
|
|
228
|
+
const hash = crypto.createHash(algo);
|
|
229
|
+
const stream = fs.createReadStream(filePath);
|
|
230
|
+
stream.on('data', (d) => hash.update(d));
|
|
231
|
+
stream.on('end', () => resolve(hash.digest('hex')));
|
|
232
|
+
stream.on('error', reject);
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
now: () => Date.now(),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
// In-memory FS (tests, and a safe sandbox for unit-running the engine)
|
|
241
|
+
// ---------------------------------------------------------------------------
|
|
242
|
+
|
|
243
|
+
function createMemoryFs(initial = {}) {
|
|
244
|
+
const files = new Map(); // path -> { data: Buffer|string, mode }
|
|
245
|
+
const dirs = new Set(['/']);
|
|
246
|
+
for (const [p, data] of Object.entries(initial)) {
|
|
247
|
+
files.set(norm(p), { data, mode: 0o644 });
|
|
248
|
+
let d = path.dirname(norm(p));
|
|
249
|
+
// guard: dirname('.') === '.' on POSIX (a Windows-style path with no
|
|
250
|
+
// posix separator) — the loop must always make progress
|
|
251
|
+
while (d && d !== '/' && d !== path.dirname(d)) { dirs.add(d); d = path.dirname(d); }
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function norm(p) {
|
|
255
|
+
// Backslashes are normalized to slashes so the in-memory fs can be
|
|
256
|
+
// used as a cross-platform test double (Windows-style paths in
|
|
257
|
+
// platform-adapter tests behave exactly like POSIX ones).
|
|
258
|
+
return path.posix.normalize(String(p).replace(/\\/g, '/'));
|
|
259
|
+
}
|
|
260
|
+
function assertParent(p) {
|
|
261
|
+
const d = path.dirname(norm(p));
|
|
262
|
+
if (d !== '/' && !dirs.has(d)) throw Object.assign(new Error(`ENOENT: no such directory ${d}`), { code: 'ENOENT' });
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
_files: files,
|
|
267
|
+
_dirs: dirs,
|
|
268
|
+
existsSync: (p) => files.has(norm(p)) || dirs.has(norm(p)),
|
|
269
|
+
isDirectory: (p) => dirs.has(norm(p)),
|
|
270
|
+
readFileSync: (p) => {
|
|
271
|
+
const f = files.get(norm(p));
|
|
272
|
+
if (!f) throw Object.assign(new Error(`ENOENT: ${p}`), { code: 'ENOENT' });
|
|
273
|
+
return typeof f.data === 'string' ? f.data : Buffer.from(f.data).toString('utf8');
|
|
274
|
+
},
|
|
275
|
+
readBufferSync(p) {
|
|
276
|
+
const f = files.get(norm(p));
|
|
277
|
+
if (!f) throw Object.assign(new Error(`ENOENT: ${p}`), { code: 'ENOENT' });
|
|
278
|
+
return Buffer.from(f.data);
|
|
279
|
+
},
|
|
280
|
+
writeFileSync: (p, data) => { assertParent(p); files.set(norm(p), { data, mode: 0o644 }); },
|
|
281
|
+
appendFileSync: (p, data) => {
|
|
282
|
+
assertParent(p);
|
|
283
|
+
const cur = files.has(norm(p)) ? files.get(norm(p)).data : '';
|
|
284
|
+
files.set(norm(p), { data: String(cur) + String(data), mode: 0o644 });
|
|
285
|
+
},
|
|
286
|
+
mkdirSync: (p, opts) => {
|
|
287
|
+
const target = norm(p);
|
|
288
|
+
if (opts && opts.recursive) {
|
|
289
|
+
let d = target;
|
|
290
|
+
const stack = [];
|
|
291
|
+
while (d && d !== '/' && !dirs.has(d)) { stack.push(d); d = path.dirname(d); }
|
|
292
|
+
for (const dd of stack.reverse()) dirs.add(dd);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
assertParent(p);
|
|
296
|
+
dirs.add(target);
|
|
297
|
+
},
|
|
298
|
+
renameSync: (a, b) => {
|
|
299
|
+
const na = norm(a);
|
|
300
|
+
const nb = norm(b);
|
|
301
|
+
const f = files.get(na);
|
|
302
|
+
if (f) {
|
|
303
|
+
assertParent(b);
|
|
304
|
+
files.set(nb, f);
|
|
305
|
+
files.delete(na);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
// directory rename (real-fs semantics): move the dir and every
|
|
309
|
+
// entry beneath it
|
|
310
|
+
if (dirs.has(na)) {
|
|
311
|
+
assertParent(b);
|
|
312
|
+
const prefix = `${na}/`;
|
|
313
|
+
for (const key of [...files.keys()]) {
|
|
314
|
+
if (key.startsWith(prefix)) {
|
|
315
|
+
files.set(nb + key.slice(na.length), files.get(key));
|
|
316
|
+
files.delete(key);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
for (const key of [...dirs]) {
|
|
320
|
+
if (key === na || key.startsWith(prefix)) {
|
|
321
|
+
dirs.add(nb + key.slice(na.length));
|
|
322
|
+
dirs.delete(key);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
throw Object.assign(new Error(`ENOENT: ${a}`), { code: 'ENOENT' });
|
|
328
|
+
},
|
|
329
|
+
unlinkSync: (p) => {
|
|
330
|
+
if (!files.has(norm(p))) throw Object.assign(new Error(`ENOENT: ${p}`), { code: 'ENOENT' });
|
|
331
|
+
files.delete(norm(p));
|
|
332
|
+
},
|
|
333
|
+
/** Recursive removal: deletes a dir and everything under it. */
|
|
334
|
+
rmSync: (p, opts = {}) => {
|
|
335
|
+
const target = norm(p);
|
|
336
|
+
const isDir = dirs.has(target);
|
|
337
|
+
const isFile = files.has(target);
|
|
338
|
+
if (!isDir && !isFile) {
|
|
339
|
+
if (opts && opts.force) return;
|
|
340
|
+
throw Object.assign(new Error(`ENOENT: ${p}`), { code: 'ENOENT' });
|
|
341
|
+
}
|
|
342
|
+
const prefix = target === '/' ? '/' : `${target}/`;
|
|
343
|
+
for (const key of [...files.keys()]) {
|
|
344
|
+
if (key === target || key.startsWith(prefix)) files.delete(key);
|
|
345
|
+
}
|
|
346
|
+
if (isDir) {
|
|
347
|
+
for (const key of [...dirs]) {
|
|
348
|
+
if (key === target || key.startsWith(prefix)) dirs.delete(key);
|
|
349
|
+
}
|
|
350
|
+
} else if (opts && opts.force) {
|
|
351
|
+
// nothing else to do for a file
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
rmdirSync: (p) => {
|
|
355
|
+
const target = norm(p);
|
|
356
|
+
if (!dirs.has(target)) throw Object.assign(new Error(`ENOENT: ${p}`), { code: 'ENOENT' });
|
|
357
|
+
const prefix = `${target}/`;
|
|
358
|
+
const hasChildren = [...files.keys(), ...dirs].some((k) => k !== target && k.startsWith(prefix));
|
|
359
|
+
if (hasChildren) throw Object.assign(new Error(`ENOTEMPTY: ${p}`), { code: 'ENOTEMPTY' });
|
|
360
|
+
dirs.delete(target);
|
|
361
|
+
},
|
|
362
|
+
copyFileSync: (a, b) => {
|
|
363
|
+
const f = files.get(norm(a));
|
|
364
|
+
if (!f) throw Object.assign(new Error(`ENOENT: ${a}`), { code: 'ENOENT' });
|
|
365
|
+
assertParent(b);
|
|
366
|
+
files.set(norm(b), { ...f });
|
|
367
|
+
},
|
|
368
|
+
chmodSync: (p, mode) => {
|
|
369
|
+
const f = files.get(norm(p));
|
|
370
|
+
if (f) f.mode = mode;
|
|
371
|
+
},
|
|
372
|
+
statSync: (p) => {
|
|
373
|
+
const f = files.get(norm(p));
|
|
374
|
+
if (f) return { size: Buffer.byteLength(f.data), isFile: true, isDirectory: false };
|
|
375
|
+
if (dirs.has(norm(p))) return { size: 0, isFile: false, isDirectory: true };
|
|
376
|
+
throw Object.assign(new Error(`ENOENT: ${p}`), { code: 'ENOENT' });
|
|
377
|
+
},
|
|
378
|
+
readdirSync: (p) => {
|
|
379
|
+
const target = norm(p);
|
|
380
|
+
if (!dirs.has(target)) throw Object.assign(new Error(`ENOENT: ${p}`), { code: 'ENOENT' });
|
|
381
|
+
const out = new Set();
|
|
382
|
+
const prefix = target === '/' ? '/' : `${target}/`;
|
|
383
|
+
for (const key of [...files.keys(), ...dirs]) {
|
|
384
|
+
if (key !== target && key.startsWith(prefix)) {
|
|
385
|
+
out.add(key.slice(prefix.length).split('/')[0]);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return Array.from(out).sort();
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Wrap an io so that ANY mutation throws. Used for --dry-run and for the
|
|
395
|
+
* "zero mutations" test invariant. Reads and prompts stay allowed.
|
|
396
|
+
*/
|
|
397
|
+
function createDryRunIo(io) {
|
|
398
|
+
const guard = (name) => () => {
|
|
399
|
+
throw new Error(`dry-run violation: attempted mutating operation "${name}"`);
|
|
400
|
+
};
|
|
401
|
+
return {
|
|
402
|
+
...io,
|
|
403
|
+
fs: {
|
|
404
|
+
existsSync: io.fs.existsSync,
|
|
405
|
+
isDirectory: io.fs.isDirectory,
|
|
406
|
+
readFileSync: io.fs.readFileSync,
|
|
407
|
+
statSync: io.fs.statSync,
|
|
408
|
+
readdirSync: io.fs.readdirSync,
|
|
409
|
+
writeFileSync: guard('fs.writeFileSync'),
|
|
410
|
+
appendFileSync: guard('fs.appendFileSync'),
|
|
411
|
+
mkdirSync: guard('fs.mkdirSync'),
|
|
412
|
+
renameSync: guard('fs.renameSync'),
|
|
413
|
+
unlinkSync: guard('fs.unlinkSync'),
|
|
414
|
+
rmSync: guard('fs.rmSync'),
|
|
415
|
+
rmdirSync: guard('fs.rmdirSync'),
|
|
416
|
+
copyFileSync: guard('fs.copyFileSync'),
|
|
417
|
+
chmodSync: guard('fs.chmodSync'),
|
|
418
|
+
},
|
|
419
|
+
exec: guard('exec'),
|
|
420
|
+
spawnDaemon: guard('spawnDaemon'),
|
|
421
|
+
kill: guard('kill'),
|
|
422
|
+
fetch: guard('fetch'),
|
|
423
|
+
http: {
|
|
424
|
+
download: guard('http.download'),
|
|
425
|
+
fetchJson: guard('http.fetchJson'),
|
|
426
|
+
fetchText: guard('http.fetchText'),
|
|
427
|
+
},
|
|
428
|
+
hashFile: io.hashFile, // read-only — allowed in dry-run
|
|
429
|
+
dryRun: true,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
module.exports = {
|
|
434
|
+
createRealIo,
|
|
435
|
+
createMemoryFs,
|
|
436
|
+
createDryRunIo,
|
|
437
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Logger — Private Worker Installer Phase 2.
|
|
5
|
+
*
|
|
6
|
+
* Diagnostic logging with step/duration tracking and a hard secret-redaction
|
|
7
|
+
* layer. Every line that leaves the logger passes through redaction:
|
|
8
|
+
* - registered secret VALUES (Worker Key, HF token…) are scrubbed;
|
|
9
|
+
* - KEY=value assignments of secret-looking names are masked.
|
|
10
|
+
* The Worker Key and download tokens are registered here the moment they are
|
|
11
|
+
* entered and are never logged, stored in state, or put in reports.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const { redactSecrets, isSecretName } = require('../safety-rules');
|
|
15
|
+
|
|
16
|
+
function createLogger({ io, sink = null, quiet = false } = {}) {
|
|
17
|
+
const secrets = new Set();
|
|
18
|
+
const lines = [];
|
|
19
|
+
|
|
20
|
+
function emit(level, msg) {
|
|
21
|
+
const safe = redact(String(msg), secrets);
|
|
22
|
+
const ts = new Date(io.now()).toISOString();
|
|
23
|
+
const line = `[${ts}] [${level}] ${safe}`;
|
|
24
|
+
lines.push(line);
|
|
25
|
+
if (!quiet) {
|
|
26
|
+
if (sink) sink(line);
|
|
27
|
+
else console.log(line); // eslint-disable-line no-console
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function redact(text, secretSet) {
|
|
32
|
+
let out = redactSecrets(text, Array.from(secretSet));
|
|
33
|
+
// belt & braces: mask any wrk.<id>.<secret> shaped token
|
|
34
|
+
out = out.replace(/wrk\.[A-Za-z0-9_-]+\.[A-Za-z0-9._-]+/g, (m) => {
|
|
35
|
+
const parts = m.split('.');
|
|
36
|
+
return `wrk.${parts[1]}.<REDACTED>`;
|
|
37
|
+
});
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
/** Register a secret value for redaction from ALL further output. */
|
|
43
|
+
registerSecret(value) {
|
|
44
|
+
if (value) secrets.add(String(value));
|
|
45
|
+
},
|
|
46
|
+
/** Redact secrets from a string WITHOUT logging it — used when
|
|
47
|
+
* subprocess output lines are surfaced through the terminal. */
|
|
48
|
+
scrub: (msg) => redact(String(msg), secrets),
|
|
49
|
+
info: (msg) => emit('INFO', msg),
|
|
50
|
+
warn: (msg) => emit('WARN', msg),
|
|
51
|
+
error: (msg) => emit('ERROR', msg),
|
|
52
|
+
/** Raw user-facing output (plan text, reports) — still redacted. */
|
|
53
|
+
output: (msg) => emit('OUT', msg),
|
|
54
|
+
/**
|
|
55
|
+
* Run fn inside a named step; logs start, result and duration.
|
|
56
|
+
* Returns { ok, value|error, ms }.
|
|
57
|
+
*/
|
|
58
|
+
async step(name, fn) {
|
|
59
|
+
emit('STEP', `${name} — started`);
|
|
60
|
+
const t0 = io.now();
|
|
61
|
+
try {
|
|
62
|
+
const value = await fn();
|
|
63
|
+
emit('STEP', `${name} — done (${io.now() - t0} ms)`);
|
|
64
|
+
return { ok: true, value, ms: io.now() - t0 };
|
|
65
|
+
} catch (err) {
|
|
66
|
+
emit('STEP', `${name} — FAILED (${io.now() - t0} ms): ${err && err.message ? err.message : err}`);
|
|
67
|
+
return { ok: false, error: err, ms: io.now() - t0 };
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
lines,
|
|
71
|
+
isSecretName,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { createLogger };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Custom node installation — Private Worker Installer Phase 2.
|
|
5
|
+
*
|
|
6
|
+
* Per required node:
|
|
7
|
+
* 1. check presence (the resolver already did; the engine re-checks);
|
|
8
|
+
* 2. if missing — git clone from the canonical manifest source;
|
|
9
|
+
* 3. pin the manifest revision when one is declared;
|
|
10
|
+
* 4. install the node's Python dependencies (requirements.txt) if present;
|
|
11
|
+
* 5. re-check presence.
|
|
12
|
+
*
|
|
13
|
+
* Already-installed compatible nodes are KEPT — never reinstalled without
|
|
14
|
+
* need. Incompatible nodes stop their step pending a user decision; no
|
|
15
|
+
* destructive replacement happens automatically.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
function findManifestDep(manifests, depId) {
|
|
21
|
+
for (const m of manifests) {
|
|
22
|
+
const dep = (m.dependencies || []).find((d) => d.id === depId);
|
|
23
|
+
if (dep) return dep;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Node python deps are installed with the runtime's torch constraint:
|
|
30
|
+
* requirements.txt carries UNPINNED torch edges — without a constraint pip
|
|
31
|
+
* would happily REPLACE the installed (CPU-flavored) torch with the newest
|
|
32
|
+
* CUDA build from PyPI (a multi-GB download that breaks a CPU-only host).
|
|
33
|
+
* Idempotent: pip skips already-satisfied requirements.
|
|
34
|
+
*/
|
|
35
|
+
function pipInstallRequirements(io, { root, reqPath, python, torchSpec, log = null }) {
|
|
36
|
+
const args = ['-m', 'pip', 'install', '-r', reqPath];
|
|
37
|
+
if (torchSpec && torchSpec.pin) {
|
|
38
|
+
const constraintFile = path.join(root, 'venv', '.animastor-torch-constraints.txt');
|
|
39
|
+
io.fs.writeFileSync(constraintFile, `torch==${String(torchSpec.pin).split('+')[0]}\n`);
|
|
40
|
+
args.push('-c', constraintFile);
|
|
41
|
+
}
|
|
42
|
+
const r = io.exec(python, args, { timeout: 60 * 60 * 1000 });
|
|
43
|
+
if (r.code !== 0) {
|
|
44
|
+
if (log) log.warn(`pip install -r requirements.txt failed: ${String(r.stderr).slice(-300)}`);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Install one missing custom node.
|
|
52
|
+
* `origin` distinguishes what the installer actually created ('installed')
|
|
53
|
+
* from what was already on disk ('pre-existing') — the uninstaller removes
|
|
54
|
+
* only 'installed' directories.
|
|
55
|
+
* `retryDeps` re-runs pip for an ALREADY-present node whose python
|
|
56
|
+
* dependencies were left incomplete by an earlier run (idempotent; needed
|
|
57
|
+
* because the resolver keys node presence off the directory, so without a
|
|
58
|
+
* retry a broken deps state would never heal).
|
|
59
|
+
* @returns {{ status: 'installed'|'blocked'|'failed', origin?, reason?, directory? }}
|
|
60
|
+
*/
|
|
61
|
+
function installCustomNode(io, { root, dep, python = null, torchSpec = null, retryDeps = false, log = null }) {
|
|
62
|
+
const src = (dep.install && dep.install.source) || {};
|
|
63
|
+
const dirName = (dep.install && dep.install.directory) || dep.name;
|
|
64
|
+
const target = path.join(root, 'custom_nodes', dirName);
|
|
65
|
+
|
|
66
|
+
if (!src.repository) {
|
|
67
|
+
return {
|
|
68
|
+
status: 'blocked',
|
|
69
|
+
reason: `no canonical repository for ${dep.id} in the manifest — the installer never invents sources (D4 research pending)`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (io.fs.existsSync(target)) {
|
|
74
|
+
// present — the resolver decides compatibility; the engine does not
|
|
75
|
+
// replace an existing node automatically. Only the python deps may
|
|
76
|
+
// be completed (pip is idempotent and never removes anything).
|
|
77
|
+
if (retryDeps && python) {
|
|
78
|
+
const req = path.join(target, 'requirements.txt');
|
|
79
|
+
if (io.fs.existsSync(req) && pipInstallRequirements(io, { root, reqPath: req, python, torchSpec, log })) {
|
|
80
|
+
return { status: 'installed', origin: 'pre-existing', directory: dirName, reason: null };
|
|
81
|
+
}
|
|
82
|
+
return { status: 'installed', origin: 'pre-existing', directory: dirName, reason: 'already present; python dependencies incomplete — see warnings' };
|
|
83
|
+
}
|
|
84
|
+
return { status: 'installed', origin: 'pre-existing', directory: dirName, reason: 'already present — kept as-is' };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let r = io.exec('git', ['clone', src.repository, target]);
|
|
88
|
+
if (r.code !== 0) {
|
|
89
|
+
return { status: 'failed', reason: `git clone ${src.repository} failed: ${String(r.stderr || r.error).slice(-300)}` };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (src.commit) {
|
|
93
|
+
r = io.exec('git', ['-C', target, 'checkout', src.commit]);
|
|
94
|
+
if (r.code !== 0) {
|
|
95
|
+
return { status: 'failed', reason: `git checkout ${src.commit} failed: ${String(r.stderr).slice(-300)}` };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const req = path.join(target, 'requirements.txt');
|
|
100
|
+
if (io.fs.existsSync(req) && python) {
|
|
101
|
+
if (!pipInstallRequirements(io, { root, reqPath: req, python, torchSpec, log })) {
|
|
102
|
+
return { status: 'installed', origin: 'installed', directory: dirName, reason: 'cloned; python dependencies incomplete — see warnings' };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!io.fs.existsSync(target)) {
|
|
107
|
+
return { status: 'failed', reason: 'clone reported success but the directory is missing' };
|
|
108
|
+
}
|
|
109
|
+
if (log) log.info(`custom node installed: ${dirName}${src.commit ? ` @ ${src.commit}` : ''}`);
|
|
110
|
+
return { status: 'installed', origin: 'installed', directory: dirName };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Install all missing required custom nodes listed in the plan step.
|
|
115
|
+
* Incompatible existing nodes are surfaced as review items — the step stops
|
|
116
|
+
* for them until the user decides (git-safe checkout to the pinned revision
|
|
117
|
+
* is a consent-gated op). `retryDeps` carries the ids of nodes whose python
|
|
118
|
+
* dependencies an earlier run left incomplete.
|
|
119
|
+
*/
|
|
120
|
+
function installCustomNodes(io, { root, manifests, planStep, python = null, torchSpec = null, retryDeps = [], log = null }) {
|
|
121
|
+
const results = [];
|
|
122
|
+
for (const item of planStep.missing || []) {
|
|
123
|
+
const dep = findManifestDep(manifests, item.id);
|
|
124
|
+
if (!dep) {
|
|
125
|
+
results.push({ id: item.id, status: 'blocked', reason: 'not found in any manifest' });
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
results.push({
|
|
129
|
+
id: item.id,
|
|
130
|
+
...installCustomNode(io, { root, dep, python, torchSpec, retryDeps: retryDeps.includes(item.id), log }),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
for (const item of planStep.review || []) {
|
|
134
|
+
results.push({
|
|
135
|
+
id: item.id,
|
|
136
|
+
status: 'needs-user-decision',
|
|
137
|
+
reason: `${item.reason || 'incompatible'} — not changed automatically; a git-safe checkout to the pinned revision is available with explicit consent`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return results;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
module.exports = {
|
|
144
|
+
installCustomNode,
|
|
145
|
+
installCustomNodes,
|
|
146
|
+
};
|