# peepshow-sink-s3

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


Uploads every frame plus a `metadata.json` to an S3-compatible bucket. Works with any provider that speaks the S3 API — AWS, MinIO, Cloudflare R2, Google Cloud Storage (S3-compat layer), DigitalOcean Spaces, Backblaze B2, Wasabi, iDrive e2, Scaleway, Linode, Oracle OCI, IBM COS.

## Install

```bash
npm install @aws-sdk/client-s3
```

## Config

| Env var | Required | Default | Purpose |
| :------ | :------- | :------ | :------ |
| `S3_BUCKET` | yes | — | target bucket name |
| `S3_ACCESS_KEY` | yes | — | access key / user |
| `S3_SECRET_KEY` | yes | — | secret key |
| `S3_REGION` | no | `us-east-1` | region name |
| `S3_ENDPOINT` | no | AWS default | full URL for non-AWS providers |
| `S3_PREFIX` | no | `peepshow/` | key prefix for every upload |
| `S3_FORCE_PATH` | no | `0` | set `1` for MinIO / R2 / path-style endpoints |

## Provider cheatsheet

| Provider | `S3_ENDPOINT` | `S3_FORCE_PATH` |
| :------- | :------------ | :-------------- |
| AWS S3 | *(unset)* | `0` |
| MinIO | `http://localhost:9000` | `1` |
| Cloudflare R2 | `https://<acct>.r2.cloudflarestorage.com` | `1` |
| DigitalOcean Spaces | `https://nyc3.digitaloceanspaces.com` | `0` |
| Backblaze B2 | `https://s3.<region>.backblazeb2.com` | `0` |
| Wasabi | `https://s3.<region>.wasabisys.com` | `0` |
| Linode Object Storage | `https://<region>.linodeobjects.com` | `0` |
| Google Cloud Storage (S3 compat) | `https://storage.googleapis.com` | `1` |

## Use

```bash
export S3_BUCKET=peepshow-archive
export S3_ACCESS_KEY=AKIAxxx
export S3_SECRET_KEY=...
export S3_ENDPOINT=https://nyc3.digitaloceanspaces.com
peepshow sinks add s3
peepshow ./video.mp4
```

## Layout in bucket

```
<S3_PREFIX>/<YYYYMMDD-HHMMSS>-<strategy>/
    frame_0001.jpg
    frame_0002.jpg
    ...
    metadata.json
```

## Caveats

- Frames are uploaded as `ContentType` inferred from extension (jpg/png/webp).
- No server-side lifecycle config — configure bucket retention at the provider level.
- For GCS, use the native `@google-cloud/storage` sink (roadmap) when you need workload identity.

## 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 S3_BUCKET="your-value"
export S3_ACCESS_KEY="…"
export S3_SECRET_KEY="…"
```

### 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 s3
# Optional: only fire for matching inputs
peepshow sinks add s3 --when extension=mp4,mov
peepshow sinks add s3 --when retention=long
```

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 `S3-compatible storage` sink.
>
> **`S3-compatible storage`**: uploads every extracted frame to an S3-compatible bucket under a deterministic `runs/{id}/` prefix for durable cold storage.
>
> **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 full transcript JSON is saved next to the frames in the per-run manifest.
