新增:ekb agent rule-create 命令,支持新建审核规则

This commit is contained in:
gitea committed 2026-04-08 00:05:34 +08:00
1 parent 0f5b4c6272
commit 21d8832e44
3 files changed
+41

No files matched your search

+2
View File
@@ -7,6 +7,7 @@ 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
from ekb_cli.commands.agent.rule_create import cmd_rule_create
app = typer.Typer(help="智能审核 Agent 管理")
@@ -16,3 +17,4 @@ app.command("update")(cmd_update)
app.command("logs")(cmd_logs)
app.command("rules")(cmd_rule_list)
app.command("rule-get")(cmd_rule_detail)
app.command("rule-create")(cmd_rule_create)
+38
View File
@@ -0,0 +1,38 @@
"""ekb agent rule-create:新建审核规则"""
import typer
from rich import print as rprint
from ekb_cli.api import get_client
from ekb_cli.api.agent import save_rule
VALID_LEVELS = {"严重", "一般"}
def cmd_rule_create(
purpose: str = typer.Option(..., "--purpose", "-p", help="适用场景(规则名称)"),
description: str = typer.Option(..., "--desc", "-d", help="规则描述"),
level: str = typer.Option("严重", "--level", "-l", help="风险等级:严重 / 一般"),
):
"""新建审核规则"""
if level not in VALID_LEVELS:
rprint(f"[red]错误:--level 只接受 严重 / 一般,当前值:{level}[/red]")
raise typer.Exit(1)
payload = {"purpose": purpose, "description": description, "level": level}
with get_client() as client:
resp = save_rule(client, payload)
data = resp.get("data", {})
if not data:
rprint(f"[red]创建失败:{resp}[/red]")
raise typer.Exit(1)
rprint(f"[green]✓ 规则创建成功[/green]")
rprint(f" 编码:[bold]{data.get('code')}[/bold]")
rprint(f" ID:[dim]{data.get('id')}[/dim]")
rprint(f" 适用场景:{data.get('purpose')}")
rprint(f" 描述:{data.get('description')}")
rprint(f" 风险等级:{'[red]' if data.get('level') == '严重' else '[yellow]'}{data.get('level')}[/{'red' if data.get('level') == '严重' else 'yellow'}]")
rprint(f" 创建时间:[dim]{data.get('createTime')}[/dim]")
+1
View File
@@ -24,6 +24,7 @@ COMMAND_TREE = {
"update": "修改 Agent 配置 → ekb agent update <id> --help",
"rules": "列出所有审核规则 → ekb agent rules --help",
"rule-get": "查看规则详情 → ekb agent rule-get <id或编码>",
"rule-create": "新建审核规则 → ekb agent rule-create --help",
"logs": "查看审核日志",
},
}