UNPKG

autosnippet

Version:

Extract code patterns into a knowledge base for AI coding assistants

186 lines (185 loc) 5.47 kB
/** * scan-recipe.js 扫描专用 Recipe 收集工具 * * 与冷启动 submit_knowledge 使用完全相同的字段 schema, * 但不入库 仅做本地验证 + 内存收集。 * * 扫描 Produce 阶段 LLM 调用此工具逐个提交 Recipe, * 执行完成后由 AgentFactory.scanKnowledge() toolCalls 中提取。 * * 设计原因: * - 冷启动 Producer 通过 submit_knowledge 工具逐个提交候选(工具驱动) * - 扫描 Produce 之前是纯 JSON 文本输出,LLM 容易 hallucinate 错误工具调用 * - 统一为工具驱动模式:相同 schema 相同字段质量 相同下游消费 * * @module scan-recipe */ export declare const collectScanRecipe: { name: string; description: string; parameters: { type: string; properties: { title: { type: string; description: string; }; language: { type: string; description: string; }; description: { type: string; description: string; }; tags: { type: string; items: { type: string; }; description: string; }; content: { type: string; description: string; properties: { pattern: { type: string; description: string; }; markdown: { type: string; description: string; }; rationale: { type: string; description: string; }; }; required: string[]; }; kind: { type: string; enum: string[]; description: string; }; category: { type: string; description: string; }; trigger: { type: string; description: string; }; doClause: { type: string; description: string; }; dontClause: { type: string; description: string; }; whenClause: { type: string; description: string; }; coreCode: { type: string; description: string; }; headers: { type: string; items: { type: string; }; description: string; }; usageGuide: { type: string; description: string; }; knowledgeType: { type: string; description: string; }; reasoning: { type: string; description: string; properties: { whyStandard: { type: string; description: string; }; sources: { type: string; items: { type: string; }; description: string; }; confidence: { type: string; description: string; }; }; required: string[]; }; complexity: { type: string; enum: string[]; }; scope: { type: string; enum: string[]; }; }; required: string[]; }; /** * Handler 本地验证 + 内存收集(不入库) * * 验证通过后返回 { status: 'collected', recipe: {...} } * AgentFactory.scanKnowledge() toolCalls 结果中提取 recipes。 */ handler: (params: Record<string, unknown>, _ctx: unknown) => Promise<{ status: string; error: string; hint: string; title?: undefined; recipe?: undefined; } | { status: string; title: string; recipe: { title: string; language: string; description: string; tags: string[]; content: { pattern: string; markdown: string; rationale: string; }; kind: string | undefined; category: string; trigger: string | undefined; doClause: string; dontClause: string; whenClause: string; coreCode: string; headers: string[]; usageGuide: string; knowledgeType: string; reasoning: { whyStandard: string; sources: string[]; confidence: number; }; complexity: string; scope: string; }; error?: undefined; hint?: undefined; }>; }; export default collectScanRecipe;