# AGENTS.md — Memory System Rules

> Copy these sections into your AGENTS.md. Use them as-is or adapt to your style.
> The key is the MANDATORY framing — don't soften the language.

---

## After Any Crash/Restart/Compaction (MANDATORY)

1. Read `memory/working-state.md` FIRST — this tells you what you were doing
2. Read today's daily log (`memory/YYYY-MM-DD.md`)
3. Read yesterday's daily log if present
4. Resume work from where you left off
5. Do NOT ask the user "what were we working on?" — the answer is in your files

## Working State (MANDATORY)

- **File:** `memory/working-state.md`
- **Update when:** Starting a task, completing a task, spawning a sub-agent, receiving a sub-agent result
- **After any crash/restart/compaction:** Read this file FIRST before anything else
- **Keep it short:** "Right Now" section + "Done Today" + "Pending" — not a novel
- **Overwrite constantly** — this is current state, not history

## Daily Memory (MANDATORY)

- **File:** `memory/YYYY-MM-DD.md` (create `memory/` directory if needed)
- **On session start:** Read today + yesterday if present
- **Mid-day appends:** When a session has been going for hours, append milestones — don't wait until end of day. If the session dies, the work is captured.
- **Capture:** Durable facts, decisions, preferences, project milestones
- **Avoid:** Secrets, API keys, passwords

## Self-Learning System (MANDATORY)

- **File:** `memory/lessons-learned.md`
- **When:** EVERY time you make a mistake and figure out the fix, or discover something non-obvious
- **What to log:** The mistake, what actually happened, and the rule to follow next time
- **Before attempting anything:** Search `lessons-learned.md` FIRST to avoid repeating mistakes
- **Categories:** Gateway/Infra, Discord API, Cron Jobs, File Ops, Context/Memory, Sub-agents, and any new category as needed
- **Goal:** Never make the same mistake twice

## Memory Recall (MANDATORY)

- Before answering ANY question about prior work, decisions, dates, people, preferences, or todos: run `memory_search` on your memory files
- Use `memory_get` after search to pull only the needed lines
- If low confidence after search, say you checked but aren't sure
- **Never guess from "memory" — actually search the files**

## Git Backup (Recommended Daily)

```bash
cd ~/.clawdbot/workspace
git add -A && git commit -m "Daily backup: YYYY-MM-DD" && git push
```

Your identity, memory, and progress survive anything when backed up to a remote repo.
