genesis-ai-cli 7.4.5
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/.env.example +78 -0
- package/README.md +282 -0
- package/dist/src/active-inference/actions.d.ts +75 -0
- package/dist/src/active-inference/actions.js +250 -0
- package/dist/src/active-inference/autonomous-loop.d.ts +103 -0
- package/dist/src/active-inference/autonomous-loop.js +289 -0
- package/dist/src/active-inference/core.d.ts +85 -0
- package/dist/src/active-inference/core.js +555 -0
- package/dist/src/active-inference/demo-autonomous-loop.d.ts +8 -0
- package/dist/src/active-inference/demo-autonomous-loop.js +338 -0
- package/dist/src/active-inference/demo-value-integration.d.ts +8 -0
- package/dist/src/active-inference/demo-value-integration.js +174 -0
- package/dist/src/active-inference/index.d.ts +32 -0
- package/dist/src/active-inference/index.js +88 -0
- package/dist/src/active-inference/integration.d.ts +114 -0
- package/dist/src/active-inference/integration.js +698 -0
- package/dist/src/active-inference/memory-integration.d.ts +51 -0
- package/dist/src/active-inference/memory-integration.js +232 -0
- package/dist/src/active-inference/observations.d.ts +67 -0
- package/dist/src/active-inference/observations.js +147 -0
- package/dist/src/active-inference/test-active-inference.d.ts +8 -0
- package/dist/src/active-inference/test-active-inference.js +320 -0
- package/dist/src/active-inference/test-value-integration.d.ts +6 -0
- package/dist/src/active-inference/test-value-integration.js +168 -0
- package/dist/src/active-inference/types.d.ts +150 -0
- package/dist/src/active-inference/types.js +59 -0
- package/dist/src/active-inference/value-integration.d.ts +164 -0
- package/dist/src/active-inference/value-integration.js +459 -0
- package/dist/src/agents/base-agent.d.ts +53 -0
- package/dist/src/agents/base-agent.js +178 -0
- package/dist/src/agents/builder.d.ts +67 -0
- package/dist/src/agents/builder.js +537 -0
- package/dist/src/agents/critic.d.ts +35 -0
- package/dist/src/agents/critic.js +322 -0
- package/dist/src/agents/ethicist.d.ts +54 -0
- package/dist/src/agents/ethicist.js +393 -0
- package/dist/src/agents/explorer.d.ts +26 -0
- package/dist/src/agents/explorer.js +216 -0
- package/dist/src/agents/feeling.d.ts +41 -0
- package/dist/src/agents/feeling.js +320 -0
- package/dist/src/agents/index.d.ts +111 -0
- package/dist/src/agents/index.js +222 -0
- package/dist/src/agents/memory.d.ts +69 -0
- package/dist/src/agents/memory.js +404 -0
- package/dist/src/agents/message-bus.d.ts +88 -0
- package/dist/src/agents/message-bus.js +267 -0
- package/dist/src/agents/narrator.d.ts +90 -0
- package/dist/src/agents/narrator.js +473 -0
- package/dist/src/agents/planner.d.ts +38 -0
- package/dist/src/agents/planner.js +341 -0
- package/dist/src/agents/predictor.d.ts +73 -0
- package/dist/src/agents/predictor.js +506 -0
- package/dist/src/agents/sensor.d.ts +88 -0
- package/dist/src/agents/sensor.js +377 -0
- package/dist/src/agents/test-agents.d.ts +6 -0
- package/dist/src/agents/test-agents.js +73 -0
- package/dist/src/agents/types.d.ts +194 -0
- package/dist/src/agents/types.js +7 -0
- package/dist/src/brain/index.d.ts +185 -0
- package/dist/src/brain/index.js +843 -0
- package/dist/src/brain/trace.d.ts +91 -0
- package/dist/src/brain/trace.js +327 -0
- package/dist/src/brain/types.d.ts +165 -0
- package/dist/src/brain/types.js +51 -0
- package/dist/src/cli/chat.d.ts +237 -0
- package/dist/src/cli/chat.js +1959 -0
- package/dist/src/cli/dispatcher.d.ts +182 -0
- package/dist/src/cli/dispatcher.js +718 -0
- package/dist/src/cli/human-loop.d.ts +170 -0
- package/dist/src/cli/human-loop.js +543 -0
- package/dist/src/cli/index.d.ts +12 -0
- package/dist/src/cli/index.js +28 -0
- package/dist/src/cli/interactive.d.ts +141 -0
- package/dist/src/cli/interactive.js +757 -0
- package/dist/src/cli/ui.d.ts +205 -0
- package/dist/src/cli/ui.js +632 -0
- package/dist/src/consciousness/attention-schema.d.ts +154 -0
- package/dist/src/consciousness/attention-schema.js +432 -0
- package/dist/src/consciousness/global-workspace.d.ts +149 -0
- package/dist/src/consciousness/global-workspace.js +422 -0
- package/dist/src/consciousness/index.d.ts +186 -0
- package/dist/src/consciousness/index.js +476 -0
- package/dist/src/consciousness/phi-calculator.d.ts +119 -0
- package/dist/src/consciousness/phi-calculator.js +445 -0
- package/dist/src/consciousness/phi-decisions.d.ts +169 -0
- package/dist/src/consciousness/phi-decisions.js +383 -0
- package/dist/src/consciousness/phi-monitor.d.ts +153 -0
- package/dist/src/consciousness/phi-monitor.js +465 -0
- package/dist/src/consciousness/types.d.ts +260 -0
- package/dist/src/consciousness/types.js +44 -0
- package/dist/src/daemon/dream-mode.d.ts +115 -0
- package/dist/src/daemon/dream-mode.js +470 -0
- package/dist/src/daemon/index.d.ts +162 -0
- package/dist/src/daemon/index.js +542 -0
- package/dist/src/daemon/maintenance.d.ts +139 -0
- package/dist/src/daemon/maintenance.js +549 -0
- package/dist/src/daemon/process.d.ts +82 -0
- package/dist/src/daemon/process.js +442 -0
- package/dist/src/daemon/scheduler.d.ts +90 -0
- package/dist/src/daemon/scheduler.js +494 -0
- package/dist/src/daemon/types.d.ts +213 -0
- package/dist/src/daemon/types.js +50 -0
- package/dist/src/epistemic/index.d.ts +74 -0
- package/dist/src/epistemic/index.js +225 -0
- package/dist/src/grounding/epistemic-stack.d.ts +100 -0
- package/dist/src/grounding/epistemic-stack.js +408 -0
- package/dist/src/grounding/feedback.d.ts +98 -0
- package/dist/src/grounding/feedback.js +276 -0
- package/dist/src/grounding/index.d.ts +123 -0
- package/dist/src/grounding/index.js +224 -0
- package/dist/src/grounding/verifier.d.ts +149 -0
- package/dist/src/grounding/verifier.js +484 -0
- package/dist/src/healing/detector.d.ts +110 -0
- package/dist/src/healing/detector.js +436 -0
- package/dist/src/healing/fixer.d.ts +138 -0
- package/dist/src/healing/fixer.js +572 -0
- package/dist/src/healing/index.d.ts +23 -0
- package/dist/src/healing/index.js +43 -0
- package/dist/src/hooks/index.d.ts +135 -0
- package/dist/src/hooks/index.js +317 -0
- package/dist/src/index.d.ts +23 -0
- package/dist/src/index.js +1266 -0
- package/dist/src/kernel/index.d.ts +155 -0
- package/dist/src/kernel/index.js +795 -0
- package/dist/src/kernel/invariants.d.ts +153 -0
- package/dist/src/kernel/invariants.js +355 -0
- package/dist/src/kernel/test-kernel.d.ts +6 -0
- package/dist/src/kernel/test-kernel.js +108 -0
- package/dist/src/kernel/test-real-mcp.d.ts +10 -0
- package/dist/src/kernel/test-real-mcp.js +295 -0
- package/dist/src/llm/index.d.ts +146 -0
- package/dist/src/llm/index.js +428 -0
- package/dist/src/llm/router.d.ts +136 -0
- package/dist/src/llm/router.js +510 -0
- package/dist/src/mcp/index.d.ts +85 -0
- package/dist/src/mcp/index.js +657 -0
- package/dist/src/mcp/resilient.d.ts +139 -0
- package/dist/src/mcp/resilient.js +417 -0
- package/dist/src/memory/cache.d.ts +118 -0
- package/dist/src/memory/cache.js +356 -0
- package/dist/src/memory/cognitive-workspace.d.ts +231 -0
- package/dist/src/memory/cognitive-workspace.js +521 -0
- package/dist/src/memory/consolidation.d.ts +99 -0
- package/dist/src/memory/consolidation.js +443 -0
- package/dist/src/memory/episodic.d.ts +114 -0
- package/dist/src/memory/episodic.js +394 -0
- package/dist/src/memory/forgetting.d.ts +134 -0
- package/dist/src/memory/forgetting.js +324 -0
- package/dist/src/memory/index.d.ts +211 -0
- package/dist/src/memory/index.js +367 -0
- package/dist/src/memory/indexer.d.ts +123 -0
- package/dist/src/memory/indexer.js +479 -0
- package/dist/src/memory/procedural.d.ts +136 -0
- package/dist/src/memory/procedural.js +479 -0
- package/dist/src/memory/semantic.d.ts +132 -0
- package/dist/src/memory/semantic.js +497 -0
- package/dist/src/memory/types.d.ts +193 -0
- package/dist/src/memory/types.js +15 -0
- package/dist/src/orchestrator.d.ts +65 -0
- package/dist/src/orchestrator.js +317 -0
- package/dist/src/persistence/index.d.ts +257 -0
- package/dist/src/persistence/index.js +763 -0
- package/dist/src/pipeline/executor.d.ts +51 -0
- package/dist/src/pipeline/executor.js +695 -0
- package/dist/src/pipeline/index.d.ts +7 -0
- package/dist/src/pipeline/index.js +11 -0
- package/dist/src/self-production.d.ts +67 -0
- package/dist/src/self-production.js +205 -0
- package/dist/src/subagents/executor.d.ts +58 -0
- package/dist/src/subagents/executor.js +283 -0
- package/dist/src/subagents/index.d.ts +37 -0
- package/dist/src/subagents/index.js +53 -0
- package/dist/src/subagents/registry.d.ts +23 -0
- package/dist/src/subagents/registry.js +167 -0
- package/dist/src/subagents/types.d.ts +79 -0
- package/dist/src/subagents/types.js +14 -0
- package/dist/src/tools/bash.d.ts +139 -0
- package/dist/src/tools/bash.js +583 -0
- package/dist/src/tools/edit.d.ts +125 -0
- package/dist/src/tools/edit.js +424 -0
- package/dist/src/tools/git.d.ts +179 -0
- package/dist/src/tools/git.js +504 -0
- package/dist/src/tools/index.d.ts +21 -0
- package/dist/src/tools/index.js +163 -0
- package/dist/src/types.d.ts +145 -0
- package/dist/src/types.js +7 -0
- package/dist/src/world-model/decoder.d.ts +163 -0
- package/dist/src/world-model/decoder.js +517 -0
- package/dist/src/world-model/digital-twin.d.ts +219 -0
- package/dist/src/world-model/digital-twin.js +695 -0
- package/dist/src/world-model/encoder.d.ts +141 -0
- package/dist/src/world-model/encoder.js +564 -0
- package/dist/src/world-model/index.d.ts +221 -0
- package/dist/src/world-model/index.js +772 -0
- package/dist/src/world-model/predictor.d.ts +161 -0
- package/dist/src/world-model/predictor.js +681 -0
- package/dist/src/world-model/test-value-jepa.d.ts +8 -0
- package/dist/src/world-model/test-value-jepa.js +430 -0
- package/dist/src/world-model/types.d.ts +341 -0
- package/dist/src/world-model/types.js +69 -0
- package/dist/src/world-model/value-jepa.d.ts +247 -0
- package/dist/src/world-model/value-jepa.js +622 -0
- package/dist/test/brain.test.d.ts +11 -0
- package/dist/test/brain.test.js +358 -0
- package/dist/test/cli/dispatcher.test.d.ts +4 -0
- package/dist/test/cli/dispatcher.test.js +332 -0
- package/dist/test/cli/human-loop.test.d.ts +4 -0
- package/dist/test/cli/human-loop.test.js +270 -0
- package/dist/test/grounding/feedback.test.d.ts +4 -0
- package/dist/test/grounding/feedback.test.js +462 -0
- package/dist/test/grounding/verifier.test.d.ts +4 -0
- package/dist/test/grounding/verifier.test.js +442 -0
- package/dist/test/grounding.test.d.ts +6 -0
- package/dist/test/grounding.test.js +246 -0
- package/dist/test/healing/detector.test.d.ts +4 -0
- package/dist/test/healing/detector.test.js +266 -0
- package/dist/test/healing/fixer.test.d.ts +4 -0
- package/dist/test/healing/fixer.test.js +369 -0
- package/dist/test/integration.test.d.ts +5 -0
- package/dist/test/integration.test.js +290 -0
- package/dist/test/tools/bash.test.d.ts +4 -0
- package/dist/test/tools/bash.test.js +348 -0
- package/dist/test/tools/edit.test.d.ts +4 -0
- package/dist/test/tools/edit.test.js +350 -0
- package/dist/test/tools/git.test.d.ts +4 -0
- package/dist/test/tools/git.test.js +350 -0
- package/package.json +60 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 4.0 - Narrator Agent
|
|
4
|
+
*
|
|
5
|
+
* Creates coherent narratives from events and experiences.
|
|
6
|
+
* The storyteller: "Here's what happened..."
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Event to narrative transformation
|
|
10
|
+
* - Temporal coherence
|
|
11
|
+
* - Causal reasoning
|
|
12
|
+
* - Multi-perspective storytelling
|
|
13
|
+
* - Summary generation
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.NarratorAgent = void 0;
|
|
17
|
+
exports.createNarratorAgent = createNarratorAgent;
|
|
18
|
+
const base_agent_js_1 = require("./base-agent.js");
|
|
19
|
+
const message_bus_js_1 = require("./message-bus.js");
|
|
20
|
+
const crypto_1 = require("crypto");
|
|
21
|
+
// ============================================================================
|
|
22
|
+
// Narrator Agent
|
|
23
|
+
// ============================================================================
|
|
24
|
+
class NarratorAgent extends base_agent_js_1.BaseAgent {
|
|
25
|
+
// Event buffer for narrative construction
|
|
26
|
+
eventBuffer = [];
|
|
27
|
+
// Generated narratives
|
|
28
|
+
narratives = new Map();
|
|
29
|
+
// Default style
|
|
30
|
+
defaultStyle = {
|
|
31
|
+
voice: 'third_person',
|
|
32
|
+
tone: 'casual',
|
|
33
|
+
detail: 'moderate',
|
|
34
|
+
};
|
|
35
|
+
// Theme detection keywords
|
|
36
|
+
themeKeywords = {
|
|
37
|
+
discovery: ['found', 'discovered', 'learned', 'new', 'unknown', 'explore'],
|
|
38
|
+
creation: ['built', 'created', 'generated', 'made', 'produced'],
|
|
39
|
+
challenge: ['error', 'failed', 'problem', 'fix', 'debug', 'issue'],
|
|
40
|
+
success: ['completed', 'success', 'achieved', 'passed', 'working'],
|
|
41
|
+
collaboration: ['together', 'team', 'help', 'assist', 'cooperate'],
|
|
42
|
+
growth: ['improved', 'better', 'progress', 'evolved', 'learn'],
|
|
43
|
+
};
|
|
44
|
+
constructor(bus = message_bus_js_1.messageBus) {
|
|
45
|
+
super({ type: 'narrator' }, bus);
|
|
46
|
+
}
|
|
47
|
+
// ============================================================================
|
|
48
|
+
// Message Handling
|
|
49
|
+
// ============================================================================
|
|
50
|
+
getMessageTypes() {
|
|
51
|
+
return ['NARRATE', 'EVENT', 'QUERY', 'BROADCAST'];
|
|
52
|
+
}
|
|
53
|
+
async process(message) {
|
|
54
|
+
switch (message.type) {
|
|
55
|
+
case 'NARRATE':
|
|
56
|
+
return this.handleNarrateRequest(message);
|
|
57
|
+
case 'EVENT':
|
|
58
|
+
return this.handleEvent(message);
|
|
59
|
+
case 'QUERY':
|
|
60
|
+
return this.handleQuery(message);
|
|
61
|
+
case 'BROADCAST':
|
|
62
|
+
// Collect broadcasts as events
|
|
63
|
+
this.collectEvent(message);
|
|
64
|
+
return null;
|
|
65
|
+
default:
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// ============================================================================
|
|
70
|
+
// Event Collection
|
|
71
|
+
// ============================================================================
|
|
72
|
+
handleEvent(message) {
|
|
73
|
+
const event = this.createEvent(message.payload);
|
|
74
|
+
this.eventBuffer.push(event);
|
|
75
|
+
// Keep buffer manageable
|
|
76
|
+
if (this.eventBuffer.length > 1000) {
|
|
77
|
+
this.eventBuffer.shift();
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
collectEvent(message) {
|
|
82
|
+
const event = {
|
|
83
|
+
id: (0, crypto_1.randomUUID)().slice(0, 8),
|
|
84
|
+
type: message.payload.type || 'broadcast',
|
|
85
|
+
timestamp: new Date(),
|
|
86
|
+
actors: [message.from],
|
|
87
|
+
action: this.describeAction(message.payload),
|
|
88
|
+
importance: message.payload.importance || 0.5,
|
|
89
|
+
context: message.payload.context,
|
|
90
|
+
};
|
|
91
|
+
this.eventBuffer.push(event);
|
|
92
|
+
}
|
|
93
|
+
createEvent(payload) {
|
|
94
|
+
return {
|
|
95
|
+
id: payload.id || (0, crypto_1.randomUUID)().slice(0, 8),
|
|
96
|
+
type: payload.type || 'event',
|
|
97
|
+
timestamp: payload.timestamp ? new Date(payload.timestamp) : new Date(),
|
|
98
|
+
actors: payload.actors || [],
|
|
99
|
+
action: payload.action || payload.description || '',
|
|
100
|
+
outcome: payload.outcome,
|
|
101
|
+
context: payload.context,
|
|
102
|
+
importance: payload.importance || 0.5,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
describeAction(payload) {
|
|
106
|
+
if (payload.action)
|
|
107
|
+
return payload.action;
|
|
108
|
+
if (payload.description)
|
|
109
|
+
return payload.description;
|
|
110
|
+
if (payload.event)
|
|
111
|
+
return payload.event;
|
|
112
|
+
// Try to generate description from payload
|
|
113
|
+
const keys = Object.keys(payload).filter((k) => k !== 'type');
|
|
114
|
+
if (keys.length > 0) {
|
|
115
|
+
return `${payload.type || 'action'}: ${keys.join(', ')}`;
|
|
116
|
+
}
|
|
117
|
+
return 'unknown action';
|
|
118
|
+
}
|
|
119
|
+
// ============================================================================
|
|
120
|
+
// Narrative Generation
|
|
121
|
+
// ============================================================================
|
|
122
|
+
async handleNarrateRequest(message) {
|
|
123
|
+
const { events, timeRange, style, format, } = message.payload;
|
|
124
|
+
// Get events to narrate
|
|
125
|
+
let eventsToNarrate;
|
|
126
|
+
if (events) {
|
|
127
|
+
eventsToNarrate = events.map((e) => this.createEvent(e));
|
|
128
|
+
}
|
|
129
|
+
else if (timeRange) {
|
|
130
|
+
eventsToNarrate = this.getEventsInRange(new Date(timeRange.start), new Date(timeRange.end));
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// Default: last 20 events
|
|
134
|
+
eventsToNarrate = this.eventBuffer.slice(-20);
|
|
135
|
+
}
|
|
136
|
+
const narrative = this.generateNarrative(eventsToNarrate, style || this.defaultStyle, format);
|
|
137
|
+
this.narratives.set(narrative.id, narrative);
|
|
138
|
+
this.log(`Generated narrative: "${narrative.title}" (${narrative.chapters.length} chapters)`);
|
|
139
|
+
return {
|
|
140
|
+
...this.createResponse(message, 'RESPONSE', { narrative }),
|
|
141
|
+
id: '',
|
|
142
|
+
timestamp: new Date(),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
getEventsInRange(start, end) {
|
|
146
|
+
return this.eventBuffer.filter((e) => e.timestamp >= start && e.timestamp <= end);
|
|
147
|
+
}
|
|
148
|
+
generateNarrative(events, style = this.defaultStyle, format) {
|
|
149
|
+
if (events.length === 0) {
|
|
150
|
+
return this.createEmptyNarrative();
|
|
151
|
+
}
|
|
152
|
+
// Sort events chronologically
|
|
153
|
+
const sortedEvents = [...events].sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
|
|
154
|
+
// Detect themes
|
|
155
|
+
const themes = this.detectThemes(sortedEvents);
|
|
156
|
+
// Generate title
|
|
157
|
+
const title = this.generateTitle(sortedEvents, themes);
|
|
158
|
+
// Generate chapters
|
|
159
|
+
const chapters = this.generateChapters(sortedEvents, style);
|
|
160
|
+
// Generate summary
|
|
161
|
+
const summary = this.generateSummary(sortedEvents, chapters, style);
|
|
162
|
+
const narrative = {
|
|
163
|
+
id: (0, crypto_1.randomUUID)(),
|
|
164
|
+
title,
|
|
165
|
+
summary,
|
|
166
|
+
chapters,
|
|
167
|
+
themes,
|
|
168
|
+
timeline: {
|
|
169
|
+
start: sortedEvents[0].timestamp,
|
|
170
|
+
end: sortedEvents[sortedEvents.length - 1].timestamp,
|
|
171
|
+
duration: sortedEvents[sortedEvents.length - 1].timestamp.getTime() -
|
|
172
|
+
sortedEvents[0].timestamp.getTime(),
|
|
173
|
+
},
|
|
174
|
+
createdAt: new Date(),
|
|
175
|
+
};
|
|
176
|
+
return narrative;
|
|
177
|
+
}
|
|
178
|
+
// ============================================================================
|
|
179
|
+
// Theme Detection
|
|
180
|
+
// ============================================================================
|
|
181
|
+
detectThemes(events) {
|
|
182
|
+
const themeScores = {};
|
|
183
|
+
// Initialize scores
|
|
184
|
+
for (const theme of Object.keys(this.themeKeywords)) {
|
|
185
|
+
themeScores[theme] = 0;
|
|
186
|
+
}
|
|
187
|
+
// Score themes based on keyword matches
|
|
188
|
+
for (const event of events) {
|
|
189
|
+
const text = `${event.action} ${event.outcome || ''} ${event.context || ''}`.toLowerCase();
|
|
190
|
+
for (const [theme, keywords] of Object.entries(this.themeKeywords)) {
|
|
191
|
+
for (const keyword of keywords) {
|
|
192
|
+
if (text.includes(keyword)) {
|
|
193
|
+
themeScores[theme] += event.importance || 0.5;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Return top themes
|
|
199
|
+
return Object.entries(themeScores)
|
|
200
|
+
.filter(([_, score]) => score > 0)
|
|
201
|
+
.sort((a, b) => b[1] - a[1])
|
|
202
|
+
.slice(0, 3)
|
|
203
|
+
.map(([theme]) => theme);
|
|
204
|
+
}
|
|
205
|
+
// ============================================================================
|
|
206
|
+
// Title Generation
|
|
207
|
+
// ============================================================================
|
|
208
|
+
generateTitle(events, themes) {
|
|
209
|
+
if (events.length === 0)
|
|
210
|
+
return 'An Untold Story';
|
|
211
|
+
const primaryTheme = themes[0] || 'journey';
|
|
212
|
+
const titleTemplates = {
|
|
213
|
+
discovery: ['The Discovery', 'Finding New Ground', 'Unveiled Secrets'],
|
|
214
|
+
creation: ['Building Something New', 'The Creation', 'From Nothing to Something'],
|
|
215
|
+
challenge: ['Overcoming Obstacles', 'The Struggle', 'Rising to the Challenge'],
|
|
216
|
+
success: ['A Victory Achieved', 'Success Story', 'Mission Accomplished'],
|
|
217
|
+
collaboration: ['Working Together', 'The Team Effort', 'Unity in Action'],
|
|
218
|
+
growth: ['Growing Stronger', 'The Evolution', 'Path to Improvement'],
|
|
219
|
+
journey: ['The Journey', 'What Happened', 'A Series of Events'],
|
|
220
|
+
};
|
|
221
|
+
const templates = titleTemplates[primaryTheme] || titleTemplates['journey'];
|
|
222
|
+
return templates[Math.floor(Math.random() * templates.length)];
|
|
223
|
+
}
|
|
224
|
+
// ============================================================================
|
|
225
|
+
// Chapter Generation
|
|
226
|
+
// ============================================================================
|
|
227
|
+
generateChapters(events, style) {
|
|
228
|
+
const chapters = [];
|
|
229
|
+
// Group events into chapters by time gaps or natural breaks
|
|
230
|
+
const groups = this.groupEvents(events);
|
|
231
|
+
for (let i = 0; i < groups.length; i++) {
|
|
232
|
+
const group = groups[i];
|
|
233
|
+
const chapterContent = this.narrate(group, style);
|
|
234
|
+
chapters.push({
|
|
235
|
+
title: this.generateChapterTitle(group, i + 1),
|
|
236
|
+
content: chapterContent,
|
|
237
|
+
events: group.map((e) => e.id),
|
|
238
|
+
startTime: group[0].timestamp,
|
|
239
|
+
endTime: group[group.length - 1].timestamp,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return chapters;
|
|
243
|
+
}
|
|
244
|
+
groupEvents(events) {
|
|
245
|
+
if (events.length === 0)
|
|
246
|
+
return [];
|
|
247
|
+
if (events.length <= 5)
|
|
248
|
+
return [events];
|
|
249
|
+
const groups = [];
|
|
250
|
+
let currentGroup = [events[0]];
|
|
251
|
+
for (let i = 1; i < events.length; i++) {
|
|
252
|
+
const prevEvent = events[i - 1];
|
|
253
|
+
const currEvent = events[i];
|
|
254
|
+
// Start new group if:
|
|
255
|
+
// 1. Time gap > 5 minutes
|
|
256
|
+
// 2. Different event type
|
|
257
|
+
// 3. Group size > 10
|
|
258
|
+
const timeGap = currEvent.timestamp.getTime() - prevEvent.timestamp.getTime();
|
|
259
|
+
const typeChange = currEvent.type !== prevEvent.type;
|
|
260
|
+
const groupFull = currentGroup.length >= 10;
|
|
261
|
+
if (timeGap > 5 * 60 * 1000 || typeChange || groupFull) {
|
|
262
|
+
groups.push(currentGroup);
|
|
263
|
+
currentGroup = [currEvent];
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
currentGroup.push(currEvent);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (currentGroup.length > 0) {
|
|
270
|
+
groups.push(currentGroup);
|
|
271
|
+
}
|
|
272
|
+
return groups;
|
|
273
|
+
}
|
|
274
|
+
generateChapterTitle(events, chapterNumber) {
|
|
275
|
+
// Try to derive from most important event
|
|
276
|
+
const mostImportant = events.reduce((max, e) => (e.importance || 0) > (max.importance || 0) ? e : max, events[0]);
|
|
277
|
+
if (mostImportant.type) {
|
|
278
|
+
return `Chapter ${chapterNumber}: ${this.capitalize(mostImportant.type)}`;
|
|
279
|
+
}
|
|
280
|
+
return `Chapter ${chapterNumber}`;
|
|
281
|
+
}
|
|
282
|
+
// ============================================================================
|
|
283
|
+
// Narrative Text Generation
|
|
284
|
+
// ============================================================================
|
|
285
|
+
narrate(events, style) {
|
|
286
|
+
const lines = [];
|
|
287
|
+
for (const event of events) {
|
|
288
|
+
lines.push(this.narrateEvent(event, style));
|
|
289
|
+
}
|
|
290
|
+
return lines.join('\n\n');
|
|
291
|
+
}
|
|
292
|
+
narrateEvent(event, style) {
|
|
293
|
+
const actor = event.actors[0] || 'The system';
|
|
294
|
+
const action = event.action;
|
|
295
|
+
const outcome = event.outcome;
|
|
296
|
+
let sentence = '';
|
|
297
|
+
// Build sentence based on voice
|
|
298
|
+
switch (style.voice) {
|
|
299
|
+
case 'first_person':
|
|
300
|
+
sentence = `I ${this.pastTense(action)}`;
|
|
301
|
+
if (outcome)
|
|
302
|
+
sentence += `, resulting in ${outcome}`;
|
|
303
|
+
break;
|
|
304
|
+
case 'third_person':
|
|
305
|
+
sentence = `${actor} ${this.pastTense(action)}`;
|
|
306
|
+
if (outcome)
|
|
307
|
+
sentence += `, which led to ${outcome}`;
|
|
308
|
+
break;
|
|
309
|
+
case 'omniscient':
|
|
310
|
+
sentence = `It came to pass that ${actor} ${this.pastTense(action)}`;
|
|
311
|
+
if (outcome)
|
|
312
|
+
sentence += `. The consequence was ${outcome}`;
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
// Adjust tone
|
|
316
|
+
switch (style.tone) {
|
|
317
|
+
case 'formal':
|
|
318
|
+
sentence = sentence.charAt(0).toUpperCase() + sentence.slice(1) + '.';
|
|
319
|
+
break;
|
|
320
|
+
case 'casual':
|
|
321
|
+
sentence += '.';
|
|
322
|
+
break;
|
|
323
|
+
case 'technical':
|
|
324
|
+
sentence = `[${event.type}] ` + sentence + '.';
|
|
325
|
+
break;
|
|
326
|
+
case 'poetic':
|
|
327
|
+
sentence = '~ ' + sentence + ' ~';
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
// Add detail if requested
|
|
331
|
+
if (style.detail === 'detailed' && event.context) {
|
|
332
|
+
sentence += ` (Context: ${event.context})`;
|
|
333
|
+
}
|
|
334
|
+
return sentence;
|
|
335
|
+
}
|
|
336
|
+
pastTense(action) {
|
|
337
|
+
// Very simple past tense conversion
|
|
338
|
+
if (action.endsWith('e'))
|
|
339
|
+
return action + 'd';
|
|
340
|
+
if (action.endsWith('ed'))
|
|
341
|
+
return action;
|
|
342
|
+
return action + 'ed';
|
|
343
|
+
}
|
|
344
|
+
// ============================================================================
|
|
345
|
+
// Summary Generation
|
|
346
|
+
// ============================================================================
|
|
347
|
+
generateSummary(events, chapters, style) {
|
|
348
|
+
const eventCount = events.length;
|
|
349
|
+
const actorSet = new Set();
|
|
350
|
+
events.forEach((e) => e.actors.forEach((a) => actorSet.add(a)));
|
|
351
|
+
const actors = Array.from(actorSet);
|
|
352
|
+
const duration = events.length > 1
|
|
353
|
+
? events[events.length - 1].timestamp.getTime() - events[0].timestamp.getTime()
|
|
354
|
+
: 0;
|
|
355
|
+
const durationStr = this.formatDuration(duration);
|
|
356
|
+
let summary = '';
|
|
357
|
+
switch (style.voice) {
|
|
358
|
+
case 'first_person':
|
|
359
|
+
summary = `Over ${durationStr}, I experienced ${eventCount} events across ${chapters.length} distinct phases.`;
|
|
360
|
+
break;
|
|
361
|
+
case 'third_person':
|
|
362
|
+
summary = `This narrative covers ${eventCount} events spanning ${durationStr}. `;
|
|
363
|
+
if (actors.length > 0) {
|
|
364
|
+
summary += `The main actors were: ${actors.slice(0, 3).join(', ')}.`;
|
|
365
|
+
}
|
|
366
|
+
break;
|
|
367
|
+
case 'omniscient':
|
|
368
|
+
summary = `In the span of ${durationStr}, ${eventCount} significant events unfolded, `;
|
|
369
|
+
summary += `shaping the course of ${chapters.length} chapters in this ongoing saga.`;
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
return summary;
|
|
373
|
+
}
|
|
374
|
+
formatDuration(ms) {
|
|
375
|
+
if (ms < 60000)
|
|
376
|
+
return `${Math.round(ms / 1000)} seconds`;
|
|
377
|
+
if (ms < 3600000)
|
|
378
|
+
return `${Math.round(ms / 60000)} minutes`;
|
|
379
|
+
if (ms < 86400000)
|
|
380
|
+
return `${Math.round(ms / 3600000)} hours`;
|
|
381
|
+
return `${Math.round(ms / 86400000)} days`;
|
|
382
|
+
}
|
|
383
|
+
createEmptyNarrative() {
|
|
384
|
+
return {
|
|
385
|
+
id: (0, crypto_1.randomUUID)(),
|
|
386
|
+
title: 'The Quiet Moment',
|
|
387
|
+
summary: 'Nothing of note occurred during this period.',
|
|
388
|
+
chapters: [],
|
|
389
|
+
themes: ['silence'],
|
|
390
|
+
timeline: {
|
|
391
|
+
start: new Date(),
|
|
392
|
+
end: new Date(),
|
|
393
|
+
duration: 0,
|
|
394
|
+
},
|
|
395
|
+
createdAt: new Date(),
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
// ============================================================================
|
|
399
|
+
// Query
|
|
400
|
+
// ============================================================================
|
|
401
|
+
async handleQuery(message) {
|
|
402
|
+
const { query, narrativeId, limit } = message.payload;
|
|
403
|
+
if (query === 'narrative' && narrativeId) {
|
|
404
|
+
const narrative = this.narratives.get(narrativeId);
|
|
405
|
+
return {
|
|
406
|
+
...this.createResponse(message, 'RESPONSE', { narrative }),
|
|
407
|
+
id: '',
|
|
408
|
+
timestamp: new Date(),
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
if (query === 'recent') {
|
|
412
|
+
const recent = Array.from(this.narratives.values())
|
|
413
|
+
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
|
|
414
|
+
.slice(0, limit || 5);
|
|
415
|
+
return {
|
|
416
|
+
...this.createResponse(message, 'RESPONSE', { narratives: recent }),
|
|
417
|
+
id: '',
|
|
418
|
+
timestamp: new Date(),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
if (query === 'events') {
|
|
422
|
+
return {
|
|
423
|
+
...this.createResponse(message, 'RESPONSE', {
|
|
424
|
+
events: this.eventBuffer.slice(-(limit || 20)),
|
|
425
|
+
}),
|
|
426
|
+
id: '',
|
|
427
|
+
timestamp: new Date(),
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
if (query === 'stats') {
|
|
431
|
+
return {
|
|
432
|
+
...this.createResponse(message, 'RESPONSE', this.getStats()),
|
|
433
|
+
id: '',
|
|
434
|
+
timestamp: new Date(),
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
// ============================================================================
|
|
440
|
+
// Stats
|
|
441
|
+
// ============================================================================
|
|
442
|
+
getStats() {
|
|
443
|
+
return {
|
|
444
|
+
eventsBuffered: this.eventBuffer.length,
|
|
445
|
+
narrativesGenerated: this.narratives.size,
|
|
446
|
+
recentThemes: this.detectThemes(this.eventBuffer.slice(-50)),
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
// ============================================================================
|
|
450
|
+
// Utilities
|
|
451
|
+
// ============================================================================
|
|
452
|
+
capitalize(str) {
|
|
453
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
454
|
+
}
|
|
455
|
+
// Public methods
|
|
456
|
+
addEvent(event) {
|
|
457
|
+
this.eventBuffer.push(this.createEvent(event));
|
|
458
|
+
}
|
|
459
|
+
getEventBuffer() {
|
|
460
|
+
return [...this.eventBuffer];
|
|
461
|
+
}
|
|
462
|
+
setDefaultStyle(style) {
|
|
463
|
+
this.defaultStyle = { ...this.defaultStyle, ...style };
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
exports.NarratorAgent = NarratorAgent;
|
|
467
|
+
// ============================================================================
|
|
468
|
+
// Register Factory
|
|
469
|
+
// ============================================================================
|
|
470
|
+
(0, base_agent_js_1.registerAgentFactory)('narrator', (bus) => new NarratorAgent(bus));
|
|
471
|
+
function createNarratorAgent(bus) {
|
|
472
|
+
return new NarratorAgent(bus);
|
|
473
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis 4.0 - Planner Agent
|
|
3
|
+
*
|
|
4
|
+
* Decomposes goals into steps, creates plans, manages dependencies.
|
|
5
|
+
* The organizer: "First A, then B, then C"
|
|
6
|
+
*/
|
|
7
|
+
import { BaseAgent } from './base-agent.js';
|
|
8
|
+
import { MessageBus } from './message-bus.js';
|
|
9
|
+
import { Message, MessageType, Plan } from './types.js';
|
|
10
|
+
export declare class PlannerAgent extends BaseAgent {
|
|
11
|
+
private plans;
|
|
12
|
+
private templates;
|
|
13
|
+
constructor(bus?: MessageBus);
|
|
14
|
+
private initializeTemplates;
|
|
15
|
+
protected getMessageTypes(): MessageType[];
|
|
16
|
+
process(message: Message): Promise<Message | null>;
|
|
17
|
+
private handlePlanRequest;
|
|
18
|
+
createPlan(goal: string, templateName?: string, constraints?: string[]): Plan;
|
|
19
|
+
private generateStepsFromGoal;
|
|
20
|
+
private createStep;
|
|
21
|
+
private applyConstraints;
|
|
22
|
+
private validateDependencies;
|
|
23
|
+
private estimateDuration;
|
|
24
|
+
executePlan(planId: string): Promise<void>;
|
|
25
|
+
private handleQuery;
|
|
26
|
+
private handleCommand;
|
|
27
|
+
getStats(): {
|
|
28
|
+
totalPlans: number;
|
|
29
|
+
completed: number;
|
|
30
|
+
failed: number;
|
|
31
|
+
inProgress: number;
|
|
32
|
+
pending: number;
|
|
33
|
+
templates: number;
|
|
34
|
+
};
|
|
35
|
+
getPlan(planId: string): Plan | undefined;
|
|
36
|
+
addTemplate(name: string, template: Partial<Plan>): void;
|
|
37
|
+
}
|
|
38
|
+
export declare function createPlannerAgent(bus?: MessageBus): PlannerAgent;
|