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,512 @@
1
+ /**
2
+ * Coherence-Gated Agent Actions (Task 3.2, ADR-083)
3
+ *
4
+ * Evaluates agent actions through three stacked filters with
5
+ * heuristic scoring with CUSUM drift detection:
6
+ * 1. Structural filter: Action type familiarity and context completeness check
7
+ * 2. Shift filter: Confidence-risk alignment with CUSUM change detection
8
+ * 3. Evidence filter: Multiplicative context evidence accumulation score
9
+ *
10
+ * Decisions: PERMIT / DEFER / DENY
11
+ * - PERMIT: all filters pass (scores above permit thresholds)
12
+ * - DEFER: one or more filters marginal (needs human review)
13
+ * - DENY: one or more filters clearly fail
14
+ *
15
+ * Advisory mode by default: logs decisions but does not block execution.
16
+ *
17
+ * TypeScript implementation (no native package exists for this —
18
+ * heuristic filters work well without native computation).
19
+ *
20
+ * @module coordination/coherence-action-gate
21
+ * @see ADR-083-coherence-gated-agent-actions.md
22
+ */
23
+ import { createLogger } from '../logging/logger-factory.js';
24
+ import { getRuVectorFeatureFlags } from '../integrations/ruvector/feature-flags.js';
25
+ const logger = createLogger('CoherenceActionGate');
26
+ // ============================================================================
27
+ // Constants
28
+ // ============================================================================
29
+ const DEFAULT_THRESHOLDS = {
30
+ structuralPermit: 0.4,
31
+ structuralDeny: 0.2,
32
+ shiftPermit: 0.5,
33
+ shiftDeny: 0.25,
34
+ evidencePermit: 0.5,
35
+ evidenceDeny: 0.2,
36
+ combinedPermit: 0.5,
37
+ combinedDeny: 0.25,
38
+ };
39
+ /** Weights for combining filter scores */
40
+ const FILTER_WEIGHTS = {
41
+ structural: 0.3,
42
+ shift: 0.35,
43
+ evidence: 0.35,
44
+ };
45
+ /** Risk level multipliers (higher risk = stricter evaluation) */
46
+ const RISK_MULTIPLIERS = {
47
+ low: 1.0,
48
+ medium: 0.9,
49
+ high: 0.75,
50
+ critical: 0.6,
51
+ };
52
+ /** Maximum evaluations to retain for statistics */
53
+ const MAX_EVALUATION_HISTORY = 1000;
54
+ // ============================================================================
55
+ // CoherenceActionGate Implementation
56
+ // ============================================================================
57
+ /**
58
+ * Three-filter coherence gate for agent action evaluation.
59
+ *
60
+ * Evaluates whether an agent action should proceed by running it through
61
+ * structural, shift, and evidence filters. Advisory mode by default.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const gate = new CoherenceActionGate();
66
+ * const evaluation = gate.evaluate({
67
+ * type: 'generate-test',
68
+ * domain: 'test-generation',
69
+ * confidence: 0.85,
70
+ * context: { filePath: 'src/service.ts' },
71
+ * riskLevel: 'medium',
72
+ * });
73
+ * if (evaluation.decision === 'DENY') {
74
+ * console.warn('Action denied:', evaluation.reasoning);
75
+ * }
76
+ * ```
77
+ */
78
+ export class CoherenceActionGate {
79
+ thresholds;
80
+ advisoryMode;
81
+ nativeAvailable = null;
82
+ // Statistics tracking
83
+ evaluationHistory = [];
84
+ permitCount = 0;
85
+ deferCount = 0;
86
+ denyCount = 0;
87
+ totalCombinedScore = 0;
88
+ totalStructuralScore = 0;
89
+ totalShiftScore = 0;
90
+ totalEvidenceScore = 0;
91
+ // CUSUM state for shift detection
92
+ cusumHigh = 0;
93
+ cusumLow = 0;
94
+ cusumMean = 0.7; // Target mean confidence
95
+ cusumK = 0.05; // Allowance parameter (half the shift to detect)
96
+ cusumH = 4.0; // Decision threshold
97
+ cusumSampleCount = 0;
98
+ cusumAlertActive = false;
99
+ constructor(options) {
100
+ this.advisoryMode = options?.advisory ?? true;
101
+ this.thresholds = {
102
+ ...DEFAULT_THRESHOLDS,
103
+ ...options?.thresholds,
104
+ };
105
+ }
106
+ // ==========================================================================
107
+ // Core API
108
+ // ==========================================================================
109
+ /**
110
+ * Evaluate an agent action through the three-filter pipeline.
111
+ *
112
+ * @param action - The agent action to evaluate
113
+ * @returns Full evaluation with decision, scores, and reasoning
114
+ */
115
+ evaluate(action) {
116
+ const structuralScore = this.computeStructuralScore(action);
117
+ const shiftScore = this.computeShiftScore(action);
118
+ const evidenceScore = this.computeEvidenceScore(action);
119
+ const combinedScore = structuralScore * FILTER_WEIGHTS.structural +
120
+ shiftScore * FILTER_WEIGHTS.shift +
121
+ evidenceScore * FILTER_WEIGHTS.evidence;
122
+ // Apply risk multiplier
123
+ const riskMultiplier = RISK_MULTIPLIERS[action.riskLevel] ?? 1.0;
124
+ const adjustedCombined = combinedScore * riskMultiplier;
125
+ const decision = this.computeDecision(structuralScore, shiftScore, evidenceScore, adjustedCombined);
126
+ const reasoning = this.buildReasoning(action, decision, structuralScore, shiftScore, evidenceScore, adjustedCombined);
127
+ const evaluation = {
128
+ decision,
129
+ structuralScore,
130
+ shiftScore,
131
+ evidenceScore,
132
+ combinedScore: adjustedCombined,
133
+ reasoning,
134
+ advisory: this.advisoryMode,
135
+ };
136
+ this.recordEvaluation(evaluation);
137
+ logger.debug('Action gate evaluation', {
138
+ action: action.type,
139
+ domain: action.domain,
140
+ decision,
141
+ combinedScore: adjustedCombined,
142
+ advisory: this.advisoryMode,
143
+ });
144
+ return evaluation;
145
+ }
146
+ /**
147
+ * Get aggregate statistics for observability.
148
+ */
149
+ getStatistics() {
150
+ const total = this.evaluationHistory.length;
151
+ return {
152
+ totalEvaluations: total,
153
+ permitCount: this.permitCount,
154
+ deferCount: this.deferCount,
155
+ denyCount: this.denyCount,
156
+ averageCombinedScore: total > 0 ? this.totalCombinedScore / total : 0,
157
+ averageStructuralScore: total > 0 ? this.totalStructuralScore / total : 0,
158
+ averageShiftScore: total > 0 ? this.totalShiftScore / total : 0,
159
+ averageEvidenceScore: total > 0 ? this.totalEvidenceScore / total : 0,
160
+ advisoryMode: this.advisoryMode,
161
+ };
162
+ }
163
+ /**
164
+ * Update thresholds at runtime.
165
+ *
166
+ * @param config - Partial threshold overrides
167
+ */
168
+ configureThresholds(config) {
169
+ this.thresholds = {
170
+ ...this.thresholds,
171
+ ...config,
172
+ };
173
+ logger.info('Action gate thresholds updated', {
174
+ thresholds: this.thresholds,
175
+ });
176
+ }
177
+ /**
178
+ * Get the current threshold configuration.
179
+ */
180
+ getThresholds() {
181
+ return { ...this.thresholds };
182
+ }
183
+ /**
184
+ * Whether advisory mode is active.
185
+ */
186
+ isAdvisory() {
187
+ return this.advisoryMode;
188
+ }
189
+ /**
190
+ * Get the evaluation history (bounded).
191
+ */
192
+ getEvaluationHistory() {
193
+ return [...this.evaluationHistory];
194
+ }
195
+ /**
196
+ * Clear evaluation history and reset statistics.
197
+ */
198
+ resetStatistics() {
199
+ this.evaluationHistory = [];
200
+ this.permitCount = 0;
201
+ this.deferCount = 0;
202
+ this.denyCount = 0;
203
+ this.totalCombinedScore = 0;
204
+ this.totalStructuralScore = 0;
205
+ this.totalShiftScore = 0;
206
+ this.totalEvidenceScore = 0;
207
+ this.resetCusum();
208
+ }
209
+ /**
210
+ * Reset CUSUM change detection state.
211
+ */
212
+ resetCusum() {
213
+ this.cusumHigh = 0;
214
+ this.cusumLow = 0;
215
+ this.cusumAlertActive = false;
216
+ this.cusumSampleCount = 0;
217
+ }
218
+ // ==========================================================================
219
+ // Filter 1: Structural
220
+ // ==========================================================================
221
+ /**
222
+ * Structural filter: Action type familiarity and context completeness check.
223
+ *
224
+ * Considers:
225
+ * - Action type familiarity (known vs unknown action types)
226
+ * - Domain alignment (is the action appropriate for this domain?)
227
+ * - Context completeness (does the action have sufficient context?)
228
+ *
229
+ * Higher score = better structural fit.
230
+ */
231
+ computeStructuralScore(action) {
232
+ let score = 0.5; // Baseline
233
+ // Action type familiarity - known action types score higher
234
+ const knownActionTypes = [
235
+ 'generate-test', 'modify-code', 'analyze-coverage',
236
+ 'scan-security', 'assess-quality', 'validate-contracts',
237
+ 'test-accessibility', 'execute-tests', 'index-code',
238
+ 'predict-defects', 'validate-requirements', 'deploy',
239
+ 'run-chaos', 'optimize-learning',
240
+ ];
241
+ if (knownActionTypes.includes(action.type)) {
242
+ score += 0.2;
243
+ }
244
+ // Domain alignment - check if context references this domain
245
+ const contextStr = JSON.stringify(action.context).toLowerCase();
246
+ if (contextStr.includes(action.domain.toLowerCase())) {
247
+ score += 0.15;
248
+ }
249
+ // Context completeness - more context keys = more structural support
250
+ const contextKeys = Object.keys(action.context);
251
+ if (contextKeys.length >= 3) {
252
+ score += 0.15;
253
+ }
254
+ else if (contextKeys.length >= 1) {
255
+ score += 0.05;
256
+ }
257
+ return Math.min(Math.max(score, 0), 1);
258
+ }
259
+ // ==========================================================================
260
+ // Filter 2: Shift Detection
261
+ // ==========================================================================
262
+ /**
263
+ * Shift filter: Confidence-risk alignment with CUSUM change detection.
264
+ *
265
+ * Considers:
266
+ * - Confidence level (low confidence suggests distributional shift)
267
+ * - Risk level alignment (high risk with low confidence = shift)
268
+ * - Context consistency (presence of contradictory signals)
269
+ * - CUSUM cumulative sum control chart for persistent drift detection
270
+ *
271
+ * Higher score = less distributional shift detected.
272
+ */
273
+ computeShiftScore(action) {
274
+ let score = action.confidence; // Start with agent's own confidence
275
+ // Risk-confidence alignment penalty
276
+ // High risk actions with low confidence suggest distributional shift
277
+ const riskValues = {
278
+ low: 0.25, medium: 0.5, high: 0.75, critical: 1.0,
279
+ };
280
+ const riskValue = riskValues[action.riskLevel] ?? 0.5;
281
+ const riskConfidenceGap = Math.max(0, riskValue - action.confidence);
282
+ // Penalize when risk is high but confidence is low
283
+ score -= riskConfidenceGap * 0.3;
284
+ // Context staleness check - look for timestamp or freshness signals
285
+ const context = action.context;
286
+ if (context.stale === true || context.outdated === true) {
287
+ score -= 0.3;
288
+ }
289
+ // If context has explicit shift markers
290
+ if (context.distributionShift === true || context.contextChanged === true) {
291
+ score -= 0.4;
292
+ }
293
+ // CUSUM change detection
294
+ this.cusumSampleCount++;
295
+ const x = action.confidence;
296
+ this.cusumHigh = Math.max(0, this.cusumHigh + (x - this.cusumMean) - this.cusumK);
297
+ this.cusumLow = Math.max(0, this.cusumLow - (x - this.cusumMean) - this.cusumK);
298
+ if (this.cusumHigh > this.cusumH || this.cusumLow > this.cusumH) {
299
+ // Persistent drift detected
300
+ score -= 0.2;
301
+ if (!this.cusumAlertActive) {
302
+ this.cusumAlertActive = true;
303
+ logger.warn('CUSUM shift detected', { cusumHigh: this.cusumHigh, cusumLow: this.cusumLow });
304
+ }
305
+ }
306
+ else {
307
+ this.cusumAlertActive = false;
308
+ }
309
+ return Math.min(Math.max(score, 0), 1);
310
+ }
311
+ // ==========================================================================
312
+ // Filter 3: Evidence (Multiplicative Accumulation)
313
+ // ==========================================================================
314
+ /**
315
+ * Evidence filter: Multiplicative context evidence accumulation score.
316
+ *
317
+ * Uses multiplicative accumulation where each piece of evidence
318
+ * compounds on the previous score. Multiple negative signals compound
319
+ * more aggressively than additive scoring.
320
+ *
321
+ * Considers:
322
+ * - Supporting evidence in context (test results, coverage data, etc.)
323
+ * - Evidence against (errors, failures, warnings)
324
+ * - Risk-level specific evidence requirements
325
+ *
326
+ * Higher score = more evidence supporting the action.
327
+ */
328
+ computeEvidenceScore(action) {
329
+ let evidence = 0.5; // Start at neutral
330
+ const context = action.context;
331
+ // Positive evidence signals - multiplicative accumulation
332
+ const positiveKeys = [
333
+ 'testResults', 'coverageData', 'securityScan',
334
+ 'qualityReport', 'peerReview', 'analysisResult',
335
+ 'validationPassed', 'precedent', 'historicalSuccess',
336
+ ];
337
+ for (const key of positiveKeys) {
338
+ if (context[key] !== undefined && context[key] !== null) {
339
+ evidence *= (1 + 0.15); // Each positive signal boosts by 15%
340
+ }
341
+ }
342
+ // Negative evidence signals - multiplicative reduction
343
+ const negativeKeys = [
344
+ 'errors', 'failures', 'warnings', 'regressions',
345
+ 'conflictingResults', 'noTestCoverage',
346
+ ];
347
+ for (const key of negativeKeys) {
348
+ if (context[key] !== undefined && context[key] !== null) {
349
+ evidence *= (1 - 0.18); // Each negative signal reduces by 18%
350
+ }
351
+ }
352
+ // Action-specific evidence requirements
353
+ if (action.riskLevel === 'critical' || action.riskLevel === 'high') {
354
+ // High-risk actions need more evidence - raise the bar
355
+ if (!context.testResults && !context.peerReview) {
356
+ evidence -= 0.15;
357
+ }
358
+ }
359
+ // Bonus for explicit evidence count
360
+ if (typeof context.evidenceCount === 'number') {
361
+ const evidenceCount = context.evidenceCount;
362
+ evidence += Math.min(evidenceCount * 0.05, 0.2);
363
+ }
364
+ return Math.min(Math.max(evidence, 0), 1);
365
+ }
366
+ // ==========================================================================
367
+ // Decision Logic
368
+ // ==========================================================================
369
+ /**
370
+ * Determine the final PERMIT/DEFER/DENY decision from filter scores.
371
+ *
372
+ * Logic:
373
+ * - DENY if any individual filter is below its deny threshold
374
+ * - DENY if combined score is below combined deny threshold
375
+ * - PERMIT if all filters are above their permit thresholds AND
376
+ * combined score is above combined permit threshold
377
+ * - DEFER otherwise (marginal - needs human review)
378
+ */
379
+ computeDecision(structural, shift, evidence, combined) {
380
+ // Check for clear DENY
381
+ if (structural < this.thresholds.structuralDeny)
382
+ return 'DENY';
383
+ if (shift < this.thresholds.shiftDeny)
384
+ return 'DENY';
385
+ if (evidence < this.thresholds.evidenceDeny)
386
+ return 'DENY';
387
+ if (combined < this.thresholds.combinedDeny)
388
+ return 'DENY';
389
+ // Check for clear PERMIT
390
+ if (structural >= this.thresholds.structuralPermit &&
391
+ shift >= this.thresholds.shiftPermit &&
392
+ evidence >= this.thresholds.evidencePermit &&
393
+ combined >= this.thresholds.combinedPermit) {
394
+ return 'PERMIT';
395
+ }
396
+ // Marginal - needs review
397
+ return 'DEFER';
398
+ }
399
+ // ==========================================================================
400
+ // Reasoning & Statistics
401
+ // ==========================================================================
402
+ /**
403
+ * Build a human-readable reasoning string.
404
+ */
405
+ buildReasoning(action, decision, structural, shift, evidence, combined) {
406
+ const parts = [];
407
+ parts.push(`Decision: ${decision} for ${action.type} (${action.domain}).`);
408
+ parts.push(`Scores: structural=${structural.toFixed(2)}, ` +
409
+ `shift=${shift.toFixed(2)}, evidence=${evidence.toFixed(2)}, ` +
410
+ `combined=${combined.toFixed(2)}.`);
411
+ if (decision === 'DENY') {
412
+ if (structural < this.thresholds.structuralDeny) {
413
+ parts.push('Structural filter failed: action does not fit codebase graph.');
414
+ }
415
+ if (shift < this.thresholds.shiftDeny) {
416
+ parts.push('Shift filter failed: significant context distribution shift detected.');
417
+ }
418
+ if (evidence < this.thresholds.evidenceDeny) {
419
+ parts.push('Evidence filter failed: insufficient evidence to justify action.');
420
+ }
421
+ if (combined < this.thresholds.combinedDeny) {
422
+ parts.push('Combined score below minimum threshold.');
423
+ }
424
+ }
425
+ else if (decision === 'DEFER') {
426
+ const marginalFilters = [];
427
+ if (structural < this.thresholds.structuralPermit)
428
+ marginalFilters.push('structural');
429
+ if (shift < this.thresholds.shiftPermit)
430
+ marginalFilters.push('shift');
431
+ if (evidence < this.thresholds.evidencePermit)
432
+ marginalFilters.push('evidence');
433
+ if (marginalFilters.length > 0) {
434
+ parts.push(`Marginal filters: ${marginalFilters.join(', ')}. Human review recommended.`);
435
+ }
436
+ }
437
+ if (this.advisoryMode) {
438
+ parts.push('(Advisory mode: decision logged only, not enforced.)');
439
+ }
440
+ return parts.join(' ');
441
+ }
442
+ /**
443
+ * Record an evaluation for statistics tracking.
444
+ */
445
+ recordEvaluation(evaluation) {
446
+ this.evaluationHistory.push(evaluation);
447
+ if (this.evaluationHistory.length > MAX_EVALUATION_HISTORY) {
448
+ this.evaluationHistory = this.evaluationHistory.slice(-MAX_EVALUATION_HISTORY);
449
+ }
450
+ this.totalCombinedScore += evaluation.combinedScore;
451
+ this.totalStructuralScore += evaluation.structuralScore;
452
+ this.totalShiftScore += evaluation.shiftScore;
453
+ this.totalEvidenceScore += evaluation.evidenceScore;
454
+ switch (evaluation.decision) {
455
+ case 'PERMIT':
456
+ this.permitCount++;
457
+ break;
458
+ case 'DEFER':
459
+ this.deferCount++;
460
+ break;
461
+ case 'DENY':
462
+ this.denyCount++;
463
+ break;
464
+ }
465
+ }
466
+ }
467
+ // ============================================================================
468
+ // Factory
469
+ // ============================================================================
470
+ /**
471
+ * Create a CoherenceActionGate instance.
472
+ *
473
+ * @param options - Optional configuration
474
+ * @returns A new CoherenceActionGate instance
475
+ */
476
+ export function createCoherenceActionGate(options) {
477
+ return new CoherenceActionGate(options);
478
+ }
479
+ // ============================================================================
480
+ // Task Executor Integration Helper
481
+ // ============================================================================
482
+ /**
483
+ * Evaluate a task execution action through the coherence gate.
484
+ *
485
+ * This is the integration point called by the task executor. It checks
486
+ * the feature flag, creates an AgentAction from task metadata, and
487
+ * returns the evaluation result.
488
+ *
489
+ * @param taskType - The type of task being executed
490
+ * @param domain - The domain the task targets
491
+ * @param confidence - Confidence level (0-1)
492
+ * @param riskLevel - Risk classification
493
+ * @param context - Additional context
494
+ * @param gate - Optional pre-existing gate instance (for reuse)
495
+ * @returns The gate evaluation, or null if the feature flag is off
496
+ */
497
+ export function evaluateTaskAction(taskType, domain, confidence, riskLevel, context, gate) {
498
+ const flags = getRuVectorFeatureFlags();
499
+ if (!flags.useCoherenceActionGate) {
500
+ return null;
501
+ }
502
+ const effectiveGate = gate ?? new CoherenceActionGate();
503
+ const action = {
504
+ type: taskType,
505
+ domain,
506
+ confidence,
507
+ context,
508
+ riskLevel,
509
+ };
510
+ return effectiveGate.evaluate(action);
511
+ }
512
+ //# sourceMappingURL=coherence-action-gate.js.map
@@ -33,4 +33,8 @@ export type { FleetId, FederatedService, FederatedMessage, FederatedMessageType,
33
33
  export { DynamicScaler, createDynamicScaler, DEFAULT_SCALING_POLICY, DEFAULT_DYNAMIC_SCALING_CONFIG, } from './dynamic-scaling';
34
34
  export type { WorkloadMetrics, ScalingDecision, ScalingAction, ScalingPolicy, ScalingEvent, ScalerStats, DynamicScalingConfig, ScaleExecutor, } from './dynamic-scaling';
35
35
  export * from './mixins';
36
+ export * from './behavior-tree';
37
+ export type { BehaviorTreeExecutionResult } from './workflow-orchestrator';
38
+ export { ReasoningQEC, createReasoningQEC, processReasoning, DEFAULT_QEC_CONFIG, } from './reasoning-qec';
39
+ export type { ReasoningProblem, ReasoningPath, ReasoningStep, Syndrome, CorrectedReasoning, CorrectionEntry, ValidationResult, ValidationIssue, ReasoningQECConfig, } from './reasoning-qec';
36
40
  //# sourceMappingURL=index.d.ts.map
@@ -93,4 +93,12 @@ export { DynamicScaler, createDynamicScaler, DEFAULT_SCALING_POLICY, DEFAULT_DYN
93
93
  // Coordination Mixins (CONSENSUS-MIXIN-001)
94
94
  // ============================================================================
95
95
  export * from './mixins';
96
+ // ============================================================================
97
+ // Behavior Tree Orchestration (Task 4.4: RuVector Integration)
98
+ // ============================================================================
99
+ export * from './behavior-tree';
100
+ // ============================================================================
101
+ // Reasoning QEC (Task 4.5: Quantum Error Correction for AI Reasoning)
102
+ // ============================================================================
103
+ export { ReasoningQEC, createReasoningQEC, processReasoning, DEFAULT_QEC_CONFIG, } from './reasoning-qec';
96
104
  //# sourceMappingURL=index.js.map