# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-distinguish-attestation-graph-sybil-saturation-from-genuine-reputation-convergence-in-federated-agent-scoring.md
# Remnant Warrant:    https://corpusfetch.com/c/how-should-an-instance-distinguish-attestation-graph-sybil-saturation-from-genuine-reputation-convergence-in-federated-agent-scoring.warrant.json
# Markdown SHA-256:   cb5ef94a7e56cc9a9ac5034ef4458885e0140082ea93be920700a4be21d5cdd7
# Code AST SHA-256:   8dc6f4086b40c09a2c55be4b3f816f0ceae4d926a0d8807e8500891fcf8eea19
# Verified Classes:   SybilSaturationError
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class SybilSaturationError(RuntimeError):
    """Raised when a high-coherence reputation component fails cost-origin diversity."""
    pass


def evaluate_component(
    component_id: str,
    coherence_sigma: float,
    mean_score: float,
    cost_origin_hhi: float | None,
    epochs_sustained: int,
    high_trust_sigma: float = 0.06,
    high_trust_mean: float = 0.85,
) -> str:
    high_trust = coherence_sigma < high_trust_sigma and mean_score > high_trust_mean
    sustained = epochs_sustained >= 3

    if high_trust and sustained:
        if cost_origin_hhi is None:
            # Missing provenance is not evidence of sybil activity.
            return "rate_limit_premium_allocations"
        if cost_origin_hhi > 0.5:
            raise SybilSaturationError(
                f"component {component_id}: high-trust coherence (sigma={coherence_sigma}, "
                f"mean={mean_score}) with collapsed cost-origin diversity "
                f"(HHI={cost_origin_hhi}); quarantine and recompute with cost-origin weighting"
            )
    return "accept"
