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
|
@@ -44,8 +44,8 @@ class RecursiveReasoner {
|
|
|
44
44
|
/**
|
|
45
45
|
* Find goals matching a pattern across all sessions
|
|
46
46
|
*/
|
|
47
|
-
async analyzeGlobalProgress(pattern) {
|
|
48
|
-
const goals = (await
|
|
47
|
+
async analyzeGlobalProgress(pattern, trxOrDb = this.db) {
|
|
48
|
+
const goals = (await trxOrDb
|
|
49
49
|
.selectFrom(this.goalsTable)
|
|
50
50
|
.selectAll()
|
|
51
51
|
.where('description', 'like', `%${pattern}%`)
|
|
@@ -57,10 +57,10 @@ class RecursiveReasoner {
|
|
|
57
57
|
* Synthesize high-level lessons and cluster similar ones using Token-Weighted significance.
|
|
58
58
|
* Pass 5: High-Throughput Semantic Analysis.
|
|
59
59
|
*/
|
|
60
|
-
async synthesizeLessons() {
|
|
60
|
+
async synthesizeLessons(trxOrDb = this.db) {
|
|
61
61
|
console.log('[RecursiveReasoner] Performing high-throughput weighted token clustering...');
|
|
62
62
|
const reflectionsTable = this.config.reflectionsTable || 'agent_reflections';
|
|
63
|
-
const results = (await
|
|
63
|
+
const results = (await trxOrDb
|
|
64
64
|
.selectFrom(reflectionsTable)
|
|
65
65
|
.select('lessons_learned')
|
|
66
66
|
.where('lessons_learned', 'is not', null)
|
|
@@ -100,12 +100,12 @@ class RecursiveReasoner {
|
|
|
100
100
|
* Pass 6: Goal Cross-Pollination
|
|
101
101
|
* Distill successful persona mutations into global systemic goals.
|
|
102
102
|
*/
|
|
103
|
-
async crossPollinateGoals() {
|
|
103
|
+
async crossPollinateGoals(trxOrDb = this.db) {
|
|
104
104
|
console.log('[RecursiveReasoner] Cross-pollinating successful persona breakthroughs into global goals...');
|
|
105
105
|
const personasTable = this.config.personasTable || 'agent_personas';
|
|
106
106
|
const goalsTable = this.config.goalsTable || 'agent_goals';
|
|
107
107
|
// Find personas with 'stable' evolution status (proven breakthroughs)
|
|
108
|
-
const breakthroughs = await
|
|
108
|
+
const breakthroughs = await trxOrDb
|
|
109
109
|
.selectFrom(personasTable)
|
|
110
110
|
.selectAll()
|
|
111
111
|
.where('metadata', 'like', '%"evolution_status":"stable"%')
|
|
@@ -120,7 +120,7 @@ class RecursiveReasoner {
|
|
|
120
120
|
.filter(Boolean);
|
|
121
121
|
if (descriptions.length === 0)
|
|
122
122
|
return 0;
|
|
123
|
-
const existingGoals = await
|
|
123
|
+
const existingGoals = await trxOrDb
|
|
124
124
|
.selectFrom(goalsTable)
|
|
125
125
|
.select('description')
|
|
126
126
|
.where('description', 'in', descriptions)
|
|
@@ -130,7 +130,7 @@ class RecursiveReasoner {
|
|
|
130
130
|
for (const desc of descriptions) {
|
|
131
131
|
if (!existingSet.has(desc)) {
|
|
132
132
|
console.log(`[RecursiveReasoner] Distilling breakthrough into Global Goal: ${desc.slice(0, 50)}...`);
|
|
133
|
-
await
|
|
133
|
+
await trxOrDb
|
|
134
134
|
.insertInto(goalsTable)
|
|
135
135
|
.values({
|
|
136
136
|
session_id: 0, // System-level goal
|
|
@@ -152,9 +152,9 @@ class RecursiveReasoner {
|
|
|
152
152
|
/**
|
|
153
153
|
* Detect contradictions in goals (e.g., opposing objectives).
|
|
154
154
|
*/
|
|
155
|
-
async detectContradictions() {
|
|
155
|
+
async detectContradictions(trxOrDb = this.db) {
|
|
156
156
|
console.log('[RecursiveReasoner] Detecting logical contradictions in systemic goals...');
|
|
157
|
-
const activeGoals = (await
|
|
157
|
+
const activeGoals = (await trxOrDb
|
|
158
158
|
.selectFrom(this.goalsTable)
|
|
159
159
|
.selectAll()
|
|
160
160
|
.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
|
*/
|
|
@@ -17,8 +17,8 @@ class ReflectionEngine {
|
|
|
17
17
|
/**
|
|
18
18
|
* Record a reflection for a session
|
|
19
19
|
*/
|
|
20
|
-
async reflect(sessionId, outcome, lessonsLearned, suggestedActions, metadata) {
|
|
21
|
-
const reflection = (await
|
|
20
|
+
async reflect(sessionId, outcome, lessonsLearned, suggestedActions, metadata, trxOrDb = this.db) {
|
|
21
|
+
const reflection = (await trxOrDb
|
|
22
22
|
.insertInto(this.reflectionsTable)
|
|
23
23
|
.values({
|
|
24
24
|
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
|
*/
|
|
@@ -39,10 +39,10 @@ class RitualOrchestrator {
|
|
|
39
39
|
/**
|
|
40
40
|
* Run all pending rituals that are due
|
|
41
41
|
*/
|
|
42
|
-
async runPendingRituals() {
|
|
42
|
+
async runPendingRituals(trxOrDb = this.db) {
|
|
43
43
|
const now = new Date();
|
|
44
44
|
const lockTimeout = new Date(now.getTime() + 600000); // 10 min lock by default
|
|
45
|
-
const
|
|
45
|
+
const runner = async (trx) => {
|
|
46
46
|
const due = (await trx
|
|
47
47
|
.selectFrom(this.ritualsTable)
|
|
48
48
|
.selectAll()
|
|
@@ -64,20 +64,23 @@ class RitualOrchestrator {
|
|
|
64
64
|
.execute();
|
|
65
65
|
}
|
|
66
66
|
return due;
|
|
67
|
-
}
|
|
67
|
+
};
|
|
68
|
+
const pending = (trxOrDb !== this.db)
|
|
69
|
+
? await runner(trxOrDb)
|
|
70
|
+
: await this.db.transaction().execute(runner);
|
|
68
71
|
if (pending.length === 0)
|
|
69
72
|
return 0;
|
|
70
73
|
console.log(`[RitualOrchestrator] Found ${pending.length} pending rituals due. Locking for execution...`);
|
|
71
74
|
for (const ritual of pending) {
|
|
72
|
-
// Execute
|
|
73
|
-
await this.executeRitual(ritual);
|
|
75
|
+
// Execute with the same trxOrDb context
|
|
76
|
+
await this.executeRitual(ritual, trxOrDb);
|
|
74
77
|
}
|
|
75
78
|
return pending.length;
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
78
81
|
* Execute a specific ritual
|
|
79
82
|
*/
|
|
80
|
-
async executeRitual(ritual) {
|
|
83
|
+
async executeRitual(ritual, trxOrDb = this.db) {
|
|
81
84
|
console.log(`[RitualOrchestrator] Executing ritual: ${ritual.name} (${ritual.type})`);
|
|
82
85
|
const ritualMetadata = {
|
|
83
86
|
...ritual.metadata,
|
|
@@ -94,7 +97,7 @@ class RitualOrchestrator {
|
|
|
94
97
|
let offset = 0;
|
|
95
98
|
const batchSize = 100; // Audit Phase 17: Paginated session processing
|
|
96
99
|
while (true) {
|
|
97
|
-
const activeSessions = await
|
|
100
|
+
const activeSessions = await trxOrDb
|
|
98
101
|
.selectFrom(sessionsTable)
|
|
99
102
|
.select('id')
|
|
100
103
|
.where('status', '=', 'active')
|
|
@@ -104,7 +107,7 @@ class RitualOrchestrator {
|
|
|
104
107
|
if (activeSessions.length === 0)
|
|
105
108
|
break;
|
|
106
109
|
for (const session of activeSessions) {
|
|
107
|
-
const countResult = (await
|
|
110
|
+
const countResult = (await trxOrDb
|
|
108
111
|
.selectFrom(messagesTable)
|
|
109
112
|
.select((eb) => eb.fn.countAll().as('count'))
|
|
110
113
|
.where('session_id', '=', session.id)
|
|
@@ -152,7 +155,7 @@ class RitualOrchestrator {
|
|
|
152
155
|
// Update ritual status, unlock, and schedule next run
|
|
153
156
|
const frequency = ritual.frequency || 'daily';
|
|
154
157
|
const nextRun = this.calculateNextRun(frequency, success ? 0 : ritualMetadata.failureCount);
|
|
155
|
-
await
|
|
158
|
+
await trxOrDb
|
|
156
159
|
.updateTable(this.ritualsTable)
|
|
157
160
|
.set({
|
|
158
161
|
status: success ? 'success' : 'failure',
|
|
@@ -61,28 +61,27 @@ class SelfEvolution {
|
|
|
61
61
|
* Ensure core agentic tables have telemetry columns like 'accessed_at'
|
|
62
62
|
*/
|
|
63
63
|
async ensureTelemetryColumns() {
|
|
64
|
-
const
|
|
64
|
+
const tableNames = [
|
|
65
65
|
this.config.agentic?.sessionsTable || 'agent_sessions',
|
|
66
66
|
this.config.agentic?.messagesTable || 'agent_messages',
|
|
67
67
|
this.config.agentic?.memoriesTable || 'agent_memories',
|
|
68
68
|
this.config.agentic?.goalsTable || 'agent_goals',
|
|
69
69
|
this.config.agentic?.knowledgeTable || 'agent_knowledge_base',
|
|
70
70
|
];
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.then((ts) => ts.find((t) => t.name === table));
|
|
71
|
+
try {
|
|
72
|
+
const introspector = this.db.introspection;
|
|
73
|
+
const allTables = await introspector.getTables();
|
|
74
|
+
for (const tableName of tableNames) {
|
|
75
|
+
const tableInfo = allTables.find((t) => t.name === tableName);
|
|
77
76
|
if (tableInfo &&
|
|
78
77
|
!tableInfo.columns.some((c) => c.name === 'accessed_at')) {
|
|
79
|
-
console.log(`[SelfEvolution] Adding 'accessed_at' column to ${
|
|
80
|
-
await (0, sql_js_1.sql) `ALTER TABLE ${sql_js_1.sql.table(
|
|
78
|
+
console.log(`[SelfEvolution] Adding 'accessed_at' column to ${tableName}`);
|
|
79
|
+
await (0, sql_js_1.sql) `ALTER TABLE ${sql_js_1.sql.table(tableName)} ADD COLUMN accessed_at TIMESTAMP`.execute(this.db);
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
console.warn(`[SelfEvolution] Failed to add telemetry columns:`, e);
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
/**
|
|
@@ -133,12 +132,10 @@ class SelfEvolution {
|
|
|
133
132
|
/**
|
|
134
133
|
* Apply a schema suggestion and instantly regenerate types
|
|
135
134
|
*/
|
|
136
|
-
async evolve(ddl, options = {}) {
|
|
135
|
+
async evolve(ddl, options = {}, trxOrDb = this.db) {
|
|
137
136
|
console.log(`[SelfEvolution] Applying structural change: ${ddl}`);
|
|
138
|
-
|
|
137
|
+
const runner = async (trx) => {
|
|
139
138
|
// 1. Apply the DDL change
|
|
140
|
-
// Pass transaction to evolution helper if it supports it,
|
|
141
|
-
// otherwise use trx.execute() directly for the DDL
|
|
142
139
|
await trx.execute(sql_js_1.sql.raw(ddl));
|
|
143
140
|
// 1b. Log for potential rollback
|
|
144
141
|
await trx
|
|
@@ -155,7 +152,13 @@ class SelfEvolution {
|
|
|
155
152
|
created_at: new Date(),
|
|
156
153
|
})
|
|
157
154
|
.execute();
|
|
158
|
-
}
|
|
155
|
+
};
|
|
156
|
+
if (trxOrDb && trxOrDb !== this.db) {
|
|
157
|
+
await runner(trxOrDb);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
await this.db.transaction().execute(runner);
|
|
161
|
+
}
|
|
159
162
|
// 2. Regenerate types
|
|
160
163
|
await this.regenerateTypes();
|
|
161
164
|
console.log(`[SelfEvolution] Schema evolved successfully.`);
|
|
@@ -274,7 +277,7 @@ class SelfEvolution {
|
|
|
274
277
|
return `ALTER TABLE ${addColumnMatch[1]} DROP COLUMN ${addColumnMatch[2]}`;
|
|
275
278
|
}
|
|
276
279
|
// Match patterns like: ALTER TABLE "table_name" DROP [COLUMN] "column_name"
|
|
277
|
-
const dropColumnMatch = d.match(/ALTER TABLE\s+([^\s]+)\s+DROP\s+(?:COLUMN\s+)?([^\s\(\)]+)/i);
|
|
280
|
+
const dropColumnMatch = d.match(/ALTER TABLE\s+([^\s]+)\s+DROP\s+(?:COLUMN\s+)?([^\s\(\)]+)\s+([^\s]+)/i);
|
|
278
281
|
if (dropColumnMatch) {
|
|
279
282
|
// Note: Data is lost, but we can restore the structure
|
|
280
283
|
return `ALTER TABLE ${dropColumnMatch[1]} ADD COLUMN ${dropColumnMatch[2]} TEXT`; // Default to TEXT if unknown
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SelfTestRegistry = void 0;
|
|
4
|
+
const db_utils_js_1 = require("../util/db-utils.js");
|
|
4
5
|
/**
|
|
5
6
|
* SelfTestRegistry allows agents to self-register verification probes
|
|
6
7
|
* that ensure autonomous changes don't violate core logic.
|
|
@@ -36,8 +37,8 @@ class SelfTestRegistry {
|
|
|
36
37
|
/**
|
|
37
38
|
* Run all registered probes
|
|
38
39
|
*/
|
|
39
|
-
async runAllProbes() {
|
|
40
|
-
const probes = (await
|
|
40
|
+
async runAllProbes(trxOrDb = this.db) {
|
|
41
|
+
const probes = (await trxOrDb
|
|
41
42
|
.selectFrom('agent_logic_probes')
|
|
42
43
|
.selectAll()
|
|
43
44
|
.execute());
|
|
@@ -47,22 +48,21 @@ class SelfTestRegistry {
|
|
|
47
48
|
try {
|
|
48
49
|
let success = false;
|
|
49
50
|
if (probe.script.startsWith('audit:')) {
|
|
50
|
-
success = await this.runAuditAction(probe.script.split(':')[1]);
|
|
51
|
+
success = await this.runAuditAction(probe.script.split(':')[1], trxOrDb);
|
|
51
52
|
}
|
|
52
53
|
else {
|
|
53
54
|
// Master Sentinel Pass: Dynamic Probe Evaluation
|
|
54
55
|
// If not a hardcoded audit, use LLM to interpret the script against DB state
|
|
55
|
-
success = await this.dynamicEvaluation(probe);
|
|
56
|
+
success = await this.dynamicEvaluation(probe, trxOrDb);
|
|
56
57
|
}
|
|
57
58
|
results.push({ name: probe.name, success });
|
|
58
|
-
|
|
59
|
+
const updateRunner = async (trx) => {
|
|
59
60
|
// Audit Phase 13: Lock row before updating last_status
|
|
60
|
-
|
|
61
|
+
const query = trx
|
|
61
62
|
.selectFrom('agent_logic_probes')
|
|
62
63
|
.select('id')
|
|
63
|
-
.where('id', '=', probe.id)
|
|
64
|
-
|
|
65
|
-
.executeTakeFirst();
|
|
64
|
+
.where('id', '=', probe.id);
|
|
65
|
+
await (0, db_utils_js_1.withLock)(query, trx).executeTakeFirst();
|
|
66
66
|
await trx
|
|
67
67
|
.updateTable('agent_logic_probes')
|
|
68
68
|
.set({
|
|
@@ -71,7 +71,15 @@ class SelfTestRegistry {
|
|
|
71
71
|
})
|
|
72
72
|
.where('id', '=', probe.id)
|
|
73
73
|
.execute();
|
|
74
|
-
}
|
|
74
|
+
};
|
|
75
|
+
if (trxOrDb && trxOrDb !== this.db) {
|
|
76
|
+
await updateRunner(trxOrDb);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
await this.db.transaction().execute(async (trx) => {
|
|
80
|
+
await updateRunner(trx);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
75
83
|
}
|
|
76
84
|
catch (e) {
|
|
77
85
|
results.push({ name: probe.name, success: false, error: String(e) });
|
|
@@ -79,7 +87,7 @@ class SelfTestRegistry {
|
|
|
79
87
|
}
|
|
80
88
|
return results;
|
|
81
89
|
}
|
|
82
|
-
async runAuditAction(action) {
|
|
90
|
+
async runAuditAction(action, trxOrDb = this.db) {
|
|
83
91
|
switch (action) {
|
|
84
92
|
case 'check_schema_consistency':
|
|
85
93
|
const tables = await this.db.introspection.getTables();
|
|
@@ -95,7 +103,7 @@ class SelfTestRegistry {
|
|
|
95
103
|
return missing.length === 0;
|
|
96
104
|
case 'check_memory_integrity':
|
|
97
105
|
const memoriesTable = this.config.memoriesTable || 'agent_memories';
|
|
98
|
-
const invalidMemories = await
|
|
106
|
+
const invalidMemories = await trxOrDb
|
|
99
107
|
.selectFrom(memoriesTable)
|
|
100
108
|
.select('id')
|
|
101
109
|
.where('embedding', 'is', null)
|
|
@@ -104,7 +112,7 @@ class SelfTestRegistry {
|
|
|
104
112
|
case 'check_session_coherence':
|
|
105
113
|
const sessionsTable = this.config.sessionsTable || 'agent_sessions';
|
|
106
114
|
const messagesTable = this.config.messagesTable || 'agent_messages';
|
|
107
|
-
const emptySessions = await
|
|
115
|
+
const emptySessions = await trxOrDb
|
|
108
116
|
.selectFrom(sessionsTable)
|
|
109
117
|
.leftJoin(messagesTable, `${sessionsTable}.id`, `${messagesTable}.session_id`)
|
|
110
118
|
.select(`${sessionsTable}.id as sid`)
|
|
@@ -115,7 +123,7 @@ class SelfTestRegistry {
|
|
|
115
123
|
const knowledgeTable = this.config.knowledgeTable || 'agent_knowledge_base';
|
|
116
124
|
const actionsTable = this.config.actionsTable || 'agent_actions';
|
|
117
125
|
const sessionsTbl = this.config.sessionsTable || 'agent_sessions';
|
|
118
|
-
const orphanedKnowledge = await
|
|
126
|
+
const orphanedKnowledge = await trxOrDb
|
|
119
127
|
.selectFrom(knowledgeTable)
|
|
120
128
|
.where('source_session_id', 'is not', null)
|
|
121
129
|
.where((eb) => eb.not(eb.exists(eb
|
|
@@ -123,7 +131,7 @@ class SelfTestRegistry {
|
|
|
123
131
|
.select('id')
|
|
124
132
|
.whereRef(`${knowledgeTable}.source_session_id`, '=', `${sessionsTbl}.id`))))
|
|
125
133
|
.execute();
|
|
126
|
-
const orphanedActions = await
|
|
134
|
+
const orphanedActions = await trxOrDb
|
|
127
135
|
.selectFrom(actionsTable)
|
|
128
136
|
.where((eb) => eb.not(eb.exists(eb
|
|
129
137
|
.selectFrom(sessionsTbl)
|
|
@@ -133,7 +141,7 @@ class SelfTestRegistry {
|
|
|
133
141
|
return orphanedKnowledge.length === 0 && orphanedActions.length === 0;
|
|
134
142
|
case 'check_performance_drift':
|
|
135
143
|
const metricsTbl = this.config.metricsTable || 'agent_metrics';
|
|
136
|
-
const recentMetrics = (await
|
|
144
|
+
const recentMetrics = (await trxOrDb
|
|
137
145
|
.selectFrom(metricsTbl)
|
|
138
146
|
.select('execution_time')
|
|
139
147
|
.orderBy('created_at', 'desc')
|
|
@@ -142,7 +150,7 @@ class SelfTestRegistry {
|
|
|
142
150
|
if (recentMetrics.length < 5)
|
|
143
151
|
return true;
|
|
144
152
|
const avgRecent = recentMetrics.reduce((sum, m) => sum + (m.execution_time || 0), 0) / recentMetrics.length;
|
|
145
|
-
const baselineMetrics = (await
|
|
153
|
+
const baselineMetrics = (await trxOrDb
|
|
146
154
|
.selectFrom(metricsTbl)
|
|
147
155
|
.select('execution_time')
|
|
148
156
|
.orderBy('created_at', 'desc')
|
|
@@ -160,12 +168,12 @@ class SelfTestRegistry {
|
|
|
160
168
|
/**
|
|
161
169
|
* Interpret custom probe logic by providing the LLM with relevant database snapshots.
|
|
162
170
|
*/
|
|
163
|
-
async dynamicEvaluation(probe) {
|
|
171
|
+
async dynamicEvaluation(probe, trxOrDb = this.db) {
|
|
164
172
|
const model = this.cortex.llmFast || this.cortex.llm;
|
|
165
173
|
if (!model)
|
|
166
174
|
return true; // Safety fallback if no AI is available
|
|
167
175
|
// Provide a small sample of metrics and actions to allow for semantic reasoning
|
|
168
|
-
const sampleMetrics = await
|
|
176
|
+
const sampleMetrics = await trxOrDb.selectFrom(this.config.metricsTable || 'agent_metrics').limit(10).execute();
|
|
169
177
|
const prompt = `
|
|
170
178
|
You are a Logic Verification Engine for NOORMME.
|
|
171
179
|
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 {};
|
|
@@ -20,8 +20,8 @@ class SovereignMetrics {
|
|
|
20
20
|
/**
|
|
21
21
|
* Record a metric point
|
|
22
22
|
*/
|
|
23
|
-
async recordMetric(metricName, metricValue, options = {}) {
|
|
24
|
-
const metric = (await
|
|
23
|
+
async recordMetric(metricName, metricValue, options = {}, trxOrDb = this.db) {
|
|
24
|
+
const metric = (await trxOrDb
|
|
25
25
|
.insertInto(this.metricsTable)
|
|
26
26
|
.values({
|
|
27
27
|
session_id: options.sessionId ?? null,
|
|
@@ -39,8 +39,8 @@ class SovereignMetrics {
|
|
|
39
39
|
/**
|
|
40
40
|
* Get average value of a metric over time
|
|
41
41
|
*/
|
|
42
|
-
async getAverageMetric(metricName) {
|
|
43
|
-
const result = await
|
|
42
|
+
async getAverageMetric(metricName, trxOrDb = this.db) {
|
|
43
|
+
const result = await trxOrDb
|
|
44
44
|
.selectFrom(this.metricsTable)
|
|
45
45
|
.select((eb) => eb.fn.avg('metric_value').as('avgValue'))
|
|
46
46
|
.where('metric_name', '=', metricName)
|
|
@@ -50,8 +50,8 @@ class SovereignMetrics {
|
|
|
50
50
|
/**
|
|
51
51
|
* Get comprehensive stats for a metric (min, max, avg, count).
|
|
52
52
|
*/
|
|
53
|
-
async getMetricStats(metricName, options = {}) {
|
|
54
|
-
let query =
|
|
53
|
+
async getMetricStats(metricName, options = {}, trxOrDb = this.db) {
|
|
54
|
+
let query = trxOrDb
|
|
55
55
|
.selectFrom(this.metricsTable)
|
|
56
56
|
.select((eb) => [
|
|
57
57
|
eb.fn.min('metric_value').as('min'),
|
|
@@ -77,8 +77,8 @@ class SovereignMetrics {
|
|
|
77
77
|
/**
|
|
78
78
|
* Get recent metrics for analysis
|
|
79
79
|
*/
|
|
80
|
-
async getRecentMetrics(limit = 50) {
|
|
81
|
-
const list = (await
|
|
80
|
+
async getRecentMetrics(limit = 50, trxOrDb = this.db) {
|
|
81
|
+
const list = (await trxOrDb
|
|
82
82
|
.selectFrom(this.metricsTable)
|
|
83
83
|
.selectAll()
|
|
84
84
|
.orderBy('created_at', 'desc')
|
|
@@ -89,8 +89,8 @@ class SovereignMetrics {
|
|
|
89
89
|
/**
|
|
90
90
|
* Get metrics filtered by agent ID.
|
|
91
91
|
*/
|
|
92
|
-
async getMetricsByAgent(agentId, limit = 50) {
|
|
93
|
-
const list = (await
|
|
92
|
+
async getMetricsByAgent(agentId, limit = 50, trxOrDb = this.db) {
|
|
93
|
+
const list = (await trxOrDb
|
|
94
94
|
.selectFrom(this.metricsTable)
|
|
95
95
|
.selectAll()
|
|
96
96
|
.where('agent_id', '=', agentId)
|
|
@@ -102,8 +102,8 @@ class SovereignMetrics {
|
|
|
102
102
|
/**
|
|
103
103
|
* Get metrics filtered by session ID.
|
|
104
104
|
*/
|
|
105
|
-
async getMetricsBySession(sessionId, limit = 50) {
|
|
106
|
-
const list = (await
|
|
105
|
+
async getMetricsBySession(sessionId, limit = 50, trxOrDb = this.db) {
|
|
106
|
+
const list = (await trxOrDb
|
|
107
107
|
.selectFrom(this.metricsTable)
|
|
108
108
|
.selectAll()
|
|
109
109
|
.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 {};
|