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

Function main

scripts/sync_from_openclaw_runtime.py:208–349  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

206
207
208def main():
209 start = time.time()
210 now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
211 now_ms = int(time.time() * 1000)
212
213 try:
214 tasks = []
215 scan_files = 0
216
217 if SESSIONS_ROOT.exists():
218 for agent_dir in sorted(SESSIONS_ROOT.iterdir()):
219 if not agent_dir.is_dir():
220 continue
221 agent_id = agent_dir.name
222 sessions_file = agent_dir / 'sessions' / 'sessions.json'
223 if not sessions_file.exists():
224 continue
225 scan_files += 1
226
227 try:
228 raw = json.loads(sessions_file.read_text())
229 except Exception:
230 continue
231
232 if not isinstance(raw, dict):
233 continue
234
235 for session_key, row in raw.items():
236 if not isinstance(row, dict):
237 continue
238 tasks.append(build_task(agent_id, session_key, row, now_ms))
239
240 # merge mission control tasks (最小接入)
241 mc_tasks_file = DATA / 'mission_control_tasks.json'
242 if mc_tasks_file.exists():
243 try:
244 mc_tasks = json.loads(mc_tasks_file.read_text())
245 if isinstance(mc_tasks, list):
246 tasks.extend(mc_tasks)
247 except Exception:
248 pass
249
250 # merge manual parallel tasks (用于军机处并行看板展示)
251 manual_tasks_file = DATA / 'manual_parallel_tasks.json'
252 if manual_tasks_file.exists():
253 try:
254 manual_tasks = json.loads(manual_tasks_file.read_text())
255 if isinstance(manual_tasks, list):
256 tasks.extend(manual_tasks)
257 except Exception:
258 pass
259
260 tasks.sort(key=lambda x: x.get('sourceMeta', {}).get('updatedAt', 0), reverse=True)
261
262 # 去重(同一 id 只保留第一个=最新的)
263 seen_ids = set()
264 deduped = []
265 for t in tasks:

Callers 1

Calls 3

atomic_json_writeFunction · 0.90
build_taskFunction · 0.85
write_statusFunction · 0.85

Tested by

no test coverage detected