commit d9843ea856e5ad3e72cd171e7727a60a71e2a707
parent b5029874b3ac9e49c43ab36f0540e5e1fc717b92
Author: Henry Unite <unitehenry@gmail.com>
Date: Sun, 18 Oct 2026 20:29:21 +0000
feat: lima shell
Diffstat:
| M | index.ts | | | 117 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------- |
1 file changed, 93 insertions(+), 24 deletions(-)
diff --git a/index.ts b/index.ts
@@ -82,6 +82,30 @@ function cloneRepo(source: string, target: string): void {
}
}
+function getLimaName(dir: string): string | null {
+ try {
+ 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;
+ }
+}
+
+function limaInstanceExists(name: string): boolean {
+ try {
+ const result = spawnSync("limactl", ["list", name], {
+ stdio: "ignore",
+ });
+ return result.status === 0;
+ } catch {
+ return false;
+ }
+}
+
export default Plugin.define({
id: "openpod",
async setup(ctx) {
@@ -95,12 +119,11 @@ export default Plugin.define({
const session = await ctx.session.get({ sessionID: event.sessionID });
const dir = session.location.directory;
const gitEnabled = isGitEnabled(dir);
- writeLog(
- `session ${event.sessionID} prompt - gitEnabled: ${gitEnabled}`,
- );
+ writeLog(`session ${event.sessionID} prompt - gitEnabled: ${gitEnabled}`);
const target = path.join(openpodRoot, event.sessionID);
const needsMove = dir !== target;
+
writeLog(
`needs move for project dir ${dir}? ${needsMove} (target=${target})`,
);
@@ -110,34 +133,80 @@ export default Plugin.define({
return;
}
- if (!needsMove) {
+ const limaName = event.sessionID;
+ const podDir = target;
+
+ if (needsMove) {
+ if (fs.existsSync(target)) {
+ writeLog(`${target} already exists`);
+ await ctx.session.move({
+ sessionID: event.sessionID,
+ directory: target,
+ });
+ } else {
+ const repoRoot = getRepoRoot(dir);
+
+ if (!repoRoot) {
+ writeLog(`failed to get repo root`);
+ return;
+ }
+
+ writeLog(`cloning ${repoRoot} -> ${target}`);
+ fs.mkdirSync(openpodRoot, { recursive: true });
+
+ cloneRepo(repoRoot, target);
+
+ writeLog(`clone complete, moving session to ${target}`);
+ await ctx.session.move({
+ sessionID: event.sessionID,
+ directory: target,
+ });
+ }
+ } else {
writeLog(`already in ${target} directory`);
- return;
}
- if (fs.existsSync(target)) {
- writeLog(`${target} already exists`);
- await ctx.session.move({
- sessionID: event.sessionID,
- directory: target,
- });
- return;
+ // ensure lima instance for this pod
+ if (!limaInstanceExists(limaName)) {
+ writeLog(`creating lima instance ${limaName} (mount-only ${podDir}:w)`);
+ const createResult = spawnSync(
+ "limactl",
+ [
+ "create",
+ `--name=${limaName}`,
+ `--mount-only=${podDir}:w`,
+ "template:default",
+ "--yes",
+ ],
+ {
+ stdio: "inherit",
+ },
+ );
+ if (createResult.status !== 0) {
+ writeLog(`limactl create exited with ${createResult.status}`);
+ }
}
- const repoRoot = getRepoRoot(dir);
-
- if (!repoRoot) {
- writeLog(`failed to get repo root`);
- return;
+ writeLog(`starting lima instance ${limaName}`);
+ const startResult = spawnSync("limactl", ["start", limaName, "--yes"], {
+ stdio: "inherit",
+ });
+ if (startResult.status !== 0) {
+ writeLog(`limactl start exited with ${startResult.status}`);
}
+ });
- writeLog(`cloning ${repoRoot} -> ${target}`);
- fs.mkdirSync(openpodRoot, { recursive: true });
-
- cloneRepo(repoRoot, target);
-
- writeLog(`clone complete, moving session to ${target}`);
- await ctx.session.move({ sessionID: event.sessionID, directory: target });
+ 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}'`;
+ writeLog(
+ `redirected shell command for lima ${limaName} (cwd=${event.cwd})`,
+ );
+ }
});
},
});