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 fff874cde9712eff88203aa3aa4fec1d534c49ff
parent d9843ea856e5ad3e72cd171e7727a60a71e2a707
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sun, 18 Oct 2026 21:32:29 +0000

chore: merge

Diffstat:
MREADME.md | 21++++++++++++++-------
Mindex.ts | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md @@ -1,13 +1,20 @@ - New Session -> Create SSH directory -> Move to dir - Execute commands on remote server +- On session delete (via `opencode session delete` or UI), automatically removes: + - the `~/.local/share/openpod/<sessionId>` directory + - the corresponding lima instance (stop + delete) setup - verify limactl is installed +verify limactl is installed prompt - check if session is new - if in git repo - git clone to `~/.local/share/openpod/<sessionId>` - move session to clone repo - else - skip +check if session is new +if in git repo +git clone to `~/.local/share/openpod/<sessionId>` +move session to clone repo +else +skip + +cleanup (on session.deleted event) +limactl stop --force + delete --force <sessionId> +rm -rf ~/.local/share/openpod/<sessionId> diff --git a/index.ts b/index.ts @@ -106,6 +106,47 @@ function limaInstanceExists(name: string): boolean { } } +function cleanupOpenpod(sessionID: string): void { + if (!sessionID || typeof sessionID !== "string") return; + + const limaName = sessionID; + const podDir = path.join(openpodRoot, sessionID); + + writeLog(`[cleanup] starting for ${sessionID}`); + + // best-effort stop (ignore errors) + try { + spawnSync("limactl", ["stop", limaName, "--force"], { stdio: "ignore" }); + writeLog(`[cleanup] stopped ${limaName} (if running)`); + } catch { + // ignore + } + + // 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}`); + } + } catch (err) { + writeLog(`[cleanup] failed to remove ${podDir}: ${err}`); + } +} + export default Plugin.define({ id: "openpod", async setup(ctx) { @@ -208,5 +249,34 @@ export default Plugin.define({ ); } }); + + // Listen for session removal (via events, since there is no ctx.session.hook("remove")) + // and clean up the corresponding openpod directory + lima instance. + const controller = new AbortController(); + void (async () => { + try { + for await (const ev of ctx.event.subscribe({ + signal: controller.signal, + })) { + if (ev.type === "session.deleted") { + const props: any = (ev as any).properties ?? ev; + const sessionID: string | undefined = + props.sessionID ?? + props.id ?? + props.info?.id ?? + (ev as any).sessionID; + if (sessionID) { + cleanupOpenpod(sessionID); + } + } + } + } catch (err: any) { + if (err?.name !== "AbortError") { + writeLog(`event subscription error: ${err}`); + } + } + })(); + + return () => controller.abort(); }, });