The plugin now registers a pre_tool_call hook, but plugin.yaml still listed only post_tool_call/on_session_end, so `plugin doctor` warned "registration adds hook 'pre_tool_call' not listed in provides_hooks" and catalog/capability listings under-reported what the plugin hooks. Also: README notes calls without a tool_call_id (execute_code RPC) are not tracked; a single _owner() helper keys both _pre_call and _recent_test_tracks so the two can't drift; drop the unused `result` parameter from the post hook (still absorbed by **_); trim the _pre_call comment.
62 lines
3.2 KiB
Markdown
62 lines
3.2 KiB
Markdown
# disk-cleanup
|
|
|
|
Auto-tracks and cleans up ephemeral files created during Hermes Agent
|
|
sessions — test scripts, temp outputs, cron logs, stale chrome profiles.
|
|
<!-- no-tmp: ok — documents the legacy scratch scope this plugin cleans up -->
|
|
Scoped strictly to `$HERMES_HOME` and `/tmp/hermes-*`.
|
|
|
|
Originally contributed by [@LVT382009](https://github.com/LVT382009) as a
|
|
skill in PR #12212. Ported to the plugin system so the behaviour runs
|
|
automatically via `post_tool_call` and `on_session_end` hooks — the agent
|
|
never needs to remember to call a tool.
|
|
|
|
## How it works
|
|
|
|
| Hook | Behaviour |
|
|
|---|---|
|
|
| `pre_tool_call` | Snapshot which paths named in the call's arguments do not exist yet, keyed by the owning task/session plus `tool_call_id` (the id alone is not unique: llama.cpp reuses one constant id). |
|
|
| `post_tool_call` | When `write_file` / `terminal` / `patch` creates a file matching `test_*`, `tmp_*`, or `*.test.*` inside `HERMES_HOME` — a path named in the call that did not exist before it — track it silently as `test` / `temp` / `cron-output`. Existing files the call edits, runs or lists are never tracked, and neither is any path the call's own snapshot did not cover (e.g. one another plugin's `modify` hook swapped in). Calls without a `tool_call_id` (execute_code RPC) are not tracked. |
|
|
| `on_session_end` | If any test files were auto-tracked during this turn, run `quick` cleanup (no prompts). |
|
|
|
|
Deletion rules (same as the original PR):
|
|
|
|
| Category | Threshold | Confirmation |
|
|
|---|---|---|
|
|
| `test` | every session end | Never |
|
|
| `temp` | >7 days since tracked | Never |
|
|
| `cron-output` | >14 days since tracked | Never |
|
|
| empty dirs under HERMES_HOME | always | Never |
|
|
| `research` | >30 days, beyond 10 newest | Always (deep only) |
|
|
| `chrome-profile` | >14 days since tracked | Always (deep only) |
|
|
| files >500 MB | never auto | Always (deep only) |
|
|
|
|
## Slash command
|
|
|
|
```
|
|
/disk-cleanup status # breakdown + top-10 largest
|
|
/disk-cleanup dry-run # preview without deleting
|
|
/disk-cleanup quick # run safe cleanup now
|
|
/disk-cleanup deep # quick + list items needing prompt
|
|
/disk-cleanup track <path> <category> # manual tracking
|
|
/disk-cleanup forget <path> # stop tracking
|
|
```
|
|
|
|
## Safety
|
|
|
|
<!-- no-tmp: ok — documents the legacy scratch scope this plugin cleans up -->
|
|
- `is_safe_path()` rejects anything outside `HERMES_HOME` or `/tmp/hermes-*`
|
|
- Windows mounts (`/mnt/c` etc.) are rejected
|
|
- The state directory `$HERMES_HOME/disk-cleanup/` is itself excluded
|
|
- `$HERMES_HOME/logs/`, `memories/`, `sessions/`, `skills/`, `plugins/`,
|
|
and config files are never tracked
|
|
- User project trees (`workspace/`, `projects/`, `plans/`, `home/`, `patches/`,
|
|
`skins/`, `themes/`, `contributors/`, `profiles/`, `backups/`) and `kanban/`
|
|
(task attachments/workspaces) are never tracked or swept, even for files
|
|
named `test_*`/`tmp_*`
|
|
- A tracked *directory* under a protected top level (e.g. `cache/`, which holds
|
|
terminal snapshots) is never removed; only its files age out. Stale entries
|
|
are logged as `SKIPPED` and dropped
|
|
- Backup/restore is scoped to `tracked.json` — the plugin never touches
|
|
agent logs
|
|
- Atomic writes: `.tmp` → backup → rename
|