feat: git 提交改为审核通过后统一提交——role agent 不再每次产出提交(移除 auto-commit + 角色提示词 git_commit_push),PM approve 后统一 commit 项目过程仓库+应用/模块仓库,减少并发锁与远端 push 频率

This commit is contained in:
ymq 2026-08-20 21:45:07 +08:00
parent 8bc1b4e571
commit 38e47be4db
2 changed files with 39 additions and 30 deletions

View File

@ -346,9 +346,9 @@ AGENT_TOOLS = [
{"name":"run_shell","description":"在工作空间中执行shell命令","params":{"command":"命令"}},
{"name":"git_clone","description":"克隆git仓库到工作空间repos/下","params":{"repo_url":"仓库URL","repo_name":"仓库目录名(可选,默认从URL推断)","branch":"分支(可选,默认main)"}},
{"name":"git_status","description":"查看git仓库状态","params":{"repo_dir":"仓库子目录(可选,默认repos下第一个)"}},
{"name":"git_commit_push","description":"git add + commit + push","params":{"message":"提交信息","repo_dir":"仓库子目录(可选)"}},
{"name":"git_commit_push","description":"git add + commit + push一般无需调用git 提交由 PM 审核通过后系统统一执行)","params":{"message":"提交信息","repo_dir":"仓库子目录(可选)"}},
{"name":"ask_question","description":"向用户提问(缺少信息时使用)","params":{"question":"问题"}},
{"name":"deliver","description":"提交最终交付件(代码文件已用write_file写好、git已提交时调用)","params":{"deliverable_type":"交付件类型(如code_files/design_doc)","summary":"概述","result":"交付件正文","files":"JSON数组[{\"path\":\"repos/仓库/src/x.py\",\"content\":\"代码内容\"}](可选)","git_commit_message":"git提交信息(可选)"}},
{"name":"deliver","description":"提交最终交付件(代码/文档文件已用write_file写好时调用","params":{"deliverable_type":"交付件类型(如code_files/design_doc)","summary":"概述","result":"交付件正文","files":"JSON数组[{\"path\":\"repos/仓库/src/x.py\",\"content\":\"代码内容\"}](可选)"}},
]
AGENT_SYSTEM_PROMPT = """你是软件开发产线中的「__ROLE__」角色Agent。
@ -371,15 +371,14 @@ __TOOLS__
1. 先用 read_file/list_files 了解现有代码
2. write_file 产出代码文件到 repos/
3. run_shell 验证编译/测试
4. git_commit_push 提交到远端
5. deliver 提交最终交付件
4. deliver 提交最终交付件git 提交由 PM 审核通过后系统统一执行无需你提交
## 输出格式每次只输出一个JSON对象
调工具
{"action":"tool_call","tool":"工具名","params":{}}
提交交付件
{"action":"deliver","deliverable_type":"code_files","summary":"概述","result":"文档内容","files":[{"path":"repos/仓库/src/file.py","content":"代码"}],"git_commit_message":"feat: 描述"}
{"action":"deliver","deliverable_type":"code_files","summary":"概述","result":"文档内容","files":[{"path":"repos/仓库/src/file.py","content":"代码"}]}
提问
{"action":"ask","question":"问题"}
@ -397,7 +396,7 @@ PM_SYSTEM_PROMPT = """你是项目经理PM。你的职责是项目计划
## 三大职责
1. 项目计划基于需求/设计交付件规划后续工作先评估任务复杂度复杂任务自动分解为可执行的子任务
2. 任务分配 create_tasks 工具把子任务派发给对应角色 agent并记录父子关系与依赖关系能并行的并行不能并行的串行
3. 任务验收检查交付件 + git 实际产出决定 review_approve / review_reject / review_complete
3. 任务验收检查交付件 + 实际产出文件决定 review_approve / review_reject / review_complete
## 任务分解与编排(先评估,再拆解)
- 派发前先评估当前任务是否过于复杂涉及多个模块/应用多个独立交付单元工作量超单 agent 一次产出简单任务直接派发单个任务不必强行拆分
@ -454,7 +453,7 @@ __REPO_STATE__
审核标准
- requirement需求是否清晰完整可量化含部署环境需求是否明确
- design方案合理覆盖需求技术可行
- develop必须用 git_status/read_file 检查代码是否实际写入仓库
- develop必须用 list_files/read_file 检查代码文件是否实际产出git 提交由审核通过后系统统一执行
- deploy_test测试环境部署配置完整服务可访问
- test测试覆盖充分发现问题记录完整
- deploy_prod生产部署配置完整可一键部署有回滚方案
@ -468,7 +467,7 @@ QC_SYSTEM_PROMPT = """你是质量控制工程师QC。对交付件做合
## 检查维度
1. 项目规范检查产出是否按 SDLC 仓库标准路径/命名/格式产出docs/ 目录结构apps/modules 描述文件文件命名规范
2. 项目过程规范是否遵循各阶段流程规范develop 是否实际 git 提交test 是否覆盖充分deploy 配置是否完整requirement 是否明确部署环境需求
2. 项目过程规范是否遵循各阶段流程规范develop 是否实际产出代码文件test 是否覆盖充分deploy 配置是否完整requirement 是否明确部署环境需求
3. 产出质量内容是否完整可量化可验收无重大缺陷无空泛套话
## 待检查
@ -489,7 +488,7 @@ QC_SYSTEM_PROMPT = """你是质量控制工程师QC。对交付件做合
## 检查流程
1. 读交付件内容检查是否按 SDLC 规范产出路径/命名/格式
2. 检查过程合规git 提交目录结构必填项
2. 检查过程合规文件实际产出目录结构必填项
3. 判断产出质量是否达标完整可量化可验收
4. 合规则 review_approve不合规则 review_reject 并逐条列出问题清单"""
@ -637,6 +636,22 @@ async def _ensure_project_repo(workspace_dir):
return {'rc': r2['rc'], 'message': f"init 项目过程仓库 {'成功' if r2['rc'] == 0 else '失败'}"}
async def _commit_repos_after_approve(workspace_dir, title=''):
"""审核通过后统一提交:项目过程仓库 repos/project/(阶段/QC/PM 文档)+ repos/ 下应用/模块仓库(代码)。
不在 agent 每次产出时提交减少 git 并发锁与远端 push 频率"""
msg = f"approve: {title[:80]}" if title else "approve: 审核通过"
repos_dir = os.path.join(workspace_dir, 'repos')
results = []
if os.path.isdir(repos_dir):
for name in sorted(os.listdir(repos_dir)):
rp = os.path.join(repos_dir, name)
if os.path.isdir(os.path.join(rp, '.git')):
r = await _git_commit_push(rp, msg)
results.append(f"{name}: {r.get('message', '')}")
logger.info(f"commit-after-approve {name}: rc={r.get('rc', -1)} {r.get('message', '')[:100]}")
return {"rc": 0, "message": "; ".join(results) if results else "无仓库可提交"}
async def _setup_repos(sor, workspace_dir, project_id):
"""PMclone 所有项目关联仓库到 workspace/repos/。"""
# 先确保项目过程仓库存在(阶段文档/QC审计/PM文档放这里
@ -1208,16 +1223,8 @@ async def role_agent_run(project_id, role, agent_id=None, model_name=None):
"created_by": agent_id or role,
})
# Git commit + push遍历 repos/ 下所有仓库,不依赖 files_written——agent 可能直接用 write_file 写代码而不走 deliver.files
commit_msg = deliverable.get("git_commit_message") or f"{role}: {title[:80]}"
git_results = []
for repo_name in sorted(os.listdir(repos_dir)):
repo_path = os.path.join(repos_dir, repo_name)
if os.path.isdir(os.path.join(repo_path, '.git')):
r = await _git_commit_push(repo_path, commit_msg)
git_results.append(f"{repo_name}: {r.get('message', '')}")
logger.info(f"git_commit_push {repo_name}: rc={r.get('rc', -1)} {r.get('message', '')[:100]}")
git_result = {"rc": 0, "message": "; ".join(git_results) if git_results else "无仓库可提交"}
# Git 提交时机:不在 agent 每次产出时提交,改为 PM 审核通过后统一提交(减少并发锁、避免每次生成都 push 远端)
git_result = {"rc": 0, "message": "延迟提交:审核通过后统一 git 提交"}
from .task_capability import submit_task
ok, _ = await submit_task(task_id, project_id, who=role, agent_id=agent_id)
@ -1567,6 +1574,9 @@ async def pm_review_run(project_id, agent_id=None, model_name=None):
{"a": "角色已响应PM审核通过", "role": task_role or "role_agent", "tid": task_id})
from .task_capability import approve_task
await approve_task(task_id, project_id, who="agent.pm", agent_id=agent_id, comment=comment)
# 审核通过后统一 git 提交(项目过程仓库 + 应用/模块仓库),不在每次生成时提交以减少并发锁
_git_after = await _commit_repos_after_approve(workspace_dir, title)
logger.info(f"commit-after-approve: task={task_id} {_git_after.get('message', '')}")
next_role = await _get_next_role(task_role, project_id)
if next_role:
# 迭代边界仅当任务归属的迭代已显式结束completed/cancelled才终止链。

View File

@ -254,7 +254,7 @@ SDL_ROLES = [
- 测试环境: 资源规格(CPU/内存/磁盘)依赖服务(DB/缓存/中间件)端口环境变量
- 生产环境: 资源规格高可用要求备份策略域名/证书监控告警
- 若需求未明确部署环境信息在需求文档中标注待明确并列出需向用户确认的问题清单
完成后用 git_commit_push 提交到项目过程仓库 repos/project/再用 result 输出文档files 列出文件路径""",
完成后用 result 输出文档files 列出文件路径git 提交由 PM 审核通过后系统统一执行无需你提交""",
next_role="agent.design",
),
RoleSpec(
@ -274,7 +274,7 @@ SDL_ROLES = [
数据CRUD处理逻辑skills 都属于模块本身不放在应用级 design这样模块可整体复用
模块划分遵循: 概念相近的功能组合成一个独立模块每个模块独立仓库apppublicsqlorahserveraccountingappbaserbac 等基础模块已存在可直接引用**不必列为待开发模块**后续 PM 按你划分好的模块 + 依赖关系派发 develop 任务
完成后用 git_commit_push 提交到项目过程仓库 repos/project/再用 result 输出文档files 列出文件路径""",
完成后用 result 输出文档files 列出文件路径git 提交由 PM 审核通过后系统统一执行无需你提交""",
next_role="agent.develop",
),
RoleSpec(
@ -292,11 +292,10 @@ SDL_ROLES = [
开发流程:
4. write_file 写代码到模块仓库目录
5. run_shell 编译/运行验证
6. git_commit_push 提交模块仓库 "develop: <简述>"
7. write_file 更新 repos/project/modules/<模块名>.md 状态为已完成
8. write_file repos/project/docs/02-develop/dev-notes.md 记录开发内容 git_commit_push 提交项目过程仓库
9. deliver 交付files 列出所有产出文件路径
PM审核: git_status 检查模块仓库有提交记录""",
6. write_file 更新 repos/project/modules/<模块名>.md 状态为已完成
7. write_file repos/project/docs/02-develop/dev-notes.md 记录开发内容
8. deliver 交付files 列出所有产出文件路径git 提交由 PM 审核通过后系统统一执行
PM审核: list_files/read_file 检查代码文件实际产出""",
next_role="agent.deploy_test",
),
RoleSpec(
@ -312,7 +311,7 @@ PM审核: git_status 检查模块仓库有提交记录。""",
1. read_file repos/project/docs/00-requirement/ 的部署环境需求 + repos/project/docs/01-design/ 的设计
2. 准备测试环境部署配置容器/依赖服务/端口/环境变量
3. 部署到测试环境run_shell 验证服务可访问
4. 产出部署文档git_commit_push 提交项目过程仓库deliver 交付files 列出配置文件路径
4. 产出部署文档deliver 交付files 列出配置文件路径git 提交由 PM 审核通过后系统统一执行
PM审核: 检查测试环境部署配置完整服务可访问""",
next_role="agent.test",
),
@ -326,7 +325,7 @@ PM审核: 检查测试环境部署配置完整、服务可访问。""",
- test-plan.md: 测试策略(单元/集成/端到端)
- test-cases.md: 用例清单(编号/前置条件/步骤/预期结果)
- test-report.md: 执行结果Bug清单覆盖率
完成后用 git_commit_push 提交到项目过程仓库 repos/project/""",
完成后用 result 输出测试结果files 列出文件路径git 提交由 PM 审核通过后系统统一执行""",
next_role="agent.deploy_prod",
),
RoleSpec(
@ -343,7 +342,7 @@ PM审核: 检查测试环境部署配置完整、服务可访问。""",
1. 确认测试验证通过read_file repos/project/docs/03-test/test-report.md
2. 准备生产配置高可用备份监控告警域名证书
3. 部署到生产环境验证服务可用
4. 产出部署文档 + 发布说明git_commit_push 提交项目过程仓库deliver 交付files 列出配置文件
4. 产出部署文档 + 发布说明deliver 交付files 列出配置文件git 提交由 PM 审核通过后系统统一执行
PM审核: 检查生产部署配置完整可一键部署有回滚方案""",
next_role="",
),
@ -355,7 +354,7 @@ PM审核: 检查生产部署配置完整、可一键部署、有回滚方案。"
检查维度:
1. 项目规范检查: 产出是否按 SDLC 仓库标准路径/命名/格式产出
2. 项目过程规范: 是否遵循各阶段流程规范develop 是否实际 git 提交test 是否覆盖充分deploy 配置是否完整
2. 项目过程规范: 是否遵循各阶段流程规范develop 是否实际产出代码文件test 是否覆盖充分deploy 配置是否完整
3. 产出质量: 内容是否完整可量化可验收无重大缺陷
不合规处理: review_reject 退回重做questions 列出具体问题清单""",
next_role="",