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

commit 10e74c283a706b57197806df3abe514daadb8201
parent 99fdc1da9852112f9d467200bde8ef177ade0afa
Author: Henry Unite <unitehenry@gmail.com>
Date:   Mon, 19 Oct 2026 21:28:00 +0000

refactor(setup): define global functions within registerSetup instead of at module scope
Diffstat:
Msetup.ts | 132++++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 66 insertions(+), 66 deletions(-)

diff --git a/setup.ts b/setup.ts @@ -3,86 +3,86 @@ import * as fs from "node:fs"; import * as os from "node:os"; import * as path from "node:path"; -const openpodRoot = path.join(os.homedir(), ".local", "share", "openpod"); -const logDir = path.join(openpodRoot, ".log"); -const logFile = path.join(logDir, "openpod.log"); +export type OpenpodContext = { + writeLog: (message: string, level?: string) => void; + openpodRoot: string; + cleanupOpenpod: (sessionID: string) => Promise<void>; +}; + +export async function registerSetup(): Promise<OpenpodContext> { + const openpodRoot = path.join(os.homedir(), ".local", "share", "openpod"); + const logDir = path.join(openpodRoot, ".log"); + const logFile = path.join(logDir, "openpod.log"); -function writeLog(message: string, level: string = "info"): void { - try { - fs.mkdirSync(logDir, { recursive: true }); - const timestamp = new Date().toISOString(); - const levelPart = level === "info" ? "" : `[${level}] `; - fs.appendFileSync( - logFile, - `[${timestamp}] [openpod] ${levelPart}${message} + function writeLog(message: string, level: string = "info"): void { + try { + fs.mkdirSync(logDir, { recursive: true }); + const timestamp = new Date().toISOString(); + const levelPart = level === "info" ? "" : `[${level}] `; + fs.appendFileSync( + logFile, + `[${timestamp}] [openpod] ${levelPart}${message} `, - ); - } catch { - // ignore logging failures + ); + } catch { + // ignore logging failures + } } -} -export async function cleanupOpenpod(sessionID: string): Promise<void> { - if (!sessionID || typeof sessionID !== "string") return; + function isCommandAvailable(command: string): boolean { + try { + if (process.platform === "win32") { + execSync(`where ${command}`, { stdio: "ignore" }); + } else { + execSync(`command -v ${command}`, { stdio: "ignore", shell: "/bin/sh" }); + } + return true; + } catch { + return false; + } + } - const limaName = sessionID; - const podDir = path.join(openpodRoot, sessionID); + async function cleanupOpenpod(sessionID: string): Promise<void> { + if (!sessionID || typeof sessionID !== "string") return; - writeLog(`[cleanup] starting for ${sessionID}`); + const limaName = sessionID; + const podDir = path.join(openpodRoot, sessionID); - // best-effort stop (ignore errors) - try { - spawnSync("limactl", ["stop", limaName, "--force"], { stdio: "ignore" }); - writeLog(`[cleanup] stopped ${limaName} (if running)`); - } catch { - // ignore - } + writeLog(`[cleanup] starting for ${sessionID}`); - // delete the lima instance - try { - const result = spawnSync("limactl", ["delete", limaName, "--force"], { - stdio: "ignore", - }); - writeLog( - `[cleanup] limactl delete ${limaName} exited with ${result.status}`, - ); - } catch (err) { - writeLog(`[cleanup] limactl delete error for ${limaName}: ${err}`); - } - - // remove the openpod directory - try { - if (fs.existsSync(podDir)) { - fs.rmSync(podDir, { recursive: true, force: true }); - writeLog(`[cleanup] removed directory ${podDir}`); - } else { - writeLog(`[cleanup] directory did not exist: ${podDir}`); + // best-effort stop (ignore errors) + try { + spawnSync("limactl", ["stop", limaName, "--force"], { stdio: "ignore" }); + writeLog(`[cleanup] stopped ${limaName} (if running)`); + } catch { + // ignore } - } catch (err) { - writeLog(`[cleanup] failed to remove ${podDir}: ${err}`); - } -} -export type OpenpodContext = { - writeLog: (message: string, level?: string) => void; - openpodRoot: string; - cleanupOpenpod: (sessionID: string) => Promise<void>; -}; + // delete the lima instance + try { + const result = spawnSync("limactl", ["delete", limaName, "--force"], { + stdio: "ignore", + }); + writeLog( + `[cleanup] limactl delete ${limaName} exited with ${result.status}`, + ); + } catch (err) { + writeLog(`[cleanup] limactl delete error for ${limaName}: ${err}`); + } -function isCommandAvailable(command: string): boolean { - try { - if (process.platform === "win32") { - execSync(`where ${command}`, { stdio: "ignore" }); - } else { - execSync(`command -v ${command}`, { stdio: "ignore", shell: "/bin/sh" }); + // remove the openpod directory + try { + if (fs.existsSync(podDir)) { + fs.rmSync(podDir, { recursive: true, force: true }); + writeLog(`[cleanup] removed directory ${podDir}`); + } else { + writeLog(`[cleanup] directory did not exist: ${podDir}`); + } + } catch (err) { + writeLog(`[cleanup] failed to remove ${podDir}: ${err}`); } - return true; - } catch { - return false; } -} -export async function registerSetup(): Promise<OpenpodContext> { if (!isCommandAvailable("limactl")) { writeLog( "`limactl` is not installed. Lima is required for openpod. See https://lima-vm.io/",