openpod

An opencode plugin that spins up a dedicated virtual machine for each session to isolate agent work.
git clone https://unitehenry.com/git/openpod.git
Log | Files | Refs | README

index.ts (1207B)


      1 import * as os from "node:os";
      2 import * as path from "node:path";
      3 
      4 import { exec } from "./exec";
      5 import { initLogger, type Logger } from "./logger";
      6 import { initCleanup, type Cleanup } from "./cleanup";
      7 
      8 const LIMA_URL = "https://lima-vm.io/";
      9 const LIMA_MISSING_MESSAGE = `\`limactl\` is not installed. Lima is required for openpod. See ${LIMA_URL}`;
     10 
     11 export type OpenpodContext = {
     12   logger: Logger;
     13   openpodRoot: string;
     14   cleanup: Cleanup;
     15   exec: typeof exec;
     16 };
     17 
     18 export async function init(): Promise<OpenpodContext> {
     19   const openpodRoot = path.join(os.homedir(), ".local", "share", "openpod");
     20 
     21   const logger = initLogger(openpodRoot);
     22   const cleanup = initCleanup(openpodRoot, logger);
     23 
     24   async function isCommandAvailable(command: string): Promise<boolean> {
     25     const result =
     26       process.platform === "win32"
     27         ? await exec("where", [command])
     28         : await exec("/bin/sh", ["-c", `command -v ${command}`]);
     29     return result.status === 0;
     30   }
     31 
     32   const isLimaInstalled = await isCommandAvailable("limactl");
     33   if (!isLimaInstalled) {
     34     logger.log(LIMA_MISSING_MESSAGE, "error");
     35     throw new Error(LIMA_MISSING_MESSAGE);
     36   }
     37 
     38   return { logger, openpodRoot, cleanup, exec };
     39 }