autosnippet
Version:
Extract code patterns into a knowledge base for AI coding assistants
51 lines (50 loc) • 1.63 kB
TypeScript
/**
* ContradictionDetector — Recipe 级矛盾检测
*
* 从 MemoryConsolidator 提升:Memory 层只做 session 内去重,
* Recipe 层做跨 lifecycle 的持久化矛盾检测。
*
* 检测维度:
* 1. 否定模式检测(中/英双语 negation patterns)
* 2. 主题词重叠 ≥ 30% Jaccard
* 3. doClause vs dontClause 交叉引用
* 4. guard regex 互斥检测
*
* 结果:硬矛盾 (confidence ≥ 0.8) / 软矛盾 (0.4-0.8)
*/
import type { SignalBus } from '../../infrastructure/signal/SignalBus.js';
import type KnowledgeRepositoryImpl from '../../repository/knowledge/KnowledgeRepository.impl.js';
export interface ContradictionResult {
recipeA: string;
recipeB: string;
confidence: number;
type: 'hard' | 'soft';
evidence: string[];
}
interface RecipeEntry {
id: string;
title: string;
lifecycle: string;
doClause: string | null;
dontClause: string | null;
guardPattern: string | null;
description: string | null;
content_markdown: string | null;
}
export declare class ContradictionDetector {
#private;
constructor(knowledgeRepo: KnowledgeRepositoryImpl, options?: {
signalBus?: SignalBus;
});
/**
* 检测所有 active/staging/evolving Recipe 之间的矛盾
*/
detectAll(): Promise<ContradictionResult[]>;
/**
* 检测两条 Recipe 是否矛盾
*/
detectPair(a: RecipeEntry, b: RecipeEntry): ContradictionResult | null;
/** 提取主题词(公开为静态方法,供 RedundancyAnalyzer 复用) */
static extractTopicWords(text: string): Set<string>;
}
export {};