forked from ultraworkers/claw-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddDirPluginSettings.ts
More file actions
71 lines (66 loc) · 2.27 KB
/
Copy pathaddDirPluginSettings.ts
File metadata and controls
71 lines (66 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Reads plugin-related settings (enabledPlugins, extraKnownMarketplaces)
* from --add-dir directories.
*
* These have the LOWEST priority — callers must spread standard settings
* on top so that user/project/local/flag/policy sources all override.
*/
import { join } from 'path'
import type { z } from 'zod/v4'
import { getAdditionalDirectoriesForClaudeMd } from '../../bootstrap/state.js'
import { parseSettingsFile } from '../settings/settings.js'
import type {
ExtraKnownMarketplaceSchema,
SettingsJson,
} from '../settings/types.js'
type ExtraKnownMarketplace = z.infer<
ReturnType<typeof ExtraKnownMarketplaceSchema>
>
const SETTINGS_FILES = ['settings.json', 'settings.local.json'] as const
/**
* Returns a merged record of enabledPlugins from all --add-dir directories.
*
* Within each directory, settings.local.json is processed after settings.json
* (local wins within that dir). Across directories, later CLI-order wins on
* conflict.
*
* This has the lowest priority — callers must spread their standard settings
* on top to let user/project/local/flag/policy override.
*/
export function getAddDirEnabledPlugins(): NonNullable<
SettingsJson['enabledPlugins']
> {
const result: NonNullable<SettingsJson['enabledPlugins']> = {}
for (const dir of getAdditionalDirectoriesForClaudeMd()) {
for (const file of SETTINGS_FILES) {
const { settings } = parseSettingsFile(join(dir, '.claude', file))
if (!settings?.enabledPlugins) {
continue
}
Object.assign(result, settings.enabledPlugins)
}
}
return result
}
/**
* Returns a merged record of extraKnownMarketplaces from all --add-dir directories.
*
* Same priority rules as getAddDirEnabledPlugins: settings.local.json wins
* within each dir, and callers spread standard settings on top.
*/
export function getAddDirExtraMarketplaces(): Record<
string,
ExtraKnownMarketplace
> {
const result: Record<string, ExtraKnownMarketplace> = {}
for (const dir of getAdditionalDirectoriesForClaudeMd()) {
for (const file of SETTINGS_FILES) {
const { settings } = parseSettingsFile(join(dir, '.claude', file))
if (!settings?.extraKnownMarketplaces) {
continue
}
Object.assign(result, settings.extraKnownMarketplaces)
}
}
return result
}