rapidkit 0.27.0 → 0.27.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapidkit",
3
- "version": "0.27.0",
3
+ "version": "0.27.1",
4
4
  "type": "module",
5
5
  "description": "Official CLI for RapidKit, an open-source workspace platform that standardizes how teams build, scale, and deploy backend services.",
6
6
  "keywords": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapidkit",
3
- "version": "0.27.0",
3
+ "version": "0.27.2",
4
4
  "type": "module",
5
5
  "description": "Official CLI for RapidKit, an open-source workspace platform that standardizes how teams build, scale, and deploy backend services.",
6
6
  "keywords": [
@@ -1,38 +0,0 @@
1
- import {b,f,d,a as a$1,k,g,i as i$1}from'./chunk-Z5LKRG57.js';import {a}from'./chunk-VM2TOHNX.js';import i from'chalk';import {execa}from'execa';import r from'fs-extra';import n from'path';import X from'inquirer';function z(t){return [...new Set(t.filter(s=>s&&s.trim().length>0))]}function Y(){let t=k().map(c=>n.join(c,a$1()?"poetry.exe":"poetry")),s=a$1()?[n.join(process.env.APPDATA||"","Python","Scripts","poetry.exe"),n.join(process.env.USERPROFILE||"","AppData","Roaming","Python","Scripts","poetry.exe")]:[],e=a$1()?[]:["/usr/local/bin/poetry","/usr/bin/poetry"];return z([...t,...s,...e])}function Z(t){let s=k().map(a=>({location:"Global (user-local)",path:n.join(a,a$1()?"rapidkit.exe":"rapidkit")})),e=[{location:"Global (pipx)",path:n.join(t,".local","bin","rapidkit")},{location:"Global (pipx)",path:n.join(t,"AppData","Roaming","Python","Scripts","rapidkit.exe")},{location:"Global (pyenv)",path:n.join(t,".pyenv","shims","rapidkit")},{location:"Global (system)",path:"/usr/local/bin/rapidkit"},{location:"Global (system)",path:"/usr/bin/rapidkit"}],c=g(n.join(process.cwd(),".venv")),o=i$1(process.cwd()),l=[{location:"Workspace (.venv)",path:c},...o.map(a=>({location:"Workspace (launcher)",path:a}))],p=[...s,...e,...l],d=new Set;return p.filter(a=>d.has(a.path)?false:(d.add(a.path),true))}function tt(t){let s=new Map([["Workspace (.venv)",0],["Global (user-local)",1],["Global (pipx)",2],["Global (pyenv)",3],["Global (system)",4]]);return [...t].sort((e,c)=>{let o=s.get(e.location)??Number.MAX_SAFE_INTEGER,l=s.get(c.location)??Number.MAX_SAFE_INTEGER;return o!==l?o-l:e.path.localeCompare(c.path)})}function j(t,s){return a$1()?`cd "${t}"; ${s}`:`cd ${t} && ${s}`}function W(t){return a$1()?j(t,"Copy-Item .env.example .env"):j(t,"cp .env.example .env")}async function J(t){try{let s=await r.stat(t);return `${n.basename(t)}:${s.isDirectory()?"d":"f"}:${s.size}:${s.mtimeMs}`}catch{return `${n.basename(t)}:missing`}}async function et(t){try{let s=new Set([".git",".venv","node_modules",".rapidkit","dist","build","coverage","__pycache__"]),e=new Set;await N(t)&&e.add(t);let c=async(o,l)=>{if(l<0)return;let p=await Q(o);for(let d of p){if(U(d,s))continue;let a=n.join(o,d);if(await N(a)){e.add(a);continue}l>0&&await c(a,l-1);}};return await c(t,1),e.size===0&&(await pt(t,3,s)).forEach(l=>e.add(l)),Array.from(e).sort((o,l)=>o.localeCompare(l))}catch{return []}}async function st(t,s){let e=[n.join(t,".rapidkit-workspace"),n.join(t,".rapidkit","workspace.json"),n.join(t,".rapidkit","policies.yml"),n.join(t,".rapidkit","toolchain.lock"),n.join(t,".rapidkit","cache-config.yml")],c=[".rapidkit/project.json",".rapidkit/context.json",".rapidkit/file-hashes.json","package.json","pyproject.toml","go.mod","go.sum","requirements.txt","Dockerfile","Makefile",".env",".env.example","src","modules","tests","test",".venv","node_modules"],o=await Promise.all(e.map(J)),l=await Promise.all(s.map(async p=>{let d=await Promise.all(c.map(a=>J(n.join(p,a))));return `${p}::${d.join("|")}`}));return [...o,...l].join("||")}async function ot(t,s){try{if(!await r.pathExists(t))return null;let e=await r.readJSON(t);return !e||e.signature!==s||!Array.isArray(e.projects)?null:e}catch{return null}}async function it(t,s){try{await r.ensureDir(n.dirname(t)),await r.writeJSON(t,s,{spaces:2});}catch{}}async function nt(t,s,e){let c=n.join(t,".rapidkit","reports","doctor-last-run.json");try{return await r.ensureDir(n.dirname(c)),await r.writeJSON(c,{generatedAt:new Date().toISOString(),workspacePath:t,workspaceName:s.workspaceName,projectScanCached:s.projectScanCached??false,projectScanSignature:s.projectScanSignature,cachePath:e,healthScore:s.healthScore,system:{python:s.python,poetry:s.poetry,pipx:s.pipx,go:s.go,rapidkitCore:s.rapidkitCore,versions:{core:s.coreVersion,npm:s.npmVersion}},projects:s.projects,summary:{totalProjects:s.projects.length,totalIssues:s.projects.reduce((o,l)=>o+l.issues.length,0),hasSystemErrors:[s.python,s.rapidkitCore].some(o=>o.status==="error")}},{spaces:2}),c}catch{return}}async function B(){let[t,s,e,c,o]=await Promise.all([at(),rt(),ct(),lt(),dt()]);return {python:t,poetry:s,pipx:e,go:c,rapidkitCore:o}}async function at(){let t=d();for(let s of t)try{let{stdout:e}=await execa(s,["--version"],{timeout:3e3}),c=e.match(/Python (\d+\.\d+\.\d+)/);if(c){let o=c[1],[l,p]=o.split(".").map(Number);return l<3||l===3&&p<10?{status:"warn",message:`Python ${o} (requires 3.10+)`,details:`${s} found but version is below minimum requirement`}:{status:"ok",message:`Python ${o}`,details:`Using ${s}`}}}catch{continue}return {status:"error",message:"Python not found",details:"Install Python 3.10+ and ensure it's in PATH"}}async function rt(){try{let{stdout:t}=await execa("poetry",["--version"],{timeout:3e3}),s=t.match(/Poetry .*version ([\d.]+)/);return s?{status:"ok",message:`Poetry ${s[1]}`,details:"Available for dependency management"}:{status:"warn",message:"Poetry version unknown"}}catch{let t=d().map(s=>({cmd:s,args:s==="py"?["-3","-m","poetry","--version"]:["-m","poetry","--version"]}));for(let s of t)try{let{stdout:e}=await execa(s.cmd,s.args,{timeout:3e3,shell:b()}),c=e.match(/Poetry .*version ([\d.]+)/)||e.match(/([\d.]+)/);return {status:"ok",message:c?.[1]?`Poetry ${c[1]}`:"Poetry detected",details:`Available via ${s.cmd} ${s.args.join(" ")}`}}catch{continue}for(let s of Y())try{if(!await r.pathExists(s))continue;let{stdout:e}=await execa(s,["--version"],{timeout:3e3,shell:b()}),c=e.match(/Poetry .*version ([\d.]+)/)||e.match(/([\d.]+)/);return {status:"ok",message:c?.[1]?`Poetry ${c[1]}`:"Poetry detected",details:`Available at ${s}`}}catch{continue}return {status:"warn",message:"Poetry not installed",details:"Optional: Install for better dependency management"}}}async function ct(){try{let{stdout:t}=await execa("pipx",["--version"],{timeout:3e3});return {status:"ok",message:`pipx ${t.trim()}`,details:"Available for global tool installation"}}catch{let t=d();for(let s of t)try{let e=s==="py"?["-3","-m","pipx","--version"]:["-m","pipx","--version"],{stdout:c}=await execa(s,e,{timeout:3e3,shell:b()});return {status:"ok",message:`pipx ${c.trim()}`,details:`Available via ${s} ${e.join(" ")}`}}catch{continue}return {status:"warn",message:"pipx not installed",details:"Optional: Install for isolated Python tools"}}}async function lt(){try{let{stdout:t}=await execa("go",["version"],{timeout:3e3}),s=t.match(/go version go(\d+\.\d+(?:\.\d+)?)/);return s?{status:"ok",message:`Go ${s[1]}`,details:"Available for Go/Fiber and Go/Gin projects"}:{status:"ok",message:"Go (version unknown)",details:"go found in PATH"}}catch{return {status:"warn",message:"Go not installed",details:"Optional: Required only for gofiber.standard / gogin.standard projects \u2014 https://go.dev/dl/"}}}async function dt(){let t=process.env.HOME||process.env.USERPROFILE||"",s=[],e=Z(t);for(let{location:o,path:l}of e)try{if(await r.pathExists(l)){let{stdout:p,exitCode:d}=await execa(l,["--version"],{timeout:3e3,reject:false});if(d===0&&(p.includes("RapidKit Version")||p.includes("RapidKit"))){let a=p.match(/v?([\d.]+(?:rc\d+)?(?:a\d+)?(?:b\d+)?)/);a&&s.push({location:o,path:l,version:a[1]});}}}catch{continue}if(s.length>0){let o=s.filter(p=>p.location!=="Workspace (launcher)");if(o.length>0){let p=tt(o);return {status:"ok",message:`RapidKit Core ${p[0].version}`,paths:p.map(a=>({location:a.location,path:a.path,version:a.version}))}}return {status:"ok",message:`RapidKit Core ${s[0].version}`,details:"Detected via workspace launcher"}}try{let{stdout:o,exitCode:l}=await execa("rapidkit",["--version"],{timeout:3e3,reject:false});if(l===0&&(o.includes("RapidKit Version")||o.includes("RapidKit"))){let p=o.match(/v?([\d.]+(?:rc\d+)?(?:a\d+)?(?:b\d+)?)/);if(p)return {status:"ok",message:`RapidKit Core ${p[1]}`,details:"Available via PATH"}}}catch{}try{let{stdout:o,exitCode:l}=await execa("poetry",["run","rapidkit","--version"],{timeout:3e3,reject:false});if(l===0&&(o.includes("RapidKit Version")||o.includes("RapidKit"))){let p=o.match(/v?([\d.]+(?:rc\d+)?(?:a\d+)?(?:b\d+)?)/);if(p)return {status:"ok",message:`RapidKit Core ${p[1]}`,details:"Available via Poetry"}}}catch{}let c=d();for(let o of c)try{let{stdout:l,exitCode:p}=await execa(o,["-c","import rapidkit_core; print(rapidkit_core.__version__)"],{timeout:3e3,reject:false});if(p===0&&l&&!l.includes("Traceback")&&!l.includes("ModuleNotFoundError")){let d=l.trim();if(d)return {status:"ok",message:`RapidKit Core ${d}`,details:`Available in ${o} environment`}}}catch{continue}return {status:"error",message:"RapidKit Core not installed",details:"Install with: pipx install rapidkit-core"}}async function I(t,s){let e=n.join(t,"Dockerfile");s.hasDocker=await r.pathExists(e);let c=n.join(t,"tests"),o=n.join(t,"test"),l=n.join(t,"src","test"),p=await r.pathExists(c)||await r.pathExists(o)||await r.pathExists(l),d=false;if(s.framework==="Go/Fiber"||s.framework==="Go/Gin")try{let a=[{dir:t,depth:0}],u=4,m=new Set([".git",".venv","node_modules","dist","build","vendor"]);for(;a.length>0&&!d;){let h=a.shift();if(!h)break;let w=[];try{w=await r.readdir(h.dir);}catch{continue}for(let f of w){let g=n.join(h.dir,f),v;try{v=await r.stat(g);}catch{continue}if(v.isFile()&&f.endsWith("_test.go")){d=true;break}v.isDirectory()&&h.depth<u&&!m.has(f)&&!f.startsWith(".")&&a.push({dir:g,depth:h.depth+1});}}}catch{}if(s.hasTests=p||d,s.framework==="NestJS"){let a=n.join(t,".eslintrc.js"),u=n.join(t,".eslintrc.json");s.hasCodeQuality=await r.pathExists(a)||await r.pathExists(u);}else if(s.framework==="Go/Fiber"||s.framework==="Go/Gin"){let a=n.join(t,".golangci.yml"),u=n.join(t,".golangci.yaml"),m=n.join(t,"Makefile"),h=await r.pathExists(m)&&(await r.readFile(m,"utf8")).includes("golangci-lint");s.hasCodeQuality=await r.pathExists(a)||await r.pathExists(u)||h;}else if(s.framework==="FastAPI"){let a=n.join(t,"ruff.toml"),u=n.join(t,"pyproject.toml");if(await r.pathExists(u))try{let m=await r.readFile(u,"utf8");s.hasCodeQuality=m.includes("[tool.ruff]")||await r.pathExists(a);}catch{s.hasCodeQuality=await r.pathExists(a);}}else if(s.framework==="Spring Boot"){let a=n.join(t,"pom.xml");if(await r.pathExists(a))try{let u=await r.readFile(a,"utf8");s.hasCodeQuality=u.includes("spotless")||u.includes("checkstyle")||u.includes("pmd")||u.includes("maven-enforcer-plugin");}catch{s.hasCodeQuality=false;}}try{if(s.framework==="NestJS"){let{stdout:a}=await execa("npm",["audit","--json"],{cwd:t,reject:false});if(a)try{let m=JSON.parse(a).metadata?.vulnerabilities;m&&(s.vulnerabilities=(m.high||0)+(m.critical||0)+(m.moderate||0));}catch{}}else if(s.framework==="FastAPI"){let a=n.join(t,".venv"),u=f(a);if(await r.pathExists(u))try{let{stdout:m}=await execa(u,["-m","pip","list","--format=json"],{timeout:5e3,reject:false});if(m){JSON.parse(m);s.vulnerabilities=0;}}catch{}}}catch{}}async function ut(t){let e={name:n.basename(t),path:t,venvActive:false,depsInstalled:false,coreInstalled:false,issues:[],fixCommands:[]},c=n.join(t,".rapidkit");if(!await r.pathExists(c))return e.issues.push("Not a valid RapidKit project (missing .rapidkit directory)"),e;try{let f=n.join(t,"registry.json");if(await r.pathExists(f)){let g=await r.readJson(f);g.installed_modules&&(e.stats={modules:g.installed_modules.length});}}catch{}let o=null;try{let f=n.join(c,"project.json");if(await r.pathExists(f)){o=await r.readJson(f);let g=o?.kit_name||o?.kit;g&&(e.kit=g);}}catch{}try{let f=n.join(t,".git");if(await r.pathExists(f)){let{stdout:g}=await execa("git",["log","-1","--format=%cr"],{cwd:t,reject:false});g&&(e.lastModified=g.trim());}else {let g=await r.stat(t),x=Date.now()-g.mtime.getTime(),k=Math.floor(x/(1e3*60*60*24));e.lastModified=k===0?"today":`${k} day${k>1?"s":""} ago`;}}catch{}let l=n.join(t,"package.json"),p=n.join(t,"pyproject.toml"),d=n.join(t,"go.mod"),a=n.join(t,"pom.xml");if(await r.pathExists(d)||o?.runtime==="go"||typeof o?.kit_name=="string"&&(o.kit_name.startsWith("gofiber")||o.kit_name.startsWith("gogin"))){let f=o?.kit_name??"";e.framework=f.startsWith("gogin")?"Go/Gin":"Go/Fiber",e.isGoProject=true,e.venvActive=true,e.coreInstalled=false;try{await execa("go",["version"],{timeout:3e3});}catch{e.issues.push("Go toolchain not found \u2014 install from https://go.dev/dl/"),e.fixCommands?.push("https://go.dev/dl/");}let g=n.join(t,"go.sum");return await r.pathExists(g)?e.depsInstalled=true:(e.depsInstalled=false,e.issues.push("Go dependencies not downloaded (go.sum missing)"),e.fixCommands?.push(j(t,"go mod tidy"))),await I(t,e),e}if(await r.pathExists(a)||o?.runtime==="java"||typeof o?.kit_name=="string"&&o.kit_name.startsWith("springboot")){e.framework="Spring Boot",e.venvActive=true,e.coreInstalled=false;let f=await r.pathExists(a),g=await r.pathExists(n.join(t,"build.gradle"))||await r.pathExists(n.join(t,"build.gradle.kts")),v=await r.pathExists(n.join(t,"mvnw"))||await r.pathExists(n.join(t,"mvnw.cmd")),x=await r.pathExists(n.join(t,"gradlew"))||await r.pathExists(n.join(t,"gradlew.bat"));try{await execa("java",["-version"],{timeout:3e3,reject:false});}catch{e.issues.push("Java runtime not found \u2014 install JDK 21+ and ensure java is on PATH"),e.fixCommands?.push("https://adoptium.net/");}if(f){if(!v)try{await execa("mvn",["-version"],{timeout:3e3,reject:false});}catch{e.issues.push("Maven not found \u2014 install Maven 3.9+ or add Maven Wrapper"),e.fixCommands?.push("https://maven.apache.org/install.html");}}else if(g&&!x)try{await execa("gradle",["--version"],{timeout:3e3,reject:false});}catch{e.issues.push("Gradle not found \u2014 install Gradle 8+ or add Gradle Wrapper"),e.fixCommands?.push("https://gradle.org/install/");}let k=n.join(t,"target"),b=n.join(t,"build","libs"),G=n.join(t,".rapidkit","cache","java","m2"),F=n.join(t,".rapidkit","cache","java","gradle");e.depsInstalled=await r.pathExists(k)||await r.pathExists(b)||await r.pathExists(G)||await r.pathExists(F),e.depsInstalled||(e.issues.push("Java dependencies are not warmed or built yet"),e.fixCommands?.push(j(t,"rapidkit init")));let E=n.join(t,".env");if(e.hasEnvFile=await r.pathExists(E),!e.hasEnvFile){let S=n.join(t,".env.example");await r.pathExists(S)&&(e.issues.push("Environment file missing (found .env.example)"),e.fixCommands?.push(W(t)));}let A=n.join(t,"src","main","resources","application.yml");if(await r.pathExists(A))try{let S=await r.readFile(A,"utf-8");/include:\s*[^\n]*health/i.test(S)||/management:\s*[\s\S]*endpoint:\s*[\s\S]*health:/i.test(S)||(e.issues.push("Actuator health endpoint exposure is not clearly configured in application.yml"),e.fixCommands?.push(j(t,"Ensure management.endpoints.web.exposure.include contains health in src/main/resources/application.yml")));}catch{e.issues.push("Unable to read application.yml for Spring Actuator health checks");}return await I(t,e),e}let h=await r.pathExists(l),w=await r.pathExists(p);if(h){e.framework="NestJS",e.venvActive=true;let f=n.join(t,"node_modules");if(await r.pathExists(f))try{let k=(await r.readdir(f)).filter(b=>!b.startsWith(".")&&!b.startsWith("_"));e.depsInstalled=k.length>0;}catch{e.depsInstalled=false;}e.depsInstalled||(e.issues.push("Dependencies not installed (node_modules empty or missing)"),e.fixCommands?.push(j(t,"rapidkit init"))),e.coreInstalled=false;let g=n.join(t,".env");if(e.hasEnvFile=await r.pathExists(g),!e.hasEnvFile){let x=n.join(t,".env.example");await r.pathExists(x)&&(e.issues.push("Environment file missing (found .env.example)"),e.fixCommands?.push(W(t)));}let v=n.join(t,"src");if(e.modulesHealthy=true,e.missingModules=[],await r.pathExists(v))try{let x=await r.readdir(v);e.modulesHealthy=x.length>0;}catch{e.modulesHealthy=false;}return await I(t,e),e}if(w){e.framework="FastAPI";let f$1=n.join(t,".venv");if(await r.pathExists(f$1)){e.venvActive=true;let k=f(f$1);if(await r.pathExists(k)){try{let{stdout:b}=await execa(k,["-c","import rapidkit_core; print(rapidkit_core.__version__)"],{timeout:2e3});e.coreInstalled=true,e.coreVersion=b.trim();}catch{e.coreInstalled=false;}try{await execa(k,["-c","import fastapi"],{timeout:2e3}),e.depsInstalled=true;}catch{try{let b=n.join(f$1,"lib");if(await r.pathExists(b)){let F=(await r.readdir(b)).find(E=>E.startsWith("python"));if(F){let E=n.join(b,F,"site-packages");if(await r.pathExists(E)){let S=(await r.readdir(E)).filter(_=>!_.startsWith("_")&&!_.includes("dist-info")&&!["pip","setuptools","wheel","pkg_resources"].includes(_));e.depsInstalled=S.length>0;}}}e.depsInstalled||(e.issues.push("Dependencies not installed"),e.fixCommands?.push(j(t,"rapidkit init")));}catch{e.issues.push("Could not verify dependency installation");}}}else e.issues.push("Virtual environment exists but Python executable not found");}else e.issues.push("Virtual environment not created"),e.fixCommands?.push(j(t,"rapidkit init"));let g=n.join(t,".env");if(e.hasEnvFile=await r.pathExists(g),!e.hasEnvFile){let k=n.join(t,".env.example");await r.pathExists(k)&&(e.issues.push("Environment file missing (found .env.example)"),e.fixCommands?.push(W(t)));}let v=n.join(t,"src"),x=n.join(t,"modules");if(e.modulesHealthy=true,e.missingModules=[],await r.pathExists(v)){let k=n.join(v,"__init__.py");await r.pathExists(k)||(e.modulesHealthy=false,e.missingModules.push("src/__init__.py"));}if(await r.pathExists(x))try{let k=await Q(x);for(let b of k){let G=n.join(x,b,"__init__.py");await r.pathExists(G)||(e.modulesHealthy=false,e.missingModules.push(`modules/${b}/__init__.py`));}}catch{}return !e.modulesHealthy&&e.missingModules.length>0&&e.issues.push(`Missing module init files: ${e.missingModules.join(", ")}`),await I(t,e),e}return e.issues.push("Unknown project type (no package.json or pyproject.toml)"),await I(t,e),e}async function Q(t){try{return (await r.readdir(t,{withFileTypes:true})).filter(e=>e.isDirectory()).map(e=>e.name)}catch{try{let s=await r.readdir(t),e=[];for(let c of s)try{(await r.stat(n.join(t,c))).isDirectory()&&e.push(c);}catch{continue}return e}catch{return []}}}async function N(t){let s=n.join(t,".rapidkit");if(!await r.pathExists(s))return false;let e=["project.json","context.json","file-hashes.json"];for(let c of e)if(await r.pathExists(n.join(s,c)))return true;return false}function U(t,s){if(s.has(t))return true;let e=t.toLowerCase();return !!(e==="dist"||e.startsWith("dist-")||e.startsWith("dist_")||e==="build"||e.startsWith("build-")||e.startsWith("build_"))}async function pt(t,s,e){let c=new Set,o=[{dir:t,depth:0}];for(;o.length>0;){let l=o.shift();if(!l)break;try{let p=await r.readdir(l.dir);for(let d of p){if(U(d,e))continue;let a=n.join(l.dir,d),u;try{u=await r.stat(a);}catch{continue}if(u.isDirectory()){if(await N(a)){c.add(a);continue}l.depth<s&&o.push({dir:a,depth:l.depth+1});}}}catch{continue}}return Array.from(c)}async function K(t){let s=t,e=n.parse(s).root;for(;s!==e;){let c=[n.join(s,".rapidkit-workspace"),n.join(s,".rapidkit","workspace-marker.json"),n.join(s,".rapidkit","config.json")];for(let o of c)if(await r.pathExists(o))return s;s=n.dirname(s);}return null}function mt(t,s){let e=0,c=0,o=0;return t.forEach(p=>{p.status==="ok"?e++:p.status==="warn"?c++:p.status==="error"&&o++;}),s.forEach(p=>{(p.isGoProject?p.issues.length===0&&p.depsInstalled:p.issues.length===0&&p.venvActive&&p.depsInstalled)?e++:p.issues.length>0&&c++;}),{total:e+c+o,passed:e,warnings:c,errors:o}}async function O(t,s=true){let e=n.basename(t);try{let m=n.join(t,".rapidkit-workspace");await r.pathExists(m)&&(e=(await r.readJSON(m)).name||e);}catch{try{let m=n.join(t,".rapidkit","config.json");e=(await r.readJSON(m)).workspace_name||e;}catch{}}let[c,o]=await Promise.all([B(),et(t)]),l={workspacePath:t,workspaceName:e,python:c.python,poetry:c.poetry,pipx:c.pipx,go:c.go,rapidkitCore:c.rapidkitCore,projects:[]};a.debug(`Workspace scan found ${o.length} project(s)`);let p=await st(t,o),d=n.join(t,".rapidkit","reports","doctor-workspace-cache.json"),a$1=s?await ot(d,p):null;if(a$1)l.projects=a$1.projects,l.projectScanCached=true,a.debug(`Workspace project health cache hit: ${d}`);else try{let m=await Promise.all(o.map(h=>ut(h)));l.projects=m,l.projectScanCached=false,await it(d,{signature:p,generatedAt:new Date().toISOString(),projects:m}),a.debug(`Workspace project health cache refreshed: ${d}`);}catch(m){a.debug(`Failed to scan workspace projects: ${m}`);}l.projectScanSignature=p,l.projectScanCachePath=d;let u=[l.python,l.poetry,l.pipx,l.go,l.rapidkitCore];if(l.healthScore=mt(u,l.projects),l.rapidkitCore.status==="ok"){let m=l.rapidkitCore.message.match(/([\d.]+(?:rc\d+)?(?:a\d+)?(?:b\d+)?)/);m&&(l.coreVersion=m[1]);}return l.evidencePath=await nt(t,l,a$1?d:null),l}function C(t,s){let e=t.status==="ok"?"\u2705":t.status==="warn"?"\u26A0\uFE0F":"\u274C",c=t.status==="ok"?i.green:t.status==="warn"?i.yellow:i.red;console.log(`${e} ${i.bold(s)}: ${c(t.message)}`),t.paths&&t.paths.length>0?t.paths.forEach(o=>{let l=o.version?i.cyan(` -> ${o.version}`):"";console.log(` ${i.cyan("\u2022")} ${i.gray(o.location)}: ${i.dim(o.path)}${l}`);}):t.details&&console.log(` ${i.gray(t.details)}`);}function ht(t){let s=t.issues.length>0,e=s?"\u26A0\uFE0F":"\u2705",c=s?i.yellow:i.green;if(console.log(`
2
- ${e} ${i.bold("Project")}: ${c(t.name)}`),t.framework){let u=t.framework==="FastAPI"?"\u{1F40D}":t.framework==="NestJS"?"\u{1F985}":t.framework==="Spring Boot"?"\u2615":t.framework==="Go/Fiber"||t.framework==="Go/Gin"?"\u{1F439}":"\u{1F4E6}";console.log(` ${u} Framework: ${i.cyan(t.framework)}${t.kit?i.gray(` (${t.kit})`):""}`);}console.log(` ${i.gray(`Path: ${t.path}`)}`);let o=t.framework==="Go/Fiber"||t.framework==="Go/Gin",l=t.framework==="Spring Boot",p=t.framework==="NestJS";if(!o&&!p&&!l&&(t.venvActive?console.log(` \u2705 Virtual environment: ${i.green("Active")}`):console.log(` \u274C Virtual environment: ${i.red("Not found")}`),t.coreInstalled?console.log(` ${i.dim("\u2139")} RapidKit Core: ${i.gray(t.coreVersion||"In venv")} ${i.dim("(optional)")}`):console.log(` ${i.dim("\u2139")} RapidKit Core: ${i.gray("Using global installation")} ${i.dim("(recommended)")}`)),t.depsInstalled?console.log(` \u2705 Dependencies: ${i.green("Installed")}`):console.log(` \u26A0\uFE0F Dependencies: ${i.yellow("Not installed")}`),t.hasEnvFile!==void 0&&(t.hasEnvFile?console.log(` \u2705 Environment: ${i.green(".env configured")}`):console.log(` \u26A0\uFE0F Environment: ${i.yellow(".env missing")}`)),t.modulesHealthy!==void 0&&(t.modulesHealthy?console.log(` \u2705 Modules: ${i.green("Healthy")}`):t.missingModules&&t.missingModules.length>0&&console.log(` \u26A0\uFE0F Modules: ${i.yellow(`Missing ${t.missingModules.length} init file(s)`)}`)),t.stats){let u=[];t.stats.modules!==void 0&&u.push(`${t.stats.modules} module${t.stats.modules!==1?"s":""}`),u.length>0&&console.log(` \u{1F4CA} Stats: ${i.cyan(u.join(" \u2022 "))}`);}t.lastModified&&console.log(` \u{1F552} Last Modified: ${i.gray(t.lastModified)}`);let a=[];if(t.hasTests!==void 0&&a.push(t.hasTests?"\u2705 Tests":i.dim("\u2298 No tests")),t.hasDocker!==void 0&&a.push(t.hasDocker?"\u2705 Docker":i.dim("\u2298 No Docker")),t.hasCodeQuality!==void 0){let u=t.framework==="NestJS"?"ESLint":t.framework==="Spring Boot"?"Static analysis":t.framework==="Go/Fiber"||t.framework==="Go/Gin"?"golangci-lint":"Ruff";a.push(t.hasCodeQuality?`\u2705 ${u}`:i.dim(`\u2298 No ${u}`));}a.length>0&&console.log(` ${a.join(" \u2022 ")}`),t.vulnerabilities!==void 0&&t.vulnerabilities>0&&console.log(` \u26A0\uFE0F Security: ${i.yellow(`${t.vulnerabilities} vulnerability(ies) found`)}`),t.issues.length>0&&(console.log(` ${i.bold("Issues:")}`),t.issues.forEach(u=>{console.log(` \u2022 ${i.yellow(u)}`);}),t.fixCommands&&t.fixCommands.length>0&&(console.log(`
3
- ${i.bold.cyan("\u{1F527} Quick Fix:")}`),t.fixCommands.forEach(u=>{console.log(` ${i.cyan("$")} ${i.white(u)}`);})));}async function q(){try{return (await execa("go",["version"],{timeout:3e3,reject:false})).exitCode===0}catch{return false}}async function L(t,s=false){let e=t.filter(u=>u.fixCommands&&u.fixCommands.length>0),c=null;if(e.length===0){console.log(i.green(`
4
- \u2705 No fixes needed - all projects are healthy!`));return}console.log(i.bold.cyan(`
5
- \u{1F527} Available Fixes:
6
- `));for(let u of e){let m=u.fixCommands??[];console.log(i.bold(`Project: ${i.yellow(u.name)}`)),m.forEach((h,w)=>{console.log(` ${w+1}. ${i.cyan(h)}`);}),console.log();}let o=0;for(let u of e){let m=u.fixCommands??[];for(let h of m){if(/^https?:\/\//i.test(h.trim()))continue;if(d(h,"cp\\s+\\.env\\.example\\s+\\.env")||d(h,"copy-item\\s+\\.env\\.example\\s+\\.env")||d(h,"rapidkit\\s+init")){o+=1;continue}if(d(h,"go\\s+mod\\s+tidy")){c===null&&(c=await q()),c&&(o+=1);continue}o+=1;}}if(o===0){console.log(i.gray("\u{1F4A1} No automatic fixes can be applied right now.")),c===false&&console.log(i.gray(" Install Go to enable go mod tidy fixes, then rerun `rapidkit doctor workspace --fix`."));return}if(!s){console.log(i.gray('\u{1F4A1} Run "npx rapidkit doctor workspace --fix" to apply fixes automatically'));return}let{confirm:l}=await X.prompt([{type:"confirm",name:"confirm",message:`Apply ${e.reduce((u,m)=>u+(m.fixCommands?.length??0),0)} fix(es)?`,default:false}]);if(!l){console.log(i.yellow(`
7
- \u26A0\uFE0F Fixes cancelled by user`));return}console.log(i.bold.cyan(`
8
- \u{1F680} Applying fixes...
9
- `));let p=u=>/^https?:\/\//i.test(u.trim());function d(u,m){let h=[new RegExp(`^cd\\s+"([^"]+)"\\s*(?:&&|;)\\s*${m}\\s*$`,"i"),new RegExp(`^cd\\s+'([^']+)'\\s*(?:&&|;)\\s*${m}\\s*$`,"i"),new RegExp(`^cd\\s+(.+?)\\s*(?:&&|;)\\s*${m}\\s*$`,"i")];for(let w of h){let f=u.match(w);if(f?.[1])return {projectPath:f[1].trim()}}return null}function a(u){return d(u,"cp\\s+\\.env\\.example\\s+\\.env")||d(u,"copy-item\\s+\\.env\\.example\\s+\\.env")}for(let u of e){let m=u.fixCommands??[];console.log(i.bold(`Fixing ${i.cyan(u.name)}...`));for(let h of m)try{if(console.log(i.gray(` $ ${h}`)),p(h)){console.log(i.yellow(` \u2139 Manual action required: open ${h}`)),console.log(i.green(` \u2705 Recorded as guidance
10
- `));continue}let w=a(h);if(w){let v=n.join(w.projectPath,".env.example"),x=n.join(w.projectPath,".env");if(!await r.pathExists(v))throw new Error(`.env.example not found at ${v}`);if(await r.pathExists(x)){console.log(i.green(` \u2705 .env already exists
11
- `));continue}await r.copy(v,x,{overwrite:false,errorOnExist:false}),console.log(i.green(` \u2705 Success
12
- `));continue}let f=d(h,"rapidkit\\s+init");if(f){await execa("rapidkit",["init"],{cwd:f.projectPath,shell:b(),stdio:"inherit"}),console.log(i.green(` \u2705 Success
13
- `));continue}let g=d(h,"go\\s+mod\\s+tidy");if(g){if(c===null&&(c=await q()),!c){console.log(i.yellow(" \u26A0 Go toolchain is not installed \u2014 skipping go mod tidy; install Go to apply this fix.")),console.log(i.green(` \u2705 Recorded as guidance
14
- `));continue}await execa("go",["mod","tidy"],{cwd:g.projectPath,shell:b(),stdio:"inherit"}),console.log(i.green(` \u2705 Success
15
- `));continue}await execa(h,{shell:true,stdio:"inherit"}),console.log(i.green(` \u2705 Success
16
- `));}catch(w){console.log(i.red(` \u274C Failed: ${w instanceof Error?w.message:String(w)}
17
- `));}}console.log(i.bold.green(`
18
- \u2705 Fix process completed!`));}async function jt(t={}){let s=!t.workspace&&t.fix?await K(process.cwd()):null,e=t.workspace||!!s;if(t.json||console.log(i.bold.cyan(`
19
- \u{1FA7A} RapidKit Health Check
20
- `)),e){let c=s??await K(process.cwd());c||(a.error("No RapidKit workspace found in current directory or parents"),a.info('Run this command from within a workspace, or use "rapidkit doctor" for system check'),process.exit(1)),t.json||(s&&console.log(i.gray("\u2139\uFE0F Detected workspace context; enabling workspace checks for --fix")),console.log(i.bold(`Workspace: ${i.cyan(n.basename(c))}`)),console.log(i.gray(`Path: ${c}`)));let o=await O(c);if(t.json||(o.projectScanCached&&console.log(i.gray(`\u2139\uFE0F Reused cached project scan${o.projectScanCachePath?` (${n.basename(o.projectScanCachePath)})`:""}`)),o.evidencePath&&console.log(i.gray(`\u2139\uFE0F Evidence saved: ${o.evidencePath}`))),t.json){let d={workspace:{name:n.basename(c),path:c},cache:{projectScan:o.projectScanCached??false,projectScanPath:o.projectScanCachePath,evidencePath:o.evidencePath},healthScore:o.healthScore,system:{python:o.python,poetry:o.poetry,pipx:o.pipx,rapidkitCore:o.rapidkitCore,versions:{core:o.coreVersion,npm:o.npmVersion}},projects:o.projects.map(a=>({name:a.name,path:a.path,venvActive:a.venvActive,depsInstalled:a.depsInstalled,coreInstalled:a.coreInstalled,coreVersion:a.coreVersion,issues:a.issues,fixCommands:a.fixCommands})),summary:{totalProjects:o.projects.length,totalIssues:o.projects.reduce((a,u)=>a+u.issues.length,0),hasSystemErrors:[o.python,o.rapidkitCore].some(a=>a.status==="error")}};console.log(JSON.stringify(d,null,2));return}if(o.healthScore){let d=o.healthScore,a=Math.round(d.passed/d.total*100),u=a>=80?i.green:a>=50?i.yellow:i.red,m="\u2588".repeat(Math.floor(a/5))+"\u2591".repeat(20-Math.floor(a/5));console.log(i.bold(`
21
- \u{1F4CA} Health Score:`)),console.log(` ${u(`${a}%`)} ${i.gray(m)}`),console.log(` ${i.green(`\u2705 ${d.passed} passed`)} ${i.gray("|")} ${i.yellow(`\u26A0\uFE0F ${d.warnings} warnings`)} ${i.gray("|")} ${i.red(`\u274C ${d.errors} errors`)}`);}if(console.log(i.bold(`
22
-
23
- System Tools:
24
- `)),C(o.python,"Python"),C(o.poetry,"Poetry"),C(o.pipx,"pipx"),C(o.go,"Go"),C(o.rapidkitCore,"RapidKit Core"),o.coreVersion&&o.npmVersion){let d=o.coreVersion.split(".")[1],a=o.npmVersion.split(".")[1];d!==a&&(console.log(i.yellow(`
25
- \u26A0\uFE0F Version mismatch: Core ${o.coreVersion} / CLI ${o.npmVersion}`)),console.log(i.gray(" Consider updating to matching versions for best compatibility")));}o.projects.length>0?(console.log(i.bold(`
26
- \u{1F4E6} Projects (${o.projects.length}):`)),o.projects.forEach(d=>ht(d))):(console.log(i.bold(`
27
- \u{1F4E6} Projects:`)),console.log(i.gray(" No RapidKit projects found in workspace")));let l=o.projects.reduce((d,a)=>d+a.issues.length,0),p=[o.python,o.rapidkitCore].some(d=>d.status==="error");if(p||l>0)if(console.log(i.bold.yellow(`
28
- \u26A0\uFE0F Found ${l} project issue(s)`)),p&&console.log(i.bold.red("\u274C System requirements not met")),t.fix){if(await L(o.projects,true),!t.json){let d=await O(c,false),a=d.projects.reduce((m,h)=>m+h.issues.length,0),u=[d.python,d.rapidkitCore].some(m=>m.status==="error");u||a>0?(console.log(i.bold.yellow(`
29
- \u26A0\uFE0F Post-fix verification found ${a} remaining issue(s)`)),u&&console.log(i.bold.red("\u274C System requirements still not met"))):console.log(i.bold.green(`
30
- \u2705 Post-fix verification passed. Workspace is healthy.`)),d.projectScanCached&&console.log(i.gray(`\u2139\uFE0F Reused cached project scan${d.projectScanCachePath?` (${n.basename(d.projectScanCachePath)})`:""}`)),d.evidencePath&&console.log(i.gray(`\u2139\uFE0F Evidence refreshed: ${d.evidencePath}`));}}else l>0&&await L(o.projects,false);else console.log(i.bold.green(`
31
- \u2705 All checks passed! Workspace is healthy.`));}else {console.log(i.bold(`System Tools:
32
- `));let c=await B(),o=c.python,l=c.poetry,p=c.pipx,d=c.go,a=c.rapidkitCore;C(o,"Python"),C(l,"Poetry"),C(p,"pipx"),C(d,"Go"),C(a,"RapidKit Core"),[o,a].some(m=>m.status==="error")?(console.log(i.bold.red(`
33
- \u274C Some required tools are missing`)),t.fix&&console.log(i.gray(`
34
- Tip: Project auto-fix runs in workspace mode. Run from a workspace and use "rapidkit doctor workspace --fix"`)),console.log(i.gray(`
35
- Tip: Run "rapidkit doctor workspace" for detailed project checks`))):(console.log(i.bold.green(`
36
- \u2705 All required tools are installed!`)),t.fix&&console.log(i.gray(`
37
- Tip: Project auto-fix runs in workspace mode. Run from a workspace and use "rapidkit doctor workspace --fix"`)),console.log(i.gray(`
38
- Tip: Run "rapidkit doctor workspace" for detailed project checks`)));}console.log("");}export{jt as runDoctor};