"""meshnet-node CLI entry point.""" import argparse import sys import time def main() -> None: parser = argparse.ArgumentParser( prog="meshnet-node", description="Distributed Inference Network node client", ) subparsers = parser.add_subparsers(dest="command") start_cmd = subparsers.add_parser("start", help="Start the node server") start_cmd.add_argument( "--tracker", default="http://localhost:8080", help="Tracker URL" ) start_cmd.add_argument("--port", type=int, default=7000, help="Port to listen on") start_cmd.add_argument( "--model", default="stub-model", help="Model preset to request from tracker" ) start_cmd.add_argument( "--model-id", help="HuggingFace model id for the real PyTorch backend", ) start_cmd.add_argument("--shard-start", type=int, help="First layer index for an explicit shard") start_cmd.add_argument("--shard-end", type=int, help="Exclusive layer end index for an explicit shard") start_cmd.add_argument( "--quantization", choices=["bfloat16", "int8", "nf4"], default="bfloat16", help="Weight quantization for the real PyTorch backend", ) start_cmd.add_argument( "--host", default="0.0.0.0", help="Interface to bind to" ) start_cmd.add_argument( "--advertise-host", help="Reachable host/IP to advertise to the tracker (defaults to FQDN when binding 0.0.0.0)", ) start_cmd.add_argument( "--tracker-mode", action="store_true", help="Enable client-facing /v1/chat/completions (auto-enabled when shard-start=0)", ) start_cmd.add_argument( "--tracker-url", default=None, help="Tracker URL for route selection (used in tracker mode)", ) args = parser.parse_args() if args.command == "start": from meshnet_node.startup import run_startup try: node = run_startup( tracker_url=args.tracker, port=args.port, model=args.model, model_id=args.model_id, shard_start=args.shard_start, shard_end=args.shard_end, quantization=args.quantization, host=args.host, advertise_host=args.advertise_host, ) except Exception as exc: print(f"ERROR: {exc}", file=sys.stderr, flush=True) sys.exit(1) try: while True: time.sleep(1) except KeyboardInterrupt: node.stop() sys.exit(0) else: parser.print_help() if __name__ == "__main__": main()