Skip to content

Auto-Memory + Auto-Dream Layer, Pure Phoenix Phase 4.4

Doctrine: FORGE-DOCTRINE.md Section 12.

Layout

Path Role
forge/scripts/forge_memory_auto_capture.py Stop-hook fact extractor. Reads recent transcript, calls Sonnet 4.6, confidence-gates writes. Self-detaches so Stop hook returns immediately.
forge/scripts/forge_memory_auto_dream.py Nightly consolidation. Dedup, stale prune (90d), promote staged, orphan check. Operations are file moves only, never deletes.
forge/scripts/forge_memory_revert.py Reverse any session's auto-memory writes by session id. Reads LESSONS.md to find writes.
~/.claude/projects/-home-justinwieb-forge/memory/auto-proposed/ Staged candidates, medium confidence (0.65 to 0.85). Reviewed nightly by auto-dream.
~/.claude/projects/-home-justinwieb-forge/memory/_archive/auto-{merged,stale,reverted}-YYYY-MM-DD/ Where reversible files land.
forge/LESSONS.md Append-only audit log of all auto-memory writes and auto-dream operations. Source of truth for the revert tool.
forge/logs/auto-capture.log Per-session stdout.
forge/logs/auto-dream.log Cron stdout.

Wiring

  • Stop hook chain in forge/.claude/settings.local.json runs auto-checkpoint.sh then forge_memory_auto_capture.py (second hook detaches via Popen + start_new_session, so the chain returns instantly).
  • Cron 0 4 * * * forge_memory_auto_dream.py runs nightly, after the eval harness at 03:00 and the search index rebuild at 03:30.

Confidence Gate

Score Action
>= 0.85 Write directly to memory/<type>_<slug>.md. If file exists, append as "Auto-memory addendum" block.
0.65 to 0.85 Stage at memory/auto-proposed/<slug>-<timestamp>.md, await auto-dream review.
< 0.65 Drop, log to LESSONS.md only.

Hard cap: 5 writes per session.

Safety Rails

  1. Forbidden paths: ~/.forge-secrets/, ~/.ssh/, ~/.aws/, ~/.gnupg/. Validated in safe_path().
  2. Sensitive content patterns: OAuth tokens (sk-ant-, ghp_, JWT), private keys, AWS keys, SSN, credit cards, password=value pairs. Validated in looks_sensitive().
  3. Pre-redaction: transcript chunks scrubbed of sensitive matches BEFORE sending to Sonnet, so the model never sees them.
  4. No overwrite: existing canonical topic files get an "Auto-memory addendum" block appended, never overwritten.
  5. Append-only LESSONS.md: every write logs there with session id, slug, confidence, target path. The revert tool keys off these entries.
  6. Stale archive, not delete: auto-dream moves stale files to _archive/auto-stale-<date>/ so they can be unarchived.

Reverting a Session

forge_memory_revert.py --list                       # see reversible sessions
forge_memory_revert.py --session <id> --dry-run     # preview
forge_memory_revert.py --session <id>               # apply

The tool can revert both fresh-created topic files (archives them) and addendum blocks appended to existing files (strips the block). Direct writes go to _archive/reverted-<date>/.

Auto-Dream Passes

Pass What Trigger
A Semantic dedup across topic files. Sonnet flags duplicate pairs; merges only when confidence >= 0.85. Loser file is appended as "Historical" block on the winner, then archived. every night
B Stale prune. Topic files with mtime >= 90 days old AND no MEMORY.md reference move to _archive/auto-stale-<date>/. every night
C Promote staged. Each auto-proposed/<slug>-<ts>.md re-evaluated by Sonnet against current memory; promote when promote=true and confidence >= 0.85. every night
D Orphan index check. MEMORY.md links scanned; broken links logged to LESSONS.md for human cleanup. every night

Cost

  • Auto-capture: 1 Sonnet 4.6 call per session (10 to 30s, ~3k input tokens, modest).
  • Auto-dream: 1 dedup call + N promote calls per night (60 to 180s, larger but bounded).
  • Both intentionally use Sonnet not Opus to stay cheap.

Tuning

Constants near the top of each script: - RECENT_EXCHANGES = 30 (auto-capture transcript window) - WRITE_CAP = 5 (per-session max writes) - HIGH_CONFIDENCE = 0.85, MEDIUM_CONFIDENCE = 0.65 - STALE_DAYS = 90 (auto-dream stale threshold) - PROMOTE_THRESHOLD = 0.85, MERGE_THRESHOLD = 0.85

[Claude Code, Pure Phoenix Phase 4.4]