Loading...
Loading...
Use when user requests autonomous operation across multiple issues. Orchestrates parallel workers, monitors progress, handles SLEEP/WAKE cycles, and works until scope is complete without user intervention.
npx skill4agent add troykelly/codex-skills autonomous-orchestrationworker-dispatchworker-protocolci-monitoringgh| State Store | Purpose | Used For |
|---|---|---|
| Project Board Status | THE source of truth | Ready, In Progress, In Review, Blocked, Done |
| Issue Comments | Activity log | Worker assignment, progress, deviations |
| Labels | Lineage only | |
| MCP Memory | Fast cache + active marker | Read optimization, active orchestration detection |
reference/state-management.md# Write to MCP Memory when orchestration starts
mcp__memory__create_entities([{
"name": "ActiveOrchestration",
"entityType": "Orchestration",
"observations": [
"Status: ACTIVE",
"Scope: [MILESTONE/EPIC/unbounded]",
"Tracking Issue: #[NUMBER]",
"Started: [ISO_TIMESTAMP]",
"Repository: [owner/repo]",
"Phase: BOOTSTRAP|MAIN_LOOP",
"Last Loop: [ISO_TIMESTAMP]"
]
}])mcp__memory__add_observations({
"observations": [{
"entityName": "ActiveOrchestration",
"contents": ["Last Loop: [ISO_TIMESTAMP]", "Phase: MAIN_LOOP"]
}]
})mcp__memory__delete_entities({
"entityNames": ["ActiveOrchestration"]
})# Check MCP Memory for active orchestration
ACTIVE=$(mcp__memory__open_nodes({"names": ["ActiveOrchestration"]}))
if [ -n "$ACTIVE" ]; then
echo "⚠️ ACTIVE ORCHESTRATION DETECTED"
echo "Scope: [from ACTIVE]"
echo "Tracking: [from ACTIVE]"
echo ""
echo "Resuming orchestration loop..."
# Invoke autonomous-orchestration skill to resume
fi## Starting Autonomous Operation
**Scope:** [MILESTONE/EPIC/ISSUES or "all open issues"]
**Workers:** Up to 5 parallel
**Mode:** Continuous until complete
Beginning work now...priority:urgentpriority:highdetect_work_scope() {
# 1. Check for urgent/high priority standalone issues first
PRIORITY_ISSUES=$(gh issue list --state open \
--label "priority:urgent,priority:high" \
--json number,labels \
--jq '[.[] | select(.labels | map(.name) | any(startswith("epic-")) | not)] | .[].number')
if [ -n "$PRIORITY_ISSUES" ]; then
echo "priority_standalone"
echo "$PRIORITY_ISSUES"
return
fi
# 2. Get epics in order (by creation date)
EPICS=$(gh issue list --state open --label "type:epic" \
--json number,title,createdAt \
--jq 'sort_by(.createdAt) | .[].number')
if [ -n "$EPICS" ]; then
echo "epics"
echo "$EPICS"
return
fi
# 3. Fall back to all open issues
ALL_ISSUES=$(gh issue list --state open --json number --jq '.[].number')
echo "all_issues"
echo "$ALL_ISSUES"
}┌──────────────────────────────────────────────────────────┐
│ BOOTSTRAP PHASE │
│ (Runs ONCE before main loop) │
└─────────────────────────┬────────────────────────────────┘
│
▼
┌───────────────────┐
│ GET OPEN PRs │
│ │
│ Filter out: │
│ - release/* │
│ - release- │
│ placeholder │
└─────────┬─────────┘
│
┌──────────┴──────────┐
▼ ▼
┌───────────┐ ┌───────────┐
│ Has PRs? │─── No ──│ → MAIN │
│ │ │ LOOP │
└─────┬─────┘ └───────────┘
│ Yes
▼
┌───────────────────────────────┐
│ FOR EACH PR: │
│ │
│ 1. Check CI status │
│ 2. Verify review artifact │
│ 3. Merge if ready OR │
│ 4. Wait/fix if not │
└───────────────────────────────┘
│
▼
MAIN LOOPresolve_existing_prs() {
echo "=== PR RESOLUTION BOOTSTRAP ==="
# Get all open PRs, excluding release placeholders
OPEN_PRS=$(gh pr list --json number,headRefName,labels \
--jq '[.[] | select(
(.headRefName | startswith("release/") | not) and
(.labels | map(.name) | index("release-placeholder") | not)
)] | .[].number')
if [ -z "$OPEN_PRS" ]; then
echo "No actionable PRs to resolve. Proceeding to main loop."
return 0
fi
echo "Found PRs to resolve: $OPEN_PRS"
for pr in $OPEN_PRS; do
echo "Processing PR #$pr..."
# Get CI status
ci_status=$(gh pr checks "$pr" --json state --jq '.[].state' 2>/dev/null | sort -u)
# Get linked issue
ISSUE=$(gh pr view "$pr" --json body --jq '.body' | grep -oE 'Closes #[0-9]+' | grep -oE '[0-9]+' | head -1)
if [ -z "$ISSUE" ]; then
echo " ⚠ No linked issue found, skipping"
continue
fi
# Check if CI passed
if echo "$ci_status" | grep -q "FAILURE"; then
echo " ❌ CI failing - triggering ci-monitoring for PR #$pr"
# Invoke ci-monitoring skill to fix
handle_ci_failure "$pr"
continue
fi
if echo "$ci_status" | grep -q "PENDING"; then
echo " ⏳ CI pending for PR #$pr, will check in main loop"
continue
fi
if echo "$ci_status" | grep -q "SUCCESS"; then
# Verify review artifact
REVIEW_EXISTS=$(gh api "/repos/$OWNER/$REPO/issues/$ISSUE/comments" \
--jq '[.[] | select(.body | contains("<!-- REVIEW:START -->"))] | length' 2>/dev/null || echo "0")
if [ "$REVIEW_EXISTS" = "0" ]; then
echo " ⚠ No review artifact - requesting review for #$ISSUE"
gh issue comment "$ISSUE" --body "## Review Required
PR #$pr has passing CI but no review artifact.
**Action needed:** Complete comprehensive-review and post artifact to this issue.
---
*Bootstrap phase - Orchestrator*"
continue
fi
# All checks pass - merge
echo " ✅ Merging PR #$pr"
gh pr merge "$pr" --squash --delete-branch
mark_issue_done "$ISSUE"
fi
done
echo "=== BOOTSTRAP COMPLETE ==="
}| Condition | Example |
|---|---|
Branch starts with | |
Has | Manual exclusion |
Has | Explicit hold |
┌──────────────────────────────────────────────────────────┐
│ MAIN LOOP │
└─────────────────────────┬────────────────────────────────┘
│
┌───────────────────┼───────────────────┐
▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────┐
│ CHECK │ │ CHECK │ │ SPAWN │
│ WORKERS │ │ CI/PRs │ │ WORKERS │
└─────┬─────┘ └─────┬─────┘ └─────┬─────┘
│ │ │
└──────────────────┼──────────────────┘
│
▼
┌───────────────────┐
│ EVALUATE STATE │
│ │
│ All done? → Exit │
│ Waiting? → SLEEP │
│ Work? → Continue │
└───────────────────┘reference/loop-implementation.md# In each loop iteration
for pr in $(gh pr list --json number,statusCheckRollup --jq '.[] | select(.statusCheckRollup | all(.conclusion == "SUCCESS")) | .number'); do
# Check for do-not-merge label
if ! gh pr view "$pr" --json labels --jq '.labels[].name' | grep -q "do-not-merge"; then
echo "Merging PR #$pr (CI passed)"
gh pr merge "$pr" --squash --delete-branch
# Get linked issue and mark done
ISSUE=$(gh pr view "$pr" --json body --jq '.body' | grep -oE 'Closes #[0-9]+' | grep -oE '[0-9]+' | head -1)
if [ -n "$ISSUE" ]; then
# Update project board status to Done
mark_issue_done "$ISSUE"
fi
fi
donegh issue list --milestone "v1.0.0" --state open --json number --jq '.[].number'gh issue list --label "epic-dark-mode" --state open --json number --jq '.[].number'gh issue list --state open --json number --jq '.[].number'Attempt 1 → Research → Attempt 2 → Research → Attempt 3 → Research → Attempt 4 → BLOCKEDreference/failure-recovery.mdcodex resume [SESSION_ID]git worktree listgh auth statusorchestration-trackingrelease/*release-placeholderdo-not-mergeissue-driven-developmentspawned-from:#N| Skill | Purpose |
|---|---|
| Spawning workers |
| Worker behavior |
| Context passing |
| CI and WAKE handling |
| Research cycles |
| Worker follows this |
| Workers must complete before PR |
| ALL state queries and updates |
reference/state-management.mdreference/loop-implementation.mdreference/failure-recovery.md