MCPcopy Create free account
hub / github.com/GCWing/BitFun / extract_fallback_summary

Function extract_fallback_summary

src/apps/cli/src/chat_state.rs:940–987  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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).
940fn 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.

Callers 3

from_core_messageMethod · 0.85
from_core_messagesMethod · 0.85
handle_tool_eventMethod · 0.85

Calls 6

collectMethod · 0.80
takeMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected