From 633b39eb53ac65330484dfeeaf0b8cf13091adf9 Mon Sep 17 00:00:00 2001 From: Evandro Fonseca Junior Date: Thu, 26 Mar 2026 19:28:23 -0300 Subject: [PATCH] feat: add cli execution previews --- crates/localllm-cli/src/main.rs | 38 ++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/crates/localllm-cli/src/main.rs b/crates/localllm-cli/src/main.rs index 30a4240..7d7e050 100644 --- a/crates/localllm-cli/src/main.rs +++ b/crates/localllm-cli/src/main.rs @@ -478,14 +478,46 @@ fn execution_stub(contract: &ExecutionContract) -> ExecutionStub { } } -fn execution_preview(_cli: &Cli, stub: &ExecutionStub) -> ExecutionPreview { +fn execution_preview(cli: &Cli, stub: &ExecutionStub) -> ExecutionPreview { match stub { ExecutionStub::SummaryOnly { command } => ExecutionPreview::SummaryOnly { command: command.clone(), }, - _ => ExecutionPreview::SummaryOnly { - command: "preview-unimplemented".to_owned(), + ExecutionStub::HttpRequest { + method, + path, + api_key_present, + body, + } => ExecutionPreview::HttpPreview { + method, + url: format!("{}{}", cli.server.trim_end_matches('/'), path), + api_key_present: *api_key_present, + body: body.clone(), }, + ExecutionStub::LocalAction { + action, + target, + detail, + } => ExecutionPreview::LocalPreview { + action, + target: target.clone(), + effect: preview_effect(action, detail.as_deref()), + }, + } +} + +fn preview_effect(action: &str, detail: Option<&str>) -> String { + match (action, detail) { + ("scan_models_dir", _) => "discover available model files".to_owned(), + ("load_model", Some(detail)) => format!("load {}", detail), + ("configure_auth", Some(detail)) => format!("set {}", detail), + ("write_config", Some(detail)) => format!("persist {}", detail), + ("tail_logs", Some(detail)) => detail + .strip_prefix("lines=") + .map(|lines| format!("tail last {} lines", lines)) + .unwrap_or_else(|| format!("apply {}", detail)), + (_, Some(detail)) => format!("apply {}", detail), + (_, None) => format!("run {}", action), } }