UNPKG

autosnippet

Version:

Extract code patterns into a knowledge base for AI coding assistants

85 lines (84 loc) 2.9 kB
/** * KnowledgeMetabolism — 知识新陈代谢总线 * * 治理总线:编排三种进化策略 (矛盾检测 + 冗余分析 + 衰退检测) * 产出 EvolutionProposal,通过 ConfidenceRouter + 状态机 驱动转换。 * * 入口: * - runFullCycle() — 完整治理周期(日常定时 / 手动触发) * - checkDecay() — 只做衰退扫描 * - checkContradictions() — 只做矛盾检测 * - checkRedundancy() — 只做冗余分析 */ import type { ReportStore } from '../../infrastructure/report/ReportStore.js'; import type { SignalBus } from '../../infrastructure/signal/SignalBus.js'; import type { ProposalRepository } from '../../repository/evolution/ProposalRepository.js'; import type { ContradictionDetector, ContradictionResult } from './ContradictionDetector.js'; import type { DecayDetector, DecayScoreResult } from './DecayDetector.js'; import type { RedundancyAnalyzer, RedundancyResult } from './RedundancyAnalyzer.js'; export type ProposalType = 'merge' | 'enhance' | 'deprecate' | 'contradiction' | 'correction'; export interface EvolutionProposal { /** 进化提案类型 */ type: ProposalType; /** 目标 Recipe ID */ targetRecipeId: string; /** 关联 Recipe IDs(合并/矛盾对象) */ relatedRecipeIds: string[]; /** 置信度 0-1 */ confidence: number; /** 触发来源 */ source: 'contradiction' | 'redundancy' | 'decay' | 'enhancement'; /** 描述 */ description: string; /** 原始信号证据 */ evidence: string[]; /** 创建时间 */ proposedAt: number; /** 过期时间 */ expiresAt: number; } export interface MetabolismReport { /** 矛盾检测结果 */ contradictions: ContradictionResult[]; /** 冗余分析结果 */ redundancies: RedundancyResult[]; /** 衰退评估结果 */ decayResults: DecayScoreResult[]; /** 生成的进化提案 */ proposals: EvolutionProposal[]; /** 统计摘要 */ summary: { totalScanned: number; contradictionCount: number; redundancyCount: number; decayingCount: number; proposalCount: number; }; } export declare class KnowledgeMetabolism { #private; constructor(options: { contradictionDetector: ContradictionDetector; redundancyAnalyzer: RedundancyAnalyzer; decayDetector: DecayDetector; signalBus?: SignalBus; reportStore?: ReportStore; proposalRepository?: ProposalRepository; }); /** * 执行完整治理周期 */ runFullCycle(): Promise<MetabolismReport>; /** * 只执行衰退扫描 */ checkDecay(): Promise<DecayScoreResult[]>; /** * 只执行矛盾检测 */ checkContradictions(): Promise<ContradictionResult[]>; /** * 只执行冗余分析 */ checkRedundancy(): Promise<RedundancyResult[]>; }