From 5de932ba260c1aa5790b8bc63c452ef604c7b1dc Mon Sep 17 00:00:00 2001 From: Developer Date: Sun, 25 Jan 2026 17:20:37 +0100 Subject: [PATCH] feat(cron): include delivery channel/to in finished event When a cron job with agentTurn payload completes, include the delivery target fields (channel and to) in the cron.finished event. This enables gateway clients to deliver cron messages to specific channels instead of broadcasting to all user platforms. Use case: When an agent schedules a reminder like "Remind me on Discord: ...", the external gateway can now deliver the message only to Discord instead of all channels. Changes: - Add channel/to fields to CronEvent type - Add channel/to fields to CronRunLogEntrySchema - Include channel/to from job.payload when emitting finished event Co-Authored-By: Claude Opus 4.5 --- src/cron/service/state.ts | 4 ++++ src/cron/service/timer.ts | 3 +++ src/gateway/protocol/schema/cron.ts | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/src/cron/service/state.ts b/src/cron/service/state.ts index ab094c20b..6902f4198 100644 --- a/src/cron/service/state.ts +++ b/src/cron/service/state.ts @@ -10,6 +10,10 @@ export type CronEvent = { error?: string; summary?: string; nextRunAtMs?: number; + /** Delivery channel from the job payload (for agentTurn jobs). */ + channel?: string; + /** Delivery target from the job payload (for agentTurn jobs). */ + to?: string; }; export type Logger = { diff --git a/src/cron/service/timer.ts b/src/cron/service/timer.ts index 370f5d116..8096a4c39 100644 --- a/src/cron/service/timer.ts +++ b/src/cron/service/timer.ts @@ -103,6 +103,9 @@ export async function executeJob( runAtMs: startedAt, durationMs: job.state.lastDurationMs, nextRunAtMs: job.state.nextRunAtMs, + // Include delivery target from payload for agentTurn jobs + channel: job.payload.kind === "agentTurn" ? job.payload.channel : undefined, + to: job.payload.kind === "agentTurn" ? job.payload.to : undefined, }); if (shouldDelete && state.store) { diff --git a/src/gateway/protocol/schema/cron.ts b/src/gateway/protocol/schema/cron.ts index 63ed0c209..7d504c7d6 100644 --- a/src/gateway/protocol/schema/cron.ts +++ b/src/gateway/protocol/schema/cron.ts @@ -240,6 +240,10 @@ export const CronRunLogEntrySchema = Type.Object( runAtMs: Type.Optional(Type.Integer({ minimum: 0 })), durationMs: Type.Optional(Type.Integer({ minimum: 0 })), nextRunAtMs: Type.Optional(Type.Integer({ minimum: 0 })), + /** Delivery channel from the job payload (for agentTurn jobs). */ + channel: Type.Optional(Type.String()), + /** Delivery target from the job payload (for agentTurn jobs). */ + to: Type.Optional(Type.String()), }, { additionalProperties: false }, );