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.
Files changed (227) hide show
  1. package/.env.example +78 -0
  2. package/README.md +282 -0
  3. package/dist/src/active-inference/actions.d.ts +75 -0
  4. package/dist/src/active-inference/actions.js +250 -0
  5. package/dist/src/active-inference/autonomous-loop.d.ts +103 -0
  6. package/dist/src/active-inference/autonomous-loop.js +289 -0
  7. package/dist/src/active-inference/core.d.ts +85 -0
  8. package/dist/src/active-inference/core.js +555 -0
  9. package/dist/src/active-inference/demo-autonomous-loop.d.ts +8 -0
  10. package/dist/src/active-inference/demo-autonomous-loop.js +338 -0
  11. package/dist/src/active-inference/demo-value-integration.d.ts +8 -0
  12. package/dist/src/active-inference/demo-value-integration.js +174 -0
  13. package/dist/src/active-inference/index.d.ts +32 -0
  14. package/dist/src/active-inference/index.js +88 -0
  15. package/dist/src/active-inference/integration.d.ts +114 -0
  16. package/dist/src/active-inference/integration.js +698 -0
  17. package/dist/src/active-inference/memory-integration.d.ts +51 -0
  18. package/dist/src/active-inference/memory-integration.js +232 -0
  19. package/dist/src/active-inference/observations.d.ts +67 -0
  20. package/dist/src/active-inference/observations.js +147 -0
  21. package/dist/src/active-inference/test-active-inference.d.ts +8 -0
  22. package/dist/src/active-inference/test-active-inference.js +320 -0
  23. package/dist/src/active-inference/test-value-integration.d.ts +6 -0
  24. package/dist/src/active-inference/test-value-integration.js +168 -0
  25. package/dist/src/active-inference/types.d.ts +150 -0
  26. package/dist/src/active-inference/types.js +59 -0
  27. package/dist/src/active-inference/value-integration.d.ts +164 -0
  28. package/dist/src/active-inference/value-integration.js +459 -0
  29. package/dist/src/agents/base-agent.d.ts +53 -0
  30. package/dist/src/agents/base-agent.js +178 -0
  31. package/dist/src/agents/builder.d.ts +67 -0
  32. package/dist/src/agents/builder.js +537 -0
  33. package/dist/src/agents/critic.d.ts +35 -0
  34. package/dist/src/agents/critic.js +322 -0
  35. package/dist/src/agents/ethicist.d.ts +54 -0
  36. package/dist/src/agents/ethicist.js +393 -0
  37. package/dist/src/agents/explorer.d.ts +26 -0
  38. package/dist/src/agents/explorer.js +216 -0
  39. package/dist/src/agents/feeling.d.ts +41 -0
  40. package/dist/src/agents/feeling.js +320 -0
  41. package/dist/src/agents/index.d.ts +111 -0
  42. package/dist/src/agents/index.js +222 -0
  43. package/dist/src/agents/memory.d.ts +69 -0
  44. package/dist/src/agents/memory.js +404 -0
  45. package/dist/src/agents/message-bus.d.ts +88 -0
  46. package/dist/src/agents/message-bus.js +267 -0
  47. package/dist/src/agents/narrator.d.ts +90 -0
  48. package/dist/src/agents/narrator.js +473 -0
  49. package/dist/src/agents/planner.d.ts +38 -0
  50. package/dist/src/agents/planner.js +341 -0
  51. package/dist/src/agents/predictor.d.ts +73 -0
  52. package/dist/src/agents/predictor.js +506 -0
  53. package/dist/src/agents/sensor.d.ts +88 -0
  54. package/dist/src/agents/sensor.js +377 -0
  55. package/dist/src/agents/test-agents.d.ts +6 -0
  56. package/dist/src/agents/test-agents.js +73 -0
  57. package/dist/src/agents/types.d.ts +194 -0
  58. package/dist/src/agents/types.js +7 -0
  59. package/dist/src/brain/index.d.ts +185 -0
  60. package/dist/src/brain/index.js +843 -0
  61. package/dist/src/brain/trace.d.ts +91 -0
  62. package/dist/src/brain/trace.js +327 -0
  63. package/dist/src/brain/types.d.ts +165 -0
  64. package/dist/src/brain/types.js +51 -0
  65. package/dist/src/cli/chat.d.ts +237 -0
  66. package/dist/src/cli/chat.js +1959 -0
  67. package/dist/src/cli/dispatcher.d.ts +182 -0
  68. package/dist/src/cli/dispatcher.js +718 -0
  69. package/dist/src/cli/human-loop.d.ts +170 -0
  70. package/dist/src/cli/human-loop.js +543 -0
  71. package/dist/src/cli/index.d.ts +12 -0
  72. package/dist/src/cli/index.js +28 -0
  73. package/dist/src/cli/interactive.d.ts +141 -0
  74. package/dist/src/cli/interactive.js +757 -0
  75. package/dist/src/cli/ui.d.ts +205 -0
  76. package/dist/src/cli/ui.js +632 -0
  77. package/dist/src/consciousness/attention-schema.d.ts +154 -0
  78. package/dist/src/consciousness/attention-schema.js +432 -0
  79. package/dist/src/consciousness/global-workspace.d.ts +149 -0
  80. package/dist/src/consciousness/global-workspace.js +422 -0
  81. package/dist/src/consciousness/index.d.ts +186 -0
  82. package/dist/src/consciousness/index.js +476 -0
  83. package/dist/src/consciousness/phi-calculator.d.ts +119 -0
  84. package/dist/src/consciousness/phi-calculator.js +445 -0
  85. package/dist/src/consciousness/phi-decisions.d.ts +169 -0
  86. package/dist/src/consciousness/phi-decisions.js +383 -0
  87. package/dist/src/consciousness/phi-monitor.d.ts +153 -0
  88. package/dist/src/consciousness/phi-monitor.js +465 -0
  89. package/dist/src/consciousness/types.d.ts +260 -0
  90. package/dist/src/consciousness/types.js +44 -0
  91. package/dist/src/daemon/dream-mode.d.ts +115 -0
  92. package/dist/src/daemon/dream-mode.js +470 -0
  93. package/dist/src/daemon/index.d.ts +162 -0
  94. package/dist/src/daemon/index.js +542 -0
  95. package/dist/src/daemon/maintenance.d.ts +139 -0
  96. package/dist/src/daemon/maintenance.js +549 -0
  97. package/dist/src/daemon/process.d.ts +82 -0
  98. package/dist/src/daemon/process.js +442 -0
  99. package/dist/src/daemon/scheduler.d.ts +90 -0
  100. package/dist/src/daemon/scheduler.js +494 -0
  101. package/dist/src/daemon/types.d.ts +213 -0
  102. package/dist/src/daemon/types.js +50 -0
  103. package/dist/src/epistemic/index.d.ts +74 -0
  104. package/dist/src/epistemic/index.js +225 -0
  105. package/dist/src/grounding/epistemic-stack.d.ts +100 -0
  106. package/dist/src/grounding/epistemic-stack.js +408 -0
  107. package/dist/src/grounding/feedback.d.ts +98 -0
  108. package/dist/src/grounding/feedback.js +276 -0
  109. package/dist/src/grounding/index.d.ts +123 -0
  110. package/dist/src/grounding/index.js +224 -0
  111. package/dist/src/grounding/verifier.d.ts +149 -0
  112. package/dist/src/grounding/verifier.js +484 -0
  113. package/dist/src/healing/detector.d.ts +110 -0
  114. package/dist/src/healing/detector.js +436 -0
  115. package/dist/src/healing/fixer.d.ts +138 -0
  116. package/dist/src/healing/fixer.js +572 -0
  117. package/dist/src/healing/index.d.ts +23 -0
  118. package/dist/src/healing/index.js +43 -0
  119. package/dist/src/hooks/index.d.ts +135 -0
  120. package/dist/src/hooks/index.js +317 -0
  121. package/dist/src/index.d.ts +23 -0
  122. package/dist/src/index.js +1266 -0
  123. package/dist/src/kernel/index.d.ts +155 -0
  124. package/dist/src/kernel/index.js +795 -0
  125. package/dist/src/kernel/invariants.d.ts +153 -0
  126. package/dist/src/kernel/invariants.js +355 -0
  127. package/dist/src/kernel/test-kernel.d.ts +6 -0
  128. package/dist/src/kernel/test-kernel.js +108 -0
  129. package/dist/src/kernel/test-real-mcp.d.ts +10 -0
  130. package/dist/src/kernel/test-real-mcp.js +295 -0
  131. package/dist/src/llm/index.d.ts +146 -0
  132. package/dist/src/llm/index.js +428 -0
  133. package/dist/src/llm/router.d.ts +136 -0
  134. package/dist/src/llm/router.js +510 -0
  135. package/dist/src/mcp/index.d.ts +85 -0
  136. package/dist/src/mcp/index.js +657 -0
  137. package/dist/src/mcp/resilient.d.ts +139 -0
  138. package/dist/src/mcp/resilient.js +417 -0
  139. package/dist/src/memory/cache.d.ts +118 -0
  140. package/dist/src/memory/cache.js +356 -0
  141. package/dist/src/memory/cognitive-workspace.d.ts +231 -0
  142. package/dist/src/memory/cognitive-workspace.js +521 -0
  143. package/dist/src/memory/consolidation.d.ts +99 -0
  144. package/dist/src/memory/consolidation.js +443 -0
  145. package/dist/src/memory/episodic.d.ts +114 -0
  146. package/dist/src/memory/episodic.js +394 -0
  147. package/dist/src/memory/forgetting.d.ts +134 -0
  148. package/dist/src/memory/forgetting.js +324 -0
  149. package/dist/src/memory/index.d.ts +211 -0
  150. package/dist/src/memory/index.js +367 -0
  151. package/dist/src/memory/indexer.d.ts +123 -0
  152. package/dist/src/memory/indexer.js +479 -0
  153. package/dist/src/memory/procedural.d.ts +136 -0
  154. package/dist/src/memory/procedural.js +479 -0
  155. package/dist/src/memory/semantic.d.ts +132 -0
  156. package/dist/src/memory/semantic.js +497 -0
  157. package/dist/src/memory/types.d.ts +193 -0
  158. package/dist/src/memory/types.js +15 -0
  159. package/dist/src/orchestrator.d.ts +65 -0
  160. package/dist/src/orchestrator.js +317 -0
  161. package/dist/src/persistence/index.d.ts +257 -0
  162. package/dist/src/persistence/index.js +763 -0
  163. package/dist/src/pipeline/executor.d.ts +51 -0
  164. package/dist/src/pipeline/executor.js +695 -0
  165. package/dist/src/pipeline/index.d.ts +7 -0
  166. package/dist/src/pipeline/index.js +11 -0
  167. package/dist/src/self-production.d.ts +67 -0
  168. package/dist/src/self-production.js +205 -0
  169. package/dist/src/subagents/executor.d.ts +58 -0
  170. package/dist/src/subagents/executor.js +283 -0
  171. package/dist/src/subagents/index.d.ts +37 -0
  172. package/dist/src/subagents/index.js +53 -0
  173. package/dist/src/subagents/registry.d.ts +23 -0
  174. package/dist/src/subagents/registry.js +167 -0
  175. package/dist/src/subagents/types.d.ts +79 -0
  176. package/dist/src/subagents/types.js +14 -0
  177. package/dist/src/tools/bash.d.ts +139 -0
  178. package/dist/src/tools/bash.js +583 -0
  179. package/dist/src/tools/edit.d.ts +125 -0
  180. package/dist/src/tools/edit.js +424 -0
  181. package/dist/src/tools/git.d.ts +179 -0
  182. package/dist/src/tools/git.js +504 -0
  183. package/dist/src/tools/index.d.ts +21 -0
  184. package/dist/src/tools/index.js +163 -0
  185. package/dist/src/types.d.ts +145 -0
  186. package/dist/src/types.js +7 -0
  187. package/dist/src/world-model/decoder.d.ts +163 -0
  188. package/dist/src/world-model/decoder.js +517 -0
  189. package/dist/src/world-model/digital-twin.d.ts +219 -0
  190. package/dist/src/world-model/digital-twin.js +695 -0
  191. package/dist/src/world-model/encoder.d.ts +141 -0
  192. package/dist/src/world-model/encoder.js +564 -0
  193. package/dist/src/world-model/index.d.ts +221 -0
  194. package/dist/src/world-model/index.js +772 -0
  195. package/dist/src/world-model/predictor.d.ts +161 -0
  196. package/dist/src/world-model/predictor.js +681 -0
  197. package/dist/src/world-model/test-value-jepa.d.ts +8 -0
  198. package/dist/src/world-model/test-value-jepa.js +430 -0
  199. package/dist/src/world-model/types.d.ts +341 -0
  200. package/dist/src/world-model/types.js +69 -0
  201. package/dist/src/world-model/value-jepa.d.ts +247 -0
  202. package/dist/src/world-model/value-jepa.js +622 -0
  203. package/dist/test/brain.test.d.ts +11 -0
  204. package/dist/test/brain.test.js +358 -0
  205. package/dist/test/cli/dispatcher.test.d.ts +4 -0
  206. package/dist/test/cli/dispatcher.test.js +332 -0
  207. package/dist/test/cli/human-loop.test.d.ts +4 -0
  208. package/dist/test/cli/human-loop.test.js +270 -0
  209. package/dist/test/grounding/feedback.test.d.ts +4 -0
  210. package/dist/test/grounding/feedback.test.js +462 -0
  211. package/dist/test/grounding/verifier.test.d.ts +4 -0
  212. package/dist/test/grounding/verifier.test.js +442 -0
  213. package/dist/test/grounding.test.d.ts +6 -0
  214. package/dist/test/grounding.test.js +246 -0
  215. package/dist/test/healing/detector.test.d.ts +4 -0
  216. package/dist/test/healing/detector.test.js +266 -0
  217. package/dist/test/healing/fixer.test.d.ts +4 -0
  218. package/dist/test/healing/fixer.test.js +369 -0
  219. package/dist/test/integration.test.d.ts +5 -0
  220. package/dist/test/integration.test.js +290 -0
  221. package/dist/test/tools/bash.test.d.ts +4 -0
  222. package/dist/test/tools/bash.test.js +348 -0
  223. package/dist/test/tools/edit.test.d.ts +4 -0
  224. package/dist/test/tools/edit.test.js +350 -0
  225. package/dist/test/tools/git.test.d.ts +4 -0
  226. package/dist/test/tools/git.test.js +350 -0
  227. package/package.json +60 -0
@@ -0,0 +1,369 @@
1
+ "use strict";
2
+ /**
3
+ * Tests for Genesis Auto-Fix Engine
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ const node_test_1 = require("node:test");
43
+ const node_assert_1 = __importDefault(require("node:assert"));
44
+ const fs = __importStar(require("fs"));
45
+ const path = __importStar(require("path"));
46
+ const fixer_js_1 = require("../../src/healing/fixer.js");
47
+ // Test directory
48
+ const TEST_DIR = '/tmp/genesis-fixer-test-' + Date.now();
49
+ (0, node_test_1.describe)('AutoFixer', () => {
50
+ (0, node_test_1.before)(() => {
51
+ fs.mkdirSync(TEST_DIR, { recursive: true });
52
+ (0, fixer_js_1.resetAutoFixer)();
53
+ });
54
+ (0, node_test_1.after)(() => {
55
+ fs.rmSync(TEST_DIR, { recursive: true, force: true });
56
+ (0, fixer_js_1.resetAutoFixer)();
57
+ });
58
+ (0, node_test_1.beforeEach)(() => {
59
+ // Clean test directory
60
+ const files = fs.readdirSync(TEST_DIR);
61
+ for (const file of files) {
62
+ fs.rmSync(path.join(TEST_DIR, file), { force: true, recursive: true });
63
+ }
64
+ });
65
+ // ==========================================================================
66
+ // Candidate Generation Tests
67
+ // ==========================================================================
68
+ (0, node_test_1.describe)('Candidate Generation', () => {
69
+ (0, node_test_1.it)('should generate fix for missing semicolon', async () => {
70
+ const filePath = path.join(TEST_DIR, 'semicolon.ts');
71
+ fs.writeFileSync(filePath, 'const x = 1\nconst y = 2;');
72
+ const error = {
73
+ category: 'syntax',
74
+ severity: 'error',
75
+ message: 'Missing semicolon',
76
+ file: filePath,
77
+ line: 1,
78
+ raw: 'Missing semicolon',
79
+ fixHint: 'syntax_fix',
80
+ };
81
+ const candidates = await (0, fixer_js_1.generateFixes)(error);
82
+ node_assert_1.default.ok(candidates.length > 0);
83
+ node_assert_1.default.ok(candidates.some(c => c.fixed.includes('const x = 1;')));
84
+ });
85
+ (0, node_test_1.it)('should generate fix for undefined variable', async () => {
86
+ const filePath = path.join(TEST_DIR, 'undefined.ts');
87
+ fs.writeFileSync(filePath, 'console.log(myVar);');
88
+ const error = {
89
+ category: 'runtime',
90
+ severity: 'error',
91
+ message: "'myVar' is not defined",
92
+ file: filePath,
93
+ line: 1,
94
+ raw: "'myVar' is not defined",
95
+ fixHint: 'runtime_error',
96
+ };
97
+ const candidates = await (0, fixer_js_1.generateFixes)(error);
98
+ node_assert_1.default.ok(candidates.length > 0);
99
+ node_assert_1.default.ok(candidates.some(c => c.fixed.includes('let myVar')));
100
+ });
101
+ (0, node_test_1.it)('should generate npm install for missing module', async () => {
102
+ const error = {
103
+ category: 'dependency',
104
+ severity: 'error',
105
+ message: "Cannot find module 'lodash'",
106
+ file: 'src/index.ts',
107
+ raw: "Cannot find module 'lodash'",
108
+ fixHint: 'install_dependency',
109
+ };
110
+ const candidates = await (0, fixer_js_1.generateFixes)(error);
111
+ node_assert_1.default.ok(candidates.length > 0);
112
+ node_assert_1.default.ok(candidates.some(c => c.fixed.includes('npm install lodash')));
113
+ });
114
+ (0, node_test_1.it)('should generate optional chaining for null checks', async () => {
115
+ const filePath = path.join(TEST_DIR, 'null.ts');
116
+ fs.writeFileSync(filePath, 'const x = obj.prop.value;');
117
+ const error = {
118
+ category: 'type',
119
+ severity: 'error',
120
+ message: "'obj' is possibly 'null'",
121
+ file: filePath,
122
+ line: 1,
123
+ raw: "'obj' is possibly 'null'",
124
+ fixHint: 'type_mismatch',
125
+ };
126
+ const candidates = await (0, fixer_js_1.generateFixes)(error);
127
+ // Should have optional chaining candidate
128
+ node_assert_1.default.ok(candidates.some(c => c.fixed.includes('?.') || c.fixed.includes('if (obj)')));
129
+ });
130
+ (0, node_test_1.it)('should not generate candidates for errors without file', async () => {
131
+ const error = {
132
+ category: 'runtime',
133
+ severity: 'error',
134
+ message: 'Some error',
135
+ raw: 'Some error',
136
+ };
137
+ const candidates = await (0, fixer_js_1.generateFixes)(error);
138
+ node_assert_1.default.strictEqual(candidates.length, 0);
139
+ });
140
+ (0, node_test_1.it)('should not generate candidates for non-existent files', async () => {
141
+ const error = {
142
+ category: 'syntax',
143
+ severity: 'error',
144
+ message: 'Missing semicolon',
145
+ file: '/nonexistent/file.ts',
146
+ line: 1,
147
+ raw: 'Missing semicolon',
148
+ };
149
+ const candidates = await (0, fixer_js_1.generateFixes)(error);
150
+ node_assert_1.default.strictEqual(candidates.length, 0);
151
+ });
152
+ });
153
+ // ==========================================================================
154
+ // Candidate Properties Tests
155
+ // ==========================================================================
156
+ (0, node_test_1.describe)('Candidate Properties', () => {
157
+ (0, node_test_1.it)('should have unique IDs', async () => {
158
+ const filePath = path.join(TEST_DIR, 'ids.ts');
159
+ fs.writeFileSync(filePath, 'const x = obj.value');
160
+ const error = {
161
+ category: 'type',
162
+ severity: 'error',
163
+ message: "'obj' is possibly 'null'",
164
+ file: filePath,
165
+ line: 1,
166
+ raw: 'possibly null',
167
+ };
168
+ const candidates = await (0, fixer_js_1.generateFixes)(error);
169
+ const ids = candidates.map(c => c.id);
170
+ const uniqueIds = new Set(ids);
171
+ node_assert_1.default.strictEqual(ids.length, uniqueIds.size);
172
+ });
173
+ (0, node_test_1.it)('should include confidence scores', async () => {
174
+ const filePath = path.join(TEST_DIR, 'conf.ts');
175
+ fs.writeFileSync(filePath, 'const x = 1');
176
+ const error = {
177
+ category: 'syntax',
178
+ severity: 'error',
179
+ message: 'Missing semicolon',
180
+ file: filePath,
181
+ line: 1,
182
+ raw: 'Missing semicolon',
183
+ };
184
+ const candidates = await (0, fixer_js_1.generateFixes)(error);
185
+ for (const candidate of candidates) {
186
+ node_assert_1.default.ok(candidate.confidence >= 0);
187
+ node_assert_1.default.ok(candidate.confidence <= 1);
188
+ }
189
+ });
190
+ (0, node_test_1.it)('should include source type', async () => {
191
+ const filePath = path.join(TEST_DIR, 'source.ts');
192
+ fs.writeFileSync(filePath, 'const x = 1');
193
+ const error = {
194
+ category: 'syntax',
195
+ severity: 'error',
196
+ message: 'Missing semicolon',
197
+ file: filePath,
198
+ line: 1,
199
+ raw: 'Missing semicolon',
200
+ };
201
+ const candidates = await (0, fixer_js_1.generateFixes)(error);
202
+ for (const candidate of candidates) {
203
+ node_assert_1.default.ok(['pattern', 'llm', 'heuristic'].includes(candidate.source));
204
+ }
205
+ });
206
+ });
207
+ // ==========================================================================
208
+ // Selection Tests
209
+ // ==========================================================================
210
+ (0, node_test_1.describe)('Selection', () => {
211
+ (0, node_test_1.it)('should select candidate with highest score', () => {
212
+ const fixer = (0, fixer_js_1.getAutoFixer)();
213
+ const evaluations = [
214
+ { candidate: { id: 'a' }, score: 0.5, testsPass: false, testsPassed: 0, testsTotal: 1, buildSuccess: true, newErrors: [], fixedErrors: [] },
215
+ { candidate: { id: 'b' }, score: 0.9, testsPass: true, testsPassed: 1, testsTotal: 1, buildSuccess: true, newErrors: [], fixedErrors: [] },
216
+ { candidate: { id: 'c' }, score: 0.3, testsPass: false, testsPassed: 0, testsTotal: 1, buildSuccess: false, newErrors: [], fixedErrors: [] },
217
+ ];
218
+ const best = fixer.selectBest(evaluations);
219
+ node_assert_1.default.ok(best);
220
+ node_assert_1.default.strictEqual(best.candidate.id, 'b');
221
+ });
222
+ (0, node_test_1.it)('should return null for empty evaluations', () => {
223
+ const fixer = (0, fixer_js_1.getAutoFixer)();
224
+ const best = fixer.selectBest([]);
225
+ node_assert_1.default.strictEqual(best, null);
226
+ });
227
+ });
228
+ // ==========================================================================
229
+ // Configuration Tests
230
+ // ==========================================================================
231
+ (0, node_test_1.describe)('Configuration', () => {
232
+ (0, node_test_1.it)('should use default configuration', () => {
233
+ const fixer = new fixer_js_1.AutoFixer();
234
+ const config = fixer.getConfig();
235
+ node_assert_1.default.strictEqual(config.maxCandidates, 5);
236
+ node_assert_1.default.strictEqual(config.maxIterations, 3);
237
+ node_assert_1.default.strictEqual(config.createBackup, true);
238
+ });
239
+ (0, node_test_1.it)('should accept custom configuration', () => {
240
+ const fixer = new fixer_js_1.AutoFixer({
241
+ maxCandidates: 10,
242
+ maxIterations: 5,
243
+ testCommand: 'npm run test:unit',
244
+ });
245
+ const config = fixer.getConfig();
246
+ node_assert_1.default.strictEqual(config.maxCandidates, 10);
247
+ node_assert_1.default.strictEqual(config.maxIterations, 5);
248
+ node_assert_1.default.strictEqual(config.testCommand, 'npm run test:unit');
249
+ });
250
+ (0, node_test_1.it)('should update configuration', () => {
251
+ const fixer = (0, fixer_js_1.getAutoFixer)();
252
+ fixer.updateConfig({ maxIterations: 10 });
253
+ const config = fixer.getConfig();
254
+ node_assert_1.default.strictEqual(config.maxIterations, 10);
255
+ });
256
+ (0, node_test_1.it)('should allow custom patterns', () => {
257
+ const fixer = new fixer_js_1.AutoFixer();
258
+ fixer.addPattern({
259
+ categories: ['custom'],
260
+ messagePattern: /custom error/,
261
+ generateFix: () => [{
262
+ id: 'custom-fix',
263
+ description: 'Custom fix',
264
+ file: 'test.ts',
265
+ original: '',
266
+ fixed: 'fixed',
267
+ confidence: 1,
268
+ source: 'pattern',
269
+ }],
270
+ });
271
+ // Pattern should be added (we can't easily test it triggers)
272
+ node_assert_1.default.ok(true);
273
+ });
274
+ });
275
+ // ==========================================================================
276
+ // LLM Integration Tests
277
+ // ==========================================================================
278
+ (0, node_test_1.describe)('LLM Integration', () => {
279
+ (0, node_test_1.it)('should accept LLM generator function', () => {
280
+ const fixer = new fixer_js_1.AutoFixer();
281
+ const mockGenerator = async (error, context) => {
282
+ return [{
283
+ id: 'llm-fix',
284
+ description: 'LLM generated fix',
285
+ file: error.file || '',
286
+ original: context,
287
+ fixed: context.replace('error', 'fixed'),
288
+ confidence: 0.8,
289
+ source: 'llm',
290
+ }];
291
+ };
292
+ fixer.setLLMGenerator(mockGenerator);
293
+ const config = fixer.getConfig();
294
+ node_assert_1.default.ok(config.llmFixGenerator !== undefined);
295
+ });
296
+ });
297
+ // ==========================================================================
298
+ // Full Fix Flow Tests
299
+ // ==========================================================================
300
+ (0, node_test_1.describe)('Fix Flow', () => {
301
+ (0, node_test_1.it)('should return success for empty errors array', async () => {
302
+ const fixer = (0, fixer_js_1.getAutoFixer)({ workingDirectory: TEST_DIR });
303
+ const result = await fixer.fix([]);
304
+ node_assert_1.default.strictEqual(result.success, true);
305
+ node_assert_1.default.strictEqual(result.iterations, 0);
306
+ });
307
+ (0, node_test_1.it)('should return failure when no candidates generated', async () => {
308
+ const fixer = (0, fixer_js_1.getAutoFixer)({ workingDirectory: TEST_DIR });
309
+ const result = await fixer.fix([{
310
+ category: 'unknown',
311
+ severity: 'error',
312
+ message: 'Unknown error type',
313
+ raw: 'Unknown',
314
+ }]);
315
+ node_assert_1.default.strictEqual(result.success, false);
316
+ node_assert_1.default.ok(result.error?.includes('No fix candidates'));
317
+ });
318
+ (0, node_test_1.it)('should track iterations', async () => {
319
+ const filePath = path.join(TEST_DIR, 'iter.ts');
320
+ fs.writeFileSync(filePath, 'const x = 1');
321
+ const fixer = (0, fixer_js_1.getAutoFixer)({
322
+ workingDirectory: TEST_DIR,
323
+ maxIterations: 2,
324
+ testCommand: 'echo "ok"',
325
+ buildCommand: 'echo "ok"',
326
+ });
327
+ const result = await fixer.fix([{
328
+ category: 'syntax',
329
+ severity: 'error',
330
+ message: 'Missing semicolon',
331
+ file: filePath,
332
+ line: 1,
333
+ raw: 'Missing semicolon',
334
+ }]);
335
+ node_assert_1.default.ok(result.iterations >= 1);
336
+ });
337
+ });
338
+ // ==========================================================================
339
+ // Edge Cases
340
+ // ==========================================================================
341
+ (0, node_test_1.describe)('Edge Cases', () => {
342
+ (0, node_test_1.it)('should handle file read errors gracefully', async () => {
343
+ const fixer = (0, fixer_js_1.getAutoFixer)({ workingDirectory: TEST_DIR });
344
+ // Create a directory with the same name as the "file"
345
+ const dirPath = path.join(TEST_DIR, 'not-a-file');
346
+ fs.mkdirSync(dirPath);
347
+ const candidates = await fixer.generateCandidates([{
348
+ category: 'syntax',
349
+ severity: 'error',
350
+ message: 'Error',
351
+ file: dirPath,
352
+ raw: 'Error',
353
+ }]);
354
+ // Should not crash, just return empty
355
+ node_assert_1.default.strictEqual(candidates.length, 0);
356
+ });
357
+ (0, node_test_1.it)('should handle multiple errors in same file', async () => {
358
+ const filePath = path.join(TEST_DIR, 'multi.ts');
359
+ fs.writeFileSync(filePath, 'const x = 1\nconst y = 2');
360
+ const errors = [
361
+ { category: 'syntax', severity: 'error', message: 'Missing semicolon', file: filePath, line: 1, raw: 'Missing semicolon' },
362
+ { category: 'syntax', severity: 'error', message: 'Missing semicolon', file: filePath, line: 2, raw: 'Missing semicolon' },
363
+ ];
364
+ const candidates = await (0, fixer_js_1.generateFixes)(errors[0]);
365
+ // Should generate candidates (deduplication happens at fix level)
366
+ node_assert_1.default.ok(candidates.length >= 0);
367
+ });
368
+ });
369
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Integration Tests for Genesis 5.x Modules
3
+ * Tests Memory, Consciousness, World Model, and Daemon modules
4
+ */
5
+ export {};
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ /**
3
+ * Integration Tests for Genesis 5.x Modules
4
+ * Tests Memory, Consciousness, World Model, and Daemon modules
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const node_test_1 = require("node:test");
11
+ const node_assert_1 = __importDefault(require("node:assert"));
12
+ // Memory Module Tests
13
+ (0, node_test_1.describe)('Memory Module', () => {
14
+ (0, node_test_1.test)('MemorySystem creates and initializes', async () => {
15
+ const { createMemorySystem, resetMemorySystem } = await import('../src/memory/index.js');
16
+ resetMemorySystem();
17
+ const memory = createMemorySystem();
18
+ node_assert_1.default.ok(memory, 'Memory system should be created');
19
+ node_assert_1.default.ok(memory.episodic, 'Episodic store should exist');
20
+ node_assert_1.default.ok(memory.semantic, 'Semantic store should exist');
21
+ node_assert_1.default.ok(memory.procedural, 'Procedural store should exist');
22
+ resetMemorySystem();
23
+ });
24
+ (0, node_test_1.test)('EpisodicStore can store and retrieve memories', async () => {
25
+ const { createEpisodicStore } = await import('../src/memory/episodic.js');
26
+ const store = createEpisodicStore();
27
+ // Store a memory using the convenience method
28
+ const memory = store.createEpisode({
29
+ what: 'Test event happened',
30
+ details: { value: 42 },
31
+ importance: 0.8,
32
+ feeling: { valence: 0.5, arousal: 0.6 },
33
+ where: { location: 'test-location', context: 'testing' },
34
+ who: { agents: ['user'], roles: { user: 'tester' } },
35
+ });
36
+ node_assert_1.default.ok(memory.id, 'Should return memory with ID');
37
+ // Retrieve by ID
38
+ const retrieved = store.get(memory.id);
39
+ node_assert_1.default.ok(retrieved, 'Should retrieve memory');
40
+ node_assert_1.default.strictEqual(retrieved?.content.what, 'Test event happened');
41
+ // Query
42
+ const results = store.query({ minImportance: 0.5 });
43
+ node_assert_1.default.ok(results.length > 0, 'Should find memories with query');
44
+ });
45
+ (0, node_test_1.test)('SemanticStore can store and retrieve facts', async () => {
46
+ const { createSemanticStore } = await import('../src/memory/semantic.js');
47
+ const store = createSemanticStore();
48
+ // Store a fact using the convenience method
49
+ const fact = store.createFact({
50
+ concept: 'Genesis',
51
+ definition: 'An autopoietic system',
52
+ properties: { version: '6.0' },
53
+ category: 'software',
54
+ confidence: 0.95,
55
+ sources: ['specification'],
56
+ });
57
+ node_assert_1.default.ok(fact.id, 'Should return fact with ID');
58
+ // Retrieve
59
+ const retrieved = store.get(fact.id);
60
+ node_assert_1.default.ok(retrieved, 'Should retrieve fact');
61
+ node_assert_1.default.strictEqual(retrieved?.content.concept, 'Genesis');
62
+ });
63
+ (0, node_test_1.test)('ProceduralStore can store and retrieve procedures', async () => {
64
+ const { createProceduralStore } = await import('../src/memory/procedural.js');
65
+ const store = createProceduralStore();
66
+ // Store a procedure using createSkill
67
+ const proc = store.createSkill({
68
+ name: 'test-procedure',
69
+ description: 'A test procedure',
70
+ steps: [
71
+ { action: 'step1' },
72
+ { action: 'step2' },
73
+ ],
74
+ });
75
+ node_assert_1.default.ok(proc.id, 'Should return procedure with ID');
76
+ // Retrieve
77
+ const retrieved = store.getByName('test-procedure');
78
+ node_assert_1.default.ok(retrieved, 'Should retrieve procedure by name');
79
+ node_assert_1.default.strictEqual(retrieved?.content.steps.length, 2, 'Should have 2 steps');
80
+ });
81
+ (0, node_test_1.test)('Forgetting module exports functions', async () => {
82
+ const forgettingModule = await import('../src/memory/forgetting.js');
83
+ // Just verify the module exports what we expect
84
+ node_assert_1.default.ok(forgettingModule.calculateRetention, 'Should export calculateRetention');
85
+ node_assert_1.default.ok(forgettingModule.FORGETTING_THRESHOLDS, 'Should export FORGETTING_THRESHOLDS');
86
+ });
87
+ });
88
+ // Consciousness Module Tests
89
+ (0, node_test_1.describe)('Consciousness Module', () => {
90
+ (0, node_test_1.test)('ConsciousnessSystem creates and initializes', async () => {
91
+ const { createConsciousnessSystem, resetConsciousnessSystem } = await import('../src/consciousness/index.js');
92
+ resetConsciousnessSystem();
93
+ const consciousness = createConsciousnessSystem();
94
+ node_assert_1.default.ok(consciousness, 'Consciousness system should be created');
95
+ // Check components exist
96
+ const state = consciousness.getState();
97
+ node_assert_1.default.ok(state, 'Should have state');
98
+ resetConsciousnessSystem();
99
+ });
100
+ (0, node_test_1.test)('PhiCalculator calculates phi values', async () => {
101
+ const { createPhiCalculator } = await import('../src/consciousness/phi-calculator.js');
102
+ const calculator = createPhiCalculator();
103
+ // Create a system state matching the expected interface
104
+ const state = {
105
+ components: [
106
+ { id: 'node1', type: 'agent', active: true, state: { value: 0.8 }, entropy: 0.5, lastUpdate: new Date() },
107
+ { id: 'node2', type: 'agent', active: true, state: { value: 0.6 }, entropy: 0.4, lastUpdate: new Date() },
108
+ { id: 'node3', type: 'agent', active: true, state: { value: 0.4 }, entropy: 0.3, lastUpdate: new Date() },
109
+ ],
110
+ connections: [
111
+ { from: 'node1', to: 'node2', strength: 0.5, informationFlow: 1.0, bidirectional: true },
112
+ { from: 'node2', to: 'node3', strength: 0.3, informationFlow: 0.8, bidirectional: true },
113
+ { from: 'node3', to: 'node1', strength: 0.4, informationFlow: 0.7, bidirectional: true },
114
+ ],
115
+ stateHash: 'test-hash',
116
+ timestamp: new Date(),
117
+ };
118
+ const result = calculator.calculate(state);
119
+ node_assert_1.default.ok(typeof result.phi === 'number', 'Phi should be a number');
120
+ node_assert_1.default.ok(result.phi >= 0, 'Phi should be non-negative');
121
+ });
122
+ (0, node_test_1.test)('GlobalWorkspace performs selection and broadcast', async () => {
123
+ const { createGlobalWorkspace } = await import('../src/consciousness/global-workspace.js');
124
+ const workspace = createGlobalWorkspace();
125
+ node_assert_1.default.ok(workspace, 'Workspace should be created');
126
+ // Get state
127
+ const state = workspace.getState();
128
+ node_assert_1.default.ok(state, 'Should have state');
129
+ });
130
+ (0, node_test_1.test)('PhiMonitor tracks phi', async () => {
131
+ const { createPhiMonitor } = await import('../src/consciousness/phi-monitor.js');
132
+ const monitor = createPhiMonitor();
133
+ node_assert_1.default.ok(monitor, 'Monitor should be created');
134
+ // Verify it has the methods we need
135
+ node_assert_1.default.ok(typeof monitor.update === 'function', 'Should have update method');
136
+ node_assert_1.default.ok(typeof monitor.getCurrentLevel === 'function', 'Should have getCurrentLevel method');
137
+ });
138
+ (0, node_test_1.test)('PhiDecisionMaker makes decisions', async () => {
139
+ const { createPhiDecisionMaker } = await import('../src/consciousness/phi-decisions.js');
140
+ const decisionMaker = createPhiDecisionMaker();
141
+ node_assert_1.default.ok(decisionMaker, 'Decision maker should be created');
142
+ });
143
+ });
144
+ // World Model Module Tests
145
+ (0, node_test_1.describe)('World Model Module', () => {
146
+ (0, node_test_1.test)('WorldModelSystem creates and initializes', async () => {
147
+ const { createWorldModelSystem, resetWorldModelSystem } = await import('../src/world-model/index.js');
148
+ resetWorldModelSystem();
149
+ const worldModel = createWorldModelSystem();
150
+ node_assert_1.default.ok(worldModel, 'World model system should be created');
151
+ node_assert_1.default.ok(worldModel.encoder, 'Encoder should exist');
152
+ node_assert_1.default.ok(worldModel.decoder, 'Decoder should exist');
153
+ node_assert_1.default.ok(worldModel.predictor, 'Predictor should exist');
154
+ node_assert_1.default.ok(worldModel.twinManager, 'Twin manager should exist');
155
+ resetWorldModelSystem();
156
+ });
157
+ (0, node_test_1.test)('LatentEncoder encodes multimodal inputs', async () => {
158
+ const { createLatentEncoder } = await import('../src/world-model/encoder.js');
159
+ const encoder = createLatentEncoder();
160
+ // Encode text
161
+ const textLatent = encoder.encode({
162
+ modality: 'text',
163
+ data: 'Hello world',
164
+ timestamp: new Date(),
165
+ metadata: {},
166
+ });
167
+ node_assert_1.default.ok(textLatent, 'Should encode text');
168
+ node_assert_1.default.ok(textLatent.vector, 'Should have vector');
169
+ node_assert_1.default.strictEqual(textLatent.vector.length, 512, 'Vector should be 512-dim');
170
+ // Encode state
171
+ const stateLatent = encoder.encode({
172
+ modality: 'state',
173
+ data: { energy: 0.8, phi: 0.6 },
174
+ timestamp: new Date(),
175
+ metadata: {},
176
+ });
177
+ node_assert_1.default.ok(stateLatent, 'Should encode state');
178
+ node_assert_1.default.strictEqual(stateLatent.vector.length, 512, 'Vector should be 512-dim');
179
+ });
180
+ (0, node_test_1.test)('LatentDecoder decodes latent states', async () => {
181
+ const { createLatentEncoder } = await import('../src/world-model/encoder.js');
182
+ const { createLatentDecoder } = await import('../src/world-model/decoder.js');
183
+ const encoder = createLatentEncoder();
184
+ const decoder = createLatentDecoder();
185
+ // Encode then decode
186
+ const latent = encoder.encode({
187
+ modality: 'text',
188
+ data: 'Test content',
189
+ timestamp: new Date(),
190
+ metadata: {},
191
+ });
192
+ const textDecoding = decoder.decodeToText(latent);
193
+ node_assert_1.default.ok(textDecoding, 'Should decode to text');
194
+ node_assert_1.default.ok(textDecoding.confidence >= 0 && textDecoding.confidence <= 1, 'Confidence should be in [0,1]');
195
+ const featureDecoding = decoder.decodeToFeatures(latent);
196
+ node_assert_1.default.ok(featureDecoding, 'Should decode to features');
197
+ });
198
+ (0, node_test_1.test)('WorldModelPredictor exists and initializes', async () => {
199
+ const { createWorldModelPredictor } = await import('../src/world-model/predictor.js');
200
+ const predictor = createWorldModelPredictor();
201
+ node_assert_1.default.ok(predictor, 'Predictor should be created');
202
+ node_assert_1.default.ok(typeof predictor.predict === 'function', 'Should have predict method');
203
+ node_assert_1.default.ok(typeof predictor.simulate === 'function', 'Should have simulate method');
204
+ });
205
+ (0, node_test_1.test)('DigitalTwinManager creates twins', async () => {
206
+ const { createDigitalTwinManager } = await import('../src/world-model/digital-twin.js');
207
+ const manager = createDigitalTwinManager();
208
+ node_assert_1.default.ok(manager, 'Manager should be created');
209
+ const twin = manager.createTwin('test-system', 'Test System');
210
+ node_assert_1.default.ok(twin, 'Should create digital twin');
211
+ node_assert_1.default.strictEqual(twin.name, 'Test System', 'Should have correct name');
212
+ node_assert_1.default.ok(twin.id, 'Should have ID');
213
+ });
214
+ });
215
+ // Daemon Module Tests
216
+ (0, node_test_1.describe)('Daemon Module', () => {
217
+ (0, node_test_1.test)('Scheduler creates and manages tasks', async () => {
218
+ const { createScheduler } = await import('../src/daemon/scheduler.js');
219
+ const scheduler = createScheduler();
220
+ node_assert_1.default.ok(scheduler, 'Scheduler should be created');
221
+ // Add a task with proper schedule format
222
+ const task = scheduler.schedule({
223
+ name: 'test-task',
224
+ schedule: { type: 'interval', intervalMs: 60000 },
225
+ handler: async (ctx) => ({ success: true, duration: 10 }),
226
+ });
227
+ node_assert_1.default.ok(task, 'Should return task');
228
+ node_assert_1.default.ok(task.id, 'Task should have ID');
229
+ // Clean up
230
+ scheduler.cancel(task.id);
231
+ });
232
+ (0, node_test_1.test)('MaintenanceService initializes', async () => {
233
+ const { createMaintenanceService } = await import('../src/daemon/maintenance.js');
234
+ const maintenance = createMaintenanceService();
235
+ node_assert_1.default.ok(maintenance, 'Maintenance service should be created');
236
+ });
237
+ (0, node_test_1.test)('DreamService initializes', async () => {
238
+ const { createDreamService } = await import('../src/daemon/dream-mode.js');
239
+ const dreamService = createDreamService();
240
+ node_assert_1.default.ok(dreamService, 'Dream service should be created');
241
+ });
242
+ });
243
+ // Cross-Module Integration Tests
244
+ (0, node_test_1.describe)('Cross-Module Integration', () => {
245
+ (0, node_test_1.test)('Memory system stores and retrieves', async () => {
246
+ const { createMemorySystem, resetMemorySystem } = await import('../src/memory/index.js');
247
+ resetMemorySystem();
248
+ const memory = createMemorySystem();
249
+ // Store an episodic memory
250
+ const episode = memory.episodic.createEpisode({
251
+ what: 'Integration test event',
252
+ details: { test: true },
253
+ importance: 0.9,
254
+ });
255
+ node_assert_1.default.ok(episode.id, 'Should store episode');
256
+ // Retrieve it
257
+ const retrieved = memory.episodic.get(episode.id);
258
+ node_assert_1.default.ok(retrieved, 'Should retrieve episode');
259
+ resetMemorySystem();
260
+ });
261
+ (0, node_test_1.test)('World Model encodes and decodes', async () => {
262
+ const { createWorldModelSystem, resetWorldModelSystem } = await import('../src/world-model/index.js');
263
+ resetWorldModelSystem();
264
+ const worldModel = createWorldModelSystem();
265
+ // Encode a state
266
+ const latent = worldModel.encode({
267
+ modality: 'state',
268
+ data: { consciousnessLevel: 0.8 },
269
+ timestamp: new Date(),
270
+ metadata: {},
271
+ });
272
+ node_assert_1.default.ok(latent, 'Should encode state');
273
+ node_assert_1.default.strictEqual(latent.vector.length, 512, 'Should have 512-dim vector');
274
+ // Decode back
275
+ const decoded = worldModel.decoder.decodeToText(latent);
276
+ node_assert_1.default.ok(decoded, 'Should decode');
277
+ resetWorldModelSystem();
278
+ });
279
+ (0, node_test_1.test)('All modules can be imported together', async () => {
280
+ const memory = await import('../src/memory/index.js');
281
+ const consciousness = await import('../src/consciousness/index.js');
282
+ const worldModel = await import('../src/world-model/index.js');
283
+ const daemon = await import('../src/daemon/index.js');
284
+ node_assert_1.default.ok(memory.createMemorySystem, 'Memory should export factory');
285
+ node_assert_1.default.ok(consciousness.createConsciousnessSystem, 'Consciousness should export factory');
286
+ node_assert_1.default.ok(worldModel.createWorldModelSystem, 'World model should export factory');
287
+ node_assert_1.default.ok(daemon.createDaemon, 'Daemon should export factory');
288
+ });
289
+ });
290
+ console.log('Running Genesis Integration Tests...\n');
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Tests for Genesis Secure Bash Executor
3
+ */
4
+ export {};