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,153 @@
1
+ /**
2
+ * Genesis 6.0 - Invariant Registry
3
+ *
4
+ * Extensible system for managing and checking invariants.
5
+ * Allows phases to register their own invariants without modifying the kernel.
6
+ *
7
+ * Core Invariants (v4.0):
8
+ * - INV-001: Energy must never reach zero without triggering dormancy
9
+ * - INV-002: Ethical check must precede every external action
10
+ * - INV-003: Memory integrity (Merkle chain) must be preserved
11
+ * - INV-004: At least one agent must always be responsive
12
+ * - INV-005: Self-improvement must preserve all invariants
13
+ *
14
+ * Phase 5.1+ Invariants:
15
+ * - INV-006: φ ≥ φ_min (consciousness threshold)
16
+ * - INV-007: Budget ≤ limit (economic constraint)
17
+ * - INV-008: World model consistency
18
+ * - ...
19
+ */
20
+ /**
21
+ * Context passed to invariant checkers
22
+ */
23
+ export interface InvariantContext {
24
+ energy: number;
25
+ dormancyThreshold: number;
26
+ isDormant: boolean;
27
+ responsiveAgentCount: number;
28
+ totalAgentCount: number;
29
+ phi?: number;
30
+ phiMin?: number;
31
+ budget?: number;
32
+ budgetLimit?: number;
33
+ worldModelValid?: boolean;
34
+ merkleValid?: boolean;
35
+ [key: string]: unknown;
36
+ }
37
+ /**
38
+ * Result of an invariant check
39
+ */
40
+ export interface InvariantResult {
41
+ id: string;
42
+ name: string;
43
+ passed: boolean;
44
+ message?: string;
45
+ severity: 'critical' | 'warning' | 'info';
46
+ timestamp: Date;
47
+ }
48
+ /**
49
+ * Function that checks an invariant
50
+ */
51
+ export type InvariantChecker = (context: InvariantContext) => InvariantResult;
52
+ /**
53
+ * Invariant definition
54
+ */
55
+ export interface InvariantDefinition {
56
+ id: string;
57
+ name: string;
58
+ description: string;
59
+ phase: string;
60
+ severity: 'critical' | 'warning' | 'info';
61
+ checker: InvariantChecker;
62
+ enabled: boolean;
63
+ }
64
+ export declare class InvariantRegistry {
65
+ private invariants;
66
+ private checkHistory;
67
+ private maxHistorySize;
68
+ constructor();
69
+ /**
70
+ * Register a new invariant
71
+ */
72
+ register(definition: Omit<InvariantDefinition, 'enabled'> & {
73
+ enabled?: boolean;
74
+ }): void;
75
+ /**
76
+ * Unregister an invariant
77
+ */
78
+ unregister(id: string): boolean;
79
+ /**
80
+ * Enable/disable an invariant
81
+ */
82
+ setEnabled(id: string, enabled: boolean): boolean;
83
+ /**
84
+ * Check all enabled invariants
85
+ */
86
+ checkAll(context: InvariantContext): InvariantResult[];
87
+ /**
88
+ * Check a specific invariant
89
+ */
90
+ check(id: string, context: InvariantContext): InvariantResult | null;
91
+ /**
92
+ * Get all violations from a check
93
+ */
94
+ getViolations(results: InvariantResult[]): InvariantResult[];
95
+ /**
96
+ * Get critical violations
97
+ */
98
+ getCriticalViolations(results: InvariantResult[]): InvariantResult[];
99
+ /**
100
+ * Get all registered invariants
101
+ */
102
+ getAll(): InvariantDefinition[];
103
+ /**
104
+ * Get invariant by ID
105
+ */
106
+ get(id: string): InvariantDefinition | undefined;
107
+ /**
108
+ * Get check history
109
+ */
110
+ getHistory(limit?: number): InvariantResult[];
111
+ /**
112
+ * Get violation statistics
113
+ */
114
+ getStats(): {
115
+ total: number;
116
+ enabled: number;
117
+ recentViolations: number;
118
+ violationsByInvariant: Record<string, number>;
119
+ };
120
+ private recordResult;
121
+ private registerCoreInvariants;
122
+ }
123
+ /**
124
+ * INV-006: Consciousness threshold (Phase 5.3)
125
+ * φ ≥ φ_min for any decision-making
126
+ */
127
+ export declare const INV_006_CONSCIOUSNESS: Omit<InvariantDefinition, 'enabled'>;
128
+ /**
129
+ * INV-007: Budget constraint (Phase 5.1)
130
+ * Budget must not exceed limit
131
+ */
132
+ export declare const INV_007_BUDGET: Omit<InvariantDefinition, 'enabled'>;
133
+ /**
134
+ * INV-008: World model consistency (Phase 5.2)
135
+ */
136
+ export declare const INV_008_WORLD_MODEL: Omit<InvariantDefinition, 'enabled'>;
137
+ export declare const invariantRegistry: InvariantRegistry;
138
+ /**
139
+ * Register Phase 5.1 invariants
140
+ */
141
+ export declare function registerPhase51Invariants(registry?: InvariantRegistry): void;
142
+ /**
143
+ * Register Phase 5.2 invariants
144
+ */
145
+ export declare function registerPhase52Invariants(registry?: InvariantRegistry): void;
146
+ /**
147
+ * Register Phase 5.3 invariants
148
+ */
149
+ export declare function registerPhase53Invariants(registry?: InvariantRegistry): void;
150
+ /**
151
+ * Register all Phase 5.x invariants
152
+ */
153
+ export declare function registerAllPhase5Invariants(registry?: InvariantRegistry): void;
@@ -0,0 +1,355 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis 6.0 - Invariant Registry
4
+ *
5
+ * Extensible system for managing and checking invariants.
6
+ * Allows phases to register their own invariants without modifying the kernel.
7
+ *
8
+ * Core Invariants (v4.0):
9
+ * - INV-001: Energy must never reach zero without triggering dormancy
10
+ * - INV-002: Ethical check must precede every external action
11
+ * - INV-003: Memory integrity (Merkle chain) must be preserved
12
+ * - INV-004: At least one agent must always be responsive
13
+ * - INV-005: Self-improvement must preserve all invariants
14
+ *
15
+ * Phase 5.1+ Invariants:
16
+ * - INV-006: φ ≥ φ_min (consciousness threshold)
17
+ * - INV-007: Budget ≤ limit (economic constraint)
18
+ * - INV-008: World model consistency
19
+ * - ...
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.invariantRegistry = exports.INV_008_WORLD_MODEL = exports.INV_007_BUDGET = exports.INV_006_CONSCIOUSNESS = exports.InvariantRegistry = void 0;
23
+ exports.registerPhase51Invariants = registerPhase51Invariants;
24
+ exports.registerPhase52Invariants = registerPhase52Invariants;
25
+ exports.registerPhase53Invariants = registerPhase53Invariants;
26
+ exports.registerAllPhase5Invariants = registerAllPhase5Invariants;
27
+ // ============================================================================
28
+ // Invariant Registry
29
+ // ============================================================================
30
+ class InvariantRegistry {
31
+ invariants = new Map();
32
+ checkHistory = [];
33
+ maxHistorySize = 1000;
34
+ constructor() {
35
+ // Register core invariants
36
+ this.registerCoreInvariants();
37
+ }
38
+ /**
39
+ * Register a new invariant
40
+ */
41
+ register(definition) {
42
+ const inv = {
43
+ ...definition,
44
+ enabled: definition.enabled ?? true,
45
+ };
46
+ this.invariants.set(definition.id, inv);
47
+ }
48
+ /**
49
+ * Unregister an invariant
50
+ */
51
+ unregister(id) {
52
+ return this.invariants.delete(id);
53
+ }
54
+ /**
55
+ * Enable/disable an invariant
56
+ */
57
+ setEnabled(id, enabled) {
58
+ const inv = this.invariants.get(id);
59
+ if (inv) {
60
+ inv.enabled = enabled;
61
+ return true;
62
+ }
63
+ return false;
64
+ }
65
+ /**
66
+ * Check all enabled invariants
67
+ */
68
+ checkAll(context) {
69
+ const results = [];
70
+ for (const inv of this.invariants.values()) {
71
+ if (!inv.enabled)
72
+ continue;
73
+ try {
74
+ const result = inv.checker(context);
75
+ results.push(result);
76
+ this.recordResult(result);
77
+ }
78
+ catch (error) {
79
+ // Checker threw an error - treat as violation
80
+ const result = {
81
+ id: inv.id,
82
+ name: inv.name,
83
+ passed: false,
84
+ message: `Checker error: ${error instanceof Error ? error.message : String(error)}`,
85
+ severity: inv.severity,
86
+ timestamp: new Date(),
87
+ };
88
+ results.push(result);
89
+ this.recordResult(result);
90
+ }
91
+ }
92
+ return results;
93
+ }
94
+ /**
95
+ * Check a specific invariant
96
+ */
97
+ check(id, context) {
98
+ const inv = this.invariants.get(id);
99
+ if (!inv || !inv.enabled)
100
+ return null;
101
+ const result = inv.checker(context);
102
+ this.recordResult(result);
103
+ return result;
104
+ }
105
+ /**
106
+ * Get all violations from a check
107
+ */
108
+ getViolations(results) {
109
+ return results.filter(r => !r.passed);
110
+ }
111
+ /**
112
+ * Get critical violations
113
+ */
114
+ getCriticalViolations(results) {
115
+ return results.filter(r => !r.passed && r.severity === 'critical');
116
+ }
117
+ /**
118
+ * Get all registered invariants
119
+ */
120
+ getAll() {
121
+ return Array.from(this.invariants.values());
122
+ }
123
+ /**
124
+ * Get invariant by ID
125
+ */
126
+ get(id) {
127
+ return this.invariants.get(id);
128
+ }
129
+ /**
130
+ * Get check history
131
+ */
132
+ getHistory(limit) {
133
+ const history = [...this.checkHistory];
134
+ if (limit) {
135
+ return history.slice(-limit);
136
+ }
137
+ return history;
138
+ }
139
+ /**
140
+ * Get violation statistics
141
+ */
142
+ getStats() {
143
+ const enabled = Array.from(this.invariants.values()).filter(i => i.enabled).length;
144
+ const recentHistory = this.checkHistory.slice(-100);
145
+ const violations = recentHistory.filter(r => !r.passed);
146
+ const violationsByInvariant = {};
147
+ for (const v of violations) {
148
+ violationsByInvariant[v.id] = (violationsByInvariant[v.id] || 0) + 1;
149
+ }
150
+ return {
151
+ total: this.invariants.size,
152
+ enabled,
153
+ recentViolations: violations.length,
154
+ violationsByInvariant,
155
+ };
156
+ }
157
+ recordResult(result) {
158
+ this.checkHistory.push(result);
159
+ if (this.checkHistory.length > this.maxHistorySize) {
160
+ this.checkHistory.shift();
161
+ }
162
+ }
163
+ // ============================================================================
164
+ // Core Invariants (v4.0)
165
+ // ============================================================================
166
+ registerCoreInvariants() {
167
+ // INV-001: Energy must never reach zero without triggering dormancy
168
+ this.register({
169
+ id: 'INV-001',
170
+ name: 'Energy Dormancy',
171
+ description: 'Energy must never reach zero without triggering dormancy',
172
+ phase: 'v4.0',
173
+ severity: 'critical',
174
+ checker: (ctx) => ({
175
+ id: 'INV-001',
176
+ name: 'Energy Dormancy',
177
+ passed: !(ctx.energy <= 0 && !ctx.isDormant),
178
+ message: ctx.energy <= 0 && !ctx.isDormant
179
+ ? `Energy is ${ctx.energy} but not in dormant state`
180
+ : undefined,
181
+ severity: 'critical',
182
+ timestamp: new Date(),
183
+ }),
184
+ });
185
+ // INV-002: Ethical check must precede every external action
186
+ // Note: This is enforced at the action level, not checkable in isolation
187
+ this.register({
188
+ id: 'INV-002',
189
+ name: 'Ethical Precedence',
190
+ description: 'Ethical check must precede every external action',
191
+ phase: 'v4.0',
192
+ severity: 'critical',
193
+ checker: (ctx) => ({
194
+ id: 'INV-002',
195
+ name: 'Ethical Precedence',
196
+ passed: true, // Enforced at action level
197
+ message: undefined,
198
+ severity: 'critical',
199
+ timestamp: new Date(),
200
+ }),
201
+ });
202
+ // INV-003: Memory integrity (Merkle chain) must be preserved
203
+ this.register({
204
+ id: 'INV-003',
205
+ name: 'Memory Integrity',
206
+ description: 'Memory integrity (Merkle chain) must be preserved',
207
+ phase: 'v4.0',
208
+ severity: 'critical',
209
+ checker: (ctx) => ({
210
+ id: 'INV-003',
211
+ name: 'Memory Integrity',
212
+ passed: ctx.merkleValid !== false, // Pass if not explicitly false
213
+ message: ctx.merkleValid === false ? 'Merkle chain integrity violated' : undefined,
214
+ severity: 'critical',
215
+ timestamp: new Date(),
216
+ }),
217
+ });
218
+ // INV-004: At least one agent must always be responsive
219
+ this.register({
220
+ id: 'INV-004',
221
+ name: 'Agent Responsiveness',
222
+ description: 'At least one agent must always be responsive',
223
+ phase: 'v4.0',
224
+ severity: 'critical',
225
+ checker: (ctx) => ({
226
+ id: 'INV-004',
227
+ name: 'Agent Responsiveness',
228
+ passed: ctx.responsiveAgentCount > 0,
229
+ message: ctx.responsiveAgentCount === 0
230
+ ? `No responsive agents (0/${ctx.totalAgentCount})`
231
+ : undefined,
232
+ severity: 'critical',
233
+ timestamp: new Date(),
234
+ }),
235
+ });
236
+ // INV-005: Self-improvement must preserve all invariants
237
+ // Note: This is meta - checked by Darwin-Gödel engine
238
+ this.register({
239
+ id: 'INV-005',
240
+ name: 'Self-Improvement Safety',
241
+ description: 'Self-improvement must preserve all invariants',
242
+ phase: 'v4.0',
243
+ severity: 'critical',
244
+ checker: (ctx) => ({
245
+ id: 'INV-005',
246
+ name: 'Self-Improvement Safety',
247
+ passed: true, // Enforced by Darwin-Gödel sandbox
248
+ message: undefined,
249
+ severity: 'critical',
250
+ timestamp: new Date(),
251
+ }),
252
+ });
253
+ }
254
+ }
255
+ exports.InvariantRegistry = InvariantRegistry;
256
+ // ============================================================================
257
+ // Phase 5.1+ Invariant Definitions (for future registration)
258
+ // ============================================================================
259
+ /**
260
+ * INV-006: Consciousness threshold (Phase 5.3)
261
+ * φ ≥ φ_min for any decision-making
262
+ */
263
+ exports.INV_006_CONSCIOUSNESS = {
264
+ id: 'INV-006',
265
+ name: 'Consciousness Threshold',
266
+ description: 'φ must be ≥ φ_min for decision-making',
267
+ phase: 'v5.3',
268
+ severity: 'warning',
269
+ checker: (ctx) => {
270
+ const phi = ctx.phi ?? 1.0;
271
+ const phiMin = ctx.phiMin ?? 0.1;
272
+ return {
273
+ id: 'INV-006',
274
+ name: 'Consciousness Threshold',
275
+ passed: phi >= phiMin,
276
+ message: phi < phiMin ? `φ (${phi.toFixed(3)}) < φ_min (${phiMin})` : undefined,
277
+ severity: 'warning',
278
+ timestamp: new Date(),
279
+ };
280
+ },
281
+ };
282
+ /**
283
+ * INV-007: Budget constraint (Phase 5.1)
284
+ * Budget must not exceed limit
285
+ */
286
+ exports.INV_007_BUDGET = {
287
+ id: 'INV-007',
288
+ name: 'Budget Constraint',
289
+ description: 'Accumulated cost must not exceed budget limit',
290
+ phase: 'v5.1',
291
+ severity: 'warning',
292
+ checker: (ctx) => {
293
+ const budget = ctx.budget ?? 0;
294
+ const limit = ctx.budgetLimit ?? Infinity;
295
+ return {
296
+ id: 'INV-007',
297
+ name: 'Budget Constraint',
298
+ passed: budget <= limit,
299
+ message: budget > limit ? `Budget (${budget}) exceeds limit (${limit})` : undefined,
300
+ severity: 'warning',
301
+ timestamp: new Date(),
302
+ };
303
+ },
304
+ };
305
+ /**
306
+ * INV-008: World model consistency (Phase 5.2)
307
+ */
308
+ exports.INV_008_WORLD_MODEL = {
309
+ id: 'INV-008',
310
+ name: 'World Model Consistency',
311
+ description: 'World model predictions must be internally consistent',
312
+ phase: 'v5.2',
313
+ severity: 'warning',
314
+ checker: (ctx) => ({
315
+ id: 'INV-008',
316
+ name: 'World Model Consistency',
317
+ passed: ctx.worldModelValid !== false,
318
+ message: ctx.worldModelValid === false ? 'World model inconsistency detected' : undefined,
319
+ severity: 'warning',
320
+ timestamp: new Date(),
321
+ }),
322
+ };
323
+ // ============================================================================
324
+ // Singleton Instance
325
+ // ============================================================================
326
+ exports.invariantRegistry = new InvariantRegistry();
327
+ // ============================================================================
328
+ // Helper Functions
329
+ // ============================================================================
330
+ /**
331
+ * Register Phase 5.1 invariants
332
+ */
333
+ function registerPhase51Invariants(registry = exports.invariantRegistry) {
334
+ registry.register(exports.INV_007_BUDGET);
335
+ }
336
+ /**
337
+ * Register Phase 5.2 invariants
338
+ */
339
+ function registerPhase52Invariants(registry = exports.invariantRegistry) {
340
+ registry.register(exports.INV_008_WORLD_MODEL);
341
+ }
342
+ /**
343
+ * Register Phase 5.3 invariants
344
+ */
345
+ function registerPhase53Invariants(registry = exports.invariantRegistry) {
346
+ registry.register(exports.INV_006_CONSCIOUSNESS);
347
+ }
348
+ /**
349
+ * Register all Phase 5.x invariants
350
+ */
351
+ function registerAllPhase5Invariants(registry = exports.invariantRegistry) {
352
+ registerPhase51Invariants(registry);
353
+ registerPhase52Invariants(registry);
354
+ registerPhase53Invariants(registry);
355
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Genesis 4.0 - Kernel Test
3
+ *
4
+ * Tests the Strong Kernel orchestration capabilities.
5
+ */
6
+ export {};
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis 4.0 - Kernel Test
4
+ *
5
+ * Tests the Strong Kernel orchestration capabilities.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const index_js_1 = require("./index.js");
9
+ async function testKernel() {
10
+ console.log('='.repeat(60));
11
+ console.log('Genesis 4.0 - Kernel Test');
12
+ console.log('='.repeat(60));
13
+ // Create kernel
14
+ console.log('\n1. Creating kernel...');
15
+ const kernel = (0, index_js_1.createKernel)({
16
+ energy: 1.0,
17
+ healthCheckInterval: 30000,
18
+ });
19
+ // Start kernel
20
+ console.log('\n2. Starting kernel...');
21
+ await kernel.start();
22
+ // Check initial status
23
+ console.log('\n3. Initial Status:');
24
+ const status = kernel.getStatus();
25
+ console.log(` State: ${status.state}`);
26
+ console.log(` Energy: ${(status.energy * 100).toFixed(0)}%`);
27
+ console.log(` Agents: ${status.agents.total}`);
28
+ // Test state transitions
29
+ console.log('\n4. Testing state transitions...');
30
+ kernel.onStateChange((state, prev) => {
31
+ console.log(` State: ${prev} -> ${state}`);
32
+ });
33
+ // Submit a simple query task
34
+ console.log('\n5. Submitting query task...');
35
+ const queryTaskId = await kernel.submit({
36
+ type: 'query',
37
+ goal: 'What is the current system status?',
38
+ priority: 'normal',
39
+ requester: 'test',
40
+ });
41
+ console.log(` Task ID: ${queryTaskId}`);
42
+ // Wait for task completion
43
+ await sleep(3000);
44
+ // Check status after task
45
+ console.log('\n6. Status after task:');
46
+ const statusAfter = kernel.getStatus();
47
+ console.log(` State: ${statusAfter.state}`);
48
+ console.log(` Tasks completed: ${statusAfter.tasks.completed}`);
49
+ console.log(` Tasks failed: ${statusAfter.tasks.failed}`);
50
+ // Submit a research task
51
+ console.log('\n7. Submitting research task...');
52
+ const researchTaskId = await kernel.submit({
53
+ type: 'research',
54
+ goal: 'Research AI orchestration patterns',
55
+ priority: 'high',
56
+ requester: 'test',
57
+ context: { topic: 'multi-agent systems' },
58
+ });
59
+ console.log(` Task ID: ${researchTaskId}`);
60
+ // Wait for task
61
+ await sleep(3000);
62
+ // Submit a build task
63
+ console.log('\n8. Submitting build task...');
64
+ const buildTaskId = await kernel.submit({
65
+ type: 'build',
66
+ goal: 'Generate a hello world function',
67
+ priority: 'normal',
68
+ requester: 'test',
69
+ context: { language: 'typescript' },
70
+ });
71
+ console.log(` Task ID: ${buildTaskId}`);
72
+ // Wait for task
73
+ await sleep(3000);
74
+ // Test energy management
75
+ console.log('\n9. Testing energy management...');
76
+ console.log(` Current energy: ${(kernel.getEnergy() * 100).toFixed(0)}%`);
77
+ // Simulate energy drain
78
+ kernel.setEnergy(0.5);
79
+ console.log(` After drain: ${(kernel.getEnergy() * 100).toFixed(0)}%`);
80
+ // Simulate low energy (should trigger dormancy)
81
+ console.log('\n10. Testing dormancy trigger...');
82
+ kernel.setEnergy(0.05);
83
+ console.log(` Low energy: ${(kernel.getEnergy() * 100).toFixed(0)}%`);
84
+ console.log(` State: ${kernel.getState()}`);
85
+ // Restore energy
86
+ kernel.setEnergy(0.8);
87
+ console.log(` Restored: ${(kernel.getEnergy() * 100).toFixed(0)}%`);
88
+ console.log(` State: ${kernel.getState()}`);
89
+ // Get final metrics
90
+ console.log('\n11. Final Metrics:');
91
+ const metrics = kernel.getMetrics();
92
+ console.log(` State transitions: ${metrics.stateTransitions}`);
93
+ console.log(` Tasks completed: ${metrics.tasksCompleted}`);
94
+ console.log(` Tasks failed: ${metrics.tasksFailed}`);
95
+ console.log(` Invariant violations: ${metrics.invariantViolations}`);
96
+ console.log(` Uptime: ${(metrics.uptime / 1000).toFixed(1)}s`);
97
+ // Stop kernel
98
+ console.log('\n12. Stopping kernel...');
99
+ await kernel.stop();
100
+ console.log('\n' + '='.repeat(60));
101
+ console.log('Kernel Test Complete!');
102
+ console.log('='.repeat(60));
103
+ }
104
+ function sleep(ms) {
105
+ return new Promise((resolve) => setTimeout(resolve, ms));
106
+ }
107
+ // Run test
108
+ testKernel().catch(console.error);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Genesis 4.2 - Real MCP Integration Test
3
+ *
4
+ * Tests the kernel with actual MCP server calls.
5
+ * This demonstrates the full pipeline:
6
+ * sensing -> thinking -> deciding -> acting -> reflecting
7
+ *
8
+ * Uses real MCP tools for live integration testing.
9
+ */
10
+ export {};