Skip to content

refactor(code-review): replace Python implementation with OpenCode + skills#74

Merged
Pertempto merged 56 commits intomainfrom
refactor/opencode-code-review
Feb 19, 2026
Merged

refactor(code-review): replace Python implementation with OpenCode + skills#74
Pertempto merged 56 commits intomainfrom
refactor/opencode-code-review

Conversation

@Pertempto
Copy link
Copy Markdown
Contributor

@Pertempto Pertempto commented Feb 11, 2026

Summary

Replaces the custom Python code review bot with OpenCode, a mature AI coding agent. Instead of implementing our own agent loop and tools, we now provide skills (markdown files) that guide OpenCode to review PRs/MRs.

Changes

  • Remove Python implementation (llm, PyGitHub, python-gitlab, tests, system prompts)
  • Add OpenCode as the AI agent runtime with markdown skills
  • Shell harness pre-fetches PR/MR data and attaches it to the agent via --file
  • Harness owns the comment lifecycle (create/update, no duplicates)
  • Smart skip logic (should_review.sh) skips trivial commits based on delta analysis
  • [review] commit message tag to force a review regardless of delta
  • Embeds <!-- reviewed-sha:... --> in bot comments to track what was reviewed
  • OpenCode session sharing link included in review comments
  • Thinking blocks enabled for better reasoning
  • Update Dockerfile to node:22-slim with OpenCode, gh, and glab CLIs
  • Update test workflow to validate scripts, skills, and Dockerfile
  • Rewrite docs: architecture, skip logic, configuration, RC process
  • Rename doc files to drop -setup suffix; update README links
  • Default model: minimax/minimax-m2.5 via OpenRouter

Architecture

Component Purpose
github_code_review.sh / gitlab_code_review.sh Shell harness: pre-fetch data, skip logic, launch agent, post comment
should_review.sh Shared delta analysis with [review] force tag support
skills/github-code-review/SKILL.md Agent instructions for GitHub PRs
skills/gitlab-code-review/SKILL.md Agent instructions for GitLab MRs
Dockerfile node:22-slim with OpenCode, gh, glab, jq

How It Works

  1. Harness finds existing bot comment and extracts last reviewed SHA
  2. should_review.sh computes delta — skips if trivial, forced if [review] in commit message
  3. Harness pre-fetches metadata, diff, comments into .bots/ files
  4. Harness attaches files and repo instructions directly into the agent prompt via --file
  5. OpenCode agent reviews code, writes output to .bots/review-body.md
  6. Harness extracts session share link, appends reviewed-sha marker, creates/updates bot comment

Skip Logic

Condition Result
No prior review Review
Commit message contains [review] Review (force)
Previous SHA not found (force push/rebase) Review
No changes since last review Skip
Delta under 20 lines Skip
Only non-code files (images, lock files, etc.) Skip
Otherwise Review

Closes #67

exe.dev user and others added 3 commits February 11, 2026 21:11
…skills

This replaces the custom Python code review bot with OpenCode, a mature
AI coding agent. Instead of implementing our own agent loop and tools,
we now provide skills that guide OpenCode to use the gh/glab CLIs directly.

Changes:
- Remove Python implementation (llm library, PyGitHub, python-gitlab)
- Add OpenCode as the AI agent runtime
- Create separate skills for GitHub and GitLab code review
- Simplify entrypoint scripts to just invoke OpenCode
- Update Dockerfile to use node:22-slim base image
- Default model: google/gemini-3-flash-preview via OpenRouter
- Support legacy OPENROUTER_KEY env var for backwards compatibility

Benefits:
- Simpler architecture - no custom agent loop to maintain
- Battle-tested agent with auto-retry, compaction, etc.
- Skills are easy to read and modify (just markdown)
- Direct CLI usage is more transparent and debuggable

Closes #67

Co-authored-by: Shelley <shelley@exe.dev>
OpenCode already knows OpenRouter models, and we pass --model and
--provider explicitly in the scripts.

Co-authored-by: Shelley <shelley@exe.dev>
Co-authored-by: Shelley <shelley@exe.dev>
Pertempto pushed a commit that referenced this pull request Feb 11, 2026
- Fix unbound-variable risks in shell scripts by using safe fallbacks
  (${VAR:-}) for OPENROUTER_KEY, GITHUB_TOKEN, and GL_TOKEN
- Make Dockerfile resilient to dpkg dependency issues with apt-get -f fallback
- Add duplicate review comment detection to both GitHub and GitLab skills,
  instructing the agent to update existing bot comments instead of creating new ones
- Replace placeholder [#XX] with [#74] in CHANGELOG.md

Co-authored-by: Shelley <shelley@exe.dev>
Pertempto pushed a commit that referenced this pull request Feb 12, 2026
- Fix unbound-variable risks in shell scripts by using safe fallbacks
  (${VAR:-}) for OPENROUTER_KEY, GITHUB_TOKEN, and GL_TOKEN
- Make Dockerfile resilient to dpkg dependency issues with apt-get -f fallback
- Add duplicate review comment detection to both GitHub and GitLab skills,
  instructing the agent to update existing bot comments instead of creating new ones
- Replace placeholder [#XX] with [#74] in CHANGELOG.md

Co-authored-by: Shelley <shelley@exe.dev>
@Pertempto Pertempto force-pushed the refactor/opencode-code-review branch from a4d5839 to efdf37a Compare February 12, 2026 21:54
Pertempto pushed a commit that referenced this pull request Feb 12, 2026
- Fix unbound-variable risks in shell scripts by using safe fallbacks
  (${VAR:-}) for OPENROUTER_KEY, GITHUB_TOKEN, and GL_TOKEN
- Make Dockerfile resilient to dpkg dependency issues with apt-get -f fallback
- Add duplicate review comment detection to both GitHub and GitLab skills,
  instructing the agent to update existing bot comments instead of creating new ones
- Replace placeholder [#XX] with [#74] in CHANGELOG.md

Co-authored-by: Shelley <shelley@exe.dev>
@Pertempto Pertempto force-pushed the refactor/opencode-code-review branch from efdf37a to b56cf68 Compare February 12, 2026 21:55
Pertempto pushed a commit that referenced this pull request Feb 12, 2026
- Fix unbound-variable risks in shell scripts by using safe fallbacks
  (${VAR:-}) for OPENROUTER_KEY, GITHUB_TOKEN, and GL_TOKEN
- Make Dockerfile resilient to dpkg dependency issues with apt-get -f fallback
- Add duplicate review comment detection to both GitHub and GitLab skills,
  instructing the agent to update existing bot comments instead of creating new ones
- Replace placeholder [#XX] with [#74] in CHANGELOG.md

Co-authored-by: Shelley <shelley@exe.dev>
@Pertempto Pertempto force-pushed the refactor/opencode-code-review branch from b56cf68 to d429aaa Compare February 12, 2026 21:56
Pertempto pushed a commit that referenced this pull request Feb 12, 2026
- Fix unbound-variable risks in shell scripts by using safe fallbacks
  (${VAR:-}) for OPENROUTER_KEY, GITHUB_TOKEN, and GL_TOKEN
- Make Dockerfile resilient to dpkg dependency issues with apt-get -f fallback
- Add duplicate review comment detection to both GitHub and GitLab skills,
  instructing the agent to update existing bot comments instead of creating new ones
- Replace placeholder [#XX] with [#74] in CHANGELOG.md

Co-authored-by: Shelley <shelley@exe.dev>
@Pertempto Pertempto force-pushed the refactor/opencode-code-review branch from d429aaa to d1d0852 Compare February 12, 2026 21:57
Pertempto pushed a commit that referenced this pull request Feb 12, 2026
- Fix unbound-variable risks in shell scripts by using safe fallbacks
  (${VAR:-}) for OPENROUTER_KEY, GITHUB_TOKEN, and GL_TOKEN
- Make Dockerfile resilient to dpkg dependency issues with apt-get -f fallback
- Add duplicate review comment detection to both GitHub and GitLab skills,
  instructing the agent to update existing bot comments instead of creating new ones
- Replace placeholder [#XX] with [#74] in CHANGELOG.md

Co-authored-by: Shelley <shelley@exe.dev>
@Pertempto Pertempto force-pushed the refactor/opencode-code-review branch from d1d0852 to 2f6aaf1 Compare February 12, 2026 21:59
Pertempto pushed a commit that referenced this pull request Feb 12, 2026
- Fix unbound-variable risks in shell scripts by using safe fallbacks
  (${VAR:-}) for OPENROUTER_KEY, GITHUB_TOKEN, and GL_TOKEN
- Make Dockerfile resilient to dpkg dependency issues with apt-get -f fallback
- Add duplicate review comment detection to both GitHub and GitLab skills,
  instructing the agent to update existing bot comments instead of creating new ones
- Replace placeholder [#XX] with [#74] in CHANGELOG.md

Co-authored-by: Shelley <shelley@exe.dev>
@Pertempto Pertempto force-pushed the refactor/opencode-code-review branch from 2f6aaf1 to d5229a0 Compare February 12, 2026 21:59
- Fix unbound-variable risks in shell scripts by using safe fallbacks
  (${VAR:-}) for OPENROUTER_KEY, GITHUB_TOKEN, and GL_TOKEN
- Make Dockerfile resilient to dpkg dependency issues with apt-get -f fallback
- Add duplicate review comment detection to both GitHub and GitLab skills,
  instructing the agent to update existing bot comments instead of creating new ones
- Replace placeholder [#XX] with [#74] in CHANGELOG.md

Co-authored-by: Shelley <shelley@exe.dev>
@Pertempto Pertempto force-pushed the refactor/opencode-code-review branch from d5229a0 to add0ea0 Compare February 12, 2026 22:01
Pertempto and others added 3 commits February 17, 2026 14:49
--provider is not a valid opencode run flag. The model must be
specified in provider/model format using -m, e.g.:
  opencode run -m openrouter/google/gemini-3-flash-preview

This was causing opencode to print help text and exit 1.

Co-authored-by: Shelley <shelley@exe.dev>
Co-authored-by: Shelley <shelley@exe.dev>
@mrs-electronics-inc mrs-electronics-inc deleted a comment from github-actions Bot Feb 17, 2026
@mrs-electronics-inc mrs-electronics-inc deleted a comment from github-actions Bot Feb 17, 2026
@mrs-electronics-inc mrs-electronics-inc deleted a comment from github-actions Bot Feb 17, 2026
@mrs-electronics-inc mrs-electronics-inc deleted a comment from github-actions Bot Feb 17, 2026
@mrs-electronics-inc mrs-electronics-inc deleted a comment from github-actions Bot Feb 17, 2026
@mrs-electronics-inc mrs-electronics-inc deleted a comment from github-actions Bot Feb 17, 2026
@mrs-electronics-inc mrs-electronics-inc deleted a comment from github-actions Bot Feb 17, 2026
@mrs-electronics-inc mrs-electronics-inc deleted a comment from github-actions Bot Feb 17, 2026
@mrs-electronics-inc mrs-electronics-inc deleted a comment from github-actions Bot Feb 17, 2026
exe.dev user and others added 9 commits February 17, 2026 21:50
Co-authored-by: Shelley <shelley@exe.dev>
…ing it

opencode's -f flag is an array type, so it consumes the trailing
positional message as another file argument. Adding -- separates
options from the positional message argument.

Co-authored-by: Shelley <shelley@exe.dev>
Co-authored-by: Shelley <shelley@exe.dev>
- Change default model to minimax/minimax-m2.5:nitro
- Capture OpenCode share link from output and append to review comment
- Remove debug logging (--print-logs --log-level DEBUG)
- Rewrite docs/code-review-bot.md (renamed from -setup suffix):
  architecture overview, skip logic table, configuration, RC process
- Update README link to new docs path

Co-authored-by: Shelley <shelley@exe.dev>
Co-authored-by: Shelley <shelley@exe.dev>
Co-authored-by: Shelley <shelley@exe.dev>
OpenCode's model registry doesn't include OpenRouter routing variants.
The model ID is minimax/minimax-m2.5, not minimax/minimax-m2.5:nitro.

Co-authored-by: Shelley <shelley@exe.dev>
Co-authored-by: Shelley <shelley@exe.dev>
@Pertempto Pertempto requested a review from bambam955 February 17, 2026 22:18
exe.dev user and others added 3 commits February 17, 2026 22:23
…ability

The agent reported truncated JSON when reading pr-metadata.json.
Pretty-printing via jq makes the structured data easier to parse
in the LLM context window.

Co-authored-by: Shelley <shelley@exe.dev>
Switch from glab mr view text output to -F json piped through jq,
consistent with the GitHub harness. Rename mr-metadata.txt to
mr-metadata.json.

Co-authored-by: Shelley <shelley@exe.dev>
Co-authored-by: Shelley <shelley@exe.dev>
Copy link
Copy Markdown
Contributor

@bambam955 bambam955 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bulk of this looks great. The harnesses look really good...I really like the optimizations with ensuring the bot only runs when it actually needs to. The *-code-review skills look really good too.

Just a few CI-related suggestions and then we should be good to go 👍

Comment thread .github/workflows/test.code-review-bot.yaml
Comment thread code-review-bot/Dockerfile
Comment thread .github/workflows/test.code-review-bot.yaml
Comment thread code-review-bot/Dockerfile
Comment thread .github/workflows/code-review.yaml
@Pertempto Pertempto merged commit 0cdc94f into main Feb 19, 2026
2 checks passed
@Pertempto Pertempto deleted the refactor/opencode-code-review branch February 19, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(code-review): rewrite with existing agent

2 participants