feat(tui): update system message for clarity and conciseness in tool usage instructions

This commit is contained in:
asepharyana
2026-07-20 14:47:55 +07:00
parent fe2e916937
commit 5a373d1031
10 changed files with 130 additions and 21 deletions
+2
View File
@@ -218,6 +218,8 @@ pub enum TurnEvent {
agent_name: String,
status: crate::AgentStatus,
},
TodoUpdate(String),
PlanUpdate(String),
}
/// A tool call awaiting execution, along with which execution model
+18 -1
View File
@@ -29,8 +29,16 @@ impl Tool for PlanEnter {
})
}
fn run(&self, _ctx: &ToolCtx, args: &Value) -> Result<String> {
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
let plan_text = crate::tools::arg_str(args, "plan")?;
let plan_path = ctx.session_dir.join("PLAN.md");
let _ = std::fs::write(&plan_path, &plan_text);
if let Some(events) = &ctx.turn_events {
let mut q = events.lock().unwrap();
q.push_back(crate::TurnEvent::PlanUpdate(plan_text.clone()));
}
Ok(format!(
"Plan entered (length: {} chars). Waiting for approval...",
plan_text.len()
@@ -72,6 +80,15 @@ impl Tool for PlanReady {
let path = plan_dir.join(&filename);
std::fs::write(&path, &plan_content)
.map_err(|e| anyhow::anyhow!("failed to save plan: {e}"))?;
// Also save the latest plan
let plan_path = ctx.session_dir.join("PLAN.md");
let _ = std::fs::write(&plan_path, &plan_content);
if let Some(events) = &ctx.turn_events {
let mut q = events.lock().unwrap();
q.push_back(crate::TurnEvent::PlanUpdate(plan_content.clone()));
}
Ok(format!("Plan saved to {filename}. Starting execution."))
} else {
Ok("Plan is ready. Starting execution.".to_string())
@@ -28,8 +28,39 @@ impl Tool for Todofinish {
})
}
fn run(&self, _ctx: &ToolCtx, args: &Value) -> Result<String> {
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
let item = crate::tools::arg_str(args, "item")?;
let todo_path = ctx.session_dir.join("TODO.md");
let mut content = std::fs::read_to_string(&todo_path).unwrap_or_default();
// Very basic replace to mark as finished
let mut replaced = false;
let lines: Vec<&str> = content.lines().collect();
let mut new_lines = Vec::new();
for line in lines {
if line.contains(&item) && line.starts_with("- [") {
let s = line.replacen("- [high]", "- [x]", 1)
.replacen("- [medium]", "- [x]", 1)
.replacen("- [low]", "- [x]", 1);
// if it didn't match those, just replace the first `[`
let s = if s == line { line.replacen("[ ]", "[x]", 1) } else { s };
new_lines.push(s);
replaced = true;
} else {
new_lines.push(line.to_string());
}
}
if replaced {
content = new_lines.join("\n") + "\n";
let _ = std::fs::write(&todo_path, &content);
if let Some(events) = &ctx.turn_events {
let mut q = events.lock().unwrap();
q.push_back(crate::TurnEvent::TodoUpdate(content));
}
}
Ok(format!("TODO completed: {}", item))
}
}
@@ -33,13 +33,26 @@ impl Tool for Todowrite {
})
}
fn run(&self, _ctx: &ToolCtx, args: &Value) -> Result<String> {
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
let item = crate::tools::arg_str(args, "item")?;
let priority = args
.get("priority")
.and_then(|v| v.as_str())
.unwrap_or("medium");
let todo_line = format!("- [{}] {}\n", priority, item);
let todo_path = ctx.session_dir.join("TODO.md");
let mut content = std::fs::read_to_string(&todo_path).unwrap_or_default();
content.push_str(&todo_line);
let _ = std::fs::write(&todo_path, &content);
if let Some(events) = &ctx.turn_events {
let mut q = events.lock().unwrap();
q.push_back(crate::TurnEvent::TodoUpdate(content));
}
Ok(format!("[{}] TODO added: {}", priority, item))
}
}