MCPcopy
hub / github.com/aiming-lab/MetaClaw / status

Function status

metaclaw/cli.py:359–433  ·  view source on GitHub ↗

Check whether MetaClaw is running.

(config: str | None, port: int | None)

Source from the content-addressed store, hash-verified

357)
358@click.option("--port", type=int, default=None, help="Proxy port of the instance to query.")
359def status(config: str | None, port: int | None):
360 """Check whether MetaClaw is running."""
361 import os
362 from pathlib import Path
363 from .launcher import pid_file_for_port
364
365 if config:
366 cs = ConfigStore(config_file=Path(config))
367 else:
368 cs = ConfigStore()
369 if port is None:
370 port = cs.get("proxy.port") or 30000
371
372 pid_file = pid_file_for_port(port)
373 if not pid_file.exists():
374 click.echo(f"MetaClaw: not running (port {port})")
375 return
376
377 try:
378 pid = int(pid_file.read_text().strip())
379 os.kill(pid, 0) # check if process exists
380 except (ProcessLookupError, ValueError):
381 click.echo("MetaClaw: not running (stale PID file)")
382 pid_file.unlink(missing_ok=True)
383 return
384 try:
385 import urllib.request
386 with urllib.request.urlopen(
387 f"http://localhost:{port}/healthz", timeout=2
388 ) as resp:
389 healthy = resp.status == 200
390 except Exception:
391 healthy = False
392
393 mode = cs.get("mode") or "?"
394 if healthy:
395 click.echo(f"MetaClaw: running (PID={pid}, mode={mode}, proxy=:{port})")
396 else:
397 click.echo(f"MetaClaw: starting (PID={pid}, mode={mode}, proxy=:{port})")
398
399 cfg = cs.to_metaclaw_config()
400 if cfg.memory_enabled:
401 from pathlib import Path as _P
402 import json as _json
403
404 policy_path = _P(cfg.memory_policy_path).expanduser()
405 if policy_path.exists():
406 try:
407 policy = _json.loads(policy_path.read_text())
408 click.echo(
409 "memory: "
410 f"mode={policy.get('retrieval_mode', '?')} "
411 f"units={policy.get('max_injected_units', '?')} "
412 f"tokens={policy.get('max_injected_tokens', '?')}"
413 )
414 except Exception:
415 click.echo(f"memory: policy file unreadable ({policy_path})")
416

Callers

nothing calls this directly

Calls 5

getMethod · 0.95
to_metaclaw_configMethod · 0.95
ConfigStoreClass · 0.85
pid_file_for_portFunction · 0.85
existsMethod · 0.45

Tested by

no test coverage detected