Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

137 lines
4.5 KiB
Python

"""Rich landing and help renderers for the OpenSRE CLI."""
from __future__ import annotations
from collections.abc import Sequence
import click
from rich.console import Console
from rich.text import Text
from platform.terminal.theme import BRAND, DIM, TEXT
from surfaces.interactive_shell.ui.banner import build_ready_panel
_LANDING_EXAMPLES: tuple[tuple[str, str], ...] = (
(
'opensre "investigate high latency in checkout-api"',
"Start the interactive agent with a prompt",
),
("opensre onboard", "Configure LLM provider and integrations"),
("opensre investigate -i alert.json", "Run RCA against an alert payload"),
("opensre investigate --service <name>", "Run RCA on a deployed remote service"),
("opensre remote --url <ip> health", "Check a remote deployed agent"),
("opensre remote ops status", "Inspect hosted service status (Railway)"),
("opensre tests", "Browse and run inventoried tests"),
("opensre integrations list", "Show configured integrations"),
("opensre guardrails rules", "List configured guardrail rules"),
("opensre health", "Check integration and agent setup status"),
("opensre doctor", "Run a full environment diagnostic"),
("opensre update", "Update to the latest version"),
("opensre version", "Print detailed version, Python and OS info"),
)
def _commands_from_group(group: click.Group) -> tuple[tuple[str, str], ...]:
ctx = click.Context(group)
rows = []
for name in group.list_commands(ctx):
cmd = group.get_command(ctx, name)
if cmd is not None and not cmd.hidden:
rows.append((name, cmd.get_short_help_str(limit=200)))
return tuple(rows)
def _options_from_command(command: click.Command) -> tuple[tuple[str, str], ...]:
ctx = click.Context(command)
rows: list[tuple[str, str]] = []
for param in command.get_params(ctx):
if getattr(param, "hidden", False):
continue
if not isinstance(param, click.Option):
continue
record = param.get_help_record(ctx)
if record is not None:
rows.append(record)
return tuple(rows)
def _render_usage(console: Console) -> None:
console.print(
Text.assemble(
(" Usage: "),
("opensre", f"bold {TEXT}"),
(" [OPTIONS] [COMMAND] [ARGS]..."),
)
)
console.print(
Text.assemble(
(" ", ""),
("No COMMAND", DIM),
(": start the interactive shell when stdin/stdout are TTYs.", DIM),
)
)
def _render_rows(
console: Console,
*,
title: str,
rows: Sequence[tuple[str, str]],
width: int | None = None,
) -> None:
effective_width = (
width + 2 if width is not None else max((len(label) for label, _ in rows), default=0) + 2
)
console.print(Text.assemble((f" {title}:", f"bold {TEXT}")))
for label, description in rows:
console.print(
Text.assemble(
(" ", ""),
(f"{label:<{effective_width}}", f"bold {BRAND}"),
description,
)
)
def render_help(group: click.Group) -> None:
"""Render the root help view, deriving the command list from the live Click group."""
console = Console(highlight=False)
commands = _commands_from_group(group)
options = _options_from_command(group)
console.print()
_render_usage(console)
console.print()
_render_rows(console, title="Commands", rows=commands, width=16)
console.print()
_render_rows(console, title="Options", rows=options)
console.print()
def render_landing(group: click.Group) -> None:
"""Render the root landing page shown with no subcommand."""
console = Console(highlight=False)
options = _options_from_command(group)
console.print()
console.print(build_ready_panel(console))
console.print(
Text.assemble(
(" ", ""),
"open-source SRE agent for automated incident investigation and root cause analysis",
)
)
console.print()
_render_usage(console)
console.print()
_render_rows(console, title="Quick start", rows=_LANDING_EXAMPLES, width=42)
console.print()
_render_rows(console, title="Options", rows=options)
console.print()
class RichGroup(click.Group):
"""Click group with a custom Rich-powered help screen."""
def format_help(self, ctx: click.Context, _formatter: click.HelpFormatter) -> None:
assert isinstance(ctx.command, click.Group)
render_help(ctx.command)