Zeitgeist Watcher
Recipe: Zeitgeist Watcher
Section titled “Recipe: Zeitgeist Watcher”“The collective consciousness of the moment — what’s hot right now?”
The Problem
Section titled “The Problem”Tracking “trending” topics traditionally requires:
- Counting events over time windows (
COUNT(*) WHERE timestamp > NOW() - INTERVAL) - Complex decay functions for “velocity”
- Separate cron jobs for cleanup
- Arbitrary thresholds for “trending”
What if trending was just high energy?
The Pattern
Section titled “The Pattern”graph LR
subgraph "Topic Energy States"
A[bitcoin<br/>E=0.95] --- Hot[🔥 HOT]
B[ethereum<br/>E=0.6] --- Warm[🌡️ WARM]
C[dogecoin<br/>E=0.2] --- Cold[❄️ COLD]
D[defunct_coin<br/>E=0.01] --- Dormant[💀 DORMANT]
end
Key insight:
- Each mention/event stimulates the topic
- Natural decay replaces explicit window-based TTLs
- Consciousness threshold (mood-dependent) defines “trending”
- Topics that stop being mentioned naturally fade
The Code
Section titled “The Code”import { MindFry } from '@mindfry/client'
class ZeitgeistWatcher { private brain: MindFry private namespace: string
constructor(brain: MindFry, namespace = 'topics') { this.brain = brain this.namespace = namespace }
// Called every time a topic is mentioned async recordMention(topic: string, weight = 0.1) { const key = `${this.namespace}:${topic}`
try { // Try to stimulate existing topic await this.brain.lineage.stimulate({ key, delta: weight, }) } catch (e) { // Topic doesn't exist yet — create it await this.brain.lineage.create({ key, energy: weight, }) } }
// Record co-occurrence (topics mentioned together) async recordCoOccurrence(topicA: string, topicB: string) { const keyA = `${this.namespace}:${topicA}` const keyB = `${this.namespace}:${topicB}`
// Create or strengthen synergy bond await this.brain.bond.connect({ from: keyA, to: keyB, strength: 0.5, polarity: 1, // Synergy }) }
// Get trending topics (above consciousness threshold) async getTrending(limit = 10): Promise<string[]> { // Set high mood to capture more topics await this.brain.system.setMood(0.7)
// In a full implementation, you'd query for // all lineages in namespace with energy > threshold // For now, this is conceptual
const stats = await this.brain.system.stats() console.log(`Total topics tracked: ${stats.lineage_count}`)
// Placeholder: return would be sorted by energy return [] }
// Get related trending topics async getRelated(topic: string): Promise<string[]> { const key = `${this.namespace}:${topic}`
// Stimulate and let propagation reveal related topics await this.brain.lineage.stimulate({ key, delta: 0.3, })
// Query neighbors that received cascade energy const neighbors = await this.brain.query.neighbors(key) return neighbors.map((n) => n.key.replace(`${this.namespace}:`, '')) }}
// Usageasync function trackSocialMedia(brain: MindFry) { const zeitgeist = new ZeitgeistWatcher(brain)
// Simulate incoming mentions await zeitgeist.recordMention('bitcoin', 0.2) await zeitgeist.recordMention('bitcoin', 0.15) await zeitgeist.recordMention('ethereum', 0.1) await zeitgeist.recordMention('bitcoin', 0.25) // Another spike
// Record that bitcoin and ethereum were mentioned together await zeitgeist.recordCoOccurrence('bitcoin', 'ethereum')
// Later: bitcoin naturally decays if not mentioned // No cron job needed — just wait
// Get what's currently hot const trending = await zeitgeist.getTrending(5) console.log('🔥 Trending:', trending)}The Insight
Section titled “The Insight”Energy Thresholds as Categories
Section titled “Energy Thresholds as Categories”function categorizeEnergy(energy: number): string { if (energy > 0.8) return '🔥 HOT' if (energy > 0.5) return '🌡️ WARM' if (energy > 0.2) return '❄️ COLD' if (energy > 0.05) return '😴 DORMANT' return '💀 FORGOTTEN'}Mood as Trend Sensitivity
Section titled “Mood as Trend Sensitivity”// Broad trend capture (include warm topics)await brain.system.setMood(0.9) // Euphoric: low thresholdconst broadTrends = await zeitgeist.getTrending(20)
// Strict trending (only truly hot)await brain.system.setMood(0.3) // Focused: high thresholdconst strictTrends = await zeitgeist.getTrending(5)Cascade for Related Topics
Section titled “Cascade for Related Topics”When you stimulate “bitcoin”, synergy bonds cascade to related topics:
graph TD
BTC[bitcoin<br/>+1.0] -->|synergy| ETH[ethereum<br/>+0.5]
BTC -->|synergy| CRYPTO[crypto<br/>+0.5]
ETH -->|synergy| DEFI[defi<br/>+0.25]
BTC -->|antagonism| FIAT[fiat<br/>-0.4]
This means searching for “bitcoin trends” automatically surfaces the entire crypto zeitgeist.
Real-World Integration
Section titled “Real-World Integration”// Hook into event streameventBus.on('social_mention', async (event) => { await zeitgeist.recordMention(event.topic, event.sentiment)
if (event.coMentions) { for (const coTopic of event.coMentions) { await zeitgeist.recordCoOccurrence(event.topic, coTopic) } }})
// Periodic trending reportsetInterval(async () => { const hot = await zeitgeist.getTrending(10) console.log(`[${new Date().toISOString()}] 🔥 Hot topics:`, hot)}, 60_000) // Every minuteNext: Explore the Architecture to understand how MindFry makes this possible.