export type CronTaskStatus = 'active' | 'paused' | 'completed'; export type CronTaskKind = 'recurring' | 'once'; export type CronSessionMode = 'persistent' | 'fresh'; export type CronBindingStatus = 'bound' | 'needs_binding'; export type CronAttentionReason = | 'failure' | 'offline' | 'overlap' | 'workspace_unavailable'; interface CronScheduleState { human: string; nextRunAt?: string; lastFiredAt?: string; lastScheduledFor?: string; jitterMs?: number; } export type CronSchedule = | (CronScheduleState & { type: 'once'; at: string }) | (CronScheduleState & { type: 'cron'; cron: string; timezone: string; }) | (CronScheduleState & { type: 'interval'; intervalMs: number; anchorAt: string; }); export interface CronTask { version?: 2; revision?: number; /** Execution configuration identity; statistics never change it. */ planId?: string; catchUp?: 'skip' | 'latest'; notifications?: 'all' | 'failures'; id: string; name: string; description?: string; status: CronTaskStatus; kind: CronTaskKind; permanent?: boolean; expiresAt?: string; /** 执行次数上限:跑满这么多次后自动完成(成功/失败都计入,与 kind==='once' 同语义,once=maxRuns:1 的特例)。 * 不设 = 不限次数(配合 expiresAt/permanent 控制终止)。 */ maxRuns?: number; schedule: CronSchedule; action: | { type: 'prompt'; prompt: string } | { type: 'workflow'; command: string }; runtime: { cwd: string; environment: 'project'; sessionId: string; sessionMode: CronSessionMode; bindingStatus: CronBindingStatus; model?: string; maxTurns?: number; }; stats: { runCount: number; successCount: number; failureCount: number; skippedCount: number; lastRunAt?: string; lastSuccessAt?: string; lastFailureAt?: string; }; createdAt: string; updatedAt: string; } /** Browser/remote input. Scheduler-owned cursors and stats are excluded. */ export interface CronTaskDraft { catchUp?: 'skip' | 'latest'; notifications?: 'all' | 'failures'; id?: string; name: string; description?: string; status: CronTaskStatus; kind: CronTaskKind; permanent?: boolean; expiresAt?: string; maxRuns?: number; schedule: | { type: 'once'; at: string; jitterMs?: number } | { type: 'cron'; cron: string; timezone: string; jitterMs?: number } | { type: 'interval'; intervalMs: number; anchorAt?: string; jitterMs?: number; }; action: CronTask['action']; runtime: { cwd: string; /** Bind the schedule to an existing workspace session. */ sessionId?: string; sessionMode?: CronSessionMode; model?: string; maxTurns?: number; }; } export interface CronRunRecord { planId?: string; /** Full older output remains in this immutable local journal archive. */ archiveFile?: string; /** Immutable execution configuration captured at enqueue time. */ snapshot?: CronTask; completionStatus?: string; managedStatus?: string; id: string; taskId: string; taskName: string; scheduledFor?: string; startedAt: string; finishedAt?: string; status: | 'queued' | 'running' | 'success' | 'failure' | 'interrupted' | 'cancelled'; owner?: string; result?: string; cwd: string; sessionId: string; model?: string; resultPreview?: string; error?: string; durationMs?: number; readAt?: string; attentionReason?: CronAttentionReason; } export interface CronMissedRecord { id: string; taskId: string; taskName: string; scheduledFor: string; detectedAt: string; actionPreview: string; reason: 'offline' | 'overlap' | 'binding_unavailable'; missedCount: number; readAt?: string; } export interface CronTaskPatch { clearMaxRuns?: boolean; clearMaxTurns?: boolean; expectedRevision?: number; catchUp?: 'skip' | 'latest'; notifications?: 'all' | 'failures'; id: string; name?: string; description?: string; status?: CronTaskStatus; kind?: CronTaskKind; permanent?: boolean; expiresAt?: string; maxRuns?: number; schedule?: CronTaskDraft['schedule']; action?: CronTask['action']; runtime?: Partial; } export interface CronListFilter { query?: string; status?: 'all' | 'active' | 'paused' | 'completed' | 'attention'; cwd?: string; sessionId?: string; } export interface CronTaskFile { tasks: CronTask[]; }