# SPDX-FileCopyrightText: 2026 David Porto Baraldés (Homo Universalis / Viveka) # SPDX-License-Identifier: Apache-2.0 """ HU-SOVEREIGN-BARYCENTER v1.0 — Temple Five-Folio Symbiotic Adapter (`logic/barycenter/temple_folio_ix_adapter.py`). Couples the zero-dependency standalone `sovereign_barycenter_core.py` (Living Folio IX — The `(0, 0, 0)` Barycenter of Leonardo's Stella Octangula) with Living Folios V (`HU-EMBODIED-SYMBIOSIS`), VI (`HU-UNIFIED-CONSCIOUSNESS`), VII (`HU-SYMBIOTIC-BRIDGE`), and VIII (`HU-ETERNAL-PROVENANCE`), WITHOUT importing `logic.engines`: 1. Verified Barycenter Transcript (Folio IX) -> VerifiedKnowledgeEnvelope (Folio VI): Verifies the RFC 6962 pre-sacrifice commitment root, Damgard-Nielsen G_p^5 sacrifice, Order-8 spectral `[8, 5, 4]_p` codeword, EU AI Act Art. 14 Human-AI symbiotic quorum, zero-origin blinding mask, and Asymmetric Wang-Guy-Davenport rational output before issuing a `VerifiedKnowledgeEnvelope` for Level 2 / Level 3 speech or silent Knowledge Vault deposit. 2. Human Quorum Veto / Byzantine Syndrome Abort / Cost-Zero Stop -> Five-Folio Cascade (Folios V..IX): Propagates `HUMAN_QUORUM_VETO`, `BYZANTINE_SYNDROME_ABORT`, 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 Post-Quantum C2PA-MCP provenance subtree (`EternalRevocationRegistry`), - Folio IX Multiparty Barycenter session hierarchy (`BarycenterRevocationRegistry`), isolating sibling sessions and upstream ancestors with zero collateral damage. Honest scope (`WO-13`): supervisory algorithmic and cryptographic software self-assessment only; never a safety-rated hardware function, never a certified FIPS 140-3 HSM, and never legal counsel. """ from __future__ import annotations import threading import time from typing import Any, Callable, Final, Mapping, Sequence from logic.barycenter.sovereign_barycenter_core import ( BYZANTINE_SYNDROME_ABORT, COST_ZERO_STOP, HUMAN_GUARDIAN_SEATS, HUMAN_QUORUM_VETO, PROTOCOL_ID, PROTOCOL_VERSION, REVOCATION_REASONS, BarycenterRevocationRegistry, SovereignBarycenterError, SymbioticQuorumError, rule14_mask_barycenter_text, verify_barycenter_transcript, ) 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 as FOLIO_VIII_COST_ZERO_STOP, EternalRevocationRegistry, ) from logic.provenance.temple_folio_viii_adapter import TempleEternalProvenanceCoordinator 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 MCP_DIAMOND_ENDPOINT: Final[str] = "https://homouniversalis.ai/mcp/diamond" MCP_BARYCENTER_TOOL_NAME: Final[str] = "verify_sovereign_barycenter_mpc_quorum" MCP_PROTOCOL_VERSION: Final[str] = "2026-07-28" def barycenter_transcript_to_verified_knowledge_envelope( transcript: Mapping[str, Any], *, revocation_registry: BarycenterRevocationRegistry | None = None, source_level: int = 2, claim_kinds: Sequence[str] | None = None, ) -> VerifiedKnowledgeEnvelope: """ Convert a verified Folio IX `zk_public_transcript` into a Folio VI `VerifiedKnowledgeEnvelope`. Note on Law U2 (Humble Crystal): hex SHA-256 / field digests (`pre_sacrifice_commitment_root`, `circuit_jcs_sha256`, `u_bar`) are intentionally excluded from `verified_facts` so accidental decimal substrings inside hex strings can never license unverified numbers in 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_barycenter_transcript( transcript, mode="zk_public_transcript", fault_policy="strict_abort", revocation_registry=revocation_registry, ) if not ver.get("verified"): raise SovereignBarycenterError("Barycenter MPC transcript failed cryptographic verification.") quorum_seats = list(transcript.get("quorum_seats") or []) bary_q3 = ver["spatial_barycenter_q3"] facts = ( f"[{PROTOCOL_ID}-{PROTOCOL_VERSION}] reconstructed_output={ver['reconstructed_output']} " f"quorum_count={len(quorum_seats)} quorum_seats={quorum_seats} " f"diag_active={transcript.get('diag_active')} " f"spatial_barycenter_q3=({bary_q3[0]}, {bary_q3[1]}, {bary_q3[2]})" ) 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(ver["pre_sacrifice_commitment_root"]) == 64), ) class TempleSovereignBarycenterCoordinator: """ Unified Five-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), - Living Folio IX (`BarycenterRevocationRegistry`: Multiparty Barycenter MPC quorum). """ def __init__( self, *, robot_name: str = "Homo Universalis Symbiotic Companion", lang: str = "ca", clock_ms: Callable[[], int] | None = None, provenance_coordinator: TempleEternalProvenanceCoordinator | None = None, barycenter_revocation_registry: BarycenterRevocationRegistry | None = None, ) -> None: self.lang = lang if lang in ("ca", "es", "en") else "ca" self.provenance = provenance_coordinator or TempleEternalProvenanceCoordinator( robot_name=robot_name, lang=self.lang, clock_ms=clock_ms, ) self.barycenter_revocation_registry = barycenter_revocation_registry or BarycenterRevocationRegistry() self._lock = threading.Lock() self._active_session_ids: set[str] = set() @property def body(self) -> EmbodiedSymbiosisGate: return self.provenance.body @property def mind(self) -> WordCircleArbiter: return self.provenance.mind @property def capability_revocation_registry(self) -> RevocationRegistry: return self.provenance.capability_revocation_registry @property def provenance_revocation_registry(self) -> EternalRevocationRegistry: return self.provenance.provenance_revocation_registry def register_barycenter_session( self, session_id: str, *, parent_session_id: str | None = None, ) -> None: """Register a Folio IX MPC session in the hierarchical revocation tree.""" self.barycenter_revocation_registry.register_session(session_id, parent_session_id=parent_session_id) with self._lock: self._active_session_ids.add(rule14_mask_barycenter_text(session_id).strip()) def deliver_barycenter_consensus_to_word_circle( self, transcript: Mapping[str, Any], *, utterance_text: str = "", silent_vault_deposit: bool = False, topic_hint: str = "", ttl_ms: int = DEFAULT_ENVELOPE_TTL_MS, ) -> dict[str, Any]: """Verify a Folio IX `zk_public_transcript` and deliver its exact output to Folio VI's `WordCircleArbiter`.""" silent_flag = strict_bool(silent_vault_deposit, "silent_vault_deposit") vke = barycenter_transcript_to_verified_knowledge_envelope( transcript, revocation_registry=self.barycenter_revocation_registry, source_level=2, ) sid = str(transcript.get("session_id") or "folio-ix-session") 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=sid, topic_hint=topic_hint, ttl_ms=ttl_ms, ) ) return { "verified_knowledge_envelope": vke.to_public_dict(), "word_circle_result": res, "pre_sacrifice_commitment_root": str(transcript.get("pre_sacrifice_commitment_root") or ""), "reconstructed_output": str(transcript.get("reconstructed_output") or ""), } def trigger_barycenter_veto_or_abort_cascade( self, *, signal_kind: str = HUMAN_QUORUM_VETO, actor_seat: int | None = 2, target_session_id: str | None = None, target_envelope_id: str | None = None, target_mandate_node_id: str | None = None, note: str = "", ) -> dict[str, Any]: """ Propagate `HUMAN_QUORUM_VETO`, `BYZANTINE_SYNDROME_ABORT`, or `COST_ZERO_STOP` simultaneously across all Five Living Folios (V, VI, VII, VIII, and IX). """ if signal_kind not in REVOCATION_REASONS: raise ValueError(f"signal_kind must be one of {sorted(REVOCATION_REASONS)}.") if signal_kind == HUMAN_QUORUM_VETO and (actor_seat is None or actor_seat not in HUMAN_GUARDIAN_SEATS): raise SymbioticQuorumError("HUMAN_QUORUM_VETO requires an explicit Human Guardian seat {2, 4, 6, 8}.") t0_ns = time.perf_counter_ns() masked_note = rule14_mask_barycenter_text(note) folio_viii_signal = FOLIO_VIII_COST_ZERO_STOP if signal_kind == COST_ZERO_STOP else AUTHOR_MORAL_VETO quad_res = self.provenance.trigger_moral_veto_or_cost_zero_stop( signal_kind=folio_viii_signal, target_envelope_id=target_envelope_id, target_mandate_node_id=target_mandate_node_id, actor=f"guardian_seat_{actor_seat}" if actor_seat is not None else "barycenter_arbiter", note=masked_note, ) if target_session_id is not None: session_targets = [target_session_id] else: with self._lock: session_targets = sorted(self._active_session_ids) revoked_sessions: list[str] = [] for sid in session_targets: affected = self.barycenter_revocation_registry.revoke_session( sid, signal_kind, actor_seat=actor_seat if signal_kind == HUMAN_QUORUM_VETO else None, detail=masked_note, ) revoked_sessions.extend(affected) 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(quad_res["q3_zero_twist_enforced"] and cmd_vel_safe.is_zero()), "levels_cancelled": list(quad_res["levels_cancelled"]), "revoked_capability_nodes": tuple(quad_res["revoked_capability_nodes"]), "revoked_provenance_nodes": tuple(quad_res["revoked_provenance_nodes"]), "revoked_barycenter_sessions": tuple(dict.fromkeys(revoked_sessions)), "note_masked": masked_note, "propagation_latency_ns": elapsed_ns, } def build_mcp_barycenter_call_request( arguments: Mapping[str, Any] | None = None, *, request_id: str = "req-folio-ix-barycenter-1", ) -> dict[str, Any]: """Build a normative MCP `2026-07-28` JSON-RPC 2.0 `tools/call` payload for `verify_sovereign_barycenter_mpc_quorum`.""" return { "jsonrpc": "2.0", "id": str(request_id), "method": "tools/call", "params": { "name": MCP_BARYCENTER_TOOL_NAME, "arguments": dict(arguments or {}), "_meta": { "io.modelcontextprotocol/clientInfo": { "name": "hu-temple-sovereign-barycenter-adapter", "version": "1.0.0", } }, }, } def build_mcp_barycenter_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_BARYCENTER_TOOL_NAME, } __all__ = [ "BYZANTINE_SYNDROME_ABORT", "COST_ZERO_STOP", "HUMAN_QUORUM_VETO", "MCP_BARYCENTER_TOOL_NAME", "MCP_DIAMOND_ENDPOINT", "MCP_PROTOCOL_VERSION", "TempleSovereignBarycenterCoordinator", "barycenter_transcript_to_verified_knowledge_envelope", "build_mcp_barycenter_call_request", "build_mcp_barycenter_http_headers", ]