/** * Skew detector. Identifies patterns where one slot value dominates * (>= min_concentration of events). Used by `log10x_find_skew` to * surface sampling opportunities: "this slot is `get` 78% of events, * sample the get case at 1/N and save volume without losing signal." * * Algorithm: * 1. Run aggregateSlotsBySymbolMessage on the input patterns * (Option B merge by precedingToken / semantic slot name). * 2. For each aggregated pattern, find slots where dominantPct >= min. * 3. Rank findings by (dominantPct × bytesShare) so strong skew on * a big-spend pattern surfaces first. * 4. Surface up to top_n patterns; for each, the skewed-slot list * and an estimated savings opportunity at 1/N sampling of the * dominant value. * * Sampling-opportunity math: if a pattern has `count` events and * `dominantPct` of them carry the dominant value, sampling those at * 1/N drops (1 - 1/N) × dominantPct of total events. Translated to * bytes: (1 - 1/N) × dominantPct × bytes. At a typical N=10 and * dominantPct=0.78, that is 0.7 × bytes — i.e. 70% volume savings on * this pattern alone. */ import type { ExtractedPattern } from '../pattern-extraction.js'; import { type AggregatedSlot } from './slot-aggregation.js'; import type { Template } from '../cli-output-parser.js'; export interface SkewFinding { patternIdentity: string; templateHashes: string[]; costPerMonthUsd?: number; totalEvents: number; totalBytes: number; skewedSlots: Array<{ slotName: string; precedingToken?: string; dominantValue: string; dominantPct: number; distinctCount: number; aggregationStatus: AggregatedSlot['aggregationStatus']; }>; /** Projected savings as a fraction of pattern bytes if dominant case is sampled 1/sampleN. */ samplingOpportunityPct: number; } export interface FindSkewOptions { minConcentration?: number; topN?: number; minEvents?: number; sampleN?: number; costPerMonthByIdentity?: (identity: string) => number | undefined; templates?: Map; } export declare function findSkew(patterns: ExtractedPattern[], opts?: FindSkewOptions): SkewFinding[];