Format massive JSON arrays into Markdown natively to avoid context blowouts
This commit is contained in:
1 parent
760ebfcd40
commit
3ee95f5c39
4 files changed
+157
-42
No files matched your search
@@ -1279,16 +1279,38 @@ impl McpTool for SweepGraphHealthHandler {
|
||||
}
|
||||
});
|
||||
|
||||
let report = serde_json::json!({
|
||||
"orphaned_entities": orphans,
|
||||
"orphans_pruned": auto_prune,
|
||||
"stale_entities": stale_entities,
|
||||
"stale_pruned": auto_prune_stale,
|
||||
"potential_duplicates": duplicates,
|
||||
"health_score": if orphans.is_empty() && duplicates.is_empty() && stale_entities.is_empty() { "100%" } else { "Needs Maintenance" }
|
||||
});
|
||||
let mut out = String::new();
|
||||
out.push_str("## Graph Health Report\n\n");
|
||||
let score = if orphans.is_empty() && duplicates.is_empty() && stale_entities.is_empty() { "100% (Healthy)" } else { "Needs Maintenance" };
|
||||
out.push_str(&format!("**Health Status:** {}\n\n", score));
|
||||
|
||||
Ok(serde_yaml::to_string(&report)?)
|
||||
out.push_str(&format!("### Orphaned Entities ({})\n", orphans.len()));
|
||||
if auto_prune {
|
||||
out.push_str("*These orphans were automatically pruned.*\n");
|
||||
}
|
||||
for o in orphans {
|
||||
out.push_str(&format!("- `{}`\n", o));
|
||||
}
|
||||
out.push_str("\n");
|
||||
|
||||
out.push_str(&format!("### Stale Entities ({})\n", stale_entities.len()));
|
||||
if auto_prune_stale {
|
||||
out.push_str("*These stale entities were automatically pruned.*\n");
|
||||
}
|
||||
for s in stale_entities {
|
||||
out.push_str(&format!("- `{}`\n", s));
|
||||
}
|
||||
out.push_str("\n");
|
||||
|
||||
out.push_str(&format!("### Potential Duplicates ({})\n", duplicates.len()));
|
||||
for d in duplicates {
|
||||
let a = d.get("entity_a").and_then(|x| x.as_str()).unwrap_or("?");
|
||||
let b = d.get("entity_b").and_then(|x| x.as_str()).unwrap_or("?");
|
||||
let act = d.get("suggested_action").and_then(|x| x.as_str()).unwrap_or("");
|
||||
out.push_str(&format!("- `{}` and `{}`\n - Suggested: `{}`\n", a, b, act));
|
||||
}
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user