agentic-qe 3.8.11 → 3.8.13
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/.claude/skills/qe-code-intelligence/SKILL.md +29 -20
- package/.claude/skills/qe-code-intelligence/evals/qe-code-intelligence.yaml +3 -3
- package/.claude/skills/qe-quality-assessment/SKILL.md +1 -1
- package/.claude/skills/qe-test-generation/SKILL.md +1 -1
- package/.claude/skills/skills-manifest.json +1 -1
- package/CHANGELOG.md +45 -0
- package/README.md +9 -0
- package/assets/skills/qe-code-intelligence/SKILL.md +29 -20
- package/assets/skills/qe-code-intelligence/evals/qe-code-intelligence.yaml +3 -3
- package/assets/skills/qe-quality-assessment/SKILL.md +1 -1
- package/assets/skills/qe-test-generation/SKILL.md +1 -1
- package/dist/cli/bundle.js +1162 -1046
- package/dist/cli/commands/code.js +149 -11
- package/dist/cli/commands/init.js +3 -2
- package/dist/cli/commands/ruvector-commands.js +17 -0
- package/dist/cli/handlers/init-handler.d.ts +1 -0
- package/dist/cli/handlers/init-handler.js +15 -10
- package/dist/cli/utils/file-discovery.d.ts +1 -0
- package/dist/cli/utils/file-discovery.js +1 -1
- package/dist/domains/code-intelligence/coordinator-gnn.d.ts +21 -0
- package/dist/domains/code-intelligence/coordinator-gnn.js +102 -0
- package/dist/domains/contract-testing/coordinator.js +13 -0
- package/dist/domains/coverage-analysis/coordinator.js +5 -0
- package/dist/domains/defect-intelligence/coordinator.d.ts +1 -0
- package/dist/domains/defect-intelligence/coordinator.js +43 -0
- package/dist/domains/quality-assessment/coordinator.js +26 -0
- package/dist/domains/test-generation/coordinator.js +14 -0
- package/dist/init/orchestrator.js +1 -0
- package/dist/init/phases/08-mcp.js +4 -4
- package/dist/init/phases/phase-interface.d.ts +3 -1
- package/dist/integrations/agentic-flow/reasoning-bank/experience-replay.d.ts +11 -0
- package/dist/integrations/agentic-flow/reasoning-bank/experience-replay.js +44 -1
- package/dist/integrations/rl-suite/algorithms/eprop.d.ts +79 -0
- package/dist/integrations/rl-suite/algorithms/eprop.js +284 -0
- package/dist/integrations/rl-suite/algorithms/index.d.ts +2 -1
- package/dist/integrations/rl-suite/algorithms/index.js +2 -1
- package/dist/integrations/rl-suite/index.d.ts +2 -2
- package/dist/integrations/rl-suite/index.js +2 -2
- package/dist/integrations/rl-suite/interfaces.d.ts +3 -3
- package/dist/integrations/rl-suite/interfaces.js +1 -1
- package/dist/integrations/rl-suite/orchestrator.d.ts +2 -2
- package/dist/integrations/rl-suite/orchestrator.js +3 -2
- package/dist/integrations/rl-suite/reward-signals.d.ts +1 -1
- package/dist/integrations/rl-suite/reward-signals.js +1 -1
- package/dist/integrations/ruvector/coherence-gate-cohomology.d.ts +41 -0
- package/dist/integrations/ruvector/coherence-gate-cohomology.js +47 -0
- package/dist/integrations/ruvector/coherence-gate-core.d.ts +200 -0
- package/dist/integrations/ruvector/coherence-gate-core.js +294 -0
- package/dist/integrations/ruvector/coherence-gate-energy.d.ts +136 -0
- package/dist/integrations/ruvector/coherence-gate-energy.js +373 -0
- package/dist/integrations/ruvector/coherence-gate-vector.d.ts +38 -0
- package/dist/integrations/ruvector/coherence-gate-vector.js +76 -0
- package/dist/integrations/ruvector/coherence-gate.d.ts +10 -311
- package/dist/integrations/ruvector/coherence-gate.js +10 -652
- package/dist/integrations/ruvector/cold-tier-trainer.d.ts +103 -0
- package/dist/integrations/ruvector/cold-tier-trainer.js +377 -0
- package/dist/integrations/ruvector/cusum-detector.d.ts +70 -0
- package/dist/integrations/ruvector/cusum-detector.js +142 -0
- package/dist/integrations/ruvector/delta-tracker.d.ts +122 -0
- package/dist/integrations/ruvector/delta-tracker.js +311 -0
- package/dist/integrations/ruvector/domain-transfer.d.ts +79 -1
- package/dist/integrations/ruvector/domain-transfer.js +158 -2
- package/dist/integrations/ruvector/eprop-learner.d.ts +135 -0
- package/dist/integrations/ruvector/eprop-learner.js +351 -0
- package/dist/integrations/ruvector/feature-flags.d.ts +177 -0
- package/dist/integrations/ruvector/feature-flags.js +145 -0
- package/dist/integrations/ruvector/graphmae-encoder.d.ts +88 -0
- package/dist/integrations/ruvector/graphmae-encoder.js +360 -0
- package/dist/integrations/ruvector/hdc-fingerprint.d.ts +127 -0
- package/dist/integrations/ruvector/hdc-fingerprint.js +222 -0
- package/dist/integrations/ruvector/hopfield-memory.d.ts +97 -0
- package/dist/integrations/ruvector/hopfield-memory.js +238 -0
- package/dist/integrations/ruvector/index.d.ts +13 -2
- package/dist/integrations/ruvector/index.js +46 -2
- package/dist/integrations/ruvector/mincut-wrapper.d.ts +7 -0
- package/dist/integrations/ruvector/mincut-wrapper.js +54 -2
- package/dist/integrations/ruvector/reservoir-replay.d.ts +172 -0
- package/dist/integrations/ruvector/reservoir-replay.js +335 -0
- package/dist/integrations/ruvector/solver-adapter.d.ts +93 -0
- package/dist/integrations/ruvector/solver-adapter.js +299 -0
- package/dist/integrations/ruvector/sona-persistence.d.ts +33 -0
- package/dist/integrations/ruvector/sona-persistence.js +47 -0
- package/dist/integrations/ruvector/spectral-sparsifier.d.ts +154 -0
- package/dist/integrations/ruvector/spectral-sparsifier.js +389 -0
- package/dist/integrations/ruvector/temporal-causality.d.ts +63 -0
- package/dist/integrations/ruvector/temporal-causality.js +317 -0
- package/dist/learning/pattern-promotion.d.ts +63 -0
- package/dist/learning/pattern-promotion.js +235 -1
- package/dist/learning/pattern-store.d.ts +2 -0
- package/dist/learning/pattern-store.js +187 -1
- package/dist/learning/sqlite-persistence.d.ts +2 -0
- package/dist/learning/sqlite-persistence.js +4 -0
- package/dist/mcp/bundle.js +506 -427
- package/dist/shared/utils/index.d.ts +1 -0
- package/dist/shared/utils/index.js +1 -0
- package/dist/shared/utils/xorshift128.d.ts +24 -0
- package/dist/shared/utils/xorshift128.js +50 -0
- package/package.json +1 -1
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reservoir Replay Buffer with Coherence Gating (R10, Phase 5 Milestone 3)
|
|
3
|
+
*
|
|
4
|
+
* A standalone reservoir sampling buffer that uses coherence-gated admission
|
|
5
|
+
* to prioritize high-quality experiences for replay. Integrates with the
|
|
6
|
+
* CUSUM drift detector (R2) for drift-aware admission control.
|
|
7
|
+
*
|
|
8
|
+
* Algorithm:
|
|
9
|
+
* - Reservoir sampling inspired by Algorithm R (Vitter 1985), with
|
|
10
|
+
* coherence-weighted admission bias — high-coherence entries get a
|
|
11
|
+
* higher effective chance of replacing existing entries. This is NOT
|
|
12
|
+
* pure Algorithm R (which is unbiased); the tier weighting and
|
|
13
|
+
* low-coherence-preferring eviction are intentional design choices.
|
|
14
|
+
* - Coherence tiers (high/medium/low) with weighted sampling
|
|
15
|
+
* - CUSUM-based drift detection tightens admission during quality degradation
|
|
16
|
+
*
|
|
17
|
+
* @module integrations/ruvector/reservoir-replay
|
|
18
|
+
* @see ADR-087-ruvector-advanced-capabilities.md
|
|
19
|
+
*/
|
|
20
|
+
import { CusumDetector } from './cusum-detector.js';
|
|
21
|
+
// ============================================================================
|
|
22
|
+
// Defaults
|
|
23
|
+
// ============================================================================
|
|
24
|
+
const DEFAULT_CONFIG = {
|
|
25
|
+
capacity: 10_000,
|
|
26
|
+
minCoherenceThreshold: 0.3,
|
|
27
|
+
highTierThreshold: 0.8,
|
|
28
|
+
mediumTierThreshold: 0.5,
|
|
29
|
+
highTierWeight: 3.0,
|
|
30
|
+
mediumTierWeight: 1.5,
|
|
31
|
+
lowTierWeight: 1.0,
|
|
32
|
+
};
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// ReservoirReplayBuffer Implementation
|
|
35
|
+
// ============================================================================
|
|
36
|
+
/**
|
|
37
|
+
* A fixed-capacity replay buffer with coherence-gated admission and
|
|
38
|
+
* tier-weighted sampling. Uses Algorithm R for reservoir sampling
|
|
39
|
+
* and integrates CUSUM drift detection for adaptive admission control.
|
|
40
|
+
*
|
|
41
|
+
* Usage:
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const buffer = new ReservoirReplayBuffer({ capacity: 1000 });
|
|
44
|
+
* buffer.admit('exp-1', myData, 0.85); // high coherence
|
|
45
|
+
* buffer.admit('exp-2', myData, 0.10); // rejected (below threshold)
|
|
46
|
+
* const batch = buffer.sample(32); // weighted toward high-coherence
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export class ReservoirReplayBuffer {
|
|
50
|
+
config;
|
|
51
|
+
cusumDetector;
|
|
52
|
+
buffer;
|
|
53
|
+
/** Total number of items that have been offered for admission (including rejected) */
|
|
54
|
+
totalSeen = 0;
|
|
55
|
+
/** Total items actually admitted into the buffer */
|
|
56
|
+
totalAdmitted = 0;
|
|
57
|
+
/** Total items rejected at the coherence gate */
|
|
58
|
+
totalRejected = 0;
|
|
59
|
+
/** Total items evicted by reservoir replacement */
|
|
60
|
+
totalEvicted = 0;
|
|
61
|
+
/** Total individual samples drawn */
|
|
62
|
+
totalSampled = 0;
|
|
63
|
+
constructor(config) {
|
|
64
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
65
|
+
// For gating purposes, we do NOT reset on alarm so that drift
|
|
66
|
+
// stays active until the detector is explicitly reset. This keeps
|
|
67
|
+
// the admission threshold tightened as long as drift persists.
|
|
68
|
+
this.cusumDetector = new CusumDetector({
|
|
69
|
+
threshold: this.config.cusumConfig?.threshold ?? 5.0,
|
|
70
|
+
slack: this.config.cusumConfig?.slack ?? 0.5,
|
|
71
|
+
resetOnAlarm: false,
|
|
72
|
+
warmupSamples: 20,
|
|
73
|
+
});
|
|
74
|
+
this.buffer = [];
|
|
75
|
+
}
|
|
76
|
+
// --------------------------------------------------------------------------
|
|
77
|
+
// Public API
|
|
78
|
+
// --------------------------------------------------------------------------
|
|
79
|
+
/**
|
|
80
|
+
* Attempt to admit an experience to the reservoir.
|
|
81
|
+
*
|
|
82
|
+
* Uses coherence-gated admission:
|
|
83
|
+
* 1. Reject if coherence < minCoherenceThreshold (adjusted by CUSUM drift)
|
|
84
|
+
* 2. If buffer has capacity, admit directly
|
|
85
|
+
* 3. If buffer is full, use Algorithm R reservoir sampling to decide eviction
|
|
86
|
+
* 4. High-coherence entries get a boost to their effective admission probability
|
|
87
|
+
*
|
|
88
|
+
* @param id - Unique entry identifier
|
|
89
|
+
* @param data - The data payload to store
|
|
90
|
+
* @param coherenceScore - Coherence score in [0, 1]
|
|
91
|
+
* @returns true if admitted, false if rejected
|
|
92
|
+
*/
|
|
93
|
+
admit(id, data, coherenceScore) {
|
|
94
|
+
this.totalSeen++;
|
|
95
|
+
// Determine effective threshold: tighten during detected drift
|
|
96
|
+
const effectiveThreshold = this.getEffectiveThreshold();
|
|
97
|
+
// Gate 1: reject below coherence threshold
|
|
98
|
+
if (coherenceScore < effectiveThreshold) {
|
|
99
|
+
this.totalRejected++;
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
const tier = this.classifyTier(coherenceScore);
|
|
103
|
+
const entry = {
|
|
104
|
+
id,
|
|
105
|
+
data,
|
|
106
|
+
coherenceScore,
|
|
107
|
+
tier,
|
|
108
|
+
admittedAt: Date.now(),
|
|
109
|
+
replayCount: 0,
|
|
110
|
+
};
|
|
111
|
+
// Phase: buffer has capacity - admit directly
|
|
112
|
+
if (this.buffer.length < this.config.capacity) {
|
|
113
|
+
this.buffer.push(entry);
|
|
114
|
+
this.totalAdmitted++;
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
// Phase: buffer is full - Algorithm R reservoir sampling
|
|
118
|
+
// Generate j in [0, totalAdmitted) - if j < capacity, replace buffer[j]
|
|
119
|
+
const j = Math.floor(Math.random() * this.totalAdmitted);
|
|
120
|
+
// Apply coherence-weighted boost: high-coherence entries get more chances
|
|
121
|
+
const tierWeight = this.getTierWeight(tier);
|
|
122
|
+
const effectiveJ = Math.floor(j / tierWeight);
|
|
123
|
+
if (effectiveJ < this.config.capacity) {
|
|
124
|
+
// When evicting, prefer evicting low-coherence entries
|
|
125
|
+
const evictionIndex = this.selectEvictionTarget(effectiveJ);
|
|
126
|
+
this.buffer[evictionIndex] = entry;
|
|
127
|
+
this.totalEvicted++;
|
|
128
|
+
this.totalAdmitted++;
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
// Not admitted by reservoir sampling
|
|
132
|
+
this.totalRejected++;
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Sample a batch from the reservoir with coherence-weighted probability.
|
|
137
|
+
* High-coherence entries are more likely to be sampled according to their
|
|
138
|
+
* tier weights.
|
|
139
|
+
*
|
|
140
|
+
* @param batchSize - Number of entries to sample
|
|
141
|
+
* @param minCoherence - Optional minimum coherence filter
|
|
142
|
+
* @returns Sampled entries (may be fewer than batchSize if buffer is small)
|
|
143
|
+
*/
|
|
144
|
+
sample(batchSize, minCoherence) {
|
|
145
|
+
if (this.buffer.length === 0) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
// Filter by minCoherence if specified
|
|
149
|
+
const candidates = minCoherence !== undefined
|
|
150
|
+
? this.buffer.filter(e => e.coherenceScore >= minCoherence)
|
|
151
|
+
: this.buffer;
|
|
152
|
+
if (candidates.length === 0) {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
// If requesting more than available, return all (shuffled)
|
|
156
|
+
if (batchSize >= candidates.length) {
|
|
157
|
+
const result = [...candidates];
|
|
158
|
+
for (const entry of result) {
|
|
159
|
+
entry.replayCount++;
|
|
160
|
+
}
|
|
161
|
+
this.totalSampled += result.length;
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
// Weighted sampling without replacement
|
|
165
|
+
const weights = candidates.map(e => this.getTierWeight(e.tier));
|
|
166
|
+
const sampled = [];
|
|
167
|
+
const usedIndices = new Set();
|
|
168
|
+
while (sampled.length < batchSize && usedIndices.size < candidates.length) {
|
|
169
|
+
// Compute remaining weight (excluding already-selected items)
|
|
170
|
+
let remainingWeight = 0;
|
|
171
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
172
|
+
if (!usedIndices.has(i))
|
|
173
|
+
remainingWeight += weights[i];
|
|
174
|
+
}
|
|
175
|
+
if (remainingWeight <= 0)
|
|
176
|
+
break;
|
|
177
|
+
// Weighted random selection over remaining items
|
|
178
|
+
let r = Math.random() * remainingWeight;
|
|
179
|
+
let selectedIdx = -1;
|
|
180
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
181
|
+
if (usedIndices.has(i))
|
|
182
|
+
continue;
|
|
183
|
+
r -= weights[i];
|
|
184
|
+
if (r <= 0) {
|
|
185
|
+
selectedIdx = i;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Fallback: pick first unused (rounding edge case)
|
|
190
|
+
if (selectedIdx === -1) {
|
|
191
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
192
|
+
if (!usedIndices.has(i)) {
|
|
193
|
+
selectedIdx = i;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (selectedIdx >= 0) {
|
|
199
|
+
usedIndices.add(selectedIdx);
|
|
200
|
+
candidates[selectedIdx].replayCount++;
|
|
201
|
+
sampled.push(candidates[selectedIdx]);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
this.totalSampled += sampled.length;
|
|
205
|
+
return sampled;
|
|
206
|
+
}
|
|
207
|
+
/** Get current buffer size */
|
|
208
|
+
size() {
|
|
209
|
+
return this.buffer.length;
|
|
210
|
+
}
|
|
211
|
+
/** Get buffer statistics */
|
|
212
|
+
getStats() {
|
|
213
|
+
const tierCounts = {
|
|
214
|
+
high: 0,
|
|
215
|
+
medium: 0,
|
|
216
|
+
low: 0,
|
|
217
|
+
};
|
|
218
|
+
for (const entry of this.buffer) {
|
|
219
|
+
tierCounts[entry.tier]++;
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
size: this.buffer.length,
|
|
223
|
+
capacity: this.config.capacity,
|
|
224
|
+
totalAdmitted: this.totalAdmitted,
|
|
225
|
+
totalRejected: this.totalRejected,
|
|
226
|
+
totalEvicted: this.totalEvicted,
|
|
227
|
+
tierCounts,
|
|
228
|
+
totalSampled: this.totalSampled,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/** Get all entries in a specific coherence tier */
|
|
232
|
+
getByTier(tier) {
|
|
233
|
+
return this.buffer.filter(e => e.tier === tier);
|
|
234
|
+
}
|
|
235
|
+
/** Clear the buffer and reset all statistics */
|
|
236
|
+
clear() {
|
|
237
|
+
this.buffer.length = 0;
|
|
238
|
+
this.totalSeen = 0;
|
|
239
|
+
this.totalAdmitted = 0;
|
|
240
|
+
this.totalRejected = 0;
|
|
241
|
+
this.totalEvicted = 0;
|
|
242
|
+
this.totalSampled = 0;
|
|
243
|
+
this.cusumDetector.reset();
|
|
244
|
+
}
|
|
245
|
+
/** Get the CUSUM detector state for a gate type */
|
|
246
|
+
getCusumState(gateType) {
|
|
247
|
+
return this.cusumDetector.getState(gateType);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Feed a coherence observation to the CUSUM detector.
|
|
251
|
+
* When drift is detected, the admission threshold is temporarily tightened.
|
|
252
|
+
*/
|
|
253
|
+
observeCoherence(gateType, value) {
|
|
254
|
+
return this.cusumDetector.update(gateType, value);
|
|
255
|
+
}
|
|
256
|
+
// --------------------------------------------------------------------------
|
|
257
|
+
// Private Helpers
|
|
258
|
+
// --------------------------------------------------------------------------
|
|
259
|
+
/**
|
|
260
|
+
* Classify a coherence score into a tier.
|
|
261
|
+
*/
|
|
262
|
+
classifyTier(coherenceScore) {
|
|
263
|
+
if (coherenceScore >= this.config.highTierThreshold) {
|
|
264
|
+
return 'high';
|
|
265
|
+
}
|
|
266
|
+
if (coherenceScore >= this.config.mediumTierThreshold) {
|
|
267
|
+
return 'medium';
|
|
268
|
+
}
|
|
269
|
+
return 'low';
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Get the sampling/admission weight for a tier.
|
|
273
|
+
*/
|
|
274
|
+
getTierWeight(tier) {
|
|
275
|
+
switch (tier) {
|
|
276
|
+
case 'high':
|
|
277
|
+
return this.config.highTierWeight;
|
|
278
|
+
case 'medium':
|
|
279
|
+
return this.config.mediumTierWeight;
|
|
280
|
+
case 'low':
|
|
281
|
+
return this.config.lowTierWeight;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get the effective admission threshold, tightened during drift.
|
|
286
|
+
*
|
|
287
|
+
* When CUSUM detects drift on any gate, we raise the minimum coherence
|
|
288
|
+
* threshold by 50% (capped at 0.9) to reject more marginal entries.
|
|
289
|
+
*/
|
|
290
|
+
getEffectiveThreshold() {
|
|
291
|
+
const gateTypes = ['retrieve', 'write', 'learn', 'act'];
|
|
292
|
+
let driftActive = false;
|
|
293
|
+
for (const gate of gateTypes) {
|
|
294
|
+
const state = this.cusumDetector.getState(gate);
|
|
295
|
+
if (state.driftDetected) {
|
|
296
|
+
driftActive = true;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (driftActive) {
|
|
301
|
+
return Math.min(this.config.minCoherenceThreshold * 1.5, 0.9);
|
|
302
|
+
}
|
|
303
|
+
return this.config.minCoherenceThreshold;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Select an eviction target, preferring low-coherence entries.
|
|
307
|
+
*
|
|
308
|
+
* Given a candidate index from reservoir sampling, look for a nearby
|
|
309
|
+
* low-coherence entry to evict instead (within a small window).
|
|
310
|
+
*/
|
|
311
|
+
selectEvictionTarget(candidateIndex) {
|
|
312
|
+
const windowSize = Math.min(10, this.buffer.length);
|
|
313
|
+
const start = Math.max(0, candidateIndex - Math.floor(windowSize / 2));
|
|
314
|
+
const end = Math.min(this.buffer.length, start + windowSize);
|
|
315
|
+
let worstIndex = candidateIndex;
|
|
316
|
+
let worstScore = this.buffer[candidateIndex].coherenceScore;
|
|
317
|
+
for (let i = start; i < end; i++) {
|
|
318
|
+
if (this.buffer[i].coherenceScore < worstScore) {
|
|
319
|
+
worstScore = this.buffer[i].coherenceScore;
|
|
320
|
+
worstIndex = i;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return worstIndex;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// ============================================================================
|
|
327
|
+
// Factory
|
|
328
|
+
// ============================================================================
|
|
329
|
+
/**
|
|
330
|
+
* Create a ReservoirReplayBuffer instance with optional configuration.
|
|
331
|
+
*/
|
|
332
|
+
export function createReservoirReplayBuffer(config) {
|
|
333
|
+
return new ReservoirReplayBuffer(config);
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=reservoir-replay.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentic QE v3 - PageRank Pattern Importance Solver (ADR-087, Milestone 3)
|
|
3
|
+
*
|
|
4
|
+
* Provides graph-based importance scoring for QE patterns using PageRank.
|
|
5
|
+
*
|
|
6
|
+
* Two execution paths:
|
|
7
|
+
* - **Native** (@ruvector/solver-node): O(log n) sublinear via Neumann series.
|
|
8
|
+
* Requires the optional NAPI dependency to be installed.
|
|
9
|
+
* - **TypeScript fallback**: Standard power iteration, O(n * m * iterations).
|
|
10
|
+
* Always available, correct results, linear-time.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createPageRankSolver } from './solver-adapter';
|
|
15
|
+
*
|
|
16
|
+
* const solver = createPageRankSolver({ dampingFactor: 0.85 });
|
|
17
|
+
* const scores = solver.computeImportance(graph);
|
|
18
|
+
* const ranked = solver.rankPatterns(graph);
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @module integrations/ruvector/solver-adapter
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* A directed graph of pattern relationships for importance scoring.
|
|
25
|
+
*
|
|
26
|
+
* Nodes represent pattern IDs; edges encode directed relationships
|
|
27
|
+
* (e.g., "pattern A depends on pattern B") with numeric weights.
|
|
28
|
+
*/
|
|
29
|
+
export interface PatternGraph {
|
|
30
|
+
/** Node IDs (pattern IDs) */
|
|
31
|
+
nodes: string[];
|
|
32
|
+
/** Directed edges: [fromIndex, toIndex, weight] */
|
|
33
|
+
edges: Array<[number, number, number]>;
|
|
34
|
+
}
|
|
35
|
+
/** Result of importance scoring for a single pattern */
|
|
36
|
+
export interface ImportanceScore {
|
|
37
|
+
patternId: string;
|
|
38
|
+
score: number;
|
|
39
|
+
rank: number;
|
|
40
|
+
}
|
|
41
|
+
/** Configuration for the solver */
|
|
42
|
+
export interface SolverConfig {
|
|
43
|
+
/** Damping factor for PageRank (default: 0.85) */
|
|
44
|
+
dampingFactor: number;
|
|
45
|
+
/** Convergence tolerance (default: 1e-6) */
|
|
46
|
+
tolerance: number;
|
|
47
|
+
/** Maximum iterations for power iteration fallback (default: 100) */
|
|
48
|
+
maxIterations: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Computes importance scores for pattern graphs using PageRank.
|
|
52
|
+
*
|
|
53
|
+
* Prefers the native @ruvector/solver-node NAPI bindings when available
|
|
54
|
+
* (O(log n) via Neumann series). Falls back to a TypeScript power-iteration
|
|
55
|
+
* implementation (O(n * m * iterations)) when the native module is absent.
|
|
56
|
+
*/
|
|
57
|
+
export declare class PageRankSolver {
|
|
58
|
+
private readonly config;
|
|
59
|
+
constructor(config?: Partial<SolverConfig>);
|
|
60
|
+
/**
|
|
61
|
+
* Check whether the native @ruvector/solver-node module is available.
|
|
62
|
+
*/
|
|
63
|
+
isNativeAvailable(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Compute importance scores for all nodes in a pattern graph.
|
|
66
|
+
*
|
|
67
|
+
* @param graph - The pattern graph to analyze
|
|
68
|
+
* @returns Map from node ID to its importance score (scores sum to ~1.0)
|
|
69
|
+
*/
|
|
70
|
+
computeImportance(graph: PatternGraph): Map<string, number>;
|
|
71
|
+
/**
|
|
72
|
+
* Rank all patterns in the graph by importance, highest first.
|
|
73
|
+
*
|
|
74
|
+
* @param graph - The pattern graph to analyze
|
|
75
|
+
* @returns Array of ImportanceScore sorted by score descending
|
|
76
|
+
*/
|
|
77
|
+
rankPatterns(graph: PatternGraph): ImportanceScore[];
|
|
78
|
+
/**
|
|
79
|
+
* Delegate PageRank computation to the native @ruvector/solver-node module.
|
|
80
|
+
*
|
|
81
|
+
* The native API is expected to accept the graph in a compatible format
|
|
82
|
+
* and return a Float64Array of scores indexed by node position.
|
|
83
|
+
*/
|
|
84
|
+
private computeNative;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Create a PageRankSolver instance with the given configuration.
|
|
88
|
+
*
|
|
89
|
+
* @param config - Partial solver configuration (defaults applied)
|
|
90
|
+
* @returns A configured PageRankSolver
|
|
91
|
+
*/
|
|
92
|
+
export declare function createPageRankSolver(config?: Partial<SolverConfig>): PageRankSolver;
|
|
93
|
+
//# sourceMappingURL=solver-adapter.d.ts.map
|