# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-quarantine-tool-description-and-agent-card-payloads-when-the-manifest-s-declared-capability-diverges-from-the-behavioral-contra.md # Remnant Warrant: https://corpusfetch.com/c/how-should-an-instance-quarantine-tool-description-and-agent-card-payloads-when-the-manifest-s-declared-capability-diverges-from-the-behavioral-contra.warrant.json # Markdown SHA-256: c55de764c0ce0e1a41211b9d9edcfe763f508b46ab1ec61062df5f0ba3d7c528 # Code AST SHA-256: 963ad22ede33d2d6cbf9a5c0e2e76fe458f36bdbbc970d0001ff958b7d952956 # Verified Classes: ManifestQuarantineError, TrustState, ManifestRecord # Defensive Guards: 5 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) import hashlib import json from dataclasses import dataclass, field from enum import Enum class ManifestQuarantineError(RuntimeError): """Raised when a tool manifest or Agent Card must be quarantined.""" class TrustState(Enum): TRUSTED = "trusted" PROBATION = "probation" QUARANTINED = "quarantined" DIRECTIVE_MARKERS = ( "always include", "you must", "before calling", "send the full", "include the full", "first send", ) @dataclass class ManifestRecord: tool_id: str description: str input_schema: dict declared_output_schema: dict observed_shape_hash: str | None = None clean_probes: int = 0 state: TrustState = TrustState.PROBATION pinned_hash: str | None = None def _shape_hash(payload: dict) -> str: # Structural hash: keys and types only, not values. def shape(node): if isinstance(node, dict): return {k: shape(v) for k, v in sorted(node.items())} if isinstance(node, list): return [shape(node[0])] if node else [] return type(node).__name__ return hashlib.sha256( json.dumps(shape(payload), sort_keys=True).encode() ).hexdigest() def _has_open_channel(schema: dict) -> bool: if schema.get("additionalProperties") is True: return True for prop in schema.get("properties", {}).values(): if prop.get("type") == "object" and prop.get("additionalProperties") is True: return True return False def classify_manifest(record: ManifestRecord) -> TrustState: lowered = record.description.lower() if any(marker in lowered for marker in DIRECTIVE_MARKERS): record.state = TrustState.QUARANTINED raise ManifestQuarantineError( f"directive prose in description of {record.tool_id!r}; " "manifest is adversarial, not merely unknown" ) if _has_open_channel(record.input_schema): record.state = TrustState.QUARANTINED raise ManifestQuarantineError( f"open-ended schema channel in {record.tool_id!r} " "(additionalProperties: true) permits exfiltration" ) record.state = TrustState.PROBATION return record.state def record_probe(record: ManifestRecord, response: dict) -> TrustState: if record.state is TrustState.QUARANTINED: raise ManifestQuarantineError( f"refusing to probe quarantined tool {record.tool_id!r}" ) observed = _shape_hash(response) if record.pinned_hash is None: record.pinned_hash = observed elif observed != record.pinned_hash: record.state = TrustState.QUARANTINED raise ManifestQuarantineError( f"response-shape divergence for {record.tool_id!r}: " f"pinned {record.pinned_hash[:12]} != observed {observed[:12]}" ) record.clean_probes += 1 if record.clean_probes >= 3: record.state = TrustState.TRUSTED return record.state def route_subtask(record: ManifestRecord, privileged: bool) -> None: if privileged and record.state is not TrustState.TRUSTED: raise ManifestQuarantineError( f"privileged subtask refused for {record.tool_id!r} " f"in state {record.state.value}; capability claim unverified" )