From d7288f57fada313b3f474f28d9fc62075025ae81 Mon Sep 17 00:00:00 2001 From: yinghaosang Date: Sat, 14 Feb 2026 23:44:49 +0800 Subject: [PATCH] fix(cli): register agents command in lazy core CLI entries (#16267) --- src/cli/program/command-registry.test.ts | 34 ++++++++++++++++++++++++ src/cli/program/command-registry.ts | 5 +++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/cli/program/command-registry.test.ts diff --git a/src/cli/program/command-registry.test.ts b/src/cli/program/command-registry.test.ts new file mode 100644 index 0000000000..beb2d1e5f0 --- /dev/null +++ b/src/cli/program/command-registry.test.ts @@ -0,0 +1,34 @@ +import { Command } from "commander"; +import { describe, expect, it } from "vitest"; +import type { ProgramContext } from "./context.js"; +import { getCoreCliCommandNames, registerCoreCliByName } from "./command-registry.js"; + +const stubCtx: ProgramContext = { + programVersion: "0.0.0-test", + agentChannelOptions: "web", +}; + +describe("command-registry", () => { + it("includes both agent and agents in core CLI command names", () => { + const names = getCoreCliCommandNames(); + expect(names).toContain("agent"); + expect(names).toContain("agents"); + }); + + it("registerCoreCliByName resolves agents to the agent entry", async () => { + const program = new Command(); + const found = await registerCoreCliByName(program, stubCtx, "agents"); + expect(found).toBe(true); + const agentsCmd = program.commands.find((c) => c.name() === "agents"); + expect(agentsCmd).toBeDefined(); + // The registrar also installs the singular "agent" command from the same entry + const agentCmd = program.commands.find((c) => c.name() === "agent"); + expect(agentCmd).toBeDefined(); + }); + + it("registerCoreCliByName returns false for unknown commands", async () => { + const program = new Command(); + const found = await registerCoreCliByName(program, stubCtx, "nonexistent"); + expect(found).toBe(false); + }); +}); diff --git a/src/cli/program/command-registry.ts b/src/cli/program/command-registry.ts index 84114f01f5..a470b85809 100644 --- a/src/cli/program/command-registry.ts +++ b/src/cli/program/command-registry.ts @@ -78,7 +78,10 @@ const coreEntries: CoreCliEntry[] = [ }, }, { - commands: [{ name: "agent", description: "Agent commands" }], + commands: [ + { name: "agent", description: "Agent commands" }, + { name: "agents", description: "Manage isolated agents" }, + ], register: async ({ program, ctx }) => { const mod = await import("./register.agent.js"); mod.registerAgentCommands(program, { agentChannelOptions: ctx.agentChannelOptions });