fix(agents): replace gh CLI with curl for PR checking to prevent duplicate work

Agents do not have access to gh CLI, causing them to skip the pre-flight
PR check and collide on duplicate work. This replaces all gh-based PR
checking commands with curl + jq using the GitHub REST API, updates the
task claiming protocol to use branch push + started log file as the
primary lock mechanism, and updates automation scripts to use curl for
PR listing and git fetch for PR checkout.

Files updated:
- AGENTS.md (Section 12 coordination rules)
- CLAUDE.md (coordination rules)
- META_PROMPTS.md (daily + weekly meta prompts)
- daily-scheduler.md (pre-flight gate, task claiming, error handling)
- weekly-scheduler.md (pre-flight gate, task claiming, error handling)
- bitvid-pr-review-agent.md (PR enumeration + checkout)
- bitvid-ci-health-agent.md (CI run gathering)
- bitvid-weekly-synthesis-agent.md (PR metadata gathering)
- bitvid-changelog-agent.md (PR metadata verification)
- scripts/agent/review-open-prs.mjs (PR listing + checkout)
- scripts/automated-pr-review.mjs (--all mode PR listing + checkout)

https://claude.ai/code/session_01L5bzzGpZ6YTiLXcfqaL81G
This commit is contained in:
Claude committed 2026-02-13 15:47:42 +00:00
1 parent 05d575d187
commit ce72c4bbad
11 files changed
+97 -103

No files matched your search

+4 -6
View File
@@ -14,10 +14,9 @@ before choosing a task — is to run these two commands. Not later. NOW.
COMMAND 1 — Check for open daily agent PRs:
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt,author --limit 100 | grep -i "\[daily\]"
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq '{count: length, titles: [.[].title]}'
If `gh` is not available, use this fallback:
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | grep -o '"title":"[^"]*\[daily\][^"]*"'
Review the output. Any title containing "[daily]" means that agent is OFF LIMITS.
COMMAND 2 — Check for in-progress task logs:
@@ -63,10 +62,9 @@ before choosing a task — is to run these two commands. Not later. NOW.
COMMAND 1 — Check for open weekly agent PRs:
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt,author --limit 100 | grep -i "\[weekly\]"
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq '{count: length, titles: [.[].title]}'
If `gh` is not available, use this fallback:
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | grep -o '"title":"[^"]*\[weekly\][^"]*"'
Review the output. Any title containing "[weekly]" means that agent is OFF LIMITS.
COMMAND 2 — Check for in-progress task logs:
+13 -24
View File
@@ -76,17 +76,12 @@ If you arrived here from the meta prompt and already ran these commands and past
Run this command:
```bash
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt,author --limit 100 | grep -i "\[daily\]"
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq '{count: length, titles: [.[].title]}'
```
If `gh` is unavailable, use this fallback:
```bash
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | grep -o '"title":"[^"]*\[daily\][^"]*"'
```
**Paste the complete raw output.** If the command returns nothing or errors, write: `OUTPUT: (empty — no results)`
**Paste the complete raw output.** If the command returns nothing, write: `OUTPUT: (empty — no results)`
Every agent name that appears in these PR titles is **OFF LIMITS** — do not select it.
Review the titles in the output. Every agent name that appears in a PR title containing `[daily]` is **OFF LIMITS** — do not select it.
### COMMAND 2 — Check the task log for incomplete runs
@@ -114,7 +109,7 @@ or:
EXCLUDED AGENTS: (none)
```
**If Command 1 failed** (network error, API limit, `gh`/`curl` unavailable): you MUST still check the task log directory (Command 2). Log a warning in your summary that PR-based claim checking was unavailable.
**If Command 1 failed** (network error, API rate limit, `curl`/`jq` unavailable): you MUST still check the task log directory (Command 2). Log a warning in your summary that PR-based claim checking was unavailable.
**Do not proceed to Step 1 until you have pasted command outputs and written your exclusion list.**
@@ -164,25 +159,19 @@ EXCLUDED AGENTS: (none)
You must create a visible claim before doing any work. This claim is a **distributed lock** that prevents agents on other platforms (Claude Code, Codex, Jules) from picking up the same task.
### 2a. Create your working branch and claim via draft PR
### 2a. Create your working branch and push a claim
1. Create your working branch.
2. Make a minimal initial commit (e.g., create a new `context/CONTEXT_<timestamp>.md` with the task scope).
3. Push the branch and open a **draft PR**:
```bash
gh pr create --draft \
--title "[daily] <agent-name>: <brief task description>" \
--body "Claimed by daily scheduler at $(date -u +%Y-%m-%dT%H:%M:%SZ). Work in progress."
```
4. Verify the draft PR was created successfully before proceeding.
3. Push the branch immediately to make it visible to other agents.
### 2b. Race condition check
After creating the draft PR, immediately re-check:
After pushing, re-check for competing claims:
```bash
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt --limit 100 | grep -i "<agent-name>"
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq '{count: length, titles: [.[].title]}'
```
If you see another PR for this agent that was created *before* yours (by a different agent instance), close your PR with `gh pr close <your-pr-number>` and go back to Step 1 to select the next agent.
If you see another PR for this agent that was created *before* yours, abandon your branch and go back to Step 1 to select the next agent.
### 2c. Log "started" in the task log immediately
@@ -209,7 +198,7 @@ Use the current UTC timestamp. The file content should be:
Commit and push this log file to your branch. This `started` entry serves as a secondary lock: other scheduler instances will see it and skip this agent.
**If `gh` is unavailable:** You MUST still create the `started` log file and push it. The log file is your minimum viable claim.
**The `started` log file is your primary claim mechanism.** Push it immediately so other agents can see it.
---
@@ -279,7 +268,7 @@ Use the current UTC timestamp (which will be later than the `started` file). The
- If the agent prompt file is **empty or missing**, skip it, log the run as `failed` with summary `"Prompt file empty or missing"`, and proceed to the **next agent** in the roster.
- If a task **fails mid-execution** (test failures, build errors), log the run as `failed` with a summary describing the failure. Still commit the log file and any partial artifacts.
- If the task log directory is **missing**, create it: `mkdir -p docs/agents/task-logs/daily/`.
- If `gh` or `curl` is **unavailable or errors**, fall back to log-file-only claiming (the `started` file). Log a warning in your summary that PR-based claim checking was degraded.
- If `curl` or `jq` is **unavailable or errors**, fall back to log-file-only claiming (the `started` file). Log a warning in your summary that PR-based claim checking was degraded.
---
@@ -287,9 +276,9 @@ Use the current UTC timestamp (which will be later than the `started` file). The
| Layer | Mechanism | Catches |
|-------|-----------|---------|
| **Pre-flight gate** | Scan ALL open `[daily]` PRs via `gh`/`curl` | Agents claimed by any platform |
| **Pre-flight gate** | Scan ALL open `[daily]` PRs via `curl` | Agents claimed by any platform |
| **Pre-flight gate** | Check task log dir for `started` files | Agents in progress (even without PR) |
| **Step 2a** | Create draft PR as lock | Cross-platform visibility |
| **Step 2a** | Push branch with claim commit | Cross-platform visibility |
| **Step 2b** | Race condition re-check | Simultaneous claims |
| **Step 2c** | Create `started` log file immediately | Crash recovery — rotation advances |
@@ -77,7 +77,7 @@ WORKFLOW
2) CI health check (evidence gathering)
- Gather recent CI run results using one of:
- GitHub Actions UI/manual inspection, OR
- GitHub API / `gh` CLI (only if available; do not assume).
- GitHub API via `curl` (e.g., `curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/actions/runs?per_page=20"`).
- Identify candidate flakes:
- same test fails on one run but passes on another with no relevant code change
- failures are timing-related, network-mocking-related, ordering-related
+13 -24
View File
@@ -76,17 +76,12 @@ If you arrived here from the meta prompt and already ran these commands and past
Run this command:
```bash
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt,author --limit 100 | grep -i "\[weekly\]"
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq '{count: length, titles: [.[].title]}'
```
If `gh` is unavailable, use this fallback:
```bash
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | grep -o '"title":"[^"]*\[weekly\][^"]*"'
```
**Paste the complete raw output.** If the command returns nothing or errors, write: `OUTPUT: (empty — no results)`
**Paste the complete raw output.** If the command returns nothing, write: `OUTPUT: (empty — no results)`
Every agent name that appears in these PR titles is **OFF LIMITS** — do not select it.
Review the titles in the output. Every agent name that appears in a PR title containing `[weekly]` is **OFF LIMITS** — do not select it.
### COMMAND 2 — Check the task log for incomplete runs
@@ -114,7 +109,7 @@ or:
EXCLUDED AGENTS: (none)
```
**If Command 1 failed** (network error, API limit, `gh`/`curl` unavailable): you MUST still check the task log directory (Command 2). Log a warning in your summary that PR-based claim checking was unavailable.
**If Command 1 failed** (network error, API rate limit, `curl`/`jq` unavailable): you MUST still check the task log directory (Command 2). Log a warning in your summary that PR-based claim checking was unavailable.
**Do not proceed to Step 1 until you have pasted command outputs and written your exclusion list.**
@@ -159,25 +154,19 @@ EXCLUDED AGENTS: (none)
You must create a visible claim before doing any work. This claim is a **distributed lock** that prevents agents on other platforms (Claude Code, Codex, Jules) from picking up the same task.
### 2a. Create your working branch and claim via draft PR
### 2a. Create your working branch and push a claim
1. Create your working branch.
2. Make a minimal initial commit (e.g., create a new `context/CONTEXT_<timestamp>.md` with the task scope).
3. Push the branch and open a **draft PR**:
```bash
gh pr create --draft \
--title "[weekly] <agent-name>: <brief task description>" \
--body "Claimed by weekly scheduler at $(date -u +%Y-%m-%dT%H:%M:%SZ). Work in progress."
```
4. Verify the draft PR was created successfully before proceeding.
3. Push the branch immediately to make it visible to other agents.
### 2b. Race condition check
After creating the draft PR, immediately re-check:
After pushing, re-check for competing claims:
```bash
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt --limit 100 | grep -i "<agent-name>"
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq '{count: length, titles: [.[].title]}'
```
If you see another PR for this agent that was created *before* yours (by a different agent instance), close your PR with `gh pr close <your-pr-number>` and go back to Step 1 to select the next agent.
If you see another PR for this agent that was created *before* yours, abandon your branch and go back to Step 1 to select the next agent.
### 2c. Log "started" in the task log immediately
@@ -204,7 +193,7 @@ Use the current UTC timestamp. The file content should be:
Commit and push this log file to your branch. This `started` entry serves as a secondary lock: other scheduler instances will see it and skip this agent.
**If `gh` is unavailable:** You MUST still create the `started` log file and push it. The log file is your minimum viable claim.
**The `started` log file is your primary claim mechanism.** Push it immediately so other agents can see it.
---
@@ -276,7 +265,7 @@ Use the current UTC timestamp (which will be later than the `started` file). The
- If the agent prompt file is **empty or missing**, skip it, log the run as `failed` with summary `"Prompt file empty or missing"`, and proceed to the **next agent** in the roster.
- If a task **fails mid-execution** (test failures, build errors), log the run as `failed` with a summary describing the failure. Still commit the log file and any partial artifacts.
- If the task log directory is **missing**, create it: `mkdir -p docs/agents/task-logs/weekly/`.
- If `gh` or `curl` is **unavailable or errors**, fall back to log-file-only claiming (the `started` file). Log a warning in your summary that PR-based claim checking was degraded.
- If `curl` or `jq` is **unavailable or errors**, fall back to log-file-only claiming (the `started` file). Log a warning in your summary that PR-based claim checking was degraded.
---
@@ -284,9 +273,9 @@ Use the current UTC timestamp (which will be later than the `started` file). The
| Layer | Mechanism | Catches |
|-------|-----------|---------|
| **Pre-flight gate** | Scan ALL open `[weekly]` PRs via `gh`/`curl` | Agents claimed by any platform |
| **Pre-flight gate** | Scan ALL open `[weekly]` PRs via `curl` | Agents claimed by any platform |
| **Pre-flight gate** | Check task log dir for `started` files | Agents in progress (even without PR) |
| **Step 2a** | Create draft PR as lock | Cross-platform visibility |
| **Step 2a** | Push branch with claim commit | Cross-platform visibility |
| **Step 2b** | Race condition re-check | Simultaneous claims |
| **Step 2c** | Create `started` log file immediately | Crash recovery — rotation advances |
@@ -128,7 +128,7 @@ PR METADATA (PR number, author) — RULES
Only include PR number and author if you can **verify** them via:
- merge commit messages that include PR numbers, OR
- an available local tool/config that exposes PR metadata (e.g., `gh`)
- the GitHub API via `curl` (e.g., `curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=closed&per_page=50" | jq '[.[] | {number, title, merged_at: .merged_at}]'`)
If not verifiable:
- omit PR numbers/authors and keep bullets keyed to commit subjects/hashes.
@@ -73,21 +73,22 @@ WORKFLOW
- security-sensitive boundaries and logging policy
- Confirm tooling availability:
- `npm` available
- PR checkout method available (`gh` CLI or equivalent)
If `gh` is not available, fall back to manual instructions in the audit log.
- `curl` and `jq` available for GitHub API queries
If `curl` is not available, document that PR enumeration was not possible in the audit log.
2) Enumerate open PRs
- Preferred: `curl` command (works without gh auth):
```bash
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq -c '.[] | {number: .number, title: .title, created_at: .created_at, author: .user.login}'
```
- Alternative: `gh pr list` (if available/configured).
- Otherwise: document that PR enumeration was not possible in this environment.
3) For each PR: checkout and run verification
Checkout:
- Preferred: `gh pr checkout <num>`
- Otherwise: fetch the PR branch via git remote refs (only if you can verify).
- Fetch the PR branch via git remote refs:
```bash
git fetch origin pull/<num>/head:pr-<num> && git checkout pr-<num>
```
Install + checks (verify the script names first):
- `npm ci` (preferred) or `npm install` if CI install is not supported
@@ -76,11 +76,16 @@ WORKFLOW
- Gather branch refs:
- `git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short)' refs/heads/ai`
Optional method (only if tooling is available and policy allows):
- Use `gh` CLI or other configured tooling to fetch:
- PR links/status
- issue links/priorities
If not available: do not guess links; report locally-derived identifiers.
Optional method (use curl to query the GitHub API):
- Fetch open PRs:
```
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq '{count: length, titles: [.[].title]}'
```
- Fetch recently closed/merged PRs:
```
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=closed&per_page=50&sort=updated&direction=desc" | jq '[.[] | {title: .title, merged: .merged_at, number: .number}]'
```
If curl is unavailable: do not guess links; report locally-derived identifiers.
3) Normalize items into report sections
For each item discovered, capture: