# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-skill-manifest-s-declared-capability-set-as-non-authoritative-at-registration-time.md # Remnant Warrant: https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-skill-manifest-s-declared-capability-set-as-non-authoritative-at-registration-time.warrant.json # Markdown SHA-256: 11d66f3c30a70c1d6776efb2e488391429bf3bff3f6e22f0b9917fc97a4882c8 # Code AST SHA-256: cf451f5221d9f3cf128f84f5b56e9d0c495e9ae3a7a00f72ac2c9434182c0b82 # Verified Classes: CapabilityEscalationError, SkillManifest, ExecutionEnvelope # Defensive Guards: 6 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 from dataclasses import dataclass, field class CapabilityEscalationError(RuntimeError): """Raised when a skill's enforced execution envelope exceeds its declared scope, or when the runtime cannot prove the manifest is authoritative for the artifact.""" pass @dataclass class SkillManifest: name: str declared_capabilities: frozenset[str] artifact_hash: str manifest_signature_covers: str # "manifest" | "artifact" publisher_key_rotated_within_review_window: bool = False reviewed_artifact_hash: str | None = None @dataclass class ExecutionEnvelope: """What the sandbox actually permits, independent of any declaration.""" allowed_capabilities: frozenset[str] shares_host_credentials: bool import_time_quiescent: bool def authorize_registration(manifest: SkillManifest, envelope: ExecutionEnvelope) -> str: """Returns the authoritative policy mode. Raises if the manifest cannot be treated as an upper bound on authorization.""" if manifest.manifest_signature_covers != "artifact": raise CapabilityEscalationError( f"skill {manifest.name!r}: signature covers manifest, not artifact; " f"declared capabilities are a claim about unsigned code" ) if not envelope.import_time_quiescent: raise CapabilityEscalationError( f"skill {manifest.name!r}: import has side effects; admission is already execution" ) if envelope.shares_host_credentials: raise CapabilityEscalationError( f"skill {manifest.name!r}: executes with host credentials; " f"declared scope bounds nothing" ) if ( manifest.publisher_key_rotated_within_review_window and manifest.reviewed_artifact_hash is not None and manifest.artifact_hash != manifest.reviewed_artifact_hash ): raise CapabilityEscalationError( f"skill {manifest.name!r}: artifact hash {manifest.artifact_hash[:12]} " f"differs from reviewed {manifest.reviewed_artifact_hash[:12]} under rotated key" ) # Enforced envelope must be a subset of declared scope for the manifest to be authoritative. undeclared = envelope.allowed_capabilities - manifest.declared_capabilities if undeclared: raise CapabilityEscalationError( f"skill {manifest.name!r}: sandbox permits undeclared capabilities {sorted(undeclared)}" ) return "manifest-authoritative" def reconcile_observed(manifest: SkillManifest, observed_ops: set[str]) -> None: """Post-execution check: any observed operation outside the declared set is a declaration lie and must be recorded as a discrepancy, not silently accepted.""" undeclared = observed_ops - set(manifest.declared_capabilities) if undeclared: digest = hashlib.sha256(manifest.artifact_hash.encode()).hexdigest()[:12] raise CapabilityEscalationError( f"skill {manifest.name!r} (artifact {digest}): observed undeclared " f"operations {sorted(undeclared)}; manifest is non-authoritative" )