Skip to content

Commit 02f41dd

Browse files
committed
refactor(core): share optional root discovery
Extract the duplicated claude/agents root building into an optionalRoots helper: roots vanish when disabled, and the global directory joins only while the global scope is enabled. No behavior change; covered by the config discovery tests.
1 parent eaa5aa4 commit 02f41dd

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

‎packages/core/src/config/discovery.ts‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ export const discover = Effect.fn("ConfigDiscovery.discover")(function* (options
6262
)
6363
.map(({ item }) => item)
6464

65+
// Optional roots vanish when disabled; their global directory joins only
66+
// while the global scope is enabled.
67+
const optionalRoots = (name: string, globalPath: AbsolutePath, enabled = true) =>
68+
enabled
69+
? [
70+
...new Set([
71+
...(globalEnabled ? [globalPath] : []),
72+
...visible.filter((item) => path.basename(item) === name).toReversed(),
73+
]),
74+
]
75+
: []
76+
6577
return {
6678
global: globalEnabled ? globalDirectory : undefined,
6779
explicit: options?.file ? AbsolutePath.make(path.resolve(options.file)) : undefined,
@@ -70,19 +82,7 @@ export const discover = Effect.fn("ConfigDiscovery.discover")(function* (options
7082
visible.filter((item) => path.basename(item) === ".opencode").toReversed(),
7183
(directory) => fs.isDir(directory).pipe(Effect.map((present) => ({ path: directory, present }))),
7284
),
73-
claude: disableClaudeCode
74-
? []
75-
: [
76-
...new Set([
77-
...(globalEnabled ? [globalClaudeDirectory] : []),
78-
...visible.filter((item) => path.basename(item) === ".claude").toReversed(),
79-
]),
80-
],
81-
agents: [
82-
...new Set([
83-
...(globalEnabled ? [globalAgentsDirectory] : []),
84-
...visible.filter((item) => path.basename(item) === ".agents").toReversed(),
85-
]),
86-
],
85+
claude: optionalRoots(".claude", globalClaudeDirectory, !disableClaudeCode),
86+
agents: optionalRoots(".agents", globalAgentsDirectory),
8787
} satisfies Sources
8888
})

0 commit comments

Comments
 (0)