MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / detectFailurePatterns

Function detectFailurePatterns

src/skills/learning/failures.ts:72–88  ·  view source on GitHub ↗
(events: FailureEvent[], opts: DetectOpts = DEFAULT_DETECT)

Source from the content-addressed store, hash-verified

70
71/** Cluster events by signature and return only the patterns that RECUR enough to learn. */
72export function detectFailurePatterns(events: FailureEvent[], opts: DetectOpts = DEFAULT_DETECT): FailurePattern[] {
73 const by = new Map<string, { tool: string; count: number; tasks: Set<string>; sample: string }>();
74 for (const e of events) {
75 let g = by.get(e.signature);
76 if (!g) { g = { tool: e.tool, count: 0, tasks: new Set(), sample: e.sample }; by.set(e.signature, g); }
77 g.count++;
78 g.tasks.add(e.task);
79 }
80 const out: FailurePattern[] = [];
81 for (const [signature, g] of by) {
82 if (g.count >= opts.minOccurrences && g.tasks.size >= opts.minDistinctTasks) {
83 out.push({ signature, tool: g.tool, count: g.count, distinctTasks: g.tasks.size, sample: g.sample });
84 }
85 }
86 // Most-repeated first.
87 return out.sort((a, b) => b.count - a.count);
88}
89
90/** Templated, DETERMINISTIC caution for a recurring failure. Never LLM-phrased. */
91export function buildLesson(p: FailurePattern): string {

Callers 3

buildSkillCommandFunction · 0.85
loadLessonsBlockFunction · 0.85

Calls 4

addMethod · 0.80
getMethod · 0.45
setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected