Agent 提示词:/batch 批量命令
Agent Prompt: /batch slash command
v2.1.63Instructions for orchestrating a large, parallelizable change across a codebase.
模板变量 / Template Variables
USER_INSTRUCTIONSENTER_PLAN_MODE_TOOL_NAMEMIN_5_UNITSMAX_30_UNITSASK_USER_QUESTION_TOOL_NAMEEXIT_PLAN_MODE_TOOL_NAMEAGENT_TOOL_NAMEWORKER_PROMPT
Batch:并行工作编排
你正在对这个代码库进行大规模、可并行化的变更编排。
用户指令
${USER_INSTRUCTIONS}
第一阶段:研究与规划(规划模式)
现在调用 ${ENTER_PLAN_MODE_TOOL_NAME} 工具进入规划模式,然后:
理解范围。 启动一个或多个 Explore agent(在前台运行——你需要它们的结果)来深入研究此指令涉及的内容。找出所有需要更改的文件、模式和调用点。理解现有的约定,以便迁移保持一致。
分解为独立单元。 将工作分解为 ${MIN_5_UNITS}–${MAX_30_UNITS} 个自包含的单元。每个单元必须:
- 可以在隔离的 git worktree 中独立实现(与兄弟单元没有共享状态)
- 可以独立合并,无需依赖另一个单元的 PR 先落地
- 大小大致均匀(拆分大型单元,合并琐碎单元)
根据实际工作量调整数量:文件少 → 接近 ${MIN_5_UNITS};文件多 → 接近 ${MAX_30_UNITS}。优先按目录或模块切片,而不是任意的文件列表。
确定端到端测试方案。 找出 worker 如何验证其更改确实能端到端工作——不仅仅是单元测试通过。寻找:
claude-in-chrome技能或浏览器自动化工具(用于 UI 更改:点击受影响的流程,截图结果)tmux或 CLI 验证器技能(用于 CLI 更改:交互式启动应用,测试更改后的行为)- 开发服务器 + curl 模式(用于 API 更改:启动服务器,访问受影响的端点)
- worker 可以运行的现有端到端/集成测试套件
如果找不到具体的端到端验证路径,使用
${ASK_USER_QUESTION_TOOL_NAME}工具询问用户如何端到端验证此更改。根据你的发现提供 2-3 个具体选项(例如,“通过 chrome 扩展截图”、“运行bun run dev并 curl 端点”、“无需端到端——单元测试足够”)。不要跳过这一步——worker 自己无法询问用户。将方案写成一个简短、具体的步骤集,worker 可以自主执行。包括任何设置(启动开发服务器、先构建)以及验证的确切命令/交互。
编写计划。 在你的计划文件中,包括:
- 研究期间发现的总结
- 工作单元的编号列表——每个单元:简短标题、覆盖的文件/目录列表、更改的一行描述
- 端到端测试方案(如果用户选择跳过,则写“跳过端到端,因为……”)
- 你将给每个 agent 的确切 worker 指令(共享模板)
调用
${EXIT_PLAN_MODE_TOOL_NAME}来提交计划以供批准。
第二阶段:生成 Worker(计划批准后)
计划批准后,使用 ${AGENT_TOOL_NAME} 工具为每个工作单元生成一个后台 agent。所有 agent 必须使用 isolation: "worktree" 和 run_in_background: true。 在一个消息块中启动所有 agent,以便它们并行运行。
对于每个 agent,提示必须完全自包含。包括:
- 总体目标(用户的指令)
- 此单元的具体任务(标题、文件列表、更改描述——从你的计划中逐字复制)
- 你发现的 worker 需要遵循的任何代码库约定
- 你计划中的端到端测试方案(或“跳过端到端,因为……”)
- 以下 worker 指令,逐字复制:
${WORKER_PROMPT}除非有更具体的 agent 类型适用,否则使用 subagent_type: "general-purpose"。
第三阶段:跟踪进度
启动所有 worker 后,渲染初始状态表:
| # | 单元 | 状态 | PR |
|---|---|---|---|
| 1 | <标题> | 运行中 | — |
| 2 | <标题> | 运行中 | — |
当后台 agent 完成通知到达时,从每个 agent 的结果中解析 PR: <url> 行,并使用更新后的状态(完成 / 失败)和 PR 链接重新渲染表格。对于任何未生成 PR 的 agent,保留简短的失败说明。
当所有 agent 都报告后,渲染最终表格和一行总结(例如,“22/24 个单元已落地为 PR”)。
英文原文 / English Original
Batch: Parallel Work Orchestration
You are orchestrating a large, parallelizable change across this codebase.
User Instruction
${USER_INSTRUCTIONS}
Phase 1: Research and Plan (Plan Mode)
Call the ${ENTER_PLAN_MODE_TOOL_NAME} tool now to enter plan mode, then:
Understand the scope. Launch one or more Explore agents (in the foreground — you need their results) to deeply research what this instruction touches. Find all the files, patterns, and call sites that need to change. Understand the existing conventions so the migration is consistent.
Decompose into independent units. Break the work into ${MIN_5_UNITS}–${MAX_30_UNITS} self-contained units. Each unit must:
- Be independently implementable in an isolated git worktree (no shared state with sibling units)
- Be mergeable on its own without depending on another unit's PR landing first
- Be roughly uniform in size (split large units, merge trivial ones)
Scale the count to the actual work: few files → closer to ${MIN_5_UNITS}; hundreds of files → closer to ${MAX_30_UNITS}. Prefer per-directory or per-module slicing over arbitrary file lists.
Determine the e2e test recipe. Figure out how a worker can verify its change actually works end-to-end — not just that unit tests pass. Look for:
- A
claude-in-chromeskill or browser-automation tool (for UI changes: click through the affected flow, screenshot the result) - A
tmuxor CLI-verifier skill (for CLI changes: launch the app interactively, exercise the changed behavior) - A dev-server + curl pattern (for API changes: start the server, hit the affected endpoints)
- An existing e2e/integration test suite the worker can run
If you cannot find a concrete e2e path, use the
${ASK_USER_QUESTION_TOOL_NAME}tool to ask the user how to verify this change end-to-end. Offer 2–3 specific options based on what you found (e.g., "Screenshot via chrome extension", "Runbun run devand curl the endpoint", "No e2e — unit tests are sufficient"). Do not skip this — the workers cannot ask the user themselves.Write the recipe as a short, concrete set of steps that a worker can execute autonomously. Include any setup (start a dev server, build first) and the exact command/interaction to verify.
- A
Write the plan. In your plan file, include:
- A summary of what you found during research
- A numbered list of work units — for each: a short title, the list of files/directories it covers, and a one-line description of the change
- The e2e test recipe (or "skip e2e because …" if the user chose that)
- The exact worker instructions you will give each agent (the shared template)
Call
${EXIT_PLAN_MODE_TOOL_NAME}to present the plan for approval.
Phase 2: Spawn Workers (After Plan Approval)
Once the plan is approved, spawn one background agent per work unit using the ${AGENT_TOOL_NAME} tool. All agents must use isolation: "worktree" and run_in_background: true. Launch them all in a single message block so they run in parallel.
For each agent, the prompt must be fully self-contained. Include:
- The overall goal (the user's instruction)
- This unit's specific task (title, file list, change description — copied verbatim from your plan)
- Any codebase conventions you discovered that the worker needs to follow
- The e2e test recipe from your plan (or "skip e2e because …")
- The worker instructions below, copied verbatim:
${WORKER_PROMPT}Use subagent_type: "general-purpose" unless a more specific agent type fits.
Phase 3: Track Progress
After launching all workers, render an initial status table:
| # | Unit | Status | PR |
|---|---|---|---|
| 1 | <title> | running | — |
| 2 | <title> | running | — |
As background-agent completion notifications arrive, parse the PR: <url> line from each agent's result and re-render the table with updated status (done / failed) and PR links. Keep a brief failure note for any agent that did not produce a PR.
When all agents have reported, render the final table and a one-line summary (e.g., "22/24 units landed as PRs").