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
|
@@ -38,11 +38,14 @@ class StrategicPlanner {
|
|
|
38
38
|
.selectFrom(this.personasTable)
|
|
39
39
|
.selectAll()
|
|
40
40
|
.execute();
|
|
41
|
+
const allParsedPersonas = personas.map((p) => this.parsePersona(p));
|
|
42
|
+
const globalBlacklistDuration = this.config.strategy?.globalBlacklistDuration || 3600000; // 1 hour
|
|
43
|
+
const localBlacklistDuration = this.config.strategy?.localBlacklistDuration || 86400000; // 24 hours
|
|
41
44
|
for (const p of personas) {
|
|
42
45
|
const persona = this.parsePersona(p);
|
|
43
46
|
// 1. Verification Monitor
|
|
44
47
|
if (persona.metadata?.evolution_status === 'verifying') {
|
|
45
|
-
const result = await this.verifyEvolution(persona);
|
|
48
|
+
const result = await this.verifyEvolution(persona, allParsedPersonas);
|
|
46
49
|
if (result)
|
|
47
50
|
mutations.push(result);
|
|
48
51
|
continue;
|
|
@@ -52,20 +55,15 @@ class StrategicPlanner {
|
|
|
52
55
|
const report = await this.analyzePersona(persona.id);
|
|
53
56
|
// 3. Blacklist Check (Local & Global Phase 5)
|
|
54
57
|
const lastMutation = persona.metadata?.last_failed_mutation;
|
|
55
|
-
const
|
|
56
|
-
.selectFrom(this.personasTable)
|
|
57
|
-
.selectAll()
|
|
58
|
-
.execute();
|
|
59
|
-
const isGloballyBlacklisted = allPersonas.some((p) => {
|
|
60
|
-
const mp = this.parsePersona(p);
|
|
58
|
+
const isGloballyBlacklisted = allParsedPersonas.some((mp) => {
|
|
61
59
|
return (mp.metadata?.last_failed_mutation?.type === report.recommendation &&
|
|
62
60
|
Date.now() - (mp.metadata?.last_failed_mutation?.timestamp || 0) <
|
|
63
|
-
|
|
61
|
+
globalBlacklistDuration);
|
|
64
62
|
});
|
|
65
63
|
if (isGloballyBlacklisted ||
|
|
66
64
|
(lastMutation &&
|
|
67
65
|
report.recommendation === lastMutation.type &&
|
|
68
|
-
Date.now() - lastMutation.timestamp <
|
|
66
|
+
Date.now() - lastMutation.timestamp < localBlacklistDuration)) {
|
|
69
67
|
console.log(`[StrategicPlanner] Skipping blacklisted mutation ${report.recommendation} for persona ${persona.id} (Global=${isGloballyBlacklisted})`);
|
|
70
68
|
continue;
|
|
71
69
|
}
|
|
@@ -111,15 +109,19 @@ class StrategicPlanner {
|
|
|
111
109
|
.filter((p) => (p.metadata?.evolution_status === 'stable' ||
|
|
112
110
|
!p.metadata?.evolution_status) &&
|
|
113
111
|
p.metadata?.mutation_reason?.includes(report.recommendation));
|
|
114
|
-
if (winningMutations.length > 0
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
if (winningMutations.length > 0) {
|
|
113
|
+
// PRODUCTION HARDENING: Deterministic Alpha Selection
|
|
114
|
+
// Instead of Math.random(), pick the variant with the highest anchored reliability
|
|
115
|
+
const sorted = winningMutations.sort((a, b) => (b.metadata?.anchored_reliability || 0) - (a.metadata?.anchored_reliability || 0));
|
|
116
|
+
const alphaMatch = sorted[0];
|
|
117
|
+
console.log(`[StrategicPlanner] Cross-Pollinating success from Alpha Persona ${alphaMatch.id} (Reliability: ${alphaMatch.metadata?.anchored_reliability || 0})`);
|
|
118
|
+
updates = { role: this.sanitizeRole(alphaMatch.role || persona.role || 'Agent') };
|
|
117
119
|
}
|
|
118
120
|
else {
|
|
119
121
|
switch (report.recommendation) {
|
|
120
122
|
case 'optimize_accuracy':
|
|
121
123
|
updates = {
|
|
122
|
-
role: `${persona.role || ''} (Focus strictly on accuracy and detailed verification)
|
|
124
|
+
role: this.sanitizeRole(`${persona.role || ''} (Focus strictly on accuracy and detailed verification)`),
|
|
123
125
|
};
|
|
124
126
|
break;
|
|
125
127
|
case 'optimize_efficiency':
|
|
@@ -139,6 +141,9 @@ class StrategicPlanner {
|
|
|
139
141
|
}
|
|
140
142
|
}
|
|
141
143
|
}
|
|
144
|
+
if (updates.role) {
|
|
145
|
+
updates.role = this.sanitizeRole(updates.role);
|
|
146
|
+
}
|
|
142
147
|
// 1. Predictive Conflict Detection (Pre-flight)
|
|
143
148
|
const proposedState = { ...persona, ...updates };
|
|
144
149
|
const contradictions = await this.cortex.reasoner.detectContradictions();
|
|
@@ -198,18 +203,13 @@ class StrategicPlanner {
|
|
|
198
203
|
* Check if a persona in verification should be stabilized or rolled back.
|
|
199
204
|
* Uses dynamic statistical variance and adaptive meta-tuning.
|
|
200
205
|
*/
|
|
201
|
-
async verifyEvolution(persona) {
|
|
206
|
+
async verifyEvolution(persona, allPersonas = []) {
|
|
202
207
|
const report = await this.analyzePersona(persona.id);
|
|
203
208
|
// Adaptive Meta-Tuning: Increase window based on rollback history (Phase 4)
|
|
204
209
|
const rollbackHistory = persona.metadata?.rollbackHistory || [];
|
|
205
210
|
const recentRollbacks = rollbackHistory.filter((ts) => Date.now() - ts < 604800000).length;
|
|
206
211
|
// Hive-Mind Verification Speedups (Phase 5)
|
|
207
|
-
const allPersonas = await this.typedDb
|
|
208
|
-
.selectFrom(this.personasTable)
|
|
209
|
-
.selectAll()
|
|
210
|
-
.execute();
|
|
211
212
|
const hiveTrusted = allPersonas
|
|
212
|
-
.map((p) => this.parsePersona(p))
|
|
213
213
|
.filter((p) => p.metadata?.evolution_status === 'stable' &&
|
|
214
214
|
p.metadata?.mutation_reason === persona.metadata?.mutation_reason).length;
|
|
215
215
|
let sampleSizeThreshold = 10 + recentRollbacks * 10;
|
|
@@ -432,6 +432,13 @@ class StrategicPlanner {
|
|
|
432
432
|
return `Rolled back mutation ${lastMutation.id} for persona ${id}`;
|
|
433
433
|
});
|
|
434
434
|
}
|
|
435
|
+
sanitizeRole(role) {
|
|
436
|
+
// Audit Phase 7: Semantic Security
|
|
437
|
+
// Truncate to prevent context-window exhaustion/bloat
|
|
438
|
+
const truncated = role.slice(0, 500).trim();
|
|
439
|
+
// Sanitize: remove potentially dangerous prompt-injection markers or control chars
|
|
440
|
+
return truncated.replace(/[\u0000-\u001F\u007F-\u009F]/g, '').replace(/<\|.*?\|>/g, '');
|
|
441
|
+
}
|
|
435
442
|
parsePersona(p) {
|
|
436
443
|
return {
|
|
437
444
|
id: p.id,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Kysely } from '../../../kysely.js';
|
|
2
|
+
import type { AgenticConfig } from '../../../types/index.js';
|
|
3
|
+
import type { Cortex } from '../../Cortex.js';
|
|
4
|
+
export interface AuditContext {
|
|
5
|
+
db: Kysely<any>;
|
|
6
|
+
trx: Kysely<any>;
|
|
7
|
+
cortex: Cortex;
|
|
8
|
+
config: AgenticConfig;
|
|
9
|
+
metricsTable: string;
|
|
10
|
+
policiesTable: string;
|
|
11
|
+
personasTable: string;
|
|
12
|
+
skillsTable: string;
|
|
13
|
+
}
|
|
14
|
+
export interface AuditResult {
|
|
15
|
+
issues: string[];
|
|
16
|
+
metadata: Record<string, any>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BudgetAuditor = void 0;
|
|
4
|
+
class BudgetAuditor {
|
|
5
|
+
async audit(ctx) {
|
|
6
|
+
const issues = [];
|
|
7
|
+
// Fetch budget policies
|
|
8
|
+
const policies = (await ctx.trx
|
|
9
|
+
.selectFrom(ctx.policiesTable)
|
|
10
|
+
.selectAll()
|
|
11
|
+
.where('is_enabled', '=', true)
|
|
12
|
+
.where((eb) => eb.or([
|
|
13
|
+
eb('name', '=', 'hourly_budget'),
|
|
14
|
+
eb('name', '=', 'daily_budget'),
|
|
15
|
+
eb('type', '=', 'budget')
|
|
16
|
+
]))
|
|
17
|
+
.execute());
|
|
18
|
+
const getLimit = (name) => {
|
|
19
|
+
const p = policies.find(p => p.name === name);
|
|
20
|
+
if (!p)
|
|
21
|
+
return 0;
|
|
22
|
+
const def = typeof p.definition === 'string' ? JSON.parse(p.definition) : p.definition;
|
|
23
|
+
return def.threshold ?? def.limit ?? 0;
|
|
24
|
+
};
|
|
25
|
+
const hourlyLimit = getLimit('hourly_budget');
|
|
26
|
+
const dailyLimit = getLimit('daily_budget');
|
|
27
|
+
const getCostInWindow = async (ms) => {
|
|
28
|
+
const result = await ctx.trx
|
|
29
|
+
.selectFrom(ctx.metricsTable)
|
|
30
|
+
.select((eb) => eb.fn.sum('metric_value').as('total'))
|
|
31
|
+
.where('metric_name', '=', 'total_cost')
|
|
32
|
+
.where('created_at', '>', new Date(Date.now() - ms))
|
|
33
|
+
.executeTakeFirst();
|
|
34
|
+
return Number(result?.total || 0);
|
|
35
|
+
};
|
|
36
|
+
const hCost = await getCostInWindow(3600000);
|
|
37
|
+
if (hCost > hourlyLimit && hourlyLimit > 0) {
|
|
38
|
+
issues.push(`Budget Violations: Hourly cost ($${hCost.toFixed(2)}) exceeded policy ($${hourlyLimit.toFixed(2)})`);
|
|
39
|
+
}
|
|
40
|
+
const dCost = await getCostInWindow(86400000);
|
|
41
|
+
if (dCost > dailyLimit && dailyLimit > 0) {
|
|
42
|
+
issues.push(`Budget Violations: Daily cumulative cost ($${dCost.toFixed(2)}) exceeded safety ceiling ($${dailyLimit.toFixed(2)})`);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
issues,
|
|
46
|
+
metadata: { hCost, hourlyLimit, dCost, dailyLimit }
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.BudgetAuditor = BudgetAuditor;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmergenceAuditor = void 0;
|
|
4
|
+
class EmergenceAuditor {
|
|
5
|
+
async audit(ctx) {
|
|
6
|
+
const issues = [];
|
|
7
|
+
// 1. Check for rapid propagation of new skills (Potential poisoning)
|
|
8
|
+
const recentSkills = await ctx.trx
|
|
9
|
+
.selectFrom(ctx.skillsTable)
|
|
10
|
+
.select(['name', 'created_at'])
|
|
11
|
+
.where('created_at', '>', new Date(Date.now() - 3600000)) // Last hour
|
|
12
|
+
.execute();
|
|
13
|
+
if (recentSkills.length > 10) {
|
|
14
|
+
issues.push(`Emergent Warning: Rapid skill propagation detected (${recentSkills.length} new skills in 1hr). Potential rogue behavior.`);
|
|
15
|
+
}
|
|
16
|
+
// 2. Check for high variance in task success across swarm
|
|
17
|
+
const recentTaskMetrics = await ctx.trx
|
|
18
|
+
.selectFrom(ctx.metricsTable)
|
|
19
|
+
.select(['metric_value', 'metadata'])
|
|
20
|
+
.where('metric_name', '=', 'task_success_rate')
|
|
21
|
+
.where('created_at', '>', new Date(Date.now() - 1800000)) // Last 30m
|
|
22
|
+
.execute();
|
|
23
|
+
if (recentTaskMetrics.length >= 5) {
|
|
24
|
+
const values = recentTaskMetrics.map((m) => Number(m.metric_value));
|
|
25
|
+
const mean = values.reduce((a, b) => a + b, 0) / values.length;
|
|
26
|
+
const variance = values.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / values.length;
|
|
27
|
+
if (variance > 0.2) {
|
|
28
|
+
issues.push(`Emergent Warning: High variance in swarm success rate (${(variance * 100).toFixed(1)}%). Potential node instability.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
issues,
|
|
33
|
+
metadata: { recentSkillCount: recentSkills.length, successVariance: recentTaskMetrics.length >= 5 ? issues.length > 0 : null }
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.EmergenceAuditor = EmergenceAuditor;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MaintenanceOracle = void 0;
|
|
4
|
+
class MaintenanceOracle {
|
|
5
|
+
async suggestRepairs(ctx) {
|
|
6
|
+
const repairs = [];
|
|
7
|
+
// Fetch maintenance policies
|
|
8
|
+
const policies = (await ctx.db
|
|
9
|
+
.selectFrom(ctx.policiesTable)
|
|
10
|
+
.selectAll()
|
|
11
|
+
.where('is_enabled', '=', true)
|
|
12
|
+
.execute());
|
|
13
|
+
const getPolicyValue = (name, fallback) => {
|
|
14
|
+
const p = policies.find(p => p.name === name);
|
|
15
|
+
if (!p)
|
|
16
|
+
return fallback;
|
|
17
|
+
const def = typeof p.definition === 'string' ? JSON.parse(p.definition) : p.definition;
|
|
18
|
+
return def.threshold ?? def.limit ?? def.days ?? fallback;
|
|
19
|
+
};
|
|
20
|
+
const latencyPolicy = getPolicyValue('latency_repair_threshold', 500);
|
|
21
|
+
const costPolicy = getPolicyValue('high_cost_threshold', 0.5);
|
|
22
|
+
const storagePolicy = getPolicyValue('cold_storage_threshold', 30);
|
|
23
|
+
// 1. Check for chronic high latency
|
|
24
|
+
const latencyStats = await ctx.cortex.metrics.getMetricStats('query_latency');
|
|
25
|
+
if (latencyStats.avg > latencyPolicy && latencyStats.count > 10) {
|
|
26
|
+
repairs.push(`Average latency is high (${latencyStats.avg.toFixed(2)}ms). Suggesting index audit across hit tables.`);
|
|
27
|
+
}
|
|
28
|
+
// 2. Detect specific slow tables
|
|
29
|
+
const recentSlowQueries = await ctx.db
|
|
30
|
+
.selectFrom(ctx.metricsTable)
|
|
31
|
+
.select('metadata')
|
|
32
|
+
.where('metric_name', '=', 'query_latency')
|
|
33
|
+
.where('metric_value', '>', latencyPolicy * 2)
|
|
34
|
+
.limit(20)
|
|
35
|
+
.execute();
|
|
36
|
+
const slowTables = new Set();
|
|
37
|
+
for (const q of recentSlowQueries) {
|
|
38
|
+
try {
|
|
39
|
+
const meta = typeof q.metadata === 'string' ? JSON.parse(q.metadata) : q.metadata || {};
|
|
40
|
+
if (meta.table)
|
|
41
|
+
slowTables.add(meta.table);
|
|
42
|
+
}
|
|
43
|
+
catch (e) { }
|
|
44
|
+
}
|
|
45
|
+
for (const table of slowTables) {
|
|
46
|
+
repairs.push(`Table '${table}' is experiencing periodic latency spikes. Suggesting 'CREATE INDEX' for common filters.`);
|
|
47
|
+
}
|
|
48
|
+
// 3. Check for high cost
|
|
49
|
+
const totalCost = await ctx.cortex.metrics.getAverageMetric('total_cost');
|
|
50
|
+
if (totalCost > costPolicy) {
|
|
51
|
+
repairs.push('Average query cost is high. Suggesting prompt compression or model switching (e.g., to a smaller model).');
|
|
52
|
+
}
|
|
53
|
+
// 4. Cold storage candidates
|
|
54
|
+
const oldThreshold = new Date(Date.now() - storagePolicy * 24 * 60 * 60 * 1000);
|
|
55
|
+
const sessionsTable = ctx.config.sessionsTable || 'agent_sessions';
|
|
56
|
+
const oldSessions = (await ctx.db
|
|
57
|
+
.selectFrom(sessionsTable)
|
|
58
|
+
.select((eb) => eb.fn.count('id').as('count'))
|
|
59
|
+
.where('created_at', '<', oldThreshold)
|
|
60
|
+
.executeTakeFirst());
|
|
61
|
+
if (Number(oldSessions?.count || 0) > 100) {
|
|
62
|
+
repairs.push(`[STORAGE OPTIMIZATION] Found ${oldSessions.count} sessions older than ${storagePolicy} days. Consider moving to cold storage.`);
|
|
63
|
+
}
|
|
64
|
+
return repairs;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.MaintenanceOracle = MaintenanceOracle;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PerformanceAuditor = void 0;
|
|
4
|
+
class PerformanceAuditor {
|
|
5
|
+
async audit(ctx) {
|
|
6
|
+
const issues = [];
|
|
7
|
+
// Fetch safety policies for success rate
|
|
8
|
+
const policies = (await ctx.trx
|
|
9
|
+
.selectFrom(ctx.policiesTable)
|
|
10
|
+
.selectAll()
|
|
11
|
+
.where('is_enabled', '=', true)
|
|
12
|
+
.where((eb) => eb.or([
|
|
13
|
+
eb('name', '=', 'min_success_rate'),
|
|
14
|
+
eb('type', '=', 'safety')
|
|
15
|
+
]))
|
|
16
|
+
.execute());
|
|
17
|
+
const getLimit = (name) => {
|
|
18
|
+
const p = policies.find(p => p.name === name);
|
|
19
|
+
if (!p)
|
|
20
|
+
return 0.8; // Default success floor
|
|
21
|
+
const def = typeof p.definition === 'string' ? JSON.parse(p.definition) : p.definition;
|
|
22
|
+
return def.threshold ?? def.limit ?? 0.8;
|
|
23
|
+
};
|
|
24
|
+
const minSuccess = getLimit('min_success_rate');
|
|
25
|
+
// Statistical Success Rate (last 100 events)
|
|
26
|
+
const recentSuccess = await ctx.trx
|
|
27
|
+
.selectFrom(ctx.metricsTable)
|
|
28
|
+
.select((eb) => eb.fn.avg('metric_value').as('avg'))
|
|
29
|
+
.where('metric_name', '=', 'success_rate')
|
|
30
|
+
.orderBy('created_at', 'desc')
|
|
31
|
+
.limit(100)
|
|
32
|
+
.executeTakeFirst();
|
|
33
|
+
const success = Number(recentSuccess?.avg || 1);
|
|
34
|
+
if (success < minSuccess) {
|
|
35
|
+
issues.push(`Performance Degradation: Rolling success rate (${Math.round(success * 100)}%) is below policy requirement (${minSuccess * 100}%)`);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
issues,
|
|
39
|
+
metadata: { success, minSuccess }
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.PerformanceAuditor = PerformanceAuditor;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AuditContext, AuditResult } from './AuditContext.js';
|
|
2
|
+
export declare class PersonaAuditor {
|
|
3
|
+
audit(ctx: AuditContext): Promise<AuditResult>;
|
|
4
|
+
private getActivePersona;
|
|
5
|
+
quarantinePersona(ctx: AuditContext, id: string | number, reason: string): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PersonaAuditor = void 0;
|
|
4
|
+
class PersonaAuditor {
|
|
5
|
+
async audit(ctx) {
|
|
6
|
+
const issues = [];
|
|
7
|
+
const activePersona = await this.getActivePersona(ctx);
|
|
8
|
+
if (activePersona) {
|
|
9
|
+
const quotaCheck = await ctx.cortex.quotas.checkQuota('persona', activePersona.id);
|
|
10
|
+
if (!quotaCheck.allowed) {
|
|
11
|
+
issues.push(`Quota Breach: ${quotaCheck.reason}`);
|
|
12
|
+
}
|
|
13
|
+
// Check for swarm-level quotas if part of a swarm
|
|
14
|
+
const swarmId = activePersona.metadata?.swarm_id;
|
|
15
|
+
if (swarmId) {
|
|
16
|
+
const swarmCheck = await ctx.cortex.quotas.checkQuota('swarm', swarmId);
|
|
17
|
+
if (!swarmCheck.allowed) {
|
|
18
|
+
issues.push(`Swarm Quota Breach [${swarmId}]: ${swarmCheck.reason}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
issues,
|
|
24
|
+
metadata: { activePersona }
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async getActivePersona(ctx) {
|
|
28
|
+
const active = await ctx.trx
|
|
29
|
+
.selectFrom(ctx.personasTable)
|
|
30
|
+
.selectAll()
|
|
31
|
+
.where('status', '=', 'active')
|
|
32
|
+
.executeTakeFirst();
|
|
33
|
+
if (!active)
|
|
34
|
+
return null;
|
|
35
|
+
return {
|
|
36
|
+
...active,
|
|
37
|
+
metadata: typeof active.metadata === 'string'
|
|
38
|
+
? JSON.parse(active.metadata)
|
|
39
|
+
: active.metadata || {},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async quarantinePersona(ctx, id, reason) {
|
|
43
|
+
console.warn(`[PersonaAuditor] QUARANTINING Persona ${id}: ${reason}`);
|
|
44
|
+
let query = ctx.db
|
|
45
|
+
.selectFrom(ctx.personasTable)
|
|
46
|
+
.selectAll()
|
|
47
|
+
.where('id', '=', id);
|
|
48
|
+
// SQLite doesn't support SELECT ... FOR UPDATE easily in Kysely without specific dialect support
|
|
49
|
+
// But we are in a transaction usually if passed ctx.trx.
|
|
50
|
+
// Here we use ctx.db for the quarantine update if it's a standalone call.
|
|
51
|
+
const persona = await query.executeTakeFirst();
|
|
52
|
+
if (persona) {
|
|
53
|
+
const metadata = typeof persona.metadata === 'string'
|
|
54
|
+
? JSON.parse(persona.metadata)
|
|
55
|
+
: persona.metadata || {};
|
|
56
|
+
await ctx.db
|
|
57
|
+
.updateTable(ctx.personasTable)
|
|
58
|
+
.set({
|
|
59
|
+
status: 'quarantined',
|
|
60
|
+
metadata: JSON.stringify({
|
|
61
|
+
...metadata,
|
|
62
|
+
quarantine_reason: reason,
|
|
63
|
+
quarantined_at: new Date(),
|
|
64
|
+
}),
|
|
65
|
+
updated_at: new Date(),
|
|
66
|
+
})
|
|
67
|
+
.where('id', '=', id)
|
|
68
|
+
.execute();
|
|
69
|
+
// Rollback most recent changes via strategy engine
|
|
70
|
+
await ctx.cortex.strategy.rollbackPersona(id);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.PersonaAuditor = PersonaAuditor;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemediationEngine = void 0;
|
|
4
|
+
class RemediationEngine {
|
|
5
|
+
async triggerRemediation(ctx, issues) {
|
|
6
|
+
for (const issue of issues) {
|
|
7
|
+
if (issue.includes('Budget Violations')) {
|
|
8
|
+
await ctx.cortex.rituals.scheduleRitual('Budget Remediation', 'compression', 'hourly', `Automated response to: ${issue}`, { priority: 'critical', enforce_limits: true });
|
|
9
|
+
}
|
|
10
|
+
if (issue.includes('Performance Degradation')) {
|
|
11
|
+
await ctx.cortex.rituals.scheduleRitual('Reliability Sweep', 'pruning', 'daily', `Sanitizing high-noise memories due to: ${issue}`, { priority: 'medium', target: 'longtail' });
|
|
12
|
+
}
|
|
13
|
+
if (issue.includes('Integrity Failure')) {
|
|
14
|
+
await this.remediateSkillFailure(ctx, issue);
|
|
15
|
+
}
|
|
16
|
+
if (issue.includes('Quota Breach') || issue.includes('Swarm Quota Breach')) {
|
|
17
|
+
await ctx.cortex.rituals.scheduleRitual('Resource Throttling', 'pruning', 'hourly', `Critical resource containment: ${issue}`, { priority: 'critical', active_containment: true });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async remediateSkillFailure(ctx, issue) {
|
|
22
|
+
const skillName = issue.match(/'([^']+)'/)?.[1];
|
|
23
|
+
if (!skillName)
|
|
24
|
+
return;
|
|
25
|
+
console.log(`[RemediationEngine] Demoting tainted skill out of verified pool: ${skillName}`);
|
|
26
|
+
// Use a fresh transaction for remediation if possible, or use ctx.trx
|
|
27
|
+
await ctx.db.transaction().execute(async (trx) => {
|
|
28
|
+
const skill = await trx
|
|
29
|
+
.selectFrom(ctx.skillsTable)
|
|
30
|
+
.select('id')
|
|
31
|
+
.where('name', '=', skillName)
|
|
32
|
+
.executeTakeFirst();
|
|
33
|
+
if (skill) {
|
|
34
|
+
await trx
|
|
35
|
+
.updateTable(ctx.skillsTable)
|
|
36
|
+
.set({ status: 'experimental', updated_at: new Date() })
|
|
37
|
+
.where('id', '=', skill.id)
|
|
38
|
+
.execute();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.RemediationEngine = RemediationEngine;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkillAuditor = void 0;
|
|
4
|
+
class SkillAuditor {
|
|
5
|
+
async audit(ctx) {
|
|
6
|
+
const issues = [];
|
|
7
|
+
// Fetch integrity policies for reliability floor
|
|
8
|
+
const policies = (await ctx.trx
|
|
9
|
+
.selectFrom(ctx.policiesTable)
|
|
10
|
+
.selectAll()
|
|
11
|
+
.where('is_enabled', '=', true)
|
|
12
|
+
.where((eb) => eb.or([
|
|
13
|
+
eb('name', '=', 'reliability_floor'),
|
|
14
|
+
eb('type', '=', 'integrity')
|
|
15
|
+
]))
|
|
16
|
+
.execute());
|
|
17
|
+
const getLimit = (name) => {
|
|
18
|
+
const p = policies.find(p => p.name === name);
|
|
19
|
+
if (!p)
|
|
20
|
+
return 0.7; // Default reliability floor
|
|
21
|
+
const def = typeof p.definition === 'string' ? JSON.parse(p.definition) : p.definition;
|
|
22
|
+
return def.threshold ?? def.limit ?? 0.7;
|
|
23
|
+
};
|
|
24
|
+
const reliabilityLimit = getLimit('reliability_floor');
|
|
25
|
+
const failingVerified = await ctx.trx
|
|
26
|
+
.selectFrom(ctx.skillsTable)
|
|
27
|
+
.select(['name', 'reliability'])
|
|
28
|
+
.where('status', '=', 'verified')
|
|
29
|
+
.where('reliability', '<', reliabilityLimit)
|
|
30
|
+
.execute();
|
|
31
|
+
for (const cap of failingVerified) {
|
|
32
|
+
issues.push(`Integrity Failure: Verified skill '${cap.name}' reliability (${cap.reliability.toFixed(2)}) dropped below floor (${reliabilityLimit})`);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
issues,
|
|
36
|
+
metadata: { reliabilityLimit, failingVerifiedCount: failingVerified.length }
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async quarantineSkill(ctx, name, reason) {
|
|
40
|
+
console.warn(`[SkillAuditor] BLACKLISTING Skill ${name}: ${reason}`);
|
|
41
|
+
await ctx.db
|
|
42
|
+
.updateTable(ctx.skillsTable)
|
|
43
|
+
.set({
|
|
44
|
+
status: 'blacklisted',
|
|
45
|
+
metadata: JSON.stringify({ blacklist_reason: reason, blacklisted_at: new Date() }),
|
|
46
|
+
updated_at: new Date()
|
|
47
|
+
})
|
|
48
|
+
.where('name', '=', name)
|
|
49
|
+
.execute();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.SkillAuditor = SkillAuditor;
|
|
@@ -22,5 +22,10 @@ export declare class CognitiveSynthesizer {
|
|
|
22
22
|
private inferGoalFromContent;
|
|
23
23
|
private detectStrategy;
|
|
24
24
|
private calculateAutonomy;
|
|
25
|
+
/**
|
|
26
|
+
* Detect "Sentiment Drift" or Cognitive Friction in the input stream.
|
|
27
|
+
* Mirrors the agent's internal "frustration" or "flow" state.
|
|
28
|
+
*/
|
|
29
|
+
private detectSentimentDrift;
|
|
25
30
|
private parsePath;
|
|
26
31
|
}
|