/** * [WHO]: createCronScheduler, CronScheduler, isRecurringTaskAged, buildMissedTaskNotification * [FROM]: Depends on chokidar, ./cron-parser, ./cron-tasks, ./cron-tasks-lock * [TO]: Consumed by loop/index * [HERE]: extensions/builtin/loop/cron/cron-scheduler.ts - non-React scheduler core for scheduled_tasks.json * * Non-React scheduler core for /cron/scheduled_tasks.json. * * Modeled on Claude Code src/utils/cronScheduler.ts. * * Lifecycle: poll scheduledTasksEnabled until true (flag flips when * CronCreate runs) → load tasks + watch the file + start a 1s check * timer → on fire, call onFire(prompt). stop() tears everything down. */ import { type CronJitterConfig, type CronTask } from "./cron-tasks.js"; /** * True when a recurring task was created more than `maxAgeMs` ago and should * be deleted on its next fire. Permanent tasks never age. `maxAgeMs === 0` * means unlimited (never ages out). */ export declare function isRecurringTaskAged(t: CronTask, nowMs: number, maxAgeMs: number): boolean; type CronSchedulerOptions = { /** Called when a task fires (regular or missed-on-startup). */ onFire: (prompt: string) => void; /** While true, firing is deferred to the next tick. */ isLoading: () => boolean; /** * When true, bypasses the isLoading gate in check() and auto-enables the * scheduler without waiting for setScheduledTasksEnabled(). */ assistantMode?: boolean; /** * When provided, receives the full CronTask on normal fires (and onFire is * NOT called for that fire). Lets callers see the task id/cron/etc * instead of just the prompt string. */ onFireTask?: (task: CronTask) => void; /** * When provided, receives the missed one-shot tasks on initial load (and * onFire is NOT called with the pre-formatted notification). */ onMissed?: (tasks: CronTask[]) => void; /** * Directory containing the cron store (e.g. ~/.catui/agents/default). * Required for durable tasks. */ dir?: string; /** * Owner key written into the lock file. Defaults to a generated UUID. * PID remains the liveness probe regardless. */ lockIdentity?: string; /** * Returns the cron jitter config to use for this tick. Called once per * check() cycle. */ getJitterConfig?: () => CronJitterConfig; /** * Killswitch: polled once per check() tick. When true, check() bails * before firing anything. */ isKilled?: () => boolean; /** * Per-task gate applied before any side effect. Tasks returning false are * invisible to this scheduler. */ filter?: (t: CronTask) => boolean; }; export type CronScheduler = { start: () => void; stop: () => void; /** * Epoch ms of the soonest scheduled fire across all loaded tasks, or null * if nothing is scheduled. */ getNextFireTime: () => number | null; }; /** * Build the missed-task notification text. Guidance precedes the task list * and the list is wrapped in a code fence so a multi-line imperative prompt * is not interpreted as immediate instructions to avoid self-inflicted * prompt injection. */ export declare function buildMissedTaskNotification(missed: CronTask[]): string; export declare function createCronScheduler(options: CronSchedulerOptions): CronScheduler; export {};