Skill: emrys-hong/nightly-workspace-audit (version 1.0.0)

--- name: workspace-audit description: Nightly workspace audit — auto-discover file dependencies by scanning all workspace files for cross-references, manage HOT/WARM/COLD memory tiers, detect orphaned files, sync inconsistencies, and report workspace health. Works out of the box on any OpenClaw workspace. Supports optional local-overrides.md for custom dependency rules. Use when triggered by a nightly cron job, or when the user asks to audit, clean up, or check workspace health. --- # Workspace Audit Auto-discover, clean, tier, sync, and report on an OpenClaw workspace. ## Memory Tiers - **HOT** — auto-loaded every session: root `.md` files (`MEMORY.md`, `TODO.md`, `USER.md`, etc.) - **WARM** — on disk, loaded on demand: `memory/*.md`, `projects/*/` files - **COLD** — archived, rarely touched: `memory/archive/` ## Procedure ### 1. Dependency Discovery Scan every `.md` and `.json` file in `workspace/` (skip `skills/`, `.git/`, `archive/`). **For each file, extract:** - File paths (relative or absolute) mentioned in content - Section headings that appear in multiple files (shared topics) - Lists that substantially overlap across files (potential duplicates) **Then cross-reference against:** - Cron job prompts: `cron list` → extract all file paths from every job's `message` field → verify each file exists - Index files: any file named `README.md` or containing a Markdown table with path-like entries → verify linked targets exist - Tree diagrams: code blocks containing directory trees → verify paths match actual filesystem Build a dependency graph: `{file → [files it references]}`. Flag: - **Broken links**: referenced file doesn't exist - **Orphaned files**: files referenced by nothing (not in any cron, not linked from any index, not a root auto-loaded file) - **Content drift**: two files that reference the same data but have diverged (e.g., a list appears in both MEMORY.md and another file but they differ) ### 2. Memory Hygiene Read all files in `memory/` (skip `archive/`). - **Merge**: Combine related entries across files (same topic split across daily files) - **Deduplicate**: Remove identical content that exists in multiple places - **Prune**: Delete entries confirmed no longer useful (completed one-off tasks, expired temporary notes) - **Archive**: Move daily files older than 7 days to `memory/archive/` - **Rename**: Fix inconsistent naming if found After changes, update the workspace structure tree in `MEMORY.md` if one exists. ### 3. Auto-promote / Demote Apply tier rules. See [tier-rules.md](references/tier-rules.md) for thresholds and exceptions. - **Promote WARM → HOT**: Add a summary line to `MEMORY.md` - **Demote HOT → WARM**: Remove from `MEMORY.md`, ensure info exists in a WARM file - **Demote WARM → COLD**: Move file to `memory/archive/` **Every promotion or demotion must be listed in the report.** ### 4. Local Overrides (optional) If [local-overrides.md](references/local-overrides.md) exists, run those additional checks. These are user-specific dependency pairs that can't be auto-discovered (e.g., content-level sync between specific sections). Skip this step if the file doesn't exist. ### 5. Report Send a concise message to the user: ``` 🔍 Workspace Audit — {date} **Dependencies** - {broken links found and fixed/flagged} - {orphaned files found} - {content drift detected} - {or "All dependencies healthy"} **Cleaned** - {what was merged/deleted/archived, or "Nothing — all clean"} **Tier changes** - ⬆️ Promoted: {item} (WARM → HOT) — reason - ⬇️ Demoted: {item} (HOT → WARM) — reason - {or "No tier changes"} **Sync issues** - {local override mismatches, or "All in sync"} **Health** - {file count} workspace files, {cron count} cron jobs, {error count} cron errors - {any expiring items} ```

path: references/tier-rules.md
content: # Tier Rules

## Promote: WARM → HOT

A WARM memory should be promoted to HOT (added to `MEMORY.md`) when:

- Referenced or opened 3+ times within the past 7 days
- Contains information needed by multiple cron jobs or skills
- Contains context that was missing during a session and caused re-fetching

**How to promote:**
1. Extract a concise summary (1-5 lines) of the key facts
2. Add to the appropriate section in `MEMORY.md`
3. Note the promotion in the report with reason

## Demote: HOT → WARM

A HOT memory (section in `MEMORY.md`) should be demoted to WARM when:

- Not referenced in any session or cron job for 30+ days
- Relates to a completed or abandoned project
- Information is stale or no longer actionable

**How to demote:**
1. Verify the info exists in a WARM file (if not, create one first)
2. Remove the section from `MEMORY.md`
3. Note the demotion in the report — user must be informed

## Demote: WARM → COLD

A WARM file should be demoted to COLD (moved to `memory/archive/`) when:

- Not read or modified for 90+ days
- All actionable items in it are completed
- Content is purely historical with no ongoing reference value

**How to demote:**
1. Move the file to `memory/archive/`
2. Update any references to the old path
3. Note the demotion in the report

## Exceptions (never auto-demote)

Do not auto-demote files that:
- Are actively referenced by a cron job prompt (check via `cron list`)
- Belong to a project with status other than "done" or "archived"
- Are explicitly listed in `local-overrides.md` as protected

## Tracking Reference Counts

During each audit, check:
- Recent session transcripts (via `memory_search`) for file references
- Cron job prompts (via `cron list`) for file paths
- Root auto-loaded files for cross-references
- Last-modified timestamps on all WARM files

Count references in the past 7 days for promotion decisions. Use last-modified date for demotion decisions.


Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (MEDIUM)