diff --git a/apps/interfaces/tui/src/action.rs b/apps/interfaces/tui/src/action.rs index 6927692..5225110 100644 --- a/apps/interfaces/tui/src/action.rs +++ b/apps/interfaces/tui/src/action.rs @@ -106,6 +106,8 @@ pub fn apply_action(state: &mut crate::state::AppStateRest, action: Action) { state.mark_dirty(); } Action::Tick => { + state.misc.tick_count = state.misc.tick_count.wrapping_add(1); + // Drain turn events from the shared queue — collect events first, // then mutate state, to avoid borrow conflicts with the mutex guard. let events: Vec = state diff --git a/apps/interfaces/tui/src/turn.rs b/apps/interfaces/tui/src/turn.rs index 55af1d5..9e4ff02 100644 --- a/apps/interfaces/tui/src/turn.rs +++ b/apps/interfaces/tui/src/turn.rs @@ -10,6 +10,7 @@ use std::collections::VecDeque; use tracing::{debug, info, warn}; +use zesdex_domain::core::tool_call::sanitize_tool_arguments; use zesdex_domain::core::ChatMessage; use zesdex_infrastructure::llm::provider::LlmClient; use zesdex_infrastructure::tools::{all_tools, tool_defs, ToolCtx}; @@ -67,6 +68,26 @@ fn run_turn( let tools = all_tools(); let defs = tool_defs(&tools); + // Build tool description list for the system prompt + let tool_desc: Vec = tools.iter().map(|t| { + let params = t.parameters(); + let required = params.get("required").and_then(|r| r.as_array()) + .map(|a| a.iter().filter_map(|v| v.as_str()).collect::>().join(", ")) + .unwrap_or_default(); + format!("- {}: {} (required params: {})", t.name(), t.description(), required) + }).collect(); + let tool_desc_text = tool_desc.join("\n"); + + // Prepend system message with tool descriptions + let sys_msg = ChatMessage::system(format!( + "You are Zesdex, an AI coding agent with access to the following tools:\n\n{}\n\n\ + When using tools, always provide ALL required parameters in your tool call. \ + If a tool returns an error, fix the issue before retrying. \ + Respond conversationally and helpfully.", + tool_desc_text + )); + messages.insert(0, sys_msg); + let tool_ctx = ToolCtx::builder() .session_dir(session_dir.clone()) .workspaces(workspace_roots.to_vec()) @@ -118,7 +139,7 @@ fn run_turn( for tc in &tool_calls { let name = &tc.function.name; - let args = tc.function.arguments.clone(); + let args = sanitize_tool_arguments(&tc.function.arguments); debug!("executing tool: {name}");