@lunora/cli 1.0.0-alpha.45 → 1.0.0-alpha.450

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 (141) hide show
  1. package/LICENSE.md +33 -0
  2. package/README.md +3 -1
  3. package/dist/bin.mjs +3 -10
  4. package/dist/cli.d.mts +31 -0
  5. package/dist/cli.d.ts +31 -0
  6. package/dist/cli.mjs +1 -0
  7. package/dist/index.d.mts +1096 -386
  8. package/dist/index.d.ts +1096 -386
  9. package/dist/index.mjs +1 -19
  10. package/dist/packem_chunks/cli.mjs +2 -0
  11. package/dist/packem_chunks/dispatch.mjs +1 -0
  12. package/dist/packem_chunks/handler.mjs +17 -158
  13. package/dist/packem_chunks/handler10.mjs +1 -16
  14. package/dist/packem_chunks/handler11.mjs +1 -22
  15. package/dist/packem_chunks/handler12.mjs +1 -192
  16. package/dist/packem_chunks/handler13.mjs +1 -131
  17. package/dist/packem_chunks/handler14.mjs +3 -65
  18. package/dist/packem_chunks/handler15.mjs +1 -58
  19. package/dist/packem_chunks/handler16.mjs +1 -80
  20. package/dist/packem_chunks/handler17.mjs +1 -43
  21. package/dist/packem_chunks/handler18.mjs +1 -105
  22. package/dist/packem_chunks/handler19.mjs +7 -170
  23. package/dist/packem_chunks/handler2.mjs +1 -114
  24. package/dist/packem_chunks/handler20.mjs +2 -94
  25. package/dist/packem_chunks/handler21.mjs +1 -94
  26. package/dist/packem_chunks/handler22.mjs +3 -0
  27. package/dist/packem_chunks/handler23.mjs +3 -0
  28. package/dist/packem_chunks/handler24.mjs +1 -0
  29. package/dist/packem_chunks/handler25.mjs +2 -0
  30. package/dist/packem_chunks/handler26.mjs +1 -0
  31. package/dist/packem_chunks/handler27.mjs +99 -0
  32. package/dist/packem_chunks/handler28.mjs +15 -0
  33. package/dist/packem_chunks/handler29.mjs +1 -0
  34. package/dist/packem_chunks/handler3.mjs +1 -204
  35. package/dist/packem_chunks/handler4.mjs +1 -33
  36. package/dist/packem_chunks/handler5.mjs +3 -49
  37. package/dist/packem_chunks/handler6.mjs +1 -91
  38. package/dist/packem_chunks/handler7.mjs +1 -42
  39. package/dist/packem_chunks/handler8.mjs +1 -174
  40. package/dist/packem_chunks/handler9.mjs +2 -315
  41. package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
  42. package/dist/packem_chunks/runDevCommand.mjs +6 -0
  43. package/dist/packem_chunks/runInitCommand.mjs +212 -1432
  44. package/dist/packem_chunks/runResetCommand.mjs +1 -41
  45. package/dist/packem_chunks/runRpcCommand.mjs +1 -68
  46. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-5xxKz-zB.mjs +1 -0
  47. package/dist/packem_shared/EXIT_CODE-DVjUgIaG.mjs +1 -0
  48. package/dist/packem_shared/admin-token-VdUnvnKW.mjs +1 -0
  49. package/dist/packem_shared/admin-url-DJB8P6Jh.mjs +1 -0
  50. package/dist/packem_shared/api-spec-lYyq4vL6.mjs +1 -0
  51. package/dist/packem_shared/binding-manifest-file-CQ1eQYy1.mjs +2 -0
  52. package/dist/packem_shared/buildRegistryIndex-Dc8D8AR6.mjs +1 -0
  53. package/dist/packem_shared/cap-error-body-YBKO32BF.mjs +1 -0
  54. package/dist/packem_shared/catalog-CahzmDLV.mjs +1 -0
  55. package/dist/packem_shared/cli-manifest-DoQ_3bzs.mjs +1 -0
  56. package/dist/packem_shared/cloudflare-credentials-BVmZnDZk.mjs +1 -0
  57. package/dist/packem_shared/codegen-error-AmH54ofi.mjs +3 -0
  58. package/dist/packem_shared/command-B6vu47iR.mjs +1 -0
  59. package/dist/packem_shared/commands-DC3ZX1yk.mjs +13 -0
  60. package/dist/packem_shared/createLogger-4TujevyB.mjs +2 -0
  61. package/dist/packem_shared/createRecordingSpawner-01ZngIwK.mjs +1 -0
  62. package/dist/packem_shared/deploy-target-resolve-BTCW1Iv4.mjs +1 -0
  63. package/dist/packem_shared/diffSnapshots-htqNZT8Q.mjs +7 -0
  64. package/dist/packem_shared/docker-DpVxvYpL.mjs +1 -0
  65. package/dist/packem_shared/free-port-DjbFhaaT.mjs +1 -0
  66. package/dist/packem_shared/health-probe-Bw9JFfIy.mjs +1 -0
  67. package/dist/packem_shared/import-DoAUdyfU.mjs +13 -0
  68. package/dist/packem_shared/index-oHZBGBwB.mjs +1 -0
  69. package/dist/packem_shared/insertSchemaExtension-CbTH3lCQ.mjs +10 -0
  70. package/dist/packem_shared/lint-ignore-report-DKZagpqk.mjs +2 -0
  71. package/dist/packem_shared/mcp-config-file-GR1Y_CVw.mjs +2 -0
  72. package/dist/packem_shared/open-url-EnKy--w-.mjs +1 -0
  73. package/dist/packem_shared/output-format-DWe_tkTR.mjs +2 -0
  74. package/dist/packem_shared/parseManifest-CwPTKdtS.mjs +1 -0
  75. package/dist/packem_shared/path-containment-CgxYZggb.mjs +1 -0
  76. package/dist/packem_shared/plan-BH4ZfiFs.mjs +5 -0
  77. package/dist/packem_shared/planDevCommand-I8-NB_CN.mjs +1 -0
  78. package/dist/packem_shared/platform-diagnostics-Cn2g6Jh-.mjs +4 -0
  79. package/dist/packem_shared/prompt-cancelled-BvsNxg_Q.mjs +1 -0
  80. package/dist/packem_shared/render-lunora-error-DUo0pA61.mjs +2 -0
  81. package/dist/packem_shared/resolve-Bdc9KEUv.mjs +5 -0
  82. package/dist/packem_shared/resolve-target-C_ZloTvd.mjs +1 -0
  83. package/dist/packem_shared/runAddCommand-CTblwN9O.mjs +1 -0
  84. package/dist/packem_shared/runDeployCommand-C5L6ZhGV.mjs +1 -0
  85. package/dist/packem_shared/runExportCommand-DiMCQ-Il.mjs +5 -0
  86. package/dist/packem_shared/runMigrateGenerateCommand-Bd2W9t1k.mjs +11 -0
  87. package/dist/packem_shared/schemaIrToSnapshot-BHuNOfgs.mjs +1 -0
  88. package/dist/packem_shared/shared-D-zCOmgY.mjs +1 -0
  89. package/dist/packem_shared/storage-BLLoZRJa.mjs +1 -0
  90. package/dist/packem_shared/tui-prompts-B3YwUhGw.mjs +4 -0
  91. package/dist/packem_shared/variables-CPYyJtsL.mjs +1 -0
  92. package/dist/packem_shared/vectorize-metadata-DOB1akh6.mjs +2 -0
  93. package/dist/packem_shared/wrangler-name-Dsk5K1f-.mjs +1 -0
  94. package/dist/packem_shared/wrangler-secrets-DlSlWvRH.mjs +1 -0
  95. package/package.json +43 -19
  96. package/skills/README.md +36 -17
  97. package/skills/lunora/SKILL.md +158 -65
  98. package/skills/lunora-cloudflare-audit/SKILL.md +163 -0
  99. package/skills/lunora-create-package/SKILL.md +97 -84
  100. package/skills/lunora-deploy/SKILL.md +175 -105
  101. package/skills/lunora-functions/SKILL.md +367 -60
  102. package/skills/lunora-migration-helper/SKILL.md +168 -137
  103. package/skills/lunora-performance-audit/SKILL.md +137 -95
  104. package/skills/lunora-quickstart/SKILL.md +136 -136
  105. package/skills/lunora-realtime/SKILL.md +217 -97
  106. package/skills/lunora-setup-auth/SKILL.md +203 -101
  107. package/skills/lunora-setup-hyperdrive/SKILL.md +138 -109
  108. package/skills/lunora-setup-hyperdrive-global/SKILL.md +125 -92
  109. package/skills/lunora-setup-mail/SKILL.md +85 -113
  110. package/skills/lunora-setup-scheduler/SKILL.md +132 -96
  111. package/skills/lunora-setup-storage/SKILL.md +189 -95
  112. package/dist/packem_chunks/planDevCommand.mjs +0 -541
  113. package/dist/packem_chunks/runDeployCommand.mjs +0 -594
  114. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +0 -397
  115. package/dist/packem_shared/COMMANDS-B0ftFD_3.mjs +0 -948
  116. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
  117. package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
  118. package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
  119. package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
  120. package/dist/packem_shared/codegen-error-DJG-ghs_.mjs +0 -31
  121. package/dist/packem_shared/command-D3lB_4Az.mjs +0 -19
  122. package/dist/packem_shared/commands-B-gR09Z_.mjs +0 -845
  123. package/dist/packem_shared/createLogger-B40gPzQo.mjs +0 -78
  124. package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +0 -43
  125. package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
  126. package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +0 -161
  127. package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
  128. package/dist/packem_shared/insertSchemaExtension-DAqbfr9Z.mjs +0 -64
  129. package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
  130. package/dist/packem_shared/output-format-wUvAN6AL.mjs +0 -17
  131. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
  132. package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
  133. package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +0 -9
  134. package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
  135. package/dist/packem_shared/runAddCommand-bnY6-HKb.mjs +0 -4
  136. package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
  137. package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +0 -43
  138. package/dist/packem_shared/storage-BIsph-Vk.mjs +0 -84
  139. package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +0 -658
  140. package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
  141. package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +0 -47
@@ -0,0 +1,5 @@
1
+ import{existsSync as q,mkdirSync as Te,openSync as J,closeSync as X,statSync as Pe,readFileSync as Q,readSync as be}from"node:fs";import{join as N,dirname as _e}from"node:path";import{readServiceBindings as $e}from"@lunora/codegen";import{readLiveDevServerState as C,discoverContainerInfo as Re,streamContainerLogs as Ne,formatLunoraEvent as Ce,updateDevServerState as b,resolveLazyFunctions as Z,targetRunsOwnDevServer as D,resolveProjectTarget as ee,claimDevServerState as De,DEV_HANDOFF_ENV as Oe,clearDevServerState as E,readDevServerState as O,isDevServerReady as j,detectFramework as re,readProjectDependencyNames as xe,DEV_LOG_FILE_ENV as Ae,DEV_DAEMON_ENV as Me,LAZY_FUNCTIONS_ENV as Ue,readProjectManifest as Ge,isRecordedProcessCurrent as Fe,DEV_LOG_FILE as je,CODEGEN_ENV as te,isCodegenDisabled as Ve,planToolchainInvocation as We,startCelldDevSession as Be,resolveDeployDriver as ne,DEV_VARS_FILE as oe,parseDevVariableEntries as Ke}from"@lunora/config";import{warnCloudflareCliConfigOnce as ze,findWranglerFile as L,readWranglerJsonc as x,materializeDevWranglerConfig as He,materializeServiceDevConfigs as Ye}from"@lunora/config/cloudflare";import{f as qe}from"./free-port-DjbFhaaT.mjs";import{networkInterfaces as Je}from"node:os";import{spawn as ie,spawnSync as T}from"node:child_process";import{setTimeout as w}from"node:timers/promises";import{EXIT_CODE as se}from"./EXIT_CODE-DVjUgIaG.mjs";import{a as h}from"./output-format-DWe_tkTR.mjs";import{spawnShellCompat as ae,defaultSpawner as Xe}from"./createRecordingSpawner-01ZngIwK.mjs";import{isLunoraError as Qe}from"@lunora/errors";import{s as V}from"./index-oHZBGBwB.mjs";import{createInterface as Ze}from"node:readline";import{detectPackageManager as A,execArgsFor as ce,toolchainExecArgs as le,runScriptCommand as er}from"@lunora/config/cli";const rr=12e4,_=250,tr=1e3,nr="LUNORA_DEV_READY_TIMEOUT_MS",or=e=>{if(e!==void 0)return e;const r=Number(process.env[nr]??"");return Number.isFinite(r)&&r>0?r:rr},ir=async(e,r)=>{try{const n=AbortSignal.timeout(tr);return await(await fetch(new URL("/_lunora/status",e),{redirect:"manual",signal:r===void 0?n:AbortSignal.any([r,n])})).body?.cancel(),!0}catch{return!1}},de=async(e,r,n)=>{const t=Date.now()+n.timeoutMs;for(;n.signal?.aborted!==!0;){const o=r(C(e));if(o!==void 0)return o;if(Date.now()>=t)return;try{await w(n.intervalMs??500,void 0,{signal:n.signal})}catch{return}}},W=(e,r)=>{Ze({crlfDelay:Number.POSITIVE_INFINITY,input:e}).on("line",r)},sr=5e3,ue=(e,r,n,t)=>{if(e.length===0)return;const o=Ce(e);if(o){t[o.level](`[lunora] ${o.text}`);return}const i=`[${r}] ${e}`;n==="stderr"?t.warn(i):t.info(i)},ar=(e,r,n=process.platform,t=T)=>{try{if(r==="SIGKILL"&&n==="win32"&&e.pid!==void 0){t("taskkill",["/pid",String(e.pid),"/T","/F"],{stdio:"ignore"});return}e.kill(r)}catch{}},fe=(e,r,n)=>{const t=e.direct===!0?{args:[...e.args],command:e.command,shell:!1}:ae(e.command,e.args),o=ie(t.command,t.args,{cwd:e.cwd??process.cwd(),env:e.env?{...process.env,...e.env}:process.env,shell:t.shell,stdio:[e.direct===!0?"ignore":"inherit","pipe","pipe"]});return W(o.stdout,i=>{r(i,"stdout")}),W(o.stderr,i=>{r(i,"stderr")}),{exited:new Promise(i=>{o.on("error",s=>{n?.(s),i(1)}),o.on("exit",(s,a)=>{i(s??(a?1:0))})}),kill:i=>{ar(o,i)}}},vt=(e,r)=>fe(e,(n,t)=>{ue(n.trimEnd(),e.tag,t,r)},n=>{r.error(`[${e.tag}] failed to start: ${n.message}`)}),gt=(e,r)=>{if(process.env.LUNORA_CONTAINER_LOGS==="0")return;const t=Re(e,"lunora").containers.map(o=>({className:o.className,exportName:o.exportName}));if(t.length!==0)return Ne({containers:t,onLine:o=>{const i=`[container:${o.name}] ${o.text}`;o.level==="error"?r.warn(i):r.info(i)},onUnavailable:o=>{r.warn(`[container] Docker engine unreachable — container logs unavailable (${o})`)}})},pt=async e=>{e.readyProbe?.abort(),await e.tunnel?.close(),await e.codegen?.close().catch(()=>{}),e.containerLogs?.close(),await e.studio?.close().catch(()=>{}),await e.hyperdrive?.stop().catch(()=>{});try{e.remoteCleanup?.(),e.serviceConfigCleanup?.()}catch{}},mt=async e=>await new Promise(r=>{const n={},t=s=>{e.info(`received ${s} — shutting down`),n.sigint&&process.off("SIGINT",n.sigint),n.sigterm&&process.off("SIGTERM",n.sigterm),r(0)},o=()=>{t("SIGINT")},i=()=>{t("SIGTERM")};n.sigint=o,n.sigterm=i,process.on("SIGINT",o),process.on("SIGTERM",i)}),wt=async(e,r,n)=>{let t=0,o;const i=l=>{e.kill(l),r?.kill(l)},s=()=>{t+=1,t===1?(n.info("received SIGINT — shutting down (press Ctrl-C again to force-kill)"),i("SIGTERM"),o=setTimeout(()=>{i("SIGKILL")},sr),o.unref()):i("SIGKILL")},a=()=>{i("SIGTERM")};process.on("SIGINT",s),process.on("SIGTERM",a);const c=await Promise.race([e.exited.then(l=>({code:l,who:"worker"})),...r===void 0?[]:[r.exited.then(l=>({code:l,who:"sidecar"}))]]);return r!==void 0&&(c.who==="sidecar"?(n.warn("[worker] the Lunora sidecar (wrangler dev) exited — shutting down the framework dev server"),e.kill("SIGTERM")):r.kill("SIGTERM"),await Promise.allSettled([e.exited,r.exited])),o&&clearTimeout(o),process.off("SIGINT",s),process.off("SIGTERM",a),c.code},y="2026.9.3",cr="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/",lr=/version (\S+)/u,B=/https:\/\/[\da-z-]+\.trycloudflare\.com/u,dr="1s",ur=5e3,K=async(e,r)=>await Promise.race([e.then(()=>!0),w(r,!1,{ref:!1})]),fr=6e4,vr='Vite answers 403 for hosts it does not know — add `server: { allowedHosts: [".trycloudflare.com"] }` to vite.config if the URL is blocked.',gr=async e=>{const r=`Install or update it: ${cr} (macOS: \`brew install cloudflared\`).`;let n;try{const o=await e({args:["--version"],captureStdoutSilently:!0,command:"cloudflared"});if(o.code!==0)return{message:`\`cloudflared --version\` exited ${String(o.code)}. ${r}`,ok:!1};n=o.stdout??""}catch(o){return Qe(o)&&o.code==="LOCAL_DEPENDENCY_MISSING"?{message:`--tunnel needs \`cloudflared\` ${y} or newer, and it is not on your PATH. ${r}`,ok:!1}:{message:`\`cloudflared --version\` could not run: ${o instanceof Error?o.message:String(o)}. ${r}`,ok:!1}}const t=V.coerce(lr.exec(n)?.[1])?.version;return t===void 0?{ok:!0,version:void 0}:V.gte(t,y)?{ok:!0,version:t}:{message:`--tunnel needs \`cloudflared\` ${y} or newer (protected quick tunnels); found ${t}. ${r}`,ok:!1}},pr=e=>{const r=[],n=[];for(const t of e??[]){const o=t.split(",").map(i=>i.trim()).filter(i=>i.length>0);o.length>0&&(n.push(...o.filter(i=>!i.includes("@"))),r.push(o.join(",")))}return{entries:r,invalid:n}},mr=(e,r)=>["tunnel","--url",e,"--output","json","--grace-period",dr,...r.flatMap(n=>["--allowed-mail",n])],wr=e=>{let r;try{r=JSON.parse(e)}catch{r=void 0}if(typeof r=="object"&&r!==null){const n=r,t=typeof n.message=="string"?n.message:"";return{level:typeof n.level=="string"?n.level:void 0,text:t,url:B.exec(t)?.[0]}}return{level:void 0,text:e,url:B.exec(e)?.[0]}},hr=e=>{e.warn(" ⚠ PUBLIC TUNNEL: anyone with the tunnel URL can reach this dev server — there is no sign-in in front of it."),e.warn(" Protect it with a one-time-PIN email allow-list: lunora dev --tunnel --allow-mail you@example.com"),e.warn(" (repeat --allow-mail, pass a comma-separated list, or allow a whole domain with '*@example.com')")},Sr=async(e,r,n,{intervalMs:t,timeoutMs:o=fr}={})=>{const i=await de(e,s=>s?.mode==="vite"?{origin:s.url,ownerPid:s.pid}:void 0,{intervalMs:t,signal:n,timeoutMs:o});return i===void 0&&!n.aborted&&r.warn(`--tunnel: the Vite dev server did not report its URL within ${String(o/1e3)}s — continuing without a tunnel.`),i},kr=e=>{const{allowMail:r,cwd:n,logger:t}=e,o=r.length===0,i=new AbortController,{signal:s}=i,a=()=>s.aborted,c=e.closeTimeoutMs??ur;let l;const d=()=>{i.abort()};process.once("SIGINT",d),process.once("SIGTERM",d);const p=(async()=>{const u=await gr(e.spawner??Xe);if(!u.ok){t.error(u.message),t.warn("continuing without a tunnel.");return}u.version===void 0&&t.warn(`could not read the cloudflared version — --tunnel needs ${y} or newer; trying anyway.`);const v=e.origin.kind==="fixed"?{origin:e.origin.origin,ownerPid:process.pid}:await Sr(n,t,s);if(v===void 0||s.aborted)return;o&&hr(t),t.info(`starting a Cloudflare quick tunnel to ${v.origin}${o?"":" (email one-time-PIN protected)"}…`);let S;const U={failedToStart:!1},Le=k=>{if(k.length===0)return;const g=wr(k);if(g.url!==void 0&&S===void 0){S=g.url,t.success(` ➜ Tunnel: ${g.url}${o?" (PUBLIC)":""}`),o||t.info(` Allowed: ${r.join(", ")} — visitors confirm with a one-time PIN; a session lasts up to 4 hours`),e.origin.kind==="vite"&&t.info(` ${vr}`),b(n,{tunnelUrl:g.url},{expectedPid:v.ownerPid});return}g.level==="error"||g.level==="fatal"?t.warn(`[cloudflared] ${g.text}`):t.debug?.(`[cloudflared] ${g.text}`)},P=(e.startChild??fe)({args:mr(v.origin,r),command:"cloudflared",direct:!0},Le,k=>{U.failedToStart=!0,t.error(`could not start cloudflared (${k.message}) — continuing without a tunnel.`)});l=P;const G=()=>{P.kill("SIGTERM")};s.addEventListener("abort",G,{once:!0});const F=await P.exited;s.removeEventListener("abort",G),l=void 0,S!==void 0&&b(n,{tunnelUrl:void 0},{expectedPid:v.ownerPid}),!(a()||U.failedToStart)&&t.warn(S===void 0?`cloudflared exited (${String(F)}) before a tunnel URL was assigned — continuing without a tunnel.`:`cloudflared exited (${String(F)}) — the tunnel is closed; the dev server keeps running.`)})().catch(u=>{t.error(`--tunnel failed (${u instanceof Error?u.message:String(u)}) — continuing without a tunnel.`)});return{close:async()=>{if(process.off("SIGINT",d),process.off("SIGTERM",d),i.abort(),await K(p,c))return;const u=l;u!==void 0&&(t.warn(`cloudflared did not exit within ${String(c/1e3)}s of SIGTERM — force-killing it.`),u.kill("SIGKILL"),!await K(u.exited,c)&&t.error(`could not confirm that cloudflared stopped — ${o?"the PUBLIC tunnel":"the tunnel"} may still be reachable. Stop the \`cloudflared\` process manually.`))}}},ht=e=>{const{cwd:r,logger:n,plan:t,tunnel:o}=e;if(o!==void 0)return kr({allowMail:o.allowMail,cwd:r,logger:n,origin:t.flavor==="wrangler"?{kind:"fixed",origin:t.workerOrigin}:{kind:"vite"},spawner:o.spawner,startChild:o.startChild})},Ir=(e,r)=>{const n=["dev"];if(e.apiSpec!==void 0&&n.push("--api-spec",e.apiSpec),Z(e.lazyFunctions)&&n.push("--lazy-functions"),e.port!==void 0&&n.push("--port",String(e.port)),e.workerPort!==void 0&&n.push("--worker-port",String(e.workerPort)),e.inspectorPort!==void 0&&n.push("--inspector-port",String(e.inspectorPort)),e.emitBindings!==void 0&&n.push("--emit-bindings",e.emitBindings),e.codegen===!1&&n.push("--no-codegen"),e.studio===!1&&n.push("--no-studio"),e.worker===!1&&n.push("--no-worker"),e.target!==void 0&&n.push("--target",e.target),e.tunnel===!0){n.push("--tunnel");for(const t of pr(e.allowMail).entries)n.push("--allow-mail",t)}return r&&n.push("--remote"),e.local===!0&&n.push("--local"),n},yr=1e4,Er=100,Lr=40,I=256*1024,Tr=new Set(["nuxt","sveltekit"]),Pr=["@lunora/rspack","@lunora/vite"],M=e=>{if(Tr.has(re(e).framework))return"framework-worker";const r=xe(e);return Pr.some(n=>r.has(n))?"vite":"wrangler"},ve=e=>{const r=A(e),n=Ge(e)?.scripts,t=typeof n=="object"&&n!==null?n.dev:void 0;if(typeof t!="string"||t.trim()===""||t.includes("lunora")){const o=ce(r,"vite",["dev"]);return{args:o.args,command:o.command}}return{args:["run","dev"],command:r}},br=e=>{Te(_e(e.logPath),{recursive:!0});const r=J(e.logPath,"w",384);let n;const t=ae(e.command,e.args);try{n=ie(t.command,t.args,{cwd:e.cwd,detached:!0,env:e.env,shell:t.shell,stdio:["ignore",r,r],windowsHide:!0})}finally{X(r)}return n.unref(),{exited:new Promise(o=>{n.on("error",()=>{o(1)}),n.on("exit",(i,s)=>{o(i??(s?1:0))})}),pid:n.pid}},_r=e=>{try{const{size:r}=Pe(e);if(r<=I)return Q(e,"utf8");const n=J(e,"r");try{const t=Buffer.alloc(I),o=be(n,t,0,I,r-I),i=t.toString("utf8",0,o);return i.slice(i.indexOf(`
2
+ `)+1)}finally{X(n)}}catch{return}},ge=(e,r)=>{const n=_r(e);if(n===void 0)return[];const t=n.split(`
3
+ `);return t.at(-1)===""&&t.pop(),r>0?t.slice(-r):t},pe=(e,r)=>r?.logFile??N(e,je),me=e=>{e.info(" Stop: lunora dev stop"),e.info(" Status: lunora dev status"),e.info(" Logs: lunora dev logs")},$r=(e,r)=>{ze(r,n=>{e.warn(n)})},Rr=(e,r)=>{e.warn(`Dev server already running at ${r.url} (pid ${String(r.pid)})`),me(e)},Nr=(e,r)=>{e.success(`Dev server running at ${r.url} (pid ${String(r.pid)})`),r.studioUrl!==void 0&&e.info(` Studio: ${r.studioUrl}`),r.tunnelUrl!==void 0&&e.info(` Tunnel: ${r.tunnelUrl}`),me(e)},Cr=3e4,Dr=async(e,r,n,t)=>{const o=await de(e,i=>i?.tunnelUrl,{intervalMs:n,timeoutMs:t});o===void 0?r.warn(" Tunnel: no URL yet — `lunora dev status` shows it once cloudflared reports one; `lunora dev logs` says why if it does not."):r.success(` Tunnel: ${o}`)},Or=async e=>{const{child:r,cwd:n,deadline:t,pollIntervalMs:o,probe:i}=e,s=r.exited.then(a=>({exitCode:a}));for(;Date.now()<t;){const a=C(n);if(a!==void 0&&a.pid!==process.pid&&await i(a.url))return{state:a,status:"ready"};const c=await Promise.race([s,w(o)]);if(c!==void 0)return{...c,status:"exited"}}return{status:"timeout"}},xr=async e=>{const{cwd:r,logger:n}=e,t=pe(r,void 0),o=or(e.readyTimeoutMs),i=(e.spawnDetached??br)({args:e.command.args,command:e.command.command,cwd:r,env:{...process.env,...e.env,[Me]:"1",[Ae]:t,...process.env.FORCE_COLOR===void 0?{NO_COLOR:"1"}:{},...e.json?{LUNORA_LOG_JSON:"1"}:{}},logPath:t}),s=await Or({child:i,cwd:r,deadline:Date.now()+o,pollIntervalMs:e.pollIntervalMs??_,probe:e.probe??ir});if(s.status==="ready")return Nr(n,s.state),e.tunnel===!0&&s.state.tunnelUrl===void 0&&await Dr(r,n,e.pollIntervalMs??_,e.tunnelUrlTimeoutMs??Cr),{code:0};if(s.status==="exited"){n.error(`dev server exited before becoming ready (exit code ${String(s.exitCode)}). Last output:`);for(const c of ge(t,Lr))n.error(` ${c}`);return E(r,i.pid??process.pid),{code:s.exitCode===0?1:s.exitCode}}i.pid!==void 0&&O(r)?.pid===process.pid&&b(r,{logFile:t,pid:i.pid});const a=i.pid===void 0?"":` (pid ${String(i.pid)})`;return n.warn(`dev server did not confirm ready within ${String(Math.round(o/1e3))}s — it may still be compiling${a}. Check \`lunora dev status\` and \`lunora dev logs\`; \`lunora dev stop\` shuts it down.`),{code:se.UNAVAILABLE}},we=e=>e.codegen!==!1&&!Ve(process.env[te]),he=e=>{const r={...Z(e.lazyFunctions)?{[Ue]:"1"}:{},...e.remote===!0?{LUNORA_REMOTE:"1"}:{},...e.codegen===!1?{[te]:"0"}:{}};return Object.keys(r).length>0?{env:r}:{}},St=async e=>{const{cwd:r,jsonLogs:n,logger:t,options:o,remote:i}=e,s=e.run??xr,a=M(r),c=a==="vite"&&D(o.target??ee(r))?"wrangler":a,l=c==="wrangler"?`http://localhost:${String(o.workerPort??8787)}`:"http://localhost:5173",d=De(r,{background:!0,mode:"cli",pid:process.pid,startedAt:new Date().toISOString(),url:l});if(!d.ok)return d.existing!==void 0&&Rr(t,d.existing),{code:0};const f={[Oe]:String(process.pid)};$r(t,r);try{return c==="vite"&&o.tunnel!==!0?await s({command:ve(r),cwd:r,env:{...he({...o,remote:i}).env,...f},json:n,logger:t}):await s({command:{args:[process.argv[1]??"lunora",...Ir(o,i)],command:process.execPath},cwd:r,env:f,json:n,logger:t,tunnel:o.tunnel===!0})}finally{E(r,process.pid)}},Ar=e=>{try{const r=T("ps",["-o","pgid=","-p",String(e)],{encoding:"utf8"}),n=Number.parseInt(r.stdout.trim(),10);return Number.isInteger(n)&&n>0?n:void 0}catch{return}},Mr=(e,r,n=process.platform,t=T)=>{if(n==="win32"){try{t("taskkill",["/pid",String(e.pid),"/T","/F"],{stdio:"ignore"})}catch{}return}if(e.background===!0)try{r(-(Ar(e.pid)??e.pid),"SIGKILL");return}catch{}try{r(e.pid,"SIGKILL")}catch{}},Ur=(e,r)=>(r.json?h({pid:e.pid,stopped:!1}):r.logger.error(`dev server (pid ${String(e.pid)}) survived the force-kill — record kept; retry \`lunora dev stop\` or kill the process manually.`),{code:1}),Gr=async e=>{const{cwd:r,logger:n}=e,t=O(r),o=e.alive??(f=>f===t?.pid&&Fe(t)),i=e.signal??((f,p)=>{process.kill(f,p)}),s=e.pollIntervalMs??_,a=e.stopGraceMs??yr,c=e.platform??process.platform,l=e.spawnSyncImpl??T;if(t===void 0||!o(t.pid))return t!==void 0&&E(r,t.pid),e.json?h({running:!1,stopped:!1}):n.info("No dev server running."),{code:0};try{i(t.pid,"SIGTERM")}catch{}const d=Date.now()+a;for(;o(t.pid)&&Date.now()<d;)await w(s);return o(t.pid)&&(Mr(t,i,c,l),await w(s),o(t.pid))?Ur(t,e):(E(r,t.pid),e.json?h({pid:t.pid,stopped:!0}):n.success(`Stopped dev server (pid ${String(t.pid)}).`),{code:0})},Fr=e=>{const{cwd:r,logger:n}=e,t=C(r);if(t===void 0)return e.json?h({running:!1}):n.info("No dev server running."),{code:0};const o=e.now??Date.now,i=t.startedAt===void 0?Number.NaN:Date.parse(t.startedAt),s=Number.isFinite(i)?Math.max(0,Math.round((o()-i)/1e3)):void 0;if(e.json)return h({background:t.background===!0,logFile:t.logFile,mode:t.mode,pid:t.pid,ready:j(t),readyAt:t.readyAt,running:!0,startedAt:t.startedAt,studioUrl:t.studioUrl,tunnelUrl:t.tunnelUrl,uptimeSeconds:s,url:t.url}),{code:0};const a=[`pid ${String(t.pid)}`,...s===void 0?[]:[`uptime ${String(s)}s`],t.background===!0?"background":"foreground",j(t)?"ready":"starting"];return n.success(`Dev server running at ${t.url} (${a.join(", ")})`),t.studioUrl!==void 0&&n.info(` Studio: ${t.studioUrl}`),t.tunnelUrl!==void 0&&n.info(` Tunnel: ${t.tunnelUrl}`),t.logFile!==void 0&&n.info(` Logs: lunora dev logs (${t.logFile})`),{code:0}},jr=e=>{const{cwd:r,logger:n}=e,t=O(r),o=pe(r,t);if(!q(o))return n.info("No dev server logs found — output is captured when the server runs in background mode (`lunora dev --background`)."),{code:0};const i=ge(o,e.lines??Er);return i.length>0&&process.stdout.write(`${i.join(`
4
+ `)}
5
+ `),{code:0}},kt=e=>{const{cwd:r,json:n,lines:t,logger:o,subcommand:i}=e;if(i==="stop")return Gr({cwd:r,json:n,logger:o});if(i==="status")return Fr({cwd:r,json:n,logger:o});if(i==="logs")return jr({cwd:r,lines:t,logger:o});if(i!==void 0)return o.error(`dev: unknown subcommand "${i}" — expected stop | status | logs (or no subcommand to start the dev server)`),{code:se.USAGE}},It=(e,r,n)=>D(e)?(r!=="wrangler"&&n.info(`target ${e} runs its own dev server, so lunora dev serves the worker on it — start the frontend's dev server separately`),"wrangler"):r,yt=async e=>{const{logger:r}=e,n=await(e.start??Be)({log:(i,{stream:s,tag:a})=>{ue(i,a,s,r)},port:e.port,projectRoot:e.projectRoot});let t=()=>{};const o=new Promise(i=>{t=i});return{exited:Promise.race([o,n.exited]),kill:()=>{n.stop().then(()=>0,()=>1).then(t).catch(()=>{})}}},Vr=e=>{const{cwd:r,driver:n,options:t,studioPort:o,workerPort:i}=e,{projectConfig:s,toolchain:a}=n;if(s===void 0||a===void 0)throw new Error(`deploy target "${n.id}" runs its own dev server but ships no config projection or toolchain for it`);if(t.remote===!0)throw new Error(`--remote proxies bindings to Cloudflare; ${n.name} has no remote bindings to proxy to`);t.inspectorPort!==void 0&&t.logger.warn(`--inspector-port is a wrangler dev flag; ${n.name} dev has no inspector to pin`);const{command:c,projection:l}=We(n,r,"dev",f=>a.dev({configPath:f,extraArgs:["--port",String(i)]}));l!==void 0&&l.dropped.length>0&&t.logger.info(`${n.name} ignores these wrangler keys, so its dev server runs without them: ${l.dropped.join(", ")}`);const d=le(A(r),c);return{flavor:"wrangler",ipv4LoopbackForced:!1,remote:{bindings:[],cleanup:()=>{},enabled:!1,withheld:[]},runsCodegenWatch:we(t),celldSession:!0,studioEnabled:t.studio!==!1,studioPort:o,workerEnabled:t.worker!==!1,workerOrigin:`http://localhost:${String(i)}`,workerPort:i,wrangler:{args:d.args,command:d.command,cwd:r,tag:c.tool}}},Se=(e=Je)=>Object.values(e()).some(r=>r?.some(n=>n.internal&&n.address==="::1")),$="wrangler.dev.jsonc",R=6173,m=8787,z=5173,ke=()=>{},Wr=(e,r)=>{if(!e.remote&&e.local===!0)return{args:[],plan:{bindings:[],cleanup:ke,enabled:!1,withheld:[]}};const t=(e.materializeDev??He)({projectRoot:r,remote:e.remote===!0}),i={bindings:t.remoteBindings.map(s=>`${s.binding} (${s.kind})`),cleanup:t.cleanup,enabled:e.remote===!0,reason:t.reason,withheld:t.withheld};return{args:t.configPath===void 0?[]:["--config",t.configPath],plan:i}},Ie=(e,r)=>{const n=[...new Set($e(r).services.map(s=>s.wranglerPath))],{cleanup:t,configPaths:o,withheld:i}=(e.materializeServiceConfigs??Ye)(n,{projectRoot:r});return{args:o.flatMap(s=>["--config",s]),cleanup:t,withheld:i}},Br=(e,r,n)=>{const t=L(e);return r.length===0||t===void 0?[]:[...n.length>0?[]:["--config",t],...r]},ye=e=>e.local===!0?["--local"]:[],H=e=>x(e).parsed?.dev?.ip,Ee=(e,r,n)=>{if(n!==void 0){const o=N(e,n);if(q(o)&&H(o)!==void 0)return[]}const t=L(e);return t!==void 0&&H(t)!==void 0?[]:r()?[]:["--ip","127.0.0.1"]},Kr=new Set(["127.0.0.1","::1","[::1]","localhost"]),zr=(e,r)=>{let n;try{n=Q(N(e,oe),"utf8")}catch{return[]}const t=[];for(const o of Ke(n)){let i;try{i=new URL(o.value)}catch{continue}Kr.has(i.hostname)&&i.port===String(r)&&t.push(o.key)}return t},Y=async(e,r)=>{if(e.workerPort!==void 0)return e.workerPort;const n=L(r);if(n!==void 0){const{parsed:i}=x(n);if(typeof i?.dev?.port=="number")return i.dev.port}const t=await(e.findFreePort??qe)(m);if(t===m)return t;const o=zr(r,m);if(o.length>0)throw new Error(`port ${String(m)} is in use, but ${oe} pins the worker origin to it (${o.join(", ")}). Serving on ${String(t)} would leave those URLs pointing at nothing. Stop whatever holds ${String(m)}, or run \`lunora dev --worker-port ${String(t)}\` and update those values to match.`);return t},Hr=(e,r)=>{if(e.inspectorPort!==void 0)return e.inspectorPort;const n=L(r);if(n===void 0)return;const{parsed:t}=x(n),o=t?.dev?.inspector_port;return typeof o=="number"?o:void 0},Yr=(e,r,n)=>{const t=Ee(r,e.hasIpv6Loopback??Se,$),o=ne(e.target??ee(r));if(o.toolchain===void 0)throw new Error(`deploy target "${o.id}" has no dev server to run the worker sidecar`);const i=Ie(e,r),s=o.toolchain.dev({configPath:$,extraArgs:[...t,...ye(e),"--var","WORKER_ENV:development",...i.args]}),a=le(n,s);return{cleanup:i.cleanup,sidecar:{args:a.args,command:a.command,cwd:r,tag:"worker"},withheld:i.withheld}},qr=(e,r)=>{e.worker===!1&&e.logger.warn(`--no-worker does not apply to the ${r} flavor: Vite owns the worker, codegen and studio in-process. Run your framework's dev script instead.`),e.inspectorPort!==void 0&&e.logger.warn(r==="framework-worker"?`--inspector-port does not apply to the ${r} flavor: pin \`dev.inspector_port\` in ${$} — that is the config the worker sidecar runs.`:`--inspector-port does not apply to the ${r} flavor: Vite owns the worker. Pin it in vite.config — \`lunora({ cloudflare: { inspectorPort: ${String(e.inspectorPort)} } })\`.`),e.local===!0&&r==="vite"&&e.logger.warn("--local does not apply to the vite flavor: Vite owns the worker. Turn remote bindings off in vite.config — `lunora({ cloudflare: { remoteBindings: false } })`.")},Jr=e=>{const r=e.cwd??process.cwd(),n=A(r),t=e.flavor??M(r);if(t==="vite"||t==="framework-worker"){const p=ve(r),u=t==="framework-worker"?Yr(e,r,n):void 0,v=u?.sidecar;return qr(e,t),{runsCodegenWatch:!1,flavor:t,ipv4LoopbackForced:!1,remote:{bindings:[],cleanup:ke,enabled:e.remote===!0,withheld:u?.withheld??[]},...u?{serviceConfigCleanup:u.cleanup}:{},...v?{sidecar:v}:{},studioEnabled:!1,studioPort:e.port??R,workerEnabled:!0,workerOrigin:`http://localhost:${String(z)}`,workerPort:z,wrangler:{args:p.args,command:p.command,cwd:r,...he(e),tag:"vite"}}}const o=re(r),i=o.framework==="none"?void 0:`this project uses ${o.framework} — the worker runs inside Vite there. run \`${er(n,"dev")}\` for the full app (frontend + HMR); \`lunora dev\` starts only the worker.`,s=e.workerPort??m,a=Wr(e,r),c=Ee(r,e.hasIpv6Loopback??Se),l=e.inspectorPort===void 0?[]:["--inspector-port",String(e.inspectorPort)],d=Ie(e,r),f=ce(n,"wrangler",["dev","--port",String(s),...l,...c,...ye(e),"--var","WORKER_ENV:development",...a.args,...Br(r,d.args,a.args)]);return{runsCodegenWatch:we(e),flavor:t,frameworkHint:i,ipv4LoopbackForced:c.length>0,remote:{...a.plan,withheld:[...a.plan.withheld,...d.withheld]},serviceConfigCleanup:d.cleanup,studioEnabled:e.studio!==!1,studioPort:e.port??R,workerEnabled:e.worker!==!1,workerOrigin:`http://localhost:${String(s)}`,workerPort:s,wrangler:{args:f.args,command:f.command,cwd:r,tag:"wrangler"}}},Et=async e=>{const r=e.cwd??process.cwd();if(e.target!==void 0&&D(e.target))return Vr({cwd:r,driver:ne(e.target),options:e,studioPort:e.port??R,workerPort:await Y(e,r)});const n=e.flavor??M(r),t=n==="wrangler"?await Y(e,r):e.workerPort,o=n==="wrangler"?Hr(e,r):e.inspectorPort;return Jr({...e,cwd:r,flavor:n,inspectorPort:o,workerPort:t})};export{_ as P,kt as a,Rr as b,hr as c,ir as d,M as e,It as f,Et as g,$r as h,ht as i,vt as j,wt as k,we as l,yt as m,pr as n,gt as o,Jr as p,Hr as q,or as r,St as s,pt as t,Y as u,mt as w};
@@ -0,0 +1 @@
1
+ import"./free-port-DjbFhaaT.mjs";import{g as a,p as s,q as l,u as p}from"./plan-BH4ZfiFs.mjs";export{a as buildDevPlan,s as planDevCommand,l as resolveInspectorPort,p as resolveWorkerPort};
@@ -0,0 +1,4 @@
1
+ import{errorAdvisoryNames as a}from"@lunora/codegen";const i=e=>e.strictAdvisories??(process.env.CI!==void 0&&process.env.CI!==""),v=(e,s)=>{const o=e.filter(t=>t.level==="ERROR");return{errorAdvisories:o,names:a(e),shouldBlock:o.length>0&&s}},p=(e,s)=>{if(e.length===0)return{errors:[],warnings:[]};const o=e.map(r=>` [${r.level.toUpperCase()}] ${r.name} — ${r.message}
2
+ ↳ ${r.remediation}`),t=e.filter(r=>r.level==="error").map(r=>r.message),n=e.filter(r=>r.level!=="error").map(r=>r.message),l=`${String(e.length)} platform ${e.length===1?"diagnostic":"diagnostics"}:
3
+ ${o.join(`
4
+ `)}`;return t.length===0?(s.warn(l),{errors:[],warnings:n}):(s.error(l),{errors:t,warnings:n})};export{p as a,v as e,i as r};
@@ -0,0 +1 @@
1
+ class e extends Error{constructor(){super("cancelled"),this.name="PromptCancelledError"}}export{e as P};
@@ -0,0 +1,2 @@
1
+ import{resolveHint as d,isLunoraError as s,flattenHint as r}from"@lunora/errors";import{VisulimaError as m,renderError as f}from"@visulima/error";import{exitCodeForError as l}from"./EXIT_CODE-DVjUgIaG.mjs";const g={filterStacktrace:()=>!1,hideErrorCodeView:!0},w=(n,i={})=>{const t=n instanceof Error?n.message:String(n),o=d(s(n)?{code:n.code,hint:n.hint,message:t}:t),e=o===void 0?[]:r(o).split(`
2
+ `),h=s(n)&&typeof n.why=="string"?[`Why: ${n.why}`]:[];s(n)&&(e.length>0&&e.push(""),e.push(`\`${n.code}\` — exits ${String(l(n))}. Run \`lunora docs exit-codes\` for the table.`));const a=[...h,...e],c=new m({hint:a.length===0?void 0:a,message:i.reason===void 0?t:`${i.reason}: ${t}`,name:n instanceof Error&&n.name.length>0?n.name:"Error"});return c.stack="",f(c,g)};export{w as r};
@@ -0,0 +1,5 @@
1
+ import{existsSync as p,readFileSync as g,writeFileSync as k,mkdtempSync as F,rmSync as w}from"node:fs";import{tmpdir as G}from"node:os";import{LunoraError as h}from"@lunora/errors";import{join as l}from"@visulima/path";import{downloadTemplate as W}from"giget";import{r as y}from"./cli-manifest-DoQ_3bzs.mjs";import{DEV_VARS_FILE as z,parseDevVariableEntries as H,writeDevVariablesFileAtomically as J}from"@lunora/config";import{modify as j,applyEdits as N,parse as K}from"jsonc-parser";import{b as q}from"./tui-prompts-B3YwUhGw.mjs";import Y from"./parseManifest-CwPTKdtS.mjs";const Z="alpha",T="main",X=new Set(["alpha","beta","next"]),Q=/^[\w./@-]+$/,ee=e=>!e.includes("..")&&Q.test(e),O=e=>{if(e==="0.0.0")return Z;const t=e.split("+")[0]??e,n=t.indexOf("-");if(n!==-1){const[s]=t.slice(n+1).split(".");if(s!==void 0&&X.has(s))return s}return T},D=e=>{if(e!==void 0&&e.length>0){if(!ee(e))throw new h("INTERNAL",`invalid --ref "${e}" — a ref may contain letters, digits, ".", "_", "-", "/", "@" and must not contain "..".`);return e}return O(y())},I="anolilab/lunora",L=/^[0-9a-f]{40}$/iu,B=String.raw`\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)+)?(?:\+[0-9A-Za-z.-]+)?`,te=new RegExp(String.raw`^v?${B}$`,"u"),ne=new RegExp(String.raw`^(?:@[\w.-]+\/)?[\w.-]+@${B}$`,"u"),se=e=>L.test(e)||te.test(e)||ne.test(e),re=()=>{const e=process.env.GITHUB_TOKEN??process.env.GH_TOKEN;return e!==void 0&&e.length>0?{authorization:`Bearer ${e}`}:{}},oe=async(e,t=I)=>{try{const n=await fetch(`https://api.github.com/repos/${t}/commits/${encodeURIComponent(e)}`,{headers:{accept:"application/vnd.github+json","user-agent":"lunora-cli",...re()},signal:AbortSignal.timeout(1e4)});if(!n.ok)return;const s=await n.json();return typeof s.sha=="string"&&L.test(s.sha)?s.sha:void 0}catch{return}},ie=async(e,t,n)=>{if(se(t))return t;const s=await oe(t,e);return s===void 0?(n.warn(`could not pin ${e}#${t} to a commit — fetching the UNPINNED branch (set GITHUB_TOKEN if rate-limited).`),t):(n.info(`pinned ${e}#${t} → ${s}`),s)},ae=async(e,t)=>ie(I,D(e),t),Me=(e=y())=>`@lunora/cli@${e}`,ce="latest",P=(e=y())=>{const t=O(e);return t===T?ce:t},de="https://registry.npmjs.org",ue=()=>{const e=process.env.npm_config_registry,t=e!==void 0&&e.length>0?e:de;return t.endsWith("/")?t.slice(0,-1):t},fe=async(e,t)=>{try{const n=await fetch(`${ue()}/${e.replaceAll("/","%2F")}`,{headers:{accept:"application/vnd.npm.install-v1+json"},signal:AbortSignal.timeout(1e4)});return n.ok?(await n.json())["dist-tags"]?.[t]:void 0}catch{return}},le=async(e,t)=>{const n=new Map;return await Promise.all([...new Set(e)].map(async s=>{const o=await fe(s,t);o!==void 0&&n.set(s,o)})),n},pe=e=>{if(!e.startsWith("workspace:"))return!1;const t=e.slice(10);return t===""||t==="*"||t==="^"||t==="~"},he=(e,t,n)=>{if(!e.startsWith("workspace:"))return e;const s=e.slice(10);return s===""||s==="*"||s==="^"||s==="~"?(n===void 0?void 0:t?.get(n))??P():s},Ue=async e=>{const t=new Set;for(const n of e)for(const s of[n.deps,n.devDependencies])for(const[o,r]of Object.entries(s??{}))pe(r)&&t.add(o);return t.size===0?new Map:le([...t],P())},ge=new Set(["@lunora/client","@lunora/do","@lunora/ratelimit","@lunora/runtime","@lunora/server","@lunora/values"]),me=/(['"])@lunora\/(client|do|ratelimit|runtime|server|values)(\/[^'"]*)?\1/gu,Fe=e=>e.replaceAll(me,(t,n,s,o)=>`${n}lunorash/${s}${o??""}${n}`),$=(e,t,n,s="dependencies",o=!1,r)=>{const a=Object.entries(e);if(a.length===0)return[];const i=l(t,"package.json");if(!p(i))return n.warn(`package.json not found at ${i} — skipping dependency updates`),[];let d=g(i,"utf8");const c=JSON.parse(d),f=[];for(const[u,M]of a){if(o&&ge.has(u)){n.info(`dep provided by the lunorash umbrella, skipping: ${u}`);continue}if(c.dependencies?.[u]!==void 0||c.devDependencies?.[u]!==void 0){n.info(`dep already present: ${u}`);continue}const U=j(d,[s,u],he(M,r,u),{formattingOptions:{insertSpaces:!0,tabSize:4}});d=N(d,U),f.push(u)}return f.length>0&&(k(i,d,"utf8"),n.success(`added ${String(f.length)} ${s==="devDependencies"?"devDependency(ies)":"dependency(ies)"} to package.json: ${f.join(", ")}`)),f},ye=(e,t,n)=>{if(e.length===0)return[];const s=l(t,z),o=p(s)?g(s,"utf8"):"",r=new Set(H(o).map(c=>c.key)),a=[],i=[],d=[];for(const c of e)c.secret&&i.push(c.name),!r.has(c.name)&&(c.description&&d.push(`# ${c.description}`),d.push(`${c.name}=${c.secret?"":c.value??""}`),a.push(c.name));if(a.length>0){const c=o===""||o.endsWith(`
2
+ `)?o:`${o}
3
+ `;J(s,`${c}${d.join(`
4
+ `)}
5
+ `),n.success(`scaffolded ${String(a.length)} env var(s) into .dev.vars: ${a.join(", ")}`)}return i.length>0&&n.info(`set secret value(s) locally in .dev.vars, then for production: ${i.map(c=>`wrangler secret put ${c}`).join("; ")}`),a},S=new Set(["ai","analytics_engine_datasets","browser","d1_databases","durable_objects","hyperdrive","kv_namespaces","mtls_certificates","queues","r2_buckets","send_email","services","vars","vectorize","version_metadata","workflows"]),ve=["binding","name","queue","pattern"],E=e=>{if(!(typeof e!="object"||e===null))for(const t of ve){const n=e[t];if(typeof n=="string"&&n.length>0)return`${t}:${n}`}},we=(e,t,n,s)=>{const o=new Set(e.map(i=>JSON.stringify(i))),r=new Set(e.map(i=>E(i)).filter(i=>i!==void 0)),a=[];for(const i of t){if(o.has(JSON.stringify(i)))continue;const d=E(i);if(d!==void 0&&r.has(d)){s.warn(`${d.replace(":"," ")} already exists in ${n} — keeping the project's entry and skipping the registry item's. Reconcile by hand if the item needs different settings.`);continue}d!==void 0&&r.add(d),a.push(i)}return a},b=e=>Array.isArray(e),R=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),$e=(e,t,n,s)=>{const o={};for(const[r,a]of Object.entries(t)){if(!Object.hasOwn(e,r)){o[r]=a;continue}JSON.stringify(e[r])!==JSON.stringify(a)&&s.warn(`${r} already exists in ${n} — keeping the project's value and skipping the registry item's. Reconcile by hand if the item needs different settings.`)}return o},Se=(e,t)=>{let n=K(e);for(const s of t){if(typeof n!="object"||n===null)return;n=n[s]}return n},Ee=(e,t)=>{const n=e[0];return n!==void 0&&S.has(n)?!0:(t.warn(`skipping binding "${e.join(".")}" — only resource bindings (${[...S].join(", ")}) may be written, not exec/entrypoint keys`),!1)},m=Symbol("skip-binding"),be=(e,t,n)=>{const{value:s}=t,o=t.path.join("."),r=Se(e,t.path);if(b(s)){if(!b(r))return s;const a=we(r,s,o,n);return a.length===0?m:[...r,...a]}if(R(s)){if(!R(r))return s;const a=$e(r,s,o,n);return Object.keys(a).length===0?m:{...r,...a}}return s},Re=(e,t,n)=>{if(e.length===0)return[];const o=["wrangler.jsonc","wrangler.json"].map(i=>l(t,i)).find(i=>p(i));if(!o)return n.warn("wrangler.jsonc not found — skipping binding updates"),[];let r=g(o,"utf8");const a=[];for(const i of e){if(!Ee(i.path,n))continue;const d=be(r,i,n);if(d===m)continue;const c=j(r,[...i.path],d,{formattingOptions:{insertSpaces:!0,tabSize:4}});c.length!==0&&(r=N(r,c),a.push(i.path.join(".")))}return a.length>0&&(k(o,r,"utf8"),n.success(`applied ${String(a.length)} binding(s) to ${o}: ${a.join(", ")}`)),a},Ge=(e,t,n,s=!1,o)=>{const r=[],a=[];return e.deps&&r.push(...$(e.deps,t,n,"dependencies",s,o)),e.devDependencies&&r.push(...$(e.devDependencies,t,n,"devDependencies",s,o)),e.bindings&&a.push(...Re(e.bindings,t,n)),e.envVars&&ye(e.envVars,t,n),{bindings:a,deps:r}},v=e=>e.source!==void 0&&e.source.length>0||e.from!==void 0&&e.from.length>0,We=async(e,t)=>{const n=e.some(({manifest:c})=>Object.keys(c.deps??{}).length>0||Object.keys(c.devDependencies??{}).length>0),s=e.some(({manifest:c})=>(c.bindings??[]).length>0),o=v(t);if(!n&&!s&&!o||t.yes)return{ok:!0};const r=[];n&&r.push("add dependencies to package.json"),s&&r.push("write wrangler.jsonc bindings"),o&&r.push(`come from a custom registry source (${String(t.from??t.source)})`);const a=r.join(", ");return!process.stdin.isTTY&&t.confirm===void 0?(t.logger.error(`add: stdin is not a TTY and the requested items ${a} — re-run with --yes to confirm`),{ok:!1,reason:"non-interactive"}):await(t.confirm??q)(`The requested items ${a}. Continue?`)?{ok:!0}:(t.logger.info("add: aborted"),{ok:!1,reason:"declined"})},V="gh:anolilab/lunora/registry",_=/^[A-Za-z0-9][\w-]*$/u,_e=e=>{if(!_.test(e))throw new h("INTERNAL",`invalid registry item name "${e}" — names must match ${_.source} (letters, digits, "-", "_"; no path separators or "..")`)},Ae=e=>e.includes("..")?!1:e.startsWith("gh:")||e.startsWith("github:")||e.startsWith("https://"),ke=e=>v(e)&&e.from===void 0&&!e.allowUnsafeSource&&!Ae(e.source??""),ze=(e,t)=>ke(t)?`${e}: refusing --source ${String(t.source)} — only gh:, github:, or https:// sources are allowed (and may not contain ".."). Re-run with --allow-unsafe-source if you really want this.`:void 0,C=async(e,t,n)=>{const s=F(l(G(),`lunora-${t}-fetch-`)),o=l(s,t);n.info(`fetching ${e}`);try{const r=await W(e,{cwd:s,dir:o,force:!0,install:!1,silent:!0});return n.info(r.commit?`resolved ${r.source} @ ${r.commit}`:`resolved ${r.source}`),{cleanup:()=>{w(s,{force:!0,recursive:!0})},directory:o}}catch(r){throw w(s,{force:!0,recursive:!0}),r}},A=new WeakMap,x=async e=>{const t=A.get(e);if(t!==void 0)return t;const n=v(e)?Promise.resolve(D(e.ref)):ae(e.ref,e.logger);return A.set(e,n),n},je=async(e,t,n=V)=>{if(_e(e),t.from!==void 0){const o=l(t.from,e);if(!p(o))throw new h("INTERNAL",`registry item not found in local source: ${o}`);return{cleanup:()=>{},directory:o}}const s=t.source??n;return C(`${s}/${e}#${await x(t)}`,"item",t.logger)},He=async e=>{if(e.from!==void 0){if(!p(e.from))throw new h("INTERNAL",`registry root not found: ${e.from}`);return{cleanup:()=>{},root:e.from}}const t=e.source??V,{cleanup:n,directory:s}=await C(`${t}#${await x(e)}`,"registry",e.logger);return{cleanup:n,root:s}},Ne=(e,t)=>{const n=JSON.parse(g(l(e,"registry.json"),"utf8"));return Y(n,t)},Je=async(e,t)=>{const n=[],s=[],o=new Set,r=new Set,a=async i=>{if(o.has(i))return;if(r.has(i))throw new h("INTERNAL",`cyclic registry dependency detected at "${i}"`);r.add(i);const{cleanup:d,directory:c}=await je(i,t);s.push(d);const f=Ne(c,i);for(const u of f.requires??[])await a(u);r.delete(i),o.add(i),n.push({directory:c,manifest:f})};try{for(const i of e)await a(i)}catch(i){for(const d of s)d();throw i}return{cleanups:s,items:n}};export{ae as a,je as b,Ge as c,Fe as d,Je as e,Ue as f,We as g,He as h,v as i,he as j,Ne as k,le as l,ie as m,P as n,D as o,Me as r,ze as s};
@@ -0,0 +1 @@
1
+ import{readLinkedProject as n}from"@lunora/config";const v=({cwd:e,env:i,url:o})=>{if(o!==void 0&&o!=="")return o;const r=n(e);if(!(r===void 0||r.env!==i))return r.workerUrl},d=({cwd:e,prod:i,url:o})=>{if(o!==void 0&&o!=="")return o;if(!i)return;const r=n(e);if(!(r===void 0||r.env!==void 0&&r.env!=="production"))return r.workerUrl};export{d as a,v as r};
@@ -0,0 +1 @@
1
+ import"./EXIT_CODE-DVjUgIaG.mjs";import"./resolve-Bdc9KEUv.mjs";import"./catalog-CahzmDLV.mjs";import{r as n,a as i,b as t}from"./commands-DC3ZX1yk.mjs";export{n as runAddCommand,i as runBuildIndexCommand,t as runRegistryViewCommand};
@@ -0,0 +1 @@
1
+ import"./platform-diagnostics-Cn2g6Jh-.mjs";import"./api-spec-lYyq4vL6.mjs";import{e as u,b as y,r as x,a as D,s as L}from"../packem_chunks/handler.mjs";import"./vectorize-metadata-DOB1akh6.mjs";import"./binding-manifest-file-CQ1eQYy1.mjs";import"./command-B6vu47iR.mjs";import"./deploy-target-resolve-BTCW1Iv4.mjs";import"./EXIT_CODE-DVjUgIaG.mjs";import"./resolve-target-C_ZloTvd.mjs";import"./health-probe-Bw9JFfIy.mjs";import"./createRecordingSpawner-01ZngIwK.mjs";export{u as execute,y as provisionBindings,x as runDeployCommand,D as runPreDeployPipeline,L as smokeLoadLazyModules};
@@ -0,0 +1,5 @@
1
+ import{randomUUID as x}from"node:crypto";import{createWriteStream as b}from"node:fs";import{unlink as E,rename as S}from"node:fs/promises";import{r as O}from"./admin-token-VdUnvnKW.mjs";import{r as T,a as $}from"./admin-url-DJB8P6Jh.mjs";import{EXIT_CODE as w,isRefusal as U,exitCodeForStatus as N}from"./EXIT_CODE-DVjUgIaG.mjs";import{E as k}from"./shared-D-zCOmgY.mjs";const I=e=>{if(e===void 0)return;const r=e.split(",").map(t=>t.trim()).filter(t=>t.length>0);return r.length>0?r:void 0},y=async(e,r)=>{e.write(r)||await new Promise((t,a)=>{let d=o=>{};const n=()=>{e.removeListener("error",d),t()};d=o=>{e.removeListener("drain",n),a(o)},e.once("drain",n),e.once("error",d)})},P=async(e,r)=>{const t=e.getReader(),a=new TextDecoder;let d=0,n=0,o="",c=!1;try{for(;!c;){const i=await t.read();if(c=i.done,i.value===void 0)continue;d+=i.value.length,o+=a.decode(i.value,{stream:!0});let s=o.indexOf(`
2
+ `);for(;s!==-1;){n+=1;const l=`${o.slice(0,s)}
3
+ `;await y(r,l),o=o.slice(s+1),s=o.indexOf(`
4
+ `)}}return o.length>0&&(n+=1,await y(r,`${o}
5
+ `)),{bytes:d,rows:n}}finally{t.releaseLock()}},v=async(e,r)=>{if(r===void 0)return;const t=e;await new Promise(a=>{if(t.closed){a();return}t.once("close",()=>{a()}),t.destroy()});try{await E(r)}catch{}},A=async(e,r,t)=>{await new Promise((d,n)=>{e.end(o=>{const c=o??t();c===void 0?d():n(c)})});const a=t();if(a!==void 0)throw await v(e,r),a},_=async(e,r,t)=>{await A(e,r.stage,t);try{await S(r.stage,r.path)}catch(a){throw await v(e,r.stage),a}},p="export --format json needs a file destination (--out <file>) — with --out - the NDJSON stream already owns stdout.",D=e=>{const r=e.out===void 0||e.out==="-"?void 0:e.out;if(e.format==="json"&&r===void 0){e.logger.error(p);return}return{destination:r}},R=e=>{if(e.prod&&e.url===void 0)return e.logger.error("--prod requires an explicit --url (refusing to export from the implicit localhost worker)"),{refused:w.USAGE};const r=T(e.url,e.logger,e.cwd);if(r===void 0)return{refused:w.USAGE};const{token:t}=O({cwd:e.cwd??process.cwd(),token:e.token,url:r});return t?{fetchImpl:e.fetchImpl??$,requestUrl:`${r}${k}`,tables:I(e.tables),token:t}:(e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)"),{refused:w.AUTH})},H=async e=>{const r=D(e);if(r===void 0)return{bytes:0,code:w.USAGE,error:p,rows:0};const{destination:t}=r,a=R(e);if(U(a))return{bytes:0,code:a.refused,error:"export: could not resolve the worker URL and admin token",rows:0};const{fetchImpl:d,requestUrl:n,tables:o,token:c}=a;e.logger.info(`POST ${n} -> export${o?` (tables: ${o.join(",")})`:""}`);const i=await d(n,{body:JSON.stringify(o?{tables:o}:{}),headers:{authorization:`Bearer ${c}`,"content-type":"application/json"},method:"POST"});if(!i.ok){const u=await i.text(),h=`export failed: HTTP ${String(i.status)}: ${u}`;return e.logger.error(h),{bytes:0,code:N(i.status),error:h,rows:0}}if(!i.body)return e.logger.error("export response carried no body"),{bytes:0,code:1,error:"export response carried no body",rows:0};const s=t===void 0?void 0:{path:t,stage:`${t}.${x()}.partial`},l=s===void 0?process.stdout:b(s.stage,{encoding:"utf8",mode:384});let g;s!==void 0&&l.on("error",u=>{g??=u});let f,m;try{({bytes:f,rows:m}=await P(i.body,l))}catch(u){throw await v(l,s?.stage),u}return s!==void 0&&(await _(l,s,()=>g),e.logger.success(`wrote ${String(m)} rows to ${s.path} (${String(f)} bytes)`)),{bytes:f,code:0,data:t===void 0?void 0:{bytes:f,out:t,rows:m,tables:o},rows:m}};export{H as runExportCommand};
@@ -0,0 +1,11 @@
1
+ import{existsSync as p,mkdirSync as _,writeFileSync as w,mkdtempSync as C,rmSync as F,readFileSync as U}from"node:fs";import{tmpdir as O}from"node:os";import{discoverMigrations as k,discoverSchema as x,readPackageDependencies as D}from"@lunora/codegen";import{isInteractive as G,promptSelect as P,promptText as j}from"@lunora/config";import{LunoraError as T}from"@lunora/errors";import{join as m}from"@visulima/path";import{Project as v}from"ts-morph";import{r as z,t as L}from"./admin-token-VdUnvnKW.mjs";import{r as B,a as q,n as H}from"./admin-url-DJB8P6Jh.mjs";import{isRefusal as W,exitCodeForStatus as J,EXIT_CODE as d}from"./EXIT_CODE-DVjUgIaG.mjs";import{diffSnapshots as K,renderMigrationFile as V}from"./diffSnapshots-htqNZT8Q.mjs";import X from"./schemaIrToSnapshot-BHuNOfgs.mjs";import{runExportCommand as Z}from"./runExportCommand-DiMCQ-Il.mjs";import{r as Q}from"./import-DoAUdyfU.mjs";import{readAndLogBody as Y}from"../packem_chunks/runRpcCommand.mjs";const h="__lunora_reproject__",ee=e=>{if(!e.startsWith(h))return;const r=e.slice(h.length);return r===""?void 0:r},re=".snapshot.json",N=/[^\da-z]+/gu,M=(e,r)=>{let t=0,o=e.length;for(;t<o&&e[t]===r;)t+=1;for(;o>t&&e[o-1]===r;)o-=1;return e.slice(t,o)},te=e=>{const r=M(e.toLowerCase().replaceAll(N,"_"),"_");return r===""?"auto":r},oe=e=>{const r=(t,o=2)=>t.toString().padStart(o,"0");return`${String(e.getUTCFullYear())}${r(e.getUTCMonth()+1)}${r(e.getUTCDate())}${r(e.getUTCHours())}${r(e.getUTCMinutes())}${r(e.getUTCSeconds())}`},ae=e=>{if(p(e))try{const r=U(e,"utf8"),t=JSON.parse(r);if(t.version!==1)throw new T("INTERNAL",`unsupported snapshot version: ${t.version}`);return t}catch(r){const t=r instanceof Error?r.message:String(r);throw new T("INTERNAL",`failed to read ${e}: ${t}`,{cause:r})}},Pe=e=>{const r=e.cwd??process.cwd(),t=m(r,"lunora","schema.ts");if(!p(t)){const f=`schema not found: ${t} — run \`vis generate lunora-table --name=<name>\` to create one`;return e.logger.error(f),{code:d.NOT_FOUND,empty:!0,error:f,migrationFile:""}}const o=new v({skipAddingFilesFromTsConfig:!0}),n=x(o,t),l=X(n),c=m(r,"lunora","migrations"),s=m(c,re);let a;try{a=ae(s)}catch(f){const S=f instanceof Error?f.message:String(f);return e.logger.error(S),{code:d.USAGE,empty:!0,error:S,migrationFile:""}}const i=K(a,l);if(i.empty)return e.logger.info("no schema changes detected — snapshot is already up to date"),{code:0,empty:!0,migrationFile:""};const g=(e.now??(()=>new Date))(),$=te(e.name??"auto"),y=`${oe(g)}_${$}.sql`,b=m(c,y);_(c,{recursive:!0});const R=V($,i,g.toISOString());return w(b,R,"utf8"),w(s,`${JSON.stringify(l,void 0,4)}
2
+ `,"utf8"),e.logger.success(`wrote ${b}`),i.unsupported.length>0&&e.logger.warn(`${String(i.unsupported.length)} unsupported diff(s) — see the comment block in ${y} and write the SQL manually`),{code:0,empty:!1,migrationFile:b}},ne="migrations.ts",A=/^[A-Za-z_]\w*$/u,ie=new Set(["await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","if","implements","import","in","instanceof","interface","let","new","null","package","private","protected","public","return","static","super","switch","this","throw","true","try","typeof","var","void","while","with","yield"]),E=/^import\s*\{\s*defineMigration\s*\}\s*from\s*["'](?:@lunora\/server|lunorash\/server)["'][^\n]*$/mu,se=e=>`import { defineMigration } from "${D(e)?.has("lunorash")??!1?"lunorash/server":"@lunora/server"}";`,ce="__lunora_admin__:runMigration",de="__lunora_admin__:migrationStatus",le="/_lunora/migrate",ue=e=>M(e.trim().toLowerCase().replaceAll(N,"-"),"-"),me=e=>e.split("-").filter(r=>r.length>0).map((r,t)=>t===0?r:r.charAt(0).toUpperCase()+r.slice(1)).join(""),ge=e=>{const r=m(e,"lunora","schema.ts");if(!p(r))return[];try{const t=new v({skipAddingFilesFromTsConfig:!0});return x(t,r).tables.map(o=>o.name)}catch{return[]}},fe=async e=>e.length>0?P("Which table does this migration iterate?",e.map(r=>({label:r,value:r}))):j("Target table for the migration: "),he=async(e,r)=>{if(r.table!==void 0)return r.table;const t=r.promptTable??(G()?fe:void 0);if(t===void 0){r.logger.error("migrate create requires a target table when not running interactively — re-run with --table <table>");return}const n=(await t(ge(e)))?.trim();if(n===void 0||n===""){r.logger.error("no table selected — re-run with --table <table>");return}return n},je=async e=>{const r=e.cwd??process.cwd(),t=ue(e.name);if(t==="")return e.logger.error(`invalid migration name: "${e.name}" — must contain at least one alphanumeric character`),{code:d.USAGE,file:""};const o=me(t);if(!A.test(o)||ie.has(o))return e.logger.error(`invalid migration name: "${e.name}" derives the export \`${o}\`, which is not a valid identifier — pick a name that starts with a letter and isn't a reserved word`),{code:d.USAGE,file:""};const n=await he(r,e);if(n===void 0)return{code:d.USAGE,file:""};if(!A.test(n))return e.logger.error(`invalid table: "${n}" — must be a valid identifier ([A-Za-z_][A-Za-z0-9_]*)`),{code:d.USAGE,file:""};const l=m(r,"lunora"),c=m(l,ne);let s=p(c)?U(c,"utf8"):"";if(s.includes(`id: "${t}"`)||new RegExp(String.raw`\bexport const ${o}\b`,"u").test(s))return e.logger.error(`a migration with id "${t}" (export \`${o}\`) already exists in ${c}`),{code:d.CONFLICT,file:""};const a=se(r);s.trim()===""?s=`${a}
3
+ `:E.test(s)?s=s.replace(E,a):s=`${a}
4
+ ${s}`;const i=`export const ${o} = defineMigration({
5
+ id: "${t}",
6
+ table: "${n}",
7
+ up: (document) => document,
8
+ });`;return _(l,{recursive:!0}),w(c,`${s.trimEnd()}
9
+
10
+ ${i}
11
+ `,"utf8"),e.logger.success(`scaffolded migration "${t}" in ${c}`),{code:0,file:c}},pe=(e,r)=>{const t=new v({skipAddingFilesFromTsConfig:!0});return k(t,m(e,"lunora")).find(n=>n.id===r)?.table},be=(e,r)=>{const t=ee(r.id);if(t!==void 0)return t;if(r.id.startsWith(h)){r.logger.error(`"${r.id}" names no table — use ${h}<table>`);return}let o;try{o=pe(e,r.id)}catch(n){r.logger.error(n instanceof Error?n.message:String(n));return}if(o===void 0){r.logger.error(`migration "${r.id}" not found under lunora/ — declare it with defineMigration({ id: "${r.id}", ... })`);return}if(o===""){r.logger.error(`migration "${r.id}" must declare \`table\` as a static string literal`);return}return o},we=e=>{const r=e.cwd??process.cwd();if(e.prod&&e.url===void 0)return e.logger.error("--prod requires an explicit --url (refusing to migrate the implicit localhost worker)"),{refused:d.USAGE};const t=be(r,e);if(t===void 0)return{refused:d.USAGE};const o=B(e.url,e.logger,e.cwd);if(o===void 0)return{refused:d.USAGE};const{token:n}=z({cwd:r,token:e.token,url:o});return n?(e.subcommand==="up"||e.subcommand==="down")&&L({prod:e.prod,url:o})&&!e.yes?(e.logger.error(`migrate ${e.subcommand} runs the migration against ${o}, which is not local. Re-run with --yes to confirm.`),{refused:d.USAGE}):{fetchImpl:e.fetchImpl??q,requestUrl:`${o}${le}`,table:t,token:n}:(e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)"),{refused:d.AUTH})},ve=e=>{if(e===null||typeof e!="object")return;const r=e,t=typeof r.failed=="number"&&r.failed>0?r.failed:0;if(t>0)return`${String(t)} shard(s) could not be reached — their rows were NOT migrated (see the per-shard errors above)`;if(r.status==="failed")return"the migration reported `failed` on at least one shard — see the per-shard results above"},$e=e=>{const r={id:e.id};return e.subcommand==="status"||(r.direction=e.subcommand,e.dryRun&&(r.dryRun=!0),e.batchSize!==void 0&&(r.batchSize=e.batchSize),e.maxBatches!==void 0&&(r.maxBatches=e.maxBatches)),r},ze=async e=>{const r=we(e);if(W(r))return{body:void 0,code:r.refused,requestUrl:""};const{fetchImpl:t,requestUrl:o,table:n,token:l}=r,c=e.subcommand==="status"?de:ce,s=$e(e);e.logger.info(`POST ${o} -> ${e.subcommand} ${e.id} (table "${n}")`);const a=await t(o,{body:JSON.stringify({args:s,functionPath:c,table:n}),headers:{authorization:`Bearer ${l}`,"content-type":"application/json"},method:"POST"}),i=await Y(a,e.logger),u=ve(i);u!==void 0&&e.logger.error(`migrate ${e.subcommand} "${e.id}": ${u}`);const g=u===void 0?0:1;return{body:i,code:a.ok?g:J(a.status),requestUrl:o}},I=e=>e===void 0?void 0:H(e),ye={"d1-to-hyperdrive":{source:"D1",target:"Hyperdrive"},"hyperdrive-to-d1":{source:"Hyperdrive",target:"D1"}},Se=(e,r,t,o)=>e?`Imported ${String(r.inserted)} and replaced ${String(r.replaced)} of ${String(r.exported)} exported row(s). The rest were not written; see the errors reported above, then fix them and re-run.`:`Imported ${String(r.inserted)} of ${String(r.exported)} exported row(s). The rest already exist in the ${o} target and were left unchanged (reported as conflicts above), so this copied rows missing from ${o}, not later edits to rows it already holds. Re-run with --replace to overwrite them with the ${t} values, or keep the dump with --out and reconcile by hand.`,Le=async e=>{const{logger:r}=e,{source:t,target:o}=ye[e.direction],n=I(e.fromUrl??e.toUrl),l=I(e.toUrl??e.fromUrl);if(n===l){const a=`source and target are the same deployment — pass distinct --from-url and --to-url so the ${t} export and ${o} import don't run against one database`;return r.error(a),{bytes:0,code:d.USAGE,error:a,exported:0,imported:0,replaced:0}}if(e.replace===!0&&(e.tables===void 0||e.tables.trim()==="")){const a="--replace needs --tables naming the .global() tables to move: an export without a table list also carries shard-local rows, and --replace would overwrite them in the target";return r.error(a),{bytes:0,code:d.USAGE,error:a,exported:0,imported:0,replaced:0}}const c=e.out===void 0?C(m(O(),"lunora-d1ps-")):void 0,s=e.out??m(c,"dump.ndjson");try{r.info(`Exporting .global() data from the ${t} source (${n??"http://localhost:8787"}) …`);const a=await Z({fetchImpl:e.fetchImpl,logger:r,out:s,prod:e.prod,tables:e.tables,token:e.fromToken,url:n});if(a.code!==0)return{bytes:a.bytes,code:a.code,exported:a.rows,imported:0,replaced:0,...a.error===void 0?{}:{error:a.error}};r.info(`Exported ${String(a.rows)} row(s) (${String(a.bytes)} bytes).`),r.info(`Importing into the ${o} target (${l??"http://localhost:8787"}) …`);const i=await Q({batchSize:e.batchSize,fetchImpl:e.fetchImpl,file:s,logger:r,prod:e.prod,replace:e.replace,token:e.toToken,url:l,yes:e.yes}),u=i.replaced??0;if(i.code!==0)return{bytes:a.bytes,code:i.code,exported:a.rows,imported:i.inserted,replaced:u,...i.error===void 0?{}:{error:i.error}};if(i.inserted+u===a.rows){const g=u>0?` (${String(u)} existing row(s) overwritten; rows deleted on ${t} since cutover are not removed)`:"";r.info(`✓ Migrated ${String(a.rows)} row(s)${g} — counts match. Verify your app reads from ${o}, then decommission the ${t} binding.`)}else r.warn(Se(e.replace===!0,{exported:a.rows,inserted:i.inserted,replaced:u},t,o));return{bytes:a.bytes,code:0,exported:a.rows,imported:i.inserted,replaced:u}}finally{c!==void 0&&F(c,{force:!0,recursive:!0})}};export{Le as runMigrateBackendCommand,je as runMigrateCreateCommand,ze as runMigrateDataCommand,Pe as runMigrateGenerateCommand};
@@ -0,0 +1 @@
1
+ import{buildSchemaSnapshot as b,isD1GlobalTable as d}from"@lunora/codegen";import{validatorKindToSqlType as p}from"./diffSnapshots-htqNZT8Q.mjs";const k=new Set(["any","null"]),f=(n,e)=>{const t=e.kindOf(n);return t!==void 0&&k.has(t)||e.nullableOf(n)?!0:t==="union"&&(e.membersOf(n)??[]).some(l=>f(l,e))},m=n=>n.kind==="optional"&&n.inner?m(n.inner):n.kind==="literal"&&n.literalValue==="null"?"null":n.kind,i=n=>n.kind==="optional"&&n.inner?i(n.inner):n,O=n=>f(n,{kindOf:m,membersOf:e=>i(e).members,nullableOf:e=>i(e).column?.notNull===!1}),N=n=>p(n.kind==="optional"&&n.inner?n.inner.kind:n.kind),T=(n,e)=>n.kind==="optional"||O(n)?!0:e===void 0?!1:e.nullable===!0,h=d,y=n=>{const e={},t=b(n,[]);for(const l of n.tables){if(!h(l))continue;const a={};for(const[o,c]of Object.entries(l.shape)){const s=t.tables[l.name]?.fields[o],r={nullable:T(c,s),sqlType:N(c)};a[o]=s===void 0?r:{...r,field:s}}const u={};for(const o of l.indexes)u[o.name]={fields:[...o.fields],name:o.name,unique:o.unique??!1};e[l.name]={columns:a,indexes:u,name:l.name}}return{tables:e,version:1}};export{y as default};
@@ -0,0 +1 @@
1
+ const a="/_lunora/admin/export",o="/_lunora/admin/import",_="/_lunora/admin/storage",n="/_lunora/admin/storage/url";export{a as E,o as I,_ as S,n as a};
@@ -0,0 +1 @@
1
+ import{s}from"./index-oHZBGBwB.mjs";import{s as n}from"./commands-DC3ZX1yk.mjs";const c=[{description:"Email + password on better-auth (default)",label:"Email & password",value:"auth"},{description:"Clerk as an OAuth login; Lunora (better-auth) owns the session",label:"Clerk",value:"auth-clerk"},{description:"Auth0 as an OIDC login; Lunora (better-auth) owns the session",label:"Auth0",value:"auth-auth0"}],r="auth",k=async t=>await t("Which auth provider?",c,{default:r})??r,D="mail",E=[{description:"Next, react-router, TanStack Start, Astro islands",label:"React",value:"auth-ui-react"},{description:"Nuxt, Vue + Vite",label:"Vue",value:"auth-ui-vue"},{description:"SvelteKit, Svelte + Vite",label:"Svelte",value:"auth-ui-svelte"},{description:"TanStack Start Solid, Solid 1.x + Vite",label:"Solid",value:"auth-ui-solid"},{description:"Solid 2.0 + Vite (@solidjs/web)",label:"Solid 2",value:"auth-ui-solid-v2"},{description:"Analog",label:"Angular",value:"auth-ui-angular"}],j="auth-ui-react",d=t=>Object.hasOwn(t,"react-native")||Object.hasOwn(t,"@lunora/react-native")||Object.hasOwn(t,"expo"),L="auth-ui has no React Native port — the screens render DOM elements and a stylesheet, which Metro has nothing to mount. Build the screens with React Native primitives against the same better-auth client (`@lunora/react-native/auth`); `lunora add auth` still installs the server half.",h=t=>{if(!(t===void 0||s.validRange(t)===null))return s.minVersion(t)?.major},v=t=>Object.hasOwn(t,"@solidjs/web")||(h(t["solid-js"])??0)>=2,B=t=>{const e=a=>Object.hasOwn(t,a);if(!d(t)){if(v(t))return"auth-ui-solid-v2";if(e("@lunora/react"))return"auth-ui-react";if(e("@lunora/vue"))return"auth-ui-vue";if(e("@lunora/svelte"))return"auth-ui-svelte";if(e("@lunora/solid"))return"auth-ui-solid";if(e("@lunora/angular"))return"auth-ui-angular";if(e("react")||e("next"))return"auth-ui-react";if(e("vue")||e("nuxt"))return"auth-ui-vue";if(e("svelte")||e("@sveltejs/kit"))return"auth-ui-svelte";if(e("solid-js"))return"auth-ui-solid";if(e("@angular/core"))return"auth-ui-angular"}},U=t=>{const e=t.trim();if(e==="")return;const a=e.toLowerCase();return a==="auth-ui"||a==="auth-ui-"?{kind:"auth-ui"}:a==="auth"?{kind:"auth"}:a==="email"||a==="mail"?{kind:"email"}:{item:a,kind:"item"}},m=/[^a-z0-9]+/u,u=(t,e,a)=>{let i=t.toLowerCase().split(m).filter(Boolean).join("-").slice(0,a);return i.endsWith("-")&&(i=i.slice(0,-1)),i.length>=e?i:void 0},b="DB",A="Name your D1 database (run `wrangler d1 create` to get its id, then put it in wrangler.jsonc)",o=t=>u(t,1,64),f="lunora-db",_=t=>o(`${t}-db`)??f,M=async(t,e)=>{const a=_(e);return o(await t(A,{default:a,placeholder:a}))??a},R=(t,e)=>n(t,"d1_databases",{key:"binding",value:b},"database_name",e),N="SEND_EMAIL",P="Verified destination email for production delivery (blank = set it later in wrangler.jsonc)",p=t=>{const e=t.trim();if(e.length===0||e.includes(" "))return!1;const a=e.indexOf("@");if(a<=0||a!==e.lastIndexOf("@"))return!1;const i=e.slice(a+1);return i.length>=3&&i.includes(".")&&!i.startsWith(".")&&!i.endsWith(".")},y=(t,e)=>{const a=t.trim();if(a!==""){if(!p(a)){e(`"${a}" doesn't look like an email — leaving the placeholder; set destination_address in wrangler.jsonc.`);return}return a}},V=(t,e)=>n(t,"send_email",{key:"name",value:N},"destination_address",e),w="UPLOADS",g="Name your R2 bucket (you can rename it in wrangler.jsonc later)",l=t=>u(t,3,63),I="lunora-uploads",O=t=>l(`${t}-uploads`)??I,C=async(t,e)=>{const a=O(e);return l(await t(g,{default:a,placeholder:a}))??a},x=(t,e)=>n(t,"r2_buckets",{key:"binding",value:w},"bucket_name",e);export{L as A,r as D,D as E,P as M,o as a,_ as b,M as c,O as d,k as e,B as f,j as g,E as h,d as i,c as j,V as k,R as l,U as n,C as p,y as r,l as s,x as w};
@@ -0,0 +1,4 @@
1
+ import{jsx as n,jsxs as u}from"react/jsx-runtime";import{isInteractive as p,ACCENT as x,LUNA_ART as ce,LUNA_NAME as le,LUNA_SIGNOFF as ae,BADGE_COLUMN_WIDTH as z,badgeWidth as J,badgeLead as se,padBadge as ue}from"@lunora/config";import{render as H}from"@visulima/tui";import{Box as d}from"@visulima/tui/components/box";import{Text as l}from"@visulima/tui/components/text";import{useApp as I}from"@visulima/tui/hooks/use-app";import{useInput as B}from"@visulima/tui/hooks/use-input";import{useInterval as de}from"@visulima/tui/hooks/use-interval";import{CommandPalette as fe}from"@visulima/tui-kit/command-palette";import{ConfirmInput as he}from"@visulima/tui-kit/confirm-input";import{SelectInput as me}from"@visulima/tui-kit/select-input";import{Spinner as pe}from"@visulima/tui-kit/spinner";import{TextInput as ve}from"@visulima/tui-kit/text-input";import{useState as S,useEffect as A}from"react";import{P as K}from"./prompt-cancelled-BvsNxg_Q.mjs";let j=!1;const V=()=>{j||(j=!0,process.getMaxListeners()<64&&process.setMaxListeners(64))},we=({children:e,onCancel:r})=>{const{exit:t}=I();return B((i,o)=>{o.ctrl&&i==="c"&&(r(),t())}),e},Q=e=>e instanceof Error?e:new Error(typeof e=="string"?e:"task failed"),Z=10,xe=8,ee=({spec:e})=>u(l,{children:[n(l,{children:se(e.text)}),n(l,{backgroundColor:e.bg,bold:!0,color:e.fg,children:ue(e.text)})]}),$=({badge:e,message:r})=>e===void 0?n(l,{bold:!0,children:r}):u(d,{children:[n(ee,{spec:e}),n(l,{bold:!0,children:` ${r}`})]}),re=2,T=" ".repeat(z-1),te=e=>" ".repeat(J(e)+1),Ce=e=>e===void 0?re:J(e)+1,D=({badge:e,children:r,message:t})=>u(d,{flexDirection:"column",children:[n($,{badge:e,message:t}),n(d,{flexDirection:"column",marginLeft:Ce(e),children:r})]}),g=({answer:e,badge:r,message:t})=>u(d,{flexDirection:"column",children:[n($,{badge:r,message:t}),e===""?null:n(l,{dimColor:!0,children:`${r===void 0?" ".repeat(re):te(r)}${e}`})]}),R=e=>{const{exit:r}=I(),[t,i]=S(void 0);return A(()=>{t!==void 0&&r()},[t,r]),{answer:t,submit:(o,c)=>{e(o),i(c)}}},Se=({children:e})=>{const{exit:r}=I();return A(()=>{r()},[r]),e},y=async e=>{V(),process.stdout.write(`
2
+ `);const r=H(n(Se,{children:e}));try{await r.waitUntilExit()}catch{}finally{r.unmount()}},Ze=async(e,r,t)=>{if(!p())return;const i=t===void 0||t===""?[]:t.split(`
3
+ `);await y(u(d,{flexDirection:"column",children:[n($,{badge:e,message:r}),i.map(o=>n(l,{dimColor:!0,children:`${te(e)}${o}`},o))]}))},G=async e=>{V(),process.stdout.write(`
4
+ `);const r={value:!1},t=H(n(we,{onCancel:()=>{r.value=!0},children:e}),{exitOnCtrlC:!1});try{await t.waitUntilExit()}finally{t.unmount()}if(r.value)throw new K},E=async(e,r)=>{let t=r;return await G(e(i=>{t=i})),t},ne=e=>e.description===void 0?e.label:`${e.label} — ${e.description}`,U=()=>{const{exit:e}=I();B((r,t)=>{t.escape&&e()})},Ie=({badge:e,finish:r,initialIndex:t,message:i,options:o})=>{const{answer:c,submit:s}=R(r);return U(),c!==void 0?n(g,{answer:c,badge:e,message:i}):n(D,{badge:e,message:i,children:n(me,{accentColor:x,initialIndex:t,items:o.map(a=>({key:a.value,label:ne(a),value:a.value})),limit:Z,onSelect:a=>{s(a.value,o.find(h=>h.value===a.value)?.label??a.value)}})})},be=({badge:e,finish:r,message:t,options:i})=>{const{exit:o}=I(),{answer:c,submit:s}=R(r);return c!==void 0?n(g,{answer:c,badge:e,message:t}):n(D,{badge:e,message:t,children:n(fe,{accentColor:x,autoFocus:!0,commands:i.map(a=>({description:a.description,id:a.value,label:a.label})),limit:Z,onCancel:()=>{o()},onSelect:a=>{s(a,i.find(h=>h.value===a)?.label??a)},placeholder:"Type to filter…"})})},er=async(e,r,t)=>{if(!p()||r.length===0)return t?.default;const{badge:i}=t??{};if(r.length>xe)return E(c=>n(be,{badge:i,finish:c,message:e,options:r}),t?.default);const o=t?.default===void 0?-1:r.findIndex(c=>c.value===t.default);return E(c=>n(Ie,{badge:i,finish:c,initialIndex:o>=0?o:void 0,message:e,options:r}),t?.default)},Te=({badge:e,defaultValue:r,finish:t,message:i,placeholder:o})=>{const{answer:c,submit:s}=R(t);return U(),c!==void 0?n(g,{answer:c,badge:e,message:i}):n(D,{badge:e,message:i,children:n(ve,{defaultValue:r,onSubmit:a=>{const h=a.trim()===""?r:a.trim();s(h,h)},placeholder:o})})},rr=async(e,r)=>{const t=r?.default??"";if(!p())return t;const{badge:i}=r??{};return E(o=>n(Te,{badge:i,defaultValue:t,finish:o,message:e,placeholder:r?.placeholder}),t)},ye=({badge:e,defaults:r,finish:t,message:i,options:o})=>{const{answer:c,submit:s}=R(t),[a,h]=S(0),[m,w]=S(()=>new Set(r));return U(),B((b,v)=>{if(!(c!==void 0||o.length===0)){if(v.upArrow)h(f=>(f-1+o.length)%o.length);else if(v.downArrow)h(f=>(f+1)%o.length);else if(b===" "){const f=o[a];f!==void 0&&w(C=>{const _=new Set(C);return _.has(f.value)?_.delete(f.value):_.add(f.value),_})}else if(v.return){const f=o.filter(C=>m.has(C.value));s(f.map(C=>C.value),f.length>0?f.map(C=>C.label).join(", "):"none")}}}),c!==void 0?n(g,{answer:c,badge:e,message:i}):n(D,{badge:e,message:i,children:u(d,{flexDirection:"column",children:[n(l,{dimColor:!0,children:"space toggles · enter confirms · esc cancels"}),o.map((b,v)=>{const f=v===a;return n(l,{color:f?x:void 0,children:`${f?"▸ ":" "}${m.has(b.value)?"◼":"◻"} ${ne(b)}`},b.value)})]})})},tr=async(e,r,t)=>{const i=t?.defaults??[];if(!p()||r.length===0)return[...i];const{badge:o}=t??{};return E(c=>n(ye,{badge:o,defaults:i,finish:c,message:e,options:r}),[...i])},Ne=({badge:e,defaultYes:r,finish:t,message:i})=>{const{answer:o,submit:c}=R(t);return o!==void 0?n(g,{answer:o,badge:e,message:i}):u(d,{children:[e===void 0?null:n(ee,{spec:e}),n(l,{bold:!0,children:e===void 0?`${i} `:` ${i} `}),n(he,{defaultChoice:r?"confirm":"cancel",onCancel:()=>{c(!1,"No")},onConfirm:()=>{c(!0,"Yes")}})]})},Ee=async(e,r)=>{const t=r?.defaultYes===!0;if(!p())return t;const{badge:i}=r??{};return E(o=>n(Ne,{badge:i,defaultYes:t,finish:o,message:e}),!1)},nr=()=>p()?e=>Ee(e,{defaultYes:!0}):()=>Promise.resolve(!1),W="#c8a8ff",L="#d9c8ff",$e="#6b5b9a",P=({moon:e,prefix:r,suffix:t})=>u(d,{children:[n(l,{color:W,dimColor:!0,children:r}),typeof e=="string"?n(l,{color:L,children:e}):e,t===void 0?null:n(l,{color:W,children:t})]}),X=({left:e,right:r})=>u(l,{color:L,children:[e,n(l,{color:$e,children:"●●"}),r]}),ge=()=>u(d,{flexDirection:"column",paddingX:1,children:[n(P,{moon:".-‐-.",prefix:"· ✦ · ",suffix:" ✦"}),n(P,{moon:n(X,{left:"/",right:"\\"}),prefix:" ✦ · ",suffix:" ·"}),n(P,{moon:n(X,{left:"\\",right:"/"}),prefix:" . ✦ · "}),u(d,{children:[n(l,{bold:!0,color:x,children:" lunora init "}),n(l,{dimColor:!0,children:"· moonrise sequence"}),n(l,{color:L})]})]}),or=async e=>{p()&&await y(u(d,{flexDirection:"column",children:[n(ge,{}),n(d,{paddingX:1,children:n(l,{dimColor:!0,children:e})})]}))},Re=({label:e})=>u(d,{children:[n(l,{color:x,children:n(pe,{type:"dots"})}),u(l,{children:[" ",e]})]}),ir=async(e,r)=>{if(!p())return r();V();const t=H(n(Re,{label:e}));try{return await r()}finally{t.unmount()}},cr=async()=>{p()&&await y(u(d,{paddingX:1,children:[n(l,{color:L,children:ce}),u(d,{flexDirection:"column",marginLeft:2,children:[n(l,{bold:!0,color:x,children:le}),n(l,{children:ae})]})]}))},_e="#06b6d4",M=" ".repeat(9),lr=async e=>{p()&&await y(n(l,{bold:!0,children:`${M}${e}`}))},ar=async e=>{p()&&await y(u(d,{children:[n(l,{color:_e,children:`${T}◼`}),n(l,{children:` ${e}`})]}))},sr=async(e,r,t,i)=>{p()&&await y(u(d,{flexDirection:"column",children:[n($,{badge:e,message:r}),n(d,{flexDirection:"column",marginTop:1,children:t.map(o=>u(l,{children:[`${M}${o.lead} `,n(l,{color:x,children:o.code}),o.tail??""]},o.lead))}),n(d,{flexDirection:"column",marginTop:1,children:i.map(o=>u(l,{children:[`${M}${o.lead} `,n(l,{color:x,children:o.code}),o.tail??""]},o.lead))})]}))},Y="#a855f7",oe="#06b6d4",N=[Y,"#9b51f6","#8a5cf6","#6f86f6","#4aa6ef","#2bb6dd","#12bcd0",oe],O=N.length-2,F=(e,r)=>Array.from({length:Math.max(0,e)},()=>r),q=[...F(N.length-1,Y),...N,...F(N.length-1,oe),...N.toReversed()],k=q.map((e,r)=>{const t=q.slice(r,r+O);return[...t,...F(O-t.length,Y)]}),Ae=" ".repeat(Math.max(0,z-O)),ie=({label:e})=>{const[r,t]=S(0);de(()=>{t(o=>(o+1)%k.length)},90);const i=k[r%k.length]??[];return u(l,{children:[Ae,i.map((o,c)=>n(l,{color:o,children:"█"},c)),` ${e}`]})},De=({label:e,status:r})=>r==="running"?n(l,{color:x,children:`${T}▶ ${e}`}):r==="failed"?n(l,{color:"red",children:`${T}✖ ${e}`}):r==="done"?n(l,{dimColor:!0,children:`${T}■ ${e}`}):n(l,{dimColor:!0,children:`${T}□ ${e}`}),Le=async(e,r,t)=>{const i=[];let o;for(const[c,s]of e.entries()){if(t())break;r(c,"running");try{i.push(await s.run()),r(c,"done")}catch(a){r(c,"failed"),o=a;break}}return{failure:o,results:i}},Pe=(e,r,t,i)=>{let o=!0;return Le(e,(s,a)=>{o&&r(h=>h.map((m,w)=>w===s?a:m))},()=>!o).then(({failure:s,results:a})=>{t(a,s),setTimeout(()=>{o&&i()},400)}).catch(s=>{t([],s)}),()=>{o=!1}},ke=({end:e,onSettle:r,onStart:t,start:i,tasks:o})=>{const{exit:c}=I(),[s,a]=S(()=>o.map(()=>"pending"));A(()=>(t(),Pe(o,a,r,c)),[c,r,t,o]);const h=s.length>0&&s.every(m=>m==="done");return u(d,{flexDirection:"column",children:[h?u(d,{children:[n(l,{bold:!0,color:"green",children:`${T}✔`}),n(l,{bold:!0,color:"green",children:` ${e}`})]}):n(ie,{label:i}),o.map((m,w)=>n(De,{label:m.label,status:s[w]??"pending"},m.label))]})},ur=async(e,r)=>{if(!p()){const s=[];for(const a of e)s.push(await a.run());return s}let t=[],i,o=()=>{},c;try{await G(n(ke,{end:r.end,onSettle:(s,a)=>{t=s,i=a,o()},onStart:()=>{c=new Promise(s=>{o=s})},start:r.start,tasks:e}))}catch(s){throw await c,s}if(i!==void 0)throw Q(i);return t},Me=async(e,r)=>{const t=[];let i;for(const[o,c]of e.entries()){r(o);try{t.push(await c.task())}catch(s){i=s;break}}return{failure:i,values:t}},Oe=({badge:e,done:r,onSettle:t,steps:i})=>{const{exit:o}=I(),[c,s]=S(0),[a,h]=S(!1);return A(()=>{let m=!0,w;return Me(i,v=>{m&&s(v)}).then(({failure:v,values:f})=>{if(m){if(v!==void 0){t({error:v,ok:!1}),o();return}h(!0),w=setTimeout(()=>{m&&(t({ok:!0,values:f}),o())},400)}}).catch(()=>{}),()=>{m=!1,w!==void 0&&clearTimeout(w)}},[o,t,i]),a?n($,{badge:e,message:r}):n(ie,{label:i[c]?.running??""})},dr=async(e,r,t)=>{if(!p()){const o=[];for(const c of r)o.push(await c.task());return o}let i;if(await G(n(Oe,{badge:e,done:t,onSettle:o=>{i=o},steps:r})),i===void 0)throw new K;if(!i.ok)throw Q(i.error);return i.values};export{rr as a,Ee as b,nr as c,cr as d,Ze as e,or as f,tr as g,lr as h,ar as i,sr as j,ur as k,dr as l,er as t,ir as w};
@@ -0,0 +1 @@
1
+ const A="LUNORA_AI_GATEWAY_ID",_="LUNORA_AI_GATEWAY_ACCOUNT_ID",I="LUNORA_AI_GATEWAY_TOKEN",R="LUNORA_AI_PROXY_URL";export{R as A,I as a,A as b,_ as c};
@@ -0,0 +1,2 @@
1
+ import{r as A,c as g}from"./cloudflare-credentials-BVmZnDZk.mjs";import{spawnSync as x}from"node:child_process";import{readFileSync as p,writeFileSync as P,existsSync as w}from"node:fs";import{join as E}from"node:path";import{DEV_VARS_FILE as u,parseDevVariableEntries as k,upsertDevVariableLine as N,generateSecretValue as L,writeDevVariablesFileAtomically as F,isPlaceholderValue as y,isMintableSecretKey as K,mintableSecretKeysFor as U,secretSourcesFromBindings as M,inferLunoraBindings as W,resolveSchemaDirectory as V}from"@lunora/config";import{modify as B,applyEdits as Y,parse as z}from"jsonc-parser";import{r as H}from"./admin-token-VdUnvnKW.mjs";import{defaultSpawner as G}from"./createRecordingSpawner-01ZngIwK.mjs";import{toolchainExecArgs as J,detectPackageManager as X}from"@lunora/config/cli";const b=5e3,D=(e,t,s)=>`POST https://api.cloudflare.com/client/v4/accounts/${e}/artifacts/namespaces with body { "namespace": "${t}", "jurisdiction": "${s}" }`,q=e=>{let t="";try{const{errors:s}=JSON.parse(e.text);t=(s??[]).flatMap(n=>typeof n.message=="string"?[n.message]:[]).slice(0,2).join("; ")}catch{}return t===""?`HTTP ${String(e.status)}`:`HTTP ${String(e.status)}: ${t}`},Q=async(e,t,s)=>{const{jurisdiction:n,namespace:r}=e;try{const a=await g({accountId:t,apiToken:s,...e.fetch===void 0?{}:{fetch:e.fetch},init:{body:JSON.stringify({jurisdiction:n,namespace:r}),method:"POST",signal:AbortSignal.timeout(b)},path:"/artifacts/namespaces"});return a.ok?{}:{reason:q(a)}}catch(a){return{reason:a instanceof Error?a.message:String(a)}}},Z=async(e,t,s)=>{const n=await g({accountId:t,apiToken:s,...e.fetch===void 0?{}:{fetch:e.fetch},init:{signal:AbortSignal.timeout(b)},path:`/artifacts/namespaces/${encodeURIComponent(e.namespace)}`}).catch(()=>{}),r=n?.ok===!0?n.body.result:void 0;return typeof r=="object"&&r!==null&&"jurisdiction"in r?r.jurisdiction:void 0},j=(e,t,s,n)=>({fix:`A namespace's jurisdiction cannot change: create one with ${D(e,"<name>",s)}, point the binding's "namespace" at it, and move the repos over.`,message:`${t} is in the "${n}" jurisdiction, but the schema pins data to "${s}".`,verdict:"mismatch"}),ee=async(e,t,s,n)=>{const{jurisdiction:r,namespace:a}=e;let i;if(e.create===!0){if(i=(await Q(e,t,s)).reason,i===void 0)return{changesAccount:!0,message:`created ${n} in the "${r}" jurisdiction, as the schema pins.`,verdict:"ok"};const l=await Z(e,t,s);if(l===r)return{message:`${n} is in the "${r}" jurisdiction, as the schema pins.`,verdict:"ok"};if(typeof l=="string")return j(t,n,r,l)}if(e.missingOk===!0)return{changesAccount:!0,message:`${n} does not exist yet; it will be created in the "${r}" jurisdiction just before the deploy.`,verdict:"ok"};const c=i===void 0?"":` (${i})`,o=e.create===!0?` and could not be created${c}`:"";return{fix:`Create it before the first repo: ${D(t,a,r)}.`,message:`${n} does not exist${o}, and the first repo create() would make it unrestricted — the schema pins data to "${r}".`,verdict:"missing"}},De=async e=>{const{binding:t,jurisdiction:s,namespace:n}=e,r=`Artifacts namespace "${n}" (binding ${t})`,{accountId:a,token:i}=A(e.environment??process.env,e.accountId);if(i===void 0||a===void 0)return{fix:"Set CLOUDFLARE_API_TOKEN (with Artifacts edit access, which creating a missing namespace needs) and CLOUDFLARE_ACCOUNT_ID (or `account_id` in wrangler.jsonc) to check it.",message:`the jurisdiction of ${r} was not checked against the schema's "${s}".`,verdict:"unchecked"};let c;try{c=await g({accountId:a,apiToken:i,...e.fetch===void 0?{}:{fetch:e.fetch},init:{signal:AbortSignal.timeout(b)},path:`/artifacts/namespaces/${encodeURIComponent(n)}`})}catch(l){return{message:`the jurisdiction of ${r} could not be read (${l instanceof Error?l.message:String(l)}).`,verdict:"unchecked"}}if(!c.ok&&c.status===404)return ee(e,a,i,r);if(!c.ok)return{...c.status===401||c.status===403?{fix:`Give CLOUDFLARE_API_TOKEN Artifacts edit access on account ${a}.`}:{},message:`the jurisdiction of ${r} could not be read (HTTP ${String(c.status)}).`,verdict:"unchecked"};const{result:o}=c.body,d=typeof o=="object"&&o!==null&&"jurisdiction"in o?o.jurisdiction:void 0;return typeof d!="string"?{message:`the jurisdiction of ${r} could not be read (the response carried none).`,verdict:"unchecked"}:d===s?{message:`${r} is in the "${d}" jurisdiction, as the schema pins.`,verdict:"ok"}:j(a,r,s,d)},m=100,f=500,S=10,te=5e3,h="Delete the Workers you no longer need (old preview / staging deploys free their classes), or set `durableObjects: { merge: true }` in lunora.config before an app's first deploy so it spends one class instead of up to three.",ne=e=>e>=f?{fix:h,message:`the Cloudflare account has ${String(e)} Durable Object classes — the Workers Paid cap is ${String(f)}, so a deploy that adds one will fail.`,verdict:"full"}:e>=f-S?{fix:h,message:`the Cloudflare account has ${String(e)} of ${String(f)} Durable Object classes (Workers Paid cap).`,verdict:"near"}:e>=m-S&&e<=m?{fix:h,message:`the Cloudflare account has ${String(e)} Durable Object classes — on Workers Free the cap is ${String(m)} (Paid: ${String(f)}).`,verdict:"near"}:{message:`the Cloudflare account has ${String(e)} Durable Object classes (caps: ${String(m)} Free, ${String(f)} Paid).`,verdict:"ok"},je=async(e={})=>{const{accountId:t,token:s}=A(e.environment??process.env,e.accountId);if(s===void 0||t===void 0)return{fix:"Set CLOUDFLARE_API_TOKEN (Workers Scripts Read) and CLOUDFLARE_ACCOUNT_ID (or `account_id` in wrangler.jsonc) to check it.",message:"the account's Durable Object class count was not checked.",verdict:"unchecked"};try{const n=await g({accountId:t,apiToken:s,...e.fetch===void 0?{}:{fetch:e.fetch},init:{signal:AbortSignal.timeout(te)},path:"/workers/durable_objects/namespaces?per_page=1"}),r=n.ok?n.body.result_info:void 0,a=typeof r=="object"&&r!==null&&"total_count"in r?r.total_count:void 0;return typeof a!="number"?{message:`the account's Durable Object class count could not be read${n.ok?"":` (HTTP ${String(n.status)})`}.`,verdict:"unchecked"}:ne(a)}catch(n){return{message:`the account's Durable Object class count could not be read (${n instanceof Error?n.message:String(n)}).`,verdict:"unchecked"}}},$=e=>e.endsWith("S")?e.slice(0,-1):e,T=e=>e.replaceAll(/([a-z\d])([A-Z])/gu,"$1_$2").toUpperCase().split(/[_-]+/u).filter(t=>t.length>0),C=new Set(["CREDENTIAL","DSN","PASSPHRASE","PASSWD","PASSWORD","SECRET","TOKEN"]),O=["ACCESS_KEY","API_KEY","ENCRYPTION_KEY","PRIVATE_KEY","SIGNING_KEY"],re=new RegExp(`(?:${[...C,...O.map(e=>e.replaceAll("_",""))].join("|")})S?$`,"iu"),se=e=>T(e).some(t=>t==="PUBLIC"||t==="PUBLISHABLE"),ae=e=>{if(se(e))return!1;const t=T(e);if(t.some(n=>C.has($(n))))return!0;const s=$(t.join("_"));return O.some(n=>s===n||s.endsWith(`_${n}`))||re.test(e)},R=e=>{const t=e.trim();return t===""||t.startsWith("<")&&t.endsWith(">")},ie=/replace[-_\s]?(?:with|me)(?![a-z])/iu,Te=e=>R(e)||ie.test(e),ce=e=>R(e)||e.trim().toLowerCase().includes("replace"),I=/\r?\n/u,oe=async(e,t)=>{const{args:s,command:n}=J(X(t),{args:e,tool:"wrangler"});try{const r=await G({args:s,captureStderr:!0,captureStdoutSilently:!0,command:n,cwd:t});return{code:r.code,stderr:r.stderr??"",stdout:r.stdout??""}}catch(r){return{code:1,stderr:r instanceof Error?r.message:String(r),stdout:""}}},v=async(e,t)=>{const s=await e(["d1","list","--json"],t);if(s.code!==0)return;let n;try{n=JSON.parse(s.stdout)}catch{return}if(!Array.isArray(n))return;const r=new Map;for(const a of n)typeof a.name=="string"&&typeof a.uuid=="string"&&r.set(a.name,a.uuid);return r},de=e=>{const t=z(e);return(Array.isArray(t?.d1_databases)?t.d1_databases:[]).flatMap((n,r)=>{if(n===null||typeof n!="object")return[];const a=n,i=typeof a.database_id=="string"?a.database_id:"";return ce(i)?[{binding:typeof a.binding=="string"&&a.binding!==""?a.binding:"<unnamed>",index:r,name:typeof a.database_name=="string"&&a.database_name!==""?a.database_name:void 0}]:[]})},ue=async(e,t,s,n)=>{const r=await v(s,t.cwd);if(r===void 0){n.skipped.push(`D1 "${e.binding}": could not run \`wrangler d1 list --json\`. Check that wrangler is installed in this project and logged in (\`wrangler login\`), then retry.`);return}const a=r.get(e.name);if(a!==void 0)return a;if(t.dryRun){n.applied.push(`would run \`wrangler d1 create ${e.name}\` and write its id into ${e.binding}`);return}const i=await s(["d1","create",e.name],t.cwd);if(i.code!==0){const d=i.stderr.trim()||`exit ${String(i.code)}`;n.skipped.push(`D1 "${e.binding}": \`wrangler d1 create ${e.name}\` failed: ${d}`);return}const o=(await v(s,t.cwd))?.get(e.name);return o===void 0&&n.skipped.push(`D1 "${e.binding}": created ${e.name} but could not read back its id.`),o},le=async(e,t)=>{if(e.configPath===void 0)return;const s=e.runner??oe,n=p(e.configPath,"utf8"),r=de(n);let a=n;for(const i of r){if(i.name===void 0){t.skipped.push(`D1 "${i.binding}" has no database_name, so there is no database to create or reuse.`);continue}const c=await ue({...i,name:i.name},e,s,t);if(c!==void 0){const o=B(a,["d1_databases",i.index,"database_id"],c,{formattingOptions:{eol:`
2
+ `,insertSpaces:!0,tabSize:4}});a=Y(a,o),t.applied.push(`${i.binding}: database_id set to the id of D1 "${i.name}"`)}}!e.dryRun&&a!==n&&P(e.configPath,a)},fe=e=>{const t=x("git",["check-ignore","-q",u],{cwd:e,stdio:"ignore"});if(t.status===0)return!0;if(t.status===1)return!1;const s=E(e,".gitignore");return w(s)&&p(s,"utf8").split(I).some(n=>n.trim()===u)},me=async(e,t)=>{try{return U(M(await W({projectRoot:e,schemaDir:V(e)})))}catch{t.skipped.push(`${u}: could not read the project's bindings, so the relay key was not checked against its role.`);return}},ge=(e,t,s,n,r)=>{const a=[],i=new Set(t.split(I).flatMap(c=>{const[o]=k(c);return o!==void 0&&!y(o.value)?[o.key]:[]}));H({cwd:e}).source===void 0&&!i.has("LUNORA_ADMIN_TOKEN")&&a.push("LUNORA_ADMIN_TOKEN");for(const c of s)!ae(c.key)||!y(c.value)||i.has(c.key)||(K(c.key,c.value,r)?a.push(c.key):n.skipped.push(`${u}: ${c.key} is a provider key and cannot be minted here; fill it in by hand.`));return a},he=async(e,t)=>{const s=E(e.cwd,u),n=w(s)?p(s,"utf8"):"",r=ge(e.cwd,n,k(n),t,await me(e.cwd,t));if(r.length===0)return;if(!fe(e.cwd)){t.skipped.push(`${u} is not in .gitignore, so no secret is written there. Add \`${u}\` to .gitignore first.`);return}if(e.dryRun){t.applied.push(`would mint ${r.join(", ")} into ${u}`);return}let a=n;for(const i of r)a=N(a,i,L());F(s,a),t.applied.push(`minted ${r.join(", ")} into ${u}`)},Ce=async e=>{const t={applied:[],skipped:[]};return await le(e,t),await he(e,t),t},Oe=e=>{switch(e){case"boolean":return"boolean";case"date":case"number":case"timestamp":return"number";case"id":case"literal":case"string":return"string";default:return}},pe=/already (?:exists|indexed)|duplicate/iu,_=e=>["vectorize","create-metadata-index",e.index,`--property-name=${e.property}`,`--type=${e.type}`],be=async(e,t)=>{try{return await e(t)}catch(s){return{code:1,stderr:s instanceof Error?s.message:String(s)}}},Re=async e=>{const{cwd:t,entries:s,exec:n,logger:r,spawner:a}=e,i=[];for(const c of s){const o=await be(a,{args:[...n.args,..._(c)],captureStderr:!0,command:n.command,cwd:t,stdoutToStderr:!0});if(o.code===0){i.push({entry:c,status:"created"});continue}const d=`${o.stderr??""}${o.stdout??""}`;if(pe.test(d)){i.push({entry:c,status:"exists"});continue}i.push({entry:c,error:d.trim()||`exit code ${String(o.code)}`,status:"failed"}),r.warn(`could not create the Vectorize metadata index for "${c.property}" on "${c.index}" — filters on that property will match nothing until it exists. Run: wrangler ${_(c).join(" ")}`)}return i};export{Ce as a,ce as b,ae as c,_ as d,je as e,De as f,Re as g,Te as i,Oe as m};
@@ -0,0 +1 @@
1
+ import{findWranglerFile as a,readWranglerJsonc as t}from"@lunora/config/cloudflare";const i=n=>{const e=a(n);if(!e)return;const{parsed:r}=t(e);return typeof r?.name=="string"&&r.name.length>0?r.name:void 0};export{i as r};
@@ -0,0 +1 @@
1
+ import{resolveDeployDriver as c,resolveProjectTarget as d}from"@lunora/config";import{defaultSpawner as l}from"./createRecordingSpawner-01ZngIwK.mjs";import{toolchainExecArgs as i,detectPackageManager as m}from"@lunora/config/cli";const u=async(e,t,o)=>{try{const r=await l({args:t,captureStderr:!0,captureStdoutSilently:!0,command:e,cwd:o});return{code:r.code,stderr:r.stderr??"",stdout:r.stdout??""}}catch(r){return{code:1,stderr:r instanceof Error?r.message:String(r),stdout:""}}},f=e=>{let t;try{t=JSON.parse(e)}catch{return}return Array.isArray(t)?[...t.map(r=>r!==null&&typeof r=="object"?r.name:void 0).filter(r=>typeof r=="string"&&r.length>0)].toSorted((r,a)=>r.localeCompare(a)):void 0},S=async e=>{const t=c(e.target??d(e.cwd)),o=t.toolchain?.secretList?.({environment:e.env,temporary:e.temporary});if(o===void 0)return{error:`deploy target "${t.id}" has no secret store to list`,names:[],ok:!1};const{args:r,command:a}=i(m(e.cwd),o),s=await(e.runner??u)(a,r,e.cwd);if(s.code!==0)return{error:s.stderr.trim()||`wrangler secret list exited ${String(s.code)}`,names:[],ok:!1};const n=f(s.stdout);return n===void 0?{error:"could not parse `wrangler secret list --format json` output",names:[],ok:!1}:{names:n,ok:!0}};export{S as l};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lunora/cli",
3
- "version": "1.0.0-alpha.45",
4
- "description": "The Lunora CLI: init, dev, deploy, codegen, run, reset, and migrate commands",
3
+ "version": "1.0.0-alpha.450",
4
+ "description": "The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands",
5
5
  "keywords": [
6
6
  "agent-skills",
7
7
  "cli",
@@ -45,33 +45,57 @@
45
45
  "types": "./dist/index.d.ts",
46
46
  "import": "./dist/index.mjs"
47
47
  },
48
+ "./cli": {
49
+ "types": "./dist/cli.d.ts",
50
+ "import": "./dist/cli.mjs"
51
+ },
48
52
  "./package.json": "./package.json"
49
53
  },
50
54
  "publishConfig": {
51
55
  "access": "public"
52
56
  },
53
57
  "dependencies": {
54
- "@bomb.sh/tab": "0.0.17",
55
- "@lunora/codegen": "1.0.0-alpha.19",
56
- "@lunora/config": "1.0.0-alpha.33",
57
- "@lunora/container": "1.0.0-alpha.5",
58
- "@lunora/d1": "1.0.0-alpha.13",
59
- "@lunora/seed": "1.0.0-alpha.7",
60
- "@visulima/cerebro": "3.0.0-alpha.32",
61
- "@visulima/error": "6.0.0-alpha.34",
62
- "@visulima/fs": "5.0.0-alpha.32",
63
- "@visulima/pail": "4.0.0-alpha.22",
64
- "@visulima/path": "3.0.0-alpha.13",
65
- "@visulima/spinner": "1.0.0-alpha.4",
66
- "@visulima/tui": "1.0.0-alpha.26",
67
- "cfonts": "^3.3.1",
68
- "giget": "3.3.0",
58
+ "@bomb.sh/tab": "0.0.22",
59
+ "@lunora/advisor": "1.0.0-alpha.270",
60
+ "@lunora/bindings": "1.0.0-alpha.141",
61
+ "@lunora/codegen": "1.0.0-alpha.371",
62
+ "@lunora/config": "1.0.0-alpha.426",
63
+ "@lunora/container": "1.0.0-alpha.97",
64
+ "@lunora/d1": "1.0.0-alpha.218",
65
+ "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
66
+ "@lunora/mcp": "1.0.0-alpha.273",
67
+ "@lunora/runtime": "1.0.0-alpha.253",
68
+ "@lunora/seed": "1.0.0-alpha.267",
69
+ "@visulima/cerebro": "4.0.1",
70
+ "@visulima/error": "6.1.0",
71
+ "@visulima/fs": "7.0.0",
72
+ "@visulima/pail": "6.0.0",
73
+ "@visulima/path": "5.0.0",
74
+ "@visulima/spinner": "1.0.1",
75
+ "@visulima/tui": "5.0.0",
76
+ "@visulima/tui-kit": "1.0.34",
77
+ "adm-zip": "0.6.1",
78
+ "csv-parse": "7.0.3",
79
+ "giget": "3.3.1",
69
80
  "jsonc-parser": "^3.3.1",
70
- "magic-string": "^0.30.21",
71
- "react": "^19.2.7",
81
+ "magic-string": "^1.4.2",
82
+ "react": "^19.3.0",
72
83
  "react-reconciler": "^0.33.0",
84
+ "smol-toml": "1.9.0",
73
85
  "ts-morph": "^28.0.0"
74
86
  },
87
+ "peerDependencies": {
88
+ "mysql2": "*",
89
+ "pg": "*"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "mysql2": {
93
+ "optional": true
94
+ },
95
+ "pg": {
96
+ "optional": true
97
+ }
98
+ },
75
99
  "engines": {
76
100
  "node": "^22.15.0 || >=24.11.0"
77
101
  }
package/skills/README.md CHANGED
@@ -9,21 +9,40 @@ framework correctly. They ship inside `@lunora/cli` and are discovered by the
9
9
  Each skill is a `SKILL.md` with YAML frontmatter (`name`, `description`) in its
10
10
  own directory:
11
11
 
12
- | Skill | Use for |
13
- | -------------------------- | --------------------------------------------------------------------------- |
14
- | `lunora` | Router — start here, then switch to the matching skill below. |
15
- | `lunora-quickstart` | `lunora init` / adding Lunora to an app + first round-trip. |
16
- | `lunora-functions` | Core authoring rules — schema, validators, query/mutation/action, `ctx.db`. |
17
- | `lunora-realtime` | Client reactivity — live hooks, optimistic updates, `@lunora/db`. |
18
- | `lunora-setup-auth` | Authentication via `lunora registry add auth` (+ providers). |
19
- | `lunora-setup-mail` | Transactional email via `lunora registry add mail` — `sendEmail` actions. |
20
- | `lunora-setup-storage` | R2 file storage via `lunora registry add storage` — signed upload/download. |
21
- | `lunora-setup-scheduler` | Deferred (`ctx.scheduler`) + cron jobs (`lunora registry add crons`). |
22
- | `lunora-create-package` | Building a reusable registry item or `@lunora/*` package. |
23
- | `lunora-migration-helper` | Schema/data migrations, `.global()` D1 flow, the drift gate. |
24
- | `lunora-deploy` | Deploying to Cloudflare — wrangler bindings, secrets, the gate. |
25
- | `lunora-performance-audit` | Scans, indexes, OCC write conflicts, sharding/`.global()`. |
12
+ | Skill | Use for |
13
+ | -------------------------------- | ---------------------------------------------------------------------------- |
14
+ | `lunora` | Router — start here, then switch to the matching skill below. |
15
+ | `lunora-quickstart` | `lunora init` / adding Lunora to an app + first round-trip. |
16
+ | `lunora-functions` | Core authoring rules — schema, validators, query/mutation/action, `ctx.db`. |
17
+ | `lunora-realtime` | Client reactivity — live hooks, optimistic updates, `@lunora/db`. |
18
+ | `lunora-setup-auth` | Authentication via `lunora registry add auth` (+ providers). |
19
+ | `lunora-setup-mail` | Transactional email via `lunora registry add mail` — `sendEmail` actions. |
20
+ | `lunora-setup-storage` | R2 file storage via `lunora registry add storage` — signed upload/download. |
21
+ | `lunora-setup-scheduler` | Deferred (`ctx.scheduler`) + cron jobs (`lunora registry add crons`). |
22
+ | `lunora-setup-hyperdrive` | Existing Postgres/MySQL from an action — `ctx.sql`, non-reactive. |
23
+ | `lunora-setup-hyperdrive-global` | Postgres/MySQL as a reactive `.global()` backend; D1 → Hyperdrive migration. |
24
+ | `lunora-create-package` | Building a reusable registry item or `@lunora/*` package. |
25
+ | `lunora-migration-helper` | Schema/data migrations, `.global()` DDL flow, the drift gate. |
26
+ | `lunora-deploy` | Deploying to Cloudflare — wrangler bindings, secrets, the gate. |
27
+ | `lunora-performance-audit` | `lunora insights`, scans, indexes, OCC conflicts, sharding/`.global()`. |
28
+ | `lunora-cloudflare-audit` | Launch/bill audit: doctor + advisor signal, fan-out, cron, public-path cost. |
26
29
 
27
- These are mirrored into `.agents/skills/` and `.claude/skills/` (via symlinks)
28
- so agents working inside this repo pick them up directly. The source of truth
29
- lives here so the published `@lunora/cli` tarball carries them.
30
+ These are mirrored (via symlinks) into `.agents/skills/` and `.claude/skills/`,
31
+ so agents working inside this repo pick them up directly, and into
32
+ `plugins/lunora/skills/`, the payload of the Claude Code / Codex plugin. The
33
+ source of truth lives here so the published `@lunora/cli` tarball carries them —
34
+ `lunora rules install` copies this directory into a consumer project.
35
+
36
+ **Adding a skill?** Create it here, then mirror it through all three hops:
37
+
38
+ ```bash
39
+ ln -s ../../packages/cli/skills/<name> .agents/skills/<name>
40
+ ln -s ../../.agents/skills/<name> .claude/skills/<name>
41
+ ln -s ../../../packages/cli/skills/<name> plugins/lunora/skills/<name>
42
+ ```
43
+
44
+ `scripts/check-skill-mirrors.js` (run on every `pnpm install`) fails if a mirror
45
+ is missing, dangling, or has become a real directory — a copied directory keeps
46
+ resolving while it silently drifts from the source, so it is treated as an
47
+ error rather than a warning. Forget a hop and it prints the exact `ln -s` for
48
+ the one you missed, so `pnpm install` is the shortest path to the right command.