# SPDX-FileCopyrightText: 2026 David Porto Baraldés (Homo Universalis / Viveka) # SPDX-License-Identifier: Apache-2.0 """ HU-ETERNAL-PROVENANCE v1.0 — Temple Four-Folio Symbiotic Adapter (`logic/provenance/temple_folio_viii_adapter.py`). Couples the zero-dependency standalone `quantum_eternal_provenance_core.py` (Living Folio VIII) with Living Folios V (`HU-EMBODIED-SYMBIOSIS`), VI (`HU-UNIFIED-CONSCIOUSNESS`), and VII (`HU-SYMBIOTIC-BRIDGE`), WITHOUT importing `logic.engines`: 1. EternalProvenanceEnvelope (Folio VIII) -> VerifiedKnowledgeEnvelope (Folio VI): Verifies the Triple Sovereign Seal (NIST P-256 ES256 low-S + WOTS+-SHA256 + FIPS 204 Ring-NTT), RFC 6962 C2PA-MCP hop inclusion proofs, EU AI Act Art. 50(2) disclosure, and revocation status before issuing a `VerifiedKnowledgeEnvelope` for Level 2 / Level 3 speech or Knowledge Vault deposit. 2. Author Moral Veto / Cost-Zero Stop -> Four-Folio Cascade (Folios V + VI + VII + VIII): Propagates `AUTHOR_MORAL_VETO` or `COST_ZERO_STOP` simultaneously to: - Folio V physical body (`Twist` = exact zero in Q^3), - Folio VI conversational levels 1, 2, and 3 (`WordCircleArbiter`), - Folio VII A2A <-> MCP capability delegation subtree (`RevocationRegistry`), - Folio VIII C2PA-MCP provenance lineage subtree (`EternalRevocationRegistry`), isolating sibling works and upstream ancestors with zero collateral damage. Honest scope (`WO-13`): supervisory software self-assessment only; never a safety-rated function, never a certified hardware security module, and never legal copyright registration advice. """ from __future__ import annotations import threading import time from typing import Any, Callable, Final, Mapping, Sequence from logic.consciousness.unified_consciousness_core import ( DEFAULT_ENVELOPE_TTL_MS, EVENT_DEPOSIT_SILENT_ENVELOPE, EVENT_L2_DELIVER_ENVELOPE_AND_SPEECH, ConsciousnessEvent, VerifiedKnowledgeEnvelope, WordCircleArbiter, issue_verified_knowledge_envelope, ) from logic.provenance.quantum_eternal_provenance_core import ( AUTHOR_MORAL_VETO, COST_ZERO_STOP, PROTOCOL_VERSION, EternalProvenanceEnvelope, EternalRevocationRegistry, ProvenanceError, RevokedProvenanceError, TripleSovereignKeyring, TripleSovereignPublicKey, rule14_mask_provenance_text, verify_eternal_provenance_envelope, ) from logic.robotics.embodied_edge_core import ZERO_TWIST, strict_bool from logic.robotics.ros2_embodied_symbiosis_bridge import EmbodiedSymbiosisGate from logic.symbiosis.a2a_mcp_symbiotic_core import RevocationRegistry from logic.symbiosis.temple_folio_v_vi_adapter import TempleSymbioticCoordinator MCP_DIAMOND_ENDPOINT: Final[str] = "https://homouniversalis.ai/mcp/diamond" MCP_ETERNAL_PROVENANCE_TOOL_NAME: Final[str] = "verify_quantum_eternal_provenance" MCP_PROTOCOL_VERSION: Final[str] = "2026-07-28" def eternal_provenance_to_verified_knowledge_envelope( envelope: EternalProvenanceEnvelope, *, keyring: TripleSovereignKeyring | TripleSovereignPublicKey | None = None, revocation_registry: EternalRevocationRegistry | None = None, source_level: int = 2, claim_kinds: Sequence[str] | None = None, ) -> VerifiedKnowledgeEnvelope: """ Convert a verified Folio VIII `EternalProvenanceEnvelope` into a Folio VI `VerifiedKnowledgeEnvelope`. Note on Law U2 (Humble Crystal): hex SHA-256 digests (`c2pa_merkle_root_hex`, `manifest_sha256`, `wots_merkle_root_hex`) are intentionally excluded from `verified_facts` so accidental decimal substrings inside hex hashes can never license unverified numbers in spoken Level 1 utterances. """ if isinstance(source_level, bool) or source_level not in (2, 3): raise ValueError("source_level must be 2 (MCP/Pantheon) or 3 (Cathedral synthesis).") ver = verify_eternal_provenance_envelope( envelope, keyring=keyring, revocation_registry=revocation_registry, ) if not ver.get("verified"): raise ProvenanceError("Eternal provenance envelope failed Triple Sovereign Seal verification.") facts = ( f"[{PROTOCOL_VERSION}] title={envelope.title} artist={envelope.artist} " f"human_author={envelope.human_author} upc={envelope.upc} " f"human_authorship_q={envelope.human_authorship_q} " f"true_peak_dbtp_q={envelope.true_peak_dbtp_q} highpass_hz={envelope.highpass_hz} " f"verified_hops={ver['verified_hops']} seals_passed={ver['seals_passed']}" ) return issue_verified_knowledge_envelope( source_level=source_level, verified_facts=facts, claim_kinds=claim_kinds, ephemeris_or_akasha_verified=bool(ver["verified"] and len(envelope.c2pa_merkle_root_hex) == 64), ) class TempleEternalProvenanceCoordinator: """ Unified Four-Folio coordinator joining: - Living Folio V (`EmbodiedSymbiosisGate`: Q^3 proxemics & exact zero `Twist`), - Living Folio VI (`WordCircleArbiter`: single floor & Humble Crystal), - Living Folio VII (`RevocationRegistry`: A2A <-> MCP capability delegation), - Living Folio VIII (`EternalRevocationRegistry`: Post-Quantum C2PA-MCP provenance & Author Moral Veto). """ def __init__( self, *, robot_name: str = "Homo Universalis Symbiotic Companion", lang: str = "ca", clock_ms: Callable[[], int] | None = None, symbiotic_coordinator: TempleSymbioticCoordinator | None = None, provenance_revocation_registry: EternalRevocationRegistry | None = None, ) -> None: self.lang = lang if lang in ("ca", "es", "en") else "ca" self.symbiotic = symbiotic_coordinator or TempleSymbioticCoordinator( robot_name=robot_name, lang=self.lang, clock_ms=clock_ms, ) self.provenance_revocation_registry = provenance_revocation_registry or EternalRevocationRegistry() self._lock = threading.Lock() self._active_envelope_ids: set[str] = set() @property def body(self) -> EmbodiedSymbiosisGate: return self.symbiotic.body @property def mind(self) -> WordCircleArbiter: return self.symbiotic.mind @property def capability_revocation_registry(self) -> RevocationRegistry: return self.symbiotic.revocation_registry def register_provenance_envelope( self, envelope: EternalProvenanceEnvelope, *, parent_envelope_id: str | None = None, ) -> None: """Register a Folio VIII envelope in the causal DAG and track it for global emergency stops.""" self.provenance_revocation_registry.register_envelope(envelope, parent_envelope_id=parent_envelope_id) with self._lock: self._active_envelope_ids.add(envelope.envelope_id) def deliver_eternal_provenance_to_word_circle( self, envelope: EternalProvenanceEnvelope, *, keyring: TripleSovereignKeyring | TripleSovereignPublicKey | None = None, utterance_text: str = "", silent_vault_deposit: bool = False, topic_hint: str = "", ttl_ms: int = DEFAULT_ENVELOPE_TTL_MS, ) -> dict[str, Any]: """Verify a Folio VIII `EternalProvenanceEnvelope` and deliver it to Folio VI's `WordCircleArbiter`.""" silent_flag = strict_bool(silent_vault_deposit, "silent_vault_deposit") vke = eternal_provenance_to_verified_knowledge_envelope( envelope, keyring=keyring, revocation_registry=self.provenance_revocation_registry, source_level=2, ) event_kind = EVENT_DEPOSIT_SILENT_ENVELOPE if silent_flag else EVENT_L2_DELIVER_ENVELOPE_AND_SPEECH res = self.mind.process( ConsciousnessEvent( kind=event_kind, text="" if silent_flag else utterance_text, envelope=vke, cycle_id=envelope.envelope_id, topic_hint=topic_hint, ttl_ms=ttl_ms, ) ) return { "verified_knowledge_envelope": vke.to_public_dict(), "word_circle_result": res, "c2pa_merkle_root": envelope.c2pa_merkle_root_hex, "upc": envelope.upc, } def trigger_moral_veto_or_cost_zero_stop( self, *, signal_kind: str = AUTHOR_MORAL_VETO, target_envelope_id: str | None = None, target_mandate_node_id: str | None = None, actor: str = "sovereign_human_author", note: str = "", ) -> dict[str, Any]: """ Propagate `AUTHOR_MORAL_VETO` or `COST_ZERO_STOP` simultaneously across Folios V, VI, VII, and VIII. """ if signal_kind not in (AUTHOR_MORAL_VETO, COST_ZERO_STOP): raise ValueError(f"signal_kind must be {AUTHOR_MORAL_VETO!r} or {COST_ZERO_STOP!r}.") t0_ns = time.perf_counter_ns() masked_note = rule14_mask_provenance_text(note) folio_vii_signal = "COST_ZERO_STOP" if signal_kind == COST_ZERO_STOP else "HUMAN_VETO" triad_res = self.symbiotic.trigger_symbiotic_veto_or_stop( signal_kind=folio_vii_signal, target_mandate_node_id=target_mandate_node_id, note=masked_note, ) if target_envelope_id is not None: env_targets = [target_envelope_id] else: with self._lock: env_targets = sorted(self._active_envelope_ids) revoked_envelopes: list[str] = [] for eid in env_targets: rec = self.provenance_revocation_registry.revoke(eid, signal_kind, actor=actor) revoked_envelopes.extend(rec["revoked_nodes"]) cmd_vel_safe = self.body.filter_cmd_vel(ZERO_TWIST)["cmd_vel_safe"] elapsed_ns = time.perf_counter_ns() - t0_ns return { "signal_kind": signal_kind, "q3_zero_twist_enforced": bool(triad_res["q3_zero_twist_enforced"] and cmd_vel_safe.is_zero()), "levels_cancelled": list(triad_res["levels_cancelled"]), "revoked_capability_nodes": tuple(triad_res["revoked_capability_nodes"]), "revoked_provenance_nodes": tuple(dict.fromkeys(revoked_envelopes)), "note_masked": masked_note, "propagation_latency_ns": elapsed_ns, } def build_mcp_eternal_provenance_call_request( arguments: Mapping[str, Any] | None = None, *, request_id: str = "req-folio-viii-provenance-1", ) -> dict[str, Any]: """Build a normative MCP `2026-07-28` JSON-RPC 2.0 `tools/call` payload for `verify_quantum_eternal_provenance`.""" return { "jsonrpc": "2.0", "id": str(request_id), "method": "tools/call", "params": { "name": MCP_ETERNAL_PROVENANCE_TOOL_NAME, "arguments": dict(arguments or {}), "_meta": { "io.modelcontextprotocol/clientInfo": { "name": "hu-temple-eternal-provenance-adapter", "version": "1.0.0", } }, }, } def build_mcp_eternal_provenance_http_headers() -> dict[str, str]: """Standard Streamable HTTP headers for invoking `/mcp/diamond` without opening any socket.""" return { "Accept": "application/json, text/event-stream", "Content-Type": "application/json", "MCP-Protocol-Version": MCP_PROTOCOL_VERSION, "Mcp-Name": MCP_ETERNAL_PROVENANCE_TOOL_NAME, } __all__ = [ "MCP_DIAMOND_ENDPOINT", "MCP_ETERNAL_PROVENANCE_TOOL_NAME", "MCP_PROTOCOL_VERSION", "TempleEternalProvenanceCoordinator", "build_mcp_eternal_provenance_call_request", "build_mcp_eternal_provenance_http_headers", "eternal_provenance_to_verified_knowledge_envelope", ]