agentic-qe 3.7.21 → 3.8.0

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 (164) hide show
  1. package/.claude/helpers/brain-checkpoint.cjs +4 -1
  2. package/.claude/helpers/statusline-v3.cjs +3 -1
  3. package/.claude/skills/skills-manifest.json +1 -1
  4. package/CHANGELOG.md +45 -0
  5. package/README.md +2 -14
  6. package/assets/helpers/statusline-v3.cjs +3 -1
  7. package/dist/cli/brain-commands.js +6 -10
  8. package/dist/cli/bundle.js +7441 -4327
  9. package/dist/cli/commands/audit.d.ts +43 -0
  10. package/dist/cli/commands/audit.js +125 -0
  11. package/dist/cli/commands/hooks.js +29 -6
  12. package/dist/cli/commands/init.js +1 -73
  13. package/dist/cli/commands/learning.js +270 -13
  14. package/dist/cli/commands/ruvector-commands.d.ts +15 -0
  15. package/dist/cli/commands/ruvector-commands.js +271 -0
  16. package/dist/cli/handlers/init-handler.d.ts +0 -1
  17. package/dist/cli/handlers/init-handler.js +0 -6
  18. package/dist/cli/index.js +4 -2
  19. package/dist/context/sources/defect-source.js +2 -2
  20. package/dist/context/sources/memory-source.js +2 -2
  21. package/dist/context/sources/requirements-source.js +2 -2
  22. package/dist/coordination/behavior-tree/decorators.d.ts +108 -0
  23. package/dist/coordination/behavior-tree/decorators.js +251 -0
  24. package/dist/coordination/behavior-tree/index.d.ts +12 -0
  25. package/dist/coordination/behavior-tree/index.js +15 -0
  26. package/dist/coordination/behavior-tree/nodes.d.ts +165 -0
  27. package/dist/coordination/behavior-tree/nodes.js +338 -0
  28. package/dist/coordination/behavior-tree/qe-trees.d.ts +105 -0
  29. package/dist/coordination/behavior-tree/qe-trees.js +181 -0
  30. package/dist/coordination/coherence-action-gate.d.ts +284 -0
  31. package/dist/coordination/coherence-action-gate.js +512 -0
  32. package/dist/coordination/index.d.ts +4 -0
  33. package/dist/coordination/index.js +8 -0
  34. package/dist/coordination/reasoning-qec.d.ts +315 -0
  35. package/dist/coordination/reasoning-qec.js +585 -0
  36. package/dist/coordination/task-executor.d.ts +16 -0
  37. package/dist/coordination/task-executor.js +99 -0
  38. package/dist/coordination/workflow-orchestrator.d.ts +29 -0
  39. package/dist/coordination/workflow-orchestrator.js +42 -0
  40. package/dist/domains/visual-accessibility/cnn-visual-regression.d.ts +135 -0
  41. package/dist/domains/visual-accessibility/cnn-visual-regression.js +327 -0
  42. package/dist/domains/visual-accessibility/index.d.ts +1 -0
  43. package/dist/domains/visual-accessibility/index.js +4 -0
  44. package/dist/governance/coherence-validator.d.ts +112 -0
  45. package/dist/governance/coherence-validator.js +180 -0
  46. package/dist/governance/index.d.ts +1 -0
  47. package/dist/governance/index.js +2 -0
  48. package/dist/governance/witness-chain.d.ts +311 -0
  49. package/dist/governance/witness-chain.js +509 -0
  50. package/dist/init/index.d.ts +0 -2
  51. package/dist/init/index.js +0 -1
  52. package/dist/init/init-wizard-steps.d.ts +10 -0
  53. package/dist/init/init-wizard-steps.js +87 -1
  54. package/dist/init/init-wizard.d.ts +1 -9
  55. package/dist/init/init-wizard.js +3 -69
  56. package/dist/init/orchestrator.js +0 -1
  57. package/dist/init/phases/01-detection.js +0 -27
  58. package/dist/init/phases/07-hooks.js +6 -4
  59. package/dist/init/phases/phase-interface.d.ts +0 -1
  60. package/dist/init/settings-merge.js +1 -1
  61. package/dist/integrations/browser/qe-dashboard/clustering.d.ts +48 -0
  62. package/dist/integrations/browser/qe-dashboard/clustering.js +183 -0
  63. package/dist/integrations/browser/qe-dashboard/index.d.ts +12 -0
  64. package/dist/integrations/browser/qe-dashboard/index.js +15 -0
  65. package/dist/integrations/browser/qe-dashboard/pattern-explorer.d.ts +165 -0
  66. package/dist/integrations/browser/qe-dashboard/pattern-explorer.js +260 -0
  67. package/dist/integrations/browser/qe-dashboard/wasm-vector-store.d.ts +144 -0
  68. package/dist/integrations/browser/qe-dashboard/wasm-vector-store.js +277 -0
  69. package/dist/integrations/ruvector/cognitive-container-codec.d.ts +51 -0
  70. package/dist/integrations/ruvector/cognitive-container-codec.js +180 -0
  71. package/dist/integrations/ruvector/cognitive-container.d.ts +125 -0
  72. package/dist/integrations/ruvector/cognitive-container.js +306 -0
  73. package/dist/integrations/ruvector/coherence-gate.d.ts +309 -0
  74. package/dist/integrations/ruvector/coherence-gate.js +631 -0
  75. package/dist/integrations/ruvector/compressed-hnsw-integration.d.ts +176 -0
  76. package/dist/integrations/ruvector/compressed-hnsw-integration.js +301 -0
  77. package/dist/integrations/ruvector/dither-adapter.d.ts +122 -0
  78. package/dist/integrations/ruvector/dither-adapter.js +295 -0
  79. package/dist/integrations/ruvector/domain-transfer.d.ts +129 -0
  80. package/dist/integrations/ruvector/domain-transfer.js +220 -0
  81. package/dist/integrations/ruvector/feature-flags.d.ts +214 -2
  82. package/dist/integrations/ruvector/feature-flags.js +167 -2
  83. package/dist/integrations/ruvector/filter-adapter.d.ts +71 -0
  84. package/dist/integrations/ruvector/filter-adapter.js +285 -0
  85. package/dist/integrations/ruvector/gnn-wrapper.d.ts +20 -0
  86. package/dist/integrations/ruvector/gnn-wrapper.js +40 -0
  87. package/dist/integrations/ruvector/hnsw-health-monitor.d.ts +237 -0
  88. package/dist/integrations/ruvector/hnsw-health-monitor.js +394 -0
  89. package/dist/integrations/ruvector/index.d.ts +8 -2
  90. package/dist/integrations/ruvector/index.js +18 -2
  91. package/dist/integrations/ruvector/interfaces.d.ts +40 -0
  92. package/dist/integrations/ruvector/sona-persistence.d.ts +54 -0
  93. package/dist/integrations/ruvector/sona-persistence.js +162 -0
  94. package/dist/integrations/ruvector/sona-three-loop.d.ts +392 -0
  95. package/dist/integrations/ruvector/sona-three-loop.js +814 -0
  96. package/dist/integrations/ruvector/sona-wrapper.d.ts +97 -0
  97. package/dist/integrations/ruvector/sona-wrapper.js +147 -3
  98. package/dist/integrations/ruvector/spectral-math.d.ts +101 -0
  99. package/dist/integrations/ruvector/spectral-math.js +254 -0
  100. package/dist/integrations/ruvector/temporal-compression.d.ts +163 -0
  101. package/dist/integrations/ruvector/temporal-compression.js +318 -0
  102. package/dist/integrations/ruvector/thompson-sampler.d.ts +61 -0
  103. package/dist/integrations/ruvector/thompson-sampler.js +118 -0
  104. package/dist/integrations/ruvector/transfer-coherence-stub.d.ts +80 -0
  105. package/dist/integrations/ruvector/transfer-coherence-stub.js +63 -0
  106. package/dist/integrations/ruvector/transfer-verification.d.ts +119 -0
  107. package/dist/integrations/ruvector/transfer-verification.js +115 -0
  108. package/dist/kernel/hnsw-adapter.d.ts +52 -1
  109. package/dist/kernel/hnsw-adapter.js +139 -4
  110. package/dist/kernel/hnsw-index-provider.d.ts +5 -0
  111. package/dist/kernel/native-hnsw-backend.d.ts +110 -0
  112. package/dist/kernel/native-hnsw-backend.js +408 -0
  113. package/dist/kernel/unified-memory.js +5 -6
  114. package/dist/learning/aqe-learning-engine.d.ts +2 -0
  115. package/dist/learning/aqe-learning-engine.js +65 -0
  116. package/dist/learning/experience-capture-middleware.js +20 -0
  117. package/dist/learning/experience-capture.d.ts +10 -0
  118. package/dist/learning/experience-capture.js +34 -0
  119. package/dist/learning/index.d.ts +2 -2
  120. package/dist/learning/index.js +4 -4
  121. package/dist/learning/metrics-tracker.d.ts +11 -0
  122. package/dist/learning/metrics-tracker.js +29 -13
  123. package/dist/learning/pattern-lifecycle.d.ts +30 -1
  124. package/dist/learning/pattern-lifecycle.js +92 -20
  125. package/dist/learning/pattern-store.d.ts +8 -0
  126. package/dist/learning/pattern-store.js +8 -2
  127. package/dist/learning/qe-unified-memory.js +1 -28
  128. package/dist/learning/regret-tracker.d.ts +201 -0
  129. package/dist/learning/regret-tracker.js +361 -0
  130. package/dist/mcp/bundle.js +5915 -474
  131. package/dist/routing/index.d.ts +4 -2
  132. package/dist/routing/index.js +3 -1
  133. package/dist/routing/neural-tiny-dancer-router.d.ts +268 -0
  134. package/dist/routing/neural-tiny-dancer-router.js +514 -0
  135. package/dist/routing/queen-integration.js +5 -5
  136. package/dist/routing/routing-config.d.ts +6 -0
  137. package/dist/routing/routing-config.js +1 -0
  138. package/dist/routing/simple-neural-router.d.ts +76 -0
  139. package/dist/routing/simple-neural-router.js +202 -0
  140. package/dist/routing/tiny-dancer-router.d.ts +20 -1
  141. package/dist/routing/tiny-dancer-router.js +21 -2
  142. package/dist/test-scheduling/dag-attention-scheduler.d.ts +81 -0
  143. package/dist/test-scheduling/dag-attention-scheduler.js +358 -0
  144. package/dist/test-scheduling/dag-attention-types.d.ts +81 -0
  145. package/dist/test-scheduling/dag-attention-types.js +10 -0
  146. package/dist/test-scheduling/index.d.ts +1 -0
  147. package/dist/test-scheduling/index.js +4 -0
  148. package/dist/test-scheduling/pipeline.d.ts +8 -0
  149. package/dist/test-scheduling/pipeline.js +28 -0
  150. package/package.json +6 -2
  151. package/dist/cli/commands/migrate.d.ts +0 -9
  152. package/dist/cli/commands/migrate.js +0 -566
  153. package/dist/init/init-wizard-migration.d.ts +0 -52
  154. package/dist/init/init-wizard-migration.js +0 -345
  155. package/dist/init/migration/config-migrator.d.ts +0 -31
  156. package/dist/init/migration/config-migrator.js +0 -149
  157. package/dist/init/migration/data-migrator.d.ts +0 -72
  158. package/dist/init/migration/data-migrator.js +0 -232
  159. package/dist/init/migration/detector.d.ts +0 -44
  160. package/dist/init/migration/detector.js +0 -105
  161. package/dist/init/migration/index.d.ts +0 -8
  162. package/dist/init/migration/index.js +0 -8
  163. package/dist/learning/v2-to-v3-migration.d.ts +0 -86
  164. package/dist/learning/v2-to-v3-migration.js +0 -529
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Transfer Coherence Gate Stub (Task 2.3)
3
+ *
4
+ * Provides a pass-through coherence gate for cross-domain transfer validation.
5
+ * When the `useCoherenceGate` feature flag is enabled, the factory function
6
+ * returns the real CoherenceGate (backed by prime-radiant-advanced-wasm).
7
+ * Otherwise, returns the pass-through stub.
8
+ *
9
+ * The interface is stable and must not change when the real implementation
10
+ * is swapped in.
11
+ *
12
+ * @module integrations/ruvector/transfer-coherence-stub
13
+ */
14
+ /**
15
+ * Coherence validation result for a cross-domain transfer.
16
+ */
17
+ export interface CoherenceValidation {
18
+ /** Whether the transfer is approved by the coherence gate */
19
+ approved: boolean;
20
+ /** Coherence energy score (lower = more coherent). Undefined when stub is used. */
21
+ energy?: number;
22
+ /** Reason for rejection (only set when approved is false) */
23
+ rejectionReason?: string;
24
+ }
25
+ /**
26
+ * Interface for the transfer coherence gate.
27
+ *
28
+ * Validates that a pattern transfer between domains does not introduce
29
+ * contradictions or reduce overall system coherence. The gate evaluates
30
+ * the energy landscape of the target domain with the proposed pattern
31
+ * and rejects transfers that would destabilize learned knowledge.
32
+ */
33
+ export interface ITransferCoherenceGate {
34
+ /**
35
+ * Validate whether a pattern can be transferred to a target domain
36
+ * without introducing coherence violations.
37
+ *
38
+ * @param pattern - The pattern to transfer (any pattern-like object with domain info)
39
+ * @param targetDomain - The domain to transfer the pattern into
40
+ * @returns Validation result with approval status and optional energy score
41
+ */
42
+ validateTransfer(pattern: {
43
+ id?: string;
44
+ domain?: string;
45
+ confidence?: number;
46
+ [key: string]: unknown;
47
+ }, targetDomain: string): CoherenceValidation;
48
+ }
49
+ /**
50
+ * Stub coherence gate that always approves transfers.
51
+ *
52
+ * This is a pass-through implementation used until the real coherence gate
53
+ * (ADR-083) is implemented in Task 3.1. It serves as a placeholder to
54
+ * keep the transfer pipeline functional while the coherence system is
55
+ * being developed.
56
+ */
57
+ export declare class TransferCoherenceStub implements ITransferCoherenceGate {
58
+ /**
59
+ * Always approves the transfer (pass-through stub).
60
+ *
61
+ * @param _pattern - Ignored in stub
62
+ * @param _targetDomain - Ignored in stub
63
+ * @returns Always returns { approved: true }
64
+ */
65
+ validateTransfer(_pattern: {
66
+ id?: string;
67
+ domain?: string;
68
+ confidence?: number;
69
+ [key: string]: unknown;
70
+ }, _targetDomain: string): CoherenceValidation;
71
+ }
72
+ /**
73
+ * Create a transfer coherence gate.
74
+ *
75
+ * When the `useCoherenceGate` feature flag is enabled, returns the real
76
+ * CoherenceGate backed by sheaf cohomology energy computation.
77
+ * Otherwise returns the pass-through stub.
78
+ */
79
+ export declare function createTransferCoherenceGate(): ITransferCoherenceGate;
80
+ //# sourceMappingURL=transfer-coherence-stub.d.ts.map
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Transfer Coherence Gate Stub (Task 2.3)
3
+ *
4
+ * Provides a pass-through coherence gate for cross-domain transfer validation.
5
+ * When the `useCoherenceGate` feature flag is enabled, the factory function
6
+ * returns the real CoherenceGate (backed by prime-radiant-advanced-wasm).
7
+ * Otherwise, returns the pass-through stub.
8
+ *
9
+ * The interface is stable and must not change when the real implementation
10
+ * is swapped in.
11
+ *
12
+ * @module integrations/ruvector/transfer-coherence-stub
13
+ */
14
+ import { createRequire } from 'module';
15
+ import { getRuVectorFeatureFlags } from './feature-flags.js';
16
+ const esmRequire = createRequire(import.meta.url);
17
+ // ============================================================================
18
+ // Stub Implementation
19
+ // ============================================================================
20
+ /**
21
+ * Stub coherence gate that always approves transfers.
22
+ *
23
+ * This is a pass-through implementation used until the real coherence gate
24
+ * (ADR-083) is implemented in Task 3.1. It serves as a placeholder to
25
+ * keep the transfer pipeline functional while the coherence system is
26
+ * being developed.
27
+ */
28
+ export class TransferCoherenceStub {
29
+ /**
30
+ * Always approves the transfer (pass-through stub).
31
+ *
32
+ * @param _pattern - Ignored in stub
33
+ * @param _targetDomain - Ignored in stub
34
+ * @returns Always returns { approved: true }
35
+ */
36
+ validateTransfer(_pattern, _targetDomain) {
37
+ return { approved: true };
38
+ }
39
+ }
40
+ // ============================================================================
41
+ // Factory
42
+ // ============================================================================
43
+ /**
44
+ * Create a transfer coherence gate.
45
+ *
46
+ * When the `useCoherenceGate` feature flag is enabled, returns the real
47
+ * CoherenceGate backed by sheaf cohomology energy computation.
48
+ * Otherwise returns the pass-through stub.
49
+ */
50
+ export function createTransferCoherenceGate() {
51
+ if (getRuVectorFeatureFlags().useCoherenceGate) {
52
+ try {
53
+ // Dynamic require to avoid circular dependency at module level
54
+ const { CoherenceGate } = esmRequire('./coherence-gate.js');
55
+ return new CoherenceGate();
56
+ }
57
+ catch {
58
+ // Fall through to stub if CoherenceGate fails to load
59
+ }
60
+ }
61
+ return new TransferCoherenceStub();
62
+ }
63
+ //# sourceMappingURL=transfer-coherence-stub.js.map
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Transfer Verification (Task 2.3)
3
+ *
4
+ * Verifies that cross-domain pattern transfers do not cause regression
5
+ * in either the source or target domain. A transfer is considered valid
6
+ * only when:
7
+ * 1. The target domain improves (or at least does not degrade)
8
+ * 2. The source domain does not regress
9
+ *
10
+ * This double-gate ensures that knowledge sharing is always net-positive.
11
+ *
12
+ * @module integrations/ruvector/transfer-verification
13
+ */
14
+ /**
15
+ * Performance snapshot for a domain at a point in time.
16
+ */
17
+ export interface DomainPerformanceSnapshot {
18
+ /** Domain identifier */
19
+ domain: string;
20
+ /** Success rate (0-1) */
21
+ successRate: number;
22
+ /** Average confidence of patterns in the domain */
23
+ avgConfidence: number;
24
+ /** Number of patterns in the domain */
25
+ patternCount: number;
26
+ /** Timestamp of the snapshot */
27
+ timestamp: number;
28
+ }
29
+ /**
30
+ * Transfer result to be verified.
31
+ */
32
+ export interface TransferResultForVerification {
33
+ /** Unique transfer identifier */
34
+ transferId: string;
35
+ /** Source domain */
36
+ sourceDomain: string;
37
+ /** Target domain */
38
+ targetDomain: string;
39
+ /** Source domain performance BEFORE the transfer */
40
+ sourcePerformanceBefore: DomainPerformanceSnapshot;
41
+ /** Source domain performance AFTER the transfer */
42
+ sourcePerformanceAfter: DomainPerformanceSnapshot;
43
+ /** Target domain performance BEFORE the transfer */
44
+ targetPerformanceBefore: DomainPerformanceSnapshot;
45
+ /** Target domain performance AFTER the transfer */
46
+ targetPerformanceAfter: DomainPerformanceSnapshot;
47
+ }
48
+ /**
49
+ * Result of the transfer verification.
50
+ */
51
+ export interface VerificationResult {
52
+ /** Whether the transfer passed verification */
53
+ passed: boolean;
54
+ /** Whether the source domain maintained performance */
55
+ sourceStable: boolean;
56
+ /** Whether the target domain improved */
57
+ targetImproved: boolean;
58
+ /** Change in source domain success rate */
59
+ sourceDelta: number;
60
+ /** Change in target domain success rate */
61
+ targetDelta: number;
62
+ /** Change in source domain confidence */
63
+ sourceConfidenceDelta: number;
64
+ /** Change in target domain confidence */
65
+ targetConfidenceDelta: number;
66
+ /** Failure reason (when passed is false) */
67
+ failureReason?: string;
68
+ }
69
+ /**
70
+ * Configuration for transfer verification thresholds.
71
+ */
72
+ export interface TransferVerificationConfig {
73
+ /**
74
+ * Maximum allowed regression in source domain success rate.
75
+ * A small tolerance is permitted to account for noise.
76
+ * @default 0.05 (5%)
77
+ */
78
+ maxSourceRegression: number;
79
+ /**
80
+ * Minimum required improvement in target domain success rate.
81
+ * Set to 0 to allow neutral transfers (no improvement but no regression).
82
+ * @default 0.0
83
+ */
84
+ minTargetImprovement: number;
85
+ /**
86
+ * Maximum allowed regression in source domain confidence.
87
+ * @default 0.1
88
+ */
89
+ maxSourceConfidenceRegression: number;
90
+ }
91
+ /** Default verification configuration */
92
+ export declare const DEFAULT_VERIFICATION_CONFIG: TransferVerificationConfig;
93
+ /**
94
+ * Verifies cross-domain transfers to prevent regression.
95
+ *
96
+ * The verifier applies a double-gate:
97
+ * Gate 1 (Source Stability): Source domain must not regress beyond tolerance
98
+ * Gate 2 (Target Improvement): Target domain must improve or stay neutral
99
+ *
100
+ * Both gates must pass for the transfer to be approved.
101
+ */
102
+ export declare class TransferVerifier {
103
+ private readonly config;
104
+ constructor(config?: Partial<TransferVerificationConfig>);
105
+ /**
106
+ * Verify that a transfer did not cause regression in either domain.
107
+ *
108
+ * @param result - The transfer result containing before/after performance data
109
+ * @returns Verification result with pass/fail and detailed deltas
110
+ */
111
+ verifyTransfer(result: TransferResultForVerification): VerificationResult;
112
+ /** Get the current verification configuration */
113
+ getConfig(): TransferVerificationConfig;
114
+ }
115
+ /**
116
+ * Create a transfer verifier with the given configuration.
117
+ */
118
+ export declare function createTransferVerifier(config?: Partial<TransferVerificationConfig>): TransferVerifier;
119
+ //# sourceMappingURL=transfer-verification.d.ts.map
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Transfer Verification (Task 2.3)
3
+ *
4
+ * Verifies that cross-domain pattern transfers do not cause regression
5
+ * in either the source or target domain. A transfer is considered valid
6
+ * only when:
7
+ * 1. The target domain improves (or at least does not degrade)
8
+ * 2. The source domain does not regress
9
+ *
10
+ * This double-gate ensures that knowledge sharing is always net-positive.
11
+ *
12
+ * @module integrations/ruvector/transfer-verification
13
+ */
14
+ import { LoggerFactory } from '../../logging/index.js';
15
+ const logger = LoggerFactory.create('transfer-verification');
16
+ /** Default verification configuration */
17
+ export const DEFAULT_VERIFICATION_CONFIG = {
18
+ maxSourceRegression: 0.05,
19
+ minTargetImprovement: 0.0,
20
+ maxSourceConfidenceRegression: 0.1,
21
+ };
22
+ // ============================================================================
23
+ // Transfer Verifier
24
+ // ============================================================================
25
+ /**
26
+ * Verifies cross-domain transfers to prevent regression.
27
+ *
28
+ * The verifier applies a double-gate:
29
+ * Gate 1 (Source Stability): Source domain must not regress beyond tolerance
30
+ * Gate 2 (Target Improvement): Target domain must improve or stay neutral
31
+ *
32
+ * Both gates must pass for the transfer to be approved.
33
+ */
34
+ export class TransferVerifier {
35
+ config;
36
+ constructor(config = {}) {
37
+ this.config = { ...DEFAULT_VERIFICATION_CONFIG, ...config };
38
+ }
39
+ /**
40
+ * Verify that a transfer did not cause regression in either domain.
41
+ *
42
+ * @param result - The transfer result containing before/after performance data
43
+ * @returns Verification result with pass/fail and detailed deltas
44
+ */
45
+ verifyTransfer(result) {
46
+ const sourceDelta = result.sourcePerformanceAfter.successRate -
47
+ result.sourcePerformanceBefore.successRate;
48
+ const targetDelta = result.targetPerformanceAfter.successRate -
49
+ result.targetPerformanceBefore.successRate;
50
+ const sourceConfidenceDelta = result.sourcePerformanceAfter.avgConfidence -
51
+ result.sourcePerformanceBefore.avgConfidence;
52
+ const targetConfidenceDelta = result.targetPerformanceAfter.avgConfidence -
53
+ result.targetPerformanceBefore.avgConfidence;
54
+ // Gate 1: Source domain must not regress beyond tolerance
55
+ const sourceStable = sourceDelta >= -this.config.maxSourceRegression &&
56
+ sourceConfidenceDelta >= -this.config.maxSourceConfidenceRegression;
57
+ // Gate 2: Target domain must improve (or at least not degrade)
58
+ const targetImproved = targetDelta >= this.config.minTargetImprovement;
59
+ // Both gates must pass
60
+ const passed = sourceStable && targetImproved;
61
+ let failureReason;
62
+ if (!passed) {
63
+ const reasons = [];
64
+ if (!sourceStable) {
65
+ reasons.push(`source domain regressed: successRate delta=${sourceDelta.toFixed(4)}, ` +
66
+ `confidence delta=${sourceConfidenceDelta.toFixed(4)}`);
67
+ }
68
+ if (!targetImproved) {
69
+ reasons.push(`target domain did not improve: successRate delta=${targetDelta.toFixed(4)}`);
70
+ }
71
+ failureReason = reasons.join('; ');
72
+ }
73
+ if (!passed) {
74
+ logger.warn('Transfer verification failed', {
75
+ transferId: result.transferId,
76
+ sourceDomain: result.sourceDomain,
77
+ targetDomain: result.targetDomain,
78
+ sourceDelta,
79
+ targetDelta,
80
+ failureReason,
81
+ });
82
+ }
83
+ else {
84
+ logger.debug('Transfer verification passed', {
85
+ transferId: result.transferId,
86
+ sourceDelta,
87
+ targetDelta,
88
+ });
89
+ }
90
+ return {
91
+ passed,
92
+ sourceStable,
93
+ targetImproved,
94
+ sourceDelta,
95
+ targetDelta,
96
+ sourceConfidenceDelta,
97
+ targetConfidenceDelta,
98
+ failureReason,
99
+ };
100
+ }
101
+ /** Get the current verification configuration */
102
+ getConfig() {
103
+ return { ...this.config };
104
+ }
105
+ }
106
+ // ============================================================================
107
+ // Factory
108
+ // ============================================================================
109
+ /**
110
+ * Create a transfer verifier with the given configuration.
111
+ */
112
+ export function createTransferVerifier(config) {
113
+ return new TransferVerifier(config);
114
+ }
115
+ //# sourceMappingURL=transfer-verification.js.map
@@ -10,12 +10,14 @@
10
10
  * @module kernel/hnsw-adapter
11
11
  */
12
12
  import type { IHnswIndexProvider, SearchResult, HnswConfig } from './hnsw-index-provider.js';
13
+ import type { HnswHealthMonitor, HnswHealthReport } from '../integrations/ruvector/hnsw-health-monitor.js';
13
14
  /**
14
15
  * Well-known index names used across the AQE platform.
15
16
  */
16
17
  export type HnswIndexName = 'patterns' | 'qe-memory' | 'learning' | 'coverage';
17
18
  /**
18
- * Adapter that wraps ProgressiveHnswBackend and provides backward-compatible
19
+ * Adapter that wraps ProgressiveHnswBackend (or NativeHnswBackend when
20
+ * the useNativeHNSW feature flag is enabled) and provides backward-compatible
19
21
  * APIs matching the old InMemoryHNSWIndex and RuvectorFlatIndex interfaces.
20
22
  *
21
23
  * This adapter bridges the gap between the new IHnswIndexProvider interface
@@ -23,11 +25,18 @@ export type HnswIndexName = 'patterns' | 'qe-memory' | 'learning' | 'coverage';
23
25
  */
24
26
  export declare class HnswAdapter implements IHnswIndexProvider {
25
27
  private readonly backend;
28
+ private readonly _isNativeBackend;
26
29
  private readonly indexName;
27
30
  /** Maps string keys to numeric IDs (for backward compat with old APIs) */
28
31
  private stringToNumericId;
29
32
  private numericToStringId;
30
33
  private nextAutoId;
34
+ /** Health monitor (lazily created when feature flag is enabled) */
35
+ private healthMonitor;
36
+ private healthMonitorLoaded;
37
+ private operationsSinceLastCheck;
38
+ private healthCheckFrequency;
39
+ private lastHealthReport;
31
40
  constructor(name: string, config?: Partial<HnswConfig>);
32
41
  add(id: number, vector: Float32Array, metadata?: Record<string, unknown>): void;
33
42
  search(query: Float32Array, k: number): SearchResult[];
@@ -68,10 +77,52 @@ export declare class HnswAdapter implements IHnswIndexProvider {
68
77
  * Check whether @ruvector/gnn is available.
69
78
  */
70
79
  isRuvectorAvailable(): boolean;
80
+ /**
81
+ * Check whether this adapter is using the native HNSW backend.
82
+ */
83
+ isNativeBackend(): boolean;
71
84
  /**
72
85
  * Get the index name.
73
86
  */
74
87
  getName(): string;
88
+ /**
89
+ * Set the health check frequency (number of operations between checks).
90
+ * Only applies when the useHnswHealthMonitor feature flag is enabled.
91
+ *
92
+ * @param frequency - Number of add/remove operations between health checks
93
+ */
94
+ setHealthCheckFrequency(frequency: number): void;
95
+ /**
96
+ * Get the health check frequency.
97
+ */
98
+ getHealthCheckFrequency(): number;
99
+ /**
100
+ * Get the last health report, or null if no check has run.
101
+ */
102
+ getLastHealthReport(): HnswHealthReport | null;
103
+ /**
104
+ * Get the health monitor instance, or null if not enabled.
105
+ */
106
+ getHealthMonitor(): HnswHealthMonitor | null;
107
+ /**
108
+ * Conditionally run a health check based on operation count and feature flag.
109
+ * Non-blocking: runs asynchronously to avoid slowing operations.
110
+ */
111
+ private maybeRunHealthCheck;
112
+ /**
113
+ * Lazily load and create the health monitor.
114
+ */
115
+ private ensureHealthMonitor;
116
+ /**
117
+ * Create the appropriate HNSW backend based on feature flags.
118
+ *
119
+ * When useNativeHNSW is enabled, tries to create a NativeHnswBackend.
120
+ * Falls back to ProgressiveHnswBackend if the native binary is unavailable.
121
+ *
122
+ * @param config - HNSW configuration
123
+ * @returns The backend instance and whether it is native
124
+ */
125
+ private static createBackend;
75
126
  /**
76
127
  * Create or retrieve a named HNSW index.
77
128
  *
@@ -10,6 +10,8 @@
10
10
  * @module kernel/hnsw-adapter
11
11
  */
12
12
  import { ProgressiveHnswBackend } from './progressive-hnsw-backend.js';
13
+ import { NativeHnswBackend, NativeHnswUnavailableError } from './native-hnsw-backend.js';
14
+ import { isNativeHNSWEnabled, isHnswHealthMonitorEnabled } from '../integrations/ruvector/feature-flags.js';
13
15
  /**
14
16
  * Default configurations for each named index.
15
17
  */
@@ -51,7 +53,8 @@ const registry = new Map();
51
53
  // HnswAdapter
52
54
  // ============================================================================
53
55
  /**
54
- * Adapter that wraps ProgressiveHnswBackend and provides backward-compatible
56
+ * Adapter that wraps ProgressiveHnswBackend (or NativeHnswBackend when
57
+ * the useNativeHNSW feature flag is enabled) and provides backward-compatible
55
58
  * APIs matching the old InMemoryHNSWIndex and RuvectorFlatIndex interfaces.
56
59
  *
57
60
  * This adapter bridges the gap between the new IHnswIndexProvider interface
@@ -59,21 +62,32 @@ const registry = new Map();
59
62
  */
60
63
  export class HnswAdapter {
61
64
  backend;
65
+ _isNativeBackend;
62
66
  indexName;
63
67
  /** Maps string keys to numeric IDs (for backward compat with old APIs) */
64
68
  stringToNumericId = new Map();
65
69
  numericToStringId = new Map();
66
70
  nextAutoId = 0;
71
+ /** Health monitor (lazily created when feature flag is enabled) */
72
+ healthMonitor = null;
73
+ healthMonitorLoaded = false;
74
+ operationsSinceLastCheck = 0;
75
+ healthCheckFrequency = 100;
76
+ lastHealthReport = null;
67
77
  constructor(name, config) {
68
78
  this.indexName = name;
69
79
  const defaults = INDEX_DEFAULTS[name] ?? {};
70
- this.backend = new ProgressiveHnswBackend({ ...defaults, ...config });
80
+ const mergedConfig = { ...defaults, ...config };
81
+ const { backend, isNative } = HnswAdapter.createBackend(mergedConfig);
82
+ this.backend = backend;
83
+ this._isNativeBackend = isNative;
71
84
  }
72
85
  // ============================================================================
73
86
  // IHnswIndexProvider implementation
74
87
  // ============================================================================
75
88
  add(id, vector, metadata) {
76
89
  this.backend.add(id, vector, metadata);
90
+ this.maybeRunHealthCheck();
77
91
  }
78
92
  search(query, k) {
79
93
  const start = performance.now();
@@ -154,7 +168,7 @@ export class HnswAdapter {
154
168
  * Clear all vectors from the index.
155
169
  */
156
170
  clear() {
157
- this.backend.clear();
171
+ this.backend.clear?.();
158
172
  this.stringToNumericId.clear();
159
173
  this.numericToStringId.clear();
160
174
  this.nextAutoId = 0;
@@ -163,7 +177,20 @@ export class HnswAdapter {
163
177
  * Check whether @ruvector/gnn is available.
164
178
  */
165
179
  isRuvectorAvailable() {
166
- return this.backend.isRuvectorAvailable();
180
+ if (this.backend instanceof ProgressiveHnswBackend) {
181
+ return this.backend.isRuvectorAvailable();
182
+ }
183
+ // NativeHnswBackend uses @ruvector/router VectorDb
184
+ if (this.backend instanceof NativeHnswBackend) {
185
+ return this.backend.isNativeAvailable();
186
+ }
187
+ return false;
188
+ }
189
+ /**
190
+ * Check whether this adapter is using the native HNSW backend.
191
+ */
192
+ isNativeBackend() {
193
+ return this._isNativeBackend;
167
194
  }
168
195
  /**
169
196
  * Get the index name.
@@ -172,6 +199,114 @@ export class HnswAdapter {
172
199
  return this.indexName;
173
200
  }
174
201
  // ============================================================================
202
+ // Health Monitoring
203
+ // ============================================================================
204
+ /**
205
+ * Set the health check frequency (number of operations between checks).
206
+ * Only applies when the useHnswHealthMonitor feature flag is enabled.
207
+ *
208
+ * @param frequency - Number of add/remove operations between health checks
209
+ */
210
+ setHealthCheckFrequency(frequency) {
211
+ this.healthCheckFrequency = Math.max(1, frequency);
212
+ }
213
+ /**
214
+ * Get the health check frequency.
215
+ */
216
+ getHealthCheckFrequency() {
217
+ return this.healthCheckFrequency;
218
+ }
219
+ /**
220
+ * Get the last health report, or null if no check has run.
221
+ */
222
+ getLastHealthReport() {
223
+ return this.lastHealthReport;
224
+ }
225
+ /**
226
+ * Get the health monitor instance, or null if not enabled.
227
+ */
228
+ getHealthMonitor() {
229
+ return this.healthMonitor;
230
+ }
231
+ /**
232
+ * Conditionally run a health check based on operation count and feature flag.
233
+ * Non-blocking: runs asynchronously to avoid slowing operations.
234
+ */
235
+ maybeRunHealthCheck() {
236
+ if (!isHnswHealthMonitorEnabled())
237
+ return;
238
+ this.operationsSinceLastCheck++;
239
+ if (this.operationsSinceLastCheck < this.healthCheckFrequency)
240
+ return;
241
+ this.operationsSinceLastCheck = 0;
242
+ this.ensureHealthMonitor();
243
+ if (this.healthMonitor) {
244
+ try {
245
+ this.lastHealthReport = this.healthMonitor.checkHealth(this.backend);
246
+ if (!this.lastHealthReport.healthy) {
247
+ console.warn(`[HNSW-Health] Index "${this.indexName}" health check failed: ` +
248
+ `${this.lastHealthReport.alerts.length} alert(s). ` +
249
+ `Coherence: ${this.lastHealthReport.metrics.coherenceScore.toFixed(3)}`);
250
+ }
251
+ }
252
+ catch (err) {
253
+ // Health checks must never break normal operations
254
+ console.warn(`[HNSW-Health] Health check error for "${this.indexName}":`, err);
255
+ }
256
+ }
257
+ }
258
+ /**
259
+ * Lazily load and create the health monitor.
260
+ */
261
+ ensureHealthMonitor() {
262
+ if (this.healthMonitorLoaded)
263
+ return;
264
+ this.healthMonitorLoaded = true;
265
+ try {
266
+ // Dynamic import to avoid circular dependencies and keep startup fast
267
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
268
+ const mod = require('../integrations/ruvector/hnsw-health-monitor.js');
269
+ this.healthMonitor = mod.createHnswHealthMonitor();
270
+ }
271
+ catch (err) {
272
+ // Module not available, health monitoring disabled
273
+ if (process.env.DEBUG)
274
+ console.debug('[HNSW-Health] Monitor module unavailable:', err instanceof Error ? err.message : err);
275
+ this.healthMonitor = null;
276
+ }
277
+ }
278
+ // ============================================================================
279
+ // Backend Selection
280
+ // ============================================================================
281
+ /**
282
+ * Create the appropriate HNSW backend based on feature flags.
283
+ *
284
+ * When useNativeHNSW is enabled, tries to create a NativeHnswBackend.
285
+ * Falls back to ProgressiveHnswBackend if the native binary is unavailable.
286
+ *
287
+ * @param config - HNSW configuration
288
+ * @returns The backend instance and whether it is native
289
+ */
290
+ static createBackend(config) {
291
+ if (isNativeHNSWEnabled()) {
292
+ try {
293
+ const native = new NativeHnswBackend(config);
294
+ return { backend: native, isNative: true };
295
+ }
296
+ catch (err) {
297
+ if (err instanceof NativeHnswUnavailableError) {
298
+ // Expected: native binary not available, fall back silently
299
+ console.info(`[HNSW] Native backend unavailable, falling back to JS: ${err.message}`);
300
+ }
301
+ else {
302
+ // Unexpected error, log warning and fall back
303
+ console.warn(`[HNSW] Unexpected error creating native backend, falling back to JS:`, err);
304
+ }
305
+ }
306
+ }
307
+ return { backend: new ProgressiveHnswBackend(config), isNative: false };
308
+ }
309
+ // ============================================================================
175
310
  // Factory
176
311
  // ============================================================================
177
312
  /**
@@ -86,5 +86,10 @@ export interface IHnswIndexProvider {
86
86
  * For approximate HNSW this returns an estimate based on configuration.
87
87
  */
88
88
  recall(): number;
89
+ /**
90
+ * Clear all vectors from the index.
91
+ * Optional: implementations that don't support clearing can omit this.
92
+ */
93
+ clear?(): void;
89
94
  }
90
95
  //# sourceMappingURL=hnsw-index-provider.d.ts.map