The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(curator): carry .git file pointers too and document the deleted-skill drop
kshitijk4poor5f24f291c2a9
diff --git a/agent/curator_backup.py b/agent/curator_backup.pyindex c82930a4dae..19e1e785ab6 100644--- a/agent/curator_backup.py+++ b/agent/curator_backup.py@@ -557,24 +557,37 @@ def _restore_cron_skill_links(snapshot_dir: Path) -> Dict[str, Any]:def _restore_excluded_subtrees(staged: Path, skills: Path) -> None:- """Move excluded subtrees (nested ``.git``/``.hub``/...) from *staged*- back under *skills* after a successful extract. Best-effort: a subtree- is only moved when its parent skill dir was restored and the target- does not already exist."""- for dirpath, dirnames, _files in os.walk(staged):+ """Move excluded entries (nested ``.git``/``.hub``/...) from *staged*+ back under *skills* after a successful extract.++ Snapshots never contain these, so the extract cannot restore them; the+ staged copy of the live tree is the only source. ``.git`` may be a dir+ or a file (submodule / worktree ``gitdir:`` pointer) — both are moved.+ Best-effort and deliberately conditional: an entry is carried over only+ when its parent skill dir was restored and nothing sits at the target.+ If the target snapshot predates the skill, the entry is dropped with the+ staging dir rather than left as an orphan; note the safety snapshot+ excludes these paths too, so that case is not undoable.+ """+ def _carry(src: Path) -> None:+ dest = skills / src.relative_to(staged)+ if dest.parent.is_dir() and not dest.exists():+ try:+ shutil.move(str(src), str(dest))+ except OSError as e:+ logger.debug("Could not restore excluded entry %s: %s", src, e)++ for dirpath, dirnames, filenames in os.walk(staged):keep = []for name in dirnames:- if name not in _EXCLUDE_TOP_LEVEL:+ if name in _EXCLUDE_TOP_LEVEL:+ _carry(Path(dirpath) / name)+ else:keep.append(name)- continue- src = Path(dirpath) / name- dest = skills / src.relative_to(staged)- if dest.parent.is_dir() and not dest.exists():- try:- shutil.move(str(src), str(dest))- except OSError as e:- logger.debug("Could not restore excluded subtree %s: %s", src, e)dirnames[:] = keep+ for name in filenames:+ if name in _EXCLUDE_TOP_LEVEL:+ _carry(Path(dirpath) / name)def _unstage(moved: List[Tuple[Path, Path]]) -> List[str]:@@ -736,10 +749,9 @@ def rollback(backup_id: Optional[str] = None) -> Tuple[bool, str, Optional[Path]# Extract succeeded. Snapshots never contain excluded subtrees (nested# ``.git``, ``.hub``, ...), so the extract cannot restore them — carry- # them over from the staged copy of the live tree instead, the same way- # a top-level ``.git`` is preserved by never being staged at all. Then- # the staging dir has served its purpose; the user's undo handle is the- # safety snapshot tarball we took earlier.+ # them over from the staged copy of the live tree (top-level ``.git`` is+ # simpler: it is never staged). Then the staging dir has served its+ # purpose; the user's undo handle is the safety snapshot tarball._restore_excluded_subtrees(staged, skills)try:shutil.rmtree(staged, ignore_errors=True)diff --git a/tests/agent/test_curator_backup.py b/tests/agent/test_curator_backup.pyindex 8ab7c8846e9..12826e49b88 100644--- a/tests/agent/test_curator_backup.py+++ b/tests/agent/test_curator_backup.py@@ -574,3 +574,26 @@ def test_rollback_preserves_nested_git_inside_skill(backup_env):assert (nested_git / "HEAD").read_text(encoding="utf-8") == "ref: refs/heads/feature\n"staging = list((skills / ".curator_backups").glob(".rollback-staging-*"))assert staging == [], f"staging dir left behind: {staging}"+++def test_rollback_preserves_nested_git_file_pointer(backup_env):+ """Submodule / worktree checkouts use a ``.git`` FILE (gitdir: pointer);+ it must be carried across rollback like the dir form."""+ cb = backup_env["cb"]+ skills = backup_env["skills"]++ _write_skill(skills, "alpha", body="v1")+ git_ptr = skills / "alpha" / ".git"+ git_ptr.write_text("gitdir: ../../.git/modules/alpha\n", encoding="utf-8")++ snap_dir = cb.snapshot_skills(reason="snap-v1")+ assert snap_dir is not None+ with tarfile.open(snap_dir / "skills.tar.gz", "r:gz") as tf:+ assert "alpha/.git" not in tf.getnames()++ _write_skill(skills, "alpha", body="v2")+ ok, msg, _ = cb.rollback(backup_id=snap_dir.name)+ assert ok, f"rollback failed: {msg}"+ assert "v1" in (skills / "alpha" / "SKILL.md").read_text(encoding="utf-8")+ assert git_ptr.is_file()+ assert git_ptr.read_text(encoding="utf-8").startswith("gitdir:")