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
|
@@ -29,9 +29,9 @@ class StrategicPlanner {
|
|
|
29
29
|
const mutations = [];
|
|
30
30
|
// 0. Pre-Flight System Health Check (Phase 4)
|
|
31
31
|
const tests = await this.cortex.tests.runAllProbes();
|
|
32
|
-
const failedTests = tests.filter(t => !t.success);
|
|
32
|
+
const failedTests = tests.filter((t) => !t.success);
|
|
33
33
|
if (failedTests.length > 0) {
|
|
34
|
-
console.warn(`[StrategicPlanner] Mutation cycle aborted. System health probes failed: ${failedTests.map(t => t.name).join(', ')}`);
|
|
34
|
+
console.warn(`[StrategicPlanner] Mutation cycle aborted. System health probes failed: ${failedTests.map((t) => t.name).join(', ')}`);
|
|
35
35
|
return [];
|
|
36
36
|
}
|
|
37
37
|
const personas = await this.typedDb
|
|
@@ -52,12 +52,20 @@ class StrategicPlanner {
|
|
|
52
52
|
const report = await this.analyzePersona(persona.id);
|
|
53
53
|
// 3. Blacklist Check (Local & Global Phase 5)
|
|
54
54
|
const lastMutation = persona.metadata?.last_failed_mutation;
|
|
55
|
-
const allPersonas = await this.typedDb
|
|
56
|
-
|
|
55
|
+
const allPersonas = await this.typedDb
|
|
56
|
+
.selectFrom(this.personasTable)
|
|
57
|
+
.selectAll()
|
|
58
|
+
.execute();
|
|
59
|
+
const isGloballyBlacklisted = allPersonas.some((p) => {
|
|
57
60
|
const mp = this.parsePersona(p);
|
|
58
|
-
return mp.metadata?.last_failed_mutation?.type === report.recommendation &&
|
|
61
|
+
return (mp.metadata?.last_failed_mutation?.type === report.recommendation &&
|
|
62
|
+
Date.now() - (mp.metadata?.last_failed_mutation?.timestamp || 0) <
|
|
63
|
+
3600000);
|
|
59
64
|
});
|
|
60
|
-
if (isGloballyBlacklisted ||
|
|
65
|
+
if (isGloballyBlacklisted ||
|
|
66
|
+
(lastMutation &&
|
|
67
|
+
report.recommendation === lastMutation.type &&
|
|
68
|
+
Date.now() - lastMutation.timestamp < 86400000)) {
|
|
61
69
|
console.log(`[StrategicPlanner] Skipping blacklisted mutation ${report.recommendation} for persona ${persona.id} (Global=${isGloballyBlacklisted})`);
|
|
62
70
|
continue;
|
|
63
71
|
}
|
|
@@ -76,22 +84,33 @@ class StrategicPlanner {
|
|
|
76
84
|
*/
|
|
77
85
|
async applyDirectMutation(persona, report, failures = []) {
|
|
78
86
|
return await this.db.transaction().execute(async (trx) => {
|
|
79
|
-
const reason = failures.length > 0
|
|
87
|
+
const reason = failures.length > 0
|
|
88
|
+
? `Failure Patterns: ${failures.join(', ')}`
|
|
89
|
+
: report.recommendation;
|
|
80
90
|
console.log(`[StrategicPlanner] Applying direct mutation to persona ${persona.id} (Reason: ${reason})`);
|
|
81
91
|
let updates = {};
|
|
82
92
|
let mutationType = 'role_update';
|
|
83
93
|
if (failures.length > 0) {
|
|
84
94
|
// Lesson-Driven Synthesis: Pull categories of lessons
|
|
85
95
|
const lessons = await this.cortex.reasoner.synthesizeLessons();
|
|
86
|
-
const relevantLessons = updates.role
|
|
87
|
-
|
|
96
|
+
const relevantLessons = updates.role
|
|
97
|
+
? []
|
|
98
|
+
: (lessons['general'] || []).slice(0, 2);
|
|
99
|
+
updates = {
|
|
100
|
+
role: `${persona.role || ''} (Optimized for: ${failures.join(', ')}. Patterns: ${relevantLessons.join('; ')})`.trim(),
|
|
101
|
+
};
|
|
88
102
|
}
|
|
89
103
|
else {
|
|
90
104
|
// Evolutionary Cross-Pollination (Phase 5)
|
|
91
|
-
const allPersonas = await
|
|
105
|
+
const allPersonas = await trx
|
|
106
|
+
.selectFrom(this.personasTable)
|
|
107
|
+
.selectAll()
|
|
108
|
+
.execute();
|
|
92
109
|
const winningMutations = allPersonas
|
|
93
|
-
.map(p => this.parsePersona(p))
|
|
94
|
-
.filter(p => (p.metadata?.evolution_status === 'stable' ||
|
|
110
|
+
.map((p) => this.parsePersona(p))
|
|
111
|
+
.filter((p) => (p.metadata?.evolution_status === 'stable' ||
|
|
112
|
+
!p.metadata?.evolution_status) &&
|
|
113
|
+
p.metadata?.mutation_reason?.includes(report.recommendation));
|
|
95
114
|
if (winningMutations.length > 0 && Math.random() > 0.5) {
|
|
96
115
|
console.log(`[StrategicPlanner] Cross-Pollinating success from Persona ${winningMutations[0].id}`);
|
|
97
116
|
updates = { role: winningMutations[0].role || persona.role };
|
|
@@ -99,10 +118,18 @@ class StrategicPlanner {
|
|
|
99
118
|
else {
|
|
100
119
|
switch (report.recommendation) {
|
|
101
120
|
case 'optimize_accuracy':
|
|
102
|
-
updates = {
|
|
121
|
+
updates = {
|
|
122
|
+
role: `${persona.role || ''} (Focus strictly on accuracy and detailed verification)`.trim(),
|
|
123
|
+
};
|
|
103
124
|
break;
|
|
104
125
|
case 'optimize_efficiency':
|
|
105
|
-
updates = {
|
|
126
|
+
updates = {
|
|
127
|
+
policies: [
|
|
128
|
+
...(persona.policies || []),
|
|
129
|
+
'timeout_reduction',
|
|
130
|
+
'concise_output',
|
|
131
|
+
],
|
|
132
|
+
};
|
|
106
133
|
mutationType = 'policy_update';
|
|
107
134
|
break;
|
|
108
135
|
case 'critical_intervention':
|
|
@@ -130,10 +157,10 @@ class StrategicPlanner {
|
|
|
130
157
|
previousState: {
|
|
131
158
|
role: persona.role,
|
|
132
159
|
policies: persona.policies,
|
|
133
|
-
capabilities: persona.capabilities
|
|
160
|
+
capabilities: persona.capabilities,
|
|
134
161
|
},
|
|
135
162
|
newState: { ...updates },
|
|
136
|
-
reason: `Auto-mutation triggered by ${report.recommendation}
|
|
163
|
+
reason: `Auto-mutation triggered by ${report.recommendation}`,
|
|
137
164
|
};
|
|
138
165
|
const history = [...(persona.metadata?.mutationHistory || []), mutation];
|
|
139
166
|
if (history.length > 5)
|
|
@@ -146,17 +173,21 @@ class StrategicPlanner {
|
|
|
146
173
|
verification_started_at: Date.now(),
|
|
147
174
|
verification_baseline: {
|
|
148
175
|
successRate: report.successRate,
|
|
149
|
-
averageLatency: report.averageLatency
|
|
150
|
-
}
|
|
176
|
+
averageLatency: report.averageLatency,
|
|
177
|
+
},
|
|
151
178
|
};
|
|
152
179
|
await trx
|
|
153
180
|
.updateTable(this.personasTable)
|
|
154
181
|
.set({
|
|
155
182
|
role: updates.role || persona.role,
|
|
156
|
-
policies: updates.policies
|
|
157
|
-
|
|
183
|
+
policies: updates.policies
|
|
184
|
+
? JSON.stringify(updates.policies)
|
|
185
|
+
: undefined,
|
|
186
|
+
capabilities: updates.capabilities
|
|
187
|
+
? JSON.stringify(updates.capabilities)
|
|
188
|
+
: undefined,
|
|
158
189
|
metadata: JSON.stringify(newMetadata),
|
|
159
|
-
updated_at: new Date()
|
|
190
|
+
updated_at: new Date(),
|
|
160
191
|
})
|
|
161
192
|
.where('id', '=', persona.id)
|
|
162
193
|
.execute();
|
|
@@ -171,25 +202,46 @@ class StrategicPlanner {
|
|
|
171
202
|
const report = await this.analyzePersona(persona.id);
|
|
172
203
|
// Adaptive Meta-Tuning: Increase window based on rollback history (Phase 4)
|
|
173
204
|
const rollbackHistory = persona.metadata?.rollbackHistory || [];
|
|
174
|
-
const recentRollbacks = rollbackHistory.filter(ts =>
|
|
205
|
+
const recentRollbacks = rollbackHistory.filter((ts) => Date.now() - ts < 604800000).length;
|
|
175
206
|
// Hive-Mind Verification Speedups (Phase 5)
|
|
176
|
-
const allPersonas = await this.typedDb
|
|
177
|
-
|
|
178
|
-
|
|
207
|
+
const allPersonas = await this.typedDb
|
|
208
|
+
.selectFrom(this.personasTable)
|
|
209
|
+
.selectAll()
|
|
210
|
+
.execute();
|
|
211
|
+
const hiveTrusted = allPersonas
|
|
212
|
+
.map((p) => this.parsePersona(p))
|
|
213
|
+
.filter((p) => p.metadata?.evolution_status === 'stable' &&
|
|
214
|
+
p.metadata?.mutation_reason === persona.metadata?.mutation_reason).length;
|
|
215
|
+
let sampleSizeThreshold = 10 + recentRollbacks * 10;
|
|
216
|
+
// Pass 5: Adaptive Verification Windows
|
|
217
|
+
// If a mutation is performing exceptionally well early on (Z-score check), accelerate stabilization.
|
|
218
|
+
const earlyStats = await this.analyzePersona(persona.id);
|
|
219
|
+
const earlyBaseline = persona.metadata?.verification_baseline || {
|
|
220
|
+
successRate: 0.8,
|
|
221
|
+
};
|
|
222
|
+
const earlyZ = (earlyStats.successRate - earlyBaseline.successRate) / 0.1; // Use nominal stdDev for early check
|
|
223
|
+
if (earlyZ > 3.0 && earlyStats.sampleSize >= 5) {
|
|
224
|
+
console.log(`[StrategicPlanner] High Performance Detected (Z=${earlyZ.toFixed(2)}). Accelerating stabilization threshold.`);
|
|
225
|
+
sampleSizeThreshold = 5; // Accelerated Stabilization
|
|
226
|
+
}
|
|
179
227
|
if (hiveTrusted >= 3) {
|
|
180
228
|
console.log(`[StrategicPlanner] Accelerating verification for Persona ${persona.id} (Hive-Mind Trusted)`);
|
|
181
229
|
sampleSizeThreshold = Math.max(5, Math.floor(sampleSizeThreshold / 2));
|
|
182
230
|
}
|
|
183
231
|
if (report.sampleSize < sampleSizeThreshold)
|
|
184
232
|
return null;
|
|
185
|
-
const baseline = persona.metadata?.verification_baseline || {
|
|
233
|
+
const baseline = persona.metadata?.verification_baseline || {
|
|
234
|
+
successRate: 0.8,
|
|
235
|
+
averageLatency: 500,
|
|
236
|
+
};
|
|
186
237
|
// Dynamic Variance Calculation (Intelligence Refinement)
|
|
187
238
|
const recentMetrics = await this.cortex.metrics.getRecentMetrics(100);
|
|
188
239
|
const values = recentMetrics
|
|
189
|
-
.filter(m => m.metricName === 'success_rate')
|
|
190
|
-
.map(m => Number(m.metricValue));
|
|
240
|
+
.filter((m) => m.metricName === 'success_rate')
|
|
241
|
+
.map((m) => Number(m.metricValue));
|
|
191
242
|
const mean = values.reduce((a, b) => a + b, 0) / (values.length || 1);
|
|
192
|
-
const variance = values.reduce((a, b) => a + Math.pow(b - mean, 2), 0) /
|
|
243
|
+
const variance = values.reduce((a, b) => a + Math.pow(b - mean, 2), 0) /
|
|
244
|
+
(values.length || 1);
|
|
193
245
|
const stdDev = Math.sqrt(variance) || 0.1;
|
|
194
246
|
const zScore = (report.successRate - baseline.successRate) / (stdDev || 1);
|
|
195
247
|
console.log(`[StrategicPlanner] Verifying persona ${persona.id}: Success=${report.successRate.toFixed(2)} (Baseline=${baseline.successRate.toFixed(2)}, Ļ=${stdDev.toFixed(3)}, Z-Score=${zScore.toFixed(2)}, Threshold=${sampleSizeThreshold})`);
|
|
@@ -199,18 +251,26 @@ class StrategicPlanner {
|
|
|
199
251
|
return await this.rollbackPersona(persona.id);
|
|
200
252
|
}
|
|
201
253
|
// 2. Stabilization (Proven improvement or stability)
|
|
202
|
-
if (report.sampleSize >=
|
|
254
|
+
if (report.sampleSize >= sampleSizeThreshold * 2 && zScore >= -0.5) {
|
|
203
255
|
console.log(`[StrategicPlanner] Evolution for persona ${persona.id} STABILIZED.`);
|
|
204
256
|
// Cognitive Rule Distillation (Phase 4)
|
|
205
257
|
if (persona.metadata?.mutation_reason?.includes('optimize_efficiency')) {
|
|
206
258
|
await this.cortex.rules.defineRule('all', 'all', 'audit', {
|
|
207
259
|
condition: 'latency > 500',
|
|
208
260
|
priority: 10,
|
|
209
|
-
metadata: {
|
|
261
|
+
metadata: {
|
|
262
|
+
reason: `Distilled from successful persona ${persona.id} optimization`,
|
|
263
|
+
},
|
|
210
264
|
});
|
|
211
265
|
}
|
|
212
|
-
await this.db
|
|
213
|
-
.
|
|
266
|
+
await this.db
|
|
267
|
+
.updateTable(this.personasTable)
|
|
268
|
+
.set({
|
|
269
|
+
metadata: JSON.stringify({
|
|
270
|
+
...persona.metadata,
|
|
271
|
+
evolution_status: 'stable',
|
|
272
|
+
}),
|
|
273
|
+
})
|
|
214
274
|
.where('id', '=', persona.id)
|
|
215
275
|
.execute();
|
|
216
276
|
return `Evolution stabilized for persona ${persona.id}`;
|
|
@@ -232,7 +292,7 @@ class StrategicPlanner {
|
|
|
232
292
|
try {
|
|
233
293
|
const failureReport = await this.cortex.actions.getFailureReport();
|
|
234
294
|
// Only consider tools that failed more than once
|
|
235
|
-
const frequentFailures = failureReport.filter(f => f.failureCount > 1);
|
|
295
|
+
const frequentFailures = failureReport.filter((f) => f.failureCount > 1);
|
|
236
296
|
for (const fail of frequentFailures) {
|
|
237
297
|
patterns.push(`tool_failure_${fail.toolName}`);
|
|
238
298
|
}
|
|
@@ -252,7 +312,7 @@ class StrategicPlanner {
|
|
|
252
312
|
.selectAll()
|
|
253
313
|
.where((eb) => eb.or([
|
|
254
314
|
eb((0, sql_js_1.sql) `json_extract(metadata, '$.persona_id')`, '=', id),
|
|
255
|
-
eb((0, sql_js_1.sql) `metadata->>'persona_id'`, '=', String(id))
|
|
315
|
+
eb((0, sql_js_1.sql) `metadata->>'persona_id'`, '=', String(id)),
|
|
256
316
|
]))
|
|
257
317
|
.orderBy('created_at', 'desc')
|
|
258
318
|
.limit(50)
|
|
@@ -260,7 +320,9 @@ class StrategicPlanner {
|
|
|
260
320
|
// 1. Fetch Global Baseline for Dynamic Thresholds
|
|
261
321
|
const globalMetrics = await this.cortex.metrics.getRecentMetrics(200);
|
|
262
322
|
const calcStats = (metricName) => {
|
|
263
|
-
const vals = globalMetrics
|
|
323
|
+
const vals = globalMetrics
|
|
324
|
+
.filter((m) => m.metricName === metricName)
|
|
325
|
+
.map((m) => Number(m.metricValue));
|
|
264
326
|
if (vals.length < 10)
|
|
265
327
|
return { mean: metricName === 'query_latency' ? 500 : 0.9, stdDev: 0.1 };
|
|
266
328
|
const mean = vals.reduce((a, b) => a + b, 0) / vals.length;
|
|
@@ -275,25 +337,27 @@ class StrategicPlanner {
|
|
|
275
337
|
successRate: successStats.mean,
|
|
276
338
|
averageLatency: latencyStats.mean,
|
|
277
339
|
sampleSize: 0,
|
|
278
|
-
recommendation: 'maintain'
|
|
340
|
+
recommendation: 'maintain',
|
|
279
341
|
};
|
|
280
342
|
}
|
|
281
|
-
const successMetrics = recentMetrics.filter(m => m.metric_name === 'task_success_rate');
|
|
282
|
-
const latencyMetrics = recentMetrics.filter(m => m.metric_name === 'query_latency');
|
|
343
|
+
const successMetrics = recentMetrics.filter((m) => m.metric_name === 'task_success_rate');
|
|
344
|
+
const latencyMetrics = recentMetrics.filter((m) => m.metric_name === 'query_latency');
|
|
283
345
|
const avgSuccess = successMetrics.length > 0
|
|
284
|
-
? successMetrics.reduce((sum, m) => sum + Number(m.metric_value), 0) /
|
|
346
|
+
? successMetrics.reduce((sum, m) => sum + Number(m.metric_value), 0) /
|
|
347
|
+
successMetrics.length
|
|
285
348
|
: successStats.mean;
|
|
286
349
|
const avgLatency = latencyMetrics.length > 0
|
|
287
|
-
? latencyMetrics.reduce((sum, m) => sum + Number(m.metric_value), 0) /
|
|
350
|
+
? latencyMetrics.reduce((sum, m) => sum + Number(m.metric_value), 0) /
|
|
351
|
+
latencyMetrics.length
|
|
288
352
|
: latencyStats.mean;
|
|
289
353
|
let recommendation = 'maintain';
|
|
290
354
|
// 2. Map Dynamic Thresholds to Recommendations
|
|
291
355
|
// Critical: Worse than 2.5 standard deviations from mean
|
|
292
|
-
const criticalThreshold = successStats.mean -
|
|
356
|
+
const criticalThreshold = successStats.mean - 2.5 * successStats.stdDev;
|
|
293
357
|
// Optimize: Worse than 1.0 standard deviations from mean
|
|
294
|
-
const accuracyThreshold = successStats.mean -
|
|
358
|
+
const accuracyThreshold = successStats.mean - 1.0 * successStats.stdDev;
|
|
295
359
|
// Efficiency: Latency > 2 standard deviations above mean
|
|
296
|
-
const efficiencyThreshold = latencyStats.mean +
|
|
360
|
+
const efficiencyThreshold = latencyStats.mean + 2.0 * latencyStats.stdDev;
|
|
297
361
|
if (avgSuccess < criticalThreshold) {
|
|
298
362
|
recommendation = 'critical_intervention';
|
|
299
363
|
}
|
|
@@ -309,11 +373,11 @@ class StrategicPlanner {
|
|
|
309
373
|
successRate: avgSuccess,
|
|
310
374
|
averageLatency: avgLatency,
|
|
311
375
|
sampleSize: recentMetrics.length,
|
|
312
|
-
recommendation
|
|
376
|
+
recommendation,
|
|
313
377
|
};
|
|
314
378
|
}
|
|
315
379
|
/**
|
|
316
|
-
*
|
|
380
|
+
* Evolve a persona directly based on performance.
|
|
317
381
|
*/
|
|
318
382
|
async evolvePersona(persona, report) {
|
|
319
383
|
return await this.applyDirectMutation(persona, report);
|
|
@@ -345,19 +409,23 @@ class StrategicPlanner {
|
|
|
345
409
|
rollbackHistory: rollbackHistory,
|
|
346
410
|
last_failed_mutation: {
|
|
347
411
|
type: lastMutation.type,
|
|
348
|
-
timestamp: Date.now()
|
|
412
|
+
timestamp: Date.now(),
|
|
349
413
|
},
|
|
350
414
|
evolution_status: 'stable',
|
|
351
|
-
lastRollback: Date.now()
|
|
415
|
+
lastRollback: Date.now(),
|
|
352
416
|
};
|
|
353
417
|
await trx
|
|
354
418
|
.updateTable(this.personasTable)
|
|
355
419
|
.set({
|
|
356
420
|
role: previous.role,
|
|
357
|
-
policies: previous.policies
|
|
358
|
-
|
|
421
|
+
policies: previous.policies
|
|
422
|
+
? JSON.stringify(previous.policies)
|
|
423
|
+
: undefined,
|
|
424
|
+
capabilities: previous.capabilities
|
|
425
|
+
? JSON.stringify(previous.capabilities)
|
|
426
|
+
: undefined,
|
|
359
427
|
metadata: JSON.stringify(newMetadata),
|
|
360
|
-
updated_at: new Date()
|
|
428
|
+
updated_at: new Date(),
|
|
361
429
|
})
|
|
362
430
|
.where('id', '=', id)
|
|
363
431
|
.execute();
|
|
@@ -369,11 +437,17 @@ class StrategicPlanner {
|
|
|
369
437
|
id: p.id,
|
|
370
438
|
name: p.name,
|
|
371
439
|
role: p.role,
|
|
372
|
-
capabilities: typeof p.capabilities === 'string'
|
|
373
|
-
|
|
374
|
-
|
|
440
|
+
capabilities: typeof p.capabilities === 'string'
|
|
441
|
+
? JSON.parse(p.capabilities)
|
|
442
|
+
: p.capabilities || [],
|
|
443
|
+
policies: typeof p.policies === 'string'
|
|
444
|
+
? JSON.parse(p.policies)
|
|
445
|
+
: p.policies || [],
|
|
446
|
+
metadata: typeof p.metadata === 'string'
|
|
447
|
+
? JSON.parse(p.metadata)
|
|
448
|
+
: p.metadata || {},
|
|
375
449
|
createdAt: new Date(p.created_at),
|
|
376
|
-
updatedAt: new Date(p.updated_at)
|
|
450
|
+
updatedAt: new Date(p.updated_at),
|
|
377
451
|
};
|
|
378
452
|
}
|
|
379
453
|
}
|
|
@@ -13,7 +13,8 @@ class CognitiveSynthesizer {
|
|
|
13
13
|
constructor(db, config = {}) {
|
|
14
14
|
this.db = db;
|
|
15
15
|
this.config = config;
|
|
16
|
-
this.evolutionTable =
|
|
16
|
+
this.evolutionTable =
|
|
17
|
+
config.sessionEvolutionTable || 'agent_session_evolution';
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Infer goals and update session evolution with production-grade persistence.
|
|
@@ -33,12 +34,13 @@ class CognitiveSynthesizer {
|
|
|
33
34
|
if (existing) {
|
|
34
35
|
const currentPath = this.parsePath(existing.evolution_path);
|
|
35
36
|
// Only append to path if goal or strategy shifted significantly
|
|
36
|
-
if (existing.inferred_goal !== goalInferred ||
|
|
37
|
+
if (existing.inferred_goal !== goalInferred ||
|
|
38
|
+
existing.strategy !== strategy) {
|
|
37
39
|
currentPath.push({
|
|
38
40
|
timestamp: new Date().toISOString(),
|
|
39
41
|
previousGoal: existing.inferred_goal,
|
|
40
42
|
newGoal: goalInferred,
|
|
41
|
-
strategyShift: strategy
|
|
43
|
+
strategyShift: strategy,
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
await trx
|
|
@@ -49,7 +51,7 @@ class CognitiveSynthesizer {
|
|
|
49
51
|
evolution_path: JSON.stringify(currentPath),
|
|
50
52
|
status: 'active',
|
|
51
53
|
autonomy_level: this.calculateAutonomy(currentPath.length, existing.autonomy_level || 1),
|
|
52
|
-
updated_at: new Date()
|
|
54
|
+
updated_at: new Date(),
|
|
53
55
|
})
|
|
54
56
|
.where('session_id', '=', sessionId)
|
|
55
57
|
.execute();
|
|
@@ -61,14 +63,16 @@ class CognitiveSynthesizer {
|
|
|
61
63
|
session_id: sessionId,
|
|
62
64
|
inferred_goal: goalInferred,
|
|
63
65
|
strategy,
|
|
64
|
-
evolution_path: JSON.stringify([
|
|
66
|
+
evolution_path: JSON.stringify([
|
|
67
|
+
{
|
|
65
68
|
timestamp: new Date().toISOString(),
|
|
66
69
|
event: 'session_start',
|
|
67
|
-
initialGoal: goalInferred
|
|
68
|
-
}
|
|
70
|
+
initialGoal: goalInferred,
|
|
71
|
+
},
|
|
72
|
+
]),
|
|
69
73
|
status: 'active',
|
|
70
74
|
autonomy_level: 1,
|
|
71
|
-
updated_at: new Date()
|
|
75
|
+
updated_at: new Date(),
|
|
72
76
|
})
|
|
73
77
|
.execute();
|
|
74
78
|
}
|
|
@@ -97,7 +101,9 @@ class CognitiveSynthesizer {
|
|
|
97
101
|
timestamp: new Date().toISOString(),
|
|
98
102
|
type: 'shift',
|
|
99
103
|
shift: shiftType,
|
|
100
|
-
reason: shiftType === 'abandonment'
|
|
104
|
+
reason: shiftType === 'abandonment'
|
|
105
|
+
? 'User manual termination or lack of progress'
|
|
106
|
+
: 'Strategic goal shift',
|
|
101
107
|
});
|
|
102
108
|
await trx
|
|
103
109
|
.updateTable(this.evolutionTable)
|
|
@@ -105,7 +111,7 @@ class CognitiveSynthesizer {
|
|
|
105
111
|
status: shiftType === 'pivot' ? 'pivoted' : 'abandoned',
|
|
106
112
|
strategy: shiftType === 'pivot' ? 'Strategic Pivot' : 'Terminated',
|
|
107
113
|
evolution_path: JSON.stringify(currentPath),
|
|
108
|
-
updated_at: new Date()
|
|
114
|
+
updated_at: new Date(),
|
|
109
115
|
})
|
|
110
116
|
.where('session_id', '=', sessionId)
|
|
111
117
|
.execute();
|
|
@@ -121,7 +127,15 @@ class CognitiveSynthesizer {
|
|
|
121
127
|
if (clean.length < 100)
|
|
122
128
|
return clean;
|
|
123
129
|
// Simple heuristic: look for "need", "want", "please", "can you"
|
|
124
|
-
const keywords = [
|
|
130
|
+
const keywords = [
|
|
131
|
+
'need',
|
|
132
|
+
'want',
|
|
133
|
+
'please',
|
|
134
|
+
'can you',
|
|
135
|
+
'implement',
|
|
136
|
+
'fix',
|
|
137
|
+
'add',
|
|
138
|
+
];
|
|
125
139
|
for (const kw of keywords) {
|
|
126
140
|
const index = clean.toLowerCase().indexOf(kw);
|
|
127
141
|
if (index !== -1) {
|
|
@@ -141,7 +155,7 @@ class CognitiveSynthesizer {
|
|
|
141
155
|
return 'Adaptive Exploration';
|
|
142
156
|
}
|
|
143
157
|
calculateAutonomy(pivots, currentLevel) {
|
|
144
|
-
// Logic: frequent pivots without completion decrease autonomy.
|
|
158
|
+
// Logic: frequent pivots without completion decrease autonomy.
|
|
145
159
|
// Consistent execution increases it.
|
|
146
160
|
if (pivots > 5)
|
|
147
161
|
return Math.min(4, currentLevel + 1);
|
|
@@ -8,7 +8,8 @@ class EventHarvester {
|
|
|
8
8
|
constructor(db, config = {}) {
|
|
9
9
|
this.db = db;
|
|
10
10
|
this.config = config;
|
|
11
|
-
this.telemetryTable =
|
|
11
|
+
this.telemetryTable =
|
|
12
|
+
config.telemetryEventsTable || 'agent_telemetry_events';
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Persist a raw telemetry event
|
|
@@ -22,7 +23,7 @@ class EventHarvester {
|
|
|
22
23
|
type,
|
|
23
24
|
content,
|
|
24
25
|
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
25
|
-
created_at: new Date()
|
|
26
|
+
created_at: new Date(),
|
|
26
27
|
})
|
|
27
28
|
.execute();
|
|
28
29
|
}
|
|
@@ -22,7 +22,7 @@ class ResearchAlchemist {
|
|
|
22
22
|
metric_name: metricName,
|
|
23
23
|
value: value,
|
|
24
24
|
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
25
|
-
created_at: new Date()
|
|
25
|
+
created_at: new Date(),
|
|
26
26
|
})
|
|
27
27
|
.execute();
|
|
28
28
|
}
|
|
@@ -34,9 +34,18 @@ class ResearchAlchemist {
|
|
|
34
34
|
* Calculate novelty or Discovery Index
|
|
35
35
|
*/
|
|
36
36
|
async trackDiscovery(sessionId, taskType) {
|
|
37
|
-
//
|
|
38
|
-
const
|
|
39
|
-
|
|
37
|
+
// Production Hardening: Real database-backed novelty check
|
|
38
|
+
const existing = await this.db
|
|
39
|
+
.selectFrom(this.metricsTable)
|
|
40
|
+
.select('id')
|
|
41
|
+
.where('metric_name', '=', 'discovery_index')
|
|
42
|
+
.where('metadata', 'like', `%${taskType}%`)
|
|
43
|
+
.executeTakeFirst();
|
|
44
|
+
const discoveryValue = existing ? 0.1 : 1.0; // 1.0 for first-time discovery, 0.1 for repeat
|
|
45
|
+
await this.transmute(sessionId, 'discovery_index', discoveryValue, {
|
|
46
|
+
taskType,
|
|
47
|
+
firstDiscovery: !existing,
|
|
48
|
+
});
|
|
40
49
|
}
|
|
41
50
|
/**
|
|
42
51
|
* Record a "Magic" moment
|
|
@@ -40,7 +40,7 @@ class CacheManager {
|
|
|
40
40
|
const item = {
|
|
41
41
|
value,
|
|
42
42
|
timestamp: Date.now(),
|
|
43
|
-
ttl: ttl || this.config.ttl || 300000 // 5 minutes default
|
|
43
|
+
ttl: ttl || this.config.ttl || 300000, // 5 minutes default
|
|
44
44
|
};
|
|
45
45
|
// Refresh LRU position if exists
|
|
46
46
|
if (this.cache.has(key)) {
|
|
@@ -76,7 +76,7 @@ class CacheManager {
|
|
|
76
76
|
size: this.cache.size,
|
|
77
77
|
hits: this.hits,
|
|
78
78
|
misses: this.misses,
|
|
79
|
-
hitRate: total > 0 ? this.hits / total : 0
|
|
79
|
+
hitRate: total > 0 ? this.hits / total : 0,
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
@@ -159,13 +159,16 @@ class CacheManager {
|
|
|
159
159
|
* Get all cache values
|
|
160
160
|
*/
|
|
161
161
|
values() {
|
|
162
|
-
return Array.from(this.cache.values()).map(item => item.value);
|
|
162
|
+
return Array.from(this.cache.values()).map((item) => item.value);
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
165
|
* Get all cache entries
|
|
166
166
|
*/
|
|
167
167
|
entries() {
|
|
168
|
-
return Array.from(this.cache.entries()).map(([key, item]) => [
|
|
168
|
+
return Array.from(this.cache.entries()).map(([key, item]) => [
|
|
169
|
+
key,
|
|
170
|
+
item.value,
|
|
171
|
+
]);
|
|
169
172
|
}
|
|
170
173
|
}
|
|
171
174
|
exports.CacheManager = CacheManager;
|
|
@@ -18,11 +18,11 @@ async function analyze(options) {
|
|
|
18
18
|
host: 'localhost',
|
|
19
19
|
port: 0,
|
|
20
20
|
username: '',
|
|
21
|
-
password: ''
|
|
21
|
+
password: '',
|
|
22
22
|
},
|
|
23
23
|
performance: {
|
|
24
|
-
enableQueryOptimization: true
|
|
25
|
-
}
|
|
24
|
+
enableQueryOptimization: true,
|
|
25
|
+
},
|
|
26
26
|
});
|
|
27
27
|
await db.initialize();
|
|
28
28
|
console.log(chalk_1.default.gray(`š Database: ${databasePath}\n`));
|
|
@@ -111,7 +111,8 @@ async function analyze(options) {
|
|
|
111
111
|
console.log(chalk_1.default.gray(` Average query time: ${sqliteMetrics.averageQueryTime.toFixed(2)}ms`));
|
|
112
112
|
console.log(chalk_1.default.gray(` Total queries executed: ${sqliteMetrics.totalQueries}`));
|
|
113
113
|
console.log(chalk_1.default.gray(` Slow queries (>1000ms): ${sqliteMetrics.slowQueries}`));
|
|
114
|
-
if (metrics.warningCount &&
|
|
114
|
+
if (metrics.warningCount &&
|
|
115
|
+
Object.keys(metrics.warningCount).length > 0) {
|
|
115
116
|
console.log(chalk_1.default.yellow('\nā ļø Warnings:'));
|
|
116
117
|
Object.entries(metrics.warningCount).forEach(([type, count]) => {
|
|
117
118
|
console.log(chalk_1.default.gray(` ${type}: ${count}`));
|