Files
hose-use/src/ekb_cli/commands/agent/detail.py
T
gitea 8ae14842cc 修复:Agent state 枚举语义反了,0=草稿 1=已发布
list/detail 两处 STATE_MAP 均将 0/1 含义对调,同步更新 README.agent.md 枚举说明。
2026-04-08 14:48:28 +08:00

90 lines
3.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""ekb agent get <id>:查看 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, get_agent
console = Console()
STATE_MAP = {0: "[dim]草稿[/dim]", 1: "[green]已发布[/green]"}
MODE_MAP = {0: "全自动", 1: "半自动", 2: "辅助"}
DESC_MAX = 24
PURPOSE_MAX = 16
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:
d = get_agent(client, agent_id)
if not d:
rprint("[red]未找到该 Agent[/red]")
raise typer.Exit(1)
state = STATE_MAP.get(d.state, str(d.state))
mode = MODE_MAP.get(d.mode, str(d.mode))
if d.mode == 1:
mode += f"(抽检 {d.samplingRate}%)"
content = "\n".join([
f"[bold]ID[/bold] {d.id}",
f"[bold]名称[/bold] {d.name}",
f"[bold]状态[/bold] {state}",
f"[bold]模式[/bold] {mode}",
f"[bold]描述[/bold] {d.description or '(无)'}",
f"[bold]创建时间[/bold] {d.createTime}",
f"[bold]更新时间[/bold] {d.updateTime}",
"",
f"[bold cyan]明确同意[/bold cyan]\n{d.agreeTerms}",
"",
f"[bold red]明确驳回[/bold red]\n{d.rejectTerms}",
"",
f"[bold yellow]理应驳回,但可豁免(即备注同意)[/bold yellow]\n{d.exemptTerms}",
"",
f"[bold green]建议复核,转人工[/bold green]\n{d.reviewTerms}",
])
console.print(Panel(content, title=f"[bold]{d.name}[/bold]", expand=False))
if d.agentRule:
table = Table(title="关联规则", show_lines=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 d.agentRule:
level_str = f"[red]{r.level}[/red]" if r.level == "严重" else f"[yellow]{r.level}[/yellow]"
update_date = r.updateTime[:10]
total_chars += len(r.description) + len(r.purpose)
if not full and (len(r.description) > DESC_MAX or len(r.purpose) > PURPOSE_MAX):
any_truncated = True
table.add_row(r.description, r.code, r.purpose, level_str, update_date, r.id)
console.print(table)
if any_truncated:
rprint(f"[yellow]⚠ 部分规则字段已截断,完整规则文本共 {total_chars} 字符[/yellow]")
rprint("[dim]使用 --full 参数获取完整内容:ekb agent get <id> --full[/dim]")
else:
rprint("[dim](未关联任何规则)[/dim]")