新增:ekb agent rule-get,规则详情含关联Agent;rules 支持 --level 筛选
- rule_detail.py:支持 ID 或编码(0001/#0001)查询,展示完整描述和关联Agent列表 - rule_list.py:新增 --level 筛选参数 - 注册 rule-get 命令,更新命令树
This commit is contained in:
1 parent
fd41415d83
commit
a863377da8
4 files changed
+72
-1
No files matched your search
@@ -6,6 +6,7 @@ from ekb_cli.commands.agent.detail import cmd_detail
|
||||
from ekb_cli.commands.agent.logs import cmd_logs
|
||||
from ekb_cli.commands.agent.update import cmd_update
|
||||
from ekb_cli.commands.agent.rule_list import cmd_rule_list
|
||||
from ekb_cli.commands.agent.rule_detail import cmd_rule_detail
|
||||
|
||||
app = typer.Typer(help="智能审核 Agent 管理")
|
||||
|
||||
@@ -14,3 +15,4 @@ app.command("get")(cmd_detail)
|
||||
app.command("update")(cmd_update)
|
||||
app.command("logs")(cmd_logs)
|
||||
app.command("rules")(cmd_rule_list)
|
||||
app.command("rule-get")(cmd_rule_detail)
|
||||
@@ -0,0 +1,63 @@
|
||||
"""ekb agent rule-get:查看单条规则详情(含关联 Agent 列表)"""
|
||||
|
||||
import typer
|
||||
from rich.console import Console
|
||||
from rich.panel import Panel
|
||||
from rich.table import Table
|
||||
from rich import print as rprint
|
||||
|
||||
from ekb_cli.api import get_client
|
||||
from ekb_cli.api.agent import list_rules
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
def cmd_rule_detail(
|
||||
rule_ref: str = typer.Argument(..., help="规则 ID 或编码(如 2040826... 或 #0001 或 0001)"),
|
||||
):
|
||||
"""查看单条规则详情(含关联 Agent 列表)"""
|
||||
with get_client() as client:
|
||||
resp = list_rules(client)
|
||||
|
||||
items = resp.get("data", {}).get("items", [])
|
||||
|
||||
# 自适应:长字符串按 ID 匹配,短字符串按编码匹配(补井号)
|
||||
if len(rule_ref) > 10:
|
||||
rule = next((r for r in items if r.get("id") == rule_ref), None)
|
||||
else:
|
||||
code = rule_ref if rule_ref.startswith("#") else f"#{rule_ref}"
|
||||
rule = next((r for r in items if r.get("code") == code), None)
|
||||
|
||||
if not rule:
|
||||
rprint(f"[red]未找到规则:{rule_ref}[/red]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
level = rule.get("level", "")
|
||||
level_str = f"[red]{level}[/red]" if level == "严重" else f"[yellow]{level}[/yellow]"
|
||||
|
||||
content = "\n".join([
|
||||
f"[bold]ID[/bold] {rule.get('id')}",
|
||||
f"[bold]编码[/bold] {rule.get('code')}",
|
||||
f"[bold]风险等级[/bold] {level_str}",
|
||||
f"[bold]创建时间[/bold] {rule.get('createTime')}",
|
||||
f"[bold]更新时间[/bold] {rule.get('updateTime')}",
|
||||
"",
|
||||
f"[bold]适用场景[/bold]\n{rule.get('purpose') or '(无)'}",
|
||||
"",
|
||||
f"[bold]规则描述[/bold]\n{rule.get('description') or '(无)'}",
|
||||
])
|
||||
|
||||
code_display = rule.get("code", "")
|
||||
console.print(Panel(content, title=f"[bold]{code_display}[/bold]", expand=False))
|
||||
|
||||
# 关联 Agent 列表
|
||||
agents = rule.get("agents", [])
|
||||
if agents:
|
||||
table = Table(title=f"关联 Agent(共 {len(agents)} 个)", show_lines=True)
|
||||
table.add_column("名称")
|
||||
table.add_column("ID", style="dim", no_wrap=True)
|
||||
for a in agents:
|
||||
table.add_row(a.get("name", ""), a.get("id", ""))
|
||||
console.print(table)
|
||||
else:
|
||||
rprint("[dim](未关联任何 Agent)[/dim]")
|
||||
@@ -16,6 +16,7 @@ PURPOSE_MAX = 12
|
||||
|
||||
def cmd_rule_list(
|
||||
full: bool = typer.Option(False, "--full", "-f", help="显示完整内容,不截断描述字段"),
|
||||
level: str = typer.Option(None, "--level", "-l", help="按风险等级筛选:严重 / 一般"),
|
||||
):
|
||||
"""列出企业所有审核规则"""
|
||||
with get_client() as client:
|
||||
@@ -25,11 +26,15 @@ def cmd_rule_list(
|
||||
items = data.get("items", [])
|
||||
total = data.get("totalItems", 0)
|
||||
|
||||
if level:
|
||||
items = [r for r in items if r.get("level") == level]
|
||||
|
||||
if not items:
|
||||
rprint("[dim](暂无规则)[/dim]")
|
||||
return
|
||||
|
||||
table = Table(title=f"审核规则(共 {total} 条)", show_lines=True)
|
||||
title = f"审核规则(共 {total} 条,筛选:{level})" if level else f"审核规则(共 {total} 条)"
|
||||
table = Table(title=title, show_lines=True)
|
||||
table.add_column("规则编码", style="dim", no_wrap=True)
|
||||
if full:
|
||||
table.add_column("规则描述")
|
||||
|
||||
@@ -23,6 +23,7 @@ COMMAND_TREE = {
|
||||
"get": "查看 Agent 详情 → ekb agent get <id> --help",
|
||||
"update": "修改 Agent 配置 → ekb agent update <id> --help",
|
||||
"rules": "列出所有审核规则 → ekb agent rules --help",
|
||||
"rule-get": "查看规则详情 → ekb agent rule-get <id或编码>",
|
||||
"logs": "查看审核日志",
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user