From 5566d496259048879ac0967513e3e46fc980c317 Mon Sep 17 00:00:00 2001 From: yunyingk Date: Mon, 6 Apr 2026 01:21:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9Arule-get=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=88=86=E5=8C=BA=E5=B8=83=E5=B1=80=EF=BC=8C=E5=85=83?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=94=A8=E8=A1=A8=E6=A0=BC=E5=B7=A6=E5=8F=B3?= =?UTF-8?q?=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ekb_cli/commands/agent/rule_detail.py | 44 ++++++++++++++--------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/ekb_cli/commands/agent/rule_detail.py b/src/ekb_cli/commands/agent/rule_detail.py index 7a4243d..bfe5c1a 100644 --- a/src/ekb_cli/commands/agent/rule_detail.py +++ b/src/ekb_cli/commands/agent/rule_detail.py @@ -4,6 +4,8 @@ import typer from rich.console import Console from rich.panel import Panel from rich.table import Table +from rich.columns import Columns +from rich.text import Text from rich import print as rprint from ekb_cli.api import get_client @@ -34,23 +36,33 @@ def cmd_rule_detail( raise typer.Exit(1) level = rule.get("level", "") - level_str = f"[bold red]{level}[/bold red]" if level == "严重" else f"[bold yellow]{level}[/bold yellow]" - - content = "\n".join([ - f"[dim]ID[/dim] {rule.get('id')}", - f"[bold]编码[/bold] [cyan]{rule.get('code')}[/cyan]", - f"[bold]风险等级[/bold] {level_str}", - f"[dim]创建时间[/dim] {rule.get('createTime')}", - f"[dim]更新时间[/dim] {rule.get('updateTime')}", - "", - f"[bold cyan]适用场景[/bold cyan]\n{rule.get('purpose') or '(无)'}", - "", - f"[bold cyan]规则描述[/bold cyan]\n{rule.get('description') or '(无)'}", - ]) - - code_display = rule.get("code", "") level_color = "red" if level == "严重" else "yellow" - console.print(Panel(content, title=f"[bold {level_color}]{code_display}[/bold {level_color}]", expand=False)) + level_str = f"[bold {level_color}]{level}[/bold {level_color}]" + code_display = rule.get("code", "") + + # 元数据表格:左右对齐,字段名右对齐,值左对齐 + meta = Table(box=None, show_header=False, padding=(0, 1)) + meta.add_column(style="dim", justify="right") + meta.add_column() + meta.add_row("编码", f"[cyan bold]{code_display}[/cyan bold]") + meta.add_row("风险等级", level_str) + meta.add_row("ID", f"[dim]{rule.get('id')}[/dim]") + meta.add_row("创建时间", f"[dim]{rule.get('createTime')}[/dim]") + meta.add_row("更新时间", f"[dim]{rule.get('updateTime')}[/dim]") + + console.print(Panel( + meta, + title=f"[bold {level_color}]{code_display}[/bold {level_color}]", + expand=False, + )) + + # 适用场景 + purpose = rule.get("purpose") or "(无)" + console.print(Panel(purpose, title="[bold cyan]适用场景[/bold cyan]", expand=False)) + + # 规则描述 + description = rule.get("description") or "(无)" + console.print(Panel(description, title="[bold cyan]规则描述[/bold cyan]", expand=False)) # 关联 Agent 列表 agents = rule.get("agents", [])