genesis-ai-cli 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/brain/index.d.ts +11 -0
- package/dist/src/brain/index.js +37 -0
- package/dist/src/brain/persistence.d.ts +105 -0
- package/dist/src/brain/persistence.js +351 -0
- package/dist/src/index.js +10 -2
- package/package.json +4 -4
|
@@ -53,6 +53,7 @@ export declare class Brain {
|
|
|
53
53
|
private stateStore;
|
|
54
54
|
private worldModel;
|
|
55
55
|
private darwinGodel;
|
|
56
|
+
private persistence;
|
|
56
57
|
private running;
|
|
57
58
|
private currentState;
|
|
58
59
|
private systemPrompt;
|
|
@@ -193,6 +194,7 @@ export declare class Brain {
|
|
|
193
194
|
private createInitialMetrics;
|
|
194
195
|
/**
|
|
195
196
|
* Update metrics after a cycle
|
|
197
|
+
* v8.1: Also persist metrics to disk
|
|
196
198
|
*/
|
|
197
199
|
private updateMetrics;
|
|
198
200
|
/**
|
|
@@ -213,6 +215,7 @@ export declare class Brain {
|
|
|
213
215
|
private emit;
|
|
214
216
|
/**
|
|
215
217
|
* Get brain status
|
|
218
|
+
* v8.1: Includes persisted consciousness stats
|
|
216
219
|
*/
|
|
217
220
|
getStatus(): {
|
|
218
221
|
running: boolean;
|
|
@@ -221,6 +224,14 @@ export declare class Brain {
|
|
|
221
224
|
lastState: BrainState | null;
|
|
222
225
|
metrics: BrainMetrics;
|
|
223
226
|
moduleStates: Record<string, boolean>;
|
|
227
|
+
persisted: {
|
|
228
|
+
peakPhi: number;
|
|
229
|
+
avgPhi: number;
|
|
230
|
+
totalIgnitions: number;
|
|
231
|
+
totalBroadcasts: number;
|
|
232
|
+
totalSessions: number;
|
|
233
|
+
totalUptime: number;
|
|
234
|
+
};
|
|
224
235
|
};
|
|
225
236
|
/**
|
|
226
237
|
* Get configuration
|
package/dist/src/brain/index.js
CHANGED
|
@@ -75,6 +75,8 @@ const index_js_6 = require("../kernel/index.js");
|
|
|
75
75
|
const index_js_7 = require("../persistence/index.js");
|
|
76
76
|
const index_js_8 = require("../world-model/index.js");
|
|
77
77
|
const index_js_9 = require("../self-modification/index.js");
|
|
78
|
+
// v8.1: Brain State Persistence
|
|
79
|
+
const persistence_js_1 = require("./persistence.js");
|
|
78
80
|
// ============================================================================
|
|
79
81
|
// Brain Class
|
|
80
82
|
// ============================================================================
|
|
@@ -95,6 +97,8 @@ class Brain {
|
|
|
95
97
|
stateStore = null;
|
|
96
98
|
worldModel = null;
|
|
97
99
|
darwinGodel = null;
|
|
100
|
+
// v8.1: State Persistence
|
|
101
|
+
persistence;
|
|
98
102
|
// State
|
|
99
103
|
running = false;
|
|
100
104
|
currentState = null;
|
|
@@ -139,6 +143,9 @@ class Brain {
|
|
|
139
143
|
thinkingBudget: 4096,
|
|
140
144
|
});
|
|
141
145
|
}
|
|
146
|
+
// v8.1: Initialize state persistence and load persisted metrics
|
|
147
|
+
this.persistence = (0, persistence_js_1.getBrainStatePersistence)();
|
|
148
|
+
this.metrics = { ...this.metrics, ...this.persistence.getMetrics() };
|
|
142
149
|
// v7.13: Initialize full module integration (lazy - on first use)
|
|
143
150
|
this.initializeV713Modules();
|
|
144
151
|
}
|
|
@@ -1374,6 +1381,7 @@ class Brain {
|
|
|
1374
1381
|
}
|
|
1375
1382
|
/**
|
|
1376
1383
|
* Update metrics after a cycle
|
|
1384
|
+
* v8.1: Also persist metrics to disk
|
|
1377
1385
|
*/
|
|
1378
1386
|
updateMetrics(state, transitions) {
|
|
1379
1387
|
const cycleTime = Date.now() - state.startTime;
|
|
@@ -1397,6 +1405,23 @@ class Brain {
|
|
|
1397
1405
|
this.metrics.moduleTransitions[module] =
|
|
1398
1406
|
(this.metrics.moduleTransitions[module] || 0) + 1;
|
|
1399
1407
|
}
|
|
1408
|
+
// v8.1: Persist metrics and phi to disk
|
|
1409
|
+
this.persistence.updateMetrics({
|
|
1410
|
+
totalCycles: 1,
|
|
1411
|
+
successfulCycles: state.error ? 0 : 1,
|
|
1412
|
+
failedCycles: state.error ? 1 : 0,
|
|
1413
|
+
avgCycleTime: cycleTime,
|
|
1414
|
+
memoryRecalls: state.context.immediate.length + state.context.episodic.length,
|
|
1415
|
+
toolExecutions: state.toolResults.length,
|
|
1416
|
+
toolSuccesses: state.toolResults.filter(r => r.success).length,
|
|
1417
|
+
toolFailures: state.toolResults.filter(r => !r.success).length,
|
|
1418
|
+
healingAttempts: state.healingAttempts,
|
|
1419
|
+
});
|
|
1420
|
+
this.persistence.recordPhi(state.phi, state.query.slice(0, 50));
|
|
1421
|
+
if (state.ignited) {
|
|
1422
|
+
this.persistence.recordBroadcast();
|
|
1423
|
+
}
|
|
1424
|
+
this.persistence.save();
|
|
1400
1425
|
}
|
|
1401
1426
|
/**
|
|
1402
1427
|
* Get current metrics
|
|
@@ -1438,8 +1463,11 @@ class Brain {
|
|
|
1438
1463
|
// ============================================================================
|
|
1439
1464
|
/**
|
|
1440
1465
|
* Get brain status
|
|
1466
|
+
* v8.1: Includes persisted consciousness stats
|
|
1441
1467
|
*/
|
|
1442
1468
|
getStatus() {
|
|
1469
|
+
const consciousnessStats = this.persistence.getConsciousnessStats();
|
|
1470
|
+
const persistedState = this.persistence.getState();
|
|
1443
1471
|
return {
|
|
1444
1472
|
running: this.running,
|
|
1445
1473
|
phi: this.getCurrentPhi(),
|
|
@@ -1461,6 +1489,15 @@ class Brain {
|
|
|
1461
1489
|
worldModel: this.worldModel !== null,
|
|
1462
1490
|
selfModify: this.darwinGodel !== null,
|
|
1463
1491
|
},
|
|
1492
|
+
// v8.1: Persisted stats across sessions
|
|
1493
|
+
persisted: {
|
|
1494
|
+
peakPhi: consciousnessStats.peakPhi,
|
|
1495
|
+
avgPhi: consciousnessStats.avgPhi,
|
|
1496
|
+
totalIgnitions: consciousnessStats.totalIgnitions,
|
|
1497
|
+
totalBroadcasts: consciousnessStats.totalBroadcasts,
|
|
1498
|
+
totalSessions: persistedState.sessions.total,
|
|
1499
|
+
totalUptime: persistedState.sessions.totalUptime,
|
|
1500
|
+
},
|
|
1464
1501
|
};
|
|
1465
1502
|
}
|
|
1466
1503
|
/**
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis v8.1 - Brain State Persistence
|
|
3
|
+
*
|
|
4
|
+
* Persists brain metrics and consciousness state between CLI invocations.
|
|
5
|
+
* State is saved to ~/.genesis/brain-state.json
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Auto-save after each brain cycle
|
|
9
|
+
* - Load state on startup
|
|
10
|
+
* - Track cumulative metrics across sessions
|
|
11
|
+
* - Persist phi history for consciousness continuity
|
|
12
|
+
*/
|
|
13
|
+
import { BrainMetrics } from './types.js';
|
|
14
|
+
export interface PersistedBrainState {
|
|
15
|
+
version: string;
|
|
16
|
+
created: string;
|
|
17
|
+
lastModified: string;
|
|
18
|
+
metrics: BrainMetrics;
|
|
19
|
+
consciousness: {
|
|
20
|
+
currentPhi: number;
|
|
21
|
+
peakPhi: number;
|
|
22
|
+
avgPhi: number;
|
|
23
|
+
phiHistory: PhiSnapshot[];
|
|
24
|
+
totalIgnitions: number;
|
|
25
|
+
totalBroadcasts: number;
|
|
26
|
+
consciousnessViolations: number;
|
|
27
|
+
};
|
|
28
|
+
sessions: {
|
|
29
|
+
total: number;
|
|
30
|
+
totalUptime: number;
|
|
31
|
+
lastSessionId: string;
|
|
32
|
+
lastSessionStart: string;
|
|
33
|
+
lastSessionEnd: string;
|
|
34
|
+
};
|
|
35
|
+
memory: {
|
|
36
|
+
totalRecalls: number;
|
|
37
|
+
totalAnticipations: number;
|
|
38
|
+
cumulativeReuseRate: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface PhiSnapshot {
|
|
42
|
+
timestamp: string;
|
|
43
|
+
phi: number;
|
|
44
|
+
ignited: boolean;
|
|
45
|
+
trigger?: string;
|
|
46
|
+
}
|
|
47
|
+
export declare class BrainStatePersistence {
|
|
48
|
+
private dataDir;
|
|
49
|
+
private statePath;
|
|
50
|
+
private state;
|
|
51
|
+
private dirty;
|
|
52
|
+
private sessionId;
|
|
53
|
+
private sessionStart;
|
|
54
|
+
constructor(dataDir?: string);
|
|
55
|
+
/**
|
|
56
|
+
* Load brain state from disk
|
|
57
|
+
*/
|
|
58
|
+
private load;
|
|
59
|
+
/**
|
|
60
|
+
* Save brain state to disk
|
|
61
|
+
*/
|
|
62
|
+
save(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Update metrics after a brain cycle
|
|
65
|
+
*/
|
|
66
|
+
updateMetrics(metrics: Partial<BrainMetrics>): void;
|
|
67
|
+
/**
|
|
68
|
+
* Record a phi snapshot
|
|
69
|
+
*/
|
|
70
|
+
recordPhi(phi: number, trigger?: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Record a broadcast event
|
|
73
|
+
*/
|
|
74
|
+
recordBroadcast(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Record a consciousness violation
|
|
77
|
+
*/
|
|
78
|
+
recordViolation(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Get current persisted state
|
|
81
|
+
*/
|
|
82
|
+
getState(): PersistedBrainState;
|
|
83
|
+
/**
|
|
84
|
+
* Get persisted metrics
|
|
85
|
+
*/
|
|
86
|
+
getMetrics(): BrainMetrics;
|
|
87
|
+
/**
|
|
88
|
+
* Get consciousness stats
|
|
89
|
+
*/
|
|
90
|
+
getConsciousnessStats(): PersistedBrainState['consciousness'];
|
|
91
|
+
/**
|
|
92
|
+
* Get current phi (persisted)
|
|
93
|
+
*/
|
|
94
|
+
getCurrentPhi(): number;
|
|
95
|
+
/**
|
|
96
|
+
* Reset all state (fresh start)
|
|
97
|
+
*/
|
|
98
|
+
reset(): void;
|
|
99
|
+
private ensureDataDir;
|
|
100
|
+
private generateSessionId;
|
|
101
|
+
private createInitialState;
|
|
102
|
+
private migrate;
|
|
103
|
+
}
|
|
104
|
+
export declare function getBrainStatePersistence(dataDir?: string): BrainStatePersistence;
|
|
105
|
+
export declare function resetBrainStatePersistence(): void;
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis v8.1 - Brain State Persistence
|
|
4
|
+
*
|
|
5
|
+
* Persists brain metrics and consciousness state between CLI invocations.
|
|
6
|
+
* State is saved to ~/.genesis/brain-state.json
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Auto-save after each brain cycle
|
|
10
|
+
* - Load state on startup
|
|
11
|
+
* - Track cumulative metrics across sessions
|
|
12
|
+
* - Persist phi history for consciousness continuity
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.BrainStatePersistence = void 0;
|
|
49
|
+
exports.getBrainStatePersistence = getBrainStatePersistence;
|
|
50
|
+
exports.resetBrainStatePersistence = resetBrainStatePersistence;
|
|
51
|
+
const fs = __importStar(require("fs"));
|
|
52
|
+
const path = __importStar(require("path"));
|
|
53
|
+
// ============================================================================
|
|
54
|
+
// Constants
|
|
55
|
+
// ============================================================================
|
|
56
|
+
const DEFAULT_DATA_DIR = path.join(process.env.HOME || '.', '.genesis');
|
|
57
|
+
const BRAIN_STATE_FILE = 'brain-state.json';
|
|
58
|
+
const PHI_HISTORY_MAX = 100; // Keep last 100 phi readings
|
|
59
|
+
const VERSION = '8.1.0';
|
|
60
|
+
// ============================================================================
|
|
61
|
+
// Brain State Persistence Class
|
|
62
|
+
// ============================================================================
|
|
63
|
+
class BrainStatePersistence {
|
|
64
|
+
dataDir;
|
|
65
|
+
statePath;
|
|
66
|
+
state;
|
|
67
|
+
dirty = false;
|
|
68
|
+
sessionId;
|
|
69
|
+
sessionStart;
|
|
70
|
+
constructor(dataDir) {
|
|
71
|
+
this.dataDir = dataDir || DEFAULT_DATA_DIR;
|
|
72
|
+
this.statePath = path.join(this.dataDir, BRAIN_STATE_FILE);
|
|
73
|
+
this.sessionId = this.generateSessionId();
|
|
74
|
+
this.sessionStart = new Date();
|
|
75
|
+
// Ensure data directory exists
|
|
76
|
+
this.ensureDataDir();
|
|
77
|
+
// Load or create initial state
|
|
78
|
+
this.state = this.load();
|
|
79
|
+
// Update session info
|
|
80
|
+
this.state.sessions.total++;
|
|
81
|
+
this.state.sessions.lastSessionId = this.sessionId;
|
|
82
|
+
this.state.sessions.lastSessionStart = this.sessionStart.toISOString();
|
|
83
|
+
this.dirty = true;
|
|
84
|
+
}
|
|
85
|
+
// ============================================================================
|
|
86
|
+
// Core Operations
|
|
87
|
+
// ============================================================================
|
|
88
|
+
/**
|
|
89
|
+
* Load brain state from disk
|
|
90
|
+
*/
|
|
91
|
+
load() {
|
|
92
|
+
try {
|
|
93
|
+
if (fs.existsSync(this.statePath)) {
|
|
94
|
+
const raw = fs.readFileSync(this.statePath, 'utf-8');
|
|
95
|
+
const state = JSON.parse(raw);
|
|
96
|
+
// Validate version and migrate if needed
|
|
97
|
+
if (state.version !== VERSION) {
|
|
98
|
+
return this.migrate(state);
|
|
99
|
+
}
|
|
100
|
+
return state;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error('[BrainPersistence] Failed to load state:', error);
|
|
105
|
+
}
|
|
106
|
+
return this.createInitialState();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Save brain state to disk
|
|
110
|
+
*/
|
|
111
|
+
save() {
|
|
112
|
+
if (!this.dirty)
|
|
113
|
+
return true;
|
|
114
|
+
try {
|
|
115
|
+
this.state.lastModified = new Date().toISOString();
|
|
116
|
+
this.state.sessions.lastSessionEnd = new Date().toISOString();
|
|
117
|
+
this.state.sessions.totalUptime += Date.now() - this.sessionStart.getTime();
|
|
118
|
+
const json = JSON.stringify(this.state, null, 2);
|
|
119
|
+
fs.writeFileSync(this.statePath, json, 'utf-8');
|
|
120
|
+
this.dirty = false;
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error('[BrainPersistence] Failed to save state:', error);
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Update metrics after a brain cycle
|
|
130
|
+
*/
|
|
131
|
+
updateMetrics(metrics) {
|
|
132
|
+
// Merge metrics (cumulative)
|
|
133
|
+
const m = this.state.metrics;
|
|
134
|
+
if (metrics.totalCycles !== undefined)
|
|
135
|
+
m.totalCycles += metrics.totalCycles;
|
|
136
|
+
if (metrics.successfulCycles !== undefined)
|
|
137
|
+
m.successfulCycles += metrics.successfulCycles;
|
|
138
|
+
if (metrics.failedCycles !== undefined)
|
|
139
|
+
m.failedCycles += metrics.failedCycles;
|
|
140
|
+
if (metrics.memoryRecalls !== undefined)
|
|
141
|
+
m.memoryRecalls += metrics.memoryRecalls;
|
|
142
|
+
if (metrics.anticipationHits !== undefined)
|
|
143
|
+
m.anticipationHits += metrics.anticipationHits;
|
|
144
|
+
if (metrics.anticipationMisses !== undefined)
|
|
145
|
+
m.anticipationMisses += metrics.anticipationMisses;
|
|
146
|
+
if (metrics.groundingChecks !== undefined)
|
|
147
|
+
m.groundingChecks += metrics.groundingChecks;
|
|
148
|
+
if (metrics.groundingPasses !== undefined)
|
|
149
|
+
m.groundingPasses += metrics.groundingPasses;
|
|
150
|
+
if (metrics.groundingFailures !== undefined)
|
|
151
|
+
m.groundingFailures += metrics.groundingFailures;
|
|
152
|
+
if (metrics.humanConsultations !== undefined)
|
|
153
|
+
m.humanConsultations += metrics.humanConsultations;
|
|
154
|
+
if (metrics.toolExecutions !== undefined)
|
|
155
|
+
m.toolExecutions += metrics.toolExecutions;
|
|
156
|
+
if (metrics.toolSuccesses !== undefined)
|
|
157
|
+
m.toolSuccesses += metrics.toolSuccesses;
|
|
158
|
+
if (metrics.toolFailures !== undefined)
|
|
159
|
+
m.toolFailures += metrics.toolFailures;
|
|
160
|
+
if (metrics.healingAttempts !== undefined)
|
|
161
|
+
m.healingAttempts += metrics.healingAttempts;
|
|
162
|
+
if (metrics.healingSuccesses !== undefined)
|
|
163
|
+
m.healingSuccesses += metrics.healingSuccesses;
|
|
164
|
+
if (metrics.healingFailures !== undefined)
|
|
165
|
+
m.healingFailures += metrics.healingFailures;
|
|
166
|
+
// Update avg cycle time (weighted average)
|
|
167
|
+
if (metrics.avgCycleTime !== undefined && metrics.totalCycles !== undefined) {
|
|
168
|
+
const totalTime = m.avgCycleTime * (m.totalCycles - metrics.totalCycles) +
|
|
169
|
+
metrics.avgCycleTime * metrics.totalCycles;
|
|
170
|
+
m.avgCycleTime = m.totalCycles > 0 ? totalTime / m.totalCycles : 0;
|
|
171
|
+
}
|
|
172
|
+
this.dirty = true;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Record a phi snapshot
|
|
176
|
+
*/
|
|
177
|
+
recordPhi(phi, trigger) {
|
|
178
|
+
const snapshot = {
|
|
179
|
+
timestamp: new Date().toISOString(),
|
|
180
|
+
phi,
|
|
181
|
+
ignited: phi >= 0.3,
|
|
182
|
+
trigger,
|
|
183
|
+
};
|
|
184
|
+
// Update consciousness tracking
|
|
185
|
+
const c = this.state.consciousness;
|
|
186
|
+
c.currentPhi = phi;
|
|
187
|
+
if (phi > c.peakPhi)
|
|
188
|
+
c.peakPhi = phi;
|
|
189
|
+
// Update running average
|
|
190
|
+
const historyLen = c.phiHistory.length;
|
|
191
|
+
c.avgPhi = historyLen > 0
|
|
192
|
+
? (c.avgPhi * historyLen + phi) / (historyLen + 1)
|
|
193
|
+
: phi;
|
|
194
|
+
// Track ignitions
|
|
195
|
+
if (snapshot.ignited) {
|
|
196
|
+
c.totalIgnitions++;
|
|
197
|
+
}
|
|
198
|
+
// Add to history (keep last N)
|
|
199
|
+
c.phiHistory.push(snapshot);
|
|
200
|
+
if (c.phiHistory.length > PHI_HISTORY_MAX) {
|
|
201
|
+
c.phiHistory.shift();
|
|
202
|
+
}
|
|
203
|
+
this.dirty = true;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Record a broadcast event
|
|
207
|
+
*/
|
|
208
|
+
recordBroadcast() {
|
|
209
|
+
this.state.consciousness.totalBroadcasts++;
|
|
210
|
+
this.dirty = true;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Record a consciousness violation
|
|
214
|
+
*/
|
|
215
|
+
recordViolation() {
|
|
216
|
+
this.state.consciousness.consciousnessViolations++;
|
|
217
|
+
this.dirty = true;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get current persisted state
|
|
221
|
+
*/
|
|
222
|
+
getState() {
|
|
223
|
+
return { ...this.state };
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get persisted metrics
|
|
227
|
+
*/
|
|
228
|
+
getMetrics() {
|
|
229
|
+
return { ...this.state.metrics };
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Get consciousness stats
|
|
233
|
+
*/
|
|
234
|
+
getConsciousnessStats() {
|
|
235
|
+
return { ...this.state.consciousness };
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get current phi (persisted)
|
|
239
|
+
*/
|
|
240
|
+
getCurrentPhi() {
|
|
241
|
+
return this.state.consciousness.currentPhi;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Reset all state (fresh start)
|
|
245
|
+
*/
|
|
246
|
+
reset() {
|
|
247
|
+
this.state = this.createInitialState();
|
|
248
|
+
this.dirty = true;
|
|
249
|
+
this.save();
|
|
250
|
+
}
|
|
251
|
+
// ============================================================================
|
|
252
|
+
// Helpers
|
|
253
|
+
// ============================================================================
|
|
254
|
+
ensureDataDir() {
|
|
255
|
+
if (!fs.existsSync(this.dataDir)) {
|
|
256
|
+
fs.mkdirSync(this.dataDir, { recursive: true });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
generateSessionId() {
|
|
260
|
+
return `session-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`;
|
|
261
|
+
}
|
|
262
|
+
createInitialState() {
|
|
263
|
+
return {
|
|
264
|
+
version: VERSION,
|
|
265
|
+
created: new Date().toISOString(),
|
|
266
|
+
lastModified: new Date().toISOString(),
|
|
267
|
+
metrics: {
|
|
268
|
+
totalCycles: 0,
|
|
269
|
+
successfulCycles: 0,
|
|
270
|
+
failedCycles: 0,
|
|
271
|
+
avgCycleTime: 0,
|
|
272
|
+
memoryRecalls: 0,
|
|
273
|
+
memoryReuseRate: 0,
|
|
274
|
+
anticipationHits: 0,
|
|
275
|
+
anticipationMisses: 0,
|
|
276
|
+
groundingChecks: 0,
|
|
277
|
+
groundingPasses: 0,
|
|
278
|
+
groundingFailures: 0,
|
|
279
|
+
humanConsultations: 0,
|
|
280
|
+
toolExecutions: 0,
|
|
281
|
+
toolSuccesses: 0,
|
|
282
|
+
toolFailures: 0,
|
|
283
|
+
healingAttempts: 0,
|
|
284
|
+
healingSuccesses: 0,
|
|
285
|
+
healingFailures: 0,
|
|
286
|
+
avgPhi: 0,
|
|
287
|
+
phiViolations: 0,
|
|
288
|
+
broadcasts: 0,
|
|
289
|
+
moduleTransitions: {},
|
|
290
|
+
},
|
|
291
|
+
consciousness: {
|
|
292
|
+
currentPhi: 0,
|
|
293
|
+
peakPhi: 0,
|
|
294
|
+
avgPhi: 0,
|
|
295
|
+
phiHistory: [],
|
|
296
|
+
totalIgnitions: 0,
|
|
297
|
+
totalBroadcasts: 0,
|
|
298
|
+
consciousnessViolations: 0,
|
|
299
|
+
},
|
|
300
|
+
sessions: {
|
|
301
|
+
total: 0,
|
|
302
|
+
totalUptime: 0,
|
|
303
|
+
lastSessionId: '',
|
|
304
|
+
lastSessionStart: '',
|
|
305
|
+
lastSessionEnd: '',
|
|
306
|
+
},
|
|
307
|
+
memory: {
|
|
308
|
+
totalRecalls: 0,
|
|
309
|
+
totalAnticipations: 0,
|
|
310
|
+
cumulativeReuseRate: 0,
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
migrate(oldState) {
|
|
315
|
+
// Migrate from older versions
|
|
316
|
+
const newState = this.createInitialState();
|
|
317
|
+
// Preserve what we can
|
|
318
|
+
if (oldState.metrics) {
|
|
319
|
+
newState.metrics = { ...newState.metrics, ...oldState.metrics };
|
|
320
|
+
}
|
|
321
|
+
if (oldState.consciousness) {
|
|
322
|
+
newState.consciousness = { ...newState.consciousness, ...oldState.consciousness };
|
|
323
|
+
}
|
|
324
|
+
if (oldState.sessions) {
|
|
325
|
+
newState.sessions = { ...newState.sessions, ...oldState.sessions };
|
|
326
|
+
}
|
|
327
|
+
if (oldState.memory) {
|
|
328
|
+
newState.memory = { ...newState.memory, ...oldState.memory };
|
|
329
|
+
}
|
|
330
|
+
newState.version = VERSION;
|
|
331
|
+
newState.created = oldState.created || newState.created;
|
|
332
|
+
return newState;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
exports.BrainStatePersistence = BrainStatePersistence;
|
|
336
|
+
// ============================================================================
|
|
337
|
+
// Singleton Instance
|
|
338
|
+
// ============================================================================
|
|
339
|
+
let persistenceInstance = null;
|
|
340
|
+
function getBrainStatePersistence(dataDir) {
|
|
341
|
+
if (!persistenceInstance) {
|
|
342
|
+
persistenceInstance = new BrainStatePersistence(dataDir);
|
|
343
|
+
}
|
|
344
|
+
return persistenceInstance;
|
|
345
|
+
}
|
|
346
|
+
function resetBrainStatePersistence() {
|
|
347
|
+
if (persistenceInstance) {
|
|
348
|
+
persistenceInstance.save();
|
|
349
|
+
}
|
|
350
|
+
persistenceInstance = null;
|
|
351
|
+
}
|
package/dist/src/index.js
CHANGED
|
@@ -909,8 +909,8 @@ async function cmdBrain(subcommand, options) {
|
|
|
909
909
|
return;
|
|
910
910
|
}
|
|
911
911
|
if (subcommand === 'phi') {
|
|
912
|
-
const
|
|
913
|
-
const phi =
|
|
912
|
+
const status = brain.getStatus();
|
|
913
|
+
const phi = status.persisted.avgPhi; // v8.1: Use persisted phi
|
|
914
914
|
console.log(c('\n=== CONSCIOUSNESS LEVEL (φ) ===\n', 'bold'));
|
|
915
915
|
// Visual bar
|
|
916
916
|
const width = 30;
|
|
@@ -930,6 +930,14 @@ async function cmdBrain(subcommand, options) {
|
|
|
930
930
|
console.log(` Level: ${c(bar, 'dim')} LOW`);
|
|
931
931
|
console.log(` Status: ${c('Local processing - no broadcasting', 'dim')}`);
|
|
932
932
|
}
|
|
933
|
+
// v8.1: Show persisted consciousness history
|
|
934
|
+
console.log();
|
|
935
|
+
console.log(c('History (persisted):', 'cyan'));
|
|
936
|
+
console.log(` Peak φ: ${status.persisted.peakPhi.toFixed(3)}`);
|
|
937
|
+
console.log(` Avg φ: ${status.persisted.avgPhi.toFixed(3)}`);
|
|
938
|
+
console.log(` Ignitions: ${status.persisted.totalIgnitions} (φ > 0.3 events)`);
|
|
939
|
+
console.log(` Broadcasts: ${status.persisted.totalBroadcasts}`);
|
|
940
|
+
console.log(` Sessions: ${status.persisted.totalSessions}`);
|
|
933
941
|
console.log();
|
|
934
942
|
console.log(c('Theory:', 'dim'));
|
|
935
943
|
console.log(' φ (phi) measures integrated information (IIT 4.0)');
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genesis-ai-cli",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "Fully Autonomous AI System - Self-funding, Self-deploying, Production Memory, A2A Protocol & Governance",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
7
7
|
"bin": {
|
|
8
|
-
"genesis": "
|
|
9
|
-
"genesis-ai-cli": "
|
|
8
|
+
"genesis": "dist/src/index.js",
|
|
9
|
+
"genesis-ai-cli": "dist/src/index.js"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "tsc",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"repository": {
|
|
43
43
|
"type": "git",
|
|
44
|
-
"url": "https://github.com/rossignoliluca/genesis.git"
|
|
44
|
+
"url": "git+https://github.com/rossignoliluca/genesis.git"
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/rossignoliluca/genesis#readme",
|
|
47
47
|
"bugs": {
|