commit 94dcf8c231c67d732cb68b9892eef10011f67012
parent 1255d4cfdf5dc1352dea9857eeee4579305dabc3
Author: Henry Unite <unitehenry@gmail.com>
Date: Sat, 24 Oct 2026 22:58:27 +0000
refactor(context): rename APIs for consistency
- writeLog → log in OpenpodContext and all call sites
- cleanupOpenpod → cleanup in OpenpodContext and all call sites
- registerSetup → init (and update entrypoint in index.ts)
- Update all imports from ./setup to ./context
- Update destructuring and method calls across prompt, shell, command, controller
Diffstat:
5 files changed, 48 insertions(+), 48 deletions(-)
diff --git a/command.ts b/command.ts
@@ -1,15 +1,15 @@
import type { Plugin } from "@opencode/plugin";
import * as fs from "node:fs";
-import type { OpenpodContext } from "./setup";
+import type { OpenpodContext } from "./context";
export async function clearAllOpenpod(deps: OpenpodContext): Promise<void> {
- const { writeLog, openpodRoot } = deps;
- writeLog("[clear] starting full openpod cleanup");
+ const { log, openpodRoot } = deps;
+ log("[clear] starting full openpod cleanup");
try {
if (!fs.existsSync(openpodRoot)) {
- writeLog("[clear] openpod root does not exist");
+ log("[clear] openpod root does not exist");
return;
}
@@ -18,15 +18,15 @@ export async function clearAllOpenpod(deps: OpenpodContext): Promise<void> {
for (const entry of entries) {
if (entry.isDirectory()) {
const sessionID = entry.name;
- await deps.cleanupOpenpod(sessionID);
+ await deps.cleanup(sessionID);
}
}
// Remove the root directory entirely (includes .log etc.)
fs.rmSync(openpodRoot, { recursive: true, force: true });
- writeLog(`[clear] removed entire directory ${openpodRoot}`);
+ log(`[clear] removed entire directory ${openpodRoot}`);
} catch (err) {
- writeLog(`[clear] error during cleanup: ${err}`);
+ log(`[clear] error during cleanup: ${err}`);
}
}
@@ -34,8 +34,8 @@ export async function registerCommand(
ctx: Plugin.Context,
deps: OpenpodContext,
): Promise<void> {
- const { writeLog } = deps;
- writeLog("registering commands");
+ const { log } = deps;
+ log("registering commands");
await ctx.command.transform((editor) => {
editor.add({
diff --git a/controller.ts b/controller.ts
@@ -1,6 +1,6 @@
import type { Plugin } from "@opencode/plugin";
-import type { OpenpodContext } from "./setup";
+import type { OpenpodContext } from "./context";
export async function registerController(
ctx: Plugin.Context,
@@ -24,14 +24,14 @@ export async function registerController(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(ev as any).sessionID;
if (sessionID) {
- void deps.cleanupOpenpod(sessionID);
+ void deps.cleanup(sessionID);
}
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
if (err?.name !== "AbortError") {
- deps.writeLog(`event subscription error: ${err}`);
+ deps.log(`event subscription error: ${err}`);
}
}
})();
diff --git a/index.ts b/index.ts
@@ -4,12 +4,12 @@ import { registerCommand } from "./command";
import { registerPrompt } from "./prompt";
import { registerShell } from "./shell";
import { registerController } from "./controller";
-import { registerSetup } from "./setup";
+import { init } from "./context";
export default Plugin.define({
id: "openpod",
async setup(ctx) {
- const openpod = await registerSetup();
+ const openpod = await init();
await registerPrompt(ctx, openpod);
await registerShell(ctx, openpod);
diff --git a/prompt.ts b/prompt.ts
@@ -3,13 +3,13 @@ import { spawnSync } from "node:child_process";
import * as fs from "node:fs";
import * as path from "node:path";
-import type { OpenpodContext } from "./setup";
+import type { OpenpodContext } from "./context";
export async function registerPrompt(
ctx: Plugin.Context,
deps: OpenpodContext,
): Promise<void> {
- const { writeLog, openpodRoot } = deps;
+ const { log, openpodRoot } = deps;
function isGitEnabled(dir: string): boolean {
try {
@@ -41,14 +41,14 @@ export async function registerPrompt(
}
return result.stdout.trim();
} catch (err) {
- writeLog(`failed to determine git root for ${dir}: ${err}`);
+ log(`failed to determine git root for ${dir}: ${err}`);
return null;
}
}
function cloneRepo(source: string, target: string): void {
try {
- writeLog(`cloning ${source} -> ${target}`);
+ log(`cloning ${source} -> ${target}`);
// Try to clone from the real remote (to get the latest default branch)
const remoteResult = spawnSync(
@@ -76,15 +76,15 @@ export async function registerPrompt(
const match = symrefResult.stdout.match(/ref: refs\/heads\/(\S+)/);
if (match) {
const branch = match[1];
- writeLog(`cloning latest default branch ${branch} from remote`);
+ log(`cloning latest default branch ${branch} from remote`);
cloneArgs = ["--branch", branch, remoteUrl, target];
} else {
- writeLog(
+ log(
`cloning from remote ${remoteUrl} (using remote default branch)`,
);
}
} else {
- writeLog(`cloning from remote ${remoteUrl} (default branch)`);
+ log(`cloning from remote ${remoteUrl} (default branch)`);
}
const result = spawnSync("git", ["clone", ...cloneArgs]);
@@ -97,7 +97,7 @@ export async function registerPrompt(
// Fallback: no "origin" remote, clone from local source and try to
// respect its origin/HEAD if present.
- writeLog(
+ log(
"no origin remote configured, falling back to local source clone",
);
@@ -113,11 +113,11 @@ export async function registerPrompt(
const ref = headRef.stdout.trim();
const branch = ref.replace(/^refs\/remotes\/origin\//, "");
if (branch) {
- writeLog(`cloning default branch ${branch} (from local origin/HEAD)`);
+ log(`cloning default branch ${branch} (from local origin/HEAD)`);
args = ["--branch", branch, source, target];
}
} else {
- writeLog("no origin/HEAD ref found, cloning source as-is");
+ log("no origin/HEAD ref found, cloning source as-is");
}
const result = spawnSync("git", ["clone", ...args]);
@@ -126,7 +126,7 @@ export async function registerPrompt(
}
copyRemotes(source, target);
} catch (err) {
- writeLog(`${err}`);
+ log(`${err}`);
try {
fs.rmSync(target, { recursive: true, force: true });
} catch {
@@ -137,7 +137,7 @@ export async function registerPrompt(
function copyRemotes(source: string, target: string): void {
try {
- writeLog(`copying remotes from ${source} to ${target}`);
+ log(`copying remotes from ${source} to ${target}`);
// clone always sets "origin" to point at the local source path;
// remove it so we can restore the original remotes (if any)
@@ -150,7 +150,7 @@ export async function registerPrompt(
stdio: ["ignore", "pipe", "ignore"],
});
if (listResult.status !== 0 || !listResult.stdout?.trim()) {
- writeLog("no remotes found in source (origin removed from clone)");
+ log("no remotes found in source (origin removed from clone)");
return;
}
@@ -180,7 +180,7 @@ export async function registerPrompt(
{ stdio: "ignore" },
);
if (addRes.status !== 0) {
- writeLog(`failed to add remote ${name} ${urls.fetch}`);
+ log(`failed to add remote ${name} ${urls.fetch}`);
}
}
if (urls.push && urls.push !== urls.fetch) {
@@ -192,9 +192,9 @@ export async function registerPrompt(
}
}
- writeLog(`copied ${Object.keys(remotes).length} remotes`);
+ log(`copied ${Object.keys(remotes).length} remotes`);
} catch (err) {
- writeLog(`copy remotes error: ${err}`);
+ log(`copy remotes error: ${err}`);
}
}
@@ -209,23 +209,23 @@ export async function registerPrompt(
}
}
- writeLog("registering prompt");
+ log("registering prompt");
await ctx.session.hook("prompt", async (event) => {
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}`);
+ log(`session ${event.sessionID} prompt - gitEnabled: ${gitEnabled}`);
const target = path.join(openpodRoot, event.sessionID);
const needsMove = dir !== target;
- writeLog(
+ log(
`needs move for project dir ${dir}? ${needsMove} (target=${target})`,
);
if (!gitEnabled) {
- writeLog(`git is not enabled`);
+ log(`git is not enabled`);
return;
}
@@ -234,7 +234,7 @@ export async function registerPrompt(
if (needsMove) {
if (fs.existsSync(target)) {
- writeLog(`${target} already exists`);
+ log(`${target} already exists`);
await ctx.session.move({
sessionID: event.sessionID,
directory: target,
@@ -243,28 +243,28 @@ export async function registerPrompt(
const repoRoot = getRepoRoot(dir);
if (!repoRoot) {
- writeLog(`failed to get repo root`);
+ log(`failed to get repo root`);
return;
}
- writeLog(`cloning ${repoRoot} -> ${target}`);
+ log(`cloning ${repoRoot} -> ${target}`);
fs.mkdirSync(openpodRoot, { recursive: true });
cloneRepo(repoRoot, target);
- writeLog(`clone complete, moving session to ${target}`);
+ log(`clone complete, moving session to ${target}`);
await ctx.session.move({
sessionID: event.sessionID,
directory: target,
});
}
} else {
- writeLog(`already in ${target} directory`);
+ log(`already in ${target} directory`);
}
// ensure lima instance for this pod
if (!limaInstanceExists(limaName)) {
- writeLog(`creating lima instance ${limaName} (mount-only ${podDir}:w)`);
+ log(`creating lima instance ${limaName} (mount-only ${podDir}:w)`);
const createResult = spawnSync(
"limactl",
[
@@ -279,16 +279,16 @@ export async function registerPrompt(
},
);
if (createResult.status !== 0) {
- writeLog(`limactl create exited with ${createResult.status}`);
+ log(`limactl create exited with ${createResult.status}`);
}
}
- writeLog(`starting lima instance ${limaName}`);
+ log(`starting lima instance ${limaName}`);
const startResult = spawnSync("limactl", ["start", limaName, "--yes"], {
stdio: "ignore",
});
if (startResult.status !== 0) {
- writeLog(`limactl start exited with ${startResult.status}`);
+ log(`limactl start exited with ${startResult.status}`);
}
});
}
diff --git a/shell.ts b/shell.ts
@@ -1,17 +1,17 @@
import type { Plugin } from "@opencode/plugin";
import * as path from "node:path";
-import type { OpenpodContext } from "./setup";
+import type { OpenpodContext } from "./context";
export async function registerShell(
ctx: Plugin.Context,
deps: OpenpodContext,
): Promise<void> {
- const { writeLog, openpodRoot } = deps;
+ const { log, openpodRoot } = deps;
function getLimaName(dir: string): string | null {
try {
- writeLog(`get lima name for ${openpodRoot} ${dir}`);
+ log(`get lima name for ${openpodRoot} ${dir}`);
const rel = path.relative(openpodRoot, dir);
if (rel.startsWith("..") || path.isAbsolute(rel)) {
return null;
@@ -23,7 +23,7 @@ export async function registerShell(
}
}
- writeLog("registering create.before");
+ log("registering create.before");
await ctx.shell.hook("create.before", async (event) => {
const limaName = getLimaName(event.cwd);
@@ -33,7 +33,7 @@ export async function registerShell(
const escapedCwd = event.cwd.replace(/'/g, "'\\''");
const escapedCmd = originalCommand.replace(/'/g, "'\\''");
event.command = `limactl shell --preserve-env --workdir='${escapedCwd}' ${limaName} bash -c '${escapedCmd}'`;
- writeLog(
+ log(
`redirected shell command for lima ${limaName} (cwd=${event.cwd})`,
);
}