rapidkit 0.23.1 → 0.24.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.22.0",
3
+ "version": "0.24.2",
4
4
  "type": "module",
5
5
  "description": "Create RapidKit projects with a single command - The official CLI for RapidKit framework",
6
6
  "keywords": [
@@ -57,6 +57,11 @@
57
57
  "security": "npm audit --audit-level=moderate",
58
58
  "security:fix": "npm audit fix",
59
59
  "metrics": "npx tsx scripts/metrics.ts",
60
+ "validate:docs-examples": "node scripts/validate-doc-examples.mjs",
61
+ "check:markdown-links": "node scripts/check-markdown-links.mjs",
62
+ "check:docs-drift": "node scripts/docs-drift-guard.mjs",
63
+ "smoke:readme": "node scripts/smoke-readme-commands.mjs",
64
+ "validate:docs": "npm run check:markdown-links && npm run check:docs-drift && npm run validate:docs-examples && npm run smoke:readme",
60
65
  "sync:contracts": "node scripts/sync-contracts.mjs",
61
66
  "check:contracts": "node scripts/sync-contracts.mjs --check",
62
67
  "bundle-size": "npm run build && du -sh dist/ && ls -lh dist/",
@@ -78,7 +83,7 @@
78
83
  "fs-extra": "^11.2.0",
79
84
  "inquirer": "^13.2.2",
80
85
  "nunjucks": "^3.2.4",
81
- "openai": "^4.80.0",
86
+ "openai": "^6.22.0",
82
87
  "ora": "^8.0.1",
83
88
  "validate-npm-package-name": "^5.0.1"
84
89
  },
@@ -95,7 +100,6 @@
95
100
  "@typescript-eslint/parser": "^8.46.2",
96
101
  "@vitest/coverage-v8": "^4.0.15",
97
102
  "@vitest/ui": "^4.0.15",
98
- "c8": "^10.1.3",
99
103
  "eslint": "^9.39.2",
100
104
  "husky": "^9.1.7",
101
105
  "lint-staged": "^15.5.2",
@@ -115,5 +119,8 @@
115
119
  "prettier --write"
116
120
  ]
117
121
  },
122
+ "overrides": {
123
+ "minimatch": "^10.2.1"
124
+ },
118
125
  "packageManager": "npm@10.8.2"
119
126
  }
@@ -1 +1 @@
1
- export{j as __test__,b as checkRapidkitCoreAvailable,h as getCachedCoreTopLevelCommands,g as getCoreTopLevelCommands,i as getModulesCatalog,c as resolveRapidkitPython,d as runCoreRapidkit,f as runCoreRapidkitCapture,e as runCoreRapidkitStreamed}from'./chunk-74G6C57B.js';
1
+ export{j as __test__,b as checkRapidkitCoreAvailable,h as getCachedCoreTopLevelCommands,g as getCoreTopLevelCommands,i as getModulesCatalog,c as resolveRapidkitPython,d as runCoreRapidkit,f as runCoreRapidkitCapture,e as runCoreRapidkitStreamed}from'./chunk-5JB4MOC5.js';
@@ -1,4 +1,4 @@
1
- import {c}from'./chunk-7LU4Z66R.js';import {promises}from'fs';import i from'path';import e from'chalk';import y from'ora';import {execa}from'execa';import k from'os';async function C(t,r){try{let o=process.env.XDG_CONFIG_HOME||process.env.APPDATA||i.join(k.homedir(),".config"),a=process.platform==="win32"?i.join(o,"rapidkit"):i.join(k.homedir(),".rapidkit"),n=i.join(a,"workspaces.json");await promises.mkdir(a,{recursive:true});let s={workspaces:[]};try{let c=await promises.readFile(n,"utf8"),m=JSON.parse(c);m&&Array.isArray(m.workspaces)&&(s=m);}catch{}s.workspaces.some(c=>c.path===t)||(s.workspaces.push({name:r,path:t,mode:"full",projects:[]}),await promises.writeFile(n,JSON.stringify(s,null,2)));}catch{console.warn(e.gray("Note: Could not register workspace in shared registry"));}}async function T(t,r=false){try{let o=process.env.XDG_CONFIG_HOME||process.env.APPDATA||i.join(k.homedir(),".config"),a=process.platform==="win32"?i.join(o,"rapidkit"):i.join(k.homedir(),".rapidkit"),n=i.join(a,"workspaces.json"),s={workspaces:[]};try{let l=await promises.readFile(n,"utf8"),h=JSON.parse(l);h&&Array.isArray(h.workspaces)&&(s=h);}catch{r||console.log("\u26A0\uFE0F Workspace registry not found");return}let d=s.workspaces.find(l=>l.path===t);if(!d){r||console.log("\u26A0\uFE0F Workspace not registered in registry");return}Array.isArray(d.projects)||(d.projects=[]);let c=await promises.readdir(t,{withFileTypes:true}),m=0,g=0;for(let l of c)if(l.isDirectory()&&!l.name.startsWith(".")){let h=i.join(t,l.name),j=i.join(h,".rapidkit","context.json"),w=i.join(h,".rapidkit","project.json");try{let $=false;try{await promises.access(j),$=true;}catch{await promises.access(w),$=true;}$&&(d.projects.some(_=>_.path===h||_.name===l.name)?g++:(d.projects.push({name:l.name,path:h}),m++,r||console.log(`\u2714 Added: ${l.name}`)));}catch{}}m>0?(await promises.writeFile(n,JSON.stringify(s,null,2)),r||console.log(`
1
+ import {c}from'./chunk-N64Z3XVF.js';import {promises}from'fs';import i from'path';import e from'chalk';import y from'ora';import {execa}from'execa';import k from'os';async function C(t,r){try{let o=process.env.XDG_CONFIG_HOME||process.env.APPDATA||i.join(k.homedir(),".config"),a=process.platform==="win32"?i.join(o,"rapidkit"):i.join(k.homedir(),".rapidkit"),n=i.join(a,"workspaces.json");await promises.mkdir(a,{recursive:true});let s={workspaces:[]};try{let c=await promises.readFile(n,"utf8"),m=JSON.parse(c);m&&Array.isArray(m.workspaces)&&(s=m);}catch{}s.workspaces.some(c=>c.path===t)||(s.workspaces.push({name:r,path:t,mode:"full",projects:[]}),await promises.writeFile(n,JSON.stringify(s,null,2)));}catch{console.warn(e.gray("Note: Could not register workspace in shared registry"));}}async function T(t,r=false){try{let o=process.env.XDG_CONFIG_HOME||process.env.APPDATA||i.join(k.homedir(),".config"),a=process.platform==="win32"?i.join(o,"rapidkit"):i.join(k.homedir(),".rapidkit"),n=i.join(a,"workspaces.json"),s={workspaces:[]};try{let l=await promises.readFile(n,"utf8"),h=JSON.parse(l);h&&Array.isArray(h.workspaces)&&(s=h);}catch{r||console.log("\u26A0\uFE0F Workspace registry not found");return}let d=s.workspaces.find(l=>l.path===t);if(!d){r||console.log("\u26A0\uFE0F Workspace not registered in registry");return}Array.isArray(d.projects)||(d.projects=[]);let c=await promises.readdir(t,{withFileTypes:true}),m=0,g=0;for(let l of c)if(l.isDirectory()&&!l.name.startsWith(".")){let h=i.join(t,l.name),j=i.join(h,".rapidkit","context.json"),w=i.join(h,".rapidkit","project.json");try{let $=false;try{await promises.access(j),$=true;}catch{await promises.access(w),$=true;}$&&(d.projects.some(_=>_.path===h||_.name===l.name)?g++:(d.projects.push({name:l.name,path:h}),m++,r||console.log(`\u2714 Added: ${l.name}`)));}catch{}}m>0?(await promises.writeFile(n,JSON.stringify(s,null,2)),r||console.log(`
2
2
  \u2705 Synced ${m} project(s) to registry`)):r||console.log(`
3
3
  \u2705 All projects already registered (${g} found)`);}catch(o){r||console.error("\u274C Failed to sync projects:",o.message);}}async function G(t,r,o){try{let a=process.env.XDG_CONFIG_HOME||process.env.APPDATA||i.join(k.homedir(),".config"),n=process.platform==="win32"?i.join(a,"rapidkit"):i.join(k.homedir(),".rapidkit"),s=i.join(n,"workspaces.json");console.log(`[REGISTRY DEBUG] Registry file: ${s}`);let d={workspaces:[]};try{let g=await promises.readFile(s,"utf8"),l=JSON.parse(g);l&&Array.isArray(l.workspaces)&&(d=l),console.log(`[REGISTRY DEBUG] Registry loaded, ${d.workspaces.length} workspaces`);}catch{console.log("[REGISTRY DEBUG] Registry doesn't exist, returning");return}let c=d.workspaces.find(g=>g.path===t);if(!c){console.log("[REGISTRY DEBUG] Workspace not found in registry, returning");return}console.log(`[REGISTRY DEBUG] Workspace found: ${c.name}`),Array.isArray(c.projects)||(c.projects=[]),c.projects.some(g=>g.path===o||g.name===r)?console.log("[REGISTRY DEBUG] Project already exists in registry"):(console.log("[REGISTRY DEBUG] Adding project to registry"),c.projects.push({name:r,path:o}),await promises.writeFile(s,JSON.stringify(d,null,2)),console.log("[REGISTRY DEBUG] Registry updated successfully"));}catch(a){console.log(`[REGISTRY DEBUG] Error: ${a}`);}}async function U(t,r){let o=y("Creating RapidKit workspace...").start();try{await promises.mkdir(t,{recursive:true}),await promises.mkdir(i.join(t,".rapidkit"),{recursive:true});let a={workspace_name:r.name,author:r.author,rapidkit_version:c(),created_at:new Date().toISOString(),type:"workspace"};await promises.writeFile(i.join(t,".rapidkit","config.json"),JSON.stringify(a,null,2));let n=x();await promises.writeFile(i.join(t,"rapidkit"),n),await promises.chmod(i.join(t,"rapidkit"),493);let s=E(r.name);if(await promises.writeFile(i.join(t,"README.md"),s),await promises.writeFile(i.join(t,".gitignore"),`# RapidKit workspace
4
4
  .env
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapidkit",
3
- "version": "0.23.1",
3
+ "version": "0.24.2",
4
4
  "type": "module",
5
5
  "description": "Create RapidKit projects with a single command - The official CLI for RapidKit framework",
6
6
  "keywords": [
@@ -57,6 +57,11 @@
57
57
  "security": "npm audit --audit-level=moderate",
58
58
  "security:fix": "npm audit fix",
59
59
  "metrics": "npx tsx scripts/metrics.ts",
60
+ "validate:docs-examples": "node scripts/validate-doc-examples.mjs",
61
+ "check:markdown-links": "node scripts/check-markdown-links.mjs",
62
+ "check:docs-drift": "node scripts/docs-drift-guard.mjs",
63
+ "smoke:readme": "node scripts/smoke-readme-commands.mjs",
64
+ "validate:docs": "npm run check:markdown-links && npm run check:docs-drift && npm run validate:docs-examples && npm run smoke:readme",
60
65
  "sync:contracts": "node scripts/sync-contracts.mjs",
61
66
  "check:contracts": "node scripts/sync-contracts.mjs --check",
62
67
  "bundle-size": "npm run build && du -sh dist/ && ls -lh dist/",
@@ -1,24 +0,0 @@
1
- import z from'crypto';import B from'os';import c from'path';import*as d from'fs-extra';import {execa}from'execa';var W=["version","project","create","init","dev","start","build","test","lint","format","add","list","info","upgrade","diff","doctor","license","commands","reconcile","rollback","uninstall","checkpoint","optimize","snapshot","frameworks","modules","merge"],A=new Set(W);var y=class extends Error{code;constructor(n,e){super(e),this.code=n;}};function C(t){if(t instanceof y)switch(t.code){case "PYTHON_NOT_FOUND":return "RapidKit (npm) could not find Python (python3/python) on your PATH.\nInstall Python 3.10+ and ensure `python3` is available, then retry.\nTip: if you are inside a RapidKit project, use the local ./rapidkit launcher.";case "BRIDGE_VENV_CREATE_FAILED":return `RapidKit (npm) failed to create its bridge virtual environment.
2
- Ensure Python venv support is installed (e.g., python3-venv).
3
- Details: ${t.message}`;case "BRIDGE_PIP_BOOTSTRAP_FAILED":return `RapidKit (npm) could not bootstrap pip inside the bridge virtual environment.
4
- Install python3-venv/python3-pip and retry.
5
- Details: ${t.message}`;case "BRIDGE_PIP_UPGRADE_FAILED":return `RapidKit (npm) could not upgrade pip in the bridge virtual environment.
6
- Check your network/proxy or disable RAPIDKIT_BRIDGE_UPGRADE_PIP.
7
- Details: ${t.message}`;case "BRIDGE_PIP_INSTALL_FAILED":return `RapidKit (npm) could not install rapidkit-core in the bridge virtual environment.
8
- Check your network/proxy, or install manually with: pipx install rapidkit-core.
9
- Details: ${t.message}`;default:return `RapidKit (npm) bridge error: ${t.message}`}return `RapidKit (npm) failed to run the Python core engine: ${t instanceof Error?t.message:String(t)}`}function S(){let t=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE;return t&&t.trim()?t.trim():"rapidkit-core"}function X(){let t=S(),n=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE_ID,e=n&&n.trim()?`${t}|${n.trim()}`:t;return z.createHash("sha256").update(e).digest("hex").slice(0,12)}function R(){let t=process.env.XDG_CACHE_HOME;return t&&t.trim()?t:c.join(B.homedir(),".cache")}function q(){return c.join(R(),"rapidkit","npm-bridge","venv")}function F(){let t=X();return c.join(R(),"rapidkit","npm-bridge",`venv-${t}`)}function O(t){return process.platform==="win32"?c.join(t,"Scripts","python.exe"):c.join(t,"bin","python")}function N(t){return process.platform==="win32"?c.join(t,"Scripts","rapidkit.exe"):c.join(t,"bin","rapidkit")}function Q(t){return /[<>=!~]=|@|\.whl$|\.tar\.gz$|\.zip$|git\+|https?:\/\//.test(t)}function Z(t){return c.dirname(c.dirname(t))}function G(){return c.join(R(),"rapidkit","npm-bridge","core-commands.json")}async function V(t){let n=!!process.env.RAPIDKIT_DEBUG,e=r=>{n&&process.stderr.write(`[DEBUG] tryRapidkit(${t}): ${r}
10
- `);};try{e("probing interpreter-specific rapidkit script");let s=((await execa(t,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"],{reject:false,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(e(`script path: ${s}`),s)try{if(await d.pathExists(s)){e(`found script at ${s}; invoking --version --json`);let i=await execa(s,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(e(`script exitCode=${i.exitCode}`),i.exitCode===0){let a=(i.stdout??"").toString().trim();try{let o=JSON.parse(a),p=!!o&&typeof o=="object"&&o!==null&&"version"in o;if(e(`script JSON parse ok=${p}`),p)return true}catch{e("script output not valid JSON");}}}}catch(i){e(`interpreter-specific script probe failed: ${String(i)}`);}}catch(r){e(`interpreter-specific script probe error: ${String(r)}`);}try{e('probing importlib.find_spec("rapidkit")');let r=await execa(t,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"],{reject:false,stdio:"pipe",timeout:2e3});if(e(`import probe exitCode=${r.exitCode} stdout=${(r.stdout??"").toString().trim()}`),r.exitCode===0&&(r.stdout??"").toString().trim()==="1")return true}catch(r){e(`import probe error: ${String(r)}`);}try{e("probing python -m rapidkit");let r=await execa(t,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:8e3});if(e(`-m probe exitCode=${r.exitCode}`),r.exitCode===0)return true}catch(r){e(`-m probe error: ${String(r)}`);}try{e("probing PATH for rapidkit executables");let r=(process.env.PATH??"").split(c.delimiter).filter(Boolean);for(let s of r){let i=c.join(s,process.platform==="win32"?"rapidkit.exe":"rapidkit");try{if(await d.pathExists(i)){e(`found candidate on PATH: ${i}; invoking --version --json`);let a=await execa(i,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(e(`candidate exitCode=${a.exitCode}`),a.exitCode===0){let o=(a.stdout??"").toString().trim();try{let p=JSON.parse(o);if(p&&typeof p=="object"&&p!==null&&"version"in p)return true}catch{e("candidate output not valid JSON, skipping");}}}}catch(a){e(`error probing candidate ${i}: ${String(a)}`);}}return e("no valid rapidkit found on PATH"),false}catch(r){return e(`PATH probe error: ${String(r)}`),false}}async function D(t){let n=(t??"").toString().trim();if(!n)return false;try{let e=JSON.parse(n);return !!e&&typeof e=="object"&&e!==null&&"version"in e}catch{return false}}async function tt(t){let n=process.platform==="win32",e=n?c.join(".venv","Scripts","rapidkit.exe"):c.join(".venv","bin","rapidkit"),r=n?c.join(".venv","Scripts","python.exe"):c.join(".venv","bin","python"),s=t;for(let i=0;i<25;i+=1){let a=c.join(s,e);if(await d.pathExists(a)){let l=await execa(a,["--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:s});if(l.exitCode===0&&await D(l.stdout))return {cmd:a,baseArgs:[]}}let o=c.join(s,r);if(await d.pathExists(o)){let l=await execa(o,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:s});if(l.exitCode===0&&await D(l.stdout))return {cmd:o,baseArgs:["-m","rapidkit"]}}let p=c.dirname(s);if(p===s)break;s=p;}return null}async function et(t){try{let n=c.join(t,".python-version");if(await d.pathExists(n)){let r=(await d.readFile(n,"utf-8")).trim();if(r)return r}}catch{}try{let n=c.join(t,".rapidkit-workspace");if(await d.pathExists(n)){let e=await d.readFile(n,"utf-8"),r=JSON.parse(e);if(r.pythonVersion)return r.pythonVersion}}catch{}return null}async function j(t){if(t&&t.trim())try{let i=await tt(t);if(i){let a=c.dirname(i.cmd).includes(".venv")?c.dirname(c.dirname(c.dirname(i.cmd))):c.dirname(i.cmd),o=await et(a);return o&&(process.env.PYENV_VERSION=o),i}}catch{}let n=await rt();if(n.kind==="venv"){let i=Z(n.pythonPath),a=N(i);return await d.pathExists(a)?{cmd:a,baseArgs:[]}:{cmd:n.pythonPath,baseArgs:["-m","rapidkit"]}}try{if((await execa(n.cmd,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:4e3})).exitCode===0)return {cmd:n.cmd,baseArgs:["-m","rapidkit"]}}catch{}try{let a=((await execa(n.cmd,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"],{reject:false,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(a&&await d.pathExists(a))try{let o=await execa(a,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(o.exitCode===0&&await D(o.stdout))return {cmd:a,baseArgs:[]}}catch{}}catch{}let e=F(),r=await x(n.cmd),s=N(e);return await d.pathExists(s)?{cmd:s,baseArgs:[]}:{cmd:r,baseArgs:["-m","rapidkit"]}}async function I(){for(let t of ["python3","python"])try{return await execa(t,["--version"],{reject:false,stdio:"pipe",timeout:2e3}),t}catch{}return null}async function nt(){let t=!!process.env.RAPIDKIT_DEBUG,n=e=>{t&&process.stderr.write(`[DEBUG] checkRapidkitCore: ${e}
11
- `);};for(let e of ["python3","python","python3.10","python3.11","python3.12"])try{n(`Method 1: trying ${e} import`);let r=await execa(e,["-c","import rapidkit_core; print(1)"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.trim()==="1")return n(`\u2713 Found via ${e} import`),true}catch{continue}for(let e of ["python3","python"])try{n(`Method 2: trying ${e} -m pip show`);let r=await execa(e,["-m","pip","show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found via ${e} -m pip show`),true}catch{continue}for(let e of ["pip","pip3"])try{n(`Method 3: trying ${e} show`);let r=await execa(e,["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found via ${e} show`),true}catch{continue}try{n("Method 4: checking pyenv versions");let e=await execa("pyenv",["versions","--bare"],{reject:false,stdio:"pipe",timeout:3e3});if(e.exitCode===0&&e.stdout){let r=e.stdout.split(`
12
- `).filter(s=>s.trim());n(`Found pyenv versions: ${r.join(", ")}`);for(let s of r){let i=process.env.PYENV_ROOT||c.join(B.homedir(),".pyenv"),a=c.join(i,"versions",s.trim(),"bin","pip");try{let o=await execa(a,["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found in pyenv ${s}`),true}catch{try{let o=await execa("bash",["-c",`PYENV_VERSION=${s.trim()} pyenv exec pip show rapidkit-core`],{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found in pyenv ${s} via PYENV_VERSION`),true}catch{continue}}}}}catch{n("pyenv not available");}for(let e of ["python3","python"])try{n(`Method 5: checking ${e} user site`);let r=await execa(e,["-m","site","--user-site"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout){let s=r.stdout.trim(),i=c.join(s,"rapidkit_core");if(await d.pathExists(i))return n("\u2713 Found in user site-packages"),true}}catch{continue}try{n("Method 6: checking pipx");let e=await execa("pipx",["list"],{reject:false,stdio:"pipe",timeout:3e3});if(e.exitCode===0&&e.stdout?.includes("rapidkit-core"))return n("\u2713 Found via pipx"),true}catch{n("pipx not available");}try{if(n("Method 7: checking poetry"),(await execa("poetry",["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3})).exitCode===0)return n("\u2713 Found via poetry"),true}catch{n("poetry check failed");}try{n("Method 8: checking conda");let e=await execa("conda",["list","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(e.exitCode===0&&e.stdout?.includes("rapidkit-core"))return n("\u2713 Found via conda"),true}catch{n("conda not available");}return n("\u2717 Not found in any environment"),false}async function x(t){let n=F(),e=q(),r=S(),s=[n];!Q(r)&&!await d.pathExists(n)&&await d.pathExists(e)&&s.push(e);for(let m of s){let h=O(m);if(await d.pathExists(h))try{let f=await execa(h,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"],{reject:false,stdio:"pipe",timeout:2e3});if(f.exitCode===0&&(f.stdout??"").toString().trim()==="1")return h;await d.remove(m);}catch{await d.remove(m);}}let i=n,a={...process.env,PIP_DISABLE_PIP_VERSION_CHECK:"1",PIP_NO_PYTHON_VERSION_WARNING:"1"},o=Math.max(0,Number(process.env.RAPIDKIT_BRIDGE_PIP_RETRY??"2")),p=Math.max(200,Number(process.env.RAPIDKIT_BRIDGE_PIP_RETRY_DELAY_MS??"800")),l=Math.max(1e4,Number(process.env.RAPIDKIT_BRIDGE_PIP_TIMEOUT_MS??"120000")),w=m=>new Promise(h=>setTimeout(h,m)),v=async(m,h,f)=>{let g=await execa(m,h,{reject:false,stdio:["ignore","pipe","inherit"],env:a,timeout:f});if(g.exitCode===0)return;let k=(g.stdout??"").toString(),b=(g.stderr??"").toString(),P=[k,b].filter(Boolean).join(`
13
- `),H=P?`${m} ${h.join(" ")}
14
- ${P}`:`${m} ${h.join(" ")}`;throw new Error(H)},E=async(m,h,f)=>{let g=0;for(;;)try{await v(m,h,f);return}catch(k){if(g>=o)throw k;let b=Math.floor(Math.random()*200),P=p*Math.pow(2,g)+b;g+=1,await w(P);}};try{await d.ensureDir(c.dirname(i));try{await v(t,["-m","venv",i],6e4);}catch(f){let g=f instanceof Error?f.message:String(f);throw new y("BRIDGE_VENV_CREATE_FAILED",g)}let m=O(i);if((await execa(m,["-m","pip","--version"],{reject:false,stdio:"pipe",timeout:2e3})).exitCode!==0&&(await execa(m,["-m","ensurepip","--default-pip"],{reject:false,stdio:["ignore","pipe","inherit"],env:a,timeout:6e4})).exitCode!==0)throw new y("BRIDGE_PIP_BOOTSTRAP_FAILED","ensurepip failed; install python3-venv/python3-pip and retry.");if(process.env.RAPIDKIT_BRIDGE_UPGRADE_PIP==="1")try{await E(m,["-m","pip","install","-U","pip"],l);}catch(f){let g=f instanceof Error?f.message:String(f);throw new y("BRIDGE_PIP_UPGRADE_FAILED",g)}try{await E(m,["-m","pip","install","-U",S()],l);}catch(f){let g=f instanceof Error?f.message:String(f);throw new y("BRIDGE_PIP_INSTALL_FAILED",g)}return m}catch(m){if(m instanceof y)throw m;let h=m instanceof Error?m.message:String(m);throw new y("BRIDGE_VENV_BOOTSTRAP_FAILED",h)}}async function rt(){if(process.env.RAPIDKIT_BRIDGE_FORCE_VENV==="1"){let e=await I();if(!e)throw new y("PYTHON_NOT_FOUND","No Python interpreter found (python3/python).");return {kind:"venv",pythonPath:await x(e)}}for(let e of ["python3","python"])if(await V(e))return {kind:"system",cmd:e};let t=await I();if(!t)throw new y("PYTHON_NOT_FOUND","No Python interpreter found (python3/python).");return {kind:"venv",pythonPath:await x(t)}}async function ht(t,n){try{let e=await j(n?.cwd),r=e.cmd,s=[...e.baseArgs,...t],i=await execa(r,s,{cwd:n?.cwd,env:{...process.env,...n?.env},reject:false,stdio:"inherit"});return typeof i.exitCode=="number"?i.exitCode:1}catch(e){return process.stderr.write(`${C(e)}
15
- `),1}}var it=[{pattern:/RapidKitError:\s*Directory '([^']+)' exists and force is not set/,message:t=>`\u274C Directory "${c.basename(t[1])}" already exists.
16
- \u{1F4A1} Choose a different name, or remove the existing directory first:
17
- rm -rf ${t[1]}`},{pattern:/RapidKitError:\s*Project name '([^']+)' is (invalid|not allowed)/i,message:t=>`\u274C Invalid project name: "${t[1]}"
18
- \u{1F4A1} Use lowercase letters, numbers, and hyphens only (e.g. my-api).`},{pattern:/RapidKitError:\s*Kit '([^']+)' not found/i,message:t=>`\u274C Unknown kit: "${t[1]}"
19
- \u{1F4A1} Run "npx rapidkit list" to see available kits.`},{pattern:/RapidKitError:\s*(.+)/,message:t=>`\u274C ${t[1].trim()}`}];async function gt(t,n){let{spawn:e}=await import('child_process');try{let r=await j(n?.cwd),s=r.cmd,i=[...r.baseArgs,...t];return await new Promise(a=>{let o=e(s,i,{cwd:n?.cwd,env:{...process.env,...n?.env},stdio:["inherit","inherit","pipe"]}),p=[];o.stderr?.on("data",l=>{p.push(l);}),o.on("close",l=>{let w=l??1;if(w!==0&&p.length>0){let v=Buffer.concat(p).toString("utf8");for(let{pattern:E,message:m}of it){let h=v.match(E);if(h){process.stderr.write(m(h)+`
20
- `),a(w);return}}process.stderr.write(v);}a(w);}),o.on("error",l=>{process.stderr.write(`${C(l)}
21
- `),a(1);});})}catch(r){return process.stderr.write(`${C(r)}
22
- `),1}}async function _(t,n){try{let e=await j(n?.cwd),r=e.cmd,s=[...e.baseArgs,...t],i=await execa(r,s,{cwd:n?.cwd,env:{...process.env,...n?.env},reject:false,stdio:"pipe"});return {exitCode:typeof i.exitCode=="number"?i.exitCode:1,stdout:(i.stdout??"").toString(),stderr:(i.stderr??"").toString()}}catch(e){return {exitCode:1,stdout:"",stderr:`${C(e)}
23
- `}}}function K(t){let n=new Set,e=t.split(`
24
- `),r=false;for(let s of e){let i=s.replace(/\r$/,"");if(!r){/^\s*Commands:\s*$/i.test(i)&&(r=true);let p=i.match(/^\s*rapidkit\s+([a-z0-9_-]+)\b/i);if(p){let l=p[1].trim();l&&!l.startsWith("-")&&n.add(l);}continue}if(!i.trim())break;if(/^\s*(Options|Arguments|Usage|Commands)\s*:/i.test(i))continue;let a=i.match(/^\s*([a-z0-9][a-z0-9_-]*)\b/i);if(!a)continue;let o=a[1].trim();o&&!o.startsWith("-")&&n.add(o);}return n}async function L(){let t=G();if(!await d.pathExists(t))return null;try{let n=await d.readJson(t);if(n&&n.schema_version===1&&Array.isArray(n.commands))return n}catch{}return null}async function T(t){let n=G();await d.ensureDir(c.dirname(n)),await d.writeJson(n,t,{spaces:2});}async function ot(){let t=await _(["version","--json"],{cwd:process.cwd()});if(t.exitCode===0)try{let e=JSON.parse(t.stdout)?.version;return typeof e=="string"?e:void 0}catch{return}}async function st(){let t=await _(["commands","--json"],{cwd:process.cwd()});if(t.exitCode!==0)return null;try{let n=JSON.parse(t.stdout);if(n?.schema_version!==1||!Array.isArray(n.commands))return null;let e=n.commands.filter(r=>typeof r=="string");return e.length?e:null}catch{return null}}async function yt(){let n=Date.now(),e=await L(),r=await ot(),s=!!e?.commands?.length;if(s&&n-e.fetched_at<864e5&&(!r||!e.rapidkit_version||e.rapidkit_version===r))return new Set(e.commands);let i=await st();if(i?.length){let l=Array.from(new Set(i)).sort();return await T({schema_version:1,fetched_at:n,rapidkit_version:r,commands:l}),new Set(l)}let a=await _(["--help"],{cwd:process.cwd()});if(a.exitCode!==0)return s&&e?.commands?new Set(e.commands):new Set(A);let o=K(a.stdout);if(o.size===0)return new Set(A);let p=Array.from(o).sort();return await T({schema_version:1,fetched_at:n,rapidkit_version:r,commands:p}),o}async function wt(){let n=Date.now(),e=await L();return !e||n-e.fetched_at>=864e5||!e.commands?.length?null:new Set(e.commands)}function J(){return c.join(R(),"rapidkit","npm-bridge","modules-catalog.json")}async function at(){let t=J();if(!await d.pathExists(t))return null;try{let n=await d.readJson(t);if(n&&n.schema_version===1&&Array.isArray(n.modules))return n}catch{}return null}async function $(t){let n=J();await d.ensureDir(c.dirname(n)),await d.writeJson(n,t,{spaces:2});}function M(t){try{return JSON.parse(t)}catch{return null}}async function vt(t={}){let n=typeof t.ttlMs=="number"?t.ttlMs:18e5,e=Date.now(),r=await at();if(r?.fetched_at&&e-r.fetched_at<n)return r;let s=["modules","list","--json-schema","1"];t.category&&s.push("--category",t.category),t.tag&&s.push("--tag",t.tag),t.detailed&&s.push("--detailed");let i=await _(s,{cwd:t.cwd,env:t.env});if(i.exitCode===0){let o=M(i.stdout);if(o&&o.schema_version===1&&Array.isArray(o.modules)){let p={...o,fetched_at:e};return await $(p),p}}let a=await _(["modules","list","--json"],{cwd:t.cwd,env:t.env});if(a.exitCode===0){let o=M(a.stdout);if(Array.isArray(o)){let p={schema_version:1,generated_at:new Date().toISOString(),filters:{category:t.category??null,tag:t.tag??null,detailed:!!t.detailed},stats:{total:o.length,returned:o.length,invalid:0},modules:o,source:"legacy-json",fetched_at:e};return await $(p),p}}return r||null}var _t={pickSystemPython:I,ensureBridgeVenv:x,parseCoreCommandsFromHelp:K,tryRapidkit:V,checkRapidkitCoreAvailable:nt};export{A as a,nt as b,rt as c,ht as d,gt as e,_ as f,yt as g,wt as h,vt as i,_t as j};