fix(cli): bound sessions list output

This commit is contained in:
Peter Steinberger
2026-05-04 21:38:39 +01:00
parent 14b5f73e2a
commit 828b6be39d
10 changed files with 267 additions and 51 deletions

View File

@@ -191,6 +191,8 @@ describe("registerStatusHealthSessionsCommands", () => {
"/tmp/sessions.json",
"--active",
"120",
"--limit",
"25",
]);
expect(setVerbose).toHaveBeenCalledWith(true);
@@ -199,6 +201,7 @@ describe("registerStatusHealthSessionsCommands", () => {
json: true,
store: "/tmp/sessions.json",
active: "120",
limit: "25",
}),
runtime,
);

View File

@@ -132,6 +132,7 @@ export function registerStatusHealthSessionsCommands(program: Command) {
.option("--agent <id>", "Agent id to inspect (default: configured default agent)")
.option("--all-agents", "Aggregate sessions across all configured agents", false)
.option("--active <minutes>", "Only show sessions updated within the past N minutes")
.option("--limit <count>", 'Max sessions to show (default: 100; use "all" for full output)')
.addHelpText(
"after",
() =>
@@ -140,6 +141,7 @@ export function registerStatusHealthSessionsCommands(program: Command) {
["openclaw sessions --agent work", "List sessions for one agent."],
["openclaw sessions --all-agents", "Aggregate sessions across agents."],
["openclaw sessions --active 120", "Only last 2 hours."],
["openclaw sessions --limit 25", "Show the newest 25 sessions."],
["openclaw sessions --json", "Machine-readable output."],
["openclaw sessions --store ./tmp/sessions.json", "Use a specific session store."],
])}\n\n${theme.muted(
@@ -160,6 +162,7 @@ export function registerStatusHealthSessionsCommands(program: Command) {
agent: opts.agent as string | undefined,
allAgents: Boolean(opts.allAgents),
active: opts.active as string | undefined,
limit: opts.limit as string | undefined,
},
defaultRuntime,
);

View File

@@ -96,6 +96,8 @@ describe("route-args", () => {
"sqlite",
"--active",
"true",
"--limit",
"25",
]),
).toEqual({
json: true,
@@ -103,8 +105,10 @@ describe("route-args", () => {
agent: "default",
store: "sqlite",
active: "true",
limit: "25",
});
expect(parseSessionsRouteArgs(["node", "openclaw", "sessions", "--agent"])).toBeNull();
expect(parseSessionsRouteArgs(["node", "openclaw", "sessions", "--limit"])).toBeNull();
expect(
parseAgentsListRouteArgs(["node", "openclaw", "agents", "list", "--json", "--bindings"]),
).toEqual({

View File

@@ -144,12 +144,17 @@ export function parseSessionsRouteArgs(argv: string[]) {
if (!active.ok) {
return null;
}
const limit = parseOptionalFlagValue(argv, "--limit");
if (!limit.ok) {
return null;
}
return {
json: hasFlag(argv, "--json"),
allAgents: hasFlag(argv, "--all-agents"),
agent: agent.value,
store: store.value,
active: active.value,
limit: limit.value,
};
}