feat: enhance prompts with detailed programmer description and add workspace tree generation

This commit is contained in:
asepharyana
2026-07-12 03:28:06 +07:00
parent 3cfe39e5f2
commit d957e8d4ce
5 changed files with 37 additions and 5 deletions
+33 -1
View File
@@ -543,6 +543,36 @@ struct TurnCtx {
abort_flag: std::sync::Arc<std::sync::atomic::AtomicBool>,
}
fn generate_workspace_tree(roots: &[std::path::PathBuf]) -> String {
let mut out = String::new();
out.push_str("Current Workspace Directory Structure:\n");
for root in roots {
out.push_str(&format!("Root: {}\n", root.display()));
let walker = ignore::WalkBuilder::new(root)
.hidden(true)
.git_ignore(true)
.build();
let mut count = 0;
for result in walker {
if let Ok(entry) = result {
let path = entry.path();
if let Ok(rel) = path.strip_prefix(root) {
if rel.as_os_str().is_empty() { continue; }
let is_dir = entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false);
let prefix = if is_dir { "[DIR] " } else { " " };
out.push_str(&format!(" {}{}\n", prefix, rel.display()));
count += 1;
if count > 1000 {
out.push_str(" ... (truncated)\n");
break;
}
}
}
}
}
out
}
fn archive_message(db: &Option<std::sync::Arc<std::sync::Mutex<rusqlite::Connection>>>, session_id: &str, msg: &ChatMessage) {
if let Some(ref arc) = db {
if let Ok(conn) = arc.lock() {
@@ -561,10 +591,12 @@ fn run_agent_turn(
let mut tool_only_rounds = 0usize;
let mut prev_shaped = false;
let tree_info = generate_workspace_tree(&tc.workspace_roots);
let system_text = format!(
"{}\n\n{}",
"{}\n\n{}\n\n{}",
crate::resources::SYSTEM_PROMPT,
crate::resources::SYSTEM_TOOLS,
tree_info
);
if !msgs.iter().any(|m| matches!(m.role, crate::dto::chat::message::Role::System)) {
let sys = ChatMessage::system(system_text);