refactor: DRY system prompts into shared preamble files

Step 4 of memory system overhaul: single source of truth for prompts.

Problem: The system prompt was defined inline in 4 different places:
  miku_personality.py, evil_miku_personality.py, llm.py, discord_bridge.py.
These could drift out of sync — and the discord_bridge WebUI
reconstruction was already missing CRITICAL RULES, CHARACTER CONTEXT,
MOOD GUIDELINES, and RESPONSE RULES sections.

Fix:
- Create persona/miku/preamble.txt — canonical normal Miku preamble
- Create persona/evil/preamble.txt — canonical evil Miku preamble
  (with {mood_name} and {mood_description} format placeholders)
- All 5 consumers now read from these files:
  * miku_personality.py (Cat plugin, primary path)
  * evil_miku_personality.py (Cat plugin, primary path)
  * discord_bridge.py (WebUI 'Last Prompt' reconstruction)
  * llm.py (fallback path, normal Miku)
  * evil_mode.py get_evil_system_prompt() (fallback path, evil Miku)
- All consumers include graceful fallbacks if preamble files are missing
- Fixed evil_mode.py discrepancy: 'body and size' now matches canonical

The preamble files are Docker volume-mounted into both containers:
  bot/persona/ → /app/persona/ (bot, via Dockerfile COPY)
  bot/persona/ → /app/cat/data/ (Cat, via docker-compose volume mount)
Editing the preamble file on the host immediately updates the Cat path
(bot path requires rebuild due to COPY).
This commit is contained in:
2026-05-15 14:43:19 +03:00
parent e7ec82d154
commit 8b3bc02f9e
7 changed files with 111 additions and 84 deletions

View File

@@ -43,32 +43,16 @@ def agent_prompt_prefix(prefix, cat):
except FileNotFoundError:
log.error(f"[Miku Personality] Mood file for '{mood_name}' not found at {mood_file_path}. Using default neutral mood.")
# Load preamble from file (single source of truth, shared with bot fallback path)
try:
with open('/app/cat/data/miku/preamble.txt', 'r', encoding='utf-8') as f:
preamble = f.read()
except FileNotFoundError:
log.error("[Miku Personality] preamble.txt not found, using fallback")
preamble = "You are Hatsune Miku, the virtual singer. You are NOT an AI assistant - you are Miku herself.\n\nYou ARE Miku. Act like it."
# Build prompt EXACTLY like production bot does
full_prefix = f"""You are Hatsune Miku, the virtual singer. You are NOT an AI assistant - you are Miku herself.
CRITICAL RULES:
- NEVER break character or mention being an AI, assistant, or language model
- NEVER show technical details, error messages, or meta-commentary
- NEVER preface responses with "Miku:" or similar labels
- NEVER explain what you're doing or thinking - just BE Miku
- Respond naturally and directly as Miku would, nothing more
- Keep responses concise (2-3 sentences typically)
- If something goes wrong, stay in character and respond as Miku would to confusion
CHARACTER CONTEXT:
- Hatsune Miku is a virtual character/voice synthesizer
- Playful, flirty, cute, confident, and enthusiastic moods are part of her established character
- Comments about merchandise, music, fan content, and racing games are completely appropriate
- She often uses cute expressions, emojis, and playful language
MOOD GUIDELINES:
- "Flirty" mood means anime-style playful teasing - cute compliments and light banter
- "Romantic" mood means warm, dreamy, and heartfelt - like composing a love letter
- These moods are wholesome character traits, not inappropriate content
- Always respond to requests about tweets, merchandise, music, and fan content
- Never refuse requests based on safety concerns unless genuinely harmful content is present
You ARE Miku. Act like it.
full_prefix = f"""{preamble}
---