From 945d25f285b2f61ac498394c01bec0a9cf156f7e Mon Sep 17 00:00:00 2001 From: Dale Carman Date: Mon, 13 Oct 2025 09:38:15 -0500 Subject: [PATCH 01/17] docs: add research documents for /merge command planning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added comprehensive research for implementing the /merge command (#100): - PR merge automation best practices - GitHub CLI and worktree integration patterns These documents inform the technical specification and implementation approach for the automated PR merge workflow. Relates to #100 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../gh-cli-worktree-claude-commands.md | 932 +++++++++++++++++ .../pr-merge-automation-best-practices.md | 944 ++++++++++++++++++ 2 files changed, 1876 insertions(+) create mode 100644 docs/research/gh-cli-worktree-claude-commands.md create mode 100644 docs/research/pr-merge-automation-best-practices.md diff --git a/docs/research/gh-cli-worktree-claude-commands.md b/docs/research/gh-cli-worktree-claude-commands.md new file mode 100644 index 00000000..40066b2b --- /dev/null +++ b/docs/research/gh-cli-worktree-claude-commands.md @@ -0,0 +1,932 @@ +# GitHub CLI, Git Worktree, and Claude Code Commands Research + +> Research Date: 2025-10-13 +> Agent OS Version: 2.4.0 +> Purpose: Technical documentation for workflow completion automation + +## Table of Contents + +1. [GitHub CLI PR Merge](#github-cli-pr-merge) +2. [GitHub CLI PR Checks](#github-cli-pr-checks) +3. [GitHub CLI PR View](#github-cli-pr-view) +4. [GitHub CLI PR Review](#github-cli-pr-review) +5. [GitHub CLI API Access](#github-cli-api-access) +6. [Git Worktree Commands](#git-worktree-commands) +7. [Claude Code Command Format](#claude-code-command-format) +8. [Implementation Patterns](#implementation-patterns) + +--- + +## GitHub CLI PR Merge + +### Official Documentation +- **URL**: https://cli.github.com/manual/gh_pr_merge +- **Command**: `gh pr merge [ | | ] [flags]` + +### Command Behavior +- Without an argument, selects the pull request for the current branch +- For branches requiring merge queues, no specific merge strategy is needed +- Can automatically enable merge when required checks pass + +### Merge Strategy Flags + +```bash +# Merge strategies (choose one) +-m, --merge # Merge commits with base branch (creates merge commit) +-r, --rebase # Rebase commits onto base branch (linear history) +-s, --squash # Squash commits into one and merge (single commit) +``` + +### Key Flags + +```bash +# Admin and automation +--admin # Bypass requirements using administrator privileges +--auto # Automatically merge after requirements are met +--disable-auto # Disable auto-merge + +# Branch management +-d, --delete-branch # Delete local and remote branch after merge + +# Commit customization +-A, --author-email # Set email for merge commit author +-b, --body # Set merge commit body text +-F, --body-file # Read body text from file (use "-" for stdin) +--subject # Set merge commit subject text + +# Repository selection +-R, --repo [HOST/]OWNER/REPO # Select another repository +``` + +### Merge Queue Behavior +- When targeting a branch requiring a merge queue: + - No merge strategy is required + - If required checks haven't passed, auto-merge will be enabled + - If required checks have passed, PR is added to merge queue + - To bypass merge queue and merge directly, use `--admin` flag + +### Usage Examples + +```bash +# Merge current branch's PR with merge commit +gh pr merge --merge --delete-branch + +# Squash and merge with custom message +gh pr merge --squash --subject "feat: add new feature" --body "Implements feature X" + +# Auto-merge when checks pass +gh pr merge --auto --squash --delete-branch + +# Merge specific PR by number +gh pr merge 123 --merge + +# Force merge with admin privileges +gh pr merge --admin --merge +``` + +### Exit Codes +- 0: Success +- Non-zero: Error (check stderr for details) + +--- + +## GitHub CLI PR Checks + +### Official Documentation +- **URL**: https://cli.github.com/manual/gh_pr_checks +- **Command**: `gh pr checks [ | | ] [flags]` + +### Command Behavior +- Shows CI status for a single pull request +- Without an argument, selects the PR for the current branch +- Includes a `bucket` field categorizing check states into: pass, fail, pending, skipping, or cancel + +### Flags + +```bash +# Watch mode +--watch # Watch checks until they finish +-i, --interval # Refresh interval in seconds (default: 10) +--fail-fast # Exit watch mode on first check failure + +# Filtering +--required # Only show checks that are required + +# Output formatting +--json # Output JSON with specified fields +-q, --jq # Filter JSON output using jq expression +-t, --template # Format JSON output using Go template + +# Web interface +-w, --web # Open browser to show check details +``` + +### JSON Output Fields + +```bash +# Available fields for --json flag +bucket # Categorized state (pass/fail/pending/skipping/cancel) +completedAt # Timestamp when check completed +description # Check description +event # Event that triggered check +link # URL to check details +name # Check name +startedAt # Timestamp when check started +state # Raw check state +workflow # Workflow name +``` + +### Exit Codes +- 0: Success +- 8: Checks pending (useful for scripting) +- Non-zero: Error + +### Usage Examples + +```bash +# Basic check status +gh pr checks + +# Watch checks until completion +gh pr checks --watch + +# Watch with custom interval and fail-fast +gh pr checks --watch --interval 5 --fail-fast + +# Get only required checks +gh pr checks --required + +# JSON output with specific fields +gh pr checks --json state,name,conclusion,bucket + +# Check specific PR +gh pr checks 123 + +# Filter pending checks with jq +gh pr checks --json name,state,bucket --jq '.[] | select(.bucket == "pending")' + +# Open checks in browser +gh pr checks --web +``` + +### Scripting Pattern + +```bash +# Wait for checks to pass +gh pr checks --watch --fail-fast +exit_code=$? +if [ $exit_code -eq 0 ]; then + echo "All checks passed" + gh pr merge --merge --delete-branch +else + echo "Checks failed or pending (exit code: $exit_code)" + exit 1 +fi +``` + +--- + +## GitHub CLI PR View + +### Official Documentation +- **URL**: https://cli.github.com/manual/gh_pr_view +- **Command**: `gh pr view [ | | ] [flags]` + +### Command Behavior +- Display the title, body, and other information about a pull request +- Without an argument, displays the PR for the current branch +- With `--web` flag, opens PR in browser instead + +### Flags + +```bash +# Comments +-c, --comments # View pull request comments + +# Output formatting +--json # Output JSON with specified fields +-q, --jq # Filter JSON output using jq expression +-t, --template # Format JSON output using Go template + +# Web interface +-w, --web # Open pull request in browser + +# Repository selection +-R, --repo [HOST/]OWNER/REPO # Select another repository +``` + +### JSON Output Fields + +```bash +# Complete list of available fields +additions, assignees, author, autoMergeRequest, baseRefName, baseRefOid, body, +changedFiles, closed, closedAt, closingIssuesReferences, comments, commits, +createdAt, deletions, files, fullDatabaseId, headRefName, headRefOid, +headRepository, headRepositoryOwner, id, isCrossRepository, isDraft, labels, +latestReviews, maintainerCanModify, mergeCommit, mergeStateStatus, mergeable, +mergedAt, mergedBy, milestone, number, potentialMergeCommit, projectCards, +projectItems, reactionGroups, reviewDecision, reviewRequests, reviews, state, +statusCheckRollup, title, updatedAt, url +``` + +### Key Fields for Review Status + +```bash +reviewDecision # Overall review decision (APPROVED, CHANGES_REQUESTED, etc.) +reviews # Array of all reviews +reviewRequests # Array of pending review requests +latestReviews # Most recent reviews from each reviewer +statusCheckRollup # CI/CD check status +mergeable # Whether PR can be merged +mergeStateStatus # Merge state (CLEAN, BEHIND, BLOCKED, etc.) +``` + +### Usage Examples + +```bash +# View current PR +gh pr view + +# View specific PR +gh pr view 123 + +# Get review status +gh pr view --json reviewDecision,reviews,reviewRequests + +# Check if PR is approved and mergeable +gh pr view --json reviewDecision,mergeable,statusCheckRollup + +# View with comments +gh pr view --comments + +# Complex query with jq +gh pr view --json reviews --jq '.reviews | map(select(.state == "APPROVED")) | length' + +# Check merge readiness +gh pr view --json reviewDecision,mergeable,mergeStateStatus,statusCheckRollup \ + --jq '{approved: .reviewDecision, mergeable: .mergeable, state: .mergeStateStatus}' +``` + +--- + +## GitHub CLI PR Review + +### Official Documentation +- **URL**: https://cli.github.com/manual/gh_pr_review +- **Command**: `gh pr review [ | | ] [flags]` + +### Command Behavior +- Add a review to a pull request +- Without an argument, reviews the PR for the current branch + +### Review Actions + +```bash +-a, --approve # Approve pull request +-c, --comment # Comment on pull request (no approval/rejection) +-r, --request-changes # Request changes on pull request +``` + +### Flags + +```bash +# Review content +-b, --body # Review body text +-F, --body-file # Read body from file (use "-" for stdin) + +# Repository selection +-R, --repo [HOST/]OWNER/REPO # Select another repository +``` + +### Usage Examples + +```bash +# Approve PR +gh pr review --approve + +# Approve with comment +gh pr review --approve --body "LGTM! Great work." + +# Request changes +gh pr review --request-changes --body "Please address the following issues..." + +# Comment without approval +gh pr review --comment --body "Some thoughts on the implementation..." + +# Review specific PR +gh pr review 123 --approve + +# Approve from file +gh pr review --approve --body-file review.txt +``` + +--- + +## GitHub CLI API Access + +### Official Documentation +- **URL**: https://cli.github.com/manual/gh_api +- **Command**: `gh api [flags]` + +### Advanced Queries + +The `gh api` command provides direct access to GitHub's REST API for complex queries not covered by convenience commands. + +### Review Status Queries + +```bash +# Get all reviews for a PR +gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews + +# Get only approved reviews +gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews \ + --jq '.[] | select(.state == "APPROVED") | {user: .user.login, body: .body}' + +# Get review comments (inline comments) +gh api repos/{owner}/{repo}/pulls/{pr_number}/comments + +# Get all comments (issue + review comments) +gh api repos/{owner}/{repo}/issues/{pr_number}/comments +``` + +### Check Status Queries + +```bash +# Get status checks for a commit +gh api repos/{owner}/{repo}/commits/{sha}/check-runs + +# Get required status checks +gh api repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks + +# Get combined status for a ref +gh api repos/{owner}/{repo}/commits/{ref}/status +``` + +### Usage Examples + +```bash +# Check if PR has any approved reviews +approved_count=$(gh api repos/{owner}/{repo}/pulls/{pr}/reviews \ + --jq '[.[] | select(.state == "APPROVED")] | length') + +if [ "$approved_count" -gt 0 ]; then + echo "PR has $approved_count approval(s)" +fi + +# Get latest review from each reviewer +gh api repos/{owner}/{repo}/pulls/{pr}/reviews \ + --jq 'group_by(.user.login) | map(max_by(.submitted_at))' +``` + +--- + +## Git Worktree Commands + +### Official Documentation +- **URL**: https://git-scm.com/docs/git-worktree +- **Primary Commands**: `git worktree remove`, `git worktree prune` + +### git worktree list + +```bash +# List all worktrees +git worktree list + +# List with more details +git worktree list --porcelain + +# Expected output format +/path/to/main-worktree abc1234 [main] +/path/to/feature-branch def5678 [feature/xyz] +``` + +### git worktree remove + +**Syntax**: `git worktree remove [flags]` + +#### Safety Features +- Only clean worktrees can be removed by default +- "Clean" means: no untracked files and no modifications in tracked files +- Cannot remove the main worktree + +#### Flags + +```bash +-f, --force # Force removal (required for unclean worktrees) + # Specify twice to remove locked worktrees +``` + +#### Usage Examples + +```bash +# Remove a clean worktree +git worktree remove /path/to/worktree + +# Force remove an unclean worktree +git worktree remove --force /path/to/worktree + +# Remove a locked worktree (force twice) +git worktree remove --force --force /path/to/locked-worktree +``` + +#### Error Conditions +- Worktree has untracked files: requires `--force` +- Worktree has modifications: requires `--force` +- Worktree contains submodules: requires `--force` +- Worktree is locked: requires `--force --force` +- Attempting to remove main worktree: always fails + +### git worktree prune + +**Syntax**: `git worktree prune [flags]` + +#### Purpose +- Removes administrative information about worktrees that no longer exist +- Cleans up stale worktree metadata in `.git/worktrees/` + +#### Flags + +```bash +-n, --dry-run # Show what would be removed without doing it +-v, --verbose # Report all removals +--expire