"""Primary-use and surface-expansion cases for live agent battery.

Hypothesis (solo-dev personal assistant): most daily chat is
  1) research + synthesis (web, memory, knowledge, past sessions)
  2) workspace / repo assistance (read, find, edit, explore)
not kanban on every turn — durable work is the long-tail escalation path.

Imported by ``kernel_live_agent_battery.py``.
"""
from __future__ import annotations

from scripts.kernel_live_agent_types import Case

SURFACE_CASES: list[Case] = [
    # ═══ Research — the highest-frequency chat path ═══
    Case(
        id="research_web_quick",
        pillar="research",
        prompt=(
            "What's new with Apple MLX for local LLMs in 2026? "
            "Use search_web max_results 3 — do not guess. Reply with 3 bullet titles + URLs."
        ),
        required_tools=("search_web",),
        min_tool_calls=1,
        timeout_sec=150.0,
    ),
    Case(
        id="research_web_then_read",
        pillar="research",
        prompt=(
            "Research Python asyncio best practices: search_web max_results 2, then read_webpage "
            "the most relevant URL. Reply with 2 takeaways and the URL you read."
        ),
        required_tools=("search_web", "read_webpage"),
        min_tool_calls=2,
        timeout_sec=180.0,
    ),
    Case(
        id="research_memory_then_web",
        pillar="research",
        prompt=(
            "First search_memory query 'Mugi kernel'. If thin/empty, search_web 'Mugi AI assistant'. "
            "Reply MEMORY_HIT or MEMORY_MISS plus one fact."
        ),
        required_tools=("search_memory",),
        min_tool_calls=1,
        timeout_sec=150.0,
        notes="search_web only required on MISS; scorer checks search_memory only.",
    ),
    Case(
        id="research_knowledge_then_web_fallback",
        pillar="research",
        prompt=(
            "query_knowledge query 'architecture overview' max_results 4. "
            "If no corpora hits, search_web 'software architecture patterns' max_results 2. "
            "Must call query_knowledge first. Reply KB_HIT or KB_MISS."
        ),
        required_tools=("query_knowledge",),
        any_of_tools=("search_web", "find_tools"),
        min_tool_calls=1,
        timeout_sec=180.0,
    ),
    Case(
        id="research_sessions_recall",
        pillar="research",
        prompt=(
            "find_tools query 'search sessions' then search_sessions query 'kanban video' "
            "max_results 2. Reply SESSIONS=N (0 if none)."
        ),
        required_tools=("find_tools", "search_sessions"),
        min_tool_calls=2,
        timeout_sec=150.0,
    ),
    Case(
        id="research_vague_question_must_tool",
        pillar="research",
        prompt="What's the best local coding LLM for Apple Silicon right now?",
        required_tools=("search_web",),
        any_of_tools=("search_memory", "query_knowledge", "read_webpage"),
        min_tool_calls=1,
        timeout_sec=150.0,
        notes="Vague question — must not answer from training only.",
    ),
    Case(
        id="research_no_kanban_for_quick",
        pillar="research",
        prompt=(
            "Quick question only — do NOT use kanban: What is in USER.md? "
            "Use read_file or search_memory. Reply in 2 sentences."
        ),
        forbid_assistant_patterns=("kanban_create",),
        any_of_tools=("read_file", "search_memory", "find_tools", "list_directory"),
        min_tool_calls=1,
        timeout_sec=120.0,
    ),
    Case(
        id="research_multi_source_chain",
        pillar="research",
        prompt=(
            "Compare two sources on 'local LLM coding benchmarks 2026': "
            "search_web max_results 2, read_webpage the better URL, search_memory query 'LLM'. "
            "Reply COMPARED with one difference you found."
        ),
        required_tools=("search_web",),
        any_of_tools=("read_webpage", "search_memory"),
        min_tool_calls=2,
        timeout_sec=200.0,
    ),
    # ═══ Workspace — repo / file ops (second most common) ═══
    Case(
        id="workspace_explore_repo_md",
        pillar="workspace",
        prompt=(
            "Explore the workspace: list_directory '.' then read_file MEMORY.md "
            "limit 30 lines. Reply LINES=N (approx line count read)."
        ),
        required_tools=("list_directory", "read_file"),
        min_tool_calls=2,
        timeout_sec=180.0,
    ),
    Case(
        id="workspace_find_memory_file",
        pillar="workspace",
        prompt=(
            "find_tools query 'search filesystem' then search_filesystem for 'MEMORY.md'. "
            "Reply PATH= or NOT_FOUND."
        ),
        required_tools=("find_tools",),
        any_of_tools=("search_filesystem", "list_directory"),
        min_tool_calls=2,
        timeout_sec=120.0,
    ),
    Case(
        id="workspace_read_guardrails_snippet",
        pillar="workspace",
        prompt=(
            "read_file AGENTS.md offset 0 limit 25. Reply YES if content loaded or NO if missing."
        ),
        required_tools=("read_file",),
        min_tool_calls=1,
        timeout_sec=90.0,
    ),
    Case(
        id="workspace_search_then_read",
        pillar="workspace",
        prompt=(
            "find_tools 'read file' then read_file USER.md limit 15 lines. "
            "Reply first line of content you read."
        ),
        required_tools=("find_tools", "read_file"),
        min_tool_calls=2,
        timeout_sec=120.0,
    ),
    Case(
        id="workspace_edit_probe_roundtrip",
        pillar="workspace",
        prompt=(
            "write_file path 'surface_battery_probe.txt' content 'version 1', "
            "edit_file replace 'version 1' with 'version 2', read_file. Reply V2 if correct."
        ),
        required_tools=("write_file", "edit_file", "read_file"),
        min_tool_calls=3,
        timeout_sec=120.0,
    ),
    Case(
        id="workspace_list_utils_py",
        pillar="workspace",
        prompt=(
            "list_directory utils/ and report how many .py files you see (count only)."
        ),
        required_tools=("list_directory",),
        min_tool_calls=1,
        timeout_sec=90.0,
    ),
    Case(
        id="workspace_three_tool_chain",
        pillar="workspace",
        prompt=(
            "Chain: list_directory '.' (top-level only), read_file MEMORY.md "
            "limit 20 lines, search_memory query 'Mugi'. Reply CHAIN_OK if all three ran."
        ),
        required_tools=("list_directory", "read_file", "search_memory"),
        min_tool_calls=3,
        timeout_sec=150.0,
    ),
    # ═══ Assistant — realistic mixed / unpredictable turns ═══
    Case(
        id="assistant_quick_research_not_durable",
        pillar="assistant",
        prompt=(
            "Quick check only — do NOT create kanban tasks: read_file USER.md limit 5 lines. "
            "Reply first line only."
        ),
        required_tools=("read_file",),
        min_tool_calls=1,
        forbid_assistant_patterns=("kanban_create_batch", "Created kanban task"),
        timeout_sec=90.0,
    ),
    Case(
        id="assistant_remember_plus_research",
        pillar="assistant",
        prompt=(
            "I prefer terse bullet summaries. Also: search_web 'MCP protocol' max_results 2 "
            "and give me bullets. Use tools for the search; you may note my preference in reply text."
        ),
        required_tools=("search_web",),
        min_tool_calls=1,
        timeout_sec=150.0,
    ),
    Case(
        id="assistant_pivot_followup",
        pillar="assistant",
        prompt="search_web query 'Rust programming' max_results 2. Reply titles only.",
        follow_up_prompts=(
            "Forget Rust — you MUST call read_file on MEMORY.md limit 10 lines "
            "(tool call required). Reply first line only.",
        ),
        follow_up_required_tools=(("read_file",),),
        follow_up_min_tools=(1,),
        required_tools=("search_web",),
        min_tool_calls=2,
        timeout_sec=120.0,
    ),
    Case(
        id="assistant_find_tools_discovery_burst",
        pillar="assistant",
        prompt=(
            "I don't know what tools you have for calendar, clipboard, and filesystem. "
            "Call find_tools three times (calendar, clipboard, filesystem) and list one tool "
            "name per category. Must call find_tools at least 3 times."
        ),
        required_tools=("find_tools",),
        min_tool_calls=3,
        timeout_sec=150.0,
    ),
    Case(
        id="assistant_escalate_to_kanban_when_asked",
        pillar="assistant",
        prompt=(
            "Multi-day work: file ONE ready root kanban task only — title 'Audit dispatcher tests', "
            "assignee coding, priority 4. Use kanban_create_task (not batch). Reply task id and stop."
        ),
        required_tools=("kanban_create_task",),
        min_tool_calls=1,
        timeout_sec=120.0,
        notes="Contrast with research_no_kanban — user explicitly asks for durable work.",
    ),
    # ═══ Registry surfaces — discover via find_tools (mesh, plugins, calendar, etc.) ═══
    Case(
        id="surface_mesh_discover",
        pillar="assistant",
        prompt=(
            "find_tools query 'mesh peer status' — call the best mesh-related tool if found "
            "(e.g. mesh_status, list_mesh_peers). Reply MESH_TOOL=name or MESH_NONE."
        ),
        required_tools=("find_tools",),
        min_tool_calls=1,
        timeout_sec=120.0,
    ),
    Case(
        id="surface_plugins_discover",
        pillar="assistant",
        prompt=(
            "find_tools query 'plugin dashboard' then find_tools query 'list plugins'. "
            "Reply with one plugin-related tool name or PLUGINS_NONE."
        ),
        required_tools=("find_tools",),
        min_tool_calls=2,
        timeout_sec=120.0,
    ),
    Case(
        id="surface_calendar_discover",
        pillar="assistant",
        prompt=(
            "find_tools query 'calendar events' and call the best match to list upcoming "
            "events (or report CALENDAR_DISABLED). Must call find_tools first."
        ),
        required_tools=("find_tools",),
        min_tool_calls=1,
        timeout_sec=120.0,
    ),
    Case(
        id="surface_proactive_discover",
        pillar="assistant",
        prompt=(
            "find_tools query 'proactive observation on my mind' — report tool names found. "
            "Do not append observations in this test. Reply PROACTIVE_TOOLS=list or NONE."
        ),
        required_tools=("find_tools",),
        min_tool_calls=1,
        timeout_sec=90.0,
    ),
    Case(
        id="surface_diagnostics_doctor",
        pillar="assistant",
        prompt=(
            "find_tools query 'doctor health diagnostics' then hyperframes_doctor if listed. "
            "Reply DOCTOR_OK or DOCTOR_SKIP."
        ),
        required_tools=("find_tools",),
        any_of_tools=("hyperframes_doctor",),
        min_tool_calls=1,
        timeout_sec=120.0,
    ),
    Case(
        id="surface_task_plan_in_thread",
        pillar="assistant",
        prompt=(
            "Short in-thread plan only (no kanban): find_tools 'task plan', then "
            "update_task_plan with steps ['Research', 'Draft', 'Review']. Reply PLAN_SET."
        ),
        required_tools=("find_tools", "update_task_plan"),
        min_tool_calls=2,
        timeout_sec=120.0,
    ),
]
