/** * Review 收敛策略(Hardening-3)— 总轮次硬上限 + FindingSeverity + ReviewScope + FindingLifecycle。 * * 解决:sf_review 收敛循环无硬上限(fixed→re-review 永真 / review_outdated 反复 / K-sample 内耗)。 * * 设计原则(遵循 convergence_controller.ts 既有原则):**旁路新增,不替换现有 review engine**。 * - 不改 K 采样 / evaluator gate / HMAC / ResolutionRecord / ImpactEngine / convergence_controller * - 不删现有 severity(error/warning/info)/criticality/resolution_status/closure_status 字段 * - 本模块是独立纯计算层 + 类型模型:输入(policy/severity/scope/lifecycle)→ 输出(收敛状态 / 阻断判定 / 差量过滤 / 迁移合法性) * * 与现有层分工: * - convergence_controller:accepted_risk 重挑战 budget(普通1/关键2)+ finding 裁决状态 * - 本模块:总轮次硬上限(max_rounds)+ 显式阻断语义(FindingSeverity)+ 差量 scope(ReviewScope)+ 生命周期状态机(FindingLifecycle) * - evaluator(gate):仍按 judgment.blockingReviewFindings(severity=error 未闭环)阻断 deliver,本模块不降低 gate 强度 */ import type { ReviewFinding } from "../adversarial_review_store.js"; /** 收敛策略状态。LIMIT_REACHED=超 max_rounds(停止自动 re-review);CONVERGED=无 open blocking;BLOCKED=预算耗尽。 */ export type ConvergencePolicyState = "RUNNING" | "CONVERGED" | "LIMIT_REACHED" | "BLOCKED"; /** 收敛停止原因(状态非 RUNNING 时填,供审计/诊断)。 */ export type ConvergenceStopReason = "converged_no_open_blocking" | "max_rounds_reached" | "blocked_budget_exhausted" | "manual_stop"; /** Review 收敛策略(总轮次硬上限,防 fixed→re-review 永真循环)。 */ export interface ReviewConvergencePolicy { /** 最大 re-review 总轮次上限(默认 DEFAULT_MAX_ROUNDS=3)。 */ max_rounds: number; /** 当前已执行轮次(调用方从 review 历史 / rounds 算)。 */ current_round: number; /** 停止原因(非 RUNNING 时填)。 */ stop_reason?: ConvergenceStopReason; /** 策略状态。 */ state: ConvergencePolicyState; } /** 默认最大轮次(总 re-review 上限)。与 DEFAULT_REVIEW_SAMPLE_K(K-sample 每轮采样数)正交。 */ export declare const DEFAULT_MAX_ROUNDS = 3; /** 创建默认收敛策略(max_rounds=DEFAULT_MAX_ROUNDS, current_round=0, RUNNING)。 */ export declare function createConvergencePolicy(maxRounds?: number): ReviewConvergencePolicy; /** 推进一轮(re-review 完成后调用,current_round+1)。 */ export declare function advanceRound(policy: ReviewConvergencePolicy): ReviewConvergencePolicy; /** re-review 触发前的收敛检查。 * - current_round >= max_rounds → LIMIT_REACHED(禁止继续自动 re-review,保留历史 findings/evidence)。 * - 无 open blocking → CONVERGED(收敛,可推进)。 * - 否则 RUNNING(允许继续 re-review)。 * 注意:LIMIT_REACHED 不放行 blocking finding(blocking 仍阻断 deliver,需人工 accepted_risk/修复);只停止自动 re-review。 */ export declare function checkConvergenceLimit(policy: ReviewConvergencePolicy, hasOpenBlocking: boolean): { policy: ReviewConvergencePolicy; action: "continue" | "stop_converged" | "limit_reached"; }; /** Finding 严重度(交付阻断语义,显式模型)。与现有 severity(error/warning/info)+criticality 映射。 * BLOCKING=必须关闭才能 deliver;ADVISORY=不阻断 deliver(留痕);INFO=只记录。 */ export type FindingSeverity = "BLOCKING" | "ADVISORY" | "INFO"; /** 从现有 severity + criticality 推断 FindingSeverity。 * criticality(security/finance/compliance)→ BLOCKING(关键发现强制阻断,即使 severity=warning); * error → BLOCKING;warning → ADVISORY;info → INFO。 */ export declare function inferFindingSeverity(severity: "error" | "warning" | "info", criticality?: "security" | "finance" | "compliance"): FindingSeverity; /** FindingSeverity 是否阻断 deliver。BLOCKING 阻断;ADVISORY/INFO 不阻断。 */ export declare function severityBlocksDeliver(fs: FindingSeverity): boolean; /** 统计 findings 中阻断数(BLOCKING)。 */ export declare function countBlocking(findings: ReadonlyArray<{ severity: FindingSeverity; }>): number; /** Review scope(re-review 差量:只进相关 scope,避免全量重审)。 */ export type ReviewScope = "SECURITY" | "CONTRACT" | "RUNTIME" | "STYLE" | "UI" | "ARCHITECTURE"; /** 从 criticality / artifactKind 推断 ReviewScope。 */ export declare function inferReviewScope(criticality?: "security" | "finance" | "compliance", artifactKind?: string): ReviewScope; /** scope 差量匹配:finding scope ∈ 目标 scope 集合才进入 re-review。空 target = 全 scope(向后兼容)。 */ export declare function scopeMatches(findingScope: ReviewScope, targetScopes: ReadonlyArray): boolean; /** 差量过滤:只保留 scope 命中的 finding(re-review 减少全量重审)。 */ export declare function filterByScope(findings: ReadonlyArray, targetScopes: ReadonlyArray): T[]; /** Finding 生命周期状态(单维状态机,与现有 resolution_status/closure_status 二维映射)。 * OPEN=待处理;FIX_PENDING=已确认待修复;CONFIRMED_FIXED=已修复核验;REOPENED=修复后重开(须新证据);WAIVED=豁免/接受风险。 */ export type FindingLifecycleState = "OPEN" | "FIX_PENDING" | "CONFIRMED_FIXED" | "REOPENED" | "WAIVED"; /** 状态迁移合法性校验。 * 禁止:CONFIRMED_FIXED → OPEN(须走 REOPENED 且有证据,防无证据重开绕过已核验修复)。 */ export declare function validateLifecycleTransition(from: FindingLifecycleState, to: FindingLifecycleState, hasEvidence: boolean): { ok: boolean; reason?: string; }; /** 从现有 resolution_status + closure_status 映射到 FindingLifecycleState。 */ export declare function mapLifecycleState(resolutionStatus?: "needs_triage" | "confirmed" | "false_positive" | "accepted_risk", closureStatus?: "open" | "fixed" | "waived"): FindingLifecycleState; /** 从 ReviewFinding 派生收敛分析用的 finding 视图(severity + scope + lifecycle 聚合)。 */ export interface ConvergenceFindingView { findingId: string; severity: FindingSeverity; scope: ReviewScope; lifecycle: FindingLifecycleState; /** 是否 open blocking(阻断 deliver 且未闭环)。 */ openBlocking: boolean; } /** 从 ReviewFinding 派生 ConvergenceFindingView(聚合 severity/scope/lifecycle)。 */ export declare function deriveConvergenceView(finding: ReviewFinding): ConvergenceFindingView;