@lunora/cli 1.0.0-alpha.12 → 1.0.0-alpha.120

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 (94) hide show
  1. package/LICENSE.md +6 -0
  2. package/__assets__/package-og.svg +1 -1
  3. package/dist/bin.mjs +2 -10
  4. package/dist/index.d.mts +357 -321
  5. package/dist/index.d.ts +357 -321
  6. package/dist/index.mjs +1 -19
  7. package/dist/packem_chunks/handler.mjs +1 -150
  8. package/dist/packem_chunks/handler10.mjs +1 -22
  9. package/dist/packem_chunks/handler11.mjs +1 -192
  10. package/dist/packem_chunks/handler12.mjs +2 -131
  11. package/dist/packem_chunks/handler13.mjs +2 -65
  12. package/dist/packem_chunks/handler14.mjs +1 -58
  13. package/dist/packem_chunks/handler15.mjs +1 -79
  14. package/dist/packem_chunks/handler16.mjs +1 -43
  15. package/dist/packem_chunks/handler17.mjs +1 -105
  16. package/dist/packem_chunks/handler18.mjs +3 -170
  17. package/dist/packem_chunks/handler19.mjs +1 -89
  18. package/dist/packem_chunks/handler2.mjs +2 -114
  19. package/dist/packem_chunks/handler20.mjs +1 -94
  20. package/dist/packem_chunks/handler21.mjs +2 -311
  21. package/dist/packem_chunks/handler22.mjs +11 -0
  22. package/dist/packem_chunks/handler3.mjs +2 -204
  23. package/dist/packem_chunks/handler4.mjs +1 -33
  24. package/dist/packem_chunks/handler5.mjs +1 -49
  25. package/dist/packem_chunks/handler6.mjs +1 -91
  26. package/dist/packem_chunks/handler7.mjs +1 -42
  27. package/dist/packem_chunks/handler8.mjs +1 -174
  28. package/dist/packem_chunks/handler9.mjs +8 -16
  29. package/dist/packem_chunks/planDevCommand.mjs +7 -500
  30. package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
  31. package/dist/packem_chunks/runDeployCommand.mjs +1 -504
  32. package/dist/packem_chunks/runInitCommand.mjs +996 -1265
  33. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +9 -395
  34. package/dist/packem_chunks/runResetCommand.mjs +1 -41
  35. package/dist/packem_chunks/runRpcCommand.mjs +1 -68
  36. package/dist/packem_shared/COMMANDS-CQNSsSgS.mjs +3 -0
  37. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-DL87PIEl.mjs +8 -0
  38. package/dist/packem_shared/admin-url-DfVehV3e.mjs +1 -0
  39. package/dist/packem_shared/api-spec-BENwiyUa.mjs +1 -0
  40. package/dist/packem_shared/buildRegistryIndex-DwySASBu.mjs +1 -0
  41. package/dist/packem_shared/codegen-error-DJN6pTH5.mjs +3 -0
  42. package/dist/packem_shared/command-Bjv4VmYA.mjs +1 -0
  43. package/dist/packem_shared/commands-BhX2Bo9B.mjs +19 -0
  44. package/dist/packem_shared/createLogger--C3x1FNE.mjs +2 -0
  45. package/dist/packem_shared/createRecordingSpawner-ByIqBepG.mjs +1 -0
  46. package/dist/packem_shared/detect-package-manager-B2eIuAiP.mjs +1 -0
  47. package/dist/packem_shared/diffSnapshots-9bDd9nOK.mjs +5 -0
  48. package/dist/packem_shared/docker-CKvYE9YF.mjs +1 -0
  49. package/dist/packem_shared/insertSchemaExtension-DZReBZ4_.mjs +8 -0
  50. package/dist/packem_shared/open-url-CTU_g9gr.mjs +1 -0
  51. package/dist/packem_shared/output-format-D7cKB-O5.mjs +2 -0
  52. package/dist/packem_shared/parseManifest-x3WsxKHz.mjs +1 -0
  53. package/dist/packem_shared/prompt-cancelled-C8Sj7OqI.mjs +1 -0
  54. package/dist/packem_shared/resolve-target-vxaXHmvg.mjs +1 -0
  55. package/dist/packem_shared/runAddCommand--TBYJQYi.mjs +1 -0
  56. package/dist/packem_shared/schema-drift-gate-CpqG-xP4.mjs +1 -0
  57. package/dist/packem_shared/schemaIrToSnapshot-Clwd2A8e.mjs +1 -0
  58. package/dist/packem_shared/storage-DOvAKGi4.mjs +1 -0
  59. package/dist/packem_shared/tui-prompts-CCt3jm1k.mjs +4 -0
  60. package/dist/packem_shared/vectorize-metadata-BvZbbqUD.mjs +1 -0
  61. package/dist/packem_shared/wrangler-name-HIl0Z6yx.mjs +1 -0
  62. package/dist/packem_shared/wrangler-secrets-BMRJwKQU.mjs +1 -0
  63. package/package.json +23 -16
  64. package/skills/README.md +28 -14
  65. package/skills/lunora/SKILL.md +48 -9
  66. package/skills/lunora-functions/SKILL.md +38 -3
  67. package/skills/lunora-migration-helper/SKILL.md +36 -17
  68. package/skills/lunora-performance-audit/SKILL.md +36 -6
  69. package/skills/lunora-quickstart/SKILL.md +86 -24
  70. package/skills/lunora-realtime/SKILL.md +43 -30
  71. package/dist/packem_shared/COMMANDS-D3h9Iwvl.mjs +0 -944
  72. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
  73. package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
  74. package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
  75. package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
  76. package/dist/packem_shared/command-BC30oSBW.mjs +0 -14
  77. package/dist/packem_shared/commands-DVr4lduS.mjs +0 -812
  78. package/dist/packem_shared/createLogger-B40gPzQo.mjs +0 -78
  79. package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +0 -43
  80. package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
  81. package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +0 -161
  82. package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
  83. package/dist/packem_shared/insertSchemaExtension-DAqbfr9Z.mjs +0 -64
  84. package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
  85. package/dist/packem_shared/output-format-wUvAN6AL.mjs +0 -17
  86. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
  87. package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
  88. package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
  89. package/dist/packem_shared/runAddCommand-C-NOz8NJ.mjs +0 -4
  90. package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
  91. package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +0 -43
  92. package/dist/packem_shared/storage-DL9OE4oE.mjs +0 -84
  93. package/dist/packem_shared/tui-prompts-M6OWsuyw.mjs +0 -663
  94. package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
@@ -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
 
@@ -129,7 +144,10 @@ lunora migrate down backfill-display-name # revert (if `down` defined)
129
144
  Useful flags: `--batch-size <n>`, `--steps <n>` (cap batches this run), and
130
145
  `--prod --url <worker> --yes` to target production (with `LUNORA_ADMIN_TOKEN`).
131
146
 
132
- ## `.global()` (D1) Structural Migration Flow
147
+ ## `.global()` on D1 Structural Migration Flow
148
+
149
+ This flow is **D1-specific**. Hyperdrive-backed globals auto-provision their DDL
150
+ at runtime and skip it entirely.
133
151
 
134
152
  ```bash
135
153
  # 1. Edit lunora/schema.ts (widen: add the optional new field to the .global() table).
@@ -146,8 +164,8 @@ lunora deploy
146
164
  ```
147
165
 
148
166
  `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.
167
+ live in ShardDO SQLite, not D1). Run it after each schema edit in the widen and
168
+ narrow steps; backfill data with an online migration between them.
151
169
 
152
170
  ## The Schema-Drift Gate
153
171
 
@@ -176,9 +194,10 @@ add the migration — not to bypass it.
176
194
  transform before it touches real rows.
177
195
  5. **Deleting a field prematurely.** Deprecate with `v.optional` + a comment;
178
196
  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.
197
+ 6. **Migrating the wrong layer.** A D1-backed `.global()` structural change needs
198
+ `lunora migrate generate` (SQL); a Hyperdrive-backed one auto-provisions; a
199
+ data backfill needs a `defineMigration`. Check the table's `.global()` /
200
+ `.shardBy()` modifier — and, for `.global()`, its `backend` — first.
182
201
 
183
202
  ## Checklist
184
203
 
@@ -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.
@@ -2,8 +2,8 @@
2
2
  name: lunora-realtime
3
3
  description: Wires Lunora's live data into a client. Use for `LunoraClient`/`LunoraProvider`,
4
4
  reactive `useQuery`/`useSubscription`, `useMutation` with optimistic updates,
5
- pagination, connection status, the React/Vue/Solid/Svelte adapters, and the
6
- `@lunora/db` TanStack binding.
5
+ pagination, connection status, the React/Vue/Solid/Svelte/Angular/React Native
6
+ adapters, and the `@lunora/db` TanStack binding.
7
7
  ---
8
8
 
9
9
  # Lunora Realtime
@@ -15,7 +15,8 @@ automatic rollback.
15
15
 
16
16
  ## When to Use
17
17
 
18
- - Wiring a frontend to a Lunora backend (React, Vue, Solid, Svelte).
18
+ - Wiring a frontend to a Lunora backend (React, Vue, Solid, Svelte, Angular,
19
+ React Native/Expo, or an Astro/Nuxt meta-framework).
19
20
  - Adding optimistic updates, pagination, or presence to the UI.
20
21
  - Choosing between live hooks and the `@lunora/db` collection layer.
21
22
 
@@ -42,6 +43,19 @@ const client = new LunoraClient({ url });
42
43
  Vue / Solid / Svelte have matching providers in `@lunora/vue`, `@lunora/solid`,
43
44
  `@lunora/svelte`; the hook names and semantics below mirror across them.
44
45
 
46
+ Two adapters differ in shape:
47
+
48
+ - **`@lunora/angular`** is signal-based rather than hook-based: register with
49
+ `provideLunora(...)`, read the client via `injectLunoraClient()`, and use
50
+ `liveQuery(...)` / `mutate(...)` / `connectionStatus(...)` in place of the
51
+ hooks below.
52
+ - **`@lunora/react-native`** re-exports all of `@lunora/react` and adds
53
+ `createLunoraClient` (plus `@lunora/react-native/auth` for the better-auth
54
+ Expo bridge) — build the client with that instead of `new LunoraClient`.
55
+
56
+ For SSR meta-frameworks, `@lunora/astro` and `@lunora/nuxt` compose Lunora into
57
+ the server (Nitro for Nuxt) and ship reactive-loader server helpers.
58
+
45
59
  ## Live Queries
46
60
 
47
61
  `useQuery(reference, args)` opens a subscription and returns the value, or
@@ -67,33 +81,32 @@ const todos = useQuery(api.todos.list, {}) as Doc<"todos">[] | undefined;
67
81
 
68
82
  ## Authorization & Live Queries
69
83
 
70
- Subscriptions re-run the query handler **server-side under anonymous
71
- identity**. The one-shot `fetch` RPC behind the initial load carries the
72
- caller's identity, but the live WebSocket channel (the subscription seed and
73
- every write-driven refresh) does not it evaluates as anonymous.
74
-
75
- This matters for any query that authorizes or filters on the authenticated
76
- user:
77
-
78
- - A query guarded by `.use(rls(...))` or one that reads `ctx.auth.userId`
79
- directly returns the user's rows on the **initial** HTTP fetch, but its
80
- **live** updates evaluate anonymously and may resolve to an empty/denied
81
- set.
82
- - This **fails closed** — the live channel shows _less_ data, never another
83
- user's data, so there is no leak. But it is a correctness caveat: the
84
- initial render and the live updates can disagree.
85
-
86
- The supported pattern today is to scope per-user data **outside** of
87
- `ctx.auth` inside a subscribed query:
88
-
89
- - Partition the data by shard with `.shardBy(userId)` (or tenant/room), so the
90
- subscription is already scoped to the right state, or
91
- - Pass the identifier as an **explicit query arg**
92
- (`useQuery(api.todos.list, { userId })`) and filter on the arg rather than on
93
- `ctx.auth`.
94
-
95
- Reserve `rls()` / `ctx.auth`-based filtering for non-subscribed reads (one-shot
96
- actions/queries) where identity is always present.
84
+ **Live queries are identity-aware.** At the WebSocket upgrade the runtime
85
+ stamps the caller's verified identity onto the socket (from the server-minted
86
+ `x-lunora-userid` / `x-lunora-identity` headers, which a client cannot forge).
87
+ Every subscription re-run, shape resolution, and poke-driven refresh executes
88
+ under that socket's own identity, passed by value so a concurrent RPC can't
89
+ clobber it.
90
+
91
+ Practically, this means:
92
+
93
+ - `.use(rls(...))` and `ctx.auth.userId` work the same in a subscribed query as
94
+ in a one-shot read. Shape subscriptions AND-merge the shape predicate with
95
+ the table's RLS read base-where, so the membership query the poke protocol
96
+ runs is RLS-correct by constructionnever the client's word for it.
97
+ - An **anonymous** socket carries no identity, so an RLS/`ctx.auth` query fails
98
+ closed (empty/denied) rather than leaking another user's rows.
99
+ - **Token expiry is enforced on the socket.** When the resolved credential
100
+ carries an expiry, the DO sends a `TOKEN_EXPIRED` error frame and closes with
101
+ code `4001` at the next send at or after that instant. `LunoraClient`
102
+ reconnects automatically and re-resolves a fresh identity — but surface it in
103
+ the UI if a re-login is required.
104
+
105
+ You can still scope data structurally when it fits the domain — `.shardBy(userId)`
106
+ (or tenant/room) partitions state so a subscription is narrow by construction,
107
+ and explicit query args keep subscriptions cheap (see the args-scoping note
108
+ above). Prefer those for _performance_; use `rls()` / `ctx.auth` for
109
+ _authorization_. They compose.
97
110
 
98
111
  ## Mutations + Optimistic Updates
99
112