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
115 lines
3.7 KiB
Python
115 lines
3.7 KiB
Python
"""Slash commands: diagnostics, version, exit."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from rich.console import Console
|
|
|
|
import platform
|
|
from platform.terminal.prompt_support import print_session_resume_hint
|
|
from surfaces.interactive_shell.command_registry.types import SlashCommand
|
|
from surfaces.interactive_shell.runtime import Session
|
|
from surfaces.interactive_shell.ui import (
|
|
BOLD_BRAND,
|
|
DIM,
|
|
ERROR,
|
|
HIGHLIGHT,
|
|
WARNING,
|
|
print_repl_table,
|
|
repl_table,
|
|
)
|
|
|
|
|
|
def _flush_analytics_on_exit(console: Console) -> None:
|
|
"""Best-effort PostHog drain with a spinner so /quit is not silent or fire-and-forget."""
|
|
from platform.analytics.provider import analytics_needs_flush, shutdown_analytics
|
|
|
|
if not analytics_needs_flush():
|
|
shutdown_analytics(flush=False)
|
|
return
|
|
|
|
if console.is_terminal:
|
|
with console.status(
|
|
f"[{DIM}]finishing up…[/]",
|
|
spinner="dots",
|
|
spinner_style=DIM,
|
|
):
|
|
shutdown_analytics(flush=True)
|
|
else:
|
|
shutdown_analytics(flush=True)
|
|
|
|
|
|
def _cmd_exit(session: Session, console: Console, _args: list[str]) -> bool:
|
|
if session.session_id:
|
|
console.print()
|
|
print_session_resume_hint(console, session.session_id)
|
|
_flush_analytics_on_exit(console)
|
|
console.print(f"[{DIM}]goodbye.[/]")
|
|
return False
|
|
|
|
|
|
def _cmd_health(_session: Session, console: Console, _args: list[str]) -> bool:
|
|
from config.config import get_environment
|
|
from integrations.store import STORE_PATH
|
|
from integrations.verify import verify_integrations
|
|
from surfaces.interactive_shell.ui.health import render_health_report
|
|
|
|
results = verify_integrations()
|
|
environment = get_environment().value
|
|
render_health_report(
|
|
console=console,
|
|
environment=environment,
|
|
integration_store_path=STORE_PATH,
|
|
results=results,
|
|
)
|
|
return True
|
|
|
|
|
|
def _cmd_doctor(_session: Session, console: Console, _args: list[str]) -> bool:
|
|
from surfaces.cli.commands.doctor import _CHECKS, _check
|
|
|
|
status_styles: dict[str, str] = {"ok": HIGHLIGHT, "warn": WARNING, "error": ERROR}
|
|
table = repl_table(title="OpenSRE Doctor\n", title_style=BOLD_BRAND)
|
|
table.add_column("check", style="bold")
|
|
table.add_column("status")
|
|
table.add_column("detail", style=DIM, overflow="fold")
|
|
|
|
issues = 0
|
|
for name, fn in _CHECKS:
|
|
result = _check(name, fn)
|
|
status = result["status"]
|
|
style = status_styles.get(status, DIM)
|
|
table.add_row(name, f"[{style}]{status}[/]", result["detail"])
|
|
if status in ("warn", "error"):
|
|
issues += 1
|
|
|
|
print_repl_table(console, table)
|
|
if issues:
|
|
console.print(f"[{WARNING}]{issues} issue(s) found.[/]")
|
|
else:
|
|
console.print(f"[{HIGHLIGHT}]all checks passed.[/]")
|
|
return True
|
|
|
|
|
|
def _cmd_version(_session: Session, console: Console, _args: list[str]) -> bool:
|
|
from config.version import get_opensre_version
|
|
|
|
table = repl_table(title="Version info\n", title_style=BOLD_BRAND, show_header=False)
|
|
table.add_column("key", style="bold")
|
|
table.add_column("value")
|
|
table.add_row("opensre", get_opensre_version())
|
|
table.add_row("python", platform.python_version())
|
|
table.add_row("os", f"{platform.system().lower()} ({platform.machine()})")
|
|
print_repl_table(console, table)
|
|
return True
|
|
|
|
|
|
COMMANDS: list[SlashCommand] = [
|
|
SlashCommand("/exit", "Exit the interactive shell.", _cmd_exit),
|
|
SlashCommand("/quit", "Alias for /exit.", _cmd_exit),
|
|
SlashCommand("/health", "Show integration and agent health.", _cmd_health),
|
|
SlashCommand("/doctor", "Run full environment diagnostic.", _cmd_doctor),
|
|
SlashCommand("/version", "Print version, Python, and OS info.", _cmd_version),
|
|
]
|
|
|
|
__all__ = ["COMMANDS"]
|