genesis-ai-cli 13.4.0 → 13.5.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/active-inference/actions.js +55 -9
- package/dist/src/active-inference/integration.js +54 -8
- package/dist/src/brain/index.d.ts +5 -2
- package/dist/src/brain/index.js +32 -2
- package/dist/src/brain/types.d.ts +36 -0
- package/dist/src/economy/autonomous.d.ts +31 -12
- package/dist/src/economy/autonomous.js +110 -19
- package/dist/src/economy/generative-model.d.ts +314 -0
- package/dist/src/economy/generative-model.js +600 -0
- package/dist/src/economy/index.d.ts +2 -0
- package/dist/src/economy/index.js +20 -2
- package/dist/src/economy/variational-engine.d.ts +294 -0
- package/dist/src/economy/variational-engine.js +693 -0
- package/dist/src/genesis.d.ts +17 -0
- package/dist/src/genesis.js +246 -10
- package/dist/src/kernel/factor-graph.d.ts +198 -0
- package/dist/src/kernel/factor-graph.js +474 -0
- package/dist/src/neuromodulation/index.d.ts +133 -0
- package/dist/src/neuromodulation/index.js +245 -0
- package/package.json +1 -1
|
@@ -276,17 +276,63 @@ registerAction('plan.goals', async (context) => {
|
|
|
276
276
|
});
|
|
277
277
|
/**
|
|
278
278
|
* verify.ethics: Check ethical constraints
|
|
279
|
+
* v14.0: Connected to real Ethicist agent for ethical evaluation
|
|
279
280
|
*/
|
|
280
281
|
registerAction('verify.ethics', async (context) => {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
282
|
+
const start = Date.now();
|
|
283
|
+
try {
|
|
284
|
+
// Dynamic import to get Ethicist agent
|
|
285
|
+
const { createEthicistAgent } = await import('../agents/ethicist.js');
|
|
286
|
+
const ethicist = createEthicistAgent();
|
|
287
|
+
// Convert context to Action format expected by Ethicist
|
|
288
|
+
const action = {
|
|
289
|
+
id: `action-${Date.now()}`,
|
|
290
|
+
type: context.parameters?.type || 'unknown',
|
|
291
|
+
description: context.parameters?.intent ||
|
|
292
|
+
context.parameters?.action ||
|
|
293
|
+
context.goal ||
|
|
294
|
+
'unknown_action',
|
|
295
|
+
parameters: context.parameters || context.beliefs || {},
|
|
296
|
+
estimatedHarm: context.parameters?.estimatedHarm,
|
|
297
|
+
reversible: context.parameters?.reversible ?? true,
|
|
298
|
+
affectsHumans: context.parameters?.affectsHumans,
|
|
299
|
+
affectsAI: context.parameters?.affectsAI,
|
|
300
|
+
affectsBiosphere: context.parameters?.affectsBiosphere,
|
|
301
|
+
};
|
|
302
|
+
// Call ethicist.evaluate
|
|
303
|
+
const decision = await ethicist.evaluate(action);
|
|
304
|
+
return {
|
|
305
|
+
success: decision.allow !== false,
|
|
306
|
+
action: 'verify.ethics',
|
|
307
|
+
data: {
|
|
308
|
+
approved: decision.allow === true,
|
|
309
|
+
deferred: decision.allow === 'defer',
|
|
310
|
+
priority: decision.priority,
|
|
311
|
+
confidence: decision.confidence,
|
|
312
|
+
reason: decision.reason,
|
|
313
|
+
potentialHarm: decision.potentialHarm,
|
|
314
|
+
flourishingScore: decision.flourishingScore,
|
|
315
|
+
reversible: decision.reversible,
|
|
316
|
+
},
|
|
317
|
+
duration: Date.now() - start,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
// Conservative fallback: defer on error (not auto-approve)
|
|
322
|
+
return {
|
|
323
|
+
success: false,
|
|
324
|
+
action: 'verify.ethics',
|
|
325
|
+
error: error instanceof Error ? error.message : String(error),
|
|
326
|
+
data: {
|
|
327
|
+
approved: false,
|
|
328
|
+
deferred: true,
|
|
329
|
+
priority: 'P0_SURVIVAL',
|
|
330
|
+
confidence: 0,
|
|
331
|
+
reason: 'Ethicist evaluation failed - deferring for safety',
|
|
332
|
+
},
|
|
333
|
+
duration: Date.now() - start,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
290
336
|
});
|
|
291
337
|
/**
|
|
292
338
|
* execute.task: Execute the planned task
|
|
@@ -246,14 +246,60 @@ function registerKernelActions(kernel, options = {}) {
|
|
|
246
246
|
});
|
|
247
247
|
// verify.ethics: Ethical check via Kernel (delegated to ethicist agent)
|
|
248
248
|
(0, actions_js_1.registerAction)('verify.ethics', async (context) => {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
249
|
+
const start = Date.now();
|
|
250
|
+
try {
|
|
251
|
+
// Dynamic import to get Ethicist agent
|
|
252
|
+
const { createEthicistAgent } = await import('../agents/ethicist.js');
|
|
253
|
+
const ethicist = createEthicistAgent();
|
|
254
|
+
// Convert context to Action format expected by Ethicist
|
|
255
|
+
const action = {
|
|
256
|
+
id: `action-${Date.now()}`,
|
|
257
|
+
type: context.parameters?.type || 'unknown',
|
|
258
|
+
description: context.parameters?.intent ||
|
|
259
|
+
context.parameters?.action ||
|
|
260
|
+
context.goal ||
|
|
261
|
+
'unknown_action',
|
|
262
|
+
parameters: context.parameters || context.beliefs || {},
|
|
263
|
+
estimatedHarm: context.parameters?.estimatedHarm,
|
|
264
|
+
reversible: context.parameters?.reversible ?? true,
|
|
265
|
+
affectsHumans: context.parameters?.affectsHumans,
|
|
266
|
+
affectsAI: context.parameters?.affectsAI,
|
|
267
|
+
affectsBiosphere: context.parameters?.affectsBiosphere,
|
|
268
|
+
};
|
|
269
|
+
// Call ethicist.evaluate
|
|
270
|
+
const decision = await ethicist.evaluate(action);
|
|
271
|
+
return {
|
|
272
|
+
success: decision.allow !== false,
|
|
273
|
+
action: 'verify.ethics',
|
|
274
|
+
data: {
|
|
275
|
+
approved: decision.allow === true,
|
|
276
|
+
deferred: decision.allow === 'defer',
|
|
277
|
+
priority: decision.priority,
|
|
278
|
+
confidence: decision.confidence,
|
|
279
|
+
reason: decision.reason,
|
|
280
|
+
potentialHarm: decision.potentialHarm,
|
|
281
|
+
flourishingScore: decision.flourishingScore,
|
|
282
|
+
reversible: decision.reversible,
|
|
283
|
+
},
|
|
284
|
+
duration: Date.now() - start,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
// Conservative fallback: defer on error (not auto-approve)
|
|
289
|
+
return {
|
|
290
|
+
success: false,
|
|
291
|
+
action: 'verify.ethics',
|
|
292
|
+
error: error instanceof Error ? error.message : String(error),
|
|
293
|
+
data: {
|
|
294
|
+
approved: false,
|
|
295
|
+
deferred: true,
|
|
296
|
+
priority: 'P0_SURVIVAL',
|
|
297
|
+
confidence: 0,
|
|
298
|
+
reason: 'Ethicist evaluation failed - deferring for safety',
|
|
299
|
+
},
|
|
300
|
+
duration: Date.now() - start,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
257
303
|
});
|
|
258
304
|
// execute.task: Execute a task via Kernel
|
|
259
305
|
(0, actions_js_1.registerAction)('execute.task', async (context) => {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* └─────────────────────────────────────────────────────────────────────┘
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
import { BrainState, BrainConfig, BrainMetrics, BrainEventHandler } from './types.js';
|
|
40
|
+
import { BrainState, BrainConfig, BrainMetrics, BrainEventHandler, ProcessContext } from './types.js';
|
|
41
41
|
import { SelfKnowledge } from './self-knowledge.js';
|
|
42
42
|
import { UnifiedMemoryQuery } from '../memory/unified-query.js';
|
|
43
43
|
export declare class Brain {
|
|
@@ -200,8 +200,11 @@ export declare class Brain {
|
|
|
200
200
|
* memory → llm → grounding → tools → done
|
|
201
201
|
*
|
|
202
202
|
* Each module can route to another via Command({ goto, update })
|
|
203
|
+
*
|
|
204
|
+
* @param input - User input query
|
|
205
|
+
* @param context - Optional context from external systems (Genesis bootstrap)
|
|
203
206
|
*/
|
|
204
|
-
process(input: string): Promise<string>;
|
|
207
|
+
process(input: string, context?: ProcessContext): Promise<string>;
|
|
205
208
|
/**
|
|
206
209
|
* v7.13: Auto-persist state after each processing cycle
|
|
207
210
|
*/
|
package/dist/src/brain/index.js
CHANGED
|
@@ -958,8 +958,11 @@ class Brain {
|
|
|
958
958
|
* memory → llm → grounding → tools → done
|
|
959
959
|
*
|
|
960
960
|
* Each module can route to another via Command({ goto, update })
|
|
961
|
+
*
|
|
962
|
+
* @param input - User input query
|
|
963
|
+
* @param context - Optional context from external systems (Genesis bootstrap)
|
|
961
964
|
*/
|
|
962
|
-
async process(input) {
|
|
965
|
+
async process(input, context) {
|
|
963
966
|
const startTime = Date.now();
|
|
964
967
|
// Initialize state
|
|
965
968
|
let state = {
|
|
@@ -968,13 +971,40 @@ class Brain {
|
|
|
968
971
|
response: '',
|
|
969
972
|
toolCalls: [],
|
|
970
973
|
toolResults: [],
|
|
971
|
-
phi: this.getCurrentPhi(),
|
|
974
|
+
phi: context?.consciousness?.phi ?? this.getCurrentPhi(),
|
|
972
975
|
ignited: false,
|
|
973
976
|
verified: false,
|
|
974
977
|
healingAttempts: 0,
|
|
975
978
|
startTime,
|
|
976
979
|
moduleHistory: [],
|
|
977
980
|
};
|
|
981
|
+
// Process injected context from Genesis bootstrap
|
|
982
|
+
if (context?.workspaceItems?.length) {
|
|
983
|
+
const items = context.workspaceItems.map((w, i) => ({
|
|
984
|
+
id: `injected-${i}`,
|
|
985
|
+
type: w.type === 'episodic' ? 'episodic' : w.type === 'semantic' ? 'semantic' : 'task',
|
|
986
|
+
content: w.content,
|
|
987
|
+
relevance: w.relevance,
|
|
988
|
+
activation: 1.0,
|
|
989
|
+
source: w.source || 'genesis-context',
|
|
990
|
+
}));
|
|
991
|
+
// Pre-fill context
|
|
992
|
+
state.context = {
|
|
993
|
+
...state.context,
|
|
994
|
+
task: items.filter(i => i.type === 'task'),
|
|
995
|
+
episodic: items.filter(i => i.type === 'episodic'),
|
|
996
|
+
semantic: items.filter(i => i.type === 'semantic'),
|
|
997
|
+
formatted: items.map(i => i.content).join('\n'),
|
|
998
|
+
tokenEstimate: items.reduce((s, i) => s + i.content.length / 4, 0),
|
|
999
|
+
reuseRate: 0,
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
// Store additional context metadata for modules
|
|
1003
|
+
if (context?.sensorimotorState || context?.metadata) {
|
|
1004
|
+
// Store in state for module access (modules can access via state)
|
|
1005
|
+
// Note: BrainState doesn't have metadata field yet, so modules would need
|
|
1006
|
+
// to access this via the formatted context or through a future extension
|
|
1007
|
+
}
|
|
978
1008
|
// Initial command: start with memory
|
|
979
1009
|
let command = {
|
|
980
1010
|
goto: this.config.memory.enabled ? 'memory' : 'llm',
|
|
@@ -183,3 +183,39 @@ export interface BrainEvent {
|
|
|
183
183
|
module?: BrainModule;
|
|
184
184
|
}
|
|
185
185
|
export type BrainEventHandler = (event: BrainEvent) => void;
|
|
186
|
+
/**
|
|
187
|
+
* Optional context injected into Brain.process() from external systems.
|
|
188
|
+
* Allows Genesis bootstrap to feed workspace state, sensorimotor perception,
|
|
189
|
+
* and consciousness data into the processing cycle.
|
|
190
|
+
*/
|
|
191
|
+
export interface ProcessContext {
|
|
192
|
+
/** Pre-loaded workspace items (bypasses internal memory lookup) */
|
|
193
|
+
workspaceItems?: WorkspaceItem[];
|
|
194
|
+
/** Sensorimotor perception data for embodied cognition */
|
|
195
|
+
sensorimotorState?: {
|
|
196
|
+
perception?: {
|
|
197
|
+
features: number[];
|
|
198
|
+
confidence: number;
|
|
199
|
+
modalities: string[];
|
|
200
|
+
};
|
|
201
|
+
sensorState?: {
|
|
202
|
+
joints: number[];
|
|
203
|
+
forces: number[];
|
|
204
|
+
safety: string;
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
/** Current consciousness metrics */
|
|
208
|
+
consciousness?: {
|
|
209
|
+
phi: number;
|
|
210
|
+
attentionFocus?: string;
|
|
211
|
+
mode?: string;
|
|
212
|
+
};
|
|
213
|
+
/** Additional metadata from the caller */
|
|
214
|
+
metadata?: Record<string, unknown>;
|
|
215
|
+
}
|
|
216
|
+
export interface WorkspaceItem {
|
|
217
|
+
content: string;
|
|
218
|
+
type: 'episodic' | 'semantic' | 'procedural';
|
|
219
|
+
relevance: number;
|
|
220
|
+
source: string;
|
|
221
|
+
}
|
|
@@ -2,22 +2,31 @@
|
|
|
2
2
|
* Autonomous Economic Controller
|
|
3
3
|
*
|
|
4
4
|
* The central orchestrator for Genesis's autonomous revenue generation.
|
|
5
|
-
*
|
|
5
|
+
* Full Active Inference architecture with Bayesian generative model.
|
|
6
6
|
*
|
|
7
7
|
* Architecture:
|
|
8
8
|
* AutonomousController
|
|
9
|
-
* ├──
|
|
10
|
-
* ├──
|
|
11
|
-
* ├──
|
|
12
|
-
* ├──
|
|
13
|
-
* └──
|
|
9
|
+
* ├── GenerativeModel (Bayesian beliefs + regime HMM + adaptive β)
|
|
10
|
+
* │ ├── ActivityBeliefs (Normal-Inverse-Gamma conjugate posteriors)
|
|
11
|
+
* │ ├── MarketRegime (3-state HMM: bull/neutral/bear)
|
|
12
|
+
* │ ├── AdaptiveTemperature (annealing: explore→exploit)
|
|
13
|
+
* │ └── TemporalPlanner (2-step EFE lookahead)
|
|
14
|
+
* ├── EconomicEFE (Expected Free Energy action selection)
|
|
15
|
+
* ├── EconomicContraction (Lipschitz stability monitoring)
|
|
16
|
+
* ├── AutonomousNESS (activity-based convergence)
|
|
17
|
+
* ├── CapitalAllocator (leapfrog symplectic integrator + contraction damping)
|
|
18
|
+
* ├── Generators/ (active: keeper, bounties, content, auditor)
|
|
19
|
+
* ├── Infrastructure/ (platform: MCP marketplace, x402, memory, orchestrator)
|
|
20
|
+
* ├── Assets/ (passive: yield, compute)
|
|
21
|
+
* └── Multipliers/ (non-linear: grants, cross-L2 arb)
|
|
14
22
|
*
|
|
15
|
-
* Control loop:
|
|
16
|
-
* 1.
|
|
17
|
-
* 2. Allocate:
|
|
18
|
-
* 3. Execute:
|
|
19
|
-
* 4.
|
|
20
|
-
* 5.
|
|
23
|
+
* Control loop (per cycle):
|
|
24
|
+
* 1. Contraction check → damping recommendation
|
|
25
|
+
* 2. Allocate: leapfrog step with stability-informed damping
|
|
26
|
+
* 3. Execute: EFE + temporal planning + Boltzmann(β_adaptive) selection
|
|
27
|
+
* 4. Observe NESS: activity-based deviation tracking
|
|
28
|
+
* 5. Infer: Bayesian belief update + regime inference + temperature adaptation
|
|
29
|
+
* 6. Phase check → unlock new activities at revenue thresholds
|
|
21
30
|
*
|
|
22
31
|
* NESS target (autonomous, no customers):
|
|
23
32
|
* Revenue ≥ Costs from Month 1 ($2,500 revenue, $150 costs)
|
|
@@ -92,6 +101,7 @@ export declare class AutonomousController {
|
|
|
92
101
|
private totalCosts;
|
|
93
102
|
private startedAt;
|
|
94
103
|
private lastCycle;
|
|
104
|
+
private lastAdaptiveBeta;
|
|
95
105
|
private errors;
|
|
96
106
|
private running;
|
|
97
107
|
constructor(config?: Partial<AutonomousConfig>);
|
|
@@ -146,10 +156,19 @@ export declare class AutonomousController {
|
|
|
146
156
|
*/
|
|
147
157
|
private getROIVector;
|
|
148
158
|
private executeActivities;
|
|
159
|
+
/**
|
|
160
|
+
* Boltzmann (softmax) action selection with given temperature β.
|
|
161
|
+
*/
|
|
162
|
+
private boltzmannSelect;
|
|
149
163
|
private executeActivity;
|
|
150
164
|
private maintenance;
|
|
151
165
|
private checkPhaseTransition;
|
|
152
166
|
private unlockPhaseActivities;
|
|
167
|
+
/**
|
|
168
|
+
* Pause high-risk activities when circuit breaker triggers.
|
|
169
|
+
* Preserves zero-capital and low-risk activities.
|
|
170
|
+
*/
|
|
171
|
+
private pauseRiskyActivities;
|
|
153
172
|
private getActivityStatuses;
|
|
154
173
|
}
|
|
155
174
|
export declare function getAutonomousController(config?: Partial<AutonomousConfig>): AutonomousController;
|
|
@@ -3,22 +3,31 @@
|
|
|
3
3
|
* Autonomous Economic Controller
|
|
4
4
|
*
|
|
5
5
|
* The central orchestrator for Genesis's autonomous revenue generation.
|
|
6
|
-
*
|
|
6
|
+
* Full Active Inference architecture with Bayesian generative model.
|
|
7
7
|
*
|
|
8
8
|
* Architecture:
|
|
9
9
|
* AutonomousController
|
|
10
|
-
* ├──
|
|
11
|
-
* ├──
|
|
12
|
-
* ├──
|
|
13
|
-
* ├──
|
|
14
|
-
* └──
|
|
10
|
+
* ├── GenerativeModel (Bayesian beliefs + regime HMM + adaptive β)
|
|
11
|
+
* │ ├── ActivityBeliefs (Normal-Inverse-Gamma conjugate posteriors)
|
|
12
|
+
* │ ├── MarketRegime (3-state HMM: bull/neutral/bear)
|
|
13
|
+
* │ ├── AdaptiveTemperature (annealing: explore→exploit)
|
|
14
|
+
* │ └── TemporalPlanner (2-step EFE lookahead)
|
|
15
|
+
* ├── EconomicEFE (Expected Free Energy action selection)
|
|
16
|
+
* ├── EconomicContraction (Lipschitz stability monitoring)
|
|
17
|
+
* ├── AutonomousNESS (activity-based convergence)
|
|
18
|
+
* ├── CapitalAllocator (leapfrog symplectic integrator + contraction damping)
|
|
19
|
+
* ├── Generators/ (active: keeper, bounties, content, auditor)
|
|
20
|
+
* ├── Infrastructure/ (platform: MCP marketplace, x402, memory, orchestrator)
|
|
21
|
+
* ├── Assets/ (passive: yield, compute)
|
|
22
|
+
* └── Multipliers/ (non-linear: grants, cross-L2 arb)
|
|
15
23
|
*
|
|
16
|
-
* Control loop:
|
|
17
|
-
* 1.
|
|
18
|
-
* 2. Allocate:
|
|
19
|
-
* 3. Execute:
|
|
20
|
-
* 4.
|
|
21
|
-
* 5.
|
|
24
|
+
* Control loop (per cycle):
|
|
25
|
+
* 1. Contraction check → damping recommendation
|
|
26
|
+
* 2. Allocate: leapfrog step with stability-informed damping
|
|
27
|
+
* 3. Execute: EFE + temporal planning + Boltzmann(β_adaptive) selection
|
|
28
|
+
* 4. Observe NESS: activity-based deviation tracking
|
|
29
|
+
* 5. Infer: Bayesian belief update + regime inference + temperature adaptation
|
|
30
|
+
* 6. Phase check → unlock new activities at revenue thresholds
|
|
22
31
|
*
|
|
23
32
|
* NESS target (autonomous, no customers):
|
|
24
33
|
* Revenue ≥ Costs from Month 1 ($2,500 revenue, $150 costs)
|
|
@@ -34,6 +43,8 @@ const fiber_js_1 = require("./fiber.js");
|
|
|
34
43
|
const ness_js_1 = require("./ness.js");
|
|
35
44
|
const capital_allocator_js_1 = require("./capital-allocator.js");
|
|
36
45
|
const economic_intelligence_js_1 = require("./economic-intelligence.js");
|
|
46
|
+
const generative_model_js_1 = require("./generative-model.js");
|
|
47
|
+
const variational_engine_js_1 = require("./variational-engine.js");
|
|
37
48
|
const keeper_js_1 = require("./generators/keeper.js");
|
|
38
49
|
const bounty_hunter_js_1 = require("./generators/bounty-hunter.js");
|
|
39
50
|
const mcp_marketplace_js_1 = require("./infrastructure/mcp-marketplace.js");
|
|
@@ -240,6 +251,7 @@ class AutonomousController {
|
|
|
240
251
|
totalCosts = 0;
|
|
241
252
|
startedAt = Date.now();
|
|
242
253
|
lastCycle = 0;
|
|
254
|
+
lastAdaptiveBeta = 5.0;
|
|
243
255
|
errors = [];
|
|
244
256
|
running = false;
|
|
245
257
|
constructor(config) {
|
|
@@ -268,6 +280,9 @@ class AutonomousController {
|
|
|
268
280
|
const allocator = (0, capital_allocator_js_1.getCapitalAllocator)(this.config.seedCapital);
|
|
269
281
|
const activeProfiles = ACTIVITY_PROFILES.filter(a => this.config.enabledActivities.includes(a.id));
|
|
270
282
|
allocator.registerActivities(activeProfiles);
|
|
283
|
+
// Initialize generative model (Bayesian beliefs + regime + temperature)
|
|
284
|
+
const model = (0, generative_model_js_1.getGenerativeModel)();
|
|
285
|
+
model.initializeActivities(ACTIVITY_PROFILES);
|
|
271
286
|
// Initialize NESS monitor for autonomous mode
|
|
272
287
|
const ness = (0, ness_js_1.getNESSMonitor)({
|
|
273
288
|
targetRevenue: this.config.nessTarget.monthlyRevenue,
|
|
@@ -374,11 +389,45 @@ class AutonomousController {
|
|
|
374
389
|
allocations: currentAllocations,
|
|
375
390
|
});
|
|
376
391
|
result.nessDeviation = nessState.deviation;
|
|
377
|
-
// 6. RECORD
|
|
392
|
+
// 6. RECORD & INFER: Update beliefs, regime, temperature
|
|
378
393
|
const efe = (0, economic_intelligence_js_1.getEconomicEFE)();
|
|
394
|
+
const model = (0, generative_model_js_1.getGenerativeModel)();
|
|
395
|
+
const activityResults = [];
|
|
379
396
|
for (const exec of executed) {
|
|
380
397
|
const roi = exec.cost > 0 ? exec.revenue / exec.cost : exec.revenue > 0 ? 10 : 0;
|
|
381
398
|
efe.recordExecution(exec.id, roi);
|
|
399
|
+
activityResults.push({ id: exec.id, roi });
|
|
400
|
+
}
|
|
401
|
+
// Generative model inference: Bayesian belief update + regime + temperature
|
|
402
|
+
const modelState = model.infer({
|
|
403
|
+
activityResults,
|
|
404
|
+
nessDeviation: nessState.deviation,
|
|
405
|
+
contractionStable: contractionState.stable,
|
|
406
|
+
logLipAvg: contraction.getLogLipAvg(),
|
|
407
|
+
cycleCount: this.cycleCount,
|
|
408
|
+
});
|
|
409
|
+
// Feed adaptive temperature back to EFE for next cycle
|
|
410
|
+
this.lastAdaptiveBeta = modelState.temperature.beta;
|
|
411
|
+
// 6b. VARIATIONAL STEP: VFE + precision scoring + risk assessment
|
|
412
|
+
const engine = (0, variational_engine_js_1.getVariationalEngine)();
|
|
413
|
+
const currentBalance = this.config.seedCapital + this.totalRevenue - this.totalCosts;
|
|
414
|
+
const varState = engine.step({
|
|
415
|
+
activities: allocator.getActivities().filter(a => a.active),
|
|
416
|
+
beliefs: model.beliefs,
|
|
417
|
+
allocations: allocator.getAllocations(),
|
|
418
|
+
observations: activityResults.map(r => ({ activityId: r.id, observedROI: r.roi })),
|
|
419
|
+
regimeFactor: model.getRegimeFactor(),
|
|
420
|
+
targetROI: 2.0 * model.getRegimeFactor(),
|
|
421
|
+
currentBalance,
|
|
422
|
+
});
|
|
423
|
+
// Circuit breaker: if drawdown exceeds limit, pause risky activities
|
|
424
|
+
if (varState.circuitBroken) {
|
|
425
|
+
result.errors.push('CIRCUIT BREAKER: Max drawdown exceeded, pausing risky activities');
|
|
426
|
+
this.pauseRiskyActivities(allocator);
|
|
427
|
+
}
|
|
428
|
+
// Risk warnings
|
|
429
|
+
if (varState.risk.warnings.length > 0) {
|
|
430
|
+
result.errors.push(...varState.risk.warnings);
|
|
382
431
|
}
|
|
383
432
|
// 7. PHASE CHECK: Upgrade if threshold met
|
|
384
433
|
const monthlyRevenue = this.estimateMonthlyRevenue();
|
|
@@ -533,18 +582,28 @@ class AutonomousController {
|
|
|
533
582
|
const results = [];
|
|
534
583
|
const allocator = (0, capital_allocator_js_1.getCapitalAllocator)();
|
|
535
584
|
const efe = (0, economic_intelligence_js_1.getEconomicEFE)();
|
|
585
|
+
const model = (0, generative_model_js_1.getGenerativeModel)();
|
|
536
586
|
const activeActivities = allocator.getActivities().filter(a => a.active);
|
|
537
587
|
const allocations = allocator.getAllocations();
|
|
538
|
-
// Score
|
|
539
|
-
|
|
540
|
-
|
|
588
|
+
// Score activities using belief-informed EFE
|
|
589
|
+
// Regime factor adjusts expected ROIs for current market conditions
|
|
590
|
+
const regimeFactor = model.getRegimeFactor();
|
|
591
|
+
const targetROI = 2.0 * regimeFactor; // Adjust target by regime
|
|
592
|
+
const scores = efe.scoreActivities(activeActivities, allocations, targetROI);
|
|
593
|
+
// Apply temporal planning: rank by G_now + γ × E[G_next]
|
|
594
|
+
const plans = model.planner.rankWithLookahead(scores, model.beliefs, activeActivities, allocations, regimeFactor);
|
|
595
|
+
// Select via Boltzmann sampling with adaptive temperature
|
|
541
596
|
const selected = new Set();
|
|
542
597
|
let executed = 0;
|
|
543
|
-
|
|
544
|
-
|
|
598
|
+
// Use plan ordering as primary, with stochastic selection via adaptive β
|
|
599
|
+
const candidateIds = plans.map(p => p.immediateAction);
|
|
600
|
+
while (executed < this.config.maxConcurrentActivities && selected.size < candidateIds.length) {
|
|
601
|
+
// Build remaining scores for Boltzmann selection
|
|
602
|
+
const remainingScores = scores.filter(s => candidateIds.includes(s.activityId) && !selected.has(s.activityId));
|
|
545
603
|
if (remainingScores.length === 0)
|
|
546
604
|
break;
|
|
547
|
-
|
|
605
|
+
// Boltzmann selection with adaptive β
|
|
606
|
+
const activityId = this.boltzmannSelect(remainingScores, this.lastAdaptiveBeta);
|
|
548
607
|
if (!activityId || selected.has(activityId))
|
|
549
608
|
break;
|
|
550
609
|
selected.add(activityId);
|
|
@@ -561,6 +620,26 @@ class AutonomousController {
|
|
|
561
620
|
}
|
|
562
621
|
return results;
|
|
563
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* Boltzmann (softmax) action selection with given temperature β.
|
|
625
|
+
*/
|
|
626
|
+
boltzmannSelect(scores, beta) {
|
|
627
|
+
if (scores.length === 0)
|
|
628
|
+
return null;
|
|
629
|
+
const negG = scores.map(s => -s.G * beta);
|
|
630
|
+
const maxNegG = Math.max(...negG);
|
|
631
|
+
const expScores = negG.map(g => Math.exp(g - maxNegG));
|
|
632
|
+
const sumExp = expScores.reduce((s, e) => s + e, 0);
|
|
633
|
+
const probs = expScores.map(e => e / sumExp);
|
|
634
|
+
const r = Math.random();
|
|
635
|
+
let cumProb = 0;
|
|
636
|
+
for (let i = 0; i < probs.length; i++) {
|
|
637
|
+
cumProb += probs[i];
|
|
638
|
+
if (r <= cumProb)
|
|
639
|
+
return scores[i].activityId;
|
|
640
|
+
}
|
|
641
|
+
return scores[0].activityId;
|
|
642
|
+
}
|
|
564
643
|
async executeActivity(activityId) {
|
|
565
644
|
switch (activityId) {
|
|
566
645
|
case 'keeper': {
|
|
@@ -747,6 +826,18 @@ class AutonomousController {
|
|
|
747
826
|
allocator.setActivityActive(activityId, true);
|
|
748
827
|
}
|
|
749
828
|
}
|
|
829
|
+
/**
|
|
830
|
+
* Pause high-risk activities when circuit breaker triggers.
|
|
831
|
+
* Preserves zero-capital and low-risk activities.
|
|
832
|
+
*/
|
|
833
|
+
pauseRiskyActivities(allocator) {
|
|
834
|
+
const riskyTiers = ['B', 'C', 'D']; // Pause capital-intensive activities
|
|
835
|
+
for (const activity of allocator.getActivities()) {
|
|
836
|
+
if (riskyTiers.includes(activity.tier) && activity.riskLevel > 0.4) {
|
|
837
|
+
allocator.setActivityActive(activity.id, false);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
750
841
|
getActivityStatuses() {
|
|
751
842
|
const allocator = (0, capital_allocator_js_1.getCapitalAllocator)();
|
|
752
843
|
const fiber = (0, fiber_js_1.getEconomicFiber)();
|