import { UnifiedOrchestrator, type ExecutionResult, type Finding, type OperationReport } from './unifiedOrchestrator.js';
import { type RankedCandidate } from './dualTournament.js';
export type RepoUpgradeMode = 'single-continuous' | 'dual-rl-continuous' | 'dual-rl-tournament';
export type UpgradeVariant = 'primary' | 'refiner';
/**
 * Reward signal components for multi-objective RL scoring.
 * Each signal is normalized to [0, 1] range.
 */
export interface RewardSignals {
    /** Did the execution complete without errors? (0 or 1) */
    executionSuccess: number;
    /** Did tests pass? (0-1, partial credit for some passing) */
    testsPassed: number;
    /** Did lint/type checks pass? (0-1) */
    staticAnalysis: number;
    /** Code quality metrics (complexity reduction, no new warnings) */
    codeQuality: number;
    /** How minimal/surgical were the changes? (inverse of blast radius) */
    blastRadius: number;
    /** Confidence from LLM self-assessment keywords */
    selfAssessment: number;
    /** Bonus for faster execution (relative to baseline) */
    speedBonus: number;
}
/**
 * Weights for combining reward signals into final score.
 * Tuned for safe, high-quality upgrades.
 */
export interface RewardWeights {
    executionSuccess: number;
    testsPassed: number;
    staticAnalysis: number;
    codeQuality: number;
    blastRadius: number;
    selfAssessment: number;
    speedBonus: number;
}
export declare const DEFAULT_REWARD_WEIGHTS: RewardWeights;
/**
 * Calculate composite reward score from individual signals.
 */
export declare function calculateRewardScore(signals: Partial<RewardSignals>, weights?: RewardWeights): number;
/**
 * Extract reward signals from execution output text.
 */
export declare function extractRewardSignals(output: string, durationMs: number, baselineDurationMs?: number): Partial<RewardSignals>;
export interface RepoUpgradeModeDefinition {
    id: RepoUpgradeMode;
    label: string;
    description: string;
    /** Ordered list of variants to execute for this mode */
    variants: UpgradeVariant[];
    /** Guidance to inject into prompts per variant */
    variantGuidance?: Partial<Record<UpgradeVariant, string>>;
    /** Bias to apply to the refiner when scores are tied (encourages RL exploration) */
    refinerBias?: number;
    /** Enable parallel variant execution (requires isolated workspaces) */
    parallelVariants?: boolean;
}
export declare const REPO_UPGRADE_MODE_DEFINITIONS: Record<RepoUpgradeMode, RepoUpgradeModeDefinition>;
export type UpgradeStepIntent = 'analyze' | 'upgrade' | 'verify' | 'cleanup';
export interface RepoUpgradeStep {
    id: string;
    intent: UpgradeStepIntent;
    description: string;
    /** Optional instruction or prompt to feed into the executor */
    prompt?: string;
}
export interface RepoUpgradeModule {
    id: string;
    label: string;
    description: string;
    scope: string[];
    /** Suggested codemod commands to run for this module (display only, not executed automatically). */
    codemodCommands?: string[];
    /** Suggested validation commands to run for this module (display only, not executed automatically). */
    validationCommands?: string[];
    steps: RepoUpgradeStep[];
}
export interface RepoUpgradePlan {
    modules: RepoUpgradeModule[];
}
export interface UpgradeStepExecutionInput {
    module: RepoUpgradeModule;
    step: RepoUpgradeStep;
    /** Which path we are taking: single-pass primary or the dual RL refiner */
    variant: UpgradeVariant;
    mode: RepoUpgradeMode;
    previousResult?: UpgradeStepResult;
    workspaceRoot?: string;
    repoPolicy?: string;
}
export interface UpgradeStepResult {
    success: boolean;
    summary: string;
    detail?: string;
    score?: number;
    /** Tournament-derived human accuracy (1=best, 0=worst across variants) */
    humanAccuracy?: number;
    rewardSignals?: Partial<RewardSignals>;
    /** Tournament breakdown for dual competitions */
    tournament?: RankedCandidate;
    durationMs?: number;
    execution?: ExecutionResult;
    findings?: Finding[];
    notes?: string[];
}
export interface UpgradeStepOutcome {
    stepId: string;
    intent: UpgradeStepIntent;
    description: string;
    primary: UpgradeStepResult;
    refiner?: UpgradeStepResult;
    winner: UpgradeStepResult;
    winnerVariant: UpgradeVariant;
    status: 'completed' | 'failed';
}
export interface UpgradeModuleReport {
    id: string;
    label: string;
    scope: string[];
    codemodCommands?: string[];
    validationCommands?: string[];
    steps: UpgradeStepOutcome[];
    status: 'completed' | 'failed' | 'skipped';
    validations?: ValidationRunResult[];
}
export interface RepoUpgradeReport extends OperationReport {
    mode: RepoUpgradeMode;
    continueOnFailure: boolean;
    modules: UpgradeModuleReport[];
    validationArtifacts?: ValidationRunResult[];
    /** True when validation commands were executed instead of just suggested */
    validationsExecuted?: boolean;
    variantStats: VariantWinStats;
    /** Paths used per variant when running dual workspaces (for git/worktree integrations). */
    variantWorkspaceRoots?: Partial<Record<UpgradeVariant, string>>;
    /** Optional policy that guided the run (e.g., upgrade or change-management policy). */
    repoPolicy?: string;
}
export interface RepoUpgradeRunOptions {
    objective?: string;
    mode: RepoUpgradeMode;
    continueOnFailure?: boolean;
    /** Optional per-variant workspace roots when running dual RL with separate repos. */
    variantWorkspaceRoots?: Partial<Record<UpgradeVariant, string>>;
    /** Optional policy/guideline string to surface in prompts and reports. */
    repoPolicy?: string;
    /** Enable parallel module processing (default: false for safety). */
    parallelModules?: boolean;
    /** Maximum concurrent modules when parallel processing is enabled (default: 3). */
    parallelModuleConcurrency?: number;
    /** Enable parallel variant execution in dual-RL mode (default: true). */
    parallelVariants?: boolean;
}
export type UpgradeStepExecutor = (input: UpgradeStepExecutionInput) => Promise<UpgradeStepResult>;
export interface ValidationRunResult {
    command: string;
    success: boolean;
    output: string;
    error?: string;
    durationMs: number;
    skipped?: boolean;
    reason?: string;
}
export interface VariantWinStats {
    primaryWins: number;
    refinerWins: number;
    /** Number of steps where scores were effectively tied and bias picked the winner */
    ties: number;
    totalSteps: number;
}
/**
 * Build a repo-wide upgrade plan using common directories. Falls back to a single
 * catch-all module when no known scopes are found.
 */
export declare function buildRepoWidePlan(workspaceRoot: string, additionalScopes?: string[]): RepoUpgradePlan;
export declare class RepoUpgradeOrchestrator extends UnifiedOrchestrator {
    private readonly executor;
    private variantWorkspaceRoots;
    private repoPolicy;
    private parallelExecutor;
    private objective;
    static repoTypeTelemetry: Map<string, {
        winsPrimary: number;
        winsRefiner: number;
    }>;
    /** Disable persisted telemetry via env or flag */
    static disableTelemetryPersistence: boolean;
    constructor(executor: UpgradeStepExecutor);
    /**
     * Get or create a parallel executor instance
     */
    private getParallelExecutor;
    /**
     * Execute the repo-wide plan using either single continuous or dual RL continuous mode.
     * Supports parallel module processing and parallel variant execution for improved performance.
     */
    run(plan: RepoUpgradePlan, options: RepoUpgradeRunOptions): Promise<RepoUpgradeReport>;
    /**
     * Run modules sequentially (original behavior)
     */
    private runModulesSequentially;
    /**
     * Run modules in parallel using the ParallelExecutor
     */
    private runModulesInParallel;
    /**
     * Process a single module (can be called in parallel or sequentially)
     */
    private processModule;
    private runStep;
    private evaluateTournamentOutcome;
    private buildTournamentCandidate;
    private attachTournamentBreakdown;
    private safeExecuteVariant;
    private pickWinner;
    private recordOutcomeArtifacts;
    private updateRepoTypeTelemetry;
    private updateVariantStats;
}
export declare function clampScore(value: number, min?: number, max?: number): number;
//# sourceMappingURL=repoUpgradeOrchestrator.d.ts.map