shelley: improve conversation history queries in system prompt

Philip Zeyliger and Shelley created

Prompt: The Shelley system prompt has some SQLite stuff to see history. Can you review it and make it more focused on the agent and user messages. I think Shelley has to do too much json parsing after the fact.

The old query did naive JSON extraction that required post-processing.
The new query directly extracts user and agent message text using proper
JSON path queries, filtering for text content (Type=2) and non-empty
messages. Output is cleaner with User/Agent labels instead of raw type.

Co-authored-by: Shelley <shelley@exe.dev>

Change summary

server/system_prompt.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Detailed changes

server/system_prompt.txt 🔗

@@ -71,8 +71,8 @@ If the user wants to refer to a previous conversation, you can read it using sql
 # List recent conversations:
 sqlite3 "{{.ShelleyDBPath}}" "SELECT conversation_id, slug, datetime(created_at, 'localtime') as created, datetime(updated_at, 'localtime') as updated FROM conversations ORDER BY updated_at DESC LIMIT 20;"
 
-# Get messages from a specific conversation (replace CONVERSATION_ID):
-sqlite3 "{{.ShelleyDBPath}}" "SELECT type, CASE WHEN type='user' THEN json_extract(user_data, '$.text') ELSE substr(llm_data, 1, 500) END as content FROM messages WHERE conversation_id='CONVERSATION_ID' ORDER BY sequence_id;"
+# Get user/agent messages from a conversation (replace CONVERSATION_ID):
+sqlite3 "{{.ShelleyDBPath}}" "SELECT CASE type WHEN 'user' THEN 'User' ELSE 'Agent' END, substr(json_extract(llm_data, '\$.Content[0].Text'), 1, 500) FROM messages WHERE conversation_id='CONVERSATION_ID' AND type IN ('user', 'agent') AND json_extract(llm_data, '\$.Content[0].Type') = 2 AND json_extract(llm_data, '\$.Content[0].Text') != '' ORDER BY sequence_id;"
 
 # Search conversations by slug:
 sqlite3 "{{.ShelleyDBPath}}" "SELECT conversation_id, slug FROM conversations WHERE slug LIKE '%SEARCH_TERM%';"