import { type SignatureProvider } from "./signature_provider.js"; /** Resolution 裁决类型。fixed=修复内容;removed=删除产物;accepted_risk=接受风险;false_positive=判误报。 */ export type ResolutionType = "fixed" | "removed" | "accepted_risk" | "false_positive"; /** Resolution 记录生命周期状态。open=待处理;resolved=已闭环;superseded=被后续 resolution 取代。 */ export type ResolutionStatus = "open" | "resolved" | "superseded"; /** Resolution 创建者。accepted_risk/false_positive 须 user(handler 层强制,store 仅存字段)。 */ export type ResolutionCreatedBy = "user" | "ai"; /** 修复涉及产物的关系。fixes=修改/新增内容;removes=删除整个产物(删除型修复)。 */ export type ResolutionArtifactRelation = "fixes" | "removes"; /** 确定性修复证据类型。git_diff=commit diff;baseline=基线快照比对;deterministic=确定性检查;removed=删除型(baseline 有+当前无);manual=人工说明。 */ export type ResolutionEvidenceKind = "git_diff" | "baseline" | "deterministic" | "removed" | "manual"; /** 修复涉及的目标产物(可多个,且可 != finding.artifact——治"修复在关联文件")。 * relation=removes 表删除型修复(删了 finding 指向的整个产物)。 */ export interface ResolutionTarget { /** 修复涉及的产物路径(可能是 QualificationService 而非 finding.artifact QualificationController) */ artifact: string; /** fixes=修改/新增;removes=删除产物 */ relation: ResolutionArtifactRelation; /** 修复后产物 digest(确定性锚点,可选) */ digest?: string; } /** 确定性修复证据引用(保存修复成立的客观依据,非 AI 自填 token)。 */ export interface ResolutionEvidenceRef { kind: ResolutionEvidenceKind; /** 引用:commit hash / baseline review_id / deterministic check_id / 手工说明 */ ref: string; detail?: string; } /** Resolution 证据记录 — Finding→Resolution→Artifact 的修复关系(append-only,不改 finding)。 * HMAC provenance 防伪造(与 gate/review/waiver/decision 同源);纯软件下读 secret 者可伪造,提高门槛非根治。 */ export interface ResolutionRecord { schema_version: 1; /** resolution id(唯一,res-;Store 文件名 + 审计定位) */ resolution_id: string; /** 所属任务(防跨任务复用,与 review/decision 一致) */ task_id: string; /** 关联 finding(= reviewFindingKey(finding.artifact, location, quote);resolution 按 finding 聚合) */ finding_id: string; /** finding 所属 review(可选,审计追溯) */ review_id?: string; /** 裁决类型(fixed/removed/accepted_risk/false_positive) */ resolution_type: ResolutionType; /** 记录生命周期状态 */ status: ResolutionStatus; /** 修复涉及的产物列表(>=1;可多个,且可 != finding.artifact) */ target_artifacts: ResolutionTarget[]; /** 确定性修复证据引用(可空:无确定性锚点时仅 resolution_evidence 文本) */ evidence_refs: ResolutionEvidenceRef[]; /** 裁决依据文本(必填) */ resolution_evidence: string; /** 推荐线半结构化锚点(可选,K4 批):原问题代码片段(落档供差量重审复核;自实践文本化锚点迁移) */ old_quote?: string; /** 推荐线半结构化锚点(可选):新代码锚点(落档供差量重审复核) */ new_anchor?: string; /** accepted_risk/false_positive 须 true(handler 层强制 user 确认) */ user_confirmed?: boolean; /** 创建者(user/ai) */ created_by: ResolutionCreatedBy; created_at: number; updated_at: number; /** HMAC provenance 签名(有 secret 时签发,read 验签排除伪造) */ hmac?: string; } /** 生成新 resolution_id(res-)。 */ export declare function generateResolutionId(): string; /** * 查找 finding 的稳定 Resolution(fixed/removed + status=resolved + 有确定性证据)。 * 纯函数(查内存数组,不读文件)——调用方预读 ResolutionStore.listBy* 后传入,避免 verifyFindingFixed(同步)变 async。 * 多条匹配选 updated_at 最新(Case5)。无确定性证据(git_diff/baseline/deterministic)不算 stable—— * 防 AI 自填 description / user_confirmed 单独判定 fixed(任务一禁止)。 */ export declare function findStableResolution(resolutions: readonly ResolutionRecord[], findingId: string): { type: ResolutionType; } | undefined; /** Resolution evidence 构造上下文(纯数据 DTO,调用方收集客观信号后传入)。 * changedFiles:目标文件存在修改(归一 artifact → 内容 hash);baselines:存在 baseline 快照(归一 artifact → 基线引用)。 * 仅承载可验证客观事实;不含 description/user_confirmed/AI 文本(不可验证,禁止作 evidence)。 */ export interface ResolutionEvidenceContext { readonly changedFiles?: ReadonlyMap; readonly baselines?: ReadonlyMap; /** 删除型修复:baseline 有 + 当前缺失的 artifact 集合(归一 path)。removed evidence 的客观来源。 */ readonly removedArtifacts?: ReadonlySet; } /** 路径归一(posix + 去 ./ 前缀 + 去尾斜杠),供 artifact 与 baseline 快照 relPath 比对(防同文件不同表示漏匹配)。 */ export declare function normalizeEvidencePath(a: string): string; /** * 从 finding 的客观信号 + 上下文生成 Resolution evidence_refs(不伪造,无信号返 [])。 * 优先级:git_diff(目标文件存在修改) > baseline(存在 baseline 快照) > deterministic(确定性标记/锚点)。 * evidence 来源限于可验证客观事实(git diff 内容 hash / baseline 快照 / 引擎核验过的锚点); * 不用 description / user_confirmed / AI 文本说明代替 evidence(不可验证,禁止)。 * digest 受 ResolutionEvidenceRef schema(kind/ref/detail)约束,放入 detail(如 detail="digest=")。 * context 由调用方收集(读 baseline 快照比对),本函数纯计算不读文件。 * removed 型:fix_action="remove" + baseline 有 + 当前无 → removed evidence(handler 接入)。 */ export declare function buildResolutionEvidence(finding: { evidence_type?: "deterministic" | "llm_subjective"; fix_verification?: { artifact?: string; }; artifact?: string; fix_action?: "remove"; }, context?: ResolutionEvidenceContext): ResolutionEvidenceRef[]; /** Resolution 证据存储 — 纯文件 CRUD + HMAC provenance,append-only(不改 finding/review)。 */ export declare class ResolutionStore { private readonly projectRoot; private readonly provider; constructor(projectRoot: string, provider?: SignatureProvider); private filePath; private withResolutionLock; /** 读取 + schema 校验 + HMAC 验签(fail-closed)。伪造/无 secret → null;损坏 schema throw。 */ private readAndValidate; read(resolutionId: string): Promise; /** 列出某 finding 的所有 resolution(append-only 下可能多条:历史 + 最新;按 updated_at 降序)。 */ listByFinding(findingId: string): Promise; /** 列出某 task 的所有 resolution。 */ listByTask(taskId: string): Promise; /** 列出涉及某 artifact 的所有 resolution(target_artifacts 命中)。 */ listByArtifact(artifact: string): Promise; private listBy; /** 持久化(append-only:只写新文件,不读不改 finding/review)。无 secret throw(fail-closed)。 */ create(record: ResolutionRecord): Promise; }