/** 单个规则文件在 manifest 中的条目 */ export interface RuleManifestEntry { /** 内容来源:'base' = GODOT_MCP_RULES,'detail' = DETAILED_RULE_TEMPLATES */ source: 'base' | 'detail'; /** 安装时文件内容的 hash(CRLF 归一化后),格式 'sha256:' */ hash: string; } /** manifest 文件结构 */ export interface RulesManifest { /** 清单格式版本,留作未来迁移 */ manifest_version: number; /** 规则文件安装时的 server 版本(仅代表规则文件,非整个 MCP 安装) */ rules_installed_at_version: string; /** 安装时间 ISO 字符串 */ installed_at: string; /** 文件名 → 条目 */ rules: Record; } /** 逐文件二维判定的四种分类(见 spec §3.3) */ export type FileClassification = 'pure-upgrade' | 'stale-and-modified' | 'latest' | 'local-modified'; /** reconcile 执行模式 */ export type RulesMode = 'check' | 'update' | 'overwrite'; /** CRLF / 裸 CR 归一化为 LF。仅用于算 hash,不用于写磁盘。 */ export declare function normalizeForHash(content: string): string; /** 计算内容的 SHA-256 hash(CRLF 归一化后),返回 'sha256:'。 */ export declare function hashContent(content: string): string; /** adopt 输入:每个规则文件的当前磁盘内容 */ export interface AdoptFileInput { filename: string; content: string; source: 'base' | 'detail'; } /** adopt 构建参数 */ export interface BuildAdoptParams { serverVersion: string; now: string; files: AdoptFileInput[]; } /** * 把当前磁盘状态固化为新 manifest 基线(spec §5)。 * 偏离模板的文件 hash 记实际内容(不报错),偏离计数由 countDeviations 单独算。 */ export declare function buildAdoptManifest(params: BuildAdoptParams): RulesManifest; /** * 统计 manifest 中磁盘 hash ≠ 当前模板 hash 的文件数(spec §5 adopt 报告用)。 * @param manifest adopt 后的 manifest * @param currentTemplateHashes 每个文件名 → 当前模板内容的 hash */ export declare function countDeviations(manifest: RulesManifest, currentTemplateHashes: Record): number; /** classifyFile 输入参数 */ export interface ClassifyParams { /** manifest 记录的安装时版本 */ installedVersion: string; /** 当前 server 版本 */ serverVersion: string; /** 当前磁盘文件内容的 hash */ diskHash: string; /** manifest 记录的安装时 hash */ manifestHash: string; } /** * 逐文件二维判定。版本与"是否动过"是两个独立维度,做笛卡尔积,不级联。 * 级联会吞用户修改(见 spec §3.3 "为什么二维而非级联")。 */ export declare function classifyFile(p: ClassifyParams): FileClassification; /** 单个文件的 reconcile 动作 */ export type FileAction = 'write' | 'keep' | 'warn-keep'; export interface FilePlan { classification: FileClassification; action: FileAction; /** action=write 时,要写入的新内容(来自当前模板) */ newContent?: string; } export interface PlanReconcileParams { manifest: RulesManifest; serverVersion: string; diskFiles: { filename: string; content: string; }[]; /** 当前模板内容(文件名 → 插值后的模板字符串)。update/overwrite 时覆盖用 */ currentTemplates?: Record; mode: RulesMode; now: string; } export interface ReconcilePlan { /** 文件名 → 动作计划 */ actions: Record; /** 是否需要写文件(check 模式为 false) */ shouldWriteFiles: boolean; /** 更新后的 manifest(无论是否写文件都给出,供报告) */ newManifest: RulesManifest; } /** * reconcile 规划的核心纯函数(spec §3.4)。 * * 集成 classifyFile 的二维判定,按 mode 决策每个文件的动作: * - check:所有文件 action=keep,shouldWriteFiles=false * - update:pure-upgrade → write;stale-and-modified/local-modified → warn-keep(保留并警告);latest → keep * - overwrite:除 latest 外都 write(全覆盖) * * 关键不变式:update 模式下 stale-and-modified(版本过时 + 用户动过)的文件 * 必须 warn-keep(保留 + 警告),绝不能 write —— 否则吞用户修改。 */ export declare function planReconcile(p: PlanReconcileParams): ReconcilePlan;