# peepshow-sink-mem0

<!-- gif:sink:mem0 -->
<p align="center">
  <img src="https://raw.githubusercontent.com/t0mtaylor/peepshow/main/docs/sink-gifs/mem0.gif" alt="peepshow → mem0 demo" width="720">
</p>
<!-- /gif:sink:mem0 -->


Write a peepshow run to [Mem0](https://mem0.ai) long-term memory. Each run
is stored as one system message (video summary) plus one user message per
extracted frame. Mem0 distils those into retrievable memories scoped to a
user (+ optional agent / app).

## Install

Ships built-in — the bin lands on PATH after `npm i -g peepshow`.

## Invocation

```bash
peepshow ./bug-repro.mov --sink mem0
```

## Configuration

| Env | Required | Default | Purpose |
|-----|----------|---------|---------|
| `MEM0_API_KEY` | ✓ | — | Mem0 cloud / self-hosted API key. |
| `MEM0_USER_ID` | ✓ | — | User the memory is written for. |
| `MEM0_API_URL` |   | `https://api.mem0.ai` | Override for self-hosted. |
| `MEM0_AGENT_ID`|   | (none) | Scope the memory to a specific agent. |
| `MEM0_APP_ID`  |   | (none) | Scope the memory to a specific app. |

## Exit codes

| Code | Meaning |
|------|---------|
| 0 | Memory accepted. |
| 2 | Missing `MEM0_API_KEY` / `MEM0_USER_ID`. |
| 4 | stdin malformed / empty. |
| 5 | Mem0 returned non-2xx. |

## Use with an LLM agent

Every peepshow sink is a zero-config extension point for any LLM CLI —
Claude Code, Cursor, Windsurf, Codex, Gemini, or any agent that can shell
out. The LLM doesn't need a plugin; it just needs `peepshow` on `PATH` and
the sink's env vars in the shell it runs under.

### 1. Set the environment

Add the sink's required env vars to your shell rc (`~/.zshrc`,
`~/.bashrc`, PowerShell profile) or a project-local `.env` that your
agent tooling loads. Example:

```sh
export MEM0_API_KEY="…"
export MEM0_USER_ID="your-value"
```

### 2. Register as an auto-sink

Auto-sinks fire on every `peepshow` run without per-invocation flags,
so the LLM doesn't have to remember a pipeline — the routing is
declarative:

```sh
peepshow sinks add mem0
# Optional: only fire for matching inputs
peepshow sinks add mem0 --when extension=mp4,mov
peepshow sinks add mem0 --when genre=tutorial
```

See [`peepshow sinks`](../../docs/PLUGINS.md) for the full matching
vocabulary.

### 3. An LLM session, end-to-end

> **You**: drop a `clip.mov` into Claude Code (or ask
> "what's in ~/bugs/crash.mov?")
>
> **Claude Code**: the `UserPromptSubmit` hook detects the video and
> auto-invokes `/peepshow:slides ~/bugs/crash.mov`. peepshow extracts
> frames + audio, transcribes locally if `whisper.cpp` is on `PATH`,
> then forwards the run to the `Mem0` sink.
>
> **`Mem0`**: writes a system summary plus one user message per frame into Mem0 so any agent on that user's memory can recall the clip.
>
> **Claude Code**: reads the frames back as images, combines them with
> the audio transcript, and writes a summary that references the
> downstream record.

### 4. What the sink sees

The sink receives the complete `--emit json` payload on stdin — not just
the frame paths. That includes:

- `video` — codec, duration, resolution, container tags (director / studio
  / title etc).
- `frames[]` — every extracted frame path + byte size.
- `audio` — `path`, `durationSeconds`, codec, loudness peak, silence
  ratio.
- `audio.transcript` — `segments[]` with timestamps, full `text`,
  language — populated when transcription is enabled (v0.4.0+).
- `extraction` — strategy, thresholds, ffmpeg path used.

> **Transcript handling**: the transcript text is a natural embedding target — indexed alongside the frames so later retrieval covers spoken content too.
