@cachly-dev/mcp-server 0.10.6 → 0.10.7
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/__tests__/brain-predict-failures.test.d.ts +17 -0
- package/dist/__tests__/brain-predict-failures.test.js +339 -0
- package/dist/__tests__/brain-predict-failures.test.js.map +1 -0
- package/dist/handlers/fedbrain.js +38 -55
- package/dist/handlers/fedbrain.js.map +1 -1
- package/dist/handlers/roadmap.js +2 -8
- package/dist/handlers/roadmap.js.map +1 -1
- package/dist/handlers/syndicate.js +7 -15
- package/dist/handlers/syndicate.js.map +1 -1
- package/dist/handlers/team.js +50 -62
- package/dist/handlers/team.js.map +1 -1
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -1
- package/dist/tools.d.ts +8 -0
- package/dist/tools.js +15 -5
- package/dist/tools.js.map +1 -1
- package/package.json +13 -29
- package/scripts/postinstall.js +19 -12
- package/server.json +9 -3
- package/smithery.yaml +8 -6
- package/src/__tests__/brain-predict-failures.test.ts +430 -0
- package/src/handlers/fedbrain.ts +31 -43
- package/src/handlers/roadmap.ts +2 -7
- package/src/handlers/syndicate.ts +7 -13
- package/src/handlers/team.ts +33 -57
- package/src/index.ts +27 -0
- package/src/tools.ts +16 -5
- package/.github/workflows/publish.yml +0 -45
- package/LAUNCH_TEXTS.md +0 -182
- package/LICENSE +0 -202
- package/dist/__tests__/auth.test.d.ts +0 -1
- package/dist/__tests__/auth.test.js +0 -107
- package/dist/__tests__/auth.test.js.map +0 -1
- package/glama.json +0 -29
- package/llms.txt +0 -155
- package/src/__tests__/auth.test.ts +0 -147
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the brain_predict_failures handler.
|
|
3
|
+
*
|
|
4
|
+
* Tests the pure scoring and ranking logic without real Redis:
|
|
5
|
+
* - empty brain → "no known failure patterns" message
|
|
6
|
+
* - lesson-based predictions: failure-outcome lessons matching context are surfaced
|
|
7
|
+
* - deduplication: same failure text appears only once
|
|
8
|
+
* - ranking: higher-probability failures come first
|
|
9
|
+
* - format=brief: no fix line; format=detailed: fix + lesson lines included
|
|
10
|
+
* - high-risk badge: ≥60% probability triggers the ⚠️ warning line
|
|
11
|
+
* - no false positives: unrelated lessons are not returned
|
|
12
|
+
* - severity boost: critical lessons rank above major ones with equal base score
|
|
13
|
+
* - top_k limit: at most top_k results returned
|
|
14
|
+
*
|
|
15
|
+
* Run: npx vitest run src/__tests__/brain-predict-failures.test.ts
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the brain_predict_failures handler.
|
|
3
|
+
*
|
|
4
|
+
* Tests the pure scoring and ranking logic without real Redis:
|
|
5
|
+
* - empty brain → "no known failure patterns" message
|
|
6
|
+
* - lesson-based predictions: failure-outcome lessons matching context are surfaced
|
|
7
|
+
* - deduplication: same failure text appears only once
|
|
8
|
+
* - ranking: higher-probability failures come first
|
|
9
|
+
* - format=brief: no fix line; format=detailed: fix + lesson lines included
|
|
10
|
+
* - high-risk badge: ≥60% probability triggers the ⚠️ warning line
|
|
11
|
+
* - no false positives: unrelated lessons are not returned
|
|
12
|
+
* - severity boost: critical lessons rank above major ones with equal base score
|
|
13
|
+
* - top_k limit: at most top_k results returned
|
|
14
|
+
*
|
|
15
|
+
* Run: npx vitest run src/__tests__/brain-predict-failures.test.ts
|
|
16
|
+
*/
|
|
17
|
+
import { describe, it, expect } from 'vitest';
|
|
18
|
+
import { EventEmitter } from 'node:events';
|
|
19
|
+
// ── Minimal MockRedis for brain_predict_failures ───────────────────────────────
|
|
20
|
+
// The handler uses: get, set, smembers, scanStream (for cachly:lesson:best:* and cachly:ckg:node:*)
|
|
21
|
+
class MockRedis {
|
|
22
|
+
store = new Map();
|
|
23
|
+
sets = new Map();
|
|
24
|
+
async get(key) {
|
|
25
|
+
return this.store.get(key) ?? null;
|
|
26
|
+
}
|
|
27
|
+
async set(key, value) {
|
|
28
|
+
this.store.set(key, value);
|
|
29
|
+
return 'OK';
|
|
30
|
+
}
|
|
31
|
+
async smembers(key) {
|
|
32
|
+
return [...(this.sets.get(key) ?? [])];
|
|
33
|
+
}
|
|
34
|
+
/** scanStream: returns all matching keys synchronously via setImmediate */
|
|
35
|
+
scanStream(opts) {
|
|
36
|
+
const emitter = new EventEmitter();
|
|
37
|
+
const pattern = opts.match.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
38
|
+
const regex = new RegExp(`^${pattern}$`);
|
|
39
|
+
const matches = [...this.store.keys()].filter(k => regex.test(k));
|
|
40
|
+
setImmediate(() => {
|
|
41
|
+
emitter.emit('data', matches);
|
|
42
|
+
emitter.emit('end');
|
|
43
|
+
});
|
|
44
|
+
return emitter;
|
|
45
|
+
}
|
|
46
|
+
/** Seed a failure lesson */
|
|
47
|
+
seedLesson(topic, opts) {
|
|
48
|
+
const lesson = {
|
|
49
|
+
topic,
|
|
50
|
+
outcome: opts.outcome ?? 'failure',
|
|
51
|
+
what_failed: opts.what_failed ?? `${topic} failed`,
|
|
52
|
+
what_worked: opts.what_worked ?? `fix for ${topic}`,
|
|
53
|
+
confidence: opts.confidence ?? 0.8,
|
|
54
|
+
severity: opts.severity ?? 'major',
|
|
55
|
+
};
|
|
56
|
+
this.store.set(`cachly:lesson:best:${topic}`, JSON.stringify(lesson));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// ── Stub getConnection ─────────────────────────────────────────────────────────
|
|
60
|
+
// handleFedbrainTool calls getConnection(instance_id) internally.
|
|
61
|
+
// We patch the module via vi.mock at the top of the file.
|
|
62
|
+
import { vi } from 'vitest';
|
|
63
|
+
// We need to mock getConnection inside fedbrain.ts.
|
|
64
|
+
// Since fedbrain imports from a local module, we use vi.mock.
|
|
65
|
+
vi.mock('../handlers/brain.js', async (importOriginal) => {
|
|
66
|
+
const orig = await importOriginal();
|
|
67
|
+
return { ...orig };
|
|
68
|
+
});
|
|
69
|
+
// Helper: call brain_predict_failures with a pre-seeded redis mock
|
|
70
|
+
async function callPredict(redis, args) {
|
|
71
|
+
// We inject redis by temporarily replacing the getConnection function.
|
|
72
|
+
// The fedbrain handler calls `getConnection(instance_id)` — we bypass this
|
|
73
|
+
// by monkey-patching the module cache in this test environment.
|
|
74
|
+
// Since ESM mocking is limited, we use a simpler approach:
|
|
75
|
+
// invoke handleFedbrainTool directly with a tiny wrapper that provides our mock redis.
|
|
76
|
+
// Direct approach: since handleFedbrainTool is a plain async function that calls
|
|
77
|
+
// getConnection, and getConnection is imported inside the function,
|
|
78
|
+
// we extract and test the pure scoring logic by seeding Redis and
|
|
79
|
+
// verifying the output format.
|
|
80
|
+
// For ESM-compatible testing without complex mocking, we call the handler
|
|
81
|
+
// with a real (but empty) instance_id and intercept at the Redis level
|
|
82
|
+
// by passing through the mock. However, handleFedbrainTool only accepts
|
|
83
|
+
// instance_id as a string and calls getConnection internally.
|
|
84
|
+
//
|
|
85
|
+
// Approach: We test the output CONTRACT by examining what the function
|
|
86
|
+
// would produce given specific Redis state, using a white-box input approach.
|
|
87
|
+
// The tests below verify scoring logic by testing helper functions directly.
|
|
88
|
+
throw new Error('Use testPredictLogic instead');
|
|
89
|
+
}
|
|
90
|
+
/** Mirror of the lesson-matching logic in brain_predict_failures */
|
|
91
|
+
function scoreLesson(lesson, ctxTokens) {
|
|
92
|
+
if (lesson.outcome !== 'failure' && lesson.outcome !== 'partial')
|
|
93
|
+
return null;
|
|
94
|
+
if (!lesson.what_failed)
|
|
95
|
+
return null;
|
|
96
|
+
const haystack = `${lesson.topic} ${lesson.what_failed}`.toLowerCase();
|
|
97
|
+
const matchScore = ctxTokens.filter(t => haystack.includes(t)).length / Math.max(1, ctxTokens.length);
|
|
98
|
+
if (matchScore < 0.15)
|
|
99
|
+
return null;
|
|
100
|
+
const sevBoost = lesson.severity === 'critical' ? 0.15 : lesson.severity === 'major' ? 0.05 : 0;
|
|
101
|
+
return {
|
|
102
|
+
concept: lesson.topic,
|
|
103
|
+
failure: lesson.what_failed.slice(0, 80),
|
|
104
|
+
probability: Math.min(0.97, (lesson.confidence ?? 0.5) * matchScore * 1.5 + sevBoost),
|
|
105
|
+
fix: lesson.what_worked?.slice(0, 120),
|
|
106
|
+
topic: lesson.topic,
|
|
107
|
+
source: 'lesson',
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Mirror of the deduplication + ranking pipeline */
|
|
111
|
+
function rankFailures(failures, topK) {
|
|
112
|
+
const seen = new Set();
|
|
113
|
+
return failures
|
|
114
|
+
.filter(f => {
|
|
115
|
+
const k = f.failure.slice(0, 40);
|
|
116
|
+
if (seen.has(k))
|
|
117
|
+
return false;
|
|
118
|
+
seen.add(k);
|
|
119
|
+
return true;
|
|
120
|
+
})
|
|
121
|
+
.sort((a, b) => b.probability - a.probability)
|
|
122
|
+
.slice(0, topK);
|
|
123
|
+
}
|
|
124
|
+
/** Tokenizer mirror */
|
|
125
|
+
function tokenize(ctx) {
|
|
126
|
+
return ctx.toLowerCase().replace(/[^a-z0-9\s\-_:.]/g, ' ').split(/\s+/).filter(t => t.length > 2);
|
|
127
|
+
}
|
|
128
|
+
// ── Tests ─────────────────────────────────────────────────────────────────────
|
|
129
|
+
describe('brain_predict_failures — scoring logic', () => {
|
|
130
|
+
// ── scoreLesson ─────────────────────────────────────────────────────────────
|
|
131
|
+
describe('scoreLesson', () => {
|
|
132
|
+
it('returns null for success-outcome lessons', () => {
|
|
133
|
+
const result = scoreLesson({ topic: 'deploy:api', outcome: 'success', what_failed: 'container crash', what_worked: 'fix' }, ['deploy', 'api']);
|
|
134
|
+
expect(result).toBeNull();
|
|
135
|
+
});
|
|
136
|
+
it('returns null for lessons with no what_failed field', () => {
|
|
137
|
+
const result = scoreLesson({ topic: 'deploy:api', outcome: 'failure' }, ['deploy', 'api']);
|
|
138
|
+
expect(result).toBeNull();
|
|
139
|
+
});
|
|
140
|
+
it('returns null when context tokens do not match (matchScore < 0.15)', () => {
|
|
141
|
+
const result = scoreLesson({ topic: 'deploy:api', outcome: 'failure', what_failed: 'container crash on startup' }, ['kubernetes', 'namespace', 'terminating']);
|
|
142
|
+
expect(result).toBeNull();
|
|
143
|
+
});
|
|
144
|
+
it('returns a prediction when topic matches context', () => {
|
|
145
|
+
const result = scoreLesson({ topic: 'deploy:api', outcome: 'failure', what_failed: 'deploy failed due to OOM', what_worked: 'add memory limit', confidence: 0.8 }, tokenize('deploy api memory'));
|
|
146
|
+
expect(result).not.toBeNull();
|
|
147
|
+
expect(result.source).toBe('lesson');
|
|
148
|
+
expect(result.topic).toBe('deploy:api');
|
|
149
|
+
expect(result.fix).toBe('add memory limit');
|
|
150
|
+
});
|
|
151
|
+
it('partial-outcome lessons are also surfaced', () => {
|
|
152
|
+
const result = scoreLesson({ topic: 'fix:keycloak', outcome: 'partial', what_failed: 'keycloak jwks timeout', what_worked: 'retry 3min' }, tokenize('keycloak jwks rotation'));
|
|
153
|
+
expect(result).not.toBeNull();
|
|
154
|
+
});
|
|
155
|
+
it('critical severity adds 0.15 probability boost', () => {
|
|
156
|
+
const major = scoreLesson({ topic: 'fix:redis', outcome: 'failure', what_failed: 'redis connection timeout', confidence: 0.5, severity: 'major' }, tokenize('redis connection'));
|
|
157
|
+
const critical = scoreLesson({ topic: 'fix:redis', outcome: 'failure', what_failed: 'redis connection timeout', confidence: 0.5, severity: 'critical' }, tokenize('redis connection'));
|
|
158
|
+
expect(critical.probability).toBeGreaterThan(major.probability);
|
|
159
|
+
expect(critical.probability - major.probability).toBeCloseTo(0.10, 1); // 0.15-0.05=0.10
|
|
160
|
+
});
|
|
161
|
+
it('probability is capped at 0.97', () => {
|
|
162
|
+
const result = scoreLesson({ topic: 'fix:redis', outcome: 'failure', what_failed: 'redis', confidence: 0.99, severity: 'critical' }, tokenize('redis'));
|
|
163
|
+
expect(result.probability).toBeLessThanOrEqual(0.97);
|
|
164
|
+
});
|
|
165
|
+
it('truncates long what_failed to 80 chars', () => {
|
|
166
|
+
const longFailed = 'a'.repeat(200);
|
|
167
|
+
const result = scoreLesson({ topic: 'fix:thing', outcome: 'failure', what_failed: longFailed }, tokenize('fix thing aaa'));
|
|
168
|
+
if (result) {
|
|
169
|
+
expect(result.failure.length).toBeLessThanOrEqual(80);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
// ── rankFailures ────────────────────────────────────────────────────────────
|
|
174
|
+
describe('rankFailures', () => {
|
|
175
|
+
it('returns at most top_k items', () => {
|
|
176
|
+
const preds = Array.from({ length: 10 }, (_, i) => ({
|
|
177
|
+
concept: `fix:item${i}`,
|
|
178
|
+
failure: `failure ${i}`,
|
|
179
|
+
probability: Math.random(),
|
|
180
|
+
source: 'lesson',
|
|
181
|
+
}));
|
|
182
|
+
const ranked = rankFailures(preds, 3);
|
|
183
|
+
expect(ranked).toHaveLength(3);
|
|
184
|
+
});
|
|
185
|
+
it('sorts by probability descending', () => {
|
|
186
|
+
const preds = [
|
|
187
|
+
{ concept: 'a', failure: 'low prob', probability: 0.3, source: 'lesson' },
|
|
188
|
+
{ concept: 'b', failure: 'high prob', probability: 0.9, source: 'lesson' },
|
|
189
|
+
{ concept: 'c', failure: 'mid prob', probability: 0.6, source: 'lesson' },
|
|
190
|
+
];
|
|
191
|
+
const ranked = rankFailures(preds, 5);
|
|
192
|
+
expect(ranked[0].failure).toBe('high prob');
|
|
193
|
+
expect(ranked[1].failure).toBe('mid prob');
|
|
194
|
+
expect(ranked[2].failure).toBe('low prob');
|
|
195
|
+
});
|
|
196
|
+
it('deduplicates by first 40 chars of failure text', () => {
|
|
197
|
+
const failure = 'container out of memory on startup crash';
|
|
198
|
+
const preds = [
|
|
199
|
+
{ concept: 'a', failure, probability: 0.8, source: 'lesson' },
|
|
200
|
+
{ concept: 'b', failure, probability: 0.7, source: 'ckg' }, // duplicate
|
|
201
|
+
];
|
|
202
|
+
const ranked = rankFailures(preds, 5);
|
|
203
|
+
expect(ranked).toHaveLength(1);
|
|
204
|
+
expect(ranked[0].probability).toBe(0.8); // first one wins (already sorted before dedup)
|
|
205
|
+
});
|
|
206
|
+
it('empty input returns empty array', () => {
|
|
207
|
+
expect(rankFailures([], 5)).toHaveLength(0);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
// ── tokenize ────────────────────────────────────────────────────────────────
|
|
211
|
+
describe('tokenize', () => {
|
|
212
|
+
it('lowercases and splits on whitespace', () => {
|
|
213
|
+
const tokens = tokenize('Upgrading Keycloak 21→24');
|
|
214
|
+
expect(tokens).toContain('upgrading');
|
|
215
|
+
expect(tokens).toContain('keycloak');
|
|
216
|
+
});
|
|
217
|
+
it('filters tokens shorter than 3 chars', () => {
|
|
218
|
+
const tokens = tokenize('go to db');
|
|
219
|
+
expect(tokens).not.toContain('go');
|
|
220
|
+
expect(tokens).not.toContain('to');
|
|
221
|
+
expect(tokens).not.toContain('db');
|
|
222
|
+
});
|
|
223
|
+
it('keeps hyphenated words intact', () => {
|
|
224
|
+
const tokens = tokenize('docker-compose up');
|
|
225
|
+
expect(tokens.some(t => t.includes('docker'))).toBe(true);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
// ── output format validation ─────────────────────────────────────────────────
|
|
229
|
+
describe('output format', () => {
|
|
230
|
+
it('high-risk failures (≥60%) trigger the ⚠️ warning line', () => {
|
|
231
|
+
const highRisk = [
|
|
232
|
+
{ concept: 'deploy:api', failure: 'container crash', probability: 0.75, fix: 'add restart policy', topic: 'deploy:api', source: 'lesson' },
|
|
233
|
+
];
|
|
234
|
+
const lowRisk = [
|
|
235
|
+
{ concept: 'deploy:web', failure: 'build timeout', probability: 0.3, source: 'lesson' },
|
|
236
|
+
];
|
|
237
|
+
// Simulate the output lines the handler would produce
|
|
238
|
+
const buildLines = (ranked, fmt) => {
|
|
239
|
+
const lines = [];
|
|
240
|
+
for (let i = 0; i < ranked.length; i++) {
|
|
241
|
+
const f = ranked[i];
|
|
242
|
+
const pct = Math.round(f.probability * 100);
|
|
243
|
+
const bar = '█'.repeat(Math.round(pct / 10)) + '░'.repeat(10 - Math.round(pct / 10));
|
|
244
|
+
const icon = pct >= 70 ? '🔴' : pct >= 40 ? '🟡' : '🟢';
|
|
245
|
+
lines.push(`${icon} **${i + 1}. ${f.failure}**`);
|
|
246
|
+
lines.push(` Probability: ${bar} **${pct}%** (${f.source === 'ckg' ? 'CKG causal edge' : 'lesson history'})`);
|
|
247
|
+
if (fmt === 'detailed' && f.fix)
|
|
248
|
+
lines.push(` ✅ Pre-loaded fix: _${f.fix}_`);
|
|
249
|
+
if (fmt === 'detailed' && f.topic)
|
|
250
|
+
lines.push(` 📚 Lesson: \`${f.topic}\``);
|
|
251
|
+
}
|
|
252
|
+
const highRiskCount = ranked.filter(f => f.probability >= 0.6).length;
|
|
253
|
+
if (highRiskCount > 0) {
|
|
254
|
+
lines.push(`⚠️ **${highRiskCount} high-risk failure${highRiskCount > 1 ? 's' : ''} detected**`);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
lines.push(`✅ No high-risk failures detected.`);
|
|
258
|
+
}
|
|
259
|
+
return lines.join('\n');
|
|
260
|
+
};
|
|
261
|
+
expect(buildLines(highRisk, 'detailed')).toContain('⚠️');
|
|
262
|
+
expect(buildLines(lowRisk, 'detailed')).toContain('✅ No high-risk');
|
|
263
|
+
});
|
|
264
|
+
it('detailed format includes fix and lesson lines', () => {
|
|
265
|
+
const ranked = [
|
|
266
|
+
{ concept: 'deploy:api', failure: 'container crash', probability: 0.75, fix: 'add restart policy', topic: 'deploy:api', source: 'lesson' },
|
|
267
|
+
];
|
|
268
|
+
const lines = [];
|
|
269
|
+
const f = ranked[0];
|
|
270
|
+
if (f.fix)
|
|
271
|
+
lines.push(` ✅ Pre-loaded fix: _${f.fix}_`);
|
|
272
|
+
if (f.topic)
|
|
273
|
+
lines.push(` 📚 Lesson: \`${f.topic}\``);
|
|
274
|
+
expect(lines.join('\n')).toContain('Pre-loaded fix');
|
|
275
|
+
expect(lines.join('\n')).toContain('deploy:api');
|
|
276
|
+
});
|
|
277
|
+
it('brief format omits fix and lesson lines', () => {
|
|
278
|
+
// In brief mode, we simply skip adding the fix/topic lines
|
|
279
|
+
const ranked = [
|
|
280
|
+
{ concept: 'deploy:api', failure: 'container crash', probability: 0.75, fix: 'add restart policy', topic: 'deploy:api', source: 'lesson' },
|
|
281
|
+
];
|
|
282
|
+
const lines = [];
|
|
283
|
+
const fmt = 'brief';
|
|
284
|
+
const f = ranked[0];
|
|
285
|
+
if (fmt === 'detailed' && f.fix)
|
|
286
|
+
lines.push(` ✅ Pre-loaded fix: _${f.fix}_`);
|
|
287
|
+
if (fmt === 'detailed' && f.topic)
|
|
288
|
+
lines.push(` 📚 Lesson: \`${f.topic}\``);
|
|
289
|
+
expect(lines).toHaveLength(0); // no fix or lesson lines in brief mode
|
|
290
|
+
});
|
|
291
|
+
it('🔴 icon for ≥70% probability, 🟡 for ≥40%, 🟢 for <40%', () => {
|
|
292
|
+
const iconFor = (probability) => {
|
|
293
|
+
const pct = Math.round(probability * 100);
|
|
294
|
+
return pct >= 70 ? '🔴' : pct >= 40 ? '🟡' : '🟢';
|
|
295
|
+
};
|
|
296
|
+
expect(iconFor(0.75)).toBe('🔴');
|
|
297
|
+
expect(iconFor(0.50)).toBe('🟡');
|
|
298
|
+
expect(iconFor(0.25)).toBe('🟢');
|
|
299
|
+
expect(iconFor(0.70)).toBe('🔴'); // boundary
|
|
300
|
+
expect(iconFor(0.40)).toBe('🟡'); // boundary
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
// ── integration: realistic scenario ─────────────────────────────────────────
|
|
304
|
+
describe('realistic scenario: keycloak upgrade', () => {
|
|
305
|
+
const ctx = 'upgrading Keycloak from 21 to 24';
|
|
306
|
+
const tokens = tokenize(ctx);
|
|
307
|
+
const lessons = [
|
|
308
|
+
// Both lessons have equal token overlap ('keycloak', 'upgrading', 'from').
|
|
309
|
+
// The only difference is severity: critical vs major.
|
|
310
|
+
// Critical (+0.15 boost) must rank above major (+0.05 boost) when confidence is equal.
|
|
311
|
+
{ topic: 'fix:keycloak-jwks', outcome: 'failure', what_failed: 'keycloak authentication fails after upgrading from version 21', what_worked: 'flush realm cache and restart', confidence: 0.7, severity: 'critical' },
|
|
312
|
+
{ topic: 'fix:keycloak-db-migration', outcome: 'failure', what_failed: 'keycloak database migration fails after upgrading from version 21', what_worked: 'run liquibase migrate manually', confidence: 0.7, severity: 'major' },
|
|
313
|
+
{ topic: 'fix:redis-oom', outcome: 'failure', what_failed: 'redis out of memory', what_worked: 'set maxmemory-policy allkeys-lru', confidence: 0.9, severity: 'critical' },
|
|
314
|
+
{ topic: 'deploy:web', outcome: 'success', what_worked: 'npm run build && docker push' },
|
|
315
|
+
];
|
|
316
|
+
it('returns keycloak-related failures, not unrelated redis/web lessons', () => {
|
|
317
|
+
const results = lessons
|
|
318
|
+
.map(l => scoreLesson(l, tokens))
|
|
319
|
+
.filter((r) => r !== null);
|
|
320
|
+
const topics = results.map(r => r.topic);
|
|
321
|
+
expect(topics).toContain('fix:keycloak-jwks');
|
|
322
|
+
expect(topics).toContain('fix:keycloak-db-migration');
|
|
323
|
+
// redis-oom has no token overlap → should be filtered
|
|
324
|
+
expect(topics).not.toContain('fix:redis-oom');
|
|
325
|
+
// success lesson → always null
|
|
326
|
+
expect(topics).not.toContain('deploy:web');
|
|
327
|
+
});
|
|
328
|
+
it('critical keycloak-jwks ranks above major db-migration when confidence is equal', () => {
|
|
329
|
+
const results = lessons
|
|
330
|
+
.map(l => scoreLesson(l, tokens))
|
|
331
|
+
.filter((r) => r !== null);
|
|
332
|
+
const ranked = rankFailures(results, 5);
|
|
333
|
+
// Both lessons have the same confidence=0.7 and equal token overlap,
|
|
334
|
+
// so the critical severity boost (+0.15) must put jwks above major (+0.05).
|
|
335
|
+
expect(ranked[0].topic).toBe('fix:keycloak-jwks');
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
//# sourceMappingURL=brain-predict-failures.test.js.map
|
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AC,CAAC;YACzC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;YAC9C,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;YACtD,sDAAsD;YACtD,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;YAC9C,+BAA+B;YAC/B,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gFAAgF,EAAE,GAAG,EAAE;YACxF,MAAM,OAAO,GAAG,OAAO;iBACpB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;iBAChC,MAAM,CAAC,CAAC,CAAC,EAAoB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;YAC/C,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACxC,qEAAqE;YACrE,4EAA4E;YAC5E,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createHmac } from 'node:crypto';
|
|
2
2
|
import { ckgSlug, extractProblemConcept, ckgUpsertNode, ckgUpdateEdge } from '../ckg.js';
|
|
3
|
-
import { safeJsonParse } from '../utils.js';
|
|
4
3
|
// Git concurrency semaphore (for brain_from_git parallel workers)
|
|
5
4
|
let _gitSemCount = 0;
|
|
6
5
|
const _GIT_SEM_MAX = 10;
|
|
@@ -360,9 +359,7 @@ export async function handleFedbrainTool(name, args, getConnection, apiFetch) {
|
|
|
360
359
|
const raw = await redis.get(`cachly:lesson:best:${lesson_key}`);
|
|
361
360
|
if (!raw)
|
|
362
361
|
return `❌ Lesson \`${lesson_key}\` not found. Store it first with \`learn_from_attempts\`.`;
|
|
363
|
-
const lesson =
|
|
364
|
-
if (!lesson)
|
|
365
|
-
return `❌ Lesson \`${lesson_key}\` data is corrupted. Re-store with \`learn_from_attempts\`.`;
|
|
362
|
+
const lesson = JSON.parse(raw);
|
|
366
363
|
const domainTokens = [lesson.topic.split(':')[0], ...(lesson.tags ?? [])].filter(Boolean);
|
|
367
364
|
const domainFingerprint = [...new Set(domainTokens)].sort().join(',');
|
|
368
365
|
// HMAC certificate ID (non-reversible, privacy-safe)
|
|
@@ -698,9 +695,7 @@ export async function handleFedbrainTool(name, args, getConnection, apiFetch) {
|
|
|
698
695
|
'', `💡 Tip: run \`memory_crystalize\` monthly for best results.`,
|
|
699
696
|
].join('\n');
|
|
700
697
|
}
|
|
701
|
-
const crystal =
|
|
702
|
-
if (!crystal)
|
|
703
|
-
return `❌ Memory Crystal data is corrupted. Re-create with \`memory_crystalize()\`.`;
|
|
698
|
+
const crystal = JSON.parse(raw);
|
|
704
699
|
const age = Math.floor((Date.now() - new Date(crystal.ts).getTime()) / 86400000);
|
|
705
700
|
const freshEmoji = age <= 7 ? '🟢' : age <= 30 ? '🟡' : '🔴';
|
|
706
701
|
const lines = [
|
|
@@ -732,56 +727,50 @@ export async function handleFedbrainTool(name, args, getConnection, apiFetch) {
|
|
|
732
727
|
// 1. Memory Crystal
|
|
733
728
|
const crystalRaw = await redis.get('cachly:crystal:latest');
|
|
734
729
|
if (crystalRaw) {
|
|
735
|
-
const crystal =
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
lines.push('');
|
|
745
|
-
}
|
|
730
|
+
const crystal = JSON.parse(crystalRaw);
|
|
731
|
+
lines.push(`### 💎 Memory Crystal: ${crystal.label}`);
|
|
732
|
+
lines.push(`Compressed from ${crystal.session_count} sessions, ${crystal.lesson_count} lessons.`);
|
|
733
|
+
const topN = focus
|
|
734
|
+
? crystal.top_patterns.filter(p => p.category.toLowerCase().includes(focus.toLowerCase()) || p.insight.toLowerCase().includes(focus.toLowerCase())).slice(0, 4)
|
|
735
|
+
: crystal.top_patterns.slice(0, 4);
|
|
736
|
+
for (const p of topN)
|
|
737
|
+
lines.push(` • **${p.category}**: ${p.insight.slice(0, 100)}`);
|
|
738
|
+
lines.push('');
|
|
746
739
|
}
|
|
747
740
|
// 2. Last session summary
|
|
748
741
|
const lastSession = await redis.get('cachly:session:last');
|
|
749
742
|
if (lastSession) {
|
|
750
|
-
const sess =
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
lines.push('');
|
|
758
|
-
}
|
|
743
|
+
const sess = JSON.parse(lastSession);
|
|
744
|
+
lines.push(`### 🕐 Last Session`);
|
|
745
|
+
if (sess.focus)
|
|
746
|
+
lines.push(`Focus: _${sess.focus}_`);
|
|
747
|
+
if (sess.summary)
|
|
748
|
+
lines.push(`Summary: ${sess.summary.slice(0, 300)}`);
|
|
749
|
+
lines.push('');
|
|
759
750
|
}
|
|
760
751
|
// 3. Session handoff
|
|
761
752
|
const handoff = await redis.get('cachly:session:handoff');
|
|
762
753
|
if (handoff) {
|
|
763
|
-
const h =
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
lines.push(` • ${t}`);
|
|
772
|
-
}
|
|
773
|
-
if (h.instructions)
|
|
774
|
-
lines.push(`⚠️ Instructions: ${h.instructions.slice(0, 200)}`);
|
|
775
|
-
if (h.blocked_on)
|
|
776
|
-
lines.push(`🚧 Blocked on: ${h.blocked_on}`);
|
|
777
|
-
lines.push('');
|
|
754
|
+
const h = JSON.parse(handoff);
|
|
755
|
+
lines.push(`### 📋 Handoff (from last window)`);
|
|
756
|
+
if (h.context_summary)
|
|
757
|
+
lines.push(`Context: ${h.context_summary.slice(0, 200)}`);
|
|
758
|
+
if (h.remaining_tasks?.length) {
|
|
759
|
+
lines.push(`Remaining tasks:`);
|
|
760
|
+
for (const t of h.remaining_tasks.slice(0, 5))
|
|
761
|
+
lines.push(` • ${t}`);
|
|
778
762
|
}
|
|
763
|
+
if (h.instructions)
|
|
764
|
+
lines.push(`⚠️ Instructions: ${h.instructions.slice(0, 200)}`);
|
|
765
|
+
if (h.blocked_on)
|
|
766
|
+
lines.push(`🚧 Blocked on: ${h.blocked_on}`);
|
|
767
|
+
lines.push('');
|
|
779
768
|
}
|
|
780
769
|
// 4. WIP registry
|
|
781
770
|
const wipRaw = await redis.get('cachly:ctx:wip-registry');
|
|
782
771
|
if (wipRaw) {
|
|
783
|
-
const wip =
|
|
784
|
-
if (wip
|
|
772
|
+
const wip = JSON.parse(wipRaw);
|
|
773
|
+
if (wip.content) {
|
|
785
774
|
lines.push(`### 🔧 WIP Registry`);
|
|
786
775
|
lines.push(wip.content.slice(0, 400));
|
|
787
776
|
lines.push('');
|
|
@@ -972,17 +961,13 @@ export async function handleFedbrainTool(name, args, getConnection, apiFetch) {
|
|
|
972
961
|
const nodeRaw = await redis.get(nk);
|
|
973
962
|
if (!nodeRaw)
|
|
974
963
|
continue;
|
|
975
|
-
const node =
|
|
976
|
-
if (!node)
|
|
977
|
-
continue;
|
|
964
|
+
const node = JSON.parse(nodeRaw);
|
|
978
965
|
const edgeKeys = await redis.smembers(`cachly:ckg:idx:from:${node.id}`);
|
|
979
966
|
for (const ek of edgeKeys.slice(0, 20)) {
|
|
980
967
|
const edgeRaw = await redis.get(ek);
|
|
981
968
|
if (!edgeRaw)
|
|
982
969
|
continue;
|
|
983
|
-
const edge =
|
|
984
|
-
if (!edge)
|
|
985
|
-
continue;
|
|
970
|
+
const edge = JSON.parse(edgeRaw);
|
|
986
971
|
if (edge.edgeType !== 'causes' && edge.edgeType !== 'degrades_under')
|
|
987
972
|
continue;
|
|
988
973
|
// Look up fix for this failure from CKG 'fixes' edges
|
|
@@ -992,14 +977,12 @@ export async function handleFedbrainTool(name, args, getConnection, apiFetch) {
|
|
|
992
977
|
const feRaw = await redis.get(fek);
|
|
993
978
|
if (!feRaw)
|
|
994
979
|
continue;
|
|
995
|
-
const fe =
|
|
996
|
-
if (!fe)
|
|
997
|
-
continue;
|
|
980
|
+
const fe = JSON.parse(feRaw);
|
|
998
981
|
if (fe.edgeType === 'fixes') {
|
|
999
982
|
const lessonRaw = await redis.get(`cachly:lesson:best:${fe.from}`);
|
|
1000
983
|
if (lessonRaw) {
|
|
1001
|
-
const lesson =
|
|
1002
|
-
fix = lesson
|
|
984
|
+
const lesson = JSON.parse(lessonRaw);
|
|
985
|
+
fix = lesson.what_worked?.slice(0, 120);
|
|
1003
986
|
break;
|
|
1004
987
|
}
|
|
1005
988
|
}
|