davsclaus commented on code in PR #26558:
URL: https://github.com/apache/camel/pull/26558#discussion_r4039596403


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java:
##########
@@ -380,14 +440,209 @@ public static JsonObject readFile(Path dir, String file) 
{
         return result;
     }
 
-    /** A plain file name inside the directory; anything else (a path, a 
parent reference) is refused. */
-    static Path resolveFile(Path dir, String file) {
+    /**
+     * Where each route of a running integration comes from, mapped onto the 
files of the project directory. The status
+     * document's {@code routes[].source} names what the runtime loaded: a jar 
entry for an exported project
+     * ({@code 
nested:.../target/app.jar/!BOOT-INF/classes/!/camel/foo.camel.yaml:4}), a 
{@code classpath:} or
+     * {@code file:} resource, or a Java class; the answer is the path a model 
can read and edit
+     * ({@code src/main/resources/camel/foo.camel.yaml}) with the line, or the 
location as given with {@code missing}
+     * when no such file exists under the directory.
+     *
+     * @param routes the status document's routes (maps with {@code routeId} 
and {@code source}), may be null
+     */
+    public static JsonArray routeSources(Collection<?> routes, Path dir) {
+        JsonArray out = new JsonArray();
+        if (routes == null) {
+            return out;
+        }
+        for (Object o : routes) {
+            if (!(o instanceof Map<?, ?> r) || !(r.get("source") instanceof 
String source) || source.isBlank()) {
+                continue;
+            }
+            SourceLocation loc = sourceLocation(source, dir);
+            JsonObject e = new JsonObject();
+            if (r.get("routeId") != null) {
+                e.put("routeId", String.valueOf(r.get("routeId")));
+            }
+            e.put("file", loc.file());
+            if (loc.line() > 0) {
+                e.put("line", loc.line());
+            }
+            if (!loc.exists()) {
+                e.put("missing", true);
+            }
+            out.add(e);
+        }
+        return out;
+    }
+
+    record SourceLocation(String file, int line, boolean exists) {
+    }
+
+    /** Maps one route source location onto a file under the directory; see 
{@link #routeSources}. */
+    static SourceLocation sourceLocation(String source, Path dir) {
+        String s = source.trim();
+        int line = 0;
+        int colon = s.lastIndexOf(':');
+        if (colon > 0 && colon < s.length() - 1 && s.substring(colon + 
1).chars().allMatch(Character::isDigit)) {
+            line = Integer.parseInt(s.substring(colon + 1));

Review Comment:
   Fixed in 0cc94e73cc3c. Rather than a length bound, `sourceLocation` now 
parses the digit suffix inside a `try` and on `NumberFormatException` leaves 
the location untouched (no `line`, the suffix stays part of the path), so a 
`:2147483648` source is reported as a missing file instead of failing the tool 
call. Covered by an extra case in 
`routeSourcesMapTheRuntimesLocationsOntoProjectFiles`.
   
   _Claude Code on behalf of davsclaus_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to