summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAiden Cline <[email protected]>2025-08-01 08:39:21 -0500
committerGitHub <[email protected]>2025-08-01 08:39:21 -0500
commit90d1698aed2e9f0d27dbd6fb854ebcce7a06b9f5 (patch)
tree7467ce170ba43eeb96905c58ba55d2727fd83454
parentb0c38ce56b61c157d06ca1cf9b36e3287666a1db (diff)
downloadopencode-90d1698aed2e9f0d27dbd6fb854ebcce7a06b9f5.tar.gz
opencode-90d1698aed2e9f0d27dbd6fb854ebcce7a06b9f5.zip
fix: {file:...} references weren't being parsed correctly in some cases (#1499)
-rw-r--r--packages/opencode/src/config/config.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts
index 533975f14..3d933a152 100644
--- a/packages/opencode/src/config/config.ts
+++ b/packages/opencode/src/config/config.ts
@@ -373,14 +373,21 @@ export namespace Config {
return process.env[varName] || ""
})
- const fileMatches = text.match(/"?\{file:([^}]+)\}"?/g)
+ const fileMatches = text.match(/\{file:[^}]+\}/g)
if (fileMatches) {
const configDir = path.dirname(configPath)
+ const lines = text.split("\n")
+
for (const match of fileMatches) {
- const filePath = match.replace(/^"?\{file:/, "").replace(/\}"?$/, "")
+ const lineIndex = lines.findIndex((line) => line.includes(match))
+ if (lineIndex !== -1 && lines[lineIndex].trim().startsWith("//")) {
+ continue // Skip if line is commented
+ }
+ const filePath = match.replace(/^\{file:/, "").replace(/\}$/, "")
const resolvedPath = path.isAbsolute(filePath) ? filePath : path.resolve(configDir, filePath)
- const fileContent = await Bun.file(resolvedPath).text()
- text = text.replace(match, JSON.stringify(fileContent))
+ const fileContent = (await Bun.file(resolvedPath).text()).trim()
+ // escape newlines/quotes, strip outer quotes
+ text = text.replace(match, JSON.stringify(fileContent).slice(1, -1))
}
}