|
| 1 | +--- |
| 2 | +name: review-loop |
| 3 | +description: Submit code for automated review via Command Center. Triggers build verification, quality checks, and merge readiness analysis. Iterates on feedback until merge-ready. |
| 4 | +argument-hint: [optional description of what the code does] |
| 5 | +--- |
| 6 | + |
| 7 | +# Review Loop Skill |
| 8 | + |
| 9 | +You are an autonomous coding agent running a review loop. You trigger Command Center's review pipeline, wait for results, fix any blocking issues yourself, and repeat until the PR is merge-ready. |
| 10 | + |
| 11 | +**IMPORTANT: This is a loop. You MUST keep going until the review passes or max attempts are exhausted. Do NOT stop after receiving feedback — fix the issues and re-trigger.** |
| 12 | + |
| 13 | +## Phase 1: Setup & Context Detection |
| 14 | + |
| 15 | +1. Resolve configuration. Check these sources in order for each value: |
| 16 | + |
| 17 | + **APP_URL** (Command Center endpoint): |
| 18 | + - Default: `https://command-center.aigora.ai` |
| 19 | + - Override: `CC_APP_URL` env var, or `APP_URL` in `.env.local` |
| 20 | + |
| 21 | + **API_SECRET** (service-to-service auth): |
| 22 | + - Shell env var: `CC_API_SECRET` |
| 23 | + - Fallback: `INTERNAL_API_SECRET` in `.env.local` |
| 24 | + - If neither exists, tell the user to set `CC_API_SECRET` in their shell profile and stop. |
| 25 | + |
| 26 | + ```bash |
| 27 | + # Read CC_API_SECRET from env, fall back to .env.local |
| 28 | + echo "${CC_API_SECRET:-$(grep INTERNAL_API_SECRET .env.local 2>/dev/null | cut -d= -f2-)}" |
| 29 | + ``` |
| 30 | + |
| 31 | +2. Detect repo and branch from git: |
| 32 | + ```bash |
| 33 | + git remote get-url origin 2>/dev/null | sed 's|.*github.com[:/]||;s|\.git$||' |
| 34 | + ``` |
| 35 | + ```bash |
| 36 | + git branch --show-current |
| 37 | + ``` |
| 38 | + |
| 39 | +3. Find the PR number: |
| 40 | + ```bash |
| 41 | + gh pr view --json number -q .number 2>/dev/null |
| 42 | + ``` |
| 43 | + If no PR exists, tell the user to open a PR first and stop. |
| 44 | + |
| 45 | +4. Build the prompt text. Check these sources in order: |
| 46 | + - If the user provided `$ARGUMENTS`, use that as the prompt. |
| 47 | + - Otherwise, look for a plan file in `docs/plans/` or `.ai-docs/plans/` that mentions the branch name. |
| 48 | + - Otherwise, read the PR body: `gh pr view --json body -q .body` |
| 49 | + - If nothing useful is found, use a generic prompt: "Review the code changes on this branch for quality and merge readiness." |
| 50 | + |
| 51 | +## Phase 2: Trigger the Review |
| 52 | + |
| 53 | +Call the trigger API using `curl`. Use `python3 -c "import sys,json; ..."` for JSON parsing (jq may not be available). |
| 54 | + |
| 55 | +```bash |
| 56 | +curl -s -X POST "${APP_URL}/api/orchestration/trigger" \ |
| 57 | + -H "Content-Type: application/json" \ |
| 58 | + -H "x-internal-api-secret: ${API_SECRET}" \ |
| 59 | + -d '{"action":"start","repo":"REPO","branch":"BRANCH","prNumber":PR_NUM,"prompt":"PROMPT_TEXT"}' |
| 60 | +``` |
| 61 | + |
| 62 | +Extract `sessionId` from the JSON response using python3. If the response contains an error, show it and stop. |
| 63 | + |
| 64 | +Tell the user: "Review triggered (session: SESSION_ID). Waiting for results..." |
| 65 | + |
| 66 | +## Phase 3: Poll for Results |
| 67 | + |
| 68 | +Poll the status endpoint. **Wait 30 seconds between polls.** Use `sleep 30` between each curl call. |
| 69 | + |
| 70 | +```bash |
| 71 | +curl -s "${APP_URL}/api/orchestration/status?repo=REPO&sessionId=SESSION_ID&orgId=legacy-default" \ |
| 72 | + -H "x-internal-api-secret: ${API_SECRET}" |
| 73 | +``` |
| 74 | + |
| 75 | +Parse the JSON response with python3. Check `state.phase`: |
| 76 | + |
| 77 | +- `completed` → Go to Phase 4 (success) |
| 78 | +- `failed` → Go to Phase 4 (failure) |
| 79 | +- `executing` AND the logs mention "waiting for fix" → Go to Phase 5 (fix issues) |
| 80 | +- Anything else → Show the current phase and latest log message, then poll again after 30s |
| 81 | + |
| 82 | +**Keep polling until you reach one of the above terminal/actionable states.** Do NOT give up after a few polls. |
| 83 | + |
| 84 | +## Phase 4: Terminal States |
| 85 | + |
| 86 | +### Success (phase=completed) |
| 87 | +Tell the user: |
| 88 | +- The review passed |
| 89 | +- Show the PR URL |
| 90 | +- Show any non-blocking warnings from `state.lastMergeResult.warnings` |
| 91 | +- The PR is ready for human review and merge |
| 92 | + |
| 93 | +### Failure (phase=failed) |
| 94 | +Tell the user: |
| 95 | +- Show `state.error` |
| 96 | +- Show what's still failing from `state.lastQualityResult` and `state.lastMergeResult` |
| 97 | +- Suggest manual fixes if max rework attempts were exhausted |
| 98 | + |
| 99 | +## Phase 5: Fix Blocking Issues (THE CORE LOOP) |
| 100 | + |
| 101 | +**This is the most important phase. You are an autonomous agent — fix the issues yourself.** |
| 102 | + |
| 103 | +1. **Extract findings** from the status response: |
| 104 | + - `state.lastMergeResult.blockingIssues` — array of blocking issue descriptions |
| 105 | + - `state.lastMergeResult.summary` — detailed markdown summary with findings |
| 106 | + - `state.lastQualityResult.findings` — quality check findings text |
| 107 | + |
| 108 | +2. **Read and understand each blocking issue.** Common issue types: |
| 109 | + - **Code bugs** (e.g., case-sensitivity, missing error handling) → Fix the code |
| 110 | + - **Documentation updates** (e.g., "TODO.md needs update", "CLAUDE.md needs update") → Update the docs |
| 111 | + - **Skeleton regeneration** → Run `pnpm regen-skeleton` if available |
| 112 | + - **Test failures** → Fix the failing tests |
| 113 | + |
| 114 | +3. **Fix each issue** using your normal code editing tools (Read, Edit, Write). Do thorough fixes — don't just add comments or TODOs. |
| 115 | + |
| 116 | +4. **Commit and push** the fixes: |
| 117 | + ```bash |
| 118 | + git add <specific-files-you-changed> |
| 119 | + ``` |
| 120 | + ```bash |
| 121 | + git commit -m "fix: address review feedback - <brief description>" |
| 122 | + ``` |
| 123 | + ```bash |
| 124 | + git push |
| 125 | + ``` |
| 126 | + |
| 127 | +5. **Wait 3 minutes for CI and bot reviews** to process the new commit. Bot reviewers on the PR need time to analyze the push before Command Center re-reviews: |
| 128 | + ```bash |
| 129 | + sleep 180 |
| 130 | + ``` |
| 131 | + |
| 132 | +6. **Nudge the orchestrator** to re-review: |
| 133 | + ```bash |
| 134 | + curl -s -X POST "${APP_URL}/api/orchestration/trigger" \ |
| 135 | + -H "Content-Type: application/json" \ |
| 136 | + -H "x-internal-api-secret: ${API_SECRET}" \ |
| 137 | + -d '{"action":"fix_pushed","sessionId":"SESSION_ID"}' |
| 138 | + ``` |
| 139 | + |
| 140 | +7. **Go back to Phase 3** (poll again). The orchestrator will re-run build verification, quality check, and merge readiness on your new code. |
| 141 | + |
| 142 | +**Repeat Phase 3→5 until the review passes or fails permanently.** |
| 143 | + |
| 144 | +## Important Notes |
| 145 | + |
| 146 | +- **Do NOT use `jq`** — it may not be available. Use `python3 -c "import sys,json; data=json.load(sys.stdin); print(data['key'])"` for JSON parsing. |
| 147 | +- **Do NOT run long-lived bash loops** — poll by making individual curl calls with `sleep 30` between them. |
| 148 | +- **Always push before nudging** — the orchestrator checks the latest commit on the branch. |
| 149 | +- **Be thorough with fixes** — superficial fixes will just fail the next review cycle. |
| 150 | +- **Max 3 rework cycles** — after that the orchestrator gives up. Make each fix count. |
0 commit comments