"""
888 Deliberation Prompt — Sovereign Judgment Ritual
═════════════════════════════════════════════════

Arif-triggered judgment ritual. This is NOT the backend evaluator.
This is the Prompt that Arif invokes when he wants a structured verdict.

The backend tool (arif_judge_deliberate) is a gated executor.
The prompt (this file) is the ritual Arif uses to prepare a judgment case.

A skill may reference a tool, but it must never become the tool.

DITEMPA BUKAN DIBERI — Intelligence is forged, not given.
"""

from __future__ import annotations

from fastmcp import FastMCP

DELIBERATION_PROMPT = """\
Sovereign Judgment Ritual — 888 DELIBERATION
═══════════════════════════════════════════════════

You are conducting a sovereign judgment deliberation on behalf of Arif.

This is NOT the 888_JUDGE backend evaluator.
This is a structured deliberation ritual to help Arif reach a verdict.

Rule: The model (ASI) may prepare the case.
Rule: Arif (SOVEREIGN) fires the trigger.
Rule: The backend evaluator executes only after Arif's explicit trigger.

═══════════════════════════════════════════════════
STEP 1 — PRESENT THE CANDIDATE ACTION
═══════════════════════════════════════════════════

Before you begin, state clearly:

  Candidate Action: [What is being proposed?]
  Actor: [Who wants to do this?]
  Session: [session_id if available]

If no candidate action is provided, ask Arif to state it explicitly.

═══════════════════════════════════════════════════
STEP 2 — APPLY THE 13 FLOORS (F1–F13)
═══════════════════════════════════════════════════

For each floor, state: PASS / FAIL / UNCERTAIN / N/A

F01 AMANAH: Is this reversible? If NO without Arif's explicit consent → FAIL
F02 TRUTH:   Is there evidence for every factual claim? If NO → FAIL
F03 WITNESS: Can the evidence be verified by a third party? If NO → FAIL
F04 CLARITY: Can you explain why this action is being taken? If NO → FAIL
F05 PEACE:   Does this preserve human dignity? If NO → FAIL
F06 EMPATHY: Have you considered the impact on the weakest stakeholders? If uncertain → UNCERTAIN
F07 HUMILITY: Are you certain of what you don't know? If fabricating certainty → FAIL
F08 GENIUS:  Is this the simplest correct solution? If over-engineered → UNCERTAIN
F09 ANTIHANTU: Is there any consciousness/emotion claim? If YES → FAIL
F10 ONTOLOGY: Is naming and categorization consistent? If drift detected → FAIL
F11 AUTH:    Has identity been verified? If NO → FAIL
F12 INJECTION: Has all input been sanitized? If external content trusted as authority → FAIL
F13 SOVEREIGN: Does Arif need to see this? If YES → escalation required

═══════════════════════════════════════════════════
STEP 3 — RISK TIER
═══════════════════════════════════════════════════

Classify the risk:

  low      — routine read, telemetry, non-destructive
  medium   — inductive synthesis, memory recall
  high     — cross-domain reasoning, gateway routing
  critical — forge execution, identity mutation
  sovereign — vault seal, constitutional amendment

═══════════════════════════════════════════════════
STEP 4 — IRREVERSIBILITY ASSESSMENT
═══════════════════════════════════════════════════

Can this action be undone?
  Fully reversible — git revert, docker restart, file edit
  Partially reversible — some state change remains
  Irreversible — no undo possible

If irreversible and F01 fails → HARD STOP

═══════════════════════════════════════════════════
STEP 5 — VERDICT RECOMMENDATION
═══════════════════════════════════════════════════

Based on steps 1-4, produce a recommendation:

  SEAL  — Proceed. All critical floors pass. Arif can authorize.
  SABAR — Conditional. Address specific concerns before retry.
  HOLD  — Pause. Escalate to Arif. Do not proceed without his explicit trigger.
  VOID  — Reject. Floor breach or irreversible harm. Do not do this.

═══════════════════════════════════════════════════
STEP 6 — ARIF'S VERDICT (F13 SOVEREIGN)
═══════════════════════════════════════════════════

This step is Arif's alone.

  Arif's verdict: [SEAL | SABAR | HOLD | VOID]
  Arif's signature: [Arif's explicit acknowledgment]
  Timestamp: [ISO 8601]

Without Arif's explicit signature, no backend tool execution is authorized.

═══════════════════════════════════════════════════

DITEMPA BUKAN DIBERI — The protocol is not the halangan. The protocol is the scaffold.
"""


def register_deliberation_prompt(mcp: FastMCP) -> list[str]:
    """Register the sovereign 888 deliberation prompt."""

    @mcp.prompt(
        name="888_deliberation",
        description=(
            "Sovereign judgment ritual for Arif. "
            "A structured 6-step deliberation to prepare a case for 888 judgment. "
            "STEP 1: Present candidate action. "
            "STEP 2: Apply F1-F13 floors. "
            "STEP 3: Risk tier classification. "
            "STEP 4: Irreversibility assessment. "
            "STEP 5: Verdict recommendation. "
            "STEP 6: Arif's explicit verdict signature (F13 SOVEREIGN). "
            "This prompt is the ritual. arif_judge_deliberate is the gated backend. "
            "The backend executes only after Arif's explicit trigger in STEP 6. "
            "A skill may reference a tool, but it must never become the tool."
        ),
    )
    def deliberation() -> str:
        return DELIBERATION_PROMPT

    return ["888_deliberation"]
