Files
mcp-memory/inject_git.py
T

63 lines
2.9 KiB
Python

import sys
main_path = r"C:\Users\reazul.ashraf\workspace\rust\mcp-memory\server\src\main.rs"
with open(main_path, "r", encoding="utf-8") as f:
content = f.read()
idx = content.find('eprintln!("MCP Memory Server running on http://127.0.0.1:3000/sse");')
if idx == -1:
print("Could not find start point")
sys.exit(1)
git_code = """
// Git Native Sync Background Task
let state_git = state_clone.clone();
tokio::spawn(async move {
let repo_path = std::env::current_dir().unwrap_or_else(|_| ".".into());
let mut last_commit_id = String::new();
loop {
tokio::time::sleep(tokio::time::Duration::from_secs(30)).await;
if let Ok(repo) = git2::Repository::discover(&repo_path) {
if let Ok(head) = repo.head() {
if let Ok(commit) = head.peel_to_commit() {
let current_id = commit.id().to_string();
if current_id != last_commit_id && !last_commit_id.is_empty() {
let msg = commit.message().unwrap_or("").to_string();
let branch = head.shorthand().unwrap_or("unknown").to_string();
state_git.code_changes.modify(|changes| {
changes.push(crate::models::CodeChange {
commit_hash: current_id.clone(),
branch: branch,
description: format!("Auto-synced commit: {}", msg.trim()),
timestamp: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs(),
files_changed: vec![],
});
});
eprintln!("Git Sync: Logged new commit {}", current_id);
state_git.tasks.modify(|tasks| {
for task in tasks.iter_mut() {
if task.status != "completed" && msg.to_lowercase().contains(&task.title.to_lowercase()) {
task.status = "completed".to_string();
eprintln!("Git Sync: Auto-completed task '{}'", task.title);
}
}
});
}
last_commit_id = current_id;
}
}
}
}
});
"""
content = content[:idx] + git_code + content[idx:]
with open(main_path, "w", encoding="utf-8") as f:
f.write(content)
print("Injected Git Sync task!")