@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.75 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 $,dirname as d}from"@visulima/path";import{d as b}from"../packem_shared/command-DwC11Cwe.mjs";const I=(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 l=i(r,"skills");return c(l)?l:void 0}}catch{}const s=d(r);if(s===r)break;r=s}},j=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 o=i(e,s),l=i(r,s);if(k(o).isDirectory()){t=m(o,l,n)||t;continue}c(l)&&!n||(y(l,g(o)),t=!0)}return t},_=["pnpm-workspace.yaml","pnpm-lock.yaml","yarn.lock","package-lock.json","bun.lock","bun.lockb",".git"],x=e=>{let r=e;for(;;){if(_.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?x(e):$(e,r),E=e=>{const r=e.cwd??process.cwd(),n=p(r,e.dir),t=e.overwrite===!0,s=I();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 o=[],l=[];for(const a of j(s)){const S=i(n,u,a);m(i(s,a),S,t)?o.push(a):l.push(a)}const h=A(r,i(n,u))||u;return o.length>0&&e.logger.success(`Installed ${String(o.length)} Lunora skill(s) into ${h}/: ${o.join(", ")}.`),l.length>0&&e.logger.info(`Skipped ${String(l.length)} existing skill(s) (re-run with --overwrite to replace): ${l.join(", ")}.`),e.logger.info("Your AI coding agent will pick these up automatically. Start with the `lunora` skill."),{code:0,installed:o,skipped:l}},O=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:[]})},T=b(({argument:e,cwd:r,logger:n,options:t})=>{const s=e[0]??"check";return s==="install"?E({cwd:r,dir:t.dir,logger:n,overwrite:t.overwrite===!0}):s==="check"?O({cwd:r,dir:t.dir,logger:n,strict:t.strict===!0}):(n.error("rules: unknown subcommand. Usage: lunora rules <install|check>"),{code:1})});export{T as execute,I as resolveBundledSkillsDirectory,O as runRulesCheck,E as runRulesInstall};