From 21d8832e441cc4e94c07396a4a8d9f321c496cb7 Mon Sep 17 00:00:00 2001 From: yunyingk Date: Wed, 8 Apr 2026 00:05:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aekb=20agent=20rule-c?= =?UTF-8?q?reate=20=E5=91=BD=E4=BB=A4=EF=BC=8C=E6=94=AF=E6=8C=81=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E5=AE=A1=E6=A0=B8=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ekb_cli/commands/agent/__init__.py | 2 ++ src/ekb_cli/commands/agent/rule_create.py | 38 +++++++++++++++++++++++ src/ekb_cli/commands/help.py | 1 + 3 files changed, 41 insertions(+) create mode 100644 src/ekb_cli/commands/agent/rule_create.py diff --git a/src/ekb_cli/commands/agent/__init__.py b/src/ekb_cli/commands/agent/__init__.py index 670e430..0302a8e 100644 --- a/src/ekb_cli/commands/agent/__init__.py +++ b/src/ekb_cli/commands/agent/__init__.py @@ -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) diff --git a/src/ekb_cli/commands/agent/rule_create.py b/src/ekb_cli/commands/agent/rule_create.py new file mode 100644 index 0000000..3b56df8 --- /dev/null +++ b/src/ekb_cli/commands/agent/rule_create.py @@ -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]") diff --git a/src/ekb_cli/commands/help.py b/src/ekb_cli/commands/help.py index eb043ce..cc7a586 100644 --- a/src/ekb_cli/commands/help.py +++ b/src/ekb_cli/commands/help.py @@ -24,6 +24,7 @@ COMMAND_TREE = { "update": "修改 Agent 配置 → ekb agent update --help", "rules": "列出所有审核规则 → ekb agent rules --help", "rule-get": "查看规则详情 → ekb agent rule-get ", + "rule-create": "新建审核规则 → ekb agent rule-create --help", "logs": "查看审核日志", }, }