Newer
Older
cortex-hub / scripts / fix_table_prompt.py
import sqlite3
import os

db_path = "/Users/axieyangb/Project/CortexAI/ai-hub/data/ai_hub.db"

if not os.path.exists(db_path):
    print(f"Error: DB not found at {db_path}")
    exit(1)

conn = sqlite3.connect(db_path)
cursor = conn.cursor()

# Get the monitor template
cursor.execute("SELECT id, system_prompt_content FROM agent_templates WHERE name LIKE '%monitor%' OR name LIKE '%Technical%'")
templates = cursor.fetchall()

table_instruction = """
IMPORTANT FORMATTING RULES:
When providing system status or technical reports, ALWAYS use standard GitHub Flavored Markdown (GFM) tables.
- Each row MUST be on a new line.
- You MUST include the separator row (e.g., |---|---|---|) immediately after the header.
- Do NOT skip newlines between table rows.
- Ensure proper alignment and vertical padding.

Example:
| Component | Status | Notes |
| :--- | :--- | :--- |
| Connectivity | ACTIVE | Responsive via gRPC |
| CPU | 15% | Nominal |
"""

for tid, content in templates:
    if content:
        if "IMPORTANT FORMATTING RULES" not in content:
            new_content = content + "\n\n" + table_instruction
            cursor.execute("UPDATE agent_templates SET system_prompt_content = ? WHERE id = ?", (new_content, tid))
            print(f"Updated template {tid}")
    else:
        # Fallback if content is null
        cursor.execute("UPDATE agent_templates SET system_prompt_content = ? WHERE id = ?", (table_instruction, tid))
        print(f"Initialized template {tid} with instruction")

conn.commit()
conn.close()
print("Done.")