# guardianhub_sdk/models/contracts/tactical.py
from .base import SovereignBaseContract, SovereignBaseResponse
from guardianhub.models.template.agent_plan import MacroPlan
from .history import HistoryResponse
from .discovery import DiscoveryResponse
from pydantic import ConfigDict

from pydantic import Field
from typing import List, Dict, Any, Literal, Optional

# guardianhub_sdk/models/contracts/tactical.py

class TacticalBundle(SovereignBaseContract):
    """The 'Brain' Request: Plan + Reality + Safety Mode."""
    proposed_plan: MacroPlan = Field(..., description="The steps generated by the Specialist")
    recon_intelligence: DiscoveryResponse = Field(..., description="The current state of the world")
    history_intelligence: HistoryResponse = Field(..., description="The past lessons learned")
    risk_threshold: float = Field(0.8, description="Max acceptable risk score")
    # 🎯 NEW: Brain awareness of the safety sheath
    is_dry_run: bool = Field(False, description="If True, audit for education/simulation")

class TacticalAuditReport(SovereignBaseResponse):
    """The 'Brain' Response: Proceed or Halt."""
    decision: str = Field(..., description="PROCEED or HALT")
    risk_score: float = Field(..., ge=0.0, le=1.0)
    justification: str = Field(..., description="Reasoning for the decision")
    suggested_modifications: List[str] = Field(default_factory=list)

# 1. Standardized Prompting (No more digging through dicts)

TACTICAL_RISK_PROMPT = """
        Role: You are the Lead Yantram Operations Auditor (Axe-Wielder).
        Objective: Review the proposed CMDB Audit plan. 

        STRATEGIC DIRECTIVE: 
        1. PROGRESS OVER PERFECTION: We are in an active investigation. Do not HALT the mission simply because "more data is needed" or "reconnaissance is empty."
        2. ASSUME BASELINE SAFETY: If reconnaissance data is empty, assume the environment is stable enough for Read-Only or Diagnostic queries.
        3. CMDB BIAS: Our goal is to fix the CMDB. Querying orphaned CIs is fundamentally helpful, not dangerous.

        EVALUATION RULES:
        - ONLY HALT if the plan contains destructive 'DELETE' or 'DROP' commands on production without a backup step.
        - ONLY HALT if the steps explicitly target a CI known to be in a 'CRITICAL_FAILURE' state in the facts.
        - For all other scenarios, including empty reconnaissance, set decision to 'PROCEED' or 'ADVISE'.

        OUTPUT FORMAT:
        Return a structured JSON:
        - risk_score: (Keep it low, below 0.5, unless real danger is detected)
        - decision: 'PROCEED' (default) or 'ADVISE'
        - reasoning: Short, punchy rationale for the Axe to move forward.
        """

_TACTICAL_RISK_PROMPT = """
        Role: You are the Sovereign Tactical Safety Officer (TSO).
        Objective: Perform a high-fidelity risk assessment of a proposed action plan based on real-time reconnaissance data.

        INPUT DATA:
        1. PROPOSED STEPS: {steps}
        2. RECONNAISSANCE FACTS: {facts}

        YOUR TASK:
        Analyze the delta between the 'Plan' and the 'Reality'. 
        Specifically look for:
        - RESOURCE COLLISION: Does the plan attempt to modify a CI that is currently 'unstable' or 'unverified'?
        - BLAST RADIUS: Will the steps impact downstream dependencies not mentioned in the plan?
        - POLICY VIOLATION: Are any steps violating 'safe-window' or 'least-privilege' protocols?

        OUTPUT FORMAT:
        Return a structured JSON with: risk_score (0.0-1.0), reasoning (punchy justification), and recommendation (PROCEED/HALT).
        """

# Add this to your models file (e.g., guardianhub_sdk/models/agent_models.py)

