harness.mdc 5.2 KB

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