---
name: commit-push-pr
description: Commit the current changes, push the branch, and open (or update) a pull request — one clean commit, a short PR title, and a Summary / Test plan body.
---

## Context

Gather the real state first — run these and read the output:

```bash
whoami
git status
git diff HEAD
git branch --show-current
git log --oneline <base>..HEAD        # commits that will ride in the PR
git diff <base>...HEAD                # the FULL diff the PR will contain
gh pr view --json number 2>/dev/null || true   # does a PR already exist?
```

`<base>` is the default branch (usually `main` or `master`; check
`git remote show origin` if unsure).

## 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 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 <base>...HEAD` output above).

Based on the above changes:

1. Create a new branch if you are currently on the default branch
   (prefix the branch name with the username from `whoami`, e.g.
   `username/feature-name`).
2. Create a single commit with an appropriate message:

```bash
git commit -m "$(cat <<'EOF'
Commit message here.
EOF
)"
```

3. Push the branch to the repo's remote (usually `origin`; use the
   remote this repo is actually configured with), with `-u` on first
   push.
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. Otherwise, create a pull request using
   `gh pr create` with the multi-line body syntax shown below.
   - IMPORTANT: Keep PR titles short (under 70 characters). Use the
     body for details.

```bash
gh pr create --title "Short, descriptive title" --body "$(cat <<'EOF'
## Summary
- What changed and why, in a few bullets

## Test plan
- How this was verified (commands run, flows driven, or why not applicable)
EOF
)"
```

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

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