Skip to content

Commit ec763b9

Browse files
committed
fix(config): avoid writeback for inline config content
1 parent e497d3a commit ec763b9

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/opencode/src/config/config.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ export namespace Config {
185185
if (Flag.OPENCODE_CONFIG_CONTENT) {
186186
result = merge(
187187
result,
188-
await load(Flag.OPENCODE_CONFIG_CONTENT, path.join(Instance.directory, "OPENCODE_CONFIG_CONTENT")),
188+
await load(Flag.OPENCODE_CONFIG_CONTENT, path.join(Instance.directory, "OPENCODE_CONFIG_CONTENT"), {
189+
writeback: false,
190+
}),
189191
)
190192
log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
191193
}
@@ -1292,7 +1294,8 @@ export namespace Config {
12921294
return load(text, filepath)
12931295
}
12941296

1295-
async function load(text: string, configFilepath: string) {
1297+
async function load(text: string, configFilepath: string, options: { writeback?: boolean } = {}) {
1298+
const writeback = options.writeback ?? true
12961299
const original = text
12971300
text = text.replace(/\{env:([^}]+)\}/g, (_, varName) => {
12981301
return process.env[varName] || ""
@@ -1361,9 +1364,11 @@ export namespace Config {
13611364
if (parsed.success) {
13621365
if (!parsed.data.$schema) {
13631366
parsed.data.$schema = "https://opencode.ai/config.json"
1364-
// Write the $schema to the original text to preserve variables like {env:VAR}
1365-
const updated = original.replace(/^\s*\{/, '{\n "$schema": "https://opencode.ai/config.json",')
1366-
await Filesystem.write(configFilepath, updated).catch(() => {})
1367+
if (writeback) {
1368+
// Write the $schema to the original text to preserve variables like {env:VAR}
1369+
const updated = original.replace(/^\s*\{/, '{\n "$schema": "https://opencode.ai/config.json",')
1370+
await Filesystem.write(configFilepath, updated).catch(() => {})
1371+
}
13671372
}
13681373
const data = parsed.data
13691374
if (data.plugin) {

packages/opencode/test/config/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,7 @@ describe("OPENCODE_CONFIG_CONTENT precedence", () => {
18991899
expect(config.auth?.enabled).toBe(false)
19001900
},
19011901
})
1902+
expect(await Bun.file(path.join(tmp.path, "project", "OPENCODE_CONFIG_CONTENT")).exists()).toBe(false)
19021903
} finally {
19031904
if (originalInlineConfig === undefined) {
19041905
delete process.env["OPENCODE_CONFIG_CONTENT"]

0 commit comments

Comments
 (0)