@lunora/cli 1.0.0-alpha.3 → 1.0.0-alpha.300

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 (118) hide show
  1. package/LICENSE.md +33 -0
  2. package/README.md +1 -1
  3. package/__assets__/package-og.svg +1 -1
  4. package/dist/bin.mjs +2 -10
  5. package/dist/index.d.mts +1087 -368
  6. package/dist/index.d.ts +1087 -368
  7. package/dist/index.mjs +1 -19
  8. package/dist/packem_chunks/dispatch.mjs +1 -0
  9. package/dist/packem_chunks/handler.mjs +1 -78
  10. package/dist/packem_chunks/handler10.mjs +1 -22
  11. package/dist/packem_chunks/handler11.mjs +2 -192
  12. package/dist/packem_chunks/handler12.mjs +1 -131
  13. package/dist/packem_chunks/handler13.mjs +1 -65
  14. package/dist/packem_chunks/handler14.mjs +1 -58
  15. package/dist/packem_chunks/handler15.mjs +1 -79
  16. package/dist/packem_chunks/handler16.mjs +3 -43
  17. package/dist/packem_chunks/handler17.mjs +1 -105
  18. package/dist/packem_chunks/handler18.mjs +1 -172
  19. package/dist/packem_chunks/handler19.mjs +7 -89
  20. package/dist/packem_chunks/handler2.mjs +1 -114
  21. package/dist/packem_chunks/handler20.mjs +1 -94
  22. package/dist/packem_chunks/handler21.mjs +3 -311
  23. package/dist/packem_chunks/handler22.mjs +3 -0
  24. package/dist/packem_chunks/handler23.mjs +1 -0
  25. package/dist/packem_chunks/handler24.mjs +2 -0
  26. package/dist/packem_chunks/handler25.mjs +99 -0
  27. package/dist/packem_chunks/handler26.mjs +10 -0
  28. package/dist/packem_chunks/handler3.mjs +1 -204
  29. package/dist/packem_chunks/handler4.mjs +1 -33
  30. package/dist/packem_chunks/handler5.mjs +1 -49
  31. package/dist/packem_chunks/handler6.mjs +1 -91
  32. package/dist/packem_chunks/handler7.mjs +3 -42
  33. package/dist/packem_chunks/handler8.mjs +1 -174
  34. package/dist/packem_chunks/handler9.mjs +1 -16
  35. package/dist/packem_chunks/planDevCommand.mjs +7 -543
  36. package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
  37. package/dist/packem_chunks/runDeployCommand.mjs +7 -504
  38. package/dist/packem_chunks/runInitCommand.mjs +1179 -544
  39. package/dist/packem_chunks/runResetCommand.mjs +1 -41
  40. package/dist/packem_chunks/runRpcCommand.mjs +1 -68
  41. package/dist/packem_shared/COMMANDS-DdaAWPtr.mjs +1 -0
  42. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-BgMPHEoe.mjs +1 -0
  43. package/dist/packem_shared/EXIT_CODE-08cwt3MK.mjs +1 -0
  44. package/dist/packem_shared/admin-token-VdUnvnKW.mjs +1 -0
  45. package/dist/packem_shared/admin-url-BhF5ufg1.mjs +1 -0
  46. package/dist/packem_shared/binding-manifest-file-CQ1eQYy1.mjs +2 -0
  47. package/dist/packem_shared/buildRegistryIndex-DVmy8fHE.mjs +1 -0
  48. package/dist/packem_shared/catalog-Cbzph90w.mjs +1 -0
  49. package/dist/packem_shared/cli-DOpChqUe.mjs +2 -0
  50. package/dist/packem_shared/codegen-error-AmH54ofi.mjs +3 -0
  51. package/dist/packem_shared/command-Mmxzxyr5.mjs +1 -0
  52. package/dist/packem_shared/commands-CdVObzRk.mjs +13 -0
  53. package/dist/packem_shared/createLogger-Cl18I8AX.mjs +2 -0
  54. package/dist/packem_shared/createRecordingSpawner-sS7LEN7x.mjs +1 -0
  55. package/dist/packem_shared/deploy-target-DCWwiuAe.mjs +1 -0
  56. package/dist/packem_shared/diffSnapshots-DtC5Cs4Z.mjs +5 -0
  57. package/dist/packem_shared/docker-DpVxvYpL.mjs +1 -0
  58. package/dist/packem_shared/import-D7qdpSmJ.mjs +12 -0
  59. package/dist/packem_shared/insertSchemaExtension-DuiV6cba.mjs +8 -0
  60. package/dist/packem_shared/lint-ignore-report-DKZagpqk.mjs +2 -0
  61. package/dist/packem_shared/open-url-EnKy--w-.mjs +1 -0
  62. package/dist/packem_shared/parseManifest-CwPTKdtS.mjs +1 -0
  63. package/dist/packem_shared/path-containment-CgxYZggb.mjs +1 -0
  64. package/dist/packem_shared/platform-diagnostics-Cn2g6Jh-.mjs +4 -0
  65. package/dist/packem_shared/prompt-cancelled-BvsNxg_Q.mjs +1 -0
  66. package/dist/packem_shared/render-lunora-error--4tmM6mt.mjs +3 -0
  67. package/dist/packem_shared/resolve-DUCSc7jQ.mjs +5 -0
  68. package/dist/packem_shared/resolve-target-C_ZloTvd.mjs +1 -0
  69. package/dist/packem_shared/runAddCommand-1tGOc-uo.mjs +1 -0
  70. package/dist/packem_shared/runExportCommand-DxsJHYZt.mjs +5 -0
  71. package/dist/packem_shared/runMigrateGenerateCommand-BfBHaTLi.mjs +11 -0
  72. package/dist/packem_shared/schema-drift-gate-BDCkQ1S6.mjs +1 -0
  73. package/dist/packem_shared/schemaIrToSnapshot-irmd5g0Y.mjs +1 -0
  74. package/dist/packem_shared/shared-D-zCOmgY.mjs +1 -0
  75. package/dist/packem_shared/storage-2MQBGhKZ.mjs +1 -0
  76. package/dist/packem_shared/tui-prompts-B3YwUhGw.mjs +4 -0
  77. package/dist/packem_shared/vectorize-metadata-dXpl2_Ar.mjs +1 -0
  78. package/dist/packem_shared/wrangler-name-Dsk5K1f-.mjs +1 -0
  79. package/dist/packem_shared/wrangler-secrets-C9lJnd5N.mjs +1 -0
  80. package/package.json +42 -19
  81. package/skills/README.md +35 -17
  82. package/skills/lunora/SKILL.md +123 -9
  83. package/skills/lunora-create-package/SKILL.md +4 -3
  84. package/skills/lunora-deploy/SKILL.md +42 -11
  85. package/skills/lunora-functions/SKILL.md +120 -15
  86. package/skills/lunora-migration-helper/SKILL.md +74 -21
  87. package/skills/lunora-performance-audit/SKILL.md +78 -9
  88. package/skills/lunora-quickstart/SKILL.md +93 -27
  89. package/skills/lunora-realtime/SKILL.md +73 -39
  90. package/skills/lunora-setup-auth/SKILL.md +33 -6
  91. package/skills/lunora-setup-hyperdrive/SKILL.md +33 -13
  92. package/skills/lunora-setup-hyperdrive-global/SKILL.md +5 -0
  93. package/skills/lunora-setup-mail/SKILL.md +34 -28
  94. package/skills/lunora-setup-scheduler/SKILL.md +18 -14
  95. package/skills/lunora-setup-storage/SKILL.md +189 -28
  96. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +0 -397
  97. package/dist/packem_shared/COMMANDS-CHw4zOZ9.mjs +0 -922
  98. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
  99. package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
  100. package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
  101. package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
  102. package/dist/packem_shared/command-BDXcJCCJ.mjs +0 -14
  103. package/dist/packem_shared/commands-DIQ3nf0C.mjs +0 -743
  104. package/dist/packem_shared/createLogger-CHPNjFw2.mjs +0 -73
  105. package/dist/packem_shared/defaultSpawner-DxI3mebw.mjs +0 -43
  106. package/dist/packem_shared/diffSnapshots-RR2ZE8Ya.mjs +0 -161
  107. package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
  108. package/dist/packem_shared/features-ocSSpZtS.mjs +0 -24
  109. package/dist/packem_shared/insertSchemaExtension-BuzF6-t2.mjs +0 -59
  110. package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
  111. package/dist/packem_shared/output-format-7gyGR3h8.mjs +0 -17
  112. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
  113. package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
  114. package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
  115. package/dist/packem_shared/runAddCommand-3I3JFZUG.mjs +0 -4
  116. package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
  117. package/dist/packem_shared/schemaIrToSnapshot-aBTo7TM5.mjs +0 -43
  118. package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
package/dist/index.d.ts CHANGED
@@ -1,33 +1,34 @@
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';
1
+ import { CodegenOptions, Finding, FieldSnapshot, SchemaIR } from '@lunora/codegen';
2
+ import { ensureDevVariables, ensureDevVarsExample, fillDevSecrets, LintTool, LintIgnoreOutcome, PackageManager, PackageManagerProbe } from '@lunora/config';
3
+ import { materializeRemoteWranglerConfig } from '@lunora/config/cloudflare';
4
+ export { REQUIRED_COMPATIBILITY_DATE, REQUIRED_FLAG, type WranglerProjectValidationOptions as WranglerValidationOptions, type WranglerValidationReport, type WranglerProjectValidationResult as WranglerValidationResult, validateWranglerProject as validateWrangler, validateWranglerConfig } from '@lunora/config/cloudflare';
5
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"];
6
+ declare const COMMANDS: readonly ["init", "add", "dev", "codegen", "build", "deploy", "containers", "prepare", "link", "deployments", "logs", "run", "insights", "reset", "migrate", "export", "import", "seed", "backup", "eval", "verify", "info", "doctor", "env", "analyze", "view", "docs", "registry", "rules", "mcp"];
7
7
  type CommandName = (typeof COMMANDS)[number];
8
8
  declare const VERSION: string;
9
9
  interface RunCliOptions {
10
10
  argv?: ReadonlyArray<string>;
11
11
  cwd?: string;
12
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
- */
13
+ * Inject a console-like logger so callers (tests) can capture cerebro's
14
+ * help / version / usage rendering AND the commands' own output. Omitted in
15
+ * production, where cerebro uses its default stdout/stderr logger and the
16
+ * commands log through the shared pail.
17
+ */
17
18
  logger?: Console;
18
19
  }
19
20
  /**
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
- */
21
+ * Run the CLI and resolve to the process exit code. cerebro handles help,
22
+ * version, usage, and unknown commands (the latter throws, caught here as 1).
23
+ * `shouldExitProcess: false` keeps the process alive so callers/tests read the
24
+ * captured exit code.
25
+ */
25
26
  declare const runCli: (options?: RunCliOptions) => Promise<number>;
26
27
  /**
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
- */
28
+ * The `--api-spec` flag's accepted values, mirroring `@lunora/codegen`'s
29
+ * `CodegenOptions["apiSpec"]`. `"openapi"` (the default) emits `openapi.json`;
30
+ * `"openrpc"` emits `openrpc.json`; `"both"` emits both; `"none"` emits neither.
31
+ */
31
32
  type ApiSpec = NonNullable<CodegenOptions["apiSpec"]>;
32
33
  interface Logger {
33
34
  debug?: (message: string) => void;
@@ -37,11 +38,11 @@ interface Logger {
37
38
  warn: (message: string) => void;
38
39
  }
39
40
  /**
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
- */
41
+ * Narrowed view over the pail instance. `createPail` returns an intersection
42
+ * type that includes a constructor signature and `(...args: any[])` logger
43
+ * overloads, which the type-aware linter cannot safely resolve. We only ever
44
+ * call the level methods with a string, so we describe exactly that surface.
45
+ */
45
46
  interface PailLogger {
46
47
  debug: (message: string) => void;
47
48
  error: (message: string) => void;
@@ -51,53 +52,107 @@ interface PailLogger {
51
52
  }
52
53
  declare const createLogger: () => Logger;
53
54
  /**
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
- */
55
+ * Direct access to the underlying pail instance for advanced use-cases.
56
+ * A Proxy keeps the public `pail` binding lazy: the real pail is only
57
+ * constructed on first property access, so importing this module (and thus
58
+ * the package barrel) stays side-effect-free.
59
+ */
66
60
  declare const pail: PailLogger;
61
+ /**
62
+ * The two renderings every Lunora command speaks. `pretty` is the human-facing
63
+ * default; `json` puts the command's structured result on stdout as a single
64
+ * JSON document and moves every human line to stderr.
65
+ *
66
+ * Resolved ONCE, by `defineHandler`, from the raw `--format` string — a command
67
+ * body receives this narrowed type and never re-validates it.
68
+ */
69
+ type OutputFormat = "json" | "pretty";
70
+ /**
71
+ * The envelope `--format json` puts on stdout — the same three keys for every
72
+ * command, so a consumer parses one shape and never has to know which command
73
+ * produced it.
74
+ *
75
+ * - `code` is the exit code the process will terminate with.
76
+ * - `data` is the command's own payload, and is absent when the run produced
77
+ * none — which is what a failure before any work looks like.
78
+ * - `error` is the single-line reason for a non-zero `code`. It is the half that
79
+ * makes a FAILURE machine-readable: before the envelope, a failed command wrote
80
+ * nothing at all to stdout and the reason could only be scraped out of English
81
+ * prose on stderr.
82
+ *
83
+ * `defineHandler` serializes exactly these keys, once, after the body returns —
84
+ * so a body may return a richer result for its in-process callers without
85
+ * widening the document, and a failure gets one for free.
86
+ */
87
+ interface CommandResult<TData> {
88
+ /** Process exit code — one of `EXIT_CODE`. */
89
+ code: number;
90
+ /** The command's structured payload. Absent when the run produced none. */
91
+ data?: TData;
92
+ /**
93
+ * Set by a command that forwards `--format json` to a child process which
94
+ * writes the document itself (`wrangler … --json`, `wrangler tail`). The
95
+ * envelope is suppressed for that run: stdout already carries exactly one
96
+ * document, and appending a second would make the stream unparseable.
97
+ */
98
+ delegated?: boolean;
99
+ /** Why the run failed. Set whenever `code` is non-zero and a reason is known. */
100
+ error?: string;
101
+ }
67
102
  interface CodegenCommandOptions {
68
103
  /** Which API spec(s) to emit. Defaults to codegen's `"openapi"` when omitted. */
69
104
  apiSpec?: ApiSpec;
70
105
  cwd?: string;
71
106
  /** Output format: `pretty` (default) or `json`. */
72
- format?: string;
107
+ format?: OutputFormat;
73
108
  logger: Logger;
109
+ /**
110
+ * Fail the run when any ERROR-level advisory is reported. Defaults to CI
111
+ * detection so a local `lunora codegen` stays advisory while a pipeline
112
+ * gates on it; `--no-strict-advisories` forces it off either way.
113
+ */
114
+ strictAdvisories?: boolean;
115
+ /** Deploy target the emitted `ctx.*` surface is tailored to. Resolved by the caller; falls back to `"target"` in `lunora.config.*`, then `"cloudflare"`. */
116
+ target?: string;
74
117
  }
75
- interface CodegenCommandResult {
118
+ /** The `--format json` payload: what codegen wrote, and what it has to say about it. */
119
+ interface CodegenCommandData {
76
120
  advisories: ReadonlyArray<{
77
121
  detail: string;
78
- level: string;
122
+ level: Finding["level"];
79
123
  name: string;
80
124
  remediation: string;
81
125
  }>;
82
126
  cronTriggers: ReadonlyArray<string>;
83
- /** Set when the run aborted on an invalid `--format` before codegen ran. */
84
- error?: string;
127
+ /** ERROR-level advisories that made the run fail, when strict mode is on. */
128
+ failedAdvisories: number;
85
129
  outputDirectory: string;
86
130
  }
131
+ interface CodegenCommandResult extends CodegenCommandData {
132
+ /**
133
+ * Exit code, when the run resolved one itself. Only a USAGE refusal does —
134
+ * every other outcome is classified from `error`/`failedAdvisories` by
135
+ * `execute`, which cannot tell a bad `--format` (the invocation is wrong,
136
+ * exit 2) from a failed codegen (exit 1) after the fact.
137
+ */
138
+ code?: number;
139
+ /** Set when the run failed: an unregistered target, or an error-level platform diagnostic. */
140
+ error?: string;
141
+ }
87
142
  declare const runCodegenCommand: (options: CodegenCommandOptions) => CodegenCommandResult;
88
- /** `lunora codegen` handler (lazy-loaded via the command's `loader`). */
89
- /** Rows per HTTP request when importing. Convex uses ~500; same here. */
90
- declare const DEFAULT_IMPORT_BATCH_SIZE = 500;
91
143
  /**
92
- * Minimal projection of `globalThis.fetch` for the export path — we need
93
- * `body` as a stream-iterable, which the shared {@link FetchLike} type
94
- * intentionally hides for the JSON-only commands.
95
- */
144
+ * Minimal projection of `globalThis.fetch` for the transfer commands: `body` is
145
+ * exposed as a stream-iterable (the export path pipes it) and accepts bytes (the
146
+ * blob path uploads them). The JSON-only commands use the narrower `FetchLike`
147
+ * in `../run/handler` instead.
148
+ */
96
149
  type StreamingFetchLike = (input: string, init?: {
97
- body?: string;
150
+ body?: string | Uint8Array;
98
151
  headers?: Record<string, string>;
99
152
  method?: string;
100
153
  }) => Promise<{
154
+ /** Optional: only the storage transfer reads raw bytes, and only real `fetch` needs to supply it. */
155
+ arrayBuffer?: () => Promise<ArrayBuffer>;
101
156
  body: ReadableStream<Uint8Array> | null;
102
157
  json: () => Promise<unknown>;
103
158
  ok: boolean;
@@ -107,6 +162,12 @@ type StreamingFetchLike = (input: string, init?: {
107
162
  interface ExportCommandOptions {
108
163
  cwd?: string;
109
164
  fetchImpl?: StreamingFetchLike;
165
+ /**
166
+ * Output format: `pretty` (default) or `json`. `json` reports the run as a
167
+ * single document and therefore requires a file destination — with `--out -`
168
+ * (or none) stdout already carries the NDJSON stream.
169
+ */
170
+ format?: OutputFormat;
110
171
  logger: Logger;
111
172
  /** Output file path; `undefined`/`-` streams to stdout. */
112
173
  out?: string;
@@ -119,18 +180,97 @@ interface ExportCommandOptions {
119
180
  /** Worker URL (default `http://localhost:8787`). */
120
181
  url?: string;
121
182
  }
122
- interface ExportCommandResult {
183
+ /** The `--format json` payload: what was dumped, from which tables, and where to. */
184
+ interface ExportCommandData {
185
+ bytes: number;
186
+ /** The file the dump landed in. */
187
+ out: string;
188
+ rows: number;
189
+ /** The table allowlist, omitted when the export covered every table. */
190
+ tables?: string[];
191
+ }
192
+ interface ExportCommandResult extends CommandResult<ExportCommandData> {
123
193
  bytes: number;
124
- code: number;
125
194
  /** Number of NDJSON lines streamed (0 on error). */
126
195
  rows: number;
127
196
  }
128
197
  /**
129
- * Stream an export. The worker emits NDJSON; we count newlines as we go and
130
- * pipe straight to the output sink, so a 10M-row export doesn't materialise
131
- * the body in memory.
132
- */
198
+ * Stream an export. The worker emits NDJSON; we count newlines as we go and
199
+ * pipe straight to the output sink, so a 10M-row export doesn't materialise
200
+ * the body in memory.
201
+ */
133
202
  declare const runExportCommand: (options: ExportCommandOptions) => Promise<ExportCommandResult>;
203
+ /** One row-scoped failure as the admin import endpoint reports it. */
204
+ interface ImportRowError {
205
+ code: string;
206
+ line: number;
207
+ message: string;
208
+ table: string;
209
+ }
210
+ /**
211
+ * One SHARD the fan-out never reached, as the admin import endpoint reports it.
212
+ *
213
+ * Distinct from {@link ImportRowError}: the rows a dead shard owned contribute
214
+ * to neither `inserted` nor `errors`, so an unknown slice of the batch is simply
215
+ * missing. The endpoint answers 207 Multi-Status when this array is non-empty.
216
+ */
217
+ interface ImportShardFailure {
218
+ message: string;
219
+ shardKey: string;
220
+ timedOut: boolean;
221
+ }
222
+ /**
223
+ * The sources `--from` accepts.
224
+ *
225
+ * Only the two that cannot be detected. A Convex snapshot announces itself (a
226
+ * directory of `<table>/documents.jsonl`, or a `.zip` of one) and anything else
227
+ * is NDJSON, so naming those would advertise a control this does not implement:
228
+ * `--from ndjson` against a Convex export would have to either refuse it or
229
+ * silently import it as Convex, and the second is what an unhonoured flag
230
+ * actually did.
231
+ */
232
+ declare const IMPORT_SOURCE_NAMES: readonly ["firebase", "supabase"];
233
+ type ImportSourceName = (typeof IMPORT_SOURCE_NAMES)[number];
234
+ /**
235
+ * The storage-reference rewrite: turning a Convex storage id into the
236
+ * content-hash R2 key its blob was migrated to.
237
+ *
238
+ * Split out of `./storage-mapping` (which owns the mapping *file*) because it
239
+ * has two callers that must never diverge — the import rewrite and `--scan`,
240
+ * which runs this same walk as a dry run to propose the mapping. A detector
241
+ * that proposed columns the rewrite would not touch, or missed ones it would,
242
+ * is worse than no detector.
243
+ */
244
+ /** One reference the walk could not rewrite, with where it was found. */
245
+ interface UnresolvedStorageReference {
246
+ column: string;
247
+ storageId: string;
248
+ table: string;
249
+ }
250
+ /**
251
+ * What a run's storage references resolved to. The two failure buckets are
252
+ * deliberately separate, because they are not the same problem and do not have
253
+ * the same remedy:
254
+ *
255
+ * `unmigrated` is a reference to a blob that does not exist — the export omitted
256
+ * it, or `--include-file-storage` was not passed. Nothing the operator writes in
257
+ * a mapping file can fix it, and the data is broken after import, so it fails
258
+ * `--verify`.
259
+ *
260
+ * `ambiguous` is a string that exactly matches a blob that *did* migrate, sitting
261
+ * in a column the mapping does not name. It may be a storage reference the
262
+ * mapping forgot, or it may be user text that happens to equal an id. Failing the
263
+ * run on a coincidence is not defensible, so it warns and names the column the
264
+ * operator would add to resolve it.
265
+ */
266
+ interface StorageRemapReport {
267
+ ambiguous: UnresolvedStorageReference[];
268
+ /** Number of references rewritten to a content-hash key. */
269
+ rewritten: number;
270
+ unmigrated: UnresolvedStorageReference[];
271
+ }
272
+ /** Rows per HTTP request when importing. Convex uses ~500; same here. */
273
+ declare const DEFAULT_IMPORT_BATCH_SIZE = 500;
134
274
  interface ImportCommandOptions {
135
275
  /** Rows per HTTP request. Defaults to {@link DEFAULT_IMPORT_BATCH_SIZE}. */
136
276
  batchSize?: number;
@@ -138,88 +278,256 @@ interface ImportCommandOptions {
138
278
  fetchImpl?: StreamingFetchLike;
139
279
  /** Source NDJSON file. Required. */
140
280
  file: string;
281
+ /** Output format: `pretty` (default) or `json`. */
282
+ format?: OutputFormat;
283
+ /**
284
+ * Which reader to use. Omit to auto-detect between a Convex export snapshot
285
+ * and a plain NDJSON file; `supabase`/`firebase` must be explicit, because a
286
+ * directory of CSV or JSON has no signature that distinguishes it from
287
+ * anything else a user might point at.
288
+ */
289
+ from?: ImportSourceName;
141
290
  logger: Logger;
142
291
  prod?: boolean;
143
292
  /**
144
- * Wrap each line as `{table:&lt;name>,doc:&lt;line>}`. Use when the source NDJSON
145
- * is bare docs from a single table — Convex's `convex import --table users`
146
- * shape.
147
- */
293
+ * Scan the export for columns holding `_storage` ids and write a candidate
294
+ * `lunora/import-convex.json`. Scan-only: nothing is imported.
295
+ */
296
+ scan?: boolean;
297
+ /**
298
+ * Local directory of storage objects to migrate alongside the rows — how
299
+ * Firebase Cloud Storage arrives, after `gcloud storage cp -r`.
300
+ */
301
+ storageDir?: string;
302
+ /**
303
+ * Wrap each line as `{table:<name>,doc:<line>}`. Use when the source NDJSON
304
+ * is bare docs from a single table — Convex's `convex import --table users`
305
+ * shape.
306
+ */
148
307
  table?: string;
149
308
  token?: string;
150
309
  url?: string;
310
+ /**
311
+ * Verify per-table row parity + dangling-storage after import. Exits non-zero
312
+ * when a table's inserted count differs from its source line count, or when a
313
+ * document references a storage id that was not migrated.
314
+ */
315
+ verify?: boolean;
316
+ /**
317
+ * Also migrate Convex `_storage` blobs: read `_storage/documents.jsonl`, upload
318
+ * each blob with sha256+size verification, and build the `storageId → key` map.
319
+ * Off by default so the plain-document import path is unchanged.
320
+ */
321
+ withStorage?: boolean;
322
+ /** Confirm bulk-writing production. Required alongside `--prod`. */
323
+ yes?: boolean;
151
324
  }
152
- interface ImportCommandResult {
153
- body: unknown;
154
- code: number;
325
+ /**
326
+ * The JSON summary a run prints and returns — the same object either way, so a
327
+ * caller reading `body.conflicts` does not have to cast its way there.
328
+ *
329
+ * `undefined` on every path that imports nothing: a rejected source, a failed
330
+ * storage phase, or `--scan` (whose product is the mapping file it writes, not
331
+ * a return value).
332
+ */
333
+ interface ImportSummary {
334
+ conflicts: number;
335
+ errors: ImportRowError[];
336
+ /** Shards the endpoint could not reach (it answered 207). Their rows are MISSING, not rejected — present only when non-empty. */
337
+ failed?: ImportShardFailure[];
338
+ inserted: Record<string, number>;
339
+ received: number;
340
+ storage?: {
341
+ /** Up to {@link UNRESOLVED_REPORT_LIMIT} distinct references — a sample, not the whole set. See `ambiguousTotal`. */
342
+ ambiguous: StorageRemapReport["ambiguous"];
343
+ /** How many DISTINCT `(table, column, storageId)` references were ambiguous. */
344
+ ambiguousTotal: number;
345
+ blobs: number;
346
+ rewritten: number;
347
+ /** Up to {@link UNRESOLVED_REPORT_LIMIT} distinct references — a sample, not the whole set. See `unmigratedTotal`. */
348
+ unmigrated: StorageRemapReport["unmigrated"];
349
+ /** How many DISTINCT `(table, column, storageId)` references resolved to no migrated blob. */
350
+ unmigratedTotal: number;
351
+ };
352
+ warnings?: string[];
353
+ }
354
+ /** The `--format json` payload: which file went in, and what the endpoint made of it. */
355
+ interface ImportCommandData {
356
+ file: string;
357
+ inserted: number;
358
+ /** The batcher's own roll-up: inserted-per-table, conflicts, row errors, unreached shards. */
359
+ summary: ImportSummary;
360
+ }
361
+ interface ImportCommandResult extends CommandResult<ImportCommandData> {
362
+ body: ImportSummary | undefined;
155
363
  /** Total inserted rows across batches. */
156
364
  inserted: number;
157
365
  }
158
- /**
159
- * Stream an NDJSON file in chunks, POSTing each batch to
160
- * `/_lunora/admin/import`. We keep the line buffer bounded by `batchSize` so a
161
- * multi-GiB file imports without buffering everything in memory.
162
- */
163
366
  declare const runImportCommand: (options: ImportCommandOptions) => Promise<ImportCommandResult>;
164
367
  /**
165
- * Injectable probe for a Docker-compatible container engine. Tests pass a
166
- * stub; production uses {@link isDockerAvailable}.
167
- */
368
+ * Injectable probe for a Docker-compatible container engine. Tests pass a
369
+ * stub; production uses {@link isDockerAvailable}.
370
+ */
168
371
  type DockerProbe = () => boolean;
169
372
  /**
170
- * True when a Docker-compatible engine answers `docker info` — the same
171
- * prerequisite `wrangler deploy` has for building and pushing a container
172
- * image from a local Dockerfile. Quiet by design (output discarded): callers
173
- * own the messaging.
174
- */
373
+ * Every exit code `lunora` can terminate with. Stable — a value never changes
374
+ * meaning, and a new bucket takes the next free number.
375
+ */
376
+ declare const EXIT_CODE: {
377
+ /** The command did what was asked. */
378
+ readonly SUCCESS: 0;
379
+ /** A failure that fits none of the narrower buckets. */
380
+ readonly FAILURE: 1;
381
+ /** Bad usage, bad input, or a validation failure — the invocation itself, or the project source it read, is wrong. */
382
+ readonly USAGE: 2;
383
+ /** Not authenticated: no credential, or an expired one. */
384
+ readonly AUTH: 3;
385
+ /** Authenticated, but not allowed to do this. */
386
+ readonly PERMISSION: 4;
387
+ /** The named thing does not exist. */
388
+ readonly NOT_FOUND: 5;
389
+ /** The write lost a race, or the name is already taken. */
390
+ readonly CONFLICT: 6;
391
+ /** Rate limited — back off and retry. */
392
+ readonly RATE_LIMITED: 7;
393
+ /** The far side is unavailable or timed out. Retryable. */
394
+ readonly UNAVAILABLE: 8;
395
+ /** A local tool the command shells out to (wrangler, git, docker, …) is missing, or not running. */
396
+ readonly MISSING_DEPENDENCY: 9;
397
+ /** Interactive cancel — the POSIX `128 + SIGINT` convention. */
398
+ readonly CANCELLED: 130;
399
+ };
400
+ /** One of {@link EXIT_CODE}'s values. */
401
+ type ExitCode = (typeof EXIT_CODE)[keyof typeof EXIT_CODE];
402
+ /** The exit code for a transport status; `undefined` and anything unmapped are a general failure. */
403
+ declare const exitCodeForStatus: (status: number | undefined) => ExitCode;
404
+ /**
405
+ * The exit code for a Lunora error `code`, resolved through the catalog. An
406
+ * unregistered code has no status to derive from, so it is a general failure.
407
+ */
408
+ declare const exitCodeForCode: (code: string) => ExitCode;
409
+ /**
410
+ * The exit code for a thrown value. A Lunora error is classified by its `code`
411
+ * (override table first) and then by the `status` the instance carries — which
412
+ * is the catalog's, unless the throw site passed a more specific one (the
413
+ * upstream-API codes do). Anything else is a general failure.
414
+ */
415
+ declare const exitCodeForError: (error: unknown) => ExitCode;
416
+ /**
417
+ * The shared `/_lunora/health` probe used by `lunora verify --health-url` and
418
+ * `lunora deploy --health-check`.
419
+ *
420
+ * Both commands ask the same question — "does this deployment answer?" — so
421
+ * they ask it through one implementation with one error-message shape. The
422
+ * runtime auto-registers both routes (`packages/runtime/src/health-routes.ts`):
423
+ * `/_lunora/health/ready` is the readiness gate ("can this version serve"), and
424
+ * `/_lunora/health` is the aggregate that also exists on older deployments.
425
+ *
426
+ * The probe is transport-only: it never throws, and reports its verdict as an
427
+ * `{ error }` message the caller decides what to do with.
428
+ */
429
+ /**
430
+ * Minimal fetch surface the probe needs — a subset of the global `fetch`,
431
+ * injectable so a test can feed a canned response without a network.
432
+ */
433
+ type HealthFetch = (url: string) => Promise<{
434
+ ok: boolean;
435
+ status: number;
436
+ }>;
175
437
  interface SpawnDescriptor {
176
438
  args: ReadonlyArray<string>;
177
439
  /**
178
- * Capture the child's stdout (in addition to streaming it to the parent), so
179
- * the caller can parse it — used by `deploy` to read the deployed URL from
180
- * `wrangler deploy` output. Each chunk is still teed to the parent's stdout
181
- * so the user sees live progress. Mutually exclusive with `stdoutToStderr`.
182
- */
440
+ * Capture the child's stderr (in addition to streaming it to the parent).
441
+ * Needed when a tool reports the *expected* outcome as an error there —
442
+ * `wrangler vectorize create-metadata-index` writes "already exists" to
443
+ * stderr, and without this the caller can only see a bare exit code and
444
+ * would warn on every re-run. Composes with `stdoutToStderr`, so a caller
445
+ * can keep stdout clean for `--format json` and still read the reason.
446
+ */
447
+ captureStderr?: boolean;
448
+ /**
449
+ * Capture the child's stdout (in addition to streaming it to the parent), so
450
+ * the caller can parse it — used by `deploy` to read the deployed URL from
451
+ * `wrangler deploy` output. Each chunk is still teed to the parent's stdout
452
+ * so the user sees live progress. Mutually exclusive with `stdoutToStderr`
453
+ * and `captureStdoutSilently`.
454
+ */
183
455
  captureStdout?: boolean;
456
+ /**
457
+ * Capture the child's stdout WITHOUT teeing it to the parent's stdout —
458
+ * for output that is parsed, never displayed (e.g. `wrangler secret list
459
+ * --format json`). Unlike `captureStdout`, nothing is written to
460
+ * `process.stdout`, so it can't interleave with — and corrupt — a
461
+ * caller's own stdout (notably `lunora deploy --format json`, which must
462
+ * emit exactly one JSON document). Mutually exclusive with `captureStdout`
463
+ * and `stdoutToStderr`.
464
+ */
465
+ captureStdoutSilently?: boolean;
184
466
  command: string;
185
467
  cwd?: string;
186
468
  env?: Readonly<Record<string, string>>;
187
469
  /**
188
- * Pipe this string into the child's stdin and close it. Used to feed
189
- * `wrangler secret put` its value without exposing it on the command
190
- * line or in env. When absent, stdin is inherited from the parent.
191
- */
470
+ * Pipe this string into the child's stdin and close it. Used to feed
471
+ * `wrangler secret put` its value without exposing it on the command
472
+ * line or in env. When absent, stdin is inherited from the parent.
473
+ */
192
474
  input?: string;
193
475
  /**
194
- * Route the child's stdout to the parent's STDERR instead of stdout. Set in
195
- * `--format json` mode so a spawned tool's human output (e.g. `wrangler
196
- * deploy`'s progress + the deployed URL) can't interleave with — and corrupt
197
- * — the single JSON document the command prints to stdout.
198
- */
476
+ * Route the child's stdout to the parent's STDERR instead of stdout. Set in
477
+ * `--format json` mode so a spawned tool's human output (e.g. `wrangler
478
+ * deploy`'s progress + the deployed URL) can't interleave with — and corrupt
479
+ * — the single JSON document the command prints to stdout.
480
+ */
199
481
  stdoutToStderr?: boolean;
200
482
  }
201
483
  interface SpawnResult {
202
484
  code: number;
203
- /** The captured stdout, present only when the descriptor set `captureStdout`. */
485
+ /** The captured stderr, present only when the descriptor set `captureStderr`. */
486
+ stderr?: string;
487
+ /** The captured stdout, present only when the descriptor set `captureStdout` or `captureStdoutSilently`. */
204
488
  stdout?: string;
205
489
  }
206
490
  /**
207
- * Injectable spawner. Tests pass a stub that just records the descriptor
208
- * instead of executing a real subprocess.
209
- */
491
+ * Injectable spawner. Tests pass a stub that just records the descriptor
492
+ * instead of executing a real subprocess.
493
+ */
210
494
  type Spawner = (descriptor: SpawnDescriptor) => Promise<SpawnResult>;
211
495
  declare const defaultSpawner: Spawner;
212
496
  interface RecordedSpawn {
213
497
  descriptor: SpawnDescriptor;
214
498
  }
215
499
  /**
216
- * Test helper: returns a spawner that records every invocation and resolves
217
- * with the configured exit code.
218
- */
500
+ * Test helper: returns a spawner that records every invocation and resolves
501
+ * with the configured exit code.
502
+ */
219
503
  declare const createRecordingSpawner: (exitCode?: number) => {
220
504
  calls: RecordedSpawn[];
221
505
  spawner: Spawner;
222
506
  };
507
+ interface SecretListRunnerResult {
508
+ code: number;
509
+ stderr: string;
510
+ stdout: string;
511
+ }
512
+ /** Runs an argv and resolves its captured output. Injected in tests. */
513
+ type SecretListRunner = (command: string, args: ReadonlyArray<string>, cwd: string) => Promise<SecretListRunnerResult>;
514
+ interface ListRemoteSecretsInputs {
515
+ cwd: string;
516
+ /** Cloudflare environment name (`--env`). */
517
+ env?: string;
518
+ /** Injected command runner; defaults to a real `wrangler secret list`. */
519
+ runner?: SecretListRunner;
520
+ /** Target a temporary-account deployment (`--temporary`). */
521
+ temporary?: boolean;
522
+ }
523
+ interface ListRemoteSecretsResult {
524
+ /** Diagnostic message when `ok` is false. */
525
+ error?: string;
526
+ /** Remote secret names (sorted), empty when none or on failure. */
527
+ names: ReadonlyArray<string>;
528
+ /** False when wrangler failed or its output could not be parsed. */
529
+ ok: boolean;
530
+ }
223
531
  type FetchLike = (input: string, init?: {
224
532
  body?: string;
225
533
  headers?: Record<string, string>;
@@ -232,105 +540,212 @@ type FetchLike = (input: string, init?: {
232
540
  }>;
233
541
  interface RunCommandOptions {
234
542
  args?: string;
543
+ /** Forge this user id for the call (dispatches through the admin-gated `runAs` op). */
544
+ as?: string;
545
+ /** JSON-encoded extra identity claims to accompany {@link RunCommandOptions.as}. */
546
+ claims?: string;
235
547
  cwd?: string;
236
548
  fetchImpl?: FetchLike;
549
+ /** Output format: `pretty` (default) or `json`. */
550
+ format?: OutputFormat;
237
551
  functionPath: string;
238
552
  logger: Logger;
239
553
  shard?: string;
554
+ /** Admin bearer for the `runAs` dispatch; resolved from the environment / `.dev.vars` when absent. */
555
+ token?: string;
240
556
  url?: string;
241
557
  }
242
558
  interface RunCommandResult {
243
559
  body: unknown;
244
560
  code: number;
561
+ /** Why the call failed before (or at) the RPC, for the `--format json` envelope. */
562
+ error?: string;
245
563
  requestUrl: string;
246
564
  }
247
565
  declare const runRpcCommand: (options: RunCommandOptions) => Promise<RunCommandResult>;
248
- /** `lunora run &lt;functionPath>` handler (lazy-loaded via the command's `loader`). */
249
566
  interface DeployCommandOptions {
250
567
  /** Override the schema-drift gate — deploy even with breaking drift and no new migration. */
251
568
  allowSchemaDrift?: boolean;
252
569
  /** Which API spec(s) codegen emits. Defaults to codegen's `"openapi"` when omitted. */
253
570
  apiSpec?: ApiSpec;
571
+ /**
572
+ * The command the operator actually ran. `build` delegates here with
573
+ * `dryRun: true`; without this the gate names the wrong command in its
574
+ * blocked message and offers flags the real caller does not accept.
575
+ */
576
+ commandName?: PreDeployCommand;
254
577
  cwd?: string;
255
578
  /** Docker-availability probe injected in tests. Defaults to a real `docker info` check. */
256
579
  dockerAvailable?: DockerProbe;
257
580
  /**
258
- * Validate, bundle, and run all pre-deploy gates without publishing
259
- * (`wrangler deploy --dry-run`). Post-deploy steps (data migrations, schema
260
- * baseline re-bless) are skipped since nothing shipped.
261
- */
581
+ * Validate, bundle, and run all pre-deploy gates without publishing
582
+ * (`wrangler deploy --dry-run`). Post-deploy steps (data migrations, schema
583
+ * baseline re-bless) are skipped since nothing shipped.
584
+ */
262
585
  dryRun?: boolean;
586
+ /**
587
+ * Write the binding manifest (`build --emit-bindings`) to this path once the
588
+ * bundle exists. Owned here rather than by the caller because it is the last
589
+ * artifact that has to read the PROVISIONED `wrangler.jsonc`, and the dry-run
590
+ * rollback below closes that window as soon as this function returns.
591
+ * Relative paths resolve against the project root.
592
+ */
593
+ emitBindings?: string;
263
594
  env?: string;
264
595
  /** Fetch implementation injected in tests for `--migrate` RPC calls. */
265
596
  fetchImpl?: FetchLike;
266
597
  /** Output format: `pretty` (default) or `json`. */
267
- format?: string;
598
+ format?: OutputFormat;
599
+ /**
600
+ * After a successful live deploy, probe the new version's health route
601
+ * (`/_lunora/health/ready`, falling back to `/_lunora/health`) and fail the
602
+ * command when it never answers. Opt-in, not default-on: a worker whose
603
+ * health route is admin-gated or unreachable from CI must still be
604
+ * deployable, and a default network step would turn a successful deploy
605
+ * into a red build for an unrelated reason.
606
+ */
607
+ healthCheck?: boolean;
608
+ /** Injectable fetch for `--health-check`; defaults to the global `fetch`. */
609
+ healthFetch?: HealthFetch;
610
+ /** Injectable inter-attempt delay for `--health-check`; injected in tests to skip the real wait. */
611
+ healthSleep?: (ms: number) => Promise<void>;
268
612
  /** Set to `false` to disable interactive spinners (test injection). */
269
613
  interactive?: boolean;
270
614
  logger: Logger;
271
615
  /**
272
- * When true, after a successful `wrangler deploy`, discover and run all
273
- * pending data migrations via the worker's `/_lunora/migrate` admin RPC.
274
- * The worker must be live (exit 0) before migrations are attempted.
275
- *
276
- * Implementation note: the status RPC returns the full shard-level
277
- * migration state, but there is no single authoritative "list of pending
278
- * migration ids" that can be read client-side before running the worker.
279
- * Instead, `--migrate` runs `migrate status` followed by `migrate up` for
280
- * each migration id discovered locally via `discoverMigrations`. The
281
- * worker's `MigrationRunner` is idempotent — running `up` on an already-
282
- * applied migration is a no-op — so this approach is safe.
283
- */
616
+ * When true, after a successful `wrangler deploy`, discover and run all
617
+ * pending data migrations via the worker's `/_lunora/migrate` admin RPC.
618
+ * The worker must be live (exit 0) before migrations are attempted.
619
+ *
620
+ * Implementation note: the status RPC returns the full shard-level
621
+ * migration state, but there is no single authoritative "list of pending
622
+ * migration ids" that can be read client-side before running the worker.
623
+ * Instead, `--migrate` runs `migrate status` followed by `migrate up` for
624
+ * each migration id discovered locally via `discoverMigrations`. The
625
+ * worker's `MigrationRunner` is idempotent — running `up` on an already-
626
+ * applied migration is a no-op — so this approach is safe.
627
+ */
284
628
  migrate?: boolean;
285
629
  /** Admin bearer token for `--migrate` (falls back to `LUNORA_ADMIN_TOKEN`). */
286
630
  migrateToken?: string;
287
631
  /**
288
- * Worker URL for `--migrate`. REQUIRED when `--migrate` is set — the deploy
289
- * handler never captures the URL `wrangler deploy` published to, so there is
290
- * no safe default; omitting it would silently target `http://localhost:8787`
291
- * (the dev worker), applying the migration to local state instead of prod.
292
- */
632
+ * Worker URL for `--migrate`. REQUIRED when `--migrate` is set — the deploy
633
+ * handler never captures the URL `wrangler deploy` published to, so there is
634
+ * no safe default; omitting it would silently target `http://localhost:8787`
635
+ * (the dev worker), applying the migration to local state instead of prod.
636
+ */
293
637
  migrateUrl?: string;
294
638
  /**
295
- * Confirm a production data migration triggered via `--migrate` (the
296
- * `migrate up --prod` confirmation the standalone command requires). Without
297
- * it a `--migrate --migrate-url &lt;prod>` deploy refuses to run the migration.
298
- */
639
+ * Confirm a production data migration triggered via `--migrate` (the
640
+ * `migrate up --prod` confirmation the standalone command requires). Without
641
+ * it a `--migrate --migrate-url <prod>` deploy refuses to run the migration.
642
+ */
299
643
  migrateYes?: boolean;
300
644
  /**
301
- * Emit the bundled worker to this directory via `wrangler deploy --outdir`
302
- * (paired with `dryRun` by `lunora build`). Also writes esbuild metadata to
303
- * `&lt;outDir>/bundle-meta.json`. When unset, no artifact is written.
304
- */
645
+ * Emit the bundled worker to this directory via `wrangler deploy --outdir`
646
+ * (paired with `dryRun` by `lunora build`). Also writes esbuild metadata to
647
+ * `<outDir>/bundle-meta.json`. When unset, no artifact is written.
648
+ */
305
649
  outDir?: string;
306
650
  /**
307
- * Upload a preview version (`wrangler versions upload`) instead of a live
308
- * `wrangler deploy`. Codegen + the drift gate + validation still run, but
309
- * the post-deploy finalize (migrations, baseline re-bless, auto-link, the
310
- * production summary) is skipped — a preview never shifts live traffic.
311
- */
651
+ * Upload a preview version (`wrangler versions upload`) instead of a live
652
+ * `wrangler deploy`. Codegen + the drift gate + validation still run, but
653
+ * the post-deploy finalize (migrations, baseline re-bless, auto-link, the
654
+ * production summary) is skipped — a preview never shifts live traffic.
655
+ */
312
656
  preview?: boolean;
313
657
  /** Railpack-availability probe injected in tests. Defaults to a real `railpack --version` + `BUILDKIT_HOST` check. */
314
658
  railpackAvailable?: DockerProbe;
659
+ /** Confirm prompt for the missing-secret offer; injected in tests. Defaults to the TTY prompt. */
660
+ secretConfirm?: (message: string) => Promise<boolean>;
661
+ /** Remote-secret lister for the missing-secret offer; injected in tests. Defaults to `wrangler secret list`. */
662
+ secretLister?: (inputs: ListRemoteSecretsInputs) => Promise<ListRemoteSecretsResult>;
315
663
  skipCodegen?: boolean;
316
664
  spawner?: Spawner;
317
665
  /**
318
- * Deploy to a temporary Cloudflare account (`wrangler deploy --temporary`).
319
- * For unauthenticated use only: wrangler provisions a short-lived account +
320
- * token, deploys, and prints a claim URL; the deployment stays live ~60
321
- * minutes before the unclaimed account is deleted. Wrangler itself errors
322
- * if credentials are already present (OAuth / `CLOUDFLARE_API_TOKEN` /
323
- * global API key), so we pass the flag straight through without guarding.
324
- */
666
+ * Fail the deploy when codegen reports an ERROR-level advisory. Same
667
+ * option `lunora codegen` exposes as `--no-strict-advisories`; defaults to
668
+ * CI detection (on in CI, off locally) so a legitimately-partial target
669
+ * can still be shipped interactively. Does NOT gate platform diagnostics
670
+ * (`platform_unsupported_feature` / `platform_unknown_target`), which
671
+ * always block — those mean the emitted `ctx.*` surface does not match
672
+ * what the target can serve, not merely a style nit.
673
+ */
674
+ strictAdvisories?: boolean;
675
+ /**
676
+ * Deploy target. Falls back to `"target"` in `lunora.config.*`, then
677
+ * `"cloudflare"`, which selects the wrangler
678
+ * toolchain — i.e. today's behavior for every project. An unregistered name
679
+ * throws rather than falling back, so a typo can never ship the app to the
680
+ * wrong provider.
681
+ */
682
+ target?: string;
683
+ /**
684
+ * Deploy to a temporary Cloudflare account (`wrangler deploy --temporary`).
685
+ * For unauthenticated use only: wrangler provisions a short-lived account +
686
+ * token, deploys, and prints a claim URL; the deployment stays live ~60
687
+ * minutes before the unclaimed account is deleted. Wrangler itself errors
688
+ * if credentials are already present (OAuth / `CLOUDFLARE_API_TOKEN` /
689
+ * global API key), so we pass the flag straight through without guarding.
690
+ */
325
691
  temporary?: boolean;
326
692
  /** Re-bless the committed schema baseline with the current shape (accepts breaking drift). */
327
693
  updateSchemaBaseline?: boolean;
328
694
  }
695
+ /**
696
+ * What this run put where — the identity of the thing that was just deployed.
697
+ *
698
+ * Present on every run that reached (and completed) the wrangler invocation,
699
+ * including `--dry-run` and `--preview`, so a consumer can tell "nothing went
700
+ * live" from "went live" without inferring it from a missing `url`. A dry run
701
+ * publishes nothing and therefore never carries a `url`.
702
+ *
703
+ * No `versionId`: the pinned wrangler (see the `wrangler` catalog entry in
704
+ * `pnpm-workspace.yaml`) has no structured deploy output
705
+ * and no flag that returns the version id — it only prints it in prose, and
706
+ * scraping a second value out of prose is exactly what this shouldn't do. The
707
+ * id is available from `lunora deployments list` after the fact.
708
+ */
709
+ interface DeployedIdentity {
710
+ /** ISO-8601 stamp taken when the wrangler invocation returned. */
711
+ deployedAt: string;
712
+ /** True when `--dry-run` validated + bundled without publishing. */
713
+ dryRun: boolean;
714
+ /** The Cloudflare environment this run targeted, when `--env` named one. */
715
+ env?: string;
716
+ /** True when `--preview` uploaded a version instead of shifting live traffic. */
717
+ preview: boolean;
718
+ /** The URL wrangler reported publishing to; absent on a dry run, or when the output carried no URL. */
719
+ url?: string;
720
+ /** The Worker name from the project's wrangler config. */
721
+ workerName?: string;
722
+ }
329
723
  interface DeployCommandResult {
330
724
  code: number;
725
+ /** What was deployed and where — set once the wrangler invocation completed. */
726
+ deployment?: DeployedIdentity;
331
727
  descriptor: SpawnDescriptor | undefined;
332
728
  /** Set when the run aborted before reaching the wrangler invocation. */
333
729
  error?: string;
730
+ /**
731
+ * The `--health-check` probe's verdict, when the flag was set and the probe
732
+ * ran. A red probe fails the command (`code` is non-zero) — but the deploy
733
+ * itself still succeeded, which is why the reason is reported separately
734
+ * from `error`.
735
+ */
736
+ healthCheck?: {
737
+ error?: string;
738
+ ok: boolean;
739
+ url: string;
740
+ };
741
+ /**
742
+ * The `.dev.vars`-shaped filename (never a full path, never a value) a
743
+ * secret minted during this run was recorded into, when the missing-
744
+ * secret gate minted one — `.dev.vars` for the default environment, or a
745
+ * `.dev.vars.<env>` sibling for an explicit `--env`. `undefined` when
746
+ * nothing was minted this run.
747
+ */
748
+ mintedSecretsFile?: string;
334
749
  /** The schema-drift gate verdict, when it ran (skipped on `--skip-codegen`). */
335
750
  schemaDrift?: {
336
751
  blocked: boolean;
@@ -342,48 +757,107 @@ interface DeployCommandResult {
342
757
  };
343
758
  }
344
759
  /**
345
- * Run a deploy, then (in `--format json` mode) serialize the structured
346
- * {@link DeployCommandResult} to stdout. Human/progress logging is routed to
347
- * stderr for json output so stdout carries only the single JSON document.
348
- */
760
+ * The commands that run the pre-deploy pipeline, as the OPERATOR typed them.
761
+ *
762
+ * These checks are reached from `lunora deploy`, `lunora prepare` and
763
+ * `lunora build`, and a blocked run naming a command the operator never ran
764
+ * reads as a bug in the tool rather than a problem in the project.
765
+ *
766
+ * `build` is one of them: it delegates to `runDeployCommand({ dryRun: true })`.
767
+ * The name is threaded through rather than assumed, because the drift gate uses
768
+ * it for two operator-facing decisions — which override flags to offer, and what
769
+ * to call the thing that was blocked. Hardcoding `"deploy"` here meant `lunora
770
+ * build` reported "deploy blocked" for a deploy nobody attempted and recommended
771
+ * a flag `build` rejects with a raw stack trace.
772
+ */
773
+ type PreDeployCommand = "build" | "deploy" | "prepare";
774
+ /**
775
+ * Run a deploy. In `--format json` mode the human/progress channel is already on
776
+ * stderr (`defineHandler` routed it) and the Vercel-style summary is skipped, so
777
+ * stdout is left to the single result document `execute` returns.
778
+ */
349
779
  declare const runDeployCommand: (options: DeployCommandOptions) => Promise<DeployCommandResult>;
350
- /** `lunora deploy` handler (lazy-loaded via the command's `loader`). */
351
780
  /**
352
- * Start the codegen watch loop and return a handle to stop it. Regenerates on
353
- * startup, then on debounced changes under `lunora/` (ignoring writes to the
354
- * `_generated/` output to avoid a feedback loop). If the platform can't do a
355
- * recursive watch, it logs once and falls back to startup-only codegen.
356
- */
781
+ * Start the codegen watch loop and return a handle to stop it. Regenerates on
782
+ * startup, then on debounced changes under `lunora/` (ignoring writes to the
783
+ * `_generated/` output to avoid a feedback loop). If the platform can't do a
784
+ * recursive watch, it logs once and falls back to startup-only codegen.
785
+ */
357
786
  declare const startCodegenWatch: (options: CodegenWatcherOptions) => CodegenWatcherHandle;
358
787
  interface CodegenWatcherOptions {
359
788
  /** Which API spec(s) to emit. Defaults to codegen's `"openapi"` when omitted. */
360
789
  apiSpec?: CodegenOptions["apiSpec"];
361
790
  /** Debounce window for coalescing rapid edits. Defaults to 100ms. */
362
791
  debounceMs?: number;
792
+ /**
793
+ * The caller's logs are NDJSON on stdout, so the `postcodegen` hook's own
794
+ * stdout must be routed to stderr or it corrupts the stream. `lunora dev`
795
+ * turns this on for `--json` AND for a detected AI agent.
796
+ */
797
+ jsonLogs?: boolean;
363
798
  logger: Logger;
364
799
  /** Override the lunora subdirectory name. Defaults to `"lunora"`. */
365
800
  lunoraDirectory?: string;
366
801
  /** Project root containing the `lunora/` directory. */
367
802
  projectRoot: string;
803
+ /** Process spawner for the `postcodegen` hook. Injectable so tests need no real subprocess. */
804
+ spawner?: Spawner;
805
+ /** Deploy target the emitted `ctx.*` surface is tailored to. Resolved by the caller; falls back to `"target"` in `lunora.config.*`, then `"cloudflare"`. */
806
+ target?: string;
368
807
  }
369
808
  interface CodegenWatcherHandle {
370
- /** Stop watching and cancel any pending regeneration. */
371
- close: () => void;
372
- /**
373
- * `true` when the platform supports recursive watch and the loop is active.
374
- * `false` when `fs.watch({ recursive })` threw — startup-only codegen was run
375
- * but schema edits will NOT auto-regenerate. Callers can surface this in the
376
- * dev banner so the degraded state is visible beyond the single startup warning.
377
- */
809
+ /**
810
+ * Stop watching, drop any queued regeneration, and resolve once the run
811
+ * already in flight has finished.
812
+ *
813
+ * Awaiting the result is what keeps a `postcodegen` child from being
814
+ * orphaned by the caller's `process.exit`; a caller that only needs the
815
+ * watcher detached can ignore it.
816
+ */
817
+ close: () => Promise<void>;
818
+ /**
819
+ * Resolves once the startup regeneration — codegen AND the project's
820
+ * `postcodegen` — has finished.
821
+ *
822
+ * Await it before starting anything that reads generated output. `runCodegen`
823
+ * is synchronous and has already run by the time `startCodegenWatch` returns,
824
+ * but the hook is the step that FINISHES that output, so a worker spawned
825
+ * without waiting can bundle the unfinished copy. Resolves (never rejects)
826
+ * even when codegen or the hook failed — both report for themselves, and a
827
+ * dev server still has to come up.
828
+ */
829
+ ready: Promise<void>;
830
+ /**
831
+ * `true` when the platform supports recursive watch and the loop is active.
832
+ * `false` when `fs.watch({ recursive })` threw — startup-only codegen was run
833
+ * but schema edits will NOT auto-regenerate. Callers can surface this in the
834
+ * dev banner so the degraded state is visible beyond the single startup warning.
835
+ */
378
836
  watchAvailable: boolean;
379
837
  }
380
838
  /**
381
- * Start the studio server and resolve once it is listening. Loads the static
382
- * bundle + renders the host HTML once up front; serves them and proxies
383
- * `/_lunora/*` (HTTP + WS) to the worker.
384
- */
839
+ * Readiness probe seam — tests swap the real HTTP probe out.
840
+ *
841
+ * The optional `signal` lets a caller cancel an attempt already in flight. Its
842
+ * absence is why a teardown used to leave one request dangling for up to
843
+ * {@link ATTEMPT_TIMEOUT_MS} after the dev server had been told to stop.
844
+ */
845
+ type ReadinessProbe = (origin: string, signal?: AbortSignal) => Promise<boolean>;
846
+ /**
847
+ * Start the studio server and resolve once it is listening. Loads the static
848
+ * bundle + renders the host HTML once up front; serves them and proxies
849
+ * `/_lunora/*` (HTTP + WS) to the worker.
850
+ */
385
851
  declare const startStudioServer: (options: StudioServerOptions) => Promise<StudioServerHandle>;
386
852
  interface StudioServerOptions {
853
+ /**
854
+ * API-spec mode the host runs codegen with, forwarded to the local endpoints
855
+ * so a studio edit regenerates the SAME spec files the host's own codegen run
856
+ * writes. Codegen writes the spec its mode names and deletes the other, so
857
+ * omitting it made every studio edit delete an `apiSpec: "openrpc"` project's
858
+ * `openrpc.json`.
859
+ */
860
+ apiSpec?: CodegenOptions["apiSpec"];
387
861
  /** Project root — `.dev.vars` is read from here for the admin token. */
388
862
  cwd: string;
389
863
  /** Loopback host to bind. Defaults to `127.0.0.1` (admin tooling stays local). */
@@ -403,6 +877,24 @@ interface StudioServerHandle {
403
877
  /** The URL to open in a browser. */
404
878
  url: string;
405
879
  }
880
+ /**
881
+ * How the dev child runs. `wrangler` is the classic `lunora dev` stack (wrangler
882
+ * worker + embedded studio + codegen watch) for a standalone class-C project.
883
+ * `vite` is a project on `@lunora/vite`: the plugin already runs the worker,
884
+ * studio, and codegen inside the Vite dev server, so `lunora dev` runs the
885
+ * project's own dev script and gets out of the way — this also covers class-B
886
+ * frameworks whose own dev server runs the worker in `workerd` (Astro 6 +
887
+ * `@astrojs/cloudflare`, which embeds `@cloudflare/vite-plugin` in `astro dev`:
888
+ * SSR + `/_lunora/*` + `ShardDO` in one process, HMR intact). `framework-worker`
889
+ * is a class-B framework whose dev server CANNOT host the `ShardDO` Durable
890
+ * Object (SvelteKit / Nuxt: their adapters use wrangler's `getPlatformProxy()`,
891
+ * which runs an empty-script Miniflare and does not emulate internal DOs); there
892
+ * `lunora dev` runs the framework's own dev server (front door, HMR, and — via
893
+ * its `@lunora/vite` plugin — studio + codegen) AND a second `wrangler dev`
894
+ * sidecar that owns the real `ShardDO` in `workerd`, wired via the committed
895
+ * `wrangler.dev.jsonc`.
896
+ */
897
+ type DevFlavor = "framework-worker" | "vite" | "wrangler";
406
898
  /** A running worker child the orchestrator controls: send signals, await its exit. */
407
899
  interface WorkerProcess {
408
900
  /** Resolves with the worker's exit code (1 if it failed to start). */
@@ -419,15 +911,39 @@ interface DevCommandOptions {
419
911
  /** Disable the codegen watch loop. */
420
912
  codegen?: boolean;
421
913
  cwd?: string;
914
+ /**
915
+ * Override where the binding manifest is written. One is always produced at
916
+ * {@link DEV_BINDINGS_FILE}; naming a path also makes a derivation failure
917
+ * fatal, since a named path means something is waiting on it.
918
+ */
919
+ emitBindings?: string;
422
920
  /** Injection seam for tests — defaults to the real `.dev.vars` scaffolder. */
423
921
  ensureEnv?: typeof ensureDevVariables;
424
922
  /** Injection seam for tests — defaults to the real `.dev.vars.example` package-aware scaffolder. */
425
923
  ensureExample?: typeof ensureDevVarsExample;
924
+ /** Injection seam for tests — defaults to the real empty-secret/admin-token filler. */
925
+ fillSecrets?: typeof fillDevSecrets;
926
+ /** Injection seam for tests — defaults to the real free-port probe ({@link findAvailablePort}). */
927
+ findFreePort?: (preferred: number) => Promise<number>;
928
+ /** Dev flavor override (tests / callers that already detected it) — defaults to {@link detectDevFlavor}. */
929
+ flavor?: DevFlavor;
930
+ /** Injection seam for tests — defaults to the real IPv6-loopback probe ({@link hasIpv6Loopback}). */
931
+ hasIpv6Loopback?: () => boolean;
932
+ /** `wrangler dev` devtools inspector port (`--inspector-port`). Wrangler flavor only — see {@link resolveInspectorPort}. */
933
+ inspectorPort?: number;
934
+ /**
935
+ * Logs are NDJSON on stdout (`--json`, or a detected AI agent). Forwarded to
936
+ * the codegen watcher so a `postcodegen` script's own stdout is routed to
937
+ * stderr instead of corrupting the stream.
938
+ */
939
+ jsonLogs?: boolean;
426
940
  logger: Logger;
427
941
  /** Injection seam for tests — defaults to the real remote-config materializer. */
428
942
  materializeRemote?: typeof materializeRemoteWranglerConfig;
429
943
  /** Studio server port. */
430
944
  port?: number;
945
+ /** Injection seam for tests — defaults to the real HTTP readiness probe. Without it the suite issues live GETs to the dev port. */
946
+ probeReady?: ReadinessProbe;
431
947
  /** Proxy D1/KV/R2 bindings to the deployed worker during dev (`LUNORA_REMOTE=1` / `--remote`); DO shards stay local. */
432
948
  remote?: boolean;
433
949
  /** Injection seam for tests — defaults to the real codegen watcher. */
@@ -438,6 +954,19 @@ interface DevCommandOptions {
438
954
  startWorker?: WorkerSpawner;
439
955
  /** Disable the embedded studio server. */
440
956
  studio?: boolean;
957
+ /** Deploy target the emitted `ctx.*` surface is tailored to. Resolved by the caller; falls back to `"target"` in `lunora.config.*`, then `"cloudflare"`. */
958
+ target?: string;
959
+ /**
960
+ * Injection seam for tests — defaults to parking until SIGINT.
961
+ *
962
+ * Attached mode (`--no-worker`) ends only on a signal, so without this the
963
+ * whole branch is unreachable from a test. That is how the readiness probe
964
+ * came to be wired after the early return, reported for a flavor it never
965
+ * covered, and shipped.
966
+ */
967
+ waitForInterrupt?: (logger: Logger) => Promise<number>;
968
+ /** Disable the `wrangler dev` spawn — an external task runner owns the worker. */
969
+ worker?: boolean;
441
970
  /** `wrangler dev` port. */
442
971
  workerPort?: number;
443
972
  }
@@ -445,10 +974,10 @@ interface DevRemotePlan {
445
974
  /** Short binding labels remoted (e.g. `"DB (D1)"`), for the banner. */
446
975
  bindings: string[];
447
976
  /**
448
- * Removes the generated temp wrangler config when dev exits. Always present
449
- * and idempotent — a no-op when remote mode is off or nothing was
450
- * materialized. The dev loop calls it on every shutdown path.
451
- */
977
+ * Removes the generated temp wrangler config when dev exits. Always present
978
+ * and idempotent — a no-op when remote mode is off or nothing was
979
+ * materialized. The dev loop calls it on every shutdown path.
980
+ */
452
981
  cleanup: () => void;
453
982
  /** Whether remote mode was requested. */
454
983
  enabled: boolean;
@@ -456,172 +985,87 @@ interface DevRemotePlan {
456
985
  reason?: string;
457
986
  }
458
987
  interface DevCommandPlan {
459
- codegenEnabled: boolean;
988
+ /** Which stack the child runs — see {@link DevFlavor}. */
989
+ flavor: DevFlavor;
990
+ /**
991
+ * One-line redirect hint printed when a meta-framework is detected on the
992
+ * wrangler flavor: without `@lunora/vite` in the dependencies the worker
993
+ * still runs *inside* the framework's dev server, so the user should run
994
+ * their framework dev script for the full app. `undefined` for the vite
995
+ * flavor (`lunora dev` already runs the project's dev script there) and
996
+ * for a standalone project. Purely informational: the wrangler spawn runs
997
+ * regardless.
998
+ */
999
+ frameworkHint?: string;
1000
+ /**
1001
+ * True when `wrangler dev` was given `--ip 127.0.0.1` because the host has no
1002
+ * IPv6 loopback (`::1`) — surfaced so the dev loop can note the rebind.
1003
+ * Always `false` for the vite flavor (the plugin owns its own bind).
1004
+ */
1005
+ ipv4LoopbackForced: boolean;
460
1006
  /** The remote-binding decision: which D1/KV/R2 bindings hit the deployed worker. */
461
1007
  remote: DevRemotePlan;
1008
+ runsCodegenWatch: boolean;
1009
+ /**
1010
+ * The `wrangler dev` sidecar for the `framework-worker` flavor (SvelteKit /
1011
+ * Nuxt): a second child that owns the real `ShardDO` in `workerd`, wired via
1012
+ * the committed `wrangler.dev.jsonc`. `undefined` for every other flavor —
1013
+ * only the two-process class-B stack has a sidecar. When present, `wrangler`
1014
+ * (above) is the framework's own dev server (the front door / HMR) and this
1015
+ * is the Lunora realtime plane.
1016
+ */
1017
+ sidecar?: SpawnDescriptor & {
1018
+ tag: string;
1019
+ };
462
1020
  studioEnabled: boolean;
463
1021
  studioPort: number;
1022
+ /**
1023
+ * Whether this process spawns `wrangler dev`.
1024
+ *
1025
+ * `--no-worker` turns it off so an external task runner (Turbo, Nx, vis, a
1026
+ * Procfile) can own worker supervision while `lunora dev` still provides
1027
+ * codegen-watch and Studio. Without it, `lunora dev` insisted on being the
1028
+ * process root, which is what blocked running the Lunora worker as one node
1029
+ * in a larger dev graph.
1030
+ */
1031
+ workerEnabled: boolean;
464
1032
  workerOrigin: string;
465
1033
  workerPort: number;
466
- /** The single child process `lunora dev` spawns: `wrangler dev`. */
1034
+ /** The primary child `lunora dev` spawns: `wrangler dev` (wrangler flavor) or the framework/`vite dev` server (vite / framework-worker). */
467
1035
  wrangler: SpawnDescriptor & {
468
1036
  tag: string;
469
1037
  };
470
1038
  }
471
1039
  /**
472
- * Resolve remote-binding mode into the extra `wrangler dev` args + a banner
473
- * summary. When `--remote`/`LUNORA_REMOTE` is set we materialize a temp wrangler
474
- * config with `"remote": true` on each D1/KV/R2 binding (Durable Object shards
475
- * stay local) and point `wrangler dev --config` at it, so the local worker reads
476
- * and writes the **deployed** resources. When disabled, or when there's nothing
477
- * to remote, the args stay empty and dev runs fully local.
478
- */
479
- /**
480
- * Plan `lunora dev`: it runs the worker via `wrangler dev` and nothing else as a
481
- * child process. Vite is intentionally NOT spawned — a project may not use Vite,
482
- * and when it does, the `@lunora/vite` plugin already runs the worker inside
483
- * Vite, so the user runs `vite` themselves. Pure + synchronous so it's unit-testable.
484
- */
1040
+ * Plan `lunora dev`. Wrangler flavor: the worker runs via `wrangler dev` and
1041
+ * nothing else as a child process. Vite flavor (`@lunora/vite` declared): the
1042
+ * plugin already runs the worker inside the Vite dev server, so the one child
1043
+ * is the project's own dev script (`vite dev`, `astro dev`, …) and every CLI
1044
+ * sibling is disabled. Pure + synchronous so it's unit-testable.
1045
+ */
485
1046
  declare const planDevCommand: (options: DevCommandOptions) => DevCommandPlan;
486
1047
  /**
487
- * Start codegen watch + the studio server, spawn `wrangler dev`, print the
488
- * banner, and resolve when the worker exits or the user interrupts — tearing
489
- * down the sibling servers either way. The three side-effecting pieces (worker,
490
- * studio, codegen) are injectable so this is testable without real I/O.
491
- */
1048
+ * Start codegen watch + the studio server, spawn `wrangler dev`, print the
1049
+ * banner, and resolve when the worker exits or the user interrupts — tearing
1050
+ * down the sibling servers either way. The three side-effecting pieces (worker,
1051
+ * studio, codegen) are injectable so this is testable without real I/O.
1052
+ */
492
1053
  declare const runDevCommand: (options: DevCommandOptions) => Promise<{
493
1054
  code: number;
494
1055
  plan: DevCommandPlan;
495
1056
  }>;
496
- /** `lunora dev` handler (lazy-loaded via the command's `loader`). */
497
1057
  /** Supported CI providers. */
498
1058
  type CiProvider = "github" | "gitlab";
499
- /** A registry item a feature can install. */
500
- type FeatureItem = "auth" | "auth-auth0" | "auth-clerk" | "mail";
501
- /** The auth-provider choices offered for `add auth` / the init auth prompt. Each value is a registry item name. */
502
-
503
- /** A feature offered in the post-scaffold multi-select. `value` is the stack-feature key, not (yet) a registry item. */
504
- type StackFeature = "auth" | "email";
505
- interface OfferDeps {
506
- /** Apply one or more registry items into the new project; resolves `true` on success. */
507
- apply: (names: ReadonlyArray<FeatureItem>) => Promise<boolean>;
508
- /** When `false`, skip all prompts and print the later-setup hint. */
509
- interactive: boolean;
510
- logger: Logger;
511
- /** Multi-select among the stack features to add (TTY-backed in production). */
512
- multiSelect: (message: string, options: ReadonlyArray<{
513
- description?: string;
514
- label: string;
515
- value: StackFeature;
516
- }>, settings?: {
517
- defaults?: ReadonlyArray<StackFeature>;
518
- }) => Promise<StackFeature[]>;
519
- /** Single-select among the auth providers (TTY-backed in production). */
520
- select: (message: string, options: ReadonlyArray<{
521
- description?: string;
522
- label: string;
523
- value: FeatureItem;
524
- }>, settings?: {
525
- default?: FeatureItem;
526
- }) => Promise<FeatureItem | undefined>;
527
- }
528
1059
  /**
529
- * Offer the stack features (authentication, transactional email) in ONE
530
- * multi-select after a successful scaffold. When auth is picked, a follow-up
531
- * single-select chooses the provider (email+password / Clerk / Auth0); email
532
- * maps to the `mail` item. Picked items are applied in selection order.
533
- * Non-interactive: prints how to add them later and changes nothing.
534
- */
535
- type Template = "astro" | "next" | "nuxt" | "standalone" | "sveltekit" | "tanstack-start-react" | "tanstack-start-solid" | "vite";
536
- interface InitCommandOptions {
537
- /**
538
- * When true, accept `--source` values that don't start with `gh:` /
539
- * `github:` / `https://` or that contain `..`. Defaults to false; the CLI
540
- * gate exists to stop arbitrary filesystem / scheme sources from being
541
- * pulled without the caller opting in.
542
- */
543
- allowUnsafeSource?: boolean;
544
- /** When set, also scaffold a CI deploy pipeline for the given provider. */
545
- ci?: CiProvider;
546
- cwd?: string;
547
- /**
548
- * Local directory containing the template subdirs (e.g. `vite/`,
549
- * `standalone/`). When provided, skips the network fetch entirely.
550
- * Useful for offline runs, the clean-machine smoke test, and unit tests.
551
- */
552
- from?: string;
553
- /**
554
- * When true, configure Lunora into the CURRENT project (`cwd`) instead of
555
- * scaffolding a new directory. Finds an existing `vite.config.*` and
556
- * patches it via `patchViteConfig`, or creates a minimal one when absent.
557
- * All other scaffold options (`name`, `templateType`, `source`, `from`)
558
- * are ignored in this mode.
559
- */
560
- inPlace?: boolean;
561
- /**
562
- * Force the post-scaffold "add auth / email?" offer on (the `--interactive`
563
- * flag). When omitted, the offer runs only when stdin is a TTY. `--yes`
564
- * suppresses it regardless. Has no effect once {@link prompt} is injected.
565
- */
566
- interactive?: boolean;
567
- logger: Logger;
568
- name?: string;
569
- /**
570
- * Inject the offer's prompts (tests). When set, the offer is treated as
571
- * interactive regardless of TTY, and these drive the feature multi-select
572
- * and the auth-provider sub-select.
573
- */
574
- prompt?: Pick<OfferDeps, "multiSelect" | "select">;
575
- /**
576
- * Override the git ref (branch, tag, or commit) the default template source
577
- * is fetched from. Takes precedence over the version-derived ref. Ignored
578
- * when `source` or `from` is set.
579
- */
580
- ref?: string;
581
- /** Local registry root for the offer's `runAddCommand` (offline / tests). Mirrors `from` but for registry items. */
582
- registryFrom?: string;
583
- /** Override the remote registry source base for the offer (default `gh:anolilab/lunora/registry`). */
584
- registrySource?: string;
585
- /**
586
- * Override the remote source giget downloads from. Default:
587
- * `gh:anolilab/lunora/templates/&lt;templateType>#&lt;ref>`, where `&lt;ref>` is
588
- * the `ref` option when set, else derived from the CLI version (pre-release
589
- * channels → their branch, stable → `main`). Tests typically use `from`
590
- * instead to skip the network.
591
- */
592
- source?: string;
593
- templateType?: Template;
594
- /** Suppress the offer entirely (the `--yes` flag): scaffold only, print the later-setup hint. */
595
- yes?: boolean;
596
- }
597
- interface InitCommandResult {
598
- code: number;
599
- files: ReadonlyArray<string>;
600
- target: string;
601
- }
602
- /**
603
- * `lunora init` entry: scaffold (in-place or a new directory), then — on success
604
- * — offer to add auth + email via the registry. The offer never affects the
605
- * scaffold's exit code.
606
- */
607
- declare const runInitCommand: (options: InitCommandOptions) => Promise<InitCommandResult>;
608
- /** Narrow a raw `--template` value to a known {@link Template} (defaults to vite). */
609
- interface MigrateGenerateCommandOptions {
610
- cwd?: string;
611
- logger: Logger;
612
- /** Migration name slug. Defaults to `auto`. */
613
- name?: string;
614
- /** Override the current time — used by tests for deterministic file names. */
615
- now?: () => Date;
616
- }
617
- interface MigrateGenerateCommandResult {
618
- code: number;
619
- /** Whether the diff was empty (no changes detected). */
620
- empty: boolean;
621
- /** Absolute path to the migration file (empty string when nothing was written). */
622
- migrationFile: string;
623
- }
624
- declare const runMigrateGenerateCommand: (options: MigrateGenerateCommandOptions) => MigrateGenerateCommandResult;
1060
+ * The per-framework auth-UI registry items (`auth-ui` resolves to one of these).
1061
+ *
1062
+ * Solid has two because these are copy-in source files, not a compiled package:
1063
+ * the 1.x and 2.0 spellings are mutually exclusive in the source itself, so the
1064
+ * two majors get one item each and {@link detectAuthUiItem} picks.
1065
+ */
1066
+ type AuthUiItem = "auth-ui-angular" | "auth-ui-react" | "auth-ui-solid" | "auth-ui-solid-v2" | "auth-ui-svelte" | "auth-ui-vue";
1067
+ /** A registry item a feature can install. */
1068
+ type FeatureItem = "auth" | "auth-auth0" | "auth-clerk" | AuthUiItem | "mail";
625
1069
  /** One catalog entry as `lunora registry list` reports it. */
626
1070
  interface CatalogItem {
627
1071
  description?: string;
@@ -631,13 +1075,11 @@ interface CatalogItem {
631
1075
  interface IndexItem extends CatalogItem {
632
1076
  title?: string;
633
1077
  }
634
- /** Names of the subdirectories under `root` that ship a `registry.json`. */
635
-
636
1078
  /**
637
- * Build the catalog (`index.json` contents) from a local registry root by
638
- * reading every item's `registry.json`. Used by both `lunora registry build`
639
- * and the registry tests so the committed index can't drift from the item dirs.
640
- */
1079
+ * Build the catalog (`index.json` contents) from a local registry root by
1080
+ * reading every item's `registry.json`. Used by both `lunora registry build`
1081
+ * and the registry tests so the committed index can't drift from the item dirs.
1082
+ */
641
1083
  declare const buildRegistryIndex: (root: string) => {
642
1084
  items: IndexItem[];
643
1085
  };
@@ -656,10 +1098,10 @@ interface RegistryBinding {
656
1098
  value: unknown;
657
1099
  }
658
1100
  /**
659
- * An environment variable an item needs. Scaffolded into `.dev.vars` (Workers'
660
- * local-secrets file) on add — non-secrets get their `value`; secrets get an
661
- * empty placeholder and a reminder to run `wrangler secret put` for production.
662
- */
1101
+ * An environment variable an item needs. Scaffolded into `.dev.vars` (Workers'
1102
+ * local-secrets file) on add — non-secrets get their `value`; secrets get an
1103
+ * empty placeholder and a reminder to run `wrangler secret put` for production.
1104
+ */
663
1105
  interface RegistryEnvVariable {
664
1106
  /** Human note on what the variable is for. */
665
1107
  description?: string;
@@ -670,6 +1112,13 @@ interface RegistryEnvVariable {
670
1112
  /** A default/example value for non-secret vars. */
671
1113
  value?: string;
672
1114
  }
1115
+ /** A re-export the item needs injected into the worker entry point (class-B/C only). */
1116
+ interface EntrypointReexport {
1117
+ /** Optional JS comment placed above the re-export line. */
1118
+ comment?: string;
1119
+ /** Module specifier (e.g. `"_generated/workflows"` → `export * from "./lunora/_generated/workflows"`). */
1120
+ module: string;
1121
+ }
673
1122
  /** The `registry.json` manifest shape. */
674
1123
  interface RegistryManifest {
675
1124
  /** wrangler.jsonc additions (best-effort structural edits). */
@@ -681,6 +1130,8 @@ interface RegistryManifest {
681
1130
  devDependencies?: Readonly<Record<string, string>>;
682
1131
  /** Post-install guidance printed after the item is added (per-item next steps). */
683
1132
  docs?: string;
1133
+ /** Worker-entry re-exports the item needs (class-B/C only). */
1134
+ entrypointReexports?: ReadonlyArray<EntrypointReexport>;
684
1135
  /** Environment variables the item needs; scaffolded into `.dev.vars`. */
685
1136
  envVars?: ReadonlyArray<RegistryEnvVariable>;
686
1137
  files: ReadonlyArray<RegistryFile>;
@@ -702,10 +1153,10 @@ interface AddCommandOptions {
702
1153
  diff?: boolean;
703
1154
  /** Print the plan and stop without writing anything. */
704
1155
  dryRun?: boolean;
1156
+ /** Output format: `pretty` (default) or `json` — a JSON snapshot of the plan/list. */
1157
+ format?: OutputFormat;
705
1158
  /** Local registry root (offline / tests). Expects per-item subdirs, each with a `registry.json`. */
706
1159
  from?: string;
707
- /** Emit a JSON snapshot of the plan/result. */
708
- json?: boolean;
709
1160
  /** `--list`: enumerate available items instead of adding. */
710
1161
  list?: boolean;
711
1162
  logger: Logger;
@@ -719,13 +1170,52 @@ interface AddCommandOptions {
719
1170
  ref?: string;
720
1171
  /** Override the remote registry source base (default gh:anolilab/lunora/registry). */
721
1172
  source?: string;
1173
+ /**
1174
+ * Customize each resolved manifest after it is loaded but before the plan is
1175
+ * printed / reconciled — used to inject user-chosen values into otherwise
1176
+ * static manifests (e.g. the R2 `bucket_name` the init storage prompt asks
1177
+ * for). Applied to every item; return the manifest unchanged to leave it as-is.
1178
+ */
1179
+ transformManifest?: (manifest: RegistryManifest) => RegistryManifest;
722
1180
  /** Skip the package.json mutation confirmation prompt. */
723
1181
  yes?: boolean;
724
1182
  }
725
- interface AddCommandResult {
1183
+ /**
1184
+ * One item in the `--format json` plan snapshot. Carries the concrete binding
1185
+ * VALUES, not just the key paths, so a plan consumer can audit the mutation
1186
+ * before it is applied.
1187
+ */
1188
+ interface RegistryPlanItem {
1189
+ bindings: {
1190
+ path: string;
1191
+ value: unknown;
1192
+ }[];
1193
+ deps: string[];
1194
+ devDependencies: string[];
1195
+ entrypointReexports: {
1196
+ comment?: string;
1197
+ module: string;
1198
+ }[];
1199
+ envVars: {
1200
+ name: string;
1201
+ secret?: boolean;
1202
+ value?: string;
1203
+ }[];
1204
+ files: {
1205
+ merge: RegistryFile["merge"];
1206
+ to: string;
1207
+ }[];
1208
+ name: string;
1209
+ requires: ReadonlyArray<string>;
1210
+ title?: string;
1211
+ }
1212
+ /** The `--format json` payload: the catalog (`list`) or the resolved plan (`add`). */
1213
+ interface RegistryCommandData {
1214
+ items: ReadonlyArray<CatalogItem | RegistryPlanItem>;
1215
+ }
1216
+ interface AddCommandResult extends CommandResult<RegistryCommandData> {
726
1217
  /** Bindings written to wrangler.jsonc. */
727
1218
  bindings: ReadonlyArray<string>;
728
- code: number;
729
1219
  /** Deps added to package.json. */
730
1220
  deps: ReadonlyArray<string>;
731
1221
  /** Files skipped because they already existed. */
@@ -733,20 +1223,244 @@ interface AddCommandResult {
733
1223
  /** Files written (absolute paths). */
734
1224
  written: ReadonlyArray<string>;
735
1225
  }
736
- /** One resolved item: its parsed manifest plus the (possibly staged) directory it lives in. */
1226
+ /**
1227
+ * A feature offered in the post-scaffold multi-select. `auth`/`email` carry a
1228
+ * sub-prompt or alias; every other value IS the registry item name applied
1229
+ * directly (`storage` → the `storage` registry item, etc.).
1230
+ */
1231
+ type StackFeature = "ai" | "auth" | "auth-ui" | "backup" | "browser" | "cloudflare-access" | "crons" | "email" | "flags" | "hyperdrive" | "payment" | "presence" | "queue" | "storage" | "workflow";
1232
+ /** Customize a resolved manifest before it is written (e.g. inject the chosen R2 bucket name). */
1233
+ type OfferTransformManifest = (manifest: RegistryManifest) => RegistryManifest;
1234
+ /**
1235
+ * One feature ready to apply: the registry item name(s), an optional manifest
1236
+ * transform, and a short `label` (the feature value) shown on the combined
1237
+ * progress line. Built up-front by the collectors so every prompt is answered
1238
+ * before any apply runs.
1239
+ */
1240
+ interface FeatureApply {
1241
+ label: string;
1242
+ names: ReadonlyArray<string>;
1243
+ transformManifest?: OfferTransformManifest;
1244
+ }
1245
+ interface OfferDeps {
1246
+ /**
1247
+ * Apply the collected features into the new project in one batch — resolves
1248
+ * `true` when every item succeeds. The CLI renders this as a single progress
1249
+ * line whose label changes per feature; each plan's `transformManifest`
1250
+ * customizes that item's manifest before it is written.
1251
+ */
1252
+ applyAll: (plans: ReadonlyArray<FeatureApply>) => Promise<boolean>;
1253
+ /** When `false`, skip all prompts and print the later-setup hint. */
1254
+ interactive: boolean;
1255
+ logger: Logger;
1256
+ /** Multi-select among the stack features to add (TTY-backed in production). */
1257
+ multiSelect: (message: string, options: ReadonlyArray<{
1258
+ description?: string;
1259
+ label: string;
1260
+ value: StackFeature;
1261
+ }>, settings?: {
1262
+ defaults?: ReadonlyArray<StackFeature>;
1263
+ }) => Promise<StackFeature[]>;
1264
+ /**
1265
+ * Features chosen non-interactively (the `--add` flag). When set, the
1266
+ * multi-select and every sub-prompt are skipped — each feature is applied with
1267
+ * its shipped defaults (base registry item, placeholder bindings).
1268
+ */
1269
+ preselected?: ReadonlyArray<StackFeature>;
1270
+ /** The new project's name — seeds smart defaults like the `project-uploads` bucket name. */
1271
+ projectName: string;
1272
+ /**
1273
+ * Resolve which per-framework auth-UI item (`auth-ui-react|vue|…`) fits the
1274
+ * scaffolded project. Injected by the CLI (detected from the template's deps);
1275
+ * defaults to `auth-ui-react` when absent so this module stays pure/testable.
1276
+ *
1277
+ * `undefined` is a REFUSAL, not "unknown": no auth-UI item fits this project
1278
+ * (React Native). `lunora add auth-ui` already refuses there, and this offer
1279
+ * used to `?? "auth-ui-react"` its way past that — copying ~85 DOM files into
1280
+ * an Expo app and exiting 0.
1281
+ */
1282
+ resolveAuthUiItem?: () => string | undefined;
1283
+ /** Single-select among the auth providers (TTY-backed in production). */
1284
+ select: (message: string, options: ReadonlyArray<{
1285
+ description?: string;
1286
+ label: string;
1287
+ value: FeatureItem;
1288
+ }>, settings?: {
1289
+ default?: FeatureItem;
1290
+ }) => Promise<FeatureItem | undefined>;
1291
+ /** Single-line text input (TTY-backed in production) — used for the storage bucket-name prompt. */
1292
+ text: (message: string, settings?: {
1293
+ default?: string;
1294
+ placeholder?: string;
1295
+ }) => Promise<string>;
1296
+ }
1297
+ /** One choice in the multi-select. */
1298
+ interface LintToolOption {
1299
+ description: string;
1300
+ label: string;
1301
+ value: LintTool;
1302
+ }
1303
+ interface LintToolOfferDeps {
1304
+ /** Write the ignores for the chosen tools — `applyLintIgnores` in production. */
1305
+ apply: (tools: ReadonlyArray<LintTool>) => LintIgnoreOutcome[];
1306
+ /** Tools already detectable in the scaffolded project — pre-selected in the prompt. */
1307
+ detected: ReadonlyArray<LintTool>;
1308
+ /** False in CI / `--yes` / off a TTY: skip the prompt and configure whatever was detected. */
1309
+ interactive: boolean;
1310
+ logger: Logger;
1311
+ multiSelect: (message: string, choices: ReadonlyArray<LintToolOption>, settings?: {
1312
+ defaults?: ReadonlyArray<LintTool>;
1313
+ }) => Promise<LintTool[]>;
1314
+ }
1315
+ type Template = "analog" | "astro" | "expo" | "next" | "nuxt" | "react-router" | "solid-v2" | "standalone" | "sveltekit" | "tanstack-start-react" | "tanstack-start-solid" | "vinext" | "vinext-pages";
1316
+ interface InitCommandOptions {
1317
+ /**
1318
+ * Add features non-interactively after scaffolding (the `--add` flag): a
1319
+ * comma-separated list of `ai | auth | auth-ui | backup | browser | cloudflare-access | crons | email | flags | hyperdrive | payment | presence | queue | storage | workflow`.
1320
+ * Bypasses the interactive multi-select and sub-prompts —
1321
+ * each named feature is applied with its shipped defaults.
1322
+ */
1323
+ add?: string;
1324
+ /**
1325
+ * When true, accept `--source` values that don't start with `gh:` /
1326
+ * `github:` / `https://` or that contain `..`. Defaults to false; the CLI
1327
+ * gate exists to stop arbitrary filesystem / scheme sources from being
1328
+ * pulled without the caller opting in.
1329
+ */
1330
+ allowUnsafeSource?: boolean;
1331
+ /** When set, also scaffold a CI deploy pipeline for the given provider. */
1332
+ ci?: CiProvider;
1333
+ cwd?: string;
1334
+ /**
1335
+ * Walk the whole flow — prompts, task list, next-steps, mascot — but make no
1336
+ * changes: skip the template fetch/copy, the feature applies, the dependency
1337
+ * install, and `git init`. Each skipped action logs a `would …` line instead.
1338
+ */
1339
+ dryRun?: boolean;
1340
+ /**
1341
+ * Local directory containing the template subdirs (e.g. `vite/`,
1342
+ * `standalone/`). When provided, skips the network fetch entirely.
1343
+ * Useful for offline runs, the clean-machine smoke test, and unit tests.
1344
+ */
1345
+ from?: string;
1346
+ /**
1347
+ * When true, configure Lunora into the CURRENT project (`cwd`) instead of
1348
+ * scaffolding a new directory. Finds an existing `vite.config.*` and
1349
+ * patches it via `patchViteConfig`, or creates a minimal one when absent.
1350
+ * All other scaffold options (`name`, `templateType`, `source`, `from`)
1351
+ * are ignored in this mode.
1352
+ */
1353
+ inPlace?: boolean;
1354
+ /**
1355
+ * Inject the post-scaffold install offer's prompts (tests). When set, the
1356
+ * offer runs regardless of TTY: `confirmInstall` drives the yes/no, and
1357
+ * `selectManager` picks among the detected managers.
1358
+ */
1359
+ installPrompt?: {
1360
+ confirmInstall: () => Promise<boolean>;
1361
+ selectManager: (managers: ReadonlyArray<PackageManager>) => Promise<PackageManager>;
1362
+ };
1363
+ /**
1364
+ * Force the post-scaffold "add auth / email?" offer on (the `--interactive`
1365
+ * flag). When omitted, the offer runs only when stdin is a TTY. `--yes`
1366
+ * suppresses it regardless. Has no effect once {@link prompt} is injected.
1367
+ */
1368
+ interactive?: boolean;
1369
+ /**
1370
+ * Test seam for the lint/formatter multi-select. Separate from {@link prompt}
1371
+ * because that one is pinned to the feature-offer's value union — reusing it
1372
+ * here would only typecheck through a cast.
1373
+ */
1374
+ lintPrompt?: LintToolOfferDeps["multiSelect"];
1375
+ logger: Logger;
1376
+ name?: string;
1377
+ /**
1378
+ * Local directory holding create-vite bases (one `template-<id>/` subdir per
1379
+ * framework). When set with `vite`, the overlay copies the base from disk
1380
+ * instead of fetching `create-vite` over the network — offline mode + tests.
1381
+ */
1382
+ overlayBaseFrom?: string;
1383
+ /** Probe for which package managers are installed (tests). Defaults to a real `<pm> --version` check. */
1384
+ packageManagerProbe?: PackageManagerProbe;
1385
+ /**
1386
+ * Inject the offer's prompts (tests). When set, the offer is treated as
1387
+ * interactive regardless of TTY, and these drive the feature multi-select,
1388
+ * the auth-provider sub-select, and the storage bucket-name text input.
1389
+ */
1390
+ prompt?: Pick<OfferDeps, "multiSelect" | "select" | "text">;
1391
+ /**
1392
+ * Override the git ref (branch, tag, or commit) the default template source
1393
+ * is fetched from. Takes precedence over the version-derived ref. Ignored
1394
+ * when `source` or `from` is set.
1395
+ */
1396
+ ref?: string;
1397
+ /** Local registry root for the offer's `runAddCommand` (offline / tests). Mirrors `from` but for registry items. */
1398
+ registryFrom?: string;
1399
+ /** Override the remote registry source base for the offer (default `gh:anolilab/lunora/registry`). */
1400
+ registrySource?: string;
1401
+ /**
1402
+ * Override the remote source giget downloads from. Default:
1403
+ * `gh:anolilab/lunora/templates/<templateType>#<ref>`, where `<ref>` is
1404
+ * the `ref` option when set, else derived from the CLI version (pre-release
1405
+ * channels → their branch, stable → `main`). Tests typically use `from`
1406
+ * instead to skip the network.
1407
+ */
1408
+ source?: string;
1409
+ /** Spawner for the post-scaffold dependency install (tests inject a recording stub). Defaults to a real subprocess. */
1410
+ spawner?: Spawner;
1411
+ templateType?: Template;
1412
+ /**
1413
+ * Scaffold via the **create-vite overlay** for this framework (`react`,
1414
+ * `vue`, `solid`, `svelte`, `vanilla`) instead of a bespoke template: fetch
1415
+ * the official create-vite base and apply the Lunora layer on top. Takes
1416
+ * precedence over `templateType`.
1417
+ */
1418
+ vite?: string;
1419
+ /** Suppress the offer entirely (the `--yes` flag): scaffold only, print the later-setup hint. */
1420
+ yes?: boolean;
1421
+ }
1422
+ interface InitCommandResult {
1423
+ code: number;
1424
+ files: ReadonlyArray<string>;
1425
+ target: string;
1426
+ }
1427
+ /**
1428
+ * `lunora init` entry: scaffold (in-place or a new directory), then — on success
1429
+ * — offer to add auth + email via the registry. The offer never affects the
1430
+ * scaffold's exit code.
1431
+ */
1432
+ declare const runInitCommand: (options: InitCommandOptions) => Promise<InitCommandResult>;
1433
+ interface MigrateGenerateCommandOptions {
1434
+ cwd?: string;
1435
+ logger: Logger;
1436
+ /** Migration name slug. Defaults to `auto`. */
1437
+ name?: string;
1438
+ /** Override the current time — used by tests for deterministic file names. */
1439
+ now?: () => Date;
1440
+ }
1441
+ interface MigrateGenerateCommandResult {
1442
+ code: number;
1443
+ /** Whether the diff was empty (no changes detected). */
1444
+ empty: boolean;
1445
+ /** Why it failed, when the reason is known — the shared `CommandResult` contract. */
1446
+ error?: string;
1447
+ /** Absolute path to the migration file (empty string when nothing was written). */
1448
+ migrationFile: string;
1449
+ }
1450
+ declare const runMigrateGenerateCommand: (options: MigrateGenerateCommandOptions) => MigrateGenerateCommandResult;
737
1451
  /** `lunora registry add` (one or more item names): scaffold items into the project. */
738
1452
  declare const runAddCommand: (options: AddCommandOptions) => Promise<AddCommandResult>;
739
1453
  /**
740
- * `lunora registry view` — inspect a registry item without installing it:
741
- * print its plan (files / deps / env vars) followed by the full contents of each
742
- * file it would scaffold. Resolves only the named item — no `requires` expansion.
743
- */
1454
+ * `lunora registry view` — inspect a registry item without installing it:
1455
+ * print its plan (files / deps / env vars) followed by the full contents of each
1456
+ * file it would scaffold. Resolves only the named item — no `requires` expansion.
1457
+ */
744
1458
  declare const runRegistryViewCommand: (options: AddCommandOptions) => Promise<AddCommandResult>;
745
1459
  /**
746
- * `lunora registry build` — regenerate `index.json` from the item directories
747
- * (the catalog `list` reads). With `--check`, verify the committed index matches
748
- * instead of rewriting it (exits non-zero on drift) — a CI guard.
749
- */
1460
+ * `lunora registry build` — regenerate `index.json` from the item directories
1461
+ * (the catalog `list` reads). With `--check`, verify the committed index matches
1462
+ * instead of rewriting it (exits non-zero on drift) — a CI guard.
1463
+ */
750
1464
  declare const runBuildIndexCommand: (options: AddCommandOptions) => Promise<AddCommandResult>;
751
1465
  /** Validate + narrow a parsed JSON value into a {@link RegistryManifest}. */
752
1466
  declare const parseManifest: (raw: unknown, itemName: string) => RegistryManifest;
@@ -764,23 +1478,6 @@ interface ResetCommandResult {
764
1478
  removed: ReadonlyArray<string>;
765
1479
  }
766
1480
  declare const runResetCommand: (options: ResetCommandOptions) => Promise<ResetCommandResult>;
767
- /** `lunora reset` handler (lazy-loaded via the command's `loader`). */
768
- /**
769
- * Tiny argv parser.
770
- *
771
- * Supports long options (`--name value`, `--name=value`, `--flag`), short
772
- * options (`-x value`, `-xvalue`), positional arguments (everything else, in
773
- * order), and a `--` terminator after which everything is positional.
774
- *
775
- * Intentionally small — replaces a full CLI library for the handful of
776
- * subcommands we need.
777
- */
778
- interface ParsedArgs {
779
- flags: Record<string, boolean>;
780
- options: Record<string, string>;
781
- positional: ReadonlyArray<string>;
782
- }
783
- declare const parseArgs: (argv: ReadonlyArray<string>, booleanFlags?: ReadonlySet<string>) => ParsedArgs;
784
1481
  type InsertSchemaExtensionResult = {
785
1482
  ok: true;
786
1483
  text: string;
@@ -789,12 +1486,12 @@ type InsertSchemaExtensionResult = {
789
1486
  reason: "already-applied" | "invalid-identifier" | "no-define-schema" | "non-object-argument";
790
1487
  };
791
1488
  /**
792
- * Append `.extend(&lt;key>.extension)` and a managed import to an existing
793
- * `lunora/schema.ts`. Idempotent: a second call for the same `key` returns
794
- * `already-applied` and leaves the text unchanged.
795
- * @param source the current `lunora/schema.ts` contents
796
- * @param key the registry item key (e.g. `"ratelimit"`)
797
- */
1489
+ * Append `.extend(<key>.extension)` and a managed import to an existing
1490
+ * `lunora/schema.ts`. Idempotent: a second call for the same `key` returns
1491
+ * `already-applied` and leaves the text unchanged.
1492
+ * @param source the current `lunora/schema.ts` contents
1493
+ * @param key the registry item key (e.g. `"ratelimit"`)
1494
+ */
798
1495
  declare const insertSchemaExtension: (source: string, key: string) => InsertSchemaExtensionResult;
799
1496
  /** Compact snapshot of a single global table — what we persist + diff. */
800
1497
  interface TableSnapshot {
@@ -804,6 +1501,20 @@ interface TableSnapshot {
804
1501
  name: string;
805
1502
  }
806
1503
  interface ColumnSnapshot {
1504
+ /**
1505
+ * The column's full validator shape — the SAME {@link FieldSnapshot} the
1506
+ * deploy gate diffs (`shared/schema-snapshot.ts`), not a second parallel
1507
+ * format.
1508
+ *
1509
+ * `sqlType` alone is lossy: `bigint`, `array`, `record`, `id`, `literal` and
1510
+ * `string` all map to the TEXT affinity, so `v.string()` → `v.bigint()` was
1511
+ * byte-identical here and `migrate generate` answered "no schema changes
1512
+ * detected" for a change `lunora prepare` blocks as breaking.
1513
+ *
1514
+ * Optional so a `.snapshot.json` written before this existed still parses —
1515
+ * it simply gets no deep check until the next generate rewrites it.
1516
+ */
1517
+ field?: FieldSnapshot;
807
1518
  /** True when the column accepts NULL (validator wrapped in v.optional). */
808
1519
  nullable: boolean;
809
1520
  /** SQLite type affinity, derived from the validator. */
@@ -837,26 +1548,34 @@ interface SchemaDiff {
837
1548
  unsupported: ReadonlyArray<UnsupportedEntry>;
838
1549
  }
839
1550
  /**
840
- * Map a Lunora validator kind to a SQLite type affinity — the canonical
841
- * `@lunora/d1/dialect` mapping. Re-exported under this name because
842
- * `schema-snapshot.ts` builds the persisted snapshot from it.
843
- */
1551
+ * Map a Lunora validator kind to a SQLite type affinity — the canonical
1552
+ * `@lunora/d1/dialect` mapping. Re-exported under this name because
1553
+ * `schema-snapshot.ts` builds the persisted snapshot from it.
1554
+ */
844
1555
  declare const validatorKindToSqlType: (kind: string) => ColumnSnapshot["sqlType"];
845
- /** Emit `CREATE TABLE` SQL for a new global table. */
1556
+ /**
1557
+ * Emit `CREATE TABLE` SQL for a new global table.
1558
+ *
1559
+ * Refuses a table past D1's column ceiling rather than writing SQL that
1560
+ * `lunora migrate up` will reject: the runtime auto-provisioner checks the same
1561
+ * number, and a migration file is the worse place to find out — the failure
1562
+ * lands later, against a database, with none of the schema context that names
1563
+ * which table and field to split.
1564
+ */
846
1565
  declare const renderCreateTable: (table: TableSnapshot) => string;
847
1566
  declare const renderDropTable: (tableName: string) => string;
848
1567
  declare const renderAddColumn: (tableName: string, columnName: string, column: ColumnSnapshot) => string;
849
1568
  declare const renderCreateIndex: (tableName: string, index: IndexSnapshot) => string;
850
1569
  declare const renderDropIndex: (tableName: string, indexName: string) => string;
851
1570
  /**
852
- * Compute a {@link SchemaDiff} from two snapshots. Pure function — no I/O.
853
- */
1571
+ * Compute a {@link SchemaDiff} from two snapshots. Pure function — no I/O.
1572
+ */
854
1573
  declare const diffSnapshots: (previous: SchemaSnapshot | undefined, next: SchemaSnapshot) => SchemaDiff;
855
1574
  /**
856
- * Render a complete migration file body from a diff. Includes a header,
857
- * each SQL statement, and (if any) a trailing comment block describing the
858
- * manual SQL the user needs to fill in for unsupported deltas.
859
- */
1575
+ * Render a complete migration file body from a diff. Includes a header,
1576
+ * each SQL statement, and (if any) a trailing comment block describing the
1577
+ * manual SQL the user needs to fill in for unsupported deltas.
1578
+ */
860
1579
  declare const renderMigrationFile: (name: string, diff: SchemaDiff, generatedAt: string) => string;
861
1580
  declare const schemaIrToSnapshot: (ir: SchemaIR) => SchemaSnapshot;
862
- 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 };
1581
+ export { type AddCommandOptions, type AddCommandResult, COMMANDS, type ColumnSnapshot, type CommandName, DEFAULT_IMPORT_BATCH_SIZE, type DeployCommandOptions, type DeployCommandResult, type DeployedIdentity, type DevCommandOptions, type DevCommandPlan, type DiffEntry, EXIT_CODE, type ExitCode, 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, exitCodeForCode, exitCodeForError, exitCodeForStatus, insertSchemaExtension, pail, parseManifest, planDevCommand, renderAddColumn, renderCreateIndex, renderCreateTable, renderDropIndex, renderDropTable, renderMigrationFile, runAddCommand, runBuildIndexCommand, runCli, runCodegenCommand, runDeployCommand, runDevCommand, runExportCommand, runImportCommand, runInitCommand, runMigrateGenerateCommand, runRegistryViewCommand, runResetCommand, runRpcCommand, schemaIrToSnapshot, validatorKindToSqlType };