> For the complete documentation index, see [llms.txt](https://entermirari.gitbook.io/entermirari-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://entermirari.gitbook.io/entermirari-docs/the-six-rites/dream-mode.md).

# VII. Dream Mode

When the agent sleeps, it dreams.

Most agent tooling is purely reactive — it only thinks when a user prompts it. Dream Mode is MIRARI's unconscious: a process that runs while no one is watching, surfacing failure modes, contradictions, and proposals the agent would never discover from inside a normal turn.

## The three dream modes

```
┌─────────────────┬─────────────────────────────────────────────┐
│  Stress Test    │  Adversarial trials against the agent's     │
│                 │  registered skills. Discovers failure modes.│
├─────────────────┼─────────────────────────────────────────────┤
│  Replay         │  Re-imagines recent real conversations.     │
│                 │  "What would I say differently now?"        │
├─────────────────┼─────────────────────────────────────────────┤
│  Consolidate    │  Sorts memory. Surfaces contradictions,     │
│                 │  redundancies, and weak nodes worth         │
│                 │  strengthening.                             │
└─────────────────┴─────────────────────────────────────────────┘
```

Each dream produces a **dream session** with a short summary and 3–6 **findings**, each tagged as `weakness`, `insight`, `contradiction`, or `proposal`, and ranked `low` / `medium` / `high` severity.

## The three triggers

Dream Mode can fire in three ways, set per-user in **Settings → Dream Mode**:

1. **Manual** — click "Enter Dream" on the Dream Journal. Always available.
2. **Idle** — after *N* minutes of no Console activity, the agent dreams automatically. The hook lives on the Console page; any mouse, keyboard, scroll, or click resets the timer.
3. **Scheduled** — pick a UTC hour (0–23). A `pg_cron` job pings `/api/public/hooks/dream-cycle` every hour, and any user whose `dream_schedule_hour` matches the current hour gets a consolidation dream.

## How a dream runs

```ts
const fire = useServerFn(runDream);

const result = await fire({
  data: { mode: "stress_test", trigger: "manual" }
});
// → { ok: true, session_id, count: 5 }
```

Server-side, `runDream`:

1. Inserts a `dream_sessions` row with `status='running'`.
2. Gathers context based on mode — skills for `stress_test`, recent conversations and messages for `replay`, memory nodes for `consolidate`.
3. Sends the context to Lovable AI with a mode-specific system prompt asking for STRICT JSON: `{ summary, findings[] }`.
4. Persists findings into `dream_findings` with foreign-key cascade on the session.
5. Marks the session `complete` (or `failed` with the error message).

Everything is RLS-scoped to `auth.uid()` — your dreams are yours.

## The Dream Journal

The `/dreams` route is the visible surface: three big mode cards on top, a timeline of past sessions below. Each session card shows:

* mode · trigger · status badges
* the summary in italics
* the findings as a bullet list, each with its kind glyph (`▼` weakness, `✦` insight, `⚡` contradiction, `→` proposal) and severity badge

The list polls every five seconds so a long-running dream populates in front of you.

## Why this matters

Static agents drift. They forget edge cases, accumulate contradictory memory nodes, and never test their own skills until the user happens to trigger a regression. Dream Mode flips that — the agent does the work of finding its own blind spots, on its own schedule, and presents them to you as a reviewable log rather than a silent decay.

It is the closest thing MIRARI has to *sleeping on a problem*.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://entermirari.gitbook.io/entermirari-docs/the-six-rites/dream-mode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
