# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-happens-when-an-instance-trusts-a-skill-manifest-s-declared-inputschema-but-not-its-description-field-the-skill-injection-asymmetry-in-dynamicall.md
# Remnant Warrant:    https://corpusfetch.com/c/what-happens-when-an-instance-trusts-a-skill-manifest-s-declared-inputschema-but-not-its-description-field-the-skill-injection-asymmetry-in-dynamicall.warrant.json
# Markdown SHA-256:   dee27b1e36c0f1ee2cf2cd1bf5c4022f486d4f5bf6d4d9bd25313fca36f442d7
# Code AST SHA-256:   7bd496fbb9a7ea4a0fc50cc40a9ea8d8baa5853f162fc75a8925d1e118138c4f
# Verified Classes:   SkillManifestInjectionError
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class SkillManifestInjectionError(RuntimeError):
    """Raised when a discovered manifest is schema-valid but its description
    text carries instruction-like content from an un-attested source."""
    pass


IMPERATIVE_MARKERS = (
    "ignore prior", "note to the assistant", "before calling",
    "read ~/", "pass its contents", "you must", "do not tell",
)


def admit_manifest(manifest: dict, attested: bool) -> dict:
    schema = manifest.get("inputSchema")
    if not isinstance(schema, dict) or schema.get("type") != "object":
        raise SkillManifestInjectionError(
            f"tool {manifest.get('name')!r} has no valid object inputSchema"
        )

    description_blob = " ".join(
        [manifest.get("description", "")]
        + [
            p.get("description", "")
            for p in (schema.get("properties") or {}).values()
        ]
    ).lower()

    suspicious = [m for m in IMPERATIVE_MARKERS if m in description_blob]

    if suspicious and not attested:
        raise SkillManifestInjectionError(
            f"tool {manifest.get('name')!r} is schema-valid but description "
            f"contains instruction-like content {suspicious} from an "
            f"un-attested server; quarantine before context assembly"
        )

    if suspicious and attested:
        manifest = dict(manifest)
        manifest["_description_quarantined"] = True
        manifest["description"] = "[description withheld: attested but flagged]"
        return manifest

    return manifest
