UNPKG

autosnippet

Version:

Extract code patterns into a knowledge base for AI coding assistants

37 lines (36 loc) 1.34 kB
/** * TopicClassifier — 按主题分组 KnowledgeEntry * * 将 kind='pattern' 的知识条目按主题分组,用于 Channel B(Smart Rules)。 * 每个主题对应一个 .mdc 文件,设 alwaysApply: false + 丰富的 description。 */ import type { KnowledgeEntryProps } from '../../domain/knowledge/KnowledgeEntry.js'; export declare class TopicClassifier { projectName: string; /** @param projectName 项目名称 */ constructor(projectName?: string); /** * 将 patterns 按主题分组 * @param entries KnowledgeEntry 数组 (kind='pattern') * @returns { topic: [entries] } */ group(entries: KnowledgeEntryProps[]): Record<string, KnowledgeEntryProps[]>; /** * 为主题构建 description — Agent 判断关联性的唯一依据 * * v3: 动态丰富化 — 除硬编码 baseKeywords 外,还从 entries 的 * tags, whenClause, trigger 中提取高价值关键词,让 Cursor 的 * description 匹配更精准。 */ buildDescription(topic: string, entries: KnowledgeEntryProps[]): string; /** * 分类单个 entry 到主题 — 直读 AI 预计算的 topicHint */ private _classifyEntry; /** * 从 entry 提取关键词 */ private _extractKeywords; private _topicLabel; } export default TopicClassifier;