CLI: route sessions cleanup through subcommand parser

This commit is contained in:
Gustavo Madeira Santana 2026-02-23 13:00:02 -05:00 committed by Shakker
parent e536dcde28
commit 382bdce4b3
No known key found for this signature in database
4 changed files with 9 additions and 2 deletions

View File

@ -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");

View File

@ -181,7 +181,7 @@ const coreEntries: CoreCliEntry[] = [
{
name: "sessions",
description: "List stored conversation sessions",
hasSubcommands: false,
hasSubcommands: true,
},
],
register: async ({ program }) => {

View File

@ -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();
});

View File

@ -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");