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,110 @@
1
+ /**
2
+ * Genesis Error Detector
3
+ *
4
+ * Detects and classifies errors from command output:
5
+ * - Syntax errors (parse errors, missing tokens)
6
+ * - Type errors (TypeScript type mismatches)
7
+ * - Runtime errors (exceptions, undefined references)
8
+ * - Test failures (assertion failures, test timeouts)
9
+ * - Build errors (compilation failures)
10
+ * - Lint errors (style violations)
11
+ */
12
+ export type ErrorCategory = 'syntax' | 'type' | 'runtime' | 'test' | 'build' | 'lint' | 'dependency' | 'permission' | 'unknown';
13
+ export type ErrorSeverity = 'error' | 'warning' | 'info';
14
+ export interface DetectedError {
15
+ /** Error category */
16
+ category: ErrorCategory;
17
+ /** Severity level */
18
+ severity: ErrorSeverity;
19
+ /** Error message */
20
+ message: string;
21
+ /** File path if available */
22
+ file?: string;
23
+ /** Line number if available */
24
+ line?: number;
25
+ /** Column number if available */
26
+ column?: number;
27
+ /** Error code if available */
28
+ code?: string;
29
+ /** Full context (surrounding lines) */
30
+ context?: string;
31
+ /** Raw matched pattern */
32
+ raw: string;
33
+ /** Suggested fix category */
34
+ fixHint?: string;
35
+ }
36
+ export interface DetectionResult {
37
+ /** All detected errors */
38
+ errors: DetectedError[];
39
+ /** Count by category */
40
+ byCategory: Record<ErrorCategory, number>;
41
+ /** Count by severity */
42
+ bySeverity: Record<ErrorSeverity, number>;
43
+ /** Overall success (no errors) */
44
+ success: boolean;
45
+ /** Has fixable errors */
46
+ hasFixable: boolean;
47
+ }
48
+ interface ErrorPattern {
49
+ /** Regex pattern to match */
50
+ pattern: RegExp;
51
+ /** Error category */
52
+ category: ErrorCategory;
53
+ /** Severity level (or function to extract it) */
54
+ severity: ErrorSeverity | ((match: RegExpMatchArray) => ErrorSeverity);
55
+ /** Extract file path (group index or function) */
56
+ extractFile?: number | ((match: RegExpMatchArray) => string | undefined);
57
+ /** Extract line number */
58
+ extractLine?: number | ((match: RegExpMatchArray) => number | undefined);
59
+ /** Extract column number */
60
+ extractColumn?: number | ((match: RegExpMatchArray) => number | undefined);
61
+ /** Extract error code */
62
+ extractCode?: number | ((match: RegExpMatchArray) => string | undefined);
63
+ /** Extract message */
64
+ extractMessage?: number | ((match: RegExpMatchArray) => string);
65
+ /** Fix hint */
66
+ fixHint?: string;
67
+ }
68
+ export declare class ErrorDetector {
69
+ private patterns;
70
+ constructor(additionalPatterns?: ErrorPattern[]);
71
+ /**
72
+ * Detect errors in output text
73
+ */
74
+ detect(output: string): DetectionResult;
75
+ /**
76
+ * Extract error details from regex match
77
+ */
78
+ private extractError;
79
+ /**
80
+ * Classify a single error message
81
+ */
82
+ classify(message: string): ErrorCategory;
83
+ /**
84
+ * Get fix suggestions for an error
85
+ */
86
+ suggestFix(error: DetectedError): string[];
87
+ /**
88
+ * Add a custom error pattern
89
+ */
90
+ addPattern(pattern: ErrorPattern): void;
91
+ /**
92
+ * Format errors for display
93
+ */
94
+ formatErrors(errors: DetectedError[]): string;
95
+ }
96
+ export declare function getErrorDetector(): ErrorDetector;
97
+ export declare function resetErrorDetector(): void;
98
+ /**
99
+ * Detect errors in output
100
+ */
101
+ export declare function detectErrors(output: string): DetectionResult;
102
+ /**
103
+ * Check if output contains errors
104
+ */
105
+ export declare function hasErrors(output: string): boolean;
106
+ /**
107
+ * Get formatted error report
108
+ */
109
+ export declare function formatErrorReport(output: string): string;
110
+ export {};
@@ -0,0 +1,436 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis Error Detector
4
+ *
5
+ * Detects and classifies errors from command output:
6
+ * - Syntax errors (parse errors, missing tokens)
7
+ * - Type errors (TypeScript type mismatches)
8
+ * - Runtime errors (exceptions, undefined references)
9
+ * - Test failures (assertion failures, test timeouts)
10
+ * - Build errors (compilation failures)
11
+ * - Lint errors (style violations)
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.ErrorDetector = void 0;
15
+ exports.getErrorDetector = getErrorDetector;
16
+ exports.resetErrorDetector = resetErrorDetector;
17
+ exports.detectErrors = detectErrors;
18
+ exports.hasErrors = hasErrors;
19
+ exports.formatErrorReport = formatErrorReport;
20
+ // ============================================================================
21
+ // Error Patterns
22
+ // ============================================================================
23
+ const ERROR_PATTERNS = [
24
+ // TypeScript errors
25
+ {
26
+ pattern: /^(.+\.tsx?)\((\d+),(\d+)\): error (TS\d+): (.+)$/gm,
27
+ category: 'type',
28
+ severity: 'error',
29
+ extractFile: 1,
30
+ extractLine: 2,
31
+ extractColumn: 3,
32
+ extractCode: 4,
33
+ extractMessage: 5,
34
+ fixHint: 'type_mismatch',
35
+ },
36
+ {
37
+ pattern: /^(.+\.tsx?):(\d+):(\d+) - error (TS\d+): (.+)$/gm,
38
+ category: 'type',
39
+ severity: 'error',
40
+ extractFile: 1,
41
+ extractLine: 2,
42
+ extractColumn: 3,
43
+ extractCode: 4,
44
+ extractMessage: 5,
45
+ fixHint: 'type_mismatch',
46
+ },
47
+ // ESLint errors
48
+ {
49
+ pattern: /^(.+):(\d+):(\d+): (error|warning) (.+) \((.+)\)$/gm,
50
+ category: 'lint',
51
+ severity: (match) => match[4],
52
+ extractFile: 1,
53
+ extractLine: 2,
54
+ extractColumn: 3,
55
+ extractCode: 6,
56
+ extractMessage: 5,
57
+ fixHint: 'lint_fix',
58
+ },
59
+ {
60
+ pattern: /^\s*(\d+):(\d+)\s+(error|warning)\s+(.+?)\s+(@?[\w\/-]+)$/gm,
61
+ category: 'lint',
62
+ severity: (match) => match[3],
63
+ extractLine: 1,
64
+ extractColumn: 2,
65
+ extractCode: 5,
66
+ extractMessage: 4,
67
+ fixHint: 'lint_fix',
68
+ },
69
+ // Syntax errors (BEFORE runtime to match SyntaxError specifically)
70
+ {
71
+ pattern: /^SyntaxError: (.+)$/gm,
72
+ category: 'syntax',
73
+ severity: 'error',
74
+ extractMessage: 1,
75
+ fixHint: 'syntax_fix',
76
+ },
77
+ {
78
+ pattern: /Unexpected token (.+)/gi,
79
+ category: 'syntax',
80
+ severity: 'error',
81
+ extractMessage: (match) => match[0],
82
+ fixHint: 'syntax_fix',
83
+ },
84
+ {
85
+ pattern: /Missing (.+) in (.+)/gi,
86
+ category: 'syntax',
87
+ severity: 'error',
88
+ extractMessage: (match) => match[0],
89
+ fixHint: 'syntax_fix',
90
+ },
91
+ // Node.js runtime errors
92
+ {
93
+ pattern: /^(\w+Error): (.+)$/gm,
94
+ category: 'runtime',
95
+ severity: 'error',
96
+ extractCode: 1,
97
+ extractMessage: 2,
98
+ fixHint: 'runtime_error',
99
+ },
100
+ {
101
+ pattern: /^\s+at .+ \((.+):(\d+):(\d+)\)$/gm,
102
+ category: 'runtime',
103
+ severity: 'info',
104
+ extractFile: 1,
105
+ extractLine: 2,
106
+ extractColumn: 3,
107
+ extractMessage: (match) => `Stack trace: ${match[0].trim()}`,
108
+ },
109
+ // Test failures (Node test runner)
110
+ {
111
+ pattern: /^✖ (.+) \([\d.]+ms\)$/gm,
112
+ category: 'test',
113
+ severity: 'error',
114
+ extractMessage: 1,
115
+ fixHint: 'test_fix',
116
+ },
117
+ {
118
+ pattern: /^AssertionError.+: (.+)$/gm,
119
+ category: 'test',
120
+ severity: 'error',
121
+ extractMessage: 1,
122
+ fixHint: 'assertion_fix',
123
+ },
124
+ {
125
+ pattern: /expected (.+) to (equal|be|match|include) (.+)/gi,
126
+ category: 'test',
127
+ severity: 'error',
128
+ extractMessage: (match) => match[0],
129
+ fixHint: 'assertion_fix',
130
+ },
131
+ // Jest/Vitest failures
132
+ {
133
+ pattern: /^FAIL (.+)$/gm,
134
+ category: 'test',
135
+ severity: 'error',
136
+ extractFile: 1,
137
+ extractMessage: (match) => `Test file failed: ${match[1]}`,
138
+ fixHint: 'test_fix',
139
+ },
140
+ {
141
+ pattern: /^\s*● (.+)$/gm,
142
+ category: 'test',
143
+ severity: 'error',
144
+ extractMessage: 1,
145
+ fixHint: 'test_fix',
146
+ },
147
+ // Build errors
148
+ {
149
+ pattern: /^error: (.+)$/gmi,
150
+ category: 'build',
151
+ severity: 'error',
152
+ extractMessage: 1,
153
+ fixHint: 'build_fix',
154
+ },
155
+ {
156
+ pattern: /^Build failed/gmi,
157
+ category: 'build',
158
+ severity: 'error',
159
+ extractMessage: () => 'Build failed',
160
+ fixHint: 'build_fix',
161
+ },
162
+ // Dependency errors
163
+ {
164
+ pattern: /Cannot find module '(.+)'/g,
165
+ category: 'dependency',
166
+ severity: 'error',
167
+ extractMessage: (match) => `Missing module: ${match[1]}`,
168
+ extractCode: (match) => match[1],
169
+ fixHint: 'install_dependency',
170
+ },
171
+ {
172
+ pattern: /Module not found: (.+)/gi,
173
+ category: 'dependency',
174
+ severity: 'error',
175
+ extractMessage: 1,
176
+ fixHint: 'install_dependency',
177
+ },
178
+ {
179
+ pattern: /ERR! (.+)/g,
180
+ category: 'dependency',
181
+ severity: 'error',
182
+ extractMessage: 1,
183
+ fixHint: 'npm_error',
184
+ },
185
+ // Permission errors
186
+ {
187
+ pattern: /EACCES: permission denied, (.+)/g,
188
+ category: 'permission',
189
+ severity: 'error',
190
+ extractMessage: (match) => match[0],
191
+ fixHint: 'permission_fix',
192
+ },
193
+ {
194
+ pattern: /ENOENT: no such file or directory, (.+) '(.+)'/g,
195
+ category: 'permission',
196
+ severity: 'error',
197
+ extractFile: 2,
198
+ extractMessage: (match) => match[0],
199
+ fixHint: 'file_not_found',
200
+ },
201
+ ];
202
+ // ============================================================================
203
+ // Error Detector Class
204
+ // ============================================================================
205
+ class ErrorDetector {
206
+ patterns;
207
+ constructor(additionalPatterns) {
208
+ this.patterns = [...ERROR_PATTERNS, ...(additionalPatterns || [])];
209
+ }
210
+ /**
211
+ * Detect errors in output text
212
+ */
213
+ detect(output) {
214
+ const errors = [];
215
+ const seen = new Set(); // Deduplicate
216
+ for (const pattern of this.patterns) {
217
+ // Reset regex lastIndex for global patterns
218
+ pattern.pattern.lastIndex = 0;
219
+ let match;
220
+ while ((match = pattern.pattern.exec(output)) !== null) {
221
+ const key = `${match[0]}:${match.index}`;
222
+ if (seen.has(key))
223
+ continue;
224
+ seen.add(key);
225
+ const error = this.extractError(match, pattern, output);
226
+ errors.push(error);
227
+ }
228
+ }
229
+ // Sort by severity, then by line number
230
+ errors.sort((a, b) => {
231
+ const severityOrder = { error: 0, warning: 1, info: 2 };
232
+ const sevDiff = severityOrder[a.severity] - severityOrder[b.severity];
233
+ if (sevDiff !== 0)
234
+ return sevDiff;
235
+ return (a.line || 0) - (b.line || 0);
236
+ });
237
+ // Count by category and severity
238
+ const byCategory = {
239
+ syntax: 0, type: 0, runtime: 0, test: 0,
240
+ build: 0, lint: 0, dependency: 0, permission: 0, unknown: 0,
241
+ };
242
+ const bySeverity = {
243
+ error: 0, warning: 0, info: 0,
244
+ };
245
+ for (const error of errors) {
246
+ byCategory[error.category]++;
247
+ bySeverity[error.severity]++;
248
+ }
249
+ const hasFixable = errors.some(e => e.fixHint !== undefined);
250
+ return {
251
+ errors,
252
+ byCategory,
253
+ bySeverity,
254
+ success: bySeverity.error === 0,
255
+ hasFixable,
256
+ };
257
+ }
258
+ /**
259
+ * Extract error details from regex match
260
+ */
261
+ extractError(match, pattern, output) {
262
+ const extract = (extractor, defaultValue) => {
263
+ if (extractor === undefined)
264
+ return defaultValue;
265
+ if (typeof extractor === 'number')
266
+ return match[extractor];
267
+ return extractor(match);
268
+ };
269
+ const file = extract(pattern.extractFile, undefined);
270
+ const line = extract(pattern.extractLine, undefined);
271
+ const lineNum = line ? parseInt(String(line), 10) : undefined;
272
+ const col = extract(pattern.extractColumn, undefined);
273
+ const colNum = col ? parseInt(String(col), 10) : undefined;
274
+ // Get context (surrounding lines)
275
+ let context;
276
+ if (file && lineNum) {
277
+ const lines = output.split('\n');
278
+ const matchLineIdx = lines.findIndex(l => l.includes(match[0]));
279
+ if (matchLineIdx >= 0) {
280
+ const start = Math.max(0, matchLineIdx - 2);
281
+ const end = Math.min(lines.length, matchLineIdx + 3);
282
+ context = lines.slice(start, end).join('\n');
283
+ }
284
+ }
285
+ const severity = typeof pattern.severity === 'function'
286
+ ? pattern.severity(match)
287
+ : pattern.severity;
288
+ return {
289
+ category: pattern.category,
290
+ severity,
291
+ message: extract(pattern.extractMessage, match[0]),
292
+ file,
293
+ line: lineNum,
294
+ column: colNum,
295
+ code: extract(pattern.extractCode, undefined),
296
+ context,
297
+ raw: match[0],
298
+ fixHint: pattern.fixHint,
299
+ };
300
+ }
301
+ /**
302
+ * Classify a single error message
303
+ */
304
+ classify(message) {
305
+ for (const pattern of this.patterns) {
306
+ pattern.pattern.lastIndex = 0;
307
+ if (pattern.pattern.test(message)) {
308
+ return pattern.category;
309
+ }
310
+ }
311
+ return 'unknown';
312
+ }
313
+ /**
314
+ * Get fix suggestions for an error
315
+ */
316
+ suggestFix(error) {
317
+ const suggestions = [];
318
+ switch (error.fixHint) {
319
+ case 'type_mismatch':
320
+ suggestions.push('Check type annotations');
321
+ suggestions.push('Add explicit type cast');
322
+ suggestions.push('Update interface/type definition');
323
+ break;
324
+ case 'lint_fix':
325
+ suggestions.push('Run eslint --fix');
326
+ suggestions.push('Run prettier --write');
327
+ break;
328
+ case 'runtime_error':
329
+ suggestions.push('Add null/undefined check');
330
+ suggestions.push('Wrap in try-catch');
331
+ suggestions.push('Check variable initialization');
332
+ break;
333
+ case 'test_fix':
334
+ suggestions.push('Update expected value');
335
+ suggestions.push('Fix implementation to match test');
336
+ suggestions.push('Update test to match new behavior');
337
+ break;
338
+ case 'assertion_fix':
339
+ suggestions.push('Compare actual vs expected values');
340
+ suggestions.push('Check test data setup');
341
+ break;
342
+ case 'syntax_fix':
343
+ suggestions.push('Check for missing brackets/parentheses');
344
+ suggestions.push('Check for missing semicolons');
345
+ suggestions.push('Validate JSON/object syntax');
346
+ break;
347
+ case 'install_dependency':
348
+ if (error.code) {
349
+ suggestions.push(`npm install ${error.code}`);
350
+ suggestions.push(`Check if ${error.code} is in package.json`);
351
+ }
352
+ break;
353
+ case 'file_not_found':
354
+ suggestions.push('Create the missing file');
355
+ suggestions.push('Check the import path');
356
+ break;
357
+ case 'permission_fix':
358
+ suggestions.push('Check file permissions');
359
+ suggestions.push('Run with appropriate privileges');
360
+ break;
361
+ default:
362
+ suggestions.push('Review the error message');
363
+ suggestions.push('Search for similar issues online');
364
+ }
365
+ return suggestions;
366
+ }
367
+ /**
368
+ * Add a custom error pattern
369
+ */
370
+ addPattern(pattern) {
371
+ this.patterns.push(pattern);
372
+ }
373
+ /**
374
+ * Format errors for display
375
+ */
376
+ formatErrors(errors) {
377
+ if (errors.length === 0)
378
+ return 'No errors detected';
379
+ const lines = [];
380
+ lines.push(`Found ${errors.length} error(s):\n`);
381
+ for (const error of errors) {
382
+ const location = error.file
383
+ ? `${error.file}${error.line ? `:${error.line}` : ''}${error.column ? `:${error.column}` : ''}`
384
+ : '';
385
+ const prefix = error.severity === 'error' ? '✖' : error.severity === 'warning' ? '⚠' : 'ℹ';
386
+ const code = error.code ? `[${error.code}] ` : '';
387
+ lines.push(`${prefix} ${code}${error.message}`);
388
+ if (location)
389
+ lines.push(` at ${location}`);
390
+ if (error.fixHint) {
391
+ const suggestions = this.suggestFix(error);
392
+ if (suggestions.length > 0) {
393
+ lines.push(` 💡 ${suggestions[0]}`);
394
+ }
395
+ }
396
+ lines.push('');
397
+ }
398
+ return lines.join('\n');
399
+ }
400
+ }
401
+ exports.ErrorDetector = ErrorDetector;
402
+ // ============================================================================
403
+ // Singleton Instance
404
+ // ============================================================================
405
+ let detectorInstance = null;
406
+ function getErrorDetector() {
407
+ if (!detectorInstance) {
408
+ detectorInstance = new ErrorDetector();
409
+ }
410
+ return detectorInstance;
411
+ }
412
+ function resetErrorDetector() {
413
+ detectorInstance = null;
414
+ }
415
+ // ============================================================================
416
+ // Convenience Functions
417
+ // ============================================================================
418
+ /**
419
+ * Detect errors in output
420
+ */
421
+ function detectErrors(output) {
422
+ return getErrorDetector().detect(output);
423
+ }
424
+ /**
425
+ * Check if output contains errors
426
+ */
427
+ function hasErrors(output) {
428
+ return !detectErrors(output).success;
429
+ }
430
+ /**
431
+ * Get formatted error report
432
+ */
433
+ function formatErrorReport(output) {
434
+ const result = detectErrors(output);
435
+ return getErrorDetector().formatErrors(result.errors);
436
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Genesis Auto-Fix Engine (Darwin-Gödel Pattern)
3
+ *
4
+ * Automatically fixes detected errors using:
5
+ * 1. Mutate: Generate N fix candidates via LLM
6
+ * 2. Test: Run test suite on each
7
+ * 3. Select: Keep the one that passes most tests
8
+ * 4. Iterate: If none pass, analyze failures and retry
9
+ */
10
+ import { DetectedError, ErrorCategory } from './detector.js';
11
+ export interface FixCandidate {
12
+ /** Unique ID */
13
+ id: string;
14
+ /** Description of the fix */
15
+ description: string;
16
+ /** File to modify */
17
+ file: string;
18
+ /** Original content */
19
+ original: string;
20
+ /** Fixed content */
21
+ fixed: string;
22
+ /** Confidence score (0-1) */
23
+ confidence: number;
24
+ /** Source of the fix (pattern, llm, heuristic) */
25
+ source: 'pattern' | 'llm' | 'heuristic';
26
+ }
27
+ export interface EvaluationResult {
28
+ /** Candidate that was evaluated */
29
+ candidate: FixCandidate;
30
+ /** Whether tests passed */
31
+ testsPass: boolean;
32
+ /** Number of tests passed */
33
+ testsPassed: number;
34
+ /** Total tests run */
35
+ testsTotal: number;
36
+ /** Build succeeded */
37
+ buildSuccess: boolean;
38
+ /** New errors introduced */
39
+ newErrors: DetectedError[];
40
+ /** Errors fixed */
41
+ fixedErrors: DetectedError[];
42
+ /** Overall score (higher is better) */
43
+ score: number;
44
+ }
45
+ export interface FixResult {
46
+ /** Whether fix was successful */
47
+ success: boolean;
48
+ /** Applied candidate (if successful) */
49
+ appliedFix?: FixCandidate;
50
+ /** All candidates evaluated */
51
+ candidates: FixCandidate[];
52
+ /** Evaluation results */
53
+ evaluations: EvaluationResult[];
54
+ /** Number of iterations */
55
+ iterations: number;
56
+ /** Error if failed */
57
+ error?: string;
58
+ }
59
+ export interface FixerConfig {
60
+ /** Maximum candidates per error */
61
+ maxCandidates: number;
62
+ /** Maximum iterations */
63
+ maxIterations: number;
64
+ /** Test command */
65
+ testCommand: string;
66
+ /** Build command */
67
+ buildCommand: string;
68
+ /** Working directory */
69
+ workingDirectory: string;
70
+ /** Create backup before fix */
71
+ createBackup: boolean;
72
+ /** LLM function for generating fixes */
73
+ llmFixGenerator?: (error: DetectedError, context: string) => Promise<FixCandidate[]>;
74
+ }
75
+ interface FixPattern {
76
+ /** Error categories this pattern handles */
77
+ categories: ErrorCategory[];
78
+ /** Error message pattern to match */
79
+ messagePattern?: RegExp;
80
+ /** Error code to match */
81
+ codePattern?: RegExp;
82
+ /** Generate fix candidates */
83
+ generateFix: (error: DetectedError, fileContent: string) => FixCandidate[];
84
+ }
85
+ export declare class AutoFixer {
86
+ private config;
87
+ private patterns;
88
+ constructor(config?: Partial<FixerConfig>);
89
+ /**
90
+ * Attempt to fix errors automatically (Darwin-Gödel pattern)
91
+ */
92
+ fix(errors: DetectedError[]): Promise<FixResult>;
93
+ /**
94
+ * Generate fix candidates for errors
95
+ */
96
+ generateCandidates(errors: DetectedError[]): Promise<FixCandidate[]>;
97
+ /**
98
+ * Evaluate fix candidates
99
+ */
100
+ evaluateCandidates(candidates: FixCandidate[]): Promise<EvaluationResult[]>;
101
+ /**
102
+ * Evaluate a single candidate
103
+ */
104
+ evaluateCandidate(candidate: FixCandidate): Promise<EvaluationResult>;
105
+ /**
106
+ * Calculate evaluation score
107
+ */
108
+ private calculateScore;
109
+ /**
110
+ * Select the best candidate from evaluations
111
+ */
112
+ selectBest(evaluations: EvaluationResult[]): EvaluationResult | null;
113
+ /**
114
+ * Apply a fix permanently
115
+ */
116
+ applyFix(candidate: FixCandidate): Promise<boolean>;
117
+ getConfig(): FixerConfig;
118
+ updateConfig(config: Partial<FixerConfig>): void;
119
+ /**
120
+ * Add a custom fix pattern
121
+ */
122
+ addPattern(pattern: FixPattern): void;
123
+ /**
124
+ * Set LLM fix generator
125
+ */
126
+ setLLMGenerator(generator: (error: DetectedError, context: string) => Promise<FixCandidate[]>): void;
127
+ }
128
+ export declare function getAutoFixer(config?: Partial<FixerConfig>): AutoFixer;
129
+ export declare function resetAutoFixer(): void;
130
+ /**
131
+ * Attempt to fix errors in output
132
+ */
133
+ export declare function autoFix(output: string, config?: Partial<FixerConfig>): Promise<FixResult>;
134
+ /**
135
+ * Generate fix candidates for an error
136
+ */
137
+ export declare function generateFixes(error: DetectedError): Promise<FixCandidate[]>;
138
+ export {};