feat(ship): add external code review command hook to ship workflow
Adds workflow.code_review_command config key that allows solo devs to plug external AI review tools into the ship flow. When configured, the ship workflow generates a diff, builds a review prompt with stats and phase context, pipes it to the command via stdin, and parses JSON output with verdict/confidence/issues. Handles timeout (120s) and failures gracefully by falling through to the existing manual review flow. Closes #1876 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -159,6 +159,68 @@ Report: "PR #{number} created: {url}"
|
||||
</step>
|
||||
|
||||
<step name="optional_review">
|
||||
|
||||
**External code review command (automated sub-step):**
|
||||
|
||||
Before prompting the user, check if an external review command is configured:
|
||||
|
||||
```bash
|
||||
REVIEW_CMD=$(node "$HOME/.claude/get-shit-done/bin/gsd-tools.cjs" config-get workflow.code_review_command --default "" 2>/dev/null)
|
||||
```
|
||||
|
||||
If `REVIEW_CMD` is non-empty and not `"null"`, run the external review:
|
||||
|
||||
1. **Generate diff and stats:**
|
||||
```bash
|
||||
DIFF=$(git diff ${BASE_BRANCH}...HEAD)
|
||||
DIFF_STATS=$(git diff --stat ${BASE_BRANCH}...HEAD)
|
||||
```
|
||||
|
||||
2. **Load phase context from STATE.md:**
|
||||
```bash
|
||||
STATE_STATUS=$(node "$HOME/.claude/get-shit-done/bin/gsd-tools.cjs" state load 2>/dev/null | head -20)
|
||||
```
|
||||
|
||||
3. **Build review prompt and pipe to command via stdin:**
|
||||
Construct a review prompt containing the diff, diff stats, and phase context, then pipe it to the configured command:
|
||||
```bash
|
||||
REVIEW_PROMPT="You are reviewing a pull request.\n\nDiff stats:\n${DIFF_STATS}\n\nPhase context:\n${STATE_STATUS}\n\nFull diff:\n${DIFF}\n\nRespond with JSON: { \"verdict\": \"APPROVED\" or \"REVISE\", \"confidence\": 0-100, \"summary\": \"...\", \"issues\": [{\"severity\": \"...\", \"file\": \"...\", \"line_range\": \"...\", \"description\": \"...\", \"suggestion\": \"...\"}] }"
|
||||
REVIEW_OUTPUT=$(echo "${REVIEW_PROMPT}" | timeout 120 ${REVIEW_CMD} 2>/tmp/gsd-review-stderr.log)
|
||||
REVIEW_EXIT=$?
|
||||
```
|
||||
|
||||
4. **Handle timeout (120s) and failure:**
|
||||
If `REVIEW_EXIT` is non-zero or the command times out:
|
||||
```bash
|
||||
if [ $REVIEW_EXIT -ne 0 ]; then
|
||||
REVIEW_STDERR=$(cat /tmp/gsd-review-stderr.log 2>/dev/null)
|
||||
echo "WARNING: External review command failed (exit ${REVIEW_EXIT}). stderr: ${REVIEW_STDERR}"
|
||||
echo "Continuing with manual review flow..."
|
||||
fi
|
||||
```
|
||||
On failure, warn with stderr output and fall through to the manual review flow below.
|
||||
|
||||
5. **Parse JSON result:**
|
||||
If the command succeeded, parse the JSON output and report the verdict:
|
||||
```bash
|
||||
# Parse verdict and summary from REVIEW_OUTPUT JSON
|
||||
VERDICT=$(echo "${REVIEW_OUTPUT}" | node -e "
|
||||
let d=''; process.stdin.on('data',c=>d+=c); process.stdin.on('end',()=>{
|
||||
try { const r=JSON.parse(d); console.log(r.verdict); }
|
||||
catch(e) { console.log('INVALID_JSON'); }
|
||||
});
|
||||
")
|
||||
```
|
||||
- If `verdict` is `"APPROVED"`: report approval with confidence and summary.
|
||||
- If `verdict` is `"REVISE"`: report issues found, list each issue with severity, file, line_range, description, and suggestion.
|
||||
- If JSON is invalid (`INVALID_JSON`): warn "External review returned invalid JSON" with stderr and continue.
|
||||
|
||||
Regardless of the external review result, fall through to the manual review options below.
|
||||
|
||||
---
|
||||
|
||||
**Manual review options:**
|
||||
|
||||
Ask if user wants to trigger a code review:
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user