From d9408fc09ad4da6207c1688e02788faacabf889d Mon Sep 17 00:00:00 2001 From: Evandro Fonseca Junior Date: Thu, 26 Mar 2026 19:34:25 -0300 Subject: [PATCH] feat: render cli dry-run previews --- crates/localllm-cli/src/main.rs | 67 ++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/crates/localllm-cli/src/main.rs b/crates/localllm-cli/src/main.rs index 549b3e7..a0e913b 100644 --- a/crates/localllm-cli/src/main.rs +++ b/crates/localllm-cli/src/main.rs @@ -303,7 +303,72 @@ fn main() -> anyhow::Result<()> { } fn render_execution_preview(cli: &Cli) -> String { - format!("DRY RUN {}", render_command_summary(cli)) + let preview = execution_preview( + cli, + &execution_stub(&execution_contract(&plan_command(cli))), + ); + + match (cli.format, preview) { + (OutputFormat::Text, ExecutionPreview::SummaryOnly { command }) => { + format!("DRY RUN {}", command) + } + ( + OutputFormat::Text, + ExecutionPreview::HttpPreview { + method, + url, + api_key_present, + .. + }, + ) => format!( + "DRY RUN {} {} api_key_present={}", + method, url, api_key_present + ), + ( + OutputFormat::Text, + ExecutionPreview::LocalPreview { + action, + target, + effect, + }, + ) => format!("DRY RUN {} target={} effect={}", action, target, effect), + (OutputFormat::Json, ExecutionPreview::SummaryOnly { command }) => { + format!(r#"{{"kind":"summary","command":"{}"}}"#, command) + } + ( + OutputFormat::Json, + ExecutionPreview::HttpPreview { + method, + url, + api_key_present, + body, + }, + ) => format!( + r#"{{"kind":"http","method":"{}","url":"{}","api_key_present":{},"body":{}}}"#, + method, + url, + api_key_present, + render_json_body(body.as_deref()) + ), + ( + OutputFormat::Json, + ExecutionPreview::LocalPreview { + action, + target, + effect, + }, + ) => format!( + r#"{{"kind":"local","action":"{}","target":"{}","effect":"{}"}}"#, + action, target, effect + ), + } +} + +fn render_json_body(body: Option<&str>) -> String { + match body { + Some(body) => format!(r#""{}""#, body), + None => "null".to_owned(), + } } fn render_command_summary(cli: &Cli) -> String {