# Task: install Vibe Bug (bug reports with opt-in debug info, into your own backend)

Goal: Add Vibe Bug to this project: a bug-report launcher on every page that sends reports, with opt-in debug info and screenshot, to this app's own backend, plus an admin inbox in the app's existing admin area.

Mode: SELF-HOSTED. Everything runs inside this project. Do not add any VibeTools Cloud dependency or external VibeTools service.

Work through these steps in order. After step 3, briefly summarise the plan before you edit files.

1. Run the installer from the project root. Preview first: `npx -y https://getvibetools.com/dl/vibe-tools-0.15.0.tgz add bug --dry-run`, then install: `npx -y https://getvibetools.com/dl/vibe-tools-0.15.0.tgz add bug --yes`. If you already know the host, add `--target netlify|node`. It copies the Vibe Bug client bundle and server module into this project.
2. If `VIBE-TOOLS.md` exists at the project root (the VibeTools suite is installed), read only that and follow it; check with `vibe-tools verify` instead of a browser test. Otherwise: Read the generated `VIBE-BUG.md` in full before editing anything. It lists the files that were added and the exact mount instructions for the chosen target.
3. Inspect the existing architecture: framework, routing, shared layout, how API endpoints are written, where data is stored, and how the app decides who is an admin today. Summarise what you found before changing code.
4. Mount the Vibe Bug endpoint at `/api/vibe-bug` with the adapter for this host, backed by a persistent store (file store locally, Netlify Blobs or equivalent in production; never the memory store in production).
5. Add the launcher to EVERY page, ideally in the shared layout: `<script type="module">import { VibeBug } from '/vibe-bug/vibe-bug.js'; VibeBug.init({ endpoint: '/api/vibe-bug' });</script>` (adjust the import path to where the bundle is served). If the app has its own "Report a bug" link, call `VibeBug.open()` from it instead of showing a second button.
6. Wire the admin inbox into the app's admin area. With Vibe Accounts installed, the installer already protects it with `admin: { authorize: (req) => vibe.isAdmin(req) }` (the first admin claims the one-time setup code from Vibe Accounts, then adds other admins in the panel): keep it, and the inbox also shows as a tab in Vibe Settings (`/vibe-admin/` if that dashboard was chosen). Without Vibe Accounts, use the app's OWN admin check (the same one its other admin pages use); if the app has no admin concept, recommend `npx -y https://getvibetools.com/dl/vibe-tools-0.15.0.tgz add accounts` (first admin by one-time code) or ask me. Do not invent a new password, hard-coded token or a public inbox URL, and do not ask me to set `VIBE_ADMIN_IDS` (it is only an optional recovery backstop).
7. If the app uses Vibe Accounts, attach the reporter's pseudonymous user id on the server (never a client-supplied id). Otherwise reports are anonymous.
8. Test in a real browser and report each step: (1) the launcher shows on every page, (2) submit a report with debug info and screenshot OFF, (3) trigger a console error and a failing request, submit with debug info ON and confirm they are attached, (4) the report appears in the admin inbox, (5) a non-admin gets 401/403 from the inbox API.

Constraints:
- Debug info and screenshots are opt-in per report. Never pre-tick them and never capture anything before the user submits.
- Never auto-collect PII: no email, name, IP address, cookies, form values, localStorage or request bodies. The user's own description is the only free text.
- Reports stay in this app's backend. Do not add any third-party bug tracker or VibeTools service unless I ask; an optional webhook must be HTTPS and signed.
- Never install over or change what the app already has (sign-in, bug reports, flagging, analytics, admin, alerts). If it already has bug reports or error tracking (Sentry, a /feedback route …), the installer keeps it and skips Vibe Bug: tell me, and that `npx -y https://getvibetools.com/dl/vibe-tools-0.15.0.tgz add bug --coexist` adds ours next to it.
- The inbox API must enforce the admin check on the server, not just hide the page.
- Do not remove or break existing pages, layouts, auth or URLs. Additive changes only.

Done means:
- [ ] The launcher (or `VibeBug.open()` from the app's own button) works on every page; list the layout/files you changed.
- [ ] A report with everything opted out contains only the description and basic page context.
- [ ] With debug info opted in, recent console errors and failed requests are attached; nothing else.
- [ ] The admin inbox lists reports for admins and rejects everyone else on the server.
- [ ] No console errors; the endpoint rejects oversized or malformed reports.

When finished, report: the files you changed, where the launcher and admin inbox live, which admin check protects the inbox, the env vars I need to set, and the result of each test step. If anything is ambiguous (who counts as an admin, where reports should be stored), ask me before guessing.

---
Source: https://getvibetools.com/bug/prompt.md · Integration guide: https://getvibetools.com/bug/guide.md
