from pathlib import Path
Path("../services/rpg_context.py").write_text('''"""Shared context blocks for RPG narrator / plot LLM calls."""

import json

from services.rpg_story import (
    format_step_for_narrator,
    normalize_story_arc,
    step_progress,
)


def format_narrator_context(
    arc: dict | None,
    quests: list | None,
    status_quo: str = "",
) -> str:
    arc = normalize_story_arc(arc or {}) if arc else {}
    return format_step_for_narrator(arc, quests, status_quo)


def format_arc_summary_for_runtime(arc: dict | None) -> str:
    arc = normalize_story_arc(arc or {}) if arc else {}
    if not arc:
        return ""
    cur, total = step_progress(arc)
    return json.dumps(
        {
            "title": arc.get("title"),
            "global_story": (arc.get("global_story") or "")[:300],
            "step": f"{cur}/{total}",
            "status": arc.get("status", "active"),
        },
        ensure_ascii=False,
    )
''', encoding='utf-8')
print('done')
