32 lines
1.7 KiB
JavaScript
32 lines
1.7 KiB
JavaScript
#!/usr/bin/env node
|
|
// The shell launchers already load/release/bootstrap. Resolve the selected config again here.
|
|
import { randomUUID } from 'node:crypto';
|
|
import { loadSystem } from '../../cli/src/config.mjs';
|
|
import { runContainer } from './containers.mjs';
|
|
import { unregisterRuntime } from './runtimes.mjs';
|
|
import { initializeControl, assertProcessing } from './state.mjs';
|
|
try {
|
|
const system = loadSystem();
|
|
initializeControl(system.dataRoot);
|
|
assertProcessing(system.dataRoot);
|
|
const args = process.argv.slice(2), tty = args[0] === '--tty';
|
|
if (args.length === 1 && args[0] === '--check') process.exit(0);
|
|
if (tty) args.shift();
|
|
const worker = tty ? {
|
|
kind: 'interactive',
|
|
workspaceDir: process.env.MOSAIC_WORKSPACE_SOURCE,
|
|
sessionDir: process.env.MOSAIC_SESSION_SOURCE,
|
|
...(process.env.MOSAIC_MISSION_SOURCE ? { missionFile: process.env.MOSAIC_MISSION_SOURCE } : {}),
|
|
...(process.env.MOSAIC_AGENT_SOUL_SOURCE ? { agentSoulFile: process.env.MOSAIC_AGENT_SOUL_SOURCE } : {}),
|
|
...(process.env.MOSAIC_SKILL_SOURCES ? { skillDirs: process.env.MOSAIC_SKILL_SOURCES.split(',') } : {}),
|
|
} : { kind: 'probe' };
|
|
const result = runContainer(system.dataRoot, { kind: 'container', business: 'instance', run: randomUUID() },
|
|
{ tty, args, worker, env: process.env, stdio: 'inherit' });
|
|
if (!result.haltGeneration && !result.proc.error && result.proc.status === 0) unregisterRuntime(system.dataRoot, result.managed.id);
|
|
if (result.proc.error) throw result.proc.error;
|
|
process.exit(result.proc.status ?? 1);
|
|
} catch (e) {
|
|
process.stderr.write(`processing: ${e.code?.startsWith('processing-') ? e.code : 'container-launch-failed'}\n`);
|
|
process.exit(3);
|
|
}
|