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