This is an automated email from the ASF dual-hosted git repository. luigidemasi pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-kit.git
commit f48590b275792a60af2447d0e575b18af4e4c4f4 Author: Luigi De Masi <[email protected]> AuthorDate: Mon Nov 23 16:17:50 2026 +0100 Fix #193: Validate workspace configuration before upgrading catalog files Read released properties files with the same byte-stream semantics as init. Reject malformed properties and legacy YAML during preview and initialization before writing the first-adoption marker. A repaired workspace can then resume its release upgrade. Doctor reports invalid properties and explains how to recover a missing configuration. Document recovery after first adoption and the manual check for edited skills retired after 0.3.x. Co-authored-by: OpenAI Codex <[email protected]> --- CHANGELOG.md | 3 +- docs/modules/ROOT/pages/agents.adoc | 1 + docs/modules/ROOT/pages/getting-started.adoc | 16 ++++++ docs/security-model.md | 3 +- docs/security-model.yaml | 2 +- .../apache/camel/kit/generator/ManagedFiles.java | 15 +++--- .../camel/kit/generator/ReleasedCatalog.java | 46 ++++++++--------- .../apache/camel/kit/service/DoctorService.java | 9 ++-- .../camel/kit/command/DoctorCommandTest.java | 12 +++++ .../camel/kit/service/InitSafeAdoptionTest.java | 60 +++++++++++++++++++++- 10 files changed, 127 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 689c6d24..40c9ac77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Upgrades from pre-ledger releases refresh stock assets and remove stock retired commands for each assistant in a shared workspace. Preview changed paths with `--dry-run`, compare `.proposed` copies under `.camel-kit/conflicts/catalog/`, and accept files or catalog directories with `--replace <path>`. Doctor - identifies retired entry points and accepts personal skills that reuse a historical name. + identifies retired entry points and accepts personal skills that reuse a historical name. Init preserves Latin-1 + configuration properties and reports malformed properties or legacy YAML before recording ownership or writing files. - Align Main environment probes, recovery guidance, direct migration and generated `AGENTS.md` with the JBang alias and the project's Camel version, matching generated `run.sh` (#110). Report incompatible local JBang plugins as environment failures. Correct the environment probe's YAML step nesting so its sample route can start. diff --git a/docs/modules/ROOT/pages/agents.adoc b/docs/modules/ROOT/pages/agents.adoc index 12e59c70..ba1409d7 100644 --- a/docs/modules/ROOT/pages/agents.adoc +++ b/docs/modules/ROOT/pages/agents.adoc @@ -63,6 +63,7 @@ camel-kit init --here --ai claude --force ---- Run with `--dry-run` first to see which skills and commands will change. +For recovery after losing the project configuration, see xref:getting-started.adoc#_upgrading_from_0_4_1_and_earlier[Upgrading from 0.4.1 and earlier]. * From 0.4.0 or 0.4.1, the command above updates stock skills and removes the nine stock command stubs. Kit removes `.claude/commands/` if deleting the last stock stub leaves it empty. diff --git a/docs/modules/ROOT/pages/getting-started.adoc b/docs/modules/ROOT/pages/getting-started.adoc index 3237e381..df4e18bd 100644 --- a/docs/modules/ROOT/pages/getting-started.adoc +++ b/docs/modules/ROOT/pages/getting-started.adoc @@ -265,6 +265,11 @@ the project. ==== Upgrading from 0.4.1 and earlier +If the workspace has lost its Kit configuration, restore the original from version control or a backup *before* +the first upgrade. Releases 0.4.x used `.camel-kit/config.properties`. Earlier releases used `.camel-kit/config.yaml`. +When both files exist, Kit reads the properties file. If the active file is malformed, both `--dry-run` and `init` +report the path before writing anything. Repair or restore that file and retry. + From the project root, run `camel-kit init --here --ai claude --force`, substituting your assistant's name. In a shared workspace, run this command once for each assistant, in any order. Kit recognizes stock catalog files from pre-ledger releases by their installed path and content for the selected assistant. @@ -274,6 +279,17 @@ init to check the assistant you just updated. When adopting a project for the first time, Kit records that ownership tracking began with this init. Copies from older releases that differ from the new rendering stay in place on this and later runs. +If you already ran `init` while the configuration was missing, restoring it afterward keeps the first-adoption +record in effect. Review the `.proposed` files under `.camel-kit/conflicts/catalog/`, then rerun `init` with +`--force --replace <path>` for the changes you accept. For Claude, `--replace .claude/skills` accepts all selected +skills and guides in that directory, including locally edited ones. Review any retired stubs Doctor lists under +`.claude/commands/` and move the ones you want to retire outside the assistant's discovery directories. + +When upgrading from 0.3.x, also inspect any `camel-flow`, `camel-project`, and `camel-migrate-mule` folders left +in your assistant's skills directory. Doctor treats an edited `SKILL.md` without an ownership record as personal. +The assistant can still discover it after Kit removes its stock guides. Keep the folder if you use it, or move it +outside the skills directory to retire it. + ==== Reviewing catalog changes * For each selected skill, guide, binary resource or command stub, `init` creates a missing file and refreshes a diff --git a/docs/security-model.md b/docs/security-model.md index 4a8a0b78..a9035ec6 100644 --- a/docs/security-model.md +++ b/docs/security-model.md @@ -563,7 +563,8 @@ violation warrants coordinated disclosure and a CVE; **hardening** means it is f the previous installation's SHA-256 records only for valid resource or stub paths under the selected agent's generated directories. A ledger record takes precedence. For a missing record, Kit can recognize the selected assistant's stock file by path and a bundled release fingerprint in a pre-ledger Kit workspace. In a - shared skills directory this includes fingerprints from assistants that install to the same path. First-time + shared skills directory this includes fingerprints from assistants that install to the same path. Init validates + the active workspace configuration before writing the ledger. First-time adoption records its origin in the ledger before writing the config, so retries preserve pre-existing copies. An unrecorded skill with different content can reuse a historical name. Review ledger changes alongside the files they track. Kit checks confinement and compares installed content before refresh or removal. diff --git a/docs/security-model.yaml b/docs/security-model.yaml index 640e7fc3..38b11f42 100644 --- a/docs/security-model.yaml +++ b/docs/security-model.yaml @@ -299,7 +299,7 @@ claimed_properties: property: init confines its writes to the operator-selected target directory and removes only what it generated, through no symlink. An untrusted tree or a symbolic link that redirects a write outside the target is in scope; an intentionally operator-selected destination is authorized. violation_symptom: File created, replaced or deleted outside the operator-selected target, or a write or deletion redirected through a symbolic link. severity: security-critical when reachable from an attacker-controllable input (analysed tree, registry data); otherwise correctness - provenance: "Contract: maintainer (2026-10-27, Q9). InitService/ConfinedPaths preflight generated leaves/ancestors and Camel-owned skill/shared/template subtrees; unrelated worktrees and data links are allowed; new atomic files use umask-default modes and replacements preserve existing POSIX modes; GeneratedAssetCleaner guards legacy deletion; catalog updates use the committed ownership ledger or, for a missing catalog record, known release fingerprints at the installed path in a pre [...] + provenance: "Contract: maintainer (2026-10-27, Q9). InitService/ConfinedPaths preflight generated leaves/ancestors and Camel-owned skill/shared/template subtrees; unrelated worktrees and data links are allowed; new atomic files use umask-default modes and replacements preserve existing POSIX modes; GeneratedAssetCleaner guards legacy deletion; catalog updates use the committed ownership ledger or, for a missing catalog record, known release fingerprints at the installed path in a pre [...] - id: P4 property: Pinned, named-repository supply chain for everything fetched or configured; Ship resolver uses fixed HTTPS Maven Central, checksum fail, no redirects, exact coordinates, size caps, SHA-256 content identity, isolated URLClassLoader payloads. Kit's own handling of what it downloads is in scope - catalog JSON is read from the JAR stream in memory, Citrus schema entries are written only inside the cache directory after lexical containment and descendant-link checks; Catalog/Cit [...] violation_symptom: Unpinned coordinate, repository outside the named lists, download accepted on checksum mismatch (Ship), artifact outside its exact path, payload class loaded from elsewhere, or a downloaded artifact that escapes the cache directory or executes code through Kit's parsing or extraction. diff --git a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ManagedFiles.java b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ManagedFiles.java index 7b094c77..301adca2 100644 --- a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ManagedFiles.java +++ b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ManagedFiles.java @@ -198,15 +198,12 @@ public final class ManagedFiles { } catch (IOException | IllegalArgumentException e) { throw new InvalidAgentConfigurationException("Cannot read " + ledgerFile + ": " + e.getMessage(), e); } - Map<String, Set<String>> released = Map.of(); - boolean startsTracking = false; - if (agentName != null && !Boolean.parseBoolean(ledger.getProperty(TRACKED_FROM_INIT))) { - if (ReleasedCatalog.hasWorkspaceConfiguration(root)) { - released = ReleasedCatalog.forAgent(agentName); - } else { - startsTracking = true; - } - } + // Validate the configuration before any writes, even when the ledger already records first adoption. + boolean configured = agentName != null && ReleasedCatalog.hasWorkspaceConfiguration(root); + boolean trackedFromInit = Boolean.parseBoolean(ledger.getProperty(TRACKED_FROM_INIT)); + Map<String, Set<String>> released + = configured && !trackedFromInit ? ReleasedCatalog.forAgent(agentName) : Map.of(); + boolean startsTracking = agentName != null && !configured && !trackedFromInit; return new ManagedFiles(root, false, replacements, ledger, released, startsTracking); } diff --git a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ReleasedCatalog.java b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ReleasedCatalog.java index 0284c66a..4249b6e0 100644 --- a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ReleasedCatalog.java +++ b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ReleasedCatalog.java @@ -18,7 +18,7 @@ import java.util.stream.Collectors; import org.apache.camel.kit.config.AgentRegistry; import org.apache.camel.kit.util.ConfinedPaths; -import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; @@ -28,32 +28,32 @@ final class ReleasedCatalog { } static boolean hasWorkspaceConfiguration(Path root) throws IOException { - Path config = root.resolve(".camel-kit/config.properties"); - ConfinedPaths.requirePath(root, config); - String configuredAgent; - if (Files.isRegularFile(config, LinkOption.NOFOLLOW_LINKS)) { - var settings = new Properties(); - try (var in = Files.newBufferedReader(config)) { - settings.load(in); - } catch (IllegalArgumentException malformed) { + Path properties = root.resolve(".camel-kit/config.properties"); + Path config = Files.notExists(properties, LinkOption.NOFOLLOW_LINKS) + ? properties.resolveSibling("config.yaml") + : properties; + try { + ConfinedPaths.requirePath(root, config); + if (Files.notExists(config, LinkOption.NOFOLLOW_LINKS)) { return false; } - configuredAgent = settings.getProperty("agent.name"); - } else { - Path yaml = root.resolve(".camel-kit/config.yaml"); - if (!Files.isRegularFile(yaml, LinkOption.NOFOLLOW_LINKS)) { - return false; - } - ConfinedPaths.requirePath(root, yaml); - try (var in = Files.newInputStream(yaml)) { - var settings = new ObjectMapper(new YAMLFactory()).readTree(in); - configuredAgent = settings == null ? null : settings.path("agent").path("name").textValue(); - } catch (JsonProcessingException malformed) { - return false; + try (var in = Files.newInputStream(config)) { + String configuredAgent; + if (config.equals(properties)) { + var settings = new Properties(); + settings.load(in); + configuredAgent = settings.getProperty("agent.name"); + } else { + var settings = new ObjectMapper(new YAMLFactory()) + .enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS).readTree(in); + configuredAgent = settings == null ? null : settings.path("agent").path("name").textValue(); + } + // A shared workspace records only the last assistant initialized. + return configuredAgent != null && !configuredAgent.isBlank(); } + } catch (IOException | IllegalArgumentException e) { + throw new InvalidAgentConfigurationException("Cannot read " + config + ": " + e.getMessage(), e); } - // A shared workspace records only the last assistant initialized. - return configuredAgent != null && !configuredAgent.isBlank(); } static Map<String, Set<String>> forAgent(String agentName) throws IOException { diff --git a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/DoctorService.java b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/DoctorService.java index fe615545..ede9ab2b 100644 --- a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/DoctorService.java +++ b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/DoctorService.java @@ -90,18 +90,19 @@ public class DoctorService { if (!Files.isRegularFile(configFile)) { findings.add(DoctorFinding.fail("config", relativize(root, configFile), ".camel-kit/config.properties is missing", - "Run camel-kit init --here --ai <agent> from the workspace root.")); + "Restore any lost Kit configuration before upgrading an existing workspace. " + + "Run camel-kit init --here --ai <agent> from the workspace root.")); return new Properties(); } Properties config = new Properties(); try (InputStream in = Files.newInputStream(configFile)) { config.load(in); - } catch (IOException e) { + } catch (IOException | IllegalArgumentException e) { findings.add(DoctorFinding.fail("config", relativize(root, configFile), "Could not read .camel-kit/config.properties: " + e.getMessage(), - "Recreate the file with camel-kit init --here --force or restore it from source control.")); - return config; + "Repair the file or restore it from source control before running init.")); + return new Properties(); } List<String> missing = REQUIRED_CONFIG_KEYS.stream() diff --git a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/DoctorCommandTest.java b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/DoctorCommandTest.java index 22d1f984..871d57f7 100644 --- a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/DoctorCommandTest.java +++ b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/DoctorCommandTest.java @@ -86,9 +86,21 @@ class DoctorCommandTest { RunResult textResult = runDoctor("--project-dir", tempDir.toString()); assertNotEquals(0, textResult.exitCode()); assertTrue(textResult.output().contains(".camel-kit/config.properties is missing")); + assertTrue(textResult.output().contains("Restore any lost Kit configuration before upgrading")); assertTrue(textResult.output().contains("Run camel-kit init --here --ai <agent>")); } + @Test + void malformedPropertiesProduceAnActionableJsonFinding() throws Exception { + writeConfig("agent.name=bob2\nextra=\\u12x4\n"); + RunResult result = runDoctor("--project-dir", tempDir.toString(), "--json"); + + assertEquals(1, result.exitCode()); + JsonNode json = MAPPER.readTree(result.output()); + assertTrue(hasFinding(json, "FAIL", "config", "Could not read .camel-kit/config.properties", + "restore it from source control"), result.output()); + } + @Test void missingAgentNameInConfigProducesSpecificFailure() throws Exception { writeConfig(""" diff --git a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/service/InitSafeAdoptionTest.java b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/service/InitSafeAdoptionTest.java index 20aeae85..ebb9c6d3 100644 --- a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/service/InitSafeAdoptionTest.java +++ b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/service/InitSafeAdoptionTest.java @@ -1,5 +1,6 @@ package org.apache.camel.kit.service; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -24,6 +25,7 @@ import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; @@ -191,7 +193,63 @@ class InitSafeAdoptionTest { } @Test - void adoptingAnExistingProjectPreservesCopiesOfReleasedFilesAcrossRetries() throws Exception { + @Tag("cli-compat") + void releasedWorkspaceUpgradesWithLatin1Properties() throws Exception { + Path config = Files.createDirectories(tempDir.resolve(".camel-kit")).resolve("config.properties"); + Files.writeString(config, "agent.name=claude\nteam.owner=André\n", StandardCharsets.ISO_8859_1); + Files.writeString(config.resolveSibling("config.yaml"), "old: ["); + Path stub = writeReleasedClaudeStub(tempDir); + var init = request(tempDir, "claude"); + var service = new InitService(); + + assertTrue(service.preview(init).stream().anyMatch(c -> c.action() == Action.REMOVE + && c.path().equals(".claude/commands/camel-validate.md"))); + service.initialize(init); + assertFalse(Files.exists(stub)); + var settings = new Properties(); + try (var in = Files.newInputStream(config)) { + settings.load(in); + } + assertEquals("André", settings.getProperty("team.owner")); + } + + @ParameterizedTest + @CsvSource({"config.properties, false", "config.yaml, false", "config.properties, true", "config.yaml, true"}) + @Tag("cli-compat") + void malformedConfigLeavesWorkspaceUntouchedAndRepairCanBeRetried(String filename, boolean trackedFromInit) + throws Exception { + Path config = Files.createDirectories(tempDir.resolve(".camel-kit")).resolve(filename); + boolean properties = filename.equals("config.properties"); + Files.writeString(config, + properties ? "agent.name=claude\nextra=\\u12x4\n" : "agent:\n name: claude\nextra: ["); + if (trackedFromInit) { + Files.writeString(tempDir.resolve(ManagedFiles.LEDGER), "catalog.tracked-from-init=true\n"); + } + Path stub = writeReleasedClaudeStub(tempDir); + var service = new InitService(); + var init = request(tempDir, "claude"); + var original = snapshot(tempDir); + var preview = assertThrows(InvalidAgentConfigurationException.class, () -> service.preview(init)); + assertTrue(preview.getMessage().contains(config.toString()), preview::getMessage); + assertEquals(original, snapshot(tempDir)); + var apply = assertThrows(InvalidAgentConfigurationException.class, () -> service.initialize(init)); + assertEquals(preview.getMessage(), apply.getMessage()); + assertEquals(original, snapshot(tempDir)); + + Files.writeString(config, properties ? "agent.name=claude\n" : "agent:\n name: claude\n"); + service.initialize(init); + assertEquals(trackedFromInit, Files.exists(stub)); + assertEquals(trackedFromInit, Boolean.parseBoolean(ledger(tempDir).getProperty("catalog.tracked-from-init"))); + } + + @ParameterizedTest + @NullAndEmptySource + @ValueSource(strings = "agent.name= \n") + void adoptingAnExistingProjectPreservesCopiesOfReleasedFilesAcrossRetries(String configuration) throws Exception { + if (configuration != null) { + Path config = Files.createDirectories(tempDir.resolve(".camel-kit")).resolve("config.properties"); + Files.writeString(config, configuration); + } String path = ".claude/skills/camel-implement/guides/run-script.md"; Path guide = tempDir.resolve(path); copyReleasedFixture(guide);
