From 382bdce4b363c18f0e6cf98df364375b7ed047ba Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Mon, 23 Feb 2026 13:00:02 -0500 Subject: [PATCH] CLI: route sessions cleanup through subcommand parser --- src/cli/program/command-registry.test.ts | 1 + src/cli/program/command-registry.ts | 2 +- src/cli/program/routes.test.ts | 4 ++++ src/cli/program/routes.ts | 4 +++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cli/program/command-registry.test.ts b/src/cli/program/command-registry.test.ts index 627a26a2d04..3fc44592ce9 100644 --- a/src/cli/program/command-registry.test.ts +++ b/src/cli/program/command-registry.test.ts @@ -68,6 +68,7 @@ describe("command-registry", () => { expect(names).toContain("memory"); expect(names).toContain("agents"); expect(names).toContain("browser"); + expect(names).toContain("sessions"); expect(names).not.toContain("agent"); expect(names).not.toContain("status"); expect(names).not.toContain("doctor"); diff --git a/src/cli/program/command-registry.ts b/src/cli/program/command-registry.ts index 72eb7b870f8..9ad44cf3eeb 100644 --- a/src/cli/program/command-registry.ts +++ b/src/cli/program/command-registry.ts @@ -181,7 +181,7 @@ const coreEntries: CoreCliEntry[] = [ { name: "sessions", description: "List stored conversation sessions", - hasSubcommands: false, + hasSubcommands: true, }, ], register: async ({ program }) => { diff --git a/src/cli/program/routes.test.ts b/src/cli/program/routes.test.ts index a36b0bd92ab..cc26a535e13 100644 --- a/src/cli/program/routes.test.ts +++ b/src/cli/program/routes.test.ts @@ -30,6 +30,10 @@ describe("program routes", () => { await expectRunFalse(["sessions"], ["node", "openclaw", "sessions", "--active"]); }); + it("does not fast-route sessions subcommands", () => { + expect(findRoutedCommand(["sessions", "cleanup"])).toBeNull(); + }); + it("does not match unknown routes", () => { expect(findRoutedCommand(["definitely-not-real"])).toBeNull(); }); diff --git a/src/cli/program/routes.ts b/src/cli/program/routes.ts index 866f35fb559..507e575087a 100644 --- a/src/cli/program/routes.ts +++ b/src/cli/program/routes.ts @@ -43,7 +43,9 @@ const routeStatus: RouteSpec = { }; const routeSessions: RouteSpec = { - match: (path) => path[0] === "sessions", + // Fast-path only bare `sessions`; subcommands (e.g. `sessions cleanup`) + // must fall through to Commander so nested handlers run. + match: (path) => path[0] === "sessions" && !path[1], run: async (argv) => { const json = hasFlag(argv, "--json"); const store = getFlagValue(argv, "--store");