/** * Pattern set loader. * * Patterns live in JSON so they can be extended or overridden without touching code, which matters * because the multilingual and client specific surface keeps growing. A broken pattern is skipped * with a warning rather than crashing the process: a bad regex in a config file must never take * down a corpus run. * * Set EMAIL_CONTENT_PATTERNS to a directory to override the bundled sets. Files are matched by * name, so an override directory may contain only the files it wants to replace. */ export interface LinePattern { id: string; lang?: string; role?: string; client?: string; strength: number; regex: RegExp; } export interface SelectorPattern { id: string; client: string; role: 'quote' | 'attribution' | 'separator' | 'signature' | 'disclaimer' | 'new' | 'hint'; strength: number; selector: string; prevalence: number; } export interface PatternSets { replyHeaders: LinePattern[]; forwardHeaders: LinePattern[]; quotedHeaderFields: LinePattern[]; /** Phrases announcing that the reply is written into the quoted text. Matched anywhere in a line. */ inlineAnnouncements: LinePattern[]; signatureDelimiters: LinePattern[]; signaturePhrases: LinePattern[]; disclaimerPhrases: LinePattern[]; htmlSelectors: SelectorPattern[]; /** Ids of patterns that failed to compile, for diagnostics. */ invalid: string[]; } /** * A classifier asset is missing or corrupt. * * An installation defect, not malformed email, and therefore deliberately outside the per message * fail-soft path. Without the pattern files every detector returns nothing: no reply header is * recognised, no quoted history is found, and every message comes back looking like new content. * That reads as success, which makes it the worst possible failure mode for a package whose whole * job is to know which parts of a message are history. */ export declare class PatternAssetError extends Error { readonly code = "pattern_assets_unusable"; readonly file: string | null; constructor(message: string, file?: string | null); } /** Total compiled patterns across every set. */ export declare function countPatterns(sets: PatternSets): number; /** * Fail loudly when no pattern survived loading. * * The bundled patterns are read from disk at runtime through path.join(__dirname, 'patterns'). * @yao-pkg/pkg detects that form and bundles the directory automatically, which is why consumers * need no pkg asset configuration, but it is a static analysis heuristic rather than a guarantee. * If it ever fails, or the files are missing from a published tarball, every detector quietly * returns nothing: no reply header is recognised and reply history stops being detected. * * The failure direction is at least the safe one, since nothing can be hidden without an anchor. * But a build that silently extracts nothing useful should not pass unnoticed. */ export declare function assertPatternsLoaded(sets: PatternSets, source: string): void; /** Load and compile all pattern sets. Cached after the first call. */ export declare function loadPatterns(overrideDir?: string | null): PatternSets; /** Where the pattern sets used by `extract()` and `analyze()` came from. */ export interface PatternSource { /** The override directory named by EMAIL_CONTENT_PATTERNS, or null for the bundled sets only. */ override: string | null; /** * Files actually read from the override directory. Any file not listed came from the bundled * set, because an override directory may replace only some files. Empty when `override` is * null, and also when the directory exists but holds none of the expected file names. */ overriddenFiles: string[]; } /** * Report which pattern source is in effect, so a caller can log it at startup. * * The override is read from an unprefixed environment variable, so it can be set for a host * process without anyone noticing. Nothing in the extraction result says the patterns differ from * the bundled ones; this is the only way to find out. */ export declare function patternSource(): PatternSource; /** Reset the cache. Used by tests that swap pattern directories. */ export declare function resetPatternCache(): void; //# sourceMappingURL=patterns.d.ts.map