From a18206baeed9379dd9c9344124bf96171f1b378c Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 12 Aug 2025 13:00:10 -0700 Subject: [PATCH 01/14] feat: new review bot --- .github/workflows/continue-inline-review.yaml | 239 ++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 .github/workflows/continue-inline-review.yaml diff --git a/.github/workflows/continue-inline-review.yaml b/.github/workflows/continue-inline-review.yaml new file mode 100644 index 000000000..2589f93d4 --- /dev/null +++ b/.github/workflows/continue-inline-review.yaml @@ -0,0 +1,239 @@ +name: Continue CLI Inline Code Review + +on: + pull_request: + types: [opened, ready_for_review] + issue_comment: + types: [created] + +permissions: + contents: read + pull-requests: write + issues: write + +jobs: + inline-code-review: + name: AI Inline Code Review + runs-on: ubuntu-latest + timeout-minutes: 10 + # Only run if: + # - It's a PR event from a team member (with write/admin permissions) + # - OR it's a comment with @continue-inline-review on a PR from a team member + if: > + (github.event_name == 'pull_request' && + (github.event.pull_request.author_association == 'OWNER' || + github.event.pull_request.author_association == 'MEMBER' || + github.event.pull_request.author_association == 'COLLABORATOR')) || + (github.event_name == 'issue_comment' && + github.event.issue.pull_request && + contains(github.event.comment.body, '@continue-inline-review') && + (github.event.comment.author_association == 'OWNER' || + github.event.comment.author_association == 'MEMBER' || + github.event.comment.author_association == 'COLLABORATOR')) + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch full history for better context + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install Continue CLI + run: npm install -g @continuedev/cli@latest + + - name: Build Inline Review Prompt + run: | + # Get PR number based on event type + if [ "${{ github.event_name }}" = "pull_request" ]; then + PR_NUMBER="${{ github.event.number }}" + else + # For issue_comment event on a PR + PR_NUMBER="${{ github.event.issue.number }}" + fi + + # Get PR files with line numbers + gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/files > pr_files.json + + # Get PR diff with context + gh pr diff $PR_NUMBER --color=never > pr_diff.txt + + # Create review prompt for inline comments + cat > inline_review_prompt.txt << 'EOF' + You are conducting a detailed inline code review for a pull request. + + Your task is to analyze the code changes and generate specific, actionable review comments for individual lines or small sections of code. + + Below is the PR diff: + + EOF + + cat pr_diff.txt >> inline_review_prompt.txt + + cat >> inline_review_prompt.txt << 'EOF' + + Please analyze these changes and provide inline review comments in the following JSON format: + + { + "review_summary": "Overall assessment of the PR", + "comments": [ + { + "path": "path/to/file.js", + "line": 42, + "side": "RIGHT", + "body": "Brief, specific comment about this line or section" + } + ] + } + + Focus on: + 1. **Critical Issues**: Security vulnerabilities, bugs that will break functionality + 2. **High Priority**: Performance problems, incorrect logic, missing error handling + 3. **Medium Priority**: Code style violations, potential edge cases, unclear code + 4. **Low Priority**: Suggestions for improvement, refactoring opportunities + + Guidelines for comments: + - Be specific and actionable + - Reference the exact line number from the diff + - Keep comments concise but informative + - Suggest concrete improvements when pointing out issues + - Only comment on actual problems or important improvements + - Use "RIGHT" for new/modified lines, "LEFT" for context about removed lines + + Important: + - Output ONLY valid JSON, no additional text + - Ensure line numbers match the actual diff + - Comment on the most important issues first + - Limit to maximum 20 most relevant comments + EOF + env: + GH_TOKEN: ${{ github.token }} + + - name: Run Continue CLI Inline Review + run: | + echo "Running Continue CLI for inline review..." + + # Run the CLI and capture JSON output + cat inline_review_prompt.txt | cn --readonly --org continuedev --config continuedev/review-bot -p > inline_review.json + + # Validate JSON output + if ! jq empty inline_review.json 2>/dev/null; then + echo "Invalid JSON output from Continue CLI" + echo "{\"review_summary\": \"Failed to generate review\", \"comments\": []}" > inline_review.json + fi + env: + CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }} + + - name: Post Inline Review Comments + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + + try { + // Read the review output + let reviewData; + try { + const reviewContent = fs.readFileSync('inline_review.json', 'utf8'); + reviewData = JSON.parse(reviewContent); + } catch (parseError) { + console.log('Failed to parse review JSON:', parseError); + reviewData = { + review_summary: 'AI review completed but failed to parse output', + comments: [] + }; + } + + // Get PR number + let prNumber; + if (context.eventName === 'pull_request') { + prNumber = context.payload.pull_request.number; + } else { + prNumber = context.payload.issue.number; + } + + // Get the latest commit SHA + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber + }); + + const commitSha = pr.head.sha; + + // Prepare review comments + const comments = reviewData.comments?.map(comment => ({ + path: comment.path, + line: comment.line || 1, + side: comment.side || 'RIGHT', + body: comment.body + })) || []; + + // Create the review + if (comments.length > 0) { + try { + await github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + commit_id: commitSha, + body: reviewData.review_summary || 'AI Code Review', + event: 'COMMENT', + comments: comments + }); + console.log(`Successfully created review with ${comments.length} inline comments`); + } catch (reviewError) { + console.log('Failed to create review:', reviewError.message); + + // Fallback: post as a regular comment if review creation fails + const fallbackBody = `## AI Code Review\n\n${reviewData.review_summary}\n\n` + + `*Failed to post ${comments.length} inline comments. Please review the changes manually.*`; + + await github.rest.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: fallbackBody + }); + } + } else { + // No inline comments, just post the summary + await github.rest.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: `## AI Code Review\n\n${reviewData.review_summary}\n\n*No specific line comments generated.*` + }); + } + + // Add triggered by note if from comment + if (context.eventName === 'issue_comment') { + await github.rest.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: `*Inline review triggered by @${context.payload.comment.user.login}*` + }); + } + + } catch (error) { + console.log('Failed to post review:', error.message); + console.log('Error details:', error); + } + env: + GITHUB_TOKEN: ${{ github.token }} + + - name: Upload Review Artifacts + uses: actions/upload-artifact@v4 + if: always() + with: + name: inline-review-results + path: | + inline_review.json + inline_review_prompt.txt + pr_files.json + pr_diff.txt + retention-days: 7 \ No newline at end of file From 9da29054f4506193a09c870e00d7df57c1a61131 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 12 Aug 2025 13:17:36 -0700 Subject: [PATCH 02/14] improv: logs --- .github/workflows/continue-inline-review.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/continue-inline-review.yaml b/.github/workflows/continue-inline-review.yaml index 2589f93d4..29d1c1413 100644 --- a/.github/workflows/continue-inline-review.yaml +++ b/.github/workflows/continue-inline-review.yaml @@ -119,6 +119,10 @@ jobs: # Run the CLI and capture JSON output cat inline_review_prompt.txt | cn --readonly --org continuedev --config continuedev/review-bot -p > inline_review.json + # Log the output for debugging + echo "Continue CLI output:" + cat inline_review.json + # Validate JSON output if ! jq empty inline_review.json 2>/dev/null; then echo "Invalid JSON output from Continue CLI" From 2bf6034068a0a996a012c0a4601685aaa22b12a0 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 12 Aug 2025 13:18:05 -0700 Subject: [PATCH 03/14] fix: add json flag --- .github/workflows/continue-inline-review.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continue-inline-review.yaml b/.github/workflows/continue-inline-review.yaml index 29d1c1413..a732b77f7 100644 --- a/.github/workflows/continue-inline-review.yaml +++ b/.github/workflows/continue-inline-review.yaml @@ -117,7 +117,7 @@ jobs: echo "Running Continue CLI for inline review..." # Run the CLI and capture JSON output - cat inline_review_prompt.txt | cn --readonly --org continuedev --config continuedev/review-bot -p > inline_review.json + cat inline_review_prompt.txt | cn --readonly --json --org continuedev --config continuedev/review-bot -p > inline_review.json # Log the output for debugging echo "Continue CLI output:" From 0153a73d77cad2622abd51cb521e894eb76d8c4b Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 12 Aug 2025 13:21:55 -0700 Subject: [PATCH 04/14] fix: format json --- .github/workflows/continue-inline-review.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continue-inline-review.yaml b/.github/workflows/continue-inline-review.yaml index a732b77f7..c18ed6092 100644 --- a/.github/workflows/continue-inline-review.yaml +++ b/.github/workflows/continue-inline-review.yaml @@ -117,7 +117,7 @@ jobs: echo "Running Continue CLI for inline review..." # Run the CLI and capture JSON output - cat inline_review_prompt.txt | cn --readonly --json --org continuedev --config continuedev/review-bot -p > inline_review.json + cat inline_review_prompt.txt | cn --readonly --format json --org continuedev --config continuedev/review-bot -p > inline_review.json # Log the output for debugging echo "Continue CLI output:" From 7f335007e46acf52d13eff2b6ed98e1f3ecf2f4e Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 13 Aug 2025 11:25:10 -0700 Subject: [PATCH 05/14] improv: use hardcoded version of the cli --- .github/workflows/continue-inline-review.yaml | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/continue-inline-review.yaml b/.github/workflows/continue-inline-review.yaml index c18ed6092..470f70866 100644 --- a/.github/workflows/continue-inline-review.yaml +++ b/.github/workflows/continue-inline-review.yaml @@ -43,7 +43,7 @@ jobs: node-version: 20 - name: Install Continue CLI - run: npm install -g @continuedev/cli@latest + run: npm install -g @continuedev/cli@1.4.25 - name: Build Inline Review Prompt run: | @@ -54,29 +54,29 @@ jobs: # For issue_comment event on a PR PR_NUMBER="${{ github.event.issue.number }}" fi - + # Get PR files with line numbers gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/files > pr_files.json - + # Get PR diff with context gh pr diff $PR_NUMBER --color=never > pr_diff.txt - + # Create review prompt for inline comments cat > inline_review_prompt.txt << 'EOF' You are conducting a detailed inline code review for a pull request. - + Your task is to analyze the code changes and generate specific, actionable review comments for individual lines or small sections of code. - + Below is the PR diff: - + EOF - + cat pr_diff.txt >> inline_review_prompt.txt - + cat >> inline_review_prompt.txt << 'EOF' - + Please analyze these changes and provide inline review comments in the following JSON format: - + { "review_summary": "Overall assessment of the PR", "comments": [ @@ -88,13 +88,13 @@ jobs: } ] } - + Focus on: 1. **Critical Issues**: Security vulnerabilities, bugs that will break functionality 2. **High Priority**: Performance problems, incorrect logic, missing error handling 3. **Medium Priority**: Code style violations, potential edge cases, unclear code 4. **Low Priority**: Suggestions for improvement, refactoring opportunities - + Guidelines for comments: - Be specific and actionable - Reference the exact line number from the diff @@ -102,7 +102,7 @@ jobs: - Suggest concrete improvements when pointing out issues - Only comment on actual problems or important improvements - Use "RIGHT" for new/modified lines, "LEFT" for context about removed lines - + Important: - Output ONLY valid JSON, no additional text - Ensure line numbers match the actual diff @@ -115,14 +115,14 @@ jobs: - name: Run Continue CLI Inline Review run: | echo "Running Continue CLI for inline review..." - + # Run the CLI and capture JSON output cat inline_review_prompt.txt | cn --readonly --format json --org continuedev --config continuedev/review-bot -p > inline_review.json - + # Log the output for debugging echo "Continue CLI output:" cat inline_review.json - + # Validate JSON output if ! jq empty inline_review.json 2>/dev/null; then echo "Invalid JSON output from Continue CLI" @@ -136,7 +136,7 @@ jobs: with: script: | const fs = require('fs'); - + try { // Read the review output let reviewData; @@ -240,4 +240,4 @@ jobs: inline_review_prompt.txt pr_files.json pr_diff.txt - retention-days: 7 \ No newline at end of file + retention-days: 7 From 474e5dc82b906fa8fb07791aea0352b7259adc31 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 13 Aug 2025 13:48:38 -0700 Subject: [PATCH 06/14] improv: naming --- .github/pull_request_template.md | 2 +- ...nue-inline-review.yaml => continue-detailed-review.yaml} | 6 +++--- .../{continue-review.yaml => continue-general-review.yaml} | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) rename .github/workflows/{continue-inline-review.yaml => continue-detailed-review.yaml} (97%) rename .github/workflows/{continue-review.yaml => continue-general-review.yaml} (97%) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 281f61c1f..d8b354440 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -5,7 +5,7 @@ ## AI Code Review - **Team members only**: AI review runs automatically when PR is opened or marked ready for review -- Team members can also trigger a review by commenting `@continue-review` +- Team members can also trigger a review by commenting `@continue-general-review` or `@continue-detailed-review` ## Checklist diff --git a/.github/workflows/continue-inline-review.yaml b/.github/workflows/continue-detailed-review.yaml similarity index 97% rename from .github/workflows/continue-inline-review.yaml rename to .github/workflows/continue-detailed-review.yaml index 470f70866..a28b03eac 100644 --- a/.github/workflows/continue-inline-review.yaml +++ b/.github/workflows/continue-detailed-review.yaml @@ -1,4 +1,4 @@ -name: Continue CLI Inline Code Review +name: Continue Detailed Review on: pull_request: @@ -18,7 +18,7 @@ jobs: timeout-minutes: 10 # Only run if: # - It's a PR event from a team member (with write/admin permissions) - # - OR it's a comment with @continue-inline-review on a PR from a team member + # - OR it's a comment with @continue-detailed-review on a PR from a team member if: > (github.event_name == 'pull_request' && (github.event.pull_request.author_association == 'OWNER' || @@ -26,7 +26,7 @@ jobs: github.event.pull_request.author_association == 'COLLABORATOR')) || (github.event_name == 'issue_comment' && github.event.issue.pull_request && - contains(github.event.comment.body, '@continue-inline-review') && + contains(github.event.comment.body, '@continue-detailed-review') && (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR')) diff --git a/.github/workflows/continue-review.yaml b/.github/workflows/continue-general-review.yaml similarity index 97% rename from .github/workflows/continue-review.yaml rename to .github/workflows/continue-general-review.yaml index 3ca4ffab4..d714c8574 100644 --- a/.github/workflows/continue-review.yaml +++ b/.github/workflows/continue-general-review.yaml @@ -1,4 +1,4 @@ -name: Continue CLI Code Review +name: Continue General Review on: pull_request: @@ -18,7 +18,7 @@ jobs: timeout-minutes: 10 # Only run if: # - It's a PR event from a team member (with write/admin permissions) - # - OR it's a comment with @continue-review on a PR from a team member + # - OR it's a comment with @continue-general-review on a PR from a team member if: | (github.event_name == 'pull_request' && (github.event.pull_request.author_association == 'OWNER' || @@ -26,7 +26,7 @@ jobs: github.event.pull_request.author_association == 'COLLABORATOR')) || (github.event_name == 'issue_comment' && github.event.issue.pull_request && - contains(github.event.comment.body, '@continue-review') && + contains(github.event.comment.body, '@continue-general-review') && (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR')) From 1a91a2d4a3de21d48f155f07f24a1f62b0993f53 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 13 Aug 2025 14:04:07 -0700 Subject: [PATCH 07/14] improv: comment handling --- .../workflows/continue-detailed-review.yaml | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/continue-detailed-review.yaml b/.github/workflows/continue-detailed-review.yaml index a28b03eac..279b75b97 100644 --- a/.github/workflows/continue-detailed-review.yaml +++ b/.github/workflows/continue-detailed-review.yaml @@ -82,8 +82,7 @@ jobs: "comments": [ { "path": "path/to/file.js", - "line": 42, - "side": "RIGHT", + "position": 42, "body": "Brief, specific comment about this line or section" } ] @@ -97,15 +96,14 @@ jobs: Guidelines for comments: - Be specific and actionable - - Reference the exact line number from the diff + - Reference the exact position in the diff (position is the line number in the diff, not the file) - Keep comments concise but informative - Suggest concrete improvements when pointing out issues - Only comment on actual problems or important improvements - - Use "RIGHT" for new/modified lines, "LEFT" for context about removed lines Important: - Output ONLY valid JSON, no additional text - - Ensure line numbers match the actual diff + - Position numbers should correspond to lines in the diff output (starting from 1) - Comment on the most important issues first - Limit to maximum 20 most relevant comments EOF @@ -168,13 +166,19 @@ jobs: const commitSha = pr.head.sha; - // Prepare review comments - const comments = reviewData.comments?.map(comment => ({ + // Prepare review comments - filter out comments without valid positions + const allComments = reviewData.comments || []; + const validComments = allComments.filter(comment => comment.position && comment.path && comment.body); + + if (validComments.length < allComments.length) { + console.log(`Filtered out ${allComments.length - validComments.length} comments due to missing position, path, or body`); + } + + const comments = validComments.map(comment => ({ path: comment.path, - line: comment.line || 1, - side: comment.side || 'RIGHT', + position: comment.position, body: comment.body - })) || []; + })); // Create the review if (comments.length > 0) { From ae723c23485aad5dbfc51c554e2bcc8f489aed57 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 13 Aug 2025 14:12:20 -0700 Subject: [PATCH 08/14] fix: naming --- .github/workflows/continue-detailed-review.yaml | 4 ++-- .github/workflows/continue-general-review.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continue-detailed-review.yaml b/.github/workflows/continue-detailed-review.yaml index 279b75b97..266565bfa 100644 --- a/.github/workflows/continue-detailed-review.yaml +++ b/.github/workflows/continue-detailed-review.yaml @@ -12,8 +12,8 @@ permissions: issues: write jobs: - inline-code-review: - name: AI Inline Code Review + detailed-code-review: + name: Continue Detailed Review runs-on: ubuntu-latest timeout-minutes: 10 # Only run if: diff --git a/.github/workflows/continue-general-review.yaml b/.github/workflows/continue-general-review.yaml index d714c8574..54f8a84b6 100644 --- a/.github/workflows/continue-general-review.yaml +++ b/.github/workflows/continue-general-review.yaml @@ -12,8 +12,8 @@ permissions: issues: write jobs: - code-review: - name: AI Code Review + general-code-review: + name: Continue General Review runs-on: ubuntu-latest timeout-minutes: 10 # Only run if: From 7fcc42a4730a15efa33b7e337c386035f76b7248 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 13 Aug 2025 14:20:31 -0700 Subject: [PATCH 09/14] fix: use line numbers --- .github/workflows/continue-detailed-review.yaml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/continue-detailed-review.yaml b/.github/workflows/continue-detailed-review.yaml index 266565bfa..c8b24e5f3 100644 --- a/.github/workflows/continue-detailed-review.yaml +++ b/.github/workflows/continue-detailed-review.yaml @@ -82,7 +82,8 @@ jobs: "comments": [ { "path": "path/to/file.js", - "position": 42, + "line": 42, + "side": "RIGHT", "body": "Brief, specific comment about this line or section" } ] @@ -96,14 +97,15 @@ jobs: Guidelines for comments: - Be specific and actionable - - Reference the exact position in the diff (position is the line number in the diff, not the file) + - Reference the exact line number from the file - Keep comments concise but informative - Suggest concrete improvements when pointing out issues - Only comment on actual problems or important improvements + - Use "RIGHT" for new/modified lines, "LEFT" for context about removed lines Important: - Output ONLY valid JSON, no additional text - - Position numbers should correspond to lines in the diff output (starting from 1) + - Line numbers should match the actual line numbers in the files - Comment on the most important issues first - Limit to maximum 20 most relevant comments EOF @@ -166,17 +168,18 @@ jobs: const commitSha = pr.head.sha; - // Prepare review comments - filter out comments without valid positions + // Prepare review comments - filter out comments without required fields const allComments = reviewData.comments || []; - const validComments = allComments.filter(comment => comment.position && comment.path && comment.body); + const validComments = allComments.filter(comment => comment.line && comment.path && comment.body && comment.side); if (validComments.length < allComments.length) { - console.log(`Filtered out ${allComments.length - validComments.length} comments due to missing position, path, or body`); + console.log(`Filtered out ${allComments.length - validComments.length} comments due to missing line, path, body, or side`); } const comments = validComments.map(comment => ({ path: comment.path, - position: comment.position, + line: comment.line, + side: comment.side, body: comment.body })); From e26549165948d856d2930e179520b50eb4ed92dd Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 13 Aug 2025 14:26:37 -0700 Subject: [PATCH 10/14] fix: prompt --- .github/workflows/continue-detailed-review.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continue-detailed-review.yaml b/.github/workflows/continue-detailed-review.yaml index c8b24e5f3..d22fe55f2 100644 --- a/.github/workflows/continue-detailed-review.yaml +++ b/.github/workflows/continue-detailed-review.yaml @@ -97,7 +97,7 @@ jobs: Guidelines for comments: - Be specific and actionable - - Reference the exact line number from the file + - Reference the exact line number from the diff - Keep comments concise but informative - Suggest concrete improvements when pointing out issues - Only comment on actual problems or important improvements @@ -105,7 +105,7 @@ jobs: Important: - Output ONLY valid JSON, no additional text - - Line numbers should match the actual line numbers in the files + - Ensure line numbers match the actual diff - Comment on the most important issues first - Limit to maximum 20 most relevant comments EOF From c920368413c71c2c471b85c85798b8adfaff4363 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 13 Aug 2025 14:28:33 -0700 Subject: [PATCH 11/14] improv: use commit SHA for security --- .github/workflows/continue-detailed-review.yaml | 2 +- .github/workflows/continue-general-review.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continue-detailed-review.yaml b/.github/workflows/continue-detailed-review.yaml index d22fe55f2..bf20a1dcd 100644 --- a/.github/workflows/continue-detailed-review.yaml +++ b/.github/workflows/continue-detailed-review.yaml @@ -33,7 +33,7 @@ jobs: steps: - name: Checkout Repository - uses: actions/checkout@v4 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: fetch-depth: 0 # Fetch full history for better context diff --git a/.github/workflows/continue-general-review.yaml b/.github/workflows/continue-general-review.yaml index 54f8a84b6..b78a8c810 100644 --- a/.github/workflows/continue-general-review.yaml +++ b/.github/workflows/continue-general-review.yaml @@ -33,7 +33,7 @@ jobs: steps: - name: Checkout Repository - uses: actions/checkout@v5 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: fetch-depth: 0 # Fetch full history for better context From 928aacc0f664a17b73a7ce465363f11321f08311 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 13 Aug 2025 14:41:56 -0700 Subject: [PATCH 12/14] fix: handle positions --- .../workflows/continue-detailed-review.yaml | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/.github/workflows/continue-detailed-review.yaml b/.github/workflows/continue-detailed-review.yaml index bf20a1dcd..69c6a5659 100644 --- a/.github/workflows/continue-detailed-review.yaml +++ b/.github/workflows/continue-detailed-review.yaml @@ -67,6 +67,29 @@ jobs: Your task is to analyze the code changes and generate specific, actionable review comments for individual lines or small sections of code. + CRITICAL: Understanding "position" for GitHub PR comments: + The "position" field is the line number within the diff, NOT the file line number. + + Example diff and position counting: + ``` + diff --git a/src/app.js b/src/app.js + index abc123..def456 100644 + --- a/src/app.js + +++ b/src/app.js + @@ -10,4 +10,6 @@ function example() { <-- This is the @@ header, not counted + console.log("context"); <-- position 1 (first line after @@) + - const old = "remove this"; <-- position 2 + + const new = "add this"; <-- position 3 + + const risky = eval(userInput); <-- position 4 (comment here about security issue!) + return result; <-- position 5 + + console.log("done"); <-- position 6 + @@ -20,3 +22,4 @@ function another() { <-- New @@ header, restart counting! + let x = 1; <-- position 1 (for this hunk) + + let y = 2; <-- position 2 (for this hunk) + ``` + + To comment on the risky eval line above, use: {"path": "src/app.js", "position": 4, "body": "Avoid using eval..."} + Below is the PR diff: EOF @@ -82,8 +105,7 @@ jobs: "comments": [ { "path": "path/to/file.js", - "line": 42, - "side": "RIGHT", + "position": 4, "body": "Brief, specific comment about this line or section" } ] @@ -97,15 +119,17 @@ jobs: Guidelines for comments: - Be specific and actionable - - Reference the exact line number from the diff + - Count position starting from 1 after each @@ header line + - Include ALL lines in count: context lines, additions (+), and deletions (-) + - Reset position count to 1 after each new @@ header - Keep comments concise but informative - Suggest concrete improvements when pointing out issues - Only comment on actual problems or important improvements - - Use "RIGHT" for new/modified lines, "LEFT" for context about removed lines Important: - Output ONLY valid JSON, no additional text - - Ensure line numbers match the actual diff + - Position is counted within the diff, NOT the file line number + - Only comment on changed lines (+ or - prefix) - Comment on the most important issues first - Limit to maximum 20 most relevant comments EOF @@ -170,16 +194,23 @@ jobs: // Prepare review comments - filter out comments without required fields const allComments = reviewData.comments || []; - const validComments = allComments.filter(comment => comment.line && comment.path && comment.body && comment.side); + const validComments = allComments.filter(comment => + comment.position && + comment.path && + comment.body && + typeof comment.position === 'number' && + comment.position > 0 + ); if (validComments.length < allComments.length) { - console.log(`Filtered out ${allComments.length - validComments.length} comments due to missing line, path, body, or side`); + console.log(`Filtered out ${allComments.length - validComments.length} comments due to missing/invalid position, path, or body`); + const invalidComments = allComments.filter(c => !validComments.includes(c)); + console.log('Invalid comments:', JSON.stringify(invalidComments, null, 2)); } const comments = validComments.map(comment => ({ path: comment.path, - line: comment.line, - side: comment.side, + position: comment.position, body: comment.body })); From 98c2bf3e148da0e4e4e6b34ec71483ead70e8453 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 13 Aug 2025 14:53:15 -0700 Subject: [PATCH 13/14] improv: add position fixing second pass --- .../workflows/continue-detailed-review.yaml | 60 +++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continue-detailed-review.yaml b/.github/workflows/continue-detailed-review.yaml index 69c6a5659..bcba06ba5 100644 --- a/.github/workflows/continue-detailed-review.yaml +++ b/.github/workflows/continue-detailed-review.yaml @@ -141,16 +141,66 @@ jobs: echo "Running Continue CLI for inline review..." # Run the CLI and capture JSON output - cat inline_review_prompt.txt | cn --readonly --format json --org continuedev --config continuedev/review-bot -p > inline_review.json + cat inline_review_prompt.txt | cn --readonly --format json --org continuedev --config continuedev/review-bot -p > inline_review_raw.json # Log the output for debugging - echo "Continue CLI output:" - cat inline_review.json + echo "Initial Continue CLI output:" + cat inline_review_raw.json # Validate JSON output - if ! jq empty inline_review.json 2>/dev/null; then + if ! jq empty inline_review_raw.json 2>/dev/null; then echo "Invalid JSON output from Continue CLI" echo "{\"review_summary\": \"Failed to generate review\", \"comments\": []}" > inline_review.json + else + # Second pass: Fix positions using Continue CLI + echo "Running second pass to fix comment positions..." + + # Create position fixing prompt + cat > fix_positions_prompt.txt << 'EOF' + You are a position calculator for GitHub PR review comments. Your ONLY job is to calculate the correct position values for inline comments. + + Here is the PR diff with line numbers added for reference: + EOF + + # Add line numbers to the diff for clarity + cat pr_diff.txt | nl -ba -v 1 >> fix_positions_prompt.txt + + cat >> fix_positions_prompt.txt << 'EOF' + + Here are the review comments that need position fixing: + EOF + + cat inline_review_raw.json >> fix_positions_prompt.txt + + cat >> fix_positions_prompt.txt << 'EOF' + + For each comment, find the exact line in the numbered diff above and return the CORRECT position. + Remember: Position is the line number in the diff (the number shown at the start of each line above). + + Return ONLY valid JSON in this exact format: + { + "review_summary": [copy the original review_summary], + "comments": [ + { + "path": [original path], + "position": [the line number from the numbered diff above], + "body": [original body] + } + ] + } + + Important: + - Use the line numbers shown in the numbered diff above + - Only include comments where you can find the exact matching line + - If you cannot find a good match for a comment, skip it + - Output ONLY valid JSON + EOF + + # Run the position fixer + cat fix_positions_prompt.txt | cn --readonly --format json --org continuedev --config continuedev/review-bot -p > inline_review.json + + echo "Fixed positions output:" + cat inline_review.json fi env: CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }} @@ -274,7 +324,9 @@ jobs: with: name: inline-review-results path: | + inline_review_raw.json inline_review.json + fix_positions_prompt.txt inline_review_prompt.txt pr_files.json pr_diff.txt From a6c0469c00c1b110126761c938094045b7d576a5 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 13 Aug 2025 15:14:19 -0700 Subject: [PATCH 14/14] improv: position calculation --- .../workflows/continue-detailed-review.yaml | 117 +++++++----------- 1 file changed, 47 insertions(+), 70 deletions(-) diff --git a/.github/workflows/continue-detailed-review.yaml b/.github/workflows/continue-detailed-review.yaml index bcba06ba5..488856df3 100644 --- a/.github/workflows/continue-detailed-review.yaml +++ b/.github/workflows/continue-detailed-review.yaml @@ -61,40 +61,57 @@ jobs: # Get PR diff with context gh pr diff $PR_NUMBER --color=never > pr_diff.txt + # Annotate diff with position numbers for easy reference + awk ' + /^@@/ { + pos = 0 + print + next + } + /^diff --git/ || /^index / || /^--- / || /^\+\+\+ / { + print + next + } + { + pos++ + printf "[POS:%d] %s\n", pos, $0 + } + ' pr_diff.txt > pr_diff_annotated.txt + # Create review prompt for inline comments cat > inline_review_prompt.txt << 'EOF' You are conducting a detailed inline code review for a pull request. Your task is to analyze the code changes and generate specific, actionable review comments for individual lines or small sections of code. - CRITICAL: Understanding "position" for GitHub PR comments: - The "position" field is the line number within the diff, NOT the file line number. + IMPORTANT: The diff below has been annotated with [POS:N] markers showing the exact position for each line. - Example diff and position counting: + Example of how to use the position markers: ``` diff --git a/src/app.js b/src/app.js index abc123..def456 100644 --- a/src/app.js +++ b/src/app.js - @@ -10,4 +10,6 @@ function example() { <-- This is the @@ header, not counted - console.log("context"); <-- position 1 (first line after @@) - - const old = "remove this"; <-- position 2 - + const new = "add this"; <-- position 3 - + const risky = eval(userInput); <-- position 4 (comment here about security issue!) - return result; <-- position 5 - + console.log("done"); <-- position 6 - @@ -20,3 +22,4 @@ function another() { <-- New @@ header, restart counting! - let x = 1; <-- position 1 (for this hunk) - + let y = 2; <-- position 2 (for this hunk) + @@ -10,4 +10,6 @@ function example() { + [POS:1] console.log("context"); + [POS:2] - const old = "remove this"; + [POS:3] + const new = "add this"; + [POS:4] + const risky = eval(userInput); <-- To comment here, use position: 4 + [POS:5] return result; + [POS:6] + console.log("done"); + @@ -20,3 +22,4 @@ function another() { + [POS:1] let x = 1; + [POS:2] + let y = 2; <-- To comment here, use position: 2 ``` - To comment on the risky eval line above, use: {"path": "src/app.js", "position": 4, "body": "Avoid using eval..."} + To comment on a line, simply use the number from its [POS:N] marker as the position value. + For example: {"path": "src/app.js", "position": 4, "body": "Avoid using eval with user input"} - Below is the PR diff: + Below is the annotated PR diff: EOF - cat pr_diff.txt >> inline_review_prompt.txt + cat pr_diff_annotated.txt >> inline_review_prompt.txt cat >> inline_review_prompt.txt << 'EOF' @@ -119,17 +136,15 @@ jobs: Guidelines for comments: - Be specific and actionable - - Count position starting from 1 after each @@ header line - - Include ALL lines in count: context lines, additions (+), and deletions (-) - - Reset position count to 1 after each new @@ header + - Use the [POS:N] number shown in the diff as the position value - Keep comments concise but informative - Suggest concrete improvements when pointing out issues - Only comment on actual problems or important improvements Important: - Output ONLY valid JSON, no additional text - - Position is counted within the diff, NOT the file line number - - Only comment on changed lines (+ or - prefix) + - Use the exact number from [POS:N] markers as the position + - Only comment on changed lines (lines with + or - prefix) - Comment on the most important issues first - Limit to maximum 20 most relevant comments EOF @@ -139,6 +154,13 @@ jobs: - name: Run Continue CLI Inline Review run: | echo "Running Continue CLI for inline review..." + + # Log the prompt for debugging + echo "===== START REVIEW PROMPT =====" + head -n 50 inline_review_prompt.txt + echo "... [diff content] ..." + tail -n 20 inline_review_prompt.txt + echo "===== END REVIEW PROMPT =====" # Run the CLI and capture JSON output cat inline_review_prompt.txt | cn --readonly --format json --org continuedev --config continuedev/review-bot -p > inline_review_raw.json @@ -152,54 +174,9 @@ jobs: echo "Invalid JSON output from Continue CLI" echo "{\"review_summary\": \"Failed to generate review\", \"comments\": []}" > inline_review.json else - # Second pass: Fix positions using Continue CLI - echo "Running second pass to fix comment positions..." - - # Create position fixing prompt - cat > fix_positions_prompt.txt << 'EOF' - You are a position calculator for GitHub PR review comments. Your ONLY job is to calculate the correct position values for inline comments. - - Here is the PR diff with line numbers added for reference: - EOF - - # Add line numbers to the diff for clarity - cat pr_diff.txt | nl -ba -v 1 >> fix_positions_prompt.txt - - cat >> fix_positions_prompt.txt << 'EOF' - - Here are the review comments that need position fixing: - EOF - - cat inline_review_raw.json >> fix_positions_prompt.txt - - cat >> fix_positions_prompt.txt << 'EOF' - - For each comment, find the exact line in the numbered diff above and return the CORRECT position. - Remember: Position is the line number in the diff (the number shown at the start of each line above). - - Return ONLY valid JSON in this exact format: - { - "review_summary": [copy the original review_summary], - "comments": [ - { - "path": [original path], - "position": [the line number from the numbered diff above], - "body": [original body] - } - ] - } - - Important: - - Use the line numbers shown in the numbered diff above - - Only include comments where you can find the exact matching line - - If you cannot find a good match for a comment, skip it - - Output ONLY valid JSON - EOF - - # Run the position fixer - cat fix_positions_prompt.txt | cn --readonly --format json --org continuedev --config continuedev/review-bot -p > inline_review.json - - echo "Fixed positions output:" + # Use the output directly since positions are already correct + cp inline_review_raw.json inline_review.json + echo "Review output:" cat inline_review.json fi env: @@ -326,8 +303,8 @@ jobs: path: | inline_review_raw.json inline_review.json - fix_positions_prompt.txt inline_review_prompt.txt pr_files.json pr_diff.txt + pr_diff_annotated.txt retention-days: 7