/** * LexSona Behavioral Rules API * * Internal API endpoints for behavioral rules: * - `getRules(context, options)` - Retrieve applicable rules for context * - `recordCorrection(db, correction)` - Capture user feedback * * These are internal APIs (not exposed via HTTP yet). * Used by LexRunner integration. * * @see docs/LEXSONA.md * @see docs/research/LexSona/MATH_FRAMEWORK_v0.1.md */ import Database from "better-sqlite3-multiple-ciphers"; import type { BehaviorRuleWithConfidence, RuleContext, Correction, GetRulesOptions } from "../../memory/store/lexsona-types.js"; /** * Retrieve applicable behavioral rules for a given context. * * Rules are filtered by: * - Exact match on module_id (if provided in context) * - Fuzzy match on task_type (if provided in context) * - Minimum observation count (N ≥ minN, default 3) * - Minimum effective confidence (confidence * decay_factor) * * Rules are sorted by effective_confidence (descending). * * @param db - Database connection * @param context - Context for filtering rules * @param options - Options for filtering (minN, minConfidence, limit) * @returns Array of applicable rules sorted by confidence * * @example * ```typescript * const rules = getRules(db, { * module_id: 'src/services/auth', * task_type: 'code-review', * environment: 'github-copilot' * }); * // Returns rules applicable to the auth module for code review * ``` */ export declare function getRules(db: Database.Database, context?: RuleContext, options?: GetRulesOptions): BehaviorRuleWithConfidence[]; /** * Record a user correction to update behavioral rules. * * If a matching rule exists (same module_id and text): * - Reinforcement (polarity=1): Increment α (alpha), increment N * - Counterexample (polarity=-1): Increment β (beta), increment N * * If no matching rule exists: * - Create new rule with initial values: α=α_0+1, β=β_0, N=1 * * The last_observed timestamp is always updated to enable decay calculation. * * @param db - Database connection * @param correction - The correction to record * @returns The updated or created rule with confidence scores * * @example * ```typescript * // Record a positive correction (reinforcement) * const rule = recordCorrection(db, { * context: { module_id: 'src/services/auth' }, * correction: 'Always use JWT for authentication in this module', * category: 'security_policy', * severity: 'must' * }); * * // Record a negative correction (counterexample) * const rule = recordCorrection(db, { * context: { module_id: 'src/utils' }, * correction: 'Use lodash for utility functions', * polarity: -1 // This is a counterexample * }); * ``` */ export declare function recordCorrection(db: Database.Database, correction: Correction): BehaviorRuleWithConfidence;