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,91 @@
1
+ /**
2
+ * Genesis Phase 10 - Brain Trace System
3
+ *
4
+ * Visual real-time output of Brain internal processing.
5
+ * Shows thinking progress during reasoning.
6
+ *
7
+ * Usage:
8
+ * const trace = new BrainTrace(brain);
9
+ * trace.enable();
10
+ * await brain.process("query");
11
+ * trace.disable();
12
+ */
13
+ import { Brain } from './index.js';
14
+ export interface BrainTraceOptions {
15
+ /** Show timing for each step */
16
+ showTiming?: boolean;
17
+ /** Show detailed data */
18
+ showDetails?: boolean;
19
+ /** Indent level for nested output */
20
+ indent?: number;
21
+ /** Prefix for all output */
22
+ prefix?: string;
23
+ }
24
+ export declare class BrainTrace {
25
+ private brain;
26
+ private options;
27
+ private unsubscribe;
28
+ private enabled;
29
+ private cycleStartTime;
30
+ private currentModule;
31
+ private moduleStartTime;
32
+ constructor(brain: Brain, options?: BrainTraceOptions);
33
+ /**
34
+ * Enable trace output
35
+ */
36
+ enable(): void;
37
+ /**
38
+ * Disable trace output
39
+ */
40
+ disable(): void;
41
+ /**
42
+ * Check if trace is enabled
43
+ */
44
+ isEnabled(): boolean;
45
+ /**
46
+ * Toggle trace on/off
47
+ */
48
+ toggle(): boolean;
49
+ /**
50
+ * Handle brain event
51
+ */
52
+ private handleEvent;
53
+ /**
54
+ * Safely get a value from event.data
55
+ */
56
+ private getData;
57
+ private onCycleStart;
58
+ private onModuleEnter;
59
+ private onModuleExit;
60
+ private onMemoryRecall;
61
+ private onMemoryAnticipate;
62
+ private onLLMRequest;
63
+ private onLLMResponse;
64
+ private onGroundingCheck;
65
+ private onToolExecute;
66
+ private onToolComplete;
67
+ private onHealingStart;
68
+ private onHealingComplete;
69
+ private onPhiUpdate;
70
+ private onBroadcast;
71
+ private onCycleComplete;
72
+ /**
73
+ * Format prefix
74
+ */
75
+ private prefix;
76
+ /**
77
+ * Format detail line (indented)
78
+ */
79
+ private detail;
80
+ /**
81
+ * Truncate string
82
+ */
83
+ private truncate;
84
+ /**
85
+ * Render mini phi bar
86
+ */
87
+ private renderPhiMini;
88
+ }
89
+ export declare function createBrainTrace(brain: Brain, options?: BrainTraceOptions): BrainTrace;
90
+ export declare function getBrainTrace(brain?: Brain): BrainTrace | null;
91
+ export declare function resetBrainTrace(): void;
@@ -0,0 +1,327 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis Phase 10 - Brain Trace System
4
+ *
5
+ * Visual real-time output of Brain internal processing.
6
+ * Shows thinking progress during reasoning.
7
+ *
8
+ * Usage:
9
+ * const trace = new BrainTrace(brain);
10
+ * trace.enable();
11
+ * await brain.process("query");
12
+ * trace.disable();
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BrainTrace = void 0;
16
+ exports.createBrainTrace = createBrainTrace;
17
+ exports.getBrainTrace = getBrainTrace;
18
+ exports.resetBrainTrace = resetBrainTrace;
19
+ // ============================================================================
20
+ // Colors
21
+ // ============================================================================
22
+ const colors = {
23
+ reset: '\x1b[0m',
24
+ bold: '\x1b[1m',
25
+ dim: '\x1b[2m',
26
+ italic: '\x1b[3m',
27
+ cyan: '\x1b[36m',
28
+ green: '\x1b[32m',
29
+ yellow: '\x1b[33m',
30
+ red: '\x1b[31m',
31
+ magenta: '\x1b[35m',
32
+ blue: '\x1b[34m',
33
+ gray: '\x1b[90m',
34
+ white: '\x1b[37m',
35
+ bgBlue: '\x1b[44m',
36
+ bgGray: '\x1b[100m',
37
+ };
38
+ function c(text, ...styles) {
39
+ const codes = styles.map(s => colors[s]).join('');
40
+ return `${codes}${text}${colors.reset}`;
41
+ }
42
+ const MODULE_ICONS = {
43
+ memory: '🧠',
44
+ llm: '💭',
45
+ grounding: '🔍',
46
+ tools: '🔧',
47
+ healing: '🩹',
48
+ consciousness: '✨',
49
+ kernel: '⚙️',
50
+ done: '✓',
51
+ };
52
+ const MODULE_COLORS = {
53
+ memory: 'blue',
54
+ llm: 'cyan',
55
+ grounding: 'yellow',
56
+ tools: 'magenta',
57
+ healing: 'red',
58
+ consciousness: 'green',
59
+ kernel: 'gray',
60
+ done: 'green',
61
+ };
62
+ class BrainTrace {
63
+ brain;
64
+ options;
65
+ unsubscribe = null;
66
+ enabled = false;
67
+ cycleStartTime = 0;
68
+ currentModule = '';
69
+ moduleStartTime = 0;
70
+ constructor(brain, options = {}) {
71
+ this.brain = brain;
72
+ this.options = {
73
+ showTiming: options.showTiming ?? true,
74
+ showDetails: options.showDetails ?? true,
75
+ indent: options.indent ?? 2,
76
+ prefix: options.prefix ?? 'BRAIN',
77
+ };
78
+ }
79
+ /**
80
+ * Enable trace output
81
+ */
82
+ enable() {
83
+ if (this.enabled)
84
+ return;
85
+ this.enabled = true;
86
+ this.unsubscribe = this.brain.on(this.handleEvent.bind(this));
87
+ }
88
+ /**
89
+ * Disable trace output
90
+ */
91
+ disable() {
92
+ if (!this.enabled)
93
+ return;
94
+ this.enabled = false;
95
+ if (this.unsubscribe) {
96
+ this.unsubscribe();
97
+ this.unsubscribe = null;
98
+ }
99
+ }
100
+ /**
101
+ * Check if trace is enabled
102
+ */
103
+ isEnabled() {
104
+ return this.enabled;
105
+ }
106
+ /**
107
+ * Toggle trace on/off
108
+ */
109
+ toggle() {
110
+ if (this.enabled) {
111
+ this.disable();
112
+ }
113
+ else {
114
+ this.enable();
115
+ }
116
+ return this.enabled;
117
+ }
118
+ /**
119
+ * Handle brain event
120
+ */
121
+ handleEvent(event) {
122
+ switch (event.type) {
123
+ case 'cycle_start':
124
+ this.onCycleStart(event);
125
+ break;
126
+ case 'module_enter':
127
+ this.onModuleEnter(event);
128
+ break;
129
+ case 'module_exit':
130
+ this.onModuleExit(event);
131
+ break;
132
+ case 'memory_recall':
133
+ this.onMemoryRecall(event);
134
+ break;
135
+ case 'memory_anticipate':
136
+ this.onMemoryAnticipate(event);
137
+ break;
138
+ case 'llm_request':
139
+ this.onLLMRequest(event);
140
+ break;
141
+ case 'llm_response':
142
+ this.onLLMResponse(event);
143
+ break;
144
+ case 'grounding_check':
145
+ this.onGroundingCheck(event);
146
+ break;
147
+ case 'tool_execute':
148
+ this.onToolExecute(event);
149
+ break;
150
+ case 'tool_complete':
151
+ this.onToolComplete(event);
152
+ break;
153
+ case 'healing_start':
154
+ this.onHealingStart(event);
155
+ break;
156
+ case 'healing_complete':
157
+ this.onHealingComplete(event);
158
+ break;
159
+ case 'phi_update':
160
+ this.onPhiUpdate(event);
161
+ break;
162
+ case 'broadcast':
163
+ this.onBroadcast(event);
164
+ break;
165
+ case 'cycle_complete':
166
+ this.onCycleComplete(event);
167
+ break;
168
+ }
169
+ }
170
+ // ==========================================================================
171
+ // Event Handlers
172
+ // ==========================================================================
173
+ /**
174
+ * Safely get a value from event.data
175
+ */
176
+ getData(event, key, defaultValue) {
177
+ const data = event.data;
178
+ if (data && key in data) {
179
+ return data[key];
180
+ }
181
+ return defaultValue;
182
+ }
183
+ onCycleStart(event) {
184
+ this.cycleStartTime = Date.now();
185
+ const query = this.getData(event, 'query', '');
186
+ const truncatedQuery = query.length > 50 ? query.substring(0, 50) + '...' : query;
187
+ console.log();
188
+ console.log(this.prefix() + c(' Processing: ', 'bold') + c(`"${truncatedQuery}"`, 'white'));
189
+ console.log(this.prefix() + c(' ─'.repeat(30), 'dim'));
190
+ }
191
+ onModuleEnter(event) {
192
+ const module = event.module || this.getData(event, 'module', 'unknown');
193
+ this.currentModule = module;
194
+ this.moduleStartTime = Date.now();
195
+ const icon = MODULE_ICONS[module] || '•';
196
+ const color = MODULE_COLORS[module] || 'white';
197
+ const moduleName = module.charAt(0).toUpperCase() + module.slice(1);
198
+ console.log(this.prefix() + c(' → ', 'dim') + icon + ' ' + c(moduleName, color, 'bold'));
199
+ }
200
+ onModuleExit(_event) {
201
+ // Module exit is handled implicitly by next module enter or cycle complete
202
+ }
203
+ onMemoryRecall(event) {
204
+ const query = this.getData(event, 'query', '');
205
+ console.log(this.detail(`recall("${this.truncate(query, 30)}")`));
206
+ }
207
+ onMemoryAnticipate(event) {
208
+ const items = this.getData(event, 'items', 0);
209
+ if (items > 0) {
210
+ console.log(this.detail(`↳ anticipated ${items} item(s)`, 'green'));
211
+ }
212
+ }
213
+ onLLMRequest(_event) {
214
+ console.log(this.detail('generating response...'));
215
+ }
216
+ onLLMResponse(event) {
217
+ const length = this.getData(event, 'length', 0);
218
+ const time = this.options.showTiming ? ` (${Date.now() - this.moduleStartTime}ms)` : '';
219
+ console.log(this.detail(`↳ ${length} chars${time}`, 'green'));
220
+ }
221
+ onGroundingCheck(_event) {
222
+ console.log(this.detail('verifying claims...'));
223
+ }
224
+ onToolExecute(event) {
225
+ const count = this.getData(event, 'count', 0);
226
+ console.log(this.detail(`executing ${count} tool(s)...`));
227
+ }
228
+ onToolComplete(event) {
229
+ const results = this.getData(event, 'results', 0);
230
+ const time = this.options.showTiming ? ` (${Date.now() - this.moduleStartTime}ms)` : '';
231
+ console.log(this.detail(`↳ ${results} result(s)${time}`, 'green'));
232
+ }
233
+ onHealingStart(event) {
234
+ const error = this.getData(event, 'error', 'unknown');
235
+ console.log(this.detail(`error: ${this.truncate(String(error), 40)}`, 'red'));
236
+ }
237
+ onHealingComplete(event) {
238
+ const success = this.getData(event, 'success', false);
239
+ if (success) {
240
+ console.log(this.detail('↳ healed successfully', 'green'));
241
+ }
242
+ else {
243
+ console.log(this.detail('↳ healing failed', 'red'));
244
+ }
245
+ }
246
+ onPhiUpdate(event) {
247
+ const phi = this.getData(event, 'phi', 0);
248
+ const bar = this.renderPhiMini(phi);
249
+ const status = phi > 0.3 ? c('ignited', 'green') : c('local', 'dim');
250
+ console.log(this.detail(`φ=${phi.toFixed(2)} ${bar} ${status}`));
251
+ }
252
+ onBroadcast(event) {
253
+ const source = this.getData(event, 'source', 'unknown');
254
+ console.log(this.detail(`↳ broadcast from ${source}`, 'cyan'));
255
+ }
256
+ onCycleComplete(event) {
257
+ const transitions = this.getData(event, 'transitions', 0);
258
+ const totalTime = Date.now() - this.cycleStartTime;
259
+ const state = this.getData(event, 'state', null);
260
+ // Final phi status
261
+ const phi = state?.phi ?? 0;
262
+ const phiStatus = phi > 0.3 ? c('✨ ignited', 'green') : c('◌ local', 'dim');
263
+ console.log(this.prefix() + c(' ─'.repeat(30), 'dim'));
264
+ console.log(this.prefix() + c(' ✓ ', 'green', 'bold') +
265
+ c(`Done`, 'green') +
266
+ c(` (${totalTime}ms, ${transitions} transitions, ${phiStatus})`, 'dim'));
267
+ console.log();
268
+ }
269
+ // ==========================================================================
270
+ // Helpers
271
+ // ==========================================================================
272
+ /**
273
+ * Format prefix
274
+ */
275
+ prefix() {
276
+ return c(`[${this.options.prefix}]`, 'cyan', 'bold');
277
+ }
278
+ /**
279
+ * Format detail line (indented)
280
+ */
281
+ detail(text, color = 'dim') {
282
+ const indent = ' '.repeat(this.options.indent + 4);
283
+ return this.prefix() + indent + c(text, color);
284
+ }
285
+ /**
286
+ * Truncate string
287
+ */
288
+ truncate(str, max) {
289
+ if (str.length <= max)
290
+ return str;
291
+ return str.substring(0, max) + '...';
292
+ }
293
+ /**
294
+ * Render mini phi bar
295
+ */
296
+ renderPhiMini(phi) {
297
+ const width = 10;
298
+ const filled = Math.round(phi * width);
299
+ const empty = width - filled;
300
+ if (phi >= 0.7)
301
+ return c('█'.repeat(filled), 'green') + c('░'.repeat(empty), 'dim');
302
+ if (phi >= 0.3)
303
+ return c('█'.repeat(filled), 'yellow') + c('░'.repeat(empty), 'dim');
304
+ return c('█'.repeat(filled), 'gray') + c('░'.repeat(empty), 'dim');
305
+ }
306
+ }
307
+ exports.BrainTrace = BrainTrace;
308
+ // ============================================================================
309
+ // Factory
310
+ // ============================================================================
311
+ function createBrainTrace(brain, options) {
312
+ return new BrainTrace(brain, options);
313
+ }
314
+ // Singleton instance management
315
+ let traceInstance = null;
316
+ function getBrainTrace(brain) {
317
+ if (!traceInstance && brain) {
318
+ traceInstance = createBrainTrace(brain);
319
+ }
320
+ return traceInstance;
321
+ }
322
+ function resetBrainTrace() {
323
+ if (traceInstance) {
324
+ traceInstance.disable();
325
+ traceInstance = null;
326
+ }
327
+ }
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Genesis Phase 10 - Brain Module Types
3
+ *
4
+ * Neural Integration Layer - connects all 17 modules.
5
+ *
6
+ * Based on:
7
+ * - arXiv:2508.13171 (Cognitive Workspace) - 54-60% memory reuse
8
+ * - LangGraph Supervisor Pattern - Command({ goto, update })
9
+ * - IWMT (Integrated World Modeling Theory) - GWT + IIT + Active Inference
10
+ *
11
+ * The Brain orchestrates:
12
+ * 1. Cognitive Workspace (active memory)
13
+ * 2. Supervisor (command routing)
14
+ * 3. Global Workspace (broadcasting)
15
+ * 4. Healing Loop (error recovery)
16
+ */
17
+ /**
18
+ * Modules that can be routed to
19
+ */
20
+ export type BrainModule = 'memory' | 'llm' | 'grounding' | 'tools' | 'healing' | 'consciousness' | 'kernel' | 'done';
21
+ /**
22
+ * Command for routing between modules
23
+ * Inspired by LangGraph's Command primitive
24
+ */
25
+ export interface Command {
26
+ goto: BrainModule;
27
+ update: Partial<BrainState>;
28
+ reason?: string;
29
+ }
30
+ /**
31
+ * State maintained during brain processing cycle
32
+ */
33
+ export interface BrainState {
34
+ query: string;
35
+ context: BrainContext;
36
+ response: string;
37
+ toolCalls: ToolCall[];
38
+ toolResults: ToolResult[];
39
+ phi: number;
40
+ ignited: boolean;
41
+ verified: boolean;
42
+ groundingFeedback?: string;
43
+ error?: Error;
44
+ healingAttempts: number;
45
+ startTime: number;
46
+ moduleHistory: BrainModule[];
47
+ }
48
+ /**
49
+ * Context retrieved from cognitive workspace
50
+ */
51
+ export interface BrainContext {
52
+ immediate: ContextItem[];
53
+ task: ContextItem[];
54
+ episodic: ContextItem[];
55
+ semantic: ContextItem[];
56
+ formatted: string;
57
+ tokenEstimate: number;
58
+ reuseRate: number;
59
+ }
60
+ export interface ContextItem {
61
+ id: string;
62
+ type: 'immediate' | 'task' | 'episodic' | 'semantic';
63
+ content: string;
64
+ relevance: number;
65
+ activation: number;
66
+ source: string;
67
+ }
68
+ export interface ToolCall {
69
+ name: string;
70
+ parameters: Record<string, unknown>;
71
+ raw: string;
72
+ }
73
+ export interface ToolResult {
74
+ name: string;
75
+ success: boolean;
76
+ data?: unknown;
77
+ error?: string;
78
+ duration: number;
79
+ }
80
+ export interface GroundingCheck {
81
+ valid: boolean;
82
+ confidence: number;
83
+ feedback: string;
84
+ domain: 'factual' | 'mathematical' | 'ethical' | 'existential' | 'aesthetic' | 'novel';
85
+ needsHuman: boolean;
86
+ humanQuestion?: string;
87
+ }
88
+ export interface HealingResult {
89
+ canRetry: boolean;
90
+ retryFrom: BrainModule;
91
+ context: string;
92
+ userMessage: string;
93
+ fixApplied?: string;
94
+ }
95
+ export interface GlobalBroadcast {
96
+ content: unknown;
97
+ source: BrainModule;
98
+ salience: number;
99
+ timestamp: Date;
100
+ }
101
+ export interface BrainConfig {
102
+ memory: {
103
+ enabled: boolean;
104
+ anticipationEnabled: boolean;
105
+ maxContextTokens: number;
106
+ };
107
+ llm: {
108
+ enabled: boolean;
109
+ maxRetries: number;
110
+ };
111
+ grounding: {
112
+ enabled: boolean;
113
+ verifyAllResponses: boolean;
114
+ confidenceThreshold: number;
115
+ };
116
+ tools: {
117
+ enabled: boolean;
118
+ maxExecutions: number;
119
+ };
120
+ healing: {
121
+ enabled: boolean;
122
+ maxAttempts: number;
123
+ autoHeal: boolean;
124
+ };
125
+ consciousness: {
126
+ enabled: boolean;
127
+ phiThreshold: number;
128
+ broadcastEnabled: boolean;
129
+ };
130
+ maxCycleTime: number;
131
+ maxModuleTransitions: number;
132
+ }
133
+ export declare const DEFAULT_BRAIN_CONFIG: BrainConfig;
134
+ export interface BrainMetrics {
135
+ totalCycles: number;
136
+ successfulCycles: number;
137
+ failedCycles: number;
138
+ avgCycleTime: number;
139
+ memoryRecalls: number;
140
+ memoryReuseRate: number;
141
+ anticipationHits: number;
142
+ anticipationMisses: number;
143
+ groundingChecks: number;
144
+ groundingPasses: number;
145
+ groundingFailures: number;
146
+ humanConsultations: number;
147
+ toolExecutions: number;
148
+ toolSuccesses: number;
149
+ toolFailures: number;
150
+ healingAttempts: number;
151
+ healingSuccesses: number;
152
+ healingFailures: number;
153
+ avgPhi: number;
154
+ phiViolations: number;
155
+ broadcasts: number;
156
+ moduleTransitions: Record<string, number>;
157
+ }
158
+ export type BrainEventType = 'cycle_start' | 'cycle_complete' | 'cycle_error' | 'module_enter' | 'module_exit' | 'memory_recall' | 'memory_anticipate' | 'llm_request' | 'llm_response' | 'grounding_check' | 'tool_execute' | 'tool_complete' | 'healing_start' | 'healing_complete' | 'broadcast' | 'phi_update';
159
+ export interface BrainEvent {
160
+ type: BrainEventType;
161
+ timestamp: Date;
162
+ data: unknown;
163
+ module?: BrainModule;
164
+ }
165
+ export type BrainEventHandler = (event: BrainEvent) => void;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis Phase 10 - Brain Module Types
4
+ *
5
+ * Neural Integration Layer - connects all 17 modules.
6
+ *
7
+ * Based on:
8
+ * - arXiv:2508.13171 (Cognitive Workspace) - 54-60% memory reuse
9
+ * - LangGraph Supervisor Pattern - Command({ goto, update })
10
+ * - IWMT (Integrated World Modeling Theory) - GWT + IIT + Active Inference
11
+ *
12
+ * The Brain orchestrates:
13
+ * 1. Cognitive Workspace (active memory)
14
+ * 2. Supervisor (command routing)
15
+ * 3. Global Workspace (broadcasting)
16
+ * 4. Healing Loop (error recovery)
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.DEFAULT_BRAIN_CONFIG = void 0;
20
+ exports.DEFAULT_BRAIN_CONFIG = {
21
+ memory: {
22
+ enabled: true,
23
+ anticipationEnabled: true,
24
+ maxContextTokens: 8192,
25
+ },
26
+ llm: {
27
+ enabled: true,
28
+ maxRetries: 2,
29
+ },
30
+ grounding: {
31
+ enabled: true,
32
+ verifyAllResponses: false, // v7.2: Only verify when explicitly requested (was too aggressive)
33
+ confidenceThreshold: 0.3, // v7.2: Lowered from 0.5 to reduce false positives
34
+ },
35
+ tools: {
36
+ enabled: true,
37
+ maxExecutions: 5,
38
+ },
39
+ healing: {
40
+ enabled: true,
41
+ maxAttempts: 3,
42
+ autoHeal: true,
43
+ },
44
+ consciousness: {
45
+ enabled: true,
46
+ phiThreshold: 0.1,
47
+ broadcastEnabled: true,
48
+ },
49
+ maxCycleTime: 300000, // 5 minutes (MCP cold starts can be slow)
50
+ maxModuleTransitions: 20,
51
+ };