# Memory Janitor

> Keep your Markdown / Obsidian agent memory from rotting: single-file zero-dependency CLI that indexes, auto-crosslinks, normalizes tags, and audits 600+ nodes in under a second at zero token cost.

Memory Janitor is a paid AI agent skill on Agensi by Scrimal, in LLM Ops. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $9.99 (one-time purchase)
- Creator: [Scrimal](https://www.agensi.io/creators/scrimal)
- Category: [LLM Ops](https://www.agensi.io/skills/llm-ops)
- Version: 1.1.1
- Last updated: 2026-12-02
- Security: scan passed (2026-12-02); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/memory-janitor
- Tags: llm-ops, ai-agents, code-review, memory, maintenance, drift-detection, index, crosslink

## About this skill

Markdown and Obsidian memory vaults decay fast: orphaned notes, broken `[[wikilinks]]`, duplicate tags (`auth_fix` vs `auth-fix`), and bloated summaries silently poison your agent's recall until it starts hallucinating or missing critical context.

**Memory Janitor** is a drop-in, single-file maintenance engine (`scripts/memory_janitor.py`) that rebuilds your entire graph index, discovers missing cross-links, enforces canonical tags, and audits structural integrity in under a second—**at zero LLM token cost**, without requiring the full `spine-memory` package.

### Why It Beats Manual Cleanup & LLM Refactoring
* **All-in-One Maintenance CLI (`600 lines`, pure stdlib):** Rebuilds reverse link/anchor/code indexes (`index`), auto-wires safe bidirectional links (`crosslink`), catches tag drift (`anchors`), and audits node health (`audit`) in one pass.
* **Incremental `cache.json` + Atomic Writes:** Skips unchanged files via `(mtime_ns, size, sha256)` and writes both indexes and Markdown updates atomically (`tmp + os.replace`) so your vault never corrupts mid-run.
* **Battle-Tested on 600+ Live Nodes:** Handles edge cases that break naive scripts—nested subdirectories, `---` delimiters inside raw log blocks, `[[wikilinks]]` inside YAML arrays, and Windows/Linux UTF-8 output.
* **CI & Pre-Commit Ready Exit Codes:** Returns deterministic exit codes (`0` clean, `1` warnings, `2` errors) so you can gate knowledge-base quality automatically before every commit.

### What's Inside
1. `scripts/memory_janitor.py` — Standalone zero-dependency CLI (`index`, `crosslink`, `anchors`, `audit`) with incremental caching and dry-run/apply modes.
2. `references/node_schema.md` — Validated Markdown + YAML node specification (`adr`, `postmortem`, `gotcha`, `contract`, `dead_end`) and section caps.

## Requires

- Python 3.10+

Zero external dependencies or network requests. Runs locally on any Markdown/YAML folder with incremental caching and atomic file writes.

## Known limitations

Requires Markdown files with YAML frontmatter; unstructured plain-text notes without frontmatter keys are skipped during indexing and audit.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Memory Janitor skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What specific problem does this skill solve for my AI's memory?

The Memory Janitor prevents 'graph drift'—the accumulation of dead links, broken YAML, and duplicate tags that degrade RAG performance—by using deterministic Python logic instead of expensive LLM tokens.

### Is this skill compatible with my specific AI agent or framework?

The tool is built on Python 3 using only the standard library, making it compatible with any AI agent environment or CI/CD pipeline that supports Python, including local setups and cloud instances.

### Do I need to install any third-party Python packages to use this?

No, this is a zero-dependency script that processes Markdown files and YAML frontmatter directly, meaning you don't need to install external libraries like 'spine_memory' or heavy NLP packages.

### What exactly is included in the purchase of this skill?

You receive SKILL.md (the vault hygiene workflow), scripts/memory_janitor.py (a standalone zero-dependency CLI supporting index, crosslink, anchors, and audit with incremental caching and exit codes 0/1/2), and references/node_schema.md (the validated YAML + section schema specification).

### Will using this skill consume my LLM token quota during maintenance tasks?

Because it uses deterministic logic based on anchor overlaps and constellation matching, it runs locally on your files without making any API calls to OpenAI or other providers.

### What are the primary requirements for my file structure?

The script requires your knowledge base to be stored as Markdown files with YAML frontmatter; it cannot audit unstructured text files or proprietary database formats without conversion.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
