import type { BudgetPreflightEstimate, CostProvenance, EvidenceVector, FailureClass, InterventionType, LoopAttempt, LoopBudget, LoopCost, LoopLifecycleState, LoopStatus, PatchDecisionArtifact, PatchScore, PolicyPhase } from "../contracts/index.js"; export interface FailureAssessment { failureClass: FailureClass; rationale: string; retryable: boolean; recommendedIntervention: InterventionType; /** Actionable diagnosis injected into the next attempt's prompt context. */ diagnosticHint?: string; } export interface CostGovernorState { pressure: "healthy" | "soft_limit" | "hard_limit"; shouldStop: boolean; remainingBudgetUsd: number; remainingIterations: number; remainingTokens?: number; recommendedIntervention?: InterventionType; } export interface ExitDecision { shouldExit: boolean; lifecycleState: LoopLifecycleState; status: LoopStatus; reason: string; /** Machine-readable stop classifier for non-attempt exits such as preflight safety blocks. */ failureClass?: FailureClass; /** Machine-readable safety surface, when the stop came from a safety leash. */ safetySurface?: string; /** Stable reason code for dashboards, MCP, and downstream automation. */ reasonCode?: string; } export interface MartinAdapterResultLike { status: "completed" | "failed"; summary: string; usage?: { actualUsd: number; estimatedUsd?: number; tokensIn: number; tokensOut: number; provenance?: CostProvenance; }; verification: { passed: boolean; summary: string; steps?: Array<{ command: string; launched: boolean; exitCode?: number; timedOut: boolean; fastFail?: boolean; detail?: string; }>; warnings?: string[]; }; failure?: { message: string; classHint?: FailureClass; }; } /** * Maps a PolicyPhase to the LoopLifecycleState used in events and persistence. * FailureClass remains a thin output label — policy reads EvidenceVector, not the label. */ export declare function policyPhaseToLifecycleState(phase: PolicyPhase): LoopLifecycleState; /** * Determines the next PolicyPhase given the current phase and last result. * This is the explicit typed transition table — no implicit fallthrough. */ export declare function nextPolicyPhase(current: PolicyPhase, result: MartinAdapterResultLike, costState: CostGovernorState, retryCount: number): PolicyPhase; export declare function classifyFailure(input: { attempts: LoopAttempt[]; result: MartinAdapterResultLike; }): FailureAssessment; export declare function evaluateCostGovernor(input: { budget: LoopBudget; cost: LoopCost; attemptsUsed: number; }): CostGovernorState; export interface CostPerOutcome { costPerAcceptedChange: number | undefined; costPerAttempt: number; acceptanceRate: number; wastedCoordinationUsd: number; } export declare function calculateCostPerOutcome(input: { totalCostUsd: number; preworkCostUsd: number; attemptCount: number; accepted: boolean; verificationPassed: boolean; }): CostPerOutcome; export declare function inferExit(input: { loop: { budget: LoopBudget; cost: LoopCost; attempts: LoopAttempt[]; }; lastResult: MartinAdapterResultLike; lastFailure?: FailureAssessment; costState: CostGovernorState; canSwitchAdapter?: boolean; verificationRequired?: boolean; }): ExitDecision; export interface BudgetPreflightInput { promptCharCount: number; attemptCount: number; remainingBudgetUsd: number; perAttemptCapUsd?: number; pricePerMTokenUsd?: number; } export interface BudgetPreflightDecision { allowed: boolean; reason: string; estimate: BudgetPreflightEstimate; } export declare function evaluateBudgetPreflight(input: BudgetPreflightInput): BudgetPreflightDecision; export interface EvidenceVectorInput { compilerOutput?: string; testOutput?: string; diff?: string; previousDiff?: string; forbiddenTouchedFiles?: string[]; missingSymbols?: string[]; actualUsd?: number; previousVerifierScore?: number; verifierScore?: number; retryCountForSurface?: number; } export declare function computeEvidenceVector(input: EvidenceVectorInput): EvidenceVector; export type RecoveryRecipe = "narrow_prompt_targeted_files" | "failing_tests_only" | "force_repo_anatomy_slices" | "tighten_allowlist_reduce_patch" | "strategy_swap" | "abort_safety_violation" | "downgrade_model" | "escalate_human"; export interface RecoveryDecision { recipe: RecoveryRecipe; rationale: string; intervention: InterventionType; } export interface PatchDecisionInput { verificationPassed: boolean; previousVerifierScore?: number; verifierScore?: number; groundingViolationCount?: number; safetyViolationCount?: number; scopeViolationCount?: number; changedFileCount?: number; mutationRequired?: boolean; definitionOfDonePreSatisfied?: boolean; diffNovelty?: number; diffStats?: { filesChanged: number; addedLines: number; deletedLines: number; }; costUsd?: number; humanApprovalRequired?: boolean; summary?: string; } export interface EvaluatedPatchDecision extends PatchDecisionArtifact { score: PatchScore; } export declare function selectRecoveryRecipe(evidence: EvidenceVector): RecoveryDecision; export declare function evaluatePatchDecision(input: PatchDecisionInput): EvaluatedPatchDecision; export declare function scorePatchDecision(input: PatchDecisionInput): PatchScore;