| 334 | } |
| 335 | |
| 336 | fn node_details(graph: &Graph, node: &atomic_core::KgNode) -> Vec<String> { |
| 337 | let mut lines = vec![ |
| 338 | format!("ID: {}", one_line(&node.id)), |
| 339 | format!("Type: {}", compact(node.primary_type())), |
| 340 | ]; |
| 341 | let label = if node.has_type(Class::File) { |
| 342 | metadata_text(node, "path").unwrap_or(&node.label) |
| 343 | } else { |
| 344 | &node.label |
| 345 | }; |
| 346 | if console::measure_text_width(&one_line(label)) > 100 { |
| 347 | lines.push(format!("Label: {}", one_line(label))); |
| 348 | } |
| 349 | let mut annotated = [node.clone()]; |
| 350 | annotate(graph, &mut annotated); |
| 351 | if let Some(summary) = &annotated[0].summary { |
| 352 | let summary = one_line(summary); |
| 353 | let summary = summary.trim(); |
| 354 | // Context is the fallback role, not evidence or a useful summary. |
| 355 | let summary = summary.strip_prefix("[context]").unwrap_or(summary).trim(); |
| 356 | if !summary.is_empty() { |
| 357 | lines.push(format!("Summary: {summary}")); |
| 358 | } |
| 359 | } |
| 360 | // References preserve graph direction without recursively expanding shared |
| 361 | // targets or cycles, so details cannot change the tree's grouping. |
| 362 | let mut edges: Vec<_> = graph |
| 363 | .edges |
| 364 | .iter() |
| 365 | .filter(|edge| edge.from_id == node.id) |
| 366 | .collect(); |
| 367 | edges.sort_by(|a, b| (a.kind, &a.to_id).cmp(&(b.kind, &b.to_id))); |
| 368 | for edge in edges { |
| 369 | let mut line = format!("{} → {}", compact(edge.kind.iri()), one_line(&edge.to_id)); |
| 370 | if let Some(evidence) = edge |
| 371 | .metadata |
| 372 | .as_ref() |
| 373 | .and_then(|m| m.get("declarationEvidence")) |
| 374 | .and_then(|v| v.as_str()) |
| 375 | { |
| 376 | line.push_str(&format!(" [Declaration evidence: {}]", one_line(evidence))); |
| 377 | } |
| 378 | lines.push(line); |
| 379 | } |
| 380 | lines |
| 381 | } |
| 382 | |
| 383 | fn metadata_text<'a>(node: &'a atomic_core::KgNode, key: &str) -> Option<&'a str> { |
| 384 | node.metadata.as_ref()?.get(key)?.as_str() |