/** * Unified Retrieval Layer — 统一检索层 * * 整合三个检索源: * 1. 文档 RAG (rag-engine.ts) → Markdown 分块 * 2. 代码切片 (本文件) → 按 export 分块 * 3. 知识图谱 (knowledge-graph.ts) → 实体关系链 * * 设计目标:一次查询,返回最相关的混合上下文,AI 不需要知道数据来源 */ import { DocumentChunk } from './rag-engine'; export interface CodeSlice { id: string; filePath: string; fileName: string; type: 'function' | 'class' | 'interface' | 'variable' | 'type' | 'enum'; name: string; /** JSDoc/注释 */ comments: string; /** 函数签名 / 类定义头 / 接口定义 */ signature: string; /** 前 N 行实现 */ body: string; /** 提取的关键词 */ keywords: string[]; /** 行号范围 */ lineStart: number; lineEnd: number; /** 相关性分数 */ relevanceScore?: number; } export interface UnifiedQuery { /** 查询语句(task名称/需求关键词) */ query: string; /** 迭代名称 */ iteration?: string; /** 任务ID */ taskId?: string; /** 平台 */ platform?: string; /** 任务目录 */ taskDir?: string; /** 源码范围 */ sourceScope?: string; /** 按端过滤(backend/web/h5/admin/...) */ platforms?: string[]; } export interface UnifiedResult { /** 文档检索结果 */ documentChunks: DocumentChunk[]; /** 代码切片结果 */ codeSlices: CodeSlice[]; /** 知识图谱上下文 */ graphContext?: string; /** 统计信息 */ stats: { docChunksFound: number; codeSlicesFound: number; totalTokensEstimate: number; }; } /** * 将源代码按 export 语句切分为多个块 * 支持:export function / class / interface / type / enum / const / let / var * * 不需要 AST 解析,用正则做轻量级分片: * - 匹配 export 语句头 * - 向后扫描到下一个 export 或文件结束 * - 提取 JSDoc 注释 */ export declare function sliceCodeFile(content: string, filePath: string): CodeSlice[]; /** * 统一检索:同时查询文档 RAG、代码索引、知识图谱 * 返回按相关性排序的混合上下文 */ export declare function unifiedSearch(cwd: string, query: UnifiedQuery): Promise; /** * 将统一检索结果组装为 Prompt 可用的格式 * 输出结构与 extraSpecs 兼容 */ export declare function assembleUnifiedContext(result: UnifiedResult, options?: { maxTotalChars?: number; generous?: boolean; }): { name: string; path: string; content: string; }[]; /** * 将统一检索结果序列化为文本(直接注入 Prompt) */ export declare function formatUnifiedContext(result: UnifiedResult): string; /** * 目录条目(轻量级,用于 AI 判断) */ export interface CatalogEntry { /** chunk ID */ id: string; /** 块标题 */ title: string; /** 源文件名 */ fileName: string; /** 标题级别 */ level: number; /** 自动摘要(≤100字) */ summary: string; /** 关键词 */ keywords: string[]; /** 字数 */ charCount: number; /** 起始行号 */ startLine?: number; /** 结束行号 */ endLine?: number; } /** * 构建轻量级目录摘要(给 AI 看的“地图”) * * 设计目标: * - 只包含 ID + 标题 + 摘要 + 关键词,不包含完整内容 * - 总大小控制在 ~2000 字以内 * - AI 看完后返回候选 ID 列表,CLI 用这些 ID 做精确读取 * * 用法: * const catalog = await buildDirectoryCatalog(cwd, iteration); * // 注入 Prompt 让 AI 判断 * const prompt = `以下是可用的文档块目录:\n${catalog}\n\n请根据用户需求返回最相关的 chunk ID 列表(JSON 数组)`; */ export declare function buildDirectoryCatalog(cwd: string, iteration?: string, options?: { maxEntries?: number; maxSummaryChars?: number; }): Promise; /** * 根据 AI 返回的候选 ID 列表,精确读取对应 chunk 内容 * * 用法: * const candidateIds = ['a1b2c3d4e5f6', 'f6e5d4c3b2a1']; * const chunks = await fetchChunksByIds(cwd, candidateIds, iteration); */ export declare function fetchChunksByIds(cwd: string, ids: string[], iteration?: string): Promise; //# sourceMappingURL=unified-retrieval.d.ts.map