davsclaus commented on code in PR #185:
URL: https://github.com/apache/camel-kit/pull/185#discussion_r4604831100


##########
kit/camel-jbang-plugin-kit/pom.xml:
##########
@@ -13,8 +13,8 @@
     <description>JBang plugin for Camel Kit - Design Apache Camel Integrations 
with AI</description>
 
     <properties>
-        <maven.compiler.source>17</maven.compiler.source>
-        <maven.compiler.target>17</maven.compiler.target>
+        <!-- The Aesh-based Camel host requires Java 21; standalone Kit stays 
on Java 17. -->
+        <maven.compiler.release>21</maven.compiler.release>

Review Comment:
   **Blocking:** Kit targets Java 21+ (and Camel 4.24+), so instead of a 
plugin-only override, please raise the Kit baseline to 21 (`jdk.version` in the 
root `pom.xml` is still `17`). As is, `snapshot.yml` (nightly on `main`) and 
`release.yml` still run JDK 17 and build `-f kit/pom.xml`, which includes this 
module, so they would fail with `release version 21 not supported`. See the 
review body for the related `build.yml`/docs cleanups.



##########
.github/workflows/build.yml:
##########
@@ -69,10 +75,34 @@ jobs:
             **/target/failsafe-reports/*.xml
           retention-days: 7
 
+  cli-compatibility:
+    name: CLI compatibility (${{ matrix.os }}, Java ${{ matrix.java }})
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [macos-latest, windows-latest]
+        java: [17, 21, 25]
+    steps:
+      - uses: actions/[email protected]
+      - uses: actions/[email protected]
+        with:
+          java-version: ${{ matrix.java }}
+          distribution: temurin
+          cache: maven
+      - name: Verify token binding, host discovery, redirected output and 
generated command prefixes
+        shell: bash
+        run: |
+          if [ "${{ matrix.java }}" = "17" ]; then
+            ./mvnw -B -pl kit/camel-kit-main -am test 
-Dtest=AeshCliCompatibilityTest,ArgumentFilesTest,CamelKitMainShipTest 
-Dsurefire.failIfNoSpecifiedTests=false
+          else
+            ./mvnw -B -pl kit/camel-jbang-plugin-kit -am test 
"-Dtest=AeshCliCompatibilityTest,ArgumentFilesTest,CamelKitMainShipTest,CamelKitPluginTest,CamelKitCommandParityTest#nativeInitAndRegenerationDetectThePrefixInSeparateProcesses+pluginRegistersStandaloneCommandSurface+bob2InitAndRegenerationExposeTheSamePublicSkills+pluginForwardsWithCitrusMcpOption,HostedCliCompatibilityTest"
 -Dsurefire.failIfNoSpecifiedTests=false

Review Comment:
   **Non-blocking:** with `-Dsurefire.failIfNoSpecifiedTests=false`, renaming 
any listed method makes this lane silently run nothing for it and still pass. A 
JUnit tag (for example `@Tag("cli-compat")` + `-Dgroups=cli-compat`) would be 
more robust. With a Java 21 baseline, the Java 17 branch above also goes away.



##########
distribution.properties:
##########
@@ -10,6 +10,11 @@
 # Each platform has its own default Camel version because release schedules
 # differ. Quarkus typically lags behind the main Camel release.
 
+# CLI host only; generated integration runtime defaults remain independent.
+camel.cli.version=4.24.0-SNAPSHOT

Review Comment:
   **Non-blocking:** targeting 4.24 is the right direction. Please switch to 
`4.24.0` once it's released, before the first Kit release that includes this 
change. Until then `main` builds against a moving snapshot.



##########
kit/camel-jbang-plugin-kit/src/main/java/org/apache/camel/kit/jbang/KitInitCommand.java:
##########
@@ -1,114 +1,20 @@
 package org.apache.camel.kit.jbang;
 
-import java.nio.file.Path;
-import java.util.List;
-
-import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
 import org.apache.camel.kit.CamelKitMain;
 import org.apache.camel.kit.command.InitCommand;
 
-import picocli.CommandLine.Command;
-import picocli.CommandLine.Option;
-import picocli.CommandLine.Parameters;
-
-/**
- * Adapter command for `camel kit init` - delegates to camel-kit-core 
InitCommand
- */
-@Command(name = "init", description = "Initialize a new Camel-Kit project")
-public class KitInitCommand extends CamelCommand {
-
-    @Parameters(index = "0", description = "Project name", arity = "0..1")
-    String projectName;
-
-    @Option(names = {"-a", "--ai"},
-            description = "AI agent: bob2 (IBM Bob 2, default), antigravity, "
-                          + "claude, codex, copilot, pi, qwen, opencode",
-            defaultValue = "bob2")
-    String ai;
-
-    @Option(names = {"--here"}, description = "Initialize in current 
directory")
-    boolean here;
-
-    @Option(names = {"--citrus-version"},
-            description = "Citrus version for test schemas",
-            defaultValue = "default")
-    String citrusVersion;
-
-    @Option(names = {"--no-fetch"}, description = "Skip external catalog 
fetching")
-    boolean noFetch;
-
-    @Option(names = {"--force"},
-            description = "Reinitialize a project that already has 
.camel-kit/. Files you changed are preserved")
-    boolean force;
-
-    @Option(names = {"--dry-run"},
-            description = "Show what init would do to files the project may 
already own, without writing anything")
-    boolean dryRun;
-
-    @Option(names = {"--replace"}, paramLabel = "<path>",
-            description = "Replace this existing shared file (for example 
AGENTS.md or mvnw) instead of "
-                          + "preserving it (repeatable)")
-    List<String> replace;
-
-    @Option(names = {"--silent"}, description = "Suppress all output (no 
banner, no progress, no summary)")
-    boolean silent;
-
-    @Option(names = {"-c", "--config"},
-            description = "Path to config properties file (default: 
~/.camel-kit/config.properties)")
-    Path configFile;
-
-    @Option(names = {"-p", "--property"}, arity = "1..*",
-            description = "Override config property: -p key=value 
(repeatable)")
-    List<String> properties;
-
-    @Option(names = {"--with-citrus-mcp"},
-            description = "Include the Citrus MCP server in agent 
configuration (default: off)")
-    boolean withCitrusMcp;
-
-    @Option(names = {"--source-platform"},
-            description = "Source platform for migration graph analysis: 
mulesoft, camel, biztalk, auto (default: auto)")
-    String sourcePlatform;
-
-    @Option(names = {"--replace-wrapper"},
-            description = "Replace Maven wrapper even if it exists (default: 
preserve existing wrapper)")
-    boolean replaceWrapper;
-
-    @Option(names = {"--record-baseline"},
-            description = "Run existing project tests during init to record 
baseline (executes project build code; default: off)")
-    boolean recordBaseline;
-
-    private final CamelKitMain camelKitMain;
+import org.aesh.command.CommandDefinition;
 
+/** Uses the core option binding and initialization behavior inside the Camel 
host. */
+@CommandDefinition(name = "init", description = "Initialize a new Camel-Kit 
project", generateHelp = true)
+public class KitInitCommand extends InitCommand {
     public KitInitCommand(CamelJBangMain main) {

Review Comment:
   **Nit:** `main` is no longer used by either constructor.



##########
kit/camel-kit-core/src/main/java/org/apache/camel/kit/CommandRunner.java:
##########
@@ -0,0 +1,200 @@
+package org.apache.camel.kit;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.EnumSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.camel.kit.command.CliCommand;
+
+import org.aesh.command.AeshCommandRuntimeBuilder;
+import org.aesh.command.Command;
+import org.aesh.command.CommandRuntime;
+import org.aesh.command.HelpFeature;
+import org.aesh.command.container.CommandContainer;
+import org.aesh.command.impl.container.AeshCommandContainer;
+import org.aesh.command.impl.container.AeshCommandContainerBuilder;
+import org.aesh.command.impl.parser.CommandLineParser;
+import org.aesh.command.impl.registry.AeshCommandRegistryBuilder;
+import org.aesh.command.impl.shell.StdoutShell;
+import org.aesh.command.invocation.CommandInvocation;
+import org.aesh.command.parser.CommandLineParserException;
+import org.aesh.command.parser.RequiredOptionException;
+import org.aesh.command.validator.CommandValidatorException;
+import org.aesh.command.validator.OptionValidatorException;
+
+/** One-shot argv execution. The runtime owns no interactive terminal. */
+public final class CommandRunner {
+    private final Command<CommandInvocation> command;
+    private final Map<String, CommandRunner> children = new LinkedHashMap<>();
+    private PrintWriter out = new PrintWriter(System.out, true, 
java.nio.charset.Charset.defaultCharset());
+    private PrintWriter err = new PrintWriter(System.err, true, 
java.nio.charset.Charset.defaultCharset());
+    private boolean argumentFiles;
+    private CommandLineParser<CommandInvocation> parser;
+    private CommandContainer<CommandInvocation> container;
+
+    public CommandRunner(Command<CommandInvocation> command) {
+        this.command = command;
+    }
+
+    public CommandRunner addSubcommand(String name, Command<CommandInvocation> 
child) {
+        return addSubcommand(name, new CommandRunner(child));
+    }
+
+    public CommandRunner addSubcommand(String name, CommandRunner child) {
+        children.put(name, child);
+        container = null;
+        parser = null;
+        return this;
+    }
+
+    public CommandRunner argumentFiles(boolean enabled) {
+        argumentFiles = enabled;
+        return this;
+    }
+
+    public CommandRunner setOut(PrintWriter out) {
+        this.out = out;
+        return this;
+    }
+
+    public CommandRunner setErr(PrintWriter err) {
+        this.err = err;
+        return this;
+    }
+
+    public CommandLineParser<CommandInvocation> parser() {
+        if (parser == null) {
+            container();
+        }
+        return parser;
+    }
+
+    private CommandContainer<CommandInvocation> container() {
+        if (container != null) {
+            configure(parser, out, err);
+            return container;
+        }
+        try {
+            var builder = new AeshCommandContainerBuilder<CommandInvocation>();
+            
builder.setHelpDefaults(EnumSet.of(HelpFeature.FAIL_ON_DUPLICATE_OPTIONS));
+            container = builder.create(command);
+            for (var entry : children.entrySet()) {
+                var child = entry.getValue().container();
+                
child.getParser().getProcessedCommand().setName(entry.getKey());
+                ((AeshCommandContainer<CommandInvocation>) 
container).addChild(child);
+            }
+            parser = container.getParser();
+            parser.updateAnsiMode(false);
+            configure(parser, out, err);
+            return container;
+        } catch (CommandLineParserException e) {
+            throw new IllegalStateException("Invalid command definition", e);
+        }
+    }
+
+    private static void configure(
+            CommandLineParser<CommandInvocation> parser,
+            PrintWriter out, PrintWriter err) {
+        if (parser.getCommand() instanceof CliCommand cli) {
+            cli.configureOutput(out, err);
+        }
+        for (var child : parser.getAllChildParsers()) {
+            configure(child, out, err);
+        }
+    }
+
+    private CommandRuntime<CommandInvocation> runtime() {
+        var registry = 
AeshCommandRegistryBuilder.<CommandInvocation>builder().command(container()).create();
+        return AeshCommandRuntimeBuilder.<CommandInvocation>builder()
+                
.commandRegistry(registry).argumentFiles(false).ansiColors(false)
+                .shell(new StdoutShell() {
+                    @Override
+                    public void write(String value, boolean paging) {
+                        out.print(value);
+                        out.flush();
+                    }
+
+                    @Override
+                    public void writeln(String value, boolean paging) {
+                        out.println(value);
+                        out.flush();
+                    }
+                }).build();
+    }
+
+    public void parse(String... args) throws Exception {
+        var runtime = runtime();
+        try {
+            for (var execution : 
runtime.buildExecutor(parser.getProcessedCommand().name(), expand(args))
+                    .getExecutions()) {
+                execution.populateCommand();
+            }
+        } finally {
+            runtime.close();
+        }
+    }
+
+    public int execute(String... args) {
+        var runtime = runtime();
+        try {
+            var executions = 
runtime.buildExecutor(parser.getProcessedCommand().name(), 
expand(args)).getExecutions();
+            var execution = executions.get(0);
+            try {
+                execution.populateCommand();
+            } catch (CommandLineParserException e) {
+                if (!rootInformationRequested() || 
!onlyInformationalErrors(parser)) {
+                    throw e;
+                }
+            }
+            if (rootInformationRequested()) {
+                if (optionGiven("help")) {
+                    out.print(parser.printHelp());
+                } else {
+                    for (String version : new VersionProvider().getVersion()) {
+                        out.println(version);
+                    }
+                }
+                return 0;
+            }
+            return execution.execute().getResultValue();
+        } catch (IOException | CommandLineParserException | 
OptionValidatorException | CommandValidatorException e) {
+            err.println(e.getMessage());
+            return 2;
+        } catch (Exception e) {
+            e.printStackTrace(err);
+            return 1;
+        } finally {
+            runtime.close();
+            out.flush();
+            err.flush();
+        }
+    }
+
+    private String[] expand(String[] args) throws IOException {
+        return argumentFiles ? ArgumentFiles.expand(args) : args;
+    }
+
+    private boolean rootInformationRequested() {
+        return command instanceof CamelKitMain && (optionGiven("help") || 
optionGiven("version"));
+    }
+
+    private boolean optionGiven(String name) {
+        return 
!parser.getProcessedCommand().findLongOptionNoActivatorCheck(name).getValues().isEmpty();
+    }
+
+    // Root information flags excuse unknown tokens and omitted required 
arguments, but never malformed options.
+    private static boolean onlyInformationalErrors(CommandLineParser<?> 
parser) {
+        for (var error : parser.getProcessedCommand().parserExceptions()) {
+            if (!(error instanceof RequiredOptionException)
+                    && !(error.getMessage().startsWith("The option ") && 
error.getMessage().contains(" is unknown."))
+                    && !error.getMessage().startsWith("Unknown argument ")
+                    && !error.getMessage().startsWith("Unexpected argument ")) 
{
+                return false;
+            }
+        }
+        return parser.getAllChildParsers().stream().filter(child -> 
child.parsedCommand() != null)
+                .allMatch(CommandRunner::onlyInformationalErrors);

Review Comment:
   **Non-blocking:** this classifies parser errors by Aesh's English message 
text. If an Aesh upgrade rewords one, `--version --invalid` quietly changes 
from exit 0 to exit 2. Matching on exception types, where Aesh provides them, 
would be sturdier.



##########
docs/modules/ROOT/pages/ship.adoc:
##########
@@ -54,6 +54,17 @@ camel-kit ship --submit RUN_ID --result PATH [--json]
 Context is optional: a bare `camel-kit ship` starts a short discovery 
conversation. Text and documents are added to
 the discovery input before any question, and open points come back as grouped 
unresolved questions.
 
+[[literal-context]]
+=== Literal context and argument files
+
+Text and document occurrences keep their original order, including mixed 
repeated options.
+Standalone `camel-kit ship --text '@note'` passes `@note` literally and never 
expands argument files.
+With the Aesh-based development plugin, the Camel host expands `@file` before 
Kit runs. Write

Review Comment:
   **Discussion:** the host runs Aesh's `ArgfileExpander`, which *fails* when 
the file doesn't exist (`Argument file not found`). So `camel kit ship --text 
"@team please check"` is now a usage error, not literal text. Please document 
that. Could a small hook in Camel's plugin SPI (letting a plugin exempt `kit 
ship` from argument-file expansion) preserve the contract from #171 instead, 
while `CommandTree` is still unreleased?



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