@lunora/cli 0.0.0 → 1.0.0-alpha.10

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 (75) hide show
  1. package/LICENSE.md +105 -0
  2. package/README.md +109 -9
  3. package/__assets__/package-og.svg +14 -0
  4. package/dist/bin.mjs +11 -0
  5. package/dist/index.d.mts +956 -0
  6. package/dist/index.d.ts +956 -0
  7. package/dist/index.mjs +19 -0
  8. package/dist/packem_chunks/handler.mjs +150 -0
  9. package/dist/packem_chunks/handler10.mjs +22 -0
  10. package/dist/packem_chunks/handler11.mjs +192 -0
  11. package/dist/packem_chunks/handler12.mjs +131 -0
  12. package/dist/packem_chunks/handler13.mjs +65 -0
  13. package/dist/packem_chunks/handler14.mjs +58 -0
  14. package/dist/packem_chunks/handler15.mjs +79 -0
  15. package/dist/packem_chunks/handler16.mjs +43 -0
  16. package/dist/packem_chunks/handler17.mjs +105 -0
  17. package/dist/packem_chunks/handler18.mjs +170 -0
  18. package/dist/packem_chunks/handler19.mjs +89 -0
  19. package/dist/packem_chunks/handler2.mjs +114 -0
  20. package/dist/packem_chunks/handler20.mjs +94 -0
  21. package/dist/packem_chunks/handler21.mjs +311 -0
  22. package/dist/packem_chunks/handler3.mjs +204 -0
  23. package/dist/packem_chunks/handler4.mjs +33 -0
  24. package/dist/packem_chunks/handler5.mjs +49 -0
  25. package/dist/packem_chunks/handler6.mjs +91 -0
  26. package/dist/packem_chunks/handler7.mjs +42 -0
  27. package/dist/packem_chunks/handler8.mjs +174 -0
  28. package/dist/packem_chunks/handler9.mjs +16 -0
  29. package/dist/packem_chunks/planDevCommand.mjs +500 -0
  30. package/dist/packem_chunks/runCodegenCommand.mjs +52 -0
  31. package/dist/packem_chunks/runDeployCommand.mjs +504 -0
  32. package/dist/packem_chunks/runInitCommand.mjs +1498 -0
  33. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +397 -0
  34. package/dist/packem_chunks/runResetCommand.mjs +41 -0
  35. package/dist/packem_chunks/runRpcCommand.mjs +68 -0
  36. package/dist/packem_shared/COMMANDS-D3h9Iwvl.mjs +944 -0
  37. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +244 -0
  38. package/dist/packem_shared/admin-url-4UzT-CI4.mjs +19 -0
  39. package/dist/packem_shared/api-spec-CtA6ilu4.mjs +13 -0
  40. package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +38 -0
  41. package/dist/packem_shared/command-BC30oSBW.mjs +14 -0
  42. package/dist/packem_shared/commands-DPKWlqqX.mjs +812 -0
  43. package/dist/packem_shared/createLogger-B40gPzQo.mjs +78 -0
  44. package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +43 -0
  45. package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +61 -0
  46. package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +161 -0
  47. package/dist/packem_shared/docker-hMQ97KSQ.mjs +21 -0
  48. package/dist/packem_shared/insertSchemaExtension-BuzF6-t2.mjs +59 -0
  49. package/dist/packem_shared/open-url-Dfq6fAyT.mjs +41 -0
  50. package/dist/packem_shared/output-format-wUvAN6AL.mjs +17 -0
  51. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +56 -0
  52. package/dist/packem_shared/parseManifest--vZf2FY1.mjs +94 -0
  53. package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +16 -0
  54. package/dist/packem_shared/runAddCommand-CTRA_JlL.mjs +4 -0
  55. package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +79 -0
  56. package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +43 -0
  57. package/dist/packem_shared/storage-2RJBhUC4.mjs +84 -0
  58. package/dist/packem_shared/tui-prompts-DEiPCKV-.mjs +661 -0
  59. package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +12 -0
  60. package/package.json +62 -18
  61. package/skills/README.md +29 -0
  62. package/skills/lunora/SKILL.md +83 -0
  63. package/skills/lunora-create-package/SKILL.md +129 -0
  64. package/skills/lunora-deploy/SKILL.md +150 -0
  65. package/skills/lunora-functions/SKILL.md +182 -0
  66. package/skills/lunora-migration-helper/SKILL.md +194 -0
  67. package/skills/lunora-performance-audit/SKILL.md +143 -0
  68. package/skills/lunora-quickstart/SKILL.md +240 -0
  69. package/skills/lunora-realtime/SKILL.md +177 -0
  70. package/skills/lunora-setup-auth/SKILL.md +170 -0
  71. package/skills/lunora-setup-hyperdrive/SKILL.md +154 -0
  72. package/skills/lunora-setup-hyperdrive-global/SKILL.md +171 -0
  73. package/skills/lunora-setup-mail/SKILL.md +151 -0
  74. package/skills/lunora-setup-scheduler/SKILL.md +157 -0
  75. package/skills/lunora-setup-storage/SKILL.md +158 -0
@@ -0,0 +1,956 @@
1
+ import { CodegenOptions, SchemaIR } from '@lunora/codegen';
2
+ import '@visulima/cerebro';
3
+ import { ensureDevVariables, ensureDevVarsExample, materializeRemoteWranglerConfig } from '@lunora/config';
4
+ export { REQUIRED_COMPATIBILITY_DATE, REQUIRED_FLAG, type WranglerProjectValidationOptions as WranglerValidationOptions, type WranglerValidationReport, type WranglerProjectValidationResult as WranglerValidationResult, validateWranglerProject as validateWrangler, validateWranglerConfig } from '@lunora/config';
5
+ /** Every command name the CLI registers (drives the `CommandName` type + tests). */
6
+ declare const COMMANDS: readonly ["init", "add", "dev", "codegen", "build", "deploy", "containers", "prepare", "link", "deployments", "logs", "run", "insights", "reset", "migrate", "export", "import", "seed", "backup", "verify", "info", "doctor", "env", "analyze", "view", "docs", "registry", "rules"];
7
+ type CommandName = (typeof COMMANDS)[number];
8
+ declare const VERSION: string;
9
+ interface RunCliOptions {
10
+ argv?: ReadonlyArray<string>;
11
+ cwd?: string;
12
+ /**
13
+ * Inject a console-like logger so callers (tests) can capture cerebro's
14
+ * help / version / usage rendering. Omitted in production, where cerebro
15
+ * uses its default stdout/stderr logger.
16
+ */
17
+ logger?: Console;
18
+ }
19
+ /**
20
+ * Run the CLI and resolve to the process exit code. cerebro handles help,
21
+ * version, usage, and unknown commands (the latter throws, caught here as 1).
22
+ * `shouldExitProcess: false` keeps the process alive so callers/tests read the
23
+ * captured exit code.
24
+ */
25
+ declare const runCli: (options?: RunCliOptions) => Promise<number>;
26
+ /**
27
+ * The `--api-spec` flag's accepted values, mirroring `@lunora/codegen`'s
28
+ * `CodegenOptions["apiSpec"]`. `"openapi"` (the default) emits `openapi.json`;
29
+ * `"openrpc"` emits `openrpc.json`; `"both"` emits both; `"none"` emits neither.
30
+ */
31
+ type ApiSpec = NonNullable<CodegenOptions["apiSpec"]>;
32
+ interface Logger {
33
+ debug?: (message: string) => void;
34
+ error: (message: string) => void;
35
+ info: (message: string) => void;
36
+ success: (message: string) => void;
37
+ warn: (message: string) => void;
38
+ }
39
+ /**
40
+ * Narrowed view over the pail instance. `createPail` returns an intersection
41
+ * type that includes a constructor signature and `(...args: any[])` logger
42
+ * overloads, which the type-aware linter cannot safely resolve. We only ever
43
+ * call the level methods with a string, so we describe exactly that surface.
44
+ */
45
+ interface PailLogger {
46
+ debug: (message: string) => void;
47
+ error: (message: string) => void;
48
+ info: (message: string) => void;
49
+ success: (message: string) => void;
50
+ warn: (message: string) => void;
51
+ }
52
+ declare const createLogger: () => Logger;
53
+ /**
54
+ * Logger whose every channel writes to `process.stderr`. Used by commands in
55
+ * `--format json` mode so all human/progress output stays off stdout — leaving
56
+ * stdout for the single JSON document the command prints, so `… --format json`
57
+ * stays cleanly pipeable (`| jq`). Each line carries a one-character level tag
58
+ * so the stream is still readable when a human watches it.
59
+ */
60
+ /**
61
+ * Direct access to the underlying pail instance for advanced use-cases.
62
+ * A Proxy keeps the public `pail` binding lazy: the real pail is only
63
+ * constructed on first property access, so importing this module (and thus
64
+ * the package barrel) stays side-effect-free.
65
+ */
66
+ declare const pail: PailLogger;
67
+ /**
68
+ * Emit a badged step line through the shared pail (the `init` flow's off-TTY
69
+ * fallback for the create-astro-style transcript). The `message` may contain
70
+ * newlines — `LunoraReporter` indents continuation lines under the badge so a
71
+ * dimmed answer sits below its question.
72
+ */
73
+ interface CodegenCommandOptions {
74
+ /** Which API spec(s) to emit. Defaults to codegen's `"openapi"` when omitted. */
75
+ apiSpec?: ApiSpec;
76
+ cwd?: string;
77
+ /** Output format: `pretty` (default) or `json`. */
78
+ format?: string;
79
+ logger: Logger;
80
+ }
81
+ interface CodegenCommandResult {
82
+ advisories: ReadonlyArray<{
83
+ detail: string;
84
+ level: string;
85
+ name: string;
86
+ remediation: string;
87
+ }>;
88
+ cronTriggers: ReadonlyArray<string>;
89
+ /** Set when the run aborted on an invalid `--format` before codegen ran. */
90
+ error?: string;
91
+ outputDirectory: string;
92
+ }
93
+ declare const runCodegenCommand: (options: CodegenCommandOptions) => CodegenCommandResult;
94
+ /** `lunora codegen` handler (lazy-loaded via the command's `loader`). */
95
+ /** Rows per HTTP request when importing. Convex uses ~500; same here. */
96
+ declare const DEFAULT_IMPORT_BATCH_SIZE = 500;
97
+ /**
98
+ * Minimal projection of `globalThis.fetch` for the export path — we need
99
+ * `body` as a stream-iterable, which the shared {@link FetchLike} type
100
+ * intentionally hides for the JSON-only commands.
101
+ */
102
+ type StreamingFetchLike = (input: string, init?: {
103
+ body?: string;
104
+ headers?: Record<string, string>;
105
+ method?: string;
106
+ }) => Promise<{
107
+ body: ReadableStream<Uint8Array> | null;
108
+ json: () => Promise<unknown>;
109
+ ok: boolean;
110
+ status: number;
111
+ text: () => Promise<string>;
112
+ }>;
113
+ interface ExportCommandOptions {
114
+ cwd?: string;
115
+ fetchImpl?: StreamingFetchLike;
116
+ logger: Logger;
117
+ /** Output file path; `undefined`/`-` streams to stdout. */
118
+ out?: string;
119
+ /** Guardrail: refuse to target localhost when set. */
120
+ prod?: boolean;
121
+ /** Comma-separated table list; omit to export every table. */
122
+ tables?: string;
123
+ /** Admin bearer token (or `LUNORA_ADMIN_TOKEN`). */
124
+ token?: string;
125
+ /** Worker URL (default `http://localhost:8787`). */
126
+ url?: string;
127
+ }
128
+ interface ExportCommandResult {
129
+ bytes: number;
130
+ code: number;
131
+ /** Number of NDJSON lines streamed (0 on error). */
132
+ rows: number;
133
+ }
134
+ /**
135
+ * Stream an export. The worker emits NDJSON; we count newlines as we go and
136
+ * pipe straight to the output sink, so a 10M-row export doesn't materialise
137
+ * the body in memory.
138
+ */
139
+ declare const runExportCommand: (options: ExportCommandOptions) => Promise<ExportCommandResult>;
140
+ interface ImportCommandOptions {
141
+ /** Rows per HTTP request. Defaults to {@link DEFAULT_IMPORT_BATCH_SIZE}. */
142
+ batchSize?: number;
143
+ cwd?: string;
144
+ fetchImpl?: StreamingFetchLike;
145
+ /** Source NDJSON file. Required. */
146
+ file: string;
147
+ logger: Logger;
148
+ prod?: boolean;
149
+ /**
150
+ * Wrap each line as `{table:&lt;name>,doc:&lt;line>}`. Use when the source NDJSON
151
+ * is bare docs from a single table — Convex's `convex import --table users`
152
+ * shape.
153
+ */
154
+ table?: string;
155
+ token?: string;
156
+ url?: string;
157
+ }
158
+ interface ImportCommandResult {
159
+ body: unknown;
160
+ code: number;
161
+ /** Total inserted rows across batches. */
162
+ inserted: number;
163
+ }
164
+ /**
165
+ * Stream an NDJSON file in chunks, POSTing each batch to
166
+ * `/_lunora/admin/import`. We keep the line buffer bounded by `batchSize` so a
167
+ * multi-GiB file imports without buffering everything in memory.
168
+ */
169
+ declare const runImportCommand: (options: ImportCommandOptions) => Promise<ImportCommandResult>;
170
+ /**
171
+ * Injectable probe for a Docker-compatible container engine. Tests pass a
172
+ * stub; production uses {@link isDockerAvailable}.
173
+ */
174
+ type DockerProbe = () => boolean;
175
+ /**
176
+ * True when a Docker-compatible engine answers `docker info` — the same
177
+ * prerequisite `wrangler deploy` has for building and pushing a container
178
+ * image from a local Dockerfile. Quiet by design (output discarded): callers
179
+ * own the messaging.
180
+ */
181
+ interface SpawnDescriptor {
182
+ args: ReadonlyArray<string>;
183
+ /**
184
+ * Capture the child's stdout (in addition to streaming it to the parent), so
185
+ * the caller can parse it — used by `deploy` to read the deployed URL from
186
+ * `wrangler deploy` output. Each chunk is still teed to the parent's stdout
187
+ * so the user sees live progress. Mutually exclusive with `stdoutToStderr`.
188
+ */
189
+ captureStdout?: boolean;
190
+ command: string;
191
+ cwd?: string;
192
+ env?: Readonly<Record<string, string>>;
193
+ /**
194
+ * Pipe this string into the child's stdin and close it. Used to feed
195
+ * `wrangler secret put` its value without exposing it on the command
196
+ * line or in env. When absent, stdin is inherited from the parent.
197
+ */
198
+ input?: string;
199
+ /**
200
+ * Route the child's stdout to the parent's STDERR instead of stdout. Set in
201
+ * `--format json` mode so a spawned tool's human output (e.g. `wrangler
202
+ * deploy`'s progress + the deployed URL) can't interleave with — and corrupt
203
+ * — the single JSON document the command prints to stdout.
204
+ */
205
+ stdoutToStderr?: boolean;
206
+ }
207
+ interface SpawnResult {
208
+ code: number;
209
+ /** The captured stdout, present only when the descriptor set `captureStdout`. */
210
+ stdout?: string;
211
+ }
212
+ /**
213
+ * Injectable spawner. Tests pass a stub that just records the descriptor
214
+ * instead of executing a real subprocess.
215
+ */
216
+ type Spawner = (descriptor: SpawnDescriptor) => Promise<SpawnResult>;
217
+ declare const defaultSpawner: Spawner;
218
+ interface RecordedSpawn {
219
+ descriptor: SpawnDescriptor;
220
+ }
221
+ /**
222
+ * Test helper: returns a spawner that records every invocation and resolves
223
+ * with the configured exit code.
224
+ */
225
+ declare const createRecordingSpawner: (exitCode?: number) => {
226
+ calls: RecordedSpawn[];
227
+ spawner: Spawner;
228
+ };
229
+ type FetchLike = (input: string, init?: {
230
+ body?: string;
231
+ headers?: Record<string, string>;
232
+ method?: string;
233
+ }) => Promise<{
234
+ json: () => Promise<unknown>;
235
+ ok: boolean;
236
+ status: number;
237
+ text: () => Promise<string>;
238
+ }>;
239
+ interface RunCommandOptions {
240
+ args?: string;
241
+ cwd?: string;
242
+ fetchImpl?: FetchLike;
243
+ functionPath: string;
244
+ logger: Logger;
245
+ shard?: string;
246
+ url?: string;
247
+ }
248
+ interface RunCommandResult {
249
+ body: unknown;
250
+ code: number;
251
+ requestUrl: string;
252
+ }
253
+ declare const runRpcCommand: (options: RunCommandOptions) => Promise<RunCommandResult>;
254
+ /** `lunora run &lt;functionPath>` handler (lazy-loaded via the command's `loader`). */
255
+ interface DeployCommandOptions {
256
+ /** Override the schema-drift gate — deploy even with breaking drift and no new migration. */
257
+ allowSchemaDrift?: boolean;
258
+ /** Which API spec(s) codegen emits. Defaults to codegen's `"openapi"` when omitted. */
259
+ apiSpec?: ApiSpec;
260
+ cwd?: string;
261
+ /** Docker-availability probe injected in tests. Defaults to a real `docker info` check. */
262
+ dockerAvailable?: DockerProbe;
263
+ /**
264
+ * Validate, bundle, and run all pre-deploy gates without publishing
265
+ * (`wrangler deploy --dry-run`). Post-deploy steps (data migrations, schema
266
+ * baseline re-bless) are skipped since nothing shipped.
267
+ */
268
+ dryRun?: boolean;
269
+ env?: string;
270
+ /** Fetch implementation injected in tests for `--migrate` RPC calls. */
271
+ fetchImpl?: FetchLike;
272
+ /** Output format: `pretty` (default) or `json`. */
273
+ format?: string;
274
+ /** Set to `false` to disable interactive spinners (test injection). */
275
+ interactive?: boolean;
276
+ logger: Logger;
277
+ /**
278
+ * When true, after a successful `wrangler deploy`, discover and run all
279
+ * pending data migrations via the worker's `/_lunora/migrate` admin RPC.
280
+ * The worker must be live (exit 0) before migrations are attempted.
281
+ *
282
+ * Implementation note: the status RPC returns the full shard-level
283
+ * migration state, but there is no single authoritative "list of pending
284
+ * migration ids" that can be read client-side before running the worker.
285
+ * Instead, `--migrate` runs `migrate status` followed by `migrate up` for
286
+ * each migration id discovered locally via `discoverMigrations`. The
287
+ * worker's `MigrationRunner` is idempotent — running `up` on an already-
288
+ * applied migration is a no-op — so this approach is safe.
289
+ */
290
+ migrate?: boolean;
291
+ /** Admin bearer token for `--migrate` (falls back to `LUNORA_ADMIN_TOKEN`). */
292
+ migrateToken?: string;
293
+ /**
294
+ * Worker URL for `--migrate`. REQUIRED when `--migrate` is set — the deploy
295
+ * handler never captures the URL `wrangler deploy` published to, so there is
296
+ * no safe default; omitting it would silently target `http://localhost:8787`
297
+ * (the dev worker), applying the migration to local state instead of prod.
298
+ */
299
+ migrateUrl?: string;
300
+ /**
301
+ * Confirm a production data migration triggered via `--migrate` (the
302
+ * `migrate up --prod` confirmation the standalone command requires). Without
303
+ * it a `--migrate --migrate-url &lt;prod>` deploy refuses to run the migration.
304
+ */
305
+ migrateYes?: boolean;
306
+ /**
307
+ * Emit the bundled worker to this directory via `wrangler deploy --outdir`
308
+ * (paired with `dryRun` by `lunora build`). Also writes esbuild metadata to
309
+ * `&lt;outDir>/bundle-meta.json`. When unset, no artifact is written.
310
+ */
311
+ outDir?: string;
312
+ /**
313
+ * Upload a preview version (`wrangler versions upload`) instead of a live
314
+ * `wrangler deploy`. Codegen + the drift gate + validation still run, but
315
+ * the post-deploy finalize (migrations, baseline re-bless, auto-link, the
316
+ * production summary) is skipped — a preview never shifts live traffic.
317
+ */
318
+ preview?: boolean;
319
+ /** Railpack-availability probe injected in tests. Defaults to a real `railpack --version` + `BUILDKIT_HOST` check. */
320
+ railpackAvailable?: DockerProbe;
321
+ skipCodegen?: boolean;
322
+ spawner?: Spawner;
323
+ /**
324
+ * Deploy to a temporary Cloudflare account (`wrangler deploy --temporary`).
325
+ * For unauthenticated use only: wrangler provisions a short-lived account +
326
+ * token, deploys, and prints a claim URL; the deployment stays live ~60
327
+ * minutes before the unclaimed account is deleted. Wrangler itself errors
328
+ * if credentials are already present (OAuth / `CLOUDFLARE_API_TOKEN` /
329
+ * global API key), so we pass the flag straight through without guarding.
330
+ */
331
+ temporary?: boolean;
332
+ /** Re-bless the committed schema baseline with the current shape (accepts breaking drift). */
333
+ updateSchemaBaseline?: boolean;
334
+ }
335
+ interface DeployCommandResult {
336
+ code: number;
337
+ descriptor: SpawnDescriptor | undefined;
338
+ /** Set when the run aborted before reaching the wrangler invocation. */
339
+ error?: string;
340
+ /** The schema-drift gate verdict, when it ran (skipped on `--skip-codegen`). */
341
+ schemaDrift?: {
342
+ blocked: boolean;
343
+ reason: string;
344
+ };
345
+ validation: {
346
+ problems: ReadonlyArray<string>;
347
+ wranglerPath: string | undefined;
348
+ };
349
+ }
350
+ /**
351
+ * Run a deploy, then (in `--format json` mode) serialize the structured
352
+ * {@link DeployCommandResult} to stdout. Human/progress logging is routed to
353
+ * stderr for json output so stdout carries only the single JSON document.
354
+ */
355
+ declare const runDeployCommand: (options: DeployCommandOptions) => Promise<DeployCommandResult>;
356
+ /** `lunora deploy` handler (lazy-loaded via the command's `loader`). */
357
+ /**
358
+ * Start the codegen watch loop and return a handle to stop it. Regenerates on
359
+ * startup, then on debounced changes under `lunora/` (ignoring writes to the
360
+ * `_generated/` output to avoid a feedback loop). If the platform can't do a
361
+ * recursive watch, it logs once and falls back to startup-only codegen.
362
+ */
363
+ declare const startCodegenWatch: (options: CodegenWatcherOptions) => CodegenWatcherHandle;
364
+ interface CodegenWatcherOptions {
365
+ /** Which API spec(s) to emit. Defaults to codegen's `"openapi"` when omitted. */
366
+ apiSpec?: CodegenOptions["apiSpec"];
367
+ /** Debounce window for coalescing rapid edits. Defaults to 100ms. */
368
+ debounceMs?: number;
369
+ logger: Logger;
370
+ /** Override the lunora subdirectory name. Defaults to `"lunora"`. */
371
+ lunoraDirectory?: string;
372
+ /** Project root containing the `lunora/` directory. */
373
+ projectRoot: string;
374
+ }
375
+ interface CodegenWatcherHandle {
376
+ /** Stop watching and cancel any pending regeneration. */
377
+ close: () => void;
378
+ /**
379
+ * `true` when the platform supports recursive watch and the loop is active.
380
+ * `false` when `fs.watch({ recursive })` threw — startup-only codegen was run
381
+ * but schema edits will NOT auto-regenerate. Callers can surface this in the
382
+ * dev banner so the degraded state is visible beyond the single startup warning.
383
+ */
384
+ watchAvailable: boolean;
385
+ }
386
+ /**
387
+ * Start the studio server and resolve once it is listening. Loads the static
388
+ * bundle + renders the host HTML once up front; serves them and proxies
389
+ * `/_lunora/*` (HTTP + WS) to the worker.
390
+ */
391
+ declare const startStudioServer: (options: StudioServerOptions) => Promise<StudioServerHandle>;
392
+ interface StudioServerOptions {
393
+ /** Project root — `.dev.vars` is read from here for the admin token. */
394
+ cwd: string;
395
+ /** Loopback host to bind. Defaults to `127.0.0.1` (admin tooling stays local). */
396
+ host?: string;
397
+ /** One-time warning sink for a missing/unbuilt `@lunora/studio`. */
398
+ logger?: {
399
+ warnOnce?: (message: string) => void;
400
+ };
401
+ /** Port to listen on. */
402
+ port: number;
403
+ /** Origin of the `wrangler dev` worker, e.g. `http://localhost:8787`. */
404
+ workerOrigin: string;
405
+ }
406
+ interface StudioServerHandle {
407
+ /** Stop listening and release the port. */
408
+ close: () => Promise<void>;
409
+ /** The URL to open in a browser. */
410
+ url: string;
411
+ }
412
+ /** A running worker child the orchestrator controls: send signals, await its exit. */
413
+ interface WorkerProcess {
414
+ /** Resolves with the worker's exit code (1 if it failed to start). */
415
+ exited: Promise<number>;
416
+ kill: (signal: NodeJS.Signals) => void;
417
+ }
418
+ /** Spawns the worker child. Injectable so tests drive the orchestration without a real process. */
419
+ type WorkerSpawner = (descriptor: SpawnDescriptor & {
420
+ tag: string;
421
+ }, logger: Logger) => WorkerProcess;
422
+ interface DevCommandOptions {
423
+ /** Which API spec(s) the codegen watcher emits. Defaults to codegen's `"openapi"` when omitted. */
424
+ apiSpec?: ApiSpec;
425
+ /** Disable the codegen watch loop. */
426
+ codegen?: boolean;
427
+ cwd?: string;
428
+ /** Injection seam for tests — defaults to the real `.dev.vars` scaffolder. */
429
+ ensureEnv?: typeof ensureDevVariables;
430
+ /** Injection seam for tests — defaults to the real `.dev.vars.example` package-aware scaffolder. */
431
+ ensureExample?: typeof ensureDevVarsExample;
432
+ logger: Logger;
433
+ /** Injection seam for tests — defaults to the real remote-config materializer. */
434
+ materializeRemote?: typeof materializeRemoteWranglerConfig;
435
+ /** Studio server port. */
436
+ port?: number;
437
+ /** Proxy D1/KV/R2 bindings to the deployed worker during dev (`LUNORA_REMOTE=1` / `--remote`); DO shards stay local. */
438
+ remote?: boolean;
439
+ /** Injection seam for tests — defaults to the real codegen watcher. */
440
+ startCodegen?: typeof startCodegenWatch;
441
+ /** Injection seam for tests — defaults to the real studio server. */
442
+ startStudio?: typeof startStudioServer;
443
+ /** Injection seam for tests — defaults to spawning a real `wrangler dev`. */
444
+ startWorker?: WorkerSpawner;
445
+ /** Disable the embedded studio server. */
446
+ studio?: boolean;
447
+ /** `wrangler dev` port. */
448
+ workerPort?: number;
449
+ }
450
+ interface DevRemotePlan {
451
+ /** Short binding labels remoted (e.g. `"DB (D1)"`), for the banner. */
452
+ bindings: string[];
453
+ /**
454
+ * Removes the generated temp wrangler config when dev exits. Always present
455
+ * and idempotent — a no-op when remote mode is off or nothing was
456
+ * materialized. The dev loop calls it on every shutdown path.
457
+ */
458
+ cleanup: () => void;
459
+ /** Whether remote mode was requested. */
460
+ enabled: boolean;
461
+ /** Why remote mode didn't take effect despite being requested, for logging. */
462
+ reason?: string;
463
+ }
464
+ interface DevCommandPlan {
465
+ codegenEnabled: boolean;
466
+ /** The remote-binding decision: which D1/KV/R2 bindings hit the deployed worker. */
467
+ remote: DevRemotePlan;
468
+ studioEnabled: boolean;
469
+ studioPort: number;
470
+ workerOrigin: string;
471
+ workerPort: number;
472
+ /** The single child process `lunora dev` spawns: `wrangler dev`. */
473
+ wrangler: SpawnDescriptor & {
474
+ tag: string;
475
+ };
476
+ }
477
+ /**
478
+ * Resolve remote-binding mode into the extra `wrangler dev` args + a banner
479
+ * summary. When `--remote`/`LUNORA_REMOTE` is set we materialize a temp wrangler
480
+ * config with `"remote": true` on each D1/KV/R2 binding (Durable Object shards
481
+ * stay local) and point `wrangler dev --config` at it, so the local worker reads
482
+ * and writes the **deployed** resources. When disabled, or when there's nothing
483
+ * to remote, the args stay empty and dev runs fully local.
484
+ */
485
+ /**
486
+ * Plan `lunora dev`: it runs the worker via `wrangler dev` and nothing else as a
487
+ * child process. Vite is intentionally NOT spawned — a project may not use Vite,
488
+ * and when it does, the `@lunora/vite` plugin already runs the worker inside
489
+ * Vite, so the user runs `vite` themselves. Pure + synchronous so it's unit-testable.
490
+ */
491
+ declare const planDevCommand: (options: DevCommandOptions) => DevCommandPlan;
492
+ /**
493
+ * Start codegen watch + the studio server, spawn `wrangler dev`, print the
494
+ * banner, and resolve when the worker exits or the user interrupts — tearing
495
+ * down the sibling servers either way. The three side-effecting pieces (worker,
496
+ * studio, codegen) are injectable so this is testable without real I/O.
497
+ */
498
+ declare const runDevCommand: (options: DevCommandOptions) => Promise<{
499
+ code: number;
500
+ plan: DevCommandPlan;
501
+ }>;
502
+ /** `lunora dev` handler (lazy-loaded via the command's `loader`). */
503
+ /** Supported CI providers. */
504
+ type CiProvider = "github" | "gitlab";
505
+ type PackageManager = "pnpm" | "npm" | "yarn" | "bun";
506
+ /** True when `manager` is on PATH — probed by running `&lt;manager> --version`. Injectable for tests. */
507
+ type PackageManagerProbe = (manager: PackageManager) => boolean;
508
+ /**
509
+ * The package managers actually installed on this machine, in preference order
510
+ * ({@link INSTALL_PREFERENCE} — pnpm > bun > yarn > npm). The first entry is the
511
+ * recommended default for the install prompt; the whole list is what the user
512
+ * picks from. Empty when none are found.
513
+ */
514
+ /** A registry item a feature can install. */
515
+ type FeatureItem = "auth" | "auth-auth0" | "auth-clerk" | "mail";
516
+ /** The auth-provider choices offered for `add auth` / the init auth prompt. Each value is a registry item name. */
517
+ /** A single file the item scaffolds into the project. */
518
+ interface RegistryFile {
519
+ /** Source path inside the item dir (e.g. `schema.ts`). */
520
+ from: string;
521
+ /** Merge strategy. `create-or-skip` writes whole files; `schema-extension` AST-merges schema.ts. */
522
+ merge: "create-or-skip" | "schema-extension";
523
+ /** Destination relative to the project root (e.g. `lunora/ratelimit/index.ts`). */
524
+ to: string;
525
+ }
526
+ /** A wrangler.jsonc binding addition. `path` is the jsonc key path; `value` the value to set. */
527
+ interface RegistryBinding {
528
+ path: ReadonlyArray<string>;
529
+ value: unknown;
530
+ }
531
+ /**
532
+ * An environment variable an item needs. Scaffolded into `.dev.vars` (Workers'
533
+ * local-secrets file) on add — non-secrets get their `value`; secrets get an
534
+ * empty placeholder and a reminder to run `wrangler secret put` for production.
535
+ */
536
+ interface RegistryEnvVariable {
537
+ /** Human note on what the variable is for. */
538
+ description?: string;
539
+ /** The variable name (e.g. `RESEND_API_KEY`). */
540
+ name: string;
541
+ /** Mark as a secret: never write a value, only a placeholder, and remind about prod. Defaults to `true` when no `value` is given. */
542
+ secret?: boolean;
543
+ /** A default/example value for non-secret vars. */
544
+ value?: string;
545
+ }
546
+ /** The `registry.json` manifest shape. */
547
+ interface RegistryManifest {
548
+ /** wrangler.jsonc additions (best-effort structural edits). */
549
+ bindings?: ReadonlyArray<RegistryBinding>;
550
+ /** npm deps to add to the project package.json (name → version range). */
551
+ deps?: Readonly<Record<string, string>>;
552
+ description?: string;
553
+ /** npm devDependencies to add to the project package.json. */
554
+ devDependencies?: Readonly<Record<string, string>>;
555
+ /** Post-install guidance printed after the item is added (per-item next steps). */
556
+ docs?: string;
557
+ /** Environment variables the item needs; scaffolded into `.dev.vars`. */
558
+ envVars?: ReadonlyArray<RegistryEnvVariable>;
559
+ files: ReadonlyArray<RegistryFile>;
560
+ name: string;
561
+ /** Other registry items this one depends on (resolved transitively, deps first). */
562
+ requires?: ReadonlyArray<string>;
563
+ /** Short human-readable label (distinct from the longer `description`). */
564
+ title?: string;
565
+ }
566
+ interface AddCommandOptions {
567
+ /** Bypass the `--source` safety gate (matches init). */
568
+ allowUnsafeSource?: boolean;
569
+ /** `registry build --check`: verify the index is current instead of rewriting it. */
570
+ check?: boolean;
571
+ /** Inject a confirmer for non-interactive callers / tests. */
572
+ confirm?: (prompt: string) => Promise<boolean>;
573
+ cwd?: string;
574
+ /** Preview the file-level changes (a content diff) and write nothing. */
575
+ diff?: boolean;
576
+ /** Print the plan and stop without writing anything. */
577
+ dryRun?: boolean;
578
+ /** Local registry root (offline / tests). Expects per-item subdirs, each with a `registry.json`. */
579
+ from?: string;
580
+ /** Emit a JSON snapshot of the plan/result. */
581
+ json?: boolean;
582
+ /** `--list`: enumerate available items instead of adding. */
583
+ list?: boolean;
584
+ logger: Logger;
585
+ /** Item names to add (positional args). */
586
+ names: ReadonlyArray<string>;
587
+ /** `registry build` output path for the generated catalog (defaults to the root's `index.json`). */
588
+ out?: string;
589
+ /** Force-overwrite existing files (take the incoming copy) instead of skipping/conflicting. */
590
+ overwrite?: boolean;
591
+ /** Override the git ref (branch, tag, or commit) items are fetched from (default: version-derived); appended to the `source` base when that is set. Ignored when `from` is set. */
592
+ ref?: string;
593
+ /** Override the remote registry source base (default gh:anolilab/lunora/registry). */
594
+ source?: string;
595
+ /**
596
+ * Customize each resolved manifest after it is loaded but before the plan is
597
+ * printed / reconciled — used to inject user-chosen values into otherwise
598
+ * static manifests (e.g. the R2 `bucket_name` the init storage prompt asks
599
+ * for). Applied to every item; return the manifest unchanged to leave it as-is.
600
+ */
601
+ transformManifest?: (manifest: RegistryManifest) => RegistryManifest;
602
+ /** Skip the package.json mutation confirmation prompt. */
603
+ yes?: boolean;
604
+ }
605
+ interface AddCommandResult {
606
+ /** Bindings written to wrangler.jsonc. */
607
+ bindings: ReadonlyArray<string>;
608
+ code: number;
609
+ /** Deps added to package.json. */
610
+ deps: ReadonlyArray<string>;
611
+ /** Files skipped because they already existed. */
612
+ skipped: ReadonlyArray<string>;
613
+ /** Files written (absolute paths). */
614
+ written: ReadonlyArray<string>;
615
+ }
616
+ /** One resolved item: its parsed manifest plus the (possibly staged) directory it lives in. */
617
+ /**
618
+ * A feature offered in the post-scaffold multi-select. `auth`/`email` carry a
619
+ * sub-prompt or alias; every other value IS the registry item name applied
620
+ * directly (`storage` → the `storage` registry item, etc.).
621
+ */
622
+ type StackFeature = "auth" | "backup" | "crons" | "email" | "presence" | "ratelimit" | "storage";
623
+ /** Customize a resolved manifest before it is written (e.g. inject the chosen R2 bucket name). */
624
+ type OfferTransformManifest = (manifest: RegistryManifest) => RegistryManifest;
625
+ /**
626
+ * One feature ready to apply: the registry item name(s), an optional manifest
627
+ * transform, and a short `label` (the feature value) shown on the combined
628
+ * progress line. Built up-front by the collectors so every prompt is answered
629
+ * before any apply runs.
630
+ */
631
+ interface FeatureApply {
632
+ label: string;
633
+ names: ReadonlyArray<string>;
634
+ transformManifest?: OfferTransformManifest;
635
+ }
636
+ interface OfferDeps {
637
+ /**
638
+ * Apply the collected features into the new project in one batch — resolves
639
+ * `true` when every item succeeds. The CLI renders this as a single progress
640
+ * line whose label changes per feature; each plan's `transformManifest`
641
+ * customizes that item's manifest before it is written.
642
+ */
643
+ applyAll: (plans: ReadonlyArray<FeatureApply>) => Promise<boolean>;
644
+ /** When `false`, skip all prompts and print the later-setup hint. */
645
+ interactive: boolean;
646
+ logger: Logger;
647
+ /** Multi-select among the stack features to add (TTY-backed in production). */
648
+ multiSelect: (message: string, options: ReadonlyArray<{
649
+ description?: string;
650
+ label: string;
651
+ value: StackFeature;
652
+ }>, settings?: {
653
+ defaults?: ReadonlyArray<StackFeature>;
654
+ }) => Promise<StackFeature[]>;
655
+ /**
656
+ * Features chosen non-interactively (the `--add` flag). When set, the
657
+ * multi-select and every sub-prompt are skipped — each feature is applied with
658
+ * its shipped defaults (base registry item, placeholder bindings).
659
+ */
660
+ preselected?: ReadonlyArray<StackFeature>;
661
+ /** The new project's name — seeds smart defaults like the `project-uploads` bucket name. */
662
+ projectName: string;
663
+ /** Single-select among the auth providers (TTY-backed in production). */
664
+ select: (message: string, options: ReadonlyArray<{
665
+ description?: string;
666
+ label: string;
667
+ value: FeatureItem;
668
+ }>, settings?: {
669
+ default?: FeatureItem;
670
+ }) => Promise<FeatureItem | undefined>;
671
+ /** Single-line text input (TTY-backed in production) — used for the storage bucket-name prompt. */
672
+ text: (message: string, settings?: {
673
+ default?: string;
674
+ placeholder?: string;
675
+ }) => Promise<string>;
676
+ }
677
+ /**
678
+ * Offer the stack features (auth, email, storage, rate limiting, crons,
679
+ * presence, backups) in ONE multi-select after a successful scaffold. Auth,
680
+ * email, and storage run a follow-up prompt (provider / destination / bucket
681
+ * name); every other feature value is applied as its registry item directly.
682
+ *
683
+ * Every question is asked FIRST (in selection order), then the picked features
684
+ * are applied together via {@link OfferDeps.applyAll} — the CLI renders that as a
685
+ * single progress line whose label changes per feature, instead of one spinner
686
+ * per item. Non-interactive: prints how to add them later and changes nothing.
687
+ */
688
+ type Template = "analog" | "astro" | "next" | "nuxt" | "react-router" | "standalone" | "sveltekit" | "tanstack-start-react" | "tanstack-start-solid";
689
+ interface InitCommandOptions {
690
+ /**
691
+ * Add features non-interactively after scaffolding (the `--add` flag): a
692
+ * comma-separated list of `auth | email | storage | ratelimit | crons |
693
+ * presence | backup`. Bypasses the interactive multi-select and sub-prompts —
694
+ * each named feature is applied with its shipped defaults.
695
+ */
696
+ add?: string;
697
+ /**
698
+ * When true, accept `--source` values that don't start with `gh:` /
699
+ * `github:` / `https://` or that contain `..`. Defaults to false; the CLI
700
+ * gate exists to stop arbitrary filesystem / scheme sources from being
701
+ * pulled without the caller opting in.
702
+ */
703
+ allowUnsafeSource?: boolean;
704
+ /** When set, also scaffold a CI deploy pipeline for the given provider. */
705
+ ci?: CiProvider;
706
+ cwd?: string;
707
+ /**
708
+ * Walk the whole flow — prompts, task list, next-steps, mascot — but make no
709
+ * changes: skip the template fetch/copy, the feature applies, the dependency
710
+ * install, and `git init`. Each skipped action logs a `would …` line instead.
711
+ */
712
+ dryRun?: boolean;
713
+ /**
714
+ * Local directory containing the template subdirs (e.g. `vite/`,
715
+ * `standalone/`). When provided, skips the network fetch entirely.
716
+ * Useful for offline runs, the clean-machine smoke test, and unit tests.
717
+ */
718
+ from?: string;
719
+ /**
720
+ * When true, configure Lunora into the CURRENT project (`cwd`) instead of
721
+ * scaffolding a new directory. Finds an existing `vite.config.*` and
722
+ * patches it via `patchViteConfig`, or creates a minimal one when absent.
723
+ * All other scaffold options (`name`, `templateType`, `source`, `from`)
724
+ * are ignored in this mode.
725
+ */
726
+ inPlace?: boolean;
727
+ /**
728
+ * Inject the post-scaffold install offer's prompts (tests). When set, the
729
+ * offer runs regardless of TTY: `confirmInstall` drives the yes/no, and
730
+ * `selectManager` picks among the detected managers.
731
+ */
732
+ installPrompt?: {
733
+ confirmInstall: () => Promise<boolean>;
734
+ selectManager: (managers: ReadonlyArray<PackageManager>) => Promise<PackageManager>;
735
+ };
736
+ /**
737
+ * Force the post-scaffold "add auth / email?" offer on (the `--interactive`
738
+ * flag). When omitted, the offer runs only when stdin is a TTY. `--yes`
739
+ * suppresses it regardless. Has no effect once {@link prompt} is injected.
740
+ */
741
+ interactive?: boolean;
742
+ logger: Logger;
743
+ name?: string;
744
+ /**
745
+ * Local directory holding create-vite bases (one `template-&lt;id>/` subdir per
746
+ * framework). When set with `vite`, the overlay copies the base from disk
747
+ * instead of fetching `create-vite` over the network — offline mode + tests.
748
+ */
749
+ overlayBaseFrom?: string;
750
+ /** Probe for which package managers are installed (tests). Defaults to a real `&lt;pm> --version` check. */
751
+ packageManagerProbe?: PackageManagerProbe;
752
+ /**
753
+ * Inject the offer's prompts (tests). When set, the offer is treated as
754
+ * interactive regardless of TTY, and these drive the feature multi-select,
755
+ * the auth-provider sub-select, and the storage bucket-name text input.
756
+ */
757
+ prompt?: Pick<OfferDeps, "multiSelect" | "select" | "text">;
758
+ /**
759
+ * Override the git ref (branch, tag, or commit) the default template source
760
+ * is fetched from. Takes precedence over the version-derived ref. Ignored
761
+ * when `source` or `from` is set.
762
+ */
763
+ ref?: string;
764
+ /** Local registry root for the offer's `runAddCommand` (offline / tests). Mirrors `from` but for registry items. */
765
+ registryFrom?: string;
766
+ /** Override the remote registry source base for the offer (default `gh:anolilab/lunora/registry`). */
767
+ registrySource?: string;
768
+ /**
769
+ * Override the remote source giget downloads from. Default:
770
+ * `gh:anolilab/lunora/templates/&lt;templateType>#&lt;ref>`, where `&lt;ref>` is
771
+ * the `ref` option when set, else derived from the CLI version (pre-release
772
+ * channels → their branch, stable → `main`). Tests typically use `from`
773
+ * instead to skip the network.
774
+ */
775
+ source?: string;
776
+ /** Spawner for the post-scaffold dependency install (tests inject a recording stub). Defaults to a real subprocess. */
777
+ spawner?: Spawner;
778
+ templateType?: Template;
779
+ /**
780
+ * Scaffold via the **create-vite overlay** for this framework (`react`,
781
+ * `vue`, `solid`, `svelte`, `vanilla`) instead of a bespoke template: fetch
782
+ * the official create-vite base and apply the Lunora layer on top. Takes
783
+ * precedence over `templateType`.
784
+ */
785
+ vite?: string;
786
+ /** Suppress the offer entirely (the `--yes` flag): scaffold only, print the later-setup hint. */
787
+ yes?: boolean;
788
+ }
789
+ interface InitCommandResult {
790
+ code: number;
791
+ files: ReadonlyArray<string>;
792
+ target: string;
793
+ }
794
+ declare const runInitCommand: (options: InitCommandOptions) => Promise<InitCommandResult>;
795
+ /** Narrow a raw `--template` value to a known {@link Template}. */
796
+ interface MigrateGenerateCommandOptions {
797
+ cwd?: string;
798
+ logger: Logger;
799
+ /** Migration name slug. Defaults to `auto`. */
800
+ name?: string;
801
+ /** Override the current time — used by tests for deterministic file names. */
802
+ now?: () => Date;
803
+ }
804
+ interface MigrateGenerateCommandResult {
805
+ code: number;
806
+ /** Whether the diff was empty (no changes detected). */
807
+ empty: boolean;
808
+ /** Absolute path to the migration file (empty string when nothing was written). */
809
+ migrationFile: string;
810
+ }
811
+ declare const runMigrateGenerateCommand: (options: MigrateGenerateCommandOptions) => MigrateGenerateCommandResult;
812
+ /** One catalog entry as `lunora registry list` reports it. */
813
+ interface CatalogItem {
814
+ description?: string;
815
+ name: string;
816
+ }
817
+ /** A built index entry (catalog item plus its short `title`). */
818
+ interface IndexItem extends CatalogItem {
819
+ title?: string;
820
+ }
821
+ /** Names of the subdirectories under `root` that ship a `registry.json`. */
822
+
823
+ /**
824
+ * Build the catalog (`index.json` contents) from a local registry root by
825
+ * reading every item's `registry.json`. Used by both `lunora registry build`
826
+ * and the registry tests so the committed index can't drift from the item dirs.
827
+ */
828
+ declare const buildRegistryIndex: (root: string) => {
829
+ items: IndexItem[];
830
+ };
831
+ /** `lunora registry add` (one or more item names): scaffold items into the project. */
832
+ declare const runAddCommand: (options: AddCommandOptions) => Promise<AddCommandResult>;
833
+ /**
834
+ * `lunora registry view` — inspect a registry item without installing it:
835
+ * print its plan (files / deps / env vars) followed by the full contents of each
836
+ * file it would scaffold. Resolves only the named item — no `requires` expansion.
837
+ */
838
+ declare const runRegistryViewCommand: (options: AddCommandOptions) => Promise<AddCommandResult>;
839
+ /**
840
+ * `lunora registry build` — regenerate `index.json` from the item directories
841
+ * (the catalog `list` reads). With `--check`, verify the committed index matches
842
+ * instead of rewriting it (exits non-zero on drift) — a CI guard.
843
+ */
844
+ declare const runBuildIndexCommand: (options: AddCommandOptions) => Promise<AddCommandResult>;
845
+ /** Validate + narrow a parsed JSON value into a {@link RegistryManifest}. */
846
+ declare const parseManifest: (raw: unknown, itemName: string) => RegistryManifest;
847
+ interface ResetCommandOptions {
848
+ all?: boolean;
849
+ /** Inject a custom confirmer (tests, non-TTY callers). Returns `true` on confirmation. */
850
+ confirm?: (prompt: string) => Promise<boolean>;
851
+ cwd?: string;
852
+ logger: Logger;
853
+ /** Skip confirmation. Required when stdin is not a TTY. */
854
+ yes?: boolean;
855
+ }
856
+ interface ResetCommandResult {
857
+ code: number;
858
+ removed: ReadonlyArray<string>;
859
+ }
860
+ declare const runResetCommand: (options: ResetCommandOptions) => Promise<ResetCommandResult>;
861
+ /** `lunora reset` handler (lazy-loaded via the command's `loader`). */
862
+ /**
863
+ * Tiny argv parser.
864
+ *
865
+ * Supports long options (`--name value`, `--name=value`, `--flag`), short
866
+ * options (`-x value`, `-xvalue`), positional arguments (everything else, in
867
+ * order), and a `--` terminator after which everything is positional.
868
+ *
869
+ * Intentionally small — replaces a full CLI library for the handful of
870
+ * subcommands we need.
871
+ */
872
+ interface ParsedArgs {
873
+ flags: Record<string, boolean>;
874
+ options: Record<string, string>;
875
+ positional: ReadonlyArray<string>;
876
+ }
877
+ declare const parseArgs: (argv: ReadonlyArray<string>, booleanFlags?: ReadonlySet<string>) => ParsedArgs;
878
+ type InsertSchemaExtensionResult = {
879
+ ok: true;
880
+ text: string;
881
+ } | {
882
+ ok: false;
883
+ reason: "already-applied" | "invalid-identifier" | "no-define-schema" | "non-object-argument";
884
+ };
885
+ /**
886
+ * Append `.extend(&lt;key>.extension)` and a managed import to an existing
887
+ * `lunora/schema.ts`. Idempotent: a second call for the same `key` returns
888
+ * `already-applied` and leaves the text unchanged.
889
+ * @param source the current `lunora/schema.ts` contents
890
+ * @param key the registry item key (e.g. `"ratelimit"`)
891
+ */
892
+ declare const insertSchemaExtension: (source: string, key: string) => InsertSchemaExtensionResult;
893
+ /** Compact snapshot of a single global table — what we persist + diff. */
894
+ interface TableSnapshot {
895
+ columns: Record<string, ColumnSnapshot>;
896
+ indexes: Record<string, IndexSnapshot>;
897
+ /** Table name (also the JSON key — duplicated for ease of iteration). */
898
+ name: string;
899
+ }
900
+ interface ColumnSnapshot {
901
+ /** True when the column accepts NULL (validator wrapped in v.optional). */
902
+ nullable: boolean;
903
+ /** SQLite type affinity, derived from the validator. */
904
+ sqlType: "BLOB" | "INTEGER" | "REAL" | "TEXT";
905
+ }
906
+ interface IndexSnapshot {
907
+ fields: ReadonlyArray<string>;
908
+ name: string;
909
+ unique: boolean;
910
+ }
911
+ interface SchemaSnapshot {
912
+ tables: Record<string, TableSnapshot>;
913
+ version: 1;
914
+ }
915
+ interface DiffEntry {
916
+ kind: "addColumn" | "createIndex" | "createTable" | "dropIndex" | "dropTable";
917
+ /** Generated SQL for this delta (already terminated with `;`). */
918
+ sql: string;
919
+ /** Human-readable summary, used in migration headers. */
920
+ summary: string;
921
+ }
922
+ interface UnsupportedEntry {
923
+ kind: "columnTypeChange" | "dropColumn" | "indexRename" | "renameColumn";
924
+ /** Human-readable description, embedded as SQL comments. */
925
+ summary: string;
926
+ }
927
+ interface SchemaDiff {
928
+ /** No-op marker — true when there is genuinely nothing to apply. */
929
+ empty: boolean;
930
+ entries: ReadonlyArray<DiffEntry>;
931
+ unsupported: ReadonlyArray<UnsupportedEntry>;
932
+ }
933
+ /**
934
+ * Map a Lunora validator kind to a SQLite type affinity — the canonical
935
+ * `@lunora/d1/dialect` mapping. Re-exported under this name because
936
+ * `schema-snapshot.ts` builds the persisted snapshot from it.
937
+ */
938
+ declare const validatorKindToSqlType: (kind: string) => ColumnSnapshot["sqlType"];
939
+ /** Emit `CREATE TABLE` SQL for a new global table. */
940
+ declare const renderCreateTable: (table: TableSnapshot) => string;
941
+ declare const renderDropTable: (tableName: string) => string;
942
+ declare const renderAddColumn: (tableName: string, columnName: string, column: ColumnSnapshot) => string;
943
+ declare const renderCreateIndex: (tableName: string, index: IndexSnapshot) => string;
944
+ declare const renderDropIndex: (tableName: string, indexName: string) => string;
945
+ /**
946
+ * Compute a {@link SchemaDiff} from two snapshots. Pure function — no I/O.
947
+ */
948
+ declare const diffSnapshots: (previous: SchemaSnapshot | undefined, next: SchemaSnapshot) => SchemaDiff;
949
+ /**
950
+ * Render a complete migration file body from a diff. Includes a header,
951
+ * each SQL statement, and (if any) a trailing comment block describing the
952
+ * manual SQL the user needs to fill in for unsupported deltas.
953
+ */
954
+ declare const renderMigrationFile: (name: string, diff: SchemaDiff, generatedAt: string) => string;
955
+ declare const schemaIrToSnapshot: (ir: SchemaIR) => SchemaSnapshot;
956
+ export { type AddCommandOptions, type AddCommandResult, COMMANDS, type ColumnSnapshot, type CommandName, DEFAULT_IMPORT_BATCH_SIZE, type DeployCommandOptions, type DeployCommandResult, type DevCommandOptions, type DevCommandPlan, type DiffEntry, type ExportCommandOptions, type ExportCommandResult, type FetchLike, type ImportCommandOptions, type ImportCommandResult, type IndexSnapshot, type InitCommandOptions, type InitCommandResult, type InsertSchemaExtensionResult, type Logger, type MigrateGenerateCommandOptions, type MigrateGenerateCommandResult, type RecordedSpawn, type RegistryBinding, type RegistryFile, type RegistryManifest, type ResetCommandOptions, type ResetCommandResult, type RunCliOptions, type RunCommandOptions, type RunCommandResult, type SchemaDiff, type SchemaSnapshot, type SpawnDescriptor, type SpawnResult, type Spawner, type StreamingFetchLike, type TableSnapshot, type Template, type UnsupportedEntry, VERSION, buildRegistryIndex, createLogger, createRecordingSpawner, defaultSpawner, diffSnapshots, insertSchemaExtension, pail, parseArgs, parseManifest, planDevCommand, renderAddColumn, renderCreateIndex, renderCreateTable, renderDropIndex, renderDropTable, renderMigrationFile, runAddCommand, runBuildIndexCommand, runCli, runCodegenCommand, runDeployCommand, runDevCommand, runExportCommand, runImportCommand, runInitCommand, runMigrateGenerateCommand, runRegistryViewCommand, runResetCommand, runRpcCommand, schemaIrToSnapshot, validatorKindToSqlType };