/** * Rule Manager - Simplified for Core Build * Manage learned rules and best practices * @requirement REQ-V2-024 - Rule Management */ import type { WorkflowState } from '@shadel/workflow-core'; import { StateBasedPattern } from '../core/pattern-provider.js'; /** * Rule structure */ export interface Rule { id: string; title: string; content: string; source?: string; score?: number; createdAt: string; applicableStates?: WorkflowState[]; requiredStates?: WorkflowState[]; validation?: { type: 'file_exists' | 'command_run' | 'code_check' | 'custom'; rule: string; message: string; severity: 'error' | 'warning' | 'info'; }; } /** * Rule collection */ export interface RuleCollection { rules: Rule[]; lastUpdated: string; } /** * Rule Manager - Manage rules and best practices * @requirement REQ-V2-024 - Rule management system * @requirement v3.1.0 - Support both rules.json and patterns.json during transition */ export declare class RuleManager { private rulesFile; private patternsFile; private rulesDir; /** * Get all rules/patterns * v3.1.0: Supports both patterns.json (new) and rules.json (legacy) * Priority: patterns.json > rules.json */ getRules(): Promise; /** * Add a new rule * @requirement REQ-V2-024 - Add rules */ addRule(rule: Omit): Promise; /** * Update an existing rule */ updateRule(id: string, updates: Partial): Promise; /** * Delete a rule */ deleteRule(id: string): Promise; /** * Import rules from markdown file * @requirement REQ-V2-024 - Import rules from other projects */ importFromMarkdown(filePath: string, source: string): Promise; /** * Parse rules from markdown */ private parseMarkdownRules; /** * Export rules to markdown */ exportToMarkdown(outputPath: string): Promise; /** * Search rules by keyword */ search(keyword: string): Promise; /** * Save rules/patterns to file * v3.1.0+: Always saves to patterns.json (never creates rules.json for new projects) * Only reads from rules.json for backward compatibility with legacy projects */ private saveRules; /** * Get rules count */ count(): Promise; /** * Clear all rules (dangerous!) */ clear(): Promise; /** * Check missing rules - NEW for v2.0 * @requirement REQ-V2-003 - Check what rules are missing */ checkMissingRules(): Promise<{ missing: string[]; present: string[]; }>; /** * Get rule template - NEW for v2.0 * @requirement REQ-V2-003 - Provide rule templates */ getRuleTemplate(id: string): Promise; /** * Get rule info - NEW for v2.0 * @requirement REQ-V2-003 - Show detailed rule information */ getRuleInfo(id: string): Promise<(Rule & { description?: string; rationale?: string; examples?: string[]; }) | null>; /** * Get patterns for specific state * Filters patterns by applicableStates or requiredStates * * @param state - Workflow state to filter by * @returns State-relevant patterns */ getPatternsForState(state: WorkflowState): Promise; /** * Get mandatory patterns for specific state * Filters patterns where requiredStates includes the state * * @param state - Workflow state to filter by * @returns Mandatory patterns for state */ getMandatoryPatternsForState(state: WorkflowState): Promise; /** * Generate template for a rule (placeholder) */ generateTemplate(ruleId: string, projectRoot: string): Promise; /** * Validate rules format (placeholder) */ validateRules(projectRoot: string): Promise<{ valid: number; details: any[]; }>; }