aptu_core/config/review.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! PR review prompt configuration.
4
5use serde::{Deserialize, Serialize};
6
7/// PR review prompt configuration.
8///
9/// Controls prompt token budgets and GitHub API constraints for PR reviews:
10///
11/// - `max_prompt_chars`: 120,000 chars is a conservative budget below common LLM context
12/// window limits (e.g., 128k token models), accounting for system prompt and response overhead.
13/// - `max_full_content_files`: 10 files caps GitHub Contents API calls per review to limit
14/// latency and rate limit usage.
15/// - `max_chars_per_file`: 16,000 chars per file gives adequate context for most files
16/// without dominating the prompt budget; budget drop logic trims below 120k if needed.
17/// - `max_instructions_chars`: 1,500 chars caps repository instructions to prevent prompt bloat.
18#[derive(Debug, Deserialize, Serialize, Clone)]
19#[serde(default)]
20pub struct ReviewConfig {
21 /// Maximum total prompt character budget (default: `120_000`).
22 pub max_prompt_chars: usize,
23 /// Maximum number of files to fetch full content for (default: 10).
24 pub max_full_content_files: usize,
25 /// Maximum characters per file's full content (default: `16_000`).
26 pub max_chars_per_file: usize,
27 /// Maximum characters for repository instructions (default: `1_500`).
28 #[serde(default = "default_max_instructions_chars")]
29 pub max_instructions_chars: usize,
30 /// Optional path to repository instructions file (overrides default AGENTS.md and .github/instructions/pr-review.md).
31 #[serde(default)]
32 pub instructions_file: Option<String>,
33 /// Minimum remaining prompt budget to auto-enable call graph (default: `20_000`).
34 #[serde(default = "default_min_budget_for_call_graph")]
35 pub min_budget_for_call_graph: usize,
36 /// Maximum characters for dependency release notes (default: `2_000`).
37 #[serde(default = "default_max_dep_release_chars")]
38 pub max_dep_release_chars: usize,
39 /// Maximum number of dependency packages to enrich (default: 3).
40 #[serde(default = "default_max_dep_packages")]
41 pub max_dep_packages: usize,
42}
43
44fn default_max_instructions_chars() -> usize {
45 1_500
46}
47
48fn default_min_budget_for_call_graph() -> usize {
49 20_000
50}
51
52fn default_max_dep_release_chars() -> usize {
53 2_000
54}
55
56fn default_max_dep_packages() -> usize {
57 3
58}
59
60impl Default for ReviewConfig {
61 fn default() -> Self {
62 Self {
63 max_prompt_chars: 120_000, // Conservative budget for LLM context windows with overhead
64 max_full_content_files: 10, // Cap GitHub Contents API calls to limit latency and rate limits
65 max_chars_per_file: 16_000, // Adequate context per file; budget drop logic trims total below 120k
66 max_instructions_chars: 1_500, // Cap repository instructions to prevent prompt bloat
67 instructions_file: None,
68 min_budget_for_call_graph: 20_000, // Auto-enable call graph if remaining budget exceeds this
69 max_dep_release_chars: 2_000, // Cap dependency release notes to prevent prompt bloat
70 max_dep_packages: 3, // Limit enriched packages to avoid excessive API calls
71 }
72 }
73}