Files
hose-use/CLAUDE.md
T

122 lines
3.8 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.
# ekb-cli 项目上下文(CLAUDE.md)
本文件是根目录总纲,面向 AI 智能体说明项目目标、分层规则和文档索引。
子域细节不要继续堆在这里,优先引用下级文档。
## 文件定位
- 面向业务人员的使用说明:见 [README.md](./README.md)
- 面向智能体的根规则:以本文件为准
- 面向通用 Agent 的入口别名:见 [Agent.md](./Agent.md)
- 具体子域细节:进入对应目录下的 `README*.md`
## 项目目标
为快报(ekuaibao)企业费控 SaaS 提供一套命令行工具和 HTTP API Server:
- CLI:给人直接用
- Server:给脚本、服务或 AI Agent 结构化调用
目标站点:
- `https://app.ekuaibao.com/web/app.html`
## 认证机制
快报主站使用三 Header 认证,不依赖 Cookie:
- `accesstoken`
- `corpid`
- `staffid`
认证信息保存在:
- `~/.config/ekb-cli/config.json`
SealAI 子域使用独立 Bearer JWT,详细流程不要写在这里,见:
- [src/ekb_cli/commands/sealai/README.sealai.md](./src/ekb_cli/commands/sealai/README.sealai.md)
- [src/ekb_cli/services/sealai/README.sealai.md](./src/ekb_cli/services/sealai/README.sealai.md)
- [src/ekb_cli/api/sealai/README.sealai.md](./src/ekb_cli/api/sealai/README.sealai.md)
## 架构总览
```text
调用方
├── commands/ CLI 表现层
├── server/ HTTP 表现层
└── services/ 业务逻辑层
└── api/ 传输层
```
核心原则:
- `commands/` 和 `server/` 都是薄壳,只做 IO 适配
- 业务编排统一放在 `services/`
- `api/` 只负责 HTTP 请求和模型校验
- `errors.py` 负责统一异常语义
- `config.py` 负责本地认证配置读写
## 文档索引
根目录只保留总纲和入口,具体内容下钻到对应层级:
- 命令层总说明:[src/ekb_cli/commands/README.commands.md](./src/ekb_cli/commands/README.commands.md)
- 业务层总说明:[src/ekb_cli/services/README.services.md](./src/ekb_cli/services/README.services.md)
- Server 总说明:[src/ekb_cli/server/README.server.md](./src/ekb_cli/server/README.server.md)
- API 总说明:[src/ekb_cli/api/README.api.md](./src/ekb_cli/api/README.api.md)
常用子域入口:
- Agent 说明:[src/ekb_cli/commands/agent/README.agent.md](./src/ekb_cli/commands/agent/README.agent.md)
- Rule 说明:[src/ekb_cli/commands/agent/README.rule.md](./src/ekb_cli/commands/agent/README.rule.md)
- SealAI 命令说明:[src/ekb_cli/commands/sealai/README.sealai.md](./src/ekb_cli/commands/sealai/README.sealai.md)
## 开发与修改规则
新增或调整功能时,优先遵循下面这条链路:
1. 先明确 `services/` 的业务边界
2. 再实现 `api/` 或复用现有传输层
3. 再接入 `commands/` 和 `server/`
4. 最后更新对应层级文档,而不是把细节补到根目录
同步更新顺序:
1. `services/`
2. `commands/` 或 `server/`
3. 对应目录下的 `README*.md`
4. 只有在总纲真的变化时,才更新本文件
## 分层导入约束
以下导入关系严格禁止:
| 禁止方向 | 说明 |
|---|---|
| `commands/* -> api/*` | CLI 表现层不得直接调用传输层 |
| `server/* -> api/*`(业务函数) | HTTP 路由不得直接调用 API 域函数 |
正确路径:
- `commands/* -> services/* -> api/*`
- `server/* -> services/* -> api/*`
例外:
- `server/deps.py` 可以作为基础设施层使用 `api.get_client`
## 异常规则
- `services/` 层只抛 `EkbError` 子类
- CLI 入口统一负责终端错误输出
- Server 入口统一负责 HTTP 状态码映射
- 路由和命令文件里不要重复做局部异常体系
## 文档规则
- 根目录文档只保留入口信息和引用关系
- 目录细节写进对应目录的 `README.{dirname}.md`
- 文件细节写进对应文件旁的说明文档
- 子域的 API 路径、枚举值、字段语义不要继续回填到根目录