noormme 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agentic/ActionJournal.d.ts +6 -6
- package/dist/cjs/agentic/ActionJournal.js +10 -10
- package/dist/cjs/agentic/CapabilityManager.d.ts +5 -5
- package/dist/cjs/agentic/CapabilityManager.js +34 -19
- package/dist/cjs/agentic/Cortex.js +12 -13
- package/dist/cjs/agentic/PersonaManager.d.ts +4 -4
- package/dist/cjs/agentic/PersonaManager.js +18 -10
- package/dist/cjs/agentic/PolicyEnforcer.d.ts +4 -8
- package/dist/cjs/agentic/PolicyEnforcer.js +25 -22
- package/dist/cjs/agentic/improvement/AblationEngine.d.ts +7 -3
- package/dist/cjs/agentic/improvement/AblationEngine.js +51 -24
- package/dist/cjs/agentic/improvement/ActionRefiner.d.ts +1 -1
- package/dist/cjs/agentic/improvement/ActionRefiner.js +25 -15
- package/dist/cjs/agentic/improvement/EvolutionRitual.js +2 -1
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.d.ts +1 -1
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.js +17 -19
- package/dist/cjs/agentic/improvement/GovernanceManager.d.ts +5 -5
- package/dist/cjs/agentic/improvement/GovernanceManager.js +12 -22
- package/dist/cjs/agentic/improvement/HiveLink.d.ts +3 -3
- package/dist/cjs/agentic/improvement/HiveLink.js +15 -157
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.d.ts +15 -29
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.js +66 -349
- package/dist/cjs/agentic/improvement/QuotaManager.d.ts +1 -1
- package/dist/cjs/agentic/improvement/QuotaManager.js +11 -11
- package/dist/cjs/agentic/improvement/RecursiveReasoner.d.ts +4 -4
- package/dist/cjs/agentic/improvement/RecursiveReasoner.js +10 -10
- package/dist/cjs/agentic/improvement/ReflectionEngine.d.ts +2 -2
- package/dist/cjs/agentic/improvement/ReflectionEngine.js +2 -2
- package/dist/cjs/agentic/improvement/RitualOrchestrator.d.ts +3 -3
- package/dist/cjs/agentic/improvement/RitualOrchestrator.js +12 -9
- package/dist/cjs/agentic/improvement/SelfEvolution.d.ts +1 -1
- package/dist/cjs/agentic/improvement/SelfEvolution.js +21 -18
- package/dist/cjs/agentic/improvement/SelfTestRegistry.d.ts +1 -1
- package/dist/cjs/agentic/improvement/SelfTestRegistry.js +31 -19
- package/dist/cjs/agentic/improvement/SovereignMetrics.d.ts +6 -6
- package/dist/cjs/agentic/improvement/SovereignMetrics.js +12 -12
- package/dist/cjs/agentic/improvement/StrategicPlanner.d.ts +10 -54
- package/dist/cjs/agentic/improvement/StrategicPlanner.js +43 -396
- package/dist/cjs/agentic/improvement/distillation/ConflictChallenger.d.ts +3 -0
- package/dist/cjs/agentic/improvement/distillation/ConflictChallenger.js +54 -0
- package/dist/cjs/agentic/improvement/distillation/FactDistiller.d.ts +10 -0
- package/dist/cjs/agentic/improvement/distillation/FactDistiller.js +115 -0
- package/dist/cjs/agentic/improvement/distillation/KnowledgeConsolidator.d.ts +6 -0
- package/dist/cjs/agentic/improvement/distillation/KnowledgeConsolidator.js +63 -0
- package/dist/cjs/agentic/improvement/distillation/RelationshipArchitect.d.ts +6 -0
- package/dist/cjs/agentic/improvement/distillation/RelationshipArchitect.js +73 -0
- package/dist/cjs/agentic/improvement/governance/MaintenanceOracle.js +5 -5
- package/dist/cjs/agentic/improvement/governance/PersonaAuditor.js +41 -29
- package/dist/cjs/agentic/improvement/governance/RemediationEngine.js +8 -3
- package/dist/cjs/agentic/improvement/governance/SkillAuditor.js +17 -9
- package/dist/cjs/agentic/improvement/hive/DomainMaster.d.ts +4 -0
- package/dist/cjs/agentic/improvement/hive/DomainMaster.js +19 -0
- package/dist/cjs/agentic/improvement/hive/KnowledgePromoter.d.ts +6 -0
- package/dist/cjs/agentic/improvement/hive/KnowledgePromoter.js +56 -0
- package/dist/cjs/agentic/improvement/hive/SkillPropagator.d.ts +6 -0
- package/dist/cjs/agentic/improvement/hive/SkillPropagator.js +91 -0
- package/dist/cjs/agentic/improvement/strategy/EvolutionVerificator.d.ts +6 -0
- package/dist/cjs/agentic/improvement/strategy/EvolutionVerificator.js +48 -0
- package/dist/cjs/agentic/improvement/strategy/MutationEngine.d.ts +10 -0
- package/dist/cjs/agentic/improvement/strategy/MutationEngine.js +119 -0
- package/dist/cjs/agentic/improvement/strategy/PerformanceAnalyst.d.ts +6 -0
- package/dist/cjs/agentic/improvement/strategy/PerformanceAnalyst.js +84 -0
- package/dist/cjs/cli/index.js +0 -0
- package/dist/cjs/types/index.d.ts +8 -0
- package/dist/esm/agentic/ActionJournal.d.ts +6 -6
- package/dist/esm/agentic/ActionJournal.js +10 -10
- package/dist/esm/agentic/CapabilityManager.d.ts +5 -5
- package/dist/esm/agentic/CapabilityManager.js +34 -19
- package/dist/esm/agentic/Cortex.js +12 -13
- package/dist/esm/agentic/PersonaManager.d.ts +4 -4
- package/dist/esm/agentic/PersonaManager.js +18 -10
- package/dist/esm/agentic/PolicyEnforcer.d.ts +4 -8
- package/dist/esm/agentic/PolicyEnforcer.js +25 -22
- package/dist/esm/agentic/improvement/AblationEngine.d.ts +7 -3
- package/dist/esm/agentic/improvement/AblationEngine.js +51 -24
- package/dist/esm/agentic/improvement/ActionRefiner.d.ts +1 -1
- package/dist/esm/agentic/improvement/ActionRefiner.js +25 -15
- package/dist/esm/agentic/improvement/EvolutionRitual.js +2 -1
- package/dist/esm/agentic/improvement/EvolutionaryPilot.d.ts +1 -1
- package/dist/esm/agentic/improvement/EvolutionaryPilot.js +17 -19
- package/dist/esm/agentic/improvement/GovernanceManager.d.ts +5 -5
- package/dist/esm/agentic/improvement/GovernanceManager.js +12 -22
- package/dist/esm/agentic/improvement/HiveLink.d.ts +3 -3
- package/dist/esm/agentic/improvement/HiveLink.js +15 -157
- package/dist/esm/agentic/improvement/KnowledgeDistiller.d.ts +15 -29
- package/dist/esm/agentic/improvement/KnowledgeDistiller.js +66 -349
- package/dist/esm/agentic/improvement/QuotaManager.d.ts +1 -1
- package/dist/esm/agentic/improvement/QuotaManager.js +11 -11
- package/dist/esm/agentic/improvement/RecursiveReasoner.d.ts +4 -4
- package/dist/esm/agentic/improvement/RecursiveReasoner.js +10 -10
- package/dist/esm/agentic/improvement/ReflectionEngine.d.ts +2 -2
- package/dist/esm/agentic/improvement/ReflectionEngine.js +2 -2
- package/dist/esm/agentic/improvement/RitualOrchestrator.d.ts +3 -3
- package/dist/esm/agentic/improvement/RitualOrchestrator.js +12 -9
- package/dist/esm/agentic/improvement/SelfEvolution.d.ts +1 -1
- package/dist/esm/agentic/improvement/SelfEvolution.js +21 -18
- package/dist/esm/agentic/improvement/SelfTestRegistry.d.ts +1 -1
- package/dist/esm/agentic/improvement/SelfTestRegistry.js +31 -19
- package/dist/esm/agentic/improvement/SovereignMetrics.d.ts +6 -6
- package/dist/esm/agentic/improvement/SovereignMetrics.js +12 -12
- package/dist/esm/agentic/improvement/StrategicPlanner.d.ts +10 -54
- package/dist/esm/agentic/improvement/StrategicPlanner.js +43 -396
- package/dist/esm/agentic/improvement/distillation/ConflictChallenger.d.ts +3 -0
- package/dist/esm/agentic/improvement/distillation/ConflictChallenger.js +51 -0
- package/dist/esm/agentic/improvement/distillation/FactDistiller.d.ts +10 -0
- package/dist/esm/agentic/improvement/distillation/FactDistiller.js +112 -0
- package/dist/esm/agentic/improvement/distillation/KnowledgeConsolidator.d.ts +6 -0
- package/dist/esm/agentic/improvement/distillation/KnowledgeConsolidator.js +60 -0
- package/dist/esm/agentic/improvement/distillation/RelationshipArchitect.d.ts +6 -0
- package/dist/esm/agentic/improvement/distillation/RelationshipArchitect.js +70 -0
- package/dist/esm/agentic/improvement/governance/MaintenanceOracle.js +5 -5
- package/dist/esm/agentic/improvement/governance/PersonaAuditor.js +41 -29
- package/dist/esm/agentic/improvement/governance/RemediationEngine.js +8 -3
- package/dist/esm/agentic/improvement/governance/SkillAuditor.js +17 -9
- package/dist/esm/agentic/improvement/hive/DomainMaster.d.ts +4 -0
- package/dist/esm/agentic/improvement/hive/DomainMaster.js +16 -0
- package/dist/esm/agentic/improvement/hive/KnowledgePromoter.d.ts +6 -0
- package/dist/esm/agentic/improvement/hive/KnowledgePromoter.js +53 -0
- package/dist/esm/agentic/improvement/hive/SkillPropagator.d.ts +6 -0
- package/dist/esm/agentic/improvement/hive/SkillPropagator.js +88 -0
- package/dist/esm/agentic/improvement/strategy/EvolutionVerificator.d.ts +6 -0
- package/dist/esm/agentic/improvement/strategy/EvolutionVerificator.js +45 -0
- package/dist/esm/agentic/improvement/strategy/MutationEngine.d.ts +10 -0
- package/dist/esm/agentic/improvement/strategy/MutationEngine.js +116 -0
- package/dist/esm/agentic/improvement/strategy/PerformanceAnalyst.d.ts +6 -0
- package/dist/esm/agentic/improvement/strategy/PerformanceAnalyst.js +81 -0
- package/dist/esm/types/index.d.ts +8 -0
- package/package.json +40 -44
|
@@ -26,24 +26,24 @@ export declare class GovernanceManager {
|
|
|
26
26
|
/**
|
|
27
27
|
* Perform a "Panic Check" - looking for critical failures or cost overruns
|
|
28
28
|
*/
|
|
29
|
-
performAudit(): Promise<{
|
|
29
|
+
performAudit(trxOrDb?: any): Promise<{
|
|
30
30
|
healthy: boolean;
|
|
31
31
|
issues: string[];
|
|
32
32
|
}>;
|
|
33
33
|
/**
|
|
34
34
|
* Suggest architectural repairs if performance is degrading
|
|
35
35
|
*/
|
|
36
|
-
suggestRepairs(): Promise<string[]>;
|
|
36
|
+
suggestRepairs(trxOrDb?: any): Promise<string[]>;
|
|
37
37
|
/**
|
|
38
38
|
* Quarantine a persona that is behaving outside safety parameters.
|
|
39
39
|
*/
|
|
40
|
-
quarantinePersona(id: string | number, reason: string): Promise<void>;
|
|
40
|
+
quarantinePersona(id: string | number, reason: string, trxOrDb?: any): Promise<void>;
|
|
41
41
|
/**
|
|
42
42
|
* Blacklist a skill that is causing systemic issues.
|
|
43
43
|
*/
|
|
44
|
-
quarantineSkill(name: string, reason: string): Promise<void>;
|
|
44
|
+
quarantineSkill(name: string, reason: string, trxOrDb?: any): Promise<void>;
|
|
45
45
|
/**
|
|
46
46
|
* Monitor cross-node behaviors and flag sudden spikes or malicious patterns.
|
|
47
47
|
*/
|
|
48
|
-
validateEmergentBehavior(
|
|
48
|
+
validateEmergentBehavior(trxOrDb?: any): Promise<string[]>;
|
|
49
49
|
}
|
|
@@ -46,13 +46,13 @@ export class GovernanceManager {
|
|
|
46
46
|
/**
|
|
47
47
|
* Perform a "Panic Check" - looking for critical failures or cost overruns
|
|
48
48
|
*/
|
|
49
|
-
async performAudit() {
|
|
49
|
+
async performAudit(trxOrDb = this.db) {
|
|
50
50
|
const issuesList = [];
|
|
51
51
|
let auditMetadata = {};
|
|
52
52
|
// Execute core audit gathering phase
|
|
53
53
|
const ctx = {
|
|
54
54
|
db: this.db,
|
|
55
|
-
trx:
|
|
55
|
+
trx: trxOrDb,
|
|
56
56
|
cortex: this.cortex,
|
|
57
57
|
config: this.config,
|
|
58
58
|
metricsTable: this.metricsTable,
|
|
@@ -90,21 +90,11 @@ export class GovernanceManager {
|
|
|
90
90
|
// Phase 1: Emergency Rollbacks
|
|
91
91
|
if (activePersona && (success < 0.4 || hCost > hourlyLimit * 1.5)) {
|
|
92
92
|
console.error(`[GovernanceManager] CRITICAL THRESHOLD BREACH. Initiating emergency containment for persona ${activePersona.id}`);
|
|
93
|
-
await this.personaAuditor.quarantinePersona(
|
|
93
|
+
await this.personaAuditor.quarantinePersona(ctx, activePersona.id, 'Critical threshold breach');
|
|
94
94
|
issuesList.push(`Containment: Emergency rollback triggered for persona ${activePersona.id}`);
|
|
95
95
|
}
|
|
96
|
-
await this.cortex.reflections.reflect(
|
|
96
|
+
await this.cortex.reflections.reflect('system', 'failure', 'Governance Compliance Audit', issuesList, undefined, trxOrDb);
|
|
97
97
|
// Phase 3: Remediation Rituals
|
|
98
|
-
const ctx = {
|
|
99
|
-
db: this.db,
|
|
100
|
-
trx: this.db, // Standalone remediation
|
|
101
|
-
cortex: this.cortex,
|
|
102
|
-
config: this.config,
|
|
103
|
-
metricsTable: this.metricsTable,
|
|
104
|
-
policiesTable: this.policiesTable,
|
|
105
|
-
personasTable: this.personasTable,
|
|
106
|
-
skillsTable: this.skillsTable
|
|
107
|
-
};
|
|
108
98
|
await this.remediationEngine.triggerRemediation(ctx, issuesList);
|
|
109
99
|
}
|
|
110
100
|
return {
|
|
@@ -115,10 +105,10 @@ export class GovernanceManager {
|
|
|
115
105
|
/**
|
|
116
106
|
* Suggest architectural repairs if performance is degrading
|
|
117
107
|
*/
|
|
118
|
-
async suggestRepairs() {
|
|
108
|
+
async suggestRepairs(trxOrDb = this.db) {
|
|
119
109
|
const ctx = {
|
|
120
110
|
db: this.db,
|
|
121
|
-
trx:
|
|
111
|
+
trx: trxOrDb,
|
|
122
112
|
cortex: this.cortex,
|
|
123
113
|
config: this.config,
|
|
124
114
|
metricsTable: this.metricsTable,
|
|
@@ -131,10 +121,10 @@ export class GovernanceManager {
|
|
|
131
121
|
/**
|
|
132
122
|
* Quarantine a persona that is behaving outside safety parameters.
|
|
133
123
|
*/
|
|
134
|
-
async quarantinePersona(id, reason) {
|
|
124
|
+
async quarantinePersona(id, reason, trxOrDb = this.db) {
|
|
135
125
|
const ctx = {
|
|
136
126
|
db: this.db,
|
|
137
|
-
trx:
|
|
127
|
+
trx: trxOrDb,
|
|
138
128
|
cortex: this.cortex,
|
|
139
129
|
config: this.config,
|
|
140
130
|
metricsTable: this.metricsTable,
|
|
@@ -147,10 +137,10 @@ export class GovernanceManager {
|
|
|
147
137
|
/**
|
|
148
138
|
* Blacklist a skill that is causing systemic issues.
|
|
149
139
|
*/
|
|
150
|
-
async quarantineSkill(name, reason) {
|
|
140
|
+
async quarantineSkill(name, reason, trxOrDb = this.db) {
|
|
151
141
|
const ctx = {
|
|
152
142
|
db: this.db,
|
|
153
|
-
trx:
|
|
143
|
+
trx: trxOrDb,
|
|
154
144
|
cortex: this.cortex,
|
|
155
145
|
config: this.config,
|
|
156
146
|
metricsTable: this.metricsTable,
|
|
@@ -163,10 +153,10 @@ export class GovernanceManager {
|
|
|
163
153
|
/**
|
|
164
154
|
* Monitor cross-node behaviors and flag sudden spikes or malicious patterns.
|
|
165
155
|
*/
|
|
166
|
-
async validateEmergentBehavior(
|
|
156
|
+
async validateEmergentBehavior(trxOrDb = this.db) {
|
|
167
157
|
const ctx = {
|
|
168
158
|
db: this.db,
|
|
169
|
-
trx:
|
|
159
|
+
trx: trxOrDb,
|
|
170
160
|
cortex: this.cortex,
|
|
171
161
|
config: this.config,
|
|
172
162
|
metricsTable: this.metricsTable,
|
|
@@ -10,11 +10,13 @@ export declare class HiveLink {
|
|
|
10
10
|
private cortex;
|
|
11
11
|
private config;
|
|
12
12
|
private knowledgeTable;
|
|
13
|
+
private promoter;
|
|
14
|
+
private propagator;
|
|
15
|
+
private domainMaster;
|
|
13
16
|
constructor(db: Kysely<any>, cortex: Cortex, config?: AgenticConfig);
|
|
14
17
|
private get typedDb();
|
|
15
18
|
/**
|
|
16
19
|
* Promote high-confidence local knowledge to global "Hive" knowledge.
|
|
17
|
-
* This creates a new, session-agnostic entry or updates an existing global one.
|
|
18
20
|
*/
|
|
19
21
|
broadcastKnowledge(options?: {
|
|
20
22
|
minConfidence?: number;
|
|
@@ -23,12 +25,10 @@ export declare class HiveLink {
|
|
|
23
25
|
}): Promise<number>;
|
|
24
26
|
/**
|
|
25
27
|
* Strengthen knowledge related to a specific domain (tag).
|
|
26
|
-
* Increases confidence of all items with this tag, representing "domain mastery".
|
|
27
28
|
*/
|
|
28
29
|
syncDomain(domainTag: string, boostFactor?: number): Promise<number>;
|
|
29
30
|
/**
|
|
30
31
|
* Propagate high-performing capabilities globally using the "Sovereign Draft" protocol.
|
|
31
|
-
* Uses Bayesian Convergence and Shadow Promotion to avoid deadlocks.
|
|
32
32
|
*/
|
|
33
33
|
broadcastSkills(): Promise<number>;
|
|
34
34
|
/**
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference types="./HiveLink.d.ts" />
|
|
2
|
-
import {
|
|
2
|
+
import { KnowledgePromoter } from './hive/KnowledgePromoter.js';
|
|
3
|
+
import { SkillPropagator } from './hive/SkillPropagator.js';
|
|
4
|
+
import { DomainMaster } from './hive/DomainMaster.js';
|
|
3
5
|
/**
|
|
4
6
|
* HiveLink facilitates "Collective Intelligence" by synchronizing
|
|
5
7
|
* knowledge and lessons learned across different agent personas.
|
|
@@ -9,108 +11,53 @@ export class HiveLink {
|
|
|
9
11
|
cortex;
|
|
10
12
|
config;
|
|
11
13
|
knowledgeTable;
|
|
14
|
+
promoter;
|
|
15
|
+
propagator;
|
|
16
|
+
domainMaster;
|
|
12
17
|
constructor(db, cortex, config = {}) {
|
|
13
18
|
this.db = db;
|
|
14
19
|
this.cortex = cortex;
|
|
15
20
|
this.config = config;
|
|
16
21
|
this.knowledgeTable = config.knowledgeTable || 'agent_knowledge_base';
|
|
22
|
+
this.promoter = new KnowledgePromoter();
|
|
23
|
+
this.propagator = new SkillPropagator();
|
|
24
|
+
this.domainMaster = new DomainMaster();
|
|
17
25
|
}
|
|
18
26
|
get typedDb() {
|
|
19
27
|
return this.db;
|
|
20
28
|
}
|
|
21
29
|
/**
|
|
22
30
|
* Promote high-confidence local knowledge to global "Hive" knowledge.
|
|
23
|
-
* This creates a new, session-agnostic entry or updates an existing global one.
|
|
24
31
|
*/
|
|
25
32
|
async broadcastKnowledge(options = {}) {
|
|
26
33
|
const minConfidence = options.minConfidence ?? 0.9;
|
|
27
34
|
const limit = options.limit ?? 100;
|
|
28
35
|
const offset = options.offset ?? 0;
|
|
29
36
|
console.log(`[HiveLink] Broadcasting knowledge (limit=${limit}, offset=${offset}) with confidence >= ${minConfidence}`);
|
|
30
|
-
// Find high-confidence items that are "local" (have a source_session_id)
|
|
31
37
|
const items = (await this.typedDb
|
|
32
38
|
.selectFrom(this.knowledgeTable)
|
|
33
39
|
.selectAll()
|
|
34
40
|
.where('confidence', '>=', minConfidence)
|
|
35
|
-
.where('source_session_id', 'is not', null)
|
|
41
|
+
.where('source_session_id', 'is not', null)
|
|
36
42
|
.limit(limit)
|
|
37
43
|
.offset(offset)
|
|
38
44
|
.execute());
|
|
39
45
|
let promotedCount = 0;
|
|
40
46
|
for (const item of items) {
|
|
41
|
-
await this.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.selectFrom(this.knowledgeTable)
|
|
45
|
-
.selectAll()
|
|
46
|
-
.where('entity', '=', item.entity)
|
|
47
|
-
.where('fact', '=', item.fact)
|
|
48
|
-
.where('source_session_id', 'is', null)
|
|
49
|
-
.forUpdate() // Audit Phase 15: prevent concurrent promotion duplication
|
|
50
|
-
.executeTakeFirst();
|
|
51
|
-
if (existingGlobal) {
|
|
52
|
-
// Reinforce existing global knowledge
|
|
53
|
-
const newConfidence = Math.min(0.99, Math.max(existingGlobal.confidence, item.confidence) + 0.01);
|
|
54
|
-
await trx
|
|
55
|
-
.updateTable(this.knowledgeTable)
|
|
56
|
-
.set({
|
|
57
|
-
confidence: newConfidence,
|
|
58
|
-
updated_at: new Date(),
|
|
59
|
-
})
|
|
60
|
-
.where('id', '=', existingGlobal.id)
|
|
61
|
-
.execute();
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
// Create new global knowledge
|
|
65
|
-
const tags = item.tags ? [...item.tags] : [];
|
|
66
|
-
if (!tags.includes('hive_mind'))
|
|
67
|
-
tags.push('hive_mind');
|
|
68
|
-
await trx
|
|
69
|
-
.insertInto(this.knowledgeTable)
|
|
70
|
-
.values({
|
|
71
|
-
entity: item.entity,
|
|
72
|
-
fact: item.fact,
|
|
73
|
-
confidence: item.confidence,
|
|
74
|
-
source_session_id: null,
|
|
75
|
-
tags: JSON.stringify(tags),
|
|
76
|
-
metadata: JSON.stringify({
|
|
77
|
-
...item.metadata,
|
|
78
|
-
promoted_from: item.id,
|
|
79
|
-
promoted_at: new Date(),
|
|
80
|
-
}),
|
|
81
|
-
created_at: new Date(),
|
|
82
|
-
updated_at: new Date(),
|
|
83
|
-
})
|
|
84
|
-
.execute();
|
|
85
|
-
promotedCount++;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
47
|
+
const promoted = await this.promoter.promote(this.db, this.cortex, this.config, this.knowledgeTable, item);
|
|
48
|
+
if (promoted)
|
|
49
|
+
promotedCount++;
|
|
88
50
|
}
|
|
89
51
|
return promotedCount;
|
|
90
52
|
}
|
|
91
53
|
/**
|
|
92
54
|
* Strengthen knowledge related to a specific domain (tag).
|
|
93
|
-
* Increases confidence of all items with this tag, representing "domain mastery".
|
|
94
55
|
*/
|
|
95
56
|
async syncDomain(domainTag, boostFactor = 0.05) {
|
|
96
|
-
|
|
97
|
-
// Use a single SQL update for high throughput
|
|
98
|
-
const result = await this.db
|
|
99
|
-
.updateTable(this.knowledgeTable)
|
|
100
|
-
.set({
|
|
101
|
-
confidence: sql `MIN(1.0, confidence + ${boostFactor})`,
|
|
102
|
-
updated_at: new Date(),
|
|
103
|
-
})
|
|
104
|
-
.where('tags', 'like', `%"${domainTag}"%`)
|
|
105
|
-
.where('confidence', '<', 1.0)
|
|
106
|
-
.execute();
|
|
107
|
-
// Kysely update .execute() returns an array of results or similar depending on adapter
|
|
108
|
-
// For simple update, we might just return the count if supported or 1
|
|
109
|
-
return Number(result[0]?.numUpdatedRows ?? 1);
|
|
57
|
+
return this.domainMaster.boostDomain(this.db, this.knowledgeTable, domainTag, boostFactor);
|
|
110
58
|
}
|
|
111
59
|
/**
|
|
112
60
|
* Propagate high-performing capabilities globally using the "Sovereign Draft" protocol.
|
|
113
|
-
* Uses Bayesian Convergence and Shadow Promotion to avoid deadlocks.
|
|
114
61
|
*/
|
|
115
62
|
async broadcastSkills() {
|
|
116
63
|
if (!this.config.evolution?.enableHiveLink &&
|
|
@@ -119,96 +66,7 @@ export class HiveLink {
|
|
|
119
66
|
return 0;
|
|
120
67
|
}
|
|
121
68
|
console.log(`[HiveLink] Executing Sovereign Draft for emergent skills...`);
|
|
122
|
-
|
|
123
|
-
const capTable = this.config.capabilitiesTable || 'agent_capabilities';
|
|
124
|
-
// 1. Resolve Verified Skills with Bayesian "Alpha" selection
|
|
125
|
-
const verifiedSkills = await this.cortex.capabilities.getCapabilities('verified');
|
|
126
|
-
// Group verified skills by lineage (base tool name)
|
|
127
|
-
const lineageGroups = new Map();
|
|
128
|
-
for (const skill of verifiedSkills) {
|
|
129
|
-
const meta = typeof skill.metadata === 'string' ? JSON.parse(skill.metadata) : (skill.metadata || {});
|
|
130
|
-
const lineage = meta.lineage || skill.name;
|
|
131
|
-
if (!lineageGroups.has(lineage))
|
|
132
|
-
lineageGroups.set(lineage, []);
|
|
133
|
-
lineageGroups.get(lineage).push({ skill, meta });
|
|
134
|
-
}
|
|
135
|
-
for (const [lineage, variants] of lineageGroups.entries()) {
|
|
136
|
-
// Bayesian Winner Selection
|
|
137
|
-
// Score = (anchored_reliability * totalCount + K * prior) / (totalCount + K)
|
|
138
|
-
// For simplicity, we use anchored_reliability which already incorporates this weighting
|
|
139
|
-
const alphaCandidate = variants.reduce((prev, curr) => {
|
|
140
|
-
const pAnchored = prev.meta.anchored_reliability ?? 0;
|
|
141
|
-
const cAnchored = curr.meta.anchored_reliability ?? 0;
|
|
142
|
-
return cAnchored > pAnchored ? curr : prev;
|
|
143
|
-
});
|
|
144
|
-
// Non-Blocking Set Update: Flag Alpha and Shadow versions
|
|
145
|
-
await this.db.transaction().execute(async (trx) => {
|
|
146
|
-
const currentMeta = alphaCandidate.meta || {};
|
|
147
|
-
const updatedMeta = {
|
|
148
|
-
...currentMeta,
|
|
149
|
-
is_alpha: true,
|
|
150
|
-
broadcasted: true,
|
|
151
|
-
broadcasted_at: new Date()
|
|
152
|
-
};
|
|
153
|
-
// Flag the winner as Alpha
|
|
154
|
-
// Audit Phase 15: Lock candidate before promotion
|
|
155
|
-
const winner = await trx
|
|
156
|
-
.selectFrom(capTable)
|
|
157
|
-
.select('id')
|
|
158
|
-
.where('id', '=', alphaCandidate.skill.id)
|
|
159
|
-
.forUpdate()
|
|
160
|
-
.executeTakeFirst();
|
|
161
|
-
if (winner) {
|
|
162
|
-
await trx
|
|
163
|
-
.updateTable(capTable)
|
|
164
|
-
.set({
|
|
165
|
-
metadata: JSON.stringify(updatedMeta),
|
|
166
|
-
})
|
|
167
|
-
.where('id', '=', winner.id)
|
|
168
|
-
.execute();
|
|
169
|
-
}
|
|
170
|
-
// Flag others in the same lineage as Shadow (Dialect-safe approach)
|
|
171
|
-
const shadowIds = variants
|
|
172
|
-
.filter(v => v.skill.id !== alphaCandidate.skill.id)
|
|
173
|
-
.map(v => v.skill.id);
|
|
174
|
-
if (shadowIds.length > 0) {
|
|
175
|
-
// We fetch and update individually or use a bulk update if the dialect supports complex JSON manipulation.
|
|
176
|
-
// For maximum compatibility (Postgres/SQLite), we do it in a loop for the shadows if the count is small.
|
|
177
|
-
for (const sid of shadowIds) {
|
|
178
|
-
const sMatch = variants.find(v => v.skill.id === sid);
|
|
179
|
-
const sMeta = sMatch?.meta || {};
|
|
180
|
-
await trx.updateTable(capTable)
|
|
181
|
-
.set({
|
|
182
|
-
metadata: JSON.stringify({ ...sMeta, is_alpha: false, is_shadow: true }),
|
|
183
|
-
status: 'experimental'
|
|
184
|
-
})
|
|
185
|
-
.where('id', '=', sid)
|
|
186
|
-
.execute();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
broadcastCount += variants.length;
|
|
191
|
-
}
|
|
192
|
-
// 2. Broadcast Blacklisted Skills (Immune Prophet)
|
|
193
|
-
const blacklisted = await this.cortex.capabilities.getCapabilities('blacklisted');
|
|
194
|
-
const blackIDs = blacklisted
|
|
195
|
-
.filter(s => {
|
|
196
|
-
const meta = typeof s.metadata === 'string' ? JSON.parse(s.metadata) : (s.metadata || {});
|
|
197
|
-
return !meta.broadcasted;
|
|
198
|
-
})
|
|
199
|
-
.map(s => s.id);
|
|
200
|
-
if (blackIDs.length > 0) {
|
|
201
|
-
await this.db
|
|
202
|
-
.updateTable(capTable)
|
|
203
|
-
.set({
|
|
204
|
-
metadata: sql `json_set(metadata, '$.broadcasted', true, '$.hive_blacklisted', true)`,
|
|
205
|
-
updated_at: new Date()
|
|
206
|
-
})
|
|
207
|
-
.where('id', 'in', blackIDs)
|
|
208
|
-
.execute();
|
|
209
|
-
broadcastCount += blackIDs.length;
|
|
210
|
-
}
|
|
211
|
-
return broadcastCount;
|
|
69
|
+
return this.propagator.propagate(this.db, this.cortex, this.config);
|
|
212
70
|
}
|
|
213
71
|
/**
|
|
214
72
|
* Simple semver-style version comparison.
|
|
@@ -35,50 +35,33 @@ export declare class KnowledgeDistiller {
|
|
|
35
35
|
private knowledgeTable;
|
|
36
36
|
private linksTable;
|
|
37
37
|
private bloomFilter;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
private get typedDb();
|
|
38
|
+
private distiller;
|
|
39
|
+
private challenger;
|
|
40
|
+
private architect;
|
|
41
|
+
private consolidator;
|
|
42
|
+
constructor(db: Kysely<any>, config?: AgenticConfig);
|
|
44
43
|
/**
|
|
45
44
|
* Add or update a knowledge item with robust merging and transaction support.
|
|
46
45
|
*/
|
|
47
46
|
distill(entity: string, fact: string, confidence: number, sourceSessionId?: string | number, tags?: string[], metadata?: Record<string, any>, source?: 'user' | 'assistant' | 'system'): Promise<KnowledgeItem>;
|
|
47
|
+
/**
|
|
48
|
+
* Manually challenge an existing fact with competing information.
|
|
49
|
+
*/
|
|
50
|
+
challengeKnowledge(entity: string, fact: string, confidence: number, trxOrDb?: any): Promise<void>;
|
|
48
51
|
/**
|
|
49
52
|
* Verify and reinforce existing knowledge.
|
|
50
|
-
* Increases confidence if the fact matches.
|
|
51
53
|
*/
|
|
52
54
|
verifyKnowledge(id: number | string, reinforcement?: number): Promise<KnowledgeItem | null>;
|
|
53
55
|
/**
|
|
54
56
|
* Search knowledge by entity with optional tag filtering.
|
|
55
|
-
* Records a "hit" for each retrieved item to track utility.
|
|
56
57
|
*/
|
|
57
58
|
getKnowledgeByEntity(entity: string, filterTags?: string[]): Promise<KnowledgeItem[]>;
|
|
58
59
|
/**
|
|
59
|
-
* Record a retrieval hit for a knowledge item.
|
|
60
|
+
* Record a retrieval hit for a knowledge item and emit hotspot telemetry.
|
|
60
61
|
*/
|
|
61
62
|
recordHit(id: number | string): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Calculate the "Fitness" of a memory item.
|
|
64
|
-
* Score = (Confidence * 0.4) + (SignalToNoise * 0.4) + (SourceMultiplier * 0.2)
|
|
65
|
-
*/
|
|
66
|
-
calculateFitness(item: KnowledgeItem): number;
|
|
67
|
-
/**
|
|
68
|
-
* Challenge existing knowledge with new evidence.
|
|
69
|
-
* If confidence of new fact is high and contradicts existing ones (same entity, different fact),
|
|
70
|
-
* we degrade the confidence of the old facts.
|
|
71
|
-
*/
|
|
72
|
-
challengeKnowledge(entity: string, competingFact: string, confidence: number, trxOrDb?: any): Promise<void>;
|
|
73
|
-
/**
|
|
74
|
-
* Automatic Semantic Linking
|
|
75
|
-
* Scans for entity mentions in facts and creates links.
|
|
76
|
-
* Production Hardening: Uses batched cross-similarity and NER-style tokenization.
|
|
77
|
-
*/
|
|
78
|
-
private autoLinkKnowledge;
|
|
79
63
|
/**
|
|
80
64
|
* Link two knowledge items together with a relationship.
|
|
81
|
-
* Transaction-aware version.
|
|
82
65
|
*/
|
|
83
66
|
linkKnowledge(sourceId: number | string, targetId: number | string, relationship: string, metadata?: Record<string, any>, trxOrDb?: any): Promise<void>;
|
|
84
67
|
/**
|
|
@@ -97,10 +80,13 @@ export declare class KnowledgeDistiller {
|
|
|
97
80
|
pruneLowConfidence(threshold?: number): Promise<number>;
|
|
98
81
|
/**
|
|
99
82
|
* Consolidate knowledge by merging similar facts for the same entity.
|
|
100
|
-
* Production Hardening: Iterative bucketed approach to avoid recursive stack issues.
|
|
101
83
|
*/
|
|
102
84
|
consolidateKnowledge(): Promise<number>;
|
|
103
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Calculate the "Fitness" of a knowledge item.
|
|
87
|
+
* Score = (Confidence * 0.4) + (SignalToNoise * 0.4) + (SourceMultiplier * 0.2)
|
|
88
|
+
*/
|
|
89
|
+
calculateFitness(item: KnowledgeItem): number;
|
|
104
90
|
private bloomHash;
|
|
105
91
|
private parseKnowledge;
|
|
106
92
|
}
|