|
| 1 | +use crate::config; |
| 2 | + |
| 3 | +pub(super) fn collect_guidance_sections( |
| 4 | + config: &config::Config, |
| 5 | + path_config: Option<&config::PathConfig>, |
| 6 | +) -> Vec<String> { |
| 7 | + let mut sections = vec![strictness_section(config)]; |
| 8 | + |
| 9 | + push_section(&mut sections, comment_types_section(config)); |
| 10 | + push_section(&mut sections, review_profile_section(config)); |
| 11 | + push_section(&mut sections, global_instructions_section(config)); |
| 12 | + push_section(&mut sections, path_instructions_section(path_config)); |
| 13 | + push_section(&mut sections, output_language_section(config)); |
| 14 | + sections.push(fix_suggestion_section(config)); |
| 15 | + |
| 16 | + sections |
| 17 | +} |
| 18 | + |
| 19 | +fn strictness_section(config: &config::Config) -> String { |
| 20 | + let strictness_guidance = match config.strictness { |
| 21 | + 1 => "Prefer high-signal findings only. Avoid low-impact nitpicks and optional suggestions.", |
| 22 | + 3 => { |
| 23 | + "Be exhaustive. Surface meaningful edge cases and maintainability concerns, including lower-severity findings." |
| 24 | + } |
| 25 | + _ => "Balance precision and coverage; prioritize clear, actionable findings.", |
| 26 | + }; |
| 27 | + |
| 28 | + format!( |
| 29 | + "Strictness ({}): {}", |
| 30 | + config.strictness, strictness_guidance |
| 31 | + ) |
| 32 | +} |
| 33 | + |
| 34 | +fn comment_types_section(config: &config::Config) -> Option<String> { |
| 35 | + if config.comment_types.is_empty() { |
| 36 | + None |
| 37 | + } else { |
| 38 | + Some(format!( |
| 39 | + "Enabled comment types: {}. Do not emit findings outside these types.", |
| 40 | + config.comment_types.join(", ") |
| 41 | + )) |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +fn review_profile_section(config: &config::Config) -> Option<String> { |
| 46 | + let profile = config.review_profile.as_deref()?; |
| 47 | + let guidance = match profile { |
| 48 | + "chill" => Some( |
| 49 | + "Be conservative and only surface high-confidence, high-impact issues. Avoid nitpicks and redundant comments.", |
| 50 | + ), |
| 51 | + "assertive" => Some( |
| 52 | + "Be thorough and proactive. Surface edge cases, latent risks, and maintainability concerns even if they are subtle.", |
| 53 | + ), |
| 54 | + _ => None, |
| 55 | + }?; |
| 56 | + |
| 57 | + Some(format!("Review profile ({}): {}", profile, guidance)) |
| 58 | +} |
| 59 | + |
| 60 | +fn global_instructions_section(config: &config::Config) -> Option<String> { |
| 61 | + let instructions = config.review_instructions.as_deref()?.trim(); |
| 62 | + if instructions.is_empty() { |
| 63 | + None |
| 64 | + } else { |
| 65 | + Some(format!("Global review instructions:\n{}", instructions)) |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +fn path_instructions_section(path_config: Option<&config::PathConfig>) -> Option<String> { |
| 70 | + let instructions = path_config?.review_instructions.as_deref()?.trim(); |
| 71 | + if instructions.is_empty() { |
| 72 | + None |
| 73 | + } else { |
| 74 | + Some(format!("Path-specific instructions:\n{}", instructions)) |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +fn output_language_section(config: &config::Config) -> Option<String> { |
| 79 | + let lang = config.output_language.as_deref()?; |
| 80 | + if lang == "en" || lang.starts_with("en-") { |
| 81 | + None |
| 82 | + } else { |
| 83 | + Some(format!( |
| 84 | + "Write all review comments and suggestions in {}.", |
| 85 | + lang |
| 86 | + )) |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +fn fix_suggestion_section(config: &config::Config) -> String { |
| 91 | + if !config.include_fix_suggestions { |
| 92 | + "Do not include code fix suggestions. Only describe the issue. Do not include <<<ORIGINAL/>>>SUGGESTED blocks.".to_string() |
| 93 | + } else { |
| 94 | + "For every finding where a concrete code fix is possible, include a code suggestion block immediately after the issue line using this exact format:\n\n<<<ORIGINAL\n<the problematic code>\n===\n<the fixed code>\n>>>SUGGESTED\n\nAlways copy the original code verbatim from the diff. Only omit the block when no concrete fix can be expressed in code.".to_string() |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +fn push_section(sections: &mut Vec<String>, section: Option<String>) { |
| 99 | + if let Some(section) = section { |
| 100 | + sections.push(section); |
| 101 | + } |
| 102 | +} |
0 commit comments