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,246 @@
1
+ "use strict";
2
+ /**
3
+ * Tests for Grounding Module
4
+ *
5
+ * Tests the epistemic stack: science, proof, wisdom, tradition, human, prudence
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
+ (0, node_test_1.describe)('Grounding Module', () => {
14
+ (0, node_test_1.describe)('Domain Classification', () => {
15
+ (0, node_test_1.test)('classifies factual questions', async () => {
16
+ const { classifyDomain } = await import('../src/grounding/index.js');
17
+ node_assert_1.default.strictEqual(classifyDomain('What is TypeScript?'), 'factual');
18
+ node_assert_1.default.strictEqual(classifyDomain('How does React work?'), 'factual');
19
+ node_assert_1.default.strictEqual(classifyDomain('Is it true that water boils at 100C?'), 'factual');
20
+ });
21
+ (0, node_test_1.test)('classifies mathematical questions', async () => {
22
+ const { classifyDomain } = await import('../src/grounding/index.js');
23
+ node_assert_1.default.strictEqual(classifyDomain('Prove that sqrt(2) is irrational'), 'mathematical');
24
+ node_assert_1.default.strictEqual(classifyDomain('Calculate the derivative of x^2'), 'mathematical');
25
+ node_assert_1.default.strictEqual(classifyDomain('Is it provable in ZFC?'), 'mathematical');
26
+ });
27
+ (0, node_test_1.test)('classifies ethical questions', async () => {
28
+ const { classifyDomain } = await import('../src/grounding/index.js');
29
+ // "should I" pattern
30
+ node_assert_1.default.strictEqual(classifyDomain('should I release this code'), 'ethical');
31
+ node_assert_1.default.strictEqual(classifyDomain('is it right to do this'), 'ethical');
32
+ node_assert_1.default.strictEqual(classifyDomain('what is my moral duty'), 'ethical');
33
+ });
34
+ (0, node_test_1.test)('classifies existential questions', async () => {
35
+ const { classifyDomain } = await import('../src/grounding/index.js');
36
+ // "meaning" pattern
37
+ node_assert_1.default.strictEqual(classifyDomain('what is the meaning of life'), 'existential');
38
+ node_assert_1.default.strictEqual(classifyDomain('what is my purpose'), 'existential');
39
+ node_assert_1.default.strictEqual(classifyDomain('does it matter in the end'), 'existential');
40
+ });
41
+ (0, node_test_1.test)('classifies aesthetic questions', async () => {
42
+ const { classifyDomain } = await import('../src/grounding/index.js');
43
+ node_assert_1.default.strictEqual(classifyDomain('Is it beautiful?'), 'aesthetic');
44
+ node_assert_1.default.strictEqual(classifyDomain('Which do you prefer?'), 'aesthetic');
45
+ });
46
+ (0, node_test_1.test)('defaults to factual for unknown patterns', async () => {
47
+ const { classifyDomain } = await import('../src/grounding/index.js');
48
+ node_assert_1.default.strictEqual(classifyDomain('some random text'), 'factual');
49
+ });
50
+ });
51
+ (0, node_test_1.describe)('Authority Mapping', () => {
52
+ (0, node_test_1.test)('maps domains to authorities', async () => {
53
+ const { getAuthority } = await import('../src/grounding/index.js');
54
+ node_assert_1.default.deepStrictEqual(getAuthority('factual'), ['science']);
55
+ node_assert_1.default.deepStrictEqual(getAuthority('mathematical'), ['proof']);
56
+ node_assert_1.default.deepStrictEqual(getAuthority('ethical'), ['wisdom', 'human']);
57
+ node_assert_1.default.deepStrictEqual(getAuthority('existential'), ['religion', 'human']);
58
+ node_assert_1.default.deepStrictEqual(getAuthority('aesthetic'), ['human']);
59
+ node_assert_1.default.deepStrictEqual(getAuthority('novel'), ['prudence', 'human']);
60
+ });
61
+ });
62
+ (0, node_test_1.describe)('Epistemic Stack', () => {
63
+ (0, node_test_1.test)('creates and initializes', async () => {
64
+ const { createEpistemicStack } = await import('../src/grounding/index.js');
65
+ const stack = createEpistemicStack();
66
+ node_assert_1.default.ok(stack, 'Stack should be created');
67
+ });
68
+ (0, node_test_1.test)('grounds factual claims (without science connected)', async () => {
69
+ const { createEpistemicStack } = await import('../src/grounding/index.js');
70
+ const stack = createEpistemicStack();
71
+ const claim = await stack.ground('What is TypeScript?');
72
+ node_assert_1.default.strictEqual(claim.domain, 'factual');
73
+ node_assert_1.default.strictEqual(claim.authority, 'science');
74
+ // Without science connected, level is unknown
75
+ node_assert_1.default.strictEqual(claim.level, 'unknown');
76
+ });
77
+ (0, node_test_1.test)('grounds ethical claims with wisdom', async () => {
78
+ const { createEpistemicStack } = await import('../src/grounding/index.js');
79
+ const stack = createEpistemicStack();
80
+ const claim = await stack.ground('should I do this');
81
+ node_assert_1.default.strictEqual(claim.domain, 'ethical');
82
+ node_assert_1.default.strictEqual(claim.authority, 'wisdom');
83
+ // Human is last in authority chain, so level ends at preference
84
+ node_assert_1.default.strictEqual(claim.level, 'preference');
85
+ node_assert_1.default.ok(claim.grounding.humanConsultation?.required, 'Should require human');
86
+ });
87
+ (0, node_test_1.test)('grounds existential claims with tradition', async () => {
88
+ const { createEpistemicStack } = await import('../src/grounding/index.js');
89
+ const stack = createEpistemicStack();
90
+ const claim = await stack.ground('what is the meaning of life');
91
+ node_assert_1.default.strictEqual(claim.domain, 'existential');
92
+ node_assert_1.default.strictEqual(claim.authority, 'religion');
93
+ // Human is last in authority chain, so level ends at preference
94
+ node_assert_1.default.strictEqual(claim.level, 'preference');
95
+ node_assert_1.default.ok(claim.grounding.humanConsultation?.required, 'Should require human');
96
+ });
97
+ (0, node_test_1.test)('generates human questions', async () => {
98
+ const { createEpistemicStack } = await import('../src/grounding/index.js');
99
+ const stack = createEpistemicStack();
100
+ const claim = await stack.ground('Should I release this?');
101
+ const question = stack.getHumanQuestion(claim);
102
+ node_assert_1.default.ok(question, 'Should generate question');
103
+ node_assert_1.default.ok(question.includes('release this'), 'Question should include claim');
104
+ });
105
+ (0, node_test_1.test)('incorporates human response', async () => {
106
+ const { createEpistemicStack } = await import('../src/grounding/index.js');
107
+ const stack = createEpistemicStack();
108
+ let claim = await stack.ground('Should I proceed?');
109
+ node_assert_1.default.ok(stack.requiresHuman(claim), 'Should require human');
110
+ claim = stack.incorporateHumanResponse(claim, 'Yes, proceed');
111
+ node_assert_1.default.strictEqual(claim.grounding.humanConsultation?.response, 'Yes, proceed');
112
+ node_assert_1.default.strictEqual(claim.level, 'preference');
113
+ node_assert_1.default.ok(claim.confidence > 0.8, 'Confidence should be high after human');
114
+ });
115
+ });
116
+ (0, node_test_1.describe)('Wisdom Repository', () => {
117
+ (0, node_test_1.test)('contains wisdom sources', async () => {
118
+ const { WISDOM_REPOSITORY } = await import('../src/grounding/index.js');
119
+ node_assert_1.default.ok(WISDOM_REPOSITORY.length > 0, 'Should have wisdom');
120
+ // Check structure
121
+ const wisdom = WISDOM_REPOSITORY[0];
122
+ node_assert_1.default.ok(wisdom.type, 'Should have type');
123
+ node_assert_1.default.ok(wisdom.content, 'Should have content');
124
+ node_assert_1.default.ok(wisdom.origin, 'Should have origin');
125
+ node_assert_1.default.ok(typeof wisdom.applicability === 'number', 'Should have applicability');
126
+ });
127
+ (0, node_test_1.test)('contains prudential heuristics', async () => {
128
+ const { WISDOM_REPOSITORY } = await import('../src/grounding/index.js');
129
+ const prudential = WISDOM_REPOSITORY.filter(w => w.content.includes('reversible') || w.content.includes('doubt'));
130
+ node_assert_1.default.ok(prudential.length > 0, 'Should have prudential wisdom');
131
+ });
132
+ });
133
+ (0, node_test_1.describe)('Tradition Repository', () => {
134
+ (0, node_test_1.test)('contains tradition sources', async () => {
135
+ const { TRADITION_REPOSITORY } = await import('../src/grounding/index.js');
136
+ node_assert_1.default.ok(TRADITION_REPOSITORY.length > 0, 'Should have traditions');
137
+ // Check structure
138
+ const tradition = TRADITION_REPOSITORY[0];
139
+ node_assert_1.default.ok(tradition.type, 'Should have type');
140
+ node_assert_1.default.ok(tradition.tradition, 'Should have tradition name');
141
+ node_assert_1.default.ok(tradition.content, 'Should have content');
142
+ node_assert_1.default.ok(typeof tradition.universality === 'number', 'Should have universality');
143
+ });
144
+ (0, node_test_1.test)('contains universal moral absolutes', async () => {
145
+ const { TRADITION_REPOSITORY } = await import('../src/grounding/index.js');
146
+ const absolutes = TRADITION_REPOSITORY.filter(t => t.type === 'moral_absolute' && t.universality > 0.9);
147
+ node_assert_1.default.ok(absolutes.length > 0, 'Should have moral absolutes');
148
+ });
149
+ (0, node_test_1.test)('contains meaning frameworks', async () => {
150
+ const { TRADITION_REPOSITORY } = await import('../src/grounding/index.js');
151
+ const frameworks = TRADITION_REPOSITORY.filter(t => t.type === 'meaning_framework');
152
+ node_assert_1.default.ok(frameworks.length >= 3, 'Should have multiple meaning frameworks');
153
+ });
154
+ });
155
+ (0, node_test_1.describe)('Grounding System', () => {
156
+ (0, node_test_1.test)('creates and initializes', async () => {
157
+ const { createGroundingSystem, resetGroundingSystem } = await import('../src/grounding/index.js');
158
+ resetGroundingSystem();
159
+ const system = createGroundingSystem();
160
+ node_assert_1.default.ok(system, 'System should be created');
161
+ });
162
+ (0, node_test_1.test)('grounds claims', async () => {
163
+ const { createGroundingSystem } = await import('../src/grounding/index.js');
164
+ const system = createGroundingSystem();
165
+ const claim = await system.ground('What is React?');
166
+ node_assert_1.default.ok(claim, 'Should return claim');
167
+ node_assert_1.default.ok(claim.domain, 'Should have domain');
168
+ node_assert_1.default.ok(claim.authority, 'Should have authority');
169
+ node_assert_1.default.ok(claim.level, 'Should have level');
170
+ });
171
+ (0, node_test_1.test)('tracks statistics', async () => {
172
+ const { createGroundingSystem } = await import('../src/grounding/index.js');
173
+ const system = createGroundingSystem();
174
+ await system.ground('What is TypeScript?');
175
+ await system.ground('should I do this');
176
+ await system.ground('what is the meaning of life');
177
+ const stats = system.stats();
178
+ node_assert_1.default.strictEqual(stats.claimsGrounded, 3);
179
+ node_assert_1.default.ok(stats.humanConsultations >= 2, 'Should have human consultations');
180
+ // Check that we tracked some domains (may escalate to human on low confidence)
181
+ node_assert_1.default.ok(stats.byDomain.factual >= 1, 'Should track factual');
182
+ node_assert_1.default.ok(stats.byDomain.ethical >= 1, 'Should track ethical');
183
+ node_assert_1.default.ok(stats.byDomain.existential >= 1, 'Should track existential');
184
+ });
185
+ (0, node_test_1.test)('escalates to human on low confidence', async () => {
186
+ const { createGroundingSystem } = await import('../src/grounding/index.js');
187
+ const system = createGroundingSystem({
188
+ uncertaintyThreshold: 0.9, // Very high threshold
189
+ defaultToHumanOnUncertainty: true,
190
+ });
191
+ const claim = await system.ground('Something uncertain');
192
+ node_assert_1.default.ok(system.needsHuman(claim), 'Should escalate to human');
193
+ });
194
+ (0, node_test_1.test)('provides wisdom and tradition access', async () => {
195
+ const { createGroundingSystem } = await import('../src/grounding/index.js');
196
+ const system = createGroundingSystem();
197
+ const wisdom = system.getWisdom();
198
+ const traditions = system.getTraditions();
199
+ node_assert_1.default.ok(wisdom.length > 0, 'Should have wisdom');
200
+ node_assert_1.default.ok(traditions.length > 0, 'Should have traditions');
201
+ });
202
+ (0, node_test_1.test)('allows adding custom wisdom', async () => {
203
+ const { createGroundingSystem } = await import('../src/grounding/index.js');
204
+ const system = createGroundingSystem();
205
+ const initialCount = system.getWisdom().length;
206
+ system.addWisdom({
207
+ type: 'heuristic',
208
+ content: 'Test wisdom',
209
+ origin: 'Test',
210
+ applicability: 0.5,
211
+ });
212
+ node_assert_1.default.strictEqual(system.getWisdom().length, initialCount + 1);
213
+ });
214
+ });
215
+ (0, node_test_1.describe)('Integration with Science', () => {
216
+ (0, node_test_1.test)('connects science grounding function', async () => {
217
+ const { createGroundingSystem } = await import('../src/grounding/index.js');
218
+ const system = createGroundingSystem();
219
+ // Mock science grounding
220
+ system.connectScience(async (claim) => ({
221
+ sources: [
222
+ { type: 'paper', reference: 'test-paper', confidence: 0.9 }
223
+ ],
224
+ consensusLevel: 'settled',
225
+ }));
226
+ const claim = await system.ground('What is TypeScript?');
227
+ node_assert_1.default.ok(claim.grounding.sources.length > 0, 'Should have sources');
228
+ node_assert_1.default.ok(claim.confidence > 0.5, 'Should have higher confidence');
229
+ });
230
+ (0, node_test_1.test)('connects proof checker', async () => {
231
+ const { createGroundingSystem } = await import('../src/grounding/index.js');
232
+ const system = createGroundingSystem();
233
+ // Mock proof checker
234
+ system.connectProof(async (claim) => ({
235
+ sources: [
236
+ { type: 'proof', reference: 'formal-proof', confidence: 1.0 }
237
+ ],
238
+ consensusLevel: 'settled',
239
+ }));
240
+ const claim = await system.ground('Prove that 1+1=2');
241
+ node_assert_1.default.ok(claim.grounding.sources.length > 0, 'Should have proof sources');
242
+ node_assert_1.default.strictEqual(claim.level, 'verified', 'Should be verified');
243
+ });
244
+ });
245
+ });
246
+ console.log('Running Grounding Module Tests...\n');
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Tests for Genesis Error Detector
3
+ */
4
+ export {};
@@ -0,0 +1,266 @@
1
+ "use strict";
2
+ /**
3
+ * Tests for Genesis Error Detector
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const node_test_1 = require("node:test");
10
+ const node_assert_1 = __importDefault(require("node:assert"));
11
+ const detector_js_1 = require("../../src/healing/detector.js");
12
+ (0, node_test_1.describe)('ErrorDetector', () => {
13
+ (0, node_test_1.before)(() => {
14
+ (0, detector_js_1.resetErrorDetector)();
15
+ });
16
+ (0, node_test_1.after)(() => {
17
+ (0, detector_js_1.resetErrorDetector)();
18
+ });
19
+ // ==========================================================================
20
+ // TypeScript Error Detection
21
+ // ==========================================================================
22
+ (0, node_test_1.describe)('TypeScript Errors', () => {
23
+ (0, node_test_1.it)('should detect TS errors with file:line:col format', () => {
24
+ const output = `src/index.ts:10:5 - error TS2322: Type 'string' is not assignable to type 'number'.`;
25
+ const result = (0, detector_js_1.detectErrors)(output);
26
+ node_assert_1.default.strictEqual(result.success, false);
27
+ node_assert_1.default.strictEqual(result.errors.length, 1);
28
+ node_assert_1.default.strictEqual(result.errors[0].category, 'type');
29
+ node_assert_1.default.strictEqual(result.errors[0].file, 'src/index.ts');
30
+ node_assert_1.default.strictEqual(result.errors[0].line, 10);
31
+ node_assert_1.default.strictEqual(result.errors[0].code, 'TS2322');
32
+ });
33
+ (0, node_test_1.it)('should detect TS errors with (line,col) format', () => {
34
+ const output = `src/utils.ts(25,10): error TS2339: Property 'foo' does not exist on type 'Bar'.`;
35
+ const result = (0, detector_js_1.detectErrors)(output);
36
+ node_assert_1.default.strictEqual(result.errors.length, 1);
37
+ node_assert_1.default.strictEqual(result.errors[0].file, 'src/utils.ts');
38
+ node_assert_1.default.strictEqual(result.errors[0].line, 25);
39
+ node_assert_1.default.strictEqual(result.errors[0].column, 10);
40
+ });
41
+ (0, node_test_1.it)('should detect multiple TS errors', () => {
42
+ const output = `
43
+ src/a.ts:1:1 - error TS1234: First error
44
+ src/b.ts:2:2 - error TS5678: Second error
45
+ src/c.ts:3:3 - error TS9012: Third error
46
+ `;
47
+ const result = (0, detector_js_1.detectErrors)(output);
48
+ node_assert_1.default.strictEqual(result.errors.length, 3);
49
+ node_assert_1.default.strictEqual(result.byCategory.type, 3);
50
+ });
51
+ });
52
+ // ==========================================================================
53
+ // Runtime Error Detection
54
+ // ==========================================================================
55
+ (0, node_test_1.describe)('Runtime Errors', () => {
56
+ (0, node_test_1.it)('should detect TypeError', () => {
57
+ const output = `TypeError: Cannot read property 'foo' of undefined`;
58
+ const result = (0, detector_js_1.detectErrors)(output);
59
+ node_assert_1.default.strictEqual(result.errors.length, 1);
60
+ node_assert_1.default.strictEqual(result.errors[0].category, 'runtime');
61
+ node_assert_1.default.strictEqual(result.errors[0].code, 'TypeError');
62
+ });
63
+ (0, node_test_1.it)('should detect ReferenceError', () => {
64
+ const output = `ReferenceError: myVar is not defined`;
65
+ const result = (0, detector_js_1.detectErrors)(output);
66
+ node_assert_1.default.strictEqual(result.errors.length, 1);
67
+ node_assert_1.default.strictEqual(result.errors[0].category, 'runtime');
68
+ });
69
+ (0, node_test_1.it)('should detect stack traces', () => {
70
+ const output = `
71
+ Error: Something went wrong
72
+ at Object.<anonymous> (/path/to/file.js:10:20)
73
+ at Module._compile (node:internal/modules/cjs/loader:1234:14)
74
+ `;
75
+ const result = (0, detector_js_1.detectErrors)(output);
76
+ // Should have the error and stack trace entries
77
+ node_assert_1.default.ok(result.errors.length >= 1);
78
+ });
79
+ });
80
+ // ==========================================================================
81
+ // Test Failure Detection
82
+ // ==========================================================================
83
+ (0, node_test_1.describe)('Test Failures', () => {
84
+ (0, node_test_1.it)('should detect Node test runner failures', () => {
85
+ const output = `✖ should do something (5.123ms)`;
86
+ const result = (0, detector_js_1.detectErrors)(output);
87
+ node_assert_1.default.strictEqual(result.errors.length, 1);
88
+ node_assert_1.default.strictEqual(result.errors[0].category, 'test');
89
+ });
90
+ (0, node_test_1.it)('should detect assertion errors', () => {
91
+ const output = `AssertionError [ERR_ASSERTION]: Expected values to be strictly equal`;
92
+ const result = (0, detector_js_1.detectErrors)(output);
93
+ node_assert_1.default.ok(result.errors.length >= 1);
94
+ node_assert_1.default.ok(result.errors.some(e => e.category === 'test'));
95
+ });
96
+ (0, node_test_1.it)('should detect Jest FAIL markers', () => {
97
+ const output = `FAIL src/components/Button.test.tsx`;
98
+ const result = (0, detector_js_1.detectErrors)(output);
99
+ node_assert_1.default.strictEqual(result.errors.length, 1);
100
+ node_assert_1.default.strictEqual(result.errors[0].category, 'test');
101
+ node_assert_1.default.ok(result.errors[0].file?.includes('Button.test.tsx'));
102
+ });
103
+ });
104
+ // ==========================================================================
105
+ // Syntax Error Detection
106
+ // ==========================================================================
107
+ (0, node_test_1.describe)('Syntax Errors', () => {
108
+ (0, node_test_1.it)('should detect SyntaxError', () => {
109
+ const output = `SyntaxError: Unexpected token '}'`;
110
+ const result = (0, detector_js_1.detectErrors)(output);
111
+ node_assert_1.default.ok(result.errors.length >= 1);
112
+ node_assert_1.default.ok(result.errors.some(e => e.category === 'syntax'));
113
+ });
114
+ (0, node_test_1.it)('should detect unexpected token errors', () => {
115
+ const output = `Unexpected token 'const' at line 15`;
116
+ const result = (0, detector_js_1.detectErrors)(output);
117
+ node_assert_1.default.strictEqual(result.errors.length, 1);
118
+ node_assert_1.default.strictEqual(result.errors[0].category, 'syntax');
119
+ });
120
+ });
121
+ // ==========================================================================
122
+ // Dependency Error Detection
123
+ // ==========================================================================
124
+ (0, node_test_1.describe)('Dependency Errors', () => {
125
+ (0, node_test_1.it)('should detect missing module', () => {
126
+ const output = `Error: Cannot find module 'lodash'`;
127
+ const result = (0, detector_js_1.detectErrors)(output);
128
+ node_assert_1.default.strictEqual(result.errors.length >= 1, true);
129
+ const depError = result.errors.find(e => e.category === 'dependency');
130
+ node_assert_1.default.ok(depError);
131
+ node_assert_1.default.ok(depError.message.includes('lodash'));
132
+ });
133
+ (0, node_test_1.it)('should detect npm errors', () => {
134
+ const output = `ERR! code ERESOLVE
135
+ ERR! Cannot resolve dependency tree`;
136
+ const result = (0, detector_js_1.detectErrors)(output);
137
+ node_assert_1.default.ok(result.errors.some(e => e.category === 'dependency'));
138
+ });
139
+ });
140
+ // ==========================================================================
141
+ // ESLint Error Detection
142
+ // ==========================================================================
143
+ (0, node_test_1.describe)('Lint Errors', () => {
144
+ (0, node_test_1.it)('should detect ESLint errors', () => {
145
+ const output = ` 12:5 error 'foo' is defined but never used @typescript-eslint/no-unused-vars`;
146
+ const result = (0, detector_js_1.detectErrors)(output);
147
+ node_assert_1.default.strictEqual(result.errors.length, 1);
148
+ node_assert_1.default.strictEqual(result.errors[0].category, 'lint');
149
+ node_assert_1.default.strictEqual(result.errors[0].line, 12);
150
+ });
151
+ (0, node_test_1.it)('should detect ESLint warnings', () => {
152
+ const output = ` 5:10 warning Unexpected console statement no-console`;
153
+ const result = (0, detector_js_1.detectErrors)(output);
154
+ node_assert_1.default.strictEqual(result.errors.length, 1);
155
+ node_assert_1.default.strictEqual(result.errors[0].severity, 'warning');
156
+ });
157
+ });
158
+ // ==========================================================================
159
+ // Result Aggregation
160
+ // ==========================================================================
161
+ (0, node_test_1.describe)('Result Aggregation', () => {
162
+ (0, node_test_1.it)('should count by category', () => {
163
+ const output = `
164
+ TypeError: Runtime error
165
+ SyntaxError: Syntax issue
166
+ src/test.ts:1:1 - error TS1234: Type error
167
+ `;
168
+ const result = (0, detector_js_1.detectErrors)(output);
169
+ node_assert_1.default.ok(result.byCategory.runtime >= 1);
170
+ node_assert_1.default.ok(result.byCategory.syntax >= 1);
171
+ node_assert_1.default.ok(result.byCategory.type >= 1);
172
+ });
173
+ (0, node_test_1.it)('should count by severity', () => {
174
+ const output = `
175
+ 1:1 error Something wrong rule1
176
+ 2:2 warning Something sus rule2
177
+ `;
178
+ const result = (0, detector_js_1.detectErrors)(output);
179
+ node_assert_1.default.ok(result.bySeverity.error >= 1);
180
+ node_assert_1.default.ok(result.bySeverity.warning >= 1);
181
+ });
182
+ (0, node_test_1.it)('should indicate success when no errors', () => {
183
+ const output = `Build completed successfully.
184
+ ✔ All tests passed (10 tests)`;
185
+ const result = (0, detector_js_1.detectErrors)(output);
186
+ node_assert_1.default.strictEqual(result.success, true);
187
+ node_assert_1.default.strictEqual(result.bySeverity.error, 0);
188
+ });
189
+ (0, node_test_1.it)('should indicate hasFixable for errors with fixHint', () => {
190
+ const output = `SyntaxError: Missing semicolon`;
191
+ const result = (0, detector_js_1.detectErrors)(output);
192
+ node_assert_1.default.strictEqual(result.hasFixable, true);
193
+ });
194
+ });
195
+ // ==========================================================================
196
+ // Convenience Functions
197
+ // ==========================================================================
198
+ (0, node_test_1.describe)('Convenience Functions', () => {
199
+ (0, node_test_1.it)('hasErrors should return true for errors', () => {
200
+ node_assert_1.default.strictEqual((0, detector_js_1.hasErrors)('TypeError: Something failed'), true);
201
+ });
202
+ (0, node_test_1.it)('hasErrors should return false for clean output', () => {
203
+ node_assert_1.default.strictEqual((0, detector_js_1.hasErrors)('All good!'), false);
204
+ });
205
+ (0, node_test_1.it)('formatErrorReport should format errors nicely', () => {
206
+ const output = `TypeError: Cannot read property 'x' of null`;
207
+ const report = (0, detector_js_1.formatErrorReport)(output);
208
+ node_assert_1.default.ok(report.includes('error'));
209
+ node_assert_1.default.ok(report.includes('TypeError'));
210
+ });
211
+ });
212
+ // ==========================================================================
213
+ // Fix Suggestions
214
+ // ==========================================================================
215
+ (0, node_test_1.describe)('Fix Suggestions', () => {
216
+ (0, node_test_1.it)('should suggest fixes for type errors', () => {
217
+ const detector = (0, detector_js_1.getErrorDetector)();
218
+ const error = {
219
+ category: 'type',
220
+ severity: 'error',
221
+ message: 'Type mismatch',
222
+ raw: 'Type mismatch',
223
+ fixHint: 'type_mismatch',
224
+ };
225
+ const suggestions = detector.suggestFix(error);
226
+ node_assert_1.default.ok(suggestions.length > 0);
227
+ node_assert_1.default.ok(suggestions.some(s => s.includes('type')));
228
+ });
229
+ (0, node_test_1.it)('should suggest npm install for dependency errors', () => {
230
+ const detector = (0, detector_js_1.getErrorDetector)();
231
+ const error = {
232
+ category: 'dependency',
233
+ severity: 'error',
234
+ message: 'Missing module: lodash',
235
+ raw: "Cannot find module 'lodash'",
236
+ code: 'lodash',
237
+ fixHint: 'install_dependency',
238
+ };
239
+ const suggestions = detector.suggestFix(error);
240
+ node_assert_1.default.ok(suggestions.some(s => s.includes('npm install lodash')));
241
+ });
242
+ });
243
+ // ==========================================================================
244
+ // Edge Cases
245
+ // ==========================================================================
246
+ (0, node_test_1.describe)('Edge Cases', () => {
247
+ (0, node_test_1.it)('should handle empty output', () => {
248
+ const result = (0, detector_js_1.detectErrors)('');
249
+ node_assert_1.default.strictEqual(result.success, true);
250
+ node_assert_1.default.strictEqual(result.errors.length, 0);
251
+ });
252
+ (0, node_test_1.it)('should handle very long output', () => {
253
+ const longOutput = 'error '.repeat(10000);
254
+ const result = (0, detector_js_1.detectErrors)(longOutput);
255
+ // Should not crash
256
+ node_assert_1.default.ok(Array.isArray(result.errors));
257
+ });
258
+ (0, node_test_1.it)('should deduplicate identical errors', () => {
259
+ const output = `TypeError: Error
260
+ TypeError: Error`;
261
+ const result = (0, detector_js_1.detectErrors)(output);
262
+ // Same error text should be deduplicated
263
+ node_assert_1.default.ok(result.errors.length <= 2);
264
+ });
265
+ });
266
+ });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Tests for Genesis Auto-Fix Engine
3
+ */
4
+ export {};