UNPKG

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