agentlink-sh 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,485 @@
1
+ # agentlink
2
+
3
+ Teach AI agents the right way to build on Supabase.
4
+
5
+ [Agent Link](https://agentlink.sh) is an opinionated skill set for Claude Code — and this CLI is how you start a project with it. One command scaffolds a Supabase backend with schema isolation, RPC-first data access, row-level security, multi-tenancy, and edge functions already wired up — plus a frontend (React + Vite or Next.js) with auth, theming, and shadcn/ui ready to go. Your agent doesn't have to figure out the architecture — it's already there. From that foundation, five domain skills give it one clear path for every decision: how to structure tables, write RLS policies, expose APIs, handle background work, and connect a frontend. No ambiguity, no wrong turns. First-try results.
6
+
7
+ ## Install & Run
8
+
9
+ ### macOS
10
+
11
+ ```bash
12
+ curl -fsSL https://agentlink.sh/install | sh
13
+ ```
14
+
15
+ ### Linux
16
+
17
+ ```bash
18
+ wget -qO- https://agentlink.sh/install | sh
19
+ ```
20
+
21
+ ### Windows (PowerShell)
22
+
23
+ ```powershell
24
+ irm https://agentlink.sh/install.ps1 | iex
25
+ ```
26
+
27
+ ### npx (any platform with Node.js 18+)
28
+
29
+ ```bash
30
+ npx agentlink-sh@latest
31
+ ```
32
+
33
+ Or run directly with npx (requires Node.js 18+):
34
+
35
+ ```bash
36
+ npx agentlink-sh@latest
37
+ ```
38
+
39
+ The install scripts automatically detect your OS, install Node.js if needed, and set up the CLI globally.
40
+
41
+ ## Quick start
42
+
43
+ ```bash
44
+ # Create a new project (cloud by default)
45
+ agentlink my-app
46
+
47
+ # With a prompt for Claude Code
48
+ agentlink my-app --prompt "Build a project management tool with kanban boards"
49
+
50
+ # Interactive wizard
51
+ agentlink
52
+ ```
53
+
54
+ ## Commands
55
+
56
+ ### `agentlink [name]`
57
+
58
+ Interactive wizard that scaffolds a new project or updates an existing one. Uses Supabase Cloud by default — region is auto-detected from your timezone, all recommended skills are installed automatically.
59
+
60
+ ```bash
61
+ # Interactive wizard
62
+ agentlink
63
+
64
+ # With project name
65
+ agentlink my-app
66
+
67
+ # With prompt (passed to Claude Code on launch)
68
+ agentlink my-app --prompt "Build a project management tool"
69
+
70
+ # Local Docker mode (instead of cloud)
71
+ agentlink my-app --local
72
+
73
+ # NextJS instead of React + Vite
74
+ agentlink my-app --nextjs
75
+
76
+ # Backend only (no frontend)
77
+ agentlink my-app --no-frontend
78
+
79
+ # Skip companion skills
80
+ agentlink my-app --no-skills
81
+
82
+ # Scaffold files only — no Supabase setup. Run `env add dev` later in a
83
+ # terminal to finish the env. Use when an agent scaffolds without browser
84
+ # access and hands off to the user.
85
+ agentlink my-app --skip-env
86
+
87
+ # Non-interactive (CI-friendly)
88
+ agentlink my-app --yes --non-interactive --token $SUPABASE_TOKEN --org $ORG_ID --region us-east-1
89
+ ```
90
+
91
+ **Options:**
92
+
93
+ | Flag | Description |
94
+ | ------------------- | ------------------------------------------------------------------------------------- |
95
+ | `--debug` | Write debug log to `agentlink-debug.log` |
96
+ | `--force-update` | Force update even if project is up to date |
97
+ | `--no-frontend` | Skip frontend scaffolding (backend only) |
98
+ | `--nextjs` | Use NextJS instead of React + Vite |
99
+ | `--local` | Use local Docker instead of Supabase Cloud |
100
+ | `--skip-env` | Scaffold files without touching Supabase (no OAuth, no project, no Docker, no apply) |
101
+ | `--no-skills` | Skip companion skill installation |
102
+ | `--no-launch` | Skip launching Claude Code after scaffold |
103
+ | `-y, --yes` | Auto-confirm all prompts |
104
+ | `--token <token>` | Supabase access token (skips interactive login) |
105
+ | `--org <id>` | Supabase organization ID |
106
+ | `--region <region>` | Supabase Cloud region (auto-detected if omitted) |
107
+ | `--prompt <prompt>` | Alternative to positional prompt argument |
108
+ | `--resume` | Resume a previously failed scaffold |
109
+ | `--non-interactive` | Error instead of prompting when info is missing |
110
+ | `--link` | Link to an existing Supabase project (with `--project-ref` + connection flags) |
111
+
112
+ ### `agentlink sb login`
113
+
114
+ Authenticate with Supabase via OAuth (opens browser). Tokens are cached per-org in `~/.config/agentlink/credentials.json` and auto-refreshed.
115
+
116
+ ```bash
117
+ agentlink sb login
118
+ ```
119
+
120
+ > The top-level `agentlink login` / `agentlink token` commands still work but print a deprecation warning. The top-level `login` namespace is reserved for future Agent Link accounts.
121
+
122
+ ### `agentlink sb token`
123
+
124
+ Show or set the Supabase personal access token (PAT) used for non-interactive CI/CD.
125
+
126
+ ```bash
127
+ agentlink sb token show # Print the current token and its source
128
+ agentlink sb token set sbp_... # Save a new token
129
+ ```
130
+
131
+ ### `agentlink env`
132
+
133
+ Manage project environments. Agent Link enforces a fixed `local → dev → prod` model — no custom names (`staging`, `dev2`, etc. are rejected).
134
+
135
+ #### `env add [name]`
136
+
137
+ Add a cloud environment and (by default) deploy the current schema + functions to it. If `[name]` is omitted, a picker shows `dev` / `prod` with a `— linked to <projectRef>` / `— not linked` hint per row.
138
+
139
+ ```bash
140
+ agentlink env add # Interactive picker
141
+ agentlink env add dev # Connect the dev cloud environment
142
+ agentlink env add prod # Connect production. Does NOT touch .env.local.
143
+ agentlink env add dev --no-deploy # Register the env but skip the initial deploy
144
+ agentlink env add dev --setup-ci # Also scaffold a GitHub Actions workflow
145
+ ```
146
+
147
+ If the environment already exists, `env add` prompts with a 3-way menu:
148
+
149
+ ```
150
+ If you just changed schemas or functions, cancel and run `agentlink env deploy <name>` instead.
151
+
152
+ ? Environment "dev" already exists. What would you like to do?
153
+ ❯ Re-apply full setup — schemas, functions, secrets, PostgREST + auth config
154
+ Relink to a different Supabase project
155
+ Cancel
156
+ ```
157
+
158
+ `Re-apply full setup` re-runs the full bootstrap (schemas + functions + vault + PostgREST + auth + verify). Use it when auth providers, PostgREST config, or vault secrets changed — otherwise prefer `env deploy` (lighter, idempotent).
159
+
160
+ #### `env use [name]`
161
+
162
+ Switch the active environment. Rewrites the managed block in `.env.local` and updates `manifest.cloud.default`. If `[name]` is omitted, a picker lists `dev` / `prod` (and `local` when the project is local-only or already on local) with a ✓ next to the active env.
163
+
164
+ ```bash
165
+ agentlink env use # Interactive picker
166
+ agentlink env use dev # Switch to dev
167
+ agentlink env use local # Switch to local Docker
168
+ agentlink env use prod # Switch to prod (requires y/N confirmation)
169
+ ```
170
+
171
+ `env use prod` prints an amber warning and requires explicit confirmation before writing `.env.local` — any app or test you run locally will hit production data. After confirming, subsequent `env deploy` / `db apply` / `db sql` / `db rebuild` invocations print an `▲ Active env: prod` banner as a reminder.
172
+
173
+ #### `env deploy [name]`
174
+
175
+ Apply schemas (`db apply`) and deploy edge functions to the chosen env. Idempotent. Does NOT mutate `manifest.cloud.default` — deploy is a one-shot action, so `env use dev && env deploy prod` stays on dev afterwards.
176
+
177
+ ```bash
178
+ agentlink env deploy # Interactive picker (preselects cloud.default)
179
+ agentlink env deploy dev # Deploy to dev
180
+ agentlink env deploy prod # Deploy to prod (requires y/N confirmation)
181
+ agentlink env deploy prod --yes # Skip the confirmation (for CI)
182
+ agentlink env deploy dev --dry-run # Print the target without applying
183
+ ```
184
+
185
+ Auth providers / PostgREST config / vault secrets are NOT touched by `env deploy` — those are configured during initial `env add`. If any of those changed, use `env add <name> → Re-apply full setup` instead.
186
+
187
+ Generated CI workflows (`env add --setup-ci`) call `env deploy <name> --yes --non-interactive`.
188
+
189
+ #### `env list`
190
+
191
+ Show all configured environments with their org, project ref, and which one is currently active.
192
+
193
+ ```bash
194
+ agentlink env list
195
+ ```
196
+
197
+ #### `env remove <name>`
198
+
199
+ Remove an environment from `agentlink.json`. Offers to also wipe the stored DB password for that project.
200
+
201
+ ```bash
202
+ agentlink env remove prod
203
+ agentlink env remove prod -y # Skip confirmations
204
+ ```
205
+
206
+ > The previous `agentlink env relink <name>` command still works but prints a deprecation warning — use `env add <name>` (with the env already registered) and pick **Relink to a different Supabase project**. The top-level `agentlink deploy` command has been removed entirely; use `agentlink env deploy` instead.
207
+
208
+ ### `agentlink check`
209
+
210
+ Verify project setup. Outputs JSON with diagnostic info: `ready`, `supabase_running`, database state (extensions, queues, functions, secrets, api_schema), and file checks.
211
+
212
+ ```bash
213
+ agentlink check
214
+ agentlink check --env prod # Check a specific cloud env
215
+ ```
216
+
217
+ ### `agentlink info [name]`
218
+
219
+ Show documentation about scaffolded components. Without a name, lists all components. With a name, shows type, summary, description, signature, and related components.
220
+
221
+ ```bash
222
+ agentlink info # List all components
223
+ agentlink info tenant_select # Detail for one component
224
+ ```
225
+
226
+ ### `agentlink db`
227
+
228
+ Database operations. Every subcommand targets the active cloud env (`manifest.cloud.default`) unless `--env <name>` or `--db-url <url>` is passed.
229
+
230
+ #### `db apply`
231
+
232
+ Apply all schema files in `supabase/schemas/` to the database using pg-delta declarative apply. Generates TypeScript types afterwards unless `--skip-types` is set.
233
+
234
+ ```bash
235
+ agentlink db apply
236
+ agentlink db apply --skip-types
237
+ agentlink db apply --env prod
238
+ agentlink db apply --db-url postgresql://...
239
+ ```
240
+
241
+ #### `db migrate <name>`
242
+
243
+ Generate a migration file from the diff between the current database state and the schema files. Intended for creating auditable deployment artifacts — `env deploy` does NOT generate migrations.
244
+
245
+ ```bash
246
+ agentlink db migrate add_charts_table
247
+ agentlink db migrate add_charts_table --env prod
248
+ ```
249
+
250
+ #### `db sql <query>`
251
+
252
+ Run ad-hoc SQL against the active database. Uses `psql` locally, Management API for cloud.
253
+
254
+ ```bash
255
+ agentlink db sql "SELECT count(*) FROM public.profiles"
256
+ agentlink db sql "SELECT * FROM api.chart_list()" --json
257
+ agentlink db sql "..." --env prod
258
+ ```
259
+
260
+ #### `db types`
261
+
262
+ Regenerate `src/types/database.ts` (Vite) or `types/database.ts` (Next.js) from the `api` schema.
263
+
264
+ ```bash
265
+ agentlink db types
266
+ agentlink db types --output custom/path.ts
267
+ ```
268
+
269
+ #### `db rebuild`
270
+
271
+ Nuke `supabase/migrations/*`, re-apply schemas, and regenerate a single baseline migration. Recovery path when migration state gets broken early in a project.
272
+
273
+ ```bash
274
+ agentlink db rebuild
275
+ ```
276
+
277
+ #### `db url [--fix]`
278
+
279
+ Show the correct pooler DB URL for the active cloud env. `--fix` updates `.env.local` if the current value is stale.
280
+
281
+ ```bash
282
+ agentlink db url
283
+ agentlink db url --fix
284
+ ```
285
+
286
+ #### `db password [value]`
287
+
288
+ Show or set the stored DB password for the active cloud env's project.
289
+
290
+ ```bash
291
+ agentlink db password # Prompt (masked) + save
292
+ agentlink db password "new-password" # Set directly
293
+ ```
294
+
295
+ #### `db backup`
296
+
297
+ Snapshot the current env's database into three SQL files following Supabase's recommended `db dump` triplet — `roles.sql` (role-only), `schema.sql` (definitions), and `data.sql` (COPY-formatted data, with the `storage.buckets_vectors` / `storage.vector_indexes` tables excluded). Files are written to `supabase/backups/<env>/<YYYY-MM-DDTHH-MM-SS>/`; each run creates a fresh timestamped subdirectory so previous snapshots are preserved.
298
+
299
+ On first run, `supabase/backups/` is appended to the project's root `.gitignore` under an "Agent Link — database backups" comment. Idempotent on re-runs. Snapshots may contain real production data, so they're gitignored by default.
300
+
301
+ ```bash
302
+ agentlink db backup # Active env (cloud.default, or local if none)
303
+ agentlink db backup --env prod # Target prod explicitly (shows ▲ Active env: prod if active)
304
+ agentlink db backup --db-url "postgresql://..." # Override URL entirely
305
+ ```
306
+
307
+ Works on cloud envs, local Docker, and bare projects — doesn't require `supabase/schemas/` or any scaffolded files, just a reachable DB. Read-only; no cloud mutation.
308
+
309
+ ### `agentlink env config [subcommand] [env-name]`
310
+
311
+ Apply one or more server-side config sections to a cloud env. The three subsystems are **independent** — run just the one that drifted, or `all` for a full re-apply. Same primitives used by `env add`'s initial bootstrap, so there's no config drift between first-time setup and re-applies.
312
+
313
+ | Subcommand | What it does |
314
+ |-----------|--------------|
315
+ | `secrets` | Seed Vault (`SUPABASE_URL` / `SUPABASE_PUBLISHABLE_KEY` / `SUPABASE_SECRET_KEY`) **and** mirror to edge-function secrets under `SB_*` prefix (set-if-absent — user-set custom values survive). |
316
+ | `db` | PATCH PostgREST to expose the `api` schema. |
317
+ | `auth` | PATCH auth config (hooks + signup settings). |
318
+ | `all` | Run all three in order. |
319
+
320
+ Both positionals are optional — omit either (or both) for an interactive picker:
321
+
322
+ ```bash
323
+ agentlink env config # Pick subcommand + env interactively
324
+ agentlink env config secrets # Secrets; env picker
325
+ agentlink env config prod # Env=prod; subcommand picker
326
+ agentlink env config secrets prod # Both specified
327
+ agentlink env config auth prod # Just auth, against prod (confirms)
328
+ agentlink env config all dev --yes # Full re-apply to dev, no prompts
329
+ agentlink env config secrets --env prod # --env flag accepted for CI scripts
330
+ ```
331
+
332
+ Idempotent. Works on bare projects (no `supabase/schemas` required). Cloud-only — `env config all local` is rejected.
333
+
334
+ ### `agentlink frontend <name>`
335
+
336
+ Scaffold only the frontend template (no Supabase setup).
337
+
338
+ ```bash
339
+ agentlink frontend my-app # React + Vite
340
+ agentlink frontend my-app --nextjs # NextJS
341
+ ```
342
+
343
+ > `agentlink template` is the previous name and still works, but prints a deprecation warning.
344
+
345
+ ## Typical workflows
346
+
347
+ ### First-time scaffold, iterate, deploy to prod
348
+
349
+ ```bash
350
+ # 1. Scaffold a cloud dev project
351
+ agentlink my-app --prompt "build a project tracker"
352
+
353
+ # 2. Agent builds — you iterate locally, `db apply` runs against dev.
354
+
355
+ # 3. Connect prod (creates a separate Supabase project)
356
+ cd my-app
357
+ agentlink env add prod
358
+
359
+ # 4. Deploy
360
+ agentlink env deploy prod # Prompts y/N; deploys schemas + functions
361
+ ```
362
+
363
+ ### Agent-driven scaffold, user finishes in terminal
364
+
365
+ ```bash
366
+ # 1. Agent (no browser access) scaffolds only — no Supabase touched
367
+ agentlink my-app --skip-env --prompt "..."
368
+
369
+ # 2. User, in their terminal:
370
+ cd my-app
371
+ agentlink env add dev # OAuth opens browser, env is ready
372
+
373
+ # 3. Continue with the agent — schemas are ready to apply.
374
+ agentlink db apply
375
+ ```
376
+
377
+ ### Hotfix on prod
378
+
379
+ ```bash
380
+ # Edit supabase/schemas/*.sql locally
381
+ agentlink env deploy prod # Pushes just the delta + functions
382
+ ```
383
+
384
+ ### Rebuild migration history early in a project
385
+
386
+ ```bash
387
+ # Dev DB is messy, migration files are inconsistent
388
+ agentlink db rebuild # Wipes migrations, re-applies schemas, creates one baseline
389
+ ```
390
+
391
+ ## What it does
392
+
393
+ The scaffold runs a multi-step process:
394
+
395
+ 1. **Prerequisites** — Checks for Supabase CLI, pg-delta, and psql
396
+ 2. **Configure files** — Writes template files, `config.toml`, and `.env.local`
397
+ 3. **Start Supabase** — Starts locally (Docker) or creates a Cloud project
398
+ 4. **Read config** — Reads Supabase API keys and connection info
399
+ 5. **Write env** — Updates `.env.local` with API keys and DB URL
400
+ 6. **Setup database** — Applies SQL schemas, writes migrations, configures auth
401
+ 7. **Verify setup** — Runs verification queries to confirm all components
402
+ 8. **Setup frontend** — Writes React + Vite or NextJS files (if selected)
403
+ 9. **Install frontend deps** — Runs `npm install` for the frontend
404
+ 10. **Configure Claude Code** — Sets up `CLAUDE.md` and Claude settings
405
+ 11. **Install MCP** — Installs Supabase MCP server (local mode only)
406
+ 12. **Install plugin** — Installs Agent Link plugin and companion skills
407
+ 13. **Finalize** — Creates git repo, writes `agentlink.json` manifest
408
+
409
+ Running `agentlink` inside an existing project (with `agentlink.json`) triggers the **update** flow instead, which patches template files, updates the plugin, applies schema changes, and regenerates migrations.
410
+
411
+ ## Modes
412
+
413
+ ### Cloud mode (default)
414
+
415
+ Creates a Supabase Cloud project. No local Docker or psql required. Uses the Management API for database operations, auth config, PostgREST config, and edge function deployment. Authenticates via OAuth (browser), token flag (`--token`), or cached credentials (`~/.config/agentlink/credentials.json`). Region is auto-detected from your timezone.
416
+
417
+ ### Local mode (`--local`)
418
+
419
+ Runs Supabase in Docker via `supabase start`. Requires Docker and psql. Applies schemas via psql. Installs the Supabase MCP server for Claude Code.
420
+
421
+ ## Frontend options
422
+
423
+ | Option | Frontend | Key features |
424
+ | ------------------------------ | ------------------ | ------------------------------------------------- |
425
+ | React + Vite (default) | Vite + React | Auth UI, theme switcher, shadcn/ui components |
426
+ | NextJS (`--nextjs`) | Next.js App Router | SSR, server/client Supabase modules, same auth UI |
427
+ | Backend only (`--no-frontend`) | None | Minimal package.json with dev dependencies only |
428
+
429
+ ## Companion skills
430
+
431
+ The CLI installs all recommended companion skills for Claude Code automatically. Use `--no-skills` to skip.
432
+
433
+ **Base skills (all frontends):**
434
+
435
+ - `supabase/agent-skills@supabase-postgres-best-practices` (required)
436
+ - `anthropics/skills@frontend-design`
437
+ - `shadcn/ui`
438
+ - `vercel-labs/agent-skills@vercel-react-best-practices`
439
+ - `resend/react-email`
440
+ - `resend/email-best-practices`
441
+ - `resend/resend-skills`
442
+
443
+ **Additional for NextJS:**
444
+
445
+ - `vercel-labs/next-skills --skill next-best-practices`
446
+
447
+ ## Scaffolded project structure
448
+
449
+ ```
450
+ my-app/
451
+ ├── agentlink.json # Project manifest
452
+ ├── CLAUDE.md # AI agent instructions
453
+ ├── .env.local # Environment variables
454
+ ├── .env.example
455
+ ├── .claude/
456
+ │ └── settings.local.json # Claude Code permissions
457
+ ├── supabase/
458
+ │ ├── config.toml
459
+ │ ├── schemas/
460
+ │ │ ├── _schemas.sql # Schema + role grants
461
+ │ │ ├── _extensions.sql # Extension declarations
462
+ │ │ ├── public/
463
+ │ │ │ ├── profiles.sql # User profiles table
464
+ │ │ │ ├── multitenancy.sql # Tenants, memberships, invitations
465
+ │ │ │ ├── _auth_tenant.sql # Tenant auth helpers (RLS)
466
+ │ │ │ ├── _internal_admin.sql # Vault, edge function calls, set_updated_at
467
+ │ │ │ └── _hooks.sql # Auth hooks
468
+ │ │ └── api/
469
+ │ │ ├── profile.sql # Profile RPCs
470
+ │ │ └── tenant.sql # Tenant/invitation/membership RPCs
471
+ │ ├── migrations/ # Generated (never hand-written)
472
+ │ └── functions/
473
+ │ ├── _shared/
474
+ │ │ ├── withSupabase.ts # Auth wrapper for edge functions
475
+ │ │ ├── responses.ts # Response helpers
476
+ │ │ └── types.ts # Type definitions
477
+ │ ├── queue-worker/ # PGMQ message queue handler
478
+ │ └── send-email/ # Email sending + templates
479
+ ├── src/ # Frontend source (Vite or NextJS)
480
+ └── package.json
481
+ ```
482
+
483
+ ## Development
484
+
485
+ See [`DEVELOPMENT.md`](./DEVELOPMENT.md) for the internal dev guide (source file layout, template system, adding scaffolded files).