MCPcopy Create free account
hub / github.com/WJX20/claude-code / refreshPluginState

Function refreshPluginState

src/cli/print.ts:1763–1788  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1761 // settings were fetched. Without clearing, getCommands() would rebuild
1762 // from a stale plugin list.
1763 async function refreshPluginState(): Promise<void> {
1764 // refreshActivePlugins handles the full cache sweep (clearAllCaches),
1765 // reloads all plugin component loaders, writes AppState.plugins +
1766 // AppState.agentDefinitions, registers hooks, and bumps mcp.pluginReconnectKey.
1767 const { agentDefinitions: freshAgentDefs } =
1768 await refreshActivePlugins(setAppState)
1769
1770 // Headless-specific: currentCommands/currentAgents are local mutable refs
1771 // captured by the query loop (REPL uses AppState instead). getCommands is
1772 // fresh because refreshActivePlugins cleared its cache.
1773 currentCommands = await getCommands(cwd())
1774
1775 // Preserve SDK-provided agents (--agents CLI flag or SDK initialize
1776 // control_request) — both inject via parseAgentsFromJson with
1777 // source='flagSettings'. loadMarkdownFilesForSubdir never assigns this
1778 // source, so it cleanly discriminates "injected, not disk-loadable".
1779 //
1780 // The previous filter used a negative set-diff (!freshAgentTypes.has(a))
1781 // which also matched plugin agents that were in the poisoned initial
1782 // currentAgents but correctly excluded from freshAgentDefs after managed
1783 // settings applied — leaking policy-blocked agents into the init message.
1784 // See gh-23085: isBridgeEnabled() at Commander-definition time poisoned
1785 // the settings cache before setEligibility(true) ran.
1786 const sdkAgents = currentAgents.filter(a => a.source === 'flagSettings')
1787 currentAgents = [...freshAgentDefs.allAgents, ...sdkAgents]
1788 }
1789
1790 // Re-diff MCP configs after plugin state changes. Filters to
1791 // process-transport-supported types and carries SDK-mode servers through

Callers 1

runFunction · 0.85

Calls 3

refreshActivePluginsFunction · 0.85
getCommandsFunction · 0.85
cwdFunction · 0.85

Tested by

no test coverage detected