Skip to content

Commit 8078652

Browse files
committed
fix(core): honor disabled project config in v2
1 parent 828a4b3 commit 8078652

2 files changed

Lines changed: 68 additions & 8 deletions

File tree

‎packages/core/src/config.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { ConfigVariable } from "./config/variable"
2828
import { ConfigWatcher } from "./config/watcher"
2929
import { ConfigV1 } from "./v1/config/config"
3030
import { ConfigMigrateV1 } from "./v1/config/migrate"
31+
import { Flag } from "./flag/flag"
3132

3233
export class Info extends Schema.Class<Info>("Config.Info")({
3334
$schema: Schema.optional(Schema.String).annotate({
@@ -194,14 +195,15 @@ const layer = Layer.effect(
194195
const globalAgentsDirectory = AbsolutePath.make(path.join(global.home, ".agents"))
195196
const globalClaudeDirectory = AbsolutePath.make(path.join(global.home, ".claude"))
196197
const locationIsGlobal = path.resolve(location.directory) === path.resolve(global.config)
197-
const discovered = locationIsGlobal
198-
? []
199-
: yield* fs
200-
.up({
201-
targets: [".opencode", ".claude", ".agents", ...names.toReversed()],
202-
start: location.directory,
203-
})
204-
.pipe(Effect.orDie)
198+
const discovered =
199+
locationIsGlobal || Flag.OPENCODE_DISABLE_PROJECT_CONFIG
200+
? []
201+
: yield* fs
202+
.up({
203+
targets: [".opencode", ".claude", ".agents", ...names.toReversed()],
204+
start: location.directory,
205+
})
206+
.pipe(Effect.orDie)
205207

206208
// We load certain files from a few other folders in the ecosystem
207209
const claude = [

‎packages/core/test/config/config.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,64 @@ describe("Config", () => {
254254
),
255255
)
256256

257+
it.live("skips project sources and preserves global config when project config is disabled", () =>
258+
Effect.acquireUseRelease(
259+
Effect.sync(() => {
260+
const previous = process.env.OPENCODE_DISABLE_PROJECT_CONFIG
261+
process.env.OPENCODE_DISABLE_PROJECT_CONFIG = "true"
262+
return previous
263+
}),
264+
() =>
265+
Effect.acquireUseRelease(
266+
Effect.promise(() => tmpdir()),
267+
(tmp) =>
268+
Effect.gen(function* () {
269+
const global = path.join(tmp.path, "global")
270+
const project = path.join(tmp.path, "project")
271+
yield* Effect.promise(async () => {
272+
await Promise.all([
273+
fs.mkdir(path.join(project, ".opencode"), { recursive: true }),
274+
fs.mkdir(path.join(project, ".claude"), { recursive: true }),
275+
fs.mkdir(path.join(project, ".agents"), { recursive: true }),
276+
fs.mkdir(global, { recursive: true }),
277+
])
278+
await Promise.all([
279+
fs.writeFile(path.join(project, "opencode.json"), JSON.stringify({ shell: "project" })),
280+
fs.writeFile(
281+
path.join(project, ".opencode", "opencode.json"),
282+
JSON.stringify({ username: "project" }),
283+
),
284+
fs.writeFile(path.join(global, "opencode.json"), JSON.stringify({ shell: "global" })),
285+
])
286+
})
287+
288+
const entries = yield* Config.Service.pipe(
289+
Effect.flatMap((config) => config.entries()),
290+
Effect.provide(testLayer(project, global, project)),
291+
)
292+
293+
expect(entries.filter((entry) => entry.type === "document")).toEqual([
294+
new Config.Document({
295+
type: "document",
296+
path: path.join(global, "opencode.json"),
297+
info: new Config.Info({ shell: "global" }),
298+
}),
299+
])
300+
expect(entries.filter((entry) => entry.type === "directory")).toEqual([
301+
new Config.Directory({ type: "directory", path: AbsolutePath.make(global) }),
302+
])
303+
expect(entries.filter((entry) => entry.type === "claude" || entry.type === "agents")).toEqual([])
304+
}),
305+
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
306+
),
307+
(previous) =>
308+
Effect.sync(() => {
309+
if (previous === undefined) delete process.env.OPENCODE_DISABLE_PROJECT_CONFIG
310+
else process.env.OPENCODE_DISABLE_PROJECT_CONFIG = previous
311+
}),
312+
),
313+
)
314+
257315
it.live("does not watch ecosystem config roots", () =>
258316
Effect.acquireRelease(
259317
Effect.promise(() => tmpdir()),

0 commit comments

Comments
 (0)