noormme 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -6
- package/dist/cjs/agentic/ActionJournal.d.ts +5 -2
- package/dist/cjs/agentic/ActionJournal.js +13 -5
- package/dist/cjs/agentic/CapabilityManager.d.ts +7 -0
- package/dist/cjs/agentic/CapabilityManager.js +84 -7
- package/dist/cjs/agentic/CognitiveRepository.js +3 -6
- package/dist/cjs/agentic/Cortex.d.ts +4 -0
- package/dist/cjs/agentic/Cortex.js +38 -17
- package/dist/cjs/agentic/EpisodicMemory.d.ts +5 -1
- package/dist/cjs/agentic/EpisodicMemory.js +11 -4
- package/dist/cjs/agentic/PersonaManager.js +37 -31
- package/dist/cjs/agentic/PolicyEnforcer.d.ts +6 -1
- package/dist/cjs/agentic/PolicyEnforcer.js +74 -17
- package/dist/cjs/agentic/ResourceMonitor.d.ts +9 -0
- package/dist/cjs/agentic/ResourceMonitor.js +36 -2
- package/dist/cjs/agentic/SessionManager.js +24 -17
- package/dist/cjs/agentic/VectorIndexer.d.ts +1 -0
- package/dist/cjs/agentic/VectorIndexer.js +26 -17
- package/dist/cjs/agentic/improvement/AblationEngine.d.ts +4 -6
- package/dist/cjs/agentic/improvement/AblationEngine.js +57 -37
- package/dist/cjs/agentic/improvement/ActionRefiner.js +30 -14
- package/dist/cjs/agentic/improvement/ConflictResolver.d.ts +3 -1
- package/dist/cjs/agentic/improvement/ConflictResolver.js +59 -47
- package/dist/cjs/agentic/improvement/CortexJanitor.js +11 -0
- package/dist/cjs/agentic/improvement/CuriosityEngine.d.ts +1 -1
- package/dist/cjs/agentic/improvement/CuriosityEngine.js +48 -21
- package/dist/cjs/agentic/improvement/EvolutionRitual.js +26 -14
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.js +16 -4
- package/dist/cjs/agentic/improvement/GoalArchitect.d.ts +6 -2
- package/dist/cjs/agentic/improvement/GoalArchitect.js +72 -34
- package/dist/cjs/agentic/improvement/GovernanceManager.d.ts +20 -6
- package/dist/cjs/agentic/improvement/GovernanceManager.js +134 -155
- package/dist/cjs/agentic/improvement/HiveLink.d.ts +7 -3
- package/dist/cjs/agentic/improvement/HiveLink.js +135 -113
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.js +43 -35
- package/dist/cjs/agentic/improvement/QuotaManager.d.ts +41 -0
- package/dist/cjs/agentic/improvement/QuotaManager.js +185 -0
- package/dist/cjs/agentic/improvement/RecursiveReasoner.js +50 -25
- package/dist/cjs/agentic/improvement/ReflectionEngine.d.ts +4 -1
- package/dist/cjs/agentic/improvement/ReflectionEngine.js +3 -1
- package/dist/cjs/agentic/improvement/RitualOrchestrator.js +27 -16
- package/dist/cjs/agentic/improvement/RuleEngine.d.ts +1 -1
- package/dist/cjs/agentic/improvement/RuleEngine.js +10 -4
- package/dist/cjs/agentic/improvement/SelfEvolution.js +22 -17
- package/dist/cjs/agentic/improvement/SelfTestRegistry.d.ts +5 -0
- package/dist/cjs/agentic/improvement/SelfTestRegistry.js +129 -109
- package/dist/cjs/agentic/improvement/SkillSynthesizer.d.ts +1 -0
- package/dist/cjs/agentic/improvement/SkillSynthesizer.js +22 -13
- package/dist/cjs/agentic/improvement/StrategicPlanner.d.ts +1 -0
- package/dist/cjs/agentic/improvement/StrategicPlanner.js +26 -19
- package/dist/cjs/agentic/improvement/governance/AuditContext.d.ts +17 -0
- package/dist/cjs/agentic/improvement/governance/AuditContext.js +2 -0
- package/dist/cjs/agentic/improvement/governance/BudgetAuditor.d.ts +4 -0
- package/dist/cjs/agentic/improvement/governance/BudgetAuditor.js +50 -0
- package/dist/cjs/agentic/improvement/governance/EmergenceAuditor.d.ts +4 -0
- package/dist/cjs/agentic/improvement/governance/EmergenceAuditor.js +37 -0
- package/dist/cjs/agentic/improvement/governance/MaintenanceOracle.d.ts +4 -0
- package/dist/cjs/agentic/improvement/governance/MaintenanceOracle.js +67 -0
- package/dist/cjs/agentic/improvement/governance/PerformanceAuditor.d.ts +4 -0
- package/dist/cjs/agentic/improvement/governance/PerformanceAuditor.js +43 -0
- package/dist/cjs/agentic/improvement/governance/PersonaAuditor.d.ts +6 -0
- package/dist/cjs/agentic/improvement/governance/PersonaAuditor.js +74 -0
- package/dist/cjs/agentic/improvement/governance/RemediationEngine.d.ts +5 -0
- package/dist/cjs/agentic/improvement/governance/RemediationEngine.js +43 -0
- package/dist/cjs/agentic/improvement/governance/SkillAuditor.d.ts +5 -0
- package/dist/cjs/agentic/improvement/governance/SkillAuditor.js +52 -0
- package/dist/cjs/agentic/telemetry/CognitiveSynthesizer.d.ts +5 -0
- package/dist/cjs/agentic/telemetry/CognitiveSynthesizer.js +54 -12
- package/dist/cjs/agentic/telemetry/EventHarvester.d.ts +1 -1
- package/dist/cjs/agentic/telemetry/EventHarvester.js +10 -3
- package/dist/cjs/agentic/telemetry/ResearchAlchemist.d.ts +7 -2
- package/dist/cjs/agentic/telemetry/ResearchAlchemist.js +49 -8
- package/dist/cjs/agentic/telemetry/TelemetryOrchestrator.d.ts +4 -1
- package/dist/cjs/agentic/telemetry/TelemetryOrchestrator.js +38 -11
- package/dist/cjs/cli/commands/inspect.js +40 -1
- package/dist/cjs/cli/commands/watch.js +31 -25
- package/dist/cjs/cli/index.js +0 -0
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +15 -5
- package/dist/cjs/helpers/agent-schema.js +15 -14
- package/dist/cjs/migration/data_migrator.js +4 -4
- package/dist/cjs/migration/schema_differ.js +37 -15
- package/dist/cjs/types/index.d.ts +12 -0
- package/dist/cjs/util/safe-sql-helpers.js +7 -10
- package/dist/esm/agentic/ActionJournal.d.ts +5 -2
- package/dist/esm/agentic/ActionJournal.js +13 -5
- package/dist/esm/agentic/CapabilityManager.d.ts +7 -0
- package/dist/esm/agentic/CapabilityManager.js +84 -7
- package/dist/esm/agentic/CognitiveRepository.js +3 -6
- package/dist/esm/agentic/Cortex.d.ts +4 -0
- package/dist/esm/agentic/Cortex.js +38 -17
- package/dist/esm/agentic/EpisodicMemory.d.ts +5 -1
- package/dist/esm/agentic/EpisodicMemory.js +11 -4
- package/dist/esm/agentic/PersonaManager.js +37 -31
- package/dist/esm/agentic/PolicyEnforcer.d.ts +6 -1
- package/dist/esm/agentic/PolicyEnforcer.js +74 -17
- package/dist/esm/agentic/ResourceMonitor.d.ts +9 -0
- package/dist/esm/agentic/ResourceMonitor.js +36 -2
- package/dist/esm/agentic/SessionManager.js +24 -17
- package/dist/esm/agentic/VectorIndexer.d.ts +1 -0
- package/dist/esm/agentic/VectorIndexer.js +26 -17
- package/dist/esm/agentic/improvement/AblationEngine.d.ts +4 -6
- package/dist/esm/agentic/improvement/AblationEngine.js +57 -37
- package/dist/esm/agentic/improvement/ActionRefiner.js +30 -14
- package/dist/esm/agentic/improvement/ConflictResolver.d.ts +3 -1
- package/dist/esm/agentic/improvement/ConflictResolver.js +59 -47
- package/dist/esm/agentic/improvement/CortexJanitor.js +11 -0
- package/dist/esm/agentic/improvement/CuriosityEngine.d.ts +1 -1
- package/dist/esm/agentic/improvement/CuriosityEngine.js +48 -21
- package/dist/esm/agentic/improvement/EvolutionRitual.js +26 -14
- package/dist/esm/agentic/improvement/EvolutionaryPilot.js +16 -4
- package/dist/esm/agentic/improvement/GoalArchitect.d.ts +6 -2
- package/dist/esm/agentic/improvement/GoalArchitect.js +72 -34
- package/dist/esm/agentic/improvement/GovernanceManager.d.ts +20 -6
- package/dist/esm/agentic/improvement/GovernanceManager.js +134 -155
- package/dist/esm/agentic/improvement/HiveLink.d.ts +7 -3
- package/dist/esm/agentic/improvement/HiveLink.js +135 -113
- package/dist/esm/agentic/improvement/KnowledgeDistiller.js +43 -35
- package/dist/esm/agentic/improvement/QuotaManager.d.ts +41 -0
- package/dist/esm/agentic/improvement/QuotaManager.js +182 -0
- package/dist/esm/agentic/improvement/RecursiveReasoner.js +50 -25
- package/dist/esm/agentic/improvement/ReflectionEngine.d.ts +4 -1
- package/dist/esm/agentic/improvement/ReflectionEngine.js +3 -1
- package/dist/esm/agentic/improvement/RitualOrchestrator.js +27 -16
- package/dist/esm/agentic/improvement/RuleEngine.d.ts +1 -1
- package/dist/esm/agentic/improvement/RuleEngine.js +10 -4
- package/dist/esm/agentic/improvement/SelfEvolution.js +22 -17
- package/dist/esm/agentic/improvement/SelfTestRegistry.d.ts +5 -0
- package/dist/esm/agentic/improvement/SelfTestRegistry.js +129 -109
- package/dist/esm/agentic/improvement/SkillSynthesizer.d.ts +1 -0
- package/dist/esm/agentic/improvement/SkillSynthesizer.js +22 -13
- package/dist/esm/agentic/improvement/StrategicPlanner.d.ts +1 -0
- package/dist/esm/agentic/improvement/StrategicPlanner.js +26 -19
- package/dist/esm/agentic/improvement/governance/AuditContext.d.ts +17 -0
- package/dist/esm/agentic/improvement/governance/AuditContext.js +2 -0
- package/dist/esm/agentic/improvement/governance/BudgetAuditor.d.ts +4 -0
- package/dist/esm/agentic/improvement/governance/BudgetAuditor.js +47 -0
- package/dist/esm/agentic/improvement/governance/EmergenceAuditor.d.ts +4 -0
- package/dist/esm/agentic/improvement/governance/EmergenceAuditor.js +34 -0
- package/dist/esm/agentic/improvement/governance/MaintenanceOracle.d.ts +4 -0
- package/dist/esm/agentic/improvement/governance/MaintenanceOracle.js +64 -0
- package/dist/esm/agentic/improvement/governance/PerformanceAuditor.d.ts +4 -0
- package/dist/esm/agentic/improvement/governance/PerformanceAuditor.js +40 -0
- package/dist/esm/agentic/improvement/governance/PersonaAuditor.d.ts +6 -0
- package/dist/esm/agentic/improvement/governance/PersonaAuditor.js +71 -0
- package/dist/esm/agentic/improvement/governance/RemediationEngine.d.ts +5 -0
- package/dist/esm/agentic/improvement/governance/RemediationEngine.js +40 -0
- package/dist/esm/agentic/improvement/governance/SkillAuditor.d.ts +5 -0
- package/dist/esm/agentic/improvement/governance/SkillAuditor.js +49 -0
- package/dist/esm/agentic/telemetry/CognitiveSynthesizer.d.ts +5 -0
- package/dist/esm/agentic/telemetry/CognitiveSynthesizer.js +54 -12
- package/dist/esm/agentic/telemetry/EventHarvester.d.ts +1 -1
- package/dist/esm/agentic/telemetry/EventHarvester.js +10 -3
- package/dist/esm/agentic/telemetry/ResearchAlchemist.d.ts +7 -2
- package/dist/esm/agentic/telemetry/ResearchAlchemist.js +49 -8
- package/dist/esm/agentic/telemetry/TelemetryOrchestrator.d.ts +4 -1
- package/dist/esm/agentic/telemetry/TelemetryOrchestrator.js +38 -11
- package/dist/esm/cli/commands/inspect.js +40 -1
- package/dist/esm/cli/commands/watch.js +31 -25
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +15 -5
- package/dist/esm/helpers/agent-schema.js +15 -14
- package/dist/esm/migration/data_migrator.js +4 -4
- package/dist/esm/migration/schema_differ.js +37 -15
- package/dist/esm/types/index.d.ts +12 -0
- package/dist/esm/util/safe-sql-helpers.js +7 -10
- package/package.json +44 -40
|
@@ -71,12 +71,14 @@ class RecursiveReasoner {
|
|
|
71
71
|
const clusters = {};
|
|
72
72
|
// Global Token Frequency Pass
|
|
73
73
|
const globalTokenFreq = new Map();
|
|
74
|
-
|
|
74
|
+
const maxItems = this.config.maxSynthesisItems || 500;
|
|
75
|
+
const limitedResults = rawLessons.slice(0, maxItems);
|
|
76
|
+
for (const lesson of limitedResults) {
|
|
75
77
|
for (const token of this.tokenize(lesson)) {
|
|
76
78
|
globalTokenFreq.set(token, (globalTokenFreq.get(token) || 0) + 1);
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
for (const lesson of
|
|
81
|
+
for (const lesson of limitedResults) {
|
|
80
82
|
const tokens = this.tokenize(lesson);
|
|
81
83
|
if (tokens.length === 0)
|
|
82
84
|
continue;
|
|
@@ -108,30 +110,34 @@ class RecursiveReasoner {
|
|
|
108
110
|
.selectAll()
|
|
109
111
|
.where('metadata', 'like', '%"evolution_status":"stable"%')
|
|
110
112
|
.execute();
|
|
113
|
+
// Audit Phase 14: Linear Batch Check
|
|
114
|
+
const descriptions = breakthroughs
|
|
115
|
+
.map((p) => {
|
|
116
|
+
const meta = JSON.parse(p.metadata || '{}');
|
|
117
|
+
const reasoning = meta.mutation_reasoning || meta.reasoning;
|
|
118
|
+
return reasoning ? `Systemic Best-Practice: ${reasoning}` : null;
|
|
119
|
+
})
|
|
120
|
+
.filter(Boolean);
|
|
121
|
+
if (descriptions.length === 0)
|
|
122
|
+
return 0;
|
|
123
|
+
const existingGoals = await this.typedDb
|
|
124
|
+
.selectFrom(goalsTable)
|
|
125
|
+
.select('description')
|
|
126
|
+
.where('description', 'in', descriptions)
|
|
127
|
+
.execute();
|
|
128
|
+
const existingSet = new Set(existingGoals.map((g) => g.description));
|
|
111
129
|
let goalsCreated = 0;
|
|
112
|
-
for (const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const reasoning = metadata.mutation_reasoning || metadata.reasoning;
|
|
116
|
-
if (!reasoning)
|
|
117
|
-
continue;
|
|
118
|
-
// Check if this goal already exists to avoid duplication
|
|
119
|
-
const existing = await this.typedDb
|
|
120
|
-
.selectFrom(goalsTable)
|
|
121
|
-
.select('id')
|
|
122
|
-
.where('description', 'like', `%${reasoning.slice(0, 50)}%`)
|
|
123
|
-
.executeTakeFirst();
|
|
124
|
-
if (!existing) {
|
|
125
|
-
console.log(`[RecursiveReasoner] Distilling breakthrough from Persona ${persona.id} into Global Goal...`);
|
|
130
|
+
for (const desc of descriptions) {
|
|
131
|
+
if (!existingSet.has(desc)) {
|
|
132
|
+
console.log(`[RecursiveReasoner] Distilling breakthrough into Global Goal: ${desc.slice(0, 50)}...`);
|
|
126
133
|
await this.typedDb
|
|
127
134
|
.insertInto(goalsTable)
|
|
128
135
|
.values({
|
|
129
136
|
session_id: 0, // System-level goal
|
|
130
|
-
description:
|
|
137
|
+
description: desc,
|
|
131
138
|
status: 'pending',
|
|
132
139
|
priority: 5,
|
|
133
140
|
metadata: JSON.stringify({
|
|
134
|
-
source_persona: persona.id,
|
|
135
141
|
cross_pollinated: true,
|
|
136
142
|
}),
|
|
137
143
|
created_at: new Date(),
|
|
@@ -154,15 +160,34 @@ class RecursiveReasoner {
|
|
|
154
160
|
.where('status', '=', 'active')
|
|
155
161
|
.execute());
|
|
156
162
|
const contradictions = [];
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
|
|
163
|
+
const subjectMap = new Map();
|
|
164
|
+
// Audit Phase 7: O(N) Linear Contradiction Detection
|
|
165
|
+
for (const goal of activeGoals) {
|
|
166
|
+
const tokens = this.tokenize(goal.description);
|
|
167
|
+
for (const token of tokens) {
|
|
168
|
+
if (!subjectMap.has(token))
|
|
169
|
+
subjectMap.set(token, []);
|
|
170
|
+
subjectMap.get(token).push({ desc: goal.description, keywords: new Set(tokens) });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const [subject, entries] of subjectMap.entries()) {
|
|
174
|
+
if (entries.length < 2)
|
|
175
|
+
continue;
|
|
176
|
+
for (let i = 0; i < entries.length; i++) {
|
|
177
|
+
for (let j = i + 1; j < entries.length; j++) {
|
|
178
|
+
const conflict = this.checkConflict(entries[i].desc, entries[j].desc);
|
|
179
|
+
if (conflict) {
|
|
180
|
+
contradictions.push(`Goal Conflict: "${entries[i].desc}" opposes "${entries[j].desc}" regarding '${conflict}'`);
|
|
181
|
+
// Limit duplicates for the same pair
|
|
182
|
+
if (contradictions.length > 50)
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
164
185
|
}
|
|
186
|
+
if (contradictions.length > 50)
|
|
187
|
+
break;
|
|
165
188
|
}
|
|
189
|
+
if (contradictions.length > 50)
|
|
190
|
+
break;
|
|
166
191
|
}
|
|
167
192
|
return contradictions;
|
|
168
193
|
}
|
|
@@ -16,7 +16,10 @@ export declare class ReflectionEngine {
|
|
|
16
16
|
/**
|
|
17
17
|
* Get reflections for a specific session
|
|
18
18
|
*/
|
|
19
|
-
getSessionReflections(sessionId: string | number
|
|
19
|
+
getSessionReflections(sessionId: string | number, options?: {
|
|
20
|
+
limit?: number;
|
|
21
|
+
offset?: number;
|
|
22
|
+
}): Promise<AgentReflection[]>;
|
|
20
23
|
/**
|
|
21
24
|
* Get recent lessons learned across all sessions
|
|
22
25
|
*/
|
|
@@ -37,12 +37,14 @@ class ReflectionEngine {
|
|
|
37
37
|
/**
|
|
38
38
|
* Get reflections for a specific session
|
|
39
39
|
*/
|
|
40
|
-
async getSessionReflections(sessionId) {
|
|
40
|
+
async getSessionReflections(sessionId, options = {}) {
|
|
41
41
|
const reflections = (await this.db
|
|
42
42
|
.selectFrom(this.reflectionsTable)
|
|
43
43
|
.selectAll()
|
|
44
44
|
.where('session_id', '=', sessionId)
|
|
45
45
|
.orderBy('created_at', 'desc')
|
|
46
|
+
.limit(options.limit ?? 500) // Audit Phase 18: Hard memory safety limit
|
|
47
|
+
.offset(options.offset ?? 0)
|
|
46
48
|
.execute());
|
|
47
49
|
return reflections.map((r) => this.parseReflection(r));
|
|
48
50
|
}
|
|
@@ -88,25 +88,36 @@ class RitualOrchestrator {
|
|
|
88
88
|
switch (ritual.type) {
|
|
89
89
|
case 'compression':
|
|
90
90
|
const sessionsTable = this.config.sessionsTable || 'agent_sessions';
|
|
91
|
-
const
|
|
92
|
-
.selectFrom(sessionsTable)
|
|
93
|
-
.select('id')
|
|
94
|
-
.where('status', '=', 'active')
|
|
95
|
-
.execute();
|
|
91
|
+
const messagesTable = this.config.messagesTable || 'agent_messages';
|
|
96
92
|
const compressionThreshold = this.config.contextWindowSize || 20;
|
|
97
93
|
let compressedCount = 0;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
.
|
|
103
|
-
.
|
|
104
|
-
.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
94
|
+
let offset = 0;
|
|
95
|
+
const batchSize = 100; // Audit Phase 17: Paginated session processing
|
|
96
|
+
while (true) {
|
|
97
|
+
const activeSessions = await this.db
|
|
98
|
+
.selectFrom(sessionsTable)
|
|
99
|
+
.select('id')
|
|
100
|
+
.where('status', '=', 'active')
|
|
101
|
+
.limit(batchSize)
|
|
102
|
+
.offset(offset)
|
|
103
|
+
.execute();
|
|
104
|
+
if (activeSessions.length === 0)
|
|
105
|
+
break;
|
|
106
|
+
for (const session of activeSessions) {
|
|
107
|
+
const countResult = (await this.db
|
|
108
|
+
.selectFrom(messagesTable)
|
|
109
|
+
.select((eb) => eb.fn.countAll().as('count'))
|
|
110
|
+
.where('session_id', '=', session.id)
|
|
111
|
+
.executeTakeFirst());
|
|
112
|
+
const count = Number(countResult?.count || 0);
|
|
113
|
+
if (count > compressionThreshold) {
|
|
114
|
+
await this.cortex.compressor.semanticPruning(session.id);
|
|
115
|
+
compressedCount++;
|
|
116
|
+
}
|
|
109
117
|
}
|
|
118
|
+
if (activeSessions.length < batchSize)
|
|
119
|
+
break;
|
|
120
|
+
offset += batchSize;
|
|
110
121
|
}
|
|
111
122
|
ritualMetadata.sessionsCompressed = compressedCount;
|
|
112
123
|
break;
|
|
@@ -33,7 +33,7 @@ export declare class RuleEngine {
|
|
|
33
33
|
priority?: number;
|
|
34
34
|
script?: string;
|
|
35
35
|
metadata?: Record<string, any>;
|
|
36
|
-
}): Promise<CognitiveRule>;
|
|
36
|
+
}, trx?: any): Promise<CognitiveRule>;
|
|
37
37
|
/**
|
|
38
38
|
* Evaluate rules against a specific data object.
|
|
39
39
|
* Returns the highest priority rule action that matches.
|
|
@@ -20,9 +20,9 @@ class RuleEngine {
|
|
|
20
20
|
/**
|
|
21
21
|
* Define a new cognitive rule transactionally.
|
|
22
22
|
*/
|
|
23
|
-
async defineRule(tableName, operation, action, options = {}) {
|
|
24
|
-
|
|
25
|
-
const rule = (await
|
|
23
|
+
async defineRule(tableName, operation, action, options = {}, trx) {
|
|
24
|
+
const defineStep = async (t) => {
|
|
25
|
+
const rule = (await t
|
|
26
26
|
.insertInto(this.rulesTable)
|
|
27
27
|
.values({
|
|
28
28
|
table_name: tableName,
|
|
@@ -38,7 +38,13 @@ class RuleEngine {
|
|
|
38
38
|
.returningAll()
|
|
39
39
|
.executeTakeFirstOrThrow());
|
|
40
40
|
return this.parseRule(rule);
|
|
41
|
-
}
|
|
41
|
+
};
|
|
42
|
+
if (trx) {
|
|
43
|
+
return await defineStep(trx);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return await this.db.transaction().execute(defineStep);
|
|
47
|
+
}
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
44
50
|
* Evaluate rules against a specific data object.
|
|
@@ -115,6 +115,7 @@ class SelfEvolution {
|
|
|
115
115
|
.addColumn('evolution_path', 'text') // JSON array of pivots
|
|
116
116
|
.addColumn('autonomy_level', 'integer')
|
|
117
117
|
.addColumn('status', 'text') // success, abandoned, pivoted
|
|
118
|
+
.addColumn('metadata', 'text') // JSON - used by CognitiveSynthesizer
|
|
118
119
|
.addColumn('updated_at', 'timestamp', (col) => col.defaultTo((0, sql_js_1.sql) `CURRENT_TIMESTAMP`))
|
|
119
120
|
.execute();
|
|
120
121
|
// 3. Research Metrics (The Alchemist's Output)
|
|
@@ -134,23 +135,27 @@ class SelfEvolution {
|
|
|
134
135
|
*/
|
|
135
136
|
async evolve(ddl, options = {}) {
|
|
136
137
|
console.log(`[SelfEvolution] Applying structural change: ${ddl}`);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.
|
|
142
|
-
.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
138
|
+
await this.db.transaction().execute(async (trx) => {
|
|
139
|
+
// 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
|
+
await trx.execute(sql_js_1.sql.raw(ddl));
|
|
143
|
+
// 1b. Log for potential rollback
|
|
144
|
+
await trx
|
|
145
|
+
.insertInto(this.snapshotsTable)
|
|
146
|
+
.values({
|
|
147
|
+
name: options.name || `auto_evolution_${Date.now()}`,
|
|
148
|
+
dna: await this.getDNA(),
|
|
149
|
+
metadata: JSON.stringify({
|
|
150
|
+
...options.metadata,
|
|
151
|
+
ddl,
|
|
152
|
+
is_auto: true,
|
|
153
|
+
timestamp: Date.now(),
|
|
154
|
+
}),
|
|
155
|
+
created_at: new Date(),
|
|
156
|
+
})
|
|
157
|
+
.execute();
|
|
158
|
+
});
|
|
154
159
|
// 2. Regenerate types
|
|
155
160
|
await this.regenerateTypes();
|
|
156
161
|
console.log(`[SelfEvolution] Schema evolved successfully.`);
|
|
@@ -45,121 +45,33 @@ class SelfTestRegistry {
|
|
|
45
45
|
for (const probe of probes) {
|
|
46
46
|
console.log(`[SelfTestRegistry] Running probe: ${probe.name}`);
|
|
47
47
|
try {
|
|
48
|
-
// Real implementation: Execute the probe script
|
|
49
|
-
// For safety and integration, we support a set of predefined audit functions
|
|
50
|
-
// or the ability to run a dynamic check if enabled.
|
|
51
48
|
let success = false;
|
|
52
49
|
if (probe.script.startsWith('audit:')) {
|
|
53
|
-
|
|
54
|
-
switch (action) {
|
|
55
|
-
case 'check_schema_consistency':
|
|
56
|
-
// Real check: compare introspection with required core tables
|
|
57
|
-
const tables = await this.db.introspection.getTables();
|
|
58
|
-
const requiredSubsets = [
|
|
59
|
-
this.config.messagesTable || 'agent_messages',
|
|
60
|
-
this.config.sessionsTable || 'agent_sessions',
|
|
61
|
-
this.config.memoriesTable || 'agent_memories',
|
|
62
|
-
this.config.knowledgeTable || 'agent_knowledge_base',
|
|
63
|
-
this.config.actionsTable || 'agent_actions',
|
|
64
|
-
this.config.metricsTable || 'agent_metrics',
|
|
65
|
-
];
|
|
66
|
-
const missing = requiredSubsets.filter((req) => !tables.some((t) => t.name === req));
|
|
67
|
-
success = missing.length === 0;
|
|
68
|
-
break;
|
|
69
|
-
case 'check_memory_integrity':
|
|
70
|
-
// Real check: verify embeddings are not null where expected
|
|
71
|
-
const memoriesTable = this.config.memoriesTable || 'agent_memories';
|
|
72
|
-
const invalidMemories = await this.db
|
|
73
|
-
.selectFrom(memoriesTable)
|
|
74
|
-
.select('id')
|
|
75
|
-
.where('embedding', 'is', null)
|
|
76
|
-
.execute();
|
|
77
|
-
success = invalidMemories.length === 0;
|
|
78
|
-
break;
|
|
79
|
-
case 'check_session_coherence':
|
|
80
|
-
// Check if sessions have at least one message
|
|
81
|
-
const sessionsTable = this.config.sessionsTable || 'agent_sessions';
|
|
82
|
-
const messagesTable = this.config.messagesTable || 'agent_messages';
|
|
83
|
-
const emptySessions = await this.db
|
|
84
|
-
.selectFrom(sessionsTable)
|
|
85
|
-
.leftJoin(messagesTable, `${sessionsTable}.id`, `${messagesTable}.session_id`)
|
|
86
|
-
.select(`${sessionsTable}.id as sid`)
|
|
87
|
-
.where(`${messagesTable}.id`, 'is', null)
|
|
88
|
-
.execute();
|
|
89
|
-
success = emptySessions.length < 5; // Allow small buffer of new sessions
|
|
90
|
-
break;
|
|
91
|
-
case 'check_data_integrity':
|
|
92
|
-
// Real check: Detect orphaned records pointing to non-existent sessions
|
|
93
|
-
const knowledgeTable = this.config.knowledgeTable || 'agent_knowledge_base';
|
|
94
|
-
const actionsTable = this.config.actionsTable || 'agent_actions';
|
|
95
|
-
const sessionsTbl = this.config.sessionsTable || 'agent_sessions';
|
|
96
|
-
const orphanedKnowledge = await this.db
|
|
97
|
-
.selectFrom(knowledgeTable)
|
|
98
|
-
.where('source_session_id', 'is not', null)
|
|
99
|
-
.where((eb) => eb.not(eb.exists(eb
|
|
100
|
-
.selectFrom(sessionsTbl)
|
|
101
|
-
.select('id')
|
|
102
|
-
.whereRef(`${knowledgeTable}.source_session_id`, '=', `${sessionsTbl}.id`))))
|
|
103
|
-
.execute();
|
|
104
|
-
const orphanedActions = await this.db
|
|
105
|
-
.selectFrom(actionsTable)
|
|
106
|
-
.where((eb) => eb.not(eb.exists(eb
|
|
107
|
-
.selectFrom(sessionsTbl)
|
|
108
|
-
.select('id')
|
|
109
|
-
.whereRef(`${actionsTable}.session_id`, '=', `${sessionsTbl}.id`))))
|
|
110
|
-
.execute();
|
|
111
|
-
success =
|
|
112
|
-
orphanedKnowledge.length === 0 && orphanedActions.length === 0;
|
|
113
|
-
break;
|
|
114
|
-
case 'check_performance_drift':
|
|
115
|
-
// Real check: Compare last 10 queries average with historical baseline
|
|
116
|
-
const metricsTbl = this.config.metricsTable || 'agent_metrics';
|
|
117
|
-
const recentMetrics = (await this.db
|
|
118
|
-
.selectFrom(metricsTbl)
|
|
119
|
-
.select('execution_time')
|
|
120
|
-
.orderBy('created_at', 'desc')
|
|
121
|
-
.limit(20)
|
|
122
|
-
.execute());
|
|
123
|
-
if (recentMetrics.length < 5) {
|
|
124
|
-
success = true; // Not enough data to determine drift
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
const avgRecent = recentMetrics.reduce((sum, m) => sum + (m.execution_time || 0), 0) / recentMetrics.length;
|
|
128
|
-
// Baseline: Avg of previous 100 metrics excluding the most recent 20
|
|
129
|
-
const baselineMetrics = (await this.db
|
|
130
|
-
.selectFrom(metricsTbl)
|
|
131
|
-
.select('execution_time')
|
|
132
|
-
.orderBy('created_at', 'desc')
|
|
133
|
-
.offset(20)
|
|
134
|
-
.limit(100)
|
|
135
|
-
.execute());
|
|
136
|
-
if (baselineMetrics.length === 0) {
|
|
137
|
-
success = avgRecent < 500; // Fallback threshold (500ms)
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
const avgBaseline = baselineMetrics.reduce((sum, m) => sum + (m.execution_time || 0), 0) / baselineMetrics.length;
|
|
141
|
-
// Fail if recent performance is > 50% worse than baseline
|
|
142
|
-
success = avgRecent < avgBaseline * 1.5;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
break;
|
|
146
|
-
default:
|
|
147
|
-
success = true;
|
|
148
|
-
}
|
|
50
|
+
success = await this.runAuditAction(probe.script.split(':')[1]);
|
|
149
51
|
}
|
|
150
52
|
else {
|
|
151
|
-
//
|
|
152
|
-
|
|
53
|
+
// Master Sentinel Pass: Dynamic Probe Evaluation
|
|
54
|
+
// If not a hardcoded audit, use LLM to interpret the script against DB state
|
|
55
|
+
success = await this.dynamicEvaluation(probe);
|
|
153
56
|
}
|
|
154
57
|
results.push({ name: probe.name, success });
|
|
155
|
-
await this.db
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
58
|
+
await this.db.transaction().execute(async (trx) => {
|
|
59
|
+
// Audit Phase 13: Lock row before updating last_status
|
|
60
|
+
await trx
|
|
61
|
+
.selectFrom('agent_logic_probes')
|
|
62
|
+
.select('id')
|
|
63
|
+
.where('id', '=', probe.id)
|
|
64
|
+
.forUpdate()
|
|
65
|
+
.executeTakeFirst();
|
|
66
|
+
await trx
|
|
67
|
+
.updateTable('agent_logic_probes')
|
|
68
|
+
.set({
|
|
69
|
+
last_run: new Date(),
|
|
70
|
+
last_status: success ? 'pass' : 'fail',
|
|
71
|
+
})
|
|
72
|
+
.where('id', '=', probe.id)
|
|
73
|
+
.execute();
|
|
74
|
+
});
|
|
163
75
|
}
|
|
164
76
|
catch (e) {
|
|
165
77
|
results.push({ name: probe.name, success: false, error: String(e) });
|
|
@@ -167,5 +79,113 @@ class SelfTestRegistry {
|
|
|
167
79
|
}
|
|
168
80
|
return results;
|
|
169
81
|
}
|
|
82
|
+
async runAuditAction(action) {
|
|
83
|
+
switch (action) {
|
|
84
|
+
case 'check_schema_consistency':
|
|
85
|
+
const tables = await this.db.introspection.getTables();
|
|
86
|
+
const requiredSubsets = [
|
|
87
|
+
this.config.messagesTable || 'agent_messages',
|
|
88
|
+
this.config.sessionsTable || 'agent_sessions',
|
|
89
|
+
this.config.memoriesTable || 'agent_memories',
|
|
90
|
+
this.config.knowledgeTable || 'agent_knowledge_base',
|
|
91
|
+
this.config.actionsTable || 'agent_actions',
|
|
92
|
+
this.config.metricsTable || 'agent_metrics',
|
|
93
|
+
];
|
|
94
|
+
const missing = requiredSubsets.filter((req) => !tables.some((t) => t.name === req));
|
|
95
|
+
return missing.length === 0;
|
|
96
|
+
case 'check_memory_integrity':
|
|
97
|
+
const memoriesTable = this.config.memoriesTable || 'agent_memories';
|
|
98
|
+
const invalidMemories = await this.db
|
|
99
|
+
.selectFrom(memoriesTable)
|
|
100
|
+
.select('id')
|
|
101
|
+
.where('embedding', 'is', null)
|
|
102
|
+
.execute();
|
|
103
|
+
return invalidMemories.length === 0;
|
|
104
|
+
case 'check_session_coherence':
|
|
105
|
+
const sessionsTable = this.config.sessionsTable || 'agent_sessions';
|
|
106
|
+
const messagesTable = this.config.messagesTable || 'agent_messages';
|
|
107
|
+
const emptySessions = await this.db
|
|
108
|
+
.selectFrom(sessionsTable)
|
|
109
|
+
.leftJoin(messagesTable, `${sessionsTable}.id`, `${messagesTable}.session_id`)
|
|
110
|
+
.select(`${sessionsTable}.id as sid`)
|
|
111
|
+
.where(`${messagesTable}.id`, 'is', null)
|
|
112
|
+
.execute();
|
|
113
|
+
return emptySessions.length < 5;
|
|
114
|
+
case 'check_data_integrity':
|
|
115
|
+
const knowledgeTable = this.config.knowledgeTable || 'agent_knowledge_base';
|
|
116
|
+
const actionsTable = this.config.actionsTable || 'agent_actions';
|
|
117
|
+
const sessionsTbl = this.config.sessionsTable || 'agent_sessions';
|
|
118
|
+
const orphanedKnowledge = await this.db
|
|
119
|
+
.selectFrom(knowledgeTable)
|
|
120
|
+
.where('source_session_id', 'is not', null)
|
|
121
|
+
.where((eb) => eb.not(eb.exists(eb
|
|
122
|
+
.selectFrom(sessionsTbl)
|
|
123
|
+
.select('id')
|
|
124
|
+
.whereRef(`${knowledgeTable}.source_session_id`, '=', `${sessionsTbl}.id`))))
|
|
125
|
+
.execute();
|
|
126
|
+
const orphanedActions = await this.db
|
|
127
|
+
.selectFrom(actionsTable)
|
|
128
|
+
.where((eb) => eb.not(eb.exists(eb
|
|
129
|
+
.selectFrom(sessionsTbl)
|
|
130
|
+
.select('id')
|
|
131
|
+
.whereRef(`${actionsTable}.session_id`, '=', `${sessionsTbl}.id`))))
|
|
132
|
+
.execute();
|
|
133
|
+
return orphanedKnowledge.length === 0 && orphanedActions.length === 0;
|
|
134
|
+
case 'check_performance_drift':
|
|
135
|
+
const metricsTbl = this.config.metricsTable || 'agent_metrics';
|
|
136
|
+
const recentMetrics = (await this.db
|
|
137
|
+
.selectFrom(metricsTbl)
|
|
138
|
+
.select('execution_time')
|
|
139
|
+
.orderBy('created_at', 'desc')
|
|
140
|
+
.limit(20)
|
|
141
|
+
.execute());
|
|
142
|
+
if (recentMetrics.length < 5)
|
|
143
|
+
return true;
|
|
144
|
+
const avgRecent = recentMetrics.reduce((sum, m) => sum + (m.execution_time || 0), 0) / recentMetrics.length;
|
|
145
|
+
const baselineMetrics = (await this.db
|
|
146
|
+
.selectFrom(metricsTbl)
|
|
147
|
+
.select('execution_time')
|
|
148
|
+
.orderBy('created_at', 'desc')
|
|
149
|
+
.offset(20)
|
|
150
|
+
.limit(100)
|
|
151
|
+
.execute());
|
|
152
|
+
if (baselineMetrics.length === 0)
|
|
153
|
+
return avgRecent < 500;
|
|
154
|
+
const avgBaseline = baselineMetrics.reduce((sum, m) => sum + (m.execution_time || 0), 0) / baselineMetrics.length;
|
|
155
|
+
return avgRecent < avgBaseline * 1.5;
|
|
156
|
+
default:
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Interpret custom probe logic by providing the LLM with relevant database snapshots.
|
|
162
|
+
*/
|
|
163
|
+
async dynamicEvaluation(probe) {
|
|
164
|
+
const model = this.cortex.llmFast || this.cortex.llm;
|
|
165
|
+
if (!model)
|
|
166
|
+
return true; // Safety fallback if no AI is available
|
|
167
|
+
// Provide a small sample of metrics and actions to allow for semantic reasoning
|
|
168
|
+
const sampleMetrics = await this.db.selectFrom(this.config.metricsTable || 'agent_metrics').limit(10).execute();
|
|
169
|
+
const prompt = `
|
|
170
|
+
You are a Logic Verification Engine for NOORMME.
|
|
171
|
+
TESTRUN: "${probe.name}"
|
|
172
|
+
SCRIPT: "${probe.script}"
|
|
173
|
+
EXPECTED: "${probe.expected_outcome || 'Unspecified'}"
|
|
174
|
+
|
|
175
|
+
DB CONTEXT (Sample Metrics):
|
|
176
|
+
${JSON.stringify(sampleMetrics, null, 2)}
|
|
177
|
+
|
|
178
|
+
TASK:
|
|
179
|
+
Evaluate if the script passes based on the context.
|
|
180
|
+
If the script is a natural language requirement, infer the result.
|
|
181
|
+
RETURN ONLY "PASS" OR "FAIL".
|
|
182
|
+
`;
|
|
183
|
+
const response = await model.complete({
|
|
184
|
+
prompt,
|
|
185
|
+
temperature: 0.1,
|
|
186
|
+
maxTokens: 5
|
|
187
|
+
});
|
|
188
|
+
return response.content.toUpperCase().includes('PASS');
|
|
189
|
+
}
|
|
170
190
|
}
|
|
171
191
|
exports.SelfTestRegistry = SelfTestRegistry;
|
|
@@ -79,10 +79,10 @@ class AISynthesisStrategy {
|
|
|
79
79
|
TOOLS TO MUTATE:
|
|
80
80
|
${contexts
|
|
81
81
|
.map((ctx, i) => `
|
|
82
|
-
[Tool ${i + 1}: ${ctx.targetTool}]
|
|
83
|
-
Current Description: ${ctx.existingDescription || 'None'}
|
|
82
|
+
[Tool ${i + 1}: ${this.sanitizeInput(ctx.targetTool)}]
|
|
83
|
+
Current Description: ${this.sanitizeInput(ctx.existingDescription || 'None')}
|
|
84
84
|
Failure Patterns:
|
|
85
|
-
${ctx.failures.map((f) => `- Args: ${JSON.stringify(f.arguments)}, Error: ${f.error}`).join('\n')}
|
|
85
|
+
${ctx.failures.map((f) => `- Args: ${this.sanitizeInput(JSON.stringify(f.arguments))}, Error: ${this.sanitizeInput(f.error || 'None')}`).join('\n')}
|
|
86
86
|
`)
|
|
87
87
|
.join('\n')}
|
|
88
88
|
|
|
@@ -122,19 +122,23 @@ class AISynthesisStrategy {
|
|
|
122
122
|
}
|
|
123
123
|
buildMutationPrompt(context) {
|
|
124
124
|
const failureList = context.failures
|
|
125
|
-
.map((f, i) => `${i + 1}. Args: ${JSON.stringify(f.arguments)}, Error: ${f.error || 'None'}`)
|
|
125
|
+
.map((f, i) => `${i + 1}. Args: ${this.sanitizeInput(JSON.stringify(f.arguments))}, Error: ${this.sanitizeInput(f.error || 'None')}`)
|
|
126
126
|
.join('\n');
|
|
127
127
|
return `
|
|
128
|
-
You are a Meta-Evolutionary AI Engine optimizing a tool: "${context.targetTool}".
|
|
128
|
+
You are a Meta-Evolutionary AI Engine optimizing a tool: "${this.sanitizeInput(context.targetTool)}".
|
|
129
129
|
Analyze FAILURES and rewrite the description to prevent them.
|
|
130
130
|
|
|
131
|
-
EXISTING: "${context.existingDescription || 'None'}"
|
|
131
|
+
EXISTING: "${this.sanitizeInput(context.existingDescription || 'None')}"
|
|
132
132
|
FAILURES:
|
|
133
133
|
${failureList}
|
|
134
134
|
|
|
135
135
|
RETURN JSON: { "description": "...", "metadata": { "fixed": [...], "reason": "..." } }
|
|
136
136
|
`;
|
|
137
137
|
}
|
|
138
|
+
sanitizeInput(input) {
|
|
139
|
+
// Audit Phase 9: Neutralize prompt injection markers and control chars
|
|
140
|
+
return input.slice(0, 1000).replace(/[\u0000-\u001F\u007F-\u009F]/g, '').replace(/<\|.*?\|>/g, '');
|
|
141
|
+
}
|
|
138
142
|
}
|
|
139
143
|
/**
|
|
140
144
|
* SkillSynthesizer implements Pass 6 Ultra-Scale Orchestration.
|
|
@@ -263,6 +267,8 @@ class SkillSynthesizer {
|
|
|
263
267
|
return await this.cortex.capabilities.registerCapability(tool, mutation.version, mutation.mutatedDescription, {
|
|
264
268
|
initialStatus: 'experimental',
|
|
265
269
|
mutatedFrom: tool,
|
|
270
|
+
lineage: mutation.mutatedMetadata?.lineage || tool,
|
|
271
|
+
variant_tag: `v${Date.now()}`,
|
|
266
272
|
synthesis_engine: 'Ultra-Scale-Tiered',
|
|
267
273
|
...mutation.mutatedMetadata,
|
|
268
274
|
synthesized_at: new Date(),
|
|
@@ -275,13 +281,16 @@ class SkillSynthesizer {
|
|
|
275
281
|
const toPrune = experimental
|
|
276
282
|
.sort((a, b) => a.reliability - b.reliability)
|
|
277
283
|
.slice(0, Math.ceil(experimental.length * 0.2));
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
284
|
+
// Audit Phase 19: Transactional pruning
|
|
285
|
+
await this.db.transaction().execute(async (trx) => {
|
|
286
|
+
for (const skill of toPrune) {
|
|
287
|
+
await trx
|
|
288
|
+
.deleteFrom(this.cortex.agenticConfig.capabilitiesTable ||
|
|
289
|
+
'agent_capabilities')
|
|
290
|
+
.where('id', '=', skill.id)
|
|
291
|
+
.execute();
|
|
292
|
+
}
|
|
293
|
+
});
|
|
285
294
|
}
|
|
286
295
|
}
|
|
287
296
|
}
|