/** * Unified exclusion rules engine. * * All message filtering rules live in the `exclusion_rules` DB table. * The parser and flagging system read from this table — no hardcoded filters. * * Rule types: * - content_prefix: message content starts with pattern * - cwd_pattern: JSONL entry cwd field contains pattern * - dir_name: source file directory name matches pattern * - skill_invocation: message matches a skill invocation syntax (regex) * * Match modes: * - starts_with: content.startsWith(pattern) * - contains: content.includes(pattern) * - exact: content === pattern * - regex: new RegExp(pattern).test(content) */ import type { Client } from "@libsql/client"; import type { Backend } from "./backends.js"; export interface ExclusionRule { id: number; platform: string; ruleType: string; pattern: string; matchMode: string; description: string; source: string; templateContent: string; isActive: boolean; } export interface CompiledRules { contentPrefix: Array<{ rule: ExclusionRule; test: (content: string) => boolean; }>; cwdPattern: Array<{ rule: ExclusionRule; test: (cwd: string) => boolean; }>; dirName: Array<{ rule: ExclusionRule; test: (dirName: string) => boolean; }>; skillInvocation: Array<{ rule: ExclusionRule; test: (content: string, platform: string) => boolean; }>; } export declare function loadExclusionRules(client: Client): Promise; export declare function compileRules(rules: ExclusionRule[]): CompiledRules; /** Check if a message content should be excluded (content_prefix rules). */ export declare function shouldExcludeContent(compiled: CompiledRules, content: string, platform: string): { excluded: boolean; ruleId: number | null; }; /** Check if a CWD indicates a programmatic (non-human) session. */ export declare function shouldExcludeCwd(compiled: CompiledRules, cwd: string): { excluded: boolean; ruleId: number | null; }; /** Check if a source directory name should be excluded. */ export declare function shouldExcludeDir(compiled: CompiledRules, dirName: string): { excluded: boolean; ruleId: number | null; }; /** * Flag existing messages that match exclusion rules. * Checks skill_invocation and content_prefix rules against unflagged messages. * Also checks template_content via hash comparison. */ export declare function flagExcludedMessages(client: Client): Promise; /** * Discover skills from all backends and upsert as exclusion rules. * Also upserts into skills table for template content storage. */ export declare function discoverAndSyncRules(client: Client, backends: Backend[]): Promise<{ skillsFound: number; rulesUpserted: number; }>; /** * Seed system-level exclusion rules. * These are platform-inherent rules that don't come from skill discovery. * Uses INSERT OR IGNORE so they're only added once. */ export declare function seedSystemRules(client: Client): Promise;