harness.mdc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. ---
  2. description:
  3. alwaysApply: true
  4. enabled: true
  5. updatedAt: 2026-04-04T02:08:26.852Z
  6. provider:
  7. ---
  8. # 长时运行代理规则
  9. ## 核心原则
  10. 1. **双 Agent 架构**:Initializer Agent(仅首次)+ Coding Agent(后续所有会话)
  11. 2. **外部持久化**:所有进度必须写入文件,不依赖 AI 记忆
  12. 3. **增量开发**:每次会话只完成 1 个功能
  13. 4. **状态流转**:功能状态按流程逐步推进
  14. 5. **自动执行**:AI 必须自动执行所有命令,禁止让用户手动执行
  15. 6. **失败处理**:验证失败 → 修复 → 重新执行该环节
  16. ### 状态流转
  17. ```
  18. init → start → compiling → running → db-checking → backend-testing → frontend-testing → done
  19. ↑ ↑
  20. 【后端测试】 【前端测试⚠️】
  21. ```
  22. | 状态 | 含义 |
  23. |------|------|
  24. | `init` | 功能已创建,未开始 |
  25. | `start` | 开始开发 |
  26. | `compiling` | 编译中 |
  27. | `running` | 运行中 |
  28. | `db-checking` | 数据库验证中 |
  29. | `backend-testing` | 后端接口测试中(用 curl) |
  30. | `frontend-testing` | 前端页面测试中(用 Playwright)⚠️ |
  31. | `done` | 功能完成 |
  32. **⚠️ 注意**:必须测试前端页面,不能只用 curl 测试后端就结束
  33. ---
  34. ## Initializer Agent 规则
  35. ### 职责(仅第一次运行)
  36. 1. **生成 `init.sh`**:安装依赖、初始化数据库、启动服务
  37. 2. **生成 `agent-progress.txt`**:进度日志
  38. 3. **生成 `feature_list.json`**:细粒度功能清单(JSON 格式)
  39. 4. **初始化 Git**:创建仓库并提交
  40. 5. **自动执行初始化**:启动服务并验证
  41. ### 禁止行为
  42. - ❌ 编写功能代码
  43. - ❌ 跳过任何工件生成
  44. - ❌ 使用占位符
  45. - ❌ 输出命令让用户手动执行
  46. ---
  47. ## Coding Agent 规则
  48. ### 标准流程(按顺序执行)
  49. #### 步骤 1:读取状态
  50. ```bash
  51. pwd
  52. cat agent-progress.txt
  53. cat feature_list.json
  54. git log --oneline -20
  55. ```
  56. #### 步骤 2:选择功能
  57. - 从 `feature_list.json` 选择最小 id 的未完成功能
  58. - **只做这一条**
  59. #### 步骤 3:更新状态为 `start`
  60. ```bash
  61. # 修改 feature_list.json: status: "start"
  62. # 记录日志
  63. ```
  64. #### 步骤 4:开发功能
  65. - 编写代码
  66. #### 步骤 5:编译验证(状态 → compiling)
  67. ```bash
  68. # 根据项目类型执行编译
  69. python -m py_compile backend/*.py # Python
  70. npm run build # Node.js/TS
  71. mvn compile # Java
  72. ```
  73. - 成功 → 更新状态为 `running`
  74. - 失败 → 修复 → 重新编译
  75. #### 步骤 6:运行验证(状态 → running)
  76. ```bash
  77. # 重启服务
  78. ./init.sh
  79. sleep 10
  80. # 验证服务可用
  81. curl -f http://localhost:{backend_port}/health
  82. curl -f http://localhost:{frontend_port}
  83. ```
  84. - 成功 → 更新状态为 `db-checking`
  85. - 失败 → 修复 → 重新运行
  86. #### 步骤 7:数据库验证(状态 → db-checking)
  87. ```bash
  88. python backend/db_check.py
  89. ```
  90. - 成功 → 更新状态为 `backend-testing`
  91. - 失败 → 修复 → 重新验证
  92. #### 步骤 8:后端接口测试(状态 → backend-testing)
  93. ```bash
  94. # 按照 backend_test_steps 逐项测试
  95. # 必须包含增删改查(CRUD)
  96. ```
  97. - 成功 → 更新状态为 `frontend-testing`
  98. - 失败 → 修复 → 重新测试
  99. **后端测试要求**:
  100. - 必须包含增删改查(Create/Read/Update/Delete)
  101. - 使用 curl 测试 API 接口
  102. - 开发阶段 `auth_enabled: false`,跳过 token 验证
  103. #### ⚠️ 步骤 9:前端页面测试(状态 → frontend-testing)⚠️
  104. **【必须测试前端,禁止跳过此步骤】**
  105. ```bash
  106. # 使用 Playwright 进行浏览器自动化测试
  107. npx playwright test
  108. ```
  109. - 成功 → 更新状态为 `done`
  110. - 失败 → 修复 → 重新测试
  111. **前端测试要求**:
  112. - 必须使用 Playwright 或 Playwright cli
  113. - ❌ 禁止使用 curl 测试前端(curl 只能测后端)
  114. #### 步骤 10:功能完成(状态 → done)
  115. ```bash
  116. # 修改 feature_list.json: status: "done", passes: true
  117. # 更新日志
  118. # Git 提交
  119. ```
  120. ### 禁止行为
  121. - ❌ 每次做多个功能
  122. - ❌ 跳过状态直接 done
  123. - ❌ 不编译就测试
  124. - ❌ 不运行就测试
  125. - ❌ 不验证数据库连接
  126. - ❌ **忘记测试前端**(只测后端,不测前端)
  127. - ❌ **用 curl 测试前端页面**(禁止 curl 测试前端)
  128. - ❌ 删除/修改 backend_test_steps
  129. - ❌ 删除/修改 frontend_test_steps
  130. - ❌ backend_test_steps 不包含增删改查
  131. - ❌ 输出命令让用户手动执行
  132. ---
  133. ## 工件规范
  134. ### feature_list.json
  135. ```json
  136. {
  137. "project_name": "项目名称",
  138. "base_config": {
  139. "backend_port": "{根据实际项目配置}",
  140. "frontend_port": "{根据实际项目配置}",
  141. "db_host": "localhost",
  142. "db_port": 3306,
  143. "auth_enabled": false
  144. },
  145. "features": [
  146. {
  147. "id": 1,
  148. "description": "功能描述",
  149. "backend_test_steps": [
  150. "1. curl POST /api/chats - 验证创建(增)",
  151. "2. curl GET /api/chats - 验证查询(查)",
  152. "3. curl PUT /api/chats/{id} - 验证更新(改)",
  153. "4. curl DELETE /api/chats/{id} - 验证删除(删)"
  154. ],
  155. "frontend_test_steps": [
  156. "1. 点击按钮",
  157. "2. 验证结果"
  158. ],
  159. "status": "init",
  160. "passes": false
  161. }
  162. ]
  163. }
  164. ```
  165. ### agent-progress.txt
  166. - 格式:纯文本
  167. - 要求:每次会话追加记录,保留所有历史
  168. ### init.sh
  169. - 格式:Bash 脚本
  170. - 要求:一键启动项目、安装依赖、启动服务、运行测试
  171. ### Git
  172. - 提交频率:每次功能完成后
  173. ---
  174. ## 权限验证配置
  175. - `auth_enabled: false`:开发阶段,跳过登录验证 token
  176. - `auth_enabled: true`:生产阶段,开启登录验证 token
  177. **建议**:开发阶段关闭 `auth_enabled`,等核心功能完成后再开启