-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathopencode-review.sh
More file actions
executable file
·62 lines (53 loc) · 2.2 KB
/
opencode-review.sh
File metadata and controls
executable file
·62 lines (53 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
# opencode-review.sh - custom review script for ralphex external review phase.
#
# uses OpenCode CLI to perform code review with a configurable model,
# allowing a different model than the one used for task/review phases.
#
# config example (~/.config/ralphex/config or .ralphex/config):
# external_review_tool = custom
# custom_review_script = /path/to/opencode-review.sh
#
# environment variables:
# e.g. OPENCODE_REVIEW_MODEL="github-copilot/gpt-5.3-codex"
OPENCODE_REVIEW_MODEL="${OPENCODE_REVIEW_MODEL:-}"
# e.g. OPENCODE_REVIEW_REASONING="high"
OPENCODE_REVIEW_REASONING="${OPENCODE_REVIEW_REASONING:-}"
set -euo pipefail
# verify opencode is available
command -v opencode >/dev/null 2>&1 || { echo "error: opencode is required but not found" >&2; exit 1; }
# verify jq is available (required for JSON config merging)
command -v jq >/dev/null 2>&1 || { echo "error: jq is required but not found" >&2; exit 1; }
# prompt file path is passed as the single argument
prompt_file="${1:-}"
if [[ -z "$prompt_file" || ! -f "$prompt_file" ]]; then
echo "error: prompt file not provided or not found" >&2
exit 1
fi
prompt=$(cat "$prompt_file")
# build coder agent overrides from env vars
coder_config="{}"
if [[ -n "$OPENCODE_REVIEW_MODEL" ]]; then
coder_config=$(echo "$coder_config" | jq -c --arg m "$OPENCODE_REVIEW_MODEL" '. + {model: $m}')
fi
if [[ -n "$OPENCODE_REVIEW_REASONING" ]]; then
coder_config=$(echo "$coder_config" | jq -c --arg r "$OPENCODE_REVIEW_REASONING" '. + {reasoningEffort: $r}')
fi
# build final config with permissions and optional coder overrides
base_config='{"permission":{"*":"allow"}}'
if [[ "$coder_config" != "{}" ]]; then
base_config=$(echo "$base_config" | jq -c --argjson coder "$coder_config" '. + {agent: {coder: $coder}}')
fi
# merge with existing OPENCODE_CONFIG_CONTENT if set
if [[ -n "${OPENCODE_CONFIG_CONTENT:-}" ]]; then
OPENCODE_CONFIG_CONTENT=$(echo "$OPENCODE_CONFIG_CONTENT" | jq -c --argjson base "$base_config" '. * $base')
else
OPENCODE_CONFIG_CONTENT="$base_config"
fi
export OPENCODE_CONFIG_CONTENT
cmd=(opencode run)
if [[ -n "$OPENCODE_REVIEW_MODEL" ]]; then
cmd+=(--model "$OPENCODE_REVIEW_MODEL")
fi
cmd+=("$prompt")
"${cmd[@]}"