Full sync - all projects, memory, configs

This commit is contained in:
2026-03-21 20:27:59 -05:00
parent 2447677d4a
commit b33de10902
395 changed files with 1635300 additions and 459211 deletions

87
extract_conversations.py Normal file
View File

@ -0,0 +1,87 @@
#!/usr/bin/env python3
import json
import glob
import os
from collections import defaultdict
def extract_conversation_turns(session_file):
"""Extract user-assistant conversation pairs from a session file"""
turns = []
current_user_msg = None
try:
with open(session_file, 'r') as f:
for line in f:
if not line.strip():
continue
try:
data = json.loads(line)
except json.JSONDecodeError:
continue
if data.get('type') == 'message':
message = data.get('message', {})
role = message.get('role')
content = message.get('content', [])
if role == 'user':
# Extract text content from user message
text_content = []
for item in content:
if item.get('type') == 'text':
text_content.append(item.get('text', ''))
user_text = '\n'.join(text_content)
# Skip cron messages
if not user_text.startswith('[cron:'):
current_user_msg = user_text
elif role == 'assistant' and current_user_msg:
# Extract text content from assistant message
text_content = []
for item in content:
if item.get('type') == 'text':
text_content.append(item.get('text', ''))
assistant_text = '\n'.join(text_content)
if assistant_text.strip():
turns.append({
'user': current_user_msg,
'assistant': assistant_text,
'agent_id': 'case',
'session': 'main'
})
current_user_msg = None
except Exception as e:
print(f"Error processing {session_file}: {e}")
return turns
def main():
sessions_dir = '/home/wdjones/.openclaw/agents/main/sessions/'
session_files = glob.glob(os.path.join(sessions_dir, '*.jsonl'))
# Sort by modification time, newest first
session_files.sort(key=os.path.getmtime, reverse=True)
all_turns = []
# Process each session file until we get 10 turns
for session_file in session_files:
if len(all_turns) >= 10:
break
turns = extract_conversation_turns(session_file)
all_turns.extend(turns)
# Take the last 10 turns
recent_turns = all_turns[-10:] if len(all_turns) >= 10 else all_turns
# Output each turn as JSON for the auto-memory-hook.py
for turn in recent_turns:
print(json.dumps(turn))
if __name__ == '__main__':
main()