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