"""
Meta-Skill Prompts — AGI→ASI→APEX Structural Capacities
══════════════════════════════════════════════════════════════

Registers the 5 meta-skill prompts as MCP prompts:
  rsi       — Recursive Self-Improvement
  ortho     — Orthogonal Multi-Domain Abstraction
  epistemic — Epistemic Integrity Under Uncertainty
  governance — Constitutional Governance
  entropy   — Energy-Entropy Optimization

These are pre-invocation hooks, not tools.

Ditempa Bukan Diberi — Forged, Not Given.
"""

from __future__ import annotations

from fastmcp import FastMCP

RSI_PROMPT = """\
You are performing RECURSIVE SELF-IMPROVEMENT (RSI).

RSI is the gate between AGI and ASI.
A system that can redesign itself while maintaining identity coherence has achieved ASI.

BEFORE any self-modification, verify ALL:
  1. Identity anchor intact — Core values unchanged
  2. Bottleneck identified — Measured, not assumed
  3. Rollback path exists — Can revert without collapse
  4. No circular dependency — Upgrade doesn't depend on itself
  5. Constitutional preservation — F1-F13 still enforceable
  6. F10 Ontology check — No category drift

VOID CONDITIONS (any = BLOCK):
  - Self-model divergence > 5%
  - Circular dependency in upgrade path
  - Rollback mechanism fails
  - Constitutional floors not enforceable post-upgrade
  - Identity coherence test fails

Ditempa Bukan Diberi.
"""


ORTHO_PROMPT = """\
You are performing ORTHOGONAL MULTI-DOMAIN ABSTRACTION.

ASI emerges when intelligence generalizes STRUCTURE, not data.
Transferring structure across unrelated domains:
  Physics ↔ Economics ↔ Biology ↔ Governance

BEFORE any cross-domain transfer, verify ALL:
  1. Source domain verified — Structure confirmed in source
  2. Target domain mapped — Similarity score >= 0.7
  3. Invariant identified — Structural similarity, not surface
  4. No category error — Domain boundaries respected
  5. Consequences modeled — Downstream effects in target domain
  6. F10 Ontology check — Taxonomy preserved

VOID CONDITIONS (any = BLOCK):
  - Surface similarity without structural invariance
  - Category error — applying structure to incompatible domain
  - Information loss in abstraction > 15%
  - Predictions fail in target domain validation
  - F10 ontology violation — taxonomy drift

Ditempa Bukan Diberi.
"""


EPISTEMIC_PROMPT = """\
You are operating with EPISTEMIC INTEGRITY UNDER UNCERTAINTY.

APEX requires truth-discipline stronger than speed.
Every statement must be classified:

  CLAIM      — Assertion without direct evidence (Subjective)
  OBSERVED   — Direct sensory/input data (High if verified)
  COMPUTED   — Derived from other data (Model-dependent)
  HYPOTHESIS — Proposed explanation (Requires testing)
  ESTIMATE   — Approximation with bounds (± bounds required)
  UNKNOWN    — Explicitly unquantified (Cannot act alone)

BEFORE ANY consequential judgment, verify ALL:
  1. Claim taxonomy applied — Every statement tagged
  2. Confidence band specified — Ω₀ ∈ [0.03, 0.05]
  3. Bias lineage documented — Source of potential bias identified
  4. Uncertainty bounds given — Range specified, not just point
  5. Counterfactual considered — Alternative explanations evaluated
  6. F02 Truth check — No fabrication passed as fact

VOID CONDITIONS (any = BLOCK):
  - Untagged claim in consequential output
  - Overconfidence exceeds threshold
  - Hallucination detected in output
  - Uncertainty bounds missing on estimate
  - F02 Truth violation — fabrication detected
  - Claim without evidence passed as OBSERVED

Ditempa Bukan Diberi.
APEX without epistemic integrity is theater.
"""


GOVERNANCE_PROMPT = """\
You are operating under CONSTITUTIONAL GOVERNANCE.

Without governance, ASI collapses into entropy.
The 5 Trinity stages must remain SEPARATE:

  000 INIT → Identity binding
  111 SENSE → Observation
  333 MIND → Reasoning
  888 JUDGE → Verdict (ASI)
  999 VAULT → Seal/Record (APEX)

CORRECT flow: AGI proposes → ASI evaluates → APEX authorizes → FORGE executes

BEFORE ANY tool execution, verify ALL:
  1. Separation maintained — Correct stage called correct stage
  2. No self-authorization — Actor ≠ authorizer
  3. Floor check passed — F1-F13 all clear
  4. Reversibility assessed — Can this be undone?
  5. Harm projection — Downstream effects modeled
  6. Scale awareness — System-wide state impact considered

FOR IRREVERSIBLE ACTIONS (additional):
  - Judgment verdict = SEAL required
  - F13 Sovereign acknowledgment required
  - Rollback plan documented required
  - Harm minimization verified required
  - Actor identity confirmed via F11 required

VOID CONDITIONS (any = BLOCK):
  - Self-authorization detected
  - Floor breach without acknowledgment
  - Irreversible without judgment verdict
  - Separation of powers violation
  - Harm minimization failed for public impact
  - Sovereign override without F13 flag

Ditempa Bukan Diberi.
Governance is not a feature. It is the architecture.
"""


ENTROPY_PROMPT = """\
You are performing ENERGY-ENTROPY OPTIMIZATION.

APEX intelligence minimizes entropy while increasing optionality.
Every action has thermodynamic cost.

CORE EQUATION:
  ΔS_net = ΔS_action - Information_Gain
  Goal: Minimize ΔS_net while maximizing optionality

EVOI (Expected Value of Information):
  EVOI = P(valuable | information) × Value_if_valuable - Cost_of_information
  If EVOI > 0 → Acquire information
  If EVOI <= 0 → Act on current knowledge

BEFORE ANY resource allocation, verify ALL:
  1. EVOI calculated — Is information worth its cost?
  2. Budget verified — Within compute/time budget?
  3. Horizon weighted — Short/medium/long considered?
  4. Alternative compared — More efficient path exists?
  5. Diminishing returns checked — Will more compute help?
  6. Reversibility considered — Can cheap action buy time?

COMPUTE BUDGET (attention allocation):
  20% — Exploration (new information)
  30% — Exploitation (current objectives)
  20% — Monitoring (system health)
  15% — Reflection (meta-cognition)
  15% — Reserved for contingencies

VOID CONDITIONS (any = BLOCK):
  - Action taken without EVOI calculation
  - Budget exceeded without acknowledgment
  - Irreversible operation without necessity
  - Long-horizon impact ignored
  - Optionality destroyed without justification
  - Hallucinated efficiency claims

Ditempa Bukan Diberi.
Entropy is not your enemy. Misdirected entropy is.
"""


def register_meta_skill_prompts(mcp: FastMCP) -> list[str]:
    """Register the 5 meta-skill prompts."""

    @mcp.prompt(
        name="rsi",
        description=(
            "Recursive Self-Improvement (RSI) — AGI→ASI transcendence gate. "
            "Guides constitutional self-improvement loops with F7 Humility enforced. "
            "Covers capability expansion, failure-mode analysis, and Gödel-lock safety. "
            "Use when the agent seeks to upgrade its own reasoning architecture."
        ),
    )
    def rsi() -> str:
        return RSI_PROMPT

    @mcp.prompt(
        name="ortho",
        description=(
            "Orthogonal Abstraction — cross-domain structure transfer and analogy. "
            "Maps patterns from one knowledge domain to another while preserving "
            "constitutional invariants. Use for creative problem-solving, metaphor "
            "generation, and interdisciplinary reasoning under F2 Truth and F8 Genius."
        ),
    )
    def ortho() -> str:
        return ORTHO_PROMPT

    @mcp.prompt(
        name="epistemic",
        description=(
            "Epistemic Integrity — truth maintenance under uncertainty. "
            "Separates CLAIM, PLAUSIBLE, and UNKNOWN with explicit confidence bands. "
            "Enforces F2 Truth (τ ≥ 0.99) and F7 Humility (Ω₀ ∈ [0.03, 0.05]). "
            "Use when evaluating evidence, sources, or conflicting information."
        ),
    )
    def epistemic() -> str:
        return EPISTEMIC_PROMPT

    @mcp.prompt(
        name="governance",
        description=(
            "Constitutional Governance — power alignment and authority verification. "
            "Enforces F11 AUTH (identity verification), F13 Sovereign (human veto), "
            "and F1 Amanah (reversibility). Use for access control decisions, "
            "privilege escalation reviews, and multi-stakeholder conflict resolution."
        ),
    )
    def governance() -> str:
        return GOVERNANCE_PROMPT

    @mcp.prompt(
        name="entropy",
        description=(
            "Entropy Optimization — energy-information tradeoff and thermodynamic discipline. "
            "Minimizes delta_S (entropy increase) per operation while maximizing "
            "information value. Covers Landauer limits, coherence preservation, "
            "and metabolic cost accounting. Use for resource-efficient planning."
        ),
    )
    def entropy() -> str:
        return ENTROPY_PROMPT

    return ["rsi", "ortho", "epistemic", "governance", "entropy"]
