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

Function mergePluginSources

source code/utils/plugins/pluginLoader.ts:3011–3066  ·  view source on GitHub ↗
(sources: {
  session: LoadedPlugin[]
  marketplace: LoadedPlugin[]
  builtin: LoadedPlugin[]
  managedNames?: Set<string> | null
})

Source from the content-addressed store, hash-verified

3009 * installed plugin.
3010 */
3011export function mergePluginSources(sources: {
3012 session: LoadedPlugin[]
3013 marketplace: LoadedPlugin[]
3014 builtin: LoadedPlugin[]
3015 managedNames?: Set<string> | null
3016}): { plugins: LoadedPlugin[]; errors: PluginError[] } {
3017 const errors: PluginError[] = []
3018 const managed = sources.managedNames
3019
3020 // Managed settings win over --plugin-dir. Drop session plugins whose
3021 // name appears in policySettings.enabledPlugins (whether force-enabled
3022 // OR force-disabled — both are admin intent that --plugin-dir must not
3023 // bypass). Surface an error so the user knows why their dev copy was
3024 // ignored.
3025 //
3026 // NOTE: managedNames contains the pluginId prefix (entry.name), which is
3027 // expected to equal manifest.name by convention (schema description at
3028 // schemas.ts PluginMarketplaceEntry.name). If a marketplace publishes a
3029 // plugin where entry.name ≠ manifest.name, this guard will silently miss —
3030 // but that's a marketplace misconfiguration that breaks other things too
3031 // (e.g., ManagePlugins constructs pluginIds from manifest.name).
3032 const sessionPlugins = sources.session.filter(p => {
3033 if (managed?.has(p.name)) {
3034 logForDebugging(
3035 `Plugin "${p.name}" from --plugin-dir is blocked by managed settings`,
3036 { level: 'warn' },
3037 )
3038 errors.push({
3039 type: 'generic-error',
3040 source: p.source,
3041 plugin: p.name,
3042 error: `--plugin-dir copy of "${p.name}" ignored: plugin is locked by managed settings`,
3043 })
3044 return false
3045 }
3046 return true
3047 })
3048
3049 const sessionNames = new Set(sessionPlugins.map(p => p.name))
3050 const marketplacePlugins = sources.marketplace.filter(p => {
3051 if (sessionNames.has(p.name)) {
3052 logForDebugging(
3053 `Plugin "${p.name}" from --plugin-dir overrides installed version`,
3054 )
3055 return false
3056 }
3057 return true
3058 })
3059 // Session first, then non-overridden marketplace, then builtin.
3060 // Downstream first-match consumers see session plugins before
3061 // installed ones for any that slipped past the name filter.
3062 return {
3063 plugins: [...sessionPlugins, ...marketplacePlugins, ...sources.builtin],
3064 errors,
3065 }
3066}
3067
3068/**

Callers 1

assemblePluginLoadResultFunction · 0.85

Calls 2

logForDebuggingFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected