`atomic query plan` over QueryGraph (Plan) — the structured plan executes handler-side; the CLI renders the domain PlanResult JSON byte-for-byte (--json) or the human summary.
(args: &super::query::PlanExec)
| 6887 | /// executes handler-side; the CLI renders the domain PlanResult JSON |
| 6888 | /// byte-for-byte (--json) or the human summary. |
| 6889 | pub fn query_plan(args: &super::query::PlanExec) -> CliResult<bool> { |
| 6890 | // Read plan from stdin — client-side (interactive/file-only). |
| 6891 | use std::io::Read; |
| 6892 | let mut plan_json = String::new(); |
| 6893 | std::io::stdin() |
| 6894 | .read_to_string(&mut plan_json) |
| 6895 | .map_err(CliError::Io)?; |
| 6896 | let Some(session) = Service::open()? else { |
| 6897 | return Ok(false); |
| 6898 | }; |
| 6899 | let request = pb::QueryGraphRequest { |
| 6900 | repository: Some(session.reference.clone()), |
| 6901 | limit: 0, |
| 6902 | query: Some(pb::query_graph_request::Query::Plan( |
| 6903 | pb::PlanExecutionQuery { |
| 6904 | plan_json: plan_json.into_bytes(), |
| 6905 | }, |
| 6906 | )), |
| 6907 | view: None, |
| 6908 | }; |
| 6909 | let response = session.query_graph(request)?; |
| 6910 | let Some(payload) = response.plan_result else { |
| 6911 | return Err(CliError::Internal(anyhow::anyhow!( |
| 6912 | "the service returned no plan result" |
| 6913 | ))); |
| 6914 | }; |
| 6915 | let result: atomic_repository::PlanResult = serde_json::from_slice(&payload) |
| 6916 | .map_err(|error| CliError::Internal(anyhow::anyhow!("plan result: {error}")))?; |
| 6917 | if args.json { |
| 6918 | println!("{}", serde_json::to_string_pretty(&result).unwrap()); |
| 6919 | } else { |
| 6920 | println!( |
| 6921 | "Plan executed in {}ms ({} steps)\n", |
| 6922 | result.elapsed_ms, |
| 6923 | result.step_stats.len() |
| 6924 | ); |
| 6925 | for (index, stat) in result.step_stats.iter().enumerate() { |
| 6926 | println!( |
| 6927 | " Step {}: {} → {} results ({}ms)", |
| 6928 | index + 1, |
| 6929 | stat.step_type, |
| 6930 | stat.result_count, |
| 6931 | stat.elapsed_ms |
| 6932 | ); |
| 6933 | } |
| 6934 | if !result.nodes.is_empty() { |
| 6935 | println!("\nNodes ({}):", result.nodes.len()); |
| 6936 | for node in &result.nodes { |
| 6937 | print!( |
| 6938 | " [{}] {}", |
| 6939 | atomic_core::kg::ontology::compact(node.primary_type()), |
| 6940 | node.label |
| 6941 | ); |
| 6942 | if let Some(summary) = &node.summary { |
| 6943 | let short: String = summary.chars().take(60).collect(); |
| 6944 | print!(": {}", short); |
| 6945 | } |
| 6946 | println!(); |