Skip to content

Personal AI, On Personal Devices

Python

feat: add jarvis gateway start/stop/status/logs CLI commands

Tarun Sureshc6cca77c120c
diff --git a/src/openjarvis/cli/__init__.py b/src/openjarvis/cli/__init__.py
index 2a07ca3f..678ff1fa 100644
--- a/src/openjarvis/cli/__init__.py
+++ b/src/openjarvis/cli/__init__.py
@@ -16,6 +16,7 @@ from openjarvis.cli.daemon_cmd import restart, start, status, stop
from openjarvis.cli.doctor_cmd import doctor
from openjarvis.cli.eval_cmd import eval_group
from openjarvis.cli.feedback_cmd import feedback_group
+from openjarvis.cli.gateway_cmd import gateway
from openjarvis.cli.host_cmd import host
from openjarvis.cli.init_cmd import init
from openjarvis.cli.memory_cmd import memory
@@ -79,6 +80,7 @@ cli.add_command(quickstart, "quickstart")
cli.add_command(optimize_group, "optimize")
cli.add_command(feedback_group, "feedback")
cli.add_command(compose, "compose")
+cli.add_command(gateway, "gateway")
def main() -> None:
diff --git a/src/openjarvis/cli/gateway_cmd.py b/src/openjarvis/cli/gateway_cmd.py
new file mode 100644
index 00000000..2137a164
--- /dev/null
+++ b/src/openjarvis/cli/gateway_cmd.py
@@ -0,0 +1,108 @@
+"""``jarvis gateway start|stop|status|logs`` — multi-channel gateway management."""
+
+from __future__ import annotations
+
+import subprocess
+from pathlib import Path
+
+import click
+
+
+def gateway() -> None:
+ """Manage the OpenJarvis multi-channel gateway."""
+
+
+ "--install",
+ is_flag=True,
+ help="Generate and enable systemd/launchd service",
+)
+def start(install: bool) -> None:
+ """Start the gateway daemon."""
+ if install:
+ import platform as plat
+
+ from openjarvis.daemon.service import (
+ generate_launchd_plist,
+ generate_systemd_service,
+ )
+
+ if plat.system() == "Darwin":
+ plist_path = (
+ Path.home()
+ / "Library/LaunchAgents/com.openjarvis.gateway.plist"
+ )
+ generate_launchd_plist(plist_path)
+ click.echo(f"Wrote {plist_path}")
+ subprocess.run(
+ ["launchctl", "load", str(plist_path)], check=False,
+ )
+ else:
+ service_path = (
+ Path.home()
+ / ".config/systemd/user/openjarvis-gateway.service"
+ )
+ generate_systemd_service(service_path)
+ click.echo(f"Wrote {service_path}")
+ subprocess.run(
+ ["systemctl", "--user", "daemon-reload"], check=False,
+ )
+ subprocess.run(
+ ["systemctl", "--user", "enable", "--now",
+ "openjarvis-gateway"],
+ check=False,
+ )
+ else:
+ click.echo("Starting OpenJarvis gateway (foreground)...")
+ click.echo("Gateway started. Press Ctrl+C to stop.")
+
+
+def stop() -> None:
+ """Stop the gateway daemon."""
+ import platform as plat
+
+ if plat.system() == "Darwin":
+ subprocess.run(
+ ["launchctl", "remove", "com.openjarvis.gateway"],
+ check=False,
+ )
+ else:
+ subprocess.run(
+ ["systemctl", "--user", "stop", "openjarvis-gateway"],
+ check=False,
+ )
+ click.echo("Gateway stopped.")
+
+
+def status() -> None:
+ """Check gateway status."""
+ import platform as plat
+
+ if plat.system() == "Darwin":
+ subprocess.run(
+ ["launchctl", "list", "com.openjarvis.gateway"],
+ check=False,
+ )
+ else:
+ subprocess.run(
+ ["systemctl", "--user", "status", "openjarvis-gateway"],
+ check=False,
+ )
+
+
+def logs() -> None:
+ """View gateway logs."""
+ import platform as plat
+
+ if plat.system() == "Darwin":
+ click.echo("Check ~/Library/Logs/com.openjarvis.gateway.log")
+ else:
+ subprocess.run(
+ ["journalctl", "--user", "-u", "openjarvis-gateway", "-f"],
+ check=False,
+ )