From 90d1698aed2e9f0d27dbd6fb854ebcce7a06b9f5 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Fri, 1 Aug 2025 08:39:21 -0500 Subject: [PATCH] fix: {file:...} references weren't being parsed correctly in some cases (#1499) --- packages/opencode/src/config/config.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index 533975f1..3d933a15 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)) } }