# Set up RewindRewind with an AI agent

RewindRewind captures back-end and front-end exceptions, custom product events, and
customer support requests.
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://www.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://www.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 public GitHub source without installing it:
```
npx github:rewind-rewind/rewindrewindcli configure --api-key rr_xxx --base-url http://www.rewindrewind.com
npx github:rewind-rewind/rewindrewindcli init            # finds the project and fetches its public key
```
No project yet? `npx github:rewind-rewind/rewindrewindcli projects create --name "My App"`
Using it often? Install it once with `npm install -g github:rewind-rewind/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`). Keep it current with `rewindrewind update --yes`.
Prefer raw HTTP? Send `Authorization: Bearer rr_xxx` to http://www.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]); }; });
      r._earlyErrorHandler = r._earlyErrorHandler || function (e) {
        r.captureException(e.error || e.message, { filename: e.filename, line: e.lineno, column: e.colno });
      };
      r._earlyRejectionHandler = r._earlyRejectionHandler || function (e) {
        if (e.reason instanceof Error || (typeof e.reason === "string" && e.reason.length))
          r.captureException(e.reason, { source: "unhandledrejection" });
      };
      r._earlyOnError = r._earlyOnError || function (msg, src, ln, col, err) {
        r.captureException(err || msg, { filename: src, line: ln, column: col });
        return r._priorOnError ? r._priorOnError.apply(this, arguments) : undefined;
      };
      if (!r._loading) {
        r._loading = 1;
        w.addEventListener("error", r._earlyErrorHandler);
        w.addEventListener("unhandledrejection", r._earlyRejectionHandler);
        r._priorOnError = w.onerror;
        w.onerror = r._earlyOnError;
        var s = d.createElement("script"); s.async = 1; s.crossOrigin = "anonymous"; s.src = "http://www.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.
  Auto-capture covers dispatched `error` events, direct `window.onerror` reports
  (how Stimulus/Vue/jQuery report exceptions they caught themselves), and unhandled
  promise rejections. Any existing `window.onerror` handler — Sentry's included —
  is chained, not replaced.
- Back-end exceptions: send with the public key, or `npx github:rewind-rewind/rewindrewindcli exceptions send …`
- App events: `rewind.captureEvent("checkout.completed", { total: 42 })`
  or `npx github:rewind-rewind/rewindrewindcli events send --type checkout.completed --properties '{"total":42}'`

## 4. Verify
```
npx github:rewind-rewind/rewindrewindcli verify
```

## 5. Optional: the support form
The same public key also takes customer support requests, which never count as a
signal. Mount the hosted form with one tag, or POST to `http://www.rewindrewind.com/v1/support`:
```html
<script src="http://www.rewindrewind.com/support/widget.js" data-project-key="rrpub_xxx"
  data-identity-id="YOUR_APP_USER_ID"></script>
```
Requests land in the project's Support inbox; the whole inbox (read, reply, note,
assign, resolve) is in the management API under `/api/projects/:id/support`.
Use `npx github:rewind-rewind/rewindrewindcli help support` for the concise CLI workflow.
Overview: http://www.rewindrewind.com/auto-support

## 6. Optional: invite the rest of the team
Members are either `admin` (account settings, billing, API keys, members) or
`member` (projects and issues). Invite and track from the CLI:
```
npx github:rewind-rewind/rewindrewindcli members invite --email teammate@example.com --role member
npx github:rewind-rewind/rewindrewindcli invites list --status pending
```
An invited email that already has a RewindRewind user joins immediately; a new one
joins when it uses the emailed link, which expires in 24 hours. Resend or revoke
with `npx github:rewind-rewind/rewindrewindcli invites resend <id>` and `npx github:rewind-rewind/rewindrewindcli invites revoke <id>`.

## 7. Explore operations
The CLI help directory is the shortest current reference for people and agents:
`help visits`, `help support`, `help health`, `help metrics`, `help noise`,
`help notifications`, `help members`, and `help sourcemaps`. Each topic gives
copy-paste commands; add `--json` for structured output.

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