From 97a2c25e4b609859831e94f03e6bba8e48f2f8b9 Mon Sep 17 00:00:00 2001 From: darrenhinde <107584450+darrenhinde@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:38:55 +0100 Subject: [PATCH 1/6] automatic pr review --- .github/workflows/opencode.yml | 98 +++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 6 deletions(-) diff --git a/.github/workflows/opencode.yml b/.github/workflows/opencode.yml index 1b5b3f6..e4daab8 100644 --- a/.github/workflows/opencode.yml +++ b/.github/workflows/opencode.yml @@ -1,27 +1,113 @@ name: opencode on: + # Trigger on issue/PR comments for manual requests issue_comment: types: [created] + + # Trigger on PR events for automatic reviews + pull_request: + types: [opened, synchronize, ready_for_review] + + # Trigger on PR review requests for re-reviews + pull_request_review: + types: [submitted] jobs: - opencode: + # Manual opencode execution via comments + opencode-manual: if: | - contains(github.event.comment.body, ' /oc') || - startsWith(github.event.comment.body, '/oc') || - contains(github.event.comment.body, ' /opencode') || - startsWith(github.event.comment.body, '/opencode') + github.event_name == 'issue_comment' && ( + contains(github.event.comment.body, ' /oc') || + startsWith(github.event.comment.body, '/oc') || + contains(github.event.comment.body, ' /opencode') || + startsWith(github.event.comment.body, '/opencode') + ) runs-on: ubuntu-latest permissions: - contents: read + contents: write + pull-requests: write + issues: write id-token: write steps: - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Run opencode uses: sst/opencode/github@latest env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + with: + model: anthropic/claude-sonnet-4-20250514 + + # Automatic PR review when PR is opened or updated + opencode-pr-review: + if: | + github.event_name == 'pull_request' && ( + github.event.action == 'opened' || + github.event.action == 'synchronize' || + github.event.action == 'ready_for_review' + ) && !github.event.pull_request.draft + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + issues: write + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Checkout PR branch + run: | + gh pr checkout ${{ github.event.number }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Auto-review PR + uses: sst/opencode/github@latest + env: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + OPENCODE_COMMENT: "/opencode Please review this PR. Check for code quality, potential bugs, security issues, and adherence to best practices. Provide constructive feedback and suggestions for improvement." + with: + model: anthropic/claude-sonnet-4-20250514 + + # Re-review when specifically requested via PR review + opencode-re-review: + if: | + github.event_name == 'pull_request_review' && + github.event.review.state == 'commented' && ( + contains(github.event.review.body, 're-review') || + contains(github.event.review.body, 'check again') || + contains(github.event.review.body, '/oc') || + contains(github.event.review.body, '/opencode') + ) + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + issues: write + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Checkout PR branch + run: | + gh pr checkout ${{ github.event.pull_request.number }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Re-review PR + uses: sst/opencode/github@latest + env: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + OPENCODE_COMMENT: "/opencode Please re-review this PR based on the latest changes. Focus on the recent updates and provide feedback on improvements made." with: model: anthropic/claude-sonnet-4-20250514 \ No newline at end of file From 63274e97a418a17e10b9f562e4559743496a5bab Mon Sep 17 00:00:00 2001 From: darrenhinde <107584450+darrenhinde@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:40:30 +0100 Subject: [PATCH 2/6] PR agent --- .github/workflows/opencode.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/opencode.yml b/.github/workflows/opencode.yml index e4daab8..5a71ad6 100644 --- a/.github/workflows/opencode.yml +++ b/.github/workflows/opencode.yml @@ -72,7 +72,7 @@ jobs: uses: sst/opencode/github@latest env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - OPENCODE_COMMENT: "/opencode Please review this PR. Check for code quality, potential bugs, security issues, and adherence to best practices. Provide constructive feedback and suggestions for improvement." + OPENCODE_COMMENT: "/opencode @codebase-agent Please review this PR. Check for code quality, potential bugs, security issues, and adherence to best practices. Provide constructive feedback and suggestions for improvement." with: model: anthropic/claude-sonnet-4-20250514 From 89077932758c296b61a145546d216b7ee0363499 Mon Sep 17 00:00:00 2001 From: darrenhinde <107584450+darrenhinde@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:43:19 +0100 Subject: [PATCH 3/6] PR agent --- .github/workflows/opencode.yml | 80 +++++++++++++--------------------- 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/.github/workflows/opencode.yml b/.github/workflows/opencode.yml index 5a71ad6..79ec9ca 100644 --- a/.github/workflows/opencode.yml +++ b/.github/workflows/opencode.yml @@ -14,8 +14,8 @@ on: types: [submitted] jobs: - # Manual opencode execution via comments - opencode-manual: + # Handle opencode execution via comments + opencode: if: | github.event_name == 'issue_comment' && ( contains(github.event.comment.body, ' /oc') || @@ -42,72 +42,54 @@ jobs: with: model: anthropic/claude-sonnet-4-20250514 - # Automatic PR review when PR is opened or updated - opencode-pr-review: + # Automatically create review comment when PR is opened + auto-review-trigger: if: | github.event_name == 'pull_request' && ( github.event.action == 'opened' || - github.event.action == 'synchronize' || github.event.action == 'ready_for_review' ) && !github.event.pull_request.draft runs-on: ubuntu-latest permissions: - contents: write pull-requests: write - issues: write - id-token: write steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Create auto-review comment + uses: actions/github-script@v7 with: - fetch-depth: 0 - - - name: Checkout PR branch - run: | - gh pr checkout ${{ github.event.number }} - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + const issue_number = context.payload.pull_request.number; + + await github.rest.issues.createComment({ + owner, + repo, + issue_number, + body: '/opencode Please review this PR. Check for code quality, potential bugs, security issues, and adherence to best practices. Provide constructive feedback and suggestions for improvement.' + }); - - name: Auto-review PR - uses: sst/opencode/github@latest - env: - ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - OPENCODE_COMMENT: "/opencode @codebase-agent Please review this PR. Check for code quality, potential bugs, security issues, and adherence to best practices. Provide constructive feedback and suggestions for improvement." - with: - model: anthropic/claude-sonnet-4-20250514 - - # Re-review when specifically requested via PR review - opencode-re-review: + # Automatically trigger re-review when requested + re-review-trigger: if: | github.event_name == 'pull_request_review' && github.event.review.state == 'commented' && ( contains(github.event.review.body, 're-review') || contains(github.event.review.body, 'check again') || - contains(github.event.review.body, '/oc') || - contains(github.event.review.body, '/opencode') + contains(github.event.review.body, 'review again') ) runs-on: ubuntu-latest permissions: - contents: write pull-requests: write - issues: write - id-token: write steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Create re-review comment + uses: actions/github-script@v7 with: - fetch-depth: 0 - - - name: Checkout PR branch - run: | - gh pr checkout ${{ github.event.pull_request.number }} - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Re-review PR - uses: sst/opencode/github@latest - env: - ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - OPENCODE_COMMENT: "/opencode Please re-review this PR based on the latest changes. Focus on the recent updates and provide feedback on improvements made." - with: - model: anthropic/claude-sonnet-4-20250514 \ No newline at end of file + script: | + const { owner, repo } = context.repo; + const issue_number = context.payload.pull_request.number; + + await github.rest.issues.createComment({ + owner, + repo, + issue_number, + body: '/opencode @review Please re-review this PR based on the latest changes. Focus on the recent updates and provide feedback on improvements made since the last review.' + }); \ No newline at end of file From b4e642a839ea1c3b4d8583bfc8db82dcb872c5da Mon Sep 17 00:00:00 2001 From: darrenhinde <107584450+darrenhinde@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:44:22 +0100 Subject: [PATCH 4/6] PR agent --- .github/workflows/opencode.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/opencode.yml b/.github/workflows/opencode.yml index 79ec9ca..78986b4 100644 --- a/.github/workflows/opencode.yml +++ b/.github/workflows/opencode.yml @@ -64,7 +64,7 @@ jobs: owner, repo, issue_number, - body: '/opencode Please review this PR. Check for code quality, potential bugs, security issues, and adherence to best practices. Provide constructive feedback and suggestions for improvement.' + body: '/opencode @review Please review this PR. Check for code quality, potential bugs, security issues, and adherence to best practices. Provide constructive feedback and suggestions for improvement.' }); # Automatically trigger re-review when requested From 2339935930d42eedf8bdafa804d5265f9c697e71 Mon Sep 17 00:00:00 2001 From: darrenhinde <107584450+darrenhinde@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:51:40 +0100 Subject: [PATCH 5/6] PR agent --- .github/workflows/opencode.yml | 74 +++++++++------------------------- 1 file changed, 18 insertions(+), 56 deletions(-) diff --git a/.github/workflows/opencode.yml b/.github/workflows/opencode.yml index 78986b4..1a6d705 100644 --- a/.github/workflows/opencode.yml +++ b/.github/workflows/opencode.yml @@ -1,31 +1,25 @@ name: opencode on: - # Trigger on issue/PR comments for manual requests issue_comment: types: [created] - - # Trigger on PR events for automatic reviews pull_request: - types: [opened, synchronize, ready_for_review] - - # Trigger on PR review requests for re-reviews - pull_request_review: - types: [submitted] + types: [opened, ready_for_review] + +env: + REVIEW_PROMPT: "Please review this PR for code quality, bugs, and best practices." jobs: - # Handle opencode execution via comments opencode: if: | github.event_name == 'issue_comment' && ( - contains(github.event.comment.body, ' /oc') || + contains(github.event.comment.body, '/oc ') || startsWith(github.event.comment.body, '/oc') || - contains(github.event.comment.body, ' /opencode') || + contains(github.event.comment.body, '/opencode ') || startsWith(github.event.comment.body, '/opencode') ) runs-on: ubuntu-latest permissions: - contents: write pull-requests: write issues: write id-token: write @@ -33,63 +27,31 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 - name: Run opencode - uses: sst/opencode/github@latest + uses: sst/opencode/github@v0.5.27 env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} with: - model: anthropic/claude-sonnet-4-20250514 + model: claude-3-5-sonnet-20241022 - # Automatically create review comment when PR is opened - auto-review-trigger: + auto-review: if: | - github.event_name == 'pull_request' && ( - github.event.action == 'opened' || - github.event.action == 'ready_for_review' - ) && !github.event.pull_request.draft + github.event_name == 'pull_request' && + (github.event.action == 'opened' || github.event.action == 'ready_for_review') && + !github.event.pull_request.draft runs-on: ubuntu-latest permissions: pull-requests: write steps: - - name: Create auto-review comment + - name: Request review uses: actions/github-script@v7 with: script: | - const { owner, repo } = context.repo; - const issue_number = context.payload.pull_request.number; - await github.rest.issues.createComment({ - owner, - repo, - issue_number, - body: '/opencode @review Please review this PR. Check for code quality, potential bugs, security issues, and adherence to best practices. Provide constructive feedback and suggestions for improvement.' - }); - - # Automatically trigger re-review when requested - re-review-trigger: - if: | - github.event_name == 'pull_request_review' && - github.event.review.state == 'commented' && ( - contains(github.event.review.body, 're-review') || - contains(github.event.review.body, 'check again') || - contains(github.event.review.body, 'review again') - ) - runs-on: ubuntu-latest - permissions: - pull-requests: write - steps: - - name: Create re-review comment - uses: actions/github-script@v7 - with: - script: | - const { owner, repo } = context.repo; - const issue_number = context.payload.pull_request.number; - - await github.rest.issues.createComment({ - owner, - repo, - issue_number, - body: '/opencode @review Please re-review this PR based on the latest changes. Focus on the recent updates and provide feedback on improvements made since the last review.' + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: `/oc ${process.env.REVIEW_PROMPT}` }); \ No newline at end of file From a26bbe5e411b6377245ae7123acffda2a08c2152 Mon Sep 17 00:00:00 2001 From: darrenhinde <107584450+darrenhinde@users.noreply.github.com> Date: Tue, 26 Aug 2025 00:06:48 +0100 Subject: [PATCH 6/6] PR agent --- .github/workflows/opencode.yml | 40 ++++------------------ .opencode/agent/{review.md => reviewer.md} | 2 ++ 2 files changed, 8 insertions(+), 34 deletions(-) rename .opencode/agent/{review.md => reviewer.md} (88%) diff --git a/.github/workflows/opencode.yml b/.github/workflows/opencode.yml index 1a6d705..c796982 100644 --- a/.github/workflows/opencode.yml +++ b/.github/workflows/opencode.yml @@ -3,26 +3,18 @@ name: opencode on: issue_comment: types: [created] - pull_request: - types: [opened, ready_for_review] - -env: - REVIEW_PROMPT: "Please review this PR for code quality, bugs, and best practices." jobs: opencode: if: | - github.event_name == 'issue_comment' && ( - contains(github.event.comment.body, '/oc ') || - startsWith(github.event.comment.body, '/oc') || - contains(github.event.comment.body, '/opencode ') || - startsWith(github.event.comment.body, '/opencode') - ) + contains(github.event.comment.body, '/oc') || + contains(github.event.comment.body, '/opencode') runs-on: ubuntu-latest permissions: + id-token: write + contents: write pull-requests: write issues: write - id-token: write steps: - name: Checkout repository uses: actions/checkout@v4 @@ -30,28 +22,8 @@ jobs: fetch-depth: 1 - name: Run opencode - uses: sst/opencode/github@v0.5.27 + uses: sst/opencode/github@latest env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} with: - model: claude-3-5-sonnet-20241022 - - auto-review: - if: | - github.event_name == 'pull_request' && - (github.event.action == 'opened' || github.event.action == 'ready_for_review') && - !github.event.pull_request.draft - runs-on: ubuntu-latest - permissions: - pull-requests: write - steps: - - name: Request review - uses: actions/github-script@v7 - with: - script: | - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - body: `/oc ${process.env.REVIEW_PROMPT}` - }); \ No newline at end of file + model: claude-3-5-sonnet-20241022 \ No newline at end of file diff --git a/.opencode/agent/review.md b/.opencode/agent/reviewer.md similarity index 88% rename from .opencode/agent/review.md rename to .opencode/agent/reviewer.md index d7d798a..0b3eee9 100644 --- a/.opencode/agent/review.md +++ b/.opencode/agent/reviewer.md @@ -32,5 +32,7 @@ Workflow: 2. Provide concise review notes with suggested diffs (do not apply changes), including any security concerns. Output: +Start with "Reviewing..., what would you devs do if I didn't check up on you?" +Then give a short summary of the review. - Risk level (including security risk) and recommended follow-ups