The Dream Cycle
Inspired by Dreamfinder's dream cycle implementation.
When a team member says "goodnight" (or "good night", "sweet dreams", etc.), Gremlin enters a multi-phase autonomous agent session modelled after real sleep stages:
Light (N1→N2) → Deep (N2→N3) → Branch per spark (parallel) → REM (converge) → Wake
Phases
Light Sleep — Review the day's chat history since the last dream cycle. File obvious items: decisions → Outline, action items → Kan cards. Emit a depth signal ([WAKE] if nothing worth going deeper for, [CONTINUE] otherwise).
Deep Sleep — Search existing Outline docs and Kan cards for connections to what surfaced in Light Sleep. Surface [SPARK] tags — interesting threads worth exploring in parallel branches.
Dream Branching — Each [SPARK] becomes a parallel agent thread running simultaneously. Each branch explores its spark fully and returns a report.
REM Convergence — A final agent pass reads all branch reports, finds meta-patterns, and synthesises a dream report.
Waking Message — Gremlin composes an in-character "waking up" message for the group summarising what it did, with dream stats (phases, branches, tool calls, tokens).
Adaptive depth
- If Light Sleep signals
[WAKE], skip all deeper phases (quiet day = shallow sleep)
- If Deep Sleep finds no sparks, skip branching and REM
- Prevent concurrent cycles (one dream per night per chat)
- Track last completed cycle timestamp to know what chat history to replay
DB additions needed
dream_cycles table: id, chat_id, date, status (running/completed/failed), started_at, completed_at, error_message
- Prevent duplicate cycles per chat per date
Goodnight detection
Regex matching: goodnight, good night, g'night, gnight, nighty night, sleep well, sweet dreams (case-insensitive)
Why this is good
Right now Gremlin has a 10-message sliding window and forgets everything after 30 minutes. The dream cycle means nothing important gets lost — it's all filed autonomously while the team sleeps.
Reference implementation: lib/src/dream/dream_cycle.dart in Dreamfinder (Dart). Architecture is identical, just needs porting to TypeScript.
The Dream Cycle
Inspired by Dreamfinder's dream cycle implementation.
When a team member says "goodnight" (or "good night", "sweet dreams", etc.), Gremlin enters a multi-phase autonomous agent session modelled after real sleep stages:
Phases
Light Sleep — Review the day's chat history since the last dream cycle. File obvious items: decisions → Outline, action items → Kan cards. Emit a depth signal (
[WAKE]if nothing worth going deeper for,[CONTINUE]otherwise).Deep Sleep — Search existing Outline docs and Kan cards for connections to what surfaced in Light Sleep. Surface
[SPARK]tags — interesting threads worth exploring in parallel branches.Dream Branching — Each
[SPARK]becomes a parallel agent thread running simultaneously. Each branch explores its spark fully and returns a report.REM Convergence — A final agent pass reads all branch reports, finds meta-patterns, and synthesises a dream report.
Waking Message — Gremlin composes an in-character "waking up" message for the group summarising what it did, with dream stats (phases, branches, tool calls, tokens).
Adaptive depth
[WAKE], skip all deeper phases (quiet day = shallow sleep)DB additions needed
dream_cyclestable: id, chat_id, date, status (running/completed/failed), started_at, completed_at, error_messageGoodnight detection
Regex matching:
goodnight,good night,g'night,gnight,nighty night,sleep well,sweet dreams(case-insensitive)Why this is good
Right now Gremlin has a 10-message sliding window and forgets everything after 30 minutes. The dream cycle means nothing important gets lost — it's all filed autonomously while the team sleeps.
Reference implementation:
lib/src/dream/dream_cycle.dartin Dreamfinder (Dart). Architecture is identical, just needs porting to TypeScript.