@lunora/cli 1.0.0-alpha.15 → 1.0.0-alpha.151

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.
Files changed (108) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +1 -1
  3. package/__assets__/package-og.svg +1 -1
  4. package/dist/bin.mjs +2 -10
  5. package/dist/index.d.mts +658 -335
  6. package/dist/index.d.ts +658 -335
  7. package/dist/index.mjs +1 -19
  8. package/dist/packem_chunks/handler.mjs +1 -150
  9. package/dist/packem_chunks/handler10.mjs +1 -22
  10. package/dist/packem_chunks/handler11.mjs +2 -192
  11. package/dist/packem_chunks/handler12.mjs +2 -131
  12. package/dist/packem_chunks/handler13.mjs +1 -65
  13. package/dist/packem_chunks/handler14.mjs +1 -58
  14. package/dist/packem_chunks/handler15.mjs +1 -79
  15. package/dist/packem_chunks/handler16.mjs +1 -43
  16. package/dist/packem_chunks/handler17.mjs +3 -105
  17. package/dist/packem_chunks/handler18.mjs +1 -170
  18. package/dist/packem_chunks/handler19.mjs +1 -89
  19. package/dist/packem_chunks/handler2.mjs +2 -114
  20. package/dist/packem_chunks/handler20.mjs +7 -94
  21. package/dist/packem_chunks/handler21.mjs +2 -311
  22. package/dist/packem_chunks/handler22.mjs +2 -0
  23. package/dist/packem_chunks/handler23.mjs +1 -0
  24. package/dist/packem_chunks/handler24.mjs +99 -0
  25. package/dist/packem_chunks/handler25.mjs +10 -0
  26. package/dist/packem_chunks/handler3.mjs +2 -204
  27. package/dist/packem_chunks/handler4.mjs +1 -33
  28. package/dist/packem_chunks/handler5.mjs +1 -49
  29. package/dist/packem_chunks/handler6.mjs +1 -91
  30. package/dist/packem_chunks/handler7.mjs +1 -42
  31. package/dist/packem_chunks/handler8.mjs +3 -174
  32. package/dist/packem_chunks/handler9.mjs +1 -16
  33. package/dist/packem_chunks/planDevCommand.mjs +7 -500
  34. package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
  35. package/dist/packem_chunks/runDeployCommand.mjs +1 -504
  36. package/dist/packem_chunks/runInitCommand.mjs +1018 -1315
  37. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +9 -395
  38. package/dist/packem_chunks/runResetCommand.mjs +1 -41
  39. package/dist/packem_chunks/runRpcCommand.mjs +1 -68
  40. package/dist/packem_shared/COMMANDS-DMyRipjO.mjs +1 -0
  41. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Dqu4Zmi0.mjs +1 -0
  42. package/dist/packem_shared/admin-token-BKmc3AUm.mjs +1 -0
  43. package/dist/packem_shared/admin-url-Ca-KI3d_.mjs +1 -0
  44. package/dist/packem_shared/advisory-gate-yaOOyUQl.mjs +1 -0
  45. package/dist/packem_shared/api-spec-BENwiyUa.mjs +1 -0
  46. package/dist/packem_shared/buildRegistryIndex-DwySASBu.mjs +1 -0
  47. package/dist/packem_shared/cli-RVVu3rxm.mjs +3 -0
  48. package/dist/packem_shared/codegen-error-DJN6pTH5.mjs +3 -0
  49. package/dist/packem_shared/command-0l-ZPhIX.mjs +1 -0
  50. package/dist/packem_shared/commands-CG9qEtqR.mjs +19 -0
  51. package/dist/packem_shared/createLogger-BoSxdb2T.mjs +2 -0
  52. package/dist/packem_shared/createRecordingSpawner-SKs4R1fc.mjs +1 -0
  53. package/dist/packem_shared/deploy-target-Dvr9vxpR.mjs +1 -0
  54. package/dist/packem_shared/detect-package-manager-DXDstphE.mjs +1 -0
  55. package/dist/packem_shared/diffSnapshots-BbwCuhoN.mjs +5 -0
  56. package/dist/packem_shared/docker-CKvYE9YF.mjs +1 -0
  57. package/dist/packem_shared/health-probe-CiFgh1hn.mjs +1 -0
  58. package/dist/packem_shared/import-DLyCq-2j.mjs +12 -0
  59. package/dist/packem_shared/insertSchemaExtension-DZReBZ4_.mjs +8 -0
  60. package/dist/packem_shared/lint-ignore-report-CKDXv9MQ.mjs +2 -0
  61. package/dist/packem_shared/open-url-zbbAo_D7.mjs +1 -0
  62. package/dist/packem_shared/output-format-Cv3aLqhP.mjs +2 -0
  63. package/dist/packem_shared/parseManifest-x3WsxKHz.mjs +1 -0
  64. package/dist/packem_shared/platform-diagnostics-C4TFj5Pu.mjs +4 -0
  65. package/dist/packem_shared/post-codegen-hook-DhL1RH5u.mjs +1 -0
  66. package/dist/packem_shared/prompt-cancelled-C8Sj7OqI.mjs +1 -0
  67. package/dist/packem_shared/resolve-target-CeiNrCAx.mjs +1 -0
  68. package/dist/packem_shared/runAddCommand-a_rW768_.mjs +1 -0
  69. package/dist/packem_shared/runExportCommand-BpE4AbuX.mjs +5 -0
  70. package/dist/packem_shared/schema-drift-gate-d12lMICD.mjs +1 -0
  71. package/dist/packem_shared/schemaIrToSnapshot-Dahp39qH.mjs +1 -0
  72. package/dist/packem_shared/shared-Ce9bKz5c.mjs +1 -0
  73. package/dist/packem_shared/tui-prompts-BU3irGxV.mjs +4 -0
  74. package/dist/packem_shared/vectorize-metadata-BvZbbqUD.mjs +1 -0
  75. package/dist/packem_shared/wrangler-name-CHDf3rMP.mjs +1 -0
  76. package/dist/packem_shared/wrangler-secrets-D0Tv5GWn.mjs +1 -0
  77. package/package.json +39 -17
  78. package/skills/README.md +28 -14
  79. package/skills/lunora/SKILL.md +48 -9
  80. package/skills/lunora-functions/SKILL.md +38 -3
  81. package/skills/lunora-migration-helper/SKILL.md +70 -17
  82. package/skills/lunora-performance-audit/SKILL.md +36 -6
  83. package/skills/lunora-quickstart/SKILL.md +86 -24
  84. package/skills/lunora-realtime/SKILL.md +58 -30
  85. package/dist/packem_shared/COMMANDS-D3h9Iwvl.mjs +0 -944
  86. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
  87. package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
  88. package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
  89. package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
  90. package/dist/packem_shared/command-BC30oSBW.mjs +0 -14
  91. package/dist/packem_shared/commands-hl0mRqqg.mjs +0 -845
  92. package/dist/packem_shared/createLogger-B40gPzQo.mjs +0 -78
  93. package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +0 -43
  94. package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
  95. package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +0 -161
  96. package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
  97. package/dist/packem_shared/insertSchemaExtension-DAqbfr9Z.mjs +0 -64
  98. package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
  99. package/dist/packem_shared/output-format-wUvAN6AL.mjs +0 -17
  100. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
  101. package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
  102. package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
  103. package/dist/packem_shared/runAddCommand-vJdgiR5t.mjs +0 -4
  104. package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
  105. package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +0 -43
  106. package/dist/packem_shared/storage-B7hHSTZP.mjs +0 -84
  107. package/dist/packem_shared/tui-prompts-M6OWsuyw.mjs +0 -663
  108. package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lunora/cli",
3
- "version": "1.0.0-alpha.15",
4
- "description": "The Lunora CLI: init, dev, deploy, codegen, run, reset, and migrate commands",
3
+ "version": "1.0.0-alpha.151",
4
+ "description": "The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands",
5
5
  "keywords": [
6
6
  "agent-skills",
7
7
  "cli",
@@ -51,26 +51,48 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@bomb.sh/tab": "0.0.16",
55
- "@lunora/codegen": "1.0.0-alpha.6",
56
- "@lunora/config": "1.0.0-alpha.8",
57
- "@lunora/container": "1.0.0-alpha.1",
58
- "@lunora/d1": "1.0.0-alpha.4",
59
- "@lunora/seed": "1.0.0-alpha.2",
60
- "@visulima/cerebro": "3.0.0-alpha.32",
61
- "@visulima/fs": "5.0.0-alpha.32",
62
- "@visulima/pail": "4.0.0-alpha.22",
63
- "@visulima/path": "3.0.0-alpha.13",
64
- "@visulima/spinner": "1.0.0-alpha.4",
65
- "@visulima/tui": "1.0.0-alpha.26",
54
+ "@bomb.sh/tab": "0.0.21",
55
+ "@lunora/advisor": "1.0.0-alpha.71",
56
+ "@lunora/bindings": "1.0.0-alpha.23",
57
+ "@lunora/codegen": "1.0.0-alpha.96",
58
+ "@lunora/config": "1.0.0-alpha.125",
59
+ "@lunora/container": "1.0.0-alpha.25",
60
+ "@lunora/d1": "1.0.0-alpha.68",
61
+ "@lunora/errors": "1.0.0-alpha.16",
62
+ "@lunora/mcp": "1.0.0-alpha.61",
63
+ "@lunora/runtime": "1.0.0-alpha.57",
64
+ "@lunora/seed": "1.0.0-alpha.66",
65
+ "@visulima/cerebro": "3.0.0",
66
+ "@visulima/error": "6.0.0",
67
+ "@visulima/fs": "5.0.5",
68
+ "@visulima/package": "5.0.5",
69
+ "@visulima/pail": "4.0.0",
70
+ "@visulima/path": "3.0.0",
71
+ "@visulima/spinner": "1.0.0",
72
+ "@visulima/tui": "1.0.5",
73
+ "adm-zip": "0.6.0",
66
74
  "cfonts": "^3.3.1",
67
- "giget": "3.3.0",
75
+ "csv-parse": "6.1.0",
76
+ "giget": "3.3.1",
68
77
  "jsonc-parser": "^3.3.1",
69
- "magic-string": "^0.30.21",
70
- "react": "^19.2.7",
78
+ "magic-string": "^1.1.0",
79
+ "react": "^19.2.8",
71
80
  "react-reconciler": "^0.33.0",
81
+ "smol-toml": "1.6.1",
72
82
  "ts-morph": "^28.0.0"
73
83
  },
84
+ "peerDependencies": {
85
+ "mysql2": "*",
86
+ "pg": "*"
87
+ },
88
+ "peerDependenciesMeta": {
89
+ "mysql2": {
90
+ "optional": true
91
+ },
92
+ "pg": {
93
+ "optional": true
94
+ }
95
+ },
74
96
  "engines": {
75
97
  "node": "^22.15.0 || >=24.11.0"
76
98
  }
package/skills/README.md CHANGED
@@ -9,21 +9,35 @@ framework correctly. They ship inside `@lunora/cli` and are discovered by the
9
9
  Each skill is a `SKILL.md` with YAML frontmatter (`name`, `description`) in its
10
10
  own directory:
11
11
 
12
- | Skill | Use for |
13
- | -------------------------- | --------------------------------------------------------------------------- |
14
- | `lunora` | Router — start here, then switch to the matching skill below. |
15
- | `lunora-quickstart` | `lunora init` / adding Lunora to an app + first round-trip. |
16
- | `lunora-functions` | Core authoring rules — schema, validators, query/mutation/action, `ctx.db`. |
17
- | `lunora-realtime` | Client reactivity — live hooks, optimistic updates, `@lunora/db`. |
18
- | `lunora-setup-auth` | Authentication via `lunora registry add auth` (+ providers). |
19
- | `lunora-setup-mail` | Transactional email via `lunora registry add mail` — `sendEmail` actions. |
20
- | `lunora-setup-storage` | R2 file storage via `lunora registry add storage` — signed upload/download. |
21
- | `lunora-setup-scheduler` | Deferred (`ctx.scheduler`) + cron jobs (`lunora registry add crons`). |
22
- | `lunora-create-package` | Building a reusable registry item or `@lunora/*` package. |
23
- | `lunora-migration-helper` | Schema/data migrations, `.global()` D1 flow, the drift gate. |
24
- | `lunora-deploy` | Deploying to Cloudflare wrangler bindings, secrets, the gate. |
25
- | `lunora-performance-audit` | Scans, indexes, OCC write conflicts, sharding/`.global()`. |
12
+ | Skill | Use for |
13
+ | -------------------------------- | ---------------------------------------------------------------------------- |
14
+ | `lunora` | Router — start here, then switch to the matching skill below. |
15
+ | `lunora-quickstart` | `lunora init` / adding Lunora to an app + first round-trip. |
16
+ | `lunora-functions` | Core authoring rules — schema, validators, query/mutation/action, `ctx.db`. |
17
+ | `lunora-realtime` | Client reactivity — live hooks, optimistic updates, `@lunora/db`. |
18
+ | `lunora-setup-auth` | Authentication via `lunora registry add auth` (+ providers). |
19
+ | `lunora-setup-mail` | Transactional email via `lunora registry add mail` — `sendEmail` actions. |
20
+ | `lunora-setup-storage` | R2 file storage via `lunora registry add storage` — signed upload/download. |
21
+ | `lunora-setup-scheduler` | Deferred (`ctx.scheduler`) + cron jobs (`lunora registry add crons`). |
22
+ | `lunora-setup-hyperdrive` | Existing Postgres/MySQL from an action `ctx.sql`, non-reactive. |
23
+ | `lunora-setup-hyperdrive-global` | Postgres/MySQL as a reactive `.global()` backend; D1 Hyperdrive migration. |
24
+ | `lunora-create-package` | Building a reusable registry item or `@lunora/*` package. |
25
+ | `lunora-migration-helper` | Schema/data migrations, `.global()` DDL flow, the drift gate. |
26
+ | `lunora-deploy` | Deploying to Cloudflare — wrangler bindings, secrets, the gate. |
27
+ | `lunora-performance-audit` | `lunora insights`, scans, indexes, OCC conflicts, sharding/`.global()`. |
26
28
 
27
29
  These are mirrored into `.agents/skills/` and `.claude/skills/` (via symlinks)
28
30
  so agents working inside this repo pick them up directly. The source of truth
29
31
  lives here so the published `@lunora/cli` tarball carries them.
32
+
33
+ **Adding a skill?** Create it here, then mirror it through both hops:
34
+
35
+ ```bash
36
+ ln -s ../../packages/cli/skills/<name> .agents/skills/<name>
37
+ ln -s ../../.agents/skills/<name> .claude/skills/<name>
38
+ ```
39
+
40
+ `scripts/check-skill-mirrors.js` (run on every `pnpm install`) fails if a mirror
41
+ is missing, dangling, or has become a real directory — a copied directory keeps
42
+ resolving while it silently drifts from the source, so it is treated as an
43
+ error rather than a warning.
@@ -14,8 +14,9 @@ Lunora exposes a Convex-style functional API (`defineSchema`, `query`,
14
14
  `mutation`, `action`) on top of Cloudflare Workers and Durable Objects. State
15
15
  lives in a per-app `ShardDO` (SQLite, OCC, hibernated WebSocket subscriptions)
16
16
  by default; `.shardBy(key)` partitions it across many DOs and `.global()`
17
- replicates a table to D1 for low-latency cross-region reads. A Vite plugin
18
- drives codegen and end-to-end type sync.
17
+ replicates a table to D1 or to Postgres/MySQL over Hyperdrive — for
18
+ low-latency cross-region reads. A Vite plugin drives codegen and end-to-end
19
+ type sync.
19
20
 
20
21
  If a more specific Lunora skill clearly matches the request, use that instead.
21
22
 
@@ -47,12 +48,13 @@ After codegen is green, use the most specific Lunora skill for the task:
47
48
  - Wiring live data into a client (hooks, optimistic updates): `lunora-realtime`
48
49
  - Authentication setup (email/password, OAuth, magic link, OTP):
49
50
  `lunora-setup-auth`
50
- - Wiring a prebuilt capability (mail, file storage, scheduled jobs, rate
51
- limiting, vectors, AI, containers, payments, MCP): install it with
52
- `lunora registry add <item>` (see `lunora registry list`). Capabilities with a
53
- dedicated skill: `lunora-setup-mail` (mail), `lunora-setup-storage` (R2 file
54
- storage), `lunora-setup-scheduler` (deferred `ctx.scheduler` + cron jobs). For
55
- the rest, read the item's README after installing.
51
+ - Transactional email: `lunora-setup-mail`
52
+ - R2 file storage (signed upload/download): `lunora-setup-storage`
53
+ - Deferred work (`ctx.scheduler`) and cron jobs: `lunora-setup-scheduler`
54
+ - Querying an **existing** Postgres/MySQL database from an action (`ctx.sql`,
55
+ non-reactive): `lunora-setup-hyperdrive`
56
+ - Using Postgres/MySQL as a **reactive `.global()` backend**, or migrating a D1
57
+ `.global()` dataset onto it: `lunora-setup-hyperdrive-global`
56
58
  - Building a reusable capability — a registry item or an `@lunora/*` package:
57
59
  `lunora-create-package`
58
60
  - Planning or running a schema/data migration: `lunora-migration-helper`
@@ -64,6 +66,41 @@ After codegen is green, use the most specific Lunora skill for the task:
64
66
  If one of those clearly matches the user's goal, switch to it instead of staying
65
67
  in this skill.
66
68
 
69
+ ## Capabilities Without a Dedicated Skill
70
+
71
+ Most other capabilities install as a **registry item** — `lunora registry add
72
+ <item>` scaffolds the `lunora/` glue, wrangler bindings, and env vars, then
73
+ prints post-install steps. Browse with `lunora registry list`; preview with
74
+ `lunora registry view <item>`. Read the installed item's README, and the
75
+ package's `docs/` for the API.
76
+
77
+ | Goal | Install / package |
78
+ | --------------------------------------------- | ------------------------------------------------------------ |
79
+ | Background jobs on Cloudflare Queues | `registry add queue` → `@lunora/queue` (`ctx.queues`) |
80
+ | Durable multi-step workflows | `registry add workflow` → `@lunora/workflow` (`ctx.runStep`) |
81
+ | Durable AI agents (tool loops, HITL, memory) | `@lunora/agent` (`defineAgent`) |
82
+ | Workers AI / RAG | `registry add ai` → `@lunora/ai` (`ctx.ai`, `defineRag`) |
83
+ | Feature flags (OpenFeature) | `registry add flags` → `@lunora/flags` (`ctx.flags`) |
84
+ | Payments (Stripe / Polar) | `registry add payment` → `@lunora/payment` |
85
+ | Rate limiting | `registry add ratelimit` → `@lunora/ratelimit` |
86
+ | Headless browser (action-only) | `registry add browser` → `@lunora/browser` (`ctx.browser`) |
87
+ | Cloudflare Containers | `@lunora/container` (`defineContainer`, `ctx.containers`) |
88
+ | Presence / who's-here | `registry add presence` |
89
+ | Cloudflare Access (Zero Trust) identity | `registry add cloudflare-access` |
90
+ | Backup / restore | `registry add backup` |
91
+ | Testing (in-memory harness, agent doubles) | `@lunora/testing` (`lunoraTest`) |
92
+ | Deterministic seed data | `@lunora/seed` + `lunora seed` |
93
+ | Local-first replica / offline mirror | `@lunora/replica` |
94
+ | Exposing the deployment to AI agents over MCP | `@lunora/mcp` |
95
+
96
+ Scaffolding inside this repo uses `vis generate lunora-<kind>` — `query`,
97
+ `mutation`, `action`, `http-route`, `table`, `cron`, `container`, `workflow`,
98
+ `queue`, `step`, `agent`, `flags`, `collections`, `package` (`vis generate
99
+ --list` for the full set). Most take a name: **always** pass it as
100
+ `--name=value`, since vis parses a space-separated `--name foo` as `--name=true`
101
+ plus a stray positional. `lunora-flags` and `lunora-collections` are singletons
102
+ and take no name.
103
+
67
104
  ## Core Mental Model
68
105
 
69
106
  - **Functions** live in `lunora/*.ts` and are one of `query` (reactive read),
@@ -75,7 +112,9 @@ in this skill.
75
112
  - **Reads go through indexes.** Prefer `ctx.db.query("t").withIndex(...)` over
76
113
  `.filter(...)`; declare the index with `.index("by_x", ["x"])`.
77
114
  - **Clients** subscribe over WebSocket. `useQuery`/`useMutation` (React, Vue,
78
- Solid, Svelte) re-render the moment a mutation changes the queried rows.
115
+ Solid, Svelte, React Native; signals in Angular) re-render the moment a
116
+ mutation changes the queried rows. Subscriptions run under the socket's
117
+ verified identity, so `rls()` / `ctx.auth` apply to live updates too.
79
118
 
80
119
  ## When Not to Use
81
120
 
@@ -150,9 +150,44 @@ Declare the index and constrain with `.withIndex`.
150
150
 
151
151
  ## Other `ctx` capabilities
152
152
 
153
- `ctx.auth` (the resolved session: `ctx.auth.userId`), `ctx.scheduler`
154
- (`runAfter` / `runAt` for deferred work), `ctx.storage` (R2), `ctx.vectors`
155
- (Vectorize), andwhen their packages are wired — `ctx.ai` and `ctx.containers`.
153
+ Always available:
154
+
155
+ - `ctx.auth`the resolved session (`ctx.auth.userId`).
156
+ - `ctx.scheduler` — `runAfter` / `runAt` for deferred work.
157
+ - `ctx.secrets` — Cloudflare Secrets Store.
158
+ - `ctx.span` / `ctx.trace` — the current span and a scoped tracing helper for
159
+ wide events.
160
+
161
+ Added by their package when wired. **A dependency in `package.json` is not
162
+ enough** — codegen scans the `lunora/` source set and flips a capability on only
163
+ when a file there imports the `@lunora/*` package or reads its `ctx.*` helper.
164
+ So write the call first, then run `lunora codegen` to surface the typed context:
165
+
166
+ | `ctx.*` | Package |
167
+ | ----------------------------------------------------------------------------------------- | ----------------------------- |
168
+ | `ctx.storage` | `@lunora/storage` (R2) |
169
+ | `ctx.ai` | `@lunora/ai` (Workers AI) |
170
+ | `ctx.flags` | `@lunora/flags` (OpenFeature) |
171
+ | `ctx.queues.<name>` | `@lunora/queue` |
172
+ | `ctx.workflows` / `ctx.runStep` | `@lunora/workflow` |
173
+ | `ctx.containers` | `@lunora/container` |
174
+ | `ctx.browser` (action-only) | `@lunora/browser` |
175
+ | `ctx.sql` (action-only) | `@lunora/hyperdrive` |
176
+ | `ctx.kv` / `ctx.images` / `ctx.analytics` / `ctx.pipelines` / `ctx.vectors` / `ctx.r2sql` | `@lunora/bindings` subpaths |
177
+
178
+ Two exceptions to the usage scan, and one extra requirement:
179
+
180
+ - **`ctx.flags` gates on a declaration file**, not on usage — codegen wires it
181
+ only when `lunora/flags.ts` exists (`vis generate lunora-flags` creates it).
182
+ `ctx.notify` / `ctx.push` work the same way via `lunora/notify.ts`.
183
+ - **`ctx.sql` also needs the real resource.** Codegen types the field, but the
184
+ connection needs a `HYPERDRIVE` binding (`wrangler hyperdrive create`) and an
185
+ explicit `createHyperdrive(ctx.env.HYPERDRIVE)` + driver adapter in the
186
+ action — see `lunora-setup-hyperdrive`. Bindings codegen can provision on its
187
+ own (e.g. `BROWSER` for `ctx.browser`) need no manual wrangler step.
188
+
189
+ `ctx.browser` and `ctx.sql` are **action-only** by design — they are
190
+ non-deterministic and would break query reactivity and mutation replay.
156
191
 
157
192
  ## HTTP endpoints
158
193
 
@@ -2,7 +2,8 @@
2
2
  name: lunora-migration-helper
3
3
  description: Plans Lunora schema and data migrations with widen-migrate-narrow. Use for
4
4
  breaking schema changes, backfills, table reshaping, online data migrations
5
- (`defineMigration` + `lunora migrate up`), the `.global()` D1 SQL flow, and the
5
+ (`defineMigration` + `lunora migrate up`), the `.global()` D1 / Hyperdrive
6
+ structural flows, and the
6
7
  pre-deploy schema-drift gate.
7
8
  ---
8
9
 
@@ -15,7 +16,7 @@ Safely change a Lunora schema and migrate data when making breaking changes.
15
16
  - Adding required fields to existing tables.
16
17
  - Changing field types or structure.
17
18
  - Splitting/merging tables, renaming/removing fields.
18
- - Reshaping `.global()` (D1-backed) tables.
19
+ - Reshaping `.global()` tables (D1- or Hyperdrive-backed).
19
20
 
20
21
  ## When Not to Use
21
22
 
@@ -23,21 +24,35 @@ Safely change a Lunora schema and migrate data when making breaking changes.
23
24
  - Adding **optional** fields that need no backfill.
24
25
  - Adding new tables or indexes with no correctness concern.
25
26
 
26
- ## Two Storage Layers — Know Which You Are Migrating
27
+ ## Storage Layers — Know Which You Are Migrating
27
28
 
28
- Lunora tables live in one of two backends, and they migrate differently:
29
+ Lunora tables live in one of three backends, and they migrate differently:
29
30
 
30
31
  - **ShardDO SQLite (default `root`, and `.shardBy(key)` tables).** State lives in
31
32
  the per-app / per-shard Durable Object. Data is reshaped with **online data
32
33
  migrations** — `defineMigration` declarations run by `lunora migrate up`,
33
34
  resumable per shard.
34
- - **`.global()` tables (D1).** Replicated to D1 for cross-region reads. Their
35
- structural DDL gets versioned **SQL migrations** via `lunora migrate generate`,
36
- applied by `@lunora/d1`'s runner at deploy time.
37
-
38
- A breaking change to a `.global()` table needs a generated SQL migration; a data
39
- backfill (either layer) is an online `defineMigration`. Both follow the same
40
- **widen migrate narrow** discipline.
35
+ - **`.global()` on D1 (the default global backend).** Replicated to D1 for
36
+ cross-region reads. Structural DDL gets versioned **SQL migrations** via
37
+ `lunora migrate generate`, applied by `@lunora/d1`'s runner at deploy time.
38
+ - **`.global({ backend: "hyperdrive" })` on Postgres/MySQL.** The same reactive
39
+ `.global()` contract served over Cloudflare Hyperdrive. Structural DDL works
40
+ differently here: tables **auto-provision on first use** the runtime applies
41
+ the DDL through the dialect — so there is no `lunora migrate generate` step
42
+ and no versioned SQL file to commit. See `lunora-setup-hyperdrive-global`.
43
+
44
+ So: a breaking structural change to a **D1-backed** `.global()` table needs a
45
+ generated SQL migration; the Hyperdrive-backed equivalent provisions itself. A
46
+ data backfill (any layer) is always an online `defineMigration`. All three
47
+ follow the same **widen → migrate → narrow** discipline — check the table's
48
+ backend before assuming which structural path applies.
49
+
50
+ > **Moving an existing dataset between global backends.** To move a `.global()`
51
+ > dataset from D1 onto Hyperdrive, use
52
+ > `lunora migrate d1-to-hyperdrive --from-url <d1-worker> --to-url <hd-worker>`
53
+ > (`--tables` scopes it; `--out` keeps the intermediate NDJSON dump). This is a
54
+ > backend move, not a schema change — the widen → migrate → narrow discipline
55
+ > below still governs any reshaping you do on either side of it.
41
56
 
42
57
  ## Key Principle: Widen, Migrate, Narrow
43
58
 
@@ -115,6 +130,40 @@ export default defineMigration({
115
130
  The transform must preserve row identity — the runner always keeps the original
116
131
  `_id` / `_creationTime`, so do not change them.
117
132
 
133
+ ### Reading another table
134
+
135
+ The transform's second argument is a **shard-scoped reader** (`ctx.db` with
136
+ `get` / `findFirst` / `findMany` / `count`), so the common backfill — read the
137
+ parent, copy a field down onto its children — is expressible. It may be `async`.
138
+
139
+ ```ts
140
+ up: async (doc, ctx) => {
141
+ const thread = await ctx.db.get(String(doc.threadId), "threads");
142
+
143
+ return thread ? { ...doc, userId: thread.userId } : undefined;
144
+ },
145
+ ```
146
+
147
+ It is a reader, not a writer: the runner accounts for exactly one rewrite per
148
+ row read, and a transform writing directly would make that count describe
149
+ something other than what happened. To touch a second table, run a second
150
+ migration over that table.
151
+
152
+ ### A shard key cannot be backfilled by a migration
153
+
154
+ If the field you are backfilling **is** the table's `.shardBy()` key, this is the
155
+ wrong tool, and no amount of reader access fixes it:
156
+
157
+ - a row whose shard key is unset does not belong to any shard, so a shard-scoped
158
+ query will never enumerate it; and
159
+ - writing the key would have to **move the row to a different Durable Object**,
160
+ which a per-shard runner has no way to do.
161
+
162
+ Re-keying is an export → transform → import (`lunora export`, rewrite the NDJSON,
163
+ `lunora import` — ids are preserved, so foreign keys survive), not a migration.
164
+ So the rule elsewhere in this skill that a data backfill is always an online
165
+ `defineMigration` has this one exception.
166
+
118
167
  ### Run it
119
168
 
120
169
  ```bash
@@ -129,7 +178,10 @@ lunora migrate down backfill-display-name # revert (if `down` defined)
129
178
  Useful flags: `--batch-size <n>`, `--steps <n>` (cap batches this run), and
130
179
  `--prod --url <worker> --yes` to target production (with `LUNORA_ADMIN_TOKEN`).
131
180
 
132
- ## `.global()` (D1) Structural Migration Flow
181
+ ## `.global()` on D1 Structural Migration Flow
182
+
183
+ This flow is **D1-specific**. Hyperdrive-backed globals auto-provision their DDL
184
+ at runtime and skip it entirely.
133
185
 
134
186
  ```bash
135
187
  # 1. Edit lunora/schema.ts (widen: add the optional new field to the .global() table).
@@ -146,8 +198,8 @@ lunora deploy
146
198
  ```
147
199
 
148
200
  `lunora migrate generate` only considers `.global()` tables (root/sharded tables
149
- are not D1-backed). Run it after each schema edit in the widen and narrow steps;
150
- backfill data with an online migration between them.
201
+ live in ShardDO SQLite, not D1). Run it after each schema edit in the widen and
202
+ narrow steps; backfill data with an online migration between them.
151
203
 
152
204
  ## The Schema-Drift Gate
153
205
 
@@ -176,9 +228,10 @@ add the migration — not to bypass it.
176
228
  transform before it touches real rows.
177
229
  5. **Deleting a field prematurely.** Deprecate with `v.optional` + a comment;
178
230
  delete only once nothing references it.
179
- 6. **Migrating the wrong layer.** A `.global()` structural change needs `lunora
180
- migrate generate` (SQL); a data backfill needs a `defineMigration`. Check the
181
- table's `.global()` / `.shardBy()` modifier first.
231
+ 6. **Migrating the wrong layer.** A D1-backed `.global()` structural change needs
232
+ `lunora migrate generate` (SQL); a Hyperdrive-backed one auto-provisions; a
233
+ data backfill needs a `defineMigration`. Check the table's `.global()` /
234
+ `.shardBy()` modifier — and, for `.global()`, its `backend` — first.
182
235
 
183
236
  ## Checklist
184
237
 
@@ -2,8 +2,8 @@
2
2
  name: lunora-performance-audit
3
3
  description: Diagnoses and fixes Lunora performance problems — full-table scans, missing
4
4
  indexes, OCC write conflicts, oversized subscriptions, and sharding/`.global()`
5
- scaling. Use when queries are slow, mutations conflict, or `@lunora/advisor`
6
- flags a table.
5
+ scaling. Use when queries are slow, mutations conflict, `lunora insights`
6
+ reports a hot-spot, or `@lunora/advisor` flags a table.
7
7
  ---
8
8
 
9
9
  # Lunora Performance Audit
@@ -34,12 +34,35 @@ apply it across sibling functions consistently.
34
34
 
35
35
  ## Signal Gathering
36
36
 
37
- Start with the static advisors — they need no traffic:
37
+ ### Runtime signal: `lunora insights`
38
+
39
+ When the worker is running and has served traffic, start here — it reports the
40
+ measured problem, not a suspected one:
41
+
42
+ ```bash
43
+ lunora insights # against the local dev worker
44
+ lunora insights --shard channel:demo # scope to one shard
45
+ lunora insights --limit 25 --json # machine-readable, more rows
46
+ lunora insights --prod --url https://app.example.com --token $LUNORA_ADMIN_TOKEN
47
+ ```
48
+
49
+ It ranks per-function **write-conflict hot-spots** (OCC contention — the
50
+ sharding signal), **error rates**, and **latency outliers**. A function at the
51
+ top of the write-conflict list is the direct input to the OCC section below; a
52
+ latency outlier usually resolves to the read-amplification section.
53
+
54
+ The Studio **Issues** panel and `lunora logs` cover the error side in more
55
+ detail once `insights` tells you where to look.
56
+
57
+ ### Static signal: the advisors
58
+
59
+ These need no traffic, so they also work on a cold codebase:
38
60
 
39
61
  - **Lunora Studio → Advisors tab** surfaces `@lunora/advisor` findings live in
40
62
  dev.
41
- - `@lunora/advisor` runs static lints over `defineSchema` + discovered query
42
- reads / insert writes. Relevant performance/schema rules:
63
+ - `@lunora/advisor` runs ~90 static lints over `defineSchema` + discovered query
64
+ reads / insert writes (plus a few runtime lints). The performance/schema rules
65
+ most relevant here:
43
66
  - `filter-without-index` — a query filters a table with no covering index.
44
67
  - `unindexed-foreign-key` — a relation/FK column has no index.
45
68
  - `duplicate-index` / `empty-index` — wasted or malformed indexes.
@@ -75,7 +98,8 @@ column. Fix every sibling query on the table the same way.
75
98
 
76
99
  ## Problem Class: Write Conflicts (OCC)
77
100
 
78
- **Symptom:** mutations on hot rows retry or fail under concurrency. ShardDO uses
101
+ **Symptom:** mutations on hot rows retry or fail under concurrency, or the
102
+ function tops the write-conflict section of `lunora insights`. ShardDO uses
79
103
  optimistic concurrency control — concurrent writes to the same DO that touch
80
104
  overlapping state conflict and retry.
81
105
 
@@ -115,6 +139,11 @@ cross-region reads (with read-your-writes via the Sessions API). Reserve it for
115
139
  read-mostly tables — `.global()` adds the D1 migration flow (see the
116
140
  `lunora-migration-helper` skill) and write-path cost.
117
141
 
142
+ If the dataset outgrows D1, `.global({ backend: "hyperdrive" })` serves the same
143
+ reactive `.global()` contract from Postgres/MySQL over Cloudflare Hyperdrive —
144
+ see the `lunora-setup-hyperdrive-global` skill (and `lunora migrate
145
+ d1-to-hyperdrive` to move an existing dataset).
146
+
118
147
  ### `.shardBy(key)` vs `.global()` — choose one per table
119
148
 
120
149
  - `.shardBy(key)`: partitions a table across Durable Objects by key — scales
@@ -135,6 +164,7 @@ read-mostly tables — `.global()` adds the D1 migration flow (see the
135
164
  ## Checklist
136
165
 
137
166
  - [ ] Scoped one concrete flow; traced every `ctx.db` read/write.
167
+ - [ ] Ran `lunora insights` (if the worker has traffic) for the measured signal.
138
168
  - [ ] Checked the Studio Advisors tab / `@lunora/advisor` findings.
139
169
  - [ ] Read amplification: replaced `.filter()` with an indexed `.withIndex()`.
140
170
  - [ ] Write conflicts: narrowed writes and/or partitioned with `.shardBy(key)`.
@@ -31,9 +31,12 @@ Set up a working Lunora project as fast as possible.
31
31
  Lunora into the current project.
32
32
  4. Run `lunora codegen` to generate `lunora/_generated/` and typecheck the
33
33
  schema + functions. This is the agent's feedback loop.
34
- 5. Start the dev loop with `lunora dev` (ask the user to run it locally, or
35
- start it in the background for cloud/headless agents it is long-running and
36
- does not exit).
34
+ 5. Start the dev loop. As an agent, run `lunora dev --background` it starts
35
+ the server as a managed detached process, blocks until it accepts requests,
36
+ prints the URL + PID, and returns (under a detected AI agent, plain
37
+ `lunora dev` does this automatically, with JSON logs). Never leave a bare
38
+ `lunora dev` running in your own shell — it is long-running and does not
39
+ exit.
37
40
  6. Verify a query/mutation round-trip works end to end.
38
41
 
39
42
  ## Path 1: New Project (Recommended)
@@ -42,27 +45,65 @@ Set up a working Lunora project as fast as possible.
42
45
  plugin + `lunora/` already wired together).
43
46
 
44
47
  ```bash
45
- lunora init my-app --template vite
48
+ lunora init my-app --vite react
46
49
  cd my-app
47
50
  pnpm install
48
51
  ```
49
52
 
50
- ### Pick a template
53
+ ### Pick a stack: `--vite` (SPA) or `-t` (bespoke template)
51
54
 
52
- | Template | Stack |
53
- | ---------------------- | ---------------------------------------------- |
54
- | `vite` | React + Vite (the simplest full-stack starter) |
55
- | `standalone` | Worker-only Lunora backend, no frontend |
56
- | `astro` | Astro integration |
57
- | `nuxt` | Nuxt (Vue) |
58
- | `sveltekit` | SvelteKit |
59
- | `tanstack-start-react` | TanStack Start (React) |
60
- | `tanstack-start-solid` | TanStack Start (Solid) |
55
+ There are **two scaffold paths**, and they take different flags:
61
56
 
62
- If the user has not specified a preference, default to `vite`. Pass `--template`
63
- explicitly to avoid the interactive prompt. Templates are fetched remotely (via
64
- `giget`) from `gh:anolilab/lunora/templates/<type>`; pass `--from <dir>` to use a
65
- local template directory offline.
57
+ **`--vite <framework>` the create-vite overlay.** Fetches the official
58
+ create-vite base and applies the Lunora layer on top. Use it for a plain SPA:
59
+
60
+ | `--vite` value | Stack |
61
+ | -------------- | ----------------------------------------------- |
62
+ | `react` | React SPA (**the default**) |
63
+ | `vue` | Vue SPA |
64
+ | `solid` | Solid SPA |
65
+ | `svelte` | Svelte SPA |
66
+ | `vanilla` | No framework (overlay-only — not in the picker) |
67
+
68
+ **`-t` / `--template <type>` — a bespoke Lunora template.** Whole-project
69
+ templates fetched remotely (via `giget`) from
70
+ `gh:anolilab/lunora/templates/<type>`:
71
+
72
+ | `-t` value | Stack |
73
+ | ---------------------- | ---------------------------------------------------------- |
74
+ | `next` | Next.js (App Router, OpenNext on Cloudflare) |
75
+ | `tanstack-start-react` | TanStack Start (React) — SSR with live-loader routes |
76
+ | `tanstack-start-solid` | TanStack Start (Solid) |
77
+ | `react-router` | React Router v7 (framework mode), SSR in the Lunora worker |
78
+ | `astro` | Astro + a standalone Lunora worker |
79
+ | `analog` | AnalogJS (Angular) — single worker, Lunora in Nitro |
80
+ | `nuxt` | Nuxt (Vue) — single worker, Lunora in Nitro |
81
+ | `sveltekit` | SvelteKit + a standalone Lunora worker |
82
+ | `expo` | React Native (Expo) — iOS/Android/web + a Lunora worker |
83
+ | `standalone` | Worker-only Lunora backend, no frontend |
84
+
85
+ > There is **no `--template vite`.** SPAs go through `--vite <framework>`; `-t`
86
+ > is only for the bespoke templates above.
87
+
88
+ With neither flag, an interactive run shows the framework picker (defaulting to
89
+ the React overlay) and a **non-interactive run errors out** — so as an agent,
90
+ always pass `--vite` or `-t` explicitly. If the user stated no preference,
91
+ use `--vite react`.
92
+
93
+ ### Useful `init` flags
94
+
95
+ ```bash
96
+ lunora init my-app --vite react --ci github # + a GitHub Actions deploy pipeline (or --ci gitlab)
97
+ lunora init my-app -t next --add auth,email # scaffold capabilities non-interactively
98
+ lunora init my-app --vite react --yes # skip the interactive auth/email offer
99
+ lunora init my-app --vite react --dry-run # walk every step, write nothing
100
+ ```
101
+
102
+ `--add` accepts a comma-separated list of `ai | auth | backup | browser |
103
+ cloudflare-access | crons | email | flags | hyperdrive | payment | presence |
104
+ queue | storage | workflow`. `--ref <branch|tag|commit>` pins the template
105
+ source (e.g. `--ref alpha`); `--from <dir>` copies from a local templates root
106
+ offline (expects `<type>/` subdirs).
66
107
 
67
108
  ### Generate types and push the first run
68
109
 
@@ -87,7 +128,23 @@ not exit, so:
87
128
 
88
129
  - **Local development (user at the keyboard):** ask the user to run `lunora dev`
89
130
  in a terminal.
90
- - **Cloud or headless agents:** start `lunora dev` in the background.
131
+ - **Agents:** run `lunora dev --background`. It detaches the server, waits until
132
+ it answers HTTP, prints `Dev server running at <url> (pid <n>)`, and exits —
133
+ no orphaned shell, no PID bookkeeping. When Lunora detects an AI agent
134
+ (Claude Code, Cursor, Codex, …), plain `lunora dev` flips into this mode
135
+ automatically with JSON logs; `LUNORA_AGENT_MODE=0` opts out.
136
+
137
+ Manage the running server afterwards:
138
+
139
+ ```bash
140
+ lunora dev status --json # machine-readable: url, pid, uptime, logFile
141
+ lunora dev logs --lines 50 # tail the captured output (.lunora/dev.log)
142
+ lunora dev stop # idempotent — succeeds even if nothing runs
143
+ ```
144
+
145
+ A second `lunora dev` never double-starts: it reports the existing instance
146
+ (`.lunora/dev.json` is the lockfile). Probe readiness or liveness at
147
+ `GET /_lunora/status` (`{"ok":true}`).
91
148
 
92
149
  Vite serves on `http://localhost:5173` by default; the Worker is served on the
93
150
  same origin via `@cloudflare/vite-plugin`.
@@ -132,9 +189,12 @@ createRoot(document.querySelector("#root")!).render(
132
189
  );
133
190
  ```
134
191
 
135
- Vue, Solid, and Svelte have matching providers in `@lunora/vue`, `@lunora/solid`,
136
- and `@lunora/svelte`. `VITE_LUNORA_URL` is optional — it defaults to
137
- `location.origin`, which is correct for the single-origin dev setup.
192
+ Every client adapter has a matching provider: `@lunora/vue`, `@lunora/solid`,
193
+ `@lunora/svelte`, `@lunora/angular` (`provideLunora` / `injectLunoraClient`),
194
+ and `@lunora/react-native` (`createLunoraClient`, re-exporting `@lunora/react`).
195
+ For meta-frameworks, `@lunora/astro` and `@lunora/nuxt` mount Lunora on the
196
+ server side. `VITE_LUNORA_URL` is optional — it defaults to `location.origin`,
197
+ which is correct for the single-origin dev setup.
138
198
 
139
199
  ## Writing Your First Function
140
200
 
@@ -233,8 +293,10 @@ ids, `.dev.vars` secrets, and container exports.
233
293
  ## Checklist
234
294
 
235
295
  - [ ] Determined starting point: new project or existing app.
236
- - [ ] New project: scaffolded with `lunora init --template <t>`.
296
+ - [ ] New project: scaffolded with `lunora init --vite <framework>` (SPA) or
297
+ `lunora init -t <template>` (bespoke) — never `--template vite`.
237
298
  - [ ] Existing app: ran `lunora init --here` and wired `LunoraProvider`.
238
299
  - [ ] Ran `lunora codegen`: `lunora/_generated/` exists and typecheck is clean.
239
- - [ ] `lunora dev` is running — user terminal, or background for cloud agents.
300
+ - [ ] Dev server is running — user terminal, or `lunora dev --background`
301
+ (check with `lunora dev status`).
240
302
  - [ ] Verified a query/mutation round-trip re-renders the client live.