feat(tui): add rich context information including active jobs, README snippet, and recent git history

This commit is contained in:
asepharyana
2026-07-20 16:16:26 +07:00
parent 919435eb84
commit 2f5f62ab09
+50
View File
@@ -259,5 +259,55 @@ pub fn build_rich_context(root: &Path) -> String {
} }
} }
// 5. Active Background Jobs
let jobs = crate::bgbash::control::bash_control().list();
if !jobs.is_empty() {
ctx.push_str("### Active Background Jobs\n```\n");
for (id, cmd, _) in jobs {
ctx.push_str(&format!("[{}] {}\n", id, cmd));
}
ctx.push_str("```\n\n");
}
// 6. Project Purpose (README)
let readme_path = root.join("README.md");
if let Ok(content) = std::fs::read_to_string(&readme_path) {
let snippet = if content.len() > 1000 {
format!("{}\n... (truncated)", &content[..1000])
} else {
content
};
ctx.push_str(&format!("### Project Purpose (README.md)\n```\n{}\n```\n\n", snippet.trim()));
}
// 7. Recent Git History & Momentum
if root.join(".git").exists() {
let commits = Command::new("git")
.arg("log")
.arg("-n")
.arg("3")
.arg("--oneline")
.current_dir(root)
.output()
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.unwrap_or_default();
if !commits.is_empty() {
ctx.push_str(&format!("### Recent Commits (Momentum)\n```\n{}\n```\n\n", commits));
}
let diff = Command::new("git")
.arg("diff")
.arg("--name-only")
.current_dir(root)
.output()
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.unwrap_or_default();
if !diff.is_empty() {
ctx.push_str(&format!("### Recently Modified Files (Uncommitted)\n```\n{}\n```\n\n", diff));
}
}
ctx.trim_end().to_string() ctx.trim_end().to_string()
} }