noormme 1.2.3 → 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 +4 -4
- 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 +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 +4 -4
- 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 +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
|
@@ -42,8 +42,8 @@ export class RecursiveReasoner {
|
|
|
42
42
|
/**
|
|
43
43
|
* Find goals matching a pattern across all sessions
|
|
44
44
|
*/
|
|
45
|
-
async analyzeGlobalProgress(pattern) {
|
|
46
|
-
const goals = (await
|
|
45
|
+
async analyzeGlobalProgress(pattern, trxOrDb = this.db) {
|
|
46
|
+
const goals = (await trxOrDb
|
|
47
47
|
.selectFrom(this.goalsTable)
|
|
48
48
|
.selectAll()
|
|
49
49
|
.where('description', 'like', `%${pattern}%`)
|
|
@@ -55,10 +55,10 @@ export class RecursiveReasoner {
|
|
|
55
55
|
* Synthesize high-level lessons and cluster similar ones using Token-Weighted significance.
|
|
56
56
|
* Pass 5: High-Throughput Semantic Analysis.
|
|
57
57
|
*/
|
|
58
|
-
async synthesizeLessons() {
|
|
58
|
+
async synthesizeLessons(trxOrDb = this.db) {
|
|
59
59
|
console.log('[RecursiveReasoner] Performing high-throughput weighted token clustering...');
|
|
60
60
|
const reflectionsTable = this.config.reflectionsTable || 'agent_reflections';
|
|
61
|
-
const results = (await
|
|
61
|
+
const results = (await trxOrDb
|
|
62
62
|
.selectFrom(reflectionsTable)
|
|
63
63
|
.select('lessons_learned')
|
|
64
64
|
.where('lessons_learned', 'is not', null)
|
|
@@ -98,12 +98,12 @@ export class RecursiveReasoner {
|
|
|
98
98
|
* Pass 6: Goal Cross-Pollination
|
|
99
99
|
* Distill successful persona mutations into global systemic goals.
|
|
100
100
|
*/
|
|
101
|
-
async crossPollinateGoals() {
|
|
101
|
+
async crossPollinateGoals(trxOrDb = this.db) {
|
|
102
102
|
console.log('[RecursiveReasoner] Cross-pollinating successful persona breakthroughs into global goals...');
|
|
103
103
|
const personasTable = this.config.personasTable || 'agent_personas';
|
|
104
104
|
const goalsTable = this.config.goalsTable || 'agent_goals';
|
|
105
105
|
// Find personas with 'stable' evolution status (proven breakthroughs)
|
|
106
|
-
const breakthroughs = await
|
|
106
|
+
const breakthroughs = await trxOrDb
|
|
107
107
|
.selectFrom(personasTable)
|
|
108
108
|
.selectAll()
|
|
109
109
|
.where('metadata', 'like', '%"evolution_status":"stable"%')
|
|
@@ -118,7 +118,7 @@ export class RecursiveReasoner {
|
|
|
118
118
|
.filter(Boolean);
|
|
119
119
|
if (descriptions.length === 0)
|
|
120
120
|
return 0;
|
|
121
|
-
const existingGoals = await
|
|
121
|
+
const existingGoals = await trxOrDb
|
|
122
122
|
.selectFrom(goalsTable)
|
|
123
123
|
.select('description')
|
|
124
124
|
.where('description', 'in', descriptions)
|
|
@@ -128,7 +128,7 @@ export class RecursiveReasoner {
|
|
|
128
128
|
for (const desc of descriptions) {
|
|
129
129
|
if (!existingSet.has(desc)) {
|
|
130
130
|
console.log(`[RecursiveReasoner] Distilling breakthrough into Global Goal: ${desc.slice(0, 50)}...`);
|
|
131
|
-
await
|
|
131
|
+
await trxOrDb
|
|
132
132
|
.insertInto(goalsTable)
|
|
133
133
|
.values({
|
|
134
134
|
session_id: 0, // System-level goal
|
|
@@ -150,9 +150,9 @@ export class RecursiveReasoner {
|
|
|
150
150
|
/**
|
|
151
151
|
* Detect contradictions in goals (e.g., opposing objectives).
|
|
152
152
|
*/
|
|
153
|
-
async detectContradictions() {
|
|
153
|
+
async detectContradictions(trxOrDb = this.db) {
|
|
154
154
|
console.log('[RecursiveReasoner] Detecting logical contradictions in systemic goals...');
|
|
155
|
-
const activeGoals = (await
|
|
155
|
+
const activeGoals = (await trxOrDb
|
|
156
156
|
.selectFrom(this.goalsTable)
|
|
157
157
|
.selectAll()
|
|
158
158
|
.where('status', '=', 'active')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Kysely } from '../../kysely.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AgentReflection, AgenticConfig } from '../../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* ReflectionEngine enables agents to perform "post-mortems" on sessions,
|
|
5
5
|
* storing lessons learned and evaluating outcomes to improve future performance.
|
|
@@ -12,7 +12,7 @@ export declare class ReflectionEngine {
|
|
|
12
12
|
/**
|
|
13
13
|
* Record a reflection for a session
|
|
14
14
|
*/
|
|
15
|
-
reflect(sessionId: string | number, outcome: AgentReflection['outcome'], lessonsLearned: string, suggestedActions?: string[], metadata?: Record<string, any
|
|
15
|
+
reflect(sessionId: string | number, outcome: AgentReflection['outcome'], lessonsLearned: string, suggestedActions?: string[], metadata?: Record<string, any>, trxOrDb?: any): Promise<AgentReflection>;
|
|
16
16
|
/**
|
|
17
17
|
* Get reflections for a specific session
|
|
18
18
|
*/
|
|
@@ -15,8 +15,8 @@ export class ReflectionEngine {
|
|
|
15
15
|
/**
|
|
16
16
|
* Record a reflection for a session
|
|
17
17
|
*/
|
|
18
|
-
async reflect(sessionId, outcome, lessonsLearned, suggestedActions, metadata) {
|
|
19
|
-
const reflection = (await
|
|
18
|
+
async reflect(sessionId, outcome, lessonsLearned, suggestedActions, metadata, trxOrDb = this.db) {
|
|
19
|
+
const reflection = (await trxOrDb
|
|
20
20
|
.insertInto(this.reflectionsTable)
|
|
21
21
|
.values({
|
|
22
22
|
session_id: sessionId,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Kysely } from '../../kysely.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AgentRitual, AgenticConfig } from '../../types/index.js';
|
|
3
3
|
import type { Cortex } from '../Cortex.js';
|
|
4
4
|
/**
|
|
5
5
|
* RitualOrchestrator handles the periodic execution of background tasks
|
|
@@ -18,11 +18,11 @@ export declare class RitualOrchestrator {
|
|
|
18
18
|
/**
|
|
19
19
|
* Run all pending rituals that are due
|
|
20
20
|
*/
|
|
21
|
-
runPendingRituals(): Promise<number>;
|
|
21
|
+
runPendingRituals(trxOrDb?: any): Promise<number>;
|
|
22
22
|
/**
|
|
23
23
|
* Execute a specific ritual
|
|
24
24
|
*/
|
|
25
|
-
executeRitual(ritual: AgentRitual): Promise<void>;
|
|
25
|
+
executeRitual(ritual: AgentRitual, trxOrDb?: any): Promise<void>;
|
|
26
26
|
/**
|
|
27
27
|
* Calculate next run with Adaptive Backoff for failures
|
|
28
28
|
*/
|
|
@@ -37,10 +37,10 @@ export class RitualOrchestrator {
|
|
|
37
37
|
/**
|
|
38
38
|
* Run all pending rituals that are due
|
|
39
39
|
*/
|
|
40
|
-
async runPendingRituals() {
|
|
40
|
+
async runPendingRituals(trxOrDb = this.db) {
|
|
41
41
|
const now = new Date();
|
|
42
42
|
const lockTimeout = new Date(now.getTime() + 600000); // 10 min lock by default
|
|
43
|
-
const
|
|
43
|
+
const runner = async (trx) => {
|
|
44
44
|
const due = (await trx
|
|
45
45
|
.selectFrom(this.ritualsTable)
|
|
46
46
|
.selectAll()
|
|
@@ -62,20 +62,23 @@ export class RitualOrchestrator {
|
|
|
62
62
|
.execute();
|
|
63
63
|
}
|
|
64
64
|
return due;
|
|
65
|
-
}
|
|
65
|
+
};
|
|
66
|
+
const pending = (trxOrDb !== this.db)
|
|
67
|
+
? await runner(trxOrDb)
|
|
68
|
+
: await this.db.transaction().execute(runner);
|
|
66
69
|
if (pending.length === 0)
|
|
67
70
|
return 0;
|
|
68
71
|
console.log(`[RitualOrchestrator] Found ${pending.length} pending rituals due. Locking for execution...`);
|
|
69
72
|
for (const ritual of pending) {
|
|
70
|
-
// Execute
|
|
71
|
-
await this.executeRitual(ritual);
|
|
73
|
+
// Execute with the same trxOrDb context
|
|
74
|
+
await this.executeRitual(ritual, trxOrDb);
|
|
72
75
|
}
|
|
73
76
|
return pending.length;
|
|
74
77
|
}
|
|
75
78
|
/**
|
|
76
79
|
* Execute a specific ritual
|
|
77
80
|
*/
|
|
78
|
-
async executeRitual(ritual) {
|
|
81
|
+
async executeRitual(ritual, trxOrDb = this.db) {
|
|
79
82
|
console.log(`[RitualOrchestrator] Executing ritual: ${ritual.name} (${ritual.type})`);
|
|
80
83
|
const ritualMetadata = {
|
|
81
84
|
...ritual.metadata,
|
|
@@ -92,7 +95,7 @@ export class RitualOrchestrator {
|
|
|
92
95
|
let offset = 0;
|
|
93
96
|
const batchSize = 100; // Audit Phase 17: Paginated session processing
|
|
94
97
|
while (true) {
|
|
95
|
-
const activeSessions = await
|
|
98
|
+
const activeSessions = await trxOrDb
|
|
96
99
|
.selectFrom(sessionsTable)
|
|
97
100
|
.select('id')
|
|
98
101
|
.where('status', '=', 'active')
|
|
@@ -102,7 +105,7 @@ export class RitualOrchestrator {
|
|
|
102
105
|
if (activeSessions.length === 0)
|
|
103
106
|
break;
|
|
104
107
|
for (const session of activeSessions) {
|
|
105
|
-
const countResult = (await
|
|
108
|
+
const countResult = (await trxOrDb
|
|
106
109
|
.selectFrom(messagesTable)
|
|
107
110
|
.select((eb) => eb.fn.countAll().as('count'))
|
|
108
111
|
.where('session_id', '=', session.id)
|
|
@@ -150,7 +153,7 @@ export class RitualOrchestrator {
|
|
|
150
153
|
// Update ritual status, unlock, and schedule next run
|
|
151
154
|
const frequency = ritual.frequency || 'daily';
|
|
152
155
|
const nextRun = this.calculateNextRun(frequency, success ? 0 : ritualMetadata.failureCount);
|
|
153
|
-
await
|
|
156
|
+
await trxOrDb
|
|
154
157
|
.updateTable(this.ritualsTable)
|
|
155
158
|
.set({
|
|
156
159
|
status: success ? 'success' : 'failure',
|
|
@@ -26,28 +26,27 @@ export class SelfEvolution {
|
|
|
26
26
|
* Ensure core agentic tables have telemetry columns like 'accessed_at'
|
|
27
27
|
*/
|
|
28
28
|
async ensureTelemetryColumns() {
|
|
29
|
-
const
|
|
29
|
+
const tableNames = [
|
|
30
30
|
this.config.agentic?.sessionsTable || 'agent_sessions',
|
|
31
31
|
this.config.agentic?.messagesTable || 'agent_messages',
|
|
32
32
|
this.config.agentic?.memoriesTable || 'agent_memories',
|
|
33
33
|
this.config.agentic?.goalsTable || 'agent_goals',
|
|
34
34
|
this.config.agentic?.knowledgeTable || 'agent_knowledge_base',
|
|
35
35
|
];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.then((ts) => ts.find((t) => t.name === table));
|
|
36
|
+
try {
|
|
37
|
+
const introspector = this.db.introspection;
|
|
38
|
+
const allTables = await introspector.getTables();
|
|
39
|
+
for (const tableName of tableNames) {
|
|
40
|
+
const tableInfo = allTables.find((t) => t.name === tableName);
|
|
42
41
|
if (tableInfo &&
|
|
43
42
|
!tableInfo.columns.some((c) => c.name === 'accessed_at')) {
|
|
44
|
-
console.log(`[SelfEvolution] Adding 'accessed_at' column to ${
|
|
45
|
-
await sql `ALTER TABLE ${sql.table(
|
|
43
|
+
console.log(`[SelfEvolution] Adding 'accessed_at' column to ${tableName}`);
|
|
44
|
+
await sql `ALTER TABLE ${sql.table(tableName)} ADD COLUMN accessed_at TIMESTAMP`.execute(this.db);
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
console.warn(`[SelfEvolution] Failed to add telemetry columns:`, e);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
@@ -98,12 +97,10 @@ export class SelfEvolution {
|
|
|
98
97
|
/**
|
|
99
98
|
* Apply a schema suggestion and instantly regenerate types
|
|
100
99
|
*/
|
|
101
|
-
async evolve(ddl, options = {}) {
|
|
100
|
+
async evolve(ddl, options = {}, trxOrDb = this.db) {
|
|
102
101
|
console.log(`[SelfEvolution] Applying structural change: ${ddl}`);
|
|
103
|
-
|
|
102
|
+
const runner = async (trx) => {
|
|
104
103
|
// 1. Apply the DDL change
|
|
105
|
-
// Pass transaction to evolution helper if it supports it,
|
|
106
|
-
// otherwise use trx.execute() directly for the DDL
|
|
107
104
|
await trx.execute(sql.raw(ddl));
|
|
108
105
|
// 1b. Log for potential rollback
|
|
109
106
|
await trx
|
|
@@ -120,7 +117,13 @@ export class SelfEvolution {
|
|
|
120
117
|
created_at: new Date(),
|
|
121
118
|
})
|
|
122
119
|
.execute();
|
|
123
|
-
}
|
|
120
|
+
};
|
|
121
|
+
if (trxOrDb && trxOrDb !== this.db) {
|
|
122
|
+
await runner(trxOrDb);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
await this.db.transaction().execute(runner);
|
|
126
|
+
}
|
|
124
127
|
// 2. Regenerate types
|
|
125
128
|
await this.regenerateTypes();
|
|
126
129
|
console.log(`[SelfEvolution] Schema evolved successfully.`);
|
|
@@ -239,7 +242,7 @@ export class SelfEvolution {
|
|
|
239
242
|
return `ALTER TABLE ${addColumnMatch[1]} DROP COLUMN ${addColumnMatch[2]}`;
|
|
240
243
|
}
|
|
241
244
|
// Match patterns like: ALTER TABLE "table_name" DROP [COLUMN] "column_name"
|
|
242
|
-
const dropColumnMatch = d.match(/ALTER TABLE\s+([^\s]+)\s+DROP\s+(?:COLUMN\s+)?([^\s\(\)]+)/i);
|
|
245
|
+
const dropColumnMatch = d.match(/ALTER TABLE\s+([^\s]+)\s+DROP\s+(?:COLUMN\s+)?([^\s\(\)]+)\s+([^\s]+)/i);
|
|
243
246
|
if (dropColumnMatch) {
|
|
244
247
|
// Note: Data is lost, but we can restore the structure
|
|
245
248
|
return `ALTER TABLE ${dropColumnMatch[1]} ADD COLUMN ${dropColumnMatch[2]} TEXT`; // Default to TEXT if unknown
|
|
@@ -34,8 +34,8 @@ export class SelfTestRegistry {
|
|
|
34
34
|
/**
|
|
35
35
|
* Run all registered probes
|
|
36
36
|
*/
|
|
37
|
-
async runAllProbes() {
|
|
38
|
-
const probes = (await
|
|
37
|
+
async runAllProbes(trxOrDb = this.db) {
|
|
38
|
+
const probes = (await trxOrDb
|
|
39
39
|
.selectFrom('agent_logic_probes')
|
|
40
40
|
.selectAll()
|
|
41
41
|
.execute());
|
|
@@ -45,22 +45,26 @@ export class SelfTestRegistry {
|
|
|
45
45
|
try {
|
|
46
46
|
let success = false;
|
|
47
47
|
if (probe.script.startsWith('audit:')) {
|
|
48
|
-
success = await this.runAuditAction(probe.script.split(':')[1]);
|
|
48
|
+
success = await this.runAuditAction(probe.script.split(':')[1], trxOrDb);
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
51
|
// Master Sentinel Pass: Dynamic Probe Evaluation
|
|
52
52
|
// If not a hardcoded audit, use LLM to interpret the script against DB state
|
|
53
|
-
success = await this.dynamicEvaluation(probe);
|
|
53
|
+
success = await this.dynamicEvaluation(probe, trxOrDb);
|
|
54
54
|
}
|
|
55
55
|
results.push({ name: probe.name, success });
|
|
56
|
-
|
|
56
|
+
const updateRunner = async (trx) => {
|
|
57
57
|
// Audit Phase 13: Lock row before updating last_status
|
|
58
|
-
|
|
58
|
+
let query = trx
|
|
59
59
|
.selectFrom('agent_logic_probes')
|
|
60
60
|
.select('id')
|
|
61
|
-
.where('id', '=', probe.id)
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
.where('id', '=', probe.id);
|
|
62
|
+
const executor = trx.getExecutor();
|
|
63
|
+
const adapterName = executor?.adapter?.constructor?.name || executor?.dialect?.constructor?.name || '';
|
|
64
|
+
if (!adapterName.toLowerCase().includes('sqlite')) {
|
|
65
|
+
query = query.forUpdate();
|
|
66
|
+
}
|
|
67
|
+
await query.executeTakeFirst();
|
|
64
68
|
await trx
|
|
65
69
|
.updateTable('agent_logic_probes')
|
|
66
70
|
.set({
|
|
@@ -69,7 +73,15 @@ export class SelfTestRegistry {
|
|
|
69
73
|
})
|
|
70
74
|
.where('id', '=', probe.id)
|
|
71
75
|
.execute();
|
|
72
|
-
}
|
|
76
|
+
};
|
|
77
|
+
if (trxOrDb && trxOrDb !== this.db) {
|
|
78
|
+
await updateRunner(trxOrDb);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
await this.db.transaction().execute(async (trx) => {
|
|
82
|
+
await updateRunner(trx);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
73
85
|
}
|
|
74
86
|
catch (e) {
|
|
75
87
|
results.push({ name: probe.name, success: false, error: String(e) });
|
|
@@ -77,7 +89,7 @@ export class SelfTestRegistry {
|
|
|
77
89
|
}
|
|
78
90
|
return results;
|
|
79
91
|
}
|
|
80
|
-
async runAuditAction(action) {
|
|
92
|
+
async runAuditAction(action, trxOrDb = this.db) {
|
|
81
93
|
switch (action) {
|
|
82
94
|
case 'check_schema_consistency':
|
|
83
95
|
const tables = await this.db.introspection.getTables();
|
|
@@ -93,7 +105,7 @@ export class SelfTestRegistry {
|
|
|
93
105
|
return missing.length === 0;
|
|
94
106
|
case 'check_memory_integrity':
|
|
95
107
|
const memoriesTable = this.config.memoriesTable || 'agent_memories';
|
|
96
|
-
const invalidMemories = await
|
|
108
|
+
const invalidMemories = await trxOrDb
|
|
97
109
|
.selectFrom(memoriesTable)
|
|
98
110
|
.select('id')
|
|
99
111
|
.where('embedding', 'is', null)
|
|
@@ -102,7 +114,7 @@ export class SelfTestRegistry {
|
|
|
102
114
|
case 'check_session_coherence':
|
|
103
115
|
const sessionsTable = this.config.sessionsTable || 'agent_sessions';
|
|
104
116
|
const messagesTable = this.config.messagesTable || 'agent_messages';
|
|
105
|
-
const emptySessions = await
|
|
117
|
+
const emptySessions = await trxOrDb
|
|
106
118
|
.selectFrom(sessionsTable)
|
|
107
119
|
.leftJoin(messagesTable, `${sessionsTable}.id`, `${messagesTable}.session_id`)
|
|
108
120
|
.select(`${sessionsTable}.id as sid`)
|
|
@@ -113,7 +125,7 @@ export class SelfTestRegistry {
|
|
|
113
125
|
const knowledgeTable = this.config.knowledgeTable || 'agent_knowledge_base';
|
|
114
126
|
const actionsTable = this.config.actionsTable || 'agent_actions';
|
|
115
127
|
const sessionsTbl = this.config.sessionsTable || 'agent_sessions';
|
|
116
|
-
const orphanedKnowledge = await
|
|
128
|
+
const orphanedKnowledge = await trxOrDb
|
|
117
129
|
.selectFrom(knowledgeTable)
|
|
118
130
|
.where('source_session_id', 'is not', null)
|
|
119
131
|
.where((eb) => eb.not(eb.exists(eb
|
|
@@ -121,7 +133,7 @@ export class SelfTestRegistry {
|
|
|
121
133
|
.select('id')
|
|
122
134
|
.whereRef(`${knowledgeTable}.source_session_id`, '=', `${sessionsTbl}.id`))))
|
|
123
135
|
.execute();
|
|
124
|
-
const orphanedActions = await
|
|
136
|
+
const orphanedActions = await trxOrDb
|
|
125
137
|
.selectFrom(actionsTable)
|
|
126
138
|
.where((eb) => eb.not(eb.exists(eb
|
|
127
139
|
.selectFrom(sessionsTbl)
|
|
@@ -131,7 +143,7 @@ export class SelfTestRegistry {
|
|
|
131
143
|
return orphanedKnowledge.length === 0 && orphanedActions.length === 0;
|
|
132
144
|
case 'check_performance_drift':
|
|
133
145
|
const metricsTbl = this.config.metricsTable || 'agent_metrics';
|
|
134
|
-
const recentMetrics = (await
|
|
146
|
+
const recentMetrics = (await trxOrDb
|
|
135
147
|
.selectFrom(metricsTbl)
|
|
136
148
|
.select('execution_time')
|
|
137
149
|
.orderBy('created_at', 'desc')
|
|
@@ -140,7 +152,7 @@ export class SelfTestRegistry {
|
|
|
140
152
|
if (recentMetrics.length < 5)
|
|
141
153
|
return true;
|
|
142
154
|
const avgRecent = recentMetrics.reduce((sum, m) => sum + (m.execution_time || 0), 0) / recentMetrics.length;
|
|
143
|
-
const baselineMetrics = (await
|
|
155
|
+
const baselineMetrics = (await trxOrDb
|
|
144
156
|
.selectFrom(metricsTbl)
|
|
145
157
|
.select('execution_time')
|
|
146
158
|
.orderBy('created_at', 'desc')
|
|
@@ -158,12 +170,12 @@ export class SelfTestRegistry {
|
|
|
158
170
|
/**
|
|
159
171
|
* Interpret custom probe logic by providing the LLM with relevant database snapshots.
|
|
160
172
|
*/
|
|
161
|
-
async dynamicEvaluation(probe) {
|
|
173
|
+
async dynamicEvaluation(probe, trxOrDb = this.db) {
|
|
162
174
|
const model = this.cortex.llmFast || this.cortex.llm;
|
|
163
175
|
if (!model)
|
|
164
176
|
return true; // Safety fallback if no AI is available
|
|
165
177
|
// Provide a small sample of metrics and actions to allow for semantic reasoning
|
|
166
|
-
const sampleMetrics = await
|
|
178
|
+
const sampleMetrics = await trxOrDb.selectFrom(this.config.metricsTable || 'agent_metrics').limit(10).execute();
|
|
167
179
|
const prompt = `
|
|
168
180
|
You are a Logic Verification Engine for NOORMME.
|
|
169
181
|
TESTRUN: "${probe.name}"
|
|
@@ -37,30 +37,30 @@ export declare class SovereignMetrics {
|
|
|
37
37
|
agentId?: string;
|
|
38
38
|
unit?: string;
|
|
39
39
|
metadata?: Record<string, any>;
|
|
40
|
-
}): Promise<AgentMetric>;
|
|
40
|
+
}, trxOrDb?: any): Promise<AgentMetric>;
|
|
41
41
|
/**
|
|
42
42
|
* Get average value of a metric over time
|
|
43
43
|
*/
|
|
44
|
-
getAverageMetric(metricName: string): Promise<number>;
|
|
44
|
+
getAverageMetric(metricName: string, trxOrDb?: any): Promise<number>;
|
|
45
45
|
/**
|
|
46
46
|
* Get comprehensive stats for a metric (min, max, avg, count).
|
|
47
47
|
*/
|
|
48
48
|
getMetricStats(metricName: string, options?: {
|
|
49
49
|
agentId?: string;
|
|
50
50
|
sessionId?: string | number;
|
|
51
|
-
}): Promise<MetricStats>;
|
|
51
|
+
}, trxOrDb?: any): Promise<MetricStats>;
|
|
52
52
|
/**
|
|
53
53
|
* Get recent metrics for analysis
|
|
54
54
|
*/
|
|
55
|
-
getRecentMetrics(limit?: number): Promise<AgentMetric[]>;
|
|
55
|
+
getRecentMetrics(limit?: number, trxOrDb?: any): Promise<AgentMetric[]>;
|
|
56
56
|
/**
|
|
57
57
|
* Get metrics filtered by agent ID.
|
|
58
58
|
*/
|
|
59
|
-
getMetricsByAgent(agentId: string, limit?: number): Promise<AgentMetric[]>;
|
|
59
|
+
getMetricsByAgent(agentId: string, limit?: number, trxOrDb?: any): Promise<AgentMetric[]>;
|
|
60
60
|
/**
|
|
61
61
|
* Get metrics filtered by session ID.
|
|
62
62
|
*/
|
|
63
|
-
getMetricsBySession(sessionId: string | number, limit?: number): Promise<AgentMetric[]>;
|
|
63
|
+
getMetricsBySession(sessionId: string | number, limit?: number, trxOrDb?: any): Promise<AgentMetric[]>;
|
|
64
64
|
private parseMetric;
|
|
65
65
|
}
|
|
66
66
|
export {};
|
|
@@ -18,8 +18,8 @@ export class SovereignMetrics {
|
|
|
18
18
|
/**
|
|
19
19
|
* Record a metric point
|
|
20
20
|
*/
|
|
21
|
-
async recordMetric(metricName, metricValue, options = {}) {
|
|
22
|
-
const metric = (await
|
|
21
|
+
async recordMetric(metricName, metricValue, options = {}, trxOrDb = this.db) {
|
|
22
|
+
const metric = (await trxOrDb
|
|
23
23
|
.insertInto(this.metricsTable)
|
|
24
24
|
.values({
|
|
25
25
|
session_id: options.sessionId ?? null,
|
|
@@ -37,8 +37,8 @@ export class SovereignMetrics {
|
|
|
37
37
|
/**
|
|
38
38
|
* Get average value of a metric over time
|
|
39
39
|
*/
|
|
40
|
-
async getAverageMetric(metricName) {
|
|
41
|
-
const result = await
|
|
40
|
+
async getAverageMetric(metricName, trxOrDb = this.db) {
|
|
41
|
+
const result = await trxOrDb
|
|
42
42
|
.selectFrom(this.metricsTable)
|
|
43
43
|
.select((eb) => eb.fn.avg('metric_value').as('avgValue'))
|
|
44
44
|
.where('metric_name', '=', metricName)
|
|
@@ -48,8 +48,8 @@ export class SovereignMetrics {
|
|
|
48
48
|
/**
|
|
49
49
|
* Get comprehensive stats for a metric (min, max, avg, count).
|
|
50
50
|
*/
|
|
51
|
-
async getMetricStats(metricName, options = {}) {
|
|
52
|
-
let query =
|
|
51
|
+
async getMetricStats(metricName, options = {}, trxOrDb = this.db) {
|
|
52
|
+
let query = trxOrDb
|
|
53
53
|
.selectFrom(this.metricsTable)
|
|
54
54
|
.select((eb) => [
|
|
55
55
|
eb.fn.min('metric_value').as('min'),
|
|
@@ -75,8 +75,8 @@ export class SovereignMetrics {
|
|
|
75
75
|
/**
|
|
76
76
|
* Get recent metrics for analysis
|
|
77
77
|
*/
|
|
78
|
-
async getRecentMetrics(limit = 50) {
|
|
79
|
-
const list = (await
|
|
78
|
+
async getRecentMetrics(limit = 50, trxOrDb = this.db) {
|
|
79
|
+
const list = (await trxOrDb
|
|
80
80
|
.selectFrom(this.metricsTable)
|
|
81
81
|
.selectAll()
|
|
82
82
|
.orderBy('created_at', 'desc')
|
|
@@ -87,8 +87,8 @@ export class SovereignMetrics {
|
|
|
87
87
|
/**
|
|
88
88
|
* Get metrics filtered by agent ID.
|
|
89
89
|
*/
|
|
90
|
-
async getMetricsByAgent(agentId, limit = 50) {
|
|
91
|
-
const list = (await
|
|
90
|
+
async getMetricsByAgent(agentId, limit = 50, trxOrDb = this.db) {
|
|
91
|
+
const list = (await trxOrDb
|
|
92
92
|
.selectFrom(this.metricsTable)
|
|
93
93
|
.selectAll()
|
|
94
94
|
.where('agent_id', '=', agentId)
|
|
@@ -100,8 +100,8 @@ export class SovereignMetrics {
|
|
|
100
100
|
/**
|
|
101
101
|
* Get metrics filtered by session ID.
|
|
102
102
|
*/
|
|
103
|
-
async getMetricsBySession(sessionId, limit = 50) {
|
|
104
|
-
const list = (await
|
|
103
|
+
async getMetricsBySession(sessionId, limit = 50, trxOrDb = this.db) {
|
|
104
|
+
const list = (await trxOrDb
|
|
105
105
|
.selectFrom(this.metricsTable)
|
|
106
106
|
.selectAll()
|
|
107
107
|
.where('session_id', '=', sessionId)
|
|
@@ -1,28 +1,6 @@
|
|
|
1
1
|
import type { Kysely } from '../../kysely.js';
|
|
2
2
|
import type { AgenticConfig, AgentPersona } from '../../types/index.js';
|
|
3
3
|
import type { Cortex } from '../Cortex.js';
|
|
4
|
-
interface PersonaTable {
|
|
5
|
-
id: number | string;
|
|
6
|
-
name: string;
|
|
7
|
-
role: string | null;
|
|
8
|
-
capabilities: string | null;
|
|
9
|
-
policies: string | null;
|
|
10
|
-
metadata: string | null;
|
|
11
|
-
created_at: string | Date;
|
|
12
|
-
updated_at: string | Date;
|
|
13
|
-
}
|
|
14
|
-
export interface MetricTable {
|
|
15
|
-
id: number | string;
|
|
16
|
-
metric_name: string;
|
|
17
|
-
metric_value: number;
|
|
18
|
-
unit: string | null;
|
|
19
|
-
metadata: string | null;
|
|
20
|
-
created_at: string | Date;
|
|
21
|
-
}
|
|
22
|
-
export interface StrategyDatabase {
|
|
23
|
-
agent_personas: PersonaTable;
|
|
24
|
-
agent_metrics: MetricTable;
|
|
25
|
-
}
|
|
26
4
|
export interface PerformanceReport {
|
|
27
5
|
personaId: string | number;
|
|
28
6
|
successRate: number;
|
|
@@ -30,14 +8,6 @@ export interface PerformanceReport {
|
|
|
30
8
|
sampleSize: number;
|
|
31
9
|
recommendation: 'maintain' | 'optimize_efficiency' | 'optimize_accuracy' | 'critical_intervention';
|
|
32
10
|
}
|
|
33
|
-
export interface PersonaMutation {
|
|
34
|
-
id: string;
|
|
35
|
-
timestamp: number;
|
|
36
|
-
type: 'role_update' | 'policy_update' | 'capability_update';
|
|
37
|
-
previousState: Partial<AgentPersona>;
|
|
38
|
-
newState: Partial<AgentPersona>;
|
|
39
|
-
reason: string;
|
|
40
|
-
}
|
|
41
11
|
/**
|
|
42
12
|
* StrategicPlanner proactively suggests mutation to agent personas
|
|
43
13
|
* based on performance trends observed in SovereignMetrics.
|
|
@@ -48,40 +18,26 @@ export declare class StrategicPlanner {
|
|
|
48
18
|
private config;
|
|
49
19
|
private personasTable;
|
|
50
20
|
private metricsTable;
|
|
21
|
+
private analyst;
|
|
22
|
+
private engine;
|
|
23
|
+
private verificator;
|
|
51
24
|
constructor(db: Kysely<any>, cortex: Cortex, config?: AgenticConfig);
|
|
52
|
-
private get typedDb();
|
|
53
25
|
/**
|
|
54
26
|
* Analyze performance for all personas and apply mutations where necessary.
|
|
55
27
|
*/
|
|
56
|
-
mutateStrategy(): Promise<string[]>;
|
|
57
|
-
/**
|
|
58
|
-
* Directly mutate a persona and put it into 'verifying' status.
|
|
59
|
-
* Performs a pre-flight conflict check and injects distilled lessons.
|
|
60
|
-
*/
|
|
61
|
-
private applyDirectMutation;
|
|
28
|
+
mutateStrategy(trxOrDb?: any): Promise<string[]>;
|
|
62
29
|
/**
|
|
63
|
-
*
|
|
64
|
-
* Uses dynamic statistical variance and adaptive meta-tuning.
|
|
30
|
+
* Directly mutate a persona.
|
|
65
31
|
*/
|
|
66
|
-
|
|
32
|
+
evolvePersona(persona: AgentPersona, report: PerformanceReport, trxOrDb?: any): Promise<string | null>;
|
|
67
33
|
/**
|
|
68
|
-
*
|
|
69
|
-
*/
|
|
70
|
-
private analyzeFailurePatterns;
|
|
71
|
-
/**
|
|
72
|
-
* Generate a performance report for a specific persona.
|
|
73
|
-
* Uses dynamic satisfaction thresholds based on global population stats (Phase 6).
|
|
74
|
-
*/
|
|
75
|
-
analyzePersona(id: string | number): Promise<PerformanceReport>;
|
|
76
|
-
/**
|
|
77
|
-
* Evolve a persona directly based on performance.
|
|
34
|
+
* Revert the last mutation for a persona.
|
|
78
35
|
*/
|
|
79
|
-
|
|
36
|
+
rollbackPersona(id: string | number, trxOrDb?: any): Promise<string>;
|
|
80
37
|
/**
|
|
81
|
-
*
|
|
38
|
+
* Analyze a persona's performance report.
|
|
82
39
|
*/
|
|
83
|
-
|
|
40
|
+
analyzePersona(id: string | number, trxOrDb?: any): Promise<PerformanceReport>;
|
|
84
41
|
private sanitizeRole;
|
|
85
42
|
private parsePersona;
|
|
86
43
|
}
|
|
87
|
-
export {};
|