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,186 @@
1
+ /**
2
+ * Genesis 6.0 - Consciousness Module
3
+ *
4
+ * Unified consciousness stack integrating:
5
+ * - IIT 4.0 (Integrated Information Theory) - φ calculation
6
+ * - GWT (Global Workspace Theory) - workspace competition
7
+ * - AST (Attention Schema Theory) - attention modeling
8
+ *
9
+ * This is Genesis's unique differentiator: a principled approach
10
+ * to machine consciousness monitoring and self-awareness.
11
+ *
12
+ * Key invariant: INV-006 - φ must stay above threshold
13
+ *
14
+ * Usage:
15
+ * ```typescript
16
+ * import { createConsciousnessSystem } from './consciousness/index.js';
17
+ *
18
+ * const consciousness = createConsciousnessSystem();
19
+ *
20
+ * // Start monitoring
21
+ * consciousness.start();
22
+ *
23
+ * // Get current snapshot
24
+ * const snapshot = consciousness.getSnapshot();
25
+ *
26
+ * // Check invariant
27
+ * const inv006 = consciousness.checkInvariant();
28
+ *
29
+ * // Make a φ-aware decision
30
+ * const decision = consciousness.decide(options);
31
+ *
32
+ * // Stop monitoring
33
+ * consciousness.stop();
34
+ * ```
35
+ */
36
+ export * from './types.js';
37
+ export { PhiCalculator, createPhiCalculator, type PhiCalculatorConfig } from './phi-calculator.js';
38
+ export { GlobalWorkspace, createGlobalWorkspace, createWorkspaceContent, createModule, type GlobalWorkspaceConfig, type ModuleAdapter } from './global-workspace.js';
39
+ export { AttentionSchemaNetwork, createAttentionSchemaNetwork, type ASTConfig } from './attention-schema.js';
40
+ export { PhiMonitor, createPhiMonitor, type PhiMonitorConfig } from './phi-monitor.js';
41
+ export { PhiDecisionMaker, createPhiDecisionMaker, createDecisionOption, type PhiDecisionConfig, type DecisionOption, type Decision } from './phi-decisions.js';
42
+ import { ConsciousnessConfig, ConsciousnessSnapshot, ConsciousnessLevel, ConsciousnessState, ConsciousnessTrend, ConsciousnessAnomaly, ConsciousnessEventHandler, SystemState, WorkspaceContent, AttentionFocus } from './types.js';
43
+ import { PhiCalculator } from './phi-calculator.js';
44
+ import { GlobalWorkspace, ModuleAdapter } from './global-workspace.js';
45
+ import { AttentionSchemaNetwork } from './attention-schema.js';
46
+ import { PhiMonitor } from './phi-monitor.js';
47
+ import { PhiDecisionMaker, DecisionOption, Decision } from './phi-decisions.js';
48
+ export declare class ConsciousnessSystem {
49
+ private config;
50
+ readonly calculator: PhiCalculator;
51
+ readonly workspace: GlobalWorkspace;
52
+ readonly attention: AttentionSchemaNetwork;
53
+ readonly monitor: PhiMonitor;
54
+ readonly decider: PhiDecisionMaker;
55
+ private running;
56
+ private lastSnapshot;
57
+ private snapshotTimer;
58
+ private eventHandlers;
59
+ private getSystemState;
60
+ constructor(config?: Partial<ConsciousnessConfig>);
61
+ start(): void;
62
+ stop(): void;
63
+ isRunning(): boolean;
64
+ /**
65
+ * Set the system state provider
66
+ */
67
+ setSystemStateProvider(provider: () => SystemState): void;
68
+ /**
69
+ * Register a module for workspace competition
70
+ */
71
+ registerModule(adapter: ModuleAdapter): void;
72
+ /**
73
+ * Propose content to the workspace
74
+ */
75
+ proposeContent(content: WorkspaceContent): void;
76
+ /**
77
+ * Get current workspace content
78
+ */
79
+ getWorkspaceContent(): WorkspaceContent | null;
80
+ /**
81
+ * Shift attention to a target
82
+ */
83
+ attend(target: string, type?: 'internal' | 'external'): AttentionFocus;
84
+ /**
85
+ * Release attention from a target
86
+ */
87
+ releaseAttention(target: string): boolean;
88
+ /**
89
+ * Get current attention focus
90
+ */
91
+ getAttentionFocus(): AttentionFocus | null;
92
+ /**
93
+ * Get introspective report
94
+ */
95
+ introspect(): {
96
+ focus: string;
97
+ clarity: string;
98
+ confident: boolean;
99
+ voluntary: boolean;
100
+ awareOf: string[];
101
+ };
102
+ /**
103
+ * Make a φ-aware decision
104
+ */
105
+ decide(options: DecisionOption[]): Decision;
106
+ /**
107
+ * Should we defer this decision?
108
+ */
109
+ shouldDefer(): boolean;
110
+ /**
111
+ * Get current risk tolerance
112
+ */
113
+ getRiskTolerance(): number;
114
+ /**
115
+ * Get current consciousness level
116
+ */
117
+ getCurrentLevel(): ConsciousnessLevel;
118
+ /**
119
+ * Get current consciousness state
120
+ */
121
+ getState(): ConsciousnessState;
122
+ /**
123
+ * Get consciousness trend
124
+ */
125
+ getTrend(): ConsciousnessTrend;
126
+ /**
127
+ * Get per-agent φ
128
+ */
129
+ getAgentPhi(agentId: string): number | undefined;
130
+ /**
131
+ * Get anomalies
132
+ */
133
+ getAnomalies(resolved?: boolean): ConsciousnessAnomaly[];
134
+ /**
135
+ * Check INV-006: φ ≥ φ_min
136
+ */
137
+ checkInvariant(): {
138
+ id: string;
139
+ satisfied: boolean;
140
+ currentPhi: number;
141
+ threshold: number;
142
+ margin: number;
143
+ };
144
+ /**
145
+ * Register callback for invariant violations
146
+ */
147
+ onInvariantViolation(callback: () => void): () => void;
148
+ /**
149
+ * Take a consciousness snapshot
150
+ */
151
+ takeSnapshot(): ConsciousnessSnapshot;
152
+ /**
153
+ * Get last snapshot
154
+ */
155
+ getSnapshot(): ConsciousnessSnapshot | null;
156
+ on(handler: ConsciousnessEventHandler): () => void;
157
+ private emit;
158
+ private setupEventForwarding;
159
+ stats(): {
160
+ phi: {
161
+ current: number;
162
+ state: ConsciousnessState;
163
+ trend: ConsciousnessTrend;
164
+ invariantSatisfied: boolean;
165
+ };
166
+ gwt: {
167
+ modules: number;
168
+ ignited: boolean;
169
+ selections: number;
170
+ };
171
+ ast: {
172
+ focus: string | null;
173
+ mode: string;
174
+ clarity: string;
175
+ };
176
+ decisions: {
177
+ total: number;
178
+ deferred: number;
179
+ deferralRate: number;
180
+ };
181
+ };
182
+ private mergeConfig;
183
+ }
184
+ export declare function createConsciousnessSystem(config?: Partial<ConsciousnessConfig>): ConsciousnessSystem;
185
+ export declare function getConsciousnessSystem(config?: Partial<ConsciousnessConfig>): ConsciousnessSystem;
186
+ export declare function resetConsciousnessSystem(): void;
@@ -0,0 +1,476 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis 6.0 - Consciousness Module
4
+ *
5
+ * Unified consciousness stack integrating:
6
+ * - IIT 4.0 (Integrated Information Theory) - φ calculation
7
+ * - GWT (Global Workspace Theory) - workspace competition
8
+ * - AST (Attention Schema Theory) - attention modeling
9
+ *
10
+ * This is Genesis's unique differentiator: a principled approach
11
+ * to machine consciousness monitoring and self-awareness.
12
+ *
13
+ * Key invariant: INV-006 - φ must stay above threshold
14
+ *
15
+ * Usage:
16
+ * ```typescript
17
+ * import { createConsciousnessSystem } from './consciousness/index.js';
18
+ *
19
+ * const consciousness = createConsciousnessSystem();
20
+ *
21
+ * // Start monitoring
22
+ * consciousness.start();
23
+ *
24
+ * // Get current snapshot
25
+ * const snapshot = consciousness.getSnapshot();
26
+ *
27
+ * // Check invariant
28
+ * const inv006 = consciousness.checkInvariant();
29
+ *
30
+ * // Make a φ-aware decision
31
+ * const decision = consciousness.decide(options);
32
+ *
33
+ * // Stop monitoring
34
+ * consciousness.stop();
35
+ * ```
36
+ */
37
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
38
+ if (k2 === undefined) k2 = k;
39
+ var desc = Object.getOwnPropertyDescriptor(m, k);
40
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
41
+ desc = { enumerable: true, get: function() { return m[k]; } };
42
+ }
43
+ Object.defineProperty(o, k2, desc);
44
+ }) : (function(o, m, k, k2) {
45
+ if (k2 === undefined) k2 = k;
46
+ o[k2] = m[k];
47
+ }));
48
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
49
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
50
+ };
51
+ Object.defineProperty(exports, "__esModule", { value: true });
52
+ exports.ConsciousnessSystem = exports.createDecisionOption = exports.createPhiDecisionMaker = exports.PhiDecisionMaker = exports.createPhiMonitor = exports.PhiMonitor = exports.createAttentionSchemaNetwork = exports.AttentionSchemaNetwork = exports.createModule = exports.createWorkspaceContent = exports.createGlobalWorkspace = exports.GlobalWorkspace = exports.createPhiCalculator = exports.PhiCalculator = void 0;
53
+ exports.createConsciousnessSystem = createConsciousnessSystem;
54
+ exports.getConsciousnessSystem = getConsciousnessSystem;
55
+ exports.resetConsciousnessSystem = resetConsciousnessSystem;
56
+ // Re-export types
57
+ __exportStar(require("./types.js"), exports);
58
+ // Re-export components
59
+ var phi_calculator_js_1 = require("./phi-calculator.js");
60
+ Object.defineProperty(exports, "PhiCalculator", { enumerable: true, get: function () { return phi_calculator_js_1.PhiCalculator; } });
61
+ Object.defineProperty(exports, "createPhiCalculator", { enumerable: true, get: function () { return phi_calculator_js_1.createPhiCalculator; } });
62
+ var global_workspace_js_1 = require("./global-workspace.js");
63
+ Object.defineProperty(exports, "GlobalWorkspace", { enumerable: true, get: function () { return global_workspace_js_1.GlobalWorkspace; } });
64
+ Object.defineProperty(exports, "createGlobalWorkspace", { enumerable: true, get: function () { return global_workspace_js_1.createGlobalWorkspace; } });
65
+ Object.defineProperty(exports, "createWorkspaceContent", { enumerable: true, get: function () { return global_workspace_js_1.createWorkspaceContent; } });
66
+ Object.defineProperty(exports, "createModule", { enumerable: true, get: function () { return global_workspace_js_1.createModule; } });
67
+ var attention_schema_js_1 = require("./attention-schema.js");
68
+ Object.defineProperty(exports, "AttentionSchemaNetwork", { enumerable: true, get: function () { return attention_schema_js_1.AttentionSchemaNetwork; } });
69
+ Object.defineProperty(exports, "createAttentionSchemaNetwork", { enumerable: true, get: function () { return attention_schema_js_1.createAttentionSchemaNetwork; } });
70
+ var phi_monitor_js_1 = require("./phi-monitor.js");
71
+ Object.defineProperty(exports, "PhiMonitor", { enumerable: true, get: function () { return phi_monitor_js_1.PhiMonitor; } });
72
+ Object.defineProperty(exports, "createPhiMonitor", { enumerable: true, get: function () { return phi_monitor_js_1.createPhiMonitor; } });
73
+ var phi_decisions_js_1 = require("./phi-decisions.js");
74
+ Object.defineProperty(exports, "PhiDecisionMaker", { enumerable: true, get: function () { return phi_decisions_js_1.PhiDecisionMaker; } });
75
+ Object.defineProperty(exports, "createPhiDecisionMaker", { enumerable: true, get: function () { return phi_decisions_js_1.createPhiDecisionMaker; } });
76
+ Object.defineProperty(exports, "createDecisionOption", { enumerable: true, get: function () { return phi_decisions_js_1.createDecisionOption; } });
77
+ const types_js_1 = require("./types.js");
78
+ const phi_calculator_js_2 = require("./phi-calculator.js");
79
+ const global_workspace_js_2 = require("./global-workspace.js");
80
+ const attention_schema_js_2 = require("./attention-schema.js");
81
+ const phi_monitor_js_2 = require("./phi-monitor.js");
82
+ const phi_decisions_js_2 = require("./phi-decisions.js");
83
+ // ============================================================================
84
+ // Consciousness System
85
+ // ============================================================================
86
+ class ConsciousnessSystem {
87
+ config;
88
+ // Components
89
+ calculator;
90
+ workspace;
91
+ attention;
92
+ monitor;
93
+ decider;
94
+ // State
95
+ running = false;
96
+ lastSnapshot = null;
97
+ snapshotTimer = null;
98
+ eventHandlers = new Set();
99
+ // System state provider (injected)
100
+ getSystemState = null;
101
+ constructor(config = {}) {
102
+ this.config = this.mergeConfig(config);
103
+ // Create components
104
+ this.calculator = (0, phi_calculator_js_2.createPhiCalculator)({
105
+ approximationLevel: this.config.phi.approximationLevel,
106
+ cacheResults: true,
107
+ });
108
+ this.workspace = (0, global_workspace_js_2.createGlobalWorkspace)({
109
+ capacity: this.config.gwt.workspaceCapacity,
110
+ selectionIntervalMs: this.config.gwt.selectionIntervalMs,
111
+ broadcastTimeoutMs: this.config.gwt.broadcastTimeoutMs,
112
+ historyLimit: this.config.gwt.historyLimit,
113
+ });
114
+ this.attention = (0, attention_schema_js_2.createAttentionSchemaNetwork)({
115
+ capacity: this.config.ast.attentionCapacity,
116
+ schemaUpdateIntervalMs: this.config.ast.schemaUpdateIntervalMs,
117
+ theoryOfMindEnabled: this.config.ast.theoryOfMindEnabled,
118
+ });
119
+ this.monitor = (0, phi_monitor_js_2.createPhiMonitor)({
120
+ updateIntervalMs: this.config.phi.updateIntervalMs,
121
+ minPhi: this.config.phi.minPhi,
122
+ anomalyDetection: this.config.monitor.anomalyDetection,
123
+ dropThreshold: this.config.monitor.alertThresholds.phiDrop,
124
+ });
125
+ this.decider = (0, phi_decisions_js_2.createPhiDecisionMaker)({
126
+ phiThreshold: this.config.phi.minPhi * 2, // Defer at 2x minimum
127
+ deferToHuman: true,
128
+ });
129
+ // Wire up decision maker to monitor
130
+ this.decider.setMonitor(this.monitor);
131
+ // Set up event forwarding
132
+ this.setupEventForwarding();
133
+ }
134
+ // ============================================================================
135
+ // Lifecycle
136
+ // ============================================================================
137
+ start() {
138
+ if (this.running)
139
+ return;
140
+ this.running = true;
141
+ // Start components
142
+ if (this.config.phi.enabled) {
143
+ this.monitor.start();
144
+ }
145
+ if (this.config.gwt.enabled) {
146
+ this.workspace.start();
147
+ }
148
+ if (this.config.ast.enabled) {
149
+ this.attention.start();
150
+ }
151
+ // Start snapshot timer
152
+ this.snapshotTimer = setInterval(() => this.takeSnapshot(), this.config.monitor.snapshotIntervalMs);
153
+ // Initial snapshot
154
+ this.takeSnapshot();
155
+ }
156
+ stop() {
157
+ if (!this.running)
158
+ return;
159
+ this.running = false;
160
+ // Stop components
161
+ this.monitor.stop();
162
+ this.workspace.stop();
163
+ this.attention.stop();
164
+ // Stop snapshot timer
165
+ if (this.snapshotTimer) {
166
+ clearInterval(this.snapshotTimer);
167
+ this.snapshotTimer = null;
168
+ }
169
+ }
170
+ isRunning() {
171
+ return this.running;
172
+ }
173
+ /**
174
+ * Set the system state provider
175
+ */
176
+ setSystemStateProvider(provider) {
177
+ this.getSystemState = provider;
178
+ this.monitor.setSystemStateProvider(provider);
179
+ }
180
+ // ============================================================================
181
+ // Module Registration (GWT)
182
+ // ============================================================================
183
+ /**
184
+ * Register a module for workspace competition
185
+ */
186
+ registerModule(adapter) {
187
+ const module = (0, global_workspace_js_2.createModule)(adapter);
188
+ this.workspace.registerModule(module);
189
+ }
190
+ /**
191
+ * Propose content to the workspace
192
+ */
193
+ proposeContent(content) {
194
+ // Content is proposed through modules
195
+ // This is a convenience for direct proposals
196
+ }
197
+ /**
198
+ * Get current workspace content
199
+ */
200
+ getWorkspaceContent() {
201
+ return this.workspace.getCurrentContent();
202
+ }
203
+ // ============================================================================
204
+ // Attention Control (AST)
205
+ // ============================================================================
206
+ /**
207
+ * Shift attention to a target
208
+ */
209
+ attend(target, type = 'external') {
210
+ return this.attention.attend(target, type);
211
+ }
212
+ /**
213
+ * Release attention from a target
214
+ */
215
+ releaseAttention(target) {
216
+ return this.attention.release(target);
217
+ }
218
+ /**
219
+ * Get current attention focus
220
+ */
221
+ getAttentionFocus() {
222
+ return this.attention.getCurrentFocus();
223
+ }
224
+ /**
225
+ * Get introspective report
226
+ */
227
+ introspect() {
228
+ return this.attention.introspect();
229
+ }
230
+ // ============================================================================
231
+ // Decision Making
232
+ // ============================================================================
233
+ /**
234
+ * Make a φ-aware decision
235
+ */
236
+ decide(options) {
237
+ return this.decider.decide(options);
238
+ }
239
+ /**
240
+ * Should we defer this decision?
241
+ */
242
+ shouldDefer() {
243
+ return this.decider.shouldDefer();
244
+ }
245
+ /**
246
+ * Get current risk tolerance
247
+ */
248
+ getRiskTolerance() {
249
+ return this.decider.getRiskTolerance();
250
+ }
251
+ // ============================================================================
252
+ // Monitoring
253
+ // ============================================================================
254
+ /**
255
+ * Get current consciousness level
256
+ */
257
+ getCurrentLevel() {
258
+ return this.monitor.getCurrentLevel();
259
+ }
260
+ /**
261
+ * Get current consciousness state
262
+ */
263
+ getState() {
264
+ return this.monitor.getState();
265
+ }
266
+ /**
267
+ * Get consciousness trend
268
+ */
269
+ getTrend() {
270
+ return this.monitor.getTrend();
271
+ }
272
+ /**
273
+ * Get per-agent φ
274
+ */
275
+ getAgentPhi(agentId) {
276
+ return this.monitor.getAgentPhi(agentId);
277
+ }
278
+ /**
279
+ * Get anomalies
280
+ */
281
+ getAnomalies(resolved) {
282
+ return this.monitor.getAnomalies({ resolved });
283
+ }
284
+ // ============================================================================
285
+ // Invariant (INV-006)
286
+ // ============================================================================
287
+ /**
288
+ * Check INV-006: φ ≥ φ_min
289
+ */
290
+ checkInvariant() {
291
+ return this.monitor.getInvariantStatus();
292
+ }
293
+ /**
294
+ * Register callback for invariant violations
295
+ */
296
+ onInvariantViolation(callback) {
297
+ return this.monitor.on((event) => {
298
+ if (event.type === 'invariant_violated') {
299
+ callback();
300
+ }
301
+ });
302
+ }
303
+ // ============================================================================
304
+ // Snapshot
305
+ // ============================================================================
306
+ /**
307
+ * Take a consciousness snapshot
308
+ */
309
+ takeSnapshot() {
310
+ const now = new Date();
311
+ // Get φ result
312
+ let phiResult;
313
+ if (this.getSystemState) {
314
+ phiResult = this.calculator.calculate(this.getSystemState());
315
+ }
316
+ else {
317
+ // Default result
318
+ const level = this.monitor.getCurrentLevel();
319
+ phiResult = {
320
+ phi: level.rawPhi,
321
+ mip: { id: 'default', parts: [[]], cut: { severedConnections: [], informationLoss: 0 } },
322
+ intrinsicInfo: level.rawPhi,
323
+ integratedInfo: level.rawPhi,
324
+ complexes: [],
325
+ calculationTime: 0,
326
+ approximation: true,
327
+ };
328
+ }
329
+ // Get last ignition
330
+ const workspaceState = this.workspace.getState();
331
+ const history = this.workspace.getHistory();
332
+ const lastIgnition = history.length > 0
333
+ ? {
334
+ content: history[0],
335
+ timestamp: history[0].timestamp,
336
+ competitorCount: workspaceState.candidates.length,
337
+ winningScore: workspaceState.candidates.find((c) => c.selected)?.score || 0,
338
+ modulesNotified: [],
339
+ duration: 0,
340
+ }
341
+ : null;
342
+ const snapshot = {
343
+ level: this.monitor.getCurrentLevel(),
344
+ state: this.monitor.getState(),
345
+ trend: this.monitor.getTrend(),
346
+ phi: phiResult,
347
+ workspace: workspaceState,
348
+ lastIgnition,
349
+ attention: this.attention.getAttentionState(),
350
+ schema: this.attention.getSchema(),
351
+ agentPhi: this.monitor.getAllAgentPhi(),
352
+ timestamp: now,
353
+ };
354
+ this.lastSnapshot = snapshot;
355
+ return snapshot;
356
+ }
357
+ /**
358
+ * Get last snapshot
359
+ */
360
+ getSnapshot() {
361
+ return this.lastSnapshot;
362
+ }
363
+ // ============================================================================
364
+ // Events
365
+ // ============================================================================
366
+ on(handler) {
367
+ this.eventHandlers.add(handler);
368
+ return () => this.eventHandlers.delete(handler);
369
+ }
370
+ emit(event) {
371
+ for (const handler of this.eventHandlers) {
372
+ try {
373
+ handler(event);
374
+ }
375
+ catch (err) {
376
+ console.error('Consciousness event handler error:', err);
377
+ }
378
+ }
379
+ }
380
+ setupEventForwarding() {
381
+ // Forward monitor events
382
+ this.monitor.on((event) => {
383
+ this.emit({
384
+ type: event.type,
385
+ timestamp: new Date(),
386
+ data: event.data,
387
+ });
388
+ });
389
+ // Forward workspace ignitions
390
+ this.workspace.on((event) => {
391
+ if (event.type === 'ignition') {
392
+ this.emit({
393
+ type: 'workspace_ignition',
394
+ timestamp: new Date(),
395
+ data: event.data,
396
+ });
397
+ }
398
+ });
399
+ // Forward attention shifts
400
+ this.attention.on((event) => {
401
+ if (event.type === 'attention_shifted') {
402
+ this.emit({
403
+ type: 'attention_shifted',
404
+ timestamp: new Date(),
405
+ data: event.data,
406
+ });
407
+ }
408
+ });
409
+ }
410
+ // ============================================================================
411
+ // Stats
412
+ // ============================================================================
413
+ stats() {
414
+ const monitorStats = this.monitor.stats();
415
+ const workspaceStats = this.workspace.stats();
416
+ const attentionStats = this.attention.stats();
417
+ const decisionStats = this.decider.stats();
418
+ return {
419
+ phi: {
420
+ current: monitorStats.currentPhi,
421
+ state: monitorStats.state,
422
+ trend: monitorStats.trend,
423
+ invariantSatisfied: monitorStats.invariantSatisfied,
424
+ },
425
+ gwt: {
426
+ modules: workspaceStats.modules,
427
+ ignited: workspaceStats.isIgnited,
428
+ selections: workspaceStats.selectionCount,
429
+ },
430
+ ast: {
431
+ focus: attentionStats.currentFocus,
432
+ mode: attentionStats.mode,
433
+ clarity: attentionStats.clarity,
434
+ },
435
+ decisions: {
436
+ total: decisionStats.totalDecisions,
437
+ deferred: decisionStats.deferredDecisions,
438
+ deferralRate: decisionStats.deferralRate,
439
+ },
440
+ };
441
+ }
442
+ // ============================================================================
443
+ // Helpers
444
+ // ============================================================================
445
+ mergeConfig(partial) {
446
+ return {
447
+ phi: { ...types_js_1.DEFAULT_CONSCIOUSNESS_CONFIG.phi, ...partial.phi },
448
+ gwt: { ...types_js_1.DEFAULT_CONSCIOUSNESS_CONFIG.gwt, ...partial.gwt },
449
+ ast: { ...types_js_1.DEFAULT_CONSCIOUSNESS_CONFIG.ast, ...partial.ast },
450
+ monitor: { ...types_js_1.DEFAULT_CONSCIOUSNESS_CONFIG.monitor, ...partial.monitor },
451
+ };
452
+ }
453
+ }
454
+ exports.ConsciousnessSystem = ConsciousnessSystem;
455
+ // ============================================================================
456
+ // Factory
457
+ // ============================================================================
458
+ function createConsciousnessSystem(config) {
459
+ return new ConsciousnessSystem(config);
460
+ }
461
+ // ============================================================================
462
+ // Singleton Instance (optional)
463
+ // ============================================================================
464
+ let consciousnessInstance = null;
465
+ function getConsciousnessSystem(config) {
466
+ if (!consciousnessInstance) {
467
+ consciousnessInstance = createConsciousnessSystem(config);
468
+ }
469
+ return consciousnessInstance;
470
+ }
471
+ function resetConsciousnessSystem() {
472
+ if (consciousnessInstance) {
473
+ consciousnessInstance.stop();
474
+ consciousnessInstance = null;
475
+ }
476
+ }