genesis-ai-cli 7.16.0 → 7.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/active-inference/core.d.ts +2 -0
- package/dist/src/active-inference/core.js +16 -3
- package/dist/src/active-inference/types.js +1 -1
- package/dist/src/brain/index.d.ts +7 -0
- package/dist/src/brain/index.js +89 -6
- package/dist/src/brain/types.js +2 -2
- package/dist/src/cli/chat.d.ts +4 -1
- package/dist/src/cli/chat.js +115 -42
- package/dist/src/llm/index.d.ts +29 -0
- package/dist/src/llm/index.js +130 -7
- package/dist/src/llm/router.js +3 -2
- package/dist/src/mcp/index.d.ts +4 -0
- package/dist/src/mcp/index.js +131 -6
- package/dist/src/mcp/resilient.js +1 -1
- package/dist/src/memory/cognitive-workspace.js +2 -2
- package/dist/src/self-modification/index.d.ts +1 -0
- package/dist/src/self-modification/index.js +8 -1
- package/dist/src/self-modification/self-improvement.d.ts +164 -0
- package/dist/src/self-modification/self-improvement.js +550 -0
- package/dist/src/unified-system.d.ts +154 -0
- package/dist/src/unified-system.js +355 -0
- package/package.json +1 -1
|
@@ -260,6 +260,9 @@ class ActiveInferenceEngine {
|
|
|
260
260
|
beliefs;
|
|
261
261
|
// Event handlers
|
|
262
262
|
eventHandlers = [];
|
|
263
|
+
// Self-improved: Track action counts for UCB exploration
|
|
264
|
+
actionCounts = new Array(types_js_1.ACTION_COUNT).fill(1);
|
|
265
|
+
totalActions = types_js_1.ACTION_COUNT;
|
|
263
266
|
// Statistics
|
|
264
267
|
stats = {
|
|
265
268
|
inferenceCount: 0,
|
|
@@ -348,9 +351,16 @@ class ActiveInferenceEngine {
|
|
|
348
351
|
for (let a = 0; a < types_js_1.ACTION_COUNT; a++) {
|
|
349
352
|
efe[a] = this.computeEFE(a);
|
|
350
353
|
}
|
|
351
|
-
// Convert to policy via softmax
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
+
// Convert to policy via softmax with exploration bonus (UCB-style)
|
|
355
|
+
// Self-improved: adds exploration term to prevent getting stuck
|
|
356
|
+
const explorationBonus = efe.map((_, a) => {
|
|
357
|
+
const count = this.actionCounts?.[a] ?? 1;
|
|
358
|
+
const total = this.totalActions ?? types_js_1.ACTION_COUNT;
|
|
359
|
+
return Math.sqrt(Math.log(total + 1) / count); // UCB term
|
|
360
|
+
});
|
|
361
|
+
const beta = 0.5; // Exploration weight
|
|
362
|
+
const augmentedEfe = efe.map((e, i) => -e + beta * explorationBonus[i]);
|
|
363
|
+
const policy = softmax(augmentedEfe, this.config.actionTemperature);
|
|
354
364
|
this.emit({
|
|
355
365
|
type: 'policy_inferred',
|
|
356
366
|
timestamp: new Date(),
|
|
@@ -377,6 +387,9 @@ class ActiveInferenceEngine {
|
|
|
377
387
|
// Track statistics
|
|
378
388
|
const count = this.stats.actionsTaken.get(action) || 0;
|
|
379
389
|
this.stats.actionsTaken.set(action, count + 1);
|
|
390
|
+
// Self-improved: Update action counts for UCB exploration
|
|
391
|
+
this.actionCounts[selectedIdx]++;
|
|
392
|
+
this.totalActions++;
|
|
380
393
|
this.emit({
|
|
381
394
|
type: 'action_selected',
|
|
382
395
|
timestamp: new Date(),
|
|
@@ -70,7 +70,7 @@ exports.ACTIONS = [
|
|
|
70
70
|
];
|
|
71
71
|
exports.ACTION_COUNT = exports.ACTIONS.length;
|
|
72
72
|
exports.DEFAULT_CONFIG = {
|
|
73
|
-
inferenceIterations:
|
|
73
|
+
inferenceIterations: 26, // Auto-improved: Φ was 0.43 // Self-improved: +50% iterations for accuracy
|
|
74
74
|
policyHorizon: 3,
|
|
75
75
|
actionTemperature: 1.0,
|
|
76
76
|
priorWeight: 0.1,
|
|
@@ -61,6 +61,7 @@ export declare class Brain {
|
|
|
61
61
|
constructor(config?: Partial<BrainConfig>);
|
|
62
62
|
/**
|
|
63
63
|
* v7.13: Initialize new module integrations
|
|
64
|
+
* v7.18: Connect real PhiMonitor and dispatcher for full integration
|
|
64
65
|
*/
|
|
65
66
|
private initializeV713Modules;
|
|
66
67
|
/**
|
|
@@ -100,6 +101,12 @@ export declare class Brain {
|
|
|
100
101
|
* Memory module: recall context and anticipate needs
|
|
101
102
|
*/
|
|
102
103
|
private stepMemory;
|
|
104
|
+
/**
|
|
105
|
+
* v7.18: Determine optimal model tier based on task complexity
|
|
106
|
+
* - fast: Simple queries, short responses, tool formatting
|
|
107
|
+
* - balanced: Complex reasoning, creative tasks
|
|
108
|
+
*/
|
|
109
|
+
private determineModelTier;
|
|
103
110
|
/**
|
|
104
111
|
* LLM module: generate response
|
|
105
112
|
*/
|
package/dist/src/brain/index.js
CHANGED
|
@@ -144,11 +144,30 @@ class Brain {
|
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
146
|
* v7.13: Initialize new module integrations
|
|
147
|
+
* v7.18: Connect real PhiMonitor and dispatcher for full integration
|
|
147
148
|
*/
|
|
148
149
|
initializeV713Modules() {
|
|
149
150
|
try {
|
|
150
151
|
// Active Inference - Free Energy minimization
|
|
151
152
|
this.activeInference = (0, index_js_5.getAutonomousLoop)();
|
|
153
|
+
// v7.18: Configure observation gatherer with real system state
|
|
154
|
+
const observationGatherer = (0, index_js_5.getObservationGatherer)();
|
|
155
|
+
observationGatherer.configure({
|
|
156
|
+
phiState: () => {
|
|
157
|
+
const level = this.phiMonitor.getCurrentLevel();
|
|
158
|
+
// Map phi to PhiState: dormant < 0.2, drowsy < 0.4, aware < 0.7, alert >= 0.7
|
|
159
|
+
const state = level.phi >= 0.7 ? 'alert'
|
|
160
|
+
: level.phi >= 0.4 ? 'aware'
|
|
161
|
+
: level.phi >= 0.2 ? 'drowsy'
|
|
162
|
+
: 'dormant';
|
|
163
|
+
return { phi: level.phi, state };
|
|
164
|
+
},
|
|
165
|
+
kernelState: () => ({
|
|
166
|
+
energy: 1.0, // Brain doesn't track energy, default to full
|
|
167
|
+
state: this.running ? 'thinking' : 'idle',
|
|
168
|
+
taskStatus: 'pending',
|
|
169
|
+
}),
|
|
170
|
+
});
|
|
152
171
|
}
|
|
153
172
|
catch {
|
|
154
173
|
// Module may not be configured
|
|
@@ -156,6 +175,8 @@ class Brain {
|
|
|
156
175
|
try {
|
|
157
176
|
// Subagent Executor - specialized task delegation
|
|
158
177
|
this.subagentExecutor = (0, executor_js_1.getSubagentExecutor)();
|
|
178
|
+
// v7.18: Connect dispatcher for multi-turn tool execution
|
|
179
|
+
this.subagentExecutor.setDispatcher(this.dispatcher);
|
|
159
180
|
}
|
|
160
181
|
catch {
|
|
161
182
|
// Module may not be configured
|
|
@@ -278,6 +299,8 @@ class Brain {
|
|
|
278
299
|
this.emit({ type: 'cycle_start', timestamp: new Date(), data: { query: input } });
|
|
279
300
|
// Supervisor loop
|
|
280
301
|
let transitions = 0;
|
|
302
|
+
let consecutiveErrors = 0; // v7.18: Track consecutive failures for early exit
|
|
303
|
+
const MAX_CONSECUTIVE_ERRORS = 3;
|
|
281
304
|
while (command.goto !== 'done' && transitions < this.config.maxModuleTransitions) {
|
|
282
305
|
// Update state
|
|
283
306
|
state = { ...state, ...command.update };
|
|
@@ -287,6 +310,14 @@ class Brain {
|
|
|
287
310
|
command = { goto: 'done', update: { response: 'Processing timeout. Please try again.' } };
|
|
288
311
|
break;
|
|
289
312
|
}
|
|
313
|
+
// v7.18: Early exit on repeated failures
|
|
314
|
+
if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) {
|
|
315
|
+
command = {
|
|
316
|
+
goto: 'done',
|
|
317
|
+
update: { response: `Unable to complete after ${consecutiveErrors} consecutive errors. Please try again.` },
|
|
318
|
+
};
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
290
321
|
try {
|
|
291
322
|
this.emit({ type: 'module_enter', timestamp: new Date(), data: { module: command.goto }, module: command.goto });
|
|
292
323
|
// Execute module
|
|
@@ -296,9 +327,11 @@ class Brain {
|
|
|
296
327
|
if (this.config.consciousness.broadcastEnabled) {
|
|
297
328
|
this.broadcast(state, command.goto);
|
|
298
329
|
}
|
|
330
|
+
consecutiveErrors = 0; // Reset on success
|
|
299
331
|
transitions++;
|
|
300
332
|
}
|
|
301
333
|
catch (error) {
|
|
334
|
+
consecutiveErrors++; // v7.18: Track consecutive errors
|
|
302
335
|
// Healing loop
|
|
303
336
|
if (this.config.healing.enabled && this.config.healing.autoHeal) {
|
|
304
337
|
command = await this.heal(error, state);
|
|
@@ -419,6 +452,30 @@ class Brain {
|
|
|
419
452
|
reason: 'context_retrieved',
|
|
420
453
|
};
|
|
421
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* v7.18: Determine optimal model tier based on task complexity
|
|
457
|
+
* - fast: Simple queries, short responses, tool formatting
|
|
458
|
+
* - balanced: Complex reasoning, creative tasks
|
|
459
|
+
*/
|
|
460
|
+
determineModelTier(query, hasToolResults) {
|
|
461
|
+
const wordCount = query.split(/\s+/).length;
|
|
462
|
+
const lowerQuery = query.toLowerCase();
|
|
463
|
+
// Use fast tier for:
|
|
464
|
+
// - Short queries (< 50 words)
|
|
465
|
+
// - Tool result formatting
|
|
466
|
+
// - Simple questions
|
|
467
|
+
const isSimple = wordCount < 50 &&
|
|
468
|
+
!lowerQuery.includes('explain') &&
|
|
469
|
+
!lowerQuery.includes('analyze') &&
|
|
470
|
+
!lowerQuery.includes('design') &&
|
|
471
|
+
!lowerQuery.includes('implement') &&
|
|
472
|
+
!lowerQuery.includes('create') &&
|
|
473
|
+
!lowerQuery.includes('refactor');
|
|
474
|
+
if (isSimple || hasToolResults) {
|
|
475
|
+
return 'fast';
|
|
476
|
+
}
|
|
477
|
+
return 'balanced';
|
|
478
|
+
}
|
|
422
479
|
/**
|
|
423
480
|
* LLM module: generate response
|
|
424
481
|
*/
|
|
@@ -429,8 +486,11 @@ class Brain {
|
|
|
429
486
|
const prompt = contextStr
|
|
430
487
|
? `Context:\n${contextStr}\n\nUser: ${state.query}`
|
|
431
488
|
: state.query;
|
|
432
|
-
//
|
|
433
|
-
const
|
|
489
|
+
// v7.18: Cost optimization - use tiered models
|
|
490
|
+
const hasToolResults = state.toolResults && state.toolResults.length > 0;
|
|
491
|
+
const tier = this.determineModelTier(state.query, hasToolResults);
|
|
492
|
+
// Call LLM with appropriate model tier
|
|
493
|
+
const response = await this.llm.chatWithTier(prompt, tier, this.systemPrompt || undefined);
|
|
434
494
|
this.emit({ type: 'llm_response', timestamp: new Date(), data: { length: response.content.length } });
|
|
435
495
|
// Parse tool calls if any
|
|
436
496
|
const toolCalls = this.parseToolCalls(response.content);
|
|
@@ -705,8 +765,9 @@ class Brain {
|
|
|
705
765
|
// Get stats for monitoring
|
|
706
766
|
const stats = this.activeInference.getStats();
|
|
707
767
|
// Route based on action type from active inference
|
|
708
|
-
//
|
|
709
|
-
|
|
768
|
+
// v7.18: Comprehensive routing for all action types
|
|
769
|
+
// Memory-related actions
|
|
770
|
+
if (actionType === 'recall.memory' || actionType === 'dream.cycle' || actionType === 'code.history') {
|
|
710
771
|
// Trigger memory anticipation based on active inference predictions
|
|
711
772
|
try {
|
|
712
773
|
const anticipated = await this.workspace.anticipate({
|
|
@@ -732,11 +793,33 @@ class Brain {
|
|
|
732
793
|
reason: 'active_inference_recall',
|
|
733
794
|
};
|
|
734
795
|
}
|
|
735
|
-
|
|
796
|
+
// Tool execution actions (MCP, web, deployment, etc.)
|
|
797
|
+
const toolActions = [
|
|
798
|
+
'execute.task', 'execute.code', 'execute.shell', 'execute.cycle', 'adapt.code',
|
|
799
|
+
'sense.mcp', 'web.search', 'web.scrape', 'web.browse',
|
|
800
|
+
'deploy.service', 'content.generate', 'api.call', 'github.deploy',
|
|
801
|
+
];
|
|
802
|
+
if (toolActions.includes(actionType)) {
|
|
736
803
|
return {
|
|
737
804
|
goto: 'tools',
|
|
738
805
|
update: { phi },
|
|
739
|
-
reason:
|
|
806
|
+
reason: `active_inference_tool:${actionType}`,
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
// Self-modification actions - route to darwin-godel
|
|
810
|
+
if (actionType === 'self.modify' || actionType === 'self.analyze' || actionType === 'code.snapshot' || actionType === 'code.diff') {
|
|
811
|
+
return {
|
|
812
|
+
goto: 'self-modify',
|
|
813
|
+
update: { phi },
|
|
814
|
+
reason: 'active_inference_self_modify',
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
// Rest actions - skip to response (energy conservation)
|
|
818
|
+
if (actionType === 'rest.idle' || actionType === 'recharge') {
|
|
819
|
+
return {
|
|
820
|
+
goto: 'llm',
|
|
821
|
+
update: { phi },
|
|
822
|
+
reason: 'active_inference_rest',
|
|
740
823
|
};
|
|
741
824
|
}
|
|
742
825
|
// Default: proceed to thinking with beliefs context
|
package/dist/src/brain/types.js
CHANGED
|
@@ -46,6 +46,6 @@ exports.DEFAULT_BRAIN_CONFIG = {
|
|
|
46
46
|
phiThreshold: 0.1,
|
|
47
47
|
broadcastEnabled: true,
|
|
48
48
|
},
|
|
49
|
-
maxCycleTime:
|
|
50
|
-
maxModuleTransitions: 20
|
|
49
|
+
maxCycleTime: 120000, // v7.18: Reduced from 10min to 2min for faster responses
|
|
50
|
+
maxModuleTransitions: 10, // v7.18: Reduced from 20 to 10 for faster convergence
|
|
51
51
|
};
|
package/dist/src/cli/chat.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export declare class ChatSession {
|
|
|
59
59
|
private inputHistory;
|
|
60
60
|
private memory;
|
|
61
61
|
private selfProduction;
|
|
62
|
+
private darwinGodel;
|
|
62
63
|
private inferenceLoop;
|
|
63
64
|
private lastCuriosity;
|
|
64
65
|
private lastSurprise;
|
|
@@ -190,7 +191,9 @@ export declare class ChatSession {
|
|
|
190
191
|
*/
|
|
191
192
|
private renderHealthBar;
|
|
192
193
|
/**
|
|
193
|
-
* Run self-improvement (v7.
|
|
194
|
+
* Run self-improvement (v7.17 Darwin-Gödel - REAL)
|
|
195
|
+
*
|
|
196
|
+
* This actually modifies Genesis code based on runtime metrics.
|
|
194
197
|
*/
|
|
195
198
|
private runSelfImprovement;
|
|
196
199
|
/**
|
package/dist/src/cli/chat.js
CHANGED
|
@@ -70,6 +70,8 @@ const index_js_4 = require("../brain/index.js");
|
|
|
70
70
|
const index_js_5 = require("../memory/index.js");
|
|
71
71
|
const index_js_6 = require("../healing/index.js");
|
|
72
72
|
const self_production_js_1 = require("../self-production.js");
|
|
73
|
+
// v7.17: Real Darwin-Gödel self-modification
|
|
74
|
+
const darwin_godel_js_1 = require("../self-modification/darwin-godel.js");
|
|
73
75
|
// v7.1: Active Inference integration
|
|
74
76
|
const index_js_7 = require("../active-inference/index.js");
|
|
75
77
|
// v7.4: Subagent System
|
|
@@ -102,6 +104,7 @@ class ChatSession {
|
|
|
102
104
|
inputHistory;
|
|
103
105
|
memory; // v7.0: Memory system with consolidation
|
|
104
106
|
selfProduction; // v7.0: Darwin-Gödel self-improvement
|
|
107
|
+
darwinGodel; // v7.17: Real self-modification engine
|
|
105
108
|
// v7.1: Active Inference integration
|
|
106
109
|
inferenceLoop = null;
|
|
107
110
|
lastCuriosity = 0; // Track curiosity level
|
|
@@ -135,6 +138,7 @@ class ChatSession {
|
|
|
135
138
|
this.brainTrace = (0, index_js_4.createBrainTrace)(this.brain); // Phase 10: Initialize trace
|
|
136
139
|
this.memory = (0, index_js_5.getMemorySystem)(); // v7.0: Initialize memory with consolidation
|
|
137
140
|
this.selfProduction = (0, self_production_js_1.createSelfProductionEngine)('7.1.0'); // v7.1: Darwin-Gödel
|
|
141
|
+
this.darwinGodel = (0, darwin_godel_js_1.getDarwinGodelEngine)({ gitEnabled: true, skipTests: true }); // v7.17: Real modification engine
|
|
138
142
|
this.subagentExecutor = (0, index_js_8.getSubagentExecutor)(); // v7.4: Subagent system
|
|
139
143
|
this.subagentExecutor.setDispatcher(this.dispatcher); // v7.4: Wire dispatcher
|
|
140
144
|
this.verbose = options.verbose ?? false;
|
|
@@ -1088,7 +1092,9 @@ INSTRUCTION: You MUST report this error to the user. Do NOT fabricate or guess w
|
|
|
1088
1092
|
console.log(' /history Show conversation history');
|
|
1089
1093
|
console.log(' /status, /s Show LLM status');
|
|
1090
1094
|
console.log(' /verbose, /v Toggle verbose mode');
|
|
1091
|
-
console.log(' /system Show system prompt');
|
|
1095
|
+
console.log(' /system Show/set custom system prompt');
|
|
1096
|
+
console.log(' /system <text> Set custom system prompt injection');
|
|
1097
|
+
console.log(' /system clear Clear custom system prompt');
|
|
1092
1098
|
console.log();
|
|
1093
1099
|
console.log((0, ui_js_1.c)('Tools:', 'bold'));
|
|
1094
1100
|
console.log(' /tools Toggle MCP tool execution');
|
|
@@ -1672,56 +1678,123 @@ INSTRUCTION: You MUST report this error to the user. Do NOT fabricate or guess w
|
|
|
1672
1678
|
return (0, ui_js_1.c)(bar, 'red');
|
|
1673
1679
|
}
|
|
1674
1680
|
/**
|
|
1675
|
-
* Run self-improvement (v7.
|
|
1681
|
+
* Run self-improvement (v7.17 Darwin-Gödel - REAL)
|
|
1682
|
+
*
|
|
1683
|
+
* This actually modifies Genesis code based on runtime metrics.
|
|
1676
1684
|
*/
|
|
1677
1685
|
async runSelfImprovement() {
|
|
1678
|
-
console.log((0, ui_js_1.c)('Darwin-Gödel Self-Improvement (v7.
|
|
1686
|
+
console.log((0, ui_js_1.c)('Darwin-Gödel Self-Improvement (v7.17 - REAL):', 'bold'));
|
|
1679
1687
|
console.log();
|
|
1680
|
-
//
|
|
1688
|
+
// Analyze brain metrics to determine what to improve
|
|
1681
1689
|
const brainMetrics = this.brain.getMetrics();
|
|
1682
|
-
const
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1690
|
+
const memoryReuse = brainMetrics.memoryReuseRate;
|
|
1691
|
+
const avgCycleTime = brainMetrics.avgCycleTime;
|
|
1692
|
+
const phi = brainMetrics.avgPhi;
|
|
1693
|
+
console.log((0, ui_js_1.info)('Current metrics:'));
|
|
1694
|
+
console.log(` Memory reuse: ${(memoryReuse * 100).toFixed(1)}%`);
|
|
1695
|
+
console.log(` Avg cycle time: ${avgCycleTime.toFixed(0)}ms`);
|
|
1696
|
+
console.log(` Φ (consciousness): ${phi.toFixed(3)}`);
|
|
1697
|
+
console.log();
|
|
1698
|
+
// Build modification plans based on metrics
|
|
1699
|
+
const plans = [];
|
|
1700
|
+
// Read current config values to build correct search strings
|
|
1701
|
+
const fs = await import('fs');
|
|
1702
|
+
const path = await import('path');
|
|
1703
|
+
const srcDir = path.join(process.cwd(), 'src');
|
|
1704
|
+
// If memory reuse is low, increase anticipation depth
|
|
1705
|
+
if (memoryReuse < 0.5) {
|
|
1706
|
+
try {
|
|
1707
|
+
const workspaceFile = path.join(srcDir, 'memory/cognitive-workspace.ts');
|
|
1708
|
+
const content = fs.readFileSync(workspaceFile, 'utf-8');
|
|
1709
|
+
const match = content.match(/anticipationDepth:\s*(\d+)/);
|
|
1710
|
+
if (match) {
|
|
1711
|
+
const current = parseInt(match[1]);
|
|
1712
|
+
const newValue = Math.min(current + 2, 15);
|
|
1713
|
+
plans.push({
|
|
1714
|
+
id: `improve-anticipation-${Date.now()}`,
|
|
1715
|
+
name: 'Increase memory anticipation for better reuse',
|
|
1716
|
+
description: `Memory reuse is ${(memoryReuse * 100).toFixed(1)}%, increasing anticipation depth`,
|
|
1717
|
+
modifications: [{
|
|
1718
|
+
id: 'anticipation-boost',
|
|
1719
|
+
description: `Increase anticipationDepth from ${current} to ${newValue}`,
|
|
1720
|
+
targetFile: 'memory/cognitive-workspace.ts',
|
|
1721
|
+
type: 'replace',
|
|
1722
|
+
search: `anticipationDepth: ${current},`,
|
|
1723
|
+
content: `anticipationDepth: ${newValue}, // Self-improved: reuse was ${(memoryReuse * 100).toFixed(0)}%`,
|
|
1724
|
+
reason: 'Low memory reuse indicates insufficient pre-loading',
|
|
1725
|
+
expectedImprovement: '+20% memory reuse',
|
|
1726
|
+
}],
|
|
1727
|
+
createdAt: new Date(),
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
catch { /* File read error, skip this improvement */ }
|
|
1732
|
+
}
|
|
1733
|
+
// If Φ is low, increase inference iterations
|
|
1734
|
+
if (phi < 0.4) {
|
|
1735
|
+
try {
|
|
1736
|
+
const typesFile = path.join(srcDir, 'active-inference/types.ts');
|
|
1737
|
+
const content = fs.readFileSync(typesFile, 'utf-8');
|
|
1738
|
+
const match = content.match(/inferenceIterations:\s*(\d+)/);
|
|
1739
|
+
if (match) {
|
|
1740
|
+
const current = parseInt(match[1]);
|
|
1741
|
+
const newValue = Math.min(current + 4, 48);
|
|
1742
|
+
plans.push({
|
|
1743
|
+
id: `improve-inference-${Date.now()}`,
|
|
1744
|
+
name: 'Increase inference depth for better consciousness',
|
|
1745
|
+
description: `Φ is ${phi.toFixed(3)}, increasing inference iterations`,
|
|
1746
|
+
modifications: [{
|
|
1747
|
+
id: 'inference-boost',
|
|
1748
|
+
description: `Increase inferenceIterations from ${current} to ${newValue}`,
|
|
1749
|
+
targetFile: 'active-inference/types.ts',
|
|
1750
|
+
type: 'replace',
|
|
1751
|
+
search: `inferenceIterations: ${current},`,
|
|
1752
|
+
content: `inferenceIterations: ${newValue}, // Self-improved: Φ was ${phi.toFixed(2)}`,
|
|
1753
|
+
reason: 'Low Φ indicates insufficient belief convergence',
|
|
1754
|
+
expectedImprovement: '+15% consciousness level',
|
|
1755
|
+
}],
|
|
1756
|
+
createdAt: new Date(),
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
catch { /* File read error, skip this improvement */ }
|
|
1695
1761
|
}
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
console.log((0, ui_js_1.muted)('No critical or high priority improvements. Skipping.'));
|
|
1762
|
+
if (plans.length === 0) {
|
|
1763
|
+
console.log((0, ui_js_1.success)('✓ System metrics are healthy. No improvements needed.'));
|
|
1764
|
+
console.log((0, ui_js_1.muted)(` Memory reuse: ${(memoryReuse * 100).toFixed(1)}% (threshold: 50%)`));
|
|
1765
|
+
console.log((0, ui_js_1.muted)(` Φ: ${phi.toFixed(3)} (threshold: 0.4)`));
|
|
1701
1766
|
return;
|
|
1702
1767
|
}
|
|
1703
|
-
console.log((0, ui_js_1.warning)(
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
console.log(
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1768
|
+
console.log((0, ui_js_1.warning)(`Found ${plans.length} potential improvement(s):`));
|
|
1769
|
+
for (const plan of plans) {
|
|
1770
|
+
console.log(` • ${plan.name}`);
|
|
1771
|
+
}
|
|
1772
|
+
console.log();
|
|
1773
|
+
// Apply each plan via Darwin-Gödel
|
|
1774
|
+
let applied = 0;
|
|
1775
|
+
for (const plan of plans) {
|
|
1776
|
+
console.log((0, ui_js_1.info)(`Applying: ${plan.name}...`));
|
|
1777
|
+
try {
|
|
1778
|
+
const result = await this.darwinGodel.apply(plan);
|
|
1779
|
+
if (result.success) {
|
|
1780
|
+
console.log((0, ui_js_1.success)(` ✓ Applied! Commit: ${result.commitHash?.slice(0, 8)}`));
|
|
1781
|
+
applied++;
|
|
1782
|
+
}
|
|
1783
|
+
else {
|
|
1784
|
+
console.log((0, ui_js_1.warning)(` ✗ Failed: ${result.verificaton.errors[0] || 'Unknown error'}`));
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
catch (err) {
|
|
1788
|
+
console.log((0, ui_js_1.error)(` ✗ Error: ${err instanceof Error ? err.message : err}`));
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
console.log();
|
|
1792
|
+
if (applied > 0) {
|
|
1793
|
+
console.log((0, ui_js_1.success)(`✓ Self-improvement complete! Applied ${applied}/${plans.length} modifications.`));
|
|
1794
|
+
console.log((0, ui_js_1.muted)(' Changes committed to git. Use `git log` to see history.'));
|
|
1722
1795
|
}
|
|
1723
1796
|
else {
|
|
1724
|
-
console.log((0, ui_js_1.warning)('
|
|
1797
|
+
console.log((0, ui_js_1.warning)('No modifications were applied.'));
|
|
1725
1798
|
}
|
|
1726
1799
|
console.log();
|
|
1727
1800
|
}
|
package/dist/src/llm/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export * from './router.js';
|
|
13
13
|
export type LLMProvider = 'ollama' | 'openai' | 'anthropic';
|
|
14
|
+
export type ModelTier = 'fast' | 'balanced' | 'powerful';
|
|
15
|
+
export declare const MODEL_TIERS: Record<LLMProvider, Record<ModelTier, string>>;
|
|
14
16
|
export declare const OLLAMA_CONFIG: {
|
|
15
17
|
baseUrl: string;
|
|
16
18
|
defaultModel: string;
|
|
@@ -86,6 +88,7 @@ export declare const GENESIS_SYSTEM_PROMPT = "# Genesis System\n\nYou are Genesi
|
|
|
86
88
|
export declare class LLMBridge {
|
|
87
89
|
private config;
|
|
88
90
|
private conversationHistory;
|
|
91
|
+
private useCache;
|
|
89
92
|
constructor(config?: Partial<LLMConfig>);
|
|
90
93
|
private detectProvider;
|
|
91
94
|
private detectApiKey;
|
|
@@ -94,8 +97,11 @@ export declare class LLMBridge {
|
|
|
94
97
|
* Check if Ollama is running
|
|
95
98
|
*/
|
|
96
99
|
isOllamaAvailable(): Promise<boolean>;
|
|
100
|
+
private fallbackAttempts;
|
|
101
|
+
private static readonly MAX_FALLBACK_ATTEMPTS;
|
|
97
102
|
/**
|
|
98
103
|
* Send a message and get a response
|
|
104
|
+
* Fallback chain: Anthropic -> OpenAI -> Ollama (max 3 attempts)
|
|
99
105
|
*/
|
|
100
106
|
chat(userMessage: string, systemPrompt?: string): Promise<LLMResponse>;
|
|
101
107
|
/**
|
|
@@ -127,6 +133,13 @@ export declare class LLMBridge {
|
|
|
127
133
|
* Check if API key is configured (or Ollama available)
|
|
128
134
|
*/
|
|
129
135
|
isConfigured(): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* v7.18: Chat with specific model tier for cost optimization
|
|
138
|
+
* - fast: GPT-4o-mini/Haiku - 17x cheaper, good for simple tasks
|
|
139
|
+
* - balanced: GPT-4o/Sonnet - default quality
|
|
140
|
+
* - powerful: Best available model
|
|
141
|
+
*/
|
|
142
|
+
chatWithTier(userMessage: string, tier?: ModelTier, systemPrompt?: string): Promise<LLMResponse>;
|
|
130
143
|
/**
|
|
131
144
|
* Get provider status
|
|
132
145
|
*/
|
|
@@ -136,6 +149,22 @@ export declare class LLMBridge {
|
|
|
136
149
|
model: string;
|
|
137
150
|
isLocal: boolean;
|
|
138
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* v7.18: Get cache statistics for cost monitoring
|
|
154
|
+
*/
|
|
155
|
+
getCacheStats(): {
|
|
156
|
+
size: number;
|
|
157
|
+
hits: number;
|
|
158
|
+
estimatedSavings: number;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* v7.18: Enable/disable response caching
|
|
162
|
+
*/
|
|
163
|
+
setCache(enabled: boolean): void;
|
|
164
|
+
/**
|
|
165
|
+
* v7.18: Clear the response cache
|
|
166
|
+
*/
|
|
167
|
+
clearCache(): void;
|
|
139
168
|
/**
|
|
140
169
|
* List available Ollama models
|
|
141
170
|
*/
|