From a32ae571ca3bdae708f8018abd193d45de69241d Mon Sep 17 00:00:00 2001 From: Guilhem Date: Fri, 27 Nov 2026 18:21:13 +0100 Subject: [PATCH] fix: tidy the mcp show tool text fallbacks (#12713) * fix: address cubic nits on the mcp show tool texts * fix: mark a live log line that starts mid-line --- .../src/ai_session_tools/deploy.rs | 11 ------ .../windmill-api/src/ai_session_tools/runs.rs | 37 +++++++++++++------ .../src/ai_session_tools/views.rs | 2 +- .../src/ai_session_tools/workspace.rs | 3 ++ 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/backend/windmill-api/src/ai_session_tools/deploy.rs b/backend/windmill-api/src/ai_session_tools/deploy.rs index 85d0cccb65..1bd8090574 100644 --- a/backend/windmill-api/src/ai_session_tools/deploy.rs +++ b/backend/windmill-api/src/ai_session_tools/deploy.rs @@ -2195,17 +2195,6 @@ pub(super) async fn show_deploy_review(ctx: &Ctx<'_>, args: &Value) -> ToolResul " Only the first {MAX_REVIEW_ITEMS} of {total} are shown." )); } - let rest: Vec<&str> = items - .iter() - .filter(|item| item.get("digest").is_none()) - .filter_map(|item| item.get("name").unwrap_or(&item["path"]).as_str()) - .collect(); - if !rest.is_empty() { - text.push_str(&format!( - " Nothing to deploy for {} (no change, or not deployable this way).", - rest.join(", ") - )); - } for line in item_lines { text.push_str(&format!("\n{line}")); } diff --git a/backend/windmill-api/src/ai_session_tools/runs.rs b/backend/windmill-api/src/ai_session_tools/runs.rs index 296104eaf0..473443edb6 100644 --- a/backend/windmill-api/src/ai_session_tools/runs.rs +++ b/backend/windmill-api/src/ai_session_tools/runs.rs @@ -2369,14 +2369,22 @@ async fn read_run(ctx: &Ctx<'_>, args: &Value, card: bool) -> ToolResult { .filter_map(|e| e["job_id"].as_str()) .last(); let live = match running { - Some(step) => log_tail(ctx, step, 400).await.map(|(tail, _)| tail), - None => logs.map(|(tail, _)| tail), + Some(step) => log_tail(ctx, step, 400).await, + None => logs, }; - if let Some(line) = live - .as_deref() - .and_then(|l| l.lines().rev().find(|l| !l.trim().is_empty())) - { - details.insert("live_log".into(), js_head(line.trim(), 300).into()); + if let Some((tail, tail_cut)) = &live { + let lines: Vec<&str> = tail.lines().collect(); + let last = lines.iter().rposition(|l| !l.trim().is_empty()); + if let Some((i, line)) = last.map(|i| (i, lines[i])) { + // The tail's first line starts where the read did, often mid-line. + let lead = if *tail_cut && i == 0 { "…" } else { "" }; + let line = line.trim(); + let head = js_head(line, 300); + if head.len() < line.len() { + details.insert("live_log_cut".into(), true.into()); + } + details.insert("live_log".into(), format!("{lead}{head}").into()); + } } } match big_image_result(ctx, id, job, entries.first()).await { @@ -2577,10 +2585,13 @@ fn run_text(run: &Map) -> String { }; if let Some((label, value)) = preview { let head = js_head(value, TEXT_PREVIEW_CHARS); + let flag = |key: &str| run.get(key) == Some(&Value::Bool(true)); let cut = head.len() < value.len() - || (finished - && value != TOO_BIG_TEXT - && run.get("result_cut") == Some(&Value::Bool(true))); + || if finished { + value != TOO_BIG_TEXT && flag("result_cut") + } else { + flag("live_log_cut") + }; lines.push(format!("{label}: {head}{}", if cut { "…" } else { "" })); } if let Some(url) = text("url") { @@ -2605,7 +2616,11 @@ fn runs_text(runs: &[Value]) -> String { } } let counts: Vec = counts.iter().map(|(s, n)| format!("{n} {s}")).collect(); - let mut lines = vec![format!("{} run(s): {}.", runs.len(), counts.join(", "))]; + let mut lines = vec![if counts.is_empty() { + "0 run(s).".to_string() + } else { + format!("{} run(s): {}.", runs.len(), counts.join(", ")) + }]; for run in runs { let what = run["path"] .as_str() diff --git a/backend/windmill-api/src/ai_session_tools/views.rs b/backend/windmill-api/src/ai_session_tools/views.rs index 3e3b53d6d4..f5a12ae351 100644 --- a/backend/windmill-api/src/ai_session_tools/views.rs +++ b/backend/windmill-api/src/ai_session_tools/views.rs @@ -82,7 +82,7 @@ pub(crate) fn definitions() -> [(&'static str, &'static str, Value); 5] { ), ( "show_run", - "Show a run to the user as a live card in the conversation: status, result, steps and logs, refreshing until it finishes, with a link to it in Windmill and a button to cancel it while it runs. Call it after starting a run the user asked for, or when they ask to see one, and once per run: the card refreshes itself. Do not call it for runs you start to check your own work: read those with get_run.", + "Show a run to the user as a live card in the conversation: status, result, steps and logs, refreshing until it finishes, with a link to it in Windmill and a button to cancel it while it runs. Call it after starting a run the user asked for, or when they ask to see one. Do not call it again to follow a run, and do not call it for runs you start to check your own work: read those with get_run.", json!({ "type": "object", "properties": { diff --git a/backend/windmill-api/src/ai_session_tools/workspace.rs b/backend/windmill-api/src/ai_session_tools/workspace.rs index 7458f98d3d..1426c5359f 100644 --- a/backend/windmill-api/src/ai_session_tools/workspace.rs +++ b/backend/windmill-api/src/ai_session_tools/workspace.rs @@ -1721,6 +1721,9 @@ pub(super) async fn show_item(ctx: &Ctx<'_>, args: &Value) -> ToolResult { if let Some(edit_url) = edit_url.as_ref().filter(|e| Some(*e) != page_url.as_ref()) { text.push_str(&format!("\nEdit: {edit_url}")); } + if let Some(runs_url) = &runs_url { + text.push_str(&format!("\nWhat it runs: {runs_url}")); + } text.push_str(&format!("\n{}", super::views::CARD_NOTE)); ctx.set_view( "windmill/item",