perf: auto-populate git context natively to avoid token waste

- Added get_git_context() to utils.rs using git2 to natively fetch branch, commit, and repo_name without CLI overhead.
- Wired native auto-population into LogCodeChangeHandler, LogErrorFixHandler, TechDebtHandler, TasksHandler, MilestonesHandler, AutoSessionCheckpointHandler, and HandoffMemosHandler.
- Eliminates the need for the LLM to waste repetitive background turns running git rev-parse HEAD and git branch --show-current via terminal shell commands just to feed the MCP logging tools.
This commit is contained in:
Riz Ashraf committed 2026-10-10 18:32:02 +01:00
1 parent 11f375017a
commit 760ebfcd40
4 files changed
+48 -15

No files matched your search

+17 -9
View File
@@ -34,8 +34,8 @@ impl McpTool for LogErrorFixHandler {
signature: req.signature.clone(),
solution: solution.clone(),
timestamp: crate::handlers::utils::now_secs(),
git_commit: req.git_commit,
git_branch: req.git_branch,
git_commit: req.git_commit.or_else(|| crate::handlers::utils::get_git_context().1),
git_branch: req.git_branch.or_else(|| crate::handlers::utils::get_git_context().0),
embedding,
..Default::default()
});
@@ -203,17 +203,20 @@ impl McpTool for LogCodeChangeHandler {
_ => crate::models::ChangeKind::Modified,
};
let (auto_branch, auto_commit, auto_repo) = crate::handlers::utils::get_git_context();
let effective_repo = req.repo_name.clone().filter(|rn| !rn.trim().is_empty()).or(auto_repo.clone());
let namespace = req
.namespace
.filter(|ns| !ns.trim().is_empty())
.or_else(|| req.repo_name.clone().filter(|rn| !rn.trim().is_empty()))
.or_else(|| effective_repo.clone())
.unwrap_or_else(crate::models::default_namespace);
let symbols = req.symbol_references.clone().unwrap_or_default();
let line_range = req.line_range.clone();
let effective_rev = req.revision.clone().or_else(|| req.git_commit.clone());
let effective_branch = req.branch.clone().or_else(|| req.git_branch.clone());
let effective_rev = req.revision.clone().or_else(|| req.git_commit.clone()).or(auto_commit);
let effective_branch = req.branch.clone().or_else(|| req.git_branch.clone()).or(auto_branch);
let detected_vcs = if let Some(vcs) = req.vcs_type.clone() {
Some(vcs)
} else if let Some(ref rev) = effective_rev {
@@ -248,7 +251,7 @@ impl McpTool for LogCodeChangeHandler {
description: description.clone(),
git_commit: effective_rev.clone(),
git_branch: effective_branch.clone(),
repo_name: req.repo_name,
repo_name: effective_repo,
repo_url: req.repo_url,
namespace: namespace.clone(),
change_kind,
@@ -629,10 +632,10 @@ impl McpTool for TechDebtHandler {
ideal_solution: ideal,
is_resolved: false,
created_at: crate::handlers::utils::now_secs(),
git_commit: git_commit,
git_branch: git_branch,
git_commit: git_commit.or_else(|| crate::handlers::utils::get_git_context().1),
git_branch: git_branch.or_else(|| crate::handlers::utils::get_git_context().0),
embedding,
repo_name: repo_name,
repo_name: repo_name.or_else(|| crate::handlers::utils::get_git_context().2),
severity: severity,
file_path: file_path,
line_range: line_range,
@@ -1823,6 +1826,8 @@ impl McpTool for AutoSessionCheckpointHandler {
timestamp, active_tasks, unverified_hyp, recent_changes
);
let (auto_branch, auto_commit, auto_repo) = crate::handlers::utils::get_git_context();
let memo = crate::models::HandoffMemo {
id: memo_id.clone(),
author,
@@ -1830,6 +1835,9 @@ impl McpTool for AutoSessionCheckpointHandler {
expires_at: None,
namespace: req.namespace,
timestamp,
git_branch: auto_branch,
vcs_revision: auto_commit,
repo_name: auto_repo,
..Default::default()
};