Jinal-Sarvaiya commented on code in PR #149:
URL: https://github.com/apache/camel-kit/pull/149#discussion_r4513117333
##########
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)) {
Review Comment:
Fixed in 768e437. I removed the substitution-only exemption. preflight() now
removes camel-ship-worker.md whenever project-config validation fails, whether
the cause is duplicate keys, a substitution or a parse error. The user's
configuration is left untouched and the original error is still thrown. New
test duplicateKeyConfigIntroducingNewServerInvalidatesShipWorkerOnReinit covers
a second mcp property that introduces probe, for opencode.json and
.opencode/opencode.json.
--
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]