fix(config): load configs across git boundaries (#36568)
Co-authored-by: Dax Raad <thdxr@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
This commit is contained in:
parent
f8f8cc9546
commit
6e55ddd078
4 changed files with 38 additions and 13 deletions
|
|
@ -404,7 +404,7 @@ const layer = Layer.effect(
|
|||
}
|
||||
|
||||
if (!Flag.OPENCODE_DISABLE_PROJECT_CONFIG) {
|
||||
for (const file of yield* ConfigPaths.files("opencode", ctx.directory, ctx.worktree).pipe(Effect.orDie)) {
|
||||
for (const file of yield* ConfigPaths.files("opencode", ctx.directory).pipe(Effect.orDie)) {
|
||||
yield* merge(file, yield* loadFile(file, authEnv), "local")
|
||||
}
|
||||
}
|
||||
|
|
@ -413,7 +413,7 @@ const layer = Layer.effect(
|
|||
result.mode = result.mode || {}
|
||||
result.plugin = result.plugin || []
|
||||
|
||||
const directories = yield* ConfigPaths.directories(ctx.directory, ctx.worktree)
|
||||
const directories = yield* ConfigPaths.directories(ctx.directory)
|
||||
|
||||
if (Flag.OPENCODE_CONFIG_DIR) {
|
||||
yield* Effect.logDebug("loading config from OPENCODE_CONFIG_DIR", { path: Flag.OPENCODE_CONFIG_DIR })
|
||||
|
|
|
|||
|
|
@ -7,29 +7,23 @@ import { unique } from "remeda"
|
|||
import * as Effect from "effect/Effect"
|
||||
import { FSUtil } from "@opencode-ai/core/fs-util"
|
||||
|
||||
export const files = Effect.fn("ConfigPaths.projectFiles")(function* (
|
||||
name: string,
|
||||
directory: string,
|
||||
worktree?: string,
|
||||
) {
|
||||
export const files = Effect.fn("ConfigPaths.projectFiles")(function* (name: string, directory: string) {
|
||||
const afs = yield* FSUtil.Service
|
||||
return (yield* afs.up({
|
||||
targets: [`${name}.jsonc`, `${name}.json`],
|
||||
start: directory,
|
||||
stop: worktree,
|
||||
})).toReversed()
|
||||
})
|
||||
|
||||
export const directories = Effect.fn("ConfigPaths.directories")(function* (directory: string, worktree?: string) {
|
||||
export const directories = Effect.fn("ConfigPaths.directories")(function* (directory: string) {
|
||||
const afs = yield* FSUtil.Service
|
||||
return unique([
|
||||
Global.Path.config,
|
||||
...(!Flag.OPENCODE_DISABLE_PROJECT_CONFIG
|
||||
? yield* afs.up({
|
||||
? (yield* afs.up({
|
||||
targets: [".opencode"],
|
||||
start: directory,
|
||||
stop: worktree,
|
||||
})
|
||||
})).toReversed()
|
||||
: []),
|
||||
...(yield* afs.up({
|
||||
targets: [".opencode"],
|
||||
|
|
|
|||
|
|
@ -999,6 +999,37 @@ it.instance("resolves scoped npm plugins in config", () =>
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("loads shared config above a child git repository", () =>
|
||||
Effect.gen(function* () {
|
||||
const root = yield* tmpdirScoped()
|
||||
const global = yield* tmpdirScoped()
|
||||
const workspace = path.join(root, "workspace")
|
||||
const project = path.join(workspace, "project")
|
||||
|
||||
yield* writeConfigEffect(path.join(workspace, ".opencode"), {
|
||||
model: "shared/model",
|
||||
username: "shared-user",
|
||||
})
|
||||
yield* writeConfigEffect(path.join(project, ".opencode"), { username: "project-user" })
|
||||
yield* Effect.promise(async () => {
|
||||
const child = Bun.spawn(["git", "init"], { cwd: project, stdout: "ignore", stderr: "ignore" })
|
||||
await child.exited
|
||||
})
|
||||
|
||||
yield* withGlobalConfigDir(
|
||||
global,
|
||||
withInstanceDir(
|
||||
project,
|
||||
Effect.gen(function* () {
|
||||
const config = yield* Config.use.get()
|
||||
expect(config.model).toBe("shared/model")
|
||||
expect(config.username).toBe("project-user")
|
||||
}),
|
||||
),
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("merges plugin arrays from global and local configs", () =>
|
||||
withConfigTree(
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue