/** * spec-merger — Section 级局部更新引擎 * * 统一处理三种场景的局部合并: * 1. analyze --task --sync → 任务分析结果局部回写 020-specs/ * 2. change → 需求变更后局部更新受影响的 specs * 3. sync-global → 迭代 specs 局部合并到全局层 * * 核心原则:只更新受影响的部分,其余内容不动 */ export interface MarkdownSection { /** 原始标题文本(不含 # 前缀) */ heading: string; /** 标题级别 (1-6) */ level: number; /** 正文内容(不含标题行) */ content: string; /** 包含标题行的完整原始文本 */ raw: string; } export interface AffectedFeature { /** 功能模块名 */ name: string; /** spec 文件路径(相对迭代目录) */ specPath: string; /** 需求源文件路径(相对迭代目录) */ reqPath: string; /** 匹配置信度 */ confidence: number; } export interface MergeResult { /** 修改的文件数 */ filesUpdated: number; /** 每个文件的变更摘要 */ changes: { file: string; sectionsPatched: string[]; action: 'patched' | 'created' | 'skipped'; }[]; } /** * 将 Markdown 文档按 H2 标题拆分为段落数组 * * 标题前的内容(前言)作为第一个元素返回(heading 为空字符串) */ export declare function splitMarkdownSections(content: string): MarkdownSection[]; /** * 替换文档中指定标题的段落,不存在则追加 * * @param docContent 原始完整文档 * @param sectionHeading 要替换的 H2 标题(精确匹配或包含匹配) * @param newContent 新的段落内容(不含标题行) * @returns 替换后的完整文档 */ export declare function patchSection(docContent: string, sectionHeading: string, newContent: string): string; /** * 从文档中提取指定标题的段落内容 */ export declare function extractSection(docContent: string, sectionHeading: string): string | null; /** * 从文本中提取特征关键词(≥3 字符,过滤停用词) */ export declare function extractKeywords(text: string): string[]; /** * 将源文档中的相关段落合并到目标文档 * * 匹配策略: * 1. 标题精确匹配 → 直接替换 * 2. 标题关键词重叠 → 替换(重叠率 > 阈值) * 3. 无匹配 → 追加到目标文档末尾 * * @param sourceContent 源文档(新分析结果) * @param targetContent 目标文档(现有 spec) * @param keywords 用于匹配的关键词集合 * @returns 合并后的文档 */ export declare function mergeSpecContent(sourceContent: string, targetContent: string, keywords: string[]): { content: string; patchedSections: string[]; }; /** * 根据关键词查找受影响的功能模块 spec 文件 * * 扫描 020-specs/features/ 目录,按文件名和内容匹配关键词 */ export declare function findAffectedFeatures(iterDir: string, keywords: string[]): Promise; /** * 根据关键词查找受影响的顶层 spec 文件(TECH.md / TEST.md 等) * * 返回需要 patch 的 section 名称列表 */ export declare function findAffectedSpecSections(iterDir: string, keywords: string[]): Promise<{ file: string; sections: string[]; }[]>; /** * 将任务分析结果局部回写到迭代级 020-specs/ * * 流程: * 1. 从任务标题/REQ.md 提取关键词 * 2. 查找受影响的功能模块 spec 文件 * 3. 对每个受影响文件执行 section 级 merge * 4. 对顶层 spec 文件(TECH.md 等)执行 section 级 patch * * @param iterDir 迭代目录绝对路径 * @param taskDir 任务目录绝对路径 * @param taskName 任务名称(用于关键词提取) * @returns 合并结果摘要 */ export declare function syncTaskToSpecs(iterDir: string, taskDir: string, taskName: string): Promise; /** * 将迭代级 spec 文件局部合并到全局层 * * 与 syncTaskToSpecs 类似,但方向是 iteration → global * * @param iterDir 迭代目录绝对路径 * @param globalDir 全局 .speccore 目录绝对路径 * @param keywords 可选的过滤关键词(只同步相关模块) */ export declare function syncIterationToGlobal(iterDir: string, globalDir: string, keywords?: string[]): Promise; /** * 归档时将新增需求局部合并回原需求文档 * * 流程: * 1. 扫描迭代下所有任务,找出「新增需求」任务 * (通过 .meta/ 标记、CHANGE_SUMMARY.md 记录、或任务名含"新增"特征) * 2. 读取任务的 _shared/REQ.md * 3. 按关键词匹配原需求文档(010-requirements/features/ 或 converted/) * 4. 用 mergeSpecContent() 做 section 级合并 * 5. 未匹配到原文档的,追加到 features/{slug}/README.md */ export declare function mergeNewRequirementsOnArchive(iterDir: string): Promise; //# sourceMappingURL=spec-merger.d.ts.map