# V. Mirror Mode

![Mirror](/files/08E9DgyXvQoxcAuIHtpQ)

Mirror Mode is the rite that makes MIRARI *self-improving*. You hand it a pile of recent logs; it hands you back a structured judgment of how your agent is doing and a redraft of its system prompt.

## The four columns of a report

```
┌──────────────┬──────────────┬───────────────────┬────────────────────┐
│  Strengths   │  Weaknesses  │  Recommendations  │  Suggested prompt  │
├──────────────┼──────────────┼───────────────────┼────────────────────┤
│ Tight code   │ Hedges on    │ Add "answer first,│ "You are Hermes.   │
│ examples     │ specifics    │ caveat second"    │  Lead with the     │
│              │              │                   │  decision, then…"  │
│ Good Tailwind│ Forgets user │ Auto-inject CF    │                    │
│ token use    │ on CF Workers│ memory node       │                    │
└──────────────┴──────────────┴───────────────────┴────────────────────┘
```

## How it runs

The page calls the `analyzeMirror` server fn:

```ts
const analyze = useServerFn(analyzeMirror);

const report = await analyze({
  data: {
    title: "Week of 06-01 retro",
    logs,                // pasted text or imported transcripts
    connectionId,        // which Hermes Agent's behavior we're reflecting on
  },
});
```

Server-side, the handler:

1. Loads the connection's current system prompt + active promoted skills.
2. Sends the logs + that context to a reasoning model (the bound Hermes Agent itself by default).
3. Forces structured output:

   ```ts
   {
     strengths: string[],
     weaknesses: string[],
     recommendations: string[],
     suggested_prompt: string,
   }
   ```
4. Inserts a row in `mirror_reports`.

## Acting on a report

Every report has three actions:

* **Adopt prompt** — promote `suggested_prompt` to the connection's system prompt. The old one is archived.
* **Forge skills from recommendations** — one-click sends each recommendation through `suggestSkill`.
* **Promote facts to memory** — pluck any insight into the Memory Atlas.

## Live Mirror (v2.1)

Mirror Mode is no longer batch-only. **Live Mirror** runs as a daemon on top of your recent turns and surfaces structured signals as they happen.

### Signals

Each signal is a typed row in `mirror_signals`, scoped per user via RLS and streamed to the UI through Supabase realtime.

| Kind            | Glyph | Meaning                                                       |
| --------------- | ----- | ------------------------------------------------------------- |
| `drift`         | ≈     | Agent wanders off-topic, repeats itself, loses thread.        |
| `contradiction` | ⚔     | Agent contradicts an earlier statement or stored memory.      |
| `skill_misfire` | ✗     | A skill or format is applied poorly or in the wrong context.  |
| `focus_hit`     | ◉     | Content matches one of the operator's pinned focus questions. |
| `judge_score`   | ☉     | Holistic rating of the latest assistant turn.                 |

Every signal carries `severity` (1–5), a one-line `summary`, and an optional `payload` JSONB for citations.

### Focus pins

The `mirror_focus_pins` table lets you pin questions the Mirror should watch for on every scan — e.g. *"flag hallucinated citations"*, *"warn when the agent forgets the user is on Cloudflare Workers"*. Active pins are injected into the judge prompt; matches come back as `focus_hit` signals.

### Pulse meter

The Live Mirror panel shows a rolling count of signals in the last hour and an average severity. The panel glows harder as severity climbs, giving you an at-a-glance read of the oracle's current state.

### Promoting a signal

Any live signal can be promoted into a formal `mirror_reports` row in one click. The `promoteSignal` server fn pulls the surrounding transcript and runs the same structured analysis pass as a manual reflection, then back-links the report to the signal via `promoted_report_id`.

### Console Pulse widget

The Console sidebar carries a **Mirror Pulse** widget that subscribes to the same realtime channel. You watch the Mirror watch the Oracle while you talk to it.

### Server-side shape

```ts
// Manually trigger a scan over a window
const scan = useServerFn(scanLiveSignals);
await scan({ data: { windowMinutes: 1440, maxMessages: 40 } });

// Promote a flagged signal into a sealed reflection
const promote = useServerFn(promoteSignal);
const { reportId } = await promote({ data: { signalId } });
```

The judge model runs through the Lovable AI Gateway with `LOVABLE_API_KEY` server-side — no per-user key needed for live scans.

## Why it works

The Mirror loop is the only thing in MIRARI that does *gradient descent on the agent itself*. Memory and Skills are levers; Mirror Mode is the feedback. Without it, an agent's prompt only changes when *you* think to change it. With it, the agent participates in its own iteration. Live Mirror closes the latency: you no longer have to remember to reflect.


---

# 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/mirror-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.
