|
| 1 | +name: archon-smart-mr-review |
| 2 | +description: | |
| 3 | + Use when: User wants an efficient code review of a GitLab MR — adaptive to complexity. |
| 4 | + Triggers: "smart review", "review MR !123", "smart mr review", "efficient review", |
| 5 | + "quick review mr", "review and approve gitlab", "gitlab smart review". |
| 6 | + Does: Loads MR → Haiku classifies MR complexity + which agents are relevant → |
| 7 | + only relevant review agents run → consolidates → |
| 8 | + posts Discussion threads (resolvable) → approves on 0 Critical → |
| 9 | + adds reviewer → sets commit status. |
| 10 | + NOT for: When ALL review agents are wanted (use archon-comprehensive-mr-review), |
| 11 | + bug fixes with issue-ref (use archon-fix-gitlab-issue), |
| 12 | + MRs you just built (idea-to-mr / plan-to-mr review inline). |
| 13 | +
|
| 14 | + GitLab counterpart to `archon-smart-pr-review`. |
| 15 | + Posting pattern: Discussion threads per 🔴 Critical, auto-approval on 0 Critical, |
| 16 | + reviewer assignment, commit status `ai-code-review`. |
| 17 | +
|
| 18 | + Smart-routing examples: |
| 19 | + - 3-line typo fix → only code-review, skip test-coverage + docs-impact |
| 20 | + - Renovate update → only code-review (with dependency logic) + docs-impact |
| 21 | + - Refactor with new APIs → code-review + error-handling + test-coverage + docs-impact |
| 22 | +
|
| 23 | + ⚠️ WARNING: Posts REAL comments + Discussion threads on the MR, |
| 24 | + approves the MR (on 0 Critical), and assigns itself as reviewer. |
| 25 | + Makes NO code changes on the MR (no self-fix). |
| 26 | +
|
| 27 | + Prerequisites: |
| 28 | + - `glab auth status` shows logged in |
| 29 | + - Access to the MR (read + comment + approve) |
| 30 | + - Optional: ENV `ARCHON_GITLAB_REVIEWER` (default: `ai-agent`) |
| 31 | +
|
| 32 | + Input: MR reference in user input — see archon-comprehensive-mr-review. |
| 33 | +
|
| 34 | +provider: claude |
| 35 | +model: sonnet |
| 36 | + |
| 37 | +nodes: |
| 38 | + # ═══════════════════════════════════════════════════════════════ |
| 39 | + # PHASE 1: LOAD MR |
| 40 | + # ═══════════════════════════════════════════════════════════════ |
| 41 | + |
| 42 | + - id: fetch-mr |
| 43 | + command: archon-gitlab-mr-fetch |
| 44 | + context: fresh |
| 45 | + |
| 46 | + # ═══════════════════════════════════════════════════════════════ |
| 47 | + # PHASE 2: SCOPE |
| 48 | + # ═══════════════════════════════════════════════════════════════ |
| 49 | + |
| 50 | + - id: review-scope |
| 51 | + command: archon-gitlab-review-scope |
| 52 | + depends_on: [fetch-mr] |
| 53 | + context: fresh |
| 54 | + |
| 55 | + # ═══════════════════════════════════════════════════════════════ |
| 56 | + # PHASE 3: CLASSIFICATION (Haiku) |
| 57 | + # ═══════════════════════════════════════════════════════════════ |
| 58 | + |
| 59 | + - id: classify |
| 60 | + prompt: | |
| 61 | + You are an MR complexity classifier for GitLab repos. |
| 62 | + Analyze the MR scope below and decide which review agents should run. |
| 63 | +
|
| 64 | + ## MR Scope |
| 65 | +
|
| 66 | + $review-scope.output |
| 67 | +
|
| 68 | + ## Rules |
| 69 | +
|
| 70 | + - **code_review**: ALWAYS `true` unless the diff is empty or touches only |
| 71 | + non-code files (README-only, config-only, .yaml-only without code). |
| 72 | + - **error_handling**: `true` when the diff touches code with try/except, |
| 73 | + error handling, async/await, or new failure paths. |
| 74 | + - **test_coverage**: `true` when the diff touches source code |
| 75 | + (not just tests/docs/config). |
| 76 | + - **comment_quality**: `true` when the diff adds/changes comments, docstrings, |
| 77 | + JSDoc, or significant inline documentation in code files. |
| 78 | + - **docs_impact**: `true` when the diff adds/removes/renames public APIs, |
| 79 | + commands, CLI flags, ENV variables, or user-facing features. |
| 80 | + ALSO on CLAUDE.md/README/docs/ changes. |
| 81 | +
|
| 82 | + ## Special cases |
| 83 | +
|
| 84 | + - **Renovate / dependency update** (major/minor/patch bump in package.json, |
| 85 | + requirements.txt, go.mod, Docker tags etc.): code_review = true with focus |
| 86 | + on breaking-changes risk. test_coverage = false. error_handling = false. |
| 87 | + docs_impact = true if user-facing. |
| 88 | + - **Pure renaming / move** without logic change: code_review = true, |
| 89 | + rest false. |
| 90 | + - **Test-file-only updates**: test_coverage = false (they ARE tests), |
| 91 | + code_review = true. |
| 92 | +
|
| 93 | + Classify the complexity: |
| 94 | + - **trivial**: typo fixes, formatting, single-line, patch version bumps |
| 95 | + - **small**: 1–3 files, simple logic, no architectural changes |
| 96 | + - **medium**: 4–10 files, moderate logic changes, some cross-cutting |
| 97 | + - **large**: 10+ files, architectural changes, new subsystems, |
| 98 | + complex refactors, major version bumps |
| 99 | +
|
| 100 | + Reasoning should be in English and briefly explain which agents run and why. |
| 101 | + depends_on: [review-scope] |
| 102 | + model: haiku |
| 103 | + allowed_tools: [] |
| 104 | + output_format: |
| 105 | + type: object |
| 106 | + properties: |
| 107 | + run_code_review: |
| 108 | + type: string |
| 109 | + enum: ["true", "false"] |
| 110 | + run_error_handling: |
| 111 | + type: string |
| 112 | + enum: ["true", "false"] |
| 113 | + run_test_coverage: |
| 114 | + type: string |
| 115 | + enum: ["true", "false"] |
| 116 | + run_comment_quality: |
| 117 | + type: string |
| 118 | + enum: ["true", "false"] |
| 119 | + run_docs_impact: |
| 120 | + type: string |
| 121 | + enum: ["true", "false"] |
| 122 | + complexity: |
| 123 | + type: string |
| 124 | + enum: ["trivial", "small", "medium", "large"] |
| 125 | + reasoning: |
| 126 | + type: string |
| 127 | + required: |
| 128 | + - run_code_review |
| 129 | + - run_error_handling |
| 130 | + - run_test_coverage |
| 131 | + - run_comment_quality |
| 132 | + - run_docs_impact |
| 133 | + - complexity |
| 134 | + - reasoning |
| 135 | + |
| 136 | + # ═══════════════════════════════════════════════════════════════ |
| 137 | + # PHASE 4: CONDITIONAL REVIEW AGENTS |
| 138 | + # ═══════════════════════════════════════════════════════════════ |
| 139 | + |
| 140 | + - id: code-review |
| 141 | + command: archon-gitlab-code-review-agent |
| 142 | + depends_on: [classify, review-scope] |
| 143 | + when: "$classify.output.run_code_review == 'true'" |
| 144 | + context: fresh |
| 145 | + |
| 146 | + - id: error-handling |
| 147 | + command: archon-gitlab-error-handling-agent |
| 148 | + depends_on: [classify, review-scope] |
| 149 | + when: "$classify.output.run_error_handling == 'true'" |
| 150 | + context: fresh |
| 151 | + |
| 152 | + - id: test-coverage |
| 153 | + command: archon-gitlab-test-coverage-agent |
| 154 | + depends_on: [classify, review-scope] |
| 155 | + when: "$classify.output.run_test_coverage == 'true'" |
| 156 | + context: fresh |
| 157 | + |
| 158 | + - id: comment-quality |
| 159 | + command: archon-gitlab-comment-quality-agent |
| 160 | + depends_on: [classify, review-scope] |
| 161 | + when: "$classify.output.run_comment_quality == 'true'" |
| 162 | + context: fresh |
| 163 | + |
| 164 | + - id: docs-impact |
| 165 | + command: archon-gitlab-docs-impact-agent |
| 166 | + depends_on: [classify, review-scope] |
| 167 | + when: "$classify.output.run_docs_impact == 'true'" |
| 168 | + context: fresh |
| 169 | + |
| 170 | + # ═══════════════════════════════════════════════════════════════ |
| 171 | + # PHASE 5: CONSOLIDATE |
| 172 | + # ═══════════════════════════════════════════════════════════════ |
| 173 | + |
| 174 | + - id: synthesize |
| 175 | + command: archon-gitlab-synthesize-review |
| 176 | + depends_on: [code-review, error-handling, test-coverage, comment-quality, docs-impact] |
| 177 | + trigger_rule: one_success |
| 178 | + context: fresh |
| 179 | + |
| 180 | + # ═══════════════════════════════════════════════════════════════ |
| 181 | + # PHASE 6: GITLAB ACTIONS (Threads + Approval + Reviewer) |
| 182 | + # ═══════════════════════════════════════════════════════════════ |
| 183 | + |
| 184 | + - id: post-review |
| 185 | + command: archon-gitlab-post-review |
| 186 | + depends_on: [synthesize] |
| 187 | + context: fresh |
| 188 | + |
| 189 | + # ═══════════════════════════════════════════════════════════════ |
| 190 | + # PHASE 7: SUMMARY |
| 191 | + # ═══════════════════════════════════════════════════════════════ |
| 192 | + |
| 193 | + - id: summary |
| 194 | + bash: | |
| 195 | + set -euo pipefail |
| 196 | +
|
| 197 | + MR_IID=$(cat "$ARTIFACTS_DIR/.mr-iid" 2>/dev/null || echo "—") |
| 198 | + MR_URL=$(cat "$ARTIFACTS_DIR/.mr-url" 2>/dev/null || echo "—") |
| 199 | +
|
| 200 | + echo "═════════════════════════════════════════════════════════════" |
| 201 | + echo " archon-smart-mr-review — DONE" |
| 202 | + echo "═════════════════════════════════════════════════════════════" |
| 203 | + echo " MR: !${MR_IID}" |
| 204 | + echo " URL: ${MR_URL}" |
| 205 | + echo "" |
| 206 | +
|
| 207 | + echo "─── Classification ───" |
| 208 | + if [ -f "$ARTIFACTS_DIR/review/scope.md" ]; then |
| 209 | + echo " (see scope.md)" |
| 210 | + fi |
| 211 | + echo "" |
| 212 | +
|
| 213 | + echo "─── Active review agents ───" |
| 214 | + for f in "$ARTIFACTS_DIR/review/"*-findings.md; do |
| 215 | + [ -f "$f" ] && { |
| 216 | + BASE=$(basename "$f" -findings.md) |
| 217 | + COUNT=$(grep -cE "^#{3}? Finding " "$f" 2>/dev/null || echo "?") |
| 218 | + echo " ${BASE}: ${COUNT} findings" |
| 219 | + } |
| 220 | + done |
| 221 | + echo "" |
| 222 | +
|
| 223 | + echo "─── Posting ───" |
| 224 | + if [ -f "$ARTIFACTS_DIR/review/findings-parsed.json" ]; then |
| 225 | + CRIT=$(jq -r '[.[] | select(.severity | startswith("🔴"))] | length' "$ARTIFACTS_DIR/review/findings-parsed.json" 2>/dev/null || echo "?") |
| 226 | + WARN=$(jq -r '[.[] | select(.severity | startswith("🟡"))] | length' "$ARTIFACTS_DIR/review/findings-parsed.json" 2>/dev/null || echo "?") |
| 227 | + POS=$(jq -r '[.[] | select(.severity | startswith("🟢"))] | length' "$ARTIFACTS_DIR/review/findings-parsed.json" 2>/dev/null || echo "?") |
| 228 | + echo " Critical: ${CRIT}" |
| 229 | + echo " Warnings: ${WARN}" |
| 230 | + echo " Positive: ${POS}" |
| 231 | + echo " Approved: $([ "${CRIT}" = "0" ] && echo "YES ✅" || echo "NO ❌")" |
| 232 | + fi |
| 233 | + echo "" |
| 234 | + echo "─── Artifacts ───" |
| 235 | + find "$ARTIFACTS_DIR" -type f \( -name "*.md" -o -name "*.json" \) | sort |
| 236 | + depends_on: [post-review] |
| 237 | + timeout: 15000 |
0 commit comments