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:
Mohamed Boudra
2026-05-05 19:56:52 +07:00
parent 82cf11aaae
commit 400934f19c
13 changed files with 887 additions and 8 deletions
@@ -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" }));
});
});