kaven-cli 0.8.0 → 0.9.0
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/index.js +104 -98
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,105 +1,110 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as
|
|
3
|
-
`)){let
|
|
4
|
-
`),
|
|
5
|
-
`);return{found:!0,beginLine:
|
|
6
|
-
${
|
|
7
|
-
${
|
|
8
|
-
${
|
|
9
|
-
`;return e.replace(t,`${t}${i}`)}removeModule(e,t){let n=
|
|
10
|
-
${this.formatZodError(
|
|
11
|
-
`)}};function
|
|
12
|
-
`)){let
|
|
2
|
+
import{a as wo,b as yo,c as vo,d as gt,e as Ze,f as fe,g as J}from"./chunk-JHLQ46NG.js";import{Command as Kr}from"commander";import E from"chalk";import{execSync as xo}from"child_process";import Eo from"path";import wt from"fs-extra";import S from"fs-extra";import G from"path";import Un from"os";var ht=class{constructor(e,t,n){this.projectRoot=e;this.markerService=t;this.manifestParser=n}async checkAll(){let e=[];return e.push(...await this.checkAnchors()),e.push(...await this.checkMarkers()),e.push(...await this.checkDependencies()),e.push(...await this.checkSchemaMerge()),e.push(...await this.checkEnvCompleteness()),e.push(...await this.checkLicense()),e.push(...await this.checkFrameworkVersion()),e.push(...await this.checkPrismaClientSync()),e}async checkAnchors(){let e=[],t=[{file:"apps/api/src/app.ts",anchor:"// [KAVEN_MODULE_IMPORTS]"},{file:"apps/api/src/app.ts",anchor:"// [KAVEN_MODULE_HOOKS]"},{file:"apps/api/src/app.ts",anchor:"// [KAVEN_MODULE_REGISTRATION]"}];for(let{file:n,anchor:a}of t){let r=G.join(this.projectRoot,n);if(!await S.pathExists(r)){e.push({type:"anchor",severity:"warning",message:`File not found: ${n}`,file:n,fixable:!1});continue}(await S.readFile(r,"utf-8")).includes(a)||e.push({type:"anchor",severity:"error",message:`Missing anchor: ${a}`,file:n,fixable:!1})}return e}async checkMarkers(){let e=[],n=(await this.readKavenConfig()).modules.filter(a=>a.installed);for(let a of n){let r=G.join(this.projectRoot,".kaven/modules",a.name,"module.json");if(!await S.pathExists(r)){e.push({type:"marker",severity:"error",message:`Manifest not found for installed module: ${a.name}`,fixable:!1});continue}try{let i=await this.manifestParser.parse(r);for(let s of i.injections){let c=G.join(this.projectRoot,s.file);if(!await S.pathExists(c)){e.push({type:"marker",severity:"error",message:`Injection target not found: ${s.file}`,file:s.file,fixable:!1});continue}let l=await S.readFile(c,"utf-8"),d=s.moduleName||a.name;this.markerService.detectMarkers(l,d).found||e.push({type:"marker",severity:"error",message:`Module ${a.name} not injected in ${s.file}`,file:s.file,fixable:!0})}}catch(i){e.push({type:"marker",severity:"error",message:`Invalid manifest for module ${a.name}: ${i instanceof Error?i.message:String(i)}`,fixable:!1})}}return e}async checkDependencies(){let e=[],n=(await this.readKavenConfig()).modules.filter(i=>i.installed),a=G.join(this.projectRoot,"package.json");if(!await S.pathExists(a))return e.push({type:"dependency",severity:"error",message:"package.json not found",fixable:!1}),e;let r=await S.readJSON(a);for(let i of n){let s=G.join(this.projectRoot,".kaven/modules",i.name,"module.json");if(await S.pathExists(s))try{let c=await this.manifestParser.parse(s);for(let l of c.dependencies.npm){let[d]=l.split("@"),u=r.dependencies?.[d],m=r.devDependencies?.[d];!u&&!m&&e.push({type:"dependency",severity:"warning",message:`Missing npm dependency: ${l}`,fixable:!0})}}catch{}}return e}async checkSchemaMerge(){let e=[],t=G.join(this.projectRoot,"packages/database/prisma/schema.base.prisma");if(!await S.pathExists(t))return e.push({type:"dependency",severity:"warning",message:"Prisma base schema not found: packages/database/prisma/schema.base.prisma",file:"packages/database/prisma/schema.base.prisma",fixable:!1}),e;let n=G.dirname(t);try{let a=await S.readdir(n);for(let r of a){if(!r.endsWith(".prisma"))continue;let i=G.join(n,r);(await S.readFile(i,"utf-8")).includes("<<<<<<<")&&e.push({type:"marker",severity:"error",message:`Merge conflict detected in schema file: ${r}`,file:G.join("packages/database/prisma",r),fixable:!1})}}catch{}return e.length===0&&e.push({type:"dependency",severity:"info",message:"Prisma schema integrity OK",fixable:!1}),e}async checkEnvCompleteness(){let e=[],t=G.join(this.projectRoot,".env.example"),n=G.join(this.projectRoot,".env");if(!await S.pathExists(t))return e.push({type:"dependency",severity:"info",message:".env.example not found \u2014 skipping env completeness check",fixable:!1}),e;if(!await S.pathExists(n))return e.push({type:"dependency",severity:"warning",message:".env file not found. Copy .env.example to .env and fill in values",file:".env",fixable:!1}),e;let a=await S.readFile(t,"utf-8"),r=await S.readFile(n,"utf-8"),i=d=>{let u=new Set;for(let m of d.split(`
|
|
3
|
+
`)){let p=m.trim();if(p.startsWith("#")||!p.includes("="))continue;let f=p.split("=")[0].trim();f&&u.add(f)}return u},s=i(a),c=i(r),l=[];for(let d of s)c.has(d)||l.push(d);return l.length>0?e.push({type:"dependency",severity:"warning",message:`Missing env vars in .env: ${l.join(", ")}`,file:".env",fixable:!0}):e.push({type:"dependency",severity:"info",message:"Env vars completeness OK",fixable:!1}),e}async checkLicense(){let e=[],t=G.join(Un.homedir(),".kaven","license.json");if(!await S.pathExists(t))return e.push({type:"dependency",severity:"warning",message:"No license found at ~/.kaven/license.json. Run 'kaven license status' to set up.",fixable:!1}),e;try{let n=await S.readJson(t);if(n.expiresAt){let a=new Date(n.expiresAt).getTime();if(Date.now()>a)return e.push({type:"dependency",severity:"error",message:`License expired on ${n.expiresAt}. Run 'kaven upgrade' to renew.`,fixable:!1}),e}e.push({type:"dependency",severity:"info",message:`License valid (tier: ${n.tier||"unknown"})`,fixable:!1})}catch{e.push({type:"dependency",severity:"warning",message:"Could not read license file. Try 'kaven license status'.",fixable:!1})}return e}async checkFrameworkVersion(){let e=[],t=G.join(this.projectRoot,"package.json");if(!await S.pathExists(t))return e.push({type:"dependency",severity:"info",message:"package.json not found \u2014 skipping framework version check",fixable:!1}),e;try{let n=await S.readJSON(t),a=n.dependencies?.["@kaven/core"]||n.devDependencies?.["@kaven/core"];if(!a)return e.push({type:"dependency",severity:"info",message:"@kaven/core not found in dependencies \u2014 not a Kaven framework project",fixable:!1}),e;let r="1.0.0",s=a.replace(/[\^~>=<]/,"").split(" ")[0].split(".").map(Number),c=r.split(".").map(Number),l=!0;for(let d=0;d<3&&!((s[d]||0)>(c[d]||0));d++)if((s[d]||0)<(c[d]||0)){l=!1;break}l?e.push({type:"dependency",severity:"info",message:`Framework version OK (${a})`,fixable:!1}):e.push({type:"dependency",severity:"warning",message:`@kaven/core version ${a} may be outdated. Minimum: ^${r}`,fixable:!1})}catch{e.push({type:"dependency",severity:"info",message:"Could not determine framework version",fixable:!1})}return e}async checkPrismaClientSync(){let e=[],t=G.join(this.projectRoot,"node_modules/@prisma/client"),n=G.join(this.projectRoot,"prisma/schema.prisma");if(!await S.pathExists(t))return e.push({type:"dependency",severity:"warning",message:"@prisma/client not found. Run 'npx prisma generate' to generate the client.",fixable:!0}),e;if(!await S.pathExists(n))return e.push({type:"dependency",severity:"info",message:"prisma/schema.prisma not found \u2014 skipping Prisma sync check",fixable:!1}),e;try{let a=await S.stat(n),r=await S.stat(t);a.mtime>r.mtime?e.push({type:"dependency",severity:"warning",message:"Prisma schema was modified after client generation. Run 'npx prisma generate'.",fixable:!0}):e.push({type:"dependency",severity:"info",message:"Prisma client is up to date",fixable:!1})}catch{e.push({type:"dependency",severity:"info",message:"Could not compare Prisma schema and client timestamps",fixable:!1})}return e}async readKavenConfig(){let e=G.join(this.projectRoot,"kaven.json");if(!await S.pathExists(e))return{modules:[]};try{return await S.readJSON(e)}catch{return{modules:[]}}}};function Qe(o){return{moduleName:o,beginMarker:`// [KAVEN_MODULE:${o} BEGIN]`,endMarker:`// [KAVEN_MODULE:${o} END]`}}var ce=class{hasModule(e,t){let n=Qe(t);return e.includes(n.beginMarker)&&e.includes(n.endMarker)}detectMarkers(e,t){let n=Qe(t),a=e.split(`
|
|
4
|
+
`),r,i;for(let s=0;s<a.length;s++)if(a[s].includes(n.beginMarker)&&(r=s),a[s].includes(n.endMarker)){i=s;break}if(r!==void 0&&i!==void 0){let s=a.slice(r+1,i).join(`
|
|
5
|
+
`);return{found:!0,beginLine:r,endLine:i,content:s}}return{found:!1}}injectModule(e,t,n,a){if(this.hasModule(e,n))throw new Error(`Module ${n} already injected`);if(!e.includes(t))throw new Error(`Anchor not found: ${t}`);let r=Qe(n),i=`
|
|
6
|
+
${r.beginMarker}
|
|
7
|
+
${a}
|
|
8
|
+
${r.endMarker}
|
|
9
|
+
`;return e.replace(t,`${t}${i}`)}removeModule(e,t){let n=Qe(t),a=this.escapeRegex(n.beginMarker),r=this.escapeRegex(n.endMarker),i=new RegExp(`\\n?${a}[\\s\\S]*?${r}\\n?`,"g"),s=e.replace(i,"");if(s===e)throw new Error(`Module ${t} not found in file`);return s}escapeRegex(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}};import bo from"fs-extra";import{z as k}from"zod";var Nn=k.object({npm:k.array(k.string()).default([]),peerModules:k.array(k.string()).default([]),kavenVersion:k.string().default(">=0.1.0")}),Lt=k.object({source:k.string(),dest:k.string()}),Kn=k.object({backend:k.array(Lt).default([]),frontend:k.array(Lt).default([]),database:k.array(Lt).default([])}),Vn=k.object({file:k.string(),anchor:k.string(),code:k.string(),moduleName:k.string().optional()}),Bn=k.object({postInstall:k.string().nullable().default(null),preRemove:k.string().nullable().default(null)}),qn=k.object({key:k.string(),required:k.boolean().default(!1),example:k.string().optional()}),ko=k.object({name:k.string().min(1),version:k.string().regex(/^\d+\.\d+\.\d+$/),description:k.string().optional(),author:k.string().default("Kaven"),license:k.string().default("Proprietary"),dependencies:Nn,files:Kn,injections:k.array(Vn),scripts:Bn,env:k.array(qn).default([])});import{ZodError as Jn}from"zod";var Oe=class{async parse(e){if(!await bo.pathExists(e))throw new Error(`Manifest not found: ${e}`);let t=await bo.readFile(e,"utf-8"),n;try{n=JSON.parse(t)}catch{throw new Error(`Failed to parse manifest JSON: ${e}`)}try{return ko.parse(n)}catch(a){throw a instanceof Jn?new Error(`Invalid manifest:
|
|
10
|
+
${this.formatZodError(a)}`):a}}async validate(e){try{return await this.parse(e),{valid:!0,errors:[]}}catch(t){return{valid:!1,errors:[t instanceof Error?t.message:String(t)]}}}formatZodError(e){return e.issues.map(t=>` - ${t.path.map(String).join(".")}: ${t.message}`).join(`
|
|
11
|
+
`)}};function Gn(o){switch(o){case"error":return E.red("[ERROR]");case"warning":return E.yellow("[WARN] ");case"info":return E.cyan("[INFO] ");default:return E.green("[OK] ")}}async function zn(o,e){let t=o.filter(n=>n.fixable);if(t.length===0){console.log(E.gray(" No automatically fixable issues found."));return}for(let n of t){let a=n.message.toLowerCase();if(a.includes("missing npm dependency")||a.includes("pnpm install")){console.log(E.blue(` Fixing: ${n.message}`));try{xo("pnpm install",{cwd:e,stdio:"inherit"}),console.log(E.green(" \u2713 pnpm install completed"))}catch{console.log(E.red(" \u2717 pnpm install failed"))}continue}if(a.includes("prisma")){console.log(E.blue(` Fixing: ${n.message}`));try{xo("npx prisma generate",{cwd:e,stdio:"inherit"}),console.log(E.green(" \u2713 npx prisma generate completed"))}catch{console.log(E.red(" \u2717 npx prisma generate failed"))}continue}if(a.includes("missing env vars")&&n.file===".env"){let r=Eo.join(e,".env"),i=Eo.join(e,".env.example");console.log(E.blue(` Fixing: ${n.message}`));try{let s=await wt.readFile(i,"utf-8"),c=await wt.pathExists(r)?await wt.readFile(r,"utf-8"):"",l=p=>{let f=new Set;for(let y of p.split(`
|
|
12
|
+
`)){let C=y.trim();if(C.startsWith("#")||!C.includes("="))continue;let R=C.split("=")[0].trim();R&&f.add(R)}return f},d=l(s),u=l(c),m=`
|
|
13
13
|
# Added by kaven doctor --fix
|
|
14
|
-
`;for(let
|
|
15
|
-
`);await
|
|
16
|
-
`));let e=new
|
|
14
|
+
`;for(let p of d)u.has(p)||(m+=`${p}=PLACEHOLDER
|
|
15
|
+
`);await wt.appendFile(r,m),console.log(E.green(" \u2713 Placeholder env vars appended to .env"))}catch{console.log(E.red(" \u2717 Could not append env vars"))}continue}console.log(E.yellow(` Manual action required: ${n.message}`))}}async function So(o){o.json||console.log(E.blue(`Running module doctor...
|
|
16
|
+
`));let e=new ce,t=new Oe,n=new ht(process.cwd(),e,t),a=[];try{a=await n.checkAll()}catch(s){o.json?console.log(JSON.stringify({success:!1,error:s instanceof Error?s.message:String(s),results:[]})):console.error(E.red(`[ERROR] Heavy failure during doctor audit: ${s instanceof Error?s.message:String(s)}`)),process.exit(1);return}if(o.json){let s=a.filter(l=>l.severity==="error"),c=a.filter(l=>l.severity==="warning");console.log(JSON.stringify({success:s.length===0,errors:s.length,warnings:c.length,results:a},null,2)),process.exit(s.length>0?1:c.length>0?2:0);return}for(let s of a){let c=Gn(s.severity);console.log(`${c} ${s.message}`),s.file&&console.log(E.gray(` file: ${s.file}`)),s.fixable&&!o.fix&&console.log(E.gray(" (fixable: run with --fix)"))}let r=a.filter(s=>s.severity==="error"),i=a.filter(s=>s.severity==="warning");console.log(),r.length===0&&i.length===0?console.log(E.green("[OK] All checks passed! Your project is healthy.")):(r.length>0&&console.log(E.red(`[ERROR] Found ${r.length} error(s)`)),i.length>0&&console.log(E.yellow(`[WARN] Found ${i.length} warning(s)`)),o.fix||(console.log(E.gray(`
|
|
17
17
|
Tip: Run with --fix to attempt automatic repairs`)),console.log(E.gray("Try: kaven module doctor --fix")))),o.fix&&(console.log(),console.log(E.blue(`Applying auto-fixes...
|
|
18
|
-
`)),await
|
|
19
|
-
Auto-fix completed.`))),
|
|
20
|
-
\u26A0 ${t} script timed out after ${this.timeoutMs/1e3}s, sending SIGTERM...`)),i.kill("SIGTERM"),setTimeout(()=>{i.kill("SIGKILL")},5e3)},this.timeoutMs);i.on("close",l=>{clearTimeout(c),l===0||l===null?
|
|
21
|
-
${e} [y/N] `,
|
|
22
|
-
\u26A0 PostInstall script failed: ${c}`)),console.warn(
|
|
23
|
-
\u26A0 PreRemove script failed: ${d}`))}}for(let c of
|
|
18
|
+
`)),await zn(a,process.cwd()),console.log(E.green(`
|
|
19
|
+
Auto-fix completed.`))),r.length>0&&process.exit(1),i.length>0&&process.exit(2)}import Po from"chalk";import Zn from"ora";import ot from"path";import Fe from"fs-extra";import re from"fs-extra";import ie from"path";import{glob as Hn}from"glob";var et=class{constructor(e,t=".agent/backups"){this.projectRoot=e;this.backupDir=ie.join(e,t),this.backupId=`backup_${Date.now()}`}backupDir;backupId;filesToBackup=[];async backup(e){let t=ie.join(this.backupDir,this.backupId);await re.ensureDir(t);for(let n of e){let a=ie.resolve(this.projectRoot,n);if(!await re.pathExists(a))throw new Error(`File not found for backup: ${n}`);let r=ie.relative(this.projectRoot,a),i=ie.join(t,r);await re.ensureDir(ie.dirname(i)),await re.copy(a,i),this.filesToBackup.push(a)}console.log(`\u{1F4E6} Backup created: ${this.backupId}`)}async rollback(){let e=ie.join(this.backupDir,this.backupId);if(!await re.pathExists(e))throw new Error(`Backup not found: ${this.backupId}`);let t=await Hn(`${e}/**/*`,{nodir:!0});for(let n of t){let a=ie.relative(e,n),r=ie.join(this.projectRoot,a);await re.ensureDir(ie.dirname(r)),await re.copy(n,r,{overwrite:!0})}console.log(`\u267B\uFE0F Rollback complete: ${this.backupId}`)}async commit(){let e=ie.join(this.backupDir,this.backupId);await re.pathExists(e)&&await re.remove(e),console.log("\u2705 Transaction committed")}getBackupId(){return this.backupId}async cleanup(){if(!await re.pathExists(this.backupDir))return;let e=await re.readdir(this.backupDir),t=Date.now(),n=10080*60*1e3;for(let a of e){let r=a.match(/backup_(\d+)/);if(r){let i=parseInt(r[1]);t-i>n&&await re.remove(ie.join(this.backupDir,a))}}}};import Wn from"child_process";import Xn from"readline";import yt from"chalk";var tt=class{timeoutMs;constructor(e=6e4){this.timeoutMs=e}async runScript(e,t,n=!1){if(!n&&!await this.confirm(`Run ${t} script: ${e.command} ${(e.args??[]).join(" ")}?`)){console.log(yt.dim(` Skipping ${t} script.`));return}return new Promise((a,r)=>{let i=Wn.spawn(e.command,e.args??[],{cwd:e.cwd,stdio:["ignore","pipe","pipe"],shell:!0}),s=yt.dim(`[${t}] `);i.stdout?.on("data",l=>{process.stdout.write(s+l.toString())}),i.stderr?.on("data",l=>{process.stderr.write(s+yt.yellow(l.toString()))});let c=setTimeout(()=>{console.warn(yt.yellow(`
|
|
20
|
+
\u26A0 ${t} script timed out after ${this.timeoutMs/1e3}s, sending SIGTERM...`)),i.kill("SIGTERM"),setTimeout(()=>{i.kill("SIGKILL")},5e3)},this.timeoutMs);i.on("close",l=>{clearTimeout(c),l===0||l===null?a():r(new Error(`${t} script exited with code ${l}`))}),i.on("error",l=>{clearTimeout(c),r(l)})})}async runScripts(e,t,n=!1){for(let a of e)await this.runScript(a,t,n)}confirm(e){return new Promise(t=>{let n=Xn.createInterface({input:process.stdin,output:process.stdout});n.question(`
|
|
21
|
+
${e} [y/N] `,a=>{n.close(),t(a.toLowerCase()==="y"||a.toLowerCase()==="yes")})})}};import Le from"fs-extra";import Ft from"path";import Ut from"chalk";var be=class{constructor(e,t){this.projectRoot=e;this.markerService=t}async isModuleInstalled(e){try{let t=await this.findProjectFiles();for(let n of t)try{let a=await Le.readFile(n,"utf-8");if(this.markerService.hasModule(a,e))return!0}catch{}return!1}catch{return!1}}async findProjectFiles(){let{glob:e}=await import("glob"),t=["**/*.ts","**/*.tsx","**/*.js","**/*.jsx"],n=["**/node_modules/**","**/.next/**","**/dist/**","**/build/**"],a=[];for(let r of t){let i=await e(r,{cwd:this.projectRoot,absolute:!0,ignore:n});a.push(...i)}return[...new Set(a)]}async install(e,t){let n=new et(this.projectRoot);try{let a=Array.from(new Set(e.injections.map(i=>i.file)));await n.backup(a);for(let i of e.injections)await this.injectCode(i);await n.commit();let r=await this.readManifest(this.projectRoot);if(r?.scripts?.postInstall?.length){let i=new tt;try{await i.runScripts(r.scripts.postInstall.map(s=>({...s,cwd:this.projectRoot})),"postInstall",!1)}catch(s){let c=s instanceof Error?s.message:String(s);console.warn(Ut.yellow(`
|
|
22
|
+
\u26A0 PostInstall script failed: ${c}`)),console.warn(Ut.dim(" The module is installed. Run the script manually if needed."))}}if(!t?.skipEnv&&r?.env?.length){let{EnvManager:i}=await import("./EnvManager-NMS3NMIE.js"),s=new i,c=r.env.map(l=>({name:l.key,description:l.example??l.key,required:l.required??!1}));await s.injectEnvVars(e.name,c,{projectDir:this.projectRoot,envFile:t?.envFile,skipEnv:t?.skipEnv,skipConfirmation:t?.yes})}}catch(a){let r=a instanceof Error?a.message:String(a);throw console.error(`\u274C Installation failed: ${r}`),console.log("\u{1F504} Rolling back..."),await n.rollback(),a}}async uninstall(e,t){let n=new et(this.projectRoot);try{let a=Array.from(new Set(e.injections.map(c=>c.file)));await n.backup(a);let{EnvManager:r}=await import("./EnvManager-NMS3NMIE.js");new r().removeEnvVars(e.name,{projectDir:this.projectRoot,skipEnv:t?.skipEnv});let s=await this.readManifest(this.projectRoot);if(s?.scripts?.preRemove?.length){let c=new tt;try{await c.runScripts(s.scripts.preRemove.map(l=>({...l,cwd:this.projectRoot})),"preRemove",!1)}catch(l){let d=l instanceof Error?l.message:String(l);console.warn(Ut.yellow(`
|
|
23
|
+
\u26A0 PreRemove script failed: ${d}`))}}for(let c of a)await this.removeCode(c,e.name);await n.commit()}catch(a){let r=a instanceof Error?a.message:String(a);throw console.error(`\u274C Removal failed: ${r}`),console.log("\u{1F504} Rolling back..."),await n.rollback(),a}}async injectCode(e){let t=Ft.join(this.projectRoot,e.file),n=await Le.readFile(t,"utf-8"),a=this.markerService.injectModule(n,e.anchor,e.moduleName||"unnamed",e.code);await Le.writeFile(t,a)}async removeCode(e,t){let n=Ft.join(this.projectRoot,e),a=await Le.readFile(n,"utf-8"),r=this.markerService.removeModule(a,t);await Le.writeFile(n,r)}async readManifest(e){try{let t=await Le.readFile(Ft.join(e,"module.json"),"utf-8");return JSON.parse(t)}catch{return null}}};import vt from"fs-extra";import Co from"path";import Yn from"os";var M=class o{static instance;logPath;buffer=[];constructor(){this.logPath=Co.join(Yn.homedir(),".kaven","telemetry.log")}static getInstance(){return o.instance||(o.instance=new o),o.instance}capture(e,t,n){let a={event:e,timestamp:new Date().toISOString(),metadata:t,duration:n};this.buffer.push(a)}async flush(){if(this.buffer.length!==0)try{let e=Co.dirname(this.logPath);await vt.ensureDir(e);let t=this.buffer.map(n=>JSON.stringify(n)).join(`
|
|
24
24
|
`)+`
|
|
25
|
-
`;await
|
|
26
|
-
`).reverse().slice(0,e).map(n=>JSON.parse(n))}catch{return[]}}};async function
|
|
27
|
-
`),n,
|
|
28
|
-
|
|
25
|
+
`;await vt.appendFile(this.logPath,t,"utf8"),this.buffer=[]}catch(e){console.debug("Erro ao gravar telemetria:",e)}}async getRecentEvents(e=20){if(!await vt.pathExists(this.logPath))return[];try{return(await vt.readFile(this.logPath,"utf8")).trim().split(`
|
|
26
|
+
`).reverse().slice(0,e).map(n=>JSON.parse(n))}catch{return[]}}};async function $o(o,e){let t=M.getInstance(),n=Date.now();t.capture("cli.module.add.start",{manifestPath:o});let a=e||process.cwd(),r=Zn("Preparando instala\xE7\xE3o do m\xF3dulo...").start();try{let i=new ce,s=new Oe,c=new be(a,i),l=ot.isAbsolute(o)?o:ot.join(a,o);if(!await Fe.pathExists(l))throw new Error(`Arquivo de manifest n\xE3o encontrado: ${o}`);r.text="Validando manifest...";let d=await s.parse(l);r.text=`Instalando ${d.name}@${d.version}...`,await c.install(d),r.text="Atualizando configura\xE7\xE3o do projeto...",await Qn(a,d.name,d.version),r.text="Salvando cache do manifest...";let u=ot.join(a,".kaven","modules",d.name);await Fe.ensureDir(u),await Fe.writeJson(ot.join(u,"module.json"),d,{spaces:2}),r.succeed(Po.green(`M\xF3dulo ${d.name} instalado com sucesso!`)),t.capture("cli.module.add.success",{name:d.name},Date.now()-n),await t.flush()}catch(i){t.capture("cli.module.add.error",{error:i.message},Date.now()-n),await t.flush(),r.fail(Po.red(`Falha na instala\xE7\xE3o: ${i instanceof Error?i.message:String(i)}`)),process.exit(1)}}async function Qn(o,e,t){let n=ot.join(o,"kaven.json"),a={modules:{}};await Fe.pathExists(n)&&(a=await Fe.readJson(n)),a.modules||(a.modules={}),a.modules[e]=t,await Fe.writeJson(n,a,{spaces:2})}import Nt from"chalk";import Kt from"ora";import Vt from"path";import Ue from"fs-extra";async function Io(o,e){let t=M.getInstance(),n=Date.now();t.capture("cli.module.remove.start",{moduleName:o});let a=e||process.cwd(),r=Kt(`Removendo m\xF3dulo ${o}...`).start();try{let i=new ce,s=new be(a,i),c=Vt.join(a,"kaven.json");if(!await Ue.pathExists(c))throw new Error("Arquivo kaven.json n\xE3o encontrado. Este \xE9 um projeto Kaven?");let l=await Ue.readJson(c);if(!l.modules||!l.modules[o])throw new Error(`O m\xF3dulo ${o} n\xE3o est\xE1 instalado.`);let d=Vt.join(a,".kaven","modules",o,"module.json");if(!await Ue.pathExists(d))throw new Error(`Cache do manifest para ${o} n\xE3o encontrado em ${d}. A remo\xE7\xE3o precisa do manifest original.`);let u=await Ue.readJson(d);r.text=`Removendo inje\xE7\xF5es de ${o}...`,await s.uninstall(u),r.text="Atualizando configura\xE7\xE3o do projeto...",delete l.modules[o],await Ue.writeJson(c,l,{spaces:2}),await Ue.remove(Vt.dirname(d)),Kt().succeed(Nt.green(`M\xF3dulo ${o} removido com sucesso!`)),t.capture("cli.module.remove.success",{moduleName:o},Date.now()-n),await t.flush()}catch(i){t.capture("cli.module.remove.error",{error:i.message},Date.now()-n),await t.flush(),Kt().fail(Nt.red(`Falha ao remover m\xF3dulo ${o}:`)),r.fail(Nt.red(`${i instanceof Error?i.message:String(i)}`)),process.exit(1)}}import D from"fs-extra";import N from"path";import la from"os";import*as To from"tar";import*as Z from"@clack/prompts";import V from"picocolors";import se from"fs-extra";import Bt from"path";import ea from"os";function Ao(o){try{let e=o.split(".");if(e.length!==3)return null;let t=e[1].replace(/-/g,"+").replace(/_/g,"/"),n=t+"=".repeat((4-t.length%4)%4),a=Buffer.from(n,"base64").toString("utf8");return JSON.parse(a)}catch{return null}}function ta(o){let e=Date.now(),t=new Date(o).getTime(),n=Math.max(0,Math.floor((t-e)/1e3));if(n===0)return"expired";let a=Math.floor(n/3600),r=Math.floor(n%3600/60);return a>0?`expires in ${a}h ${r}m`:`expires in ${r}m`}var A=class{configPath;constructor(){this.configPath=Bt.join(ea.homedir(),".kaven","auth.json")}async saveTokens(e){let t=Bt.dirname(this.configPath);await se.ensureDir(t),await se.writeJson(this.configPath,e,{spaces:2}),process.platform!=="win32"&&await se.chmod(this.configPath,384)}async storeToken(e){let t=Bt.dirname(this.configPath);await se.ensureDir(t),await se.writeJson(this.configPath,{token:e},{spaces:2}),process.platform!=="win32"&&await se.chmod(this.configPath,384)}async getAuth(){if(!await se.pathExists(this.configPath))return null;try{let e=await se.readJson(this.configPath);return e.access_token?e:null}catch{return null}}async getToken(){if(!await se.pathExists(this.configPath))return null;try{let e=await se.readJson(this.configPath);return e.access_token?e.access_token:e.token||null}catch{return null}}async getValidToken(){let e=await this.getAuth();if(!e)throw new Error("Not authenticated. Run 'kaven auth login' to authenticate.");let t=new Date(e.expires_at).getTime(),n=Date.now(),a=300*1e3,r=t-n<a,i=n>=t;if(!r)return e.access_token;try{let{MarketplaceClient:s}=await import("./MarketplaceClient-YCFH2VU4.js"),l=await new s(this).refreshToken(e.refresh_token),d={access_token:l.access_token,refresh_token:l.refresh_token,expires_at:l.expires_at,user:e.user};return await this.saveTokens(d),l.access_token}catch{if(!i)return console.warn("[kaven] Warning: Failed to refresh token. Using existing token."),e.access_token;throw new Error("Session expired. Run 'kaven auth login' to re-authenticate.")}}async isAuthenticated(){try{return!!await this.getToken()}catch{return!1}}async logout(){await se.pathExists(this.configPath)&&await se.remove(this.configPath)}async clearToken(){return this.logout()}async getUserInfo(){let e=await this.getAuth();if(!e)return null;let t=Ao(e.access_token);return t?{id:t.sub,email:t.email,name:t.githubId}:{id:e.user.githubId,email:e.user.email,name:void 0}}async getDecodedToken(){let e=await this.getAuth();return e?Ao(e.access_token):null}async getWhoamiInfo(){let e=await this.getAuth();return e?{email:e.user.email,githubId:e.user.githubId,tier:e.user.tier.charAt(0).toUpperCase()+e.user.tier.slice(1),sessionExpiry:ta(e.expires_at)}:null}};import{spawn as oa}from"child_process";import*as nt from"fs-extra";var kt=class{async performMerge(e,t,n){if(!await nt.pathExists(t))throw new Error("Baseline cache file missing: "+t+". Cannot perform safe merge.");return await nt.pathExists(e)?new Promise((a,r)=>{let i=oa("git",["merge-file","-L","Your Modifications (OURS)","-L","Original Version (BASE)","-L","Kaven Update (THEIRS)",e,t,n]),s="";i.stdout.on("data",c=>{s+=c.toString()}),i.stderr.on("data",c=>{s+=c.toString()}),i.on("close",c=>{c===0?a({success:!0,conflicts:!1,output:s}):c!==null&&c>0?a({success:!0,conflicts:!0,output:s}):r(new Error("Git merge-file failed critically: "+s))})}):(await nt.copy(n,e),{success:!0,conflicts:!1,output:"New file copied"})}};import bt from"crypto";import na from"fs-extra";async function aa(o){let e=await na.readFile(o);return bt.createHash("sha256").update(e).digest("hex")}var ra=/^[0-9a-fA-F]+$/;function ia(o){return ra.test(o)&&o.length===128?Buffer.from(o,"hex"):Buffer.from(o,"base64")}function sa(o,e,t){try{let n=bt.createPublicKey({key:Buffer.from(t,"base64"),type:"spki",format:"der"}),a=ia(e);return bt.verify(null,Buffer.from(o),n,a)?!0:bt.verify(null,Buffer.from(o+`
|
|
27
|
+
`),n,a)}catch{return!1}}async function xt(o){let e=await aa(o.filePath);if(e!==o.expectedChecksum)throw new Ze(`Checksum mismatch: expected ${o.expectedChecksum.substring(0,16)}..., got ${e.substring(0,16)}...`);if(!sa(o.expectedChecksum,o.signature,o.publicKeyBase64))throw new Ze("Ed25519 signature verification failed. The package may have been tampered with.")}import Ne from"fs-extra";import qt from"path";var Jt=".kaven/cache/modules";function ca(o,e){let t=o.split(".").map(Number),n=e.split(".").map(Number);for(let a=0;a<3;a++)if((t[a]??0)!==(n[a]??0))return(t[a]??0)-(n[a]??0);return 0}async function Et(o,e,t,n){let a=qt.join(n,Jt,`${o}-${e}`);await Ne.ensureDir(a),await Ne.copy(t,a)}async function St(o,e){let t=qt.join(e,Jt);if(!await Ne.pathExists(t))return null;let a=(await Ne.readdir(t)).filter(i=>{let s=i.lastIndexOf("-");return s>0&&i.slice(0,s)===o});if(a.length===0)return null;a.sort((i,s)=>{let c=i.slice(i.lastIndexOf("-")+1),l=s.slice(s.lastIndexOf("-")+1);return ca(c,l)});let r=a[0];return r.slice(r.lastIndexOf("-")+1)}function Gt(o,e,t){return qt.join(t,Jt,`${o}-${e}`)}async function Mo(o,e,t){let n=Gt(o,e,t);await Ne.pathExists(n)&&await Ne.remove(n)}var da={x:To.x},B={intro:Z.intro,outro:Z.outro,spinner:Z.spinner,confirm:Z.confirm,select:Z.select,isCancel:Z.isCancel,log:Z.log};function jo(o){return o.filter(e=>{let t=N.normalize(e);return!t.startsWith("..")&&!N.isAbsolute(t)})}async function ua(){let o=N.join(la.tmpdir(),`kaven-update-${Date.now()}`);return await D.ensureDir(o),o}async function pa(o,e){let t=N.join(o,".kaven","conflicts.json");if(!await D.pathExists(t))return null;try{let n=await D.readJson(t);if(n.module===e)return n}catch{}return null}async function at(o,e,t={}){let n=M.getInstance(),a=Date.now(),r=e??process.cwd();if(B.intro(V.bold(V.cyan("kaven module update"))),!o&&(o=await fa(r),!o)){B.outro(V.yellow("Nenhum m\xF3dulo selecionado."));return}n.capture("cli.module.update.start",{slug:o});let i;try{let s=await pa(r,o);if(s){let b=await B.confirm({message:V.yellow(`Conflitos pendentes encontrados do update ${s.fromVersion}\u2192${s.toVersion}. Deseja tentar novamente?`)});if(B.isCancel(b)||!b){B.outro(V.yellow("Update cancelado. Resolva os conflitos manualmente e rode novamente."));return}await D.remove(N.join(r,".kaven","conflicts.json"))}let c=await St(o,r);c||(B.outro(V.red(`M\xF3dulo '${o}' n\xE3o est\xE1 instalado. Use 'kaven marketplace install ${o}' primeiro.`)),process.exit(1));let l=B.spinner();l.start(`Verificando vers\xE3o mais recente de '${o}'...`);let d=new A,u=new J(d);try{await d.getValidToken()}catch{l.stop("Autentica\xE7\xE3o necess\xE1ria."),B.outro(V.red("Execute: kaven auth login")),process.exit(1)}let m=await u.getModule(o),p=m.latestVersion??m.releases?.[0]?.version;if(p||(l.stop(),B.outro(V.red(`Nenhuma vers\xE3o publicada encontrada para '${o}'.`)),process.exit(1)),l.stop(`Vers\xE3o instalada: ${V.bold(c)} \u2014 \xDAltima vers\xE3o: ${V.bold(p)}`),c===p){B.outro(V.green(`\u2713 '${o}' j\xE1 est\xE1 na vers\xE3o mais recente (${p}).`)),n.capture("cli.module.update.already_latest",{slug:o,version:p},Date.now()-a),await n.flush();return}l.start(`Baixando '${o}@${p}'...`);let f=await u.createDownloadToken(o,p);i=await ua();let y=N.join(i,"module.tar.gz"),C=N.join(i,"extracted");await D.ensureDir(C);let R=await u.resolveUrl(f.downloadUrl),K=await fetch(R);if(!K.ok||!K.body)throw new Error(`Download falhou: ${K.status} ${K.statusText}`);let g=D.createWriteStream(y),$=K.body.getReader();if(await new Promise((b,I)=>{(async()=>{try{let ae=!0;for(;ae;){let{done:Ie,value:_t}=await $.read();Ie?(g.end(),ae=!1):g.write(_t)||await new Promise(Ot=>g.once("drain",Ot))}g.once("finish",b),g.once("error",I)}catch(ae){I(ae)}})()}),l.stop(`Download conclu\xEDdo: ${o}@${p}`),!t.skipVerify){l.start(`Verificando assinatura de ${o}@${p}...`);let b=await u.getReleaseInfo(o,p);b.checksum&&b.signature&&b.publicKey?(await xt({filePath:y,expectedChecksum:b.checksum,signature:b.signature,publicKeyBase64:b.publicKey}),l.stop(`Assinatura verificada: ${o}@${p}`)):l.stop(`Sem dados de assinatura para ${o}@${p} \u2014 verifica\xE7\xE3o ignorada`)}l.start("Extraindo arquivos..."),await da.x({file:y,cwd:C}),l.stop("Extra\xE7\xE3o completa.");let me=N.join(C,"module.json");if(!await D.pathExists(me))throw new Error(`module.json n\xE3o encontrado no pacote de '${o}@${p}'`);let Ye=await D.readJson(me),Pe=jo(Ye.mergeable??[]),Dt=jo(Ye.copyOnly??[]);l.start(`Cacheando baseline de ${o}@${p}...`),await Et(o,p,C,r),l.stop("Baseline cacheado.");let ho=Gt(o,c,r),ft=new kt,$e=[];for(let b of Pe){let I=N.join(r,b),ne=N.join(ho,b),ae=N.join(C,b);if(!await D.pathExists(ae))continue;l.start(`Mergeando ${b}...`),(await ft.performMerge(I,ne,ae)).conflicts?($e.push(b),l.stop(V.yellow(` Conflito em ${b}`))):l.stop(V.green(` \u2713 ${b}`))}for(let b of Dt){let I=N.join(C,b),ne=N.join(r,b);await D.pathExists(I)&&(l.start(`Copiando ${b}...`),await D.ensureDir(N.dirname(ne)),await D.copy(I,ne,{overwrite:!0}),l.stop(V.green(` \u2713 ${b} (sobrescrito)`)))}if($e.length>0){let b={module:o,fromVersion:c,toVersion:p,timestamp:new Date().toISOString(),conflicts:$e};await D.ensureDir(N.join(r,".kaven")),await D.writeJson(N.join(r,".kaven","conflicts.json"),b,{spaces:2}),B.outro(V.red(`Update parcial \u2014 ${$e.length} conflito(s) detectado(s):
|
|
28
|
+
`+$e.map(I=>` \u2022 ${I}`).join(`
|
|
29
29
|
`)+`
|
|
30
30
|
|
|
31
|
-
Resolva os conflitos (marcadores git <<<<<<< / ======= / >>>>>>>), depois rode 'kaven module update ${o}' novamente.`)),n.capture("cli.module.update.conflicts",{slug:o,fromVersion:c,toVersion:
|
|
32
|
-
`),i=-1,s=-1;for(let c=0;c<
|
|
31
|
+
Resolva os conflitos (marcadores git <<<<<<< / ======= / >>>>>>>), depois rode 'kaven module update ${o}' novamente.`)),n.capture("cli.module.update.conflicts",{slug:o,fromVersion:c,toVersion:p,conflictCount:$e.length},Date.now()-a),await n.flush();return}await ma(r,o,p),await Mo(o,c,r),B.outro(V.green(`\u2713 '${o}' atualizado de ${c} \u2192 ${p}`)),n.capture("cli.module.update.success",{slug:o,fromVersion:c,toVersion:p},Date.now()-a),await n.flush()}catch(s){let c=fe(s);B.outro(V.red(`Falha ao atualizar '${o}': ${c.message}`)),n.capture("cli.module.update.error",{slug:o,error:c.message},Date.now()-a),await n.flush(),process.exit(1)}finally{i&&await D.remove(i).catch(()=>{})}}async function ma(o,e,t){let n=N.join(o,"kaven.json"),a={};await D.pathExists(n)&&(a=await D.readJson(n)),(!a.modules||typeof a.modules!="object"||Array.isArray(a.modules))&&(a.modules={}),a.modules[e]=t,await D.writeJson(n,a,{spaces:2})}async function fa(o){let e=N.join(o,".kaven","cache","modules");if(!await D.pathExists(e)){B.log.warn("Nenhum m\xF3dulo instalado encontrado.");return}let t=await D.readdir(e);if(t.length===0){B.log.warn("Nenhum m\xF3dulo instalado encontrado.");return}let n=t.map(r=>{let i=r.lastIndexOf("-"),s=r.slice(0,i),c=r.slice(i+1);return{value:s,label:`${s} (${c})`}}),a=await B.select({message:"Selecione o m\xF3dulo para atualizar:",options:n});if(!B.isCancel(a))return a}import _ from"chalk";import Ke from"ora";import Ct from"path";import O from"fs-extra";import it from"crypto";import Ro from"os";import{z as xe}from"zod";var ga=xe.object({name:xe.string().min(1),slug:xe.string().min(1).regex(/^[a-z0-9-]+$/),version:xe.string().regex(/^\d+\.\d+\.\d+$/),description:xe.string().min(1),author:xe.string().optional(),license:xe.string().optional(),tier:xe.enum(["free","starter","complete","pro"])}),rt=Ct.join(Ro.homedir(),".kaven","signing-key.json");async function ha(){if(await O.pathExists(rt))try{let a=await O.readJson(rt),r=it.createPrivateKey({key:Buffer.from(a.privateKey,"base64"),type:"pkcs8",format:"der"}),i=it.createPublicKey(r);return{privateKey:r,publicKey:i}}catch{}let{privateKey:o,publicKey:e}=it.generateKeyPairSync("ed25519"),t=o.export({type:"pkcs8",format:"der"}),n=e.export({type:"spki",format:"der"});return await O.ensureDir(Ct.dirname(rt)),await O.writeJson(rt,{privateKey:t.toString("base64"),publicKey:n.toString("base64")},{spaces:2}),process.platform!=="win32"&&await O.chmod(rt,384),{privateKey:o,publicKey:e}}async function wa(o){let e=await O.readFile(o);return it.createHash("sha256").update(e).digest("hex")}async function ya(o,e){await(await import("tar")).create({gzip:!0,file:e,cwd:o,filter:n=>{let a=n.replace(/\\/g,"/"),r=["node_modules",".git","dist",".env"];for(let i of r)if(a.startsWith(i+"/")||a===i||a.endsWith(".log"))return!1;return!0}},["."])}async function Do(o){let e=process.cwd(),t=Ct.join(e,"module.json");await O.pathExists(t)||(console.error(_.red("Error: module.json not found in current directory.")),console.error(_.gray("Try: run this command from inside a module directory")),process.exit(1));let n;try{let g=await O.readJson(t),$=ga.safeParse(g);if(!$.success){console.error(_.red("Error: Invalid module.json:"));for(let me of $.error.issues)console.error(_.red(` - ${me.path.join(".")}: ${me.message}`));process.exit(1)}n=$.data}catch(g){console.error(_.red(`Error: Failed to parse module.json: ${g instanceof Error?g.message:String(g)}`)),process.exit(1)}console.log(),console.log(_.bold(`Publishing module: ${n.name} v${n.version}`)),console.log(_.gray(`Slug: ${n.slug} | Tier: ${n.tier}`)),console.log();let a=Ct.join(Ro.tmpdir(),`kaven-${n.slug}-${n.version}.tar.gz`),r=Ke("Creating module package...").start();try{await ya(e,a);let g=await O.stat(a);r.succeed(`Package created (${(g.size/1024).toFixed(1)} KB)`)}catch(g){r.fail("Failed to create package"),console.error(_.red(g instanceof Error?g.message:String(g))),await O.remove(a).catch(()=>{}),process.exit(1)}let i=Ke("Computing SHA-256 checksum...").start(),s;try{s=await wa(a),i.succeed(`Checksum: ${s.substring(0,16)}...`)}catch{i.fail("Failed to compute checksum"),await O.remove(a).catch(()=>{}),process.exit(1);return}let c=Ke("Signing package...").start(),l,d;try{let{privateKey:g,publicKey:$}=await ha();l=it.sign(null,Buffer.from(s),g).toString("base64"),d=$.export({type:"spki",format:"der"}).toString("base64"),c.succeed(`Package signed (${l.substring(0,16)}...)`)}catch{c.fail("Failed to sign package"),await O.remove(a).catch(()=>{}),process.exit(1);return}if(o.dryRun){console.log(),console.log(_.yellow("Dry-run mode: skipping upload and release creation.")),console.log(_.green("\u2705 Package validated successfully.")),await O.remove(a).catch(()=>{});return}let u=new A;try{await u.getValidToken()}catch{console.error(_.red("Error: Not authenticated. Run 'kaven auth login' first.")),await O.remove(a).catch(()=>{}),process.exit(1);return}let m=new J(u),p=await O.stat(a),f=Ke("Getting upload URL...").start(),y,C;try{let g=await m.getUploadUrl(n.slug,n.version,p.size);y=g.uploadUrl,C=g.s3Key,f.succeed("Upload URL received")}catch(g){f.fail("Failed to get upload URL"),console.error(_.red(g instanceof Error?g.message:String(g))),await O.remove(a).catch(()=>{}),process.exit(1);return}let R=Ke(`Uploading package (${(p.size/1024).toFixed(1)} KB)...`).start();try{let g=await O.readFile(a),$=await fetch(y,{method:"PUT",headers:{"Content-Type":"application/gzip","Content-Length":String(p.size)},body:g});if(!$.ok)throw new Error(`Upload failed: ${$.status} ${$.statusText}`);R.succeed("Package uploaded successfully")}catch(g){R.fail("Upload failed"),console.error(_.red(g instanceof Error?g.message:String(g))),await O.remove(a).catch(()=>{}),process.exit(1);return}let K=Ke("Creating release record...").start();try{let g=await m.createRelease({moduleSlug:n.slug,version:n.version,s3Key:C,checksum:s,signature:l,publicKey:d,changelog:o.changelog});K.succeed(`Release created: ${n.slug}@${g.version} (ID: ${g.id})`)}catch(g){K.fail("Failed to create release"),console.error(_.red(g instanceof Error?g.message:String(g))),await O.remove(a).catch(()=>{}),process.exit(1);return}await O.remove(a).catch(()=>{}),console.log(),console.log(_.green(`\u2705 Published ${n.name} v${n.version} to the Kaven Marketplace!`)),console.log(_.gray(`View your module at: https://marketplace.kaven.site/modules/${n.slug}`)),console.log(),console.log(_.bold("Next steps:")),console.log(_.gray(" 1. Share your module with the community")),console.log(_.gray(" 2. Monitor installation metrics")),console.log(_.gray(" 3. Update module with 'kaven module publish' when ready"))}import v from"chalk";import _o from"ora";import ba from"path";import*as Oo from"@inquirer/prompts";import zt from"fs-extra";import va from"path";var Ae=[{id:"auth",label:"Auth & Identity",description:"Gest\xE3o de usu\xE1rios, permiss\xF5es e sess\xF5es",models:["User","Role","Capability","AuthSession","AuditLog"],enums:["UserRole"],dependsOn:[]},{id:"billing",label:"Billing",description:"Faturamento, assinaturas e pagamentos",models:["Invoice","Order","Subscription","Plan","Payment","Product"],enums:[],dependsOn:["auth"]},{id:"projects",label:"Projects",description:"Gest\xE3o de projetos e tasks",models:["Project","Task"],enums:["ProjectStatus","TaskStatus","TaskPriority"],dependsOn:["auth"]},{id:"notifications",label:"Notifications",description:"Notifica\xE7\xF5es e prefer\xEAncias de usu\xE1rio",models:["Notification","UserPreference"],enums:[],dependsOn:["auth"]},{id:"marketing-tracking",label:"Marketing Tracking",description:"Observabilidade de an\xFAncios, GTM, GA4 e Meta CAPI",models:["TrackingEvent"],enums:["TrackingSource"],dependsOn:["auth"]}],st=o=>`// [KAVEN_MODULE:${o.toUpperCase()} BEGIN]`,ct=o=>`// [KAVEN_MODULE:${o.toUpperCase()} END]`,ka=/^(\s*)\/\/\s*(.*)$/,Ve=class{schemaPath;constructor(e){this.schemaPath=va.join(e,"packages","database","prisma","schema.extended.prisma")}async exists(){return zt.pathExists(this.schemaPath)}get path(){return this.schemaPath}async readSchema(){return zt.readFile(this.schemaPath,"utf-8")}async writeSchema(e){await zt.writeFile(this.schemaPath,e,"utf-8")}validateMarkers(e,t){let n=st(t),a=ct(t),r=e.includes(n),i=e.includes(a);if(r&&!i)throw new Error(`Marcador \xF3rf\xE3o detectado: Faltando END para o m\xF3dulo "${t}".`);if(!r&&i)throw new Error(`Marcador \xF3rf\xE3o detectado: Faltando BEGIN para o m\xF3dulo "${t}".`);if(!r&&!i)throw new Error(`O m\xF3dulo "${t}" n\xE3o possui uma se\xE7\xE3o marcada no schema.`);if(e.indexOf(n)>e.indexOf(a))throw new Error(`Marcadores invertidos para o m\xF3dulo "${t}".`)}async getModuleStatus(e){let t=await this.readSchema(),n=st(e.id),a=ct(e.id),r=t.includes(n)&&t.includes(a),i=!1;if(r){let s=this.extractBlock(t,e.id);i=s!==null&&this.isBlockActive(s)}else i=e.models.some(s=>this.isModelActive(t,s));return{id:e.id,label:e.label,description:e.description,models:e.models,dependsOn:e.dependsOn,active:i,hasMarkers:r}}async activateModule(e){let t=await this.readSchema();this.validateMarkers(t,e.id);let n=this.uncommentBlock(t,e.id);await this.writeSchema(n)}async deactivateModule(e){let t=await this.readSchema();this.validateMarkers(t,e.id);let n=this.commentBlock(t,e.id);await this.writeSchema(n)}extractBlock(e,t){let n=st(t),a=ct(t),r=e.split(`
|
|
32
|
+
`),i=-1,s=-1;for(let c=0;c<r.length;c++)if(r[c].includes(n)&&(i=c),r[c].includes(a)&&i!==-1){s=c;break}return i===-1||s===-1?null:r.slice(i+1,s).join(`
|
|
33
33
|
`)}isBlockActive(e){return e.split(`
|
|
34
34
|
`).some(t=>{let n=t.trim();return n.length>0&&!n.startsWith("//")&&!n.startsWith("/*")&&!n.startsWith("*")})}isModelActive(e,t){let n=e.split(`
|
|
35
|
-
`);for(let
|
|
36
|
-
`),i=!1,s=[];for(let c of
|
|
37
|
-
`)}uncommentBlock(e,t){let n=
|
|
38
|
-
`),i=!1,s=[];for(let c of
|
|
39
|
-
`)}};var
|
|
40
|
-
Error: Schema not found at: ${t}`)),console.error(v.gray("Make sure you are in the root of a valid Kaven project.")),process.exit(1)}}async function
|
|
41
|
-
Unknown module: "${o}".`)),console.error(v.gray(`Available modules: ${
|
|
42
|
-
Inactive dependencies for "${o}": ${m.map(
|
|
43
|
-
${m.map(
|
|
35
|
+
`);for(let a of n)if(a.trim().startsWith(`model ${t}`)&&!a.trimStart().startsWith("//"))return!0;return!1}commentBlock(e,t){let n=st(t),a=ct(t),r=e.split(`
|
|
36
|
+
`),i=!1,s=[];for(let c of r){if(c.includes(n)){i=!0,s.push(c);continue}if(c.includes(a)){i=!1,s.push(c);continue}if(i){let l=c.trim();l.length===0||l.startsWith("//")?s.push(c):s.push(`// ${c}`)}else s.push(c)}return s.join(`
|
|
37
|
+
`)}uncommentBlock(e,t){let n=st(t),a=ct(t),r=e.split(`
|
|
38
|
+
`),i=!1,s=[];for(let c of r){if(c.includes(n)){i=!0,s.push(c);continue}if(c.includes(a)){i=!1,s.push(c);continue}if(i){let l=c.match(ka);l?s.push(l[1]+l[2]):s.push(c)}else s.push(c)}return s.join(`
|
|
39
|
+
`)}};var xa={confirm:Oo.confirm};function Ht(o){return Ae.find(e=>e.id===o.toLowerCase())}function Lo(o,e){if(!o){let t=ba.join(e,"packages","database","prisma","schema.extended.prisma");console.error(v.red(`
|
|
40
|
+
Error: Schema not found at: ${t}`)),console.error(v.gray("Make sure you are in the root of a valid Kaven project.")),process.exit(1)}}async function Wt(o,e,t={}){let n=M.getInstance(),a=Date.now();n.capture("cli.module.activate.start",{moduleName:o});let r=e??process.cwd(),i=new Ve(r),s=_o(`Activating module ${o}...`).start();try{let c=await i.exists();s.stop(),Lo(c,r);let l=Ht(o);if(l||(console.error(v.red(`
|
|
41
|
+
Unknown module: "${o}".`)),console.error(v.gray(`Available modules: ${Ae.map(u=>u.id).join(", ")}`)),process.exit(1)),l.dependsOn.length>0){s.start("Checking dependencies...");let u=[];for(let p of l.dependsOn){let f=Ht(p);if(!f)continue;let y=await i.getModuleStatus(f);u.push(y)}let m=u.filter(p=>!p.active);if(m.length>0)if(s.stop(),t.withDeps)for(let p of m)await Wt(p.id,e,{...t,withDeps:!0});else console.error(v.red(`
|
|
42
|
+
Inactive dependencies for "${o}": ${m.map(p=>p.id).join(", ")}`)),console.error(v.gray(`Activate them first:
|
|
43
|
+
${m.map(p=>` kaven module activate ${p.id}`).join(`
|
|
44
44
|
`)}`)),console.log(v.gray(`
|
|
45
45
|
Or use --with-deps to activate them automatically.`)),process.exit(1);s.stop()}if((await i.getModuleStatus(l)).active){console.log(v.yellow(`
|
|
46
|
-
Module "${l.label}" is already active.`));return}if(!t.yes&&!await
|
|
46
|
+
Module "${l.label}" is already active.`));return}if(!t.yes&&!await xa.confirm({message:`Activate module "${l.label}"? This will uncomment ${l.models.length} model(s) in the schema.`,default:!0})){console.log(v.gray(`
|
|
47
47
|
Activation aborted.`));return}if(t.dryRun){console.log(v.bold(`
|
|
48
48
|
--- DRY RUN: Activating ${l.label} ---`)),console.log(`Models to uncomment: ${l.models.join(", ")}`),l.enums.length>0&&console.log(`Enums to uncomment: ${l.enums.join(", ")}`);return}s.start(`Uncommenting ${l.label} models in schema...`),await i.activateModule(l),s.succeed(v.green(`
|
|
49
|
-
Module ${l.label} activated. ${l.models.length} models added: ${l.models.join(", ")}`)),t.skipMigrate||console.log(v.cyan("\nNext step: Run `pnpm db:generate && pnpm db:migrate` to apply changes.")),n.capture("cli.module.activate.success",{moduleName:l.id,models:l.models.length},Date.now()-
|
|
50
|
-
Unknown module: "${o}".`)),console.error(v.gray(`Available modules: ${
|
|
49
|
+
Module ${l.label} activated. ${l.models.length} models added: ${l.models.join(", ")}`)),t.skipMigrate||console.log(v.cyan("\nNext step: Run `pnpm db:generate && pnpm db:migrate` to apply changes.")),n.capture("cli.module.activate.success",{moduleName:l.id,models:l.models.length},Date.now()-a),await n.flush()}catch(c){let l=fe(c);s.fail(v.red(`Failed to activate module: ${l.message}`)),n.capture("cli.module.activate.error",{moduleName:o,error:l.message},Date.now()-a),await n.flush(),process.exit(1)}}async function Fo(o,e,t={}){let n=M.getInstance(),a=Date.now();n.capture("cli.module.deactivate.start",{moduleName:o});let r=e??process.cwd(),i=new Ve(r),s=_o(`Deactivating module ${o}...`).start();try{let c=await i.exists();s.stop(),Lo(c,r);let l=Ht(o);l||(console.error(v.red(`
|
|
50
|
+
Unknown module: "${o}".`)),console.error(v.gray(`Available modules: ${Ae.map(m=>m.id).join(", ")}`)),process.exit(1)),s.start("Checking reverse dependencies...");let d=[];for(let m of Ae){if(m.id===l.id||!m.dependsOn.includes(l.id))continue;(await i.getModuleStatus(m)).active&&d.push(m.id)}if(d.length>0&&(s.stop(),console.error(v.red(`
|
|
51
51
|
Cannot deactivate "${o}": the following active modules depend on it:`)),console.error(v.gray(` ${d.join(", ")}`)),console.error(v.gray(`Deactivate them first:
|
|
52
52
|
${d.map(m=>` kaven module deactivate ${m}`).join(`
|
|
53
53
|
`)}`)),process.exit(1)),!(await i.getModuleStatus(l)).active){s.stop(),console.log(v.yellow(`
|
|
54
54
|
Module "${l.label}" is already inactive.`));return}if(t.dryRun){s.stop(),console.log(v.bold(`
|
|
55
55
|
--- DRY RUN: Deactivating ${l.label} ---`)),console.log(`Models to comment: ${l.models.join(", ")}`);return}s.start(`Commenting ${l.label} models in schema...`),await i.deactivateModule(l),s.succeed(v.green(`
|
|
56
|
-
Module ${l.label} deactivated successfully.`)),t.skipMigrate||console.log(v.cyan("\nNext step: Run `pnpm db:generate && pnpm db:migrate` to apply changes.")),n.capture("cli.module.deactivate.success",{moduleName:l.id},Date.now()-
|
|
57
|
-
`)),console.log(
|
|
58
|
-
`));let
|
|
59
|
-
`)),console.log(
|
|
60
|
-
`));try{await
|
|
61
|
-
`))}let d=
|
|
56
|
+
Module ${l.label} deactivated successfully.`)),t.skipMigrate||console.log(v.cyan("\nNext step: Run `pnpm db:generate && pnpm db:migrate` to apply changes.")),n.capture("cli.module.deactivate.success",{moduleName:l.id},Date.now()-a),await n.flush()}catch(c){let l=fe(c);s.fail(v.red(`Failed to deactivate module: ${l.message}`)),n.capture("cli.module.deactivate.error",{moduleName:o,error:l.message},Date.now()-a),await n.flush(),process.exit(1)}}async function Uo(o){let e=o??process.cwd(),t=new Ve(e),n=await t.exists(),a={module:18,status:10,models:44,deps:20},r=v.bold("Module".padEnd(a.module))+v.bold("Status".padEnd(a.status))+v.bold("Models".padEnd(a.models))+v.bold("Depends on"),i="\u2500".repeat(a.module+a.status+a.models+a.deps);if(console.log(),console.log(v.blue(`Kaven Schema Modules
|
|
57
|
+
`)),console.log(r),console.log(v.gray(i)),!n){for(let s of Ae){let c=s.id.padEnd(a.module),l=v.gray("unknown".padEnd(a.status)),d=s.models.join(", ").padEnd(a.models),u=s.dependsOn.length>0?s.dependsOn.join(", "):"\u2014";console.log(`${c}${l}${d}${u}`)}console.log(),console.log(v.yellow("Warning: schema.extended.prisma not found. Status cannot be determined.")),console.log(v.gray("Run this command in the root of a Kaven project to see real status."));return}for(let s of Ae){let c=await t.getModuleStatus(s),l=s.id.padEnd(a.module),d=c.active?"active":"inactive",u=c.active?v.green(d.padEnd(a.status)):v.gray(d.padEnd(a.status)),m=s.models.join(", ").padEnd(a.models),p=s.dependsOn.length>0?s.dependsOn.join(", "):"\u2014";console.log(`${l}${u}${m}${p}`)}console.log(),console.log(v.gray("To activate: kaven module activate <name> | To deactivate: kaven module deactivate <name>"))}import te from"chalk";import No from"ora";import Ea from"open";function Sa(o){return new Promise(e=>setTimeout(e,o))}async function Ca(o,e,t,n,a){let r=Date.now()+t*1e3,i=[5,10,15,20],s=0,c=n;for(;Date.now()<r;){let l=Math.ceil((r-Date.now())/1e3),d=Math.floor(l/60),u=String(l%60).padStart(2,"0");a.text=`Waiting for authorization... (expires in ${d}:${u})`,await Sa(c*1e3);try{let m=await o.pollDeviceToken(e);if(m.status==="success"&&m.tokens)return m.tokens;switch(m.status){case"slow_down":c+=5;break;case"access_denied":throw new Error("Authorization denied by user. Try again with 'kaven auth login'.");case"expired_token":throw new Error("Device code expired. Run 'kaven auth login' again.");case"authorization_pending":s<i.length-1&&(s++,c=i[s]);break}}catch(m){if(m.message.includes("denied")||m.message.includes("expired"))throw m;let p=m;throw p.code==="ECONNREFUSED"||p.code==="ENOTFOUND"?new Error("Network error. Check your connection and try again."):m}}throw new Error("Device code expired. Run 'kaven auth login' again.")}async function Ko(){let o=M.getInstance(),e=Date.now();o.capture("cli.auth.login.start");let t=new J,n=new A;console.log(te.blue(`\u{1F510} Starting authentication flow...
|
|
58
|
+
`));let a=No("Requesting device code from marketplace...").start();try{let{device_code:r,user_code:i,verification_uri:s,expires_in:c,interval:l}=await t.requestDeviceCode();a.stop(),console.log(te.yellow(`To complete login, follow these steps:
|
|
59
|
+
`)),console.log(te.bold(` Your verification code: ${te.cyan(i)}
|
|
60
|
+
`));try{await Ea(s),console.log(te.dim(" \u2713 Browser opened automatically"))}catch{console.log(te.yellow(" Open this URL in your browser:")),console.log(te.underline(` ${s}
|
|
61
|
+
`))}let d=No("Waiting for authorization...").start(),u=await Ca(t,r,c,l,d);await n.saveTokens(u),d.succeed(te.green(`Logged in as ${te.bold(u.user.email)}`)),console.log(te.dim(` Tier: ${u.user.tier}`)),console.log(te.gray(`
|
|
62
62
|
Your credentials were saved securely in ~/.kaven/auth.json
|
|
63
|
-
`)),o.capture("cli.auth.login.success",{tier:
|
|
64
|
-
Error: ${
|
|
65
|
-
`)),process.exit(1)}}import
|
|
63
|
+
`)),o.capture("cli.auth.login.success",{tier:u.user.tier},Date.now()-e),await o.flush()}catch(r){o.capture("cli.auth.login.error",{error:r.message},Date.now()-e),await o.flush(),a.fail(te.red("Authentication failed")),console.error(te.red(`
|
|
64
|
+
Error: ${r.message}
|
|
65
|
+
`)),process.exit(1)}}import Xt from"chalk";async function Vo(){let o=new A;try{if(!await o.isAuthenticated()){console.log(Xt.yellow("You are not authenticated."));return}await o.logout(),console.log(Xt.green("Logged out successfully."))}catch{console.error(Xt.red("Error during logout.")),process.exit(1)}}import Me from"chalk";async function Bo(){let o=M.getInstance();o.capture("cli.auth.whoami.start");let e=new A;try{let t=await e.getWhoamiInfo();if(!t){console.log(Me.yellow("You are not authenticated.")),console.log(Me.gray("Use 'kaven auth login' to sign in.")),o.capture("cli.auth.whoami.not_authenticated"),await o.flush();return}o.capture("cli.auth.whoami.authenticated"),console.log(),console.log(` ${Me.bold("Email:")} ${t.email}`),console.log(` ${Me.bold("GitHub:")} ${t.githubId}`),console.log(` ${Me.bold("Tier:")} ${t.tier}`),console.log(` ${Me.bold("Session:")} ${t.sessionExpiry}`),console.log()}catch{console.error(Me.red("Error checking authentication status.")),process.exit(1)}await o.flush()}import L from"chalk";import Pa from"ora";import $a from"cli-table3";function Ia(o){switch(o.toLowerCase()){case"starter":return L.green(o.toLowerCase());case"complete":return L.yellow(o.toLowerCase());case"pro":return L.magenta(o.toLowerCase());case"enterprise":return L.blue(o.toLowerCase());default:return o}}async function qo(o={}){let e=M.getInstance(),t=Date.now();e.capture("cli.marketplace.list.start");let n=new A,a=new J(n),r=o.page??1,i=Math.min(o.limit??20,100),s=o.sort??"newest";await n.isAuthenticated()||console.log(L.yellow("Warning: Not authenticated. Only public modules will be shown. Run: kaven auth login"));let l=Pa("Fetching modules from Marketplace...").start();try{let d=await a.listModules({category:o.category,page:r,pageSize:i,q:void 0});l.stop();let u=d.data,m=d.meta,p=d.total??m?.total??u.length;if(o.json){console.log(JSON.stringify(d,null,2)),e.capture("cli.marketplace.list.success",{count:u.length,json:!0},Date.now()-t),await e.flush();return}if(u.length===0){console.log(L.yellow("No modules found matching your criteria.")),e.capture("cli.marketplace.list.success",{count:0},Date.now()-t),await e.flush();return}let f=new $a({head:[L.white.bold("Slug"),L.white.bold("Name"),L.white.bold("Version"),L.white.bold("Tier"),L.white.bold("Installs")],style:{head:[],border:["gray"]}}),y=[...u];s==="popular"?y.sort((g,$)=>$.installCount-g.installCount):s==="name"&&y.sort((g,$)=>g.name.localeCompare($.name));for(let g of y)f.push([L.cyan(g.slug),L.white(g.name),L.green(g.latestVersion??"\u2014"),Ia(g.requiredTier??g.tier??""),L.gray(String(g.installCount))]);console.log(L.blue.bold(`
|
|
66
66
|
Available Marketplace Modules:
|
|
67
|
-
`)),console.log(f.toString());let
|
|
68
|
-
Showing ${
|
|
69
|
-
\u2717 This module requires a ${
|
|
70
|
-
`)),t.capture("cli.marketplace.install.error",{slug:o,error:"tier_insufficient",userTier:oe,moduleTier:ne},Date.now()-n),await t.flush(),process.exit(1);return}}let u=new se,f=new ye(i,u);if(await f.isModuleInstalled(o)&&!e.force){c.stop(),console.log(z.yellow(`Module '${o}' is already installed. Use --force to overwrite.`)),t.capture("cli.marketplace.install.skipped",{slug:o,reason:"already_installed"},Date.now()-n),await t.flush();return}c.text=`Creating download token for '${o}@${m}'...`;let S=await a.createDownloadToken(o,m);l=await Cr();let I=kt.join(l,"module.tar.gz"),N=kt.join(l,"extracted");await $e.ensureDir(N),c.text=`Downloading ${o} v${m}...`;let g=await a.resolveUrl(S.downloadUrl),P=await fetch(g);if(!P.ok)throw new Error(`Download failed: ${P.status} ${P.statusText}`);let ue=P.headers.get("content-length"),ze=ue?` (${Sr(parseInt(ue,10))})`:"";if(c.text=`Downloading ${o} v${m}${ze}...`,!P.body)throw new Error("No response body received for download");let be=$e.createWriteStream(I),jt=P.body.getReader();if(await new Promise((M,oe)=>{(async()=>{try{let Ee=!0;for(;Ee;){let{done:Tt,value:It}=await jt.read();Tt?(be.end(),Ee=!1):be.write(It)||await new Promise(An=>be.once("drain",An))}be.once("finish",M),be.once("error",oe)}catch(Ee){oe(Ee)}})()}),(await $e.stat(I)).size===0)throw new Error("Downloaded file is empty");if(!e.skipVerify){c.text=`Verifying signature for ${o} v${m}...`;let M=await a.getReleaseInfo(o,m);M.checksum&&M.signature&&M.publicKey?(await ht({filePath:I,expectedChecksum:M.checksum,signature:M.signature,publicKeyBase64:M.publicKey}),c.text=`Signature verified for ${o} v${m}`):c.text=`No signature data for ${o} v${m} \u2014 skipping verification`}c.text=`Extracting ${o} v${m}...`,await Er.x({file:I,cwd:N});let ct=kt.join(N,"module.json");if(!await $e.pathExists(ct))throw new Error(`module.json not found in extracted archive for '${o}'`);let b=await $e.readJson(ct);c.text=`Caching baseline for ${o} v${m}...`,await yt(o,m,N,i),c.text=`Installing ${o} v${m}...`,await f.install(b),c.succeed(z.green(`Module '${o}@${m}' installed successfully.`)),console.log(z.gray("Use 'kaven module doctor' to verify the installation.")),t.capture("cli.marketplace.install.success",{slug:o,version:m},Date.now()-n),await t.flush()}catch(d){let p=pe(d);if(c.stop(),p instanceof He){console.error(z.red(`Signature verification failed for '${o}': ${p.message}`)),console.error(z.yellow("Use --skip-verify to bypass (not recommended).")),t.capture("cli.marketplace.install.error",{slug:o,error:"signature_verification_failed"},Date.now()-n),await t.flush(),process.exit(1);return}if(p instanceof fo){console.error(z.red(`License required: '${o}' requires a '${p.requiredTier}' license.`)),console.error(z.yellow(`Run: kaven upgrade ${p.requiredTier}`)),t.capture("cli.marketplace.install.error",{slug:o,error:"license_required",tier:p.requiredTier},Date.now()-n),await t.flush(),process.exit(1);return}if(p instanceof mo||p.message.includes("Not authenticated")){console.error(z.red("Authentication required. Run: kaven auth login")),t.capture("cli.marketplace.install.error",{slug:o,error:"auth_error"},Date.now()-n),await t.flush(),process.exit(1);return}if(p instanceof lt){console.error(z.red("Could not reach marketplace. Check your connection.")),t.capture("cli.marketplace.install.error",{slug:o,error:"network_error"},Date.now()-n),await t.flush(),process.exit(1);return}t.capture("cli.marketplace.install.error",{slug:o,error:p.message},Date.now()-n),await t.flush(),c.fail(z.red(`Failed to install module '${o}'.`)),console.error(p),process.exit(1)}finally{l&&await $e.remove(l).catch(()=>{})}}import{select as Wt,spinner as Ar,outro as jr,isCancel as Tr,cancel as Ir}from"@clack/prompts";import $ from"picocolors";import{createInstance as $r}from"i18next";var Pr={common:{welcome:"Welcome to Kaven CLI",success:"Success",error:"Error",warning:"Warning",suggestion:"Suggestion",proceed:"Do you want to proceed?",cancelled:"Operation cancelled",exit:"Exit",back:"Back",cancel:"Cancel"},init:{intro:"Bootstrapping a new Kaven project",outro:"Project created successfully! Ready to build.",projectName:"What is the name of your project?",template:"Select a template",withSquad:"Include AIOX Squad (AI Agents)?",installing:"Installing dependencies..."},module:{activate:{title:"Module Activation: {{name}}",models:"Models to be added: {{count}}",envVars:"Env vars to inject: {{count}}",alreadyActive:"Module '{{name}}' is already active."},list:{header:"Kaven Schema Modules"}},doctor:{checking:"Running diagnostics...",allClear:"Your project is healthy!",issuesFound:"Found {{count}} issue(s).",fixSuggestion:"\u{1F4A1} Run 'kaven module doctor --fix' to resolve automatically."},marketplace:{browse:{loadingCategories:"Loading categories...",categoryLoadFailed:"Could not load categories \u2014 showing all modules.",browseByCategory:"Browse by category:",allModules:"All modules",loadingModules:"Loading modules...",errorLoadingModules:"Error loading modules: {{error}}",noModulesFound:"No modules found.",nextPage:"\u2192 Next page",prevPage:"\u2190 Previous page",backToCategories:"\u2191 Back to categories",whatToDo:"What would you like to do?",install:"Install {{name}}",backToList:"Back to module list",sessionEnded:"Browse session ended."}},config:{features:{catalogHeader:"Kaven Framework \u2014 Capability Catalog",capabilitiesTotal:"{{count}} capabilities total",tierPresets:"Tier presets:",tuiHeader:"\u{1F6E1}\uFE0F Kaven Feature Flag Configuration",selectTier:"Select a base tier:",customize:"Customize individual capabilities?",confirmOverwrite:"Seed file already exists. Overwrite?",seedWritten:"Seed file written to: {{path}}",runSeed:"Run pnpm prisma db seed to apply capabilities to your database.",dryRunHeader:"--- DRY RUN: Generated Content ---"}}},Mr={common:{welcome:"Bem-vindo \xE0 Kaven CLI",success:"Sucesso",error:"Erro",warning:"Aviso",suggestion:"Sugest\xE3o",proceed:"Deseja continuar?",cancelled:"Opera\xE7\xE3o cancelada",exit:"Sair",back:"Voltar",cancel:"Cancelar"},init:{intro:"Iniciando um novo projeto Kaven",outro:"Projeto criado com sucesso! Hora de construir.",projectName:"Qual o nome do seu projeto?",template:"Selecione um template",withSquad:"Incluir AIOX Squad (Agentes de IA)?",installing:"Instalando depend\xEAncias..."},module:{activate:{title:"Ativa\xE7\xE3o de M\xF3dulo: {{name}}",models:"Models a serem adicionados: {{count}}",envVars:"Vari\xE1veis de ambiente: {{count}}",alreadyActive:"O m\xF3dulo '{{name}}' j\xE1 est\xE1 ativo."},list:{header:"M\xF3dulos de Schema Kaven"}},doctor:{checking:"Executando diagn\xF3sticos...",allClear:"Seu projeto est\xE1 saud\xE1vel!",issuesFound:"Encontrados {{count}} problema(s).",fixSuggestion:"\u{1F4A1} Execute 'kaven module doctor --fix' para resolver automaticamente."},marketplace:{browse:{loadingCategories:"Carregando categorias...",categoryLoadFailed:"N\xE3o foi poss\xEDvel carregar categorias \u2014 exibindo todos os m\xF3dulos.",browseByCategory:"Navegar por categoria:",allModules:"Todos os m\xF3dulos",loadingModules:"Carregando m\xF3dulos...",errorLoadingModules:"Erro ao carregar m\xF3dulos: {{error}}",noModulesFound:"Nenhum m\xF3dulo encontrado.",nextPage:"\u2192 Pr\xF3xima p\xE1gina",prevPage:"\u2190 P\xE1gina anterior",backToCategories:"\u2191 Voltar \xE0s categorias",whatToDo:"O que deseja fazer?",install:"Instalar {{name}}",backToList:"Voltar \xE0 lista",sessionEnded:"Sess\xE3o de navega\xE7\xE3o encerrada."}},config:{features:{catalogHeader:"Kaven Framework \u2014 Cat\xE1logo de Capacidades",capabilitiesTotal:"{{count}} capacidades no total",tierPresets:"Presets de tier:",tuiHeader:"\u{1F6E1}\uFE0F Configura\xE7\xE3o de Feature Flags Kaven",selectTier:"Selecione um tier base:",customize:"Personalizar capacidades individualmente?",confirmOverwrite:"Arquivo de seed j\xE1 existe. Sobrescrever?",seedWritten:"Seed escrito em: {{path}}",runSeed:"Execute pnpm prisma db seed para aplicar as capacidades ao banco.",dryRunHeader:"--- DRY RUN: Conte\xFAdo Gerado ---"}}},ce=class o{static instance;i18n=$r();constructor(){}static async getInstance(){return o.instance||(o.instance=new o,await o.instance.init()),o.instance}async init(){let e=process.env.KAVEN_LANG||"en";await this.i18n.init({lng:e,fallbackLng:"en",resources:{en:{translation:Pr},"pt-BR":{translation:Mr}}})}t(e,t){return this.i18n.t(e,t)}async setLanguage(e){await this.i18n.changeLanguage(e)}getI18n(){return this.i18n}};var Bo=10;function Jo(o){switch(o.toUpperCase()){case"FREE":return $.dim("[FREE]");case"STARTER":return $.green("[STARTER]");case"COMPLETE":return $.yellow("[COMPLETE]");case"PRO":return $.magenta("[PRO]");case"ENTERPRISE":return $.cyan("[ENTERPRISE]");default:return $.dim(`[${o}]`)}}function Xt(o){Tr(o)&&(Ir("Cancelled."),process.exit(0))}async function zo(){let o=await ce.getInstance(),e=new A,t=new B(e),n=Ar(),a=(await e.getAuth())?.user?.tier??"starter",i={category:null,page:1,selectedModule:null,screen:"categories"};for(;i.screen!=="exit";){if(i.screen==="categories"){n.start(o.t("marketplace.browse.loadingCategories"));let s=[];try{s=await t.getCategories(),n.stop()}catch{n.stop($.yellow(o.t("marketplace.browse.categoryLoadFailed")))}let c=[{label:o.t("marketplace.browse.allModules"),value:"__all__"},...s.map(d=>({label:d,value:d})),{label:$.dim(o.t("common.exit")),value:"__exit__"}],l=await Wt({message:o.t("marketplace.browse.browseByCategory"),options:c});if(Xt(l),l==="__exit__"){i.screen="exit";break}i.category=l==="__all__"?null:l,i.page=1,i.screen="list";continue}if(i.screen==="list"){n.start(o.t("marketplace.browse.loadingModules"));let s=[],c=1;try{let f=await t.listModules({category:i.category||void 0,page:i.page,pageSize:Bo});s=f.data,c=Math.ceil(f.total/Bo)||1,n.stop()}catch(f){n.stop($.red(o.t("marketplace.browse.errorLoadingModules",{error:f instanceof Error?f.message:String(f)}))),i.screen="categories";continue}if(s.length===0){console.log($.yellow(o.t("marketplace.browse.noModulesFound"))),i.screen="categories";continue}let l=i.category?` [${i.category}]`:"",d=c>1?` (${i.page}/${c})`:"",p=[...s.map(f=>{let w=f.requiredTier??f.tier??"",S=w&&!nt(a,w),I=Jo(w),N=S?$.red(" \u{1F512}"):"";return{label:`${f.name} ${I}${N}`,hint:f.description,value:f.slug}}),...i.page<c?[{label:$.cyan(o.t("marketplace.browse.nextPage")),value:"__next__"}]:[],...i.page>1?[{label:$.cyan(o.t("marketplace.browse.prevPage")),value:"__prev__"}]:[],{label:$.dim(o.t("marketplace.browse.backToCategories")),value:"__back__"},{label:$.dim(o.t("common.exit")),value:"__exit__"}],m=await Wt({message:`Modules${l}${d}:`,options:p});if(Xt(m),m==="__exit__"){i.screen="exit";break}if(m==="__back__"){i.screen="categories";continue}if(m==="__next__"){i.page++;continue}if(m==="__prev__"){i.page=Math.max(1,i.page-1);continue}let u=s.find(f=>f.slug===m);u&&(i.selectedModule=u,i.screen="detail");continue}if(i.screen==="detail"&&i.selectedModule){let s=i.selectedModule,c=s.requiredTier??s.tier??"",l=c&&!nt(a,c);console.log(),console.log($.bold(s.name),Jo(c),l?$.red("\u{1F512}"):""),console.log($.dim(`Version: ${s.latestVersion||"latest"}`)),s.installCount!==void 0&&console.log($.dim(`Installs: ${s.installCount.toLocaleString()}`)),s.description&&(console.log(),console.log(s.description)),l&&(console.log(),console.log($.yellow("Requires a higher plan. Upgrade: https://kaven.site/pricing"))),console.log();let d=await Wt({message:o.t("marketplace.browse.whatToDo"),options:[{label:o.t("marketplace.browse.install",{name:s.name}),value:"install"},{label:$.dim(o.t("marketplace.browse.backToList")),value:"back"},{label:$.dim(o.t("common.exit")),value:"exit"}]});if(Xt(d),d==="exit"){i.screen="exit";break}if(d==="back"){i.selectedModule=null,i.screen="list";continue}if(d==="install"){console.log(),await bt(s.slug,{force:!1,skipEnv:!1}),i.screen="exit";break}}}jr($.dim(o.t("marketplace.browse.sessionEnded")))}import me from"chalk";async function Ho(o=10){let t=await j.getInstance().getRecentEvents(o);if(t.length===0){console.log(me.yellow(`
|
|
67
|
+
`)),console.log(f.toString());let C=Math.ceil(p/i),R=(r-1)*i+1,K=Math.min(r*i,p);console.log(L.gray(`
|
|
68
|
+
Showing ${R}-${K} of ${p} modules (page ${r}/${C})`)),console.log(L.gray("Use 'kaven marketplace install <slug>' to install a module.")),e.capture("cli.marketplace.list.success",{count:u.length,total:p},Date.now()-t),await e.flush()}catch(d){l.stop(),d instanceof gt&&(console.error(L.red("Could not reach marketplace. Check your connection.")),e.capture("cli.marketplace.list.error",{error:"network_error"},Date.now()-t),await e.flush(),process.exit(1)),e.capture("cli.marketplace.list.error",{error:d.message},Date.now()-t),await e.flush(),console.error(L.red("Error fetching modules from Marketplace.")),console.error(d),process.exit(1)}}import z from"chalk";import Aa from"ora";import je from"fs-extra";import Pt from"path";import ja from"os";import*as Go from"tar";var Jo=["starter","complete","pro","enterprise"];function Yt(o){return(o??"starter").toLowerCase()}function lt(o,e){let t=Yt(o),n=Yt(e),a=Jo.indexOf(t),r=Jo.indexOf(n),i=a>=0?a:0,s=r>=0?r:0;return i>=s}function Zt(o){let e=Yt(o);return{starter:"Starter",complete:"Complete",pro:"Pro",enterprise:"Enterprise"}[e]??o??"Starter"}var Ma={ora:Aa},Ta={x:Go.x};async function Ra(){let o=Pt.join(ja.tmpdir(),"kaven-install-");return je.mkdtemp(o)}function Da(o){return o<1024?`${o} B`:o<1024*1024?`${Math.round(o/1024)} KB`:`${(o/(1024*1024)).toFixed(1)} MB`}async function $t(o,e={}){let t=M.getInstance(),n=Date.now();t.capture("cli.marketplace.install.start",{slug:o});let a=new A,r=new J(a),i=process.cwd(),s;try{s=await a.getValidToken()}catch{console.error(z.red("Authentication required. Run: kaven auth login")),t.capture("cli.marketplace.install.error",{slug:o,error:"not_authenticated"},Date.now()-n),await t.flush(),process.exit(1);return}let c=Ma.ora(`Preparing installation of '${o}'...`).start(),l=null;try{c.text=`Fetching module '${o}' from Marketplace...`;let d;try{d=await r.getModule(o)}catch(I){if(I instanceof vo){c.fail(z.red(`Module '${o}' not found in Marketplace.`)),process.exit(1);return}throw I}let u=d.latestVersion??d.releases?.[0]?.version,m=e.version??u;if(!m){c.fail(z.red(`No published version found for '${o}'.`)),process.exit(1);return}if(!e.skipTierCheck){let ne=(await a.getAuth())?.user?.tier??"starter",ae=d.requiredTier??d.tier;if(!lt(ne,ae)){c.stop(),console.error(z.red(`
|
|
69
|
+
\u2717 This module requires a ${Zt(ae)} plan or higher.`)),console.error(z.yellow(` Your current plan: ${Zt(ne)}`)),console.error(z.dim(` Upgrade: https://kaven.site/pricing
|
|
70
|
+
`)),t.capture("cli.marketplace.install.error",{slug:o,error:"tier_insufficient",userTier:ne,moduleTier:ae},Date.now()-n),await t.flush(),process.exit(1);return}}let p=new ce,f=new be(i,p);if(await f.isModuleInstalled(o)&&!e.force){c.stop(),console.log(z.yellow(`Module '${o}' is already installed. Use --force to overwrite.`)),t.capture("cli.marketplace.install.skipped",{slug:o,reason:"already_installed"},Date.now()-n),await t.flush();return}c.text=`Creating download token for '${o}@${m}'...`;let C=await r.createDownloadToken(o,m);l=await Ra();let R=Pt.join(l,"module.tar.gz"),K=Pt.join(l,"extracted");await je.ensureDir(K),c.text=`Downloading ${o} v${m}...`;let g=await r.resolveUrl(C.downloadUrl),$=await fetch(g);if(!$.ok)throw new Error(`Download failed: ${$.status} ${$.statusText}`);let me=$.headers.get("content-length"),Ye=me?` (${Da(parseInt(me,10))})`:"";if(c.text=`Downloading ${o} v${m}${Ye}...`,!$.body)throw new Error("No response body received for download");let Pe=je.createWriteStream(R),Dt=$.body.getReader();if(await new Promise((I,ne)=>{(async()=>{try{let Ie=!0;for(;Ie;){let{done:_t,value:Ot}=await Dt.read();_t?(Pe.end(),Ie=!1):Pe.write(Ot)||await new Promise(Fn=>Pe.once("drain",Fn))}Pe.once("finish",I),Pe.once("error",ne)}catch(Ie){ne(Ie)}})()}),(await je.stat(R)).size===0)throw new Error("Downloaded file is empty");if(!e.skipVerify){c.text=`Verifying signature for ${o} v${m}...`;let I=await r.getReleaseInfo(o,m);I.checksum&&I.signature&&I.publicKey?(await xt({filePath:R,expectedChecksum:I.checksum,signature:I.signature,publicKeyBase64:I.publicKey}),c.text=`Signature verified for ${o} v${m}`):c.text=`No signature data for ${o} v${m} \u2014 skipping verification`}c.text=`Extracting ${o} v${m}...`,await Ta.x({file:R,cwd:K});let ft=Pt.join(K,"module.json");if(!await je.pathExists(ft))throw new Error(`module.json not found in extracted archive for '${o}'`);let b=await je.readJson(ft);c.text=`Caching baseline for ${o} v${m}...`,await Et(o,m,K,i),c.text=`Installing ${o} v${m}...`,await f.install(b),c.succeed(z.green(`Module '${o}@${m}' installed successfully.`)),console.log(z.gray("Use 'kaven module doctor' to verify the installation.")),t.capture("cli.marketplace.install.success",{slug:o,version:m},Date.now()-n),await t.flush()}catch(d){let u=fe(d);if(c.stop(),u instanceof Ze){console.error(z.red(`Signature verification failed for '${o}': ${u.message}`)),console.error(z.yellow("Use --skip-verify to bypass (not recommended).")),t.capture("cli.marketplace.install.error",{slug:o,error:"signature_verification_failed"},Date.now()-n),await t.flush(),process.exit(1);return}if(u instanceof yo){console.error(z.red(`License required: '${o}' requires a '${u.requiredTier}' license.`)),console.error(z.yellow(`Run: kaven upgrade ${u.requiredTier}`)),t.capture("cli.marketplace.install.error",{slug:o,error:"license_required",tier:u.requiredTier},Date.now()-n),await t.flush(),process.exit(1);return}if(u instanceof wo||u.message.includes("Not authenticated")){console.error(z.red("Authentication required. Run: kaven auth login")),t.capture("cli.marketplace.install.error",{slug:o,error:"auth_error"},Date.now()-n),await t.flush(),process.exit(1);return}if(u instanceof gt){console.error(z.red("Could not reach marketplace. Check your connection.")),t.capture("cli.marketplace.install.error",{slug:o,error:"network_error"},Date.now()-n),await t.flush(),process.exit(1);return}t.capture("cli.marketplace.install.error",{slug:o,error:u.message},Date.now()-n),await t.flush(),c.fail(z.red(`Failed to install module '${o}'.`)),console.error(u),process.exit(1)}finally{l&&await je.remove(l).catch(()=>{})}}import{select as Qt,spinner as Fa,outro as Ua,isCancel as Na,cancel as Ka}from"@clack/prompts";import P from"picocolors";import{createInstance as _a}from"i18next";var Oa={common:{welcome:"Welcome to Kaven CLI",success:"Success",error:"Error",warning:"Warning",suggestion:"Suggestion",proceed:"Do you want to proceed?",cancelled:"Operation cancelled",exit:"Exit",back:"Back",cancel:"Cancel"},init:{intro:"Bootstrapping a new Kaven project",outro:"Project created successfully! Ready to build.",projectName:"What is the name of your project?",template:"Select a template",withSquad:"Include AIOX Squad (AI Agents)?",installing:"Installing dependencies..."},module:{activate:{title:"Module Activation: {{name}}",models:"Models to be added: {{count}}",envVars:"Env vars to inject: {{count}}",alreadyActive:"Module '{{name}}' is already active."},list:{header:"Kaven Schema Modules"}},doctor:{checking:"Running diagnostics...",allClear:"Your project is healthy!",issuesFound:"Found {{count}} issue(s).",fixSuggestion:"\u{1F4A1} Run 'kaven module doctor --fix' to resolve automatically."},marketplace:{browse:{loadingCategories:"Loading categories...",categoryLoadFailed:"Could not load categories \u2014 showing all modules.",browseByCategory:"Browse by category:",allModules:"All modules",loadingModules:"Loading modules...",errorLoadingModules:"Error loading modules: {{error}}",noModulesFound:"No modules found.",nextPage:"\u2192 Next page",prevPage:"\u2190 Previous page",backToCategories:"\u2191 Back to categories",whatToDo:"What would you like to do?",install:"Install {{name}}",backToList:"Back to module list",sessionEnded:"Browse session ended."}},config:{features:{catalogHeader:"Kaven Framework \u2014 Capability Catalog",capabilitiesTotal:"{{count}} capabilities total",tierPresets:"Tier presets:",tuiHeader:"\u{1F6E1}\uFE0F Kaven Feature Flag Configuration",selectTier:"Select a base tier:",customize:"Customize individual capabilities?",confirmOverwrite:"Seed file already exists. Overwrite?",seedWritten:"Seed file written to: {{path}}",runSeed:"Run pnpm prisma db seed to apply capabilities to your database.",dryRunHeader:"--- DRY RUN: Generated Content ---"}}},La={common:{welcome:"Bem-vindo \xE0 Kaven CLI",success:"Sucesso",error:"Erro",warning:"Aviso",suggestion:"Sugest\xE3o",proceed:"Deseja continuar?",cancelled:"Opera\xE7\xE3o cancelada",exit:"Sair",back:"Voltar",cancel:"Cancelar"},init:{intro:"Iniciando um novo projeto Kaven",outro:"Projeto criado com sucesso! Hora de construir.",projectName:"Qual o nome do seu projeto?",template:"Selecione um template",withSquad:"Incluir AIOX Squad (Agentes de IA)?",installing:"Instalando depend\xEAncias..."},module:{activate:{title:"Ativa\xE7\xE3o de M\xF3dulo: {{name}}",models:"Models a serem adicionados: {{count}}",envVars:"Vari\xE1veis de ambiente: {{count}}",alreadyActive:"O m\xF3dulo '{{name}}' j\xE1 est\xE1 ativo."},list:{header:"M\xF3dulos de Schema Kaven"}},doctor:{checking:"Executando diagn\xF3sticos...",allClear:"Seu projeto est\xE1 saud\xE1vel!",issuesFound:"Encontrados {{count}} problema(s).",fixSuggestion:"\u{1F4A1} Execute 'kaven module doctor --fix' para resolver automaticamente."},marketplace:{browse:{loadingCategories:"Carregando categorias...",categoryLoadFailed:"N\xE3o foi poss\xEDvel carregar categorias \u2014 exibindo todos os m\xF3dulos.",browseByCategory:"Navegar por categoria:",allModules:"Todos os m\xF3dulos",loadingModules:"Carregando m\xF3dulos...",errorLoadingModules:"Erro ao carregar m\xF3dulos: {{error}}",noModulesFound:"Nenhum m\xF3dulo encontrado.",nextPage:"\u2192 Pr\xF3xima p\xE1gina",prevPage:"\u2190 P\xE1gina anterior",backToCategories:"\u2191 Voltar \xE0s categorias",whatToDo:"O que deseja fazer?",install:"Instalar {{name}}",backToList:"Voltar \xE0 lista",sessionEnded:"Sess\xE3o de navega\xE7\xE3o encerrada."}},config:{features:{catalogHeader:"Kaven Framework \u2014 Cat\xE1logo de Capacidades",capabilitiesTotal:"{{count}} capacidades no total",tierPresets:"Presets de tier:",tuiHeader:"\u{1F6E1}\uFE0F Configura\xE7\xE3o de Feature Flags Kaven",selectTier:"Selecione um tier base:",customize:"Personalizar capacidades individualmente?",confirmOverwrite:"Arquivo de seed j\xE1 existe. Sobrescrever?",seedWritten:"Seed escrito em: {{path}}",runSeed:"Execute pnpm prisma db seed para aplicar as capacidades ao banco.",dryRunHeader:"--- DRY RUN: Conte\xFAdo Gerado ---"}}},le=class o{static instance;i18n=_a();constructor(){}static async getInstance(){return o.instance||(o.instance=new o,await o.instance.init()),o.instance}async init(){let e=process.env.KAVEN_LANG||"en";await this.i18n.init({lng:e,fallbackLng:"en",resources:{en:{translation:Oa},"pt-BR":{translation:La}}})}t(e,t){return this.i18n.t(e,t)}async setLanguage(e){await this.i18n.changeLanguage(e)}getI18n(){return this.i18n}};var zo=10;function Ho(o){switch(o.toUpperCase()){case"FREE":return P.dim("[FREE]");case"STARTER":return P.green("[STARTER]");case"COMPLETE":return P.yellow("[COMPLETE]");case"PRO":return P.magenta("[PRO]");case"ENTERPRISE":return P.cyan("[ENTERPRISE]");default:return P.dim(`[${o}]`)}}function eo(o){Na(o)&&(Ka("Cancelled."),process.exit(0))}async function Wo(){let o=await le.getInstance(),e=new A,t=new J(e),n=Fa(),r=(await e.getAuth())?.user?.tier??"starter",i={category:null,page:1,selectedModule:null,screen:"categories"};for(;i.screen!=="exit";){if(i.screen==="categories"){n.start(o.t("marketplace.browse.loadingCategories"));let s=[];try{s=await t.getCategories(),n.stop()}catch{n.stop(P.yellow(o.t("marketplace.browse.categoryLoadFailed")))}let c=[{label:o.t("marketplace.browse.allModules"),value:"__all__"},...s.map(d=>({label:d,value:d})),{label:P.dim(o.t("common.exit")),value:"__exit__"}],l=await Qt({message:o.t("marketplace.browse.browseByCategory"),options:c});if(eo(l),l==="__exit__"){i.screen="exit";break}i.category=l==="__all__"?null:l,i.page=1,i.screen="list";continue}if(i.screen==="list"){n.start(o.t("marketplace.browse.loadingModules"));let s=[],c=1;try{let f=await t.listModules({category:i.category||void 0,page:i.page,pageSize:zo});s=f.data,c=Math.ceil(f.total/zo)||1,n.stop()}catch(f){n.stop(P.red(o.t("marketplace.browse.errorLoadingModules",{error:f instanceof Error?f.message:String(f)}))),i.screen="categories";continue}if(s.length===0){console.log(P.yellow(o.t("marketplace.browse.noModulesFound"))),i.screen="categories";continue}let l=i.category?` [${i.category}]`:"",d=c>1?` (${i.page}/${c})`:"",u=[...s.map(f=>{let y=f.requiredTier??f.tier??"",C=y&&!lt(r,y),R=Ho(y),K=C?P.red(" \u{1F512}"):"";return{label:`${f.name} ${R}${K}`,hint:f.description,value:f.slug}}),...i.page<c?[{label:P.cyan(o.t("marketplace.browse.nextPage")),value:"__next__"}]:[],...i.page>1?[{label:P.cyan(o.t("marketplace.browse.prevPage")),value:"__prev__"}]:[],{label:P.dim(o.t("marketplace.browse.backToCategories")),value:"__back__"},{label:P.dim(o.t("common.exit")),value:"__exit__"}],m=await Qt({message:`Modules${l}${d}:`,options:u});if(eo(m),m==="__exit__"){i.screen="exit";break}if(m==="__back__"){i.screen="categories";continue}if(m==="__next__"){i.page++;continue}if(m==="__prev__"){i.page=Math.max(1,i.page-1);continue}let p=s.find(f=>f.slug===m);p&&(i.selectedModule=p,i.screen="detail");continue}if(i.screen==="detail"&&i.selectedModule){let s=i.selectedModule,c=s.requiredTier??s.tier??"",l=c&&!lt(r,c);console.log(),console.log(P.bold(s.name),Ho(c),l?P.red("\u{1F512}"):""),console.log(P.dim(`Version: ${s.latestVersion||"latest"}`)),s.installCount!==void 0&&console.log(P.dim(`Installs: ${s.installCount.toLocaleString()}`)),s.description&&(console.log(),console.log(s.description)),l&&(console.log(),console.log(P.yellow("Requires a higher plan. Upgrade: https://kaven.site/pricing"))),console.log();let d=await Qt({message:o.t("marketplace.browse.whatToDo"),options:[{label:o.t("marketplace.browse.install",{name:s.name}),value:"install"},{label:P.dim(o.t("marketplace.browse.backToList")),value:"back"},{label:P.dim(o.t("common.exit")),value:"exit"}]});if(eo(d),d==="exit"){i.screen="exit";break}if(d==="back"){i.selectedModule=null,i.screen="list";continue}if(d==="install"){console.log(),await $t(s.slug,{force:!1,skipEnv:!1}),i.screen="exit";break}}}Ua(P.dim(o.t("marketplace.browse.sessionEnded")))}import ge from"chalk";async function Xo(o=10){let t=await M.getInstance().getRecentEvents(o);if(t.length===0){console.log(ge.yellow(`
|
|
71
71
|
Nenhum evento de telemetria encontrado localmente.
|
|
72
|
-
`));return}console.log(
|
|
72
|
+
`));return}console.log(ge.blue.bold(`
|
|
73
73
|
\u{1F4CA} \xDAltimos ${t.length} eventos de telemetria:
|
|
74
|
-
`)),t.forEach(n=>{let
|
|
74
|
+
`)),t.forEach(n=>{let a=ge.gray(`[${new Date(n.timestamp).toLocaleTimeString()}]`),r=n.event.includes("error")?ge.red("\u2716"):ge.green("\u2714"),i=n.duration?ge.yellow(` (${n.duration}ms)`):"";console.log(`${a} ${r} ${ge.cyan(n.event)}${i}`),n.metadata&&Object.keys(n.metadata).length>0&&console.log(ge.gray(` > ${JSON.stringify(n.metadata)}`))}),console.log(ge.gray(`
|
|
75
75
|
Log local: ~/.kaven/telemetry.log
|
|
76
|
-
`))}import{Command as
|
|
77
|
-
`+
|
|
78
|
-
`),console.log(` Key: ${
|
|
76
|
+
`))}import{Command as qa}from"commander";import{Command as Ba}from"commander";import de from"chalk";import to from"fs/promises";import Zo from"path";import Qo from"os";var Yo=Zo.join(Qo.homedir(),".kaven","cache","licenses.json"),Va=3600*1e3,It=class{cacheDir=Zo.join(Qo.homedir(),".kaven","cache");isValidFormat(e){return/^KAVEN-(STARTER|COMPLETE|PRO|ENTERPRISE)-[A-Z0-9]{8}-[A-Z0-9]{2}$/.test(e)}async readCache(){try{let e=await to.readFile(Yo,"utf-8");return JSON.parse(e)}catch{return{}}}async writeCache(e){await to.mkdir(this.cacheDir,{recursive:!0}),await to.writeFile(Yo,JSON.stringify(e,null,2),"utf-8")}isCacheValid(e){return Date.now()-e.validatedAt<Va}async getCached(e){let n=(await this.readCache())[e];return n&&this.isCacheValid(n)?n:null}async setCached(e){let t=await this.readCache();t[e.key]={...e,validatedAt:Date.now()},await this.writeCache(t)}async validateLicense(e,t){let n=await this.getCached(e);if(n)return{valid:!0,tier:n.tier,expiresAt:n.expiresAt,source:"cache"};if(!this.isValidFormat(e))throw new Error("Invalid license key format");let{MarketplaceClient:a}=await import("./MarketplaceClient-YCFH2VU4.js"),i=await new a().validateLicense(e,t);return await this.setCached({key:e,tier:i.tier,expiresAt:i.expiresAt,validatedAt:Date.now()}),{...i,source:"api"}}async getLicenseStatus(e){let{MarketplaceClient:t}=await import("./MarketplaceClient-YCFH2VU4.js");return new t().getLicenseStatus(e)}tierLevel(e){return{STARTER:1,COMPLETE:2,PRO:3,ENTERPRISE:4}[e.toUpperCase()]??0}userHasRequiredTier(e,t){return this.tierLevel(e)>=this.tierLevel(t)}};function en(){return new Ba("status").description("Show license status and tier information").argument("[license-key]","License key to check (uses stored license if omitted)").action(async o=>{let e=new It,t=o??process.env.KAVEN_LICENSE_KEY;t||(console.error(de.red("\u2717 No license key provided. Pass as argument or set KAVEN_LICENSE_KEY.")),process.exit(1));try{console.log(de.dim("Checking license status..."));let n=await e.getLicenseStatus(t);if(console.log(`
|
|
77
|
+
`+de.bold("License Status")+`
|
|
78
|
+
`),console.log(` Key: ${de.dim(n.key.substring(0,16)+"...")}`),console.log(` Tier: ${de.magenta(n.tier)}`),n.expiresAt){let a=n.daysUntilExpiry,r=a!==null&&a<30?de.red:de.green;console.log(` Expires: ${r(n.expiresAt)}${a!==null?de.dim(` (${a} days)`):""}`)}else console.log(` Expires: ${de.green("Never")}`);console.log()}catch(n){let a=n instanceof Error?n.message:"Failed to check license status";console.error(de.red("\u2717 "+a)),process.exit(1)}})}function tn(){let o=new qa("license").description("Manage Kaven licenses");return o.addCommand(en()),o}import we from"path";import ye from"fs-extra";import{fileURLToPath as pn}from"url";import{intro as tr,outro as or,text as jt,select as dn,confirm as un,spinner as nr,note as ar,isCancel as rr,cancel as ro}from"@clack/prompts";import Y from"picocolors";import j from"fs-extra";import ue from"path";import{spawn as Ja}from"child_process";var Ga="https://github.com/kaven-co/kaven-template.git",za="https://github.com/bychrisr/kaven-squad";function Te(o,e,t,n={}){let a=typeof n=="function"?{onData:n}:n,{onData:r,timeoutMs:i,env:s}=a;return new Promise((c,l)=>{let d=Ja(o,e,{cwd:t,stdio:r?"pipe":"inherit",env:{...process.env,...s}}),u;i&&(u=setTimeout(()=>{d.kill("SIGKILL"),c(1)},i)),r&&d.stdout&&d.stdout.on("data",m=>r(m.toString())),r&&d.stderr&&d.stderr.on("data",m=>r(m.toString())),d.on("error",m=>{clearTimeout(u),l(m)}),d.on("close",m=>{clearTimeout(u),c(m??0)})})}var Be=class{validateName(e){return!e||e.trim().length===0?{valid:!1,reason:"Project name cannot be empty"}:/\s/.test(e)?{valid:!1,reason:"Project name cannot contain spaces"}:/^[a-z0-9-]+$/.test(e)?{valid:!0}:{valid:!1,reason:"Project name must only contain lowercase letters, numbers, and hyphens"}}async cloneTemplate(e,t){let n=t||Ga;if(console.log(`[INIT] Clone Source: ${n}`),console.log(`[INIT] Target Dir: ${e}`),await j.pathExists(n)&&(n.startsWith("/")||n.startsWith("./")||n.startsWith("../"))){console.log("[INIT] Local Path Detected. Copying..."),await j.copy(n,e,{filter:r=>!r.includes("node_modules")&&!r.includes(".git")&&!r.includes(".turbo")}),console.log("[INIT] Local Copy Done.");return}let a=await Te("git",["clone","--depth","1",n,e],process.cwd());if(a!==0)throw new Error(`git clone failed with exit code ${a}`)}async removeGitDir(e){let t=ue.join(e,".git");await j.pathExists(t)&&await j.remove(t)}async replacePlaceholders(e,t){let n={"{{PROJECT_NAME}}":t.projectName,"{{DATABASE_URL}}":t.dbUrl,"{{DEFAULT_LOCALE}}":t.locale,"{{DEFAULT_CURRENCY}}":t.currency},a=["package.json",".env.example","packages/database/prisma/schema.prisma","apps/api/package.json","apps/admin/package.json","apps/tenant/package.json","docs/architecture/tech-stack.md","docs/architecture/source-tree.md","docs/architecture/coding-standards.md"];for(let i of a){let s=ue.join(e,i);if(!await j.pathExists(s))continue;let c=await j.readFile(s,"utf-8");for(let[l,d]of Object.entries(n))c=c.split(l).join(d);await j.writeFile(s,c,"utf-8")}let r=ue.join(e,"package.json");if(await j.pathExists(r)){let i=await j.readJson(r);i.name!==t.projectName&&(i.name=t.projectName,await j.writeJson(r,i,{spaces:2}))}}async runInstall(e){let t=await Te("pnpm",["install"],e);if(t!==0)throw new Error(`pnpm install failed with exit code ${t}`)}async initGit(e){await Te("git",["init"],e),await Te("git",["add","."],e),await Te("git",["commit","-m","chore: initial kaven setup"],e)}async installSquad(e){let t=ue.join(e,"squads"),n=ue.join(t,"kaven-squad");if(await j.pathExists(n))return{installed:!1,reason:"already-exists"};await j.ensureDir(t);let a=await Te("git",["clone","--depth","1",za,n],process.cwd(),{env:{GIT_TERMINAL_PROMPT:"0"},timeoutMs:3e4});if(a!==0)return await j.pathExists(n)&&await j.remove(n),{installed:!1,reason:`git clone exited with code ${a}`};let r=ue.join(n,".git");return await j.pathExists(r)&&await j.remove(r),{installed:!0}}async installAIOXCore(e){if(parseInt(process.version.slice(1).split(".")[0],10)<18)return{installed:!1,reason:`Node >= 18 required (current: ${process.version})`};let n=ue.join(e,"squads","kaven-squad");if(!await j.pathExists(n))return{installed:!1,reason:"kaven-squad not found \u2014 run squad install first"};if((await j.readdir(n)).length===0)return{installed:!1,reason:"kaven-squad directory is empty \u2014 squad install may have failed"};let r=ue.join(e,".aiox-core");if(await j.pathExists(r))return{installed:!0,reason:"already-installed"};let i=await Te("npx",["aiox-core@latest","install","--quiet"],e,{timeoutMs:12e4});return i!==0?{installed:!1,reason:`npx aiox-core exited with code ${i}`}:{installed:!0}}async healthCheck(e){let t=[],n=["package.json",".env.example","packages/database/prisma/schema.prisma"];for(let r of n)await j.pathExists(ue.join(e,r))||t.push(`Missing required file: ${r}`);return await j.pathExists(ue.join(e,"node_modules"))||t.push("Dependencies not installed. Run: pnpm install"),{healthy:t.length===0,issues:t}}};import Re from"path";import he from"fs-extra";import Ha from"os";import on from"js-yaml";import{z as T}from"zod";var At=Re.join(Ha.homedir(),".kaven"),oo=Re.join(At,"config.json"),nn="kaven-config.yaml",an=T.object({registry:T.string().url().default("https://marketplace.kaven.site"),telemetry:T.boolean().default(!0),theme:T.enum(["light","dark"]).default("dark"),language:T.enum(["en","pt-BR"]).default("en"),customRegistry:T.string().url().optional(),projectId:T.string().uuid().optional(),activeModules:T.array(T.string()).default([]),capabilities:T.record(T.string(),T.union([T.string(),T.boolean(),T.number()])).default({}),lastLogin:T.string().datetime().optional(),projectDefaults:T.object({dbUrl:T.string().optional(),emailProvider:T.enum(["postmark","resend","ses","smtp"]).optional(),locale:T.string().optional(),currency:T.string().optional()}).optional()}),no=class{globalConfig={};projectConfig={};currentConfig;constructor(){this.currentConfig=an.parse({})}async initialize(){if(await he.ensureDir(At),await he.pathExists(oo))try{this.globalConfig=await he.readJson(oo)}catch{this.globalConfig={}}let e=this.findProjectRoot();if(e){let t=Re.join(e,nn);if(await he.pathExists(t))try{let n=await he.readFile(t,"utf-8");this.projectConfig=on.load(n)}catch{this.projectConfig={}}}this.resolve()}resolve(){this.currentConfig=an.parse({...this.globalConfig,...this.projectConfig})}findProjectRoot(){let e=process.cwd();for(;e!==Re.parse(e).root;){if(he.existsSync(Re.join(e,"package.json")))return e;e=Re.dirname(e)}return null}get(e){let t=`KAVEN_${e.toUpperCase()}`;if(process.env[t]!==void 0){let n=process.env[t];return typeof this.currentConfig[e]=="boolean"?n==="true":typeof this.currentConfig[e]=="number"?Number(n):n}return this.currentConfig[e]}async set(e,t,n="project"){n==="project"?(this.projectConfig[e]=t,await this.persistProject()):(this.globalConfig[e]=t,await this.persistGlobal()),this.resolve()}async persistGlobal(){await he.ensureDir(At),await he.writeJson(oo,this.globalConfig,{spaces:2})}async persistProject(){let e=this.findProjectRoot();if(!e)return;let t=Re.join(e,nn),n=on.dump(this.projectConfig,{lineWidth:120,noRefs:!0});await he.writeFile(t,n,"utf-8")}async reset(){this.globalConfig={},this.projectConfig={},await this.persistGlobal(),await this.persistProject(),this.resolve()}getRegistry(){return this.currentConfig.customRegistry||this.currentConfig.registry}getAll(){return{...this.currentConfig}}getProjectRoot(){return this.findProjectRoot()}getConfigDir(){return At}},q=new no;import Ee from"picocolors";var Wa=`
|
|
79
79
|
\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557
|
|
80
80
|
\u2588\u2588\u2551 \u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551
|
|
81
81
|
\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551
|
|
82
82
|
\u2588\u2588\u2554\u2550\u2588\u2588\u2557 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u255A\u2588\u2588\u2557 \u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551
|
|
83
83
|
\u2588\u2588\u2551 \u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551
|
|
84
84
|
\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D
|
|
85
|
-
`;function
|
|
86
|
-
${
|
|
87
|
-
`).map(t=>
|
|
85
|
+
`;function rn(){return`
|
|
86
|
+
${Wa.split(`
|
|
87
|
+
`).map(t=>Ee.cyan(t)).join(`
|
|
88
88
|
`)}
|
|
89
|
-
${
|
|
90
|
-
`}var
|
|
89
|
+
${Ee.dim(" The Premium Framework Orchestrator for SaaS")}
|
|
90
|
+
`}var Nl={primary:Ee.cyan,secondary:Ee.magenta,success:Ee.green,warning:Ee.yellow,error:Ee.red,dim:Ee.dim};import*as Xa from"child_process";import ao from"fs-extra";import*as Mt from"path";import Za from"ora";import sn from"chalk";var Ya={...Xa},Qa={ora:Za};async function dt(o,e={}){if(e.skipAiox)return;let t=Mt.join(o,".aiox-core");if(!ao.existsSync(t)&&!ao.existsSync(Mt.join(o,".aiox")))return;let n=Qa.ora("Bootstrapping AIOX environment...").start();try{let a=ao.existsSync(Mt.join(o,".aiox-core/bin/aiox.js"))?".aiox-core/bin/aiox.js":".aiox/bin/aiox.js";Ya.execSync(`node ${a} devops environment-bootstrap --quiet`,{cwd:o,stdio:"pipe",timeout:6e4}),n.succeed("AIOX environment bootstrapped")}catch(a){n.warn("AIOX environment bootstrap failed"),console.log(sn.yellow(" \u26A0 Run manually inside the project: kaven aiox bootstrap")),process.env.KAVEN_DEBUG&&console.error(sn.gray(` Error: ${a.message}`))}}import qe from"fs-extra";import cn from"path";var er=".kaven/init-state.json",ln=["clone","configure","install","git","squad","aiox-core","env-bootstrap"],ut=class o{constructor(e){this.projectDir=e;this.statePath=cn.join(e,er)}statePath;state=null;static async findIncomplete(e){let t=new o(e);return!await qe.pathExists(t.statePath)||(await t.load(),t.isComplete())?null:t}async load(){return this.state=await qe.readJson(this.statePath),this.state}async create(e,t,n){let a={clone:"pending",configure:"pending",install:"pending",git:"pending",squad:"pending","aiox-core":"pending","env-bootstrap":"pending"};n.skipInstall&&(a.install="skipped"),n.skipGit&&(a.git="skipped"),n.withSquad||(a.squad="skipped",a["aiox-core"]="skipped"),n.skipAiox&&(a["env-bootstrap"]="skipped"),this.state={version:"1",projectName:e,answers:t,options:n,steps:a,startedAt:new Date().toISOString(),updatedAt:new Date().toISOString()},await qe.ensureDir(cn.dirname(this.statePath)),await this.persist()}async markStep(e,t){if(!this.state)throw new Error("State not initialized");this.state.steps[e]=t,this.state.updatedAt=new Date().toISOString(),await this.persist()}getState(){if(!this.state)throw new Error("State not loaded");return this.state}getResumePoint(){return this.state?ln.find(e=>this.state.steps[e]==="pending"||this.state.steps[e]==="failed")??null:null}isComplete(){return this.state?ln.every(e=>this.state.steps[e]==="done"||this.state.steps[e]==="skipped"):!1}async cleanup(){await qe.pathExists(this.statePath)&&await qe.remove(this.statePath)}async persist(){await qe.writeJson(this.statePath,this.state,{spaces:2})}};function Se(o){rr(o)&&(ro("Operation cancelled."),process.exit(0))}async function X(o,e,t,n,a={}){let r=nr();r.start(t);try{return await n(),await o.markStep(e,"done"),r.stop(Y.green(`${t} \u2713`)),!0}catch(i){await o.markStep(e,"failed");let s=i instanceof Error?i.message:String(i);return r.stop(Y.red(`${t} \u2717`)),a.fatal&&(ro(s),process.exit(1)),console.log(Y.dim(` Error: ${s}`)),!1}}async function mn(o,e){let t=await le.getInstance(),n=new Be,a=await dn({message:"\u{1F310} Select Language / Selecione o Idioma:",options:[{label:"English",value:"en"},{label:"Portugu\xEAs (Brasil)",value:"pt-BR"}],initialValue:"en"});Se(a),await t.setLanguage(a),await q.initialize(),await q.set("language",a,"global"),console.log(rn()),tr(Y.cyan(t.t("init.intro")));let r=o;r||(e.defaults?r="my-kaven-app":(r=await jt({message:t.t("init.projectName"),placeholder:"my-kaven-app",validate:d=>{let u=n.validateName(d||"");return u.valid?void 0:u.reason}}),Se(r)));let i=we.resolve(process.cwd(),r),s=await ut.findIncomplete(i);if(s&&!e.force){let d=s.getResumePoint(),u=e.resume?!0:await un({message:Y.yellow(`\u26A0 Incomplete init detected (stopped at: ${Y.bold(d??"unknown")}). Resume from here?`),initialValue:!0});if(e.resume||Se(u),u){await sr(i,s,n);return}e.force=!0}else await ye.pathExists(i)&&!e.force&&(ro(Y.red(`Error: Directory "${r}" already exists. Use --force to overwrite.`)),process.exit(1));let c;if(e.defaults){let d=q.getAll().projectDefaults||{};c={dbUrl:e.dbUrl||d.dbUrl||`postgresql://user:password@localhost:5432/${r}`,emailProvider:e.emailProvider||d.emailProvider||"postmark",locale:e.locale||d.locale||"en-US",currency:e.currency||d.currency||"USD"}}else{let d=q.getAll().projectDefaults||{},u=await jt({message:"Database URL (PostgreSQL):",initialValue:d.dbUrl||`postgresql://user:password@localhost:5432/${r}`});Se(u);let m=await dn({message:"Email provider:",options:[{label:"Postmark",value:"postmark"},{label:"Resend",value:"resend"},{label:"AWS SES",value:"ses"},{label:"SMTP",value:"smtp"}],initialValue:d.emailProvider||"postmark"});Se(m);let p=await jt({message:"Default locale:",initialValue:d.locale||"en-US"});Se(p);let f=await jt({message:"Default currency:",initialValue:d.currency||"USD"});Se(f);let y=await un({message:t.t("init.withSquad"),initialValue:!0});Se(y),e.withSquad=y,c={dbUrl:u,emailProvider:m,locale:p,currency:f}}let l=new ut(i);await l.create(r,{...c,projectName:r},{withSquad:e.withSquad,skipInstall:e.skipInstall,skipGit:e.skipGit,skipAiox:e.skipAiox,template:e.template}),await ir(i,r,c,l,n,e)}async function ir(o,e,t,n,a,r){let i=pn(import.meta.url),s=we.dirname(i);await X(n,"clone","Cloning kaven-template...",async()=>{await a.cloneTemplate(o,r.template)},{fatal:!0}),await X(n,"configure","Configuring project...",async()=>{await a.removeGitDir(o),await a.replacePlaceholders(o,{...t,projectName:e});let c=we.join(o,".claude","CLAUDE.md");await ye.ensureDir(we.dirname(c));let l=we.resolve(s,"../../core/templates/CLAUDE.md.hbs");if(await ye.pathExists(l)){let d=await ye.readFile(l,"utf-8");await ye.writeFile(c,d.replace("${new Date().toLocaleDateString()}",new Date().toLocaleDateString()),"utf-8")}},{fatal:!0}),r.skipInstall?await n.markStep("install","skipped"):await X(n,"install",cr(),async()=>{await a.runInstall(o)}),r.skipGit?await n.markStep("git","skipped"):await X(n,"git","Initializing git...",async()=>{await a.initGit(o)}),r.withSquad?await X(n,"squad","Installing kaven-squad...",async()=>{let l=await a.installSquad(o);if(!l.installed)throw new Error(l.reason??"squad install failed")})?await X(n,"aiox-core","Installing AIOX Core...",async()=>{let l=await a.installAIOXCore(o);if(!l.installed)throw new Error(l.reason??"aiox-core install failed")}):(await n.markStep("aiox-core","skipped"),console.log(Y.dim(` To retry: cd ${e} && kaven init --resume`))):(await n.markStep("squad","skipped"),await n.markStep("aiox-core","skipped")),r.skipAiox?await n.markStep("env-bootstrap","skipped"):await X(n,"env-bootstrap","Bootstrapping AIOX environment...",async()=>{await dt(o,{skipAiox:!1})}),await fn(e,n)}async function sr(o,e,t){let n=e.getState(),{answers:a,options:r,projectName:i}=n;console.log(Y.cyan(`
|
|
91
|
+
Resuming init for ${Y.bold(i)}...
|
|
92
|
+
`));let s=pn(import.meta.url),c=we.dirname(s),l=d=>{let u=n.steps[d];return u==="pending"||u==="failed"};l("clone")&&await X(e,"clone","Cloning kaven-template...",async()=>{await t.cloneTemplate(o,r.template)},{fatal:!0}),l("configure")&&await X(e,"configure","Configuring project...",async()=>{await t.removeGitDir(o),await t.replacePlaceholders(o,a);let d=we.join(o,".claude","CLAUDE.md");await ye.ensureDir(we.dirname(d));let u=we.resolve(c,"../../core/templates/CLAUDE.md.hbs");if(await ye.pathExists(u)){let m=await ye.readFile(u,"utf-8");await ye.writeFile(d,m.replace("${new Date().toLocaleDateString()}",new Date().toLocaleDateString()),"utf-8")}},{fatal:!0}),l("install")&&await X(e,"install","Installing dependencies...",async()=>{await t.runInstall(o)}),l("git")&&await X(e,"git","Initializing git...",async()=>{await t.initGit(o)}),l("squad")?await X(e,"squad","Installing kaven-squad...",async()=>{let u=await t.installSquad(o);if(!u.installed)throw new Error(u.reason??"squad install failed")})&&l("aiox-core")&&await X(e,"aiox-core","Installing AIOX Core...",async()=>{let u=await t.installAIOXCore(o);if(!u.installed)throw new Error(u.reason??"aiox-core install failed")}):l("aiox-core")&&await X(e,"aiox-core","Installing AIOX Core...",async()=>{let d=await t.installAIOXCore(o);if(!d.installed)throw new Error(d.reason??"aiox-core install failed")}),l("env-bootstrap")&&await X(e,"env-bootstrap","Bootstrapping AIOX environment...",async()=>{await dt(o,{skipAiox:!1})}),await fn(i,e)}function cr(){return"Installing dependencies..."}async function fn(o,e){if(e.isComplete())await e.cleanup();else{let t=e.getResumePoint();console.log(Y.yellow(`
|
|
93
|
+
\u26A0 Setup incomplete (stopped at: ${Y.bold(t??"unknown")})`)),console.log(Y.dim(` Resume with: kaven init ${o} --resume
|
|
94
|
+
`))}ar(`cd ${Y.cyan(o)}
|
|
91
95
|
cp .env.example .env
|
|
92
|
-
|
|
93
|
-
pnpm
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
Para atualizar
|
|
96
|
+
pnpm docker:up
|
|
97
|
+
pnpm db:migrate && pnpm db:seed
|
|
98
|
+
pnpm dev`,"Next Steps"),or(Y.cyan("Project ready. Happy building \u{1F680}"));try{await q.initialize();let t=e.getState();await q.set("projectDefaults",{dbUrl:t.answers.dbUrl,emailProvider:t.answers.emailProvider,locale:t.answers.locale,currency:t.answers.currency},"global")}catch{}}import F from"chalk";import lo from"ora";import gr from"open";import kn from"path";import Ge from"fs-extra";import hr from"os";import H from"chalk";import io from"ora";import Tt from"path";import{fileURLToPath as lr}from"url";import{spawn as dr}from"child_process";import gn from"fs";var ur=lr(import.meta.url),hn=Tt.dirname(ur);function pr(){let o=[Tt.join(hn,"../../package.json"),Tt.join(hn,"../../../package.json"),Tt.join(process.cwd(),"package.json")];for(let e of o)if(gn.existsSync(e))try{return JSON.parse(gn.readFileSync(e,"utf8"))}catch{continue}return{version:"0.4.2-alpha.0"}}var mr=pr(),Je=mr.version,De="kaven-cli";async function so(){let o=io("Checking for updates...").start();try{let e=await fetch(`https://registry.npmjs.org/${De}`);if(!e.ok){o.fail("Could not check for updates");return}let a=(await e.json())["dist-tags"]?.latest||Je;if(o.stop(),console.log(),console.log(H.bold("Version Check:")),console.log(` Current: ${H.cyan(Je)}`),console.log(` Latest: ${H.cyan(a)}`),console.log(),a===Je){console.log(H.green("\u2705 You're on the latest version!"));return}let r=wn(Je),i=wn(a);i.major>r.major||i.major===r.major&&i.minor>r.minor||i.major===r.major&&i.minor===r.minor&&i.patch>r.patch?(console.log(H.yellow(`\u26A0 Update available: ${a}`)),console.log(),console.log(H.bold("To upgrade, run:")),console.log(H.cyan(` npm install -g ${De}@latest`)),console.log(H.cyan(" or")),console.log(H.cyan(` pnpm add -g ${De}@latest`)),console.log(),console.log(H.gray("Release notes: https://github.com/kaven-co/kaven-cli/releases"))):console.log(H.green("\u2705 You're on the latest version!"))}catch(e){o.fail(`Check failed: ${e instanceof Error?e.message:String(e)}`),console.log(H.gray("You can manually check at: https://www.npmjs.com/package/kaven-cli"))}}async function co(){console.log();let o=io("Fetching latest version...").start();try{let e=await fetch(`https://registry.npmjs.org/${De}`);if(!e.ok)throw new Error("Failed to fetch package info");let a=(await e.json())["dist-tags"]?.latest||Je;if(a===Je){o.succeed("Already on latest version");return}o.text=`Installing ${De}@${a}...`;let r=process.env.npm_config_user_agent?.includes("pnpm")?"pnpm":"npm",i=await yn(r,["install","-g",`${De}@${a}`]);if(i!==0){o.fail(`Installation failed with exit code ${i}`),console.error(H.gray(`Try: ${r} install -g ${De}@latest`)),process.exit(1);return}o.succeed(`Updated to ${a}`);let s=io("Running health check...").start(),c=await fr();c.ok?(s.succeed("Installation verified"),console.log(),console.log(H.green("\u2705 CLI upgraded successfully!")),console.log(H.gray("Try: kaven --version"))):(s.warn("Installation verification failed"),console.log(H.yellow(c.errors.join(`
|
|
99
|
+
`))))}catch(e){o.fail(`Installation failed: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}async function fr(){let o=[];try{await yn("kaven",["--version"],{stdio:"pipe"})!==0&&o.push("kaven command not available in PATH")}catch{o.push("Could not execute kaven command")}return{ok:o.length===0,errors:o}}function yn(o,e,t){return new Promise((n,a)=>{let r=dr(o,e,t||{stdio:"inherit"});r.on("error",a),r.on("close",i=>n(i??0))})}function wn(o){let e=o.replace(/^v/,"").split("-")[0],[t,n,a]=e.split(".").map(Number);return{major:t||0,minor:n||0,patch:a||0}}var ze=kn.join(hr.homedir(),".kaven","license.json"),wr=["starter","complete","pro","enterprise"],pt={starter:"Starter",complete:"Complete",pro:"Pro",enterprise:"Enterprise"},yr=5e3,vn=120;async function vr(){if(!await Ge.pathExists(ze))return null;try{return(await Ge.readJson(ze)).key||null}catch{return null}}async function kr(o){let e={};if(await Ge.pathExists(ze))try{e=await Ge.readJson(ze)}catch{}await Ge.ensureDir(kn.dirname(ze)),await Ge.writeJson(ze,{...e,tier:o},{spaces:2})}function br(o){return new Promise(e=>setTimeout(e,o))}async function bn(o){let e=new A;try{await e.getValidToken()}catch{console.error(F.red("Error: Not authenticated. Run 'kaven auth login' first.")),process.exit(1);return}let t=await vr();if(!t){console.error(F.red("Error: No license found. Add your license key first with 'kaven license status'.")),process.exit(1);return}let n=new J(e),a=lo("Loading your current license...").start(),r;try{r=(await n.getLicenseStatus(t)).tier.toLowerCase(),a.succeed(`Current tier: ${F.bold(pt[r]||r)}`)}catch{a.fail("Could not load license status"),console.error(F.gray("Try: kaven license status")),process.exit(1);return}let{printTierComparisonTable:i}=await import("./tier-table-DQMPQSI2.js");i(r,"pro"),console.log();let{select:s}=await import("@inquirer/prompts"),c=wr.filter(f=>f!==r&&f!=="enterprise");if(c.length===0){console.log(F.yellow(`You're already on the highest available tier (${pt[r]||r}).`)),console.log(F.gray("For Enterprise plans, contact: enterprise@kaven.site"));return}let l=await s({message:"Select target tier:",choices:c.map(f=>({name:pt[f],value:f}))});if(l===r){console.log(F.yellow(`Already on ${pt[r]||r}.`));return}let d=lo("Creating checkout session...").start(),u,m;try{let f=await n.createCheckoutSession(l,t);u=f.sessionUrl,m=f.sessionId,d.succeed("Checkout session created")}catch(f){d.fail("Failed to create checkout session"),console.error(F.red(f instanceof Error?f.message:String(f))),process.exit(1);return}if(o.browser!==!1){console.log(F.cyan("Opening checkout in your browser...")),console.log(F.gray(`URL: ${u}`));try{await gr(u)}catch{console.log(F.yellow("Could not open browser automatically. Open this URL manually:")),console.log(F.cyan(u))}}else console.log(F.cyan("Open this URL to complete checkout:")),console.log(F.bold(u));console.log();let p=lo("Waiting for payment confirmation (checking every 5s, max 10 min)...").start();for(let f=0;f<vn;f++){await br(yr);let y=vn-f-1;p.text=`Waiting for payment confirmation... (${y*5}s remaining)`;try{let C=await n.getCheckoutStatus(m);if(C.status==="confirmed"){p.succeed("Payment confirmed!");let R=C.tier||l;await kr(R),console.log(),console.log(F.green(`\u2705 Successfully upgraded to ${pt[R]||R}!`)),console.log(F.gray("Your new features are now unlocked."));return}if(C.status==="cancelled"){p.fail("Checkout was cancelled."),console.log(F.gray("No changes were made to your subscription."));return}if(C.status==="failed"){p.fail("Payment failed."),console.log(F.gray("Please try again or contact support@kaven.site")),process.exit(1);return}}catch{}}p.warn("Timed out waiting for payment confirmation."),console.log(),console.log(F.yellow("If you completed payment, your upgrade may take a few minutes to activate.")),console.log(F.gray("Check your upgrade status at: https://dashboard.kaven.site/billing"))}import He from"path";import Rt from"fs-extra";import*as oe from"@clack/prompts";import x from"picocolors";var U={intro:oe.intro,outro:oe.outro,spinner:oe.spinner,log:{info:oe.log.info,warn:oe.log.warn,success:oe.log.success,error:oe.log.error,step:oe.log.step,message:oe.log.message}},xr="kaven-cli";function Er(o){let e=[He.join(o,"package.json"),He.join(He.dirname(new URL(import.meta.url).pathname),"../../../package.json"),He.join(He.dirname(new URL(import.meta.url).pathname),"../../package.json")];for(let t of e)try{if(Rt.existsSync(t)){let n=JSON.parse(Rt.readFileSync(t,"utf8"));if(n.version)return n.version}}catch{}return"0.4.2-alpha.0"}async function Sr(){try{let o=await fetch(`https://registry.npmjs.org/${xr}`);return o.ok?(await o.json())["dist-tags"]?.latest??null:null}catch{return null}}function xn(o,e){let t=r=>r.replace(/^v/,"").split("-")[0].split(".").map(Number),n=t(o),a=t(e);for(let r=0;r<3;r++)if((n[r]??0)!==(a[r]??0))return(n[r]??0)-(a[r]??0);return 0}async function Cr(o){let e=He.join(o,".kaven","cache","modules");if(!await Rt.pathExists(e))return[];let t=await Rt.readdir(e),n=new Set;for(let a of t){let r=a.lastIndexOf("-");r>0&&n.add(a.slice(0,r))}return[...n]}async function Pr(o,e){let t=Er(o),n=null,a=!1;e&&(n=await Sr(),n&&xn(n,t)>0&&(a=!0));let r=await Cr(o),i=[];if(r.length>0){let s=null;try{let c=new A;await c.getValidToken(),s=new J(c)}catch{}for(let c of r){let l=await St(c,o);if(!l)continue;let d=null,u;if(s)try{d=(await s.getModule(c)).latestVersion??null}catch(p){u=fe(p).message}else u="marketplace offline or not authenticated";let m=!!(d&&xn(d,l)>0);i.push({slug:c,installed:l,latest:d,outdated:m,error:u})}}return{cliCurrent:t,cliLatest:n,cliOutdated:a,modules:i}}function $r(o,e){if(e&&(o.cliLatest===null?U.log.warn(x.yellow(`kaven-cli: ${x.bold(o.cliCurrent)} (could not reach npm)`)):o.cliOutdated?U.log.warn(x.yellow(`kaven-cli: ${x.bold(o.cliCurrent)} \u2192 ${x.bold(o.cliLatest)} available`)+x.dim(`
|
|
100
|
+
npm install -g kaven-cli@latest`)):U.log.success(x.green(`kaven-cli: ${x.bold(o.cliCurrent)} \u2713 up to date`))),o.modules.length===0){U.log.info(x.dim("No modules installed in this project."));return}for(let t of o.modules)t.error?U.log.warn(x.yellow(`${t.slug}: ${x.bold(t.installed)} (${t.error})`)):t.outdated?U.log.warn(x.yellow(`${t.slug}: ${x.bold(t.installed)} \u2192 ${x.bold(t.latest)} available`)):U.log.success(x.green(`${t.slug}: ${x.bold(t.installed)} \u2713`))}async function En(o={},e){let t=e??process.cwd(),{core:n,module:a,all:r,check:i,skipVerify:s}=o;if(a){await at(a,t,{skipVerify:s});return}let c=!!(n||r||!n&&!a);U.intro(x.bold(x.cyan("kaven update")));let l=U.spinner();l.start("Verificando atualiza\xE7\xF5es dispon\xEDveis...");let d=await Pr(t,c);if(l.stop("Status de atualiza\xE7\xF5es:"),$r(d,c),!(d.cliOutdated||d.modules.some(m=>m.outdated))){U.outro(x.green("\u2713 Tudo atualizado."));return}if(i){U.outro(x.yellow("Atualiza\xE7\xF5es dispon\xEDveis. Rode sem --check para aplicar."));return}if((r||n)&&d.cliOutdated&&d.cliLatest&&(U.log.info(x.cyan(`Atualizando kaven-cli ${d.cliCurrent} \u2192 ${d.cliLatest}...`)),U.log.info(x.dim(" Execute: npm install -g kaven-cli@latest"))),r){let m=d.modules.filter(p=>p.outdated);for(let p of m)U.log.info(x.cyan(`
|
|
101
|
+
Atualizando m\xF3dulo ${p.slug} ${p.installed} \u2192 ${p.latest}...`)),await at(p.slug,t,{skipVerify:s});U.outro(x.green("\u2713 Todos os m\xF3dulos atualizados."));return}if(!n){let m=d.modules.filter(p=>p.outdated);if(m.length>0){U.log.info(x.dim(`
|
|
102
|
+
Para atualizar m\xF3dulos:`));for(let p of m)U.log.info(x.dim(` kaven update --module ${p.slug}`));U.log.info(x.dim(`
|
|
103
|
+
Para atualizar tudo: kaven update --all`))}U.outro("")}}import ve from"chalk";import pe from"fs-extra";import We from"path";import Ir from"os";var po=class{cacheDir;maxSizeBytes;indexPath;constructor(e,t){this.cacheDir=e??We.join(Ir.homedir(),".kaven","cache"),this.maxSizeBytes=t??50*1024*1024,this.indexPath=We.join(this.cacheDir,"_index.json")}async ensureDir(){await pe.ensureDir(this.cacheDir)}keyToFileName(e){return e.replace(/[^a-zA-Z0-9-_:.]/g,"_")+".json"}async readIndex(){try{if(await pe.pathExists(this.indexPath))return await pe.readJson(this.indexPath)}catch{}return{}}async writeIndex(e){await this.ensureDir(),await pe.writeJson(this.indexPath,e,{spaces:2})}async get(e){let n=(await this.readIndex())[e];if(!n||Date.now()>n.expiresAt)return null;try{let a=We.join(this.cacheDir,n.file);return(await pe.readJson(a)).data}catch{return null}}async getStale(e){let n=(await this.readIndex())[e];if(!n)return null;try{let a=We.join(this.cacheDir,n.file);return(await pe.readJson(a)).data}catch{return null}}async set(e,t,n){await this.ensureDir();let a=JSON.stringify(t),r=Buffer.byteLength(a,"utf8"),i=Date.now(),s=i+n,c=this.keyToFileName(e),l=We.join(this.cacheDir,c),d={data:t,expiresAt:s,size:r,createdAt:i};await pe.writeJson(l,d,{spaces:2});let u=await this.readIndex();u[e]={file:c,expiresAt:s,size:r,createdAt:i},await this.writeIndex(u),await this.evict()}async evict(){let e=await this.readIndex(),t=Object.entries(e),n=t.reduce((r,[,i])=>r+i.size,0);if(n<=this.maxSizeBytes)return;t.sort(([,r],[,i])=>r.createdAt-i.createdAt);let a={...e};for(let[r,i]of t){if(n<=this.maxSizeBytes)break;try{let s=We.join(this.cacheDir,i.file);await pe.remove(s),delete a[r],n-=i.size}catch{}}await this.writeIndex(a)}async stats(){let e=await this.readIndex(),t=Object.values(e);if(t.length===0)return{totalSize:0,entries:0};let n=t.reduce((s,c)=>s+c.size,0),a=t.map(s=>s.createdAt),r=new Date(Math.min(...a)),i=new Date(Math.max(...a));return{totalSize:n,entries:t.length,oldest:r,newest:i}}async clear(){await pe.pathExists(this.cacheDir)&&await pe.remove(this.cacheDir)}},uo=null;function mo(){return uo||(uo=new po),uo}function Sn(o){if(o===0)return"0 B";let e=1024,t=["B","KB","MB","GB"],n=Math.floor(Math.log(o)/Math.log(e));return`${parseFloat((o/Math.pow(e,n)).toFixed(1))} ${t[n]}`}async function Cn(){let o=mo(),e=await o.stats();console.log(ve.bold(`
|
|
99
104
|
Kaven CLI Cache Status
|
|
100
|
-
`)),console.log(` Cache directory: ${
|
|
101
|
-
`+" ".repeat(n+3)):
|
|
102
|
-
`));let e=[...new Set(
|
|
105
|
+
`)),console.log(` Cache directory: ${ve.cyan(o.cacheDir)}`),console.log(` Total size: ${ve.cyan(Sn(e.totalSize))}`),console.log(` Cached entries: ${ve.cyan(e.entries.toString())}`),e.oldest&&console.log(` Oldest entry: ${ve.gray(e.oldest.toLocaleString())}`),e.newest&&console.log(` Newest entry: ${ve.gray(e.newest.toLocaleString())}`),console.log(),console.log(ve.gray("Run 'kaven cache clear' to remove all cached data."))}async function Pn(){let o=mo(),e=await o.stats();if(e.entries===0){console.log(ve.gray("Cache is already empty."));return}await o.clear(),console.log(ve.green(`Cache cleared: ${e.entries} entries (${Sn(e.totalSize)}) removed.`))}import Q from"chalk";async function $n(o,e){(!o||!e)&&(console.error(Q.red("Error: Both key and value are required")),console.error(Q.gray("Usage: kaven config set KEY VALUE")),process.exit(1)),await q.initialize();try{await q.set(o,e),console.log(Q.green(`\u2705 Set ${Q.bold(o)} = ${Q.bold(e)}`))}catch(t){console.error(Q.red(`Error: ${t instanceof Error?t.message:String(t)}`)),process.exit(1)}}async function In(o,e){o||(console.error(Q.red("Error: Key is required")),console.error(Q.gray("Usage: kaven config get KEY")),process.exit(1)),await q.initialize();try{let t=q.get(o);e.json?console.log(JSON.stringify({[o]:t},null,2)):console.log(t)}catch(t){console.error(Q.red(`Error: ${t instanceof Error?t.message:String(t)}`)),process.exit(1)}}async function An(o){await q.initialize();let e=q.getAll();if(o.json)console.log(JSON.stringify(e,null,2));else{console.log(Q.bold("Kaven Configuration:")),console.log(Q.gray(`Location: ${q.getConfigDir()}/config.json`)),console.log();let t=Object.entries(e),n=Math.max(...t.map(([a])=>a.length));for(let[a,r]of t){let i=" ".repeat(n-a.length),s=typeof r=="object"?JSON.stringify(r,null,2).replace(/\n/g,`
|
|
106
|
+
`+" ".repeat(n+3)):r;console.log(` ${a}${i} ${Q.cyan(s)}`)}}}async function Mn(){let{confirm:o}=await import("@inquirer/prompts");if(!await o({message:"Are you sure you want to reset config to defaults?",default:!1})){console.log(Q.yellow("Cancelled."));return}await q.initialize(),await q.reset(),console.log(Q.green("\u2705 Config reset to defaults"))}import{select as Ar,confirm as jn,text as Mr,multiselect as jr,isCancel as Tr,cancel as Rr}from"@clack/prompts";import W from"picocolors";import go from"fs-extra";import Tn from"path";var ke=[{key:"FEATURE_EMAIL_VERIFICATION",type:"boolean",description:"Email verification on signup",category:"Auth",defaultValue:"true"},{key:"FEATURE_2FA_TOTP",type:"boolean",description:"Two-factor authentication via TOTP",category:"Auth",defaultValue:"false"},{key:"FEATURE_SSO_SAML",type:"boolean",description:"Single Sign-On via SAML/OIDC",category:"Auth",defaultValue:"false"},{key:"FEATURE_SOCIAL_LOGIN",type:"boolean",description:"Login via Google, GitHub, etc.",category:"Auth",defaultValue:"true"},{key:"FEATURE_MAGIC_LINK",type:"boolean",description:"Passwordless login via email",category:"Auth",defaultValue:"false"},{key:"FEATURE_CUSTOM_DOMAIN",type:"boolean",description:"Custom domain per tenant",category:"Tenancy",defaultValue:"false"},{key:"FEATURE_WHITE_LABEL",type:"boolean",description:"Remove Kaven branding",category:"Tenancy",defaultValue:"false"},{key:"FEATURE_MULTI_BUSINESS",type:"boolean",description:"Multiple businesses per user",category:"Tenancy",defaultValue:"false"},{key:"FEATURE_AGENCY_HUB",type:"boolean",description:"Agency management dashboard",category:"Tenancy",defaultValue:"false"},{key:"FEATURE_TENANT_THEMES",type:"boolean",description:"Custom themes for tenants",category:"Tenancy",defaultValue:"true"},{key:"FEATURE_SUBSCRIPTIONS",type:"boolean",description:"Subscription management",category:"Billing",defaultValue:"true"},{key:"FEATURE_INVOICING",type:"boolean",description:"Automatic invoicing",category:"Billing",defaultValue:"true"},{key:"FEATURE_USAGE_BILLING",type:"boolean",description:"Metered usage billing",category:"Billing",defaultValue:"false"},{key:"FEATURE_PADDLE_CHECKOUT",type:"boolean",description:"Paddle payment integration",category:"Billing",defaultValue:"true"},{key:"FEATURE_PAGUBIT_PIX",type:"boolean",description:"Pix payment support",category:"Billing",defaultValue:"false"},{key:"FEATURE_API_ACCESS",type:"boolean",description:"External API access",category:"API",defaultValue:"false"},{key:"FEATURE_WEBHOOKS",type:"boolean",description:"Outgoing webhooks",category:"API",defaultValue:"false"},{key:"FEATURE_MARKETPLACE_ACCESS",type:"boolean",description:"Kaven Marketplace access",category:"API",defaultValue:"true"},{key:"MAX_API_CALLS_MONTH",type:"numeric",description:"Maximum API calls per month",category:"API",defaultValue:"10000"},{key:"MAX_AGENT_API_CALLS_HOUR",type:"numeric",description:"Maximum agent calls per hour",category:"API",defaultValue:"100"},{key:"MAX_TEAM_MEMBERS",type:"numeric",description:"Maximum team members per tenant",category:"Limits",defaultValue:"5"},{key:"MAX_PROJECTS",type:"numeric",description:"Maximum projects per tenant",category:"Limits",defaultValue:"3"},{key:"MAX_STORAGE_GB",type:"numeric",description:"Maximum storage in GB",category:"Limits",defaultValue:"1"},{key:"MAX_TENANTS",type:"numeric",description:"Maximum sub-tenants",category:"Limits",defaultValue:"1"},{key:"FEATURE_PRIORITY_SUPPORT",type:"boolean",description:"Priority support queue",category:"Support",defaultValue:"false"},{key:"FEATURE_AUDIT_COMPLIANCE",type:"boolean",description:"Audit logs and compliance",category:"Support",defaultValue:"false"},{key:"FEATURE_DATA_EXPORT",type:"boolean",description:"Customer data export",category:"Support",defaultValue:"true"}],fo={starter:{FEATURE_EMAIL_VERIFICATION:!0,FEATURE_SOCIAL_LOGIN:!0,FEATURE_MARKETPLACE_ACCESS:!0,MAX_TEAM_MEMBERS:"5",MAX_PROJECTS:"3",MAX_API_CALLS_MONTH:"10000",MAX_AGENT_API_CALLS_HOUR:"100"},complete:{FEATURE_EMAIL_VERIFICATION:!0,FEATURE_SOCIAL_LOGIN:!0,FEATURE_CUSTOM_DOMAIN:!0,FEATURE_API_ACCESS:!0,FEATURE_MARKETPLACE_ACCESS:!0,MAX_TEAM_MEMBERS:"25",MAX_PROJECTS:"20",MAX_API_CALLS_MONTH:"100000",MAX_AGENT_API_CALLS_HOUR:"500"},pro:{FEATURE_EMAIL_VERIFICATION:!0,FEATURE_SOCIAL_LOGIN:!0,FEATURE_CUSTOM_DOMAIN:!0,FEATURE_WHITE_LABEL:!0,FEATURE_API_ACCESS:!0,FEATURE_MARKETPLACE_ACCESS:!0,MAX_TEAM_MEMBERS:"100",MAX_PROJECTS:"100",MAX_API_CALLS_MONTH:"1000000",MAX_AGENT_API_CALLS_HOUR:"2000"},enterprise:{}};function mt(o){Tr(o)&&(Rr("Cancelled."),process.exit(0))}async function Rn(o){let e=o.outputPath??Tn.join(process.cwd(),"packages","database","prisma","seeds","capabilities.seed.ts");if(o.list){let t=await le.getInstance();Dr(t);return}if(o.tier){await Dn(o.tier,e,o);return}await _r(e,o)}function Dr(o){console.log(),console.log(W.bold(W.underline(o.t("config.features.catalogHeader")))),console.log(W.dim(o.t("config.features.capabilitiesTotal",{count:ke.length})+`
|
|
107
|
+
`));let e=[...new Set(ke.map(t=>t.category))];for(let t of e){let n=ke.filter(a=>a.category===t);console.log(W.bold(W.cyan(` ${t} (${n.length})`)));for(let a of n)console.log(` ${W.white(a.key.padEnd(30))} ${W.dim(`[${a.type}]`)}`),console.log(` ${W.dim(a.description)}`);console.log()}console.log(W.bold(o.t("config.features.tierPresets")));for(let t of["starter","complete","pro","enterprise"])console.log(` ${W.white(t.padEnd(12))}`);console.log()}async function Dn(o,e,t){let n=fo[o]||{},a={};for(let r of ke)o==="enterprise"?a[r.key]=r.type==="boolean"?!0:"-1":a[r.key]=n[r.key]??(r.type==="boolean"?!1:r.defaultValue);await _n(a,e,t,o)}async function _r(o,e){let t=await le.getInstance();console.log(),console.log(W.bold(W.underline(t.t("config.features.tuiHeader"))));let n=await Ar({message:t.t("config.features.selectTier"),options:[{label:"Starter \u2014 Essential SaaS features",value:"starter"},{label:"Complete \u2014 White-label + Custom Domains",value:"complete"},{label:"Pro \u2014 Extended API + Limits",value:"pro"},{label:"Enterprise \u2014 Unlimited everything",value:"enterprise"},{label:W.dim(t.t("common.cancel")),value:"cancel"}]});if(mt(n),n==="cancel")return;let a=n,r=fo[a]||{},i={},s=await jn({message:t.t("config.features.customize"),initialValue:!1});if(mt(s),!s)return Dn(a,o,e);let c=[...new Set(ke.map(l=>l.category))];for(let l of c){let d=ke.filter(p=>p.category===l),u=d.filter(p=>p.type==="boolean"),m=d.filter(p=>p.type==="numeric");if(u.length>0){let p=u.filter(y=>a==="enterprise"||r[y.key]===!0).map(y=>y.key),f=await jr({message:`${l} features:`,options:u.map(y=>({label:`${y.key.padEnd(30)} \u2014 ${y.description}`,value:y.key})),initialValues:p,required:!1});mt(f);for(let y of u)i[y.key]=f.includes(y.key)}for(let p of m){let f=a==="enterprise"?"-1":r[p.key]||p.defaultValue,y=await Mr({message:`${p.key} (${p.description}):`,placeholder:f,defaultValue:f});mt(y),i[p.key]=y}}await _n(i,o,e,a)}async function _n(o,e,t,n){let a=await le.getInstance(),r=ke.map(s=>{let c=o[s.key];return` { key: "${s.key}", type: "${s.type}", defaultValue: "${c}", description: "${s.description}" },`}).join(`
|
|
103
108
|
`),i=`// packages/database/prisma/seeds/capabilities.seed.ts
|
|
104
109
|
// Generated by kaven config features \u2014 ${new Date().toISOString()}
|
|
105
110
|
// Tier: ${n}
|
|
@@ -108,10 +113,10 @@ import { PrismaClient } from "@prisma/client";
|
|
|
108
113
|
|
|
109
114
|
export async function seedCapabilities(prisma: PrismaClient) {
|
|
110
115
|
const capabilities = [
|
|
111
|
-
${
|
|
116
|
+
${r}
|
|
112
117
|
];
|
|
113
118
|
|
|
114
|
-
console.log("\u{1F510} Seeding ${
|
|
119
|
+
console.log("\u{1F510} Seeding ${ke.length} Capabilities...");
|
|
115
120
|
|
|
116
121
|
for (const cap of capabilities) {
|
|
117
122
|
await prisma.capability.upsert({
|
|
@@ -122,8 +127,8 @@ ${a}
|
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
129
|
`;if(t.dryRun){console.log(W.bold(`
|
|
125
|
-
`+
|
|
126
|
-
\u2705 ${
|
|
130
|
+
`+a.t("config.features.dryRunHeader"))),console.log(i);return}if(go.existsSync(e)&&!t.force){let s=await jn({message:a.t("config.features.confirmOverwrite"),initialValue:!1});if(mt(s),!s)return}await go.ensureDir(Tn.dirname(e)),await go.writeFile(e,i,"utf-8"),console.log(W.green(`
|
|
131
|
+
\u2705 ${a.t("config.features.seedWritten",{path:e})}`)),console.log(W.dim(a.t("config.features.runSeed")))}import ee from"chalk";import Or from"ora";import Xe from"path";import _e from"fs-extra";var Lr=`name: Tests
|
|
127
132
|
on:
|
|
128
133
|
push:
|
|
129
134
|
branches: [main, develop]
|
|
@@ -159,7 +164,7 @@ jobs:
|
|
|
159
164
|
- run: pnpm lint
|
|
160
165
|
- run: pnpm test
|
|
161
166
|
- run: pnpm build
|
|
162
|
-
`,
|
|
167
|
+
`,Fr=`name: Publish Module
|
|
163
168
|
on:
|
|
164
169
|
push:
|
|
165
170
|
tags:
|
|
@@ -183,7 +188,7 @@ jobs:
|
|
|
183
188
|
env:
|
|
184
189
|
KAVEN_LICENSE_KEY: \${{ secrets.KAVEN_LICENSE_KEY }}
|
|
185
190
|
run: kaven module publish
|
|
186
|
-
`,
|
|
191
|
+
`,Ur=`#!/bin/bash
|
|
187
192
|
# Pre-commit hook for Kaven projects
|
|
188
193
|
set -e
|
|
189
194
|
|
|
@@ -204,7 +209,7 @@ if command -v pnpm format &> /dev/null; then
|
|
|
204
209
|
fi
|
|
205
210
|
|
|
206
211
|
echo "\u2705 All pre-commit checks passed"
|
|
207
|
-
`;async function
|
|
212
|
+
`;async function On(o){let e=process.cwd(),t=Xe.join(e,"package.json");await _e.pathExists(t)||(console.error(ee.red("Error: package.json not found. Run this in a Kaven project root.")),process.exit(1));let n=Or("Setting up CI/CD configuration...").start();try{let a=Xe.join(e,".github","workflows");await _e.ensureDir(a);let r=Xe.join(a,"test.yml");o.dryRun||await _e.writeFile(r,Lr),n.text=`Creating ${ee.cyan(".github/workflows/test.yml")}...`;let i=Xe.join(a,"publish.yml");o.dryRun||await _e.writeFile(i,Fr),n.text=`Creating ${ee.cyan(".github/workflows/publish.yml")}...`;let s=Xe.join(e,".husky");await _e.ensureDir(s);let c=Xe.join(s,"pre-commit");o.dryRun||(await _e.writeFile(c,Ur),await _e.chmod(c,493)),n.text=`Creating ${ee.cyan(".husky/pre-commit")}...`,n.succeed("CI/CD configuration created"),console.log(),console.log(ee.bold("Files created:")),console.log(` ${ee.cyan(".github/workflows/test.yml")} - Run tests on push/PR`),console.log(` ${ee.cyan(".github/workflows/publish.yml")} - Publish on git tags`),console.log(` ${ee.cyan(".husky/pre-commit")} - Local pre-commit validation`),console.log(),console.log(ee.bold("Next steps:")),console.log(ee.gray(" 1. Install husky: pnpm husky install")),console.log(ee.gray(" 2. Add GitHub secrets: KAVEN_LICENSE_KEY")),console.log(ee.gray(" 3. Push to GitHub and watch workflows run")),o.dryRun&&(console.log(),console.log(ee.yellow("(Dry-run: No files were actually created)")))}catch(a){n.fail("Failed to create CI/CD configuration"),console.error(ee.red(a instanceof Error?a.message:String(a))),process.exit(1)}}import Ce from"picocolors";import{spinner as Nr}from"@clack/prompts";function Ln(o){let e=o.command("aiox").description("AIOX integration utilities");e.command("bootstrap").description("Run AIOX environment bootstrap in current project").option("--skip-aiox","Skip AIOX logic (for testing)").action(async t=>{let n=process.cwd();await dt(n,t)}),e.command("install-squad").description("Install or repair kaven-squad in current project (resumes incomplete kaven init)").action(async()=>{let t=process.cwd(),n=new Be,a=Nr();a.start("Installing kaven-squad...");let r=await n.installSquad(t);if(r.installed){a.stop(Ce.green("kaven-squad installed \u2713")),a.start("Installing AIOX Core runtime...");let i=await n.installAIOXCore(t);i.installed?a.stop(Ce.green("AIOX Core installed \u2713")):(a.stop(Ce.yellow(`AIOX Core skipped: ${i.reason}`)),console.log(Ce.dim(" Run manually: npx aiox-core@latest install --quiet")))}else r.reason==="already-exists"?(a.stop(Ce.yellow("kaven-squad already installed \u2014 nothing to do")),console.log(Ce.dim(" To reinstall: remove squads/kaven-squad/ and re-run"))):(a.stop(Ce.red(`Squad install failed: ${r.reason}`)),console.log(Ce.dim(" Manual fallback: git clone https://github.com/bychrisr/kaven-squad squads/kaven-squad")),process.exit(1))})}var Vr=()=>{let o=new Kr;o.name("kaven").description("The official CLI for the Kaven SaaS boilerplate ecosystem").version("0.4.2-alpha.0").addHelpText("after",`
|
|
208
213
|
Examples:
|
|
209
214
|
$ kaven init my-saas-app Bootstrap a new Kaven project
|
|
210
215
|
$ kaven auth login Authenticate with Kaven Marketplace
|
|
@@ -215,13 +220,14 @@ Examples:
|
|
|
215
220
|
|
|
216
221
|
Documentation: https://docs.kaven.site/cli
|
|
217
222
|
Support: https://github.com/kaven-co/kaven-cli/issues
|
|
218
|
-
`),o.command("init [project-name]").description("Bootstrap a new Kaven project from the official template").option("--defaults","Skip interactive prompts and use default values").option("--skip-install","Skip running pnpm install after setup").option("--skip-git","Skip git init and initial commit").option("--force","Overwrite existing directory if it exists").option("--template <path>","Path to a local template or custom git repository URL").option("--with-squad","Install kaven-squad (AIOX) into squads/kaven-squad/ after scaffold").option("--skip-aiox","Skip AIOX environment bootstrap").addHelpText("after",`
|
|
223
|
+
`),o.command("init [project-name]").description("Bootstrap a new Kaven project from the official template").option("--defaults","Skip interactive prompts and use default values").option("--skip-install","Skip running pnpm install after setup").option("--skip-git","Skip git init and initial commit").option("--force","Overwrite existing directory if it exists").option("--template <path>","Path to a local template or custom git repository URL").option("--with-squad","Install kaven-squad (AIOX) into squads/kaven-squad/ after scaffold").option("--skip-aiox","Skip AIOX environment bootstrap").option("--resume","Resume an incomplete init from where it stopped").addHelpText("after",`
|
|
219
224
|
Examples:
|
|
220
225
|
$ kaven init my-app Interactive setup
|
|
221
226
|
$ kaven init my-app --defaults Use defaults (no prompts)
|
|
222
227
|
$ kaven init my-app --skip-git Skip git initialization
|
|
223
228
|
$ kaven init my-app --with-squad Install kaven-squad for AIOX integration
|
|
224
|
-
|
|
229
|
+
$ kaven init my-app --resume Resume incomplete setup from last step
|
|
230
|
+
`).action((c,l)=>mn(c,{defaults:l.defaults,skipInstall:l.skipInstall,skipGit:l.skipGit,force:l.force,template:l.template,withSquad:l.withSquad,skipAiox:l.skipAiox,resume:l.resume}));let e=o.command("module").alias("m").description("Manage Kaven modules: install, remove, publish, activate, and diagnose").addHelpText("after",`
|
|
225
231
|
Examples:
|
|
226
232
|
$ kaven module doctor Check module integrity
|
|
227
233
|
$ kaven module doctor --fix Auto-fix detected issues
|
|
@@ -241,15 +247,15 @@ Examples:
|
|
|
241
247
|
$ kaven module doctor
|
|
242
248
|
$ kaven module doctor --fix
|
|
243
249
|
$ kaven module doctor --json
|
|
244
|
-
`).action(c=>
|
|
250
|
+
`).action(c=>So({fix:c.fix,json:c.json})),e.command("add <path>").description("Install a module from a local manifest file").addHelpText("after",`
|
|
245
251
|
Examples:
|
|
246
252
|
$ kaven module add ./modules/payments/module.json
|
|
247
253
|
$ kaven module add /absolute/path/to/module.json
|
|
248
|
-
`).action(c
|
|
254
|
+
`).action(c=>$o(c)),e.command("remove <name>").description("Remove an installed module and clean up injected code").addHelpText("after",`
|
|
249
255
|
Examples:
|
|
250
256
|
$ kaven module remove payments
|
|
251
257
|
$ kaven module remove notifications
|
|
252
|
-
`).action(c=>
|
|
258
|
+
`).action(c=>Io(c)),e.command("publish").description("Publish the current directory as a module to Kaven Marketplace").option("--dry-run","Validate and package the module without uploading").option("--changelog <text>","Release notes for this version").addHelpText("after",`
|
|
253
259
|
Requirements:
|
|
254
260
|
- module.json must exist in the current directory
|
|
255
261
|
- Must be authenticated: run 'kaven auth login' first
|
|
@@ -258,7 +264,7 @@ Examples:
|
|
|
258
264
|
$ kaven module publish
|
|
259
265
|
$ kaven module publish --dry-run
|
|
260
266
|
$ kaven module publish --changelog "Added dark mode support"
|
|
261
|
-
`).action(c=>
|
|
267
|
+
`).action(c=>Do({dryRun:c.dryRun,changelog:c.changelog})),e.command("activate <name> [root]").description("Activate a Kaven schema module by uncommenting its models in schema.extended.prisma").option("--with-deps","Automatically activate required dependencies").option("--skip-migrate","Skip db:generate and db:migrate after activation").option("--dry-run","Show affected models without modifying schema").option("--yes","Skip confirmation prompt").addHelpText("after",`
|
|
262
268
|
Modules: billing, projects, notifications
|
|
263
269
|
|
|
264
270
|
Examples:
|
|
@@ -266,64 +272,64 @@ Examples:
|
|
|
266
272
|
$ kaven module activate projects
|
|
267
273
|
$ kaven module activate projects ./my-app
|
|
268
274
|
$ kaven module activate billing --with-deps
|
|
269
|
-
`).action((c,l,d)=>
|
|
275
|
+
`).action((c,l,d)=>Wt(c,l,d)),e.command("deactivate <name> [root]").description("Deactivate a Kaven schema module by commenting its models in schema.extended.prisma").option("--skip-migrate","Skip db:generate and db:migrate").option("--dry-run","Show affected models without modifying schema").option("--yes","Skip confirmation prompt").addHelpText("after",`
|
|
270
276
|
Modules: billing, projects, notifications
|
|
271
277
|
|
|
272
278
|
Examples:
|
|
273
279
|
$ kaven module deactivate billing
|
|
274
280
|
$ kaven module deactivate projects
|
|
275
281
|
$ kaven module deactivate projects ./my-app
|
|
276
|
-
`).action((c,l,d)=>
|
|
282
|
+
`).action((c,l,d)=>Fo(c,l,d)),e.command("list [root]").description("List available Kaven schema modules with their status, models, and dependencies").addHelpText("after",`
|
|
277
283
|
Examples:
|
|
278
284
|
$ kaven module list
|
|
279
285
|
$ kaven module list ./my-app
|
|
280
|
-
`).action(c=>
|
|
286
|
+
`).action(c=>Uo(c)),e.command("update [slug]").description("Update an installed marketplace module to the latest version").option("--skip-verify","Skip Ed25519 signature verification (dev only)").addHelpText("after",`
|
|
281
287
|
Examples:
|
|
282
288
|
$ kaven module update payments Update the payments module
|
|
283
289
|
$ kaven module update Interactive: select module to update
|
|
284
290
|
$ kaven module update payments --skip-verify Skip signature check (dev only)
|
|
285
|
-
`).action((c,l)=>
|
|
291
|
+
`).action((c,l)=>at(c,void 0,{skipVerify:l.skipVerify??!1}));let t=o.command("auth").description("Manage authentication and session tokens").addHelpText("after",`
|
|
286
292
|
Examples:
|
|
287
293
|
$ kaven auth login Start device code authentication flow
|
|
288
294
|
$ kaven auth whoami Show current user info
|
|
289
295
|
$ kaven auth logout End the local session
|
|
290
|
-
`);t.command("login").description("Start the interactive device code authentication flow (RFC 8628)").action(()=>
|
|
296
|
+
`);t.command("login").description("Start the interactive device code authentication flow (RFC 8628)").action(()=>Ko()),t.command("logout").description("Clear the local authentication session").action(()=>Vo()),t.command("whoami").description("Display information about the currently authenticated user").action(()=>Bo());let n=o.command("marketplace").alias("mkt").alias("market").description("Explore, browse, and install modules from the Kaven Marketplace").addHelpText("after",`
|
|
291
297
|
Examples:
|
|
292
298
|
$ kaven marketplace list
|
|
293
299
|
$ kaven marketplace list --category auth --sort popular
|
|
294
300
|
$ kaven marketplace install payments
|
|
295
301
|
$ kaven marketplace browse
|
|
296
|
-
`);n.command("list").description("List all modules available in the marketplace").option("--category <category>","Filter modules by category").option("--sort <field>","Sort order: newest (default), popular, name","newest").option("--page <n>","Page number (default: 1)","1").option("--limit <n>","Results per page (default: 20, max: 100)","20").option("--json","Output raw JSON instead of formatted table").action(c=>
|
|
302
|
+
`);n.command("list").description("List all modules available in the marketplace").option("--category <category>","Filter modules by category").option("--sort <field>","Sort order: newest (default), popular, name","newest").option("--page <n>","Page number (default: 1)","1").option("--limit <n>","Results per page (default: 20, max: 100)","20").option("--json","Output raw JSON instead of formatted table").action(c=>qo({category:c.category,sort:c.sort,page:parseInt(c.page,10),limit:parseInt(c.limit,10),json:c.json??!1})),n.command("install <moduleId>").description("Download and install a module from the Kaven Marketplace").option("--version <ver>","Install a specific version (default: latest)").option("--force","Skip overwrite confirmation").option("--skip-env","Skip environment variable injection").option("--skip-verify","Skip Ed25519 signature verification (dev only)").option("--env-file <path>","Target .env file (default: .env)").addHelpText("after",`
|
|
297
303
|
Examples:
|
|
298
304
|
$ kaven marketplace install payments
|
|
299
305
|
$ kaven marketplace install payments --version 1.2.0
|
|
300
306
|
$ kaven marketplace install auth --skip-env
|
|
301
307
|
$ kaven marketplace install my-module --skip-verify
|
|
302
|
-
`).action((c,l)
|
|
308
|
+
`).action((c,l)=>$t(c,{version:l.version,force:l.force??!1,skipEnv:l.skipEnv??!1,skipVerify:l.skipVerify??!1,envFile:l.envFile})),n.command("browse").description("Interactive TUI module browser \u2014 explore modules by category").addHelpText("after",`
|
|
303
309
|
Navigate with arrow keys, press Enter to select.
|
|
304
310
|
Supports category filtering and pagination.
|
|
305
|
-
`).action(()=>
|
|
311
|
+
`).action(()=>Wo()),o.command("update").description("Check and apply updates for CLI and installed modules").option("--core","Update only the CLI itself").option("--module <slug>","Update a specific installed module").option("--all","Apply all available updates (CLI + modules)").option("--check","Check for updates without applying").option("--skip-verify","Skip Ed25519 signature verification (dev only)").addHelpText("after",`
|
|
306
312
|
Examples:
|
|
307
313
|
$ kaven update Check all updates (CLI + modules)
|
|
308
314
|
$ kaven update --core Check/apply CLI update only
|
|
309
315
|
$ kaven update --module payments Update the payments module
|
|
310
316
|
$ kaven update --all Apply all updates
|
|
311
317
|
$ kaven update --check List updates without applying
|
|
312
|
-
`).action(c=>
|
|
318
|
+
`).action(c=>En({core:c.core,module:c.module,all:c.all,check:c.check,skipVerify:c.skipVerify}));let a=o.command("upgrade").description("Upgrade your Kaven license plan").addHelpText("after",`
|
|
313
319
|
Examples:
|
|
314
320
|
$ kaven upgrade Upgrade license tier (interactive)
|
|
315
321
|
$ kaven upgrade check Check current license status
|
|
316
322
|
$ kaven upgrade install Force install latest CLI (manual)
|
|
317
323
|
|
|
318
324
|
Note: To update the CLI or modules, use \`kaven update\` instead.
|
|
319
|
-
`);
|
|
325
|
+
`);a.command("tier").description("Upgrade your Kaven license to a higher tier (default)").option("--no-browser","Print the checkout URL instead of opening the browser").action(c=>bn({browser:c.browser!==!1})),a.command("check").description("Check current license status").action(()=>so()),a.command("install").description("Force install the latest Kaven CLI version globally").action(()=>co()),o.command("telemetry").description("View observability and command audit logs").command("view").description("Display the most recent local telemetry events").option("-l, --limit <number>","Number of events to display","10").action(c=>Xo(parseInt(c.limit))),o.addCommand(tn());let i=o.command("cache").description("Manage the local API response cache").addHelpText("after",`
|
|
320
326
|
Cache directory: ~/.kaven/cache (max 50 MB)
|
|
321
327
|
Cached data: module listings (24h TTL), manifests (7d), license status (1h)
|
|
322
328
|
|
|
323
329
|
Examples:
|
|
324
330
|
$ kaven cache status
|
|
325
331
|
$ kaven cache clear
|
|
326
|
-
`);i.command("status").description("Show cache statistics (size, entry count, age)").action(()=>
|
|
332
|
+
`);i.command("status").description("Show cache statistics (size, entry count, age)").action(()=>Cn()),i.command("clear").description("Delete all locally cached API responses").action(()=>Pn());let s=o.command("config").description("Manage Kaven CLI configuration").addHelpText("after",`
|
|
327
333
|
Config file: ~/.kaven/config.json
|
|
328
334
|
|
|
329
335
|
Examples:
|
|
@@ -334,7 +340,7 @@ Examples:
|
|
|
334
340
|
$ kaven config features
|
|
335
341
|
$ kaven config features --tier complete
|
|
336
342
|
$ kaven config features --list
|
|
337
|
-
`);s.command("set <key> <value>").description("Set a configuration value").action((c,l)
|
|
343
|
+
`);s.command("set <key> <value>").description("Set a configuration value").action((c,l)=>$n(c,l)),s.command("get <key>").description("Get a configuration value").option("--json","Output as JSON").action((c,l)=>In(c,{json:l.json})),s.command("view").description("Display all configuration").option("--json","Output as JSON").action(c=>An({json:c.json})),s.command("reset").description("Reset configuration to defaults").action(()=>Mn()),s.command("features").description("Interactive TUI to select and configure the 60 framework capabilities (feature flags)").option("--tier <tier>","Apply a preset tier directly without prompts: starter | complete | pro | enterprise").option("--list","List all available capabilities grouped by category, without modifying anything").addHelpText("after",`
|
|
338
344
|
Output: packages/database/prisma/seeds/capabilities.seed.ts (relative to cwd)
|
|
339
345
|
|
|
340
346
|
Examples:
|
|
@@ -345,7 +351,7 @@ Examples:
|
|
|
345
351
|
|
|
346
352
|
After generating the seed file:
|
|
347
353
|
$ pnpm prisma db seed
|
|
348
|
-
`).action(c=>
|
|
354
|
+
`).action(c=>Rn({tier:c.tier,list:c.list??!1})),o.command("init-ci").description("Initialize GitHub Actions CI/CD workflows").option("--dry-run","Show what would be created without writing files").addHelpText("after",`
|
|
349
355
|
Creates:
|
|
350
356
|
- .github/workflows/test.yml Run tests on push/PR
|
|
351
357
|
- .github/workflows/publish.yml Publish modules on git tags
|
|
@@ -354,4 +360,4 @@ Creates:
|
|
|
354
360
|
Examples:
|
|
355
361
|
$ kaven init-ci Interactive setup
|
|
356
362
|
$ kaven init-ci --dry-run Show what would be created
|
|
357
|
-
`).action(c=>
|
|
363
|
+
`).action(c=>On({dryRun:c.dryRun})),Ln(o),o.parse(process.argv)},Br=process.argv[1]&&(process.argv[1].endsWith("/kaven")||process.argv[1].endsWith("/index.ts")||process.argv[1].endsWith("/index.js"));Br&&Vr();export{Vr as main};
|