新增:ekb agent rules 命令,列出企业所有审核规则
- api/agent.py 增加 list_rules / save_rule / update_rule 封装 - 新增 commands/agent/rule_list.py,支持 --full 展开截断字段 - 注册 rules 子命令,更新命令树和 CLAUDE.md API 路径
This commit is contained in:
1 parent
468b13437a
commit
fd41415d83
5 files changed
+95
-5
No files matched your search
@@ -34,11 +34,12 @@ src/ekb_cli/
|
||||
|
||||
## 已知 API 路径
|
||||
```
|
||||
GET/POST /api/engine/hab/agent/list
|
||||
GET/POST /api/engine/hab/agent/detail
|
||||
POST /api/engine/hab/agent/save
|
||||
GET /api/engine/hab/agent/rule/list
|
||||
POST /api/engine/hab/agent/rule/save
|
||||
GET /api/engine/hab/agent/list
|
||||
GET /api/engine/hab/agent/detail
|
||||
POST /api/engine/hab/agent/save
|
||||
GET /api/engine/hab/agent/rule/list
|
||||
POST /api/engine/hab/agent/rule/save
|
||||
POST /api/engine/hab/agent/rule/update
|
||||
```
|
||||
|
||||
> 详细请求/响应结构参考 api/agent.py 和 Chrome DevTools 网络请求记录。
|
||||
|
||||
@@ -13,3 +13,17 @@ def get_agent(client: EkbClient, agent_id: str) -> dict:
|
||||
|
||||
def save_agent(client: EkbClient, payload: dict) -> dict:
|
||||
return client.post("/engine/hab/agent/save", payload)
|
||||
|
||||
|
||||
def list_rules(client: EkbClient, page: int = 1, size: int = 1000) -> dict:
|
||||
return client.get("/engine/hab/agent/rule/list", page=page, size=size)
|
||||
|
||||
|
||||
def save_rule(client: EkbClient, payload: dict) -> dict:
|
||||
"""新建规则:payload 包含 purpose / description / level"""
|
||||
return client.post("/engine/hab/agent/rule/save", payload)
|
||||
|
||||
|
||||
def update_rule(client: EkbClient, payload: dict) -> dict:
|
||||
"""更新规则:payload 包含 id / code / purpose / description / level"""
|
||||
return client.post("/engine/hab/agent/rule/update", payload)
|
||||
@@ -5,6 +5,7 @@ from ekb_cli.commands.agent.list import cmd_list
|
||||
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
|
||||
|
||||
app = typer.Typer(help="智能审核 Agent 管理")
|
||||
|
||||
@@ -12,3 +13,4 @@ app.command("list")(cmd_list)
|
||||
app.command("get")(cmd_detail)
|
||||
app.command("update")(cmd_update)
|
||||
app.command("logs")(cmd_logs)
|
||||
app.command("rules")(cmd_rule_list)
|
||||
@@ -0,0 +1,72 @@
|
||||
"""ekb agent rules:列出企业所有审核规则"""
|
||||
|
||||
import typer
|
||||
from rich.console import Console
|
||||
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()
|
||||
|
||||
DESC_MAX = 20
|
||||
PURPOSE_MAX = 12
|
||||
|
||||
|
||||
def cmd_rule_list(
|
||||
full: bool = typer.Option(False, "--full", "-f", help="显示完整内容,不截断描述字段"),
|
||||
):
|
||||
"""列出企业所有审核规则"""
|
||||
with get_client() as client:
|
||||
resp = list_rules(client)
|
||||
|
||||
data = resp.get("data", {})
|
||||
items = data.get("items", [])
|
||||
total = data.get("totalItems", 0)
|
||||
|
||||
if not items:
|
||||
rprint("[dim](暂无规则)[/dim]")
|
||||
return
|
||||
|
||||
table = Table(title=f"审核规则(共 {total} 条)", show_lines=True)
|
||||
table.add_column("规则编码", style="dim", no_wrap=True)
|
||||
if full:
|
||||
table.add_column("规则描述")
|
||||
table.add_column("适用场景")
|
||||
else:
|
||||
table.add_column("规则描述", max_width=DESC_MAX, no_wrap=True)
|
||||
table.add_column("适用场景", max_width=PURPOSE_MAX, no_wrap=True)
|
||||
table.add_column("风险等级", no_wrap=True)
|
||||
table.add_column("关联Agent", no_wrap=True)
|
||||
table.add_column("更新日期", style="dim", no_wrap=True)
|
||||
table.add_column("ID", style="dim", no_wrap=True)
|
||||
|
||||
any_truncated = False
|
||||
total_chars = 0
|
||||
for r in items:
|
||||
level = r.get("level", "")
|
||||
level_str = f"[red]{level}[/red]" if level == "严重" else f"[yellow]{level}[/yellow]"
|
||||
update_date = (r.get("updateTime", "") or "")[:10]
|
||||
desc = r.get("description", "") or ""
|
||||
purpose = r.get("purpose", "") or ""
|
||||
total_chars += len(desc) + len(purpose)
|
||||
if not full and (len(desc) > DESC_MAX or len(purpose) > PURPOSE_MAX):
|
||||
any_truncated = True
|
||||
agents = r.get("agents", [])
|
||||
agent_str = str(len(agents)) if agents else "0"
|
||||
table.add_row(
|
||||
r.get("code", ""),
|
||||
desc,
|
||||
purpose,
|
||||
level_str,
|
||||
agent_str,
|
||||
update_date,
|
||||
r.get("id", ""),
|
||||
)
|
||||
|
||||
console.print(table)
|
||||
|
||||
if any_truncated:
|
||||
rprint(f"[yellow]⚠ 部分字段已截断,完整规则文本共 {total_chars} 字符[/yellow]")
|
||||
rprint("[dim]使用 --full 参数获取完整内容:ekb agent rules --full[/dim]")
|
||||
@@ -22,6 +22,7 @@ COMMAND_TREE = {
|
||||
"list": "列出所有 Agent",
|
||||
"get": "查看 Agent 详情 → ekb agent get <id> --help",
|
||||
"update": "修改 Agent 配置 → ekb agent update <id> --help",
|
||||
"rules": "列出所有审核规则 → ekb agent rules --help",
|
||||
"logs": "查看审核日志",
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user