genesis-ai-cli 7.4.5 → 7.4.7
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/README.md +14 -9
- package/dist/src/active-inference/integration.d.ts +25 -3
- package/dist/src/active-inference/integration.js +68 -37
- package/dist/src/cli/chat.d.ts +1 -0
- package/dist/src/cli/chat.js +34 -5
- package/dist/src/index.js +8 -3
- package/dist/src/kernel/index.js +3 -2
- package/dist/src/persistence/index.d.ts +5 -0
- package/dist/src/persistence/index.js +11 -0
- package/dist/src/subagents/executor.js +65 -11
- package/dist/src/subagents/types.d.ts +1 -0
- package/dist/src/subagents/types.js +1 -0
- package/dist/src/world-model/encoder.d.ts +9 -1
- package/dist/src/world-model/encoder.js +74 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Genesis
|
|
1
|
+
# Genesis 7.4.5
|
|
2
2
|
|
|
3
3
|
**Claude Code Equivalent - Autonomous AI System Creator**
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@ Genesis is a self-improving AI system powered by 13 MCP servers. It doesn't just
|
|
|
14
14
|
║ ╚██████╔╝███████╗██║ ╚████║███████╗███████║██║███████║ ║
|
|
15
15
|
║ ╚═════╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚══════╝╚═╝╚══════╝ ║
|
|
16
16
|
║ ║
|
|
17
|
-
║ "Not just intelligent, but alive."
|
|
17
|
+
║ "Not just intelligent, but alive." v7.4.5 ║
|
|
18
18
|
║ ║
|
|
19
19
|
╚═══════════════════════════════════════════════════════════════════════╝
|
|
20
20
|
```
|
|
@@ -22,20 +22,21 @@ Genesis is a self-improving AI system powered by 13 MCP servers. It doesn't just
|
|
|
22
22
|
## Quick Start
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
#
|
|
25
|
+
# Install from npm (recommended)
|
|
26
|
+
npm install -g genesis-ai-cli
|
|
27
|
+
|
|
28
|
+
# Or clone and build from source
|
|
26
29
|
git clone https://github.com/rossignoliluca/genesis.git
|
|
27
30
|
cd genesis
|
|
28
31
|
npm install
|
|
29
32
|
npm run build
|
|
33
|
+
npm link
|
|
30
34
|
|
|
31
35
|
# Configure API keys
|
|
32
36
|
cp .env.example .env
|
|
33
37
|
# Edit .env with your API keys (see below)
|
|
34
38
|
chmod 600 .env
|
|
35
39
|
|
|
36
|
-
# Install globally (optional)
|
|
37
|
-
npm link
|
|
38
|
-
|
|
39
40
|
# Start!
|
|
40
41
|
genesis help
|
|
41
42
|
genesis chat
|
|
@@ -162,7 +163,7 @@ genesis infer mcp --cycles 20 --verbose
|
|
|
162
163
|
|
|
163
164
|
```
|
|
164
165
|
┌─────────────────────────────────────────────────────────────────────┐
|
|
165
|
-
│ GENESIS
|
|
166
|
+
│ GENESIS 7.4 │
|
|
166
167
|
├─────────────────────────────────────────────────────────────────────┤
|
|
167
168
|
│ │
|
|
168
169
|
│ ┌─────────────────────────────────────────────────────────────┐ │
|
|
@@ -232,7 +233,9 @@ GENESIS_MCP_LOG=false # Enable debug logging
|
|
|
232
233
|
|
|
233
234
|
| Version | Codename | Key Features |
|
|
234
235
|
|---------|----------|--------------|
|
|
235
|
-
| **
|
|
236
|
+
| **v7.4.5** | **Claude Code Parity** | Subagents, Background Tasks, Headless Mode, Session Management, Extended Thinking, Hooks System |
|
|
237
|
+
| v6.8.0 | Local-First | Ollama integration, offline mode, hybrid routing |
|
|
238
|
+
| v6.7.0 | Standalone Complete | Human-in-Loop, Tool Orchestration, Claude Code equivalent |
|
|
236
239
|
| v6.6.0 | Tool Orchestration | Dispatcher, Interactive REPL |
|
|
237
240
|
| v6.5.0 | Grounding | Output verification, feedback loop |
|
|
238
241
|
| v6.4.x | Self-Healing | Bash sandbox, Edit tool, Git operations, Darwin-Gödel |
|
|
@@ -279,4 +282,6 @@ Created by **rossignoliluca**
|
|
|
279
282
|
|
|
280
283
|
---
|
|
281
284
|
|
|
282
|
-
*Genesis
|
|
285
|
+
*Genesis 7.4.5 - Claude Code Parity*
|
|
286
|
+
|
|
287
|
+
[](https://www.npmjs.com/package/genesis-ai-cli)
|
|
@@ -31,6 +31,8 @@ import { AutonomousLoop } from './autonomous-loop.js';
|
|
|
31
31
|
import { ObservationGatherer, KernelState, PhiState, SensorResult, WorldModelState } from './observations.js';
|
|
32
32
|
import type { Kernel } from '../kernel/index.js';
|
|
33
33
|
import type { Daemon } from '../daemon/index.js';
|
|
34
|
+
import { PhiMonitor } from '../consciousness/phi-monitor.js';
|
|
35
|
+
import { CognitiveWorkspace } from '../memory/cognitive-workspace.js';
|
|
34
36
|
export interface IntegrationConfig {
|
|
35
37
|
cycleInterval: number;
|
|
36
38
|
maxCycles: number;
|
|
@@ -42,14 +44,27 @@ export interface IntegrationConfig {
|
|
|
42
44
|
verbose: boolean;
|
|
43
45
|
}
|
|
44
46
|
export declare const DEFAULT_INTEGRATION_CONFIG: IntegrationConfig;
|
|
47
|
+
/**
|
|
48
|
+
* Options for the observation bridge
|
|
49
|
+
*/
|
|
50
|
+
export interface ObservationBridgeOptions {
|
|
51
|
+
phiMonitor?: PhiMonitor;
|
|
52
|
+
workspace?: CognitiveWorkspace;
|
|
53
|
+
}
|
|
45
54
|
/**
|
|
46
55
|
* Creates an observation gatherer connected to Kernel state
|
|
47
56
|
*/
|
|
48
|
-
export declare function createKernelObservationBridge(kernel: Kernel): ObservationGatherer;
|
|
57
|
+
export declare function createKernelObservationBridge(kernel: Kernel, options?: ObservationBridgeOptions): ObservationGatherer;
|
|
58
|
+
/**
|
|
59
|
+
* Options for registering kernel actions
|
|
60
|
+
*/
|
|
61
|
+
export interface RegisterActionsOptions {
|
|
62
|
+
workspace?: CognitiveWorkspace;
|
|
63
|
+
}
|
|
49
64
|
/**
|
|
50
65
|
* Registers action executors that connect to Kernel operations
|
|
51
66
|
*/
|
|
52
|
-
export declare function registerKernelActions(kernel: Kernel): void;
|
|
67
|
+
export declare function registerKernelActions(kernel: Kernel, options?: RegisterActionsOptions): void;
|
|
53
68
|
/**
|
|
54
69
|
* Registers Active Inference as a daemon scheduled task
|
|
55
70
|
*/
|
|
@@ -62,7 +77,14 @@ export declare function registerDaemonTask(daemon: Daemon, loop: AutonomousLoop,
|
|
|
62
77
|
* @param config - Integration configuration
|
|
63
78
|
* @returns Configured AutonomousLoop
|
|
64
79
|
*/
|
|
65
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Options for Active Inference integration
|
|
82
|
+
*/
|
|
83
|
+
export interface IntegrationOptions {
|
|
84
|
+
phiMonitor?: PhiMonitor;
|
|
85
|
+
workspace?: CognitiveWorkspace;
|
|
86
|
+
}
|
|
87
|
+
export declare function integrateActiveInference(kernel: Kernel, daemon?: Daemon, config?: Partial<IntegrationConfig>, options?: IntegrationOptions): AutonomousLoop;
|
|
66
88
|
export interface IntegratedSystem {
|
|
67
89
|
kernel: Kernel;
|
|
68
90
|
daemon: Daemon;
|
|
@@ -40,6 +40,8 @@ exports.createMCPInferenceLoop = createMCPInferenceLoop;
|
|
|
40
40
|
const autonomous_loop_js_1 = require("./autonomous-loop.js");
|
|
41
41
|
const observations_js_1 = require("./observations.js");
|
|
42
42
|
const actions_js_1 = require("./actions.js");
|
|
43
|
+
const phi_monitor_js_1 = require("../consciousness/phi-monitor.js");
|
|
44
|
+
const cognitive_workspace_js_1 = require("../memory/cognitive-workspace.js");
|
|
43
45
|
exports.DEFAULT_INTEGRATION_CONFIG = {
|
|
44
46
|
cycleInterval: 1000,
|
|
45
47
|
maxCycles: 0,
|
|
@@ -76,14 +78,13 @@ function mapKernelStateToTaskStatus(state) {
|
|
|
76
78
|
return 'none';
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
// ============================================================================
|
|
80
|
-
// Observation Bridge
|
|
81
|
-
// ============================================================================
|
|
82
81
|
/**
|
|
83
82
|
* Creates an observation gatherer connected to Kernel state
|
|
84
83
|
*/
|
|
85
|
-
function createKernelObservationBridge(kernel) {
|
|
84
|
+
function createKernelObservationBridge(kernel, options = {}) {
|
|
86
85
|
const gatherer = (0, observations_js_1.createObservationGatherer)();
|
|
86
|
+
// Get or create phi-monitor
|
|
87
|
+
const phiMonitor = options.phiMonitor || (0, phi_monitor_js_1.createPhiMonitor)();
|
|
87
88
|
gatherer.configure({
|
|
88
89
|
// Map Kernel energy and state to observations
|
|
89
90
|
kernelState: () => ({
|
|
@@ -91,13 +92,13 @@ function createKernelObservationBridge(kernel) {
|
|
|
91
92
|
state: kernel.getState(),
|
|
92
93
|
taskStatus: mapKernelStateToTaskStatus(kernel.getState()),
|
|
93
94
|
}),
|
|
94
|
-
//
|
|
95
|
+
// Connected to real phi-monitor
|
|
95
96
|
phiState: () => {
|
|
96
|
-
|
|
97
|
-
const
|
|
97
|
+
const level = phiMonitor.getCurrentLevel();
|
|
98
|
+
const consciousnessState = phiMonitor.getState();
|
|
98
99
|
return {
|
|
99
|
-
phi:
|
|
100
|
-
state:
|
|
100
|
+
phi: level.phi,
|
|
101
|
+
state: consciousnessState === 'dormant' ? 'dormant' : 'aware',
|
|
101
102
|
};
|
|
102
103
|
},
|
|
103
104
|
// Sensor result from agent health
|
|
@@ -121,13 +122,12 @@ function createKernelObservationBridge(kernel) {
|
|
|
121
122
|
});
|
|
122
123
|
return gatherer;
|
|
123
124
|
}
|
|
124
|
-
// ============================================================================
|
|
125
|
-
// Action Executors
|
|
126
|
-
// ============================================================================
|
|
127
125
|
/**
|
|
128
126
|
* Registers action executors that connect to Kernel operations
|
|
129
127
|
*/
|
|
130
|
-
function registerKernelActions(kernel) {
|
|
128
|
+
function registerKernelActions(kernel, options = {}) {
|
|
129
|
+
// Get or create workspace for memory actions
|
|
130
|
+
const workspace = options.workspace || (0, cognitive_workspace_js_1.getCognitiveWorkspace)();
|
|
131
131
|
// sense.mcp: Use Kernel's sensor agent
|
|
132
132
|
(0, actions_js_1.registerAction)('sense.mcp', async (context) => {
|
|
133
133
|
try {
|
|
@@ -154,15 +154,52 @@ function registerKernelActions(kernel) {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
|
-
// recall.memory: Query memory via
|
|
157
|
+
// recall.memory: Query memory via CognitiveWorkspace
|
|
158
158
|
(0, actions_js_1.registerAction)('recall.memory', async (context) => {
|
|
159
159
|
try {
|
|
160
|
-
|
|
160
|
+
const startTime = Date.now();
|
|
161
|
+
// Anticipate memories based on current goal/context
|
|
162
|
+
if (context.goal) {
|
|
163
|
+
await workspace.anticipate({
|
|
164
|
+
goal: context.goal,
|
|
165
|
+
keywords: context.parameters?.keywords,
|
|
166
|
+
tags: context.parameters?.tags,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
// Get all active memories from working memory
|
|
170
|
+
const activeItems = workspace.getActive();
|
|
171
|
+
const recalled = activeItems.map(item => {
|
|
172
|
+
// Extract summary based on memory type
|
|
173
|
+
let summary;
|
|
174
|
+
const mem = item.memory;
|
|
175
|
+
if (mem.type === 'episodic') {
|
|
176
|
+
summary = mem.content.what;
|
|
177
|
+
}
|
|
178
|
+
else if (mem.type === 'semantic') {
|
|
179
|
+
summary = mem.content.concept;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// procedural
|
|
183
|
+
summary = `${mem.content.name}: ${mem.content.description}`;
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
id: item.memory.id,
|
|
187
|
+
type: item.memory.type,
|
|
188
|
+
summary,
|
|
189
|
+
relevance: item.relevance,
|
|
190
|
+
activation: item.activation,
|
|
191
|
+
};
|
|
192
|
+
});
|
|
161
193
|
return {
|
|
162
194
|
success: true,
|
|
163
195
|
action: 'recall.memory',
|
|
164
|
-
data: {
|
|
165
|
-
|
|
196
|
+
data: {
|
|
197
|
+
recalled,
|
|
198
|
+
query: context.goal,
|
|
199
|
+
count: recalled.length,
|
|
200
|
+
metrics: workspace.getMetrics(),
|
|
201
|
+
},
|
|
202
|
+
duration: Date.now() - startTime,
|
|
166
203
|
};
|
|
167
204
|
}
|
|
168
205
|
catch (error) {
|
|
@@ -350,19 +387,11 @@ function registerDaemonTask(daemon, loop, config) {
|
|
|
350
387
|
retries: 0, // Don't retry - just run next cycle
|
|
351
388
|
});
|
|
352
389
|
}
|
|
353
|
-
|
|
354
|
-
// Integration Function
|
|
355
|
-
// ============================================================================
|
|
356
|
-
/**
|
|
357
|
-
* Integrates Active Inference with Kernel and Daemon
|
|
358
|
-
*
|
|
359
|
-
* @param kernel - The Genesis Kernel instance
|
|
360
|
-
* @param daemon - The Genesis Daemon instance (optional)
|
|
361
|
-
* @param config - Integration configuration
|
|
362
|
-
* @returns Configured AutonomousLoop
|
|
363
|
-
*/
|
|
364
|
-
function integrateActiveInference(kernel, daemon, config = {}) {
|
|
390
|
+
function integrateActiveInference(kernel, daemon, config = {}, options = {}) {
|
|
365
391
|
const fullConfig = { ...exports.DEFAULT_INTEGRATION_CONFIG, ...config };
|
|
392
|
+
// Get or create phi-monitor and workspace
|
|
393
|
+
const phiMonitor = options.phiMonitor || (0, phi_monitor_js_1.createPhiMonitor)();
|
|
394
|
+
const workspace = options.workspace || (0, cognitive_workspace_js_1.getCognitiveWorkspace)();
|
|
366
395
|
// Create the loop
|
|
367
396
|
const loop = (0, autonomous_loop_js_1.createAutonomousLoop)({
|
|
368
397
|
cycleInterval: fullConfig.cycleInterval,
|
|
@@ -370,21 +399,23 @@ function integrateActiveInference(kernel, daemon, config = {}) {
|
|
|
370
399
|
stopOnEnergyCritical: fullConfig.stopOnDormant,
|
|
371
400
|
verbose: fullConfig.verbose,
|
|
372
401
|
});
|
|
373
|
-
// Connect observations to Kernel
|
|
374
|
-
const observationBridge = createKernelObservationBridge(kernel);
|
|
402
|
+
// Connect observations to Kernel with real phi-monitor
|
|
403
|
+
const observationBridge = createKernelObservationBridge(kernel, { phiMonitor, workspace });
|
|
375
404
|
const components = loop.getComponents();
|
|
376
|
-
// Replace the observations gatherer configuration
|
|
405
|
+
// Replace the observations gatherer configuration with real phi-monitor
|
|
377
406
|
components.observations.configure({
|
|
378
407
|
kernelState: () => ({
|
|
379
408
|
energy: kernel.getEnergy(),
|
|
380
409
|
state: kernel.getState(),
|
|
381
410
|
taskStatus: mapKernelStateToTaskStatus(kernel.getState()),
|
|
382
411
|
}),
|
|
412
|
+
// Connected to real phi-monitor
|
|
383
413
|
phiState: () => {
|
|
384
|
-
const
|
|
414
|
+
const level = phiMonitor.getCurrentLevel();
|
|
415
|
+
const consciousnessState = phiMonitor.getState();
|
|
385
416
|
return {
|
|
386
|
-
phi:
|
|
387
|
-
state:
|
|
417
|
+
phi: level.phi,
|
|
418
|
+
state: consciousnessState === 'dormant' ? 'dormant' : 'aware',
|
|
388
419
|
};
|
|
389
420
|
},
|
|
390
421
|
sensorResult: async () => {
|
|
@@ -403,8 +434,8 @@ function integrateActiveInference(kernel, daemon, config = {}) {
|
|
|
403
434
|
};
|
|
404
435
|
},
|
|
405
436
|
});
|
|
406
|
-
// Register Kernel action executors
|
|
407
|
-
registerKernelActions(kernel);
|
|
437
|
+
// Register Kernel action executors with workspace
|
|
438
|
+
registerKernelActions(kernel, { workspace });
|
|
408
439
|
// Connect to Kernel state changes
|
|
409
440
|
kernel.onStateChange((newState, prevState) => {
|
|
410
441
|
if (fullConfig.verbose) {
|
package/dist/src/cli/chat.d.ts
CHANGED
package/dist/src/cli/chat.js
CHANGED
|
@@ -94,6 +94,7 @@ class ChatSession {
|
|
|
94
94
|
messageCount = 0;
|
|
95
95
|
toolExecutions = 0;
|
|
96
96
|
systemPrompt = ''; // Built dynamically at start()
|
|
97
|
+
customSystemPrompt = ''; // User-defined system prompt prefix
|
|
97
98
|
// v7.0: Modern UI components
|
|
98
99
|
spinner;
|
|
99
100
|
thinkingSpinner; // v7.3.8: Shows time, module, action
|
|
@@ -388,7 +389,11 @@ class ChatSession {
|
|
|
388
389
|
// v7.0: Modern spinner instead of static text
|
|
389
390
|
this.spinner.start('Thinking');
|
|
390
391
|
try {
|
|
391
|
-
|
|
392
|
+
// Combine custom and base system prompts
|
|
393
|
+
const effectiveSystemPrompt = this.customSystemPrompt
|
|
394
|
+
? `${this.customSystemPrompt}\n\n${this.systemPrompt}`
|
|
395
|
+
: this.systemPrompt;
|
|
396
|
+
const response = await this.llm.chat(message, effectiveSystemPrompt);
|
|
392
397
|
this.messageCount++;
|
|
393
398
|
// v7.0: Stop spinner and print formatted response
|
|
394
399
|
this.spinner.stop();
|
|
@@ -617,10 +622,31 @@ class ChatSession {
|
|
|
617
622
|
break;
|
|
618
623
|
case 'system':
|
|
619
624
|
if (args.length > 0) {
|
|
620
|
-
|
|
625
|
+
const subCmd = args[0].toLowerCase();
|
|
626
|
+
if (subCmd === 'clear' || subCmd === 'reset') {
|
|
627
|
+
this.customSystemPrompt = '';
|
|
628
|
+
console.log((0, ui_js_1.c)('Custom system prompt cleared.', 'green'));
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
// Set custom system prompt (everything after /system)
|
|
632
|
+
this.customSystemPrompt = args.join(' ');
|
|
633
|
+
console.log((0, ui_js_1.c)('Custom system prompt set:', 'green'));
|
|
634
|
+
console.log((0, ui_js_1.c)('─'.repeat(60), 'dim'));
|
|
635
|
+
console.log(this.customSystemPrompt);
|
|
636
|
+
console.log((0, ui_js_1.c)('─'.repeat(60), 'dim'));
|
|
637
|
+
console.log((0, ui_js_1.c)('Use /system clear to reset.', 'dim'));
|
|
638
|
+
}
|
|
621
639
|
}
|
|
622
640
|
else {
|
|
623
|
-
|
|
641
|
+
// Show current system prompt
|
|
642
|
+
if (this.customSystemPrompt) {
|
|
643
|
+
console.log((0, ui_js_1.c)('Custom System Prompt:', 'green'));
|
|
644
|
+
console.log((0, ui_js_1.c)('─'.repeat(60), 'dim'));
|
|
645
|
+
console.log(this.customSystemPrompt);
|
|
646
|
+
console.log((0, ui_js_1.c)('─'.repeat(60), 'dim'));
|
|
647
|
+
console.log();
|
|
648
|
+
}
|
|
649
|
+
console.log((0, ui_js_1.c)('Base System Prompt (dynamically built):', 'cyan'));
|
|
624
650
|
console.log((0, ui_js_1.c)('─'.repeat(60), 'dim'));
|
|
625
651
|
console.log(this.systemPrompt || index_js_1.GENESIS_IDENTITY_PROMPT);
|
|
626
652
|
console.log((0, ui_js_1.c)('─'.repeat(60), 'dim'));
|
|
@@ -1811,8 +1837,11 @@ class ChatSession {
|
|
|
1811
1837
|
response = await this.brain.process(prompt);
|
|
1812
1838
|
}
|
|
1813
1839
|
else {
|
|
1814
|
-
// Direct LLM call
|
|
1815
|
-
const
|
|
1840
|
+
// Direct LLM call with combined system prompt
|
|
1841
|
+
const effectiveSystemPrompt = this.customSystemPrompt
|
|
1842
|
+
? `${this.customSystemPrompt}\n\n${this.systemPrompt}`
|
|
1843
|
+
: this.systemPrompt;
|
|
1844
|
+
const result = await this.llm.chat(prompt, effectiveSystemPrompt);
|
|
1816
1845
|
response = result.content;
|
|
1817
1846
|
}
|
|
1818
1847
|
// Output based on format
|
package/dist/src/index.js
CHANGED
|
@@ -334,14 +334,19 @@ async function cmdChat(options, promptArg) {
|
|
|
334
334
|
const model = options.model || (provider === 'ollama' ? 'qwen2.5-coder' : undefined);
|
|
335
335
|
const verbose = options.verbose === 'true';
|
|
336
336
|
// v7.4: Headless mode with -p/--print flag
|
|
337
|
-
|
|
337
|
+
// -p "text" → options.p = "text" (prompt from flag)
|
|
338
|
+
// -p (no arg) → options.p = 'true' (prompt from stdin/positional)
|
|
339
|
+
const headlessFlag = options.print || options.p;
|
|
340
|
+
const isHeadless = !!headlessFlag;
|
|
338
341
|
const outputFormat = (options.format || options.output || 'text');
|
|
339
342
|
// v7.4: Session resume
|
|
340
343
|
const resume = options.resume || options.r;
|
|
341
344
|
const sessionName = options.name;
|
|
342
345
|
if (isHeadless) {
|
|
343
|
-
// Get prompt from argument or stdin
|
|
344
|
-
let prompt =
|
|
346
|
+
// Get prompt from -p argument (if string), positional arg, or stdin
|
|
347
|
+
let prompt = (typeof headlessFlag === 'string' && headlessFlag !== 'true')
|
|
348
|
+
? headlessFlag
|
|
349
|
+
: (promptArg || '');
|
|
345
350
|
// If no prompt argument, try reading from stdin
|
|
346
351
|
if (!prompt) {
|
|
347
352
|
prompt = await (0, chat_js_1.readStdin)();
|
package/dist/src/kernel/index.js
CHANGED
|
@@ -38,6 +38,7 @@ const STATE_TRANSITIONS = {
|
|
|
38
38
|
};
|
|
39
39
|
// Invariant Registry (extensible system for Phase 5.1+)
|
|
40
40
|
const invariants_js_1 = require("./invariants.js");
|
|
41
|
+
const index_js_2 = require("../persistence/index.js");
|
|
41
42
|
// ============================================================================
|
|
42
43
|
// Kernel Class
|
|
43
44
|
// ============================================================================
|
|
@@ -589,8 +590,8 @@ class Kernel {
|
|
|
589
590
|
responsiveAgentCount: responsiveCount,
|
|
590
591
|
totalAgentCount: this.agents.size,
|
|
591
592
|
// Extended context (for Phase 5.1+ invariants)
|
|
592
|
-
//
|
|
593
|
-
merkleValid:
|
|
593
|
+
// Verify state checksum via StateStore (Merkle chain validation)
|
|
594
|
+
merkleValid: (0, index_js_2.getStateStore)().verifyChecksum(),
|
|
594
595
|
// phi: undefined, // Phase 5.3
|
|
595
596
|
// phiMin: undefined, // Phase 5.3
|
|
596
597
|
// budget: undefined, // Phase 5.1
|
|
@@ -185,6 +185,11 @@ export declare class StateStore {
|
|
|
185
185
|
private ensureDirectories;
|
|
186
186
|
private cleanOldBackups;
|
|
187
187
|
private cleanOldBackupsSync;
|
|
188
|
+
/**
|
|
189
|
+
* Verify the current state checksum matches the stored checksum
|
|
190
|
+
* Returns true if checksum is valid, false if corrupted
|
|
191
|
+
*/
|
|
192
|
+
verifyChecksum(): boolean;
|
|
188
193
|
/**
|
|
189
194
|
* Get data directory path
|
|
190
195
|
*/
|
|
@@ -541,6 +541,17 @@ class StateStore {
|
|
|
541
541
|
}
|
|
542
542
|
}
|
|
543
543
|
}
|
|
544
|
+
/**
|
|
545
|
+
* Verify the current state checksum matches the stored checksum
|
|
546
|
+
* Returns true if checksum is valid, false if corrupted
|
|
547
|
+
*/
|
|
548
|
+
verifyChecksum() {
|
|
549
|
+
if (!this.state.checksum) {
|
|
550
|
+
return true; // No checksum stored, assume valid
|
|
551
|
+
}
|
|
552
|
+
const calculated = this.calculateChecksum(this.state);
|
|
553
|
+
return this.state.checksum === calculated;
|
|
554
|
+
}
|
|
544
555
|
/**
|
|
545
556
|
* Get data directory path
|
|
546
557
|
*/
|
|
@@ -237,17 +237,71 @@ After completing your task, provide a clear summary of:
|
|
|
237
237
|
2. Key results with file:line references where applicable
|
|
238
238
|
3. Any issues or warnings`;
|
|
239
239
|
}
|
|
240
|
-
async runSubagent(llm, systemPrompt, userPrompt,
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
240
|
+
async runSubagent(llm, systemPrompt, userPrompt, allowedTools, taskId) {
|
|
241
|
+
// Multi-turn tool execution loop
|
|
242
|
+
const maxTurns = this.config.maxTurns || 10;
|
|
243
|
+
let turn = 0;
|
|
244
|
+
let conversationHistory = [];
|
|
245
|
+
let lastResponse = '';
|
|
246
|
+
// Initial user message
|
|
247
|
+
conversationHistory.push({ role: 'user', content: userPrompt });
|
|
248
|
+
while (turn < maxTurns) {
|
|
249
|
+
turn++;
|
|
250
|
+
// Build prompt with conversation history
|
|
251
|
+
const historyPrompt = conversationHistory
|
|
252
|
+
.map(m => `${m.role === 'user' ? 'User' : 'Assistant'}: ${m.content}`)
|
|
253
|
+
.join('\n\n');
|
|
254
|
+
const response = await llm.chat(historyPrompt, systemPrompt);
|
|
255
|
+
lastResponse = response.content;
|
|
256
|
+
this.emit({
|
|
257
|
+
type: 'task_progress',
|
|
258
|
+
taskId,
|
|
259
|
+
timestamp: new Date(),
|
|
260
|
+
data: { turn, tokensUsed: response.usage },
|
|
261
|
+
});
|
|
262
|
+
// Add assistant response to history
|
|
263
|
+
conversationHistory.push({ role: 'assistant', content: lastResponse });
|
|
264
|
+
// Check for tool calls
|
|
265
|
+
if (!this.dispatcher) {
|
|
266
|
+
// No dispatcher, single-turn only
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
const toolCalls = this.dispatcher.parseToolCalls(lastResponse);
|
|
270
|
+
// Filter to allowed tools only
|
|
271
|
+
const allowedCalls = allowedTools.includes('*')
|
|
272
|
+
? toolCalls
|
|
273
|
+
: toolCalls.filter(call => allowedTools.includes(call.name));
|
|
274
|
+
if (allowedCalls.length === 0) {
|
|
275
|
+
// No tool calls, we're done
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
// Execute tools
|
|
279
|
+
const dispatchResult = await this.dispatcher.dispatch(allowedCalls);
|
|
280
|
+
// Format results for continuation
|
|
281
|
+
const resultsText = dispatchResult.results
|
|
282
|
+
.map(r => {
|
|
283
|
+
if (r.success) {
|
|
284
|
+
const data = typeof r.data === 'string' ? r.data : JSON.stringify(r.data, null, 2);
|
|
285
|
+
return `Tool ${r.name} succeeded:\n${data}`;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
return `Tool ${r.name} failed: ${r.error}`;
|
|
289
|
+
}
|
|
290
|
+
})
|
|
291
|
+
.join('\n\n');
|
|
292
|
+
// Add tool results as user message for next turn
|
|
293
|
+
conversationHistory.push({
|
|
294
|
+
role: 'user',
|
|
295
|
+
content: `Tool execution results:\n\n${resultsText}\n\nContinue with your task based on these results.`,
|
|
296
|
+
});
|
|
297
|
+
this.emit({
|
|
298
|
+
type: 'task_progress',
|
|
299
|
+
taskId,
|
|
300
|
+
timestamp: new Date(),
|
|
301
|
+
data: { turn, toolsExecuted: allowedCalls.length, results: dispatchResult.results.length },
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
return lastResponse;
|
|
251
305
|
}
|
|
252
306
|
timeoutPromise(ms, taskId) {
|
|
253
307
|
return new Promise((_, reject) => {
|
|
@@ -68,7 +68,15 @@ export declare class LatentEncoder {
|
|
|
68
68
|
private encodeText;
|
|
69
69
|
/**
|
|
70
70
|
* Encode image to latent vector
|
|
71
|
-
*
|
|
71
|
+
*
|
|
72
|
+
* Uses multi-level feature extraction:
|
|
73
|
+
* 1. Perceptual hash for content fingerprint
|
|
74
|
+
* 2. Color histogram analysis
|
|
75
|
+
* 3. Spatial frequency features
|
|
76
|
+
* 4. Metadata-based features (size, aspect ratio)
|
|
77
|
+
*
|
|
78
|
+
* For MCP integration: Can be enhanced with vision model embeddings
|
|
79
|
+
* by calling openai vision or similar through MCP client.
|
|
72
80
|
*/
|
|
73
81
|
private encodeImage;
|
|
74
82
|
/**
|
|
@@ -61,7 +61,7 @@ class LatentEncoder {
|
|
|
61
61
|
dimensionality: this.config.latentDim,
|
|
62
62
|
encode: (input) => this.encodeText(input),
|
|
63
63
|
});
|
|
64
|
-
// Image encoder -
|
|
64
|
+
// Image encoder - multi-level feature extraction
|
|
65
65
|
this.modalityEncoders.set('image', {
|
|
66
66
|
modality: 'image',
|
|
67
67
|
dimensionality: this.config.latentDim,
|
|
@@ -210,20 +210,84 @@ class LatentEncoder {
|
|
|
210
210
|
}
|
|
211
211
|
/**
|
|
212
212
|
* Encode image to latent vector
|
|
213
|
-
*
|
|
213
|
+
*
|
|
214
|
+
* Uses multi-level feature extraction:
|
|
215
|
+
* 1. Perceptual hash for content fingerprint
|
|
216
|
+
* 2. Color histogram analysis
|
|
217
|
+
* 3. Spatial frequency features
|
|
218
|
+
* 4. Metadata-based features (size, aspect ratio)
|
|
219
|
+
*
|
|
220
|
+
* For MCP integration: Can be enhanced with vision model embeddings
|
|
221
|
+
* by calling openai vision or similar through MCP client.
|
|
214
222
|
*/
|
|
215
223
|
encodeImage(input) {
|
|
216
224
|
const vector = new Array(this.config.latentDim).fill(0);
|
|
217
|
-
// Simple encoding based on image metadata
|
|
218
|
-
// In production, would use actual image encoder
|
|
219
225
|
const data = input.data;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
226
|
+
// Decode base64 to get raw bytes for analysis
|
|
227
|
+
let imageBytes;
|
|
228
|
+
try {
|
|
229
|
+
// Handle base64 data URLs or raw base64
|
|
230
|
+
const base64Data = data.includes('base64,')
|
|
231
|
+
? data.split('base64,')[1]
|
|
232
|
+
: data;
|
|
233
|
+
imageBytes = Buffer.from(base64Data, 'base64');
|
|
225
234
|
}
|
|
226
|
-
|
|
235
|
+
catch {
|
|
236
|
+
// Fallback: treat as URL or path, use hash
|
|
237
|
+
imageBytes = Buffer.from(data);
|
|
238
|
+
}
|
|
239
|
+
// 1. Perceptual hash for content fingerprint (positions 3-34)
|
|
240
|
+
const contentHash = (0, crypto_1.createHash)('sha256').update(imageBytes).digest();
|
|
241
|
+
for (let i = 0; i < 32 && i + 3 < this.config.latentDim; i++) {
|
|
242
|
+
vector[i + 3] = (contentHash[i] - 128) / 128;
|
|
243
|
+
}
|
|
244
|
+
// 2. Byte frequency analysis (simulates color distribution, positions 35-66)
|
|
245
|
+
const byteFreq = new Array(256).fill(0);
|
|
246
|
+
for (let i = 0; i < Math.min(imageBytes.length, 10000); i++) {
|
|
247
|
+
byteFreq[imageBytes[i]]++;
|
|
248
|
+
}
|
|
249
|
+
const totalBytes = Math.min(imageBytes.length, 10000);
|
|
250
|
+
for (let i = 0; i < 32 && i + 35 < this.config.latentDim; i++) {
|
|
251
|
+
// Sample 32 frequency bins across the byte range
|
|
252
|
+
const binIdx = Math.floor(i * 8);
|
|
253
|
+
vector[i + 35] = byteFreq[binIdx] / totalBytes * 10;
|
|
254
|
+
}
|
|
255
|
+
// 3. Entropy estimation (information density, position 67-68)
|
|
256
|
+
let entropy = 0;
|
|
257
|
+
for (let i = 0; i < 256; i++) {
|
|
258
|
+
if (byteFreq[i] > 0) {
|
|
259
|
+
const p = byteFreq[i] / totalBytes;
|
|
260
|
+
entropy -= p * Math.log2(p);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (67 < this.config.latentDim)
|
|
264
|
+
vector[67] = entropy / 8; // Normalize to 0-1
|
|
265
|
+
// 4. Spatial features from byte patterns (positions 68-100)
|
|
266
|
+
// Look for repeating patterns (indicates structure)
|
|
267
|
+
let repeatScore = 0;
|
|
268
|
+
for (let i = 1; i < Math.min(imageBytes.length, 1000); i++) {
|
|
269
|
+
if (imageBytes[i] === imageBytes[i - 1])
|
|
270
|
+
repeatScore++;
|
|
271
|
+
}
|
|
272
|
+
if (68 < this.config.latentDim) {
|
|
273
|
+
vector[68] = repeatScore / Math.min(imageBytes.length - 1, 999);
|
|
274
|
+
}
|
|
275
|
+
// 5. File size feature (position 69)
|
|
276
|
+
if (69 < this.config.latentDim) {
|
|
277
|
+
vector[69] = Math.log(imageBytes.length + 1) / 20;
|
|
278
|
+
}
|
|
279
|
+
// 6. Format detection from magic bytes (positions 70-72)
|
|
280
|
+
if (70 < this.config.latentDim) {
|
|
281
|
+
const isPNG = imageBytes[0] === 0x89 && imageBytes[1] === 0x50;
|
|
282
|
+
const isJPG = imageBytes[0] === 0xFF && imageBytes[1] === 0xD8;
|
|
283
|
+
const isWebP = imageBytes[8] === 0x57 && imageBytes[9] === 0x45;
|
|
284
|
+
vector[70] = isPNG ? 1.0 : 0.0;
|
|
285
|
+
if (71 < this.config.latentDim)
|
|
286
|
+
vector[71] = isJPG ? 1.0 : 0.0;
|
|
287
|
+
if (72 < this.config.latentDim)
|
|
288
|
+
vector[72] = isWebP ? 1.0 : 0.0;
|
|
289
|
+
}
|
|
290
|
+
// 7. Metadata features (positions 0-2, reserved for size info)
|
|
227
291
|
if (input.width && input.height) {
|
|
228
292
|
vector[0] = Math.log(input.width) / 10;
|
|
229
293
|
vector[1] = Math.log(input.height) / 10;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genesis-ai-cli",
|
|
3
|
-
"version": "7.4.
|
|
3
|
+
"version": "7.4.7",
|
|
4
4
|
"description": "Autonomous AI System Creator - Brain ON by default, Active Inference integrated, Curiosity-driven, Φ monitoring in every response",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|