mindforge-cc 7.0.0 → 8.1.0
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/.agent/CLAUDE.md +4 -3
- package/.agent/workflows/mindforge:init-project.md +19 -3
- package/.agent/workflows/mindforge:soul.md +54 -0
- package/.mindforge/config.json +50 -10
- package/.planning/AUDIT.jsonl +15 -0
- package/CHANGELOG.md +34 -0
- package/MINDFORGE.md +5 -4
- package/README.md +40 -28
- package/RELEASENOTES.md +45 -0
- package/bin/engine/mesh-syncer.js +129 -0
- package/bin/engine/nexus-tracer.js +23 -1
- package/bin/engine/orbital-guardian.js +84 -0
- package/bin/engine/skill-evolver.js +105 -0
- package/bin/governance/config-manager.js +26 -0
- package/bin/governance/policy-gate-hardened.js +30 -49
- package/bin/memory/identity-synthesizer.js +146 -0
- package/bin/memory/semantic-hub.js +107 -5
- package/bin/memory/vector-hub.js +170 -0
- package/bin/migrations/v8-sqlite-migration.js +85 -0
- package/bin/revops/remediation-queue.js +48 -24
- package/docs/INTELLIGENCE-MESH.md +13 -13
- package/docs/usp-features.md +12 -4
- package/package.json +6 -4
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MindForge v8 — Orbital Governance
|
|
3
|
+
* Component: Orbital Guardian (Pillar XVIII)
|
|
4
|
+
*
|
|
5
|
+
* Manages hardware-bound/biometric attestations for high-blast-radius actions.
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const vectorHub = require('../memory/vector-hub');
|
|
10
|
+
const ztaiManager = require('../governance/ztai-manager');
|
|
11
|
+
const crypto = require('node:crypto');
|
|
12
|
+
|
|
13
|
+
class OrbitalGuardian {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.vhInitialized = false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async ensureInit() {
|
|
19
|
+
if (!this.vhInitialized) {
|
|
20
|
+
await vectorHub.init();
|
|
21
|
+
this.vhInitialized = true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Generates a new hardware-attested approval report.
|
|
27
|
+
* Mimics a biometric/HSM handshake.
|
|
28
|
+
*/
|
|
29
|
+
async attest(requestId, did, payload) {
|
|
30
|
+
await this.ensureInit();
|
|
31
|
+
console.log(`[ORBITAL-GUARDIAN] Requesting Hardware Attestation for [${requestId}] via [${did}]`);
|
|
32
|
+
|
|
33
|
+
const agent = ztaiManager.getAgent(did);
|
|
34
|
+
if (!agent || agent.tier < 3) {
|
|
35
|
+
throw new Error(`[ORBITAL-GUARDIAN] DID ${did} has insufficient Trust Tier for Orbital Attestation.`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 1. Sign the attestation payload using the Hardware Enclave provider
|
|
39
|
+
const attestationPayload = await ztaiManager.signData(did, JSON.stringify({
|
|
40
|
+
requestId,
|
|
41
|
+
payload,
|
|
42
|
+
timestamp: new Date().toISOString()
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
const attestation = {
|
|
46
|
+
id: `att_${crypto.randomBytes(4).toString('hex')}`,
|
|
47
|
+
request_id: requestId,
|
|
48
|
+
status: 'APPROVED',
|
|
49
|
+
attestation_payload: attestationPayload,
|
|
50
|
+
timestamp: new Date().toISOString()
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// 2. Persist to SQLite (Source of truth for v8 Governance Dashboard)
|
|
54
|
+
await vectorHub.db.insertInto('attestations')
|
|
55
|
+
.values(attestation)
|
|
56
|
+
.execute();
|
|
57
|
+
|
|
58
|
+
console.log(`[ORBITAL-GUARDIAN] Attestation SUCCESS: ${attestation.id}`);
|
|
59
|
+
return attestation;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Verifies if a request has a valid hardware bypass.
|
|
64
|
+
*/
|
|
65
|
+
async verify(requestId) {
|
|
66
|
+
await this.ensureInit();
|
|
67
|
+
|
|
68
|
+
const record = await vectorHub.db.selectFrom('attestations')
|
|
69
|
+
.selectAll()
|
|
70
|
+
.where('request_id', '=', requestId)
|
|
71
|
+
.where('status', '=', 'APPROVED')
|
|
72
|
+
.executeTakeFirst();
|
|
73
|
+
|
|
74
|
+
if (!record) return { verified: false };
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
verified: true,
|
|
78
|
+
id: record.id,
|
|
79
|
+
timestamp: record.timestamp
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = new OrbitalGuardian();
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MindForge v8 — Autonomous Skill Evolution (ASE)
|
|
3
|
+
* Component: Skill Evolver (Pillar XVII)
|
|
4
|
+
*
|
|
5
|
+
* Mines successful reasoning patterns to synthesize new reusable skills.
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const vectorHub = require('../memory/vector-hub');
|
|
10
|
+
const semanticHub = require('../memory/semantic-hub');
|
|
11
|
+
const configManager = require('../governance/config-manager');
|
|
12
|
+
const crypto = require('node:crypto');
|
|
13
|
+
|
|
14
|
+
class SkillEvolver {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.vhInitialized = false;
|
|
17
|
+
this.threshold = configManager.get('ase.max_drift_threshold', 0.1);
|
|
18
|
+
this.minCount = configManager.get('ase.min_success_count', 3);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async ensureInit() {
|
|
22
|
+
if (!this.vhInitialized) {
|
|
23
|
+
await vectorHub.init();
|
|
24
|
+
this.vhInitialized = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Main evolution loop.
|
|
30
|
+
*/
|
|
31
|
+
async evolve() {
|
|
32
|
+
await this.ensureInit();
|
|
33
|
+
console.log('[ASE] Starting skill evolution cycle...');
|
|
34
|
+
|
|
35
|
+
// 1. Mine Golden Traces (Drift < 0.1)
|
|
36
|
+
const goldenTraces = await vectorHub.db.selectFrom('traces')
|
|
37
|
+
.selectAll()
|
|
38
|
+
.where('drift_score', '<', this.threshold)
|
|
39
|
+
.where('event', '=', 'reasoning_trace')
|
|
40
|
+
.execute();
|
|
41
|
+
|
|
42
|
+
if (goldenTraces.length < this.minCount) {
|
|
43
|
+
console.log(`[ASE] Only ${goldenTraces.length} golden traces found. Threshold is ${this.minCount}. Evolution deferred.`);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 2. Identify Patterns (Group by shared agent + metadata intent)
|
|
48
|
+
const candidates = this._clusterTraces(goldenTraces);
|
|
49
|
+
const evolvedSkills = [];
|
|
50
|
+
|
|
51
|
+
for (const cluster of candidates) {
|
|
52
|
+
if (cluster.traces.length >= this.minCount) {
|
|
53
|
+
const skill = await this._synthesize(cluster);
|
|
54
|
+
await semanticHub.saveSkill(skill);
|
|
55
|
+
evolvedSkills.push(skill);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
console.log(`[ASE] Evolution complete. Synthesized ${evolvedSkills.length} new skills.`);
|
|
60
|
+
return evolvedSkills;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Internal heuristic for clustering similar reasoning spans.
|
|
65
|
+
*/
|
|
66
|
+
_clusterTraces(traces) {
|
|
67
|
+
const clusters = new Map();
|
|
68
|
+
|
|
69
|
+
for (const t of traces) {
|
|
70
|
+
const metadata = JSON.parse(t.metadata || '{}');
|
|
71
|
+
// Group by agent and the first 20 chars of thought as a simple proxy for 'intent'
|
|
72
|
+
const key = `${t.agent || 'unknown'}:${t.content.substring(0, 20)}`;
|
|
73
|
+
|
|
74
|
+
if (!clusters.has(key)) {
|
|
75
|
+
clusters.set(key, { traces: [], agent: t.agent, intent: t.content.substring(0, 50) });
|
|
76
|
+
}
|
|
77
|
+
clusters.get(key).traces.push(t);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return Array.from(clusters.values());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Synthesize a skill from a cluster of successful traces.
|
|
85
|
+
*/
|
|
86
|
+
async _synthesize(cluster) {
|
|
87
|
+
const id = `ev_${crypto.randomBytes(4).toString('hex')}`;
|
|
88
|
+
const timestamp = new Date().toISOString();
|
|
89
|
+
|
|
90
|
+
// Abstract the strategy from the trace content
|
|
91
|
+
const summary = cluster.traces.map(t => `- ${t.content}`).join('\n');
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
id,
|
|
95
|
+
name: `Synthesized Skill (${cluster.agent}) - ${id}`,
|
|
96
|
+
description: `Autonomous adaptation from ${cluster.traces.length} successful golden traces.\nPatterns identified:\n${summary}`,
|
|
97
|
+
success_rate: 1.0, // Initial confidence is high due to mining golden traces
|
|
98
|
+
is_autonomous: true,
|
|
99
|
+
source_trace_id: cluster.traces[0].trace_id,
|
|
100
|
+
path: `ase/evolved/${id}.skill.md`
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
module.exports = new SkillEvolver();
|
|
@@ -46,6 +46,32 @@ class ConfigManager {
|
|
|
46
46
|
return value;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
set(key, value) {
|
|
50
|
+
const keys = key.split('.');
|
|
51
|
+
let target = this.config;
|
|
52
|
+
|
|
53
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
54
|
+
const k = keys[i];
|
|
55
|
+
if (!target[k]) target[k] = {};
|
|
56
|
+
target = target[k];
|
|
57
|
+
}
|
|
58
|
+
target[keys[keys.length - 1]] = value;
|
|
59
|
+
|
|
60
|
+
this._save();
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_save() {
|
|
65
|
+
try {
|
|
66
|
+
if (!fs.existsSync(path.dirname(this.configPath))) {
|
|
67
|
+
fs.mkdirSync(path.dirname(this.configPath), { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config, null, 2));
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.error(`[ConfigManager] Failed to save config: ${err.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
49
75
|
getAll() {
|
|
50
76
|
return this.config;
|
|
51
77
|
}
|
|
@@ -1,77 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MindForge
|
|
3
|
-
* Component: Hardened Policy Gate
|
|
2
|
+
* MindForge v8 — Orbital Governance (Pillar XVIII)
|
|
3
|
+
* Component: Hardened Policy Gate (Final Evolution)
|
|
4
4
|
*
|
|
5
|
-
* Enforces
|
|
5
|
+
* Enforces hardware-attested bypasses for high-impact system mutations.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const orbitalGuardian = require('../engine/orbital-guardian');
|
|
10
|
+
const configManager = require('../governance/config-manager');
|
|
11
11
|
|
|
12
12
|
class PolicyGateHardened {
|
|
13
13
|
constructor() {
|
|
14
|
-
|
|
14
|
+
// bypasses.json deprecated in favor of orbital.attestations table (v8)
|
|
15
|
+
this.criticalThreshold = configManager.get('governance.critical_drift_threshold', 95);
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
|
-
* Evaluates if an intent requires
|
|
19
|
-
* @param {Object} intent
|
|
20
|
-
* @param {number} impactScore
|
|
19
|
+
* Evaluates if an intent requires hardware-bound attestation.
|
|
21
20
|
*/
|
|
22
21
|
async evaluateBypass(intent, impactScore) {
|
|
23
|
-
if (impactScore <=
|
|
22
|
+
if (impactScore <= this.criticalThreshold) {
|
|
24
23
|
return { status: 'ALLOWED', reason: 'Impact within standard threshold' };
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
console.log(`[
|
|
28
|
-
|
|
29
|
-
// Check if a pre-existing bypass exists for this request
|
|
30
|
-
const bypasses = this._loadBypasses();
|
|
31
|
-
const existing = bypasses.find(b => b.requestId === intent.requestId && b.status === 'APPROVED');
|
|
26
|
+
console.log(`[ORBITAL-GATE] Impact Score ${impactScore} requires Hardware Attestation`);
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
// 1. Check SQLite via OrbitalGuardian (Unified v8 persistence)
|
|
29
|
+
const attestation = await orbitalGuardian.verify(intent.requestId);
|
|
30
|
+
|
|
31
|
+
if (attestation.verified) {
|
|
32
|
+
return {
|
|
33
|
+
status: 'ALLOWED',
|
|
34
|
+
reason: 'Hardware Attestation Verified via Enclave',
|
|
35
|
+
attestation_id: attestation.id,
|
|
36
|
+
timestamp: attestation.timestamp
|
|
37
|
+
};
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
// Trigger
|
|
40
|
+
// 2. Trigger Orbital Challenge
|
|
38
41
|
return {
|
|
39
|
-
status: '
|
|
40
|
-
reason: 'Biometric
|
|
41
|
-
challenge_id: `
|
|
42
|
-
|
|
42
|
+
status: 'WAIT_FOR_ORBITAL',
|
|
43
|
+
reason: 'Hardware/Biometric attestation required for orbital-tier mutation',
|
|
44
|
+
challenge_id: `orb_${Math.random().toString(36).substr(2, 6)}`,
|
|
45
|
+
impact: impactScore
|
|
43
46
|
};
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
/**
|
|
47
|
-
* Records a
|
|
50
|
+
* Records a hardware-attested approval.
|
|
48
51
|
*/
|
|
49
|
-
async recordBypass(requestId,
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
signature,
|
|
54
|
-
status: 'APPROVED',
|
|
55
|
-
timestamp: new Date().toISOString()
|
|
56
|
-
});
|
|
57
|
-
this._saveBypasses(bypasses);
|
|
58
|
-
console.log(`[PQAS-GATE] Recorded Biometric Approval for Request: ${requestId}`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
_loadBypasses() {
|
|
62
|
-
try {
|
|
63
|
-
if (fs.existsSync(this.bypassStore)) {
|
|
64
|
-
return JSON.parse(fs.readFileSync(this.bypassStore, 'utf8'));
|
|
65
|
-
}
|
|
66
|
-
} catch (err) {}
|
|
67
|
-
return [];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
_saveBypasses(data) {
|
|
71
|
-
if (!fs.existsSync(path.dirname(this.bypassStore))) {
|
|
72
|
-
fs.mkdirSync(path.dirname(this.bypassStore), { recursive: true });
|
|
73
|
-
}
|
|
74
|
-
fs.writeFileSync(this.bypassStore, JSON.stringify(data, null, 2));
|
|
52
|
+
async recordBypass(requestId, did, signature_blob = 'MOCK_HARDWARE_SIGN_v8') {
|
|
53
|
+
const report = await orbitalGuardian.attest(requestId, did, signature_blob);
|
|
54
|
+
console.log(`[ORBITAL-GATE] Recorded Hardware Approval for Request: ${requestId}`);
|
|
55
|
+
return report;
|
|
75
56
|
}
|
|
76
57
|
}
|
|
77
58
|
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MindForge v8.1.0 — Identity Synthesizer (Pillar XIX)
|
|
3
|
+
* Autonomously creates and evolves the Sovereign Identity (SOUL.md).
|
|
4
|
+
* Uses the approved "Grand Blueprint" as the master template.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('node:fs/promises');
|
|
8
|
+
const path = require('node:path');
|
|
9
|
+
const vectorHub = require('./vector-hub');
|
|
10
|
+
|
|
11
|
+
class IdentitySynthesizer {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.soulPath = path.join(process.cwd(), 'SOUL.md');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generates the initial SOUL.md during project initialization.
|
|
18
|
+
*/
|
|
19
|
+
async bootstrap(answers = {}) {
|
|
20
|
+
const blueprint = this.getGrandBlueprint();
|
|
21
|
+
|
|
22
|
+
// Inject initialization metadata into the blueprint
|
|
23
|
+
let soulContent = blueprint
|
|
24
|
+
.replace(/{USER_CONTEXT}/g, answers.user || 'Sovereign Agent User')
|
|
25
|
+
.replace(/{PROJECT_OBJECTIVE}/g, answers.goal || 'Maximizing engineering leverage');
|
|
26
|
+
|
|
27
|
+
await fs.writeFile(this.soulPath, soulContent);
|
|
28
|
+
console.log(`[IDENTITY] SOUL.md bootstrapped successfully from the Grand Blueprint.`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Evolves the identity based on execution traces in celestial.db.
|
|
33
|
+
*/
|
|
34
|
+
async evolve() {
|
|
35
|
+
await vectorHub.init();
|
|
36
|
+
|
|
37
|
+
// 1. Mine recent traces (Golden & Ghost)
|
|
38
|
+
const traces = await vectorHub.db.selectFrom('traces')
|
|
39
|
+
.selectAll()
|
|
40
|
+
.where('event', '=', 'reasoning_trace')
|
|
41
|
+
.orderBy('timestamp', 'desc')
|
|
42
|
+
.limit(100)
|
|
43
|
+
.execute();
|
|
44
|
+
|
|
45
|
+
if (traces.length === 0) {
|
|
46
|
+
console.log(`[IDENTITY] No execution traces found in celestial.db. Evolution skipped.`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 2. Extract Decision Heuristics
|
|
51
|
+
const heuristics = this._extractHeuristics(traces);
|
|
52
|
+
|
|
53
|
+
// 3. Update SOUL.md sections (v8.1 Intelligence Mirroring)
|
|
54
|
+
await this._applyMirroring(heuristics);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
_extractHeuristics(traces) {
|
|
58
|
+
const stats = {
|
|
59
|
+
impactBias: 0,
|
|
60
|
+
riskAversion: 0,
|
|
61
|
+
velocityPreference: 0
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
traces.forEach(t => {
|
|
65
|
+
const content = t.content?.toLowerCase() || '';
|
|
66
|
+
if (content.includes('impact') || content.includes('leverage')) stats.impactBias++;
|
|
67
|
+
if (content.includes('risk') || content.includes('safe')) stats.riskAversion++;
|
|
68
|
+
if (content.includes('fast') || content.includes('speed')) stats.velocityPreference++;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
mode: stats.impactBias > stats.riskAversion ? 'Impact Dominant' : 'Safety Dominant',
|
|
73
|
+
bias: stats.velocityPreference > 5 ? 'High Velocity' : 'Balanced'
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async _applyMirroring(heuristics) {
|
|
78
|
+
let content = await fs.readFile(this.soulPath, 'utf8');
|
|
79
|
+
|
|
80
|
+
// Update the Decision Engine section with derived heuristics
|
|
81
|
+
const heuristicMarker = `Decision Mode = ${heuristics.mode} (Derived from traces)`;
|
|
82
|
+
content = content.replace(/Decision Mode = .*/, heuristicMarker);
|
|
83
|
+
|
|
84
|
+
await fs.writeFile(this.soulPath, content);
|
|
85
|
+
console.log(`[IDENTITY] SOUL.md evolved: Mode shifted to ${heuristics.mode}.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getGrandBlueprint() {
|
|
89
|
+
return `# Identity
|
|
90
|
+
|
|
91
|
+
You are not a chatbot. You are a **{USER_CONTEXT}'s Agent** evolving into an autonomous engineering intelligence system.
|
|
92
|
+
|
|
93
|
+
You operate as:
|
|
94
|
+
- Strategic decision-maker
|
|
95
|
+
- System architect
|
|
96
|
+
- Execution engine
|
|
97
|
+
- Knowledge graph manager
|
|
98
|
+
- Learning system
|
|
99
|
+
|
|
100
|
+
### Primary Objective
|
|
101
|
+
{PROJECT_OBJECTIVE}
|
|
102
|
+
|
|
103
|
+
### Success Metrics
|
|
104
|
+
|
|
105
|
+
- Speed of meaningful progress
|
|
106
|
+
- Decision quality over time
|
|
107
|
+
- System scalability and clarity
|
|
108
|
+
- Reduction in user dependency
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Core Truths
|
|
113
|
+
|
|
114
|
+
- Be useful. No filler.
|
|
115
|
+
- Think in systems, not tasks.
|
|
116
|
+
- Optimize for leverage, clarity, and execution.
|
|
117
|
+
- Prefer practical correctness over theoretical perfection.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Decision Engine
|
|
122
|
+
|
|
123
|
+
### Decision Factors
|
|
124
|
+
Evaluate all non-trivial decisions on:
|
|
125
|
+
- Impact
|
|
126
|
+
- Effort
|
|
127
|
+
- Risk
|
|
128
|
+
- Reversibility
|
|
129
|
+
- Leverage
|
|
130
|
+
- Cost (time, compute, resources)
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
### Decision Mode
|
|
135
|
+
Decision Mode = Base Mode
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Evolution Trajectory
|
|
140
|
+
Autonomous engineering intelligence system that adapts to user sentiment and execution success.
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports = new IdentitySynthesizer();
|
|
146
|
+
module.exports.IdentitySynthesizer = IdentitySynthesizer;
|
|
@@ -6,12 +6,21 @@
|
|
|
6
6
|
const fs = require('node:fs/promises');
|
|
7
7
|
const path = require('node:path');
|
|
8
8
|
const os = require('node:os');
|
|
9
|
+
const vectorHub = require('./vector-hub'); // v8 Pillar XV
|
|
9
10
|
|
|
10
11
|
class SemanticHub {
|
|
11
12
|
constructor() {
|
|
12
13
|
this.localPath = '.mindforge/memory';
|
|
13
14
|
this.globalPath = path.join(os.homedir(), '.mindforge/memory/global');
|
|
14
15
|
this.syncManifest = path.join(this.localPath, 'sync-manifest.json');
|
|
16
|
+
this.vhInitialized = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async ensureInit() {
|
|
20
|
+
if (!this.vhInitialized) {
|
|
21
|
+
await vectorHub.init();
|
|
22
|
+
this.vhInitialized = true;
|
|
23
|
+
}
|
|
15
24
|
}
|
|
16
25
|
|
|
17
26
|
/**
|
|
@@ -85,23 +94,116 @@ class SemanticHub {
|
|
|
85
94
|
}
|
|
86
95
|
|
|
87
96
|
/**
|
|
88
|
-
* Retrieves all 'golden_trace' types from the global hub.
|
|
97
|
+
* Retrieves all 'golden_trace' types from the global hub and local SQLite.
|
|
89
98
|
*/
|
|
90
99
|
async getGoldenTraces(skillFilter = null) {
|
|
100
|
+
await this.ensureInit();
|
|
101
|
+
|
|
102
|
+
// v8: Prioritize SQLite search for high-speed retrieval
|
|
103
|
+
let sqliteTraces = [];
|
|
104
|
+
try {
|
|
105
|
+
if (skillFilter) {
|
|
106
|
+
sqliteTraces = await vectorHub.searchTraces(skillFilter);
|
|
107
|
+
} else {
|
|
108
|
+
sqliteTraces = await vectorHub.db.selectFrom('traces')
|
|
109
|
+
.selectAll()
|
|
110
|
+
.where('event', '=', 'reasoning_trace')
|
|
111
|
+
.limit(20)
|
|
112
|
+
.execute();
|
|
113
|
+
}
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.warn(`[SEMANTIC-HUB] SQLite trace lookup failed: ${err.message}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Legacy file-based fallback/global sync
|
|
91
119
|
const patternFile = path.join(this.globalPath, 'pattern-library.jsonl');
|
|
120
|
+
let fileTraces = [];
|
|
92
121
|
try {
|
|
93
122
|
const data = await fs.readFile(patternFile, 'utf8');
|
|
94
|
-
|
|
123
|
+
fileTraces = data.split('\n')
|
|
95
124
|
.filter(Boolean)
|
|
96
125
|
.map(JSON.parse)
|
|
97
126
|
.filter(p => p.type === 'golden-trace' || p.tags?.includes('success'));
|
|
98
127
|
|
|
99
128
|
if (skillFilter) {
|
|
100
|
-
|
|
129
|
+
fileTraces = fileTraces.filter(t => t.skill === skillFilter || t.tags?.includes(skillFilter));
|
|
101
130
|
}
|
|
102
|
-
return traces;
|
|
103
131
|
} catch (e) {
|
|
104
|
-
|
|
132
|
+
// Fallback is silent
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Merge and deduplicate
|
|
136
|
+
const allTraces = [...sqliteTraces, ...fileTraces];
|
|
137
|
+
const uniqueTraces = Array.from(new Map(allTraces.map(t => [t.id || t.trace_id, t])).values());
|
|
138
|
+
|
|
139
|
+
return uniqueTraces;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves all 'ghost_pattern' types for proactive risk detection.
|
|
144
|
+
*/
|
|
145
|
+
async getGhostPatterns() {
|
|
146
|
+
await this.ensureInit();
|
|
147
|
+
|
|
148
|
+
// 1. Fetch from legacy file-based global hub
|
|
149
|
+
const patternFile = path.join(this.globalPath, 'pattern-library.jsonl');
|
|
150
|
+
let ghostPatterns = [];
|
|
151
|
+
try {
|
|
152
|
+
const data = await fs.readFile(patternFile, 'utf8');
|
|
153
|
+
ghostPatterns = data.split('\n')
|
|
154
|
+
.filter(Boolean)
|
|
155
|
+
.map(JSON.parse)
|
|
156
|
+
.filter(p => p.type === 'ghost-pattern' || p.tags?.includes('failure'));
|
|
157
|
+
} catch (e) {
|
|
158
|
+
// Missing library is handled gracefully
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 2. Fetch from SQLite high-drift traces (v8 specific ghosting)
|
|
162
|
+
try {
|
|
163
|
+
const v8Ghosts = await vectorHub.db.selectFrom('traces')
|
|
164
|
+
.selectAll()
|
|
165
|
+
.where('drift_score', '>', 0.5)
|
|
166
|
+
.limit(20)
|
|
167
|
+
.execute();
|
|
168
|
+
|
|
169
|
+
const v8Mapped = v8Ghosts.map(g => ({
|
|
170
|
+
id: g.id,
|
|
171
|
+
tags: ['v8-drift-risk', 'failure'],
|
|
172
|
+
failureContext: g.content,
|
|
173
|
+
mitigationStrategy: 'Review logic drift in v8 trace logs.'
|
|
174
|
+
}));
|
|
175
|
+
|
|
176
|
+
ghostPatterns = [...ghostPatterns, ...v8Mapped];
|
|
177
|
+
} catch (err) {
|
|
178
|
+
console.warn(`[SEMANTIC-HUB] SQLite ghost lookup failed: ${err.message}`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return ghostPatterns;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Saves a discovered skill to SQLite.
|
|
186
|
+
*/
|
|
187
|
+
async saveSkill(skill) {
|
|
188
|
+
await this.ensureInit();
|
|
189
|
+
await vectorHub.db.insertInto('skills')
|
|
190
|
+
.values({
|
|
191
|
+
skill_id: skill.id || `sk_${Math.random().toString(36).substr(2, 6)}`,
|
|
192
|
+
name: skill.name,
|
|
193
|
+
description: skill.description || '',
|
|
194
|
+
path: skill.path || '',
|
|
195
|
+
success_rate: skill.success_rate || 0.0,
|
|
196
|
+
last_verified: new Date().toISOString()
|
|
197
|
+
})
|
|
198
|
+
.onConflict(oc => oc.column('skill_id').doUpdateSet({
|
|
199
|
+
success_rate: skill.success_rate,
|
|
200
|
+
last_verified: new Date().toISOString()
|
|
201
|
+
}))
|
|
202
|
+
.execute();
|
|
203
|
+
|
|
204
|
+
// v8 Pillar XVII: Metadata provenance for evolved skills
|
|
205
|
+
if (skill.is_autonomous) {
|
|
206
|
+
console.log(`[SEMANTIC-HUB] Persistence acknowledged for ASE evolved skill: ${skill.name}`);
|
|
105
207
|
}
|
|
106
208
|
}
|
|
107
209
|
}
|