@lunora/cli 1.0.0-alpha.8 → 1.0.0-alpha.81

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 (60) hide show
  1. package/LICENSE.md +6 -0
  2. package/__assets__/package-og.svg +1 -1
  3. package/dist/bin.mjs +1 -1
  4. package/dist/index.d.mts +293 -134
  5. package/dist/index.d.ts +293 -134
  6. package/dist/index.mjs +8 -9
  7. package/dist/packem_chunks/handler.mjs +87 -6
  8. package/dist/packem_chunks/handler10.mjs +8 -14
  9. package/dist/packem_chunks/handler11.mjs +20 -189
  10. package/dist/packem_chunks/handler12.mjs +176 -115
  11. package/dist/packem_chunks/handler13.mjs +118 -52
  12. package/dist/packem_chunks/handler14.mjs +50 -43
  13. package/dist/packem_chunks/handler15.mjs +48 -67
  14. package/dist/packem_chunks/handler16.mjs +85 -37
  15. package/dist/packem_chunks/handler17.mjs +39 -100
  16. package/dist/packem_chunks/handler18.mjs +87 -152
  17. package/dist/packem_chunks/handler19.mjs +148 -67
  18. package/dist/packem_chunks/handler2.mjs +6 -4
  19. package/dist/packem_chunks/handler20.mjs +77 -75
  20. package/dist/packem_chunks/handler21.mjs +71 -288
  21. package/dist/packem_chunks/handler3.mjs +8 -4
  22. package/dist/packem_chunks/handler4.mjs +2 -2
  23. package/dist/packem_chunks/handler5.mjs +7 -4
  24. package/dist/packem_chunks/handler6.mjs +10 -7
  25. package/dist/packem_chunks/handler7.mjs +2 -2
  26. package/dist/packem_chunks/handler8.mjs +1 -1
  27. package/dist/packem_chunks/handler9.mjs +323 -12
  28. package/dist/packem_chunks/planDevCommand.mjs +758 -81
  29. package/dist/packem_chunks/runCodegenCommand.mjs +5 -4
  30. package/dist/packem_chunks/runDeployCommand.mjs +126 -20
  31. package/dist/packem_chunks/runInitCommand.mjs +1661 -179
  32. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +47 -41
  33. package/dist/packem_chunks/runResetCommand.mjs +2 -2
  34. package/dist/packem_chunks/runRpcCommand.mjs +3 -2
  35. package/dist/packem_shared/{COMMANDS-Bn8luojF.mjs → COMMANDS-D0tmnAwr.mjs} +106 -27
  36. package/dist/packem_shared/{DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs → DEFAULT_IMPORT_BATCH_SIZE-D0VOTerB.mjs} +7 -2
  37. package/dist/packem_shared/{api-spec-CtA6ilu4.mjs → api-spec-Bx0iKbxA.mjs} +3 -1
  38. package/dist/packem_shared/{buildRegistryIndex-BcYe607_.mjs → buildRegistryIndex-BS5ig822.mjs} +1 -1
  39. package/dist/packem_shared/codegen-error-DJG-ghs_.mjs +31 -0
  40. package/dist/packem_shared/{command-BDXcJCCJ.mjs → command-lYnl4QyF.mjs} +6 -1
  41. package/dist/packem_shared/{commands-DqsEzojt.mjs → commands-ClEvcz3V.mjs} +224 -18
  42. package/dist/packem_shared/{createLogger-CHPNjFw2.mjs → createLogger-CIWSHrTL.mjs} +40 -8
  43. package/dist/packem_shared/{createRecordingSpawner-DxI3mebw.mjs → createRecordingSpawner-WuSn20kb.mjs} +23 -2
  44. package/dist/packem_shared/{detect-package-manager-DYp7n3mJ.mjs → detect-package-manager-DvEthdCw.mjs} +26 -30
  45. package/dist/packem_shared/{insertSchemaExtension-BuzF6-t2.mjs → insertSchemaExtension-DAqbfr9Z.mjs} +15 -10
  46. package/dist/packem_shared/{open-url-Dfq6fAyT.mjs → open-url-4PBLY9X0.mjs} +3 -2
  47. package/dist/packem_shared/{output-format-7gyGR3h8.mjs → output-format-B4642rjE.mjs} +1 -1
  48. package/dist/packem_shared/{parseManifest--vZf2FY1.mjs → parseManifest-Dbp-Q2q3.mjs} +36 -9
  49. package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +9 -0
  50. package/dist/packem_shared/runAddCommand-DGjFXGqa.mjs +4 -0
  51. package/dist/packem_shared/storage-DEXpJkXh.mjs +84 -0
  52. package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +658 -0
  53. package/dist/packem_shared/wrangler-secrets-Dq_Fkbm-.mjs +49 -0
  54. package/package.json +16 -13
  55. package/skills/lunora-quickstart/SKILL.md +25 -5
  56. package/skills/lunora-setup-storage/SKILL.md +7 -3
  57. package/dist/packem_shared/features-ocSSpZtS.mjs +0 -24
  58. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
  59. package/dist/packem_shared/runAddCommand-G544_v6e.mjs +0 -4
  60. package/dist/packem_shared/tui-prompts-XHFxlOg5.mjs +0 -269
@@ -1,19 +1,22 @@
1
- import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync, mkdtempSync, cpSync, rmSync, renameSync } from 'node:fs';
1
+ import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync, rmSync, mkdtempSync, lstatSync, cpSync, renameSync } from 'node:fs';
2
2
  import { tmpdir } from 'node:os';
3
- import { detectFramework as detectFramework$1, isInteractive } from '@lunora/config';
3
+ import { detectFramework as detectFramework$1, isInteractive, LUNA_ART, LUNA_NAME, LUNA_SIGNOFF, paintAnswer, BADGES } from '@lunora/config';
4
4
  import { walkSync } from '@visulima/fs';
5
5
  import { join as join$1, dirname as dirname$1, basename, resolve, relative } from '@visulima/path';
6
6
  import { downloadTemplate } from 'giget';
7
7
  import { modify, applyEdits } from 'jsonc-parser';
8
8
  import { join, dirname } from 'node:path';
9
- import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
10
- import { a as detectInstalledManagers, i as installArgsFor } from '../packem_shared/detect-package-manager-DYp7n3mJ.mjs';
9
+ import { d as defineHandler } from '../packem_shared/command-lYnl4QyF.mjs';
10
+ import { d as detectPackageManager, a as detectInstalledManagers, i as installArgsFor, r as runScriptCommand } from '../packem_shared/detect-package-manager-DvEthdCw.mjs';
11
11
  import MagicString from 'magic-string';
12
12
  import { Project, SyntaxKind } from 'ts-morph';
13
- import { c as resolveDistTag, d as resolveSourceRef, r as runAddCommand } from '../packem_shared/commands-DqsEzojt.mjs';
14
- import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
15
- import { b as tuiOutro, d as tuiBanner, e as tuiText, f as tuiIntro, t as tuiSelect, w as withTuiSpinner, a as tuiConfirm, g as tuiMultiSelect } from '../packem_shared/tui-prompts-XHFxlOg5.mjs';
16
- import { p as promptAuthProvider, E as EMAIL_ITEM } from '../packem_shared/features-ocSSpZtS.mjs';
13
+ import { P as PromptCancelledError } from '../packem_shared/prompt-cancelled-APzX1Im-.mjs';
14
+ import { c as resolveTagVersions, d as resolveSourceRef, e as resolvePinnedSourceRef, f as resolveDistTag, r as runAddCommand } from '../packem_shared/commands-ClEvcz3V.mjs';
15
+ import { defaultSpawner } from '../packem_shared/createRecordingSpawner-WuSn20kb.mjs';
16
+ import { d as tuiMascot, e as tuiStep, f as tuiMoonrise, t as tuiText, g as tuiHeadline, h as tuiInfo, a as tuiSelect, b as tuiConfirm, w as withTuiSpinner, i as tuiNextSteps, j as tuiTasks, k as tuiMultiSelect, l as withTuiBadgeProgress } from '../packem_shared/tui-prompts-BjEN8XgP.mjs';
17
+ import { logStep } from '../packem_shared/createLogger-CIWSHrTL.mjs';
18
+ import { E as EMAIL_ITEM, p as promptBucketName, w as withStorageBucketName, M as MAIL_DESTINATION_PROMPT, r as resolveTypedDestination, f as withMailDestination, e as promptAuthProvider, c as promptDatabaseName, g as withAuthDatabaseName } from '../packem_shared/storage-DEXpJkXh.mjs';
19
+ import dns from 'node:dns/promises';
17
20
 
18
21
  const GITHUB_CONTENT = `name: Deploy
19
22
 
@@ -285,31 +288,1058 @@ const patchViteConfig = (source) => {
285
288
  return { changed: true, code: ms.toString() };
286
289
  };
287
290
 
291
+ const NETWORK_ERROR_PATTERN = /enotfound|eai_again|econnrefused|etimedout|network|fetch failed|getaddrinfo/u;
292
+ const NOT_FOUND_ERROR_PATTERN = /404|not found|could not find|no such/u;
293
+ const describeDownloadFailure = (error, context) => {
294
+ const raw = error instanceof Error ? error.message : String(error);
295
+ const lower = raw.toLowerCase();
296
+ const genericMessage = `failed to download template "${context.templateType}" from ${context.remote}: ${raw}`;
297
+ if (NOT_FOUND_ERROR_PATTERN.test(lower)) {
298
+ return {
299
+ hints: [
300
+ `Check the template name "${context.templateType}" and the ref "${context.ref}".`,
301
+ "List/inspect available templates, or target a branch/tag with `--ref <branch>`."
302
+ ],
303
+ message: `template "${context.templateType}" not found at ${context.remote}: ${raw}`
304
+ };
305
+ }
306
+ if (NETWORK_ERROR_PATTERN.test(lower)) {
307
+ return {
308
+ hints: [
309
+ "You appear to be offline or unable to reach GitHub.",
310
+ "To scaffold without a network, point at a local template root: `lunora init --from <dir>`."
311
+ ],
312
+ message: genericMessage
313
+ };
314
+ }
315
+ return {
316
+ hints: ["If this is a network/offline issue, scaffold from a local root with `lunora init --from <dir>`."],
317
+ message: genericMessage
318
+ };
319
+ };
320
+
321
+ const emitStep = async (type, message, answer) => {
322
+ if (isInteractive()) {
323
+ await tuiStep(BADGES[type], message, answer);
324
+ return;
325
+ }
326
+ process.stdout.write("\n");
327
+ if (answer === void 0 || answer === "") {
328
+ logStep(type, message);
329
+ return;
330
+ }
331
+ const dimmed = answer.split("\n").map((line) => paintAnswer(line)).join("\n");
332
+ logStep(type, `${message}
333
+ ${dimmed}`);
334
+ };
335
+ const emitMascot = async (logger) => {
336
+ if (isInteractive()) {
337
+ await tuiMascot();
338
+ return;
339
+ }
340
+ logger.info(`
341
+ ${LUNA_ART}
342
+ ${LUNA_NAME}: ${LUNA_SIGNOFF}`);
343
+ };
344
+
288
345
  const STACK_FEATURE_OPTIONS = [
346
+ { description: "LLMs via Workers AI (summarize, generate, stream)", label: "AI", value: "ai" },
289
347
  { description: "Sign-up / sign-in (asks which provider)", label: "Authentication", value: "auth" },
290
- { description: "Cloudflare Email Workers + a dev mail catcher", label: "Transactional email", value: "email" },
291
- { description: "Typed R2 buckets + signed URLs (@lunora/storage)", label: "File storage", value: "storage" },
292
- { description: "Token-bucket / sliding-window limits (@lunora/ratelimit)", label: "Rate limiting", value: "ratelimit" },
348
+ { description: "Snapshot + restore your Durable Object data", label: "Backups", value: "backup" },
349
+ { description: "Headless browser screenshots + PDFs", label: "Browser rendering", value: "browser" },
350
+ { description: "Zero Trust identity via Cloudflare Access", label: "Cloudflare Access", value: "cloudflare-access" },
293
351
  { description: "Scheduled jobs via Cron Triggers (@lunora/scheduler)", label: "Cron jobs", value: "crons" },
352
+ { description: "Cloudflare Email Workers + a dev mail catcher", label: "Transactional email", value: "email" },
353
+ { description: "OpenFeature feature flags (ctx.flags)", label: "Feature flags", value: "flags" },
354
+ { description: "External Postgres/MySQL via Hyperdrive", label: "Hyperdrive", value: "hyperdrive" },
355
+ { description: "Stripe-first payments (checkout, subscription, webhooks)", label: "Payments", value: "payment" },
294
356
  { description: "Live presence / who's-online over hibernated WebSockets", label: "Presence", value: "presence" },
295
- { description: "Snapshot + restore your Durable Object data", label: "Backups", value: "backup" }
357
+ { description: "Async message queues (push/pull consumers)", label: "Queues", value: "queue" },
358
+ { description: "Typed R2 buckets + signed URLs (@lunora/storage)", label: "File storage", value: "storage" },
359
+ { description: "Durable long-running workflows (step.do, sleep, branch)", label: "Workflows", value: "workflow" }
296
360
  ];
361
+ const STACK_FEATURE_VALUES = STACK_FEATURE_OPTIONS.map((option) => option.value);
362
+ const featureItem = (feature) => feature === "email" ? EMAIL_ITEM : feature;
363
+ const parseFeatureList = (raw, warn) => {
364
+ const features = [];
365
+ for (const part of raw.split(",").map((entry) => entry.trim()).filter(Boolean)) {
366
+ if (STACK_FEATURE_VALUES.includes(part)) {
367
+ if (!features.includes(part)) {
368
+ features.push(part);
369
+ }
370
+ } else {
371
+ warn(`init: unknown --add feature "${part}" — expected ${STACK_FEATURE_VALUES.join(" | ")}; skipping.`);
372
+ }
373
+ }
374
+ return features;
375
+ };
376
+ const collectAuthFeature = async (deps) => {
377
+ const provider = await promptAuthProvider(deps.select);
378
+ const databaseName = await promptDatabaseName(deps.text, deps.projectName);
379
+ return { label: "auth", names: [provider], transformManifest: (manifest) => withAuthDatabaseName(manifest, databaseName) };
380
+ };
381
+ const collectEmailFeature = async (deps) => {
382
+ const answer = await deps.text(MAIL_DESTINATION_PROMPT, { placeholder: "you@yourdomain.com" });
383
+ const destination = resolveTypedDestination(answer, (message) => {
384
+ deps.logger.warn(message);
385
+ });
386
+ return {
387
+ label: "email",
388
+ names: [EMAIL_ITEM],
389
+ transformManifest: destination === void 0 ? void 0 : (manifest) => withMailDestination(manifest, destination)
390
+ };
391
+ };
392
+ const collectStorageFeature = async (deps) => {
393
+ const bucketName = await promptBucketName(deps.text, deps.projectName);
394
+ return { label: "storage", names: ["storage"], transformManifest: (manifest) => withStorageBucketName(manifest, bucketName) };
395
+ };
396
+ const FEATURE_COLLECTORS = {
397
+ auth: collectAuthFeature,
398
+ email: collectEmailFeature,
399
+ storage: collectStorageFeature
400
+ };
297
401
  const offerRegistryExtras = async (deps) => {
402
+ if (deps.preselected !== void 0 && deps.preselected.length > 0) {
403
+ await deps.applyAll(
404
+ deps.preselected.map((feature) => {
405
+ return { label: feature, names: [featureItem(feature)] };
406
+ })
407
+ );
408
+ return;
409
+ }
298
410
  if (!deps.interactive) {
299
- deps.logger.info("tip: add features later with `lunora add <auth|email|storage|ratelimit|crons|presence|backup>`.");
411
+ deps.logger.info(
412
+ // eslint-disable-next-line no-secrets/no-secrets -- the pipe-separated feature list in this tip is a UI prompt, not a credential
413
+ "tip: add features later with `lunora add <ai|auth|backup|browser|cloudflare-access|crons|email|flags|hyperdrive|payment|presence|queue|storage|workflow>`."
414
+ );
300
415
  return;
301
416
  }
302
417
  const picked = await deps.multiSelect("Which features do you want to add?", STACK_FEATURE_OPTIONS, { defaults: [] });
418
+ if (picked.length === 0) {
419
+ return;
420
+ }
421
+ const plans = [];
303
422
  for (const feature of picked) {
304
- if (feature === "auth") {
305
- const provider = await promptAuthProvider(deps.select);
306
- await deps.apply([provider]);
307
- } else {
308
- await deps.apply([feature === "email" ? EMAIL_ITEM : feature]);
309
- }
423
+ const collect = FEATURE_COLLECTORS[feature];
424
+ plans.push(collect ? await collect(deps) : { label: feature, names: [feature] });
310
425
  }
426
+ await deps.applyAll(plans);
311
427
  };
312
428
 
429
+ const LOGO_PATH = "M 259.500 10.552 C 220.080 15.859, 182.424 32.566, 152.500 58.025 C 110.179 94.031, 85.380 137.183, 77.518 188.500 C 75.410 202.255, 74.569 225.677, 75.796 236.466 C 76.757 244.917, 76.683 245.692, 74.518 249.966 C 63.118 272.466, 53.141 303.876, 51.382 322.799 L 50.718 329.943 71.960 320.471 C 83.643 315.262, 93.326 311, 93.478 311 C 93.630 311, 96.547 316.063, 99.959 322.250 C 103.371 328.438, 107.249 334.850, 108.577 336.500 L 110.990 339.500 110.981 336 C 110.977 334.075, 111.499 324.991, 112.143 315.813 L 113.312 299.127 121.406 293.336 C 132.495 285.403, 149.593 271.554, 161 261.268 C 171.556 251.748, 189.116 235, 188.540 235 C 188.337 235, 183.069 238.648, 176.835 243.106 C 142.318 267.789, 68.537 314, 63.646 314 C 61.843 314, 72.791 281.179, 80.905 262.259 C 92.233 235.845, 107.473 212.389, 132.106 183.453 L 138.451 176 148.268 176 C 176.192 176, 197.512 187.154, 212.868 209.797 C 216.470 215.108, 217.035 216.595, 216.477 219.297 C 211.386 243.968, 202.359 274.496, 193.797 296 C 183.898 320.861, 167.147 352.101, 152.395 373.215 L 147.004 380.930 152.891 385.830 C 161.400 392.911, 165.563 396, 166.594 395.998 C 167.092 395.998, 168.772 391.641, 170.327 386.317 C 176.279 365.934, 188.422 338.749, 200.942 317.778 C 223.060 280.731, 256.432 244.369, 294.500 215.836 C 309.956 204.252, 313.937 201.603, 314.719 202.385 C 315.116 202.783, 315.449 213.096, 315.460 225.304 C 315.474 241.855, 315.021 250.405, 313.680 258.924 C 307.009 301.272, 291.175 336.677, 263.112 372 C 255.259 381.883, 227.182 410.673, 218.516 417.727 L 213.532 421.783 223.439 424.880 C 281.705 443.093, 349.165 436.018, 398.616 406.508 C 446.728 377.797, 483.322 331.466, 497.366 281.481 C 503.381 260.075, 504.480 250.741, 504.491 221 C 504.501 191.997, 503.598 184.047, 497.987 163.732 C 484.768 115.871, 452.505 72.708, 407.718 42.964 C 381.051 25.254, 352.818 14.828, 319.695 10.460 C 305.932 8.645, 273.298 8.695, 259.500 10.552";
430
+ const WELCOME_CSS = `/* The welcome page is a full-bleed starter — reset the browser's default
431
+ body margin/padding so it sits flush; everything else is scoped under
432
+ .lunora-welcome (collision-safe). */
433
+ body {
434
+ margin: 0;
435
+ padding: 0;
436
+ }
437
+
438
+ .lunora-welcome {
439
+ --cyan: hsl(186 84% 56%); --violet: hsl(256 72% 68%); --rose: hsl(330 80% 64%);
440
+ --ribbon: linear-gradient(115deg, var(--cyan), var(--violet) 52%, var(--rose));
441
+ --sans: "Geist Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
442
+ --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
443
+ /* NIGHT (default) */
444
+ --bg: #0e0e11; --surface: hsl(240 12% 8% / 0.72); --surface-2: hsl(240 11% 11% / 0.82);
445
+ --line: hsl(0 0% 100% / 0.08); --line-2: hsl(0 0% 100% / 0.14);
446
+ --t-display: hsl(228 30% 97%); --t-primary: hsl(228 26% 90%); --t-secondary: hsl(228 12% 62%); --t-faint: hsl(228 10% 44%);
447
+ --logo: hsl(228 30% 97%); --accent: var(--violet); --shot-bg: hsl(240 12% 6%);
448
+ --glow-1: hsl(256 80% 52% / 0.30); --glow-2: hsl(196 84% 52% / 0.13); --arc: hsl(256 60% 70% / 0.11);
449
+
450
+ position: relative; min-height: 100vh; background: var(--bg); color: var(--t-primary);
451
+ font-family: var(--sans); line-height: 1.55; -webkit-font-smoothing: antialiased; overflow-x: hidden;
452
+ transition: background .3s, color .3s;
453
+ }
454
+ .lunora-welcome[data-theme="light"] {
455
+ --bg: hsl(228 32% 97%); --surface: hsl(0 0% 100% / 0.82); --surface-2: hsl(0 0% 100% / 0.95);
456
+ --line: hsl(228 16% 88%); --line-2: hsl(228 14% 80%);
457
+ --t-display: hsl(240 14% 10%); --t-primary: hsl(240 12% 18%); --t-secondary: hsl(235 9% 42%); --t-faint: hsl(235 8% 58%);
458
+ --logo: hsl(240 16% 9%); --accent: hsl(256 58% 56%); --shot-bg: hsl(228 26% 99%);
459
+ --glow-1: hsl(256 80% 60% / 0.14); --glow-2: hsl(196 84% 58% / 0.08); --arc: hsl(256 40% 55% / 0.12);
460
+ }
461
+ .lunora-welcome *, .lunora-welcome *::before, .lunora-welcome *::after { box-sizing: border-box; }
462
+ .lunora-welcome a { color: inherit; text-decoration: none; }
463
+ .lunora-welcome button { font-family: inherit; cursor: pointer; }
464
+ .lunora-welcome ::selection { background: hsl(256 72% 68% / 0.3); }
465
+ .lunora-welcome code { font-family: var(--mono); }
466
+
467
+ /* glow background */
468
+ .lunora-welcome .lw-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
469
+ .lunora-welcome .lw-bg .glow { position: absolute; left: 50%; top: -4%; width: 860px; height: 720px; transform: translateX(-50%);
470
+ border-radius: 50%; background: radial-gradient(circle at 50% 50%, var(--glow-1), var(--glow-2) 40%, transparent 66%); }
471
+ .lunora-welcome .lw-bg .arc { position: absolute; left: 50%; border-radius: 50%; border: 1px solid var(--arc); transform: translateX(-50%); }
472
+ .lunora-welcome .lw-bg .arc.a1 { top: -340px; width: 980px; height: 980px; }
473
+ .lunora-welcome .lw-bg .arc.a2 { top: -240px; width: 720px; height: 720px; opacity: .7; }
474
+
475
+ /* theme toggle */
476
+ .lunora-welcome .lw-toggle { position: fixed; z-index: 5; top: 20px; right: clamp(16px,4vw,36px); display: inline-flex; align-items: center;
477
+ gap: 7px; border: 1px solid var(--line-2); background: var(--surface); backdrop-filter: blur(12px); color: var(--t-secondary);
478
+ font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; padding: 7px 11px; transition: .15s; }
479
+ .lunora-welcome .lw-toggle:hover { color: var(--t-display); border-color: var(--accent); }
480
+ .lunora-welcome .lw-toggle svg { width: 13px; height: 13px; }
481
+
482
+ .lunora-welcome .lw-wrap { position: relative; z-index: 2; width: 100%; max-width: 1080px; margin: 0 auto;
483
+ padding: clamp(44px,8vh,92px) clamp(20px,5vw,48px); display: flex; flex-direction: column; min-height: 100vh; }
484
+ .lunora-welcome .brand { display: flex; align-items: center; justify-content: center; gap: 15px; margin-bottom: clamp(38px,6vh,68px); color: var(--logo); }
485
+ .lunora-welcome .brand svg { width: 54px; height: auto; display: block; }
486
+ .lunora-welcome .brand .word { font-size: 34px; font-weight: 600; letter-spacing: -0.03em; color: var(--t-display); }
487
+
488
+ .lunora-welcome .grid { display: grid; grid-template-columns: 1.06fr 0.94fr; gap: 16px; align-items: stretch; flex: 1; max-height: 580px; }
489
+ @media (max-width: 820px) { .lunora-welcome .grid { grid-template-columns: 1fr; max-height: none; } }
490
+
491
+ .lunora-welcome .card { border: 1px solid var(--line); background: var(--surface); backdrop-filter: blur(10px); transition: border-color .2s, background .2s; }
492
+ .lunora-welcome .card:hover { border-color: var(--line-2); background: var(--surface-2); }
493
+ .lunora-welcome .card:hover .arrow { color: var(--accent); transform: translateX(3px); }
494
+ .lunora-welcome .arrow { color: var(--t-faint); transition: color .2s, transform .2s; }
495
+ .lunora-welcome .arrow svg { width: 20px; height: 20px; display: block; }
496
+ .lunora-welcome .ic { display: grid; place-items: center; color: var(--accent);
497
+ border: 1px solid color-mix(in oklab, var(--accent) 36%, transparent); background: color-mix(in oklab, var(--accent) 12%, transparent); }
498
+ .lunora-welcome .ic svg { display: block; }
499
+
500
+ /* left feature card — stretches to fill the box height */
501
+ .lunora-welcome .feature { padding: clamp(18px,2vw,24px); display: flex; flex-direction: column; }
502
+ .lunora-welcome .shot { border: 1px solid var(--line); overflow: hidden; background: var(--shot-bg);
503
+ -webkit-mask-image: linear-gradient(to bottom, #000 56%, transparent 100%); mask-image: linear-gradient(to bottom, #000 56%, transparent 100%); }
504
+ .lunora-welcome .shot .top { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
505
+ .lunora-welcome .shot .wm { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--t-primary); }
506
+ .lunora-welcome .shot .wm i { width: 11px; height: 11px; background: var(--ribbon); -webkit-mask: radial-gradient(circle,#000 60%,transparent 62%); mask: radial-gradient(circle,#000 60%,transparent 62%); }
507
+ .lunora-welcome .shot .search { flex: 1; height: 22px; border: 1px solid var(--line); border-radius: 4px; }
508
+ .lunora-welcome .shot .ver { font-family: var(--mono); font-size: 8px; letter-spacing: .08em; color: var(--t-faint); }
509
+ .lunora-welcome .shot .body { display: grid; grid-template-columns: 92px 1fr; min-height: 224px; }
510
+ .lunora-welcome .shot .nav { border-right: 1px solid var(--line); padding: 14px 12px; display: flex; flex-direction: column; gap: 11px; }
511
+ .lunora-welcome .shot .nav i, .lunora-welcome .shot .doc i { height: 5px; border-radius: 2px; background: var(--line); }
512
+ .lunora-welcome .shot .doc { padding: 16px 18px; display: flex; flex-direction: column; gap: 9px; }
513
+ .lunora-welcome .shot .doc .h { height: 8px; width: 46%; border-radius: 2px; background: var(--line-2); margin-bottom: 5px; }
514
+ .lunora-welcome .shot .doc .accent { height: 5px; width: 26%; border-radius: 2px; background: var(--accent); }
515
+ .lunora-welcome .feature .info { margin-top: auto; padding-top: clamp(18px,2.4vh,28px); }
516
+ .lunora-welcome .feature .ic { width: 40px; height: 40px; margin-bottom: 15px; }
517
+ .lunora-welcome .feature .ic svg { width: 19px; height: 19px; }
518
+ .lunora-welcome .feature h2 { margin: 0 0 10px; font-size: 19px; font-weight: 600; letter-spacing: -0.015em; color: var(--t-display); }
519
+ .lunora-welcome .feature .row { display: flex; align-items: flex-end; gap: 16px; }
520
+ .lunora-welcome .feature p { margin: 0; color: var(--t-secondary); font-size: 14px; max-width: 50ch; }
521
+ .lunora-welcome .feature .row .arrow { margin-left: auto; }
522
+
523
+ /* right stack — smaller cards, spread to align bottoms with the feature */
524
+ .lunora-welcome .stack { display: flex; flex-direction: column; gap: 16px; height: 100%; }
525
+ .lunora-welcome .mini { flex: 1; padding: 15px 17px; display: flex; align-items: center; gap: 16px; min-height: 0; }
526
+ .lunora-welcome .mini .mc { flex: 1; }
527
+ .lunora-welcome .mini .ic { width: 32px; height: 32px; margin-bottom: 10px; }
528
+ .lunora-welcome .mini .ic svg { width: 16px; height: 16px; }
529
+ .lunora-welcome .mini h3 { margin: 0 0 5px; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; color: var(--t-display); }
530
+ .lunora-welcome .mini p { margin: 0; color: var(--t-secondary); font-size: 12.5px; line-height: 1.45; }
531
+
532
+ .lunora-welcome .lw-foot { text-align: center; padding-top: 26px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--t-faint); }
533
+
534
+ @media (prefers-reduced-motion: reduce) { .lunora-welcome * { transition: none !important; } }
535
+ `;
536
+ const REACT_APP = `import { useEffect, useState } from "react";
537
+
538
+ type Theme = "dark" | "light";
539
+
540
+ export default function App() {
541
+ // Default to "dark" for a stable first paint, then reconcile to the OS
542
+ // preference; the toggle takes over after that.
543
+ const [theme, setTheme] = useState<Theme>("dark");
544
+
545
+ useEffect(() => {
546
+ if (typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: light)").matches) {
547
+ setTheme("light");
548
+ }
549
+ }, []);
550
+
551
+ const isLight = theme === "light";
552
+
553
+ return (
554
+ <div className="lunora-welcome" data-theme={theme}>
555
+ <div className="lw-bg">
556
+ <div className="arc a1" />
557
+ <div className="arc a2" />
558
+ <div className="glow" />
559
+ </div>
560
+
561
+ <button className="lw-toggle" type="button" aria-label="Toggle color theme" onClick={() => setTheme(isLight ? "dark" : "light")}>
562
+ {isLight ? (
563
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
564
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
565
+ </svg>
566
+ ) : (
567
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
568
+ <circle cx="12" cy="12" r="4" />
569
+ <path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M19 5l-1.5 1.5M6.5 17.5 5 19" />
570
+ </svg>
571
+ )}
572
+ <span>{isLight ? "Ivory" : "Night"}</span>
573
+ </button>
574
+
575
+ <div className="lw-wrap">
576
+ <div className="brand">
577
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
578
+ <path d="${LOGO_PATH}" fill="currentColor" fillRule="evenodd" />
579
+ </svg>
580
+ <span className="word">Lunora</span>
581
+ </div>
582
+
583
+ <div className="grid">
584
+ <a className="card feature" href="https://lunora.sh/docs">
585
+ <div className="shot" aria-hidden="true">
586
+ <div className="top">
587
+ <span className="wm">
588
+ <i /> Lunora
589
+ </span>
590
+ <span className="search" />
591
+ <span className="ver">v0.1</span>
592
+ </div>
593
+ <div className="body">
594
+ <div className="nav">
595
+ <i style={{ width: "80%" }} />
596
+ <i style={{ width: "60%" }} />
597
+ <i style={{ width: "72%" }} />
598
+ <i style={{ width: "50%" }} />
599
+ <i style={{ width: "66%" }} />
600
+ <i style={{ width: "44%" }} />
601
+ <i style={{ width: "58%" }} />
602
+ </div>
603
+ <div className="doc">
604
+ <span className="h" />
605
+ <i style={{ width: "92%" }} />
606
+ <i style={{ width: "88%" }} />
607
+ <span className="accent" />
608
+ <i style={{ width: "80%" }} />
609
+ <i style={{ width: "90%" }} />
610
+ <i style={{ width: "72%" }} />
611
+ <i style={{ width: "84%" }} />
612
+ <i style={{ width: "78%" }} />
613
+ </div>
614
+ </div>
615
+ </div>
616
+ <div className="info">
617
+ <span className="ic">
618
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
619
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
620
+ <path d="M14 3v5h5" />
621
+ </svg>
622
+ </span>
623
+ <h2>Documentation</h2>
624
+ <div className="row">
625
+ <p>
626
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
627
+ you'll have a live app fast.
628
+ </p>
629
+ <span className="arrow">
630
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
631
+ <path d="M5 12h14M13 6l6 6-6 6" />
632
+ </svg>
633
+ </span>
634
+ </div>
635
+ </div>
636
+ </a>
637
+
638
+ <div className="stack">
639
+ <a className="card mini" href="https://lunora.sh/blog">
640
+ <div className="mc">
641
+ <span className="ic">
642
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
643
+ <path d="M5 4h11a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V5a1 1 0 0 1 1-1zM8 8h7M8 12h7M8 16h4" />
644
+ </svg>
645
+ </span>
646
+ <h3>Blog</h3>
647
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
648
+ </div>
649
+ <span className="arrow">
650
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
651
+ <path d="M5 12h14M13 6l6 6-6 6" />
652
+ </svg>
653
+ </span>
654
+ </a>
655
+ <a className="card mini" href="/_lunora">
656
+ <div className="mc">
657
+ <span className="ic">
658
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
659
+ <rect x="3" y="3" width="18" height="18" rx="1" />
660
+ <path d="M3 9h18M9 21V9" />
661
+ </svg>
662
+ </span>
663
+ <h3>Lunora Studio</h3>
664
+ <p>Local admin for schema, data, logs, and advisors.</p>
665
+ </div>
666
+ <span className="arrow">
667
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
668
+ <path d="M5 12h14M13 6l6 6-6 6" />
669
+ </svg>
670
+ </span>
671
+ </a>
672
+ <a className="card mini" href="https://lunora.sh/packages">
673
+ <div className="mc">
674
+ <span className="ic">
675
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
676
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
677
+ <path d="M3 7l9 5 9-5M12 12v10" />
678
+ </svg>
679
+ </span>
680
+ <h3>Cloudflare ecosystem</h3>
681
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
682
+ </div>
683
+ <span className="arrow">
684
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
685
+ <path d="M5 12h14M13 6l6 6-6 6" />
686
+ </svg>
687
+ </span>
688
+ </a>
689
+ </div>
690
+ </div>
691
+
692
+ <div className="lw-foot">Running on Lunora · Vite + React</div>
693
+ </div>
694
+ </div>
695
+ );
696
+ }
697
+ `;
698
+ const VUE_APP = `<script setup lang="ts">
699
+ import { onMounted, ref } from "vue";
700
+
701
+ // Default to "dark" for a stable first paint, then reconcile to the OS
702
+ // preference; the toggle takes over after that.
703
+ const theme = ref<"dark" | "light">("dark");
704
+
705
+ onMounted(() => {
706
+ if (window.matchMedia("(prefers-color-scheme: light)").matches) {
707
+ theme.value = "light";
708
+ }
709
+ });
710
+
711
+ const toggle = (): void => {
712
+ theme.value = theme.value === "light" ? "dark" : "light";
713
+ };
714
+ <\/script>
715
+
716
+ <template>
717
+ <div class="lunora-welcome" :data-theme="theme">
718
+ <div class="lw-bg">
719
+ <div class="arc a1" />
720
+ <div class="arc a2" />
721
+ <div class="glow" />
722
+ </div>
723
+
724
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme" @click="toggle">
725
+ <svg v-if="theme === 'light'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
726
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
727
+ </svg>
728
+ <svg v-else viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
729
+ <circle cx="12" cy="12" r="4" />
730
+ <path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M19 5l-1.5 1.5M6.5 17.5 5 19" />
731
+ </svg>
732
+ <span>{{ theme === "light" ? "Ivory" : "Night" }}</span>
733
+ </button>
734
+
735
+ <div class="lw-wrap">
736
+ <div class="brand">
737
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
738
+ <path d="${LOGO_PATH}" fill="currentColor" fill-rule="evenodd" />
739
+ </svg>
740
+ <span class="word">Lunora</span>
741
+ </div>
742
+
743
+ <div class="grid">
744
+ <a class="card feature" href="https://lunora.sh/docs">
745
+ <div class="shot" aria-hidden="true">
746
+ <div class="top">
747
+ <span class="wm"><i /> Lunora</span>
748
+ <span class="search" />
749
+ <span class="ver">v0.1</span>
750
+ </div>
751
+ <div class="body">
752
+ <div class="nav">
753
+ <i style="width: 80%" />
754
+ <i style="width: 60%" />
755
+ <i style="width: 72%" />
756
+ <i style="width: 50%" />
757
+ <i style="width: 66%" />
758
+ <i style="width: 44%" />
759
+ <i style="width: 58%" />
760
+ </div>
761
+ <div class="doc">
762
+ <span class="h" />
763
+ <i style="width: 92%" />
764
+ <i style="width: 88%" />
765
+ <span class="accent" />
766
+ <i style="width: 80%" />
767
+ <i style="width: 90%" />
768
+ <i style="width: 72%" />
769
+ <i style="width: 84%" />
770
+ <i style="width: 78%" />
771
+ </div>
772
+ </div>
773
+ </div>
774
+ <div class="info">
775
+ <span class="ic">
776
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
777
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
778
+ <path d="M14 3v5h5" />
779
+ </svg>
780
+ </span>
781
+ <h2>Documentation</h2>
782
+ <div class="row">
783
+ <p>
784
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
785
+ you'll have a live app fast.
786
+ </p>
787
+ <span class="arrow">
788
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
789
+ <path d="M5 12h14M13 6l6 6-6 6" />
790
+ </svg>
791
+ </span>
792
+ </div>
793
+ </div>
794
+ </a>
795
+
796
+ <div class="stack">
797
+ <a class="card mini" href="https://lunora.sh/blog">
798
+ <div class="mc">
799
+ <span class="ic">
800
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
801
+ <path d="M5 4h11a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V5a1 1 0 0 1 1-1zM8 8h7M8 12h7M8 16h4" />
802
+ </svg>
803
+ </span>
804
+ <h3>Blog</h3>
805
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
806
+ </div>
807
+ <span class="arrow">
808
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
809
+ <path d="M5 12h14M13 6l6 6-6 6" />
810
+ </svg>
811
+ </span>
812
+ </a>
813
+ <a class="card mini" href="/_lunora">
814
+ <div class="mc">
815
+ <span class="ic">
816
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
817
+ <rect x="3" y="3" width="18" height="18" rx="1" />
818
+ <path d="M3 9h18M9 21V9" />
819
+ </svg>
820
+ </span>
821
+ <h3>Lunora Studio</h3>
822
+ <p>Local admin for schema, data, logs, and advisors.</p>
823
+ </div>
824
+ <span class="arrow">
825
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
826
+ <path d="M5 12h14M13 6l6 6-6 6" />
827
+ </svg>
828
+ </span>
829
+ </a>
830
+ <a class="card mini" href="https://lunora.sh/packages">
831
+ <div class="mc">
832
+ <span class="ic">
833
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
834
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
835
+ <path d="M3 7l9 5 9-5M12 12v10" />
836
+ </svg>
837
+ </span>
838
+ <h3>Cloudflare ecosystem</h3>
839
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
840
+ </div>
841
+ <span class="arrow">
842
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
843
+ <path d="M5 12h14M13 6l6 6-6 6" />
844
+ </svg>
845
+ </span>
846
+ </a>
847
+ </div>
848
+ </div>
849
+
850
+ <div class="lw-foot">Running on Lunora · Vite + Vue</div>
851
+ </div>
852
+ </div>
853
+ </template>
854
+ `;
855
+ const SOLID_APP = `import { createSignal, onMount } from "solid-js";
856
+
857
+ export default function App() {
858
+ // Default to "dark" for a stable first paint, then reconcile to the OS
859
+ // preference; the toggle takes over after that.
860
+ const [theme, setTheme] = createSignal<"dark" | "light">("dark");
861
+
862
+ onMount(() => {
863
+ if (window.matchMedia("(prefers-color-scheme: light)").matches) {
864
+ setTheme("light");
865
+ }
866
+ });
867
+
868
+ const isLight = () => theme() === "light";
869
+
870
+ return (
871
+ <div class="lunora-welcome" data-theme={theme()}>
872
+ <div class="lw-bg">
873
+ <div class="arc a1" />
874
+ <div class="arc a2" />
875
+ <div class="glow" />
876
+ </div>
877
+
878
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme" onClick={() => setTheme(isLight() ? "dark" : "light")}>
879
+ {isLight() ? (
880
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
881
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
882
+ </svg>
883
+ ) : (
884
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
885
+ <circle cx="12" cy="12" r="4" />
886
+ <path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M19 5l-1.5 1.5M6.5 17.5 5 19" />
887
+ </svg>
888
+ )}
889
+ <span>{isLight() ? "Ivory" : "Night"}</span>
890
+ </button>
891
+
892
+ <div class="lw-wrap">
893
+ <div class="brand">
894
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
895
+ <path d="${LOGO_PATH}" fill="currentColor" fill-rule="evenodd" />
896
+ </svg>
897
+ <span class="word">Lunora</span>
898
+ </div>
899
+
900
+ <div class="grid">
901
+ <a class="card feature" href="https://lunora.sh/docs">
902
+ <div class="shot" aria-hidden="true">
903
+ <div class="top">
904
+ <span class="wm">
905
+ <i /> Lunora
906
+ </span>
907
+ <span class="search" />
908
+ <span class="ver">v0.1</span>
909
+ </div>
910
+ <div class="body">
911
+ <div class="nav">
912
+ <i style={{ width: "80%" }} />
913
+ <i style={{ width: "60%" }} />
914
+ <i style={{ width: "72%" }} />
915
+ <i style={{ width: "50%" }} />
916
+ <i style={{ width: "66%" }} />
917
+ <i style={{ width: "44%" }} />
918
+ <i style={{ width: "58%" }} />
919
+ </div>
920
+ <div class="doc">
921
+ <span class="h" />
922
+ <i style={{ width: "92%" }} />
923
+ <i style={{ width: "88%" }} />
924
+ <span class="accent" />
925
+ <i style={{ width: "80%" }} />
926
+ <i style={{ width: "90%" }} />
927
+ <i style={{ width: "72%" }} />
928
+ <i style={{ width: "84%" }} />
929
+ <i style={{ width: "78%" }} />
930
+ </div>
931
+ </div>
932
+ </div>
933
+ <div class="info">
934
+ <span class="ic">
935
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
936
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
937
+ <path d="M14 3v5h5" />
938
+ </svg>
939
+ </span>
940
+ <h2>Documentation</h2>
941
+ <div class="row">
942
+ <p>
943
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
944
+ you'll have a live app fast.
945
+ </p>
946
+ <span class="arrow">
947
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
948
+ <path d="M5 12h14M13 6l6 6-6 6" />
949
+ </svg>
950
+ </span>
951
+ </div>
952
+ </div>
953
+ </a>
954
+
955
+ <div class="stack">
956
+ <a class="card mini" href="https://lunora.sh/blog">
957
+ <div class="mc">
958
+ <span class="ic">
959
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
960
+ <path d="M5 4h11a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V5a1 1 0 0 1 1-1zM8 8h7M8 12h7M8 16h4" />
961
+ </svg>
962
+ </span>
963
+ <h3>Blog</h3>
964
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
965
+ </div>
966
+ <span class="arrow">
967
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
968
+ <path d="M5 12h14M13 6l6 6-6 6" />
969
+ </svg>
970
+ </span>
971
+ </a>
972
+ <a class="card mini" href="/_lunora">
973
+ <div class="mc">
974
+ <span class="ic">
975
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
976
+ <rect x="3" y="3" width="18" height="18" rx="1" />
977
+ <path d="M3 9h18M9 21V9" />
978
+ </svg>
979
+ </span>
980
+ <h3>Lunora Studio</h3>
981
+ <p>Local admin for schema, data, logs, and advisors.</p>
982
+ </div>
983
+ <span class="arrow">
984
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
985
+ <path d="M5 12h14M13 6l6 6-6 6" />
986
+ </svg>
987
+ </span>
988
+ </a>
989
+ <a class="card mini" href="https://lunora.sh/packages">
990
+ <div class="mc">
991
+ <span class="ic">
992
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
993
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
994
+ <path d="M3 7l9 5 9-5M12 12v10" />
995
+ </svg>
996
+ </span>
997
+ <h3>Cloudflare ecosystem</h3>
998
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
999
+ </div>
1000
+ <span class="arrow">
1001
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1002
+ <path d="M5 12h14M13 6l6 6-6 6" />
1003
+ </svg>
1004
+ </span>
1005
+ </a>
1006
+ </div>
1007
+ </div>
1008
+
1009
+ <div class="lw-foot">Running on Lunora · Vite + Solid</div>
1010
+ </div>
1011
+ </div>
1012
+ );
1013
+ }
1014
+ `;
1015
+ const SVELTE_APP = `<script lang="ts">
1016
+ import { onMount } from "svelte";
1017
+
1018
+ // Default to "dark" for a stable first paint, then reconcile to the OS
1019
+ // preference; the toggle takes over after that.
1020
+ let theme = $state<"dark" | "light">("dark");
1021
+ const isLight = $derived(theme === "light");
1022
+
1023
+ onMount(() => {
1024
+ if (window.matchMedia("(prefers-color-scheme: light)").matches) {
1025
+ theme = "light";
1026
+ }
1027
+ });
1028
+
1029
+ const toggle = (): void => {
1030
+ theme = theme === "light" ? "dark" : "light";
1031
+ };
1032
+ <\/script>
1033
+
1034
+ <div class="lunora-welcome" data-theme={theme}>
1035
+ <div class="lw-bg">
1036
+ <div class="arc a1"></div>
1037
+ <div class="arc a2"></div>
1038
+ <div class="glow"></div>
1039
+ </div>
1040
+
1041
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme" onclick={toggle}>
1042
+ {#if isLight}
1043
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
1044
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
1045
+ </svg>
1046
+ {:else}
1047
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
1048
+ <circle cx="12" cy="12" r="4" />
1049
+ <path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M19 5l-1.5 1.5M6.5 17.5 5 19" />
1050
+ </svg>
1051
+ {/if}
1052
+ <span>{isLight ? "Ivory" : "Night"}</span>
1053
+ </button>
1054
+
1055
+ <div class="lw-wrap">
1056
+ <div class="brand">
1057
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
1058
+ <path d="${LOGO_PATH}" fill="currentColor" fill-rule="evenodd" />
1059
+ </svg>
1060
+ <span class="word">Lunora</span>
1061
+ </div>
1062
+
1063
+ <div class="grid">
1064
+ <a class="card feature" href="https://lunora.sh/docs">
1065
+ <div class="shot" aria-hidden="true">
1066
+ <div class="top">
1067
+ <span class="wm"><i></i> Lunora</span>
1068
+ <span class="search"></span>
1069
+ <span class="ver">v0.1</span>
1070
+ </div>
1071
+ <div class="body">
1072
+ <div class="nav">
1073
+ <i style="width: 80%"></i>
1074
+ <i style="width: 60%"></i>
1075
+ <i style="width: 72%"></i>
1076
+ <i style="width: 50%"></i>
1077
+ <i style="width: 66%"></i>
1078
+ <i style="width: 44%"></i>
1079
+ <i style="width: 58%"></i>
1080
+ </div>
1081
+ <div class="doc">
1082
+ <span class="h"></span>
1083
+ <i style="width: 92%"></i>
1084
+ <i style="width: 88%"></i>
1085
+ <span class="accent"></span>
1086
+ <i style="width: 80%"></i>
1087
+ <i style="width: 90%"></i>
1088
+ <i style="width: 72%"></i>
1089
+ <i style="width: 84%"></i>
1090
+ <i style="width: 78%"></i>
1091
+ </div>
1092
+ </div>
1093
+ </div>
1094
+ <div class="info">
1095
+ <span class="ic">
1096
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1097
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
1098
+ <path d="M14 3v5h5" />
1099
+ </svg>
1100
+ </span>
1101
+ <h2>Documentation</h2>
1102
+ <div class="row">
1103
+ <p>
1104
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
1105
+ you'll have a live app fast.
1106
+ </p>
1107
+ <span class="arrow">
1108
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1109
+ <path d="M5 12h14M13 6l6 6-6 6" />
1110
+ </svg>
1111
+ </span>
1112
+ </div>
1113
+ </div>
1114
+ </a>
1115
+
1116
+ <div class="stack">
1117
+ <a class="card mini" href="https://lunora.sh/blog">
1118
+ <div class="mc">
1119
+ <span class="ic">
1120
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1121
+ <path d="M5 4h11a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V5a1 1 0 0 1 1-1zM8 8h7M8 12h7M8 16h4" />
1122
+ </svg>
1123
+ </span>
1124
+ <h3>Blog</h3>
1125
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
1126
+ </div>
1127
+ <span class="arrow">
1128
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1129
+ <path d="M5 12h14M13 6l6 6-6 6" />
1130
+ </svg>
1131
+ </span>
1132
+ </a>
1133
+ <a class="card mini" href="/_lunora">
1134
+ <div class="mc">
1135
+ <span class="ic">
1136
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1137
+ <rect x="3" y="3" width="18" height="18" rx="1" />
1138
+ <path d="M3 9h18M9 21V9" />
1139
+ </svg>
1140
+ </span>
1141
+ <h3>Lunora Studio</h3>
1142
+ <p>Local admin for schema, data, logs, and advisors.</p>
1143
+ </div>
1144
+ <span class="arrow">
1145
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1146
+ <path d="M5 12h14M13 6l6 6-6 6" />
1147
+ </svg>
1148
+ </span>
1149
+ </a>
1150
+ <a class="card mini" href="https://lunora.sh/packages">
1151
+ <div class="mc">
1152
+ <span class="ic">
1153
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1154
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
1155
+ <path d="M3 7l9 5 9-5M12 12v10" />
1156
+ </svg>
1157
+ </span>
1158
+ <h3>Cloudflare ecosystem</h3>
1159
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
1160
+ </div>
1161
+ <span class="arrow">
1162
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1163
+ <path d="M5 12h14M13 6l6 6-6 6" />
1164
+ </svg>
1165
+ </span>
1166
+ </a>
1167
+ </div>
1168
+ </div>
1169
+
1170
+ <div class="lw-foot">Running on Lunora · Vite + Svelte</div>
1171
+ </div>
1172
+ </div>
1173
+ `;
1174
+ const VANILLA_MAIN = `import "./style.css";
1175
+
1176
+ import { LunoraClient } from "lunorash/client";
1177
+
1178
+ import { api } from "#lunora/_generated/api.js";
1179
+
1180
+ // \`@lunora/vite\` runs the Worker on the same origin as Vite, so default to
1181
+ // \`location.origin\`. Point \`VITE_LUNORA_URL\` at a deployed Worker to develop
1182
+ // the client against production data.
1183
+ const url = (import.meta.env.VITE_LUNORA_URL as string | undefined) ?? globalThis.location.origin;
1184
+ const client = new LunoraClient({ url });
1185
+
1186
+ const MOON_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" /></svg>';
1187
+ const SUN_ICON =
1188
+ '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><circle cx="12" cy="12" r="4" /><path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M19 5l-1.5 1.5M6.5 17.5 5 19" /></svg>';
1189
+
1190
+ const welcomeHtml = \`
1191
+ <div class="lw-bg">
1192
+ <div class="arc a1"></div>
1193
+ <div class="arc a2"></div>
1194
+ <div class="glow"></div>
1195
+ </div>
1196
+
1197
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme"></button>
1198
+
1199
+ <div class="lw-wrap">
1200
+ <div class="brand">
1201
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
1202
+ <path d="${LOGO_PATH}" fill="currentColor" fill-rule="evenodd" />
1203
+ </svg>
1204
+ <span class="word">Lunora</span>
1205
+ </div>
1206
+
1207
+ <div class="grid">
1208
+ <a class="card feature" href="https://lunora.sh/docs">
1209
+ <div class="shot" aria-hidden="true">
1210
+ <div class="top">
1211
+ <span class="wm"><i></i> Lunora</span>
1212
+ <span class="search"></span>
1213
+ <span class="ver">v0.1</span>
1214
+ </div>
1215
+ <div class="body">
1216
+ <div class="nav">
1217
+ <i style="width: 80%"></i>
1218
+ <i style="width: 60%"></i>
1219
+ <i style="width: 72%"></i>
1220
+ <i style="width: 50%"></i>
1221
+ <i style="width: 66%"></i>
1222
+ <i style="width: 44%"></i>
1223
+ <i style="width: 58%"></i>
1224
+ </div>
1225
+ <div class="doc">
1226
+ <span class="h"></span>
1227
+ <i style="width: 92%"></i>
1228
+ <i style="width: 88%"></i>
1229
+ <span class="accent"></span>
1230
+ <i style="width: 80%"></i>
1231
+ <i style="width: 90%"></i>
1232
+ <i style="width: 72%"></i>
1233
+ <i style="width: 84%"></i>
1234
+ <i style="width: 78%"></i>
1235
+ </div>
1236
+ </div>
1237
+ </div>
1238
+ <div class="info">
1239
+ <span class="ic">
1240
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1241
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
1242
+ <path d="M14 3v5h5" />
1243
+ </svg>
1244
+ </span>
1245
+ <h2>Documentation</h2>
1246
+ <div class="row">
1247
+ <p>
1248
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
1249
+ you'll have a live app fast.
1250
+ </p>
1251
+ <span class="arrow">
1252
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1253
+ <path d="M5 12h14M13 6l6 6-6 6" />
1254
+ </svg>
1255
+ </span>
1256
+ </div>
1257
+ </div>
1258
+ </a>
1259
+
1260
+ <div class="stack">
1261
+ <a class="card mini" href="https://lunora.sh/blog">
1262
+ <div class="mc">
1263
+ <span class="ic">
1264
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1265
+ <path d="M5 4h11a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V5a1 1 0 0 1 1-1zM8 8h7M8 12h7M8 16h4" />
1266
+ </svg>
1267
+ </span>
1268
+ <h3>Blog</h3>
1269
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
1270
+ </div>
1271
+ <span class="arrow">
1272
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1273
+ <path d="M5 12h14M13 6l6 6-6 6" />
1274
+ </svg>
1275
+ </span>
1276
+ </a>
1277
+ <a class="card mini" href="/_lunora">
1278
+ <div class="mc">
1279
+ <span class="ic">
1280
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1281
+ <rect x="3" y="3" width="18" height="18" rx="1" />
1282
+ <path d="M3 9h18M9 21V9" />
1283
+ </svg>
1284
+ </span>
1285
+ <h3>Lunora Studio</h3>
1286
+ <p>Local admin for schema, data, logs, and advisors.</p>
1287
+ </div>
1288
+ <span class="arrow">
1289
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1290
+ <path d="M5 12h14M13 6l6 6-6 6" />
1291
+ </svg>
1292
+ </span>
1293
+ </a>
1294
+ <a class="card mini" href="https://lunora.sh/packages">
1295
+ <div class="mc">
1296
+ <span class="ic">
1297
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1298
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
1299
+ <path d="M3 7l9 5 9-5M12 12v10" />
1300
+ </svg>
1301
+ </span>
1302
+ <h3>Cloudflare ecosystem</h3>
1303
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
1304
+ </div>
1305
+ <span class="arrow">
1306
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1307
+ <path d="M5 12h14M13 6l6 6-6 6" />
1308
+ </svg>
1309
+ </span>
1310
+ </a>
1311
+ </div>
1312
+ </div>
1313
+
1314
+ <div class="lw-foot">Running on Lunora · Vite + Vanilla · <span id="lw-count">0</span> messages</div>
1315
+ </div>
1316
+ \`;
1317
+
1318
+ const root = document.querySelector<HTMLDivElement>("#app")!;
1319
+ root.classList.add("lunora-welcome");
1320
+ root.innerHTML = welcomeHtml;
1321
+
1322
+ // Theme toggle: flip the root's data-theme + swap the button's icon/label.
1323
+ const toggleButton = root.querySelector<HTMLButtonElement>(".lw-toggle")!;
1324
+
1325
+ const paintToggle = (theme: "dark" | "light"): void => {
1326
+ root.dataset.theme = theme;
1327
+ toggleButton.innerHTML = \`\${theme === "light" ? MOON_ICON : SUN_ICON}<span>\${theme === "light" ? "Ivory" : "Night"}</span>\`;
1328
+ };
1329
+
1330
+ paintToggle(window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark");
1331
+ toggleButton.addEventListener("click", () => {
1332
+ paintToggle(root.dataset.theme === "light" ? "dark" : "light");
1333
+ });
1334
+
1335
+ // Live demo: the message count of a demo channel re-renders on every delta.
1336
+ const count = document.querySelector<HTMLSpanElement>("#lw-count")!;
1337
+
1338
+ client.onUpdate(api.messages.list, { channelId: "channel:demo" }, (result) => {
1339
+ count.textContent = String(result.messages.length);
1340
+ });
1341
+ `;
1342
+
313
1343
  const READ_URL = `const url = (import.meta.env.VITE_LUNORA_URL as string | undefined) ?? globalThis.location.origin;`;
314
1344
  const REACT_MAIN = `import "./index.css";
315
1345
 
@@ -396,51 +1426,103 @@ const app = mount(Root, { target: document.getElementById("app")! });
396
1426
 
397
1427
  export default app;
398
1428
  `;
399
- const VANILLA_MAIN = `import "./style.css";
400
-
401
- import { LunoraClient } from "lunorash/client";
402
-
403
- import { api } from "../lunora/_generated/api";
404
-
405
- // Vanilla starter: no framework provider — talk to Lunora through the client
406
- // directly. \`@lunora/vite\` runs the Worker on the same origin as Vite.
407
- ${READ_URL}
408
- const client = new LunoraClient({ url });
409
-
410
- const root = document.querySelector<HTMLDivElement>("#app")!;
411
-
412
- const heading = document.createElement("h1");
413
- heading.textContent = "Vite + Lunora";
414
-
415
- const output = document.createElement("pre");
416
- root.replaceChildren(heading, output);
417
-
418
- const render = (messages: unknown): void => {
419
- // textContent (not innerHTML) — never inject server data as markup.
420
- output.textContent = JSON.stringify(messages, null, 2);
421
- };
422
-
423
- // Live subscription: the list re-renders on every server delta.
424
- client.onUpdate(api.messages.list, { channelId: "channel:demo" }, render);
425
- `;
426
1429
  const ADAPTERS = {
427
- react: { adapter: "@lunora/react", createViteTemplate: "react-ts", files: [{ contents: REACT_MAIN, path: "src/main.tsx" }], label: "React" },
428
- solid: { adapter: "@lunora/solid", createViteTemplate: "solid", files: [{ contents: SOLID_INDEX, path: "src/index.tsx" }], label: "Solid" },
1430
+ react: {
1431
+ adapter: "@lunora/react",
1432
+ createViteTemplate: "react-ts",
1433
+ files: [
1434
+ { contents: REACT_MAIN, path: "src/main.tsx" },
1435
+ { contents: REACT_APP, path: "src/App.tsx" },
1436
+ { contents: WELCOME_CSS, path: "src/index.css" }
1437
+ ],
1438
+ label: "React"
1439
+ },
1440
+ solid: {
1441
+ adapter: "@lunora/solid",
1442
+ createViteTemplate: "solid-ts",
1443
+ files: [
1444
+ { contents: SOLID_INDEX, path: "src/index.tsx" },
1445
+ { contents: SOLID_APP, path: "src/App.tsx" },
1446
+ { contents: WELCOME_CSS, path: "src/index.css" }
1447
+ ],
1448
+ label: "Solid"
1449
+ },
429
1450
  svelte: {
430
1451
  adapter: "@lunora/svelte",
431
1452
  createViteTemplate: "svelte-ts",
432
1453
  files: [
433
1454
  { contents: SVELTE_ROOT, path: "src/Root.svelte" },
434
- { contents: SVELTE_MAIN, path: "src/main.ts" }
1455
+ { contents: SVELTE_MAIN, path: "src/main.ts" },
1456
+ { contents: SVELTE_APP, path: "src/App.svelte" },
1457
+ { contents: WELCOME_CSS, path: "src/app.css" }
435
1458
  ],
436
1459
  label: "Svelte"
437
1460
  },
438
- vanilla: { adapter: "lunorash/client", createViteTemplate: "vanilla-ts", files: [{ contents: VANILLA_MAIN, path: "src/main.ts" }], label: "Vanilla" },
439
- vue: { adapter: "@lunora/vue", createViteTemplate: "vue-ts", files: [{ contents: VUE_MAIN, path: "src/main.ts" }], label: "Vue" }
1461
+ vanilla: {
1462
+ adapter: "lunorash/client",
1463
+ createViteTemplate: "vanilla-ts",
1464
+ files: [
1465
+ { contents: VANILLA_MAIN, path: "src/main.ts" },
1466
+ { contents: WELCOME_CSS, path: "src/style.css" }
1467
+ ],
1468
+ label: "Vanilla"
1469
+ },
1470
+ vue: {
1471
+ adapter: "@lunora/vue",
1472
+ createViteTemplate: "vue-ts",
1473
+ files: [
1474
+ { contents: VUE_MAIN, path: "src/main.ts" },
1475
+ { contents: VUE_APP, path: "src/App.vue" },
1476
+ { contents: WELCOME_CSS, path: "src/style.css" }
1477
+ ],
1478
+ label: "Vue"
1479
+ }
440
1480
  };
441
1481
  const isOverlayFramework = (value) => Object.hasOwn(ADAPTERS, value);
442
1482
 
443
- const LUNORA_SCHEMA = `import { defineSchema, defineTable, v } from "lunorash/server";
1483
+ const RATELIMIT_SCHEMA = `import type { Middleware } from "lunorash/server";
1484
+ import { defineSchemaExtension, defineTable, definePlugin, v } from "lunorash/server";
1485
+ import { createDbStore, RateLimiter } from "lunorash/ratelimit";
1486
+ import type { RateLimitConfigMap } from "lunorash/ratelimit";
1487
+
1488
+ export const limits = {
1489
+ default: { kind: "token bucket", period: 60_000, rate: 10 },
1490
+ } as const satisfies RateLimitConfigMap;
1491
+
1492
+ export type LimitName = keyof typeof limits;
1493
+
1494
+ export const makeRateLimiter = (ctx: { db: unknown }): RateLimiter<LimitName> =>
1495
+ new RateLimiter<LimitName>({
1496
+ config: limits,
1497
+ store: createDbStore({ db: ctx.db as never, table: "ratelimit_buckets" }),
1498
+ });
1499
+
1500
+ const middleware: Middleware<{ api?: Record<string, unknown>; db: unknown }, { api: Record<string, unknown>; db: unknown }> = ({ ctx, next }) =>
1501
+ next({
1502
+ ctx: {
1503
+ ...ctx,
1504
+ api: { ...ctx.api, ratelimit: makeRateLimiter(ctx) },
1505
+ },
1506
+ });
1507
+
1508
+ export const ratelimit = definePlugin("ratelimit", {
1509
+ extension: defineSchemaExtension("ratelimit", {
1510
+ tables: {
1511
+ buckets: defineTable({
1512
+ key: v.string(),
1513
+ value: v.number(),
1514
+ ts: v.number(),
1515
+ prev: v.optional(v.number()),
1516
+ })
1517
+ .index("by_key", ["key"])
1518
+ .externallyManaged(),
1519
+ },
1520
+ }),
1521
+ middleware,
1522
+ });
1523
+ `;
1524
+ const LUNORA_SCHEMA = `import { ratelimit } from "./ratelimit/schema.js";
1525
+ import { defineSchema, defineTable, v } from "lunorash/server";
444
1526
 
445
1527
  export default defineSchema({
446
1528
  messages: defineTable({
@@ -449,17 +1531,36 @@ export default defineSchema({
449
1531
  })
450
1532
  .shardBy("channelId")
451
1533
  .index("by_channel", ["channelId"]),
452
- });
1534
+ }).extend(ratelimit.extension);
453
1535
  `;
454
- const LUNORA_MESSAGES = `import { mutation, query, v } from "./_generated/server.js";
1536
+ const LUNORA_MESSAGES = `import { RateLimiter, rateLimit, createDbStore } from "lunorash/ratelimit";
1537
+
1538
+ import { mutation, query, v } from "#lunora/_generated/server.js";
455
1539
 
456
- export const list = query.input({ channelId: v.string(), limit: v.optional(v.number()) }).query(async ({ args }) => {
457
- return { channelId: args.channelId, limit: args.limit ?? 50, messages: [] };
1540
+ const limiter = (ctx: { db: unknown }) => new RateLimiter({
1541
+ config: {
1542
+ send: { kind: "token bucket", period: 60_000, rate: 30 },
1543
+ },
1544
+ store: createDbStore({ db: ctx.db as never, table: "ratelimit_buckets" }),
458
1545
  });
459
1546
 
460
- export const send = mutation.input({ channelId: v.string(), text: v.string() }).mutation(async ({ args }) => {
461
- return { channelId: args.channelId, text: args.text };
1547
+ export const list = query.input({ channelId: v.string().meta({ schema: { maxLength: 256 } }), limit: v.optional(v.number()) }).query(async ({ args, ctx }) => {
1548
+ const messages = await ctx.db
1549
+ .query("messages")
1550
+ .withIndex("by_channel", (q) => q.eq("channelId", args.channelId))
1551
+ .take(args.limit ?? 50);
1552
+
1553
+ return { channelId: args.channelId, messages };
462
1554
  });
1555
+
1556
+ export const send = mutation
1557
+ .input({ channelId: v.string().meta({ schema: { maxLength: 256 } }), text: v.string().meta({ schema: { maxLength: 4096 } }) })
1558
+ .use(rateLimit(limiter, "send", { key: (ctx) => ctx.auth.userId ?? "anon" }))
1559
+ .mutation(async ({ args, ctx }) => {
1560
+ const id = await ctx.db.insert("messages", { channelId: args.channelId, text: args.text });
1561
+
1562
+ return { channelId: args.channelId, id, text: args.text };
1563
+ });
463
1564
  `;
464
1565
  const SERVER_ENTRY = `import type { ShardNamespaceLike } from "lunorash/runtime";
465
1566
 
@@ -520,15 +1621,17 @@ const ensureGitignore = (target) => {
520
1621
  ${missing.join("\n")}
521
1622
  `, "utf8");
522
1623
  };
523
- const stampRange = (name, range, distTag) => name === "lunorash" || name.startsWith("@lunora/") ? distTag : range;
1624
+ const isLunoraDep$1 = (name) => name === "lunorash" || name.startsWith("@lunora/");
1625
+ const stampRange = (name, range, distTag, versions) => isLunoraDep$1(name) ? versions?.get(name) ?? distTag : range;
524
1626
  const withDependency = (map, name, range, distTag) => {
525
1627
  return { ...map, [name]: stampRange(name, range, distTag) };
526
1628
  };
527
- const restampLunora = (map, distTag) => Object.fromEntries(Object.entries(map).map(([name, range]) => [name, stampRange(name, range, distTag)]));
528
- const patchPackageJson = (target, name, adapter, distTag) => {
1629
+ const restampLunora = (map, distTag, versions) => Object.fromEntries(Object.entries(map).map(([name, range]) => [name, stampRange(name, range, distTag, versions)]));
1630
+ const patchPackageJson = async (target, name, adapter, distTag) => {
529
1631
  const path = join$1(target, "package.json");
530
1632
  const parsed = JSON.parse(readFileSync(path, "utf8"));
531
1633
  let dependencies = withDependency(parsed.dependencies ?? {}, "lunorash", distTag, distTag);
1634
+ dependencies = withDependency(dependencies, "@lunora/ratelimit", distTag, distTag);
532
1635
  if (adapter.adapter.startsWith("@lunora/")) {
533
1636
  dependencies = withDependency(dependencies, adapter.adapter, distTag, distTag);
534
1637
  }
@@ -536,12 +1639,16 @@ const patchPackageJson = (target, name, adapter, distTag) => {
536
1639
  dependencies = withDependency(dependencies, depName, range, distTag);
537
1640
  }
538
1641
  let devDependencies = withDependency(parsed.devDependencies ?? {}, "@lunora/vite", distTag, distTag);
1642
+ devDependencies = withDependency(devDependencies, "@lunora/studio", distTag, distTag);
539
1643
  for (const [depName, range] of Object.entries(COMMON_DEV_DEPENDENCIES)) {
540
1644
  devDependencies = withDependency(devDependencies, depName, range, distTag);
541
1645
  }
1646
+ const lunoraNames = [...Object.keys(dependencies), ...Object.keys(devDependencies)].filter((depName) => isLunoraDep$1(depName));
1647
+ const versions = await resolveTagVersions(lunoraNames, distTag);
542
1648
  parsed.name = name;
543
- parsed.dependencies = restampLunora(dependencies, distTag);
544
- parsed.devDependencies = restampLunora(devDependencies, distTag);
1649
+ parsed.imports = { ...parsed.imports, "#lunora/*": "./lunora/*" };
1650
+ parsed.dependencies = restampLunora(dependencies, distTag, versions);
1651
+ parsed.devDependencies = restampLunora(devDependencies, distTag, versions);
545
1652
  parsed.scripts = { ...parsed.scripts, codegen: "lunora codegen", deploy: "vite build && lunora deploy" };
546
1653
  writeFileSync(path, `${JSON.stringify(parsed, void 0, 4)}
547
1654
  `, "utf8");
@@ -557,9 +1664,10 @@ const patchBaseViteConfig = (target, logger) => {
557
1664
  writeFileSync(candidate, result.code, "utf8");
558
1665
  }
559
1666
  };
560
- const applyLunoraOverlay = (options) => {
1667
+ const applyLunoraOverlay = async (options) => {
561
1668
  const { adapter, distTag, logger, name, target } = options;
562
1669
  const written = [];
1670
+ writeFile(target, join$1("lunora", "ratelimit", "schema.ts"), RATELIMIT_SCHEMA, written);
563
1671
  writeFile(target, join$1("lunora", "schema.ts"), LUNORA_SCHEMA, written);
564
1672
  writeFile(target, join$1("lunora", "messages.ts"), LUNORA_MESSAGES, written);
565
1673
  writeFile(target, join$1("src", "server.ts"), SERVER_ENTRY, written);
@@ -569,11 +1677,111 @@ const applyLunoraOverlay = (options) => {
569
1677
  writeFile(target, file.path, file.contents, written);
570
1678
  }
571
1679
  patchBaseViteConfig(target, logger);
572
- patchPackageJson(target, name, adapter, distTag);
1680
+ await patchPackageJson(target, name, adapter, distTag);
573
1681
  ensureGitignore(target);
574
1682
  return written;
575
1683
  };
576
1684
 
1685
+ const ADJECTIVES = [
1686
+ "lunar",
1687
+ "silver",
1688
+ "silent",
1689
+ "waning",
1690
+ "waxing",
1691
+ "crescent",
1692
+ "cosmic",
1693
+ "stellar",
1694
+ "orbital",
1695
+ "gibbous",
1696
+ "twilight",
1697
+ "midnight",
1698
+ "shimmering",
1699
+ "drifting",
1700
+ "weightless"
1701
+ ];
1702
+ const NOUNS = [
1703
+ "moon",
1704
+ "tide",
1705
+ "crater",
1706
+ "comet",
1707
+ "eclipse",
1708
+ "halo",
1709
+ "orbit",
1710
+ "nebula",
1711
+ "voyager",
1712
+ "lander",
1713
+ "rover",
1714
+ "beacon",
1715
+ "harbor",
1716
+ "meadow",
1717
+ "fox"
1718
+ ];
1719
+ const pick = (items) => (
1720
+ // eslint-disable-next-line sonarjs/pseudo-random -- cosmetic default project name, not a security decision.
1721
+ items[Math.floor(Math.random() * items.length)]
1722
+ );
1723
+ const generateProjectName = () => `${pick(ADJECTIVES)}-${pick(NOUNS)}`;
1724
+
1725
+ const isOnline = async () => dns.lookup("github.com").then(
1726
+ () => true,
1727
+ () => false
1728
+ );
1729
+ const GITHUB_SOURCE = /^(?:gh|github):([^/]+)\/([^#/]+)(?:\/[^#]*)?(?:#(.+))?$/;
1730
+ const parseGitHubSource = (source) => {
1731
+ const match = GITHUB_SOURCE.exec(source);
1732
+ if (match === null) {
1733
+ return void 0;
1734
+ }
1735
+ const [, owner, repo, ref] = match;
1736
+ if (owner === void 0 || repo === void 0) {
1737
+ return void 0;
1738
+ }
1739
+ return { owner, ref: ref ?? "HEAD", repo };
1740
+ };
1741
+ const templateRefExists = async (source) => {
1742
+ const parsed = parseGitHubSource(source);
1743
+ if (parsed === void 0) {
1744
+ return void 0;
1745
+ }
1746
+ const url = `https://codeload.github.com/${parsed.owner}/${parsed.repo}/tar.gz/${parsed.ref}`;
1747
+ try {
1748
+ const response = await fetch(url, { method: "HEAD" });
1749
+ if (response.status === 404) {
1750
+ return false;
1751
+ }
1752
+ return response.ok ? true : void 0;
1753
+ } catch {
1754
+ return void 0;
1755
+ }
1756
+ };
1757
+ const verifyRemoteTemplate = async (params) => {
1758
+ if (params.isLocal) {
1759
+ return true;
1760
+ }
1761
+ const isGitHubBacked = params.source === void 0 || parseGitHubSource(params.source) !== void 0;
1762
+ if (!isGitHubBacked) {
1763
+ return true;
1764
+ }
1765
+ if (!await isOnline()) {
1766
+ params.logger.error("you appear to be offline — connect to the internet and try again, or scaffold from a local template with `--from <dir>`.");
1767
+ return false;
1768
+ }
1769
+ if (params.source !== void 0 && await templateRefExists(params.source) === false) {
1770
+ params.logger.error(`template source not found: ${params.source} — double-check --ref / --source, or browse the templates at https://lunora.sh/docs.`);
1771
+ return false;
1772
+ }
1773
+ return true;
1774
+ };
1775
+
1776
+ const COPY = {
1777
+ extras: "Let's finish setting up your app.",
1778
+ framework: "Which framework should we launch?",
1779
+ git: "Initialize a new git repository? (optional)",
1780
+ install: "Install dependencies now?",
1781
+ name: "Where should we land your project?",
1782
+ nextHeader: "Liftoff confirmed — explore your project!",
1783
+ packageManager: "Which package manager?"
1784
+ };
577
1785
  const TEXT_EXTENSIONS = /* @__PURE__ */ new Set([".gitignore", ".html", ".js", ".json", ".jsonc", ".md", ".mjs", ".ts", ".tsx"]);
578
1786
  const VITE_CONFIG_CANDIDATES = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"];
579
1787
  const MINIMAL_VITE_CONFIG = `import { defineConfig } from "vite";
@@ -616,7 +1824,27 @@ const isTextFile = (filePath) => {
616
1824
  };
617
1825
  const substitute = (content, name) => content.replaceAll("{{name}}", name);
618
1826
  const isLunoraDep = (name) => name === "lunorash" || name.startsWith("@lunora/");
619
- const stampLunoraDeps = (packageJsonText, distTag) => {
1827
+ const resolveLunoraVersions = async (files, distTag) => {
1828
+ const names = /* @__PURE__ */ new Set();
1829
+ for (const file of files) {
1830
+ if (basename(file) !== "package.json") {
1831
+ continue;
1832
+ }
1833
+ try {
1834
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
1835
+ for (const section of ["dependencies", "devDependencies"]) {
1836
+ for (const name of Object.keys(parsed[section] ?? {})) {
1837
+ if (isLunoraDep(name)) {
1838
+ names.add(name);
1839
+ }
1840
+ }
1841
+ }
1842
+ } catch {
1843
+ }
1844
+ }
1845
+ return resolveTagVersions(names, distTag);
1846
+ };
1847
+ const stampLunoraDeps = (packageJsonText, distTag, versions) => {
620
1848
  let parsed;
621
1849
  try {
622
1850
  parsed = JSON.parse(packageJsonText);
@@ -629,23 +1857,50 @@ const stampLunoraDeps = (packageJsonText, distTag) => {
629
1857
  if (!isLunoraDep(name)) {
630
1858
  continue;
631
1859
  }
632
- const edits = modify(text, [section, name], distTag, { formattingOptions: { insertSpaces: true, tabSize: 4 } });
1860
+ const pin = versions.get(name) ?? distTag;
1861
+ const edits = modify(text, [section, name], pin, { formattingOptions: { insertSpaces: true, tabSize: 4 } });
633
1862
  text = applyEdits(text, edits);
634
1863
  }
635
1864
  }
636
1865
  return text;
637
1866
  };
1867
+ const PNPM_BUILT_DEPENDENCIES = [
1868
+ "@parcel/watcher",
1869
+ "esbuild",
1870
+ "lmdb",
1871
+ "msgpackr-extract",
1872
+ "rs-module-lexer",
1873
+ "sharp",
1874
+ "unrs-resolver",
1875
+ "workerd"
1876
+ ];
1877
+ const PNPM_DENIED_BUILD_DEPENDENCIES = ["cpu-features", "protobufjs", "ssh2"];
1878
+ const PNPM_WORKSPACE_FILENAME = "pnpm-workspace.yaml";
1879
+ const pnpmWorkspaceYaml = () => [
1880
+ "# pnpm reads its settings from here (the package.json `pnpm` field is no longer read).",
1881
+ "# Pre-approve the toolchain's native build scripts so `pnpm install` runs them",
1882
+ "# without the interactive `pnpm approve-builds` step; deny the optional native",
1883
+ "# builds a scaffold doesn't need (so no C/C++ toolchain is required).",
1884
+ "allowBuilds:",
1885
+ ...PNPM_BUILT_DEPENDENCIES.map((name) => ` '${name}': true`),
1886
+ ...PNPM_DENIED_BUILD_DEPENDENCIES.map((name) => ` '${name}': false`),
1887
+ ""
1888
+ ].join("\n");
638
1889
  const collectFiles = (directory) => {
639
1890
  const out = [];
640
1891
  for (const entry of walkSync(directory, { includeDirs: false, includeFiles: true })) {
1892
+ if (lstatSync(entry.path).isSymbolicLink()) {
1893
+ continue;
1894
+ }
641
1895
  out.push(entry.path);
642
1896
  }
643
1897
  return out;
644
1898
  };
645
- const copyTemplate = (sourceDirectory, target, name) => {
1899
+ const copyTemplate = async (sourceDirectory, target, name) => {
646
1900
  const files = collectFiles(sourceDirectory);
647
1901
  const written = [];
648
1902
  const distTag = resolveDistTag();
1903
+ const versions = await resolveLunoraVersions(files, distTag);
649
1904
  for (const source of files) {
650
1905
  const relativePath = relative(sourceDirectory, source);
651
1906
  const destination = join$1(target, relativePath);
@@ -653,7 +1908,7 @@ const copyTemplate = (sourceDirectory, target, name) => {
653
1908
  const raw = readFileSync(source);
654
1909
  let text = isTextFile(source) ? substitute(raw.toString("utf8"), name) : void 0;
655
1910
  if (text !== void 0 && basename(source) === "package.json") {
656
- text = stampLunoraDeps(text, distTag);
1911
+ text = stampLunoraDeps(text, distTag, versions);
657
1912
  }
658
1913
  if (text === void 0) {
659
1914
  writeFileSync(destination, raw);
@@ -676,68 +1931,152 @@ const isSafeSource = (source) => {
676
1931
  }
677
1932
  return source.startsWith("gh:") || source.startsWith("github:") || source.startsWith("https://");
678
1933
  };
1934
+ const logWould = (logger, action) => {
1935
+ logger.info(`[dry-run] would ${action}`);
1936
+ };
679
1937
  const logScaffoldSuccess = (logger, written, target) => {
1938
+ if (isInteractive()) {
1939
+ process.stdout.write("\n");
1940
+ }
680
1941
  logger.success(`scaffolded ${String(written.length)} files into ${target}`);
681
1942
  };
682
- const runScriptCommand = (manager, script) => {
683
- if (manager === "npm") {
684
- return `npm run ${script}`;
1943
+ const installCommand = (manager, packages) => {
1944
+ const verb = manager === "npm" ? "install" : "add";
1945
+ return `${manager} ${verb} ${packages.join(" ")}`;
1946
+ };
1947
+ const isInsideMonorepo = (startDirectory) => {
1948
+ let directory = resolve(startDirectory);
1949
+ for (; ; ) {
1950
+ if (existsSync(join$1(directory, "pnpm-workspace.yaml"))) {
1951
+ return true;
1952
+ }
1953
+ const packagePath = join$1(directory, "package.json");
1954
+ if (existsSync(packagePath)) {
1955
+ try {
1956
+ const parsed = JSON.parse(readFileSync(packagePath, "utf8"));
1957
+ if (parsed.workspaces !== void 0) {
1958
+ return true;
1959
+ }
1960
+ } catch {
1961
+ }
1962
+ }
1963
+ const parent = dirname$1(directory);
1964
+ if (parent === directory) {
1965
+ return false;
1966
+ }
1967
+ directory = parent;
685
1968
  }
686
- if (manager === "bun") {
687
- return `bun run ${script}`;
1969
+ };
1970
+ const isInsideGitRepo = (startDirectory) => {
1971
+ let directory = resolve(startDirectory);
1972
+ for (; ; ) {
1973
+ if (existsSync(join$1(directory, ".git"))) {
1974
+ return true;
1975
+ }
1976
+ const parent = dirname$1(directory);
1977
+ if (parent === directory) {
1978
+ return false;
1979
+ }
1980
+ directory = parent;
688
1981
  }
689
- return `${manager} ${script}`;
690
1982
  };
691
- const printNextSteps = (logger, name, installed) => {
692
- const manager = installed ?? "pnpm";
693
- logger.info("next steps:");
694
- logger.info(` cd ${name}`);
1983
+ const maybeOfferGit = async (options, target) => {
1984
+ if (options.yes === true || !isInteractive() || isInsideGitRepo(dirname$1(target))) {
1985
+ return;
1986
+ }
1987
+ if (!await tuiConfirm(COPY.git, { badge: BADGES.git, defaultYes: false })) {
1988
+ await tuiInfo("Sounds good! You can always run git init manually.");
1989
+ return;
1990
+ }
1991
+ if (options.dryRun === true) {
1992
+ logWould(options.logger, "initialize a git repository");
1993
+ return;
1994
+ }
1995
+ const spawner = options.spawner ?? defaultSpawner;
1996
+ const result = await withTuiSpinner("Initializing a git repository…", () => spawner({ args: ["init"], command: "git", cwd: target }));
1997
+ if (result.code === 0) {
1998
+ await emitStep("git", "Initialized an empty git repository.");
1999
+ } else {
2000
+ options.logger.warn("`git init` failed — initialize it yourself later with `git init`.");
2001
+ }
2002
+ };
2003
+ const printNextSteps = async (name, installed, manager, insideMonorepo) => {
2004
+ const steps = [{ code: `cd ./${name}`, lead: "Enter your project directory using" }];
695
2005
  if (installed === void 0) {
696
- logger.info(` ${manager} install`);
2006
+ steps.push({ code: `${manager} install`, lead: "Install dependencies with", tail: insideMonorepo ? " from the workspace root" : void 0 });
2007
+ }
2008
+ steps.push(
2009
+ { code: runScriptCommand(manager, "dev"), lead: "Run", tail: " to start the dev server." },
2010
+ { code: "lunora add", lead: "Add features like auth or storage using" }
2011
+ );
2012
+ const help = [
2013
+ { code: "https://lunora.sh/docs", lead: "Read the docs at" },
2014
+ { code: "https://lunora.sh/chat", lead: "Stuck? Join the chat at" }
2015
+ ];
2016
+ if (isInteractive()) {
2017
+ await tuiNextSteps(BADGES.next, COPY.nextHeader, steps, help);
2018
+ return;
697
2019
  }
698
- logger.info(` ${runScriptCommand(manager, "dev")}`);
2020
+ const lines = steps.map((step) => `${step.lead} ${step.code}${step.tail ?? ""}`);
2021
+ lines.push("", ...help.map((line) => `${line.lead} ${line.code}${line.tail ?? ""}`));
2022
+ await emitStep("next", COPY.nextHeader, lines.join("\n"));
699
2023
  };
700
2024
  const offerInstallIsInteractive = (options) => options.yes !== true && (options.installPrompt !== void 0 || isInteractive());
701
2025
  const maybeOfferInstall = async (options, target) => {
702
2026
  if (!offerInstallIsInteractive(options)) {
703
2027
  return void 0;
704
2028
  }
2029
+ if (isInsideMonorepo(dirname$1(target))) {
2030
+ return void 0;
2031
+ }
705
2032
  const managers = detectInstalledManagers(options.packageManagerProbe);
706
2033
  const [defaultManager] = managers;
707
2034
  if (defaultManager === void 0) {
708
2035
  return void 0;
709
2036
  }
710
- const confirm = options.installPrompt?.confirmInstall ?? (async () => tuiConfirm("Install dependencies now?", { defaultYes: true }));
2037
+ const confirm = options.installPrompt?.confirmInstall ?? (async () => tuiConfirm(COPY.install, { badge: BADGES.deps, defaultYes: true }));
711
2038
  if (!await confirm()) {
2039
+ await tuiInfo("No problem! Remember to install dependencies after setup.");
712
2040
  return void 0;
713
2041
  }
714
2042
  let manager = defaultManager;
715
2043
  if (managers.length > 1) {
716
2044
  manager = options.installPrompt ? await options.installPrompt.selectManager(managers) : await tuiSelect(
717
- "Which package manager?",
2045
+ COPY.packageManager,
718
2046
  managers.map((candidate) => {
719
2047
  return { label: candidate, value: candidate };
720
2048
  }),
721
- { default: defaultManager }
2049
+ { badge: BADGES.deps, default: defaultManager }
722
2050
  ) ?? defaultManager;
723
2051
  }
2052
+ if (options.dryRun === true) {
2053
+ logWould(options.logger, `install dependencies with ${manager}`);
2054
+ return void 0;
2055
+ }
2056
+ if (manager === "pnpm") {
2057
+ const workspacePath = join$1(target, PNPM_WORKSPACE_FILENAME);
2058
+ if (!existsSync(workspacePath)) {
2059
+ writeFileSync(workspacePath, pnpmWorkspaceYaml(), "utf8");
2060
+ }
2061
+ }
724
2062
  const spawner = options.spawner ?? defaultSpawner;
725
2063
  const { args, command } = installArgsFor(manager);
726
- const result = await withTuiSpinner(`Installing dependencies with ${manager}…`, () => spawner({ args, command, cwd: target }));
2064
+ await emitStep("deps", `Installing dependencies with ${manager}…`);
2065
+ const result = await spawner({ args, command, cwd: target });
727
2066
  if (result.code !== 0) {
728
2067
  options.logger.warn(`\`${command} install\` exited with code ${String(result.code)} — run it yourself in ${basename(target)}/.`);
729
2068
  return void 0;
730
2069
  }
731
- options.logger.success(`installed dependencies with ${manager}`);
2070
+ await emitStep("deps", `Dependencies installed with ${manager}.`);
732
2071
  return manager;
733
2072
  };
734
- const scaffoldFromLocal = (fromRoot, templateType, target, name, logger) => {
2073
+ const scaffoldFromLocal = async (fromRoot, templateType, target, name, logger) => {
735
2074
  const templateDirectory = join$1(fromRoot, templateType);
736
2075
  if (!existsSync(templateDirectory)) {
737
2076
  logger.error(`template not found in local source: ${templateDirectory}`);
738
2077
  return { code: 1, files: [], target };
739
2078
  }
740
- const written = copyTemplate(templateDirectory, target, name);
2079
+ const written = await copyTemplate(templateDirectory, target, name);
741
2080
  logScaffoldSuccess(logger, written, target);
742
2081
  return { code: 0, files: written, target };
743
2082
  };
@@ -746,30 +2085,55 @@ const scaffoldFromRemote = async (options) => {
746
2085
  const stagingRoot = mkdtempSync(join$1(tmpdir(), "lunora-init-fetch-"));
747
2086
  const stagingDirectory = join$1(stagingRoot, "template");
748
2087
  try {
749
- const remote = resolveTemplateSource(templateType, source, ref);
750
- const downloaded = await withTuiSpinner(
751
- `Fetching the ${templateType} template…`,
752
- () => downloadTemplate(remote, {
753
- cwd: stagingRoot,
754
- dir: stagingDirectory,
755
- force: true,
756
- install: false,
757
- silent: true
758
- })
2088
+ const pinnedRef = source !== void 0 && source.length > 0 ? ref : await resolvePinnedSourceRef(ref, logger);
2089
+ const remote = resolveTemplateSource(templateType, source, pinnedRef);
2090
+ let downloaded;
2091
+ let written = [];
2092
+ await tuiTasks(
2093
+ [
2094
+ {
2095
+ label: `${templateType} template fetched`,
2096
+ run: async () => {
2097
+ downloaded = await downloadTemplate(remote, {
2098
+ cwd: stagingRoot,
2099
+ dir: stagingDirectory,
2100
+ force: true,
2101
+ install: false,
2102
+ silent: true
2103
+ });
2104
+ }
2105
+ },
2106
+ {
2107
+ label: `files copied into ${name}/`,
2108
+ run: async () => {
2109
+ written = await copyTemplate(stagingDirectory, target, name);
2110
+ }
2111
+ }
2112
+ ],
2113
+ { end: "Project initialized!", start: "Project initializing…" }
759
2114
  );
760
2115
  const staged = collectFiles(stagingDirectory);
2116
+ if (isInteractive()) {
2117
+ process.stdout.write("\n");
2118
+ }
761
2119
  logger.info(
762
- downloaded.commit ? `template: ${downloaded.source} @ ${downloaded.commit} (${String(staged.length)} files)` : `template: ${downloaded.source} (${String(staged.length)} files)`
763
- );
764
- const written = await withTuiSpinner(
765
- `Scaffolding ${String(staged.length)} files into ${name}/…`,
766
- () => Promise.resolve(copyTemplate(stagingDirectory, target, name))
2120
+ downloaded?.commit ? `template: ${downloaded.source} @ ${downloaded.commit} (${String(staged.length)} files)` : `template: ${downloaded?.source ?? remote} (${String(staged.length)} files)`
767
2121
  );
768
2122
  logScaffoldSuccess(logger, written, target);
769
2123
  return { code: 0, files: written, target };
770
2124
  } catch (error) {
771
- const message = error instanceof Error ? error.message : String(error);
772
- logger.error(`failed to download template: ${message}`);
2125
+ if (error instanceof PromptCancelledError) {
2126
+ throw error;
2127
+ }
2128
+ const { hints, message } = describeDownloadFailure(error, {
2129
+ ref: resolveSourceRef(ref),
2130
+ remote: resolveTemplateSource(templateType, source, ref),
2131
+ templateType
2132
+ });
2133
+ logger.error(message);
2134
+ for (const hint of hints) {
2135
+ logger.warn(hint);
2136
+ }
773
2137
  return { code: 1, files: [], target };
774
2138
  } finally {
775
2139
  rmSync(stagingRoot, { force: true, recursive: true });
@@ -788,30 +2152,44 @@ const scaffoldViteOverlay = async (options) => {
788
2152
  const adapter = ADAPTERS[framework];
789
2153
  const stagingRoot = mkdtempSync(join$1(tmpdir(), "lunora-vite-base-"));
790
2154
  try {
791
- if (overlayBaseFrom === void 0) {
792
- const stagingDirectory = join$1(stagingRoot, "base");
793
- const remote = `github:vitejs/vite/packages/create-vite/template-${adapter.createViteTemplate}#main`;
794
- await withTuiSpinner(
795
- `Fetching the ${adapter.label} (create-vite) base…`,
796
- () => downloadTemplate(remote, { cwd: stagingRoot, dir: stagingDirectory, force: true, install: false, silent: true })
797
- );
798
- renameCreateViteDotfiles(stagingDirectory);
799
- cpSync(stagingDirectory, target, { recursive: true });
800
- } else {
801
- const localBase = join$1(overlayBaseFrom, `template-${adapter.createViteTemplate}`);
2155
+ let localBase;
2156
+ if (overlayBaseFrom !== void 0) {
2157
+ localBase = join$1(overlayBaseFrom, `template-${adapter.createViteTemplate}`);
802
2158
  if (!existsSync(localBase)) {
803
2159
  logger.error(`create-vite base not found on disk: ${localBase}`);
804
2160
  return { code: 1, files: [], target };
805
2161
  }
806
- cpSync(localBase, target, { recursive: true });
807
2162
  }
808
- const written = await withTuiSpinner(
809
- `Applying the Lunora overlay (${adapter.label})…`,
810
- () => Promise.resolve(applyLunoraOverlay({ adapter, distTag: resolveDistTag(), logger, name, target }))
2163
+ const copyBase = async () => {
2164
+ if (localBase !== void 0) {
2165
+ cpSync(localBase, target, { recursive: true });
2166
+ return;
2167
+ }
2168
+ const stagingDirectory = join$1(stagingRoot, "base");
2169
+ const remote = `github:vitejs/vite/packages/create-vite/template-${adapter.createViteTemplate}#main`;
2170
+ await downloadTemplate(remote, { cwd: stagingRoot, dir: stagingDirectory, force: true, install: false, silent: true });
2171
+ renameCreateViteDotfiles(stagingDirectory);
2172
+ cpSync(stagingDirectory, target, { recursive: true });
2173
+ };
2174
+ let written = [];
2175
+ await tuiTasks(
2176
+ [
2177
+ { label: `create-vite (${adapter.label}) base ready`, run: copyBase },
2178
+ {
2179
+ label: `Lunora overlay applied (${adapter.label})`,
2180
+ run: async () => {
2181
+ written = await applyLunoraOverlay({ adapter, distTag: resolveDistTag(), logger, name, target });
2182
+ }
2183
+ }
2184
+ ],
2185
+ { end: "Project initialized!", start: "Project initializing…" }
811
2186
  );
812
2187
  logScaffoldSuccess(logger, written, target);
813
2188
  return { code: 0, files: [...collectFiles(target)], target };
814
2189
  } catch (error) {
2190
+ if (error instanceof PromptCancelledError) {
2191
+ throw error;
2192
+ }
815
2193
  const message = error instanceof Error ? error.message : String(error);
816
2194
  logger.error(`failed to scaffold the ${adapter.label} base: ${message}`);
817
2195
  return { code: 1, files: [], target };
@@ -879,12 +2257,12 @@ const scaffoldLunoraDirectory = (cwd, logger) => {
879
2257
  }
880
2258
  return written;
881
2259
  };
882
- const printFrameworkNextSteps = (detection, logger) => {
2260
+ const printFrameworkNextSteps = (detection, manager, logger) => {
883
2261
  const { adapter, class: frameworkClass, framework } = detection;
884
2262
  logger.info("");
885
2263
  logger.info(`detected framework: ${framework} (class ${frameworkClass})`);
886
2264
  logger.info("next steps:");
887
- logger.info(` 1. install the adapter: pnpm add ${adapter} @lunora/client @lunora/runtime @lunora/server`);
2265
+ logger.info(` 1. install the adapter: ${installCommand(manager, [adapter, "@lunora/client", "@lunora/runtime", "@lunora/server"])}`);
888
2266
  logger.info(" 2. run codegen: lunora codegen");
889
2267
  if (frameworkClass === "A") {
890
2268
  logger.info(" 3. compose one worker: wrap your worker entry with");
@@ -930,48 +2308,77 @@ const runInPlaceInit = (cwd, logger) => {
930
2308
  return viteResult;
931
2309
  }
932
2310
  const scaffolded = scaffoldLunoraDirectory(cwd, logger);
933
- printFrameworkNextSteps(detection, logger);
2311
+ printFrameworkNextSteps(detection, detectPackageManager(cwd), logger);
934
2312
  return { code: 0, files: [...viteResult.files, ...scaffolded], target: cwd };
935
2313
  };
936
2314
  const offerIsInteractive = (options) => options.yes !== true && (options.prompt !== void 0 || (options.interactive ?? isInteractive()));
937
2315
  const maybeOfferExtras = async (options, projectDirectory) => {
938
2316
  const interactive = offerIsInteractive(options);
939
- const apply = async (names) => {
2317
+ const preselected = options.add === void 0 ? [] : parseFeatureList(options.add, (message) => {
2318
+ options.logger.warn(message);
2319
+ });
2320
+ const applyAll = async (plans) => {
2321
+ if (plans.length === 0) {
2322
+ return true;
2323
+ }
2324
+ if (options.dryRun === true) {
2325
+ logWould(options.logger, `add ${plans.map((plan) => plan.label).join(", ")}`);
2326
+ return true;
2327
+ }
2328
+ const buffered = [];
940
2329
  const applyLogger = isInteractive() ? {
941
2330
  error: (message) => {
942
- options.logger.error(message);
2331
+ buffered.push({ level: "error", message });
943
2332
  },
944
2333
  info: () => {
945
2334
  },
946
2335
  success: () => {
947
2336
  },
948
2337
  warn: (message) => {
949
- options.logger.warn(message);
2338
+ buffered.push({ level: "warn", message });
950
2339
  }
951
2340
  } : options.logger;
952
- const result = await withTuiSpinner(
953
- `adding ${names.join(", ")}…`,
954
- () => runAddCommand({
955
- allowUnsafeSource: options.allowUnsafeSource,
956
- cwd: projectDirectory,
957
- from: options.registryFrom,
958
- logger: applyLogger,
959
- names: [...names],
960
- ref: options.ref,
961
- source: options.registrySource,
962
- yes: true
963
- })
964
- );
965
- return result.code === 0;
2341
+ const steps = plans.map((plan) => {
2342
+ return {
2343
+ running: `adding ${plan.label}…`,
2344
+ task: () => runAddCommand({
2345
+ allowUnsafeSource: options.allowUnsafeSource,
2346
+ cwd: projectDirectory,
2347
+ from: options.registryFrom,
2348
+ logger: applyLogger,
2349
+ names: [...plan.names],
2350
+ ref: options.ref,
2351
+ source: options.registrySource,
2352
+ transformManifest: plan.transformManifest,
2353
+ yes: true
2354
+ })
2355
+ };
2356
+ });
2357
+ const done = `added ${plans.map((plan) => plan.label).join(", ")}`;
2358
+ const results = await withTuiBadgeProgress(BADGES.add, steps, done);
2359
+ for (const { level, message } of buffered) {
2360
+ options.logger[level](message);
2361
+ }
2362
+ return results.every((result) => result.code === 0);
966
2363
  };
967
- await tuiIntro("let's finish setting up your app");
968
- await offerRegistryExtras({
969
- apply,
2364
+ const deps = {
2365
+ applyAll,
970
2366
  interactive,
971
2367
  logger: options.logger,
972
- multiSelect: options.prompt?.multiSelect ?? ((message, choices, settings) => tuiMultiSelect(message, choices, settings)),
973
- select: options.prompt?.select ?? ((message, choices, settings) => tuiSelect(message, choices, settings))
974
- });
2368
+ multiSelect: options.prompt?.multiSelect ?? ((message, choices, settings) => tuiMultiSelect(message, choices, { ...settings, badge: BADGES.add })),
2369
+ preselected: preselected.length > 0 ? preselected : void 0,
2370
+ projectName: basename(projectDirectory),
2371
+ select: options.prompt?.select ?? ((message, choices, settings) => tuiSelect(message, choices, { ...settings, badge: BADGES.add })),
2372
+ text: options.prompt?.text ?? ((message, settings) => tuiText(message, { ...settings, badge: BADGES.add }))
2373
+ };
2374
+ if (preselected.length > 0) {
2375
+ await offerRegistryExtras(deps);
2376
+ return;
2377
+ }
2378
+ if (isInteractive()) {
2379
+ await tuiHeadline(COPY.extras);
2380
+ }
2381
+ await offerRegistryExtras(deps);
975
2382
  };
976
2383
  const DEFAULT_FRAMEWORK = "react";
977
2384
  const FRAMEWORK_CHOICES = [
@@ -1001,7 +2408,7 @@ const resolveScaffoldChoice = async (options) => {
1001
2408
  if (!isInteractive() || options.yes === true) {
1002
2409
  return { framework: DEFAULT_FRAMEWORK, kind: "overlay" };
1003
2410
  }
1004
- return toScaffoldChoice(await tuiSelect("Which framework would you like?", FRAMEWORK_CHOICES, { default: DEFAULT_FRAMEWORK }) ?? DEFAULT_FRAMEWORK);
2411
+ return toScaffoldChoice(await tuiSelect(COPY.framework, FRAMEWORK_CHOICES, { badge: BADGES.tmpl, default: DEFAULT_FRAMEWORK }) ?? DEFAULT_FRAMEWORK);
1005
2412
  };
1006
2413
  const nonInteractiveInitError = (options) => {
1007
2414
  if (isInteractive() || options.yes === true) {
@@ -1019,65 +2426,138 @@ const nonInteractiveInitError = (options) => {
1019
2426
  }
1020
2427
  return `lunora init can't prompt in a non-interactive terminal — provide ${missing.join(" and ")}, or pass --yes to accept the defaults.`;
1021
2428
  };
1022
- const scaffoldNewProject = async (options, cwd) => {
1023
- await tuiBanner("realtime backend on Cloudflare Workers + Durable Objects");
2429
+ const scaffoldOverlayPath = async (options, framework, name, target) => {
2430
+ if (!isOverlayFramework(framework)) {
2431
+ options.logger.error(`init: unknown framework "${framework}". Supported overlays: ${Object.keys(ADAPTERS).join(", ")}.`);
2432
+ return { code: 1, files: [], target };
2433
+ }
2434
+ if (!await verifyRemoteTemplate({ isLocal: options.overlayBaseFrom !== void 0, logger: options.logger })) {
2435
+ return { code: 1, files: [], target };
2436
+ }
2437
+ mkdirSync(target, { recursive: true });
2438
+ return scaffoldViteOverlay({ framework, logger: options.logger, name, overlayBaseFrom: options.overlayBaseFrom, target });
2439
+ };
2440
+ const scaffoldTemplatePath = async (options, templateType, name, target) => {
2441
+ if (templateType === "next") {
2442
+ options.logger.warn('template "next" is not yet available — re-run with `--vite react` or `-t standalone`.');
2443
+ return { code: 1, files: [], target };
2444
+ }
2445
+ if (options.from !== void 0) {
2446
+ return await scaffoldFromLocal(options.from, templateType, target, name, options.logger);
2447
+ }
2448
+ if (options.source !== void 0 && options.source.length > 0 && !options.allowUnsafeSource && !isSafeSource(options.source)) {
2449
+ options.logger.error(
2450
+ `init: refusing --source ${options.source} — only gh:, github:, or https:// sources are allowed (and may not contain ".."). Re-run with --allow-unsafe-source if you really want this.`
2451
+ );
2452
+ return { code: 1, files: [], target };
2453
+ }
2454
+ if (!await verifyRemoteTemplate({ isLocal: false, logger: options.logger, source: resolveTemplateSource(templateType, options.source, options.ref) })) {
2455
+ return { code: 1, files: [], target };
2456
+ }
2457
+ return scaffoldFromRemote({ logger: options.logger, name, ref: options.ref, source: options.source, target, templateType });
2458
+ };
2459
+ const scaffoldNewProject = async (options, cwd, recordTarget) => {
2460
+ await tuiMoonrise("realtime backend on Cloudflare Workers + Durable Objects");
1024
2461
  const blocked = nonInteractiveInitError(options);
1025
2462
  if (blocked !== void 0) {
1026
2463
  options.logger.error(blocked);
1027
2464
  return { code: 1, files: [], target: "" };
1028
2465
  }
1029
- const name = options.name ?? await tuiText("What should we call your project?", { default: "lunora-app", placeholder: "lunora-app" });
2466
+ const suggestedName = generateProjectName();
2467
+ const rawName = options.name ?? await tuiText(COPY.name, { badge: BADGES.dir, default: suggestedName, placeholder: suggestedName });
1030
2468
  const choice = await resolveScaffoldChoice(options);
2469
+ const name = rawName.trim();
2470
+ if (name.length === 0) {
2471
+ options.logger.error(`init: refusing an empty project name — pass a directory name (e.g. \`lunora init my-app\`).`);
2472
+ return { code: 1, files: [], target: "" };
2473
+ }
1031
2474
  if (name.includes("/") || name.includes("\\") || name === ".." || name === ".") {
1032
2475
  options.logger.error(`init: refusing project name "${name}" — must not contain path separators or be "." / "..".`);
1033
2476
  return { code: 1, files: [], target: "" };
1034
2477
  }
1035
2478
  const target = resolve(cwd, name);
1036
- if (existsSync(target)) {
2479
+ const targetPreExisted = existsSync(target);
2480
+ if (targetPreExisted) {
1037
2481
  const entries = readdirSync(target);
1038
2482
  if (entries.length > 0) {
1039
2483
  options.logger.error(`target directory not empty: ${target}`);
1040
2484
  return { code: 1, files: [], target };
1041
2485
  }
1042
2486
  }
1043
- if (choice.kind === "overlay") {
1044
- if (!isOverlayFramework(choice.framework)) {
1045
- options.logger.error(`init: unknown framework "${choice.framework}". Supported overlays: ${Object.keys(ADAPTERS).join(", ")}.`);
1046
- return { code: 1, files: [], target };
2487
+ if (options.dryRun === true) {
2488
+ const what = choice.kind === "overlay" ? `the ${choice.framework} create-vite overlay` : `the ${choice.templateType} template`;
2489
+ logWould(options.logger, `scaffold ${what} into ${target}`);
2490
+ return { code: 0, files: [], target };
2491
+ }
2492
+ recordTarget(target, targetPreExisted);
2493
+ return choice.kind === "overlay" ? scaffoldOverlayPath(options, choice.framework, name, target) : scaffoldTemplatePath(options, choice.templateType, name, target);
2494
+ };
2495
+ const resetScaffoldOnCancel = (cleanup, logger) => {
2496
+ const { target, targetPreExisted } = cleanup;
2497
+ if (target === void 0 || !existsSync(target)) {
2498
+ return;
2499
+ }
2500
+ if (targetPreExisted === true) {
2501
+ for (const entry of readdirSync(target)) {
2502
+ rmSync(join$1(target, entry), { force: true, recursive: true });
1047
2503
  }
1048
- mkdirSync(target, { recursive: true });
1049
- return scaffoldViteOverlay({ framework: choice.framework, logger: options.logger, name, overlayBaseFrom: options.overlayBaseFrom, target });
2504
+ } else {
2505
+ rmSync(target, { force: true, recursive: true });
1050
2506
  }
1051
- const { templateType } = choice;
1052
- if (templateType === "next") {
1053
- options.logger.warn('template "next" is not yet available re-run with `--vite react` or `-t standalone`.');
1054
- return { code: 1, files: [], target };
2507
+ logger.info(`removed the partially-created project at ${target}`);
2508
+ };
2509
+ const runScaffoldStep = async (options, cwd, recordTarget) => {
2510
+ if (options.inPlace !== true) {
2511
+ return scaffoldNewProject(options, cwd, recordTarget);
1055
2512
  }
1056
- if (options.from !== void 0) {
1057
- return scaffoldFromLocal(options.from, templateType, target, name, options.logger);
2513
+ if (options.dryRun === true) {
2514
+ logWould(options.logger, `configure Lunora into ${cwd}`);
2515
+ return { code: 0, files: [], target: cwd };
1058
2516
  }
1059
- if (options.source !== void 0 && options.source.length > 0 && !options.allowUnsafeSource && !isSafeSource(options.source)) {
1060
- options.logger.error(
1061
- `init: refusing --source ${options.source} — only gh:, github:, or https:// sources are allowed (and may not contain ".."). Re-run with --allow-unsafe-source if you really want this.`
1062
- );
1063
- return { code: 1, files: [], target };
2517
+ return runInPlaceInit(cwd, options.logger);
2518
+ };
2519
+ const runPostScaffold = async (options, result, cwd) => {
2520
+ await maybeOfferExtras(options, result.target);
2521
+ const installedManager = options.inPlace === true ? void 0 : await maybeOfferInstall(options, result.target);
2522
+ if (options.inPlace !== true) {
2523
+ await maybeOfferGit(options, result.target);
2524
+ const manager = installedManager ?? detectPackageManager(result.target);
2525
+ await printNextSteps(basename(result.target), installedManager, manager, isInsideMonorepo(cwd));
2526
+ await emitMascot(options.logger);
1064
2527
  }
1065
- return scaffoldFromRemote({ logger: options.logger, name, ref: options.ref, source: options.source, target, templateType });
2528
+ };
2529
+ const scaffoldCiPipeline = (options, result, cwd) => {
2530
+ if (result.code !== 0 || options.ci === void 0) {
2531
+ return;
2532
+ }
2533
+ if (options.dryRun === true) {
2534
+ logWould(options.logger, `scaffold a ${options.ci} CI deploy pipeline`);
2535
+ return;
2536
+ }
2537
+ scaffoldCiWorkflow(options.inPlace === true ? cwd : result.target, options.ci, options.logger);
1066
2538
  };
1067
2539
  const runInitCommand = async (options) => {
1068
2540
  const cwd = options.cwd ?? process.cwd();
1069
- const result = options.inPlace === true ? runInPlaceInit(cwd, options.logger) : await scaffoldNewProject(options, cwd);
1070
- if (result.code === 0 && result.target !== "") {
1071
- await maybeOfferExtras(options, result.target);
1072
- const installedManager = options.inPlace === true ? void 0 : await maybeOfferInstall(options, result.target);
1073
- if (options.inPlace !== true) {
1074
- await tuiOutro("you're all set 🎉");
1075
- printNextSteps(options.logger, basename(result.target), installedManager);
2541
+ const cleanup = {};
2542
+ let result;
2543
+ try {
2544
+ result = await runScaffoldStep(options, cwd, (target, preExisted) => {
2545
+ cleanup.target = target;
2546
+ cleanup.targetPreExisted = preExisted;
2547
+ });
2548
+ if (result.code === 0 && result.target !== "") {
2549
+ cleanup.target = void 0;
2550
+ await runPostScaffold(options, result, cwd);
1076
2551
  }
2552
+ } catch (error) {
2553
+ if (error instanceof PromptCancelledError) {
2554
+ resetScaffoldOnCancel(cleanup, options.logger);
2555
+ process.stdout.write("\n ✖ Setup cancelled — run `lunora init` again whenever you're ready. 🌙\n");
2556
+ return { code: 130, files: [], target: "" };
2557
+ }
2558
+ throw error;
1077
2559
  }
1078
- if (result.code === 0 && options.ci !== void 0) {
1079
- scaffoldCiWorkflow(options.inPlace === true ? cwd : result.target, options.ci, options.logger);
1080
- }
2560
+ scaffoldCiPipeline(options, result, cwd);
1081
2561
  return result;
1082
2562
  };
1083
2563
  const isTemplate = (value) => value === "analog" || value === "astro" || value === "next" || value === "nuxt" || value === "react-router" || value === "standalone" || value === "sveltekit" || value === "tanstack-start-react" || value === "tanstack-start-solid";
@@ -1094,9 +2574,11 @@ const resolveCiProvider = (raw, logger) => {
1094
2574
  const execute = defineHandler(({ argument, cwd, logger, options }) => {
1095
2575
  const templateType = options.template !== void 0 && isTemplate(options.template) ? options.template : void 0;
1096
2576
  return runInitCommand({
2577
+ add: options.add,
1097
2578
  allowUnsafeSource: options.allowUnsafeSource === true,
1098
2579
  cwd,
1099
2580
  ci: resolveCiProvider(options.ci, logger),
2581
+ dryRun: options.dryRun === true,
1100
2582
  from: options.from,
1101
2583
  inPlace: options.here === true,
1102
2584
  interactive: options.interactive === true ? true : void 0,