Enhanced PR Review System - #2
Open
blacksyan wants to merge 43 commits into
Open
Conversation
…for inline comments
…ck, Phase 1 skip logic
…OVE with reminders
…NCURRENT IMPLEMENTATION RULES
…and explicit examples
blacksyan
marked this pull request as ready for review
January 3, 2026 14:39
- Disabled auto-commit and push after AI response - Any file changes made by AI are discarded (git checkout -- .) - OpenCode now only reviews and posts comments, never modifies code
- Parse Git patch to extract valid line ranges from @@ hunk headers - Filter comments to only include lines present in the diff - Add prompt guidance: only comment on added/modified lines - Invalid comments are shown in summary instead of causing API errors - Prevents GitHub API 422 'Line could not be resolved' errors
- Accepts null from LLM but transforms to undefined for cleaner type - Type is now 'string | undefined' instead of 'string | null | undefined'
…her PR - Added schema definitions to list of skippable concurrent deps - Explicitly states static schema(), column definitions are PART OF migrations - Updated all 3 prompts consistently - AI now correctly marks these as Skipped instead of Fail
- Added prompt rule: suggestion must be RAW CODE ONLY - Added Zod transform to strip markdown code blocks if AI includes them - Prevents 'Unterminated string' JSON parse errors
AI sometimes uses 'warning' or other strings for passed field. Added defensive preprocess to coerce non-boolean values to null.
- Re-implemented line-range validation against PR diff (fixes 422 'Line could not be resolved') - Added defensive schema handling to normalize 'null' suggestions and 'warning' statuses - Added markdown sanitization for code suggestions to prevent JSON parse errors - Enhanced non-strict branch rules to explicitly skip schema/model internals when handled in concurrent PRs
- Updated Recheck, Direct Review, and Phase 2 prompts - Explicitly instructs AI to mark Previous Feedback as 'Skipped' (passed: null) if fix is in a separate PR - Strengthens the non-strict override over the global 'track previous issues' rule
- Upgraded regex to handle escaped quotes: (?:[^"\\]|\\.)* - Applies to ALL string fields, not just 'suggestion' - Handles both escaped (\n) and actual newlines in code blocks
- Implemented character-aware JSON repair scanner - Automatically escapes unescaped control chars (newlines) in strings - Strips hallucinated triple-backtick blocks - Normalizes trailing commas in objects/arrays - This provides absolute resilience against common LLM formatting hallucinations.
- Added generateObject fallback when JSON repair fails - Uses Gemini's responseMimeType: 'application/json' for bulletproof JSON extraction - Two-tier approach: fast repair first, native structured output as fallback - This implements Google's structured output spec per user request
Previous commit 5e3212a added these restrictions but they were accidentally removed in a later refactor. Re-adding to ensure AI cannot modify files during PR reviews.
- Zod transforms/preprocess cannot be represented in JSON Schema - Added *Raw versions of schemas without transforms for generateObject - generateObject uses ReviewOutputRaw, then validates with full schema - Fixes: 'Transforms cannot be represented in JSON Schema' error
- Extracted repairAndParseJson to util/json-repair.ts with Enhanced Smart Quote logic - Extracted parsePatchForValidLines to util/git-diff.ts - Added comprehensive unit tests (github-review.test.ts) covering: - JSON repair edge cases (trailing commas, unescaped quotes/newlines, markdown blocks) - Diff parsing (hunks, context lines, deletions) - Verified all tests pass
- Extracted renderReviewMarkdown and filterCommentsByDiff to github-review-logic.ts - Achieved 100% line coverage for all extracted PR review modules - Simplified github.ts orchestration logic - Added unit tests for markdown rendering and diff-based filtering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enhanced PR Review System
A context-aware, multi-phase AI code review system for GitHub PRs using OpenCode.
🎯 Problem & Solution
The Problem
Current OpenCode capabilities for PR reviews have some limitations:
The Solution
This system enhances OpenCode with a context-aware review layer that:
main, relaxed for feature branches.📋 Table of Contents
✨ Features
🔍 OpenCode File Reading
The system leverages OpenCode's native capability to read files from your repository. You can verify this in the GitHub Actions logs:
This ensures the AI analyzes your actual source files to understand the broader context beyond just the diff.
🎯 Multi-Phase Review Flow
/oc/oc!/oc recheck🎛 Branch-Aware Strictness
The review logic adapts to your target branch:
main,staging,productionfeature/*,trial/*,developConfigure via:
STRICT_REVIEW_BRANCHES=main,staging,production📝 Multi-Line Committable Suggestions
Comments can now span multiple lines (e.g., lines 42-65) and include GitHub's suggestion syntax:
Users can click "Commit suggestion" directly on GitHub to apply the fix.
📚 Context Injection System
🔄 How It Works
/ocon a PR.🚀 Quick Start
1. Add Workflow to Your Repo
Create
.github/workflows/opencode.ymlin your target repository:2. Add Required Secrets
In your repo Settings → Secrets → Actions:
GOOGLE_GENERATIVE_AI_API_KEY: Your Gemini API key.GITHUB_TOKEN: Automatically handled if using default permissions.3. Add Project Rules (Optional)
Create
RAKAMIND.md(orOPENCODE.md) in your repo root to guide the AI:📊 Test Results
Verified on rakamindev/paragon-api:
📝 Changelog