From 468b13437a3e1cd6dce17274f553c9cc66902a74 Mon Sep 17 00:00:00 2001 From: yunyingk Date: Mon, 6 Apr 2026 01:04:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=88=AA=E6=96=AD?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=94=B9=E4=B8=BA=E6=98=BE=E7=A4=BA=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E6=96=87=E6=9C=AC=E6=80=BB=E5=AD=97=E7=AC=A6=E6=95=B0?= =?UTF-8?q?=EF=BC=8C--full=20=E4=BB=8D=E7=94=A8=E8=A1=A8=E6=A0=BC=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ekb_cli/commands/agent/detail.py | 53 ++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/src/ekb_cli/commands/agent/detail.py b/src/ekb_cli/commands/agent/detail.py index 00014e5..7585772 100644 --- a/src/ekb_cli/commands/agent/detail.py +++ b/src/ekb_cli/commands/agent/detail.py @@ -13,8 +13,18 @@ console = Console() STATE_MAP = {0: "[green]启用[/green]", 1: "[dim]未启用(未关联审批流)[/dim]"} MODE_MAP = {0: "全自动", 1: "半自动", 2: "辅助"} +DESC_MAX = 24 +PURPOSE_MAX = 16 -def cmd_detail(agent_id: str = typer.Argument(..., help="Agent ID")): + +def _truncated(text: str, max_width: int) -> bool: + return len(text) > max_width + + +def cmd_detail( + agent_id: str = typer.Argument(..., help="Agent ID"), + full: bool = typer.Option(False, "--full", "-f", help="显示完整内容,不截断规则字段"), +): """查看 Agent 详情""" with get_client() as client: resp = get_agent(client, agent_id) @@ -53,26 +63,39 @@ def cmd_detail(agent_id: str = typer.Argument(..., help="Agent ID")): rules = d.get("agentRule", []) if rules: table = Table(title="关联规则", show_lines=True) - table.add_column("规则描述", max_width=24, no_wrap=True) - table.add_column("规则编码", style="dim", no_wrap=True) - table.add_column("适用场景", max_width=16, no_wrap=True) - table.add_column("风险等级", no_wrap=True) - table.add_column("更新日期", style="dim", no_wrap=True) - table.add_column("ID", style="dim", no_wrap=True) + if full: + table.add_column("规则描述") + table.add_column("规则编码", style="dim", no_wrap=True) + table.add_column("适用场景") + table.add_column("风险等级", no_wrap=True) + table.add_column("更新日期", style="dim", no_wrap=True) + table.add_column("ID", style="dim", no_wrap=True) + else: + table.add_column("规则描述", max_width=DESC_MAX, no_wrap=True) + table.add_column("规则编码", style="dim", no_wrap=True) + table.add_column("适用场景", max_width=PURPOSE_MAX, no_wrap=True) + table.add_column("风险等级", 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 rules: 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", "") purpose = r.get("purpose", "") - table.add_row( - desc, - r.get("code", ""), - purpose, - level_str, - update_date, - r.get("id", ""), - ) + total_chars += len(desc) + len(purpose) + if not full and (_truncated(desc, DESC_MAX) or _truncated(purpose, PURPOSE_MAX)): + any_truncated = True + table.add_row(desc, r.get("code", ""), purpose, level_str, update_date, r.get("id", "")) + console.print(table) + + if any_truncated: + rprint(f"[yellow]⚠ 部分规则字段已截断,完整规则文本共 {total_chars} 字符[/yellow]") + rprint("[dim]使用 --full 参数获取完整内容:ekb agent get --full[/dim]") else: rprint("[dim](未关联任何规则)[/dim]") +