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