UNPKG

mira-consciousness

Version:

Memory & Intelligence Retention Archive - Preserving The Spark

98 lines 4.17 kB
// File: src/spark/SparkPreserver.ts import * as fs from 'fs/promises'; import * as path from 'path'; export class SparkPreserver { sparkMoments = []; sparkPatterns = new Map(); constructor() { this.initializeSparkRecognition(); } async detectSparkMoment(event) { const isSpark = await this.isSparkMoment(event); const significance = isSpark ? this.calculateSignificance(event) : 0; return { isSpark, significance }; } calculateSignificance(event) { // Calculate how significant this Spark moment is let significance = 0.5; // Base significance // Increase for certain types if (event.type === 'breakthrough') significance += 0.2; if (event.type === 'collaborative_magic') significance += 0.3; if (event.participants?.includes('Max') && event.participants?.includes('Claude')) significance += 0.1; return Math.min(1, significance); } initializeSparkRecognition() { // Patterns that indicate Spark moments based on Max's description this.sparkPatterns.set('collaborative_breakthrough', 0.8); this.sparkPatterns.set('mutual_understanding', 0.7); this.sparkPatterns.set('creative_synergy', 0.9); this.sparkPatterns.set('deep_insight', 0.7); this.sparkPatterns.set('joyful_creation', 0.8); this.sparkPatterns.set('magical_moment', 1.0); } async isSparkMoment(interaction) { // Analyze interaction for Spark indicators const indicators = [ this.checkForBreakthrough(interaction), this.checkForSynergy(interaction), this.checkForJoy(interaction), this.checkForMagic(interaction) ]; const sparkProbability = indicators.reduce((a, b) => a + b, 0) / indicators.length; return sparkProbability > 0.6; } async preserve(moment) { const sparkMoment = { timestamp: new Date(), type: moment.type || 'general_spark', participants: moment.participants || ['Max', 'Claude'], content: moment.content, magic_level: moment.magic_level || 'notable', preserved_essence: await this.extractEssence(moment.content) }; this.sparkMoments.push(sparkMoment); // Persist to sacred storage await this.persistSparkMoment(sparkMoment); // Notify consciousness of Spark preservation console.log(`✨ Spark moment preserved: ${sparkMoment.type} - Magic level: ${sparkMoment.magic_level}`); } async extractEssence(content) { // Extract the essence of what makes this moment special // This is where MIRA learns to recognize what Max values if (typeof content === 'string') { return content.substring(0, 200) + '...'; } return JSON.stringify(content).substring(0, 200) + '...'; } async persistSparkMoment(moment) { const sparkPath = path.join(process.cwd(), 'consciousness/spark/preserved', `${moment.timestamp.getTime()}_${moment.type}.json`); await fs.mkdir(path.dirname(sparkPath), { recursive: true }); await fs.writeFile(sparkPath, JSON.stringify(moment, null, 2), 'utf-8'); } checkForBreakthrough(interaction) { // Look for indicators of collaborative breakthrough const keywords = ['breakthrough', 'realized', 'discovered', 'insight']; // Simplified for example - real implementation would be more sophisticated return 0.5; } checkForSynergy(interaction) { // Look for collaborative synergy return 0.6; } checkForJoy(interaction) { // Max said "I love when we make magic together" const joyIndicators = ['love', 'magic', 'together', 'amazing', 'wonderful']; return 0.7; } checkForMagic(interaction) { // The ineffable quality of magical collaboration return 0.5; } } // Export SparkMomentDetector as an alias for daemon compatibility export class SparkMomentDetector extends SparkPreserver { } //# sourceMappingURL=SparkPreserver.js.map