The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(distribution): preserve profile skills on update
MKanso5029a382341b
diff --git a/hermes_cli/profile_distribution.py b/hermes_cli/profile_distribution.pyindex 2734d2a8221..eaf76cd73b4 100644--- a/hermes_cli/profile_distribution.py+++ b/hermes_cli/profile_distribution.py@@ -28,7 +28,7 @@ ENV_EXAMPLE_FILENAME = ".env.EXAMPLE"# Default distribution-owned paths (relative to profile root). Authors may override via# ``distribution_owned:``. config.yaml is dist-owned but preserved on update by default.-DEFAULT_DIST_OWNED: Tuple[str, ...] = ("SOUL.md", "config.yaml", "mcp.json", "skills", "cron", MANIFEST_FILENAME)+DEFAULT_DIST_OWNED: Tuple[str, ...] = ("SOUL.md", "config.yaml", "mcp.json", "cron", MANIFEST_FILENAME)# Paths NEVER part of a distribution: user-owned, protected on update. Keep consistent with# ``profiles.py`` export exclusions plus the ``local/`` convention for user customizations.@@ -356,12 +356,20 @@ def _owned_entries(staged: Path, manifest: DistributionManifest):yield src, rel_parts-def _copy_dist_payload(staged: Path, target: Path, manifest: DistributionManifest, preserve_config: bool) -> None:+def _copy_dist_payload(+ staged: Path,+ target: Path,+ manifest: DistributionManifest,+ preserve_config: bool,+ preserve_skills: bool = False,+) -> None:"""Copy distribution-owned files (see ``_owned_entries``) from *staged* into *target*.User-owned paths are never touched. ``config.yaml`` is replaced only when``preserve_config`` is False (fresh install / ``--force-config``). ``.env.template`` lands- as ``.env.EXAMPLE`` so it never shadows a real ``.env``."""+ as ``.env.EXAMPLE`` so it never shadows a real ``.env``. During an update,+ the skills tree is merged so skills that are not in the new distribution+ are left alone."""target.mkdir(parents=True, exist_ok=True)staged_resolved = staged.resolve()@@ -380,9 +388,10 @@ def _copy_dist_payload(staged: Path, target: Path, manifest: DistributionManifesdest = target.joinpath(*rel_parts)dest.parent.mkdir(parents=True, exist_ok=True)if src.is_dir():- if dest.exists():+ merge_skills = preserve_skills and rel_parts[0] == "skills"+ if dest.exists() and not merge_skills:shutil.rmtree(dest)- shutil.copytree(src, dest, ignore=_ignore_user_owned)+ shutil.copytree(src, dest, ignore=_ignore_user_owned, dirs_exist_ok=merge_skills)else:shutil.copy2(src, dest)@@ -451,7 +460,13 @@ def update_distribution(profile_name: str, force_config: bool = False) -> Instalwith tempfile.TemporaryDirectory(prefix="hermes_dist_update_") as tmp:plan = plan_install(existing_manifest.source, Path(tmp), override_name=canon)plan.preserves_config = not force_config- _copy_dist_payload(plan.staged_dir, plan.target_dir, plan.manifest, preserve_config=plan.preserves_config)+ _copy_dist_payload(+ plan.staged_dir,+ plan.target_dir,+ plan.manifest,+ preserve_config=plan.preserves_config,+ preserve_skills=True,+ )return plandiff --git a/tests/hermes_cli/test_profile_distribution.py b/tests/hermes_cli/test_profile_distribution.pyindex 0a542307560..cf7ec7fd5ce 100644--- a/tests/hermes_cli/test_profile_distribution.py+++ b/tests/hermes_cli/test_profile_distribution.py@@ -375,6 +375,42 @@ class TestInstall:class TestUpdate:+ def test_update_merges_skills_without_removing_profile_skills(self, profile_env):+ staged = _make_staging_dir(profile_env, "src")+ plan = install_distribution(str(staged), name="skills_safe")++ custom = plan.target_dir / "skills" / "custom"+ custom.mkdir()+ (custom / "SKILL.md").write_text("custom skill\n")+ stale = plan.target_dir / "skills" / "stale"+ stale.mkdir()+ (stale / "SKILL.md").write_text("stale skill\n")+ (staged / "skills" / "demo" / "SKILL.md").write_text("updated demo\n")+ (staged / "skills" / "new").mkdir()+ (staged / "skills" / "new" / "SKILL.md").write_text("new skill\n")++ update_distribution("skills_safe")++ assert (plan.target_dir / "skills" / "custom" / "SKILL.md").read_text() == "custom skill\n"+ assert (plan.target_dir / "skills" / "stale" / "SKILL.md").read_text() == "stale skill\n"+ assert (plan.target_dir / "skills" / "demo" / "SKILL.md").read_text() == "updated demo\n"+ assert (plan.target_dir / "skills" / "new" / "SKILL.md").read_text() == "new skill\n"++ def test_update_preserves_skills_when_distribution_uses_explicit_allowlist(self, profile_env):+ mf = DistributionManifest(name="skills_allowlist", version="0.1.0", distribution_owned=["skills"])+ staged = _make_staging_dir(profile_env, "src", manifest=mf)+ plan = install_distribution(str(staged), name="skills_allowlist")++ custom = plan.target_dir / "skills" / "custom"+ custom.mkdir()+ (custom / "SKILL.md").write_text("custom skill\n")+ (staged / "skills" / "demo" / "SKILL.md").write_text("updated demo\n")++ update_distribution("skills_allowlist")++ assert (plan.target_dir / "skills" / "custom" / "SKILL.md").read_text() == "custom skill\n"+ assert (plan.target_dir / "skills" / "demo" / "SKILL.md").read_text() == "updated demo\n"+def test_update_preserves_user_data(self, profile_env):# 1. Build staging dir, installstaged = _make_staging_dir(profile_env, "src")@@ -758,4 +794,3 @@ class TestManifestCrashDurability:mode = stat.S_IMODE(mf.stat().st_mode)assert mode == 0o644, f"new manifest created as {oct(mode)}"-