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
|
@@ -86,8 +86,8 @@ export declare function getRuVectorStatus(config?: Partial<RuVectorConfig>): Pro
|
|
|
86
86
|
}>;
|
|
87
87
|
export * from './wrappers';
|
|
88
88
|
export { RuVectorServiceProvider, getDomainRuVectorServices, getRuVectorProvider, getRuVectorServiceAvailability, type RuVectorServiceConfig, } from './provider';
|
|
89
|
-
export { getRuVectorFeatureFlags, setRuVectorFeatureFlags, resetRuVectorFeatureFlags, isSONAEnabled, isFlashAttentionEnabled, isGNNIndexEnabled, isTemporalCompressionEnabled, isCrossDomainTransferEnabled, shouldLogMigrationMetrics, initFeatureFlagsFromEnv, DEFAULT_FEATURE_FLAGS, type RuVectorFeatureFlags, } from './feature-flags';
|
|
90
|
-
export { DomainTransferEngine, ThompsonSampler, createDomainTransferEngine, DEFAULT_DOMAIN_TRANSFER_CONFIG, type TransferCandidate, type TransferResult, type TransferRecord, type DomainTransferConfig, } from './domain-transfer';
|
|
89
|
+
export { getRuVectorFeatureFlags, setRuVectorFeatureFlags, resetRuVectorFeatureFlags, isSONAEnabled, isFlashAttentionEnabled, isGNNIndexEnabled, isTemporalCompressionEnabled, isCrossDomainTransferEnabled, shouldLogMigrationMetrics, initFeatureFlagsFromEnv, isHDCFingerprintingEnabled, isCusumDriftDetectionEnabled, isDeltaEventSourcingEnabled, isEwcPlusPlusEnabled, isGraphMAEEnabled, isHopfieldMemoryEnabled, isColdTierGNNEnabled, isMetaLearningEnabled, isSublinearSolverEnabled, isSpectralSparsificationEnabled, isReservoirReplayEnabled, isEpropOnlineLearningEnabled, isGrangerCausalityEnabled, DEFAULT_FEATURE_FLAGS, type RuVectorFeatureFlags, } from './feature-flags';
|
|
90
|
+
export { DomainTransferEngine, ThompsonSampler, createDomainTransferEngine, DEFAULT_DOMAIN_TRANSFER_CONFIG, DecayingBeta, PlateauDetector, ParetoFront, CuriosityBonus, type TransferCandidate, type TransferResult, type TransferRecord, type DomainTransferConfig, type ParetoPoint, } from './domain-transfer';
|
|
91
91
|
export { TransferCoherenceStub, createTransferCoherenceGate, type ITransferCoherenceGate, type CoherenceValidation, } from './transfer-coherence-stub';
|
|
92
92
|
export { TransferVerifier, createTransferVerifier, DEFAULT_VERIFICATION_CONFIG, type DomainPerformanceSnapshot, type TransferResultForVerification, type VerificationResult, type TransferVerificationConfig, } from './transfer-verification';
|
|
93
93
|
export { TemporalCompressionService, getTemporalCompressionService, createTemporalCompressionService, resetTemporalCompressionService, cosineSimilarity, TIER_CONFIG, THEORETICAL_COMPRESSION_RATIOS, ACTUAL_FALLBACK_RATIO, EXPECTED_COMPRESSION_RATIOS, HOT_THRESHOLD_DAYS, WARM_THRESHOLD_DAYS, type CompressionTier, type CompressedVector, type CompressionStats, } from './temporal-compression';
|
|
@@ -101,5 +101,16 @@ export { RvfDualWriter, createDualWriter } from './rvf-dual-writer.js';
|
|
|
101
101
|
export type { DualWriteConfig, DualWriteResult, DivergenceReport } from './rvf-dual-writer.js';
|
|
102
102
|
export { getSharedRvfDualWriter, getSharedRvfDualWriterSync, resetSharedRvfDualWriter, } from './shared-rvf-dual-writer.js';
|
|
103
103
|
export { CognitiveContainer, createCognitiveContainer, generateSigningKeyPair, type ContainerSegment, type ContainerManifest, type ExportOptions, type ImportOptions, type ImportResult, type VerificationResult as CognitiveContainerVerificationResult, type ContainerInfo, type Ed25519KeyPair, } from './cognitive-container';
|
|
104
|
+
export { HdcFingerprinter, createHdcFingerprinter, type HdcConfig, type PatternFingerprint, } from './hdc-fingerprint';
|
|
105
|
+
export { CusumDetector, type CusumConfig, type CusumResult, type GateType, } from './cusum-detector';
|
|
106
|
+
export { DeltaTracker, PATTERN_DELTAS_SCHEMA, type DeltaEvent, type DeltaTrackerConfig, type JsonPatch, } from './delta-tracker';
|
|
107
|
+
export { GraphMAEEncoder, createGraphMAEEncoder, type GraphMAEConfig, type QEGraph, type GraphMAEResult, } from './graphmae-encoder';
|
|
108
|
+
export { HopfieldMemory, createHopfieldMemory, type HopfieldConfig, type StoredPattern, type RecallResult, } from './hopfield-memory';
|
|
109
|
+
export { ColdTierTrainer, InMemoryGraph, FileBackedGraph, createColdTierTrainer, type ColdTierConfig, type ColdTierGraph, type TrainingResult, type CacheStats, } from './cold-tier-trainer';
|
|
110
|
+
export { PageRankSolver, createPageRankSolver, type PatternGraph, type ImportanceScore, type SolverConfig, } from './solver-adapter';
|
|
111
|
+
export { SpectralSparsifier, createSpectralSparsifier, type SparsifierGraph, type SpectralValidation, type SparsifierConfig, } from './spectral-sparsifier';
|
|
112
|
+
export { ReservoirReplayBuffer, createReservoirReplayBuffer, type ReservoirEntry, type ReservoirConfig, type ReservoirStats, type CoherenceTier, } from './reservoir-replay';
|
|
113
|
+
export { EpropNetwork, createEpropNetwork, type EpropConfig, type EpropStats, } from './eprop-learner';
|
|
114
|
+
export { GrangerAnalyzer, createGrangerAnalyzer, type TestExecutionHistory, type CausalLink, type GrangerConfig, } from './temporal-causality';
|
|
104
115
|
export { initializeSharedMemory, getSharedServerClient as getFleetSharedClient, setSharedServerClient, isSharedMemoryAvailable, getSharedMemoryStatus, getLastInitResult, shutdownSharedMemory, resetSharedMemoryState, integrateWithFleet, DEFAULT_SHARED_MEMORY_CONFIG, type SharedMemoryConfig, type SharedMemoryResult, type SharedMemoryStatus, } from './shared-memory';
|
|
105
116
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -287,11 +287,21 @@ export { RuVectorServiceProvider, getDomainRuVectorServices, getRuVectorProvider
|
|
|
287
287
|
// ============================================================================
|
|
288
288
|
// Feature Flags
|
|
289
289
|
// ============================================================================
|
|
290
|
-
export { getRuVectorFeatureFlags, setRuVectorFeatureFlags, resetRuVectorFeatureFlags, isSONAEnabled, isFlashAttentionEnabled, isGNNIndexEnabled, isTemporalCompressionEnabled, isCrossDomainTransferEnabled, shouldLogMigrationMetrics, initFeatureFlagsFromEnv,
|
|
290
|
+
export { getRuVectorFeatureFlags, setRuVectorFeatureFlags, resetRuVectorFeatureFlags, isSONAEnabled, isFlashAttentionEnabled, isGNNIndexEnabled, isTemporalCompressionEnabled, isCrossDomainTransferEnabled, shouldLogMigrationMetrics, initFeatureFlagsFromEnv,
|
|
291
|
+
// Phase 5 Milestone 1 (ADR-087)
|
|
292
|
+
isHDCFingerprintingEnabled, isCusumDriftDetectionEnabled, isDeltaEventSourcingEnabled, isEwcPlusPlusEnabled,
|
|
293
|
+
// Phase 5 Milestone 2 (ADR-087)
|
|
294
|
+
isGraphMAEEnabled, isHopfieldMemoryEnabled, isColdTierGNNEnabled,
|
|
295
|
+
// Phase 5 Milestone 3 (ADR-087)
|
|
296
|
+
isMetaLearningEnabled, isSublinearSolverEnabled, isSpectralSparsificationEnabled, isReservoirReplayEnabled,
|
|
297
|
+
// Phase 5 Milestone 4 (ADR-087)
|
|
298
|
+
isEpropOnlineLearningEnabled, isGrangerCausalityEnabled, DEFAULT_FEATURE_FLAGS, } from './feature-flags';
|
|
291
299
|
// ============================================================================
|
|
292
300
|
// Cross-Domain Transfer Learning (ADR-084, Task 2.3)
|
|
293
301
|
// ============================================================================
|
|
294
|
-
export { DomainTransferEngine, ThompsonSampler, createDomainTransferEngine, DEFAULT_DOMAIN_TRANSFER_CONFIG,
|
|
302
|
+
export { DomainTransferEngine, ThompsonSampler, createDomainTransferEngine, DEFAULT_DOMAIN_TRANSFER_CONFIG,
|
|
303
|
+
// R7: Meta-Learning Enhancements (ADR-087, Milestone 3)
|
|
304
|
+
DecayingBeta, PlateauDetector, ParetoFront, CuriosityBonus, } from './domain-transfer';
|
|
295
305
|
export { TransferCoherenceStub, createTransferCoherenceGate, } from './transfer-coherence-stub';
|
|
296
306
|
export { TransferVerifier, createTransferVerifier, DEFAULT_VERIFICATION_CONFIG, } from './transfer-verification';
|
|
297
307
|
// ============================================================================
|
|
@@ -325,6 +335,40 @@ export { getSharedRvfDualWriter, getSharedRvfDualWriterSync, resetSharedRvfDualW
|
|
|
325
335
|
// ============================================================================
|
|
326
336
|
export { CognitiveContainer, createCognitiveContainer, generateSigningKeyPair, } from './cognitive-container';
|
|
327
337
|
// ============================================================================
|
|
338
|
+
// Phase 5: Pattern Intelligence (ADR-087, Milestone 1)
|
|
339
|
+
// ============================================================================
|
|
340
|
+
// R1: HDC Pattern Fingerprinting
|
|
341
|
+
export { HdcFingerprinter, createHdcFingerprinter, } from './hdc-fingerprint';
|
|
342
|
+
// R2: CUSUM Drift Detection
|
|
343
|
+
export { CusumDetector, } from './cusum-detector';
|
|
344
|
+
// R3: Delta Event Sourcing
|
|
345
|
+
export { DeltaTracker, PATTERN_DELTAS_SCHEMA, } from './delta-tracker';
|
|
346
|
+
// ============================================================================
|
|
347
|
+
// Phase 5: Graph Learning (ADR-087, Milestone 2)
|
|
348
|
+
// ============================================================================
|
|
349
|
+
// R4: GraphMAE Self-Supervised Learning
|
|
350
|
+
export { GraphMAEEncoder, createGraphMAEEncoder, } from './graphmae-encoder';
|
|
351
|
+
// R5: Modern Hopfield Networks
|
|
352
|
+
export { HopfieldMemory, createHopfieldMemory, } from './hopfield-memory';
|
|
353
|
+
// R6: Cold-Tier GNN Training
|
|
354
|
+
export { ColdTierTrainer, InMemoryGraph, FileBackedGraph, createColdTierTrainer, } from './cold-tier-trainer';
|
|
355
|
+
// ============================================================================
|
|
356
|
+
// Phase 5: Scale & Optimization (ADR-087, Milestone 3)
|
|
357
|
+
// ============================================================================
|
|
358
|
+
// R8: PageRank Pattern Importance Solver
|
|
359
|
+
export { PageRankSolver, createPageRankSolver, } from './solver-adapter';
|
|
360
|
+
// R9: Spectral Graph Sparsification
|
|
361
|
+
export { SpectralSparsifier, createSpectralSparsifier, } from './spectral-sparsifier';
|
|
362
|
+
// R10: Reservoir Replay with Coherence Gating
|
|
363
|
+
export { ReservoirReplayBuffer, createReservoirReplayBuffer, } from './reservoir-replay';
|
|
364
|
+
// ============================================================================
|
|
365
|
+
// Phase 5: Advanced Learning (ADR-087, Milestone 4)
|
|
366
|
+
// ============================================================================
|
|
367
|
+
// R11: E-prop Online Learning
|
|
368
|
+
export { EpropNetwork, createEpropNetwork, } from './eprop-learner';
|
|
369
|
+
// R12: Granger Causality for Test Failure Prediction
|
|
370
|
+
export { GrangerAnalyzer, createGrangerAnalyzer, } from './temporal-causality';
|
|
371
|
+
// ============================================================================
|
|
328
372
|
// Shared Memory Integration (Fleet Integration)
|
|
329
373
|
// ============================================================================
|
|
330
374
|
export { initializeSharedMemory, getSharedServerClient as getFleetSharedClient, setSharedServerClient, isSharedMemoryAvailable, getSharedMemoryStatus, getLastInitResult, shutdownSharedMemory, resetSharedMemoryState, integrateWithFleet, DEFAULT_SHARED_MEMORY_CONFIG, } from './shared-memory';
|
|
@@ -168,6 +168,13 @@ export declare class QEMinCutService {
|
|
|
168
168
|
* @returns Health report with lambda, weak points, and suggestions
|
|
169
169
|
*/
|
|
170
170
|
getStructuralHealth(graph: TaskGraph): HealthReport;
|
|
171
|
+
/**
|
|
172
|
+
* Optionally sparsify a large task graph before mincut analysis.
|
|
173
|
+
* Only activates when the useSpectralSparsification feature flag is enabled
|
|
174
|
+
* AND the graph has more than 100 edges (below that, sparsification costs
|
|
175
|
+
* more than it saves).
|
|
176
|
+
*/
|
|
177
|
+
private maybeSparsify;
|
|
171
178
|
/**
|
|
172
179
|
* Convert a TaskGraph to a SwarmGraph for use with MinCutCalculator
|
|
173
180
|
*/
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { MinCutCalculator } from '../../coordination/mincut/mincut-calculator.js';
|
|
13
13
|
import { SwarmGraph } from '../../coordination/mincut/swarm-graph.js';
|
|
14
|
+
import { getRuVectorFeatureFlags } from './feature-flags.js';
|
|
15
|
+
import { SpectralSparsifier } from './spectral-sparsifier.js';
|
|
14
16
|
// ============================================================================
|
|
15
17
|
// QEMinCutService
|
|
16
18
|
// ============================================================================
|
|
@@ -49,7 +51,8 @@ export class QEMinCutService {
|
|
|
49
51
|
* @returns The min-cut lambda value (0 if graph is empty/disconnected)
|
|
50
52
|
*/
|
|
51
53
|
computeLambda(graph) {
|
|
52
|
-
const
|
|
54
|
+
const effective = this.maybeSparsify(graph);
|
|
55
|
+
const swarmGraph = this.toSwarmGraph(effective);
|
|
53
56
|
return this.calculator.getMinCutValue(swarmGraph);
|
|
54
57
|
}
|
|
55
58
|
/**
|
|
@@ -99,7 +102,8 @@ export class QEMinCutService {
|
|
|
99
102
|
* @returns Health report with lambda, weak points, and suggestions
|
|
100
103
|
*/
|
|
101
104
|
getStructuralHealth(graph) {
|
|
102
|
-
const
|
|
105
|
+
const effective = this.maybeSparsify(graph);
|
|
106
|
+
const swarmGraph = this.toSwarmGraph(effective);
|
|
103
107
|
if (swarmGraph.isEmpty()) {
|
|
104
108
|
return this.emptyHealthReport();
|
|
105
109
|
}
|
|
@@ -129,6 +133,54 @@ export class QEMinCutService {
|
|
|
129
133
|
};
|
|
130
134
|
}
|
|
131
135
|
// ==========================================================================
|
|
136
|
+
// Spectral Sparsification (R9, ADR-087)
|
|
137
|
+
// ==========================================================================
|
|
138
|
+
/**
|
|
139
|
+
* Optionally sparsify a large task graph before mincut analysis.
|
|
140
|
+
* Only activates when the useSpectralSparsification feature flag is enabled
|
|
141
|
+
* AND the graph has more than 100 edges (below that, sparsification costs
|
|
142
|
+
* more than it saves).
|
|
143
|
+
*/
|
|
144
|
+
maybeSparsify(graph) {
|
|
145
|
+
if (!getRuVectorFeatureFlags().useSpectralSparsification)
|
|
146
|
+
return graph;
|
|
147
|
+
if (graph.edges.length <= 100)
|
|
148
|
+
return graph;
|
|
149
|
+
// Build node ID→index map
|
|
150
|
+
const nodeIndex = new Map();
|
|
151
|
+
graph.nodes.forEach((n, i) => nodeIndex.set(n.id, i));
|
|
152
|
+
// Convert to SparsifierGraph (undirected, weighted)
|
|
153
|
+
const sparsifierEdges = [];
|
|
154
|
+
for (const e of graph.edges) {
|
|
155
|
+
const si = nodeIndex.get(e.source);
|
|
156
|
+
const ti = nodeIndex.get(e.target);
|
|
157
|
+
if (si !== undefined && ti !== undefined) {
|
|
158
|
+
sparsifierEdges.push([si, ti, e.weight]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const sparsifierGraph = {
|
|
162
|
+
nodeCount: graph.nodes.length,
|
|
163
|
+
edges: sparsifierEdges,
|
|
164
|
+
};
|
|
165
|
+
const sparsifier = new SpectralSparsifier({ epsilon: 0.3 });
|
|
166
|
+
const sparsified = sparsifier.sparsify(sparsifierGraph);
|
|
167
|
+
// Convert back to TaskGraph edges
|
|
168
|
+
const sparsifiedEdges = [];
|
|
169
|
+
for (const [u, v, w] of sparsified.edges) {
|
|
170
|
+
const sourceNode = graph.nodes[u];
|
|
171
|
+
const targetNode = graph.nodes[v];
|
|
172
|
+
if (sourceNode && targetNode) {
|
|
173
|
+
sparsifiedEdges.push({
|
|
174
|
+
source: sourceNode.id,
|
|
175
|
+
target: targetNode.id,
|
|
176
|
+
weight: w,
|
|
177
|
+
edgeType: 'coordination',
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return { nodes: graph.nodes, edges: sparsifiedEdges };
|
|
182
|
+
}
|
|
183
|
+
// ==========================================================================
|
|
132
184
|
// Graph Conversion
|
|
133
185
|
// ==========================================================================
|
|
134
186
|
/**
|
|
@@ -0,0 +1,172 @@
|
|
|
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 { type CusumResult, type GateType } from './cusum-detector.js';
|
|
21
|
+
/** Coherence tier classification */
|
|
22
|
+
export type CoherenceTier = 'high' | 'medium' | 'low';
|
|
23
|
+
/** An experience entry in the reservoir */
|
|
24
|
+
export interface ReservoirEntry<T = unknown> {
|
|
25
|
+
/** Unique entry ID */
|
|
26
|
+
id: string;
|
|
27
|
+
/** The stored data */
|
|
28
|
+
data: T;
|
|
29
|
+
/** Coherence score at admission time (0-1) */
|
|
30
|
+
coherenceScore: number;
|
|
31
|
+
/** Classified coherence tier */
|
|
32
|
+
tier: CoherenceTier;
|
|
33
|
+
/** Timestamp of admission */
|
|
34
|
+
admittedAt: number;
|
|
35
|
+
/** Number of times this entry has been sampled for replay */
|
|
36
|
+
replayCount: number;
|
|
37
|
+
}
|
|
38
|
+
/** Configuration for the reservoir */
|
|
39
|
+
export interface ReservoirConfig {
|
|
40
|
+
/** Maximum buffer capacity (default: 10000) */
|
|
41
|
+
capacity: number;
|
|
42
|
+
/** Minimum coherence score for admission (default: 0.3) */
|
|
43
|
+
minCoherenceThreshold: number;
|
|
44
|
+
/** Coherence threshold for 'high' tier (default: 0.8) */
|
|
45
|
+
highTierThreshold: number;
|
|
46
|
+
/** Coherence threshold for 'medium' tier (default: 0.5) */
|
|
47
|
+
mediumTierThreshold: number;
|
|
48
|
+
/** Sampling weight multiplier for high-coherence entries (default: 3.0) */
|
|
49
|
+
highTierWeight: number;
|
|
50
|
+
/** Sampling weight multiplier for medium-coherence entries (default: 1.5) */
|
|
51
|
+
mediumTierWeight: number;
|
|
52
|
+
/** Sampling weight multiplier for low-coherence entries (default: 1.0) */
|
|
53
|
+
lowTierWeight: number;
|
|
54
|
+
/** CUSUM config for drift-aware gating */
|
|
55
|
+
cusumConfig?: {
|
|
56
|
+
threshold?: number;
|
|
57
|
+
slack?: number;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Statistics about the reservoir buffer */
|
|
61
|
+
export interface ReservoirStats {
|
|
62
|
+
/** Current number of entries */
|
|
63
|
+
size: number;
|
|
64
|
+
/** Maximum capacity */
|
|
65
|
+
capacity: number;
|
|
66
|
+
/** Total entries admitted */
|
|
67
|
+
totalAdmitted: number;
|
|
68
|
+
/** Total entries rejected (below threshold) */
|
|
69
|
+
totalRejected: number;
|
|
70
|
+
/** Total entries evicted (reservoir overflow) */
|
|
71
|
+
totalEvicted: number;
|
|
72
|
+
/** Breakdown by coherence tier */
|
|
73
|
+
tierCounts: Record<CoherenceTier, number>;
|
|
74
|
+
/** Total samples drawn */
|
|
75
|
+
totalSampled: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A fixed-capacity replay buffer with coherence-gated admission and
|
|
79
|
+
* tier-weighted sampling. Uses Algorithm R for reservoir sampling
|
|
80
|
+
* and integrates CUSUM drift detection for adaptive admission control.
|
|
81
|
+
*
|
|
82
|
+
* Usage:
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const buffer = new ReservoirReplayBuffer({ capacity: 1000 });
|
|
85
|
+
* buffer.admit('exp-1', myData, 0.85); // high coherence
|
|
86
|
+
* buffer.admit('exp-2', myData, 0.10); // rejected (below threshold)
|
|
87
|
+
* const batch = buffer.sample(32); // weighted toward high-coherence
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare class ReservoirReplayBuffer<T = unknown> {
|
|
91
|
+
private readonly config;
|
|
92
|
+
private readonly cusumDetector;
|
|
93
|
+
private readonly buffer;
|
|
94
|
+
/** Total number of items that have been offered for admission (including rejected) */
|
|
95
|
+
private totalSeen;
|
|
96
|
+
/** Total items actually admitted into the buffer */
|
|
97
|
+
private totalAdmitted;
|
|
98
|
+
/** Total items rejected at the coherence gate */
|
|
99
|
+
private totalRejected;
|
|
100
|
+
/** Total items evicted by reservoir replacement */
|
|
101
|
+
private totalEvicted;
|
|
102
|
+
/** Total individual samples drawn */
|
|
103
|
+
private totalSampled;
|
|
104
|
+
constructor(config?: Partial<ReservoirConfig>);
|
|
105
|
+
/**
|
|
106
|
+
* Attempt to admit an experience to the reservoir.
|
|
107
|
+
*
|
|
108
|
+
* Uses coherence-gated admission:
|
|
109
|
+
* 1. Reject if coherence < minCoherenceThreshold (adjusted by CUSUM drift)
|
|
110
|
+
* 2. If buffer has capacity, admit directly
|
|
111
|
+
* 3. If buffer is full, use Algorithm R reservoir sampling to decide eviction
|
|
112
|
+
* 4. High-coherence entries get a boost to their effective admission probability
|
|
113
|
+
*
|
|
114
|
+
* @param id - Unique entry identifier
|
|
115
|
+
* @param data - The data payload to store
|
|
116
|
+
* @param coherenceScore - Coherence score in [0, 1]
|
|
117
|
+
* @returns true if admitted, false if rejected
|
|
118
|
+
*/
|
|
119
|
+
admit(id: string, data: T, coherenceScore: number): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Sample a batch from the reservoir with coherence-weighted probability.
|
|
122
|
+
* High-coherence entries are more likely to be sampled according to their
|
|
123
|
+
* tier weights.
|
|
124
|
+
*
|
|
125
|
+
* @param batchSize - Number of entries to sample
|
|
126
|
+
* @param minCoherence - Optional minimum coherence filter
|
|
127
|
+
* @returns Sampled entries (may be fewer than batchSize if buffer is small)
|
|
128
|
+
*/
|
|
129
|
+
sample(batchSize: number, minCoherence?: number): ReservoirEntry<T>[];
|
|
130
|
+
/** Get current buffer size */
|
|
131
|
+
size(): number;
|
|
132
|
+
/** Get buffer statistics */
|
|
133
|
+
getStats(): ReservoirStats;
|
|
134
|
+
/** Get all entries in a specific coherence tier */
|
|
135
|
+
getByTier(tier: CoherenceTier): ReservoirEntry<T>[];
|
|
136
|
+
/** Clear the buffer and reset all statistics */
|
|
137
|
+
clear(): void;
|
|
138
|
+
/** Get the CUSUM detector state for a gate type */
|
|
139
|
+
getCusumState(gateType: GateType): CusumResult;
|
|
140
|
+
/**
|
|
141
|
+
* Feed a coherence observation to the CUSUM detector.
|
|
142
|
+
* When drift is detected, the admission threshold is temporarily tightened.
|
|
143
|
+
*/
|
|
144
|
+
observeCoherence(gateType: GateType, value: number): CusumResult;
|
|
145
|
+
/**
|
|
146
|
+
* Classify a coherence score into a tier.
|
|
147
|
+
*/
|
|
148
|
+
private classifyTier;
|
|
149
|
+
/**
|
|
150
|
+
* Get the sampling/admission weight for a tier.
|
|
151
|
+
*/
|
|
152
|
+
private getTierWeight;
|
|
153
|
+
/**
|
|
154
|
+
* Get the effective admission threshold, tightened during drift.
|
|
155
|
+
*
|
|
156
|
+
* When CUSUM detects drift on any gate, we raise the minimum coherence
|
|
157
|
+
* threshold by 50% (capped at 0.9) to reject more marginal entries.
|
|
158
|
+
*/
|
|
159
|
+
private getEffectiveThreshold;
|
|
160
|
+
/**
|
|
161
|
+
* Select an eviction target, preferring low-coherence entries.
|
|
162
|
+
*
|
|
163
|
+
* Given a candidate index from reservoir sampling, look for a nearby
|
|
164
|
+
* low-coherence entry to evict instead (within a small window).
|
|
165
|
+
*/
|
|
166
|
+
private selectEvictionTarget;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a ReservoirReplayBuffer instance with optional configuration.
|
|
170
|
+
*/
|
|
171
|
+
export declare function createReservoirReplayBuffer<T = unknown>(config?: Partial<ReservoirConfig>): ReservoirReplayBuffer<T>;
|
|
172
|
+
//# sourceMappingURL=reservoir-replay.d.ts.map
|