From f692288301eb9be82dea75e6afbf4633ea04eec1 Mon Sep 17 00:00:00 2001 From: Matt Hulme Date: Wed, 25 Feb 2026 22:16:51 -0600 Subject: [PATCH] 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 --- src/cli/cron-cli/register.cron-add.ts | 7 +++++++ src/cli/cron-cli/register.cron-edit.ts | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/cli/cron-cli/register.cron-add.ts b/src/cli/cron-cli/register.cron-add.ts index 2388b00a388..8d44c77778f 100644 --- a/src/cli/cron-cli/register.cron-add.ts +++ b/src/cli/cron-cli/register.cron-add.ts @@ -71,6 +71,7 @@ export function registerCronAddCommand(cron: Command) { .option("--keep-after-run", "Keep one-shot job after it succeeds", false) .option("--agent ", "Agent id for this job") .option("--session ", "Session target (main|isolated)") + .option("--session-key ", "Session key for job routing (e.g. agent:my-agent:my-session)") .option("--wake ", "Wake mode (now|next-heartbeat)", "now") .option("--at ", "Run once at time (ISO) or +duration (e.g. 20m)") .option("--every ", "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, diff --git a/src/cli/cron-cli/register.cron-edit.ts b/src/cli/cron-cli/register.cron-edit.ts index f1e6c74d77f..9bc9916a06d 100644 --- a/src/cli/cron-cli/register.cron-edit.ts +++ b/src/cli/cron-cli/register.cron-edit.ts @@ -37,6 +37,8 @@ export function registerCronEditCommand(cron: Command) { .option("--session ", "Session target (main|isolated)") .option("--agent ", "Set agent id") .option("--clear-agent", "Unset agent and use default", false) + .option("--session-key ", "Set session key for job routing") + .option("--clear-session-key", "Unset session key", false) .option("--wake ", "Wake mode (now|next-heartbeat)") .option("--at ", "Set one-shot time (ISO) or duration like 20m") .option("--every ", "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) {