noormme 1.2.3 → 1.2.5
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 +35 -24
- package/dist/cjs/agentic/Cortex.js +12 -13
- package/dist/cjs/agentic/EpisodicMemory.js +4 -3
- package/dist/cjs/agentic/PersonaManager.d.ts +4 -4
- package/dist/cjs/agentic/PersonaManager.js +19 -15
- package/dist/cjs/agentic/PolicyEnforcer.d.ts +4 -8
- package/dist/cjs/agentic/PolicyEnforcer.js +26 -26
- package/dist/cjs/agentic/ResourceMonitor.js +2 -1
- package/dist/cjs/agentic/SessionManager.js +7 -6
- package/dist/cjs/agentic/improvement/AblationEngine.d.ts +3 -3
- package/dist/cjs/agentic/improvement/AblationEngine.js +41 -24
- package/dist/cjs/agentic/improvement/ActionRefiner.d.ts +1 -1
- package/dist/cjs/agentic/improvement/ActionRefiner.js +21 -15
- package/dist/cjs/agentic/improvement/ConflictResolver.js +4 -3
- 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/GoalArchitect.js +10 -9
- 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 +69 -351
- 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 +27 -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 +7 -11
- package/dist/cjs/agentic/improvement/governance/RemediationEngine.js +8 -3
- 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 +57 -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/agentic/util/db-utils.d.ts +4 -0
- package/dist/cjs/agentic/util/db-utils.js +27 -0
- package/dist/cjs/cli/index.js +0 -0
- package/dist/cjs/helpers/agent-schema.js +1 -0
- package/dist/cjs/testing/test-utils.js +2 -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 +35 -24
- package/dist/esm/agentic/Cortex.js +12 -13
- package/dist/esm/agentic/EpisodicMemory.js +4 -3
- package/dist/esm/agentic/PersonaManager.d.ts +4 -4
- package/dist/esm/agentic/PersonaManager.js +19 -15
- package/dist/esm/agentic/PolicyEnforcer.d.ts +4 -8
- package/dist/esm/agentic/PolicyEnforcer.js +26 -26
- package/dist/esm/agentic/ResourceMonitor.js +2 -1
- package/dist/esm/agentic/SessionManager.js +7 -6
- package/dist/esm/agentic/improvement/AblationEngine.d.ts +3 -3
- package/dist/esm/agentic/improvement/AblationEngine.js +41 -24
- package/dist/esm/agentic/improvement/ActionRefiner.d.ts +1 -1
- package/dist/esm/agentic/improvement/ActionRefiner.js +21 -15
- package/dist/esm/agentic/improvement/ConflictResolver.js +4 -3
- 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/GoalArchitect.js +10 -9
- 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 +69 -351
- 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 +27 -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 +7 -11
- package/dist/esm/agentic/improvement/governance/RemediationEngine.js +8 -3
- 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 +54 -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/agentic/util/db-utils.d.ts +4 -0
- package/dist/esm/agentic/util/db-utils.js +25 -0
- package/dist/esm/helpers/agent-schema.js +1 -0
- package/dist/esm/testing/test-utils.js +2 -0
- package/dist/esm/types/index.d.ts +8 -0
- package/package.json +40 -44
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FactDistiller = void 0;
|
|
4
|
+
class FactDistiller {
|
|
5
|
+
/**
|
|
6
|
+
* typedDb helper (internal use)
|
|
7
|
+
*/
|
|
8
|
+
getTypedDb(db) {
|
|
9
|
+
return db;
|
|
10
|
+
}
|
|
11
|
+
async distillExact(trx, knowledgeTable, entity, fact, confidence, sourceSessionId, tags = [], metadata = {}, source = 'assistant') {
|
|
12
|
+
// Check for exact match
|
|
13
|
+
const existing = await trx
|
|
14
|
+
.selectFrom(knowledgeTable)
|
|
15
|
+
.selectAll()
|
|
16
|
+
.where('entity', '=', entity)
|
|
17
|
+
.where('fact', '=', fact)
|
|
18
|
+
.executeTakeFirst();
|
|
19
|
+
if (existing) {
|
|
20
|
+
// Merge tags
|
|
21
|
+
const existingTags = existing.tags ? JSON.parse(existing.tags) : [];
|
|
22
|
+
const mergedTags = Array.from(new Set([...existingTags, ...tags]));
|
|
23
|
+
// Merge metadata
|
|
24
|
+
const existingMeta = existing.metadata ? JSON.parse(existing.metadata) : {};
|
|
25
|
+
const sessions = new Set(existingMeta.sessions || []);
|
|
26
|
+
if (sourceSessionId)
|
|
27
|
+
sessions.add(sourceSessionId);
|
|
28
|
+
const mergedMeta = {
|
|
29
|
+
...existingMeta,
|
|
30
|
+
...metadata,
|
|
31
|
+
sessions: Array.from(sessions),
|
|
32
|
+
session_count: sessions.size,
|
|
33
|
+
};
|
|
34
|
+
// Source weighting
|
|
35
|
+
const boost = source === 'user' ? 0.2 : 0.05;
|
|
36
|
+
const finalConfidence = Math.min(1.0, existing.confidence + boost);
|
|
37
|
+
// Status Lifecycle
|
|
38
|
+
let finalStatus = existing.status || 'proposed';
|
|
39
|
+
if (source === 'user' || mergedMeta.session_count >= 3) {
|
|
40
|
+
finalStatus = 'verified';
|
|
41
|
+
}
|
|
42
|
+
return await trx
|
|
43
|
+
.updateTable(knowledgeTable)
|
|
44
|
+
.set({
|
|
45
|
+
confidence: finalConfidence,
|
|
46
|
+
status: finalStatus,
|
|
47
|
+
tags: JSON.stringify(mergedTags),
|
|
48
|
+
metadata: JSON.stringify(mergedMeta),
|
|
49
|
+
updated_at: new Date(),
|
|
50
|
+
source_session_id: sourceSessionId ?? existing.source_session_id,
|
|
51
|
+
})
|
|
52
|
+
.where('id', '=', existing.id)
|
|
53
|
+
.returningAll()
|
|
54
|
+
.executeTakeFirstOrThrow();
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
async createInitial(trx, knowledgeTable, entity, fact, confidence, sourceSessionId, tags = [], metadata = {}, source = 'assistant') {
|
|
59
|
+
const initialMeta = {
|
|
60
|
+
...metadata,
|
|
61
|
+
source,
|
|
62
|
+
sessions: sourceSessionId ? [sourceSessionId] : [],
|
|
63
|
+
session_count: sourceSessionId ? 1 : 0,
|
|
64
|
+
};
|
|
65
|
+
return await trx
|
|
66
|
+
.insertInto(knowledgeTable)
|
|
67
|
+
.values({
|
|
68
|
+
entity,
|
|
69
|
+
fact,
|
|
70
|
+
confidence: source === 'user' ? Math.max(confidence, 0.8) : confidence,
|
|
71
|
+
status: source === 'user' ? 'verified' : 'proposed',
|
|
72
|
+
source_session_id: sourceSessionId ?? null,
|
|
73
|
+
tags: JSON.stringify(tags),
|
|
74
|
+
metadata: JSON.stringify(initialMeta),
|
|
75
|
+
created_at: new Date(),
|
|
76
|
+
updated_at: new Date(),
|
|
77
|
+
})
|
|
78
|
+
.returningAll()
|
|
79
|
+
.executeTakeFirstOrThrow();
|
|
80
|
+
}
|
|
81
|
+
async verify(db, knowledgeTable, id, reinforcement = 0.1) {
|
|
82
|
+
const existing = await db
|
|
83
|
+
.selectFrom(knowledgeTable)
|
|
84
|
+
.selectAll()
|
|
85
|
+
.where('id', '=', id)
|
|
86
|
+
.executeTakeFirst();
|
|
87
|
+
if (!existing)
|
|
88
|
+
return null;
|
|
89
|
+
const metadata = typeof existing.metadata === 'string'
|
|
90
|
+
? JSON.parse(existing.metadata)
|
|
91
|
+
: existing.metadata || {};
|
|
92
|
+
// Hallucination Guard
|
|
93
|
+
let maxConfidence = 1.0;
|
|
94
|
+
if (metadata.source !== 'user' && (metadata.session_count || 0) < 3) {
|
|
95
|
+
maxConfidence = 0.85;
|
|
96
|
+
}
|
|
97
|
+
const newConfidence = Math.min(maxConfidence, existing.confidence + reinforcement);
|
|
98
|
+
// Promotion Lifecycle
|
|
99
|
+
let newStatus = existing.status || 'proposed';
|
|
100
|
+
if (newConfidence >= 0.9 || metadata.session_count >= 3) {
|
|
101
|
+
newStatus = 'verified';
|
|
102
|
+
}
|
|
103
|
+
return await db
|
|
104
|
+
.updateTable(knowledgeTable)
|
|
105
|
+
.set({
|
|
106
|
+
confidence: newConfidence,
|
|
107
|
+
status: newStatus,
|
|
108
|
+
updated_at: new Date(),
|
|
109
|
+
})
|
|
110
|
+
.where('id', '=', id)
|
|
111
|
+
.returningAll()
|
|
112
|
+
.executeTakeFirstOrThrow();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.FactDistiller = FactDistiller;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Kysely } from '../../../kysely.js';
|
|
2
|
+
import type { KnowledgeItem } from '../../../types/index.js';
|
|
3
|
+
export declare class KnowledgeConsolidator {
|
|
4
|
+
consolidate(db: Kysely<any>, knowledgeTable: string, getKnowledgeByEntityFn: (entity: string) => Promise<KnowledgeItem[]>): Promise<number>;
|
|
5
|
+
private mergeItems;
|
|
6
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KnowledgeConsolidator = void 0;
|
|
4
|
+
const similarity_js_1 = require("../../../util/similarity.js");
|
|
5
|
+
class KnowledgeConsolidator {
|
|
6
|
+
async consolidate(db, knowledgeTable, getKnowledgeByEntityFn) {
|
|
7
|
+
let totalMerged = 0;
|
|
8
|
+
const candidates = await db
|
|
9
|
+
.selectFrom(knowledgeTable)
|
|
10
|
+
.select('entity')
|
|
11
|
+
.groupBy('entity')
|
|
12
|
+
.having((eb) => eb.fn.count('id'), '>', 1)
|
|
13
|
+
.limit(500)
|
|
14
|
+
.execute();
|
|
15
|
+
for (const cand of candidates) {
|
|
16
|
+
const entity = cand.entity;
|
|
17
|
+
const items = await getKnowledgeByEntityFn(entity);
|
|
18
|
+
const mergedIds = new Set();
|
|
19
|
+
const iterLimit = Math.min(items.length, 100);
|
|
20
|
+
for (let i = 0; i < iterLimit; i++) {
|
|
21
|
+
if (mergedIds.has(items[i].id))
|
|
22
|
+
continue;
|
|
23
|
+
for (let j = i + 1; j < iterLimit; j++) {
|
|
24
|
+
if (mergedIds.has(items[j].id))
|
|
25
|
+
continue;
|
|
26
|
+
const sim = (0, similarity_js_1.calculateSimilarity)(items[i].fact, items[j].fact);
|
|
27
|
+
if (sim > 0.85) {
|
|
28
|
+
await this.mergeItems(db, knowledgeTable, items[i], items[j]);
|
|
29
|
+
mergedIds.add(items[j].id);
|
|
30
|
+
totalMerged++;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return totalMerged;
|
|
36
|
+
}
|
|
37
|
+
async mergeItems(db, knowledgeTable, primary, secondary) {
|
|
38
|
+
const mergedMeta = {
|
|
39
|
+
...secondary.metadata,
|
|
40
|
+
...primary.metadata,
|
|
41
|
+
consolidated_from: secondary.id,
|
|
42
|
+
consolidated_at: new Date().toISOString(),
|
|
43
|
+
};
|
|
44
|
+
const mergedTags = Array.from(new Set([...(primary.tags || []), ...(secondary.tags || [])]));
|
|
45
|
+
await db.transaction().execute(async (trx) => {
|
|
46
|
+
await trx
|
|
47
|
+
.updateTable(knowledgeTable)
|
|
48
|
+
.set({
|
|
49
|
+
confidence: Math.max(primary.confidence, secondary.confidence),
|
|
50
|
+
metadata: JSON.stringify(mergedMeta),
|
|
51
|
+
tags: JSON.stringify(mergedTags),
|
|
52
|
+
updated_at: new Date(),
|
|
53
|
+
})
|
|
54
|
+
.where('id', '=', primary.id)
|
|
55
|
+
.execute();
|
|
56
|
+
await trx
|
|
57
|
+
.deleteFrom(knowledgeTable)
|
|
58
|
+
.where('id', '=', secondary.id)
|
|
59
|
+
.execute();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.KnowledgeConsolidator = KnowledgeConsolidator;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Transaction } from '../../../kysely.js';
|
|
2
|
+
import type { KnowledgeItem } from '../../../types/index.js';
|
|
3
|
+
export declare class RelationshipArchitect {
|
|
4
|
+
autoLink(item: KnowledgeItem, trx: Transaction<any>, knowledgeTable: string, linksTable: string): Promise<void>;
|
|
5
|
+
link(sourceId: number | string, targetId: number | string, relationship: string, metadata: Record<string, any> | undefined, trxOrDb: any, linksTable: string): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelationshipArchitect = void 0;
|
|
4
|
+
const similarity_js_1 = require("../../../util/similarity.js");
|
|
5
|
+
class RelationshipArchitect {
|
|
6
|
+
async autoLink(item, trx, knowledgeTable, linksTable) {
|
|
7
|
+
// 1. Structural Extraction (NER-style)
|
|
8
|
+
const tokens = item.fact.match(/([A-Z][a-z]+(?:\s[A-Z][a-z]+)*)|("[^"]+")|([a-z]+[A-Z][a-z]+)/g) || [];
|
|
9
|
+
const potentialEntities = Array.from(new Set(tokens.map((t) => t.replace(/"/g, '').trim())))
|
|
10
|
+
.filter((t) => t.length > 2 && t !== item.entity);
|
|
11
|
+
if (potentialEntities.length > 0) {
|
|
12
|
+
const matches = await trx
|
|
13
|
+
.selectFrom(knowledgeTable)
|
|
14
|
+
.select(['id', 'entity'])
|
|
15
|
+
.where('entity', 'in', potentialEntities)
|
|
16
|
+
.execute();
|
|
17
|
+
for (const match of matches) {
|
|
18
|
+
await this.link(item.id, match.id, 'mentions', { auto: true, source: 'structural_extraction' }, trx, linksTable);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// 2. Semantic Similarity Pass
|
|
22
|
+
const candidates = await trx
|
|
23
|
+
.selectFrom(knowledgeTable)
|
|
24
|
+
.selectAll()
|
|
25
|
+
.where('id', '!=', item.id)
|
|
26
|
+
.where('confidence', '>', 0.4)
|
|
27
|
+
.orderBy('updated_at', 'desc')
|
|
28
|
+
.limit(50)
|
|
29
|
+
.execute();
|
|
30
|
+
const linksToCreate = [];
|
|
31
|
+
for (const other of candidates) {
|
|
32
|
+
const otherFact = other.fact;
|
|
33
|
+
const sim = (0, similarity_js_1.calculateSimilarity)(item.fact, otherFact);
|
|
34
|
+
if (sim > 0.75) {
|
|
35
|
+
linksToCreate.push({ targetId: other.id, sim });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const l of linksToCreate) {
|
|
39
|
+
await this.link(item.id, l.targetId, 'semantically_related', { similarity: l.sim, version: '2.0' }, trx, linksTable);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async link(sourceId, targetId, relationship, metadata, trxOrDb, linksTable) {
|
|
43
|
+
if (sourceId === targetId)
|
|
44
|
+
return;
|
|
45
|
+
const existing = await trxOrDb
|
|
46
|
+
.selectFrom(linksTable)
|
|
47
|
+
.select('id')
|
|
48
|
+
.where('source_id', '=', sourceId)
|
|
49
|
+
.where('target_id', '=', targetId)
|
|
50
|
+
.where('relationship', '=', relationship)
|
|
51
|
+
.executeTakeFirst();
|
|
52
|
+
if (existing) {
|
|
53
|
+
await trxOrDb
|
|
54
|
+
.updateTable(linksTable)
|
|
55
|
+
.set({ metadata: metadata ? JSON.stringify(metadata) : null })
|
|
56
|
+
.where('id', '=', existing.id)
|
|
57
|
+
.execute();
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await trxOrDb
|
|
61
|
+
.insertInto(linksTable)
|
|
62
|
+
.values({
|
|
63
|
+
source_id: sourceId,
|
|
64
|
+
target_id: targetId,
|
|
65
|
+
relationship,
|
|
66
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
67
|
+
created_at: new Date(),
|
|
68
|
+
})
|
|
69
|
+
.execute();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.RelationshipArchitect = RelationshipArchitect;
|
|
@@ -5,7 +5,7 @@ class MaintenanceOracle {
|
|
|
5
5
|
async suggestRepairs(ctx) {
|
|
6
6
|
const repairs = [];
|
|
7
7
|
// Fetch maintenance policies
|
|
8
|
-
const policies = (await ctx.
|
|
8
|
+
const policies = (await ctx.trx
|
|
9
9
|
.selectFrom(ctx.policiesTable)
|
|
10
10
|
.selectAll()
|
|
11
11
|
.where('is_enabled', '=', true)
|
|
@@ -21,12 +21,12 @@ class MaintenanceOracle {
|
|
|
21
21
|
const costPolicy = getPolicyValue('high_cost_threshold', 0.5);
|
|
22
22
|
const storagePolicy = getPolicyValue('cold_storage_threshold', 30);
|
|
23
23
|
// 1. Check for chronic high latency
|
|
24
|
-
const latencyStats = await ctx.cortex.metrics.getMetricStats('query_latency');
|
|
24
|
+
const latencyStats = await ctx.cortex.metrics.getMetricStats('query_latency', {}, ctx.trx);
|
|
25
25
|
if (latencyStats.avg > latencyPolicy && latencyStats.count > 10) {
|
|
26
26
|
repairs.push(`Average latency is high (${latencyStats.avg.toFixed(2)}ms). Suggesting index audit across hit tables.`);
|
|
27
27
|
}
|
|
28
28
|
// 2. Detect specific slow tables
|
|
29
|
-
const recentSlowQueries = await ctx.
|
|
29
|
+
const recentSlowQueries = await ctx.trx
|
|
30
30
|
.selectFrom(ctx.metricsTable)
|
|
31
31
|
.select('metadata')
|
|
32
32
|
.where('metric_name', '=', 'query_latency')
|
|
@@ -46,14 +46,14 @@ class MaintenanceOracle {
|
|
|
46
46
|
repairs.push(`Table '${table}' is experiencing periodic latency spikes. Suggesting 'CREATE INDEX' for common filters.`);
|
|
47
47
|
}
|
|
48
48
|
// 3. Check for high cost
|
|
49
|
-
const totalCost = await ctx.cortex.metrics.getAverageMetric('total_cost');
|
|
49
|
+
const totalCost = await ctx.cortex.metrics.getAverageMetric('total_cost', ctx.trx);
|
|
50
50
|
if (totalCost > costPolicy) {
|
|
51
51
|
repairs.push('Average query cost is high. Suggesting prompt compression or model switching (e.g., to a smaller model).');
|
|
52
52
|
}
|
|
53
53
|
// 4. Cold storage candidates
|
|
54
54
|
const oldThreshold = new Date(Date.now() - storagePolicy * 24 * 60 * 60 * 1000);
|
|
55
55
|
const sessionsTable = ctx.config.sessionsTable || 'agent_sessions';
|
|
56
|
-
const oldSessions = (await ctx.
|
|
56
|
+
const oldSessions = (await ctx.trx
|
|
57
57
|
.selectFrom(sessionsTable)
|
|
58
58
|
.select((eb) => eb.fn.count('id').as('count'))
|
|
59
59
|
.where('created_at', '<', oldThreshold)
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PersonaAuditor = void 0;
|
|
4
|
+
const db_utils_js_1 = require("../../util/db-utils.js");
|
|
4
5
|
class PersonaAuditor {
|
|
5
6
|
async audit(ctx) {
|
|
6
7
|
const issues = [];
|
|
7
8
|
const activePersona = await this.getActivePersona(ctx);
|
|
8
9
|
if (activePersona) {
|
|
9
|
-
const quotaCheck = await ctx.cortex.quotas.checkQuota('persona', activePersona.id);
|
|
10
|
+
const quotaCheck = await ctx.cortex.quotas.checkQuota('persona', activePersona.id, ctx.trx);
|
|
10
11
|
if (!quotaCheck.allowed) {
|
|
11
12
|
issues.push(`Quota Breach: ${quotaCheck.reason}`);
|
|
12
13
|
}
|
|
13
14
|
// Check for swarm-level quotas if part of a swarm
|
|
14
15
|
const swarmId = activePersona.metadata?.swarm_id;
|
|
15
16
|
if (swarmId) {
|
|
16
|
-
const swarmCheck = await ctx.cortex.quotas.checkQuota('swarm', swarmId);
|
|
17
|
+
const swarmCheck = await ctx.cortex.quotas.checkQuota('swarm', swarmId, ctx.trx);
|
|
17
18
|
if (!swarmCheck.allowed) {
|
|
18
19
|
issues.push(`Swarm Quota Breach [${swarmId}]: ${swarmCheck.reason}`);
|
|
19
20
|
}
|
|
@@ -43,17 +44,12 @@ class PersonaAuditor {
|
|
|
43
44
|
console.warn(`[PersonaAuditor] QUARANTINING Persona ${id}: ${reason}`);
|
|
44
45
|
// Use the provided transaction or start a new one to ensure atomicity
|
|
45
46
|
const runner = async (trx) => {
|
|
46
|
-
|
|
47
|
+
const query = trx
|
|
47
48
|
.selectFrom(ctx.personasTable)
|
|
48
49
|
.selectAll()
|
|
49
50
|
.where('id', '=', id);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const adapterName = executor?.adapter?.constructor?.name || executor?.dialect?.constructor?.name || '';
|
|
53
|
-
if (!adapterName.toLowerCase().includes('sqlite')) {
|
|
54
|
-
query = query.forUpdate();
|
|
55
|
-
}
|
|
56
|
-
const persona = await query.executeTakeFirst();
|
|
51
|
+
const persona = await (0, db_utils_js_1.withLock)(query, trx)
|
|
52
|
+
.executeTakeFirst();
|
|
57
53
|
if (persona) {
|
|
58
54
|
const metadata = typeof persona.metadata === 'string'
|
|
59
55
|
? JSON.parse(persona.metadata)
|
|
@@ -72,7 +68,7 @@ class PersonaAuditor {
|
|
|
72
68
|
.where('id', '=', id)
|
|
73
69
|
.execute();
|
|
74
70
|
// Rollback most recent changes via strategy engine
|
|
75
|
-
await ctx.cortex.strategy.rollbackPersona(id);
|
|
71
|
+
await ctx.cortex.strategy.rollbackPersona(id, trx);
|
|
76
72
|
}
|
|
77
73
|
};
|
|
78
74
|
if (ctx.trx && ctx.trx !== ctx.db) {
|
|
@@ -23,8 +23,7 @@ class RemediationEngine {
|
|
|
23
23
|
if (!skillName)
|
|
24
24
|
return;
|
|
25
25
|
console.log(`[RemediationEngine] Demoting tainted skill out of verified pool: ${skillName}`);
|
|
26
|
-
|
|
27
|
-
await ctx.db.transaction().execute(async (trx) => {
|
|
26
|
+
const runner = async (trx) => {
|
|
28
27
|
const skill = await trx
|
|
29
28
|
.selectFrom(ctx.skillsTable)
|
|
30
29
|
.select('id')
|
|
@@ -37,7 +36,13 @@ class RemediationEngine {
|
|
|
37
36
|
.where('id', '=', skill.id)
|
|
38
37
|
.execute();
|
|
39
38
|
}
|
|
40
|
-
}
|
|
39
|
+
};
|
|
40
|
+
if (ctx.trx && ctx.trx !== ctx.db) {
|
|
41
|
+
await runner(ctx.trx);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
await ctx.db.transaction().execute((trx) => runner(trx));
|
|
45
|
+
}
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
48
|
exports.RemediationEngine = RemediationEngine;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DomainMaster = void 0;
|
|
4
|
+
const sql_js_1 = require("../../../raw-builder/sql.js");
|
|
5
|
+
class DomainMaster {
|
|
6
|
+
async boostDomain(db, knowledgeTable, domainTag, boostFactor = 0.05) {
|
|
7
|
+
const result = await db
|
|
8
|
+
.updateTable(knowledgeTable)
|
|
9
|
+
.set({
|
|
10
|
+
confidence: (0, sql_js_1.sql) `MIN(1.0, confidence + ${boostFactor})`,
|
|
11
|
+
updated_at: new Date(),
|
|
12
|
+
})
|
|
13
|
+
.where('tags', 'like', `%"${domainTag}"%`)
|
|
14
|
+
.where('confidence', '<', 1.0)
|
|
15
|
+
.execute();
|
|
16
|
+
return Number(result[0]?.numUpdatedRows ?? 1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DomainMaster = DomainMaster;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Kysely } from '../../../kysely.js';
|
|
2
|
+
import type { AgenticConfig, KnowledgeItem } from '../../../types/index.js';
|
|
3
|
+
import type { Cortex } from '../../Cortex.js';
|
|
4
|
+
export declare class KnowledgePromoter {
|
|
5
|
+
promote(db: Kysely<any>, cortex: Cortex, config: AgenticConfig, knowledgeTable: string, item: KnowledgeItem): Promise<boolean>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KnowledgePromoter = void 0;
|
|
4
|
+
const db_utils_js_1 = require("../../util/db-utils.js");
|
|
5
|
+
class KnowledgePromoter {
|
|
6
|
+
async promote(db, cortex, config, knowledgeTable, item) {
|
|
7
|
+
return await db.transaction().execute(async (trx) => {
|
|
8
|
+
// Check if a global version already exists
|
|
9
|
+
const query = trx
|
|
10
|
+
.selectFrom(knowledgeTable)
|
|
11
|
+
.selectAll()
|
|
12
|
+
.where('entity', '=', item.entity)
|
|
13
|
+
.where('fact', '=', item.fact)
|
|
14
|
+
.where('source_session_id', 'is', null);
|
|
15
|
+
const existingGlobal = await (0, db_utils_js_1.withLock)(query, trx) // Prevent concurrent promotion duplication
|
|
16
|
+
.executeTakeFirst();
|
|
17
|
+
if (existingGlobal) {
|
|
18
|
+
// Reinforce existing global knowledge
|
|
19
|
+
const newConfidence = Math.min(0.99, Math.max(existingGlobal.confidence, item.confidence) + 0.01);
|
|
20
|
+
await trx
|
|
21
|
+
.updateTable(knowledgeTable)
|
|
22
|
+
.set({
|
|
23
|
+
confidence: newConfidence,
|
|
24
|
+
updated_at: new Date(),
|
|
25
|
+
})
|
|
26
|
+
.where('id', '=', existingGlobal.id)
|
|
27
|
+
.execute();
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// Create new global knowledge
|
|
32
|
+
const tags = item.tags ? [...item.tags] : [];
|
|
33
|
+
if (!tags.includes('hive_mind'))
|
|
34
|
+
tags.push('hive_mind');
|
|
35
|
+
await trx
|
|
36
|
+
.insertInto(knowledgeTable)
|
|
37
|
+
.values({
|
|
38
|
+
entity: item.entity,
|
|
39
|
+
fact: item.fact,
|
|
40
|
+
confidence: item.confidence,
|
|
41
|
+
source_session_id: null,
|
|
42
|
+
tags: JSON.stringify(tags),
|
|
43
|
+
metadata: JSON.stringify({
|
|
44
|
+
...item.metadata,
|
|
45
|
+
promoted_from: item.id,
|
|
46
|
+
promoted_at: new Date(),
|
|
47
|
+
}),
|
|
48
|
+
created_at: new Date(),
|
|
49
|
+
updated_at: new Date(),
|
|
50
|
+
})
|
|
51
|
+
.execute();
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.KnowledgePromoter = KnowledgePromoter;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Kysely } from '../../../kysely.js';
|
|
2
|
+
import type { AgenticConfig } from '../../../types/index.js';
|
|
3
|
+
import type { Cortex } from '../../Cortex.js';
|
|
4
|
+
export declare class SkillPropagator {
|
|
5
|
+
propagate(db: Kysely<any>, cortex: Cortex, config: AgenticConfig): Promise<number>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkillPropagator = void 0;
|
|
4
|
+
class SkillPropagator {
|
|
5
|
+
async propagate(db, cortex, config) {
|
|
6
|
+
let broadcastCount = 0;
|
|
7
|
+
const capTable = config.capabilitiesTable || 'agent_capabilities';
|
|
8
|
+
// 1. Regular Skill Propagation (Verified Alpha/Shadow)
|
|
9
|
+
const verifiedSkills = await cortex.capabilities.getCapabilities('verified');
|
|
10
|
+
const lineageGroups = new Map();
|
|
11
|
+
for (const skill of verifiedSkills) {
|
|
12
|
+
const meta = typeof skill.metadata === 'string' ? JSON.parse(skill.metadata) : (skill.metadata || {});
|
|
13
|
+
const lineage = meta.lineage || skill.name;
|
|
14
|
+
if (!lineageGroups.has(lineage))
|
|
15
|
+
lineageGroups.set(lineage, []);
|
|
16
|
+
lineageGroups.get(lineage).push({ skill, meta });
|
|
17
|
+
}
|
|
18
|
+
for (const [_, variants] of lineageGroups.entries()) {
|
|
19
|
+
const alphaCandidate = variants.reduce((prev, curr) => {
|
|
20
|
+
const getScore = (v) => {
|
|
21
|
+
const r = v.skill.reliability ?? 0.5;
|
|
22
|
+
const n = (typeof v.meta === 'string' ? JSON.parse(v.meta) : v.meta)?.usages ?? 1;
|
|
23
|
+
const K = 5;
|
|
24
|
+
const prior = 0.5;
|
|
25
|
+
return (r * n + K * prior) / (n + K);
|
|
26
|
+
};
|
|
27
|
+
return getScore(curr) > getScore(prev) ? curr : prev;
|
|
28
|
+
});
|
|
29
|
+
await db.transaction().execute(async (trx) => {
|
|
30
|
+
const currentMeta = alphaCandidate.meta || {};
|
|
31
|
+
const updatedMeta = {
|
|
32
|
+
...currentMeta,
|
|
33
|
+
is_alpha: true,
|
|
34
|
+
broadcasted: true,
|
|
35
|
+
broadcasted_at: new Date()
|
|
36
|
+
};
|
|
37
|
+
await trx
|
|
38
|
+
.updateTable(capTable)
|
|
39
|
+
.set({ metadata: JSON.stringify(updatedMeta) })
|
|
40
|
+
.where('id', '=', alphaCandidate.skill.id)
|
|
41
|
+
.execute();
|
|
42
|
+
const shadowIds = variants
|
|
43
|
+
.filter(v => v.skill.id !== alphaCandidate.skill.id)
|
|
44
|
+
.map(v => v.skill.id);
|
|
45
|
+
for (const sid of shadowIds) {
|
|
46
|
+
const sMatch = variants.find(v => v.skill.id === sid);
|
|
47
|
+
const sMeta = sMatch?.meta || {};
|
|
48
|
+
await trx.updateTable(capTable)
|
|
49
|
+
.set({
|
|
50
|
+
metadata: JSON.stringify({ ...sMeta, is_alpha: false, is_shadow: true }),
|
|
51
|
+
status: 'experimental'
|
|
52
|
+
})
|
|
53
|
+
.where('id', '=', sid)
|
|
54
|
+
.execute();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
broadcastCount++;
|
|
58
|
+
}
|
|
59
|
+
// 2. Blacklisted Skill Propagation (Immune Prophet)
|
|
60
|
+
const blacklisted = await cortex.capabilities.getCapabilities('blacklisted');
|
|
61
|
+
const blackIDs = blacklisted
|
|
62
|
+
.filter(s => {
|
|
63
|
+
const meta = typeof s.metadata === 'string' ? JSON.parse(s.metadata) : (s.metadata || {});
|
|
64
|
+
return !meta.broadcasted || !meta.hive_blacklisted;
|
|
65
|
+
})
|
|
66
|
+
.map(s => s.id);
|
|
67
|
+
if (blackIDs.length > 0) {
|
|
68
|
+
await db.transaction().execute(async (trx) => {
|
|
69
|
+
for (const bid of blackIDs) {
|
|
70
|
+
const skill = await trx.selectFrom(capTable)
|
|
71
|
+
.select('metadata')
|
|
72
|
+
.where('id', '=', bid)
|
|
73
|
+
.executeTakeFirst();
|
|
74
|
+
if (skill) {
|
|
75
|
+
const meta = typeof skill.metadata === 'string' ? JSON.parse(skill.metadata) : (skill.metadata || {});
|
|
76
|
+
await trx.updateTable(capTable)
|
|
77
|
+
.set({
|
|
78
|
+
metadata: JSON.stringify({ ...meta, broadcasted: true, hive_blacklisted: true }),
|
|
79
|
+
updated_at: new Date()
|
|
80
|
+
})
|
|
81
|
+
.where('id', '=', bid)
|
|
82
|
+
.execute();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
broadcastCount += blackIDs.length;
|
|
87
|
+
}
|
|
88
|
+
return broadcastCount;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.SkillPropagator = SkillPropagator;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AgentPersona } from '../../../types/index.js';
|
|
2
|
+
import type { Cortex } from '../../Cortex.js';
|
|
3
|
+
import type { PerformanceReport } from '../StrategicPlanner.js';
|
|
4
|
+
export declare class EvolutionVerificator {
|
|
5
|
+
verify(trxOrDb: any, cortex: Cortex, personasTable: string, persona: AgentPersona, report: PerformanceReport, allPersonas: AgentPersona[], rollbackFn: (id: string | number, trx: any) => Promise<string>): Promise<string | null>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EvolutionVerificator = void 0;
|
|
4
|
+
class EvolutionVerificator {
|
|
5
|
+
async verify(trxOrDb, cortex, personasTable, persona, report, allPersonas, rollbackFn) {
|
|
6
|
+
const rollbackHistory = persona.metadata?.rollbackHistory || [];
|
|
7
|
+
const recentRollbacks = rollbackHistory.filter((ts) => Date.now() - ts < 604800000).length;
|
|
8
|
+
const hiveTrusted = allPersonas.filter((p) => p.metadata?.evolution_status === 'stable' && p.metadata?.mutation_reason === persona.metadata?.mutation_reason).length;
|
|
9
|
+
let sampleSizeThreshold = 10 + recentRollbacks * 10;
|
|
10
|
+
const baseline = persona.metadata?.verification_baseline || { successRate: 0.8, averageLatency: 500 };
|
|
11
|
+
// Accelerated Stabilization
|
|
12
|
+
const earlyZ = (report.successRate - baseline.successRate) / 0.1;
|
|
13
|
+
if (earlyZ > 3.0 && report.sampleSize >= 5)
|
|
14
|
+
sampleSizeThreshold = 5;
|
|
15
|
+
if (hiveTrusted >= 3)
|
|
16
|
+
sampleSizeThreshold = Math.max(5, Math.floor(sampleSizeThreshold / 2));
|
|
17
|
+
if (report.sampleSize < sampleSizeThreshold)
|
|
18
|
+
return null;
|
|
19
|
+
// Dynamic Variance
|
|
20
|
+
const recentMetrics = await cortex.metrics.getRecentMetrics(100, trxOrDb);
|
|
21
|
+
const values = recentMetrics.filter((m) => m.metricName === 'success_rate').map((m) => Number(m.metricValue));
|
|
22
|
+
const mean = values.reduce((a, b) => a + b, 0) / (values.length || 1);
|
|
23
|
+
const variance = values.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / (values.length || 1);
|
|
24
|
+
const stdDev = Math.sqrt(variance) || 0.1;
|
|
25
|
+
const zScore = (report.successRate - baseline.successRate) / (stdDev || 1);
|
|
26
|
+
if (zScore < -2.0)
|
|
27
|
+
return await rollbackFn(persona.id, trxOrDb);
|
|
28
|
+
if (report.sampleSize >= sampleSizeThreshold * 2 && zScore >= -0.5) {
|
|
29
|
+
if (persona.metadata?.mutation_reason?.includes('optimize_efficiency')) {
|
|
30
|
+
await cortex.rules.defineRule('all', 'all', 'audit', {
|
|
31
|
+
condition: 'latency > 500',
|
|
32
|
+
priority: 10,
|
|
33
|
+
metadata: { reason: `Distilled from successful persona ${persona.id} optimization` },
|
|
34
|
+
}, trxOrDb);
|
|
35
|
+
}
|
|
36
|
+
await trxOrDb.updateTable(personasTable)
|
|
37
|
+
.set({ metadata: JSON.stringify({ ...persona.metadata, evolution_status: 'stable' }) })
|
|
38
|
+
.where('id', '=', persona.id)
|
|
39
|
+
.execute();
|
|
40
|
+
return `Evolution stabilized for persona ${persona.id}`;
|
|
41
|
+
}
|
|
42
|
+
const timeInVerification = (Date.now() - (persona.metadata?.verification_started_at || 0)) / 1000;
|
|
43
|
+
if (timeInVerification > 86400 * 3)
|
|
44
|
+
return await rollbackFn(persona.id, trxOrDb);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.EvolutionVerificator = EvolutionVerificator;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Kysely } from '../../../kysely.js';
|
|
2
|
+
import type { AgentPersona } from '../../../types/index.js';
|
|
3
|
+
import type { Cortex } from '../../Cortex.js';
|
|
4
|
+
import type { PerformanceReport } from '../StrategicPlanner.js';
|
|
5
|
+
export declare class MutationEngine {
|
|
6
|
+
private personasTable;
|
|
7
|
+
constructor(personasTable: string);
|
|
8
|
+
applyMutation(db: Kysely<any>, cortex: Cortex, persona: AgentPersona, report: PerformanceReport, failures: string[] | undefined, sanitizeRoleFn: (role: string) => string, parsePersonaFn: (p: any) => AgentPersona): Promise<string | null>;
|
|
9
|
+
rollback(db: Kysely<any>, id: string | number, parsePersonaFn: (p: any) => AgentPersona): Promise<string>;
|
|
10
|
+
}
|