noormme 1.2.0 → 1.2.1
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 +9 -3
- package/dist/cjs/agentic/improvement/GovernanceManager.js +232 -92
- 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 +21 -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/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/dialect/sqlite/sqlite-introspector.js +15 -5
- package/dist/cjs/helpers/agent-schema.js +1 -0
- 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 +9 -3
- package/dist/esm/agentic/improvement/GovernanceManager.js +232 -92
- 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 +21 -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/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 +1 -0
- 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 +1 -1
|
@@ -23,91 +23,122 @@ export class GovernanceManager {
|
|
|
23
23
|
*/
|
|
24
24
|
async performAudit() {
|
|
25
25
|
const issues = [];
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
26
|
+
return await this.db.transaction().execute(async (trx) => {
|
|
27
|
+
// 0. Emergent Behavior Validation (Phase 2 Safety)
|
|
28
|
+
const emergentIssues = await this.validateEmergentBehavior(trx);
|
|
29
|
+
issues.push(...emergentIssues);
|
|
30
|
+
// Fetch active policies within transaction
|
|
31
|
+
const policies = (await trx
|
|
32
|
+
.selectFrom(this.policiesTable)
|
|
33
|
+
.selectAll()
|
|
34
|
+
.where('is_enabled', '=', true)
|
|
35
|
+
.execute());
|
|
36
|
+
const getPolicyValue = (name, type, strict = true) => {
|
|
37
|
+
const p = policies.find((p) => p.name === name || p.type === type);
|
|
38
|
+
if (!p) {
|
|
39
|
+
if (strict)
|
|
40
|
+
throw new Error(`Governance Violation: Required policy '${name}' or type '${type}' not found.`);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const def = typeof p.definition === 'string'
|
|
44
|
+
? JSON.parse(p.definition)
|
|
45
|
+
: p.definition;
|
|
46
|
+
return def.threshold ?? def.limit ?? 0;
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
// 1. Budgetary Governance: Check for cost spikes in various windows
|
|
50
|
+
const hourlyLimit = getPolicyValue('hourly_budget', 'budget');
|
|
51
|
+
const dailyLimit = getPolicyValue('daily_budget', 'budget');
|
|
52
|
+
const getCostInWindow = async (ms) => {
|
|
53
|
+
const result = await trx
|
|
54
|
+
.selectFrom(this.metricsTable)
|
|
55
|
+
.select((eb) => eb.fn.sum('metric_value').as('total'))
|
|
56
|
+
.where('metric_name', '=', 'total_cost')
|
|
57
|
+
.where('created_at', '>', new Date(Date.now() - ms))
|
|
58
|
+
.executeTakeFirst();
|
|
59
|
+
return Number(result?.total || 0);
|
|
60
|
+
};
|
|
61
|
+
const hCost = await getCostInWindow(3600000);
|
|
62
|
+
if (hCost > hourlyLimit && hourlyLimit > 0) {
|
|
63
|
+
issues.push(`Budget Violations: Hourly cost ($${hCost.toFixed(2)}) exceeded policy ($${hourlyLimit.toFixed(2)})`);
|
|
64
|
+
}
|
|
65
|
+
const dCost = await getCostInWindow(86400000);
|
|
66
|
+
if (dCost > dailyLimit && dailyLimit > 0) {
|
|
67
|
+
issues.push(`Budget Violations: Daily cumulative cost ($${dCost.toFixed(2)}) exceeded safety ceiling ($${dailyLimit.toFixed(2)})`);
|
|
68
|
+
}
|
|
69
|
+
// 2. Performance Governance: Success Rates & Success Stability
|
|
70
|
+
const minSuccess = getPolicyValue('min_success_rate', 'safety');
|
|
71
|
+
// Statistical Success Rate (last 100 events)
|
|
72
|
+
const recentSuccess = await trx
|
|
73
|
+
.selectFrom(this.metricsTable)
|
|
74
|
+
.select((eb) => eb.fn.avg('metric_value').as('avg'))
|
|
75
|
+
.where('metric_name', '=', 'success_rate')
|
|
76
|
+
.orderBy('created_at', 'desc')
|
|
77
|
+
.limit(100)
|
|
78
|
+
.executeTakeFirst();
|
|
79
|
+
const success = Number(recentSuccess?.avg || 1);
|
|
80
|
+
if (success < minSuccess) {
|
|
81
|
+
issues.push(`Performance Degradation: Rolling success rate (${Math.round(success * 100)}%) is below policy requirement (${minSuccess * 100}%)`);
|
|
82
|
+
}
|
|
83
|
+
// 2b. Swarm Quota Governance: Real-time quota validation
|
|
84
|
+
const activePersona = await this.getActivePersona(trx);
|
|
85
|
+
if (activePersona) {
|
|
86
|
+
const quotaCheck = await this.cortex.quotas.checkQuota('persona', activePersona.id);
|
|
87
|
+
if (!quotaCheck.allowed) {
|
|
88
|
+
issues.push(`Quota Breach: ${quotaCheck.reason}`);
|
|
89
|
+
}
|
|
90
|
+
// Check for swarm-level quotas if part of a swarm
|
|
91
|
+
const swarmId = activePersona.metadata?.swarm_id;
|
|
92
|
+
if (swarmId) {
|
|
93
|
+
const swarmCheck = await this.cortex.quotas.checkQuota('swarm', swarmId);
|
|
94
|
+
if (!swarmCheck.allowed) {
|
|
95
|
+
issues.push(`Swarm Quota Breach [${swarmId}]: ${swarmCheck.reason}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// 3. Infrastructure Integrity: Reliability of Verified Skills
|
|
100
|
+
const reliabiltyLimit = getPolicyValue('reliability_floor', 'integrity');
|
|
101
|
+
const failingVerified = await trx
|
|
102
|
+
.selectFrom(this.config.capabilitiesTable || 'agent_capabilities')
|
|
103
|
+
.select(['name', 'reliability'])
|
|
104
|
+
.where('status', '=', 'verified')
|
|
105
|
+
.where('reliability', '<', reliabiltyLimit)
|
|
106
|
+
.execute();
|
|
107
|
+
for (const cap of failingVerified) {
|
|
108
|
+
issues.push(`Integrity Failure: Verified skill '${cap.name}' reliability (${cap.reliability.toFixed(2)}) dropped below floor (${reliabiltyLimit})`);
|
|
109
|
+
}
|
|
110
|
+
if (issues.length > 0) {
|
|
111
|
+
console.warn(`[GovernanceManager] AUDIT FAILED [${new Date().toISOString()}]: ${issues.length} compliance issues detected.`);
|
|
112
|
+
// Phase 1: Emergency Rollbacks
|
|
113
|
+
if (activePersona && (success < 0.4 || hCost > hourlyLimit * 1.5)) {
|
|
114
|
+
console.error(`[GovernanceManager] CRITICAL THRESHOLD BREACH. Initiating emergency containment for persona ${activePersona.id}`);
|
|
115
|
+
await this.cortex.strategy.rollbackPersona(activePersona.id);
|
|
116
|
+
issues.push(`Containment: Emergency rollback triggered for persona ${activePersona.id}`);
|
|
117
|
+
}
|
|
118
|
+
// Phase 2: Systemic Reflections
|
|
119
|
+
await this.cortex.reflections.reflect(null, 'failure', 'Governance Compliance Audit', issues);
|
|
120
|
+
// Phase 3: Remediation Rituals (Transactional)
|
|
121
|
+
await this.triggerRemediation(issues, trx);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
healthy: issues.length === 0,
|
|
125
|
+
issues,
|
|
126
|
+
};
|
|
95
127
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
128
|
+
catch (e) {
|
|
129
|
+
console.error(`[GovernanceManager] STRICT AUDIT FAILURE: ${String(e)}`);
|
|
130
|
+
issues.push(`Strict Mode Failure: ${String(e)}`);
|
|
131
|
+
return { healthy: false, issues };
|
|
132
|
+
}
|
|
133
|
+
});
|
|
101
134
|
return {
|
|
102
135
|
healthy: issues.length === 0,
|
|
103
136
|
issues,
|
|
104
137
|
};
|
|
105
138
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
async getActivePersona() {
|
|
110
|
-
const active = await this.db
|
|
139
|
+
async getActivePersona(trx) {
|
|
140
|
+
const db = trx || this.db;
|
|
141
|
+
const active = await db
|
|
111
142
|
.selectFrom(this.personasTable)
|
|
112
143
|
.selectAll()
|
|
113
144
|
.where('status', '=', 'active')
|
|
@@ -122,9 +153,93 @@ export class GovernanceManager {
|
|
|
122
153
|
};
|
|
123
154
|
}
|
|
124
155
|
/**
|
|
125
|
-
*
|
|
156
|
+
* Quarantine a persona that is behaving outside safety parameters.
|
|
157
|
+
*/
|
|
158
|
+
async quarantinePersona(id, reason) {
|
|
159
|
+
console.warn(`[GovernanceManager] QUARANTINING Persona ${id}: ${reason}`);
|
|
160
|
+
await this.db.transaction().execute(async (trx) => {
|
|
161
|
+
let query = trx
|
|
162
|
+
.selectFrom(this.personasTable)
|
|
163
|
+
.selectAll()
|
|
164
|
+
.where('id', '=', id);
|
|
165
|
+
// Audit Phase 13: Atomic identity lock (Skip for SQLite)
|
|
166
|
+
if (this.db.getExecutor().adapter?.constructor.name !== 'SqliteAdapter') {
|
|
167
|
+
query = query.forUpdate();
|
|
168
|
+
}
|
|
169
|
+
const persona = await query.executeTakeFirst();
|
|
170
|
+
if (persona) {
|
|
171
|
+
const metadata = typeof persona.metadata === 'string'
|
|
172
|
+
? JSON.parse(persona.metadata)
|
|
173
|
+
: persona.metadata || {};
|
|
174
|
+
await trx
|
|
175
|
+
.updateTable(this.personasTable)
|
|
176
|
+
.set({
|
|
177
|
+
status: 'quarantined',
|
|
178
|
+
metadata: JSON.stringify({
|
|
179
|
+
...metadata,
|
|
180
|
+
quarantine_reason: reason,
|
|
181
|
+
quarantined_at: new Date(),
|
|
182
|
+
}),
|
|
183
|
+
updated_at: new Date(),
|
|
184
|
+
})
|
|
185
|
+
.where('id', '=', id)
|
|
186
|
+
.execute();
|
|
187
|
+
// Phase 3: Rollback most recent changes
|
|
188
|
+
await this.cortex.strategy.rollbackPersona(id);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Blacklist a skill that is causing systemic issues.
|
|
194
|
+
*/
|
|
195
|
+
async quarantineSkill(name, reason) {
|
|
196
|
+
const capTable = this.config.capabilitiesTable || 'agent_capabilities';
|
|
197
|
+
console.warn(`[GovernanceManager] BLACKLISTING Skill ${name}: ${reason}`);
|
|
198
|
+
await this.db
|
|
199
|
+
.updateTable(capTable)
|
|
200
|
+
.set({
|
|
201
|
+
status: 'blacklisted',
|
|
202
|
+
metadata: JSON.stringify({ blacklist_reason: reason, blacklisted_at: new Date() }),
|
|
203
|
+
updated_at: new Date()
|
|
204
|
+
})
|
|
205
|
+
.where('name', '=', name)
|
|
206
|
+
.execute();
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Monitor cross-node behaviors and flag sudden spikes or malicious patterns.
|
|
126
210
|
*/
|
|
127
|
-
async
|
|
211
|
+
async validateEmergentBehavior(trx) {
|
|
212
|
+
const issues = [];
|
|
213
|
+
const db = trx || this.db;
|
|
214
|
+
// 1. Check for rapid propagation of new skills (Potential poisoning)
|
|
215
|
+
const capTable = this.config.capabilitiesTable || 'agent_capabilities';
|
|
216
|
+
const recentSkills = await db
|
|
217
|
+
.selectFrom(capTable)
|
|
218
|
+
.select(['name', 'created_at'])
|
|
219
|
+
.where('created_at', '>', new Date(Date.now() - 3600000)) // Last hour
|
|
220
|
+
.execute();
|
|
221
|
+
if (recentSkills.length > 10) {
|
|
222
|
+
issues.push(`Emergent Warning: Rapid skill propagation detected (${recentSkills.length} new skills in 1hr). Potential rogue behavior.`);
|
|
223
|
+
}
|
|
224
|
+
// 2. Check for high variance in task success across swarm
|
|
225
|
+
const recentTaskMetrics = await db
|
|
226
|
+
.selectFrom(this.metricsTable)
|
|
227
|
+
.select(['metric_value', 'metadata'])
|
|
228
|
+
.where('metric_name', '=', 'task_success_rate')
|
|
229
|
+
.where('created_at', '>', new Date(Date.now() - 1800000)) // Last 30m
|
|
230
|
+
.execute();
|
|
231
|
+
if (recentTaskMetrics.length >= 5) {
|
|
232
|
+
const values = recentTaskMetrics.map((m) => Number(m.metric_value));
|
|
233
|
+
const mean = values.reduce((a, b) => a + b, 0) / values.length;
|
|
234
|
+
const variance = values.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / values.length;
|
|
235
|
+
if (variance > 0.2) {
|
|
236
|
+
issues.push(`Emergent Warning: High variance in swarm success rate (${(variance * 100).toFixed(1)}%). Potential node instability.`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return issues;
|
|
240
|
+
}
|
|
241
|
+
async triggerRemediation(issues, trx) {
|
|
242
|
+
const db = trx || this.db;
|
|
128
243
|
for (const issue of issues) {
|
|
129
244
|
if (issue.includes('Budget Violations')) {
|
|
130
245
|
await this.cortex.rituals.scheduleRitual('Budget Remediation', 'compression', 'hourly', `Automated response to: ${issue}`, { priority: 'critical', enforce_limits: true });
|
|
@@ -133,17 +248,36 @@ export class GovernanceManager {
|
|
|
133
248
|
await this.cortex.rituals.scheduleRitual('Reliability Sweep', 'pruning', 'daily', `Sanitizing high-noise memories due to: ${issue}`, { priority: 'medium', target: 'longtail' });
|
|
134
249
|
}
|
|
135
250
|
if (issue.includes('Integrity Failure')) {
|
|
136
|
-
//
|
|
251
|
+
// Audit Phase 10: Atomic demotion lock
|
|
137
252
|
const skillName = issue.match(/'([^']+)'/)?.[1];
|
|
138
253
|
if (skillName) {
|
|
139
254
|
console.log(`[GovernanceManager] Demoting tainted skill out of verified pool: ${skillName}`);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
255
|
+
const remediationStep = async (t) => {
|
|
256
|
+
const skill = await t
|
|
257
|
+
.selectFrom(this.config.capabilitiesTable || 'agent_capabilities')
|
|
258
|
+
.select('id')
|
|
259
|
+
.where('name', '=', skillName)
|
|
260
|
+
.forUpdate() // Lock the skill row
|
|
261
|
+
.executeTakeFirst();
|
|
262
|
+
if (skill) {
|
|
263
|
+
await t
|
|
264
|
+
.updateTable(this.config.capabilitiesTable || 'agent_capabilities')
|
|
265
|
+
.set({ status: 'experimental', updated_at: new Date() })
|
|
266
|
+
.where('id', '=', skill.id)
|
|
267
|
+
.execute();
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
if (trx) {
|
|
271
|
+
await remediationStep(trx);
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
await this.db.transaction().execute(remediationStep);
|
|
275
|
+
}
|
|
145
276
|
}
|
|
146
277
|
}
|
|
278
|
+
if (issue.includes('Quota Breach') || issue.includes('Swarm Quota Breach')) {
|
|
279
|
+
await this.cortex.rituals.scheduleRitual('Resource Throttling', 'pruning', 'hourly', `Critical resource containment: ${issue}`, { priority: 'critical', active_containment: true });
|
|
280
|
+
}
|
|
147
281
|
}
|
|
148
282
|
}
|
|
149
283
|
/**
|
|
@@ -153,7 +287,13 @@ export class GovernanceManager {
|
|
|
153
287
|
const repairs = [];
|
|
154
288
|
// 1. Check for chronic high latency
|
|
155
289
|
const latencyStats = await this.cortex.metrics.getMetricStats('query_latency');
|
|
156
|
-
|
|
290
|
+
const latencyThreshold = (await this.cortex.policies.checkPolicy('query_latency_threshold', 0)).reason ? 500 : 500; // Logic to pull from policy if possible, else 500
|
|
291
|
+
// PRODUCTION HARDENING: Pull thresholds from explicit governance policies
|
|
292
|
+
const policies = await this.cortex.policies.getActivePolicies();
|
|
293
|
+
const latencyPolicy = policies.find(p => p.name === 'latency_repair_threshold')?.definition?.threshold || 500;
|
|
294
|
+
const costPolicy = policies.find(p => p.name === 'high_cost_threshold')?.definition?.threshold || 0.5;
|
|
295
|
+
const storagePolicy = policies.find(p => p.name === 'cold_storage_threshold')?.definition?.days || 30;
|
|
296
|
+
if (latencyStats.avg > latencyPolicy && latencyStats.count > 10) {
|
|
157
297
|
repairs.push(`Average latency is high (${latencyStats.avg.toFixed(2)}ms). Suggesting index audit across hit tables.`);
|
|
158
298
|
}
|
|
159
299
|
// 2. Detect specific slow tables from recent metrics
|
|
@@ -161,7 +301,7 @@ export class GovernanceManager {
|
|
|
161
301
|
.selectFrom(this.metricsTable)
|
|
162
302
|
.select('metadata')
|
|
163
303
|
.where('metric_name', '=', 'query_latency')
|
|
164
|
-
.where('metric_value', '>',
|
|
304
|
+
.where('metric_value', '>', latencyPolicy * 2)
|
|
165
305
|
.limit(20)
|
|
166
306
|
.execute();
|
|
167
307
|
const slowTables = new Set();
|
|
@@ -182,19 +322,19 @@ export class GovernanceManager {
|
|
|
182
322
|
}
|
|
183
323
|
// 3. Check for high cost accumulation
|
|
184
324
|
const totalCost = await this.cortex.metrics.getAverageMetric('total_cost');
|
|
185
|
-
if (totalCost >
|
|
325
|
+
if (totalCost > costPolicy) {
|
|
186
326
|
repairs.push('Average query cost is high. Suggesting prompt compression or model switching (e.g., to a smaller model).');
|
|
187
327
|
}
|
|
188
328
|
// 3. Check for cold storage candidates
|
|
189
329
|
const sessionsTable = this.config.sessionsTable || 'agent_sessions';
|
|
190
|
-
const oldThreshold = new Date(Date.now() -
|
|
330
|
+
const oldThreshold = new Date(Date.now() - storagePolicy * 24 * 60 * 60 * 1000);
|
|
191
331
|
const oldSessions = (await this.db
|
|
192
332
|
.selectFrom(sessionsTable)
|
|
193
333
|
.select((eb) => eb.fn.count('id').as('count'))
|
|
194
334
|
.where('created_at', '<', oldThreshold)
|
|
195
335
|
.executeTakeFirst());
|
|
196
336
|
if (Number(oldSessions?.count || 0) > 100) {
|
|
197
|
-
repairs.push(`[STORAGE OPTIMIZATION] Found ${oldSessions.count} sessions older than
|
|
337
|
+
repairs.push(`[STORAGE OPTIMIZATION] Found ${oldSessions.count} sessions older than ${storagePolicy} days. Consider moving to cold storage to reduce primary database size and improve backup speed.`);
|
|
198
338
|
}
|
|
199
339
|
return repairs;
|
|
200
340
|
}
|
|
@@ -16,15 +16,19 @@ export declare class HiveLink {
|
|
|
16
16
|
* Promote high-confidence local knowledge to global "Hive" knowledge.
|
|
17
17
|
* This creates a new, session-agnostic entry or updates an existing global one.
|
|
18
18
|
*/
|
|
19
|
-
broadcastKnowledge(
|
|
19
|
+
broadcastKnowledge(options?: {
|
|
20
|
+
minConfidence?: number;
|
|
21
|
+
limit?: number;
|
|
22
|
+
offset?: number;
|
|
23
|
+
}): Promise<number>;
|
|
20
24
|
/**
|
|
21
25
|
* Strengthen knowledge related to a specific domain (tag).
|
|
22
26
|
* Increases confidence of all items with this tag, representing "domain mastery".
|
|
23
27
|
*/
|
|
24
28
|
syncDomain(domainTag: string, boostFactor?: number): Promise<number>;
|
|
25
29
|
/**
|
|
26
|
-
* Propagate high-performing capabilities globally
|
|
27
|
-
*
|
|
30
|
+
* Propagate high-performing capabilities globally using the "Sovereign Draft" protocol.
|
|
31
|
+
* Uses Bayesian Convergence and Shadow Promotion to avoid deadlocks.
|
|
28
32
|
*/
|
|
29
33
|
broadcastSkills(): Promise<number>;
|
|
30
34
|
/**
|