@monoes/monomindcli 1.15.3 → 1.15.5
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/src/mcp-client.d.ts.map +1 -1
- package/dist/src/mcp-client.js +7 -0
- package/dist/src/mcp-client.js.map +1 -1
- package/dist/src/mcp-tools/coherence/causal-infer.d.ts +15 -0
- package/dist/src/mcp-tools/coherence/causal-infer.d.ts.map +1 -0
- package/dist/src/mcp-tools/coherence/causal-infer.js +347 -0
- package/dist/src/mcp-tools/coherence/causal-infer.js.map +1 -0
- package/dist/src/mcp-tools/coherence/coherence-check.d.ts +15 -0
- package/dist/src/mcp-tools/coherence/coherence-check.d.ts.map +1 -0
- package/dist/src/mcp-tools/coherence/coherence-check.js +206 -0
- package/dist/src/mcp-tools/coherence/coherence-check.js.map +1 -0
- package/dist/src/mcp-tools/coherence/consensus-verify.d.ts +15 -0
- package/dist/src/mcp-tools/coherence/consensus-verify.d.ts.map +1 -0
- package/dist/src/mcp-tools/coherence/consensus-verify.js +303 -0
- package/dist/src/mcp-tools/coherence/consensus-verify.js.map +1 -0
- package/dist/src/mcp-tools/coherence/memory-gate.d.ts +15 -0
- package/dist/src/mcp-tools/coherence/memory-gate.d.ts.map +1 -0
- package/dist/src/mcp-tools/coherence/memory-gate.js +266 -0
- package/dist/src/mcp-tools/coherence/memory-gate.js.map +1 -0
- package/dist/src/mcp-tools/coherence/quantum-topology.d.ts +15 -0
- package/dist/src/mcp-tools/coherence/quantum-topology.d.ts.map +1 -0
- package/dist/src/mcp-tools/coherence/quantum-topology.js +406 -0
- package/dist/src/mcp-tools/coherence/quantum-topology.js.map +1 -0
- package/dist/src/mcp-tools/coherence/spectral-analyze.d.ts +15 -0
- package/dist/src/mcp-tools/coherence/spectral-analyze.d.ts.map +1 -0
- package/dist/src/mcp-tools/coherence/spectral-analyze.js +293 -0
- package/dist/src/mcp-tools/coherence/spectral-analyze.js.map +1 -0
- package/dist/src/mcp-tools/coherence/types.d.ts +277 -0
- package/dist/src/mcp-tools/coherence/types.d.ts.map +1 -0
- package/dist/src/mcp-tools/coherence/types.js +159 -0
- package/dist/src/mcp-tools/coherence/types.js.map +1 -0
- package/dist/src/mcp-tools/coherence-tools.d.ts +9 -0
- package/dist/src/mcp-tools/coherence-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/coherence-tools.js +25 -0
- package/dist/src/mcp-tools/coherence-tools.js.map +1 -0
- package/dist/src/mcp-tools/quality/chaos-resilience/chaos-inject.d.ts +163 -0
- package/dist/src/mcp-tools/quality/chaos-resilience/chaos-inject.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/chaos-resilience/chaos-inject.js +414 -0
- package/dist/src/mcp-tools/quality/chaos-resilience/chaos-inject.js.map +1 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/analyze-coverage.d.ts +128 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/analyze-coverage.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/analyze-coverage.js +375 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/analyze-coverage.js.map +1 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/prioritize-gaps.d.ts +161 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/prioritize-gaps.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/prioritize-gaps.js +423 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/prioritize-gaps.js.map +1 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/track-trends.d.ts +165 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/track-trends.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/track-trends.js +395 -0
- package/dist/src/mcp-tools/quality/coverage-analysis/track-trends.js.map +1 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/analyze-root-cause.d.ts +165 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/analyze-root-cause.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/analyze-root-cause.js +508 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/analyze-root-cause.js.map +1 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/find-similar-defects.d.ts +147 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/find-similar-defects.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/find-similar-defects.js +391 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/find-similar-defects.js.map +1 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/predict-defects.d.ts +147 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/predict-defects.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/predict-defects.js +422 -0
- package/dist/src/mcp-tools/quality/defect-intelligence/predict-defects.js.map +1 -0
- package/dist/src/mcp-tools/quality/quality-assessment/assess-readiness.d.ts +185 -0
- package/dist/src/mcp-tools/quality/quality-assessment/assess-readiness.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/quality-assessment/assess-readiness.js +437 -0
- package/dist/src/mcp-tools/quality/quality-assessment/assess-readiness.js.map +1 -0
- package/dist/src/mcp-tools/quality/quality-assessment/calculate-risk.d.ts +166 -0
- package/dist/src/mcp-tools/quality/quality-assessment/calculate-risk.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/quality-assessment/calculate-risk.js +410 -0
- package/dist/src/mcp-tools/quality/quality-assessment/calculate-risk.js.map +1 -0
- package/dist/src/mcp-tools/quality/quality-assessment/evaluate-quality-gate.d.ts +201 -0
- package/dist/src/mcp-tools/quality/quality-assessment/evaluate-quality-gate.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/quality-assessment/evaluate-quality-gate.js +363 -0
- package/dist/src/mcp-tools/quality/quality-assessment/evaluate-quality-gate.js.map +1 -0
- package/dist/src/mcp-tools/quality/security-compliance/audit-compliance.d.ts +166 -0
- package/dist/src/mcp-tools/quality/security-compliance/audit-compliance.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/security-compliance/audit-compliance.js +394 -0
- package/dist/src/mcp-tools/quality/security-compliance/audit-compliance.js.map +1 -0
- package/dist/src/mcp-tools/quality/security-compliance/detect-secrets.d.ts +129 -0
- package/dist/src/mcp-tools/quality/security-compliance/detect-secrets.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/security-compliance/detect-secrets.js +383 -0
- package/dist/src/mcp-tools/quality/security-compliance/detect-secrets.js.map +1 -0
- package/dist/src/mcp-tools/quality/security-compliance/security-scan.d.ts +171 -0
- package/dist/src/mcp-tools/quality/security-compliance/security-scan.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/security-compliance/security-scan.js +476 -0
- package/dist/src/mcp-tools/quality/security-compliance/security-scan.js.map +1 -0
- package/dist/src/mcp-tools/quality/test-generation/generate-tests.d.ts +147 -0
- package/dist/src/mcp-tools/quality/test-generation/generate-tests.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/test-generation/generate-tests.js +400 -0
- package/dist/src/mcp-tools/quality/test-generation/generate-tests.js.map +1 -0
- package/dist/src/mcp-tools/quality/test-generation/suggest-tests.d.ts +145 -0
- package/dist/src/mcp-tools/quality/test-generation/suggest-tests.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/test-generation/suggest-tests.js +328 -0
- package/dist/src/mcp-tools/quality/test-generation/suggest-tests.js.map +1 -0
- package/dist/src/mcp-tools/quality/test-generation/tdd-cycle.d.ts +126 -0
- package/dist/src/mcp-tools/quality/test-generation/tdd-cycle.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality/test-generation/tdd-cycle.js +348 -0
- package/dist/src/mcp-tools/quality/test-generation/tdd-cycle.js.map +1 -0
- package/dist/src/mcp-tools/quality-tools.d.ts +9 -0
- package/dist/src/mcp-tools/quality-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/quality-tools.js +308 -0
- package/dist/src/mcp-tools/quality-tools.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coherence Check Tool - pr_coherence_check
|
|
3
|
+
*
|
|
4
|
+
* Checks coherence of vectors using Sheaf Laplacian energy.
|
|
5
|
+
* Energy 0 = fully coherent, Energy 1 = contradictory
|
|
6
|
+
*
|
|
7
|
+
* Uses CohomologyEngine from prime-radiant-advanced-wasm
|
|
8
|
+
*/
|
|
9
|
+
import { CoherenceInputSchema, successResult, errorResult, } from './types.js';
|
|
10
|
+
// Default logger for when context doesn't provide one
|
|
11
|
+
const defaultLogger = {
|
|
12
|
+
debug: (msg, meta) => console.debug(`[pr_coherence_check] ${msg}`, meta),
|
|
13
|
+
info: (msg, meta) => console.info(`[pr_coherence_check] ${msg}`, meta),
|
|
14
|
+
warn: (msg, meta) => console.warn(`[pr_coherence_check] ${msg}`, meta),
|
|
15
|
+
error: (msg, meta) => console.error(`[pr_coherence_check] ${msg}`, meta),
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Compute Sheaf Laplacian energy for coherence detection
|
|
19
|
+
*
|
|
20
|
+
* The Sheaf Laplacian measures how well local data sections can be
|
|
21
|
+
* glued together into a global section. High energy indicates contradictions.
|
|
22
|
+
*
|
|
23
|
+
* For vectors v1, v2, ..., vn:
|
|
24
|
+
* 1. Construct a sheaf over the complete graph
|
|
25
|
+
* 2. Compute the Laplacian matrix L = D - A (where A captures similarities)
|
|
26
|
+
* 3. Energy = sum of disagreements across edges
|
|
27
|
+
*/
|
|
28
|
+
function computeSheafLaplacianEnergy(vectors) {
|
|
29
|
+
if (vectors.length < 2)
|
|
30
|
+
return 0;
|
|
31
|
+
const n = vectors.length;
|
|
32
|
+
let totalEnergy = 0;
|
|
33
|
+
let edgeCount = 0;
|
|
34
|
+
// Compute pairwise disagreement (1 - cosine_similarity)
|
|
35
|
+
for (let i = 0; i < n; i++) {
|
|
36
|
+
for (let j = i + 1; j < n; j++) {
|
|
37
|
+
const vi = vectors[i];
|
|
38
|
+
const vj = vectors[j];
|
|
39
|
+
const similarity = cosineSimilarity(vi, vj);
|
|
40
|
+
const disagreement = 1 - Math.max(0, similarity); // Clamp negative similarities
|
|
41
|
+
totalEnergy += disagreement;
|
|
42
|
+
edgeCount++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Normalize by number of edges
|
|
46
|
+
return edgeCount > 0 ? totalEnergy / edgeCount : 0;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Detect contradictions in the vector set
|
|
50
|
+
*/
|
|
51
|
+
function detectContradictions(vectors, threshold) {
|
|
52
|
+
const violations = [];
|
|
53
|
+
const n = vectors.length;
|
|
54
|
+
for (let i = 0; i < n; i++) {
|
|
55
|
+
for (let j = i + 1; j < n; j++) {
|
|
56
|
+
const vi = vectors[i];
|
|
57
|
+
const vj = vectors[j];
|
|
58
|
+
const similarity = cosineSimilarity(vi, vj);
|
|
59
|
+
// Negative similarity indicates potential contradiction
|
|
60
|
+
if (similarity < -0.3) {
|
|
61
|
+
violations.push(`Contradiction between vectors ${i} and ${j} (similarity: ${similarity.toFixed(3)})`);
|
|
62
|
+
}
|
|
63
|
+
// Low similarity with high threshold indicates inconsistency
|
|
64
|
+
else if (similarity < threshold && similarity > 0) {
|
|
65
|
+
violations.push(`Weak coherence between vectors ${i} and ${j} (similarity: ${similarity.toFixed(3)})`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return violations;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Calculate cosine similarity
|
|
73
|
+
*/
|
|
74
|
+
function cosineSimilarity(a, b) {
|
|
75
|
+
if (a.length !== b.length)
|
|
76
|
+
return 0;
|
|
77
|
+
let dotProduct = 0;
|
|
78
|
+
let normA = 0;
|
|
79
|
+
let normB = 0;
|
|
80
|
+
for (let i = 0; i < a.length; i++) {
|
|
81
|
+
const ai = a[i];
|
|
82
|
+
const bi = b[i];
|
|
83
|
+
dotProduct += ai * bi;
|
|
84
|
+
normA += ai * ai;
|
|
85
|
+
normB += bi * bi;
|
|
86
|
+
}
|
|
87
|
+
const denominator = Math.sqrt(normA) * Math.sqrt(normB);
|
|
88
|
+
return denominator > 0 ? dotProduct / denominator : 0;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get interpretation of energy level
|
|
92
|
+
*/
|
|
93
|
+
function getInterpretation(energy) {
|
|
94
|
+
if (energy < 0.1)
|
|
95
|
+
return 'Fully coherent - vectors are highly consistent';
|
|
96
|
+
if (energy < 0.3)
|
|
97
|
+
return 'Minor inconsistencies - generally coherent with small variations';
|
|
98
|
+
if (energy < 0.5)
|
|
99
|
+
return 'Moderate inconsistencies - some conflicting information detected';
|
|
100
|
+
if (energy < 0.7)
|
|
101
|
+
return 'Significant contradictions - vectors contain conflicting content';
|
|
102
|
+
return 'Major contradictions detected - high disagreement between vectors';
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Handler for pr_coherence_check tool
|
|
106
|
+
*/
|
|
107
|
+
async function handler(input, context) {
|
|
108
|
+
const logger = context?.logger ?? defaultLogger;
|
|
109
|
+
const startTime = performance.now();
|
|
110
|
+
try {
|
|
111
|
+
// Validate input
|
|
112
|
+
const validationResult = CoherenceInputSchema.safeParse(input);
|
|
113
|
+
if (!validationResult.success) {
|
|
114
|
+
logger.error('Input validation failed', { error: validationResult.error.message });
|
|
115
|
+
return errorResult(`Invalid input: ${validationResult.error.message}`);
|
|
116
|
+
}
|
|
117
|
+
const { vectors, threshold } = validationResult.data;
|
|
118
|
+
logger.debug('Processing coherence check', { vectorCount: vectors.length, threshold });
|
|
119
|
+
// Convert to Float32Arrays
|
|
120
|
+
const float32Vectors = vectors.map(v => new Float32Array(v));
|
|
121
|
+
let energy;
|
|
122
|
+
let violations;
|
|
123
|
+
// Try to use WASM bridge if available
|
|
124
|
+
if (context?.bridge?.initialized) {
|
|
125
|
+
try {
|
|
126
|
+
logger.debug('Using WASM bridge for coherence check');
|
|
127
|
+
const result = await context.bridge.checkCoherence(float32Vectors);
|
|
128
|
+
energy = result.energy;
|
|
129
|
+
violations = result.violations;
|
|
130
|
+
}
|
|
131
|
+
catch (wasmError) {
|
|
132
|
+
logger.warn('WASM bridge failed, falling back to JS implementation', {
|
|
133
|
+
error: wasmError instanceof Error ? wasmError.message : String(wasmError),
|
|
134
|
+
});
|
|
135
|
+
energy = computeSheafLaplacianEnergy(float32Vectors);
|
|
136
|
+
violations = detectContradictions(float32Vectors, threshold);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// Pure JavaScript fallback implementation
|
|
141
|
+
logger.debug('Using JavaScript fallback for coherence check');
|
|
142
|
+
energy = computeSheafLaplacianEnergy(float32Vectors);
|
|
143
|
+
violations = detectContradictions(float32Vectors, threshold);
|
|
144
|
+
}
|
|
145
|
+
const isCoherent = energy < threshold;
|
|
146
|
+
const confidence = 1 - energy;
|
|
147
|
+
const output = {
|
|
148
|
+
energy,
|
|
149
|
+
isCoherent,
|
|
150
|
+
details: {
|
|
151
|
+
violations,
|
|
152
|
+
confidence,
|
|
153
|
+
interpretation: getInterpretation(energy),
|
|
154
|
+
vectorCount: vectors.length,
|
|
155
|
+
threshold,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
const duration = performance.now() - startTime;
|
|
159
|
+
logger.info('Coherence check completed', {
|
|
160
|
+
energy: energy.toFixed(4),
|
|
161
|
+
isCoherent,
|
|
162
|
+
violations: violations.length,
|
|
163
|
+
durationMs: duration.toFixed(2),
|
|
164
|
+
});
|
|
165
|
+
return successResult(output);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
const duration = performance.now() - startTime;
|
|
169
|
+
logger.error('Coherence check failed', {
|
|
170
|
+
error: error instanceof Error ? error.message : String(error),
|
|
171
|
+
durationMs: duration.toFixed(2),
|
|
172
|
+
});
|
|
173
|
+
return errorResult(error instanceof Error ? error : new Error(String(error)));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* pr_coherence_check MCP Tool Definition
|
|
178
|
+
*/
|
|
179
|
+
export const coherenceCheckTool = {
|
|
180
|
+
name: 'pr_coherence_check',
|
|
181
|
+
description: 'Check coherence of vectors using Sheaf Laplacian energy. Energy 0 = fully coherent, 1 = contradictory. Uses CohomologyEngine for mathematical validation of vector consistency.',
|
|
182
|
+
category: 'coherence',
|
|
183
|
+
version: '0.1.3',
|
|
184
|
+
tags: ['coherence', 'sheaf-laplacian', 'contradiction-detection', 'ai-interpretability'],
|
|
185
|
+
cacheable: true,
|
|
186
|
+
cacheTTL: 60000, // 1 minute cache
|
|
187
|
+
inputSchema: {
|
|
188
|
+
type: 'object',
|
|
189
|
+
properties: {
|
|
190
|
+
vectors: {
|
|
191
|
+
type: 'array',
|
|
192
|
+
items: { type: 'array', items: { type: 'number' } },
|
|
193
|
+
description: 'Array of embedding vectors to check for coherence',
|
|
194
|
+
},
|
|
195
|
+
threshold: {
|
|
196
|
+
type: 'number',
|
|
197
|
+
default: 0.3,
|
|
198
|
+
description: 'Energy threshold for coherence (0-1). Lower = stricter coherence requirement.',
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
required: ['vectors'],
|
|
202
|
+
},
|
|
203
|
+
handler,
|
|
204
|
+
};
|
|
205
|
+
export default coherenceCheckTool;
|
|
206
|
+
//# sourceMappingURL=coherence-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coherence-check.js","sourceRoot":"","sources":["../../../../src/mcp-tools/coherence/coherence-check.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,sDAAsD;AACtD,MAAM,aAAa,GAAG;IACpB,KAAK,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,wBAAwB,GAAG,EAAE,EAAE,IAAI,CAAC;IAC1G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AChC,CAAC,CAAC;QACH,OAAO,WAAW,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChF,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAY;IACzC,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EAAE,iLAAiL;IAC9L,QAAQ,EAAE,WAAW;IACrB,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,CAAC,WAAW,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,qBAAqB,CAAC;IACxF,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,KAAK,EAAE,iBAAiB;IAClC,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;gBACnD,WAAW,EAAE,mDAAmD;aACjE;YACD,SAAS,EAAE;gBACT,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,GAAG;gBACZ,WAAW,EAAE,+EAA+E;aAC7F;SACF;QACD,QAAQ,EAAE,CAAC,SAAS,CAAC;KACtB;IACD,OAAO;CACR,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consensus Verification Tool - pr_consensus_verify
|
|
3
|
+
*
|
|
4
|
+
* Verifies multi-agent consensus mathematically using coherence analysis.
|
|
5
|
+
* Identifies divergent agents and measures agreement ratios.
|
|
6
|
+
*
|
|
7
|
+
* Uses CohomologyEngine for multi-agent consensus validation
|
|
8
|
+
*/
|
|
9
|
+
import type { MCPTool } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* pr_consensus_verify MCP Tool Definition
|
|
12
|
+
*/
|
|
13
|
+
export declare const consensusVerifyTool: MCPTool;
|
|
14
|
+
export default consensusVerifyTool;
|
|
15
|
+
//# sourceMappingURL=consensus-verify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consensus-verify.d.ts","sourceRoot":"","sources":["../../../../src/mcp-tools/coherence/consensus-verify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,OAAO,EAKR,MAAM,YAAY,CAAC;AA2TpB;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,OAqCjC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consensus Verification Tool - pr_consensus_verify
|
|
3
|
+
*
|
|
4
|
+
* Verifies multi-agent consensus mathematically using coherence analysis.
|
|
5
|
+
* Identifies divergent agents and measures agreement ratios.
|
|
6
|
+
*
|
|
7
|
+
* Uses CohomologyEngine for multi-agent consensus validation
|
|
8
|
+
*/
|
|
9
|
+
import { ConsensusInputSchema, successResult, errorResult, cosineSimilarity, } from './types.js';
|
|
10
|
+
// Default logger
|
|
11
|
+
const defaultLogger = {
|
|
12
|
+
debug: (msg, meta) => console.debug(`[pr_consensus_verify] ${msg}`, meta),
|
|
13
|
+
info: (msg, meta) => console.info(`[pr_consensus_verify] ${msg}`, meta),
|
|
14
|
+
warn: (msg, meta) => console.warn(`[pr_consensus_verify] ${msg}`, meta),
|
|
15
|
+
error: (msg, meta) => console.error(`[pr_consensus_verify] ${msg}`, meta),
|
|
16
|
+
};
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Consensus Analysis Functions
|
|
19
|
+
// ============================================================================
|
|
20
|
+
/**
|
|
21
|
+
* Compute pairwise similarity matrix
|
|
22
|
+
*/
|
|
23
|
+
function computeSimilarityMatrix(embeddings) {
|
|
24
|
+
const n = embeddings.length;
|
|
25
|
+
const matrix = [];
|
|
26
|
+
for (let i = 0; i < n; i++) {
|
|
27
|
+
const row = [];
|
|
28
|
+
const embi = embeddings[i];
|
|
29
|
+
for (let j = 0; j < n; j++) {
|
|
30
|
+
const embj = embeddings[j];
|
|
31
|
+
row.push(cosineSimilarity(embi, embj));
|
|
32
|
+
}
|
|
33
|
+
matrix.push(row);
|
|
34
|
+
}
|
|
35
|
+
return matrix;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Compute coherence energy using Sheaf Laplacian approach
|
|
39
|
+
*/
|
|
40
|
+
function computeCoherenceEnergy(embeddings) {
|
|
41
|
+
if (embeddings.length < 2)
|
|
42
|
+
return 0;
|
|
43
|
+
const n = embeddings.length;
|
|
44
|
+
let totalDisagreement = 0;
|
|
45
|
+
let edgeCount = 0;
|
|
46
|
+
for (let i = 0; i < n; i++) {
|
|
47
|
+
for (let j = i + 1; j < n; j++) {
|
|
48
|
+
const embi = embeddings[i];
|
|
49
|
+
const embj = embeddings[j];
|
|
50
|
+
const similarity = cosineSimilarity(embi, embj);
|
|
51
|
+
const disagreement = 1 - Math.max(0, similarity);
|
|
52
|
+
totalDisagreement += disagreement;
|
|
53
|
+
edgeCount++;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return edgeCount > 0 ? totalDisagreement / edgeCount : 0;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Identify divergent agents whose embeddings differ significantly from the group
|
|
60
|
+
*/
|
|
61
|
+
function identifyDivergentAgents(agentStates, threshold) {
|
|
62
|
+
if (agentStates.length < 2)
|
|
63
|
+
return [];
|
|
64
|
+
const embeddings = agentStates.map(s => s.embedding);
|
|
65
|
+
const n = embeddings.length;
|
|
66
|
+
const divergentAgents = [];
|
|
67
|
+
// Compute centroid
|
|
68
|
+
const firstEmb = embeddings[0];
|
|
69
|
+
if (!firstEmb)
|
|
70
|
+
return [];
|
|
71
|
+
const dim = firstEmb.length;
|
|
72
|
+
const centroid = new Array(dim).fill(0);
|
|
73
|
+
for (const emb of embeddings) {
|
|
74
|
+
for (let d = 0; d < dim; d++) {
|
|
75
|
+
const val = emb[d];
|
|
76
|
+
if (val !== undefined) {
|
|
77
|
+
centroid[d] = (centroid[d] ?? 0) + val / n;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Find agents far from centroid
|
|
82
|
+
for (let i = 0; i < n; i++) {
|
|
83
|
+
const embi = embeddings[i];
|
|
84
|
+
const agentState = agentStates[i];
|
|
85
|
+
const similarity = cosineSimilarity(embi, centroid);
|
|
86
|
+
if (similarity < threshold) {
|
|
87
|
+
divergentAgents.push(agentState.agentId);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return divergentAgents;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Compute vote-based agreement ratio
|
|
94
|
+
*/
|
|
95
|
+
function computeVoteAgreement(agentStates) {
|
|
96
|
+
const votes = agentStates.filter(s => s.vote !== undefined).map(s => s.vote);
|
|
97
|
+
if (votes.length < 2)
|
|
98
|
+
return 1;
|
|
99
|
+
// Count vote frequencies
|
|
100
|
+
const voteCounts = new Map();
|
|
101
|
+
for (const vote of votes) {
|
|
102
|
+
voteCounts.set(vote, (voteCounts.get(vote) || 0) + 1);
|
|
103
|
+
}
|
|
104
|
+
// Agreement is based on majority
|
|
105
|
+
const values = Array.from(voteCounts.values());
|
|
106
|
+
const maxCount = values.length > 0 ? Math.max(...values) : 0;
|
|
107
|
+
return maxCount / votes.length;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Compute spectral stability from similarity matrix
|
|
111
|
+
*/
|
|
112
|
+
function computeSpectralStability(similarityMatrix) {
|
|
113
|
+
const n = similarityMatrix.length;
|
|
114
|
+
if (n < 2)
|
|
115
|
+
return { stable: true, spectralGap: 1 };
|
|
116
|
+
// Convert similarity to adjacency (threshold at 0.5)
|
|
117
|
+
const adjacency = [];
|
|
118
|
+
for (let i = 0; i < n; i++) {
|
|
119
|
+
const row = [];
|
|
120
|
+
const simRow = similarityMatrix[i];
|
|
121
|
+
for (let j = 0; j < n; j++) {
|
|
122
|
+
const simVal = simRow[j] ?? 0;
|
|
123
|
+
row.push(simVal > 0.5 ? simVal : 0);
|
|
124
|
+
}
|
|
125
|
+
adjacency.push(row);
|
|
126
|
+
}
|
|
127
|
+
// Compute degree matrix and Laplacian
|
|
128
|
+
const degrees = [];
|
|
129
|
+
for (let i = 0; i < n; i++) {
|
|
130
|
+
let degree = 0;
|
|
131
|
+
const adjRow = adjacency[i];
|
|
132
|
+
for (let j = 0; j < n; j++) {
|
|
133
|
+
degree += adjRow[j] ?? 0;
|
|
134
|
+
}
|
|
135
|
+
degrees.push(degree);
|
|
136
|
+
}
|
|
137
|
+
// Estimate spectral gap using power iteration on Laplacian
|
|
138
|
+
// Simplified: use average degree connectivity as proxy
|
|
139
|
+
const avgDegree = degrees.reduce((a, b) => a + b, 0) / n;
|
|
140
|
+
const maxDegree = Math.max(...degrees);
|
|
141
|
+
const spectralGap = maxDegree > 0 ? avgDegree / maxDegree : 0;
|
|
142
|
+
const stable = spectralGap > 0.3;
|
|
143
|
+
return { stable, spectralGap };
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get interpretation of consensus results
|
|
147
|
+
*/
|
|
148
|
+
function getInterpretation(verified, coherenceScore, divergentAgents, spectralStability) {
|
|
149
|
+
if (verified && divergentAgents.length === 0) {
|
|
150
|
+
return 'Strong consensus achieved - all agents are aligned';
|
|
151
|
+
}
|
|
152
|
+
if (verified && divergentAgents.length > 0) {
|
|
153
|
+
return `Consensus achieved with ${divergentAgents.length} minority agent(s)`;
|
|
154
|
+
}
|
|
155
|
+
if (!spectralStability) {
|
|
156
|
+
return 'Consensus not achieved - agent network shows instability patterns';
|
|
157
|
+
}
|
|
158
|
+
if (coherenceScore < 0.5) {
|
|
159
|
+
return 'Consensus not achieved - significant disagreement between agents';
|
|
160
|
+
}
|
|
161
|
+
return `Consensus not achieved - ${divergentAgents.length} divergent agent(s) detected`;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Handler for pr_consensus_verify tool
|
|
165
|
+
*/
|
|
166
|
+
async function handler(input, context) {
|
|
167
|
+
const logger = context?.logger ?? defaultLogger;
|
|
168
|
+
const startTime = performance.now();
|
|
169
|
+
try {
|
|
170
|
+
// Validate input
|
|
171
|
+
const validationResult = ConsensusInputSchema.safeParse(input);
|
|
172
|
+
if (!validationResult.success) {
|
|
173
|
+
logger.error('Input validation failed', { error: validationResult.error.message });
|
|
174
|
+
return errorResult(`Invalid input: ${validationResult.error.message}`);
|
|
175
|
+
}
|
|
176
|
+
const { agentStates, threshold } = validationResult.data;
|
|
177
|
+
logger.debug('Processing consensus verification', {
|
|
178
|
+
agentCount: agentStates.length,
|
|
179
|
+
threshold,
|
|
180
|
+
});
|
|
181
|
+
if (agentStates.length === 0) {
|
|
182
|
+
return errorResult('No agent states provided');
|
|
183
|
+
}
|
|
184
|
+
// Validate embedding dimensions are consistent
|
|
185
|
+
const firstDim = agentStates[0].embedding.length;
|
|
186
|
+
for (let i = 1; i < agentStates.length; i++) {
|
|
187
|
+
if (agentStates[i].embedding.length !== firstDim) {
|
|
188
|
+
return errorResult(`Embedding dimension mismatch: agent ${agentStates[i].agentId} has ` +
|
|
189
|
+
`${agentStates[i].embedding.length} dimensions, expected ${firstDim}`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const embeddings = agentStates.map(s => s.embedding);
|
|
193
|
+
let coherenceEnergy;
|
|
194
|
+
let divergentAgents;
|
|
195
|
+
// Try to use WASM bridge if available
|
|
196
|
+
if (context?.bridge?.initialized) {
|
|
197
|
+
try {
|
|
198
|
+
logger.debug('Using WASM bridge for coherence check');
|
|
199
|
+
const float32Embeddings = embeddings.map(e => new Float32Array(e));
|
|
200
|
+
const result = await context.bridge.checkCoherence(float32Embeddings);
|
|
201
|
+
coherenceEnergy = result.energy;
|
|
202
|
+
// WASM doesn't return divergent agents, compute separately
|
|
203
|
+
divergentAgents = identifyDivergentAgents(agentStates, threshold);
|
|
204
|
+
}
|
|
205
|
+
catch (wasmError) {
|
|
206
|
+
logger.warn('WASM bridge failed, falling back to JS implementation', {
|
|
207
|
+
error: wasmError instanceof Error ? wasmError.message : String(wasmError),
|
|
208
|
+
});
|
|
209
|
+
coherenceEnergy = computeCoherenceEnergy(embeddings);
|
|
210
|
+
divergentAgents = identifyDivergentAgents(agentStates, threshold);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
// Pure JavaScript fallback
|
|
215
|
+
logger.debug('Using JavaScript fallback for consensus verification');
|
|
216
|
+
coherenceEnergy = computeCoherenceEnergy(embeddings);
|
|
217
|
+
divergentAgents = identifyDivergentAgents(agentStates, threshold);
|
|
218
|
+
}
|
|
219
|
+
// Compute additional metrics
|
|
220
|
+
const similarityMatrix = computeSimilarityMatrix(embeddings);
|
|
221
|
+
const { stable: spectralStability, spectralGap } = computeSpectralStability(similarityMatrix);
|
|
222
|
+
const voteAgreement = computeVoteAgreement(agentStates);
|
|
223
|
+
// Coherence score is inverse of energy
|
|
224
|
+
const coherenceScore = 1 - coherenceEnergy;
|
|
225
|
+
// Agreement ratio combines embedding coherence and vote agreement
|
|
226
|
+
const agreementRatio = (coherenceScore + voteAgreement) / 2;
|
|
227
|
+
// Consensus is verified if agreement exceeds threshold and no major divergence
|
|
228
|
+
const verified = agreementRatio >= threshold &&
|
|
229
|
+
divergentAgents.length <= Math.floor(agentStates.length * 0.2); // Allow 20% minority
|
|
230
|
+
const output = {
|
|
231
|
+
verified,
|
|
232
|
+
coherenceScore,
|
|
233
|
+
divergentAgents,
|
|
234
|
+
details: {
|
|
235
|
+
agreementRatio,
|
|
236
|
+
coherenceEnergy,
|
|
237
|
+
spectralStability,
|
|
238
|
+
spectralGap,
|
|
239
|
+
interpretation: getInterpretation(verified, coherenceScore, divergentAgents, spectralStability),
|
|
240
|
+
agentCount: agentStates.length,
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
const duration = performance.now() - startTime;
|
|
244
|
+
logger.info('Consensus verification completed', {
|
|
245
|
+
verified,
|
|
246
|
+
coherenceScore: coherenceScore.toFixed(4),
|
|
247
|
+
divergentAgents: divergentAgents.length,
|
|
248
|
+
durationMs: duration.toFixed(2),
|
|
249
|
+
});
|
|
250
|
+
return successResult(output);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
const duration = performance.now() - startTime;
|
|
254
|
+
logger.error('Consensus verification failed', {
|
|
255
|
+
error: error instanceof Error ? error.message : String(error),
|
|
256
|
+
durationMs: duration.toFixed(2),
|
|
257
|
+
});
|
|
258
|
+
return errorResult(error instanceof Error ? error : new Error(String(error)));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* pr_consensus_verify MCP Tool Definition
|
|
263
|
+
*/
|
|
264
|
+
export const consensusVerifyTool = {
|
|
265
|
+
name: 'pr_consensus_verify',
|
|
266
|
+
description: 'Verify multi-agent consensus mathematically using coherence analysis. Identifies divergent agents and measures agreement ratios. Uses CohomologyEngine for consensus validation.',
|
|
267
|
+
category: 'consensus',
|
|
268
|
+
version: '0.1.3',
|
|
269
|
+
tags: ['consensus', 'multi-agent', 'coherence', 'swarm', 'ai-interpretability'],
|
|
270
|
+
cacheable: false, // Agent states change frequently
|
|
271
|
+
inputSchema: {
|
|
272
|
+
type: 'object',
|
|
273
|
+
properties: {
|
|
274
|
+
agentStates: {
|
|
275
|
+
type: 'array',
|
|
276
|
+
items: {
|
|
277
|
+
type: 'object',
|
|
278
|
+
properties: {
|
|
279
|
+
agentId: { type: 'string', description: 'Unique agent identifier' },
|
|
280
|
+
embedding: {
|
|
281
|
+
type: 'array',
|
|
282
|
+
items: { type: 'number' },
|
|
283
|
+
description: 'Agent state embedding vector',
|
|
284
|
+
},
|
|
285
|
+
vote: { type: 'string', description: 'Agent vote or decision' },
|
|
286
|
+
metadata: { type: 'object', description: 'Additional agent metadata' },
|
|
287
|
+
},
|
|
288
|
+
required: ['agentId', 'embedding'],
|
|
289
|
+
},
|
|
290
|
+
description: 'Array of agent states to verify consensus',
|
|
291
|
+
},
|
|
292
|
+
threshold: {
|
|
293
|
+
type: 'number',
|
|
294
|
+
default: 0.8,
|
|
295
|
+
description: 'Required agreement threshold (0-1)',
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
required: ['agentStates'],
|
|
299
|
+
},
|
|
300
|
+
handler,
|
|
301
|
+
};
|
|
302
|
+
export default consensusVerifyTool;
|
|
303
|
+
//# sourceMappingURL=consensus-verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consensus-verify.js","sourceRoot":"","sources":["../../../../src/mcp-tools/coherence/consensus-verify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAEpB,iBAAiB;AACjB,MAAM,aAAa,GAAG;IACpB,KAAK,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,yBAAyB,GAAG,EAAE,EAAE,IAAI,CAAC;IAC3G,IAAI,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,yBAAyB,GAAG,EAAE,EAAE,IAAI,CAAC;IACzG,IAAI,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,yBAAyB,GAAG,EAAE,EAAE,IAAI,CAAC;IACzG,KAAK,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,yBAAyB,GAAG,EAAE,EAAE,IAAI,CAAC;CAC5G,CAAC;AAEF,+EAA+E;AAC/E,+BAA+B;AAC/B,+EAA+E;AAE/E;;GAEG;AACH,SAAS,uBAAuB,CAAC,UAAsB;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gBACT,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,GAAG;gBACZ,WAAW,EAAE,oCAAoC;aAClD;SACF;QACD,QAAQ,EAAE,CAAC,aAAa,CAAC;KAC1B;IACD,OAAO;CACR,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Gate Tool - pr_memory_gate
|
|
3
|
+
*
|
|
4
|
+
* Pre-storage coherence gate for memory entries.
|
|
5
|
+
* Validates that new entries are coherent with existing context before storage.
|
|
6
|
+
*
|
|
7
|
+
* Uses CohomologyEngine Sheaf Laplacian for coherence validation
|
|
8
|
+
*/
|
|
9
|
+
import type { MCPTool } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* pr_memory_gate MCP Tool Definition
|
|
12
|
+
*/
|
|
13
|
+
export declare const memoryGateTool: MCPTool;
|
|
14
|
+
export default memoryGateTool;
|
|
15
|
+
//# sourceMappingURL=memory-gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-gate.d.ts","sourceRoot":"","sources":["../../../../src/mcp-tools/coherence/memory-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,OAAO,EAIR,MAAM,YAAY,CAAC;AA0QpB;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,OA0C5B,CAAC;AAEF,eAAe,cAAc,CAAC"}
|