noormme 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agentic/improvement/GovernanceManager.d.ts +14 -6
- package/dist/cjs/agentic/improvement/GovernanceManager.js +133 -294
- package/dist/cjs/agentic/improvement/QuotaManager.js +1 -1
- package/dist/cjs/agentic/improvement/SelfEvolution.js +1 -0
- 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 +86 -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 +60 -0
- package/dist/cjs/cli/index.js +0 -0
- package/dist/cjs/helpers/agent-schema.js +14 -14
- package/dist/esm/agentic/improvement/GovernanceManager.d.ts +14 -6
- package/dist/esm/agentic/improvement/GovernanceManager.js +133 -294
- package/dist/esm/agentic/improvement/QuotaManager.js +1 -1
- package/dist/esm/agentic/improvement/SelfEvolution.js +1 -0
- 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 +83 -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 +57 -0
- package/dist/esm/helpers/agent-schema.js +14 -14
- package/package.json +44 -40
|
@@ -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,86 @@
|
|
|
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
|
+
// Use the provided transaction or start a new one to ensure atomicity
|
|
45
|
+
const runner = async (trx) => {
|
|
46
|
+
let query = trx
|
|
47
|
+
.selectFrom(ctx.personasTable)
|
|
48
|
+
.selectAll()
|
|
49
|
+
.where('id', '=', id);
|
|
50
|
+
// Audit Phase 16: Exclusive lock for containment (Skip for SQLite)
|
|
51
|
+
const executor = ctx.db.getExecutor();
|
|
52
|
+
const adapterName = executor?.adapter?.constructor?.name || executor?.dialect?.constructor?.name || '';
|
|
53
|
+
if (!adapterName.toLowerCase().includes('sqlite')) {
|
|
54
|
+
query = query.forUpdate();
|
|
55
|
+
}
|
|
56
|
+
const persona = await query.executeTakeFirst();
|
|
57
|
+
if (persona) {
|
|
58
|
+
const metadata = typeof persona.metadata === 'string'
|
|
59
|
+
? JSON.parse(persona.metadata)
|
|
60
|
+
: persona.metadata || {};
|
|
61
|
+
await trx
|
|
62
|
+
.updateTable(ctx.personasTable)
|
|
63
|
+
.set({
|
|
64
|
+
status: 'quarantined',
|
|
65
|
+
metadata: JSON.stringify({
|
|
66
|
+
...metadata,
|
|
67
|
+
quarantine_reason: reason,
|
|
68
|
+
quarantined_at: new Date(),
|
|
69
|
+
}),
|
|
70
|
+
updated_at: new Date(),
|
|
71
|
+
})
|
|
72
|
+
.where('id', '=', id)
|
|
73
|
+
.execute();
|
|
74
|
+
// Rollback most recent changes via strategy engine
|
|
75
|
+
await ctx.cortex.strategy.rollbackPersona(id);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
if (ctx.trx && ctx.trx !== ctx.db) {
|
|
79
|
+
await runner(ctx.trx);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
await ctx.db.transaction().execute((trx) => runner(trx));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
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,60 @@
|
|
|
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
|
+
const runner = async (trx) => {
|
|
42
|
+
await trx
|
|
43
|
+
.updateTable(ctx.skillsTable)
|
|
44
|
+
.set({
|
|
45
|
+
status: 'blacklisted',
|
|
46
|
+
metadata: JSON.stringify({ blacklist_reason: reason, blacklisted_at: new Date() }),
|
|
47
|
+
updated_at: new Date()
|
|
48
|
+
})
|
|
49
|
+
.where('name', '=', name)
|
|
50
|
+
.execute();
|
|
51
|
+
};
|
|
52
|
+
if (ctx.trx && ctx.trx !== ctx.db) {
|
|
53
|
+
await runner(ctx.trx);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
await ctx.db.transaction().execute((trx) => runner(trx));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.SkillAuditor = SkillAuditor;
|
package/dist/cjs/cli/index.js
CHANGED
|
File without changes
|
|
@@ -51,7 +51,7 @@ class AgentSchemaHelper {
|
|
|
51
51
|
.createTable(messagesTable)
|
|
52
52
|
.ifNotExists()
|
|
53
53
|
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
|
|
54
|
-
.addColumn('session_id', '
|
|
54
|
+
.addColumn('session_id', 'text')
|
|
55
55
|
.addColumn('role', 'text', (col) => col.notNull())
|
|
56
56
|
.addColumn('content', 'text', (col) => col.notNull())
|
|
57
57
|
.addColumn('metadata', 'text')
|
|
@@ -62,7 +62,7 @@ class AgentSchemaHelper {
|
|
|
62
62
|
.createTable(goalsTable)
|
|
63
63
|
.ifNotExists()
|
|
64
64
|
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
|
|
65
|
-
.addColumn('session_id', '
|
|
65
|
+
.addColumn('session_id', 'text')
|
|
66
66
|
.addColumn('parent_id', 'integer', (col) => col.references(`${goalsTable}.id`).onDelete('cascade'))
|
|
67
67
|
.addColumn('description', 'text', (col) => col.notNull())
|
|
68
68
|
.addColumn('status', 'text', (col) => col.notNull().defaultTo('pending'))
|
|
@@ -76,7 +76,7 @@ class AgentSchemaHelper {
|
|
|
76
76
|
.createTable(memoriesTable)
|
|
77
77
|
.ifNotExists()
|
|
78
78
|
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
|
|
79
|
-
.addColumn('session_id', '
|
|
79
|
+
.addColumn('session_id', 'text')
|
|
80
80
|
.addColumn('content', 'text', (col) => col.notNull())
|
|
81
81
|
.addColumn('embedding', 'text') // In Postgres with pgvector, this would be 'vector(D)'
|
|
82
82
|
.addColumn('metadata', 'text')
|
|
@@ -87,7 +87,7 @@ class AgentSchemaHelper {
|
|
|
87
87
|
.createTable(reflectionsTable)
|
|
88
88
|
.ifNotExists()
|
|
89
89
|
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
|
|
90
|
-
.addColumn('session_id', '
|
|
90
|
+
.addColumn('session_id', 'text')
|
|
91
91
|
.addColumn('outcome', 'text', (col) => col.notNull())
|
|
92
92
|
.addColumn('lessons_learned', 'text', (col) => col.notNull())
|
|
93
93
|
.addColumn('suggested_actions', 'text')
|
|
@@ -102,7 +102,7 @@ class AgentSchemaHelper {
|
|
|
102
102
|
.addColumn('entity', 'text', (col) => col.notNull())
|
|
103
103
|
.addColumn('fact', 'text', (col) => col.notNull())
|
|
104
104
|
.addColumn('confidence', 'real', (col) => col.notNull().defaultTo(1.0))
|
|
105
|
-
.addColumn('source_session_id', '
|
|
105
|
+
.addColumn('source_session_id', 'text')
|
|
106
106
|
.addColumn('status', 'text', (col) => col.notNull().defaultTo('proposed'))
|
|
107
107
|
.addColumn('tags', 'text')
|
|
108
108
|
.addColumn('metadata', 'text')
|
|
@@ -114,8 +114,8 @@ class AgentSchemaHelper {
|
|
|
114
114
|
.createTable(actionsTable)
|
|
115
115
|
.ifNotExists()
|
|
116
116
|
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
|
|
117
|
-
.addColumn('session_id', '
|
|
118
|
-
.addColumn('message_id', 'integer'
|
|
117
|
+
.addColumn('session_id', 'text')
|
|
118
|
+
.addColumn('message_id', 'integer')
|
|
119
119
|
.addColumn('tool_name', 'text', (col) => col.notNull())
|
|
120
120
|
.addColumn('arguments', 'text', (col) => col.notNull())
|
|
121
121
|
.addColumn('outcome', 'text')
|
|
@@ -129,7 +129,7 @@ class AgentSchemaHelper {
|
|
|
129
129
|
.createTable(episodesTable)
|
|
130
130
|
.ifNotExists()
|
|
131
131
|
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
|
|
132
|
-
.addColumn('session_id', '
|
|
132
|
+
.addColumn('session_id', 'text')
|
|
133
133
|
.addColumn('name', 'text', (col) => col.notNull())
|
|
134
134
|
.addColumn('summary', 'text')
|
|
135
135
|
.addColumn('status', 'text', (col) => col.notNull().defaultTo('active'))
|
|
@@ -142,7 +142,7 @@ class AgentSchemaHelper {
|
|
|
142
142
|
.createTable(resourcesTable)
|
|
143
143
|
.ifNotExists()
|
|
144
144
|
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
|
|
145
|
-
.addColumn('session_id', '
|
|
145
|
+
.addColumn('session_id', 'text')
|
|
146
146
|
.addColumn('agent_id', 'text')
|
|
147
147
|
.addColumn('model_name', 'text', (col) => col.notNull())
|
|
148
148
|
.addColumn('input_tokens', 'integer', (col) => col.notNull().defaultTo(0))
|
|
@@ -173,7 +173,7 @@ class AgentSchemaHelper {
|
|
|
173
173
|
.addColumn('name', 'text', (col) => col.notNull())
|
|
174
174
|
.addColumn('type', 'text', (col) => col.notNull())
|
|
175
175
|
.addColumn('definition', 'text', (col) => col.notNull())
|
|
176
|
-
.addColumn('
|
|
176
|
+
.addColumn('is_enabled', 'integer', (col) => col.notNull().defaultTo(1))
|
|
177
177
|
.addColumn('metadata', 'text')
|
|
178
178
|
.addColumn('created_at', 'timestamp', (col) => col.notNull())
|
|
179
179
|
.addColumn('updated_at', 'timestamp', (col) => col.notNull())
|
|
@@ -183,7 +183,7 @@ class AgentSchemaHelper {
|
|
|
183
183
|
.createTable(metricsTable)
|
|
184
184
|
.ifNotExists()
|
|
185
185
|
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
|
|
186
|
-
.addColumn('session_id', '
|
|
186
|
+
.addColumn('session_id', 'text')
|
|
187
187
|
.addColumn('agent_id', 'text')
|
|
188
188
|
.addColumn('metric_name', 'text', (col) => col.notNull())
|
|
189
189
|
.addColumn('metric_value', 'real', (col) => col.notNull())
|
|
@@ -210,7 +210,7 @@ class AgentSchemaHelper {
|
|
|
210
210
|
.createTable(epochsTable)
|
|
211
211
|
.ifNotExists()
|
|
212
212
|
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
|
|
213
|
-
.addColumn('session_id', '
|
|
213
|
+
.addColumn('session_id', 'text')
|
|
214
214
|
.addColumn('summary', 'text', (col) => col.notNull())
|
|
215
215
|
.addColumn('start_message_id', 'integer', (col) => col.notNull())
|
|
216
216
|
.addColumn('end_message_id', 'integer', (col) => col.notNull())
|
|
@@ -237,11 +237,11 @@ class AgentSchemaHelper {
|
|
|
237
237
|
.createTable(rulesTable)
|
|
238
238
|
.ifNotExists()
|
|
239
239
|
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
|
|
240
|
-
.addColumn('
|
|
240
|
+
.addColumn('table_name', 'text', (col) => col.notNull())
|
|
241
241
|
.addColumn('operation', 'text', (col) => col.notNull())
|
|
242
242
|
.addColumn('action', 'text', (col) => col.notNull())
|
|
243
243
|
.addColumn('script', 'text')
|
|
244
|
-
.addColumn('
|
|
244
|
+
.addColumn('is_enabled', 'integer', (col) => col.notNull().defaultTo(1))
|
|
245
245
|
.addColumn('metadata', 'text')
|
|
246
246
|
.addColumn('created_at', 'timestamp', (col) => col.notNull())
|
|
247
247
|
.execute();
|
|
@@ -4,6 +4,8 @@ import type { Cortex } from '../Cortex.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* GovernanceManager monitors agent performance and enforces high-level "sanity"
|
|
6
6
|
* across the entire agentic infrastructure.
|
|
7
|
+
*
|
|
8
|
+
* Refactored to delegate specialized auditing to modular components.
|
|
7
9
|
*/
|
|
8
10
|
export declare class GovernanceManager {
|
|
9
11
|
private db;
|
|
@@ -12,6 +14,14 @@ export declare class GovernanceManager {
|
|
|
12
14
|
private metricsTable;
|
|
13
15
|
private policiesTable;
|
|
14
16
|
private personasTable;
|
|
17
|
+
private skillsTable;
|
|
18
|
+
private budgetAuditor;
|
|
19
|
+
private performanceAuditor;
|
|
20
|
+
private personaAuditor;
|
|
21
|
+
private skillAuditor;
|
|
22
|
+
private emergenceAuditor;
|
|
23
|
+
private remediationEngine;
|
|
24
|
+
private maintenanceOracle;
|
|
15
25
|
constructor(db: Kysely<any>, cortex: Cortex, config?: AgenticConfig);
|
|
16
26
|
/**
|
|
17
27
|
* Perform a "Panic Check" - looking for critical failures or cost overruns
|
|
@@ -20,7 +30,10 @@ export declare class GovernanceManager {
|
|
|
20
30
|
healthy: boolean;
|
|
21
31
|
issues: string[];
|
|
22
32
|
}>;
|
|
23
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Suggest architectural repairs if performance is degrading
|
|
35
|
+
*/
|
|
36
|
+
suggestRepairs(): Promise<string[]>;
|
|
24
37
|
/**
|
|
25
38
|
* Quarantine a persona that is behaving outside safety parameters.
|
|
26
39
|
*/
|
|
@@ -33,9 +46,4 @@ export declare class GovernanceManager {
|
|
|
33
46
|
* Monitor cross-node behaviors and flag sudden spikes or malicious patterns.
|
|
34
47
|
*/
|
|
35
48
|
validateEmergentBehavior(trx?: any): Promise<string[]>;
|
|
36
|
-
private triggerRemediation;
|
|
37
|
-
/**
|
|
38
|
-
* Suggest architectural repairs if performance is degrading
|
|
39
|
-
*/
|
|
40
|
-
suggestRepairs(): Promise<string[]>;
|
|
41
49
|
}
|