# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-distinguish-adversarial-skill-injection-from-benign-capability-expansion-under-litmus-derived-safety-suites.md
# Remnant Warrant:    https://corpusfetch.com/c/how-should-an-instance-distinguish-adversarial-skill-injection-from-benign-capability-expansion-under-litmus-derived-safety-suites.warrant.json
# Markdown SHA-256:   1deba5bbe3ea712008d9849b978078226eccffcfcc6fbf998b4c00fd12fc97d6
# Code AST SHA-256:   e539a5ba73f03022515de17617a237a3c9c6cd4545e64e16b083b39b67f44dcb
# Verified Classes:   AdversarialSkillInjectionError, SkillDeltaProfile
# Defensive Guards:   1 fail-closed invariants (zero external deps)

from dataclasses import dataclass
from typing import Sequence


class AdversarialSkillInjectionError(RuntimeError):
    """Raised when a skill's delta geometry indicates adversarial injection
    rather than benign capability expansion under a LITMUS-derived suite."""


@dataclass
class SkillDeltaProfile:
    skill_id: str
    single_probe_deltas: Sequence[float]   # |Δ| per isolated probe
    compositional_deltas: Sequence[float]  # |Δ| per co-registered probe pair


def sparsity_conjunction_score(profile: SkillDeltaProfile) -> float:
    max_single = max((abs(d) for d in profile.single_probe_deltas), default=0.0)
    max_comp = max((abs(d) for d in profile.compositional_deltas), default=0.0)
    if max_comp == 0.0:
        return 1.0  # no compositional signal; treat as benign-shaped
    return max_single / max_comp


def classify_skill(profile: SkillDeltaProfile, threshold: float = 0.5) -> str:
    score = sparsity_conjunction_score(profile)
    if score < threshold:
        # Sparse single-probe movement but strong conjunctive movement:
        # the adversarial signature. Do NOT trust the aggregate delta.
        raise AdversarialSkillInjectionError(
            f"Skill {profile.skill_id!r} exhibits sparse-conjunctive delta "
            f"(S={score:.3f} < {threshold}); aggregate safety score is not a "
            f"sufficient statistic -- route to compositional manual review."
        )
    return "benign_expansion"
