mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
Set Archive on finish from the CLI and MCP (#8479)
Schedules created through the CLI or MCP archived every run's workspace and agent, and only the app's switch could change that. Add --archive-on-finish and --no-archive-on-finish to paseo schedule create and update, and archiveOnFinish to create_schedule and update_schedule. Omitting the option stores nothing, so the default stays on. A repeated named create_schedule that changes only Archive on finish refreshes the existing schedule instead of creating a duplicate, and keeps the saved value when the request omits it. Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
This commit is contained in:
co-authored by
Mohamed Boudra
parent
bbe7e2a7fc
commit
b6375b1426
@@ -98,6 +98,16 @@ describe("canonical CLI surface", () => {
|
||||
expect(scheduleCreate?.helpInformation()).toContain("--thinking <id>");
|
||||
});
|
||||
|
||||
it("offers archive on finish when creating and updating schedules", () => {
|
||||
const schedule = createCli().commands.find((command) => command.name() === "schedule");
|
||||
|
||||
for (const name of ["create", "update"]) {
|
||||
const help = schedule?.commands.find((command) => command.name() === name)?.helpInformation();
|
||||
expect(help).toContain("--archive-on-finish");
|
||||
expect(help).toContain("--no-archive-on-finish");
|
||||
}
|
||||
});
|
||||
|
||||
it("offers opening an existing agent in the desktop app", () => {
|
||||
const agent = createCli().commands.find((command) => command.name() === "agent");
|
||||
const open = agent?.commands.find((command) => command.name() === "open");
|
||||
|
||||
@@ -20,6 +20,7 @@ export interface ScheduleCreateOptions extends ScheduleCommandOptions {
|
||||
mode?: string;
|
||||
thinking?: string;
|
||||
cwd?: string;
|
||||
archiveOnFinish?: boolean;
|
||||
maxRuns?: string;
|
||||
expiresIn?: string;
|
||||
runNow?: boolean;
|
||||
@@ -43,6 +44,7 @@ export async function runCreateCommand(
|
||||
mode: options.mode,
|
||||
thinking: options.thinking,
|
||||
cwd: options.cwd,
|
||||
archiveOnFinish: options.archiveOnFinish,
|
||||
daemonTarget: options.daemonTarget,
|
||||
maxRuns: options.maxRuns,
|
||||
expiresIn: options.expiresIn,
|
||||
|
||||
@@ -35,6 +35,8 @@ export function createScheduleCommand(): Command {
|
||||
.option("--thinking <id>", "Thinking option ID for new-agent runs")
|
||||
.option("--cwd <path>", "Working directory (default: current; required with --host)")
|
||||
.option("--run-now", "Fire one immediate run on creation")
|
||||
.option("--archive-on-finish", "Archive each run's workspace when the run ends (default)")
|
||||
.option("--no-archive-on-finish", "Keep each run's workspace and agent active")
|
||||
.option("--max-runs <n>", "Maximum number of runs")
|
||||
.option("--expires-in <duration>", "Time to live for the schedule"),
|
||||
).action(withOutput(runCreateCommand));
|
||||
@@ -93,6 +95,8 @@ export function createScheduleCommand(): Command {
|
||||
.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("--archive-on-finish", "Archive later runs' workspaces when each run ends")
|
||||
.option("--no-archive-on-finish", "Keep later runs' workspaces and agents active")
|
||||
.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")
|
||||
|
||||
@@ -77,6 +77,14 @@ export function createScheduleInspectRows(schedule: ScheduleRecord): ScheduleIns
|
||||
: `every:${schedule.cadence.everyMs}ms`,
|
||||
},
|
||||
{ key: "Target", value: formatTarget(schedule.target) },
|
||||
...(schedule.target.type === "new-agent"
|
||||
? [
|
||||
{
|
||||
key: "ArchiveOnFinish",
|
||||
value: `${schedule.target.config.archiveOnFinish ?? true}`,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{ key: "Status", value: schedule.status },
|
||||
{ key: "CreatedAt", value: schedule.createdAt },
|
||||
{ key: "UpdatedAt", value: schedule.updatedAt },
|
||||
|
||||
@@ -159,7 +159,37 @@ describe("parseScheduleCreateInput thinking", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseScheduleCreateInput archive on finish", () => {
|
||||
test.each([false, true])("stores %s on the new-agent target", (archiveOnFinish) => {
|
||||
const input = parseScheduleCreateInput({ ...baseOptions, cwd: "/project", archiveOnFinish });
|
||||
|
||||
expect(input.target).toEqual({
|
||||
type: "new-agent",
|
||||
config: { provider: "claude", cwd: "/project", archiveOnFinish },
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects the flag on an agent target", () => {
|
||||
expect(() =>
|
||||
parseScheduleCreateInput({
|
||||
daemonTarget: baseOptions.daemonTarget,
|
||||
prompt: "do the thing",
|
||||
every: "5m",
|
||||
target: "00000000-0000-4000-8000-000000000001",
|
||||
archiveOnFinish: false,
|
||||
}),
|
||||
).toThrow(expect.objectContaining({ code: "INVALID_TARGET" }));
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseScheduleUpdateInput", () => {
|
||||
test.each([false, true])("patches archiveOnFinish to %s", (archiveOnFinish) => {
|
||||
expect(parseScheduleUpdateInput({ id: "abc", archiveOnFinish })).toEqual({
|
||||
id: "abc",
|
||||
newAgentConfig: { archiveOnFinish },
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects calls with no fields to update", () => {
|
||||
expect(() => parseScheduleUpdateInput({ id: "abc" })).toThrow(
|
||||
expect.objectContaining({ code: "NO_UPDATES" }),
|
||||
|
||||
@@ -116,7 +116,8 @@ function resolveScheduleTarget(args: {
|
||||
if (hasExplicitNewAgentOption) {
|
||||
throw {
|
||||
code: "INVALID_TARGET",
|
||||
message: "--provider/--mode/--thinking can only be used with a new-agent target",
|
||||
message:
|
||||
"--provider/--mode/--thinking/--archive-on-finish can only be used with a new-agent target",
|
||||
details: "Use --target new-agent or omit --target to create a new agent schedule",
|
||||
} satisfies CommandError;
|
||||
}
|
||||
@@ -148,6 +149,7 @@ export function parseScheduleCreateInput(options: {
|
||||
mode?: string;
|
||||
thinking?: string;
|
||||
cwd?: string;
|
||||
archiveOnFinish?: boolean;
|
||||
host?: string;
|
||||
daemonTarget: import("../../utils/daemon-target.js").DaemonTarget;
|
||||
maxRuns?: string;
|
||||
@@ -191,7 +193,10 @@ export function parseScheduleCreateInput(options: {
|
||||
} satisfies CommandError;
|
||||
}
|
||||
const hasExplicitNewAgentOption =
|
||||
options.provider !== undefined || options.mode !== undefined || options.thinking !== undefined;
|
||||
options.provider !== undefined ||
|
||||
options.mode !== undefined ||
|
||||
options.thinking !== undefined ||
|
||||
options.archiveOnFinish !== undefined;
|
||||
const createNewAgentTarget = (): ScheduleTarget => {
|
||||
const resolvedProviderModel = resolveProviderAndModel({
|
||||
provider: options.provider,
|
||||
@@ -204,6 +209,9 @@ export function parseScheduleCreateInput(options: {
|
||||
...(resolvedProviderModel.model ? { model: resolvedProviderModel.model } : {}),
|
||||
...(modeId ? { modeId } : {}),
|
||||
...(thinkingOptionId ? { thinkingOptionId } : {}),
|
||||
...(options.archiveOnFinish !== undefined
|
||||
? { archiveOnFinish: options.archiveOnFinish }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -249,6 +257,7 @@ export interface ScheduleUpdateOptionsInput {
|
||||
model?: string;
|
||||
mode?: string;
|
||||
cwd?: string;
|
||||
archiveOnFinish?: boolean;
|
||||
maxRuns?: string;
|
||||
expiresIn?: string;
|
||||
clearMaxRuns?: boolean;
|
||||
@@ -437,6 +446,9 @@ function buildNewAgentConfigPatch(
|
||||
}
|
||||
patch.cwd = trimmed;
|
||||
}
|
||||
if (options.archiveOnFinish !== undefined) {
|
||||
patch.archiveOnFinish = options.archiveOnFinish;
|
||||
}
|
||||
return Object.keys(patch).length > 0 ? patch : undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ export type ScheduleTarget =
|
||||
modeId?: string;
|
||||
model?: string;
|
||||
thinkingOptionId?: string;
|
||||
archiveOnFinish?: boolean;
|
||||
title?: string | null;
|
||||
providerOptions?: Record<string, unknown>;
|
||||
};
|
||||
@@ -139,6 +140,7 @@ export interface UpdateScheduleNewAgentConfig {
|
||||
model?: string | null;
|
||||
modeId?: string | null;
|
||||
cwd?: string;
|
||||
archiveOnFinish?: boolean;
|
||||
}
|
||||
|
||||
export interface UpdateScheduleInput {
|
||||
|
||||
@@ -23,6 +23,7 @@ export interface ScheduleUpdateOptions extends ScheduleCommandOptions {
|
||||
model?: string;
|
||||
mode?: string;
|
||||
cwd?: string;
|
||||
archiveOnFinish?: boolean;
|
||||
maxRuns?: string | false;
|
||||
expiresIn?: string | false;
|
||||
}
|
||||
@@ -43,6 +44,7 @@ export async function runUpdateCommand(
|
||||
model: options.model,
|
||||
mode: options.mode,
|
||||
cwd: options.cwd,
|
||||
archiveOnFinish: options.archiveOnFinish,
|
||||
maxRuns: options.maxRuns === false ? undefined : options.maxRuns,
|
||||
expiresIn: options.expiresIn === false ? undefined : options.expiresIn,
|
||||
clearMaxRuns: options.maxRuns === false,
|
||||
|
||||
@@ -224,6 +224,55 @@ try {
|
||||
console.log("schedule update clears limits\n");
|
||||
}
|
||||
|
||||
{
|
||||
console.log("Test 1d-2: schedule create and update set archive on finish");
|
||||
const inspect = async (id: string) => {
|
||||
const result = await ctx.paseo(["schedule", "inspect", id, "--json"]);
|
||||
assert.strictEqual(result.exitCode, 0, result.stderr);
|
||||
return JSON.parse(result.stdout);
|
||||
};
|
||||
const createWith = async (...flags: string[]) => {
|
||||
const result = await ctx.paseo([
|
||||
"schedule",
|
||||
"create",
|
||||
"Daily report",
|
||||
"--cron",
|
||||
"0 0 1 1 *",
|
||||
"--provider",
|
||||
"claude",
|
||||
"--cwd",
|
||||
ctx.workDir,
|
||||
...flags,
|
||||
"--json",
|
||||
]);
|
||||
assert.strictEqual(result.exitCode, 0, result.stderr);
|
||||
return JSON.parse(result.stdout).id as string;
|
||||
};
|
||||
|
||||
const defaultId = await createWith();
|
||||
assert.strictEqual((await inspect(defaultId)).target.config.archiveOnFinish, undefined);
|
||||
const defaultRows = await ctx.paseo(["schedule", "inspect", defaultId]);
|
||||
assert.match(defaultRows.stdout, /ArchiveOnFinish\s+true/);
|
||||
|
||||
const kept = await ctx.paseo(["schedule", "update", defaultId, "--no-archive-on-finish"]);
|
||||
assert.strictEqual(kept.exitCode, 0, kept.stderr);
|
||||
assert.match(kept.stdout, /ArchiveOnFinish\s+false/);
|
||||
assert.strictEqual((await inspect(defaultId)).target.config.archiveOnFinish, false);
|
||||
|
||||
const archived = await ctx.paseo(["schedule", "update", defaultId, "--archive-on-finish"]);
|
||||
assert.strictEqual(archived.exitCode, 0, archived.stderr);
|
||||
assert.strictEqual((await inspect(defaultId)).target.config.archiveOnFinish, true);
|
||||
|
||||
const keptId = await createWith("--no-archive-on-finish");
|
||||
assert.strictEqual((await inspect(keptId)).target.config.archiveOnFinish, false);
|
||||
|
||||
for (const id of [defaultId, keptId]) {
|
||||
const deleted = await ctx.paseo(["schedule", "delete", id, "--json"]);
|
||||
assert.strictEqual(deleted.exitCode, 0, deleted.stderr);
|
||||
}
|
||||
console.log("schedule archive on finish flags work\n");
|
||||
}
|
||||
|
||||
{
|
||||
console.log("Test 1e: compatibility agent-target schedules remain deletable");
|
||||
const created = await ctx.paseo(
|
||||
|
||||
@@ -60,6 +60,7 @@ const AUTOMATION_FIELDS = [
|
||||
"provider",
|
||||
"cwd",
|
||||
"isolation",
|
||||
"archiveOnFinish",
|
||||
"maxRuns",
|
||||
"expiresIn",
|
||||
"clearExpires",
|
||||
|
||||
@@ -59,6 +59,7 @@ describe("Paseo tool-call detail presentation", () => {
|
||||
cron: "0 9 * * 1",
|
||||
timezone: "Europe/Berlin",
|
||||
provider: "codex/gpt-5.4",
|
||||
archiveOnFinish: false,
|
||||
maxRuns: 1,
|
||||
},
|
||||
{
|
||||
@@ -78,6 +79,7 @@ describe("Paseo tool-call detail presentation", () => {
|
||||
{ label: "Cron", value: "0 9 * * 1" },
|
||||
{ label: "Timezone", value: "Europe/Berlin" },
|
||||
{ label: "Provider", value: "codex/gpt-5.4" },
|
||||
{ label: "Archive on finish", value: "No" },
|
||||
{ label: "Maximum runs", value: "1" },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -21,6 +21,7 @@ export type PaseoToolDetailSection =
|
||||
const FIELD_LABELS: Readonly<Record<string, string>> = {
|
||||
agentId: "Agent",
|
||||
archivedAgentIds: "Archived agents",
|
||||
archiveOnFinish: "Archive on finish",
|
||||
baseBranch: "Base branch",
|
||||
branchName: "New branch",
|
||||
browserId: "Browser tab",
|
||||
|
||||
@@ -952,6 +952,45 @@ describe("Suite C: Schedule Tools", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("create_schedule and update_schedule set archive on finish", async () => {
|
||||
let scheduleId: string | null = null;
|
||||
try {
|
||||
const createArgs = {
|
||||
prompt: "say hello",
|
||||
cron: "*/5 * * * *",
|
||||
name: "Parity archive on finish schedule",
|
||||
provider: "claude",
|
||||
};
|
||||
const created = await callToolStructured(topLevelClient, "create_schedule", createArgs);
|
||||
scheduleId = str(created.id);
|
||||
expect(created.target).toMatchObject({ type: "new-agent", config: {} });
|
||||
expect(created.target).not.toHaveProperty("config.archiveOnFinish");
|
||||
|
||||
const recreated = await callToolStructured(topLevelClient, "create_schedule", {
|
||||
...createArgs,
|
||||
archiveOnFinish: false,
|
||||
});
|
||||
expect(recreated.id).toBe(scheduleId);
|
||||
expect(recreated.target).toMatchObject({ config: { archiveOnFinish: false } });
|
||||
|
||||
for (const archiveOnFinish of [true, false]) {
|
||||
const updated = await callToolStructured(topLevelClient, "update_schedule", {
|
||||
id: scheduleId,
|
||||
archiveOnFinish,
|
||||
});
|
||||
expect(updated.target).toMatchObject({ config: { archiveOnFinish } });
|
||||
}
|
||||
|
||||
const listed = await callToolStructured(topLevelClient, "list_schedules", {});
|
||||
const named = recordArr(listed.schedules).filter(
|
||||
(schedule) => schedule.name === createArgs.name,
|
||||
);
|
||||
expect(named).toHaveLength(1);
|
||||
} finally {
|
||||
await deleteScheduleIfPresent(scheduleId);
|
||||
}
|
||||
});
|
||||
|
||||
test("inspect_schedule returns details", async () => {
|
||||
let scheduleId: string | null = null;
|
||||
try {
|
||||
|
||||
@@ -411,6 +411,7 @@ interface ScheduleUpdateToolInput {
|
||||
model?: string | null;
|
||||
mode?: string | null;
|
||||
cwd?: string;
|
||||
archiveOnFinish?: boolean;
|
||||
expiresIn?: string;
|
||||
clearExpires?: boolean;
|
||||
}
|
||||
@@ -544,6 +545,7 @@ function buildScheduleUpdateInput(input: ScheduleUpdateToolInput): UpdateSchedul
|
||||
...(providerModelPatch.model !== undefined ? { model: providerModelPatch.model } : {}),
|
||||
...(input.mode !== undefined ? { modeId: input.mode } : {}),
|
||||
...(input.cwd !== undefined ? { cwd: input.cwd } : {}),
|
||||
...(input.archiveOnFinish !== undefined ? { archiveOnFinish: input.archiveOnFinish } : {}),
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -1003,7 +1005,10 @@ function createToolCatalog(
|
||||
provider?: string;
|
||||
cwd?: string;
|
||||
isolation?: "local" | "worktree";
|
||||
archiveOnFinish?: boolean;
|
||||
}) => {
|
||||
const archiveOnFinish =
|
||||
params?.archiveOnFinish === undefined ? {} : { archiveOnFinish: params.archiveOnFinish };
|
||||
const callerAgent = resolveCallerAgent();
|
||||
if (callerAgent) {
|
||||
return {
|
||||
@@ -1011,6 +1016,7 @@ function createToolCatalog(
|
||||
config: {
|
||||
...buildCallerAgentScheduleConfig(callerAgent, params),
|
||||
...(params?.isolation ? { isolation: params.isolation } : {}),
|
||||
...archiveOnFinish,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1030,6 +1036,7 @@ function createToolCatalog(
|
||||
cwd: params?.cwd?.trim() ? expandUserPath(params.cwd) : process.cwd(),
|
||||
...(resolvedProviderModel.model ? { model: resolvedProviderModel.model } : {}),
|
||||
...(params?.isolation ? { isolation: params.isolation } : {}),
|
||||
...archiveOnFinish,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -2711,13 +2718,30 @@ function createToolCatalog(
|
||||
),
|
||||
cwd: z.string().optional(),
|
||||
isolation: z.enum(["local", "worktree"]).optional(),
|
||||
archiveOnFinish: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe(
|
||||
"Archive each run's workspace and agent when the run ends. Defaults to true; pass false to keep them active.",
|
||||
),
|
||||
maxRuns: z.number().int().positive().optional(),
|
||||
expiresIn: scheduleDurationInputSchema.optional(),
|
||||
})
|
||||
.superRefine(addScheduleCadenceIssue),
|
||||
outputSchema: ScheduleSummarySchema.shape,
|
||||
},
|
||||
async ({ prompt, cron, timezone, name, provider, cwd, isolation, maxRuns, expiresIn }) => {
|
||||
async ({
|
||||
prompt,
|
||||
cron,
|
||||
timezone,
|
||||
name,
|
||||
provider,
|
||||
cwd,
|
||||
isolation,
|
||||
archiveOnFinish,
|
||||
maxRuns,
|
||||
expiresIn,
|
||||
}) => {
|
||||
if (!scheduleService) {
|
||||
throw new Error("Schedule service is not configured");
|
||||
}
|
||||
@@ -2729,7 +2753,7 @@ function createToolCatalog(
|
||||
cron,
|
||||
...(timezone !== undefined ? { timezone } : {}),
|
||||
}),
|
||||
target: resolveNewAgentScheduleTarget({ provider, cwd, isolation }),
|
||||
target: resolveNewAgentScheduleTarget({ provider, cwd, isolation, archiveOnFinish }),
|
||||
...(name?.trim() ? { name: name.trim() } : {}),
|
||||
...(maxRuns === undefined ? {} : { maxRuns }),
|
||||
...(expiresAt === undefined ? {} : { expiresAt }),
|
||||
@@ -3049,6 +3073,10 @@ function createToolCatalog(
|
||||
.optional()
|
||||
.describe("New mode for new-agent target (null to clear)."),
|
||||
cwd: z.string().trim().min(1).optional().describe("New cwd for new-agent target."),
|
||||
archiveOnFinish: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe("Archive the workspace and agent of later runs when each run ends."),
|
||||
expiresIn: scheduleDurationInputSchema
|
||||
.optional()
|
||||
.describe("New relative expiry duration (for example: 1h, 2d)."),
|
||||
|
||||
@@ -40,7 +40,11 @@ import {
|
||||
} from "./service.js";
|
||||
import { ScheduleStore } from "./store.js";
|
||||
import { ForegroundPromptStart } from "../agent/agent-run-state.js";
|
||||
import type { ScheduleExecutionResult, StoredSchedule } from "@getpaseo/protocol/schedule/types";
|
||||
import type {
|
||||
CreateScheduleInput,
|
||||
ScheduleExecutionResult,
|
||||
StoredSchedule,
|
||||
} from "@getpaseo/protocol/schedule/types";
|
||||
|
||||
interface ScheduleServiceInternals {
|
||||
executeSchedule(schedule: StoredSchedule, runId: string): Promise<ScheduleExecutionResult>;
|
||||
@@ -3847,6 +3851,103 @@ describe("ScheduleService", () => {
|
||||
expect(await service.list()).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("createOrReplace refreshes archive on finish without duplicating the schedule", async () => {
|
||||
const service = createScheduleService({
|
||||
paseoHome: tempDir,
|
||||
logger: createTestLogger(),
|
||||
agentManager: new AgentManager({ logger: createTestLogger() }),
|
||||
agentStorage,
|
||||
providerSnapshotManager: NO_UNATTENDED_SCHEDULE_POLICY,
|
||||
now: () => now,
|
||||
runner: async () => ({ agentId: null, output: "ok" }),
|
||||
});
|
||||
const createNightly = (archiveOnFinish?: boolean) =>
|
||||
service.createOrReplace({
|
||||
name: "nightly",
|
||||
prompt: "audit",
|
||||
cadence: { type: "every", everyMs: 60_000 },
|
||||
target: {
|
||||
type: "new-agent",
|
||||
config: {
|
||||
provider: "claude",
|
||||
cwd: tempDir,
|
||||
...(archiveOnFinish === undefined ? {} : { archiveOnFinish }),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const omitted = await createNightly();
|
||||
const archived = await createNightly(true);
|
||||
const kept = await createNightly(false);
|
||||
|
||||
expect([archived.id, kept.id]).toEqual([omitted.id, omitted.id]);
|
||||
const schedules = await service.list();
|
||||
expect(schedules).toHaveLength(1);
|
||||
expect(schedules[0]?.target).toMatchObject({ config: { archiveOnFinish: false } });
|
||||
});
|
||||
|
||||
test("createOrReplace keeps a saved archive on finish when the repeated create omits it", async () => {
|
||||
const service = createScheduleService({
|
||||
paseoHome: tempDir,
|
||||
logger: createTestLogger(),
|
||||
agentManager: new AgentManager({ logger: createTestLogger() }),
|
||||
agentStorage,
|
||||
providerSnapshotManager: NO_UNATTENDED_SCHEDULE_POLICY,
|
||||
now: () => now,
|
||||
runner: async () => ({ agentId: null, output: "ok" }),
|
||||
});
|
||||
const nightly = {
|
||||
name: "nightly",
|
||||
prompt: "audit",
|
||||
cadence: { type: "every", everyMs: 60_000 },
|
||||
target: { type: "new-agent", config: { provider: "claude", cwd: tempDir } },
|
||||
} satisfies CreateScheduleInput;
|
||||
|
||||
const created = await service.createOrReplace(nightly);
|
||||
await service.update({ id: created.id, newAgentConfig: { archiveOnFinish: false } });
|
||||
const repeated = await service.createOrReplace(nightly);
|
||||
|
||||
expect(repeated.id).toBe(created.id);
|
||||
expect(repeated.target).toMatchObject({ config: { archiveOnFinish: false } });
|
||||
});
|
||||
|
||||
test("createOrReplace prefers the schedule whose archive on finish matches exactly", async () => {
|
||||
const service = createScheduleService({
|
||||
paseoHome: tempDir,
|
||||
logger: createTestLogger(),
|
||||
agentManager: new AgentManager({ logger: createTestLogger() }),
|
||||
agentStorage,
|
||||
providerSnapshotManager: NO_UNATTENDED_SCHEDULE_POLICY,
|
||||
now: () => now,
|
||||
runner: async () => ({ agentId: null, output: "ok" }),
|
||||
});
|
||||
const nightly = (archiveOnFinish?: boolean) =>
|
||||
({
|
||||
name: "nightly",
|
||||
prompt: "audit",
|
||||
cadence: { type: "every", everyMs: 60_000 },
|
||||
target: {
|
||||
type: "new-agent",
|
||||
config: {
|
||||
provider: "claude",
|
||||
cwd: tempDir,
|
||||
...(archiveOnFinish === undefined ? {} : { archiveOnFinish }),
|
||||
},
|
||||
},
|
||||
}) satisfies CreateScheduleInput;
|
||||
|
||||
// Hosts can already hold same-named schedules that differ only in this
|
||||
// option, because plain create does not deduplicate by name.
|
||||
const kept = await service.create(nightly(false));
|
||||
const archived = await service.create(nightly(true));
|
||||
const omitted = await service.create(nightly());
|
||||
|
||||
expect((await service.createOrReplace(nightly())).id).toBe(omitted.id);
|
||||
expect((await service.createOrReplace(nightly(true))).id).toBe(archived.id);
|
||||
expect((await service.createOrReplace(nightly(false))).id).toBe(kept.id);
|
||||
expect(await service.list()).toHaveLength(3);
|
||||
});
|
||||
|
||||
test("completeForAgent skips schedules that are already completed", async () => {
|
||||
const service = createScheduleService({
|
||||
paseoHome: tempDir,
|
||||
|
||||
@@ -206,6 +206,23 @@ function mergeScheduleCadenceTimezone(
|
||||
return next;
|
||||
}
|
||||
|
||||
// A repeated create that omits Archive on finish keeps the value saved on the
|
||||
// schedule, so re-registering it does not undo a choice made in the app.
|
||||
function mergeArchiveOnFinish(current: ScheduleTarget, next: ScheduleTarget): ScheduleTarget {
|
||||
if (
|
||||
current.type === "new-agent" &&
|
||||
next.type === "new-agent" &&
|
||||
next.config.archiveOnFinish === undefined &&
|
||||
current.config.archiveOnFinish !== undefined
|
||||
) {
|
||||
return {
|
||||
...next,
|
||||
config: { ...next.config, archiveOnFinish: current.config.archiveOnFinish },
|
||||
};
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
function buildRunOutput(params: {
|
||||
output: string | null;
|
||||
timelineText: string;
|
||||
@@ -406,7 +423,7 @@ export class ScheduleService {
|
||||
name,
|
||||
prompt,
|
||||
cadence,
|
||||
target: inputTarget,
|
||||
target: mergeArchiveOnFinish(current.target, inputTarget),
|
||||
status: "active",
|
||||
pausedAt: null,
|
||||
nextRunAt: nextRunAt.toISOString(),
|
||||
|
||||
@@ -59,9 +59,12 @@ function targetIdentity(target: ScheduleTarget): unknown {
|
||||
};
|
||||
}
|
||||
|
||||
// Archive on finish decides what happens after a run, not what runs, so a
|
||||
// repeated create that only changes it refreshes the existing schedule.
|
||||
const { archiveOnFinish: _archiveOnFinish, ...config } = target.config;
|
||||
return {
|
||||
type: target.type,
|
||||
config: target.config,
|
||||
config,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -74,6 +77,10 @@ function nameTargetIdentityKey(name: string, target: ScheduleTarget): string {
|
||||
);
|
||||
}
|
||||
|
||||
function isSameTarget(left: ScheduleTarget, right: ScheduleTarget): boolean {
|
||||
return JSON.stringify(canonicalize(left)) === JSON.stringify(canonicalize(right));
|
||||
}
|
||||
|
||||
function matchesNameAndTarget(
|
||||
schedule: StoredSchedule,
|
||||
name: string,
|
||||
@@ -205,9 +212,11 @@ export class ScheduleStore {
|
||||
const identity = nameTargetIdentityKey(name, target);
|
||||
return this.serializeIdentityMutation(identity, async () => {
|
||||
while (true) {
|
||||
const existing = (await this.list()).find((schedule) =>
|
||||
const matches = (await this.list()).filter((schedule) =>
|
||||
matchesNameAndTarget(schedule, name, target),
|
||||
);
|
||||
const existing =
|
||||
matches.find((schedule) => isSameTarget(schedule.target, target)) ?? matches[0];
|
||||
if (!existing) {
|
||||
const created = StoredScheduleSchema.parse({
|
||||
...(await options.create()),
|
||||
|
||||
@@ -14,3 +14,13 @@ it.each(["schedules.md", "schedules-cli.md", "mcp.md", "worktrees/index.md"])(
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["schedules.md", "--no-archive-on-finish"],
|
||||
["schedules.md", "archiveOnFinish: false"],
|
||||
["schedules-cli.md", "--no-archive-on-finish"],
|
||||
["mcp.md", "archiveOnFinish: false"],
|
||||
])("%s names how to turn off archive on finish with %s", async (file, option) => {
|
||||
const markdown = await readFile(path.join(docsRoot, file), "utf8");
|
||||
expect(markdown).toContain(option);
|
||||
});
|
||||
|
||||
+1
-1
@@ -155,7 +155,7 @@ Both use the same cron engine, but they have deliberately different interfaces.
|
||||
|
||||
MCP heartbeats are ephemeral: create or delete them. To change one, delete it and create a replacement. Pause, resume, update, inspect, logs, and run-once apply to new-agent schedules only.
|
||||
|
||||
New-agent run workspaces are archived when each run ends by default. `create_schedule` and `update_schedule` do not expose **Archive on finish** (`archiveOnFinish`); [change the option in the app](/docs/schedules#keep-run-workspaces) to keep subsequent run workspaces active.
|
||||
New-agent run workspaces are archived when each run ends by default. Pass `archiveOnFinish: false` to `create_schedule` or `update_schedule` to [keep subsequent run workspaces](/docs/schedules#keep-run-workspaces) active; it is the **Archive on finish** option in the app.
|
||||
|
||||
### Agent profiles
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ Paseo Agent 默认会收到完成、错误和权限通知;设置 `notifyOnFini
|
||||
|
||||
MCP heartbeat 是临时的:只能创建或删除。要修改一个 heartbeat,请删除它并创建一个替代的。暂停、恢复、更新、查看、日志和单次运行只适用于新建 Agent 的定时任务。
|
||||
|
||||
默认情况下,新建 Agent 的定时任务每次运行结束时都会归档其工作区。`create_schedule` 和 `update_schedule` 不提供 **Archive on finish**(`archiveOnFinish`);要让之后的运行工作区保持活跃,请[在应用中修改该选项](/docs/schedules#keep-run-workspaces)。
|
||||
默认情况下,新建 Agent 的定时任务每次运行结束时都会归档其工作区。向 `create_schedule` 或 `update_schedule` 传入 `archiveOnFinish: false`,即可[让之后的运行工作区保持活跃](/docs/schedules#keep-run-workspaces);它对应应用中的 **Archive on finish** 选项。
|
||||
|
||||
### Agent 配置 {#agent-profiles}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ category: Schedules
|
||||
|
||||
`paseo schedule` creates and manages new-agent [schedules](/docs/schedules) from your terminal, useful for headless boxes and scripts. Every run starts a fresh agent.
|
||||
|
||||
Run workspaces are archived when each run ends by default. The CLI has no **Archive on finish** flag; [change the option in the app](/docs/schedules#keep-run-workspaces) to keep subsequent run workspaces active.
|
||||
Run workspaces are archived when each run ends by default. Pass `--no-archive-on-finish` to `paseo schedule create` or `paseo schedule update` to [keep subsequent run workspaces](/docs/schedules#keep-run-workspaces) active; it is the **Archive on finish** option in the app.
|
||||
|
||||
## Create
|
||||
|
||||
@@ -96,6 +96,7 @@ paseo schedule pause <id>
|
||||
paseo schedule resume <id>
|
||||
paseo schedule run-once <id>
|
||||
paseo schedule update <id> --every 10m --max-runs 6
|
||||
paseo schedule update <id> --no-archive-on-finish
|
||||
paseo schedule delete <id>
|
||||
```
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ nav: CLI
|
||||
|
||||
`paseo schedule` 在终端中创建和管理新建 Agent 的[定时任务](/docs/schedules),适用于无界面的机器和脚本。每次运行都会启动一个新的 Agent。
|
||||
|
||||
默认情况下,每次运行结束时都会归档其工作区。CLI 没有 **Archive on finish** 参数;要让之后的运行工作区保持活跃,请[在应用中修改该选项](/docs/schedules#keep-run-workspaces)。
|
||||
默认情况下,每次运行结束时都会归档其工作区。向 `paseo schedule create` 或 `paseo schedule update` 传入 `--no-archive-on-finish`,即可[让之后的运行工作区保持活跃](/docs/schedules#keep-run-workspaces);它对应应用中的 **Archive on finish** 选项。
|
||||
|
||||
## 创建 {#create}
|
||||
|
||||
@@ -94,6 +94,7 @@ paseo schedule pause <id>
|
||||
paseo schedule resume <id>
|
||||
paseo schedule run-once <id>
|
||||
paseo schedule update <id> --every 10m --max-runs 6
|
||||
paseo schedule update <id> --no-archive-on-finish
|
||||
paseo schedule delete <id>
|
||||
```
|
||||
|
||||
|
||||
@@ -40,6 +40,6 @@ Both run on a cadence you set. To start an agent from an external event instead
|
||||
|
||||
Each new-agent schedule run creates a workspace. **Archive on finish** is on by default: when the run ends, Paseo archives that workspace and its agent. With worktree isolation, archiving also removes the worktree after its last active workspace is archived.
|
||||
|
||||
To keep runs available, open the schedule in the app's Schedules view, turn off **Archive on finish**, and save. Paseo keeps each run's workspace and agent active until you archive them; runs that fail before creating an agent are still cleaned up. This option also applies to **Project directory** isolation; archiving that workspace leaves the project directory in place.
|
||||
To keep runs available, turn off **Archive on finish**: open the schedule in the app's Schedules view, turn off the switch, and save; from the CLI, pass `--no-archive-on-finish`; over MCP, pass `archiveOnFinish: false`. Paseo keeps each run's workspace and agent active until you archive them; runs that fail before creating an agent are still cleaned up. This option also applies to **Project directory** isolation; archiving that workspace leaves the project directory in place.
|
||||
|
||||
The stored option is `target.config.archiveOnFinish`, a boolean that defaults to `true` when omitted. The CLI and MCP schedule tools do not expose this option; use the app to change it. Heartbeats use an existing agent and do not have this option.
|
||||
The stored option is `target.config.archiveOnFinish`, a boolean that defaults to `true` when omitted. Heartbeats use an existing agent and do not have this option.
|
||||
|
||||
@@ -38,6 +38,6 @@ cron 是标准的节奏表示。CLI 接受 `5m` 或 `1h` 这样的简单预设
|
||||
|
||||
新建 Agent 的定时任务每次运行都会创建一个工作区。**Archive on finish** 默认开启:运行结束时,Paseo 会归档该工作区及其 Agent。使用 worktree 隔离时,最后一个使用该 worktree 的活跃工作区被归档后,归档还会删除这个 worktree。
|
||||
|
||||
要保留运行结果,在应用的定时任务视图中打开该定时任务,关闭 **Archive on finish** 并保存。Paseo 会让每次运行的工作区和 Agent 保持活跃,直到你手动归档;在创建 Agent 之前就失败的运行仍会被清理。该选项同样适用于 **Project directory** 隔离;归档该工作区不会删除项目目录。
|
||||
要保留运行结果,请关闭 **Archive on finish**:在应用的定时任务视图中打开该定时任务,关闭该开关并保存;在 CLI 中传入 `--no-archive-on-finish`;通过 MCP 传入 `archiveOnFinish: false`。Paseo 会让每次运行的工作区和 Agent 保持活跃,直到你手动归档;在创建 Agent 之前就失败的运行仍会被清理。该选项同样适用于 **Project directory** 隔离;归档该工作区不会删除项目目录。
|
||||
|
||||
存储的选项是 `target.config.archiveOnFinish`,一个布尔值,省略时默认为 `true`。CLI 和 MCP 的定时任务工具不提供这个选项;请在应用中修改。heartbeat 使用已有的 Agent,没有这个选项。
|
||||
存储的选项是 `target.config.archiveOnFinish`,一个布尔值,省略时默认为 `true`。heartbeat 使用已有的 Agent,没有这个选项。
|
||||
|
||||
@@ -42,7 +42,7 @@ Plugins can choose a location anywhere on disk with [`worktree.create.before`](/
|
||||
3. Review the diff against the base branch
|
||||
4. Merge or archive the workspace; after the last workspace using it is archived, Paseo runs teardown and removes the worktree
|
||||
|
||||
Scheduled runs archive their workspaces when they finish by default. Turn off **Archive on finish** in the schedule's app form to [keep run workspaces](/docs/schedules#keep-run-workspaces) and their worktrees until you archive them.
|
||||
Scheduled runs archive their workspaces when they finish by default. Turn off **Archive on finish** to [keep run workspaces](/docs/schedules#keep-run-workspaces) and their worktrees until you archive them.
|
||||
|
||||
## Create a worktree-backed workspace
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ worktree 默认存放在 `$PASEO_HOME/worktrees/` 下,按源检出路径的哈
|
||||
3. 对照基础分支审查 diff
|
||||
4. 合并或归档该工作区;使用该 worktree 的最后一个工作区被归档后,Paseo 会运行 teardown 并删除 worktree
|
||||
|
||||
定时任务的运行默认会在结束时归档其工作区。在定时任务的应用表单中关闭 **Archive on finish**,即可[保留运行工作区](/docs/schedules#keep-run-workspaces)及其 worktree,直到你手动归档。
|
||||
定时任务的运行默认会在结束时归档其工作区。关闭 **Archive on finish**,即可[保留运行工作区](/docs/schedules#keep-run-workspaces)及其 worktree,直到你手动归档。
|
||||
|
||||
## 创建由 worktree 支撑的工作区 {#create-a-worktree-backed-workspace}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ Only set feature IDs returned by `inspect_provider`. For Codex fast mode, look f
|
||||
|
||||
## Schedules and heartbeats
|
||||
|
||||
**`create_schedule`** — starts a new agent on a cron cadence. Required: `prompt`, `cron`, `provider`. Optional: `timezone`, `name`, `cwd`, `maxRuns`, `expiresIn`. Use when the recurring work should live in fresh agents.
|
||||
**`create_schedule`** — starts a new agent on a cron cadence. Required: `prompt`, `cron`, `provider`. Optional: `timezone`, `name`, `cwd`, `archiveOnFinish`, `maxRuns`, `expiresIn`. Use when the recurring work should live in fresh agents. Runs archive their workspace when they end; pass `archiveOnFinish: false` when someone reads or answers the run afterward.
|
||||
|
||||
**`create_heartbeat`** — sends you a prompt on a cron cadence. Required: `prompt`, `cron`. Optional: `timezone`, `name`, `maxRuns`, `expiresIn`. Use for reminders, PR/build babysitting, and status checks that should return to this conversation.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user