magi-code 0.102.1

Repository-aware CLI coding agent for terminal work
Documentation
pub use crate::output::{ToolResult, ToolResultDisplay};
use serde_json::Value;

impl ToolResult {
    pub(crate) fn structured_content(&self) -> Option<&Value> {
        match self.tool_name.as_str() {
            "read" | "find" => self.metadata.get("structured_result"),
            name if name.starts_with("mcp__") || name.starts_with(super::client::PREFIX) => {
                self.metadata.get("structured_result")
            }
            _ => None,
        }
    }

    pub(crate) fn structured_result(&self, provider_output: &str) -> Value {
        let content = self
            .structured_content()
            .cloned()
            .unwrap_or_else(|| serde_json::json!({"text":provider_output}));
        if self.success {
            serde_json::json!({"success":true,"content":content})
        } else {
            serde_json::json!({"success":false,"content":content,"error":{"code":"tool_error","message":provider_output}})
        }
    }
}