$npx -y skills add xwtro0tk1t-cloud/harness --skill harness-cleanup--- description: Trigger when user says "harness cleanup", "cleanup temp files", "archive temp files", "clean up root junk", "project cleanup", "archive junk files". Scans project root for temp files, interactively archives to archive/ directory. NEVER deletes — only moves. Do NO
| 1 | # Harness Cleanup — Interactive Temp File Archive |
| 2 | |
| 3 | --- |
| 4 | description: Trigger when user says "harness cleanup", "cleanup temp files", "archive temp files", "clean up root junk", "project cleanup", "archive junk files". Scans project root for temp files, interactively archives to archive/ directory. NEVER deletes — only moves. Do NOT trigger for: deleting files (this skill only moves), cleaning dependencies (use package manager), cleaning git history. |
| 5 | --- |
| 6 | |
| 7 | ## Behavior |
| 8 | |
| 9 | Scan project root directory only (not recursive) for temp/junk files. Interactively archive to `archive/YYYY-MM-DD/`. |
| 10 | **Never deletes** — only moves. Works with `harness-audit` (passive detection). |
| 11 | |
| 12 | --- |
| 13 | |
| 14 | ## Scan Scope & Exclusions |
| 15 | |
| 16 | ### Scan Scope |
| 17 | Project root directory only, no recursion. |
| 18 | |
| 19 | ### Static Exclusion List |
| 20 | ``` |
| 21 | archive/** .git/** node_modules/** venv/** .venv/** |
| 22 | dist/** build/** .harness/** __pycache__/** |
| 23 | .pytest_cache/** .mypy_cache/** .tox/** .eggs/** *.egg-info/** |
| 24 | ``` |
| 25 | |
| 26 | ### Dynamic Exclusion List |
| 27 | ``` |
| 28 | archive*/ *_archive/ _archive*/ |
| 29 | backup*/ *_backup/ _backup*/ |
| 30 | old_*/ _old/ trash/ .trash/ |
| 31 | ``` |
| 32 | - Self-marker: any directory containing README.md with first line "harness-cleanup archive" → exclude |
| 33 | - User extension: `.harness/cleanup-exclude-dirs` (one glob pattern per line) |
| 34 | |
| 35 | --- |
| 36 | |
| 37 | ## File Detection Rules |
| 38 | |
| 39 | ### Strong Signal (unconditional) |
| 40 | ``` |
| 41 | debug_*.py fix_*.py tmp_* scratch_* wip_*.py |
| 42 | *.bak foo.py bar.py baz.py qux.py |
| 43 | scratch_*.md wip_* NOTES.md output.txt |
| 44 | ``` |
| 45 | |
| 46 | ### Weak Signal: test_*.py (conditional) |
| 47 | |
| 48 | Check pytest testpaths in official precedence order: |
| 49 | 1. `pytest.ini` — `testpaths` setting |
| 50 | 2. `pyproject.toml` `[tool.pytest.ini_options]` — `testpaths` |
| 51 | 3. `tox.ini` `[pytest]` — `testpaths` |
| 52 | 4. `setup.cfg` `[tool:pytest]` — `testpaths` |
| 53 | |
| 54 | **Additional signals** (raise threshold to 20): `noxfile.py` exists / `[tool.hatch.envs.*.scripts]` contains pytest / Makefile has pytest target |
| 55 | |
| 56 | Logic: |
| 57 | - testpaths configured AND root test_*.py is outside testpaths → **strong signal** (unconditional) |
| 58 | - No config AND root has >10 test_*.py → suggest (heuristic threshold, adjust after pilot) |
| 59 | - Standard pytest project (testpaths points to tests/) → skip |
| 60 | |
| 61 | --- |
| 62 | |
| 63 | ## Dirty-Check (pre-archive state detection) |
| 64 | |
| 65 | Use `git status --porcelain -- "$file" | cut -c1-2` to detect file git state: |
| 66 | |
| 67 | | Code | Meaning | Color | Interaction | |
| 68 | |------|---------|-------|-------------| |
| 69 | | `""` | clean_tracked | 🟡 Yellow warning | "File is committed, can git rm after archive" | |
| 70 | | `??"` | untracked | 🟢 Green (primary target) | Archive directly | |
| 71 | | ` M`/`M `/`MM` | dirty_tracked | 🔴 Red warning | "Has uncommitted changes, consider committing first" | |
| 72 | | `A `/`AM` | staged | 🔴 Red strong warning | "Already staged, need to unstage before archiving" | |
| 73 | | Other | other | 🔴 Red | "Unknown state, please confirm before proceeding" | |
| 74 | |
| 75 | **Important**: Do NOT use `git diff --quiet HEAD -- <file>` — it returns 0 for untracked files (misclassifies primary targets as clean). |
| 76 | |
| 77 | --- |
| 78 | |
| 79 | ## Interactive Flow |
| 80 | |
| 81 | 1. **List detected files** (grouped: strong signal / weak signal) |
| 82 | 2. **Per file**: show dirty-check state + archive/skip option |
| 83 | 3. **Bulk actions**: `[Archive All] [Skip All] [Review One by One]` |
| 84 | 4. **.gitignore linkage**: if file is tracked, suggest `git rm --cached <file>` |
| 85 | |
| 86 | --- |
| 87 | |
| 88 | ## Archive Operation (race-safe) |
| 89 | |
| 90 | ``` |
| 91 | 1. dirty-check via porcelain |
| 92 | 2. mkdir -p archive/YYYY-MM-DD/ |
| 93 | 3. flock archive/.lock |
| 94 | 4. mv -n <file> archive/YYYY-MM-DD/<file> |
| 95 | 5. If mv -n fails (name collision) → retry <file>.1, <file>.2, ... |
| 96 | 6. Release lock |
| 97 | 7. Generate archive/YYYY-MM-DD/README.md manifest |
| 98 | ``` |
| 99 | |
| 100 | ### Archive Manifest Template |
| 101 | ```markdown |
| 102 | # Archive YYYY-MM-DD |
| 103 | |
| 104 | | File | Original Path | State | |
| 105 | |------|--------------|-------| |
| 106 | | debug_auth.py | ./debug_auth.py | untracked | |
| 107 | ``` |
| 108 | |
| 109 | --- |
| 110 | |
| 111 | ## Archive Lifecycle |
| 112 | |
| 113 | - Auto-generate README.md manifest in each archive directory |
| 114 | - Archive >90 days → INFO message "Consider deleting archive/YYYY-MM-DD/" (**never auto-delete**) |