diff --git a/packages/adapters/opencode-local/README.md b/packages/adapters/opencode-local/README.md new file mode 100644 index 00000000000..13c7bdd4441 --- /dev/null +++ b/packages/adapters/opencode-local/README.md @@ -0,0 +1,13 @@ +# OpenCode local adapter + +## Runtime configuration + +`prepareOpenCodeRuntimeConfig` stages an isolated OpenCode configuration directory +on the host for both local and remote execution targets. It copies the operator +configuration and applies the runtime provider and permission settings. Its +returned `XDG_CONFIG_HOME` points to that host directory. + +For remote execution, `execute` and `testEnvironment` pass the staged directory +to `prepareAdapterExecutionTargetRuntime` as the `xdgConfig` asset. They replace +`XDG_CONFIG_HOME` with the asset's remote destination before running OpenCode. +The helper's cleanup function removes the host staging directory. diff --git a/packages/adapters/opencode-local/src/server/runtime-config.test.ts b/packages/adapters/opencode-local/src/server/runtime-config.test.ts index c1c96bbf893..de8d940743e 100644 --- a/packages/adapters/opencode-local/src/server/runtime-config.test.ts +++ b/packages/adapters/opencode-local/src/server/runtime-config.test.ts @@ -34,6 +34,29 @@ async function makeConfigHome(initialConfig?: Record) { } describe("prepareOpenCodeRuntimeConfig", () => { + it("stages isolated configuration for remote asset transfer even with remote target metadata", async () => { + const configHome = await makeConfigHome({ theme: "system" }); + const input = { + env: { XDG_CONFIG_HOME: configHome }, + config: { model: "gateway/test-model" }, + targetIsRemote: true, + }; + const prepared = await prepareOpenCodeRuntimeConfig(input); + expect(prepared.env.XDG_CONFIG_HOME).not.toBe(configHome); + cleanupPaths.add(prepared.env.XDG_CONFIG_HOME); + expect(JSON.parse(await fs.readFile( + path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8", + ))).toMatchObject({ + theme: "system", + permission: "allow", + provider: { gateway: { models: { "test-model": {} } } }, + }); + await prepared.cleanup(); + await expect(fs.stat(prepared.env.XDG_CONFIG_HOME)).rejects.toMatchObject({ code: "ENOENT" }); + expect(JSON.parse(await fs.readFile(path.join(configHome, "opencode", "opencode.json"), "utf8"))) + .toEqual({ theme: "system" }); + }); + it("stages a relocatable sandbox shell hook without changing the parent environment", async () => { const configHome = await makeConfigHome({ plugin: ["operator-plugin"], permission: { bash: "ask" } }); const input = { env: { XDG_CONFIG_HOME: configHome }, config: { dangerouslySkipPermissions: false }, sandboxToolOomPreference: true }; diff --git a/packages/adapters/opencode-local/src/server/runtime-config.ts b/packages/adapters/opencode-local/src/server/runtime-config.ts index 9dc6ec4208b..1b25d1e1dd0 100644 --- a/packages/adapters/opencode-local/src/server/runtime-config.ts +++ b/packages/adapters/opencode-local/src/server/runtime-config.ts @@ -107,24 +107,10 @@ async function readJsonObject(filepath: string): Promise export async function prepareOpenCodeRuntimeConfig(input: { env: Record; config: Record; - targetIsRemote?: boolean; sandboxToolOomPreference?: boolean; }): Promise { const skipPermissions = asBoolean(input.config.dangerouslySkipPermissions, true); - // For remote execution targets the host XDG_CONFIG_HOME path is meaningless - // (and actively harmful — it leaks a macOS-only path into the remote Linux - // env). Callers that need to ship a runtime opencode config to the remote - // box do that via prepareAdapterExecutionTargetRuntime in execute.ts; this - // host-fs helper is local-only. - if (input.targetIsRemote) { - return { - env: input.env, - notes: [], - cleanup: async () => {}, - }; - } - const sourceConfigDir = path.join(resolveXdgConfigHome(input.env), "opencode"); const runtimeConfigHome = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-opencode-config-")); const runtimeConfigDir = path.join(runtimeConfigHome, "opencode");