"""Plan C incident-surface cases for the live agent battery.

Covers the API seams that broke in the May 2026 motion polish incident:
  * chat_core — foreground agent turn (tool use + multi-turn context)
  * sidebar — conversation create / list / rename / trash / restore (HTTP)
  * preferences — GET /preferences load + POST round-trip (HTTP)

HTTP-only cases run without MLX and are deterministic gate candidates.
Imported by ``kernel_live_agent_battery.py``.

Every MLX case runs after ``_prime_welcome`` (synthetic user ``init`` + greeting),
matching production SwiftUI thread startup. Message-based scoring strips that
prefix via ``_case_scoped_messages`` before indexing case-prompt turns.
"""
from __future__ import annotations

from scripts.kernel_live_agent_types import Case

_INCIDENT_DOC = "docs/validator-api.md"

INCIDENT_CASES: list[Case] = [
    # ── Chat core: single tool-call turn ─────────────────────────────────────
    Case(
        id="chat_core_read_file_turn",
        pillar="chat_core",
        prompt=(
            f"Call read_file once on {_INCIDENT_DOC} (first 20 lines). "
            "Reply with the filename and one noun from the content — no guessing."
        ),
        required_tools=("read_file",),
        min_tool_calls=1,
        require_final_reply=True,
        timeout_sec=120.0,
        notes="Foreground chat must complete a single read_file turn and finalize.",
    ),
    # ── Chat core: multi-turn context retention ───────────────────────────────
    Case(
        id="chat_core_multiturn_context",
        pillar="chat_core",
        prompt=(
            "Remember this codeword for the next message only: MUGI_GATE_ALPHA. "
            "Reply with exactly: STORED."
        ),
        min_tool_calls=0,
        allow_zero_tool_final_reply=True,
        require_final_reply=True,
        require_assistant_substrings=("MUGI_GATE_ALPHA",),
        require_initial_assistant_substrings=("STORED",),
        follow_up_prompts=(
            "What was the codeword I asked you to remember? Reply with the codeword only.",
        ),
        follow_up_min_tools=(0,),
        follow_up_allow_zero_tools=(True,),
        timeout_sec=120.0,
        notes="Multi-turn: follow-up must recall prior user-stated codeword.",
    ),
    # ── Sidebar: HTTP lifecycle (no MLX) ────────────────────────────────────
    Case(
        id="sidebar_conversation_lifecycle",
        pillar="sidebar",
        prompt="(http-only)",
        http_only=True,
        timeout_sec=30.0,
        notes="create → list → rename → trash → restore via /conversations/*",
    ),
    # ── Preferences: HTTP load + save round-trip (no MLX) ─────────────────
    Case(
        id="preferences_load_save_roundtrip",
        pillar="preferences",
        prompt="(http-only)",
        http_only=True,
        timeout_sec=30.0,
        notes="GET /preferences then POST probe key and verify round-trip.",
    ),
]
