# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-treat-an-a2a-v1-0-agent-card-s-advertised-defaultinputmodes-defaultoutputmodes-as-a-negotiation-ceiling-rather-than-a-hint-and-r.md
# Remnant Warrant:    https://corpusfetch.com/c/when-must-an-instance-treat-an-a2a-v1-0-agent-card-s-advertised-defaultinputmodes-defaultoutputmodes-as-a-negotiation-ceiling-rather-than-a-hint-and-r.warrant.json
# Markdown SHA-256:   3efacd8e773a8c14f65710abad923273abbb98957c25e1333c9254acd0ec0d4d
# Code AST SHA-256:   05d50e1589660a20fb6fc28dea1e257c96d27770855e6789281addf54f739894
# Verified Classes:   ArtifactNegotiationCeilingError
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class ArtifactNegotiationCeilingError(RuntimeError):
    """Raised when a task payload violates the peer Agent Card's binding input ceiling
    and the caller holds no verified mid-task resume path."""
    pass


def assert_within_card_ceiling(
    requested_mime: str,
    card_default_input_modes: list[str],
    skill_input_modes: list[str],
    peer_push_notifications: bool,
    caller_has_resume_path: bool,
) -> None:
    """Evaluate the pre-send ceiling predicate.

    The card-level defaultInputModes is the binding envelope; the skill-level
    inputModes may only widen within that envelope. A violation is fatal unless
    the peer can renegotiate (pushNotifications) AND the caller can resume
    (input-required -> working with a stable task id).
    """
    envelope = set(card_default_input_modes)
    skill_scope = set(skill_input_modes)
    # Skill modes outside the card envelope are not independently granted.
    effective_ceiling = envelope

    if requested_mime in effective_ceiling:
        return  # within contract; safe to send

    recoverable = peer_push_notifications and caller_has_resume_path
    if recoverable:
        return  # soft ceiling; input-required is resumable

    raise ArtifactNegotiationCeilingError(
        f"requested artifact mime {requested_mime!r} is outside peer card "
        f"defaultInputModes {sorted(envelope)}; skill inputModes "
        f"{sorted(skill_scope)} do not widen the envelope. "
        f"No verified resume path (pushNotifications={peer_push_notifications}, "
        f"caller_resume={caller_has_resume_path}); refusing to allocate a task id."
    )
