This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 933afdb35b54 CAMEL-25362: camel-jbang - Shift+F8 with AI on the 
Health, Circuit Breaker, Routes and SQL Trace screens (#30492)
933afdb35b54 is described below

commit 933afdb35b54340673154f59c1bd147330e59726
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 20 16:00:59 2026 +0100

    CAMEL-25362: camel-jbang - Shift+F8 with AI on the Health, Circuit Breaker, 
Routes and SQL Trace screens (#30492)
    
    Health: fix with AI on the checks that are not UP (in the table, the 
selected
    one). The question has the message, what DOWN means for the integration
    (readiness or liveness), the details of the check (route.id, endpoint.uri),
    the source line of its route and the stack trace of the error, shortened.
    The status parser now keeps the stack trace and details of a check, which
    the health console already sends.
    
    Circuit Breaker: explain with AI on the selected breaker when it is open or
    half open, or calls failed, timed out or were rejected: its counters, its
    configuration (as the resilience4j console sends it), its source line and
    the last error of its route. It asks for no file change unless agreed.
    
    Routes: fix with AI on a route whose exchanges failed or whose error handler
    handled failures: the counts, the steps they fail at with their source
    lines, and the last error of the route. On a route without failures that
    had exchanges, explain with AI where the time goes: mean, max and
    percentile times and the slowest steps.
    
    SQL Trace: fix with AI on a statement that failed, with the SQL, its
    endpoint (masked), the route and source line, and the error of its exchange
    from the error registry. On a slow statement (100 ms or more), explain with
    AI why, with its rows and how often the same SQL ran.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../ROOT/pages/camel-jbang-tui-ai-ways.adoc        |   6 +-
 .../ROOT/pages/camel-jbang-tui-observe.adoc        |  19 ++
 .../core/commands/tui/CircuitBreakerAiPrompt.java  | 111 +++++++++
 .../core/commands/tui/CircuitBreakerInfo.java      |   6 +
 .../jbang/core/commands/tui/CircuitBreakerTab.java |  39 ++++
 .../jbang/core/commands/tui/HealthAiPrompt.java    | 188 ++++++++++++++++
 .../jbang/core/commands/tui/HealthCheckInfo.java   |   7 +
 .../dsl/jbang/core/commands/tui/HealthTab.java     |  48 ++++
 .../dsl/jbang/core/commands/tui/RouteAiPrompt.java | 158 +++++++++++++
 .../dsl/jbang/core/commands/tui/RoutesTab.java     |  47 ++++
 .../jbang/core/commands/tui/SqlTraceAiPrompt.java  | 122 ++++++++++
 .../dsl/jbang/core/commands/tui/SqlTraceTab.java   |  40 +++-
 .../dsl/jbang/core/commands/tui/StatusParser.java  |  11 +
 .../src/main/resources/tui/help/circuit-breaker.md |  12 +
 .../src/main/resources/tui/help/health.md          |  10 +
 .../src/main/resources/tui/help/routes.md          |  15 ++
 .../src/main/resources/tui/help/sql-trace.md       |  13 ++
 .../commands/tui/CircuitBreakerAiPromptTest.java   | 189 ++++++++++++++++
 .../core/commands/tui/HealthAiPromptTest.java      | 250 +++++++++++++++++++++
 .../jbang/core/commands/tui/RouteAiPromptTest.java | 179 +++++++++++++++
 .../core/commands/tui/SqlTraceAiPromptTest.java    | 158 +++++++++++++
 21 files changed, 1620 insertions(+), 8 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-ai-ways.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-ai-ways.adoc
index 13e237c8bdaa..d3a5c8b68885 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-ai-ways.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-ai-ways.adoc
@@ -125,8 +125,10 @@ to the TUI; the agent then has both servers.
   This holds for the built-in panel, an ACP agent and an external MCP agent 
alike.
 * *You can see what happened.* The AI log (*F2* -> _AI & MCP_ -> _AI Log_) 
records the questions, tool calls and
   answers of the panel; the MCP log records the calls agents made through the 
MCP server.
-* *The same shortcuts open the panel.* *Shift+F8* in the Source editor, the 
Log tab and the Errors view writes the
-  question for you ("fix with AI") and sends it to whichever provider or agent 
the panel uses. `/overview`, which
+* *The same shortcuts open the panel.* *Shift+F8* in the Source editor, the 
Log tab, the Errors view, the Health
+  tab, and on a failing route or SQL statement writes the question for you 
("fix with AI"). On the Timeline, Chaos
+  and Circuit Breaker screens and on a slow route or SQL statement, it writes 
a question that asks for an explanation
+  ("explain with AI"). The panel sends the question to whichever provider or 
agent it uses. `/overview`, which
   explains the project, needs a model (way 1); an agent explains it with the 
`camel_project_overview` and
   `camel_save_project_summary` tools when you ask it to.
 
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc
index 8450a29f878e..bbb2ace40c32 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc
@@ -210,6 +210,25 @@ listed once.
 
 image::jbang/camel-tui-log-fix-with-ai-pick.png[Shift+F8 in the Log tab with 
two different ERRORs on the screen]
 
+The Routes, SQL Trace, Health and Circuit Breaker tabs have the key too:
+
+* *Routes*: *Shift+F8* on a route whose exchanges fail asks the AI to fix it, 
with the steps they fail at, their source
+lines and the last error of the route. On a route without failures, it asks 
the AI to explain where the time goes, with
+its slowest steps.
+* *SQL Trace*: *Shift+F8* on a statement that failed asks the AI to fix it, 
with the SQL, the route and source line, and
+the error of its exchange. On a slow statement (100 ms or more), it asks the 
AI why it is slow and what could make it
+faster.
+
+* *Health*: *Shift+F8* asks the AI to fix the checks that are not UP (in the 
table, the selected one). The question has
+the message of the check and what being DOWN means for the integration (taken 
out of service, or restarted). It also
+has the details of the check, such as the route and endpoint, the source line 
of its route, and the stack trace of the
+error. The AI tells whether the cause is in the project, and fixes it there, 
or outside the integration, such as a
+broker that is not running.
+* *Circuit Breaker*: *Shift+F8* asks the AI to explain the selected circuit 
breaker when it is open or half open, or its
+calls failed, timed out or were rejected. The question has its state and 
counters, its configuration, its line in the
+source and the last error of its route. An open circuit breaker is often the 
breaker doing its job, so the AI explains
+and suggests, and changes no file unless you agree.
+
 The Log tab shows the log in one of three views, and *c* goes to the next one:
 
 * *compact* (the default): the time, level, logger and message of each line, 
as the date, pid and thread take most of
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerAiPrompt.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerAiPrompt.java
new file mode 100644
index 000000000000..6803a188a764
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerAiPrompt.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.Map;
+
+/**
+ * The question the AI panel is opened with to explain a circuit breaker 
(Shift+F8 on the Circuit Breaker tab,
+ * CAMEL-25362): its state and counters, its configuration, where it is in the 
source, and the last error of its route.
+ * An open breaker is often the breaker doing its job, so the AI is asked to 
explain and suggest, not to change the
+ * files on its own. It is put in the input of the panel, for the user to send 
with Enter or change first.
+ */
+final class CircuitBreakerAiPrompt {
+
+    private CircuitBreakerAiPrompt() {
+    }
+
+    /** Whether a breaker has something to explain: it is not closed, or calls 
failed, timed out or were rejected. */
+    static boolean hasTrouble(CircuitBreakerInfo cb) {
+        return cb.state != null && !"closed".equalsIgnoreCase(cb.state)
+                || cb.failedCalls > 0 || cb.timedOutCalls > 0 || 
cb.notPermittedCalls > 0
+                || cb.bulkheadRejectedCalls > 0;
+    }
+
+    static String of(IntegrationInfo info, CircuitBreakerInfo cb) {
+        StringBuilder sb = new StringBuilder();
+        String name = info.name != null ? info.name : info.pid;
+        sb.append("Explain the circuit breaker ").append(cb.id != null ? cb.id 
: "")
+                .append(" in route ").append(cb.routeId != null ? cb.routeId : 
"")
+                .append(" of the running integration ").append(name).append(": 
it is ")
+                .append(cb.state != null ? cb.state : "in an unknown state");
+        if (cb.component != null) {
+            sb.append(" (").append(cb.component).append(')');
+        }
+        sb.append(".\n");
+        sb.append("Its sliding window: ").append(cb.successfulCalls).append(" 
successful, ").append(cb.failedCalls)
+                .append(" failed");
+        if (cb.timedOutCalls > 0) {
+            sb.append(" (").append(cb.timedOutCalls).append(" of all calls 
timed out)");
+        }
+        if (cb.failureRate >= 0) {
+            sb.append(", failure rate ").append(String.format("%.0f%%", 
cb.failureRate));
+        }
+        sb.append(".\n");
+        if (cb.notPermittedCalls > 0 || cb.fallbackCalls > 0 || 
cb.bulkheadRejectedCalls > 0) {
+            sb.append("Since it started: 
").append(cb.notPermittedCalls).append(" calls rejected while open, ")
+                    .append(cb.fallbackCalls).append(" answered by the 
fallback");
+            if (cb.bulkheadRejectedCalls > 0) {
+                sb.append(", ").append(cb.bulkheadRejectedCalls).append(" 
rejected by a full bulkhead");
+            }
+            sb.append(".\n");
+        }
+        if (cb.total > 0) {
+            sb.append("Calls in total: ").append(cb.total).append(", failed 
").append(cb.totalFailed)
+                    .append("; processing time mean 
").append(ChaosTab.shortTime(cb.meanTime)).append(", max ")
+                    .append(ChaosTab.shortTime(cb.maxTime)).append(".\n");
+        }
+        if (!cb.configuration.isEmpty()) {
+            StringBuilder conf = new StringBuilder();
+            for (Map.Entry<String, Object> e : cb.configuration.entrySet()) {
+                if (e.getValue() != null) {
+                    conf.append(conf.isEmpty() ? "" : ", 
").append(e.getKey()).append('=').append(e.getValue());
+                }
+            }
+            sb.append("Its configuration: ").append(conf).append('\n');
+        }
+        String source = sourceOf(info, cb);
+        if (source != null) {
+            sb.append("It is at ").append(source).append(".\n");
+        }
+        ErrorInfo last = RouteAiPrompt.lastError(info, cb.routeId);
+        if (last != null) {
+            sb.append("The last error of the route: 
").append(RuntimeFailures.failureOf(last)).append('\n');
+        }
+        sb.append("Tell whether the breaker did its job (the call it protects 
failed or was slow, and why, from the")
+                .append(" integration's errors and log) or whether its 
configuration does not fit the traffic, and")
+                .append(" what the callers got meanwhile. Then suggest what to 
change, if anything. tui_get_table on")
+                .append(" the Circuit Breaker tab has the counters. Make no 
changes to the files unless I agree.");
+        return sb.toString();
+    }
+
+    /** The source location (file:line) of the breaker's processor, else of 
its route; null when not known. */
+    static String sourceOf(IntegrationInfo info, CircuitBreakerInfo cb) {
+        for (RouteInfo r : info.routes) {
+            if (cb.routeId == null || !cb.routeId.equals(r.routeId)) {
+                continue;
+            }
+            for (ProcessorInfo p : r.processors) {
+                if (cb.id != null && cb.id.equals(p.id) && p.source != null) {
+                    return p.source;
+                }
+            }
+            return r.source;
+        }
+        return null;
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerInfo.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerInfo.java
index 3213125370c6..1c454d522ff9 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerInfo.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerInfo.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.dsl.jbang.core.commands.tui;
 
+import java.util.Map;
+
 class CircuitBreakerInfo {
     String routeId;
     String id;
@@ -38,4 +40,8 @@ class CircuitBreakerInfo {
     String sinceLastStarted;
     String sinceLastSuccess;
     String sinceLastFail;
+    /**
+     * The configuration of the breaker (failureRateThreshold, 
waitDurationInOpenState ...), when its console has it.
+     */
+    Map<String, Object> configuration = Map.of();
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerTab.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerTab.java
index c5869c5b9be1..582e378b2029 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerTab.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerTab.java
@@ -29,6 +29,8 @@ import dev.tamboui.terminal.Frame;
 import dev.tamboui.text.Line;
 import dev.tamboui.text.Span;
 import dev.tamboui.text.Text;
+import dev.tamboui.tui.event.KeyCode;
+import dev.tamboui.tui.event.KeyEvent;
 import dev.tamboui.widgets.block.Block;
 import dev.tamboui.widgets.block.BorderType;
 import dev.tamboui.widgets.block.Borders;
@@ -181,6 +183,43 @@ class CircuitBreakerTab extends AbstractTableTab {
         hint(spans, "s", "sort");
     }
 
+    @Override
+    protected boolean handleTabKeyEvent(KeyEvent ke) {
+        if (ke.isKey(KeyCode.F8) && ke.hasShift()) {
+            // explain with AI (CAMEL-25362): why the selected breaker opened, 
or why its calls fail
+            IntegrationInfo info = ctx.findSelectedIntegration();
+            CircuitBreakerInfo cb = info != null ? selectedBreaker(info) : 
null;
+            if (cb != null && ctx.askAiCallback != null) {
+                if (CircuitBreakerAiPrompt.hasTrouble(cb)) {
+                    ctx.askAiCallback.ask(CircuitBreakerAiPrompt.of(info, cb));
+                } else if (ctx.notificationCallback != null) {
+                    ctx.notificationCallback.accept("This circuit breaker is 
closed and no call failed: ask the AI with F8",
+                            false);
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void renderFKeyHints(List<Span> spans) {
+        // with the global F-keys, as the AI key of a screen is an F-key of 
every screen that has one
+        IntegrationInfo info = ctx.findSelectedIntegration();
+        CircuitBreakerInfo cb = info != null && ctx.askAiCallback != null ? 
selectedBreaker(info) : null;
+        if (cb != null && CircuitBreakerAiPrompt.hasTrouble(cb)) {
+            hint(spans, "Shift+F8", "explain with AI");
+        }
+    }
+
+    /** The breaker selected in the table, in the order it is shown; null when 
none is. */
+    CircuitBreakerInfo selectedBreaker(IntegrationInfo info) {
+        List<CircuitBreakerInfo> sorted = new 
ArrayList<>(info.circuitBreakers);
+        sorted.sort(this::sortCb);
+        Integer sel = tableState.selected();
+        return sel != null && sel >= 0 && sel < sorted.size() ? 
sorted.get(sel) : null;
+    }
+
     private int sortCb(CircuitBreakerInfo a, CircuitBreakerInfo b) {
         int result = switch (sort) {
             case "id" -> compareStr(a.id, b.id);
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthAiPrompt.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthAiPrompt.java
new file mode 100644
index 000000000000..4a183c097010
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthAiPrompt.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.util.TimeUtils;
+
+/**
+ * The question the AI panel is opened with to fix a health check that is not 
UP (Shift+F8 on the Health tab,
+ * CAMEL-25362): the check, what being DOWN means for the integration, its 
message, details and error, and the source of
+ * its route. The cause may be in the routes or the configuration, or outside 
the integration (a broker that is not
+ * running), so the AI is asked to tell which before it changes a file. It is 
put in the input of the panel, for the
+ * user to send with Enter or change first.
+ */
+final class HealthAiPrompt {
+
+    /** The most lines of a stack trace that are quoted, so a deep trace does 
not flood the question. */
+    static final int MAX_TRACE_LINES = 30;
+    /** The frames quoted under each exception of a stack trace (the exception 
itself and each Caused by). */
+    static final int FRAMES_PER_EXCEPTION = 3;
+
+    /** The details every check has (counts and times): the page already says 
them, the AI needs none of them. */
+    private static final Set<String> BOOKKEEPING = Set.of(
+            "invocation.count", "invocation.time", "invocation.attempted",
+            "failure.count", "failure.start.time", "failure.time", 
"failure.error.count", "failure.error.message",
+            "success.count", "success.start.time", "success.time");
+
+    private HealthAiPrompt() {
+    }
+
+    /**
+     * @param checks the checks to ask about, those that are not UP
+     * @param now    the time now (epoch millis), to say how long a check has 
been DOWN
+     */
+    static String of(IntegrationInfo info, List<HealthCheckInfo> checks, long 
now) {
+        StringBuilder sb = new StringBuilder();
+        String name = info.name != null ? info.name : info.pid;
+        if (checks.size() == 1) {
+            HealthCheckInfo hc = checks.get(0);
+            sb.append("The health check ").append(label(hc)).append(" of the 
running integration ").append(name)
+                    .append(" is ").append(hc.state).append(".\n");
+            check(sb, info, hc, now);
+        } else {
+            sb.append("These health checks of the running integration 
").append(name).append(" are not UP:\n");
+            for (HealthCheckInfo hc : checks) {
+                sb.append("\nThe check ").append(label(hc)).append(" is 
").append(hc.state).append(".\n");
+                check(sb, info, hc, now);
+            }
+            sb.append('\n');
+        }
+        sb.append("Find the cause first. When it is in the project's routes or 
configuration, fix it with")
+                .append(" camel_edit_file and check the file with 
camel_validate_source; dev mode reloads the file")
+                .append(" when it is saved. When it is outside the 
integration, such as a broker, database or server")
+                .append(" that is not running or cannot be reached, say how to 
start or reach it, and make no changes")
+                .append(" to the files.");
+        return sb.toString();
+    }
+
+    private static void check(StringBuilder sb, IntegrationInfo info, 
HealthCheckInfo hc, long now) {
+        if (hc.readiness && hc.liveness) {
+            sb.append("It is a readiness and liveness check: the integration 
is taken out of service and restarted.\n");
+        } else if (hc.readiness) {
+            sb.append("It is a readiness check: while it is not UP, the 
integration is taken out of service.\n");
+        } else if (hc.liveness) {
+            sb.append("It is a liveness check: while it is not UP, the 
integration is restarted.\n");
+        }
+        if (hc.message != null && !hc.message.isBlank()) {
+            sb.append("Its message: ").append(hc.message.strip()).append('\n');
+        }
+        if (hc.since > 0 || hc.failures > 0) {
+            sb.append("It has been ").append(hc.state);
+            if (hc.since > 0) {
+                sb.append(" for ").append(TimeUtils.printDuration(Math.max(0, 
now - hc.since), false));
+            }
+            if (hc.failures > 0) {
+                sb.append(", and failed ").append(hc.failures).append(" of 
").append(hc.invocations)
+                        .append(" times it ran");
+            }
+            sb.append(".\n");
+        }
+        StringBuilder details = new StringBuilder();
+        for (Map.Entry<String, String> e : hc.details.entrySet()) {
+            if (!BOOKKEEPING.contains(e.getKey()) && 
!e.getKey().startsWith("check.")) {
+                details.append(details.isEmpty() ? "" : ", 
").append(e.getKey()).append('=').append(e.getValue());
+            }
+        }
+        if (!details.isEmpty()) {
+            sb.append("Its details: ").append(details).append('\n');
+        }
+        String route = routeOf(hc);
+        if (route != null) {
+            for (RouteInfo r : info.routes) {
+                if (route.equals(r.routeId) && r.source != null) {
+                    sb.append("Its route ").append(route).append(" is at 
").append(r.source).append(".\n");
+                    break;
+                }
+            }
+        }
+        String trace = trace(hc.stackTrace);
+        if (trace != null) {
+            sb.append("The error:\n```\n").append(trace).append("```\n");
+        }
+    }
+
+    /** The group and the name of a check: consumers/consumer:orders. */
+    private static String label(HealthCheckInfo hc) {
+        String name = hc.name != null ? hc.name : "";
+        return hc.group != null && !hc.group.isEmpty() ? hc.group + "/" + name 
: name;
+    }
+
+    /** The route of a check: its route.id detail, else the name of a route or 
consumer check (route:orders). */
+    static String routeOf(HealthCheckInfo hc) {
+        String route = hc.details.get("route.id");
+        if (route != null) {
+            return route;
+        }
+        String name = hc.name;
+        if (name != null) {
+            for (String prefix : List.of("route:", "consumer:")) {
+                if (name.startsWith(prefix)) {
+                    return name.substring(prefix.length());
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * The stack trace, shortened: each exception (the first line and each 
Caused by) with its first few frames, at most
+     * {@link #MAX_TRACE_LINES} lines; null when there is none.
+     */
+    static String trace(List<String> lines) {
+        if (lines == null || lines.isEmpty()) {
+            return null;
+        }
+        StringBuilder sb = new StringBuilder();
+        int count = 0;
+        int frames = 0;
+        boolean skipped = false;
+        for (String line : lines) {
+            String text = line.stripTrailing();
+            if (text.isBlank()) {
+                continue;
+            }
+            boolean frame = text.stripLeading().startsWith("at ") || 
text.stripLeading().startsWith("...");
+            if (frame) {
+                if (++frames > FRAMES_PER_EXCEPTION) {
+                    skipped = true;
+                    continue;
+                }
+            } else {
+                frames = 0;
+                if (skipped) {
+                    sb.append("\t...\n");
+                    count++;
+                    skipped = false;
+                }
+            }
+            if (count >= MAX_TRACE_LINES) {
+                sb.append("\t...\n");
+                return sb.toString();
+            }
+            sb.append(text).append('\n');
+            count++;
+        }
+        if (skipped) {
+            sb.append("\t...\n");
+        }
+        return sb.toString();
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthCheckInfo.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthCheckInfo.java
index 6545b86ae9eb..197d3fc0d564 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthCheckInfo.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthCheckInfo.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.dsl.jbang.core.commands.tui;
 
+import java.util.List;
+import java.util.Map;
+
 class HealthCheckInfo {
     String group;
     String name;
@@ -32,4 +35,8 @@ class HealthCheckInfo {
     long failures;
     /** When it last failed (epoch millis), 0 when it did not. */
     long lastFailure;
+    /** The stack trace of the error of a check that is not UP, one line per 
entry; empty when there is none. */
+    List<String> stackTrace = List.of();
+    /** The details of the check (route.id, endpoint.uri and the check's own), 
as the health console gives them. */
+    Map<String, String> details = Map.of();
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthTab.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthTab.java
index b3b5b995ce14..3a2d7d73fffc 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthTab.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthTab.java
@@ -24,6 +24,7 @@ import dev.tamboui.layout.Rect;
 import dev.tamboui.style.Style;
 import dev.tamboui.terminal.Frame;
 import dev.tamboui.text.Span;
+import dev.tamboui.tui.event.KeyCode;
 import dev.tamboui.tui.event.KeyEvent;
 import dev.tamboui.tui.event.MouseEvent;
 import dev.tamboui.widgets.block.Block;
@@ -62,6 +63,10 @@ class HealthTab extends AbstractTableTab {
 
     @Override
     protected boolean handleTabKeyEvent(KeyEvent ke) {
+        if (ke.isKey(KeyCode.F8) && ke.hasShift()) {
+            askAiAboutChecksNotUp();
+            return true;
+        }
         if (ke.isCharIgnoreCase('t')) {
             table = !table;
             return true;
@@ -167,6 +172,49 @@ class HealthTab extends AbstractTableTab {
         }
     }
 
+    @Override
+    public void renderFKeyHints(List<Span> spans) {
+        // with the global F-keys, as the AI key of a screen is an F-key of 
every screen that has one
+        IntegrationInfo info = ctx.findSelectedIntegration();
+        if (ctx.askAiCallback != null && info != null && 
!checksToAskAbout(info).isEmpty()) {
+            hint(spans, "Shift+F8", "fix with AI");
+        }
+    }
+
+    /**
+     * Fix with AI (Shift+F8, CAMEL-25362): the selected check in the table, 
or every check that is not UP on the page.
+     */
+    private void askAiAboutChecksNotUp() {
+        IntegrationInfo info = ctx.findSelectedIntegration();
+        if (info == null || ctx.askAiCallback == null) {
+            return;
+        }
+        List<HealthCheckInfo> checks = checksToAskAbout(info);
+        if (checks.isEmpty()) {
+            if (ctx.notificationCallback != null) {
+                ctx.notificationCallback.accept(table
+                        ? "The selected check is UP: select one that is DOWN, 
or ask the AI with F8"
+                        : "All checks are UP: ask the AI with F8", false);
+            }
+            return;
+        }
+        ctx.askAiCallback.ask(HealthAiPrompt.of(info, checks, 
System.currentTimeMillis()));
+    }
+
+    /** The checks Shift+F8 asks about: the selected one in the table when it 
is not UP, else all that are not UP. */
+    List<HealthCheckInfo> checksToAskAbout(IntegrationInfo info) {
+        if (table) {
+            List<HealthCheckInfo> checks = new 
ArrayList<>(getFilteredHealthChecks(info));
+            checks.sort(this::sortHealth);
+            Integer sel = tableState.selected();
+            if (sel == null || sel < 0 || sel >= checks.size() || 
"UP".equals(checks.get(sel).state)) {
+                return List.of();
+            }
+            return List.of(checks.get(sel));
+        }
+        return info.healthChecks.stream().filter(hc -> 
!"UP".equals(hc.state)).toList();
+    }
+
     boolean isTable() {
         return table;
     }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteAiPrompt.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteAiPrompt.java
new file mode 100644
index 000000000000..c014f695bd1b
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteAiPrompt.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * The questions the AI panel is opened with on the Routes tab (Shift+F8, 
CAMEL-25362): fix a route whose exchanges
+ * fail, with the steps they fail at and the last error; or explain where the 
time goes in a route, with its slowest
+ * steps. It is put in the input of the panel, for the user to send with Enter 
or change first.
+ */
+final class RouteAiPrompt {
+
+    /** The most steps that are listed, so a big route does not flood the 
question. */
+    static final int MAX_STEPS = 8;
+    /** The slowest steps that are listed when explaining the time of a route. 
*/
+    static final int SLOWEST_STEPS = 5;
+
+    private RouteAiPrompt() {
+    }
+
+    /** Whether exchanges failed in the route, or failures were handled by its 
error handler. */
+    static boolean hasFailures(RouteInfo route) {
+        return route.failed > 0 || route.failuresHandled > 0;
+    }
+
+    static String ofFailures(IntegrationInfo info, RouteInfo route) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("Exchanges fail in route ").append(route.routeId).append(" 
of the running integration ")
+                .append(name(info)).append(": ").append(route.failed).append(" 
of ").append(route.total)
+                .append(" failed");
+        if (route.failuresHandled > 0) {
+            sb.append(", ").append(route.failuresHandled).append(" failures 
handled by the error handler");
+        }
+        if (route.redeliveries > 0) {
+            sb.append(", ").append(route.redeliveries).append(" redeliveries");
+        }
+        if (route.sinceLastFailed != null && !route.sinceLastFailed.isBlank()) 
{
+            sb.append("; the last failure 
").append(route.sinceLastFailed).append(" ago");
+        }
+        sb.append(".\n");
+        where(sb, route);
+        List<ProcessorInfo> failing = route.processors.stream()
+                .filter(p -> p.failed > 0 || p.failuresHandled > 
0).limit(MAX_STEPS).toList();
+        if (!failing.isEmpty()) {
+            sb.append("The steps they fail at (an EIP counts the failures of 
the steps inside it too):\n");
+            for (ProcessorInfo p : failing) {
+                step(sb, p);
+                sb.append(": ").append(p.failed).append(" failed");
+                if (p.failuresHandled > 0) {
+                    sb.append(", ").append(p.failuresHandled).append(" 
handled");
+                }
+                sb.append('\n');
+            }
+        }
+        ErrorInfo last = lastError(info, route.routeId);
+        if (last != null) {
+            sb.append("The last error of the route: 
").append(RuntimeFailures.failureOf(last));
+            String at = RuntimeFailures.sourceOf(info.routes, last);
+            if (last.nodeId != null) {
+                sb.append(" (at ").append(last.nodeId).append(at != null ? ", 
" + at : "").append(')');
+            }
+            sb.append('\n');
+        }
+        sb.append("Find the cause from the integration's errors and log, then 
fix it with camel_edit_file (the fix may")
+                .append(" belong on another line or in another route) and 
check the file with camel_validate_source.")
+                .append(" Dev mode reloads the file when it is saved.");
+        return sb.toString();
+    }
+
+    static String ofPerformance(IntegrationInfo info, RouteInfo route) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("Explain where the time goes in route 
").append(route.routeId).append(" of the running integration ")
+                .append(name(info)).append(": ").append(route.total).append(" 
exchanges, mean ")
+                .append(ChaosTab.shortTime(route.meanTime)).append(", max 
").append(ChaosTab.shortTime(route.maxTime));
+        if (route.p95Time >= 0) {
+            sb.append(", p95 ").append(ChaosTab.shortTime(route.p95Time));
+        }
+        if (route.p99Time >= 0) {
+            sb.append(", p99 ").append(ChaosTab.shortTime(route.p99Time));
+        }
+        if (route.throughput != null && !route.throughput.isBlank()) {
+            sb.append(", ").append(route.throughput).append(" msg/s");
+        }
+        if (route.inflight > 0) {
+            sb.append(", ").append(route.inflight).append(" in flight now");
+        }
+        sb.append(".\n");
+        where(sb, route);
+        List<ProcessorInfo> slowest = route.processors.stream().filter(p -> 
p.total > 0)
+                .sorted(Comparator.comparingLong((ProcessorInfo p) -> 
p.meanTime).reversed())
+                .limit(SLOWEST_STEPS).toList();
+        if (!slowest.isEmpty()) {
+            sb.append("The slowest steps by mean time (the time of an EIP 
includes the steps inside it):\n");
+            for (ProcessorInfo p : slowest) {
+                step(sb, p);
+                sb.append(": mean 
").append(ChaosTab.shortTime(p.meanTime)).append(", max ")
+                        .append(ChaosTab.shortTime(p.maxTime)).append(", 
").append(p.total).append(" calls\n");
+            }
+        }
+        sb.append("Tell which steps take the time and why (such as a remote 
call, a slow query, a delay or a large")
+                .append(" body), and suggest what could make the route faster, 
if anything. tui_get_table on the")
+                .append(" Routes tab has the numbers. Make no changes to the 
files unless I agree.");
+        return sb.toString();
+    }
+
+    private static void where(StringBuilder sb, RouteInfo route) {
+        if (route.from != null) {
+            sb.append("It starts from ").append(route.from);
+            sb.append(route.source != null ? " and is at " + route.source : 
"").append(".\n");
+        } else if (route.source != null) {
+            sb.append("It is at ").append(route.source).append(".\n");
+        }
+    }
+
+    private static void step(StringBuilder sb, ProcessorInfo p) {
+        sb.append("  ").append(p.id != null ? p.id : "?");
+        if (p.processor != null) {
+            sb.append(" (").append(p.processor).append(')');
+        }
+        if (p.uri != null) {
+            sb.append(" to ").append(p.uri);
+        }
+        if (p.source != null) {
+            sb.append(" at ").append(p.source);
+        }
+    }
+
+    /** The newest error of the route in the error registry; null when there 
is none. */
+    static ErrorInfo lastError(IntegrationInfo info, String routeId) {
+        ErrorInfo last = null;
+        for (ErrorInfo e : info.errors) {
+            if (routeId != null && routeId.equals(e.routeId) && (last == null 
|| e.timestamp > last.timestamp)) {
+                last = e;
+            }
+        }
+        return last;
+    }
+
+    private static String name(IntegrationInfo info) {
+        return info.name != null ? info.name : info.pid;
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
index a721f4737d44..171a1a43c4a0 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
@@ -148,6 +148,10 @@ class RoutesTab extends AbstractDiagramTab {
      * Keys in the route table view (sort, top mode, description, open 
diagram, source, start/stop, suspend/resume).
      */
     private boolean handleTableKeys(KeyEvent ke) {
+        if (!diagram.isShowDiagram() && !sourceViewer.isVisible() && 
ke.isKey(KeyCode.F8) && ke.hasShift()) {
+            askAiAboutSelectedRoute();
+            return true;
+        }
         // Sort (only when not in diagram)
         if (!diagram.isShowDiagram() && ke.isChar('s')) {
             if (routeTopMode) {
@@ -815,6 +819,49 @@ class RoutesTab extends AbstractDiagramTab {
         }
     }
 
+    @Override
+    public void renderFKeyHints(List<Span> spans) {
+        // with the global F-keys, as the AI key of a screen is an F-key of 
every screen that has one
+        String label = aiHintLabel();
+        if (label != null) {
+            hint(spans, "Shift+F8", label);
+        }
+    }
+
+    /** The label of Shift+F8 for the selected route: fix its failures, else 
explain its time; null when not offered. */
+    String aiHintLabel() {
+        if (ctx.askAiCallback == null || diagram.isShowDiagram() || 
sourceViewer.isVisible()
+                || gotoNodePopup.isVisible()) {
+            return null;
+        }
+        RouteInfo route = selectedRoute();
+        if (route == null) {
+            return null;
+        }
+        if (RouteAiPrompt.hasFailures(route)) {
+            return "fix with AI";
+        }
+        return route.total > 0 ? "explain with AI" : null;
+    }
+
+    /**
+     * Shift+F8 on a route (CAMEL-25362): fix with AI when its exchanges fail, 
else explain with AI where its time goes.
+     */
+    private void askAiAboutSelectedRoute() {
+        IntegrationInfo info = ctx.findSelectedIntegration();
+        RouteInfo route = selectedRoute();
+        if (info == null || route == null || ctx.askAiCallback == null) {
+            return;
+        }
+        if (RouteAiPrompt.hasFailures(route)) {
+            ctx.askAiCallback.ask(RouteAiPrompt.ofFailures(info, route));
+        } else if (route.total > 0) {
+            ctx.askAiCallback.ask(RouteAiPrompt.ofPerformance(info, route));
+        } else if (ctx.notificationCallback != null) {
+            ctx.notificationCallback.accept("No exchanges in this route yet: 
ask the AI with F8", false);
+        }
+    }
+
     private String routeFromLabel(RouteInfo route) {
         if (showDescription && route.description != null && 
!route.description.isBlank()) {
             return route.description;
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SqlTraceAiPrompt.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SqlTraceAiPrompt.java
new file mode 100644
index 000000000000..98c1eccc3ea0
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SqlTraceAiPrompt.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.camel.util.URISupport;
+
+/**
+ * The questions the AI panel is opened with on the SQL Trace tab (Shift+F8, 
CAMEL-25362): fix a statement that failed,
+ * with the exception of its exchange; or explain a slow one, with how often 
the same SQL ran and how long it took. It
+ * is put in the input of the panel, for the user to send with Enter or change 
first.
+ */
+final class SqlTraceAiPrompt {
+
+    /** A statement this slow or slower is slow, as the KPI strip and the 
table count it. */
+    static final long SLOW_MS = 100;
+
+    private SqlTraceAiPrompt() {
+    }
+
+    /** Whether Shift+F8 has something to ask about a statement: it failed, or 
it was slow. */
+    static boolean hasTrouble(SqlTraceInfo si) {
+        return si.failed || si.duration >= SLOW_MS;
+    }
+
+    static String of(IntegrationInfo info, SqlTraceInfo si) {
+        StringBuilder sb = new StringBuilder();
+        String name = info.name != null ? info.name : info.pid;
+        if (si.failed) {
+            sb.append("A SQL statement failed in the running integration 
").append(name);
+        } else {
+            sb.append("A SQL statement is slow in the running integration 
").append(name).append(": it took ")
+                    .append(si.duration).append(" ms");
+        }
+        sb.append(".\n");
+        sb.append("The statement").append(si.category != null ? " (" + 
si.category + ")" : "").append(":\n```sql\n")
+                .append(si.query != null ? si.query.strip() : 
"").append("\n```\n");
+        if (si.endpoint != null) {
+            sb.append("Its endpoint: 
").append(URISupport.sanitizeUri(si.endpoint)).append('\n');
+        }
+        if (si.routeId != null) {
+            sb.append("It ran in route ").append(si.routeId);
+            if (si.nodeId != null) {
+                sb.append(" at step ").append(si.nodeId);
+            }
+            if (si.location != null) {
+                sb.append(", ").append(si.location);
+            }
+            sb.append(".\n");
+        }
+        if (si.failed) {
+            ErrorInfo error = errorOf(info, si);
+            if (error != null) {
+                sb.append("The error: 
").append(RuntimeFailures.failureOf(error)).append('\n');
+            }
+            sb.append("Find the cause (such as the SQL itself, a table or 
column that does not exist, the parameters,")
+                    .append(" or the connection) from the integration's errors 
and log. When it is in the project's")
+                    .append(" routes or configuration, fix it with 
camel_edit_file and check the file with")
+                    .append(" camel_validate_source; dev mode reloads the file 
when it is saved. When it is in the")
+                    .append(" database (its schema or data), say what to 
change there, and make no changes to the")
+                    .append(" files.");
+        } else {
+            same(sb, info.sqlTraceStatements, si);
+            if (si.rowCount > 0) {
+                sb.append("It returned ").append(si.rowCount).append(" 
rows.\n");
+            } else if (si.updateCount > 0) {
+                sb.append("It updated ").append(si.updateCount).append(" 
rows.\n");
+            }
+            sb.append("Tell why it may be slow (such as a missing index, many 
rows, a lock, or a statement per")
+                    .append(" message that could be a batch) and suggest what 
could make it faster, in the SQL, the")
+                    .append(" database or the route. tui_execute_sql can run 
an EXPLAIN of it to check.")
+                    .append(" Make no changes to the files unless I agree.");
+        }
+        return sb.toString();
+    }
+
+    /** How often the same SQL ran among the traced statements, and its mean 
and slowest time. */
+    private static void same(StringBuilder sb, List<SqlTraceInfo> all, 
SqlTraceInfo si) {
+        long count = 0;
+        long sum = 0;
+        long max = 0;
+        for (SqlTraceInfo other : all) {
+            if (Objects.equals(other.query, si.query)) {
+                count++;
+                sum += other.duration;
+                max = Math.max(max, other.duration);
+            }
+        }
+        if (count > 1) {
+            sb.append("The same SQL ran ").append(count).append(" times among 
the traced statements: mean ")
+                    .append(sum / count).append(" ms, slowest 
").append(max).append(" ms.\n");
+        }
+    }
+
+    /** The error of the statement's exchange, else the newest error of its 
route; null when there is none. */
+    static ErrorInfo errorOf(IntegrationInfo info, SqlTraceInfo si) {
+        if (si.exchangeId != null) {
+            for (ErrorInfo e : info.errors) {
+                if (si.exchangeId.equals(e.exchangeId)) {
+                    return e;
+                }
+            }
+        }
+        return RouteAiPrompt.lastError(info, si.routeId);
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SqlTraceTab.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SqlTraceTab.java
index 3a70646f0c6e..4d0ece516ebc 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SqlTraceTab.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SqlTraceTab.java
@@ -82,6 +82,10 @@ class SqlTraceTab extends AbstractTableTab {
 
     @Override
     protected boolean handleTabKeyEvent(KeyEvent ke) {
+        if (ke.isKey(KeyCode.F8) && ke.hasShift()) {
+            askAiAboutSelectedStatement();
+            return true;
+        }
         if (ke.isCharIgnoreCase('w')) {
             wordWrap = !wordWrap;
             return true;
@@ -174,16 +178,40 @@ class SqlTraceTab extends AbstractTableTab {
 
     private String getSelectedQuery() {
         IntegrationInfo info = ctx.findSelectedIntegration();
-        if (info == null) {
-            return null;
-        }
+        SqlTraceInfo si = info != null ? selectedStatement(info) : null;
+        return si != null ? si.query : null;
+    }
+
+    /** The statement selected in the table, in the order it is shown; null 
when none is. */
+    SqlTraceInfo selectedStatement(IntegrationInfo info) {
         List<SqlTraceInfo> sorted = new ArrayList<>(info.sqlTraceStatements);
         sorted.sort(this::sortTrace);
         Integer sel = tableState.selected();
-        if (sel != null && sel >= 0 && sel < sorted.size()) {
-            return sorted.get(sel).query;
+        return sel != null && sel >= 0 && sel < sorted.size() ? 
sorted.get(sel) : null;
+    }
+
+    @Override
+    public void renderFKeyHints(List<Span> spans) {
+        // with the global F-keys, as the AI key of a screen is an F-key of 
every screen that has one
+        IntegrationInfo info = ctx.findSelectedIntegration();
+        SqlTraceInfo si = info != null && ctx.askAiCallback != null ? 
selectedStatement(info) : null;
+        if (si != null && SqlTraceAiPrompt.hasTrouble(si)) {
+            hint(spans, "Shift+F8", si.failed ? "fix with AI" : "explain with 
AI");
+        }
+    }
+
+    /** Shift+F8 (CAMEL-25362): fix with AI a statement that failed, explain 
with AI a slow one. */
+    private void askAiAboutSelectedStatement() {
+        IntegrationInfo info = ctx.findSelectedIntegration();
+        SqlTraceInfo si = info != null ? selectedStatement(info) : null;
+        if (si == null || ctx.askAiCallback == null) {
+            return;
+        }
+        if (SqlTraceAiPrompt.hasTrouble(si)) {
+            ctx.askAiCallback.ask(SqlTraceAiPrompt.of(info, si));
+        } else if (ctx.notificationCallback != null) {
+            ctx.notificationCallback.accept("This statement did not fail and 
was not slow: ask the AI with F8", false);
         }
-        return null;
     }
 
     private static String traceKey(SqlTraceInfo si) {
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/StatusParser.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/StatusParser.java
index a306928a7679..a92351861d69 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/StatusParser.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/StatusParser.java
@@ -404,6 +404,9 @@ final class StatusParser {
                     if (details != null) {
                         healthDetails(hc, details);
                     }
+                    if (cj.get("stackTrace") instanceof JsonArray trace) {
+                        hc.stackTrace = 
trace.stream().map(String::valueOf).toList();
+                    }
                     addHealthCheck(info.healthChecks, hc);
                 }
             }
@@ -417,6 +420,9 @@ final class StatusParser {
         hc.lastFailure = epochMillis(details.getString("failure.time"));
         hc.invocations = TuiHelper.objToLong(details.get("invocation.count"));
         hc.failures = TuiHelper.objToLong(details.get("failure.count"));
+        Map<String, String> all = new LinkedHashMap<>();
+        details.forEach((k, v) -> all.put(k, String.valueOf(v)));
+        hc.details = all;
     }
 
     /** A time as the health check details have it 
(2026-11-09T17:02:42.44+01:00[Europe/Copenhagen]); 0 when not. */
@@ -446,6 +452,8 @@ final class StatusParser {
                 if (!"DOWN".equals(known.state) && hc.state != null && 
!"UP".equals(hc.state)) {
                     known.state = hc.state;
                     known.message = hc.message != null ? hc.message : 
known.message;
+                    known.stackTrace = hc.stackTrace;
+                    known.details = hc.details;
                     known.since = hc.since;
                     known.lastUp = hc.lastUp;
                 }
@@ -1424,6 +1432,9 @@ final class StatusParser {
             cb.bulkheadRejectedCalls = 
TuiHelper.objToLong(bj.get("bulkheadRejectedCalls"));
             Object fr = bj.get("failureRate");
             cb.failureRate = fr instanceof Number n ? n.doubleValue() : -1;
+            if (bj.get("configuration") instanceof JsonObject conf) {
+                cb.configuration = new LinkedHashMap<>(conf);
+            }
             info.circuitBreakers.add(cb);
         }
     }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/circuit-breaker.md
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/circuit-breaker.md
index 797ec6646829..77e6c052efd9 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/circuit-breaker.md
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/circuit-breaker.md
@@ -101,6 +101,17 @@ The bottom panel shows when a circuit breaker is selected:
   fallback, timeout, bulkhead (calls rejected because the bulkhead
   was full) and timing statistics (mean/min/max processing time)
 
+## Explain with AI
+
+Press `Shift+F8` on a circuit breaker that is open or half open, or
+whose calls failed, timed out or were rejected, to ask the AI about it.
+The AI panel opens with a question made of its state and counters, its
+configuration, its line in the source and the last error of its route.
+The AI tells whether the breaker did its job (the service it protects
+failed or was slow) or whether its configuration does not fit the
+traffic, and suggests what to change. It changes no file unless you
+agree.
+
 ## Configuration Tips
 
 Common Resilience4j settings you can tune in your route:
@@ -117,3 +128,4 @@ Common Resilience4j settings you can tune in your route:
 - `Up/Down` — select circuit breaker
 - `s` — cycle sort column
 - `S` — reverse sort order
+- `Shift+F8` — explain with AI why the selected circuit breaker is open, or 
why its calls fail
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/health.md 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/health.md
index 4a578fcdf2c6..b4d2802e508a 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/health.md
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/health.md
@@ -34,6 +34,15 @@ Under both, `ready` and `live` are drawn second by second 
over the last
 minutes, as the TUI read them: a check that went DOWN and came back
 between two looks at the tab shows there, with how long it was down.
 
+Press `Shift+F8` to ask the AI why a check is DOWN. The AI panel opens
+with a question about the checks that are not UP (in the table, the
+selected one): the message, what it means for the integration, the
+details of the check (such as its route and endpoint), the source line
+of its route and the stack trace of the error. The AI finds the cause
+and fixes it when it is in your routes or configuration, or says how to
+start or reach what is down when it is outside the integration, such as
+a broker that is not running.
+
 Press `t` for the checks one by one in the table below, and `d` there
 for only the DOWN ones. The More menu has a `DOWN` badge on Health while
 a check is DOWN.
@@ -110,3 +119,4 @@ when to restart it.
 - `S` — reverse sort order
 - `t` — the checks one by one in a table, or the page again
 - `d` — in the table: show only the checks that are DOWN, or all of them again
+- `Shift+F8` — fix with AI: on the page, the checks that are not UP; in the 
table, the selected one when it is not UP
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/routes.md 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/routes.md
index 32ce02c312eb..8cde87eb82a0 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/routes.md
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/routes.md
@@ -66,6 +66,20 @@ processor (step) inside a route, not just the route totals.
 
 - **LOAD** — Three throughput averages over 1m/5m/15m windows, similar to Unix 
load average but measuring message throughput instead of CPU. Higher values 
mean more messages flowing through. The three windows help you see if traffic 
is increasing or decreasing
 
+## Fix or Explain with AI
+
+Press `Shift+F8` on a route to ask the AI about it:
+
+- When exchanges failed in the route, or its error handler handled
+  failures, the AI is asked to fix it ("fix with AI"): the question has
+  the counts, the steps the exchanges fail at with their source lines,
+  and the last error of the route.
+- Otherwise, when the route had exchanges, the AI is asked to explain
+  where the time goes ("explain with AI"): the question has the mean,
+  max and percentile times, and the slowest steps with their source
+  lines. The AI suggests what could make it faster and changes no file
+  unless you agree.
+
 ## Route Diagram
 
 Press `d` to see a topology diagram showing how all routes connect to each
@@ -149,6 +163,7 @@ in the diagram.
 - `s` — cycle sort column
 - `S` — reverse sort order
 - `t` — toggle Top mode
+- `Shift+F8` — fix with AI a route whose exchanges fail, or explain with AI 
where its time goes
 
 **Topology view:**
 - `↑↓←→` — navigate between route boxes
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/sql-trace.md
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/sql-trace.md
index 7b6cb926909a..89d49e1e078c 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/sql-trace.md
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/sql-trace.md
@@ -28,6 +28,18 @@ The top bar shows aggregate statistics:
 Select a statement with Up/Down to see full details below the table:
 SQL text, endpoint URI, route, exchange ID, timing, and row counts.
 
+## Fix or Explain with AI
+
+Press `Shift+F8` on a statement that failed to ask the AI to fix it: the
+question has the SQL, its endpoint, the route and source line it ran
+at, and the error of its exchange. The AI tells whether the cause is in
+the project, and fixes it there, or in the database.
+
+On a slow statement (100 ms or more), `Shift+F8` asks the AI to explain
+why it is slow: the SQL, its time and rows, and how often the same SQL
+ran. The AI suggests what could make it faster and changes no file
+unless you agree.
+
 ## Keys
 
 - `Up/Down` — select statement
@@ -37,3 +49,4 @@ SQL text, endpoint URI, route, exchange ID, timing, and row 
counts.
 - `S` — reverse sort order
 - `w` — toggle word wrap
 - `F4` — edit the selected statement in the SQL Query tab
+- `Shift+F8` — fix with AI a statement that failed, or explain with AI a slow 
one
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerAiPromptTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerAiPromptTest.java
new file mode 100644
index 000000000000..3ff040f439fd
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/CircuitBreakerAiPromptTest.java
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import dev.tamboui.text.Span;
+import dev.tamboui.tui.event.KeyCode;
+import dev.tamboui.tui.event.KeyEvent;
+import dev.tamboui.tui.event.KeyModifiers;
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * CAMEL-25362: explain with AI (Shift+F8) on the Circuit Breaker tab, for a 
breaker that is open or whose calls fail.
+ */
+class CircuitBreakerAiPromptTest {
+
+    private final List<String> asked = new ArrayList<>();
+    private final List<String> notified = new ArrayList<>();
+    private IntegrationInfo info;
+    private MonitorContext ctx;
+
+    @BeforeEach
+    void setUp() {
+        Theme.resetForTesting();
+        info = new IntegrationInfo();
+        info.pid = "1234";
+        info.name = "circuit-breaker";
+        ctx = new MonitorContext(new AtomicReference<>(List.of(info)), new 
AtomicReference<>(List.of()));
+        ctx.selectedPid = "1234";
+        ctx.askAiCallback = new MonitorContext.AskAi() {
+            @Override
+            public void fixProblem(Path file, int line, String problem, String 
lineText) {
+                asked.add("fix: " + problem);
+            }
+
+            @Override
+            public void ask(String question) {
+                asked.add(question);
+            }
+        };
+        ctx.notificationCallback = (message, error) -> notified.add(message);
+    }
+
+    @Test
+    void theQuestionHasTheStateCountersConfigurationSourceAndLastError() {
+        RouteInfo route = new RouteInfo();
+        route.routeId = "stock-check";
+        route.source = "stock.camel.yaml:5";
+        ProcessorInfo breaker = new ProcessorInfo();
+        breaker.id = "supplier-breaker";
+        breaker.source = "stock.camel.yaml:9";
+        route.processors.add(breaker);
+        info.routes.add(route);
+        ErrorInfo older = error("stock-check", 1000, 
"java.net.SocketTimeoutException", "Read timed out");
+        ErrorInfo newer = error("stock-check", 2000, 
"java.net.ConnectException", "Connection refused");
+        ErrorInfo other = error("orders", 3000, 
"java.lang.IllegalStateException", "other route");
+        info.errors = new ArrayList<>(List.of(older, newer, other));
+        CircuitBreakerInfo cb = openBreaker();
+
+        String question = CircuitBreakerAiPrompt.of(info, cb);
+
+        assertThat(question)
+                .startsWith("Explain the circuit breaker supplier-breaker in 
route stock-check of the running integration"
+                            + " circuit-breaker: it is OPEN (resilience4j).\n")
+                .contains("Its sliding window: 3 successful, 2 failed (1 of 
all calls timed out), failure rate 40%.\n")
+                .contains("Since it started: 9 calls rejected while open, 11 
answered by the fallback.\n")
+                .contains("Its configuration: failureRateThreshold=50.0, 
minimumNumberOfCalls=5,"
+                          + " waitDurationInOpenState=10000\n")
+                .contains("It is at stock.camel.yaml:9.\n")
+                .contains("The last error of the route: ConnectException: 
Connection refused\n")
+                .endsWith("Make no changes to the files unless I agree.");
+    }
+
+    @Test
+    void aClosedBreakerWithoutFailuresHasNothingToExplain() {
+        CircuitBreakerInfo cb = new CircuitBreakerInfo();
+        cb.state = "CLOSED";
+        cb.successfulCalls = 10;
+        assertThat(CircuitBreakerAiPrompt.hasTrouble(cb)).isFalse();
+        cb.timedOutCalls = 1;
+        assertThat(CircuitBreakerAiPrompt.hasTrouble(cb)).isTrue();
+        cb.timedOutCalls = 0;
+        cb.state = "HALF_OPEN";
+        assertThat(CircuitBreakerAiPrompt.hasTrouble(cb)).isTrue();
+    }
+
+    @Test
+    void theStatusKeepsTheConfigurationOfABreaker() throws Exception {
+        JsonObject root = (JsonObject) Jsoner.deserialize("""
+                {"context": {"name": "circuit-breaker"},
+                 "resilience4j": {"circuitBreakers": [
+                   {"id": "supplier-breaker", "routeId": "stock-check", 
"state": "OPEN", "failedCalls": 2,
+                    "configuration": {"failureRateThreshold": 50.0, 
"waitDurationInOpenState": 10000}}]}}
+                """);
+        IntegrationInfo parsed = 
StatusParser.parseIntegration(ProcessHandle.current(), root);
+
+        assertThat(parsed.circuitBreakers).singleElement()
+                .satisfies(cb -> 
assertThat(cb.configuration).containsKeys("failureRateThreshold",
+                        "waitDurationInOpenState"));
+    }
+
+    @Test
+    void shiftF8AsksAboutTheSelectedBreakerWhenItHasTrouble() {
+        CircuitBreakerInfo healthy = new CircuitBreakerInfo();
+        healthy.routeId = "checkout";
+        healthy.id = "payment-breaker";
+        healthy.state = "CLOSED";
+        healthy.successfulCalls = 450;
+        info.circuitBreakers.add(healthy);
+        info.circuitBreakers.add(openBreaker());
+        CircuitBreakerTab tab = new CircuitBreakerTab(ctx, new 
MetricsCollector());
+        tab.onTabSelected();
+
+        // sorted by route: checkout first, closed and quiet
+        assertThat(fKeyHints(tab)).isEmpty();
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+        assertThat(asked).isEmpty();
+        assertThat(notified).singleElement().asString().startsWith("This 
circuit breaker is closed");
+
+        tab.tableState.select(1);
+        assertThat(fKeyHints(tab)).contains("Shift+F8").contains("explain with 
AI");
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+        assertThat(asked).singleElement().asString()
+                .startsWith("Explain the circuit breaker supplier-breaker in 
route stock-check");
+    }
+
+    private static CircuitBreakerInfo openBreaker() {
+        CircuitBreakerInfo cb = new CircuitBreakerInfo();
+        cb.routeId = "stock-check";
+        cb.id = "supplier-breaker";
+        cb.component = "resilience4j";
+        cb.state = "OPEN";
+        cb.successfulCalls = 3;
+        cb.failedCalls = 2;
+        cb.timedOutCalls = 1;
+        cb.notPermittedCalls = 9;
+        cb.fallbackCalls = 11;
+        cb.failureRate = 40;
+        Map<String, Object> conf = new LinkedHashMap<>();
+        conf.put("failureRateThreshold", 50.0);
+        conf.put("minimumNumberOfCalls", 5);
+        conf.put("waitDurationInOpenState", 10000);
+        conf.put("timeoutDuration", null);
+        cb.configuration = conf;
+        return cb;
+    }
+
+    private static ErrorInfo error(String routeId, long timestamp, String 
type, String message) {
+        ErrorInfo e = new ErrorInfo();
+        e.routeId = routeId;
+        e.timestamp = timestamp;
+        e.exceptionType = type;
+        e.exceptionMessage = message;
+        return e;
+    }
+
+    private static String fKeyHints(MonitorTab tab) {
+        List<Span> spans = new ArrayList<>();
+        tab.renderFKeyHints(spans);
+        StringBuilder sb = new StringBuilder();
+        spans.forEach(s -> sb.append(s.content()));
+        return sb.toString();
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthAiPromptTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthAiPromptTest.java
new file mode 100644
index 000000000000..1a0dffb0f855
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthAiPromptTest.java
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import dev.tamboui.text.Span;
+import dev.tamboui.tui.event.KeyCode;
+import dev.tamboui.tui.event.KeyEvent;
+import dev.tamboui.tui.event.KeyModifiers;
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * CAMEL-25362: fix with AI (Shift+F8) on the Health tab, for the checks that 
are not UP.
+ */
+class HealthAiPromptTest {
+
+    private static final long NOW = 1_800_000_000_000L;
+
+    private final List<String> asked = new ArrayList<>();
+    private final List<String> notified = new ArrayList<>();
+    private IntegrationInfo info;
+    private MonitorContext ctx;
+
+    @BeforeEach
+    void setUp() {
+        Theme.resetForTesting();
+        info = new IntegrationInfo();
+        info.pid = "1234";
+        info.name = "orders-app";
+        ctx = new MonitorContext(new AtomicReference<>(List.of(info)), new 
AtomicReference<>(List.of()));
+        ctx.selectedPid = "1234";
+        ctx.askAiCallback = new MonitorContext.AskAi() {
+            @Override
+            public void fixProblem(Path file, int line, String problem, String 
lineText) {
+                asked.add("fix: " + problem);
+            }
+
+            @Override
+            public void ask(String question) {
+                asked.add(question);
+            }
+        };
+        ctx.notificationCallback = (message, error) -> notified.add(message);
+    }
+
+    @Test
+    void theQuestionHasTheMessageDetailsRouteAndError() {
+        RouteInfo orders = new RouteInfo();
+        orders.routeId = "orders";
+        orders.source = "orders.camel.yaml:3";
+        info.routes.add(orders);
+        HealthCheckInfo hc = consumerDown();
+
+        String question = HealthAiPrompt.of(info, List.of(hc), NOW);
+
+        assertThat(question)
+                .startsWith("The health check consumers/consumer:orders of the 
running integration orders-app is DOWN.\n")
+                .contains("It is a readiness check: while it is not UP, the 
integration is taken out of service.\n")
+                .contains("Its message: Consumer failed polling 3 times route: 
orders (kafka://orders)\n")
+                .contains("It has been DOWN for 2m0s, and failed 3 of 10 times 
it ran.\n")
+                // the details that say where, not the bookkeeping the page 
already shows
+                .contains("Its details: route.id=orders, 
endpoint.uri=kafka://orders, consumer.failure=connect\n")
+                
.doesNotContain("invocation.count").doesNotContain("failure.start.time").doesNotContain("check.kind")
+                .contains("Its route orders is at orders.camel.yaml:3.\n")
+                .contains("The 
error:\n```\norg.apache.kafka.common.KafkaException: Failed to construct kafka 
consumer\n")
+                .contains("Find the cause first.").contains("camel_edit_file")
+                .endsWith("say how to start or reach it, and make no changes 
to the files.");
+    }
+
+    @Test
+    void severalChecksAreAskedAboutTogether() {
+        HealthCheckInfo route = new HealthCheckInfo();
+        route.group = "camel";
+        route.name = "route:shipping";
+        route.state = "DOWN";
+        route.liveness = true;
+        String question = HealthAiPrompt.of(info, List.of(consumerDown(), 
route), NOW);
+
+        assertThat(question)
+                .startsWith("These health checks of the running integration 
orders-app are not UP:\n")
+                .contains("\nThe check consumers/consumer:orders is DOWN.\n")
+                .contains("\nThe check camel/route:shipping is DOWN.\n"
+                          + "It is a liveness check: while it is not UP, the 
integration is restarted.\n");
+    }
+
+    @Test
+    void theRouteOfACheckFromItsDetailsOrName() {
+        HealthCheckInfo hc = new HealthCheckInfo();
+        hc.name = "route:shipping";
+        assertThat(HealthAiPrompt.routeOf(hc)).isEqualTo("shipping");
+        hc.details = Map.of("route.id", "orders");
+        assertThat(HealthAiPrompt.routeOf(hc)).isEqualTo("orders");
+        hc.details = Map.of();
+        hc.name = "context";
+        assertThat(HealthAiPrompt.routeOf(hc)).isNull();
+    }
+
+    @Test
+    void aLongStackTraceIsShortenedToTheExceptionsAndTheirFirstFrames() {
+        List<String> lines = new ArrayList<>();
+        lines.add("java.lang.IllegalStateException: boom");
+        for (int i = 0; i < 20; i++) {
+            lines.add("\tat org.example.Foo.bar" + i + "(Foo.java:" + i + ")");
+        }
+        lines.add("Caused by: java.net.ConnectException: Connection refused");
+        lines.add("\tat java.base/sun.nio.ch.Net.connect0(Native Method)");
+        lines.add("\t... 20 more");
+
+        String trace = HealthAiPrompt.trace(lines);
+
+        assertThat(trace).isEqualTo("""
+                java.lang.IllegalStateException: boom
+                \tat org.example.Foo.bar0(Foo.java:0)
+                \tat org.example.Foo.bar1(Foo.java:1)
+                \tat org.example.Foo.bar2(Foo.java:2)
+                \t...
+                Caused by: java.net.ConnectException: Connection refused
+                \tat java.base/sun.nio.ch.Net.connect0(Native Method)
+                \t... 20 more
+                """);
+        assertThat(HealthAiPrompt.trace(List.of())).isNull();
+    }
+
+    @Test
+    void theStatusKeepsTheStackTraceAndDetailsOfACheck() throws Exception {
+        JsonObject root = (JsonObject) Jsoner.deserialize("""
+                {"context": {"name": "orders-app"},
+                 "healthChecks": {"ready": false, "live": true, "checks": [
+                   {"id": "consumer:orders", "group": "consumers", "state": 
"DOWN", "readiness": true,
+                    "message": "Consumer failed polling",
+                    "stackTrace": ["java.net.ConnectException: Connection 
refused", "\\tat a.B.c(B.java:1)"],
+                    "details": {"route.id": "orders", "endpoint.uri": 
"kafka://orders", "failure.count": 2}}]}}
+                """);
+        IntegrationInfo parsed = 
StatusParser.parseIntegration(ProcessHandle.current(), root);
+
+        HealthCheckInfo hc = parsed.healthChecks.get(0);
+        assertThat(hc.stackTrace).containsExactly("java.net.ConnectException: 
Connection refused", "\tat a.B.c(B.java:1)");
+        assertThat(hc.details).containsEntry("route.id", 
"orders").containsEntry("endpoint.uri", "kafka://orders")
+                .containsEntry("failure.count", "2");
+        assertThat(hc.failures).isEqualTo(2);
+    }
+
+    @Test
+    void shiftF8OnThePageAsksAboutTheChecksThatAreNotUp() {
+        info.healthChecks.add(up("context"));
+        info.healthChecks.add(consumerDown());
+        HealthTab tab = new HealthTab(ctx);
+
+        assertThat(fKeyHints(tab)).contains("Shift+F8").contains("fix with 
AI");
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+
+        assertThat(asked).singleElement().asString()
+                .startsWith("The health check consumers/consumer:orders of the 
running integration orders-app is DOWN.");
+    }
+
+    @Test
+    void shiftF8InTheTableAsksAboutTheSelectedCheckOnlyWhenItIsNotUp() {
+        info.healthChecks.add(up("context"));
+        info.healthChecks.add(consumerDown());
+        HealthTab tab = new HealthTab(ctx);
+        tab.handleKeyEvent(KeyEvent.ofChar('t', KeyModifiers.NONE));
+        // sorted by name: consumer:orders, context
+        tab.tableState.select(1);
+
+        assertThat(fKeyHints(tab)).doesNotContain("Shift+F8");
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+        assertThat(asked).isEmpty();
+        assertThat(notified).singleElement().asString().startsWith("The 
selected check is UP");
+
+        tab.tableState.select(0);
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+        
assertThat(asked).singleElement().asString().contains("consumers/consumer:orders");
+    }
+
+    @Test
+    void noHintWhenAllChecksAreUp() {
+        info.healthChecks.add(up("context"));
+        HealthTab tab = new HealthTab(ctx);
+
+        assertThat(fKeyHints(tab)).isEmpty();
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+        assertThat(asked).isEmpty();
+        assertThat(notified).containsExactly("All checks are UP: ask the AI 
with F8");
+    }
+
+    private static HealthCheckInfo consumerDown() {
+        HealthCheckInfo hc = new HealthCheckInfo();
+        hc.group = "consumers";
+        hc.name = "consumer:orders";
+        hc.state = "DOWN";
+        hc.readiness = true;
+        hc.message = "Consumer failed polling 3 times route: orders 
(kafka://orders)";
+        hc.since = NOW - 120_000;
+        hc.failures = 3;
+        hc.invocations = 10;
+        Map<String, String> details = new LinkedHashMap<>();
+        details.put("check.kind", "READINESS");
+        details.put("invocation.count", "10");
+        details.put("failure.start.time", "2026-11-17T10:00:00+01:00");
+        details.put("route.id", "orders");
+        details.put("endpoint.uri", "kafka://orders");
+        details.put("consumer.failure", "connect");
+        hc.details = details;
+        hc.stackTrace = List.of("org.apache.kafka.common.KafkaException: 
Failed to construct kafka consumer",
+                "\tat 
org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:830)");
+        return hc;
+    }
+
+    private static HealthCheckInfo up(String name) {
+        HealthCheckInfo hc = new HealthCheckInfo();
+        hc.group = "camel";
+        hc.name = name;
+        hc.state = "UP";
+        hc.readiness = true;
+        return hc;
+    }
+
+    private static String fKeyHints(MonitorTab tab) {
+        List<Span> spans = new ArrayList<>();
+        tab.renderFKeyHints(spans);
+        StringBuilder sb = new StringBuilder();
+        spans.forEach(s -> sb.append(s.content()));
+        return sb.toString();
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteAiPromptTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteAiPromptTest.java
new file mode 100644
index 000000000000..ca1e33d6e25f
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteAiPromptTest.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import dev.tamboui.text.Span;
+import dev.tamboui.tui.event.KeyCode;
+import dev.tamboui.tui.event.KeyEvent;
+import dev.tamboui.tui.event.KeyModifiers;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * CAMEL-25362: Shift+F8 on the Routes tab: fix with AI a route whose 
exchanges fail, explain with AI where the time of
+ * another goes.
+ */
+class RouteAiPromptTest {
+
+    private final List<String> asked = new ArrayList<>();
+    private final List<String> notified = new ArrayList<>();
+    private IntegrationInfo info;
+    private MonitorContext ctx;
+
+    @BeforeEach
+    void setUp() {
+        Theme.resetForTesting();
+        info = new IntegrationInfo();
+        info.pid = "1234";
+        info.name = "orders-app";
+        ctx = new MonitorContext(new AtomicReference<>(List.of(info)), new 
AtomicReference<>(List.of()));
+        ctx.selectedPid = "1234";
+        ctx.askAiCallback = new MonitorContext.AskAi() {
+            @Override
+            public void fixProblem(Path file, int line, String problem, String 
lineText) {
+                asked.add("fix: " + problem);
+            }
+
+            @Override
+            public void ask(String question) {
+                asked.add(question);
+            }
+        };
+        ctx.notificationCallback = (message, error) -> notified.add(message);
+    }
+
+    @Test
+    void theFailuresQuestionHasTheFailingStepsAndTheLastError() {
+        RouteInfo route = failingRoute();
+        info.routes.add(route);
+        ErrorInfo error = new ErrorInfo();
+        error.routeId = "orders";
+        error.nodeId = "to-payment";
+        error.timestamp = 5000;
+        error.exceptionType = 
"org.apache.camel.http.base.HttpOperationFailedException";
+        error.exceptionMessage = "HTTP operation failed with statusCode: 503";
+        error.repeatCount = 4;
+        info.errors = new ArrayList<>(List.of(error));
+
+        String question = RouteAiPrompt.ofFailures(info, route);
+
+        assertThat(question)
+                .startsWith("Exchanges fail in route orders of the running 
integration orders-app: 4 of 120 failed,"
+                            + " 2 failures handled by the error handler, 6 
redeliveries; the last failure 12s ago.\n")
+                .contains("It starts from timer://orders?period=500 and is at 
orders.camel.yaml:3.\n")
+                .contains("  to-payment (to) to http://localhost:8080/pay at 
orders.camel.yaml:9: 4 failed, 2 handled\n")
+                // a step without failures is not listed
+                .doesNotContain("log-order")
+                .contains("The last error of the route: 
HttpOperationFailedException: HTTP operation failed with"
+                          + " statusCode: 503 (4 times) (at to-payment, 
orders.camel.yaml:9)\n")
+                .endsWith("Dev mode reloads the file when it is saved.");
+    }
+
+    @Test
+    void thePerformanceQuestionHasTheSlowestStepsFirst() {
+        RouteInfo route = failingRoute();
+        route.failed = 0;
+        route.failuresHandled = 0;
+        route.p95Time = 900;
+        route.p99Time = 1500;
+
+        String question = RouteAiPrompt.ofPerformance(info, route);
+
+        assertThat(question)
+                .startsWith("Explain where the time goes in route orders of 
the running integration orders-app:"
+                            + " 120 exchanges, mean 450ms, max 2s, p95 900ms, 
p99 1s.\n")
+                .contains("The slowest steps by mean time (the time of an EIP 
includes the steps inside it):\n"
+                          + "  to-payment (to) to http://localhost:8080/pay at 
orders.camel.yaml:9: mean 400ms, max 2s,"
+                          + " 120 calls\n"
+                          + "  log-order (log) at orders.camel.yaml:7: mean 
1ms, max 3ms, 120 calls\n")
+                .endsWith("Make no changes to the files unless I agree.");
+    }
+
+    @Test
+    void shiftF8FixesAFailingRouteAndExplainsAQuietOne() {
+        info.routes.add(failingRoute());
+        RoutesTab tab = new RoutesTab(ctx);
+
+        assertThat(fKeyHints(tab)).contains("fix with AI");
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+        assertThat(asked).singleElement().asString().startsWith("Exchanges 
fail in route orders");
+
+        asked.clear();
+        info.routes.get(0).failed = 0;
+        info.routes.get(0).failuresHandled = 0;
+        assertThat(fKeyHints(tab)).contains("explain with AI");
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+        assertThat(asked).singleElement().asString().startsWith("Explain where 
the time goes in route orders");
+
+        asked.clear();
+        info.routes.get(0).total = 0;
+        assertThat(fKeyHints(tab)).isEmpty();
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+        assertThat(asked).isEmpty();
+        assertThat(notified).containsExactly("No exchanges in this route yet: 
ask the AI with F8");
+    }
+
+    private static RouteInfo failingRoute() {
+        RouteInfo route = new RouteInfo();
+        route.routeId = "orders";
+        route.from = "timer://orders?period=500";
+        route.source = "orders.camel.yaml:3";
+        route.state = "Started";
+        route.total = 120;
+        route.failed = 4;
+        route.failuresHandled = 2;
+        route.redeliveries = 6;
+        route.sinceLastFailed = "12s";
+        route.meanTime = 450;
+        route.maxTime = 2000;
+        ProcessorInfo log = new ProcessorInfo();
+        log.id = "log-order";
+        log.processor = "log";
+        log.source = "orders.camel.yaml:7";
+        log.total = 120;
+        log.meanTime = 1;
+        log.maxTime = 3;
+        ProcessorInfo pay = new ProcessorInfo();
+        pay.id = "to-payment";
+        pay.processor = "to";
+        pay.uri = "http://localhost:8080/pay";;
+        pay.source = "orders.camel.yaml:9";
+        pay.total = 120;
+        pay.failed = 4;
+        pay.failuresHandled = 2;
+        pay.meanTime = 400;
+        pay.maxTime = 2000;
+        route.processors.add(log);
+        route.processors.add(pay);
+        return route;
+    }
+
+    private static String fKeyHints(MonitorTab tab) {
+        List<Span> spans = new ArrayList<>();
+        tab.renderFKeyHints(spans);
+        StringBuilder sb = new StringBuilder();
+        spans.forEach(s -> sb.append(s.content()));
+        return sb.toString();
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SqlTraceAiPromptTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SqlTraceAiPromptTest.java
new file mode 100644
index 000000000000..902d51436c6f
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SqlTraceAiPromptTest.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import dev.tamboui.text.Span;
+import dev.tamboui.tui.event.KeyCode;
+import dev.tamboui.tui.event.KeyEvent;
+import dev.tamboui.tui.event.KeyModifiers;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * CAMEL-25362: Shift+F8 on the SQL Trace tab: fix with AI a statement that 
failed, explain with AI a slow one.
+ */
+class SqlTraceAiPromptTest {
+
+    private final List<String> asked = new ArrayList<>();
+    private final List<String> notified = new ArrayList<>();
+    private IntegrationInfo info;
+    private MonitorContext ctx;
+
+    @BeforeEach
+    void setUp() {
+        Theme.resetForTesting();
+        info = new IntegrationInfo();
+        info.pid = "1234";
+        info.name = "orders-app";
+        ctx = new MonitorContext(new AtomicReference<>(List.of(info)), new 
AtomicReference<>(List.of()));
+        ctx.selectedPid = "1234";
+        ctx.askAiCallback = new MonitorContext.AskAi() {
+            @Override
+            public void fixProblem(Path file, int line, String problem, String 
lineText) {
+                asked.add("fix: " + problem);
+            }
+
+            @Override
+            public void ask(String question) {
+                asked.add(question);
+            }
+        };
+        ctx.notificationCallback = (message, error) -> notified.add(message);
+    }
+
+    @Test
+    void aFailedStatementIsAskedWithTheErrorOfItsExchange() {
+        SqlTraceInfo si = statement("INSERT INTO ordrs (id) VALUES (:#id)", 3, 
true);
+        si.exchangeId = "EX-2";
+        si.endpoint = "sql:INSERT INTO ordrs (id) VALUES 
(:#id)?dataSource=#ds&password=secret";
+        ErrorInfo other = error("EX-1", "java.lang.IllegalStateException", 
"other");
+        other.timestamp = 9000;
+        ErrorInfo mine = error("EX-2", 
"org.h2.jdbc.JdbcSQLSyntaxErrorException", "Table \"ORDRS\" not found");
+        info.errors = new ArrayList<>(List.of(other, mine));
+
+        String question = SqlTraceAiPrompt.of(info, si);
+
+        assertThat(question)
+                .startsWith("A SQL statement failed in the running integration 
orders-app.\n"
+                            + "The statement (INSERT):\n```sql\nINSERT INTO 
ordrs (id) VALUES (:#id)\n```\n")
+                // the endpoint is masked before it goes to the AI
+                .contains("password=xxxxxx").doesNotContain("secret")
+                .contains("It ran in route orders at step insert-order, 
orders.camel.yaml:12.\n")
+                .contains("The error: JdbcSQLSyntaxErrorException: Table 
\"ORDRS\" not found\n")
+                .endsWith("say what to change there, and make no changes to 
the files.");
+    }
+
+    @Test
+    void aSlowStatementIsAskedWithHowOftenTheSameSqlRan() {
+        SqlTraceInfo slow = statement("SELECT * FROM orders WHERE status = 
'NEW'", 450, false);
+        slow.rowCount = 5000;
+        info.sqlTraceStatements.add(slow);
+        info.sqlTraceStatements.add(statement("SELECT * FROM orders WHERE 
status = 'NEW'", 150, false));
+        info.sqlTraceStatements.add(statement("SELECT 1", 1, false));
+
+        String question = SqlTraceAiPrompt.of(info, slow);
+
+        assertThat(question)
+                .startsWith("A SQL statement is slow in the running 
integration orders-app: it took 450 ms.\n")
+                .contains("The same SQL ran 2 times among the traced 
statements: mean 300 ms, slowest 450 ms.\n")
+                .contains("It returned 5000 rows.\n")
+                .contains("tui_execute_sql")
+                .endsWith("Make no changes to the files unless I agree.");
+    }
+
+    @Test
+    void shiftF8OnlyOnAStatementThatFailedOrWasSlow() {
+        SqlTraceInfo fast = statement("SELECT 1", 1, false);
+        fast.timestamp = 2000;
+        SqlTraceInfo failed = statement("SELECT * FROM nope", 2, true);
+        failed.timestamp = 1000;
+        info.sqlTraceStatements.add(fast);
+        info.sqlTraceStatements.add(failed);
+        SqlTraceTab tab = new SqlTraceTab(ctx);
+        tab.onTabSelected();
+        SqlTraceInfo first = tab.selectedStatement(info);
+        int fastRow = first == fast ? 0 : 1;
+
+        tab.tableState.select(fastRow);
+        assertThat(fKeyHints(tab)).isEmpty();
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+        assertThat(asked).isEmpty();
+        assertThat(notified).singleElement().asString().startsWith("This 
statement did not fail");
+
+        tab.tableState.select(1 - fastRow);
+        assertThat(fKeyHints(tab)).contains("fix with AI");
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.F8, KeyModifiers.SHIFT));
+        assertThat(asked).singleElement().asString().startsWith("A SQL 
statement failed");
+    }
+
+    private static SqlTraceInfo statement(String sql, long duration, boolean 
failed) {
+        SqlTraceInfo si = new SqlTraceInfo();
+        si.query = sql;
+        si.category = sql.substring(0, sql.indexOf(' '));
+        si.routeId = "orders";
+        si.nodeId = "insert-order";
+        si.location = "orders.camel.yaml:12";
+        si.duration = duration;
+        si.failed = failed;
+        return si;
+    }
+
+    private static ErrorInfo error(String exchangeId, String type, String 
message) {
+        ErrorInfo e = new ErrorInfo();
+        e.exchangeId = exchangeId;
+        e.routeId = "orders";
+        e.exceptionType = type;
+        e.exceptionMessage = message;
+        return e;
+    }
+
+    private static String fKeyHints(MonitorTab tab) {
+        List<Span> spans = new ArrayList<>();
+        tab.renderFKeyHints(spans);
+        StringBuilder sb = new StringBuilder();
+        spans.forEach(s -> sb.append(s.content()));
+        return sb.toString();
+    }
+}

Reply via email to