Files
hose-use/docs/daily/2026-04-08@c041966.md
T

73 lines
2.7 KiB
Markdown
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.
# 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 <id>` | 复制 Agent,名称自动追加「(副本)」,检测重名 |
| `ekb agent delete <id>` | 删除 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` — 删除规则(接口待确认)