diff --git a/backend/services/regulars_v2.py b/backend/services/regulars_v2.py index addc98b..1e13303 100644 --- a/backend/services/regulars_v2.py +++ b/backend/services/regulars_v2.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +from datetime import date from pathlib import Path import json import re @@ -103,3 +104,33 @@ async def _call_sonnet(prompt: str) -> dict: async def evaluate_promotion(caller_name: str, call_transcript: str) -> dict: prompt = PROMOTION_PROMPT.format(name=caller_name, transcript=call_transcript) return await _call_sonnet(prompt) + + +def write_new_regular(name: str, voice: str, age: int, identity_paragraph: str, + arc_plan: str, first_call_summary: str) -> Path: + REGULARS_DIR.mkdir(parents=True, exist_ok=True) + slug = name.lower().replace(" ", "-") + path = REGULARS_DIR / f"{slug}.md" + today = date.today().isoformat() + content = f"""--- +name: {name} +voice: {voice} +age: {age} +arc_state: {arc_plan} +promoted_on: {today} +--- + +# {name} + +{identity_paragraph} + +## Arc Plan + +{arc_plan} + +## Arc Log + +- {today}: {first_call_summary} +""" + path.write_text(content) + return path diff --git a/tests/test_regulars_v2.py b/tests/test_regulars_v2.py index affb24d..79d3026 100644 --- a/tests/test_regulars_v2.py +++ b/tests/test_regulars_v2.py @@ -69,3 +69,24 @@ def test_call_sonnet_strips_markdown_fences(): result = asyncio.run(_call_sonnet("prompt")) assert result["promote"] is True assert result["arc_plan"] == "ok" + + +def test_write_new_regular_creates_lore_file(tmp_path, monkeypatch): + monkeypatch.setattr("backend.services.regulars_v2.REGULARS_DIR", tmp_path) + from backend.services.regulars_v2 import write_new_regular + + write_new_regular( + name="Bobby", + voice="Marcus", + age=34, + identity_paragraph="A landscaper in Las Cruces who...", + arc_plan="3 episodes: distant → reveal → apology", + first_call_summary="Called about damaged car", + ) + f = tmp_path / "bobby.md" + assert f.exists() + body = f.read_text() + assert "name: Bobby" in body + assert "voice: Marcus" in body + assert "A landscaper in Las Cruces" in body + assert "3 episodes: distant → reveal → apology" in body