# sonor-setup

Set up, verify and migrate a Next.js site on [Sonor](https://sonor.io), for
[`@sonordev/site-kit`](https://www.npmjs.com/package/@sonordev/site-kit).

```bash
npx sonor-setup init            # SiteKitLayout in app/layout.tsx, SONOR_API_KEY in .env.local
npx sonor-setup scaffold        # sitemap, robots, llms.txt, live updates, proxy, OG card
npx sonor-setup verify          # exit 0 means the integration is done
npx sonor-setup codemod --write # move an older site to the current site-kit
npx sonor-setup mcp             # give agents the site's tools (MCP endpoint, card, relay)
```

`codemod --write` takes a 2.x-6.x site to site-kit 7 in one pass: root
imports to their module, old paths to their 7.x homes, `middleware.ts` to
`proxy.ts`, and `sonor-setup` into devDependencies where scripts run it.
Anything it can't rewrite safely it flags with the fix.

- **The proxy lands where Next reads it:** `src/proxy.ts` when the app is
  `src/app`, `proxy.ts` otherwise. Next ignores a proxy anywhere else
  without a word, so the codemod also moves one an earlier run left at the
  root, and `doctor` warns about it.
- **Nothing extra in the project.** Originals of the files it writes go to a
  folder in your OS temp directory, and it prints where (`--no-backup` skips
  them). It never creates or edits `.env.example`: `.env.local` is the one
  env file.
- **Old fallbacks collapse:**
  `process.env.SONOR_API_KEY || process.env.UPTRADE_API_KEY` becomes
  `process.env.SONOR_API_KEY`.

`scaffold` writes the live-updates route, `app/api/seo-revalidate/route.ts`.
On a site with articles it passes the publication's path,
`createRevalidateRoute({ publicationBasePath: '/insights' })`, read from the
app directory. When more than one folder looks like the publication, it
writes the one-line route and lists them. `doctor` checks for the same form.

Every command takes `--json` and answers with one envelope (`ok`, `status`,
`exitCode`, `checks`, `nextSteps`), exit codes included, so coding agents can
run it without parsing prose. `npx sonor-setup manifest --json` prints
site-kit's agent manifest: the site's installed copy, or the one this package
ships for a site that hasn't installed site-kit yet.

## Versions

sonor-setup's major matches the site-kit major it sets up: 7 sets up
site-kit 7. It reads the site's installed site-kit version itself, and
reports both (`siteKitVersion`, `setupVersion`) in every `--json` envelope.

## Where it lives

This package was part of `@sonordev/site-kit` until 7.0. Its source is in
the site-kit repo under `packages/sonor-setup`, built from there (it shares
site-kit's sitemap discovery, OG template and Next.js file rules, compiled
from the same source, so the two can't disagree).

```bash
# from the site-kit repo root
pnpm build:setup
pnpm test:setup
```
