4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
"""Slash command: /gateway — control the OpenSRE gateway daemon."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from rich.console import Console
|
|
from rich.markup import escape
|
|
|
|
from gateway.daemon import (
|
|
GATEWAY_LOG_FILE,
|
|
gateway_daemon_pid,
|
|
read_component_status,
|
|
read_gateway_log_tail,
|
|
start_gateway_daemon,
|
|
stop_gateway_daemon,
|
|
)
|
|
from surfaces.interactive_shell.command_registry.types import SlashCommand
|
|
from surfaces.interactive_shell.runtime import Session
|
|
from surfaces.interactive_shell.ui import DIM, ERROR, HIGHLIGHT
|
|
|
|
_USAGE = "/gateway [start|stop|status|logs [lines]]"
|
|
|
|
|
|
def _print_outcome(console: Console, ok: bool, message: str) -> None:
|
|
console.print(f"[{HIGHLIGHT if ok else ERROR}]{escape(message)}[/]")
|
|
|
|
|
|
def _cmd_gateway(_session: Session, console: Console, args: list[str]) -> bool:
|
|
sub = args[0].lower() if args else "status"
|
|
|
|
if sub == "start":
|
|
_print_outcome(console, *start_gateway_daemon())
|
|
console.print(f"[{DIM}]logs: {GATEWAY_LOG_FILE} — /gateway logs to tail[/]")
|
|
elif sub == "stop":
|
|
_print_outcome(console, *stop_gateway_daemon())
|
|
elif sub == "status":
|
|
pid = gateway_daemon_pid()
|
|
state = f"[{HIGHLIGHT}]running (pid {pid})[/]" if pid else f"[{DIM}]stopped[/]"
|
|
console.print(f"OpenSRE gateway: {state}")
|
|
for name, detail in read_component_status().items():
|
|
console.print(f" {escape(name)}: {escape(detail)}")
|
|
console.print(f"[{DIM}]logs: {GATEWAY_LOG_FILE}[/]")
|
|
elif sub == "logs":
|
|
lines = int(args[1]) if len(args) > 1 and args[1].isdigit() else 30
|
|
if tail := read_gateway_log_tail(lines):
|
|
console.print(escape(tail))
|
|
else:
|
|
console.print(f"[{DIM}]no gateway logs yet at {GATEWAY_LOG_FILE}[/]")
|
|
else:
|
|
console.print(f"[{ERROR}]usage:[/] {_USAGE}")
|
|
return True
|
|
|
|
|
|
COMMANDS: list[SlashCommand] = [
|
|
SlashCommand(
|
|
"/gateway",
|
|
"Control the background OpenSRE gateway daemon: start, stop, status, logs.",
|
|
_cmd_gateway,
|
|
usage=(_USAGE,),
|
|
notes=(
|
|
"The gateway daemon runs the web health app, Telegram chat, and the "
|
|
"task scheduler; logs are stored in ~/.opensre/gateway/gateway.log.",
|
|
),
|
|
first_arg_completions=(
|
|
("start", "start the gateway daemon (web, telegram, scheduler)"),
|
|
("stop", "stop the gateway daemon"),
|
|
("status", "show the daemon and its components"),
|
|
("logs", "print recent gateway log lines"),
|
|
),
|
|
),
|
|
]
|
|
|
|
__all__ = ["COMMANDS"]
|