The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(curator): purge ages by usage archived_at when present
kshitijk4poor59b77622a9d3
diff --git a/hermes_cli/curator.py b/hermes_cli/curator.pyindex e7b43aaf670..18dbb63a896 100644--- a/hermes_cli/curator.py+++ b/hermes_cli/curator.py@@ -423,7 +423,7 @@ def _cmd_purge(args) -> int:import shutilimport timefrom hermes_cli.config import cfg_get, load_config- from tools import skill_ledger+ from tools import skill_ledger, skill_usagefrom tools.skill_usage import _archive_dirttl_days = getattr(args, "days", None)if ttl_days is None:@@ -438,8 +438,16 @@ def _cmd_purge(args) -> int:print("curator: no archive directory — nothing to purge.")return 0cutoff = time.time() - ttl_days * 86400++ def _archived_ts(p: Path) -> float:+ # Prefer the usage record's archived_at: archives made before archive_skill stamped the+ # dir mtime still carry the skill's last-edit mtime and would be purged at once.+ rec = skill_usage.get_record(p.name)+ at = skill_usage._parse_iso_timestamp(rec.get("archived_at")) if rec.get("state") == skill_usage.STATE_ARCHIVED else None+ return at.timestamp() if at else p.stat().st_mtime+candidates = sorted(- p for p in archive_root.iterdir() if p.is_dir() and p.stat().st_mtime < cutoff)+ p for p in archive_root.iterdir() if p.is_dir() and _archived_ts(p) < cutoff)if not candidates:print(f"curator: no archived skills older than {ttl_days}d.")return 0diff --git a/tests/hermes_cli/test_curator_archive_prune.py b/tests/hermes_cli/test_curator_archive_prune.pyindex 8dd37dc8c10..cd3501b3414 100644--- a/tests/hermes_cli/test_curator_archive_prune.py+++ b/tests/hermes_cli/test_curator_archive_prune.py@@ -59,6 +59,31 @@ def test_purge_ages_an_archive_from_when_it_was_archived(tmp_path, monkeypatch):assert (tmp_path / "skills" / ".archive" / "old-helper" / "SKILL.md").is_file()+def test_purge_prefers_recorded_archived_at_over_a_stale_dir_mtime(tmp_path, monkeypatch):+ """An archive made before the mtime stamp keeps an old dir mtime; its usage record's+ archived_at (today) is what the TTL counts from."""+ import os+ import time++ import hermes_cli.curator as curator_cli+ from tools import skill_usage++ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ skill_dir = tmp_path / "skills" / "legacy"+ skill_dir.mkdir(parents=True)+ (skill_dir / "SKILL.md").write_text(+ "---\nname: legacy\ndescription: x\n---\n# body\n", encoding="utf-8")+ skill_usage.record_created("legacy", agent_created=True)+ ok, msg = skill_usage.archive_skill("legacy")+ assert ok, msg+ archived = tmp_path / "skills" / ".archive" / "legacy"+ long_ago = time.time() - 100 * 86400+ os.utime(archived, (long_ago, long_ago))++ assert curator_cli._cmd_purge(_ns(days=30, dry_run=False, yes=True)) == 0+ assert (archived / "SKILL.md").is_file()++# ─── prune ──────────────────────────────────────────────────────────────────