@lunora/cli
Version:
The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands
9 lines (8 loc) • 19.1 kB
JavaScript
import{projectConfigCandidatePaths as ee,readServiceBindings as ve,createCodegenProject as me,refreshCodegenProject as he,findTsconfig as we,PROJECT_CONFIG_FILENAMES as ye,runCodegen as re}from"@lunora/codegen";import{runPostCodegenHook as pe,resolveLazyFunctions as D,detectAgentRules as te,resolveSchemaDirectory as C,updateDevServerState as oe,readDevServerState as Se,DEV_DAEMON_ENV as ne,detectAiAgent as Ee,readProjectRemotePreference as be,readLiveDevServerState as ae,createDiscoveryCache as Pe,DEV_HANDOFF_ENV as I,clearDevServerState as Re,claimDevServerState as _e,DEV_LOG_FILE_ENV as De,secretSourcesFromBindings as ke,inferLunoraBindings as Te,ensureDevVarsExample as $e,ensureDevVariables as Ce,isInteractive as Ae,DEV_VARS_FILE as H,DEV_VARS_EXAMPLE_FILE as Oe,fillDevSecrets as Fe,DEV_BINDINGS_FILE as Le,DEV_STATE_FILE as ie,writeCelldDevProjection as Ie,claimAgentRulesHint as Ne,AGENT_RULES_HINT as je}from"@lunora/config";import{WRANGLER_FILES as Me,wranglerCodegenInputs as se,resolveRemoteEnabled as We,startLocalHyperdrive as He,describeWithheld as xe}from"@lunora/config/cloudflare";import{p as Ue}from"../packem_shared/api-spec-lYyq4vL6.mjs";import{w as Ve}from"../packem_shared/binding-manifest-file-CQ1eQYy1.mjs";import{createHash as Be}from"node:crypto";import{existsSync as A,watch as N,readFileSync as ce,statSync as ze}from"node:fs";import{join as R,dirname as M}from"node:path";import{STUDIO_WRITE_TEMP_SUFFIX as Ge,consumeStudioWrite as x,loadStudioAssets as U,studioAssetsStamp as V,createStudioDocumentCache as Xe,renderStudioHtml as Je,resolveAdminToken as Ye,requestPathname as B,transportRejectionReason as z,SCHEMA_EDIT_ENDPOINT as Ke,POLICY_SCAFFOLD_ENDPOINT as Qe,SEED_ENDPOINT as Ze,ADVISOR_PROCEDURES_ENDPOINT as qe,sendStudioDocument as er,serveJsonHandler as rr,isStandaloneModulePath as tr,readStandaloneAsset as or,assetContentType as nr,handleSchemaEditRequest as ar,handlePolicyScaffoldRequest as ir,handleSeedRequest as sr,handleAdvisorProceduresRequest as cr,sendStudioAsset as dr}from"@lunora/config/studio-host";import{LunoraError as lr}from"@lunora/errors";import{ts as G}from"ts-morph";import{a as ur}from"../packem_shared/codegen-error-AmH54ofi.mjs";import{a as fr}from"../packem_shared/platform-diagnostics-Cn2g6Jh-.mjs";import{d as gr}from"../packem_shared/command-BpMv2n0o.mjs";import{a as vr}from"../packem_shared/deploy-target-resolve-BTCW1Iv4.mjs";import{EXIT_CODE as $}from"../packem_shared/EXIT_CODE-DQVhSE-1.mjs";import{forceJsonLogging as mr}from"../packem_shared/createLogger-4TujevyB.mjs";import{createServer as hr,request as wr}from"node:http";import{connect as yr}from"node:net";import{pipeline as pr}from"node:stream";import{c as Sr}from"../packem_shared/tui-prompts-B3YwUhGw.mjs";import{setTimeout as Er}from"node:timers/promises";import{r as br,d as Pr,P as Rr,a as _r,b as j,c as Dr,s as kr,n as de,e as Tr,f as $r,g as Cr,h as Ar,i as X,w as Or,j as Fr,k as Lr,t as Ir,l as Nr,m as jr,o as Mr}from"../packem_shared/plan-BH6l7s48.mjs";import{b as Wr}from"./handler.mjs";const Hr=100,xr=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,L=300,J=/[/\\]/u,Y=e=>{try{return ce(e,"utf8")}catch{return""}},Ur=e=>{try{const{mtimeMs:r,size:o}=ze(e);return`${String(r)}:${String(o)}`}catch{return""}},Vr=["pnpm-lock.yaml","package-lock.json","yarn.lock","bun.lock","node_modules/.modules.yaml","node_modules/.package-lock.json","node_modules/.yarn-integrity"],le=e=>{const r=M(e);return r===e?[e]:[e,...le(r)]},Br=e=>{const r={...G.sys,onUnRecoverableConfigFileDiagnostic:()=>{},readDirectory:()=>[]},o=G.getParsedCommandLineOfConfigFile(e,{},r);return o===void 0?"":JSON.stringify(o.options)},zr=(e,r)=>{const o=we(r),n=[...new Set([...ee(r),...ye.map(s=>R(e,s))])].map(s=>`${s}
${Y(s)}`),a=le(e).flatMap(s=>Vr.map(i=>`${R(s,i)}
${Ur(R(s,i))}`));return[o===void 0?"":`${o}
${Y(o)}
${Br(o)}`,...n,...a].join("\0")},Gr=(e,r)=>{let o,t;return{drop:()=>{o=void 0},get:()=>{const n=zr(e,r);return o===void 0||n!==t?(t=n,o=me(r)):he(o,r),o}}},Xr=(e,r,o,t)=>{const{apiSpec:n,lazyFunctions:a,logger:d,projectRoot:s,target:i}=e;try{const g=R(s,r,"schema.ts");if(!A(g))throw new lr("INTERNAL",`schema.ts not found at ${g}`);const h=re({apiSpec:n,lazyFunctions:D(a),lunoraDirectory:r,project:t.get(),projectRoot:s,target:i,...se(s)});d.success(`codegen: wrote ${r}/_generated (${o})`),fr(h.platformDiagnostics,d)}catch(g){return t.drop(),d.error(ur(g,o)),!1}return!0},K=e=>{const r=Be("sha256");for(const o of e){if(r.update(o).update("\0"),A(o)){r.update("present\0");try{r.update(ce(o))}catch{r.update("unreadable")}}else r.update("absent");r.update("\0")}return r.digest("hex")},Q=e=>e instanceof Error?e.stack??e.message:String(e),Jr=(e,r,o)=>{const t=[];for(const n of new Set([...e].map(a=>M(a))))if(A(n))try{const a=N(n,(d,s)=>{typeof s!="string"?r(void 0):e.has(R(n,s))&&r(s)});a.on("error",d=>{o(`codegen watch: stopped watching ${n} for lunora.config changes
${Q(d)}`),a.close()}),t.push(a)}catch(a){o(`codegen watch: could not watch ${n} for lunora.config changes
${Q(a)}`)}return t},Yr=e=>{const r=e.lunoraDirectory??"lunora",o=R(e.projectRoot,r),t=e.debounceMs??Hr;let n=!1,a=!1,d=!1,s,i=0,g;const h=[...ee(o),...Me.map(u=>R(e.projectRoot,u))];let p=Promise.resolve();const S=Gr(e.projectRoot,o);let c;const l=new Promise(u=>{c=u}),f=(u,m)=>{n||(s={codegen:m||s?.codegen===!0,reason:u},!a&&(a=!0,p=(async()=>{try{for(;s!==void 0;){const y=s;if(s=void 0,y.codegen&&(g=K(h)),!(y.codegen&&!Xr(e,r,y.reason,S))){d=!0;try{(await pe({cwd:e.projectRoot,logger:e.logger,spawner:e.spawner,stdoutToStderr:e.jsonLogs})).ran&&(i=Date.now())}finally{d=!1}}}}catch(y){e.logger.error(`codegen watch: ${y instanceof Error?y.message:String(y)}`)}finally{a=!1,c()}})()))};f("startup",!0);const w=u=>(e.logger.warn(`codegen watch unavailable (${u}) — schema edits will NOT auto-regenerate. Run \`lunora codegen\` manually after each edit.`),{close:()=>(n=!0,s=void 0,p),ready:l,watchAvailable:!1});let v,P;if(!A(o))return w(`no such directory: ${o}`);const E=new Set;let _=!1;const k=(u,m)=>{if(d||Date.now()-i<L){v&&(clearTimeout(v),v=void 0);let y=!1;for(const b of[...E,u])b!==void 0&&x(b)&&(y=!0);E.clear(),_=!1,y&&f(`change: ${m}`,!1);return}u===void 0?_=!0:E.add(u),v&&clearTimeout(v),v=setTimeout(()=>{const y=[...E].map(ge=>x(ge)),b=_||y.includes(!1);E.clear(),_=!1,f(`change: ${m}`,b)},t)},O=[],F=[],ue=new Set(h);let T;const W=u=>{if(!n){if(!d&&Date.now()-i>=L){clearTimeout(T),(u===void 0||K(h)!==g)&&k(void 0,u??"?");return}clearTimeout(T),T=setTimeout(()=>{W(u)},L)}};try{P=N(o,{recursive:!0},(u,m)=>{if(typeof m!="string"){k(void 0,"?");return}m.split(J).includes("_generated")||m.endsWith(Ge)||k(R(o,m),m)});for(const u of ve(e.projectRoot).services)if(u.rpcEntrypoint!==void 0){const m=N(M(u.wranglerPath),{recursive:!0},(y,b)=>{typeof b=="string"&&xr.test(b)&&!b.split(J).includes("node_modules")&&k(void 0,b)});m.on("error",y=>{e.logger.warn(`codegen watch: stopped watching service "${u.name}" (${y.message})`),m.close()}),O.push(m)}F.push(...Jr(ue,u=>{W(u)},u=>{e.logger.warn(u)}))}catch(u){P?.close();for(const m of O)m.close();for(const m of F)m.close();return w(u instanceof Error?u.message:String(u))}const fe=P;return{close:()=>{n=!0,s=void 0,v&&clearTimeout(v),clearTimeout(T),fe.close();for(const u of O)u.close();for(const u of F)u.close();return p},ready:l,watchAvailable:!0}},Z="/_lunora",Kr=3e4,q=(e,r,o,t=Kr)=>{const n=wr({headers:{...e.headers,host:o.host},hostname:o.hostname,method:e.method,path:e.url,port:o.port},a=>{n.setTimeout(0),r.writeHead(a.statusCode??502,a.headers),pr(a,r,()=>{})});n.setTimeout(t,()=>{n.destroy(new Error(`no response within ${String(t)}ms`))}),n.on("error",a=>{if(r.headersSent){r.destroy();return}r.statusCode=a.message.startsWith("no response within")?504:502,r.end(`lunora dev: worker unreachable (${a.message})`)}),r.on("close",()=>{r.writableFinished||n.destroy()}),e.pipe(n)},Qr=5e3,Zr=(e,r,o,t)=>{const n=yr({host:t.hostname,port:Number(t.port)},()=>{n.setTimeout(0);const a=[`${e.method??"GET"} ${e.url??"/"} HTTP/1.1`];for(const[d,s]of Object.entries(e.headers))if(d!=="host")for(const i of Array.isArray(s)?s:[s])i!==void 0&&a.push(`${d}: ${i}`);a.push(`host: ${t.host}`,"",""),n.write(a.join(`\r
`)),o.length>0&&n.write(o),n.pipe(r),r.pipe(n)});n.setTimeout(Qr,()=>n.destroy()),n.on("error",()=>r.destroy()),r.on("error",()=>n.destroy())},qr=async e=>{const r=e.host??"127.0.0.1",o=r==="127.0.0.1"||r==="localhost"||r==="::1",t=new URL(e.workerOrigin);let n=U(e.logger,import.meta.url),a=V(import.meta.url);const d=Xe(e.cwd,()=>Buffer.from(Je({adminToken:o?Ye(e.cwd):void 0,advisorProcedures:o,basePath:"/",dataEditable:o,rulesInstalled:te(e.cwd).installed,runAsIdentity:o,schemaEditable:o,scriptSrc:"/studio.js",styleHref:"/styles.css"}))),s=(c,l,f,w,v)=>{dr(c,l,f,w,v,a)},i=(c,l,f)=>{c.statusCode=l,c.setHeader("Content-Type","text/plain"),c.end(f)},g=C(e.cwd),h=(c,l,f,w)=>{if(o){rr(c,l,f,e.cwd,{apiSpec:e.apiSpec,lazyFunctions:D(e.lazyFunctions),schemaDirectory:g});return}i(l,403,w)},p=(c,l,f)=>{const w=c==="/styles.css",v=tr(c);if(!w&&!v)return!1;const P=V(import.meta.url);if(P!==a&&(n=U(e.logger,import.meta.url),a=P),n===void 0)return i(f,501,"Lunora studio assets not found — install and build @lunora/studio."),!0;if(w)return s(l,f,n.styles,"text/css; charset=utf-8","styles.css"),!0;const E=c.slice(c.lastIndexOf("/")+1),_=or(E,import.meta.url);return _===void 0?(i(f,404,"Not found"),!0):(s(l,f,_,nr(E),E),!0)};d();const S=hr((c,l)=>{const f=B(c.url??"/");if(o){const v=z(c,e.logger);if(v!==void 0){i(l,403,v);return}}if(f.startsWith(Z)){if(!o){i(l,403,"Lunora studio: the worker admin proxy is only available on a loopback bind.");return}q(c,l,t);return}if(f===Ke){h(c,l,ar,"Lunora schema editing is only available on loopback hosts in dev.");return}if(f===Qe){h(c,l,ir,"Lunora policy scaffolding is only available on loopback hosts in dev.");return}if(f===Ze){h(c,l,sr,"Lunora data seeding is only available on loopback hosts in dev.");return}if(f===qe){h(c,l,cr,"Lunora advisor data is only available on loopback hosts in dev.");return}if(p(f,c,l))return;const w=c.headers["sec-fetch-mode"];if(o&&typeof w=="string"&&w!=="navigate"){q(c,l,t);return}er(l,d())});return S.on("upgrade",(c,l,f)=>{if(!o||z(c,e.logger)!==void 0){l.destroy();return}B(c.url??"").startsWith(Z)?Zr(c,l,f,t):l.destroy()}),await new Promise((c,l)=>{S.once("error",f=>{f.code==="EADDRINUSE"?l(new Error(`studio port ${String(e.port)} is already in use — pass a different port with --port, or stop the process using it`,{cause:f})):l(f)}),S.listen(e.port,r,()=>{c()})}),{close:()=>new Promise(c=>{S.close(()=>{c()})}),url:`http://${r==="0.0.0.0"||r==="::"?"localhost":r}:${String(e.port)}`}},et=async e=>{const{cwd:r,logger:o,origin:t,signal:n}=e,a=e.probe??Pr,d=br(e.readyTimeoutMs),s=Date.now()+d,i=()=>n.aborted;for(;!i()&&Date.now()<s;){let g=!1;try{g=await a(t,n)}catch{}if(i()||Date.now()>=s)break;if(g)return oe(r,{readyAt:new Date().toISOString()},{expectedPid:process.pid}),Se(r)?.readyAt!==void 0;try{await Er(Rr,void 0,{signal:n})}catch{}}return i()||o.warn(`server did not answer on ${t} within ${String(Math.round(d/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},rt=(e,r,o,t)=>{e.info(""),e.success("Lunora dev"),e.info(` ➜ Worker: ${r.workerOrigin}`),o!==void 0&&e.info(` ➜ Studio: ${o}`),r.runsCodegenWatch&&e.info(" ➜ Codegen: watching lunora/"),t!==void 0&&e.info(` ➜ Supervisor: ${t} (needs) · ${ie} (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 n of r.remote.withheld)e.warn(` ➜ ${xe(n)}`);e.info("")},tt=(e,r)=>{te(r).installed||!Ne()||(e.info(` ⓘ ${je}`),e.info(""))},ot=async(e,r,o)=>{let t;try{t=ke(await Te({cache:o,projectRoot:r,schemaDir:C(r)}))}catch{}if(t!==void 0)try{const a=(e.ensureExample??$e)(r,t);if(a.length>0){const d=t.map(s=>s.includes(":")?`${s.replace(":"," (")})`:s);e.logger.info(`Updated .dev.vars.example with secrets for: ${d.join(", ")} (${a.join(", ")})`)}}catch{}(await(e.ensureEnv??Ce)({confirm:Sr(),cwd:r,info:a=>{e.logger.info(a)}})).status==="declined"&&!Ae()&&e.logger.info(`hint: ${H} was not scaffolded (non-interactive run). Copy ${Oe} → ${H} and fill in secrets, or run \`lunora dev\` in an interactive terminal to scaffold automatically.`);try{(e.fillSecrets??Fe)({cwd:r,secretSources:t,info:a=>{e.logger.info(a)}})}catch{}},nt=(e,r,o,t,n)=>{if(e.flavor!=="wrangler")return;t!==void 0&&oe(r,{studioUrl:t});let a;try{a=Mr(r,o)}catch{}return rt(o,e,t,n),a},at=(e,r)=>{const o=Number(process.env[I]),t=_e(r,{background:process.env[ne]==="1",logFile:process.env[De],mode:"cli",pid:process.pid,startedAt:new Date().toISOString(),url:e.workerOrigin},Number.isInteger(o)&&o>0?{supersedePid:o}:void 0);return t.ok?void 0:t.existing},it=e=>{const{cwd:r,destination:o,logger:t,plan:n}=e,a=o!==void 0,d=o??Le,s=Ve({destination:d,dev:{...n.flavor==="wrangler"?{origin:n.workerOrigin}:{},statusFile:ie},logger:a?t:{...t,success:()=>{},warn:()=>{}},projectRoot:r});return s.error!==void 0?a?s:(t.debug?.(`skipped the default binding manifest: ${s.error}`),{}):{written:d}},st=async(e,r,o,t)=>{if(r.studioEnabled)try{return await(e.startStudio??qr)({apiSpec:e.apiSpec,lazyFunctions:D(e.lazyFunctions),cwd:o,logger:{warnOnce:n=>{t.warn(n)}},port:r.studioPort,workerOrigin:r.workerOrigin})}catch(n){t.warn(`studio server failed to start (${n instanceof Error?n.message:String(n)}) — continuing without it`);return}},ct=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}.`},dt=(e,r,o,t,n)=>{if(!(e.sidecar===void 0||!Nr(r)))try{re({apiSpec:r.apiSpec,lazyFunctions:D(r.lazyFunctions),lunoraDirectory:C(o),projectRoot:o,target:n,...se(o)})}catch(a){t.warn(`codegen (pre-sidecar) failed: ${a instanceof Error?a.message:String(a)} — the framework dev server will retry`)}},lt=e=>e.flavor==="vite"?"starting vite dev (worker + studio + codegen run inside Vite via @lunora/vite)":`starting ${e.wrangler.tag} dev + studio`,ut=(e,r)=>{e.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.")},ft=async(e,r,o,t)=>{if(e.celldSession!==!0||e.workerEnabled)return!0;try{for(const n of await(r.writeCelldProjection??Ie)({projectRoot:o}))t.warn(n);return!0}catch(n){return t.error(`could not write the celld projection: ${n instanceof Error?n.message:String(n)}`),!1}},gt=async(e,r,o,t,n)=>{try{return e.celldSession===!0?await jr({logger:n,port:e.workerPort,projectRoot:t,start:r.startCelldSession}):o(e.wrangler,n)}catch(a){n.error(`could not start the worker: ${a instanceof Error?a.message:String(a)}`);return}},vt=async(e,r,o)=>{const t=await(e.startHyperdrive??He)({onWarning:n=>{o.warn(n)},projectRoot:r});return t!==void 0&&t.bindings.length>0&&o.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},mt=async e=>{const{logger:r}=e,o=Pe(),t=e.cwd??process.cwd(),n=e.flavor??Tr(t),a=vr(t,e.target);if(a.target===void 0)throw new Error(a.error??"unknown deploy target");const{target:d}=a,s=$r(d,n,r);s==="wrangler"&&await Wr(t,r,void 0,d,void 0,o);const i=await Cr({...e,flavor:s,target:d}),g={remoteCleanup:i.remote.cleanup,serviceConfigCleanup:i.serviceConfigCleanup};try{const h=Number(process.env[I]),p=ae(t);if(p!==void 0&&p.pid!==process.pid&&p.pid!==h)return j(r,p),{code:0,plan:i};const S=at(i,t);if(S!==void 0)return j(r,S),{code:0,plan:i};(i.flavor==="vite"||i.flavor==="framework-worker")&&(i.wrangler.env={...i.wrangler.env,[I]:String(process.pid)}),i.workerEnabled&&d==="cloudflare"&&(g.hyperdrive=await vt(e,t,r)),await ot(e,t,o),r.info(lt(i)),Ar(r,t),ut(i,r),i.runsCodegenWatch&&(g.codegen=(e.startCodegen??Yr)({apiSpec:e.apiSpec,lazyFunctions:D(e.lazyFunctions),jsonLogs:e.jsonLogs,logger:r,lunoraDirectory:C(t),projectRoot:t,target:d})),g.studio=await st(e,i,t,r);const c=it({cwd:t,destination:e.emitBindings,logger:r,plan:i});if(c.error!==void 0)return r.error(c.error),{code:$.USAGE,plan:i};await g.codegen?.ready;const l=g.studio?.url;i.frameworkHint!==void 0&&r.warn(i.frameworkHint);const f=()=>{i.flavor==="wrangler"&&(g.readyProbe=new AbortController,et({cwd:t,logger:r,origin:i.workerOrigin,probe:e.probeReady,signal:g.readyProbe.signal}))};if(!await ft(i,e,t,r))return{code:$.FAILURE,plan:i};if(!i.workerEnabled)return f(),r.info(ct(i)),g.tunnel=X({cwd:t,logger:r,plan:i,tunnel:e.tunnel}),{code:await(e.waitForInterrupt??Or)(r),plan:i};dt(i,e,t,r,d);const w=e.startWorker??Fr,v=await gt(i,e,w,t,r);if(v===void 0)return{code:$.FAILURE,plan:i};const P=i.sidecar===void 0?void 0:w(i.sidecar,r);return f(),g.containerLogs=nt(i,t,r,l,c.written),g.tunnel=X({cwd:t,logger:r,plan:i,tunnel:e.tunnel}),tt(r,t),{code:await Lr(v,P,r),plan:i}}finally{g.readyProbe?.abort(),Re(t,process.pid),await Ir(g)}},ht=e=>({codegen:e.codegen===!1?!1:void 0,studio:e.studio===!1?!1:void 0,worker:e.worker===!1?!1:void 0}),wt=e=>{if(e.local===!0&&e.remote===!0)return"`--local` and `--remote` are mutually exclusive — pass at most one.";const{entries:r,invalid:o}=de(e.allowMail);if(o.length>0)return`\`--allow-mail\` takes email addresses or '*@domain' — not ${o.map(t=>`"${t}"`).join(", ")}.`;if(r.length>0&&e.tunnel!==!0)return"`--allow-mail` only applies to a tunnel — add `--tunnel`."},yt=e=>e.tunnel===!0?{allowMail:de(e.allowMail).entries}:void 0,Vt=gr(async({argument:e,cwd:r,logger:o,options:t})=>{const n=t.json===!0,a=_r({cwd:r,json:n,lines:t.lines,logger:o,subcommand:e[0]});if(a!==void 0)return a;const d=process.env[ne]==="1",s=d?void 0:Ee(),i=n||s!==void 0;i&&mr(),s!==void 0&&t.background!==!0&&o.info(`AI agent detected (${s.name} via ${s.variable}) — starting the dev server in background mode with JSON logs. Set LUNORA_AGENT_MODE=0 to opt out.`);const g=wt(t);if(g!==void 0)return o.error(`dev: ${g}`),{code:$.USAGE};const h=yt(t),p=t.local===!0?!1:We({configPreference:be(r),envValue:process.env.LUNORA_REMOTE,flag:t.remote});if(!d&&(t.background===!0||s!==void 0)){const S=ae(r);return S!==void 0?(j(o,S),{code:0}):(h?.allowMail.length===0&&Dr(o),kr({cwd:r,jsonLogs:i,logger:o,options:t,remote:p}))}return mt({apiSpec:Ue(t.apiSpec),cwd:r,emitBindings:t.emitBindings,inspectorPort:t.inspectorPort,lazyFunctions:D(t.lazyFunctions),jsonLogs:i,local:t.local,logger:o,port:t.port,remote:p,target:t.target,tunnel:h,workerPort:t.workerPort,...ht(t)})});export{wt as devFlagConflict,Vt as execute,ht as negatableDevFlags,mt as runDevCommand};