Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081import nanoSpawn from 'nano-spawn';import { tagged, } from '@monochromatic-dev/module-logger/ts';
import { LIBVIRT_URI, validateName, VM_PREFIX,} from './config.ts';
/** Logger root for mvm after removing the package log shim. @example ```ts const rl = tagged({ tag: someFunction.name, l, },); ``` */const l = tagged({ tag: 'mvm', },);
/** Opens an interactive serial console session to a running VM via `virsh console`. The VM is configured with auto-login on ttyS0, so no credentials are needed. Press `Ctrl+]` to disconnect from the console. @param name - VM name without the mvm- prefix @example ```ts await shell({ name: 'dev-01' }); ``` */export async function shell({ name, }: { readonly name: string; },): Promise<void> { validateName(name,); /** Tagged logger so console-session messages name the call site. */ const rl = tagged({ tag: shell.name, l, },); /** Fully prefixed VM name expected by virsh commands. */ const fullName = `${VM_PREFIX}${name}`;
rl.info(`connecting to VM ${name} via console (press Ctrl+] to disconnect, not exit)`,);
try { await nanoSpawn( 'virsh', [ '--connect', LIBVIRT_URI, 'console', fullName, ], { stderr: 'inherit', stdin: 'inherit', stdout: 'inherit', }, ); } catch (error: unknown) { if ((error !== null) && (error !== undefined) && ((typeof error) === 'object') && ('exitCode' in error)) { /** Forwarded so the shell exit code reflects the virsh console outcome. */ const exitCode = ((typeof error.exitCode) === 'number') ? error.exitCode : undefined; if (exitCode !== undefined) process.exitCode = exitCode; } }}