davsclaus opened a new pull request, #29882:
URL: https://github.com/apache/camel/pull/29882

   ## What
   
   CAMEL-26939, a sub-task of CAMEL-26935 (make the Camel CLI faster for AI 
agents).
   
   After an edit, an agent waited for the next scan of dev mode (every 2 
seconds, 1.1 s on average), and read the log to find out whether the reload 
worked. `camel cmd reload` did not help: it reloads the context, which rebuilds 
the routes from what was loaded, not from the files.
   
   `camel cmd reload <name> --wait` asks the integration to reload the files 
changed since the last scan now, and prints them, or why the reload failed 
(exit code 1). With `--json` the outcome is one document:
   
   ```
   $ camel cmd reload rl1 --wait --json
   {"pid":35136,"name":"rl1","status":"reloaded","files":["hello.camel.yaml"]}
   $ camel cmd reload rl1 --wait --json
   {"pid":35136,"name":"rl1","status":"unchanged","files":[]}
   $ camel cmd reload rl1 --wait --json        # after a typo in the route
   
{"pid":35136,"name":"rl1","status":"failed","files":["hello.camel.yaml"],"error":"Unknown
 node id: lgo\n in file:hello.camel.yaml, line 8, column 11:\n            - 
lgo:\n              ^\n"}
   ```
   
   The statuses are the ones of the reload outcome of the MCP write tools 
(`reloaded`, `failed`), and `unchanged`.
   
   - `camel-support`: `FileWatcherResourceReloadStrategy.reloadChanged()` scans 
and reloads the changed files on the calling thread, under the same lock as the 
scan of the watcher, so a file is reloaded once. A file still being written, 
such as the one just edited, is waited for (up to five times the stable 
timeout). `onReload`, which did nothing, does the same.
   - `camel-cli-connector`: the `reload` action with `"changed": true` reloads 
through the strategy that scans (`camel run --source-dir` also has a 
`RouteOnDemandReloadStrategy`, which only reloads on demand), and answers with 
the files and the error. Without dev mode the answer says that the integration 
does not watch its files.
   - `camel-jbang-core`: `camel cmd reload --wait [--json]` for one 
integration. An integration of Camel before 4.24 is told apart before anything 
is sent; `--json` without `--wait` is a usage error.
   
   The scan of dev mode stays at 2 seconds (CAMEL-25042: it groups the files of 
one save into one reload); `camel_run` of the MCP server keeps its 500 ms.
   
   `camel cmd reload` without `--wait` does as before, except on an integration 
whose only reload strategy is the file watcher (no context reload, such as 
Spring Boot with `camel.main.routesReloadEnabled`): there it now reloads the 
changed files, where it did nothing.
   
   ## Tried end to end
   
   The camel-launcher with the three jars of this PR, macOS, JDK 25, `camel run 
hello.camel.yaml --dev --background`, and the same with `--source-dir=.`:
   
   - an edit, then `camel cmd reload --wait --json`: `reloaded` in 0.67 s for 
the whole command (the CLI starting included), and the log has one reload, on 
the connector thread, and the new message right after;
   - again: `unchanged`;
   - a typo: `failed` with the line and column of the parser, exit code 1.
   
   Found on the way, also on main without this PR: after a failed reload, the 
reload of the fixed file fails with `duplicate route id detected hello`, and 
the old route keeps running until a restart. The route restored from the last 
good content is an in-memory resource whose URI is relative 
(`file:hello.camel.yaml`), and the file from disk has an absolute one, so the 
next reload does not see they are the same file and loads both. Not changed 
here; it is in `RouteWatcherReloadStrategy` and gets a JIRA of its own.
   
   ## Tests
   
   - `FileScanReloadTest` (camel-core): a reload asked for reloads the changed 
files at once, the properties first, and nothing when nothing changed; it waits 
for a file just written.
   - `LocalCliConnectorFileTransportTest`: the answer with the files, with the 
error of a failed reload, and without dev mode.
   - `CamelReloadActionTest`, moved to AssertJ: `--wait` sends `changed`, 
prints the files, the outcome as JSON, a failed reload is exit code 1 (one JSON 
document, or an `ERROR:`), an integration that cannot reload on demand, and 
`--json` without `--wait`.
   - The reload tests of camel-core, and the tests of `camel-cli-connector` and 
`camel-jbang-core` pass.
   
   _Claude Code on behalf of Claus Ibsen (davsclaus)_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_012nJsFsjqqFiwroeHRWaKbS
   


-- 
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