MCPcopy Create free account
hub / github.com/1jehuang/jcode / main

Function main

scripts/jcode_monitor.py:281–337  ·  view source on GitHub ↗

Main monitor loop

()

Source from the content-addressed store, hash-verified

279
280
281def main():
282 """Main monitor loop"""
283 socket_path = sys.argv[1] if len(sys.argv) > 1 else get_socket_path()
284
285 print(f"Connecting to {socket_path}...")
286
287 state = MonitorState()
288 sock = None
289 request_id = 1
290 last_ping = 0
291
292 while True:
293 try:
294 # Connect if needed
295 if sock is None:
296 sock = connect_to_socket(socket_path)
297 if sock:
298 state.connected = True
299 # Subscribe to events
300 send_request(sock, {"type": "subscribe", "id": request_id})
301 request_id += 1
302 # Get initial state
303 send_request(sock, {"type": "state", "id": request_id})
304 request_id += 1
305 else:
306 state.connected = False
307
308 # Read events
309 if sock:
310 events = read_events(sock)
311 for event in events:
312 process_event(event, state)
313
314 # Periodic ping
315 if time.time() - last_ping > 5:
316 send_request(sock, {"type": "ping", "id": request_id})
317 request_id += 1
318 last_ping = time.time()
319
320 # Render dashboard
321 render_dashboard(state)
322
323 # Small delay
324 time.sleep(0.1)
325
326 except KeyboardInterrupt:
327 print(f"\n{Colors.DIM}Exiting...{Colors.RESET}")
328 break
329 except BrokenPipeError:
330 state.connected = False
331 sock = None
332 except Exception as e:
333 state.errors.append(str(e))
334 time.sleep(1)
335
336 if sock:
337 sock.close()
338

Callers 1

jcode_monitor.pyFile · 0.70

Calls 8

get_socket_pathFunction · 0.85
MonitorStateClass · 0.85
connect_to_socketFunction · 0.85
process_eventFunction · 0.85
render_dashboardFunction · 0.85
send_requestFunction · 0.70
read_eventsFunction · 0.70
closeMethod · 0.45

Tested by

no test coverage detected