summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-07-10 11:45:31 -0400
committerDax Raad <[email protected]>2025-07-10 11:45:31 -0400
commitb5d690620df8b79dfb3d191e6c14a39c6e7ee891 (patch)
tree3809412c4a08646bd432d4619da51e8fc827d4d1
parent9db3ce1d0bd5e76494e34050b19f42a1c30ff399 (diff)
downloadopencode-b5d690620df8b79dfb3d191e6c14a39c6e7ee891.tar.gz
opencode-b5d690620df8b79dfb3d191e6c14a39c6e7ee891.zip
support env and file pointers in config
-rw-r--r--packages/opencode/src/config/config.ts35
1 files changed, 28 insertions, 7 deletions
diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts
index b9614a3f5..740580d5e 100644
--- a/packages/opencode/src/config/config.ts
+++ b/packages/opencode/src/config/config.ts
@@ -195,19 +195,40 @@ export namespace Config {
return result
})
- async function load(path: string) {
- const data = await Bun.file(path)
- .json()
+ async function load(configPath: string) {
+ let text = await Bun.file(configPath)
+ .text()
.catch((err) => {
- if (err.code === "ENOENT") return {}
- throw new JsonError({ path }, { cause: err })
+ if (err.code === "ENOENT") return "{}"
+ throw new JsonError({ path: configPath }, { cause: err })
})
+ text = text.replace(/\{env:([^}]+)\}/g, (_, varName) => {
+ return process.env[varName] || ""
+ })
+
+ const fileMatches = text.match(/\{file:([^}]+)\}/g)
+ if (fileMatches) {
+ const configDir = path.dirname(configPath)
+ for (const match of fileMatches) {
+ const filePath = match.slice(6, -1)
+ const resolvedPath = path.isAbsolute(filePath) ? filePath : path.resolve(configDir, filePath)
+ const fileContent = await Bun.file(resolvedPath).text()
+ text = text.replace(match, fileContent)
+ }
+ }
+
+ let data: any
+ try {
+ data = JSON.parse(text)
+ } catch (err) {
+ throw new JsonError({ path: configPath }, { cause: err as Error })
+ }
+
const parsed = Info.safeParse(data)
if (parsed.success) return parsed.data
- throw new InvalidError({ path, issues: parsed.error.issues })
+ throw new InvalidError({ path: configPath, issues: parsed.error.issues })
}
-
export const JsonError = NamedError.create(
"ConfigJsonError",
z.object({