genesis-ai-cli 7.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +78 -0
- package/README.md +282 -0
- package/dist/src/active-inference/actions.d.ts +75 -0
- package/dist/src/active-inference/actions.js +250 -0
- package/dist/src/active-inference/autonomous-loop.d.ts +103 -0
- package/dist/src/active-inference/autonomous-loop.js +289 -0
- package/dist/src/active-inference/core.d.ts +85 -0
- package/dist/src/active-inference/core.js +555 -0
- package/dist/src/active-inference/demo-autonomous-loop.d.ts +8 -0
- package/dist/src/active-inference/demo-autonomous-loop.js +338 -0
- package/dist/src/active-inference/demo-value-integration.d.ts +8 -0
- package/dist/src/active-inference/demo-value-integration.js +174 -0
- package/dist/src/active-inference/index.d.ts +32 -0
- package/dist/src/active-inference/index.js +88 -0
- package/dist/src/active-inference/integration.d.ts +114 -0
- package/dist/src/active-inference/integration.js +698 -0
- package/dist/src/active-inference/memory-integration.d.ts +51 -0
- package/dist/src/active-inference/memory-integration.js +232 -0
- package/dist/src/active-inference/observations.d.ts +67 -0
- package/dist/src/active-inference/observations.js +147 -0
- package/dist/src/active-inference/test-active-inference.d.ts +8 -0
- package/dist/src/active-inference/test-active-inference.js +320 -0
- package/dist/src/active-inference/test-value-integration.d.ts +6 -0
- package/dist/src/active-inference/test-value-integration.js +168 -0
- package/dist/src/active-inference/types.d.ts +150 -0
- package/dist/src/active-inference/types.js +59 -0
- package/dist/src/active-inference/value-integration.d.ts +164 -0
- package/dist/src/active-inference/value-integration.js +459 -0
- package/dist/src/agents/base-agent.d.ts +53 -0
- package/dist/src/agents/base-agent.js +178 -0
- package/dist/src/agents/builder.d.ts +67 -0
- package/dist/src/agents/builder.js +537 -0
- package/dist/src/agents/critic.d.ts +35 -0
- package/dist/src/agents/critic.js +322 -0
- package/dist/src/agents/ethicist.d.ts +54 -0
- package/dist/src/agents/ethicist.js +393 -0
- package/dist/src/agents/explorer.d.ts +26 -0
- package/dist/src/agents/explorer.js +216 -0
- package/dist/src/agents/feeling.d.ts +41 -0
- package/dist/src/agents/feeling.js +320 -0
- package/dist/src/agents/index.d.ts +111 -0
- package/dist/src/agents/index.js +222 -0
- package/dist/src/agents/memory.d.ts +69 -0
- package/dist/src/agents/memory.js +404 -0
- package/dist/src/agents/message-bus.d.ts +88 -0
- package/dist/src/agents/message-bus.js +267 -0
- package/dist/src/agents/narrator.d.ts +90 -0
- package/dist/src/agents/narrator.js +473 -0
- package/dist/src/agents/planner.d.ts +38 -0
- package/dist/src/agents/planner.js +341 -0
- package/dist/src/agents/predictor.d.ts +73 -0
- package/dist/src/agents/predictor.js +506 -0
- package/dist/src/agents/sensor.d.ts +88 -0
- package/dist/src/agents/sensor.js +377 -0
- package/dist/src/agents/test-agents.d.ts +6 -0
- package/dist/src/agents/test-agents.js +73 -0
- package/dist/src/agents/types.d.ts +194 -0
- package/dist/src/agents/types.js +7 -0
- package/dist/src/brain/index.d.ts +185 -0
- package/dist/src/brain/index.js +843 -0
- package/dist/src/brain/trace.d.ts +91 -0
- package/dist/src/brain/trace.js +327 -0
- package/dist/src/brain/types.d.ts +165 -0
- package/dist/src/brain/types.js +51 -0
- package/dist/src/cli/chat.d.ts +237 -0
- package/dist/src/cli/chat.js +1959 -0
- package/dist/src/cli/dispatcher.d.ts +182 -0
- package/dist/src/cli/dispatcher.js +718 -0
- package/dist/src/cli/human-loop.d.ts +170 -0
- package/dist/src/cli/human-loop.js +543 -0
- package/dist/src/cli/index.d.ts +12 -0
- package/dist/src/cli/index.js +28 -0
- package/dist/src/cli/interactive.d.ts +141 -0
- package/dist/src/cli/interactive.js +757 -0
- package/dist/src/cli/ui.d.ts +205 -0
- package/dist/src/cli/ui.js +632 -0
- package/dist/src/consciousness/attention-schema.d.ts +154 -0
- package/dist/src/consciousness/attention-schema.js +432 -0
- package/dist/src/consciousness/global-workspace.d.ts +149 -0
- package/dist/src/consciousness/global-workspace.js +422 -0
- package/dist/src/consciousness/index.d.ts +186 -0
- package/dist/src/consciousness/index.js +476 -0
- package/dist/src/consciousness/phi-calculator.d.ts +119 -0
- package/dist/src/consciousness/phi-calculator.js +445 -0
- package/dist/src/consciousness/phi-decisions.d.ts +169 -0
- package/dist/src/consciousness/phi-decisions.js +383 -0
- package/dist/src/consciousness/phi-monitor.d.ts +153 -0
- package/dist/src/consciousness/phi-monitor.js +465 -0
- package/dist/src/consciousness/types.d.ts +260 -0
- package/dist/src/consciousness/types.js +44 -0
- package/dist/src/daemon/dream-mode.d.ts +115 -0
- package/dist/src/daemon/dream-mode.js +470 -0
- package/dist/src/daemon/index.d.ts +162 -0
- package/dist/src/daemon/index.js +542 -0
- package/dist/src/daemon/maintenance.d.ts +139 -0
- package/dist/src/daemon/maintenance.js +549 -0
- package/dist/src/daemon/process.d.ts +82 -0
- package/dist/src/daemon/process.js +442 -0
- package/dist/src/daemon/scheduler.d.ts +90 -0
- package/dist/src/daemon/scheduler.js +494 -0
- package/dist/src/daemon/types.d.ts +213 -0
- package/dist/src/daemon/types.js +50 -0
- package/dist/src/epistemic/index.d.ts +74 -0
- package/dist/src/epistemic/index.js +225 -0
- package/dist/src/grounding/epistemic-stack.d.ts +100 -0
- package/dist/src/grounding/epistemic-stack.js +408 -0
- package/dist/src/grounding/feedback.d.ts +98 -0
- package/dist/src/grounding/feedback.js +276 -0
- package/dist/src/grounding/index.d.ts +123 -0
- package/dist/src/grounding/index.js +224 -0
- package/dist/src/grounding/verifier.d.ts +149 -0
- package/dist/src/grounding/verifier.js +484 -0
- package/dist/src/healing/detector.d.ts +110 -0
- package/dist/src/healing/detector.js +436 -0
- package/dist/src/healing/fixer.d.ts +138 -0
- package/dist/src/healing/fixer.js +572 -0
- package/dist/src/healing/index.d.ts +23 -0
- package/dist/src/healing/index.js +43 -0
- package/dist/src/hooks/index.d.ts +135 -0
- package/dist/src/hooks/index.js +317 -0
- package/dist/src/index.d.ts +23 -0
- package/dist/src/index.js +1266 -0
- package/dist/src/kernel/index.d.ts +155 -0
- package/dist/src/kernel/index.js +795 -0
- package/dist/src/kernel/invariants.d.ts +153 -0
- package/dist/src/kernel/invariants.js +355 -0
- package/dist/src/kernel/test-kernel.d.ts +6 -0
- package/dist/src/kernel/test-kernel.js +108 -0
- package/dist/src/kernel/test-real-mcp.d.ts +10 -0
- package/dist/src/kernel/test-real-mcp.js +295 -0
- package/dist/src/llm/index.d.ts +146 -0
- package/dist/src/llm/index.js +428 -0
- package/dist/src/llm/router.d.ts +136 -0
- package/dist/src/llm/router.js +510 -0
- package/dist/src/mcp/index.d.ts +85 -0
- package/dist/src/mcp/index.js +657 -0
- package/dist/src/mcp/resilient.d.ts +139 -0
- package/dist/src/mcp/resilient.js +417 -0
- package/dist/src/memory/cache.d.ts +118 -0
- package/dist/src/memory/cache.js +356 -0
- package/dist/src/memory/cognitive-workspace.d.ts +231 -0
- package/dist/src/memory/cognitive-workspace.js +521 -0
- package/dist/src/memory/consolidation.d.ts +99 -0
- package/dist/src/memory/consolidation.js +443 -0
- package/dist/src/memory/episodic.d.ts +114 -0
- package/dist/src/memory/episodic.js +394 -0
- package/dist/src/memory/forgetting.d.ts +134 -0
- package/dist/src/memory/forgetting.js +324 -0
- package/dist/src/memory/index.d.ts +211 -0
- package/dist/src/memory/index.js +367 -0
- package/dist/src/memory/indexer.d.ts +123 -0
- package/dist/src/memory/indexer.js +479 -0
- package/dist/src/memory/procedural.d.ts +136 -0
- package/dist/src/memory/procedural.js +479 -0
- package/dist/src/memory/semantic.d.ts +132 -0
- package/dist/src/memory/semantic.js +497 -0
- package/dist/src/memory/types.d.ts +193 -0
- package/dist/src/memory/types.js +15 -0
- package/dist/src/orchestrator.d.ts +65 -0
- package/dist/src/orchestrator.js +317 -0
- package/dist/src/persistence/index.d.ts +257 -0
- package/dist/src/persistence/index.js +763 -0
- package/dist/src/pipeline/executor.d.ts +51 -0
- package/dist/src/pipeline/executor.js +695 -0
- package/dist/src/pipeline/index.d.ts +7 -0
- package/dist/src/pipeline/index.js +11 -0
- package/dist/src/self-production.d.ts +67 -0
- package/dist/src/self-production.js +205 -0
- package/dist/src/subagents/executor.d.ts +58 -0
- package/dist/src/subagents/executor.js +283 -0
- package/dist/src/subagents/index.d.ts +37 -0
- package/dist/src/subagents/index.js +53 -0
- package/dist/src/subagents/registry.d.ts +23 -0
- package/dist/src/subagents/registry.js +167 -0
- package/dist/src/subagents/types.d.ts +79 -0
- package/dist/src/subagents/types.js +14 -0
- package/dist/src/tools/bash.d.ts +139 -0
- package/dist/src/tools/bash.js +583 -0
- package/dist/src/tools/edit.d.ts +125 -0
- package/dist/src/tools/edit.js +424 -0
- package/dist/src/tools/git.d.ts +179 -0
- package/dist/src/tools/git.js +504 -0
- package/dist/src/tools/index.d.ts +21 -0
- package/dist/src/tools/index.js +163 -0
- package/dist/src/types.d.ts +145 -0
- package/dist/src/types.js +7 -0
- package/dist/src/world-model/decoder.d.ts +163 -0
- package/dist/src/world-model/decoder.js +517 -0
- package/dist/src/world-model/digital-twin.d.ts +219 -0
- package/dist/src/world-model/digital-twin.js +695 -0
- package/dist/src/world-model/encoder.d.ts +141 -0
- package/dist/src/world-model/encoder.js +564 -0
- package/dist/src/world-model/index.d.ts +221 -0
- package/dist/src/world-model/index.js +772 -0
- package/dist/src/world-model/predictor.d.ts +161 -0
- package/dist/src/world-model/predictor.js +681 -0
- package/dist/src/world-model/test-value-jepa.d.ts +8 -0
- package/dist/src/world-model/test-value-jepa.js +430 -0
- package/dist/src/world-model/types.d.ts +341 -0
- package/dist/src/world-model/types.js +69 -0
- package/dist/src/world-model/value-jepa.d.ts +247 -0
- package/dist/src/world-model/value-jepa.js +622 -0
- package/dist/test/brain.test.d.ts +11 -0
- package/dist/test/brain.test.js +358 -0
- package/dist/test/cli/dispatcher.test.d.ts +4 -0
- package/dist/test/cli/dispatcher.test.js +332 -0
- package/dist/test/cli/human-loop.test.d.ts +4 -0
- package/dist/test/cli/human-loop.test.js +270 -0
- package/dist/test/grounding/feedback.test.d.ts +4 -0
- package/dist/test/grounding/feedback.test.js +462 -0
- package/dist/test/grounding/verifier.test.d.ts +4 -0
- package/dist/test/grounding/verifier.test.js +442 -0
- package/dist/test/grounding.test.d.ts +6 -0
- package/dist/test/grounding.test.js +246 -0
- package/dist/test/healing/detector.test.d.ts +4 -0
- package/dist/test/healing/detector.test.js +266 -0
- package/dist/test/healing/fixer.test.d.ts +4 -0
- package/dist/test/healing/fixer.test.js +369 -0
- package/dist/test/integration.test.d.ts +5 -0
- package/dist/test/integration.test.js +290 -0
- package/dist/test/tools/bash.test.d.ts +4 -0
- package/dist/test/tools/bash.test.js +348 -0
- package/dist/test/tools/edit.test.d.ts +4 -0
- package/dist/test/tools/edit.test.js +350 -0
- package/dist/test/tools/git.test.d.ts +4 -0
- package/dist/test/tools/git.test.js +350 -0
- package/package.json +60 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 6.1 - Active Inference Tests
|
|
4
|
+
*
|
|
5
|
+
* Tests for the autonomous decision-making system.
|
|
6
|
+
*
|
|
7
|
+
* Run: node --test dist/active-inference/test-active-inference.js
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
const node_test_1 = require("node:test");
|
|
14
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
15
|
+
const index_js_1 = require("./index.js");
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Core Engine Tests
|
|
18
|
+
// ============================================================================
|
|
19
|
+
(0, node_test_1.describe)('ActiveInferenceEngine', () => {
|
|
20
|
+
(0, node_test_1.it)('should initialize with default beliefs', () => {
|
|
21
|
+
const engine = (0, index_js_1.createActiveInferenceEngine)();
|
|
22
|
+
const beliefs = engine.getBeliefs();
|
|
23
|
+
node_assert_1.default.ok(beliefs.viability.length === 5);
|
|
24
|
+
node_assert_1.default.ok(beliefs.worldState.length === 4);
|
|
25
|
+
node_assert_1.default.ok(beliefs.coupling.length === 5);
|
|
26
|
+
node_assert_1.default.ok(beliefs.goalProgress.length === 4);
|
|
27
|
+
// Beliefs should sum to 1
|
|
28
|
+
const sumViability = beliefs.viability.reduce((a, b) => a + b, 0);
|
|
29
|
+
node_assert_1.default.ok(Math.abs(sumViability - 1) < 0.001, 'Viability beliefs should sum to 1');
|
|
30
|
+
});
|
|
31
|
+
(0, node_test_1.it)('should update beliefs on observation', () => {
|
|
32
|
+
const engine = (0, index_js_1.createActiveInferenceEngine)();
|
|
33
|
+
const obs = {
|
|
34
|
+
energy: 4, // full
|
|
35
|
+
phi: 3, // high
|
|
36
|
+
tool: 2, // success
|
|
37
|
+
coherence: 2, // consistent
|
|
38
|
+
task: 2, // active
|
|
39
|
+
};
|
|
40
|
+
const beforeBeliefs = engine.getBeliefs();
|
|
41
|
+
const afterBeliefs = engine.inferStates(obs);
|
|
42
|
+
// Beliefs should have changed
|
|
43
|
+
node_assert_1.default.ok(JSON.stringify(beforeBeliefs) !== JSON.stringify(afterBeliefs), 'Beliefs should update after observation');
|
|
44
|
+
// High energy observation should increase viability belief
|
|
45
|
+
node_assert_1.default.ok(afterBeliefs.viability[4] > beforeBeliefs.viability[4], 'High energy obs should increase optimal viability belief');
|
|
46
|
+
});
|
|
47
|
+
(0, node_test_1.it)('should infer policy with correct dimensions', () => {
|
|
48
|
+
const engine = (0, index_js_1.createActiveInferenceEngine)();
|
|
49
|
+
// Update beliefs first
|
|
50
|
+
engine.inferStates({
|
|
51
|
+
energy: 2,
|
|
52
|
+
phi: 2,
|
|
53
|
+
tool: 1,
|
|
54
|
+
coherence: 1,
|
|
55
|
+
task: 1,
|
|
56
|
+
});
|
|
57
|
+
const policy = engine.inferPolicies();
|
|
58
|
+
node_assert_1.default.ok(policy.length === index_js_1.ACTIONS.length, 'Policy should have same length as actions');
|
|
59
|
+
// Policy should sum to 1
|
|
60
|
+
const sum = policy.reduce((a, b) => a + b, 0);
|
|
61
|
+
node_assert_1.default.ok(Math.abs(sum - 1) < 0.001, 'Policy should sum to 1');
|
|
62
|
+
// All probabilities should be non-negative
|
|
63
|
+
node_assert_1.default.ok(policy.every(p => p >= 0), 'All policy probabilities should be non-negative');
|
|
64
|
+
});
|
|
65
|
+
(0, node_test_1.it)('should sample valid action from policy', () => {
|
|
66
|
+
const engine = (0, index_js_1.createActiveInferenceEngine)();
|
|
67
|
+
engine.inferStates({
|
|
68
|
+
energy: 2,
|
|
69
|
+
phi: 2,
|
|
70
|
+
tool: 1,
|
|
71
|
+
coherence: 1,
|
|
72
|
+
task: 1,
|
|
73
|
+
});
|
|
74
|
+
const policy = engine.inferPolicies();
|
|
75
|
+
const action = engine.sampleAction(policy);
|
|
76
|
+
node_assert_1.default.ok(index_js_1.ACTIONS.includes(action), `Action ${action} should be valid`);
|
|
77
|
+
});
|
|
78
|
+
(0, node_test_1.it)('should prefer recharge when energy is critical', () => {
|
|
79
|
+
const engine = (0, index_js_1.createActiveInferenceEngine)();
|
|
80
|
+
// Low energy observation
|
|
81
|
+
engine.inferStates({
|
|
82
|
+
energy: 0, // depleted
|
|
83
|
+
phi: 1,
|
|
84
|
+
tool: 1,
|
|
85
|
+
coherence: 1,
|
|
86
|
+
task: 1,
|
|
87
|
+
});
|
|
88
|
+
const policy = engine.inferPolicies();
|
|
89
|
+
// Recharge should have high probability
|
|
90
|
+
const rechargeIdx = index_js_1.ACTIONS.indexOf('recharge');
|
|
91
|
+
const restIdx = index_js_1.ACTIONS.indexOf('rest.idle');
|
|
92
|
+
// Either recharge or rest should be preferred
|
|
93
|
+
const preferSurvival = policy[rechargeIdx] > 0.1 || policy[restIdx] > 0.1;
|
|
94
|
+
node_assert_1.default.ok(preferSurvival, 'Should prefer survival actions when energy is critical');
|
|
95
|
+
});
|
|
96
|
+
(0, node_test_1.it)('should prefer execute.task when close to goal', () => {
|
|
97
|
+
const engine = (0, index_js_1.createActiveInferenceEngine)();
|
|
98
|
+
// High energy, on-track observation
|
|
99
|
+
engine.inferStates({
|
|
100
|
+
energy: 4, // full
|
|
101
|
+
phi: 3, // high
|
|
102
|
+
tool: 2, // success
|
|
103
|
+
coherence: 2, // consistent
|
|
104
|
+
task: 2, // active
|
|
105
|
+
});
|
|
106
|
+
const policy = engine.inferPolicies();
|
|
107
|
+
// Execute task should have reasonable probability
|
|
108
|
+
const executeIdx = index_js_1.ACTIONS.indexOf('execute.task');
|
|
109
|
+
node_assert_1.default.ok(policy[executeIdx] > 0.05, 'Should consider executing task when conditions are good');
|
|
110
|
+
});
|
|
111
|
+
(0, node_test_1.it)('should track statistics correctly', () => {
|
|
112
|
+
const engine = (0, index_js_1.createActiveInferenceEngine)();
|
|
113
|
+
// Run several inference cycles
|
|
114
|
+
for (let i = 0; i < 5; i++) {
|
|
115
|
+
engine.inferStates({
|
|
116
|
+
energy: 2,
|
|
117
|
+
phi: 2,
|
|
118
|
+
tool: 1,
|
|
119
|
+
coherence: 1,
|
|
120
|
+
task: 1,
|
|
121
|
+
});
|
|
122
|
+
const policy = engine.inferPolicies();
|
|
123
|
+
engine.sampleAction(policy);
|
|
124
|
+
}
|
|
125
|
+
const stats = engine.getStats();
|
|
126
|
+
node_assert_1.default.strictEqual(stats.inferenceCount, 5);
|
|
127
|
+
node_assert_1.default.ok(stats.averageSurprise >= 0, 'Average surprise should be non-negative');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
// ============================================================================
|
|
131
|
+
// Observation Gatherer Tests
|
|
132
|
+
// ============================================================================
|
|
133
|
+
(0, node_test_1.describe)('ObservationGatherer', () => {
|
|
134
|
+
(0, node_test_1.it)('should create observations from raw values', () => {
|
|
135
|
+
const gatherer = (0, index_js_1.createObservationGatherer)();
|
|
136
|
+
const obs = gatherer.fromRaw({
|
|
137
|
+
energy: 0.9,
|
|
138
|
+
phi: 0.8,
|
|
139
|
+
toolSuccess: true,
|
|
140
|
+
coherent: true,
|
|
141
|
+
taskStatus: 'running',
|
|
142
|
+
});
|
|
143
|
+
node_assert_1.default.strictEqual(obs.energy, 4, 'High energy should map to 4');
|
|
144
|
+
node_assert_1.default.strictEqual(obs.phi, 3, 'High phi should map to 3');
|
|
145
|
+
node_assert_1.default.strictEqual(obs.tool, 2, 'Success should map to 2');
|
|
146
|
+
node_assert_1.default.strictEqual(obs.coherence, 2, 'Coherent should map to 2');
|
|
147
|
+
node_assert_1.default.strictEqual(obs.task, 2, 'Running should map to 2');
|
|
148
|
+
});
|
|
149
|
+
(0, node_test_1.it)('should gather observations with defaults', async () => {
|
|
150
|
+
const gatherer = (0, index_js_1.createObservationGatherer)();
|
|
151
|
+
// Without configuration, should use defaults
|
|
152
|
+
const obs = await gatherer.gather();
|
|
153
|
+
node_assert_1.default.ok(obs.energy >= 0 && obs.energy <= 4);
|
|
154
|
+
node_assert_1.default.ok(obs.phi >= 0 && obs.phi <= 3);
|
|
155
|
+
node_assert_1.default.ok(obs.tool >= 0 && obs.tool <= 2);
|
|
156
|
+
node_assert_1.default.ok(obs.coherence >= 0 && obs.coherence <= 2);
|
|
157
|
+
node_assert_1.default.ok(obs.task >= 0 && obs.task <= 3);
|
|
158
|
+
});
|
|
159
|
+
(0, node_test_1.it)('should use configured sources', async () => {
|
|
160
|
+
const gatherer = (0, index_js_1.createObservationGatherer)();
|
|
161
|
+
gatherer.configure({
|
|
162
|
+
kernelState: () => ({ energy: 0.1, state: 'idle', taskStatus: 'pending' }),
|
|
163
|
+
phiState: () => ({ phi: 0.2, state: 'drowsy' }),
|
|
164
|
+
});
|
|
165
|
+
const obs = await gatherer.gather();
|
|
166
|
+
node_assert_1.default.strictEqual(obs.energy, 1, 'Low energy should map to 1');
|
|
167
|
+
node_assert_1.default.strictEqual(obs.phi, 1, 'Low phi should map to 1');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
// ============================================================================
|
|
171
|
+
// Action Executor Tests
|
|
172
|
+
// ============================================================================
|
|
173
|
+
(0, node_test_1.describe)('ActionExecutorManager', () => {
|
|
174
|
+
(0, node_test_1.it)('should execute actions and track history', async () => {
|
|
175
|
+
const manager = (0, index_js_1.createActionExecutorManager)();
|
|
176
|
+
const result = await manager.execute('rest.idle');
|
|
177
|
+
node_assert_1.default.ok(result.success);
|
|
178
|
+
node_assert_1.default.strictEqual(result.action, 'rest.idle');
|
|
179
|
+
const history = manager.getHistory();
|
|
180
|
+
node_assert_1.default.strictEqual(history.length, 1);
|
|
181
|
+
});
|
|
182
|
+
(0, node_test_1.it)('should allow custom action registration', async () => {
|
|
183
|
+
const manager = (0, index_js_1.createActionExecutorManager)();
|
|
184
|
+
let executed = false;
|
|
185
|
+
(0, index_js_1.registerAction)('sense.mcp', async () => {
|
|
186
|
+
executed = true;
|
|
187
|
+
return {
|
|
188
|
+
success: true,
|
|
189
|
+
action: 'sense.mcp',
|
|
190
|
+
data: { test: true },
|
|
191
|
+
duration: 0,
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
await manager.execute('sense.mcp');
|
|
195
|
+
node_assert_1.default.ok(executed, 'Custom action should be executed');
|
|
196
|
+
});
|
|
197
|
+
(0, node_test_1.it)('should calculate statistics correctly', async () => {
|
|
198
|
+
const manager = (0, index_js_1.createActionExecutorManager)();
|
|
199
|
+
await manager.execute('rest.idle');
|
|
200
|
+
await manager.execute('rest.idle');
|
|
201
|
+
await manager.execute('sense.mcp');
|
|
202
|
+
const stats = manager.getStats();
|
|
203
|
+
node_assert_1.default.strictEqual(stats.total, 3);
|
|
204
|
+
node_assert_1.default.strictEqual(stats.successful, 3);
|
|
205
|
+
node_assert_1.default.strictEqual(stats.successRate, 1);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
// ============================================================================
|
|
209
|
+
// Autonomous Loop Tests
|
|
210
|
+
// ============================================================================
|
|
211
|
+
(0, node_test_1.describe)('AutonomousLoop', () => {
|
|
212
|
+
(0, node_test_1.it)('should run specified number of cycles', async () => {
|
|
213
|
+
const loop = (0, index_js_1.createAutonomousLoop)({
|
|
214
|
+
cycleInterval: 0, // No delay between cycles
|
|
215
|
+
verbose: false,
|
|
216
|
+
});
|
|
217
|
+
const stats = await loop.run(5);
|
|
218
|
+
node_assert_1.default.strictEqual(stats.cycles, 5);
|
|
219
|
+
node_assert_1.default.ok(stats.finalBeliefs.viability.length === 5);
|
|
220
|
+
});
|
|
221
|
+
(0, node_test_1.it)('should call onCycle handlers', async () => {
|
|
222
|
+
const loop = (0, index_js_1.createAutonomousLoop)({
|
|
223
|
+
cycleInterval: 0,
|
|
224
|
+
verbose: false,
|
|
225
|
+
});
|
|
226
|
+
let cyclesCalled = 0;
|
|
227
|
+
loop.onCycle(() => {
|
|
228
|
+
cyclesCalled++;
|
|
229
|
+
});
|
|
230
|
+
await loop.run(3);
|
|
231
|
+
node_assert_1.default.strictEqual(cyclesCalled, 3);
|
|
232
|
+
});
|
|
233
|
+
(0, node_test_1.it)('should call onStop handlers', async () => {
|
|
234
|
+
const loop = (0, index_js_1.createAutonomousLoop)({
|
|
235
|
+
cycleInterval: 0,
|
|
236
|
+
verbose: false,
|
|
237
|
+
});
|
|
238
|
+
let stopReason = '';
|
|
239
|
+
loop.onStop((reason) => {
|
|
240
|
+
stopReason = reason;
|
|
241
|
+
});
|
|
242
|
+
await loop.run(2);
|
|
243
|
+
node_assert_1.default.strictEqual(stopReason, 'cycle_limit');
|
|
244
|
+
});
|
|
245
|
+
(0, node_test_1.it)('should stop on manual stop', async () => {
|
|
246
|
+
const loop = (0, index_js_1.createAutonomousLoop)({
|
|
247
|
+
cycleInterval: 10,
|
|
248
|
+
maxCycles: 0, // Unlimited
|
|
249
|
+
verbose: false,
|
|
250
|
+
});
|
|
251
|
+
// Schedule stop after 2 cycles
|
|
252
|
+
setTimeout(() => loop.stop('test_stop'), 25);
|
|
253
|
+
const stats = await loop.run();
|
|
254
|
+
node_assert_1.default.ok(stats.cycles >= 1 && stats.cycles <= 5, 'Should have run a few cycles before stop');
|
|
255
|
+
});
|
|
256
|
+
(0, node_test_1.it)('should provide valid most likely state', async () => {
|
|
257
|
+
const loop = (0, index_js_1.createAutonomousLoop)({
|
|
258
|
+
cycleInterval: 0,
|
|
259
|
+
verbose: false,
|
|
260
|
+
});
|
|
261
|
+
await loop.run(3);
|
|
262
|
+
const state = loop.getMostLikelyState();
|
|
263
|
+
node_assert_1.default.ok(['critical', 'low', 'medium', 'high', 'optimal'].includes(state.viability));
|
|
264
|
+
node_assert_1.default.ok(['unknown', 'stable', 'changing', 'hostile'].includes(state.worldState));
|
|
265
|
+
node_assert_1.default.ok(['none', 'weak', 'medium', 'strong', 'synced'].includes(state.coupling));
|
|
266
|
+
node_assert_1.default.ok(['blocked', 'slow', 'onTrack', 'achieved'].includes(state.goalProgress));
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
// ============================================================================
|
|
270
|
+
// Integration Tests
|
|
271
|
+
// ============================================================================
|
|
272
|
+
(0, node_test_1.describe)('Active Inference Integration', () => {
|
|
273
|
+
(0, node_test_1.it)('should run complete inference cycle', async () => {
|
|
274
|
+
const loop = (0, index_js_1.createAutonomousLoop)({
|
|
275
|
+
cycleInterval: 0,
|
|
276
|
+
verbose: false,
|
|
277
|
+
});
|
|
278
|
+
// Configure custom observation source
|
|
279
|
+
loop.configureObservations({
|
|
280
|
+
kernelState: () => ({
|
|
281
|
+
energy: 0.7,
|
|
282
|
+
state: 'thinking',
|
|
283
|
+
taskStatus: 'running',
|
|
284
|
+
}),
|
|
285
|
+
});
|
|
286
|
+
// Run cycles
|
|
287
|
+
const stats = await loop.run(10);
|
|
288
|
+
// Verify reasonable behavior
|
|
289
|
+
node_assert_1.default.ok(stats.cycles === 10);
|
|
290
|
+
node_assert_1.default.ok(Object.keys(stats.actions).length > 0, 'Should have taken some actions');
|
|
291
|
+
});
|
|
292
|
+
(0, node_test_1.it)('should adapt behavior to changing observations', async () => {
|
|
293
|
+
const engine = (0, index_js_1.createActiveInferenceEngine)();
|
|
294
|
+
// Start with low energy
|
|
295
|
+
engine.inferStates({
|
|
296
|
+
energy: 0,
|
|
297
|
+
phi: 1,
|
|
298
|
+
tool: 1,
|
|
299
|
+
coherence: 1,
|
|
300
|
+
task: 1,
|
|
301
|
+
});
|
|
302
|
+
const lowEnergyPolicy = engine.inferPolicies();
|
|
303
|
+
const lowEnergyRecharge = lowEnergyPolicy[index_js_1.ACTIONS.indexOf('recharge')];
|
|
304
|
+
const lowEnergyRest = lowEnergyPolicy[index_js_1.ACTIONS.indexOf('rest.idle')];
|
|
305
|
+
// Then high energy
|
|
306
|
+
engine.inferStates({
|
|
307
|
+
energy: 4,
|
|
308
|
+
phi: 3,
|
|
309
|
+
tool: 2,
|
|
310
|
+
coherence: 2,
|
|
311
|
+
task: 2,
|
|
312
|
+
});
|
|
313
|
+
const highEnergyPolicy = engine.inferPolicies();
|
|
314
|
+
const highEnergyRecharge = highEnergyPolicy[index_js_1.ACTIONS.indexOf('recharge')];
|
|
315
|
+
const highEnergyRest = highEnergyPolicy[index_js_1.ACTIONS.indexOf('rest.idle')];
|
|
316
|
+
// Low energy should prefer recharge/rest more than high energy
|
|
317
|
+
node_assert_1.default.ok((lowEnergyRecharge + lowEnergyRest) > (highEnergyRecharge + highEnergyRest), 'Low energy should prefer survival actions more');
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
console.log('Active Inference Tests - Ready to run');
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Test Value Integration (Genesis 6.2)
|
|
4
|
+
*
|
|
5
|
+
* Verifies that Value-Guided JEPA integrates correctly with Active Inference.
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
const node_test_1 = require("node:test");
|
|
12
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
13
|
+
const value_integration_js_1 = require("./value-integration.js");
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Test Utilities
|
|
16
|
+
// ============================================================================
|
|
17
|
+
function createTestObservation(overrides = {}) {
|
|
18
|
+
return {
|
|
19
|
+
energy: 2, // 0=critical, 1=low, 2=normal, 3=high, 4=optimal
|
|
20
|
+
phi: 1, // 0=none, 1=low, 2=medium, 3=high
|
|
21
|
+
tool: 1, // 0=none, 1=success, 2=failure
|
|
22
|
+
coherence: 1, // 0=none, 1=low, 2=high
|
|
23
|
+
task: 1, // 0=none, 1=active, 2=blocked, 3=completed
|
|
24
|
+
...overrides,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Tests
|
|
29
|
+
// ============================================================================
|
|
30
|
+
(0, node_test_1.describe)('ValueAugmentedEngine', () => {
|
|
31
|
+
let engine;
|
|
32
|
+
(0, node_test_1.beforeEach)(() => {
|
|
33
|
+
engine = (0, value_integration_js_1.createValueAugmentedEngine)();
|
|
34
|
+
});
|
|
35
|
+
(0, node_test_1.describe)('creation', () => {
|
|
36
|
+
(0, node_test_1.it)('should create with default config', () => {
|
|
37
|
+
node_assert_1.default.ok(engine);
|
|
38
|
+
node_assert_1.default.strictEqual(typeof engine.step, 'function');
|
|
39
|
+
});
|
|
40
|
+
(0, node_test_1.it)('should create with custom config', () => {
|
|
41
|
+
const custom = (0, value_integration_js_1.createValueAugmentedEngine)({
|
|
42
|
+
valueWeight: 0.8,
|
|
43
|
+
useWorldModelPredictions: false,
|
|
44
|
+
});
|
|
45
|
+
node_assert_1.default.ok(custom);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
(0, node_test_1.describe)('step', () => {
|
|
49
|
+
(0, node_test_1.it)('should perform inference step with value augmentation', async () => {
|
|
50
|
+
const obs = createTestObservation();
|
|
51
|
+
const result = await engine.step(obs);
|
|
52
|
+
node_assert_1.default.ok(result.action);
|
|
53
|
+
node_assert_1.default.ok(result.beliefs);
|
|
54
|
+
node_assert_1.default.ok(typeof result.value.value === 'number');
|
|
55
|
+
node_assert_1.default.ok(result.policy);
|
|
56
|
+
node_assert_1.default.ok(Array.isArray(result.policy));
|
|
57
|
+
});
|
|
58
|
+
(0, node_test_1.it)('should return valid action', async () => {
|
|
59
|
+
const obs = createTestObservation();
|
|
60
|
+
const result = await engine.step(obs);
|
|
61
|
+
// Action should be a valid ActionType string
|
|
62
|
+
node_assert_1.default.strictEqual(typeof result.action, 'string');
|
|
63
|
+
});
|
|
64
|
+
(0, node_test_1.it)('should update beliefs over time', async () => {
|
|
65
|
+
const obs1 = createTestObservation({ energy: 3 });
|
|
66
|
+
const result1 = await engine.step(obs1);
|
|
67
|
+
const obs2 = createTestObservation({ energy: 1 });
|
|
68
|
+
const result2 = await engine.step(obs2);
|
|
69
|
+
// Both should have beliefs
|
|
70
|
+
node_assert_1.default.ok(result1.beliefs);
|
|
71
|
+
node_assert_1.default.ok(result2.beliefs);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
(0, node_test_1.describe)('value estimation', () => {
|
|
75
|
+
(0, node_test_1.it)('should return value estimate with components', async () => {
|
|
76
|
+
const obs = createTestObservation();
|
|
77
|
+
const result = await engine.step(obs);
|
|
78
|
+
node_assert_1.default.ok(typeof result.value.value === 'number');
|
|
79
|
+
node_assert_1.default.ok(typeof result.value.components === 'object');
|
|
80
|
+
node_assert_1.default.ok('survival' in result.value.components);
|
|
81
|
+
node_assert_1.default.ok('integrity' in result.value.components);
|
|
82
|
+
node_assert_1.default.ok('progress' in result.value.components);
|
|
83
|
+
});
|
|
84
|
+
(0, node_test_1.it)('should estimate higher value for better states', async () => {
|
|
85
|
+
// Run multiple steps to let beliefs converge
|
|
86
|
+
const goodObs = createTestObservation({ energy: 4, task: 3, phi: 3, coherence: 2 });
|
|
87
|
+
await engine.step(goodObs);
|
|
88
|
+
await engine.step(goodObs);
|
|
89
|
+
const goodResult = await engine.step(goodObs);
|
|
90
|
+
// Reset and try bad state
|
|
91
|
+
const engine2 = (0, value_integration_js_1.createValueAugmentedEngine)();
|
|
92
|
+
const badObs = createTestObservation({ energy: 0, task: 0, phi: 0, coherence: 0 });
|
|
93
|
+
await engine2.step(badObs);
|
|
94
|
+
await engine2.step(badObs);
|
|
95
|
+
const badResult = await engine2.step(badObs);
|
|
96
|
+
// Good state should have higher value (with tolerance for noise)
|
|
97
|
+
// The value difference should be meaningful
|
|
98
|
+
const diff = goodResult.value.value - badResult.value.value;
|
|
99
|
+
node_assert_1.default.ok(diff > -0.05, `Expected good value (${goodResult.value.value.toFixed(3)}) to be close to or greater than bad value (${badResult.value.value.toFixed(3)}), diff=${diff.toFixed(3)}`);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
(0, node_test_1.describe)('policy computation', () => {
|
|
103
|
+
(0, node_test_1.it)('should compute value-augmented policy', async () => {
|
|
104
|
+
const obs = createTestObservation();
|
|
105
|
+
const result = await engine.step(obs);
|
|
106
|
+
// Policy should be an array of probabilities
|
|
107
|
+
node_assert_1.default.ok(Array.isArray(result.policy));
|
|
108
|
+
node_assert_1.default.ok(result.policy.length > 0);
|
|
109
|
+
// All probabilities should be non-negative
|
|
110
|
+
for (const p of result.policy) {
|
|
111
|
+
node_assert_1.default.ok(p >= 0, `Probability ${p} should be >= 0`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
(0, node_test_1.it)('should have policy sum to approximately 1', async () => {
|
|
115
|
+
const obs = createTestObservation();
|
|
116
|
+
const result = await engine.step(obs);
|
|
117
|
+
const sum = result.policy.reduce((a, b) => a + b, 0);
|
|
118
|
+
node_assert_1.default.ok(Math.abs(sum - 1) < 0.01, `Policy sum ${sum} should be ~1`);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
(0, node_test_1.describe)('learning', () => {
|
|
122
|
+
(0, node_test_1.it)('should update from outcome', async () => {
|
|
123
|
+
const obs = createTestObservation();
|
|
124
|
+
await engine.step(obs);
|
|
125
|
+
// Get latent state after step
|
|
126
|
+
const latentState = engine.getLatentState();
|
|
127
|
+
node_assert_1.default.ok(latentState, 'Should have latent state after step');
|
|
128
|
+
// Update with positive outcome
|
|
129
|
+
const obs2 = createTestObservation({ energy: 3 });
|
|
130
|
+
engine.updateFromOutcome(latentState, 'execute.task', {
|
|
131
|
+
success: true,
|
|
132
|
+
newObservation: obs2,
|
|
133
|
+
});
|
|
134
|
+
// Should not throw and continue working
|
|
135
|
+
const result = await engine.step(obs);
|
|
136
|
+
node_assert_1.default.ok(result.action);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
(0, node_test_1.describe)('statistics', () => {
|
|
140
|
+
(0, node_test_1.it)('should track statistics', async () => {
|
|
141
|
+
const obs = createTestObservation();
|
|
142
|
+
await engine.step(obs);
|
|
143
|
+
await engine.step(obs);
|
|
144
|
+
const stats = engine.getStats();
|
|
145
|
+
node_assert_1.default.strictEqual(stats.cycleCount, 2);
|
|
146
|
+
node_assert_1.default.ok(typeof stats.totalValue === 'number');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
(0, node_test_1.describe)('createFullyIntegratedEngine', () => {
|
|
151
|
+
(0, node_test_1.it)('should create fully integrated engine with JEPA', async () => {
|
|
152
|
+
const engine = await (0, value_integration_js_1.createFullyIntegratedEngine)();
|
|
153
|
+
node_assert_1.default.ok(engine);
|
|
154
|
+
node_assert_1.default.strictEqual(typeof engine.step, 'function');
|
|
155
|
+
// Should have initialized JEPA
|
|
156
|
+
const stats = engine.getStats();
|
|
157
|
+
node_assert_1.default.strictEqual(stats.cycleCount, 0);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
(0, node_test_1.describe)('DEFAULT_VALUE_INTEGRATION_CONFIG', () => {
|
|
161
|
+
(0, node_test_1.it)('should have valid default values', () => {
|
|
162
|
+
node_assert_1.default.strictEqual(typeof value_integration_js_1.DEFAULT_VALUE_INTEGRATION_CONFIG.valueWeight, 'number');
|
|
163
|
+
node_assert_1.default.ok(value_integration_js_1.DEFAULT_VALUE_INTEGRATION_CONFIG.valueWeight >= 0);
|
|
164
|
+
node_assert_1.default.ok(value_integration_js_1.DEFAULT_VALUE_INTEGRATION_CONFIG.valueWeight <= 1);
|
|
165
|
+
node_assert_1.default.strictEqual(typeof value_integration_js_1.DEFAULT_VALUE_INTEGRATION_CONFIG.predictionHorizon, 'number');
|
|
166
|
+
node_assert_1.default.ok(value_integration_js_1.DEFAULT_VALUE_INTEGRATION_CONFIG.predictionHorizon >= 1);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis 6.1 - Active Inference Types
|
|
3
|
+
*
|
|
4
|
+
* Based on pymdp and Free Energy Principle (Friston)
|
|
5
|
+
*
|
|
6
|
+
* Core concepts:
|
|
7
|
+
* - Hidden states: What the system believes about the world
|
|
8
|
+
* - Observations: What the system perceives
|
|
9
|
+
* - Actions: What the system can do
|
|
10
|
+
* - Preferences: What the system wants (C matrix)
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Hidden state factors - factorized to avoid combinatorial explosion
|
|
14
|
+
*
|
|
15
|
+
* Instead of 400 states (5×4×5×4), we have 4 factors with small dimensions.
|
|
16
|
+
* This reduces B matrix from 400×400×8 = 1.28M to ~900 parameters.
|
|
17
|
+
*/
|
|
18
|
+
export type ViabilityLevel = 0 | 1 | 2 | 3 | 4;
|
|
19
|
+
export type WorldState = 0 | 1 | 2 | 3;
|
|
20
|
+
export type CouplingState = 0 | 1 | 2 | 3 | 4;
|
|
21
|
+
export type GoalProgress = 0 | 1 | 2 | 3;
|
|
22
|
+
export interface HiddenState {
|
|
23
|
+
viability: ViabilityLevel;
|
|
24
|
+
worldState: WorldState;
|
|
25
|
+
coupling: CouplingState;
|
|
26
|
+
goalProgress: GoalProgress;
|
|
27
|
+
}
|
|
28
|
+
export declare const HIDDEN_STATE_DIMS: {
|
|
29
|
+
readonly viability: 5;
|
|
30
|
+
readonly worldState: 4;
|
|
31
|
+
readonly coupling: 5;
|
|
32
|
+
readonly goalProgress: 4;
|
|
33
|
+
};
|
|
34
|
+
export declare const HIDDEN_STATE_LABELS: {
|
|
35
|
+
viability: readonly ["critical", "low", "medium", "high", "optimal"];
|
|
36
|
+
worldState: readonly ["unknown", "stable", "changing", "hostile"];
|
|
37
|
+
coupling: readonly ["none", "weak", "medium", "strong", "synced"];
|
|
38
|
+
goalProgress: readonly ["blocked", "slow", "onTrack", "achieved"];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Observation modalities - what the system perceives
|
|
42
|
+
*/
|
|
43
|
+
export type EnergyObs = 0 | 1 | 2 | 3 | 4;
|
|
44
|
+
export type PhiObs = 0 | 1 | 2 | 3;
|
|
45
|
+
export type ToolObs = 0 | 1 | 2;
|
|
46
|
+
export type CoherenceObs = 0 | 1 | 2;
|
|
47
|
+
export type TaskObs = 0 | 1 | 2 | 3;
|
|
48
|
+
export interface Observation {
|
|
49
|
+
energy: EnergyObs;
|
|
50
|
+
phi: PhiObs;
|
|
51
|
+
tool: ToolObs;
|
|
52
|
+
coherence: CoherenceObs;
|
|
53
|
+
task: TaskObs;
|
|
54
|
+
}
|
|
55
|
+
export declare const OBSERVATION_DIMS: {
|
|
56
|
+
readonly energy: 5;
|
|
57
|
+
readonly phi: 4;
|
|
58
|
+
readonly tool: 3;
|
|
59
|
+
readonly coherence: 3;
|
|
60
|
+
readonly task: 4;
|
|
61
|
+
};
|
|
62
|
+
export declare const OBSERVATION_LABELS: {
|
|
63
|
+
energy: readonly ["depleted", "low", "medium", "high", "full"];
|
|
64
|
+
phi: readonly ["dormant", "low", "medium", "high"];
|
|
65
|
+
tool: readonly ["failed", "partial", "success"];
|
|
66
|
+
coherence: readonly ["broken", "degraded", "consistent"];
|
|
67
|
+
task: readonly ["none", "pending", "active", "completed"];
|
|
68
|
+
};
|
|
69
|
+
export type ActionType = 'sense.mcp' | 'recall.memory' | 'plan.goals' | 'verify.ethics' | 'execute.task' | 'dream.cycle' | 'rest.idle' | 'recharge';
|
|
70
|
+
export declare const ACTIONS: ActionType[];
|
|
71
|
+
export declare const ACTION_COUNT: number;
|
|
72
|
+
/**
|
|
73
|
+
* Beliefs are probability distributions over hidden states
|
|
74
|
+
* Factorized: one distribution per factor
|
|
75
|
+
*/
|
|
76
|
+
export interface Beliefs {
|
|
77
|
+
viability: number[];
|
|
78
|
+
worldState: number[];
|
|
79
|
+
coupling: number[];
|
|
80
|
+
goalProgress: number[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Policy is a probability distribution over actions
|
|
84
|
+
*/
|
|
85
|
+
export type Policy = number[];
|
|
86
|
+
/**
|
|
87
|
+
* A matrix: P(observation | hidden_state)
|
|
88
|
+
* Maps hidden states to expected observations
|
|
89
|
+
*
|
|
90
|
+
* Factorized: A[modality][obs_level][state_level]
|
|
91
|
+
*/
|
|
92
|
+
export interface AMatrix {
|
|
93
|
+
energy: number[][];
|
|
94
|
+
phi: number[][];
|
|
95
|
+
tool: number[][];
|
|
96
|
+
coherence: number[][];
|
|
97
|
+
task: number[][];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* B matrix: P(next_state | current_state, action)
|
|
101
|
+
* Transition probabilities
|
|
102
|
+
*
|
|
103
|
+
* Factorized: B[factor][next_state][current_state][action]
|
|
104
|
+
*/
|
|
105
|
+
export interface BMatrix {
|
|
106
|
+
viability: number[][][];
|
|
107
|
+
worldState: number[][][];
|
|
108
|
+
coupling: number[][][];
|
|
109
|
+
goalProgress: number[][][];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* C matrix: log P(preferred_observation)
|
|
113
|
+
* Encodes preferences (what the system wants to observe)
|
|
114
|
+
*
|
|
115
|
+
* Negative values = aversive
|
|
116
|
+
* Positive values = attractive
|
|
117
|
+
*/
|
|
118
|
+
export interface CMatrix {
|
|
119
|
+
energy: number[];
|
|
120
|
+
phi: number[];
|
|
121
|
+
tool: number[];
|
|
122
|
+
coherence: number[];
|
|
123
|
+
task: number[];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* D matrix: P(initial_state)
|
|
127
|
+
* Prior beliefs about initial state
|
|
128
|
+
*/
|
|
129
|
+
export interface DMatrix {
|
|
130
|
+
viability: number[];
|
|
131
|
+
worldState: number[];
|
|
132
|
+
coupling: number[];
|
|
133
|
+
goalProgress: number[];
|
|
134
|
+
}
|
|
135
|
+
export interface ActiveInferenceConfig {
|
|
136
|
+
inferenceIterations: number;
|
|
137
|
+
policyHorizon: number;
|
|
138
|
+
actionTemperature: number;
|
|
139
|
+
priorWeight: number;
|
|
140
|
+
learningRateA: number;
|
|
141
|
+
learningRateB: number;
|
|
142
|
+
}
|
|
143
|
+
export declare const DEFAULT_CONFIG: ActiveInferenceConfig;
|
|
144
|
+
export type AIEventType = 'beliefs_updated' | 'policy_inferred' | 'action_selected' | 'action_executed' | 'observation_received' | 'surprise_high' | 'goal_achieved' | 'energy_critical';
|
|
145
|
+
export interface AIEvent {
|
|
146
|
+
type: AIEventType;
|
|
147
|
+
timestamp: Date;
|
|
148
|
+
data: Record<string, any>;
|
|
149
|
+
}
|
|
150
|
+
export type AIEventHandler = (event: AIEvent) => void;
|