diff --git a/packages/cli/src/commands/schedule/index.ts b/packages/cli/src/commands/schedule/index.ts index 5a91f71431..b77d7a9793 100644 --- a/packages/cli/src/commands/schedule/index.ts +++ b/packages/cli/src/commands/schedule/index.ts @@ -41,9 +41,12 @@ export function createScheduleCommand(): Command { .option("--expires-in ", "Time to live for the schedule"), ).action(withOutput(runCreateCommand)); - addJsonAndDaemonHostOptions(schedule.command("ls").description("List schedules")).action( - withOutput(runLsCommand), - ); + addJsonAndDaemonHostOptions( + schedule + .command("ls") + .description("List new-agent schedules") + .option("--all", "Include schedules targeting existing agents"), + ).action(withOutput(runLsCommand)); addJsonAndDaemonHostOptions( schedule.command("inspect").description("Inspect a schedule").argument("", "Schedule ID"), diff --git a/packages/cli/src/commands/schedule/ls.ts b/packages/cli/src/commands/schedule/ls.ts index c3dfb6db28..28bf057901 100644 --- a/packages/cli/src/commands/schedule/ls.ts +++ b/packages/cli/src/commands/schedule/ls.ts @@ -1,5 +1,5 @@ import type { Command } from "commander"; -import type { ListResult } from "../../output/index.js"; +import { isHumanOutput, type ListResult } from "../../output/index.js"; import { scheduleSchema } from "./schema.js"; import { connectScheduleClient, @@ -10,7 +10,7 @@ import { } from "./shared.js"; export async function runLsCommand( - options: ScheduleCommandOptions, + options: ScheduleCommandOptions & { all?: boolean }, _command: Command, ): Promise> { const { client } = await connectScheduleClient(options.daemonTarget); @@ -19,11 +19,18 @@ export async function runLsCommand( if (payload.error) { throw new Error(payload.error); } + const visible = options.all + ? payload.schedules + : payload.schedules.filter((schedule) => schedule.target.type === "new-agent"); + const hiddenCount = payload.schedules.length - visible.length; + if (hiddenCount > 0 && isHumanOutput(options)) { + console.error( + `Schedules targeting existing agents: ${hiddenCount} hidden. Use --all to include them.`, + ); + } return { type: "list", - data: payload.schedules - .filter((schedule) => schedule.target.type === "new-agent") - .map(toScheduleRow), + data: visible.map(toScheduleRow), schema: scheduleSchema, }; } catch (error) { diff --git a/packages/cli/src/output/index.ts b/packages/cli/src/output/index.ts index 37323e0c9b..0d195ff10a 100644 --- a/packages/cli/src/output/index.ts +++ b/packages/cli/src/output/index.ts @@ -60,4 +60,9 @@ export { } from "./render-async.js"; // Command wrapper -export { withOutput, createOutputOptions, type CommandOptions } from "./with-output.js"; +export { + withOutput, + createOutputOptions, + isHumanOutput, + type CommandOptions, +} from "./with-output.js"; diff --git a/packages/cli/src/output/with-output.ts b/packages/cli/src/output/with-output.ts index a2f2cf35cc..582f98a606 100644 --- a/packages/cli/src/output/with-output.ts +++ b/packages/cli/src/output/with-output.ts @@ -63,6 +63,11 @@ function extractOutputOptions(options: CommandOptions): OutputOptions { }; } +export function isHumanOutput(options: CommandOptions): boolean { + const { format, quiet } = extractOutputOptions(options); + return format === "table" && !quiet; +} + /** * Wrap a command handler to automatically render output. * diff --git a/packages/cli/tests/31-schedule.test.ts b/packages/cli/tests/31-schedule.test.ts index c262756085..1bc1022a69 100644 --- a/packages/cli/tests/31-schedule.test.ts +++ b/packages/cli/tests/31-schedule.test.ts @@ -294,6 +294,24 @@ try { const createdJson = JSON.parse(created.stdout); assert.strictEqual(createdJson.target, "agent:0000000"); + const human = await ctx.paseo(["schedule", "ls"]); + assert.strictEqual(human.exitCode, 0, human.stderr); + assert.match(human.stderr, /1 hidden.*--all/); + + const alias = await ctx.paseo(["--format", "cli", "schedule", "ls"]); + assert.strictEqual(alias.exitCode, 0, alias.stderr); + assert.match(alias.stderr, /1 hidden.*--all/); + + const all = await ctx.paseo(["schedule", "ls", "--all", "--json"]); + assert.strictEqual(all.exitCode, 0, all.stderr); + assert( + JSON.parse(all.stdout).some( + (row: { id: string; target: string }) => + row.id === createdJson.id && row.target === createdJson.target, + ), + all.stdout, + ); + const deleted = await ctx.paseo(["schedule", "delete", createdJson.id, "--json"]); assert.strictEqual(deleted.exitCode, 0, deleted.stderr); assert.strictEqual(JSON.parse(deleted.stdout).id, createdJson.id);