# Set up RewindRewind with an AI agent

RewindRewind captures back-end and front-end exceptions plus custom product events.
This guide is self-contained; follow it top to bottom. Never invent an API key.

## 1. Make sure there is an account and an admin key
Ask the user for their RewindRewind admin key (it starts with `rr_`).

If they do not have an account yet:
1. Ask the user for their email address.
2. Create the account (this emails them a sign-in link):
   ```
   curl -X POST http://rewindrewind.com/agents/signup -H 'content-type: application/json' -d '{"email":"USER_EMAIL"}'
   ```
3. Tell the user: open your inbox and click the RewindRewind sign-in link.
4. Then have them mint an admin key: go to http://rewindrewind.com/organization/keys, click
   "New key", copy the `rr_…` secret (shown only once), and paste it back to me.

## 2. Configure the CLI (or call the API directly)
Run the CLI straight from the public repo, no install needed:
```
npx github:bananatron/rewindrewindcli configure --api-key rr_xxx --base-url http://rewindrewind.com
npx github:bananatron/rewindrewindcli init            # finds the project and fetches its public key
```
No project yet? `npx github:bananatron/rewindrewindcli projects create --name "My App"`
Using it often? Install it once with `npm install -g github:bananatron/rewindrewindcli` for a persistent `rewindrewind` (alias `rr`) command, and set long-term auth so you never pass the key again: `rewindrewind config set api-key-file /path/to/key` (or export `REWINDREWIND_API_KEY`).
Prefer raw HTTP? Send `Authorization: Bearer rr_xxx` to http://rewindrewind.com/api/* (see OpenAPI below).

## 3. Wire the three surfaces
- Front-end exceptions: add one `<script>` to your `<head>` (order-independent; safe to re-run on SPA / Hotwire-Turbo navigations):
  ```html
  <script>
    (function (w, d) {
      var r = (w.RewindRewind = w.RewindRewind || { _q: [] });
      ["init","captureException","captureEvent","captureMessage","addBreadcrumb","setIdentity","setTags","setContext","flush"]
        .forEach(function (m) { r[m] = r[m] || function () { (r._q = r._q || []).push([m, arguments]); }; });
      if (!r._loading) { r._loading = 1; var s = d.createElement("script"); s.async = 1; s.src = "http://rewindrewind.com/sdk/v1/rewind.js"; d.head.appendChild(s); }
    })(window, document);
    RewindRewind.init({ key: "rrpub_xxx", environment: "production" });
  </script>
  ```
  The public key (`rrpub_xxx`) is safe to embed, like a Sentry DSN.
- Back-end exceptions: send with the public key, or `npx github:bananatron/rewindrewindcli exceptions send …`
- App events: `rewind.captureEvent("checkout.completed", { total: 42 })`
  or `npx github:bananatron/rewindrewindcli events send --type checkout.completed --properties '{"total":42}'`

## 4. Verify
```
npx github:bananatron/rewindrewindcli verify
```

## Reference
- Full SDK docs: http://rewindrewind.com/docs/exception-capture-sdk
- OpenAPI (every endpoint): http://rewindrewind.com/openapi.json
- All CLI commands: `npx github:bananatron/rewindrewindcli --help`
