/** * System Reminder Service * * Notification service that sends system reminders to chat platforms (Discord/Slack) * and formats them for agent context injection. * * Features: * - Formats background task event messages (started, completed, failed) * - Sends notifications to Discord/Slack channels via callbacks * - Batches multiple completions within a configurable window into single notifications * - Provides formatted context for agent conversation injection * - Supports both English and Korean * - Stores last 50 reminders per channel for context retrieval * * @module system-reminder * @version 1.0 */ /** * System reminder event types for background task lifecycle */ export type SystemReminderType = 'task-started' | 'task-completed' | 'task-failed' | 'all-tasks-complete' | 'delegation-started' | 'delegation-completed'; /** * A single system reminder event */ export interface SystemReminder { /** Event type */ type: SystemReminderType; /** Background task ID */ taskId: string; /** Human-readable description of the task */ description: string; /** Agent that executed the task */ agentId: string; /** Agent that requested the task */ requestedBy: string; /** Channel where the task was initiated */ channelId: string; /** Source platform (discord/slack) — only send to matching callback */ source?: 'discord' | 'slack'; /** Task duration in milliseconds (for completed/failed) */ duration?: number; /** Error message (for failed tasks) */ error?: string; /** Unix timestamp in milliseconds */ timestamp: number; } /** * Callback for sending formatted notifications to chat platforms. * Actual Discord/Slack message sending is handled externally. */ export type ChatNotifyCallback = (channelId: string, message: string, source: 'discord' | 'slack') => Promise; /** * Configuration options for SystemReminderService */ export interface SystemReminderServiceOptions { /** Batch window in milliseconds (default: 2000) */ batchWindowMs?: number; /** Maximum reminders per batch (default: 10) */ maxBatchSize?: number; /** Enable sending chat notifications (default: true) */ enableChatNotifications?: boolean; } /** * Supported languages for reminder formatting */ export type ReminderLanguage = 'en' | 'ko'; /** * System Reminder Service * * Manages background task notifications for chat platforms and agent context injection. * Batches multiple completions within a configurable window into single messages. * * @example * ```typescript * const service = new SystemReminderService({ * batchWindowMs: 2000, * enableChatNotifications: true, * }); * * service.registerCallback(async (channelId, message, source) => { * await discordSend(channelId, message); * }, 'discord'); * * await service.notify({ * type: 'task-started', * taskId: 'bg_abc12345', * description: 'Implement auth module', * agentId: 'developer', * requestedBy: 'conductor', * channelId: 'channel-123', * timestamp: Date.now(), * }); * ``` */ export declare class SystemReminderService { private readonly batchWindowMs; private readonly maxBatchSize; private readonly enableChatNotifications; /** Per-channel reminder history (last MAX_REMINDERS_PER_CHANNEL) */ private channelReminders; /** Per-channel pending batch of completion/failure reminders */ private pendingBatches; /** Registered platform callbacks */ private callbacks; /** Language for formatting */ private language; constructor(options?: SystemReminderServiceOptions); /** * Register a chat platform callback for sending notifications * * @param callback - Function to send messages * @param source - Platform identifier */ registerCallback(callback: ChatNotifyCallback, source: 'discord' | 'slack'): void; /** * Remove a previously registered callback * * @param source - Platform identifier to unregister */ unregisterCallback(source: 'discord' | 'slack'): void; /** * Set the language for formatted messages * * @param language - 'en' or 'ko' */ setLanguage(language: ReminderLanguage): void; /** * Process and dispatch a system reminder. * * - `task-started` reminders are sent immediately. * - `task-completed` and `task-failed` reminders are batched within the configured window. * - `all-tasks-complete` reminders are sent immediately. * * Reminders are always stored in channel history regardless of notification setting. * * @param reminder - The system reminder to process */ notify(reminder: SystemReminder): Promise; /** * Format a single reminder as a chat message (Discord/Slack compatible markdown) * * @param reminder - The system reminder to format * @returns Formatted message string */ formatChatMessage(reminder: SystemReminder): string; /** * Format multiple reminders into a single batch notification message * * @param reminders - Array of completed/failed reminders * @returns Formatted batch message string */ formatBatchMessage(reminders: SystemReminder[]): string; /** * Get recent reminders for a channel (for agent context injection) * * @param channelId - The channel to retrieve reminders for * @param limit - Maximum number of reminders to return (default: 10) * @returns Array of recent reminders, newest first */ getRecentReminders(channelId: string, limit?: number): SystemReminder[]; /** * Clear all stored reminders for a channel * * @param channelId - The channel to clear */ clearChannel(channelId: string): void; /** * Format recent reminders as context string for agent conversation injection * * @param channelId - Channel to pull context from * @param limit - Maximum number of reminders to include (default: 5) * @returns Formatted context string, or empty string if no reminders */ formatContextInjection(channelId: string, limit?: number): string; /** * Destroy the service and clear all state. * Flushes pending batches immediately before clearing. */ destroy(): Promise; /** * Store a reminder in the per-channel history ring buffer */ private storeReminder; /** * Add a completed/failed reminder to the batch queue for its channel. * Starts or extends the batch window timer. */ /** * Build a scope key for batching: source:channelId to prevent cross-platform mixing. */ private getBatchKey; private addToBatch; /** * Flush the pending batch for a scope key (source:channelId), sending a combined message */ private flushBatch; /** * Send a message to all registered platform callbacks */ private sendToAllCallbacks; /** * Enforce Discord character limit */ private enforceLimit; } //# sourceMappingURL=system-reminder.d.ts.map