mindforge-cc 6.7.0 → 8.0.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/.mindforge/bypasses.json +8 -0
- package/.mindforge/celestial.db +0 -0
- package/.mindforge/config.json +66 -0
- package/.mindforge/memory/sync-manifest.json +6 -0
- package/.mindforge/remediation-queue.json +47 -0
- package/.planning/AUDIT.jsonl +45 -0
- package/.planning/RISK-AUDIT.jsonl +5 -0
- package/CHANGELOG.md +23 -0
- package/README.md +33 -27
- package/RELEASENOTES.md +31 -0
- package/bin/engine/logic-drift-detector.js +4 -2
- package/bin/engine/logic-validator.js +74 -0
- package/bin/engine/mesh-syncer.js +129 -0
- package/bin/engine/nexus-tracer.js +44 -8
- package/bin/engine/orbital-guardian.js +84 -0
- package/bin/engine/remediation-engine.js +17 -8
- package/bin/engine/skill-evolver.js +105 -0
- package/bin/engine/test-remediation.js +61 -0
- package/bin/engine/test-v7-blueprint.js +44 -0
- package/bin/governance/config-manager.js +85 -0
- package/bin/governance/policies/critical-data.json +1 -0
- package/bin/governance/policy-engine.js +27 -29
- package/bin/governance/policy-gate-hardened.js +59 -0
- package/bin/governance/quantum-crypto.js +25 -4
- package/bin/governance/test-config.js +40 -0
- package/bin/governance/test-crypto-pluggable.js +50 -0
- package/bin/governance/test-hardened-gate.js +71 -0
- package/bin/memory/semantic-hub.js +110 -3
- package/bin/memory/vector-hub.js +170 -0
- package/bin/migrations/v8-sqlite-migration.js +85 -0
- package/bin/revops/market-evaluator.js +3 -9
- package/bin/revops/remediation-queue.js +107 -0
- package/docs/INTELLIGENCE-MESH.md +13 -13
- package/docs/commands-skills/DISCOVERED_SKILLS.md +1 -1
- package/docs/usp-features.md +12 -4
- package/package.json +6 -4
|
@@ -10,8 +10,11 @@ const path = require('path');
|
|
|
10
10
|
const crypto = require('crypto');
|
|
11
11
|
const ztai = require('../governance/ztai-manager');
|
|
12
12
|
const SREManager = require('./sre-manager');
|
|
13
|
+
const configManager = require('../governance/config-manager');
|
|
13
14
|
const driftDetector = require('./logic-drift-detector'); // v6.1 Pillar X
|
|
14
15
|
const remediationEngine = require('./remediation-engine'); // v6.1 Pillar X
|
|
16
|
+
const logicValidator = require('./logic-validator'); // v7 Pillar X
|
|
17
|
+
const vectorHub = require('../memory/vector-hub'); // v8 Pillar XV
|
|
15
18
|
|
|
16
19
|
class NexusTracer {
|
|
17
20
|
constructor(config = {}) {
|
|
@@ -22,19 +25,21 @@ class NexusTracer {
|
|
|
22
25
|
this.did = config.did || null; // Active Agent DID
|
|
23
26
|
this.enableZtai = config.enableZtai !== false;
|
|
24
27
|
this.sreManager = new SREManager();
|
|
28
|
+
this.vhInitialized = false;
|
|
25
29
|
|
|
26
|
-
//
|
|
27
|
-
this.RES_THRESHOLD = 0.8;
|
|
30
|
+
// v7: Centralized Thresholds
|
|
31
|
+
this.RES_THRESHOLD = configManager.get('governance.res_threshold', 0.8);
|
|
28
32
|
this.entropyCache = new Map();
|
|
29
33
|
|
|
30
34
|
// v6.1: Neural Drift Remediation (NDR)
|
|
31
35
|
this.DRIFT_SAMPLE_RATE = 1.0;
|
|
32
36
|
|
|
33
|
-
//
|
|
37
|
+
// v7: Agentic SBOM with Arbitrage
|
|
34
38
|
this.sbom = {
|
|
35
|
-
manifest_version: '1.
|
|
39
|
+
manifest_version: '1.1.0',
|
|
36
40
|
models: new Set(),
|
|
37
41
|
skills: new Set(),
|
|
42
|
+
arbitrage_total: 0,
|
|
38
43
|
startTime: new Date().toISOString()
|
|
39
44
|
};
|
|
40
45
|
}
|
|
@@ -148,15 +153,26 @@ class NexusTracer {
|
|
|
148
153
|
|
|
149
154
|
// v6.1 Pillar X: Neural Drift Remediation (NDR)
|
|
150
155
|
const driftReport = driftDetector.analyze(spanId, sanitizedThought);
|
|
151
|
-
|
|
152
|
-
|
|
156
|
+
|
|
157
|
+
// v7 Pillar X: Semantic Logic Validation
|
|
158
|
+
const validationResult = await logicValidator.validate(sanitizedThought, { span_id: spanId });
|
|
159
|
+
|
|
160
|
+
if (driftReport.status === 'DRIFT_DETECTED' || !validationResult.is_valid) {
|
|
161
|
+
const remediation = await remediationEngine.trigger(spanId, {
|
|
162
|
+
...driftReport,
|
|
163
|
+
invalid_logic: !validationResult.is_valid
|
|
164
|
+
});
|
|
153
165
|
|
|
154
166
|
await this._recordEvent('drift_remediation_event', {
|
|
155
167
|
span_id: spanId,
|
|
156
168
|
score: driftReport.drift_score,
|
|
157
169
|
strategy: remediation.strategy,
|
|
158
170
|
remediation_id: remediation.remediation_id,
|
|
159
|
-
markers: driftReport.markers
|
|
171
|
+
markers: driftReport.markers,
|
|
172
|
+
validation: {
|
|
173
|
+
is_valid: validationResult.is_valid,
|
|
174
|
+
critique: validationResult.critique
|
|
175
|
+
}
|
|
160
176
|
});
|
|
161
177
|
}
|
|
162
178
|
|
|
@@ -247,7 +263,6 @@ class NexusTracer {
|
|
|
247
263
|
if (this.enableZtai && this.did) {
|
|
248
264
|
try {
|
|
249
265
|
entry.did = this.did;
|
|
250
|
-
// Sign the stringified entry WITHOUT the signature field itself
|
|
251
266
|
const payload = JSON.stringify(entry);
|
|
252
267
|
entry.signature = await ztai.signData(this.did, payload);
|
|
253
268
|
} catch (err) {
|
|
@@ -255,6 +270,27 @@ class NexusTracer {
|
|
|
255
270
|
}
|
|
256
271
|
}
|
|
257
272
|
|
|
273
|
+
// v8: SQLite Persistence (VectorHub)
|
|
274
|
+
try {
|
|
275
|
+
if (!this.vhInitialized) {
|
|
276
|
+
await vectorHub.init();
|
|
277
|
+
this.vhInitialized = true;
|
|
278
|
+
}
|
|
279
|
+
await vectorHub.recordTrace({
|
|
280
|
+
id: entry.id,
|
|
281
|
+
trace_id: entry.trace_id,
|
|
282
|
+
span_id: data.span_id || null,
|
|
283
|
+
event: event,
|
|
284
|
+
timestamp: entry.timestamp,
|
|
285
|
+
agent: data.agent || null,
|
|
286
|
+
content: data.thought || data.span_name || data.strategy || null,
|
|
287
|
+
metadata: entry,
|
|
288
|
+
drift_score: data.drift_score || 0
|
|
289
|
+
});
|
|
290
|
+
} catch (err) {
|
|
291
|
+
console.warn(`[NexusTracer] VectorHub persist failed: ${err.message}`);
|
|
292
|
+
}
|
|
293
|
+
|
|
258
294
|
try {
|
|
259
295
|
if (!fs.existsSync(path.dirname(this.auditPath))) {
|
|
260
296
|
fs.mkdirSync(path.dirname(this.auditPath), { recursive: true });
|
|
@@ -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();
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const remediationQueue = require('../revops/remediation-queue');
|
|
11
|
+
const logicValidator = require('./logic-validator');
|
|
12
|
+
const semanticHub = require('../memory/semantic-hub');
|
|
11
13
|
|
|
12
14
|
class RemediationEngine {
|
|
13
15
|
constructor() {
|
|
@@ -25,7 +27,7 @@ class RemediationEngine {
|
|
|
25
27
|
|
|
26
28
|
// Tiered Remediation Logic
|
|
27
29
|
if (drift_score > 0.9) strategy = 'REASONING_RESTART';
|
|
28
|
-
else if (drift_score > 0.8) strategy = 'GOLDEN_TRACE_INJECTION';
|
|
30
|
+
else if (drift_score > 0.8 || report.invalid_logic) strategy = 'GOLDEN_TRACE_INJECTION';
|
|
29
31
|
else if (drift_score > 0.75) strategy = 'CONTEXT_COMPRESSION';
|
|
30
32
|
|
|
31
33
|
if (strategy === 'NOT_REQUIRED') return { status: 'STABLE', strategy };
|
|
@@ -38,18 +40,19 @@ class RemediationEngine {
|
|
|
38
40
|
effectiveness_prediction: 0.85
|
|
39
41
|
};
|
|
40
42
|
|
|
41
|
-
console.log(`[Remediation] Triggered ${strategy} for ${spanId} (
|
|
43
|
+
console.log(`[Remediation] Triggered ${strategy} for ${spanId} (Score: ${drift_score})`);
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
// v7: Finalize with Stateful Queueing
|
|
46
|
+
await remediationQueue.enqueue(action);
|
|
47
|
+
|
|
48
|
+
// Mock implementation of remediation execution
|
|
46
49
|
this._executeStrategy(strategy, spanId);
|
|
47
50
|
|
|
48
51
|
return action;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
/**
|
|
52
|
-
*
|
|
55
|
+
* functional implementation of remediation strategies.
|
|
53
56
|
*/
|
|
54
57
|
async _executeStrategy(strategy, spanId) {
|
|
55
58
|
switch(strategy) {
|
|
@@ -59,7 +62,13 @@ class RemediationEngine {
|
|
|
59
62
|
break;
|
|
60
63
|
case 'GOLDEN_TRACE_INJECTION':
|
|
61
64
|
console.log(`[Remediation] Injecting successful trace heuristics into ${spanId}`);
|
|
62
|
-
|
|
65
|
+
const traces = await semanticHub.getGoldenTraces();
|
|
66
|
+
if (traces.length > 0) {
|
|
67
|
+
const bestTrace = traces[0];
|
|
68
|
+
console.log(`[Remediation] Injected Golden Trace: ${bestTrace.id} (Skill: ${bestTrace.skill})`);
|
|
69
|
+
} else {
|
|
70
|
+
console.warn(`[Remediation] No Golden Traces found in SemanticHub for injection.`);
|
|
71
|
+
}
|
|
63
72
|
break;
|
|
64
73
|
}
|
|
65
74
|
}
|
|
@@ -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();
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MindForge v7 — NDR Integration Test
|
|
3
|
+
* Verifies that logic drift triggers remediation and pulls from SemanticHub.
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const fs = require('node:fs');
|
|
8
|
+
const path = require('node:path');
|
|
9
|
+
const os = require('node:os');
|
|
10
|
+
const driftDetector = require('./logic-drift-detector');
|
|
11
|
+
const remediationEngine = require('./remediation-engine');
|
|
12
|
+
const semanticHub = require('../memory/semantic-hub');
|
|
13
|
+
|
|
14
|
+
async function testNDR() {
|
|
15
|
+
console.log('--- NDR Pillar Test ---');
|
|
16
|
+
|
|
17
|
+
// 1. Setup Mock Semantic Hub Data
|
|
18
|
+
const globalPath = path.join(os.homedir(), '.mindforge/memory/global');
|
|
19
|
+
const patternFile = path.join(globalPath, 'pattern-library.jsonl');
|
|
20
|
+
|
|
21
|
+
if (!fs.existsSync(globalPath)) {
|
|
22
|
+
fs.mkdirSync(globalPath, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const mockTrace = {
|
|
26
|
+
id: 'gt_test_001',
|
|
27
|
+
type: 'golden-trace',
|
|
28
|
+
skill: 'testing',
|
|
29
|
+
tags: ['success', 'logic-fix'],
|
|
30
|
+
content: 'Always verify before you trust.'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
fs.appendFileSync(patternFile, JSON.stringify(mockTrace) + '\n');
|
|
34
|
+
console.log('[Test Setup] Injected mock golden trace into global hub.');
|
|
35
|
+
|
|
36
|
+
// 2. Simulate Drift
|
|
37
|
+
const spanId = 'sp_test_drift';
|
|
38
|
+
const ramblingThought = 'I am thinking about the thing and the thing is a thing and I keep repeating the thing because things are things.';
|
|
39
|
+
|
|
40
|
+
const report = driftDetector.analyze(spanId, ramblingThought);
|
|
41
|
+
console.log(`[Drift Detector] Report Status: ${report.status} (Score: ${report.drift_score})`);
|
|
42
|
+
|
|
43
|
+
if (report.status !== 'DRIFT_DETECTED') {
|
|
44
|
+
throw new Error('Drift detector failed to recognize rambling pattern');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 3. Trigger Remediation
|
|
48
|
+
const action = await remediationEngine.trigger(spanId, report);
|
|
49
|
+
console.log(`[Remediation Engine] Action: ${action.strategy} (ID: ${action.remediation_id})`);
|
|
50
|
+
|
|
51
|
+
if (action.strategy !== 'GOLDEN_TRACE_INJECTION') {
|
|
52
|
+
throw new Error(`Expected GOLDEN_TRACE_INJECTION but got ${action.strategy}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log('PASSED');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
testNDR().catch(err => {
|
|
59
|
+
console.error(`FAILED: ${err.message}`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MindForge v7 — Test Suite
|
|
3
|
+
* Blueprint Verification: NDR Pillar X
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const tracer = require('./nexus-tracer');
|
|
8
|
+
const remediationQueue = require('../revops/remediation-queue');
|
|
9
|
+
const fs = require('node:fs');
|
|
10
|
+
|
|
11
|
+
async function testNDRBlueprint() {
|
|
12
|
+
console.log('--- STARTING NDR BLUEPRINT VERIFICATION ---');
|
|
13
|
+
|
|
14
|
+
// Clear existing queue for clean test
|
|
15
|
+
if (fs.existsSync(remediationQueue.queuePath)) fs.unlinkSync(remediationQueue.queuePath);
|
|
16
|
+
|
|
17
|
+
// We need to create an active span to record reasoning
|
|
18
|
+
await tracer.startSpan('span_stable', { agent: 'mf-researcher' });
|
|
19
|
+
await tracer.startSpan('span_drift', { agent: 'mf-researcher' });
|
|
20
|
+
|
|
21
|
+
// 1. Simulate a Stable Thought (should have high confidence)
|
|
22
|
+
console.log('\n[TEST 1] Testing Stable reasoning...');
|
|
23
|
+
await tracer.recordReasoning('span_stable', 'mf-researcher', 'I will now analyze the dependencies and create a plan.');
|
|
24
|
+
|
|
25
|
+
// 2. Simulate a Drifting Thought (should trigger validator critique)
|
|
26
|
+
console.log('\n[TEST 2] Testing Drifting reasoning (Self-Doubt)...');
|
|
27
|
+
await tracer.recordReasoning('span_drift', 'mf-researcher', 'I am not sure how to proceed, maybe I should wait and check the goal again.');
|
|
28
|
+
|
|
29
|
+
// 3. Verify Queue Persistence
|
|
30
|
+
const pending = remediationQueue.getPending();
|
|
31
|
+
console.log(`\n[RESULT] Pending Remediations in Queue: ${pending.length}`);
|
|
32
|
+
|
|
33
|
+
if (pending.length > 0) {
|
|
34
|
+
console.log('--- NDR BLUEPRINT VERIFICATION PASSED ---');
|
|
35
|
+
} else {
|
|
36
|
+
console.error('--- NDR BLUEPRINT VERIFICATION FAILED: No remediation queued ---');
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
testNDRBlueprint().catch(err => {
|
|
42
|
+
console.error(err);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MindForge v7 — Core Governance
|
|
3
|
+
* Component: Config Manager
|
|
4
|
+
*
|
|
5
|
+
* Centralized configuration loader for MindForge system parameters.
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const fs = require('node:fs');
|
|
10
|
+
const path = require('node:path');
|
|
11
|
+
|
|
12
|
+
class ConfigManager {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.configPath = path.join(process.cwd(), '.mindforge', 'config.json');
|
|
15
|
+
this.config = null;
|
|
16
|
+
this._loadConfig();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_loadConfig() {
|
|
20
|
+
try {
|
|
21
|
+
if (fs.existsSync(this.configPath)) {
|
|
22
|
+
const raw = fs.readFileSync(this.configPath, 'utf8');
|
|
23
|
+
this.config = JSON.parse(raw);
|
|
24
|
+
console.log(`[ConfigManager] Loaded configuration from ${this.configPath}`);
|
|
25
|
+
} else {
|
|
26
|
+
console.warn(`[ConfigManager] Config file not found at ${this.configPath}. Using defaults.`);
|
|
27
|
+
this.config = { env: 'default' };
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error(`[ConfigManager] Failed to load config: ${err.message}`);
|
|
31
|
+
this.config = { error: err.message };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get(key, defaultValue = null) {
|
|
36
|
+
const keys = key.split('.');
|
|
37
|
+
let value = this.config;
|
|
38
|
+
|
|
39
|
+
for (const k of keys) {
|
|
40
|
+
if (value && Object.prototype.hasOwnProperty.call(value, k)) {
|
|
41
|
+
value = value[k];
|
|
42
|
+
} else {
|
|
43
|
+
return defaultValue;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
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
|
+
|
|
75
|
+
getAll() {
|
|
76
|
+
return this.config;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
reload() {
|
|
80
|
+
this._loadConfig();
|
|
81
|
+
return this.config;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = new ConfigManager();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"pol_critical_001","effect":"PERMIT","max_impact":100,"conditions":{"resource":"STATE.md"}}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
const fs = require('node:fs');
|
|
8
8
|
const path = require('node:path');
|
|
9
9
|
const ImpactAnalyzer = require('./impact-analyzer');
|
|
10
|
+
const policyGate = require('./policy-gate-hardened');
|
|
10
11
|
|
|
11
12
|
class PolicyEngine {
|
|
12
13
|
constructor(config = {}) {
|
|
@@ -25,7 +26,7 @@ class PolicyEngine {
|
|
|
25
26
|
/**
|
|
26
27
|
* Evaluates an agent's intent against all active policies using CADIA.
|
|
27
28
|
*/
|
|
28
|
-
evaluate(intent) {
|
|
29
|
+
async evaluate(intent) {
|
|
29
30
|
const requestId = `pol_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
|
|
30
31
|
const sessionId = intent.sessionId || 'default_session';
|
|
31
32
|
const currentGoal = this.getCurrentGoal();
|
|
@@ -67,22 +68,26 @@ class PolicyEngine {
|
|
|
67
68
|
// 2. Pillar II (v6.0.0): Dynamic Blast Radius Enforcement with Tier 3 Bypass
|
|
68
69
|
for (const policy of policies) {
|
|
69
70
|
if (this.matches(policy, intent)) {
|
|
70
|
-
if (policy.max_impact && impactScore
|
|
71
|
+
if (policy.max_impact && impactScore >= policy.max_impact) {
|
|
71
72
|
|
|
72
|
-
// [PQAS] v7:
|
|
73
|
+
// [PQAS] v7: Hardened Biometric Bypass for Risk > 95
|
|
73
74
|
if (impactScore > 95) {
|
|
74
|
-
|
|
75
|
-
if (
|
|
75
|
+
const gateResult = await policyGate.evaluateBypass(intent, impactScore);
|
|
76
|
+
if (gateResult.status === 'WAIT_FOR_BIOMETRIC') {
|
|
76
77
|
verdict = {
|
|
77
78
|
verdict: 'DENY',
|
|
78
|
-
reason:
|
|
79
|
+
reason: gateResult.reason,
|
|
79
80
|
requestId,
|
|
80
|
-
status: 'WAIT_FOR_BIOMETRIC'
|
|
81
|
+
status: 'WAIT_FOR_BIOMETRIC',
|
|
82
|
+
challenge_id: gateResult.challenge_id
|
|
81
83
|
};
|
|
82
84
|
this.logAudit(intent, impactScore, verdict);
|
|
83
85
|
return verdict;
|
|
84
86
|
}
|
|
85
|
-
console.log(`[PQAS-
|
|
87
|
+
console.log(`[PQAS-GATE] [${requestId}] Biometric signature verified. Proceeding with high-risk mutation.`);
|
|
88
|
+
verdict = { verdict: 'PERMIT', reason: `Authorized via Biometric Bypass [${gateResult.signature || 'WEB-AUTHN-DEX'}]`, requestId };
|
|
89
|
+
this.logAudit(intent, impactScore, verdict);
|
|
90
|
+
return verdict;
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
// [ENTERPRISE] Tier 3 Reasoning/PQ Proof Bypass
|
|
@@ -183,28 +188,21 @@ class PolicyEngine {
|
|
|
183
188
|
}
|
|
184
189
|
|
|
185
190
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
191
|
+
* Simple glob matching for policy conditions.
|
|
192
|
+
* Supports '*' (any string) and '?' (any character).
|
|
188
193
|
*/
|
|
189
|
-
|
|
190
|
-
return
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
},
|
|
202
|
-
policy_engine: {
|
|
203
|
-
version: '6.2.0-alpha',
|
|
204
|
-
sovereign_enforcement: 'STRICT',
|
|
205
|
-
total_policies: this.loadPolicies().length
|
|
206
|
-
}
|
|
207
|
-
};
|
|
194
|
+
globMatch(pattern, text) {
|
|
195
|
+
if (!pattern || !text) return false;
|
|
196
|
+
if (pattern === '*') return true;
|
|
197
|
+
|
|
198
|
+
// Escape regex characters but keep * and ?
|
|
199
|
+
const regexStr = pattern
|
|
200
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
201
|
+
.replace(/\*/g, '.*')
|
|
202
|
+
.replace(/\?/g, '.');
|
|
203
|
+
|
|
204
|
+
const regex = new RegExp(`^${regexStr}$`, 'i');
|
|
205
|
+
return regex.test(text);
|
|
208
206
|
}
|
|
209
207
|
}
|
|
210
208
|
|