@lunora/cli 1.0.0-alpha.21 → 1.0.0-alpha.23

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.
@@ -1,16 +1,315 @@
1
+ import { writeFileSync, existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { DEV_VARS_FILE, DEV_VARS_KEY_PATTERN, generateSecretValue, DEV_VARS_EXAMPLE_FILE, parseDevVariableEntries, isPlaceholderValue, packageNamesFromBindings, inferLunoraBindings, requiredSecrets, isMintableSecretKey } from '@lunora/config';
1
4
  import { d as defineHandler } from '../packem_shared/command-BC30oSBW.mjs';
2
- import { a as resolveProductionWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
3
- import { runExportCommand } from '../packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs';
5
+ import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
6
+ import { l as listRemoteSecrets } from '../packem_shared/wrangler-secrets-P2_ZUR-k.mjs';
4
7
 
5
- const execute = defineHandler(
6
- ({ argument, cwd, logger, options }) => runExportCommand({
8
+ const NEWLINE_PRESENT = /[\r\n]/u;
9
+ const UNREPRESENTABLE_PRESENT = /["\\]/u;
10
+ const parseDevVariables = (content) => {
11
+ const map = /* @__PURE__ */ new Map();
12
+ for (const entry of parseDevVariableEntries(content)) {
13
+ map.set(entry.key, entry);
14
+ }
15
+ return map;
16
+ };
17
+ const serializeDevVariables = (map) => {
18
+ const lines = [];
19
+ for (const entry of map.values()) {
20
+ lines.push(`${entry.key}="${entry.value}"`);
21
+ }
22
+ return `${lines.join("\n")}
23
+ `;
24
+ };
25
+ const redact = (value) => {
26
+ if (value.length <= 4) {
27
+ return "****";
28
+ }
29
+ return `${value.slice(0, 4)}${"*".repeat(Math.min(8, value.length - 4))}`;
30
+ };
31
+ const loadDevVariables = (devVariablesPath) => {
32
+ if (!existsSync(devVariablesPath)) {
33
+ return /* @__PURE__ */ new Map();
34
+ }
35
+ return parseDevVariables(readFileSync(devVariablesPath, "utf8"));
36
+ };
37
+ const runEnvList = (context) => {
38
+ const map = loadDevVariables(context.devVariablesPath);
39
+ if (map.size === 0) {
40
+ context.logger.info(`${DEV_VARS_FILE}: (empty)`);
41
+ return { code: 0, descriptors: [] };
42
+ }
43
+ for (const entry of map.values()) {
44
+ context.logger.info(`${entry.key}=${redact(entry.value)}`);
45
+ }
46
+ return { code: 0, descriptors: [] };
47
+ };
48
+ const runEnvGet = (context) => {
49
+ const { devVariablesPath, logger, options } = context;
50
+ if (!options.key) {
51
+ logger.error("env get requires a key. Usage: lunora env get <KEY>");
52
+ return { code: 1, descriptors: [] };
53
+ }
54
+ const entry = loadDevVariables(devVariablesPath).get(options.key);
55
+ if (!entry) {
56
+ logger.error(`env: ${options.key} is not set in ${DEV_VARS_FILE}`);
57
+ return { code: 1, descriptors: [] };
58
+ }
59
+ process.stdout.write(`${entry.value}
60
+ `);
61
+ return { code: 0, descriptors: [] };
62
+ };
63
+ const runEnvSet = (context) => {
64
+ const { devVariablesPath, logger, options } = context;
65
+ if (!options.key) {
66
+ logger.error("env set requires a key. Usage: lunora env set <KEY> <VALUE>");
67
+ return { code: 1, descriptors: [] };
68
+ }
69
+ if (!DEV_VARS_KEY_PATTERN.test(options.key)) {
70
+ logger.error(`env: invalid key "${options.key}" — must match [A-Za-z_][A-Za-z0-9_]*`);
71
+ return { code: 1, descriptors: [] };
72
+ }
73
+ if (options.value === void 0) {
74
+ logger.error("env set requires a value. Usage: lunora env set <KEY> <VALUE>");
75
+ return { code: 1, descriptors: [] };
76
+ }
77
+ if (NEWLINE_PRESENT.test(options.value)) {
78
+ logger.error(`env: value for "${options.key}" contains a newline, which .dev.vars cannot represent`);
79
+ return { code: 1, descriptors: [] };
80
+ }
81
+ if (UNREPRESENTABLE_PRESENT.test(options.value)) {
82
+ logger.error(`env: value for "${options.key}" contains a double-quote or backslash, which .dev.vars cannot round-trip`);
83
+ return { code: 1, descriptors: [] };
84
+ }
85
+ const map = loadDevVariables(devVariablesPath);
86
+ map.set(options.key, { key: options.key, value: options.value });
87
+ writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
88
+ logger.success(`env: set ${options.key} (${redact(options.value)}) in ${DEV_VARS_FILE}`);
89
+ return { code: 0, descriptors: [] };
90
+ };
91
+ const runEnvUnset = (context) => {
92
+ const { devVariablesPath, logger, options } = context;
93
+ if (!options.key) {
94
+ logger.error("env unset requires a key. Usage: lunora env unset <KEY>");
95
+ return { code: 1, descriptors: [] };
96
+ }
97
+ const map = loadDevVariables(devVariablesPath);
98
+ if (!map.delete(options.key)) {
99
+ logger.warn(`env: ${options.key} was not set in ${DEV_VARS_FILE}`);
100
+ return { code: 0, descriptors: [] };
101
+ }
102
+ writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
103
+ logger.success(`env: unset ${options.key} in ${DEV_VARS_FILE}`);
104
+ return { code: 0, descriptors: [] };
105
+ };
106
+ const runEnvPush = async (context) => {
107
+ const { devVariablesPath, logger, options } = context;
108
+ if (!options.yes) {
109
+ logger.error("env push uploads secrets to Cloudflare. Re-run with --yes to confirm.");
110
+ return { code: 1, descriptors: [] };
111
+ }
112
+ const map = loadDevVariables(devVariablesPath);
113
+ if (map.size === 0) {
114
+ logger.warn(`${DEV_VARS_FILE}: nothing to push (empty)`);
115
+ return { code: 0, descriptors: [] };
116
+ }
117
+ const spawner = options.spawner ?? defaultSpawner;
118
+ const descriptors = [];
119
+ for (const entry of map.values()) {
120
+ const args = ["exec", "wrangler", "secret", "put", entry.key];
121
+ if (options.prod) {
122
+ args.push("--env", "production");
123
+ }
124
+ if (options.temporary) {
125
+ args.push("--temporary");
126
+ }
127
+ const descriptor = {
128
+ args,
129
+ command: "pnpm",
130
+ cwd: options.cwd ?? process.cwd(),
131
+ // `wrangler secret put <name>` reads the value from stdin. We
132
+ // pipe it through the spawner's `input` channel so the secret
133
+ // never lands on the command line, in env, or in shell history.
134
+ input: entry.value
135
+ };
136
+ descriptors.push(descriptor);
137
+ logger.info(`pushing ${entry.key} -> wrangler secret${options.prod ? " (production)" : ""}`);
138
+ const result = await spawner(descriptor);
139
+ if (result.code !== 0) {
140
+ logger.error(`env push: failed at ${entry.key} (exit ${String(result.code)})`);
141
+ return { code: result.code, descriptors };
142
+ }
143
+ }
144
+ logger.success(`env: pushed ${String(map.size)} secret(s)`);
145
+ return { code: 0, descriptors };
146
+ };
147
+ const fetchRemoteSecretNames = (context) => {
148
+ const lister = context.options.secretLister ?? listRemoteSecrets;
149
+ return lister({
150
+ cwd: context.cwd,
151
+ env: context.options.prod ? "production" : void 0,
152
+ temporary: context.options.temporary
153
+ });
154
+ };
155
+ const runEnvDiff = async (context) => {
156
+ const { devVariablesPath, logger } = context;
157
+ const remote = await fetchRemoteSecretNames(context);
158
+ if (!remote.ok) {
159
+ logger.error(`env diff: ${remote.error ?? "failed to list remote secrets"}`);
160
+ return { code: 1, descriptors: [] };
161
+ }
162
+ const localKeys = new Set(loadDevVariables(devVariablesPath).keys());
163
+ const remoteKeys = new Set(remote.names);
164
+ const localOnly = [...localKeys].filter((key) => !remoteKeys.has(key)).toSorted((a, b) => a.localeCompare(b));
165
+ const remoteOnly = remote.names.filter((name) => !localKeys.has(name));
166
+ const both = [...localKeys].filter((key) => remoteKeys.has(key)).toSorted((a, b) => a.localeCompare(b));
167
+ for (const key of localOnly) {
168
+ logger.info(`local only (run \`lunora env push\`): ${key}`);
169
+ }
170
+ for (const key of remoteOnly) {
171
+ logger.info(`remote only (in Cloudflare, not ${DEV_VARS_FILE}): ${key}`);
172
+ }
173
+ logger.info(`in both: ${String(both.length)} secret(s)`);
174
+ if (localOnly.length === 0 && remoteOnly.length === 0) {
175
+ logger.success("env diff: local and remote secret names match");
176
+ }
177
+ return { code: 0, descriptors: [] };
178
+ };
179
+ const runEnvDoctor = (context) => {
180
+ const { cwd, devVariablesPath, logger } = context;
181
+ const examplePath = join(cwd, DEV_VARS_EXAMPLE_FILE);
182
+ if (!existsSync(examplePath)) {
183
+ logger.info(`env doctor: no ${DEV_VARS_EXAMPLE_FILE} to check against — nothing to validate.`);
184
+ return { code: 0, descriptors: [] };
185
+ }
186
+ const exampleKeys = parseDevVariableEntries(readFileSync(examplePath, "utf8")).map((entry) => entry.key);
187
+ const current = loadDevVariables(devVariablesPath);
188
+ if (!existsSync(devVariablesPath)) {
189
+ logger.error(`env doctor: ${DEV_VARS_FILE} is missing. Run \`lunora dev\` to scaffold it, or \`lunora env set <KEY> <VALUE>\`.`);
190
+ logger.info(`expected (from ${DEV_VARS_EXAMPLE_FILE}): ${exampleKeys.join(", ")}`);
191
+ return { code: 1, descriptors: [] };
192
+ }
193
+ const missing = exampleKeys.filter((key) => !current.has(key));
194
+ const placeholders = [...current.values()].filter((entry) => isPlaceholderValue(entry.value)).map((entry) => entry.key);
195
+ const exampleKeySet = new Set(exampleKeys);
196
+ const extra = [...current.keys()].filter((key) => !exampleKeySet.has(key));
197
+ for (const key of missing) {
198
+ logger.error(`missing: ${key} is in ${DEV_VARS_EXAMPLE_FILE} but not ${DEV_VARS_FILE}`);
199
+ }
200
+ for (const key of placeholders) {
201
+ logger.error(`unset: ${key} still has a placeholder value`);
202
+ }
203
+ for (const key of extra) {
204
+ logger.info(`extra: ${key} is set locally but not listed in ${DEV_VARS_EXAMPLE_FILE}`);
205
+ }
206
+ if (missing.length === 0 && placeholders.length === 0) {
207
+ logger.success(`env doctor: ${DEV_VARS_FILE} looks good (${String(current.size)} var(s)).`);
208
+ return { code: 0, descriptors: [] };
209
+ }
210
+ return { code: 1, descriptors: [] };
211
+ };
212
+ const resolveMintableKeys = async (context) => {
213
+ let packages = [];
214
+ try {
215
+ packages = packageNamesFromBindings(await inferLunoraBindings({ projectRoot: context.cwd }));
216
+ } catch {
217
+ }
218
+ const fromPackages = requiredSecrets(packages).map((entry) => entry.key).filter((key) => isMintableSecretKey(key));
219
+ const fromLocal = [...loadDevVariables(context.devVariablesPath).keys()].filter((key) => isMintableSecretKey(key));
220
+ return [.../* @__PURE__ */ new Set([...fromPackages, ...fromLocal])];
221
+ };
222
+ const runEnvGenerate = async (context) => {
223
+ const { devVariablesPath, logger, options } = context;
224
+ let keys;
225
+ if (options.key === void 0) {
226
+ keys = await resolveMintableKeys(context);
227
+ if (keys.length === 0) {
228
+ logger.info("env generate: no locally-generatable secrets for this project. Name one explicitly: lunora env generate <KEY>");
229
+ return { code: 0, descriptors: [] };
230
+ }
231
+ } else {
232
+ if (!DEV_VARS_KEY_PATTERN.test(options.key)) {
233
+ logger.error(`env: invalid key "${options.key}" — must match [A-Za-z_][A-Za-z0-9_]*`);
234
+ return { code: 1, descriptors: [] };
235
+ }
236
+ keys = [options.key];
237
+ }
238
+ const generated = keys.map((key) => {
239
+ return { key, value: generateSecretValue() };
240
+ });
241
+ if (options.set === true) {
242
+ const map = loadDevVariables(devVariablesPath);
243
+ for (const entry of generated) {
244
+ map.set(entry.key, entry);
245
+ }
246
+ writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
247
+ logger.success(`env: generated ${String(generated.length)} secret(s) into ${DEV_VARS_FILE}: ${generated.map((entry) => entry.key).join(", ")}`);
248
+ return { code: 0, descriptors: [] };
249
+ }
250
+ for (const entry of generated) {
251
+ process.stdout.write(`${entry.key}=${entry.value}
252
+ `);
253
+ }
254
+ return { code: 0, descriptors: [] };
255
+ };
256
+ const runEnvCommand = async (options) => {
257
+ const cwd = options.cwd ?? process.cwd();
258
+ const context = {
259
+ cwd,
260
+ devVariablesPath: join(cwd, DEV_VARS_FILE),
261
+ logger: options.logger,
262
+ options
263
+ };
264
+ switch (options.subcommand) {
265
+ case "diff": {
266
+ return runEnvDiff(context);
267
+ }
268
+ case "doctor": {
269
+ return runEnvDoctor(context);
270
+ }
271
+ case "generate": {
272
+ return runEnvGenerate(context);
273
+ }
274
+ case "get": {
275
+ return runEnvGet(context);
276
+ }
277
+ case "list": {
278
+ return runEnvList(context);
279
+ }
280
+ case "push": {
281
+ return runEnvPush(context);
282
+ }
283
+ case "set": {
284
+ return runEnvSet(context);
285
+ }
286
+ case "unset": {
287
+ return runEnvUnset(context);
288
+ }
289
+ default: {
290
+ options.logger.error(`env: unknown subcommand "${options.subcommand}"`);
291
+ return { code: 1, descriptors: [] };
292
+ }
293
+ }
294
+ };
295
+ const isEnvSubcommand = (value) => value === "list" || value === "get" || value === "set" || value === "unset" || value === "push" || value === "diff" || value === "doctor" || value === "generate";
296
+ const execute = defineHandler(({ argument, cwd, logger, options }) => {
297
+ const sub = argument[0];
298
+ if (!isEnvSubcommand(sub)) {
299
+ logger.error(`env: unknown subcommand "${sub ?? ""}" — expected list | get | set | unset | push | diff | doctor | generate`);
300
+ return { code: 1 };
301
+ }
302
+ return runEnvCommand({
303
+ cwd,
304
+ key: argument[1],
7
305
  logger,
8
- out: argument[0] ?? options.out,
9
306
  prod: options.prod === true,
10
- tables: options.tables,
11
- token: options.token,
12
- url: resolveProductionWorkerUrl({ cwd, prod: options.prod === true, url: options.url })
13
- })
14
- );
307
+ set: options.set === true,
308
+ subcommand: sub,
309
+ temporary: options.temporary === true,
310
+ value: argument[2],
311
+ yes: options.yes === true
312
+ });
313
+ });
15
314
 
16
- export { execute };
315
+ export { execute, runEnvCommand };
@@ -1,5 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { detectAgentRules, resolveRemoteEnabled, readProjectRemotePreference, inferLunoraBindings, packageNamesFromBindings, ensureDevVarsExample, ensureDevVariables, isInteractive, DEV_VARS_FILE, DEV_VARS_EXAMPLE_FILE, claimAgentRulesHint, AGENT_RULES_HINT, materializeRemoteWranglerConfig, formatLunoraEvent } from '@lunora/config';
2
+ import { detectAgentRules, resolveRemoteEnabled, readProjectRemotePreference, inferLunoraBindings, packageNamesFromBindings, ensureDevVarsExample, ensureDevVariables, isInteractive, DEV_VARS_FILE, DEV_VARS_EXAMPLE_FILE, fillDevSecrets, claimAgentRulesHint, AGENT_RULES_HINT, materializeRemoteWranglerConfig, formatLunoraEvent } from '@lunora/config';
3
3
  import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
4
4
  import { existsSync, watch } from 'node:fs';
5
5
  import { join } from 'node:path';
@@ -409,6 +409,15 @@ const offerDevVariablesScaffold = async (options, cwd) => {
409
409
  `hint: ${DEV_VARS_FILE} was not scaffolded (non-interactive run). Copy ${DEV_VARS_EXAMPLE_FILE} → ${DEV_VARS_FILE} and fill in secrets, or run \`lunora dev\` in an interactive terminal to scaffold automatically.`
410
410
  );
411
411
  }
412
+ try {
413
+ (options.fillSecrets ?? fillDevSecrets)({
414
+ cwd,
415
+ info: (message) => {
416
+ options.logger.info(message);
417
+ }
418
+ });
419
+ } catch {
420
+ }
412
421
  };
413
422
  const runDevCommand = async (options) => {
414
423
  const plan = planDevCommand(options);
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { runCodegen, discoverMigrations } from '@lunora/codegen';
3
- import { readLinkedProject, writeLinkedProject, validateWranglerProject, inferLunoraBindings, reconcileWranglerBindings, DEV_VARS_FILE, parseDevVariableEntries, findWranglerFile, readWranglerJsonc, discoverContainerInfo } from '@lunora/config';
3
+ import { readLinkedProject, writeLinkedProject, validateWranglerProject, inferLunoraBindings, reconcileWranglerBindings, DEV_VARS_FILE, parseDevVariableEntries, isMintableSecretKey, findWranglerFile, readWranglerJsonc, discoverContainerInfo, packageNamesFromBindings, requiredSecrets, generateSecretValue } from '@lunora/config';
4
4
  import { join } from '@visulima/path';
5
5
  import { Spinner } from '@visulima/spinner';
6
6
  import { Project } from 'ts-morph';
@@ -13,6 +13,8 @@ import { containerBuildTag } from '@lunora/container';
13
13
  import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
14
14
  import { r as resolveWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
15
15
  import { r as runSchemaDriftGate } from '../packem_shared/schema-drift-gate-BtBt0as0.mjs';
16
+ import { c as createTuiConfirm } from '../packem_shared/tui-prompts-M6OWsuyw.mjs';
17
+ import { l as listRemoteSecrets } from '../packem_shared/wrangler-secrets-P2_ZUR-k.mjs';
16
18
  import { runMigrateDataCommand } from './runMigrateGenerateCommand.mjs';
17
19
 
18
20
  const WORKERS_DEV_URL = /https?:\/\/[^\s"'<>]+\.workers\.dev[^\s"'<>]*/u;
@@ -210,6 +212,88 @@ const warnDevVariablesNotPushed = (cwd, logger) => {
210
212
  `Note: \`lunora deploy\` does not push secrets. ${DEV_VARS_FILE} has ${String(keyCount)} key(s); if you changed them, run \`lunora env push --yes\` to update the deployed secrets.`
211
213
  );
212
214
  };
215
+ const SECRET_LIKE_KEY = /(?:KEY|PASSWORD|SECRET|TOKEN)$/u;
216
+ const resolveRequiredSecretKeys = async (cwd) => {
217
+ let packages = [];
218
+ try {
219
+ packages = packageNamesFromBindings(await inferLunoraBindings({ projectRoot: cwd }));
220
+ } catch {
221
+ }
222
+ const fromPackages = requiredSecrets(packages).map((entry) => entry.key);
223
+ let fromLocal = [];
224
+ try {
225
+ const devVariablesPath = join(cwd, DEV_VARS_FILE);
226
+ if (existsSync(devVariablesPath)) {
227
+ fromLocal = parseDevVariableEntries(readFileSync(devVariablesPath, "utf8")).map((entry) => entry.key).filter((key) => SECRET_LIKE_KEY.test(key));
228
+ }
229
+ } catch {
230
+ }
231
+ return [.../* @__PURE__ */ new Set([...fromPackages, ...fromLocal])];
232
+ };
233
+ const pushMintableSecrets = async (cwd, options, keys) => {
234
+ const { logger } = options;
235
+ const spawner = options.spawner ?? defaultSpawner;
236
+ const environmentFlag = options.env === void 0 ? "" : ` --env ${options.env}`;
237
+ for (const key of keys) {
238
+ const args = ["exec", "wrangler", "secret", "put", key];
239
+ if (options.env !== void 0) {
240
+ args.push("--env", options.env);
241
+ }
242
+ if (options.temporary === true) {
243
+ args.push("--temporary");
244
+ }
245
+ const pushResult = await spawner({ args, command: "pnpm", cwd, input: generateSecretValue() });
246
+ if (pushResult.code !== 0) {
247
+ logger.error(
248
+ `failed to push secret ${key} (exit ${String(pushResult.code)}); set it manually with \`wrangler secret put ${key}${environmentFlag}\`.`
249
+ );
250
+ return false;
251
+ }
252
+ logger.success(`generated + pushed ${key}`);
253
+ }
254
+ return true;
255
+ };
256
+ const offerMissingSecrets = async (cwd, options, interactive) => {
257
+ if (options.dryRun === true || options.preview === true) {
258
+ return void 0;
259
+ }
260
+ const { logger } = options;
261
+ const environmentFlag = options.env === void 0 ? "" : ` --env ${options.env}`;
262
+ let remote;
263
+ try {
264
+ remote = await (options.secretLister ?? listRemoteSecrets)({ cwd, env: options.env, temporary: options.temporary });
265
+ } catch {
266
+ return void 0;
267
+ }
268
+ if (!remote.ok) {
269
+ return void 0;
270
+ }
271
+ const remoteNames = new Set(remote.names);
272
+ const required = await resolveRequiredSecretKeys(cwd);
273
+ const missing = required.filter((key) => !remoteNames.has(key));
274
+ if (missing.length === 0) {
275
+ return void 0;
276
+ }
277
+ if (!interactive) {
278
+ return `missing required secret(s) on the deploy target: ${missing.join(", ")}. Set them with \`wrangler secret put <KEY>${environmentFlag}\` (or \`lunora env generate --set\` then \`lunora env push --yes${options.env === void 0 ? "" : " --prod"}\`), then re-deploy.`;
279
+ }
280
+ for (const key of missing.filter((name) => !isMintableSecretKey(name))) {
281
+ logger.warn(`required secret ${key} is not set on the target — set it with: wrangler secret put ${key}${environmentFlag}`);
282
+ }
283
+ const mintable = missing.filter((key) => isMintableSecretKey(key));
284
+ if (mintable.length === 0) {
285
+ return void 0;
286
+ }
287
+ const confirm = options.secretConfirm ?? createTuiConfirm();
288
+ if (await confirm(`${String(mintable.length)} required secret(s) not set on the target (${mintable.join(", ")}). Generate strong values and push them now?`)) {
289
+ await pushMintableSecrets(cwd, options, mintable);
290
+ return void 0;
291
+ }
292
+ logger.warn(
293
+ `${String(mintable.length)} required secret(s) not set on the target: ${mintable.join(", ")}. Generate + push with \`lunora env generate --set\` then \`lunora env push --yes${options.env === void 0 ? "" : " --prod"}\`.`
294
+ );
295
+ return void 0;
296
+ };
213
297
  const runPostDeployMigrations = async (options, cwd) => {
214
298
  const project = new Project({ skipAddingFilesFromTsConfig: true });
215
299
  const lunoraDirectory = join(cwd, "lunora");
@@ -375,6 +459,16 @@ const buildWranglerDeployArgs = (cwd, options) => {
375
459
  }
376
460
  return args;
377
461
  };
462
+ const reportWranglerProblems = (validation, logger) => {
463
+ if (validation.problems.length === 0) {
464
+ return false;
465
+ }
466
+ logger.error("wrangler.jsonc validation failed:");
467
+ for (const problem of validation.problems) {
468
+ logger.error(` - ${problem}`);
469
+ }
470
+ return true;
471
+ };
378
472
  const executeDeploy = async (options) => {
379
473
  const cwd = options.cwd ?? process.cwd();
380
474
  const interactive = isInteractive(options);
@@ -420,19 +514,15 @@ const executeDeploy = async (options) => {
420
514
  return { code: 1, descriptor: void 0, error: preflightError, validation: { problems: [], wranglerPath: void 0 } };
421
515
  }
422
516
  const validation = validateWranglerProject({ projectRoot: cwd });
423
- if (validation.problems.length > 0) {
424
- options.logger.error("wrangler.jsonc validation failed:");
425
- for (const problem of validation.problems) {
426
- options.logger.error(` - ${problem}`);
427
- }
428
- return {
429
- code: 1,
430
- descriptor: void 0,
431
- error: "wrangler validation failed",
432
- validation
433
- };
517
+ if (reportWranglerProblems(validation, options.logger)) {
518
+ return { code: 1, descriptor: void 0, error: "wrangler validation failed", validation };
434
519
  }
435
520
  warnDevVariablesNotPushed(cwd, options.logger);
521
+ const secretAbort = await offerMissingSecrets(cwd, options, interactive);
522
+ if (secretAbort !== void 0) {
523
+ options.logger.error(secretAbort);
524
+ return { code: 1, descriptor: void 0, error: secretAbort, validation };
525
+ }
436
526
  const shouldAutoLink = !isJsonFormat(options.format) && options.dryRun !== true && options.preview !== true && readLinkedProject(cwd) === void 0;
437
527
  const descriptor = {
438
528
  args: buildWranglerDeployArgs(cwd, options),
@@ -260,21 +260,24 @@ const doctorCommand = {
260
260
  };
261
261
 
262
262
  const envCommand = {
263
- argument: { description: "list | get <KEY> | set <KEY> <VALUE> | unset <KEY> | push | diff | doctor", name: "subcommand", type: String },
264
- description: "Manage .dev.vars and sync secrets via wrangler (list | get | set | unset | push | diff | doctor)",
263
+ argument: { description: "list | get <KEY> | set <KEY> <VALUE> | unset <KEY> | generate [KEY] | push | diff | doctor", name: "subcommand", type: String },
264
+ description: "Manage .dev.vars and sync secrets via wrangler (list | get | set | unset | generate | push | diff | doctor)",
265
265
  examples: [
266
266
  ["lunora env list", "List .dev.vars keys"],
267
267
  ["lunora env set API_KEY secret", "Set a local variable"],
268
+ ["lunora env generate", "Generate strong values for the project's secrets (print KEY=value)"],
269
+ ["lunora env generate AUTH_SECRET --set", "Generate one secret and write it to .dev.vars"],
268
270
  ["lunora env push --yes", "Upload secrets to Cloudflare"],
269
271
  ["lunora env diff", "Compare local .dev.vars keys against Cloudflare"]
270
272
  ],
271
273
  group: "Data",
272
- loader: () => import('../packem_chunks/handler21.mjs').then((m) => {
274
+ loader: () => import('../packem_chunks/handler9.mjs').then((m) => {
273
275
  return { default: m.execute };
274
276
  }),
275
277
  name: "env",
276
278
  options: [
277
279
  { description: "Target production for `push` (passes --env production to wrangler)", name: "prod", type: Boolean },
280
+ { description: "For `generate` — write the generated secrets into .dev.vars instead of printing them", name: "set", type: Boolean },
278
281
  {
279
282
  description: "Push secrets to a temporary-account deployment when unauthenticated (wrangler secret put --temporary). Errors if you're already authenticated.",
280
283
  name: "temporary",
@@ -292,7 +295,7 @@ const exportCommand = {
292
295
  ["lunora export --tables messages,users", "Export only specific tables"]
293
296
  ],
294
297
  group: "Data",
295
- loader: () => import('../packem_chunks/handler9.mjs').then((m) => {
298
+ loader: () => import('../packem_chunks/handler10.mjs').then((m) => {
296
299
  return { default: m.execute };
297
300
  }),
298
301
  name: "export",
@@ -314,7 +317,7 @@ const importCommand = {
314
317
  description: "Bulk-insert rows from an NDJSON file via the worker's admin endpoint",
315
318
  examples: [["lunora import backup.ndjson", "Bulk-insert rows from an NDJSON file"]],
316
319
  group: "Data",
317
- loader: () => import('../packem_chunks/handler10.mjs').then((m) => {
320
+ loader: () => import('../packem_chunks/handler11.mjs').then((m) => {
318
321
  return { default: m.execute };
319
322
  }),
320
323
  name: "import",
@@ -338,7 +341,7 @@ const infoCommand = {
338
341
  ["lunora info --json", "Emit a JSON snapshot"]
339
342
  ],
340
343
  group: "Project",
341
- loader: () => import('../packem_chunks/handler11.mjs').then((m) => {
344
+ loader: () => import('../packem_chunks/handler12.mjs').then((m) => {
342
345
  return { default: m.execute };
343
346
  }),
344
347
  name: "info",
@@ -442,7 +445,7 @@ const insightsCommand = {
442
445
  ["lunora insights --prod --url https://app.example.com --token $LUNORA_ADMIN_TOKEN", "Report against production"]
443
446
  ],
444
447
  group: "Develop",
445
- loader: () => import('../packem_chunks/handler12.mjs').then((m) => {
448
+ loader: () => import('../packem_chunks/handler13.mjs').then((m) => {
446
449
  return { default: m.execute };
447
450
  }),
448
451
  name: "insights",
@@ -464,7 +467,7 @@ const linkCommand = {
464
467
  ["lunora link --remove", "Remove the link"]
465
468
  ],
466
469
  group: "Deploy",
467
- loader: () => import('../packem_chunks/handler13.mjs').then((m) => {
470
+ loader: () => import('../packem_chunks/handler14.mjs').then((m) => {
468
471
  return { default: m.execute };
469
472
  }),
470
473
  name: "link",
@@ -480,7 +483,7 @@ const logsCommand = {
480
483
  argument: { description: "Worker name (defaults to the name in wrangler config)", name: "worker", type: String },
481
484
  description: "Stream live logs from a deployed Lunora Worker",
482
485
  group: "Deploy",
483
- loader: () => import('../packem_chunks/handler14.mjs').then((m) => {
486
+ loader: () => import('../packem_chunks/handler15.mjs').then((m) => {
484
487
  return { default: m.execute };
485
488
  }),
486
489
  name: "logs",
@@ -540,7 +543,7 @@ const prepareCommand = {
540
543
  description: "Run codegen + binding reconcile + wrangler validation (no Vite) — for CI",
541
544
  examples: [["lunora prepare", "Codegen + binding reconcile + validate (CI, before deploy)"]],
542
545
  group: "Deploy",
543
- loader: () => import('../packem_chunks/handler15.mjs').then((m) => {
546
+ loader: () => import('../packem_chunks/handler16.mjs').then((m) => {
544
547
  return { default: m.execute };
545
548
  }),
546
549
  name: "prepare",
@@ -564,7 +567,7 @@ const registryCommand = {
564
567
  ["lunora registry build --check", "Verify the committed catalog is current"]
565
568
  ],
566
569
  group: "Project",
567
- loader: () => import('../packem_chunks/handler16.mjs').then((m) => {
570
+ loader: () => import('../packem_chunks/handler17.mjs').then((m) => {
568
571
  return { default: m.execute };
569
572
  }),
570
573
  name: "registry",
@@ -614,7 +617,7 @@ const rulesCommand = {
614
617
  ["lunora rules check --strict", "Exit non-zero when rules are missing (CI gate)"]
615
618
  ],
616
619
  group: "Project",
617
- loader: () => import('../packem_chunks/handler17.mjs').then((m) => {
620
+ loader: () => import('../packem_chunks/handler18.mjs').then((m) => {
618
621
  return { default: m.execute };
619
622
  }),
620
623
  name: "rules",
@@ -652,7 +655,7 @@ const seedCommand = {
652
655
  ["lunora seed --seed 7 --dry-run", "Print the NDJSON for seed 7 without inserting"]
653
656
  ],
654
657
  group: "Data",
655
- loader: () => import('../packem_chunks/handler18.mjs').then((m) => {
658
+ loader: () => import('../packem_chunks/handler19.mjs').then((m) => {
656
659
  return { default: m.execute };
657
660
  }),
658
661
  name: "seed",
@@ -681,7 +684,7 @@ const verifyCommand = {
681
684
  ["lunora verify --no-typecheck", "Skip the TypeScript type-check"]
682
685
  ],
683
686
  group: "Deploy",
684
- loader: () => import('../packem_chunks/handler19.mjs').then((m) => {
687
+ loader: () => import('../packem_chunks/handler20.mjs').then((m) => {
685
688
  return { default: m.execute };
686
689
  }),
687
690
  name: "verify",
@@ -700,7 +703,7 @@ const viewCommand = {
700
703
  ["lunora view --remote", "Open the deployed studio"]
701
704
  ],
702
705
  group: "Project",
703
- loader: () => import('../packem_chunks/handler20.mjs').then((m) => {
706
+ loader: () => import('../packem_chunks/handler21.mjs').then((m) => {
704
707
  return { default: m.execute };
705
708
  }),
706
709
  name: "view",
@@ -0,0 +1,47 @@
1
+ import { execFile } from 'node:child_process';
2
+
3
+ const execCode = (error) => {
4
+ if (!error) {
5
+ return 0;
6
+ }
7
+ return typeof error.code === "number" ? error.code : 1;
8
+ };
9
+ const defaultRunner = (command, args, cwd) => new Promise((resolve) => {
10
+ execFile(command, [...args], { cwd }, (error, stdout, stderr) => {
11
+ resolve({ code: execCode(error), stderr, stdout });
12
+ });
13
+ });
14
+ const parseSecretNames = (stdout) => {
15
+ let parsed;
16
+ try {
17
+ parsed = JSON.parse(stdout);
18
+ } catch {
19
+ return void 0;
20
+ }
21
+ if (!Array.isArray(parsed)) {
22
+ return void 0;
23
+ }
24
+ const names = parsed.map((entry) => entry !== null && typeof entry === "object" ? entry.name : void 0).filter((name) => typeof name === "string" && name.length > 0);
25
+ return [...names].toSorted((a, b) => a.localeCompare(b));
26
+ };
27
+ const listRemoteSecrets = async (inputs) => {
28
+ const args = ["exec", "wrangler", "secret", "list", "--format", "json"];
29
+ if (inputs.env !== void 0) {
30
+ args.push("--env", inputs.env);
31
+ }
32
+ if (inputs.temporary) {
33
+ args.push("--temporary");
34
+ }
35
+ const runner = inputs.runner ?? defaultRunner;
36
+ const result = await runner("pnpm", args, inputs.cwd);
37
+ if (result.code !== 0) {
38
+ return { error: result.stderr.trim() || `wrangler secret list exited ${String(result.code)}`, names: [], ok: false };
39
+ }
40
+ const names = parseSecretNames(result.stdout);
41
+ if (names === void 0) {
42
+ return { error: "could not parse `wrangler secret list --format json` output", names: [], ok: false };
43
+ }
44
+ return { names, ok: true };
45
+ };
46
+
47
+ export { listRemoteSecrets as l };