@lunora/cli
Version:
The Lunora CLI: init, dev, deploy, codegen, run, reset, and migrate commands
2 lines (1 loc) • 2.46 kB
JavaScript
import{existsSync as a,readFileSync as g,readdirSync as p,statSync as m,mkdirSync as f,writeFileSync as w}from"node:fs";import{fileURLToPath as S}from"node:url";import{AGENT_RULES_DIR as u,detectAgentRules as y,LUNORA_SKILL_NAMES as L}from"@lunora/config";import{join as l,relative as R,dirname as d}from"@visulima/path";import{i as v}from"../packem_shared/command-Bjv4VmYA.mjs";const $=(e=d(S(import.meta.url)))=>{let t=e;for(let r=0;r<6;r+=1){const n=l(t,"package.json");if(a(n))try{if(JSON.parse(g(n,"utf8")).name==="@lunora/cli"){const o=l(t,"skills");return a(o)?o:void 0}}catch{}const s=d(t);if(s===t)break;t=s}},I=e=>p(e).filter(t=>{const r=l(e,t);return m(r).isDirectory()&&a(l(r,"SKILL.md"))}),h=(e,t,r)=>{f(t,{recursive:!0});let n=!1;for(const s of p(e)){const o=l(e,s),i=l(t,s);if(m(o).isDirectory()){n=h(o,i,r)||n;continue}a(i)&&!r||(w(i,g(o)),n=!0)}return n},A=e=>{const t=e.cwd??process.cwd(),r=e.overwrite===!0,n=$();if(n===void 0)return e.logger.error("rules: could not locate the bundled skills (is @lunora/cli installed correctly?)."),{code:1,installed:[],skipped:[]};const s=[],o=[];for(const c of I(n)){const k=l(t,u,c);h(l(n,c),k,r)?s.push(c):o.push(c)}const i=R(t,l(t,u))||u;return s.length>0&&e.logger.success(`Installed ${String(s.length)} Lunora skill(s) into ${i}/: ${s.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:s,skipped:o}},j=e=>{const t=e.cwd??process.cwd(),r=y(t);return r.installed?(e.logger.success(`Lunora agent rules are installed (${String(r.present.length)}/${String(L.length)} skills).`),r.missing.length>0&&e.logger.info(`Missing: ${r.missing.join(", ")}. Run \`lunora rules install\` to add them.`),{code:0,installed:r.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:r.present,skipped:[]})},b=v(({argument:e,cwd:t,logger:r,options:n})=>{const s=e[0]??"check";return s==="install"?A({cwd:t,logger:r,overwrite:n.overwrite===!0}):s==="check"?j({cwd:t,logger:r,strict:n.strict===!0}):(r.error("rules: unknown subcommand. Usage: lunora rules <install|check>"),{code:1})});export{b as execute,$ as resolveBundledSkillsDirectory,j as runRulesCheck,A as runRulesInstall};