This commit implements a comprehensive system to prevent duplicate PRs
from being created for the same issue. This addresses the ironic situation
where duplicate PRs were being created for issue #1128, which was about
cleaning up duplicate PRs.
## Changes
### 1. Pre-flight Check Scripts
- `scripts/check-existing-prs.sh` - Bash script to check for existing PRs
- `scripts/check_existing_prs.py` - Python version of the check
- `scripts/pr-safe.sh` - User-friendly wrapper with guidance
### 2. Fixed Existing Script
- Fixed syntax error in `scripts/cleanup-duplicate-prs.sh` (line 21)
- Fixed AUTH header format
### 3. Documentation
- Added `docs/duplicate-pr-prevention.md` with comprehensive usage guide
## How It Works
### Pre-flight Checks
Before creating a PR, agents should run:
```bash
./scripts/check-existing-prs.sh <issue_number>
```
Exit codes:
- 0: No existing PRs found (safe to create new PR)
- 1: Existing PRs found (do not create new PR)
- 2: Error (API failure, missing parameters, etc.)
### Cleanup Tools
For cleaning up existing duplicate PRs:
```bash
./scripts/cleanup-duplicate-prs.sh --dry-run # Show what would be done
./scripts/cleanup-duplicate-prs.sh --close # Actually close duplicates
```
## Prevention Strategy
1. **Pre-flight Checks**: Always check before creating a PR
2. **Agent Discipline**: Add to agent instructions to check before creating PRs
3. **Tooling Integration**: Integrate into existing workflows
## Testing
Tested the scripts with various scenarios:
- Issue with no existing PRs (exit code 0)
- Issue with existing PRs (exit code 1)
- Invalid inputs (exit code 2)
- API failures (exit code 2)
## Related Issues
Closes#1474: [META] Still creating duplicate PRs for issue #1128 despite cleanup