MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / loadPluginSettings

Function loadPluginSettings

source code/utils/plugins/pluginLoader.ts:1809–1851  ·  view source on GitHub ↗

* Load plugin settings from settings.json file or manifest.settings. * settings.json takes priority over manifest.settings when both exist. * Only allowlisted keys are included in the result.

(
  pluginPath: string,
  manifest: PluginManifest,
)

Source from the content-addressed store, hash-verified

1807 * Only allowlisted keys are included in the result.
1808 */
1809async function loadPluginSettings(
1810 pluginPath: string,
1811 manifest: PluginManifest,
1812): Promise<Record<string, unknown> | undefined> {
1813 // Try loading settings.json from the plugin directory
1814 const settingsJsonPath = join(pluginPath, 'settings.json')
1815 try {
1816 const content = await readFile(settingsJsonPath, { encoding: 'utf-8' })
1817 const parsed = jsonParse(content)
1818 if (isRecord(parsed)) {
1819 const filtered = parsePluginSettings(parsed)
1820 if (filtered) {
1821 logForDebugging(
1822 `Loaded settings from settings.json for plugin ${manifest.name}`,
1823 )
1824 return filtered
1825 }
1826 }
1827 } catch (e: unknown) {
1828 // Missing/inaccessible is expected - settings.json is optional
1829 if (!isFsInaccessible(e)) {
1830 logForDebugging(
1831 `Failed to parse settings.json for plugin ${manifest.name}: ${e}`,
1832 { level: 'warn' },
1833 )
1834 }
1835 }
1836
1837 // Fall back to manifest.settings
1838 if (manifest.settings) {
1839 const filtered = parsePluginSettings(
1840 manifest.settings as Record<string, unknown>,
1841 )
1842 if (filtered) {
1843 logForDebugging(
1844 `Loaded settings from manifest for plugin ${manifest.name}`,
1845 )
1846 return filtered
1847 }
1848 }
1849
1850 return undefined
1851}
1852
1853/**
1854 * Merge two HooksSettings objects

Callers 1

createPluginFromPathFunction · 0.85

Calls 6

readFileFunction · 0.85
jsonParseFunction · 0.85
parsePluginSettingsFunction · 0.85
logForDebuggingFunction · 0.85
isFsInaccessibleFunction · 0.85
isRecordFunction · 0.70

Tested by

no test coverage detected