@lunora/cli 1.0.0-alpha.422 → 1.0.0-alpha.423
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import{readServiceBindings as
|
|
2
|
-
`)),n.length>0&&o.write(n),o.pipe(r),r.pipe(o)});o.setTimeout(gr,()=>o.destroy()),o.on("error",()=>r.destroy()),r.on("error",()=>o.destroy())},wr=async e=>{const r=e.host??"127.0.0.1",n=r==="127.0.0.1"||r==="localhost"||r==="::1",t=new URL(e.workerOrigin);let o=P(e.logger,import.meta.url),i=C(import.meta.url);const l=Pe({adminToken:n?Ce(e.cwd):void 0,basePath:"/",dataEditable:n,rulesInstalled:W(e.cwd).installed,runAsIdentity:n,schemaEditable:n,scriptSrc:"/studio.js",styleHref:"/styles.css"}),d=(c,s,u,m,h)=>{Ve(c,s,h,i)||(s.statusCode=200,s.setHeader("Content-Type",m),s.end(u))},a=(c,s,u)=>{c.statusCode=s,c.setHeader("Content-Type","text/plain"),c.end(u)},f=(c,s,u,m)=>{if(n){Ne(c,s,u,e.cwd,{apiSpec:e.apiSpec,lazyFunctions:E(e.lazyFunctions)});return}a(s,403,m)},S=(c,s,u)=>{const m=c==="/styles.css",h=Ie(c);if(!m&&!h)return!1;const p=C(import.meta.url);if(p!==i&&(o=P(e.logger,import.meta.url),i=p),o===void 0)return a(u,501,"Lunora studio assets not found — install and build @lunora/studio."),!0;if(m)return d(s,u,o.styles,"text/css; charset=utf-8","styles.css"),!0;const v=c.slice(c.lastIndexOf("/")+1),g=je(v,import.meta.url);return g===void 0?(a(u,404,"Not found"),!0):(d(s,u,g,Me(v),v),!0)},y=Buffer.from(l),w=ke((c,s)=>{const u=O(c.url??"/");if(n){const h=$(c,e.logger);if(h!==void 0){a(s,403,h);return}}if(u.startsWith(N)){if(!n){a(s,403,"Lunora studio: the worker admin proxy is only available on a loopback bind.");return}j(c,s,t);return}if(u===Oe){f(c,s,We,"Lunora schema editing is only available on loopback hosts in dev.");return}if(u===$e){f(c,s,He,"Lunora policy scaffolding is only available on loopback hosts in dev.");return}if(u===Le){f(c,s,xe,"Lunora data seeding is only available on loopback hosts in dev.");return}if(S(u,c,s))return;const m=c.headers["sec-fetch-mode"];if(n&&typeof m=="string"&&m!=="navigate"){j(c,s,t);return}Fe(s,y)});return w.on("upgrade",(c,s,u)=>{if(!n||$(c,e.logger)!==void 0){s.destroy();return}O(c.url??"").startsWith(N)?mr(c,s,u,t):s.destroy()}),await new Promise((c,s)=>{w.once("error",u=>{u.code==="EADDRINUSE"?s(new Error(`studio port ${String(e.port)} is already in use — pass a different port with --port, or stop the process using it`,{cause:u})):s(u)}),w.listen(e.port,r,()=>{c()})}),{close:()=>new Promise(c=>{w.close(()=>{c()})}),url:`http://${r==="0.0.0.0"||r==="::"?"localhost":r}:${String(e.port)}`}},hr=async e=>{const{cwd:r,logger:n,origin:t,signal:o}=e,i=e.probe??Ge,l=ze(e.readyTimeoutMs),d=Date.now()+l,a=()=>o.aborted;for(;!a()&&Date.now()<d;){let f=!1;try{f=await i(t,o)}catch{}if(a()||Date.now()>=d)break;if(f)return H(r,{readyAt:new Date().toISOString()},{expectedPid:process.pid}),Y(r)?.readyAt!==void 0;try{await Ue(Xe,void 0,{signal:o})}catch{}}return a()||n.warn(`server did not answer on ${t} within ${String(Math.round(l/1e3))}s — .lunora/dev.json will have no readyAt, so anything polling for readiness will keep waiting. The server itself is unaffected; raise LUNORA_DEV_READY_TIMEOUT_MS if it is just slow to boot.`),!1},yr=(e,r,n,t)=>{e.info(""),e.success("Lunora dev"),e.info(` ➜ Worker: ${r.workerOrigin}`),n!==void 0&&e.info(` ➜ Studio: ${n}`),r.runsCodegenWatch&&e.info(" ➜ Codegen: watching lunora/"),t!==void 0&&e.info(` ➜ Supervisor: ${t} (needs) · ${B} (status)`),r.remote.enabled&&(r.remote.bindings.length>0?e.info(` ➜ Remote: ${r.remote.bindings.join(", ")} → deployed worker`):r.remote.reason!==void 0&&e.warn(` ➜ Remote: requested but inactive (${r.remote.reason}) — running fully local`));for(const o of r.remote.withheld)e.warn(` ➜ ${ge(o)}`);e.info("")},Sr=(e,r)=>{W(r).installed||!le()||(e.info(` ⓘ ${ue}`),e.info(""))},pr=async(e,r,n)=>{try{const o=await re({cache:n,projectRoot:r,schemaDir:te(r)}),i=ne(o),l=(e.ensureExample??oe)(r,i);if(l.length>0){const d=i.map(a=>a.includes(":")?`${a.replace(":"," (")})`:a);e.logger.info(`Updated .dev.vars.example with secrets for: ${d.join(", ")} (${l.join(", ")})`)}}catch{}(await(e.ensureEnv??ae)({confirm:Be(),cwd:r,info:o=>{e.logger.info(o)}})).status==="declined"&&!ie()&&e.logger.info(`hint: ${T} was not scaffolded (non-interactive run). Copy ${se} → ${T} and fill in secrets, or run \`lunora dev\` in an interactive terminal to scaffold automatically.`);try{(e.fillSecrets??ce)({cwd:r,info:o=>{e.logger.info(o)}})}catch{}},Er=(e,r,n,t,o)=>{if(e.flavor!=="wrangler")return;t!==void 0&&H(r,{studioUrl:t});let i;try{i=sr(r,n)}catch{}return yr(n,e,t,o),i},br=(e,r)=>{const n=Number(process.env[_]),t=q(r,{background:process.env[x]==="1",logFile:process.env[ee],mode:"cli",pid:process.pid,startedAt:new Date().toISOString(),url:e.workerOrigin},Number.isInteger(n)&&n>0?{supersedePid:n}:void 0);return t.ok?void 0:t.existing},Dr=e=>{const{cwd:r,destination:n,logger:t,plan:o}=e,i=n!==void 0,l=n??de,d=we({destination:l,dev:{...o.flavor==="wrangler"?{origin:o.workerOrigin}:{},statusFile:B},logger:i?t:{...t,success:()=>{},warn:()=>{}},projectRoot:r});return d.error!==void 0?i?d:(t.debug?.(`skipped the default binding manifest: ${d.error}`),{}):{written:l}},_r=async(e,r,n,t)=>{if(r.studioEnabled)try{return await(e.startStudio??wr)({apiSpec:e.apiSpec,lazyFunctions:E(e.lazyFunctions),cwd:n,logger:{warnOnce:o=>{t.warn(o)}},port:r.studioPort,workerOrigin:r.workerOrigin})}catch(o){t.warn(`studio server failed to start (${o instanceof Error?o.message:String(o)}) — continuing without it`);return}},kr=e=>{const r=[e.runsCodegenWatch?"codegen watch":void 0,e.studioEnabled?"studio":void 0].filter(t=>t!==void 0);return`--no-worker: not starting wrangler. ${r.length>0?`${r.join(" + ")} running`:"nothing else to run"}; your task runner owns the worker on ${e.workerOrigin}.`},Rr=(e,r,n,t,o)=>{if(!(e.sidecar===void 0||!ar(r)))try{M({apiSpec:r.apiSpec,lazyFunctions:E(r.lazyFunctions),lunoraDirectory:"lunora",projectRoot:n,target:o,...U(n)})}catch(i){t.warn(`codegen (pre-sidecar) failed: ${i instanceof Error?i.message:String(i)} — the framework dev server will retry`)}},Tr=e=>e.flavor==="vite"?"starting vite dev (worker + studio + codegen run inside Vite via @lunora/vite)":`starting ${e.wrangler.tag} dev + studio`,Ar=async(e,r,n,t,o)=>{try{return e.celldSession===!0?await ir({logger:o,port:e.workerPort,projectRoot:t,start:r.startCelldSession}):n(e.wrangler,o)}catch(i){o.error(`could not start the worker: ${i instanceof Error?i.message:String(i)}`);return}},Pr=async(e,r,n)=>{const t=await(e.startHyperdrive??ve)({onWarning:o=>{n.warn(o)},projectRoot:r});return t!==void 0&&t.bindings.length>0&&n.info(`Hyperdrive ${t.bindings.join(", ")}: embedded Postgres (PGlite), data in .wrangler/state/lunora-pglite. Set CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING> to use your own.`),t},Cr=async e=>{const{logger:r}=e,n=Q(),t=e.cwd??process.cwd(),o=e.flavor??Qe(t),i=De(t,e.target);if(i.target===void 0)throw new Error(i.error??"unknown deploy target");const{target:l}=i,d=Ze(l,o,r);d==="wrangler"&&await cr(t,r,void 0,l,void 0,n);const a=await qe({...e,flavor:d,target:l}),f={remoteCleanup:a.remote.cleanup,serviceConfigCleanup:a.serviceConfigCleanup};try{const S=Number(process.env[_]),y=V(t);if(y!==void 0&&y.pid!==process.pid&&y.pid!==S)return R(r,y),{code:0,plan:a};const w=br(a,t);if(w!==void 0)return R(r,w),{code:0,plan:a};(a.flavor==="vite"||a.flavor==="framework-worker")&&(a.wrangler.env={...a.wrangler.env,[_]:String(process.pid)}),a.workerEnabled&&l==="cloudflare"&&(f.hyperdrive=await Pr(e,t,r)),await pr(e,t,n),r.info(Tr(a)),er(r,t),a.ipv4LoopbackForced&&r.info("no IPv6 loopback (::1) on this host — binding the worker to 127.0.0.1 (--ip) so wrangler dev doesn't crash. Pin `dev.ip` in wrangler.jsonc to override."),a.runsCodegenWatch&&(f.codegen=(e.startCodegen??vr)({apiSpec:e.apiSpec,lazyFunctions:E(e.lazyFunctions),jsonLogs:e.jsonLogs,logger:r,projectRoot:t,target:l})),f.studio=await _r(e,a,t,r);const c=Dr({cwd:t,destination:e.emitBindings,logger:r,plan:a});if(c.error!==void 0)return r.error(c.error),{code:k.USAGE,plan:a};await f.codegen?.ready;const s=f.studio?.url;a.frameworkHint!==void 0&&r.warn(a.frameworkHint);const u=()=>{a.flavor==="wrangler"&&(f.readyProbe=new AbortController,hr({cwd:t,logger:r,origin:a.workerOrigin,probe:e.probeReady,signal:f.readyProbe.signal}))};if(!a.workerEnabled)return u(),r.info(kr(a)),f.tunnel=L({cwd:t,logger:r,plan:a,tunnel:e.tunnel}),{code:await(e.waitForInterrupt??rr)(r),plan:a};Rr(a,e,t,r,l);const m=e.startWorker??tr,h=await Ar(a,e,m,t,r);if(h===void 0)return{code:k.FAILURE,plan:a};const p=a.sidecar===void 0?void 0:m(a.sidecar,r);return u(),f.containerLogs=Er(a,t,r,s,c.written),f.tunnel=L({cwd:t,logger:r,plan:a,tunnel:e.tunnel}),Sr(r,t),{code:await nr(h,p,r),plan:a}}finally{f.readyProbe?.abort(),Z(t,process.pid),await or(f)}},Or=e=>({codegen:e.codegen===!1?!1:void 0,studio:e.studio===!1?!1:void 0,worker:e.worker===!1?!1:void 0}),$r=e=>{if(e.local===!0&&e.remote===!0)return"`--local` and `--remote` are mutually exclusive — pass at most one.";const{entries:r,invalid:n}=z(e.allowMail);if(n.length>0)return`\`--allow-mail\` takes email addresses or '*@domain' — not ${n.map(t=>`"${t}"`).join(", ")}.`;if(r.length>0&&e.tunnel!==!0)return"`--allow-mail` only applies to a tunnel — add `--tunnel`."},Lr=e=>e.tunnel===!0?{allowMail:z(e.allowMail).entries}:void 0,rt=be(async({argument:e,cwd:r,logger:n,options:t})=>{const o=t.json===!0,i=Ye({cwd:r,json:o,lines:t.lines,logger:n,subcommand:e[0]});if(i!==void 0)return i;const l=process.env[x]==="1",d=l?void 0:J(),a=o||d!==void 0;a&&_e(),d!==void 0&&t.background!==!0&&n.info(`AI agent detected (${d.name} via ${d.variable}) — starting the dev server in background mode with JSON logs. Set LUNORA_AGENT_MODE=0 to opt out.`);const f=$r(t);if(f!==void 0)return n.error(`dev: ${f}`),{code:k.USAGE};const S=Lr(t),y=t.local===!0?!1:fe({configPreference:K(r),envValue:process.env.LUNORA_REMOTE,flag:t.remote});if(!l&&(t.background===!0||d!==void 0)){const w=V(r);return w!==void 0?(R(n,w),{code:0}):(S?.allowMail.length===0&&Je(n),Ke({cwd:r,jsonLogs:a,logger:n,options:t,remote:y}))}return Cr({apiSpec:me(t.apiSpec),cwd:r,emitBindings:t.emitBindings,inspectorPort:t.inspectorPort,lazyFunctions:E(t.lazyFunctions),jsonLogs:a,local:t.local,logger:n,port:t.port,remote:y,target:t.target,tunnel:S,workerPort:t.workerPort,...Or(t)})});export{$r as devFlagConflict,rt as execute,Or as negatableDevFlags,Cr as runDevCommand};
|
|
1
|
+
import{readServiceBindings as Z,createCodegenProject as q,refreshCodegenProject as ee,findTsconfig as re,projectConfigCandidatePaths as te,PROJECT_CONFIG_FILENAMES as ne,runCodegen as V}from"@lunora/codegen";import{runPostCodegenHook as oe,resolveLazyFunctions as b,detectAgentRules as U,updateDevServerState as B,readDevServerState as ae,DEV_DAEMON_ENV as z,detectAiAgent as ie,readProjectRemotePreference as se,readLiveDevServerState as G,createDiscoveryCache as ce,DEV_HANDOFF_ENV as R,clearDevServerState as de,claimDevServerState as le,DEV_LOG_FILE_ENV as ue,inferLunoraBindings as fe,resolveSchemaDirectory as ge,secretSourcesFromBindings as ve,ensureDevVarsExample as me,ensureDevVariables as we,isInteractive as he,DEV_VARS_FILE as T,DEV_VARS_EXAMPLE_FILE as ye,fillDevSecrets as pe,DEV_BINDINGS_FILE as Se,DEV_STATE_FILE as J,claimAgentRulesHint as Ee,AGENT_RULES_HINT as be}from"@lunora/config";import{wranglerCodegenInputs as X,resolveRemoteEnabled as _e,startLocalHyperdrive as ke,describeWithheld as Pe}from"@lunora/config/cloudflare";import{p as Re}from"../packem_shared/api-spec-lYyq4vL6.mjs";import{w as Ce}from"../packem_shared/binding-manifest-file-CQ1eQYy1.mjs";import{existsSync as De,watch as A,readFileSync as Te,statSync as Ae}from"node:fs";import{join as k,dirname as Y}from"node:path";import{ts as $}from"ts-morph";import{a as $e}from"../packem_shared/codegen-error-AmH54ofi.mjs";import{a as Oe}from"../packem_shared/platform-diagnostics-Cn2g6Jh-.mjs";import{d as Fe}from"../packem_shared/command-CB4JM-Jl.mjs";import{a as Le}from"../packem_shared/deploy-target-resolve-BTCW1Iv4.mjs";import{EXIT_CODE as C}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{forceJsonLogging as Ne}from"../packem_shared/createLogger-4TujevyB.mjs";import{createServer as Ie,request as je}from"node:http";import{connect as Me}from"node:net";import{pipeline as We}from"node:stream";import{loadStudioAssets as O,studioAssetsStamp as F,renderStudioHtml as He,resolveAdminToken as xe,requestPathname as L,transportRejectionReason as N,SCHEMA_EDIT_ENDPOINT as Ve,POLICY_SCAFFOLD_ENDPOINT as Ue,SEED_ENDPOINT as Be,sendStudioDocument as ze,serveJsonHandler as Ge,isStandaloneModulePath as Je,readStandaloneAsset as Xe,assetContentType as Ye,handleSchemaEditRequest as Ke,handlePolicyScaffoldRequest as Qe,handleSeedRequest as Ze,applyStudioAssetCache as qe}from"@lunora/config/studio-host";import{c as er}from"../packem_shared/tui-prompts-B3YwUhGw.mjs";import{setTimeout as rr}from"node:timers/promises";import{r as tr,d as nr,P as or,a as ar,b as D,c as ir,s as sr,n as K,e as cr,f as dr,g as lr,h as ur,i as I,w as fr,j as gr,k as vr,t as mr,l as wr,m as hr,o as yr}from"../packem_shared/plan-DFY3CqHD.mjs";import{b as pr}from"./handler.mjs";const Sr=100,Er=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,br=300,j=/[/\\]/u,M=e=>{try{return Te(e,"utf8")}catch{return""}},_r=e=>{try{const{mtimeMs:r,size:n}=Ae(e);return`${String(r)}:${String(n)}`}catch{return""}},kr=["pnpm-lock.yaml","package-lock.json","yarn.lock","bun.lock","node_modules/.modules.yaml","node_modules/.package-lock.json","node_modules/.yarn-integrity"],Q=e=>{const r=Y(e);return r===e?[e]:[e,...Q(r)]},Pr=e=>{const r={...$.sys,onUnRecoverableConfigFileDiagnostic:()=>{},readDirectory:()=>[]},n=$.getParsedCommandLineOfConfigFile(e,{},r);return n===void 0?"":JSON.stringify(n.options)},Rr=(e,r)=>{const n=re(r),o=[...new Set([...te(r),...ne.map(i=>k(e,i))])].map(i=>`${i}
|
|
2
|
+
${M(i)}`),s=Q(e).flatMap(i=>kr.map(a=>`${k(i,a)}
|
|
3
|
+
${_r(k(i,a))}`));return[n===void 0?"":`${n}
|
|
4
|
+
${M(n)}
|
|
5
|
+
${Pr(n)}`,...o,...s].join("\0")},Cr=(e,r)=>{let n,t;return{drop:()=>{n=void 0},get:()=>{const o=Rr(e,r);return n===void 0||o!==t?(t=o,n=q(r)):ee(n,r),n}}},Dr=(e,r,n,t)=>{const{apiSpec:o,lazyFunctions:s,logger:u,projectRoot:i,target:a}=e;try{const f=V({apiSpec:o,lazyFunctions:b(s),lunoraDirectory:r,project:t.get(),projectRoot:i,target:a,...X(i)});u.success(`codegen: wrote ${r}/_generated (${n})`),Oe(f.platformDiagnostics,u)}catch(f){return t.drop(),u.error($e(f,n)),!1}return!0},Tr=e=>{const r=e.lunoraDirectory??"lunora",n=k(e.projectRoot,r),t=e.debounceMs??Sr;let o=!1,s=!1,u=!1,i,a=0,f=Promise.resolve();const p=Cr(e.projectRoot,n);let h;const w=new Promise(g=>{h=g}),c=g=>{o||(i=g,!s&&(s=!0,f=(async()=>{try{for(;i!==void 0;){const m=i;if(i=void 0,!!Dr(e,r,m,p)){u=!0;try{(await oe({cwd:e.projectRoot,logger:e.logger,spawner:e.spawner,stdoutToStderr:e.jsonLogs})).ran&&(a=Date.now())}finally{u=!1}}}}catch(m){e.logger.error(`codegen watch: ${m instanceof Error?m.message:String(m)}`)}finally{s=!1,h()}})()))};c("startup");const d=g=>(e.logger.warn(`codegen watch unavailable (${g}) — schema edits will NOT auto-regenerate. Run \`lunora codegen\` manually after each edit.`),{close:()=>(o=!0,i=void 0,f),ready:w,watchAvailable:!1});let l,v;if(!De(n))return d(`no such directory: ${n}`);const y=g=>{if(u||Date.now()-a<br){l&&(clearTimeout(l),l=void 0);return}l&&clearTimeout(l),l=setTimeout(()=>{c(`change: ${g??"?"}`)},t)},S=[];try{v=A(n,{recursive:!0},(g,m)=>{typeof m=="string"&&m.split(j).includes("_generated")||y(m)});for(const g of Z(e.projectRoot).services)if(g.rpcEntrypoint!==void 0){const m=A(Y(g.wranglerPath),{recursive:!0},(P,_)=>{typeof _=="string"&&Er.test(_)&&!_.split(j).includes("node_modules")&&y(_)});m.on("error",P=>{e.logger.warn(`codegen watch: stopped watching service "${g.name}" (${P.message})`),m.close()}),S.push(m)}}catch(g){v?.close();for(const m of S)m.close();return d(g instanceof Error?g.message:String(g))}const E=v;return{close:()=>{o=!0,i=void 0,l&&clearTimeout(l),E.close();for(const g of S)g.close();return f},ready:w,watchAvailable:!0}},W="/_lunora",H=3e4,x=(e,r,n)=>{const t=je({headers:{...e.headers,host:n.host},hostname:n.hostname,method:e.method,path:e.url,port:n.port},o=>{r.writeHead(o.statusCode??502,o.headers),We(o,r,()=>{})});t.setTimeout(H,()=>{t.destroy(new Error(`no response within ${String(H)}ms`))}),t.on("error",o=>{if(r.headersSent){r.destroy();return}r.statusCode=o.message.startsWith("no response within")?504:502,r.end(`lunora dev: worker unreachable (${o.message})`)}),r.on("close",()=>{r.writableFinished||t.destroy()}),e.pipe(t)},Ar=5e3,$r=(e,r,n,t)=>{const o=Me({host:t.hostname,port:Number(t.port)},()=>{o.setTimeout(0);const s=[`${e.method??"GET"} ${e.url??"/"} HTTP/1.1`];for(const[u,i]of Object.entries(e.headers))if(u!=="host")for(const a of Array.isArray(i)?i:[i])a!==void 0&&s.push(`${u}: ${a}`);s.push(`host: ${t.host}`,"",""),o.write(s.join(`\r
|
|
6
|
+
`)),n.length>0&&o.write(n),o.pipe(r),r.pipe(o)});o.setTimeout(Ar,()=>o.destroy()),o.on("error",()=>r.destroy()),r.on("error",()=>o.destroy())},Or=async e=>{const r=e.host??"127.0.0.1",n=r==="127.0.0.1"||r==="localhost"||r==="::1",t=new URL(e.workerOrigin);let o=O(e.logger,import.meta.url),s=F(import.meta.url);const u=He({adminToken:n?xe(e.cwd):void 0,basePath:"/",dataEditable:n,rulesInstalled:U(e.cwd).installed,runAsIdentity:n,schemaEditable:n,scriptSrc:"/studio.js",styleHref:"/styles.css"}),i=(c,d,l,v,y)=>{qe(c,d,y,s)||(d.statusCode=200,d.setHeader("Content-Type",v),d.end(l))},a=(c,d,l)=>{c.statusCode=d,c.setHeader("Content-Type","text/plain"),c.end(l)},f=(c,d,l,v)=>{if(n){Ge(c,d,l,e.cwd,{apiSpec:e.apiSpec,lazyFunctions:b(e.lazyFunctions)});return}a(d,403,v)},p=(c,d,l)=>{const v=c==="/styles.css",y=Je(c);if(!v&&!y)return!1;const S=F(import.meta.url);if(S!==s&&(o=O(e.logger,import.meta.url),s=S),o===void 0)return a(l,501,"Lunora studio assets not found — install and build @lunora/studio."),!0;if(v)return i(d,l,o.styles,"text/css; charset=utf-8","styles.css"),!0;const E=c.slice(c.lastIndexOf("/")+1),g=Xe(E,import.meta.url);return g===void 0?(a(l,404,"Not found"),!0):(i(d,l,g,Ye(E),E),!0)},h=Buffer.from(u),w=Ie((c,d)=>{const l=L(c.url??"/");if(n){const y=N(c,e.logger);if(y!==void 0){a(d,403,y);return}}if(l.startsWith(W)){if(!n){a(d,403,"Lunora studio: the worker admin proxy is only available on a loopback bind.");return}x(c,d,t);return}if(l===Ve){f(c,d,Ke,"Lunora schema editing is only available on loopback hosts in dev.");return}if(l===Ue){f(c,d,Qe,"Lunora policy scaffolding is only available on loopback hosts in dev.");return}if(l===Be){f(c,d,Ze,"Lunora data seeding is only available on loopback hosts in dev.");return}if(p(l,c,d))return;const v=c.headers["sec-fetch-mode"];if(n&&typeof v=="string"&&v!=="navigate"){x(c,d,t);return}ze(d,h)});return w.on("upgrade",(c,d,l)=>{if(!n||N(c,e.logger)!==void 0){d.destroy();return}L(c.url??"").startsWith(W)?$r(c,d,l,t):d.destroy()}),await new Promise((c,d)=>{w.once("error",l=>{l.code==="EADDRINUSE"?d(new Error(`studio port ${String(e.port)} is already in use — pass a different port with --port, or stop the process using it`,{cause:l})):d(l)}),w.listen(e.port,r,()=>{c()})}),{close:()=>new Promise(c=>{w.close(()=>{c()})}),url:`http://${r==="0.0.0.0"||r==="::"?"localhost":r}:${String(e.port)}`}},Fr=async e=>{const{cwd:r,logger:n,origin:t,signal:o}=e,s=e.probe??nr,u=tr(e.readyTimeoutMs),i=Date.now()+u,a=()=>o.aborted;for(;!a()&&Date.now()<i;){let f=!1;try{f=await s(t,o)}catch{}if(a()||Date.now()>=i)break;if(f)return B(r,{readyAt:new Date().toISOString()},{expectedPid:process.pid}),ae(r)?.readyAt!==void 0;try{await rr(or,void 0,{signal:o})}catch{}}return a()||n.warn(`server did not answer on ${t} within ${String(Math.round(u/1e3))}s — .lunora/dev.json will have no readyAt, so anything polling for readiness will keep waiting. The server itself is unaffected; raise LUNORA_DEV_READY_TIMEOUT_MS if it is just slow to boot.`),!1},Lr=(e,r,n,t)=>{e.info(""),e.success("Lunora dev"),e.info(` ➜ Worker: ${r.workerOrigin}`),n!==void 0&&e.info(` ➜ Studio: ${n}`),r.runsCodegenWatch&&e.info(" ➜ Codegen: watching lunora/"),t!==void 0&&e.info(` ➜ Supervisor: ${t} (needs) · ${J} (status)`),r.remote.enabled&&(r.remote.bindings.length>0?e.info(` ➜ Remote: ${r.remote.bindings.join(", ")} → deployed worker`):r.remote.reason!==void 0&&e.warn(` ➜ Remote: requested but inactive (${r.remote.reason}) — running fully local`));for(const o of r.remote.withheld)e.warn(` ➜ ${Pe(o)}`);e.info("")},Nr=(e,r)=>{U(r).installed||!Ee()||(e.info(` ⓘ ${be}`),e.info(""))},Ir=async(e,r,n)=>{try{const o=await fe({cache:n,projectRoot:r,schemaDir:ge(r)}),s=ve(o),u=(e.ensureExample??me)(r,s);if(u.length>0){const i=s.map(a=>a.includes(":")?`${a.replace(":"," (")})`:a);e.logger.info(`Updated .dev.vars.example with secrets for: ${i.join(", ")} (${u.join(", ")})`)}}catch{}(await(e.ensureEnv??we)({confirm:er(),cwd:r,info:o=>{e.logger.info(o)}})).status==="declined"&&!he()&&e.logger.info(`hint: ${T} was not scaffolded (non-interactive run). Copy ${ye} → ${T} and fill in secrets, or run \`lunora dev\` in an interactive terminal to scaffold automatically.`);try{(e.fillSecrets??pe)({cwd:r,info:o=>{e.logger.info(o)}})}catch{}},jr=(e,r,n,t,o)=>{if(e.flavor!=="wrangler")return;t!==void 0&&B(r,{studioUrl:t});let s;try{s=yr(r,n)}catch{}return Lr(n,e,t,o),s},Mr=(e,r)=>{const n=Number(process.env[R]),t=le(r,{background:process.env[z]==="1",logFile:process.env[ue],mode:"cli",pid:process.pid,startedAt:new Date().toISOString(),url:e.workerOrigin},Number.isInteger(n)&&n>0?{supersedePid:n}:void 0);return t.ok?void 0:t.existing},Wr=e=>{const{cwd:r,destination:n,logger:t,plan:o}=e,s=n!==void 0,u=n??Se,i=Ce({destination:u,dev:{...o.flavor==="wrangler"?{origin:o.workerOrigin}:{},statusFile:J},logger:s?t:{...t,success:()=>{},warn:()=>{}},projectRoot:r});return i.error!==void 0?s?i:(t.debug?.(`skipped the default binding manifest: ${i.error}`),{}):{written:u}},Hr=async(e,r,n,t)=>{if(r.studioEnabled)try{return await(e.startStudio??Or)({apiSpec:e.apiSpec,lazyFunctions:b(e.lazyFunctions),cwd:n,logger:{warnOnce:o=>{t.warn(o)}},port:r.studioPort,workerOrigin:r.workerOrigin})}catch(o){t.warn(`studio server failed to start (${o instanceof Error?o.message:String(o)}) — continuing without it`);return}},xr=e=>{const r=[e.runsCodegenWatch?"codegen watch":void 0,e.studioEnabled?"studio":void 0].filter(t=>t!==void 0);return`--no-worker: not starting wrangler. ${r.length>0?`${r.join(" + ")} running`:"nothing else to run"}; your task runner owns the worker on ${e.workerOrigin}.`},Vr=(e,r,n,t,o)=>{if(!(e.sidecar===void 0||!wr(r)))try{V({apiSpec:r.apiSpec,lazyFunctions:b(r.lazyFunctions),lunoraDirectory:"lunora",projectRoot:n,target:o,...X(n)})}catch(s){t.warn(`codegen (pre-sidecar) failed: ${s instanceof Error?s.message:String(s)} — the framework dev server will retry`)}},Ur=e=>e.flavor==="vite"?"starting vite dev (worker + studio + codegen run inside Vite via @lunora/vite)":`starting ${e.wrangler.tag} dev + studio`,Br=async(e,r,n,t,o)=>{try{return e.celldSession===!0?await hr({logger:o,port:e.workerPort,projectRoot:t,start:r.startCelldSession}):n(e.wrangler,o)}catch(s){o.error(`could not start the worker: ${s instanceof Error?s.message:String(s)}`);return}},zr=async(e,r,n)=>{const t=await(e.startHyperdrive??ke)({onWarning:o=>{n.warn(o)},projectRoot:r});return t!==void 0&&t.bindings.length>0&&n.info(`Hyperdrive ${t.bindings.join(", ")}: embedded Postgres (PGlite), data in .wrangler/state/lunora-pglite. Set CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING> to use your own.`),t},Gr=async e=>{const{logger:r}=e,n=ce(),t=e.cwd??process.cwd(),o=e.flavor??cr(t),s=Le(t,e.target);if(s.target===void 0)throw new Error(s.error??"unknown deploy target");const{target:u}=s,i=dr(u,o,r);i==="wrangler"&&await pr(t,r,void 0,u,void 0,n);const a=await lr({...e,flavor:i,target:u}),f={remoteCleanup:a.remote.cleanup,serviceConfigCleanup:a.serviceConfigCleanup};try{const p=Number(process.env[R]),h=G(t);if(h!==void 0&&h.pid!==process.pid&&h.pid!==p)return D(r,h),{code:0,plan:a};const w=Mr(a,t);if(w!==void 0)return D(r,w),{code:0,plan:a};(a.flavor==="vite"||a.flavor==="framework-worker")&&(a.wrangler.env={...a.wrangler.env,[R]:String(process.pid)}),a.workerEnabled&&u==="cloudflare"&&(f.hyperdrive=await zr(e,t,r)),await Ir(e,t,n),r.info(Ur(a)),ur(r,t),a.ipv4LoopbackForced&&r.info("no IPv6 loopback (::1) on this host — binding the worker to 127.0.0.1 (--ip) so wrangler dev doesn't crash. Pin `dev.ip` in wrangler.jsonc to override."),a.runsCodegenWatch&&(f.codegen=(e.startCodegen??Tr)({apiSpec:e.apiSpec,lazyFunctions:b(e.lazyFunctions),jsonLogs:e.jsonLogs,logger:r,projectRoot:t,target:u})),f.studio=await Hr(e,a,t,r);const c=Wr({cwd:t,destination:e.emitBindings,logger:r,plan:a});if(c.error!==void 0)return r.error(c.error),{code:C.USAGE,plan:a};await f.codegen?.ready;const d=f.studio?.url;a.frameworkHint!==void 0&&r.warn(a.frameworkHint);const l=()=>{a.flavor==="wrangler"&&(f.readyProbe=new AbortController,Fr({cwd:t,logger:r,origin:a.workerOrigin,probe:e.probeReady,signal:f.readyProbe.signal}))};if(!a.workerEnabled)return l(),r.info(xr(a)),f.tunnel=I({cwd:t,logger:r,plan:a,tunnel:e.tunnel}),{code:await(e.waitForInterrupt??fr)(r),plan:a};Vr(a,e,t,r,u);const v=e.startWorker??gr,y=await Br(a,e,v,t,r);if(y===void 0)return{code:C.FAILURE,plan:a};const S=a.sidecar===void 0?void 0:v(a.sidecar,r);return l(),f.containerLogs=jr(a,t,r,d,c.written),f.tunnel=I({cwd:t,logger:r,plan:a,tunnel:e.tunnel}),Nr(r,t),{code:await vr(y,S,r),plan:a}}finally{f.readyProbe?.abort(),de(t,process.pid),await mr(f)}},Jr=e=>({codegen:e.codegen===!1?!1:void 0,studio:e.studio===!1?!1:void 0,worker:e.worker===!1?!1:void 0}),Xr=e=>{if(e.local===!0&&e.remote===!0)return"`--local` and `--remote` are mutually exclusive — pass at most one.";const{entries:r,invalid:n}=K(e.allowMail);if(n.length>0)return`\`--allow-mail\` takes email addresses or '*@domain' — not ${n.map(t=>`"${t}"`).join(", ")}.`;if(r.length>0&&e.tunnel!==!0)return"`--allow-mail` only applies to a tunnel — add `--tunnel`."},Yr=e=>e.tunnel===!0?{allowMail:K(e.allowMail).entries}:void 0,yt=Fe(async({argument:e,cwd:r,logger:n,options:t})=>{const o=t.json===!0,s=ar({cwd:r,json:o,lines:t.lines,logger:n,subcommand:e[0]});if(s!==void 0)return s;const u=process.env[z]==="1",i=u?void 0:ie(),a=o||i!==void 0;a&&Ne(),i!==void 0&&t.background!==!0&&n.info(`AI agent detected (${i.name} via ${i.variable}) — starting the dev server in background mode with JSON logs. Set LUNORA_AGENT_MODE=0 to opt out.`);const f=Xr(t);if(f!==void 0)return n.error(`dev: ${f}`),{code:C.USAGE};const p=Yr(t),h=t.local===!0?!1:_e({configPreference:se(r),envValue:process.env.LUNORA_REMOTE,flag:t.remote});if(!u&&(t.background===!0||i!==void 0)){const w=G(r);return w!==void 0?(D(n,w),{code:0}):(p?.allowMail.length===0&&ir(n),sr({cwd:r,jsonLogs:a,logger:n,options:t,remote:h}))}return Gr({apiSpec:Re(t.apiSpec),cwd:r,emitBindings:t.emitBindings,inspectorPort:t.inspectorPort,lazyFunctions:b(t.lazyFunctions),jsonLogs:a,local:t.local,logger:n,port:t.port,remote:h,target:t.target,tunnel:p,workerPort:t.workerPort,...Jr(t)})});export{Xr as devFlagConflict,yt as execute,Jr as negatableDevFlags,Gr as runDevCommand};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.423",
|
|
4
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",
|
|
@@ -52,16 +52,16 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@bomb.sh/tab": "0.0.22",
|
|
55
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
55
|
+
"@lunora/advisor": "1.0.0-alpha.251",
|
|
56
56
|
"@lunora/bindings": "1.0.0-alpha.131",
|
|
57
|
-
"@lunora/codegen": "1.0.0-alpha.
|
|
58
|
-
"@lunora/config": "1.0.0-alpha.
|
|
57
|
+
"@lunora/codegen": "1.0.0-alpha.347",
|
|
58
|
+
"@lunora/config": "1.0.0-alpha.399",
|
|
59
59
|
"@lunora/container": "1.0.0-alpha.89",
|
|
60
|
-
"@lunora/d1": "1.0.0-alpha.
|
|
60
|
+
"@lunora/d1": "1.0.0-alpha.202",
|
|
61
61
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
62
|
-
"@lunora/mcp": "1.0.0-alpha.
|
|
63
|
-
"@lunora/runtime": "1.0.0-alpha.
|
|
64
|
-
"@lunora/seed": "1.0.0-alpha.
|
|
62
|
+
"@lunora/mcp": "1.0.0-alpha.256",
|
|
63
|
+
"@lunora/runtime": "1.0.0-alpha.232",
|
|
64
|
+
"@lunora/seed": "1.0.0-alpha.249",
|
|
65
65
|
"@visulima/cerebro": "3.1.2",
|
|
66
66
|
"@visulima/error": "6.1.0",
|
|
67
67
|
"@visulima/fs": "6.0.29",
|