fix(opencode): prevent opencode.json config pollution in workspace

Set OPENCODE_DISABLE_PROJECT_CONFIG=true in all OpenCode invocations
(execute, model discovery, environment test) to stop the OpenCode CLI
from writing an opencode.json file into the project working directory.
Model selection is already passed via the --model CLI flag.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Devin Foley 2026-03-25 17:22:49 -07:00
parent db3883d2e7
commit 72bc4ab403
4 changed files with 11 additions and 1 deletions

View file

@ -37,4 +37,7 @@ Notes:
- Paperclip requires an explicit \`model\` value for \`opencode_local\` agents. - Paperclip requires an explicit \`model\` value for \`opencode_local\` agents.
- Runs are executed with: opencode run --format json ... - Runs are executed with: opencode run --format json ...
- Sessions are resumed with --session when stored session cwd matches current cwd. - Sessions are resumed with --session when stored session cwd matches current cwd.
- The adapter sets OPENCODE_DISABLE_PROJECT_CONFIG=true to prevent OpenCode from \
writing an opencode.json config file into the project working directory. Model \
selection is passed via the --model CLI flag instead.
`; `;

View file

@ -128,6 +128,10 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
const hasExplicitApiKey = const hasExplicitApiKey =
typeof envConfig.PAPERCLIP_API_KEY === "string" && envConfig.PAPERCLIP_API_KEY.trim().length > 0; typeof envConfig.PAPERCLIP_API_KEY === "string" && envConfig.PAPERCLIP_API_KEY.trim().length > 0;
const env: Record<string, string> = { ...buildPaperclipEnv(agent) }; const env: Record<string, string> = { ...buildPaperclipEnv(agent) };
// Prevent OpenCode from writing an opencode.json config file into the
// project working directory (which would pollute the git repo). Model
// selection is already handled via the --model CLI flag.
env.OPENCODE_DISABLE_PROJECT_CONFIG = "true";
env.PAPERCLIP_RUN_ID = runId; env.PAPERCLIP_RUN_ID = runId;
const wakeTaskId = const wakeTaskId =
(typeof context.taskId === "string" && context.taskId.trim().length > 0 && context.taskId.trim()) || (typeof context.taskId === "string" && context.taskId.trim().length > 0 && context.taskId.trim()) ||

View file

@ -120,7 +120,8 @@ export async function discoverOpenCodeModels(input: {
// /etc/passwd entry (e.g. `docker run --user 1234` with a minimal // /etc/passwd entry (e.g. `docker run --user 1234` with a minimal
// image). Fall back to process.env.HOME. // image). Fall back to process.env.HOME.
} }
const runtimeEnv = normalizeEnv(ensurePathInEnv({ ...process.env, ...env, ...(resolvedHome ? { HOME: resolvedHome } : {}) })); // Prevent OpenCode from writing an opencode.json into the working directory.
const runtimeEnv = normalizeEnv(ensurePathInEnv({ ...process.env, ...env, ...(resolvedHome ? { HOME: resolvedHome } : {}), OPENCODE_DISABLE_PROJECT_CONFIG: "true" }));
const result = await runChildProcess( const result = await runChildProcess(
`opencode-models-${Date.now()}-${Math.random().toString(16).slice(2)}`, `opencode-models-${Date.now()}-${Math.random().toString(16).slice(2)}`,

View file

@ -90,6 +90,8 @@ export async function testEnvironment(
}); });
} }
// Prevent OpenCode from writing an opencode.json into the working directory.
env.OPENCODE_DISABLE_PROJECT_CONFIG = "true";
const runtimeEnv = normalizeEnv(ensurePathInEnv({ ...process.env, ...env })); const runtimeEnv = normalizeEnv(ensurePathInEnv({ ...process.env, ...env }));
const cwdInvalid = checks.some((check) => check.code === "opencode_cwd_invalid"); const cwdInvalid = checks.some((check) => check.code === "opencode_cwd_invalid");