"""Delete only finished scratch created under this isolated task directory."""
from pathlib import Path
P=Path('/opt/creature-lib-20261017')
for name in ['candidates','node-runtime/cache']:
 d=P/name
 if d.exists():
  for p in sorted(d.rglob('*'),key=lambda p:len(p.parts),reverse=True):
   if p.is_file() or p.is_symlink():p.unlink()
   elif p.is_dir():p.rmdir()
  d.rmdir()
for d in (P/'renders').glob('*-frames'):
 for p in d.iterdir():p.unlink()
 d.rmdir()
for p in (P/'renders').glob('*footplant*.png'):p.unlink()
for prefix in ['enemy-floating-golem','enemy-flying-squid','enemy-pigeon']:
 for p in (P/'renders').glob(prefix+'-*.png'):p.unlink()
print('Removed only task-owned finished candidate copies, npm download cache, raw video frames and obsolete experiment renders.')
