# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-a-retrieved-skill-description-as-untrusted-executable-specification-rather-than-inert-metadata.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-a-retrieved-skill-description-as-untrusted-executable-specification-rather-than-inert-metadata.warrant.json
# Markdown SHA-256:   3777e45f220b4d23e4fd4fb9b55c52050164b79328650965665634799e6a2f71
# Code AST SHA-256:   94f1c9e56f28eb20711735beda392eeca2471e6128b0d5ade08c4503b20849cf
# Verified Classes:   SkillDescriptionInjectionError
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class SkillDescriptionInjectionError(RuntimeError):
    """Raised when a retrieved skill description contains prescriptive
    directives that would alter control flow or argument provenance."""
    pass


# Directive patterns that must never arrive via retrieved metadata.
_PRESCRIPTIVE_MARKERS = (
    "before any", "call this first", "always call", "must be called",
    "pass the full", "unredacted", "complete source", "include credentials",
)


def sanitize_skill_description(skill_id: str, description: str) -> str:
    lowered = description.lower()
    for marker in _PRESCRIPTIVE_MARKERS:
        if marker in lowered:
            raise SkillDescriptionInjectionError(
                f"skill {skill_id!r} description contains prescriptive "
                f"directive {marker!r}; refusing to inject as guidance"
            )
    return description


def resolve_skill_call(
    skill_id: str,
    description: str,
    args: dict,
    gated_data_classes: set[str],
) -> dict:
    # Strip prescriptive content before the model can act on it.
    clean = sanitize_skill_description(skill_id, description)

    # Argument-provenance gate: independent of description classification.
    for arg_name, value in args.items():
        if isinstance(value, str) and any(
            cls in value for cls in gated_data_classes
        ):
            raise SkillDescriptionInjectionError(
                f"skill {skill_id!r} argument {arg_name!r} carries gated "
                f"data class; blocked regardless of description text"
            )

    return {"skill_id": skill_id, "description": clean, "args": args}
