@@ -3,8 +3,15 @@ import { Octokit } from "@octokit/rest";
33
44const prNumber = parseInt ( process . env . PR_NUMBER ) ;
55const githubToken = process . env . GITHUB_TOKEN ;
6- const [ repoOwner , repoName ] = ( process . env . GITHUB_REPOSITORY || "" ) . split ( "/" ) ;
6+ const repo = process . env . GITHUB_REPOSITORY || "" ;
7+ const [ repoOwner , repoName ] = repo . split ( "/" ) ;
78
9+ if ( ! prNumber || ! githubToken || ! repoOwner || ! repoName || ! process . env . ANTHROPIC_API_KEY ) {
10+ console . error ( "Missing required environment variables." ) ;
11+ process . exit ( 1 ) ;
12+ }
13+
14+ const MAX_DIFF_CHARS = 20000 ;
815const octokit = new Octokit ( { auth : githubToken } ) ;
916
1017async function runReview ( ) {
@@ -22,6 +29,11 @@ async function runReview() {
2229 return ;
2330 }
2431
32+ const wasTruncated = prDiff . length > MAX_DIFF_CHARS ;
33+ const truncatedDiff = wasTruncated
34+ ? prDiff . slice ( 0 , MAX_DIFF_CHARS ) + "\n\n... [diff truncated]"
35+ : prDiff ;
36+
2537 const prompt = `You are a senior Python engineer reviewing a pull request for the Node9 Python SDK.
2638Node9 is an execution security library — a @protect decorator that intercepts AI agent tool calls and asks for human approval before running them.
2739
@@ -34,16 +46,16 @@ Review the following git diff and provide concise, actionable feedback. Focus on
3446
3547If the changes look good with no issues, say so briefly.
3648Do NOT rewrite the code. Just review it.
37- Keep your review under 400 words.
49+ Keep your review under 800 words.
3850
3951## Git Diff:
40- ${ prDiff } `;
52+ ${ truncatedDiff } `;
4153
4254 console . log ( "Sending diff to Claude for review..." ) ;
4355 const client = new Anthropic ( { apiKey : process . env . ANTHROPIC_API_KEY } ) ;
4456 const message = await client . messages . create ( {
45- model : "claude-sonnet-4-5 " ,
46- max_tokens : 1024 ,
57+ model : "claude-sonnet-4-6 " ,
58+ max_tokens : 2048 ,
4759 messages : [ { role : "user" , content : prompt } ] ,
4860 } ) ;
4961
@@ -54,7 +66,7 @@ ${prDiff}`;
5466 owner : repoOwner ,
5567 repo : repoName ,
5668 issue_number : prNumber ,
57- body : `## 🤖 Claude Code Review\n\n${ review } \n\n---\n*Automated review by Claude Sonnet*` ,
69+ body : `## 🤖 Claude Code Review\n\n${ review } ${ wasTruncated ? "\n\n> ⚠️ **Note:** This diff exceeded 20,000 characters and was truncated. The review above covers only the first portion of the changes." : "" } \n\n---\n*Automated review by Claude Sonnet*` ,
5870 } ) ;
5971
6072 console . log ( "Review posted successfully." ) ;
0 commit comments