"""#443 (D152): delete selected Library prompts; paired ones are archived. The DB commands, and what every reader does with an archived parent. """ import re import sqlite3 import tempfile import unittest from pathlib import Path from database.execution_history_schema import rotate_history_epoch from database.library_commands import LibraryCommandError from database.library_folders import folder_prefixes from database.operations import PromptDatabase from database.prompt_archive import TABLE as ARCHIVE from utils.hashing import generate_prompt_hash def save(db, text, **metadata): return db.save_prompt(text, prompt_hash=generate_prompt_hash(text), **metadata) def rows(db, sql, params=()): with db.model.get_connection() as conn: return [tuple(row) for row in conn.execute(sql, params).fetchall()] def archived_ids(db): return sorted(row[0] for row in rows(db, f"SELECT prompt_id FROM {ARCHIVE}")) def prompt_ids(db): return sorted(row[0] for row in rows(db, "SELECT id FROM prompts")) _STAMP = re.compile(r"^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}") def _stable(value): return "