@lunora/cli 1.0.0-alpha.362 → 1.0.0-alpha.363

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/cli",
3
- "version": "1.0.0-alpha.362",
3
+ "version": "1.0.0-alpha.363",
4
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",
@@ -54,14 +54,14 @@
54
54
  "@bomb.sh/tab": "0.0.22",
55
55
  "@lunora/advisor": "1.0.0-alpha.199",
56
56
  "@lunora/bindings": "1.0.0-alpha.101",
57
- "@lunora/codegen": "1.0.0-alpha.276",
58
- "@lunora/config": "1.0.0-alpha.321",
57
+ "@lunora/codegen": "1.0.0-alpha.277",
58
+ "@lunora/config": "1.0.0-alpha.322",
59
59
  "@lunora/container": "1.0.0-alpha.70",
60
60
  "@lunora/d1": "1.0.0-alpha.167",
61
61
  "@lunora/errors": "1.0.0-alpha.51",
62
62
  "@lunora/mcp": "1.0.0-alpha.223",
63
63
  "@lunora/runtime": "1.0.0-alpha.185",
64
- "@lunora/seed": "1.0.0-alpha.200",
64
+ "@lunora/seed": "1.0.0-alpha.201",
65
65
  "@visulima/cerebro": "3.1.2",
66
66
  "@visulima/error": "6.1.0",
67
67
  "@visulima/fs": "6.0.28",
@@ -1,197 +1,173 @@
1
1
  ---
2
2
  name: lunora
3
- description: Routes general Lunora requests to the right project skill. Use when the user
4
- asks which Lunora skill to use, or gives an underspecified task for a Lunora
5
- app (a type-safe, real-time backend on Cloudflare Workers + Durable Objects
6
- with a Vite-first DX).
3
+ description: Routes general Lunora requests to the right Lunora skill and gives the
4
+ shared mental model (codegen loop, generated `api`/`internal` references,
5
+ review commands, add-on capabilities, the `@lunora/mcp` server). Use when the
6
+ user asks which Lunora skill to use, gives an underspecified task in a project
7
+ with a `lunora/` directory or `lunorash`/`@lunora/*` dependencies, asks to
8
+ review or audit Lunora code, asks about an add-on without its own skill
9
+ (queues, workflows, agents, AI, flags, payments, notifications), or wants to
10
+ expose a deployment to an AI agent over MCP.
7
11
  ---
8
12
 
9
13
  # Lunora
10
14
 
11
- Use this as the routing skill for Lunora work in this repo.
15
+ Lunora is a type-safe, real-time backend on Cloudflare Workers + Durable
16
+ Objects. Functions are chainable `query` / `mutation` / `action` builders; state
17
+ lives in one `ShardDO` per app by default (SQLite, OCC, hibernated WebSocket
18
+ subscriptions). `.shardBy(key)` partitions a table across many DOs and
19
+ `.global()` replicates it to D1 (or Postgres/MySQL over Hyperdrive) for
20
+ cross-region reads. Codegen produces the types the client and server share.
12
21
 
13
- Lunora exposes a Convex-style functional API (`defineSchema`, `query`,
14
- `mutation`, `action`) on top of Cloudflare Workers and Durable Objects. State
15
- lives in a per-app `ShardDO` (SQLite, OCC, hibernated WebSocket subscriptions)
16
- by default; `.shardBy(key)` partitions it across many DOs and `.global()`
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.
22
+ If a project-level `AGENTS.md` / `CLAUDE.md` exists, read it first; it overrides
23
+ these defaults. If a more specific Lunora skill matches, switch to it.
20
24
 
21
- If a more specific Lunora skill clearly matches the request, use that instead.
22
-
23
- ## Start Here
24
-
25
- Before writing or changing any `lunora/` code, make sure the generated types are
26
- current — they are the contract the client and server share.
25
+ ## The feedback loop
27
26
 
28
27
  ```bash
29
- lunora codegen
28
+ lunora codegen # regenerate lunora/_generated/ from lunora/schema.ts + function files
29
+ lunora verify # wrangler config + codegen dry-run + tsc --noEmit; writes nothing
30
30
  ```
31
31
 
32
- This regenerates `lunora/_generated/` (`api.ts`, `server.ts`, `dataModel.ts`,
33
- `shard.ts`, `openapi.ts`, …) from `lunora/schema.ts` and your function files. The
34
- output typechecks your schema and functions, so it doubles as the agent's main
35
- feedback loop after each edit. Commit `lunora/_generated/` — it is part of the
36
- source tree, not a build artifact to gitignore.
37
-
38
- If a project-level `AGENTS.md` / `CLAUDE.md` exists, read it first — it overrides
39
- these defaults.
32
+ `lunora codegen` writes `lunora/_generated/` (`api.ts`, `internal.ts`,
33
+ `server.ts`, `dataModel.ts`, `shard.ts`, `app.ts`, `openapi.ts`, …; it prints
34
+ the exact list) and reports schema advisories and platform diagnostics. It does
35
+ not run `tsc`, so use `lunora verify` as the check that the code you wrote is
36
+ done. Its `tsc --noEmit` step runs only when the project has a `tsconfig.json`
37
+ (otherwise it warns and skips) and is turned off by `--no-typecheck`. `lunora dev` re-runs codegen on save, and `lunora deploy` runs it too.
38
+ Scaffolded projects gitignore `lunora/_generated/`; never hand-edit it.
40
39
 
41
- ## Route to the Right Skill
42
-
43
- After codegen is green, use the most specific Lunora skill for the task:
40
+ ## Route to the right skill
44
41
 
45
42
  - New project, or adding Lunora to an existing app: `lunora-quickstart`
46
43
  - Writing or reviewing schema + functions (the core authoring rules):
47
44
  `lunora-functions`
48
45
  - Wiring live data into a client (hooks, optimistic updates): `lunora-realtime`
49
- - Authentication setup (email/password, OAuth, magic link, OTP):
50
- `lunora-setup-auth`
46
+ - Authentication (email/password, OAuth, magic link, OTP): `lunora-setup-auth`
51
47
  - Transactional email: `lunora-setup-mail`
52
48
  - R2 file storage (signed upload/download): `lunora-setup-storage`
53
49
  - Deferred work (`ctx.scheduler`) and cron jobs: `lunora-setup-scheduler`
54
- - Querying an **existing** Postgres/MySQL database from an action (`ctx.sql`,
50
+ - Querying an existing Postgres/MySQL database from an action (`ctx.sql`,
55
51
  non-reactive): `lunora-setup-hyperdrive`
56
- - Using Postgres/MySQL as a **reactive `.global()` backend**, or migrating a D1
52
+ - Postgres/MySQL as a reactive `.global()` backend, or migrating a D1
57
53
  `.global()` dataset onto it: `lunora-setup-hyperdrive-global`
58
- - Building a reusable capability — a registry item or an `@lunora/*` package:
54
+ - Building a reusable capability (registry item or `@lunora/*` package):
59
55
  `lunora-create-package`
60
- - Planning or running a schema/data migration: `lunora-migration-helper`
61
- - Deploying to Cloudflare (wrangler, bindings, secrets, the drift gate):
62
- `lunora-deploy`
63
- - Investigating performance, scan, or write-conflict issues:
64
- `lunora-performance-audit`
56
+ - Schema/data migrations: `lunora-migration-helper`
57
+ - Deploying (wrangler, bindings, secrets, the drift gate): `lunora-deploy`
58
+ - Slow queries, scans, write conflicts: `lunora-performance-audit`
59
+
60
+ ### Reviewing existing `lunora/` code
65
61
 
66
- **Reviewing or auditing existing `lunora/` code** has no skill of its own,
67
- because two commands do the work mechanically — run them before reading
68
- anything:
62
+ There is no review skill because two commands do the mechanical part. Run them
63
+ before reading code by hand:
69
64
 
70
65
  ```bash
71
- lunora verify # wrangler config + codegen dry-run + tsc --noEmit
72
- lunora advisor # the static + runtime lint set, scored per procedure
66
+ lunora verify # does it build and typecheck
67
+ lunora advisor # static + runtime lint set, scored per procedure
73
68
  ```
74
69
 
75
- `lunora advisor` is the security/quality review: RLS coverage, ownership and
76
- identity checks, fail-open guards, input validators, unindexed reads,
77
- non-deterministic calls in queries, SQL interpolation, and leaked secrets. It
78
- prints each finding's own lint id and category, so read its output rather than
79
- grepping for rule names. Use `--entry <file>#<export>` to inspect one procedure
80
- and `--min-score` / `--baseline` to gate CI. Only after it is clean is a by-hand
81
- pass over `lunora-functions` worth the tokens.
82
-
83
- If one of those clearly matches the user's goal, switch to it instead of staying
84
- in this skill.
85
-
86
- ## Capabilities Without a Dedicated Skill
87
-
88
- Most other capabilities install as a **registry item** — `lunora registry add
89
- <item>` scaffolds the `lunora/` glue, wrangler bindings, and env vars, then
90
- prints post-install steps. Browse with `lunora registry list`; preview with
91
- `lunora registry view <item>`. Read the installed item's README, and the
92
- package's `docs/` for the API.
93
-
94
- | Goal | Install / package |
95
- | --------------------------------------------- | ------------------------------------------------------------ |
96
- | Background jobs on Cloudflare Queues | `registry add queue` → `@lunora/queue` (`ctx.queues`) |
97
- | Durable multi-step workflows | `registry add workflow` → `@lunora/workflow` (`ctx.runStep`) |
98
- | Durable AI agents (tool loops, HITL, memory) | `@lunora/agent` (`defineAgent`) |
99
- | Workers AI / RAG | `registry add ai` → `@lunora/ai` (`ctx.ai`, `defineRag`) |
100
- | Feature flags (OpenFeature) | `registry add flags` → `@lunora/flags` (`ctx.flags`) |
101
- | Payments (Stripe / Polar) | `registry add payment` → `@lunora/payment` |
102
- | Rate limiting | `registry add ratelimit` → `@lunora/ratelimit` |
103
- | Headless browser (action-only) | `registry add browser` → `@lunora/browser` (`ctx.browser`) |
104
- | Cloudflare Containers | `@lunora/container` (`defineContainer`, `ctx.containers`) |
105
- | Presence / who's-here | `registry add presence` |
106
- | Cloudflare Access (Zero Trust) identity | `registry add cloudflare-access` |
107
- | Backup / restore | `registry add backup` |
108
- | Testing (in-memory harness, agent doubles) | `@lunora/testing` (`lunoraTest`) |
109
- | Deterministic seed data | `@lunora/seed` + `lunora seed` |
110
- | Local-first replica / offline mirror | `@lunora/replica` |
111
- | Exposing the deployment to AI agents over MCP | `@lunora/mcp` |
112
-
113
- Scaffolding inside this repo uses `vis generate lunora-<kind>` — `query`,
114
- `mutation`, `action`, `http-route`, `table`, `cron`, `container`, `workflow`,
115
- `queue`, `step`, `agent`, `flags`, `collections`, `package` (`vis generate
116
- --list` for the full set). Most take a name: **always** pass it as
117
- `--name=value`, since vis parses a space-separated `--name foo` as `--name=true`
118
- plus a stray positional. `lunora-flags` and `lunora-collections` are singletons
119
- and take no name.
120
-
121
- ## Exposing a Deployment Over MCP
122
-
123
- `@lunora/mcp` puts a **running deployment** behind an MCP server (`lunora-mcp`),
124
- so an agent can introspect and call it. It needs `LUNORA_URL` and
125
- `LUNORA_ADMIN_TOKEN` — the admin bearer, which cannot be scoped down, because
126
- every tool reads admin-gated routes. The safety story is therefore the gates
127
- below, never the credential.
128
-
129
- Always advertised, no gate:
130
-
131
- | Tool | What it does |
132
- | ---------------------------- | ---------------------------------------------------------------------- |
133
- | `lunora_list_functions` | The deployment's public functions and their kinds. |
134
- | `lunora_list_tables` | `.global()` tables with row counts. |
135
- | `lunora_get_function_schema` | One function's argument descriptors, so a caller can build valid args. |
136
- | `lunora_run_query` | Runs a query. Read-only. |
137
- | `lunora_explain_error` | Explains an error `code` or raw `message` from the static catalog. |
138
-
139
- `lunora_explain_error` touches no deployment and needs no token — the catalog is
140
- compiled into `@lunora/errors`. Reach for it before guessing at what a Lunora
141
- error means.
142
-
143
- **Three env gates hold back everything else.** Each one both omits the tool from
144
- the advertised list _and_ refuses it at dispatch, so the guarantee does not
145
- depend on the client behaving:
70
+ `lunora advisor` covers RLS coverage, ownership and identity checks, fail-open
71
+ guards, input validators, unindexed reads, non-deterministic calls in queries,
72
+ SQL interpolation and leaked secrets. It prints each finding's lint id and
73
+ category, so read its output rather than guessing rule names. `--entry
74
+ <file>#<export>` inspects one procedure; `--min-score` / `--baseline` gate CI.
75
+ Once it is clean, a by-hand pass against `lunora-functions` is worth the tokens.
76
+
77
+ ## Core mental model
78
+
79
+ - Functions live in `lunora/**/*.ts` and import their builders from the
80
+ generated server module: `query` (reactive read), `mutation` (transactional
81
+ write), `action` (side effects, `fetch`, no direct db). `internalQuery` /
82
+ `internalMutation` / `internalAction` are not callable from clients.
83
+ - Schema lives in `lunora/schema.ts` (`defineSchema` + `defineTable`, validators
84
+ from `v.*`), imported from `lunorash/server` or `@lunora/server`.
85
+ - Function references mirror the folder tree: `lunora/billing/invoices.ts`
86
+ exporting `create` is `api.billing.invoices.create`. Public references come
87
+ from `_generated/api`, internal ones from `_generated/internal` (kept separate
88
+ so client bundles never carry internal names). A reference is a plain
89
+ `{ __lunoraRef: "billing_invoices:create" }` object; there is no `anyApi`
90
+ proxy.
91
+ - Reads go through indexes: declare `.index("by_x", ["x"])` and query with
92
+ `ctx.db.query("t").withIndex("by_x", (q) => q.eq("x", value))`, not
93
+ `.filter(...)`.
94
+ - Clients subscribe over WebSocket; `useQuery` re-renders when a mutation
95
+ changes the queried rows. Subscriptions run under the socket's verified
96
+ identity, so `rls()` and `ctx.auth` apply to live updates too.
97
+
98
+ ## Capabilities without a dedicated skill
99
+
100
+ Most add-ons install as a registry item: `lunora add <feature>` (or
101
+ `lunora registry add <item>`) scaffolds the `lunora/` glue, wrangler bindings
102
+ and `.dev.vars` entries, then prints post-install steps. Browse with
103
+ `lunora registry list`, preview with `lunora registry view <item>`. Read the
104
+ installed item's README and the package's `docs/` for the API.
105
+
106
+ | Goal | Install / package |
107
+ | --------------------------------------------- | ---------------------------------------------------------- |
108
+ | Background jobs on Cloudflare Queues | `lunora add queue` → `@lunora/queue` (`ctx.queues`) |
109
+ | Durable multi-step workflows | `lunora add workflow` → `@lunora/workflow` (`ctx.runStep`) |
110
+ | Durable AI agents (tool loops, HITL, memory) | `@lunora/agent` (`defineAgent`) |
111
+ | Workers AI / RAG | `lunora add ai` → `@lunora/ai` (`ctx.ai`, `defineRag`) |
112
+ | Feature flags (OpenFeature) | `lunora add flags` → `@lunora/flags` (`ctx.flags`) |
113
+ | Payments (Stripe / Polar) | `lunora add payment` → `@lunora/payment` |
114
+ | Agent payments (x402) | `@lunora/x402` |
115
+ | Push / in-app / webhook notifications | `@lunora/notify` (`ctx.notify`, `ctx.push`) |
116
+ | Rate limiting | `lunora add ratelimit` → `@lunora/ratelimit` |
117
+ | Headless browser (action-only) | `lunora add browser` → `@lunora/browser` (`ctx.browser`) |
118
+ | Cloudflare Containers | `@lunora/container` (`defineContainer`, `ctx.containers`) |
119
+ | Presence / who's-here | `lunora add presence` |
120
+ | Cloudflare Access (Zero Trust) identity | `lunora add cloudflare-access` |
121
+ | Backup / restore | `lunora add backup` |
122
+ | Testing (in-memory harness, agent doubles) | `@lunora/testing` (`lunoraTest`) |
123
+ | Deterministic seed data | `@lunora/seed` + `lunora seed` |
124
+ | Local-first replica / offline mirror | `@lunora/replica` |
125
+ | Exposing the deployment to AI agents over MCP | `@lunora/mcp` (below) |
126
+
127
+ Inside the Lunora monorepo, `vis generate lunora-<kind>` scaffolds code:
128
+ `query`, `mutation`, `action`, `http-route`, `table`, `cron`, `container`,
129
+ `workflow`, `queue`, `step`, `agent`, `package`, plus the no-name singletons
130
+ `flags`, `auth-do` and `collections` (`vis generate --list` for the set). Pass
131
+ names as `--name=value`: vis parses `--name foo` as `--name=true` plus a stray
132
+ positional.
133
+
134
+ ## Exposing a deployment over MCP
135
+
136
+ Two entry points:
137
+
138
+ - `lunora mcp install` wires an editor (Claude Code, Cursor, …) to the hosted
139
+ docs server plus this project's dev server; `lunora mcp serve` is the stdio
140
+ server those entries spawn (`--allow-writes`, `--token` opt into more).
141
+ - The `lunora-mcp` binary from `@lunora/mcp` fronts a deployed Worker. It needs
142
+ `LUNORA_URL` and `LUNORA_ADMIN_TOKEN`. Every tool reads admin-gated routes, so
143
+ the token cannot be scoped down; safety comes from the gates below.
144
+
145
+ Always advertised: `lunora_list_functions`, `lunora_list_tables` (`.global()`
146
+ tables with row counts), `lunora_get_function_schema`, `lunora_run_query`
147
+ (read-only), and `lunora_explain_error`, which explains an error `code` or
148
+ message from the catalog compiled into `@lunora/errors` and needs no
149
+ deployment. Use it before guessing what a Lunora error means.
150
+
151
+ Everything else sits behind an env gate that both hides the tool and refuses it
152
+ at dispatch. All default to off; enable one only when the answer to "may a model
153
+ see this?" is yes.
146
154
 
147
155
  - `LUNORA_MCP_ALLOW_WRITES` → `lunora_run_mutation`, `lunora_run_action`.
148
156
  - `LUNORA_MCP_ALLOW_OBSERVABILITY` → the five `lunora_get_*` tools (logs,
149
157
  issues, advisories, query insights, migration status). Read-only, but they
150
- return production log lines and error messages — user data that lands at the
151
- model provider.
152
- - `LUNORA_MCP_ALLOW_DATA_READS` → `lunora_find_related`. **It returns raw table
153
- rows read through the deployment's admin writer, with RLS policies and column
154
- masks bypassed**, plus everything reachable within `depth` hops. It is
155
- deliberately not folded into the observability gate: enabling log reading for
156
- debugging must not silently also hand over every row.
157
-
158
- All three default to **off**. Set one only when the answer to "may a model see
159
- this?" is yes.
160
-
161
- ### Writes are a two-step handshake
162
-
163
- Past `LUNORA_MCP_ALLOW_WRITES`, each individual write still needs its own
164
- confirmation. The first `lunora_run_mutation` / `lunora_run_action` call does
165
- **not** execute — it returns `status: "action_required"` carrying
166
- `proposedAction`, an `actionDigest`, and the `expiresAt` it is valid until (ten
167
- minutes). The client shows that to a human, then calls the same tool again with
168
- the identical `functionPath`, `args` and `shardKey`, plus `confirmed: true` and
169
- that digest.
170
-
171
- Editing anything produces a different digest and needs a fresh proposal; an
172
- expired digest is refused rather than quietly re-proposed. Be precise about what
173
- this buys: the digest binds the **call**, proving the write that runs is exactly
174
- the one proposed on this deployment inside the window. It does **not** prove a
175
- human ever saw it — an MCP server has no channel to a person, and a client that
176
- asks nobody can echo the digest straight back. Enabling writes is the operator
177
- asserting that the client on the other end does the asking.
178
-
179
- ## Core Mental Model
180
-
181
- - **Functions** live in `lunora/*.ts` and are one of `query` (reactive read),
182
- `mutation` (transactional write), or `action` (side effects / `fetch` / no
183
- direct db). `internalQuery` / `internalMutation` / `internalAction` are the
184
- non-public variants.
185
- - **Schema** lives in `lunora/schema.ts` via `defineSchema` + `defineTable`,
186
- with validators from `v.*` (re-exported by `@lunora/server`).
187
- - **Reads go through indexes.** Prefer `ctx.db.query("t").withIndex(...)` over
188
- `.filter(...)`; declare the index with `.index("by_x", ["x"])`.
189
- - **Clients** subscribe over WebSocket. `useQuery`/`useMutation` (React, Vue,
190
- Solid, Svelte, React Native; signals in Angular) re-render the moment a
191
- mutation changes the queried rows. Subscriptions run under the socket's
192
- verified identity, so `rls()` / `ctx.auth` apply to live updates too.
193
-
194
- ## When Not to Use
195
-
196
- - The user has already named a more specific Lunora workflow.
197
- - Another Lunora skill obviously fits the request better.
158
+ return production log lines and error messages, which then reach the model
159
+ provider.
160
+ - `LUNORA_MCP_ALLOW_DATA_READS` → `lunora_find_related`. It returns raw rows
161
+ read through the admin writer, with RLS and column masks bypassed. It is kept
162
+ separate from observability so enabling logs never also hands over rows.
163
+ - `LUNORA_MCP_ALLOW_AGENTS` (with `LUNORA_MCP_AGENTS="name:description;…"`) →
164
+ the `agent_<name>` tools and `lunora_agent_status`.
165
+
166
+ Writes are a two-step handshake. The first `lunora_run_mutation` /
167
+ `lunora_run_action` call does not execute; it returns `status:
168
+ "action_required"` with `proposedAction`, an `actionDigest`, and an `expiresAt`
169
+ ten minutes out. The client shows that to a human, then repeats the call with
170
+ identical `functionPath`, `args` and `shardKey` plus `confirmed: true` and the
171
+ digest. Any edit needs a fresh proposal, and an expired digest is refused. The
172
+ digest proves the write that runs is the one proposed; it does not prove a human
173
+ saw it, so enabling writes means trusting the client to ask.
@@ -1,47 +1,36 @@
1
1
  ---
2
2
  name: lunora-create-package
3
- description: Builds a reusable Lunora capability — either a registry item installed with
4
- `lunora registry add`, or a publishable `@lunora/*` workspace package. Use for
5
- packaging schema + functions + bindings others can drop into their app.
3
+ description: Builds a reusable Lunora capability, either as a registry item that
4
+ `lunora add` / `lunora registry add` copies into an app's `lunora/`, or as a
5
+ publishable `@lunora/*` workspace package in the Lunora monorepo. Use when the
6
+ user wants to package schema + functions + wrangler bindings + env vars for
7
+ other apps, add or edit an item under `registry/<name>/` (`registry.json`),
8
+ run `vis generate lunora-package`, or wire a new `ctx.*` capability into
9
+ codegen.
6
10
  ---
7
11
 
8
12
  # Lunora Create Package
9
13
 
10
- Package a reusable Lunora capability. There are two distribution shapes; pick
11
- based on whether the capability is **copied into the user's `lunora/`** or
12
- **imported as a dependency**.
14
+ Pick the shape by whether the code is copied into the user's `lunora/` or
15
+ imported as a dependency:
13
16
 
14
- | Shape | Distribution | Use for |
15
- | ----------------- | -------------------------------- | -------------------------------------------------------- |
16
- | **Registry item** | `lunora registry add <name>` | App-owned code (schema/functions) the user edits + wires |
17
- | **Workspace pkg** | `import … from "@lunora/<name>"` | Reusable library code imported as a dependency |
17
+ | Shape | Distribution | Use for |
18
+ | ------------- | -------------------------------- | ------------------------------------------------ |
19
+ | Registry item | `lunora registry add <name>` | App-owned code (schema/functions) the user edits |
20
+ | Workspace pkg | `import … from "@lunora/<name>"` | Library code consumed as a versioned dependency |
18
21
 
19
- Many capabilities use **both**: a thin `@lunora/<name>` package holding the
20
- reusable runtime, plus a registry item that scaffolds the glue (`lunora/<name>/`
21
- files, bindings, env vars) into the user's project. `auth`, `mail`, `ratelimit`,
22
- and `storage` all follow this pattern.
22
+ Many capabilities use both: a `@lunora/<name>` package holds the runtime and a
23
+ registry item scaffolds the glue (files under `lunora/<name>/`, bindings, env
24
+ vars). `auth`, `mail`, `ratelimit` and `storage` follow this pattern.
23
25
 
24
- ## When to Use
26
+ Skip this skill for a one-off feature in a single app (write it in `lunora/`),
27
+ or when the capability already exists (`lunora registry list`).
25
28
 
26
- - Extracting schema + functions you have written into something reusable.
27
- - Authoring a new capability (presence, search, payments, …) for other apps.
28
- - Adding a new item to this repo's `registry/`.
29
+ ## Path A: registry item
29
30
 
30
- ## When Not to Use
31
-
32
- - A one-off feature for a single app — just write it in `lunora/`.
33
- - The capability already exists as a registry item or `@lunora/*` package — use
34
- it (`lunora registry list` to browse).
35
-
36
- ## Path A: Registry Item
37
-
38
- A registry item is a directory under `registry/<name>/` with three files:
39
-
40
- - `registry.json` — the manifest (deps, bindings, env vars, files, requires).
41
- - `index.ts` (and any siblings) — the code copied into the user's project.
42
- - `README.md` — install + configuration docs.
43
-
44
- ### Manifest shape
31
+ An item is a directory `registry/<name>/` holding `registry.json`, the source
32
+ files it copies, and a `README.md`. Validate against
33
+ `registry/schema/registry-item.schema.json`.
45
34
 
46
35
  ```jsonc
47
36
  // registry/<name>/registry.json
@@ -50,81 +39,104 @@ A registry item is a directory under `registry/<name>/` with three files:
50
39
  "name": "<name>",
51
40
  "title": "Human Title",
52
41
  "description": "One-paragraph summary shown in `lunora registry list`.",
53
- "docs": "Post-install steps surfaced to the user after `lunora registry add`.",
54
- "requires": [], // other item names this one depends on
42
+ "docs": "Post-install steps printed after `lunora registry add`.",
43
+ "requires": [], // other items, installed first (e.g. auth-clerk requires auth)
55
44
  "deps": { "@lunora/server": "workspace:*" },
45
+ "devDependencies": {},
56
46
  "bindings": [
57
- // reconciled into wrangler.jsonc
47
+ // structural edits applied to wrangler.jsonc
58
48
  { "path": ["d1_databases"], "value": [{ "binding": "DB", "database_name": "REPLACE_ME-db", "database_id": "<replace-with-d1-create-id>" }] },
59
49
  ],
60
50
  "envVars": [{ "name": "MY_SECRET", "description": "What it is and how to generate it.", "secret": true }],
61
- "files": [{ "from": "index.ts", "to": "lunora/<name>/index.ts", "merge": "create-or-skip" }],
51
+ "files": [
52
+ { "from": "schema.ts", "to": "lunora/<name>/schema.ts", "merge": "schema-extension" },
53
+ { "from": "<name>.ts", "to": "lunora/<name>/index.ts", "merge": "create-or-skip" },
54
+ ],
62
55
  }
63
56
  ```
64
57
 
65
- - `files[].merge` is typically `create-or-skip` (never clobber edited user code);
66
- `bindings` are reconciled into `wrangler.jsonc`; `envVars` are scaffolded into
67
- `.dev.vars` (secret-looking ones get generated values).
68
- - `requires` lets a provider item (e.g. `auth-clerk`) build on a base item
69
- (`auth`). The resolver installs the chain.
70
-
71
- ### Register and validate
72
-
73
- Add an entry to `registry/index.json`, then rebuild and check the index:
58
+ - `files[].merge`: `create-or-skip` writes whole files and never clobbers a file
59
+ the user edited; `schema-extension` AST-merges into `lunora/schema.ts`.
60
+ - `envVars` land in `.dev.vars`. Non-secret vars get their `value`; secrets get
61
+ an empty placeholder plus a `wrangler secret put <NAME>` reminder.
62
+ - `entrypointReexports` (`[{ "module": "_generated/workflows" }]`) injects
63
+ `export * from './lunora/<module>'` into the worker entry of framework
64
+ (class B/C) projects, for items whose generated classes the worker must
65
+ export. No shipped item uses it yet.
66
+ - Function files import builders from `#lunora/_generated/server.js`, the
67
+ module codegen emits in a consumer project. `registry/tsconfig.json` stubs
68
+ that module so the item typechecks here.
69
+ - `deps` ranges are copied verbatim into the user's `package.json`. Use
70
+ `workspace:*` for `@lunora/*` (resolved at publish); any other range must
71
+ admit the version the workspace resolves, or `pnpm install` fails
72
+ (`scripts/check-registry-catalog-ranges.js`).
73
+
74
+ Verify:
74
75
 
75
76
  ```bash
76
- lunora registry build --from ./registry # regenerate registry/index.json
77
- lunora registry build --from ./registry --check # verify the index is up to date (CI)
78
- lunora registry view <name> # preview what `add` would do
79
- lunora registry add <name> # install into the current project
77
+ lunora registry build --from ./registry # regenerate registry/index.json from the item dirs
78
+ lunora registry build --from ./registry --check # CI: index is current
79
+ pnpm run lint:types:registry # tsc over every item (builds packages first)
80
+ pnpm run lint:registry:items # manifest + generated-deps tests
81
+ lunora registry view <name> --from <repo>/registry # preview
82
+ lunora registry add <name> --from <repo>/registry --dry-run # in a scratch app
80
83
  ```
81
84
 
82
- ## Path B: Workspace Package
85
+ `registry/index.json` is generated; do not hand-edit it.
83
86
 
84
- Scaffold a fresh `@lunora/<name>` package with the generator (always use the
85
- `--name=value` form):
87
+ ## Path B: workspace package (Lunora monorepo)
86
88
 
87
89
  ```bash
88
- vis generate lunora-package --name=search --description='Typed full-text search over Lunora tables'
90
+ vis generate lunora-package --name=search --description='Typed full-text search over Lunora tables' --category=add-on
89
91
  ```
90
92
 
91
- This creates `packages/search/` following the repo's package shape: `src/index.ts`,
92
- `__tests__/`, `vitest.config.ts`, `tsconfig.json` (extends `../../tsconfig.base.json`),
93
- `project.json` (vis tags `type:package` + `category:<slug>`), `package.json` (ESM,
94
- `"sideEffects": false`, conditional exports), and `.releaserc.json`.
93
+ Pass every option as `--name=value`; vis reads `--name search` as
94
+ `--name=true` plus a stray positional.
95
+
96
+ This writes `packages/search/` with `package.json` (ESM-only,
97
+ `"sideEffects": false`, catalog versions), `src/index.ts`, `tsconfig.json`,
98
+ `vitest.config.ts`, `packem.config.ts`, `eslint.config.js`,
99
+ `prettier.config.js`, `project.json` (tags `type:package` +
100
+ `category:<category>`), `.releaserc.json` and `README.md`. It does not create
101
+ `__tests__/` or `LICENSE.md`. Then:
95
102
 
96
- ### Repo conventions to honor
103
+ 1. `cp packages/config/LICENSE.md packages/search/LICENSE.md` (packem and
104
+ `files` expect it).
105
+ 2. Add a row to `.agents/docs/packages.md`, and list the directory in one tier
106
+ of `scripts/api-snapshot.js` and the matching tier in `ROADMAP.md`. The
107
+ `pnpm install` postinstall checks (`check-agents-md-packages`,
108
+ `check-roadmap-tiers`) fail until both are done.
109
+ 3. `pnpm install`, then add tests under `__tests__/`.
97
110
 
98
- - **No `.js` extensions** in relative imports (`moduleResolution: "bundler"`).
99
- The lone exception is `@lunora/codegen`'s emitted output.
100
- - **No mixed default + named exports** in one file — named-only when there is
101
- more than one export.
102
- - **Use the dependency catalogs** in `pnpm-workspace.yaml` (`catalog:test`,
103
- `catalog:lint`, …) — never hard-code a version that lives in a catalog.
104
- - Tag `project.json` with `type:package` and a `category:<slug>`.
111
+ Repo conventions: relative imports without `.js`, named exports only (a
112
+ `default` only as a file's sole export), dependency versions via `catalog:*`
113
+ from `pnpm-workspace.yaml`.
105
114
 
106
- Build and test the new package in isolation:
115
+ Verify:
107
116
 
108
117
  ```bash
118
+ pnpm --filter "@lunora/search..." run build
109
119
  pnpm --filter "@lunora/search" run lint:types
110
120
  pnpm --filter "@lunora/search" run test
121
+ pnpm run lint:package-json
122
+ pnpm run api:update # writes api-snapshots/search.api.md from the fresh build; commit it
111
123
  ```
112
124
 
113
- ## Codegen-Wired Capabilities
114
-
115
- If your capability surfaces functions on a context (e.g. `ctx.ai`, `ctx.containers`)
116
- or new generated tables, it must be discoverable by `@lunora/codegen` — codegen
117
- parses `lunora/schema.ts` and the function files. Document any `lunora/*.ts`
118
- declaration the user must add so codegen wires the typed surface.
119
-
120
- ## Checklist
121
-
122
- - [ ] Chose the right shape (registry item, workspace package, or both).
123
- - [ ] Registry item: `registry.json` + `index.ts` + `README.md` authored;
124
- `bindings`/`envVars`/`requires`/`files` correct.
125
- - [ ] `lunora registry build --from ./registry` run; the same command with
126
- `--check` passes.
127
- - [ ] Workspace package: scaffolded via `vis generate lunora-package`; no `.js`
128
- extensions, no mixed default+named exports, catalog versions used.
129
- - [ ] `lint:types` and `test` pass for the new package.
130
- - [ ] README documents install, bindings, env vars, and any `lunora/` glue.
125
+ ## Wiring a `ctx.*` capability into codegen
126
+
127
+ Codegen decides which `ctx.*` fields exist by detecting usage, so a new
128
+ binding-backed helper is a literal row in `CAPABILITY_ROWS`
129
+ (`packages/codegen/src/capabilities.ts`; `CAPABILITIES` is a read-only view of
130
+ it): its package, `ctx` property, tier
131
+ (`"every"` or `"action"`-only), ctx type fragment, ShardDO binding, and
132
+ `defineApp` method. Rate the feature for every target in the
133
+ `PlatformCapabilities` matrices in `@lunora/platform`
134
+ (`packages/platform/src/capabilities/`) as `native`, `emulated` or
135
+ `unsupported` in the same change. A feature a target leaves unrated is dropped
136
+ from that target's generated surface with a diagnostic. Declaration-gated
137
+ surfaces (flags, notify, containers, workflows, queues, agents) also have their
138
+ own emitters; some of them (flags, notify, containers, workflows) keep a row too,
139
+ for usage probing, so a row and a dedicated emitter can coexist.
140
+
141
+ Document in the README any `lunora/*.ts` declaration the user must add for
142
+ codegen to emit the typed surface.