@@ -89,35 +89,36 @@ impl ReviewAnalyzer {
8989 } )
9090 }
9191
92- pub fn analyze_diff ( & mut self , diff : & str ) -> Result < String , JsError > {
93- let findings = self . analyze_diff_internal ( diff) ?;
92+ pub fn analyze_diff ( & mut self , diff : & str , context : & str ) -> Result < String , JsError > {
93+ let findings = self . analyze_diff_internal ( diff, context ) ?;
9494 serde_json:: to_string ( & findings)
9595 . map_err ( |e| JsError :: new ( & format ! ( "failed to serialize findings: {e}" ) ) )
9696 }
9797
9898 pub fn analyze_diff_chunked (
9999 & mut self ,
100100 diff : & str ,
101+ context : & str ,
101102 _max_tokens_per_chunk : u32 ,
102103 ) -> Result < String , JsError > {
103104 let chunks = split_diff_by_file ( diff) ;
104105 let mut all_findings: Vec < ReviewFinding > = Vec :: new ( ) ;
105106
106107 for chunk in chunks {
107- let chunk_findings = self . analyze_diff_internal ( & chunk) ?;
108+ let chunk_findings = self . analyze_diff_internal ( & chunk, context ) ?;
108109 all_findings. extend ( chunk_findings) ;
109110 }
110111
111112 serde_json:: to_string ( & all_findings)
112113 . map_err ( |e| JsError :: new ( & format ! ( "failed to serialize merged findings: {e}" ) ) )
113114 }
114115
115- fn analyze_diff_internal ( & mut self , diff : & str ) -> Result < Vec < ReviewFinding > , JsError > {
116+ fn analyze_diff_internal ( & mut self , diff : & str , context : & str ) -> Result < Vec < ReviewFinding > , JsError > {
116117 if diff. trim ( ) . is_empty ( ) {
117118 return Ok ( Vec :: new ( ) ) ;
118119 }
119120
120- let prompt = self . format_prompt ( diff) ;
121+ let prompt = self . format_prompt ( diff, context ) ;
121122 let response = self . generate ( & prompt, 1024 ) ?;
122123
123124 // Extract JSON block
@@ -134,9 +135,16 @@ impl ReviewAnalyzer {
134135}
135136
136137impl ReviewAnalyzer {
137- fn format_prompt ( & self , diff : & str ) -> String {
138+ fn format_prompt ( & self , diff : & str , context : & str ) -> String {
139+ let context_section = if context. is_empty ( ) {
140+ String :: new ( )
141+ } else {
142+ format ! ( "\n \n ### Business Context / Requirements:\n {}\n " , context)
143+ } ;
144+
138145 format ! (
139- "<|im_start|>system\n You are an expert Senior Software Engineer and Code Reviewer. Analyze the git diff and provide a comprehensive code review for TypeScript, NestJS, and React Native code.\n Focus on:\n 1. **Security**: Vulnerabilities, secrets, insecure handling.\n 2. **Quality**: Bugs, anti-patterns, logical errors.\n 3. **Performance**: Bottlenecks, inefficient code.\n 4. **Maintainability**: Readability, naming, complexity.\n \n Return a JSON array ONLY. Format: [{{ \" file\" : \" path\" , \" line\" : 12, \" severity\" : \" high\" |\" medium\" |\" low\" , \" category\" : \" security\" |\" quality\" |\" performance\" |\" maintainability\" , \" issue\" : \" description\" , \" suggested_fix\" : \" code\" }}]\n If no issues, return [].<|im_end|>\n <|im_start|>user\n Analyze this diff:\n {}\n <|im_end|>\n <|im_start|>assistant\n " ,
146+ "<|im_start|>system\n You are an expert Senior Software Engineer and Code Reviewer. Analyze the git diff and provide a comprehensive code review for TypeScript, NestJS, and React Native code.{} \n \n Focus on:\n 1. **Security**: Vulnerabilities, secrets, insecure handling.\n 2. **Quality**: Bugs, anti-patterns, logical errors.\n 3. **Performance**: Bottlenecks, inefficient code.\n 4. **Maintainability**: Readability, naming, complexity.\n \n Return a JSON array ONLY. Format: [{{ \" file\" : \" path\" , \" line\" : 12, \" severity\" : \" high\" |\" medium\" |\" low\" , \" category\" : \" security\" |\" quality\" |\" performance\" |\" maintainability\" , \" issue\" : \" description\" , \" suggested_fix\" : \" code\" }}]\n If no issues, return [].<|im_end|>\n <|im_start|>user\n Analyze this diff:\n {}\n <|im_end|>\n <|im_start|>assistant\n " ,
147+ context_section,
140148 diff
141149 )
142150 }
0 commit comments