/** * Loop (Scheduled Tasks) scheduler module. * * Manages Loop CRUD, cron scheduling, execution lifecycle, and output capture. * Each Loop is a scheduled prompt sent to Claude on a cron schedule. * Executions are persisted as JSONL files for later replay. */ import type { ClaudeMessage, HandleChatOptions } from './claude.js'; import type { HistoryMessage } from './history.js'; export interface Loop { id: string; name: string; prompt: string; schedule: string; scheduleType: 'manual' | 'hourly' | 'daily' | 'weekly' | 'cron'; scheduleConfig: { hour?: number; minute?: number; dayOfWeek?: number; }; workDir: string; enabled: boolean; brainMode?: boolean; createdAt: string; updatedAt: string; lastExecution?: LoopExecutionSummary; } export interface LoopExecution { id: string; loopId: string; status: 'running' | 'success' | 'error' | 'cancelled'; trigger: 'scheduled' | 'manual'; startedAt: string; completedAt?: string; durationMs?: number; claudeSessionId?: string; conversationId?: string; summary?: string; error?: string; } export type LoopExecutionSummary = Pick; type SendFn = (msg: Record) => void; type HandleChatFn = (conversationId: string | undefined, prompt: string, workDir: string, options?: HandleChatOptions) => void; type CancelExecutionFn = (conversationId?: string) => void; type AddOutputObserverFn = (fn: (conversationId: string, msg: ClaudeMessage) => boolean | void) => void; type RemoveOutputObserverFn = (fn: (conversationId: string, msg: ClaudeMessage) => boolean | void) => void; type AddCloseObserverFn = (fn: (conversationId: string, exitCode: number | null, resultReceived: boolean) => void) => void; type RemoveCloseObserverFn = (fn: (conversationId: string, exitCode: number | null, resultReceived: boolean) => void) => void; /** * Initialize the scheduler. Loads loops from disk, reconciles orphaned * executions, and starts cron jobs for all enabled loops. */ export declare function initScheduler(deps: { send: SendFn; handleChat: HandleChatFn; cancelExecution: CancelExecutionFn; addOutputObserver: AddOutputObserverFn; removeOutputObserver: RemoveOutputObserverFn; addCloseObserver: AddCloseObserverFn; removeCloseObserver: RemoveCloseObserverFn; }): void; /** * Shutdown the scheduler. Stops all cron jobs. * Running executions are NOT cancelled; they complete naturally. */ export declare function shutdownScheduler(): void; export declare function createLoop(config: { name: string; prompt: string; schedule: string; scheduleType: Loop['scheduleType']; scheduleConfig: Loop['scheduleConfig']; workDir: string; brainMode?: boolean; }): Loop; export declare function updateLoop(loopId: string, updates: Partial>): Loop | null; export declare function deleteLoop(loopId: string): boolean; export declare function listLoops(workDir?: string): Loop[]; export declare function getLoop(loopId: string): Loop | null; export declare function listLoopExecutions(loopId: string, limit?: number): LoopExecution[]; export declare function getLoopExecutionMessages(loopId: string, executionId: string): HistoryMessage[]; export declare function runLoopNow(loopId: string): void; export declare function cancelLoopExecution(loopId: string): void; /** Get currently running executions (for status queries). */ export declare function getRunningExecutions(): Map; export {};