From 3dbeaa4746f3972d49d76b686bd164e297f1670f Mon Sep 17 00:00:00 2001 From: Mufeed VH Date: Wed, 25 Jun 2025 03:06:13 +0530 Subject: [PATCH] refactor: clean up migration code and improve widget display formatting - Remove obsolete migrate_agent_runs_to_session_ids function from agents commands - Add trailing empty line removal logic to ReadResultWidget for cleaner code display - Improve code presentation consistency in UI components --- src-tauri/src/commands/agents.rs | 60 -------------------------------- src/components/ToolWidgets.tsx | 5 +++ 2 files changed, 5 insertions(+), 60 deletions(-) diff --git a/src-tauri/src/commands/agents.rs b/src-tauri/src/commands/agents.rs index a0cd9ed..43f3cf2 100644 --- a/src-tauri/src/commands/agents.rs +++ b/src-tauri/src/commands/agents.rs @@ -698,66 +698,6 @@ pub async fn list_agent_runs_with_metrics( Ok(runs_with_metrics) } -/// Migration function for existing agent_runs data -#[tauri::command] -pub async fn migrate_agent_runs_to_session_ids(db: State<'_, AgentDb>) -> Result { - let conn = db.0.lock().map_err(|e| e.to_string())?; - - // Get all agent_runs that have empty session_id but have output data - let mut stmt = conn.prepare( - "SELECT id, output FROM agent_runs WHERE session_id = '' AND output != ''" - ).map_err(|e| e.to_string())?; - - let rows = stmt.query_map([], |row| { - Ok((row.get::<_, i64>(0)?, row.get::<_, String>(1)?)) - }).map_err(|e| e.to_string())?; - - let mut migrated_count = 0; - let mut failed_count = 0; - - for row_result in rows { - let (run_id, output) = row_result.map_err(|e| e.to_string())?; - - // Extract session ID from JSONL output - let mut session_id = String::new(); - for line in output.lines() { - if let Ok(json) = serde_json::from_str::(line) { - if let Some(sid) = json.get("sessionId").and_then(|s| s.as_str()) { - session_id = sid.to_string(); - break; - } - } - } - - if !session_id.is_empty() { - // Update the run with the extracted session ID - match conn.execute( - "UPDATE agent_runs SET session_id = ?1 WHERE id = ?2", - params![session_id, run_id], - ) { - Ok(_) => { - migrated_count += 1; - info!("Migrated agent_run {} with session_id {}", run_id, session_id); - } - Err(e) => { - error!("Failed to update agent_run {}: {}", run_id, e); - failed_count += 1; - } - } - } else { - warn!("Could not extract session ID from agent_run {}", run_id); - failed_count += 1; - } - } - - let message = format!( - "Migration completed: {} runs migrated, {} failed", - migrated_count, failed_count - ); - info!("{}", message); - Ok(message) -} - /// Execute a CC agent with streaming output #[tauri::command] pub async fn execute_agent( diff --git a/src/components/ToolWidgets.tsx b/src/components/ToolWidgets.tsx index 3bcf75a..394427b 100644 --- a/src/components/ToolWidgets.tsx +++ b/src/components/ToolWidgets.tsx @@ -474,6 +474,11 @@ export const ReadResultWidget: React.FC<{ content: string; filePath?: string }> } } + // Remove trailing empty lines + while (codeLines.length > 0 && codeLines[codeLines.length - 1] === '') { + codeLines.pop(); + } + return { codeContent: codeLines.join('\n'), startLineNumber: minLineNumber === Infinity ? 1 : minLineNumber