feat(cron): add --session-key option to cron add/edit CLI commands

Expose the existing CronJob.sessionKey field through the CLI so users
can target cron jobs at specific named sessions without needing an
external shell script + system crontab workaround.

The backend already fully supports sessionKey on cron jobs - this
change wires it to the CLI surface with --session-key on cron add,
and --session-key / --clear-session-key on cron edit.

Closes #27158

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt Hulme
2026-02-25 22:16:51 -06:00
committed by Peter Steinberger
parent 452a8c9db9
commit f692288301
2 changed files with 18 additions and 0 deletions

View File

@@ -71,6 +71,7 @@ export function registerCronAddCommand(cron: Command) {
.option("--keep-after-run", "Keep one-shot job after it succeeds", false)
.option("--agent <id>", "Agent id for this job")
.option("--session <target>", "Session target (main|isolated)")
.option("--session-key <key>", "Session key for job routing (e.g. agent:my-agent:my-session)")
.option("--wake <mode>", "Wake mode (now|next-heartbeat)", "now")
.option("--at <when>", "Run once at time (ISO) or +duration (e.g. 20m)")
.option("--every <duration>", "Run every duration (e.g. 10m, 1h)")
@@ -240,12 +241,18 @@ export function registerCronAddCommand(cron: Command) {
? opts.description.trim()
: undefined;
const sessionKey =
typeof opts.sessionKey === "string" && opts.sessionKey.trim()
? opts.sessionKey.trim()
: undefined;
const params = {
name,
description,
enabled: !opts.disabled,
deleteAfterRun: opts.deleteAfterRun ? true : opts.keepAfterRun ? false : undefined,
agentId,
sessionKey,
schedule,
sessionTarget,
wakeMode,

View File

@@ -37,6 +37,8 @@ export function registerCronEditCommand(cron: Command) {
.option("--session <target>", "Session target (main|isolated)")
.option("--agent <id>", "Set agent id")
.option("--clear-agent", "Unset agent and use default", false)
.option("--session-key <key>", "Set session key for job routing")
.option("--clear-session-key", "Unset session key", false)
.option("--wake <mode>", "Wake mode (now|next-heartbeat)")
.option("--at <when>", "Set one-shot time (ISO) or duration like 20m")
.option("--every <duration>", "Set interval duration like 10m")
@@ -133,6 +135,15 @@ export function registerCronEditCommand(cron: Command) {
if (opts.clearAgent) {
patch.agentId = null;
}
if (opts.sessionKey && opts.clearSessionKey) {
throw new Error("Use --session-key or --clear-session-key, not both");
}
if (typeof opts.sessionKey === "string" && opts.sessionKey.trim()) {
patch.sessionKey = opts.sessionKey.trim();
}
if (opts.clearSessionKey) {
patch.sessionKey = null;
}
const scheduleChosen = [opts.at, opts.every, opts.cron].filter(Boolean).length;
if (scheduleChosen > 1) {