/** * Bayesian Anomaly Score Calculator. * * Computes per-token anomaly scores from top-K logprob distributions, * approximating Misra's Bayesian geometry signals. Used by the streaming * verifier (Task 11) and MCP server (Task 12) in the production pipeline. * * 8 features extracted per token: * 1. outputEntropy — Shannon entropy of the top-K distribution * 2. entropyDelta — Change in entropy from previous token * 3. distributionGini — Normalized Gini coefficient: G / (1 - 1/K) * 4. repetitionConfidence — How often this token appeared in prompt * 5. structuralMismatch — Placeholder (0) — wired in Task 10.5 * 6. bayesianUpdateRate — KL divergence proxy: |H_t - H_{t-1}| / H_t * 7. distributionModality — Number of modes in the distribution * 8. entropyAcceleration — Second derivative of entropy over time * * Score: sigmoid(weights . features + intercept) * Depth: green (< greenThreshold), red (> redThreshold), amber otherwise */ import type { TokenLogprobs, BayesianAnomalyScore, BASConfig } from './types.js'; export declare class BASCalculator { private readonly config; private prevEntropy; private prevDelta; private promptTokenSet; private structuralEntropy; private language; constructor(config: BASConfig); /** Set the language for structural entropy computation. */ setLanguage(lang: string): void; /** Feed prompt tokens so repetitionConfidence can be computed. */ setPromptTokens(tokens: string[]): void; /** Reset sequential state between sequences. */ reset(): void; /** Process a single token and return its BAS result. */ processToken(token: TokenLogprobs): BayesianAnomalyScore; private extractFeatures; private computeScore; private classifyDepth; }