/** * reverse-requirement.ts — 从源码反推需求(两跳 IR → UR 渐进抽象) * * 方法论对齐 UserTrace:源码不是直接跳到用户需求,而是分两跳—— * 第一跳(源码 → 中间需求 IR):按技术模块切分,每个模块产出一份「实现级」IR; * 第二跳(IR → 用户需求 UR):合并所有 IR,抽象出「用户级」需求 + EARS 五句式验收标准。 * 验证环(v8.3.301+):校验 UR 溯源锚点与 IR 模块清单一致性,悬空锚点即疑似 AI 幻觉。 * * 架构边界(SpecCore 哲学): * - CLI 只做「确定性」分层:扫描分组、依赖排序、tree-sitter 摘要、骨架生成、锚点校验。 * - 宿主 AI 做「语义」抽象:IR 的业务语义填充、功能单元划分、EARS 验收标准撰写。 * - 所有产物标 status: candidate(候选),澄清后才成 Spec。 * * 复用能力: * - code-scanner 的 CodeIndex(modules 分组 + endpoints 端识别 + CodeFile 符号/API) * - multi-lang-parser 的 tree-sitter 结构化摘要(summarizeCode / summarizeSources) * * v8.3.184+ */ export declare const DEPTH_CONFIG: { readonly quick: { readonly maxFiles: 3; readonly slicesPerFile: 2; readonly maxBodyLines: 30; }; readonly normal: { readonly maxFiles: 8; readonly slicesPerFile: 3; readonly maxBodyLines: 50; }; readonly deep: { readonly maxFiles: 20; readonly slicesPerFile: 5; readonly maxBodyLines: 50; }; }; export type ReverseDepth = keyof typeof DEPTH_CONFIG; export interface ReverseRequirementOptions { /** 源码目录(可选,缺省用 code-index 的默认扫描范围) */ sources?: string[]; /** 分析深度 quick/normal/deep,影响读文件数与摘要粒度 */ depth?: string; /** 输出根目录,默认 .speccore/GLOBAL/requirements(v8.3.379: 按端组织——产物落 requirements/{端}/,根级 REQUIREMENT.md 留给全局分析总纲) */ outputDir?: string; /** 只反推指定端(frontend/backend/mobile/cli/shared),缺省全端 */ platforms?: string[]; /** 最多反推的模块数(防止超大工程爆量),默认 30 */ maxModules?: number; } /** 一个技术模块的中间需求(IR)——第一跳产物 */ export interface IRModule { /** 唯一 id:{endpoint}/{module} */ id: string; endpoint: string; module: string; files: string[]; symbols: string[]; apis: string[]; imports: string[]; /** tree-sitter 结构化摘要 */ summary: string; /** v8.3.365+: 带函数体的导出符号切片——业务语义抽象的素材来源 */ slices: IRCodeSlice[]; lines: number; } /** 业务切片(v8.3.365+):导出符号 + 注释 + 签名 + 函数体(截断后) */ export interface IRCodeSlice { /** 来源文件路径 */ file: string; /** 符号名 */ name: string; /** 符号类型(function/class/interface/type/enum/variable) */ type: string; /** 前置注释(JSDoc 等) */ comments: string; /** 签名行 */ signature: string; /** 函数体(截断后) */ body: string; /** 起始行号(1-based) */ lineStart: number; } export interface ReverseResult { outputDir: string; /** v8.3.379: 按端输出目录清单(GLOBAL/requirements/{端}/),单端时为一项 */ outputDirs: string[]; irDir: string; irCount: number; modules: IRModule[]; /** 两跳执行 prompt 路径(宿主 AI 据此完成语义抽象;多端时各端目录内各一份) */ promptPath: string; } export declare function reverseRequirementsFromCode(options: ReverseRequirementOptions): Promise; export declare function sanitize(id: string): string; /** 统计端目录内 UR 与 IR 骨架的未填占位符数量 */ export declare function countSkeletonPlaceholders(epDir: string): Promise<{ requirement: number; irFilled: number; irTotal: number; irPlaceholders: number; }>; /** 锚点校验结果(UR 溯源锚点 vs IR 模块清单) */ export interface VerifyAnchorsResult { outputDir: string; /** 已填写的锚点总数(不含 AI 未填的占位) */ total: number; /** 能回溯到真实 IR 模块的锚点数 */ valid: number; /** 悬空锚点(引用了不存在的模块 id,疑似 AI 幻觉) */ dangling: string[]; reportPath: string; } /** * 提取 REQUIREMENT.md 中已填写的溯源锚点(占位锚点「_AI 填写模块id」不计入)。 * v8.3.367: 从 verifyReverseAnchors 抽出,供 QA 环(完整性基线)复用。 */ export declare function extractFilledAnchors(content: string): string[]; /** * 校验 REQUIREMENT.md 的溯源锚点与 IR 模块清单的一致性。 * 锚点与 IR 文件名都经过 sanitize 归一化后比对('/' → '-'), * 悬空锚点即宿主 AI 引用了不存在的模块——典型幻觉特征,须修正后重新校验。 */ export declare function verifyReverseAnchors(outputDir: string): Promise; //# sourceMappingURL=reverse-requirement.d.ts.map