/** * QA Orchestrator Agent * * Coordination layer on top of QualityGateAgent and ComplianceMonitor. * Provides: * 1. Scenario replay — re-run blackboard entries through quality gates * 2. Feedback loop — route rejections back to agents with suggested fixes * 3. Regression tracker — historical quality metrics over time * 4. Cross-agent consistency — detect contradictions in multi-agent output * * @module lib/qa-orchestrator */ import { QualityGateAgent, type GateDecision, type AIReviewCallback, type ValidationConfig } from './blackboard-validator'; import { ComplianceMonitor, type ComplianceMonitorOptions } from './compliance-monitor'; /** A recorded blackboard entry that can be replayed through the QA pipeline. */ export interface QAScenario { /** Unique scenario identifier */ id: string; /** Blackboard key */ key: string; /** The value that was (or would be) written */ value: unknown; /** Agent that produced the value */ sourceAgent: string; /** Optional metadata carried through gating */ metadata?: Record; /** Minimum acceptable quality score (overrides global threshold) */ minScore?: number; } /** Result of running a single scenario through the QA pipeline. */ export interface QAScenarioResult { scenarioId: string; decision: GateDecision; score: number; passed: boolean; issues: string[]; feedbackRouted: boolean; /** Non-null when feedback was routed back to the agent */ feedbackPayload?: QAFeedback; } /** Structured feedback sent back to the originating agent. */ export interface QAFeedback { scenarioId: string; sourceAgent: string; key: string; decision: GateDecision; score: number; issues: string[]; suggestedFixes: string[]; retryCount: number; } /** A snapshot of quality metrics at a point in time. */ export interface QASnapshot { timestamp: string; gateMetrics: Readonly<{ totalChecked: number; approved: number; rejected: number; quarantined: number; aiReviewed: number; }>; complianceViolations: number; violationsByType: Record; violationsByAgent: Record; scenariosRun: number; scenarioPassRate: number; } /** Options for creating a QAOrchestratorAgent instance. */ export interface QAOrchestratorOptions { /** Quality gate configuration */ qualityThreshold?: number; autoRejectThreshold?: number; validationConfig?: Partial; aiReviewCallback?: AIReviewCallback; /** Compliance monitor configuration */ complianceOptions?: ComplianceMonitorOptions; /** Feedback loop settings */ maxRetries?: number; /** Callback invoked when a rejection should be routed back to an agent */ onFeedback?: (feedback: QAFeedback) => void | Promise; /** Consistency checker: given two values for the same key, return true if contradictory */ contradictionDetector?: (a: unknown, b: unknown) => boolean; } /** Detected contradiction between two agents writing the same key. */ export interface Contradiction { key: string; agentA: string; agentB: string; valueA: unknown; valueB: unknown; detectedAt: string; } /** Aggregate result of running a full test harness. */ export interface QAHarnessResult { total: number; passed: number; failed: number; passRate: number; results: QAScenarioResult[]; contradictions: Contradiction[]; snapshot: QASnapshot; } /** * QA Orchestrator Agent — coordinates quality gating, compliance monitoring, * feedback routing, regression tracking, and cross-agent consistency checks. * * @example * ```typescript * const qa = new QAOrchestratorAgent({ * qualityThreshold: 0.7, * maxRetries: 2, * onFeedback: (fb) => console.log('Route to agent:', fb), * }); * * const result = await qa.runScenario({ * id: 'test-1', key: 'analysis', value: { findings: [...] }, * sourceAgent: 'analyst', * }); * ``` */ export declare class QAOrchestratorAgent { private readonly gate; private readonly compliance; private readonly maxRetries; private readonly onFeedback?; private readonly contradictionDetector; /** Historical snapshots for regression tracking */ private readonly history; /** Track retry counts per scenario */ private readonly retryCounts; /** Track last-seen value per key+agent for contradiction detection */ private readonly agentOutputs; constructor(options?: QAOrchestratorOptions); /** * Run a single scenario through the two-layer quality gate. * If the entry is rejected or quarantined and a feedback callback is * configured, structured feedback is routed back to the source agent. */ runScenario(scenario: QAScenario): Promise; /** * Run a batch of scenarios and collect aggregate results, contradictions, * and a quality snapshot. */ runHarness(scenarios: QAScenario[]): Promise; /** * Take an explicit quality snapshot and store it in history. * Called automatically after `runHarness()`, but can also be called manually. */ takeSnapshot(scenariosRun?: number, scenariosPassed?: number): QASnapshot; /** * Get all historical quality snapshots for trend analysis. */ getHistory(): ReadonlyArray>; /** * Compare the latest two snapshots and return a regression report. * Returns null if fewer than two snapshots exist. */ getRegressionReport(): RegressionReport | null; /** * Detect contradictions across agents that wrote to the same blackboard key. */ detectContradictions(): Contradiction[]; /** Access the underlying QualityGateAgent for direct configuration. */ getQualityGate(): QualityGateAgent; /** Access the underlying ComplianceMonitor for direct configuration. */ getComplianceMonitor(): ComplianceMonitor; /** Get current gate metrics without taking a full snapshot. */ getMetrics(): Readonly<{ totalChecked: number; approved: number; rejected: number; quarantined: number; aiReviewed: number; }>; /** Get the number of remaining retries for a scenario. */ getRetriesRemaining(scenarioId: string): number; /** Reset retry count for a scenario (e.g., after manual fix). */ resetRetries(scenarioId: string): void; /** Clear all tracked agent outputs (for fresh contradiction detection). */ clearOutputTracking(): void; private trackAgentOutput; private extractSuggestedFixes; } /** Comparison between two consecutive quality snapshots. */ export interface RegressionReport { from: string; to: string; /** Positive = improvement, negative = regression */ passRateDelta: number; /** Positive = more violations (worse), negative = fewer (better) */ complianceDelta: number; /** Positive = higher approval rate (better) */ approvalRateDelta: number; /** True if any metric regressed */ regressed: boolean; } //# sourceMappingURL=qa-orchestrator.d.ts.map