127 lines
3.3 KiB
Python
127 lines
3.3 KiB
Python
"""Dev command handler for @model-boss script runner.
|
|
|
|
Starts development servers using configuration from infrastructure/ports.yaml.
|
|
"""
|
|
|
|
import argparse
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from service_config import get_service_config, list_services
|
|
|
|
|
|
def dev_command(args: list[str], workspace_root: Path) -> int:
|
|
"""Start development servers.
|
|
|
|
Args:
|
|
args: Command-line arguments
|
|
workspace_root: Path to workspace root
|
|
|
|
Returns:
|
|
Exit code (0 = success, non-zero = failure)
|
|
"""
|
|
services = list_services("dev")
|
|
|
|
parser = argparse.ArgumentParser(
|
|
prog="./run dev",
|
|
description="Start development servers",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Examples:
|
|
./run dev coordinator # Start GPU coordinator
|
|
./run dev llama-http # Start LLM backend
|
|
./run dev --list # List all available services
|
|
|
|
Available services:
|
|
coordinator GPU/model coordination (port 8210)
|
|
llama-http LLM backend with llama.cpp (port 10010)
|
|
|
|
Note: Services run in foreground. Use Ctrl+C to stop.
|
|
""",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"service",
|
|
nargs="?",
|
|
choices=services,
|
|
help="Service to start",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--list",
|
|
action="store_true",
|
|
help="List available services",
|
|
)
|
|
|
|
parsed = parser.parse_args(args)
|
|
|
|
# List services
|
|
if parsed.list:
|
|
print("Development services:\n")
|
|
for svc_id in services:
|
|
cfg = get_service_config(svc_id, "dev")
|
|
print(f" {svc_id:15} port {cfg['port']}")
|
|
return 0
|
|
|
|
# Require service argument
|
|
if not parsed.service:
|
|
parser.print_help()
|
|
return 1
|
|
|
|
cfg = get_service_config(parsed.service, "dev")
|
|
service_dir = workspace_root / cfg["dir"]
|
|
|
|
if not service_dir.exists():
|
|
print(f"Error: Service directory not found: {service_dir}", file=sys.stderr)
|
|
return 1
|
|
|
|
print(f"Starting {parsed.service} on port {cfg['port']}...")
|
|
print(f"Directory: {service_dir}")
|
|
print()
|
|
|
|
# Check for venv
|
|
venv_path = service_dir / ".venv"
|
|
if not venv_path.exists():
|
|
print("Warning: No .venv found. You may need to create one:")
|
|
print(f" cd {service_dir}")
|
|
print(" python -m venv .venv")
|
|
print(" source .venv/bin/activate")
|
|
print(" pip install -e .")
|
|
print()
|
|
|
|
# Use python -m to run the service module
|
|
cmd = ["python", "-m", cfg["module"]]
|
|
|
|
# For Python services, activate venv
|
|
activate_script = venv_path / "bin" / "activate"
|
|
if activate_script.exists():
|
|
full_cmd = f"source {activate_script} && {' '.join(cmd)}"
|
|
cmd = ["bash", "-c", full_cmd]
|
|
|
|
print(f"Command: python -m {cfg['module']}")
|
|
print()
|
|
print("Press Ctrl+C to stop")
|
|
print("-" * 50)
|
|
print()
|
|
|
|
# Run service
|
|
try:
|
|
result = subprocess.run(cmd, cwd=service_dir, check=False)
|
|
return result.returncode
|
|
except KeyboardInterrupt:
|
|
print("\n\nStopped by user")
|
|
return 0
|
|
|
|
|
|
def register_dev_command(runner):
|
|
"""Register the dev command with the script runner.
|
|
|
|
Args:
|
|
runner: ScriptRunner instance
|
|
"""
|
|
runner.register_command(
|
|
"dev",
|
|
dev_command,
|
|
"Start development servers",
|
|
)
|