diff --git a/src/cli/command-catalog.ts b/src/cli/command-catalog.ts index d3b01987d9b..ede0e796e7b 100644 --- a/src/cli/command-catalog.ts +++ b/src/cli/command-catalog.ts @@ -73,6 +73,12 @@ export const cliCommandCatalog: readonly CliCommandCatalogEntry[] = [ }, { commandPath: ["agents", "list"], + // JSON callers (dashboards, monitoring scripts, IDE plugins) poll this + // command and don't need the plugin-derived `providers` enrichment that + // is only used in human text output. text-only skips the bundled-plugin + // import waterfall in `--json` mode, mirroring what `channels list` + // already does. Human (non-JSON) invocations still load plugins. (#71739) + policy: { loadPlugins: "text-only" }, route: { id: "agents-list" }, }, { diff --git a/src/cli/command-startup-policy.test.ts b/src/cli/command-startup-policy.test.ts index 051c0bbbdcf..6bf36f6f5a3 100644 --- a/src/cli/command-startup-policy.test.ts +++ b/src/cli/command-startup-policy.test.ts @@ -80,6 +80,15 @@ describe("command-startup-policy", () => { jsonOutputMode: false, }), ).toBe(true); + // text-only opts agents list out of plugin preload in --json mode so + // dashboards/scripts that poll this command don't pay the bundled-plugin + // import waterfall when they only consume config-derived fields. (#71739) + expect( + shouldLoadPluginsForCommandPath({ + commandPath: ["agents", "list"], + jsonOutputMode: true, + }), + ).toBe(false); }); it("matches banner suppression policy", () => { diff --git a/src/commands/agents.commands.list.ts b/src/commands/agents.commands.list.ts index b18b4a4b8f4..720def19074 100644 --- a/src/commands/agents.commands.list.ts +++ b/src/commands/agents.commands.list.ts @@ -99,7 +99,14 @@ export async function agentsListCommand( } } - const providerStatus = await buildProviderStatusIndex(cfg); + // `buildProviderStatusIndex` triggers on-demand plugin loads and is only + // used for human text output (`summary.providers` is rendered in the text + // formatter). JSON callers (dashboards, monitors, IDE plugins) poll this + // command and don't need provider enrichment, so skip the plugin load when + // emitting JSON — combined with `loadPlugins: "text-only"` in the catalog + // entry, this drops `agents list --json` cold time from ~9s to sub-second. + // (#71739) + const providerStatus = opts.json ? null : await buildProviderStatusIndex(cfg); for (const summary of summaries) { const bindings = bindingMap.get(summary.id) ?? []; @@ -110,14 +117,16 @@ export async function agentsListCommand( summary.routes = ["default (no explicit rules)"]; } - const providerLines = listProvidersForAgent({ - summaryIsDefault: summary.isDefault, - cfg, - bindings, - providerStatus, - }); - if (providerLines.length > 0) { - summary.providers = providerLines; + if (providerStatus) { + const providerLines = listProvidersForAgent({ + summaryIsDefault: summary.isDefault, + cfg, + bindings, + providerStatus, + }); + if (providerLines.length > 0) { + summary.providers = providerLines; + } } }