fix(cron): add cron edit --clear-model

Completes the CLI half of #91298.
This commit is contained in:
ly-wang19
2026-06-15 23:54:00 +08:00
committed by GitHub
parent 794bd89fa0
commit 0888debcd3
4 changed files with 47 additions and 2 deletions

View File

@@ -200,4 +200,32 @@ describe("cron edit command", () => {
},
);
});
it("clears the model override with --clear-model (CLI parity with cron.update model:null)", async () => {
const program = createCronProgram();
await program.parseAsync(["edit", "job-1", "--clear-model"], { from: "user" });
expect(callGatewayFromCli).toHaveBeenCalledWith(
"cron.update",
expect.objectContaining({ clearModel: true }),
{
id: "job-1",
patch: {
payload: {
kind: "agentTurn",
model: null,
},
},
},
);
});
it("documents the --clear-model flag alongside the sibling --clear-tools", () => {
const editCommand = createCronProgram().commands.find((command) => command.name() === "edit");
const help = editCommand?.helpInformation() ?? "";
expect(help).toContain("--clear-model");
expect(help).toContain("--clear-tools");
});
});

View File

@@ -115,6 +115,11 @@ export function registerCronEditCommand(cron: Command) {
"Thinking level for agent jobs (off|minimal|low|medium|high|xhigh)",
)
.option("--model <model>", "Model override for agent jobs")
.option(
"--clear-model",
"Remove the per-job model override (restore normal cron model precedence)",
false,
)
.option("--timeout-seconds <n>", "Timeout seconds for agent or command jobs")
.option("--no-output-timeout-seconds <n>", "No-output timeout seconds for command jobs")
.option("--output-max-bytes <n>", "Maximum captured stdout/stderr bytes for command jobs")
@@ -279,6 +284,9 @@ export function registerCronEditCommand(cron: Command) {
);
}
const model = normalizeOptionalString(opts.model);
if (model && opts.clearModel) {
throw new Error("Use --model or --clear-model, not both");
}
const thinking = normalizeOptionalString(opts.thinking);
const toolsAllow = parseCronToolsAllow(opts.tools);
const rawTimeoutSeconds =
@@ -346,6 +354,7 @@ export function registerCronEditCommand(cron: Command) {
const hasAgentTurnPayloadField =
typeof opts.message === "string" ||
Boolean(model) ||
Boolean(opts.clearModel) ||
Boolean(thinking) ||
(hasTimeoutSeconds &&
!hasCommandSpecificPayloadField &&
@@ -373,7 +382,11 @@ export function registerCronEditCommand(cron: Command) {
} else if (hasAgentTurnPatch) {
const payload: Record<string, unknown> = { kind: "agentTurn" };
assignIf(payload, "message", String(opts.message), typeof opts.message === "string");
assignIf(payload, "model", model, Boolean(model));
if (opts.clearModel) {
payload.model = null;
} else {
assignIf(payload, "model", model, Boolean(model));
}
assignIf(payload, "thinking", thinking, Boolean(thinking));
assignIf(payload, "timeoutSeconds", timeoutSeconds, hasTimeoutSeconds);
assignIf(