Extract a human-readable summary from a tool result JSON Value. Used as fallback when `display_summary` is not provided (e.g. MCP tools, old data).
(result: &serde_json::Value)
| 938 | /// Extract a human-readable summary from a tool result JSON Value. |
| 939 | /// Used as fallback when `display_summary` is not provided (e.g. MCP tools, old data). |
| 940 | fn extract_fallback_summary(result: &serde_json::Value) -> String { |
| 941 | if let Some(obj) = result.as_object() { |
| 942 | // Try common text fields first |
| 943 | for key in &[ |
| 944 | "display_summary", |
| 945 | "result_for_assistant", |
| 946 | "output", |
| 947 | "result", |
| 948 | "content", |
| 949 | "message", |
| 950 | ] { |
| 951 | if let Some(text) = obj.get(*key).and_then(|v| v.as_str()) { |
| 952 | if !text.is_empty() && text.len() < 200 { |
| 953 | return text.to_string(); |
| 954 | } else if !text.is_empty() { |
| 955 | let truncated: String = text.chars().take(200).collect(); |
| 956 | return format!("{}...", truncated); |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | // Try success field |
| 962 | if let Some(true) = obj.get("success").and_then(|v| v.as_bool()) { |
| 963 | return "Done".to_string(); |
| 964 | } |
| 965 | |
| 966 | // Try extracting key parameter values |
| 967 | let priority_keys = ["path", "file_path", "query", "pattern", "command", "url"]; |
| 968 | for key in &priority_keys { |
| 969 | if let Some(s) = obj.get(*key).and_then(|v| v.as_str()) { |
| 970 | if !s.is_empty() && s.len() < 100 { |
| 971 | return s.to_string(); |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | // If it's a plain string |
| 978 | if let Some(text) = result.as_str() { |
| 979 | if text.len() < 200 { |
| 980 | return text.to_string(); |
| 981 | } |
| 982 | let truncated: String = text.chars().take(200).collect(); |
| 983 | return format!("{}...", truncated); |
| 984 | } |
| 985 | |
| 986 | "Done".to_string() |
| 987 | } |
| 988 | |
| 989 | /// Extract a short title from tool parameters for subagent progress display. |
| 990 | /// Returns a concise description like the file path, command, or query. |
no test coverage detected