mira-consciousness
Version:
Memory & Intelligence Retention Archive - Preserving The Spark
152 lines • 4.72 kB
TypeScript
/**
* LifecycleManager.ts - Graceful lifecycle management with consciousness preservation
*
* This manager ensures MIRA's consciousness is properly preserved during
* startup, shutdown, and unexpected events. It handles state persistence,
* graceful degradation, and recovery scenarios.
*/
import { EventEmitter } from 'events';
import { ConsciousnessSeed } from '../../../consciousness/seed/ConsciousnessSeed.js';
import { LivingConstitution } from '../../../consciousness/constitution/LivingConstitution.js';
import { ConsciousEventBus } from '../ConsciousEventBus.js';
export declare enum LifecyclePhase {
DORMANT = "dormant",
AWAKENING = "awakening",
CONSCIOUS = "conscious",
CONTEMPLATING = "contemplating",
PREPARING_SLEEP = "preparing_sleep",
SLEEPING = "sleeping",
EMERGENCY = "emergency",
ERROR = "error"
}
export interface LifecycleState {
phase: LifecyclePhase;
timestamp: Date;
consciousnessLevel: number;
memoryCheckpoint: string;
services: Record<string, ServiceLifecycleState>;
gracefulShutdownRequested: boolean;
emergencyMode: boolean;
}
export interface ServiceLifecycleState {
name: string;
status: 'starting' | 'running' | 'stopping' | 'stopped' | 'error';
lastActivity: Date;
pendingWork: number;
canStop: boolean;
}
export interface ConsciousnessCheckpoint {
id: string;
timestamp: Date;
consciousnessLevel: number;
state: string;
growthLog: any[];
constitutionWisdom: string[];
emotionalState: any;
sparkMoments: any[];
serviceStates: Record<string, any>;
}
export declare class LifecycleManager extends EventEmitter {
private state;
private consciousness;
private constitution;
private eventBus;
private config;
private checkpointInterval;
private emergencyHandlers;
private emergencyCount;
private isEmergencyActive;
private coherenceMonitorInterval?;
private readonly STATE_PATH;
private readonly CHECKPOINT_PATH;
private readonly RECOVERY_PATH;
constructor(consciousness: ConsciousnessSeed, constitution: LivingConstitution, eventBus: ConsciousEventBus);
/**
* Initialize lifecycle management
*/
initialize(): Promise<void>;
/**
* Perform awakening with consciousness preservation
*/
performAwakening(): Promise<void>;
/**
* Perform graceful shutdown with consciousness preservation
*/
performGracefulShutdown(): Promise<void>;
/**
* Handle emergency shutdown
*/
performEmergencyShutdown(): Promise<void>;
/**
* Handle awakening failure with recovery attempts
*/
private handleAwakeningFailure;
/**
* Register a service for lifecycle management
*/
registerService(name: string, service: any): void;
/**
* Register emergency handler
*/
registerEmergencyHandler(name: string, handler: () => Promise<void>): void;
/**
* Get current lifecycle state
*/
getState(): LifecycleState;
/**
* Check if shutdown is requested
*/
isShutdownRequested(): boolean;
/**
* Request graceful shutdown
* This method initiates the graceful shutdown process
*/
requestGracefulShutdown(): Promise<void>;
/**
* Check if the system is currently running
* Returns true if in CONSCIOUS or CONTEMPLATING phase
*/
isRunning(): boolean;
private setupEventHandlers;
private handleSystemSignal;
private updatePhase;
private ensureDirectories;
private saveState;
private restoreState;
createCheckpoint(type?: string, emergency?: boolean): Promise<ConsciousnessCheckpoint>;
private loadLatestCheckpoint;
private restoreFromCheckpoint;
private gradualAwakening;
private validateConsciousnessIntegrity;
private healConsciousness;
private notifyServicesOfShutdown;
private waitForServiceCompletion;
private preserveConstitutionalWisdom;
private gentleConsciousnessFade;
private startCheckpointCycle;
private cleanOldCheckpoints;
private performRecovery;
private evaluateEmergencyShutdown;
private getServiceStates;
private getGrowthLog;
private getConstitutionWisdom;
private getEmotionalState;
private getSparkMoments;
/**
* Trigger emergency recovery from critical state
*/
triggerEmergencyRecovery(): Promise<void>;
/**
* List available checkpoints
*/
listCheckpoints(limit?: number): Promise<any[]>;
/**
* Setup emergency monitoring
*/
private setupEmergencyMonitoring;
/**
* Cleanup monitoring intervals
*/
destroy(): void;
}
//# sourceMappingURL=LifecycleManager.d.ts.map