rapidkit 0.27.3 → 0.27.5

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.3",
3
+ "version": "0.27.5",
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": [
@@ -47,6 +47,9 @@
47
47
  "test:e2e:user-first-install": "bash scripts/e2e-user-first-install.sh",
48
48
  "test": "vitest run",
49
49
  "test:drift": "RAPIDKIT_DRIFT_GUARD=1 vitest run src/__tests__/drift-guard.test.ts",
50
+ "sync:parity-snapshot": "node scripts/sync-import-stack-parity-snapshot.mjs",
51
+ "check:parity-snapshot": "node scripts/sync-import-stack-parity-snapshot.mjs --check",
52
+ "test:parity-contract": "npm run sync:parity-snapshot -- --npm-only && vitest run src/__tests__/contracts/import-stack-parity.snapshot.test.ts",
50
53
  "test:watch": "vitest",
51
54
  "test:coverage": "vitest run --coverage",
52
55
  "test:prepare-embeddings": "npx tsx scripts/generate-mock-embeddings.ts",
@@ -0,0 +1 @@
1
+ export{k as __test__,b as checkRapidkitCoreAvailable,c as checkRapidkitCoreVersionCompatible,i as getCachedCoreTopLevelCommands,h as getCoreTopLevelCommands,j as getModulesCatalog,d as resolveRapidkitPython,e as runCoreRapidkit,g as runCoreRapidkitCapture,f as runCoreRapidkitStreamed}from'./chunk-RWV2GNJJ.js';
@@ -1,6 +1,6 @@
1
- import {j as j$1}from'./chunk-Z5LKRG57.js';import {b as b$1}from'./chunk-Q7ULIFQA.js';import {promises}from'fs';import n from'path';import a from'chalk';import b from'ora';import {execa}from'execa';function j(e){let t=n.resolve(e);return process.platform==="win32"?t.toLowerCase():t}function I(e){let t=j(e.path),r=Array.isArray(e.projects)?e.projects:[],o=[],i=new Set;for(let s of r){if(!s||typeof s.name!="string"||typeof s.path!="string")continue;let c=j(s.path);i.has(c)||(i.add(c),o.push({name:s.name,path:c}));}return {name:e.name,path:t,mode:e.mode,projects:o}}function x(e){let t=[],r=new Set;for(let o of e.workspaces||[]){if(!o||typeof o.name!="string"||typeof o.path!="string")continue;let i=I(o);r.has(i.path)||(r.add(i.path),t.push(i));}return {workspaces:t}}async function A(e,t){try{let r=j(e),o=j$1(),i=n.join(o,"workspaces.json");await promises.mkdir(o,{recursive:true});let s={workspaces:[]};try{let p=await promises.readFile(i,"utf8"),d=JSON.parse(p);d&&Array.isArray(d.workspaces)&&(s=x(d));}catch{}s.workspaces.some(p=>p.path===r)||(s.workspaces.push({name:t,path:r,mode:"full",projects:[]}),await promises.writeFile(i,JSON.stringify(s,null,2)));}catch{console.warn(a.gray("Note: Could not register workspace in shared registry"));}}async function X(e,t=false){try{let r=j(e),o=j$1(),i=n.join(o,"workspaces.json"),s={workspaces:[]};try{let g=await promises.readFile(i,"utf8"),f=JSON.parse(g);f&&Array.isArray(f.workspaces)&&(s=x(f));}catch{t||console.log("\u26A0\uFE0F Workspace registry not found");return}let c=s.workspaces.find(g=>g.path===r);if(!c){t||console.log("\u26A0\uFE0F Workspace not registered in registry");return}Array.isArray(c.projects)||(c.projects=[]);let p=0,d=0,u=[e],m=new Set;for(;u.length>0;){let g=u.shift();if(!g||m.has(g))continue;m.add(g);let f=await promises.readdir(g,{withFileTypes:true});for(let y of f){if(!y.isDirectory()||y.name.startsWith(".")||["node_modules","dist","build","target","coverage","htmlcov"].includes(y.name))continue;let k=n.join(g,y.name),h=j(k),v=n.join(h,".rapidkit","context.json"),E=n.join(h,".rapidkit","project.json");try{let _=false;try{await promises.access(v),_=true;}catch{await promises.access(E),_=true;}if(_){let $=n.basename(h);c.projects.some(R=>R.path===h||R.name===$)?d++:(c.projects.push({name:$,path:h}),p++,t||console.log(`\u2714 Added: ${n.relative(e,h)}`));continue}}catch{}u.push(k);}}p>0?(await promises.writeFile(i,JSON.stringify(s,null,2)),t||console.log(`
1
+ import {c}from'./chunk-NFUXULIF.js';import {j as j$1}from'./chunk-Z5LKRG57.js';import {b as b$1}from'./chunk-Q7ULIFQA.js';import {promises}from'fs';import n from'path';import a from'chalk';import b from'ora';import {execa}from'execa';function j(e){let t=n.resolve(e);return process.platform==="win32"?t.toLowerCase():t}function A(e){let t=j(e.path),r=Array.isArray(e.projects)?e.projects:[],o=[],i=new Set;for(let s of r){if(!s||typeof s.name!="string"||typeof s.path!="string")continue;let c=j(s.path);i.has(c)||(i.add(c),o.push({name:s.name,path:c}));}return {name:e.name,path:t,mode:e.mode,projects:o}}function x(e){let t=[],r=new Set;for(let o of e.workspaces||[]){if(!o||typeof o.name!="string"||typeof o.path!="string")continue;let i=A(o);r.has(i.path)||(r.add(i.path),t.push(i));}return {workspaces:t}}async function F(e,t){try{let r=j(e),o=j$1(),i=n.join(o,"workspaces.json");await promises.mkdir(o,{recursive:true});let s={workspaces:[]};try{let p=await promises.readFile(i,"utf8"),d=JSON.parse(p);d&&Array.isArray(d.workspaces)&&(s=x(d));}catch{}s.workspaces.some(p=>p.path===r)||(s.workspaces.push({name:t,path:r,mode:"full",projects:[]}),await promises.writeFile(i,JSON.stringify(s,null,2)));}catch{console.warn(a.gray("Note: Could not register workspace in shared registry"));}}async function te(e,t=false){try{let r=j(e),o=j$1(),i=n.join(o,"workspaces.json"),s={workspaces:[]};try{let g=await promises.readFile(i,"utf8"),k=JSON.parse(g);k&&Array.isArray(k.workspaces)&&(s=x(k));}catch{t||console.log("\u26A0\uFE0F Workspace registry not found");return}let c=s.workspaces.find(g=>g.path===r);if(!c){t||console.log("\u26A0\uFE0F Workspace not registered in registry");return}Array.isArray(c.projects)||(c.projects=[]);let p=0,d=0,u=[e],m=new Set;for(;u.length>0;){let g=u.shift();if(!g||m.has(g))continue;m.add(g);let k=await promises.readdir(g,{withFileTypes:true});for(let y of k){if(!y.isDirectory()||y.name.startsWith(".")||["node_modules","dist","build","target","coverage","htmlcov"].includes(y.name))continue;let f=n.join(g,y.name),h=j(f),v=n.join(h,".rapidkit","context.json"),E=n.join(h,".rapidkit","project.json");try{let _=false;try{await promises.access(v),_=true;}catch{await promises.access(E),_=true;}if(_){let $=n.basename(h);c.projects.some(R=>R.path===h||R.name===$)?d++:(c.projects.push({name:$,path:h}),p++,t||console.log(`\u2714 Added: ${n.relative(e,h)}`));continue}}catch{}u.push(f);}}p>0?(await promises.writeFile(i,JSON.stringify(s,null,2)),t||console.log(`
2
2
  \u2705 Synced ${p} project(s) to registry`)):t||console.log(`
3
- \u2705 All projects already registered (${d} found)`);}catch(r){t||console.error("\u274C Failed to sync projects:",r.message);}}async function Z(e,t,r){try{let o=j(e),i=j(r),s=j$1(),c=n.join(s,"workspaces.json"),p={workspaces:[]};try{let m=await promises.readFile(c,"utf8"),g=JSON.parse(m);g&&Array.isArray(g.workspaces)&&(p=x(g));}catch{return}let d=p.workspaces.find(m=>m.path===o);if(!d)return;Array.isArray(d.projects)||(d.projects=[]),d.projects.some(m=>m.path===i||m.name===t)||(d.projects.push({name:t,path:i}),await promises.writeFile(c,JSON.stringify(p,null,2)));}catch{}}async function ee(e,t){let r=b("Creating RapidKit workspace...").start();try{await promises.mkdir(e,{recursive:true}),await promises.mkdir(n.join(e,".rapidkit"),{recursive:true});let o={workspace_name:t.name,author:t.author,rapidkit_version:b$1(),created_at:new Date().toISOString(),type:"workspace"};await promises.writeFile(n.join(e,".rapidkit","config.json"),JSON.stringify(o,null,2));let{syncWorkspaceFoundationFiles:i}=await import('./create-3V7O72CO.js');await i(e,{workspaceName:t.name,installMethod:"venv",writeMarker:true,writeGitignore:false,onlyIfMissing:true});let s=F();await promises.writeFile(n.join(e,"rapidkit"),s),await promises.chmod(n.join(e,"rapidkit"),493);let c=O();await promises.writeFile(n.join(e,"rapidkit.cmd"),c);let p=B(t.name);if(await promises.writeFile(n.join(e,"README.md"),p),await promises.writeFile(n.join(e,".gitignore"),`# RapidKit workspace
3
+ \u2705 All projects already registered (${d} found)`);}catch(r){t||console.error("\u274C Failed to sync projects:",r.message);}}async function re(e,t,r){try{let o=j(e),i=j(r),s=j$1(),c=n.join(s,"workspaces.json"),p={workspaces:[]};try{let m=await promises.readFile(c,"utf8"),g=JSON.parse(m);g&&Array.isArray(g.workspaces)&&(p=x(g));}catch{return}let d=p.workspaces.find(m=>m.path===o);if(!d)return;Array.isArray(d.projects)||(d.projects=[]),d.projects.some(m=>m.path===i||m.name===t)||(d.projects.push({name:t,path:i}),await promises.writeFile(c,JSON.stringify(p,null,2)));}catch{}}async function ie(e,t){let r=b("Creating RapidKit workspace...").start();try{await promises.mkdir(e,{recursive:true}),await promises.mkdir(n.join(e,".rapidkit"),{recursive:true});let o={workspace_name:t.name,author:t.author,rapidkit_version:b$1(),created_at:new Date().toISOString(),type:"workspace"};await promises.writeFile(n.join(e,".rapidkit","config.json"),JSON.stringify(o,null,2));let{syncWorkspaceFoundationFiles:i}=await import('./create-4NQKTQ3C.js');await i(e,{workspaceName:t.name,installMethod:"venv",writeMarker:true,writeGitignore:false,onlyIfMissing:true});let s=O();await promises.writeFile(n.join(e,"rapidkit"),s),await promises.chmod(n.join(e,"rapidkit"),493);let c=B();await promises.writeFile(n.join(e,"rapidkit.cmd"),c);let p=T(t.name);if(await promises.writeFile(n.join(e,"README.md"),p),await promises.writeFile(n.join(e,".gitignore"),`# RapidKit workspace
4
4
  .env
5
5
  .env.*
6
6
  !.env.example
@@ -15,7 +15,7 @@ Thumbs.db
15
15
 
16
16
  # Logs
17
17
  *.log
18
- `),await promises.writeFile(n.join(e,".rapidkit-workspace"),JSON.stringify({signature:"RAPIDKIT_WORKSPACE",createdBy:"rapidkit-npm",version:b$1(),createdAt:new Date().toISOString(),name:t.name},null,2)),await T(e),r.succeed("Workspace created!"),!t.skipGit){let u=b("Initializing git repository...").start();try{await execa("git",["init"],{cwd:e}),await execa("git",["add","."],{cwd:e}),await execa("git",["commit","-m","Initial commit: RapidKit workspace"],{cwd:e}),u.succeed("Git repository initialized");}catch{u.warn("Could not initialize git repository");}}await A(e,t.name),console.log(`
18
+ `),await promises.writeFile(n.join(e,".rapidkit-workspace"),JSON.stringify({signature:"RAPIDKIT_WORKSPACE",createdBy:"rapidkit-npm",version:b$1(),createdAt:new Date().toISOString(),name:t.name},null,2)),await z(e),r.succeed("Workspace created!"),!t.skipGit){let u=b("Initializing git repository...").start();try{await execa("git",["init"],{cwd:e}),await execa("git",["add","."],{cwd:e}),await execa("git",["commit","-m","Initial commit: RapidKit workspace"],{cwd:e}),u.succeed("Git repository initialized");}catch{u.warn("Could not initialize git repository");}}await F(e,t.name),console.log(`
19
19
  ${a.green("\u2728 RapidKit workspace created successfully!")}
20
20
 
21
21
  ${a.bold("\u{1F4C2} Workspace structure:")}
@@ -52,7 +52,7 @@ ${a.bold("\u{1F4DA} Commands:")}
52
52
 
53
53
  ${a.gray("Alternative: ./rapidkit dev (Windows: .\\rapidkit.cmd dev), make dev")}
54
54
  ${a.gray("\u{1F4A1} Tip: Install globally (npm i -g rapidkit) to use without npx")}
55
- `);}catch(o){throw r.fail("Failed to create workspace"),o}}function F(){return `#!/usr/bin/env bash
55
+ `);}catch(o){throw r.fail("Failed to create workspace"),o}}function O(){return `#!/usr/bin/env bash
56
56
  #
57
57
  # RapidKit CLI - Local workspace commands
58
58
  # This script provides rapidkit commands within the workspace
@@ -412,7 +412,7 @@ main() {
412
412
  }
413
413
 
414
414
  main "$@"
415
- `}function O(){return `@echo off
415
+ `}function B(){return `@echo off
416
416
  setlocal enabledelayedexpansion
417
417
 
418
418
  set "SCRIPT_DIR=%~dp0"
@@ -432,7 +432,7 @@ if %ERRORLEVEL%==0 (
432
432
  echo [RapidKit] No sh/bash found. Falling back to npx rapidkit.
433
433
  npx rapidkit %*
434
434
  exit /b %ERRORLEVEL%
435
- `}function B(e){return `# ${e}
435
+ `}function T(e){return `# ${e}
436
436
 
437
437
  RapidKit workspace for building API projects.
438
438
 
@@ -480,7 +480,7 @@ npx rapidkit dev # Start dev server
480
480
 
481
481
  - [RapidKit Documentation](https://rapidkit.dev)
482
482
  - [GitHub Repository](https://github.com/Baziar/rapidkit)
483
- `}async function T(e){let{fileURLToPath:t}=await import('url'),r=t(import.meta.url),o=n.dirname(r),i=n.resolve(o,".."),s=n.join(i,"templates","kits"),c=n.join(e,".rapidkit","templates"),{default:p}=await import('fs-extra');await p.copy(s,c);let d=n.join(i,"templates","generator.js"),u=n.join(e,".rapidkit","generator.js");await p.copy(d,u);}async function te(e,t){let r=t.template==="fastapi",o=r?"FastAPI":"NestJS",i=b(`Creating ${o} project...`).start();try{let{fileURLToPath:s}=await import('url'),c=s(import.meta.url),p=n.dirname(c),d=n.resolve(p,".."),u=r?"fastapi-standard":"nestjs-standard",m=n.join(d,"templates","kits",u);await promises.mkdir(e,{recursive:true});let g={project_name:r?t.name.replace(/-/g,"_").toLowerCase():t.name.replace(/_/g,"-").toLowerCase(),author:t.author,description:t.description||`${o} application generated with RapidKit`,app_version:"0.1.0",license:"MIT",package_manager:t.package_manager||"npm",created_at:new Date().toISOString(),rapidkit_version:b$1()};await W(m,e,g);let f=r?`# Python
483
+ `}async function z(e){let{fileURLToPath:t}=await import('url'),r=t(import.meta.url),o=n.dirname(r),i=n.resolve(o,".."),s=n.join(i,"templates","kits"),c=n.join(e,".rapidkit","templates"),{default:p}=await import('fs-extra');await p.copy(s,c);let d=n.join(i,"templates","generator.js"),u=n.join(e,".rapidkit","generator.js");await p.copy(d,u);}async function ae(e,t){let r=t.template==="fastapi",o=r?"FastAPI":"NestJS",i=b(`Creating ${o} project...`).start();try{let{fileURLToPath:s}=await import('url'),c=s(import.meta.url),p=n.dirname(c),d=n.resolve(p,".."),u=r?"fastapi-standard":"nestjs-standard",m=n.join(d,"templates","kits",u);await promises.mkdir(e,{recursive:true});let g={project_name:r?t.name.replace(/-/g,"_").toLowerCase():t.name.replace(/_/g,"-").toLowerCase(),author:t.author,description:t.description||`${o} application generated with RapidKit`,app_version:"0.1.0",license:"MIT",package_manager:t.package_manager||"npm",created_at:new Date().toISOString(),rapidkit_version:b$1()};await W(m,e,g);let k=r?`# Python
484
484
  __pycache__/
485
485
  *.py[cod]
486
486
  *$py.class
@@ -548,7 +548,7 @@ Thumbs.db
548
548
 
549
549
  # Coverage
550
550
  coverage/
551
- `;if(await promises.writeFile(n.join(e,".gitignore"),f),i.succeed(`${o} project created!`),!t.skipGit){let k=b("Initializing git repository...").start();try{await execa("git",["init"],{cwd:e}),await execa("git",["add","."],{cwd:e}),await execa("git",["commit","-m",`Initial commit: ${o} project via RapidKit`],{cwd:e}),k.succeed("Git repository initialized");}catch{k.warn("Could not initialize git repository");}}if(!t.skipInstall&&!r){let k=t.package_manager||"npm",h=b(`Installing dependencies with ${k}...`).start();try{await execa(k,["install"],{cwd:e}),h.succeed("Dependencies installed");}catch{h.warn(`Could not install dependencies. Run '${k} install' manually.`);}}let y=n.basename(e);console.log(r?`
551
+ `;if(await promises.writeFile(n.join(e,".gitignore"),k),i.succeed(`${o} project created!`),!t.skipGit){let f=b("Initializing git repository...").start();try{await execa("git",["init"],{cwd:e}),await execa("git",["add","."],{cwd:e}),await execa("git",["commit","-m",`Initial commit: ${o} project via RapidKit`],{cwd:e}),f.succeed("Git repository initialized");}catch{f.warn("Could not initialize git repository");}}if(!t.skipInstall&&!r){let f=t.package_manager||"npm",h=b(`Installing dependencies with ${f}...`).start();try{await execa(f,["install"],{cwd:e}),h.succeed("Dependencies installed");}catch{h.warn(`Could not install dependencies. Run '${f} install' manually.`);}}let y=n.basename(e);console.log(r?`
552
552
  ${a.green("\u2728 FastAPI project created successfully!")}
553
553
 
554
554
  ${a.bold("\u{1F4C2} Project structure:")}
@@ -614,7 +614,7 @@ ${a.bold("\u{1F310} API endpoints:")}
614
614
  http://localhost:8000/examples/notes # Example API
615
615
 
616
616
  ${a.gray("\u{1F4A1} Tip: Install globally (npm i -g rapidkit) to use without npx")}
617
- `);}catch(s){throw i.fail(`Failed to create ${o} project`),s}}async function W(e,t,r){let o=await promises.readdir(e,{withFileTypes:true});for(let i of o){let s=n.join(e,i.name),c=i.name.replace(/\.j2$/,""),p=n.join(t,c);if(i.isDirectory())await promises.mkdir(p,{recursive:true}),await W(s,p,r);else {let d=await promises.readFile(s,"utf-8");i.name.endsWith(".j2")&&(d=z(d,r)),await promises.writeFile(p,d),(c==="rapidkit"||c==="activate"||c.endsWith(".py")&&p.includes(".rapidkit"))&&await promises.chmod(p,493);}}}function z(e,t){let r=e;for(let[o,i]of Object.entries(t)){let s=new RegExp(`\\{\\{\\s*${o}\\s*\\}\\}`,"g");r=r.replace(s,String(i));let c=new RegExp(`\\{\\{\\s*${o}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\}\\}`,"g");r=r.replace(c,(u,m,g)=>String(i).replace(new RegExp(m,"g"),g));let p=new RegExp(`\\{\\{\\s*${o}\\s*\\|\\s*lower\\s*\\}\\}`,"g");r=r.replace(p,String(i).toLowerCase());let d=new RegExp(`\\{\\{\\s*${o}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\|\\s*lower\\s*\\}\\}`,"g");r=r.replace(d,(u,m,g)=>String(i).replace(new RegExp(m,"g"),g).toLowerCase());}return r}async function re(){let e=j$1(),t=n.join(e,"workspaces.json");if(!await promises.stat(t).catch(()=>null)){console.log(a.yellow(`
617
+ `);}catch(s){throw i.fail(`Failed to create ${o} project`),s}}async function W(e,t,r){let o=await promises.readdir(e,{withFileTypes:true});for(let i of o){let s=n.join(e,i.name),c=i.name.replace(/\.j2$/,""),p=n.join(t,c);if(i.isDirectory())await promises.mkdir(p,{recursive:true}),await W(s,p,r);else {let d=await promises.readFile(s,"utf-8");i.name.endsWith(".j2")&&(d=U(d,r)),await promises.writeFile(p,d),(c==="rapidkit"||c==="activate"||c.endsWith(".py")&&p.includes(".rapidkit"))&&await promises.chmod(p,493);}}}function U(e,t){let r=e;for(let[o,i]of Object.entries(t)){let s=new RegExp(`\\{\\{\\s*${o}\\s*\\}\\}`,"g");r=r.replace(s,String(i));let c=new RegExp(`\\{\\{\\s*${o}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\}\\}`,"g");r=r.replace(c,(u,m,g)=>String(i).replace(new RegExp(m,"g"),g));let p=new RegExp(`\\{\\{\\s*${o}\\s*\\|\\s*lower\\s*\\}\\}`,"g");r=r.replace(p,String(i).toLowerCase());let d=new RegExp(`\\{\\{\\s*${o}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\|\\s*lower\\s*\\}\\}`,"g");r=r.replace(d,(u,m,g)=>String(i).replace(new RegExp(m,"g"),g).toLowerCase());}return r}async function oe(){let e=j$1(),t=n.join(e,"workspaces.json");if(!await promises.stat(t).catch(()=>null)){console.log(a.yellow(`
618
618
  \u26A0\uFE0F No workspaces registered yet.
619
619
  `)),console.log(a.gray(`Create a workspace with: npx rapidkit <workspace-name>
620
620
  `));return}try{let r=await promises.readFile(t,"utf8"),o=JSON.parse(r);if(!o||typeof o!="object"||!Array.isArray(o.workspaces)){console.log(a.yellow(`
@@ -626,4 +626,4 @@ ${a.gray("\u{1F4A1} Tip: Install globally (npm i -g rapidkit) to use without npx
626
626
  \u{1F4E6} Registered RapidKit Workspaces:
627
627
  `));for(let m of p.workspaces)console.log(a.cyan(` ${m.name}`)),console.log(a.gray(` Path: ${m.path}`)),console.log(a.gray(` Projects: ${m.projects?.length||0}`)),console.log();c>0&&console.log(a.gray(`Cleaned ${c} stale workspace entr${c===1?"y":"ies"}.`)),console.log(a.gray(`Total: ${p.workspaces.length} workspace(s)
628
628
  `));}catch(r){console.error(a.red(`
629
- \u274C Failed to read workspace registry`)),console.error(a.gray(String(r)));}}async function P(e){try{let t=await promises.readFile(e,"utf8");return JSON.parse(t)}catch{return null}}async function D(e){try{return await promises.access(e),true}catch{return false}}async function U(e){let t=[],r=[e],o=new Set;for(;r.length>0;){let i=r.shift();if(!i||o.has(i))continue;o.add(i);let s=[];try{s=await promises.readdir(i,{withFileTypes:true});}catch{continue}for(let c of s){if(!c.isDirectory()||c.name.startsWith(".")||["node_modules","dist","build","target","coverage","htmlcov"].includes(c.name))continue;let p=n.join(i,c.name),d=await D(n.join(p,".rapidkit","context.json")),u=await D(n.join(p,".rapidkit","project.json"));(d||u)&&t.push(p),r.push(p);}}return t.sort((i,s)=>i.localeCompare(s))}async function L(e){try{return (await promises.readdir(e,{withFileTypes:true})).filter(r=>r.isFile()&&r.name.toLowerCase().endsWith(".json")).map(r=>r.name).sort((r,o)=>r.localeCompare(o))}catch{return []}}async function ie(e,t){let r=t?.includePaths===true,o=t?.includeDoctorEvidence!==false,i=n.resolve(e),s=await P(n.join(i,".rapidkit","workspace.json")),c=typeof s?.workspace_name=="string"&&s.workspace_name.trim()||n.basename(i),p=typeof s?.profile=="string"?s.profile:void 0,d=typeof s?.rapidkit_version=="string"?s.rapidkit_version:void 0,u=await U(i),m=[];for(let h of u){let v=await P(n.join(h,".rapidkit","project.json")),E=n.relative(i,h)||".",_=n.join(h,".rapidkit","reports"),$={name:n.basename(h),relative_path:E,runtime:typeof v?.runtime=="string"?v.runtime:void 0,kit_name:typeof v?.kit_name=="string"?v.kit_name:void 0};if(r&&($.absolute_path=h),o){let R=await P(n.join(_,"doctor-last-run.json"));R&&($.doctor_report=R);}let N=await L(_);N.length>0&&($.reports=N),m.push($);}let g=n.join(i,".rapidkit","reports"),f=await L(g),y={schema_version:"1.0",generated_at:new Date().toISOString(),generated_by:"rapidkit-npm",workspace:{name:c,relative_root:".",profile:p,rapidkit_version:d,...r?{absolute_root:i}:{}},summary:{project_count:m.length,doctor_evidence_included:o},reports:{workspace:f},projects:m},k=t?.outputPath?n.resolve(t.outputPath):n.join(g,"share-bundle.json");return await promises.mkdir(n.dirname(k),{recursive:true}),await promises.writeFile(k,JSON.stringify(y,null,2),"utf8"),k}export{te as createProject,ee as createWorkspace,ie as createWorkspaceShareBundle,re as listWorkspaces,Z as registerProjectInWorkspace,A as registerWorkspace,X as syncWorkspaceProjects};
629
+ \u274C Failed to read workspace registry`)),console.error(a.gray(String(r)));}}async function P(e){try{let t=await promises.readFile(e,"utf8");return JSON.parse(t)}catch{return null}}function J(e){return c(e)}async function L(e){try{return await promises.access(e),true}catch{return false}}async function G(e){let t=[],r=[e],o=new Set;for(;r.length>0;){let i=r.shift();if(!i||o.has(i))continue;o.add(i);let s=[];try{s=await promises.readdir(i,{withFileTypes:true});}catch{continue}for(let c of s){if(!c.isDirectory()||c.name.startsWith(".")||["node_modules","dist","build","target","coverage","htmlcov"].includes(c.name))continue;let p=n.join(i,c.name),d=await L(n.join(p,".rapidkit","context.json")),u=await L(n.join(p,".rapidkit","project.json"));(d||u)&&t.push(p),r.push(p);}}return t.sort((i,s)=>i.localeCompare(s))}async function I(e){try{return (await promises.readdir(e,{withFileTypes:true})).filter(r=>r.isFile()&&r.name.toLowerCase().endsWith(".json")).map(r=>r.name).sort((r,o)=>r.localeCompare(o))}catch{return []}}async function ne(e,t){let r=t?.includePaths===true,o=t?.includeDoctorEvidence!==false,i=n.resolve(e),s=await P(n.join(i,".rapidkit","workspace.json")),c=typeof s?.workspace_name=="string"&&s.workspace_name.trim()||n.basename(i),p=typeof s?.profile=="string"?s.profile:void 0,d=typeof s?.rapidkit_version=="string"?s.rapidkit_version:void 0,u=await G(i),m=[];for(let h of u){let v=await P(n.join(h,".rapidkit","project.json")),E=n.relative(i,h)||".",_=n.join(h,".rapidkit","reports"),$={name:n.basename(h),relative_path:E,runtime:typeof v?.runtime=="string"?v.runtime:void 0,kit_name:typeof v?.kit_name=="string"?v.kit_name:void 0};if(r&&($.absolute_path=h),o){let R=await P(n.join(_,"doctor-last-run.json"));J(R)&&($.doctor_report=R);}let N=await I(_);N.length>0&&($.reports=N),m.push($);}let g=n.join(i,".rapidkit","reports"),k=await I(g),y={schema_version:"1.0",generated_at:new Date().toISOString(),generated_by:"rapidkit-npm",workspace:{name:c,relative_root:".",profile:p,rapidkit_version:d,...r?{absolute_root:i}:{}},summary:{project_count:m.length,doctor_evidence_included:o},reports:{workspace:k},projects:m},f=t?.outputPath?n.resolve(t.outputPath):n.join(g,"share-bundle.json");return await promises.mkdir(n.dirname(f),{recursive:true}),await promises.writeFile(f,JSON.stringify(y,null,2),"utf8"),f}export{ae as createProject,ie as createWorkspace,ne as createWorkspaceShareBundle,oe as listWorkspaces,re as registerProjectInWorkspace,F as registerWorkspace,te as syncWorkspaceProjects};
@@ -0,0 +1,3 @@
1
+ import {e,d,a,b}from'./chunk-TYC54P7X.js';import v from'fs';import m from'path';import R from'chalk';import {execa}from'execa';var ue={"python-fastapi":{runtime:"python",framework:"FastAPI",markers:["pyproject.toml","fastapi"],commands:{init:"python -m pip install -e .",test:"pytest",build:"python -m build",start:"uvicorn main:app --reload"},errorPatterns:{setup:["ModuleNotFoundError","No module named","pip: command not found"],"test-failure":["FAILED","ERROR","test session started"],dependency:["ImportError","missing.*dependency"],runtime:["TypeError","AttributeError","ValueError"],timeout:["timeout","Timeout","timed out"],unknown:[]},healthCheck:{stage:"start",type:"http",value:"http://localhost:8000/docs"},validation:{command:"python -m pip list | grep fastapi",error:"FastAPI not installed"}},"python-django":{runtime:"python",framework:"Django",markers:["manage.py","django"],commands:{init:"python manage.py migrate",test:"python manage.py test",build:"python manage.py collectstatic --noinput",start:"python manage.py runserver 0.0.0.0:8000"},errorPatterns:{setup:["ModuleNotFoundError","ProgrammingError.*migrate"],"test-failure":["FAILED","ERROR","Ran.*test"],dependency:["ImportError","missing.*dependency"],runtime:["DatabaseError","ImproperlyConfigured"],timeout:["timeout","Timeout"],unknown:[]},healthCheck:{stage:"start",type:"port",value:8e3},dependencies:["init"]},"node-nestjs":{runtime:"node",framework:"NestJS",markers:["package.json","@nestjs/core"],commands:{init:"npm install",test:"npm run test",build:"npm run build",start:"npm run start"},errorPatterns:{setup:["npm ERR!","ENOENT","not found"],"test-failure":["Tests.*failed","FAIL","fail.*test"],dependency:["Cannot find module","ERR_MODULE_NOT_FOUND"],runtime:["TypeError","Error: ","ReferenceError"],timeout:["timeout","TIMEOUT"],unknown:[]},healthCheck:{stage:"start",type:"port",value:3e3}},"node-express":{runtime:"node",framework:"Express",markers:["package.json","express"],commands:{init:"npm install",test:"npm run test",build:"npm run build",start:"npm start"},errorPatterns:{setup:["npm ERR!","ENOENT"],"test-failure":["failed","FAIL"],dependency:["Cannot find module"],runtime:["Error","TypeError"],timeout:["timeout"],unknown:[]}},"go-fiber":{runtime:"go",framework:"Fiber",markers:["go.mod","fiber"],commands:{init:"go mod download && go mod tidy",test:"go test ./...",build:"go build -o app .",start:"./app"},errorPatterns:{setup:["go: .*not found","cannot find","go mod tidy"],"test-failure":["FAIL","--- FAIL"],dependency:["missing.*module"],runtime:["panic","fatal","Error"],timeout:["timeout","context deadline"],unknown:[]},dependencies:["init"]},"go-gin":{runtime:"go",framework:"Gin",markers:["go.mod","gin-gonic"],commands:{init:"go mod download && go mod tidy",test:"go test ./...",build:"go build -o app .",start:"./app"},errorPatterns:{setup:["go: .*not found"],"test-failure":["FAIL"],dependency:["missing.*module"],runtime:["panic"],timeout:["timeout"],unknown:[]}},"java-springboot":{runtime:"java",framework:"Spring Boot",markers:["pom.xml","build.gradle","spring-boot"],commands:{init:"mvn dependency:go-offline",test:"mvn test",build:"mvn package -DskipTests",start:"mvn spring-boot:run"},errorPatterns:{setup:["\\[ERROR\\]","BUILD FAILURE","missing dependencies"],"test-failure":["\\[ERROR\\] Tests run:","BUILD FAILURE"],dependency:["missing.*dependency"],runtime:["Exception","Error","NullPointerException"],timeout:["timeout","Timeout"],unknown:[]},healthCheck:{stage:"start",type:"port",value:8080}},"php-laravel":{runtime:"php",framework:"Laravel",markers:["composer.json","artisan","app/Models"],commands:{init:"composer install && php artisan migrate:fresh --seed",test:"php artisan test",build:"php artisan config:cache && php artisan route:cache && php artisan view:cache",start:"php artisan serve --host=0.0.0.0 --port=8000"},errorPatterns:{setup:["Composer.*lock","Fatal error","Class.*not found"],"test-failure":["FAILED","Tests.*failed"],dependency:["Class.*not found","require.*failed"],runtime:["Fatal error","Exception","Error"],timeout:["timeout","Timeout"],unknown:[]},healthCheck:{stage:"start",type:"port",value:8e3},dependencies:["init"]},"php-symfony":{runtime:"php",framework:"Symfony",markers:["composer.json","symfony.lock","bin/console"],commands:{init:"composer install && php bin/console doctrine:database:create",test:"php bin/phpunit",build:"php bin/console cache:clear --env=prod",start:"symfony serve --no-tls"},errorPatterns:{setup:["Composer.*error","Fatal error"],"test-failure":["FAILED","failure"],dependency:["Class.*not found"],runtime:["Fatal error","Exception"],timeout:["timeout"],unknown:[]},dependencies:["init"]},"rust-actix":{runtime:"rust",framework:"Actix-web",markers:["Cargo.toml","actix"],commands:{init:"cargo fetch",test:"cargo test",build:"cargo build --release",start:"cargo run --release"},errorPatterns:{setup:["error: .*could not find","failed.*download"],"test-failure":["test result:","FAILED"],dependency:["can.t find.*crate"],runtime:["error\\[E","thread.*panicked"],timeout:["timeout"],unknown:[]},validation:{command:"cargo --version",error:"Rust/Cargo not installed"}},"rust-axum":{runtime:"rust",framework:"Axum",markers:["Cargo.toml","axum"],commands:{init:"cargo fetch",test:"cargo test",build:"cargo build --release",start:"cargo run --release"},errorPatterns:{setup:["error: .*could not find"],"test-failure":["test result:","FAILED"],dependency:["can.t find.*crate"],runtime:["error\\[E"],timeout:["timeout"],unknown:[]}},"rust-rocket":{runtime:"rust",framework:"Rocket",markers:["Cargo.toml","rocket"],commands:{init:"cargo fetch",test:"cargo test",build:"cargo build --release",start:"cargo run --release"},errorPatterns:{setup:["error: .*could not find"],"test-failure":["FAILED"],dependency:["can.t find"],runtime:["error\\[E"],timeout:["timeout"],unknown:[]}},"dotnet-aspnetcore":{runtime:"dotnet",framework:"ASP.NET Core",markers:[".csproj",".sln","Program.cs"],commands:{init:"dotnet restore",test:"dotnet test",build:"dotnet build -c Release",start:"dotnet run"},errorPatterns:{setup:["error CS","CSPROJ.*not found","NuGet.*restore"],"test-failure":["Failed:.*test","FAILED"],dependency:["error NU1101"],runtime:["error CS","Exception"],timeout:["timeout"],unknown:[]},healthCheck:{stage:"start",type:"port",value:5e3}},"elixir-phoenix":{runtime:"elixir",framework:"Phoenix",markers:["mix.exs","phoenix"],commands:{init:"mix setup",test:"mix test",build:"mix compile --all-warnings",start:"mix phx.server"},errorPatterns:{setup:["\\*\\* \\(.*Error\\)","Mix.InstallError"],"test-failure":["\\d+\\sfailed","FAILED"],dependency:["dependencies are not available"],runtime:["\\*\\* \\(","RuntimeError"],timeout:["timeout"],unknown:[]},healthCheck:{stage:"start",type:"port",value:4e3},dependencies:["init"]},"ruby-rails":{runtime:"ruby",framework:"Rails",markers:["Gemfile","config/application.rb","bin/rails"],commands:{init:"bundle install && rails db:prepare",test:"rails test",build:"rails assets:precompile",start:"rails server --binding=0.0.0.0 --port=3000"},errorPatterns:{setup:["Bundler::.*Error","Gem::.*Error"],"test-failure":["failures,","error,","FAILED"],dependency:["Could not find.*gem"],runtime:["Error","Exception","NoMethodError"],timeout:["timeout"],unknown:[]},healthCheck:{stage:"start",type:"port",value:3e3},dependencies:["init"]},"ruby-sinatra":{runtime:"ruby",framework:"Sinatra",markers:["Gemfile","app.rb","sinatra"],commands:{init:"bundle install",test:"rspec",build:`echo "Sinatra apps don't require build"`,start:"ruby app.rb"},errorPatterns:{setup:["Bundler.*Error","Gem.*Error"],"test-failure":["failure","FAILED"],dependency:["Could not find.*gem"],runtime:["Error","NoMethodError"],timeout:["timeout"],unknown:[]}}},ce={init:{python:["pip install -e .","poetry install","pip install -r requirements.txt"],node:["npm install","pnpm install","yarn install"],go:["go mod download && go mod tidy","go get ./..."],java:["mvn dependency:go-offline","gradle dependencies"],php:["composer install"],rust:["cargo fetch"],dotnet:["dotnet restore"],elixir:["mix deps.get"],ruby:["bundle install"],"jvm-generic":["mvn dependency:go-offline","gradle dependencies"],unknown:[]},test:{python:["pytest","python -m unittest","python -m pytest"],node:["npm test","npm run test"],go:["go test ./...","make test"],java:["mvn test","gradle test"],php:["php artisan test","phpunit","pest"],rust:["cargo test"],dotnet:["dotnet test"],elixir:["mix test"],ruby:["rspec","ruby -m minitest"],"jvm-generic":["mvn test","gradle test"],unknown:[]},build:{python:["python -m build","python setup.py build"],node:["npm run build"],go:["go build -o app .","go build ./..."],java:["mvn package -DskipTests","gradle build -x test"],php:['echo "PHP build: typically no build step"'],rust:["cargo build --release"],dotnet:["dotnet build -c Release"],elixir:["mix compile"],ruby:["gem build *.gemspec"],"jvm-generic":["mvn package -DskipTests","gradle build"],unknown:[]},start:{python:["python app.py","python main.py","uvicorn main:app --reload"],node:["npm start","node index.js","node src/index.js"],go:["./app","go run main.go","go run ./..."],java:["mvn spring-boot:run","gradle bootRun","java -jar target/*.jar"],php:["php -S 0.0.0.0:8000","php artisan serve"],rust:["cargo run --release","./target/release/app"],dotnet:["dotnet run"],elixir:["mix phx.server","iex -S mix"],ruby:["rails server","ruby app.rb","bundle exec puma"],"jvm-generic":["java -jar *.jar","gradle run"],unknown:[]}};function z(e,r,t){if(r){let n=r.trim().toLowerCase().replace(/[_.\s]+/g,"-"),c=a(r),s=`${e}-${c==="gofiber"?"fiber":c==="gogin"?"gin":c==="dotnet"?"aspnetcore":c!=="unknown"?c:n==="fiber"?"fiber":n==="aspnetcore"||n==="asp-net-core"?"aspnetcore":n}`,o=ue[s];if(o&&o.commands[t])return o.commands[t]}let a$1=ce[t]?.[e]??[];return a$1.length>0?a$1[0]:void 0}function de(e){let r=d(e).map(t=>t==="python"?"python":t==="node"||t==="bun"?"node":t==="go"?"go":t==="java"?"java":t==="php"?"php":t==="rust"?"rust":t==="dotnet"?"dotnet":t==="elixir"?"elixir":t==="ruby"?"ruby":t==="clojure"||t==="scala"||t==="kotlin"?"jvm-generic":null).filter(t=>t!==null).filter((t,a,n)=>n.indexOf(t)===a);return {primary:r.length>0?r[0]:"unknown",secondary:r.slice(1)}}function q(e){return de(e).primary}function Y(e,r){if(!e)return "unknown";r||(r={setup:["ModuleNotFoundError","npm ERR!","error:","not found"],"test-failure":["FAILED","FAIL","failed"],dependency:["cannot find module","import.*error"],runtime:["Exception","Error:","panic","TypeError"],timeout:["timeout","Timeout","deadline exceeded"],unknown:[]});for(let[t,a]of Object.entries(r))for(let n of a)if(new RegExp(n,"i").test(e))return t;return "unknown"}async function Q(e){let r=e.split(/[&|;]\s*/)[0].trim().split(/\s+/)[0];if(["echo","cd","pwd","test","true","false","exit"].includes(r))return {valid:true};try{let a=process.platform==="win32"?"where":"which";if((await execa(a,[r],{reject:false})).exitCode===0)return {valid:true}}catch{}return {valid:false,reason:`Command '${r}' not found or not executable`}}function X(e,r,t){return r?t&&typeof r[t]=="string"?r[t]:typeof r.default=="string"?r.default:e:e}var le=new Set(["init","test","build","start"]),me=new Set([".git","node_modules",".rapidkit",".venv","dist","build","coverage","htmlcov"]);async function O(e){try{return await v.promises.access(e,v.constants.F_OK),true}catch{return false}}async function pe(e){let r=await v.promises.readFile(e,"utf-8");return JSON.parse(r)}async function fe(e,r){await v.promises.mkdir(m.dirname(e),{recursive:true}),await v.promises.writeFile(e,`${JSON.stringify(r,null,2)}
2
+ `,"utf-8");}function M(e){return e.replace(/\\/g,"/")}async function ge(e){let r=new Set,t=m.resolve(e);async function a(n){let c;try{c=await v.promises.readdir(n,{withFileTypes:true});}catch{return}if(await O(m.join(n,".rapidkit","context.json"))||await O(m.join(n,".rapidkit","project.json"))){r.add(m.resolve(n));return}if(m.resolve(n)!==t&&d(n).length>0){r.add(m.resolve(n));return}for(let i of c){if(!i.isDirectory()||me.has(i.name))continue;let s=m.join(n,i.name);await a(s);}}return await a(m.resolve(e)),[...r].sort((n,c)=>n.localeCompare(c))}async function ye(e,r,t){let a=await execa("git",["diff","--name-only",`${t}...HEAD`],{cwd:e,reject:false});if(a.exitCode!==0)return new Set(r);let n=a.stdout.split(/\r?\n/).map(i=>i.trim()).filter(i=>i.length>0).map(i=>M(i));if(n.length===0)return new Set;let c=new Set;for(let i of r){let s=M(m.relative(e,i));if(!s||s===".")continue;let o=`${s}/`;n.some(p=>p===s||p.startsWith(o))&&c.add(i);}return c}async function he(e,r,t){let a=m.join(e,".rapidkit","workspace-dependency-graph.json");if(!await O(a))return {expanded:t,graphStatus:"missing",expansionDepth:0};let n;try{n=await pe(a);}catch{return {expanded:t,graphStatus:"invalid",expansionDepth:0}}let c=new Set(r.map(g=>m.resolve(g))),i=new Map;if(!n||typeof n!="object"||Array.isArray(n))return {expanded:t,graphStatus:"invalid",expansionDepth:0};let s=Array.isArray(n.projects)?n.projects:[];for(let g of s){if(!g||typeof g!="object"||Array.isArray(g))continue;let h=g,b=typeof h.path=="string"?h.path:"",l=m.resolve(e,b);if(!c.has(l))continue;let y=Array.isArray(h.dependsOn)?h.dependsOn.filter(E=>typeof E=="string"):[];for(let E of y){let C=m.resolve(e,E);c.has(C)&&(i.has(C)||i.set(C,new Set),i.get(C)?.add(l));}}let o=new Set(t),p=[...o],k=0;for(;p.length>0;){let g=p.shift();if(!g)continue;let h=i.get(g);if(h)for(let b of h)o.has(b)||(o.add(b),p.push(b),k+=1);}return {expanded:o,graphStatus:"loaded",expansionDepth:k}}async function ke(e,r){if(typeof r=="boolean")return r;let t=m.join(e,".rapidkit","policies.yml");if(!await O(t))return true;let a="";try{a=await v.promises.readFile(t,"utf-8");}catch{return true}let n=a.match(/^[\t ]*rules\.enforce_workspace_run_gates:\s*(true|false)\s*(?:#.*)?$/m);return n?n[1]==="true":true}async function N(e,r){let t=process.argv[1];if(!t)return {exitCode:1,stdout:"",stderr:"RapidKit entrypoint is unavailable for nested workspace-run execution."};let a=await execa(process.execPath,[t,...e],{cwd:r,reject:false,env:{...process.env,RAPIDKIT_WORKSPACE_RUN_CHILD:"1"}});return {exitCode:Number(a.exitCode??1),stdout:a.stdout,stderr:a.stderr}}function we(e){return e==="node"||e==="go"||e==="java"||e==="python"}function be(){return process.env.VITEST==="true"||process.env.VITEST==="1"||process.env.NODE_ENV==="test"}async function xe(e){let r=process.cwd();try{process.chdir(e);let{handleInitCommand:t}=await import('./index.js');return {exitCode:await t(["init"]),stdout:"",stderr:""}}finally{process.chdir(r);}}async function Re(e$1){let r=s=>{let o=b(s);return o==="node"||o==="bun"?"node":o==="python"?"python":o==="go"?"go":o==="java"?"java":o==="php"?"php":o==="ruby"?"ruby":o==="rust"?"rust":o==="dotnet"?"dotnet":o==="elixir"?"elixir":o==="clojure"||o==="scala"||o==="kotlin"?"jvm-generic":q(e$1)},t=s=>{if(!s)return;let o=a(s);if(new Set(["fastapi","django","flask","nestjs","express","fastify","koa","gofiber","gogin","echo","springboot","laravel","symfony","rails","sinatra","dotnet","actix","axum","rocket","phoenix"]).has(o))return o},a$1=m.join(e$1,".rapidkit","context.json");if(v.existsSync(a$1))try{let s=JSON.parse(v.readFileSync(a$1,"utf-8"));if(typeof s.runtime=="string"){let o={};if(s.commands&&typeof s.commands=="object")for(let[p,k]of Object.entries(s.commands))typeof k=="string"&&(o[p]=k);return {runtime:r(s.runtime),framework:t(typeof s.framework=="string"?s.framework:void 0),commandOverrides:Object.keys(o).length>0?o:void 0,environment:typeof s.environment=="string"?s.environment:void 0}}}catch{}let n=e(e$1),c=r(n.runtime),i=t(n.key);return {runtime:c,framework:i}}async function ve(e,r,t,a,n,c){let i=!n?.[r]&&we(t),s;if(n&&n[r]?s=n[r]:i?s=`rapidkit ${r}`:s=z(t,a,r),!s)return {exitCode:127,command:`<stage not supported for ${t}>`,message:`No stage command found for runtime '${t}' and framework '${a||"unknown"}'`,errorCategory:"runtime"};let o=X(s,n,c);if(!o)return {exitCode:127,command:s,message:"Failed to resolve stage command",errorCategory:"runtime"};if(!i){let l=await Q(o);if(!l.valid)return {exitCode:127,command:o,message:l.reason||"Command not available",errorCategory:"setup"}}let p=0,k="",g="",h;try{let l=i?r==="init"&&be()?await xe(e):await N([r],e):await execa(o,[],{cwd:e,reject:false,shell:true});if(p=Number(l.exitCode??0),k=l.stdout,g=l.stderr,p!==0){let y=`${k}
3
+ ${g}`;h=Y(y);}}catch(l){return {exitCode:1,command:o,message:l instanceof Error?l.message:"Command execution failed",errorCategory:"runtime"}}return {exitCode:p,command:o,errorCategory:h,healthStatus:void 0,message:p!==0?`Stage failed with exit code ${p}`:void 0}}function Z(e){try{return JSON.parse(e)}catch{return null}}async function Ee(e){let r=[],t=await N(["doctor","workspace","--json"],e);if(t.exitCode!==0)r.push({gate:"doctor-workspace",status:"fail",summary:"doctor workspace command failed"});else {let c=Z(t.stdout)?.healthScore,i=Number(c?.errors??0);Number.isFinite(i)&&i>0?r.push({gate:"doctor-workspace",status:"fail",summary:`doctor workspace reports ${i} error(s)`}):r.push({gate:"doctor-workspace",status:"pass",summary:"doctor workspace passed"});}let a=await N(["readiness","--json"],e);if(a.exitCode!==0)r.push({gate:"readiness",status:"fail",summary:"readiness command failed"});else {let n=Z(a.stdout),c=String(n?.overallStatus??"").toLowerCase();c==="fail"?r.push({gate:"readiness",status:"fail",summary:"readiness overall status is fail"}):c==="warn"?r.push({gate:"readiness",status:"warn",summary:"readiness overall status is warn"}):r.push({gate:"readiness",status:"pass",summary:"readiness overall status is pass"});}return r}function Ce(e){return le.has(e)}function Se(e,r){let t=Math.max(1,Math.min(4,r)),a=Number(e??t);return Number.isFinite(a)?Math.max(1,Math.min(16,Math.trunc(a))):t}async function Be(e){if(!Ce(e.stage))throw new Error(`Unsupported workspace run stage: ${e.stage}`);let r=Date.now(),t=m.resolve(e.workspacePath),a=await ge(t),n=e.affected===true,c=e.blastRadius===true,i=e.since?.trim()||"HEAD~1",s=n?await ye(t,a,i):new Set(a),o,p="not-applicable",k=0,g="all";if(n&&c){let u=await he(t,a,s);o=u.expanded,p=u.graphStatus,k=u.expansionDepth,g="affected+blast-radius";}else n?(o=s,g="affected"):(o=s,g="all");let h=e.stage==="init"?false:await ke(t,e.enforceGates),b=h?await Ee(t):[{gate:"doctor-workspace",status:"skipped",summary:"workspace run gates disabled"},{gate:"readiness",status:"skipped",summary:"workspace run gates disabled"}],l=b.find(u=>u.status==="fail"),y=a.filter(u=>o.has(u)),E=e.continueOnError===true,C=e.parallel===true,W=Se(e.maxWorkers,y.length),T=y.length,$=0;e.json||console.log(R.gray(`Workspace run (${e.stage}) started: ${T} target(s), ${C?`parallel x${W}`:"sequential"}`));let S=new Map;for(let u of a)S.set(u,{path:u,relativePath:M(m.relative(t,u)),selected:o.has(u),affected:o.has(u),status:(o.has(u),"skipped"),exitCode:null,durationMs:0,reason:o.has(u)?void 0:"not affected",framework:void 0,runtimeDetected:void 0,executionCommand:void 0});if(l)for(let u of y){let f=S.get(u);f&&(f.status="skipped",f.reason=`blocked by ${l.gate}`);}else {let u=async f=>{let d=S.get(f);if(!d)return;let P=M(m.relative(t,f));e.json||console.log(R.gray(`\u23F3 [${$}/${T}] ${e.stage} ${P}`)),d.selected=true,d.affected=true;let j=Date.now(),{runtime:w,framework:x,commandOverrides:te,environment:re}=await Re(f);d.runtimeDetected=w,d.framework=x;let F=await ve(f,e.stage,w,x,te,re);if(d.executionCommand=F.command,d.errorCategory=F.errorCategory,d.healthStatus=F.healthStatus,d.durationMs=Date.now()-j,d.exitCode=F.exitCode,F.exitCode===0?(d.status="passed",d.reason=void 0):(d.status="failed",d.reason=F.message||"stage command failed",d.errorMessage=F.message),$+=1,!e.json){let ne=T>0?Math.round($/T*100):100,oe=d.status==="passed"?R.green("\u2705"):R.red("\u274C");console.log(R.gray(`${oe} [${$}/${T}] (${ne}%) ${P} ${d.durationMs}ms`));}};if(C&&y.length>1){let f=0,d=false,P=new Array(W).fill(null).map(async()=>{for(;f<y.length;){if(d&&!E)return;let j=f;f+=1;let w=y[j];await u(w),S.get(w)?.status==="failed"&&(d=true);}});if(await Promise.all(P),!E&&d){let j=false;for(let w of y){let x=S.get(w);if(x){if(x.status==="failed"){j=true;continue}j&&x.status==="skipped"&&(x.reason=x.reason||"stopped after failure");}}}}else for(let f of y){await u(f);let d=S.get(f);if(!E&&d?.status==="failed"){let P=y.slice(y.indexOf(f)+1);for(let j of P){let w=S.get(j);w&&(w.status="skipped",w.reason="stopped after failure");}break}}}let A=[];for(let u of a){let f=S.get(u);f&&A.push(f);}let B=A.filter(u=>u.status==="passed").length,L=A.filter(u=>u.status==="failed").length,_=A.filter(u=>u.status==="skipped").length,H=e.strict===true,ee=L>0||H&&b.some(u=>u.status!=="pass")?1:0,V={schemaVersion:"1.0",workspacePath:t,stage:e.stage,generatedAt:new Date().toISOString(),durationMs:Date.now()-r,options:{affected:n,blastRadius:c,since:n?i:null,parallel:C,maxWorkers:W,continueOnError:E,strict:H,enforceGates:h},selection:{mode:g,since:n?i:null,graphStatus:p,expansionDepth:k},gates:{enforced:h,results:b,blocked:!!l,blockingGate:l?.gate},summary:{projectCount:a.length,selectedCount:y.length,passed:B,failed:L,skipped:_,exitCode:ee},projects:A},J=m.join(t,".rapidkit","reports","workspace-run-last.json");return await fe(J,V),e.json||(l&&(console.log(R.red(`\u274C Workspace run blocked by ${l.gate}`)),console.log(R.gray(` ${l.summary}`))),console.log(R.cyan(`Workspace run (${e.stage}) => passed: ${B}, failed: ${L}, skipped: ${_}`)),console.log(R.gray(`Report: ${J}`))),V}export{Be as runWorkspaceStage};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapidkit",
3
- "version": "0.27.3",
3
+ "version": "0.27.5",
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": [
@@ -47,6 +47,9 @@
47
47
  "test:e2e:user-first-install": "bash scripts/e2e-user-first-install.sh",
48
48
  "test": "vitest run",
49
49
  "test:drift": "RAPIDKIT_DRIFT_GUARD=1 vitest run src/__tests__/drift-guard.test.ts",
50
+ "sync:parity-snapshot": "node scripts/sync-import-stack-parity-snapshot.mjs",
51
+ "check:parity-snapshot": "node scripts/sync-import-stack-parity-snapshot.mjs --check",
52
+ "test:parity-contract": "npm run sync:parity-snapshot -- --npm-only && vitest run src/__tests__/contracts/import-stack-parity.snapshot.test.ts",
50
53
  "test:watch": "vitest",
51
54
  "test:coverage": "vitest run --coverage",
52
55
  "test:prepare-embeddings": "npx tsx scripts/generate-mock-embeddings.ts",
@@ -1,33 +0,0 @@
1
- import {a,d as d$1,e,f,c,g}from'./chunk-Z5LKRG57.js';import it from'crypto';import U from'os';import u from'path';import*as d from'fs-extra';import {execa}from'execa';var rt=["version","project","create","add","list","info","upgrade","diff","doctor","license","commands","reconcile","rollback","uninstall","checkpoint","optimize","snapshot","frameworks","modules","merge"],j=new Set(rt);function Y(){return d$1()}function w(t,e){return t==="py"?["-3",...e]:e}function V(t){if(!t)return t;let e=["Installed Poetry version does not support '--no-update'. Falling back to 'poetry lock'."];return t.split(/\r?\n/).filter(o=>!e.some(i=>o.includes(i))).join(`
2
- `)}var y=class extends Error{code;constructor(e,r){super(r),this.code=e;}};function k(t){if(t instanceof y)switch(t.code){case "PYTHON_NOT_FOUND":return `RapidKit (npm) could not find Python (python3/python/py) on your PATH.
3
- Install Python 3.10+ and ensure \`${c()}\` is available, then retry.
4
- Tip: 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.
5
- `+(a()?`Ensure Python is installed with venv support.
6
- `:`Ensure Python venv support is installed (e.g., python3-venv).
7
- `)+`Details: ${t.message}`;case "BRIDGE_PIP_BOOTSTRAP_FAILED":return `RapidKit (npm) could not bootstrap pip inside the bridge virtual environment.
8
- `+(a()?`Ensure pip is available for your Python installation and retry.
9
- `:`Install python3-venv/python3-pip and retry.
10
- `)+`Details: ${t.message}`;case "BRIDGE_PIP_UPGRADE_FAILED":return `RapidKit (npm) could not upgrade pip in the bridge virtual environment.
11
- Check your network/proxy or disable RAPIDKIT_BRIDGE_UPGRADE_PIP.
12
- Details: ${t.message}`;case "BRIDGE_PIP_INSTALL_FAILED":return `RapidKit (npm) could not install rapidkit-core in the bridge virtual environment.
13
- Check your network/proxy, or install manually with: pipx install rapidkit-core.
14
- 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 N(){let t=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE;return t&&t.trim()?t.trim():"rapidkit-core"}function ot(){let t=N(),e=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE_ID,r=e&&e.trim()?`${t}|${e.trim()}`:t;return it.createHash("sha256").update(r).digest("hex").slice(0,12)}function b(){let t=process.env.XDG_CACHE_HOME;return t&&t.trim()?t:u.join(U.homedir(),".cache")}function st(){return u.join(b(),"rapidkit","npm-bridge","venv")}function W(){let t=ot();return u.join(b(),"rapidkit","npm-bridge",`venv-${t}`)}function G(t){return f(t)}function K(t){return g(t)}function at(t){return /[<>=!~]=|@|\.whl$|\.tar\.gz$|\.zip$|git\+|https?:\/\//.test(t)}function ct(t){return u.dirname(u.dirname(t))}function z(){return u.join(b(),"rapidkit","npm-bridge","core-commands.json")}async function X(t){let e=!!process.env.RAPIDKIT_DEBUG,r=n=>{e&&process.stderr.write(`[DEBUG] tryRapidkit(${t}): ${n}
15
- `);};try{r("probing interpreter-specific rapidkit script");let o=((await execa(t,w(t,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"]),{reject:false,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(r(`script path: ${o}`),o)try{if(await d.pathExists(o)){r(`found script at ${o}; invoking --version --json`);let i=await execa(o,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(r(`script exitCode=${i.exitCode}`),i.exitCode===0){let a=(i.stdout??"").toString().trim();try{let s=JSON.parse(a),c=!!s&&typeof s=="object"&&s!==null&&"version"in s;if(r(`script JSON parse ok=${c}`),c)return true}catch{r("script output not valid JSON");}}}}catch(i){r(`interpreter-specific script probe failed: ${String(i)}`);}}catch(n){r(`interpreter-specific script probe error: ${String(n)}`);}try{r('probing importlib.find_spec("rapidkit")');let n=await execa(t,w(t,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"]),{reject:false,stdio:"pipe",timeout:2e3});if(r(`import probe exitCode=${n.exitCode} stdout=${(n.stdout??"").toString().trim()}`),n.exitCode===0&&(n.stdout??"").toString().trim()==="1")return true}catch(n){r(`import probe error: ${String(n)}`);}try{r("probing python -m rapidkit");let n=await execa(t,w(t,["-m","rapidkit","--version","--json"]),{reject:false,stdio:"pipe",timeout:8e3});if(r(`-m probe exitCode=${n.exitCode}`),n.exitCode===0)return true}catch(n){r(`-m probe error: ${String(n)}`);}try{r("probing PATH for rapidkit executables");let n=(process.env.PATH??"").split(u.delimiter).filter(Boolean);for(let o of n){let i=u.join(o,a()?"rapidkit.exe":"rapidkit");try{if(await d.pathExists(i)){r(`found candidate on PATH: ${i}; invoking --version --json`);let a=await execa(i,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(r(`candidate exitCode=${a.exitCode}`),a.exitCode===0){let s=(a.stdout??"").toString().trim();try{let c=JSON.parse(s);if(c&&typeof c=="object"&&c!==null&&"version"in c)return true}catch{r("candidate output not valid JSON, skipping");}}}}catch(a){r(`error probing candidate ${i}: ${String(a)}`);}}return r("no valid rapidkit found on PATH"),false}catch(n){return r(`PATH probe error: ${String(n)}`),false}}async function T(t){let e=(t??"").toString().trim();if(!e)return false;try{let r=JSON.parse(e);return !!r&&typeof r=="object"&&r!==null&&"version"in r}catch{return false}}async function dt(t){let e=u.relative(".",g(".venv")),r=u.relative(".",f(".venv")),n=t;for(let o=0;o<25;o+=1){let i=u.join(n,e);if(await d.pathExists(i)){let c=await execa(i,["--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:n});if(c.exitCode===0&&await T(c.stdout))return {cmd:i,baseArgs:[]}}let a=u.join(n,r);if(await d.pathExists(a)){let c=await execa(a,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:n});if(c.exitCode===0&&await T(c.stdout))return {cmd:a,baseArgs:["-m","rapidkit"]}}let s=u.dirname(n);if(s===n)break;n=s;}return null}async function pt(t){try{let e=u.join(t,".python-version");if(await d.pathExists(e)){let n=(await d.readFile(e,"utf-8")).trim();if(n)return n}}catch{}try{let e=u.join(t,".rapidkit-workspace");if(await d.pathExists(e)){let r=await d.readFile(e,"utf-8"),n=JSON.parse(r);if(n.pythonVersion)return n.pythonVersion}}catch{}return null}async function M(t){if(t&&t.trim())try{let i=await dt(t);if(i){let a=u.dirname(i.cmd).includes(".venv")?u.dirname(u.dirname(u.dirname(i.cmd))):u.dirname(i.cmd),s=await pt(a);return s&&(process.env.PYENV_VERSION=s),i}}catch{}let e=await mt();if(e.kind==="venv"){let i=ct(e.pythonPath),a=K(i);return await d.pathExists(a)?{cmd:a,baseArgs:[]}:{cmd:e.pythonPath,baseArgs:["-m","rapidkit"]}}try{if((await execa(e.cmd,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:4e3})).exitCode===0)return {cmd:e.cmd,baseArgs:["-m","rapidkit"]}}catch{}try{let a=((await execa(e.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 s=await execa(a,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(s.exitCode===0&&await T(s.stdout))return {cmd:a,baseArgs:[]}}catch{}}catch{}let r=W(),n=await R(e.cmd),o=K(r);return await d.pathExists(o)?{cmd:o,baseArgs:[]}:{cmd:n,baseArgs:["-m","rapidkit"]}}async function $(){for(let t of Y())try{return await execa(t,w(t,["--version"]),{reject:false,stdio:"pipe",timeout:2e3}),t}catch{}return null}async function ut(){let t=!!process.env.RAPIDKIT_DEBUG,e$1=n=>{t&&process.stderr.write(`[DEBUG] checkRapidkitCore: ${n}
16
- `);},r=Array.from(new Set([...d$1(),...e(14,10).map(n=>n.command)]));for(let n of r)try{e$1(`Method 1: trying ${n} import`);let o=await execa(n,w(n,["-c","import rapidkit_core; print(1)"]),{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.trim()==="1")return e$1(`\u2713 Found via ${n} import`),true}catch{continue}for(let n of r)try{e$1(`Method 2: trying ${n} -m pip show`);let o=await execa(n,w(n,["-m","pip","show","rapidkit-core"]),{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.includes("Name: rapidkit-core"))return e$1(`\u2713 Found via ${n} -m pip show`),true}catch{continue}for(let n of ["pip","pip3"])try{e$1(`Method 3: trying ${n} show`);let o=await execa(n,["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.includes("Name: rapidkit-core"))return e$1(`\u2713 Found via ${n} show`),true}catch{continue}try{e$1("Method 4: checking pyenv versions");let n=await execa("pyenv",["versions","--bare"],{reject:false,stdio:"pipe",timeout:3e3});if(n.exitCode===0&&n.stdout){let o=n.stdout.split(`
17
- `).filter(i=>i.trim());e$1(`Found pyenv versions: ${o.join(", ")}`);for(let i of o){let a=process.env.PYENV_ROOT||u.join(U.homedir(),".pyenv"),s=u.join(a,"versions",i.trim(),"bin","pip");try{let c=await execa(s,["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(c.exitCode===0&&c.stdout?.includes("Name: rapidkit-core"))return e$1(`\u2713 Found in pyenv ${i}`),true}catch{try{let c=await execa("pyenv",["exec","pip","show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3,env:{...process.env,PYENV_VERSION:i.trim()}});if(c.exitCode===0&&c.stdout?.includes("Name: rapidkit-core"))return e$1(`\u2713 Found in pyenv ${i} via PYENV_VERSION`),true}catch{continue}}}}}catch{e$1("pyenv not available");}for(let n of r)try{e$1(`Method 5: checking ${n} user site`);let o=await execa(n,w(n,["-m","site","--user-site"]),{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout){let i=o.stdout.trim(),a=u.join(i,"rapidkit_core");if(await d.pathExists(a))return e$1("\u2713 Found in user site-packages"),true}}catch{continue}try{e$1("Method 6: checking pipx");let n=await execa("pipx",["list"],{reject:false,stdio:"pipe",timeout:3e3});if(n.exitCode===0&&n.stdout?.includes("rapidkit-core"))return e$1("\u2713 Found via pipx"),true}catch{e$1("pipx not available");}for(let n of r)try{e$1(`Method 6: checking ${n} -m pipx list`);let o=await execa(n,w(n,["-m","pipx","list"]),{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.includes("rapidkit-core"))return e$1(`\u2713 Found via ${n} -m pipx list`),true}catch{continue}try{if(e$1("Method 7: checking poetry"),(await execa("poetry",["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3})).exitCode===0)return e$1("\u2713 Found via poetry"),true}catch{e$1("poetry check failed");}for(let n of r)try{if(e$1(`Method 7: checking ${n} -m poetry show rapidkit-core`),(await execa(n,w(n,["-m","poetry","show","rapidkit-core"]),{reject:false,stdio:"pipe",timeout:3e3})).exitCode===0)return e$1(`\u2713 Found via ${n} -m poetry`),true}catch{continue}try{e$1("Method 8: checking conda");let n=await execa("conda",["list","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(n.exitCode===0&&n.stdout?.includes("rapidkit-core"))return e$1("\u2713 Found via conda"),true}catch{e$1("conda not available");}return e$1("\u2717 Not found in any environment"),false}async function R(t){let e=W(),r=st(),n=N(),o=[e];!at(n)&&!await d.pathExists(e)&&await d.pathExists(r)&&o.push(r);for(let m of o){let h=G(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=e,a={...process.env,PIP_DISABLE_PIP_VERSION_CHECK:"1",PIP_NO_PYTHON_VERSION_WARNING:"1"},s=Math.max(0,Number(process.env.RAPIDKIT_BRIDGE_PIP_RETRY??"2")),c=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")),v=m=>new Promise(h=>setTimeout(h,m)),P=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 A=(g.stdout??"").toString(),I=(g.stderr??"").toString(),C=[A,I].filter(Boolean).join(`
18
- `),tt=C?`${m} ${h.join(" ")}
19
- ${C}`:`${m} ${h.join(" ")}`;throw new Error(tt)},_=async(m,h,f)=>{let g=0;for(;;)try{await P(m,h,f);return}catch(A){if(g>=s)throw A;let I=Math.floor(Math.random()*200),C=c*Math.pow(2,g)+I;g+=1,await v(C);}};try{await d.ensureDir(u.dirname(i));try{await P(t,w(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=G(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 _(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 _(m,["-m","pip","install","-U",N()],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 mt(){if(process.env.RAPIDKIT_BRIDGE_FORCE_VENV==="1"){let r=await $();if(!r)throw new y("PYTHON_NOT_FOUND","No Python interpreter found (python3/python/py).");return {kind:"venv",pythonPath:await R(r)}}for(let r of Y())if(await X(r))return {kind:"system",cmd:r};let t=await $();if(!t)throw new y("PYTHON_NOT_FOUND","No Python interpreter found (python3/python/py).");return {kind:"venv",pythonPath:await R(t)}}async function kt(t,e){try{let r=await M(e?.cwd),n=r.cmd,o=[...r.baseArgs,...t];if(t[0]==="init"){let s=await execa(n,o,{cwd:e?.cwd,env:{...process.env,...e?.env},reject:false,stdio:"pipe"}),c=V((s.stdout??"").toString()),l=V((s.stderr??"").toString());return c&&process.stdout.write(c.endsWith(`
20
- `)?c:`${c}
21
- `),l&&process.stderr.write(l.endsWith(`
22
- `)?l:`${l}
23
- `),typeof s.exitCode=="number"?s.exitCode:1}let a=await execa(n,o,{cwd:e?.cwd,env:{...process.env,...e?.env},reject:false,stdio:"inherit"});return typeof a.exitCode=="number"?a.exitCode:1}catch(r){return process.stderr.write(`${k(r)}
24
- `),1}}var lt=[{pattern:/RapidKitError:\s*Directory '([^']+)' exists and force is not set/,message:t=>`\u274C Directory "${u.basename(t[1])}" already exists.
25
- \u{1F4A1} Choose a different name, or remove the existing directory first:
26
- rm -rf ${t[1]}`},{pattern:/RapidKitError:\s*Project name '([^']+)' is (invalid|not allowed)/i,message:t=>`\u274C Invalid project name: "${t[1]}"
27
- \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]}"
28
- \u{1F4A1} Run "npx rapidkit list" to see available kits.`},{pattern:/RapidKitError:\s*(.+)/,message:t=>`\u274C ${t[1].trim()}`}];async function Rt(t,e){let{spawn:r}=await import('child_process');try{let n=await M(e?.cwd),o=n.cmd,i=[...n.baseArgs,...t];return await new Promise(a=>{let s=r(o,i,{cwd:e?.cwd,env:{...process.env,...e?.env},stdio:["inherit","inherit","pipe"]}),c=[];s.stderr?.on("data",l=>{c.push(l);}),s.on("close",l=>{let v=l??1;if(v!==0&&c.length>0){let P=Buffer.concat(c).toString("utf8");for(let{pattern:_,message:m}of lt){let h=P.match(_);if(h){process.stderr.write(m(h)+`
29
- `),a(v);return}}process.stderr.write(P);}a(v);}),s.on("error",l=>{process.stderr.write(`${k(l)}
30
- `),a(1);});})}catch(n){return process.stderr.write(`${k(n)}
31
- `),1}}async function E(t,e){try{let r=await M(e?.cwd),n=r.cmd,o=[...r.baseArgs,...t],i=await execa(n,o,{cwd:e?.cwd,env:{...process.env,...e?.env},reject:false,stdio:"pipe"});return {exitCode:typeof i.exitCode=="number"?i.exitCode:1,stdout:(i.stdout??"").toString(),stderr:(i.stderr??"").toString()}}catch(r){return {exitCode:1,stdout:"",stderr:`${k(r)}
32
- `}}}function q(t){let e=new Set,r=t.split(`
33
- `),n=false;for(let o of r){let i=o.replace(/\r$/,"");if(!n){/^\s*Commands:\s*$/i.test(i)&&(n=true);let c=i.match(/^\s*rapidkit\s+([a-z0-9_-]+)\b/i);if(c){let l=c[1].trim();l&&!l.startsWith("-")&&e.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 s=a[1].trim();s&&!s.startsWith("-")&&e.add(s);}return e}async function Q(){let t=z();if(!await d.pathExists(t))return null;try{let e=await d.readJson(t);if(e&&e.schema_version===1&&Array.isArray(e.commands))return e}catch{}return null}async function L(t){let e=z();await d.ensureDir(u.dirname(e)),await d.writeJson(e,t,{spaces:2});}async function ft(){let t=await E(["version","--json"],{cwd:process.cwd()});if(t.exitCode===0)try{let r=JSON.parse(t.stdout)?.version;return typeof r=="string"?r:void 0}catch{return}}async function ht(){let t=await E(["commands","--json"],{cwd:process.cwd()});if(t.exitCode!==0)return null;try{let e=JSON.parse(t.stdout);if(e?.schema_version!==1||!Array.isArray(e.commands))return null;let r=e.commands.filter(n=>typeof n=="string");return r.length?r:null}catch{return null}}async function bt(){let e=Date.now(),r=await Q(),n=await ft(),o=!!r?.commands?.length;if(o&&e-r.fetched_at<864e5&&(!n||!r.rapidkit_version||r.rapidkit_version===n))return new Set(r.commands);let i=await ht();if(i?.length){let l=Array.from(new Set(i)).sort();return await L({schema_version:1,fetched_at:e,rapidkit_version:n,commands:l}),new Set(l)}let a=await E(["--help"],{cwd:process.cwd()});if(a.exitCode!==0)return o&&r?.commands?new Set(r.commands):new Set(j);let s=q(a.stdout);if(s.size===0)return new Set(j);let c=Array.from(s).sort();return await L({schema_version:1,fetched_at:e,rapidkit_version:n,commands:c}),s}async function At(){let e=Date.now(),r=await Q();return !r||e-r.fetched_at>=864e5||!r.commands?.length?null:new Set(r.commands)}function Z(){return u.join(b(),"rapidkit","npm-bridge","modules-catalog.json")}async function gt(){let t=Z();if(!await d.pathExists(t))return null;try{let e=await d.readJson(t);if(e&&e.schema_version===1&&Array.isArray(e.modules))return e}catch{}return null}async function J(t){let e=Z();await d.ensureDir(u.dirname(e)),await d.writeJson(e,t,{spaces:2});}function H(t){try{return JSON.parse(t)}catch{return null}}async function It(t={}){let e=typeof t.ttlMs=="number"?t.ttlMs:18e5,r=Date.now(),n=await gt();if(n?.fetched_at&&r-n.fetched_at<e)return n;let o=["modules","list","--json-schema","1"];t.category&&o.push("--category",t.category),t.tag&&o.push("--tag",t.tag),t.detailed&&o.push("--detailed");let i=await E(o,{cwd:t.cwd,env:t.env});if(i.exitCode===0){let s=H(i.stdout);if(s&&s.schema_version===1&&Array.isArray(s.modules)){let c={...s,fetched_at:r};return await J(c),c}}let a=await E(["modules","list","--json"],{cwd:t.cwd,env:t.env});if(a.exitCode===0){let s=H(a.stdout);if(Array.isArray(s)){let c={schema_version:1,generated_at:new Date().toISOString(),filters:{category:t.category??null,tag:t.tag??null,detailed:!!t.detailed},stats:{total:s.length,returned:s.length,invalid:0},modules:s,source:"legacy-json",fetched_at:r};return await J(c),c}}return n||null}var Dt={pickSystemPython:$,ensureBridgeVenv:R,parseCoreCommandsFromHelp:q,tryRapidkit:X,checkRapidkitCoreAvailable:ut};export{j as a,ut as b,mt as c,kt as d,Rt as e,E as f,bt as g,At as h,It as i,Dt as j};