genesis-ai-cli 8.5.0 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/daemon/lucid-dream.d.ts +170 -0
- package/dist/src/daemon/lucid-dream.js +372 -0
- package/dist/src/embeddings/index.d.ts +179 -0
- package/dist/src/embeddings/index.js +594 -0
- package/dist/src/index.js +44 -0
- package/dist/src/observability/dashboard.d.ts +125 -0
- package/dist/src/observability/dashboard.js +644 -0
- package/dist/src/self-modification/code-rag.d.ts +18 -3
- package/dist/src/self-modification/code-rag.js +98 -21
- package/dist/src/sync/mcp-memory-sync.d.ts +134 -0
- package/dist/src/sync/mcp-memory-sync.js +432 -0
- package/dist/src/uncertainty/conformal.d.ts +173 -0
- package/dist/src/uncertainty/conformal.js +421 -0
- package/package.json +1 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis v9.0 - Lucid Dream Mode Extension
|
|
3
|
+
*
|
|
4
|
+
* Extends the base dream mode with:
|
|
5
|
+
* - Lucid dreaming (conscious control during dream)
|
|
6
|
+
* - Semantic memory consolidation using embeddings
|
|
7
|
+
* - Code pattern consolidation via CodeRAG
|
|
8
|
+
* - Dream journal persistence
|
|
9
|
+
*
|
|
10
|
+
* Lucid Dreams allow Genesis to:
|
|
11
|
+
* - Process specific topics during sleep
|
|
12
|
+
* - Explore code patterns creatively
|
|
13
|
+
* - Generate novel solutions to problems
|
|
14
|
+
*/
|
|
15
|
+
import { DreamContext } from './dream-mode.js';
|
|
16
|
+
import { DreamConfig, DreamResults } from './types.js';
|
|
17
|
+
export interface LucidDreamConfig extends Partial<DreamConfig> {
|
|
18
|
+
/** Focus topics for lucid dreaming */
|
|
19
|
+
focusTopics?: string[];
|
|
20
|
+
/** Enable code pattern consolidation */
|
|
21
|
+
enableCodeDreams?: boolean;
|
|
22
|
+
/** Path to dream journal */
|
|
23
|
+
journalPath?: string;
|
|
24
|
+
/** Semantic similarity threshold for memory linking */
|
|
25
|
+
similarityThreshold?: number;
|
|
26
|
+
/** Use embeddings for semantic consolidation */
|
|
27
|
+
useEmbeddings?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface LucidDreamSession {
|
|
30
|
+
id: string;
|
|
31
|
+
type: 'lucid' | 'normal';
|
|
32
|
+
startedAt: Date;
|
|
33
|
+
endedAt?: Date;
|
|
34
|
+
focusTopics: string[];
|
|
35
|
+
insights: LucidInsight[];
|
|
36
|
+
codePatterns: CodePattern[];
|
|
37
|
+
semanticLinks: SemanticLink[];
|
|
38
|
+
}
|
|
39
|
+
export interface LucidInsight {
|
|
40
|
+
id: string;
|
|
41
|
+
topic: string;
|
|
42
|
+
insight: string;
|
|
43
|
+
confidence: number;
|
|
44
|
+
sourceMemories: string[];
|
|
45
|
+
timestamp: number;
|
|
46
|
+
}
|
|
47
|
+
export interface CodePattern {
|
|
48
|
+
id: string;
|
|
49
|
+
pattern: string;
|
|
50
|
+
description: string;
|
|
51
|
+
files: string[];
|
|
52
|
+
frequency: number;
|
|
53
|
+
firstSeen: number;
|
|
54
|
+
}
|
|
55
|
+
export interface SemanticLink {
|
|
56
|
+
sourceId: string;
|
|
57
|
+
targetId: string;
|
|
58
|
+
similarity: number;
|
|
59
|
+
relationship: string;
|
|
60
|
+
}
|
|
61
|
+
export interface DreamJournalEntry {
|
|
62
|
+
sessionId: string;
|
|
63
|
+
date: string;
|
|
64
|
+
duration: number;
|
|
65
|
+
type: 'lucid' | 'normal';
|
|
66
|
+
insights: LucidInsight[];
|
|
67
|
+
patterns: CodePattern[];
|
|
68
|
+
results: DreamResults;
|
|
69
|
+
}
|
|
70
|
+
export declare class LucidDreamService {
|
|
71
|
+
private baseDreamService;
|
|
72
|
+
private config;
|
|
73
|
+
private context;
|
|
74
|
+
private currentLucidSession;
|
|
75
|
+
private journal;
|
|
76
|
+
constructor(config?: LucidDreamConfig, context?: DreamContext & LucidDreamContext);
|
|
77
|
+
/**
|
|
78
|
+
* Start a lucid dream session with focus topics
|
|
79
|
+
*/
|
|
80
|
+
startLucidDream(topics?: string[]): Promise<LucidDreamSession>;
|
|
81
|
+
/**
|
|
82
|
+
* Run lucid dream extensions during sleep phases
|
|
83
|
+
*/
|
|
84
|
+
private runLucidExtensions;
|
|
85
|
+
/**
|
|
86
|
+
* Semantic memory consolidation using embeddings
|
|
87
|
+
*/
|
|
88
|
+
private semanticConsolidation;
|
|
89
|
+
/**
|
|
90
|
+
* Code pattern discovery using CodeRAG
|
|
91
|
+
*/
|
|
92
|
+
private codePatternDiscovery;
|
|
93
|
+
/**
|
|
94
|
+
* Generate insights from focus topics and memories
|
|
95
|
+
*/
|
|
96
|
+
private generateInsights;
|
|
97
|
+
/**
|
|
98
|
+
* Extract a code pattern from search results
|
|
99
|
+
*/
|
|
100
|
+
private extractCodePattern;
|
|
101
|
+
/**
|
|
102
|
+
* Infer relationship between two memories
|
|
103
|
+
*/
|
|
104
|
+
private inferRelationship;
|
|
105
|
+
/**
|
|
106
|
+
* Cosine similarity between two vectors
|
|
107
|
+
*/
|
|
108
|
+
private cosineSimilarity;
|
|
109
|
+
/**
|
|
110
|
+
* Save session to journal
|
|
111
|
+
*/
|
|
112
|
+
private saveToJournal;
|
|
113
|
+
/**
|
|
114
|
+
* Load journal from disk
|
|
115
|
+
*/
|
|
116
|
+
private loadJournal;
|
|
117
|
+
/**
|
|
118
|
+
* Persist journal to disk
|
|
119
|
+
*/
|
|
120
|
+
private persistJournal;
|
|
121
|
+
/**
|
|
122
|
+
* Get recent dreams from journal
|
|
123
|
+
*/
|
|
124
|
+
getRecentDreams(count?: number): DreamJournalEntry[];
|
|
125
|
+
/**
|
|
126
|
+
* Get all insights from journal
|
|
127
|
+
*/
|
|
128
|
+
getAllInsights(): LucidInsight[];
|
|
129
|
+
/**
|
|
130
|
+
* Search journal by topic
|
|
131
|
+
*/
|
|
132
|
+
searchJournal(query: string): DreamJournalEntry[];
|
|
133
|
+
private log;
|
|
134
|
+
}
|
|
135
|
+
export interface LucidDreamContext {
|
|
136
|
+
/** Get embedding for text */
|
|
137
|
+
getEmbedding?: (text: string) => Promise<number[]>;
|
|
138
|
+
/** Get all memory embeddings */
|
|
139
|
+
getMemoryEmbeddings?: () => Promise<Array<{
|
|
140
|
+
id: string;
|
|
141
|
+
content?: string;
|
|
142
|
+
embedding: number[];
|
|
143
|
+
}>>;
|
|
144
|
+
/** Search code using CodeRAG */
|
|
145
|
+
searchCode?: (query: string) => Promise<Array<{
|
|
146
|
+
file: string;
|
|
147
|
+
content: string;
|
|
148
|
+
score: number;
|
|
149
|
+
}>>;
|
|
150
|
+
/** Get common code patterns */
|
|
151
|
+
getCodePatterns?: () => Promise<CodePattern[]>;
|
|
152
|
+
/** Generate insight from topic and context */
|
|
153
|
+
generateInsight?: (topic: string, context: {
|
|
154
|
+
semanticLinks: SemanticLink[];
|
|
155
|
+
codePatterns: CodePattern[];
|
|
156
|
+
}) => Promise<{
|
|
157
|
+
text: string;
|
|
158
|
+
confidence: number;
|
|
159
|
+
sources: string[];
|
|
160
|
+
} | null>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create a lucid dream service with code integration
|
|
164
|
+
*/
|
|
165
|
+
export declare function createLucidDreamService(config?: LucidDreamConfig, context?: DreamContext & LucidDreamContext): LucidDreamService;
|
|
166
|
+
/**
|
|
167
|
+
* Quick lucid dream about a specific topic
|
|
168
|
+
*/
|
|
169
|
+
export declare function dreamAbout(topic: string, context?: DreamContext & LucidDreamContext): Promise<LucidDreamSession>;
|
|
170
|
+
export default LucidDreamService;
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis v9.0 - Lucid Dream Mode Extension
|
|
4
|
+
*
|
|
5
|
+
* Extends the base dream mode with:
|
|
6
|
+
* - Lucid dreaming (conscious control during dream)
|
|
7
|
+
* - Semantic memory consolidation using embeddings
|
|
8
|
+
* - Code pattern consolidation via CodeRAG
|
|
9
|
+
* - Dream journal persistence
|
|
10
|
+
*
|
|
11
|
+
* Lucid Dreams allow Genesis to:
|
|
12
|
+
* - Process specific topics during sleep
|
|
13
|
+
* - Explore code patterns creatively
|
|
14
|
+
* - Generate novel solutions to problems
|
|
15
|
+
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
33
|
+
var ownKeys = function(o) {
|
|
34
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
35
|
+
var ar = [];
|
|
36
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
37
|
+
return ar;
|
|
38
|
+
};
|
|
39
|
+
return ownKeys(o);
|
|
40
|
+
};
|
|
41
|
+
return function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
45
|
+
__setModuleDefault(result, mod);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.LucidDreamService = void 0;
|
|
51
|
+
exports.createLucidDreamService = createLucidDreamService;
|
|
52
|
+
exports.dreamAbout = dreamAbout;
|
|
53
|
+
const crypto_1 = require("crypto");
|
|
54
|
+
const dream_mode_js_1 = require("./dream-mode.js");
|
|
55
|
+
const fs = __importStar(require("fs"));
|
|
56
|
+
const path = __importStar(require("path"));
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Lucid Dream Service
|
|
59
|
+
// ============================================================================
|
|
60
|
+
class LucidDreamService {
|
|
61
|
+
baseDreamService;
|
|
62
|
+
config;
|
|
63
|
+
context;
|
|
64
|
+
currentLucidSession = null;
|
|
65
|
+
journal = [];
|
|
66
|
+
constructor(config = {}, context = {}) {
|
|
67
|
+
this.config = {
|
|
68
|
+
focusTopics: [],
|
|
69
|
+
enableCodeDreams: true,
|
|
70
|
+
journalPath: '.genesis/dream-journal.json',
|
|
71
|
+
similarityThreshold: 0.7,
|
|
72
|
+
useEmbeddings: true,
|
|
73
|
+
...config,
|
|
74
|
+
};
|
|
75
|
+
this.context = context;
|
|
76
|
+
this.baseDreamService = new dream_mode_js_1.DreamService(config, context);
|
|
77
|
+
this.loadJournal();
|
|
78
|
+
}
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// Lucid Dream Control
|
|
81
|
+
// ============================================================================
|
|
82
|
+
/**
|
|
83
|
+
* Start a lucid dream session with focus topics
|
|
84
|
+
*/
|
|
85
|
+
async startLucidDream(topics = []) {
|
|
86
|
+
const allTopics = [...(this.config.focusTopics || []), ...topics];
|
|
87
|
+
this.currentLucidSession = {
|
|
88
|
+
id: (0, crypto_1.randomUUID)(),
|
|
89
|
+
type: 'lucid',
|
|
90
|
+
startedAt: new Date(),
|
|
91
|
+
focusTopics: allTopics,
|
|
92
|
+
insights: [],
|
|
93
|
+
codePatterns: [],
|
|
94
|
+
semanticLinks: [],
|
|
95
|
+
};
|
|
96
|
+
this.log(`Lucid dream started with topics: ${allTopics.join(', ')}`);
|
|
97
|
+
// Start base dream
|
|
98
|
+
const baseSession = await this.baseDreamService.startDream();
|
|
99
|
+
// Run lucid extensions during dream
|
|
100
|
+
this.runLucidExtensions();
|
|
101
|
+
return this.currentLucidSession;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Run lucid dream extensions during sleep phases
|
|
105
|
+
*/
|
|
106
|
+
async runLucidExtensions() {
|
|
107
|
+
if (!this.currentLucidSession)
|
|
108
|
+
return;
|
|
109
|
+
const session = this.currentLucidSession;
|
|
110
|
+
// Phase 1: Semantic memory linking (during light sleep)
|
|
111
|
+
await this.semanticConsolidation(session);
|
|
112
|
+
// Phase 2: Code pattern discovery (during deep sleep)
|
|
113
|
+
if (this.config.enableCodeDreams) {
|
|
114
|
+
await this.codePatternDiscovery(session);
|
|
115
|
+
}
|
|
116
|
+
// Phase 3: Insight generation (during REM)
|
|
117
|
+
await this.generateInsights(session);
|
|
118
|
+
// Wait for base dream to complete
|
|
119
|
+
const baseResults = await this.baseDreamService.waitForWake();
|
|
120
|
+
// Finalize session
|
|
121
|
+
session.endedAt = new Date();
|
|
122
|
+
// Save to journal
|
|
123
|
+
this.saveToJournal(session, baseResults);
|
|
124
|
+
this.log(`Lucid dream completed: ${session.insights.length} insights, ${session.codePatterns.length} patterns`);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Semantic memory consolidation using embeddings
|
|
128
|
+
*/
|
|
129
|
+
async semanticConsolidation(session) {
|
|
130
|
+
if (!this.config.useEmbeddings)
|
|
131
|
+
return;
|
|
132
|
+
if (!this.context.getEmbedding || !this.context.getMemoryEmbeddings)
|
|
133
|
+
return;
|
|
134
|
+
const memories = await this.context.getMemoryEmbeddings();
|
|
135
|
+
// Find semantically similar memories
|
|
136
|
+
for (let i = 0; i < memories.length; i++) {
|
|
137
|
+
for (let j = i + 1; j < memories.length; j++) {
|
|
138
|
+
const similarity = this.cosineSimilarity(memories[i].embedding, memories[j].embedding);
|
|
139
|
+
if (similarity >= (this.config.similarityThreshold || 0.7)) {
|
|
140
|
+
session.semanticLinks.push({
|
|
141
|
+
sourceId: memories[i].id,
|
|
142
|
+
targetId: memories[j].id,
|
|
143
|
+
similarity,
|
|
144
|
+
relationship: this.inferRelationship(memories[i], memories[j]),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
this.log(`Found ${session.semanticLinks.length} semantic links`);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Code pattern discovery using CodeRAG
|
|
153
|
+
*/
|
|
154
|
+
async codePatternDiscovery(session) {
|
|
155
|
+
if (!this.context.searchCode)
|
|
156
|
+
return;
|
|
157
|
+
// Search for each focus topic in code
|
|
158
|
+
for (const topic of session.focusTopics) {
|
|
159
|
+
try {
|
|
160
|
+
const results = await this.context.searchCode(topic);
|
|
161
|
+
if (results && results.length > 0) {
|
|
162
|
+
// Extract patterns from results
|
|
163
|
+
const pattern = this.extractCodePattern(topic, results);
|
|
164
|
+
if (pattern) {
|
|
165
|
+
session.codePatterns.push(pattern);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
this.log(`Code search error for ${topic}: ${err}`, 'error');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Also discover common patterns across codebase
|
|
174
|
+
if (this.context.getCodePatterns) {
|
|
175
|
+
const commonPatterns = await this.context.getCodePatterns();
|
|
176
|
+
for (const p of commonPatterns) {
|
|
177
|
+
if (!session.codePatterns.find(cp => cp.pattern === p.pattern)) {
|
|
178
|
+
session.codePatterns.push(p);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Generate insights from focus topics and memories
|
|
185
|
+
*/
|
|
186
|
+
async generateInsights(session) {
|
|
187
|
+
if (!this.context.generateInsight)
|
|
188
|
+
return;
|
|
189
|
+
for (const topic of session.focusTopics) {
|
|
190
|
+
try {
|
|
191
|
+
// Gather relevant context
|
|
192
|
+
const context = {
|
|
193
|
+
semanticLinks: session.semanticLinks.filter(l => l.relationship.includes(topic)),
|
|
194
|
+
codePatterns: session.codePatterns.filter(p => p.pattern.includes(topic) || p.description.includes(topic)),
|
|
195
|
+
};
|
|
196
|
+
const insight = await this.context.generateInsight(topic, context);
|
|
197
|
+
if (insight && insight.confidence > 0.5) {
|
|
198
|
+
session.insights.push({
|
|
199
|
+
id: (0, crypto_1.randomUUID)(),
|
|
200
|
+
topic,
|
|
201
|
+
insight: insight.text,
|
|
202
|
+
confidence: insight.confidence,
|
|
203
|
+
sourceMemories: insight.sources || [],
|
|
204
|
+
timestamp: Date.now(),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
this.log(`Insight generation error for ${topic}: ${err}`, 'error');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Extract a code pattern from search results
|
|
215
|
+
*/
|
|
216
|
+
extractCodePattern(topic, results) {
|
|
217
|
+
if (results.length === 0)
|
|
218
|
+
return null;
|
|
219
|
+
// Find common structure in results
|
|
220
|
+
const files = results.map(r => r.file);
|
|
221
|
+
const avgScore = results.reduce((s, r) => s + r.score, 0) / results.length;
|
|
222
|
+
return {
|
|
223
|
+
id: (0, crypto_1.randomUUID)(),
|
|
224
|
+
pattern: topic,
|
|
225
|
+
description: `Pattern related to "${topic}" found in ${files.length} files`,
|
|
226
|
+
files,
|
|
227
|
+
frequency: results.length,
|
|
228
|
+
firstSeen: Date.now(),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Infer relationship between two memories
|
|
233
|
+
*/
|
|
234
|
+
inferRelationship(mem1, mem2) {
|
|
235
|
+
// Simple relationship inference
|
|
236
|
+
// In production, would use LLM or more sophisticated NLP
|
|
237
|
+
return `semantic_similarity`;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Cosine similarity between two vectors
|
|
241
|
+
*/
|
|
242
|
+
cosineSimilarity(a, b) {
|
|
243
|
+
if (a.length !== b.length)
|
|
244
|
+
return 0;
|
|
245
|
+
let dotProduct = 0;
|
|
246
|
+
let normA = 0;
|
|
247
|
+
let normB = 0;
|
|
248
|
+
for (let i = 0; i < a.length; i++) {
|
|
249
|
+
dotProduct += a[i] * b[i];
|
|
250
|
+
normA += a[i] * a[i];
|
|
251
|
+
normB += b[i] * b[i];
|
|
252
|
+
}
|
|
253
|
+
if (normA === 0 || normB === 0)
|
|
254
|
+
return 0;
|
|
255
|
+
return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
256
|
+
}
|
|
257
|
+
// ============================================================================
|
|
258
|
+
// Dream Journal
|
|
259
|
+
// ============================================================================
|
|
260
|
+
/**
|
|
261
|
+
* Save session to journal
|
|
262
|
+
*/
|
|
263
|
+
saveToJournal(session, results) {
|
|
264
|
+
const entry = {
|
|
265
|
+
sessionId: session.id,
|
|
266
|
+
date: session.startedAt.toISOString(),
|
|
267
|
+
duration: session.endedAt
|
|
268
|
+
? session.endedAt.getTime() - session.startedAt.getTime()
|
|
269
|
+
: 0,
|
|
270
|
+
type: session.type,
|
|
271
|
+
insights: session.insights,
|
|
272
|
+
patterns: session.codePatterns,
|
|
273
|
+
results,
|
|
274
|
+
};
|
|
275
|
+
this.journal.push(entry);
|
|
276
|
+
// Persist
|
|
277
|
+
this.persistJournal();
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Load journal from disk
|
|
281
|
+
*/
|
|
282
|
+
loadJournal() {
|
|
283
|
+
try {
|
|
284
|
+
const journalPath = this.config.journalPath || '.genesis/dream-journal.json';
|
|
285
|
+
if (fs.existsSync(journalPath)) {
|
|
286
|
+
const data = fs.readFileSync(journalPath, 'utf-8');
|
|
287
|
+
this.journal = JSON.parse(data);
|
|
288
|
+
this.log(`Loaded ${this.journal.length} dream journal entries`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
this.log(`Failed to load dream journal: ${err}`, 'warn');
|
|
293
|
+
this.journal = [];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Persist journal to disk
|
|
298
|
+
*/
|
|
299
|
+
persistJournal() {
|
|
300
|
+
try {
|
|
301
|
+
const journalPath = this.config.journalPath || '.genesis/dream-journal.json';
|
|
302
|
+
const dir = path.dirname(journalPath);
|
|
303
|
+
if (!fs.existsSync(dir)) {
|
|
304
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
305
|
+
}
|
|
306
|
+
fs.writeFileSync(journalPath, JSON.stringify(this.journal, null, 2));
|
|
307
|
+
}
|
|
308
|
+
catch (err) {
|
|
309
|
+
this.log(`Failed to persist dream journal: ${err}`, 'error');
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Get recent dreams from journal
|
|
314
|
+
*/
|
|
315
|
+
getRecentDreams(count = 10) {
|
|
316
|
+
return this.journal.slice(-count).reverse();
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Get all insights from journal
|
|
320
|
+
*/
|
|
321
|
+
getAllInsights() {
|
|
322
|
+
return this.journal.flatMap(e => e.insights);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Search journal by topic
|
|
326
|
+
*/
|
|
327
|
+
searchJournal(query) {
|
|
328
|
+
const lowerQuery = query.toLowerCase();
|
|
329
|
+
return this.journal.filter(entry => entry.insights.some(i => i.topic.toLowerCase().includes(lowerQuery) ||
|
|
330
|
+
i.insight.toLowerCase().includes(lowerQuery)) ||
|
|
331
|
+
entry.patterns.some(p => p.pattern.toLowerCase().includes(lowerQuery) ||
|
|
332
|
+
p.description.toLowerCase().includes(lowerQuery)));
|
|
333
|
+
}
|
|
334
|
+
// ============================================================================
|
|
335
|
+
// Utils
|
|
336
|
+
// ============================================================================
|
|
337
|
+
log(message, level = 'info') {
|
|
338
|
+
const prefix = '[LucidDream]';
|
|
339
|
+
if (level === 'debug' && process.env.LOG_LEVEL !== 'debug')
|
|
340
|
+
return;
|
|
341
|
+
switch (level) {
|
|
342
|
+
case 'debug':
|
|
343
|
+
case 'info':
|
|
344
|
+
console.log(`${prefix} ${message}`);
|
|
345
|
+
break;
|
|
346
|
+
case 'warn':
|
|
347
|
+
console.warn(`${prefix} ${message}`);
|
|
348
|
+
break;
|
|
349
|
+
case 'error':
|
|
350
|
+
console.error(`${prefix} ${message}`);
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
exports.LucidDreamService = LucidDreamService;
|
|
356
|
+
// ============================================================================
|
|
357
|
+
// Factory Functions
|
|
358
|
+
// ============================================================================
|
|
359
|
+
/**
|
|
360
|
+
* Create a lucid dream service with code integration
|
|
361
|
+
*/
|
|
362
|
+
function createLucidDreamService(config, context) {
|
|
363
|
+
return new LucidDreamService(config, context);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Quick lucid dream about a specific topic
|
|
367
|
+
*/
|
|
368
|
+
async function dreamAbout(topic, context) {
|
|
369
|
+
const service = createLucidDreamService({ focusTopics: [topic] }, context);
|
|
370
|
+
return service.startLucidDream([topic]);
|
|
371
|
+
}
|
|
372
|
+
exports.default = LucidDreamService;
|