Files
workspace/debug_memory.py

48 lines
2.0 KiB
Python

#!/usr/bin/env python3
import json
import os
import glob
def find_newest_session():
sessions_dir = "/home/wdjones/.openclaw/agents/main/sessions/"
pattern = os.path.join(sessions_dir, "*.jsonl")
files = glob.glob(pattern)
files = [f for f in files if not "deleted" in f and not f.endswith(".lock")]
newest_file = max(files, key=os.path.getmtime)
return newest_file
def debug_messages(session_file):
"""Debug what messages are in the file"""
messages = []
with open(session_file, 'r') as f:
for line_num, line in enumerate(f, 1):
try:
data = json.loads(line.strip())
if data.get("type") == "message" and "message" in data:
msg = data["message"]
role = msg.get("role")
if role in ["user", "assistant"]:
content_parts = msg.get("content", [])
print(f"Line {line_num}: {role} message with {len(content_parts)} content parts")
for i, part in enumerate(content_parts):
part_type = part.get("type", "unknown")
print(f" Part {i}: {part_type}")
if part_type == "text":
text = part.get("text", "")[:100] # First 100 chars
print(f" Text: {text}...")
messages.append({
"line": line_num,
"role": role,
"content_parts": len(content_parts)
})
except json.JSONDecodeError:
continue
print(f"\nTotal messages found: {len(messages)}")
for msg in messages:
print(f" Line {msg['line']}: {msg['role']} ({msg['content_parts']} parts)")
session_file = "/home/wdjones/.openclaw/agents/main/sessions/83fac8ec-437c-4841-8ce4-c4b437266acc.jsonl"
print(f"Debugging: {session_file}")
debug_messages(session_file)