Jinal-Sarvaiya commented on code in PR #149:
URL: https://github.com/apache/camel-kit/pull/149#discussion_r4513122734


##########
kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/OpenCodeGenerator.java:
##########
@@ -1,51 +1,360 @@
 package org.apache.camel.kit.generator;
 
+import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
 
+import org.apache.camel.kit.config.OpenCodeProjectConfig;
 import org.apache.camel.kit.util.AnsiColors;
 
+import com.fasterxml.jackson.databind.JsonNode;
+
 public class OpenCodeGenerator extends DefaultGenerator {
 
     private static final String[] AGENTS = {
             "brainstormer", "planner", "implementer",
             "validator", "tester", "migrator", "executor",
-            "researcher", "reviewer"
+            "researcher", "reviewer", "camel-ship-worker"
     };
 
+    private static final Set<String> BUILTIN_PERMISSION_PREFIXES = 
Set.of("external");
+
+    private static final Pattern SUBSTITUTION_PATTERN = 
Pattern.compile("\\{(env|file):[^}]+}");
+
+    private static final List<String> GLOBAL_CONFIG_FILES = 
List.of("opencode.json", "opencode.jsonc");
+
+    private static final List<String> ANCESTOR_CONFIG_FILES = List.of(
+            "opencode.json", "opencode.jsonc",
+            ".opencode/opencode.json", ".opencode/opencode.jsonc");
+
     private final QuteTemplateEngine templateEngine = new QuteTemplateEngine();
 
     @Override
     public void preflight(InitContext ctx) throws Exception {
-        new 
OpenCodeConfigMerger().validateExisting(ctx.projectDir().resolve(ctx.agent().mcpConfigPath()));
+        try {
+            new 
OpenCodeConfigMerger().validateExisting(ctx.projectDir().resolve(ctx.agent().mcpConfigPath()));
+        } catch (Exception e) {
+            // OpenCode substitutes {env:}/{file:} before parsing, so a 
project config that is invalid as raw
+            // JSON may still be valid for the host. Initialization aborts 
here, so remove the installed worker:
+            // its denial list can no longer be shown to match the effective 
MCP server set. Other validation
+            // failures (e.g. duplicate keys) keep the "fail before any 
project writes" contract.
+            if (projectConfigMayContainSubstitution(ctx)) {
+                
Files.deleteIfExists(ctx.projectDir().resolve(".opencode/agents/camel-ship-worker.md"));

Review Comment:
   Fixed- Before any delete in preflight() and generate(), the code now checks 
.opencode, .opencode/agents and .opencode/agents/camel-ship-worker.md for 
symlinks and aborts with the existing "Initialization aborted … symbolic link" 
error.



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