/** * 智能错误记录与学习系统 * * 记录在会话过程中纠正的错误,帮助 agent 避免重复犯错。 * 支持错误分类、模式识别和预防提醒。 */ /** * 错误严重级别 */ export type ErrorSeverity = 'low' | 'medium' | 'high' | 'critical'; /** * 错误类型分类 */ export type ErrorCategory = 'syntax' | 'logic' | 'api_usage' | 'type_error' | 'runtime' | 'workflow' | 'dependency' | 'config' | 'test' | 'performance' | 'security' | 'other'; /** * 错误记录条目 */ export interface ErrorRecord { id: string; timestamp: string; sessionId: string; taskId?: string; title: string; description: string; severity: ErrorSeverity; category: ErrorCategory; tags: string[]; context: { filePath?: string; lineNumber?: number; codeSnippet?: string; errorMessage?: string; stackTrace?: string; }; fix: { description: string; codeBefore?: string; codeAfter?: string; fixBy: 'user' | 'agent' | 'system'; fixTimestamp: string; }; learning: { rootCause: string; prevention: string; relatedDocs?: string[]; similarErrors?: string[]; }; stats: { occurrenceCount: number; lastOccurrence: string; reviewCount: number; }; status: 'active' | 'resolved' | 'suppressed'; } /** * 错误模式(用于识别重复错误) */ export interface ErrorPattern { id: string; name: string; description: string; category: ErrorCategory; severity: ErrorSeverity; matchingRules: { keywords: string[]; filePatterns?: string[]; errorPatterns?: string[]; codePatterns?: string[]; }; relatedErrorIds: string[]; createdAt: string; updatedAt: string; occurrenceCount: number; } /** * 经验教训 */ export interface Lesson { id: string; title: string; content: string; category: ErrorCategory; relatedErrorIds: string[]; relatedTaskIds: string[]; createdAt: string; updatedAt: string; priority: 'low' | 'medium' | 'high'; reminderTrigger?: { filePatterns?: string[]; keywords?: string[]; commands?: string[]; }; } /** * 错误过滤器 */ export interface ErrorFilter { category?: ErrorCategory; severity?: ErrorSeverity; status?: ErrorRecord['status']; taskId?: string; sessionId?: string; tags?: string[]; since?: string; until?: string; } /** * 学习管理器 */ export declare class LearningManager { private basePath; private initialized; constructor(basePath?: string); /** * 初始化学习系统目录结构 */ initialize(): Promise; /** * 记录一个新错误 */ recordError(error: Omit): Promise; /** * 获取所有错误记录 */ getErrors(filter?: ErrorFilter): Promise; /** * 获取单个错误详情 */ getError(errorId: string): Promise; /** * 更新错误记录 */ updateError(errorId: string, updates: Partial>): Promise; /** * 添加经验教训 */ addLesson(lesson: Omit): Promise; /** * 获取所有经验教训 */ getLessons(filter?: { category?: ErrorCategory; priority?: Lesson['priority']; }): Promise; /** * 获取当前会话应该记住的教训(启动时提醒) */ getReminderForSession(sessionContext: { taskId?: string; filePaths?: string[]; command?: string; }): Promise; /** * 标记错误为已复习 */ markErrorReviewed(errorId: string): Promise; /** * 获取最近的错误 */ getRecentErrors(limit?: number): Promise; /** * 获取最常见的错误类别 */ getTopCategories(limit?: number): Promise>; /** * 生成统计报告 */ generateReport(options?: { since?: string; until?: string; }): Promise<{ totalErrors: number; totalLessons: number; byCategory: Record; bySeverity: Record; recentTrend: Array<{ date: string; count: number; }>; topLessons: Lesson[]; }>; private generateId; private loadErrors; private loadErrorsUnsafe; private saveErrorsUnsafe; private loadLessons; private loadLessonsUnsafe; private saveLessonsUnsafe; private updateIndex; private findSimilarError; private similarity; private filterErrors; private matchPattern; } /** * 获取学习管理器实例 */ export declare function getLearningManager(basePath?: string): LearningManager; /** * 快速记录错误(便捷函数) */ export declare function quickRecordError(params: { title: string; description: string; category: ErrorCategory; severity?: ErrorSeverity; filePath?: string; errorMessage?: string; fixDescription: string; rootCause: string; prevention: string; sessionId: string; taskId?: string; }, basePath?: string): Promise; //# sourceMappingURL=learning.d.ts.map