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,276 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis Grounding Feedback Loop
4
+ *
5
+ * Iterative verification and fixing pipeline:
6
+ * 1. Generate code
7
+ * 2. Verify (compile, test, semantic)
8
+ * 3. If fails: pass errors to fixer
9
+ * 4. Regenerate with error context
10
+ * 5. Max N iterations
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.FeedbackLoop = void 0;
14
+ exports.getFeedbackLoop = getFeedbackLoop;
15
+ exports.resetFeedbackLoop = resetFeedbackLoop;
16
+ exports.runFeedbackLoop = runFeedbackLoop;
17
+ exports.verifyAndFix = verifyAndFix;
18
+ exports.isProjectValid = isProjectValid;
19
+ exports.formatFeedbackResult = formatFeedbackResult;
20
+ const verifier_js_1 = require("./verifier.js");
21
+ const fixer_js_1 = require("../healing/fixer.js");
22
+ const DEFAULT_CONFIG = {
23
+ maxIterations: 3,
24
+ stopOnSuccess: true,
25
+ verificationContext: {
26
+ workingDirectory: process.cwd(),
27
+ },
28
+ enableAutoFix: true,
29
+ verbose: false,
30
+ };
31
+ // ============================================================================
32
+ // FeedbackLoop Class
33
+ // ============================================================================
34
+ class FeedbackLoop {
35
+ config;
36
+ verifier;
37
+ fixer;
38
+ constructor(config) {
39
+ this.config = { ...DEFAULT_CONFIG, ...config };
40
+ this.verifier = (0, verifier_js_1.getVerifier)();
41
+ this.fixer = (0, fixer_js_1.getAutoFixer)({
42
+ workingDirectory: this.config.verificationContext.workingDirectory,
43
+ });
44
+ }
45
+ /**
46
+ * Run the feedback loop
47
+ */
48
+ async run() {
49
+ const startTime = Date.now();
50
+ const history = [];
51
+ let success = false;
52
+ let finalResult = null;
53
+ for (let i = 1; i <= this.config.maxIterations; i++) {
54
+ const iterationStart = Date.now();
55
+ if (this.config.verbose) {
56
+ console.log(`\n[Iteration ${i}/${this.config.maxIterations}]`);
57
+ }
58
+ // Step 1: Verify
59
+ if (this.config.verbose) {
60
+ console.log(' Verifying...');
61
+ }
62
+ const verification = await this.verifier.verify(this.config.verificationContext);
63
+ finalResult = verification;
64
+ if (this.config.verbose) {
65
+ console.log(` Compiles: ${verification.compiles ? '✓' : '✗'}`);
66
+ console.log(` Types: ${verification.typesValid ? '✓' : '✗'}`);
67
+ console.log(` Tests: ${verification.testsPass ? '✓' : '✗'} (${verification.testsPassed}/${verification.testsTotal})`);
68
+ }
69
+ // Check if successful
70
+ if (verification.success) {
71
+ if (this.config.verbose) {
72
+ console.log(' Status: SUCCESS');
73
+ }
74
+ history.push({
75
+ iteration: i,
76
+ verification,
77
+ duration: Date.now() - iterationStart,
78
+ success: true,
79
+ });
80
+ success = true;
81
+ if (this.config.stopOnSuccess)
82
+ break;
83
+ continue;
84
+ }
85
+ // Step 2: Auto-fix if enabled
86
+ let fixResult;
87
+ if (this.config.enableAutoFix && verification.issues.length > 0) {
88
+ if (this.config.verbose) {
89
+ console.log(` Attempting auto-fix for ${verification.issues.length} issues...`);
90
+ }
91
+ // Convert grounding issues to detected errors
92
+ const errors = verification.issues.map(issue => ({
93
+ category: this.mapIssueType(issue.type),
94
+ severity: issue.severity,
95
+ message: issue.message,
96
+ file: issue.file,
97
+ line: issue.line,
98
+ raw: issue.message,
99
+ fixHint: issue.suggestion,
100
+ }));
101
+ fixResult = await this.fixer.fix(errors);
102
+ if (this.config.verbose) {
103
+ console.log(` Fix result: ${fixResult.success ? 'SUCCESS' : 'FAILED'}`);
104
+ if (fixResult.appliedFix) {
105
+ console.log(` Fix applied: ${fixResult.appliedFix.description}`);
106
+ }
107
+ }
108
+ }
109
+ history.push({
110
+ iteration: i,
111
+ verification,
112
+ fix: fixResult,
113
+ duration: Date.now() - iterationStart,
114
+ success: false,
115
+ });
116
+ }
117
+ // Ensure we have a final result
118
+ if (!finalResult) {
119
+ finalResult = await this.verifier.verify(this.config.verificationContext);
120
+ }
121
+ const totalDuration = Date.now() - startTime;
122
+ // Generate summary
123
+ const summary = this.generateSummary(success, history, totalDuration);
124
+ return {
125
+ success,
126
+ iterations: history.length,
127
+ history,
128
+ finalResult,
129
+ totalDuration,
130
+ summary,
131
+ };
132
+ }
133
+ /**
134
+ * Run verification only (no fixing)
135
+ */
136
+ async verifyOnly() {
137
+ return this.verifier.verify(this.config.verificationContext);
138
+ }
139
+ /**
140
+ * Map grounding issue type to error category
141
+ */
142
+ mapIssueType(type) {
143
+ switch (type) {
144
+ case 'compile':
145
+ return 'build';
146
+ case 'type':
147
+ return 'type';
148
+ case 'test':
149
+ return 'test';
150
+ case 'lint':
151
+ return 'lint';
152
+ default:
153
+ return 'unknown';
154
+ }
155
+ }
156
+ /**
157
+ * Generate summary message
158
+ */
159
+ generateSummary(success, history, duration) {
160
+ if (success) {
161
+ const successIteration = history.findIndex(h => h.success) + 1;
162
+ if (successIteration === 1) {
163
+ return `Verification passed on first attempt (${duration}ms)`;
164
+ }
165
+ return `Verification passed after ${successIteration} iterations with ${history.filter(h => h.fix?.appliedFix).length} fixes (${duration}ms)`;
166
+ }
167
+ const totalIssues = history[history.length - 1]?.verification.issues.length || 0;
168
+ const totalFixes = history.filter(h => h.fix?.appliedFix).length;
169
+ return `Verification failed after ${history.length} iterations. ${totalIssues} issues remaining, ${totalFixes} fixes attempted (${duration}ms)`;
170
+ }
171
+ /**
172
+ * Update configuration
173
+ */
174
+ updateConfig(updates) {
175
+ this.config = { ...this.config, ...updates };
176
+ if (updates.verificationContext) {
177
+ this.fixer = (0, fixer_js_1.getAutoFixer)({
178
+ workingDirectory: updates.verificationContext.workingDirectory,
179
+ });
180
+ }
181
+ }
182
+ /**
183
+ * Get current configuration
184
+ */
185
+ getConfig() {
186
+ return { ...this.config };
187
+ }
188
+ }
189
+ exports.FeedbackLoop = FeedbackLoop;
190
+ // ============================================================================
191
+ // Singleton Instance
192
+ // ============================================================================
193
+ let feedbackLoopInstance = null;
194
+ function getFeedbackLoop(config) {
195
+ if (!feedbackLoopInstance) {
196
+ feedbackLoopInstance = new FeedbackLoop(config);
197
+ }
198
+ else if (config) {
199
+ feedbackLoopInstance.updateConfig(config);
200
+ }
201
+ return feedbackLoopInstance;
202
+ }
203
+ function resetFeedbackLoop() {
204
+ feedbackLoopInstance = null;
205
+ }
206
+ // ============================================================================
207
+ // Convenience Functions
208
+ // ============================================================================
209
+ /**
210
+ * Run feedback loop with default configuration
211
+ */
212
+ async function runFeedbackLoop(workingDirectory, options) {
213
+ const loop = new FeedbackLoop({
214
+ ...options,
215
+ verificationContext: {
216
+ workingDirectory,
217
+ },
218
+ });
219
+ return loop.run();
220
+ }
221
+ /**
222
+ * Verify and fix until success or max iterations
223
+ */
224
+ async function verifyAndFix(workingDirectory, maxIterations = 3) {
225
+ return runFeedbackLoop(workingDirectory, { maxIterations });
226
+ }
227
+ /**
228
+ * Quick check if code is currently valid
229
+ */
230
+ async function isProjectValid(workingDirectory) {
231
+ const loop = new FeedbackLoop({
232
+ verificationContext: { workingDirectory },
233
+ maxIterations: 1,
234
+ enableAutoFix: false,
235
+ });
236
+ const result = await loop.run();
237
+ return result.success;
238
+ }
239
+ /**
240
+ * Format feedback loop result for display
241
+ */
242
+ function formatFeedbackResult(result) {
243
+ const lines = [];
244
+ // Header
245
+ const status = result.success ? '✓ SUCCESS' : '✗ FAILED';
246
+ lines.push(`Feedback Loop ${status}`);
247
+ lines.push(`${result.summary}`);
248
+ lines.push('');
249
+ // Iteration history
250
+ lines.push('Iteration History:');
251
+ for (const iter of result.history) {
252
+ const iterStatus = iter.success ? '✓' : '✗';
253
+ const fixInfo = iter.fix?.appliedFix ? ' (1 fix)' : '';
254
+ lines.push(` ${iter.iteration}. ${iterStatus} ${iter.verification.issues.length} issues${fixInfo} [${iter.duration}ms]`);
255
+ }
256
+ lines.push('');
257
+ // Final state
258
+ lines.push('Final State:');
259
+ lines.push(` Compiles: ${result.finalResult.compiles ? '✓' : '✗'}`);
260
+ lines.push(` Types: ${result.finalResult.typesValid ? '✓' : '✗'}`);
261
+ lines.push(` Tests: ${result.finalResult.testsPass ? '✓' : '✗'} (${result.finalResult.testsPassed}/${result.finalResult.testsTotal})`);
262
+ lines.push(` Semantic: ${(result.finalResult.semanticMatch * 100).toFixed(0)}%`);
263
+ // Remaining issues
264
+ if (result.finalResult.issues.length > 0 && !result.success) {
265
+ lines.push('');
266
+ lines.push(`Remaining Issues (${result.finalResult.issues.length}):`);
267
+ for (const issue of result.finalResult.issues.slice(0, 5)) {
268
+ const prefix = issue.severity === 'error' ? '✗' : '⚠';
269
+ lines.push(` ${prefix} ${issue.message}`);
270
+ }
271
+ if (result.finalResult.issues.length > 5) {
272
+ lines.push(` ... and ${result.finalResult.issues.length - 5} more`);
273
+ }
274
+ }
275
+ return lines.join('\n');
276
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Genesis 6.0 - Grounding Module
3
+ *
4
+ * Epistemic foundation for all claims and decisions:
5
+ *
6
+ * 1. SCIENCE - factual/empirical (arxiv, semantic-scholar, web)
7
+ * 2. PROOF - mathematical/logical (wolfram, type-check)
8
+ * 3. WISDOM - practical heuristics (repository + patterns)
9
+ * 4. RELIGION/TRADITION - meaning and morals (repository)
10
+ * 5. HUMAN - preferences and final authority
11
+ * 6. PRUDENCE - acting under uncertainty
12
+ *
13
+ * Usage:
14
+ * ```typescript
15
+ * import { createGroundingSystem } from './grounding/index.js';
16
+ *
17
+ * const grounding = createGroundingSystem();
18
+ *
19
+ * // Ground a factual claim
20
+ * const fact = await grounding.ground('TypeScript is a typed superset of JavaScript');
21
+ * // → verified via science
22
+ *
23
+ * // Ground an ethical question
24
+ * const ethics = await grounding.ground('Should I release this code?');
25
+ * // → requires human consultation via wisdom
26
+ *
27
+ * // Ground a novel situation
28
+ * const novel = await grounding.ground('How should I handle this unprecedented bug?');
29
+ * // → prudence + human
30
+ * ```
31
+ */
32
+ export * from './epistemic-stack.js';
33
+ export * from './verifier.js';
34
+ export * from './feedback.js';
35
+ import { EpistemicClaim, EpistemicDomain, GroundingResult, WisdomSource, TraditionSource } from './epistemic-stack.js';
36
+ export interface GroundingConfig {
37
+ scienceEnabled?: boolean;
38
+ proofEnabled?: boolean;
39
+ wisdomEnabled?: boolean;
40
+ traditionEnabled?: boolean;
41
+ humanEnabled?: boolean;
42
+ defaultToHumanOnUncertainty?: boolean;
43
+ uncertaintyThreshold?: number;
44
+ }
45
+ export declare class GroundingSystem {
46
+ private config;
47
+ private stack;
48
+ private claimsGrounded;
49
+ private humanConsultations;
50
+ private byDomain;
51
+ constructor(config?: Partial<GroundingConfig>);
52
+ /**
53
+ * Connect science grounding to MCP servers
54
+ */
55
+ connectScience(grounter: (claim: string) => Promise<GroundingResult>): void;
56
+ /**
57
+ * Connect proof checking
58
+ */
59
+ connectProof(checker: (claim: string) => Promise<GroundingResult>): void;
60
+ /**
61
+ * Ground a claim through the full epistemic stack
62
+ */
63
+ ground(claim: string): Promise<EpistemicClaim>;
64
+ /**
65
+ * Quick check: does this claim need human input?
66
+ */
67
+ needsHuman(claim: EpistemicClaim): boolean;
68
+ /**
69
+ * Get the question to ask the human
70
+ */
71
+ getQuestion(claim: EpistemicClaim): string | undefined;
72
+ /**
73
+ * Process human response
74
+ */
75
+ respondHuman(claim: EpistemicClaim, response: string): EpistemicClaim;
76
+ /**
77
+ * Get statistics
78
+ */
79
+ stats(): {
80
+ claimsGrounded: number;
81
+ humanConsultations: number;
82
+ humanRate: number;
83
+ byDomain: Record<EpistemicDomain, number>;
84
+ };
85
+ /**
86
+ * Get all wisdom sources
87
+ */
88
+ getWisdom(): WisdomSource[];
89
+ /**
90
+ * Get all tradition sources
91
+ */
92
+ getTraditions(): TraditionSource[];
93
+ /**
94
+ * Add custom wisdom
95
+ */
96
+ addWisdom(wisdom: WisdomSource): void;
97
+ /**
98
+ * Add custom tradition
99
+ */
100
+ addTradition(tradition: TraditionSource): void;
101
+ }
102
+ export declare function createGroundingSystem(config?: Partial<GroundingConfig>): GroundingSystem;
103
+ export declare function getGroundingSystem(config?: Partial<GroundingConfig>): GroundingSystem;
104
+ export declare function resetGroundingSystem(): void;
105
+ import { verifyCode, quickVerify, isCodeValid, formatVerificationResult, getVerifier, resetVerifier } from './verifier.js';
106
+ import { runFeedbackLoop, verifyAndFix, isProjectValid, formatFeedbackResult, getFeedbackLoop, resetFeedbackLoop } from './feedback.js';
107
+ /**
108
+ * Code verification and feedback loop utilities
109
+ */
110
+ export declare const codeGrounding: {
111
+ verify: typeof verifyCode;
112
+ quickVerify: typeof quickVerify;
113
+ isCodeValid: typeof isCodeValid;
114
+ formatResult: typeof formatVerificationResult;
115
+ getVerifier: typeof getVerifier;
116
+ resetVerifier: typeof resetVerifier;
117
+ runLoop: typeof runFeedbackLoop;
118
+ verifyAndFix: typeof verifyAndFix;
119
+ isProjectValid: typeof isProjectValid;
120
+ formatLoopResult: typeof formatFeedbackResult;
121
+ getLoop: typeof getFeedbackLoop;
122
+ resetLoop: typeof resetFeedbackLoop;
123
+ };
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis 6.0 - Grounding Module
4
+ *
5
+ * Epistemic foundation for all claims and decisions:
6
+ *
7
+ * 1. SCIENCE - factual/empirical (arxiv, semantic-scholar, web)
8
+ * 2. PROOF - mathematical/logical (wolfram, type-check)
9
+ * 3. WISDOM - practical heuristics (repository + patterns)
10
+ * 4. RELIGION/TRADITION - meaning and morals (repository)
11
+ * 5. HUMAN - preferences and final authority
12
+ * 6. PRUDENCE - acting under uncertainty
13
+ *
14
+ * Usage:
15
+ * ```typescript
16
+ * import { createGroundingSystem } from './grounding/index.js';
17
+ *
18
+ * const grounding = createGroundingSystem();
19
+ *
20
+ * // Ground a factual claim
21
+ * const fact = await grounding.ground('TypeScript is a typed superset of JavaScript');
22
+ * // → verified via science
23
+ *
24
+ * // Ground an ethical question
25
+ * const ethics = await grounding.ground('Should I release this code?');
26
+ * // → requires human consultation via wisdom
27
+ *
28
+ * // Ground a novel situation
29
+ * const novel = await grounding.ground('How should I handle this unprecedented bug?');
30
+ * // → prudence + human
31
+ * ```
32
+ */
33
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
34
+ if (k2 === undefined) k2 = k;
35
+ var desc = Object.getOwnPropertyDescriptor(m, k);
36
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
37
+ desc = { enumerable: true, get: function() { return m[k]; } };
38
+ }
39
+ Object.defineProperty(o, k2, desc);
40
+ }) : (function(o, m, k, k2) {
41
+ if (k2 === undefined) k2 = k;
42
+ o[k2] = m[k];
43
+ }));
44
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
45
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.codeGrounding = exports.GroundingSystem = void 0;
49
+ exports.createGroundingSystem = createGroundingSystem;
50
+ exports.getGroundingSystem = getGroundingSystem;
51
+ exports.resetGroundingSystem = resetGroundingSystem;
52
+ // Re-export everything from epistemic stack
53
+ __exportStar(require("./epistemic-stack.js"), exports);
54
+ // Re-export verifier and feedback loop
55
+ __exportStar(require("./verifier.js"), exports);
56
+ __exportStar(require("./feedback.js"), exports);
57
+ const epistemic_stack_js_1 = require("./epistemic-stack.js");
58
+ const DEFAULT_CONFIG = {
59
+ scienceEnabled: true,
60
+ proofEnabled: true,
61
+ wisdomEnabled: true,
62
+ traditionEnabled: true,
63
+ humanEnabled: true,
64
+ defaultToHumanOnUncertainty: false, // v7.2: Disabled by default (too aggressive without connected grounders)
65
+ uncertaintyThreshold: 0.2, // v7.2: Lowered from 0.5 - only flag truly uncertain claims
66
+ };
67
+ class GroundingSystem {
68
+ config;
69
+ stack;
70
+ // Stats
71
+ claimsGrounded = 0;
72
+ humanConsultations = 0;
73
+ byDomain = {
74
+ factual: 0,
75
+ mathematical: 0,
76
+ ethical: 0,
77
+ existential: 0,
78
+ aesthetic: 0,
79
+ novel: 0,
80
+ };
81
+ constructor(config = {}) {
82
+ this.config = { ...DEFAULT_CONFIG, ...config };
83
+ this.stack = (0, epistemic_stack_js_1.createEpistemicStack)();
84
+ }
85
+ /**
86
+ * Connect science grounding to MCP servers
87
+ */
88
+ connectScience(grounter) {
89
+ if (this.config.scienceEnabled) {
90
+ this.stack.setScienceGrounder(grounter);
91
+ }
92
+ }
93
+ /**
94
+ * Connect proof checking
95
+ */
96
+ connectProof(checker) {
97
+ if (this.config.proofEnabled) {
98
+ this.stack.setProofChecker(checker);
99
+ }
100
+ }
101
+ /**
102
+ * Ground a claim through the full epistemic stack
103
+ */
104
+ async ground(claim) {
105
+ const result = await this.stack.ground(claim);
106
+ // Track stats
107
+ this.claimsGrounded++;
108
+ this.byDomain[result.domain]++;
109
+ if (result.grounding.humanConsultation?.required) {
110
+ this.humanConsultations++;
111
+ }
112
+ // Check if we need to escalate to human due to uncertainty
113
+ if (this.config.defaultToHumanOnUncertainty &&
114
+ result.confidence < this.config.uncertaintyThreshold &&
115
+ !result.grounding.humanConsultation?.required) {
116
+ result.grounding.humanConsultation = {
117
+ required: true,
118
+ reason: `Confidence ${(result.confidence * 100).toFixed(0)}% below threshold ${(this.config.uncertaintyThreshold * 100).toFixed(0)}%`,
119
+ question: `Incertezza su: "${claim}". Vuoi procedere comunque?`,
120
+ };
121
+ this.humanConsultations++;
122
+ }
123
+ return result;
124
+ }
125
+ /**
126
+ * Quick check: does this claim need human input?
127
+ */
128
+ needsHuman(claim) {
129
+ return this.stack.requiresHuman(claim);
130
+ }
131
+ /**
132
+ * Get the question to ask the human
133
+ */
134
+ getQuestion(claim) {
135
+ return this.stack.getHumanQuestion(claim);
136
+ }
137
+ /**
138
+ * Process human response
139
+ */
140
+ respondHuman(claim, response) {
141
+ return this.stack.incorporateHumanResponse(claim, response);
142
+ }
143
+ /**
144
+ * Get statistics
145
+ */
146
+ stats() {
147
+ return {
148
+ claimsGrounded: this.claimsGrounded,
149
+ humanConsultations: this.humanConsultations,
150
+ humanRate: this.claimsGrounded > 0
151
+ ? this.humanConsultations / this.claimsGrounded
152
+ : 0,
153
+ byDomain: { ...this.byDomain },
154
+ };
155
+ }
156
+ /**
157
+ * Get all wisdom sources
158
+ */
159
+ getWisdom() {
160
+ return [...epistemic_stack_js_1.WISDOM_REPOSITORY];
161
+ }
162
+ /**
163
+ * Get all tradition sources
164
+ */
165
+ getTraditions() {
166
+ return [...epistemic_stack_js_1.TRADITION_REPOSITORY];
167
+ }
168
+ /**
169
+ * Add custom wisdom
170
+ */
171
+ addWisdom(wisdom) {
172
+ epistemic_stack_js_1.WISDOM_REPOSITORY.push(wisdom);
173
+ }
174
+ /**
175
+ * Add custom tradition
176
+ */
177
+ addTradition(tradition) {
178
+ epistemic_stack_js_1.TRADITION_REPOSITORY.push(tradition);
179
+ }
180
+ }
181
+ exports.GroundingSystem = GroundingSystem;
182
+ // ============================================================================
183
+ // Factory
184
+ // ============================================================================
185
+ function createGroundingSystem(config) {
186
+ return new GroundingSystem(config);
187
+ }
188
+ // ============================================================================
189
+ // Singleton
190
+ // ============================================================================
191
+ let groundingInstance = null;
192
+ function getGroundingSystem(config) {
193
+ if (!groundingInstance) {
194
+ groundingInstance = createGroundingSystem(config);
195
+ }
196
+ return groundingInstance;
197
+ }
198
+ function resetGroundingSystem() {
199
+ groundingInstance = null;
200
+ }
201
+ // ============================================================================
202
+ // Code Verification (from verifier.ts)
203
+ // ============================================================================
204
+ const verifier_js_1 = require("./verifier.js");
205
+ const feedback_js_1 = require("./feedback.js");
206
+ /**
207
+ * Code verification and feedback loop utilities
208
+ */
209
+ exports.codeGrounding = {
210
+ // Verification
211
+ verify: verifier_js_1.verifyCode,
212
+ quickVerify: verifier_js_1.quickVerify,
213
+ isCodeValid: verifier_js_1.isCodeValid,
214
+ formatResult: verifier_js_1.formatVerificationResult,
215
+ getVerifier: verifier_js_1.getVerifier,
216
+ resetVerifier: verifier_js_1.resetVerifier,
217
+ // Feedback Loop
218
+ runLoop: feedback_js_1.runFeedbackLoop,
219
+ verifyAndFix: feedback_js_1.verifyAndFix,
220
+ isProjectValid: feedback_js_1.isProjectValid,
221
+ formatLoopResult: feedback_js_1.formatFeedbackResult,
222
+ getLoop: feedback_js_1.getFeedbackLoop,
223
+ resetLoop: feedback_js_1.resetFeedbackLoop,
224
+ };