diff --git a/crates/forge_app/src/git_app.rs b/crates/forge_app/src/git_app.rs index 8751d913ca..9bf871f7a4 100644 --- a/crates/forge_app/src/git_app.rs +++ b/crates/forge_app/src/git_app.rs @@ -224,15 +224,12 @@ where /// Fetches git context (branch name and recent commits) async fn fetch_git_context(&self, cwd: &Path) -> Result<(String, String)> { + let max_commit_count = self.services.get_environment().max_commit_count; + let git_log_cmd = + format!("git log --pretty=format:%s --abbrev-commit --max-count={max_commit_count}"); let (recent_commits, branch_name) = tokio::join!( - self.services.execute( - "git log --pretty=format:%s --abbrev-commit --max-count=20".into(), - cwd.to_path_buf(), - false, - true, - None, - None, - ), + self.services + .execute(git_log_cmd, cwd.to_path_buf(), false, true, None, None,), self.services.execute( "git rev-parse --abbrev-ref HEAD".into(), cwd.to_path_buf(), diff --git a/crates/forge_app/src/orch_spec/orch_setup.rs b/crates/forge_app/src/orch_spec/orch_setup.rs index f03ff78aca..1a1ddbcae0 100644 --- a/crates/forge_app/src/orch_spec/orch_setup.rs +++ b/crates/forge_app/src/orch_spec/orch_setup.rs @@ -96,6 +96,7 @@ impl Default for TestContext { model_cache_ttl: 604_800, session: None, commit: None, + max_commit_count: 20, suggest: None, is_restricted: false, temperature: None, diff --git a/crates/forge_config/src/config.rs b/crates/forge_config/src/config.rs index 366633054e..189bfe11e1 100644 --- a/crates/forge_config/src/config.rs +++ b/crates/forge_config/src/config.rs @@ -106,6 +106,10 @@ pub struct ForgeConfig { /// Model and provider configuration used for commit message generation. #[serde(default, skip_serializing_if = "Option::is_none")] pub commit: Option, + /// Maximum number of recent commits included as context for commit message + /// generation. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub max_commit_count: Option, /// Model and provider configuration used for shell command suggestion /// generation. #[serde(default, skip_serializing_if = "Option::is_none")] diff --git a/crates/forge_domain/src/env.rs b/crates/forge_domain/src/env.rs index 1db2b2903c..ea332a26eb 100644 --- a/crates/forge_domain/src/env.rs +++ b/crates/forge_domain/src/env.rs @@ -141,6 +141,9 @@ pub struct Environment { /// Provider and model for commit message generation. #[dummy(default)] pub commit: Option, + /// Maximum number of recent commits to include as context during commit + /// message generation. + pub max_commit_count: usize, /// Provider and model for shell command suggestion generation. #[dummy(default)] pub suggest: Option, diff --git a/crates/forge_infra/src/env.rs b/crates/forge_infra/src/env.rs index aeb5882838..6feb359979 100644 --- a/crates/forge_infra/src/env.rs +++ b/crates/forge_infra/src/env.rs @@ -165,6 +165,7 @@ fn to_environment(fc: ForgeConfig, cwd: PathBuf) -> Environment { model_cache_ttl: fc.model_cache_ttl_secs.unwrap_or_default(), session: fc.session.as_ref().map(to_session_config), commit: fc.commit.as_ref().map(to_session_config), + max_commit_count: fc.max_commit_count.unwrap_or(20), suggest: fc.suggest.as_ref().map(to_session_config), is_restricted: fc.restricted.unwrap_or_default(), tool_supported: fc.tool_supported.unwrap_or_default(), @@ -349,6 +350,7 @@ fn to_forge_config(env: &Environment) -> ForgeConfig { provider_id: sc.provider_id.clone(), model_id: sc.model_id.clone(), }); + fc.max_commit_count = Some(env.max_commit_count); fc.suggest = env.suggest.as_ref().map(|sc| ModelConfig { provider_id: sc.provider_id.clone(), model_id: sc.model_id.clone(), diff --git a/forge.schema.json b/forge.schema.json index b529d71e07..8c55d587f6 100644 --- a/forge.schema.json +++ b/forge.schema.json @@ -69,6 +69,15 @@ } ] }, + "max_commit_count": { + "description": "Maximum number of recent commits included as context for commit message\ngeneration.", + "type": [ + "integer", + "null" + ], + "format": "uint", + "minimum": 0 + }, "max_conversations": { "description": "Maximum number of conversations shown in the conversation list.", "type": [