feat: bot reset with hard confirm and event-driven purge

This commit is contained in:
Joseph Doherty
2026-04-26 14:07:56 -04:00
parent 46062973c2
commit 82be8b3f51
5 changed files with 279 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
from __future__ import annotations
from sqlite3 import Connection
from chat.eventlog.log import append_and_apply
from chat.state.entities import get_bot
def reset_bot(conn: Connection, bot_id: str, *, confirm_name: str) -> None:
"""Reset a bot's runtime state via a ``bot_reset`` event.
Validates that ``confirm_name`` matches the bot's stored ``name``
exactly (case-sensitive, no trim). Raises:
- ``ValueError("bot {bot_id} not found")`` when the bot is missing.
- ``ValueError("confirm_name does not match bot name")`` on mismatch.
"""
bot = get_bot(conn, bot_id)
if bot is None:
raise ValueError(f"bot {bot_id} not found")
if confirm_name != bot["name"]:
raise ValueError("confirm_name does not match bot name")
append_and_apply(conn, kind="bot_reset", payload={"bot_id": bot_id})