schedule: add paseo schedule update to edit schedules in place (#694)
* schedule: add `paseo schedule update` to edit schedules in place Editing a schedule today requires delete+recreate, losing run history and the schedule id. This adds an additive RPC and CLI command that patches name, prompt, cadence, new-agent target fields, max-runs, and expires-in without touching runs or in-flight executions. nextRunAt is recomputed only when the cadence actually changes. * schedule(cli): share cadence flag parser between create and update Both paths were turning --every/--cron into a ScheduleCadence with near-identical code. Extract `parseCadenceFromFlags` so the literals and the exclusivity check live in one place; create wraps it to require a value, update lets it stay optional.
This commit is contained in:
@@ -9,6 +9,7 @@ import { runPauseCommand } from "./pause.js";
|
||||
import { runResumeCommand } from "./resume.js";
|
||||
import { runDeleteCommand } from "./delete.js";
|
||||
import { runRunOnceCommand } from "./run-once.js";
|
||||
import { runUpdateCommand } from "./update.js";
|
||||
|
||||
export function createScheduleCommand(): Command {
|
||||
const schedule = new Command("schedule").description("Manage recurring schedules");
|
||||
@@ -74,5 +75,27 @@ export function createScheduleCommand(): Command {
|
||||
.argument("<id>", "Schedule ID"),
|
||||
).action(withOutput(runRunOnceCommand));
|
||||
|
||||
addJsonAndDaemonHostOptions(
|
||||
schedule
|
||||
.command("update")
|
||||
.description("Update an existing schedule in place")
|
||||
.argument("<id>", "Schedule ID")
|
||||
.option("--every <duration>", "Switch to fixed interval cadence (for example: 5m, 1h)")
|
||||
.option("--cron <expr>", "Switch to cron cadence expression")
|
||||
.option("--name <name>", "Rename the schedule (empty string clears the name)")
|
||||
.option("--prompt <text>", "Replace the schedule prompt")
|
||||
.option(
|
||||
"--provider <provider>",
|
||||
"New agent provider, or provider/model (only for new-agent target)",
|
||||
)
|
||||
.option("--model <model>", "New agent model (only for new-agent target)")
|
||||
.option("--mode <mode>", "New agent provider mode (only for new-agent target)")
|
||||
.option("--cwd <path>", "New working directory (only for new-agent target)")
|
||||
.option("--max-runs <n>", "Set or change maximum number of runs")
|
||||
.option("--no-max-runs", "Clear the max-runs limit")
|
||||
.option("--expires-in <duration>", "Set or change time to live for the schedule")
|
||||
.option("--no-expires-in", "Clear the expiration"),
|
||||
).action(withOutput(runUpdateCommand));
|
||||
|
||||
return schedule;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { parseScheduleCreateInput } from "./shared.js";
|
||||
import { parseScheduleCreateInput, parseScheduleUpdateInput } from "./shared.js";
|
||||
|
||||
const baseOptions = {
|
||||
prompt: "do the thing",
|
||||
@@ -106,3 +106,127 @@ describe("parseScheduleCreateInput first-run timing", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseScheduleUpdateInput", () => {
|
||||
test("rejects calls with no fields to update", () => {
|
||||
expect(() => parseScheduleUpdateInput({ id: "abc" })).toThrow(
|
||||
expect.objectContaining({ code: "NO_UPDATES" }),
|
||||
);
|
||||
});
|
||||
|
||||
test("parses prompt and name updates", () => {
|
||||
expect(parseScheduleUpdateInput({ id: "abc", prompt: " hello ", name: " named " })).toEqual(
|
||||
{
|
||||
id: "abc",
|
||||
name: "named",
|
||||
prompt: "hello",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("name set to empty string clears the name", () => {
|
||||
expect(parseScheduleUpdateInput({ id: "abc", name: "" })).toEqual({
|
||||
id: "abc",
|
||||
name: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects empty prompt", () => {
|
||||
expect(() => parseScheduleUpdateInput({ id: "abc", prompt: " " })).toThrow(
|
||||
expect.objectContaining({ code: "INVALID_PROMPT" }),
|
||||
);
|
||||
});
|
||||
|
||||
test("parses --every cadence", () => {
|
||||
expect(parseScheduleUpdateInput({ id: "abc", every: "5m" })).toEqual({
|
||||
id: "abc",
|
||||
cadence: { type: "every", everyMs: 5 * 60_000 },
|
||||
});
|
||||
});
|
||||
|
||||
test("parses --cron cadence", () => {
|
||||
expect(parseScheduleUpdateInput({ id: "abc", cron: "30 9 * * *" })).toEqual({
|
||||
id: "abc",
|
||||
cadence: { type: "cron", expression: "30 9 * * *" },
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects passing both --every and --cron", () => {
|
||||
expect(() => parseScheduleUpdateInput({ id: "abc", every: "5m", cron: "0 9 * * *" })).toThrow(
|
||||
expect.objectContaining({ code: "INVALID_CADENCE" }),
|
||||
);
|
||||
});
|
||||
|
||||
test("parses provider/model shorthand and explicit mode", () => {
|
||||
expect(
|
||||
parseScheduleUpdateInput({
|
||||
id: "abc",
|
||||
provider: "codex/gpt-5",
|
||||
mode: "full-access",
|
||||
cwd: "/tmp/proj",
|
||||
}),
|
||||
).toEqual({
|
||||
id: "abc",
|
||||
newAgentConfig: {
|
||||
provider: "codex",
|
||||
model: "gpt-5",
|
||||
modeId: "full-access",
|
||||
cwd: "/tmp/proj",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("--mode with empty value clears the modeId", () => {
|
||||
expect(parseScheduleUpdateInput({ id: "abc", mode: "" })).toEqual({
|
||||
id: "abc",
|
||||
newAgentConfig: { modeId: null },
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects empty --cwd", () => {
|
||||
expect(() => parseScheduleUpdateInput({ id: "abc", cwd: " " })).toThrow(
|
||||
expect.objectContaining({ code: "INVALID_CWD" }),
|
||||
);
|
||||
});
|
||||
|
||||
test("--max-runs sets a positive integer; --no-max-runs clears", () => {
|
||||
expect(parseScheduleUpdateInput({ id: "abc", maxRuns: "3" })).toEqual({
|
||||
id: "abc",
|
||||
maxRuns: 3,
|
||||
});
|
||||
expect(parseScheduleUpdateInput({ id: "abc", clearMaxRuns: true })).toEqual({
|
||||
id: "abc",
|
||||
maxRuns: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects passing both --max-runs and --no-max-runs", () => {
|
||||
expect(() => parseScheduleUpdateInput({ id: "abc", maxRuns: "3", clearMaxRuns: true })).toThrow(
|
||||
expect.objectContaining({ code: "CONFLICTING_MAX_RUNS" }),
|
||||
);
|
||||
});
|
||||
|
||||
test("--expires-in computes an absolute timestamp; --no-expires-in clears", () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-01-01T00:00:00.000Z"));
|
||||
try {
|
||||
expect(parseScheduleUpdateInput({ id: "abc", expiresIn: "1h" })).toEqual({
|
||||
id: "abc",
|
||||
expiresAt: "2026-01-01T01:00:00.000Z",
|
||||
});
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
|
||||
expect(parseScheduleUpdateInput({ id: "abc", clearExpires: true })).toEqual({
|
||||
id: "abc",
|
||||
expiresAt: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects passing both --expires-in and --no-expires-in", () => {
|
||||
expect(() =>
|
||||
parseScheduleUpdateInput({ id: "abc", expiresIn: "1h", clearExpires: true }),
|
||||
).toThrow(expect.objectContaining({ code: "CONFLICTING_EXPIRES" }));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,8 @@ import type {
|
||||
ScheduleListItem,
|
||||
ScheduleRecord,
|
||||
ScheduleTarget,
|
||||
UpdateScheduleInput,
|
||||
UpdateScheduleNewAgentConfig,
|
||||
} from "./types.js";
|
||||
import { parseDuration } from "../../utils/duration.js";
|
||||
import { resolveProviderAndModel } from "../../utils/provider-model.js";
|
||||
@@ -145,18 +147,14 @@ export function parseScheduleCreateInput(options: {
|
||||
} satisfies CommandError;
|
||||
}
|
||||
|
||||
const cadenceCount = Number(options.every !== undefined) + Number(options.cron !== undefined);
|
||||
if (cadenceCount !== 1) {
|
||||
const cadence = parseCadenceFromFlags(options.every, options.cron);
|
||||
if (!cadence) {
|
||||
throw {
|
||||
code: "INVALID_CADENCE",
|
||||
message: "Specify exactly one of --every or --cron",
|
||||
} satisfies CommandError;
|
||||
}
|
||||
|
||||
const cadence: ScheduleCadence = options.every
|
||||
? { type: "every", everyMs: parseDuration(options.every) }
|
||||
: { type: "cron", expression: options.cron!.trim() };
|
||||
|
||||
const cwdInput = options.cwd?.trim();
|
||||
if (options.host !== undefined && !cwdInput) {
|
||||
throw {
|
||||
@@ -230,6 +228,167 @@ function resolveRunOnCreate(
|
||||
return runNow ?? cadenceType === "every";
|
||||
}
|
||||
|
||||
export interface ScheduleUpdateOptionsInput {
|
||||
id: string;
|
||||
every?: string;
|
||||
cron?: string;
|
||||
name?: string;
|
||||
prompt?: string;
|
||||
provider?: string;
|
||||
model?: string;
|
||||
mode?: string;
|
||||
cwd?: string;
|
||||
maxRuns?: string;
|
||||
expiresIn?: string;
|
||||
clearMaxRuns?: boolean;
|
||||
clearExpires?: boolean;
|
||||
}
|
||||
|
||||
export function parseScheduleUpdateInput(options: ScheduleUpdateOptionsInput): UpdateScheduleInput {
|
||||
const id = options.id.trim();
|
||||
if (!id) {
|
||||
throw {
|
||||
code: "INVALID_SCHEDULE_ID",
|
||||
message: "Schedule id cannot be empty",
|
||||
} satisfies CommandError;
|
||||
}
|
||||
|
||||
const cadence = parseCadenceFromFlags(options.every, options.cron);
|
||||
const newAgentConfig = buildNewAgentConfigPatch(options);
|
||||
const maxRuns = parseUpdateMaxRuns(options);
|
||||
const expiresAt = parseUpdateExpiresAt(options);
|
||||
const name = parseUpdateName(options);
|
||||
const prompt = parseUpdatePrompt(options);
|
||||
|
||||
if (
|
||||
name === undefined &&
|
||||
prompt === undefined &&
|
||||
cadence === undefined &&
|
||||
newAgentConfig === undefined &&
|
||||
maxRuns === undefined &&
|
||||
expiresAt === undefined
|
||||
) {
|
||||
throw {
|
||||
code: "NO_UPDATES",
|
||||
message: "Specify at least one field to update",
|
||||
} satisfies CommandError;
|
||||
}
|
||||
|
||||
return {
|
||||
id,
|
||||
...(name !== undefined ? { name } : {}),
|
||||
...(prompt !== undefined ? { prompt } : {}),
|
||||
...(cadence !== undefined ? { cadence } : {}),
|
||||
...(newAgentConfig !== undefined ? { newAgentConfig } : {}),
|
||||
...(maxRuns !== undefined ? { maxRuns } : {}),
|
||||
...(expiresAt !== undefined ? { expiresAt } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function parseCadenceFromFlags(
|
||||
every: string | undefined,
|
||||
cron: string | undefined,
|
||||
): ScheduleCadence | undefined {
|
||||
if (every !== undefined && cron !== undefined) {
|
||||
throw {
|
||||
code: "INVALID_CADENCE",
|
||||
message: "Specify at most one of --every or --cron",
|
||||
} satisfies CommandError;
|
||||
}
|
||||
if (every !== undefined) {
|
||||
return { type: "every", everyMs: parseDuration(every) };
|
||||
}
|
||||
if (cron !== undefined) {
|
||||
return { type: "cron", expression: cron.trim() };
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseUpdateMaxRuns(options: ScheduleUpdateOptionsInput): number | null | undefined {
|
||||
if (options.maxRuns !== undefined && options.clearMaxRuns) {
|
||||
throw {
|
||||
code: "CONFLICTING_MAX_RUNS",
|
||||
message: "Use either --max-runs <n> or --no-max-runs, not both",
|
||||
} satisfies CommandError;
|
||||
}
|
||||
if (options.clearMaxRuns) {
|
||||
return null;
|
||||
}
|
||||
if (options.maxRuns !== undefined) {
|
||||
return parsePositiveInt(options.maxRuns, "--max-runs");
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseUpdateExpiresAt(options: ScheduleUpdateOptionsInput): string | null | undefined {
|
||||
if (options.expiresIn !== undefined && options.clearExpires) {
|
||||
throw {
|
||||
code: "CONFLICTING_EXPIRES",
|
||||
message: "Use either --expires-in <duration> or --no-expires-in, not both",
|
||||
} satisfies CommandError;
|
||||
}
|
||||
if (options.clearExpires) {
|
||||
return null;
|
||||
}
|
||||
if (options.expiresIn !== undefined) {
|
||||
return new Date(Date.now() + parseDuration(options.expiresIn)).toISOString();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseUpdateName(options: ScheduleUpdateOptionsInput): string | null | undefined {
|
||||
if (options.name === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = options.name.trim();
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
|
||||
function parseUpdatePrompt(options: ScheduleUpdateOptionsInput): string | undefined {
|
||||
if (options.prompt === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = options.prompt.trim();
|
||||
if (!trimmed) {
|
||||
throw {
|
||||
code: "INVALID_PROMPT",
|
||||
message: "--prompt cannot be empty",
|
||||
} satisfies CommandError;
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
function buildNewAgentConfigPatch(
|
||||
options: ScheduleUpdateOptionsInput,
|
||||
): UpdateScheduleNewAgentConfig | undefined {
|
||||
const patch: UpdateScheduleNewAgentConfig = {};
|
||||
if (options.provider !== undefined || options.model !== undefined) {
|
||||
const resolved = resolveProviderAndModel({
|
||||
provider: options.provider,
|
||||
model: options.model,
|
||||
});
|
||||
patch.provider = resolved.provider;
|
||||
if (resolved.model !== undefined) {
|
||||
patch.model = resolved.model;
|
||||
}
|
||||
}
|
||||
if (options.mode !== undefined) {
|
||||
const trimmed = options.mode.trim();
|
||||
patch.modeId = trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
if (options.cwd !== undefined) {
|
||||
const trimmed = options.cwd.trim();
|
||||
if (!trimmed) {
|
||||
throw {
|
||||
code: "INVALID_CWD",
|
||||
message: "--cwd cannot be empty",
|
||||
} satisfies CommandError;
|
||||
}
|
||||
patch.cwd = trimmed;
|
||||
}
|
||||
return Object.keys(patch).length > 0 ? patch : undefined;
|
||||
}
|
||||
|
||||
function parsePositiveInt(value: string, flag: string): number {
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
if (!Number.isInteger(parsed) || parsed <= 0) {
|
||||
|
||||
@@ -136,6 +136,29 @@ export interface ScheduleRunOncePayload {
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
export interface UpdateScheduleNewAgentConfig {
|
||||
provider?: string;
|
||||
model?: string | null;
|
||||
modeId?: string | null;
|
||||
cwd?: string;
|
||||
}
|
||||
|
||||
export interface UpdateScheduleInput {
|
||||
id: string;
|
||||
name?: string | null;
|
||||
prompt?: string;
|
||||
cadence?: ScheduleCadence;
|
||||
newAgentConfig?: UpdateScheduleNewAgentConfig;
|
||||
maxRuns?: number | null;
|
||||
expiresAt?: string | null;
|
||||
}
|
||||
|
||||
export interface ScheduleUpdatePayload {
|
||||
requestId: string;
|
||||
schedule: ScheduleRecord | null;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
export interface ScheduleDaemonClient {
|
||||
scheduleCreate(input: CreateScheduleInput): Promise<ScheduleCreatePayload>;
|
||||
scheduleList(): Promise<ScheduleListPayload>;
|
||||
@@ -145,5 +168,6 @@ export interface ScheduleDaemonClient {
|
||||
scheduleResume(input: { id: string }): Promise<ScheduleResumePayload>;
|
||||
scheduleDelete(input: { id: string }): Promise<ScheduleDeletePayload>;
|
||||
scheduleRunOnce(input: { id: string }): Promise<ScheduleRunOncePayload>;
|
||||
scheduleUpdate(input: UpdateScheduleInput): Promise<ScheduleUpdatePayload>;
|
||||
close(): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import type { Command } from "commander";
|
||||
import type { ListResult } from "../../output/index.js";
|
||||
import {
|
||||
createScheduleInspectRows,
|
||||
createScheduleInspectSchema,
|
||||
type ScheduleInspectRow,
|
||||
} from "./schema.js";
|
||||
import {
|
||||
connectScheduleClient,
|
||||
parseScheduleUpdateInput,
|
||||
toScheduleCommandError,
|
||||
type ScheduleCommandOptions,
|
||||
} from "./shared.js";
|
||||
|
||||
export interface ScheduleUpdateOptions extends ScheduleCommandOptions {
|
||||
every?: string;
|
||||
cron?: string;
|
||||
name?: string;
|
||||
prompt?: string;
|
||||
provider?: string;
|
||||
model?: string;
|
||||
mode?: string;
|
||||
cwd?: string;
|
||||
maxRuns?: string;
|
||||
noMaxRuns?: boolean;
|
||||
expiresIn?: string;
|
||||
noExpiresIn?: boolean;
|
||||
}
|
||||
|
||||
export async function runUpdateCommand(
|
||||
id: string,
|
||||
options: ScheduleUpdateOptions,
|
||||
_command: Command,
|
||||
): Promise<ListResult<ScheduleInspectRow>> {
|
||||
const input = parseScheduleUpdateInput({
|
||||
id,
|
||||
every: options.every,
|
||||
cron: options.cron,
|
||||
name: options.name,
|
||||
prompt: options.prompt,
|
||||
provider: options.provider,
|
||||
model: options.model,
|
||||
mode: options.mode,
|
||||
cwd: options.cwd,
|
||||
maxRuns: options.maxRuns,
|
||||
expiresIn: options.expiresIn,
|
||||
clearMaxRuns: options.noMaxRuns,
|
||||
clearExpires: options.noExpiresIn,
|
||||
});
|
||||
const { client } = await connectScheduleClient(options.host);
|
||||
try {
|
||||
const payload = await client.scheduleUpdate(input);
|
||||
if (payload.error || !payload.schedule) {
|
||||
throw new Error(payload.error ?? `Failed to update schedule: ${id}`);
|
||||
}
|
||||
return {
|
||||
type: "list",
|
||||
data: createScheduleInspectRows(payload.schedule),
|
||||
schema: createScheduleInspectSchema(payload.schedule),
|
||||
};
|
||||
} catch (error) {
|
||||
throw toScheduleCommandError("SCHEDULE_UPDATE_FAILED", "update schedule", error);
|
||||
} finally {
|
||||
await client.close().catch(() => {});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user