zentao-autofix
# zentao-autofix
把禅道(ZenTao)上指派给自己的缺陷,交给 AI 智能体自动修掉。
**它不替你改代码——它让任何智能体学会改。** 一个零依赖的 MCP 服务 + 一份 skill:
MCP 负责取缺陷、判断能不能修、给出仓库上下文、记账、汇总;智能体负责读代码、改代码。
分工明确,所以它在 Qoder CN、Claude Code、Cursor、DSH 里都能跑。
```
禅道缺陷 → 预筛(改数据的跳过) → 产品映射到仓库 → 智能体改代码 → 自动汇总
```
## 解决什么问题
缺陷列表里混着两类东西:
| 类型 | 例子 | 能不能自动修 |
| --- | --- | --- |
| **代码缺陷** | 「内部转让单中内部转让值默认不要填 0,应为空白必填校验就行」 | ✅ 能 |
| **代码缺陷** | 「报废申请显示的英文,应该是报废申请」 | ✅ 能(i18n 词条) |
| **数据问题** | 「生产-补充缺失数据-不动产租赁数据」 | ❌ 跳过 |
| **数据问题** | 「生产环境固定资产台账初始化导入数据有些数据没有创建时间和创建人」 | ❌ 跳过 |
第二类碰了就是生产事故。这个插件**在预筛阶段就把它们摘出去**,不交给模型判断——
因为让模型「自己决定要不要改数据库」是把风险交给了运气。
区别只有一条:**改完之后是代码变了,还是数据库里的记录变了。** 只有前者能做。
## 特性
- **产品 → 仓库字典**:禅道的「所属产品」列映射到本地代码仓库,支持包含匹配(「资产管理系统」能匹配「北辰集团资产管理」)。没配仓库的产品会被标出来,工具绝不猜路径。
- **两道跳闸**:改数据的缺陷在预筛阶段摘除;同一方向连续失败 2 次自动停,不在错的路上硬撞。
- **自动收尾**:没有可修的、或达到本轮上限(默认 10 条),自动停止并给出汇总报告——修了什么、怎么修的、哪些跳过了、为什么。
- **登录真验**:同时探测 REST API v1(`/api.php/v1/tokens`,新版本)和网页 Cookie(`/user-login.html`,老版本兜底),两个通道哪个通用哪个。
- **默认只读**:不写回禅道。写回需要显式打开,且会在缺陷下留 `【AI 自动修复】` 评论。
- **零依赖**:纯 Node ESM,无 npm 依赖,内网断网可用。配置跟着机器走(`~/.zentao-autofix`),插件装在任意目录都行。
## 安装
需要 Node ≥ 18。
```bash
git clone https://github.com/Fzl-Code-Repository/zentao-autofix.git
cd zentao-autofix
node scripts/install.mjs # 只检测本机装了哪些智能体
node scripts/install.mjs --apply # 写入 MCP 配置 + skill
```
支持的落点,自动探测:
| 智能体 | MCP 配置 | Skill |
| --- | --- | --- |
| Qoder CN | `~/.qoder-cn/settings.json`、`shared_client/mcp.json` | `~/.qoder-cn/skills` |
| Qoder | `~/.qoder/mcp.json` | `~/.qoder/skills` |
| Claude Code | `~/.claude.json` | `~/.claude/skills` |
| Cursor | `~/.cursor/mcp.json` | `~/.cursor/skills` |
| Windsurf | `~/.codeium/windsurf/mcp_config.json` | `~/.codeium/windsurf/skills` |
| Cline | VS Code globalStorage | — |
| DeepSeek Harness | profile 的 `cordis.patch.yml` | `~/.dsh/skills` |
写入前自动备份成 `*.bak-zentao-autofix`,`--remove` 卸载,`--targets qoder-cn,claude` 只装指定的。
装完重启智能体。任何 MCP 客户端也可以手动配:
```json
{
"mcpServers": {
"zentao-autofix": {
"command": "node",
"args": ["/absolute/path/to/zentao-autofix/bin/zentao-autofix.mjs"]
}
}
}
```
用绝对路径而不是 `npx`,是为了断网和内网也能起来。
## 用法
装好后不用记工具名,直接说人话:
> 把禅道指派给我的缺陷修一下
智能体会加载 skill,按流程走。也可以自己驱动:
```text
zentao_config {action:"set", baseUrl:"https://iip.sgai.com.cn/zentao", account:"me", password:"..."}
zentao_login # 验证登录
zentao_config {action:"add_repo", product:"资产管理系统", repoPath:"D:/work/asset-system", branch:"master"}
zentao_products # 看哪些产品还没配仓库
zentao_next → 改代码 → zentao_report → zentao_next → ...
```
### 没有密码也用得上:粘一个浏览器会话
有些禅道没开 REST API,或者你不想把密码交给工具。浏览器里已经登录过的话,
F12 → Application → Cookies → 复制 `zentaosid` 的值,顶掉密码那一格:
```text
zentao_config {action:"set", baseUrl:"https://…/zentao", sessionCookie:"<zentaosid 的值>"}
zentao_login
```
粘整行 `zentaosid=xxx; lang=zh-cn` 也行,`Path`、`HttpOnly` 这类属性会被丢掉。
会话过期了就把浏览器里新的值再粘一次。这个值只写本机 config.json,不回显(`action:"show"` 里打码)。
`zentao_next` 返回 `action:"fix"` 就干活,返回 `action:"stop"` 就停——它附带的 summary 就是最终报告。
回填的样子:
```json
{
"bugId": 10200,
"outcome": "fixed",
"rootCause": "前端初始化把 value 默认成 0",
"fix": "改为空字符串,提交时加必填校验",
"files": ["src/views/transfer/InternalTransfer.vue"],
"verify": "npm run test -- transfer 通过;手工验证默认空白、提交报必填"
}
```
## 九个工具
| 工具 | 作用 |
| --- | --- |
| `zentao_config` | 禅道地址/账号、产品→仓库字典、修复策略 |
| `zentao_login` | 验证登录(双通道探测) |
| `zentao_products` | 产品列表 + 哪些还没配仓库 |
| `zentao_bugs` | 「指派给我」的缺陷,逐条预判能否自动修 |
| `zentao_bug` | 单条完整信息 + 仓库快照 + 相关文件线索 |
| `zentao_next` | **核心循环**:取下一条该修的,或叫停 |
| `zentao_report` | 回填结果,拿下一步指示 |
| `zentao_run` | 轮次进度/汇总/历史/停止 |
| `zentao_doctor` | 环境自检:配置、凭证、仓库、git |
## 配置
`~/.zentao-autofix/config.json`(可用 `ZENTAO_AUTOFIX_HOME` 改位置):
```json
{
"zentao": {
"baseUrl": "https://iip.sgai.com.cn/zentao",
"account": "me",
"password": "***",
"sessionCookie": "",
"insecure": false,
"readonly": true
},
"repos": {
"资产管理系统": {
"path": "D:/work/asset-system",
"branch": "master",
"testCommand": "npm test"
}
},
"policy": {
"skipDataChanges": true,
"maxBugsPerRun": 10,
"allowedSeverity": [1, 2, 3, 4],
"stopAfterConsecutiveFailures": 2,
"writeBack": false
}
}
```
环境变量可覆盖连接信息:`ZENTAO_BASE_URL`、`ZENTAO_ACCOUNT`、`ZENTAO_PASSWORD`、`ZENTAO_SESSION_COOKIE`、`ZENTAO_INSECURE`。
密码/会话只留在本机文件里,不发给任何模型。`insecure: true` 给内网自签证书用。
## 禅道接口
优先走官方 REST API v1:`POST /api.php/v1/tokens` 换 token,之后带 `Token:` 头。
服务器没有 API v1 时退回网页通道:`/user-login.html` 拿 `zentaosid` cookie,读 `/my-work-bug.json`。
已经有会话 cookie(粘的或缓存的)时直接验一下就用,跳过后面的登录。
注意老版本禅道的 `.json` 端点会套一层壳:`{"status":"success","data":"<真正的 JSON 字符串>"}`,
本工具会自己扒开(最多剥 4 层),列表和详情都按这个处理。
登录凭证缓存 6 小时,过期自动重新登录。
## 自测
```bash
node scripts/selftest.mjs
```
内置一个假禅道服务器(真 HTTP,真 MCP JSON-RPC),覆盖 API 通道和网页通道两条路径。
测试数据里有真实的坑:改数据的缺陷必须被跳过、没配仓库的产品必须被标出、只读模式必须拒绝写回。
```
14/14 通过
```
## 边界
- **不做代码修改**:改代码是智能体的事。插件只保证「取对了、判对了、记全了」。
- **不猜仓库路径**:产品到仓库的映射必须用户提供。
- **不替你点「已解决」**:默认只读。生产环境通常需要人工复核。
- **不处理改数据的缺陷**:这类交给 DBA 或写数据订正脚本的人。
## 许可
MIT
TDQS
Scored across 9 tools
Most tools have clearly distinct roles: environment check (doctor), auth (login), config, product gap listing, and the core next→report loop. The only genuinely confusable pair is zentao_bugs (list with predictions) vs zentao_bug (single bug context pack), distinguished only by singular/plural. zentao_next also re-does some of zentao_bugs' filtering, and zentao_run overlaps slightly with zentao_report on 'summary/stop', but descriptions make the boundaries workable.
All tools share a consistent zentao_ snake_case prefix with single-word nouns, which is predictable. The deviation is that names are pure nouns plus an action parameter (zentao_run, zentao_config) rather than verb_noun, and the singular/plural pair zentao_bug/zentao_bugs is a real readability hazard. Still coherent overall, just not a strict verb_noun convention.
Nine tools is well within the ideal 3-15 range and each one maps to a distinct stage of the autofix lifecycle (auth, doctor, config, products, list, detail, next, report, run). Nothing feels redundant enough to cut, and nothing essential is obviously missing at this granularity.
The surface covers setup (config/login/doctor), discovery (products/bugs/bug), the fix loop (next/report), and session lifecycle (run with status/summary/stop/list/resume) — a full workflow arc. Gaps: there is no explicit tool to mark a bug resolved/closed in Zentao (report only hints at confirmation) and no batch/report-all operation, but agents can work around both within the stated loop.