From 6f5c93f3878f65f3b0c2978e77975c89bc2e999f Mon Sep 17 00:00:00 2001 From: yunyingk Date: Wed, 8 Apr 2026 00:45:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E6=8A=A5=EF=BC=9A2026-04-08=20?= =?UTF-8?q?=E5=86=99=E6=93=8D=E4=BD=9C=E5=91=BD=E4=BB=A4=E4=B8=8E=20API=20?= =?UTF-8?q?=E5=B1=82=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/daily/2026-04-08@c041966.md | 72 ++++++++++++++++++++++ src/ekb_cli/commands/agent/README.agent.md | 5 ++ src/ekb_cli/commands/agent/README.rule.md | 3 + 3 files changed, 80 insertions(+) create mode 100644 docs/daily/2026-04-08@c041966.md diff --git a/docs/daily/2026-04-08@c041966.md b/docs/daily/2026-04-08@c041966.md new file mode 100644 index 0000000..5267e44 --- /dev/null +++ b/docs/daily/2026-04-08@c041966.md @@ -0,0 +1,72 @@ +# 2026-04-08 开发日报 + +> 截止提交:`c041966`(日报本身所在提交) +> 下一个实例可用 `git log c041966` 查看全部历史,或 `git checkout c041966` 还原此状态。 + +## 今日目标 + +在昨日基础上扩展写操作命令,完善 API 层架构。 + +--- + +## 完成事项 + +### 一、新增写操作命令 + +**规则管理** + +| 命令 | 功能 | +|---|---| +| `ekb agent rule-create` | 新建审核规则(`--purpose` / `--desc` / `--level`) | + +**Agent 管理** + +| 命令 | 功能 | +|---|---| +| `ekb agent create` | 新建 Agent(支持全部字段,含关联规则 ID) | +| `ekb agent copy ` | 复制 Agent,名称自动追加「(副本)」,检测重名 | +| `ekb agent delete ` | 删除 Agent,方向键交互确认,不可恢复 | + +### 二、API 层重构 + +- **拆分文件**:`api/agent.py`(Agent 接口)+ `api/rule.py`(Rule 接口)+ `api/schemas.py`(Pydantic 模型) +- **统一 re-export**:所有 commands 只从 `ekb_cli.api` 导入,内部拆分对上层透明 +- **引入 Pydantic 校验**:所有接口响应经 `model_validate` 强制校验,字段变更时抛 `ValidationError` 精确定位,而非静默返回空值 +- 新增接口:`GET /engine/hab/agent/checkName`、`GET /engine/hab/agent/active` + +### 三、交互体验优化 + +- `ekb agent delete` 默认使用 `questionary` 方向键选择器,默认停在「取消」 +- 非 tty 环境(管道/AI调用)自动降级为 `y/N` 文字输入;`--ai` 参数可强制指定;`--yes` 跳过确认 +- 修复 `checkName` 接口语义反转 bug(`data=false` 表示名称可用) + +### 四、文档补全 + +- 新增 `api/README.api.md`:三层架构说明、各接口签名、Pydantic 应对策略 +- 补全 `README.agent.md`:`state` 枚举含义(0=启用 / 1=禁用 / 2=已删除)及对应接口 +- 补全 `README.rule.md`:`rule-create` 命令速查 + +--- + +## 新增接口 + +``` +GET /api/engine/hab/agent/checkName?name=xxx # 检查名称唯一性(data=false 表示可用) +GET /api/engine/hab/agent/active?id=xxx&state= # 变更 Agent 状态(0启用/1禁用/2删除) +``` + +--- + +## 设计决策 + +- **"删除"是状态变更**:快报无真正的 DELETE 接口,`state=2` 即为删除,通过 `/active` 接口实现。 +- **Pydantic `extra="allow"`**:允许快报新增字段,但已知字段强制类型,兼顾前向兼容与变更感知。 +- **`questionary` 仅在 tty 下启用**:`sys.stdin.isatty()` 自动检测,无需用户关心环境差异。 + +--- + +## 待办 + +- [ ] `ekb agent logs` — 需抓包确认 API 结构 +- [ ] `ekb agent rule update` — 修改规则内容(API 已封装,命令未实现) +- [ ] `ekb agent rule delete` — 删除规则(接口待确认) diff --git a/src/ekb_cli/commands/agent/README.agent.md b/src/ekb_cli/commands/agent/README.agent.md index 2d917e3..e7746de 100644 --- a/src/ekb_cli/commands/agent/README.agent.md +++ b/src/ekb_cli/commands/agent/README.agent.md @@ -35,6 +35,11 @@ ekb agent list # 列出所有 Agent ekb agent get # 查看 Agent 详情(含关联规则) ekb agent get --full # 不截断规则字段 +ekb agent create --name <名称> --help # 新建 Agent,查看全部参数 +ekb agent copy # 复制 Agent(名称自动加「副本」) ekb agent update --help # 查看可修改字段 ekb agent update --mode assist # 切换模式(auto/semi/assist) +ekb agent delete # 删除 Agent(方向键交互确认) +ekb agent delete --ai # 删除 Agent(y/N 文字确认,AI/脚本友好) +ekb agent delete --yes # 删除 Agent(跳过确认,危险) ``` diff --git a/src/ekb_cli/commands/agent/README.rule.md b/src/ekb_cli/commands/agent/README.rule.md index 404cedb..0e4b761 100644 --- a/src/ekb_cli/commands/agent/README.rule.md +++ b/src/ekb_cli/commands/agent/README.rule.md @@ -24,6 +24,9 @@ ekb agent rules --level 严重 # 筛选严重等级 ekb agent rule-get <编码或ID> # 查看规则详情(含关联 Agent 列表) # 编码支持多种写法:0001 / 01 / 1 / #0001(自动补零对齐) + +ekb agent rule-create --purpose <场景> --desc <描述> --level 严重 +# --level 默认严重,可选:严重 / 一般 ``` ## 已知 API