agentic-qe 3.8.11 → 3.8.12

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.
Files changed (80) hide show
  1. package/.claude/skills/skills-manifest.json +1 -1
  2. package/CHANGELOG.md +24 -0
  3. package/dist/cli/bundle.js +1141 -1045
  4. package/dist/cli/commands/ruvector-commands.js +17 -0
  5. package/dist/domains/code-intelligence/coordinator-gnn.d.ts +21 -0
  6. package/dist/domains/code-intelligence/coordinator-gnn.js +102 -0
  7. package/dist/domains/contract-testing/coordinator.js +13 -0
  8. package/dist/domains/coverage-analysis/coordinator.js +5 -0
  9. package/dist/domains/defect-intelligence/coordinator.d.ts +1 -0
  10. package/dist/domains/defect-intelligence/coordinator.js +43 -0
  11. package/dist/domains/quality-assessment/coordinator.js +26 -0
  12. package/dist/domains/test-generation/coordinator.js +14 -0
  13. package/dist/integrations/agentic-flow/reasoning-bank/experience-replay.d.ts +11 -0
  14. package/dist/integrations/agentic-flow/reasoning-bank/experience-replay.js +44 -1
  15. package/dist/integrations/rl-suite/algorithms/eprop.d.ts +79 -0
  16. package/dist/integrations/rl-suite/algorithms/eprop.js +284 -0
  17. package/dist/integrations/rl-suite/algorithms/index.d.ts +2 -1
  18. package/dist/integrations/rl-suite/algorithms/index.js +2 -1
  19. package/dist/integrations/rl-suite/index.d.ts +2 -2
  20. package/dist/integrations/rl-suite/index.js +2 -2
  21. package/dist/integrations/rl-suite/interfaces.d.ts +3 -3
  22. package/dist/integrations/rl-suite/interfaces.js +1 -1
  23. package/dist/integrations/rl-suite/orchestrator.d.ts +2 -2
  24. package/dist/integrations/rl-suite/orchestrator.js +3 -2
  25. package/dist/integrations/rl-suite/reward-signals.d.ts +1 -1
  26. package/dist/integrations/rl-suite/reward-signals.js +1 -1
  27. package/dist/integrations/ruvector/coherence-gate-cohomology.d.ts +41 -0
  28. package/dist/integrations/ruvector/coherence-gate-cohomology.js +47 -0
  29. package/dist/integrations/ruvector/coherence-gate-core.d.ts +200 -0
  30. package/dist/integrations/ruvector/coherence-gate-core.js +294 -0
  31. package/dist/integrations/ruvector/coherence-gate-energy.d.ts +136 -0
  32. package/dist/integrations/ruvector/coherence-gate-energy.js +373 -0
  33. package/dist/integrations/ruvector/coherence-gate-vector.d.ts +38 -0
  34. package/dist/integrations/ruvector/coherence-gate-vector.js +76 -0
  35. package/dist/integrations/ruvector/coherence-gate.d.ts +10 -311
  36. package/dist/integrations/ruvector/coherence-gate.js +10 -652
  37. package/dist/integrations/ruvector/cold-tier-trainer.d.ts +103 -0
  38. package/dist/integrations/ruvector/cold-tier-trainer.js +377 -0
  39. package/dist/integrations/ruvector/cusum-detector.d.ts +70 -0
  40. package/dist/integrations/ruvector/cusum-detector.js +142 -0
  41. package/dist/integrations/ruvector/delta-tracker.d.ts +122 -0
  42. package/dist/integrations/ruvector/delta-tracker.js +311 -0
  43. package/dist/integrations/ruvector/domain-transfer.d.ts +79 -1
  44. package/dist/integrations/ruvector/domain-transfer.js +158 -2
  45. package/dist/integrations/ruvector/eprop-learner.d.ts +135 -0
  46. package/dist/integrations/ruvector/eprop-learner.js +351 -0
  47. package/dist/integrations/ruvector/feature-flags.d.ts +177 -0
  48. package/dist/integrations/ruvector/feature-flags.js +145 -0
  49. package/dist/integrations/ruvector/graphmae-encoder.d.ts +88 -0
  50. package/dist/integrations/ruvector/graphmae-encoder.js +360 -0
  51. package/dist/integrations/ruvector/hdc-fingerprint.d.ts +127 -0
  52. package/dist/integrations/ruvector/hdc-fingerprint.js +222 -0
  53. package/dist/integrations/ruvector/hopfield-memory.d.ts +97 -0
  54. package/dist/integrations/ruvector/hopfield-memory.js +238 -0
  55. package/dist/integrations/ruvector/index.d.ts +13 -2
  56. package/dist/integrations/ruvector/index.js +46 -2
  57. package/dist/integrations/ruvector/mincut-wrapper.d.ts +7 -0
  58. package/dist/integrations/ruvector/mincut-wrapper.js +54 -2
  59. package/dist/integrations/ruvector/reservoir-replay.d.ts +172 -0
  60. package/dist/integrations/ruvector/reservoir-replay.js +335 -0
  61. package/dist/integrations/ruvector/solver-adapter.d.ts +93 -0
  62. package/dist/integrations/ruvector/solver-adapter.js +299 -0
  63. package/dist/integrations/ruvector/sona-persistence.d.ts +33 -0
  64. package/dist/integrations/ruvector/sona-persistence.js +47 -0
  65. package/dist/integrations/ruvector/spectral-sparsifier.d.ts +154 -0
  66. package/dist/integrations/ruvector/spectral-sparsifier.js +389 -0
  67. package/dist/integrations/ruvector/temporal-causality.d.ts +63 -0
  68. package/dist/integrations/ruvector/temporal-causality.js +317 -0
  69. package/dist/learning/pattern-promotion.d.ts +63 -0
  70. package/dist/learning/pattern-promotion.js +235 -1
  71. package/dist/learning/pattern-store.d.ts +2 -0
  72. package/dist/learning/pattern-store.js +187 -1
  73. package/dist/learning/sqlite-persistence.d.ts +2 -0
  74. package/dist/learning/sqlite-persistence.js +4 -0
  75. package/dist/mcp/bundle.js +506 -427
  76. package/dist/shared/utils/index.d.ts +1 -0
  77. package/dist/shared/utils/index.js +1 -0
  78. package/dist/shared/utils/xorshift128.d.ts +24 -0
  79. package/dist/shared/utils/xorshift128.js +50 -0
  80. package/package.json +1 -1
@@ -3,7 +3,8 @@
3
3
  *
4
4
  * Enables knowledge transfer between QE domains using Thompson Sampling
5
5
  * with Beta priors, sqrt-dampening, transfer verification gates, domain
6
- * pair affinity scoring, and coherence gate integration.
6
+ * pair affinity scoring, coherence gate integration, and R7 meta-learning
7
+ * enhancements (DecayingBeta, PlateauDetector, ParetoFront, CuriosityBonus).
7
8
  *
8
9
  * @module integrations/ruvector/domain-transfer
9
10
  */
@@ -12,6 +13,7 @@ import { createTransferCoherenceGate } from './transfer-coherence-stub.js';
12
13
  import { createTransferVerifier, } from './transfer-verification.js';
13
14
  import { getRuVectorFeatureFlags } from './feature-flags.js';
14
15
  import { ThompsonSampler } from './thompson-sampler.js';
16
+ import { CusumDetector } from './cusum-detector.js';
15
17
  export { ThompsonSampler } from './thompson-sampler.js';
16
18
  const logger = LoggerFactory.create('domain-transfer');
17
19
  /** Default domain transfer configuration */
@@ -20,7 +22,115 @@ export const DEFAULT_DOMAIN_TRANSFER_CONFIG = {
20
22
  explorationWarmup: 5,
21
23
  verification: {},
22
24
  maxHistorySize: 1000,
25
+ useMetaLearningEnhancements: true,
23
26
  };
27
+ /** Applies time-based decay to Thompson Sampler exploration variance. */
28
+ export class DecayingBeta {
29
+ decayThreshold;
30
+ constructor(decayThreshold = 100) {
31
+ this.decayThreshold = decayThreshold;
32
+ }
33
+ /** Decay multiplier: 0.5^(successCount/threshold). 1.0 when count=0, 0.5 at threshold. */
34
+ getDecayMultiplier(successCount) {
35
+ if (successCount <= 0)
36
+ return 1.0;
37
+ return Math.pow(0.5, successCount / this.decayThreshold);
38
+ }
39
+ /** Shrink sampled value toward mean by the decay multiplier. */
40
+ applyDecay(sampled, mean, successCount) {
41
+ return mean + (sampled - mean) * this.getDecayMultiplier(successCount);
42
+ }
43
+ }
44
+ /**
45
+ * Detects when transfer success rate has plateaued using CUSUM (R2).
46
+ *
47
+ * Feeds a running success rate into a CusumDetector on the 'learn' gate.
48
+ * Plateau is detected when CUSUM does NOT fire — i.e., the rate is
49
+ * stationary (no drift in either direction) for enough samples.
50
+ * CUSUM firing means the rate is changing, so NOT plateaued.
51
+ */
52
+ export class PlateauDetector {
53
+ cusum;
54
+ outcomes = [];
55
+ windowSize;
56
+ constructor(windowSize = 20) {
57
+ this.windowSize = windowSize;
58
+ // Low threshold + low slack = sensitive to any drift from mean.
59
+ // If CUSUM doesn't fire after windowSize samples, rate is flat.
60
+ // resetOnAlarm: false keeps the drift flag active so isPlateaued()
61
+ // returns false for the rest of the window after a rate change.
62
+ this.cusum = new CusumDetector({
63
+ threshold: 3.0,
64
+ slack: 0.1,
65
+ resetOnAlarm: false,
66
+ warmupSamples: Math.min(10, Math.floor(windowSize / 2)),
67
+ });
68
+ }
69
+ record(success) {
70
+ this.outcomes.push(success);
71
+ if (this.outcomes.length > this.windowSize * 2) {
72
+ this.outcomes.splice(0, this.outcomes.length - this.windowSize * 2);
73
+ }
74
+ // Feed current success rate to CUSUM on the 'learn' gate
75
+ const rate = this.getCurrentRate();
76
+ this.cusum.update('learn', rate);
77
+ }
78
+ /**
79
+ * Plateau = we have enough data AND CUSUM has not detected drift.
80
+ * No drift means the rate is stationary — learning has stalled.
81
+ */
82
+ isPlateaued() {
83
+ if (this.outcomes.length < this.windowSize)
84
+ return false;
85
+ const state = this.cusum.getState('learn');
86
+ return !state.driftDetected;
87
+ }
88
+ getCurrentRate() {
89
+ if (this.outcomes.length === 0)
90
+ return 0;
91
+ const recent = this.outcomes.slice(-this.windowSize);
92
+ return recent.filter(Boolean).length / recent.length;
93
+ }
94
+ getOutcomeCount() { return this.outcomes.length; }
95
+ /** Expose CUSUM state for observability */
96
+ getCusumState() { return this.cusum.getState('learn'); }
97
+ }
98
+ /** Tracks Pareto-optimal transfer candidates across multiple objectives. */
99
+ export class ParetoFront {
100
+ front = [];
101
+ dominates(a, b) {
102
+ const geq = a.successRate >= b.successRate && a.speed >= b.speed && a.confidence >= b.confidence;
103
+ const gt = a.successRate > b.successRate || a.speed > b.speed || a.confidence > b.confidence;
104
+ return geq && gt;
105
+ }
106
+ add(point) {
107
+ for (let i = this.front.length - 1; i >= 0; i--) {
108
+ if (this.dominates(point, this.front[i]))
109
+ this.front.splice(i, 1);
110
+ }
111
+ if (!this.front.some(e => this.dominates(e, point)))
112
+ this.front.push(point);
113
+ }
114
+ getFront() { return [...this.front]; }
115
+ isNonDominated(point) {
116
+ return !this.front.some(e => this.dominates(e, point));
117
+ }
118
+ }
119
+ /** Curiosity bonus for novel/untried source-target domain pairs. */
120
+ export class CuriosityBonus {
121
+ bonusScale;
122
+ triedPairs = new Set();
123
+ constructor(bonusScale = 0.2) {
124
+ this.bonusScale = bonusScale;
125
+ }
126
+ markTried(pairKey) { this.triedPairs.add(pairKey); }
127
+ isTried(pairKey) { return this.triedPairs.has(pairKey); }
128
+ getBonus(pairKey) { return this.triedPairs.has(pairKey) ? 0 : this.bonusScale; }
129
+ apply(sampledProbability, pairKey) {
130
+ return Math.min(1.0, sampledProbability + this.getBonus(pairKey));
131
+ }
132
+ getTriedCount() { return this.triedPairs.size; }
133
+ }
24
134
  // ============================================================================
25
135
  // Domain Transfer Engine
26
136
  // ============================================================================
@@ -38,26 +148,44 @@ export class DomainTransferEngine {
38
148
  performanceProvider = null;
39
149
  transferExecutor = null;
40
150
  nativeModule = null;
151
+ // R7 Meta-Learning components (ADR-087, Milestone 3)
152
+ decayingBeta;
153
+ plateauDetector;
154
+ paretoFront;
155
+ curiosityBonus;
41
156
  constructor(config = {}) {
42
157
  this.config = { ...DEFAULT_DOMAIN_TRANSFER_CONFIG, ...config };
43
158
  this.sampler = new ThompsonSampler();
44
159
  this.verifier = createTransferVerifier(this.config.verification);
45
160
  this.coherenceGate = createTransferCoherenceGate();
161
+ this.decayingBeta = new DecayingBeta();
162
+ this.plateauDetector = new PlateauDetector();
163
+ this.paretoFront = new ParetoFront();
164
+ this.curiosityBonus = new CuriosityBonus();
46
165
  this.tryLoadNativeModule();
47
166
  }
48
167
  /**
49
168
  * Evaluate whether a transfer between two domains should be attempted.
50
169
  * Uses Thompson Sampling to balance exploration and exploitation.
170
+ * When meta-learning is enabled, applies DecayingBeta and CuriosityBonus.
51
171
  */
52
172
  evaluateTransfer(sourceDomain, targetDomain) {
53
173
  if (!this.isEnabled()) {
54
174
  return this.createRejectedCandidate(sourceDomain, targetDomain);
55
175
  }
56
176
  const pairKey = this.makePairKey(sourceDomain, targetDomain);
57
- const sampledProbability = this.sampler.sample(pairKey);
177
+ let sampledProbability = this.sampler.sample(pairKey);
58
178
  const observationCount = this.sampler.getObservationCount(pairKey);
59
179
  const isExploration = observationCount < this.config.explorationWarmup;
60
180
  const affinityScore = this.getAffinityScore(sourceDomain, targetDomain);
181
+ if (this.isMetaLearningEnabled()) {
182
+ // DecayingBeta: reduce exploration variance for well-known pairs
183
+ const mean = this.sampler.getMean(pairKey);
184
+ const successCount = this.sampler.getAlpha(pairKey) - 1; // subtract prior
185
+ sampledProbability = this.decayingBeta.applyDecay(sampledProbability, mean, successCount);
186
+ // CuriosityBonus: boost untried domain pairs
187
+ sampledProbability = this.curiosityBonus.apply(sampledProbability, pairKey);
188
+ }
61
189
  return { sourceDomain, targetDomain, sampledProbability, affinityScore, isExploration, pairKey };
62
190
  }
63
191
  /**
@@ -93,6 +221,18 @@ export class DomainTransferEngine {
93
221
  // Step 6: Update Thompson Sampling and affinity
94
222
  this.sampler.update(candidate.pairKey, success);
95
223
  this.updateAffinityScore(candidate.pairKey, success);
224
+ // Step 6b: Update meta-learning components
225
+ if (this.isMetaLearningEnabled()) {
226
+ this.plateauDetector.record(success);
227
+ this.curiosityBonus.markTried(candidate.pairKey);
228
+ const mean = this.sampler.getMean(candidate.pairKey);
229
+ this.paretoFront.add({
230
+ pairKey: candidate.pairKey,
231
+ successRate: mean,
232
+ speed: 1 / (1 + dampeningFactor), // inverse dampening as speed proxy
233
+ confidence: this.getAffinityScore(candidate.sourceDomain, candidate.targetDomain),
234
+ });
235
+ }
96
236
  this.addToHistory({
97
237
  transferId, sourceDomain: candidate.sourceDomain, targetDomain: candidate.targetDomain,
98
238
  success, sampledProbability: candidate.sampledProbability, dampeningFactor,
@@ -140,10 +280,26 @@ export class DomainTransferEngine {
140
280
  getSampler() { return this.sampler; }
141
281
  /** Get the coherence gate (for testing). */
142
282
  getCoherenceGate() { return this.coherenceGate; }
283
+ /** Get the DecayingBeta component (for testing). */
284
+ getDecayingBeta() { return this.decayingBeta; }
285
+ /** Get the PlateauDetector component (for testing). */
286
+ getPlateauDetector() { return this.plateauDetector; }
287
+ /** Get the ParetoFront component (for testing). */
288
+ getParetoFront() { return this.paretoFront; }
289
+ /** Get the CuriosityBonus component (for testing). */
290
+ getCuriosityBonus() { return this.curiosityBonus; }
291
+ /** Check if learning has plateaued */
292
+ isLearningPlateaued() { return this.plateauDetector.isPlateaued(); }
143
293
  // --- Private Helpers ---
144
294
  isEnabled() {
145
295
  return getRuVectorFeatureFlags().useCrossDomainTransfer === true;
146
296
  }
297
+ isMetaLearningEnabled() {
298
+ // Check both the engine config AND the system-wide feature flag.
299
+ // Either one being false disables meta-learning.
300
+ return this.config.useMetaLearningEnhancements === true
301
+ && getRuVectorFeatureFlags().useMetaLearningEnhancements !== false;
302
+ }
147
303
  makePairKey(source, target) {
148
304
  return `${source}->${target}`;
149
305
  }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Agentic QE v3 - E-prop Online Learning (ADR-087 Milestone 4, R11)
3
+ *
4
+ * Eligibility propagation for online learning with 12 bytes/synapse,
5
+ * no backprop required. Uses eligibility traces and feedback alignment
6
+ * (Lillicrap et al. 2016) to avoid the weight transport problem.
7
+ *
8
+ * Algorithm: dw = eta * eligibility * reward
9
+ * Memory budget: 4B weight + 4B trace + 4B feedback = 12 bytes/synapse
10
+ */
11
+ export interface EpropConfig {
12
+ /** Number of input neurons */
13
+ inputSize: number;
14
+ /** Number of hidden neurons */
15
+ hiddenSize: number;
16
+ /** Number of output neurons */
17
+ outputSize: number;
18
+ /** Learning rate (eta) */
19
+ learningRate: number;
20
+ /** Eligibility trace decay factor (tau_e) */
21
+ eligibilityDecay: number;
22
+ /** Use random feedback weights instead of weight transport */
23
+ feedbackAlignment: boolean;
24
+ }
25
+ export interface EpropStats {
26
+ totalSteps: number;
27
+ totalReward: number;
28
+ avgReward: number;
29
+ synapsCount: number;
30
+ memoryBytes: number;
31
+ }
32
+ /**
33
+ * E-prop neural network with online eligibility-trace learning.
34
+ *
35
+ * Architecture: input -> hidden (tanh) -> output (softmax or linear)
36
+ *
37
+ * Each synapse stores exactly 12 bytes:
38
+ * - weight: Float32 (4 bytes)
39
+ * - trace: Float32 (4 bytes) — eligibility trace
40
+ * - feedback: Float32 (4 bytes) — random feedback weight (fixed)
41
+ */
42
+ export declare class EpropNetwork {
43
+ private readonly config;
44
+ private inputHiddenWeights;
45
+ private hiddenOutputWeights;
46
+ private inputHiddenTraces;
47
+ private hiddenOutputTraces;
48
+ private feedbackWeights;
49
+ private lastInput;
50
+ private lastHidden;
51
+ private lastHiddenRaw;
52
+ private lastOutput;
53
+ private totalSteps;
54
+ private totalReward;
55
+ private rewardHistory;
56
+ constructor(config?: Partial<EpropConfig>);
57
+ /**
58
+ * Compute output from input. Stores activations for eligibility updates.
59
+ *
60
+ * input -> (inputHidden weights) -> tanh -> (hiddenOutput weights) -> output
61
+ *
62
+ * Output activation depends on outputSize:
63
+ * - outputSize === 1: sigmoid (for binary tasks)
64
+ * - outputSize > 1: softmax (for classification)
65
+ */
66
+ forward(input: Float32Array): Float32Array;
67
+ /**
68
+ * Update weights using eligibility traces and reward/error signal.
69
+ *
70
+ * Hidden->output layer:
71
+ * dw[j][k] = learningRate * e_ho[j][k] * reward
72
+ *
73
+ * Input->hidden layer (feedback alignment):
74
+ * The learning signal for hidden neuron j is computed by projecting
75
+ * the scalar reward through feedback weights (or transposed output
76
+ * weights if feedbackAlignment is false).
77
+ * dw[i][j] = learningRate * e_ih[i][j] * L[j]
78
+ * where L[j] = sum_k(B[k][j] * reward) [feedback alignment]
79
+ * L[j] = sum_k(W_ho[j][k] * reward) [weight transport]
80
+ */
81
+ updateOnline(reward: number): void;
82
+ /**
83
+ * Update eligibility traces after a forward pass.
84
+ *
85
+ * Traces capture purely local information (Hebbian-like):
86
+ * Hidden->output: e[j][k] = decay * e[j][k] + h[j]
87
+ * Input->hidden: e[i][j] = decay * e[i][j] + x[i] * dtanh(raw[j])
88
+ *
89
+ * The feedback/learning signal is applied separately in updateOnline().
90
+ */
91
+ private updateTraces;
92
+ /**
93
+ * Reset all eligibility traces to zero (between episodes).
94
+ */
95
+ resetTraces(): void;
96
+ /**
97
+ * Get network statistics including memory budget verification.
98
+ */
99
+ getStats(): EpropStats;
100
+ /**
101
+ * Export current weights (without traces — those are transient).
102
+ */
103
+ exportWeights(): {
104
+ inputHidden: Float32Array;
105
+ hiddenOutput: Float32Array;
106
+ };
107
+ /**
108
+ * Import weights. Resets traces since the network state has changed.
109
+ */
110
+ importWeights(weights: {
111
+ inputHidden: Float32Array;
112
+ hiddenOutput: Float32Array;
113
+ }): void;
114
+ /** Get the current config (read-only). */
115
+ getConfig(): Readonly<EpropConfig>;
116
+ /** Get the raw eligibility trace values for testing/debugging. */
117
+ getTraces(): {
118
+ inputHidden: Float32Array;
119
+ hiddenOutput: Float32Array;
120
+ };
121
+ private validateConfig;
122
+ /** Xavier/Glorot uniform initialization */
123
+ private xavierInit;
124
+ /** Random uniform initialization in [-0.5, 0.5] */
125
+ private randomInit;
126
+ /** Sigmoid activation */
127
+ private sigmoid;
128
+ /** Softmax activation */
129
+ private softmax;
130
+ }
131
+ /**
132
+ * Create a new E-prop network with the given configuration.
133
+ */
134
+ export declare function createEpropNetwork(config?: Partial<EpropConfig>): EpropNetwork;
135
+ //# sourceMappingURL=eprop-learner.d.ts.map