noormme 1.0.6 → 1.2.0

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 (249) hide show
  1. package/README.md +92 -63
  2. package/dist/cjs/agentic/ActionJournal.js +13 -9
  3. package/dist/cjs/agentic/CapabilityManager.d.ts +9 -4
  4. package/dist/cjs/agentic/CapabilityManager.js +113 -17
  5. package/dist/cjs/agentic/CognitiveRepository.js +19 -9
  6. package/dist/cjs/agentic/ContextBuffer.js +24 -12
  7. package/dist/cjs/agentic/Cortex.d.ts +8 -1
  8. package/dist/cjs/agentic/Cortex.js +30 -7
  9. package/dist/cjs/agentic/EpisodicMemory.js +7 -5
  10. package/dist/cjs/agentic/PersonaManager.js +16 -8
  11. package/dist/cjs/agentic/PolicyEnforcer.js +31 -12
  12. package/dist/cjs/agentic/ResourceMonitor.js +4 -4
  13. package/dist/cjs/agentic/SessionCompressor.js +22 -14
  14. package/dist/cjs/agentic/SessionManager.js +36 -18
  15. package/dist/cjs/agentic/VectorIndexer.js +22 -18
  16. package/dist/cjs/agentic/improvement/AblationEngine.js +22 -15
  17. package/dist/cjs/agentic/improvement/ActionRefiner.js +12 -10
  18. package/dist/cjs/agentic/improvement/ConflictResolver.js +5 -5
  19. package/dist/cjs/agentic/improvement/CortexJanitor.d.ts +1 -1
  20. package/dist/cjs/agentic/improvement/CortexJanitor.js +64 -27
  21. package/dist/cjs/agentic/improvement/CuriosityEngine.d.ts +2 -2
  22. package/dist/cjs/agentic/improvement/CuriosityEngine.js +68 -59
  23. package/dist/cjs/agentic/improvement/EvolutionRitual.d.ts +24 -0
  24. package/dist/cjs/agentic/improvement/EvolutionRitual.js +91 -0
  25. package/dist/cjs/agentic/improvement/EvolutionaryPilot.d.ts +5 -0
  26. package/dist/cjs/agentic/improvement/EvolutionaryPilot.js +80 -7
  27. package/dist/cjs/agentic/improvement/GoalArchitect.d.ts +2 -2
  28. package/dist/cjs/agentic/improvement/GoalArchitect.js +20 -18
  29. package/dist/cjs/agentic/improvement/GovernanceManager.d.ts +1 -1
  30. package/dist/cjs/agentic/improvement/GovernanceManager.js +85 -49
  31. package/dist/cjs/agentic/improvement/HiveLink.d.ts +9 -0
  32. package/dist/cjs/agentic/improvement/HiveLink.js +120 -26
  33. package/dist/cjs/agentic/improvement/KnowledgeDistiller.d.ts +2 -0
  34. package/dist/cjs/agentic/improvement/KnowledgeDistiller.js +101 -47
  35. package/dist/cjs/agentic/improvement/RecursiveReasoner.d.ts +7 -1
  36. package/dist/cjs/agentic/improvement/RecursiveReasoner.js +106 -22
  37. package/dist/cjs/agentic/improvement/ReflectionEngine.js +10 -8
  38. package/dist/cjs/agentic/improvement/RitualOrchestrator.js +34 -22
  39. package/dist/cjs/agentic/improvement/RuleEngine.js +22 -17
  40. package/dist/cjs/agentic/improvement/SelfEvolution.js +24 -18
  41. package/dist/cjs/agentic/improvement/SelfTestRegistry.js +18 -15
  42. package/dist/cjs/agentic/improvement/SkillSynthesizer.d.ts +48 -0
  43. package/dist/cjs/agentic/improvement/SkillSynthesizer.js +288 -0
  44. package/dist/cjs/agentic/improvement/SovereignMetrics.js +19 -17
  45. package/dist/cjs/agentic/improvement/StrategicPlanner.d.ts +1 -1
  46. package/dist/cjs/agentic/improvement/StrategicPlanner.js +129 -55
  47. package/dist/cjs/agentic/telemetry/CognitiveSynthesizer.js +26 -12
  48. package/dist/cjs/agentic/telemetry/EventHarvester.js +3 -2
  49. package/dist/cjs/agentic/telemetry/ResearchAlchemist.js +13 -4
  50. package/dist/cjs/cache/cache-manager.js +7 -4
  51. package/dist/cjs/cli/commands/analyze.js +5 -4
  52. package/dist/cjs/cli/commands/generate.js +81 -44
  53. package/dist/cjs/cli/commands/init.js +7 -3
  54. package/dist/cjs/cli/commands/inspect.js +139 -36
  55. package/dist/cjs/cli/commands/migrate.js +5 -4
  56. package/dist/cjs/cli/commands/optimize.js +4 -4
  57. package/dist/cjs/cli/commands/status.js +9 -7
  58. package/dist/cjs/cli/commands/watch.js +7 -6
  59. package/dist/cjs/cli/index.js +2 -2
  60. package/dist/cjs/cli/ui/spinner.d.ts +15 -0
  61. package/dist/cjs/cli/ui/spinner.js +76 -0
  62. package/dist/cjs/dialect/database-introspector.js +3 -1
  63. package/dist/cjs/dialect/postgresql/postgresql-driver.js +3 -1
  64. package/dist/cjs/dialect/postgresql/postgresql-features.js +18 -8
  65. package/dist/cjs/dialect/postgresql/postgresql-introspector.js +2 -2
  66. package/dist/cjs/dialect/sqlite/sqlite-auto-indexer.js +47 -33
  67. package/dist/cjs/dialect/sqlite/sqlite-auto-optimizer.js +8 -7
  68. package/dist/cjs/dialect/sqlite/sqlite-driver.js +2 -2
  69. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +15 -12
  70. package/dist/cjs/edge-runtime/edge-config.js +21 -19
  71. package/dist/cjs/errors/NoormError.js +22 -20
  72. package/dist/cjs/helpers/agent-schema.js +3 -0
  73. package/dist/cjs/helpers/postgresql.js +7 -4
  74. package/dist/cjs/helpers/schema-evolution.js +31 -6
  75. package/dist/cjs/index.d.ts +18 -16
  76. package/dist/cjs/logging/logger.js +8 -4
  77. package/dist/cjs/migration/data_migrator.js +12 -11
  78. package/dist/cjs/migration/database_migration_manager.js +17 -13
  79. package/dist/cjs/migration/schema_differ.js +22 -14
  80. package/dist/cjs/migration/schema_introspector.js +8 -8
  81. package/dist/cjs/migration/type_mapper.js +68 -67
  82. package/dist/cjs/noormme.js +54 -37
  83. package/dist/cjs/performance/index.js +5 -5
  84. package/dist/cjs/performance/query-optimizer.js +26 -21
  85. package/dist/cjs/performance/services/cache-service.js +26 -16
  86. package/dist/cjs/performance/services/connection-factory.js +28 -23
  87. package/dist/cjs/performance/services/metrics-collector.js +41 -36
  88. package/dist/cjs/performance/utils/query-parser.js +15 -16
  89. package/dist/cjs/relationships/relationship-engine.js +10 -8
  90. package/dist/cjs/repository/repository-factory.js +97 -38
  91. package/dist/cjs/schema/core/coordinators/schema-discovery.coordinator.js +1 -3
  92. package/dist/cjs/schema/core/discovery/relationship-discovery.js +16 -16
  93. package/dist/cjs/schema/core/discovery/table-metadata-discovery.js +9 -9
  94. package/dist/cjs/schema/core/discovery/view-discovery.js +5 -4
  95. package/dist/cjs/schema/core/factories/discovery-factory.js +4 -4
  96. package/dist/cjs/schema/core/utils/name-generator.js +14 -5
  97. package/dist/cjs/schema/core/utils/type-mapper.js +24 -24
  98. package/dist/cjs/schema/dialects/postgresql/postgresql-discovery.coordinator.js +8 -7
  99. package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +17 -15
  100. package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-index-discovery.js +8 -8
  101. package/dist/cjs/schema/dialects/sqlite/introspection/sqlite-schema-introspector.js +6 -11
  102. package/dist/cjs/schema/dialects/sqlite/sqlite-discovery.coordinator.js +14 -13
  103. package/dist/cjs/schema/test/basic-schema-test.js +11 -9
  104. package/dist/cjs/schema/test/dialect-capabilities.test.js +6 -6
  105. package/dist/cjs/schema/test/discovery-factory.test.js +2 -2
  106. package/dist/cjs/schema/test/error-handling.test.js +8 -6
  107. package/dist/cjs/schema/test/integration.test.js +24 -18
  108. package/dist/cjs/schema/test/schema-discovery-coordinator.test.js +9 -9
  109. package/dist/cjs/schema/test/simple-schema-test.js +9 -9
  110. package/dist/cjs/schema/test/sqlite-discovery-coordinator.test.js +64 -48
  111. package/dist/cjs/schema/test/test-runner.js +3 -3
  112. package/dist/cjs/sqlite-migration/index.d.ts +2 -2
  113. package/dist/cjs/sqlite-migration/sqlite-migration-manager.js +21 -17
  114. package/dist/cjs/sqlite-migration/sqlite-migration-provider.js +38 -34
  115. package/dist/cjs/testing/test-utils.js +36 -34
  116. package/dist/cjs/types/index.d.ts +61 -4
  117. package/dist/cjs/types/index.js +6 -3
  118. package/dist/cjs/types/type-generator.js +46 -42
  119. package/dist/cjs/util/safe-sql-helpers.js +1 -1
  120. package/dist/cjs/util/security-validator.js +20 -9
  121. package/dist/cjs/utils/errorHelpers.js +20 -10
  122. package/dist/cjs/watch/schema-watcher.js +22 -23
  123. package/dist/esm/agentic/ActionJournal.js +13 -9
  124. package/dist/esm/agentic/CapabilityManager.d.ts +9 -4
  125. package/dist/esm/agentic/CapabilityManager.js +113 -17
  126. package/dist/esm/agentic/CognitiveRepository.js +19 -9
  127. package/dist/esm/agentic/ContextBuffer.js +24 -12
  128. package/dist/esm/agentic/Cortex.d.ts +8 -1
  129. package/dist/esm/agentic/Cortex.js +30 -7
  130. package/dist/esm/agentic/EpisodicMemory.js +7 -5
  131. package/dist/esm/agentic/PersonaManager.js +16 -8
  132. package/dist/esm/agentic/PolicyEnforcer.js +31 -12
  133. package/dist/esm/agentic/ResourceMonitor.js +4 -4
  134. package/dist/esm/agentic/SessionCompressor.js +22 -14
  135. package/dist/esm/agentic/SessionManager.js +36 -18
  136. package/dist/esm/agentic/VectorIndexer.js +22 -18
  137. package/dist/esm/agentic/improvement/AblationEngine.js +22 -15
  138. package/dist/esm/agentic/improvement/ActionRefiner.js +12 -10
  139. package/dist/esm/agentic/improvement/ConflictResolver.js +5 -5
  140. package/dist/esm/agentic/improvement/CortexJanitor.d.ts +1 -1
  141. package/dist/esm/agentic/improvement/CortexJanitor.js +64 -27
  142. package/dist/esm/agentic/improvement/CuriosityEngine.d.ts +2 -2
  143. package/dist/esm/agentic/improvement/CuriosityEngine.js +68 -59
  144. package/dist/esm/agentic/improvement/EvolutionRitual.d.ts +24 -0
  145. package/dist/esm/agentic/improvement/EvolutionRitual.js +88 -0
  146. package/dist/esm/agentic/improvement/EvolutionaryPilot.d.ts +5 -0
  147. package/dist/esm/agentic/improvement/EvolutionaryPilot.js +80 -7
  148. package/dist/esm/agentic/improvement/GoalArchitect.d.ts +2 -2
  149. package/dist/esm/agentic/improvement/GoalArchitect.js +20 -18
  150. package/dist/esm/agentic/improvement/GovernanceManager.d.ts +1 -1
  151. package/dist/esm/agentic/improvement/GovernanceManager.js +85 -49
  152. package/dist/esm/agentic/improvement/HiveLink.d.ts +9 -0
  153. package/dist/esm/agentic/improvement/HiveLink.js +120 -26
  154. package/dist/esm/agentic/improvement/KnowledgeDistiller.d.ts +2 -0
  155. package/dist/esm/agentic/improvement/KnowledgeDistiller.js +101 -47
  156. package/dist/esm/agentic/improvement/RecursiveReasoner.d.ts +7 -1
  157. package/dist/esm/agentic/improvement/RecursiveReasoner.js +106 -22
  158. package/dist/esm/agentic/improvement/ReflectionEngine.js +10 -8
  159. package/dist/esm/agentic/improvement/RitualOrchestrator.js +34 -22
  160. package/dist/esm/agentic/improvement/RuleEngine.js +22 -17
  161. package/dist/esm/agentic/improvement/SelfEvolution.js +24 -18
  162. package/dist/esm/agentic/improvement/SelfTestRegistry.js +18 -15
  163. package/dist/esm/agentic/improvement/SkillSynthesizer.d.ts +48 -0
  164. package/dist/esm/agentic/improvement/SkillSynthesizer.js +285 -0
  165. package/dist/esm/agentic/improvement/SovereignMetrics.js +19 -17
  166. package/dist/esm/agentic/improvement/StrategicPlanner.d.ts +1 -1
  167. package/dist/esm/agentic/improvement/StrategicPlanner.js +129 -55
  168. package/dist/esm/agentic/telemetry/CognitiveSynthesizer.js +26 -12
  169. package/dist/esm/agentic/telemetry/EventHarvester.js +3 -2
  170. package/dist/esm/agentic/telemetry/ResearchAlchemist.js +13 -4
  171. package/dist/esm/cache/cache-manager.js +7 -4
  172. package/dist/esm/cli/commands/analyze.js +5 -4
  173. package/dist/esm/cli/commands/generate.js +82 -45
  174. package/dist/esm/cli/commands/init.js +8 -4
  175. package/dist/esm/cli/commands/inspect.js +140 -37
  176. package/dist/esm/cli/commands/migrate.js +5 -4
  177. package/dist/esm/cli/commands/optimize.js +4 -4
  178. package/dist/esm/cli/commands/status.js +9 -7
  179. package/dist/esm/cli/commands/watch.js +7 -6
  180. package/dist/esm/cli/index.js +2 -2
  181. package/dist/esm/cli/ui/spinner.d.ts +15 -0
  182. package/dist/esm/cli/ui/spinner.js +70 -0
  183. package/dist/esm/dialect/database-introspector.js +3 -1
  184. package/dist/esm/dialect/postgresql/postgresql-driver.js +3 -1
  185. package/dist/esm/dialect/postgresql/postgresql-features.js +18 -8
  186. package/dist/esm/dialect/postgresql/postgresql-introspector.js +2 -2
  187. package/dist/esm/dialect/sqlite/sqlite-auto-indexer.js +47 -33
  188. package/dist/esm/dialect/sqlite/sqlite-auto-optimizer.js +8 -7
  189. package/dist/esm/dialect/sqlite/sqlite-driver.js +2 -2
  190. package/dist/esm/dialect/sqlite/sqlite-introspector.js +15 -12
  191. package/dist/esm/dynamic/dynamic.js +1 -1
  192. package/dist/esm/edge-runtime/edge-config.js +21 -19
  193. package/dist/esm/errors/NoormError.js +22 -20
  194. package/dist/esm/helpers/agent-schema.js +3 -0
  195. package/dist/esm/helpers/postgresql.js +7 -4
  196. package/dist/esm/helpers/schema-evolution.js +31 -6
  197. package/dist/esm/index.d.ts +18 -16
  198. package/dist/esm/index.js +2 -2
  199. package/dist/esm/logging/logger.js +8 -4
  200. package/dist/esm/migration/data_migrator.js +12 -11
  201. package/dist/esm/migration/database_migration_manager.js +18 -14
  202. package/dist/esm/migration/schema_differ.js +22 -14
  203. package/dist/esm/migration/schema_introspector.js +8 -8
  204. package/dist/esm/migration/type_mapper.js +68 -67
  205. package/dist/esm/noormme.js +54 -37
  206. package/dist/esm/performance/index.js +5 -5
  207. package/dist/esm/performance/query-optimizer.js +26 -21
  208. package/dist/esm/performance/services/cache-service.js +26 -16
  209. package/dist/esm/performance/services/connection-factory.js +28 -23
  210. package/dist/esm/performance/services/metrics-collector.js +41 -36
  211. package/dist/esm/performance/utils/query-parser.js +15 -16
  212. package/dist/esm/raw-builder/sql.js +1 -1
  213. package/dist/esm/relationships/relationship-engine.js +10 -8
  214. package/dist/esm/repository/repository-factory.js +98 -39
  215. package/dist/esm/schema/builders/alter-table-add-index-builder.js +1 -1
  216. package/dist/esm/schema/builders/create-index-builder.js +2 -2
  217. package/dist/esm/schema/core/coordinators/schema-discovery.coordinator.js +1 -3
  218. package/dist/esm/schema/core/discovery/relationship-discovery.js +16 -16
  219. package/dist/esm/schema/core/discovery/table-metadata-discovery.js +9 -9
  220. package/dist/esm/schema/core/discovery/view-discovery.js +5 -4
  221. package/dist/esm/schema/core/factories/discovery-factory.js +4 -4
  222. package/dist/esm/schema/core/utils/name-generator.js +14 -5
  223. package/dist/esm/schema/core/utils/type-mapper.js +24 -24
  224. package/dist/esm/schema/dialects/postgresql/postgresql-discovery.coordinator.js +8 -7
  225. package/dist/esm/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +17 -15
  226. package/dist/esm/schema/dialects/sqlite/discovery/sqlite-index-discovery.js +8 -8
  227. package/dist/esm/schema/dialects/sqlite/introspection/sqlite-schema-introspector.js +6 -11
  228. package/dist/esm/schema/dialects/sqlite/sqlite-discovery.coordinator.js +14 -13
  229. package/dist/esm/schema/test/basic-schema-test.js +11 -9
  230. package/dist/esm/schema/test/dialect-capabilities.test.js +6 -6
  231. package/dist/esm/schema/test/discovery-factory.test.js +2 -2
  232. package/dist/esm/schema/test/error-handling.test.js +8 -6
  233. package/dist/esm/schema/test/integration.test.js +24 -18
  234. package/dist/esm/schema/test/schema-discovery-coordinator.test.js +9 -9
  235. package/dist/esm/schema/test/simple-schema-test.js +9 -9
  236. package/dist/esm/schema/test/sqlite-discovery-coordinator.test.js +64 -48
  237. package/dist/esm/schema/test/test-runner.js +3 -3
  238. package/dist/esm/sqlite-migration/index.d.ts +2 -2
  239. package/dist/esm/sqlite-migration/sqlite-migration-manager.js +21 -17
  240. package/dist/esm/sqlite-migration/sqlite-migration-provider.js +38 -34
  241. package/dist/esm/testing/test-utils.js +36 -34
  242. package/dist/esm/types/index.d.ts +61 -4
  243. package/dist/esm/types/index.js +6 -3
  244. package/dist/esm/types/type-generator.js +46 -42
  245. package/dist/esm/util/safe-sql-helpers.js +1 -1
  246. package/dist/esm/util/security-validator.js +20 -9
  247. package/dist/esm/utils/errorHelpers.js +21 -11
  248. package/dist/esm/watch/schema-watcher.js +22 -23
  249. package/package.json +40 -44
@@ -0,0 +1,285 @@
1
+ /// <reference types="./SkillSynthesizer.d.ts" />
2
+ /**
3
+ * High-Throughput Tiered AI Synthesis Strategy.
4
+ * Orchestrates multiple model tiers for cost-effective ultra-scale evolution.
5
+ */
6
+ class AISynthesisStrategy {
7
+ cortex;
8
+ synthesizer;
9
+ name = 'AISynthesisEngine';
10
+ constructor(cortex, synthesizer) {
11
+ this.cortex = cortex;
12
+ this.synthesizer = synthesizer;
13
+ }
14
+ async synthesize(context) {
15
+ let attempts = 0;
16
+ const maxRetries = 3;
17
+ // Pass 6: Ultra-Scale Tiered Routing
18
+ // Use premium model for individual mutations if available
19
+ const model = this.cortex.llmPremium || this.cortex.llm;
20
+ while (attempts < maxRetries) {
21
+ try {
22
+ const prompt = this.buildMutationPrompt(context);
23
+ if (!model) {
24
+ console.warn(`[SkillSynthesizer] No LLMProvider available. Skipping synthesis.`);
25
+ return {
26
+ mutatedDescription: context.existingDescription ||
27
+ 'Unmodified skill (Synthesis skipped: No LLM)',
28
+ mutatedMetadata: { synthesis_status: 'skipped_no_llm' },
29
+ version: `1.0.${Date.now()}`,
30
+ };
31
+ }
32
+ const response = await model.complete({
33
+ prompt,
34
+ responseFormat: 'json',
35
+ temperature: 0.3,
36
+ });
37
+ if (response.usage) {
38
+ this.synthesizer.totalTokensConsumed += response.usage.totalTokens;
39
+ }
40
+ try {
41
+ const parsed = JSON.parse(response.content);
42
+ return {
43
+ mutatedDescription: parsed.description || context.existingDescription,
44
+ mutatedMetadata: {
45
+ ...parsed.metadata,
46
+ synthesis_engine: this.cortex.llmPremium
47
+ ? 'Tiered-Premium'
48
+ : 'Production-LLM',
49
+ failure_context_size: context.failures.length,
50
+ },
51
+ version: `1.0.${Date.now()}`,
52
+ };
53
+ }
54
+ catch (err) {
55
+ throw new Error('Synthesis parse failure');
56
+ }
57
+ }
58
+ catch (error) {
59
+ attempts++;
60
+ if (attempts >= maxRetries)
61
+ throw error;
62
+ await new Promise((resolve) => setTimeout(resolve, 1000 * attempts));
63
+ }
64
+ }
65
+ throw new Error('Synthesis failed after maximum retries');
66
+ }
67
+ /**
68
+ * Batch Synthesis using FAST model (Pass 6)
69
+ */
70
+ async synthesizeBatch(contexts) {
71
+ const model = this.cortex.llmFast || this.cortex.llm;
72
+ if (!model)
73
+ return [];
74
+ const batchPrompt = `
75
+ You are a Meta-Evolutionary AI Engine optimizing multiple tools in parallel.
76
+
77
+ TOOLS TO MUTATE:
78
+ ${contexts
79
+ .map((ctx, i) => `
80
+ [Tool ${i + 1}: ${ctx.targetTool}]
81
+ Current Description: ${ctx.existingDescription || 'None'}
82
+ Failure Patterns:
83
+ ${ctx.failures.map((f) => `- Args: ${JSON.stringify(f.arguments)}, Error: ${f.error}`).join('\n')}
84
+ `)
85
+ .join('\n')}
86
+
87
+ TASK:
88
+ For each tool, provide a mutation as a JSON array of objects:
89
+ [
90
+ {
91
+ "tool": "tool_name",
92
+ "description": "Updated tool description",
93
+ "metadata": { "fixed_edge_cases": [...], "reasoning": "..." }
94
+ },
95
+ ...
96
+ ]
97
+ `;
98
+ const response = await model.complete({
99
+ prompt: batchPrompt,
100
+ responseFormat: 'json',
101
+ temperature: 0.2,
102
+ });
103
+ if (response.usage) {
104
+ this.synthesizer.totalTokensConsumed += response.usage.totalTokens;
105
+ }
106
+ try {
107
+ const parsed = JSON.parse(response.content);
108
+ return parsed.map((item) => ({
109
+ tool: item.tool,
110
+ mutation: {
111
+ mutatedDescription: item.description,
112
+ mutatedMetadata: item.metadata,
113
+ version: `1.0.${Date.now()}`,
114
+ },
115
+ }));
116
+ }
117
+ catch (err) {
118
+ return [];
119
+ }
120
+ }
121
+ buildMutationPrompt(context) {
122
+ const failureList = context.failures
123
+ .map((f, i) => `${i + 1}. Args: ${JSON.stringify(f.arguments)}, Error: ${f.error || 'None'}`)
124
+ .join('\n');
125
+ return `
126
+ You are a Meta-Evolutionary AI Engine optimizing a tool: "${context.targetTool}".
127
+ Analyze FAILURES and rewrite the description to prevent them.
128
+
129
+ EXISTING: "${context.existingDescription || 'None'}"
130
+ FAILURES:
131
+ ${failureList}
132
+
133
+ RETURN JSON: { "description": "...", "metadata": { "fixed": [...], "reason": "..." } }
134
+ `;
135
+ }
136
+ }
137
+ /**
138
+ * SkillSynthesizer implements Pass 6 Ultra-Scale Orchestration.
139
+ */
140
+ export class SkillSynthesizer {
141
+ db;
142
+ cortex;
143
+ config;
144
+ evolutionConfig;
145
+ actionsTable;
146
+ strategy;
147
+ totalTokensConsumed = 0;
148
+ constructor(db, cortex, config = {}) {
149
+ this.db = db;
150
+ this.cortex = cortex;
151
+ this.config = config;
152
+ this.evolutionConfig = config.evolution || {
153
+ verificationWindow: 20,
154
+ rollbackThresholdZ: 2.5,
155
+ enableHiveLink: true,
156
+ mutationAggressiveness: 0.5,
157
+ maxSandboxSkills: 5,
158
+ };
159
+ this.actionsTable = config.actionsTable || 'agent_actions';
160
+ this.strategy = new AISynthesisStrategy(this.cortex, this);
161
+ }
162
+ /**
163
+ * Pass 6: Predictive Pre-warming Hook
164
+ * Called by CapabilityManager when an experimental skill nears promotion.
165
+ */
166
+ async preWarmSkill(name) {
167
+ const capability = await this.cortex.capabilities.getCapabilities('experimental');
168
+ const target = capability.find((c) => c.name === name);
169
+ if (!target)
170
+ return;
171
+ // Synthesis pre-run to ensure 'Verified' description is optimized before status change
172
+ const mutation = await this.strategy.synthesize({
173
+ targetTool: target.name,
174
+ failures: [], // No recent failures, just optimizing for permanence
175
+ existingDescription: target.description,
176
+ evolutionConfig: this.evolutionConfig,
177
+ });
178
+ await this.db
179
+ .updateTable(this.cortex.agenticConfig.capabilitiesTable ||
180
+ 'agent_capabilities')
181
+ .set({
182
+ description: mutation.mutatedDescription,
183
+ metadata: JSON.stringify({
184
+ ...target.metadata,
185
+ pre_warmed: true,
186
+ pre_warmed_at: new Date(),
187
+ }),
188
+ updated_at: new Date(),
189
+ })
190
+ .where('name', '=', name)
191
+ .execute();
192
+ }
193
+ async discoverAndSynthesize() {
194
+ console.log('[SkillSynthesizer] Analyzing telemetry for parallel gaps (Ultra-Scale Batch)...');
195
+ const recentFailures = await this.db
196
+ .selectFrom(this.actionsTable)
197
+ .select(['tool_name', 'arguments', 'outcome', 'metadata', 'created_at'])
198
+ .where('status', '=', 'failure')
199
+ .orderBy('created_at', 'desc')
200
+ .limit(200)
201
+ .execute();
202
+ if (recentFailures.length < 3)
203
+ return [];
204
+ const failureClusters = new Map();
205
+ for (const f of recentFailures) {
206
+ const name = f.tool_name;
207
+ if (!failureClusters.has(name))
208
+ failureClusters.set(name, []);
209
+ failureClusters.get(name).push(f);
210
+ }
211
+ const targets = [];
212
+ for (const [name, list] of failureClusters.entries()) {
213
+ if (list.length >= 3)
214
+ targets.push({ tool: name, failures: list });
215
+ }
216
+ if (targets.length === 0)
217
+ return [];
218
+ const domainBatches = new Map();
219
+ for (const target of targets) {
220
+ const domain = target.tool.split('_')[0] || 'general';
221
+ if (!domainBatches.has(domain))
222
+ domainBatches.set(domain, []);
223
+ domainBatches.get(domain).push(target);
224
+ }
225
+ await this.pruneSandboxIfNeeded();
226
+ const results = [];
227
+ for (const [domain, items] of domainBatches.entries()) {
228
+ const contexts = await Promise.all(items.map(async (item) => {
229
+ return {
230
+ targetTool: item.tool,
231
+ failures: item.failures.map((f) => ({
232
+ arguments: typeof f.arguments === 'string'
233
+ ? JSON.parse(f.arguments)
234
+ : f.arguments,
235
+ error: f.outcome,
236
+ timestamp: new Date(f.created_at),
237
+ })),
238
+ evolutionConfig: this.evolutionConfig,
239
+ };
240
+ }));
241
+ if (items.length > 1 && (this.cortex.llmFast || this.cortex.llm)) {
242
+ const batchMutations = await this.strategy.synthesizeBatch(contexts);
243
+ for (const bm of batchMutations) {
244
+ const reg = await this.registerMutation(bm.tool, bm.mutation);
245
+ if (reg)
246
+ results.push(reg);
247
+ }
248
+ }
249
+ else {
250
+ for (const ctx of contexts) {
251
+ const mutation = await this.strategy.synthesize(ctx);
252
+ const reg = await this.registerMutation(ctx.targetTool, mutation);
253
+ if (reg)
254
+ results.push(reg);
255
+ }
256
+ }
257
+ }
258
+ return results;
259
+ }
260
+ async registerMutation(tool, mutation) {
261
+ return await this.cortex.capabilities.registerCapability(tool, mutation.version, mutation.mutatedDescription, {
262
+ initialStatus: 'experimental',
263
+ mutatedFrom: tool,
264
+ synthesis_engine: 'Ultra-Scale-Tiered',
265
+ ...mutation.mutatedMetadata,
266
+ synthesized_at: new Date(),
267
+ });
268
+ }
269
+ async pruneSandboxIfNeeded() {
270
+ const experimental = await this.cortex.capabilities.getCapabilities('experimental');
271
+ const maxSkills = this.evolutionConfig.maxSandboxSkills || 5;
272
+ if (experimental.length >= maxSkills) {
273
+ const toPrune = experimental
274
+ .sort((a, b) => a.reliability - b.reliability)
275
+ .slice(0, Math.ceil(experimental.length * 0.2));
276
+ for (const skill of toPrune) {
277
+ await this.db
278
+ .deleteFrom(this.cortex.agenticConfig.capabilitiesTable ||
279
+ 'agent_capabilities')
280
+ .where('id', '=', skill.id)
281
+ .execute();
282
+ }
283
+ }
284
+ }
285
+ }
@@ -19,7 +19,7 @@ export class SovereignMetrics {
19
19
  * Record a metric point
20
20
  */
21
21
  async recordMetric(metricName, metricValue, options = {}) {
22
- const metric = await this.db
22
+ const metric = (await this.db
23
23
  .insertInto(this.metricsTable)
24
24
  .values({
25
25
  session_id: options.sessionId ?? null,
@@ -28,10 +28,10 @@ export class SovereignMetrics {
28
28
  metric_value: metricValue,
29
29
  unit: options.unit ?? null,
30
30
  metadata: options.metadata ? JSON.stringify(options.metadata) : null,
31
- created_at: new Date()
31
+ created_at: new Date(),
32
32
  })
33
33
  .returningAll()
34
- .executeTakeFirstOrThrow();
34
+ .executeTakeFirstOrThrow());
35
35
  return this.parseMetric(metric);
36
36
  }
37
37
  /**
@@ -55,7 +55,7 @@ export class SovereignMetrics {
55
55
  eb.fn.min('metric_value').as('min'),
56
56
  eb.fn.max('metric_value').as('max'),
57
57
  eb.fn.avg('metric_value').as('avg'),
58
- eb.fn.count('id').as('count')
58
+ eb.fn.count('id').as('count'),
59
59
  ])
60
60
  .where('metric_name', '=', metricName);
61
61
  if (options.agentId) {
@@ -64,51 +64,51 @@ export class SovereignMetrics {
64
64
  if (options.sessionId) {
65
65
  query = query.where('session_id', '=', options.sessionId);
66
66
  }
67
- const result = await query.executeTakeFirst();
67
+ const result = (await query.executeTakeFirst());
68
68
  return {
69
69
  min: Number(result?.min || 0),
70
70
  max: Number(result?.max || 0),
71
71
  avg: Number(result?.avg || 0),
72
- count: Number(result?.count || 0)
72
+ count: Number(result?.count || 0),
73
73
  };
74
74
  }
75
75
  /**
76
76
  * Get recent metrics for analysis
77
77
  */
78
78
  async getRecentMetrics(limit = 50) {
79
- const list = await this.typedDb
79
+ const list = (await this.typedDb
80
80
  .selectFrom(this.metricsTable)
81
81
  .selectAll()
82
82
  .orderBy('created_at', 'desc')
83
83
  .limit(limit)
84
- .execute();
85
- return list.map(m => this.parseMetric(m));
84
+ .execute());
85
+ return list.map((m) => this.parseMetric(m));
86
86
  }
87
87
  /**
88
88
  * Get metrics filtered by agent ID.
89
89
  */
90
90
  async getMetricsByAgent(agentId, limit = 50) {
91
- const list = await this.typedDb
91
+ const list = (await this.typedDb
92
92
  .selectFrom(this.metricsTable)
93
93
  .selectAll()
94
94
  .where('agent_id', '=', agentId)
95
95
  .orderBy('created_at', 'desc')
96
96
  .limit(limit)
97
- .execute();
98
- return list.map(m => this.parseMetric(m));
97
+ .execute());
98
+ return list.map((m) => this.parseMetric(m));
99
99
  }
100
100
  /**
101
101
  * Get metrics filtered by session ID.
102
102
  */
103
103
  async getMetricsBySession(sessionId, limit = 50) {
104
- const list = await this.typedDb
104
+ const list = (await this.typedDb
105
105
  .selectFrom(this.metricsTable)
106
106
  .selectAll()
107
107
  .where('session_id', '=', sessionId)
108
108
  .orderBy('created_at', 'desc')
109
109
  .limit(limit)
110
- .execute();
111
- return list.map(m => this.parseMetric(m));
110
+ .execute());
111
+ return list.map((m) => this.parseMetric(m));
112
112
  }
113
113
  parseMetric(m) {
114
114
  return {
@@ -118,8 +118,10 @@ export class SovereignMetrics {
118
118
  metricName: m.metric_name,
119
119
  metricValue: m.metric_value,
120
120
  unit: m.unit,
121
- metadata: typeof m.metadata === 'string' ? JSON.parse(m.metadata) : (m.metadata || {}),
122
- createdAt: new Date(m.created_at)
121
+ metadata: typeof m.metadata === 'string'
122
+ ? JSON.parse(m.metadata)
123
+ : m.metadata || {},
124
+ createdAt: new Date(m.created_at),
123
125
  };
124
126
  }
125
127
  }
@@ -74,7 +74,7 @@ export declare class StrategicPlanner {
74
74
  */
75
75
  analyzePersona(id: string | number): Promise<PerformanceReport>;
76
76
  /**
77
- * (Deprecated in favor of initiateAblationMutation) Evolve a persona directly.
77
+ * Evolve a persona directly based on performance.
78
78
  */
79
79
  evolvePersona(persona: AgentPersona, report: PerformanceReport): Promise<string | null>;
80
80
  /**