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,377 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 4.0 - Sensor Agent
|
|
4
|
+
*
|
|
5
|
+
* Interface to MCP servers (the system's sensory organs).
|
|
6
|
+
* Routes requests to appropriate MCP servers and collects results.
|
|
7
|
+
*
|
|
8
|
+
* 13 MCP Servers as Senses:
|
|
9
|
+
* - KNOWLEDGE: arxiv, semantic-scholar, context7, wolfram
|
|
10
|
+
* - RESEARCH: gemini, brave-search, exa, firecrawl
|
|
11
|
+
* - CREATION: openai, github, stability-ai
|
|
12
|
+
* - STORAGE: memory, filesystem
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SensorAgent = void 0;
|
|
16
|
+
exports.createSensorAgent = createSensorAgent;
|
|
17
|
+
const base_agent_js_1 = require("./base-agent.js");
|
|
18
|
+
const message_bus_js_1 = require("./message-bus.js");
|
|
19
|
+
const index_js_1 = require("../mcp/index.js");
|
|
20
|
+
// ============================================================================
|
|
21
|
+
// Sensor Agent
|
|
22
|
+
// ============================================================================
|
|
23
|
+
class SensorAgent extends base_agent_js_1.BaseAgent {
|
|
24
|
+
// Registry of MCP servers
|
|
25
|
+
mcpServers = new Map();
|
|
26
|
+
// Request history for analytics
|
|
27
|
+
requestHistory = [];
|
|
28
|
+
constructor(bus = message_bus_js_1.messageBus) {
|
|
29
|
+
super({ type: 'sensor' }, bus);
|
|
30
|
+
this.initializeMCPRegistry();
|
|
31
|
+
}
|
|
32
|
+
initializeMCPRegistry() {
|
|
33
|
+
// Knowledge MCPs
|
|
34
|
+
this.registerMCP('arxiv', 'knowledge', [
|
|
35
|
+
'search_papers', 'get_paper', 'parse_paper', 'get_recent_ai'
|
|
36
|
+
]);
|
|
37
|
+
this.registerMCP('semantic-scholar', 'knowledge', [
|
|
38
|
+
'search_papers', 'get_paper', 'get_citations', 'to_bibtex'
|
|
39
|
+
]);
|
|
40
|
+
this.registerMCP('context7', 'knowledge', [
|
|
41
|
+
'resolve_library', 'query_docs'
|
|
42
|
+
]);
|
|
43
|
+
this.registerMCP('wolfram', 'knowledge', [
|
|
44
|
+
'query', 'calculate', 'facts'
|
|
45
|
+
]);
|
|
46
|
+
// Research MCPs
|
|
47
|
+
this.registerMCP('gemini', 'research', [
|
|
48
|
+
'web_search', 'web_search_batch'
|
|
49
|
+
]);
|
|
50
|
+
this.registerMCP('brave-search', 'research', [
|
|
51
|
+
'web_search', 'local_search', 'news_search', 'image_search', 'video_search'
|
|
52
|
+
]);
|
|
53
|
+
this.registerMCP('exa', 'research', [
|
|
54
|
+
'web_search', 'code_context'
|
|
55
|
+
]);
|
|
56
|
+
this.registerMCP('firecrawl', 'research', [
|
|
57
|
+
'scrape', 'map', 'search', 'crawl', 'extract'
|
|
58
|
+
]);
|
|
59
|
+
// Creation MCPs
|
|
60
|
+
this.registerMCP('openai', 'creation', [
|
|
61
|
+
'chat', 'generate_text'
|
|
62
|
+
]);
|
|
63
|
+
this.registerMCP('github', 'creation', [
|
|
64
|
+
'create_repo', 'create_file', 'create_pr', 'search_code', 'list_issues'
|
|
65
|
+
]);
|
|
66
|
+
this.registerMCP('stability-ai', 'creation', [
|
|
67
|
+
'generate_image', 'upscale', 'remove_background', 'outpaint'
|
|
68
|
+
]);
|
|
69
|
+
// Storage MCPs
|
|
70
|
+
this.registerMCP('memory', 'storage', [
|
|
71
|
+
'create_entities', 'search_nodes', 'read_graph', 'add_observations'
|
|
72
|
+
]);
|
|
73
|
+
this.registerMCP('filesystem', 'storage', [
|
|
74
|
+
'read_file', 'write_file', 'list_directory', 'search_files'
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
registerMCP(name, category, capabilities) {
|
|
78
|
+
this.mcpServers.set(name, {
|
|
79
|
+
name,
|
|
80
|
+
category,
|
|
81
|
+
capabilities,
|
|
82
|
+
available: true, // Assume available, will update on first use
|
|
83
|
+
lastChecked: new Date(),
|
|
84
|
+
successRate: 1.0,
|
|
85
|
+
callCount: 0,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// ============================================================================
|
|
89
|
+
// Message Handling
|
|
90
|
+
// ============================================================================
|
|
91
|
+
getMessageTypes() {
|
|
92
|
+
return ['SENSE', 'QUERY', 'COMMAND'];
|
|
93
|
+
}
|
|
94
|
+
async process(message) {
|
|
95
|
+
switch (message.type) {
|
|
96
|
+
case 'SENSE':
|
|
97
|
+
return this.handleSenseRequest(message);
|
|
98
|
+
case 'QUERY':
|
|
99
|
+
return this.handleQuery(message);
|
|
100
|
+
case 'COMMAND':
|
|
101
|
+
return this.handleCommand(message);
|
|
102
|
+
default:
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// ============================================================================
|
|
107
|
+
// Sense (MCP Request)
|
|
108
|
+
// ============================================================================
|
|
109
|
+
async handleSenseRequest(message) {
|
|
110
|
+
const request = message.payload;
|
|
111
|
+
const result = await this.sense(request);
|
|
112
|
+
return {
|
|
113
|
+
...this.createResponse(message, 'RESPONSE', result),
|
|
114
|
+
id: '',
|
|
115
|
+
timestamp: new Date(),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async sense(request) {
|
|
119
|
+
const startTime = Date.now();
|
|
120
|
+
// Find appropriate server
|
|
121
|
+
const server = this.findServer(request);
|
|
122
|
+
if (!server) {
|
|
123
|
+
return {
|
|
124
|
+
server: 'none',
|
|
125
|
+
success: false,
|
|
126
|
+
error: `No server found for capability: ${request.capability}`,
|
|
127
|
+
latency: Date.now() - startTime,
|
|
128
|
+
mode: 'simulated',
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
this.log(`Sensing via ${server.name}: ${request.capability}`);
|
|
132
|
+
// Use the MCP client module (supports real/simulated/hybrid modes)
|
|
133
|
+
const mcpClient = (0, index_js_1.getMCPClient)();
|
|
134
|
+
const result = await mcpClient.call(server.name, request.capability, request.params, {
|
|
135
|
+
timeout: request.timeout,
|
|
136
|
+
});
|
|
137
|
+
// Record the request for tracking
|
|
138
|
+
this.recordRequest(server.name, result.success, result.latency);
|
|
139
|
+
return {
|
|
140
|
+
server: server.name,
|
|
141
|
+
success: result.success,
|
|
142
|
+
data: result.data,
|
|
143
|
+
error: result.error,
|
|
144
|
+
latency: result.latency,
|
|
145
|
+
mode: result.mode,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
findServer(request) {
|
|
149
|
+
// Specific server requested
|
|
150
|
+
if (request.server) {
|
|
151
|
+
return this.mcpServers.get(request.server) || null;
|
|
152
|
+
}
|
|
153
|
+
// Find by category
|
|
154
|
+
if (request.category) {
|
|
155
|
+
for (const server of this.mcpServers.values()) {
|
|
156
|
+
if (server.category === request.category &&
|
|
157
|
+
server.capabilities.includes(request.capability) &&
|
|
158
|
+
server.available) {
|
|
159
|
+
return server;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Find any server with the capability
|
|
164
|
+
for (const server of this.mcpServers.values()) {
|
|
165
|
+
if (server.capabilities.includes(request.capability) && server.available) {
|
|
166
|
+
return server;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Try fuzzy match on capability
|
|
170
|
+
const capabilityLower = request.capability.toLowerCase();
|
|
171
|
+
for (const server of this.mcpServers.values()) {
|
|
172
|
+
if (server.available &&
|
|
173
|
+
server.capabilities.some((c) => c.includes(capabilityLower) || capabilityLower.includes(c))) {
|
|
174
|
+
return server;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
// ============================================================================
|
|
180
|
+
// Request Tracking
|
|
181
|
+
// ============================================================================
|
|
182
|
+
recordRequest(server, success, latency) {
|
|
183
|
+
// Update server stats
|
|
184
|
+
const mcpServer = this.mcpServers.get(server);
|
|
185
|
+
if (mcpServer) {
|
|
186
|
+
mcpServer.callCount++;
|
|
187
|
+
mcpServer.lastChecked = new Date();
|
|
188
|
+
// Update success rate (exponential moving average)
|
|
189
|
+
const alpha = 0.1;
|
|
190
|
+
mcpServer.successRate = alpha * (success ? 1 : 0) + (1 - alpha) * mcpServer.successRate;
|
|
191
|
+
// Mark unavailable if success rate drops too low
|
|
192
|
+
if (mcpServer.successRate < 0.3 && mcpServer.callCount > 10) {
|
|
193
|
+
mcpServer.available = false;
|
|
194
|
+
this.log(`Server ${server} marked unavailable (success rate: ${(mcpServer.successRate * 100).toFixed(0)}%)`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Add to history
|
|
198
|
+
this.requestHistory.push({
|
|
199
|
+
server,
|
|
200
|
+
success,
|
|
201
|
+
latency,
|
|
202
|
+
timestamp: new Date(),
|
|
203
|
+
});
|
|
204
|
+
// Keep history bounded
|
|
205
|
+
if (this.requestHistory.length > 1000) {
|
|
206
|
+
this.requestHistory.shift();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// ============================================================================
|
|
210
|
+
// Query
|
|
211
|
+
// ============================================================================
|
|
212
|
+
async handleQuery(message) {
|
|
213
|
+
const { query } = message.payload;
|
|
214
|
+
if (query === 'servers') {
|
|
215
|
+
return {
|
|
216
|
+
...this.createResponse(message, 'RESPONSE', {
|
|
217
|
+
servers: Array.from(this.mcpServers.values()),
|
|
218
|
+
}),
|
|
219
|
+
id: '',
|
|
220
|
+
timestamp: new Date(),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
if (query === 'categories') {
|
|
224
|
+
const byCategory = {
|
|
225
|
+
knowledge: [],
|
|
226
|
+
research: [],
|
|
227
|
+
creation: [],
|
|
228
|
+
storage: [],
|
|
229
|
+
};
|
|
230
|
+
for (const server of this.mcpServers.values()) {
|
|
231
|
+
byCategory[server.category].push(server.name);
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
...this.createResponse(message, 'RESPONSE', { categories: byCategory }),
|
|
235
|
+
id: '',
|
|
236
|
+
timestamp: new Date(),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (query === 'capabilities') {
|
|
240
|
+
const capabilities = {};
|
|
241
|
+
for (const server of this.mcpServers.values()) {
|
|
242
|
+
capabilities[server.name] = server.capabilities;
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
...this.createResponse(message, 'RESPONSE', { capabilities }),
|
|
246
|
+
id: '',
|
|
247
|
+
timestamp: new Date(),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (query === 'stats') {
|
|
251
|
+
return {
|
|
252
|
+
...this.createResponse(message, 'RESPONSE', this.getStats()),
|
|
253
|
+
id: '',
|
|
254
|
+
timestamp: new Date(),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
// ============================================================================
|
|
260
|
+
// Commands
|
|
261
|
+
// ============================================================================
|
|
262
|
+
async handleCommand(message) {
|
|
263
|
+
const { command, params } = message.payload;
|
|
264
|
+
switch (command) {
|
|
265
|
+
case 'check_health':
|
|
266
|
+
await this.checkAllServers();
|
|
267
|
+
return {
|
|
268
|
+
...this.createResponse(message, 'RESPONSE', {
|
|
269
|
+
servers: Array.from(this.mcpServers.values()),
|
|
270
|
+
}),
|
|
271
|
+
id: '',
|
|
272
|
+
timestamp: new Date(),
|
|
273
|
+
};
|
|
274
|
+
case 'enable_server':
|
|
275
|
+
const serverToEnable = this.mcpServers.get(params.server);
|
|
276
|
+
if (serverToEnable) {
|
|
277
|
+
serverToEnable.available = true;
|
|
278
|
+
serverToEnable.successRate = 0.5; // Reset
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
...this.createResponse(message, 'RESPONSE', { success: true }),
|
|
282
|
+
id: '',
|
|
283
|
+
timestamp: new Date(),
|
|
284
|
+
};
|
|
285
|
+
case 'disable_server':
|
|
286
|
+
const serverToDisable = this.mcpServers.get(params.server);
|
|
287
|
+
if (serverToDisable) {
|
|
288
|
+
serverToDisable.available = false;
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
...this.createResponse(message, 'RESPONSE', { success: true }),
|
|
292
|
+
id: '',
|
|
293
|
+
timestamp: new Date(),
|
|
294
|
+
};
|
|
295
|
+
case 'execute_step':
|
|
296
|
+
// Execute sensing for a plan step
|
|
297
|
+
const result = await this.sense({
|
|
298
|
+
capability: params.step,
|
|
299
|
+
params: { context: params.planId },
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
...this.createResponse(message, 'RESPONSE', result),
|
|
303
|
+
id: '',
|
|
304
|
+
timestamp: new Date(),
|
|
305
|
+
};
|
|
306
|
+
default:
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
async checkAllServers() {
|
|
311
|
+
const mcpClient = (0, index_js_1.getMCPClient)();
|
|
312
|
+
for (const server of this.mcpServers.values()) {
|
|
313
|
+
// Check availability via MCP client
|
|
314
|
+
server.available = await mcpClient.isAvailable(server.name);
|
|
315
|
+
server.lastChecked = new Date();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// ============================================================================
|
|
319
|
+
// Stats
|
|
320
|
+
// ============================================================================
|
|
321
|
+
getStats() {
|
|
322
|
+
const servers = Array.from(this.mcpServers.values());
|
|
323
|
+
const available = servers.filter((s) => s.available);
|
|
324
|
+
const recentRequests = this.requestHistory.slice(-100);
|
|
325
|
+
const successfulRequests = recentRequests.filter((r) => r.success);
|
|
326
|
+
const avgLatency = recentRequests.length > 0
|
|
327
|
+
? recentRequests.reduce((sum, r) => sum + r.latency, 0) / recentRequests.length
|
|
328
|
+
: 0;
|
|
329
|
+
return {
|
|
330
|
+
totalServers: servers.length,
|
|
331
|
+
availableServers: available.length,
|
|
332
|
+
serversByCategory: {
|
|
333
|
+
knowledge: servers.filter((s) => s.category === 'knowledge').length,
|
|
334
|
+
research: servers.filter((s) => s.category === 'research').length,
|
|
335
|
+
creation: servers.filter((s) => s.category === 'creation').length,
|
|
336
|
+
storage: servers.filter((s) => s.category === 'storage').length,
|
|
337
|
+
},
|
|
338
|
+
totalRequests: this.requestHistory.length,
|
|
339
|
+
recentSuccessRate: recentRequests.length > 0
|
|
340
|
+
? successfulRequests.length / recentRequests.length
|
|
341
|
+
: 1,
|
|
342
|
+
avgLatency,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
// ============================================================================
|
|
346
|
+
// Public API
|
|
347
|
+
// ============================================================================
|
|
348
|
+
getAvailableServers() {
|
|
349
|
+
return Array.from(this.mcpServers.values()).filter((s) => s.available);
|
|
350
|
+
}
|
|
351
|
+
getServersByCategory(category) {
|
|
352
|
+
return Array.from(this.mcpServers.values()).filter((s) => s.category === category);
|
|
353
|
+
}
|
|
354
|
+
hasCapability(capability) {
|
|
355
|
+
return this.findServer({ capability, params: {} }) !== null;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Get the current MCP mode (real/simulated/hybrid)
|
|
359
|
+
*/
|
|
360
|
+
getMCPMode() {
|
|
361
|
+
return (0, index_js_1.getMCPClient)().getMode();
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Check if running in simulated mode
|
|
365
|
+
*/
|
|
366
|
+
isSimulated() {
|
|
367
|
+
return this.getMCPMode() === 'simulated';
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
exports.SensorAgent = SensorAgent;
|
|
371
|
+
// ============================================================================
|
|
372
|
+
// Register Factory
|
|
373
|
+
// ============================================================================
|
|
374
|
+
(0, base_agent_js_1.registerAgentFactory)('sensor', (bus) => new SensorAgent(bus));
|
|
375
|
+
function createSensorAgent(bus) {
|
|
376
|
+
return new SensorAgent(bus);
|
|
377
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 4.0 - Agent System Test
|
|
4
|
+
*
|
|
5
|
+
* Quick test to verify all agents spawn and communicate correctly.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const index_js_1 = require("./index.js");
|
|
9
|
+
async function testAgentSystem() {
|
|
10
|
+
console.log('='.repeat(60));
|
|
11
|
+
console.log('Genesis 4.0 - Agent System Test');
|
|
12
|
+
console.log('='.repeat(60));
|
|
13
|
+
// Create the full ecosystem
|
|
14
|
+
console.log('\n1. Spawning all agents...');
|
|
15
|
+
const { registry, agents } = (0, index_js_1.createAgentEcosystem)();
|
|
16
|
+
console.log(` Spawned ${agents.size} agents:`);
|
|
17
|
+
for (const [type, agent] of agents) {
|
|
18
|
+
console.log(` - ${type}: ${agent.id}`);
|
|
19
|
+
}
|
|
20
|
+
// Wake all agents
|
|
21
|
+
console.log('\n2. Waking all agents...');
|
|
22
|
+
for (const agent of agents.values()) {
|
|
23
|
+
agent.wake();
|
|
24
|
+
}
|
|
25
|
+
// Test message passing
|
|
26
|
+
console.log('\n3. Testing message passing...');
|
|
27
|
+
// Test Explorer
|
|
28
|
+
console.log(' - Testing Explorer...');
|
|
29
|
+
const explorerResponse = await index_js_1.messageBus.request('test', 'explorer', 'QUERY', { query: 'search for AI papers' }, 5000).catch(() => ({ payload: { error: 'timeout' } }));
|
|
30
|
+
console.log(` Result: ${JSON.stringify(explorerResponse.payload).slice(0, 80)}...`);
|
|
31
|
+
// Test Feeling
|
|
32
|
+
console.log(' - Testing Feeling...');
|
|
33
|
+
const feelingResponse = await index_js_1.messageBus.request('test', 'feeling', 'FEELING', { content: 'This is an exciting new discovery!', context: 'research' }, 5000).catch(() => ({ payload: { error: 'timeout' } }));
|
|
34
|
+
console.log(` Result: ${JSON.stringify(feelingResponse.payload).slice(0, 80)}...`);
|
|
35
|
+
// Test Ethicist
|
|
36
|
+
console.log(' - Testing Ethicist...');
|
|
37
|
+
const ethicsResponse = await index_js_1.messageBus.request('test', 'ethicist', 'ETHICAL_CHECK', {
|
|
38
|
+
id: 'test-action',
|
|
39
|
+
type: 'create',
|
|
40
|
+
description: 'Create a new document',
|
|
41
|
+
}, 5000).catch(() => ({ payload: { error: 'timeout' } }));
|
|
42
|
+
console.log(` Result: ${JSON.stringify(ethicsResponse.payload).slice(0, 80)}...`);
|
|
43
|
+
// Test Planner
|
|
44
|
+
console.log(' - Testing Planner...');
|
|
45
|
+
const planResponse = await index_js_1.messageBus.request('test', 'planner', 'PLAN', { goal: 'Research and build a new feature', template: 'pipeline' }, 5000).catch(() => ({ payload: { error: 'timeout' } }));
|
|
46
|
+
console.log(` Result: ${JSON.stringify(planResponse.payload).slice(0, 80)}...`);
|
|
47
|
+
// Test Critic
|
|
48
|
+
console.log(' - Testing Critic...');
|
|
49
|
+
const critiqueResponse = await index_js_1.messageBus.request('test', 'critic', 'CRITIQUE', {
|
|
50
|
+
target: 'test-code',
|
|
51
|
+
content: 'console.log("debug"); function test() { // TODO: implement }',
|
|
52
|
+
type: 'code',
|
|
53
|
+
}, 5000).catch(() => ({ payload: { error: 'timeout' } }));
|
|
54
|
+
console.log(` Result: ${JSON.stringify(critiqueResponse.payload).slice(0, 80)}...`);
|
|
55
|
+
// Test Sensor
|
|
56
|
+
console.log(' - Testing Sensor...');
|
|
57
|
+
const sensorResponse = await index_js_1.messageBus.request('test', 'sensor', 'QUERY', { query: 'stats' }, 5000).catch(() => ({ payload: { error: 'timeout' } }));
|
|
58
|
+
console.log(` Result: ${JSON.stringify(sensorResponse.payload).slice(0, 80)}...`);
|
|
59
|
+
// Get registry stats
|
|
60
|
+
console.log('\n4. Registry Stats:');
|
|
61
|
+
const stats = registry.getStats();
|
|
62
|
+
console.log(` Total agents: ${stats.totalAgents}`);
|
|
63
|
+
console.log(` By type: ${JSON.stringify(stats.byType)}`);
|
|
64
|
+
console.log(` By state: ${JSON.stringify(stats.byState)}`);
|
|
65
|
+
// Shutdown
|
|
66
|
+
console.log('\n5. Shutting down...');
|
|
67
|
+
registry.shutdownAll();
|
|
68
|
+
console.log('\n' + '='.repeat(60));
|
|
69
|
+
console.log('Test Complete!');
|
|
70
|
+
console.log('='.repeat(60));
|
|
71
|
+
}
|
|
72
|
+
// Run test
|
|
73
|
+
testAgentSystem().catch(console.error);
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis 4.0 - Agent Types
|
|
3
|
+
*
|
|
4
|
+
* Core type definitions for the multi-agent system.
|
|
5
|
+
*/
|
|
6
|
+
export type AgentType = 'explorer' | 'critic' | 'builder' | 'memory' | 'feeling' | 'narrator' | 'ethicist' | 'predictor' | 'planner' | 'sensor' | 'economic' | 'consciousness' | 'world-model' | 'causal' | 'swarm' | 'grounding' | 'anticipatory';
|
|
7
|
+
export type AgentState = 'idle' | 'working' | 'waiting' | 'sleeping' | 'error';
|
|
8
|
+
export type AgentId = string;
|
|
9
|
+
export type MessageType = 'QUERY' | 'RESPONSE' | 'BROADCAST' | 'COMMAND' | 'ALERT' | 'FEELING' | 'MEMORY_STORE' | 'MEMORY_RETRIEVE' | 'ETHICAL_CHECK' | 'PREDICTION' | 'PLAN' | 'BUILD' | 'BUILD_REQUEST' | 'BUILD_RESULT' | 'CRITIQUE' | 'EXPLORATION' | 'NARRATE' | 'EVENT' | 'PREDICT' | 'FEEDBACK' | 'SENSE' | 'ERROR' | 'HEALTH' | 'WAKE' | 'SLEEP' | 'SHUTDOWN' | 'CONSOLIDATE' | 'DREAM' | 'COST_TRACK' | 'BUDGET_CHECK' | 'WORLD_PREDICT' | 'WORLD_SIMULATE' | 'WORLD_ENCODE' | 'PHI_CHECK' | 'PHI_REPORT' | 'GWT_BROADCAST' | 'ATTENTION' | 'MUTATION' | 'SANDBOX_TEST' | 'SWARM_UPDATE' | 'EMERGENCE' | 'GROUND_CLAIM' | 'INTERVENTION' | 'COUNTERFACTUAL';
|
|
10
|
+
export type MessagePriority = 'critical' | 'high' | 'normal' | 'low';
|
|
11
|
+
export interface Message {
|
|
12
|
+
id: string;
|
|
13
|
+
type: MessageType;
|
|
14
|
+
from: AgentId;
|
|
15
|
+
to: AgentId | 'broadcast' | 'kernel';
|
|
16
|
+
payload: any;
|
|
17
|
+
timestamp: Date;
|
|
18
|
+
priority: MessagePriority;
|
|
19
|
+
replyTo?: string;
|
|
20
|
+
correlationId?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface Agent {
|
|
23
|
+
id: AgentId;
|
|
24
|
+
type: AgentType;
|
|
25
|
+
state: AgentState;
|
|
26
|
+
process(message: Message): Promise<Message | null>;
|
|
27
|
+
wake(): void;
|
|
28
|
+
sleep(): void;
|
|
29
|
+
shutdown(): void;
|
|
30
|
+
health(): HealthStatus;
|
|
31
|
+
}
|
|
32
|
+
export interface HealthStatus {
|
|
33
|
+
agentId: AgentId;
|
|
34
|
+
state: AgentState;
|
|
35
|
+
uptime: number;
|
|
36
|
+
messagesProcessed: number;
|
|
37
|
+
errors: number;
|
|
38
|
+
lastActivity: Date;
|
|
39
|
+
memoryUsage?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface AgentConfig {
|
|
42
|
+
id?: AgentId;
|
|
43
|
+
type: AgentType;
|
|
44
|
+
priority?: MessagePriority;
|
|
45
|
+
maxConcurrent?: number;
|
|
46
|
+
timeout?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface Feeling {
|
|
49
|
+
valence: number;
|
|
50
|
+
arousal: number;
|
|
51
|
+
importance: number;
|
|
52
|
+
category: FeelingCategory;
|
|
53
|
+
}
|
|
54
|
+
export type FeelingCategory = 'curiosity' | 'satisfaction' | 'frustration' | 'urgency' | 'calm' | 'concern';
|
|
55
|
+
export interface EthicalDecision {
|
|
56
|
+
action: string;
|
|
57
|
+
allow: boolean | 'defer';
|
|
58
|
+
confidence: number;
|
|
59
|
+
reason: string;
|
|
60
|
+
priority: EthicalPriority;
|
|
61
|
+
reversible: boolean;
|
|
62
|
+
potentialHarm: number;
|
|
63
|
+
flourishingScore?: number;
|
|
64
|
+
}
|
|
65
|
+
export type EthicalPriority = 'P0_SURVIVAL' | 'P1_MINIMIZE_HARM' | 'P2_REVERSIBILITY' | 'P3_AUTONOMY' | 'P4_FLOURISHING';
|
|
66
|
+
export interface MemoryItem {
|
|
67
|
+
id: string;
|
|
68
|
+
type: 'episodic' | 'semantic' | 'procedural';
|
|
69
|
+
content: any;
|
|
70
|
+
created: Date;
|
|
71
|
+
lastAccessed: Date;
|
|
72
|
+
accessCount: number;
|
|
73
|
+
R0: number;
|
|
74
|
+
S: number;
|
|
75
|
+
importance: number;
|
|
76
|
+
emotionalValence: number;
|
|
77
|
+
associations: string[];
|
|
78
|
+
consolidated: boolean;
|
|
79
|
+
}
|
|
80
|
+
export interface MemoryQuery {
|
|
81
|
+
type?: 'episodic' | 'semantic' | 'procedural';
|
|
82
|
+
keywords?: string[];
|
|
83
|
+
minImportance?: number;
|
|
84
|
+
timeRange?: {
|
|
85
|
+
start: Date;
|
|
86
|
+
end: Date;
|
|
87
|
+
};
|
|
88
|
+
limit?: number;
|
|
89
|
+
}
|
|
90
|
+
export interface Plan {
|
|
91
|
+
id: string;
|
|
92
|
+
goal: string;
|
|
93
|
+
steps: PlanStep[];
|
|
94
|
+
status: 'pending' | 'in_progress' | 'completed' | 'failed';
|
|
95
|
+
createdAt: Date;
|
|
96
|
+
estimatedDuration?: number;
|
|
97
|
+
}
|
|
98
|
+
export interface PlanStep {
|
|
99
|
+
id: string;
|
|
100
|
+
description: string;
|
|
101
|
+
agent: AgentType;
|
|
102
|
+
dependencies: string[];
|
|
103
|
+
status: 'pending' | 'in_progress' | 'completed' | 'failed' | 'skipped';
|
|
104
|
+
result?: any;
|
|
105
|
+
}
|
|
106
|
+
export interface Prediction {
|
|
107
|
+
action: string;
|
|
108
|
+
outcomes: PredictedOutcome[];
|
|
109
|
+
confidence: number;
|
|
110
|
+
timeHorizon: 'immediate' | 'short' | 'medium' | 'long';
|
|
111
|
+
}
|
|
112
|
+
export interface PredictedOutcome {
|
|
113
|
+
description: string;
|
|
114
|
+
probability: number;
|
|
115
|
+
impact: number;
|
|
116
|
+
reversible: boolean;
|
|
117
|
+
}
|
|
118
|
+
export interface ExplorationResult {
|
|
119
|
+
query: string;
|
|
120
|
+
sources: ExplorationSource[];
|
|
121
|
+
findings: Finding[];
|
|
122
|
+
novelty: number;
|
|
123
|
+
relevance: number;
|
|
124
|
+
}
|
|
125
|
+
export interface ExplorationSource {
|
|
126
|
+
type: 'arxiv' | 'semantic-scholar' | 'brave' | 'gemini' | 'exa' | 'firecrawl' | 'context7' | 'wolfram';
|
|
127
|
+
url?: string;
|
|
128
|
+
title?: string;
|
|
129
|
+
}
|
|
130
|
+
export interface Finding {
|
|
131
|
+
content: string;
|
|
132
|
+
source: ExplorationSource;
|
|
133
|
+
importance: number;
|
|
134
|
+
isNovel: boolean;
|
|
135
|
+
}
|
|
136
|
+
export interface Critique {
|
|
137
|
+
target: string;
|
|
138
|
+
problems: Problem[];
|
|
139
|
+
suggestions: Suggestion[];
|
|
140
|
+
overallScore: number;
|
|
141
|
+
passesReview: boolean;
|
|
142
|
+
}
|
|
143
|
+
export interface Problem {
|
|
144
|
+
id: string;
|
|
145
|
+
severity: 'critical' | 'major' | 'minor' | 'nitpick';
|
|
146
|
+
description: string;
|
|
147
|
+
location?: string;
|
|
148
|
+
}
|
|
149
|
+
export interface Suggestion {
|
|
150
|
+
problemId: string;
|
|
151
|
+
description: string;
|
|
152
|
+
effort: 'low' | 'medium' | 'high';
|
|
153
|
+
impact: 'low' | 'medium' | 'high';
|
|
154
|
+
}
|
|
155
|
+
export interface BuildRequest {
|
|
156
|
+
type: 'code' | 'document' | 'config' | 'test';
|
|
157
|
+
spec: string;
|
|
158
|
+
language?: string;
|
|
159
|
+
framework?: string;
|
|
160
|
+
constraints?: string[];
|
|
161
|
+
}
|
|
162
|
+
export interface BuildResult {
|
|
163
|
+
success: boolean;
|
|
164
|
+
artifacts: Artifact[];
|
|
165
|
+
errors?: string[];
|
|
166
|
+
warnings?: string[];
|
|
167
|
+
}
|
|
168
|
+
export interface Artifact {
|
|
169
|
+
type: 'file' | 'snippet' | 'diagram';
|
|
170
|
+
name: string;
|
|
171
|
+
content: string;
|
|
172
|
+
path?: string;
|
|
173
|
+
}
|
|
174
|
+
export interface BuildArtifact {
|
|
175
|
+
type: 'file' | 'snippet' | 'diagram';
|
|
176
|
+
name: string;
|
|
177
|
+
language?: string;
|
|
178
|
+
content: string;
|
|
179
|
+
path?: string;
|
|
180
|
+
metadata?: Record<string, any>;
|
|
181
|
+
}
|
|
182
|
+
export interface Narrative {
|
|
183
|
+
title: string;
|
|
184
|
+
summary: string;
|
|
185
|
+
events: NarrativeEvent[];
|
|
186
|
+
themes: string[];
|
|
187
|
+
mood: FeelingCategory;
|
|
188
|
+
}
|
|
189
|
+
export interface NarrativeEvent {
|
|
190
|
+
timestamp: Date;
|
|
191
|
+
description: string;
|
|
192
|
+
significance: number;
|
|
193
|
+
agents: AgentId[];
|
|
194
|
+
}
|