diff --git a/pipeline_service/agent_loop.py b/pipeline_service/agent_loop.py index a940b53..75f9dbe 100644 --- a/pipeline_service/agent_loop.py +++ b/pipeline_service/agent_loop.py @@ -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): """PM:clone 所有项目关联仓库到 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)才终止链。 diff --git a/pipeline_service/sdlc_ability.py b/pipeline_service/sdlc_ability.py index 13508c9..c33f4d5 100644 --- a/pipeline_service/sdlc_ability.py +++ b/pipeline_service/sdlc_ability.py @@ -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——这样模块可整体复用。 模块划分遵循: 概念相近的功能组合成一个独立模块,每个模块独立仓库。apppublic、sqlor、ahserver、accounting、appbase、rbac 等基础模块已存在、可直接引用,**不必列为待开发模块**。后续 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="",