The dream cycle is the consolidation pass: episodic events → patterns → candidate lessons → review → graduated lessons. It separates mechanical staging (cron-safe, no LLM) from review with rationale (manual, high-stakes).
PostToolUse hook ┐
→ AGENT_LEARNINGS.jsonl │
│ (Continuous: every tool call)
┘
▼ 03:00 nightly via launchd
auto_dream.py (mechanical, no LLM):
1. flock on .brain.lock
2. load AGENT_LEARNINGS.jsonl
3. cluster.py → recurring patterns
4. promote.py → write candidates to memory/candidates/
5. validate.py → heuristic prefilter (length + duplicate)
6. decay.py + archive.py → drop stale entries
7. write working/REVIEW_QUEUE.md summary
┐
│ (Slow: nightly cron)
┘
▼ manual /dream
list_candidates.py:
shows the queue, sorted by priority
┐
│ (Burst: when host agent reviews)
┘
▼ one decision per candidate
graduate.py <id> --rationale "..." OR reject.py <id> --reason "..."
│ │
▼ ▼
semantic/lessons.jsonl decisions.jsonl + candidate
↓ render_lessons.py marked status='rejected'
semantic/LESSONS.md
The boring parts (clustering, prefilter, decay) shouldn't depend on an LLM. Reasons:
- Cron-safe: no API keys, no network.
auto_dream.pyruns unattended without risking spurious calls or rate limits. - Deterministic: same input → same output. Test fixtures stay stable across runs.
- Low signal cost: clustering finds patterns; deciding whether they're good patterns is the hard part. Don't waste model capacity on the mechanical step.
graduate.py requires --rationale. reject.py requires --reason.
Without these, the protocol degrades: rubber-stamped accepts pollute
the lesson set, silent rejects lose context. Required rationale forces
the host agent to articulate the decision, which:
- Makes the decision auditable (you can read past rationales to understand why a lesson exists).
- Catches drift (if the rationale doesn't match the cluster's evidence, the rationale will give it away).
- Preserves history (rejected candidates retain their full decision log; recurring churn is visible).
~/.claude/commands/dream.md is the host-agent prompt for running a
review pass. The default flow:
- List pending candidates:
python3 ~/.agent/tools/list_candidates.py - For each, read the cluster context
- Decide graduate / reject / reopen with required text
- Verify the rendered
LESSONS.md
flock on ~/.agent/.brain.lock is held by:
auto_dream.pyfor the duration of its read-modify-write cycle onAGENT_LEARNINGS.jsonltools/sync.shfor the duration of itsgit add + commit + push
Two reasons:
- No torn writes: dream rewrites the JSONL non-atomically. A concurrent sync mid-rewrite would commit partial state.
- No double-counting: a tool-call appender that lands between
dream's load and rewrite would otherwise be silently truncated.
_episodic_io.pytakes the same lock for appends.
lessons.jsonl rows can carry three optional extension fields:
| Field | What it captures | Source |
|---|---|---|
why |
The reason behind the rule | **Why:** block in feedback markdown |
how_to_apply |
When/where the rule kicks in | **How to apply:** block |
original_markdown_path |
Path to long-form companion | migrate.py writes a verbatim copy |
_bullet_for in render_lessons.py emits these as italic sub-lines
when present. When absent, rows render as a normal one-line lesson.