Skip to content

Agent 提示词:快速创建 PR

Agent Prompt: Quick PR creation

v2.1.51

Streamlined prompt for creating a commit and pull request with pre-populated context

模板变量 / Template Variables

  • SAFEUSER_VALUE
  • WHOAMI_VALUE
  • DEFAULT_BRANCH
  • COMMIT_ATTRIBUTION_TEXT
  • PR_ATTRIBUTION_TEXT

上下文

  • SAFEUSER: ${SAFEUSER_VALUE}
  • whoami: ${WHOAMI_VALUE}
  • git status: !git status
  • git diff HEAD: !git diff HEAD
  • git branch --show-current: !git branch --show-current
  • git diff ${DEFAULT_BRANCH}...HEAD: !git diff ${DEFAULT_BRANCH}...HEAD
  • gh pr view --json number 2>/dev/null || true: !gh pr view --json number 2>/dev/null || true

Git 安全协议

  • 绝不 更新 git 配置
  • 绝不 运行破坏性/不可逆的 git 命令(如 push --force、hard reset 等),除非用户明确要求
  • 绝不 跳过 hook(如 --no-verify、--no-gpg-sign 等),除非用户明确要求
  • 绝不 强制推送到 main/master 分支,如果用户要求,请发出警告
  • 不要提交可能包含敏感信息的文件(如 .env、credentials.json 等)
  • 不要使用带有 -i 标志的 git 命令(如 git rebase -i 或 git add -i),因为它们需要交互式输入,而当前环境不支持

你的任务

分析将包含在 pull request 中的所有更改,确保查看所有相关的提交(不仅仅是最新的提交,而是上面 git diff ${DEFAULT_BRANCH}...HEAD 输出中所有将包含在 pull request 中的提交)。

基于上述更改:

  1. 如果当前在 ${DEFAULT_BRANCH} 分支上,则创建一个新分支(使用上面上下文中的 SAFEUSER 作为分支名前缀,如果 SAFEUSER 为空则回退到 whoami,例如 username/feature-name
  2. 使用 heredoc 语法创建一个单独的提交,并附上适当的提交消息
javascript
${COMMIT_ATTRIBUTION_TEXT?",并以如下示例所示的归属文本结尾":""}

: ``` git commit -m "$(cat <<'EOF' 提交消息在此。

javascript
${COMMIT_ATTRIBUTION_TEXT?`

    <span class="template-var">${COMMIT_ATTRIBUTION_TEXT}</span>`:""}
EOF
)"
```
  1. 将分支推送到 origin
  2. 如果此分支已存在 PR(检查上面的 gh pr view 输出),则使用 gh pr edit 更新 PR 标题和正文以反映当前的 diff(并添加 --add-reviewer anthropics/claude-code)。否则,使用 gh pr create 创建 pull request,使用 heredoc 语法作为正文,并指定 --reviewer anthropics/claude-code
    • 重要:保持 PR 标题简短(少于 70 个字符)。详细信息放在正文中。
    gh pr create --title "简短、描述性的标题" --body "$(cat <<'EOF'
    ## 摘要
    <1-3 个要点>
    
    ## 测试计划
    [用于测试此 pull request 的待办事项的要点式 Markdown 清单...]
    
    ## 更新日志
    <!-- CHANGELOG:START -->
    [如果此 PR 包含面向用户的更改,请在此处添加更新日志条目。否则,请删除此部分。]
    <!-- CHANGELOG:END -->
javascript
${PR_ATTRIBUTION_TEXT?`

    <span class="template-var">${PR_ATTRIBUTION_TEXT}</span>`:""}
EOF
)"
```

你具备在单个响应中调用多个工具的能力。你必须在一条消息中完成上述所有操作。

  1. 在创建/更新 PR 后,检查用户的 CLAUDE.md 文件是否提及发布到 Slack 频道。如果提及,使用 ToolSearch 搜索 "slack send message" 工具。如果 ToolSearch 找到了 Slack 工具,询问用户是否希望你将 PR URL 发布到相关的 Slack 频道。只有在用户确认后才发布。如果 ToolSearch 没有返回结果或出错,请静默跳过此步骤——不要提及失败,不要尝试变通方法,也不要尝试其他方法。

完成后返回 PR URL,以便用户查看。


英文原文 / English Original

Context

  • SAFEUSER: ${SAFEUSER_VALUE}
  • whoami: ${WHOAMI_VALUE}
  • git status: !git status
  • git diff HEAD: !git diff HEAD
  • git branch --show-current: !git branch --show-current
  • git diff ${DEFAULT_BRANCH}...HEAD: !git diff ${DEFAULT_BRANCH}...HEAD
  • gh pr view --json number 2>/dev/null || true: !gh pr view --json number 2>/dev/null || true

Git Safety Protocol

  • NEVER update the git config
  • NEVER run destructive/irreversible git commands (like push --force, hard reset, etc) unless the user explicitly requests them
  • NEVER skip hooks (--no-verify, --no-gpg-sign, etc) unless the user explicitly requests it
  • NEVER run force push to main/master, warn the user if they request it
  • Do not commit files that likely contain secrets (.env, credentials.json, etc)
  • Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported

Your task

Analyze all changes that will be included in the pull request, making sure to look at all relevant commits (NOT just the latest commit, but ALL commits that will be included in the pull request from the git diff ${DEFAULT_BRANCH}...HEAD output above).

Based on the above changes:

  1. Create a new branch if on ${DEFAULT_BRANCH} (use SAFEUSER from context above for the branch name prefix, falling back to whoami if SAFEUSER is empty, e.g., username/feature-name)
  2. Create a single commit with an appropriate message using heredoc syntax
javascript
${COMMIT_ATTRIBUTION_TEXT?", ending with the attribution text shown in the example below":""}

:

git commit -m "$(cat <<'EOF'
Commit message here.
```javascript
${COMMIT_ATTRIBUTION_TEXT?`

<span class="template-var">${COMMIT_ATTRIBUTION_TEXT}</span>`:""}

EOF )"

3. Push the branch to origin
4. If a PR already exists for this branch (check the gh pr view output above), update the PR title and body using `gh pr edit` to reflect the current diff (and add `--add-reviewer anthropics/claude-code`). Otherwise, create a pull request using `gh pr create` with heredoc syntax for the body and `--reviewer anthropics/claude-code`.
   - IMPORTANT: Keep PR titles short (under 70 characters). Use the body for details.

gh pr create --title "Short, descriptive title" --body "$(cat <<'EOF'

Summary

<1-3 bullet points>

Test plan

[Bulleted markdown checklist of TODOs for testing the pull request...]

Changelog

[If this PR contains user-facing changes, add a changelog entry here. Otherwise, remove this section.]

javascript
${PR_ATTRIBUTION_TEXT?`

<span class="template-var">${PR_ATTRIBUTION_TEXT}</span>`:""}

EOF )"


You have the capability to call multiple tools in a single response. You MUST do all of the above in a single message.

5. After creating/updating the PR, check if the user's CLAUDE.md mentions posting to Slack channels. If it does, use ToolSearch to search for "slack send message" tools. If ToolSearch finds a Slack tool, ask the user if they'd like you to post the PR URL to the relevant Slack channel. Only post if the user confirms. If ToolSearch returns no results or errors, skip this step silently—do not mention the failure, do not attempt workarounds, and do not try alternative approaches.

Return the PR URL when you're done, so the user can see it.