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 5ffecfe15055256459544e7e01bdfd5117c62e3c
parent 806a6ac6c0c1f4bea38af4b6e931a3b0f83053a9
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sun, 15 Nov 2026 20:01:24 +0000

refactor(context): use access directly instead of exists helper

Inline path existence checks with node:fs/promises access and remove the context/fs module and its tests.

Diffstat:
Mcommand/clear.ts | 14+++++++-------
Mcontext/cleanup.ts | 18++++++++++--------
Dcontext/fs.test.ts | 32--------------------------------
Dcontext/fs.ts | 10----------
Mprompt/handle.ts | 13++++++++++---
5 files changed, 27 insertions(+), 60 deletions(-)

diff --git a/command/clear.ts b/command/clear.ts @@ -1,18 +1,18 @@ import type { OpenpodContext } from "../context"; -import { readdir, rm } from "node:fs/promises"; - -import { exists } from "../context/fs"; +import { access, readdir, rm } from "node:fs/promises"; export async function clear(deps: OpenpodContext): Promise<void> { const { logger, openpodRoot } = deps; logger.log("[clear] starting full openpod cleanup"); try { - if (!(await exists(openpodRoot))) { - logger.log("[clear] openpod root does not exist"); - return; - } + await access(openpodRoot); + } catch { + logger.log("[clear] openpod root does not exist"); + return; + } + try { // Clean up each session/pod individually (stops + deletes lima + removes dir) const entries = await readdir(openpodRoot, { withFileTypes: true }); for (const entry of entries) { diff --git a/context/cleanup.ts b/context/cleanup.ts @@ -1,8 +1,7 @@ -import { rm } from "node:fs/promises"; +import { access, rm } from "node:fs/promises"; import * as path from "node:path"; import { exec } from "./exec"; -import { exists } from "./fs"; import type { Logger } from "./logger"; export type Cleanup = { @@ -27,12 +26,15 @@ export function initCleanup(openpodRoot: string, logger?: Logger): Cleanup { async function removePodDirectory(podDir: string): Promise<void> { try { - if (await exists(podDir)) { - await rm(podDir, { recursive: true, force: true }); - log(`[cleanup] removed directory ${podDir}`); - } else { - log(`[cleanup] directory did not exist: ${podDir}`); - } + await access(podDir); + } catch { + log(`[cleanup] directory did not exist: ${podDir}`); + return; + } + + try { + await rm(podDir, { recursive: true, force: true }); + log(`[cleanup] removed directory ${podDir}`); } catch (err) { log(`[cleanup] failed to remove ${podDir}: ${err}`); } diff --git a/context/fs.test.ts b/context/fs.test.ts @@ -1,32 +0,0 @@ -import { describe, it, expect, beforeEach, afterEach } from "vitest"; -import * as fs from "node:fs"; -import * as path from "node:path"; -import * as os from "node:os"; - -import { exists } from "./fs"; - -describe("fs", () => { - let tempRoot: string; - - beforeEach(() => { - tempRoot = path.join( - os.tmpdir(), - `openpod-test-${Date.now()}-${Math.random()}`, - ); - fs.mkdirSync(tempRoot, { recursive: true }); - }); - - afterEach(() => { - if (fs.existsSync(tempRoot)) { - fs.rmSync(tempRoot, { recursive: true, force: true }); - } - }); - - it("returns true for an existing path", async () => { - expect(await exists(tempRoot)).toBe(true); - }); - - it("returns false for a missing path", async () => { - expect(await exists(path.join(tempRoot, "missing"))).toBe(false); - }); -}); diff --git a/context/fs.ts b/context/fs.ts @@ -1,10 +0,0 @@ -import { access } from "node:fs/promises"; - -export async function exists(target: string): Promise<boolean> { - try { - await access(target); - return true; - } catch { - return false; - } -} diff --git a/prompt/handle.ts b/prompt/handle.ts @@ -1,9 +1,8 @@ import type { OpenpodContext } from "../context"; -import { mkdir, rm } from "node:fs/promises"; +import { access, mkdir, rm } from "node:fs/promises"; import * as path from "node:path"; import { exec } from "../context/exec"; -import { exists } from "../context/fs"; export type HandleParams = { ctx: OpenpodContext; @@ -104,7 +103,15 @@ export async function handle(params: HandleParams): Promise<void> { ); if (needsMove) { - if (await exists(target)) { + let targetExists = false; + try { + await access(target); + targetExists = true; + } catch { + // target does not exist + } + + if (targetExists) { logger.log(`${target} already exists`); move(sessionId, target); } else {