@lunora/cli
Version:
The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands
2 lines (1 loc) • 2.84 kB
JavaScript
import{existsSync as c,readFileSync as g,readdirSync as f,statSync as k,mkdirSync as w,writeFileSync as y}from"node:fs";import{fileURLToPath as R}from"node:url";import{AGENT_RULES_DIR as u,detectAgentRules as v,LUNORA_SKILL_NAMES as L}from"@lunora/config";import{join as i,relative as A,resolve as E,dirname as d}from"@visulima/path";import{d as I}from"../packem_shared/command-Mmxzxyr5.mjs";import{EXIT_CODE as $}from"../packem_shared/EXIT_CODE-08cwt3MK.mjs";const b=(e=d(R(import.meta.url)))=>{let r=e;for(let n=0;n<6;n+=1){const t=i(r,"package.json");if(c(t))try{if(JSON.parse(g(t,"utf8")).name==="@lunora/cli"){const o=i(r,"skills");return c(o)?o:void 0}}catch{}const s=d(r);if(s===r)break;r=s}},_=e=>f(e).filter(r=>{const n=i(e,r);return k(n).isDirectory()&&c(i(n,"SKILL.md"))}),m=(e,r,n)=>{w(r,{recursive:!0});let t=!1;for(const s of f(e)){const l=i(e,s),o=i(r,s);if(k(l).isDirectory()){t=m(l,o,n)||t;continue}c(o)&&!n||(y(o,g(l)),t=!0)}return t},j=["pnpm-workspace.yaml","pnpm-lock.yaml","yarn.lock","package-lock.json","bun.lock","bun.lockb",".git"],O=e=>{let r=e;for(;;){if(j.some(t=>c(i(r,t))))return r;const n=d(r);if(n===r)return e;r=n}},p=(e,r)=>r===void 0?O(e):E(e,r),x=e=>{const r=e.cwd??process.cwd(),n=p(r,e.dir),t=e.overwrite===!0,s=b();if(s===void 0)return e.logger.error("rules: could not locate the bundled skills (is @lunora/cli installed correctly?)."),{code:1,installed:[],skipped:[]};const l=[],o=[];for(const a of _(s)){const h=i(n,u,a);m(i(s,a),h,t)?l.push(a):o.push(a)}const S=A(r,i(n,u))||u;return l.length>0&&e.logger.success(`Installed ${String(l.length)} Lunora skill(s) into ${S}/: ${l.join(", ")}.`),o.length>0&&e.logger.info(`Skipped ${String(o.length)} existing skill(s) (re-run with --overwrite to replace): ${o.join(", ")}.`),e.logger.info("Your AI coding agent will pick these up automatically. Start with the `lunora` skill."),{code:0,installed:l,skipped:o}},D=e=>{const r=e.cwd??process.cwd(),n=p(r,e.dir),t=v(n);return t.installed?(e.logger.success(`Lunora agent rules are installed (${String(t.present.length)}/${String(L.length)} skills).`),t.missing.length>0&&e.logger.info(`Missing: ${t.missing.join(", ")}. Run \`lunora rules install\` to add them.`),{code:0,installed:t.present,skipped:[]}):(e.logger.warn("Lunora agent rules are not installed. Run `lunora rules install` so your AI agent knows how to use Lunora."),{code:e.strict===!0?1:0,installed:t.present,skipped:[]})},B=I(({argument:e,cwd:r,logger:n,options:t})=>{const s=e[0]??"check";return s==="install"?x({cwd:r,dir:t.dir,logger:n,overwrite:t.overwrite===!0}):s==="check"?D({cwd:r,dir:t.dir,logger:n,strict:t.strict===!0}):(n.error("rules: unknown subcommand. Usage: lunora rules <install|check>"),{code:$.USAGE})});export{B as execute,_ as listBundledSkills,b as resolveBundledSkillsDirectory,D as runRulesCheck,x as runRulesInstall};