The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): exclude .git and .curator_backups in curator snapshot_skills
Jakub Wolniewicz5b92b9f91387
diff --git a/agent/curator_backup.py b/agent/curator_backup.pyindex dbd0f4701f5..9a1c0d81a94 100644--- a/agent/curator_backup.py+++ b/agent/curator_backup.py@@ -11,6 +11,7 @@ is undoable, then extracts the chosen snapshot into place.The snapshot does NOT include:- ``.curator_backups/`` (would recurse)- ``.hub/`` (hub-installed skills — managed by the hub, not us)+ - ``.git/`` (repository metadata — managed by git, not the curator)It DOES include:- all SKILL.md files + their directories (``scripts/``, ``references/``,@@ -60,7 +61,8 @@ DEFAULT_KEEP = 5# Entries under skills/ that should NEVER be rolled up into a snapshot.# .hub/ is managed by the skills hub; rolling it back would break lockfile# invariants. .curator_backups is the backup dir itself — recursion bomb.-_EXCLUDE_TOP_LEVEL = {".curator_backups", ".hub"}+# .git is repository metadata — rolling it back would break git tracking.+_EXCLUDE_TOP_LEVEL = {".curator_backups", ".hub", ".git"}# Snapshot id regex: UTC ISO with colons replaced by dashes so the filename# is portable (Windows-safe). An optional ``-NN`` suffix handles two@@ -260,6 +262,12 @@ def snapshot_skills(reason: str = "manual", *, protect_ids: Optional[Set[str]] =return Nonearchive = dest / "skills.tar.gz"+ def _tar_filter(tarinfo: tarfile.TarInfo) -> Optional[tarfile.TarInfo]:+ parts = Path(tarinfo.name).parts+ if any(p in _EXCLUDE_TOP_LEVEL for p in parts):+ return None+ return tarinfo+try:# Stream into the tarball — no tempdir copy needed.with tarfile.open(archive, "w:gz", compresslevel=6) as tf:@@ -268,7 +276,7 @@ def snapshot_skills(reason: str = "manual", *, protect_ids: Optional[Set[str]] =continue# arcname: store paths relative to skills/ so extraction# drops cleanly back into the skills dir.- tf.add(str(entry), arcname=entry.name, recursive=True)+ tf.add(str(entry), arcname=entry.name, recursive=True, filter=_tar_filter)# Capture cron/jobs.json alongside the tarball. Never fails the# snapshot — the skills side is the core guarantee; cron is# additive. We still record in the manifest whether it wasdiff --git a/tests/agent/test_curator_backup.py b/tests/agent/test_curator_backup.pyindex fcd55112b8c..215679504e6 100644--- a/tests/agent/test_curator_backup.py+++ b/tests/agent/test_curator_backup.py@@ -484,3 +484,67 @@ def test_rollback_recovers_cleanly_from_a_partial_extract(backup_env, monkeypatcassert present == ["alpha", "beta"], f"tree not restored: {present}"assert "current copy" in (skills / "alpha" / "SKILL.md").read_text(encoding="utf-8")assert "current only" in (skills / "beta" / "SKILL.md").read_text(encoding="utf-8")+++def test_snapshot_excludes_git_and_curator_backups_and_hub(backup_env):+ """Tar snapshots must exclude .git, .curator_backups, and .hub (top-level and nested)."""+ cb = backup_env["cb"]+ skills = backup_env["skills"]++ # Top-level excluded structures+ (skills / ".git").mkdir()+ (skills / ".git" / "config").write_text("[core]\nrepositoryformatversion = 0\n", encoding="utf-8")+ (skills / ".hub").mkdir()+ (skills / ".hub" / "lock.json").write_text("{}", encoding="utf-8")++ # Regular skill with nested .git+ _write_skill(skills, "alpha", body="alpha body")+ nested_git = skills / "alpha" / ".git"+ nested_git.mkdir()+ (nested_git / "HEAD").write_text("ref: refs/heads/main\n", encoding="utf-8")++ snap_dir = cb.snapshot_skills(reason="test-exclude-git")+ assert snap_dir is not None++ archive = snap_dir / "skills.tar.gz"+ assert archive.exists()++ with tarfile.open(archive, "r:gz") as tf:+ members = tf.getnames()++ # Ensure no member contains .git, .curator_backups, or .hub+ for name in members:+ parts = Path(name).parts+ assert ".git" not in parts, f".git found in archive: {name}"+ assert ".curator_backups" not in parts, f".curator_backups found in archive: {name}"+ assert ".hub" not in parts, f".hub found in archive: {name}"++ assert "alpha/SKILL.md" in members+++def test_rollback_preserves_top_level_git(backup_env):+ """Rollback must preserve repository .git metadata untouched in the skills root."""+ cb = backup_env["cb"]+ skills = backup_env["skills"]++ git_dir = skills / ".git"+ git_dir.mkdir()+ (git_dir / "HEAD").write_text("ref: refs/heads/main\n", encoding="utf-8")+ _write_skill(skills, "alpha", body="v1")++ snap_dir = cb.snapshot_skills(reason="snap-v1")+ assert snap_dir is not None++ # Mutate skills tree and git metadata+ _write_skill(skills, "alpha", body="v2")+ _write_skill(skills, "beta", body="new")+ (git_dir / "HEAD").write_text("ref: refs/heads/feature\n", encoding="utf-8")++ ok, msg, _ = cb.rollback(backup_id=snap_dir.name)+ assert ok, f"rollback failed: {msg}"++ assert (skills / "alpha" / "SKILL.md").read_text(encoding="utf-8").find("v1") != -1+ assert not (skills / "beta").exists()+ assert (git_dir / "HEAD").exists()+ assert (git_dir / "HEAD").read_text(encoding="utf-8") == "ref: refs/heads/feature\n"+