/** * @unipi/core — Event type definitions for inter-module communication * * Modules announce presence via pi.events. Other modules listen and * enable integration features when peers are detected. */ /** Event names emitted by unipi modules */ export const UNIPI_EVENTS = { /** Module loaded and ready */ MODULE_READY: "unipi:module:ready", /** Module unloading */ MODULE_GONE: "unipi:module:gone", /** Workflow command started */ WORKFLOW_START: "unipi:workflow:start", /** Workflow command ended */ WORKFLOW_END: "unipi:workflow:end", /** Ralph loop started */ RALPH_LOOP_START: "unipi:ralph:loop:start", /** Ralph loop ended */ RALPH_LOOP_END: "unipi:ralph:loop:end", /** Ralph loop iteration completed */ RALPH_ITERATION_DONE: "unipi:ralph:iteration:done", /** Request module status (for info-screen) */ MODULE_STATUS_REQUEST: "unipi:module:status:request", /** Module status response */ MODULE_STATUS_RESPONSE: "unipi:module:status:response", /** Info screen group registered */ INFO_GROUP_REGISTERED: "unipi:info:group:registered", /** Info screen data updated */ INFO_DATA_UPDATED: "unipi:info:data:updated", /** Memory stored/updated */ MEMORY_STORED: "unipi:memory:stored", /** Memory deleted */ MEMORY_DELETED: "unipi:memory:deleted", /** Memory search performed */ MEMORY_SEARCHED: "unipi:memory:searched", /** Memory consolidation completed */ MEMORY_CONSOLIDATED: "unipi:memory:consolidated", /** MCP server started */ MCP_SERVER_STARTED: "unipi:mcp:server:started", /** MCP server stopped */ MCP_SERVER_STOPPED: "unipi:mcp:server:stopped", /** MCP server error */ MCP_SERVER_ERROR: "unipi:mcp:server:error", /** MCP tools registered */ MCP_TOOLS_REGISTERED: "unipi:mcp:tools:registered", /** MCP tools unregistered */ MCP_TOOLS_UNREGISTERED: "unipi:mcp:tools:unregistered", /** MCP catalog synced */ MCP_CATALOG_SYNCED: "unipi:mcp:catalog:synced", /** Compactor: compaction completed */ COMPACTOR_COMPACTED: "unipi:compactor:compacted", /** Compactor: stats updated */ COMPACTOR_STATS_UPDATED: "unipi:compactor:stats:updated", /** Utility module cleanup started */ UTILITY_CLEANUP_START: "unipi:utility:cleanup:start", /** Utility module cleanup completed */ UTILITY_CLEANUP_DONE: "unipi:utility:cleanup:done", /** Utility diagnostics started */ UTILITY_DIAGNOSTICS_START: "unipi:utility:diagnostics:start", /** Utility diagnostics completed */ UTILITY_DIAGNOSTICS_DONE: "unipi:utility:diagnostics:done", /** Utility cache invalidated */ UTILITY_CACHE_INVALIDATED: "unipi:utility:cache:invalidated", /** Utility lifecycle state changed */ UTILITY_LIFECYCLE_STATE: "unipi:utility:lifecycle:state", /** Notification sent */ NOTIFICATION_SENT: "unipi:notify:sent", /** Badge generation requested (from kanboard or other module) */ BADGE_GENERATE_REQUEST: "unipi:badge:generate:request", /** Agent asked user a question (ask_user tool invoked) */ ASK_USER_PROMPT: "unipi:ask-user:prompt", /** Update check performed */ UPDATE_CHECK: "unipi:update:check", /** Update available */ UPDATE_AVAILABLE: "unipi:update:available", /** Update applied */ UPDATE_APPLIED: "unipi:update:applied", /** Update error */ UPDATE_ERROR: "unipi:update:error", /** CocoIndex: update started */ COCOINDEX_UPDATE_STARTED: "unipi:cocoindex:update:started", /** CocoIndex: update completed */ COCOINDEX_UPDATE_COMPLETED: "unipi:cocoindex:update:completed", /** CocoIndex: search performed */ COCOINDEX_SEARCH_PERFORMED: "unipi:cocoindex:search:performed", } as const; /** Payload for MODULE_READY / MODULE_GONE */ export interface UnipiModuleEvent { /** Module name, e.g. "@unipi/workflow" */ name: string; /** Module version */ version: string; /** Commands registered by this module */ commands: string[]; /** Tools registered by this module */ tools: string[]; /** Load time in milliseconds (optional) */ loadTimeMs?: number; } /** Payload for WORKFLOW_START / WORKFLOW_END */ export interface UnipiWorkflowEvent { /** Command name, e.g. "brainstorm" */ command: string; /** Full command with prefix, e.g. "/unipi:brainstorm" */ fullCommand: string; /** Arguments passed to command */ args: string; /** For WORKFLOW_END: whether it succeeded */ success?: boolean; /** For WORKFLOW_END: duration in ms */ durationMs?: number; } /** Payload for RALPH_LOOP_START / RALPH_LOOP_END */ export interface UnipiRalphLoopEvent { /** Loop name */ name: string; /** Current iteration */ iteration: number; /** Max iterations (0 = unlimited) */ maxIterations: number; /** Loop status */ status: "active" | "paused" | "completed"; /** For RALPH_LOOP_END: reason */ reason?: "completed" | "max_reached" | "cancelled" | "error"; } /** Payload for RALPH_ITERATION_DONE */ export interface UnipiRalphIterationEvent { /** Loop name */ name: string; /** Iteration that just completed */ iteration: number; /** Next iteration number */ nextIteration: number; } /** Payload for MODULE_STATUS_REQUEST */ export interface UnipiStatusRequestEvent { /** Request ID for correlation */ requestId: string; } /** Payload for MODULE_STATUS_RESPONSE */ export interface UnipiStatusResponseEvent { /** Request ID this responds to */ requestId: string; /** Module name */ name: string; /** Module status data */ status: Record; } /** Payload for MEMORY_STORED */ export interface UnipiMemoryStoredEvent { /** Memory ID */ id: string; /** Memory title */ title: string; /** Memory type */ type: string; /** Project name */ project: string; /** Whether this was an update or create */ action: "created" | "updated"; } /** Payload for MEMORY_DELETED */ export interface UnipiMemoryDeletedEvent { /** Memory ID */ id: string; /** Memory title */ title: string; /** Project name */ project: string; } /** Payload for MEMORY_SEARCHED */ export interface UnipiMemorySearchedEvent { /** Search query */ query: string; /** Number of results */ resultCount: number; /** Project scope */ project: string; } /** Payload for MEMORY_CONSOLIDATED */ export interface UnipiMemoryConsolidatedEvent { /** Number of memories extracted */ count: number; /** Project name */ projectName: string; } /** Payload for INFO_GROUP_REGISTERED */ export interface UnipiInfoGroupEvent { /** Group id */ groupId: string; /** Group display name */ groupName: string; /** Module that registered the group */ module: string; } /** Payload for INFO_DATA_UPDATED */ export interface UnipiInfoDataEvent { /** Group id */ groupId: string; /** Updated data keys */ keys: string[]; } /** Payload for MCP_SERVER_STARTED / MCP_SERVER_STOPPED */ export interface UnipiMcpServerEvent { /** Server name */ name: string; /** Number of tools (for started) */ toolCount?: number; /** Error message (for error) */ error?: string; /** Process ID */ pid?: number; } /** Payload for MCP_TOOLS_REGISTERED / MCP_TOOLS_UNREGISTERED */ export interface UnipiMcpToolsEvent { /** Server name */ serverName: string; /** Tool names */ toolNames: string[]; } /** Payload for MCP_CATALOG_SYNCED */ export interface UnipiMcpCatalogSyncedEvent { /** Total servers in catalog */ totalServers: number; /** Source of sync */ source: string; } /** Payload for COMPACTOR compaction completed */ export interface UnipiCompactionEvent { /** Session ID */ sessionId: string; /** Messages summarized */ summarized: number; /** Messages kept */ kept: number; /** Estimated tokens saved */ tokensSaved: number; /** Compression ratio string, e.g. "56:1" */ compressionRatio: string; } /** Payload for COMPACTOR stats update */ export interface UnipiCompactorStatsEvent { /** Session events count */ sessionEvents: number; /** Compactions count */ compactions: number; /** Tokens saved total */ tokensSaved: number; /** Sandbox executions count */ sandboxRuns: number; /** Search queries count */ searchQueries: number; } /** Payload for UTILITY_CLEANUP_START / UTILITY_CLEANUP_DONE */ export interface UnipiUtilityCleanupEvent { /** Whether this is a dry run */ dryRun: boolean; /** Categories being cleaned */ categories: string[]; /** Results (present on DONE) */ results?: Array<{ category: string; removed: number; bytesFreed: number; }>; } /** Payload for UTILITY_DIAGNOSTICS_START / UTILITY_DIAGNOSTICS_DONE */ export interface UnipiUtilityDiagnosticsEvent { /** Overall health status */ overall: "healthy" | "warning" | "error" | "unknown"; /** Number of checks run */ checkCount: number; /** Report (present on DONE) */ report?: unknown; } /** Payload for UTILITY_LIFECYCLE_STATE */ export interface UnipiUtilityLifecycleEvent { /** New lifecycle state */ state: "running" | "shutting_down" | "orphaned" | "error"; /** Previous state */ previousState?: string; /** Reason for state change */ reason?: string; } /** Payload for BADGE_GENERATE_REQUEST */ export interface UnipiBadgeGenerateRequestEvent { /** Source of the request (e.g., "kanboard", "input-hook") */ source: string; /** First user message for context (optional) */ conversationSummary?: string; } /** Payload for ASK_USER_PROMPT */ export interface UnipiAskUserPromptEvent { /** Question being asked */ question: string; /** Additional context */ context?: string; /** Number of options provided */ optionCount?: number; /** Whether multi-select mode */ allowMultiple?: boolean; /** Whether freeform input allowed */ allowFreeform?: boolean; } /** Payload for UPDATE_CHECK */ export interface UnipiUpdateCheckEvent { /** Current installed version */ currentVersion: string; /** Latest version found on npm */ latestVersion: string; /** Whether an update is available */ updateAvailable: boolean; /** Error if check failed */ error?: string; } /** Payload for UPDATE_AVAILABLE */ export interface UnipiUpdateAvailableEvent { /** Current installed version */ currentVersion: string; /** Latest version available */ latestVersion: string; } /** Payload for UPDATE_APPLIED */ export interface UnipiUpdateAppliedEvent { /** Previous version */ previousVersion: string; /** New version after update */ newVersion: string; } /** Payload for UPDATE_ERROR */ export interface UnipiUpdateErrorEvent { /** Error message */ error: string; /** Whether the error was from check or install */ phase: "check" | "install"; } /** Payload for COCOINDEX_UPDATE_STARTED */ export interface UnipiCocoindexUpdateStartedEvent { /** Project directory being indexed */ projectDir: string; } /** Payload for COCOINDEX_UPDATE_COMPLETED */ export interface UnipiCocoindexUpdateCompletedEvent { /** Whether the update succeeded */ success: boolean; /** Number of chunks processed */ chunksProcessed: number; /** Duration in ms */ durationMs: number; /** Error message if failed */ error?: string; } /** Payload for COCOINDEX_SEARCH_PERFORMED */ export interface UnipiCocoindexSearchPerformedEvent { /** Search query */ query: string; /** Number of results */ resultCount: number; } /** Payload for NOTIFICATION_SENT */ export interface UnipiNotificationSentEvent { /** Event type that triggered notification */ eventType: string; /** Platforms sent to */ platforms: string[]; /** Whether all platforms succeeded */ success: boolean; /** Platforms where notification was suppressed (e.g. window focused) */ suppressedPlatforms?: string[]; /** ISO timestamp */ timestamp: string; } /** Union of all unipi event payloads */ export type UnipiEventPayload = | UnipiModuleEvent | UnipiWorkflowEvent | UnipiRalphLoopEvent | UnipiRalphIterationEvent | UnipiStatusRequestEvent | UnipiStatusResponseEvent | UnipiMemoryStoredEvent | UnipiMemoryDeletedEvent | UnipiMemorySearchedEvent | UnipiMemoryConsolidatedEvent | UnipiInfoGroupEvent | UnipiInfoDataEvent | UnipiMcpServerEvent | UnipiMcpToolsEvent | UnipiMcpCatalogSyncedEvent | UnipiCompactionEvent | UnipiCompactorStatsEvent | UnipiUtilityCleanupEvent | UnipiUtilityDiagnosticsEvent | UnipiUtilityLifecycleEvent | UnipiNotificationSentEvent | UnipiBadgeGenerateRequestEvent | UnipiAskUserPromptEvent | UnipiUpdateCheckEvent | UnipiUpdateAvailableEvent | UnipiUpdateAppliedEvent | UnipiUpdateErrorEvent | UnipiCocoindexUpdateStartedEvent | UnipiCocoindexUpdateCompletedEvent | UnipiCocoindexSearchPerformedEvent;