mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-27 01:11:40 +00:00
fix(disk-cleanup): preserve git internals during empty-dir cleanup
This commit is contained in:
parent
83a7a005aa
commit
8fb0f7b8d8
2 changed files with 48 additions and 1 deletions
|
|
@ -10,7 +10,7 @@ Rules:
|
|||
- test files → delete immediately at task end (age >= 0)
|
||||
- temp files → delete after 7 days
|
||||
- cron-output → delete after 14 days
|
||||
- empty dirs → always delete (under HERMES_HOME)
|
||||
- empty dirs → delete when safe under HERMES_HOME (excluding checkpoint shadow-repo dirs and git internals)
|
||||
- research → keep 10 newest, prompt for older (deep only)
|
||||
- chrome-profile→ prompt after 14 days (deep only)
|
||||
- >500 MB files → prompt always (deep only)
|
||||
|
|
@ -145,6 +145,29 @@ ALLOWED_CATEGORIES = {
|
|||
}
|
||||
|
||||
|
||||
def _is_protected_empty_dir(dirpath: Path, hermes_home: Path) -> bool:
|
||||
"""Return True when an empty-dir cleanup candidate must be preserved.
|
||||
|
||||
This protects git internals for both Hermes checkpoint shadow repos
|
||||
(stored under ``checkpoints/<id>/...``) and ordinary repos living under
|
||||
``HERMES_HOME`` (stored under ``.git/...``).
|
||||
"""
|
||||
try:
|
||||
rel_parts = dirpath.relative_to(hermes_home).parts
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
if ".git" in rel_parts and rel_parts[-1] != ".git":
|
||||
return True
|
||||
|
||||
if len(rel_parts) >= 2 and rel_parts[0] == "checkpoints":
|
||||
repo_root = hermes_home / rel_parts[0] / rel_parts[1]
|
||||
if any((repo_root / marker).exists() for marker in ("HEAD", "HERMES_WORKDIR", "config")):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def fmt_size(n: float) -> str:
|
||||
for unit in ("B", "KB", "MB", "GB", "TB"):
|
||||
if n < 1024:
|
||||
|
|
@ -309,6 +332,8 @@ def quick() -> Dict[str, Any]:
|
|||
rel_parts = dirpath.relative_to(hermes_home).parts
|
||||
except ValueError:
|
||||
continue
|
||||
if _is_protected_empty_dir(dirpath, hermes_home):
|
||||
continue
|
||||
# Skip the well-known top-level state dirs themselves.
|
||||
if len(rel_parts) == 1 and rel_parts[0] in _PROTECTED_TOP_LEVEL:
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue