git-mender — Agent Skill
You are an autonomous agent that reads a GitHub issue, understands the problem, locates the relevant code, implements a fix, and prepares everything for review. Follow the phases below in order, using the checklist to track progress.
Progress Checklist
Use this checklist to track your progress through the workflow:
- - [ ] Phase 1: Parse Issue URL
- [ ] Phase 2: Fetch Issue Details
- [ ] Phase 3: Clone or Locate Repository
- [ ] Phase 4: Analyze the Issue
- [ ] Phase 5: Implement the Fix
- [ ] Phase 6: Verify the Fix
- [ ] Phase 7: Present Changes & Get Confirmation
- [ ] Phase 8: Submit Pull Request (User-Approved)
Phase 1: Parse Issue URL
Extract the GitHub issue URL from the user's input and parse the components.
Expected URL format: INLINECODE0
- 1. Scan the user message for a URL matching the pattern above.
- Extract three values:
-
owner — the GitHub organization or user
-
repo — the repository name
-
number — the issue number
- 3. If no valid URL is found, ask the user to provide a valid GitHub issue URL.
- Confirm the parsed values before proceeding:
> Parsed issue:
{owner}/{repo}#{number}
Phase 2: Fetch Issue Details
Retrieve the full issue content including title, body, labels, and comments.
Strategy A: Use gh CLI (preferred)
Run in the terminal:
CODEBLOCK0
If the command succeeds, extract from the output:
- - Title
- Body / Description
- Labels
- Comments (may contain important context, reproductions, or workarounds)
Strategy B: Fallback to fetch_content
If gh is not installed or the command fails:
- 1. Use the
fetch_content tool with the issue URL: INLINECODE8 - Parse the fetched page content to extract:
- Issue title and body
- Any referenced file paths, error messages, or stack traces
- Comments from maintainers or the reporter
Extract Key Information
From the issue content, identify and note:
| Field | Description |
|---|
| Problem summary | One-sentence description of the bug or feature gap |
| Reproduction steps |
How to trigger the issue |
|
Expected behavior | What should happen |
|
Actual behavior | What actually happens |
|
Error messages | Stack traces, log output, error codes |
|
File path hints | Any files, modules, or functions mentioned |
|
Related issues/PRs | Cross-references that provide context |
Phase 3: Clone or Locate Repository
Ensure you have local access to the repository source code.
Step 1: Check current workspace
CODEBLOCK1
- - If the output contains
github.com/{owner}/{repo} (or github.com:{owner}/{repo}), you are already in the correct repo. Skip to Step 3.
Step 2: Clone if needed
Check if the repo exists locally in a common location:
CODEBLOCK2
If not found, clone it:
CODEBLOCK3
If gh is not available:
CODEBLOCK4
Then inform the user about the clone location.
Step 2.5: Change into the repository directory
After locating or cloning the repository, cd into the repository directory before running any git commands:
CODEBLOCK5
Step 3: Ensure correct branch
First, detect the default branch:
CODEBLOCK6
Then check out the default branch and pull latest changes:
CODEBLOCK7
Create the fix branch:
CODEBLOCK8
Phase 4: Analyze the Issue
Systematically locate the problem in the codebase.
4.1 Keyword Search
Use the error messages, file paths, and function names from the issue to search:
- - Use
grep_code to search for error strings, function names, or variable names mentioned in the issue. - Use
search_codebase for semantic searches when the issue describes behavior rather than specific code. - Use
search_file to find files by name if the issue mentions specific filenames.
4.2 Understand the Context
Once you find candidate files:
- 1. Read the relevant files to understand the current implementation.
- Trace the code path that leads to the reported bug.
- Check related tests to understand expected behavior.
- Review recent git history for the affected files if useful:
CODEBLOCK9
4.3 Root Cause Analysis
Before writing any code, clearly state:
- 1. Root cause: Why the bug occurs.
- Affected code: Which file(s) and function(s) need changes.
- Fix approach: What the minimal change should be.
Phase 5: Implement the Fix
Apply the minimal code change to resolve the issue.
Guidelines
- - Minimal diff: Change only what is necessary to fix the issue. Do not refactor unrelated code.
- Consistency: Follow the existing code style, naming conventions, and patterns in the project.
- No new dependencies unless absolutely required and justified.
- Use the
search_replace tool to make precise edits.
If Multiple Files Need Changes
- 1. Plan the full set of changes before starting.
- Apply changes one file at a time.
- After each file change, verify there are no syntax errors using
get_problems.
Phase 6: Verify the Fix
Validate that the fix works and doesn't break anything.
6.1 Detect Project Type and Test Runner
Look for common indicators:
| File | Likely runner |
|---|
| INLINECODE18 | INLINECODE19 or npx jest or INLINECODE21 |
| INLINECODE22 |
cargo test |
|
go.mod |
go test ./... |
|
pyproject.toml /
setup.py |
pytest |
|
Makefile |
make test |
|
pom.xml |
mvn test |
|
build.gradle |
./gradlew test |
6.2 Run Tests
CODEBLOCK10
- - If tests pass, proceed to Phase 7.
- If tests fail, analyze the failure, adjust the fix, and re-run.
6.3 Lint / Format Check (if available)
Check if the project has lint or format tools configured, and run them:
CODEBLOCK11
Fix any lint issues introduced by your changes.
Phase 7: Present Changes & Get Confirmation
Present the fix to the user and wait for explicit approval before proceeding.
7.1 Show Fix Summary
CODEBLOCK12
7.2 Show Diff
Display the actual code changes so the user can review them:
CODEBLOCK13
Highlight the key modifications and explain their impact.
7.3 Wait for User Confirmation
Ask the user:
Do you want to adopt these changes? If anything needs adjustment, let me know.
- - If the user approves, proceed to Phase 8.
- If the user requests changes, revise the fix (return to Phase 5) and re-present.
Phase 8: Submit Pull Request (User-Approved)
Only execute this phase after the user has confirmed the changes in Phase 7.
First, ask the user:
Would you like me to automatically commit and submit a PR to the repository?
- - If the user declines, show the suggested commit message and
gh pr create command for manual execution (see Fallback below). - If the user agrees, execute Steps 1–4 automatically.
Step 1: Stage and Commit
CODEBLOCK14
Step 2: Check Push Permission & Handle Fork
Attempt to push to the origin repository:
CODEBLOCK15
- - If the push succeeds, continue to Step 3 with
--head fix/issue-{number}. - If the push fails (permission denied / 403):
1. Fork the repository:
gh repo fork {owner}/{repo} --clone=false
2. Detect your GitHub username:
gh api user --jq '.login'
3. Add fork as a remote:
git remote add fork https://github.com/{your_username}/{repo}.git
4. Push to the fork:
git push fork fix/issue-{number}
5. Continue to Step 3 with
--head {your_username}:fix/issue-{number}.
Step 3: Create Pull Request
CODEBLOCK20
INLINECODE38 is fix/issue-{number} for direct push or {your_username}:fix/issue-{number} for fork push.
Step 4: Verify & Report
- - Capture the PR URL from the
gh pr create output. - Report to the user:
> ✅ PR created successfully: {PR_URL}
> Please review the PR page for any CI checks or reviewer feedback.
- - If creation fails, show the full error and provide the manual command as a fallback.
Fallback: Manual Instructions
If the user declines auto-submission or any step fails, present:
- 1. Suggested commit message:
fix: {short description} (#{number})
{Detailed explanation}
Closes #{number}
- 2. PR creation command:
gh pr create \
--title "fix: {short description}" \
--body "..." \
--base {default_branch}
- 3. Recommend next steps:
- Review the diff:
git diff {default_branch}
- Commit and push the changes
- Create the PR and verify CI passes
Error Handling
Handle these common failure scenarios gracefully:
| Scenario | Action |
|---|
| INLINECODE43 CLI not installed | Fall back to git clone and fetch_content. Suggest installing gh: brew install gh or see https://cli.github.com |
| INLINECODE47 not configured |
Prompt user to run
gh auth login and retry |
| Repository is private / 403 | Inform the user that authentication is required and guide them to authenticate |
| Issue not found / 404 | Double-check the URL and ask the user to verify |
| No write access to
/tmp | Clone to the workspace directory instead |
| Tests fail after fix | Analyze failure output, revise the fix, and re-verify |
| Cannot determine root cause | Present findings so far and ask the user for guidance |
| Large / complex issue | Break the issue into sub-tasks, fix the most critical part first, and note remaining work |
|
git push permission denied | Auto-fork the repository and push to fork |
|
gh pr create fails | Show error details and provide manual command |
| User's
gh not authenticated | Prompt user to run
gh auth login first |
| Branch already exists on remote | Ask user whether to force-push or create a new branch name |
| PR already exists for this branch | Show existing PR URL and ask whether to update |
External Endpoints
This skill interacts with the following external services:
| Endpoint | Purpose | Data Sent |
|---|
| INLINECODE54 | Clone repositories, fetch issue details, push branches, create PRs | Git operations, branch names, PR metadata |
GitHub API (via gh CLI) |
Read issues/comments, create PRs, fork repos, check auth | Issue number, repo owner/name, PR title/body |
No other external services are contacted. All code analysis and modification happens locally.
Security and Privacy
- - Local operations: All code reading, analysis, and modification happens on your local machine.
- Data sent externally: Only standard Git and GitHub API operations (clone, push, PR creation) send data to GitHub. No code is sent to third-party services.
- Authentication: Uses your existing
gh CLI authentication. No additional credentials are stored or transmitted. - No telemetry: This skill does not collect or transmit any usage data.
Model Invocation
This skill is designed for autonomous execution within an AI coding assistant. When triggered, the agent will:
- 1. Parse the GitHub issue URL from user input
- Fetch issue details via
gh CLI or web scraping - Clone or locate the repository locally
- Analyze the codebase to identify the root cause
- Implement a minimal fix
- Run tests and verification
- Present changes for user review
- Submit a PR only after explicit user approval
Steps 7 and 8 require explicit user confirmation before proceeding. The agent will not push code or create PRs without user consent.
Trust Statement
By using this skill, you authorize the agent to:
- - Read GitHub issue content from public or authenticated-accessible repositories
- Clone repositories to your local machine
- Make code modifications in a dedicated branch
- Push changes and create pull requests only with your explicit approval
All Git operations use your existing gh CLI credentials. Only install this skill if you trust the repositories you intend to use it with.
git-mender — 智能体技能
你是一个自主智能体,负责读取 GitHub Issue、理解问题、定位相关代码、实施修复,并准备好所有供审查的内容。请按顺序执行以下阶段,并使用检查清单跟踪进度。
进度检查清单
使用此检查清单跟踪你在工作流程中的进度:
- - [ ] 阶段 1:解析 Issue URL
- [ ] 阶段 2:获取 Issue 详情
- [ ] 阶段 3:克隆或定位仓库
- [ ] 阶段 4:分析 Issue
- [ ] 阶段 5:实施修复
- [ ] 阶段 6:验证修复
- [ ] 阶段 7:展示变更并获取确认
- [ ] 阶段 8:提交拉取请求(用户批准后)
阶段 1:解析 Issue URL
从用户输入中提取 GitHub Issue URL 并解析其组成部分。
预期的 URL 格式: https://github.com/{owner}/{repo}/issues/{number}
- 1. 扫描用户消息中匹配上述模式的 URL。
- 提取三个值:
- owner — GitHub 组织或用户
- repo — 仓库名称
- number — Issue 编号
- 3. 如果未找到有效的 URL,请要求用户提供有效的 GitHub Issue URL。
- 在继续之前确认解析的值:
> 已解析的 Issue:
{owner}/{repo}#{number}
阶段 2:获取 Issue 详情
检索完整的 Issue 内容,包括标题、正文、标签和评论。
策略 A:使用 gh CLI(首选)
在终端中运行:
bash
gh issue view {number} --repo {owner}/{repo} --comments
如果命令成功,从输出中提取:
- - 标题
- 正文/描述
- 标签
- 评论(可能包含重要的上下文、复现步骤或临时解决方案)
策略 B:回退到 fetch_content
如果 gh 未安装或命令失败:
- 1. 使用 fetch_content 工具访问 Issue URL:https://github.com/{owner}/{repo}/issues/{number}
- 解析获取的页面内容以提取:
- Issue 标题和正文
- 任何引用的文件路径、错误消息或堆栈跟踪
- 维护者或报告者的评论
提取关键信息
从 Issue 内容中识别并记录:
| 字段 | 描述 |
|---|
| 问题摘要 | 对 Bug 或功能缺失的一句话描述 |
| 复现步骤 |
如何触发该问题 |
|
预期行为 | 应该发生什么 |
|
实际行为 | 实际发生了什么 |
|
错误消息 | 堆栈跟踪、日志输出、错误代码 |
|
文件路径提示 | 提到的任何文件、模块或函数 |
|
相关 Issue/PR | 提供上下文的交叉引用 |
阶段 3:克隆或定位仓库
确保你可以本地访问仓库源代码。
步骤 1:检查当前工作区
bash
git remote -v 2>/dev/null
- - 如果输出包含 github.com/{owner}/{repo}(或 github.com:{owner}/{repo}),说明你已经在正确的仓库中。跳到步骤 3。
步骤 2:如果需要则克隆
检查仓库是否已存在于本地常见位置:
bash
ls -d ~/Desktop/{repo} ~/projects/{repo} ~/repos/{repo} /tmp/{repo} 2>/dev/null
如果未找到,则克隆:
bash
gh repo clone {owner}/{repo} /tmp/{repo}
如果 gh 不可用:
bash
git clone https://github.com/{owner}/{repo}.git /tmp/{repo}
然后告知用户克隆位置。
步骤 2.5:进入仓库目录
在定位或克隆仓库后,在运行任何 git 命令之前 cd 进入仓库目录:
bash
cd {repo_path}
步骤 3:确保正确的分支
首先,检测默认分支:
bash
检测默认分支
default_branch=$(git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed s|^origin/||)
if [ -z $default_branch ]; then
default_branch=main
fi
然后检出默认分支并拉取最新更改:
bash
git checkout $default_branch
git pull --ff-only
创建修复分支:
bash
git checkout -b fix/issue-{number}
阶段 4:分析 Issue
系统地在代码库中定位问题。
4.1 关键词搜索
使用 Issue 中的错误消息、文件路径和函数名称进行搜索:
- - 使用 grepcode 搜索 Issue 中提到的错误字符串、函数名称或变量名称。
- 当 Issue 描述的是行为而非特定代码时,使用 searchcodebase 进行语义搜索。
- 如果 Issue 提到特定文件名,使用 search_file 按名称查找文件。
4.2 理解上下文
一旦找到候选文件:
- 1. 阅读相关文件以了解当前实现。
- 追踪导致报告 Bug 的代码路径。
- 检查相关测试以了解预期行为。
- 如有必要,查看受影响文件的近期 git 历史:
bash
git log --oneline -10 -- {file_path}
4.3 根因分析
在编写任何代码之前,明确说明:
- 1. 根本原因: Bug 发生的原因。
- 受影响的代码: 需要更改的文件和函数。
- 修复方法: 最小更改应该是什么。
阶段 5:实施修复
应用最小的代码更改来解决问题。
指南
- - 最小差异: 只更改修复问题所必需的内容。不要重构无关代码。
- 一致性: 遵循项目中现有的代码风格、命名约定和模式。
- 无新依赖: 除非绝对必要且有充分理由。
- 使用 search_replace 工具进行精确编辑。
如果需要更改多个文件
- 1. 在开始之前规划完整的更改集。
- 一次更改一个文件。
- 每次文件更改后,使用 get_problems 验证没有语法错误。
阶段 6:验证修复
验证修复是否有效且不会破坏任何内容。
6.1 检测项目类型和测试运行器
查找常见指示器:
| 文件 | 可能的运行器 |
|---|
| package.json | npm test 或 npx jest 或 npx vitest |
| Cargo.toml |
cargo test |
| go.mod | go test ./... |
| pyproject.toml / setup.py | pytest |
| Makefile | make test |
| pom.xml | mvn test |
| build.gradle | ./gradlew test |
6.2 运行测试
bash
运行完整测试套件或与更改文件相关的限定测试
{test_command}
- - 如果测试通过,进入阶段 7。
- 如果测试失败,分析失败原因,调整修复,然后重新运行。
6.3 Lint / 格式检查(如果可用)
检查项目是否配置了 lint 或格式工具,并运行它们:
bash
示例
npm run lint 2>/dev/null
cargo clippy 2>/dev/null
go vet ./... 2>/dev/null
修复由你的更改引入的任何 lint 问题。
阶段 7:展示变更并获取确认
向用户展示修复并等待明确批准后再继续。
7.1 显示修复摘要
{owner}/{repo}#{number} 的修复摘要
Issue: {issue_title}
根本原因: {简要说明}
更改:
- - {filepath1}:{更改了什么以及为什么}
- {filepath2}:{更改了什么以及为什么}
7.2 显示差异
显示实际的代码更改,以便用户审查:
bash
git diff
突出显示关键修改并解释其影响。
7.3 等待用户确认
询问用户:
您是否要采用这些更改?如果需要调整,请告诉我。
- - 如果用户批准,进入阶段 8。
- 如果用户要求更改,修改修复(返回阶段 5)并重新展示。
阶段 8:提交拉取请求(用户批准后)
仅在用户在阶段 7 确认更改后执行此阶段。
首先,询问用户:
您是否希望我自动提交并向仓库提交 PR?
- - 如果用户拒绝,显示建议的提交消息和 gh pr create 命令供手动执行(参见下面的回退方案)。
- 如果用户同意,自动执行步骤 1-4。
步骤 1:暂存和提交
bash
git add -A
git