Skip to content

Commit 50626a7

Browse files
committed
Parse provider/model/small_model overrides from /review comments
1 parent f7bed58 commit 50626a7

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

.github/workflows/pull-review-crush.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111
;;
112112
esac
113113
114-
# Set CRUSH_SMALL_MODEL based on provider (with override support)
114+
# Set SMALL_MODEL based on provider (with override support)
115115
if [ -n "$REVIEW_SMALL_MODEL" ]; then
116116
SMALL_MODEL="$REVIEW_SMALL_MODEL"
117117
elif [ "$REVIEW_PROVIDER" = "zai-coding-plan" ]; then
@@ -122,9 +122,9 @@ jobs:
122122
123123
# Prefix small model with provider for crush
124124
case "$REVIEW_PROVIDER" in
125-
openrouter) echo "CRUSH_SMALL_MODEL=openrouter/$SMALL_MODEL" >> "$GITHUB_ENV" ;;
126-
zai-coding-plan) echo "CRUSH_SMALL_MODEL=zai/$SMALL_MODEL" >> "$GITHUB_ENV" ;;
127-
*) echo "CRUSH_SMALL_MODEL=zai/glm-4.7" >> "$GITHUB_ENV" ;;
125+
openrouter) echo "SMALL_MODEL=openrouter/$SMALL_MODEL" >> "$GITHUB_ENV" ;;
126+
zai-coding-plan) echo "SMALL_MODEL=zai/$SMALL_MODEL" >> "$GITHUB_ENV" ;;
127+
*) echo "SMALL_MODEL=zai/glm-4.7" >> "$GITHUB_ENV" ;;
128128
esac
129129
130130
- name: Get PR number
@@ -467,7 +467,7 @@ jobs:
467467
- name: Run agentic review
468468
if: steps.size-check.outputs.too_large == 'false'
469469
run: |
470-
crush run -q -m "$CRUSH_MODEL" --small-model "$CRUSH_SMALL_MODEL" < /tmp/agentic_prompt.txt > /tmp/agentic_review.txt 2>/tmp/crush_stderr.txt || {
470+
crush run -q -m "$CRUSH_MODEL" --small-model "$SMALL_MODEL" < /tmp/agentic_prompt.txt > /tmp/agentic_review.txt 2>/tmp/crush_stderr.txt || {
471471
echo "::warning::Agentic review via crush failed"
472472
cat /tmp/crush_stderr.txt >&2
473473
echo "Agentic review unavailable (crush encountered an error)." > /tmp/agentic_review.txt

.github/workflows/pull-review.yml

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ jobs:
6060
echo "FAST_MODE=false" >> "$GITHUB_ENV"
6161
fi
6262
63+
- name: Parse provider/model override
64+
env:
65+
COMMENT_BODY: ${{ github.event.comment.body }}
66+
run: |
67+
# Check for {{provider, model}} or {{provider, model, small_model}} override syntax after /review or /review_fast command
68+
if [[ "$COMMENT_BODY" =~ ^[[:space:]]*/review(_fast)?[[:space:]]+\{\{[[:space:]]*([^,]+)[[:space:]]*,[[:space:]]*([^,}]+)[[:space:]]*(,[[:space:]]*([^}]+)[[:space:]]*)?\}\} ]]; then
69+
PROVIDER=$(echo "${BASH_REMATCH[2]}" | xargs)
70+
MODEL=$(echo "${BASH_REMATCH[3]}" | xargs)
71+
SMALL_MODEL=$(echo "${BASH_REMATCH[5]}" | xargs)
72+
# Validate provider and models contain only safe characters
73+
if [[ "$PROVIDER" =~ ^[a-zA-Z0-9_-]+$ ]] && [[ "$MODEL" =~ ^[a-zA-Z0-9_./-]+$ ]] && { [[ -z "$SMALL_MODEL" ]] || [[ "$SMALL_MODEL" =~ ^[a-zA-Z0-9_./-]+$ ]]; }; then
74+
echo "Overriding provider to: $PROVIDER"
75+
echo "Overriding model to: $MODEL"
76+
echo "REVIEW_PROVIDER=$PROVIDER" >> "$GITHUB_ENV"
77+
echo "REVIEW_MODEL=$MODEL" >> "$GITHUB_ENV"
78+
if [[ -n "$SMALL_MODEL" ]]; then
79+
echo "Overriding small model to: $SMALL_MODEL"
80+
echo "REVIEW_SMALL_MODEL=$SMALL_MODEL" >> "$GITHUB_ENV"
81+
fi
82+
else
83+
echo "::warning::Invalid provider or model format in override, using defaults"
84+
fi
85+
fi
86+
6387
- name: Resolve provider settings
6488
run: |
6589
case "$REVIEW_PROVIDER" in
@@ -87,6 +111,22 @@ jobs:
87111
;;
88112
esac
89113
114+
# Set SMALL_MODEL based on provider (with override support)
115+
if [ -n "$REVIEW_SMALL_MODEL" ]; then
116+
SMALL_MODEL="$REVIEW_SMALL_MODEL"
117+
elif [ "$REVIEW_PROVIDER" = "zai-coding-plan" ]; then
118+
SMALL_MODEL="glm-4.7"
119+
else
120+
SMALL_MODEL="google/gemini-3-flash-preview"
121+
fi
122+
123+
# Prefix small model with provider
124+
case "$REVIEW_PROVIDER" in
125+
openrouter) echo "SMALL_MODEL=openrouter/$SMALL_MODEL" >> "$GITHUB_ENV" ;;
126+
zai-coding-plan) echo "SMALL_MODEL=zai-coding-plan/$SMALL_MODEL" >> "$GITHUB_ENV" ;;
127+
*) echo "SMALL_MODEL=zai-coding-plan/glm-4.7" >> "$GITHUB_ENV" ;;
128+
esac
129+
90130
- name: Get PR number
91131
id: pr-info
92132
run: |
@@ -102,6 +142,7 @@ jobs:
102142
echo "base_ref=$(jq -r '.base.ref' pr_data.json)"
103143
} >> "$GITHUB_OUTPUT"
104144
jq -r '.body // ""' pr_data.json > /tmp/pr_body.txt
145+
jq -r '.title // ""' pr_data.json > /tmp/pr_title.txt
105146
106147
- name: Check for linked issue
107148
id: check-issue
@@ -178,11 +219,14 @@ jobs:
178219
HAS_ISSUE: ${{ steps.check-issue.outputs.has_issue }}
179220
ISSUE_NUMBER: ${{ steps.check-issue.outputs.issue_number }}
180221
run: |
222+
# Start with PR title
223+
printf '<pr_title>\n%s\n</pr_title>\n' "$(cat /tmp/pr_title.txt)" > /tmp/helpful_context.txt
224+
181225
if [ "$HAS_ISSUE" = "true" ]; then
182226
# Fetch the issue
183227
if ! gh api "/repos/$GITHUB_REPOSITORY/issues/$ISSUE_NUMBER" > issue_data.json 2>/dev/null; then
184228
echo "::warning::Could not fetch issue #$ISSUE_NUMBER"
185-
echo "<issue_summary>Issue context unavailable.</issue_summary>" > /tmp/helpful_context.txt
229+
echo "<issue_summary>Issue context unavailable.</issue_summary>" >> /tmp/helpful_context.txt
186230
exit 0
187231
fi
188232
@@ -232,7 +276,7 @@ jobs:
232276
SUMMARY=$(cat /tmp/issue_conversation.txt)
233277
fi
234278
235-
printf '<issue_summary>\n%s\n</issue_summary>\n' "$SUMMARY" > /tmp/helpful_context.txt
279+
printf '<issue_summary>\n%s\n</issue_summary>\n' "$SUMMARY" >> /tmp/helpful_context.txt
236280
else
237281
# No referenced issue — summarize the PR description instead
238282
jq -n \
@@ -427,6 +471,11 @@ jobs:
427471
env:
428472
OPENCODE_PERMISSION: '{ "edit": "deny", "write": "deny", "bash": "deny", "read": "allow", "grep": "allow", "glob": "allow", "list": "allow", "task": "allow", "todowrite": "allow" }'
429473
run: |
474+
# TODO: implement $SMALL_MODEL for opencode
475+
# NOTE: opencode has a bug when switching to small models: https://github.com/anomalyco/opencode/issues/6636
476+
# To configure subagents with a specific model you need to create one as a file first
477+
# - https://opencode.ai/docs/agents/#model
478+
# - https://opencode.ai/docs/agents/#examples
430479
opencode run -m "$OPENCODE_MODEL" < /tmp/agentic_prompt.txt > /tmp/agentic_review.txt 2>/tmp/opencode_stderr.txt || {
431480
echo "::warning::Agentic review via opencode failed"
432481
cat /tmp/opencode_stderr.txt >&2

0 commit comments

Comments
 (0)