noormme 1.2.2 → 1.2.4
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/dist/cjs/agentic/ActionJournal.d.ts +6 -6
- package/dist/cjs/agentic/ActionJournal.js +10 -10
- package/dist/cjs/agentic/CapabilityManager.d.ts +5 -5
- package/dist/cjs/agentic/CapabilityManager.js +34 -19
- package/dist/cjs/agentic/Cortex.js +12 -13
- package/dist/cjs/agentic/PersonaManager.d.ts +4 -4
- package/dist/cjs/agentic/PersonaManager.js +18 -10
- package/dist/cjs/agentic/PolicyEnforcer.d.ts +4 -8
- package/dist/cjs/agentic/PolicyEnforcer.js +25 -22
- package/dist/cjs/agentic/improvement/AblationEngine.d.ts +7 -3
- package/dist/cjs/agentic/improvement/AblationEngine.js +51 -24
- package/dist/cjs/agentic/improvement/ActionRefiner.d.ts +1 -1
- package/dist/cjs/agentic/improvement/ActionRefiner.js +25 -15
- package/dist/cjs/agentic/improvement/EvolutionRitual.js +2 -1
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.d.ts +1 -1
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.js +17 -19
- package/dist/cjs/agentic/improvement/GovernanceManager.d.ts +5 -5
- package/dist/cjs/agentic/improvement/GovernanceManager.js +12 -22
- package/dist/cjs/agentic/improvement/HiveLink.d.ts +3 -3
- package/dist/cjs/agentic/improvement/HiveLink.js +15 -157
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.d.ts +15 -29
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.js +66 -349
- package/dist/cjs/agentic/improvement/QuotaManager.d.ts +1 -1
- package/dist/cjs/agentic/improvement/QuotaManager.js +11 -11
- package/dist/cjs/agentic/improvement/RecursiveReasoner.d.ts +4 -4
- package/dist/cjs/agentic/improvement/RecursiveReasoner.js +10 -10
- package/dist/cjs/agentic/improvement/ReflectionEngine.d.ts +2 -2
- package/dist/cjs/agentic/improvement/ReflectionEngine.js +2 -2
- package/dist/cjs/agentic/improvement/RitualOrchestrator.d.ts +3 -3
- package/dist/cjs/agentic/improvement/RitualOrchestrator.js +12 -9
- package/dist/cjs/agentic/improvement/SelfEvolution.d.ts +1 -1
- package/dist/cjs/agentic/improvement/SelfEvolution.js +21 -18
- package/dist/cjs/agentic/improvement/SelfTestRegistry.d.ts +1 -1
- package/dist/cjs/agentic/improvement/SelfTestRegistry.js +31 -19
- package/dist/cjs/agentic/improvement/SovereignMetrics.d.ts +6 -6
- package/dist/cjs/agentic/improvement/SovereignMetrics.js +12 -12
- package/dist/cjs/agentic/improvement/StrategicPlanner.d.ts +10 -54
- package/dist/cjs/agentic/improvement/StrategicPlanner.js +43 -396
- package/dist/cjs/agentic/improvement/distillation/ConflictChallenger.d.ts +3 -0
- package/dist/cjs/agentic/improvement/distillation/ConflictChallenger.js +54 -0
- package/dist/cjs/agentic/improvement/distillation/FactDistiller.d.ts +10 -0
- package/dist/cjs/agentic/improvement/distillation/FactDistiller.js +115 -0
- package/dist/cjs/agentic/improvement/distillation/KnowledgeConsolidator.d.ts +6 -0
- package/dist/cjs/agentic/improvement/distillation/KnowledgeConsolidator.js +63 -0
- package/dist/cjs/agentic/improvement/distillation/RelationshipArchitect.d.ts +6 -0
- package/dist/cjs/agentic/improvement/distillation/RelationshipArchitect.js +73 -0
- package/dist/cjs/agentic/improvement/governance/MaintenanceOracle.js +5 -5
- package/dist/cjs/agentic/improvement/governance/PersonaAuditor.js +41 -29
- package/dist/cjs/agentic/improvement/governance/RemediationEngine.js +8 -3
- package/dist/cjs/agentic/improvement/governance/SkillAuditor.js +17 -9
- package/dist/cjs/agentic/improvement/hive/DomainMaster.d.ts +4 -0
- package/dist/cjs/agentic/improvement/hive/DomainMaster.js +19 -0
- package/dist/cjs/agentic/improvement/hive/KnowledgePromoter.d.ts +6 -0
- package/dist/cjs/agentic/improvement/hive/KnowledgePromoter.js +56 -0
- package/dist/cjs/agentic/improvement/hive/SkillPropagator.d.ts +6 -0
- package/dist/cjs/agentic/improvement/hive/SkillPropagator.js +91 -0
- package/dist/cjs/agentic/improvement/strategy/EvolutionVerificator.d.ts +6 -0
- package/dist/cjs/agentic/improvement/strategy/EvolutionVerificator.js +48 -0
- package/dist/cjs/agentic/improvement/strategy/MutationEngine.d.ts +10 -0
- package/dist/cjs/agentic/improvement/strategy/MutationEngine.js +119 -0
- package/dist/cjs/agentic/improvement/strategy/PerformanceAnalyst.d.ts +6 -0
- package/dist/cjs/agentic/improvement/strategy/PerformanceAnalyst.js +84 -0
- package/dist/cjs/cli/index.js +0 -0
- package/dist/cjs/types/index.d.ts +8 -0
- package/dist/esm/agentic/ActionJournal.d.ts +6 -6
- package/dist/esm/agentic/ActionJournal.js +10 -10
- package/dist/esm/agentic/CapabilityManager.d.ts +5 -5
- package/dist/esm/agentic/CapabilityManager.js +34 -19
- package/dist/esm/agentic/Cortex.js +12 -13
- package/dist/esm/agentic/PersonaManager.d.ts +4 -4
- package/dist/esm/agentic/PersonaManager.js +18 -10
- package/dist/esm/agentic/PolicyEnforcer.d.ts +4 -8
- package/dist/esm/agentic/PolicyEnforcer.js +25 -22
- package/dist/esm/agentic/improvement/AblationEngine.d.ts +7 -3
- package/dist/esm/agentic/improvement/AblationEngine.js +51 -24
- package/dist/esm/agentic/improvement/ActionRefiner.d.ts +1 -1
- package/dist/esm/agentic/improvement/ActionRefiner.js +25 -15
- package/dist/esm/agentic/improvement/EvolutionRitual.js +2 -1
- package/dist/esm/agentic/improvement/EvolutionaryPilot.d.ts +1 -1
- package/dist/esm/agentic/improvement/EvolutionaryPilot.js +17 -19
- package/dist/esm/agentic/improvement/GovernanceManager.d.ts +5 -5
- package/dist/esm/agentic/improvement/GovernanceManager.js +12 -22
- package/dist/esm/agentic/improvement/HiveLink.d.ts +3 -3
- package/dist/esm/agentic/improvement/HiveLink.js +15 -157
- package/dist/esm/agentic/improvement/KnowledgeDistiller.d.ts +15 -29
- package/dist/esm/agentic/improvement/KnowledgeDistiller.js +66 -349
- package/dist/esm/agentic/improvement/QuotaManager.d.ts +1 -1
- package/dist/esm/agentic/improvement/QuotaManager.js +11 -11
- package/dist/esm/agentic/improvement/RecursiveReasoner.d.ts +4 -4
- package/dist/esm/agentic/improvement/RecursiveReasoner.js +10 -10
- package/dist/esm/agentic/improvement/ReflectionEngine.d.ts +2 -2
- package/dist/esm/agentic/improvement/ReflectionEngine.js +2 -2
- package/dist/esm/agentic/improvement/RitualOrchestrator.d.ts +3 -3
- package/dist/esm/agentic/improvement/RitualOrchestrator.js +12 -9
- package/dist/esm/agentic/improvement/SelfEvolution.d.ts +1 -1
- package/dist/esm/agentic/improvement/SelfEvolution.js +21 -18
- package/dist/esm/agentic/improvement/SelfTestRegistry.d.ts +1 -1
- package/dist/esm/agentic/improvement/SelfTestRegistry.js +31 -19
- package/dist/esm/agentic/improvement/SovereignMetrics.d.ts +6 -6
- package/dist/esm/agentic/improvement/SovereignMetrics.js +12 -12
- package/dist/esm/agentic/improvement/StrategicPlanner.d.ts +10 -54
- package/dist/esm/agentic/improvement/StrategicPlanner.js +43 -396
- package/dist/esm/agentic/improvement/distillation/ConflictChallenger.d.ts +3 -0
- package/dist/esm/agentic/improvement/distillation/ConflictChallenger.js +51 -0
- package/dist/esm/agentic/improvement/distillation/FactDistiller.d.ts +10 -0
- package/dist/esm/agentic/improvement/distillation/FactDistiller.js +112 -0
- package/dist/esm/agentic/improvement/distillation/KnowledgeConsolidator.d.ts +6 -0
- package/dist/esm/agentic/improvement/distillation/KnowledgeConsolidator.js +60 -0
- package/dist/esm/agentic/improvement/distillation/RelationshipArchitect.d.ts +6 -0
- package/dist/esm/agentic/improvement/distillation/RelationshipArchitect.js +70 -0
- package/dist/esm/agentic/improvement/governance/MaintenanceOracle.js +5 -5
- package/dist/esm/agentic/improvement/governance/PersonaAuditor.js +41 -29
- package/dist/esm/agentic/improvement/governance/RemediationEngine.js +8 -3
- package/dist/esm/agentic/improvement/governance/SkillAuditor.js +17 -9
- package/dist/esm/agentic/improvement/hive/DomainMaster.d.ts +4 -0
- package/dist/esm/agentic/improvement/hive/DomainMaster.js +16 -0
- package/dist/esm/agentic/improvement/hive/KnowledgePromoter.d.ts +6 -0
- package/dist/esm/agentic/improvement/hive/KnowledgePromoter.js +53 -0
- package/dist/esm/agentic/improvement/hive/SkillPropagator.d.ts +6 -0
- package/dist/esm/agentic/improvement/hive/SkillPropagator.js +88 -0
- package/dist/esm/agentic/improvement/strategy/EvolutionVerificator.d.ts +6 -0
- package/dist/esm/agentic/improvement/strategy/EvolutionVerificator.js +45 -0
- package/dist/esm/agentic/improvement/strategy/MutationEngine.d.ts +10 -0
- package/dist/esm/agentic/improvement/strategy/MutationEngine.js +116 -0
- package/dist/esm/agentic/improvement/strategy/PerformanceAnalyst.d.ts +6 -0
- package/dist/esm/agentic/improvement/strategy/PerformanceAnalyst.js +81 -0
- package/dist/esm/types/index.d.ts +8 -0
- package/package.json +40 -44
|
@@ -23,16 +23,27 @@ class AblationEngine {
|
|
|
23
23
|
get typedDb() {
|
|
24
24
|
return this.db;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Helper to apply forUpdate only where supported (Skip for SQLite)
|
|
28
|
+
*/
|
|
29
|
+
withLock(query, trx) {
|
|
30
|
+
const executor = trx.getExecutor();
|
|
31
|
+
const adapterName = executor?.adapter?.constructor?.name || executor?.dialect?.constructor?.name || '';
|
|
32
|
+
if (adapterName.toLowerCase().includes('sqlite')) {
|
|
33
|
+
return query;
|
|
34
|
+
}
|
|
35
|
+
return query.forUpdate();
|
|
36
|
+
}
|
|
26
37
|
/**
|
|
27
38
|
* Identify "Zombies": Items that have never been retrieved/hit and are old.
|
|
28
39
|
*/
|
|
29
|
-
async pruneZombies(thresholdDays = 30) {
|
|
40
|
+
async pruneZombies(thresholdDays = 30, trxOrDb = this.db) {
|
|
30
41
|
const cutoff = new Date(Date.now() - thresholdDays * 24 * 3600000);
|
|
31
42
|
let totalPruned = 0;
|
|
32
|
-
|
|
43
|
+
const runner = async (trx) => {
|
|
33
44
|
// 1. Prune Knowledge (with dependency check and pagination)
|
|
34
45
|
// Audit Phase 9: Paginated selection to prevent OOM
|
|
35
|
-
const
|
|
46
|
+
const query = trx
|
|
36
47
|
.selectFrom(this.knowledgeTable)
|
|
37
48
|
.selectAll()
|
|
38
49
|
.where((eb) => eb.or([
|
|
@@ -43,9 +54,8 @@ class AblationEngine {
|
|
|
43
54
|
.where('updated_at', '<', cutoff)
|
|
44
55
|
.where('id', 'not in', (eb) => eb.selectFrom(this.linksTable).select('source_id'))
|
|
45
56
|
.where('id', 'not in', (eb) => eb.selectFrom(this.linksTable).select('target_id'))
|
|
46
|
-
.limit(500) // Audit Phase 9: Batch limit
|
|
47
|
-
|
|
48
|
-
.execute();
|
|
57
|
+
.limit(500); // Audit Phase 9: Batch limit
|
|
58
|
+
const knowledgeToPrune = await this.withLock(query, trx).execute();
|
|
49
59
|
if (knowledgeToPrune.length > 0) {
|
|
50
60
|
const candidates = knowledgeToPrune.map((k) => this.cortex.knowledge['parseKnowledge'](k));
|
|
51
61
|
const idsToDelete = [];
|
|
@@ -80,16 +90,22 @@ class AblationEngine {
|
|
|
80
90
|
console.log(`[AblationEngine] Pruned ${totalPruned} zombie items older than ${thresholdDays} days.`);
|
|
81
91
|
}
|
|
82
92
|
return totalPruned;
|
|
83
|
-
}
|
|
93
|
+
};
|
|
94
|
+
if (trxOrDb && trxOrDb !== this.db) {
|
|
95
|
+
return await runner(trxOrDb);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return await this.db.transaction().execute(runner);
|
|
99
|
+
}
|
|
84
100
|
}
|
|
85
101
|
/**
|
|
86
102
|
* Monitor Performance and perform Intelligent Rollbacks.
|
|
87
103
|
* Prioritizes recovery of items with highest historical hit counts.
|
|
88
104
|
*/
|
|
89
|
-
async monitorAblationPerformance() {
|
|
90
|
-
|
|
91
|
-
const baseline = await this.cortex.metrics.getAverageMetric('success_rate');
|
|
92
|
-
const stats = await this.cortex.metrics.getMetricStats('success_rate');
|
|
105
|
+
async monitorAblationPerformance(trxOrDb = this.db) {
|
|
106
|
+
const runner = async (trx) => {
|
|
107
|
+
const baseline = await this.cortex.metrics.getAverageMetric('success_rate', trx);
|
|
108
|
+
const stats = await this.cortex.metrics.getMetricStats('success_rate', {}, trx);
|
|
93
109
|
// If current average is significantly lower than overall average
|
|
94
110
|
if (stats.count > 10 && stats.avg < baseline * 0.8) {
|
|
95
111
|
console.warn(`[AblationEngine] PERFORMANCE DEGRADATION DETECTED (Avg: ${stats.avg}, Baseline: ${baseline}). Triggering targeted recovery.`);
|
|
@@ -117,20 +133,25 @@ class AblationEngine {
|
|
|
117
133
|
return { status: 'degraded', recoveredCount };
|
|
118
134
|
}
|
|
119
135
|
return { status: 'stable', recoveredCount: 0 };
|
|
120
|
-
}
|
|
136
|
+
};
|
|
137
|
+
if (trxOrDb && trxOrDb !== this.db) {
|
|
138
|
+
return await runner(trxOrDb);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return await this.db.transaction().execute(runner);
|
|
142
|
+
}
|
|
121
143
|
}
|
|
122
144
|
/**
|
|
123
145
|
* Conduct an "Ablation Test": Temporarily disable a knowledge item.
|
|
124
146
|
*/
|
|
125
|
-
async testAblation(id) {
|
|
147
|
+
async testAblation(id, trxOrDb = this.db) {
|
|
126
148
|
console.log(`[AblationEngine] Conducting ablation test on item ${id}`);
|
|
127
|
-
|
|
128
|
-
const
|
|
149
|
+
const runner = async (trx) => {
|
|
150
|
+
const query = trx
|
|
129
151
|
.selectFrom(this.knowledgeTable)
|
|
130
152
|
.selectAll()
|
|
131
|
-
.where('id', '=', id)
|
|
132
|
-
|
|
133
|
-
.executeTakeFirst());
|
|
153
|
+
.where('id', '=', id);
|
|
154
|
+
const item = (await this.withLock(query, trx).executeTakeFirst());
|
|
134
155
|
if (!item)
|
|
135
156
|
return false;
|
|
136
157
|
const metadata = typeof item.metadata === 'string'
|
|
@@ -140,7 +161,7 @@ class AblationEngine {
|
|
|
140
161
|
`Temporary confidence reduction to evaluate reasoning impact.`,
|
|
141
162
|
`Original confidence: ${item.confidence}`,
|
|
142
163
|
`Historical hits: ${metadata.hit_count || 0}`
|
|
143
|
-
]);
|
|
164
|
+
], undefined, trx);
|
|
144
165
|
await trx
|
|
145
166
|
.updateTable(this.knowledgeTable)
|
|
146
167
|
.set({
|
|
@@ -155,19 +176,25 @@ class AblationEngine {
|
|
|
155
176
|
.where('id', '=', id)
|
|
156
177
|
.execute();
|
|
157
178
|
return true;
|
|
158
|
-
}
|
|
179
|
+
};
|
|
180
|
+
if (trxOrDb && trxOrDb !== this.db) {
|
|
181
|
+
await runner(trxOrDb);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
await this.db.transaction().execute(runner);
|
|
185
|
+
}
|
|
186
|
+
return true;
|
|
159
187
|
}
|
|
160
188
|
/**
|
|
161
189
|
* Restore an ablated knowledge item to its original state.
|
|
162
190
|
*/
|
|
163
191
|
async recoverAblatedItem(id, trx) {
|
|
164
192
|
const recoveryStep = async (t) => {
|
|
165
|
-
const
|
|
193
|
+
const query = t
|
|
166
194
|
.selectFrom(this.knowledgeTable)
|
|
167
195
|
.selectAll()
|
|
168
|
-
.where('id', '=', id)
|
|
169
|
-
|
|
170
|
-
.executeTakeFirst());
|
|
196
|
+
.where('id', '=', id);
|
|
197
|
+
const item = (await this.withLock(query, t).executeTakeFirst());
|
|
171
198
|
if (!item)
|
|
172
199
|
return false;
|
|
173
200
|
const metadata = typeof item.metadata === 'string'
|
|
@@ -14,7 +14,7 @@ export declare class ActionRefiner {
|
|
|
14
14
|
/**
|
|
15
15
|
* Analyze recent actions and propose improvements
|
|
16
16
|
*/
|
|
17
|
-
refineActions(): Promise<string[]>;
|
|
17
|
+
refineActions(trxOrDb?: any): Promise<string[]>;
|
|
18
18
|
/**
|
|
19
19
|
* Propose a rule to reflect on a specific tool usage
|
|
20
20
|
*/
|
|
@@ -19,12 +19,12 @@ class ActionRefiner {
|
|
|
19
19
|
/**
|
|
20
20
|
* Analyze recent actions and propose improvements
|
|
21
21
|
*/
|
|
22
|
-
async refineActions() {
|
|
22
|
+
async refineActions(trxOrDb = this.db) {
|
|
23
23
|
const recommendations = [];
|
|
24
24
|
// 1. Find tools with high failure rates (Last 24h Window)
|
|
25
25
|
// Audit Phase 14: Sliding window to prevent global table scans
|
|
26
26
|
const windowStart = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
|
27
|
-
const failureStats = (await
|
|
27
|
+
const failureStats = (await trxOrDb
|
|
28
28
|
.selectFrom(this.actionsTable)
|
|
29
29
|
.select('tool_name')
|
|
30
30
|
.select((eb) => eb.fn.count('id').as('total'))
|
|
@@ -43,11 +43,11 @@ class ActionRefiner {
|
|
|
43
43
|
if (rate > failureRateThreshold && total > minActionBatch) {
|
|
44
44
|
recommendations.push(`Tool '${stat.tool_name}' has a ${Math.round(rate * 100)}% failure rate. Suggesting automatic reflection rule.`);
|
|
45
45
|
// Automatically propose a rule to reflect on this tool's usage
|
|
46
|
-
await this.proposeReflectionRule(stat.tool_name);
|
|
46
|
+
await this.proposeReflectionRule(stat.tool_name, trxOrDb);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
// 2. Discover missing capabilities based on error patterns (Last 24h)
|
|
50
|
-
const missingCapabilities = (await
|
|
50
|
+
const missingCapabilities = (await trxOrDb
|
|
51
51
|
.selectFrom(this.actionsTable)
|
|
52
52
|
.select('tool_name')
|
|
53
53
|
.where('status', '=', 'failure')
|
|
@@ -62,25 +62,29 @@ class ActionRefiner {
|
|
|
62
62
|
.execute());
|
|
63
63
|
for (const row of missingCapabilities) {
|
|
64
64
|
recommendations.push(`Detected repeated access/existence failures for tool '${row.tool_name}'. Proposing capability expansion.`);
|
|
65
|
-
await this.proposeCapabilityUpdate(row.tool_name);
|
|
65
|
+
await this.proposeCapabilityUpdate(row.tool_name, trxOrDb);
|
|
66
66
|
}
|
|
67
67
|
return recommendations;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* Propose a rule to reflect on a specific tool usage
|
|
71
71
|
*/
|
|
72
|
-
async proposeReflectionRule(toolName) {
|
|
72
|
+
async proposeReflectionRule(toolName, trxOrDb = this.db) {
|
|
73
73
|
// Audit Phase 19: Atomic rule proposal via transaction + existence check
|
|
74
|
-
|
|
74
|
+
const runner = async (trx) => {
|
|
75
75
|
const rulesTable = this.cortex.config.rulesTable || 'agent_rules';
|
|
76
|
-
|
|
76
|
+
let query = trx
|
|
77
77
|
.selectFrom(rulesTable)
|
|
78
78
|
.select('id')
|
|
79
|
-
.where('
|
|
79
|
+
.where('table_name', '=', 'agent_actions')
|
|
80
80
|
.where('operation', '=', 'insert')
|
|
81
|
-
.where('metadata', 'like', `%\"targetTool\":\"${toolName}\"%`)
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
.where('metadata', 'like', `%\"targetTool\":\"${toolName}\"%`);
|
|
82
|
+
const executor = trx.getExecutor();
|
|
83
|
+
const adapterName = executor?.adapter?.constructor?.name || executor?.dialect?.constructor?.name || '';
|
|
84
|
+
if (!adapterName.toLowerCase().includes('sqlite')) {
|
|
85
|
+
query = query.forUpdate();
|
|
86
|
+
}
|
|
87
|
+
const existing = await query.executeTakeFirst();
|
|
84
88
|
if (!existing) {
|
|
85
89
|
console.log(`[ActionRefiner] Proposing reflection rule for tool: ${toolName}`);
|
|
86
90
|
await this.cortex.rules.defineRule('agent_actions', 'insert', 'audit', {
|
|
@@ -90,17 +94,23 @@ class ActionRefiner {
|
|
|
90
94
|
},
|
|
91
95
|
}, trx); // Pass transaction object
|
|
92
96
|
}
|
|
93
|
-
}
|
|
97
|
+
};
|
|
98
|
+
if (trxOrDb && trxOrDb !== this.db) {
|
|
99
|
+
await runner(trxOrDb);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
await this.db.transaction().execute((trx) => runner(trx));
|
|
103
|
+
}
|
|
94
104
|
}
|
|
95
105
|
/**
|
|
96
106
|
* Propose an update to capabilities
|
|
97
107
|
*/
|
|
98
|
-
async proposeCapabilityUpdate(toolName) {
|
|
108
|
+
async proposeCapabilityUpdate(toolName, trxOrDb = this.db) {
|
|
99
109
|
console.log(`[ActionRefiner] Proposing capability expansion for tool: ${toolName}`);
|
|
100
110
|
await this.cortex.reflections.reflect('system', 'failure', `Architectural Gap: Missing Capability for '${toolName}'`, [
|
|
101
111
|
`Identified repeated failures using tool '${toolName}'.`,
|
|
102
112
|
`Resolution: Inspect permission sets and ensure the tool is correctly registered in the CapabilityManager.`,
|
|
103
|
-
]);
|
|
113
|
+
], undefined, trxOrDb);
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
116
|
exports.ActionRefiner = ActionRefiner;
|
|
@@ -64,7 +64,8 @@ class EvolutionRitual {
|
|
|
64
64
|
// Find domains that are currently "hot" (high density of recent knowledge)
|
|
65
65
|
// Refactored Phase 13: Paginated scanning to handle large knowledge bursts
|
|
66
66
|
const domainScores = new Map();
|
|
67
|
-
const
|
|
67
|
+
const lookbackHours = this.config.evolutionLookbackHours || 24;
|
|
68
|
+
const cutoff = new Date(Date.now() - lookbackHours * 60 * 60 * 1000);
|
|
68
69
|
let offset = 0;
|
|
69
70
|
const limit = 1000;
|
|
70
71
|
while (true) {
|
|
@@ -18,7 +18,7 @@ class EvolutionaryPilot {
|
|
|
18
18
|
/**
|
|
19
19
|
* Run a self-improvement cycle based on dynamic baselining
|
|
20
20
|
*/
|
|
21
|
-
async runSelfImprovementCycle() {
|
|
21
|
+
async runSelfImprovementCycle(trxOrDb = this.db) {
|
|
22
22
|
console.log('[EvolutionaryPilot] Initiating self-improvement cycle with full-spectrum baselining...');
|
|
23
23
|
const changes = [];
|
|
24
24
|
let evolved = false;
|
|
@@ -30,7 +30,7 @@ class EvolutionaryPilot {
|
|
|
30
30
|
'trust_signal',
|
|
31
31
|
];
|
|
32
32
|
const samplingCount = this.config.evolution?.samplingCount || 100;
|
|
33
|
-
const recentMetrics = await this.cortex.metrics.getRecentMetrics(samplingCount);
|
|
33
|
+
const recentMetrics = await this.cortex.metrics.getRecentMetrics(samplingCount, trxOrDb);
|
|
34
34
|
for (const metricName of metrics) {
|
|
35
35
|
// Audit Phase 17: Bounded metric slice for scale-safe baselining
|
|
36
36
|
const values = recentMetrics
|
|
@@ -43,14 +43,14 @@ class EvolutionaryPilot {
|
|
|
43
43
|
const minSamples = this.config.evolution?.minSamples || 5;
|
|
44
44
|
if (values.length < minSamples)
|
|
45
45
|
continue;
|
|
46
|
-
const policies = await this.cortex.policies.getActivePolicies();
|
|
46
|
+
const policies = await this.cortex.policies.getActivePolicies(trxOrDb);
|
|
47
47
|
const latencyZ = policies.find(p => p.name === 'latency_drift_z')?.definition?.threshold || 2.0;
|
|
48
48
|
const latencyMean = policies.find(p => p.name === 'latency_mean_ceiling')?.definition?.threshold || 1000;
|
|
49
49
|
console.log(`[EvolutionaryPilot] Baselining ${metricName}: Mean=${stats.mean.toFixed(2)}, StdDev=${stats.stdDev.toFixed(2)}, Current=${stats.current.toFixed(2)}, Z-Score=${stats.zScore.toFixed(2)}`);
|
|
50
50
|
// 2. Trigger Evolution based on metric-specific thresholds
|
|
51
51
|
if (metricName === 'query_latency' &&
|
|
52
52
|
(stats.zScore > latencyZ || stats.mean > latencyMean)) {
|
|
53
|
-
const result = await this.optimizeLatency();
|
|
53
|
+
const result = await this.optimizeLatency(trxOrDb);
|
|
54
54
|
if (result) {
|
|
55
55
|
changes.push(...result);
|
|
56
56
|
evolved = true;
|
|
@@ -61,7 +61,7 @@ class EvolutionaryPilot {
|
|
|
61
61
|
if (metricName === 'success_rate' &&
|
|
62
62
|
(stats.zScore < successZ || stats.mean < successMean)) {
|
|
63
63
|
console.warn(`[EvolutionaryPilot] Success rate collapse detected (${stats.mean.toFixed(2)}). Triggering strategic mutation.`);
|
|
64
|
-
const strategies = await this.cortex.strategy.mutateStrategy();
|
|
64
|
+
const strategies = await this.cortex.strategy.mutateStrategy(trxOrDb);
|
|
65
65
|
changes.push(...strategies);
|
|
66
66
|
evolved = true;
|
|
67
67
|
}
|
|
@@ -74,13 +74,13 @@ class EvolutionaryPilot {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
// 3. Meta-Meta Evolution Tuning
|
|
77
|
-
const tuned = await this.tuneEmergentSkillHyperparameters(recentMetrics);
|
|
77
|
+
const tuned = await this.tuneEmergentSkillHyperparameters(recentMetrics, trxOrDb);
|
|
78
78
|
if (tuned) {
|
|
79
79
|
changes.push('Self-tuned emergent skill hyperparameters (Meta-Meta Evolution)');
|
|
80
80
|
evolved = true;
|
|
81
81
|
}
|
|
82
82
|
// 4. Verify: Perform an audit
|
|
83
|
-
const audit = await this.cortex.governor.performAudit();
|
|
83
|
+
const audit = await this.cortex.governor.performAudit(trxOrDb);
|
|
84
84
|
if (!audit.healthy) {
|
|
85
85
|
console.warn('[EvolutionaryPilot] Evolution resulted in unhealthy state. Reverting may be required.');
|
|
86
86
|
changes.push('WARNING: Unhealthy state detected after evolution');
|
|
@@ -91,11 +91,11 @@ class EvolutionaryPilot {
|
|
|
91
91
|
* Meta-Meta Evolution: Adjusts the hyperparameters of the SkillSynthesizer
|
|
92
92
|
* based on the systemic success or failure of recently verified skills.
|
|
93
93
|
*/
|
|
94
|
-
async tuneEmergentSkillHyperparameters(recentMetrics) {
|
|
94
|
+
async tuneEmergentSkillHyperparameters(recentMetrics, trxOrDb = this.db) {
|
|
95
95
|
console.log(`[EvolutionaryPilot] Running Meta-Meta Evolution tuning...`);
|
|
96
96
|
// Count how many skills are currently blacklisted vs verified
|
|
97
|
-
const blacklisted = await this.cortex.capabilities.getCapabilities('blacklisted');
|
|
98
|
-
const verified = await this.cortex.capabilities.getCapabilities('verified');
|
|
97
|
+
const blacklisted = await this.cortex.capabilities.getCapabilities('blacklisted', trxOrDb);
|
|
98
|
+
const verified = await this.cortex.capabilities.getCapabilities('verified', trxOrDb);
|
|
99
99
|
let tuned = false;
|
|
100
100
|
const config = this.config.evolution;
|
|
101
101
|
if (!config)
|
|
@@ -152,21 +152,19 @@ class EvolutionaryPilot {
|
|
|
152
152
|
const zScore = stdDev === 0 ? 0 : (current - mean) / stdDev;
|
|
153
153
|
return { mean, stdDev, current, zScore };
|
|
154
154
|
}
|
|
155
|
-
async optimizeLatency() {
|
|
155
|
+
async optimizeLatency(trxOrDb = this.db) {
|
|
156
156
|
const changes = [];
|
|
157
157
|
console.log(`[EvolutionaryPilot] Triggering latency optimization...`);
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
.adapter.constructor.name.toLowerCase()
|
|
162
|
-
.includes('sqlite') ||
|
|
163
|
-
(dialect && dialect.constructor.name.toLowerCase().includes('sqlite'));
|
|
158
|
+
const executor = trxOrDb.getExecutor();
|
|
159
|
+
const adapterName = executor?.adapter?.constructor?.name || executor?.dialect?.constructor?.name || '';
|
|
160
|
+
const isSqlite = adapterName.toLowerCase().includes('sqlite');
|
|
164
161
|
if (isSqlite) {
|
|
165
|
-
await (0, sql_js_1.sql) `PRAGMA optimize`.execute(
|
|
162
|
+
await (0, sql_js_1.sql) `PRAGMA optimize`.execute(trxOrDb);
|
|
166
163
|
changes.push('Applied PRAGMA optimize');
|
|
167
164
|
}
|
|
168
165
|
const messagesTable = this.config.messagesTable || 'agent_messages';
|
|
169
|
-
|
|
166
|
+
// NOTE: cortex.evolution.evolve should be transaction-aware
|
|
167
|
+
await this.cortex.evolution.evolve(`CREATE INDEX IF NOT EXISTS idx_agent_msg_session_time ON ${messagesTable}(session_id, created_at)`, {}, trxOrDb);
|
|
170
168
|
changes.push(`Applied composite index to ${messagesTable}`);
|
|
171
169
|
return changes;
|
|
172
170
|
}
|
|
@@ -26,24 +26,24 @@ export declare class GovernanceManager {
|
|
|
26
26
|
/**
|
|
27
27
|
* Perform a "Panic Check" - looking for critical failures or cost overruns
|
|
28
28
|
*/
|
|
29
|
-
performAudit(): Promise<{
|
|
29
|
+
performAudit(trxOrDb?: any): Promise<{
|
|
30
30
|
healthy: boolean;
|
|
31
31
|
issues: string[];
|
|
32
32
|
}>;
|
|
33
33
|
/**
|
|
34
34
|
* Suggest architectural repairs if performance is degrading
|
|
35
35
|
*/
|
|
36
|
-
suggestRepairs(): Promise<string[]>;
|
|
36
|
+
suggestRepairs(trxOrDb?: any): Promise<string[]>;
|
|
37
37
|
/**
|
|
38
38
|
* Quarantine a persona that is behaving outside safety parameters.
|
|
39
39
|
*/
|
|
40
|
-
quarantinePersona(id: string | number, reason: string): Promise<void>;
|
|
40
|
+
quarantinePersona(id: string | number, reason: string, trxOrDb?: any): Promise<void>;
|
|
41
41
|
/**
|
|
42
42
|
* Blacklist a skill that is causing systemic issues.
|
|
43
43
|
*/
|
|
44
|
-
quarantineSkill(name: string, reason: string): Promise<void>;
|
|
44
|
+
quarantineSkill(name: string, reason: string, trxOrDb?: any): Promise<void>;
|
|
45
45
|
/**
|
|
46
46
|
* Monitor cross-node behaviors and flag sudden spikes or malicious patterns.
|
|
47
47
|
*/
|
|
48
|
-
validateEmergentBehavior(
|
|
48
|
+
validateEmergentBehavior(trxOrDb?: any): Promise<string[]>;
|
|
49
49
|
}
|
|
@@ -48,13 +48,13 @@ class GovernanceManager {
|
|
|
48
48
|
/**
|
|
49
49
|
* Perform a "Panic Check" - looking for critical failures or cost overruns
|
|
50
50
|
*/
|
|
51
|
-
async performAudit() {
|
|
51
|
+
async performAudit(trxOrDb = this.db) {
|
|
52
52
|
const issuesList = [];
|
|
53
53
|
let auditMetadata = {};
|
|
54
54
|
// Execute core audit gathering phase
|
|
55
55
|
const ctx = {
|
|
56
56
|
db: this.db,
|
|
57
|
-
trx:
|
|
57
|
+
trx: trxOrDb,
|
|
58
58
|
cortex: this.cortex,
|
|
59
59
|
config: this.config,
|
|
60
60
|
metricsTable: this.metricsTable,
|
|
@@ -92,21 +92,11 @@ class GovernanceManager {
|
|
|
92
92
|
// Phase 1: Emergency Rollbacks
|
|
93
93
|
if (activePersona && (success < 0.4 || hCost > hourlyLimit * 1.5)) {
|
|
94
94
|
console.error(`[GovernanceManager] CRITICAL THRESHOLD BREACH. Initiating emergency containment for persona ${activePersona.id}`);
|
|
95
|
-
await this.personaAuditor.quarantinePersona(
|
|
95
|
+
await this.personaAuditor.quarantinePersona(ctx, activePersona.id, 'Critical threshold breach');
|
|
96
96
|
issuesList.push(`Containment: Emergency rollback triggered for persona ${activePersona.id}`);
|
|
97
97
|
}
|
|
98
|
-
await this.cortex.reflections.reflect(
|
|
98
|
+
await this.cortex.reflections.reflect('system', 'failure', 'Governance Compliance Audit', issuesList, undefined, trxOrDb);
|
|
99
99
|
// Phase 3: Remediation Rituals
|
|
100
|
-
const ctx = {
|
|
101
|
-
db: this.db,
|
|
102
|
-
trx: this.db, // Standalone remediation
|
|
103
|
-
cortex: this.cortex,
|
|
104
|
-
config: this.config,
|
|
105
|
-
metricsTable: this.metricsTable,
|
|
106
|
-
policiesTable: this.policiesTable,
|
|
107
|
-
personasTable: this.personasTable,
|
|
108
|
-
skillsTable: this.skillsTable
|
|
109
|
-
};
|
|
110
100
|
await this.remediationEngine.triggerRemediation(ctx, issuesList);
|
|
111
101
|
}
|
|
112
102
|
return {
|
|
@@ -117,10 +107,10 @@ class GovernanceManager {
|
|
|
117
107
|
/**
|
|
118
108
|
* Suggest architectural repairs if performance is degrading
|
|
119
109
|
*/
|
|
120
|
-
async suggestRepairs() {
|
|
110
|
+
async suggestRepairs(trxOrDb = this.db) {
|
|
121
111
|
const ctx = {
|
|
122
112
|
db: this.db,
|
|
123
|
-
trx:
|
|
113
|
+
trx: trxOrDb,
|
|
124
114
|
cortex: this.cortex,
|
|
125
115
|
config: this.config,
|
|
126
116
|
metricsTable: this.metricsTable,
|
|
@@ -133,10 +123,10 @@ class GovernanceManager {
|
|
|
133
123
|
/**
|
|
134
124
|
* Quarantine a persona that is behaving outside safety parameters.
|
|
135
125
|
*/
|
|
136
|
-
async quarantinePersona(id, reason) {
|
|
126
|
+
async quarantinePersona(id, reason, trxOrDb = this.db) {
|
|
137
127
|
const ctx = {
|
|
138
128
|
db: this.db,
|
|
139
|
-
trx:
|
|
129
|
+
trx: trxOrDb,
|
|
140
130
|
cortex: this.cortex,
|
|
141
131
|
config: this.config,
|
|
142
132
|
metricsTable: this.metricsTable,
|
|
@@ -149,10 +139,10 @@ class GovernanceManager {
|
|
|
149
139
|
/**
|
|
150
140
|
* Blacklist a skill that is causing systemic issues.
|
|
151
141
|
*/
|
|
152
|
-
async quarantineSkill(name, reason) {
|
|
142
|
+
async quarantineSkill(name, reason, trxOrDb = this.db) {
|
|
153
143
|
const ctx = {
|
|
154
144
|
db: this.db,
|
|
155
|
-
trx:
|
|
145
|
+
trx: trxOrDb,
|
|
156
146
|
cortex: this.cortex,
|
|
157
147
|
config: this.config,
|
|
158
148
|
metricsTable: this.metricsTable,
|
|
@@ -165,10 +155,10 @@ class GovernanceManager {
|
|
|
165
155
|
/**
|
|
166
156
|
* Monitor cross-node behaviors and flag sudden spikes or malicious patterns.
|
|
167
157
|
*/
|
|
168
|
-
async validateEmergentBehavior(
|
|
158
|
+
async validateEmergentBehavior(trxOrDb = this.db) {
|
|
169
159
|
const ctx = {
|
|
170
160
|
db: this.db,
|
|
171
|
-
trx:
|
|
161
|
+
trx: trxOrDb,
|
|
172
162
|
cortex: this.cortex,
|
|
173
163
|
config: this.config,
|
|
174
164
|
metricsTable: this.metricsTable,
|
|
@@ -10,11 +10,13 @@ export declare class HiveLink {
|
|
|
10
10
|
private cortex;
|
|
11
11
|
private config;
|
|
12
12
|
private knowledgeTable;
|
|
13
|
+
private promoter;
|
|
14
|
+
private propagator;
|
|
15
|
+
private domainMaster;
|
|
13
16
|
constructor(db: Kysely<any>, cortex: Cortex, config?: AgenticConfig);
|
|
14
17
|
private get typedDb();
|
|
15
18
|
/**
|
|
16
19
|
* Promote high-confidence local knowledge to global "Hive" knowledge.
|
|
17
|
-
* This creates a new, session-agnostic entry or updates an existing global one.
|
|
18
20
|
*/
|
|
19
21
|
broadcastKnowledge(options?: {
|
|
20
22
|
minConfidence?: number;
|
|
@@ -23,12 +25,10 @@ export declare class HiveLink {
|
|
|
23
25
|
}): Promise<number>;
|
|
24
26
|
/**
|
|
25
27
|
* Strengthen knowledge related to a specific domain (tag).
|
|
26
|
-
* Increases confidence of all items with this tag, representing "domain mastery".
|
|
27
28
|
*/
|
|
28
29
|
syncDomain(domainTag: string, boostFactor?: number): Promise<number>;
|
|
29
30
|
/**
|
|
30
31
|
* Propagate high-performing capabilities globally using the "Sovereign Draft" protocol.
|
|
31
|
-
* Uses Bayesian Convergence and Shadow Promotion to avoid deadlocks.
|
|
32
32
|
*/
|
|
33
33
|
broadcastSkills(): Promise<number>;
|
|
34
34
|
/**
|