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 9dfdbfddfa64fbfb232e2bb27da445ee45da614f
parent 950ee04ba3c24e21fdcede9f6c07371ac99a59fe
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sat, 24 Oct 2026 23:47:33 +0000

refactor(shell): move to /shell directory with wrap helper

- shell.ts -> shell/index.ts exporting registerShell
- Extract wrapping logic to shell/wrap.ts as wrap(deps, cwd, command)
- wrap handles limaName detection and command rewriting
- Updated hook to use the new wrap function

Diffstat:
Dshell.ts | 41-----------------------------------------
Ashell/index.ts | 18++++++++++++++++++
Ashell/wrap.ts | 36++++++++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+), 41 deletions(-)

diff --git a/shell.ts b/shell.ts @@ -1,41 +0,0 @@ -import type { Plugin } from "@opencode/plugin"; -import * as path from "node:path"; - -import type { OpenpodContext } from "./context"; - -export async function registerShell( - ctx: Plugin.Context, - deps: OpenpodContext, -): Promise<void> { - const { logger, openpodRoot } = deps; - - function getLimaName(dir: string): string | null { - try { - logger.log(`get lima name for ${openpodRoot} ${dir}`); - const rel = path.relative(openpodRoot, dir); - if (rel.startsWith("..") || path.isAbsolute(rel)) { - return null; - } - const first = rel.split(path.sep).find((p) => p.length > 0); - return first || null; - } catch { - return null; - } - } - - logger.log("registering create.before"); - - await ctx.shell.hook("create.before", async (event) => { - const limaName = getLimaName(event.cwd); - - if (limaName) { - const originalCommand = event.command; - const escapedCwd = event.cwd.replace(/'/g, "'\\''"); - const escapedCmd = originalCommand.replace(/'/g, "'\\''"); - event.command = `limactl shell --preserve-env --workdir='${escapedCwd}' ${limaName} bash -c '${escapedCmd}'`; - logger.log( - `redirected shell command for lima ${limaName} (cwd=${event.cwd})`, - ); - } - }); -} diff --git a/shell/index.ts b/shell/index.ts @@ -0,0 +1,18 @@ +import type { Plugin } from "@opencode/plugin"; + +import type { OpenpodContext } from "../context"; + +import { wrap } from "./wrap"; + +export async function registerShell( + ctx: Plugin.Context, + deps: OpenpodContext, +): Promise<void> { + const { logger } = deps; + + logger.log("registering create.before"); + + await ctx.shell.hook("create.before", async (event) => { + event.command = wrap(deps, event.cwd, event.command); + }); +} diff --git a/shell/wrap.ts b/shell/wrap.ts @@ -0,0 +1,36 @@ +import type { OpenpodContext } from "../context"; +import * as path from "node:path"; + +export function wrap( + deps: OpenpodContext, + cwd: string, + command: string, +): string { + const limaName = getLimaName(deps, cwd); + if (!limaName) { + return command; + } + + const escapedCwd = cwd.replace(/'/g, "'\\''"); + const escapedCmd = command.replace(/'/g, "'\\''"); + const wrapped = `limactl shell --preserve-env --workdir='${escapedCwd}' ${limaName} bash -c '${escapedCmd}'`; + + deps.logger.log(`redirected shell command for lima ${limaName} (cwd=${cwd})`); + + return wrapped; +} + +function getLimaName(deps: OpenpodContext, dir: string): string | null { + const { logger, openpodRoot } = deps; + try { + logger.log(`get lima name for ${openpodRoot} ${dir}`); + const rel = path.relative(openpodRoot, dir); + if (rel.startsWith("..") || path.isAbsolute(rel)) { + return null; + } + const first = rel.split(path.sep).find((p) => p.length > 0); + return first || null; + } catch { + return null; + } +}