MCPcopy
hub / github.com/cft0808/edict / load_activity

Function load_activity

scripts/sync_from_openclaw_runtime.py:62–129  ·  view source on GitHub ↗
(session_file, limit=12)

Source from the content-addressed store, hash-verified

60
61
62def load_activity(session_file, limit=12):
63 p = pathlib.Path(session_file or '')
64 if not p.exists():
65 return []
66 rows = []
67 try:
68 lines = p.read_text(errors='ignore').splitlines()
69 except Exception:
70 return []
71
72 # Read all valid JSON lines first
73 events = []
74 for ln in lines:
75 try:
76 item = json.loads(ln)
77 events.append(item)
78 except:
79 continue
80
81 # Process events to extract meaningful activity
82 # We want to show what the agent is *thinking* or *doing*
83 for item in reversed(events):
84 msg = item.get('message') or {}
85 role = msg.get('role')
86 ts = item.get('timestamp') or ''
87
88 if role == 'toolResult':
89 tool = msg.get('toolName', '-')
90 details = msg.get('details') or {}
91 # If tool output is short, show it
92 content = msg.get('content', [{'text': ''}])[0].get('text', '')
93 if len(content) < 50:
94 text = f"Tool '{tool}' returned: {content}"
95 else:
96 text = f"Tool '{tool}' finished"
97 rows.append({'at': ts, 'kind': 'tool', 'text': text})
98
99 elif role == 'assistant':
100 text = ''
101 for c in msg.get('content', []):
102 if c.get('type') == 'text' and c.get('text'):
103 raw_text = c.get('text').strip()
104 # Clean up common prefixes
105 clean_text = raw_text.replace('[[reply_to_current]]', '').strip()
106 if clean_text:
107 text = clean_text
108 break
109 if text:
110 # Prioritize showing the "thought" - usually the first few sentences
111 summary = text.split('\n')[0]
112 if len(summary) > 200:
113 summary = summary[:200] + '...'
114 rows.append({'at': ts, 'kind': 'assistant', 'text': summary})
115
116 elif role == 'user':
117 # Also show what user asked, can be context relevant
118 text = ''
119 for c in msg.get('content', []):

Callers 1

build_taskFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected