UNPKG

autosnippet

Version:

Extract code patterns into a knowledge base for AI coding assistants

136 lines (135 loc) 4.82 kB
/** * scan-prompts.js — scanKnowledge 任务配置 + 统一管线工厂 + 关系发现管线 * * scan pipeline (extract/summarize): * 共享 Insight Pipeline (Analyze → QualityGate → Produce → RejectionGate), * Analyze 使用与冷启动一致的 ANALYST_SYSTEM_PROMPT + ExplorationTracker 四阶段管理, * Produce 阶段均为工具驱动 (collect_scan_recipe),与冷启动 submit_knowledge 对齐。 * * relations pipeline (独立): * 知识图谱关系发现: Explore → Synthesize 两阶段, * 通过查询知识库 + 读取源码发现条目间语义关系。 * * @module scan-prompts */ /** Source file shape (used for fallback prompt) */ interface ScanSourceFile { relativePath?: string; name?: string; content?: string; } /** Tool call record shape in stage results */ interface ScanToolCallRecord { tool?: string; name?: string; result?: string | { status?: string; [key: string]: unknown; }; [key: string]: unknown; } /** Phase result shape (from pipeline execution) */ interface PhaseResult { reply?: string; toolCalls?: ScanToolCallRecord[]; [key: string]: unknown; } /** Parameters for buildScanPipelineStages */ interface ScanPipelineOpts { task: 'extract' | 'summarize'; producePrompt: string; analyzeCaps: string[]; produceCaps: string[]; files?: ScanSourceFile[]; analyzeMaxIter?: number; } /** * task → Produce 阶段配置 (extract + summarize) * * 两种 task 均为工具驱动 (collect_scan_recipe),Recipe 格式与冷启动 submit_knowledge 对齐: * - extract: 多文件 target 扫描 → 多个 Recipe * - summarize: 单文件/代码片段 → 1~2 个 Recipe */ export declare const SCAN_TASK_CONFIGS: { extract: { producePrompt: string; fallback: (label: string) => { targetName: string; extracted: number; recipes: never[]; }; }; summarize: { producePrompt: string; fallback: (label: string) => { targetName: string; extracted: number; recipes: never[]; }; }; }; /** * 构建 scanKnowledge 的标准 4 阶段 Pipeline stages * * 与冷启动 orchestrator 完全对齐: * 1. analyze — 代码分析 (ExplorationTracker 四阶段管理) * 2. quality_gate — 分析质量门控 (insightGateEvaluator + buildAnalysisArtifact) * 3. produce — 知识生产 (artifact-aware promptBuilder + 工具驱动提交) * 4. rejection_gate — 拒绝率门控 (producerRejectionGateEvaluator) * * 与冷启动对齐的关键节点: * - quality_gate 通过 strategyContext.activeContext 走 buildAnalysisArtifact * (而非降级的 buildAnalysisReport),保留 findings/evidenceMap/negativeSignals * - produce 使用 promptBuilder (而非 promptTransform), * 从 gateArtifact 注入结构化发现和代码证据到 prompt * - strategyContext 需要包含 activeContext / outputType / dimId * (由 AgentFactory.buildSystemContext 设置) * * @param opts.task 任务类型 * @param opts.producePrompt Produce 阶段 systemPrompt * @param opts.analyzeCaps Analyze 阶段 capabilities * @param opts.produceCaps Produce 阶段 capabilities * @param [opts.files] 源文件 (fallback prompt 用) * @param [opts.analyzeMaxIter=24] Analyze 最大迭代 * @returns PipelineStrategy stages 数组 */ export declare function buildScanPipelineStages({ task, producePrompt, analyzeCaps, produceCaps, files, analyzeMaxIter, }?: ScanPipelineOpts): Record<string, unknown>[]; /** * 构建知识图谱关系发现的独立 Pipeline stages * * 与 scan pipeline 不同,relations pipeline: * - 不需要源文件输入 (从知识库查询) * - 2 阶段: explore (工具驱动) → synthesize (文本输出) * - 无质量门控 (探索结果质量由工具返回保证) * * @param [opts.exploreCaps] Explore 阶段 capabilities * @param [opts.exploreMaxIter=20] Explore 最大迭代 * @returns PipelineStrategy stages 数组 */ export declare function buildRelationsPipelineStages({ exploreCaps, exploreMaxIter, }?: { exploreCaps?: string[] | undefined; exploreMaxIter?: number | undefined; }): ({ name: string; capabilities: string[]; budget: { maxIterations: number; maxTokens: number; temperature: number; timeoutMs: number; }; systemPrompt: string; promptTransform?: undefined; } | { name: string; capabilities: never[]; budget: { maxIterations: number; maxTokens: number; temperature: number; timeoutMs: number; }; systemPrompt: string; promptTransform: (_input: string, prev: Record<string, PhaseResult>) => string; })[]; export default SCAN_TASK_CONFIGS;