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

Function refreshActivePlugins

source code/utils/plugins/refresh.ts:74–193  ·  view source on GitHub ↗
(
  setAppState: SetAppState,
)

Source from the content-addressed store, hash-verified

72 * re-reads config. Servers are lazy-started so this is just config parsing.
73 */
74export async function refreshActivePlugins(
75 setAppState: SetAppState,
76): Promise<RefreshActivePluginsResult> {
77 logForDebugging('refreshActivePlugins: clearing all plugin caches')
78 clearAllCaches()
79 // Orphan exclusions are session-frozen by default, but /reload-plugins is
80 // an explicit "disk changed, re-read it" signal — recompute them too.
81 clearPluginCacheExclusions()
82
83 // Sequence the full load before cache-only consumers. Before #23693 all
84 // three shared loadAllPlugins()'s memoize promise so Promise.all was a
85 // no-op race. After #23693 getPluginCommands/getAgentDefinitions call
86 // loadAllPluginsCacheOnly (separate memoize) — racing them means they
87 // read installed_plugins.json before loadAllPlugins() has cloned+cached
88 // the plugin, returning plugin-cache-miss. loadAllPlugins warms the
89 // cache-only memoize on completion, so the awaits below are ~free.
90 const pluginResult = await loadAllPlugins()
91 const [pluginCommands, agentDefinitions] = await Promise.all([
92 getPluginCommands(),
93 getAgentDefinitionsWithOverrides(getOriginalCwd()),
94 ])
95
96 const { enabled, disabled, errors } = pluginResult
97
98 // Populate mcpServers/lspServers on each enabled plugin. These are lazy
99 // cache slots NOT filled by loadAllPlugins() — they're written later by
100 // extractMcpServersFromPlugins/getPluginLspServers, which races with this.
101 // Loading here gives accurate metrics AND warms the cache slots so the MCP
102 // connection manager (triggered by pluginReconnectKey bump) sees the servers
103 // without re-parsing manifests. Errors are pushed to the shared errors array.
104 const [mcpCounts, lspCounts] = await Promise.all([
105 Promise.all(
106 enabled.map(async p => {
107 if (p.mcpServers) return Object.keys(p.mcpServers).length
108 const servers = await loadPluginMcpServers(p, errors)
109 if (servers) p.mcpServers = servers
110 return servers ? Object.keys(servers).length : 0
111 }),
112 ),
113 Promise.all(
114 enabled.map(async p => {
115 if (p.lspServers) return Object.keys(p.lspServers).length
116 const servers = await loadPluginLspServers(p, errors)
117 if (servers) p.lspServers = servers
118 return servers ? Object.keys(servers).length : 0
119 }),
120 ),
121 ])
122 const mcp_count = mcpCounts.reduce((sum, n) => sum + n, 0)
123 const lsp_count = lspCounts.reduce((sum, n) => sum + n, 0)
124
125 setAppState(prev => ({
126 ...prev,
127 plugins: {
128 ...prev.plugins,
129 enabled,
130 disabled,
131 commands: pluginCommands,

Callers 4

callFunction · 0.85
refreshPluginStateFunction · 0.85
runHeadlessStreamingFunction · 0.85

Calls 13

logForDebuggingFunction · 0.85
clearAllCachesFunction · 0.85
loadAllPluginsFunction · 0.85
getOriginalCwdFunction · 0.85
loadPluginMcpServersFunction · 0.85
loadPluginLspServersFunction · 0.85
mergePluginErrorsFunction · 0.85
loadPluginHooksFunction · 0.85
keysMethod · 0.80
logErrorFunction · 0.50

Tested by

no test coverage detected