fix(disk-cleanup): re-validate stale test entries and protect new dirs from sweep

Address review feedback from teknium1:

1. Re-validate stale 'test' category entries in quick() — existing
   tracked.json entries under now-protected directories (patches/,
   projects/, etc.) are re-classified via guess_category() and
   dropped instead of deleted, mirroring the cron-output pattern.

2. Add patches, projects, skins, themes, contributors to
   _EMPTY_DIR_PROTECTED_TOP_LEVEL so the empty-directory sweep
   never traverses into these user-authored project trees.
This commit is contained in:
Baophan00 2026-07-31 20:59:19 +07:00 committed by Teknium
parent 5286fe1981
commit 6f400d2a20
1 changed files with 18 additions and 0 deletions

View File

@ -148,6 +148,9 @@ _EMPTY_DIR_PROTECTED_TOP_LEVEL = frozenset({
"logs", "memories", "sessions", "cron", "cronjobs",
"cache", "skills", "plugins", "disk-cleanup", "optional-skills",
"hermes-agent", "backups", "profiles", ".worktrees",
# User-authored project trees — never sweep empty directories
# inside these (#75403).
"patches", "projects", "skins", "themes", "contributors",
})
_EMPTY_DIR_SWEEP_PRUNE_DIRS = frozenset({
@ -336,6 +339,21 @@ def quick() -> Dict[str, Any]:
# Drop the stale entry — it was misclassified.
continue
# ---- stale-state migration for 'test' category (fixes #75403) ----
# Old tracked.json entries may carry a "test" category for paths
# that are now under protected project directories (patches/,
# projects/, etc.). guess_category() was tightened in the fix for
# #75403, but existing entries are never re-validated. Re-classify
# here so stale entries for protected paths are not deleted.
if cat == "test":
re_cat = guess_category(p)
if re_cat != "test":
_log(
f"SKIP stale test entry: {p} "
f"(re-classified as {re_cat!r} — under protected tree)"
)
continue
# Hard safety net: never delete cron control-plane state even if
# the category somehow slipped through re-validation above.
if _is_protected_cron_path(p):