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

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 (53) hide show
  1. package/__assets__/package-og.svg +1 -1
  2. package/dist/bin.mjs +1 -1
  3. package/dist/index.d.mts +243 -114
  4. package/dist/index.d.ts +243 -114
  5. package/dist/index.mjs +7 -7
  6. package/dist/packem_chunks/handler.mjs +89 -7
  7. package/dist/packem_chunks/handler10.mjs +8 -14
  8. package/dist/packem_chunks/handler11.mjs +19 -189
  9. package/dist/packem_chunks/handler12.mjs +176 -115
  10. package/dist/packem_chunks/handler13.mjs +118 -52
  11. package/dist/packem_chunks/handler14.mjs +50 -43
  12. package/dist/packem_chunks/handler15.mjs +46 -67
  13. package/dist/packem_chunks/handler16.mjs +74 -37
  14. package/dist/packem_chunks/handler17.mjs +38 -100
  15. package/dist/packem_chunks/handler18.mjs +87 -154
  16. package/dist/packem_chunks/handler19.mjs +148 -67
  17. package/dist/packem_chunks/handler2.mjs +2 -2
  18. package/dist/packem_chunks/handler20.mjs +75 -75
  19. package/dist/packem_chunks/handler21.mjs +71 -288
  20. package/dist/packem_chunks/handler3.mjs +1 -1
  21. package/dist/packem_chunks/handler4.mjs +1 -1
  22. package/dist/packem_chunks/handler5.mjs +2 -2
  23. package/dist/packem_chunks/handler6.mjs +2 -2
  24. package/dist/packem_chunks/handler7.mjs +1 -1
  25. package/dist/packem_chunks/handler8.mjs +1 -1
  26. package/dist/packem_chunks/handler9.mjs +311 -12
  27. package/dist/packem_chunks/planDevCommand.mjs +48 -50
  28. package/dist/packem_chunks/runCodegenCommand.mjs +2 -2
  29. package/dist/packem_chunks/runDeployCommand.mjs +105 -15
  30. package/dist/packem_chunks/runInitCommand.mjs +1980 -77
  31. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +5 -5
  32. package/dist/packem_chunks/runResetCommand.mjs +4 -4
  33. package/dist/packem_chunks/runRpcCommand.mjs +1 -1
  34. package/dist/packem_shared/{COMMANDS-CHw4zOZ9.mjs → COMMANDS-B0ftFD_3.mjs} +47 -21
  35. package/dist/packem_shared/codegen-error-DJG-ghs_.mjs +31 -0
  36. package/dist/packem_shared/{command-BDXcJCCJ.mjs → command-D3lB_4Az.mjs} +6 -1
  37. package/dist/packem_shared/{commands-DIQ3nf0C.mjs → commands-B-gR09Z_.mjs} +124 -22
  38. package/dist/packem_shared/{createLogger-CHPNjFw2.mjs → createLogger-B40gPzQo.mjs} +9 -4
  39. package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +61 -0
  40. package/dist/packem_shared/{diffSnapshots-RR2ZE8Ya.mjs → diffSnapshots-BeDvvNiF.mjs} +1 -1
  41. package/dist/packem_shared/{insertSchemaExtension-BuzF6-t2.mjs → insertSchemaExtension-DAqbfr9Z.mjs} +15 -10
  42. package/dist/packem_shared/{output-format-7gyGR3h8.mjs → output-format-wUvAN6AL.mjs} +1 -1
  43. package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +9 -0
  44. package/dist/packem_shared/runAddCommand-bnY6-HKb.mjs +4 -0
  45. package/dist/packem_shared/{schemaIrToSnapshot-aBTo7TM5.mjs → schemaIrToSnapshot-DdsljJT-.mjs} +1 -1
  46. package/dist/packem_shared/storage-BIsph-Vk.mjs +84 -0
  47. package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +658 -0
  48. package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +47 -0
  49. package/package.json +13 -11
  50. package/skills/lunora-setup-storage/SKILL.md +7 -3
  51. package/dist/packem_shared/features-ocSSpZtS.mjs +0 -24
  52. package/dist/packem_shared/runAddCommand-3I3JFZUG.mjs +0 -4
  53. /package/dist/packem_shared/{defaultSpawner-DxI3mebw.mjs → createRecordingSpawner-DxI3mebw.mjs} +0 -0
@@ -1,16 +1,315 @@
1
- import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.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';
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';
4
+ import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.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,14 +1,16 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { detectAgentRules, inferLunoraBindings, packageNamesFromBindings, ensureDevVarsExample, ensureDevVariables, createConfirm, isInteractive, DEV_VARS_FILE, DEV_VARS_EXAMPLE_FILE, claimAgentRulesHint, AGENT_RULES_HINT, materializeRemoteWranglerConfig, formatLunoraEvent, resolveRemoteEnabled, readProjectRemotePreference } from '@lunora/config';
2
+ import { detectAgentRules, resolveRemoteEnabled, readProjectRemotePreference, inferLunoraBindings, packageNamesFromBindings, ensureDevVarsExample, ensureDevVariables, isInteractive, DEV_VARS_FILE, DEV_VARS_EXAMPLE_FILE, fillDevSecrets, discoverContainerInfo, streamContainerLogs, claimAgentRulesHint, AGENT_RULES_HINT, materializeRemoteWranglerConfig, formatLunoraEvent } from '@lunora/config';
3
3
  import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
4
- import { existsSync, watch, readFileSync } from 'node:fs';
4
+ import { existsSync, watch } from 'node:fs';
5
5
  import { join } from 'node:path';
6
6
  import { runCodegen } from '@lunora/codegen';
7
- import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
8
- import { dirname, join as join$1 } from '@visulima/path';
7
+ import { r as renderCodegenFailure } from '../packem_shared/codegen-error-DJG-ghs_.mjs';
8
+ import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
9
+ import { d as detectPackageManager, e as execArgsFor } from '../packem_shared/detect-package-manager-DYp7n3mJ.mjs';
9
10
  import { createServer, request } from 'node:http';
10
11
  import { connect } from 'node:net';
11
12
  import { loadStudioAssets, studioAssetsStamp, renderStudioHtml, resolveAdminToken, SCHEMA_EDIT_ENDPOINT, POLICY_SCAFFOLD_ENDPOINT, SEED_ENDPOINT, serveJsonHandler, handleSchemaEditRequest, handlePolicyScaffoldRequest, handleSeedRequest } from '@lunora/config/studio-host';
13
+ import { c as createTuiConfirm } from '../packem_shared/tui-prompts-BjEN8XgP.mjs';
12
14
 
13
15
  const DEFAULT_DEBOUNCE_MS = 100;
14
16
  const PATH_SEGMENT_SEPARATOR = /[/\\]/u;
@@ -17,7 +19,7 @@ const runOnce = (projectRoot, lunoraDirectory, apiSpec, logger, reason) => {
17
19
  runCodegen({ apiSpec, lunoraDirectory, projectRoot });
18
20
  logger.success(`codegen: wrote ${lunoraDirectory}/_generated (${reason})`);
19
21
  } catch (error) {
20
- logger.error(`codegen failed (${reason}): ${error instanceof Error ? error.message : String(error)}`);
22
+ logger.error(renderCodegenFailure(error, reason));
21
23
  }
22
24
  };
23
25
  const startCodegenWatch = (options) => {
@@ -70,50 +72,6 @@ const startCodegenWatch = (options) => {
70
72
  };
71
73
  };
72
74
 
73
- const FALLBACK = "pnpm";
74
- const KNOWN_MANAGERS = ["pnpm", "yarn", "npm", "bun"];
75
- const parseDeclaredManager = (declared) => {
76
- if (typeof declared !== "string") {
77
- return void 0;
78
- }
79
- return KNOWN_MANAGERS.find((manager) => declared.startsWith(`${manager}@`));
80
- };
81
- const readDeclaredManager = (directory) => {
82
- const candidate = join$1(directory, "package.json");
83
- if (!existsSync(candidate)) {
84
- return void 0;
85
- }
86
- try {
87
- const parsed = JSON.parse(readFileSync(candidate, "utf8"));
88
- return parseDeclaredManager(parsed.packageManager);
89
- } catch {
90
- return void 0;
91
- }
92
- };
93
- const detectPackageManager = (startDirectory) => {
94
- let directory = startDirectory;
95
- while (directory && directory !== dirname(directory)) {
96
- const declared = readDeclaredManager(directory);
97
- if (declared !== void 0) {
98
- return declared;
99
- }
100
- directory = dirname(directory);
101
- }
102
- return FALLBACK;
103
- };
104
- const execArgsFor = (manager, command, args) => {
105
- if (manager === "yarn") {
106
- return { args: [command, ...args], command: "yarn" };
107
- }
108
- if (manager === "bun") {
109
- return { args: ["x", command, ...args], command: "bun" };
110
- }
111
- if (manager === "npm") {
112
- return { args: ["--", command, ...args], command: "npx" };
113
- }
114
- return { args: ["exec", command, ...args], command: "pnpm" };
115
- };
116
-
117
75
  const PROXY_PREFIX = "/_lunora";
118
76
  const pathnameOf = (url) => {
119
77
  const queryIndex = url.indexOf("?");
@@ -422,8 +380,35 @@ const printAgentRulesHint = (logger, cwd) => {
422
380
  logger.info(` ⓘ ${AGENT_RULES_HINT}`);
423
381
  logger.info("");
424
382
  };
383
+ const startContainerLogStreaming = (cwd, logger) => {
384
+ if (process.env.LUNORA_CONTAINER_LOGS === "0") {
385
+ return void 0;
386
+ }
387
+ const discovery = discoverContainerInfo(cwd, "lunora");
388
+ const containers = discovery.containers.map((container) => {
389
+ return { className: container.className, exportName: container.exportName };
390
+ });
391
+ if (containers.length === 0) {
392
+ return void 0;
393
+ }
394
+ return streamContainerLogs({
395
+ containers,
396
+ onLine: (line) => {
397
+ const tagged = `[container:${line.name}] ${line.text}`;
398
+ if (line.level === "error") {
399
+ logger.warn(tagged);
400
+ } else {
401
+ logger.info(tagged);
402
+ }
403
+ },
404
+ onUnavailable: (message) => {
405
+ logger.warn(`[container] Docker engine unreachable — container logs unavailable (${message})`);
406
+ }
407
+ });
408
+ };
425
409
  const teardown = async (handles) => {
426
410
  handles.codegen?.close();
411
+ handles.containerLogs?.close();
427
412
  await handles.studio?.close().catch(() => void 0);
428
413
  try {
429
414
  handles.remoteCleanup?.();
@@ -441,7 +426,7 @@ const offerDevVariablesScaffold = async (options, cwd) => {
441
426
  } catch {
442
427
  }
443
428
  const result = await (options.ensureEnv ?? ensureDevVariables)({
444
- confirm: createConfirm(),
429
+ confirm: createTuiConfirm(),
445
430
  cwd,
446
431
  info: (message) => {
447
432
  options.logger.info(message);
@@ -452,6 +437,15 @@ const offerDevVariablesScaffold = async (options, cwd) => {
452
437
  `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.`
453
438
  );
454
439
  }
440
+ try {
441
+ (options.fillSecrets ?? fillDevSecrets)({
442
+ cwd,
443
+ info: (message) => {
444
+ options.logger.info(message);
445
+ }
446
+ });
447
+ } catch {
448
+ }
455
449
  };
456
450
  const runDevCommand = async (options) => {
457
451
  const plan = planDevCommand(options);
@@ -483,6 +477,10 @@ const runDevCommand = async (options) => {
483
477
  }
484
478
  }
485
479
  const worker = (options.startWorker ?? defaultWorkerSpawner)(plan.wrangler, logger);
480
+ try {
481
+ handles.containerLogs = startContainerLogStreaming(cwd, logger);
482
+ } catch {
483
+ }
486
484
  printBanner(logger, plan, studioUrl);
487
485
  printAgentRulesHint(logger, cwd);
488
486
  let sigintCount = 0;
@@ -1,7 +1,7 @@
1
1
  import { runCodegen } from '@lunora/codegen';
2
2
  import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
3
- import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
4
- import { v as validateOutputFormat, p as printJson, l as loggerForFormat, i as isJsonFormat } from '../packem_shared/output-format-7gyGR3h8.mjs';
3
+ import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
4
+ import { v as validateOutputFormat, p as printJson, l as loggerForFormat, i as isJsonFormat } from '../packem_shared/output-format-wUvAN6AL.mjs';
5
5
 
6
6
  const CRON_TRIGGER_LIMIT = 3;
7
7
  const runCodegenCommand = (options) => {
@@ -1,18 +1,20 @@
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';
7
7
  import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
8
8
  import { r as readWranglerName } from '../packem_shared/wrangler-name-cy4yhm9j.mjs';
9
- import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
9
+ import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
10
10
  import { a as isRailpackAvailable, i as isDockerAvailable } from '../packem_shared/docker-hMQ97KSQ.mjs';
11
- import { v as validateOutputFormat, i as isJsonFormat, p as printJson, l as loggerForFormat } from '../packem_shared/output-format-7gyGR3h8.mjs';
11
+ import { v as validateOutputFormat, i as isJsonFormat, p as printJson, l as loggerForFormat } from '../packem_shared/output-format-wUvAN6AL.mjs';
12
12
  import { containerBuildTag } from '@lunora/container';
13
- import { defaultSpawner } from '../packem_shared/defaultSpawner-DxI3mebw.mjs';
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-BjEN8XgP.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),