@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,376 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Canonical Install Manifest — loader & validator.
5
+ *
6
+ * Phase 1 of the Private Worker Installer architecture. This module is
7
+ * read-only tooling: it is NOT loaded by the backend runtime, does not
8
+ * touch workflows/connectors/GPU Hub/worker runtime, and performs no
9
+ * installation.
10
+ *
11
+ * Manifest location: backend/ai/install-manifests/{type}/{profile}.json
12
+ * (architecture draft §9; kept in a separate tree from prompt-assembly
13
+ * profiles on purpose).
14
+ *
15
+ * Evidence taxonomy (per-entry `basis` field):
16
+ * required — required by production workflows (workflow-derived)
17
+ * known_working — verified present & working on a known working instance
18
+ * minimum_supported — minimal admissible configuration, already justifiable
19
+ * optional — not required; utility / "for growth"
20
+ * environment_reference — provider/image-specific reference info, never canonical
21
+ * unknown — insufficient data; explicit TODO / separate check needed
22
+ *
23
+ * Key principle: runtime audits are reference/verification material only —
24
+ * they are NEVER the source of truth. Production workflows are the single
25
+ * source of `required`.
26
+ *
27
+ * Phase 1.5 adds the top-level `workflows` section: baseline workflows are
28
+ * first-class install artifacts with policy `editable-baseline` — they are
29
+ * starting points the user may customize locally, never immutable config.
30
+ */
31
+
32
+ const fs = require('fs');
33
+ const path = require('path');
34
+
35
+ const MANIFEST_SCHEMA_VERSION = '1.0.0';
36
+ // Priority: baked-in (container) > repo checkout (development)
37
+ const MANIFEST_ROOT = (() => {
38
+ const bakedIn = path.join('/app', 'artifacts', 'install-manifests');
39
+ try { if (require('fs').existsSync(bakedIn)) return bakedIn; } catch (_) {}
40
+ return path.join(__dirname, '..', '..', 'ai', 'install-manifests');
41
+ })();
42
+
43
+ const BASIS_VALUES = Object.freeze([
44
+ 'required',
45
+ 'known_working',
46
+ 'minimum_supported',
47
+ 'optional',
48
+ 'environment_reference',
49
+ 'unknown',
50
+ ]);
51
+
52
+ const REQUIREMENT_VALUES = Object.freeze(['required', 'optional', 'unknown']);
53
+
54
+ const DEPENDENCY_KINDS = Object.freeze([
55
+ 'custom_node',
56
+ 'model',
57
+ 'model_repo',
58
+ 'python_package',
59
+ ]);
60
+
61
+ const VERIFICATION_VALUES = Object.freeze(['confirmed', 'needs_verification', 'unknown']);
62
+
63
+ const WORKFLOW_POLICY_VALUES = Object.freeze(['editable-baseline']);
64
+
65
+ const WORKFLOW_SOURCE_KINDS = Object.freeze(['animastor']);
66
+
67
+ const RUNTIME_COMPONENTS = Object.freeze([
68
+ 'comfyui',
69
+ 'python',
70
+ 'torch',
71
+ 'nodejs',
72
+ 'nvidia_driver',
73
+ ]);
74
+
75
+ function isPlainObject(v) {
76
+ return v !== null && typeof v === 'object' && !Array.isArray(v);
77
+ }
78
+
79
+ function isNonEmptyString(v) {
80
+ return typeof v === 'string' && v.length > 0;
81
+ }
82
+
83
+ /**
84
+ * Validate a manifest object. Returns { valid, errors[], warnings[] }.
85
+ * Errors block loading; warnings record honesty gaps (unknown sources,
86
+ * TODOs) without blocking — a draft manifest is allowed to have them.
87
+ */
88
+ function validateManifest(manifest) {
89
+ const errors = [];
90
+ const warnings = [];
91
+
92
+ if (!isPlainObject(manifest)) {
93
+ return { valid: false, errors: ['manifest must be an object'], warnings };
94
+ }
95
+
96
+ if (manifest.manifest_version !== MANIFEST_SCHEMA_VERSION) {
97
+ errors.push(`manifest_version must be "${MANIFEST_SCHEMA_VERSION}" (got ${JSON.stringify(manifest.manifest_version)})`);
98
+ }
99
+ if (!isNonEmptyString(manifest.revision)) {
100
+ errors.push('revision is required (non-empty string)');
101
+ }
102
+
103
+ const profile = manifest.profile;
104
+ if (!isPlainObject(profile) || !isNonEmptyString(profile.id) || !isNonEmptyString(profile.type) || !isNonEmptyString(profile.name)) {
105
+ errors.push('profile.{id,type,name} are required');
106
+ } else if (profile.id !== `${profile.type}/${profile.name}`) {
107
+ errors.push(`profile.id must equal "{type}/{name}" (got "${profile.id}")`);
108
+ }
109
+
110
+ const prov = manifest.provenance;
111
+ if (!isPlainObject(prov) || !Array.isArray(prov.workflows) || prov.workflows.length === 0) {
112
+ errors.push('provenance.workflows must be a non-empty array (workflows are the single source of "required")');
113
+ }
114
+
115
+ const rt = manifest.runtime_requirements;
116
+ if (!isPlainObject(rt)) {
117
+ errors.push('runtime_requirements is required');
118
+ } else {
119
+ for (const component of RUNTIME_COMPONENTS) {
120
+ const spec = rt[component];
121
+ if (!isPlainObject(spec)) {
122
+ errors.push(`runtime_requirements.${component} is required`);
123
+ continue;
124
+ }
125
+ if (!BASIS_VALUES.includes(spec.basis)) {
126
+ errors.push(`runtime_requirements.${component}.basis must be one of ${BASIS_VALUES.join('|')}`);
127
+ }
128
+ if (component === 'comfyui' && !isNonEmptyString(spec.policy)) {
129
+ errors.push('runtime_requirements.comfyui.policy is required');
130
+ }
131
+ if (component === 'comfyui' && spec.pin !== null && spec.pin !== undefined) {
132
+ if (!isPlainObject(spec.pin) || !isNonEmptyString(spec.pin.repository)) {
133
+ errors.push('runtime_requirements.comfyui.pin must be null or {repository, tag|commit}');
134
+ }
135
+ }
136
+ if (spec.basis === 'unknown' && !isNonEmptyString(spec.todo) && !(Array.isArray(spec.notes) && spec.notes.length > 0)) {
137
+ warnings.push(`runtime_requirements.${component} has basis=unknown but no todo/notes explaining what must be checked`);
138
+ }
139
+ }
140
+ }
141
+
142
+ const deps = manifest.dependencies;
143
+ if (!Array.isArray(deps)) {
144
+ errors.push('dependencies must be an array');
145
+ } else {
146
+ const seenIds = new Set();
147
+ deps.forEach((dep, i) => {
148
+ const where = `dependencies[${i}]`;
149
+ if (!isPlainObject(dep)) {
150
+ errors.push(`${where} must be an object`);
151
+ return;
152
+ }
153
+ if (!isNonEmptyString(dep.id)) errors.push(`${where}.id is required`);
154
+ else if (seenIds.has(dep.id)) errors.push(`${where}.id "${dep.id}" is duplicated`);
155
+ else seenIds.add(dep.id);
156
+
157
+ if (!DEPENDENCY_KINDS.includes(dep.kind)) {
158
+ errors.push(`${where}.kind must be one of ${DEPENDENCY_KINDS.join('|')}`);
159
+ }
160
+ if (!REQUIREMENT_VALUES.includes(dep.requirement)) {
161
+ errors.push(`${where}.requirement must be one of ${REQUIREMENT_VALUES.join('|')}`);
162
+ }
163
+ if (!BASIS_VALUES.includes(dep.basis)) {
164
+ errors.push(`${where}.basis must be one of ${BASIS_VALUES.join('|')}`);
165
+ }
166
+
167
+ if (dep.requirement === 'required' && !isPlainObject(dep.provenance)) {
168
+ errors.push(`${where}.provenance is required for requirement=required`);
169
+ } else if (dep.requirement === 'required' && isPlainObject(dep.provenance)
170
+ && (!Array.isArray(dep.provenance.workflows) || dep.provenance.workflows.length === 0)) {
171
+ errors.push(`${where}.provenance.workflows must be non-empty for requirement=required (workflows are the source of "required")`);
172
+ }
173
+
174
+ if (dep.kind === 'model' && !isNonEmptyString(dep.filename)) {
175
+ errors.push(`${where}.filename is required for kind=model`);
176
+ }
177
+ if ((dep.kind === 'model' || dep.kind === 'model_repo') && !isNonEmptyString(dep.target_dir)) {
178
+ errors.push(`${where}.target_dir is required for kind=${dep.kind}`);
179
+ }
180
+ if (dep.kind === 'custom_node' && isPlainObject(dep.install) && isPlainObject(dep.install.source)) {
181
+ const src = dep.install.source;
182
+ if (src.verification && !VERIFICATION_VALUES.includes(src.verification)) {
183
+ errors.push(`${where}.install.source.verification must be one of ${VERIFICATION_VALUES.join('|')}`);
184
+ }
185
+ if (src.verification !== 'confirmed') {
186
+ warnings.push(`${where} (${dep.id}): source verification is "${src.verification || 'unset'}" — needs research before the manifest can become stable`);
187
+ }
188
+ }
189
+ if (dep.kind === 'model' && isPlainObject(dep.source) && dep.source.verification !== 'confirmed') {
190
+ warnings.push(`${where} (${dep.id}): download source is "${dep.source.verification || 'unset'}" — D5 research required`);
191
+ }
192
+ });
193
+ }
194
+
195
+ // Phase 1.5: workflows are first-class install artifacts (editable baselines).
196
+ if (manifest.workflows !== undefined) {
197
+ const wfs = manifest.workflows;
198
+ if (!isPlainObject(wfs)) {
199
+ errors.push('workflows must be an object { policy, baseline_dir, artifacts[] }');
200
+ } else {
201
+ if (!WORKFLOW_POLICY_VALUES.includes(wfs.policy)) {
202
+ errors.push(`workflows.policy must be one of ${WORKFLOW_POLICY_VALUES.join('|')} (a baseline workflow is an editable starting point, never an immutable prison)`);
203
+ }
204
+ if (!isNonEmptyString(wfs.baseline_dir)) {
205
+ errors.push('workflows.baseline_dir is required (user-visible location, e.g. user/default/workflows/animastor)');
206
+ }
207
+ const profileWorkflows = new Set(
208
+ isPlainObject(manifest.provenance) && Array.isArray(manifest.provenance.workflows) ? manifest.provenance.workflows : []
209
+ );
210
+ if (!Array.isArray(wfs.artifacts) || wfs.artifacts.length === 0) {
211
+ errors.push('workflows.artifacts must be a non-empty array');
212
+ } else {
213
+ const seenWfIds = new Set();
214
+ wfs.artifacts.forEach((wf, i) => {
215
+ const where = `workflows.artifacts[${i}]`;
216
+ if (!isPlainObject(wf)) {
217
+ errors.push(`${where} must be an object`);
218
+ return;
219
+ }
220
+ if (!isNonEmptyString(wf.id) || !wf.id.startsWith('workflow:')) {
221
+ errors.push(`${where}.id is required and must start with "workflow:"`);
222
+ } else if (seenWfIds.has(wf.id)) {
223
+ errors.push(`${where}.id "${wf.id}" is duplicated`);
224
+ } else {
225
+ seenWfIds.add(wf.id);
226
+ }
227
+ if (!isNonEmptyString(wf.name)) errors.push(`${where}.name is required (user-visible)`);
228
+ if (!isNonEmptyString(wf.filename) || !wf.filename.endsWith('.json')) {
229
+ errors.push(`${where}.filename is required and must end with .json`);
230
+ }
231
+ if (!isNonEmptyString(wf.target_dir)) errors.push(`${where}.target_dir is required`);
232
+ if (!REQUIREMENT_VALUES.includes(wf.requirement)) {
233
+ errors.push(`${where}.requirement must be one of ${REQUIREMENT_VALUES.join('|')}`);
234
+ }
235
+ if (wf.editable === false) {
236
+ errors.push(`${where}.editable must not be false — baseline workflows are editable by design; the installer never enforces immutability on the user's copy`);
237
+ }
238
+ if (wf.baseline_sha256 !== null && wf.baseline_sha256 !== undefined && !/^[0-9a-f]{64}$/i.test(String(wf.baseline_sha256))) {
239
+ errors.push(`${where}.baseline_sha256 must be null or a full sha256 hex string`);
240
+ }
241
+ if (!isPlainObject(wf.source) || !WORKFLOW_SOURCE_KINDS.includes(wf.source.kind)) {
242
+ errors.push(`${where}.source.kind must be one of ${WORKFLOW_SOURCE_KINDS.join('|')}`);
243
+ } else if (!isNonEmptyString(wf.source.repository_path) && !isNonEmptyString(wf.source.endpoint)) {
244
+ errors.push(`${where}.source needs repository_path and/or endpoint`);
245
+ }
246
+ if (!isPlainObject(wf.provenance) || !Array.isArray(wf.provenance.workflows) || wf.provenance.workflows.length === 0) {
247
+ errors.push(`${where}.provenance.workflows must be non-empty (production workflows are the source of required)`);
248
+ } else {
249
+ for (const ref of wf.provenance.workflows) {
250
+ if (!profileWorkflows.has(ref)) {
251
+ errors.push(`${where} references workflow "${ref}" that is not in manifest provenance.workflows`);
252
+ }
253
+ }
254
+ }
255
+ if (wf.baseline_sha256 === null || wf.baseline_sha256 === undefined) {
256
+ warnings.push(`${where} (${wf.id}): baseline_sha256 is null — customized-copy detection falls back to presence-only until the canonical file is hashed`);
257
+ }
258
+ });
259
+ }
260
+ }
261
+ }
262
+
263
+ if (!isPlainObject(manifest.worker_bundle)) {
264
+ errors.push('worker_bundle is required');
265
+ } else {
266
+ const wb = manifest.worker_bundle;
267
+ if (!isNonEmptyString(wb.min_version)) errors.push('worker_bundle.min_version is required');
268
+ if (!Array.isArray(wb.files) || wb.files.length === 0) errors.push('worker_bundle.files must be a non-empty array');
269
+ if (!isPlainObject(wb.env) || !Array.isArray(wb.env.required) || wb.env.required.length === 0) {
270
+ errors.push('worker_bundle.env.required must be a non-empty array');
271
+ }
272
+ }
273
+
274
+ if (!isPlainObject(manifest.verification)) {
275
+ errors.push('verification section is required');
276
+ }
277
+
278
+ if (manifest.environment_reference !== undefined) {
279
+ if (!Array.isArray(manifest.environment_reference)) {
280
+ errors.push('environment_reference must be an array');
281
+ } else {
282
+ manifest.environment_reference.forEach((ref, i) => {
283
+ if (!isPlainObject(ref) || !isNonEmptyString(ref.provider) || !isNonEmptyString(ref.audit)) {
284
+ errors.push(`environment_reference[${i}] must contain provider and audit reference`);
285
+ } else if (!isNonEmptyString(ref.disclaimer)) {
286
+ warnings.push(`environment_reference[${i}] has no disclaimer — reference environments must be explicitly marked as non-canonical`);
287
+ }
288
+ });
289
+ }
290
+ }
291
+
292
+ return { valid: errors.length === 0, errors, warnings };
293
+ }
294
+
295
+ function manifestPath(profileId) {
296
+ return path.join(MANIFEST_ROOT, `${profileId}.json`);
297
+ }
298
+
299
+ /**
300
+ * Load + validate a manifest by profile id (e.g. "audio/qwen-tts").
301
+ * Throws on missing file or validation errors. Warnings are attached to the
302
+ * returned object as `manifest._validation`.
303
+ */
304
+ function loadManifest(profileId, opts = {}) {
305
+ const file = manifestPath(profileId);
306
+ if (!fs.existsSync(file)) {
307
+ throw new Error(`Install manifest not found for profile "${profileId}" (${file})`
308
+ + (profileId.includes('/')
309
+ ? ''
310
+ : ` — profile ids are "<category>/<name>", e.g. audio/qwen-tts. Available: ${listProfileIds().join(', ') || 'none'}`));
311
+ }
312
+ let manifest;
313
+ try {
314
+ manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
315
+ } catch (err) {
316
+ throw new Error(`Install manifest for "${profileId}" is not valid JSON: ${err.message}`);
317
+ }
318
+ const validation = validateManifest(manifest);
319
+ if (!validation.valid && !opts.skipValidation) {
320
+ throw new Error(`Install manifest for "${profileId}" failed validation:\n - ${validation.errors.join('\n - ')}`);
321
+ }
322
+ Object.defineProperty(manifest, '_validation', { value: validation, enumerable: false });
323
+ return manifest;
324
+ }
325
+
326
+ /**
327
+ * Load all manifests under MANIFEST_ROOT. Returns a map keyed by profile id.
328
+ */
329
+ function loadAllManifests(opts = {}) {
330
+ const result = {};
331
+ if (!fs.existsSync(MANIFEST_ROOT)) return result;
332
+ for (const type of fs.readdirSync(MANIFEST_ROOT).sort()) {
333
+ const typeDir = path.join(MANIFEST_ROOT, type);
334
+ if (!fs.statSync(typeDir).isDirectory()) continue;
335
+ for (const file of fs.readdirSync(typeDir).sort()) {
336
+ if (!file.endsWith('.json')) continue;
337
+ const profileId = `${type}/${path.basename(file, '.json')}`;
338
+ result[profileId] = loadManifest(profileId, opts);
339
+ }
340
+ }
341
+ return result;
342
+ }
343
+
344
+ /**
345
+ * List available profile ids ("<category>/<name>") without loading/validating
346
+ * the manifests — used for error hints.
347
+ */
348
+ function listProfileIds() {
349
+ const ids = [];
350
+ if (!fs.existsSync(MANIFEST_ROOT)) return ids;
351
+ for (const type of fs.readdirSync(MANIFEST_ROOT).sort()) {
352
+ const typeDir = path.join(MANIFEST_ROOT, type);
353
+ if (!fs.statSync(typeDir).isDirectory()) continue;
354
+ for (const file of fs.readdirSync(typeDir).sort()) {
355
+ if (file.endsWith('.json')) ids.push(`${type}/${path.basename(file, '.json')}`);
356
+ }
357
+ }
358
+ return ids;
359
+ }
360
+
361
+ module.exports = {
362
+ MANIFEST_SCHEMA_VERSION,
363
+ MANIFEST_ROOT,
364
+ BASIS_VALUES,
365
+ REQUIREMENT_VALUES,
366
+ DEPENDENCY_KINDS,
367
+ VERIFICATION_VALUES,
368
+ WORKFLOW_POLICY_VALUES,
369
+ WORKFLOW_SOURCE_KINDS,
370
+ RUNTIME_COMPONENTS,
371
+ validateManifest,
372
+ manifestPath,
373
+ loadManifest,
374
+ loadAllManifests,
375
+ listProfileIds,
376
+ };